Pavona Software APIs
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 scafi_deprecated.
10
*/
11
12
#include "hw/top/dt/flash_ctrl.h"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
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
*/
29
top_scafi_deprecated_plic_irq_id_t
first_irq
;
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_desc_flash_ctrl_t
;
33
34
35
36
37
static
const
dt_desc_flash_ctrl_t
flash_ctrl_desc[
kDtFlashCtrlCount
] = {
38
[
kDtFlashCtrl
] = {
39
.inst_id =
kDtInstanceIdFlashCtrl
,
40
.reg_addr = {
41
[kDtFlashCtrlRegBlockCore] = 0x41000000,
42
},
43
.mem_addr = {
44
[kDtFlashCtrlMemoryMem] = 0x20000000,
45
},
46
.mem_size = {
47
[kDtFlashCtrlMemoryMem] = 0x10000,
48
},
49
.first_irq =
kTopScafiDeprecatedPlicIrqIdFlashCtrlProgEmpty
,
50
.clock = {
51
[
kDtFlashCtrlClockClk
] =
kDtClockMain
,
52
[
kDtFlashCtrlClockOtp
] =
kDtClockIoDiv4
,
53
},
54
.reset = {
55
[
kDtFlashCtrlResetRst
] =
kDtResetLc
,
56
[
kDtFlashCtrlResetOtp
] =
kDtResetLcIoDiv4
,
57
},
58
},
59
};
60
61
/**
62
* Return a pointer to the `dt_flash_ctrl_desc_t` structure of the requested
63
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
64
* the function) with the provided default value.
65
*/
66
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_flash_ctrl_t)0 || (int)(dt) >= kDtFlashCtrlCount) return (default); &flash_ctrl_desc[dt]; })
67
68
dt_flash_ctrl_t
dt_flash_ctrl_from_instance_id
(
dt_instance_id_t
inst_id) {
69
if
(inst_id >=
kDtInstanceIdFlashCtrl
&& inst_id <=
kDtInstanceIdFlashCtrl
) {
70
return
(
dt_flash_ctrl_t
)(inst_id -
kDtInstanceIdFlashCtrl
);
71
}
72
return
(
dt_flash_ctrl_t
)0;
73
}
74
75
dt_instance_id_t
dt_flash_ctrl_instance_id
(
76
dt_flash_ctrl_t
dt) {
77
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
78
}
79
80
uint32_t
dt_flash_ctrl_reg_block
(
81
dt_flash_ctrl_t
dt,
82
dt_flash_ctrl_reg_block_t
reg_block) {
83
// Return a recognizable address in case of wrong argument.
84
return
TRY_GET_DT
(dt, 0xdeadbeef)->reg_addr[reg_block];
85
}
86
87
uint32_t
dt_flash_ctrl_memory_base
(
88
dt_flash_ctrl_t
dt,
89
dt_flash_ctrl_memory_t
mem) {
90
// Return a recognizable address in case of wrong argument.
91
return
TRY_GET_DT
(dt, 0xdeadbeef)->mem_addr[mem];
92
}
93
94
uint32_t
dt_flash_ctrl_memory_size
(
95
dt_flash_ctrl_t
dt,
96
dt_flash_ctrl_memory_t
mem) {
97
// Return an empty size in case of wrong argument.
98
return
TRY_GET_DT
(dt, 0)->mem_size[mem];
99
}
100
101
dt_plic_irq_id_t
dt_flash_ctrl_irq_to_plic_id
(
102
dt_flash_ctrl_t
dt,
103
dt_flash_ctrl_irq_t
irq) {
104
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, kDtPlicIrqIdNone)->first_irq;
105
if
(first_irq == kDtPlicIrqIdNone) {
106
return
kDtPlicIrqIdNone;
107
}
108
return
(
dt_plic_irq_id_t
)((uint32_t)first_irq + (uint32_t)irq);
109
}
110
111
dt_flash_ctrl_irq_t
dt_flash_ctrl_irq_from_plic_id
(
112
dt_flash_ctrl_t
dt,
113
dt_plic_irq_id_t
irq) {
114
dt_flash_ctrl_irq_t
count =
kDtFlashCtrlIrqCount
;
115
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, count)->first_irq;
116
if
(first_irq == kDtPlicIrqIdNone) {
117
return
count;
118
}
119
if
(irq < first_irq || irq >= first_irq + (
dt_plic_irq_id_t
)count) {
120
return
count;
121
}
122
return
(
dt_flash_ctrl_irq_t
)(irq - first_irq);
123
}
124
125
126
127
128
dt_clock_t
dt_flash_ctrl_clock
(
129
dt_flash_ctrl_t
dt,
130
dt_flash_ctrl_clock_t
clk) {
131
// Return the first clock in case of invalid argument.
132
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
133
}
134
135
dt_reset_t
dt_flash_ctrl_reset
(
136
dt_flash_ctrl_t
dt,
137
dt_flash_ctrl_reset_t
rst) {
138
const
dt_flash_ctrl_reset_t
count =
kDtFlashCtrlResetCount
;
139
if
(rst >= count) {
140
return
kDtResetUnknown
;
141
}
142
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
143
}
144
145
(scafi_deprecated)
hw
top
dt
flash_ctrl.c
Generated by
1.13.2