Software APIs
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 darjeeling.
10 */
11
12#include "hw/top/dt/rstmgr.h"
13
14
15#include "hw/top/dt/aon_timer.h"
16#include "hw/top/dt/soc_proxy.h"
17
18
19
20/**
21 * Description of instances.
22 */
23typedef struct dt_desc_rstmgr {
24 dt_instance_id_t inst_id; /**< Instance ID */
25 uint32_t reg_addr[kDtRstmgrRegBlockCount]; /**< Base address of each register block */
26 /**
27 * Alert ID of the first Alert of this instance.
28 *
29 * This value is undefined if the block is not connected to the Alert Handler.
30 */
32 dt_clock_t clock[kDtRstmgrClockCount]; /**< Clock signal connected to each clock port */
33 dt_reset_t reset[kDtRstmgrResetCount]; /**< Reset signal connected to each reset port */
34 struct {
35 dt_reset_t sw_rst[3]; /**< List of software resets, in the order of the register fields */
36 dt_rstmgr_reset_req_src_t hw_req[5]; /**< List of hardware reset requests, in the order of the register fields */
37 } rstmgr_ext; /**< Extension */
39
40
41
42
43static const dt_desc_rstmgr_t rstmgr_desc[kDtRstmgrCount] = {
44 [kDtRstmgrAon] = {
45 .inst_id = kDtInstanceIdRstmgrAon,
46 .reg_addr = {
47 [kDtRstmgrRegBlockCore] = 0x30410000,
48 },
50 .clock = {
56 },
57 .reset = {
60 },
61 .rstmgr_ext = {
62 .sw_rst = {
64 [1] = kDtResetSpiHost0,
65 [2] = kDtResetI2c0,
66 },
67 .hw_req = {
68 [0] = {
69 .inst_id = kDtInstanceIdAonTimerAon,
70 .reset_req = kDtAonTimerResetReqAonTimer,
71 },
72 [1] = {
73 .inst_id = kDtInstanceIdSocProxy,
74 .reset_req = kDtSocProxyResetReqExternal,
75 },
76 [2] = {
77 .inst_id = kDtInstanceIdPwrmgrAon,
78 .reset_req = 0,
79 },
80 [3] = {
82 .reset_req = 0,
83 },
84 [4] = {
85 .inst_id = kDtInstanceIdRvDm,
86 .reset_req = 0,
87 },
88 },
89 },
90 },
91};
92
93/**
94 * Return a pointer to the `dt_rstmgr_desc_t` structure of the requested
95 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
96 * the function) with the provided default value.
97 */
98#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_rstmgr_t)0 || (dt) >= kDtRstmgrCount) return (default); &rstmgr_desc[dt]; })
99
101 if (inst_id >= kDtInstanceIdRstmgrAon && inst_id <= kDtInstanceIdRstmgrAon) {
102 return (dt_rstmgr_t)(inst_id - kDtInstanceIdRstmgrAon);
103 }
104 return (dt_rstmgr_t)0;
105}
106
111
113 dt_rstmgr_t dt,
114 dt_rstmgr_reg_block_t reg_block) {
115 // Return a recognizable address in case of wrong argument.
116 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
117}
118
119
121 dt_rstmgr_t dt,
122 dt_rstmgr_alert_t alert) {
123 return (dt_alert_id_t)((uint32_t)rstmgr_desc[dt].first_alert + (uint32_t)alert);
124}
125
127 dt_rstmgr_t dt,
128 dt_alert_id_t alert) {
129 dt_rstmgr_alert_t count = kDtRstmgrAlertCount;
130 if (alert < rstmgr_desc[dt].first_alert || alert >= rstmgr_desc[dt].first_alert + (dt_alert_id_t)count) {
131 return count;
132 }
133 return (dt_rstmgr_alert_t)(alert - rstmgr_desc[dt].first_alert);
134}
135
136
137
139 dt_rstmgr_t dt,
140 dt_rstmgr_clock_t clk) {
141 // Return the first clock in case of invalid argument.
142 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
143}
144
146 dt_rstmgr_t dt,
147 dt_rstmgr_reset_t rst) {
148 const dt_rstmgr_reset_t count = kDtRstmgrResetCount;
149 if (rst >= count) {
150 return kDtResetUnknown;
151 }
152 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
153}
154
155
156
158 return 3;
159}
160
162 if (idx >= 3) {
163 return kDtResetUnknown;
164 }
165 return TRY_GET_DT(dt, kDtResetUnknown)->rstmgr_ext.sw_rst[idx];
166}
167
169 return 5;
170}
171
173 dt_rstmgr_reset_req_src_t invalid_req = {
174 .inst_id = kDtInstanceIdUnknown,
175 .reset_req = kDtResetUnknown,
176 };
177 if (idx >= 5) {
178 return invalid_req;
179 }
180 return TRY_GET_DT(dt, invalid_req)->rstmgr_ext.hw_req[idx];
181}
182
183