11 #include "keymgr_dpe_regs.h"
19 static_assert(KEYMGR_DPE_SW_BINDING_1_REG_OFFSET ==
20 KEYMGR_DPE_SW_BINDING_0_REG_OFFSET + 4,
21 "SW_BINDING_N registers must be contiguous.");
22 static_assert(KEYMGR_DPE_SW_BINDING_2_REG_OFFSET ==
23 KEYMGR_DPE_SW_BINDING_0_REG_OFFSET + 8,
24 "SW_BINDING_N registers must be contiguous.");
25 static_assert(KEYMGR_DPE_SW_BINDING_3_REG_OFFSET ==
26 KEYMGR_DPE_SW_BINDING_0_REG_OFFSET + 12,
27 "SW_BINDING_N registers must be contiguous.");
28 static_assert(KEYMGR_DPE_SW_BINDING_4_REG_OFFSET ==
29 KEYMGR_DPE_SW_BINDING_0_REG_OFFSET + 16,
30 "SW_BINDING_N registers must be contiguous.");
31 static_assert(KEYMGR_DPE_SW_BINDING_5_REG_OFFSET ==
32 KEYMGR_DPE_SW_BINDING_0_REG_OFFSET + 20,
33 "SW_BINDING_N registers must be contiguous.");
34 static_assert(KEYMGR_DPE_SW_BINDING_6_REG_OFFSET ==
35 KEYMGR_DPE_SW_BINDING_0_REG_OFFSET + 24,
36 "SW_BINDING_N registers must be contiguous.");
37 static_assert(KEYMGR_DPE_SW_BINDING_7_REG_OFFSET ==
38 KEYMGR_DPE_SW_BINDING_0_REG_OFFSET + 28,
39 "SW_BINDING_N registers must be contiguous.");
41 static_assert(KEYMGR_DPE_SALT_1_REG_OFFSET == KEYMGR_DPE_SALT_0_REG_OFFSET + 4,
42 "SALT_N registers must be contiguous.");
43 static_assert(KEYMGR_DPE_SALT_2_REG_OFFSET == KEYMGR_DPE_SALT_0_REG_OFFSET + 8,
44 "SALT_N registers must be contiguous.");
45 static_assert(KEYMGR_DPE_SALT_3_REG_OFFSET == KEYMGR_DPE_SALT_0_REG_OFFSET + 12,
46 "SALT_N registers must be contiguous.");
47 static_assert(KEYMGR_DPE_SALT_4_REG_OFFSET == KEYMGR_DPE_SALT_0_REG_OFFSET + 16,
48 "SALT_N registers must be contiguous.");
49 static_assert(KEYMGR_DPE_SALT_5_REG_OFFSET == KEYMGR_DPE_SALT_0_REG_OFFSET + 20,
50 "SALT_N registers must be contiguous.");
51 static_assert(KEYMGR_DPE_SALT_6_REG_OFFSET == KEYMGR_DPE_SALT_0_REG_OFFSET + 24,
52 "SALT_N registers must be contiguous.");
53 static_assert(KEYMGR_DPE_SALT_7_REG_OFFSET == KEYMGR_DPE_SALT_0_REG_OFFSET + 28,
54 "SALT_N registers must be contiguous.");
56 static_assert(KEYMGR_DPE_SW_SHARE0_OUTPUT_1_REG_OFFSET ==
57 KEYMGR_DPE_SW_SHARE0_OUTPUT_0_REG_OFFSET + 4,
58 "SW_SHARE0_OUTPUT_N registers must be contiguous.");
59 static_assert(KEYMGR_DPE_SW_SHARE0_OUTPUT_2_REG_OFFSET ==
60 KEYMGR_DPE_SW_SHARE0_OUTPUT_0_REG_OFFSET + 8,
61 "SW_SHARE0_OUTPUT_N registers must be contiguous.");
62 static_assert(KEYMGR_DPE_SW_SHARE0_OUTPUT_3_REG_OFFSET ==
63 KEYMGR_DPE_SW_SHARE0_OUTPUT_0_REG_OFFSET + 12,
64 "SW_SHARE0_OUTPUT_N registers must be contiguous.");
65 static_assert(KEYMGR_DPE_SW_SHARE0_OUTPUT_4_REG_OFFSET ==
66 KEYMGR_DPE_SW_SHARE0_OUTPUT_0_REG_OFFSET + 16,
67 "SW_SHARE0_OUTPUT_N registers must be contiguous.");
68 static_assert(KEYMGR_DPE_SW_SHARE0_OUTPUT_5_REG_OFFSET ==
69 KEYMGR_DPE_SW_SHARE0_OUTPUT_0_REG_OFFSET + 20,
70 "SW_SHARE0_OUTPUT_N registers must be contiguous.");
71 static_assert(KEYMGR_DPE_SW_SHARE0_OUTPUT_6_REG_OFFSET ==
72 KEYMGR_DPE_SW_SHARE0_OUTPUT_0_REG_OFFSET + 24,
73 "SW_SHARE0_OUTPUT_N registers must be contiguous.");
74 static_assert(KEYMGR_DPE_SW_SHARE0_OUTPUT_7_REG_OFFSET ==
75 KEYMGR_DPE_SW_SHARE0_OUTPUT_0_REG_OFFSET + 28,
76 "SW_SHARE0_OUTPUT_N registers must be contiguous.");
78 static_assert(KEYMGR_DPE_SW_SHARE1_OUTPUT_1_REG_OFFSET ==
79 KEYMGR_DPE_SW_SHARE1_OUTPUT_0_REG_OFFSET + 4,
80 "SW_SHARE1_OUTPUT_N registers must be contiguous.");
81 static_assert(KEYMGR_DPE_SW_SHARE1_OUTPUT_2_REG_OFFSET ==
82 KEYMGR_DPE_SW_SHARE1_OUTPUT_0_REG_OFFSET + 8,
83 "SW_SHARE1_OUTPUT_N registers must be contiguous.");
84 static_assert(KEYMGR_DPE_SW_SHARE1_OUTPUT_3_REG_OFFSET ==
85 KEYMGR_DPE_SW_SHARE1_OUTPUT_0_REG_OFFSET + 12,
86 "SW_SHARE1_OUTPUT_N registers must be contiguous.");
87 static_assert(KEYMGR_DPE_SW_SHARE1_OUTPUT_4_REG_OFFSET ==
88 KEYMGR_DPE_SW_SHARE1_OUTPUT_0_REG_OFFSET + 16,
89 "SW_SHARE1_OUTPUT_N registers must be contiguous.");
90 static_assert(KEYMGR_DPE_SW_SHARE1_OUTPUT_5_REG_OFFSET ==
91 KEYMGR_DPE_SW_SHARE1_OUTPUT_0_REG_OFFSET + 20,
92 "SW_SHARE1_OUTPUT_N registers must be contiguous.");
93 static_assert(KEYMGR_DPE_SW_SHARE1_OUTPUT_6_REG_OFFSET ==
94 KEYMGR_DPE_SW_SHARE1_OUTPUT_0_REG_OFFSET + 24,
95 "SW_SHARE1_OUTPUT_N registers must be contiguous.");
96 static_assert(KEYMGR_DPE_SW_SHARE1_OUTPUT_7_REG_OFFSET ==
97 KEYMGR_DPE_SW_SHARE1_OUTPUT_0_REG_OFFSET + 28,
98 "SW_SHARE1_OUTPUT_N registers must be contiguous.");
105 1 << KEYMGR_DPE_ERR_CODE_INVALID_OP_BIT,
106 "Layout of ERR_CODE register changed.");
108 1 << KEYMGR_DPE_ERR_CODE_INVALID_KMAC_INPUT_BIT,
109 "Layout of ERR_CODE register changed.");
116 KEYMGR_DPE_CONTROL_SHADOWED_DEST_SEL_VALUE_AES,
117 "Key destination macros must match the values from its enum.");
119 KEYMGR_DPE_CONTROL_SHADOWED_DEST_SEL_VALUE_KMAC,
120 "Key destination macros must match the values from its enum.");
122 KEYMGR_DPE_CONTROL_SHADOWED_DEST_SEL_VALUE_OTBN,
123 "Key destination macros must match the values from its enum.");
128 static_assert(kDifKeymgrDpeStateReset ==
129 KEYMGR_DPE_WORKING_STATE_STATE_VALUE_RESET,
130 "Keymgr_DPE reported FSM state and SW enums must match.");
131 static_assert(kDifKeymgrDpeStateAvailable ==
132 KEYMGR_DPE_WORKING_STATE_STATE_VALUE_AVAILABLE,
133 "Keymgr_DPE reported FSM state and SW enums must match.");
134 static_assert(kDifKeymgrDpeStateDisabled ==
135 KEYMGR_DPE_WORKING_STATE_STATE_VALUE_DISABLED,
136 "Keymgr_DPE reported FSM state and SW enums must match.");
137 static_assert(kDifKeymgrDpeStateInvalid ==
138 KEYMGR_DPE_WORKING_STATE_STATE_VALUE_INVALID,
139 "Keymgr_DPE reported FSM state and SW enums must match.");
148 uint32_t reg_op_status = mmio_region_read32(keymgr_dpe->
base_addr,
149 KEYMGR_DPE_OP_STATUS_REG_OFFSET);
151 KEYMGR_DPE_OP_STATUS_STATUS_VALUE_IDLE) {
154 uint32_t reg_cfg_regwen = mmio_region_read32(
155 keymgr_dpe->
base_addr, KEYMGR_DPE_CFG_REGWEN_REG_OFFSET);
160 uint32_t slot_dst_sel) {
161 if (keymgr_dpe == NULL) {
165 if (!is_ready(keymgr_dpe)) {
170 KEYMGR_DPE_CONTROL_SHADOWED_REG_RESVAL,
171 KEYMGR_DPE_CONTROL_SHADOWED_SLOT_DST_SEL_FIELD, slot_dst_sel);
173 reg_control, KEYMGR_DPE_CONTROL_SHADOWED_OPERATION_FIELD,
174 KEYMGR_DPE_CONTROL_SHADOWED_OPERATION_VALUE_ADVANCE);
175 mmio_region_write32_shadowed(keymgr_dpe->
base_addr,
176 KEYMGR_DPE_CONTROL_SHADOWED_REG_OFFSET,
179 mmio_region_write32(keymgr_dpe->
base_addr, KEYMGR_DPE_START_REG_OFFSET,
180 1 << KEYMGR_DPE_START_EN_BIT);
188 if (keymgr_dpe == NULL || params == NULL) {
192 if (!is_ready(keymgr_dpe)) {
198 uint32_t slot_policy_regwen = mmio_region_read32(
199 keymgr_dpe->
base_addr, KEYMGR_DPE_SLOT_POLICY_REGWEN_REG_OFFSET);
201 KEYMGR_DPE_SLOT_POLICY_REGWEN_EN_BIT)) {
205 uint32_t reg_max_key_ver_wen = mmio_region_read32(
206 keymgr_dpe->
base_addr, KEYMGR_DPE_MAX_KEY_VER_REGWEN_REG_OFFSET);
208 KEYMGR_DPE_MAX_KEY_VER_REGWEN_EN_BIT)) {
212 uint32_t sw_binding_regwen = mmio_region_read32(
213 keymgr_dpe->
base_addr, KEYMGR_DPE_SW_BINDING_REGWEN_REG_OFFSET);
215 KEYMGR_DPE_SW_BINDING_REGWEN_EN_BIT)) {
221 mmio_region_write32(keymgr_dpe->
base_addr, KEYMGR_DPE_SLOT_POLICY_REG_OFFSET,
223 mmio_region_write32(keymgr_dpe->
base_addr,
224 KEYMGR_DPE_SLOT_POLICY_REGWEN_REG_OFFSET, 0);
226 mmio_region_write32_shadowed(keymgr_dpe->
base_addr,
227 KEYMGR_DPE_MAX_KEY_VER_SHADOWED_REG_OFFSET,
229 mmio_region_write32(keymgr_dpe->
base_addr,
230 KEYMGR_DPE_MAX_KEY_VER_REGWEN_REG_OFFSET, 0);
233 keymgr_dpe->
base_addr, KEYMGR_DPE_SW_BINDING_0_REG_OFFSET,
235 mmio_region_write32(keymgr_dpe->
base_addr,
236 KEYMGR_DPE_SW_BINDING_REGWEN_REG_OFFSET, 0);
239 KEYMGR_DPE_CONTROL_SHADOWED_REG_RESVAL,
240 KEYMGR_DPE_CONTROL_SHADOWED_SLOT_SRC_SEL_FIELD, params->
slot_src_sel);
242 reg_control, KEYMGR_DPE_CONTROL_SHADOWED_SLOT_DST_SEL_FIELD,
245 reg_control, KEYMGR_DPE_CONTROL_SHADOWED_OPERATION_FIELD,
246 KEYMGR_DPE_CONTROL_SHADOWED_OPERATION_VALUE_ADVANCE);
247 mmio_region_write32_shadowed(keymgr_dpe->
base_addr,
248 KEYMGR_DPE_CONTROL_SHADOWED_REG_OFFSET,
250 mmio_region_write32(keymgr_dpe->
base_addr, KEYMGR_DPE_START_REG_OFFSET,
251 1 << KEYMGR_DPE_START_EN_BIT);
259 if (keymgr_dpe == NULL) {
263 if (!is_ready(keymgr_dpe)) {
268 KEYMGR_DPE_CONTROL_SHADOWED_REG_RESVAL,
269 KEYMGR_DPE_CONTROL_SHADOWED_SLOT_DST_SEL_FIELD, params->
slot_dst_sel);
271 reg_control, KEYMGR_DPE_CONTROL_SHADOWED_OPERATION_FIELD,
272 KEYMGR_DPE_CONTROL_SHADOWED_OPERATION_VALUE_ERASE_SLOT);
273 mmio_region_write32_shadowed(keymgr_dpe->
base_addr,
274 KEYMGR_DPE_CONTROL_SHADOWED_REG_OFFSET,
276 mmio_region_write32(keymgr_dpe->
base_addr, KEYMGR_DPE_START_REG_OFFSET,
277 1 << KEYMGR_DPE_START_EN_BIT);
285 if (keymgr_dpe == NULL || params == NULL) {
289 if (!is_ready(keymgr_dpe)) {
294 KEYMGR_DPE_CONTROL_SHADOWED_REG_RESVAL,
295 KEYMGR_DPE_CONTROL_SHADOWED_DEST_SEL_FIELD, params->
key_dest);
297 reg_control, KEYMGR_DPE_CONTROL_SHADOWED_SLOT_SRC_SEL_FIELD,
302 reg_control, KEYMGR_DPE_CONTROL_SHADOWED_OPERATION_FIELD,
303 KEYMGR_DPE_CONTROL_SHADOWED_OPERATION_VALUE_GENERATE_HW_OUTPUT);
306 reg_control, KEYMGR_DPE_CONTROL_SHADOWED_OPERATION_FIELD,
307 KEYMGR_DPE_CONTROL_SHADOWED_OPERATION_VALUE_GENERATE_SW_OUTPUT);
309 mmio_region_write32_shadowed(keymgr_dpe->
base_addr,
310 KEYMGR_DPE_CONTROL_SHADOWED_REG_OFFSET,
315 KEYMGR_DPE_SALT_0_REG_OFFSET, params->
salt,
316 sizeof(params->
salt));
317 mmio_region_write32(keymgr_dpe->
base_addr, KEYMGR_DPE_KEY_VERSION_REG_OFFSET,
321 mmio_region_write32(keymgr_dpe->
base_addr, KEYMGR_DPE_START_REG_OFFSET,
322 1 << KEYMGR_DPE_START_EN_BIT);
329 if (keymgr_dpe == NULL || output == NULL) {
334 KEYMGR_DPE_SW_SHARE0_OUTPUT_0_REG_OFFSET,
335 output->value[0],
sizeof(output->value[0]));
337 KEYMGR_DPE_SW_SHARE1_OUTPUT_0_REG_OFFSET,
338 output->value[1],
sizeof(output->value[1]));
346 if (keymgr_dpe == NULL || status_codes == NULL) {
351 uint32_t reg_op_status = mmio_region_read32(keymgr_dpe->
base_addr,
352 KEYMGR_DPE_OP_STATUS_REG_OFFSET);
354 bool is_idle =
false;
355 bool has_error =
false;
356 switch (reg_op_status) {
357 case KEYMGR_DPE_OP_STATUS_STATUS_VALUE_IDLE:
360 case KEYMGR_DPE_OP_STATUS_STATUS_VALUE_DONE_SUCCESS:
362 mmio_region_write32(keymgr_dpe->
base_addr,
363 KEYMGR_DPE_OP_STATUS_REG_OFFSET, reg_op_status);
365 case KEYMGR_DPE_OP_STATUS_STATUS_VALUE_DONE_ERROR:
368 mmio_region_write32(keymgr_dpe->
base_addr,
369 KEYMGR_DPE_OP_STATUS_REG_OFFSET, reg_op_status);
371 case KEYMGR_DPE_OP_STATUS_STATUS_VALUE_WIP:
380 0, kIdleBitfield, is_idle);
384 uint32_t reg_err_code = mmio_region_read32(keymgr_dpe->
base_addr,
385 KEYMGR_DPE_ERR_CODE_REG_OFFSET);
386 mmio_region_write32(keymgr_dpe->
base_addr, KEYMGR_DPE_ERR_CODE_REG_OFFSET,
389 *status_codes, kErrorBitfield, reg_err_code);
397 if (keymgr_dpe == NULL || state == NULL) {
401 uint32_t reg_state = mmio_region_read32(keymgr_dpe->
base_addr,
402 KEYMGR_DPE_WORKING_STATE_REG_OFFSET);