Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp84377imn; Mon, 25 Jul 2022 10:39:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1teCtBv2jnusg2adzPlOOb4hvhx43Q3DPCMyGen4majxBiUCEQVC2hGJYAIMWhY65EEW5/M X-Received: by 2002:a05:6402:331d:b0:43b:ee33:8a5e with SMTP id e29-20020a056402331d00b0043bee338a5emr8148876eda.49.1658770775203; Mon, 25 Jul 2022 10:39:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658770775; cv=none; d=google.com; s=arc-20160816; b=bBc18J/OLe5iHbXWaxgTVhJSRfpzJCdp4WRWM6HVnG6ovdArXeL1L3B9PuyR6Yli+R FaccCMeADUyd+iQLZkTHZUUn8YYNvbIsCaBwksCJRgyRggflapfM8SQCqoU+C0t+P8v0 A8wGttVxOVeD5hv+gaKM4OPD8qKcM/rw0mqnLLf8nYUKjD1YztvMxyVNpgpcq7QMx9Lz vonjtrYOqMMuiQEs7823K7rbCS01KE6oHV3Iig3I4wVWaf3qDrxoD3PqA3YrF7OngimY KvUwGRRbE/3sc61wEmN3SJyZuFYTQT1qoeAKCrHfsclEd3D4X77WxrGEoAIgsawikDSz InAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=BgPULM6P/cTvFLWqZRStLZTQSJGMY3yJ07dVAyRUCBk=; b=eOJPi3z5wlDE357UXuZxTtL71MU6RstolHQWToftZQL0+zKe5aPNZ8IxTY/1rmdrM/ 1vJjQ6z+vlBKOlmW5ShaR3JR3eif7Mx4WC+mkn/sFj2+Ohb2SZ4Jlba0CIJ0eSEofuha T8XIoxq4NryRjH50upNAQ+3fXigxuhatsjxtblpSiQy+bKsiKTEQ2WBFT+KYSSeJKhm6 3uQv1kwNckyAWaCVoKGwc0zb8S8Kj57r3/TrV0WSUWhIB+t40Y9mxIV+ILcYWElUiZG/ 5/l3cZUjA7Jt1OFYzvQjaha0mLZfJrzZwoAsNSTEBoTx54SDXqd526RhBR55dxFsVyAG MrNA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v17-20020a50d091000000b0043bc450a117si13155928edd.407.2022.07.25.10.39.10; Mon, 25 Jul 2022 10:39:35 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236433AbiGYQjY (ORCPT + 99 others); Mon, 25 Jul 2022 12:39:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236338AbiGYQjQ (ORCPT ); Mon, 25 Jul 2022 12:39:16 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D2B7F1CFFB; Mon, 25 Jul 2022 09:39:14 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2CD1D152B; Mon, 25 Jul 2022 09:39:15 -0700 (PDT) Received: from mammon-tx2.austin.arm.com (mammon-tx2.austin.arm.com [10.118.28.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 63D843F73D; Mon, 25 Jul 2022 09:39:14 -0700 (PDT) From: Jeremy Linton To: linux-pci@vger.kernel.org Cc: will@kernel.org, bhelgaas@google.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, lpieralisi@kernel.org, kw@linux.com, mark.rutland@arm.com, sudeep.holla@arm.com, boqun.feng@gmail.com, catalin.marinas@arm.com, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Jeremy Linton Subject: [PATCH 3/4] PCI: host-generic: Add firmware managed config ops Date: Mon, 25 Jul 2022 11:39:04 -0500 Message-Id: <20220725163905.2024437-4-jeremy.linton@arm.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220725163905.2024437-1-jeremy.linton@arm.com> References: <20220725163905.2024437-1-jeremy.linton@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE 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 The generic PCI host driver leaves the configuration and mgmt of the clock/phy/etc on PCI root ports to the firmware and PCIe defined mechanisms as is done on UEFI/ACPI systems. If the PCIe config operations were abstracted as well then a number of the resulting Linux PCie drivers would no longer be needed. Given that Arm has standardized a generic SMC conduit for reading and writing the PCIe config space. Using it on DT based systems seems a natural way to reduce some of the driver diversity on DT based systems as well. This patch adds a compatible type "pci-host-smc-generic" which expects that the 'reg' property of the root port is missing, and the PCI SMCCC exists. When that happens it binds the SMC to the pci_ecam_ops. Signed-off-by: Jeremy Linton --- drivers/pci/controller/pci-host-common.c | 34 ++++++++++++++++------- drivers/pci/controller/pci-host-generic.c | 6 ++++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c index d3924a44db02..2673fd81d3e0 100644 --- a/drivers/pci/controller/pci-host-common.c +++ b/drivers/pci/controller/pci-host-common.c @@ -20,22 +20,41 @@ static void gen_pci_unmap_cfg(void *ptr) pci_ecam_free((struct pci_config_window *)ptr); } +__weak int pcie_has_fw_conduit(void) +{ + return -EOPNOTSUPP; +} + +__weak struct pci_config_window *pci_setup_fw_mapping(struct device *dev, + u16 seg, struct resource *bus_res) +{ + return NULL; +} + static struct pci_config_window *gen_pci_init(struct device *dev, - struct pci_host_bridge *bridge, const struct pci_ecam_ops *ops) + struct pci_host_bridge *bridge) { int err; struct resource cfgres; struct resource_entry *bus; struct pci_config_window *cfg; + const struct pci_ecam_ops *ops; + + bus = resource_list_first_type(&bridge->windows, IORESOURCE_BUS); + if (!bus) + return ERR_PTR(-ENODEV); err = of_address_to_resource(dev->of_node, 0, &cfgres); if (err) { + if (!pcie_has_fw_conduit()) + return pci_setup_fw_mapping(dev, bridge->busnr, bus->res); + dev_err(dev, "missing \"reg\" property\n"); return ERR_PTR(err); } - bus = resource_list_first_type(&bridge->windows, IORESOURCE_BUS); - if (!bus) + ops = of_device_get_match_data(dev); + if (!ops) return ERR_PTR(-ENODEV); cfg = pci_ecam_create(dev, &cfgres, bus->res, ops); @@ -54,11 +73,6 @@ int pci_host_common_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct pci_host_bridge *bridge; struct pci_config_window *cfg; - const struct pci_ecam_ops *ops; - - ops = of_device_get_match_data(&pdev->dev); - if (!ops) - return -ENODEV; bridge = devm_pci_alloc_host_bridge(dev, 0); if (!bridge) @@ -69,7 +83,7 @@ int pci_host_common_probe(struct platform_device *pdev) of_pci_check_probe_only(); /* Parse and map our Configuration Space windows */ - cfg = gen_pci_init(dev, bridge, ops); + cfg = gen_pci_init(dev, bridge); if (IS_ERR(cfg)) return PTR_ERR(cfg); @@ -78,7 +92,7 @@ int pci_host_common_probe(struct platform_device *pdev) pci_add_flags(PCI_REASSIGN_ALL_BUS); bridge->sysdata = cfg; - bridge->ops = (struct pci_ops *)&ops->pci_ops; + bridge->ops = (struct pci_ops *)&cfg->ops->pci_ops; bridge->msi_domain = true; return pci_host_probe(bridge); diff --git a/drivers/pci/controller/pci-host-generic.c b/drivers/pci/controller/pci-host-generic.c index 63865aeb636b..d20d33b3c689 100644 --- a/drivers/pci/controller/pci-host-generic.c +++ b/drivers/pci/controller/pci-host-generic.c @@ -56,6 +56,9 @@ static const struct pci_ecam_ops pci_dw_ecam_bus_ops = { } }; +static const struct pci_ecam_ops pci_generic_smc_ops = { +}; + static const struct of_device_id gen_pci_of_match[] = { { .compatible = "pci-host-cam-generic", .data = &gen_pci_cfg_cam_bus_ops }, @@ -63,6 +66,9 @@ static const struct of_device_id gen_pci_of_match[] = { { .compatible = "pci-host-ecam-generic", .data = &pci_generic_ecam_ops }, + { .compatible = "pci-host-smc-generic", + .data = &pci_generic_smc_ops }, + { .compatible = "marvell,armada8k-pcie-ecam", .data = &pci_dw_ecam_bus_ops }, -- 2.37.1