API GUIDE / HASH / LL

G32S10 HASH LL 接口

LL 层接口:LL helper 定义在 ll_hash.h,不维护状态、不做参数校验、不做 padding、不等待、不维护 cache。

1. LL 接口

LL helper 定义在 ll_hash.h,不维护状态、不做参数校验、不做 padding、不等待、不维护 cache。

1.1 实例

bool ll_hash_is_supported_instance(const hash_regs_t *hashx);

仅 hashx == HASH 返回 true。

1.2 HSCR

void ll_hash_set_output_little_endian(hash_regs_t *hashx);
void ll_hash_set_output_big_endian(hash_regs_t *hashx);
void ll_hash_set_input_big_endian(hash_regs_t *hashx);
void ll_hash_set_input_little_endian(hash_regs_t *hashx);
void ll_hash_start_dma_transfer(hash_regs_t *hashx);
void ll_hash_enable_dma(hash_regs_t *hashx);
void ll_hash_disable_dma(hash_regs_t *hashx);
void ll_hash_start_new_round(hash_regs_t *hashx);
void ll_hash_set_algorithm(hash_regs_t *hashx,
                           hash_hscr_sel_t alg_sel);
void ll_hash_enable(hash_regs_t *hashx);
void ll_hash_disable(hash_regs_t *hashx);

INIT 和 DMAS 由硬件自动清零。

1.3 HSSR

uint32_t ll_hash_get_status(const hash_regs_t *hashx);
void ll_hash_clear_status(hash_regs_t *hashx, uint32_t status_mask);
bool ll_hash_is_mrd_set(const hash_regs_t *hashx);
void ll_hash_clear_mrd(hash_regs_t *hashx);
bool ll_hash_is_ord_set(const hash_regs_t *hashx);
void ll_hash_clear_ord(hash_regs_t *hashx);

MRD 表示 DMA read done,ORD 表示 CPU output/read done。

1.4 HSINTEN

void ll_hash_enable_mrd_interrupt(hash_regs_t *hashx);
void ll_hash_disable_mrd_interrupt(hash_regs_t *hashx);
void ll_hash_enable_ord_interrupt(hash_regs_t *hashx);
void ll_hash_disable_ord_interrupt(hash_regs_t *hashx);

这些 helper 执行 read-modify-write,调用方必须串行化 HSINTEN 访问。

1.5 DMA 参数

void ll_hash_set_dma_source_addr(hash_regs_t *hashx,
                                 uint32_t src_phys_addr);
void ll_hash_set_dma_transfer_words(hash_regs_t *hashx,
                                    uint32_t word_count);
void ll_hash_set_dma_block_count(hash_regs_t *hashx,
                                 uint32_t block_count);

HSSA 必须先于 HSTC 写入。HSTC 单位为 32-bit word,HSBNUM 单位为 64-byte DMA block。

1.6 FIFO

void ll_hash_write_data(hash_regs_t *hashx, uint32_t word);
uint32_t ll_hash_read_digest_word(const hash_regs_t *hashx);

HSDI 为 write-only,HSDO 为 read-only。只能在对应完成状态有效后读取 digest。

1.7 HSCG

void ll_hash_enable_clock_gate(hash_regs_t *hashx);
void ll_hash_disable_clock_gate(hash_regs_t *hashx);

2. 寄存器

Offset寄存器用途
0x0000HSCR算法、endian、DMA、INIT、EN
0x0004HSSRORD/MRD 状态
0x0008HSINTENORD/MRD 本地中断使能
0x000CHSSADMA 源物理地址
0x0010HSTCDMA transfer word count
0x0014HSBNUMDMA block count
0x0018HSDICPU 数据输入
0x001CHSDOdigest word 输出
0x0020HSCGHASH clock gate

关键字段:

字段说明
HSCR.PS[31:28]page size,保持硬件默认值
HSCR.DORVS输出 word 字节翻转
HSCR.DIRVS输入 word 字节翻转
HSCR.DMASDMA start,自清
HSCR.DMAEDMA mode
HSCR.INIT新 round,自清
HSCR.SEL[3:1]MD5=0,SHA1=1,SHA224=2,SHA256=3,SHA384=4,SHA512=5
HSCR.ENcontroller enable
HSSR.MRDDMA read done
HSSR.ORDCPU output/read done