Software APIs
dt_edn.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 edn and top earlgrey.
10
*/
11
12
#include "hw/top/dt/dt_edn.h"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_edn
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
reg_addr
[kDtEdnRegBlockCount];
/**< Base address of each register block */
22
uint32_t
mem_addr
[kDtEdnMemoryCount];
/**< Base address of each memory */
23
uint32_t
mem_size
[kDtEdnMemoryCount];
/**< 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_earlgrey_plic_irq_id_t
first_irq
;
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
*/
35
top_earlgrey_alert_id_t
first_alert
;
36
dt_clock_t
clock
[kDtEdnClockCount];
/**< Clock signal connected to each clock port */
37
dt_reset_t
reset
[kDtEdnResetCount];
/**< Reset signal connected to each reset port */
38
}
dt_desc_edn_t
;
39
40
41
42
43
static
const
dt_desc_edn_t
edn_desc[kDtEdnCount] = {
44
[
kDtEdn0
] = {
45
.inst_id =
kDtInstanceIdEdn0
,
46
.reg_addr = {
47
[kDtEdnRegBlockCore] = 0x41170000,
48
},
49
.mem_addr = {
50
},
51
.mem_size = {
52
},
53
.first_irq =
kTopEarlgreyPlicIrqIdEdn0EdnCmdReqDone
,
54
.first_alert =
kTopEarlgreyAlertIdEdn0RecovAlert
,
55
.clock = {
56
[
kDtEdnClockClk
] =
kDtClockMain
,
57
},
58
.reset = {
59
[
kDtEdnResetRst
] =
kDtResetLc
,
60
},
61
},
62
[
kDtEdn1
] = {
63
.inst_id =
kDtInstanceIdEdn1
,
64
.reg_addr = {
65
[kDtEdnRegBlockCore] = 0x41180000,
66
},
67
.mem_addr = {
68
},
69
.mem_size = {
70
},
71
.first_irq =
kTopEarlgreyPlicIrqIdEdn1EdnCmdReqDone
,
72
.first_alert =
kTopEarlgreyAlertIdEdn1RecovAlert
,
73
.clock = {
74
[
kDtEdnClockClk
] =
kDtClockMain
,
75
},
76
.reset = {
77
[
kDtEdnResetRst
] =
kDtResetLc
,
78
},
79
},
80
};
81
82
/**
83
* Return a pointer to the `dt_edn_desc_t` structure of the requested
84
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
85
* the function) with the provided default value.
86
*/
87
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_edn_t)0 || (dt) >= kDtEdnCount) return (default); &edn_desc[dt]; })
88
89
dt_edn_t
dt_edn_from_instance_id
(
dt_instance_id_t
inst_id) {
90
if
(inst_id >=
kDtInstanceIdEdn0
&& inst_id <=
kDtInstanceIdEdn1
) {
91
return
(
dt_edn_t
)(inst_id -
kDtInstanceIdEdn0
);
92
}
93
return
(
dt_edn_t
)0;
94
}
95
96
dt_instance_id_t
dt_edn_instance_id
(
97
dt_edn_t
dt) {
98
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
99
}
100
101
uint32_t
dt_edn_reg_block
(
102
dt_edn_t
dt,
103
dt_edn_reg_block_t
reg_block) {
104
// Return a recognizable address in case of wrong argument.
105
return
TRY_GET_DT
(dt, 0xdeadbeef)->reg_addr[reg_block];
106
}
107
108
uint32_t
dt_edn_memory_base
(
109
dt_edn_t
dt,
110
dt_edn_memory_t
mem) {
111
// Return a recognizable address in case of wrong argument.
112
return
TRY_GET_DT
(dt, 0xdeadbeef)->mem_addr[mem];
113
}
114
115
uint32_t
dt_edn_memory_size
(
116
dt_edn_t
dt,
117
dt_edn_memory_t
mem) {
118
// Return an empty size in case of wrong argument.
119
return
TRY_GET_DT
(dt, 0)->mem_size[mem];
120
}
121
122
dt_plic_irq_id_t
dt_edn_irq_to_plic_id
(
123
dt_edn_t
dt,
124
dt_edn_irq_t
irq) {
125
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, kDtPlicIrqIdNone)->first_irq;
126
if
(first_irq == kDtPlicIrqIdNone) {
127
return
kDtPlicIrqIdNone;
128
}
129
return
(
dt_plic_irq_id_t
)((uint32_t)first_irq + (uint32_t)irq);
130
}
131
132
dt_edn_irq_t
dt_edn_irq_from_plic_id
(
133
dt_edn_t
dt,
134
dt_plic_irq_id_t
irq) {
135
dt_edn_irq_t
count = kDtEdnIrqCount;
136
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, count)->first_irq;
137
if
(first_irq == kDtPlicIrqIdNone) {
138
return
count;
139
}
140
if
(irq < first_irq || irq >= first_irq + (
dt_plic_irq_id_t
)count) {
141
return
count;
142
}
143
return
(
dt_edn_irq_t
)(irq - first_irq);
144
}
145
146
147
dt_alert_id_t
dt_edn_alert_to_alert_id
(
148
dt_edn_t
dt,
149
dt_edn_alert_t
alert) {
150
return
(
dt_alert_id_t
)((uint32_t)edn_desc[dt].first_alert + (uint32_t)alert);
151
}
152
153
dt_edn_alert_t
dt_edn_alert_from_alert_id
(
154
dt_edn_t
dt,
155
dt_alert_id_t
alert) {
156
dt_edn_alert_t
count = kDtEdnAlertCount;
157
if
(alert < edn_desc[dt].first_alert || alert >= edn_desc[dt].first_alert + (
dt_alert_id_t
)count) {
158
return
count;
159
}
160
return
(
dt_edn_alert_t
)(alert - edn_desc[dt].first_alert);
161
}
162
163
164
165
dt_clock_t
dt_edn_clock
(
166
dt_edn_t
dt,
167
dt_edn_clock_t
clk) {
168
// Return the first clock in case of invalid argument.
169
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
170
}
171
172
dt_reset_t
dt_edn_reset
(
173
dt_edn_t
dt,
174
dt_edn_reset_t
rst) {
175
const
dt_edn_reset_t
count = kDtEdnResetCount;
176
if
(rst >= count) {
177
return
kDtResetUnknown
;
178
}
179
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
180
}
181
182
(earlgrey)
hw
top
dt
dt_edn.c
Return to
OpenTitan Documentation