Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3559275rwb; Mon, 7 Aug 2023 16:03:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGtUHAX6LFYqdoFdO4QVTZGSmBKbYv6I8HWSin1IO4sA4LKadRLxwnTdEZM1YaGa/i2LTFq X-Received: by 2002:a17:902:d50e:b0:1b8:2c2a:962e with SMTP id b14-20020a170902d50e00b001b82c2a962emr13975452plg.33.1691449409561; Mon, 07 Aug 2023 16:03:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691449409; cv=none; d=google.com; s=arc-20160816; b=P1zJeYv+sxK5rw6N49OyQYGEqnElnSUlwOUioOtrWS9MeK+sPKr2ZxMB16/kdRSJzv 4c2fT9U1hivoECDt2bDeEG8vDkbIKUnrxUNtdiyfUdevTiHHqQo5nkQSKpxussIWh0cT OhK3M1IXTyXrJHgA2mGpczMISLATsQeyHAx89mKsvg6eMKjX8tkaOaavdpMGpHob/nZA 007Q4p5Pcq6Q9wbgsbldOXANw2RVLjvc0i6YzNcRpEI30ZAXodffBxliqn57nstFoIO1 QDrBXASCQVw0UsQXnQUF90DHBj4Jh2sD28nTlb8FeR3mke7JXKDIDblb2DK7m31fxoWv BVig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=dxqfg1A/mZeXTlf1stWjmaoemep8oZ0J8/qBcGNdn0w=; fh=pN/jcSMvEfqBHTJPYAbv46XH3GyFDIAvpvBd8e7DvzM=; b=EegHGdjQCpRFf+RimS8MwqY3Al7q1FPbIxVrollEXtLPx5XctiaB6XKGcWeskAFq0L X8zJ9z5OxVqPJn52ekG6yAbBP+yRyaiUrpvtI9uugPLzcGiHh+W7o810dLqSPtKUZ4C9 qemgKx7yRf2saQRwEh1SvS9WkXeO068ngRoS8uTugRVe7qQPHajNCu9ls9PDF+v1E1eU Hc6rdsyEEElFiCg/SrHbJaFx6jjybZ8q6x/f/5F9dpRjuSlIzUgUxhAhY6+GguHH8PS7 7UhrSGMZKL6adGqiIiEtzwI98QaOQ2DC23/NfoI04FjrSChlEpca069MQuk4QQUyBAf+ JI4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Vto2ACVm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m12-20020a170902c44c00b001b8af570da3si6209516plm.258.2023.08.07.16.03.17; Mon, 07 Aug 2023 16:03:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Vto2ACVm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230281AbjHGWl7 (ORCPT + 99 others); Mon, 7 Aug 2023 18:41:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229863AbjHGWl5 (ORCPT ); Mon, 7 Aug 2023 18:41:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FBB7F1; Mon, 7 Aug 2023 15:41:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (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 dfw.source.kernel.org (Postfix) with ESMTPS id 2F2BE622DC; Mon, 7 Aug 2023 22:41:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DB88C433C7; Mon, 7 Aug 2023 22:41:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691448114; bh=/wqwxDzojgw9myRfOZV564yc0J8qMQhJKtSUll8LP68=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=Vto2ACVmYOtKrWbtwRsyoqYdXTD8QSqVm8z+hf0KtmIVU72Eb6ewshTEg26/gd0XE BerjH6Lzq5bu8HPW+skCACpfVrrH+8Y1EOxOnwEASJViWHyR3cMoCSt/jvzPiWIgS5 P/f1B5s74dhXm+ya5L++o6/8YvuPorxWeh5F2t3XtDbq1qA0LYCQR0H7UYnlqkUjAb bPzcj/9jkML6UTYuux0i2oeMgp+mDyFi404BTE4f3mCB7AjAlcoFFXgp0bLiEwIk3h JVoHoB5WTIhshJwf10e+0acMiMuZMxQ1OE8SoDRMtB9rHXJN32FaTjr8cOpx97LTpG R2dpJFe4Xf0fw== Date: Mon, 7 Aug 2023 17:41:52 -0500 From: Bjorn Helgaas To: Sunil V L Cc: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Daniel Lezcano , Thomas Gleixner , Anup Patel , Marc Zyngier , Bjorn Helgaas , Robert Moore , Haibo Xu , Andrew Jones , Conor Dooley , Atish Kumar Patra Subject: Re: [RFC PATCH v1 05/21] arm64: PCI: Migrate ACPI related functions to pci-acpi.c Message-ID: <20230807224152.GA274647@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230803175916.3174453-6-sunilvl@ventanamicro.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 03, 2023 at 11:29:00PM +0530, Sunil V L wrote: > The functions defined in arm64 for ACPI support are required > for RISC-V also. To avoid duplication, copy these functions > to common location. I assume this is a "move" (not a copy) and the code being moved isn't being changed. If so, Acked-by: Bjorn Helgaas > Signed-off-by: Sunil V L > --- > arch/arm64/kernel/pci.c | 193 ---------------------------------------- > drivers/pci/pci-acpi.c | 182 +++++++++++++++++++++++++++++++++++++ > 2 files changed, 182 insertions(+), 193 deletions(-) > > diff --git a/arch/arm64/kernel/pci.c b/arch/arm64/kernel/pci.c > index 2276689b5411..fd9a7bed83ce 100644 > --- a/arch/arm64/kernel/pci.c > +++ b/arch/arm64/kernel/pci.c > @@ -6,30 +6,7 @@ > * Copyright (C) 2014 ARM Ltd. > */ > > -#include > -#include > -#include > -#include > -#include > -#include > -#include > #include > -#include > -#include > -#include > - > -#ifdef CONFIG_ACPI > -/* > - * Try to assign the IRQ number when probing a new device > - */ > -int pcibios_alloc_irq(struct pci_dev *dev) > -{ > - if (!acpi_disabled) > - acpi_pci_irq_enable(dev); > - > - return 0; > -} > -#endif > > /* > * raw_pci_read/write - Platform-specific PCI config space access. > @@ -63,173 +40,3 @@ int pcibus_to_node(struct pci_bus *bus) > EXPORT_SYMBOL(pcibus_to_node); > > #endif > - > -#ifdef CONFIG_ACPI > - > -struct acpi_pci_generic_root_info { > - struct acpi_pci_root_info common; > - struct pci_config_window *cfg; /* config space mapping */ > -}; > - > -int acpi_pci_bus_find_domain_nr(struct pci_bus *bus) > -{ > - struct pci_config_window *cfg = bus->sysdata; > - struct acpi_device *adev = to_acpi_device(cfg->parent); > - struct acpi_pci_root *root = acpi_driver_data(adev); > - > - return root->segment; > -} > - > -int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge) > -{ > - struct pci_config_window *cfg; > - struct acpi_device *adev; > - struct device *bus_dev; > - > - if (acpi_disabled) > - return 0; > - > - cfg = bridge->bus->sysdata; > - > - /* > - * On Hyper-V there is no corresponding ACPI device for a root bridge, > - * therefore ->parent is set as NULL by the driver. And set 'adev' as > - * NULL in this case because there is no proper ACPI device. > - */ > - if (!cfg->parent) > - adev = NULL; > - else > - adev = to_acpi_device(cfg->parent); > - > - bus_dev = &bridge->bus->dev; > - > - ACPI_COMPANION_SET(&bridge->dev, adev); > - set_dev_node(bus_dev, acpi_get_node(acpi_device_handle(adev))); > - > - return 0; > -} > - > -static int pci_acpi_root_prepare_resources(struct acpi_pci_root_info *ci) > -{ > - struct resource_entry *entry, *tmp; > - int status; > - > - status = acpi_pci_probe_root_resources(ci); > - resource_list_for_each_entry_safe(entry, tmp, &ci->resources) { > - if (!(entry->res->flags & IORESOURCE_WINDOW)) > - resource_list_destroy_entry(entry); > - } > - return status; > -} > - > -/* > - * Lookup the bus range for the domain in MCFG, and set up config space > - * mapping. > - */ > -static struct pci_config_window * > -pci_acpi_setup_ecam_mapping(struct acpi_pci_root *root) > -{ > - struct device *dev = &root->device->dev; > - struct resource *bus_res = &root->secondary; > - u16 seg = root->segment; > - const struct pci_ecam_ops *ecam_ops; > - struct resource cfgres; > - struct acpi_device *adev; > - struct pci_config_window *cfg; > - int ret; > - > - ret = pci_mcfg_lookup(root, &cfgres, &ecam_ops); > - if (ret) { > - dev_err(dev, "%04x:%pR ECAM region not found\n", seg, bus_res); > - return NULL; > - } > - > - adev = acpi_resource_consumer(&cfgres); > - if (adev) > - dev_info(dev, "ECAM area %pR reserved by %s\n", &cfgres, > - dev_name(&adev->dev)); > - else > - dev_warn(dev, FW_BUG "ECAM area %pR not reserved in ACPI namespace\n", > - &cfgres); > - > - cfg = pci_ecam_create(dev, &cfgres, bus_res, ecam_ops); > - if (IS_ERR(cfg)) { > - dev_err(dev, "%04x:%pR error %ld mapping ECAM\n", seg, bus_res, > - PTR_ERR(cfg)); > - return NULL; > - } > - > - return cfg; > -} > - > -/* release_info: free resources allocated by init_info */ > -static void pci_acpi_generic_release_info(struct acpi_pci_root_info *ci) > -{ > - struct acpi_pci_generic_root_info *ri; > - > - ri = container_of(ci, struct acpi_pci_generic_root_info, common); > - pci_ecam_free(ri->cfg); > - kfree(ci->ops); > - kfree(ri); > -} > - > -/* Interface called from ACPI code to setup PCI host controller */ > -struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) > -{ > - struct acpi_pci_generic_root_info *ri; > - struct pci_bus *bus, *child; > - struct acpi_pci_root_ops *root_ops; > - struct pci_host_bridge *host; > - > - ri = kzalloc(sizeof(*ri), GFP_KERNEL); > - if (!ri) > - return NULL; > - > - root_ops = kzalloc(sizeof(*root_ops), GFP_KERNEL); > - if (!root_ops) { > - kfree(ri); > - return NULL; > - } > - > - ri->cfg = pci_acpi_setup_ecam_mapping(root); > - if (!ri->cfg) { > - kfree(ri); > - kfree(root_ops); > - return NULL; > - } > - > - root_ops->release_info = pci_acpi_generic_release_info; > - root_ops->prepare_resources = pci_acpi_root_prepare_resources; > - root_ops->pci_ops = (struct pci_ops *)&ri->cfg->ops->pci_ops; > - bus = acpi_pci_root_create(root, root_ops, &ri->common, ri->cfg); > - if (!bus) > - return NULL; > - > - /* If we must preserve the resource configuration, claim now */ > - host = pci_find_host_bridge(bus); > - if (host->preserve_config) > - pci_bus_claim_resources(bus); > - > - /* > - * Assign whatever was left unassigned. If we didn't claim above, > - * this will reassign everything. > - */ > - pci_assign_unassigned_root_bus_resources(bus); > - > - list_for_each_entry(child, &bus->children, node) > - pcie_bus_configure_settings(child); > - > - return bus; > -} > - > -void pcibios_add_bus(struct pci_bus *bus) > -{ > - acpi_pci_add_bus(bus); > -} > - > -void pcibios_remove_bus(struct pci_bus *bus) > -{ > - acpi_pci_remove_bus(bus); > -} > - > -#endif > diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c > index a05350a4e49c..d6b2d64b8237 100644 > --- a/drivers/pci/pci-acpi.c > +++ b/drivers/pci/pci-acpi.c > @@ -15,6 +15,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1517,4 +1518,185 @@ static int __init acpi_pci_init(void) > > return 0; > } > + > arch_initcall(acpi_pci_init); > + > +#if defined(CONFIG_ARM64) > +/* > + * Try to assign the IRQ number when probing a new device > + */ > +int pcibios_alloc_irq(struct pci_dev *dev) > +{ > + if (!acpi_disabled) > + acpi_pci_irq_enable(dev); > + > + return 0; > +} > + > +struct acpi_pci_generic_root_info { > + struct acpi_pci_root_info common; > + struct pci_config_window *cfg; /* config space mapping */ > +}; > + > +int acpi_pci_bus_find_domain_nr(struct pci_bus *bus) > +{ > + struct pci_config_window *cfg = bus->sysdata; > + struct acpi_device *adev = to_acpi_device(cfg->parent); > + struct acpi_pci_root *root = acpi_driver_data(adev); > + > + return root->segment; > +} > + > +int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge) > +{ > + struct pci_config_window *cfg; > + struct acpi_device *adev; > + struct device *bus_dev; > + > + if (acpi_disabled) > + return 0; > + > + cfg = bridge->bus->sysdata; > + > + /* > + * On Hyper-V there is no corresponding ACPI device for a root bridge, > + * therefore ->parent is set as NULL by the driver. And set 'adev' as > + * NULL in this case because there is no proper ACPI device. > + */ > + if (!cfg->parent) > + adev = NULL; > + else > + adev = to_acpi_device(cfg->parent); > + > + bus_dev = &bridge->bus->dev; > + > + ACPI_COMPANION_SET(&bridge->dev, adev); > + set_dev_node(bus_dev, acpi_get_node(acpi_device_handle(adev))); > + > + return 0; > +} > + > +static int pci_acpi_root_prepare_resources(struct acpi_pci_root_info *ci) > +{ > + struct resource_entry *entry, *tmp; > + int status; > + > + status = acpi_pci_probe_root_resources(ci); > + resource_list_for_each_entry_safe(entry, tmp, &ci->resources) { > + if (!(entry->res->flags & IORESOURCE_WINDOW)) > + resource_list_destroy_entry(entry); > + } > + return status; > +} > + > +/* > + * Lookup the bus range for the domain in MCFG, and set up config space > + * mapping. > + */ > +static struct pci_config_window * > +pci_acpi_setup_ecam_mapping(struct acpi_pci_root *root) > +{ > + struct device *dev = &root->device->dev; > + struct resource *bus_res = &root->secondary; > + u16 seg = root->segment; > + const struct pci_ecam_ops *ecam_ops; > + struct resource cfgres; > + struct acpi_device *adev; > + struct pci_config_window *cfg; > + int ret; > + > + ret = pci_mcfg_lookup(root, &cfgres, &ecam_ops); > + if (ret) { > + dev_err(dev, "%04x:%pR ECAM region not found\n", seg, bus_res); > + return NULL; > + } > + > + adev = acpi_resource_consumer(&cfgres); > + if (adev) > + dev_info(dev, "ECAM area %pR reserved by %s\n", &cfgres, > + dev_name(&adev->dev)); > + else > + dev_warn(dev, FW_BUG "ECAM area %pR not reserved in ACPI namespace\n", > + &cfgres); > + > + cfg = pci_ecam_create(dev, &cfgres, bus_res, ecam_ops); > + if (IS_ERR(cfg)) { > + dev_err(dev, "%04x:%pR error %ld mapping ECAM\n", seg, bus_res, > + PTR_ERR(cfg)); > + return NULL; > + } > + > + return cfg; > +} > + > +/* release_info: free resources allocated by init_info */ > +static void pci_acpi_generic_release_info(struct acpi_pci_root_info *ci) > +{ > + struct acpi_pci_generic_root_info *ri; > + > + ri = container_of(ci, struct acpi_pci_generic_root_info, common); > + pci_ecam_free(ri->cfg); > + kfree(ci->ops); > + kfree(ri); > +} > + > +/* Interface called from ACPI code to setup PCI host controller */ > +struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) > +{ > + struct acpi_pci_generic_root_info *ri; > + struct pci_bus *bus, *child; > + struct acpi_pci_root_ops *root_ops; > + struct pci_host_bridge *host; > + > + ri = kzalloc(sizeof(*ri), GFP_KERNEL); > + if (!ri) > + return NULL; > + > + root_ops = kzalloc(sizeof(*root_ops), GFP_KERNEL); > + if (!root_ops) { > + kfree(ri); > + return NULL; > + } > + > + ri->cfg = pci_acpi_setup_ecam_mapping(root); > + if (!ri->cfg) { > + kfree(ri); > + kfree(root_ops); > + return NULL; > + } > + > + root_ops->release_info = pci_acpi_generic_release_info; > + root_ops->prepare_resources = pci_acpi_root_prepare_resources; > + root_ops->pci_ops = (struct pci_ops *)&ri->cfg->ops->pci_ops; > + bus = acpi_pci_root_create(root, root_ops, &ri->common, ri->cfg); > + if (!bus) > + return NULL; > + > + /* If we must preserve the resource configuration, claim now */ > + host = pci_find_host_bridge(bus); > + if (host->preserve_config) > + pci_bus_claim_resources(bus); > + > + /* > + * Assign whatever was left unassigned. If we didn't claim above, > + * this will reassign everything. > + */ > + pci_assign_unassigned_root_bus_resources(bus); > + > + list_for_each_entry(child, &bus->children, node) > + pcie_bus_configure_settings(child); > + > + return bus; > +} > + > +void pcibios_add_bus(struct pci_bus *bus) > +{ > + acpi_pci_add_bus(bus); > +} > + > +void pcibios_remove_bus(struct pci_bus *bus) > +{ > + acpi_pci_remove_bus(bus); > +} > + > +#endif > -- > 2.39.2 > > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel