Software APIs
dt_flash_ctrl.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 flash_ctrl and top earlgrey.
10 */
11
12#include "hw/top/dt/dt_flash_ctrl.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_flash_ctrl {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t reg_addr[kDtFlashCtrlRegBlockCount]; /**< Base address of each register block */
22 uint32_t mem_addr[kDtFlashCtrlMemoryCount]; /**< Base address of each memory */
23 uint32_t mem_size[kDtFlashCtrlMemoryCount]; /**< Size in bytes of each memory */
24 /**
25 * PLIC ID of the first IRQ of this instance
26 *
27 * This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
28 */
30 /**
31 * Alert ID of the first Alert of this instance.
32 *
33 * This value is undefined if the block is not connected to the Alert Handler.
34 */
36 dt_clock_t clock[kDtFlashCtrlClockCount]; /**< Clock signal connected to each clock port */
37 dt_reset_t reset[kDtFlashCtrlResetCount]; /**< Reset signal connected to each reset port */
38 dt_periph_io_t periph_io[kDtFlashCtrlPeriphIoCount]; /**< Description of each peripheral I/O */
40
41
42
43
44static const dt_desc_flash_ctrl_t flash_ctrl_desc[kDtFlashCtrlCount] = {
45 [kDtFlashCtrl] = {
46 .inst_id = kDtInstanceIdFlashCtrl,
47 .reg_addr = {
48 [kDtFlashCtrlRegBlockCore] = 0x41000000,
49 [kDtFlashCtrlRegBlockPrim] = 0x41008000,
50 },
51 .mem_addr = {
52 [kDtFlashCtrlMemoryMem] = 0x20000000,
53 },
54 .mem_size = {
55 [kDtFlashCtrlMemoryMem] = 0x100000,
56 },
59 .clock = {
62 },
63 .reset = {
66 },
67 .periph_io = {
68 [kDtFlashCtrlPeriphIoTck] = {
69 .__internal = {
70 .type = kDtPeriphIoTypeMio,
71 .dir = kDtPeriphIoDirIn,
72 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInFlashCtrlTck,
73 .outsel_or_dt_pad = 0,
74 },
75 },
76 [kDtFlashCtrlPeriphIoTms] = {
77 .__internal = {
78 .type = kDtPeriphIoTypeMio,
79 .dir = kDtPeriphIoDirIn,
80 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInFlashCtrlTms,
81 .outsel_or_dt_pad = 0,
82 },
83 },
84 [kDtFlashCtrlPeriphIoTdi] = {
85 .__internal = {
86 .type = kDtPeriphIoTypeMio,
87 .dir = kDtPeriphIoDirIn,
88 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInFlashCtrlTdi,
89 .outsel_or_dt_pad = 0,
90 },
91 },
92 [kDtFlashCtrlPeriphIoTdo] = {
93 .__internal = {
94 .type = kDtPeriphIoTypeMio,
95 .dir = kDtPeriphIoDirOut,
96 .periph_input_or_direct_pad = 0,
97 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselFlashCtrlTdo,
98 },
99 },
100 },
101 },
102};
103
104/**
105 * Return a pointer to the `dt_flash_ctrl_desc_t` structure of the requested
106 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
107 * the function) with the provided default value.
108 */
109#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_flash_ctrl_t)0 || (dt) >= kDtFlashCtrlCount) return (default); &flash_ctrl_desc[dt]; })
110
117
122
125 dt_flash_ctrl_reg_block_t reg_block) {
126 // Return a recognizable address in case of wrong argument.
127 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
128}
129
133 // Return a recognizable address in case of wrong argument.
134 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
135}
136
140 // Return an empty size in case of wrong argument.
141 return TRY_GET_DT(dt, 0)->mem_size[mem];
142}
143
147 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
148 if (first_irq == kDtPlicIrqIdNone) {
149 return kDtPlicIrqIdNone;
150 }
151 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
152}
153
156 dt_plic_irq_id_t irq) {
157 dt_flash_ctrl_irq_t count = kDtFlashCtrlIrqCount;
158 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
159 if (first_irq == kDtPlicIrqIdNone) {
160 return count;
161 }
162 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
163 return count;
164 }
165 return (dt_flash_ctrl_irq_t)(irq - first_irq);
166}
167
168
171 dt_flash_ctrl_alert_t alert) {
172 return (dt_alert_id_t)((uint32_t)flash_ctrl_desc[dt].first_alert + (uint32_t)alert);
173}
174
177 dt_alert_id_t alert) {
178 dt_flash_ctrl_alert_t count = kDtFlashCtrlAlertCount;
179 if (alert < flash_ctrl_desc[dt].first_alert || alert >= flash_ctrl_desc[dt].first_alert + (dt_alert_id_t)count) {
180 return count;
181 }
182 return (dt_flash_ctrl_alert_t)(alert - flash_ctrl_desc[dt].first_alert);
183}
184
185
189 // Return a harmless value in case of wrong argument.
190 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
191}
192
196 // Return the first clock in case of invalid argument.
197 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
198}
199
203 const dt_flash_ctrl_reset_t count = kDtFlashCtrlResetCount;
204 if (rst >= count) {
205 return kDtResetUnknown;
206 }
207 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
208}
209
210