11 #include "keymgr_regs.h"
19 KEYMGR_SIDELOAD_CLEAR_VAL_VALUE_NONE);
21 KEYMGR_SIDELOAD_CLEAR_VAL_VALUE_AES);
23 KEYMGR_SIDELOAD_CLEAR_VAL_VALUE_KMAC);
25 KEYMGR_SIDELOAD_CLEAR_VAL_VALUE_OTBN);
27 KEYMGR_SIDELOAD_CLEAR_VAL_MASK);
34 static_assert(KEYMGR_SEALING_SW_BINDING_1_REG_OFFSET ==
35 KEYMGR_SEALING_SW_BINDING_0_REG_OFFSET + 4,
36 "SEALING_SW_BINDING_N registers must be contiguous.");
37 static_assert(KEYMGR_SEALING_SW_BINDING_2_REG_OFFSET ==
38 KEYMGR_SEALING_SW_BINDING_0_REG_OFFSET + 8,
39 "SEALING_SW_BINDING_N registers must be contiguous.");
40 static_assert(KEYMGR_SEALING_SW_BINDING_3_REG_OFFSET ==
41 KEYMGR_SEALING_SW_BINDING_0_REG_OFFSET + 12,
42 "SEALING_SW_BINDING_N registers must be contiguous.");
43 static_assert(KEYMGR_SEALING_SW_BINDING_4_REG_OFFSET ==
44 KEYMGR_SEALING_SW_BINDING_0_REG_OFFSET + 16,
45 "SEALING_SW_BINDING_N registers must be contiguous.");
46 static_assert(KEYMGR_SEALING_SW_BINDING_5_REG_OFFSET ==
47 KEYMGR_SEALING_SW_BINDING_0_REG_OFFSET + 20,
48 "SEALING_SW_BINDING_N registers must be contiguous.");
49 static_assert(KEYMGR_SEALING_SW_BINDING_6_REG_OFFSET ==
50 KEYMGR_SEALING_SW_BINDING_0_REG_OFFSET + 24,
51 "SEALING_SW_BINDING_N registers must be contiguous.");
52 static_assert(KEYMGR_SEALING_SW_BINDING_7_REG_OFFSET ==
53 KEYMGR_SEALING_SW_BINDING_0_REG_OFFSET + 28,
54 "SEALING_SW_BINDING_N registers must be contiguous.");
56 static_assert(KEYMGR_SALT_1_REG_OFFSET == KEYMGR_SALT_0_REG_OFFSET + 4,
57 "SALT_N registers must be contiguous.");
58 static_assert(KEYMGR_SALT_2_REG_OFFSET == KEYMGR_SALT_0_REG_OFFSET + 8,
59 "SALT_N registers must be contiguous.");
60 static_assert(KEYMGR_SALT_3_REG_OFFSET == KEYMGR_SALT_0_REG_OFFSET + 12,
61 "SALT_N registers must be contiguous.");
62 static_assert(KEYMGR_SALT_4_REG_OFFSET == KEYMGR_SALT_0_REG_OFFSET + 16,
63 "SALT_N registers must be contiguous.");
64 static_assert(KEYMGR_SALT_5_REG_OFFSET == KEYMGR_SALT_0_REG_OFFSET + 20,
65 "SALT_N registers must be contiguous.");
66 static_assert(KEYMGR_SALT_6_REG_OFFSET == KEYMGR_SALT_0_REG_OFFSET + 24,
67 "SALT_N registers must be contiguous.");
68 static_assert(KEYMGR_SALT_7_REG_OFFSET == KEYMGR_SALT_0_REG_OFFSET + 28,
69 "SALT_N registers must be contiguous.");
71 static_assert(KEYMGR_SW_SHARE0_OUTPUT_1_REG_OFFSET ==
72 KEYMGR_SW_SHARE0_OUTPUT_0_REG_OFFSET + 4,
73 "SW_SHARE0_OUTPUT_N registers must be contiguous.");
74 static_assert(KEYMGR_SW_SHARE0_OUTPUT_2_REG_OFFSET ==
75 KEYMGR_SW_SHARE0_OUTPUT_0_REG_OFFSET + 8,
76 "SW_SHARE0_OUTPUT_N registers must be contiguous.");
77 static_assert(KEYMGR_SW_SHARE0_OUTPUT_3_REG_OFFSET ==
78 KEYMGR_SW_SHARE0_OUTPUT_0_REG_OFFSET + 12,
79 "SW_SHARE0_OUTPUT_N registers must be contiguous.");
80 static_assert(KEYMGR_SW_SHARE0_OUTPUT_4_REG_OFFSET ==
81 KEYMGR_SW_SHARE0_OUTPUT_0_REG_OFFSET + 16,
82 "SW_SHARE0_OUTPUT_N registers must be contiguous.");
83 static_assert(KEYMGR_SW_SHARE0_OUTPUT_5_REG_OFFSET ==
84 KEYMGR_SW_SHARE0_OUTPUT_0_REG_OFFSET + 20,
85 "SW_SHARE0_OUTPUT_N registers must be contiguous.");
86 static_assert(KEYMGR_SW_SHARE0_OUTPUT_6_REG_OFFSET ==
87 KEYMGR_SW_SHARE0_OUTPUT_0_REG_OFFSET + 24,
88 "SW_SHARE0_OUTPUT_N registers must be contiguous.");
89 static_assert(KEYMGR_SW_SHARE0_OUTPUT_7_REG_OFFSET ==
90 KEYMGR_SW_SHARE0_OUTPUT_0_REG_OFFSET + 28,
91 "SW_SHARE0_OUTPUT_N registers must be contiguous.");
93 static_assert(KEYMGR_SW_SHARE1_OUTPUT_1_REG_OFFSET ==
94 KEYMGR_SW_SHARE1_OUTPUT_0_REG_OFFSET + 4,
95 "SW_SHARE1_OUTPUT_N registers must be contiguous.");
96 static_assert(KEYMGR_SW_SHARE1_OUTPUT_2_REG_OFFSET ==
97 KEYMGR_SW_SHARE1_OUTPUT_0_REG_OFFSET + 8,
98 "SW_SHARE1_OUTPUT_N registers must be contiguous.");
99 static_assert(KEYMGR_SW_SHARE1_OUTPUT_3_REG_OFFSET ==
100 KEYMGR_SW_SHARE1_OUTPUT_0_REG_OFFSET + 12,
101 "SW_SHARE1_OUTPUT_N registers must be contiguous.");
102 static_assert(KEYMGR_SW_SHARE1_OUTPUT_4_REG_OFFSET ==
103 KEYMGR_SW_SHARE1_OUTPUT_0_REG_OFFSET + 16,
104 "SW_SHARE1_OUTPUT_N registers must be contiguous.");
105 static_assert(KEYMGR_SW_SHARE1_OUTPUT_5_REG_OFFSET ==
106 KEYMGR_SW_SHARE1_OUTPUT_0_REG_OFFSET + 20,
107 "SW_SHARE1_OUTPUT_N registers must be contiguous.");
108 static_assert(KEYMGR_SW_SHARE1_OUTPUT_6_REG_OFFSET ==
109 KEYMGR_SW_SHARE1_OUTPUT_0_REG_OFFSET + 24,
110 "SW_SHARE1_OUTPUT_N registers must be contiguous.");
111 static_assert(KEYMGR_SW_SHARE1_OUTPUT_7_REG_OFFSET ==
112 KEYMGR_SW_SHARE1_OUTPUT_0_REG_OFFSET + 28,
113 "SW_SHARE1_OUTPUT_N registers must be contiguous.");
120 1 << KEYMGR_ERR_CODE_INVALID_OP_BIT,
121 "Layout of ERR_CODE register changed.");
123 1 << KEYMGR_ERR_CODE_INVALID_KMAC_INPUT_BIT,
124 "Layout of ERR_CODE register changed.");
133 uint32_t reg_op_status =
134 mmio_region_read32(keymgr->
base_addr, KEYMGR_OP_STATUS_REG_OFFSET);
136 KEYMGR_OP_STATUS_STATUS_VALUE_IDLE) {
139 uint32_t reg_cfg_regwen =
140 mmio_region_read32(keymgr->
base_addr, KEYMGR_CFG_REGWEN_REG_OFFSET);
170 static bool get_max_key_version_reg_info_for_next_state(
173 case KEYMGR_WORKING_STATE_STATE_VALUE_INIT:
176 .reg_offset = KEYMGR_MAX_CREATOR_KEY_VER_SHADOWED_REG_OFFSET,
177 .wen_reg_offset = KEYMGR_MAX_CREATOR_KEY_VER_REGWEN_REG_OFFSET,
178 .wen_bit_index = KEYMGR_MAX_CREATOR_KEY_VER_REGWEN_EN_BIT,
181 case KEYMGR_WORKING_STATE_STATE_VALUE_CREATOR_ROOT_KEY:
184 .reg_offset = KEYMGR_MAX_OWNER_INT_KEY_VER_SHADOWED_REG_OFFSET,
185 .wen_reg_offset = KEYMGR_MAX_OWNER_INT_KEY_VER_REGWEN_REG_OFFSET,
186 .wen_bit_index = KEYMGR_MAX_OWNER_INT_KEY_VER_REGWEN_EN_BIT,
189 case KEYMGR_WORKING_STATE_STATE_VALUE_OWNER_INTERMEDIATE_KEY:
192 .reg_offset = KEYMGR_MAX_OWNER_KEY_VER_SHADOWED_REG_OFFSET,
193 .wen_reg_offset = KEYMGR_MAX_OWNER_KEY_VER_REGWEN_REG_OFFSET,
194 .wen_bit_index = KEYMGR_MAX_OWNER_KEY_VER_REGWEN_EN_BIT,
197 case KEYMGR_WORKING_STATE_STATE_VALUE_RESET:
198 case KEYMGR_WORKING_STATE_STATE_VALUE_OWNER_KEY:
199 case KEYMGR_WORKING_STATE_STATE_VALUE_DISABLED:
200 case KEYMGR_WORKING_STATE_STATE_VALUE_INVALID:
240 0, KEYMGR_CONTROL_SHADOWED_DEST_SEL_FIELD, params.
dest);
242 reg_control, KEYMGR_CONTROL_SHADOWED_OPERATION_FIELD, params.
op);
246 .index = KEYMGR_CONTROL_SHADOWED_CDI_SEL_BIT},
248 mmio_region_write32_shadowed(keymgr->
base_addr,
249 KEYMGR_CONTROL_SHADOWED_REG_OFFSET, reg_control);
250 mmio_region_write32(keymgr->
base_addr, KEYMGR_START_REG_OFFSET,
251 1 << KEYMGR_START_EN_BIT);
256 if (keymgr == NULL) {
263 mmio_region_write32_shadowed(
264 keymgr->
base_addr, KEYMGR_RESEED_INTERVAL_SHADOWED_REG_OFFSET, reg_val);
271 if (keymgr == NULL) {
275 if (!is_ready(keymgr)) {
282 uint32_t reg_working_state =
283 mmio_region_read32(keymgr->
base_addr, KEYMGR_WORKING_STATE_REG_OFFSET);
284 if (!get_max_key_version_reg_info_for_next_state(
286 KEYMGR_WORKING_STATE_STATE_FIELD)),
287 &max_key_ver_reg_info)) {
294 if (params == NULL) {
299 uint32_t reg_sw_binding_wen = mmio_region_read32(
300 keymgr->
base_addr, KEYMGR_SW_BINDING_REGWEN_REG_OFFSET);
302 KEYMGR_SW_BINDING_REGWEN_EN_BIT)) {
307 uint32_t reg_max_key_ver_wen = mmio_region_read32(
317 keymgr->
base_addr, KEYMGR_SEALING_SW_BINDING_0_REG_OFFSET,
319 mmio_region_write32(keymgr->
base_addr, KEYMGR_SW_BINDING_REGWEN_REG_OFFSET,
323 mmio_region_write32_shadowed(keymgr->
base_addr,
328 }
else if (params != NULL) {
333 start_operation(keymgr,
335 .dest = KEYMGR_CONTROL_SHADOWED_DEST_SEL_VALUE_NONE,
336 .op = KEYMGR_CONTROL_SHADOWED_OPERATION_VALUE_ADVANCE,
343 if (keymgr == NULL) {
347 if (!is_ready(keymgr)) {
352 start_operation(keymgr,
354 .dest = KEYMGR_CONTROL_SHADOWED_DEST_SEL_VALUE_NONE,
355 .op = KEYMGR_CONTROL_SHADOWED_OPERATION_VALUE_ADVANCE,
362 if (keymgr == NULL) {
366 if (!is_ready(keymgr)) {
371 start_operation(keymgr,
373 .dest = KEYMGR_CONTROL_SHADOWED_DEST_SEL_VALUE_NONE,
374 .op = KEYMGR_CONTROL_SHADOWED_OPERATION_VALUE_DISABLE,
382 if (keymgr == NULL || status_codes == NULL) {
387 uint32_t reg_op_status =
388 mmio_region_read32(keymgr->
base_addr, KEYMGR_OP_STATUS_REG_OFFSET);
390 bool is_idle =
false;
391 bool has_error =
false;
392 switch (reg_op_status) {
393 case KEYMGR_OP_STATUS_STATUS_VALUE_IDLE:
396 case KEYMGR_OP_STATUS_STATUS_VALUE_DONE_SUCCESS:
398 mmio_region_write32(keymgr->
base_addr, KEYMGR_OP_STATUS_REG_OFFSET,
401 case KEYMGR_OP_STATUS_STATUS_VALUE_DONE_ERROR:
404 mmio_region_write32(keymgr->
base_addr, KEYMGR_OP_STATUS_REG_OFFSET,
407 case KEYMGR_OP_STATUS_STATUS_VALUE_WIP:
420 uint32_t reg_err_code =
421 mmio_region_read32(keymgr->
base_addr, KEYMGR_ERR_CODE_REG_OFFSET);
422 mmio_region_write32(keymgr->
base_addr, KEYMGR_ERR_CODE_REG_OFFSET,
430 if (reg_err_code > kErrorBitfield.
mask || reg_err_code == 0) {
434 *status_codes, kErrorBitfield, reg_err_code);
442 if (keymgr == NULL || state == NULL) {
447 mmio_region_read32(keymgr->
base_addr, KEYMGR_WORKING_STATE_REG_OFFSET);
450 case KEYMGR_WORKING_STATE_STATE_VALUE_RESET:
453 case KEYMGR_WORKING_STATE_STATE_VALUE_INIT:
456 case KEYMGR_WORKING_STATE_STATE_VALUE_CREATOR_ROOT_KEY:
459 case KEYMGR_WORKING_STATE_STATE_VALUE_OWNER_INTERMEDIATE_KEY:
462 case KEYMGR_WORKING_STATE_STATE_VALUE_OWNER_KEY:
465 case KEYMGR_WORKING_STATE_STATE_VALUE_DISABLED:
468 case KEYMGR_WORKING_STATE_STATE_VALUE_INVALID:
478 if (keymgr == NULL) {
482 if (!is_ready(keymgr)) {
486 start_operation(keymgr,
488 .dest = KEYMGR_CONTROL_SHADOWED_DEST_SEL_VALUE_NONE,
489 .op = KEYMGR_CONTROL_SHADOWED_OPERATION_VALUE_GENERATE_ID,
497 if (keymgr == NULL) {
502 switch (params.
dest) {
505 .
dest = KEYMGR_CONTROL_SHADOWED_DEST_SEL_VALUE_NONE,
506 .op = KEYMGR_CONTROL_SHADOWED_OPERATION_VALUE_GENERATE_SW_OUTPUT,
511 .
dest = KEYMGR_CONTROL_SHADOWED_DEST_SEL_VALUE_AES,
512 .op = KEYMGR_CONTROL_SHADOWED_OPERATION_VALUE_GENERATE_HW_OUTPUT,
517 .
dest = KEYMGR_CONTROL_SHADOWED_DEST_SEL_VALUE_KMAC,
518 .op = KEYMGR_CONTROL_SHADOWED_OPERATION_VALUE_GENERATE_HW_OUTPUT,
523 .
dest = KEYMGR_CONTROL_SHADOWED_DEST_SEL_VALUE_OTBN,
524 .op = KEYMGR_CONTROL_SHADOWED_OPERATION_VALUE_GENERATE_HW_OUTPUT,
531 if (!is_ready(keymgr)) {
538 mmio_region_write32(keymgr->
base_addr, KEYMGR_KEY_VERSION_REG_OFFSET,
541 start_operation(keymgr, hw_op_params);
553 ? kDifKeyMgrSideLoadClearAll
554 : kDifKeyMgrSideLoadClearNone;
556 mmio_region_write32(keymgr->
base_addr, KEYMGR_SIDELOAD_CLEAR_REG_OFFSET, val);
563 if (keymgr == NULL || state == NULL) {
568 mmio_region_read32(keymgr->
base_addr, KEYMGR_SIDELOAD_CLEAR_REG_OFFSET);
576 if (keymgr == NULL || output == NULL) {
581 KEYMGR_SW_SHARE0_OUTPUT_0_REG_OFFSET,
582 output->value[0],
sizeof(output->value[0]));
584 KEYMGR_SW_SHARE1_OUTPUT_0_REG_OFFSET,
585 output->value[1],
sizeof(output->value[1]));
592 if (keymgr == NULL || output == NULL) {
597 KEYMGR_SEALING_SW_BINDING_0_REG_OFFSET,
601 keymgr->
base_addr, KEYMGR_ATTEST_SW_BINDING_0_REG_OFFSET,
609 if (keymgr == NULL || versions == NULL) {
614 keymgr->
base_addr, KEYMGR_MAX_CREATOR_KEY_VER_SHADOWED_REG_OFFSET);
616 keymgr->
base_addr, KEYMGR_MAX_OWNER_INT_KEY_VER_SHADOWED_REG_OFFSET);
618 keymgr->
base_addr, KEYMGR_MAX_OWNER_KEY_VER_SHADOWED_REG_OFFSET);