Skip to content

Commit 8c756a0

Browse files
Sakari Ailusrafaeljw
authored andcommitted
device property: Convert device_{dma_supported,get_dma_attr} to fwnode
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>
1 parent 3123109 commit 8c756a0

4 files changed

Lines changed: 38 additions & 21 deletions

File tree

drivers/acpi/property.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,17 @@ static bool acpi_fwnode_device_is_available(const struct fwnode_handle *fwnode)
12561256
return acpi_device_is_present(to_acpi_device_node(fwnode));
12571257
}
12581258

1259+
static bool acpi_fwnode_device_dma_supported(const struct fwnode_handle *fwnode)
1260+
{
1261+
return acpi_dma_supported(to_acpi_device_node(fwnode));
1262+
}
1263+
1264+
static enum dev_dma_attr
1265+
acpi_fwnode_device_get_dma_attr(const struct fwnode_handle *fwnode)
1266+
{
1267+
return acpi_get_dma_attr(to_acpi_device_node(fwnode));
1268+
}
1269+
12591270
static bool acpi_fwnode_property_present(const struct fwnode_handle *fwnode,
12601271
const char *propname)
12611272
{
@@ -1387,6 +1398,9 @@ acpi_fwnode_device_get_match_data(const struct fwnode_handle *fwnode,
13871398
const struct fwnode_operations ops = { \
13881399
.device_is_available = acpi_fwnode_device_is_available, \
13891400
.device_get_match_data = acpi_fwnode_device_get_match_data, \
1401+
.device_dma_supported = \
1402+
acpi_fwnode_device_dma_supported, \
1403+
.device_get_dma_attr = acpi_fwnode_device_get_dma_attr, \
13901404
.property_present = acpi_fwnode_property_present, \
13911405
.property_read_int_array = \
13921406
acpi_fwnode_property_read_int_array, \

drivers/base/property.c

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -823,33 +823,16 @@ EXPORT_SYMBOL_GPL(device_get_child_node_count);
823823

824824
bool device_dma_supported(struct device *dev)
825825
{
826-
const struct fwnode_handle *fwnode = dev_fwnode(dev);
827-
828-
/* For DT, this is always supported.
829-
* For ACPI, this depends on CCA, which
830-
* is determined by the acpi_dma_supported().
831-
*/
832-
if (is_of_node(fwnode))
833-
return true;
834-
835-
return acpi_dma_supported(to_acpi_device_node(fwnode));
826+
return fwnode_call_bool_op(dev_fwnode(dev), device_dma_supported);
836827
}
837828
EXPORT_SYMBOL_GPL(device_dma_supported);
838829

839830
enum dev_dma_attr device_get_dma_attr(struct device *dev)
840831
{
841-
const struct fwnode_handle *fwnode = dev_fwnode(dev);
842-
enum dev_dma_attr attr = DEV_DMA_NOT_SUPPORTED;
843-
844-
if (is_of_node(fwnode)) {
845-
if (of_dma_is_coherent(to_of_node(fwnode)))
846-
attr = DEV_DMA_COHERENT;
847-
else
848-
attr = DEV_DMA_NON_COHERENT;
849-
} else
850-
attr = acpi_get_dma_attr(to_acpi_device_node(fwnode));
832+
if (!fwnode_has_op(dev_fwnode(dev), device_get_dma_attr))
833+
return DEV_DMA_NOT_SUPPORTED;
851834

852-
return attr;
835+
return fwnode_call_int_op(dev_fwnode(dev), device_get_dma_attr);
853836
}
854837
EXPORT_SYMBOL_GPL(device_get_dma_attr);
855838

drivers/of/property.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define pr_fmt(fmt) "OF: " fmt
2323

2424
#include <linux/of.h>
25+
#include <linux/of_address.h>
2526
#include <linux/of_device.h>
2627
#include <linux/of_graph.h>
2728
#include <linux/of_irq.h>
@@ -872,6 +873,20 @@ static bool of_fwnode_device_is_available(const struct fwnode_handle *fwnode)
872873
return of_device_is_available(to_of_node(fwnode));
873874
}
874875

876+
static bool of_fwnode_device_dma_supported(const struct fwnode_handle *fwnode)
877+
{
878+
return true;
879+
}
880+
881+
static enum dev_dma_attr
882+
of_fwnode_device_get_dma_attr(const struct fwnode_handle *fwnode)
883+
{
884+
if (of_dma_is_coherent(to_of_node(fwnode)))
885+
return DEV_DMA_COHERENT;
886+
else
887+
return DEV_DMA_NON_COHERENT;
888+
}
889+
875890
static bool of_fwnode_property_present(const struct fwnode_handle *fwnode,
876891
const char *propname)
877892
{
@@ -1472,6 +1487,8 @@ const struct fwnode_operations of_fwnode_ops = {
14721487
.put = of_fwnode_put,
14731488
.device_is_available = of_fwnode_device_is_available,
14741489
.device_get_match_data = of_fwnode_device_get_match_data,
1490+
.device_dma_supported = of_fwnode_device_dma_supported,
1491+
.device_get_dma_attr = of_fwnode_device_get_dma_attr,
14751492
.property_present = of_fwnode_property_present,
14761493
.property_read_int_array = of_fwnode_property_read_int_array,
14771494
.property_read_string_array = of_fwnode_property_read_string_array,

include/linux/fwnode.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ struct fwnode_operations {
113113
bool (*device_is_available)(const struct fwnode_handle *fwnode);
114114
const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
115115
const struct device *dev);
116+
bool (*device_dma_supported)(const struct fwnode_handle *fwnode);
117+
enum dev_dma_attr
118+
(*device_get_dma_attr)(const struct fwnode_handle *fwnode);
116119
bool (*property_present)(const struct fwnode_handle *fwnode,
117120
const char *propname);
118121
int (*property_read_int_array)(const struct fwnode_handle *fwnode,

0 commit comments

Comments
 (0)