From nobody Sat Apr 11 21:29:11 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1773122283; cv=none; d=zohomail.com; s=zohoarc; b=WWaDaOLQCbpsK3HZyMWpg7WHDh7aSNudPneIyYPk7UJ4uCbnMuKFZE1SGLaLnfflnQFPqSnIuIURvDLtLnrgcOQk1rAwMyqukjaoH1fSwW7uwWSutAvunCY0ezNZ/63c2vXq7/P99qz7fajN16W8beGx7AXYpBgngwoLK0Y52PE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773122283; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OY51g9+eUvj1djQZBkWHLh3VByefHAuAYmIFtE21EwQ=; b=oKeOFkH5xaHeCD2mspjNi6KMUvJem6n2KIFjrSid4NF1mqO/lxdWql/sQng+3U0mpVFjcwi7cCIV0mUQ13SS5nxxl9cQUH+WjexYzaN2/lc27SVJG4FoJtlCGjQbbYDp62BBFyFO5Mh/2ZUGQAXchU8eExu65a7tTPvW5BHT7c4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1773122283352205.22219903556527; Mon, 9 Mar 2026 22:58:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vzq5R-0000WF-5K; Tue, 10 Mar 2026 01:56:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vzq5O-0000MU-5t for qemu-devel@nongnu.org; Tue, 10 Mar 2026 01:56:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vzq5L-0006KI-UI for qemu-devel@nongnu.org; Tue, 10 Mar 2026 01:56:53 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-398-u_pXyqVnOra0kGGWHYgyjQ-1; Tue, 10 Mar 2026 01:56:47 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 56A53195608E; Tue, 10 Mar 2026 05:56:46 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.44.32.69]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3BA021956095; Tue, 10 Mar 2026 05:56:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773122211; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OY51g9+eUvj1djQZBkWHLh3VByefHAuAYmIFtE21EwQ=; b=FaSmuhglm1EI0etBsw+GBCInFAqwbc7YA1z+MWvIWovQ/FoOmH4/1Mk8mYl7/qdDhkLGT7 Ke2lNAi/xvHh/eHKe+ajB/Wr5i665dacDP25vfC8L2AfSvlc63Uc12vaieMA/8FPw07NUf /qkOy4rS1B+fj7WZeGNRFPT4nfWqFrk= X-MC-Unique: u_pXyqVnOra0kGGWHYgyjQ-1 X-Mimecast-MFC-AGG-ID: u_pXyqVnOra0kGGWHYgyjQ_1773122206 From: Thomas Huth To: Peter Maydell Cc: qemu-devel@nongnu.org, Jared Rossi , Matthew Rosato , Farhan Ali Subject: [PULL 18/25] pc-bios/s390-ccw: Introduce PCI device Date: Tue, 10 Mar 2026 06:55:23 +0100 Message-ID: <20260310055530.8893-19-thuth@redhat.com> In-Reply-To: <20260310055530.8893-1-thuth@redhat.com> References: <20260310055530.8893-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1773122284667154100 Content-Type: text/plain; charset="utf-8" From: Jared Rossi Define selected s390x PCI instructions. Signed-off-by: Jared Rossi Reviewed-by: Matthew Rosato Acked-by: Thomas Huth Message-ID: <20260309003601.242634-11-jrossi@linux.ibm.com> Reviewed-by: Farhan Ali [thuth: Remove unused defines as suggested by Farhan] Signed-off-by: Thomas Huth --- pc-bios/s390-ccw/pci.h | 36 ++++++++++++ pc-bios/s390-ccw/pci.c | 118 ++++++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/Makefile | 2 +- 3 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 pc-bios/s390-ccw/pci.h create mode 100644 pc-bios/s390-ccw/pci.c diff --git a/pc-bios/s390-ccw/pci.h b/pc-bios/s390-ccw/pci.h new file mode 100644 index 00000000000..968635eff11 --- /dev/null +++ b/pc-bios/s390-ccw/pci.h @@ -0,0 +1,36 @@ +/* + * s390x PCI definitions + * + * Copyright 2025 IBM Corp. + * Author(s): Jared Rossi + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef PCI_H +#define PCI_H + +#include +#include +#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 PCI_CFGBAR 0xF /* Base Address Register for config sp= ace */ +#define PCI_CAPABILITY_LIST 0x34 /* Offset of first capability list ent= ry */ + +int pci_write(uint32_t fhandle, uint64_t offset, uint8_t pcias, uint64_t d= ata, + uint8_t len); +int pci_read(uint32_t fhandle, uint64_t offset, uint8_t pcias, void *buf, + uint8_t len); + +#endif diff --git a/pc-bios/s390-ccw/pci.c b/pc-bios/s390-ccw/pci.c new file mode 100644 index 00000000000..247070e5f07 --- /dev/null +++ b/pc-bios/s390-ccw/pci.c @@ -0,0 +1,118 @@ +/* + * s390x PCI functionality + * + * Copyright 2025 IBM Corp. + * Author(s): Jared Rossi + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "clp.h" +#include "pci.h" +#include "bswap.h" +#include +#include + +/* PCI load */ +static inline int pcilg(uint64_t *data, uint64_t req, uint64_t offset, + uint8_t *status) +{ + union register_pair req_off =3D {.even =3D req, .odd =3D offset}; + int cc =3D -1; + uint64_t __data; + + asm volatile ( + " .insn rre,0xb9d20000,%[data],%[req_off]\n" + " ipm %[cc]\n" + " srl %[cc],28\n" + : [cc] "+d" (cc), [data] "=3Dd" (__data), + [req_off] "+d" (req_off.pair) :: "cc"); + *status =3D req_off.even >> 24 & 0xff; + *data =3D __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 =3D {.even =3D req, .odd =3D offset}; + int cc =3D -1; + + asm volatile ( + " .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 =3D req_off.even >> 24 & 0xff; + return cc; +} + +int pci_write(uint32_t fhandle, uint64_t offset, uint8_t pcias, uint64_t d= ata, + uint8_t len) +{ + + uint64_t req =3D 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 =3D pcistg(data, req, offset, &status); + break; + default: + return -1; + } + + /* Error condition detected */ + if (rc !=3D 0) { + printf("PCI store failed with status condition %d, return code %d\= n", + status, rc); + return -1; + } + + return 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 =3D ZPCI_CREATE_REQ(fhandle, pcias, len); + rc =3D pcilg(&data, req, offset, &status); + + /* Error condition detected */ + if (rc !=3D 0) { + printf("PCI load failed with status condition %d, return code %d\n= ", + status, rc); + return -1; + } + + switch (len) { + case 1: + *(uint8_t *)buf =3D data; + break; + case 2: + *(uint16_t *)buf =3D data; + break; + case 4: + *(uint32_t *)buf =3D data; + break; + case 8: + *(uint64_t *)buf =3D data; + break; + default: + return -1; + } + + return 0; +} diff --git a/pc-bios/s390-ccw/Makefile b/pc-bios/s390-ccw/Makefile index 9c29548f849..a62fc9d7660 100644 --- a/pc-bios/s390-ccw/Makefile +++ b/pc-bios/s390-ccw/Makefile @@ -35,7 +35,7 @@ QEMU_DGFLAGS =3D -MMD -MP -MT $@ -MF $(@D)/$(*F).d =20 OBJECTS =3D 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 =20 SLOF_DIR :=3D $(SRC_PATH)/../../roms/SLOF =20 --=20 2.53.0