Software APIs
dt_csrng.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 csrng and top earlgrey.
10
*/
11
12
#include "hw/top/dt/dt_csrng.h"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_csrng
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
reg_addr
[kDtCsrngRegBlockCount];
/**< Base address of each register block */
22
uint32_t
mem_addr
[kDtCsrngMemoryCount];
/**< Base address of each memory */
23
uint32_t
mem_size
[kDtCsrngMemoryCount];
/**< 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
/**
31
* Alert ID of the first Alert of this instance.
32
*
33
* This value is undefined if the block is not connected to the Alert Handler.
34
*/
35
top_earlgrey_alert_id_t
first_alert
;
36
dt_clock_t
clock
[kDtCsrngClockCount];
/**< Clock signal connected to each clock port */
37
dt_reset_t
reset
[kDtCsrngResetCount];
/**< Reset signal connected to each reset port */
38
}
dt_desc_csrng_t
;
39
40
41
42
43
static
const
dt_desc_csrng_t
csrng_desc[kDtCsrngCount] = {
44
[
kDtCsrng
] = {
45
.inst_id =
kDtInstanceIdCsrng
,
46
.reg_addr = {
47
[kDtCsrngRegBlockCore] = 0x41150000,
48
},
49
.mem_addr = {
50
},
51
.mem_size = {
52
},
53
.first_irq =
kTopEarlgreyPlicIrqIdCsrngCsCmdReqDone
,
54
.first_alert =
kTopEarlgreyAlertIdCsrngRecovAlert
,
55
.clock = {
56
[
kDtCsrngClockClk
] =
kDtClockMain
,
57
},
58
.reset = {
59
[
kDtCsrngResetRst
] =
kDtResetLc
,
60
},
61
},
62
};
63
64
/**
65
* Return a pointer to the `dt_csrng_desc_t` structure of the requested
66
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
67
* the function) with the provided default value.
68
*/
69
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_csrng_t)0 || (dt) >= kDtCsrngCount) return (default); &csrng_desc[dt]; })
70
71
dt_csrng_t
dt_csrng_from_instance_id
(
dt_instance_id_t
inst_id) {
72
if
(inst_id >=
kDtInstanceIdCsrng
&& inst_id <=
kDtInstanceIdCsrng
) {
73
return
(
dt_csrng_t
)(inst_id -
kDtInstanceIdCsrng
);
74
}
75
return
(
dt_csrng_t
)0;
76
}
77
78
dt_instance_id_t
dt_csrng_instance_id
(
79
dt_csrng_t
dt) {
80
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
81
}
82
83
uint32_t
dt_csrng_reg_block
(
84
dt_csrng_t
dt,
85
dt_csrng_reg_block_t
reg_block) {
86
// Return a recognizable address in case of wrong argument.
87
return
TRY_GET_DT
(dt, 0xdeadbeef)->reg_addr[reg_block];
88
}
89
90
uint32_t
dt_csrng_memory_base
(
91
dt_csrng_t
dt,
92
dt_csrng_memory_t
mem) {
93
// Return a recognizable address in case of wrong argument.
94
return
TRY_GET_DT
(dt, 0xdeadbeef)->mem_addr[mem];
95
}
96
97
uint32_t
dt_csrng_memory_size
(
98
dt_csrng_t
dt,
99
dt_csrng_memory_t
mem) {
100
// Return an empty size in case of wrong argument.
101
return
TRY_GET_DT
(dt, 0)->mem_size[mem];
102
}
103
104
dt_plic_irq_id_t
dt_csrng_irq_to_plic_id
(
105
dt_csrng_t
dt,
106
dt_csrng_irq_t
irq) {
107
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, kDtPlicIrqIdNone)->first_irq;
108
if
(first_irq == kDtPlicIrqIdNone) {
109
return
kDtPlicIrqIdNone;
110
}
111
return
(
dt_plic_irq_id_t
)((uint32_t)first_irq + (uint32_t)irq);
112
}
113
114
dt_csrng_irq_t
dt_csrng_irq_from_plic_id
(
115
dt_csrng_t
dt,
116
dt_plic_irq_id_t
irq) {
117
dt_csrng_irq_t
count = kDtCsrngIrqCount;
118
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, count)->first_irq;
119
if
(first_irq == kDtPlicIrqIdNone) {
120
return
count;
121
}
122
if
(irq < first_irq || irq >= first_irq + (
dt_plic_irq_id_t
)count) {
123
return
count;
124
}
125
return
(
dt_csrng_irq_t
)(irq - first_irq);
126
}
127
128
129
dt_alert_id_t
dt_csrng_alert_to_alert_id
(
130
dt_csrng_t
dt,
131
dt_csrng_alert_t
alert) {
132
return
(
dt_alert_id_t
)((uint32_t)csrng_desc[dt].first_alert + (uint32_t)alert);
133
}
134
135
dt_csrng_alert_t
dt_csrng_alert_from_alert_id
(
136
dt_csrng_t
dt,
137
dt_alert_id_t
alert) {
138
dt_csrng_alert_t
count = kDtCsrngAlertCount;
139
if
(alert < csrng_desc[dt].first_alert || alert >= csrng_desc[dt].first_alert + (
dt_alert_id_t
)count) {
140
return
count;
141
}
142
return
(
dt_csrng_alert_t
)(alert - csrng_desc[dt].first_alert);
143
}
144
145
146
147
dt_clock_t
dt_csrng_clock
(
148
dt_csrng_t
dt,
149
dt_csrng_clock_t
clk) {
150
// Return the first clock in case of invalid argument.
151
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
152
}
153
154
dt_reset_t
dt_csrng_reset
(
155
dt_csrng_t
dt,
156
dt_csrng_reset_t
rst) {
157
const
dt_csrng_reset_t
count = kDtCsrngResetCount;
158
if
(rst >= count) {
159
return
kDtResetUnknown
;
160
}
161
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
162
}
163
164
(earlgrey)
hw
top
dt
dt_csrng.c
Return to
OpenTitan Documentation