Software APIs
dt_kmac.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 kmac and top earlgrey.
10
*/
11
12
#include "dt/dt_kmac.h"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_kmac
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
base_addr
[kDtKmacRegBlockCount];
/**< Base address of each register block */
22
/**
23
* PLIC ID of the first IRQ of this instance
24
*
25
* This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
26
*/
27
top_earlgrey_plic_irq_id_t
first_irq
;
28
/**
29
* Alert ID of the first Alert of this instance.
30
*
31
* This value is undefined if the block is not connected to the Alert Handler.
32
*/
33
top_earlgrey_alert_id_t
first_alert
;
34
dt_clock_t
clock
[kDtKmacClockCount];
/**< Clock signal connected to each clock port */
35
dt_reset_t
reset
[kDtKmacResetCount];
/**< Reset signal connected to each reset port */
36
}
dt_desc_kmac_t
;
37
38
39
40
41
static
const
dt_desc_kmac_t
kmac_desc[kDtKmacCount] = {
42
[
kDtKmac
] = {
43
.inst_id =
kDtInstanceIdKmac
,
44
.base_addr = {
45
[kDtKmacRegBlockCore] = 0x41120000,
46
},
47
.first_irq =
kTopEarlgreyPlicIrqIdKmacKmacDone
,
48
.first_alert =
kTopEarlgreyAlertIdKmacRecovOperationErr
,
49
.clock = {
50
[
kDtKmacClockClk
] =
kDtClockMain
,
51
[
kDtKmacClockEdn
] =
kDtClockMain
,
52
},
53
.reset = {
54
[
kDtKmacResetRst
] =
kDtResetLc
,
55
[
kDtKmacResetEdn
] =
kDtResetLc
,
56
},
57
},
58
};
59
60
/**
61
* Return a pointer to the `dt_kmac_desc_t` structure of the requested
62
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
63
* the function) with the provided default value.
64
*/
65
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_kmac_t)0 || (dt) >= kDtKmacCount) return (default); &kmac_desc[dt]; })
66
67
dt_kmac_t
dt_kmac_from_instance_id
(
dt_instance_id_t
inst_id) {
68
if
(inst_id >=
kDtInstanceIdKmac
&& inst_id <=
kDtInstanceIdKmac
) {
69
return
(
dt_kmac_t
)(inst_id -
kDtInstanceIdKmac
);
70
}
71
return
(
dt_kmac_t
)0;
72
}
73
74
dt_instance_id_t
dt_kmac_instance_id
(
75
dt_kmac_t
dt) {
76
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
77
}
78
79
uint32_t
dt_kmac_reg_block
(
80
dt_kmac_t
dt,
81
dt_kmac_reg_block_t
reg_block) {
82
// Return a recognizable address in case of wrong argument.
83
return
TRY_GET_DT
(dt, 0xdeadbeef)->base_addr[reg_block];
84
}
85
86
dt_plic_irq_id_t
dt_kmac_irq_to_plic_id
(
87
dt_kmac_t
dt,
88
dt_kmac_irq_t
irq) {
89
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, kDtPlicIrqIdNone)->first_irq;
90
if
(first_irq == kDtPlicIrqIdNone) {
91
return
kDtPlicIrqIdNone;
92
}
93
return
(
dt_plic_irq_id_t
)((uint32_t)first_irq + (uint32_t)irq);
94
}
95
96
dt_kmac_irq_t
dt_kmac_irq_from_plic_id
(
97
dt_kmac_t
dt,
98
dt_plic_irq_id_t
irq) {
99
dt_kmac_irq_t
count = kDtKmacIrqCount;
100
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, count)->first_irq;
101
if
(first_irq == kDtPlicIrqIdNone) {
102
return
count;
103
}
104
if
(irq < first_irq || irq >= first_irq + (
dt_plic_irq_id_t
)count) {
105
return
count;
106
}
107
return
(
dt_kmac_irq_t
)(irq - first_irq);
108
}
109
110
111
dt_alert_id_t
dt_kmac_alert_to_alert_id
(
112
dt_kmac_t
dt,
113
dt_kmac_alert_t
alert) {
114
return
(
dt_alert_id_t
)((uint32_t)kmac_desc[dt].first_alert + (uint32_t)alert);
115
}
116
117
dt_kmac_alert_t
dt_kmac_alert_from_alert_id
(
118
dt_kmac_t
dt,
119
dt_alert_id_t
alert) {
120
dt_kmac_alert_t
count = kDtKmacAlertCount;
121
if
(alert < kmac_desc[dt].first_alert || alert >= kmac_desc[dt].first_alert + (
dt_alert_id_t
)count) {
122
return
count;
123
}
124
return
(
dt_kmac_alert_t
)(alert - kmac_desc[dt].first_alert);
125
}
126
127
128
129
dt_clock_t
dt_kmac_clock
(
130
dt_kmac_t
dt,
131
dt_kmac_clock_t
clk) {
132
// Return the first clock in case of invalid argument.
133
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
134
}
135
136
dt_reset_t
dt_kmac_reset
(
137
dt_kmac_t
dt,
138
dt_kmac_reset_t
rst) {
139
const
dt_kmac_reset_t
count = kDtKmacResetCount;
140
if
(rst >= count) {
141
return
kDtResetUnknown
;
142
}
143
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
144
}
145
146
(earlgrey)
hw
top
dt
dt_kmac.c
Return to
OpenTitan Documentation