diff mbox

[V3,3/5] device property: Introduces device_dma_is_coherent()

Message ID 1431045436-8690-4-git-send-email-Suravee.Suthikulpanit@amd.com (mailing list archive)
State Deferred, archived
Headers show

Commit Message

Suravee Suthikulpanit May 8, 2015, 12:37 a.m. UTC
Currently, device drivers, which support both OF and ACPI,
need to call two separate APIs, of_dma_is_coherent() and
acpi_dma_is_coherent()) to determine device coherency attribute.

This patch simplifies this process by introducing a new device
property API, device_dma_is_coherent(), which calls the appropriate
interface based on the booting architecture.

Signed-off-by: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>
---
 drivers/base/property.c  | 12 ++++++++++++
 include/linux/property.h |  2 ++
 2 files changed, 14 insertions(+)

Comments

Santosh Shilimkar May 8, 2015, 4:12 a.m. UTC | #1
On 5/7/15 5:37 PM, Suravee Suthikulpanit wrote:
> Currently, device drivers, which support both OF and ACPI,
> need to call two separate APIs, of_dma_is_coherent() and
> acpi_dma_is_coherent()) to determine device coherency attribute.
>
> This patch simplifies this process by introducing a new device
> property API, device_dma_is_coherent(), which calls the appropriate
> interface based on the booting architecture.
>
> Signed-off-by: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>
> ---
>   drivers/base/property.c  | 12 ++++++++++++
>   include/linux/property.h |  2 ++
>   2 files changed, 14 insertions(+)
>
> diff --git a/drivers/base/property.c b/drivers/base/property.c
> index 1d0b116..8123c6e 100644
> --- a/drivers/base/property.c
> +++ b/drivers/base/property.c
> @@ -14,6 +14,7 @@
>   #include <linux/export.h>
>   #include <linux/kernel.h>
>   #include <linux/of.h>
> +#include <linux/of_address.h>
>   #include <linux/property.h>
>
>   /**
> @@ -519,3 +520,14 @@ unsigned int device_get_child_node_count(struct device *dev)
>   	return count;
>   }
>   EXPORT_SYMBOL_GPL(device_get_child_node_count);
> +
> +bool device_dma_is_coherent(struct device *dev)
> +{
> +	if (IS_ENABLED(CONFIG_OF) && dev->of_node)

Do you really need that IS_ENABLED(CONFIG_OF) ?
In other words, dev->of_node should be null for !CONFIG_OF

Regards,
Santosh
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Santosh Shilimkar May 8, 2015, 8:27 p.m. UTC | #2
On 5/8/2015 1:49 PM, Rafael J. Wysocki wrote:
> On Thursday, May 07, 2015 09:12:00 PM santosh.shilimkar@oracle.com wrote:
>> On 5/7/15 5:37 PM, Suravee Suthikulpanit wrote:
>>> Currently, device drivers, which support both OF and ACPI,
>>> need to call two separate APIs, of_dma_is_coherent() and
>>> acpi_dma_is_coherent()) to determine device coherency attribute.
>>>
>>> This patch simplifies this process by introducing a new device
>>> property API, device_dma_is_coherent(), which calls the appropriate
>>> interface based on the booting architecture.
>>>
>>> Signed-off-by: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>
>>> ---
>>>    drivers/base/property.c  | 12 ++++++++++++
>>>    include/linux/property.h |  2 ++
>>>    2 files changed, 14 insertions(+)
>>>
>>> diff --git a/drivers/base/property.c b/drivers/base/property.c
>>> index 1d0b116..8123c6e 100644
>>> --- a/drivers/base/property.c
>>> +++ b/drivers/base/property.c
>>> @@ -14,6 +14,7 @@
>>>    #include <linux/export.h>
>>>    #include <linux/kernel.h>
>>>    #include <linux/of.h>
>>> +#include <linux/of_address.h>
>>>    #include <linux/property.h>
>>>
>>>    /**
>>> @@ -519,3 +520,14 @@ unsigned int device_get_child_node_count(struct device *dev)
>>>    	return count;
>>>    }
>>>    EXPORT_SYMBOL_GPL(device_get_child_node_count);
>>> +
>>> +bool device_dma_is_coherent(struct device *dev)
>>> +{
>>> +	if (IS_ENABLED(CONFIG_OF) && dev->of_node)
>>
>> Do you really need that IS_ENABLED(CONFIG_OF) ?
>> In other words, dev->of_node should be null for !CONFIG_OF
>
> Yes, but IS_ENABLED(CONFIG_OF) causes the check to be optimized away by the
> compiler if CONFIG_OF is not enabled.
>
Sure but my point was why you need it when just 'dev->of_node' check
is enough. May be I missed something.

Regards,
Santosh
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Santosh Shilimkar May 8, 2015, 8:36 p.m. UTC | #3
On 5/8/2015 1:58 PM, Rafael J. Wysocki wrote:
> On Friday, May 08, 2015 01:27:00 PM santosh shilimkar wrote:
>> On 5/8/2015 1:49 PM, Rafael J. Wysocki wrote:
>>> On Thursday, May 07, 2015 09:12:00 PM santosh.shilimkar@oracle.com wrote:
>>>> On 5/7/15 5:37 PM, Suravee Suthikulpanit wrote:
>>>>> Currently, device drivers, which support both OF and ACPI,
>>>>> need to call two separate APIs, of_dma_is_coherent() and
>>>>> acpi_dma_is_coherent()) to determine device coherency attribute.
>>>>>
>>>>> This patch simplifies this process by introducing a new device
>>>>> property API, device_dma_is_coherent(), which calls the appropriate
>>>>> interface based on the booting architecture.
>>>>>
>>>>> Signed-off-by: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>
>>>>> ---
>>>>>     drivers/base/property.c  | 12 ++++++++++++
>>>>>     include/linux/property.h |  2 ++
>>>>>     2 files changed, 14 insertions(+)
>>>>>
>>>>> diff --git a/drivers/base/property.c b/drivers/base/property.c
>>>>> index 1d0b116..8123c6e 100644
>>>>> --- a/drivers/base/property.c
>>>>> +++ b/drivers/base/property.c
>>>>> @@ -14,6 +14,7 @@
>>>>>     #include <linux/export.h>
>>>>>     #include <linux/kernel.h>
>>>>>     #include <linux/of.h>
>>>>> +#include <linux/of_address.h>
>>>>>     #include <linux/property.h>
>>>>>
>>>>>     /**
>>>>> @@ -519,3 +520,14 @@ unsigned int device_get_child_node_count(struct device *dev)
>>>>>     	return count;
>>>>>     }
>>>>>     EXPORT_SYMBOL_GPL(device_get_child_node_count);
>>>>> +
>>>>> +bool device_dma_is_coherent(struct device *dev)
>>>>> +{
>>>>> +	if (IS_ENABLED(CONFIG_OF) && dev->of_node)
>>>>
>>>> Do you really need that IS_ENABLED(CONFIG_OF) ?
>>>> In other words, dev->of_node should be null for !CONFIG_OF
>>>
>>> Yes, but IS_ENABLED(CONFIG_OF) causes the check to be optimized away by the
>>> compiler if CONFIG_OF is not enabled.
>>>
>> Sure but my point was why you need it when just 'dev->of_node' check
>> is enough. May be I missed something.
>
> dev->of_node is present when CONFIG_OF is not enabled too.  Without the
> IS_ENABLED(CONFIG_OF) this becomes a pointless pointer check that will
> always evaluate to 'false' on systems without CONFIG_OF, AFAICS.
>
Got it now. Thanks for expanding it.

Regards,
Santosh
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Rafael J. Wysocki May 8, 2015, 8:49 p.m. UTC | #4
On Thursday, May 07, 2015 09:12:00 PM santosh.shilimkar@oracle.com wrote:
> On 5/7/15 5:37 PM, Suravee Suthikulpanit wrote:
> > Currently, device drivers, which support both OF and ACPI,
> > need to call two separate APIs, of_dma_is_coherent() and
> > acpi_dma_is_coherent()) to determine device coherency attribute.
> >
> > This patch simplifies this process by introducing a new device
> > property API, device_dma_is_coherent(), which calls the appropriate
> > interface based on the booting architecture.
> >
> > Signed-off-by: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>
> > ---
> >   drivers/base/property.c  | 12 ++++++++++++
> >   include/linux/property.h |  2 ++
> >   2 files changed, 14 insertions(+)
> >
> > diff --git a/drivers/base/property.c b/drivers/base/property.c
> > index 1d0b116..8123c6e 100644
> > --- a/drivers/base/property.c
> > +++ b/drivers/base/property.c
> > @@ -14,6 +14,7 @@
> >   #include <linux/export.h>
> >   #include <linux/kernel.h>
> >   #include <linux/of.h>
> > +#include <linux/of_address.h>
> >   #include <linux/property.h>
> >
> >   /**
> > @@ -519,3 +520,14 @@ unsigned int device_get_child_node_count(struct device *dev)
> >   	return count;
> >   }
> >   EXPORT_SYMBOL_GPL(device_get_child_node_count);
> > +
> > +bool device_dma_is_coherent(struct device *dev)
> > +{
> > +	if (IS_ENABLED(CONFIG_OF) && dev->of_node)
> 
> Do you really need that IS_ENABLED(CONFIG_OF) ?
> In other words, dev->of_node should be null for !CONFIG_OF

Yes, but IS_ENABLED(CONFIG_OF) causes the check to be optimized away by the
compiler if CONFIG_OF is not enabled.
Rafael J. Wysocki May 8, 2015, 8:58 p.m. UTC | #5
On Friday, May 08, 2015 01:27:00 PM santosh shilimkar wrote:
> On 5/8/2015 1:49 PM, Rafael J. Wysocki wrote:
> > On Thursday, May 07, 2015 09:12:00 PM santosh.shilimkar@oracle.com wrote:
> >> On 5/7/15 5:37 PM, Suravee Suthikulpanit wrote:
> >>> Currently, device drivers, which support both OF and ACPI,
> >>> need to call two separate APIs, of_dma_is_coherent() and
> >>> acpi_dma_is_coherent()) to determine device coherency attribute.
> >>>
> >>> This patch simplifies this process by introducing a new device
> >>> property API, device_dma_is_coherent(), which calls the appropriate
> >>> interface based on the booting architecture.
> >>>
> >>> Signed-off-by: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>
> >>> ---
> >>>    drivers/base/property.c  | 12 ++++++++++++
> >>>    include/linux/property.h |  2 ++
> >>>    2 files changed, 14 insertions(+)
> >>>
> >>> diff --git a/drivers/base/property.c b/drivers/base/property.c
> >>> index 1d0b116..8123c6e 100644
> >>> --- a/drivers/base/property.c
> >>> +++ b/drivers/base/property.c
> >>> @@ -14,6 +14,7 @@
> >>>    #include <linux/export.h>
> >>>    #include <linux/kernel.h>
> >>>    #include <linux/of.h>
> >>> +#include <linux/of_address.h>
> >>>    #include <linux/property.h>
> >>>
> >>>    /**
> >>> @@ -519,3 +520,14 @@ unsigned int device_get_child_node_count(struct device *dev)
> >>>    	return count;
> >>>    }
> >>>    EXPORT_SYMBOL_GPL(device_get_child_node_count);
> >>> +
> >>> +bool device_dma_is_coherent(struct device *dev)
> >>> +{
> >>> +	if (IS_ENABLED(CONFIG_OF) && dev->of_node)
> >>
> >> Do you really need that IS_ENABLED(CONFIG_OF) ?
> >> In other words, dev->of_node should be null for !CONFIG_OF
> >
> > Yes, but IS_ENABLED(CONFIG_OF) causes the check to be optimized away by the
> > compiler if CONFIG_OF is not enabled.
> >
> Sure but my point was why you need it when just 'dev->of_node' check
> is enough. May be I missed something.

dev->of_node is present when CONFIG_OF is not enabled too.  Without the
IS_ENABLED(CONFIG_OF) this becomes a pointless pointer check that will
always evaluate to 'false' on systems without CONFIG_OF, AFAICS.
diff mbox

Patch

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 1d0b116..8123c6e 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -14,6 +14,7 @@ 
 #include <linux/export.h>
 #include <linux/kernel.h>
 #include <linux/of.h>
+#include <linux/of_address.h>
 #include <linux/property.h>
 
 /**
@@ -519,3 +520,14 @@  unsigned int device_get_child_node_count(struct device *dev)
 	return count;
 }
 EXPORT_SYMBOL_GPL(device_get_child_node_count);
+
+bool device_dma_is_coherent(struct device *dev)
+{
+	if (IS_ENABLED(CONFIG_OF) && dev->of_node)
+		return of_dma_is_coherent(dev->of_node);
+	else if (has_acpi_companion(dev))
+		return acpi_dma_is_coherent(acpi_node(dev->fwnode));
+
+	return false;
+}
+EXPORT_SYMBOL_GPL(device_dma_is_coherent);
diff --git a/include/linux/property.h b/include/linux/property.h
index de8bdf4..76ebde9 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -164,4 +164,6 @@  struct property_set {
 
 void device_add_property_set(struct device *dev, struct property_set *pset);
 
+bool device_dma_is_coherent(struct device *dev);
+
 #endif /* _LINUX_PROPERTY_H_ */