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/** Tie constantly to zero. */
356static const dt_pinmux_outsel_t kDtPinmuxOutselConstantZero = kTopScafi_deprecatedPinmuxOutselConstantZero;
357
358/** Tie constantly to one. */
359static const dt_pinmux_outsel_t kDtPinmuxOutselConstantOne = kTopScafi_deprecatedPinmuxOutselConstantOne;
360
361/** Tie constantly to high-Z. */
362static const dt_pinmux_outsel_t kDtPinmuxOutselConstantHighZ = kTopScafi_deprecatedPinmuxOutselConstantHighZ;
363
364/**
365 * Return the peripheral input for an MIO peripheral I/O.
366 *
367 * This is the index of the `MIO_PERIPH_INSEL` pinmux register that controls this peripheral I/O.
368 *
369 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeMio`.
370 * @return The peripheral input number of the MIO that this peripheral I/O is connected to.
371 *
372 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeMio` which are
373 * inputs (`kDtPeriphIoDirIn`). For any other peripheral I/O, the return value is unspecified.
374 */
375static inline dt_pinmux_peripheral_in_t dt_periph_io_mio_periph_input(dt_periph_io_t periph_io) {
376 return (dt_pinmux_peripheral_in_t)periph_io.__internal.periph_input_or_direct_pad;
377}
378
379/**
380 * Return the outsel for an MIO peripheral I/O.
381 *
382 * This is the value to put in the `MIO_OUTSEL` pinmux registers to connect a pad to this peripheral I/O.
383 *
384 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeMio`.
385 * @return The outsel of the MIO that this peripheral I/O is connected to.
386 *
387 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeMio` which are
388 * outputs (`kDtPeriphIoDirOut`). For any other peripheral I/O, the return value is unspecified.
389 */
390static inline dt_pinmux_outsel_t dt_periph_io_mio_outsel(dt_periph_io_t periph_io) {
391 return (dt_pinmux_outsel_t)periph_io.__internal.outsel_or_dt_pad;
392}
393
394/**
395 * Return the direct pad number of a DIO peripheral I/O.
396 *
397 * This is the index of the various `DIO_PAD_*` pinmux registers that control this peripheral I/O.
398 *
399 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeDio`.
400 * @return The direct pad number of the DIO that this peripheral I/O is connected to.
401 *
402 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeDio` which are
403 * either outputs or inouts. For any other peripheral I/O type, the return value is unspecified.
404 */
405static inline dt_pinmux_direct_pad_t dt_periph_io_dio_pad_index(dt_periph_io_t periph_io) {
406 return (dt_pinmux_direct_pad_t)periph_io.__internal.periph_input_or_direct_pad;
407}
408
409/**
410 * Return the pad of a DIO peripheral I/O.
411 *
412 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeDio`.
413 * @return The pad to which this peripheral I/O is connected to.
414 *
415 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeDio` which are
416 * either outputs or inouts. For any other peripheral I/O type, the return value is unspecified.
417 */
418static inline dt_pad_t dt_periph_io_dio_pad(dt_periph_io_t periph_io) {
419 return (dt_pad_t)periph_io.__internal.outsel_or_dt_pad;
420}
421
422/** Type of a pad. */
423typedef enum dt_pad_type {
424 /** This pad is a muxed IO (MIO). */
426 /** This pad is a direct IO (DIO). */
428 /** This pad is not an MIO or a DIO. */
431
432/**
433 * Return the type of a `dt_pad_t`.
434 *
435 * @param pad A pad description.
436 * @return The pad type (MIO, DIO, etc).
437 */
439
440/**
441 * Return the pad out number for an MIO pad.
442 *
443 * This is the index of the `MIO_OUT` registers that control this pad
444 * (or the output part of this pad).
445 *
446 * @param pad A pad of type `kDtPadTypeMio`.
447 * @return The pad out number of the MIO.
448 *
449 * **Note:** This function only makes sense for pads of type `kDtPadTypeMio` which are
450 * either inputs or inouts. For any other pad, the return value is unspecified.
451 */
452dt_pinmux_mio_out_t dt_pad_mio_out(dt_pad_t pad);
453
454/**
455 * Return the pad out number for an MIO pad.
456 *
457 * This is the index of the `MIO_PAD` registers that control this pad
458 * (or the output part of this pad).
459 *
460 * @param pad A pad of type `kDtPadTypeMio`.
461 * @return The pad out number of the MIO.
462 *
463 * **Note:** This function only makes sense for pads of type `kDtPadTypeMio`.
464 * For any other pad, the return value is unspecified.
465 */
466dt_pinmux_muxed_pad_t dt_pad_mio_pad_index(dt_pad_t pad);
467
468/**
469 * Return the insel for an MIO pad.
470 *
471 * This is the value to put in the `MIO_PERIPH_INSEL` registers to connect a peripheral I/O to this pad.
472 *
473 * @param pad A pad of type `kDtPadTypeMio`.
474 * @return The insel of the MIO that this pad is connected to.
475 *
476 * **Note:** This function only makes sense for pads of type `kDtPadTypeMio`.
477 * For any other pad, the return value is unspecified.
478 */
479dt_pinmux_insel_t dt_pad_mio_insel(dt_pad_t pad);
480
481/**
482 * Return the direct pad number of a DIO pad.
483 *
484 * This is the index of the various `DIO_PAD_*` registers that control this pad.
485 *
486 * @param pad A pad of type `kDtPadTypeDio`.
487 * @return The direct pad number of the DID that this pad is connected to.
488 *
489 * **Note:** This function only makes sense for pads of type `kDtPeriphIoTypeDio` which are
490 * either outputs or inouts. For any other pad type, the return value is unspecified.
491 */
492dt_pinmux_direct_pad_t dt_pad_dio_pad_index(dt_pad_t pad);
493
494#ifdef __cplusplus
495} // extern "C"
496#endif // __cplusplus
497
498#endif // OPENTITAN_TOP_SCAFI_DEPRECATED_DT_API_H_