s390x: Add support for virtio-blk-pci IPL device
cover s390x: Add support for virtio-blk-pci IPL device
From: Jared Rossi <[email protected]>
This patch series introduces an IPLB subtype to support PCI devices, which may be built if a device has been assigned a boot index and is identified as a PCI device with a corresponding s390 PCI Bus device.
A simple test to check basic functionality is added to the cdrom-tests in qtest.
Boot support is only added for virtio-blk-pci at this time and has the following limitations:
1) A PCI device must be assigned a boot index to be eligible for boot
2) A PCI boot device cannot be assigned a per-device loadparm
Point 1 relates to boot device probing, which occurs if no device has been assigned a boot index. Currently, there is a basic probing routine to scan through the CCW devices for any devices that *might* boot, and to then try booting them; however, the routine provides limited coverage even for CCW devices (some CCW devices, such as net devices, are not probed). The PCI bus could be added to this routine in a similarly limited form, or it may be more desirable to do a comprehensive enhancement of the probing routine as a separate patch series.
Point 2 relates to the QOM device properties. The loadparm is specific to s390x and has generally only been relevant for CCW devices, of which bootable types have a corresponding QOM property for the loadparm. There is some precedence for making the s390x loadparm property assignable to non-CCW devices (see QEMU commit 429442e), but it may not be an acceptable solution for generic PCI devices, in which case an alternative solution would be needed.
Further consideration is needed on how to best handle to above points and feedback is encouraged. Additionally, it is worth noting that all of the s390 BIOS code lives in the "s390-ccw" directory. Should the entire directory be renamed, given that non-ccw devices will be supported?
Referenced commit ID 429442e: hw: Add "loadparm" property to scsi disk devices
for booting on s390x (https://gitlab.com/qemu-project/qemu/-/commit/429442e52d94f890fa194a151e8cd649b04e9e63)
Jared Rossi (7):
pc-bios/s390-ccw: Fix Misattributed Function Prototypes pc-bios/s390-ccw: Split virtio-ccw and generic virtio pc-bios/s390-ccw: Introduce CLP Architecture pc-bios/s390-ccw: Introduce PCI device IPL format pc-bios/s390-ccw: Add support for virtio-blk-pci IPL
s390x: Build IPLB for virtio-pci devices tests/qtest: Add s390x PCI boot test to cdrom-test.c
hw/s390x/ipl.h | 8 +- include/hw/s390x/ipl/qipl.h | 15 ++ include/hw/s390x/s390-pci-bus.h | 2 + pc-bios/s390-ccw/clp.h | 24 +++ pc-bios/s390-ccw/iplb.h | 4 - pc-bios/s390-ccw/pci.h | 77 +++++++ pc-bios/s390-ccw/s390-ccw.h | 4 - pc-bios/s390-ccw/virtio-ccw.h | 25 +++ pc-bios/s390-ccw/virtio-pci.h | 73 +++++++ pc-bios/s390-ccw/virtio-scsi.h | 2 +- pc-bios/s390-ccw/virtio.h | 17 +- hw/s390x/ipl.c | 56 ++++- hw/s390x/s390-pci-bus.c | 2 +- pc-bios/s390-ccw/bootmap.c | 2 +- pc-bios/s390-ccw/clp.c | 106 +++++++++ pc-bios/s390-ccw/main.c | 72 ++++++- pc-bios/s390-ccw/pci.c | 191 +++++++++++++++++ pc-bios/s390-ccw/virtio-blkdev.c | 62 ++++-- pc-bios/s390-ccw/virtio-ccw.c | 240 +++++++++++++++++++++ pc-bios/s390-ccw/virtio-net.c | 5 +- pc-bios/s390-ccw/virtio-pci.c | 357 +++++++++++++++++++++++++++++++ pc-bios/s390-ccw/virtio-scsi.c | 7 +- pc-bios/s390-ccw/virtio.c | 214 ++++-------------- tests/qtest/cdrom-test.c | 7 + pc-bios/s390-ccw/Makefile | 3 +- 25 files changed, 1342 insertions(+), 233 deletions(-) create mode 100644 pc-bios/s390-ccw/clp.h create mode 100644 pc-bios/s390-ccw/pci.h create mode 100644 pc-bios/s390-ccw/virtio-ccw.h create mode 100644 pc-bios/s390-ccw/virtio-pci.h create mode 100644 pc-bios/s390-ccw/clp.c create mode 100644 pc-bios/s390-ccw/pci.c create mode 100644 pc-bios/s390-ccw/virtio-ccw.c create mode 100644 pc-bios/s390-ccw/virtio-pci.c
Signature · 1 line
2.49.0
PATCH 1/7 pc-bios/s390-ccw: Fix Misattributed Function Prototypes
From: Jared Rossi <[email protected]>
The virtio-blkdev functions are incorrectly listed in s390-ccw.h as belonging to virtio.c. Additionally, virtio_load_direct() has an unused subchan_id argument.
Remove the unused argument and move the prototypes to virtio.h so that they are independent from the CCW bus.
--- pc-bios/s390-ccw/s390-ccw.h | 4 ---- pc-bios/s390-ccw/virtio.h | 7 +++++++ pc-bios/s390-ccw/bootmap.c | 2 +- pc-bios/s390-ccw/virtio-blkdev.c | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-)
pc-bios/s390-ccw/s390-ccw.h +0 -4
@@ -67,11 +67,7 @@ void sclp_get_loadparm_ascii(char *loadparm);int sclp_read (char *str,size_t count);/* virtio.c */ -unsigned long virtio_load_direct (unsigned long rec_list1,unsigned long rec_list2, -unsigned long subchan_id,void *load_addr);bool virtio_is_supported (SubChannelId schid); -int virtio_blk_setup_device (SubChannelId schid); -int virtio_read (unsigned long sector,void *load_addr);/* bootmap.c */ void zipl_load (void );
pc-bios/s390-ccw/virtio.h +7 -0
@@ -277,7 +277,14 @@ int virtio_run(VDev *vdev, int vqid, VirtioCmd *cmd);int virtio_reset (VDev *vdev);int virtio_setup_ccw (VDev *vdev); +/* virtio-net.c */ int virtio_net_init (void *mac_addr);void virtio_net_deinit (void ); +/* virtio-blkdev.c */ +int virtio_blk_setup_device (SubChannelId schid); +int virtio_read (unsigned long sector,void *load_addr); +unsigned long virtio_load_direct (unsigned long rec_list1,unsigned long rec_list2, +void *load_addr); +#endif /* VIRTIO_H */
pc-bios/s390-ccw/bootmap.c +1 -1
@@ -662,7 +662,7 @@ static int zipl_load_segment(ComponentEntry *entry)*/ break ; } - address =virtio_load_direct (cur_desc[0 ], cur_desc[1 ],0 , + address =virtio_load_direct (cur_desc[0 ], cur_desc[1 ], (void *)address);if (!address) {puts ("zIPL load segment failed" );
pc-bios/s390-ccw/virtio-blkdev.c +1 -1
@@ -64,7 +64,7 @@ int virtio_read_many(unsigned long sector, void *load_addr, int sec_num) }unsigned long virtio_load_direct (unsigned long rec_list1,unsigned long rec_list2, -unsigned long subchan_id,void *load_addr) +void *load_addr) {u8 status;int sec = rec_list1;
Signature · 1 line
2.49.0
Re: [PATCH 1/7] pc-bios/s390-ccw: Fix Misattributed Function Prototypes
Quoted 10 lines · On 20/10/2025 18.20, [email protected] wrote:
From: Jared Rossi <[email protected]>
The virtio-blkdev functions are incorrectly listed in
s390-ccw.has belonging tovirtio.c. Additionally,virtio_load_direct()has an unusedsubchan_idargument.Remove the unused argument and move the prototypes to
virtio.hso that they are independent from the CCW bus.Signed-off-by Jared Rossi <[email protected]>---
I'd maybe spell "Misattributed Function Prototypes" with small letters in the title, but apart from that, patch looks good to me:
Re: [PATCH 1/7] pc-bios/s390-ccw: Fix Misattributed Function Prototypes
Quoted 9 lines · Thomas Huth
Quoted 8 lines · On 20/10/2025 18.20, [email protected] wrote:
From: Jared Rossi <[email protected]>
The virtio-blkdev functions are incorrectly listed in
s390-ccw.has belonging to virtio.c. Additionally,virtio_load_direct()has an unusedsubchan_idargument.Remove the unused argument and move the prototypes to
virtio.hso that they are independent from the CCW bus.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Jared Rossi <[email protected]>---
I'd maybe spell "Misattributed Function Prototypes" with small letters in the title, but apart from that, patch looks good to me:
Reviewed-by Thomas Huth <[email protected]>
Thanks Thomas,
I'm not sure why I wrote it like that. I notice now I did the same thing with "Architecture" in patch 3. I'll fix the capitalization in both patches for the next version.
Regards,
Jared Rossi
PATCH 2/7 pc-bios/s390-ccw: Split virtio-ccw and generic virtio
In reply to [email protected]From: Jared Rossi <[email protected]>
Separate the CCW specific virtio routines and create generic wrappers for easier reuse of existing virtio functions with non-CCW devices.
--- hw/s390x/ipl.h | 5 - include/hw/s390x/ipl/qipl.h | 6 + pc-bios/s390-ccw/iplb.h | 4 - pc-bios/s390-ccw/virtio-ccw.h | 25 ++++ pc-bios/s390-ccw/virtio-scsi.h | 2 +- pc-bios/s390-ccw/virtio.h | 11 +- pc-bios/s390-ccw/main.c | 13 +- pc-bios/s390-ccw/virtio-blkdev.c | 57 +++++--- pc-bios/s390-ccw/virtio-ccw.c | 240 +++++++++++++++++++++++++++++++ pc-bios/s390-ccw/virtio-net.c | 5 +- pc-bios/s390-ccw/virtio-scsi.c | 7 +- pc-bios/s390-ccw/virtio.c | 209 +++++---------------------- pc-bios/s390-ccw/Makefile | 3 +- 13 files changed, 367 insertions(+), 220 deletions(-) create mode 100644 pc-bios/s390-ccw/virtio-ccw.h create mode 100644 pc-bios/s390-ccw/virtio-ccw.c
hw/s390x/ipl.h +0 -5
@@ -103,11 +103,6 @@ QEMU_BUILD_BUG_MSG(offsetof(S390IPLState, iplb) & 3, "alignment of iplb wrong");#define DIAG308_PV_STORE 9#define DIAG308_PV_START 10 -#define S390_IPL_TYPE_FCP 0x00 -#define S390_IPL_TYPE_CCW 0x02 -#define S390_IPL_TYPE_PV 0x05 -#define S390_IPL_TYPE_QEMU_SCSI 0xff -#define S390_IPLB_HEADER_LEN 8#define S390_IPLB_MIN_PV_LEN 148#define S390_IPLB_MIN_CCW_LEN 200
include/hw/s390x/ipl/qipl.h +6 -0
@@ -20,6 +20,12 @@#define LOADPARM_LEN 8#define NO_LOADPARM "\0\0\0\0\0\0\0\0" +#define S390_IPL_TYPE_FCP 0x00 +#define S390_IPL_TYPE_CCW 0x02 +#define S390_IPL_TYPE_PCI 0x04 +#define S390_IPL_TYPE_PV 0x05 +#define S390_IPL_TYPE_QEMU_SCSI 0xff +/* * The QEMU IPL Parameters will be stored at absolute address * 204 (0xcc) which means it is 32-bit word aligned but not
pc-bios/s390-ccw/iplb.h +0 -4
@@ -23,10 +23,6 @@ extern QemuIplParameters qipl; extern IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE)));extern bool have_iplb; -#define S390_IPL_TYPE_FCP 0x00 -#define S390_IPL_TYPE_CCW 0x02 -#define S390_IPL_TYPE_QEMU_SCSI 0xff -static inline bool manage_iplb (IplParameterBlock *iplb,bool store) { register unsigned long addr asm("0") = (unsigned long) iplb;
pc-bios/s390-ccw/virtio-ccw.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Virtio definitions for CCW devices +* +* Copyright 2025 IBM Corp. +* Author(s): Jared Rossi <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef VIRTIO_CCW_H +#define VIRTIO_CCW_H + +/* main.c */ +extern SubChannelId blk_schid; + +/* virtio-ccw.c */ +int run_ccw (VDev *vdev,int cmd,void *ptr,int len,bool sli); +int drain_irqs_ccw (SubChannelId schid); +bool virtio_ccw_is_supported (SubChannelId schid); +int virtio_ccw_run (VDev *vdev,int vqid,VirtioCmd *cmd); +long virtio_ccw_notify (SubChannelId schid,int vq_idx,long cookie); +int virtio_ccw_setup (VDev *vdev); +int virtio_ccw_reset (VDev *vdev); + +#endif
pc-bios/s390-ccw/virtio-scsi.h +1 -1
@@ -69,6 +69,6 @@ static inline bool virtio_scsi_response_ok(const VirtioScsiCmdResp *r)int virtio_scsi_read_many (VDev *vdev,unsigned long sector,void *load_addr,int sec_num); -int virtio_scsi_setup_device (SubChannelId schid); +int virtio_scsi_setup_device (void );#endif /* VIRTIO_SCSI_H */
pc-bios/s390-ccw/virtio.h +9 -2
@@ -109,6 +109,8 @@ struct VRing { };typedef struct VRing VRing ; +char *virtio_get_ring_area (void ); +/*********************************************** * Virtio block *
@@ -138,6 +140,9 @@ typedef struct VRing VRing;/* Barrier before this op. */ #define VIRTIO_BLK_T_BARRIER 0x80000000 +/* For device bus switches */ +extern int ipl_type; +/* This is the first element of the read scatter-gather list. */ struct VirtioBlkOuthdr {/* VIRTIO_BLK_T* */
@@ -236,6 +241,7 @@ struct VDev {int cmd_vr_idx;void *ring_area;long wait_reply_timeout; +VirtioDevType type;VirtioGDN guessed_disk_nature;SubChannelId schid;SenseId senseid;
@@ -268,8 +274,9 @@ struct VirtioCmd { };typedef struct VirtioCmd VirtioCmd ; +void vring_init (VRing *vr,VqInfo *info);bool vring_notify (VRing *vr); -int drain_irqs (SubChannelId schid); +int drain_irqs (VRing *vr);void vring_send_buf (VRing *vr,void *p,int len,int flags);int vr_poll (VRing *vr);int vring_wait_reply (void );
@@ -282,7 +289,7 @@ int virtio_net_init(void *mac_addr);void virtio_net_deinit (void );/* virtio-blkdev.c */ -int virtio_blk_setup_device (SubChannelId schid); +int virtio_blk_setup_device (void );int virtio_read (unsigned long sector,void *load_addr);unsigned long virtio_load_direct (unsigned long rec_list1,unsigned long rec_list2,void *load_addr);
pc-bios/s390-ccw/main.c +8 -5
@@ -19,11 +19,12 @@#include "virtio-scsi.h" #include "dasd-ipl.h" -static SubChannelId blk_schid = { .one =1 }; +SubChannelId blk_schid = { .one =1 };static char loadparm_str[LOADPARM_LEN +1 ];QemuIplParameters qipl; IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE)));bool have_iplb; +int ipl_type;static uint16_t cutype;LowCore *lowcore;/* Yes, this *is* a pointer to address 0 */
@@ -216,7 +217,7 @@ static bool find_boot_device(void)VDev *vdev =virtio_get_device ();bool found = false; -switch (iplb.pbt) { +switch (ipl_type) {case S390_IPL_TYPE_CCW : vdev->scsi_device_selected = false;debug_print_int ("device no. " , iplb.ccw.devno);
@@ -245,15 +246,15 @@ static int virtio_setup(void) vdev->is_cdrom = false;int ret; -switch (vdev->senseid.cu_model) { +switch (vdev->type) {case VIRTIO_ID_NET :puts ("Network boot device detected" );return 0 ;case VIRTIO_ID_BLOCK : - ret =virtio_blk_setup_device (blk_schid); + ret =virtio_blk_setup_device ();break ;case VIRTIO_ID_SCSI : - ret =virtio_scsi_setup_device (blk_schid); + ret =virtio_scsi_setup_device ();break ;default :puts ("\n! No IPL device available !\n" );
@@ -316,11 +317,13 @@ void main(void)css_setup (); have_iplb =store_iplb (&iplb);if (!have_iplb) { + ipl_type =S390_IPL_TYPE_CCW ;/* Assume CCW for probing */ boot_setup ();probe_boot_device (); }while (have_iplb) { + ipl_type = iplb.pbt;boot_setup ();if (have_iplb &&find_boot_device ()) {ipl_boot_device ();
pc-bios/s390-ccw/virtio-blkdev.c +35 -22
163 lines not on this page · raw message
pc-bios/s390-ccw/virtio-ccw.c new file +240 -0
240 lines not on this page · raw message
pc-bios/s390-ccw/virtio-net.c +3 -2
@@ -19,6 +19,7 @@#include <ethernet.h> #include "s390-ccw.h" #include "virtio.h" +#include "virtio-ccw.h" #include "s390-time.h" #include "helper.h"
@@ -54,7 +55,7 @@ int virtio_net_init(void *mac_addr) rx_last_idx =0 ; vdev->guest_features[0 ] =VIRTIO_NET_F_MAC_BIT ; -virtio_setup_ccw (vdev); +virtio_ccw_setup (vdev);if (!(vdev->guest_features[0 ] &VIRTIO_NET_F_MAC_BIT )) {puts ("virtio-net device does not support the MAC address feature" );
@@ -88,7 +89,7 @@ int send(int fd, const void *buf, int len, int flags)while (!vr_poll (txvq)) {yield (); } -if (drain_irqs (txvq->schid)) { +if (drain_irqs (txvq)) {puts ("send: drain irqs failed" );return -1 ; }
pc-bios/s390-ccw/virtio-scsi.c +4 -3
@@ -13,6 +13,7 @@#include <stdio.h> #include "s390-ccw.h" #include "virtio.h" +#include "virtio-ccw.h" #include "scsi.h" #include "virtio-scsi.h" #include "s390-time.h"
@@ -476,12 +477,12 @@ static int virtio_scsi_setup(VDev *vdev)return 0 ; } -int virtio_scsi_setup_device (SubChannelId schid) +int virtio_scsi_setup_device () {VDev *vdev =virtio_get_device (); - vdev->schid = schid; -virtio_setup_ccw (vdev); + vdev->schid = blk_schid; +virtio_ccw_setup (vdev);if (vdev->config.scsi.sense_size !=VIRTIO_SCSI_SENSE_SIZE ) {puts ("Config: sense size mismatch" );
pc-bios/s390-ccw/virtio.c +34 -175
265 lines not on this page · raw message
pc-bios/s390-ccw/Makefile +2 -1
@@ -34,7 +34,8 @@ QEMU_DGFLAGS = -MMD -MP -MT $@ -MF $(@D)/$(*F).d .PHONY : all clean build-all distclean OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o menu.o netmain.o \ - virtio.o virtio-net.o virtio-scsi.o virtio-blkdev.o cio.o dasd-ipl.o + virtio.o virtio-net.o virtio-scsi.o virtio-blkdev.o cio.o dasd-ipl.o \ + virtio-ccw.o SLOF_DIR := $(SRC_PATH)/../../roms/SLOF
Signature · 1 line
2.49.0
Re: [PATCH 2/7] pc-bios/s390-ccw: Split virtio-ccw and generic virtio
Hi Jared!
Quoted 62 lines · On 20/10/2025 18.20, [email protected] wrote:
From: Jared Rossi <[email protected]>
Separate the CCW specific virtio routines and create generic wrappers for easier reuse of existing virtio functions with non-CCW devices.
Signed-off-by Jared Rossi <[email protected]>--- hw/s390x/ipl.h | 5 - include/hw/s390x/ipl/qipl.h | 6 + pc-bios/s390-ccw/iplb.h | 4 - pc-bios/s390-ccw/virtio-ccw.h | 25 ++++ pc-bios/s390-ccw/virtio-scsi.h | 2 +- pc-bios/s390-ccw/virtio.h | 11 +- pc-bios/s390-ccw/main.c | 13 +- pc-bios/s390-ccw/virtio-blkdev.c | 57 +++++--- pc-bios/s390-ccw/virtio-ccw.c | 240 +++++++++++++++++++++++++++++++ pc-bios/s390-ccw/virtio-net.c | 5 +- pc-bios/s390-ccw/virtio-scsi.c | 7 +- pc-bios/s390-ccw/virtio.c | 209 +++++---------------------- pc-bios/s390-ccw/Makefile | 3 +- 13 files changed, 367 insertions(+), 220 deletions(-)create mode 100644
pc-bios/s390-ccw/virtio-ccw.hcreate mode 100644pc-bios/s390-ccw/virtio-ccw.chw/s390x/ipl.h +0
-5@@ -103,11 +103,6 @@ QEMU_BUILD_BUG_MSG(offsetof(S390IPLState, iplb) & 3, "alignment of iplb wrong");#define DIAG308_PV_STORE 9#define DIAG308_PV_START 10 -#define S390_IPL_TYPE_FCP 0x00 -#define S390_IPL_TYPE_CCW 0x02 -#define S390_IPL_TYPE_PV 0x05 -#define S390_IPL_TYPE_QEMU_SCSI 0xff -#define S390_IPLB_HEADER_LEN 8#define S390_IPLB_MIN_PV_LEN 148#define S390_IPLB_MIN_CCW_LEN 200include/hw/s390x/ipl/qipl.h +6
-0@@ -20,6 +20,12 @@#define LOADPARM_LEN 8#define NO_LOADPARM "\0\0\0\0\0\0\0\0" +#define S390_IPL_TYPE_FCP 0x00 +#define S390_IPL_TYPE_CCW 0x02 +#define S390_IPL_TYPE_PCI 0x04 +#define S390_IPL_TYPE_PV 0x05 +#define S390_IPL_TYPE_QEMU_SCSI 0xff +/* * The QEMU IPL Parameters will be stored at absolute address * 204 (0xcc) which means it is 32-bit word aligned but not pc-bios/s390-ccw/iplb.h +0
-0
pc-bios/s390-ccw/iplb.h extern QemuIplParameters qipl; · line 28
Quoted 6 lines
pc-bios/s390-ccw/iplb.h +0
-3@@ -23,10 +23,6 @@ extern QemuIplParameters qipl; extern IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE)));extern bool have_iplb; -#define S390_IPL_TYPE_FCP 0x00 -#define S390_IPL_TYPE_CCW 0x02 -#define S390_IPL_TYPE_QEMU_SCSI 0xff
This patch is doing quite a bit of different changes at once, making it hard to review ... It would be nice if you could at least move the "S390_IPL_TYPE_*" movement into a separate patch.
Quoted 99 lines
pc-bios/s390-ccw/virtio-ccw.h new file +25
-0@@ -0,0 +1,25 @@ +/* +* Virtio definitions for CCW devices +* +* Copyright 2025 IBM Corp. +* Author(s): Jared Rossi <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef VIRTIO_CCW_H +#define VIRTIO_CCW_H + +/* main.c */ +extern SubChannelId blk_schid; + +/* virtio-ccw.c */ +int run_ccw (VDev *vdev,int cmd,void *ptr,int len,bool sli); +int drain_irqs_ccw (SubChannelId schid); +bool virtio_ccw_is_supported (SubChannelId schid); +int virtio_ccw_run (VDev *vdev,int vqid,VirtioCmd *cmd); +long virtio_ccw_notify (SubChannelId schid,int vq_idx,long cookie); +int virtio_ccw_setup (VDev *vdev); +int virtio_ccw_reset (VDev *vdev); + +#endif pc-bios/s390-ccw/virtio-scsi.h +1
-1@@ -69,6 +69,6 @@ static inline bool virtio_scsi_response_ok(const VirtioScsiCmdResp *r)int virtio_scsi_read_many (VDev *vdev,unsigned long sector,void *load_addr,int sec_num); -int virtio_scsi_setup_device (SubChannelId schid); +int virtio_scsi_setup_device (void );#endif /* VIRTIO_SCSI_H */ pc-bios/s390-ccw/virtio.h +9
-2@@ -109,6 +109,8 @@ struct VRing { };typedef struct VRing VRing ; +char *virtio_get_ring_area (void ); +/*********************************************** * Virtio block * @@ -138,6 +140,9 @@ typedef struct VRing VRing;/* Barrier before this op. */ #define VIRTIO_BLK_T_BARRIER 0x80000000 +/* For device bus switches */ +extern int ipl_type; +/* This is the first element of the read scatter-gather list. */ struct VirtioBlkOuthdr {/* VIRTIO_BLK_T* */ @@ -236,6 +241,7 @@ struct VDev {int cmd_vr_idx;void *ring_area;long wait_reply_timeout; +VirtioDevType type;VirtioGDN guessed_disk_nature;SubChannelId schid;SenseId senseid;@@ -268,8 +274,9 @@ struct VirtioCmd { };typedef struct VirtioCmd VirtioCmd ; +void vring_init (VRing *vr,VqInfo *info);bool vring_notify (VRing *vr); -int drain_irqs (SubChannelId schid); +int drain_irqs (VRing *vr);void vring_send_buf (VRing *vr,void *p,int len,int flags);int vr_poll (VRing *vr);int vring_wait_reply (void );@@ -282,7 +289,7 @@ int virtio_net_init(void *mac_addr);void virtio_net_deinit (void );/* virtio-blkdev.c */ -int virtio_blk_setup_device (SubChannelId schid); +int virtio_blk_setup_device (void );int virtio_read (unsigned long sector,void *load_addr);unsigned long virtio_load_direct (unsigned long rec_list1,unsigned long rec_list2,void *load_addr);pc-bios/s390-ccw/main.c +0
-0
pc-bios/s390-ccw/main.c line 27
Quoted 10 lines
pc-bios/s390-ccw/main.c +2
-1@@ -19,11 +19,12 @@#include "virtio-scsi.h" #include "dasd-ipl.h" -static SubChannelId blk_schid = { .one =1 }; +SubChannelId blk_schid = { .one =1 };static char loadparm_str[LOADPARM_LEN +1 ];QemuIplParameters qipl; IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE)));bool have_iplb; +int ipl_type;
Having two new global variables to pass around information is somewhat ugly...
pc-bios/s390-ccw/main.c static bool find_boot_device(void) · line 222
Quoted 11 lines
pc-bios/s390-ccw/main.c +1
-1static uint16_t cutype;LowCore *lowcore;/* Yes, this *is* a pointer to address 0 */ @@ -216,7 +217,7 @@ static bool find_boot_device(void)VDev *vdev =virtio_get_device ();bool found = false; -switch (iplb.pbt) { +switch (ipl_type) {case S390_IPL_TYPE_CCW : vdev->scsi_device_selected = false;
... could we maybe set up vdev->schid here already (or in virtio_setup below) ...
pc-bios/s390-ccw/main.c static int virtio_setup(void) · line 254
Quoted 13 lines
pc-bios/s390-ccw/main.c +2
-2debug_print_int ("device no. " , iplb.ccw.devno);@@ -245,15 +246,15 @@ static int virtio_setup(void) vdev->is_cdrom = false;int ret; -switch (vdev->senseid.cu_model) { +switch (vdev->type) {case VIRTIO_ID_NET :puts ("Network boot device detected" );return 0 ;case VIRTIO_ID_BLOCK : - ret =virtio_blk_setup_device (blk_schid); + ret =virtio_blk_setup_device ();
... and then simply pass vdev as parameter to virtio_blk_setup_device() here ...
pc-bios/s390-ccw/main.c static int virtio_setup(void) · line 257
Quoted 4 lines
pc-bios/s390-ccw/main.c +1
-1break ;case VIRTIO_ID_SCSI : - ret =virtio_scsi_setup_device (blk_schid); + ret =virtio_scsi_setup_device ();
... and here.
Then we don't have to make blk_schid global.
(Please also make this as a separate patch first, since this one here is already quite complicated).
Would it also be possible to store ipl_type in the VDev, so we don't have to make this variable global?
Quoted 30 lines
pc-bios/s390-ccw/main.c +2
-0break ;default :puts ("\n! No IPL device available !\n" );@@ -316,11 +317,13 @@ void main(void)css_setup (); have_iplb =store_iplb (&iplb);if (!have_iplb) { + ipl_type =S390_IPL_TYPE_CCW ;/* Assume CCW for probing */ boot_setup ();probe_boot_device (); }while (have_iplb) { + ipl_type = iplb.pbt;boot_setup ();if (have_iplb &&find_boot_device ()) {ipl_boot_device ();pc-bios/s390-ccw/virtio-blkdev.c +1
-0@@ -11,6 +11,7 @@#include <stdio.h> #include "s390-ccw.h" #include "virtio.h" +#include "virtio-ccw.h" #include "virtio-scsi.h" #define VIRTIO_BLK_F_GEOMETRY (1 << 4)
pc-bios/s390-ccw/virtio-blkdev.c static int virtio_blk_read_many(VDev *vdev, unsigned long sector, void *load_add · line 44
Quoted 4 lines
pc-bios/s390-ccw/virtio-blkdev.c +1
-0@@ -40,9 +41,10 @@ static int virtio_blk_read_many(VDev *vdev, unsigned long sector, void *load_add VRING_DESC_F_WRITE | VRING_HIDDEN_IS_CHAIN);/* Now we can tell the host to read */ +vring_notify (vr);
Why is there suddenly a new call to vring_notify() popping up here? ... if it's necessary now, this deserves a separate patch, I think.
Quoted 165 lines
pc-bios/s390-ccw/virtio-blkdev.c +33
-22vring_wait_reply (); -if (drain_irqs (vr->schid)) { +if (drain_irqs (vr)) {/* Well, whatever status is supposed to contain... */ status =1 ; }@@ -53,14 +55,14 @@ int virtio_read_many(unsigned long sector, void *load_addr, int sec_num) {VDev *vdev =virtio_get_device (); -switch (vdev->senseid.cu_model) { +switch (vdev->type) {case VIRTIO_ID_BLOCK :return virtio_blk_read_many (vdev, sector, load_addr, sec_num);case VIRTIO_ID_SCSI :return virtio_scsi_read_many (vdev, sector, load_addr, sec_num); +default : +return -1 ; } - -return -1 ; } unsigned long virtio_load_direct(unsigned long rec_list1, unsigned long rec_list2,@@ -119,7 +121,7 @@ void virtio_assume_iso9660(void) {VDev *vdev =virtio_get_device (); -switch (vdev->senseid.cu_model) { +switch (vdev->type) {case VIRTIO_ID_BLOCK : vdev->guessed_disk_nature =VIRTIO_GDN_SCSI ; vdev->config.blk.blk_size =VIRTIO_ISO_BLOCK_SIZE ;@@ -129,6 +131,8 @@ void virtio_assume_iso9660(void)case VIRTIO_ID_SCSI : vdev->scsi_block_size =VIRTIO_ISO_BLOCK_SIZE ;break ; +default : +panic ("Virtio device type mismatch for iso9660 IPL" ); } }@@ -139,13 +143,15 @@ void virtio_assume_eckd(void) vdev->guessed_disk_nature =VIRTIO_GDN_DASD ; vdev->blk_factor =1 ; vdev->config.blk.physical_block_exp =0 ; -switch (vdev->senseid.cu_model) { +switch (vdev->type) {case VIRTIO_ID_BLOCK : vdev->config.blk.blk_size =VIRTIO_DASD_DEFAULT_BLOCK_SIZE ;break ;case VIRTIO_ID_SCSI : vdev->config.blk.blk_size = vdev->scsi_block_size;break ; +default : +panic ("Virtio device type mismatch for ECKD IPL" ); } vdev->config.blk.geometry.heads =15 ; vdev->config.blk.geometry.sectors =@@ -162,8 +168,7 @@ bool virtio_ipl_disk_is_valid(void)return true; } -return (vdev->senseid.cu_model ==VIRTIO_ID_BLOCK || - vdev->senseid.cu_model ==VIRTIO_ID_SCSI ) && +return (vdev->type ==VIRTIO_ID_BLOCK || vdev->type ==VIRTIO_ID_SCSI ) && blksize >=512 && blksize <=4096 ; }@@ -171,41 +176,44 @@ int virtio_get_block_size(void) {VDev *vdev =virtio_get_device (); -switch (vdev->senseid.cu_model) { +switch (vdev->type) {case VIRTIO_ID_BLOCK :return vdev->config.blk.blk_size;case VIRTIO_ID_SCSI :return vdev->scsi_block_size; +default : +return 0 ; } -return 0 ; }uint8_t virtio_get_heads (void ) {VDev *vdev =virtio_get_device (); -switch (vdev->senseid.cu_model) { +switch (vdev->type) {case VIRTIO_ID_BLOCK :return vdev->config.blk.geometry.heads;case VIRTIO_ID_SCSI :return vdev->guessed_disk_nature ==VIRTIO_GDN_DASD ? vdev->config.blk.geometry.heads :255 ; +default : +return 0 ; } -return 0 ; }uint8_t virtio_get_sectors (void ) {VDev *vdev =virtio_get_device (); -switch (vdev->senseid.cu_model) { +switch (vdev->type) {case VIRTIO_ID_BLOCK :return vdev->config.blk.geometry.sectors;case VIRTIO_ID_SCSI :return vdev->guessed_disk_nature ==VIRTIO_GDN_DASD ? vdev->config.blk.geometry.sectors :63 ; +default : +return 0 ; } -return 0 ; }uint64_t virtio_get_blocks (void )@@ -213,24 +221,29 @@ uint64_t virtio_get_blocks(void)VDev *vdev =virtio_get_device ();const uint64_t factor =virtio_get_block_size () /VIRTIO_SECTOR_SIZE ; -switch (vdev->senseid.cu_model) { +switch (vdev->type) {case VIRTIO_ID_BLOCK :return vdev->config.blk.capacity / factor;case VIRTIO_ID_SCSI :return vdev->scsi_last_block / factor; +default : +return 0 ; } -return 0 ; } -int virtio_blk_setup_device (SubChannelId schid) +int virtio_blk_setup_device () {VDev *vdev =virtio_get_device (); - vdev->guest_features[0 ] =VIRTIO_BLK_F_GEOMETRY |VIRTIO_BLK_F_BLK_SIZE ; - vdev->schid = schid; -virtio_setup_ccw (vdev); -puts ("Using virtio-blk." ); -return 0 ; + vdev->guest_features[0 ] =VIRTIO_BLK_F_GEOMETRY |VIRTIO_BLK_F_BLK_SIZE ; +switch (ipl_type) { +case S390_IPL_TYPE_QEMU_SCSI : +case S390_IPL_TYPE_CCW : + vdev->schid = blk_schid; +return virtio_ccw_setup (vdev); + } + +return 1 ; }pc-bios/s390-ccw/virtio-ccw.c new file +0
-0
pc-bios/s390-ccw/virtio-ccw.c line 5
Quoted 5 lines
pc-bios/s390-ccw/virtio-ccw.c new file +5
-0@@ -0,0 +1,240 @@ +/* +* Virtio functionality for CCW devices +* +* Copyright 2025 IBM Corp. +* Author(s): Jared Rossi <[email protected]>
Since you're copying over functions from another file, I think it would make sense to add the copyright statement from the other file here, too.
Quoted 52 lines
pc-bios/s390-ccw/virtio-ccw.c new file +52
-0+* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include <string.h> +#include "s390-ccw.h" +#include "cio.h" +#include "virtio.h" +#include "virtio-ccw.h" +#include "virtio-scsi.h" +#include "bswap.h" +#include "helper.h" +#include "s390-time.h" + +/* virtio spec v1.0 para 4.3.3.2 */ +static long kvm_hypercall (unsigned long nr,unsigned long param1, +unsigned long param2,unsigned long param3) +{ + register unsigned long r_nr asm("1") = nr; + register unsigned long r_param1 asm("2") = param1; + register unsigned long r_param2 asm("3") = param2; + register unsigned long r_param3 asm("4") = param3; + registerlong retval asm("2" ); + + asmvolatile ("diag %%r2,%%r4,0x500" + :"=d" (retval) + :"d" (r_nr),"0" (r_param1),"r" (r_param2),"d" (r_param3) + :"memory" ,"cc" ); + +return retval; +} + +bool virtio_ccw_is_supported (SubChannelId schid) +{ +VDev *vdev =virtio_get_device (); + vdev->schid = schid; +memset (&vdev->senseid,0 ,sizeof (vdev->senseid)); + +/* +* Run sense id command. +* The size of the senseid data differs between devices (notably, +* between virtio devices and dasds), so specify the largest possible +* size and suppress the incorrect length indication for smaller sizes. +*/ +if (run_ccw (vdev,CCW_CMD_SENSE_ID , &vdev->senseid,sizeof (vdev->senseid), + true)) { +return false; + } + + vdev->type = vdev->senseid.cu_model; + +if (vdev->senseid.cu_type ==0x3832 ) { +switch (vdev->type) {
pc-bios/s390-ccw/virtio-ccw.c line 68
Quoted 10 lines
pc-bios/s390-ccw/virtio-ccw.c new file +10
-0+case VIRTIO_ID_BLOCK : +case VIRTIO_ID_SCSI : +case VIRTIO_ID_NET : +return true; +default : +return false; + } + } +return false; +}
You copied the is_supported() function to the new file, but also kept the original. As far as I can see, virtio_ccw_is_supported() is not used at all in your new code, so you could remove that here again? Or remove the original function and only use this one here?
Quoted 46 lines
pc-bios/s390-ccw/virtio-ccw.c new file +46
-0+int drain_irqs_ccw (SubChannelId schid) +{ +Irb irb = {}; +int r =0 ; + +while (1 ) { +/* FIXME: make use of TPI, for that enable subchannel and isc */ +if (tsch (schid, &irb)) { +/* Might want to differentiate error codes later on. */ +if (irb.scsw.cstat) { + r = -EIO ; + }else if (irb.scsw.dstat !=0xc ) { + r = -EIO ; + } +return r; + } + } +} + +long virtio_ccw_notify (SubChannelId schid,int vq_idx,long cookie) +{ +return kvm_hypercall (KVM_S390_VIRTIO_CCW_NOTIFY , *(u32 *)&schid, + vq_idx, cookie); +} + +int virtio_ccw_run (VDev *vdev,int vqid,VirtioCmd *cmd) +{ +VRing *vr = &vdev->vrings[vqid]; +int i =0 ; + +do { +vring_send_buf (vr, cmd[i].data, cmd[i].size, + cmd[i].flags | (i ?VRING_HIDDEN_IS_CHAIN :0 )); + }while (cmd[i++].flags &VRING_DESC_F_NEXT ); + +vring_wait_reply (); +if (drain_irqs (vr)) { +return -1 ; + } +return 0 ; +} + +int run_ccw (VDev *vdev,int cmd,void *ptr,int len,bool sli) +{ +Ccw1 ccw = {}; +
pc-bios/s390-ccw/virtio-ccw.c line 125
Quoted 10 lines
pc-bios/s390-ccw/virtio-ccw.c new file +10
-0+ ccw.cmd_code = cmd; + ccw.cda = (long )ptr; + ccw.count = len; + +if (sli) { + ccw.flags |=CCW_FLAG_SLI ; + } + +return do_cio (vdev->schid, vdev->senseid.cu_type,ptr2u32 (&ccw),CCW_FMT1 ); +}
As far as I can see, run_ccw() is now only used in the new file, so you could make this function "static".
Thomas
Re: [PATCH 2/7] pc-bios/s390-ccw: Split virtio-ccw and generic virtio
Hi Thomas,
Thanks for your comments...
Quoted 27 lines · Thomas Huth
Hi Jared!
Quoted 20 lines · On 20/10/2025 18.20, [email protected] wrote:
From: Jared Rossi <[email protected]>
Separate the CCW specific virtio routines and create generic wrappers for easier reuse of existing virtio functions with non-CCW devices.
Signed-off-by Jared Rossi <[email protected]>---
hw/s390x/ipl.h | 5 - include/hw/s390x/ipl/qipl.h | 6 + pc-bios/s390-ccw/iplb.h | 4 - pc-bios/s390-ccw/virtio-ccw.h | 25 ++++ pc-bios/s390-ccw/virtio-scsi.h | 2 +- pc-bios/s390-ccw/virtio.h | 11 +- pc-bios/s390-ccw/main.c | 13 +-pc-bios/s390-ccw/virtio-blkdev.c| 57 +++++--- pc-bios/s390-ccw/virtio-ccw.c | 240 +++++++++++++++++++++++++++++++ pc-bios/s390-ccw/virtio-net.c | 5 +- pc-bios/s390-ccw/virtio-scsi.c | 7 +- pc-bios/s390-ccw/virtio.c | 209 +++++---------------------- pc-bios/s390-ccw/Makefile | 3 +-Quoted 4 lines
13 files changed, 367 insertions(+), 220 deletions(-)create mode 100644
pc-bios/s390-ccw/virtio-ccw.hcreate mode 100644pc-bios/s390-ccw/virtio-ccw.c
Quoted 1 line
This patch is doing quite a bit of different changes at once, making it hard to review ... It would be nice if you could at least move the "S390_IPL_TYPE_*" movement into a separate patch.
Sure, I can break this up. I think your suggestions about removing the global variables by storing them in the VDev struct make sense. I'll split it into smaller patches and clean up the things you mentioned.
Thanks,
Jared Rossi
PATCH 3/7 pc-bios/s390-ccw: Introduce CLP Architecture
In reply to [email protected]From: Jared Rossi <[email protected]>
Call Logical Processor (CLP) Architecture is used for managing PCI functions on s390x. Define and include the structures and routines needed to interact with PCI devices during IPL.
Headers in ~/qemu/include/hw are not normally visible and must be included using a relative path. Due to this, the QEMU_PACKED macro must also be defined here.
--- pc-bios/s390-ccw/clp.h | 24 +++++++++ pc-bios/s390-ccw/clp.c | 106 ++++++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/Makefile | 2 +- 3 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 pc-bios/s390-ccw/clp.h create mode 100644 pc-bios/s390-ccw/clp.c
pc-bios/s390-ccw/clp.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Call Logical Processor (CLP) architecture definitions +* +* Copyright 2025 IBM Corp. +* Author(s): Jared Rossi <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef CLP_H +#define CLP_H + +#ifndef QEMU_PACKED +#define QEMU_PACKED __attribute__((packed)) +#endif + +#include <stdint.h> +#include "../../include/hw/s390x/s390-pci-clp.h" + +int clp_pci (void *data); +int enable_pci_function (uint32_t *fhandle); +int enumerate_pci_functions (void ); + +#endif
pc-bios/s390-ccw/clp.c new file +106 -0
106 lines not on this page · raw message
pc-bios/s390-ccw/Makefile +1 -1
@@ -35,7 +35,7 @@ QEMU_DGFLAGS = -MMD -MP -MT $@ -MF $(@D)/$(*F).d OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o menu.o netmain.o \ virtio.o virtio-net.o virtio-scsi.o virtio-blkdev.o cio.o dasd-ipl.o \ - virtio-ccw.o + virtio-ccw.o clp.o SLOF_DIR := $(SRC_PATH)/../../roms/SLOF
Signature · 1 line
2.49.0
Re: [PATCH 3/7] pc-bios/s390-ccw: Introduce CLP Architecture
Quoted 8 lines · On 20/10/2025 18.20, [email protected] wrote:
From: Jared Rossi <[email protected]>
Call Logical Processor (CLP) Architecture is used for managing PCI functions on s390x. Define and include the structures and routines needed to interact with PCI devices during IPL.
Headers in ~/qemu/include/hw are not normally visible and must be included using a relative path.
That's kind of ugly. Could we move the header (or at least the structs that you need) into include/hw/s390x/ipl/ instead? IMHO it should be ok to include "include/hw/s390x/ipl/s390-pci-bus.h" from hw/s390x/s390-pci-vfio.c, but if you mind the "ipl" here, we could also keep a stub header in include/hw/s390x/s390-pci-bus.h that itself simply includes "ipl/s390-pci-bus.h" ? Or something similar?
Thomas
Re: [PATCH 3/7] pc-bios/s390-ccw: Introduce CLP Architecture
In reply to [email protected]Quoted 37 lines · On 20/10/2025 18.20, [email protected] wrote:
From: Jared Rossi <[email protected]>
Call Logical Processor (CLP) Architecture is used for managing PCI functions on s390x. Define and include the structures and routines needed to interact with PCI devices during IPL.
Headers in ~/qemu/include/hw are not normally visible and must be included using a relative path. Due to this, the
QEMU_PACKEDmacro must also be defined here.Signed-off-by Jared Rossi <[email protected]>--- pc-bios/s390-ccw/clp.h | 24 +++++++++ pc-bios/s390-ccw/clp.c | 106 ++++++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/Makefile | 2 +- 3 files changed, 131 insertions(+), 1 deletion(-)create mode 100644
pc-bios/s390-ccw/clp.h
create mode 100644pc-bios/s390-ccw/clp.cpc-bios/s390-ccw/clp.h new file +12
-0@@ -0,0 +1,24 @@ +/* +* Call Logical Processor (CLP) architecture definitions +* +* Copyright 2025 IBM Corp. +* Author(s): Jared Rossi <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef CLP_H +#define CLP_H +
pc-bios/s390-ccw/clp.h line 22
Quoted 10 lines
pc-bios/s390-ccw/clp.h new file +10
-0+#ifndef QEMU_PACKED +#define QEMU_PACKED __attribute__((packed)) +#endif + +#include <stdint.h> +#include "../../include/hw/s390x/s390-pci-clp.h" + +int clp_pci (void *data); +int enable_pci_function (uint32_t *fhandle); +int enumerate_pci_functions (void );
I just noticed that you later remove this unused prototype for enumerate_pci_functions() in a later patch again. Please remove it from this patch here in the next respin instead.
Thanks,
Thomas
PATCH 4/7 pc-bios/s390-ccw: Introduce PCI device IPL format
In reply to [email protected]From: Jared Rossi <[email protected]>
Define selected s390x PCI instructions and extend IPLB to allow PCI devices.
--- include/hw/s390x/ipl/qipl.h | 9 ++ pc-bios/s390-ccw/pci.h | 77 +++++++++++++++ pc-bios/s390-ccw/pci.c | 191 ++++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/Makefile | 2 +- 4 files changed, 278 insertions(+), 1 deletion(-) create mode 100644 pc-bios/s390-ccw/pci.h create mode 100644 pc-bios/s390-ccw/pci.c
include/hw/s390x/ipl/qipl.h +9 -0
@@ -104,6 +104,14 @@ struct IplBlockQemuScsi { }QEMU_PACKED ;typedef struct IplBlockQemuScsi IplBlockQemuScsi ; +struct IplBlockPci { +uint32_t reserved0[80 ]; +uint8_t opt; +uint8_t reserved1[3 ]; +uint32_t fid; +}QEMU_PACKED ; +typedef struct IplBlockPci IplBlockPci ; + union IplParameterBlock { struct { uint32_t len;
@@ -119,6 +127,7 @@ union IplParameterBlock {IplBlockFcp fcp;IPLBlockPV pv;IplBlockQemuScsi scsi; +IplBlockPci pci; }; }QEMU_PACKED ;struct {
pc-bios/s390-ccw/pci.h new file +77 -0
77 lines not on this page · raw message
pc-bios/s390-ccw/pci.c new file +191 -0
191 lines not on this page · raw message
pc-bios/s390-ccw/Makefile +1 -1
@@ -35,7 +35,7 @@ QEMU_DGFLAGS = -MMD -MP -MT $@ -MF $(@D)/$(*F).d OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o menu.o netmain.o \ virtio.o virtio-net.o virtio-scsi.o virtio-blkdev.o cio.o dasd-ipl.o \ - virtio-ccw.o clp.o + virtio-ccw.o clp.o pci.o SLOF_DIR := $(SRC_PATH)/../../roms/SLOF
Signature · 1 line
2.49.0
Re: [PATCH 4/7] pc-bios/s390-ccw: Introduce PCI device IPL format
Quoted 19 lines · On 20/10/2025 18.20, [email protected] wrote:
From: Jared Rossi <[email protected]>
Define selected s390x PCI instructions and extend IPLB to allow PCI devices.
Signed-off-by Jared Rossi <[email protected]>--- include/hw/s390x/ipl/qipl.h | 9 ++ pc-bios/s390-ccw/pci.h | 77 +++++++++++++++ pc-bios/s390-ccw/pci.c | 191 ++++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/Makefile | 2 +- 4 files changed, 278 insertions(+), 1 deletion(-)create mode 100644
pc-bios/s390-ccw/pci.h
create mode 100644pc-bios/s390-ccw/pci.cinclude/hw/s390x/ipl/qipl.h +0
-0
include/hw/s390x/ipl/qipl.h struct IplBlockQemuScsi { · line 112
Quoted 9 lines
include/hw/s390x/ipl/qipl.h +6
-0@@ -104,6 +104,14 @@ struct IplBlockQemuScsi { }QEMU_PACKED ;typedef struct IplBlockQemuScsi IplBlockQemuScsi ; +struct IplBlockPci { +uint32_t reserved0[80 ]; +uint8_t opt; +uint8_t reserved1[3 ]; +uint32_t fid; +}QEMU_PACKED ;
Looks like all members of this struct are naturally aligned ... I think you could likely drop the QEMU_PACKED here.
Quoted 13 lines
include/hw/s390x/ipl/qipl.h +3
-0+typedef struct IplBlockPci IplBlockPci ; + union IplParameterBlock { struct { uint32_t len;@@ -119,6 +127,7 @@ union IplParameterBlock {IplBlockFcp fcp;IPLBlockPV pv;IplBlockQemuScsi scsi; +IplBlockPci pci; }; }QEMU_PACKED ;struct {
...
Quoted 22 lines
pc-bios/s390-ccw/pci.c new file +16
-0@@ -0,0 +1,191 @@ +/* +* s390x PCI funcionality +* +* Copyright 2025 IBM Corp. +* Author(s): Jared Rossi <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "clp.h" +#include "pci.h" +#include <stdio.h> + +/* PCI load */ +static inline int pcilg (uint64_t *data,uint64_t req,uint64_t offset,uint8_t *status) +{
pc-bios/s390-ccw/pci.c line 26
Quoted 10 lines
pc-bios/s390-ccw/pci.c new file +10
-0+union register_pair req_off = {.even = req, .odd = offset}; +int cc =-1 ; +uint64_t __data =0x92 ; + + asmvolatile ( +" .insn rre,0xb9d20000,%[data],%[req_off]\n" +" ipm %[cc]\n" +" srl %[cc],28\n" + : [cc]"+d" (cc), [data]"=d" (__data), + [req_off]"+&d" (req_off.pair) ::"cc" );
What's the "&" good for here?
Quoted 6 lines
pc-bios/s390-ccw/pci.c new file +6
-0+ *status = req_off.even >>24 &0xff ; + *data = __data; +return cc; +} + +/* PCI store */
pc-bios/s390-ccw/pci.c line 42
Quoted 10 lines
pc-bios/s390-ccw/pci.c new file +10
-0+int pcistg (uint64_t data,uint64_t req,uint64_t offset,uint8_t *status) +{ +union register_pair req_off = {.even = req, .odd = offset}; +int cc =-1 ; + + asmvolatile ( +" .insn rre,0xb9d00000,%[data],%[req_off]\n" +" ipm %[cc]\n" +" srl %[cc],28\n" + : [cc] "+d" (cc), [req_off] "+&d" (req_off.pair)
dito
Quoted 58 lines
pc-bios/s390-ccw/pci.c new file +58
-0+ : [data] "d" (data) + : "cc"); + *status = req_off.even >>24 &0xff ; +return cc; +} + +/* store PCI function controls */ +int stpcifc (uint64_t req,PciFib *fib,uint8_t *status) +{ +uint8_t cc; + + asmvolatile ( +" .insn rxy,0xe300000000d4,%[req],%[fib]\n" +" ipm %[cc]\n" +" srl %[cc],28\n" + : [cc]"=d" (cc), [req]"+d" (req), [fib]"+Q" (*fib) + : :"cc" ); + *status = req >>24 &0xff ; +return cc; +} + +/* modify PCI function controls */ +int mpcifc (uint64_t req,PciFib *fib,uint8_t *status) +{ +uint8_t cc; + + asmvolatile ( +" .insn rxy,0xe300000000d0,%[req],%[fib]\n" +" ipm %[cc]\n" +" srl %[cc],28\n" + : [cc]"=d" (cc), [req]"+d" (req), [fib]"+Q" (*fib) + : :"cc" ); + *status = req >>24 &0xff ; +return cc; +} + +int pci_write (uint32_t fhandle,uint64_t offset,uint64_t data,uint8_t len) +{ + +uint64_t req =ZPCI_CREATE_REQ (fhandle,4 , len); +uint8_t status; +int rc; + + rc =pcistg (data, req, offset, &status); +if (rc ==1 ) { +return status; + }else if (rc) { +return rc; + } + +return 0 ; +} + +int pci_read (uint32_t fhandle,uint64_t offset,uint8_t picas,void *buf,uint8_t len) +{ +uint64_t req; +uint64_t data; +uint8_t status;
pc-bios/s390-ccw/pci.c line 110
Quoted 10 lines
pc-bios/s390-ccw/pci.c new file +10
-0+int readlen; +int i =0 ; +int rc =0 ; + +while (len >0 && !rc) { + data =0 ; + readlen = len >8 ?8 : len; + req =ZPCI_CREATE_REQ (fhandle, picas, readlen); + rc =pcilg (&data, req, offset + (i *8 ), &status); + ((uint64_t *)buf)[i] = data;
This looks somewhat dangerous ... what if buf points to a buffer where its lengths is not divisible by 8? ... you'll happily overwrite the data that is right behind the buffer in memory.
Quoted 8 lines
pc-bios/s390-ccw/pci.c new file +8
-0+ len -= readlen; + i++; + } + +if (rc ==1 ) { +return status; + }else if (rc) { +return rc;
pc-bios/s390-ccw/pci.c line 128
Quoted 10 lines
pc-bios/s390-ccw/pci.c new file +10
-0+ } + +return 0 ; +} + +/* +* Find the position of the capability config within PCI configuration +* space for a given cfg type. Return the position if found, otherwise 0. +*/ +uint8_t find_cap_pos (uint32_t fhandle,uint64_t cfg_type) {
Curly bracket on the next line, please.
pc-bios/s390-ccw/pci.c line 135
Quoted 7 lines
pc-bios/s390-ccw/pci.c new file +7
-0+uint64_t req, next, cfg; +uint8_t status; +int rc; + + req =ZPCI_CREATE_REQ (fhandle,0xf ,1 ); + rc =pcilg (&next, req,PCI_CAPABILITY_LIST , &status); + rc =pcilg (&cfg, req, next +3 , &status);
Assigning rc just to discard the value again in the next line does not make sense... if you're lazy, use "rc |= ..." in the second line. Otherwise please explicitly check the "rc" after the first call.
pc-bios/s390-ccw/pci.c line 139
Quoted 3 lines
pc-bios/s390-ccw/pci.c new file +3
-0+while (!rc && (cfg != cfg_type) && next) { + rc =pcilg (&next, req, next +1 , &status); + rc =pcilg (&cfg, req, next +3 , &status);
dito
pc-bios/s390-ccw/pci.c line 143
Quoted 4 lines
pc-bios/s390-ccw/pci.c new file +4
-0+ } + +return rc ?0 : next; +}
Thomas
Re: [PATCH 4/7] pc-bios/s390-ccw: Introduce PCI device IPL format
In reply to [email protected]Hi Jared,
Quoted 140 lines · On 10/20/2025 9:20 AM, [email protected] wrote:
From: Jared Rossi<[email protected]>
Define selected s390x PCI instructions and extend IPLB to allow PCI devices.
Signed-off-by Jared Rossi<[email protected]>--- include/hw/s390x/ipl/qipl.h | 9 ++ pc-bios/s390-ccw/pci.h | 77 +++++++++++++++ pc-bios/s390-ccw/pci.c | 191 ++++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/Makefile | 2 +- 4 files changed, 278 insertions(+), 1 deletion(-)create mode 100644
pc-bios/s390-ccw/pci.h
create mode 100644pc-bios/s390-ccw/pci.cinclude/hw/s390x/ipl/qipl.h +9
-0@@ -104,6 +104,14 @@ struct IplBlockQemuScsi { }QEMU_PACKED ;typedef struct IplBlockQemuScsi IplBlockQemuScsi ; +struct IplBlockPci { +uint32_t reserved0[80 ]; +uint8_t opt; +uint8_t reserved1[3 ]; +uint32_t fid; +}QEMU_PACKED ; +typedef struct IplBlockPci IplBlockPci ; + union IplParameterBlock { struct { uint32_t len;@@ -119,6 +127,7 @@ union IplParameterBlock {IplBlockFcp fcp;IPLBlockPV pv;IplBlockQemuScsi scsi; +IplBlockPci pci; }; }QEMU_PACKED ;struct {pc-bios/s390-ccw/pci.h new file +77
-0@@ -0,0 +1,77 @@ +/* +* s390x PCI definitions +* +* Copyright 2025 IBM Corp. +* Author(s): Jared Rossi<[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef PCI_H +#define PCI_H + +#include <stdint.h> +#include "clp.h" + +#define ZPCI_CREATE_REQ (handle, space, len) \ + ((uint64_t) handle << 32 | space << 16 | len) + +union register_pair { +unsigned __int128 pair; +struct { +unsigned long even; +unsigned long odd; + }; +}; + +#define PCIFIB_FC_ENABLED 0x80 +#define PCIFIB_FC_ERROR 0x40 +#define PCIFIB_FC_BLOCKED 0x20 +#define PCIFIB_FC_DMAREG 0x10 + +#define PCIST_DISABLED 0x0 +#define PCIST_ENABLED 0x1 + +#define PCI_CAPABILITY_LIST 0x34/* Offset of first capability list entry */ + +struct PciFib { +uint32_t reserved0[2 ]; +uint8_t fcflags; +uint8_t reserved1[3 ]; +uint32_t reserved2; +uint64_t pba; +uint64_t pal; +uint64_t iota; +uint16_t isc:4 ; +uint16_t noi:12 ; +uint8_t reserved3:2 ; +uint8_t aibvo:6 ; +uint8_t s:1 ; +uint8_t reserved4:1 ; +uint8_t aisbo:6 ; +uint32_t reserved5; +uint64_t aibv; +uint64_t aisb; +uint64_t fmba; +uint32_t reserved6[2 ]; +}; +typedef struct PciFib PciFib ; + +struct PciDevice { +uint16_t device_id; +uint16_t vendor_id; +uint32_t fid; +uint32_t fhandle; +uint8_t status; +PciFib fib; +}; +typedef struct PciDevice PciDevice ; + +int pci_write (uint32_t fhandle,uint64_t offset,uint64_t data,uint8_t len); +int pci_read (uint32_t fhandle,uint64_t offset,uint8_t picas,void *buf,uint8_t len); +uint8_t find_cap_pos (uint32_t fhandle,uint64_t cfg_type); +int pci_dev_enable (PciDevice *pcidev); +int get_fib (PciFib *fib,uint32_t fhandle); +int set_fib (PciFib *fib,uint32_t fhandle,uint8_t dma_as,uint8_t opcontrol); + +#endif pc-bios/s390-ccw/pci.c new file +10
-0@@ -0,0 +1,191 @@ +/* +* s390x PCI funcionality +* +* Copyright 2025 IBM Corp. +* Author(s): Jared Rossi<[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "clp.h"
pc-bios/s390-ccw/pci.c line 20
Quoted 10 lines
pc-bios/s390-ccw/pci.c new file +10
-0+#include "pci.h" +#include <stdio.h> + +/* PCI load */ +static inline int pcilg (uint64_t *data,uint64_t req,uint64_t offset,uint8_t *status) +{ +union register_pair req_off = {.even = req, .odd = offset}; +int cc =-1 ; +uint64_t __data =0x92 ; +
Why is __data initialized to 0x92?
Quoted 52 lines
pc-bios/s390-ccw/pci.c new file +52
-0+ asmvolatile ( +" .insn rre,0xb9d20000,%[data],%[req_off]\n" +" ipm %[cc]\n" +" srl %[cc],28\n" + : [cc]"+d" (cc), [data]"=d" (__data), + [req_off]"+&d" (req_off.pair) ::"cc" ); + *status = req_off.even >>24 &0xff ; + *data = __data; +return cc; +} + +/* PCI store */ +int pcistg (uint64_t data,uint64_t req,uint64_t offset,uint8_t *status) +{ +union register_pair req_off = {.even = req, .odd = offset}; +int cc =-1 ; + + asmvolatile ( +" .insn rre,0xb9d00000,%[data],%[req_off]\n" +" ipm %[cc]\n" +" srl %[cc],28\n" + : [cc]"+d" (cc), [req_off]"+&d" (req_off.pair) + : [data]"d" (data) + :"cc" ); + *status = req_off.even >>24 &0xff ; +return cc; +} + +/* store PCI function controls */ +int stpcifc (uint64_t req,PciFib *fib,uint8_t *status) +{ +uint8_t cc; + + asmvolatile ( +" .insn rxy,0xe300000000d4,%[req],%[fib]\n" +" ipm %[cc]\n" +" srl %[cc],28\n" + : [cc]"=d" (cc), [req]"+d" (req), [fib]"+Q" (*fib) + : :"cc" ); + *status = req >>24 &0xff ; +return cc; +} + +/* modify PCI function controls */ +int mpcifc (uint64_t req,PciFib *fib,uint8_t *status) +{ +uint8_t cc; + + asmvolatile ( +" .insn rxy,0xe300000000d0,%[req],%[fib]\n" +" ipm %[cc]\n" + " srl %[cc],28\n"
pc-bios/s390-ccw/pci.c line 82
Quoted 10 lines
pc-bios/s390-ccw/pci.c new file +10
-0+ : [cc] "=d" (cc), [req] "+d" (req), [fib] "+Q" (*fib) + : : "cc"); + *status = req >>24 &0xff ; +return cc; +} + +int pci_write (uint32_t fhandle,uint64_t offset,uint64_t data,uint8_t len) +{ + +uint64_t req =ZPCI_CREATE_REQ (fhandle,4 , len);
This assumes that we will only read to BAR 4? I think we should pass the PCIAS here as well if we want to generalize this function?
Quoted 17 lines
pc-bios/s390-ccw/pci.c new file +17
-0+uint8_t status; +int rc; + + rc =pcistg (data, req, offset, &status); +if (rc ==1 ) { +return status; + }else if (rc) { +return rc; + } + +return 0 ; +} + +int pci_read (uint32_t fhandle,uint64_t offset,uint8_t picas,void *buf,uint8_t len) +{ +uint64_t req; +uint64_t data;
pc-bios/s390-ccw/pci.c line 109
Quoted 10 lines
pc-bios/s390-ccw/pci.c new file +10
-0+uint8_t status; +int readlen; +int i =0 ; +int rc =0 ; + +while (len >0 && !rc) { + data =0 ; + readlen = len >8 ?8 : len; + req =ZPCI_CREATE_REQ (fhandle, picas, readlen); + rc =pcilg (&data, req, offset + (i *8 ), &status);
Shouldn't this be offset + (i * readlen)? but I guess this works because we will only increment i on reads greater than 8 bytes. Maybe we could try to simplify this and have a single pci_read function and several other helper functions that uses pci_read to read sizes of 1/2/4/8 bytes. For reads greater than 8 bytes we can have another function (similar to zpci_memcpy_from_io, in the kernel). From what I can tell most of the pci_read calls reads are 8 bytes in the rest of the patches, except maybe for one case which reads greater than 8?
Quoted 16 lines
pc-bios/s390-ccw/pci.c new file +16
-0+ ((uint64_t *)buf)[i] = data; + len -= readlen; + i++; + } + +if (rc ==1 ) { +return status; + }else if (rc) { +return rc; + } + +return 0 ; +} + +/* +* Find the position of the capability config within PCI configuration
pc-bios/s390-ccw/pci.c line 135
Quoted 10 lines
pc-bios/s390-ccw/pci.c new file +10
-0+* space for a given cfg type. Return the position if found, otherwise 0. +*/ +uint8_t find_cap_pos (uint32_t fhandle,uint64_t cfg_type) { +uint64_t req, next, cfg; +uint8_t status; +int rc; + + req =ZPCI_CREATE_REQ (fhandle,0xf ,1 ); + rc =pcilg (&next, req,PCI_CAPABILITY_LIST , &status); + rc =pcilg (&cfg, req, next +3 , &status);
Why are we reading next + 3 into cfg? If I understand this correctly next will be the address of the first capability in the linked list, and so we should just read the first byte from next to get the capability id? I think we should have helper function like qpci_find_capability to find the capabilities?
pc-bios/s390-ccw/pci.c line 139
Quoted 4 lines
pc-bios/s390-ccw/pci.c new file +4
-0+ +while (!rc && (cfg != cfg_type) && next) { + rc =pcilg (&next, req, next +1 , &status); + rc =pcilg (&cfg, req, next +3 , &status);
Same question here?
Quoted 5 lines
pc-bios/s390-ccw/pci.c new file +5
-0+ } + +return rc ?0 : next; +} +
[..snip..]
Re: [PATCH 4/7] pc-bios/s390-ccw: Introduce PCI device IPL format
Quoted 24 lines · Farhan Ali
pc-bios/s390-ccw/pci.c line 135
Quoted 12 lines
+ * Find the position of the capability config within PCI configuration
+ * space for a given cfg type. Return the position if found, otherwise 0.
+ */pc-bios/s390-ccw/pci.c new file +8
-0+uint8_t find_cap_pos (uint32_t fhandle,uint64_t cfg_type) { + uint64_t req, next, cfg; + uint8_t status; + int rc; + + req = ZPCI_CREATE_REQ(fhandle, 0xf, 1); + rc = pcilg(&next, req, PCI_CAPABILITY_LIST, &status); + rc = pcilg(&cfg, req, next + 3, &status);Why are we reading next + 3 into cfg? If I understand this correctly next will be the address of the first capability in the linked list, and so we should just read the first byte from next to get the capability id? I think we should have helper function like
qpci_find_capabilityto find the capabilities?Quoted 4 lines
+
+ while (!rc && (cfg !=cfg_type) && next) { + rc =pcilg(&next, req, next + 1, &status); + rc =pcilg(&cfg, req, next + 3, &status);Same question here?
Quoted 8 lines
Quoted 5 lines
+ }
pc-bios/s390-ccw/pci.c new file +4
-0+ + return rc ? 0 : next; +} +[..snip..]
Ah I see in patch 5 we are using this function to get virtio config type, which is a vendor specific capability and according to spec the virtio config type is defined in the 4th byte. Maybe we could just move the function to virtio-pci.c? I would expect a function defined here will try to find a specific PCI capability by searching through the PCI capability list.
Thanks
Farhan
Re: [PATCH 4/7] pc-bios/s390-ccw: Introduce PCI device IPL format
In reply to Farhan AliThanks Farhan,
Quoted 9 lines · Farhan Ali
[snip]
pc-bios/s390-ccw/pci.c line 82
Quoted 6 lines
(quoted diff) +2
-0+ +int pci_write(uint32_t fhandle, uint64_t offset, uint64_t data,
uint8_tlen)pc-bios/s390-ccw/pci.c new file +3
-0+{ + + uint64_t req = ZPCI_CREATE_REQ(fhandle, 4, len);This assumes that we will only read to BAR 4? I think we should pass the PCIAS here as well if we want to generalize this function?
I was thinking about this too and I agree that it should be generalized. Also when reading the capabilities from the configuration space, I did not check that the location is, actually, BAR 4. I will generalize the functions so that we do not make any assumptions about BAR 4.
Quoted 23 lines
Quoted 23 lines
+
uint8_tstatus;
+ int rc;pc-bios/s390-ccw/pci.c new file +12
-0+ + rc = pcistg(data, req, offset, &status); + if (rc == 1) { + return status; + } else if (rc) { + return rc; + } + + return 0; +} + +int pci_read(uint32_t fhandle, uint64_t offset, uint8_t picas, void*buf,
uint8_tlen)
+{
+uint64_treq;
+uint64_tdata;
+uint8_tstatus;
+ int readlen;
+ int i = 0;
+ int rc = 0;
Quoted 8 lines
Quoted 6 lines
+
+ while (len > 0 && !rc) {
+ data = 0;
+ readlen = len > 8 ? 8 : len;
+ req =ZPCI_CREATE_REQ(fhandle, picas, readlen); + rc =pcilg(&data, req, offset + (i * 8), &status);Shouldn't this be offset + (i * readlen)? but I guess this works because we will only increment i on reads greater than 8 bytes. Maybe we could try to simplify this and have a single
pci_readfunction and several other helper functions that usespci_readto read sizes of 1/2/4/8 bytes. For reads greater than 8 bytes we can have another function (similar tozpci_memcpy_from_io, in the kernel). From what I can tell most of thepci_readcalls reads are 8 bytes in the rest of the patches, except maybe for one case which reads greater than 8?
Yes I agree. Thomas mentioned something similar. I think using some helper functions will make the code easier to read also.
Quoted 32 lines
Quoted 20 lines
+ ((
uint64_t*)buf)[i] = data;
+ len -= readlen;
+ i++;
+ }pc-bios/s390-ccw/pci.c new file +13
-0+ + if (rc == 1) { + return status; + } else if (rc) { + return rc; + } + + return 0; +} + +/* +* Find the position of the capability config within PCI configuration +* space for a given cfg type. Return the position if found, otherwise 0.
+ */pc-bios/s390-ccw/pci.c line 135
Quoted 8 lines
pc-bios/s390-ccw/pci.c new file +8
-0+uint8_t find_cap_pos (uint32_t fhandle,uint64_t cfg_type) { + uint64_t req, next, cfg; + uint8_t status; + int rc; + + req = ZPCI_CREATE_REQ(fhandle, 0xf, 1); + rc = pcilg(&next, req, PCI_CAPABILITY_LIST, &status); + rc = pcilg(&cfg, req, next + 3, &status);Why are we reading next + 3 into cfg? If I understand this correctly next will be the address of the first capability in the linked list, and so we should just read the first byte from next to get the capability id? I think we should have helper function like
qpci_find_capabilityto find the capabilities?
Quoted 6 lines
Quoted 4 lines
+
+ while (!rc && (cfg !=cfg_type) && next) { + rc =pcilg(&next, req, next + 1, &status); + rc =pcilg(&cfg, req, next + 3, &status);Same question here?
I see you already answered this yourself in a follow-up mail, but you are correct that this is for the vendor-specific capabilities. I will move it to virtio-pci.c and add a comment for clarity.
Quoted 9 lines
Quoted 6 lines
+ }
pc-bios/s390-ccw/pci.c new file +4
-0+ + return rc ? 0 : next; +} +[..snip..]
Regards,
Jared Rossi
PATCH 5/7 pc-bios/s390-ccw: Add support for virtio-blk-pci IPL
In reply to [email protected]From: Jared Rossi <[email protected]>
Enable virt-queue PCI configuration and add routines for virtio-blk-pci devices.
--- pc-bios/s390-ccw/clp.h | 2 +- pc-bios/s390-ccw/virtio-pci.h | 73 +++++++ pc-bios/s390-ccw/virtio.h | 1 + pc-bios/s390-ccw/main.c | 59 ++++- pc-bios/s390-ccw/virtio-blkdev.c | 3 + pc-bios/s390-ccw/virtio-pci.c | 357 +++++++++++++++++++++++++++++++ pc-bios/s390-ccw/virtio.c | 5 + pc-bios/s390-ccw/Makefile | 2 +- 8 files changed, 498 insertions(+), 4 deletions(-) create mode 100644 pc-bios/s390-ccw/virtio-pci.h create mode 100644 pc-bios/s390-ccw/virtio-pci.c
pc-bios/s390-ccw/clp.h +1 -1
@@ -19,6 +19,6 @@int clp_pci (void *data);int enable_pci_function (uint32_t *fhandle); -int enumerate_pci_functions (void ); +int find_pci_function (uint32_t fid,ClpFhListEntry *entry);#endif
pc-bios/s390-ccw/virtio-pci.h new file +73 -0
73 lines not on this page · raw message
pc-bios/s390-ccw/virtio.h +1 -0
@@ -259,6 +259,7 @@ struct VDev {uint8_t scsi_dev_heads;bool scsi_device_selected;ScsiDevice selected_scsi_device; +uint32_t pci_fh;uint32_t max_transfer;uint32_t guest_features[2 ]; };
pc-bios/s390-ccw/main.c +57 -2
91 lines not on this page · raw message
pc-bios/s390-ccw/virtio-blkdev.c +3 -0
@@ -13,6 +13,7 @@#include "virtio.h" #include "virtio-ccw.h" #include "virtio-scsi.h" +#include "virtio-pci.h" #define VIRTIO_BLK_F_GEOMETRY (1 << 4)#define VIRTIO_BLK_F_BLK_SIZE (1 << 6)
@@ -243,6 +244,8 @@ int virtio_blk_setup_device()case S390_IPL_TYPE_CCW : vdev->schid = blk_schid;return virtio_ccw_setup (vdev); +case S390_IPL_TYPE_PCI : +return virtio_pci_setup (vdev); }return 1 ;
pc-bios/s390-ccw/virtio-pci.c new file +357 -0
357 lines not on this page · raw message
pc-bios/s390-ccw/virtio.c +5 -0
@@ -14,6 +14,7 @@#include "virtio.h" #include "virtio-scsi.h" #include "virtio-ccw.h" +#include "virtio-pci.h" #include "bswap.h" #include "helper.h" #include "s390-time.h"
@@ -97,6 +98,8 @@ bool vring_notify(VRing *vr)case S390_IPL_TYPE_QEMU_SCSI :case S390_IPL_TYPE_CCW : vr->cookie =virtio_ccw_notify (vr->schid, vr->id, vr->cookie); +case S390_IPL_TYPE_PCI : + vr->cookie =virtio_pci_notify (virtio_get_device ()->pci_fh, vr->id); }return vr->cookie >=0 ;
@@ -181,6 +184,8 @@ int virtio_reset(VDev *vdev)case S390_IPL_TYPE_QEMU_SCSI :case S390_IPL_TYPE_CCW :return virtio_ccw_reset (vdev); +case S390_IPL_TYPE_PCI : +return virtio_pci_reset (vdev); }return -1 ;
pc-bios/s390-ccw/Makefile +1 -1
@@ -35,7 +35,7 @@ QEMU_DGFLAGS = -MMD -MP -MT $@ -MF $(@D)/$(*F).d OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o menu.o netmain.o \ virtio.o virtio-net.o virtio-scsi.o virtio-blkdev.o cio.o dasd-ipl.o \ - virtio-ccw.o clp.o pci.o + virtio-ccw.o clp.o pci.o virtio-pci.o SLOF_DIR := $(SRC_PATH)/../../roms/SLOF
Signature · 1 line
2.49.0
Re: [PATCH 5/7] pc-bios/s390-ccw: Add support for virtio-blk-pci IPL
Quoted 6 lines · On 20/10/2025 18.20, [email protected] wrote:
From: Jared Rossi <[email protected]>
Enable virt-queue PCI configuration and add routines for virtio-blk-pci devices.
Signed-off-by Jared Rossi <[email protected]>---
...
Quoted 28 lines
pc-bios/s390-ccw/virtio.h +1
-0@@ -259,6 +259,7 @@ struct VDev {uint8_t scsi_dev_heads;bool scsi_device_selected;ScsiDevice selected_scsi_device; +uint32_t pci_fh;uint32_t max_transfer;uint32_t guest_features[2 ]; };pc-bios/s390-ccw/main.c +2
-0@@ -15,8 +15,10 @@#include "s390-arch.h" #include "s390-ccw.h" #include "cio.h" +#include "clp.h" #include "virtio.h" #include "virtio-scsi.h" +#include "virtio-pci.h" #include "dasd-ipl.h" SubChannelId blk_schid = { .one =1 };
pc-bios/s390-ccw/main.c static bool find_subch(int dev_no) · line 155
Quoted 4 lines
pc-bios/s390-ccw/main.c +1
-0@@ -150,6 +152,20 @@ static bool find_subch(int dev_no)return false; } +static bool find_fid (uint32_t fid) {
Put the curly bracket into the next line, please.
pc-bios/s390-ccw/main.c static bool find_subch(int dev_no) · line 166
Quoted 11 lines
pc-bios/s390-ccw/main.c +11
-0+ClpFhListEntry entry; +VDev *vdev =virtio_get_device (); + +if (find_pci_function (fid, &entry)) { +return false; + } + + vdev->pci_fh = entry.fh; +virtio_pci_id2type (vdev, entry.device_id); + +return (vdev->type !=0 );
You could drop the braces here.
Quoted 2 lines
pc-bios/s390-ccw/main.c +2
-0+} +
...
Quoted 41 lines
pc-bios/s390-ccw/virtio-pci.c new file +35
-0@@ -0,0 +1,357 @@ +/* +* Functionality for virtio-pci +* +* Copyright 2025 IBM Corp. +* Author(s): Jared Rossi <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "clp.h" +#include "pci.h" +#include "helper.h" +#include "s390-ccw.h" +#include "virtio.h" +#include "bswap.h" +#include "virtio-pci.h" +#include "s390-time.h" +#include <stdio.h> + +/* Variable offsets used for reads/writes to modern memory region BAR 4 */ +uint32_t common_offset; +uint32_t device_offset; +uint32_t notify_offset; +uint32_t notify_mult; +uint16_t q_notify_offset; + +static int virtio_pci_set_status (VDev *vdev,uint8_t status) +{ +uint64_t status64 = status; + +return pci_write (vdev->pci_fh,VPCI_C_OFFSET_STATUS , status64,1 ); +} + +static int virtio_pci_get_status (VDev *vdev,uint8_t *status) +{
pc-bios/s390-ccw/virtio-pci.c line 45
Quoted 10 lines
pc-bios/s390-ccw/virtio-pci.c new file +10
-0+uint64_t status64; +int rc; + + rc =pci_read (vdev->pci_fh,VPCI_C_OFFSET_STATUS ,4 , &status64,1 ); +if (rc) { +puts ("Failed to read virtio-pci status" ); +return rc; + } + + *status = (uint8_t ) status64;
Ok, so after reading this code, I realized that pci_read is definitely only supposed to work on 64-bit values.
Could you please change the "buf" parameter of pci_read() from "void *" to "uint64_t *", otherwise this is super-confusing.
Quoted 23 lines
pc-bios/s390-ccw/virtio-pci.c new file +23
-0+return 0 ; +} + +static int virtio_pci_get_hfeatures (VDev *vdev,uint64_t *features) +{ +uint64_t feat0, feat1; +uint32_t selector; +int rc; + + selector =bswap32 (0 ); + rc =pci_write (vdev->pci_fh,VPCI_C_OFFSET_DFSELECT , selector,4 ); + rc |=pci_read (vdev->pci_fh,VPCI_C_OFFSET_DF ,4 , &feat0,4 ); + feat0 =bswap32 (feat0); +> + selector = bswap32(1); + rc |=pci_write (vdev->pci_fh,VPCI_C_OFFSET_DFSELECT , selector,4 ); + rc |=pci_read (vdev->pci_fh,VPCI_C_OFFSET_DF ,4 , &feat1,4 ); + feat1 =bswap32 (feat1); +> + *features = feat1 << 32; + *features |= feat0; + +return rc; +} +
pc-bios/s390-ccw/virtio-pci.c line 80
Quoted 10 lines
pc-bios/s390-ccw/virtio-pci.c new file +10
-0+static int virtio_pci_set_gfeatures (VDev *vdev) +{ +uint64_t feats; +uint32_t selector; +int rc; + + selector =bswap32 (0 ); + rc =pci_write (vdev->pci_fh,VPCI_C_OFFSET_GFSELECT , selector,4 ); + + feats =bswap32 ((uint64_t )vdev->guest_features[1 ]);
The cast to 64-bit does not make sense here.
pc-bios/s390-ccw/virtio-pci.c line 86
Quoted 6 lines
pc-bios/s390-ccw/virtio-pci.c new file +6
-0+ rc |=pci_write (vdev->pci_fh,VPCI_C_OFFSET_GF , feats,4 ); + + selector =bswap32 (1 ); + rc |=pci_write (vdev->pci_fh,VPCI_C_OFFSET_GFSELECT , selector,4 ); + + feats =bswap32 ((uint64_t )vdev->guest_features[0 ]);
dito
pc-bios/s390-ccw/virtio-pci.c line 96
Quoted 10 lines
pc-bios/s390-ccw/virtio-pci.c new file +10
-0+ rc |=pci_write (vdev->pci_fh,VPCI_C_OFFSET_GF , feats,4 ); + +return rc; +} + +static int virtio_pci_get_blk_config (VDev *vdev) +{ +return pci_read (vdev->pci_fh, device_offset,4 , (uint64_t *)&vdev->config.blk, +sizeof (VirtioBlkConfig)); +
Please remove the empty line.
pc-bios/s390-ccw/virtio-pci.c line 104
Quoted 8 lines
pc-bios/s390-ccw/virtio-pci.c new file +8
-0+} + +int virtio_pci_set_selected_vq (VDev *vdev,uint16_t queue_num) +{ +uint16_t le_queue_num; + + le_queue_num =bswap16 (queue_num); +return pci_write (vdev->pci_fh,VPCI_C_OFFSET_Q_SELECT , (uint64_t )le_queue_num,2 );
The "(uint64_t)" is not required here, I think.
pc-bios/s390-ccw/virtio-pci.c line 112
Quoted 8 lines
pc-bios/s390-ccw/virtio-pci.c new file +8
-0+} + +int virtio_pci_set_queue_size (VDev *vdev,uint16_t queue_size) +{ +uint16_t le_queue_size; + + le_queue_size =bswap16 (queue_size); +return pci_write (vdev->pci_fh,VPCI_C_OFFSET_Q_SIZE , (uint64_t )le_queue_size,2 );
dito
pc-bios/s390-ccw/virtio-pci.c line 120
Quoted 8 lines
pc-bios/s390-ccw/virtio-pci.c new file +8
-0+} + +static int virtio_pci_set_queue_enable (VDev *vdev,uint16_t enabled) +{ +uint16_t le_enabled; + + le_enabled =bswap16 (enabled); +return pci_write (vdev->pci_fh,VPCI_C_OFFSET_Q_ENABLE , (uint64_t )le_enabled,2 );
dito
Quoted 6 lines
pc-bios/s390-ccw/virtio-pci.c new file +6
-0+} + +static int set_pci_vq_addr (VDev *vdev,void * addr,uint64_t config_offset_lo) +{ +uint32_t le_lo, le_hi; +uint32_t tmp;
pc-bios/s390-ccw/virtio-pci.c line 136
Quoted 10 lines
pc-bios/s390-ccw/virtio-pci.c new file +10
-0+int rc; + + tmp = (uint32_t )(((uint64_t )addr) >>32 ); + le_hi =bswap32 (tmp); + + tmp = (uint32_t )((uint64_t )addr &0xFFFFFFFF ); + le_lo =bswap32 (tmp); + + rc =pci_write (vdev->pci_fh, config_offset_lo, (uint64_t )le_lo,4 ); + rc |=pci_write (vdev->pci_fh, config_offset_lo +4 , (uint64_t )le_hi,4 );
Wouldn't it be possible bswap64() the value and write all 8 bytes at once?
Quoted 60 lines
pc-bios/s390-ccw/virtio-pci.c new file +60
-0+return rc; +} + +/* virtio spec v1.1 para 4.1.2.1 */ +void virtio_pci_id2type (VDev *vdev,uint16_t device_id) +{ +switch (device_id) { +case 0x1001 : + vdev->type =VIRTIO_ID_BLOCK ; +break ; +case 0x1000 :/* Other valid but currently unsupported virtio device types */ +case 0x1004 : +default : + vdev->type =0 ; + } +} + +/* +* Read PCI configuration space to find the offset of the Common, Device, and +* Notification memory regions within the modern memory space. +* Returns 0 if success, 1 if a capability could not be located, or a +* negative RC if the configuration read failed. +*/ +static int virtio_pci_read_pci_cap_config (VDev *vdev) +{ +uint8_t pos; +uint64_t data; + +/* Common cabilities */ + pos =find_cap_pos (vdev->pci_fh,VIRTIO_PCI_CAP_COMMON_CFG ); +if (!pos) { +puts ("Failed to locate PCI common configuration" ); +return 1 ; + } +if (pci_read (vdev->pci_fh, pos +VIRTIO_PCI_CAP_OFFSET ,15 , &data,4 )) { +return -EIO ; + } + common_offset =bswap32 (data); + +/* Device cabilities */ + pos =find_cap_pos (vdev->pci_fh,VIRTIO_PCI_CAP_DEVICE_CFG ); +if (!pos) { +puts ("Failed to locate PCI device configuration" ); +return 1 ; + } +if (pci_read (vdev->pci_fh, pos +VIRTIO_PCI_CAP_OFFSET ,15 , &data,4 )) { +return -EIO ; + } + device_offset =bswap32 (data); + +/* Notification cabilities */ + pos =find_cap_pos (vdev->pci_fh,VIRTIO_PCI_CAP_NOTIFY_CFG ); +if (!pos) { +puts ("Failed to locate PCI notification configuration" ); +return 1 ; + } +if (pci_read (vdev->pci_fh, pos +VIRTIO_PCI_CAP_OFFSET ,15 , &data,4 )) { +return -EIO ; + } + notify_offset =bswap32 (data);
pc-bios/s390-ccw/virtio-pci.c line 207
Quoted 10 lines
pc-bios/s390-ccw/virtio-pci.c new file +10
-0+ +if (pci_read (vdev->pci_fh, pos +VIRTIO_PCI_NOTIFY_CAP_MULT ,15 , &data,4 )) { +return -EIO ; + } + notify_mult =bswap32 (data); + +if (pci_read (vdev->pci_fh, device_offset +VPCI_C_OFFSET_Q_NOFF ,4 , &data,2 )) { +return -EIO ; + } + q_notify_offset =bswap16 (data);
After reading all this code, I wonder whether it would make sense to have proper pci_read16(), pci_read32() and pci_read64() functions that do also the byte-swapping for you and operate on the right size of variable size?
Quoted 4 lines
pc-bios/s390-ccw/virtio-pci.c new file +4
-0+return 0 ; +} + +int virtio_pci_reset (VDev *vdev)
pc-bios/s390-ccw/virtio-pci.c line 222
Quoted 10 lines
pc-bios/s390-ccw/virtio-pci.c new file +10
-0+{ +int rc; +uint8_t status =VPCI_S_RESET ; + + rc =virtio_pci_set_status (vdev, status); + rc |=virtio_pci_get_status (vdev, &status); + +if (rc || status) { +puts ("Failed to reset virtio-pci device" ); +return 1 ;
Maybe nicer to return a negative error code (-1 if nothing else fits)?
pc-bios/s390-ccw/virtio-pci.c line 47
Quoted 4 lines
pc-bios/s390-ccw/virtio-pci.c new file +4
-0+ } + +return 0 ; +}
Thomas
Re: [PATCH 5/7] pc-bios/s390-ccw: Add support for virtio-blk-pci IPL
In reply to [email protected]Quoted 439 lines · On 10/20/25 12:20 PM, [email protected] wrote:
From: Jared Rossi <[email protected]>
Enable virt-queue PCI configuration and add routines for virtio-blk-pci devices.
Signed-off-by Jared Rossi <[email protected]>--- pc-bios/s390-ccw/clp.h | 2 +- pc-bios/s390-ccw/virtio-pci.h | 73 +++++++ pc-bios/s390-ccw/virtio.h | 1 + pc-bios/s390-ccw/main.c | 59 ++++- pc-bios/s390-ccw/virtio-blkdev.c | 3 + pc-bios/s390-ccw/virtio-pci.c | 357 +++++++++++++++++++++++++++++++ pc-bios/s390-ccw/virtio.c | 5 + pc-bios/s390-ccw/Makefile | 2 +- 8 files changed, 498 insertions(+), 4 deletions(-) create mode 100644 pc-bios/s390-ccw/virtio-pci.h create mode 100644 pc-bios/s390-ccw/virtio-pci.cpc-bios/s390-ccw/clp.h +1
-1@@ -19,6 +19,6 @@int clp_pci (void *data);int enable_pci_function (uint32_t *fhandle); -int enumerate_pci_functions (void ); +int find_pci_function (uint32_t fid,ClpFhListEntry *entry);#endif pc-bios/s390-ccw/virtio-pci.h new file +73
-0@@ -0,0 +1,73 @@ +/* +* Definitions for virtio-pci +* +* Copyright 2025 IBM Corp. +* Author(s): Jared Rossi <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef VIRTIO_PCI_H +#define VIRTIO_PCI_H + +/* Common configuration */ +#define VIRTIO_PCI_CAP_COMMON_CFG 1 +/* Notifications */ +#define VIRTIO_PCI_CAP_NOTIFY_CFG 2 +/* ISR access */ +#define VIRTIO_PCI_CAP_ISR_CFG 3 +/* Device specific configuration */ +#define VIRTIO_PCI_CAP_DEVICE_CFG 4 +/* PCI configuration access */ +#define VIRTIO_PCI_CAP_PCI_CFG 5 +/* Additional shared memory capability */ +#define VIRTIO_PCI_CAP_SHARED_MEMORY_CFG 8 +/* PCI vendor data configuration */ +#define VIRTIO_PCI_CAP_VENDOR_CFG 9 + +/* Offsets within capability header */ +#define VIRTIO_PCI_CAP_VNDR 0 +#define VIRTIO_PCI_CAP_NEXT 1 +#define VIRTIO_PCI_CAP_LEN 2 +#define VIRTIO_PCI_CAP_CFG_TYPE 3 +#define VIRTIO_PCI_CAP_BAR 4 +#define VIRTIO_PCI_CAP_OFFSET 8 +#define VIRTIO_PCI_CAP_LENGTH 12 + +#define VIRTIO_PCI_NOTIFY_CAP_MULT 16/* VIRTIO_PCI_CAP_NOTIFY_CFG only */ + +/* Common Area Offsets for virtio-pci queue */ +#define VPCI_C_OFFSET_DFSELECT 0 +#define VPCI_C_OFFSET_DF 4 +#define VPCI_C_OFFSET_GFSELECT 8 +#define VPCI_C_OFFSET_GF 12 +#define VPCI_C_COMMON_NUMQ 18 +#define VPCI_C_OFFSET_STATUS 20 +#define VPCI_C_OFFSET_Q_SELECT 22 +#define VPCI_C_OFFSET_Q_SIZE 24 +#define VPCI_C_OFFSET_Q_ENABLE 28 +#define VPCI_C_OFFSET_Q_NOFF 30 +#define VPCI_C_OFFSET_Q_DESCLO 32 +#define VPCI_C_OFFSET_Q_DESCHI 36 +#define VPCI_C_OFFSET_Q_AVAILLO 40 +#define VPCI_C_OFFSET_Q_AVAILHI 44 +#define VPCI_C_OFFSET_Q_USEDLO 48 +#define VPCI_C_OFFSET_Q_USEDHI 52 + +#define VPCI_S_RESET 0 +#define VPCI_S_ACKNOWLEDGE 1 +#define VPCI_S_DRIVER 2 +#define VPCI_S_DRIVER_OK 4 +#define VPCI_S_FEATURES_OK 8 + +#define VIRTIO_F_VERSION_1 (1 << (32 - 32))/* Feature bit 32 */ + +#define VIRT_Q_SIZE 16 + +long virtio_pci_notify (uint32_t fhandle,int vq_id); +int virtio_pci_setup (VDev *vdev); +int virtio_pci_setup_device (void ); +int virtio_pci_reset (VDev *vdev); +void virtio_pci_id2type (VDev *vdev,uint16_t device_id); + +#endif pc-bios/s390-ccw/virtio.h +1
-0@@ -259,6 +259,7 @@ struct VDev {uint8_t scsi_dev_heads;bool scsi_device_selected;ScsiDevice selected_scsi_device; +uint32_t pci_fh;uint32_t max_transfer;uint32_t guest_features[2 ]; };pc-bios/s390-ccw/main.c +57
-2@@ -15,8 +15,10 @@#include "s390-arch.h" #include "s390-ccw.h" #include "cio.h" +#include "clp.h" #include "virtio.h" #include "virtio-scsi.h" +#include "virtio-pci.h" #include "dasd-ipl.h" SubChannelId blk_schid = { .one =1 };@@ -150,6 +152,20 @@ static bool find_subch(int dev_no)return false; } +static bool find_fid (uint32_t fid) { +ClpFhListEntry entry; +VDev *vdev =virtio_get_device (); + +if (find_pci_function (fid, &entry)) { +return false; + } + + vdev->pci_fh = entry.fh; +virtio_pci_id2type (vdev, entry.device_id); + +return (vdev->type !=0 ); +} +static void menu_setup (void ) {if (memcmp (loadparm_str,LOADPARM_PROMPT ,LOADPARM_LEN ) ==0 ) {@@ -233,6 +249,9 @@ static bool find_boot_device(void) blk_schid.ssid = iplb.scsi.ssid &0x3 ; found =find_subch (iplb.scsi.devno);break ; +case S390_IPL_TYPE_PCI : + found =find_fid (iplb.pci.fid); +break ;default :puts ("Unsupported IPLB" ); }@@ -269,7 +288,7 @@ static int virtio_setup(void)return ret; } -static void ipl_boot_device (void ) +static void ipl_ccw_device (void ) {switch (cutype) {case CU_TYPE_DASD_3990 :@@ -282,7 +301,43 @@ static void ipl_boot_device(void) }break ;default : -printf ("Attempting to boot from unexpected device type 0x%X\n" , cutype); +printf ("Cannot boot CCW device with cu type 0x%X\n" , cutype); + } +} + +static void ipl_pci_device (void ) +{ +VDev *vdev =virtio_get_device (); + vdev->is_cdrom = false; + vdev->scsi_device_selected = false; + +if (virtio_pci_setup_device ()) { +return ; + } + +switch (vdev->type) { +case VIRTIO_ID_BLOCK : +if (virtio_setup () ==0 ) { +zipl_load (); + } +break ; +default : +printf ("Cannot boot PCI device type 0x%X\n" , vdev->type); + } +} + +static void ipl_boot_device (void ) +{ +switch (ipl_type) { +case S390_IPL_TYPE_QEMU_SCSI : +case S390_IPL_TYPE_CCW : +ipl_ccw_device (); +break ; +case S390_IPL_TYPE_PCI : +ipl_pci_device (); +break ; +default : +puts ("Unrecognized IPL type!" ); } }pc-bios/s390-ccw/virtio-blkdev.c +3
-0@@ -13,6 +13,7 @@#include "virtio.h" #include "virtio-ccw.h" #include "virtio-scsi.h" +#include "virtio-pci.h" #define VIRTIO_BLK_F_GEOMETRY (1 << 4)#define VIRTIO_BLK_F_BLK_SIZE (1 << 6)@@ -243,6 +244,8 @@ int virtio_blk_setup_device()case S390_IPL_TYPE_CCW : vdev->schid = blk_schid;return virtio_ccw_setup (vdev); +case S390_IPL_TYPE_PCI : +return virtio_pci_setup (vdev); }return 1 ;pc-bios/s390-ccw/virtio-pci.c new file +191
-0@@ -0,0 +1,357 @@ +/* +* Functionality for virtio-pci +* +* Copyright 2025 IBM Corp. +* Author(s): Jared Rossi <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "clp.h" +#include "pci.h" +#include "helper.h" +#include "s390-ccw.h" +#include "virtio.h" +#include "bswap.h" +#include "virtio-pci.h" +#include "s390-time.h" +#include <stdio.h> + +/* Variable offsets used for reads/writes to modern memory region BAR 4 */ +uint32_t common_offset; +uint32_t device_offset; +uint32_t notify_offset; +uint32_t notify_mult; +uint16_t q_notify_offset; + +static int virtio_pci_set_status (VDev *vdev,uint8_t status) +{ +uint64_t status64 = status; + +return pci_write (vdev->pci_fh,VPCI_C_OFFSET_STATUS , status64,1 ); +} + +static int virtio_pci_get_status (VDev *vdev,uint8_t *status) +{ +uint64_t status64; +int rc; + + rc =pci_read (vdev->pci_fh,VPCI_C_OFFSET_STATUS ,4 , &status64,1 ); +if (rc) { +puts ("Failed to read virtio-pci status" ); +return rc; + } + + *status = (uint8_t ) status64; +return 0 ; +} + +static int virtio_pci_get_hfeatures (VDev *vdev,uint64_t *features) +{ +uint64_t feat0, feat1; +uint32_t selector; +int rc; + + selector =bswap32 (0 ); + rc =pci_write (vdev->pci_fh,VPCI_C_OFFSET_DFSELECT , selector,4 ); + rc |=pci_read (vdev->pci_fh,VPCI_C_OFFSET_DF ,4 , &feat0,4 ); + feat0 =bswap32 (feat0); + + selector =bswap32 (1 ); + rc |=pci_write (vdev->pci_fh,VPCI_C_OFFSET_DFSELECT , selector,4 ); + rc |=pci_read (vdev->pci_fh,VPCI_C_OFFSET_DF ,4 , &feat1,4 ); + feat1 =bswap32 (feat1); + + *features = feat1 <<32 ; + *features |= feat0; + +return rc; +} + +static int virtio_pci_set_gfeatures (VDev *vdev) +{ +uint64_t feats; +uint32_t selector; +int rc; + + selector =bswap32 (0 ); + rc =pci_write (vdev->pci_fh,VPCI_C_OFFSET_GFSELECT , selector,4 ); + + feats =bswap32 ((uint64_t )vdev->guest_features[1 ]); + rc |=pci_write (vdev->pci_fh,VPCI_C_OFFSET_GF , feats,4 ); + + selector =bswap32 (1 ); + rc |=pci_write (vdev->pci_fh,VPCI_C_OFFSET_GFSELECT , selector,4 ); + + feats =bswap32 ((uint64_t )vdev->guest_features[0 ]); + rc |=pci_write (vdev->pci_fh,VPCI_C_OFFSET_GF , feats,4 ); + +return rc; +} + +static int virtio_pci_get_blk_config (VDev *vdev) +{ +return pci_read (vdev->pci_fh, device_offset,4 , (uint64_t *)&vdev->config.blk, +sizeof (VirtioBlkConfig)); + +} + +int virtio_pci_set_selected_vq (VDev *vdev,uint16_t queue_num) +{ +uint16_t le_queue_num; + + le_queue_num =bswap16 (queue_num); +return pci_write (vdev->pci_fh,VPCI_C_OFFSET_Q_SELECT , (uint64_t )le_queue_num,2 ); +} + +int virtio_pci_set_queue_size (VDev *vdev,uint16_t queue_size) +{ +uint16_t le_queue_size; + + le_queue_size =bswap16 (queue_size); +return pci_write (vdev->pci_fh,VPCI_C_OFFSET_Q_SIZE , (uint64_t )le_queue_size,2 ); +} + +static int virtio_pci_set_queue_enable (VDev *vdev,uint16_t enabled) +{ +uint16_t le_enabled; + + le_enabled =bswap16 (enabled); +return pci_write (vdev->pci_fh,VPCI_C_OFFSET_Q_ENABLE , (uint64_t )le_enabled,2 ); +} + +static int set_pci_vq_addr (VDev *vdev,void * addr,uint64_t config_offset_lo) +{ +uint32_t le_lo, le_hi; +uint32_t tmp; +int rc; + + tmp = (uint32_t )(((uint64_t )addr) >>32 ); + le_hi =bswap32 (tmp); + + tmp = (uint32_t )((uint64_t )addr &0xFFFFFFFF ); + le_lo =bswap32 (tmp); + + rc =pci_write (vdev->pci_fh, config_offset_lo, (uint64_t )le_lo,4 ); + rc |=pci_write (vdev->pci_fh, config_offset_lo +4 , (uint64_t )le_hi,4 ); + +return rc; +} + +/* virtio spec v1.1 para 4.1.2.1 */ +void virtio_pci_id2type (VDev *vdev,uint16_t device_id) +{ +switch (device_id) { +case 0x1001 : + vdev->type =VIRTIO_ID_BLOCK ; +break ; +case 0x1000 :/* Other valid but currently unsupported virtio device types */ +case 0x1004 : +default : + vdev->type =0 ; + } +} + +/* +* Read PCI configuration space to find the offset of the Common, Device, and +* Notification memory regions within the modern memory space. +* Returns 0 if success, 1 if a capability could not be located, or a +* negative RC if the configuration read failed. +*/ +static int virtio_pci_read_pci_cap_config (VDev *vdev) +{ +uint8_t pos; +uint64_t data; + +/* Common cabilities */ + pos =find_cap_pos (vdev->pci_fh,VIRTIO_PCI_CAP_COMMON_CFG ); +if (!pos) { +puts ("Failed to locate PCI common configuration" ); +return 1 ; + } +if (pci_read (vdev->pci_fh, pos +VIRTIO_PCI_CAP_OFFSET ,15 , &data,4 )) { +return -EIO ; + } + common_offset =bswap32 (data); + +/* Device cabilities */ + pos =find_cap_pos (vdev->pci_fh,VIRTIO_PCI_CAP_DEVICE_CFG ); +if (!pos) { +puts ("Failed to locate PCI device configuration" ); +return 1 ; + } +if (pci_read (vdev->pci_fh, pos +VIRTIO_PCI_CAP_OFFSET ,15 , &data,4 )) { +return -EIO ; + } + device_offset =bswap32 (data); + +/* Notification cabilities */ + pos =find_cap_pos (vdev->pci_fh,VIRTIO_PCI_CAP_NOTIFY_CFG ); +if (!pos) { +puts ("Failed to locate PCI notification configuration" );
pc-bios/s390-ccw/virtio-pci.c line 201
Quoted 10 lines
pc-bios/s390-ccw/virtio-pci.c new file +10
-0+return 1 ; + } +if (pci_read (vdev->pci_fh, pos +VIRTIO_PCI_CAP_OFFSET ,15 , &data,4 )) { +return -EIO ; + } + notify_offset =bswap32 (data); + +if (pci_read (vdev->pci_fh, pos +VIRTIO_PCI_NOTIFY_CAP_MULT ,15 , &data,4 )) { +return -EIO ; + }
Could you please explain why we usepci_read(vdev->pci_fh, pos + VIRTIO_PCI_NOTIFY_CAP_MULT, 15, &data, 4) instead ofpci_read(vdev->pci_fh, notify_offset + VIRTIO_PCI_NOTIFY_CAP_MULT, 4, &data, 4) here?
pc-bios/s390-ccw/virtio-pci.c line 206
Quoted 5 lines
pc-bios/s390-ccw/virtio-pci.c new file +5
-0+ notify_mult =bswap32 (data); + +if (pci_read (vdev->pci_fh, device_offset +VPCI_C_OFFSET_Q_NOFF ,4 , &data,2 )) { +return -EIO ; + }
Should queue_notify_off be read using pci_read(vdev->pci_fh, common_offset + VPCI_C_OFFSET_Q_NOFF, 4, &data, 2)?
(Virtio specs v-1.3 section 4.1.4.3 Common configuration structure layout)
Quoted 138 lines
pc-bios/s390-ccw/virtio-pci.c new file +138
-0+ q_notify_offset =bswap16 (data); + +return 0 ; +} + +int virtio_pci_reset (VDev *vdev) +{ +int rc; +uint8_t status =VPCI_S_RESET ; + + rc =virtio_pci_set_status (vdev, status); + rc |=virtio_pci_get_status (vdev, &status); + +if (rc || status) { +puts ("Failed to reset virtio-pci device" ); +return 1 ; + } + +return 0 ; +} + +int virtio_pci_setup (VDev *vdev) +{ +VRing *vr; +int rc; +uint64_t pci_features, data; +uint8_t status; +int i =0 ; + + vdev->config.blk.blk_size =0 ; + vdev->guessed_disk_nature =VIRTIO_GDN_NONE ; + vdev->cmd_vr_idx =0 ; + +if (virtio_reset (vdev)) { +return -EIO ; + } + + status =VPCI_S_ACKNOWLEDGE ; + rc =virtio_pci_set_status (vdev, status); +if (rc) { +puts ("Virtio-pci device Failed to ACKNOWLEDGE" ); +return -EIO ; + } + +virtio_pci_read_pci_cap_config (vdev); +if (rc) { +printf ("Invalid PCI capabilities" ); +return -EIO ; + } + +switch (vdev->type) { +case VIRTIO_ID_BLOCK : + vdev->nr_vqs =1 ; + vdev->cmd_vr_idx =0 ; +virtio_pci_get_blk_config (vdev); +break ; +default : +puts ("Unsupported virtio device" ); +return -ENODEV ; + } + + status |=VPCI_S_DRIVER ; + rc =virtio_pci_set_status (vdev, status); +if (rc) { +puts ("Set status failed" ); +return -EIO ; + } + +/* Feature negotiation */ + rc =virtio_pci_get_hfeatures (vdev, &pci_features); +if (rc) { +puts ("Failed to get feature bits" ); +return -EIO ; + } + + rc =virtio_pci_set_gfeatures (vdev); +if (rc) { +puts ("Failed to set feature bits" ); +return -EIO ; + } + +/* Configure virt-queues for pci */ +for (i =0 ; i < vdev->nr_vqs; i++) { +VqInfo info = { + .queue = (unsigned long long )virtio_get_ring_area () + (i *VIRTIO_RING_SIZE ), + .align =KVM_S390_VIRTIO_RING_ALIGN , + .index = i, + .num =0 , + }; + + vr = &vdev->vrings[i]; + rc =pci_read (vdev->pci_fh,VPCI_C_COMMON_NUMQ ,4 , &data,2 ); +if (rc) { +return rc; + } + + info.num = data; +vring_init (vr, &info); + + rc =virtio_pci_set_selected_vq (vdev, vr->id); +if (rc) { +puts ("Failed to set selected virt-queue" ); +return -EIO ; + } + + rc =virtio_pci_set_queue_size (vdev,16 ); +if (rc) { +puts ("Failed to set virt-queue size" ); +return -EIO ; + } + + rc =set_pci_vq_addr (vdev, vr->desc,VPCI_C_OFFSET_Q_DESCLO ); + rc |=set_pci_vq_addr (vdev, vr->avail,VPCI_C_OFFSET_Q_AVAILLO ); + rc |=set_pci_vq_addr (vdev, vr->used,VPCI_C_OFFSET_Q_USEDLO ); +if (rc) { +puts ("Failed to set virt-queue address" ); +return -EIO ; + } + + rc =virtio_pci_set_queue_enable (vdev, true); +if (rc) { +puts ("Failed to set virt-queue enabled" ); +return -EIO ; + } + } + + status |=VPCI_S_FEATURES_OK |VPCI_S_DRIVER_OK ; +return virtio_pci_set_status (vdev, status); +} + +int virtio_pci_setup_device (void ) +{ +int rc; +VDev *vdev =virtio_get_device (); + + rc =enable_pci_function (&vdev->pci_fh); +if (rc) { +puts ("Failed to enable PCI function" );
pc-bios/s390-ccw/virtio-pci.c line 354
Quoted 10 lines
pc-bios/s390-ccw/virtio-pci.c new file +10
-0+return rc; + } + +return 0 ; +} + +long virtio_pci_notify (uint32_t fhandle,int vq_id) +{ +uint64_t notice =1 ; +uint32_t offset = notify_offset + vq_id * q_notify_offset;
Shoud the offset be calculated as notify_offset + q_notify_offset * notify_mult?
(Virtio specs v-1.3 section 4.1.4.4 Notification structure layout)
pc-bios/s390-ccw/virtio-pci.c line 356
Quoted 2 lines
pc-bios/s390-ccw/virtio-pci.c new file +2
-0+ +return pci_write (fhandle, offset, notice,4 );
Please correct me if I'm wrong - instead of always writing notice = 1, should we write vq_id to vq_index of the Queue Notify address. (Virtio specs v-1.3 section 4.1.5.2 Available Buffer Notifications)
Quoted 44 lines
pc-bios/s390-ccw/virtio-pci.c new file +1
-0+}pc-bios/s390-ccw/virtio.c +5
-0@@ -14,6 +14,7 @@#include "virtio.h" #include "virtio-scsi.h" #include "virtio-ccw.h" +#include "virtio-pci.h" #include "bswap.h" #include "helper.h" #include "s390-time.h" @@ -97,6 +98,8 @@ bool vring_notify(VRing *vr)case S390_IPL_TYPE_QEMU_SCSI :case S390_IPL_TYPE_CCW : vr->cookie =virtio_ccw_notify (vr->schid, vr->id, vr->cookie); +case S390_IPL_TYPE_PCI : + vr->cookie =virtio_pci_notify (virtio_get_device ()->pci_fh, vr->id); }return vr->cookie >=0 ;@@ -181,6 +184,8 @@ int virtio_reset(VDev *vdev)case S390_IPL_TYPE_QEMU_SCSI :case S390_IPL_TYPE_CCW :return virtio_ccw_reset (vdev); +case S390_IPL_TYPE_PCI : +return virtio_pci_reset (vdev); }return -1 ;pc-bios/s390-ccw/Makefile +1
-1@@ -35,7 +35,7 @@ QEMU_DGFLAGS = -MMD -MP -MT $@ -MF $(@D)/$(*F).d OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o menu.o netmain.o \ virtio.o virtio-net.o virtio-scsi.o virtio-blkdev.o cio.o dasd-ipl.o \ - virtio-ccw.o clp.o pci.o + virtio-ccw.o clp.o pci.o virtio-pci.o SLOF_DIR := $(SRC_PATH)/../../roms/SLOF
Re: [PATCH 5/7] pc-bios/s390-ccw: Add support for virtio-blk-pci IPL
Quoted 49 lines · Zhuoying Cai
[snip...]
pc-bios/s390-ccw/virtio-pci.c new file +47
-0+/* +* Read PCI configuration space to find the offset of the Common, Device, and +* Notification memory regions within the modern memory space. +* Returns 0 if success, 1 if a capability could not be located, or a +* negative RC if the configuration read failed. +*/ +static int virtio_pci_read_pci_cap_config (VDev *vdev) +{ +uint8_t pos; +uint64_t data; + +/* Common cabilities */ + pos =find_cap_pos (vdev->pci_fh,VIRTIO_PCI_CAP_COMMON_CFG ); +if (!pos) { +puts ("Failed to locate PCI common configuration" ); +return 1 ; + } +if (pci_read (vdev->pci_fh, pos +VIRTIO_PCI_CAP_OFFSET ,15 , &data,4 )) { +return -EIO ; + } + common_offset =bswap32 (data); + +/* Device cabilities */ + pos =find_cap_pos (vdev->pci_fh,VIRTIO_PCI_CAP_DEVICE_CFG ); +if (!pos) { +puts ("Failed to locate PCI device configuration" ); +return 1 ; + } +if (pci_read (vdev->pci_fh, pos +VIRTIO_PCI_CAP_OFFSET ,15 , &data,4 )) { +return -EIO ; + } + device_offset =bswap32 (data); + +/* Notification cabilities */ + pos =find_cap_pos (vdev->pci_fh,VIRTIO_PCI_CAP_NOTIFY_CFG ); +if (!pos) { +puts ("Failed to locate PCI notification configuration" ); +return 1 ; + } +if (pci_read (vdev->pci_fh, pos +VIRTIO_PCI_CAP_OFFSET ,15 , &data,4 )) { +return -EIO ; + } + notify_offset =bswap32 (data); + +if (pci_read (vdev->pci_fh, pos +VIRTIO_PCI_NOTIFY_CAP_MULT ,15 , &data,4 )) { +return -EIO ; + }
Quoted 5 lines
Could you please explain why we use
pci_read(vdev->pci_fh, pos + VIRTIO_PCI_NOTIFY_CAP_MULT, 15, &data, 4)instead ofpci_read(vdev->pci_fh, notify_offset + VIRTIO_PCI_NOTIFY_CAP_MULT, 4, &data, 4)here?
The notification capability in particular has an extra field at the end, which is what we are looking for. We are still in PCI configuration space (BAR 15), we just want to read some different bytes in the notification capability configuration.
Quoted 8 lines
pc-bios/s390-ccw/virtio-pci.c line 206
Quoted 5 lines
pc-bios/s390-ccw/virtio-pci.c new file +5
-0+ notify_mult =bswap32 (data); + +if (pci_read (vdev->pci_fh, device_offset +VPCI_C_OFFSET_Q_NOFF ,4 , &data,2 )) { +return -EIO ; + }Should
queue_notify_offbe read usingpci_read(vdev->pci_fh, common_offset + VPCI_C_OFFSET_Q_NOFF, 4, &data, 2)?
(Virtio specs v-1.3 section 4.1.4.3 Common configuration structure layout)
I think you are correct. This is a mistake. The queue notification offset is in the common configuration, not the device configuration. I suspect it didn't cause a problem here because virtio-blk uses only one queue.
Quoted 8 lines
pc-bios/s390-ccw/virtio-pci.c line 354
Quoted 5 lines
pc-bios/s390-ccw/virtio-pci.c new file +4
-0+long virtio_pci_notify (uint32_t fhandle,int vq_id) +{ +uint64_t notice =1 ; +uint32_t offset = notify_offset + vq_id * q_notify_offset;Shoud the offset be calculated as
notify_offset+q_notify_offset*notify_mult?
(Virtio specs v-1.3 section 4.1.4.4 Notification structure layout)
I'll double check this, but you are probably right. As with the previous instance it didn't cause a problem due to there only being one queue for virtio-blk, so the offset is always just the base notify_offset and, luckily, the incorrect parts get multiplied by zero.
Quoted 6 lines
pc-bios/s390-ccw/virtio-pci.c line 356
Quoted 3 lines
pc-bios/s390-ccw/virtio-pci.c new file +2
-0+ +return pci_write (fhandle, offset, notice,4 );Please correct me if I'm wrong - instead of always writing notice = 1, should we write
vq_idtovq_indexof the Queue Notify address. (Virtio specs v-1.3 section 4.1.5.2 Available Buffer Notifications)
I'll double and triple check the queue offset/notification calculations since it seems there are multiple errors on my part and I just got lucky that virtio-blk wasn't affected. Thanks for catching these mistakes.
Regards,
Jared Rossi
Re: [PATCH 5/7] pc-bios/s390-ccw: Add support for virtio-blk-pci IPL
In reply to [email protected]Quoted 6 lines · On 10/20/2025 9:20 AM, [email protected] wrote:
From: Jared Rossi<[email protected]>
Enable virt-queue PCI configuration and add routines for virtio-blk-pci devices.
Signed-off-by Jared Rossi<[email protected]>---
Just a general observation in this patch, the BAR we are reading and writing to is BAR 4 for the virtio device. I think QEMU defines all the structure in BAR 4 (https://github.com/qemu/qemu/blob/88f72048d2f5835a1b9eaba690c7861393aef283/hw/virtio/virtio-pci.c#L2169). But after looking through the virtio spec, I couldn't tell if BAR 4 is hardcoded in the spec and should be used by default. So maybe we should try to read the BAR number from what the device provides to be more spec compliant? If we think that its okay to just use BAR 4 for now, then we should at least have a #define for it (also for magic number 15 which is a zpci address space number for PCI config space).
Thanks
Farhan
PATCH 6/7 s390x: Build IPLB for virtio-pci devices
In reply to [email protected]From: Jared Rossi <[email protected]>
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). Per-device loadparm is not yet supported for PCI devices.
--- hw/s390x/ipl.h | 3 ++ include/hw/s390x/s390-pci-bus.h | 2 ++ hw/s390x/ipl.c | 56 ++++++++++++++++++++++++++++++--- hw/s390x/s390-pci-bus.c | 2 +- 4 files changed, 57 insertions(+), 6 deletions(-)
hw/s390x/ipl.h +3 -0
@@ -107,6 +107,7 @@ QEMU_BUILD_BUG_MSG(offsetof(S390IPLState, iplb) & 3, "alignment of iplb wrong");#define S390_IPLB_MIN_PV_LEN 148#define S390_IPLB_MIN_CCW_LEN 200#define S390_IPLB_MIN_FCP_LEN 384 +#define S390_IPLB_MIN_PCI_LEN 376#define S390_IPLB_MIN_QEMU_SCSI_LEN 200static inline bool iplb_valid_len (IplParameterBlock *iplb)
@@ -179,6 +180,8 @@ static inline bool iplb_valid(IplParameterBlock *iplb)return len >=S390_IPLB_MIN_FCP_LEN ;case S390_IPL_TYPE_CCW :return len >=S390_IPLB_MIN_CCW_LEN ; +case S390_IPL_TYPE_PCI : +return len >=S390_IPLB_MIN_PCI_LEN ;case S390_IPL_TYPE_QEMU_SCSI :default :return false;
include/hw/s390x/s390-pci-bus.h +2 -0
@@ -402,6 +402,8 @@ S390PCIBusDevice *s390_pci_find_dev_by_fh(S390pciState *s, uint32_t fh);S390PCIBusDevice *s390_pci_find_dev_by_fid (S390pciState *s,uint32_t fid);S390PCIBusDevice *s390_pci_find_dev_by_target (S390pciState *s,const char *target); +S390PCIBusDevice *s390_pci_find_dev_by_pci (S390pciState *s, +PCIDevice *pci_dev);S390PCIBusDevice *s390_pci_find_next_avail_dev (S390pciState *s,S390PCIBusDevice *pbdev);void s390_pci_ism_reset (void );
hw/s390x/ipl.c +51 -5
103 lines not on this page · raw message
hw/s390x/s390-pci-bus.c +1 -1
@@ -249,7 +249,7 @@ S390PCIBusDevice *s390_pci_find_dev_by_target(S390pciState *s,return NULL ; } -static S390PCIBusDevice *s390_pci_find_dev_by_pci (S390pciState *s, +S390PCIBusDevice *s390_pci_find_dev_by_pci (S390pciState *s,PCIDevice *pci_dev) {S390PCIBusDevice *pbdev;
Signature · 1 line
2.49.0
Re: [PATCH 6/7] s390x: Build IPLB for virtio-pci devices
Quoted 7 lines · On 20/10/2025 18.20, [email protected] wrote:
From: Jared Rossi <[email protected]>
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). Per-device loadparm is not yet supported for PCI devices.
Could you add it? Something similar to what has been done in scsi_property_add_specifics() in hw/scsi/scsi-disk.c for the SCSI disks?
...
Quoted 10 lines
hw/s390x/ipl.c +1
-1@@ -346,7 +349,7 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl)static CcwDevice *s390_get_ccw_device (DeviceState *dev_st,int *devtype) {CcwDevice *ccw_dev =NULL ; -int tmp_dt =CCW_DEVTYPE_NONE ; +int tmp_dt =S390_DEVTYPE_NONE ;if (dev_st) { VirtIONet *virtio_net_dev = (VirtIONet *)
hw/s390x/ipl.c static CcwDevice *s390_get_ccw_device(DeviceState *dev_st, int *devtype) · line 399
Quoted 4 lines
hw/s390x/ipl.c +1
-0@@ -393,6 +396,31 @@ static CcwDevice *s390_get_ccw_device(DeviceState *dev_st, int *devtype)return ccw_dev; } +#define PCI_DEVTYPE_VIRTIO 0x05
Is this for virtio-block only ? If so, I'd maybe rather name it PCI_DEVTYPE_VIRTIO_BLK or so. Or will this be used for virtio-scsi-pci etc., too?
Thomas
Re: [PATCH 6/7] s390x: Build IPLB for virtio-pci devices
Quoted 11 lines · Thomas Huth
Quoted 7 lines · On 20/10/2025 18.20, [email protected] wrote:
From: Jared Rossi <[email protected]>
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). Per-device loadparm is not yet supported for PCI devices.
Could you add it? Something similar to what has been done in
scsi_property_add_specifics()inhw/scsi/scsi-disk.cfor the SCSI disks?
Sure. It will be included in the next version.
Quoted 17 lines
...
Quoted 13 lines
hw/s390x/ipl.c +1
-1@@ -346,7 +349,7 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl) static CcwDevice *s390_get_ccw_device(DeviceState *dev_st, int *devtype) { CcwDevice *ccw_dev = NULL; - int tmp_dt = CCW_DEVTYPE_NONE; + int tmp_dt = S390_DEVTYPE_NONE; if (dev_st) { VirtIONet *virtio_net_dev = (VirtIONet *)@@ -393,6 +396,31 @@ static CcwDevice *s390_get_ccw_device(DeviceState *dev_st, int *devtype) return ccw_dev; }Quoted 1 line
+#define PCI_DEVTYPE_VIRTIO
0x05Is this for virtio-block only ? If so, I'd maybe rather name it
PCI_DEVTYPE_VIRTIO_BLKor so. Or will this be used for virtio-scsi-pci etc., too?
I named it this way because it is the PCI equivalent of CCW_DEVTYPE_VIRTIO used in the above s390_get_ccw_device() function. Although The CCW function also has a different designation for virtio-net devices I don't think that will be useful for PCI (due to the change with the netboot binary). So, this device type could be used for both virtio-blk-pci and virtio-net-pci. Virtio-scsi-pci would need a different designation though (much like how there exists CCW_DEVTYPE_SCSI).
Regards,
Jared Rossi
PATCH 7/7 tests/qtest: Add s390x PCI boot test to cdrom-test.c
In reply to [email protected]From: Jared Rossi <[email protected]>
Add a rudimentary test for s390x IPL to verify that a guest may boot using virtio-blk-pci device.
--- tests/qtest/cdrom-test.c | 7 +++++++ 1 file changed, 7 insertions(+)
tests/qtest/cdrom-test.c +7 -0
@@ -246,6 +246,13 @@ static void add_s390x_tests(void)"-drive if=none,id=d2,media=cdrom,file=" , test_cdboot); } +if (qtest_has_device ("virtio-blk-pci" )) { +qtest_add_data_func ("cdrom/boot/pci-bus-with-bootindex" , +"-device virtio-scsi -device virtio-serial " +"-device virtio-blk-pci,drive=d1,bootindex=1 " +"-drive if=none,id=d1,media=cdrom,file=" , + test_cdboot); + } }int main (int argc,char **argv)
Signature · 1 line
2.49.0
Re: [PATCH 7/7] tests/qtest: Add s390x PCI boot test to cdrom-test.c
Quoted 18 lines · On 20/10/2025 18.20, [email protected] wrote:
From: Jared Rossi <[email protected]>
Add a rudimentary test for s390x IPL to verify that a guest may boot using virtio-blk-pci device.
Signed-off-by Jared Rossi <[email protected]>--- tests/qtest/cdrom-test.c | 7 +++++++ 1 file changed, 7 insertions(+)tests/qtest/cdrom-test.c +0
-0@@ -246,6 +246,13 @@ static void add_s390x_tests(void)"-drive if=none,id=d2,media=cdrom,file=" , test_cdboot); }
tests/qtest/cdrom-test.c static void add_s390x_tests(void) · line 258
Quoted 10 lines
tests/qtest/cdrom-test.c +7
-0+if (qtest_has_device ("virtio-blk-pci" )) { +qtest_add_data_func ("cdrom/boot/pci-bus-with-bootindex" , +"-device virtio-scsi -device virtio-serial " +"-device virtio-blk-pci,drive=d1,bootindex=1 " +"-drive if=none,id=d1,media=cdrom,file=" , + test_cdboot); + } }int main (int argc,char **argv)