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 "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
base_addr
[kDtEdnRegBlockCount];
/**< Base address of each register block */
22
/**
23
* PLIC ID of the first IRQ of this instance
24
*
25
* This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
26
*/
27
top_earlgrey_plic_irq_id_t
first_irq
;
28
/**
29
* Alert ID of the first Alert of this instance.
30
*
31
* This value is undefined if the block is not connected to the Alert Handler.
32
*/
33
top_earlgrey_alert_id_t
first_alert
;
34
dt_clock_t
clock
[kDtEdnClockCount];
/**< Clock signal connected to each clock port */
35
dt_reset_t
reset
[kDtEdnResetCount];
/**< Reset signal connected to each reset port */
36
}
dt_desc_edn_t
;
37
38
39
40
41
static
const
dt_desc_edn_t
edn_desc[kDtEdnCount] = {
42
[
kDtEdn0
] = {
43
.inst_id =
kDtInstanceIdEdn0
,
44
.base_addr = {
45
[kDtEdnRegBlockCore] = 0x41170000,
46
},
47
.first_irq =
kTopEarlgreyPlicIrqIdEdn0EdnCmdReqDone
,
48
.first_alert =
kTopEarlgreyAlertIdEdn0RecovAlert
,
49
.clock = {
50
[
kDtEdnClockClk
] =
kDtClockMain
,
51
},
52
.reset = {
53
[
kDtEdnResetRst
] =
kDtResetLc
,
54
},
55
},
56
[
kDtEdn1
] = {
57
.inst_id =
kDtInstanceIdEdn1
,
58
.base_addr = {
59
[kDtEdnRegBlockCore] = 0x41180000,
60
},
61
.first_irq =
kTopEarlgreyPlicIrqIdEdn1EdnCmdReqDone
,
62
.first_alert =
kTopEarlgreyAlertIdEdn1RecovAlert
,
63
.clock = {
64
[
kDtEdnClockClk
] =
kDtClockMain
,
65
},
66
.reset = {
67
[
kDtEdnResetRst
] =
kDtResetLc
,
68
},
69
},
70
};
71
72
/**
73
* Return a pointer to the `dt_edn_desc_t` structure of the requested
74
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
75
* the function) with the provided default value.
76
*/
77
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_edn_t)0 || (dt) >= kDtEdnCount) return (default); &edn_desc[dt]; })
78
79
dt_edn_t
dt_edn_from_instance_id
(
dt_instance_id_t
inst_id) {
80
if
(inst_id >=
kDtInstanceIdEdn0
&& inst_id <=
kDtInstanceIdEdn1
) {
81
return
(
dt_edn_t
)(inst_id -
kDtInstanceIdEdn0
);
82
}
83
return
(
dt_edn_t
)0;
84
}
85
86
dt_instance_id_t
dt_edn_instance_id
(
87
dt_edn_t
dt) {
88
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
89
}
90
91
uint32_t
dt_edn_reg_block
(
92
dt_edn_t
dt,
93
dt_edn_reg_block_t
reg_block) {
94
// Return a recognizable address in case of wrong argument.
95
return
TRY_GET_DT
(dt, 0xdeadbeef)->base_addr[reg_block];
96
}
97
98
dt_plic_irq_id_t
dt_edn_irq_to_plic_id
(
99
dt_edn_t
dt,
100
dt_edn_irq_t
irq) {
101
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, kDtPlicIrqIdNone)->first_irq;
102
if
(first_irq == kDtPlicIrqIdNone) {
103
return
kDtPlicIrqIdNone;
104
}
105
return
(
dt_plic_irq_id_t
)((uint32_t)first_irq + (uint32_t)irq);
106
}
107
108
dt_edn_irq_t
dt_edn_irq_from_plic_id
(
109
dt_edn_t
dt,
110
dt_plic_irq_id_t
irq) {
111
dt_edn_irq_t
count = kDtEdnIrqCount;
112
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, count)->first_irq;
113
if
(first_irq == kDtPlicIrqIdNone) {
114
return
count;
115
}
116
if
(irq < first_irq || irq >= first_irq + (
dt_plic_irq_id_t
)count) {
117
return
count;
118
}
119
return
(
dt_edn_irq_t
)(irq - first_irq);
120
}
121
122
123
dt_alert_id_t
dt_edn_alert_to_alert_id
(
124
dt_edn_t
dt,
125
dt_edn_alert_t
alert) {
126
return
(
dt_alert_id_t
)((uint32_t)edn_desc[dt].first_alert + (uint32_t)alert);
127
}
128
129
dt_edn_alert_t
dt_edn_alert_from_alert_id
(
130
dt_edn_t
dt,
131
dt_alert_id_t
alert) {
132
dt_edn_alert_t
count = kDtEdnAlertCount;
133
if
(alert < edn_desc[dt].first_alert || alert >= edn_desc[dt].first_alert + (
dt_alert_id_t
)count) {
134
return
count;
135
}
136
return
(
dt_edn_alert_t
)(alert - edn_desc[dt].first_alert);
137
}
138
139
140
141
dt_clock_t
dt_edn_clock
(
142
dt_edn_t
dt,
143
dt_edn_clock_t
clk) {
144
// Return the first clock in case of invalid argument.
145
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
146
}
147
148
dt_reset_t
dt_edn_reset
(
149
dt_edn_t
dt,
150
dt_edn_reset_t
rst) {
151
const
dt_edn_reset_t
count = kDtEdnResetCount;
152
if
(rst >= count) {
153
return
kDtResetUnknown
;
154
}
155
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
156
}
157
158
(earlgrey)
hw
top
dt
dt_edn.c
Return to
OpenTitan Documentation