quic/qbox
Loading...
Searching...
No Matches
qemu_xhci.h
1/*
2 * This file is part of libqbox
3 * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#ifndef _LIBQBOX_COMPONENTS_USB_XHCI_H
9#define _LIBQBOX_COMPONENTS_USB_XHCI_H
10
11#include <module_factory_registery.h>
12
13#include <qemu_gpex.h>
14
17{
18public:
19 class Device : public QemuDevice
20 {
21 friend qemu_xhci;
22
23 public:
24 Device(const sc_core::sc_module_name& name, QemuInstance& inst, const char* qom_type)
25 : QemuDevice(name, inst, qom_type)
26 {
27 }
28
29 std::function<void()> set_dev_props;
30
33 void end_of_elaboration() override {}
34
35 protected:
36 virtual void usb_realize(qemu::Bus& usb_bus)
37 {
38 m_dev.set_parent_bus(usb_bus);
39 QemuDevice::end_of_elaboration();
40 }
41 };
42
43protected:
44 std::vector<Device*> m_devices;
45
46public:
47 qemu_xhci(const sc_core::sc_module_name& name, sc_core::sc_object* o, sc_core::sc_object* t)
49 {
50 }
51 qemu_xhci(const sc_core::sc_module_name& n, QemuInstance& inst, qemu_gpex* gpex)
52 : qemu_gpex::Device(n, inst, "qemu-xhci")
53 {
54 gpex->add_device(*this);
55 }
56
57 void add_device(Device& dev)
58 {
59 if (m_inst != dev.get_qemu_inst()) {
60 SCP_FATAL(SCMOD) << "USB device and host have to be in same qemu instance";
61 }
62 m_devices.push_back(&dev);
63 }
64
65 void end_of_elaboration() override
66 {
67 qemu_gpex::Device::end_of_elaboration();
68
69 qemu::Bus root_bus = m_dev.get_child_bus("usb-bus.0");
70 for (Device* device : m_devices) {
71 if (device->set_dev_props) {
72 device->set_dev_props();
73 }
74 device->usb_realize(root_bus);
75 }
76 }
77};
78
79extern "C" void module_register();
80#endif
QEMU device abstraction as a SystemC module.
Definition device.h:37
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 libqemu-cxx.h:732
Definition qemu_gpex.h:35
Definition qemu_gpex.h:32
Definition qemu_xhci.h:20
void end_of_elaboration() override
We cannot do the end_of_elaboration at this point because we need the USB bus (created only during th...
Definition qemu_xhci.h:33
This class wraps the qemu's XHCI USB controller: eXtensible Host Controller Interface.
Definition qemu_xhci.h:17