linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] DMA: add help function to check whether dma controller registered
@ 2013-08-02  6:04 Richard Zhao
  2013-08-02 19:59 ` Stephen Warren
  2013-08-22  6:43 ` [PATCH v2] " Richard Zhao
  0 siblings, 2 replies; 7+ messages in thread
From: Richard Zhao @ 2013-08-02  6:04 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel
  Cc: vinod.koul, djbw, grant.likely, rob.herring, swarren, Richard Zhao

DMA client device driver usually needs to know at probe time whether
dma controller has been registered to deffer probe. So add a help
function of_dma_check_controller.

DMA request channel functions can also used to check it, but they
are usually called at open() time.

Signed-off-by: Richard Zhao <rizhao@nvidia.com>
---
 drivers/dma/of-dma.c   | 38 ++++++++++++++++++++++++++++++++++++++
 include/linux/of_dma.h |  6 ++++++
 2 files changed, 44 insertions(+)

diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
index e1c4d3b..b6828c1 100644
--- a/drivers/dma/of-dma.c
+++ b/drivers/dma/of-dma.c
@@ -188,6 +188,44 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
 }
 
 /**
+ * of_dma_check_controller - Check whether dma controller registered
+ * @dev:	pointer to client device structure
+ * @name:	slave channel name
+ */
+int of_dma_check_controller(struct device *dev, const char *name)
+{
+	struct device_node *np = dev->of_node;
+	struct of_phandle_args dma_spec;
+	struct of_dma *ofdma = NULL;
+	int count, i;
+
+	if (!np || !name)
+		return -EINVAL;
+
+	count = of_property_count_strings(np, "dma-names");
+	if (count < 0) {
+		dev_err(dev, "dma-names property missing or empty\n");
+		return -EINVAL;
+	}
+
+	for (i = 0; i < count; i++) {
+		if (of_dma_match_channel(np, name, i, &dma_spec))
+			continue;
+
+		mutex_lock(&of_dma_lock);
+		ofdma = of_dma_find_controller(&dma_spec);
+		mutex_unlock(&of_dma_lock);
+		of_node_put(dma_spec.np);
+	}
+
+	if (ofdma)
+		return 0;
+	else
+		return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(of_dma_check_controller);
+
+/**
  * of_dma_simple_xlate - Simple DMA engine translation function
  * @dma_spec:	pointer to DMA specifier as found in the device tree
  * @of_dma:	pointer to DMA controller data
diff --git a/include/linux/of_dma.h b/include/linux/of_dma.h
index ae36298..bc7195f 100644
--- a/include/linux/of_dma.h
+++ b/include/linux/of_dma.h
@@ -39,6 +39,7 @@ extern int of_dma_controller_register(struct device_node *np,
 extern void of_dma_controller_free(struct device_node *np);
 extern struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
 						     const char *name);
+extern int of_dma_check_controller(struct device *dev, const char *name);
 extern struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,
 		struct of_dma *ofdma);
 #else
@@ -60,6 +61,11 @@ static inline struct dma_chan *of_dma_request_slave_channel(struct device_node *
 	return NULL;
 }
 
+static inline int of_dma_check_controller(struct device *dev, const char *name)
+{
+	return 0;
+}
+
 static inline struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,
 		struct of_dma *ofdma)
 {
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] DMA: add help function to check whether dma controller registered
  2013-08-02  6:04 [PATCH] DMA: add help function to check whether dma controller registered Richard Zhao
@ 2013-08-02 19:59 ` Stephen Warren
  2013-08-05  5:56   ` Richard Zhao
  2013-08-22  6:43 ` [PATCH v2] " Richard Zhao
  1 sibling, 1 reply; 7+ messages in thread
From: Stephen Warren @ 2013-08-02 19:59 UTC (permalink / raw)
  To: Richard Zhao
  Cc: linux-kernel, linux-arm-kernel, vinod.koul, djbw, grant.likely,
	rob.herring

On 08/02/2013 12:04 AM, Richard Zhao wrote:
> DMA client device driver usually needs to know at probe time whether
> dma controller has been registered to deffer probe. So add a help
> function of_dma_check_controller.
> 
> DMA request channel functions can also used to check it, but they
> are usually called at open() time.

> diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
> index e1c4d3b..b6828c1 100644

> +int of_dma_check_controller(struct device *dev, const char *name)


> +	for (i = 0; i < count; i++) {
> +		if (of_dma_match_channel(np, name, i, &dma_spec))
> +			continue;
> +
> +		mutex_lock(&of_dma_lock);
> +		ofdma = of_dma_find_controller(&dma_spec);
> +		mutex_unlock(&of_dma_lock);
> +		of_node_put(dma_spec.np);

Do we need to add the following here:

if (ofdma)
	break

To ensure that as soon as a successful match is found, the loop exits?
Otherwise, if there are multiple providers for that name, and the first
N are registered but the last isn't, this function will still return
failure.

> +	if (ofdma)
> +		return 0;
> +	else
> +		return -ENODEV;

That probably should be -EPROBE_DEFER?

Although, what about differentiating between "entry not found by
of_dma_match_channel" and "controller not yet probed"?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] DMA: add help function to check whether dma controller registered
  2013-08-02 19:59 ` Stephen Warren
@ 2013-08-05  5:56   ` Richard Zhao
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Zhao @ 2013-08-05  5:56 UTC (permalink / raw)
  To: Stephen Warren
  Cc: linux-kernel, linux-arm-kernel, vinod.koul, djbw, grant.likely,
	rob.herring

On Sat, Aug 03, 2013 at 03:59:59AM +0800, Stephen Warren wrote:
> On 08/02/2013 12:04 AM, Richard Zhao wrote:
> > DMA client device driver usually needs to know at probe time whether
> > dma controller has been registered to deffer probe. So add a help
> > function of_dma_check_controller.
> > 
> > DMA request channel functions can also used to check it, but they
> > are usually called at open() time.
> 
> > diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
> > index e1c4d3b..b6828c1 100644
> 
> > +int of_dma_check_controller(struct device *dev, const char *name)
> 
> 
> > +	for (i = 0; i < count; i++) {
> > +		if (of_dma_match_channel(np, name, i, &dma_spec))
> > +			continue;
> > +
> > +		mutex_lock(&of_dma_lock);
> > +		ofdma = of_dma_find_controller(&dma_spec);
> > +		mutex_unlock(&of_dma_lock);
> > +		of_node_put(dma_spec.np);
> 
> Do we need to add the following here:
> 
> if (ofdma)
> 	break
> 
> To ensure that as soon as a successful match is found, the loop exits?
> Otherwise, if there are multiple providers for that name, and the first
> N are registered but the last isn't, this function will still return
> failure.
Right. Thanks.
> 
> > +	if (ofdma)
> > +		return 0;
> > +	else
> > +		return -ENODEV;
> 
> That probably should be -EPROBE_DEFER?
> 
> Although, what about differentiating between "entry not found by
> of_dma_match_channel" and "controller not yet probed"?
I thought it might be called in non-probe functions.  If no people
against it, I'll change it to EPROBE_DEFER.

Thanks
Richard

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] DMA: add help function to check whether dma controller registered
  2013-08-02  6:04 [PATCH] DMA: add help function to check whether dma controller registered Richard Zhao
  2013-08-02 19:59 ` Stephen Warren
@ 2013-08-22  6:43 ` Richard Zhao
  2013-08-22 20:36   ` Stephen Warren
  1 sibling, 1 reply; 7+ messages in thread
From: Richard Zhao @ 2013-08-22  6:43 UTC (permalink / raw)
  To: linux-kernel, linux-omap, linux-arm-kernel
  Cc: vinod.koul, djbw, swarren, grant.likely, rob.herring, devicetree,
	Richard Zhao

DMA client device driver usually needs to know at probe time whether
dma controller has been registered to deffer probe. So add a help
function of_dma_check_controller.

DMA request channel functions can also used to check it, but they
are usually called at open() time.

Signed-off-by: Richard Zhao <rizhao@nvidia.com>
---
 drivers/dma/of-dma.c   | 39 +++++++++++++++++++++++++++++++++++++++
 include/linux/of_dma.h |  6 ++++++
 2 files changed, 45 insertions(+)

diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
index 8cd5f3f..0063ddf 100644
--- a/drivers/dma/of-dma.c
+++ b/drivers/dma/of-dma.c
@@ -189,6 +189,45 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
 }
 
 /**
+ * of_dma_check_controller - Check whether dma controller registered
+ * @dev:	pointer to client device structure
+ * @name:	slave channel name
+ */
+int of_dma_check_controller(struct device *dev, const char *name)
+{
+	struct device_node *np = dev->of_node;
+	struct of_phandle_args dma_spec;
+	struct of_dma *ofdma = NULL;
+	int count, i, ret = 0;
+
+	if (!np || !name)
+		return -EINVAL;
+
+	count = of_property_count_strings(np, "dma-names");
+	if (count < 0) {
+		dev_err(dev, "dma-names property missing or empty\n");
+		return -EINVAL;
+	}
+
+	for (i = 0; i < count; i++) {
+		ret = of_dma_match_channel(np, name, i, &dma_spec);
+		if (ret)
+			continue;
+
+		mutex_lock(&of_dma_lock);
+		ofdma = of_dma_find_controller(&dma_spec);
+		mutex_unlock(&of_dma_lock);
+		of_node_put(dma_spec.np);
+		if (!ofdma)
+			ret = -EPROBE_DEFER;
+		break;
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(of_dma_check_controller);
+
+/**
  * of_dma_simple_xlate - Simple DMA engine translation function
  * @dma_spec:	pointer to DMA specifier as found in the device tree
  * @of_dma:	pointer to DMA controller data
diff --git a/include/linux/of_dma.h b/include/linux/of_dma.h
index ae36298..bc7195f 100644
--- a/include/linux/of_dma.h
+++ b/include/linux/of_dma.h
@@ -39,6 +39,7 @@ extern int of_dma_controller_register(struct device_node *np,
 extern void of_dma_controller_free(struct device_node *np);
 extern struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
 						     const char *name);
+extern int of_dma_check_controller(struct device *dev, const char *name);
 extern struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,
 		struct of_dma *ofdma);
 #else
@@ -60,6 +61,11 @@ static inline struct dma_chan *of_dma_request_slave_channel(struct device_node *
 	return NULL;
 }
 
+static inline int of_dma_check_controller(struct device *dev, const char *name)
+{
+	return 0;
+}
+
 static inline struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,
 		struct of_dma *ofdma)
 {
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] DMA: add help function to check whether dma controller registered
  2013-08-22  6:43 ` [PATCH v2] " Richard Zhao
@ 2013-08-22 20:36   ` Stephen Warren
  2013-08-23  1:17     ` Richard Zhao
  0 siblings, 1 reply; 7+ messages in thread
From: Stephen Warren @ 2013-08-22 20:36 UTC (permalink / raw)
  To: Richard Zhao
  Cc: linux-kernel, linux-omap, linux-arm-kernel, vinod.koul, djbw,
	grant.likely, rob.herring, devicetree

On 08/22/2013 12:43 AM, Richard Zhao wrote:
> DMA client device driver usually needs to know at probe time whether
> dma controller has been registered to deffer probe. So add a help
> function of_dma_check_controller.
> 
> DMA request channel functions can also used to check it, but they
> are usually called at open() time.

This new function is almost identical to the existing
of_dma_request_slave_channel(). Surely the code should be shared?

But that said, I don't see any need for a new function; why can't
drivers simply call of_dma_request_slave_channel() at probe time; from
what I can see, that function doesn't actually request the channel, but
rather simply looks it up, just like this one. The only difference is
that of_dma_xlate() is also called, but that's just doing some data
transformation, not actually recording channel ownership.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] DMA: add help function to check whether dma controller registered
  2013-08-22 20:36   ` Stephen Warren
@ 2013-08-23  1:17     ` Richard Zhao
  2013-08-23 15:56       ` Stephen Warren
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Zhao @ 2013-08-23  1:17 UTC (permalink / raw)
  To: Stephen Warren
  Cc: linux-kernel, linux-omap, linux-arm-kernel, vinod.koul, djbw,
	grant.likely, rob.herring, devicetree

On Fri, Aug 23, 2013 at 04:36:53AM +0800, Stephen Warren wrote:
> On 08/22/2013 12:43 AM, Richard Zhao wrote:
> > DMA client device driver usually needs to know at probe time whether
> > dma controller has been registered to deffer probe. So add a help
> > function of_dma_check_controller.
> > 
> > DMA request channel functions can also used to check it, but they
> > are usually called at open() time.
> 
> This new function is almost identical to the existing
> of_dma_request_slave_channel(). Surely the code should be shared?
ofdma->of_dma_xlate(&dma_spec, ofdma);
The above is called holding of_dma_lock. If I want to abstract the
common lines, there' two options.

Option 1:
static struct of_dma* of_dma_check_controller_locked(np, name)
{
	parameter check
	get dma-names count and check return value
	for loop to get of_dma
	return PTR_ERR(err) or of_dma
}

struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
					      const char *name)
{
	chan = null;
	mutex_lock(&of_dma_lock);
	of_dma = of_dma_check_controller_locked(np, name)
	if(!IS_ERR(of_dma))
		chan = ofdma->of_dma_xlate(&dma_spec, ofdma);
	mutex_unlock(&of_dma_lock);
	return chan;
}

int of_dma_check_controller(struct device *dev, const char *name)
{
	mutex_lock(&of_dma_lock);
	ofdma = of_dma_check_controller_locked(dev->of_node, name);
	mutex_unlock(&of_dma_lock);
	if (IS_ERR(ofdma))
		return ERR_PTR(ofdma);
	else
		return 0;
}

Option 2:
static struct of_dma* of_dma_check_controller_getlock(np, name)
{
	parameter check
	get dma-names count and check return value
	for loop to get of_dma, get lock at old place
	if failed, unlock.
	return PTR_ERR(err) or of_dma
}

struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
					      const char *name)
{
}	of_dma = of_dma_check_controller_getlock(np, name)
	if(!IS_ERR(of_dma)) {
		chan = ofdma->of_dma_xlate(&dma_spec, ofdma);
		unlock;
	}
	return chan;
}

int of_dma_check_controller(struct device *dev, const char *name)
	ofdma = of_dma_check_controller_locked(dev->of_node, name);

	if (IS_ERR(ofdma)) {
		return ERR_PTR(ofdma);
	} else {
		unlock;
		return 0;
	}
}

> But that said, I don't see any need for a new function; why can't
> drivers simply call of_dma_request_slave_channel() at probe time;
It'll mislead user. channel supposed to be request at open time.

> from
> what I can see, that function doesn't actually request the channel, but
> rather simply looks it up, just like this one. The only difference is
> that of_dma_xlate() is also called, but that's just doing some data
> transformation, not actually recording channel ownership.
xlate function request the channel if things go well.

Thanks
Richard

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] DMA: add help function to check whether dma controller registered
  2013-08-23  1:17     ` Richard Zhao
@ 2013-08-23 15:56       ` Stephen Warren
  0 siblings, 0 replies; 7+ messages in thread
From: Stephen Warren @ 2013-08-23 15:56 UTC (permalink / raw)
  To: Richard Zhao
  Cc: linux-kernel, linux-omap, linux-arm-kernel, vinod.koul, djbw,
	grant.likely, rob.herring, devicetree

On 08/22/2013 07:17 PM, Richard Zhao wrote:
> On Fri, Aug 23, 2013 at 04:36:53AM +0800, Stephen Warren wrote:
>> On 08/22/2013 12:43 AM, Richard Zhao wrote:
>>> DMA client device driver usually needs to know at probe time whether
>>> dma controller has been registered to deffer probe. So add a help
>>> function of_dma_check_controller.
>>>
>>> DMA request channel functions can also used to check it, but they
>>> are usually called at open() time.
>>
>> This new function is almost identical to the existing
>> of_dma_request_slave_channel(). Surely the code should be shared?
>
> ofdma->of_dma_xlate(&dma_spec, ofdma);
> The above is called holding of_dma_lock. If I want to abstract the
> common lines, there' two options.

What is the problem with acquiring the lock? If request_slave_channel()
needs to take the lock, then there must be a reason which presumably
applies to the other path too.

...
>> But that said, I don't see any need for a new function; why can't
>> drivers simply call of_dma_request_slave_channel() at probe time;
>
> It'll mislead user. channel supposed to be request at open time.

I don't agree.

>> from
>> what I can see, that function doesn't actually request the channel, but
>> rather simply looks it up, just like this one. The only difference is
>> that of_dma_xlate() is also called, but that's just doing some data
>> transformation, not actually recording channel ownership.
>
> xlate function request the channel if things go well.

Oh. xlate should not do that; that's a design flaw. xlate should do
nothing more than translate the DT content to an internal channel ID.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-08-23 15:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-02  6:04 [PATCH] DMA: add help function to check whether dma controller registered Richard Zhao
2013-08-02 19:59 ` Stephen Warren
2013-08-05  5:56   ` Richard Zhao
2013-08-22  6:43 ` [PATCH v2] " Richard Zhao
2013-08-22 20:36   ` Stephen Warren
2013-08-23  1:17     ` Richard Zhao
2013-08-23 15:56       ` Stephen Warren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).