Software APIs
dt_pwrmgr.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 pwrmgr and top darjeeling.
10 */
11
12#include "hw/top/dt/dt_pwrmgr.h"
13
14
15#include "dt_pinmux.h"
16#include "dt_aon_timer.h"
17#include "dt_soc_proxy.h"
18
19
20
21/**
22 * Description of instances.
23 */
24typedef struct dt_desc_pwrmgr {
25 dt_instance_id_t inst_id; /**< Instance ID */
26 uint32_t reg_addr[kDtPwrmgrRegBlockCount]; /**< Base address of each register block */
27 uint32_t mem_addr[kDtPwrmgrMemoryCount]; /**< Base address of each memory */
28 uint32_t mem_size[kDtPwrmgrMemoryCount]; /**< Size in bytes of each memory */
29 /**
30 * PLIC ID of the first IRQ of this instance
31 *
32 * This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
33 */
35 /**
36 * Alert ID of the first Alert of this instance.
37 *
38 * This value is undefined if the block is not connected to the Alert Handler.
39 */
41 dt_clock_t clock[kDtPwrmgrClockCount]; /**< Clock signal connected to each clock port */
42 dt_reset_t reset[kDtPwrmgrResetCount]; /**< Reset signal connected to each reset port */
43 struct {
44 dt_pwrmgr_wakeup_src_t wakeup_src[4]; /**< List of wakeup sources, in the order of the register fields */
45 dt_pwrmgr_reset_req_src_t rst_reqs[2]; /**< List of reset requests, in the order of the register fields */
46 } pwrmgr_ext; /**< Extension */
48
49
50
51
52static const dt_desc_pwrmgr_t pwrmgr_desc[kDtPwrmgrCount] = {
53 [kDtPwrmgrAon] = {
54 .inst_id = kDtInstanceIdPwrmgrAon,
55 .reg_addr = {
56 [kDtPwrmgrRegBlockCore] = 0x30400000,
57 },
58 .mem_addr = {
59 },
60 .mem_size = {
61 },
64 .clock = {
69 },
70 .reset = {
76 },
77 .pwrmgr_ext = {
78 .wakeup_src = {
79 [0] = {
80 .inst_id = kDtInstanceIdPinmuxAon,
82 },
83 [1] = {
84 .inst_id = kDtInstanceIdAonTimerAon,
86 },
87 [2] = {
88 .inst_id = kDtInstanceIdSocProxy,
90 },
91 [3] = {
92 .inst_id = kDtInstanceIdSocProxy,
94 },
95 },
96 .rst_reqs = {
97 [0] = {
98 .inst_id = kDtInstanceIdAonTimerAon,
99 .reset_req = kDtAonTimerResetReqAonTimer,
100 },
101 [1] = {
102 .inst_id = kDtInstanceIdSocProxy,
103 .reset_req = kDtSocProxyResetReqExternal,
104 },
105 },
106 },
107 },
108};
109
110/**
111 * Return a pointer to the `dt_pwrmgr_desc_t` structure of the requested
112 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
113 * the function) with the provided default value.
114 */
115#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_pwrmgr_t)0 || (dt) >= kDtPwrmgrCount) return (default); &pwrmgr_desc[dt]; })
116
118 if (inst_id >= kDtInstanceIdPwrmgrAon && inst_id <= kDtInstanceIdPwrmgrAon) {
119 return (dt_pwrmgr_t)(inst_id - kDtInstanceIdPwrmgrAon);
120 }
121 return (dt_pwrmgr_t)0;
122}
123
128
130 dt_pwrmgr_t dt,
131 dt_pwrmgr_reg_block_t reg_block) {
132 // Return a recognizable address in case of wrong argument.
133 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
134}
135
137 dt_pwrmgr_t dt,
138 dt_pwrmgr_memory_t mem) {
139 // Return a recognizable address in case of wrong argument.
140 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
141}
142
144 dt_pwrmgr_t dt,
145 dt_pwrmgr_memory_t mem) {
146 // Return an empty size in case of wrong argument.
147 return TRY_GET_DT(dt, 0)->mem_size[mem];
148}
149
151 dt_pwrmgr_t dt,
152 dt_pwrmgr_irq_t irq) {
153 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
154 if (first_irq == kDtPlicIrqIdNone) {
155 return kDtPlicIrqIdNone;
156 }
157 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
158}
159
161 dt_pwrmgr_t dt,
162 dt_plic_irq_id_t irq) {
163 dt_pwrmgr_irq_t count = kDtPwrmgrIrqCount;
164 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
165 if (first_irq == kDtPlicIrqIdNone) {
166 return count;
167 }
168 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
169 return count;
170 }
171 return (dt_pwrmgr_irq_t)(irq - first_irq);
172}
173
174
176 dt_pwrmgr_t dt,
177 dt_pwrmgr_alert_t alert) {
178 return (dt_alert_id_t)((uint32_t)pwrmgr_desc[dt].first_alert + (uint32_t)alert);
179}
180
182 dt_pwrmgr_t dt,
183 dt_alert_id_t alert) {
184 dt_pwrmgr_alert_t count = kDtPwrmgrAlertCount;
185 if (alert < pwrmgr_desc[dt].first_alert || alert >= pwrmgr_desc[dt].first_alert + (dt_alert_id_t)count) {
186 return count;
187 }
188 return (dt_pwrmgr_alert_t)(alert - pwrmgr_desc[dt].first_alert);
189}
190
191
192
194 dt_pwrmgr_t dt,
195 dt_pwrmgr_clock_t clk) {
196 // Return the first clock in case of invalid argument.
197 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
198}
199
201 dt_pwrmgr_t dt,
202 dt_pwrmgr_reset_t rst) {
203 const dt_pwrmgr_reset_t count = kDtPwrmgrResetCount;
204 if (rst >= count) {
205 return kDtResetUnknown;
206 }
207 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
208}
209
210
211
213 return 4;
214}
215
217 dt_pwrmgr_wakeup_src_t invalid = {.inst_id = kDtInstanceIdUnknown, .wakeup = 0};
218 return TRY_GET_DT(dt, invalid)->pwrmgr_ext.wakeup_src[idx];
219}
220
222 return 2;
223}
224
226 dt_pwrmgr_reset_req_src_t invalid = {.inst_id = kDtInstanceIdUnknown, .reset_req = 0};
227 return TRY_GET_DT(dt, invalid)->pwrmgr_ext.rst_reqs[idx];
228}
229
230