Software APIs
dt_csrng.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 csrng and top earlgrey.
10 */
11
12#include "hw/top/dt/dt_csrng.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_csrng {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t reg_addr[kDtCsrngRegBlockCount]; /**< Base address of each register block */
22 uint32_t mem_addr[kDtCsrngMemoryCount]; /**< Base address of each memory */
23 uint32_t mem_size[kDtCsrngMemoryCount]; /**< Size in bytes of each memory */
24 /**
25 * PLIC ID of the first IRQ of this instance
26 *
27 * This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
28 */
30 /**
31 * Alert ID of the first Alert of this instance.
32 *
33 * This value is undefined if the block is not connected to the Alert Handler.
34 */
36 dt_clock_t clock[kDtCsrngClockCount]; /**< Clock signal connected to each clock port */
37 dt_reset_t reset[kDtCsrngResetCount]; /**< Reset signal connected to each reset port */
39
40
41
42
43static const dt_desc_csrng_t csrng_desc[kDtCsrngCount] = {
44 [kDtCsrng] = {
45 .inst_id = kDtInstanceIdCsrng,
46 .reg_addr = {
47 [kDtCsrngRegBlockCore] = 0x41150000,
48 },
49 .mem_addr = {
50 },
51 .mem_size = {
52 },
55 .clock = {
57 },
58 .reset = {
60 },
61 },
62};
63
64/**
65 * Return a pointer to the `dt_csrng_desc_t` structure of the requested
66 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
67 * the function) with the provided default value.
68 */
69#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_csrng_t)0 || (dt) >= kDtCsrngCount) return (default); &csrng_desc[dt]; })
70
72 if (inst_id >= kDtInstanceIdCsrng && inst_id <= kDtInstanceIdCsrng) {
73 return (dt_csrng_t)(inst_id - kDtInstanceIdCsrng);
74 }
75 return (dt_csrng_t)0;
76}
77
82
84 dt_csrng_t dt,
85 dt_csrng_reg_block_t reg_block) {
86 // Return a recognizable address in case of wrong argument.
87 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
88}
89
91 dt_csrng_t dt,
93 // Return a recognizable address in case of wrong argument.
94 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
95}
96
98 dt_csrng_t dt,
100 // Return an empty size in case of wrong argument.
101 return TRY_GET_DT(dt, 0)->mem_size[mem];
102}
103
105 dt_csrng_t dt,
106 dt_csrng_irq_t irq) {
107 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
108 if (first_irq == kDtPlicIrqIdNone) {
109 return kDtPlicIrqIdNone;
110 }
111 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
112}
113
115 dt_csrng_t dt,
116 dt_plic_irq_id_t irq) {
117 dt_csrng_irq_t count = kDtCsrngIrqCount;
118 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
119 if (first_irq == kDtPlicIrqIdNone) {
120 return count;
121 }
122 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
123 return count;
124 }
125 return (dt_csrng_irq_t)(irq - first_irq);
126}
127
128
130 dt_csrng_t dt,
131 dt_csrng_alert_t alert) {
132 return (dt_alert_id_t)((uint32_t)csrng_desc[dt].first_alert + (uint32_t)alert);
133}
134
136 dt_csrng_t dt,
137 dt_alert_id_t alert) {
138 dt_csrng_alert_t count = kDtCsrngAlertCount;
139 if (alert < csrng_desc[dt].first_alert || alert >= csrng_desc[dt].first_alert + (dt_alert_id_t)count) {
140 return count;
141 }
142 return (dt_csrng_alert_t)(alert - csrng_desc[dt].first_alert);
143}
144
145
146
148 dt_csrng_t dt,
149 dt_csrng_clock_t clk) {
150 // Return the first clock in case of invalid argument.
151 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
152}
153
155 dt_csrng_t dt,
156 dt_csrng_reset_t rst) {
157 const dt_csrng_reset_t count = kDtCsrngResetCount;
158 if (rst >= count) {
159 return kDtResetUnknown;
160 }
161 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
162}
163
164