From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH proxmox-perl-rs v3 5/9] pve: add bindings for `pve-qemu-server-pci` crate
Date: Fri, 6 Nov 2026 14:25:48 +0100 [thread overview]
Message-ID: <20261106132604.2556840-6-d.csapak@proxmox.com> (raw)
In-Reply-To: <20261106132604.2556840-1-d.csapak@proxmox.com>
These provide bindings for using the rust pci code in PVE's qemu-server
perl code. This exposes 'PVE::RS::PCI::HardwareConfig' which provides an
object that can be used to query the pci addresses of qemu vms.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
pve-rs/Cargo.toml | 1 +
pve-rs/Makefile | 1 +
pve-rs/src/bindings/mod.rs | 3 +
pve-rs/src/bindings/pci/hardware_config.rs | 120 +++++++++++++++++++++
pve-rs/src/bindings/pci/mod.rs | 2 +
5 files changed, 127 insertions(+)
create mode 100644 pve-rs/src/bindings/pci/hardware_config.rs
create mode 100644 pve-rs/src/bindings/pci/mod.rs
diff --git a/pve-rs/Cargo.toml b/pve-rs/Cargo.toml
index ecedb1e..d728dcd 100644
--- a/pve-rs/Cargo.toml
+++ b/pve-rs/Cargo.toml
@@ -53,6 +53,7 @@ proxmox-tfa = { version = "6.0.3", features = ["api"] }
proxmox-time = "2"
proxmox-ve-config = { version = "0.11.0", features = [ "frr" ] }
proxmox-wireguard = { version = "0.1.2" }
+pve-qemu-server-pci = "0.1"
# [patch.crates-io]
# pbs-api-types = { path = "../../proxmox/pbs-api-types" }
diff --git a/pve-rs/Makefile b/pve-rs/Makefile
index 60f68c7..be0284d 100644
--- a/pve-rs/Makefile
+++ b/pve-rs/Makefile
@@ -31,6 +31,7 @@ PERLMOD_PACKAGES := \
PVE::RS::NVML \
PVE::RS::OCI \
PVE::RS::OpenId \
+ PVE::RS::PCI::HardwareConfig \
PVE::RS::ResourceScheduling::Static \
PVE::RS::ResourceScheduling::Dynamic \
PVE::RS::SDN::Fabrics \
diff --git a/pve-rs/src/bindings/mod.rs b/pve-rs/src/bindings/mod.rs
index 143a62b..9afcd4a 100644
--- a/pve-rs/src/bindings/mod.rs
+++ b/pve-rs/src/bindings/mod.rs
@@ -6,6 +6,9 @@ pub use nvml::pve_rs_nvml;
mod oci;
pub use oci::pve_rs_oci;
+mod pci;
+pub use pci::pve_rs_pci_hardware_config;
+
pub mod resource_scheduling;
mod tfa;
diff --git a/pve-rs/src/bindings/pci/hardware_config.rs b/pve-rs/src/bindings/pci/hardware_config.rs
new file mode 100644
index 0000000..d00aea4
--- /dev/null
+++ b/pve-rs/src/bindings/pci/hardware_config.rs
@@ -0,0 +1,120 @@
+#[perlmod::package(name = "PVE::RS::PCI::HardwareConfig", lib = "pve_rs")]
+pub mod pve_rs_pci_hardware_config {
+ //! The `PVE::RS::PCI::HardwareConfig` package.
+ //!
+ //! Provides bindings for the `HardwareConfig` struct of the `pve-qemu-server-pci` crate.
+
+ use std::ops::Deref;
+ use std::rc::Rc;
+
+ use anyhow::Error;
+
+ use perlmod::Value;
+
+ use pve_qemu_server_pci::{HardwareConfigParams, LayoutError, address};
+
+ perlmod::declare_magic!(Box<HardwareConfig>: &HardwareConfig as "PVE::RS::PCI::HardwareConfig");
+
+ /// Wrapper for [`pve_qemu_server_pci::HardwareConfig`].
+ pub struct HardwareConfig {
+ inner: Rc<pve_qemu_server_pci::HardwareConfig>,
+ }
+
+ impl Deref for HardwareConfig {
+ type Target = pve_qemu_server_pci::HardwareConfig;
+
+ fn deref(&self) -> &Self::Target {
+ &self.inner
+ }
+ }
+
+ #[export(raw_return)]
+ /// Class method: Create an instance of the `HardwareConfig` struct.
+ pub fn new(#[raw] class: Value, params: HardwareConfigParams) -> Result<Value, Error> {
+ let hw_config = pve_qemu_server_pci::HardwareConfig::new(params);
+ Ok(
+ perlmod::instantiate_magic!(&class, MAGIC => Box::new(HardwareConfig { inner: Rc::new(hw_config) })),
+ )
+ }
+
+ #[export]
+ /// Method: Returns the PCI or PCIe address of the chosen device on the given machine if the
+ /// device exists on the layout.
+ pub fn addr(
+ #[try_from_ref] this: &HardwareConfig,
+ id: &str,
+ ) -> Result<Option<String>, LayoutError> {
+ match address(this, id) {
+ Ok(addr) => Ok(Some(addr.to_qemu_addr())),
+ Err(LayoutError::NoAddressFound(_)) => Ok(None),
+ Err(other) => Err(other),
+ }
+ }
+
+ #[export]
+ /// Method: Get the `-device` arguments of all bridges, root ports and chipset devices forming
+ /// the buses of the guest, which have to come before any device on them.
+ pub fn pci_bus_devices(
+ #[try_from_ref] this: &HardwareConfig,
+ ) -> Result<Vec<String>, LayoutError> {
+ pve_qemu_server_pci::pci_bus_devices(this)
+ }
+
+ #[export]
+ /// Method: Whether the q35 chipset devices still have to be loaded from `pve-q35-4.0.cfg`.
+ pub fn uses_q35_config_file(#[try_from_ref] this: &HardwareConfig) -> bool {
+ this.uses_q35_config_file()
+ }
+
+ #[export]
+ /// Method: Get the architecture of the machine
+ pub fn arch(#[try_from_ref] this: &HardwareConfig) -> String {
+ this.arch().to_string()
+ }
+
+ #[export]
+ /// Method: Get the machines mainboard model
+ pub fn machine_type(#[try_from_ref] this: &HardwareConfig) -> String {
+ this.mainboard.to_string()
+ }
+
+ #[export]
+ /// Method: Get the layout of the given machine.
+ pub fn layout(#[try_from_ref] this: &HardwareConfig) -> String {
+ this.layout.to_string()
+ }
+
+ #[export]
+ /// Method: Checks if the given machine is at least the given version
+ /// Note: records the necessary PVE revision.
+ pub fn version_at_least(
+ #[try_from_ref] this: &HardwareConfig,
+ major: u16,
+ minor: u16,
+ pve: Option<u16>,
+ ) -> bool {
+ this.version_at_least(major, minor, pve)
+ }
+
+ #[export]
+ /// Method: Returns the windows version (if any)
+ pub fn windows_version(#[try_from_ref] this: &HardwareConfig) -> u8 {
+ this.windows_version()
+ }
+
+ #[export]
+ /// Method: Returns the bus the given device sits on, if it is a known device.
+ pub fn pci_bridge_for_device(
+ #[try_from_ref] this: &HardwareConfig,
+ device: &str,
+ ) -> Option<String> {
+ let bus = pve_qemu_server_pci::pci_bridge_for_device(this, device)?;
+ Some(bus.to_string())
+ }
+
+ #[export]
+ /// Method: Returns the required '+pveX' version of the machine.
+ pub fn required_pve_version(#[try_from_ref] this: &HardwareConfig) -> u16 {
+ this.required_pve_version()
+ }
+}
diff --git a/pve-rs/src/bindings/pci/mod.rs b/pve-rs/src/bindings/pci/mod.rs
new file mode 100644
index 0000000..d1b00dd
--- /dev/null
+++ b/pve-rs/src/bindings/pci/mod.rs
@@ -0,0 +1,2 @@
+mod hardware_config;
+pub use hardware_config::pve_rs_pci_hardware_config;
--
2.47.3
next prev parent reply other threads:[~2026-11-06 13:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 13:25 [RFC proxmox-perl-rs/qemu-server/qemu-server-rs v3 0/9] pci-handling rewrite (part 1/2/3) Dominik Csapak
2026-11-06 13:25 ` [PATCH pve-qemu-server-rs v3 1/9] add pve-qemu-server-pci crate for guest PCI address generation Dominik Csapak
2026-11-06 13:25 ` [PATCH pve-qemu-server-rs v3 2/9] pci: legacy: generate pci bridges Dominik Csapak
2026-11-06 13:25 ` [PATCH pve-qemu-server-rs v3 3/9] pci: legacy: generate q35 chipset devices and hostpcie root ports Dominik Csapak
2026-11-06 13:25 ` [PATCH pve-qemu-server-rs v3 4/9] pci: layout: add grouped PCI and PCIe layouts Dominik Csapak
2026-11-06 13:25 ` Dominik Csapak [this message]
2026-11-06 13:25 ` [PATCH qemu-server v3 6/9] pci: use PVE::RS::PCI bindings for addresses and bus devices Dominik Csapak
2026-11-06 13:25 ` [PATCH qemu-server v3 7/9] tree-wide: use HardwareConfig for the machine version checks Dominik Csapak
2026-11-06 13:25 ` [PATCH qemu-server v3 8/9] cfg2cmd: q35: generate chipset devices with machine version 11.1+pve1 Dominik Csapak
2026-11-06 13:25 ` [PATCH qemu-server v3 9/9] machine: add 'pci-layout' option Dominik Csapak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261106132604.2556840-6-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.