3
3
#include " processor.h"
4
4
#include " arith.h"
5
5
#include " sim.h"
6
+ #include " dts.h"
6
7
7
8
#define DOMAINCFG 0x0
8
9
#define SOURCECFG_BASE 0x4
39
40
#define TARGET_GUEST_MASK 0x3f000
40
41
#define TARGET_EIID_MASK 0x7ff
41
42
42
- aplic_t ::aplic_t (std::vector< processor_t *>& procs , aplic_t *parent) : procs(procs ), parent(parent), child(nullptr ), domaincfg((0x80 << 24 ) | DOMAINCFG_DM_MASK), sourcecfg(), mmsiaddrcfgh(MMSIADDRCFGH_L_MASK), ie(), target(), level(), genmsi(0 ), deleg_mask()
43
+ aplic_t ::aplic_t (const simif_t *simif , aplic_t *parent) : simif(simif ), parent(parent), child(nullptr ), domaincfg((0x80 << 24 ) | DOMAINCFG_DM_MASK), sourcecfg(), mmsiaddrcfgh(MMSIADDRCFGH_L_MASK), ie(), target(), level(), genmsi(0 ), deleg_mask()
43
44
{
44
45
}
45
46
@@ -113,10 +114,12 @@ void aplic_t::set_interrupt_level(uint32_t id, int lvl)
113
114
114
115
void aplic_t::send_msi (uint32_t proc_id, uint32_t guest, uint32_t eiid)
115
116
{
116
- if (!eiid || proc_id >= procs.size ())
117
+ auto &procs = simif->get_harts ();
118
+ auto it = procs.find (proc_id);
119
+ if (!eiid || it == procs.end ())
117
120
return ;
118
121
119
- auto proc = procs[proc_id] ;
122
+ processor_t * proc = it-> second ;
120
123
if (!parent) {
121
124
proc->imsic ->m ->pendei (eiid);
122
125
} else if (guest) {
@@ -255,7 +258,7 @@ bool aplic_t::store(reg_t addr, size_t len, const uint8_t* bytes)
255
258
return true ;
256
259
}
257
260
258
- std::string aplic_generate_dts (const sim_t * sim, const std::vector<std::string>& sargs UNUSED)
261
+ std::string aplic_m_generate_dts (const sim_t * sim, const std::vector<std::string>& sargs UNUSED)
259
262
{
260
263
auto cfg = sim->get_cfg ();
261
264
isa_parser_t isa (cfg.isa , cfg.priv );
@@ -273,6 +276,14 @@ std::string aplic_generate_dts(const sim_t* sim, const std::vector<std::string>&
273
276
" compatible = \" riscv,aplic\" ;\n "
274
277
" };\n " ;
275
278
}
279
+ return s.str ();
280
+ }
281
+
282
+ std::string aplic_s_generate_dts (const sim_t * sim, const std::vector<std::string>& sargs UNUSED)
283
+ {
284
+ auto cfg = sim->get_cfg ();
285
+ isa_parser_t isa (cfg.isa , cfg.priv );
286
+ std::stringstream s;
276
287
if (isa.extension_enabled (EXT_SSAIA)) {
277
288
s << std::hex
278
289
<< " APLIC_S: aplic@" << APLIC_S_BASE << " {\n "
@@ -287,9 +298,33 @@ std::string aplic_generate_dts(const sim_t* sim, const std::vector<std::string>&
287
298
return s.str ();
288
299
}
289
300
290
- aplic_t * aplic_parse_from_fdt (const void * fdt, const sim_t * sim, reg_t * base, const std::vector<std::string>& sargs UNUSED)
301
+ typedef aplic_t aplic_m_t ;
302
+ typedef aplic_t aplic_s_t ;
303
+ aplic_m_t * aplic_m_parse_from_fdt (const void * fdt, const sim_t * sim, reg_t * base, const std::vector<std::string>& sargs UNUSED)
291
304
{
305
+ reg_t aplic_m_base, aplic_s_base;
306
+ if (fdt_parse_aplic (fdt, &aplic_m_base, &aplic_s_base, " riscv,aplic" ) == 0 ) {
307
+ if (aplic_m_base) {
308
+ *base = aplic_m_base;
309
+ return new aplic_t (sim, nullptr );
310
+ }
311
+ }
292
312
return nullptr ;
293
313
}
294
314
295
- REGISTER_DEVICE (aplic, aplic_parse_from_fdt, aplic_generate_dts)
315
+ aplic_s_t * aplic_s_parse_from_fdt (const void * fdt, const sim_t * sim, reg_t * base, const std::vector<std::string>& sargs UNUSED)
316
+ {
317
+ reg_t aplic_m_base, aplic_s_base;
318
+ if (fdt_parse_aplic (fdt, &aplic_m_base, &aplic_s_base, " riscv,aplic" ) == 0 ) {
319
+ if (aplic_s_base) {
320
+ *base = aplic_s_base;
321
+ auto *ptr = new aplic_t (sim, sim->aplic_m .get ());
322
+ if (sim->aplic_m )
323
+ sim->aplic_m ->set_child (ptr);
324
+ return ptr;
325
+ }
326
+ }
327
+ return nullptr ;
328
+ }
329
+ REGISTER_DEVICE (aplic_m, aplic_m_parse_from_fdt, aplic_m_generate_dts)
330
+ REGISTER_DEVICE(aplic_s, aplic_s_parse_from_fdt, aplic_s_generate_dts)
0 commit comments