Software APIs
dt_otbn.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 otbn and top earlgrey.
10
*/
11
12
#include "dt/dt_otbn.h"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_otbn
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
base_addr
[kDtOtbnRegBlockCount];
/**< 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
[kDtOtbnClockCount];
/**< Clock signal connected to each clock port */
35
dt_reset_t
reset
[kDtOtbnResetCount];
/**< Reset signal connected to each reset port */
36
}
dt_desc_otbn_t
;
37
38
39
40
41
static
const
dt_desc_otbn_t
otbn_desc[kDtOtbnCount] = {
42
[
kDtOtbn
] = {
43
.inst_id =
kDtInstanceIdOtbn
,
44
.base_addr = {
45
[kDtOtbnRegBlockCore] = 0x41130000,
46
},
47
.first_irq =
kTopEarlgreyPlicIrqIdOtbnDone
,
48
.first_alert =
kTopEarlgreyAlertIdOtbnFatal
,
49
.clock = {
50
[
kDtOtbnClockClk
] =
kDtClockMain
,
51
[
kDtOtbnClockEdn
] =
kDtClockMain
,
52
[
kDtOtbnClockOtp
] =
kDtClockIoDiv4
,
53
},
54
.reset = {
55
[
kDtOtbnResetRst
] =
kDtResetLc
,
56
[
kDtOtbnResetEdn
] =
kDtResetLc
,
57
[
kDtOtbnResetOtp
] =
kDtResetLcIoDiv4
,
58
},
59
},
60
};
61
62
/**
63
* Return a pointer to the `dt_otbn_desc_t` structure of the requested
64
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
65
* the function) with the provided default value.
66
*/
67
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_otbn_t)0 || (dt) >= kDtOtbnCount) return (default); &otbn_desc[dt]; })
68
69
dt_otbn_t
dt_otbn_from_instance_id
(
dt_instance_id_t
inst_id) {
70
if
(inst_id >=
kDtInstanceIdOtbn
&& inst_id <=
kDtInstanceIdOtbn
) {
71
return
(
dt_otbn_t
)(inst_id -
kDtInstanceIdOtbn
);
72
}
73
return
(
dt_otbn_t
)0;
74
}
75
76
dt_instance_id_t
dt_otbn_instance_id
(
77
dt_otbn_t
dt) {
78
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
79
}
80
81
uint32_t
dt_otbn_reg_block
(
82
dt_otbn_t
dt,
83
dt_otbn_reg_block_t
reg_block) {
84
// Return a recognizable address in case of wrong argument.
85
return
TRY_GET_DT
(dt, 0xdeadbeef)->base_addr[reg_block];
86
}
87
88
dt_plic_irq_id_t
dt_otbn_irq_to_plic_id
(
89
dt_otbn_t
dt,
90
dt_otbn_irq_t
irq) {
91
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, kDtPlicIrqIdNone)->first_irq;
92
if
(first_irq == kDtPlicIrqIdNone) {
93
return
kDtPlicIrqIdNone;
94
}
95
return
(
dt_plic_irq_id_t
)((uint32_t)first_irq + (uint32_t)irq);
96
}
97
98
dt_otbn_irq_t
dt_otbn_irq_from_plic_id
(
99
dt_otbn_t
dt,
100
dt_plic_irq_id_t
irq) {
101
dt_otbn_irq_t
count = kDtOtbnIrqCount;
102
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, count)->first_irq;
103
if
(first_irq == kDtPlicIrqIdNone) {
104
return
count;
105
}
106
if
(irq < first_irq || irq >= first_irq + (
dt_plic_irq_id_t
)count) {
107
return
count;
108
}
109
return
(
dt_otbn_irq_t
)(irq - first_irq);
110
}
111
112
113
dt_alert_id_t
dt_otbn_alert_to_alert_id
(
114
dt_otbn_t
dt,
115
dt_otbn_alert_t
alert) {
116
return
(
dt_alert_id_t
)((uint32_t)otbn_desc[dt].first_alert + (uint32_t)alert);
117
}
118
119
dt_otbn_alert_t
dt_otbn_alert_from_alert_id
(
120
dt_otbn_t
dt,
121
dt_alert_id_t
alert) {
122
dt_otbn_alert_t
count = kDtOtbnAlertCount;
123
if
(alert < otbn_desc[dt].first_alert || alert >= otbn_desc[dt].first_alert + (
dt_alert_id_t
)count) {
124
return
count;
125
}
126
return
(
dt_otbn_alert_t
)(alert - otbn_desc[dt].first_alert);
127
}
128
129
130
131
dt_clock_t
dt_otbn_clock
(
132
dt_otbn_t
dt,
133
dt_otbn_clock_t
clk) {
134
// Return the first clock in case of invalid argument.
135
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
136
}
137
138
dt_reset_t
dt_otbn_reset
(
139
dt_otbn_t
dt,
140
dt_otbn_reset_t
rst) {
141
const
dt_otbn_reset_t
count = kDtOtbnResetCount;
142
if
(rst >= count) {
143
return
kDtResetUnknown
;
144
}
145
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
146
}
147
148
(earlgrey)
hw
top
dt
dt_otbn.c
Return to
OpenTitan Documentation