From nobody Thu Apr 3 10:24:55 2025 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1741285644; cv=none; d=zohomail.com; s=zohoarc; b=bFxSd2L/Z1YnmrVAA2UV7WbB9RXXjRq8z1/m3Z7jknGxzXaRaA5WSUCUFv9gby/5P3kPq4/HAhb9w/JZYRO5wZ7ADAtPA6mR8esUmk24ZWdOBx69dBLNoj72CASYw2m/bgIkOkALdW6xO/7kgcu5Zs1E+G6xNcWJOFAxr/pc4FI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741285644; 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=Mvd2byRBLj1EWurRow3kwEAQYrHkAuspw1kE35aVtA8=; b=Y3eJviv+EhyNtjEunrGhRx3g12B/FIP8ZAtwB9dmftxJs69X/Bor5AbVWYDPuLohwtF9KgfLhbWduvGFmJN27WZV8Wxjdiv7G/Ubk/KYxbsuQCqtIScXzeTQpei1zfZ8ZFYx7EUN7d6fJFqN8RzqR/Cv+0qKrMInDBI15dEvi7A= 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 1741285644922534.1122187869669; Thu, 6 Mar 2025 10:27:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tqFXq-00038y-UV; Thu, 06 Mar 2025 13:02:06 -0500 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 1tqFXk-00034s-3Z for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:02:00 -0500 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tqFXa-000089-Ur for qemu-devel@nongnu.org; Thu, 06 Mar 2025 13:01:58 -0500 Received: by mail-pl1-x643.google.com with SMTP id d9443c01a7336-22337bc9ac3so21342435ad.1 for ; Thu, 06 Mar 2025 10:01:47 -0800 (PST) Received: from localhost.localdomain ([58.37.175.138]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-af28126db9bsm1338498a12.58.2025.03.06.10.01.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 10:01:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741284107; x=1741888907; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Mvd2byRBLj1EWurRow3kwEAQYrHkAuspw1kE35aVtA8=; b=Jsu+t8SGep7D8CVfGfRGz4covtcInakwnXsHbVMdIQZ99ynI8DF0yaJX2ZT4uERCY5 E6HbU7bUFDc668JT0/mL79UHYFlDCn8x0W6ox+VDd6joSqGut9JjajMk6yW6KYsqL5Eo t/n8H1/FCOKd5baKLpkwtpqnZmkP1kWhDkDtSYoxAw3jgM38czkji2cZEvs52esokDGO j8bXWFgb2BWHWQ0IsWvX9hYoDiv/Njn82iZzUGjmFqYpDVotiAZ++YAVWrqWRHC/5/wI 8H3oy2SGmkrq2DfcP32r7uiK9MQi3ZNPrZuPQbv84G8utoovqe6tLUiPuop8xLP1hkLn Zgsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741284107; x=1741888907; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Mvd2byRBLj1EWurRow3kwEAQYrHkAuspw1kE35aVtA8=; b=X4JYqQr5x7DQ/2WxFTM7zNqr/hOQJUo/iT6B5aam1RjDabvQU2mMutJr+dK0KeUHlR zvX5sT7GO+TObhA4o/QOBktwrFhUn+RoIGUqScEwZR8yIP8izUwHtWUujsH2dwLYrbxs PshvhSRXlDjh3eMrJgmc4jF2OCwEcroeXUFKZvGtUtNQzlRemDPNFuBi6JZBp6Vd4boQ y4mueQwOk6/CDTr1qj5228NCUn4VUjVeVzFxcUnboo5v0d0JYmYPuw85vua/lkVwqezV bZwM92BVrfKAl+mvwC2WaImn5A6KoAH3SYpB/uISDsve6a425uve3GbAgEBZ12+BUUQu DzQw== X-Gm-Message-State: AOJu0YzIWyGc0qAeVmdpOtFySYT40R286sqQcPrVo8Drmx0woB62hMM6 u849W+aETK2IW/QABeQFgWaqWOs4tYR4vD8FgsZ5eBScKUlJqux50Rg6cRFdIw== X-Gm-Gg: ASbGncsqQjzpsVBgBU25Rnl0XNvZtsyQEKNEhhcciir5/sGvhRqO1/CikGIOrN7B/5N OU5bxLUCbEikqJFGSJgKT0HKaJE4FJgQlc24OCy5scpO5mH2ZCQxjh29faym2TzeDk/3JzXzOI/ A2fcqvOrFZukcV/HhEHbtSbldvy1REtcJta8UPwI0bmqpjF/nGbJDUddxqM9XOCLWfUCo91SVID EOqZMBYYBfQzwgOrtZAl+jUK9DWesT5WGFzBpeQl3AB6SpWRKYYl6Ht8MShha6EuYf2LkilCE0H K3A78WdoKYtuaPfiXGIzdlFeKItqMRV1RHw8AEcl+Qv3bXyWWjjh0PR+Kw== X-Google-Smtp-Source: AGHT+IEPu+g214qh6HyKpc9FbNm2wQshtagCkuKR9pSGN+w7eUUnIi/mwORZIcKOrfc87ef9uxr+kg== X-Received: by 2002:a05:6a21:78a7:b0:1f3:194b:30b0 with SMTP id adf61e73a8af0-1f544ad717cmr663232637.5.1741284106595; Thu, 06 Mar 2025 10:01:46 -0800 (PST) From: Tomita Moeko To: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Cc: qemu-devel@nongnu.org, =?UTF-8?q?Corvin=20K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 04/10] vfio/igd: Move LPC bridge initialization to a separate function Date: Fri, 7 Mar 2025 02:01:24 +0800 Message-ID: <20250306180131.32970-5-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250306180131.32970-1-tomitamoeko@gmail.com> References: <20250306180131.32970-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::643; envelope-from=tomitamoeko@gmail.com; helo=mail-pl1-x643.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1741285646557019000 Content-Type: text/plain; charset="utf-8" A new option will soon be introduced to decouple the LPC bridge/Host bridge ID quirk from legacy mode. To prepare for this, move the LPC bridge initialization into a separate function. Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 122 +++++++++++++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 52 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 50e4007abe..9d2b761d1d 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -351,6 +351,72 @@ static int vfio_pci_igd_lpc_init(VFIOPCIDevice *vdev, return ret; } =20 +static bool vfio_pci_igd_setup_lpc_bridge(VFIOPCIDevice *vdev, Error **err= p) +{ + g_autofree struct vfio_region_info *host =3D NULL; + g_autofree struct vfio_region_info *lpc =3D NULL; + PCIDevice *lpc_bridge; + int ret; + + /* + * Copying IDs or creating new devices are not supported on hotplug + */ + if (vdev->pdev.qdev.hotplugged) { + error_setg(errp, "IGD LPC is not supported on hotplugged device"); + return false; + } + + /* + * We need to create an LPC/ISA bridge at PCI bus address 00:1f.0 that= we + * can stuff host values into, so if there's already one there and it'= s not + * one we can hack on, this quirk is no-go. Sorry Q35. + */ + lpc_bridge =3D pci_find_device(pci_device_root_bus(&vdev->pdev), + 0, PCI_DEVFN(0x1f, 0)); + if (lpc_bridge && !object_dynamic_cast(OBJECT(lpc_bridge), + "vfio-pci-igd-lpc-bridge")) { + error_setg(errp, + "Cannot create LPC bridge due to existing device at 1f.= 0"); + return false; + } + + /* + * Check whether we have all the vfio device specific regions to + * support LPC quirk (added in Linux v4.6). + */ + ret =3D vfio_get_dev_region_info(&vdev->vbasedev, + VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_I= NTEL, + VFIO_REGION_SUBTYPE_INTEL_IGD_LPC_CFG, &lpc); + if (ret) { + error_setg(errp, "IGD LPC bridge access is not supported by kernel= "); + return false; + } + + ret =3D vfio_get_dev_region_info(&vdev->vbasedev, + VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_I= NTEL, + VFIO_REGION_SUBTYPE_INTEL_IGD_HOST_CFG, &host); + if (ret) { + error_setg(errp, "IGD host bridge access is not supported by kerne= l"); + return false; + } + + /* Create/modify LPC bridge */ + ret =3D vfio_pci_igd_lpc_init(vdev, lpc); + if (ret) { + error_setg(errp, "Failed to create/modify LPC bridge for IGD"); + return false; + } + + /* Stuff some host values into the VM PCI host bridge */ + ret =3D vfio_pci_igd_host_init(vdev, host); + if (ret) { + error_setg(errp, "Failed to modify host bridge for IGD"); + return false; + } + + return true; +} + #define IGD_GGC_MMIO_OFFSET 0x108040 #define IGD_BDSM_MMIO_OFFSET 0x1080C0 =20 @@ -419,9 +485,6 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int= nr) void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) { g_autofree struct vfio_region_info *rom =3D NULL; - g_autofree struct vfio_region_info *host =3D NULL; - g_autofree struct vfio_region_info *lpc =3D NULL; - PCIDevice *lpc_bridge; int ret, gen; uint64_t gms_size; uint64_t *bdsm_size; @@ -440,20 +503,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, in= t nr) return; } =20 - /* - * We need to create an LPC/ISA bridge at PCI bus address 00:1f.0 that= we - * can stuff host values into, so if there's already one there and it'= s not - * one we can hack on, legacy mode is no-go. Sorry Q35. - */ - lpc_bridge =3D pci_find_device(pci_device_root_bus(&vdev->pdev), - 0, PCI_DEVFN(0x1f, 0)); - if (lpc_bridge && !object_dynamic_cast(OBJECT(lpc_bridge), - "vfio-pci-igd-lpc-bridge")) { - error_report("IGD device %s cannot support legacy mode due to exis= ting " - "devices at address 1f.0", vdev->vbasedev.name); - return; - } - /* * IGD is not a standard, they like to change their specs often. We * only attempt to support back to SandBridge and we hope that newer @@ -490,28 +539,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, in= t nr) return; } =20 - /* - * Check whether we have all the vfio device specific regions to - * support legacy mode (added in Linux v4.6). If not, bail. - */ - ret =3D vfio_get_dev_region_info(&vdev->vbasedev, - VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_I= NTEL, - VFIO_REGION_SUBTYPE_INTEL_IGD_HOST_CFG, &host); - if (ret) { - error_report("IGD device %s does not support host bridge access," - "legacy mode disabled", vdev->vbasedev.name); - return; - } - - ret =3D vfio_get_dev_region_info(&vdev->vbasedev, - VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_I= NTEL, - VFIO_REGION_SUBTYPE_INTEL_IGD_LPC_CFG, &lpc); - if (ret) { - error_report("IGD device %s does not support LPC bridge access," - "legacy mode disabled", vdev->vbasedev.name); - return; - } - gmch =3D vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4); =20 /* @@ -533,19 +560,10 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, i= nt nr) return; } =20 - /* Create our LPC/ISA bridge */ - ret =3D vfio_pci_igd_lpc_init(vdev, lpc); - if (ret) { - error_report("IGD device %s failed to create LPC bridge, " - "legacy mode disabled", vdev->vbasedev.name); - return; - } - - /* Stuff some host values into the VM PCI host bridge */ - ret =3D vfio_pci_igd_host_init(vdev, host); - if (ret) { - error_report("IGD device %s failed to modify host bridge, " - "legacy mode disabled", vdev->vbasedev.name); + /* Setup LPC bridge / Host bridge PCI IDs */ + if (!vfio_pci_igd_setup_lpc_bridge(vdev, &err)) { + error_append_hint(&err, "IGD legacy mode disabled\n"); + error_report_err(err); return; } =20 --=20 2.47.2