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 base_addr[kDtAcRangeCheckRegBlockCount]; /**< Base address of each register block */
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[kDtAcRangeCheckClockCount]; /**< Clock signal connected to each clock port */
37 dt_reset_t reset[kDtAcRangeCheckResetCount]; /**< Reset signal connected to each reset port */
38 struct {
39 uint8_t num_ranges; /**< Number of range registers */
40 } ipgen_ext; /**< Extension */
42
43
44
45
46static const dt_desc_ac_range_check_t ac_range_check_desc[kDtAcRangeCheckCount] = {
47 [kDtAcRangeCheck] = {
49 .base_addr = {
50 [kDtAcRangeCheckRegBlockCore] = 0xffffffff,
51 },
54 .clock = {
56 },
57 .reset = {
59 },
60 .ipgen_ext = {
61 .num_ranges = 32,
62 },
63 },
64};
65
66/**
67 * Return a pointer to the `dt_ac_range_check_desc_t` structure of the requested
68 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
69 * the function) with the provided default value.
70 */
71#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_ac_range_check_t)0 || (dt) >= kDtAcRangeCheckCount) return (default); &ac_range_check_desc[dt]; })
72
79
84
88 // Return a recognizable address in case of wrong argument.
89 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
90}
91
95 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
96 if (first_irq == kDtPlicIrqIdNone) {
97 return kDtPlicIrqIdNone;
98 }
99 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
100}
101
104 dt_plic_irq_id_t irq) {
105 dt_ac_range_check_irq_t count = kDtAcRangeCheckIrqCount;
106 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
107 if (first_irq == kDtPlicIrqIdNone) {
108 return count;
109 }
110 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
111 return count;
112 }
113 return (dt_ac_range_check_irq_t)(irq - first_irq);
114}
115
116
120 return (dt_alert_id_t)((uint32_t)ac_range_check_desc[dt].first_alert + (uint32_t)alert);
121}
122
125 dt_alert_id_t alert) {
126 dt_ac_range_check_alert_t count = kDtAcRangeCheckAlertCount;
127 if (alert < ac_range_check_desc[dt].first_alert || alert >= ac_range_check_desc[dt].first_alert + (dt_alert_id_t)count) {
128 return count;
129 }
130 return (dt_ac_range_check_alert_t)(alert - ac_range_check_desc[dt].first_alert);
131}
132
133
134
138 // Return the first clock in case of invalid argument.
139 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
140}
141
145 const dt_ac_range_check_reset_t count = kDtAcRangeCheckResetCount;
146 if (rst >= count) {
147 return kDtResetUnknown;
148 }
149 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
150}
151
152
153
155 return TRY_GET_DT(dt, 0)->ipgen_ext.num_ranges;
156}
157
158