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 */
19typedef 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 */
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 */
31
32
33
34
35static const dt_desc_aes_t aes_desc[kDtAesCount] = {
36 [kDtAes] = {
37 .inst_id = kDtInstanceIdAes,
38 .base_addr = {
39 [kDtAesRegBlockCore] = 0x41100000,
40 },
42 .clock = {
45 },
46 .reset = {
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
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
71
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
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
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
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
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