Pavona Software APIs
api.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_TOP_SCAFI_DEPRECATED_DT_API_H_
8#define OPENTITAN_TOP_SCAFI_DEPRECATED_DT_API_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) API for top scafi_deprecated
17 *
18 * This file contains the type definitions and global functions of the DT.
19 *
20 * The DT models the chip as a collection of instances. Each instance has
21 * a type (the IP block) and a number of attributes such as I/Os, IRQs
22 * and so on. The DT also provides top-specific lists of global resources
23 * such as I/O pads, clocks and interrupts.
24 */
25
26#include <stddef.h>
27#include <stdint.h>
29
30/**
31 * List of device types.
32 *
33 * Device types are guaranteed to be numbered consecutively from 0.
34 */
35typedef enum dt_device_type {
36 kDtDeviceTypeUnknown = 0, /**< Instance of unknown type */
37 kDtDeviceTypeAes = 1, /**< instance of aes */
38 kDtDeviceTypeAonTimer = 2, /**< instance of aon_timer */
39 kDtDeviceTypeAst = 3, /**< instance of ast */
40 kDtDeviceTypeClkmgr = 4, /**< instance of clkmgr */
41 kDtDeviceTypeFlashCtrl = 5, /**< instance of flash_ctrl */
42 kDtDeviceTypeFlashMacroWrapper = 6, /**< instance of flash_macro_wrapper */
43 kDtDeviceTypeGpio = 7, /**< instance of gpio */
44 kDtDeviceTypePinmux = 8, /**< instance of pinmux */
45 kDtDeviceTypePwrmgr = 9, /**< instance of pwrmgr */
46 kDtDeviceTypeRomCtrl = 10, /**< instance of rom_ctrl */
47 kDtDeviceTypeRstmgr = 11, /**< instance of rstmgr */
48 kDtDeviceTypeRvCoreIbex = 12, /**< instance of rv_core_ibex */
49 kDtDeviceTypeRvPlic = 13, /**< instance of rv_plic */
50 kDtDeviceTypeRvTimer = 14, /**< instance of rv_timer */
51 kDtDeviceTypeSpiDevice = 15, /**< instance of spi_device */
52 kDtDeviceTypeSpiHost = 16, /**< instance of spi_host */
53 kDtDeviceTypeSramCtrl = 17, /**< instance of sram_ctrl */
54 kDtDeviceTypeUart = 18, /**< instance of uart */
55 kDtDeviceTypeUsbdev = 19, /**< instance of usbdev */
57
58enum {
59 kDtDeviceTypeCount = 20, /**< Number of instance types */
60};
61
62
63/**
64 * List of instance IDs.
65 *
66 * Instance IDs are guaranteed to be numbered consecutively from 0.
67 */
68typedef enum dt_instance_id {
69 kDtInstanceIdUnknown = 0, /**< Unknown instance */
70 kDtInstanceIdAes = 1, /**< instance aes of aes */
71 kDtInstanceIdAonTimerAon = 2, /**< instance aon_timer_aon of aon_timer */
72 kDtInstanceIdAst = 3, /**< instance ast of ast */
73 kDtInstanceIdClkmgrAon = 4, /**< instance clkmgr_aon of clkmgr */
74 kDtInstanceIdFlashCtrl = 5, /**< instance flash_ctrl of flash_ctrl */
75 kDtInstanceIdFlashMacroWrapper = 6, /**< instance flash_macro_wrapper of flash_macro_wrapper */
76 kDtInstanceIdGpio = 7, /**< instance gpio of gpio */
77 kDtInstanceIdPinmuxAon = 8, /**< instance pinmux_aon of pinmux */
78 kDtInstanceIdPwrmgrAon = 9, /**< instance pwrmgr_aon of pwrmgr */
79 kDtInstanceIdRomCtrl = 10, /**< instance rom_ctrl of rom_ctrl */
80 kDtInstanceIdRstmgrAon = 11, /**< instance rstmgr_aon of rstmgr */
81 kDtInstanceIdRvCoreIbex = 12, /**< instance rv_core_ibex of rv_core_ibex */
82 kDtInstanceIdRvPlic = 13, /**< instance rv_plic of rv_plic */
83 kDtInstanceIdRvTimer = 14, /**< instance rv_timer of rv_timer */
84 kDtInstanceIdSpiDevice = 15, /**< instance spi_device of spi_device */
85 kDtInstanceIdSpiHost0 = 16, /**< instance spi_host0 of spi_host */
86 kDtInstanceIdSramCtrlMain = 17, /**< instance sram_ctrl_main of sram_ctrl */
87 kDtInstanceIdUart0 = 18, /**< instance uart0 of uart */
88 kDtInstanceIdUart1 = 19, /**< instance uart1 of uart */
89 kDtInstanceIdUsbdev = 20, /**< instance usbdev of usbdev */
91
92enum {
93 kDtInstanceIdCount = 21, /**< Number of instance IDs */
94};
95
96
97/**
98 * Get the instance type of a device instance.
99 *
100 * For example the instance type of `kDtUart0` is `kDtInstanceTypeUart`.
101 *
102 * @param id An instance ID.
103 * @return The instance type, or `kDtInstanceIdUnknown` if the ID is not valid.
104 */
106
107/** PLIC IRQ ID type.
108 *
109 * This type represents a raw IRQ ID from the PLIC.
110 *
111 * This is an alias to the top's `plic_irq_id_t` type for backward compatibility
112 * with existing code.
113 */
115
116/** PLIC IRQ ID for no interrupt. */
117static const dt_plic_irq_id_t kDtPlicIrqIdNone = kTopScafiDeprecatedPlicIrqIdNone;
118
119/**
120 * Get the instance ID for a given PLIC IRQ ID.
121 *
122 * For example, on egret, the instance ID of `kTopEgretPlicIrqIdUart0TxWatermark`
123 * is `kDtInstanceIdUart0`. One can then use the type specific function to retrieve the
124 * IRQ name, for example `dt_uart_irq_from_plic_id` for the UART.
125 *
126 * @param irq A PLIC ID.
127 * @return The instance ID, or `kDtInstanceIdUnknown` if the PLIC ID is not valid.
128 */
130
131/**
132 * List of clocks.
133 *
134 * Clocks are guaranteed to be numbered consecutively from 0.
135 */
136typedef enum dt_clock {
137 kDtClockMain = 0, /**< clock main */
138 kDtClockIo = 1, /**< clock io */
139 kDtClockUsb = 2, /**< clock usb */
140 kDtClockAon = 3, /**< clock aon */
141 kDtClockIoDiv2 = 4, /**< clock io_div2 */
142 kDtClockIoDiv4 = 5, /**< clock io_div4 */
144
145enum {
146 kDtClockCount = 6, /**< Number of clocks */
147};
148
149
150/**
151 * Get the frequency of a clock.
152 *
153 * @param clk A clock ID.
154 * @return Clock frequency in Hz.
155 */
157
158/**
159 * List of resets.
160 *
161 * Resets are guaranteed to be numbered consecutively from 0.
162 */
163typedef enum dt_reset {
164 kDtResetUnknown = 0, /**< Unknown reset */
165 kDtResetPorAon = 1, /**< Reset node por_aon */
166 kDtResetLcSrc = 2, /**< Reset node lc_src */
167 kDtResetSysSrc = 3, /**< Reset node sys_src */
168 kDtResetPor = 4, /**< Reset node por */
169 kDtResetPorIo = 5, /**< Reset node por_io */
170 kDtResetPorIoDiv2 = 6, /**< Reset node por_io_div2 */
171 kDtResetPorIoDiv4 = 7, /**< Reset node por_io_div4 */
172 kDtResetPorUsb = 8, /**< Reset node por_usb */
173 kDtResetLc = 9, /**< Reset node lc */
174 kDtResetLcIoDiv4 = 10, /**< Reset node lc_io_div4 */
175 kDtResetSys = 11, /**< Reset node sys */
176 kDtResetSysIoDiv4 = 12, /**< Reset node sys_io_div4 */
177 kDtResetSysAon = 13, /**< Reset node sys_aon */
178 kDtResetSpiDevice = 14, /**< Reset node spi_device */
179 kDtResetSpiHost0 = 15, /**< Reset node spi_host0 */
180 kDtResetUsb = 16, /**< Reset node usb */
182
183enum {
184 kDtResetCount = 17, /**< Number of resets */
185};
186
187
188/**
189 * List of pads names.
190 */
191typedef enum dt_pad {
192 kDtPadConstantZero = 0, /**< Pad that is constantly tied to zero (input) */
193 kDtPadConstantOne = 1, /**< Pad that is constantly tied to one (input) */
194 kDtPadIoa0 = 2, /**< Muxed IO pad */
195 kDtPadIoa1 = 3, /**< Muxed IO pad */
196 kDtPadIoa2 = 4, /**< Muxed IO pad */
197 kDtPadIoa3 = 5, /**< Muxed IO pad */
198 kDtPadIoa4 = 6, /**< Muxed IO pad */
199 kDtPadIoa5 = 7, /**< Muxed IO pad */
200 kDtPadIoa6 = 8, /**< Muxed IO pad */
201 kDtPadIoa7 = 9, /**< Muxed IO pad */
202 kDtPadIoa8 = 10, /**< Muxed IO pad */
203 kDtPadIob0 = 11, /**< Muxed IO pad */
204 kDtPadIob1 = 12, /**< Muxed IO pad */
205 kDtPadIob2 = 13, /**< Muxed IO pad */
206 kDtPadIob3 = 14, /**< Muxed IO pad */
207 kDtPadIob4 = 15, /**< Muxed IO pad */
208 kDtPadIob5 = 16, /**< Muxed IO pad */
209 kDtPadIob6 = 17, /**< Muxed IO pad */
210 kDtPadIob7 = 18, /**< Muxed IO pad */
211 kDtPadIob8 = 19, /**< Muxed IO pad */
212 kDtPadIob9 = 20, /**< Muxed IO pad */
213 kDtPadIob10 = 21, /**< Muxed IO pad */
214 kDtPadIob11 = 22, /**< Muxed IO pad */
215 kDtPadIob12 = 23, /**< Muxed IO pad */
216 kDtPadIoc0 = 24, /**< Muxed IO pad */
217 kDtPadIoc1 = 25, /**< Muxed IO pad */
218 kDtPadIoc2 = 26, /**< Muxed IO pad */
219 kDtPadIoc3 = 27, /**< Muxed IO pad */
220 kDtPadIoc4 = 28, /**< Muxed IO pad */
221 kDtPadIoc5 = 29, /**< Muxed IO pad */
222 kDtPadIoc6 = 30, /**< Muxed IO pad */
223 kDtPadIoc7 = 31, /**< Muxed IO pad */
224 kDtPadIoc8 = 32, /**< Muxed IO pad */
225 kDtPadIoc9 = 33, /**< Muxed IO pad */
226 kDtPadIoc10 = 34, /**< Muxed IO pad */
227 kDtPadIoc11 = 35, /**< Muxed IO pad */
228 kDtPadIoc12 = 36, /**< Muxed IO pad */
229 kDtPadIor0 = 37, /**< Muxed IO pad */
230 kDtPadIor1 = 38, /**< Muxed IO pad */
231 kDtPadIor2 = 39, /**< Muxed IO pad */
232 kDtPadIor3 = 40, /**< Muxed IO pad */
233 kDtPadIor4 = 41, /**< Muxed IO pad */
234 kDtPadIor5 = 42, /**< Muxed IO pad */
235 kDtPadIor6 = 43, /**< Muxed IO pad */
236 kDtPadIor7 = 44, /**< Muxed IO pad */
237 kDtPadIor10 = 45, /**< Muxed IO pad */
238 kDtPadIor11 = 46, /**< Muxed IO pad */
239 kDtPadIor12 = 47, /**< Muxed IO pad */
240 kDtPadIor13 = 48, /**< Muxed IO pad */
241 kDtPadSpiHost0Sd0 = 49, /**< SPI host data */
242 kDtPadSpiHost0Sd1 = 50, /**< SPI host data */
243 kDtPadSpiHost0Sd2 = 51, /**< SPI host data */
244 kDtPadSpiHost0Sd3 = 52, /**< SPI host data */
245 kDtPadSpiDeviceSd0 = 53, /**< SPI device data */
246 kDtPadSpiDeviceSd1 = 54, /**< SPI device data */
247 kDtPadSpiDeviceSd2 = 55, /**< SPI device data */
248 kDtPadSpiDeviceSd3 = 56, /**< SPI device data */
249 kDtPadUsbdevUsbDp = 57, /**< */
250 kDtPadUsbdevUsbDn = 58, /**< */
251 kDtPadSpiDeviceSck = 59, /**< SPI device clock */
252 kDtPadSpiDeviceCsb = 60, /**< SPI device chip select */
253 kDtPadSpiHost0Sck = 61, /**< SPI host clock */
254 kDtPadSpiHost0Csb = 62, /**< SPI host chip select */
256
257enum {
258 kDtPadCount = 63, /**< Number of pads */
259};
260
261
262/** Type of peripheral I/O. */
263typedef enum dt_periph_io_type {
264 /** This peripheral I/O is connected to a muxed IO (MIO). */
266 /** This peripheral I/O is connected to a direct IO (DIO). */
268 /** This peripheral I/O is not connected to either a MIO or a DIO. */
271
272
273/** Direction of a peripheral I/O. */
274typedef enum dt_periph_io_dir {
275 /** This peripheral I/O is an input. */
277 /** This peripheral I/O is an output */
279 /** This peripheral I/O is an input-output */
282
283/** Peripheral I/O description.
284 *
285 * A `dt_periph_io_t` represents a HW IP block peripheral I/O, which can be an input, output or both.
286 * Importantly, this only represents how the block peripheral I/O is wired, i.e.
287 * whether it is connected a MIO or a direct IO on the pinmux, and the relevant information necessary to
288 * configure it.
289 *
290 * **Note:** The fields of this structure are internal, use the dt_periph_io_* functions to access them.
291 */
292typedef struct dt_periph_io {
293 struct {
294 dt_periph_io_type_t type; /**< Peripheral I/O type */
295 dt_periph_io_dir_t dir; /**< Peripheral I/O direction */
296 /**
297 * For `kDtPeriphIoTypeMio`: peripheral input number. This is the index of the MIO_PERIPH_INSEL register
298 * that controls this peripheral I/O.
299 *
300 * For `kDtPeriphIoTypeDio`: DIO pad number. This is the index of the various DIO_PAD_* registers
301 * that control this peripheral I/O.
302 */
304 /**
305 * For `kDtPeriphIoTypeMio`: peripheral output number. This is the value to put in the MIO_OUTSEL registers
306 * to connect an output to this peripheral I/O. For `kDtPeriphIoTypeDio`: the pad index (`dt_pad_t`) to which this I/O is connected.
307 */
308 uint16_t outsel_or_dt_pad;
309 } __internal; /**< Private fields */
311
312
313/* Peripheral I/O that is constantly tied to high-Z (output only) */
314extern const dt_periph_io_t kDtPeriphIoConstantHighZ;
315
316/* Peripheral I/O that is constantly tied to one (output only) */
317extern const dt_periph_io_t kDtPeriphIoConstantZero;
318
319/* Peripheral I/O that is constantly tied to zero (output only) */
320extern const dt_periph_io_t kDtPeriphIoConstantOne;
321
322/**
323 * Return the type of a `dt_periph_io_t`.
324 *
325 * @param periph_io A peripheral I/O description.
326 * @return The peripheral I/O type (MIO, DIO, etc).
327 */
329 return periph_io.__internal.type;
330}
331
332/**
333 * Return the direction of a `dt_periph_io_t`.
334 *
335 * @param periph_io A peripheral I/O description.
336 * @return The peripheral I/O direction.
337 */
338static inline dt_periph_io_dir_t dt_periph_io_dir(dt_periph_io_t periph_io) {
339 return periph_io.__internal.dir;
340}
341
342/**
343 * Pinmux types.
344 *
345 * These types are aliases to top-level types for backward compatibility
346 * with existing code.
347 */
349typedef top_scafi_deprecated_pinmux_insel_t dt_pinmux_insel_t;
350typedef top_scafi_deprecated_pinmux_outsel_t dt_pinmux_outsel_t;
351typedef top_scafi_deprecated_pinmux_mio_out_t dt_pinmux_mio_out_t;
352typedef top_scafi_deprecated_direct_pads_t dt_pinmux_direct_pad_t;
353typedef top_scafi_deprecated_muxed_pads_t dt_pinmux_muxed_pad_t;
354
355
356/** The last valid insel value. */
357static const dt_pinmux_insel_t kDtPinmuxInselLast = kTopScafi_deprecatedPinmuxInselLast;
358
359/** The last valid outsel value. */
360static const dt_pinmux_outsel_t kDtPinmuxOutselLast = kTopScafi_deprecatedPinmuxOutselLast;
361
362/** Tie constantly to zero. */
363static const dt_pinmux_outsel_t kDtPinmuxOutselConstantZero = kTopScafi_deprecatedPinmuxOutselConstantZero;
364
365/** Tie constantly to one. */
366static const dt_pinmux_outsel_t kDtPinmuxOutselConstantOne = kTopScafi_deprecatedPinmuxOutselConstantOne;
367
368/** Tie constantly to high-Z. */
369static const dt_pinmux_outsel_t kDtPinmuxOutselConstantHighZ = kTopScafi_deprecatedPinmuxOutselConstantHighZ;
370
371/**
372 * Return the peripheral input for an MIO peripheral I/O.
373 *
374 * This is the index of the `MIO_PERIPH_INSEL` pinmux register that controls this peripheral I/O.
375 *
376 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeMio`.
377 * @return The peripheral input number of the MIO that this peripheral I/O is connected to.
378 *
379 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeMio` which are
380 * inputs (`kDtPeriphIoDirIn`). For any other peripheral I/O, the return value is unspecified.
381 */
382static inline dt_pinmux_peripheral_in_t dt_periph_io_mio_periph_input(dt_periph_io_t periph_io) {
383 return (dt_pinmux_peripheral_in_t)periph_io.__internal.periph_input_or_direct_pad;
384}
385
386/**
387 * Return the outsel for an MIO peripheral I/O.
388 *
389 * This is the value to put in the `MIO_OUTSEL` pinmux registers to connect a pad to this peripheral I/O.
390 *
391 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeMio`.
392 * @return The outsel of the MIO that this peripheral I/O is connected to.
393 *
394 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeMio` which are
395 * outputs (`kDtPeriphIoDirOut`). For any other peripheral I/O, the return value is unspecified.
396 */
397static inline dt_pinmux_outsel_t dt_periph_io_mio_outsel(dt_periph_io_t periph_io) {
398 return (dt_pinmux_outsel_t)periph_io.__internal.outsel_or_dt_pad;
399}
400
401/**
402 * Return the direct pad number of a DIO peripheral I/O.
403 *
404 * This is the index of the various `DIO_PAD_*` pinmux registers that control this peripheral I/O.
405 *
406 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeDio`.
407 * @return The direct pad number of the DIO that this peripheral I/O is connected to.
408 *
409 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeDio` which are
410 * either outputs or inouts. For any other peripheral I/O type, the return value is unspecified.
411 */
412static inline dt_pinmux_direct_pad_t dt_periph_io_dio_pad_index(dt_periph_io_t periph_io) {
413 return (dt_pinmux_direct_pad_t)periph_io.__internal.periph_input_or_direct_pad;
414}
415
416/**
417 * Return the pad of a DIO peripheral I/O.
418 *
419 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeDio`.
420 * @return The pad to which this peripheral I/O is connected to.
421 *
422 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeDio` which are
423 * either outputs or inouts. For any other peripheral I/O type, the return value is unspecified.
424 */
425static inline dt_pad_t dt_periph_io_dio_pad(dt_periph_io_t periph_io) {
426 return (dt_pad_t)periph_io.__internal.outsel_or_dt_pad;
427}
428
429/** Type of a pad. */
430typedef enum dt_pad_type {
431 /** This pad is a muxed IO (MIO). */
433 /** This pad is a direct IO (DIO). */
435 /** This pad is not an MIO or a DIO. */
438
439/**
440 * Return the type of a `dt_pad_t`.
441 *
442 * @param pad A pad description.
443 * @return The pad type (MIO, DIO, etc).
444 */
446
447/**
448 * Return the pad out number for an MIO pad.
449 *
450 * This is the index of the `MIO_OUT` registers that control this pad
451 * (or the output part of this pad).
452 *
453 * @param pad A pad of type `kDtPadTypeMio`.
454 * @return The pad out number of the MIO.
455 *
456 * **Note:** This function only makes sense for pads of type `kDtPadTypeMio` which are
457 * either inputs or inouts. For any other pad, the return value is unspecified.
458 */
459dt_pinmux_mio_out_t dt_pad_mio_out(dt_pad_t pad);
460
461/**
462 * Return the pad out number for an MIO pad.
463 *
464 * This is the index of the `MIO_PAD` registers that control this pad
465 * (or the output part of this pad).
466 *
467 * @param pad A pad of type `kDtPadTypeMio`.
468 * @return The pad out number of the MIO.
469 *
470 * **Note:** This function only makes sense for pads of type `kDtPadTypeMio`.
471 * For any other pad, the return value is unspecified.
472 */
473dt_pinmux_muxed_pad_t dt_pad_mio_pad_index(dt_pad_t pad);
474
475/**
476 * Return the insel for an MIO pad.
477 *
478 * This is the value to put in the `MIO_PERIPH_INSEL` registers to connect a peripheral I/O to this pad.
479 *
480 * @param pad A pad of type `kDtPadTypeMio`.
481 * @return The insel of the MIO that this pad is connected to.
482 *
483 * **Note:** This function only makes sense for pads of type `kDtPadTypeMio`.
484 * For any other pad, the return value is unspecified.
485 */
486dt_pinmux_insel_t dt_pad_mio_insel(dt_pad_t pad);
487
488/**
489 * Return the direct pad number of a DIO pad.
490 *
491 * This is the index of the various `DIO_PAD_*` registers that control this pad.
492 *
493 * @param pad A pad of type `kDtPadTypeDio`.
494 * @return The direct pad number of the DID that this pad is connected to.
495 *
496 * **Note:** This function only makes sense for pads of type `kDtPeriphIoTypeDio` which are
497 * either outputs or inouts. For any other pad type, the return value is unspecified.
498 */
499dt_pinmux_direct_pad_t dt_pad_dio_pad_index(dt_pad_t pad);
500
501#ifdef __cplusplus
502} // extern "C"
503#endif // __cplusplus
504
505#endif // OPENTITAN_TOP_SCAFI_DEPRECATED_DT_API_H_