From patchwork Sun Feb 6 09:16:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 540445 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02783C433EF for ; Sun, 6 Feb 2022 09:26:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232566AbiBFJ0R (ORCPT ); Sun, 6 Feb 2022 04:26:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232361AbiBFJ0P (ORCPT ); Sun, 6 Feb 2022 04:26:15 -0500 Received: from hillosipuli.retiisi.eu (hillosipuli.retiisi.eu [IPv6:2a01:4f9:c010:4572::81:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46A4BC061355; Sun, 6 Feb 2022 01:26:14 -0800 (PST) Received: from lanttu.localdomain (unknown [IPv6:fd35:1bc8:1a6:d3d5::e1:3]) by hillosipuli.retiisi.eu (Postfix) with ESMTP id 24207634C91; Sun, 6 Feb 2022 11:18:21 +0200 (EET) From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: andriy.shevchenko@linux.intel.com, devicetree@vger.kernel.org, "Rafael J. Wysocki" , Daniel Scally , Heikki Krogerus , Rob Herring , Frank Rowand Subject: [PATCH 1/4] device property: Convert device_{dma_supported,get_dma_attr} to fwnode Date: Sun, 6 Feb 2022 11:16:40 +0200 Message-Id: <20220206091643.276833-2-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220206091643.276833-1-sakari.ailus@linux.intel.com> References: <20220206091643.276833-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Make the device_dma_supported and device_get_dma_attr functions to use the fwnode ops, and move the implementation to ACPI and OF frameworks. Depends-on: ("device property: Don't split fwnode_get_irq*() APIs in the code") Signed-off-by: Sakari Ailus --- drivers/acpi/property.c | 14 ++++++++++++++ drivers/base/property.c | 25 ++++--------------------- drivers/of/property.c | 17 +++++++++++++++++ include/linux/fwnode.h | 3 +++ 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index d0986bda2964..1541b318ba46 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -1253,6 +1253,17 @@ static bool acpi_fwnode_device_is_available(const struct fwnode_handle *fwnode) return acpi_device_is_present(to_acpi_device_node(fwnode)); } +static bool acpi_fwnode_device_dma_supported(const struct fwnode_handle *fwnode) +{ + return acpi_dma_supported(to_acpi_device_node(fwnode)); +} + +static enum dev_dma_attr +acpi_fwnode_device_get_dma_attr(const struct fwnode_handle *fwnode) +{ + return acpi_get_dma_attr(to_acpi_device_node(fwnode)); +} + static bool acpi_fwnode_property_present(const struct fwnode_handle *fwnode, const char *propname) { @@ -1384,6 +1395,9 @@ acpi_fwnode_device_get_match_data(const struct fwnode_handle *fwnode, const struct fwnode_operations ops = { \ .device_is_available = acpi_fwnode_device_is_available, \ .device_get_match_data = acpi_fwnode_device_get_match_data, \ + .device_dma_supported = \ + acpi_fwnode_device_dma_supported, \ + .device_get_dma_attr = acpi_fwnode_device_get_dma_attr, \ .property_present = acpi_fwnode_property_present, \ .property_read_int_array = \ acpi_fwnode_property_read_int_array, \ diff --git a/drivers/base/property.c b/drivers/base/property.c index c0e94cce9c29..09686e2e903e 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -823,33 +823,16 @@ EXPORT_SYMBOL_GPL(device_get_child_node_count); bool device_dma_supported(struct device *dev) { - const struct fwnode_handle *fwnode = dev_fwnode(dev); - - /* For DT, this is always supported. - * For ACPI, this depends on CCA, which - * is determined by the acpi_dma_supported(). - */ - if (is_of_node(fwnode)) - return true; - - return acpi_dma_supported(to_acpi_device_node(fwnode)); + return fwnode_call_bool_op(dev_fwnode(dev), device_dma_supported); } EXPORT_SYMBOL_GPL(device_dma_supported); enum dev_dma_attr device_get_dma_attr(struct device *dev) { - const struct fwnode_handle *fwnode = dev_fwnode(dev); - enum dev_dma_attr attr = DEV_DMA_NOT_SUPPORTED; - - if (is_of_node(fwnode)) { - if (of_dma_is_coherent(to_of_node(fwnode))) - attr = DEV_DMA_COHERENT; - else - attr = DEV_DMA_NON_COHERENT; - } else - attr = acpi_get_dma_attr(to_acpi_device_node(fwnode)); + if (!fwnode_has_op(dev_fwnode(dev), device_get_dma_attr)) + return DEV_DMA_NOT_SUPPORTED; - return attr; + return fwnode_call_int_op(dev_fwnode(dev), device_get_dma_attr); } EXPORT_SYMBOL_GPL(device_get_dma_attr); diff --git a/drivers/of/property.c b/drivers/of/property.c index 8e90071de6ed..676899566f7c 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -22,6 +22,7 @@ #define pr_fmt(fmt) "OF: " fmt #include +#include #include #include #include @@ -872,6 +873,20 @@ static bool of_fwnode_device_is_available(const struct fwnode_handle *fwnode) return of_device_is_available(to_of_node(fwnode)); } +static bool of_fwnode_device_dma_supported(const struct fwnode_handle *fwnode) +{ + return true; +} + +static enum dev_dma_attr +of_fwnode_device_get_dma_attr(const struct fwnode_handle *fwnode) +{ + if (of_dma_is_coherent(to_of_node(fwnode))) + return DEV_DMA_COHERENT; + else + return DEV_DMA_NON_COHERENT; +} + static bool of_fwnode_property_present(const struct fwnode_handle *fwnode, const char *propname) { @@ -1472,6 +1487,8 @@ const struct fwnode_operations of_fwnode_ops = { .put = of_fwnode_put, .device_is_available = of_fwnode_device_is_available, .device_get_match_data = of_fwnode_device_get_match_data, + .device_dma_supported = of_fwnode_device_dma_supported, + .device_get_dma_attr = of_fwnode_device_get_dma_attr, .property_present = of_fwnode_property_present, .property_read_int_array = of_fwnode_property_read_int_array, .property_read_string_array = of_fwnode_property_read_string_array, diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index 3a532ba66f6c..6f307f21fc65 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -113,6 +113,9 @@ struct fwnode_operations { bool (*device_is_available)(const struct fwnode_handle *fwnode); const void *(*device_get_match_data)(const struct fwnode_handle *fwnode, const struct device *dev); + bool (*device_dma_supported)(const struct fwnode_handle *fwnode); + enum dev_dma_attr + (*device_get_dma_attr)(const struct fwnode_handle *fwnode); bool (*property_present)(const struct fwnode_handle *fwnode, const char *propname); int (*property_read_int_array)(const struct fwnode_handle *fwnode,