Software APIs
dt_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 "dt/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
base_addr
[kDtSramCtrlRegBlockCount];
/**< Base address of each register block */
22
/**
23
* Alert ID of the first Alert of this instance.
24
*
25
* This value is undefined if the block is not connected to the Alert Handler.
26
*/
27
top_earlgrey_alert_id_t
first_alert
;
28
dt_clock_t
clock
[kDtSramCtrlClockCount];
/**< Clock signal connected to each clock port */
29
dt_reset_t
reset
[kDtSramCtrlResetCount];
/**< Reset signal connected to each reset port */
30
}
dt_desc_sram_ctrl_t
;
31
32
33
34
35
static
const
dt_desc_sram_ctrl_t
sram_ctrl_desc[kDtSramCtrlCount] = {
36
[
kDtSramCtrlRetAon
] = {
37
.inst_id =
kDtInstanceIdSramCtrlRetAon
,
38
.base_addr = {
39
[kDtSramCtrlRegBlockRegs] = 0x40500000,
40
[kDtSramCtrlRegBlockRam] = 0x40600000,
41
},
42
.first_alert =
kTopEarlgreyAlertIdSramCtrlRetAonFatalError
,
43
.clock = {
44
[
kDtSramCtrlClockClk
] =
kDtClockIoDiv4
,
45
[
kDtSramCtrlClockOtp
] =
kDtClockIoDiv4
,
46
},
47
.reset = {
48
[
kDtSramCtrlResetRst
] =
kDtResetLcIoDiv4
,
49
[
kDtSramCtrlResetOtp
] =
kDtResetLcIoDiv4
,
50
},
51
},
52
[
kDtSramCtrlMain
] = {
53
.inst_id =
kDtInstanceIdSramCtrlMain
,
54
.base_addr = {
55
[kDtSramCtrlRegBlockRegs] = 0x411C0000,
56
[kDtSramCtrlRegBlockRam] = 0x10000000,
57
},
58
.first_alert =
kTopEarlgreyAlertIdSramCtrlMainFatalError
,
59
.clock = {
60
[
kDtSramCtrlClockClk
] =
kDtClockMain
,
61
[
kDtSramCtrlClockOtp
] =
kDtClockIoDiv4
,
62
},
63
.reset = {
64
[
kDtSramCtrlResetRst
] =
kDtResetLc
,
65
[
kDtSramCtrlResetOtp
] =
kDtResetLcIoDiv4
,
66
},
67
},
68
};
69
70
/**
71
* Return a pointer to the `dt_sram_ctrl_desc_t` structure of the requested
72
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
73
* the function) with the provided default value.
74
*/
75
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_sram_ctrl_t)0 || (dt) >= kDtSramCtrlCount) return (default); &sram_ctrl_desc[dt]; })
76
77
dt_sram_ctrl_t
dt_sram_ctrl_from_instance_id
(
dt_instance_id_t
inst_id) {
78
if
(inst_id >=
kDtInstanceIdSramCtrlRetAon
&& inst_id <=
kDtInstanceIdSramCtrlMain
) {
79
return
(
dt_sram_ctrl_t
)(inst_id -
kDtInstanceIdSramCtrlRetAon
);
80
}
81
return
(
dt_sram_ctrl_t
)0;
82
}
83
84
dt_instance_id_t
dt_sram_ctrl_instance_id
(
85
dt_sram_ctrl_t
dt) {
86
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
87
}
88
89
uint32_t
dt_sram_ctrl_reg_block
(
90
dt_sram_ctrl_t
dt,
91
dt_sram_ctrl_reg_block_t
reg_block) {
92
// Return a recognizable address in case of wrong argument.
93
return
TRY_GET_DT
(dt, 0xdeadbeef)->base_addr[reg_block];
94
}
95
96
97
dt_alert_id_t
dt_sram_ctrl_alert_to_alert_id
(
98
dt_sram_ctrl_t
dt,
99
dt_sram_ctrl_alert_t
alert) {
100
return
(
dt_alert_id_t
)((uint32_t)sram_ctrl_desc[dt].first_alert + (uint32_t)alert);
101
}
102
103
dt_sram_ctrl_alert_t
dt_sram_ctrl_alert_from_alert_id
(
104
dt_sram_ctrl_t
dt,
105
dt_alert_id_t
alert) {
106
dt_sram_ctrl_alert_t
count = kDtSramCtrlAlertCount;
107
if
(alert < sram_ctrl_desc[dt].first_alert || alert >= sram_ctrl_desc[dt].first_alert + (
dt_alert_id_t
)count) {
108
return
count;
109
}
110
return
(
dt_sram_ctrl_alert_t
)(alert - sram_ctrl_desc[dt].first_alert);
111
}
112
113
114
115
dt_clock_t
dt_sram_ctrl_clock
(
116
dt_sram_ctrl_t
dt,
117
dt_sram_ctrl_clock_t
clk) {
118
// Return the first clock in case of invalid argument.
119
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
120
}
121
122
dt_reset_t
dt_sram_ctrl_reset
(
123
dt_sram_ctrl_t
dt,
124
dt_sram_ctrl_reset_t
rst) {
125
const
dt_sram_ctrl_reset_t
count = kDtSramCtrlResetCount;
126
if
(rst >= count) {
127
return
kDtResetUnknown
;
128
}
129
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
130
}
131
132
(earlgrey)
hw
top
dt
dt_sram_ctrl.c
Return to
OpenTitan Documentation