Software APIs
dt_rv_dm.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 rv_dm and top earlgrey.
10 */
11
12#include "hw/top/dt/dt_rv_dm.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_rv_dm {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t reg_addr[kDtRvDmRegBlockCount]; /**< Base address of each register block */
22 uint32_t mem_addr[kDtRvDmMemoryCount]; /**< Base address of each memory */
23 uint32_t mem_size[kDtRvDmMemoryCount]; /**< 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[kDtRvDmClockCount]; /**< Clock signal connected to each clock port */
31 dt_reset_t reset[kDtRvDmResetCount]; /**< Reset signal connected to each reset port */
33
34
35
36
37static const dt_desc_rv_dm_t rv_dm_desc[kDtRvDmCount] = {
38 [kDtRvDm] = {
39 .inst_id = kDtInstanceIdRvDm,
40 .reg_addr = {
41 [kDtRvDmRegBlockRegs] = 0x41200000,
42 [kDtRvDmRegBlockMem] = 0x00010000,
43 [kDtRvDmRegBlockDbg] = 0x00001000,
44 },
45 .mem_addr = {
46 },
47 .mem_size = {
48 },
50 .clock = {
53 },
54 .reset = {
57 },
58 },
59};
60
61/**
62 * Return a pointer to the `dt_rv_dm_desc_t` structure of the requested
63 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
64 * the function) with the provided default value.
65 */
66#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_rv_dm_t)0 || (dt) >= kDtRvDmCount) return (default); &rv_dm_desc[dt]; })
67
69 if (inst_id >= kDtInstanceIdRvDm && inst_id <= kDtInstanceIdRvDm) {
70 return (dt_rv_dm_t)(inst_id - kDtInstanceIdRvDm);
71 }
72 return (dt_rv_dm_t)0;
73}
74
79
81 dt_rv_dm_t dt,
82 dt_rv_dm_reg_block_t reg_block) {
83 // Return a recognizable address in case of wrong argument.
84 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
85}
86
88 dt_rv_dm_t dt,
90 // Return a recognizable address in case of wrong argument.
91 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
92}
93
95 dt_rv_dm_t dt,
97 // Return an empty size in case of wrong argument.
98 return TRY_GET_DT(dt, 0)->mem_size[mem];
99}
100
101
103 dt_rv_dm_t dt,
104 dt_rv_dm_alert_t alert) {
105 return (dt_alert_id_t)((uint32_t)rv_dm_desc[dt].first_alert + (uint32_t)alert);
106}
107
109 dt_rv_dm_t dt,
110 dt_alert_id_t alert) {
111 dt_rv_dm_alert_t count = kDtRvDmAlertCount;
112 if (alert < rv_dm_desc[dt].first_alert || alert >= rv_dm_desc[dt].first_alert + (dt_alert_id_t)count) {
113 return count;
114 }
115 return (dt_rv_dm_alert_t)(alert - rv_dm_desc[dt].first_alert);
116}
117
118
119
121 dt_rv_dm_t dt,
122 dt_rv_dm_clock_t clk) {
123 // Return the first clock in case of invalid argument.
124 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
125}
126
128 dt_rv_dm_t dt,
129 dt_rv_dm_reset_t rst) {
130 const dt_rv_dm_reset_t count = kDtRvDmResetCount;
131 if (rst >= count) {
132 return kDtResetUnknown;
133 }
134 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
135}
136
137