Software APIs
dt_alert_handler.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 alert_handler and top earlgrey.
10
*/
11
12
#include "hw/top/dt/dt_alert_handler.h"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_alert_handler
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
reg_addr
[kDtAlertHandlerRegBlockCount];
/**< Base address of each register block */
22
uint32_t
mem_addr
[kDtAlertHandlerMemoryCount];
/**< Base address of each memory */
23
uint32_t
mem_size
[kDtAlertHandlerMemoryCount];
/**< 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
dt_clock_t
clock
[kDtAlertHandlerClockCount];
/**< Clock signal connected to each clock port */
31
dt_reset_t
reset
[kDtAlertHandlerResetCount];
/**< Reset signal connected to each reset port */
32
}
dt_desc_alert_handler_t
;
33
34
35
36
37
static
const
dt_desc_alert_handler_t
alert_handler_desc[kDtAlertHandlerCount] = {
38
[
kDtAlertHandler
] = {
39
.inst_id =
kDtInstanceIdAlertHandler
,
40
.reg_addr = {
41
[kDtAlertHandlerRegBlockCore] = 0x40150000,
42
},
43
.mem_addr = {
44
},
45
.mem_size = {
46
},
47
.first_irq =
kTopEarlgreyPlicIrqIdAlertHandlerClassa
,
48
.clock = {
49
[
kDtAlertHandlerClockClk
] =
kDtClockIoDiv4
,
50
[
kDtAlertHandlerClockEdn
] =
kDtClockMain
,
51
},
52
.reset = {
53
[
kDtAlertHandlerResetRst
] =
kDtResetLcIoDiv4
,
54
[
kDtAlertHandlerResetEdn
] =
kDtResetLc
,
55
},
56
},
57
};
58
59
/**
60
* Return a pointer to the `dt_alert_handler_desc_t` structure of the requested
61
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
62
* the function) with the provided default value.
63
*/
64
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_alert_handler_t)0 || (dt) >= kDtAlertHandlerCount) return (default); &alert_handler_desc[dt]; })
65
66
dt_alert_handler_t
dt_alert_handler_from_instance_id
(
dt_instance_id_t
inst_id) {
67
if
(inst_id >=
kDtInstanceIdAlertHandler
&& inst_id <=
kDtInstanceIdAlertHandler
) {
68
return
(
dt_alert_handler_t
)(inst_id -
kDtInstanceIdAlertHandler
);
69
}
70
return
(
dt_alert_handler_t
)0;
71
}
72
73
dt_instance_id_t
dt_alert_handler_instance_id
(
74
dt_alert_handler_t
dt) {
75
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
76
}
77
78
uint32_t
dt_alert_handler_reg_block
(
79
dt_alert_handler_t
dt,
80
dt_alert_handler_reg_block_t
reg_block) {
81
// Return a recognizable address in case of wrong argument.
82
return
TRY_GET_DT
(dt, 0xdeadbeef)->reg_addr[reg_block];
83
}
84
85
uint32_t
dt_alert_handler_memory_base
(
86
dt_alert_handler_t
dt,
87
dt_alert_handler_memory_t
mem) {
88
// Return a recognizable address in case of wrong argument.
89
return
TRY_GET_DT
(dt, 0xdeadbeef)->mem_addr[mem];
90
}
91
92
uint32_t
dt_alert_handler_memory_size
(
93
dt_alert_handler_t
dt,
94
dt_alert_handler_memory_t
mem) {
95
// Return an empty size in case of wrong argument.
96
return
TRY_GET_DT
(dt, 0)->mem_size[mem];
97
}
98
99
dt_plic_irq_id_t
dt_alert_handler_irq_to_plic_id
(
100
dt_alert_handler_t
dt,
101
dt_alert_handler_irq_t
irq) {
102
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, kDtPlicIrqIdNone)->first_irq;
103
if
(first_irq == kDtPlicIrqIdNone) {
104
return
kDtPlicIrqIdNone;
105
}
106
return
(
dt_plic_irq_id_t
)((uint32_t)first_irq + (uint32_t)irq);
107
}
108
109
dt_alert_handler_irq_t
dt_alert_handler_irq_from_plic_id
(
110
dt_alert_handler_t
dt,
111
dt_plic_irq_id_t
irq) {
112
dt_alert_handler_irq_t
count = kDtAlertHandlerIrqCount;
113
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, count)->first_irq;
114
if
(first_irq == kDtPlicIrqIdNone) {
115
return
count;
116
}
117
if
(irq < first_irq || irq >= first_irq + (
dt_plic_irq_id_t
)count) {
118
return
count;
119
}
120
return
(
dt_alert_handler_irq_t
)(irq - first_irq);
121
}
122
123
124
125
126
dt_clock_t
dt_alert_handler_clock
(
127
dt_alert_handler_t
dt,
128
dt_alert_handler_clock_t
clk) {
129
// Return the first clock in case of invalid argument.
130
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
131
}
132
133
dt_reset_t
dt_alert_handler_reset
(
134
dt_alert_handler_t
dt,
135
dt_alert_handler_reset_t
rst) {
136
const
dt_alert_handler_reset_t
count = kDtAlertHandlerResetCount;
137
if
(rst >= count) {
138
return
kDtResetUnknown
;
139
}
140
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
141
}
142
143
(earlgrey)
hw
top
dt
dt_alert_handler.c
Return to
OpenTitan Documentation