From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 72E87D2A53C for ; Wed, 16 Oct 2024 18:10:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=5uhFNN33rkOBbo0X4+mInZUuFyIJuu4VucaM/qHKNC0=; b=OCLqWMzRCcLGRkEwAluUKpli7k xUdOQd0yh89c51IqC0F/KJ8ZQtSh1v7zLUqkkxzxl2SMWSw6FrjJSz7S7PESZrflptpHnlBfgejXw sho3NPMy/aEycTXm9+mo+Wu/tBtSTRnHyJax4Z5MmP8ua0YVowY59FpvMKAfbW2cOd1YjARmt2UR0 PWmibaxiVGKm924ELNAdsnDHFbHu0gPcE6RioaFvDf2RyZdm+I5jwPC6rsWubVsX12R5enQvKCkbY yRnZ7i6DzOlDdHHBfe/LFH4qj+3OibNoSHSd72IrXnEGWq2qW27W9W5Wg1ZmmKbrS8xJmF7RJj3T4 3XmCyCPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t18Td-0000000CeAS-2oES; Wed, 16 Oct 2024 18:10:29 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t18SC-0000000Cdxv-2Ft0 for linux-arm-kernel@lists.infradead.org; Wed, 16 Oct 2024 18:09:02 +0000 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-2e2bd0e2c4fso65558a91.3 for ; Wed, 16 Oct 2024 11:08:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1729102139; x=1729706939; darn=lists.infradead.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=5uhFNN33rkOBbo0X4+mInZUuFyIJuu4VucaM/qHKNC0=; b=A9y28svoHymp50c/2JX7rADKIn7HyJYWXJEl0hjk6YnFWkqG1VDx1I5b22hxmP65VW J53RyizQmsO6V4WXuuGiCuRJp9ty6qgawAkytnpAwL6hN1NgjyvHeFGeX9aETbSX9uVS Ot5JO17dBXEcszilB4ws6tqNjDJFGSyExVYsaKs1Hr9iJBxqeSnbqjF/l/caUQ9Jc/RZ SxsD9FV/2Tzl4KHseb386/f6xObQRn9CtWH0GlOm4TBAJ1RKwkCn7d79IJDgDPgmvWZ7 8ZeLzve8qNLdG72FsYJy4nGU9ZeEy56zAn4IObP3MLRj73T7BTavFcclPW/fE4UqkEEr Svdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729102139; x=1729706939; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5uhFNN33rkOBbo0X4+mInZUuFyIJuu4VucaM/qHKNC0=; b=UkwDtS3v0i2/dkXhQ2bs9Uwx4A3zzVcM3jO/ufk4X0Va8F56W2ydwTERldJdpaaS4g 8ifSju9qzv33a+GPyKMHBvddhaFw3k+HKD1JA0x3tLeQGnHj2pp8yzg4DGaYZSlxc3tA DpN2dKWcmp/FN4v5kVV8V6VRNPe2JQK7lQZDYW5kkWH0yzjT/LW6cNpsX458klJC5jAX nrIIAVzZXmGTZQiEQ7xyrl1Ec5n9phxmm5t+/6TzDtGLQpnEmK9xKf5ULJEBxKOubJNI fURgPIgTkh4wzU3KITJwtsli4X5B5ww4KbrPYyese86ZJkyc47RRT7qcB7Dp6wHT9HYk jcvA== X-Forwarded-Encrypted: i=1; AJvYcCWY3IXdZ28Dlu9oxfyiTtm4bJGvihkA0ahT9QwN6PZTuqxzXYqTKtI9FcQuctJqDh/hNHVkWJzPTzcEO/KSXGlR@lists.infradead.org X-Gm-Message-State: AOJu0YzZIq5+4ryB0wERIcLMB3l2qyi5k6MNr5vg5uIrZhjoNOZH1Ddq Rv2ki+01pEzKfwEoon/NNH/d05nRkJr4ehoqeXZwTDSXe7K8TgK4WDk6USJkZw== X-Google-Smtp-Source: AGHT+IGPB/e3Mv/kBhAsvannUBHkBVdeyvA4J3m8LTgwvb/W9x7q39/hVQ+QnlMomNBs8BHh+WJXvA== X-Received: by 2002:a17:90a:e2d7:b0:2e2:ca12:6bc7 with SMTP id 98e67ed59e1d1-2e2f0d9da63mr21713239a91.33.1729102138690; Wed, 16 Oct 2024 11:08:58 -0700 (PDT) Received: from thinkpad ([220.158.156.88]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e3e01003a8sm78075a91.12.2024.10.16.11.08.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 11:08:58 -0700 (PDT) Date: Wed, 16 Oct 2024 23:38:49 +0530 From: Manivannan Sadhasivam To: Frank Li Cc: Lorenzo Pieralisi , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Rob Herring , Bjorn Helgaas , Krzysztof Kozlowski , Conor Dooley , Abraham I , Saravana Kannan , Jingoo Han , Gustavo Pimentel , Jesper Nilsson , Richard Zhu , Lucas Stach , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , linux-pci@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@axis.com, linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev, Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= Subject: Re: [PATCH v2 1/4] PCI: dwc: ep: Add bus_addr_base for outbound window Message-ID: <20241016180849.w7vppj2bsvagqhb7@thinkpad> References: <20240923-pcie_ep_range-v2-0-78d2ea434d9f@nxp.com> <20240923-pcie_ep_range-v2-1-78d2ea434d9f@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240923-pcie_ep_range-v2-1-78d2ea434d9f@nxp.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241016_110900_631069_272F7536 X-CRM114-Status: GOOD ( 27.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Sep 23, 2024 at 02:59:19PM -0400, Frank Li wrote: > Endpoint Root complex > ┌───────┐ ┌─────────┐ > ┌─────┐ │ EP │ │ │ ┌─────┐ > │ │ │ Ctrl │ │ │ │ CPU │ > │ DDR │ │ │ │ ┌────┐ │ └──┬──┘ > │ │◄──────┼─ATU ◄─┼────────┼─┤BarN│◄─┼─────────┘ > │ │ │ │ │ └────┘ │ Outbound Transfer > └─────┘ │ │ │ │ > │ │ │ │ > │ │ │ │ > │ │ │ │ Inbound Transfer > │ │ │ │ ┌──▼──┐ > ┌───────┐ │ │ │ ┌───────┼─────►│DDR │ > │ │ outbound Transfer* │ │ │ └─────┘ > ┌─────┐ │ Bus ┼─────►│ ATU ─┬────────┼─┘ │ > │ │ │ Fabric│Bus │ │ PCI Addr │ > │ CPU ├───►│ │Addr │ │ 0xA000_0000 │ > │ │CPU │ │0x8000_0000 │ │ │ > └─────┘Addr└───────┘ │ │ │ │ > 0x7000_0000 └───────┘ └─────────┘ > > Add `bus_addr_base` to configure the outbound window address for CPU write. > The bus fabric generally passes the same address to the PCIe EP controller, > but some bus fabrics convert the address before sending it to the PCIe EP > controller. > > Above diagram, CPU write data to outbound windows address 0x7000_0000, > Bus fabric convert it to 0x8000_0000. ATU should use bus address > 0x8000_0000 as input address and convert to PCI address 0xA000_0000. > > Previously, `cpu_addr_fixup()` was used to handle address conversion. Now, > the device tree provides this information, preferring a common method. > > bus@5f000000 { > compatible = "simple-bus"; > ranges = <0x5f000000 0x0 0x5f000000 0x21000000>, > <0x80000000 0x0 0x70000000 0x10000000>; > > pcie-ep@5f010000 { > reg = <0x5f010000 0x00010000>, > <0x80000000 0x10000000>; > reg-names = "dbi", "addr_space"; > ... > }; > ... > }; > > 'ranges' in bus@5f000000 descript how address convert from CPU address > to bus address. > > Use `of_property_read_reg()` to obtain the bus address and set it to the > ATU correctly, eliminating the need for vendor-specific cpu_addr_fixup(). > > Signed-off-by: Frank Li > --- > drivers/pci/controller/dwc/pcie-designware-ep.c | 12 +++++++++++- > drivers/pci/controller/dwc/pcie-designware.h | 1 + > 2 files changed, 12 insertions(+), 1 deletion(-) > > diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c > index 43ba5c6738df1..51eefdcb1b293 100644 > --- a/drivers/pci/controller/dwc/pcie-designware-ep.c > +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c > @@ -9,6 +9,7 @@ > #include > #include > #include > +#include > #include > > #include "pcie-designware.h" > @@ -294,7 +295,7 @@ static int dw_pcie_ep_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no, > > atu.func_no = func_no; > atu.type = PCIE_ATU_TYPE_MEM; > - atu.cpu_addr = addr; > + atu.cpu_addr = addr - ep->phys_base + ep->bus_addr_base; If you convert the address here, aren't he drivers with cpu_addr_fixup() will be broken? You should only update the address if the callback is not available. - Mani > atu.pci_addr = pci_addr; > atu.size = size; > ret = dw_pcie_ep_outbound_atu(ep, &atu); > @@ -861,6 +862,7 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) > struct device *dev = pci->dev; > struct platform_device *pdev = to_platform_device(dev); > struct device_node *np = dev->of_node; > + int index; > > INIT_LIST_HEAD(&ep->func_list); > > @@ -873,6 +875,14 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) > return -EINVAL; > > ep->phys_base = res->start; > + ep->bus_addr_base = ep->phys_base; > + > + index = of_property_match_string(np, "reg-names", "addr_space"); > + if (index < 0) > + return -EINVAL; > + > + of_property_read_reg(np, index, &ep->bus_addr_base, NULL); > + > ep->addr_size = resource_size(res); > > if (ep->ops->pre_init) > diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h > index 347ab74ac35aa..c189781524fb8 100644 > --- a/drivers/pci/controller/dwc/pcie-designware.h > +++ b/drivers/pci/controller/dwc/pcie-designware.h > @@ -410,6 +410,7 @@ struct dw_pcie_ep { > struct list_head func_list; > const struct dw_pcie_ep_ops *ops; > phys_addr_t phys_base; > + phys_addr_t bus_addr_base; > size_t addr_size; > size_t page_size; > u8 bar_to_atu[PCI_STD_NUM_BARS]; > > -- > 2.34.1 > -- மணிவண்ணன் சதாசிவம்