quic/qbox
Loading...
Searching...
No Matches
virtio-mmio.h
1/*
2 * This file is part of libqbox
3 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
4 * Author: GreenSocs 2022
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#pragma once
10
11#include <vector>
12
13#include <cci_configuration>
14
15#include <device.h>
16#include <ports/target.h>
17#include <ports/qemu-initiator-signal-socket.h>
18
19#include <cciutils.h>
20#include <scp/report.h>
21
23{
24 SCP_LOGGER();
25
26public:
27 QemuTargetSocket<> socket;
29 QemuDevice virtio_mmio_device;
30
31 /*
32 * qemu qbus hierachy created behind this sc_module:
33 * virtio_mmio_device
34 * + qemu-type: "virtio-mmio" (this is a sysbus device)
35 * + qbus-child(&qon-child) "virtio-mmio-bus":
36 * + qdev-child (this QemuVirtioMMIO object):
37 * + qemu-type: "virtio-net-device"
38 */
39 QemuVirtioMMIO(sc_core::sc_module_name nm, QemuInstance& inst, const char* device_type)
40 : QemuDevice(nm, inst, device_type)
41 , socket("mem", inst)
42 , irq_out("irq_out")
43 , virtio_mmio_device("virtio_mmio", inst, "virtio-mmio")
44 {
45 SCP_TRACE(())("Constructor");
46 }
47
48 void before_end_of_elaboration() override
49 {
50 virtio_mmio_device.instantiate();
51 QemuDevice::before_end_of_elaboration();
52 for (auto n : gs::sc_cci_children((std::string(name()) + ".device_properties").c_str())) {
53 cci::cci_value v = gs::cci_get(cci::cci_get_broker(), std::string(name()) + ".device_properties." + n);
54 /* NB we could use _parse here,but JSON strings dont always match QEMU command line strings! */
55 if (v.is_bool()) {
56 SCP_DEBUG(())("Setting bool {} to {}", n, v.to_json());
57 m_dev.set_prop_bool(n.c_str(), v.get_bool());
58 continue;
59 }
60 if (v.is_number()) {
61 SCP_DEBUG(())("Setting number {} to {}", n, v.to_json());
62 m_dev.set_prop_int(n.c_str(), v.get_uint64());
63 continue;
64 }
65 if (v.is_string()) {
66 SCP_DEBUG(())("Setting string {} to {}", n, v.to_json());
67 m_dev.set_prop_str(n.c_str(), v.get_string().c_str());
68 continue;
69 }
70 SCP_WARN(())("Ignoring property {}, unknown type. {}", n, v.to_json());
71 }
72
73 virtio_mmio_device.get_qemu_dev().set_prop_bool("force-legacy", true);
74
75 // force MMIO devices to use transport address (which will be 0, causing automatic ID)
76 virtio_mmio_device.get_qemu_dev().set_prop_bool("format_transport_address", false);
77 }
78
79 void end_of_elaboration() override
80 {
81 /*
82 * we realize virtio_mmio_device first because
83 * it creates the "virtio-mmio-bus" we need below
84 */
85 virtio_mmio_device.set_sysbus_as_parent_bus();
86 virtio_mmio_device.realize();
87
88 /*
89 * Expose the sysbus device mmio & irq
90 */
91 qemu::SysBusDevice sbd(virtio_mmio_device.get_qemu_dev());
92 socket.init(sbd, 0);
93 irq_out.init_sbd(sbd, 0);
94
95 /*
96 * Realize the true virtio net object
97 */
99 virtio_device.set_parent_bus(QemuVirtioMMIO::get_bus());
100 QemuDevice::end_of_elaboration();
101 }
102
103private:
104 qemu::Bus get_bus()
105 {
106 qemu::Device virtio_mmio_dev(virtio_mmio_device.get_qemu_dev());
107 return virtio_mmio_dev.get_prop_link("virtio-mmio-bus");
108 }
109};
QEMU device abstraction as a SystemC module.
Definition device.h:37
A QEMU output GPIO exposed as a InitiatorSignalSocket<bool>
Definition qemu-initiator-signal-socket.h:40
void init_sbd(qemu::SysBusDevice sbd, int gpio_idx)
Initialize this socket with a QEMU SysBusDevice, and a GPIO index.
Definition qemu-initiator-signal-socket.h:173
This class encapsulates a libqemu-cxx qemu::LibQemu instance. It handles QEMU parameters and instance...
Definition qemu-instance.h:89
Definition target.h:160
Definition virtio-mmio.h:23
Definition libqemu-cxx.h:732
Definition libqemu-cxx.h:616
Definition libqemu-cxx.h:638
std::list< std::string > sc_cci_children(sc_core::sc_module_name name)
return a list of 'unconsumed' children from the given module name, can be used inside or outside the ...
Definition cciutils.cc:63