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 darjeeling.
10 */
11
12#include "dt/dt_rstmgr.h"
13
14
15#include "dt_aon_timer.h"
16#include "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 base_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 .base_addr = {
47 [kDtRstmgrRegBlockCore] = 0x30410000,
48 },
50 .clock = {
58 },
59 .reset = {
62 },
63 .rstmgr_ext = {
64 .sw_rst = {
66 [1] = kDtResetSpiHost0,
67 [2] = kDtResetI2c0,
68 },
69 .hw_req = {
70 [0] = {
71 .inst_id = kDtInstanceIdAonTimerAon,
72 .reset_req = kDtAonTimerResetReqAonTimer,
73 },
74 [1] = {
75 .inst_id = kDtInstanceIdSocProxy,
76 .reset_req = kDtSocProxyResetReqExternal,
77 },
78 [2] = {
79 .inst_id = kDtInstanceIdPwrmgrAon,
80 .reset_req = 0,
81 },
82 [3] = {
84 .reset_req = 0,
85 },
86 [4] = {
87 .inst_id = kDtInstanceIdRvDm,
88 .reset_req = 0,
89 },
90 },
91 },
92 },
93};
94
95/**
96 * Return a pointer to the `dt_rstmgr_desc_t` structure of the requested
97 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
98 * the function) with the provided default value.
99 */
100#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_rstmgr_t)0 || (dt) >= kDtRstmgrCount) return (default); &rstmgr_desc[dt]; })
101
103 if (inst_id >= kDtInstanceIdRstmgrAon && inst_id <= kDtInstanceIdRstmgrAon) {
104 return (dt_rstmgr_t)(inst_id - kDtInstanceIdRstmgrAon);
105 }
106 return (dt_rstmgr_t)0;
107}
108
113
115 dt_rstmgr_t dt,
116 dt_rstmgr_reg_block_t reg_block) {
117 // Return a recognizable address in case of wrong argument.
118 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
119}
120
121
123 dt_rstmgr_t dt,
124 dt_rstmgr_alert_t alert) {
125 return (dt_alert_id_t)((uint32_t)rstmgr_desc[dt].first_alert + (uint32_t)alert);
126}
127
129 dt_rstmgr_t dt,
130 dt_alert_id_t alert) {
131 dt_rstmgr_alert_t count = kDtRstmgrAlertCount;
132 if (alert < rstmgr_desc[dt].first_alert || alert >= rstmgr_desc[dt].first_alert + (dt_alert_id_t)count) {
133 return count;
134 }
135 return (dt_rstmgr_alert_t)(alert - rstmgr_desc[dt].first_alert);
136}
137
138
139
141 dt_rstmgr_t dt,
142 dt_rstmgr_clock_t clk) {
143 // Return the first clock in case of invalid argument.
144 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
145}
146
148 dt_rstmgr_t dt,
149 dt_rstmgr_reset_t rst) {
150 const dt_rstmgr_reset_t count = kDtRstmgrResetCount;
151 if (rst >= count) {
152 return kDtResetUnknown;
153 }
154 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
155}
156
157
158
160 return 3;
161}
162
164 if (idx >= 3) {
165 return kDtResetUnknown;
166 }
167 return TRY_GET_DT(dt, kDtResetUnknown)->rstmgr_ext.sw_rst[idx];
168}
169
170