quic/qbox
Loading...
Searching...
No Matches
ivshmem_plain.h
1/*
2 * This file is part of libqbox
3 * Copyright (c) 2024 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_shm_path;
23 cci::cci_param<uint32_t> p_shm_size;
24 std::string p_shm_id;
25
26public:
27 ivshmem_plain(const sc_core::sc_module_name& name, sc_core::sc_object* o, sc_core::sc_object* t)
28 : ivshmem_plain(name, *(dynamic_cast<QemuInstance*>(o)), (dynamic_cast<qemu_gpex*>(t)))
29 {
30 }
31 ivshmem_plain(const sc_core::sc_module_name& name, QemuInstance& inst, qemu_gpex* gpex)
32 : qemu_gpex::Device(name, inst, "ivshmem-plain")
33 , p_shm_path("shm_path", "", "path of shm file (i.e. /dev/shm/<name of the shm segment>)")
34 , p_shm_size("shm_size", 1024, "size of the shm in MB")
35 , p_shm_id(std::string(sc_core::sc_module::name()) + "-id")
36 {
37 std::stringstream object_string;
38 object_string << "memory-backend-file,size=" << p_shm_size.get_value()
39 << "M,mem-path=" << p_shm_path.get_value() << ",share=on,id=" << p_shm_id;
40
41 m_inst.add_arg("-object");
42 m_inst.add_arg(object_string.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 m_dev.set_prop_str("memdev", p_shm_id.c_str());
51 }
52
54 {
55 // in case Qemu didn't unlink the file at exit
56 unlink(p_shm_path.get_value().c_str());
57 }
58};
59
60extern "C" void module_register();
61
62#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 ivshmem_plain.h:21
Definition qemu_gpex.h:35
Definition qemu_gpex.h:32