s390x: Add support for virtio-blk-pci IPL device
v3 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.
Boot support is only added for virtio-blk-pci at this time and is limited to devices with an assigned bootindex.
A "loadparm" property is added to virtio-blk-pci boot devices on s390x.
A simple test to check basic functionality is added to the cdrom-tests in qtest.
Changes v2 -> v3:
- Negotiate VIRTIO_F_VERSION_1 and support PCI native little endian
- Split patches further to isolate clean-up and substantive changes
- Move byteswap helpers from pci.c to virtio-pci.c to avoid passing the file handle throughout
- Convert IPL type to enum and add defaults for switch cases
- Add PCI loadparm only to virtio-blk devices
- Do not assume PCI devices are virtio when building IPLB
Jared Rossi (14):
pc-bios/s390-ccw: Fix misattributed function prototypes pc-bios/s390-ccw: Remove redundant vring schid attribute
s390x: Remove duplicate definitions of IPL types pc-bios/s390-ccw: Store device type independent of sense data pc-bios/s390-ccw: Split virtio-ccw and generic virtio include/hw/s390x: Move CLP definitions for easier BIOS access pc-bios/s390-ccw: Introduce CLP Architecture
s390x: Add definitions for PCI IPL type pc-bios/s390-ccw: Introduce PCI device pc-bios/s390-ccw: Introduce virtio-pci functions pc-bios/s390-ccw: Add support for virtio-blk-pci IPL
s390x: Build IPLB for virtio-pci devices
hw: Add "loadparm" property to virtio block PCI devices booting on
s390x
tests/qtest: Add s390x PCI boot test to cdrom-test.c
hw/pci/pci.c | 39 ++
hw/s390x/ipl.c | 63 +++-
hw/s390x/ipl.h | 8 +-
hw/s390x/s390-pci-bus.c | 3 +-
hw/s390x/s390-pci-vfio.c | 2 +-
hw/virtio/virtio-blk-pci.c | 1 +
include/hw/pci/pci.h | 1 +
include/hw/pci/pci_device.h | 3 +
include/hw/s390x/ipl/qipl.h | 20 +
include/hw/s390x/{ => ipl}/s390-pci-clp.h | 0
include/hw/s390x/s390-pci-bus.h | 4 +-
pc-bios/s390-ccw/Makefile | 3 +-
pc-bios/s390-ccw/bootmap.c | 2 +-
pc-bios/s390-ccw/clp.c | 96 +++++
pc-bios/s390-ccw/clp.h | 24 ++
pc-bios/s390-ccw/iplb.h | 4 -
pc-bios/s390-ccw/main.c | 79 +++-
pc-bios/s390-ccw/netmain.c | 2 +-
pc-bios/s390-ccw/pci.c | 194 ++++++++++
pc-bios/s390-ccw/pci.h | 80 ++++
pc-bios/s390-ccw/s390-ccw.h | 7 -
pc-bios/s390-ccw/virtio-blkdev.c | 74 ++--
pc-bios/s390-ccw/virtio-ccw.c | 241 ++++++++++++
pc-bios/s390-ccw/virtio-ccw.h | 24 ++
pc-bios/s390-ccw/virtio-net.c | 5 +-
pc-bios/s390-ccw/virtio-pci.c | 424 ++++++++++++++++++++++
pc-bios/s390-ccw/virtio-pci.h | 88 +++++
pc-bios/s390-ccw/virtio-scsi.c | 6 +-
pc-bios/s390-ccw/virtio-scsi.h | 2 +-
pc-bios/s390-ccw/virtio.c | 285 +++++----------
pc-bios/s390-ccw/virtio.h | 17 +-
tests/qtest/cdrom-test.c | 7 +
32 files changed, 1543 insertions(+), 265 deletions(-)
rename include/hw/s390x/{ => ipl}/s390-pci-clp.h (100%)
create mode 100644 pc-bios/s390-ccw/clp.c
create mode 100644 pc-bios/s390-ccw/clp.h
create mode 100644 pc-bios/s390-ccw/pci.c
create mode 100644 pc-bios/s390-ccw/pci.h
create mode 100644 pc-bios/s390-ccw/virtio-ccw.c
create mode 100644 pc-bios/s390-ccw/virtio-ccw.h
create mode 100644 pc-bios/s390-ccw/virtio-pci.c
create mode 100644 pc-bios/s390-ccw/virtio-pci.hSignature · 1 line
2.52.0
PATCH v3 1/14 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/bootmap.c | 2 +- pc-bios/s390-ccw/s390-ccw.h | 4 ---- pc-bios/s390-ccw/virtio-blkdev.c | 2 +- pc-bios/s390-ccw/virtio.h | 7 +++++++ 4 files changed, 9 insertions(+), 6 deletions(-)
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/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-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;
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 */
Signature · 1 line
2.52.0
Re: [PATCH v3 01/14] pc-bios/s390-ccw: Fix misattributed function prototypes
Quoted 11 lines · On 1/27/2026 8:15 AM, [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.Reviewed-by Thomas Huth<[email protected]>Reviewed-by Eric Farman<[email protected]>Signed-off-by Jared Rossi<[email protected]>
Quoted 6 lines
--- pc-bios/s390-ccw/bootmap.c | 2 +- pc-bios/s390-ccw/s390-ccw.h | 4 ---- pc-bios/s390-ccw/virtio-blkdev.c | 2 +- pc-bios/s390-ccw/virtio.h | 7 +++++++ 4 files changed, 9 insertions(+), 6 deletions(-)
PATCH v3 2/14 pc-bios/s390-ccw: Remove redundant vring schid attribute
In reply to [email protected]From: Jared Rossi <[email protected]>
The schid is already stored as an attribute of the VDev itself and any other instances are copies of this same value. To avoid CCW specific attributes in the VRing let's just access the existing VDev schid attribute as needed.
--- pc-bios/s390-ccw/virtio-blkdev.c | 2 +- pc-bios/s390-ccw/virtio-net.c | 2 +- pc-bios/s390-ccw/virtio.c | 9 ++++----- pc-bios/s390-ccw/virtio.h | 3 +-- 4 files changed, 7 insertions(+), 9 deletions(-)
pc-bios/s390-ccw/virtio-blkdev.c +1 -1
@@ -42,7 +42,7 @@ static int virtio_blk_read_many(VDev *vdev, unsigned long sector, void *load_add/* Now we can tell the host to read */ vring_wait_reply (); -if (drain_irqs (vr->schid)) { +if (drain_irqs ()) {/* Well, whatever status is supposed to contain... */ status =1 ; }
pc-bios/s390-ccw/virtio-net.c +1 -1
@@ -88,7 +88,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 ()) {puts ("send: drain irqs failed" );return -1 ; }
pc-bios/s390-ccw/virtio.c +4 -5
@@ -72,14 +72,14 @@ static long virtio_notify(SubChannelId schid, int vq_idx, long cookie)* Virtio functions * ***********************************************/ -int drain_irqs (SubChannelId schid) +int drain_irqs (void ) {Irb irb = {};int r =0 ;while (1 ) {/* FIXME: make use of TPI, for that enable subchannel and isc */ -if (tsch (schid, &irb)) { +if (tsch (vdev.schid, &irb)) {/* Might want to differentiate error codes later on. */ if (irb.scsw.cstat) { r = -EIO ;
@@ -134,7 +134,7 @@ static void vring_init(VRing *vr, VqInfo *info)bool vring_notify (VRing *vr) { - vr->cookie =virtio_notify (vr->schid, vr->id, vr->cookie); + vr->cookie =virtio_notify (vdev.schid, vr->id, vr->cookie);return vr->cookie >=0 ; }
@@ -211,7 +211,7 @@ int virtio_run(VDev *vdev, int vqid, VirtioCmd *cmd) }while (cmd[i++].flags &VRING_DESC_F_NEXT );vring_wait_reply (); -if (drain_irqs (vr->schid)) { +if (drain_irqs ()) {return -1 ; }return 0 ;
@@ -316,7 +316,6 @@ int virtio_setup_ccw(VDev *vdev) } info.num = config.num;vring_init (&vdev->vrings[i], &info); - vdev->vrings[i].schid = vdev->schid;if (run_ccw (vdev,CCW_CMD_SET_VQ , &info,sizeof (info), false)) {puts ("Cannot set VQ info" );return -EIO ;
pc-bios/s390-ccw/virtio.h +1 -2
@@ -103,7 +103,6 @@ struct VRing {VRingDesc *desc;VRingAvail *avail;VRingUsed *used; -SubChannelId schid;long cookie;int id; };
@@ -269,7 +268,7 @@ struct VirtioCmd {typedef struct VirtioCmd VirtioCmd ;bool vring_notify (VRing *vr); -int drain_irqs (SubChannelId schid); +int drain_irqs (void );void vring_send_buf (VRing *vr,void *p,int len,int flags);int vr_poll (VRing *vr);int vring_wait_reply (void );
Signature · 1 line
2.52.0
Re: [PATCH v3 02/14] pc-bios/s390-ccw: Remove redundant vring schid attribute
Quoted 19 lines · On 27/01/2026 17.15, [email protected] wrote:
From: Jared Rossi <[email protected]>
The schid is already stored as an attribute of the VDev itself and any other instances are copies of this same value. To avoid CCW specific attributes in the VRing let's just access the existing VDev schid attribute as needed.
Signed-off-by Jared Rossi <[email protected]>--- pc-bios/s390-ccw/virtio-blkdev.c | 2 +- pc-bios/s390-ccw/virtio-net.c | 2 +- pc-bios/s390-ccw/virtio.c | 9 ++++----- pc-bios/s390-ccw/virtio.h | 3 +-- 4 files changed, 7 insertions(+), 9 deletions(-)pc-bios/s390-ccw/virtio-blkdev.c +0
-0
pc-bios/s390-ccw/virtio-blkdev.c static int virtio_blk_read_many(VDev *vdev, unsigned long sector, void *load_add · line 48
Quoted 8 lines
pc-bios/s390-ccw/virtio-blkdev.c +1
-1@@ -42,7 +42,7 @@ static int virtio_blk_read_many(VDev *vdev, unsigned long sector, void *load_add/* Now we can tell the host to read */ vring_wait_reply (); -if (drain_irqs (vr->schid)) { +if (drain_irqs ()) {/* Well, whatever status is supposed to contain... */ status =1 ; }
Just a thought: Maybe we should rather get rid of the global access to the "vdev" in the long run (in case we ever want to deal with multiple devices at once), so it might be nicer to add a "VDev *vdev" parameter to the drain_irqs() function now instead of making its parameter list "void". Anyway, it's just a thought, we can also still tackle this later if needed, so I'm also fine with this patch as it:
Eric Farman
Reviewed-byRe: [PATCH v3 02/14] pc-bios/s390-ccw: Remove redundant vring schid attribute
Quoted 35 lines · Thomas Huth
Quoted 19 lines · On 27/01/2026 17.15, [email protected] wrote:
From: Jared Rossi <[email protected]>
The schid is already stored as an attribute of the VDev itself and any other instances are copies of this same value. To avoid CCW specific attributes in the VRing let's just access the existing VDev schid attribute as needed.
Signed-off-by Jared Rossi <[email protected]>--- pc-bios/s390-ccw/virtio-blkdev.c | 2 +- pc-bios/s390-ccw/virtio-net.c | 2 +- pc-bios/s390-ccw/virtio.c | 9 ++++----- pc-bios/s390-ccw/virtio.h | 3 +-- 4 files changed, 7 insertions(+), 9 deletions(-)pc-bios/s390-ccw/virtio-blkdev.c +0
-0pc-bios/s390-ccw/virtio-blkdev.c static int virtio_blk_read_many(VDev *vdev, unsigned long sector, void *load_add · line 48
Quoted 8 lines
pc-bios/s390-ccw/virtio-blkdev.c +1
-1@@ -42,7 +42,7 @@ static int virtio_blk_read_many(VDev *vdev, unsigned long sector, void *load_add/* Now we can tell the host to read */ vring_wait_reply (); -if (drain_irqs (vr->schid)) { +if (drain_irqs ()) {/* Well, whatever status is supposed to contain... */ status =1 ; }Just a thought: Maybe we should rather get rid of the global access to the "vdev" in the long run (in case we ever want to deal with multiple devices at once), so it might be nicer to add a "VDev *vdev" parameter to the
drain_irqs()function now instead of making its parameter list "void". Anyway, it's just a thought, we can also still tackle this later if needed, so I'm also fine with this patch as it:
Quoted 1 line
Reviewed-by Thomas Huth <[email protected]>
I agree. Removing that global access to the vdev would be a good goal, since it's sometimes passed around today and sometimes not, and this series highlights that oddity. But, that doesn't need to be addressed at this particular moment. So...
Re: [PATCH v3 02/14] pc-bios/s390-ccw: Remove redundant vring schid attribute
In reply to [email protected]Quoted 6 lines · On 1/27/2026 8:15 AM, [email protected] wrote:
From: Jared Rossi<[email protected]>
The schid is already stored as an attribute of the VDev itself and any other instances are copies of this same value. To avoid CCW specific attributes in the VRing let's just access the existing VDev schid attribute as needed.
Quoted 7 lines
Signed-off-by Jared Rossi<[email protected]>--- pc-bios/s390-ccw/virtio-blkdev.c | 2 +- pc-bios/s390-ccw/virtio-net.c | 2 +- pc-bios/s390-ccw/virtio.c | 9 ++++----- pc-bios/s390-ccw/virtio.h | 3 +-- 4 files changed, 7 insertions(+), 9 deletions(-)
PATCH v3 3/14 s390x: Remove duplicate definitions of IPL types
In reply to [email protected]From: Jared Rossi <[email protected]>
Remove the duplicate definitions from hw/s390x/ipl.h and pc-bios/s390-ccw/iplb.h and add a shared definition. The new definition is an enum to enforce default handling in switches.
--- hw/s390x/ipl.h | 5 ----- include/hw/s390x/ipl/qipl.h | 10 ++++++++++ pc-bios/s390-ccw/iplb.h | 4 ---- pc-bios/s390-ccw/main.c | 9 +++++++-- pc-bios/s390-ccw/virtio.h | 1 + 5 files changed, 18 insertions(+), 11 deletions(-)
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 +10 -0
@@ -20,6 +20,16 @@#define LOADPARM_LEN 8#define NO_LOADPARM "\0\0\0\0\0\0\0\0" +enum S390IplType { +S390_IPL_TYPE_FCP =0x00 , +S390_IPL_TYPE_CCW =0x02 , +S390_IPL_TYPE_PV =0x05 , +S390_IPL_TYPE_QEMU_SCSI =0xff +}; +typedef enum S390IplType S390IplType ; + +#define QEMU_DEFAULT_IPL S390_IPL_TYPE_CCW +/* * 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/main.c +7 -2
@@ -162,11 +162,12 @@ static void menu_setup(void)return ; } -switch (iplb.pbt) { +switch (virtio_get_device ()->ipl_type) {case S390_IPL_TYPE_CCW :case S390_IPL_TYPE_QEMU_SCSI :menu_set_parms (qipl.qipl_flags &BOOT_MENU_FLAG_MASK , qipl.boot_menu_timeout); +default :return ; } }
@@ -190,6 +191,7 @@ static void css_setup(void)static void boot_setup (void ) {char lpmsg[] ="LOADPARM=[________]\n" ; +VDev *vdev =virtio_get_device ();if (have_iplb &&memcmp (iplb.loadparm,NO_LOADPARM ,LOADPARM_LEN ) !=0 ) {ebcdic_to_ascii ((char *) iplb.loadparm, loadparm_str,LOADPARM_LEN );
@@ -198,7 +200,10 @@ static void boot_setup(void) }if (have_iplb) { + vdev->ipl_type = iplb.pbt;menu_setup (); + }else { + vdev->ipl_type =QEMU_DEFAULT_IPL ; }memcpy (lpmsg +10 , loadparm_str,8 );
@@ -216,7 +221,7 @@ static bool find_boot_device(void)VDev *vdev =virtio_get_device ();bool found = false; -switch (iplb.pbt) { +switch (vdev->ipl_type) {case S390_IPL_TYPE_CCW : vdev->scsi_device_selected = false;debug_print_int ("device no. " , iplb.ccw.devno);
pc-bios/s390-ccw/virtio.h +1 -0
@@ -238,6 +238,7 @@ struct VDev {VirtioGDN guessed_disk_nature;SubChannelId schid;SenseId senseid; +S390IplType ipl_type;union {VirtioBlkConfig blk;VirtioScsiConfig scsi;
Signature · 1 line
2.52.0
Re: [PATCH v3 03/14] s390x: Remove duplicate definitions of IPL types
Quoted 14 lines · On 27/01/2026 17.15, [email protected] wrote:
From: Jared Rossi <[email protected]>
Remove the duplicate definitions from
hw/s390x/ipl.handpc-bios/s390-ccw/iplb.hand add a shared definition. The new definition is an enum to enforce default handling in switches.Signed-off-by Jared Rossi <[email protected]>--- hw/s390x/ipl.h | 5 ----- include/hw/s390x/ipl/qipl.h | 10 ++++++++++ pc-bios/s390-ccw/iplb.h | 4 ---- pc-bios/s390-ccw/main.c | 9 +++++++-- pc-bios/s390-ccw/virtio.h | 1 + 5 files changed, 18 insertions(+), 11 deletions(-)
...
pc-bios/s390-ccw/main.c static void boot_setup(void) · line 207
Quoted 9 lines
pc-bios/s390-ccw/main.c +3
-0@@ -198,7 +200,10 @@ static void boot_setup(void) }if (have_iplb) { + vdev->ipl_type = iplb.pbt;menu_setup (); + }else { + vdev->ipl_type =QEMU_DEFAULT_IPL ; }
Could you maybe add a sentence about that new DEFAULT_IPL setting to the patch description? I assume this is some prep work for some of the following patches? In that case, please mention it. Otherwise this looks unnecessary when just looking at the context of this single patch.
Thanks,
Thomas
PATCH v3 4/14 pc-bios/s390-ccw: Store device type independent of sense data
In reply to [email protected]From: Jared Rossi <[email protected]>
Store the device type (e.g. block) directly and an attribute of the VDev rather than assume all devices can be identified by accessing CCW specific sense data.
--- pc-bios/s390-ccw/main.c | 2 +- pc-bios/s390-ccw/virtio-blkdev.c | 39 +++++++++++++++++++------------- pc-bios/s390-ccw/virtio.c | 11 ++++++--- pc-bios/s390-ccw/virtio.h | 1 + 4 files changed, 33 insertions(+), 20 deletions(-)
pc-bios/s390-ccw/main.c +1 -1
@@ -250,7 +250,7 @@ static int virtio_setup(void) vdev->is_cdrom = false;int ret; -switch (vdev->senseid.cu_model) { +switch (vdev->dev_type) {case VIRTIO_ID_NET :puts ("Network boot device detected" );return 0 ;
pc-bios/s390-ccw/virtio-blkdev.c +23 -16
@@ -53,14 +53,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->dev_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 +119,7 @@ void virtio_assume_iso9660(void) {VDev *vdev =virtio_get_device (); -switch (vdev->senseid.cu_model) { +switch (vdev->dev_type) {case VIRTIO_ID_BLOCK : vdev->guessed_disk_nature =VIRTIO_GDN_SCSI ; vdev->config.blk.blk_size =VIRTIO_ISO_BLOCK_SIZE ;
@@ -129,6 +129,8 @@ void virtio_assume_iso9660(void)case VIRTIO_ID_SCSI : vdev->scsi_block_size =VIRTIO_ISO_BLOCK_SIZE ;break ; +default : +return ; } }
@@ -139,13 +141,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->dev_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 : +break ; } vdev->config.blk.geometry.heads =15 ; vdev->config.blk.geometry.sectors =
@@ -162,50 +166,52 @@ bool virtio_ipl_disk_is_valid(void)return true; } -return (vdev->senseid.cu_model ==VIRTIO_ID_BLOCK || - vdev->senseid.cu_model ==VIRTIO_ID_SCSI ) && - blksize >=512 && blksize <=4096 ; +return (vdev->dev_type ==VIRTIO_ID_BLOCK || vdev->dev_type ==VIRTIO_ID_SCSI ) + && blksize >=512 && blksize <=4096 ; }int virtio_get_block_size (void ) {VDev *vdev =virtio_get_device (); -switch (vdev->senseid.cu_model) { +switch (vdev->dev_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->dev_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->dev_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,13 +219,14 @@ 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->dev_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)
pc-bios/s390-ccw/virtio.c +8 -3
@@ -41,7 +41,7 @@ VDev *virtio_get_device(void)VirtioDevType virtio_get_device_type (void ) { -return vdev.senseid.cu_model; +return vdev.dev_type; }/* virtio spec v1.0 para 4.3.3.2 */
@@ -248,7 +248,7 @@ int virtio_setup_ccw(VDev *vdev)return -EIO ; } -switch (vdev->senseid.cu_model) { +switch (vdev->dev_type) {case VIRTIO_ID_NET : vdev->nr_vqs =2 ; vdev->cmd_vr_idx =0 ;
@@ -346,12 +346,17 @@ bool virtio_is_supported(SubChannelId schid) true)) {return false; } + + vdev.dev_type = vdev.senseid.cu_model; +if (vdev.senseid.cu_type ==0x3832 ) { -switch (vdev.senseid.cu_model) { +switch (vdev.dev_type) {case VIRTIO_ID_BLOCK :case VIRTIO_ID_SCSI :case VIRTIO_ID_NET :return true; +default : +return false; } }return false;
pc-bios/s390-ccw/virtio.h +1 -0
@@ -239,6 +239,7 @@ struct VDev {SubChannelId schid;SenseId senseid;S390IplType ipl_type; +VirtioDevType dev_type;union {VirtioBlkConfig blk;VirtioScsiConfig scsi;
Signature · 1 line
2.52.0
Re: [PATCH v3 04/14] pc-bios/s390-ccw: Store device type independent of sense data
Quoted 7 lines · On 27/01/2026 17.15, [email protected] wrote:
From: Jared Rossi <[email protected]>
Store the device type (e.g. block) directly and an attribute of the VDev rather than assume all devices can be identified by accessing CCW specific sense data.
Signed-off-by Jared Rossi <[email protected]>---
...
Quoted 9 lines
pc-bios/s390-ccw/virtio.c +3
-1@@ -346,12 +346,17 @@ bool virtio_is_supported(SubChannelId schid) true)) {return false; } + + vdev.dev_type = vdev.senseid.cu_model; +if (vdev.senseid.cu_type ==0x3832 ) { -switch (vdev.senseid.cu_model) {
pc-bios/s390-ccw/virtio.c bool virtio_is_supported(SubChannelId schid) · line 362
Quoted 10 lines
pc-bios/s390-ccw/virtio.c +3
-0+switch (vdev.dev_type) {case VIRTIO_ID_BLOCK :case VIRTIO_ID_SCSI :case VIRTIO_ID_NET :return true; +default : +return false; } }return false;
It feels a bit weird to set up vdev.dev_type in a function called "virtio_is_supported" (I'd rather expect a function with that name to check only stuff, not to set values) ... but we're doing the same with vdev.schid there, too, so I guess it's ok for now. In the long run, we should maybe split up virtio_is_supported in two pieces, one function that does early setup, and one that is checking whether it's a supported virtio device.
Anyway, for now:
Re: [PATCH v3 04/14] pc-bios/s390-ccw: Store device type independent of sense data
In reply to [email protected]Quoted 4 lines · On 1/27/2026 8:15 AM, [email protected] wrote:
From: Jared Rossi<[email protected]>
Store the device type (e.g. block) directly and an attribute of the VDev rather than assume all devices can be identified by accessing CCW specific sense data.
I think it should be "as an attribute"?
Quoted 7 lines
Signed-off-by Jared Rossi<[email protected]>--- pc-bios/s390-ccw/main.c | 2 +- pc-bios/s390-ccw/virtio-blkdev.c | 39 +++++++++++++++++++------------- pc-bios/s390-ccw/virtio.c | 11 ++++++--- pc-bios/s390-ccw/virtio.h | 1 + 4 files changed, 33 insertions(+), 20 deletions(-)
The patch looks good to me
PATCH v3 5/14 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.
--- pc-bios/s390-ccw/Makefile | 3 +- pc-bios/s390-ccw/main.c | 8 +- pc-bios/s390-ccw/netmain.c | 2 +- pc-bios/s390-ccw/s390-ccw.h | 3 - pc-bios/s390-ccw/virtio-blkdev.c | 13 +- pc-bios/s390-ccw/virtio-ccw.c | 241 +++++++++++++++++++++++++++++++ pc-bios/s390-ccw/virtio-ccw.h | 24 +++ pc-bios/s390-ccw/virtio-net.c | 3 +- pc-bios/s390-ccw/virtio-scsi.c | 6 +- pc-bios/s390-ccw/virtio-scsi.h | 2 +- pc-bios/s390-ccw/virtio.c | 239 +++++------------------------- pc-bios/s390-ccw/virtio.h | 5 +- 12 files changed, 332 insertions(+), 217 deletions(-) create mode 100644 pc-bios/s390-ccw/virtio-ccw.c create mode 100644 pc-bios/s390-ccw/virtio-ccw.h
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
pc-bios/s390-ccw/main.c +5 -3
@@ -71,6 +71,7 @@ static int is_dev_possibly_bootable(int dev_no, int sch_no)bool is_virtio;Schib schib;int r; +VDev *vdev =virtio_get_device (); blk_schid.sch_no = sch_no; r =stsch_err (blk_schid, &schib);
@@ -91,7 +92,8 @@ static int is_dev_possibly_bootable(int dev_no, int sch_no)* Note: we always have to run virtio_is_supported() here to make * sure that the vdev.senseid data gets pre-initialized correctly */ - is_virtio =virtio_is_supported (blk_schid); + vdev->schid = blk_schid; + is_virtio =virtio_is_supported (vdev);/* No specific devno given, just return whether the device is possibly bootable */ if (dev_no <0 ) {
@@ -255,10 +257,10 @@ static int virtio_setup(void)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" );
pc-bios/s390-ccw/netmain.c +1 -1
@@ -500,7 +500,7 @@ static bool find_net_dev(Schib *schib, int dev_no)continue ; }enable_subchannel (net_schid); -if (!virtio_is_supported (net_schid)) { +if (!virtio_is_supported (virtio_get_device ())) {continue ; }if (virtio_get_device_type () !=VIRTIO_ID_NET ) {
pc-bios/s390-ccw/s390-ccw.h +0 -3
@@ -66,9 +66,6 @@ void sclp_setup(void);void sclp_get_loadparm_ascii (char *loadparm);int sclp_read (char *str,size_t count); -/* virtio.c */ -bool virtio_is_supported (SubChannelId schid); -/* bootmap.c */ void zipl_load (void );
pc-bios/s390-ccw/virtio-blkdev.c +9 -4
@@ -12,6 +12,7 @@#include "s390-ccw.h" #include "virtio.h" #include "virtio-scsi.h" +#include "virtio-ccw.h" #define VIRTIO_BLK_F_GEOMETRY (1 << 4)#define VIRTIO_BLK_F_BLK_SIZE (1 << 6)
@@ -229,15 +230,19 @@ uint64_t virtio_get_blocks(void) } } -int virtio_blk_setup_device (SubChannelId schid) +int virtio_blk_setup_device (void ) {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 ; +switch (vdev->ipl_type) { +case S390_IPL_TYPE_QEMU_SCSI : +case S390_IPL_TYPE_CCW : +return virtio_ccw_setup (vdev); +default : +return 1 ; + } }
pc-bios/s390-ccw/virtio-ccw.c new file +241 -0
241 lines not on this page · raw message
pc-bios/s390-ccw/virtio-ccw.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* 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 drain_irqs_ccw (SubChannelId schid); +bool virtio_ccw_is_supported (VDev *vdev); +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-net.c +2 -1
@@ -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" );
pc-bios/s390-ccw/virtio-scsi.c +3 -3
@@ -15,6 +15,7 @@#include "virtio.h" #include "scsi.h" #include "virtio-scsi.h" +#include "virtio-ccw.h" #include "s390-time.h" #include "helper.h"
@@ -476,12 +477,11 @@ static int virtio_scsi_setup(VDev *vdev)return 0 ; } -int virtio_scsi_setup_device (SubChannelId schid) +int virtio_scsi_setup_device (void ) {VDev *vdev =virtio_get_device (); - vdev->schid = schid; -virtio_setup_ccw (vdev); +virtio_ccw_setup (vdev);if (vdev->config.scsi.sense_size !=VIRTIO_SCSI_SENSE_SIZE ) {puts ("Config: sense size mismatch" );
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.c +40 -199
290 lines not on this page · raw message
pc-bios/s390-ccw/virtio.h +4 -1
@@ -108,6 +108,7 @@ struct VRing { };typedef struct VRing VRing ; +char *virtio_get_ring_area (int ring_num);/*********************************************** * Virtio block *
@@ -269,6 +270,8 @@ struct VirtioCmd { };typedef struct VirtioCmd VirtioCmd ; +void vring_init (VRing *vr,VqInfo *info); +bool virtio_is_supported (VDev *vdev);bool vring_notify (VRing *vr);int drain_irqs (void );void vring_send_buf (VRing *vr,void *p,int len,int flags);
@@ -283,7 +286,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);
Signature · 1 line
2.52.0
Re: [PATCH v3 05/14] pc-bios/s390-ccw: Split virtio-ccw and generic virtio
Quoted 7 lines · On 27/01/2026 17.15, [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]>---
...
Quoted 23 lines
pc-bios/s390-ccw/main.c +3
-1@@ -71,6 +71,7 @@ static int is_dev_possibly_bootable(int dev_no, int sch_no)bool is_virtio;Schib schib;int r; +VDev *vdev =virtio_get_device (); blk_schid.sch_no = sch_no; r =stsch_err (blk_schid, &schib);@@ -91,7 +92,8 @@ static int is_dev_possibly_bootable(int dev_no, int sch_no)* Note: we always have to run virtio_is_supported() here to make * sure that the vdev.senseid data gets pre-initialized correctly */ - is_virtio =virtio_is_supported (blk_schid); + vdev->schid = blk_schid; + is_virtio =virtio_is_supported (vdev);/* No specific devno given, just return whether the device is possibly bootable */ if (dev_no <0 ) {
pc-bios/s390-ccw/main.c static int virtio_setup(void) · line 264
Quoted 10 lines
pc-bios/s390-ccw/main.c +2
-2@@ -255,10 +257,10 @@ static int virtio_setup(void)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 ;
In virtio_setup(), there is already a "VDev *vdev = virtio_get_device()" at the beginning of the function. virtio_blk_setup_device() and virtio_scsi_setup_device() are doing this again. So while you're at it, may I suggest to turn that vdev pointer into a parameter of these functions now, so that you now pass a vdev instead of a blk_schid to those functions? That way we can get rid of the additional virtio_get_device() in virtio_blk_setup_device() and virtio_scsi_setup_device().
Apart from that nit, the patch looks fine to me.
Thanks,
Thomas
...
Quoted 36 lines
pc-bios/s390-ccw/virtio-blkdev.c +9
-4@@ -12,6 +12,7 @@#include "s390-ccw.h" #include "virtio.h" #include "virtio-scsi.h" +#include "virtio-ccw.h" #define VIRTIO_BLK_F_GEOMETRY (1 << 4)#define VIRTIO_BLK_F_BLK_SIZE (1 << 6)@@ -229,15 +230,19 @@ uint64_t virtio_get_blocks(void) } } -int virtio_blk_setup_device (SubChannelId schid) +int virtio_blk_setup_device (void ) {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 ; +switch (vdev->ipl_type) { +case S390_IPL_TYPE_QEMU_SCSI : +case S390_IPL_TYPE_CCW : +return virtio_ccw_setup (vdev); +default : +return 1 ; + } }
...
PATCH v3 6/14 include/hw/s390x: Move CLP definitions for easier BIOS access
In reply to [email protected]From: Jared Rossi <[email protected]>
Move the s390-pci-clp definitions into the "ipl" sub-directory, which is visible to the s390-bios. This allows the bios to reuse the architected definitions and prevents code duplication.
---
hw/s390x/s390-pci-vfio.c | 2 +-
include/hw/s390x/{ => ipl}/s390-pci-clp.h | 0
include/hw/s390x/s390-pci-bus.h | 2 +-
3 files changed, 2 insertions(+), 2 deletions(-)
rename include/hw/s390x/{ => ipl}/s390-pci-clp.h (100%)hw/s390x/s390-pci-vfio.c +1 -1
@@ -17,7 +17,7 @@#include "trace.h" #include "hw/s390x/s390-pci-bus.h" -#include "hw/s390x/s390-pci-clp.h" +#include "hw/s390x/ipl/s390-pci-clp.h" #include "hw/s390x/s390-pci-vfio.h" #include "hw/vfio/pci.h" #include "hw/vfio/vfio-container-legacy.h"
include/hw/s390x/ipl/s390-pci-clp.h renamed from include/hw/s390x/s390-pci-clp.h +0 -0
include/hw/s390x/s390-pci-bus.h +1 -1
@@ -19,7 +19,7 @@#include "hw/s390x/sclp.h" #include "hw/s390x/s390_flic.h" #include "hw/s390x/css.h" -#include "hw/s390x/s390-pci-clp.h" +#include "hw/s390x/ipl/s390-pci-clp.h" #include "qom/object.h" #define TYPE_S390_PCI_HOST_BRIDGE "s390-pcihost"
Signature · 1 line
2.52.0
Re: [PATCH v3 06/14] include/hw/s390x: Move CLP definitions for easier BIOS access
Quoted 6 lines · On Tue, 2026-01-27 at 11:15 -0500, [email protected] wrote:
From: Jared Rossi <[email protected]>
Move the s390-pci-clp definitions into the "ipl" sub-directory, which is visible to the s390-bios. This allows the bios to reuse the architected definitions and prevents code duplication.
Quoted 8 lines
Reviewed-by Thomas Huth <[email protected]>Signed-off-by Jared Rossi <[email protected]>--- hw/s390x/s390-pci-vfio.c | 2 +- include/hw/s390x/{ => ipl}/s390-pci-clp.h | 0 include/hw/s390x/s390-pci-bus.h | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename include/hw/s390x/{ => ipl}/s390-pci-clp.h (100%)
Re: [PATCH v3 06/14] include/hw/s390x: Move CLP definitions for easier BIOS access
Quoted 16 lines · Eric Farman
Quoted 6 lines · On Tue, 2026-01-27 at 11:15 -0500, [email protected] wrote:
From: Jared Rossi <[email protected]>
Move the s390-pci-clp definitions into the "ipl" sub-directory, which is visible to the s390-bios. This allows the bios to reuse the architected definitions and prevents code duplication.
Quoted 8 lines
Reviewed-by Thomas Huth <[email protected]>Signed-off-by Jared Rossi <[email protected]>--- hw/s390x/s390-pci-vfio.c | 2 +- include/hw/s390x/{ => ipl}/s390-pci-clp.h | 0 include/hw/s390x/s390-pci-bus.h | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename include/hw/s390x/{ => ipl}/s390-pci-clp.h (100%)
Quoted 1 line
Reviewed-by Eric Farman <[email protected]>
Actually, small nit that popped into my head on the drive home... Could you update MAINTAINERS so that we don't lose the PCI CLP header file from the S390 PCI group?
Re: [PATCH v3 06/14] include/hw/s390x: Move CLP definitions for easier BIOS access
Quoted 16 lines · Eric Farman
Quoted 15 lines · Eric Farman
Quoted 14 lines · On Tue, 2026-01-27 at 11:15 -0500, [email protected] wrote:
From: Jared Rossi <[email protected]>
Move the s390-pci-clp definitions into the "ipl" sub-directory, which is visible to the s390-bios. This allows the bios to reuse the architected definitions and prevents code duplication.
Reviewed-by Thomas Huth <[email protected]>Signed-off-by Jared Rossi <[email protected]>--- hw/s390x/s390-pci-vfio.c | 2 +- include/hw/s390x/{ => ipl}/s390-pci-clp.h | 0 include/hw/s390x/s390-pci-bus.h | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-)rename
include/hw/s390x/{=>ipl}/s390-pci-clp.h(100%)
Quoted 3 lines
Quoted 1 line
Reviewed-by Eric Farman <[email protected]>Actually, small nit that popped into my head on the drive home... Could you update
MAINTAINERSso that we don't lose the PCI CLP header file from the S390 PCI group?
Sure thing, will do.
Thanks again for the reviews,
Jared Rossi
Re: [PATCH v3 06/14] include/hw/s390x: Move CLP definitions for easier BIOS access
In reply to [email protected]Quoted 8 lines · On 1/27/26 11:15 AM, [email protected] wrote:
From: Jared Rossi <[email protected]>
Move the s390-pci-clp definitions into the "ipl" sub-directory, which is visible to the s390-bios. This allows the bios to reuse the architected definitions and prevents code duplication.
Reviewed-by Thomas Huth <[email protected]>Signed-off-by Jared Rossi <[email protected]>
PATCH v3 7/14 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.
--- pc-bios/s390-ccw/Makefile | 2 +- pc-bios/s390-ccw/clp.c | 96 +++++++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/clp.h | 24 ++++++++++ 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 pc-bios/s390-ccw/clp.c create mode 100644 pc-bios/s390-ccw/clp.h
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
pc-bios/s390-ccw/clp.c new file +96 -0
96 lines not on this page · raw message
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 <s390-pci-clp.h> + +int clp_pci (void *data); +int find_pci_function (uint32_t fid,ClpFhListEntry *entry); +int enable_pci_function (uint32_t *fhandle); + +#endif
Signature · 1 line
2.52.0
Re: [PATCH v3 07/14] pc-bios/s390-ccw: Introduce CLP Architecture
Quoted 51 lines · On 27/01/2026 17.15, [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.
Signed-off-by Jared Rossi <[email protected]>--- pc-bios/s390-ccw/Makefile | 2 +- pc-bios/s390-ccw/clp.c | 96 +++++++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/clp.h | 24 ++++++++++ 3 files changed, 121 insertions(+), 1 deletion(-)create mode 100644
pc-bios/s390-ccw/clp.c
create mode 100644pc-bios/s390-ccw/clp.hpc-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/SLOFpc-bios/s390-ccw/clp.c new file +17
-0@@ -0,0 +1,96 @@ +/* +* Call Logical Processor (CLP) architecture +* +* Copyright 2025 IBM Corp. +* Author(s): Jared Rossi <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "clp.h" +#include <stdio.h> +#include <string.h> + +int clp_pci (void *data) +{ +struct {uint8_t _[2048 ]; } *req = data; +int cc =3 ;
pc-bios/s390-ccw/clp.c line 27
Quoted 10 lines
pc-bios/s390-ccw/clp.c new file +10
-0+ + asmvolatile ( +" .insn rrf,0xb9a00000,0,%[req],0,2\n" +" ipm %[cc]\n" +" srl %[cc],28\n" + : [cc]"+d" (cc),"+m" (*req) + : [req]"a" (req) + :"cc" ); +return cc; +}
Since this instruction is not part of the public Principles of Operation, I'd appreciate if someone from IBM could review this patch.
From my side, I can only provide:
Re: [PATCH v3 07/14] pc-bios/s390-ccw: Introduce CLP Architecture
Quoted 3 lines
Since this instruction is not part of the public Principles of Operation, I'd appreciate if someone from IBM could review this patch.
ACK, will get to this in the next couple of days if someone else (e.g. Eric or Farhan) doesn't beat me to it.
Thanks,
Matt
Re: [PATCH v3 07/14] pc-bios/s390-ccw: Introduce CLP Architecture
In reply to [email protected]Quoted 6 lines · On Tue, 2026-01-27 at 11:15 -0500, [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.
Quoted 8 lines
Signed-off-by Jared Rossi <[email protected]>--- pc-bios/s390-ccw/Makefile | 2 +- pc-bios/s390-ccw/clp.c | 96 +++++++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/clp.h | 24 ++++++++++ 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 pc-bios/s390-ccw/clp.c create mode 100644 pc-bios/s390-ccw/clp.h
First off, this looks like correct according to my reading.
My only question is whether we need any breadcrumbs in case things fail? Dumping the requested FID in case of an enable, or the response code in either case? (I haven't gotten to the later patches yet, just looking at the puts here has me wondering if that's enough of a clue.)
Quoted 146 lines
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/SLOFpc-bios/s390-ccw/clp.c new file +96
-0@@ -0,0 +1,96 @@ +/* +* Call Logical Processor (CLP) architecture +* +* Copyright 2025 IBM Corp. +* Author(s): Jared Rossi <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "clp.h" +#include <stdio.h> +#include <string.h> + +int clp_pci (void *data) +{ +struct {uint8_t _[2048 ]; } *req = data; +int cc =3 ; + + asmvolatile ( +" .insn rrf,0xb9a00000,0,%[req],0,2\n" +" ipm %[cc]\n" +" srl %[cc],28\n" + : [cc]"+d" (cc),"+m" (*req) + : [req]"a" (req) + :"cc" ); +return cc; +} + +/* +* Get the PCI function entry for a given function ID +* Return 0 on success, 1 if the FID is not found, or a negative RC on error +*/ +int find_pci_function (uint32_t fid,ClpFhListEntry *entry) +{ +int count =0 ; +int limit =PCI_MAX_FUNCTIONS ; +ClpReqRspListPci rrb; + + rrb.request.hdr.len =32 ; + rrb.request.hdr.cmd =0x02 ; + rrb.request.resume_token =0 ; + rrb.response.hdr.len =sizeof (ClpRspListPci); + +do { +if (clp_pci (&rrb) || rrb.response.hdr.rsp !=0x0010 ) { +puts ("Failed to list PCI functions" ); +return -1 ; + } + +/* Resume token set when max enteries are returned */ +if (rrb.response.resume_token) { + count =CLP_FH_LIST_NR_ENTRIES ; + rrb.request.resume_token = rrb.response.resume_token; + }else { + count = (rrb.response.hdr.len -32 ) /sizeof (ClpFhListEntry); + } + + limit -= count; + +for (int i =0 ; i < count; i++) { +if (rrb.response.fh_list[i].fid == fid) { +memcpy (entry, &rrb.response.fh_list[i],sizeof (ClpFhListEntry)); +return 0 ; + } + } + + }while (rrb.request.resume_token && limit >0 ); + +puts ("No function entry found for FID!" ); + +return 1 ; +} + +/* +* Enable the PCI function associated with a given handle +* Return 0 on success or a negative RC on error +*/ +int enable_pci_function (uint32_t *fhandle) +{ +ClpReqRspSetPci rrb; + + rrb.request.hdr.len =32 ; + rrb.request.hdr.cmd =0x05 ; + rrb.request.fh = *fhandle; + rrb.request.oc =0 ; + rrb.request.ndas =1 ; + rrb.response.hdr.len =32 ; + +if (clp_pci (&rrb) || rrb.response.hdr.rsp !=0x0010 ) { +puts ("Failed to enable PCI function" ); +return -1 ; + } + + *fhandle = rrb.response.fh; +return 0 ; +}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 <s390-pci-clp.h> + +int clp_pci (void *data); +int find_pci_function (uint32_t fid,ClpFhListEntry *entry); +int enable_pci_function (uint32_t *fhandle); + +#endif
Re: [PATCH v3 07/14] pc-bios/s390-ccw: Introduce CLP Architecture
Quoted 15 lines · Eric Farman
Quoted 6 lines · On Tue, 2026-01-27 at 11:15 -0500, [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.
Quoted 8 lines
Signed-off-by Jared Rossi <[email protected]>--- pc-bios/s390-ccw/Makefile | 2 +- pc-bios/s390-ccw/clp.c | 96 +++++++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/clp.h | 24 ++++++++++ 3 files changed, 121 insertions(+), 1 deletion(-)create mode 100644
pc-bios/s390-ccw/clp.c
create mode 100644pc-bios/s390-ccw/clp.h
Quoted 5 lines
First off, this looks like correct according to my reading.
My only question is whether we need any breadcrumbs in case things fail? Dumping the requested FID in case of an enable, or the response code in either case? (I haven't gotten to the later patches yet, just looking at the puts here has me wondering if that's enough of a clue.)
Improving the logging makes sense; I'll add more useful output.
Thanks,
Jared Rossi
Quoted 146 lines
Quoted 146 lines
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/SLOFpc-bios/s390-ccw/clp.c new file +96
-0@@ -0,0 +1,96 @@ +/* +* Call Logical Processor (CLP) architecture +* +* Copyright 2025 IBM Corp. +* Author(s): Jared Rossi <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "clp.h" +#include <stdio.h> +#include <string.h> + +int clp_pci (void *data) +{ +struct {uint8_t _[2048 ]; } *req = data; +int cc =3 ; + + asmvolatile ( +" .insn rrf,0xb9a00000,0,%[req],0,2\n" +" ipm %[cc]\n" +" srl %[cc],28\n" + : [cc]"+d" (cc),"+m" (*req) + : [req]"a" (req) + :"cc" ); +return cc; +} + +/* +* Get the PCI function entry for a given function ID +* Return 0 on success, 1 if the FID is not found, or a negative RC on error +*/ +int find_pci_function (uint32_t fid,ClpFhListEntry *entry) +{ +int count =0 ; +int limit =PCI_MAX_FUNCTIONS ; +ClpReqRspListPci rrb; + + rrb.request.hdr.len =32 ; + rrb.request.hdr.cmd =0x02 ; + rrb.request.resume_token =0 ; + rrb.response.hdr.len =sizeof (ClpRspListPci); + +do { +if (clp_pci (&rrb) || rrb.response.hdr.rsp !=0x0010 ) { +puts ("Failed to list PCI functions" ); +return -1 ; + } + +/* Resume token set when max enteries are returned */ +if (rrb.response.resume_token) { + count =CLP_FH_LIST_NR_ENTRIES ; + rrb.request.resume_token = rrb.response.resume_token; + }else { + count = (rrb.response.hdr.len -32 ) /sizeof (ClpFhListEntry); + } + + limit -= count; + +for (int i =0 ; i < count; i++) { +if (rrb.response.fh_list[i].fid == fid) { +memcpy (entry, &rrb.response.fh_list[i],sizeof (ClpFhListEntry)); +return 0 ; + } + } + + }while (rrb.request.resume_token && limit >0 ); + +puts ("No function entry found for FID!" ); + +return 1 ; +} + +/* +* Enable the PCI function associated with a given handle +* Return 0 on success or a negative RC on error +*/ +int enable_pci_function (uint32_t *fhandle) +{ +ClpReqRspSetPci rrb; + + rrb.request.hdr.len =32 ; + rrb.request.hdr.cmd =0x05 ; + rrb.request.fh = *fhandle; + rrb.request.oc =0 ; + rrb.request.ndas =1 ; + rrb.response.hdr.len =32 ; + +if (clp_pci (&rrb) || rrb.response.hdr.rsp !=0x0010 ) { +puts ("Failed to enable PCI function" ); +return -1 ; + } + + *fhandle = rrb.response.fh; +return 0 ; +}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 <s390-pci-clp.h> + +int clp_pci (void *data); +int find_pci_function (uint32_t fid,ClpFhListEntry *entry); +int enable_pci_function (uint32_t *fhandle); + +#endif
Re: [PATCH v3 07/14] pc-bios/s390-ccw: Introduce CLP Architecture
In reply to [email protected]Quoted 40 lines · On 1/27/2026 8:15 AM, [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.
Signed-off-by Jared Rossi <[email protected]>--- pc-bios/s390-ccw/Makefile | 2 +- pc-bios/s390-ccw/clp.c | 96 +++++++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/clp.h | 24 ++++++++++ 3 files changed, 121 insertions(+), 1 deletion(-)create mode 100644
pc-bios/s390-ccw/clp.c
create mode 100644pc-bios/s390-ccw/clp.hpc-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/SLOFpc-bios/s390-ccw/clp.c new file +6
-0@@ -0,0 +1,96 @@ +/* +* Call Logical Processor (CLP) architecture +* +* Copyright 2025 IBM Corp. +* Author(s): Jared Rossi <[email protected]> +*
pc-bios/s390-ccw/clp.c line 16
Quoted 10 lines
pc-bios/s390-ccw/clp.c new file +10
-0+* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "clp.h" +#include <stdio.h> +#include <string.h> + +int clp_pci (void *data) +{ +struct {uint8_t _[2048 ]; } *req = data;
The architecture specifies that size of the request + response block size can be maximum of 8192 bytes. If I understand correctly I think QEMU (similar to kernel) uses CLP_BLK_SIZE when calculating the CLP_FH_LIST_NR_ENTRIES, so it assumes that the request + response block is 4096. So we can return more than 2048 bytes here and overflow.
I think we should use at least CLP_BLK_SIZE here instead of 2048 or set this to the maximum possible value of 8192.
Thanks
Farhan
Quoted 13 lines
pc-bios/s390-ccw/clp.c new file +12
-0+int cc =3 ; + + asmvolatile ( +" .insn rrf,0xb9a00000,0,%[req],0,2\n" +" ipm %[cc]\n" +" srl %[cc],28\n" + : [cc]"+d" (cc),"+m" (*req) + : [req]"a" (req) + :"cc" ); +return cc; +} +
Re: [PATCH v3 07/14] pc-bios/s390-ccw: Introduce CLP Architecture
Quoted 52 lines · Farhan Ali
Quoted 37 lines · On 1/27/2026 8:15 AM, [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.
Signed-off-by Jared Rossi <[email protected]>---
pc-bios/s390-ccw/Makefile | 2 +-
pc-bios/s390-ccw/clp.c | 96 +++++++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/clp.h | 24 ++++++++++3 files changed, 121 insertions(+), 1 deletion(-)create mode 100644
pc-bios/s390-ccw/clp.c
create mode 100644pc-bios/s390-ccw/clp.hpc-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
diff --gita/pc-bios/s390-ccw/clp.cb/pc-bios/s390-ccw/clp.cnew file mode 100644
index 0000000000..2a14bb9b73pc-bios/s390-ccw/clp.c new file +6
-0@@ -0,0 +1,96 @@ +/* +* Call Logical Processor (CLP) architecture +* +* Copyright 2025 IBM Corp. +* Author(s): Jared Rossi <[email protected]> +* pc-bios/s390-ccw/clp.c line 16
Quoted 10 lines
pc-bios/s390-ccw/clp.c new file +10
-0+* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "clp.h" +#include <stdio.h> +#include <string.h> + +int clp_pci (void *data) +{ + struct { uint8_t _[2048]; } *req = data;The architecture specifies that size of the request + response block size can be maximum of 8192 bytes. If I understand correctly I think QEMU (similar to kernel) uses
CLP_BLK_SIZEwhen calculating theCLP_FH_LIST_NR_ENTRIES, so it assumes that the request + response block is 4096. So we can return more than 2048 bytes here and overflow.
Quoted 5 lines
I think we should use at least
CLP_BLK_SIZEhere instead of 2048 or set this to the maximum possible value of 8192.Thanks
Farhan
Thanks for pointing that out, I'll fix it.
Regards,
Jared Rossi
Quoted 14 lines
Quoted 14 lines
pc-bios/s390-ccw/clp.c new file +12
-0+ int cc = 3; + + asm volatile ( + " .insn rrf,0xb9a00000,0,%[req],0,2\n" + " ipm %[cc]\n" + " srl %[cc],28\n" + : [cc] "+d" (cc), "+m" (*req) + : [req] "a" (req) + : "cc"); + return cc; +} +
PATCH v3 8/14 s390x: Add definitions for PCI IPL type
In reply to [email protected]From: Jared Rossi <[email protected]>
Define a new PBT code and IPLB layout in preperation for supporting PCI device IPL on s390x.
--- include/hw/s390x/ipl/qipl.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/hw/s390x/ipl/qipl.h +10 -0
@@ -23,6 +23,7 @@enum S390IplType {S390_IPL_TYPE_FCP =0x00 ,S390_IPL_TYPE_CCW =0x02 , +S390_IPL_TYPE_PCI =0x04 ,S390_IPL_TYPE_PV =0x05 ,S390_IPL_TYPE_QEMU_SCSI =0xff };
@@ -108,6 +109,14 @@ struct IplBlockQemuScsi { }QEMU_PACKED ;typedef struct IplBlockQemuScsi IplBlockQemuScsi ; +struct IplBlockPci { +uint32_t reserved0[76 ]; +uint8_t opt; +uint8_t reserved1[3 ]; +uint32_t fid; +}QEMU_PACKED ; +typedef struct IplBlockPci IplBlockPci ; + union IplParameterBlock { struct { uint32_t len;
@@ -123,6 +132,7 @@ union IplParameterBlock {IplBlockFcp fcp;IPLBlockPV pv;IplBlockQemuScsi scsi; +IplBlockPci pci; }; }QEMU_PACKED ;struct {
Signature · 1 line
2.52.0
Re: [PATCH v3 08/14] s390x: Add definitions for PCI IPL type
Quoted 38 lines · On 27/01/2026 17.15, [email protected] wrote:
From: Jared Rossi <[email protected]>
Define a new PBT code and IPLB layout in preperation for supporting PCI device IPL on s390x.
Signed-off-by Jared Rossi <[email protected]>--- include/hw/s390x/ipl/qipl.h | 10 ++++++++++ 1 file changed, 10 insertions(+)include/hw/s390x/ipl/qipl.h +9
-0@@ -23,6 +23,7 @@enum S390IplType {S390_IPL_TYPE_FCP =0x00 ,S390_IPL_TYPE_CCW =0x02 , +S390_IPL_TYPE_PCI =0x04 ,S390_IPL_TYPE_PV =0x05 ,S390_IPL_TYPE_QEMU_SCSI =0xff };@@ -108,6 +109,14 @@ struct IplBlockQemuScsi { }QEMU_PACKED ;typedef struct IplBlockQemuScsi IplBlockQemuScsi ; +struct IplBlockPci { +uint32_t reserved0[76 ]; +uint8_t opt; +uint8_t reserved1[3 ]; +uint32_t fid; +}QEMU_PACKED ; +typedef struct IplBlockPci IplBlockPci ; + union IplParameterBlock { struct { uint32_t len;
include/hw/s390x/ipl/qipl.h union IplParameterBlock { · line 138
Quoted 7 lines
include/hw/s390x/ipl/qipl.h +1
-0@@ -123,6 +132,7 @@ union IplParameterBlock {IplBlockFcp fcp;IPLBlockPV pv;IplBlockQemuScsi scsi; +IplBlockPci pci; }; }QEMU_PACKED ;struct {
Re: [PATCH v3 08/14] s390x: Add definitions for PCI IPL type
In reply to [email protected]Quoted 3 lines · On Tue, 2026-01-27 at 11:15 -0500, [email protected] wrote:
From: Jared Rossi <[email protected]>
Define a new PBT code and IPLB layout in preperation for supporting PCI device
s/preperation/preparation/
Quoted 6 lines
IPL on s390x.
Signed-off-by Jared Rossi <[email protected]>--- include/hw/s390x/ipl/qipl.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
PATCH v3 9/14 pc-bios/s390-ccw: Introduce PCI device
In reply to [email protected]From: Jared Rossi <[email protected]>
Define selected s390x PCI instructions.
--- pc-bios/s390-ccw/Makefile | 2 +- pc-bios/s390-ccw/pci.c | 194 ++++++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/pci.h | 80 ++++++++++++++++ 3 files changed, 275 insertions(+), 1 deletion(-) create mode 100644 pc-bios/s390-ccw/pci.c create mode 100644 pc-bios/s390-ccw/pci.h
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
pc-bios/s390-ccw/pci.c new file +194 -0
194 lines not on this page · raw message
pc-bios/s390-ccw/pci.h new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.52.0
Re: [PATCH v3 09/14] pc-bios/s390-ccw: Introduce PCI device
Quoted 6 lines · On 27/01/2026 17.15, [email protected] wrote:
From: Jared Rossi <[email protected]>
Define selected s390x PCI instructions.
Signed-off-by Jared Rossi <[email protected]>---
...
Quoted 56 lines
pc-bios/s390-ccw/pci.h new file +50
-0@@ -0,0 +1,80 @@ +/* +* 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 <stdbool.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_CFGBAR 0xF /* Base Address Register for config space */ +#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;
pc-bios/s390-ccw/pci.h line 60
Quoted 10 lines
pc-bios/s390-ccw/pci.h new file +10
-0+ 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 ;
I can't comment on the gory details here since I don't have the spec, but from a distance, the patch looks fine to me now.
Re: [PATCH v3 09/14] pc-bios/s390-ccw: Introduce PCI device
In reply to [email protected]Quoted 32 lines · On Tue, 2026-01-27 at 11:15 -0500, [email protected] wrote:
From: Jared Rossi <[email protected]>
Define selected s390x PCI instructions.
Signed-off-by Jared Rossi <[email protected]>--- pc-bios/s390-ccw/Makefile | 2 +- pc-bios/s390-ccw/pci.c | 194 ++++++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/pci.h | 80 ++++++++++++++++ 3 files changed, 275 insertions(+), 1 deletion(-) create mode 100644 pc-bios/s390-ccw/pci.c create mode 100644 pc-bios/s390-ccw/pci.hpc-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/SLOFpc-bios/s390-ccw/pci.c new file +0
-0
pc-bios/s390-ccw/pci.c line 2
Quoted 2 lines
pc-bios/s390-ccw/pci.c new file +2
-0@@ -0,0 +1,194 @@ +/* +* s390x PCI funcionality
functionality
Quoted 147 lines
pc-bios/s390-ccw/pci.c new file +147
-0+* +* 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 "bswap.h" +#include <stdio.h> +#include <stdbool.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; + + 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 */ +static inline 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 */ +static inline 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 */ +static inline 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,uint8_t pcias,uint64_t data, +uint8_t len) +{ + +uint64_t req =ZPCI_CREATE_REQ (fhandle, pcias, len); +uint8_t status; +int rc; + +/* len must be non-zero power of 2 with a maximum of 8 bytes per write */ +switch (len) { +case 1 : +case 2 : +case 4 : +case 8 : + rc =pcistg (data, req, offset, &status); +break ; +default : + rc =-1 ; + } + +/* Error condition detected */ +if (rc ==1 ) { +printf ("PCI store failed with status condition %d\n" , status); +return -1 ; + } + +return rc ?-1 :0 ; +} + +int pci_read (uint32_t fhandle,uint64_t offset,uint8_t pcias,void *buf, +uint8_t len) +{ +uint64_t req, data; +uint8_t status; +int rc; + + req =ZPCI_CREATE_REQ (fhandle, pcias, len); + rc =pcilg (&data, req, offset, &status); + +/* Error condition detected */ +if (rc ==1 ) { +printf ("PCI load failed with status condition %d\n" , status); +return -1 ; + } + +switch (len) { +case 1 : + *(uint8_t *)buf = data; +break ; +case 2 : + *(uint16_t *)buf = data; +break ; +case 4 : + *(uint32_t *)buf = data; +break ; +case 8 : + *(uint64_t *)buf = data; +break ; +default : +return -1 ; + } + +return rc ?-1 :0 ; +} + +int pci_dev_enable (PciDevice *pcidev) +{
pc-bios/s390-ccw/pci.c line 159
Quoted 10 lines
pc-bios/s390-ccw/pci.c new file +10
-0+int rc; + + rc =enable_pci_function (&pcidev->fhandle); +if (rc) { +return rc; + } + + pcidev->status =PCIST_ENABLED ; + +return pci_get_fib (&pcidev->fib, pcidev->fhandle);
Is pcidev->status meant to be left "enabled" if this fails? Seems that the error cases would be unexpected, but severe.
Oh... But pci_dev_enable doesn't seem to be called anywhere (enable_pci_function is called by virtio_pci_setup_device, in patch 11). Nor pci_get/set_fib below... So maybe all these chunks are not needed? (Ditto the related structs in pci.h, below)
Quoted 121 lines
pc-bios/s390-ccw/pci.c new file +35
-0+} + +int pci_get_fib (PciFib *fib,uint32_t fhandle) +{ +uint64_t req =ZPCI_CREATE_REQ (fhandle,0 ,0 ); +uint8_t status; +int rc; + + rc =stpcifc (req, fib, &status); + +if (rc ==1 ) { +return status; + }else if (rc) { +return rc; + } + +return 0 ; +} + +int pci_set_fib (PciFib *fib,uint32_t fhandle,uint8_t dma_as,uint8_t opcontrol) +{ +uint64_t req =ZPCI_CREATE_REQ (fhandle, dma_as, opcontrol); +uint8_t status; +int rc; + + rc =mpcifc (req, fib, &status); + +if (rc ==1 ) { +return status; + }else if (rc) { +return rc; + } + +return 0 ; +}pc-bios/s390-ccw/pci.h new file +80
-0@@ -0,0 +1,80 @@ +/* +* 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 <stdbool.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_CFGBAR 0xF/* Base Address Register for config space */ +#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_dev_enable (PciDevice *pcidev); +int pci_get_fib (PciFib *fib,uint32_t fhandle); +int pci_set_fib (PciFib *fib,uint32_t fhandle,uint8_t dma_as,uint8_t opcontrol); +int pci_write (uint32_t fhandle,uint64_t offset,uint8_t pcias,uint64_t data, +uint8_t len); +int pci_read (uint32_t fhandle,uint64_t offset,uint8_t pcias,void *buf, +uint8_t len); + +#endif
Re: [PATCH v3 09/14] pc-bios/s390-ccw: Introduce PCI device
In reply to [email protected]Quoted 43 lines · On 1/27/2026 8:15 AM, [email protected] wrote:
From: Jared Rossi <[email protected]>
Define selected s390x PCI instructions.
Signed-off-by Jared Rossi <[email protected]>--- pc-bios/s390-ccw/Makefile | 2 +- pc-bios/s390-ccw/pci.c | 194 ++++++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/pci.h | 80 ++++++++++++++++ 3 files changed, 275 insertions(+), 1 deletion(-)create mode 100644
pc-bios/s390-ccw/pci.c
create mode 100644pc-bios/s390-ccw/pci.hpc-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/SLOFpc-bios/s390-ccw/pci.c new file +11
-0@@ -0,0 +1,194 @@ +/* +* 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"
pc-bios/s390-ccw/pci.c line 21
Quoted 10 lines
pc-bios/s390-ccw/pci.c new file +10
-0+#include "bswap.h" +#include <stdio.h> +#include <stdbool.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 ;
Nit: Setting cc = -1 doesn't make any difference since the cc gets overwritten and the pcilg will return cc > 0.
Quoted 9 lines
pc-bios/s390-ccw/pci.c new file +9
-0+uint64_t __data; + + 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 ;
pc-bios/s390-ccw/pci.c line 40
Quoted 10 lines
pc-bios/s390-ccw/pci.c new file +10
-0+ *data = __data; +return cc; +} + +/* PCI store */ +static inline 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 ;
Nit: Same as pcilg.
Quoted 54 lines
pc-bios/s390-ccw/pci.c new file +54
-0+ + 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 */ +static inline 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 */ +static inline 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,uint8_t pcias,uint64_t data, +uint8_t len) +{ + +uint64_t req =ZPCI_CREATE_REQ (fhandle, pcias, len); +uint8_t status; +int rc; + +/* len must be non-zero power of 2 with a maximum of 8 bytes per write */ +switch (len) { +case 1 : +case 2 :
pc-bios/s390-ccw/pci.c line 104
Quoted 10 lines
pc-bios/s390-ccw/pci.c new file +10
-0+case 4 : +case 8 : + rc =pcistg (data, req, offset, &status); +break ; +default : + rc =-1 ; + } + +/* Error condition detected */ +if (rc ==1 ) {
According to the architecture a return code of 0 would indicate normal completion. But we do have error scenarios that can return error code > 1. For example an error code of 3 would indicate 'Unrecognized handle'. May we should check for non-zero rc in this if condition...
pc-bios/s390-ccw/pci.c line 105
Quoted 1 line
pc-bios/s390-ccw/pci.c new file +1
-0+printf ("PCI store failed with status condition %d\n" , status);
... and print both the rc and status here.
Quoted 8 lines
pc-bios/s390-ccw/pci.c new file +8
-0+return -1 ; + } + +return rc ?-1 :0 ; +} + +int pci_read (uint32_t fhandle,uint64_t offset,uint8_t pcias,void *buf, +uint8_t len)
pc-bios/s390-ccw/pci.c line 123
Quoted 10 lines
pc-bios/s390-ccw/pci.c new file +10
-0+{ +uint64_t req, data; +uint8_t status; +int rc; + + req =ZPCI_CREATE_REQ (fhandle, pcias, len); + rc =pcilg (&data, req, offset, &status); + +/* Error condition detected */ +if (rc ==1 ) {
Similar to pci_write we should check for non-zero return code here? And should do the same in pci_get_fib (stpcifc) and pci_set_fib (mpcifc)?
Quoted 24 lines
pc-bios/s390-ccw/pci.c new file +24
-0+printf ("PCI load failed with status condition %d\n" , status); +return -1 ; + } + +switch (len) { +case 1 : + *(uint8_t *)buf = data; +break ; +case 2 : + *(uint16_t *)buf = data; +break ; +case 4 : + *(uint32_t *)buf = data; +break ; +case 8 : + *(uint64_t *)buf = data; +break ; +default : +return -1 ; + } + +return rc ?-1 :0 ; +} +
<...snip...>
PATCH v3 10/14 pc-bios/s390-ccw: Introduce virtio-pci functions
In reply to [email protected]From: Jared Rossi <[email protected]>
Define common functionality for interacting with virtio-pci devices.
--- pc-bios/s390-ccw/Makefile | 2 +- pc-bios/s390-ccw/virtio-pci.c | 168 ++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/virtio-pci.h | 86 +++++++++++++++++ pc-bios/s390-ccw/virtio.h | 1 + 4 files changed, 256 insertions(+), 1 deletion(-) create mode 100644 pc-bios/s390-ccw/virtio-pci.c create mode 100644 pc-bios/s390-ccw/virtio-pci.h
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
pc-bios/s390-ccw/virtio-pci.c new file +168 -0
168 lines not on this page · raw message
pc-bios/s390-ccw/virtio-pci.h new file +86 -0
86 lines not on this page · raw message
pc-bios/s390-ccw/virtio.h +1 -0
@@ -255,6 +255,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 ]; };
Signature · 1 line
2.52.0
Re: [PATCH v3 10/14] pc-bios/s390-ccw: Introduce virtio-pci functions
Quoted 6 lines · On 27/01/2026 17.15, [email protected] wrote:
From: Jared Rossi <[email protected]>
Define common functionality for interacting with virtio-pci devices.
Signed-off-by Jared Rossi <[email protected]>---
...
pc-bios/s390-ccw/virtio-pci.c line 52
Quoted 5 lines
pc-bios/s390-ccw/virtio-pci.c new file +5
-0+/* virtio spec v1.3 section 4.1.2.1 */ +void virtio_pci_id2type (VDev *vdev,uint16_t device_id) +{ +switch (device_id) { +case 0x1001 :
When using modern-only mode for a virtio-block device ("-device virtio-blk-pci,disable-legacy=on,..."), the virtio-block device should come up with a different device ID, I think it's 0x1042 ... shouldn't this get added here, too?
pc-bios/s390-ccw/virtio-pci.c line 90
Quoted 7 lines
pc-bios/s390-ccw/virtio-pci.c new file +7
-0+/* +* Wrappers to byte swap common data sizes then write +*/ +int vpci_write_byte (uint64_t offset,uint8_t pcias,uint8_t data) +{ +return pci_write (virtio_get_device ()->pci_fh, offset, pcias, (uint64_t ) data,1 ); +}
I'm a little bit torn ... would it be nicer to have a "VDev *vdev" as a parameter for these functions, so we don't have this hidden state via virtio_get_device() here? ... OTOH, that makes the calling functions a little bit more clunky ... does anybody else got an opinion on this?
Thomas
Re: [PATCH v3 10/14] pc-bios/s390-ccw: Introduce virtio-pci functions
In reply to [email protected]Quoted 258 lines · On Tue, 2026-01-27 at 11:15 -0500, [email protected] wrote:
From: Jared Rossi <[email protected]>
Define common functionality for interacting with virtio-pci devices.
Signed-off-by Jared Rossi <[email protected]>--- pc-bios/s390-ccw/Makefile | 2 +- pc-bios/s390-ccw/virtio-pci.c | 168 ++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/virtio-pci.h | 86 +++++++++++++++++ pc-bios/s390-ccw/virtio.h | 1 + 4 files changed, 256 insertions(+), 1 deletion(-) create mode 100644 pc-bios/s390-ccw/virtio-pci.c create mode 100644 pc-bios/s390-ccw/virtio-pci.hpc-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/SLOFpc-bios/s390-ccw/virtio-pci.c new file +168
-0@@ -0,0 +1,168 @@ +/* +* 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 "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 regions */ +VirtioPciCap c_cap;/* Common capabilities */ +VirtioPciCap d_cap;/* Device capabilities */ +VirtioPciCap n_cap;/* Notify capabilities */ +uint32_t notify_mult; +uint16_t q_notify_offset; + +static int virtio_pci_set_status (uint8_t status) +{ +int rc =vpci_write_byte (c_cap.off +VPCI_C_OFFSET_STATUS , c_cap.bar, status); +if (rc) { +puts ("Failed to write virtio-pci status" ); +return -EIO ; + } + +return 0 ; +} + +static int virtio_pci_get_status (uint8_t *status) +{ +int rc =vpci_read_byte (c_cap.off +VPCI_C_OFFSET_STATUS , c_cap.bar, status); +if (rc) { +puts ("Failed to read virtio-pci status" ); +return -EIO ; + } + +return 0 ; +} + +/* virtio spec v1.3 section 4.1.2.1 */ +void virtio_pci_id2type (VDev *vdev,uint16_t device_id) +{ +switch (device_id) { +case 0x1001 : + vdev->dev_type =VIRTIO_ID_BLOCK ; +break ; +case 0x1000 :/* Other valid but currently unsupported virtio device types */ +case 0x1004 : +default : + vdev->dev_type =0 ; + } +} + +int virtio_pci_reset (VDev *vdev) +{ +int rc; +uint8_t status =VPCI_S_RESET ; + + rc =virtio_pci_set_status (status); + rc |=virtio_pci_get_status (&status); + +if (rc || status) { +puts ("Failed to reset virtio-pci device" ); +return 1 ; + } + +return 0 ; +} + +long virtio_pci_notify (int vq_id) +{ +uint32_t offset = n_cap.off + notify_mult * q_notify_offset; +return vpci_bswap16_write (offset, n_cap.bar, (uint16_t ) vq_id); +} + +/* +* Wrappers to byte swap common data sizes then write +*/ +int vpci_write_byte (uint64_t offset,uint8_t pcias,uint8_t data) +{ +return pci_write (virtio_get_device ()->pci_fh, offset, pcias, (uint64_t ) data,1 ); +} + +int vpci_bswap16_write (uint64_t offset,uint8_t pcias,uint16_t data) +{ +uint64_t le_data =bswap16 (data); +return pci_write (virtio_get_device ()->pci_fh, offset, pcias, le_data,2 ); +} + +int vpci_bswap32_write (uint64_t offset,uint8_t pcias,uint32_t data) +{ +uint64_t le_data =bswap32 (data); +return pci_write (virtio_get_device ()->pci_fh, offset, pcias, le_data,4 ); +} + +int vpci_bswap64_write (uint64_t offset,uint8_t pcias,uint64_t data) +{ +uint64_t le_data =bswap64 (data); +return pci_write (virtio_get_device ()->pci_fh, offset, pcias, le_data,8 ); +} + +/* +* Wrappers to read common data sizes then byte swap +*/ +int vpci_read_byte (uint64_t offset,uint8_t pcias,uint8_t *buf) +{ +return pci_read (virtio_get_device ()->pci_fh, offset, pcias, buf,1 ); +} + +int vpci_read_bswap16 (uint64_t offset,uint8_t pcias,uint16_t *buf) +{ +int rc =pci_read (virtio_get_device ()->pci_fh, offset, pcias, buf,2 ); + *buf =bswap16 (*buf); +return rc; +} + +int vpci_read_bswap32 (uint64_t offset,uint8_t pcias,uint32_t *buf) +{ +int rc =pci_read (virtio_get_device ()->pci_fh, offset, pcias, buf,4 ); + *buf =bswap32 (*buf); +return rc; +} + +int vpci_read_bswap64 (uint64_t offset,uint8_t pcias,uint64_t *buf) +{ +int rc =pci_read (virtio_get_device ()->pci_fh, offset, pcias, buf,8 ); + *buf =bswap64 (*buf); +return rc; +} + +/* +* Read to an arbitrary length buffer without byte swapping +*/ +int vpci_read_flex (uint64_t offset,uint8_t pcias,void *buf,int len) +{ +uint8_t readlen; +int rc; +int remaining = len; + +/* Read bytes in powers of 2, up to a maximum of 8 bytes per read */ +while (remaining) { +for (int i =3 ; i >=0 ; i--) { + readlen =1 << i; +if (remaining >= readlen) { +break ; + } + } + + rc =pci_read (virtio_get_device ()->pci_fh, offset, pcias, buf, readlen); +if (rc) { +return -1 ; + } + + remaining -= readlen; + buf += readlen; + offset += readlen; + } + +return 0 ; +}pc-bios/s390-ccw/virtio-pci.h new file +51
-0@@ -0,0 +1,86 @@ +/* +* 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 VPCI_CAP_COMMON_CFG 1 +/* Notifications */ +#define VPCI_CAP_NOTIFY_CFG 2 +/* ISR access */ +#define VPCI_CAP_ISR_CFG 3 +/* Device specific configuration */ +#define VPCI_CAP_DEVICE_CFG 4 +/* PCI configuration access */ +#define VPCI_CAP_PCI_CFG 5 +/* Additional shared memory capability */ +#define VPCI_CAP_SHARED_MEMORY_CFG 8 +/* PCI vendor data configuration */ +#define VPCI_CAP_VENDOR_CFG 9 + +/* Offsets within capability header */ +#define VPCI_CAP_VNDR 0 +#define VPCI_CAP_NEXT 1 +#define VPCI_CAP_LEN 2 +#define VPCI_CAP_CFG_TYPE 3 +#define VPCI_CAP_BAR 4 +#define VPCI_CAP_OFFSET 8 +#define VPCI_CAP_LENGTH 12 + +#define VPCI_N_CAP_MULT 16/* Notify multiplier, VPCI_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
pc-bios/s390-ccw/virtio-pci.h line 61
Quoted 10 lines
pc-bios/s390-ccw/virtio-pci.h new file +10
-0+#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
How are these status values different from VIRTIO_CONFIG_S_* in pc-bios/s390-ccw/virtio.h? Maybe expand that list instead?
The rest of this seems fine to me, though I do need another coffee.
Quoted 37 lines
pc-bios/s390-ccw/virtio-pci.h new file +25
-0+ +#define VIRTIO_F_VERSION_1 (1 << (32 - 32))/* Feature bit 32 */ + +struct VirtioPciCap { +uint8_t bar;/* Which PCIAS it's in */ +uint32_t off;/* Offset within bar */ +}; +typedef struct VirtioPciCap VirtioPciCap ; + +void virtio_pci_id2type (VDev *vdev,uint16_t device_id); +int virtio_pci_reset (VDev *vdev); +long virtio_pci_notify (int vq_id); + +int vpci_read_flex (uint64_t offset,uint8_t pcias,void *buf,int len); +int vpci_read_bswap64 (uint64_t offset,uint8_t pcias,uint64_t *buf); +int vpci_read_bswap32 (uint64_t offset,uint8_t pcias,uint32_t *buf); +int vpci_read_bswap16 (uint64_t offset,uint8_t pcias,uint16_t *buf); +int vpci_read_byte (uint64_t offset,uint8_t pcias,uint8_t *buf); + +int vpci_bswap64_write (uint64_t offset,uint8_t pcias,uint64_t data); +int vpci_bswap32_write (uint64_t offset,uint8_t pcias,uint32_t data); +int vpci_bswap16_write (uint64_t offset,uint8_t pcias,uint16_t data); +int vpci_write_byte (uint64_t offset,uint8_t pcias,uint8_t data); + +#endif pc-bios/s390-ccw/virtio.h +1
-0@@ -255,6 +255,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 ]; };
PATCH v3 11/14 pc-bios/s390-ccw: Add support for virtio-blk-pci IPL
In reply to [email protected]From: Jared Rossi <[email protected]>
Add little-endian virt-queue configuration and support for virtio-blk-pci IPL devices.
--- pc-bios/s390-ccw/main.c | 60 +++++++- pc-bios/s390-ccw/virtio-blkdev.c | 18 +++ pc-bios/s390-ccw/virtio-pci.c | 256 +++++++++++++++++++++++++++++++ pc-bios/s390-ccw/virtio-pci.h | 2 + pc-bios/s390-ccw/virtio.c | 46 +++++- pc-bios/s390-ccw/virtio.h | 1 + 6 files changed, 379 insertions(+), 4 deletions(-)
pc-bios/s390-ccw/main.c +58 -2
@@ -18,6 +18,8 @@#include "virtio.h" #include "virtio-scsi.h" #include "dasd-ipl.h" +#include "clp.h" +#include "virtio-pci.h" static SubChannelId blk_schid = { .one =1 };static char loadparm_str[LOADPARM_LEN +1 ];
@@ -151,6 +153,21 @@ 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->dev_type !=0 ; +} +static void menu_setup (void ) {if (memcmp (loadparm_str,LOADPARM_PROMPT ,LOADPARM_LEN ) ==0 ) {
@@ -239,6 +256,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" ); }
@@ -275,7 +295,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 :
@@ -288,7 +308,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->dev_type) { +case VIRTIO_ID_BLOCK : +if (virtio_setup () ==0 ) { +zipl_load (); + } +break ; +default : +printf ("Cannot boot PCI device type 0x%X\n" , vdev->dev_type); + } +} + +static void ipl_boot_device (void ) +{ +switch (virtio_get_device ()->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 +18 -0
@@ -13,10 +13,22 @@#include "virtio.h" #include "virtio-scsi.h" #include "virtio-ccw.h" +#include "virtio-pci.h" +#include "bswap.h" #define VIRTIO_BLK_F_GEOMETRY (1 << 4)#define VIRTIO_BLK_F_BLK_SIZE (1 << 6) +/* +* Format header for little endian IPL +*/ +static void fmt_blk_hdr_le (VirtioBlkOuthdr *hdr) +{ + hdr->type =bswap32 (hdr->type); + hdr->ioprio =bswap32 (hdr->ioprio); + hdr->sector =bswap64 (hdr->sector); +} +static int virtio_blk_read_many (VDev *vdev,unsigned long sector,void *load_addr,int sec_num) {
@@ -29,6 +41,10 @@ static int virtio_blk_read_many(VDev *vdev, unsigned long sector, void *load_add out_hdr.ioprio =99 ; out_hdr.sector =virtio_sector_adjust (sector); +if (!be_ipl ()) { +fmt_blk_hdr_le (&out_hdr); + } +vring_send_buf (vr, &out_hdr,sizeof (out_hdr),VRING_DESC_F_NEXT );/* This is where we want to receive data */
@@ -242,6 +258,8 @@ int virtio_blk_setup_device(void)case S390_IPL_TYPE_QEMU_SCSI :case S390_IPL_TYPE_CCW :return virtio_ccw_setup (vdev); +case S390_IPL_TYPE_PCI : +return virtio_pci_setup (vdev);default :return 1 ; }
pc-bios/s390-ccw/virtio-pci.c +256 -0
259 lines not on this page · raw message
pc-bios/s390-ccw/virtio-pci.h +2 -0
@@ -71,6 +71,8 @@ typedef struct VirtioPciCap VirtioPciCap;void virtio_pci_id2type (VDev *vdev,uint16_t device_id);int virtio_pci_reset (VDev *vdev);long virtio_pci_notify (int vq_id); +int virtio_pci_setup (VDev *vdev); +int virtio_pci_setup_device (void );int vpci_read_flex (uint64_t offset,uint8_t pcias,void *buf,int len);int vpci_read_bswap64 (uint64_t offset,uint8_t pcias,uint64_t *buf);
pc-bios/s390-ccw/virtio.c +44 -2
88 lines not on this page · raw message
pc-bios/s390-ccw/virtio.h +1 -0
@@ -271,6 +271,7 @@ struct VirtioCmd { };typedef struct VirtioCmd VirtioCmd ; +bool be_ipl (void );void vring_init (VRing *vr,VqInfo *info);bool virtio_is_supported (VDev *vdev);bool vring_notify (VRing *vr);
Signature · 1 line
2.52.0
Re: [PATCH v3 11/14] pc-bios/s390-ccw: Add support for virtio-blk-pci IPL
I found the following mistake after posting...
Quoted 15 lines
pc-bios/s390-ccw/virtio-pci.c +15
-0+int virtio_pci_setup (VDev *vdev) +{ +VRing *vr; +int rc; +uint8_t status; +int i =0 ; + + vdev->guessed_disk_nature =VIRTIO_GDN_NONE ; + vdev->cmd_vr_idx =0 ; + +if (virtio_reset (vdev)) { +return -EIO ; + } + + status =VPCI_S_ACKNOWLEDGE ;
pc-bios/s390-ccw/virtio-pci.c int vpci_read_flex(uint64_t offset, uint8_t pcias, void *buf, int len) · line 343
Quoted 10 lines
pc-bios/s390-ccw/virtio-pci.c +10
-0+if (virtio_pci_set_status (status)) { +puts ("Virtio-pci device Failed to ACKNOWLEDGE" ); +return -EIO ; + } + + rc =virtio_pci_read_pci_cap_config (); +if (rc) { +puts ("Invalid virtio PCI capabilities" ); +return -EIO ; + }
Reading the capabilities configuration must be done before writing status to the device.
I have already fixed it for the next version.
Regards,
Jared Rossi
Re: [PATCH v3 11/14] pc-bios/s390-ccw: Add support for virtio-blk-pci IPL
In reply to [email protected]<...snip...>
Quoted 83 lines · On 1/27/2026 8:15 AM, [email protected] wrote:
int
virtio_pci_setup(VDev *vdev)pc-bios/s390-ccw/virtio-pci.c +82
-0+{ +VRing *vr; +int rc; +uint8_t status; +int i =0 ; + + vdev->guessed_disk_nature =VIRTIO_GDN_NONE ; + vdev->cmd_vr_idx =0 ; + +if (virtio_reset (vdev)) { +return -EIO ; + } + + status =VPCI_S_ACKNOWLEDGE ; +if (virtio_pci_set_status (status)) { +puts ("Virtio-pci device Failed to ACKNOWLEDGE" ); +return -EIO ; + } + + rc =virtio_pci_read_pci_cap_config (); +if (rc) { +puts ("Invalid virtio PCI capabilities" ); +return -EIO ; + } + + vdev->guest_features[1 ] =VIRTIO_F_VERSION_1 ; +if (virtio_pci_negotiate ()) { +panic ("Virtio feature negotation failed!" ); + } + +switch (vdev->dev_type) { +case VIRTIO_ID_BLOCK : + vdev->nr_vqs =1 ; + vdev->cmd_vr_idx =0 ; + vdev->config.blk.blk_size =0 ; +virtio_pci_get_blk_config (); +break ; +default : +puts ("Unsupported virtio device" ); +return -ENODEV ; + } + + status |=VPCI_S_DRIVER ; + rc =virtio_pci_set_status (status); +if (rc) { +puts ("Set status failed" ); +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), + .align =KVM_S390_VIRTIO_RING_ALIGN , + .index = i, + .num =0 , + }; + + vr = &vdev->vrings[i]; + +if (vpci_read_flex (VPCI_C_COMMON_NUMQ , c_cap.bar, &info.num,2 )) { +return -EIO ; + } + +vring_init (vr, &info); + +if (vpci_set_selected_vq (vr->id)) { +puts ("Failed to set selected virt-queue" ); +return -EIO ; + } + +if (vpci_set_queue_size (VIRTIO_RING_SIZE )) { +puts ("Failed to set virt-queue size" ); +return -EIO ; + } + + rc =set_pci_vq_addr (VPCI_C_OFFSET_Q_DESCLO , vr->desc); + rc |=set_pci_vq_addr (VPCI_C_OFFSET_Q_AVAILLO , vr->avail); + rc |=set_pci_vq_addr (VPCI_C_OFFSET_Q_USEDLO , vr->used); +if (rc) { +puts ("Failed to configure virt-queue address" ); +return -EIO ;
pc-bios/s390-ccw/virtio-pci.c int vpci_read_flex(uint64_t offset, uint8_t pcias, void *buf, int len) · line 411
Quoted 10 lines
pc-bios/s390-ccw/virtio-pci.c +10
-0+ } + +if (vpci_set_queue_enable (true)) { +puts ("Failed to set virt-queue enabled" ); +return -EIO ; + } + } + + status |=VPCI_S_FEATURES_OK |VPCI_S_DRIVER_OK ; +return virtio_pci_set_status (status);
Should we also enable Bus master bit as part of the device setup? QEMU though has a workaround where if we have setup the ACKNOWLEDGE and DRIVER status flags set then it would enable the Bus master by default since older Linux virtio-pci drivers didn't do it (https://github.com/qemu/qemu/blob/cd5a79dc98e3087e7658e643bdbbb0baec77ac8a/hw/virtio/virtio-pci.c#L480-L487). But latest virtio-pci drivers seems to be doing the right thing, so not sure how long this workaround would be supported :) .
Quoted 2 lines
(quoted diff) +2
-0+} +
<..snip..>
Quoted 79 lines
pc-bios/s390-ccw/virtio-pci.h +2
-0@@ -71,6 +71,8 @@ typedef struct VirtioPciCap VirtioPciCap;void virtio_pci_id2type (VDev *vdev,uint16_t device_id);int virtio_pci_reset (VDev *vdev);long virtio_pci_notify (int vq_id); +int virtio_pci_setup (VDev *vdev); +int virtio_pci_setup_device (void );int vpci_read_flex (uint64_t offset,uint8_t pcias,void *buf,int len);int vpci_read_bswap64 (uint64_t offset,uint8_t pcias,uint64_t *buf);pc-bios/s390-ccw/virtio.c +38
-0@@ -17,6 +17,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" @@ -112,6 +113,8 @@ bool vring_notify(VRing *vr)case S390_IPL_TYPE_CCW : vr->cookie =virtio_ccw_notify (vdev.schid, vr->id, vr->cookie);break ; +case S390_IPL_TYPE_PCI : + vr->cookie =virtio_pci_notify (vr->id);default :return 1 ; }@@ -119,8 +122,43 @@ bool vring_notify(VRing *vr)return vr->cookie >=0 ; } +/* +* Get endienness of the IPL type +* Return true for s390x native big-endian +*/ +bool be_ipl (void ) +{ +switch (virtio_get_device ()->ipl_type) { +case S390_IPL_TYPE_QEMU_SCSI : +case S390_IPL_TYPE_CCW : +return true; +case S390_IPL_TYPE_PCI : +return false; +default : +return true; + } +} + +/* +* Format the virtio ring descriptor endianness +* Return the available index increment in the appropriate endianness +*/ +static uint16_t vr_fmt_descriptor (VRingDesc *desc) +{ +if (!be_ipl ()) { + desc->addr =bswap64 (desc->addr); + desc->len =bswap32 (desc->len); + desc->flags =bswap16 (desc->flags); + desc->next =bswap16 (desc->next); + } + +return be_ipl () ?1 :bswap16 (1 ); +} +void vring_send_buf (VRing *vr,void *p,int len,int flags) { +uint16_t increment; +/* For follow-up chains we need to keep the first entry point */ if (!(flags &VRING_HIDDEN_IS_CHAIN )) { vr->avail->ring[vr->avail->idx % vr->num] = vr->next_idx;
pc-bios/s390-ccw/virtio.c void vring_send_buf(VRing *vr, void *p, int len, int flags) · line 173
Quoted 5 lines
pc-bios/s390-ccw/virtio.c +2
-0@@ -131,11 +169,13 @@ void vring_send_buf(VRing *vr, void *p, int len, int flags) vr->desc[vr->next_idx].flags = flags & ~VRING_HIDDEN_IS_CHAIN ; vr->desc[vr->next_idx].next = vr->next_idx; vr->desc[vr->next_idx].next++; + + increment =vr_fmt_descriptor (&vr->desc[vr->next_idx]);
If we are only returning 1 from the function vr_fmt_descriptor(), why not just set increment=1 or remove it completely and keep vr->avail->idx++? That way we don't need to do any endian conversion?
Thanks
Farhan
Quoted 8 lines
pc-bios/s390-ccw/virtio.c +1
-1vr->next_idx++;/* Chains only have a single ID */ if (!(flags &VRING_DESC_F_NEXT )) { - vr->avail->idx++; + vr->avail->idx += increment; } }
Re: [PATCH v3 11/14] pc-bios/s390-ccw: Add support for virtio-blk-pci IPL
Quoted 95 lines · Farhan Ali
<...snip...>
Quoted 92 lines · On 1/27/2026 8:15 AM, [email protected] wrote:
int
virtio_pci_setup(VDev *vdev)pc-bios/s390-ccw/virtio-pci.c +91
-0+{ +VRing *vr; +int rc; +uint8_t status; +int i =0 ; + + vdev->guessed_disk_nature =VIRTIO_GDN_NONE ; + vdev->cmd_vr_idx =0 ; + +if (virtio_reset (vdev)) { +return -EIO ; + } + + status =VPCI_S_ACKNOWLEDGE ; +if (virtio_pci_set_status (status)) { +puts ("Virtio-pci device Failed to ACKNOWLEDGE" ); +return -EIO ; + } + + rc =virtio_pci_read_pci_cap_config (); +if (rc) { +puts ("Invalid virtio PCI capabilities" ); +return -EIO ; + } + + vdev->guest_features[1 ] =VIRTIO_F_VERSION_1 ; +if (virtio_pci_negotiate ()) { +panic ("Virtio feature negotation failed!" ); + } + +switch (vdev->dev_type) { +case VIRTIO_ID_BLOCK : + vdev->nr_vqs =1 ; + vdev->cmd_vr_idx =0 ; + vdev->config.blk.blk_size =0 ; +virtio_pci_get_blk_config (); +break ; +default : +puts ("Unsupported virtio device" ); +return -ENODEV ; + } + + status |=VPCI_S_DRIVER ; + rc =virtio_pci_set_status (status); +if (rc) { +puts ("Set status failed" ); +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), + .align =KVM_S390_VIRTIO_RING_ALIGN , + .index = i, + .num =0 , + }; + + vr = &vdev->vrings[i]; + +if (vpci_read_flex (VPCI_C_COMMON_NUMQ , c_cap.bar, &info.num,2 )) { +return -EIO ; + } + +vring_init (vr, &info); + +if (vpci_set_selected_vq (vr->id)) { +puts ("Failed to set selected virt-queue" ); +return -EIO ; + } + +if (vpci_set_queue_size (VIRTIO_RING_SIZE )) { +puts ("Failed to set virt-queue size" ); +return -EIO ; + } + + rc =set_pci_vq_addr (VPCI_C_OFFSET_Q_DESCLO , vr->desc); + rc |=set_pci_vq_addr (VPCI_C_OFFSET_Q_AVAILLO , vr->avail); + rc |=set_pci_vq_addr (VPCI_C_OFFSET_Q_USEDLO , vr->used); +if (rc) { +puts ("Failed to configure virt-queue address" ); +return -EIO ; + } + +if (vpci_set_queue_enable (true)) { +puts ("Failed to set virt-queue enabled" ); +return -EIO ; + } + } + + status |=VPCI_S_FEATURES_OK |VPCI_S_DRIVER_OK ;
Quoted 9 lines
Quoted 1 line
+ return
virtio_pci_set_status(status);Should we also enable Bus master bit as part of the device setup? QEMU
though has a workaround where if we have setup the ACKNOWLEDGE and DRIVER
status flags set then it would enable the Bus master by default since older
Linux virtio-pci drivers didn't do it (https://github.com/qemu/qemu/blob/cd5a79dc98e3087e7658e643bdbbb0baec77ac8a/hw/virtio/virtio-pci.c#L480-L487).
But latest virtio-pci drivers seems to be doing the right thing, so not sure
how long this workaround would be supported :) .
Please do. linux 2.6.x is ancient and there's no guarantee we will keep supporting this indefinitely.
Quoted 105 lines
Quoted 2 lines
(quoted diff) +2
-0+} +<..snip..>
Quoted 77 lines
pc-bios/s390-ccw/virtio-pci.h +2
-0@@ -71,6 +71,8 @@ typedef struct VirtioPciCap VirtioPciCap;void virtio_pci_id2type (VDev *vdev,uint16_t device_id);int virtio_pci_reset (VDev *vdev);long virtio_pci_notify (int vq_id); +int virtio_pci_setup (VDev *vdev); +int virtio_pci_setup_device (void );int vpci_read_flex (uint64_t offset,uint8_t pcias,void *buf,int len);int vpci_read_bswap64 (uint64_t offset,uint8_t pcias,uint64_t *buf);pc-bios/s390-ccw/virtio.c +38
-0@@ -17,6 +17,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" @@ -112,6 +113,8 @@ bool vring_notify(VRing *vr)case S390_IPL_TYPE_CCW : vr->cookie =virtio_ccw_notify (vdev.schid, vr->id, vr->cookie);break ; +case S390_IPL_TYPE_PCI : + vr->cookie =virtio_pci_notify (vr->id);default :return 1 ; }@@ -119,8 +122,43 @@ bool vring_notify(VRing *vr)return vr->cookie >=0 ; } +/* +* Get endienness of the IPL type +* Return true for s390x native big-endian +*/ +bool be_ipl (void ) +{ +switch (virtio_get_device ()->ipl_type) { +case S390_IPL_TYPE_QEMU_SCSI : +case S390_IPL_TYPE_CCW : +return true; +case S390_IPL_TYPE_PCI : +return false; +default : +return true; + } +} + +/* +* Format the virtio ring descriptor endianness +* Return the available index increment in the appropriate endianness +*/ +static uint16_t vr_fmt_descriptor (VRingDesc *desc) +{ +if (!be_ipl ()) { + desc->addr =bswap64 (desc->addr); + desc->len =bswap32 (desc->len); + desc->flags =bswap16 (desc->flags); + desc->next =bswap16 (desc->next); + } + +return be_ipl () ?1 :bswap16 (1 ); +} +void vring_send_buf (VRing *vr,void *p,int len,int flags) { +uint16_t increment; +/* For follow-up chains we need to keep the first entry point */ if (!(flags &VRING_HIDDEN_IS_CHAIN )) { vr->avail->ring[vr->avail->idx % vr->num] = vr->next_idx;pc-bios/s390-ccw/virtio.c void vring_send_buf(VRing *vr, void *p, int len, int flags) · line 173
Quoted 5 lines
pc-bios/s390-ccw/virtio.c +2
-0@@ -131,11 +169,13 @@ void vring_send_buf(VRing *vr, void *p, int len, int flags) vr->desc[vr->next_idx].flags = flags & ~VRING_HIDDEN_IS_CHAIN ; vr->desc[vr->next_idx].next = vr->next_idx; vr->desc[vr->next_idx].next++; + + increment =vr_fmt_descriptor (&vr->desc[vr->next_idx]);If we are only returning 1 from the function
vr_fmt_descriptor(), why not just set increment=1 or remove it completely and keep vr->avail->idx++? That way we don't need to do any endian conversion?Thanks
Farhan
Quoted 7 lines
pc-bios/s390-ccw/virtio.c +1
-1vr->next_idx++;/* Chains only have a single ID */ if (!(flags &VRING_DESC_F_NEXT )) { - vr->avail->idx++; + vr->avail->idx += increment; } }
PATCH v3 12/14 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).
--- hw/s390x/ipl.c | 56 ++++++++++++++++++++++++++++++--- hw/s390x/ipl.h | 3 ++ hw/s390x/s390-pci-bus.c | 3 +- include/hw/s390x/s390-pci-bus.h | 2 ++ 4 files changed, 57 insertions(+), 7 deletions(-)
hw/s390x/ipl.c +51 -5
@@ -28,6 +28,8 @@#include "hw/s390x/ebcdic.h" #include "hw/scsi/scsi.h" #include "hw/virtio/virtio-net.h" +#include "hw/virtio/virtio-pci.h" +#include "hw/s390x/s390-pci-bus.h" #include "exec/cpu-common.h" #include "ipl.h" #include "qemu/error-report.h"
@@ -340,7 +342,8 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl) ipl->qipl.boot_menu_timeout =cpu_to_be32 (splash_time); } -#define CCW_DEVTYPE_NONE 0x00 +#define S390_DEVTYPE_NONE 0x00 +#define CCW_DEVTYPE_VIRTIO 0x01#define CCW_DEVTYPE_VIRTIO_NET 0x02#define CCW_DEVTYPE_SCSI 0x03
@@ -349,7 +352,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 *)
@@ -396,6 +399,31 @@ static CcwDevice *s390_get_ccw_device(DeviceState *dev_st, int *devtype)return ccw_dev; } +#define PCI_DEVTYPE_VIRTIO 0x05 + +static S390PCIBusDevice *s390_get_pci_device (DeviceState *dev_st,int *devtype) +{ +S390PCIBusDevice *pbdev =NULL ; +int tmp_dt =S390_DEVTYPE_NONE ; + +if (dev_st) { +PCIDevice *pci_dev = (PCIDevice *) +object_dynamic_cast (OBJECT (qdev_get_parent_bus (dev_st)->parent), +TYPE_VIRTIO_PCI ); +if (pci_dev) { + pbdev =s390_pci_find_dev_by_pci (s390_get_phb (), pci_dev); +if (pbdev) { + tmp_dt =PCI_DEVTYPE_VIRTIO ; + } + } + } +if (devtype) { + *devtype = tmp_dt; + } + +return pbdev; +} +static uint64_t s390_ipl_map_iplb_chain (IplParameterBlock *iplb_chain) {S390IPLState *ipl =get_ipl_device ();
@@ -428,14 +456,12 @@ void s390_ipl_convert_loadparm(char *ascii_lp, uint8_t *ebcdic_lp)static bool s390_build_iplb (DeviceState *dev_st,IplParameterBlock *iplb) {CcwDevice *ccw_dev =NULL ; +S390PCIBusDevice *pbdev =NULL ;SCSIDevice *sd;int devtype;uint8_t *lp; g_autofree void *scsi_lp = NULL; -/* -* Currently allow IPL only from CCW devices. -*/ ccw_dev =s390_get_ccw_device (dev_st, &devtype);if (ccw_dev) { lp = ccw_dev->loadparm;
@@ -485,6 +511,26 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb)return true; } + pbdev =s390_get_pci_device (dev_st, &devtype); +if (pbdev) { +switch (devtype) { +case PCI_DEVTYPE_VIRTIO : + iplb->len =S390_IPLB_MIN_PCI_LEN ; + iplb->pbt =S390_IPL_TYPE_PCI ; + iplb->pci.fid = pbdev->fid; +break ; +default : +return false; + } + +/* Per-device loadparm not yet supported for non-ccw IPL */ + lp =S390_CCW_MACHINE (qdev_get_machine ())->loadparm; +s390_ipl_convert_loadparm ((char *)lp, iplb->loadparm); + iplb->flags |=DIAG308_FLAGS_LP_VALID ; + +return true; + } +return false; }
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;
hw/s390x/s390-pci-bus.c +1 -2
@@ -250,8 +250,7 @@ S390PCIBusDevice *s390_pci_find_dev_by_target(S390pciState *s,return NULL ; } -static S390PCIBusDevice *s390_pci_find_dev_by_pci (S390pciState *s, -PCIDevice *pci_dev) +S390PCIBusDevice *s390_pci_find_dev_by_pci (S390pciState *s,PCIDevice *pci_dev) {S390PCIBusDevice *pbdev;
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 );
Signature · 1 line
2.52.0
Re: [PATCH v3 12/14] s390x: Build IPLB for virtio-pci devices
Quoted 7 lines · On 27/01/2026 17.15, [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).
Quoted 7 lines
Signed-off-by Jared Rossi <[email protected]>--- hw/s390x/ipl.c | 56 ++++++++++++++++++++++++++++++--- hw/s390x/ipl.h | 3 ++ hw/s390x/s390-pci-bus.c | 3 +- include/hw/s390x/s390-pci-bus.h | 2 ++ 4 files changed, 57 insertions(+), 7 deletions(-)
PATCH v3 13/14 hw: Add "loadparm" property to virtio block PCI devices booting on s390x
In reply to [email protected]From: Jared Rossi <[email protected]>
The loadparm is required on s390x to pass the information to the boot loader such as which kernel should be started or whether the boot menu should be shown.
Because PCI devices do not naturally allocate space for this, the property is added on an architecture specific basis for supported device types.
--- hw/pci/pci.c | 39 +++++++++++++++++++++++++++++++++++++ hw/s390x/ipl.c | 11 +++++++++-- hw/virtio/virtio-blk-pci.c | 1 + include/hw/pci/pci.h | 1 + include/hw/pci/pci_device.h | 3 +++ 5 files changed, 53 insertions(+), 2 deletions(-)
hw/pci/pci.c +39 -0
@@ -36,6 +36,7 @@#include "migration/qemu-file-types.h" #include "migration/vmstate.h" #include "net/net.h" +#include "system/arch_init.h" #include "system/numa.h" #include "system/runstate.h" #include "system/system.h"
@@ -2825,6 +2826,43 @@ int pci_qdev_find_device(const char *id, PCIDevice **pdev)return rc; } +static char *pci_qdev_property_get_loadparm (Object *obj,Error **errp) +{ +return g_strdup (PCI_DEVICE (obj)->loadparm); +} + +static void pci_qdev_property_set_loadparm (Object *obj,const char *value, +Error **errp) +{ +void *lp_str; + +if (object_property_get_int (obj,"bootindex" ,NULL ) <0 ) { +error_setg (errp,"'loadparm' is only valid for boot devices" ); +return ; + } + + lp_str =g_malloc0 (strlen (value) +1 ); +if (!qdev_prop_sanitize_s390x_loadparm (lp_str, value, errp)) { +g_free (lp_str); +return ; + } +PCI_DEVICE (obj)->loadparm = lp_str; +} + +void pci_qdev_property_add_specifics (DeviceClass *dc) +{ +ObjectClass *oc =OBJECT_CLASS (dc); + +/* The loadparm property is only supported on s390x */ +if (qemu_arch_available (QEMU_ARCH_S390X )) { +object_class_property_add_str (oc,"loadparm" , + pci_qdev_property_get_loadparm, + pci_qdev_property_set_loadparm); +object_class_property_set_description (oc,"loadparm" , +"load parameter (s390x only)" ); + } +} +MemoryRegion *pci_address_space (PCIDevice *dev) {return pci_get_bus (dev)->address_space_mem;
@@ -2843,6 +2881,7 @@ static void pci_device_class_init(ObjectClass *klass, const void *data) k->unrealize = pci_qdev_unrealize; k->bus_type =TYPE_PCI_BUS ;device_class_set_props (k, pci_props); +object_class_property_set_description ( klass,"x-max-bounce-buffer-size" , "Maximum buffer size allocated for bounce buffers used for mapped "
hw/s390x/ipl.c +9 -2
@@ -461,6 +461,7 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb)int devtype;uint8_t *lp; g_autofree void *scsi_lp = NULL; + g_autofree void *pci_lp = NULL; ccw_dev =s390_get_ccw_device (dev_st, &devtype);if (ccw_dev) {
@@ -513,6 +514,14 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb) pbdev =s390_get_pci_device (dev_st, &devtype);if (pbdev) { + pci_lp =object_property_get_str (OBJECT (pbdev->pdev),"loadparm" ,NULL ); +if (pci_lp &&strlen (pci_lp) >0 ) { + lp = pci_lp; + }else { +/* Use machine loadparm as a place holder if PCI LP is unset */ + lp =S390_CCW_MACHINE (qdev_get_machine ())->loadparm; + } +switch (devtype) {case PCI_DEVTYPE_VIRTIO : iplb->len =S390_IPLB_MIN_PCI_LEN ;
@@ -523,8 +532,6 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb)return false; } -/* Per-device loadparm not yet supported for non-ccw IPL */ - lp =S390_CCW_MACHINE (qdev_get_machine ())->loadparm;s390_ipl_convert_loadparm ((char *)lp, iplb->loadparm); iplb->flags |=DIAG308_FLAGS_LP_VALID ;
hw/virtio/virtio-blk-pci.c +1 -0
@@ -71,6 +71,7 @@ static void virtio_blk_pci_class_init(ObjectClass *klass, const void *data)set_bit (DEVICE_CATEGORY_STORAGE , dc->categories);device_class_set_props (dc, virtio_blk_pci_properties); +pci_qdev_property_add_specifics (dc); k->realize = virtio_blk_pci_realize; pcidev_k->vendor_id =PCI_VENDOR_ID_REDHAT_QUMRANET ; pcidev_k->device_id =PCI_DEVICE_ID_VIRTIO_BLOCK ;
include/hw/pci/pci.h +1 -0
@@ -382,6 +382,7 @@ const char *pci_root_bus_path(PCIDevice *dev);bool pci_bus_bypass_iommu (PCIBus *bus);PCIDevice *pci_find_device (PCIBus *bus,int bus_num,uint8_t devfn);int pci_qdev_find_device (const char *id,PCIDevice **pdev); +void pci_qdev_property_add_specifics (DeviceClass *dc);void pci_bus_get_w64_range (PCIBus *bus,Range *range);void pci_device_deassert_intx (PCIDevice *dev);
include/hw/pci/pci_device.h +3 -0
@@ -62,6 +62,9 @@ struct PCIDevice {bool partially_hotplugged;bool enabled; +/* only for s390x */ +char *loadparm; +/* PCI config space */ uint8_t *config;
Signature · 1 line
2.52.0
PATCH v3 14/14 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.52.0