7 #include "sw/device/lib/base/multibits.h"
9 #include "sram_ctrl_regs.h"
18 return mmio_region_read32(sram_ctrl->
base_addr,
19 SRAM_CTRL_CTRL_REGWEN_REG_OFFSET)
31 return mmio_region_read32(sram_ctrl->
base_addr,
32 SRAM_CTRL_EXEC_REGWEN_REG_OFFSET)
42 static bool sram_ctrl_readback_locked(
const dif_sram_ctrl_t *sram_ctrl) {
43 return mmio_region_read32(sram_ctrl->
base_addr,
44 SRAM_CTRL_READBACK_REGWEN_REG_OFFSET)
55 mmio_region_write32(sram_ctrl->
base_addr, SRAM_CTRL_CTRL_REGWEN_REG_OFFSET,
66 mmio_region_write32(sram_ctrl->
base_addr, SRAM_CTRL_EXEC_REGWEN_REG_OFFSET,
77 SRAM_CTRL_READBACK_REGWEN_REG_OFFSET, 0);
85 static uint32_t sram_ctrl_get_status(
const dif_sram_ctrl_t *sram_ctrl) {
86 return mmio_region_read32(sram_ctrl->
base_addr, SRAM_CTRL_STATUS_REG_OFFSET);
90 if (sram_ctrl == NULL) {
94 if (sram_ctrl_locked_ctrl(sram_ctrl)) {
101 mmio_region_write32(sram_ctrl->
base_addr, SRAM_CTRL_CTRL_REG_OFFSET, reg);
106 status = sram_ctrl_get_status(sram_ctrl);
111 mmio_region_write32(sram_ctrl->
base_addr, SRAM_CTRL_CTRL_REG_OFFSET, reg);
115 status = sram_ctrl_get_status(sram_ctrl);
123 if (sram_ctrl == NULL) {
127 if (sram_ctrl_locked_ctrl(sram_ctrl)) {
133 mmio_region_write32(sram_ctrl->
base_addr, SRAM_CTRL_CTRL_REG_OFFSET, reg);
139 if (sram_ctrl == NULL) {
143 if (sram_ctrl_locked_ctrl(sram_ctrl)) {
148 mmio_region_write32(sram_ctrl->
base_addr, SRAM_CTRL_CTRL_REG_OFFSET, reg);
155 if (sram_ctrl == NULL) {
163 *
status = sram_ctrl_get_status(sram_ctrl);
170 if (sram_ctrl == NULL || state == NULL) {
175 mmio_region_read32(sram_ctrl->
base_addr, SRAM_CTRL_EXEC_REG_OFFSET);
184 if (sram_ctrl == NULL) {
188 if (sram_ctrl_exec_locked(sram_ctrl)) {
194 mmio_region_write32(sram_ctrl->
base_addr, SRAM_CTRL_EXEC_REG_OFFSET, value);
201 if (sram_ctrl == NULL) {
205 if (sram_ctrl_readback_locked(sram_ctrl)) {
211 mmio_region_write32(sram_ctrl->
base_addr, SRAM_CTRL_READBACK_REG_OFFSET,
219 if (sram_ctrl == NULL) {
225 sram_ctrl_lock_ctrl(sram_ctrl);
228 sram_ctrl_lock_exec(sram_ctrl);
231 sram_ctrl_lock_readback(sram_ctrl);
243 if (sram_ctrl == NULL || is_locked == NULL) {
249 *is_locked = sram_ctrl_locked_ctrl(sram_ctrl);
252 *is_locked = sram_ctrl_exec_locked(sram_ctrl);
255 *is_locked = sram_ctrl_readback_locked(sram_ctrl);
265 multi_bit_bool_t *success,
266 multi_bit_bool_t clear) {
267 if (sram_ctrl == NULL || success == NULL) {
277 *success = mmio_region_read32(sram_ctrl->
base_addr,
278 SRAM_CTRL_SCR_KEY_ROTATED_REG_OFFSET);
279 mmio_region_write32(sram_ctrl->
base_addr,
280 SRAM_CTRL_SCR_KEY_ROTATED_REG_OFFSET, clear);