Software APIs
dt_hmac.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 hmac and top earlgrey.
10
*/
11
12
#include "dt/dt_hmac.h"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_hmac
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
base_addr
[kDtHmacRegBlockCount];
/**< 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
[kDtHmacClockCount];
/**< Clock signal connected to each clock port */
35
dt_reset_t
reset
[kDtHmacResetCount];
/**< Reset signal connected to each reset port */
36
}
dt_desc_hmac_t
;
37
38
39
40
41
static
const
dt_desc_hmac_t
hmac_desc[kDtHmacCount] = {
42
[
kDtHmac
] = {
43
.inst_id =
kDtInstanceIdHmac
,
44
.base_addr = {
45
[kDtHmacRegBlockCore] = 0x41110000,
46
},
47
.first_irq =
kTopEarlgreyPlicIrqIdHmacHmacDone
,
48
.first_alert =
kTopEarlgreyAlertIdHmacFatalFault
,
49
.clock = {
50
[
kDtHmacClockClk
] =
kDtClockMain
,
51
},
52
.reset = {
53
[
kDtHmacResetRst
] =
kDtResetLc
,
54
},
55
},
56
};
57
58
/**
59
* Return a pointer to the `dt_hmac_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_hmac_t)0 || (dt) >= kDtHmacCount) return (default); &hmac_desc[dt]; })
64
65
dt_hmac_t
dt_hmac_from_instance_id
(
dt_instance_id_t
inst_id) {
66
if
(inst_id >=
kDtInstanceIdHmac
&& inst_id <=
kDtInstanceIdHmac
) {
67
return
(
dt_hmac_t
)(inst_id -
kDtInstanceIdHmac
);
68
}
69
return
(
dt_hmac_t
)0;
70
}
71
72
dt_instance_id_t
dt_hmac_instance_id
(
73
dt_hmac_t
dt) {
74
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
75
}
76
77
uint32_t
dt_hmac_reg_block
(
78
dt_hmac_t
dt,
79
dt_hmac_reg_block_t
reg_block) {
80
// Return a recognizable address in case of wrong argument.
81
return
TRY_GET_DT
(dt, 0xdeadbeef)->base_addr[reg_block];
82
}
83
84
dt_plic_irq_id_t
dt_hmac_irq_to_plic_id
(
85
dt_hmac_t
dt,
86
dt_hmac_irq_t
irq) {
87
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, kDtPlicIrqIdNone)->first_irq;
88
if
(first_irq == kDtPlicIrqIdNone) {
89
return
kDtPlicIrqIdNone;
90
}
91
return
(
dt_plic_irq_id_t
)((uint32_t)first_irq + (uint32_t)irq);
92
}
93
94
dt_hmac_irq_t
dt_hmac_irq_from_plic_id
(
95
dt_hmac_t
dt,
96
dt_plic_irq_id_t
irq) {
97
dt_hmac_irq_t
count = kDtHmacIrqCount;
98
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, count)->first_irq;
99
if
(first_irq == kDtPlicIrqIdNone) {
100
return
count;
101
}
102
if
(irq < first_irq || irq >= first_irq + (
dt_plic_irq_id_t
)count) {
103
return
count;
104
}
105
return
(
dt_hmac_irq_t
)(irq - first_irq);
106
}
107
108
109
dt_alert_id_t
dt_hmac_alert_to_alert_id
(
110
dt_hmac_t
dt,
111
dt_hmac_alert_t
alert) {
112
return
(
dt_alert_id_t
)((uint32_t)hmac_desc[dt].first_alert + (uint32_t)alert);
113
}
114
115
dt_hmac_alert_t
dt_hmac_alert_from_alert_id
(
116
dt_hmac_t
dt,
117
dt_alert_id_t
alert) {
118
dt_hmac_alert_t
count = kDtHmacAlertCount;
119
if
(alert < hmac_desc[dt].first_alert || alert >= hmac_desc[dt].first_alert + (
dt_alert_id_t
)count) {
120
return
count;
121
}
122
return
(
dt_hmac_alert_t
)(alert - hmac_desc[dt].first_alert);
123
}
124
125
126
127
dt_clock_t
dt_hmac_clock
(
128
dt_hmac_t
dt,
129
dt_hmac_clock_t
clk) {
130
// Return the first clock in case of invalid argument.
131
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
132
}
133
134
dt_reset_t
dt_hmac_reset
(
135
dt_hmac_t
dt,
136
dt_hmac_reset_t
rst) {
137
const
dt_hmac_reset_t
count = kDtHmacResetCount;
138
if
(rst >= count) {
139
return
kDtResetUnknown
;
140
}
141
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
142
}
143
144
(earlgrey)
hw
top
dt
dt_hmac.c
Return to
OpenTitan Documentation