Software APIs
dt_mbx.h
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#ifndef OPENTITAN_DT_MBX_H_
8#define OPENTITAN_DT_MBX_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) for IP mbx and top darjeeling.
17 *
18 * This file contains the type definitions and global functions of the mbx.
19 */
20
21#include "dt_api.h"
22#include <stdint.h>
23
24
25
26/**
27 * List of instances.
28 */
29typedef enum dt_mbx {
30 kDtMbx0 = 0, /**< mbx0 */
31 kDtMbx1 = 1, /**< mbx1 */
32 kDtMbx2 = 2, /**< mbx2 */
33 kDtMbx3 = 3, /**< mbx3 */
34 kDtMbx4 = 4, /**< mbx4 */
35 kDtMbx5 = 5, /**< mbx5 */
36 kDtMbx6 = 6, /**< mbx6 */
37 kDtMbxJtag = 7, /**< mbx_jtag */
38 kDtMbxPcie0 = 8, /**< mbx_pcie0 */
39 kDtMbxPcie1 = 9, /**< mbx_pcie1 */
40 kDtMbxFirst = 0, /**< \internal First instance */
41 kDtMbxCount = 10, /**< \internal Number of instances */
43
44/**
45 * List of register blocks.
46 *
47 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
48 */
49typedef enum dt_mbx_reg_block {
50 kDtMbxRegBlockCore = 0, /**< */
51 kDtMbxRegBlockSoc = 1, /**< */
52 kDtMbxRegBlockCount = 2, /**< \internal Number of register blocks */
54
55/** Primary register block (associated with the "primary" set of registers that control the IP). */
56static const dt_mbx_reg_block_t kDtMbxRegBlockPrimary = kDtMbxRegBlockCore;
57
58/**
59 * List of IRQs.
60 *
61 * IRQs are guaranteed to be numbered consecutively from 0.
62 */
63typedef enum dt_mbx_irq {
64 kDtMbxIrqMbxReady = 0, /**< A new object was received in the inbound mailbox. */
65 kDtMbxIrqMbxAbort = 1, /**< An abort request was received from the requester. */
66 kDtMbxIrqMbxError = 2, /**< The mailbox instance generated an error. */
67 kDtMbxIrqCount = 3, /**< \internal Number of IRQs */
69
70/**
71 * List of Alerts.
72 *
73 * Alerts are guaranteed to be numbered consecutively from 0.
74 */
75typedef enum dt_mbx_alert {
76 kDtMbxAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
77 kDtMbxAlertRecovFault = 1, /**< This recoverable alert is triggered when memory with invalid ECC (e.g., uninitialized memory) or at an invalid address is accessed. */
78 kDtMbxAlertCount = 2, /**< \internal Number of Alerts */
80
81/**
82 * List of clock ports.
83 *
84 * Clock ports are guaranteed to be numbered consecutively from 0.
85 */
86typedef enum dt_mbx_clock {
87 kDtMbxClockClk = 0, /**< Clock port clk_i */
88 kDtMbxClockCount = 1, /**< \internal Number of clock ports */
90
91/**
92 * List of reset ports.
93 *
94 * Reset ports are guaranteed to be numbered consecutively from 0.
95 */
96typedef enum dt_mbx_reset {
97 kDtMbxResetRst = 0, /**< Reset port rst_ni */
98 kDtMbxResetCount = 1, /**< \internal Number of reset ports */
100
101
102/**
103 * Get the mbx instance from an instance ID
104 *
105 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
106 *
107 * @param inst_id Instance ID.
108 * @return A mbx instance.
109 *
110 * **Note:** This function only makes sense if the instance ID has device type mbx,
111 * otherwise the returned value is unspecified.
112 */
114
115/**
116 * Get the instance ID of an instance.
117 *
118 * @param dt Instance of mbx.
119 * @return The instance ID of that instance.
120 */
122
123/**
124 * Get the register base address of an instance.
125 *
126 * @param dt Instance of mbx.
127 * @param reg_block The register block requested.
128 * @return The register base address of the requested block.
129 */
130uint32_t dt_mbx_reg_block(
131 dt_mbx_t dt,
132 dt_mbx_reg_block_t reg_block);
133
134/**
135 * Get the primary register base address of an instance.
136 *
137 * This is just a convenience function, equivalent to
138 * `dt_mbx_reg_block(dt, kDtMbxRegBlockCore)`
139 *
140 * @param dt Instance of mbx.
141 * @return The register base address of the primary register block.
142 */
143static inline uint32_t dt_mbx_primary_reg_block(
144 dt_mbx_t dt) {
145 return dt_mbx_reg_block(dt, kDtMbxRegBlockCore);
146}
147
148/**
149 * Get the PLIC ID of a mbx IRQ for a given instance.
150 *
151 * If the instance is not connected to the PLIC, this function
152 * will return `kDtPlicIrqIdNone`.
153 *
154 * @param dt Instance of mbx.
155 * @param irq A mbx IRQ.
156 * @return The PLIC ID of the IRQ of this instance.
157 */
159 dt_mbx_t dt,
160 dt_mbx_irq_t irq);
161
162/**
163 * Convert a global IRQ ID to a local mbx IRQ type.
164 *
165 * @param dt Instance of mbx.
166 * @param irq A PLIC ID that belongs to this instance.
167 * @return The mbx IRQ, or `kDtMbxIrqCount`.
168 *
169 * **Note:** This function assumes that the PLIC ID belongs to the instance
170 * of mbx passed in parameter. In other words, it must be the case that
171 * `dt_mbx_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
172 * will return `kDtMbxIrqCount`.
173 */
175 dt_mbx_t dt,
176 dt_plic_irq_id_t irq);
177
178
179/**
180 * Get the alert ID of a mbx alert for a given instance.
181 *
182 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
183 * instances where the instance is not connected, the return value is unspecified.
184 *
185 * @param dt Instance of mbx.
186 * @param alert A mbx alert.
187 * @return The Alert Handler alert ID of the alert of this instance.
188 */
190 dt_mbx_t dt,
191 dt_mbx_alert_t alert);
192
193/**
194 * Convert a global alert ID to a local mbx alert type.
195 *
196 * @param dt Instance of mbx.
197 * @param alert A global alert ID that belongs to this instance.
198 * @return The mbx alert, or `kDtMbxAlertCount`.
199 *
200 * **Note:** This function assumes that the global alert ID belongs to the
201 * instance of mbx passed in parameter. In other words, it must be the case
202 * that `dt_mbx_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
203 * this function will return `kDtMbxAlertCount`.
204 */
206 dt_mbx_t dt,
207 dt_alert_id_t alert);
208
209
210
211/**
212 * Get the clock signal connected to a clock port of an instance.
213 *
214 * @param dt Instance of mbx.
215 * @param clk Clock port.
216 * @return Clock signal.
217 */
219 dt_mbx_t dt,
220 dt_mbx_clock_t clk);
221
222/**
223 * Get the reset signal connected to a reset port of an instance.
224 *
225 * @param dt Instance of mbx.
226 * @param rst Reset port.
227 * @return Reset signal.
228 */
230 dt_mbx_t dt,
231 dt_mbx_reset_t rst);
232
233
234
235#ifdef __cplusplus
236} // extern "C"
237#endif // __cplusplus
238
239#endif // OPENTITAN_DT_MBX_H_