Software APIs
dt_rom_ctrl.c
Go to the documentation of this file.
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//
5// Device table API auto-generated by `dtgen`
6
7/**
8 * @file
9 * @brief Device Tables (DT) for IP rom_ctrl and top darjeeling.
10 */
11
12#include "dt/dt_rom_ctrl.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_rom_ctrl {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t base_addr[kDtRomCtrlRegBlockCount]; /**< Base address of each register block */
22 /**
23 * Alert ID of the first Alert of this instance.
24 *
25 * This value is undefined if the block is not connected to the Alert Handler.
26 */
28 dt_clock_t clock[kDtRomCtrlClockCount]; /**< Clock signal connected to each clock port */
29 dt_reset_t reset[kDtRomCtrlResetCount]; /**< Reset signal connected to each reset port */
31
32
33
34
35static const dt_desc_rom_ctrl_t rom_ctrl_desc[kDtRomCtrlCount] = {
36 [kDtRomCtrl0] = {
37 .inst_id = kDtInstanceIdRomCtrl0,
38 .base_addr = {
39 [kDtRomCtrlRegBlockRom] = 0x00008000,
40 [kDtRomCtrlRegBlockRegs] = 0x211e0000,
41 },
43 .clock = {
45 },
46 .reset = {
48 },
49 },
50 [kDtRomCtrl1] = {
51 .inst_id = kDtInstanceIdRomCtrl1,
52 .base_addr = {
53 [kDtRomCtrlRegBlockRom] = 0x00020000,
54 [kDtRomCtrlRegBlockRegs] = 0x211e1000,
55 },
57 .clock = {
59 },
60 .reset = {
62 },
63 },
64};
65
66/**
67 * Return a pointer to the `dt_rom_ctrl_desc_t` structure of the requested
68 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
69 * the function) with the provided default value.
70 */
71#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_rom_ctrl_t)0 || (dt) >= kDtRomCtrlCount) return (default); &rom_ctrl_desc[dt]; })
72
74 if (inst_id >= kDtInstanceIdRomCtrl0 && inst_id <= kDtInstanceIdRomCtrl1) {
75 return (dt_rom_ctrl_t)(inst_id - kDtInstanceIdRomCtrl0);
76 }
77 return (dt_rom_ctrl_t)0;
78}
79
84
87 dt_rom_ctrl_reg_block_t reg_block) {
88 // Return a recognizable address in case of wrong argument.
89 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
90}
91
92
95 dt_rom_ctrl_alert_t alert) {
96 return (dt_alert_id_t)((uint32_t)rom_ctrl_desc[dt].first_alert + (uint32_t)alert);
97}
98
100 dt_rom_ctrl_t dt,
101 dt_alert_id_t alert) {
102 dt_rom_ctrl_alert_t count = kDtRomCtrlAlertCount;
103 if (alert < rom_ctrl_desc[dt].first_alert || alert >= rom_ctrl_desc[dt].first_alert + (dt_alert_id_t)count) {
104 return count;
105 }
106 return (dt_rom_ctrl_alert_t)(alert - rom_ctrl_desc[dt].first_alert);
107}
108
109
110
112 dt_rom_ctrl_t dt,
114 // Return the first clock in case of invalid argument.
115 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
116}
117
119 dt_rom_ctrl_t dt,
121 const dt_rom_ctrl_reset_t count = kDtRomCtrlResetCount;
122 if (rst >= count) {
123 return kDtResetUnknown;
124 }
125 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
126}
127
128