Software APIs
dt_aes.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 aes and top earlgrey.
10
*/
11
12
#include "dt/dt_aes.h"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_aes
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
base_addr
[kDtAesRegBlockCount];
/**< 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
[kDtAesClockCount];
/**< Clock signal connected to each clock port */
29
dt_reset_t
reset
[kDtAesResetCount];
/**< Reset signal connected to each reset port */
30
}
dt_desc_aes_t
;
31
32
33
34
35
static
const
dt_desc_aes_t
aes_desc[kDtAesCount] = {
36
[
kDtAes
] = {
37
.inst_id =
kDtInstanceIdAes
,
38
.base_addr = {
39
[kDtAesRegBlockCore] = 0x41100000,
40
},
41
.first_alert =
kTopEarlgreyAlertIdAesRecovCtrlUpdateErr
,
42
.clock = {
43
[
kDtAesClockClk
] =
kDtClockMain
,
44
[
kDtAesClockEdn
] =
kDtClockMain
,
45
},
46
.reset = {
47
[
kDtAesResetRst
] =
kDtResetLc
,
48
[
kDtAesResetEdn
] =
kDtResetLc
,
49
},
50
},
51
};
52
53
/**
54
* Return a pointer to the `dt_aes_desc_t` structure of the requested
55
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
56
* the function) with the provided default value.
57
*/
58
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_aes_t)0 || (dt) >= kDtAesCount) return (default); &aes_desc[dt]; })
59
60
dt_aes_t
dt_aes_from_instance_id
(
dt_instance_id_t
inst_id) {
61
if
(inst_id >=
kDtInstanceIdAes
&& inst_id <=
kDtInstanceIdAes
) {
62
return
(
dt_aes_t
)(inst_id -
kDtInstanceIdAes
);
63
}
64
return
(
dt_aes_t
)0;
65
}
66
67
dt_instance_id_t
dt_aes_instance_id
(
68
dt_aes_t
dt) {
69
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
70
}
71
72
uint32_t
dt_aes_reg_block
(
73
dt_aes_t
dt,
74
dt_aes_reg_block_t
reg_block) {
75
// Return a recognizable address in case of wrong argument.
76
return
TRY_GET_DT
(dt, 0xdeadbeef)->base_addr[reg_block];
77
}
78
79
80
dt_alert_id_t
dt_aes_alert_to_alert_id
(
81
dt_aes_t
dt,
82
dt_aes_alert_t
alert) {
83
return
(
dt_alert_id_t
)((uint32_t)aes_desc[dt].first_alert + (uint32_t)alert);
84
}
85
86
dt_aes_alert_t
dt_aes_alert_from_alert_id
(
87
dt_aes_t
dt,
88
dt_alert_id_t
alert) {
89
dt_aes_alert_t
count = kDtAesAlertCount;
90
if
(alert < aes_desc[dt].first_alert || alert >= aes_desc[dt].first_alert + (
dt_alert_id_t
)count) {
91
return
count;
92
}
93
return
(
dt_aes_alert_t
)(alert - aes_desc[dt].first_alert);
94
}
95
96
97
98
dt_clock_t
dt_aes_clock
(
99
dt_aes_t
dt,
100
dt_aes_clock_t
clk) {
101
// Return the first clock in case of invalid argument.
102
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
103
}
104
105
dt_reset_t
dt_aes_reset
(
106
dt_aes_t
dt,
107
dt_aes_reset_t
rst) {
108
const
dt_aes_reset_t
count = kDtAesResetCount;
109
if
(rst >= count) {
110
return
kDtResetUnknown
;
111
}
112
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
113
}
114
115
(earlgrey)
hw
top
dt
dt_aes.c
Return to
OpenTitan Documentation