yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-spapr-Adjust-firmware-path-of-PCI-devices.patch

6e7d01
From dfdf950e893c23e77c9dc0be18fca66ad195d260 Mon Sep 17 00:00:00 2001
6e7d01
From: Greg Kurz <gkurz@redhat.com>
6e7d01
Date: Wed, 10 Feb 2021 15:56:45 +0000
6e7d01
Subject: [PATCH 2/2] spapr: Adjust firmware path of PCI devices
6e7d01
MIME-Version: 1.0
6e7d01
Content-Type: text/plain; charset=UTF-8
6e7d01
Content-Transfer-Encoding: 8bit
6e7d01
6e7d01
RH-Author: Greg Kurz <gkurz@redhat.com>
6e7d01
Message-id: <20210210165645.470195-2-gkurz@redhat.com>
6e7d01
Patchwork-id: 101038
6e7d01
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH 1/1] spapr: Adjust firmware path of PCI devices
6e7d01
Bugzilla: 1912891
6e7d01
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
6e7d01
RH-Acked-by: David Gibson <dgibson@redhat.com>
6e7d01
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
6e7d01
6e7d01
From: Greg Kurz <groug@kaod.org>
6e7d01
6e7d01
It is currently not possible to perform a strict boot from USB storage:
6e7d01
6e7d01
$ qemu-system-ppc64 -accel kvm -nodefaults -nographic -serial stdio \
6e7d01
	-boot strict=on \
6e7d01
	-device qemu-xhci \
6e7d01
	-device usb-storage,drive=disk,bootindex=0 \
6e7d01
	-blockdev driver=file,node-name=disk,filename=fedora-ppc64le.qcow2
6e7d01
6e7d01
SLOF **********************************************************************
6e7d01
QEMU Starting
6e7d01
 Build Date = Jul 17 2020 11:15:24
6e7d01
 FW Version = git-e18ddad8516ff2cf
6e7d01
 Press "s" to enter Open Firmware.
6e7d01
6e7d01
Populating /vdevice methods
6e7d01
Populating /vdevice/vty@71000000
6e7d01
Populating /vdevice/nvram@71000001
6e7d01
Populating /pci@800000020000000
6e7d01
                     00 0000 (D) : 1b36 000d    serial bus [ usb-xhci ]
6e7d01
No NVRAM common partition, re-initializing...
6e7d01
Scanning USB
6e7d01
  XHCI: Initializing
6e7d01
    USB Storage
6e7d01
       SCSI: Looking for devices
6e7d01
          101000000000000 DISK     : "QEMU     QEMU HARDDISK    2.5+"
6e7d01
Using default console: /vdevice/vty@71000000
6e7d01
6e7d01
  Welcome to Open Firmware
6e7d01
6e7d01
  Copyright (c) 2004, 2017 IBM Corporation All rights reserved.
6e7d01
  This program and the accompanying materials are made available
6e7d01
  under the terms of the BSD License available at
6e7d01
  http://www.opensource.org/licenses/bsd-license.php
6e7d01
6e7d01
Trying to load:  from: /pci@800000020000000/usb@0/storage@1/disk@101000000000000 ...
6e7d01
E3405: No such device
6e7d01
6e7d01
E3407: Load failed
6e7d01
6e7d01
  Type 'boot' and press return to continue booting the system.
6e7d01
  Type 'reset-all' and press return to reboot the system.
6e7d01
6e7d01
Ready!
6e7d01
0 >
6e7d01
6e7d01
The device tree handed over by QEMU to SLOF indeed contains:
6e7d01
6e7d01
qemu,boot-list =
6e7d01
	"/pci@800000020000000/usb@0/storage@1/disk@101000000000000 HALT";
6e7d01
6e7d01
but the device node is named usb-xhci@0, not usb@0.
6e7d01
6e7d01
This happens because the firmware names of PCI devices returned
6e7d01
by get_boot_devices_list() come from pcibus_get_fw_dev_path(),
6e7d01
while the sPAPR PHB code uses a different naming scheme for
6e7d01
device nodes. This inconsistency has always been there but it was
6e7d01
hidden for a long time because SLOF used to rename USB device
6e7d01
nodes, until this commit, merged in QEMU 4.2.0 :
6e7d01
6e7d01
commit 85164ad4ed9960cac842fa4cc067c6b6699b0994
6e7d01
Author: Alexey Kardashevskiy <aik@ozlabs.ru>
6e7d01
Date:   Wed Sep 11 16:24:32 2019 +1000
6e7d01
6e7d01
    pseries: Update SLOF firmware image
6e7d01
6e7d01
    This fixes USB host bus adapter name in the device tree to match QEMU's
6e7d01
    one.
6e7d01
6e7d01
    Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
6e7d01
    Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6e7d01
6e7d01
Fortunately, sPAPR implements the firmware path provider interface.
6e7d01
This provides a way to override the default firmware paths.
6e7d01
6e7d01
Just factor out the sPAPR PHB naming logic from spapr_dt_pci_device()
6e7d01
to a helper, and use it in the sPAPR firmware path provider hook.
6e7d01
6e7d01
Fixes: 85164ad4ed99 ("pseries: Update SLOF firmware image")
6e7d01
Signed-off-by: Greg Kurz <groug@kaod.org>
6e7d01
Message-Id: <20210122170157.246374-1-groug@kaod.org>
6e7d01
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
6e7d01
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6e7d01
(cherry picked from commit 040bdafce12f750816d879442014df2999a995c4)
6e7d01
Signed-off-by: Greg Kurz <gkurz@redhat.com>
6e7d01
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
6e7d01
---
6e7d01
 hw/ppc/spapr.c              |  5 +++++
6e7d01
 hw/ppc/spapr_pci.c          | 33 ++++++++++++++++++---------------
6e7d01
 include/hw/pci-host/spapr.h |  2 ++
6e7d01
 3 files changed, 25 insertions(+), 15 deletions(-)
6e7d01
6e7d01
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
6e7d01
index 00b1ef075e..bee2299199 100644
6e7d01
--- a/hw/ppc/spapr.c
6e7d01
+++ b/hw/ppc/spapr.c
6e7d01
@@ -3013,6 +3013,7 @@ static char *spapr_get_fw_dev_path(FWPathProvider *p, BusState *bus,
6e7d01
     SCSIDevice *d = CAST(SCSIDevice,  dev, TYPE_SCSI_DEVICE);
6e7d01
     SpaprPhbState *phb = CAST(SpaprPhbState, dev, TYPE_SPAPR_PCI_HOST_BRIDGE);
6e7d01
     VHostSCSICommon *vsc = CAST(VHostSCSICommon, dev, TYPE_VHOST_SCSI_COMMON);
6e7d01
+    PCIDevice *pcidev = CAST(PCIDevice, dev, TYPE_PCI_DEVICE);
6e7d01
 
6e7d01
     if (d) {
6e7d01
         void *spapr = CAST(void, bus->parent, "spapr-vscsi");
6e7d01
@@ -3086,6 +3087,10 @@ static char *spapr_get_fw_dev_path(FWPathProvider *p, BusState *bus,
6e7d01
         return g_strdup_printf("pci@%x", PCI_SLOT(pcidev->devfn));
6e7d01
     }
6e7d01
 
6e7d01
+    if (pcidev) {
6e7d01
+        return spapr_pci_fw_dev_name(pcidev);
6e7d01
+    }
6e7d01
+
6e7d01
     return NULL;
6e7d01
 }
6e7d01
 
6e7d01
diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
6e7d01
index f6fbcf99ed..befa570aa8 100644
6e7d01
--- a/hw/ppc/spapr_pci.c
6e7d01
+++ b/hw/ppc/spapr_pci.c
6e7d01
@@ -1348,15 +1348,29 @@ static int spapr_dt_pci_bus(SpaprPhbState *sphb, PCIBus *bus,
6e7d01
     return offset;
6e7d01
 }
6e7d01
 
6e7d01
+char *spapr_pci_fw_dev_name(PCIDevice *dev)
6e7d01
+{
6e7d01
+    const gchar *basename;
6e7d01
+    int slot = PCI_SLOT(dev->devfn);
6e7d01
+    int func = PCI_FUNC(dev->devfn);
6e7d01
+    uint32_t ccode = pci_default_read_config(dev, PCI_CLASS_PROG, 3);
6e7d01
+
6e7d01
+    basename = dt_name_from_class((ccode >> 16) & 0xff, (ccode >> 8) & 0xff,
6e7d01
+                                  ccode & 0xff);
6e7d01
+
6e7d01
+    if (func != 0) {
6e7d01
+        return g_strdup_printf("%s@%x,%x", basename, slot, func);
6e7d01
+    } else {
6e7d01
+        return g_strdup_printf("%s@%x", basename, slot);
6e7d01
+    }
6e7d01
+}
6e7d01
+
6e7d01
 /* create OF node for pci device and required OF DT properties */
6e7d01
 static int spapr_dt_pci_device(SpaprPhbState *sphb, PCIDevice *dev,
6e7d01
                                void *fdt, int parent_offset)
6e7d01
 {
6e7d01
     int offset;
6e7d01
-    const gchar *basename;
6e7d01
-    gchar *nodename;
6e7d01
-    int slot = PCI_SLOT(dev->devfn);
6e7d01
-    int func = PCI_FUNC(dev->devfn);
6e7d01
+    g_autofree gchar *nodename = spapr_pci_fw_dev_name(dev);
6e7d01
     PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
6e7d01
     ResourceProps rp;
6e7d01
     SpaprDrc *drc = drc_from_dev(sphb, dev);
6e7d01
@@ -1373,19 +1387,8 @@ static int spapr_dt_pci_device(SpaprPhbState *sphb, PCIDevice *dev,
6e7d01
     uint32_t pci_status = pci_default_read_config(dev, PCI_STATUS, 2);
6e7d01
     gchar *loc_code;
6e7d01
 
6e7d01
-    basename = dt_name_from_class((ccode >> 16) & 0xff, (ccode >> 8) & 0xff,
6e7d01
-                                  ccode & 0xff);
6e7d01
-
6e7d01
-    if (func != 0) {
6e7d01
-        nodename = g_strdup_printf("%s@%x,%x", basename, slot, func);
6e7d01
-    } else {
6e7d01
-        nodename = g_strdup_printf("%s@%x", basename, slot);
6e7d01
-    }
6e7d01
-
6e7d01
     _FDT(offset = fdt_add_subnode(fdt, parent_offset, nodename));
6e7d01
 
6e7d01
-    g_free(nodename);
6e7d01
-
6e7d01
     /* in accordance with PAPR+ v2.7 13.6.3, Table 181 */
6e7d01
     _FDT(fdt_setprop_cell(fdt, offset, "vendor-id", vendor_id));
6e7d01
     _FDT(fdt_setprop_cell(fdt, offset, "device-id", device_id));
6e7d01
diff --git a/include/hw/pci-host/spapr.h b/include/hw/pci-host/spapr.h
6e7d01
index 8877ff51fb..9522db9047 100644
6e7d01
--- a/include/hw/pci-host/spapr.h
6e7d01
+++ b/include/hw/pci-host/spapr.h
6e7d01
@@ -212,4 +212,6 @@ static inline unsigned spapr_phb_windows_supported(SpaprPhbState *sphb)
6e7d01
     return sphb->ddw_enabled ? SPAPR_PCI_DMA_MAX_WINDOWS : 1;
6e7d01
 }
6e7d01
 
6e7d01
+char *spapr_pci_fw_dev_name(PCIDevice *dev);
6e7d01
+
6e7d01
 #endif /* PCI_HOST_SPAPR_H */
6e7d01
-- 
6e7d01
2.27.0
6e7d01