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 englishbreakfast.
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 dt_clock_t clock[kDtFlashCtrlClockCount]; /**< Clock signal connected to each clock port */
31 dt_reset_t reset[kDtFlashCtrlResetCount]; /**< Reset signal connected to each reset port */
32 dt_periph_io_t periph_io[kDtFlashCtrlPeriphIoCount]; /**< Description of each peripheral I/O */
34
35
36
37
38static const dt_desc_flash_ctrl_t flash_ctrl_desc[kDtFlashCtrlCount] = {
39 [kDtFlashCtrl] = {
40 .inst_id = kDtInstanceIdFlashCtrl,
41 .reg_addr = {
42 [kDtFlashCtrlRegBlockCore] = 0x41000000,
43 [kDtFlashCtrlRegBlockPrim] = 0x41008000,
44 },
45 .mem_addr = {
46 [kDtFlashCtrlMemoryMem] = 0x20000000,
47 },
48 .mem_size = {
49 [kDtFlashCtrlMemoryMem] = 0x10000,
50 },
52 .clock = {
55 },
56 .reset = {
59 },
60 .periph_io = {
61 [kDtFlashCtrlPeriphIoTck] = {
62 .__internal = {
63 .type = kDtPeriphIoTypeMio,
64 .dir = kDtPeriphIoDirIn,
65 .periph_input_or_direct_pad = kTopEnglishbreakfastPinmuxPeripheralInFlashCtrlTck,
66 .outsel_or_dt_pad = 0,
67 },
68 },
69 [kDtFlashCtrlPeriphIoTms] = {
70 .__internal = {
71 .type = kDtPeriphIoTypeMio,
72 .dir = kDtPeriphIoDirIn,
73 .periph_input_or_direct_pad = kTopEnglishbreakfastPinmuxPeripheralInFlashCtrlTms,
74 .outsel_or_dt_pad = 0,
75 },
76 },
77 [kDtFlashCtrlPeriphIoTdi] = {
78 .__internal = {
79 .type = kDtPeriphIoTypeMio,
80 .dir = kDtPeriphIoDirIn,
81 .periph_input_or_direct_pad = kTopEnglishbreakfastPinmuxPeripheralInFlashCtrlTdi,
82 .outsel_or_dt_pad = 0,
83 },
84 },
85 [kDtFlashCtrlPeriphIoTdo] = {
86 .__internal = {
87 .type = kDtPeriphIoTypeMio,
88 .dir = kDtPeriphIoDirOut,
89 .periph_input_or_direct_pad = 0,
91 },
92 },
93 },
94 },
95};
96
97/**
98 * Return a pointer to the `dt_flash_ctrl_desc_t` structure of the requested
99 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
100 * the function) with the provided default value.
101 */
102#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_flash_ctrl_t)0 || (dt) >= kDtFlashCtrlCount) return (default); &flash_ctrl_desc[dt]; })
103
110
115
118 dt_flash_ctrl_reg_block_t reg_block) {
119 // Return a recognizable address in case of wrong argument.
120 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
121}
122
126 // Return a recognizable address in case of wrong argument.
127 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
128}
129
133 // Return an empty size in case of wrong argument.
134 return TRY_GET_DT(dt, 0)->mem_size[mem];
135}
136
140 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
141 if (first_irq == kDtPlicIrqIdNone) {
142 return kDtPlicIrqIdNone;
143 }
144 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
145}
146
149 dt_plic_irq_id_t irq) {
150 dt_flash_ctrl_irq_t count = kDtFlashCtrlIrqCount;
151 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
152 if (first_irq == kDtPlicIrqIdNone) {
153 return count;
154 }
155 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
156 return count;
157 }
158 return (dt_flash_ctrl_irq_t)(irq - first_irq);
159}
160
161
162
166 // Return a harmless value in case of wrong argument.
167 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
168}
169
173 // Return the first clock in case of invalid argument.
174 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
175}
176
180 const dt_flash_ctrl_reset_t count = kDtFlashCtrlResetCount;
181 if (rst >= count) {
182 return kDtResetUnknown;
183 }
184 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
185}
186
187