Software APIs
dt_keymgr.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 keymgr and top earlgrey.
10
*/
11
12
#include "
dt/dt_keymgr.h
"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_keymgr
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
base_addr
[kDtKeymgrRegBlockCount];
/**< 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
[kDtKeymgrClockCount];
/**< Clock signal connected to each clock port */
35
dt_reset_t
reset
[kDtKeymgrResetCount];
/**< Reset signal connected to each reset port */
36
}
dt_desc_keymgr_t
;
37
38
39
40
41
static
const
dt_desc_keymgr_t
keymgr_desc[kDtKeymgrCount] = {
42
[
kDtKeymgr
] = {
43
.inst_id =
kDtInstanceIdKeymgr
,
44
.base_addr = {
45
[kDtKeymgrRegBlockCore] = 0x41140000,
46
},
47
.first_irq =
kTopEarlgreyPlicIrqIdKeymgrOpDone
,
48
.first_alert =
kTopEarlgreyAlertIdKeymgrRecovOperationErr
,
49
.clock = {
50
[
kDtKeymgrClockClk
] =
kDtClockMain
,
51
[
kDtKeymgrClockEdn
] =
kDtClockMain
,
52
},
53
.reset = {
54
[
kDtKeymgrResetRst
] =
kDtResetLc
,
55
[
kDtKeymgrResetEdn
] =
kDtResetLc
,
56
},
57
},
58
};
59
60
/**
61
* Return a pointer to the `dt_keymgr_desc_t` structure of the requested
62
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
63
* the function) with the provided default value.
64
*/
65
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_keymgr_t)0 || (dt) >= kDtKeymgrCount) return (default); &keymgr_desc[dt]; })
66
67
dt_keymgr_t
dt_keymgr_from_instance_id
(
dt_instance_id_t
inst_id) {
68
if
(inst_id >=
kDtInstanceIdKeymgr
&& inst_id <=
kDtInstanceIdKeymgr
) {
69
return
(
dt_keymgr_t
)(inst_id -
kDtInstanceIdKeymgr
);
70
}
71
return
(
dt_keymgr_t
)0;
72
}
73
74
dt_instance_id_t
dt_keymgr_instance_id
(
75
dt_keymgr_t
dt) {
76
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
77
}
78
79
uint32_t
dt_keymgr_reg_block
(
80
dt_keymgr_t
dt,
81
dt_keymgr_reg_block_t
reg_block) {
82
// Return a recognizable address in case of wrong argument.
83
return
TRY_GET_DT
(dt, 0xdeadbeef)->base_addr[reg_block];
84
}
85
86
dt_plic_irq_id_t
dt_keymgr_irq_to_plic_id
(
87
dt_keymgr_t
dt,
88
dt_keymgr_irq_t
irq) {
89
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, kDtPlicIrqIdNone)->first_irq;
90
if
(first_irq == kDtPlicIrqIdNone) {
91
return
kDtPlicIrqIdNone;
92
}
93
return
(
dt_plic_irq_id_t
)((uint32_t)first_irq + (uint32_t)irq);
94
}
95
96
dt_keymgr_irq_t
dt_keymgr_irq_from_plic_id
(
97
dt_keymgr_t
dt,
98
dt_plic_irq_id_t
irq) {
99
dt_keymgr_irq_t
count = kDtKeymgrIrqCount;
100
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, count)->first_irq;
101
if
(first_irq == kDtPlicIrqIdNone) {
102
return
count;
103
}
104
if
(irq < first_irq || irq >= first_irq + (
dt_plic_irq_id_t
)count) {
105
return
count;
106
}
107
return
(
dt_keymgr_irq_t
)(irq - first_irq);
108
}
109
110
111
dt_alert_id_t
dt_keymgr_alert_to_alert_id
(
112
dt_keymgr_t
dt,
113
dt_keymgr_alert_t
alert) {
114
return
(
dt_alert_id_t
)((uint32_t)keymgr_desc[dt].first_alert + (uint32_t)alert);
115
}
116
117
dt_keymgr_alert_t
dt_keymgr_alert_from_alert_id
(
118
dt_keymgr_t
dt,
119
dt_alert_id_t
alert) {
120
dt_keymgr_alert_t
count = kDtKeymgrAlertCount;
121
if
(alert < keymgr_desc[dt].first_alert || alert >= keymgr_desc[dt].first_alert + (
dt_alert_id_t
)count) {
122
return
count;
123
}
124
return
(
dt_keymgr_alert_t
)(alert - keymgr_desc[dt].first_alert);
125
}
126
127
128
129
dt_clock_t
dt_keymgr_clock
(
130
dt_keymgr_t
dt,
131
dt_keymgr_clock_t
clk) {
132
// Return the first clock in case of invalid argument.
133
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
134
}
135
136
dt_reset_t
dt_keymgr_reset
(
137
dt_keymgr_t
dt,
138
dt_keymgr_reset_t
rst) {
139
const
dt_keymgr_reset_t
count = kDtKeymgrResetCount;
140
if
(rst >= count) {
141
return
kDtResetUnknown
;
142
}
143
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
144
}
145
146
(earlgrey)
hw
top
dt
dt_keymgr.c
Return to
OpenTitan Documentation