Skip to content

Commit b2396f7

Browse files
author
Vinod Koul
committed
Merge branch 'topic/of' into for-linus
Conflicts: include/linux/dmaengine.h Signed-off-by: Vinod Koul <vinod.koul@intel.com>
2 parents 42361f2 + de61608 commit b2396f7

4 files changed

Lines changed: 37 additions & 75 deletions

File tree

‎drivers/dma/dmaengine.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ EXPORT_SYMBOL_GPL(__dma_request_channel);
560560
* @dev: pointer to client device structure
561561
* @name: slave channel name
562562
*/
563-
struct dma_chan *dma_request_slave_channel(struct device *dev, char *name)
563+
struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name)
564564
{
565565
/* If device-tree is present get slave info from here */
566566
if (dev->of_node)

‎drivers/dma/of-dma.c‎

Lines changed: 30 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -13,66 +13,38 @@
1313
#include <linux/device.h>
1414
#include <linux/err.h>
1515
#include <linux/module.h>
16-
#include <linux/rculist.h>
16+
#include <linux/mutex.h>
1717
#include <linux/slab.h>
1818
#include <linux/of.h>
1919
#include <linux/of_dma.h>
2020

2121
static LIST_HEAD(of_dma_list);
22-
static DEFINE_SPINLOCK(of_dma_lock);
22+
static DEFINE_MUTEX(of_dma_lock);
2323

2424
/**
25-
* of_dma_get_controller - Get a DMA controller in DT DMA helpers list
25+
* of_dma_find_controller - Get a DMA controller in DT DMA helpers list
2626
* @dma_spec: pointer to DMA specifier as found in the device tree
2727
*
2828
* Finds a DMA controller with matching device node and number for dma cells
29-
* in a list of registered DMA controllers. If a match is found the use_count
30-
* variable is increased and a valid pointer to the DMA data stored is retuned.
31-
* A NULL pointer is returned if no match is found.
29+
* in a list of registered DMA controllers. If a match is found a valid pointer
30+
* to the DMA data stored is retuned. A NULL pointer is returned if no match is
31+
* found.
3232
*/
33-
static struct of_dma *of_dma_get_controller(struct of_phandle_args *dma_spec)
33+
static struct of_dma *of_dma_find_controller(struct of_phandle_args *dma_spec)
3434
{
3535
struct of_dma *ofdma;
3636

37-
spin_lock(&of_dma_lock);
38-
39-
if (list_empty(&of_dma_list)) {
40-
spin_unlock(&of_dma_lock);
41-
return NULL;
42-
}
43-
4437
list_for_each_entry(ofdma, &of_dma_list, of_dma_controllers)
4538
if ((ofdma->of_node == dma_spec->np) &&
46-
(ofdma->of_dma_nbcells == dma_spec->args_count)) {
47-
ofdma->use_count++;
48-
spin_unlock(&of_dma_lock);
39+
(ofdma->of_dma_nbcells == dma_spec->args_count))
4940
return ofdma;
50-
}
51-
52-
spin_unlock(&of_dma_lock);
5341

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

5745
return NULL;
5846
}
5947

60-
/**
61-
* of_dma_put_controller - Decrement use count for a registered DMA controller
62-
* @of_dma: pointer to DMA controller data
63-
*
64-
* Decrements the use_count variable in the DMA data structure. This function
65-
* should be called only when a valid pointer is returned from
66-
* of_dma_get_controller() and no further accesses to data referenced by that
67-
* pointer are needed.
68-
*/
69-
static void of_dma_put_controller(struct of_dma *ofdma)
70-
{
71-
spin_lock(&of_dma_lock);
72-
ofdma->use_count--;
73-
spin_unlock(&of_dma_lock);
74-
}
75-
7648
/**
7749
* of_dma_controller_register - Register a DMA controller to DT DMA helpers
7850
* @np: device node of DMA controller
@@ -93,6 +65,7 @@ int of_dma_controller_register(struct device_node *np,
9365
{
9466
struct of_dma *ofdma;
9567
int nbcells;
68+
const __be32 *prop;
9669

9770
if (!np || !of_dma_xlate) {
9871
pr_err("%s: not enough information provided\n", __func__);
@@ -103,8 +76,11 @@ int of_dma_controller_register(struct device_node *np,
10376
if (!ofdma)
10477
return -ENOMEM;
10578

106-
nbcells = be32_to_cpup(of_get_property(np, "#dma-cells", NULL));
107-
if (!nbcells) {
79+
prop = of_get_property(np, "#dma-cells", NULL);
80+
if (prop)
81+
nbcells = be32_to_cpup(prop);
82+
83+
if (!prop || !nbcells) {
10884
pr_err("%s: #dma-cells property is missing or invalid\n",
10985
__func__);
11086
kfree(ofdma);
@@ -115,12 +91,11 @@ int of_dma_controller_register(struct device_node *np,
11591
ofdma->of_dma_nbcells = nbcells;
11692
ofdma->of_dma_xlate = of_dma_xlate;
11793
ofdma->of_dma_data = data;
118-
ofdma->use_count = 0;
11994

12095
/* Now queue of_dma controller structure in list */
121-
spin_lock(&of_dma_lock);
96+
mutex_lock(&of_dma_lock);
12297
list_add_tail(&ofdma->of_dma_controllers, &of_dma_list);
123-
spin_unlock(&of_dma_lock);
98+
mutex_unlock(&of_dma_lock);
12499

125100
return 0;
126101
}
@@ -132,32 +107,20 @@ EXPORT_SYMBOL_GPL(of_dma_controller_register);
132107
*
133108
* Memory allocated by of_dma_controller_register() is freed here.
134109
*/
135-
int of_dma_controller_free(struct device_node *np)
110+
void of_dma_controller_free(struct device_node *np)
136111
{
137112
struct of_dma *ofdma;
138113

139-
spin_lock(&of_dma_lock);
140-
141-
if (list_empty(&of_dma_list)) {
142-
spin_unlock(&of_dma_lock);
143-
return -ENODEV;
144-
}
114+
mutex_lock(&of_dma_lock);
145115

146116
list_for_each_entry(ofdma, &of_dma_list, of_dma_controllers)
147117
if (ofdma->of_node == np) {
148-
if (ofdma->use_count) {
149-
spin_unlock(&of_dma_lock);
150-
return -EBUSY;
151-
}
152-
153118
list_del(&ofdma->of_dma_controllers);
154-
spin_unlock(&of_dma_lock);
155119
kfree(ofdma);
156-
return 0;
120+
break;
157121
}
158122

159-
spin_unlock(&of_dma_lock);
160-
return -ENODEV;
123+
mutex_unlock(&of_dma_lock);
161124
}
162125
EXPORT_SYMBOL_GPL(of_dma_controller_free);
163126

@@ -172,8 +135,8 @@ EXPORT_SYMBOL_GPL(of_dma_controller_free);
172135
* specifiers, matches the name provided. Returns 0 if the name matches and
173136
* a valid pointer to the DMA specifier is found. Otherwise returns -ENODEV.
174137
*/
175-
static int of_dma_match_channel(struct device_node *np, char *name, int index,
176-
struct of_phandle_args *dma_spec)
138+
static int of_dma_match_channel(struct device_node *np, const char *name,
139+
int index, struct of_phandle_args *dma_spec)
177140
{
178141
const char *s;
179142

@@ -198,7 +161,7 @@ static int of_dma_match_channel(struct device_node *np, char *name, int index,
198161
* Returns pointer to appropriate dma channel on success or NULL on error.
199162
*/
200163
struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
201-
char *name)
164+
const char *name)
202165
{
203166
struct of_phandle_args dma_spec;
204167
struct of_dma *ofdma;
@@ -220,14 +183,15 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
220183
if (of_dma_match_channel(np, name, i, &dma_spec))
221184
continue;
222185

223-
ofdma = of_dma_get_controller(&dma_spec);
224-
225-
if (!ofdma)
226-
continue;
186+
mutex_lock(&of_dma_lock);
187+
ofdma = of_dma_find_controller(&dma_spec);
227188

228-
chan = ofdma->of_dma_xlate(&dma_spec, ofdma);
189+
if (ofdma)
190+
chan = ofdma->of_dma_xlate(&dma_spec, ofdma);
191+
else
192+
chan = NULL;
229193

230-
of_dma_put_controller(ofdma);
194+
mutex_unlock(&of_dma_lock);
231195

232196
of_node_put(dma_spec.np);
233197

‎include/linux/dmaengine.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx);
969969
void dma_issue_pending_all(void);
970970
struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
971971
dma_filter_fn fn, void *fn_param);
972-
struct dma_chan *dma_request_slave_channel(struct device *dev, char *name);
972+
struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name);
973973
void dma_release_channel(struct dma_chan *chan);
974974
#else
975975
static inline enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx)
@@ -985,7 +985,7 @@ static inline struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
985985
return NULL;
986986
}
987987
static inline struct dma_chan *dma_request_slave_channel(struct device *dev,
988-
char *name)
988+
const char *name)
989989
{
990990
return NULL;
991991
}

‎include/linux/of_dma.h‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ struct of_dma {
2525
struct dma_chan *(*of_dma_xlate)
2626
(struct of_phandle_args *, struct of_dma *);
2727
void *of_dma_data;
28-
int use_count;
2928
};
3029

3130
struct of_dma_filter_info {
@@ -38,9 +37,9 @@ extern int of_dma_controller_register(struct device_node *np,
3837
struct dma_chan *(*of_dma_xlate)
3938
(struct of_phandle_args *, struct of_dma *),
4039
void *data);
41-
extern int of_dma_controller_free(struct device_node *np);
40+
extern void of_dma_controller_free(struct device_node *np);
4241
extern struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
43-
char *name);
42+
const char *name);
4443
extern struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,
4544
struct of_dma *ofdma);
4645
#else
@@ -52,13 +51,12 @@ static inline int of_dma_controller_register(struct device_node *np,
5251
return -ENODEV;
5352
}
5453

55-
static inline int of_dma_controller_free(struct device_node *np)
54+
static inline void of_dma_controller_free(struct device_node *np)
5655
{
57-
return -ENODEV;
5856
}
5957

6058
static inline struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
61-
char *name)
59+
const char *name)
6260
{
6361
return NULL;
6462
}

0 commit comments

Comments
 (0)