Software APIs
dt_soc_dbg_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 soc_dbg_ctrl and top darjeeling.
10
*/
11
12
#include "
hw/top/dt/dt_soc_dbg_ctrl.h
"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_soc_dbg_ctrl
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
reg_addr
[kDtSocDbgCtrlRegBlockCount];
/**< Base address of each register block */
22
uint32_t
mem_addr
[kDtSocDbgCtrlMemoryCount];
/**< Base address of each memory */
23
uint32_t
mem_size
[kDtSocDbgCtrlMemoryCount];
/**< 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_darjeeling_alert_id_t
first_alert
;
30
dt_clock_t
clock
[kDtSocDbgCtrlClockCount];
/**< Clock signal connected to each clock port */
31
dt_reset_t
reset
[kDtSocDbgCtrlResetCount];
/**< Reset signal connected to each reset port */
32
}
dt_desc_soc_dbg_ctrl_t
;
33
34
35
36
37
static
const
dt_desc_soc_dbg_ctrl_t
soc_dbg_ctrl_desc[kDtSocDbgCtrlCount] = {
38
[
kDtSocDbgCtrl
] = {
39
.inst_id =
kDtInstanceIdSocDbgCtrl
,
40
.reg_addr = {
41
[kDtSocDbgCtrlRegBlockCore] = 0x30170000,
42
[kDtSocDbgCtrlRegBlockJtag] = 0xffffffff,
43
},
44
.mem_addr = {
45
},
46
.mem_size = {
47
},
48
.first_alert =
kTopDarjeelingAlertIdSocDbgCtrlFatalFault
,
49
.clock = {
50
[
kDtSocDbgCtrlClockClk
] =
kDtClockIoDiv4
,
51
},
52
.reset = {
53
[
kDtSocDbgCtrlResetRst
] =
kDtResetLcIoDiv4
,
54
},
55
},
56
};
57
58
/**
59
* Return a pointer to the `dt_soc_dbg_ctrl_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_soc_dbg_ctrl_t)0 || (dt) >= kDtSocDbgCtrlCount) return (default); &soc_dbg_ctrl_desc[dt]; })
64
65
dt_soc_dbg_ctrl_t
dt_soc_dbg_ctrl_from_instance_id
(
dt_instance_id_t
inst_id) {
66
if
(inst_id >=
kDtInstanceIdSocDbgCtrl
&& inst_id <=
kDtInstanceIdSocDbgCtrl
) {
67
return
(
dt_soc_dbg_ctrl_t
)(inst_id -
kDtInstanceIdSocDbgCtrl
);
68
}
69
return
(
dt_soc_dbg_ctrl_t
)0;
70
}
71
72
dt_instance_id_t
dt_soc_dbg_ctrl_instance_id
(
73
dt_soc_dbg_ctrl_t
dt) {
74
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
75
}
76
77
uint32_t
dt_soc_dbg_ctrl_reg_block
(
78
dt_soc_dbg_ctrl_t
dt,
79
dt_soc_dbg_ctrl_reg_block_t
reg_block) {
80
// Return a recognizable address in case of wrong argument.
81
return
TRY_GET_DT
(dt, 0xdeadbeef)->reg_addr[reg_block];
82
}
83
84
uint32_t
dt_soc_dbg_ctrl_memory_base
(
85
dt_soc_dbg_ctrl_t
dt,
86
dt_soc_dbg_ctrl_memory_t
mem) {
87
// Return a recognizable address in case of wrong argument.
88
return
TRY_GET_DT
(dt, 0xdeadbeef)->mem_addr[mem];
89
}
90
91
uint32_t
dt_soc_dbg_ctrl_memory_size
(
92
dt_soc_dbg_ctrl_t
dt,
93
dt_soc_dbg_ctrl_memory_t
mem) {
94
// Return an empty size in case of wrong argument.
95
return
TRY_GET_DT
(dt, 0)->mem_size[mem];
96
}
97
98
99
dt_alert_id_t
dt_soc_dbg_ctrl_alert_to_alert_id
(
100
dt_soc_dbg_ctrl_t
dt,
101
dt_soc_dbg_ctrl_alert_t
alert) {
102
return
(
dt_alert_id_t
)((uint32_t)soc_dbg_ctrl_desc[dt].first_alert + (uint32_t)alert);
103
}
104
105
dt_soc_dbg_ctrl_alert_t
dt_soc_dbg_ctrl_alert_from_alert_id
(
106
dt_soc_dbg_ctrl_t
dt,
107
dt_alert_id_t
alert) {
108
dt_soc_dbg_ctrl_alert_t
count = kDtSocDbgCtrlAlertCount;
109
if
(alert < soc_dbg_ctrl_desc[dt].first_alert || alert >= soc_dbg_ctrl_desc[dt].first_alert + (
dt_alert_id_t
)count) {
110
return
count;
111
}
112
return
(
dt_soc_dbg_ctrl_alert_t
)(alert - soc_dbg_ctrl_desc[dt].first_alert);
113
}
114
115
116
117
dt_clock_t
dt_soc_dbg_ctrl_clock
(
118
dt_soc_dbg_ctrl_t
dt,
119
dt_soc_dbg_ctrl_clock_t
clk) {
120
// Return the first clock in case of invalid argument.
121
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
122
}
123
124
dt_reset_t
dt_soc_dbg_ctrl_reset
(
125
dt_soc_dbg_ctrl_t
dt,
126
dt_soc_dbg_ctrl_reset_t
rst) {
127
const
dt_soc_dbg_ctrl_reset_t
count = kDtSocDbgCtrlResetCount;
128
if
(rst >= count) {
129
return
kDtResetUnknown
;
130
}
131
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
132
}
133
134
(darjeeling)
hw
top
dt
dt_soc_dbg_ctrl.c
Return to
OpenTitan Documentation