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 "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 base_addr[kDtCsrngRegBlockCount]; /**< 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[kDtCsrngClockCount]; /**< Clock signal connected to each clock port */
35 dt_reset_t reset[kDtCsrngResetCount]; /**< Reset signal connected to each reset port */
37
38
39
40
41static const dt_desc_csrng_t csrng_desc[kDtCsrngCount] = {
42 [kDtCsrng] = {
43 .inst_id = kDtInstanceIdCsrng,
44 .base_addr = {
45 [kDtCsrngRegBlockCore] = 0x41150000,
46 },
49 .clock = {
51 },
52 .reset = {
54 },
55 },
56};
57
58/**
59 * Return a pointer to the `dt_csrng_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_csrng_t)0 || (dt) >= kDtCsrngCount) return (default); &csrng_desc[dt]; })
64
66 if (inst_id >= kDtInstanceIdCsrng && inst_id <= kDtInstanceIdCsrng) {
67 return (dt_csrng_t)(inst_id - kDtInstanceIdCsrng);
68 }
69 return (dt_csrng_t)0;
70}
71
76
78 dt_csrng_t dt,
79 dt_csrng_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
85 dt_csrng_t dt,
86 dt_csrng_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
95 dt_csrng_t dt,
96 dt_plic_irq_id_t irq) {
97 dt_csrng_irq_t count = kDtCsrngIrqCount;
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_csrng_irq_t)(irq - first_irq);
106}
107
108
110 dt_csrng_t dt,
111 dt_csrng_alert_t alert) {
112 return (dt_alert_id_t)((uint32_t)csrng_desc[dt].first_alert + (uint32_t)alert);
113}
114
116 dt_csrng_t dt,
117 dt_alert_id_t alert) {
118 dt_csrng_alert_t count = kDtCsrngAlertCount;
119 if (alert < csrng_desc[dt].first_alert || alert >= csrng_desc[dt].first_alert + (dt_alert_id_t)count) {
120 return count;
121 }
122 return (dt_csrng_alert_t)(alert - csrng_desc[dt].first_alert);
123}
124
125
126
128 dt_csrng_t dt,
129 dt_csrng_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
135 dt_csrng_t dt,
136 dt_csrng_reset_t rst) {
137 const dt_csrng_reset_t count = kDtCsrngResetCount;
138 if (rst >= count) {
139 return kDtResetUnknown;
140 }
141 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
142}
143
144