Software APIs
dt_rv_plic.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_plic and top earlgrey.
10 */
11
12#include "hw/top/dt/dt_rv_plic.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_rv_plic {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t reg_addr[kDtRvPlicRegBlockCount]; /**< Base address of each register block */
22 uint32_t mem_addr[kDtRvPlicMemoryCount]; /**< Base address of each memory */
23 uint32_t mem_size[kDtRvPlicMemoryCount]; /**< 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[kDtRvPlicClockCount]; /**< Clock signal connected to each clock port */
31 dt_reset_t reset[kDtRvPlicResetCount]; /**< Reset signal connected to each reset port */
33
34
35
36
37static const dt_desc_rv_plic_t rv_plic_desc[kDtRvPlicCount] = {
38 [kDtRvPlic] = {
39 .inst_id = kDtInstanceIdRvPlic,
40 .reg_addr = {
41 [kDtRvPlicRegBlockCore] = 0x48000000,
42 },
43 .mem_addr = {
44 },
45 .mem_size = {
46 },
48 .clock = {
50 },
51 .reset = {
53 },
54 },
55};
56
57/**
58 * Return a pointer to the `dt_rv_plic_desc_t` structure of the requested
59 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
60 * the function) with the provided default value.
61 */
62#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_rv_plic_t)0 || (dt) >= kDtRvPlicCount) return (default); &rv_plic_desc[dt]; })
63
65 if (inst_id >= kDtInstanceIdRvPlic && inst_id <= kDtInstanceIdRvPlic) {
66 return (dt_rv_plic_t)(inst_id - kDtInstanceIdRvPlic);
67 }
68 return (dt_rv_plic_t)0;
69}
70
75
77 dt_rv_plic_t dt,
78 dt_rv_plic_reg_block_t reg_block) {
79 // Return a recognizable address in case of wrong argument.
80 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
81}
82
84 dt_rv_plic_t dt,
86 // Return a recognizable address in case of wrong argument.
87 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
88}
89
91 dt_rv_plic_t dt,
93 // Return an empty size in case of wrong argument.
94 return TRY_GET_DT(dt, 0)->mem_size[mem];
95}
96
97
99 dt_rv_plic_t dt,
100 dt_rv_plic_alert_t alert) {
101 return (dt_alert_id_t)((uint32_t)rv_plic_desc[dt].first_alert + (uint32_t)alert);
102}
103
105 dt_rv_plic_t dt,
106 dt_alert_id_t alert) {
107 dt_rv_plic_alert_t count = kDtRvPlicAlertCount;
108 if (alert < rv_plic_desc[dt].first_alert || alert >= rv_plic_desc[dt].first_alert + (dt_alert_id_t)count) {
109 return count;
110 }
111 return (dt_rv_plic_alert_t)(alert - rv_plic_desc[dt].first_alert);
112}
113
114
115
117 dt_rv_plic_t dt,
118 dt_rv_plic_clock_t clk) {
119 // Return the first clock in case of invalid argument.
120 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
121}
122
124 dt_rv_plic_t dt,
125 dt_rv_plic_reset_t rst) {
126 const dt_rv_plic_reset_t count = kDtRvPlicResetCount;
127 if (rst >= count) {
128 return kDtResetUnknown;
129 }
130 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
131}
132
133