Software APIs
dt_entropy_src.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 entropy_src and top earlgrey.
10
*/
11
12
#include "
dt/dt_entropy_src.h
"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_entropy_src
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
base_addr
[kDtEntropySrcRegBlockCount];
/**< 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
[kDtEntropySrcClockCount];
/**< Clock signal connected to each clock port */
35
dt_reset_t
reset
[kDtEntropySrcResetCount];
/**< Reset signal connected to each reset port */
36
}
dt_desc_entropy_src_t
;
37
38
39
40
41
static
const
dt_desc_entropy_src_t
entropy_src_desc[kDtEntropySrcCount] = {
42
[
kDtEntropySrc
] = {
43
.inst_id =
kDtInstanceIdEntropySrc
,
44
.base_addr = {
45
[kDtEntropySrcRegBlockCore] = 0x41160000,
46
},
47
.first_irq =
kTopEarlgreyPlicIrqIdEntropySrcEsEntropyValid
,
48
.first_alert =
kTopEarlgreyAlertIdEntropySrcRecovAlert
,
49
.clock = {
50
[
kDtEntropySrcClockClk
] =
kDtClockMain
,
51
},
52
.reset = {
53
[
kDtEntropySrcResetRst
] =
kDtResetLc
,
54
},
55
},
56
};
57
58
/**
59
* Return a pointer to the `dt_entropy_src_desc_t` structure of the requested
60
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
61
* the function) with the provided default value.
62
*/
63
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_entropy_src_t)0 || (dt) >= kDtEntropySrcCount) return (default); &entropy_src_desc[dt]; })
64
65
dt_entropy_src_t
dt_entropy_src_from_instance_id
(
dt_instance_id_t
inst_id) {
66
if
(inst_id >=
kDtInstanceIdEntropySrc
&& inst_id <=
kDtInstanceIdEntropySrc
) {
67
return
(
dt_entropy_src_t
)(inst_id -
kDtInstanceIdEntropySrc
);
68
}
69
return
(
dt_entropy_src_t
)0;
70
}
71
72
dt_instance_id_t
dt_entropy_src_instance_id
(
73
dt_entropy_src_t
dt) {
74
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
75
}
76
77
uint32_t
dt_entropy_src_reg_block
(
78
dt_entropy_src_t
dt,
79
dt_entropy_src_reg_block_t
reg_block) {
80
// Return a recognizable address in case of wrong argument.
81
return
TRY_GET_DT
(dt, 0xdeadbeef)->base_addr[reg_block];
82
}
83
84
dt_plic_irq_id_t
dt_entropy_src_irq_to_plic_id
(
85
dt_entropy_src_t
dt,
86
dt_entropy_src_irq_t
irq) {
87
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, kDtPlicIrqIdNone)->first_irq;
88
if
(first_irq == kDtPlicIrqIdNone) {
89
return
kDtPlicIrqIdNone;
90
}
91
return
(
dt_plic_irq_id_t
)((uint32_t)first_irq + (uint32_t)irq);
92
}
93
94
dt_entropy_src_irq_t
dt_entropy_src_irq_from_plic_id
(
95
dt_entropy_src_t
dt,
96
dt_plic_irq_id_t
irq) {
97
dt_entropy_src_irq_t
count = kDtEntropySrcIrqCount;
98
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, count)->first_irq;
99
if
(first_irq == kDtPlicIrqIdNone) {
100
return
count;
101
}
102
if
(irq < first_irq || irq >= first_irq + (
dt_plic_irq_id_t
)count) {
103
return
count;
104
}
105
return
(
dt_entropy_src_irq_t
)(irq - first_irq);
106
}
107
108
109
dt_alert_id_t
dt_entropy_src_alert_to_alert_id
(
110
dt_entropy_src_t
dt,
111
dt_entropy_src_alert_t
alert) {
112
return
(
dt_alert_id_t
)((uint32_t)entropy_src_desc[dt].first_alert + (uint32_t)alert);
113
}
114
115
dt_entropy_src_alert_t
dt_entropy_src_alert_from_alert_id
(
116
dt_entropy_src_t
dt,
117
dt_alert_id_t
alert) {
118
dt_entropy_src_alert_t
count = kDtEntropySrcAlertCount;
119
if
(alert < entropy_src_desc[dt].first_alert || alert >= entropy_src_desc[dt].first_alert + (
dt_alert_id_t
)count) {
120
return
count;
121
}
122
return
(
dt_entropy_src_alert_t
)(alert - entropy_src_desc[dt].first_alert);
123
}
124
125
126
127
dt_clock_t
dt_entropy_src_clock
(
128
dt_entropy_src_t
dt,
129
dt_entropy_src_clock_t
clk) {
130
// Return the first clock in case of invalid argument.
131
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
132
}
133
134
dt_reset_t
dt_entropy_src_reset
(
135
dt_entropy_src_t
dt,
136
dt_entropy_src_reset_t
rst) {
137
const
dt_entropy_src_reset_t
count = kDtEntropySrcResetCount;
138
if
(rst >= count) {
139
return
kDtResetUnknown
;
140
}
141
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
142
}
143
144
(earlgrey)
hw
top
dt
dt_entropy_src.c
Return to
OpenTitan Documentation