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 darjeeling.
10 */
11
12#include "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 base_addr[kDtRvDmRegBlockCount]; /**< Base address of each register block */
22 /**
23 * Alert ID of the first Alert of this instance.
24 *
25 * This value is undefined if the block is not connected to the Alert Handler.
26 */
28 dt_clock_t clock[kDtRvDmClockCount]; /**< Clock signal connected to each clock port */
29 dt_reset_t reset[kDtRvDmResetCount]; /**< Reset signal connected to each reset port */
31
32
33
34
35static const dt_desc_rv_dm_t rv_dm_desc[kDtRvDmCount] = {
36 [kDtRvDm] = {
37 .inst_id = kDtInstanceIdRvDm,
38 .base_addr = {
39 [kDtRvDmRegBlockMem] = 0x00040000,
40 [kDtRvDmRegBlockRegs] = 0x21200000,
41 [kDtRvDmRegBlockDbg] = 0xffffffff,
42 },
44 .clock = {
47 },
48 .reset = {
51 },
52 },
53};
54
55/**
56 * Return a pointer to the `dt_rv_dm_desc_t` structure of the requested
57 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
58 * the function) with the provided default value.
59 */
60#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_rv_dm_t)0 || (dt) >= kDtRvDmCount) return (default); &rv_dm_desc[dt]; })
61
63 if (inst_id >= kDtInstanceIdRvDm && inst_id <= kDtInstanceIdRvDm) {
64 return (dt_rv_dm_t)(inst_id - kDtInstanceIdRvDm);
65 }
66 return (dt_rv_dm_t)0;
67}
68
73
75 dt_rv_dm_t dt,
76 dt_rv_dm_reg_block_t reg_block) {
77 // Return a recognizable address in case of wrong argument.
78 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
79}
80
81
83 dt_rv_dm_t dt,
84 dt_rv_dm_alert_t alert) {
85 return (dt_alert_id_t)((uint32_t)rv_dm_desc[dt].first_alert + (uint32_t)alert);
86}
87
89 dt_rv_dm_t dt,
90 dt_alert_id_t alert) {
91 dt_rv_dm_alert_t count = kDtRvDmAlertCount;
92 if (alert < rv_dm_desc[dt].first_alert || alert >= rv_dm_desc[dt].first_alert + (dt_alert_id_t)count) {
93 return count;
94 }
95 return (dt_rv_dm_alert_t)(alert - rv_dm_desc[dt].first_alert);
96}
97
98
99
101 dt_rv_dm_t dt,
102 dt_rv_dm_clock_t clk) {
103 // Return the first clock in case of invalid argument.
104 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
105}
106
108 dt_rv_dm_t dt,
109 dt_rv_dm_reset_t rst) {
110 const dt_rv_dm_reset_t count = kDtRvDmResetCount;
111 if (rst >= count) {
112 return kDtResetUnknown;
113 }
114 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
115}
116
117