From nobody Mon Feb 9 11:51:35 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1656683139; cv=none; d=zohomail.com; s=zohoarc; b=T0FmbxNFrJ7NmuDztYOcQIZVuZPkKUl4HwVgxI2TG8g9SxTlYnALAIdA/tQwUh2kzW5+N1dSbP2o3W7bVdmIz5WGOG89t1yD0RPzAltt3CUG3RmWlwS8HdaiuGtDlqifM8YUlZrF+i7psNaRtrzA80iaNcCGI6d4Grqc58HcBxI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656683139; 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=B1HY2YviDG+7fdNOZcTrS79MXvYdAdOhm0F+WvLxLsg=; b=FTWBbr5cMPIlsJ6nDWkdX2wfyqwtJ/+3o1zMA6r//LfHEwNoMT7TtQoaYXfcIJc59pdXmr2HCKH4DIs9m9tfuLB5KfNnRgE1kS3vdyDqxgIRQjouL2ieu2qdkRLBLge+8cwd5OgXDHq4vOrtbA9Autz7XFkCLucxe1MoCCqOrkA= 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 1656683139561307.47802693018343; Fri, 1 Jul 2022 06:45:39 -0700 (PDT) Received: from localhost ([::1]:40862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7Gxm-0007Ks-8u for importer@patchew.org; Fri, 01 Jul 2022 09:45:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59026) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7Go5-00014Q-0x for qemu-devel@nongnu.org; Fri, 01 Jul 2022 09:35:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26943) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7Go2-000557-0F for qemu-devel@nongnu.org; Fri, 01 Jul 2022 09:35:36 -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-390-NsKBLZzZOTK5CcZcmn3ARg-1; Fri, 01 Jul 2022 09:35:32 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B7A5F801E80; Fri, 1 Jul 2022 13:35:31 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B47A40E7F28; Fri, 1 Jul 2022 13:35:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656682533; 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=B1HY2YviDG+7fdNOZcTrS79MXvYdAdOhm0F+WvLxLsg=; b=Bfef9NnLZZXAwS9cLZ3jPAUJLuG1/BuDt11QHS1kpi0U4EKPNqmPfKVN9DyUZVPOR1FqEl ot60LDMy01M+aD3v7wIBGg+aeX5mSl5fp2MONwxz+ACeADsdrsZZ4zgWENeMzi7j55KRuL jcig2nsRnd9ZA9PBYtMMPTxGOdy+FmU= X-MC-Unique: NsKBLZzZOTK5CcZcmn3ARg-1 From: Igor Mammedov To: qemu-devel@nongnu.org Cc: mst@redhat.com, ani@anisinha.ca Subject: [PATCH 17/17] x86: pci: acpi: deduplate PCI slots creation Date: Fri, 1 Jul 2022 09:35:15 -0400 Message-Id: <20220701133515.137890-18-imammedo@redhat.com> In-Reply-To: <20220701133515.137890-1-imammedo@redhat.com> References: <20220701133515.137890-1-imammedo@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.1 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=imammedo@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 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_NONE=-0.0001, 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: 1656683141491100001 No functional change nor AML bytcode change. Consolidate code that generates empty and populated slots descriptors. Beside of eliminating duplication, it helps to consolidate conditions for generating parts of Device{} desriptor in one place, which makes code more compact and easier to read. Signed-off-by: Igor Mammedov --- hw/i386/acpi-build.c | 111 +++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 57 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 406bbac1c7..9d0512666d 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -427,13 +427,41 @@ static void build_append_pci_bus_devices(Aml *parent_= scope, PCIBus *bus, int func =3D PCI_FUNC(devfn); /* ACPI spec: 1.0b: Table 6-2 _ADR Object Bus Types, PCI type */ int adr =3D slot << 16 | func; - bool hotplug_enabled_dev; - bool bridge_in_acpi; - bool cold_plugged_bridge; + bool hotpluggbale_slot =3D false; + bool bridge_in_acpi =3D false; + bool cold_plugged_bridge =3D false; + bool is_vga =3D false; + + if (pdev) { + pc =3D PCI_DEVICE_GET_CLASS(pdev); + dc =3D DEVICE_GET_CLASS(pdev); + + if (pc->class_id =3D=3D PCI_CLASS_BRIDGE_ISA) { + continue; + } + + is_vga =3D pc->class_id =3D=3D PCI_CLASS_DISPLAY_VGA; =20 - if (!pdev) { /* - * add hotplug slots for non present devices. + * Cold plugged bridges aren't themselves hot-pluggable. + * Hotplugged bridges *are* hot-pluggable. + */ + cold_plugged_bridge =3D pc->is_bridge && !DEVICE(pdev)->hotplu= gged; + bridge_in_acpi =3D cold_plugged_bridge && pcihp_bridge_en; + + hotpluggbale_slot =3D bsel && dc->hotpluggable && + !cold_plugged_bridge; + + /* + * allow describing coldplugged bridges in ACPI even if they a= re not + * on function 0, as they are not unpluggable, for all other d= evices + * generate description only for function 0 per slot + */ + if (func && !bridge_in_acpi) { + continue; + } + } else { + /* * hotplug is supported only for non-multifunction device * so generate device description only for function 0 */ @@ -441,46 +469,11 @@ static void build_append_pci_bus_devices(Aml *parent_= scope, PCIBus *bus, if (pci_bus_is_express(bus) && slot > 0) { break; } - dev =3D aml_device("S%.02X", devfn); - aml_append(dev, aml_name_decl("_ADR", aml_int(adr))); - aml_append(dev, aml_name_decl("ASUN", aml_int(slot))); - aml_append(dev, aml_pci_device_dsm()); - aml_append(dev, aml_name_decl("_SUN", aml_int(slot))); - method =3D aml_method("_EJ0", 1, AML_NOTSERIALIZED); - aml_append(method, - aml_call2("PCEJ", aml_name("BSEL"), aml_name("_SUN")) - ); - aml_append(dev, method); - aml_append(parent_scope, dev); - - build_append_pcihp_notify_entry(notify_method, slot); + /* mark it as empty hotpluggable slot */ + hotpluggbale_slot =3D true; + } else { + continue; } - continue; - } - - pc =3D PCI_DEVICE_GET_CLASS(pdev); - dc =3D DEVICE_GET_CLASS(pdev); - - /* - * Cold plugged bridges aren't themselves hot-pluggable. - * Hotplugged bridges *are* hot-pluggable. - */ - cold_plugged_bridge =3D pc->is_bridge && !DEVICE(pdev)->hotplugged; - bridge_in_acpi =3D cold_plugged_bridge && pcihp_bridge_en; - - hotplug_enabled_dev =3D bsel && dc->hotpluggable && !cold_plugged_= bridge; - - if (pc->class_id =3D=3D PCI_CLASS_BRIDGE_ISA) { - continue; - } - - /* - * allow describing coldplugged bridges in ACPI even if they are n= ot - * on function 0, as they are not unpluggable, for all other devic= es - * generate description only for function 0 per slot - */ - if (func && !bridge_in_acpi) { - continue; } =20 /* start to compose PCI device descriptor */ @@ -496,7 +489,7 @@ static void build_append_pci_bus_devices(Aml *parent_sc= ope, PCIBus *bus, aml_append(dev, aml_pci_device_dsm()); } =20 - if (pc->class_id =3D=3D PCI_CLASS_DISPLAY_VGA) { + if (is_vga) { /* add VGA specific AML methods */ int s3d; =20 @@ -517,19 +510,10 @@ static void build_append_pci_bus_devices(Aml *parent_= scope, PCIBus *bus, method =3D aml_method("_S3D", 0, AML_NOTSERIALIZED); aml_append(method, aml_return(aml_int(s3d))); aml_append(dev, method); - } else if (hotplug_enabled_dev) { - aml_append(dev, aml_name_decl("_SUN", aml_int(slot))); - /* add _EJ0 to make slot hotpluggable */ - method =3D aml_method("_EJ0", 1, AML_NOTSERIALIZED); - aml_append(method, - aml_call2("PCEJ", aml_name("BSEL"), aml_name("_SUN")) - ); - aml_append(dev, method); + } =20 - if (bsel) { - build_append_pcihp_notify_entry(notify_method, slot); - } - } else if (bridge_in_acpi) { + bridge_in_acpi =3D cold_plugged_bridge && pcihp_bridge_en; + if (bridge_in_acpi) { /* * device is coldplugged bridge, * add child device descriptions into its scope @@ -538,6 +522,19 @@ static void build_append_pci_bus_devices(Aml *parent_s= cope, PCIBus *bus, =20 build_append_pci_bus_devices(dev, sec_bus, pcihp_bridge_en); } + + if (hotpluggbale_slot) { + aml_append(dev, aml_name_decl("_SUN", aml_int(slot))); + /* add _EJ0 to make slot hotpluggable */ + method =3D aml_method("_EJ0", 1, AML_NOTSERIALIZED); + aml_append(method, + aml_call2("PCEJ", aml_name("BSEL"), aml_name("_SUN")) + ); + aml_append(dev, method); + + build_append_pcihp_notify_entry(notify_method, slot); + } + /* device descriptor has been composed, add it into parent context= */ aml_append(parent_scope, dev); } --=20 2.31.1