@samitouri / QOSamiQemu / commits / 395116781d

s390x: Build IPLB for virtio-pci devices

Search for a corresponding S390PCIBusDevice and build an IPLB if a device has been indexed for boot but does not identify as a CCW device, PCI devices are not yet included in boot probing (they must have a boot index). Reviewed-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Eric Farman <farman@linux.ibm.com> Signed-off-by: Jared Rossi <jrossi@linux.ibm.com> Message-ID: <20260309003601.242634-14-jrossi@linux.ibm.com> [thuth: Fix endianness issue when running on a little endian host] Signed-off-by: Thomas Huth <thuth@redhat.com>

Jared Rossi committed Mar 8, 2026 at 20:35 UTC 395116781df5daa25bf053b7ef2a3f310036b444
4 files changed +57 -7
hw/s390x/ipl.c
+51 -5
@@ -28,6 +28,8 @@
28 #include "hw/s390x/ebcdic.h"
29 #include "hw/scsi/scsi.h"
30 #include "hw/virtio/virtio-net.h"
31 +#include "hw/virtio/virtio-pci.h"
32 +#include "hw/s390x/s390-pci-bus.h"
33 #include "exec/cpu-common.h"
34 #include "ipl.h"
35 #include "qemu/error-report.h"
@@ -340,7 +342,8 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl)
342 ipl->qipl.boot_menu_timeout = cpu_to_be32(splash_time);
343 }
344
343 -#define CCW_DEVTYPE_NONE 0x00
345 +#define S390_DEVTYPE_NONE 0x00
346 +
347 #define CCW_DEVTYPE_VIRTIO 0x01
348 #define CCW_DEVTYPE_VIRTIO_NET 0x02
349 #define CCW_DEVTYPE_SCSI 0x03
@@ -349,7 +352,7 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl)
352 static CcwDevice *s390_get_ccw_device(DeviceState *dev_st, int *devtype)
353 {
354 CcwDevice *ccw_dev = NULL;
352 - int tmp_dt = CCW_DEVTYPE_NONE;
355 + int tmp_dt = S390_DEVTYPE_NONE;
356
357 if (dev_st) {
358 VirtIONet *virtio_net_dev = (VirtIONet *)
@@ -396,6 +399,31 @@ static CcwDevice *s390_get_ccw_device(DeviceState *dev_st, int *devtype)
399 return ccw_dev;
400 }
401
402 +#define PCI_DEVTYPE_VIRTIO 0x05
403 +
404 +static S390PCIBusDevice *s390_get_pci_device(DeviceState *dev_st, int *devtype)
405 +{
406 + S390PCIBusDevice *pbdev = NULL;
407 + int tmp_dt = S390_DEVTYPE_NONE;
408 +
409 + if (dev_st) {
410 + PCIDevice *pci_dev = (PCIDevice *)
411 + object_dynamic_cast(OBJECT(qdev_get_parent_bus(dev_st)->parent),
412 + TYPE_VIRTIO_PCI);
413 + if (pci_dev) {
414 + pbdev = s390_pci_find_dev_by_pci(s390_get_phb(), pci_dev);
415 + if (pbdev) {
416 + tmp_dt = PCI_DEVTYPE_VIRTIO;
417 + }
418 + }
419 + }
420 + if (devtype) {
421 + *devtype = tmp_dt;
422 + }
423 +
424 + return pbdev;
425 +}
426 +
427 static uint64_t s390_ipl_map_iplb_chain(IplParameterBlock *iplb_chain)
428 {
429 S390IPLState *ipl = get_ipl_device();
@@ -428,14 +456,12 @@ void s390_ipl_convert_loadparm(char *ascii_lp, uint8_t *ebcdic_lp)
456 static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb)
457 {
458 CcwDevice *ccw_dev = NULL;
459 + S390PCIBusDevice *pbdev = NULL;
460 SCSIDevice *sd;
461 int devtype;
462 uint8_t *lp;
463 g_autofree void *scsi_lp = NULL;
464
436 - /*
437 - * Currently allow IPL only from CCW devices.
438 - */
465 ccw_dev = s390_get_ccw_device(dev_st, &devtype);
466 if (ccw_dev) {
467 lp = ccw_dev->loadparm;
@@ -485,6 +511,26 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb)
511 return true;
512 }
513
514 + pbdev = s390_get_pci_device(dev_st, &devtype);
515 + if (pbdev) {
516 + switch (devtype) {
517 + case PCI_DEVTYPE_VIRTIO:
518 + iplb->len = cpu_to_be32(S390_IPLB_MIN_PCI_LEN);
519 + iplb->pbt = S390_IPL_TYPE_PCI;
520 + iplb->pci.fid = cpu_to_be32(pbdev->fid);
521 + break;
522 + default:
523 + return false;
524 + }
525 +
526 + /* Per-device loadparm not yet supported for non-ccw IPL */
527 + lp = S390_CCW_MACHINE(qdev_get_machine())->loadparm;
528 + s390_ipl_convert_loadparm((char *)lp, iplb->loadparm);
529 + iplb->flags |= DIAG308_FLAGS_LP_VALID;
530 +
531 + return true;
532 + }
533 +
534 return false;
535 }
536
hw/s390x/ipl.h
+3
@@ -107,6 +107,7 @@ QEMU_BUILD_BUG_MSG(offsetof(S390IPLState, iplb) & 3, "alignment of iplb wrong");
107 #define S390_IPLB_MIN_PV_LEN 148
108 #define S390_IPLB_MIN_CCW_LEN 200
109 #define S390_IPLB_MIN_FCP_LEN 384
110 +#define S390_IPLB_MIN_PCI_LEN 376
111 #define S390_IPLB_MIN_QEMU_SCSI_LEN 200
112
113 static inline bool iplb_valid_len(IplParameterBlock *iplb)
@@ -179,6 +180,8 @@ static inline bool iplb_valid(IplParameterBlock *iplb)
180 return len >= S390_IPLB_MIN_FCP_LEN;
181 case S390_IPL_TYPE_CCW:
182 return len >= S390_IPLB_MIN_CCW_LEN;
183 + case S390_IPL_TYPE_PCI:
184 + return len >= S390_IPLB_MIN_PCI_LEN;
185 case S390_IPL_TYPE_QEMU_SCSI:
186 default:
187 return false;
hw/s390x/s390-pci-bus.c
+1 -2
@@ -250,8 +250,7 @@ S390PCIBusDevice *s390_pci_find_dev_by_target(S390pciState *s,
250 return NULL;
251 }
252
253 -static S390PCIBusDevice *s390_pci_find_dev_by_pci(S390pciState *s,
254 - PCIDevice *pci_dev)
253 +S390PCIBusDevice *s390_pci_find_dev_by_pci(S390pciState *s, PCIDevice *pci_dev)
254 {
255 S390PCIBusDevice *pbdev;
256
include/hw/s390x/s390-pci-bus.h
+2
@@ -402,6 +402,8 @@ S390PCIBusDevice *s390_pci_find_dev_by_fh(S390pciState *s, uint32_t fh);
402 S390PCIBusDevice *s390_pci_find_dev_by_fid(S390pciState *s, uint32_t fid);
403 S390PCIBusDevice *s390_pci_find_dev_by_target(S390pciState *s,
404 const char *target);
405 +S390PCIBusDevice *s390_pci_find_dev_by_pci(S390pciState *s,
406 + PCIDevice *pci_dev);
407 S390PCIBusDevice *s390_pci_find_next_avail_dev(S390pciState *s,
408 S390PCIBusDevice *pbdev);
409 void s390_pci_ism_reset(void);