Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 66 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,68 @@ build_lua()

if (NOT WITHOUT_QEMU)

# TODO(Jhieb) pull request changes to make sure capabilities are DWORD aligned.
CPMAddPackage(
NAME pcie_model
GIT_REPOSITORY "https://github.com/joshwhieb/pcie-model.git"
Copy link
Author

@joshwhieb joshwhieb Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently have it as a fork as I need to PR and potentially put in checks to make sure that capabilities are DWORD aligned. Otherwise when the host tries to read them it doesn't read the correct values. For some reason X86 in their demos doesn't have problems with it but it is a challenge in the ARM simulation. I'll have to PR that against the primary repository when i get a chance.

https://github.com/Xilinx/pcie-model

Xilinx/pcie-model@020cd98

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a PR to update the dword alignment of capability pointers so that I can switch the git repository to the xilinx one.

Xilinx/pcie-model#2

GIT_TAG "master"
GIT_SHALLOW TRUE
)


set(LIBPCIE_DIR ${pcie_model_SOURCE_DIR}/libpcie)
set(LIBPCIE_C_SOURCES
${LIBPCIE_DIR}/src/pcie/cosim_common.c
${LIBPCIE_DIR}/src/pcie/cosim_socket.c
${LIBPCIE_DIR}/src/pcie/cosim_tlp.c
${LIBPCIE_DIR}/src/pcie/pcie.c
${LIBPCIE_DIR}/src/pcie/pseudocore.c
${LIBPCIE_DIR}/src/pcie/platform.c
${LIBPCIE_DIR}/src/pcie/pcie_cfgspc.c
${LIBPCIE_DIR}/src/pcie/pcie_cfgutil.c
${LIBPCIE_DIR}/src/pcie/pcie_msix.c
)

# C++ sources from the TLM modules
set(LIBPCIE_CXX_SOURCES
${pcie_model_SOURCE_DIR}/tlm-modules/pcie-controller.cc
${pcie_model_SOURCE_DIR}/tlm-modules/libpcie-callbacks.cc
)

# Create the static library
add_library(libpcie STATIC
${LIBPCIE_C_SOURCES}
${LIBPCIE_CXX_SOURCES}
)

# Set the output name to libpcie.a (without the extra 'lib' prefix)
set_target_properties(libpcie PROPERTIES OUTPUT_NAME pcie)

# Add compile definitions
target_compile_definitions(libpcie PRIVATE
__STDC_WANT_LIB_EXT2__=1
CONFIG_TLM=1
)

# Set include directories
target_include_directories(libpcie PUBLIC
${LIBPCIE_DIR}/src
${pcie_model_SOURCE_DIR}
${systemclanguage_SOURCE_DIR}/src
)

# Set compile options (matching the original Makefile)
target_compile_options(libpcie PRIVATE
-fPIC
$<$<CONFIG:Debug>:-g3 -O0>
$<$<CONFIG:Release>:-O2>
)

# Link against SystemC
target_link_libraries(libpcie PUBLIC
SystemC::systemc
)

CPMAddPackage(
NAME libslirp
GIT_REPOSITORY https://gitlab.freedesktop.org/slirp/libslirp.git
Expand Down Expand Up @@ -436,6 +498,8 @@ target_include_directories(
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/systemc-components/common/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}>
${LIBELF_INCLUDE_DIR}
${pcie_model_SOURCE_DIR}
${pcie_model_SOURCE_DIR}/libpcie/src
)

target_link_libraries(${PROJECT_NAME} PUBLIC
Expand All @@ -446,7 +510,8 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
${CROW_DEP}
zip
${PYBIND11_EMBED}
${CMAKE_DL_LIBS}
${CMAKE_DL_LIBS}
libpcie
)

install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/systemc-components" DESTINATION ${CMAKE_INSTALL_PREFIX})
Expand Down
2 changes: 2 additions & 0 deletions qemu-components/common/include/libqemu-cxx/libqemu-cxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ class MemoryRegionOps
struct MemTxAttrs {
bool secure = false;
bool debug = false;
/* Requester ID (for MSI for example) */
unsigned int requester_id:16;

MemTxAttrs() = default;
MemTxAttrs(const ::MemTxAttrs& qemu_attrs);
Expand Down
8 changes: 8 additions & 0 deletions qemu-components/common/include/ports/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "qemu-instance.h"
#include "tlm-extensions/qemu-cpu-hint.h"
#include "tlm-extensions/qemu-mr-hint.h"
#include "tlm-extensions/pcie_extension.h"
#include <tlm_sockets_buswidth.h>

class TlmTargetToQemuBridge : public tlm::tlm_fw_transport_if<>
Expand Down Expand Up @@ -93,6 +94,13 @@ class TlmTargetToQemuBridge : public tlm::tlm_fw_transport_if<>
return;
}

// Extract PCIe extension if present
gs::PcieExtension* pcie_ext = nullptr;
trans.get_extension(pcie_ext);
if (pcie_ext) {
attrs.requester_id = pcie_ext->requester_id;
}

current_cpu_save = push_current_cpu(trans);

switch (trans.get_command()) {
Expand Down
31 changes: 31 additions & 0 deletions qemu-components/common/include/tlm-extensions/pcie_extension.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef _GREENSOCS_PCIE_EXTENSION_H
#define _GREENSOCS_PCIE_EXTENSION_H

#include <tlm>

namespace gs {

class PcieExtension : public tlm::tlm_extension<PcieExtension>
{
public:
uint16_t requester_id;
uint8_t tag;

PcieExtension() : requester_id(0), tag(0) {}

virtual tlm_extension_base* clone() const override {
PcieExtension* ext = new PcieExtension();
ext->requester_id = this->requester_id;
ext->tag = this->tag;
return ext;
}

virtual void copy_from(tlm_extension_base const& ext) override {
requester_id = static_cast<PcieExtension const&>(ext).requester_id;
tag = static_cast<PcieExtension const&>(ext).tag;
}
};

} // namespace gs

#endif
1 change: 1 addition & 0 deletions qemu-components/common/src/libqemu-cxx/memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ AddressSpace::MemTxResult AddressSpace::write(uint64_t addr, const void* data, s
::MemTxResult qemu_res;

qemu_attrs.secure = attrs.secure;
qemu_attrs.requester_id = attrs.requester_id;

qemu_res = m_int->exports().address_space_write(m_as, addr, qemu_attrs, data, size);

Expand Down
7 changes: 4 additions & 3 deletions qemu-components/nvme/include/nvme.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QemuInstance*>(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<QemuInstance*>(o)), *(dynamic_cast<qemu_gpex*>(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")
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion qemu-components/nvme/src/nvme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

#include "nvme.h"

void module_register() { GSC_MODULE_REGISTER_C(nvme_disk, sc_core::sc_object*); }
void module_register() { GSC_MODULE_REGISTER_C(nvme_disk, sc_core::sc_object*, sc_core::sc_object*); }
1 change: 1 addition & 0 deletions systemc-components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_subdirectory(macs)
add_subdirectory(gs_memory)
add_subdirectory(memory_dumper)
add_subdirectory(pass)
add_subdirectory(pci)
if((NOT WITHOUT_PYTHON_BINDER) AND (NOT GS_ONLY))
add_subdirectory(python_binder)
endif()
Expand Down
2 changes: 2 additions & 0 deletions systemc-components/pci/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(gs_gpex)
add_subdirectory(nvme_ssd)
6 changes: 6 additions & 0 deletions systemc-components/pci/gs_gpex/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
gs_create_dymod(gs_gpex)

target_include_directories(
gs_gpex PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/qemu-components/common/include>
)
Loading