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
19class nvme : public qemu_gpex::Device
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(const sc_core::sc_module_name& name, sc_core::sc_object* o, sc_core::sc_object* t)
30 : nvme(name, *(dynamic_cast<QemuInstance*>(o)), (dynamic_cast<qemu_gpex*>(t)))
31 {
32 }
33 nvme(const sc_core::sc_module_name& name, QemuInstance& inst, qemu_gpex* gpex)
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 if (p_blob_file.get_value().empty()) {
41 SCP_FATAL(()) << "the nvme device needs blob_file CCI parameter!";
42 }
43 m_drive_id += "_drive";
44 std::string file = p_blob_file.get_value();
45
46 std::stringstream opts;
47 opts << "if=sd,id=" << m_drive_id << ",file=" << file << ",format=raw";
48 m_inst.add_arg("-drive");
49 m_inst.add_arg(opts.str().c_str());
50
51 gpex->add_device(*this);
52 }
53
54 void before_end_of_elaboration() override
55 {
56 qemu_gpex::Device::before_end_of_elaboration();
57
58 std::string serial = p_serial;
59 m_dev.set_prop_str("serial", serial.c_str());
60 m_dev.set_prop_parse("drive", m_drive_id.c_str());
61 m_dev.set_prop_int("max_ioqpairs", max_ioqpairs);
62 }
63
64 void gpex_realize(qemu::Bus& bus) override { qemu_gpex::Device::gpex_realize(bus); }
65};
66
67extern "C" void module_register();
68
69#endif
This class encapsulates a libqemu-cxx qemu::LibQemu instance. It handles QEMU parameters and instance...
Definition qemu-instance.h:86
void add_arg(const char *arg)
Add a command line argument to the qemu instance.
Definition qemu-instance.h:327
Definition target.h:160
Definition nvme.h:20
Definition libqemu-cxx.h:739
Definition qemu_gpex.h:35
Definition qemu_gpex.h:32