8 #include "sw/device/lib/base/multibits.h"
9 #include "sw/device/lib/dif/dif_csrng_shared.h"
14 if (mmio_region_read32(edn->
base_addr, EDN_REGWEN_REG_OFFSET) == 0) {
26 uint32_t reg = mmio_region_read32(edn->
base_addr, EDN_CTRL_REG_OFFSET);
29 mmio_region_write32(edn->
base_addr, EDN_CTRL_REG_OFFSET, reg);
38 mmio_region_write32(edn->
base_addr, EDN_REGWEN_REG_OFFSET, 0);
43 if (edn == NULL || is_locked == NULL) {
46 *is_locked = check_locked(edn) !=
kDifOk;
56 uint32_t reg = mmio_region_read32(edn->
base_addr, EDN_CTRL_REG_OFFSET);
59 mmio_region_write32(edn->
base_addr, EDN_CTRL_REG_OFFSET, reg);
73 uint32_t ctrl_reg = mmio_region_read32(edn->
base_addr, EDN_CTRL_REG_OFFSET);
74 const uint32_t edn_en =
85 mmio_region_write32(edn->
base_addr, EDN_CTRL_REG_OFFSET, ctrl_reg);
90 mmio_region_write32(edn->
base_addr, EDN_CTRL_REG_OFFSET, ctrl_reg);
96 mmio_region_write32(edn->
base_addr, EDN_CTRL_REG_OFFSET, ctrl_reg);
99 mmio_region_write32(edn->
base_addr, EDN_RESEED_CMD_REG_OFFSET,
102 mmio_region_write32(edn->
base_addr, EDN_RESEED_CMD_REG_OFFSET,
107 mmio_region_write32(edn->
base_addr, EDN_GENERATE_CMD_REG_OFFSET,
110 mmio_region_write32(edn->
base_addr, EDN_GENERATE_CMD_REG_OFFSET,
116 EDN_MAX_NUM_REQS_BETWEEN_RESEEDS_REG_OFFSET,
124 mmio_region_write32(edn->
base_addr, EDN_CTRL_REG_OFFSET, ctrl_reg);
156 if (edn == NULL || set == NULL) {
160 uint32_t reg = mmio_region_read32(edn->
base_addr, EDN_SW_CMD_STS_REG_OFFSET);
171 *set = field_val ? true :
false;
185 if (edn == NULL || unhealthy_fifos == NULL || errors == NULL) {
188 *unhealthy_fifos = 0;
191 uint32_t reg = mmio_region_read32(edn->
base_addr, EDN_ERR_CODE_REG_OFFSET);
194 EDN_ERR_CODE_SFIFO_RESCMD_ERR_BIT);
197 EDN_ERR_CODE_SFIFO_GENCMD_ERR_BIT);
200 EDN_ERR_CODE_EDN_ACK_SM_ERR_BIT);
202 EDN_ERR_CODE_EDN_MAIN_SM_ERR_BIT);
204 EDN_ERR_CODE_EDN_CNTR_ERR_BIT);
206 EDN_ERR_CODE_FIFO_WRITE_ERR_BIT);
208 EDN_ERR_CODE_FIFO_READ_ERR_BIT);
210 EDN_ERR_CODE_FIFO_STATE_ERR_BIT);
223 case kDifEdnFifoReseedCmd:
224 fifo_bit = EDN_ERR_CODE_SFIFO_RESCMD_ERR_BIT;
226 case kDifEdnFifoGenerateCmd:
227 fifo_bit = EDN_ERR_CODE_SFIFO_GENCMD_ERR_BIT;
234 mmio_region_write32(edn->
base_addr, EDN_ERR_CODE_TEST_REG_OFFSET, fifo_bit);
247 error_bit = EDN_ERR_CODE_EDN_ACK_SM_ERR_BIT;
250 error_bit = EDN_ERR_CODE_EDN_MAIN_SM_ERR_BIT;
253 error_bit = EDN_ERR_CODE_EDN_CNTR_ERR_BIT;
256 error_bit = EDN_ERR_CODE_FIFO_WRITE_ERR_BIT;
259 error_bit = EDN_ERR_CODE_FIFO_READ_ERR_BIT;
262 error_bit = EDN_ERR_CODE_FIFO_STATE_ERR_BIT;
269 mmio_region_write32(edn->
base_addr, EDN_ERR_CODE_TEST_REG_OFFSET, error_bit);
275 if (edn == NULL || state == NULL) {
279 *state = mmio_region_read32(edn->
base_addr, EDN_MAIN_SM_STATE_REG_OFFSET);
289 return csrng_send_app_cmd(
292 .id = kCsrngAppCmdInstantiate,
293 .entropy_src_enable =
294 (dif_csrng_entropy_src_toggle_t)entropy_src_enable,
295 .seed_material = (const dif_csrng_seed_material_t *)seed_material,
301 if (edn == NULL || seed_material == NULL) {
305 memcpy(&seed_material2, seed_material,
sizeof(seed_material2));
306 return csrng_send_app_cmd(edn->
base_addr, kCsrngAppCmdTypeEdnSw,
308 .id = kCsrngAppCmdReseed,
309 .seed_material = &seed_material2,
315 if (edn == NULL || seed_material == NULL) {
319 memcpy(&seed_material2, seed_material,
sizeof(seed_material2));
320 return csrng_send_app_cmd(edn->
base_addr, kCsrngAppCmdTypeEdnSw,
322 .id = kCsrngAppCmdUpdate,
323 .seed_material = &seed_material2,
328 if (edn == NULL || len == 0) {
334 const uint32_t num_128bit_blocks = (len + 3) / 4;
335 return csrng_send_app_cmd(edn->
base_addr, kCsrngAppCmdTypeEdnSw,
337 .id = kCsrngAppCmdGenerate,
338 .generate_len = num_128bit_blocks,
346 return csrng_send_app_cmd(edn->
base_addr, kCsrngAppCmdTypeEdnSw,
348 .id = kCsrngAppCmdUninstantiate,
359 uint32_t reg = mmio_region_read32(edn->
base_addr, EDN_CTRL_REG_OFFSET);
362 mmio_region_write32(edn->
base_addr, EDN_CTRL_REG_OFFSET, reg);
366 mmio_region_write32(edn->
base_addr, EDN_CTRL_REG_OFFSET, EDN_CTRL_REG_RESVAL);
373 if (edn == NULL || alerts == NULL) {
379 mmio_region_read32(edn->
base_addr, EDN_RECOV_ALERT_STS_REG_OFFSET);
381 EDN_RECOV_ALERT_STS_EDN_ENABLE_FIELD_ALERT_BIT);
384 EDN_RECOV_ALERT_STS_BOOT_REQ_MODE_FIELD_ALERT_BIT);
387 EDN_RECOV_ALERT_STS_AUTO_REQ_MODE_FIELD_ALERT_BIT);
390 EDN_RECOV_ALERT_STS_CMD_FIFO_RST_FIELD_ALERT_BIT);
392 reg, EDN_RECOV_ALERT_STS_EDN_BUS_CMP_ALERT_BIT);
400 mmio_region_write32(edn->
base_addr, EDN_RECOV_ALERT_STS_REG_OFFSET, 0);