Software APIs
dt_otbn.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 otbn and top earlgrey.
10 */
11
12#include "dt/dt_otbn.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_otbn {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t base_addr[kDtOtbnRegBlockCount]; /**< 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 */
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 */
34 dt_clock_t clock[kDtOtbnClockCount]; /**< Clock signal connected to each clock port */
35 dt_reset_t reset[kDtOtbnResetCount]; /**< Reset signal connected to each reset port */
37
38
39
40
41static const dt_desc_otbn_t otbn_desc[kDtOtbnCount] = {
42 [kDtOtbn] = {
43 .inst_id = kDtInstanceIdOtbn,
44 .base_addr = {
45 [kDtOtbnRegBlockCore] = 0x41130000,
46 },
48 .first_alert = kTopEarlgreyAlertIdOtbnFatal,
49 .clock = {
53 },
54 .reset = {
58 },
59 },
60};
61
62/**
63 * Return a pointer to the `dt_otbn_desc_t` structure of the requested
64 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
65 * the function) with the provided default value.
66 */
67#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_otbn_t)0 || (dt) >= kDtOtbnCount) return (default); &otbn_desc[dt]; })
68
70 if (inst_id >= kDtInstanceIdOtbn && inst_id <= kDtInstanceIdOtbn) {
71 return (dt_otbn_t)(inst_id - kDtInstanceIdOtbn);
72 }
73 return (dt_otbn_t)0;
74}
75
80
82 dt_otbn_t dt,
83 dt_otbn_reg_block_t reg_block) {
84 // Return a recognizable address in case of wrong argument.
85 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
86}
87
89 dt_otbn_t dt,
90 dt_otbn_irq_t irq) {
91 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
92 if (first_irq == kDtPlicIrqIdNone) {
93 return kDtPlicIrqIdNone;
94 }
95 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
96}
97
99 dt_otbn_t dt,
100 dt_plic_irq_id_t irq) {
101 dt_otbn_irq_t count = kDtOtbnIrqCount;
102 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
103 if (first_irq == kDtPlicIrqIdNone) {
104 return count;
105 }
106 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
107 return count;
108 }
109 return (dt_otbn_irq_t)(irq - first_irq);
110}
111
112
114 dt_otbn_t dt,
115 dt_otbn_alert_t alert) {
116 return (dt_alert_id_t)((uint32_t)otbn_desc[dt].first_alert + (uint32_t)alert);
117}
118
120 dt_otbn_t dt,
121 dt_alert_id_t alert) {
122 dt_otbn_alert_t count = kDtOtbnAlertCount;
123 if (alert < otbn_desc[dt].first_alert || alert >= otbn_desc[dt].first_alert + (dt_alert_id_t)count) {
124 return count;
125 }
126 return (dt_otbn_alert_t)(alert - otbn_desc[dt].first_alert);
127}
128
129
130
132 dt_otbn_t dt,
133 dt_otbn_clock_t clk) {
134 // Return the first clock in case of invalid argument.
135 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
136}
137
139 dt_otbn_t dt,
140 dt_otbn_reset_t rst) {
141 const dt_otbn_reset_t count = kDtOtbnResetCount;
142 if (rst >= count) {
143 return kDtResetUnknown;
144 }
145 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
146}
147
148