device property: Convert device_{dma_supported,get_dma_attr} to fwnode
authorSakari Ailus <sakari.ailus@linux.intel.com>
Thu, 31 Mar 2022 12:54:47 +0000 (15:54 +0300)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 5 Apr 2022 13:30:47 +0000 (15:30 +0200)
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.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Rob Herring <robh@kernel.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/property.c
drivers/base/property.c
drivers/of/property.c
include/linux/fwnode.h

index 12bbfe833609531c7eb16d5423f3e908f7eb3c10..24983c379aba41f4c379de050dece5b71b06f170 100644 (file)
@@ -1256,6 +1256,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)
 {
@@ -1387,6 +1398,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,            \
index c0e94cce9c29411669b7e6dd2e55b2e4ac6de708..09686e2e903e059d7f4e7cc7d25a068a6a88467b 100644 (file)
@@ -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);
 
index 8e90071de6ed75b51b2c5d7c93e3fdc1368465b2..676899566f7c164e927e849bcd4e0bfb0aab07dd 100644 (file)
@@ -22,6 +22,7 @@
 #define pr_fmt(fmt)    "OF: " fmt
 
 #include <linux/of.h>
+#include <linux/of_address.h>
 #include <linux/of_device.h>
 #include <linux/of_graph.h>
 #include <linux/of_irq.h>
@@ -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,
index 3a532ba66f6c291a7415ab4cca52a469fcbc6405..6f307f21fc659044b7f524fed9723c01dca4fb61 100644 (file)
@@ -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,