From patchwork Wed Aug 26 13:54:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 7077541 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 27F5B9F344 for ; Wed, 26 Aug 2015 13:56:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 05F1F2088B for ; Wed, 26 Aug 2015 13:56:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6A763208A5 for ; Wed, 26 Aug 2015 13:56:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755582AbbHZNzS (ORCPT ); Wed, 26 Aug 2015 09:55:18 -0400 Received: from mail-bn1on0063.outbound.protection.outlook.com ([157.56.110.63]:49408 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752552AbbHZNzN (ORCPT ); Wed, 26 Aug 2015 09:55:13 -0400 Received: from DM3PR12CA0041.namprd12.prod.outlook.com (10.164.12.179) by BLUPR12MB0707.namprd12.prod.outlook.com (10.163.218.145) with Microsoft SMTP Server (TLS) id 15.1.243.23; Wed, 26 Aug 2015 13:55:09 +0000 Received: from DM3NAM03FT009.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e49::200) by DM3PR12CA0041.outlook.office365.com (2a01:111:e400:599f::51) with Microsoft SMTP Server (TLS) id 15.1.256.15 via Frontend Transport; Wed, 26 Aug 2015 13:55:09 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.222) smtp.mailfrom=amd.com; arm.com; dkim=none (message not signed) header.d=none; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from atltwp02.amd.com (165.204.84.222) by DM3NAM03FT009.mail.protection.outlook.com (10.152.82.114) with Microsoft SMTP Server id 15.1.256.10 via Frontend Transport; Wed, 26 Aug 2015 13:55:04 +0000 X-WSS-ID: 0NTOZZP-08-NV9-02 X-M-MSG: Received: from satlvexedge01.amd.com (satlvexedge01.amd.com [10.177.96.28]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by atltwp02.amd.com (Axway MailGate 5.3.1) with ESMTPS id 2905DD16002; Wed, 26 Aug 2015 09:55:00 -0400 (EDT) Received: from SATLEXDAG01.amd.com (10.181.40.3) by satlvexedge01.amd.com (10.177.96.28) with Microsoft SMTP Server (TLS) id 14.3.195.1; Wed, 26 Aug 2015 08:55:09 -0500 Received: from ssuthiku-fedora-lt.amd.com (10.180.168.240) by SATLEXDAG01.amd.com (10.181.40.3) with Microsoft SMTP Server id 14.3.195.1; Wed, 26 Aug 2015 09:55:00 -0400 From: Suravee Suthikulpanit To: , , , , CC: , , , , , Suravee Suthikulpanit , Rob Herring Subject: [PATCH V3 2/4] ACPI/scan: Clean up acpi_check_dma Date: Wed, 26 Aug 2015 20:54:37 +0700 Message-ID: <1440597279-11802-3-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1440597279-11802-1-git-send-email-Suravee.Suthikulpanit@amd.com> References: <1440597279-11802-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:165.204.84.222; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(428002)(3050300001)(189002)(199003)(2950100001)(48376002)(68736005)(5003940100001)(5003600100002)(105586002)(47776003)(64706001)(2201001)(50986999)(77156002)(50466002)(87936001)(53416004)(62966003)(46102003)(5001860100001)(92566002)(36756003)(575784001)(86362001)(5001830100001)(229853001)(5007970100001)(4001540100001)(76176999)(101416001)(5001770100001)(19580405001)(19580395003)(50226001)(106466001)(77096005)(189998001)(97736004); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR12MB0707; H:atltwp02.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0707; 2:Ok+cCzCfxxCTz+4Of3Z63ZBQ38nFPKU21gmGmTS+vLc9Z0fkX4+GLfGHaGWZ/TwW2ajTC6v55wOzZZjX8lpLJR2t/LnP/LjG6SXvo8MHNO7GZqw+95dwZjPOzrNm3M3fg1bZHQWNqLc9nhz5f1kr+ieXIrFAHI1NlS8NnsJHpf8=; 3:ylW8S4J82x1MKViPVVwp8sK985apEUfdRarWya4NBFcXOtUuG17bOCWUTLSWKfMs6piD+XvK6qKyRNMGi9sCiH+MQnvtlCvbPbirqX7++wMVRx2tJyM90wacmf79QDT6392Yf0gAPBxzc7f5UAOTeuhPHhJlzu/vhFuG6rNCpUxh39sGb+TkJEK3ZizU/BnwvyXL0OLyg7h2Iy5UMHkbQzr2lmKwwj9NhhpnehgU8vWcESX/8rQkxoVxPZoiDYxp; 25:zI4O6kyIIM5mnW62FCgq5mcwfiWUZRWSAXAhSbHNvbToQe56O/WCplS2B9lc4PY6EehLaDC2X7ifbcIthMeaUek7h+3biiR2ztMjOjdbRCpkwM6w8Yb0WusDg7KG5OnjcqKcsqECYwyvAtH9xWqCSnyfDINU2OIY+ZkwL2FFsJNkcNkMHT4ePrjBE6fD+86rdhKncBV95MQNd9VqL1PHeX0y3/p/isX6V1Mm4HnSmLAuVntFMES3gtLgJu8oQW6l X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR12MB0707; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0707; 20:/lInVmrfJga2nk//ENrw637z6+lpQJdUDNx6FbfNjmaLCrlhaJNLmz3pSn9Z+wv+8D10EbXSRAk5aFHyUv6zt2azRVtK3TQgo21bEjiImHI0ohuE/Lk2TPnfhbVDEzcy1ViPUjSqHlMl1AJqRnXGvBxTv0gVv07tXdmConsx0S/gHmNbFsbG7Ov6HAMfl0LKQWllu40gjnlqCdyLP9tujBM8CFOXuSll2gdzzAZO2JlZ744iYPLSjb9K/HP07d/Z2dcOouB6SifKuLS57Ko5EcpMmkx4JFzG/7ZtYPE4CtbIZDUlNlDsTx2YYsuo1vYf9OCQcH/DCstAbP6z4xkUWRIWGx9Yz9RxRXddUA1aJ9SEATg81230h3r7qRAl13JymVR5UXa2dH4IxDfk50SWDXbeLjJVRbCxxl0xnPeQC1xpzhSolPaSjvehQ5voYMbURsgGzVVzVxD7Z5iKjBp6bkmYraQZLpmEYzdtZ2KKbPBUa7TmyQecEL0PyqMlnUE2; 4:Kjtyl8h8I73UvDBpqhb1Ks3A3w5l3nVsD4hCs4l1aaM1PmJKRHZIloB2hcP9COw3FFieqEVI+pKWfr/Abaf9+8MU9182JkNlpPKjtBfoaE8r7mT0Xa2eifLh9mGj+9IIIT9lNZ32+NZNQ5iHaXEGPEF/RY6prH6aRyxBud3Q8lNDb2PxQ/vXHY4GMxDqAkH9oHcecHgRRwdxv5eShwbJdvk74b//4GCrMFQCk2kLStmlzfk2PHYh6o2qHrOXqqqILPHfmQSH2DytuHlQzC42WN5JBnORsiVJRJk063z5iBjc1zVyzaPpR9nhY7Re4CaK 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:BLUPR12MB0707; BCL:0; PCL:0; RULEID:; SRVR:BLUPR12MB0707; X-Forefront-PRVS: 0680FADD48 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR12MB0707; 23:1ZL1Qqv0Da397lzl2iD7+Icg2s+aL25cy9bxMEmoO?= =?us-ascii?Q?up2+qt6ARaV+06GN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lf2ZO3dsUZ?= =?us-ascii?Q?8qaAlTcImxIQZ04diQlGdnix3jXUdxTqHkRe0pm8hlYM9SaUt6Bq8GT9laTv?= =?us-ascii?Q?/mte8fCCK4QOnCgKsg1/BJl7xSXNKTL+yi+gykueg0N22l5sphhzJZkMCMZO?= =?us-ascii?Q?qn6EojuG9wR2AqEuBiUv4iqTjbAZl9+qIZ92qZzo2UANFVlEeOWHoe9DcYbZ?= =?us-ascii?Q?owYI9n/vZW5fD0MGgJEAZd11bQIEAUc?= X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0707; 5:s95RZRCWTPznTYSGCubW8FYSa6ztou+2TIcYwsS/ZlfOMlT02xqtIExMXrhoAfnU3h7F5O2B80R8jamlbSiUAUMt4Atx7ud4xWvRhbARa+tMLG4D7UYHT/Fh2A9AQMgqXrNEpP1UdhH7gh/76oITlA==; 24:Siyw7KaHsD6i34piP/WOwtOUFwWMxPA7wTV3N5MEcrVHkC14wfn6sUUx8k+7gc8RHoW5Y3enCm75cbQTXOACLw1YHSOFru0PbZ+SwPUkbD0=; 20:OBOPKDhd1gENcWvcwoNEwXBmGSC+Kj14YZda8Cvo5JThQjcAknlBVISNZCrRcRUiywQfRrXnHJJEnGGactbF+A== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2015 13:55:04.3728 (UTC) X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.222]; Helo=[atltwp02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0707 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 The original name of acpi_check_dma() function does not clearly tell what exactly it is checking. Also, returning two boolean values (one to indicate device is DMA capability, and the other to inidicate device coherency attribute) can be confusing. So, in order to simplify the function, this patch renames acpi_check_dma() to acpi_check_dma_coherency() to clearly indicate the purpose of this function, and only returns an integer where -1 means DMA not supported, 1 means coherent DMA, and 0 means non-coherent DMA. Also, this patch moves the function into drivers/acpi/scan.c since it is easier to follow the logic in the acpi_init_coherency() in the same file here. Signed-off-by: Suravee Suthikulpanit Suggested-by: Bjorn Helgaas Suggested-by: Rafael J. Wysocki CC: Catalin Marinas CC: Rob Herring CC: Will Deacon --- drivers/acpi/acpi_platform.c | 7 ++++++- drivers/acpi/glue.c | 6 +++--- drivers/acpi/scan.c | 39 +++++++++++++++++++++++++++++++++++++++ drivers/base/property.c | 10 +++++++--- include/acpi/acpi_bus.h | 36 ++---------------------------------- include/linux/acpi.h | 4 ++-- 6 files changed, 59 insertions(+), 43 deletions(-) diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c index 06a67d5..0b17a78 100644 --- a/drivers/acpi/acpi_platform.c +++ b/drivers/acpi/acpi_platform.c @@ -103,7 +103,12 @@ 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; + + if (acpi_check_dma_coherency(adev) < 0) + pdevinfo.dma_mask = 0; + else + pdevinfo.dma_mask = DMA_BIT_MASK(32); + 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..9be7f0f 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,9 @@ 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); + retval = acpi_check_dma_coherency(acpi_dev); + if (retval >= 0) + arch_setup_dma_ops(dev, 0, 0, NULL, retval); acpi_physnode_link_name(physical_node_name, node_id); retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj, diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index ec25635..1d68289 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -2182,6 +2182,45 @@ void acpi_free_pnp_ids(struct acpi_device_pnp *pnp) kfree(pnp->unique_id); } +/** + * acpi_check_dma_coherency - Check DMA coherency for the specified device. + * @adev: The pointer to acpi device to check coherency attribute + * + * Return -ENOTSUPP if DMA is not supported. Otherwise, return 1 if the + * device support coherent DMA, or 0 for non-coherent DMA. + */ +int acpi_check_dma_coherency(struct acpi_device *adev) +{ + int ret = -ENOTSUPP; + + if (!adev) + return ret; + + /** + * 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: + * 1. Do not support and disable DMA. + * 2. Support but rely on arch-specific cache maintenance for + * non-coherenje DMA operations. + * Currently, we implement case 2 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.cca_seen && IS_ENABLED(CONFIG_ACPI_CCA_REQUIRED)) + return ret; + + return adev->flags.coherent_dma; +} +EXPORT_SYMBOL_GPL(acpi_check_dma_coherency); + static void acpi_init_coherency(struct acpi_device *adev) { unsigned long long cca = 0; diff --git a/drivers/base/property.c b/drivers/base/property.c index f3f6d16..cd45dfc 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -525,10 +525,14 @@ bool device_dma_is_coherent(struct device *dev) { bool coherent = false; - if (IS_ENABLED(CONFIG_OF) && dev->of_node) + if (IS_ENABLED(CONFIG_OF) && dev->of_node) { coherent = of_dma_is_coherent(dev->of_node); - else - acpi_check_dma(ACPI_COMPANION(dev), &coherent); + } else { + int ret = acpi_check_dma_coherency(ACPI_COMPANION(dev)); + + if (ret >= 0) + coherent = ret; + } return coherent; } diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 7ecb8e4..baf43ea 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -382,40 +382,6 @@ struct acpi_device { void (*remove)(struct acpi_device *); }; -static inline bool acpi_check_dma(struct acpi_device *adev, bool *coherent) -{ - bool ret = false; - - 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 2 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 || - (adev->flags.cca_seen && IS_ENABLED(CONFIG_ARM64))) { - ret = true; - if (coherent) - *coherent = adev->flags.coherent_dma; - } - return ret; -} - static inline bool is_acpi_node(struct fwnode_handle *fwnode) { return fwnode && fwnode->type == FWNODE_ACPI; @@ -640,6 +606,8 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev) return adev->power.states[ACPI_STATE_D3_COLD].flags.valid; } +int acpi_check_dma_coherency(struct acpi_device *adev); + #else /* CONFIG_ACPI */ static inline int register_acpi_bus_type(void *bus) { return 0; } diff --git a/include/linux/acpi.h b/include/linux/acpi.h index d2445fa..d350c9e 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -562,9 +562,9 @@ 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 int acpi_check_dma_coherency(struct acpi_device *adev) { - return false; + return -ENOTSUPP; } #define ACPI_PTR(_ptr) (NULL)