quic/qbox
Loading...
Searching...
No Matches
nvme.h
1/*
2 * This file is part of libqbox
3 * Copyright (c) 2022-2023 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_PCI_NVME_H
10#define _LIBQBOX_COMPONENTS_PCI_NVME_H
11
12#include <cci_configuration>
13
14#include <module_factory_registery.h>
15#include <libgssync.h>
16
17#include <qemu_gpex.h>
18
20{
21 // TODO: use a real backend object
22protected:
23 cci::cci_param<std::string> p_serial;
24 cci::cci_param<std::string> p_blob_file;
25 cci::cci_param<uint32_t> max_ioqpairs;
26 std::string m_drive_id;
27
28public:
29 nvme_disk(const sc_core::sc_module_name& name, sc_core::sc_object* o)
30 : nvme_disk(name, *(dynamic_cast<QemuInstance*>(o)))
31 {
32 }
33 nvme_disk(const sc_core::sc_module_name& name, QemuInstance& inst)
34 : qemu_gpex::Device(name, inst, "nvme")
35 , p_serial("serial", basename(), "Serial name of the nvme disk")
36 , p_blob_file("blob_file", "", "Blob file to load as data storage")
37 , max_ioqpairs("max_ioqpairs", 64, "Passed through to QEMU max_ioqpairs")
38 , m_drive_id(basename())
39 {
40 m_drive_id += "_drive";
41 std::string file = p_blob_file;
42
43 std::stringstream opts;
44 opts << "if=sd,id=" << m_drive_id << ",file=" << file << ",format=raw";
45 m_inst.add_arg("-drive");
46 m_inst.add_arg(opts.str().c_str());
47 }
48
49 void before_end_of_elaboration() override
50 {
51 qemu_gpex::Device::before_end_of_elaboration();
52
53 std::string serial = p_serial;
54 m_dev.set_prop_str("serial", serial.c_str());
55 m_dev.set_prop_parse("drive", m_drive_id.c_str());
56 m_dev.set_prop_int("max_ioqpairs", max_ioqpairs);
57 }
58
59 void gpex_realize(qemu::Bus& bus) override { qemu_gpex::Device::gpex_realize(bus); }
60};
61
62extern "C" void module_register();
63
64#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 nvme.h:20
Definition libqemu-cxx.h:732
Definition qemu_gpex.h:35