From patchwork Fri Aug 14 01:50:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 7011821 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5D9E5C05AC for ; Fri, 14 Aug 2015 01:52:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E9497207BB for ; Fri, 14 Aug 2015 01:52:29 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 810C7206EA for ; Fri, 14 Aug 2015 01:52:28 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZQ48h-0000tZ-Vm; Fri, 14 Aug 2015 01:50:36 +0000 Received: from mail-ig0-x22f.google.com ([2607:f8b0:4001:c05::22f]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZQ48f-0000mT-2H for linux-arm-kernel@lists.infradead.org; Fri, 14 Aug 2015 01:50:34 +0000 Received: by igbjg10 with SMTP id jg10so3225021igb.0 for ; Thu, 13 Aug 2015 18:50:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=zdvQva1tEIojjWh6gsXnYb+KKuL0UXvxuR2kkWwSwmY=; b=DRLSUhgfmGHkzOLJuJ7cmKBFUOdrrl99dNC8LNv8qN6GcjAXpUgERO45y6ycguHae+ +4dPOvlPMyz3wuYYcc72UGDAhF7D1GZsUPbKbps6viJ9ZTmW2eqI/uuM4I5qoBpVC/JX t/69d+stx8ndFfNibwJFj7xmI4hmWFsX8qffnLGXOFzhYSb87szIVbBFpudNzMpRmPOu FqGOSw0Rc6LkaVYM3jUzG6eXs61w1P2MOE1MpdweEp9ssAVdKw++Ebqtlv5iODoPx/07 eYJ1S1vNpcMohhWiBjVON7yGT3lm+axMt7kED23luqUl09umP6TUu7FCYh4YrZ5z/iVc zUXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=zdvQva1tEIojjWh6gsXnYb+KKuL0UXvxuR2kkWwSwmY=; b=J5N70uzoI7W2fvid0b7Fiapd1r7T9OZzlvq67TM9f7NSWkXaQRFx4FYEssF2VpQD9V Qr61xNNJ8hlpekkkItAtaPyKGR4A6Dp4Uf4fCqU22Ppf8bM4TuTl29rzkKyGSidmF9Nk wF9EpbOit+kdryN0fhQzCwQwwzCJqwXpZr6bD2poDvCpgb7k+cHsn1bGQ4srcGZuiS3X 9+xndxdaSQ7sXc4NIyziShLIa15BElc9uYmrfK7nw3Vw17xIol7vs15QHTah06ur2KPF 8YMT0dbOFoWXIXSPRvOJWLHOXSzL1oRtglareuwlXYLZZELhGju/QOygvNngv5czvozg yanw== X-Gm-Message-State: ALoCoQmn16E1v3Y4rxPyKyVy0wqM9cd0Tp1qHVtbmJHLsQ0LhAxY3wkN6HxB/HToYQWXVSpR2HnP X-Received: by 10.50.138.70 with SMTP id qo6mr366600igb.15.1439517010783; Thu, 13 Aug 2015 18:50:10 -0700 (PDT) Received: from google.com ([69.71.1.1]) by smtp.gmail.com with ESMTPSA id z3sm3024089iod.24.2015.08.13.18.50.08 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 13 Aug 2015 18:50:09 -0700 (PDT) Date: Thu, 13 Aug 2015 20:50:04 -0500 From: Bjorn Helgaas To: Suravee Suthikulpanit Subject: Re: [PATCH] pci: acpi: Generic function for setting up PCI device DMA coherency Message-ID: <20150814015004.GA26431@google.com> References: <1439459925-2361-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1439459925-2361-1-git-send-email-Suravee.Suthikulpanit@amd.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150813_185033_203417_ED33FFC2 X-CRM114-Status: GOOD ( 36.25 ) X-Spam-Score: -0.8 (/) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: catalin.marinas@arm.com, rjw@rjwysocki.net, linux-kernel@vger.kernel.org, will.deacon@arm.com, Murali Karicheri , linux-acpi@vger.kernel.org, Rob Herring , hanjun.guo@linaro.org, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, lenb@kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FSL_HELO_FAKE, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Suravee, On Thu, Aug 13, 2015 at 04:58:45PM +0700, Suravee Suthikulpanit wrote: > This patch refactors of_pci_dma_configure() into a more generic > pci_dma_configure(), which can be reused by non-OF code. > Then, it adds support for setting up PCI device DMA coherency from > ACPI _CCA object that should normally be specified in the DSDT node > of its PCI host bridge.. Since this does two things: 1) Rename of_pci_dma_configure() and move it to PCI 2) Add _CCA support, maybe it should be split into two patches? There are a couple more comments below. While looking at this, I thought some of the existing code could be made simpler and easier to follow. I appended a couple possible patches; you can incorporate them or ignore them, whatever seems best to you. Bjorn > Signed-off-by: Suravee Suthikulpanit > CC: Bjorn Helgaas > CC: Catalin Marinas > CC: Will Deacon > CC: Rafael J. Wysocki > CC: Rob Herring > CC: Murali Karicheri > --- > Note: According to the ACPI spec, the _CCA attribute is required > for ARM64. Therefore, this patch is a pre-req for ACPI PCI > support for ARM64 which is currently in development. > > Also, this should not affect other architectures since > if CCA is not required, the default value is coherent. > Please see include/acpi/acpi_bus.h: acpi_check_dma() and > drivers/acpi/scan.c: acpi_init_coherency() for more information > > drivers/of/of_pci.c | 20 -------------------- > drivers/pci/probe.c | 35 +++++++++++++++++++++++++++++++++-- > include/linux/of_pci.h | 3 --- > 3 files changed, 33 insertions(+), 25 deletions(-) > > diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c > index 5751dc5..b66ee4e 100644 > --- a/drivers/of/of_pci.c > +++ b/drivers/of/of_pci.c > @@ -117,26 +117,6 @@ int of_get_pci_domain_nr(struct device_node *node) > } > EXPORT_SYMBOL_GPL(of_get_pci_domain_nr); > > -/** > - * of_pci_dma_configure - Setup DMA configuration > - * @dev: ptr to pci_dev struct of the PCI device > - * > - * Function to update PCI devices's DMA configuration using the same > - * info from the OF node of host bridge's parent (if any). > - */ > -void of_pci_dma_configure(struct pci_dev *pci_dev) > -{ > - struct device *dev = &pci_dev->dev; > - struct device *bridge = pci_get_host_bridge_device(pci_dev); > - > - if (!bridge->parent) > - return; > - > - of_dma_configure(dev, bridge->parent->of_node); > - pci_put_host_bridge_device(bridge); > -} > -EXPORT_SYMBOL_GPL(of_pci_dma_configure); > - > #if defined(CONFIG_OF_ADDRESS) > /** > * of_pci_get_host_bridge_resources - Parse PCI host bridge resources from DT > diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c > index cefd636..e2fcd3b 100644 > --- a/drivers/pci/probe.c > +++ b/drivers/pci/probe.c > @@ -6,12 +6,14 @@ > #include > #include > #include > -#include > +#include > #include > #include > #include > #include > #include > +#include > +#include > #include > #include "pci.h" > > @@ -1544,6 +1546,35 @@ static void pci_init_capabilities(struct pci_dev *dev) > pci_enable_acs(dev); > } > > +/** > + * pci_dma_configure - Setup DMA configuration > + * @pci_dev: ptr to pci_dev struct of the PCI device > + * > + * Function to update PCI devices's DMA configuration using the same > + * info from the OF node or ACPI node of host bridge's parent (if any). > + */ > +static void pci_dma_configure(struct pci_dev *pci_dev) Almost all pci_dev pointers in probe.c are named "dev", so I would use that for this one, too. I probably would just drop the "struct device *dev" below and use "&dev->dev" the two places you need it. That's a common idiom in PCI. > +{ > + struct device *dev = &pci_dev->dev; > + struct device *bridge = pci_get_host_bridge_device(pci_dev); > + struct acpi_device *adev; > + bool coherent; > + > + if (has_acpi_companion(bridge)) { > + adev = to_acpi_node(bridge->fwnode); > + if (acpi_check_dma(adev, &coherent)) > + arch_setup_dma_ops(dev, 0, 0, NULL, coherent); > + } else { > + struct device *host = bridge->parent; > + if (!host) > + return; > + > + of_dma_configure(dev, host->of_node); > + } Why is this check reversed with respect to device_dma_is_coherent()? In device_dma_is_coherent(), we first look for an OF property, then look for ACPI _CCA. But here we check for _CCA, then for OF. > + > + pci_put_host_bridge_device(bridge); > +} > + > void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) > { > int ret; > @@ -1557,7 +1588,7 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) > dev->dev.dma_mask = &dev->dma_mask; > dev->dev.dma_parms = &dev->dma_parms; > dev->dev.coherent_dma_mask = 0xffffffffull; > - of_pci_dma_configure(dev); > + pci_dma_configure(dev); > > pci_set_dma_max_seg_size(dev, 65536); > pci_set_dma_seg_boundary(dev, 0xffffffff); > diff --git a/include/linux/of_pci.h b/include/linux/of_pci.h > index 29fd3fe..ce0e5ab 100644 > --- a/include/linux/of_pci.h > +++ b/include/linux/of_pci.h > @@ -16,7 +16,6 @@ int of_pci_get_devfn(struct device_node *np); > int of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin); > int of_pci_parse_bus_range(struct device_node *node, struct resource *res); > int of_get_pci_domain_nr(struct device_node *node); > -void of_pci_dma_configure(struct pci_dev *pci_dev); > #else > static inline int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq) > { > @@ -51,8 +50,6 @@ of_get_pci_domain_nr(struct device_node *node) > { > return -1; > } > - > -static inline void of_pci_dma_configure(struct pci_dev *pci_dev) { } > #endif > > #if defined(CONFIG_OF_ADDRESS) > -- > 2.1.0 > commit 18183957888f601807ca0e166516ae60f682eb62 Author: Bjorn Helgaas Date: Thu Aug 13 20:01:21 2015 -0500 ACPI / scan: Move _CCA comments to acpi_init_coherency() Move the comments about how we handle _CCA to the code that looks at _CCA, and fix a couple typos. No functional change. Signed-off-by: Bjorn Helgaas diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index ec25635..a12e522 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -2188,6 +2188,22 @@ static void acpi_init_coherency(struct acpi_device *adev) acpi_status status; struct acpi_device *parent = adev->parent; + /** + * Currently, we only support _CCA=1 (i.e. coherent_dma=1) + * This should be equivalent to specifying dma-coherent for + * a device in OF. + * + * For the case when _CCA=0 (i.e. coherent_dma=0 && cca_seen=1), + * we have two choices: + * case 1. Do not support and disable DMA. + * case 2. Support but rely on arch-specific cache maintenance for + * non-coherent DMA operations. + * Currently, we implement case 1 above. + * + * For the case when _CCA is missing (i.e. cca_seen=0) and + * platform specifies ACPI_CCA_REQUIRED, we do not support DMA, + * and fallback to arch-specific default handling. + */ if (parent && parent->flags.cca_seen) { /* * From ACPI spec, OSPM will ignore _CCA if an ancestor diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 83061ca..718942b 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -389,24 +389,6 @@ static inline bool acpi_check_dma(struct acpi_device *adev, bool *coherent) if (!adev) return ret; - /** - * Currently, we only support _CCA=1 (i.e. coherent_dma=1) - * This should be equivalent to specifyig dma-coherent for - * a device in OF. - * - * For the case when _CCA=0 (i.e. coherent_dma=0 && cca_seen=1), - * There are two cases: - * case 1. Do not support and disable DMA. - * case 2. Support but rely on arch-specific cache maintenance for - * non-coherence DMA operations. - * Currently, we implement case 1 above. - * - * For the case when _CCA is missing (i.e. cca_seen=0) and - * platform specifies ACPI_CCA_REQUIRED, we do not support DMA, - * and fallback to arch-specific default handling. - * - * See acpi_init_coherency() for more info. - */ if (adev->flags.coherent_dma) { ret = true; if (coherent) commit 84cfb2213cd400fef227ec0d7829ec4e12895da9 Author: Bjorn Helgaas Date: Thu Aug 13 19:49:52 2015 -0500 ACPI / scan: Rename acpi_check_dma() to acpi_dma_is_coherent() The name "acpi_check_dma()" doesn't give any much indication about what exactly it checks. The function also returns information both as a normal return value and as the "bool *coherent" return parameter. But "*coherent" doesn't actually give any extra information: it is unchanged when returning false and set to true when returning true. Rename acpi_check_dma() to acpi_dma_is_coherent() so the callers read more naturally. Drop the return parameter and just use the function return value. Signed-off-by: Bjorn Helgaas diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c index 06a67d5..fc6138d 100644 --- a/drivers/acpi/acpi_platform.c +++ b/drivers/acpi/acpi_platform.c @@ -103,7 +103,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev) pdevinfo.res = resources; pdevinfo.num_res = count; pdevinfo.fwnode = acpi_fwnode_handle(adev); - pdevinfo.dma_mask = acpi_check_dma(adev, NULL) ? DMA_BIT_MASK(32) : 0; + pdevinfo.dma_mask = acpi_dma_is_coherent(adev) ? DMA_BIT_MASK(32) : 0; pdev = platform_device_register_full(&pdevinfo); if (IS_ERR(pdev)) dev_err(&adev->dev, "platform device creation failed: %ld\n", diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c index b9657af..89b1cf8 100644 --- a/drivers/acpi/glue.c +++ b/drivers/acpi/glue.c @@ -168,7 +168,6 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev) struct list_head *physnode_list; unsigned int node_id; int retval = -EINVAL; - bool coherent; if (has_acpi_companion(dev)) { if (acpi_dev) { @@ -225,8 +224,8 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev) if (!has_acpi_companion(dev)) ACPI_COMPANION_SET(dev, acpi_dev); - if (acpi_check_dma(acpi_dev, &coherent)) - arch_setup_dma_ops(dev, 0, 0, NULL, coherent); + if (acpi_dma_is_coherent(acpi_dev)) + arch_setup_dma_ops(dev, 0, 0, NULL, true); acpi_physnode_link_name(physical_node_name, node_id); retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj, diff --git a/drivers/base/property.c b/drivers/base/property.c index f3f6d16..1124130 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -523,13 +523,9 @@ EXPORT_SYMBOL_GPL(device_get_child_node_count); bool device_dma_is_coherent(struct device *dev) { - bool coherent = false; - if (IS_ENABLED(CONFIG_OF) && dev->of_node) - coherent = of_dma_is_coherent(dev->of_node); - else - acpi_check_dma(ACPI_COMPANION(dev), &coherent); + return of_dma_is_coherent(dev->of_node); - return coherent; + return acpi_dma_is_coherent(ACPI_COMPANION(dev)); } EXPORT_SYMBOL_GPL(device_dma_is_coherent); diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 718942b..39f1be6 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -382,19 +382,12 @@ struct acpi_device { void (*remove)(struct acpi_device *); }; -static inline bool acpi_check_dma(struct acpi_device *adev, bool *coherent) +static inline bool acpi_dma_is_coherent(struct acpi_device *adev) { - bool ret = false; + if (adev && adev->flags.coherent_dma) + return true; - if (!adev) - return ret; - - if (adev->flags.coherent_dma) { - ret = true; - if (coherent) - *coherent = adev->flags.coherent_dma; - } - return ret; + return false; } static inline bool is_acpi_node(struct fwnode_handle *fwnode) diff --git a/include/linux/acpi.h b/include/linux/acpi.h index d2445fa..f29b8b5 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -562,7 +562,7 @@ static inline int acpi_device_modalias(struct device *dev, return -ENODEV; } -static inline bool acpi_check_dma(struct acpi_device *adev, bool *coherent) +static inline bool acpi_dma_is_coherent(struct acpi_device *adev) { return false; }