From 9a5eaab9fef17a13ea92b7b25879f85c91ca07c2 Mon Sep 17 00:00:00 2001 From: jhieb Date: Mon, 18 Aug 2025 13:38:27 -0600 Subject: [PATCH] Signoff fix - Add qpex to nvme_disk for lua config support. Updated the nvme disk to take an instance of the gpex via constructor so that it is realized. Updated the documentation with an example of instantiating via lua. Signed-off-by: jhieb --- docs/extra-components/README-local.md | 22 ++++++++++++++++++++-- docs/extra-components/README.md | 20 +++++++++++++++++++- qemu-components/nvme/include/nvme.h | 7 ++++--- qemu-components/nvme/src/nvme.cc | 2 +- 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/docs/extra-components/README-local.md b/docs/extra-components/README-local.md index 0fe29d8e..199be3a5 100644 --- a/docs/extra-components/README-local.md +++ b/docs/extra-components/README-local.md @@ -24,18 +24,36 @@ Components available: * NVME : This allows an NVME disk to be added. Initialise `QemuNvmeDisk` with a qemu instance from the libqbox library (see the libqbox section to initiate a qemu instance): ```c++ - QemuNvmeDisk m_disk1("disk1", m_qemu_inst) + QemuNvmeDisk m_disk1("disk1", m_qemu_inst, m_gpex_inst) ``` The class `QemuNvmeDisk` has 3 parameters: -The constructor : `QemuNvmeDisk(const sc_core::sc_module_name &name, QemuInstance &inst)` +The constructor : `QemuNvmeDisk(const sc_core::sc_module_name &name, QemuInstance &inst, qemu_gpex &gpex)` - "name" : name of the disk - "inst" : instance Qemu +- "gpex" : instance of PCIe GPEX The parameters : - "serial" : Serial name of the nvme disk - "bloc-file" : Blob file to load as data storage - "drive-id" +Example of adding a nvme disk via the conf.lua. Gpex_0 needs to be defined as well so that an instance is passed to the nvme disk so that it can the gpex.add_device(nvme_disk_0) is called. + +```lua +platform = { + gpex_0={...}; + + nvme_disk_0 = { + moduletype = "nvme_disk", + dylib_path = "nvme", + args = {"&platform.qemu_inst", "&platform.gpex_0"}, + serial = "nvme_serial_001", + blob_file=top().."fw/Artifacts/nvme_disk.img", + max_ioqpairs = 64 + }; +}; +``` + ## How to add QEMU OpenCores Eth MAC ### SystemC Code Here there is an example of SystemC Code: diff --git a/docs/extra-components/README.md b/docs/extra-components/README.md index c59fb2c4..3ceb5674 100644 --- a/docs/extra-components/README.md +++ b/docs/extra-components/README.md @@ -186,15 +186,33 @@ Components available: QemuNvmeDisk m_disk1("disk1", m_qemu_inst) ``` The class `QemuNvmeDisk` has 3 parameters: -The constructor : `QemuNvmeDisk(const sc_core::sc_module_name &name, QemuInstance &inst)` +The constructor : `QemuNvmeDisk(const sc_core::sc_module_name &name, QemuInstance &inst, qemu_gpex &gpex)` - "name" : name of the disk - "inst" : instance Qemu +- "gpex" : instance of PCIe GPEX The parameters : - "serial" : Serial name of the nvme disk - "bloc-file" : Blob file to load as data storage - "drive-id" +Example of adding a nvme disk via the conf.lua. Gpex_0 needs to be defined as well so that an instance is passed to the nvme disk so that it can the gpex.add_device(nvme_disk_0) is called. + +```lua +platform = { + gpex_0={...}; + + nvme_disk_0 = { + moduletype = "nvme_disk", + dylib_path = "nvme", + args = {"&platform.qemu_inst", "&platform.gpex_0"}, + serial = "nvme_serial_001", + blob_file=top().."fw/Artifacts/nvme_disk.img", + max_ioqpairs = 64 + }; +}; +``` + ## How to add QEMU OpenCores Eth MAC ### SystemC Code Here there is an example of SystemC Code: diff --git a/qemu-components/nvme/include/nvme.h b/qemu-components/nvme/include/nvme.h index 883ae057..561cf59a 100644 --- a/qemu-components/nvme/include/nvme.h +++ b/qemu-components/nvme/include/nvme.h @@ -26,11 +26,11 @@ class nvme_disk : public qemu_gpex::Device std::string m_drive_id; public: - nvme_disk(const sc_core::sc_module_name& name, sc_core::sc_object* o) - : nvme_disk(name, *(dynamic_cast(o))) + nvme_disk(const sc_core::sc_module_name& name, sc_core::sc_object* o, sc_core::sc_object* gpex) + : nvme_disk(name, *(dynamic_cast(o)), *(dynamic_cast(gpex))) { } - nvme_disk(const sc_core::sc_module_name& name, QemuInstance& inst) + nvme_disk(const sc_core::sc_module_name& name, QemuInstance& inst, qemu_gpex& gpex) : qemu_gpex::Device(name, inst, "nvme") , p_serial("serial", basename(), "Serial name of the nvme disk") , p_blob_file("blob_file", "", "Blob file to load as data storage") @@ -44,6 +44,7 @@ class nvme_disk : public qemu_gpex::Device opts << "if=sd,id=" << m_drive_id << ",file=" << file << ",format=raw"; m_inst.add_arg("-drive"); m_inst.add_arg(opts.str().c_str()); + gpex.add_device(*this); } void before_end_of_elaboration() override diff --git a/qemu-components/nvme/src/nvme.cc b/qemu-components/nvme/src/nvme.cc index 371e1d5d..80f133f9 100644 --- a/qemu-components/nvme/src/nvme.cc +++ b/qemu-components/nvme/src/nvme.cc @@ -8,4 +8,4 @@ #include "nvme.h" -void module_register() { GSC_MODULE_REGISTER_C(nvme_disk, sc_core::sc_object*); } \ No newline at end of file +void module_register() { GSC_MODULE_REGISTER_C(nvme_disk, sc_core::sc_object*, sc_core::sc_object*); } \ No newline at end of file