Software APIs
dt_entropy_src.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 entropy_src and top earlgrey.
10 */
11
12#include "dt/dt_entropy_src.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_entropy_src {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t base_addr[kDtEntropySrcRegBlockCount]; /**< 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[kDtEntropySrcClockCount]; /**< Clock signal connected to each clock port */
35 dt_reset_t reset[kDtEntropySrcResetCount]; /**< Reset signal connected to each reset port */
37
38
39
40
41static const dt_desc_entropy_src_t entropy_src_desc[kDtEntropySrcCount] = {
42 [kDtEntropySrc] = {
43 .inst_id = kDtInstanceIdEntropySrc,
44 .base_addr = {
45 [kDtEntropySrcRegBlockCore] = 0x41160000,
46 },
49 .clock = {
51 },
52 .reset = {
54 },
55 },
56};
57
58/**
59 * Return a pointer to the `dt_entropy_src_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_entropy_src_t)0 || (dt) >= kDtEntropySrcCount) return (default); &entropy_src_desc[dt]; })
64
71
76
80 // Return a recognizable address in case of wrong argument.
81 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
82}
83
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
96 dt_plic_irq_id_t irq) {
97 dt_entropy_src_irq_t count = kDtEntropySrcIrqCount;
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_entropy_src_irq_t)(irq - first_irq);
106}
107
108
112 return (dt_alert_id_t)((uint32_t)entropy_src_desc[dt].first_alert + (uint32_t)alert);
113}
114
117 dt_alert_id_t alert) {
118 dt_entropy_src_alert_t count = kDtEntropySrcAlertCount;
119 if (alert < entropy_src_desc[dt].first_alert || alert >= entropy_src_desc[dt].first_alert + (dt_alert_id_t)count) {
120 return count;
121 }
122 return (dt_entropy_src_alert_t)(alert - entropy_src_desc[dt].first_alert);
123}
124
125
126
130 // Return the first clock in case of invalid argument.
131 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
132}
133
137 const dt_entropy_src_reset_t count = kDtEntropySrcResetCount;
138 if (rst >= count) {
139 return kDtResetUnknown;
140 }
141 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
142}
143
144