[PATCH qemu-server 04/10] pci: add get_pci_addr

Alexandre Derumier alexandre.derumier at groupe-cyllene.com
Wed Jul 2 16:48:54 CEST 2025


return a hash with pci bus && pci address

Signed-off-by: Alexandre Derumier <alexandre.derumier at groupe-cyllene.com>
---
 src/PVE/QemuServer/PCI.pm | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/PVE/QemuServer/PCI.pm b/src/PVE/QemuServer/PCI.pm
index ddf2f028..7952dc61 100644
--- a/src/PVE/QemuServer/PCI.pm
+++ b/src/PVE/QemuServer/PCI.pm
@@ -16,6 +16,7 @@ use PVE::QemuServer::Machine;
 use base 'Exporter';
 
 our @EXPORT_OK = qw(
+    get_pci_addr
     print_pci_addr
     print_pcie_addr
     print_pcie_root_port
@@ -288,27 +289,38 @@ my $get_addr_mapping_from_id = sub {
     return { bus => $d->{bus}, addr => sprintf("0x%x", $d->{addr}) };
 };
 
-sub print_pci_addr {
+sub get_pci_addr {
     my ($id, $bridges, $arch) = @_;
 
-    my $res = '';
+    my $res = {};
 
     # using same bus slots on all HW, so we need to check special cases here:
     my $busname = 'pci';
     if ($arch eq 'aarch64') {
-        die "aarch64 cannot use IDE devices\n" if $id =~ /^ide/;
-        $busname = 'pcie';
+	die "aarch64 cannot use IDE devices\n" if $id =~ /^ide/;
+	$busname = 'pcie';
     }
 
     my $map = get_pci_addr_map();
     if (my $d = $get_addr_mapping_from_id->($map, $id)) {
-        $res = ",bus=$busname.$d->{bus},addr=$d->{addr}";
+        $res = { bus => "$busname.$d->{bus}", addr => $d->{addr} };
         $bridges->{ $d->{bus} } = 1 if $bridges;
     }
 
     return $res;
 }
 
+
+sub print_pci_addr {
+    my ($id, $bridges, $arch) = @_;
+
+    my $pci = get_pci_addr($id, $bridges, $arch);
+    my $res = "";
+    $res.=",bus=$pci->{bus}" if $pci->{bus};
+    $res.=",addr=$pci->{addr}" if $pci->{addr};
+    return $res;
+}
+
 my $pcie_addr_map;
 
 sub get_pcie_addr_map {
-- 
2.39.5




More information about the pve-devel mailing list