quic/qbox
Loading...
Searching...
No Matches
device.h
1/*
2 * This file is part of libqbox
3 * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All Rights Reserved.
4 * Author: GreenSocs 2021
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#ifndef _LIBQBOX_COMPONENTS_DEVICE_H
10#define _LIBQBOX_COMPONENTS_DEVICE_H
11
12#include <systemc>
13
14#include "qemu-instance.h"
15
36class QemuDevice : public sc_core::sc_module, public QemuDeviceBaseIF
37{
38private:
39 std::string m_qom_type;
40
41protected:
42 QemuInstance& m_inst;
43 qemu::Device m_dev;
44 bool m_instanciated = false;
45 bool m_realized = false;
46
47public:
48 void instantiate()
49 {
50 if (m_instanciated) {
51 return;
52 }
53
54 m_dev = m_inst.get().object_new(m_qom_type.c_str());
55 m_instanciated = true;
56 }
57
58 void realize()
59 {
60 if (m_realized) {
61 return;
62 }
63
64 m_dev.set_prop_bool("realized", true);
65 m_realized = true;
66 }
67
75 QemuDevice(const sc_core::sc_module_name& name, QemuInstance& inst, const char* qom_type)
76 : sc_module(name), m_qom_type(qom_type), m_inst(inst)
77 {
78 SCP_WARN(())("QOM Device creation {}", qom_type);
79 }
80
81 virtual ~QemuDevice() {}
82
83 virtual void before_end_of_elaboration() override { instantiate(); }
84
85 virtual void end_of_elaboration() override { realize(); }
86
87 void set_qom_type(std::string const& qom_type) { m_qom_type = qom_type; }
88
89 const char* get_qom_type() const { return m_qom_type.c_str(); }
90
91 qemu::Device get_qemu_dev() { return m_dev; }
92
93 QemuInstance& get_qemu_inst() { return m_inst; }
94
95 void set_sysbus_as_parent_bus(void) { m_dev.set_parent_bus(m_inst.get().sysbus_get_default()); }
96};
97
98#endif
Definition qemu-instance.h:33
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:75
This class encapsulates a libqemu-cxx qemu::LibQemu instance. It handles QEMU parameters and instance...
Definition qemu-instance.h:89
qemu::LibQemu & get()
Returns the underlying qemu::LibQemu instance.
Definition qemu-instance.h:448
Definition target.h:160
Definition libqemu-cxx.h:616