qualcomm/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<std::string> p_format;
26 cci::cci_param<uint32_t> max_ioqpairs;
27 std::string m_drive_id;
28
29public:
30 nvme(const sc_core::sc_module_name& name, sc_core::sc_object* o, sc_core::sc_object* t)
31 : nvme(name, *(dynamic_cast<QemuInstance*>(o)), (dynamic_cast<qemu_gpex*>(t)))
32 {
33 }
34 nvme(const sc_core::sc_module_name& name, QemuInstance& inst, qemu_gpex* gpex)
35 : qemu_gpex::Device(name, inst, "nvme")
36 , p_serial("serial", basename(), "Serial name of the nvme disk")
37 , p_blob_file("blob_file", "", "Blob file to load as data storage")
38 , p_format("format", "raw", "Format of the blob file (supported: raw, qcow2)")
39 , max_ioqpairs("max_ioqpairs", 64, "Passed through to QEMU max_ioqpairs")
40 , m_drive_id(basename())
41 {
42 if (p_blob_file.get_value().empty()) {
43 SCP_FATAL(()) << "the nvme device needs blob_file CCI parameter!";
44 }
45 std::string format = p_format.get_value();
46 if (format != "raw" && format != "qcow2") {
47 SCP_FATAL(()) << "format parameter must be 'raw' or 'qcow2', got: " << format;
48 }
49 m_drive_id += "_drive";
50 std::string file = p_blob_file.get_value();
51
52 std::stringstream opts;
53 opts << "if=sd,id=" << m_drive_id << ",file=" << file << ",format=" << p_format.get_value();
54 m_inst.add_arg("-drive");
55 m_inst.add_arg(opts.str().c_str());
56
57 gpex->add_device(*this);
58 }
59
60 void before_end_of_elaboration() override
61 {
62 qemu_gpex::Device::before_end_of_elaboration();
63
64 std::string serial = p_serial;
65 m_dev.set_prop_str("serial", serial.c_str());
66 m_dev.set_prop_parse("drive", m_drive_id.c_str());
67 m_dev.set_prop_int("max_ioqpairs", max_ioqpairs);
68 }
69
70 void gpex_realize(qemu::Bus& bus) override { qemu_gpex::Device::gpex_realize(bus); }
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 libqemu-cxx.h:793
Definition qemu_gpex.h:35