Software APIs
sram_ctrl.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 sram_ctrl and top earlgrey.
10
*/
11
12
#include "hw/top/dt/sram_ctrl.h"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_sram_ctrl
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
reg_addr
[
kDtSramCtrlRegBlockCount
];
/**< Base address of each register block */
22
uint32_t
mem_addr
[
kDtSramCtrlMemoryCount
];
/**< Base address of each memory */
23
uint32_t
mem_size
[
kDtSramCtrlMemoryCount
];
/**< Size in bytes of each memory */
24
/**
25
* Alert ID of the first Alert of this instance.
26
*
27
* This value is undefined if the block is not connected to the Alert Handler.
28
*/
29
top_earlgrey_alert_id_t
first_alert
;
30
dt_clock_t
clock
[
kDtSramCtrlClockCount
];
/**< Clock signal connected to each clock port */
31
dt_reset_t
reset
[
kDtSramCtrlResetCount
];
/**< Reset signal connected to each reset port */
32
}
dt_desc_sram_ctrl_t
;
33
34
35
36
37
static
const
dt_desc_sram_ctrl_t
sram_ctrl_desc[
kDtSramCtrlCount
] = {
38
[
kDtSramCtrlRetAon
] = {
39
.inst_id =
kDtInstanceIdSramCtrlRetAon
,
40
.reg_addr = {
41
[kDtSramCtrlRegBlockRegs] = 0x40500000,
42
},
43
.mem_addr = {
44
[kDtSramCtrlMemoryRam] = 0x40600000,
45
},
46
.mem_size = {
47
[kDtSramCtrlMemoryRam] = 0x1000,
48
},
49
.first_alert =
kTopEarlgreyAlertIdSramCtrlRetAonFatalError
,
50
.clock = {
51
[
kDtSramCtrlClockClk
] =
kDtClockIoDiv4
,
52
[
kDtSramCtrlClockOtp
] =
kDtClockIoDiv4
,
53
},
54
.reset = {
55
[
kDtSramCtrlResetRst
] =
kDtResetLcIoDiv4
,
56
[
kDtSramCtrlResetOtp
] =
kDtResetLcIoDiv4
,
57
},
58
},
59
[
kDtSramCtrlMain
] = {
60
.inst_id =
kDtInstanceIdSramCtrlMain
,
61
.reg_addr = {
62
[kDtSramCtrlRegBlockRegs] = 0x411C0000,
63
},
64
.mem_addr = {
65
[kDtSramCtrlMemoryRam] = 0x10000000,
66
},
67
.mem_size = {
68
[kDtSramCtrlMemoryRam] = 0x20000,
69
},
70
.first_alert =
kTopEarlgreyAlertIdSramCtrlMainFatalError
,
71
.clock = {
72
[
kDtSramCtrlClockClk
] =
kDtClockMain
,
73
[
kDtSramCtrlClockOtp
] =
kDtClockIoDiv4
,
74
},
75
.reset = {
76
[
kDtSramCtrlResetRst
] =
kDtResetLc
,
77
[
kDtSramCtrlResetOtp
] =
kDtResetLcIoDiv4
,
78
},
79
},
80
};
81
82
/**
83
* Return a pointer to the `dt_sram_ctrl_desc_t` structure of the requested
84
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
85
* the function) with the provided default value.
86
*/
87
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_sram_ctrl_t)0 || (int)(dt) >= kDtSramCtrlCount) return (default); &sram_ctrl_desc[dt]; })
88
89
dt_sram_ctrl_t
dt_sram_ctrl_from_instance_id
(
dt_instance_id_t
inst_id) {
90
if
(inst_id >=
kDtInstanceIdSramCtrlRetAon
&& inst_id <=
kDtInstanceIdSramCtrlMain
) {
91
return
(
dt_sram_ctrl_t
)(inst_id -
kDtInstanceIdSramCtrlRetAon
);
92
}
93
return
(
dt_sram_ctrl_t
)0;
94
}
95
96
dt_instance_id_t
dt_sram_ctrl_instance_id
(
97
dt_sram_ctrl_t
dt) {
98
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
99
}
100
101
uint32_t
dt_sram_ctrl_reg_block
(
102
dt_sram_ctrl_t
dt,
103
dt_sram_ctrl_reg_block_t
reg_block) {
104
// Return a recognizable address in case of wrong argument.
105
return
TRY_GET_DT
(dt, 0xdeadbeef)->reg_addr[reg_block];
106
}
107
108
uint32_t
dt_sram_ctrl_memory_base
(
109
dt_sram_ctrl_t
dt,
110
dt_sram_ctrl_memory_t
mem) {
111
// Return a recognizable address in case of wrong argument.
112
return
TRY_GET_DT
(dt, 0xdeadbeef)->mem_addr[mem];
113
}
114
115
uint32_t
dt_sram_ctrl_memory_size
(
116
dt_sram_ctrl_t
dt,
117
dt_sram_ctrl_memory_t
mem) {
118
// Return an empty size in case of wrong argument.
119
return
TRY_GET_DT
(dt, 0)->mem_size[mem];
120
}
121
122
123
dt_alert_id_t
dt_sram_ctrl_alert_to_alert_id
(
124
dt_sram_ctrl_t
dt,
125
dt_sram_ctrl_alert_t
alert) {
126
return
(
dt_alert_id_t
)((uint32_t)sram_ctrl_desc[dt].first_alert + (uint32_t)alert);
127
}
128
129
dt_sram_ctrl_alert_t
dt_sram_ctrl_alert_from_alert_id
(
130
dt_sram_ctrl_t
dt,
131
dt_alert_id_t
alert) {
132
dt_sram_ctrl_alert_t
count =
kDtSramCtrlAlertCount
;
133
if
(alert < sram_ctrl_desc[dt].first_alert || alert >= sram_ctrl_desc[dt].first_alert + (
dt_alert_id_t
)count) {
134
return
count;
135
}
136
return
(
dt_sram_ctrl_alert_t
)(alert - sram_ctrl_desc[dt].first_alert);
137
}
138
139
140
141
dt_clock_t
dt_sram_ctrl_clock
(
142
dt_sram_ctrl_t
dt,
143
dt_sram_ctrl_clock_t
clk) {
144
// Return the first clock in case of invalid argument.
145
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
146
}
147
148
dt_reset_t
dt_sram_ctrl_reset
(
149
dt_sram_ctrl_t
dt,
150
dt_sram_ctrl_reset_t
rst) {
151
const
dt_sram_ctrl_reset_t
count =
kDtSramCtrlResetCount
;
152
if
(rst >= count) {
153
return
kDtResetUnknown
;
154
}
155
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
156
}
157
158
(earlgrey)
hw
top
dt
sram_ctrl.c
Return to
OpenTitan Documentation