quic/qbox
Loading...
Searching...
No Matches
rtl8139_pci.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_RTL8139_PCI_H
9#define _LIBQBOX_COMPONENTS_RTL8139_PCI_H
10
11#include <cci_configuration>
12
13#include <libgssync.h>
14#include <qemu-instance.h>
15
16#include <module_factory_registery.h>
17
18#include <qemu_gpex.h>
19
21{
22 cci::cci_param<std::string> p_mac;
23 std::string m_netdev_id;
24 cci::cci_param<std::string> p_netdev_str;
25
26public:
27 rtl8139_pci(const sc_core::sc_module_name& name, sc_core::sc_object* o, sc_core::sc_object* t)
28 : rtl8139_pci(name, *(dynamic_cast<QemuInstance*>(o)), (dynamic_cast<qemu_gpex*>(t)))
29 {
30 }
31 rtl8139_pci(const sc_core::sc_module_name& name, QemuInstance& inst, qemu_gpex* gpex)
32 : qemu_gpex::Device(name, inst, "rtl8139")
33 , p_mac("mac", "", "MAC address of NIC")
34 , m_netdev_id(std::string(sc_core::sc_module::name()) + "-id")
35 , p_netdev_str("netdev_str", "type=user", "netdev string for QEMU (do not specify ID)")
36 {
37 std::stringstream opts;
38 opts << p_netdev_str.get_value();
39 opts << ",id=" << m_netdev_id;
40
41 m_inst.add_arg("-netdev");
42 m_inst.add_arg(opts.str().c_str());
43
44 gpex->add_device(*this);
45 }
46
47 void before_end_of_elaboration() override
48 {
49 qemu_gpex::Device::before_end_of_elaboration();
50 // if p_mac is empty, a MAC address will be generated for us
51 if (!p_mac.get_value().empty()) m_dev.set_prop_str("mac", p_mac.get_value().c_str());
52 m_dev.set_prop_str("netdev", m_netdev_id.c_str());
53
54 m_dev.set_prop_str("romfile", "");
55 }
56};
57
58extern "C" void module_register();
59
60#endif
This class encapsulates a libqemu-cxx qemu::LibQemu instance. It handles QEMU parameters and instance...
Definition qemu-instance.h:89
void add_arg(const char *arg)
Add a command line argument to the qemu instance.
Definition qemu-instance.h:329
Definition target.h:160
Definition qemu_gpex.h:35
Definition qemu_gpex.h:32
Definition rtl8139_pci.h:21