Software APIs
dt_rv_dm.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 rv_dm and top darjeeling.
10
*/
11
12
#include "hw/top/dt/dt_rv_dm.h"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_rv_dm
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
reg_addr
[kDtRvDmRegBlockCount];
/**< Base address of each register block */
22
uint32_t
mem_addr
[kDtRvDmMemoryCount];
/**< Base address of each memory */
23
uint32_t
mem_size
[kDtRvDmMemoryCount];
/**< 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
[kDtRvDmClockCount];
/**< Clock signal connected to each clock port */
31
dt_reset_t
reset
[kDtRvDmResetCount];
/**< Reset signal connected to each reset port */
32
}
dt_desc_rv_dm_t
;
33
34
35
36
37
static
const
dt_desc_rv_dm_t
rv_dm_desc[kDtRvDmCount] = {
38
[
kDtRvDm
] = {
39
.inst_id =
kDtInstanceIdRvDm
,
40
.reg_addr = {
41
[kDtRvDmRegBlockRegs] = 0x21200000,
42
[kDtRvDmRegBlockMem] = 0x00040000,
43
[kDtRvDmRegBlockDbg] = 0xffffffff,
44
},
45
.mem_addr = {
46
},
47
.mem_size = {
48
},
49
.first_alert =
kTopDarjeelingAlertIdRvDmFatalFault
,
50
.clock = {
51
[
kDtRvDmClockClk
] =
kDtClockMain
,
52
[
kDtRvDmClockLc
] =
kDtClockMain
,
53
},
54
.reset = {
55
[
kDtRvDmResetRst
] =
kDtResetSys
,
56
[
kDtRvDmResetLc
] =
kDtResetLc
,
57
},
58
},
59
};
60
61
/**
62
* Return a pointer to the `dt_rv_dm_desc_t` structure of the requested
63
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
64
* the function) with the provided default value.
65
*/
66
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_rv_dm_t)0 || (dt) >= kDtRvDmCount) return (default); &rv_dm_desc[dt]; })
67
68
dt_rv_dm_t
dt_rv_dm_from_instance_id
(
dt_instance_id_t
inst_id) {
69
if
(inst_id >=
kDtInstanceIdRvDm
&& inst_id <=
kDtInstanceIdRvDm
) {
70
return
(
dt_rv_dm_t
)(inst_id -
kDtInstanceIdRvDm
);
71
}
72
return
(
dt_rv_dm_t
)0;
73
}
74
75
dt_instance_id_t
dt_rv_dm_instance_id
(
76
dt_rv_dm_t
dt) {
77
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
78
}
79
80
uint32_t
dt_rv_dm_reg_block
(
81
dt_rv_dm_t
dt,
82
dt_rv_dm_reg_block_t
reg_block) {
83
// Return a recognizable address in case of wrong argument.
84
return
TRY_GET_DT
(dt, 0xdeadbeef)->reg_addr[reg_block];
85
}
86
87
uint32_t
dt_rv_dm_memory_base
(
88
dt_rv_dm_t
dt,
89
dt_rv_dm_memory_t
mem) {
90
// Return a recognizable address in case of wrong argument.
91
return
TRY_GET_DT
(dt, 0xdeadbeef)->mem_addr[mem];
92
}
93
94
uint32_t
dt_rv_dm_memory_size
(
95
dt_rv_dm_t
dt,
96
dt_rv_dm_memory_t
mem) {
97
// Return an empty size in case of wrong argument.
98
return
TRY_GET_DT
(dt, 0)->mem_size[mem];
99
}
100
101
102
dt_alert_id_t
dt_rv_dm_alert_to_alert_id
(
103
dt_rv_dm_t
dt,
104
dt_rv_dm_alert_t
alert) {
105
return
(
dt_alert_id_t
)((uint32_t)rv_dm_desc[dt].first_alert + (uint32_t)alert);
106
}
107
108
dt_rv_dm_alert_t
dt_rv_dm_alert_from_alert_id
(
109
dt_rv_dm_t
dt,
110
dt_alert_id_t
alert) {
111
dt_rv_dm_alert_t
count = kDtRvDmAlertCount;
112
if
(alert < rv_dm_desc[dt].first_alert || alert >= rv_dm_desc[dt].first_alert + (
dt_alert_id_t
)count) {
113
return
count;
114
}
115
return
(
dt_rv_dm_alert_t
)(alert - rv_dm_desc[dt].first_alert);
116
}
117
118
119
120
dt_clock_t
dt_rv_dm_clock
(
121
dt_rv_dm_t
dt,
122
dt_rv_dm_clock_t
clk) {
123
// Return the first clock in case of invalid argument.
124
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
125
}
126
127
dt_reset_t
dt_rv_dm_reset
(
128
dt_rv_dm_t
dt,
129
dt_rv_dm_reset_t
rst) {
130
const
dt_rv_dm_reset_t
count = kDtRvDmResetCount;
131
if
(rst >= count) {
132
return
kDtResetUnknown
;
133
}
134
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
135
}
136
137
(darjeeling)
hw
top
dt
dt_rv_dm.c
Return to
OpenTitan Documentation