qualcomm/qbox
Loading...
Searching...
No Matches
arm_gicv2m.h
1/*
2 * Self-contained arm_gicv2m QBox module.
3 *
4 * Wraps QEMU's "arm-gicv2m" device as an independently loadable DLL module.
5 * When a GIC reference (v2 or v3) is passed as a constructor argument, SPI
6 * outputs are automatically bound to the GIC's SPI inputs.
7 *
8 * Copyright (c) 2025 Qualcomm Innovation Center, Inc.
9 * SPDX-License-Identifier: BSD-3-Clause
10 */
11
12#ifndef _LIBQBOX_COMPONENTS_IRQ_CTRL_ARM_GICV2M_H
13#define _LIBQBOX_COMPONENTS_IRQ_CTRL_ARM_GICV2M_H
14
15#include <string>
16
17#include <systemc>
18#include <cci_configuration>
19
20#include <scp/report.h>
21
22#include <module_factory_registery.h>
23
24#include <cciutils.h>
25#include <device.h>
26#include <ports/target.h>
27#include <ports/qemu-initiator-signal-socket.h>
28#include <ports/qemu-target-signal-socket.h>
29
30class arm_gicv2m : public QemuDevice
31{
32protected:
33 cci::cci_param<unsigned int> p_base_spi;
34 cci::cci_param<unsigned int> p_num_spis;
35
36private:
37 sc_core::sc_object* m_gic;
38
39public:
40 sc_core::sc_vector<QemuInitiatorSignalSocket> spi_out;
41
42 QemuTargetSocket<> iface;
43
44 arm_gicv2m(const sc_core::sc_module_name& name, sc_core::sc_object* o, sc_core::sc_object* gic)
45 : arm_gicv2m(name, *(dynamic_cast<QemuInstance*>(o)), gic)
46 {
47 }
48
49 arm_gicv2m(const sc_core::sc_module_name& name, QemuInstance& inst, sc_core::sc_object* gic = nullptr)
50 : QemuDevice(name, inst, "arm-gicv2m")
51 , p_base_spi("base_spi", 0, "Start index of gic's spis")
52 , p_num_spis("num_spis", 0, "Number of gic's spis")
53 , m_gic(gic)
54 , spi_out("spi_out", p_num_spis)
55 , iface("iface", inst)
56 {
57 }
58
59 void before_end_of_elaboration() override
60 {
61 QemuDevice::before_end_of_elaboration();
62
63 m_dev.set_prop_int("base-spi", p_base_spi);
64 m_dev.set_prop_int("num-spi", p_num_spis);
65
66 if (m_gic) {
67 for (unsigned int i = 0; i < p_num_spis; i++) {
68 std::string spi_name = std::string(m_gic->name()) + ".spi_in_" + std::to_string(p_base_spi + i);
69 sc_core::sc_object* obj = gs::find_sc_obj(nullptr, spi_name);
70 if (!obj) {
71 SCP_FATAL(SCMOD) << "Cannot find " << spi_name << " for auto-bind";
72 }
73 auto* target = dynamic_cast<QemuTargetSignalSocket*>(obj);
74 if (!target) {
75 SCP_FATAL(SCMOD) << spi_name << " is not a QemuTargetSignalSocket";
76 }
77 spi_out[i].bind(*target);
78 }
79 }
80 }
81
82 void end_of_elaboration() override
83 {
84 QemuDevice::set_sysbus_as_parent_bus();
85 QemuDevice::end_of_elaboration();
86
87 qemu::SysBusDevice sbd(m_dev);
88
89 iface.init(sbd, 0);
90
91 for (unsigned int i = 0; i < p_num_spis; i++) {
92 spi_out[i].init_sbd(sbd, i);
93 }
94 }
95};
96
97extern "C" void module_register();
98
99#endif
QEMU device abstraction as a SystemC module.
Definition device.h:37
QemuDevice(const sc_core::sc_module_name &name, QemuInstance &inst, const char *qom_type)
Construct a QEMU device.
Definition device.h:86
Definition arm-gicv2.h:25
sc_core::sc_object * find_sc_obj(sc_core::sc_object *m, std::string name, bool test=false)
Helper function to find a sc_object by fully qualified name throws SC_ERROR if nothing found.
Definition cciutils.cc:18