Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755278AbbHXTKB (ORCPT ); Mon, 24 Aug 2015 15:10:01 -0400 Received: from mail-bl2on0123.outbound.protection.outlook.com ([65.55.169.123]:10049 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750992AbbHXTJ6 (ORCPT ); Mon, 24 Aug 2015 15:09:58 -0400 Authentication-Results: spf=none (sender IP is 165.204.84.221) smtp.mailfrom=amd.com; arm.com; dkim=none (message not signed) header.d=none; X-WSS-ID: 0NTLP8H-07-OHM-02 X-M-MSG: Subject: Re: [PATCH] pci: acpi: Generic function for setting up PCI device DMA coherency To: Bjorn Helgaas References: <1439459925-2361-1-git-send-email-Suravee.Suthikulpanit@amd.com> <20150814015004.GA26431@google.com> CC: Rafael Wysocki , Len Brown , "Catalin Marinas" , Will Deacon , "Hanjun Guo" , "linux-acpi@vger.kernel.org" , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" , linux-arm , Rob Herring , Murali Karicheri , Jeremy Linton From: Suravee Suthikulpanit Message-ID: <55DB6BF6.1030206@amd.com> Date: Tue, 25 Aug 2015 02:09:42 +0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.180.168.240] X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD044;1:fwzHuvm1zGg4yOhDigrvvPI6w0BG3NibM+1w3VpoZOC8D2RlHDW+ZPwYSGCdQzrZXkGUwjkoHGBAKVyluAlmN9BHD/G7Gr+oObSzg4pbkLAogdlw7bFLLj/DNvN1GAZGP3CRNoQ6dF96o/jgeJ2q/i/WcTmHEagPW2TvNMOQ//nRlqLRUBpTkmGhQmx7GHOuSxTwI6p+SoivW5+kVsN7n42DV/Dc/kQpWLP+MK8GT6RAExeMc/GHTvCTSGWBncE+9TFNx7xVtl/oZ9uOo0yUYae/Ym1P6x9g3zNOWZVilbKIRPQ1ecCMxMKmSfz1yNAmLPS1d61R9l/qAMW9xavjFU2IJmYWFxDKSO6EsafQb7B0s0MzQ1XXK2WB3SJBi7V/ X-Forefront-Antispam-Report: CIP:165.204.84.221;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(428002)(3050300001)(24454002)(479174004)(76104003)(377454003)(189002)(164054003)(43544003)(199003)(5001830100001)(97736004)(80316001)(575784001)(110136002)(19580395003)(47776003)(2950100001)(4001350100001)(59896002)(101416001)(68736005)(189998001)(23676002)(86362001)(19580405001)(105586002)(65956001)(87936001)(4001540100001)(5004730100002)(65816999)(5001860100001)(64706001)(106466001)(50986999)(50466002)(54356999)(33656002)(64126003)(83506001)(46102003)(65806001)(76176999)(87266999)(36756003)(15975445007)(77156002)(62966003)(77096005)(5007970100001)(92566002)(41533002);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR0201MB1473;H:atltwp01.amd.com;FPR:;SPF:None;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BLUPR0201MB1473;2:Lv7+5ol8ddZYmZU+lZVnKJth3mQayxMrHknkroZKS7RABBIks5ah8FyyBxQI4HBTpeaHrxbzIrmtZJqulobbGfju64sM4fm8c91mOpqGGb6nUKyz4uhc2yd/TxkAnJC3gCcNw8joudc4IujF4TmQ19UICDiB/K3KTDUzin8Q8Hk=;3:B566A0U3FF2PCym8PDOmpmcl7EJ0Uyw7uI9d/ICSeTQswO+op4dYfSfa8ojw6QKPzGP3/TACqdcnS61n9swPQepPrGnH9MI0qJG47YNIQZp5YjujYX/Qp3UOVS2LVCanSfUmBWKJLtZYkqXLZ1UUAT1y0SJayUV1ugZd6vzdKF8h7WQNyZ2kL/qcaBtlU+I3/gn8lR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6N9fceyQ8EwR8jy74viPPnfROdlvkkpQ0JUsN4jfkbGvcWEplInp6pRyC87KvnHmXsit0LlqfvE+HyjHXXMXA1zWolPUiu4DD6KsYMtcgvJgpFkrIGKsHMCCx9AsswtqlPqbwDXetvukzJ+eN6uvwfl3m78XQTOfRDVzTz71GPyzXYErd7RnByhwajh6dIRqt1rJO6Pl5n3p X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(8121501046)(3002001);SRVR:BLUPR0201MB1473;BCL:0;PCL:0;RULEID:;SRVR:BLUPR0201MB1473; X-Forefront-PRVS: 06780E24F8 X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTFVQUjAyMDFNQjE0NzM7MjM6RkpDRHRZQnp4aU02bzRRaEdtcDVUb3o0?= =?utf-8?B?czdBdVNvUDYzRE1OdkV2d2ZsVnVEemtPQWU3RUhoTDBZSXErZHVsNDJtMjF4?= =?utf-8?B?aThvb1gyVUY1RWMrYVU4aEpPcCtIV005RDcwVWdtejNpSlFteUZxbVlLYU5h?= =?utf-8?B?bEtTcDBqQmN6QnNmMy9Zc2ZRdHArRllYVUw5c05OY1VUdHhWdVduaWo1cjhn?= =?utf-8?B?RTBxWDJ2d2t3S2s1b1BnV2xCMVk3M2dBMEpGcnN0bWVBVFU0eEQ0V1lGRzVr?= =?utf-8?B?RDRNaGhQdWRsRGdsbDNOZVNwVCtPQ3d0NzFRRFF4clQ5a0tQZ0YwYk1kS0wv?= =?utf-8?B?UHRnd2phTjRtblo0SFpuMHh0TzdhQmd4WUVaVkRQM25wL2s0dktDcnlhQ2xk?= =?utf-8?B?MG5JZ0xycWcwQTJpZ3FtN0o3Nzc1NDN6NWRGRWIyRjAvbU14eDlmcUo3QlJq?= =?utf-8?B?MFVRVms3aGgwemRCY0ZFb1pOVllCbFpwUGg4aFFlSk96b2lqU3ZQVURiNTMr?= =?utf-8?B?RWd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PM X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2015 19:09:54.3108 (UTC) X-MS-Exchange-CrossTenant-Id: fde4dada-be84-483f-92cc-e026cbee8e96 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fde4dada-be84-483f-92cc-e026cbee8e96;Ip=[165.204.84.221];Helo=[atltwp01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0201MB1473 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 8365 Lines: 215 Hi Bjorn, On 8/25/15 00:32, Bjorn Helgaas wrote: > Here it is again. > > On Thu, Aug 13, 2015 at 6:50 PM, Bjorn Helgaas wrote: >> 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? Sure, I can take care of that and separate them 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 Please see my response below. >> [...] >>> 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. >> I'll take care of this. >>> +{ >>> + 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. >> I was trying to save some additional logic. But, think again I should not have done so. I'll fix this. >> [...] >> 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) >> Actually, the reason I put the comment in the acpi_check_dma() is because the logic for determining the coherency is in this function, which is separate from the CCA parsing/detection logic. I can probably just get rid of the inline and move the whole function into /driver/acpi/scan.c to make it more readable, and fix the typos. >> 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 This was because, at one point, we wanted to be able to differentiate between the case _CCA=0 and missing _CCA in ARM64, where we would support DMA (using arch-specific cache maintenance) if _CCA=0, and disable DMA when missing _CCA on ARM64. It seems like the logic is now required (please see https://www.mail-archive.com/linux-usb@vger.kernel.org/msg62735.html). So, we would need the true/false return, and the coherent variable to be able to differentiate between the two cases. Please let me know what you think. Thanks, Suravee -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/