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 "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 base_addr[kDtRvPlicRegBlockCount]; /**< 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[kDtRvPlicClockCount]; /**< Clock signal connected to each clock port */
29 dt_reset_t reset[kDtRvPlicResetCount]; /**< Reset signal connected to each reset port */
31
32
33
34
35static const dt_desc_rv_plic_t rv_plic_desc[kDtRvPlicCount] = {
36 [kDtRvPlic] = {
37 .inst_id = kDtInstanceIdRvPlic,
38 .base_addr = {
39 [kDtRvPlicRegBlockCore] = 0x48000000,
40 },
42 .clock = {
44 },
45 .reset = {
47 },
48 },
49};
50
51/**
52 * Return a pointer to the `dt_rv_plic_desc_t` structure of the requested
53 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
54 * the function) with the provided default value.
55 */
56#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_rv_plic_t)0 || (dt) >= kDtRvPlicCount) return (default); &rv_plic_desc[dt]; })
57
59 if (inst_id >= kDtInstanceIdRvPlic && inst_id <= kDtInstanceIdRvPlic) {
60 return (dt_rv_plic_t)(inst_id - kDtInstanceIdRvPlic);
61 }
62 return (dt_rv_plic_t)0;
63}
64
69
71 dt_rv_plic_t dt,
72 dt_rv_plic_reg_block_t reg_block) {
73 // Return a recognizable address in case of wrong argument.
74 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
75}
76
77
79 dt_rv_plic_t dt,
80 dt_rv_plic_alert_t alert) {
81 return (dt_alert_id_t)((uint32_t)rv_plic_desc[dt].first_alert + (uint32_t)alert);
82}
83
85 dt_rv_plic_t dt,
86 dt_alert_id_t alert) {
87 dt_rv_plic_alert_t count = kDtRvPlicAlertCount;
88 if (alert < rv_plic_desc[dt].first_alert || alert >= rv_plic_desc[dt].first_alert + (dt_alert_id_t)count) {
89 return count;
90 }
91 return (dt_rv_plic_alert_t)(alert - rv_plic_desc[dt].first_alert);
92}
93
94
95
97 dt_rv_plic_t dt,
99 // Return the first clock in case of invalid argument.
100 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
101}
102
104 dt_rv_plic_t dt,
105 dt_rv_plic_reset_t rst) {
106 const dt_rv_plic_reset_t count = kDtRvPlicResetCount;
107 if (rst >= count) {
108 return kDtResetUnknown;
109 }
110 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
111}
112
113