From nobody Sat May 18 05:53:09 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651677825; cv=none; d=zohomail.com; s=zohoarc; b=B83CfGyQdlnyc8z5YX85UMexl5lwgxXMVWtZGPlb9MPtm2wuNG4Mf2/lIX4sz8yKYHRhitFpV+SbvIYqI5IGxLw5oT7zOttxy67LfxAo+XtCpr+v3i2O75kOfbEeum2xHtwEDF+vZxl15TPDbijxHtEUamhLw0oDVzSoTBPENY0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651677825; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KTTwL4eI09OhZ1xtEBRGxKN11GNQQbWrIC8mu7jdO4g=; b=AdPav5sUO/d3/ZQJ9Ah38JRoWThN7z4W5+SZTX2seTszF6WxmtsjCJqRNOA+HjH6FSAmOmhT0M9UiDJZNoU6qU54A9RYy74MQ7oVTYa9iiHgCreYPy8GZSM2n+TU5bi4+8LXRcGNlGqWq3YXeq9K+a+u4VJ5GZY7r3EhYKtY9rc= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651677825517218.41996552122566; Wed, 4 May 2022 08:23:45 -0700 (PDT) Received: from localhost ([::1]:35518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmGqu-0000Ex-Ey for importer@patchew.org; Wed, 04 May 2022 11:23:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59338) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmGnu-0003PH-Vi for qemu-devel@nongnu.org; Wed, 04 May 2022 11:20:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32371) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmGns-0003Pe-Tx for qemu-devel@nongnu.org; Wed, 04 May 2022 11:20:38 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-534-5qdR3AfpOY6FssvCrXvzcA-1; Wed, 04 May 2022 11:20:32 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2C2D529ABA01; Wed, 4 May 2022 15:20:32 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04698400D277; Wed, 4 May 2022 15:20:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651677635; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KTTwL4eI09OhZ1xtEBRGxKN11GNQQbWrIC8mu7jdO4g=; b=J9ze3cLCacgC+mwf+3XwEjrVIx7x60RHBgXZlIjo2cAxJuwp76DOcH0J+8RYNSIwUJLidk aORQs5yLokWKmwigu3FIqd90QUmnAD9b0Dk6xEUYI8UotN8aivHp9sCNKMISNm1/BLBYbp ZmUBDSykZy7E76cxk7Ot3Pb4BygT3gA= X-MC-Unique: 5qdR3AfpOY6FssvCrXvzcA-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, pbonzini@redhat.com, qemu-arm@nongnu.org, qemu-devel@nongnu.org, mst@redhat.com, david@gibson.dropbear.id.au, clg@kaod.org, eesposit@redhat.com, Coiby.Xu@gmail.com, stefanha@redhat.com Cc: jean-philippe@linaro.org Subject: [PATCH v6 1/3] tests/qtest/libqos/pci: Introduce pio_limit Date: Wed, 4 May 2022 17:20:23 +0200 Message-Id: <20220504152025.1785704-2-eric.auger@redhat.com> In-Reply-To: <20220504152025.1785704-1-eric.auger@redhat.com> References: <20220504152025.1785704-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651677827097100001 At the moment the IO space limit is hardcoded to QPCI_PIO_LIMIT =3D 0x10000. When accesses are performed to a bar, the base address of this latter is compared against the limit to decide whether we perform an IO or a memory access. On ARM, we cannot keep this PIO limit as the arm-virt machine uses [0x3eff0000, 0x3f000000 ] for the IO space map and we are mandated to allocate at 0x0. Add a new flag in QPCIBar indicating whether it is an IO bar or a memory bar. This flag is set on QPCIBar allocation and provisionned based on the BAR configuration. Then the new flag is used in access functions and in iomap() function. Signed-off-by: Eric Auger Reviewed-by: Thomas Huth Reviewed-by: Alex Benn=C3=A9e --- tests/qtest/libqos/pci-pc.c | 1 + tests/qtest/libqos/pci-spapr.c | 1 + tests/qtest/libqos/pci.c | 78 ++++++++++++++++++++++------------ tests/qtest/libqos/pci.h | 5 +-- 4 files changed, 54 insertions(+), 31 deletions(-) diff --git a/tests/qtest/libqos/pci-pc.c b/tests/qtest/libqos/pci-pc.c index e9dd5a57ec..81c2c055ca 100644 --- a/tests/qtest/libqos/pci-pc.c +++ b/tests/qtest/libqos/pci-pc.c @@ -150,6 +150,7 @@ void qpci_init_pc(QPCIBusPC *qpci, QTestState *qts, QGu= estAllocator *alloc) =20 qpci->bus.qts =3D qts; qpci->bus.pio_alloc_ptr =3D 0xc000; + qpci->bus.pio_limit =3D 0x10000; qpci->bus.mmio_alloc_ptr =3D 0xE0000000; qpci->bus.mmio_limit =3D 0x100000000ULL; =20 diff --git a/tests/qtest/libqos/pci-spapr.c b/tests/qtest/libqos/pci-spapr.c index 76bf9a855d..0f1023e4a7 100644 --- a/tests/qtest/libqos/pci-spapr.c +++ b/tests/qtest/libqos/pci-spapr.c @@ -197,6 +197,7 @@ void qpci_init_spapr(QPCIBusSPAPR *qpci, QTestState *qt= s, =20 qpci->bus.qts =3D qts; qpci->bus.pio_alloc_ptr =3D 0xc000; + qpci->bus.pio_limit =3D 0x10000; qpci->bus.mmio_alloc_ptr =3D qpci->mmio32.pci_base; qpci->bus.mmio_limit =3D qpci->mmio32.pci_base + qpci->mmio32.size; =20 diff --git a/tests/qtest/libqos/pci.c b/tests/qtest/libqos/pci.c index 3a9076ae58..b23d72346b 100644 --- a/tests/qtest/libqos/pci.c +++ b/tests/qtest/libqos/pci.c @@ -398,44 +398,56 @@ void qpci_config_writel(QPCIDevice *dev, uint8_t offs= et, uint32_t value) =20 uint8_t qpci_io_readb(QPCIDevice *dev, QPCIBar token, uint64_t off) { - if (token.addr < QPCI_PIO_LIMIT) { - return dev->bus->pio_readb(dev->bus, token.addr + off); + QPCIBus *bus =3D dev->bus; + + if (token.is_io) { + return bus->pio_readb(bus, token.addr + off); } else { uint8_t val; - dev->bus->memread(dev->bus, token.addr + off, &val, sizeof(val)); + + bus->memread(dev->bus, token.addr + off, &val, sizeof(val)); return val; } } =20 uint16_t qpci_io_readw(QPCIDevice *dev, QPCIBar token, uint64_t off) { - if (token.addr < QPCI_PIO_LIMIT) { - return dev->bus->pio_readw(dev->bus, token.addr + off); + QPCIBus *bus =3D dev->bus; + + if (token.is_io) { + return bus->pio_readw(bus, token.addr + off); } else { uint16_t val; - dev->bus->memread(dev->bus, token.addr + off, &val, sizeof(val)); + + bus->memread(bus, token.addr + off, &val, sizeof(val)); return le16_to_cpu(val); } } =20 uint32_t qpci_io_readl(QPCIDevice *dev, QPCIBar token, uint64_t off) { - if (token.addr < QPCI_PIO_LIMIT) { - return dev->bus->pio_readl(dev->bus, token.addr + off); + QPCIBus *bus =3D dev->bus; + + if (token.is_io) { + return bus->pio_readl(bus, token.addr + off); } else { uint32_t val; - dev->bus->memread(dev->bus, token.addr + off, &val, sizeof(val)); + + bus->memread(dev->bus, token.addr + off, &val, sizeof(val)); return le32_to_cpu(val); } } =20 uint64_t qpci_io_readq(QPCIDevice *dev, QPCIBar token, uint64_t off) { - if (token.addr < QPCI_PIO_LIMIT) { - return dev->bus->pio_readq(dev->bus, token.addr + off); + QPCIBus *bus =3D dev->bus; + + if (token.is_io) { + return bus->pio_readq(bus, token.addr + off); } else { uint64_t val; - dev->bus->memread(dev->bus, token.addr + off, &val, sizeof(val)); + + bus->memread(bus, token.addr + off, &val, sizeof(val)); return le64_to_cpu(val); } } @@ -443,57 +455,65 @@ uint64_t qpci_io_readq(QPCIDevice *dev, QPCIBar token= , uint64_t off) void qpci_io_writeb(QPCIDevice *dev, QPCIBar token, uint64_t off, uint8_t value) { - if (token.addr < QPCI_PIO_LIMIT) { - dev->bus->pio_writeb(dev->bus, token.addr + off, value); + QPCIBus *bus =3D dev->bus; + + if (token.is_io) { + bus->pio_writeb(bus, token.addr + off, value); } else { - dev->bus->memwrite(dev->bus, token.addr + off, &value, sizeof(valu= e)); + bus->memwrite(bus, token.addr + off, &value, sizeof(value)); } } =20 void qpci_io_writew(QPCIDevice *dev, QPCIBar token, uint64_t off, uint16_t value) { - if (token.addr < QPCI_PIO_LIMIT) { - dev->bus->pio_writew(dev->bus, token.addr + off, value); + QPCIBus *bus =3D dev->bus; + + if (token.is_io) { + bus->pio_writew(bus, token.addr + off, value); } else { value =3D cpu_to_le16(value); - dev->bus->memwrite(dev->bus, token.addr + off, &value, sizeof(valu= e)); + bus->memwrite(bus, token.addr + off, &value, sizeof(value)); } } =20 void qpci_io_writel(QPCIDevice *dev, QPCIBar token, uint64_t off, uint32_t value) { - if (token.addr < QPCI_PIO_LIMIT) { - dev->bus->pio_writel(dev->bus, token.addr + off, value); + QPCIBus *bus =3D dev->bus; + + if (token.is_io) { + bus->pio_writel(bus, token.addr + off, value); } else { value =3D cpu_to_le32(value); - dev->bus->memwrite(dev->bus, token.addr + off, &value, sizeof(valu= e)); + bus->memwrite(bus, token.addr + off, &value, sizeof(value)); } } =20 void qpci_io_writeq(QPCIDevice *dev, QPCIBar token, uint64_t off, uint64_t value) { - if (token.addr < QPCI_PIO_LIMIT) { - dev->bus->pio_writeq(dev->bus, token.addr + off, value); + QPCIBus *bus =3D dev->bus; + + if (token.is_io) { + bus->pio_writeq(bus, token.addr + off, value); } else { value =3D cpu_to_le64(value); - dev->bus->memwrite(dev->bus, token.addr + off, &value, sizeof(valu= e)); + bus->memwrite(bus, token.addr + off, &value, sizeof(value)); } } =20 void qpci_memread(QPCIDevice *dev, QPCIBar token, uint64_t off, void *buf, size_t len) { - g_assert(token.addr >=3D QPCI_PIO_LIMIT); + g_assert(!token.is_io); dev->bus->memread(dev->bus, token.addr + off, buf, len); } =20 void qpci_memwrite(QPCIDevice *dev, QPCIBar token, uint64_t off, const void *buf, size_t len) { - g_assert(token.addr >=3D QPCI_PIO_LIMIT); + g_assert(!token.is_io); dev->bus->memwrite(dev->bus, token.addr + off, buf, len); } =20 @@ -534,9 +554,10 @@ QPCIBar qpci_iomap(QPCIDevice *dev, int barno, uint64_= t *sizeptr) loc =3D QEMU_ALIGN_UP(bus->pio_alloc_ptr, size); =20 g_assert(loc >=3D bus->pio_alloc_ptr); - g_assert(loc + size <=3D QPCI_PIO_LIMIT); /* Keep PIO below 64kiB = */ + g_assert(loc + size <=3D bus->pio_limit); =20 bus->pio_alloc_ptr =3D loc + size; + bar.is_io =3D true; =20 qpci_config_writel(dev, bar_reg, loc | PCI_BASE_ADDRESS_SPACE_IO); } else { @@ -547,6 +568,7 @@ QPCIBar qpci_iomap(QPCIDevice *dev, int barno, uint64_t= *sizeptr) g_assert(loc + size <=3D bus->mmio_limit); =20 bus->mmio_alloc_ptr =3D loc + size; + bar.is_io =3D false; =20 qpci_config_writel(dev, bar_reg, loc); } @@ -562,7 +584,7 @@ void qpci_iounmap(QPCIDevice *dev, QPCIBar bar) =20 QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr) { - QPCIBar bar =3D { .addr =3D addr }; + QPCIBar bar =3D { .addr =3D addr, .is_io =3D true }; return bar; } =20 diff --git a/tests/qtest/libqos/pci.h b/tests/qtest/libqos/pci.h index e705e06598..a3c657d962 100644 --- a/tests/qtest/libqos/pci.h +++ b/tests/qtest/libqos/pci.h @@ -16,8 +16,6 @@ #include "../libqtest.h" #include "qgraph.h" =20 -#define QPCI_PIO_LIMIT 0x10000 - #define QPCI_DEVFN(dev, fn) (((dev) << 3) | (fn)) =20 typedef struct QPCIDevice QPCIDevice; @@ -51,7 +49,7 @@ struct QPCIBus { uint8_t offset, uint32_t value); =20 QTestState *qts; - uint16_t pio_alloc_ptr; + uint64_t pio_alloc_ptr, pio_limit; uint64_t mmio_alloc_ptr, mmio_limit; bool has_buggy_msi; /* TRUE for spapr, FALSE for pci */ =20 @@ -59,6 +57,7 @@ struct QPCIBus { =20 struct QPCIBar { uint64_t addr; + bool is_io; }; =20 struct QPCIDevice --=20 2.35.1 From nobody Sat May 18 05:53:09 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651677918; cv=none; d=zohomail.com; s=zohoarc; b=KBHFtvRCkqeaoqS1vQWe21YSCqjAqccFGsar1EDLDK5gfEgeAdDtPnsRafojpkSm6U4E37Y5HM/VirS7G7Rx2bh2Ln+2TZmpu+NsPD0cazjMM+/spjAwUGE/10Wxu6J88vPwOfdw8r+AVvgK/BH8FDDaclMPY0By/DDyXDN/bDQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651677918; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=a8uJJltk8oZ/5bdUF+OtR7ADwgE+tWUIoF/G21nkzrQ=; b=YWc2b6TiEhbQxmrd9bc3lEum7fnwruBux/l5ta+aBxkgTeSofZXHskj044IQdb5lE7lDQ+ImrKJCgFPiv2gqy9FPlQY+j4XGuaaOXlxhuOlgN4gMomdUHk5m5Ec+YNeFSd3RvFaCEjnmr59fvSyU+B3Eg2CEAIx7kJhWDaeY1qs= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651677918601852.0358095418441; Wed, 4 May 2022 08:25:18 -0700 (PDT) Received: from localhost ([::1]:39538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmGsP-0003Ax-6B for importer@patchew.org; Wed, 04 May 2022 11:25:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59368) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmGnx-0003UZ-Ki for qemu-devel@nongnu.org; Wed, 04 May 2022 11:20:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:53868) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmGnv-0003R5-TO for qemu-devel@nongnu.org; Wed, 04 May 2022 11:20:41 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-475-1R91XdEUOu63bTyEV4eLbg-1; Wed, 04 May 2022 11:20:35 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BEF2729ABA06; Wed, 4 May 2022 15:20:34 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74B50403D193; Wed, 4 May 2022 15:20:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651677639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a8uJJltk8oZ/5bdUF+OtR7ADwgE+tWUIoF/G21nkzrQ=; b=HB881f6yUWxpgh92/KFwX9yFURquSGEymrCokyFFCnw63rYmF+ADxI2vU4ZGneKEBg3dwL QaJ9xWsBieI32TMP2g5liwyKQA2T1OPG+jsCdodwtuSPX6H99OI+oSQUr0Q3NfbjpSfVjP r/dq6EtNGy6NgeHXwfnStzhWdZmur6Q= X-MC-Unique: 1R91XdEUOu63bTyEV4eLbg-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, pbonzini@redhat.com, qemu-arm@nongnu.org, qemu-devel@nongnu.org, mst@redhat.com, david@gibson.dropbear.id.au, clg@kaod.org, eesposit@redhat.com, Coiby.Xu@gmail.com, stefanha@redhat.com Cc: jean-philippe@linaro.org Subject: [PATCH v6 2/3] tests/qtest/libqos: Skip hotplug tests if pci root bus is not hotpluggable Date: Wed, 4 May 2022 17:20:24 +0200 Message-Id: <20220504152025.1785704-3-eric.auger@redhat.com> In-Reply-To: <20220504152025.1785704-1-eric.auger@redhat.com> References: <20220504152025.1785704-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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.129.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651677919766100001 ARM does not not support hotplug on pcie.0. Add a flag on the bus which tells if devices can be hotplugged and skip hotplug tests if the bus cannot be hotplugged. This is a temporary solution to enable the other pci tests on aarch64. Signed-off-by: Eric Auger Acked-by: Thomas Huth Reviewed-by: Alex Benn=C3=A9e --- v1 ->v2: - reword g_test_skip msg into "pci bus does not support hotplug" --- tests/qtest/e1000e-test.c | 6 ++++++ tests/qtest/libqos/pci.h | 1 + tests/qtest/vhost-user-blk-test.c | 10 ++++++++++ tests/qtest/virtio-blk-test.c | 5 +++++ tests/qtest/virtio-net-test.c | 5 +++++ tests/qtest/virtio-rng-test.c | 5 +++++ 6 files changed, 32 insertions(+) diff --git a/tests/qtest/e1000e-test.c b/tests/qtest/e1000e-test.c index ddd6983ede..c98779c7c0 100644 --- a/tests/qtest/e1000e-test.c +++ b/tests/qtest/e1000e-test.c @@ -233,6 +233,12 @@ static void test_e1000e_multiple_transfers(void *obj, = void *data, static void test_e1000e_hotplug(void *obj, void *data, QGuestAllocator * a= lloc) { QTestState *qts =3D global_qtest; /* TODO: get rid of global_qtest he= re */ + QE1000E_PCI *dev =3D obj; + + if (dev->pci_dev.bus->not_hotpluggable) { + g_test_skip("pci bus does not support hotplug"); + return; + } =20 qtest_qmp_device_add(qts, "e1000e", "e1000e_net", "{'addr': '0x06'}"); qpci_unplug_acpi_device_test(qts, "e1000e_net", 0x06); diff --git a/tests/qtest/libqos/pci.h b/tests/qtest/libqos/pci.h index a3c657d962..8389614523 100644 --- a/tests/qtest/libqos/pci.h +++ b/tests/qtest/libqos/pci.h @@ -52,6 +52,7 @@ struct QPCIBus { uint64_t pio_alloc_ptr, pio_limit; uint64_t mmio_alloc_ptr, mmio_limit; bool has_buggy_msi; /* TRUE for spapr, FALSE for pci */ + bool not_hotpluggable; /* TRUE if devices cannot be hotplugged */ =20 }; =20 diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk= -test.c index 659b5050d8..a81c2a2715 100644 --- a/tests/qtest/vhost-user-blk-test.c +++ b/tests/qtest/vhost-user-blk-test.c @@ -676,6 +676,11 @@ static void pci_hotplug(void *obj, void *data, QGuestA= llocator *t_alloc) QVirtioPCIDevice *dev; QTestState *qts =3D dev1->pdev->bus->qts; =20 + if (dev1->pdev->bus->not_hotpluggable) { + g_test_skip("pci bus does not support hotplug"); + return; + } + /* plug secondary disk */ qtest_qmp_device_add(qts, "vhost-user-blk-pci", "drv1", "{'addr': %s, 'chardev': 'char2'}", @@ -703,6 +708,11 @@ static void multiqueue(void *obj, void *data, QGuestAl= locator *t_alloc) uint64_t features; uint16_t num_queues; =20 + if (pdev1->pdev->bus->not_hotpluggable) { + g_test_skip("bus pci.0 does not support hotplug"); + return; + } + /* * The primary device has 1 queue and VIRTIO_BLK_F_MQ is not enabled. = The * VIRTIO specification allows VIRTIO_BLK_F_MQ to be enabled when ther= e is diff --git a/tests/qtest/virtio-blk-test.c b/tests/qtest/virtio-blk-test.c index f22594a1a8..dc5eed31c8 100644 --- a/tests/qtest/virtio-blk-test.c +++ b/tests/qtest/virtio-blk-test.c @@ -701,6 +701,11 @@ static void pci_hotplug(void *obj, void *data, QGuestA= llocator *t_alloc) QVirtioPCIDevice *dev; QTestState *qts =3D dev1->pdev->bus->qts; =20 + if (dev1->pdev->bus->not_hotpluggable) { + g_test_skip("pci bus does not support hotplug"); + return; + } + /* plug secondary disk */ qtest_qmp_device_add(qts, "virtio-blk-pci", "drv1", "{'addr': %s, 'drive': 'drive1'}", diff --git a/tests/qtest/virtio-net-test.c b/tests/qtest/virtio-net-test.c index fc9f2b9498..6ded252901 100644 --- a/tests/qtest/virtio-net-test.c +++ b/tests/qtest/virtio-net-test.c @@ -173,6 +173,11 @@ static void hotplug(void *obj, void *data, QGuestAlloc= ator *t_alloc) QTestState *qts =3D dev->pdev->bus->qts; const char *arch =3D qtest_get_arch(); =20 + if (dev->pdev->bus->not_hotpluggable) { + g_test_skip("pci bus does not support hotplug"); + return; + } + qtest_qmp_device_add(qts, "virtio-net-pci", "net1", "{'addr': %s}", stringify(PCI_SLOT_HP)); =20 diff --git a/tests/qtest/virtio-rng-test.c b/tests/qtest/virtio-rng-test.c index 092ba13068..64e131cd8c 100644 --- a/tests/qtest/virtio-rng-test.c +++ b/tests/qtest/virtio-rng-test.c @@ -20,6 +20,11 @@ static void rng_hotplug(void *obj, void *data, QGuestAll= ocator *alloc) QVirtioPCIDevice *dev =3D obj; QTestState *qts =3D dev->pdev->bus->qts; =20 + if (dev->pdev->bus->not_hotpluggable) { + g_test_skip("pci bus does not support hotplug"); + return; + } + const char *arch =3D qtest_get_arch(); =20 qtest_qmp_device_add(qts, "virtio-rng-pci", "rng1", --=20 2.35.1 From nobody Sat May 18 05:53:09 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651677753; cv=none; d=zohomail.com; s=zohoarc; b=WWZYHe1HBFZuxrCNLGlbKKxdT8NrjDVDsmhIMbPETRXibSd5kcQ7UOJPzoIaJV3kBruw1y3uupqvG6nycfhHE9aZl+MqzHbzb5vpJlz7ITWAyKsw1WKsde5hiFo9mS2hA1yTYJNBYQJ7FL5hAOrUD/NafIN3KU713nansOjYOtw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651677753; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8E1fxhKaOoh+DYXlc7iGYsJlcKhVDSorbVMXrVfnA5s=; b=cNA0iNI5BwLjZCfH1EO7HzsX4wZXqrmzwUbxPp5W+LLMINoCBZGVWd57ef28P6+4K4VpIRS8UdbRdlZ4HXWdcjqP9gueRTX0TOW1ruz2B6XZ0mro4jnvTU4+SLMUoVh2qtbTW5saUBhuS+7Rjy6S2Hu3wlY+zakSDPeC/fKz9Hg= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651677753556773.6203112127364; Wed, 4 May 2022 08:22:33 -0700 (PDT) Received: from localhost ([::1]:59930 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmGpk-000618-Bx for importer@patchew.org; Wed, 04 May 2022 11:22:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmGo2-0003jG-BU for qemu-devel@nongnu.org; Wed, 04 May 2022 11:20:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:57284) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmGnz-0003TH-Kv for qemu-devel@nongnu.org; Wed, 04 May 2022 11:20:45 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-231-YFFKeWs3N9iSX8xUMSLs-w-1; Wed, 04 May 2022 11:20:37 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 325581014A68; Wed, 4 May 2022 15:20:37 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 135EA400D277; Wed, 4 May 2022 15:20:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651677642; 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=8E1fxhKaOoh+DYXlc7iGYsJlcKhVDSorbVMXrVfnA5s=; b=CjWZ2Z7acFXdSPltBJgIcKDzY83K6760YnbboL3wK9W68Dl6vPUIiPxaULLzRmmLKoGlfW ABcuwWpI11uOoyNCT4YxRqPm4iOAXTyklKQJ+XhvJl8Q+GFVCCDZ+xmDjlH1e7QI4LPYRX B4qUKehMKYs3XqCvOus2fiBFC5BSk5I= X-MC-Unique: YFFKeWs3N9iSX8xUMSLs-w-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, pbonzini@redhat.com, qemu-arm@nongnu.org, qemu-devel@nongnu.org, mst@redhat.com, david@gibson.dropbear.id.au, clg@kaod.org, eesposit@redhat.com, Coiby.Xu@gmail.com, stefanha@redhat.com Cc: jean-philippe@linaro.org Subject: [PATCH v6 3/3] tests/qtest/libqos: Add generic pci host bridge in arm-virt machine Date: Wed, 4 May 2022 17:20:25 +0200 Message-Id: <20220504152025.1785704-4-eric.auger@redhat.com> In-Reply-To: <20220504152025.1785704-1-eric.auger@redhat.com> References: <20220504152025.1785704-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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.129.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651677754761100001 Content-Type: text/plain; charset="utf-8" Up to now the virt-machine node contains a virtio-mmio node. However no driver produces any PCI interface node. Hence, PCI tests cannot be run with aarch64 binary. Add a GPEX driver node that produces a pci interface node. This latter then can be consumed by all the pci tests. One of the first motivation was to be able to run the virtio-iommu-pci tests. We still face an issue with pci hotplug tests as hotplug cannot happen on the pcie root bus and require a generic root port. This will be addressed later on. We force cpu=3Dmax along with aarch64/virt machine as some PCI tests require high MMIO regions to be available. Signed-off-by: Eric Auger Reviewed-by: Alex Benn=C3=A9e --- v5 -> v6: - change header path: #include "../libqtest.h" v3 -> v4: - properly handle le/cpu conversions on config access v2 -> v3: - force cpu=3Dmax with aarch64/virt v1 -> v2: - copyright updated to 2022 - QPCIBusARM renamed into QGenericPCIBus - QGenericPCIHost declarations and definitions moved in the same place as the generic pci implementation - rename pci-arm.c/h in generic-pcihost.c/h and remove any ref to ARM there - remove qos_node_produces_opts, qpci_new_arm, qpci_free_arm - ecam_alloc_ptr now is a field of QGenericPCIBus and not QPCIBus - new libqos_init to create generic-pcihost driver that contains pci-bus-generic - QGenericPCIHost moved in the same place as the generic pci bindings Signed-off-by: Eric Auger --- tests/qtest/libqos/arm-virt-machine.c | 19 ++- tests/qtest/libqos/generic-pcihost.c | 231 ++++++++++++++++++++++++++ tests/qtest/libqos/generic-pcihost.h | 54 ++++++ tests/qtest/libqos/meson.build | 1 + 4 files changed, 301 insertions(+), 4 deletions(-) create mode 100644 tests/qtest/libqos/generic-pcihost.c create mode 100644 tests/qtest/libqos/generic-pcihost.h diff --git a/tests/qtest/libqos/arm-virt-machine.c b/tests/qtest/libqos/arm= -virt-machine.c index 2e0beaefb8..139eaba142 100644 --- a/tests/qtest/libqos/arm-virt-machine.c +++ b/tests/qtest/libqos/arm-virt-machine.c @@ -22,6 +22,8 @@ #include "malloc.h" #include "qgraph.h" #include "virtio-mmio.h" +#include "generic-pcihost.h" +#include "hw/pci/pci_regs.h" =20 #define ARM_PAGE_SIZE 4096 #define VIRTIO_MMIO_BASE_ADDR 0x0A003E00 @@ -35,6 +37,7 @@ struct QVirtMachine { QOSGraphObject obj; QGuestAllocator alloc; QVirtioMMIODevice virtio_mmio; + QGenericPCIHost bridge; }; =20 static void virt_destructor(QOSGraphObject *obj) @@ -57,11 +60,13 @@ static void *virt_get_driver(void *object, const char *= interface) static QOSGraphObject *virt_get_device(void *obj, const char *device) { QVirtMachine *machine =3D obj; - if (!g_strcmp0(device, "virtio-mmio")) { + if (!g_strcmp0(device, "generic-pcihost")) { + return &machine->bridge.obj; + } else if (!g_strcmp0(device, "virtio-mmio")) { return &machine->virtio_mmio.obj; } =20 - fprintf(stderr, "%s not present in arm/virtio\n", device); + fprintf(stderr, "%s not present in arm/virt\n", device); g_assert_not_reached(); } =20 @@ -76,16 +81,22 @@ static void *qos_create_machine_arm_virt(QTestState *qt= s) qvirtio_mmio_init_device(&machine->virtio_mmio, qts, VIRTIO_MMIO_BASE_= ADDR, VIRTIO_MMIO_SIZE); =20 + qos_create_generic_pcihost(&machine->bridge, qts, &machine->alloc); + machine->obj.get_device =3D virt_get_device; machine->obj.get_driver =3D virt_get_driver; machine->obj.destructor =3D virt_destructor; return machine; } =20 -static void virtio_mmio_register_nodes(void) +static void virt_machine_register_nodes(void) { qos_node_create_machine("arm/virt", qos_create_machine_arm_virt); qos_node_contains("arm/virt", "virtio-mmio", NULL); + + qos_node_create_machine_args("aarch64/virt", qos_create_machine_arm_vi= rt, + " -cpu max"); + qos_node_contains("aarch64/virt", "generic-pcihost", NULL); } =20 -libqos_init(virtio_mmio_register_nodes); +libqos_init(virt_machine_register_nodes); diff --git a/tests/qtest/libqos/generic-pcihost.c b/tests/qtest/libqos/gene= ric-pcihost.c new file mode 100644 index 0000000000..3124b0e46b --- /dev/null +++ b/tests/qtest/libqos/generic-pcihost.c @@ -0,0 +1,231 @@ +/* + * libqos PCI bindings for generic PCI + * + * Copyright Red Hat Inc., 2022 + * + * Authors: + * Eric Auger + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "../libqtest.h" +#include "generic-pcihost.h" +#include "qapi/qmp/qdict.h" +#include "hw/pci/pci_regs.h" +#include "qemu/host-utils.h" + +#include "qemu/module.h" + +/* QGenericPCIHost */ + +QOSGraphObject *generic_pcihost_get_device(void *obj, const char *device) +{ + QGenericPCIHost *host =3D obj; + if (!g_strcmp0(device, "pci-bus-generic")) { + return &host->pci.obj; + } + fprintf(stderr, "%s not present in generic-pcihost\n", device); + g_assert_not_reached(); +} + +void qos_create_generic_pcihost(QGenericPCIHost *host, + QTestState *qts, + QGuestAllocator *alloc) +{ + host->obj.get_device =3D generic_pcihost_get_device; + qpci_init_generic(&host->pci, qts, alloc, false); +} + +static uint8_t qpci_generic_pio_readb(QPCIBus *bus, uint32_t addr) +{ + QGenericPCIBus *s =3D container_of(bus, QGenericPCIBus, bus); + + return qtest_readb(bus->qts, s->gpex_pio_base + addr); +} + +static void qpci_generic_pio_writeb(QPCIBus *bus, uint32_t addr, uint8_t v= al) +{ + QGenericPCIBus *s =3D container_of(bus, QGenericPCIBus, bus); + + qtest_writeb(bus->qts, s->gpex_pio_base + addr, val); +} + +static uint16_t qpci_generic_pio_readw(QPCIBus *bus, uint32_t addr) +{ + QGenericPCIBus *s =3D container_of(bus, QGenericPCIBus, bus); + + return qtest_readw(bus->qts, s->gpex_pio_base + addr); +} + +static void qpci_generic_pio_writew(QPCIBus *bus, uint32_t addr, uint16_t = val) +{ + QGenericPCIBus *s =3D container_of(bus, QGenericPCIBus, bus); + + qtest_writew(bus->qts, s->gpex_pio_base + addr, val); +} + +static uint32_t qpci_generic_pio_readl(QPCIBus *bus, uint32_t addr) +{ + QGenericPCIBus *s =3D container_of(bus, QGenericPCIBus, bus); + + return qtest_readl(bus->qts, s->gpex_pio_base + addr); +} + +static void qpci_generic_pio_writel(QPCIBus *bus, uint32_t addr, uint32_t = val) +{ + QGenericPCIBus *s =3D container_of(bus, QGenericPCIBus, bus); + + qtest_writel(bus->qts, s->gpex_pio_base + addr, val); +} + +static uint64_t qpci_generic_pio_readq(QPCIBus *bus, uint32_t addr) +{ + QGenericPCIBus *s =3D container_of(bus, QGenericPCIBus, bus); + + return qtest_readq(bus->qts, s->gpex_pio_base + addr); +} + +static void qpci_generic_pio_writeq(QPCIBus *bus, uint32_t addr, uint64_t = val) +{ + QGenericPCIBus *s =3D container_of(bus, QGenericPCIBus, bus); + + qtest_writeq(bus->qts, s->gpex_pio_base + addr, val); +} + +static void qpci_generic_memread(QPCIBus *bus, uint32_t addr, void *buf, s= ize_t len) +{ + qtest_memread(bus->qts, addr, buf, len); +} + +static void qpci_generic_memwrite(QPCIBus *bus, uint32_t addr, + const void *buf, size_t len) +{ + qtest_memwrite(bus->qts, addr, buf, len); +} + +static uint8_t qpci_generic_config_readb(QPCIBus *bus, int devfn, uint8_t = offset) +{ + QGenericPCIBus *gbus =3D container_of(bus, QGenericPCIBus, bus); + uint64_t addr =3D gbus->ecam_alloc_ptr + ((0 << 20) | (devfn << 12) | = offset); + uint8_t val; + + qtest_memread(bus->qts, addr, &val, 1); + return val; +} + +static uint16_t qpci_generic_config_readw(QPCIBus *bus, int devfn, uint8_t= offset) +{ + QGenericPCIBus *gbus =3D container_of(bus, QGenericPCIBus, bus); + uint64_t addr =3D gbus->ecam_alloc_ptr + ((0 << 20) | (devfn << 12) | = offset); + uint16_t val; + + qtest_memread(bus->qts, addr, &val, 2); + return le16_to_cpu(val); +} + +static uint32_t qpci_generic_config_readl(QPCIBus *bus, int devfn, uint8_t= offset) +{ + QGenericPCIBus *gbus =3D container_of(bus, QGenericPCIBus, bus); + uint64_t addr =3D gbus->ecam_alloc_ptr + ((0 << 20) | (devfn << 12) | = offset); + uint32_t val; + + qtest_memread(bus->qts, addr, &val, 4); + return le32_to_cpu(val); +} + +static void +qpci_generic_config_writeb(QPCIBus *bus, int devfn, uint8_t offset, uint8_= t value) +{ + QGenericPCIBus *gbus =3D container_of(bus, QGenericPCIBus, bus); + uint64_t addr =3D gbus->ecam_alloc_ptr + ((0 << 20) | (devfn << 12) | = offset); + + qtest_memwrite(bus->qts, addr, &value, 1); +} + +static void +qpci_generic_config_writew(QPCIBus *bus, int devfn, uint8_t offset, uint16= _t value) +{ + QGenericPCIBus *gbus =3D container_of(bus, QGenericPCIBus, bus); + uint64_t addr =3D gbus->ecam_alloc_ptr + ((0 << 20) | (devfn << 12) | = offset); + uint16_t val =3D cpu_to_le16(value); + + qtest_memwrite(bus->qts, addr, &val, 2); +} + +static void +qpci_generic_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint32= _t value) +{ + QGenericPCIBus *gbus =3D container_of(bus, QGenericPCIBus, bus); + uint64_t addr =3D gbus->ecam_alloc_ptr + ((0 << 20) | (devfn << 12) | = offset); + uint32_t val =3D cpu_to_le32(value); + + qtest_memwrite(bus->qts, addr, &val, 4); +} + +static void *qpci_generic_get_driver(void *obj, const char *interface) +{ + QGenericPCIBus *qpci =3D obj; + if (!g_strcmp0(interface, "pci-bus")) { + return &qpci->bus; + } + fprintf(stderr, "%s not present in pci-bus-generic\n", interface); + g_assert_not_reached(); +} + +void qpci_init_generic(QGenericPCIBus *qpci, QTestState *qts, + QGuestAllocator *alloc, bool hotpluggable) +{ + assert(qts); + + qpci->gpex_pio_base =3D 0x3eff0000; + qpci->bus.not_hotpluggable =3D !hotpluggable; + qpci->bus.has_buggy_msi =3D false; + + qpci->bus.pio_readb =3D qpci_generic_pio_readb; + qpci->bus.pio_readw =3D qpci_generic_pio_readw; + qpci->bus.pio_readl =3D qpci_generic_pio_readl; + qpci->bus.pio_readq =3D qpci_generic_pio_readq; + + qpci->bus.pio_writeb =3D qpci_generic_pio_writeb; + qpci->bus.pio_writew =3D qpci_generic_pio_writew; + qpci->bus.pio_writel =3D qpci_generic_pio_writel; + qpci->bus.pio_writeq =3D qpci_generic_pio_writeq; + + qpci->bus.memread =3D qpci_generic_memread; + qpci->bus.memwrite =3D qpci_generic_memwrite; + + qpci->bus.config_readb =3D qpci_generic_config_readb; + qpci->bus.config_readw =3D qpci_generic_config_readw; + qpci->bus.config_readl =3D qpci_generic_config_readl; + + qpci->bus.config_writeb =3D qpci_generic_config_writeb; + qpci->bus.config_writew =3D qpci_generic_config_writew; + qpci->bus.config_writel =3D qpci_generic_config_writel; + + qpci->bus.qts =3D qts; + qpci->bus.pio_alloc_ptr =3D 0x0000; + qpci->bus.pio_limit =3D 0x10000; + qpci->bus.mmio_alloc_ptr =3D 0x10000000; + qpci->bus.mmio_limit =3D 0x2eff0000; + qpci->ecam_alloc_ptr =3D 0x4010000000; + + qpci->obj.get_driver =3D qpci_generic_get_driver; +} + +static void qpci_generic_register_nodes(void) +{ + qos_node_create_driver("pci-bus-generic", NULL); + qos_node_produces("pci-bus-generic", "pci-bus"); +} + +static void qpci_generic_pci_register_nodes(void) +{ + qos_node_create_driver("generic-pcihost", NULL); + qos_node_contains("generic-pcihost", "pci-bus-generic", NULL); +} + +libqos_init(qpci_generic_register_nodes); +libqos_init(qpci_generic_pci_register_nodes); diff --git a/tests/qtest/libqos/generic-pcihost.h b/tests/qtest/libqos/gene= ric-pcihost.h new file mode 100644 index 0000000000..c693c769df --- /dev/null +++ b/tests/qtest/libqos/generic-pcihost.h @@ -0,0 +1,54 @@ +/* + * libqos Generic PCI bindings and generic pci host bridge + * + * Copyright Red Hat Inc., 2022 + * + * Authors: + * Eric Auger + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef LIBQOS_GENERIC_PCIHOST_H +#define LIBQOS_GENERIC_PCIHOST_H + +#include "pci.h" +#include "malloc.h" +#include "qgraph.h" + +typedef struct QGenericPCIBus { + QOSGraphObject obj; + QPCIBus bus; + uint64_t gpex_pio_base; + uint64_t ecam_alloc_ptr; +} QGenericPCIBus; + +/* + * qpci_init_generic(): + * @ret: A valid QGenericPCIBus * pointer + * @qts: The %QTestState + * @alloc: A previously initialized @alloc providing memory for @qts + * @bool: devices can be hotplugged on this bus + * + * This function initializes an already allocated + * QGenericPCIBus object. + */ +void qpci_init_generic(QGenericPCIBus *ret, QTestState *qts, + QGuestAllocator *alloc, bool hotpluggable); + +/* QGenericPCIHost */ + +typedef struct QGenericPCIHost QGenericPCIHost; + +struct QGenericPCIHost { + QOSGraphObject obj; + QGenericPCIBus pci; +}; + +QOSGraphObject *generic_pcihost_get_device(void *obj, const char *device); +void qos_create_generic_pcihost(QGenericPCIHost *host, + QTestState *qts, + QGuestAllocator *alloc); + +#endif diff --git a/tests/qtest/libqos/meson.build b/tests/qtest/libqos/meson.build index 9f292339f9..fd5d6e5ae1 100644 --- a/tests/qtest/libqos/meson.build +++ b/tests/qtest/libqos/meson.build @@ -45,6 +45,7 @@ libqos_srcs =3D files( 'virtio-scsi.c', 'virtio-serial.c', 'virtio-iommu.c', + 'generic-pcihost.c', =20 # qgraph machines: 'aarch64-xlnx-zcu102-machine.c', --=20 2.35.1