qualcomm/qbox
Loading...
Searching...
No Matches
qemu_rciep_pci.h
1/*
2 * This file is part of libqbox
3 * Copyright (c) 2026 Qualcomm Innovation Center, Inc. All Rights Reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 * qemu_rciep_pci: QBox wrapper for the QEMU "rciep" PCIe device.
8 *
9 * Derives from qemu_gpex::Device, registers with the gpex bus, and
10 * forwards CCI parameters to the underlying QEMU properties:
11 * devfn PCI devfn (dev<<3 | fn) → "addr" property
12 * vendor_id uint16 → "vendor-id"
13 * device_id uint16 → "device-id"
14 * class_id uint16 → "class-id"
15 * revision uint8 → "revision"
16 * num_vfs uint16 → "num-vfs"
17 * num_msi_vectors uint16 → "num-msi-vectors"
18 * bar0_size uint64 → "bar0-size"
19 * commblock_base uint64 → "commblock-base" (BAR0 MMIO forward target)
20 * private_base uint64 → "private-base" (reserved — not consumed yet)
21 * pf_shadow_base uint64 → "pf-shadow-base" (reserved — not consumed yet)
22 */
23
24#ifndef _LIBQBOX_COMPONENTS_PCI_RCIEP_H
25#define _LIBQBOX_COMPONENTS_PCI_RCIEP_H
26
27#include <sstream>
28#include <iomanip>
29
30#include <cci_configuration>
31
32#include <libgssync.h>
33#include <qemu-instance.h>
34#include <module_factory_registery.h>
35
36#include <qemu_gpex.h>
37
38class qemu_rciep_pci : public qemu_gpex::Device
39{
40public:
41 cci::cci_param<uint32_t> p_devfn;
42 cci::cci_param<uint32_t> p_vendor_id;
43 cci::cci_param<uint32_t> p_device_id;
44 cci::cci_param<uint32_t> p_class_id;
45 cci::cci_param<uint32_t> p_revision;
46 cci::cci_param<uint32_t> p_num_vfs;
47 cci::cci_param<uint32_t> p_num_msi_vectors;
48 cci::cci_param<uint64_t> p_bar0_size;
49 cci::cci_param<uint64_t> p_private_base;
50 cci::cci_param<uint64_t> p_pf_shadow_base;
51 cci::cci_param<uint64_t> p_commblock_base;
52
53 qemu_rciep_pci(const sc_core::sc_module_name& name, sc_core::sc_object* o, sc_core::sc_object* t)
54 : qemu_rciep_pci(name, *(dynamic_cast<QemuInstance*>(o)), (dynamic_cast<qemu_gpex*>(t)))
55 {
56 }
57
58 qemu_rciep_pci(const sc_core::sc_module_name& name, QemuInstance& inst, qemu_gpex* gpex)
59 : qemu_gpex::Device(name, inst, "rciep")
60 , p_devfn("devfn", 0, "PCI devfn (dev<<3 | fn)")
61 , p_vendor_id("vendor_id", 0x17CB, "PCI Vendor ID")
62 , p_device_id("device_id", 0x0D0A, "PCI Device ID")
63 , p_class_id("class_id", 0x1200, "PCI class code")
64 , p_revision("revision", 0x00, "PCI revision ID")
65 , p_num_vfs("num_vfs", 8, "Number of SR-IOV VFs")
66 , p_num_msi_vectors("num_msi_vectors", 4,
67 "MSI vectors advertised per PF (keep small vs platform IRQ pool, e.g. GICv2m 64 SPIs)")
68 , p_bar0_size("bar0_size", 0x800000, "PF BAR0 MMIO window size in bytes (8 MiB doorbell/comm-block aperture)")
69 , p_private_base("private_base", 0, "Reserved — not consumed yet (future CPU-facing PRIVATE window)")
70 , p_pf_shadow_base("pf_shadow_base", 0, "Reserved — not consumed yet (future config-monitor mirror)")
71 , p_commblock_base("commblock_base", 0,
72 "System-bus base of the external comm-block component (BAR0 forward target)")
73 {
74 gpex->add_device(*this);
75 }
76
77 void before_end_of_elaboration() override
78 {
79 qemu_gpex::Device::before_end_of_elaboration();
80
81 /* Convert devfn to QEMU "addr" property string: "DD.F" */
82 uint32_t devfn = p_devfn.get_value();
83 uint32_t dev = (devfn >> 3) & 0x1f;
84 uint32_t fn = devfn & 0x7;
85 std::ostringstream addr_str;
86 addr_str << std::hex << std::setfill('0') << std::setw(2) << dev << "." << fn;
87 m_dev.set_prop_str("addr", addr_str.str().c_str());
88
89 m_dev.set_prop_uint("vendor-id", p_vendor_id.get_value());
90 m_dev.set_prop_uint("device-id", p_device_id.get_value());
91 m_dev.set_prop_uint("class-id", p_class_id.get_value());
92 m_dev.set_prop_uint("revision", p_revision.get_value());
93 m_dev.set_prop_uint("num-vfs", p_num_vfs.get_value());
94 m_dev.set_prop_uint("num-msi-vectors", p_num_msi_vectors.get_value());
95 m_dev.set_prop_uint("bar0-size", p_bar0_size.get_value());
96 m_dev.set_prop_uint("private-base", p_private_base.get_value());
97 m_dev.set_prop_uint("pf-shadow-base", p_pf_shadow_base.get_value());
98 m_dev.set_prop_uint("commblock-base", p_commblock_base.get_value());
99 }
100};
101
102extern "C" void module_register();
103
104#endif /* _LIBQBOX_COMPONENTS_PCI_RCIEP_H */
This class encapsulates a libqemu-cxx qemu::LibQemu instance. It handles QEMU parameters and instance...
Definition qemu-instance.h:89
Definition qemu_gpex.h:35