Software APIs
dif_rom_ctrl.c
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
6 
7 #include <stdint.h>
8 
11 
12 #include "rom_ctrl_regs.h" // Generated.
13 
14 static_assert(ROM_CTRL_DIGEST_DIGEST_FIELD_WIDTH == 32,
15  "ROM Controller digest register width changed.");
16 static_assert(ROM_CTRL_EXP_DIGEST_DIGEST_FIELD_WIDTH == 32,
17  "ROM Controller expected digest register width changed.");
18 static_assert(ROM_CTRL_DIGEST_7_REG_OFFSET == ROM_CTRL_DIGEST_0_REG_OFFSET + 28,
19  "ROM Controller digest register layout is not consecutive.");
20 static_assert(
21  ROM_CTRL_EXP_DIGEST_7_REG_OFFSET == ROM_CTRL_EXP_DIGEST_0_REG_OFFSET + 28,
22  "ROM Controller expected digest register layout is not consecutive.");
23 
25  const dif_rom_ctrl_t *rom_ctrl,
26  dif_rom_ctrl_fatal_alert_causes_t *alert_causes) {
27  if (rom_ctrl == NULL || alert_causes == NULL) {
28  return kDifBadArg;
29  }
30 
31  *alert_causes = mmio_region_read32(rom_ctrl->base_addr,
32  ROM_CTRL_FATAL_ALERT_CAUSE_REG_OFFSET);
33 
34  return kDifOk;
35 }
36 
38  dif_rom_ctrl_digest_t *digest) {
39  if (rom_ctrl == NULL || digest == NULL) {
40  return kDifBadArg;
41  }
42 
44  rom_ctrl->base_addr, ROM_CTRL_DIGEST_0_REG_OFFSET, digest->digest,
45  ROM_CTRL_DIGEST_MULTIREG_COUNT * sizeof(uint32_t));
46 
47  return kDifOk;
48 }
49 
51  const dif_rom_ctrl_t *rom_ctrl, dif_rom_ctrl_digest_t *expected_digest) {
52  if (rom_ctrl == NULL || expected_digest == NULL) {
53  return kDifBadArg;
54  }
55 
57  rom_ctrl->base_addr, ROM_CTRL_EXP_DIGEST_0_REG_OFFSET,
58  expected_digest->digest,
59  ROM_CTRL_EXP_DIGEST_MULTIREG_COUNT * sizeof(uint32_t));
60 
61  return kDifOk;
62 }