Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 358483
b: refs/heads/master
c: 9743a3b
h: refs/heads/master
i:
  358481: e6aaad7
  358479: 8d9376f
v: v3
  • Loading branch information
Jon Hunter authored and Vinod Koul committed Jan 8, 2013
1 parent 6f3eeb9 commit 0421b35
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 25 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 5ca7c109e8eee8d97267d3308548509bb80d8bf0
refs/heads/master: 9743a3b62dee8c9d8af1319f8d1c1ff39130267d
89 changes: 67 additions & 22 deletions trunk/drivers/of/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,60 @@
#include <linux/of_dma.h>

static LIST_HEAD(of_dma_list);
static DEFINE_SPINLOCK(of_dma_lock);

/**
* of_dma_find_controller - Find a DMA controller in DT DMA helpers list
* @np: device node of DMA controller
* of_dma_get_controller - Get a DMA controller in DT DMA helpers list
* @dma_spec: pointer to DMA specifier as found in the device tree
*
* Finds a DMA controller with matching device node and number for dma cells
* in a list of registered DMA controllers. If a match is found the use_count
* variable is increased and a valid pointer to the DMA data stored is retuned.
* A NULL pointer is returned if no match is found.
*/
static struct of_dma *of_dma_find_controller(struct device_node *np)
static struct of_dma *of_dma_get_controller(struct of_phandle_args *dma_spec)
{
struct of_dma *ofdma;

spin_lock(&of_dma_lock);

if (list_empty(&of_dma_list)) {
pr_err("empty DMA controller list\n");
spin_unlock(&of_dma_lock);
return NULL;
}

list_for_each_entry_rcu(ofdma, &of_dma_list, of_dma_controllers)
if (ofdma->of_node == np)
list_for_each_entry(ofdma, &of_dma_list, of_dma_controllers)
if ((ofdma->of_node == dma_spec->np) &&
(ofdma->of_dma_nbcells == dma_spec->args_count)) {
ofdma->use_count++;
spin_unlock(&of_dma_lock);
return ofdma;
}

spin_unlock(&of_dma_lock);

pr_debug("%s: can't find DMA controller %s\n", __func__,
dma_spec->np->full_name);

return NULL;
}

/**
* of_dma_put_controller - Decrement use count for a registered DMA controller
* @of_dma: pointer to DMA controller data
*
* Decrements the use_count variable in the DMA data structure. This function
* should be called only when a valid pointer is returned from
* of_dma_get_controller() and no further accesses to data referenced by that
* pointer are needed.
*/
static void of_dma_put_controller(struct of_dma *ofdma)
{
spin_lock(&of_dma_lock);
ofdma->use_count--;
spin_unlock(&of_dma_lock);
}

/**
* of_dma_controller_register - Register a DMA controller to DT DMA helpers
* @np: device node of DMA controller
Expand Down Expand Up @@ -81,9 +114,10 @@ int of_dma_controller_register(struct device_node *np,
ofdma->of_dma_nbcells = nbcells;
ofdma->of_dma_xlate = of_dma_xlate;
ofdma->of_dma_data = data;
ofdma->use_count = 0;

/* Now queue of_dma controller structure in list */
list_add_tail_rcu(&ofdma->of_dma_controllers, &of_dma_list);
list_add_tail(&ofdma->of_dma_controllers, &of_dma_list);

return 0;
}
Expand All @@ -95,15 +129,32 @@ EXPORT_SYMBOL_GPL(of_dma_controller_register);
*
* Memory allocated by of_dma_controller_register() is freed here.
*/
void of_dma_controller_free(struct device_node *np)
int of_dma_controller_free(struct device_node *np)
{
struct of_dma *ofdma;

ofdma = of_dma_find_controller(np);
if (ofdma) {
list_del_rcu(&ofdma->of_dma_controllers);
kfree(ofdma);
spin_lock(&of_dma_lock);

if (list_empty(&of_dma_list)) {
spin_unlock(&of_dma_lock);
return -ENODEV;
}

list_for_each_entry(ofdma, &of_dma_list, of_dma_controllers)
if (ofdma->of_node == np) {
if (ofdma->use_count) {
spin_unlock(&of_dma_lock);
return -EBUSY;
}

list_del(&ofdma->of_dma_controllers);
spin_unlock(&of_dma_lock);
kfree(ofdma);
return 0;
}

spin_unlock(&of_dma_lock);
return -ENODEV;
}
EXPORT_SYMBOL_GPL(of_dma_controller_free);

Expand Down Expand Up @@ -166,21 +217,15 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
if (of_dma_match_channel(np, name, i, &dma_spec))
continue;

ofdma = of_dma_find_controller(dma_spec.np);
if (!ofdma) {
pr_debug("%s: can't find DMA controller %s\n",
np->full_name, dma_spec.np->full_name);
continue;
}
ofdma = of_dma_get_controller(&dma_spec);

if (dma_spec.args_count != ofdma->of_dma_nbcells) {
pr_debug("%s: wrong #dma-cells for %s\n", np->full_name,
dma_spec.np->full_name);
if (!ofdma)
continue;
}

chan = ofdma->of_dma_xlate(&dma_spec, ofdma);

of_dma_put_controller(ofdma);

of_node_put(dma_spec.np);

if (chan)
Expand Down
5 changes: 3 additions & 2 deletions trunk/include/linux/of_dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct of_dma {
struct dma_chan *(*of_dma_xlate)
(struct of_phandle_args *, struct of_dma *);
void *of_dma_data;
int use_count;
};

struct of_dma_filter_info {
Expand All @@ -37,7 +38,7 @@ extern int of_dma_controller_register(struct device_node *np,
struct dma_chan *(*of_dma_xlate)
(struct of_phandle_args *, struct of_dma *),
void *data);
extern void of_dma_controller_free(struct device_node *np);
extern int of_dma_controller_free(struct device_node *np);
extern struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
char *name);
extern struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,
Expand All @@ -51,7 +52,7 @@ static int of_dma_controller_register(struct device_node *np,
return -ENODEV;
}

static void of_dma_controller_free(struct device_node *np)
static int of_dma_controller_free(struct device_node *np)
{
}

Expand Down

0 comments on commit 0421b35

Please sign in to comment.