Software APIs
dt_rom_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 rom_ctrl and top earlgrey.
10
*/
11
12
#include "dt/dt_rom_ctrl.h"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_rom_ctrl
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
base_addr
[kDtRomCtrlRegBlockCount];
/**< 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
[kDtRomCtrlClockCount];
/**< Clock signal connected to each clock port */
29
dt_reset_t
reset
[kDtRomCtrlResetCount];
/**< Reset signal connected to each reset port */
30
}
dt_desc_rom_ctrl_t
;
31
32
33
34
35
static
const
dt_desc_rom_ctrl_t
rom_ctrl_desc[kDtRomCtrlCount] = {
36
[
kDtRomCtrl
] = {
37
.inst_id =
kDtInstanceIdRomCtrl
,
38
.base_addr = {
39
[kDtRomCtrlRegBlockRom] = 0x00008000,
40
[kDtRomCtrlRegBlockRegs] = 0x411e0000,
41
},
42
.first_alert =
kTopEarlgreyAlertIdRomCtrlFatal
,
43
.clock = {
44
[
kDtRomCtrlClockClk
] =
kDtClockMain
,
45
},
46
.reset = {
47
[
kDtRomCtrlResetRst
] =
kDtResetLc
,
48
},
49
},
50
};
51
52
/**
53
* Return a pointer to the `dt_rom_ctrl_desc_t` structure of the requested
54
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
55
* the function) with the provided default value.
56
*/
57
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_rom_ctrl_t)0 || (dt) >= kDtRomCtrlCount) return (default); &rom_ctrl_desc[dt]; })
58
59
dt_rom_ctrl_t
dt_rom_ctrl_from_instance_id
(
dt_instance_id_t
inst_id) {
60
if
(inst_id >=
kDtInstanceIdRomCtrl
&& inst_id <=
kDtInstanceIdRomCtrl
) {
61
return
(
dt_rom_ctrl_t
)(inst_id -
kDtInstanceIdRomCtrl
);
62
}
63
return
(
dt_rom_ctrl_t
)0;
64
}
65
66
dt_instance_id_t
dt_rom_ctrl_instance_id
(
67
dt_rom_ctrl_t
dt) {
68
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
69
}
70
71
uint32_t
dt_rom_ctrl_reg_block
(
72
dt_rom_ctrl_t
dt,
73
dt_rom_ctrl_reg_block_t
reg_block) {
74
// Return a recognizable address in case of wrong argument.
75
return
TRY_GET_DT
(dt, 0xdeadbeef)->base_addr[reg_block];
76
}
77
78
79
dt_alert_id_t
dt_rom_ctrl_alert_to_alert_id
(
80
dt_rom_ctrl_t
dt,
81
dt_rom_ctrl_alert_t
alert) {
82
return
(
dt_alert_id_t
)((uint32_t)rom_ctrl_desc[dt].first_alert + (uint32_t)alert);
83
}
84
85
dt_rom_ctrl_alert_t
dt_rom_ctrl_alert_from_alert_id
(
86
dt_rom_ctrl_t
dt,
87
dt_alert_id_t
alert) {
88
dt_rom_ctrl_alert_t
count = kDtRomCtrlAlertCount;
89
if
(alert < rom_ctrl_desc[dt].first_alert || alert >= rom_ctrl_desc[dt].first_alert + (
dt_alert_id_t
)count) {
90
return
count;
91
}
92
return
(
dt_rom_ctrl_alert_t
)(alert - rom_ctrl_desc[dt].first_alert);
93
}
94
95
96
97
dt_clock_t
dt_rom_ctrl_clock
(
98
dt_rom_ctrl_t
dt,
99
dt_rom_ctrl_clock_t
clk) {
100
// Return the first clock in case of invalid argument.
101
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
102
}
103
104
dt_reset_t
dt_rom_ctrl_reset
(
105
dt_rom_ctrl_t
dt,
106
dt_rom_ctrl_reset_t
rst) {
107
const
dt_rom_ctrl_reset_t
count = kDtRomCtrlResetCount;
108
if
(rst >= count) {
109
return
kDtResetUnknown
;
110
}
111
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
112
}
113
114
(earlgrey)
hw
top
dt
dt_rom_ctrl.c
Return to
OpenTitan Documentation