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#include "dt_aon_timer.h"
15#include "dt_soc_proxy.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[3]; /**< 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] = 0x30410000,
46 },
48 .clock = {
56 },
57 .reset = {
60 },
61 .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)->base_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
157 return 3;
158}
159
161 if (idx >= 3) {
162 return kDtResetUnknown;
163 }
164 return TRY_GET_DT(dt, kDtResetUnknown)->ext.sw_rst[idx];
165}
166