qualcomm/qbox
Loading...
Searching...
No Matches
pub.h
1/*
2 * QEMU DSP PUB
3 *
4 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All Rights Reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <ports/initiator-signal-socket.h>
23#include <ports/target-signal-socket.h>
24#include <module_factory_registery.h>
25#include <tlm_sockets_buswidth.h>
26#include <systemc>
27#include <tlm>
28#include <tlm_utils/simple_target_socket.h>
29
30#include <scp/report.h>
31
32#define QDSP6SS_NMI 0x00040
33#define QDSP6SS_BOOT_CORE_START 0x00400
34#define QDSP6SS_BOOT_CMD 0x00404
35
36#define NMI_CLEAR_STATUS_MASK 0x02
37#define NMI_SET_MASK 0x01
38#define BOOT_CORE_MASK 0x01
39#define BOOT_CMD_MASK 0x01
40
41#define QDSP6SS_VERSION 0x00000
42#define QDSP6SS_DBG_CFG 0x00018
43#define QDSP6SS_RET_CFG 0x0001C
44#define QDSP6SS_NMI_STATUS 0x00044
45#define QDSP6SS_STRAP_TCM_BASE_STATUS 0x00100
46#define QDSP6SS_STRAP_AHBUPPER_STATUS 0x00104
47#define QDSP6SS_STRAP_AHBLOWER_STATUS 0x00108
48#define QDSP6SS_STRAP_AHBS_BASE_STATUS 0x0010C
49#define QDSP6SS_STRAP_CLADE_RWCFG_BASE_STATUS 0x00110
50#define QDSP6SS_STRAP_AXIM2UPPER_STATUS 0x0011C
51#define QDSP6SS_STRAP_AXIM2LOWER_STATUS 0x00120
52#define QDSP6SS_CORE_MEM_STAGGER_CTL 0x00140
53#define QDSP6SS_DBG_NMI_PWR_STATUS 0x00304
54#define QDSP6SS_BOOT_STATUS 0x00408
55#define QDSP6SS_MEM_STATUS 0x00438
56#define QDSP6SS_L2MEM_EFUSE_STATUS 0x00490
57#define QDSP6SS_CP_CLK_CTL 0x00508
58#define QDSP6SS_CPMEM_STATUS 0x00528
59#define QDSP6SS_L2ITCM_STATUS 0x00538
60#define QDSP6SS_LMH_STATUS 0x0081C
61#define QDSP6SS_ISENSE_STATUS 0x00830
62#define QDSP6SS_TEST_BUS_VALUE 0x02004
63#define QDSP6SS_HMX_STATUS 0x02024
64#define QDSP6SS_CORE_STATUS 0x02028
65#define QDSP6SS_INTF_HALTACK 0x0208C
66#define QDSP6SS_INTFCLAMP_STATUS 0x02098
67#define QDSP6SS_CORE_BHS_STATUS 0x02418
68#define QDSP6SS_RESET_STATUS 0x02448
69#define QDSP6SS_CLAMP_STATUS 0x02458
70#define QDSP6SS_CLK_STATUS 0x02468
71#define QDSP6SS_MEM_STAGGER_RESET_STATUS 0x02478
72
73#define PUBCSR_TRIG_MASK 0x1
74
75class pub : public sc_core::sc_module
76{
77 SCP_LOGGER();
78
79private:
80 bool nmi_gen = false;
81 bool nmi_clear_status = false;
82 bool nmi_triggered_pub = false;
83 bool boot_core_start = false;
84 bool boot_status = false;
85 bool prev_hex_halt = false;
86 bool prev_hex_halt_valid = false;
87 bool coproc_enabled = false;
88 sc_core::sc_event update_ev;
89 uint64_t ret_cfg;
90 uint64_t dbg_cfg;
91 uint64_t core_mem_stagger_ctl;
92
93public:
94 InitiatorSignalSocket<bool> hex_halt;
95 InitiatorSignalSocket<bool> nmi;
96 tlm_utils::simple_target_socket<pub, DEFAULT_TLM_BUSWIDTH> socket;
98
99private:
100 void pub_update()
101 {
102 if (nmi_gen) {
103 nmi_triggered_pub = true;
104 nmi->write(1);
105 nmi->write(0);
106 }
107 if (nmi_clear_status) {
108 nmi_triggered_pub = false;
109 }
110 const bool hex_halt_value = !boot_status;
111 if (!prev_hex_halt_valid || hex_halt_value != prev_hex_halt) {
112 hex_halt->write(hex_halt_value);
113 prev_hex_halt = hex_halt_value;
114 prev_hex_halt_valid = true;
115 }
116 }
117
118 void pub_write(uint64_t offset, uint64_t val, unsigned size)
119 {
120 switch (offset) {
121 case QDSP6SS_NMI:
122 nmi_clear_status = (val & NMI_CLEAR_STATUS_MASK);
123 nmi_gen = (val & NMI_SET_MASK);
124 break;
125 case QDSP6SS_BOOT_CORE_START:
126 boot_core_start = (val & BOOT_CORE_MASK);
127 break;
128 case QDSP6SS_BOOT_CMD:
129 boot_status = (val & BOOT_CMD_MASK);
130 SCP_WARN(()) << "BOOT_CMD write value=0x" << std::hex << val << " boot_status=" << std::dec << boot_status;
131 break;
132 case QDSP6SS_DBG_CFG:
133 dbg_cfg = val;
134 break;
135 case QDSP6SS_RET_CFG:
136 ret_cfg = val;
137 break;
138 case QDSP6SS_CORE_MEM_STAGGER_CTL:
139 // TURING_QDSP6SS_CORE_MEM_STAGGER_CTL.DIV is bits [3:0].
140 core_mem_stagger_ctl = val & 0xf;
141 break;
142 case QDSP6SS_CP_CLK_CTL:
143 coproc_enabled = val;
144 break;
145 default:
146 SCP_WARN(()) << "Unimplemented write offset=0x" << std::hex << offset << " value=0x" << val << std::dec;
147 break;
148 }
149
150 update_ev.notify();
151 }
152
153 uint64_t pub_read(uint64_t offset, unsigned size)
154 {
155 switch (offset) {
156 /* RO registers: */
157 case QDSP6SS_VERSION:
158 return 0x10020000;
159 case QDSP6SS_DBG_CFG:
160 return dbg_cfg;
161 case QDSP6SS_RET_CFG:
162 return ret_cfg;
163 case QDSP6SS_NMI_STATUS:
164 return nmi_triggered_pub ? PUBCSR_TRIG_MASK : 0x0;
165 case QDSP6SS_STRAP_TCM_BASE_STATUS:
166 return 0x0;
167 case QDSP6SS_STRAP_AHBUPPER_STATUS:
168 return 0x0;
169 case QDSP6SS_STRAP_AHBLOWER_STATUS:
170 return 0x0;
171 case QDSP6SS_STRAP_AHBS_BASE_STATUS:
172 return 0x0;
173 case QDSP6SS_STRAP_CLADE_RWCFG_BASE_STATUS:
174 return 0x0;
175 case QDSP6SS_STRAP_AXIM2UPPER_STATUS:
176 return 0x0;
177 case QDSP6SS_STRAP_AXIM2LOWER_STATUS:
178 return 0x0;
179 case QDSP6SS_CORE_MEM_STAGGER_CTL:
180 return core_mem_stagger_ctl;
181 case QDSP6SS_DBG_NMI_PWR_STATUS:
182 return 0x0;
183 case QDSP6SS_BOOT_STATUS:
184 return boot_status ? 0x1 : 0x0;
185 case QDSP6SS_MEM_STATUS:
186 return 0x1F001F;
187 case QDSP6SS_L2MEM_EFUSE_STATUS:
188 return 0xF;
189 case QDSP6SS_CP_CLK_CTL:
190 return coproc_enabled;
191 case QDSP6SS_CPMEM_STATUS:
192 return 0x0;
193 case QDSP6SS_L2ITCM_STATUS:
194 return 0x0;
195 case QDSP6SS_LMH_STATUS:
196 return 0x1;
197 case QDSP6SS_ISENSE_STATUS:
198 return 0x0;
199 case QDSP6SS_TEST_BUS_VALUE:
200 return 0x0;
201 case QDSP6SS_HMX_STATUS:
202 return 0x14;
203 case QDSP6SS_CORE_STATUS:
204 return 0x0;
205 case QDSP6SS_INTF_HALTACK:
206 return 0x0;
207 case QDSP6SS_INTFCLAMP_STATUS:
208 return 0x0;
209 case QDSP6SS_CORE_BHS_STATUS:
210 return 0x0;
211 case QDSP6SS_RESET_STATUS:
212 return 0x0;
213 case QDSP6SS_CLAMP_STATUS:
214 return 0x0;
215 case QDSP6SS_CLK_STATUS:
216 return 0x1FFF;
217 case QDSP6SS_MEM_STAGGER_RESET_STATUS:
218 return 0x0;
219 default:
220 SCP_WARN(()) << "Unimplemented read offset=0x" << std::hex << offset << std::dec;
221 return 0x0;
222 }
223 return 0;
224 }
225
226 void pub_reset()
227 {
228 SCP_WARN(())("Reset");
229
230 nmi_gen = false;
231 nmi_clear_status = false;
232 nmi_triggered_pub = false;
233 boot_core_start = false;
234 boot_status = false;
235 prev_hex_halt = false;
236 prev_hex_halt_valid = false;
237 dbg_cfg = 0;
238 core_mem_stagger_ctl = 0;
239 }
240
241 void b_transport(tlm::tlm_generic_payload& txn, sc_core::sc_time& delay)
242 {
243 unsigned int len = txn.get_data_length();
244 unsigned char* ptr = txn.get_data_ptr();
245 sc_dt::uint64 addr = txn.get_address();
246 assert(len == 4);
247
248 switch (txn.get_command()) {
249 case tlm::TLM_READ_COMMAND: {
250 uint32_t data = pub_read(addr & 0xfff, len);
251 memcpy(ptr, &data, len);
252 SCP_INFO(()) << "b_transport read " << std::hex << addr << " " << data;
253 break;
254 }
255 case tlm::TLM_WRITE_COMMAND: {
256 uint32_t data;
257 memcpy(&data, ptr, len);
258 SCP_INFO(()) << "b_transport write " << std::hex << addr << " " << data;
259 pub_write(addr & 0xfff, data, len);
260 break;
261 }
262 default:
263 SCP_ERR(()) << "TLM command not supported";
264 break;
265 }
266
267 txn.set_response_status(tlm::TLM_OK_RESPONSE);
268 }
269
270public:
271 pub(sc_core::sc_module_name name): hex_halt("hex_halt"), nmi("nmi"), socket("socket"), reset("reset")
272 {
273 SCP_TRACE(())("Init");
274 socket.register_b_transport(this, &pub::b_transport);
275
276 reset.register_value_changed_cb([&](bool asserted) {
277 if (asserted) {
278 pub_reset();
279 pub_update();
280 }
281 });
282 pub_reset();
283
284 SC_METHOD(pub_update);
285 sensitive << update_ev;
286 }
287};
288
289extern "C" void module_register();
Definition target-signal-socket.h:163