pussuw commented on code in PR #16387: URL: https://github.com/apache/nuttx/pull/16387#discussion_r2092611969
########## arch/arm64/src/imx9/imx9_ele.c: ########## @@ -387,3 +391,103 @@ int imx9_ele_verify_image(uint32_t img_id, uint32_t *response) return -EIO; } + +int imx9_ele_start_rng(void) +{ + msg.header.version = ELE_VERSION; + msg.header.tag = ELE_CMD_TAG; + msg.header.size = 1; + msg.header.command = ELE_START_RNG_REQ; + + imx9_ele_sendmsg(&msg); + imx9_ele_receivemsg(&msg); + + if ((msg.data[0] & 0xff) == ELE_OK) + { + return 0; + } + + return -EIO; +} + +int imx9_ele_get_trng_state(void) +{ + msg.header.version = ELE_VERSION; + msg.header.tag = ELE_CMD_TAG; + msg.header.size = 1; + msg.header.command = ELE_GET_TRNG_STATE_REQ; + + imx9_ele_sendmsg(&msg); + imx9_ele_receivemsg(&msg); + + if ((msg.data[0] & 0xff) == ELE_OK) + { + struct ele_trng_state *ele_trng = + (struct ele_trng_state *)(msg.data + 1); + if (ele_trng->trng_state != ELE_TRNG_STATUS_READY || + ele_trng->csal_state != ELE_CSAL_STATUS_READY) + { + /* Ensure imx9_ele_start_rng() was called earlier or we will + * end up here. + */ + + return -EBUSY; + } + else + { + return 0; + } + } + + return -EIO; +} + +int imx9_ele_get_random(uint32_t paddr, size_t len) +{ + uint16_t counter = 0; + uint16_t max_tries = ELE_RNG_TIMEOUT_US / ELE_RNG_SLEEP_US; + + if (paddr == 0 || len == 0) + { + _err("Wrong input parameters!\n"); + return -EINVAL; + } + + while ((imx9_ele_get_trng_state() != 0)) + { + if (counter > max_tries) + { + _err("Timed out after %hu iterations!\n", counter); + return -EBUSY; + } + + usleep(ELE_RNG_SLEEP_US); + counter++; + } + + /* Flush the cache before sending the request to ELE. */ + + up_flush_dcache((uintptr_t)paddr, (uintptr_t)(paddr + len)); + + msg.header.version = ELE_VERSION_FW; + msg.header.tag = ELE_CMD_TAG; + msg.header.size = 4; + msg.header.command = ELE_GET_RNG_REQ; + msg.data[0] = 0; + msg.data[1] = paddr; + msg.data[2] = len; + + imx9_ele_sendmsg(&msg); + imx9_ele_receivemsg(&msg); + + if ((msg.data[0] & 0xff) == ELE_OK) + { + /* Invalidate the cache so we can read the result from RAM. */ + + up_invalidate_dcache((uintptr_t)paddr, Review Comment: Cache ops deal with virtual addresses, is this an issue, or is paddr=vaddr ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org