Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5170458rwb; Sun, 13 Nov 2022 23:36:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf7st1xzJ76+ihmlRdw5WqYwiRmuxHgSt/O7JcYMLpMQ4cs96S6jesd2lV/bCFg1gpadMykC X-Received: by 2002:a17:906:374a:b0:7ad:9ad7:e882 with SMTP id e10-20020a170906374a00b007ad9ad7e882mr9334285ejc.520.1668411406118; Sun, 13 Nov 2022 23:36:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668411406; cv=none; d=google.com; s=arc-20160816; b=CfUDovaoT4+p4vXBQSURXIRU8f83LFM7FHzuA76PPeT7+dMmRb50ytl/3SoWLJ2Eb3 OoLy0BhAhNFzONUSKWA+WJtUxBtq0s0qRGEyXajTEodec1JHOFZqDvTGMbxCvxR2lOIB 4Y6MkFBrhCXWxi/RY8uB4KbxXBUDwRpRIeT1ZyIMUkQ1MG1JkoEBgEo/8NyVmg8LakYD hoYVxiNYVUWINe8vaDQGy1sxQx6TAFy1PvBfy9tRTouS8fq69/nNkm8KDDC5kHEirwxr 9uAjnXVW6jbGWuL37V0LTiwkADBiTWJaNukHi2F88yy27/7aAgmiIQW+gclPVg4XzL3m DZ0w== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=QZtprdy3YMauuNxJyGM33F0yhRH8lqvH9drf5Sla3kA=; b=ytqNNkZK2eevZ3oKRBZB8Ucht83T1zoMjSyYm7/Kv/MZdSTlXqnUEpXysHNrp4/Pz4 M92hdl6SM8VsG0ZAdroVPzaU8gvwH2Ii5dC+ZoBmJFaORDg+rWFlSEyMKFJz9vS7sHh4 O9hbUAC6xDmaVrs4NytEyKb8kxa3R2KyvNcbwZeOZ2stCcMIi5u75VxzNwEywkDN0TRz 7vz1rGToUryBhnzBEY/WYmd21b5Rd0vapbz1HDBkZB7LauDoK/3AcM6KUMllXYMoV3VY g+mTZZJx0IyuOJZSEwwSIsMI74dShQ7nntgt1oReDmgb1WwFLV/oX9Jdnz0mYixmX/fF mGHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TTKm1wq+; 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 z16-20020a05640235d000b00462535d609dsi8600794edc.97.2022.11.13.23.36.24; Sun, 13 Nov 2022 23:36:46 -0800 (PST) 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=TTKm1wq+; 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 S235827AbiKNGrK (ORCPT + 88 others); Mon, 14 Nov 2022 01:47:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234803AbiKNGrJ (ORCPT ); Mon, 14 Nov 2022 01:47:09 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B44EF64D1; Sun, 13 Nov 2022 22:47:07 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 59E9EB80D22; Mon, 14 Nov 2022 06:47:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F6CBC433D6; Mon, 14 Nov 2022 06:46:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668408425; bh=nGkXAbiksNr/IhUnct5oFWftIT89bB6FxYQx+j/zWB0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TTKm1wq+1/HYjQ2y1FBPZIX8D6LncyyFN/2lZEEsbUE+Xjj9ULe2DdgQ/YDQFGCaK LgfEtqSwj+JqcrQ1Dp/njlCFtgLrnvPmclRJMIpXxZham+jvitBB0d0jdDgIWwEcTV XzwR6pYW++r4p28fPOWcyZAM7lYb4L9OYz20RLu/y497bxx/8QECdM4s4ZNkpL3/Te zdA5S3sKDLWJAOSeZIStlSDEvppDFp5oqn2AP8/4hkLj6qSes97JyjzuKEGXhgxpUV 01X4ZVk/NhL1ynzSgSYB/xdYiGPXAeuNmWqEgcASBvaQ9M2aOZcN/H3wfC2u42k8TR lUWYvSxGUScKQ== Date: Mon, 14 Nov 2022 12:16:54 +0530 From: Manivannan Sadhasivam To: Serge Semin Cc: Rob Herring , Rob Herring , Krzysztof Kozlowski , Bjorn Helgaas , Lorenzo Pieralisi , Cai Huoqing , Robin Murphy , Jingoo Han , Gustavo Pimentel , Lorenzo Pieralisi , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Serge Semin , Alexey Malahov , Pavel Parkhomenko , Frank Li , Manivannan Sadhasivam , caihuoqing , Vinod Koul , linux-pci@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 17/20] PCI: dwc: Introduce generic resources getter Message-ID: <20221114064654.GE3869@thinkpad> References: <20221113191301.5526-1-Sergey.Semin@baikalelectronics.ru> <20221113191301.5526-18-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20221113191301.5526-18-Sergey.Semin@baikalelectronics.ru> 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 Sun, Nov 13, 2022 at 10:12:58PM +0300, Serge Semin wrote: > Currently the DW PCIe Root Port and Endpoint CSR spaces are retrieved in > the separate parts of the DW PCIe core driver. It doesn't really make > sense since the both controller types have identical set of the core CSR > regions: DBI, DBI CS2 and iATU/eDMA. Thus we can simplify the DW PCIe Host > and EP initialization methods by moving the platform-specific registers > space getting and mapping into a common method. It gets to be even more > justified seeing the CSRs base address pointers are preserved in the > common DW PCIe descriptor. Note all the OF-based common DW PCIe settings > initialization will be moved to the new method too in order to have a > single function for all the generic platform properties handling in single > place. > > A nice side-effect of this change is that the pcie-designware-host.c and > pcie-designware-ep.c drivers are cleaned up from all the direct dw_pcie > storage modification, which makes the DW PCIe core, Root Port and Endpoint > modules more coherent. > You have clubbed both generic resource API and introducing CDM_CHECK flag. Please split them into separate patches. Thanks, Mani > Signed-off-by: Serge Semin > Reviewed-by: Rob Herring > > --- > > Changelog v3: > - This is a new patch created on v3 lap of the series. > > Changelog v4: > - Convert the method name from dw_pcie_get_res() to > dw_pcie_get_resources(). (@Bjorn) > > Changelog v7: > - Get back device.of_node pointer to the dw_pcie_ep_init() method. > (@Yoshihiro) > --- > .../pci/controller/dwc/pcie-designware-ep.c | 25 +------ > .../pci/controller/dwc/pcie-designware-host.c | 15 +--- > drivers/pci/controller/dwc/pcie-designware.c | 75 ++++++++++++++----- > drivers/pci/controller/dwc/pcie-designware.h | 3 + > 4 files changed, 65 insertions(+), 53 deletions(-) > > diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c > index 237bb01d7852..f68d1ab83bb3 100644 > --- a/drivers/pci/controller/dwc/pcie-designware-ep.c > +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c > @@ -13,8 +13,6 @@ > #include > #include > > -#include "../../pci.h" > - > void dw_pcie_ep_linkup(struct dw_pcie_ep *ep) > { > struct pci_epc *epc = ep->epc; > @@ -694,23 +692,9 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) > > INIT_LIST_HEAD(&ep->func_list); > > - if (!pci->dbi_base) { > - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi"); > - pci->dbi_base = devm_pci_remap_cfg_resource(dev, res); > - if (IS_ERR(pci->dbi_base)) > - return PTR_ERR(pci->dbi_base); > - } > - > - if (!pci->dbi_base2) { > - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi2"); > - if (!res) { > - pci->dbi_base2 = pci->dbi_base + SZ_4K; > - } else { > - pci->dbi_base2 = devm_pci_remap_cfg_resource(dev, res); > - if (IS_ERR(pci->dbi_base2)) > - return PTR_ERR(pci->dbi_base2); > - } > - } > + ret = dw_pcie_get_resources(pci); > + if (ret) > + return ret; > > res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "addr_space"); > if (!res) > @@ -739,9 +723,6 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) > return -ENOMEM; > ep->outbound_addr = addr; > > - if (pci->link_gen < 1) > - pci->link_gen = of_pci_get_max_link_speed(np); > - > epc = devm_pci_epc_create(dev, &epc_ops); > if (IS_ERR(epc)) { > dev_err(dev, "Failed to create epc device\n"); > diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c > index ea923c25e12d..3ab6ae3712c4 100644 > --- a/drivers/pci/controller/dwc/pcie-designware-host.c > +++ b/drivers/pci/controller/dwc/pcie-designware-host.c > @@ -16,7 +16,6 @@ > #include > #include > > -#include "../../pci.h" > #include "pcie-designware.h" > > static struct pci_ops dw_pcie_ops; > @@ -395,6 +394,10 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp) > > raw_spin_lock_init(&pp->lock); > > + ret = dw_pcie_get_resources(pci); > + if (ret) > + return ret; > + > res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "config"); > if (res) { > pp->cfg0_size = resource_size(res); > @@ -408,13 +411,6 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp) > return -ENODEV; > } > > - if (!pci->dbi_base) { > - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi"); > - pci->dbi_base = devm_pci_remap_cfg_resource(dev, res); > - if (IS_ERR(pci->dbi_base)) > - return PTR_ERR(pci->dbi_base); > - } > - > bridge = devm_pci_alloc_host_bridge(dev, 0); > if (!bridge) > return -ENOMEM; > @@ -429,9 +425,6 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp) > pp->io_base = pci_pio_to_address(win->res->start); > } > > - if (pci->link_gen < 1) > - pci->link_gen = of_pci_get_max_link_speed(np); > - > /* Set default bus ops */ > bridge->ops = &dw_pcie_ops; > bridge->child_ops = &dw_child_pcie_ops; > diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c > index 9d78e7ca61e1..a8436027434d 100644 > --- a/drivers/pci/controller/dwc/pcie-designware.c > +++ b/drivers/pci/controller/dwc/pcie-designware.c > @@ -11,6 +11,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -19,6 +20,59 @@ > #include "../../pci.h" > #include "pcie-designware.h" > > +int dw_pcie_get_resources(struct dw_pcie *pci) > +{ > + struct platform_device *pdev = to_platform_device(pci->dev); > + struct device_node *np = dev_of_node(pci->dev); > + struct resource *res; > + > + if (!pci->dbi_base) { > + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi"); > + pci->dbi_base = devm_pci_remap_cfg_resource(pci->dev, res); > + if (IS_ERR(pci->dbi_base)) > + return PTR_ERR(pci->dbi_base); > + } > + > + /* DBI2 is mainly useful for the endpoint controller */ > + if (!pci->dbi_base2) { > + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi2"); > + if (res) { > + pci->dbi_base2 = devm_pci_remap_cfg_resource(pci->dev, res); > + if (IS_ERR(pci->dbi_base2)) > + return PTR_ERR(pci->dbi_base2); > + } else { > + pci->dbi_base2 = pci->dbi_base + SZ_4K; > + } > + } > + > + /* For non-unrolled iATU/eDMA platforms this range will be ignored */ > + if (!pci->atu_base) { > + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "atu"); > + if (res) { > + pci->atu_size = resource_size(res); > + pci->atu_base = devm_ioremap_resource(pci->dev, res); > + if (IS_ERR(pci->atu_base)) > + return PTR_ERR(pci->atu_base); > + } else { > + pci->atu_base = pci->dbi_base + DEFAULT_DBI_ATU_OFFSET; > + } > + } > + > + /* Set a default value suitable for at most 8 in and 8 out windows */ > + if (!pci->atu_size) > + pci->atu_size = SZ_4K; > + > + if (pci->link_gen < 1) > + pci->link_gen = of_pci_get_max_link_speed(np); > + > + of_property_read_u32(np, "num-lanes", &pci->num_lanes); > + > + if (of_property_read_bool(np, "snps,enable-cdm-check")) > + dw_pcie_cap_set(pci, CDM_CHECK); > + > + return 0; > +} > + > void dw_pcie_version_detect(struct dw_pcie *pci) > { > u32 ver; > @@ -639,25 +693,8 @@ static void dw_pcie_iatu_detect_regions(struct dw_pcie *pci) > > void dw_pcie_iatu_detect(struct dw_pcie *pci) > { > - struct platform_device *pdev = to_platform_device(pci->dev); > - > if (dw_pcie_iatu_unroll_enabled(pci)) { > dw_pcie_cap_set(pci, IATU_UNROLL); > - > - if (!pci->atu_base) { > - struct resource *res = > - platform_get_resource_byname(pdev, IORESOURCE_MEM, "atu"); > - if (res) { > - pci->atu_size = resource_size(res); > - pci->atu_base = devm_ioremap_resource(pci->dev, res); > - } > - if (!pci->atu_base || IS_ERR(pci->atu_base)) > - pci->atu_base = pci->dbi_base + DEFAULT_DBI_ATU_OFFSET; > - } > - > - if (!pci->atu_size) > - /* Pick a minimal default, enough for 8 in and 8 out windows */ > - pci->atu_size = SZ_4K; > } else { > pci->atu_base = pci->dbi_base + PCIE_ATU_VIEWPORT_BASE; > pci->atu_size = PCIE_ATU_VIEWPORT_SIZE; > @@ -675,7 +712,6 @@ void dw_pcie_iatu_detect(struct dw_pcie *pci) > > void dw_pcie_setup(struct dw_pcie *pci) > { > - struct device_node *np = pci->dev->of_node; > u32 val; > > if (pci->link_gen > 0) > @@ -703,14 +739,13 @@ void dw_pcie_setup(struct dw_pcie *pci) > val |= PORT_LINK_DLL_LINK_EN; > dw_pcie_writel_dbi(pci, PCIE_PORT_LINK_CONTROL, val); > > - if (of_property_read_bool(np, "snps,enable-cdm-check")) { > + if (dw_pcie_cap_is(pci, CDM_CHECK)) { > val = dw_pcie_readl_dbi(pci, PCIE_PL_CHK_REG_CONTROL_STATUS); > val |= PCIE_PL_CHK_REG_CHK_REG_CONTINUOUS | > PCIE_PL_CHK_REG_CHK_REG_START; > dw_pcie_writel_dbi(pci, PCIE_PL_CHK_REG_CONTROL_STATUS, val); > } > > - of_property_read_u32(np, "num-lanes", &pci->num_lanes); > if (!pci->num_lanes) { > dev_dbg(pci->dev, "Using h/w default number of lanes\n"); > return; > diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h > index c6dddacee3b1..081f169e6021 100644 > --- a/drivers/pci/controller/dwc/pcie-designware.h > +++ b/drivers/pci/controller/dwc/pcie-designware.h > @@ -46,6 +46,7 @@ > > /* DWC PCIe controller capabilities */ > #define DW_PCIE_CAP_IATU_UNROLL 1 > +#define DW_PCIE_CAP_CDM_CHECK 2 > > #define dw_pcie_cap_is(_pci, _cap) \ > test_bit(DW_PCIE_CAP_ ## _cap, &(_pci)->caps) > @@ -338,6 +339,8 @@ struct dw_pcie { > #define to_dw_pcie_from_ep(endpoint) \ > container_of((endpoint), struct dw_pcie, ep) > > +int dw_pcie_get_resources(struct dw_pcie *pci); > + > void dw_pcie_version_detect(struct dw_pcie *pci); > > u8 dw_pcie_find_capability(struct dw_pcie *pci, u8 cap); > -- > 2.38.1 > > -- மணிவண்ணன் சதாசிவம்