Software APIs
dt_rom_ctrl.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 rom_ctrl and top earlgrey.
10 */
11
12#include "hw/top/dt/dt_rom_ctrl.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_rom_ctrl {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t reg_addr[kDtRomCtrlRegBlockCount]; /**< Base address of each register block */
22 uint32_t mem_addr[kDtRomCtrlMemoryCount]; /**< Base address of each memory */
23 uint32_t mem_size[kDtRomCtrlMemoryCount]; /**< Size in bytes of each memory */
24 /**
25 * Alert ID of the first Alert of this instance.
26 *
27 * This value is undefined if the block is not connected to the Alert Handler.
28 */
30 dt_clock_t clock[kDtRomCtrlClockCount]; /**< Clock signal connected to each clock port */
31 dt_reset_t reset[kDtRomCtrlResetCount]; /**< Reset signal connected to each reset port */
33
34
35
36
37static const dt_desc_rom_ctrl_t rom_ctrl_desc[kDtRomCtrlCount] = {
38 [kDtRomCtrl] = {
39 .inst_id = kDtInstanceIdRomCtrl,
40 .reg_addr = {
41 [kDtRomCtrlRegBlockRegs] = 0x411e0000,
42 },
43 .mem_addr = {
44 [kDtRomCtrlMemoryRom] = 0x00008000,
45 },
46 .mem_size = {
47 [kDtRomCtrlMemoryRom] = 0x8000,
48 },
50 .clock = {
52 },
53 .reset = {
55 },
56 },
57};
58
59/**
60 * Return a pointer to the `dt_rom_ctrl_desc_t` structure of the requested
61 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
62 * the function) with the provided default value.
63 */
64#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_rom_ctrl_t)0 || (dt) >= kDtRomCtrlCount) return (default); &rom_ctrl_desc[dt]; })
65
67 if (inst_id >= kDtInstanceIdRomCtrl && inst_id <= kDtInstanceIdRomCtrl) {
68 return (dt_rom_ctrl_t)(inst_id - kDtInstanceIdRomCtrl);
69 }
70 return (dt_rom_ctrl_t)0;
71}
72
77
80 dt_rom_ctrl_reg_block_t reg_block) {
81 // Return a recognizable address in case of wrong argument.
82 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
83}
84
88 // Return a recognizable address in case of wrong argument.
89 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
90}
91
95 // Return an empty size in case of wrong argument.
96 return TRY_GET_DT(dt, 0)->mem_size[mem];
97}
98
99
101 dt_rom_ctrl_t dt,
102 dt_rom_ctrl_alert_t alert) {
103 return (dt_alert_id_t)((uint32_t)rom_ctrl_desc[dt].first_alert + (uint32_t)alert);
104}
105
107 dt_rom_ctrl_t dt,
108 dt_alert_id_t alert) {
109 dt_rom_ctrl_alert_t count = kDtRomCtrlAlertCount;
110 if (alert < rom_ctrl_desc[dt].first_alert || alert >= rom_ctrl_desc[dt].first_alert + (dt_alert_id_t)count) {
111 return count;
112 }
113 return (dt_rom_ctrl_alert_t)(alert - rom_ctrl_desc[dt].first_alert);
114}
115
116
117
119 dt_rom_ctrl_t dt,
121 // Return the first clock in case of invalid argument.
122 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
123}
124
126 dt_rom_ctrl_t dt,
128 const dt_rom_ctrl_reset_t count = kDtRomCtrlResetCount;
129 if (rst >= count) {
130 return kDtResetUnknown;
131 }
132 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
133}
134
135