Software APIs
dt_lc_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 lc_ctrl and top earlgrey.
10 */
11
12#include "hw/top/dt/dt_lc_ctrl.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_lc_ctrl {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t reg_addr[kDtLcCtrlRegBlockCount]; /**< Base address of each register block */
22 uint32_t mem_addr[kDtLcCtrlMemoryCount]; /**< Base address of each memory */
23 uint32_t mem_size[kDtLcCtrlMemoryCount]; /**< 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[kDtLcCtrlClockCount]; /**< Clock signal connected to each clock port */
31 dt_reset_t reset[kDtLcCtrlResetCount]; /**< Reset signal connected to each reset port */
33
34
35
36
37static const dt_desc_lc_ctrl_t lc_ctrl_desc[kDtLcCtrlCount] = {
38 [kDtLcCtrl] = {
39 .inst_id = kDtInstanceIdLcCtrl,
40 .reg_addr = {
41 [kDtLcCtrlRegBlockRegs] = 0x40140000,
42 [kDtLcCtrlRegBlockDmi] = 0x0,
43 },
44 .mem_addr = {
45 },
46 .mem_size = {
47 },
49 .clock = {
52 },
53 .reset = {
56 },
57 },
58};
59
60/**
61 * Return a pointer to the `dt_lc_ctrl_desc_t` structure of the requested
62 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
63 * the function) with the provided default value.
64 */
65#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_lc_ctrl_t)0 || (dt) >= kDtLcCtrlCount) return (default); &lc_ctrl_desc[dt]; })
66
68 if (inst_id >= kDtInstanceIdLcCtrl && inst_id <= kDtInstanceIdLcCtrl) {
69 return (dt_lc_ctrl_t)(inst_id - kDtInstanceIdLcCtrl);
70 }
71 return (dt_lc_ctrl_t)0;
72}
73
78
80 dt_lc_ctrl_t dt,
81 dt_lc_ctrl_reg_block_t reg_block) {
82 // Return a recognizable address in case of wrong argument.
83 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
84}
85
87 dt_lc_ctrl_t dt,
89 // Return a recognizable address in case of wrong argument.
90 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
91}
92
94 dt_lc_ctrl_t dt,
96 // Return an empty size in case of wrong argument.
97 return TRY_GET_DT(dt, 0)->mem_size[mem];
98}
99
100
102 dt_lc_ctrl_t dt,
103 dt_lc_ctrl_alert_t alert) {
104 return (dt_alert_id_t)((uint32_t)lc_ctrl_desc[dt].first_alert + (uint32_t)alert);
105}
106
108 dt_lc_ctrl_t dt,
109 dt_alert_id_t alert) {
110 dt_lc_ctrl_alert_t count = kDtLcCtrlAlertCount;
111 if (alert < lc_ctrl_desc[dt].first_alert || alert >= lc_ctrl_desc[dt].first_alert + (dt_alert_id_t)count) {
112 return count;
113 }
114 return (dt_lc_ctrl_alert_t)(alert - lc_ctrl_desc[dt].first_alert);
115}
116
117
118
120 dt_lc_ctrl_t dt,
121 dt_lc_ctrl_clock_t clk) {
122 // Return the first clock in case of invalid argument.
123 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
124}
125
127 dt_lc_ctrl_t dt,
128 dt_lc_ctrl_reset_t rst) {
129 const dt_lc_ctrl_reset_t count = kDtLcCtrlResetCount;
130 if (rst >= count) {
131 return kDtResetUnknown;
132 }
133 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
134}
135
136