qualcomm/qbox
Loading...
Searching...
No Matches
e1000e_pci.h
1/*
2 * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause-Clear
5 */
6
7#ifndef _LIBQBOX_COMPONENTS_E1000E_PCI_H
8#define _LIBQBOX_COMPONENTS_E1000E_PCI_H
9
10#include <cci_configuration>
11
12#include <libgssync.h>
13#include <qemu-instance.h>
14
15#include <module_factory_registery.h>
16
17#include <qemu_gpex.h>
18
19// Wraps QEMU's "e1000e" PCIe NIC (Intel 82574L) so it can be instantiated
20// as a qbox PCI device. Same boilerplate as virtio_net_pci / rtl8139_pci;
21// the only thing that differs is the QEMU device-model name string passed
22// to qemu_gpex::Device.
23//
24// Why this NIC: kdnet (Windows kernel network debugging transport) ships
25// with native support for a fixed set of vendor/device IDs, and e1000e
26// (8086:10D3) is on that list. virtio-net is not, which makes it unusable
27// for kdnet without a custom extensibility module.
28class e1000e_pci : public qemu_gpex::Device
29{
30 std::string m_netdev_id;
31 cci::cci_param<std::string> p_mac;
32 cci::cci_param<std::string> p_netdev_str;
33 // PCI slot pinning. Empty = auto-assign by gpex. Useful when the
34 // guest OS records a specific bus/device/function in persistent state
35 // (e.g. Windows kdnet busparams in BCD, NVMe boot device records) and
36 // re-assignment causes mismatches that break the guest. Format is
37 // "<dev>.<func>" or just "<dev>"; QEMU's addr qdev prop takes that
38 // string verbatim.
39 cci::cci_param<std::string> p_addr;
40
41public:
42 e1000e_pci(const sc_core::sc_module_name& name, sc_core::sc_object* o, sc_core::sc_object* t)
43 : e1000e_pci(name, *(dynamic_cast<QemuInstance*>(o)), (dynamic_cast<qemu_gpex*>(t)))
44 {
45 }
46 e1000e_pci(const sc_core::sc_module_name& name, QemuInstance& inst, qemu_gpex* gpex)
47 : qemu_gpex::Device(name, inst, "e1000e")
48 , m_netdev_id(std::string(sc_core::sc_module::name()) + "-id")
49 , p_mac("mac", "", "MAC address of NIC")
50 , p_netdev_str("netdev_str", "type=user", "netdev string for QEMU (do not specify ID)")
51 , p_addr("addr", "", "PCI slot pinning, e.g. \"02.0\"; empty leaves it to gpex auto-assignment")
52 {
53 std::stringstream opts;
54 opts << p_netdev_str.get_value();
55 opts << ",id=" << m_netdev_id;
56
57 m_inst.add_arg("-netdev");
58 m_inst.add_arg(opts.str().c_str());
59
60 gpex->add_device(*this);
61 }
62
63 void before_end_of_elaboration() override
64 {
65 qemu_gpex::Device::before_end_of_elaboration();
66 if (!p_mac.get_value().empty()) m_dev.set_prop_str("mac", p_mac.get_value().c_str());
67 m_dev.set_prop_str("netdev", m_netdev_id.c_str());
68 m_dev.set_prop_str("romfile", "");
69 if (!p_addr.get_value().empty()) m_dev.set_prop_str("addr", p_addr.get_value().c_str());
70 }
71};
72
73extern "C" void module_register();
74
75#endif
This class encapsulates a libqemu-cxx qemu::LibQemu instance. It handles QEMU parameters and instance...
Definition qemu-instance.h:89
Definition qemu_gpex.h:35