Software APIs
dt_rstmgr.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 rstmgr and top earlgrey.
10 */
11
12#include "dt/dt_rstmgr.h"
13
14#include "dt_sysrst_ctrl.h"
15#include "dt_aon_timer.h"
16
17
18/**
19 * Description of instances.
20 */
21typedef struct dt_desc_rstmgr {
22 dt_instance_id_t inst_id; /**< Instance ID */
23 uint32_t base_addr[kDtRstmgrRegBlockCount]; /**< Base address of each register block */
24 /**
25 * Alert ID of the first Alert of this instance.
26 *
27 * This value is undefined if the block is not connected to the Alert Handler.
28 */
30 dt_clock_t clock[kDtRstmgrClockCount]; /**< Clock signal connected to each clock port */
31 dt_reset_t reset[kDtRstmgrResetCount]; /**< Reset signal connected to each reset port */
32 struct {
33 dt_reset_t sw_rst[8]; /**< List of software resets, in the order of the register fields */
34 dt_rstmgr_reset_req_src_t hw_req[5]; /**< List of hardware reset requests, in the order of the register fields */
35 } ext; /**< Extension */
37
38
39
40
41static const dt_desc_rstmgr_t rstmgr_desc[kDtRstmgrCount] = {
42 [kDtRstmgrAon] = {
43 .inst_id = kDtInstanceIdRstmgrAon,
44 .base_addr = {
45 [kDtRstmgrRegBlockCore] = 0x40410000,
46 },
48 .clock = {
57 },
58 .reset = {
61 },
62 .ext = {
63 .sw_rst = {
65 [1] = kDtResetSpiHost0,
66 [2] = kDtResetSpiHost1,
67 [3] = kDtResetUsb,
68 [4] = kDtResetUsbAon,
69 [5] = kDtResetI2c0,
70 [6] = kDtResetI2c1,
71 [7] = kDtResetI2c2,
72 },
73 .hw_req = {
74 [0] = {
76 .reset_req = kDtSysrstCtrlResetReqRstReq,
77 },
78 [1] = {
79 .inst_id = kDtInstanceIdAonTimerAon,
80 .reset_req = kDtAonTimerResetReqAonTimer,
81 },
82 [2] = {
83 .inst_id = kDtInstanceIdPwrmgrAon,
84 .reset_req = 0,
85 },
86 [3] = {
88 .reset_req = 0,
89 },
90 [4] = {
91 .inst_id = kDtInstanceIdRvDm,
92 .reset_req = 0,
93 },
94 },
95 },
96 },
97};
98
99/**
100 * Return a pointer to the `dt_rstmgr_desc_t` structure of the requested
101 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
102 * the function) with the provided default value.
103 */
104#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_rstmgr_t)0 || (dt) >= kDtRstmgrCount) return (default); &rstmgr_desc[dt]; })
105
107 if (inst_id >= kDtInstanceIdRstmgrAon && inst_id <= kDtInstanceIdRstmgrAon) {
108 return (dt_rstmgr_t)(inst_id - kDtInstanceIdRstmgrAon);
109 }
110 return (dt_rstmgr_t)0;
111}
112
117
119 dt_rstmgr_t dt,
120 dt_rstmgr_reg_block_t reg_block) {
121 // Return a recognizable address in case of wrong argument.
122 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
123}
124
125
127 dt_rstmgr_t dt,
128 dt_rstmgr_alert_t alert) {
129 return (dt_alert_id_t)((uint32_t)rstmgr_desc[dt].first_alert + (uint32_t)alert);
130}
131
133 dt_rstmgr_t dt,
134 dt_alert_id_t alert) {
135 dt_rstmgr_alert_t count = kDtRstmgrAlertCount;
136 if (alert < rstmgr_desc[dt].first_alert || alert >= rstmgr_desc[dt].first_alert + (dt_alert_id_t)count) {
137 return count;
138 }
139 return (dt_rstmgr_alert_t)(alert - rstmgr_desc[dt].first_alert);
140}
141
142
143
145 dt_rstmgr_t dt,
146 dt_rstmgr_clock_t clk) {
147 // Return the first clock in case of invalid argument.
148 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
149}
150
152 dt_rstmgr_t dt,
153 dt_rstmgr_reset_t rst) {
154 const dt_rstmgr_reset_t count = kDtRstmgrResetCount;
155 if (rst >= count) {
156 return kDtResetUnknown;
157 }
158 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
159}
160
161
163 return 8;
164}
165
167 if (idx >= 8) {
168 return kDtResetUnknown;
169 }
170 return TRY_GET_DT(dt, kDtResetUnknown)->ext.sw_rst[idx];
171}
172