Software APIs
dt_ac_range_check.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 ac_range_check and top darjeeling.
10 */
11
13
14
15
16
17
18/**
19 * Description of instances.
20 */
21typedef struct dt_desc_ac_range_check {
22 dt_instance_id_t inst_id; /**< Instance ID */
23 uint32_t reg_addr[kDtAcRangeCheckRegBlockCount]; /**< Base address of each register block */
24 uint32_t mem_addr[kDtAcRangeCheckMemoryCount]; /**< Base address of each memory */
25 uint32_t mem_size[kDtAcRangeCheckMemoryCount]; /**< Size in bytes of each memory */
26 /**
27 * PLIC ID of the first IRQ of this instance
28 *
29 * This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
30 */
32 /**
33 * Alert ID of the first Alert of this instance.
34 *
35 * This value is undefined if the block is not connected to the Alert Handler.
36 */
38 dt_clock_t clock[kDtAcRangeCheckClockCount]; /**< Clock signal connected to each clock port */
39 dt_reset_t reset[kDtAcRangeCheckResetCount]; /**< Reset signal connected to each reset port */
40 struct {
41 uint8_t num_ranges; /**< Number of range registers */
42 } ipgen_ext; /**< Extension */
44
45
46
47
48static const dt_desc_ac_range_check_t ac_range_check_desc[kDtAcRangeCheckCount] = {
49 [kDtAcRangeCheck] = {
51 .reg_addr = {
52 [kDtAcRangeCheckRegBlockCore] = 0xffffffff,
53 },
54 .mem_addr = {
55 },
56 .mem_size = {
57 },
60 .clock = {
62 },
63 .reset = {
65 },
66 .ipgen_ext = {
67 .num_ranges = 32,
68 },
69 },
70};
71
72/**
73 * Return a pointer to the `dt_ac_range_check_desc_t` structure of the requested
74 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
75 * the function) with the provided default value.
76 */
77#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_ac_range_check_t)0 || (dt) >= kDtAcRangeCheckCount) return (default); &ac_range_check_desc[dt]; })
78
85
90
94 // Return a recognizable address in case of wrong argument.
95 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
96}
97
101 // Return a recognizable address in case of wrong argument.
102 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
103}
104
108 // Return an empty size in case of wrong argument.
109 return TRY_GET_DT(dt, 0)->mem_size[mem];
110}
111
115 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
116 if (first_irq == kDtPlicIrqIdNone) {
117 return kDtPlicIrqIdNone;
118 }
119 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
120}
121
124 dt_plic_irq_id_t irq) {
125 dt_ac_range_check_irq_t count = kDtAcRangeCheckIrqCount;
126 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
127 if (first_irq == kDtPlicIrqIdNone) {
128 return count;
129 }
130 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
131 return count;
132 }
133 return (dt_ac_range_check_irq_t)(irq - first_irq);
134}
135
136
140 return (dt_alert_id_t)((uint32_t)ac_range_check_desc[dt].first_alert + (uint32_t)alert);
141}
142
145 dt_alert_id_t alert) {
146 dt_ac_range_check_alert_t count = kDtAcRangeCheckAlertCount;
147 if (alert < ac_range_check_desc[dt].first_alert || alert >= ac_range_check_desc[dt].first_alert + (dt_alert_id_t)count) {
148 return count;
149 }
150 return (dt_ac_range_check_alert_t)(alert - ac_range_check_desc[dt].first_alert);
151}
152
153
154
158 // Return the first clock in case of invalid argument.
159 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
160}
161
165 const dt_ac_range_check_reset_t count = kDtAcRangeCheckResetCount;
166 if (rst >= count) {
167 return kDtResetUnknown;
168 }
169 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
170}
171
172
173
175 return TRY_GET_DT(dt, 0)->ipgen_ext.num_ranges;
176}
177
178