Skip to content

Commit 209b84a

Browse files
committed
dmaengine: replace dma_async_client_register with dmaengine_get
Now that clients no longer need to be notified of channel arrival dma_async_client_register can simply increment the dmaengine_ref_count. Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 74465b4 commit 209b84a

4 files changed

Lines changed: 11 additions & 133 deletions

File tree

‎crypto/async_tx/async_tx.c‎

Lines changed: 2 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -28,120 +28,9 @@
2828
#include <linux/async_tx.h>
2929

3030
#ifdef CONFIG_DMA_ENGINE
31-
static enum dma_state_client
32-
dma_channel_add_remove(struct dma_client *client,
33-
struct dma_chan *chan, enum dma_state state);
34-
35-
static struct dma_client async_tx_dma = {
36-
.event_callback = dma_channel_add_remove,
37-
/* .cap_mask == 0 defaults to all channels */
38-
};
39-
40-
/**
41-
* async_tx_lock - protect modification of async_tx_master_list and serialize
42-
* rebalance operations
43-
*/
44-
static DEFINE_SPINLOCK(async_tx_lock);
45-
46-
static LIST_HEAD(async_tx_master_list);
47-
48-
static void
49-
free_dma_chan_ref(struct rcu_head *rcu)
50-
{
51-
struct dma_chan_ref *ref;
52-
ref = container_of(rcu, struct dma_chan_ref, rcu);
53-
kfree(ref);
54-
}
55-
56-
static void
57-
init_dma_chan_ref(struct dma_chan_ref *ref, struct dma_chan *chan)
58-
{
59-
INIT_LIST_HEAD(&ref->node);
60-
INIT_RCU_HEAD(&ref->rcu);
61-
ref->chan = chan;
62-
atomic_set(&ref->count, 0);
63-
}
64-
65-
static enum dma_state_client
66-
dma_channel_add_remove(struct dma_client *client,
67-
struct dma_chan *chan, enum dma_state state)
68-
{
69-
unsigned long found, flags;
70-
struct dma_chan_ref *master_ref, *ref;
71-
enum dma_state_client ack = DMA_DUP; /* default: take no action */
72-
73-
switch (state) {
74-
case DMA_RESOURCE_AVAILABLE:
75-
found = 0;
76-
rcu_read_lock();
77-
list_for_each_entry_rcu(ref, &async_tx_master_list, node)
78-
if (ref->chan == chan) {
79-
found = 1;
80-
break;
81-
}
82-
rcu_read_unlock();
83-
84-
pr_debug("async_tx: dma resource available [%s]\n",
85-
found ? "old" : "new");
86-
87-
if (!found)
88-
ack = DMA_ACK;
89-
else
90-
break;
91-
92-
/* add the channel to the generic management list */
93-
master_ref = kmalloc(sizeof(*master_ref), GFP_KERNEL);
94-
if (master_ref) {
95-
init_dma_chan_ref(master_ref, chan);
96-
spin_lock_irqsave(&async_tx_lock, flags);
97-
list_add_tail_rcu(&master_ref->node,
98-
&async_tx_master_list);
99-
spin_unlock_irqrestore(&async_tx_lock,
100-
flags);
101-
} else {
102-
printk(KERN_WARNING "async_tx: unable to create"
103-
" new master entry in response to"
104-
" a DMA_RESOURCE_ADDED event"
105-
" (-ENOMEM)\n");
106-
return 0;
107-
}
108-
break;
109-
case DMA_RESOURCE_REMOVED:
110-
found = 0;
111-
spin_lock_irqsave(&async_tx_lock, flags);
112-
list_for_each_entry(ref, &async_tx_master_list, node)
113-
if (ref->chan == chan) {
114-
list_del_rcu(&ref->node);
115-
call_rcu(&ref->rcu, free_dma_chan_ref);
116-
found = 1;
117-
break;
118-
}
119-
spin_unlock_irqrestore(&async_tx_lock, flags);
120-
121-
pr_debug("async_tx: dma resource removed [%s]\n",
122-
found ? "ours" : "not ours");
123-
124-
if (found)
125-
ack = DMA_ACK;
126-
else
127-
break;
128-
break;
129-
case DMA_RESOURCE_SUSPEND:
130-
case DMA_RESOURCE_RESUME:
131-
printk(KERN_WARNING "async_tx: does not support dma channel"
132-
" suspend/resume\n");
133-
break;
134-
default:
135-
BUG();
136-
}
137-
138-
return ack;
139-
}
140-
14131
static int __init async_tx_init(void)
14232
{
143-
dma_async_client_register(&async_tx_dma);
144-
dma_async_client_chan_request(&async_tx_dma);
33+
dmaengine_get();
14534

14635
printk(KERN_INFO "async_tx: api initialized (async)\n");
14736

@@ -150,7 +39,7 @@ static int __init async_tx_init(void)
15039

15140
static void __exit async_tx_exit(void)
15241
{
153-
dma_async_client_unregister(&async_tx_dma);
42+
dmaengine_put();
15443
}
15544

15645
/**

‎drivers/dma/dmaengine.c‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,9 @@ static void dma_clients_notify_available(void)
600600
}
601601

602602
/**
603-
* dma_async_client_register - register a &dma_client
604-
* @client: ptr to a client structure with valid 'event_callback' and 'cap_mask'
603+
* dmaengine_get - register interest in dma_channels
605604
*/
606-
void dma_async_client_register(struct dma_client *client)
605+
void dmaengine_get(void)
607606
{
608607
struct dma_device *device, *_d;
609608
struct dma_chan *chan;
@@ -634,25 +633,18 @@ void dma_async_client_register(struct dma_client *client)
634633
*/
635634
if (dmaengine_ref_count == 1)
636635
dma_channel_rebalance();
637-
list_add_tail(&client->global_node, &dma_client_list);
638636
mutex_unlock(&dma_list_mutex);
639637
}
640-
EXPORT_SYMBOL(dma_async_client_register);
638+
EXPORT_SYMBOL(dmaengine_get);
641639

642640
/**
643-
* dma_async_client_unregister - unregister a client and free the &dma_client
644-
* @client: &dma_client to free
645-
*
646-
* Force frees any allocated DMA channels, frees the &dma_client memory
641+
* dmaengine_put - let dma drivers be removed when ref_count == 0
647642
*/
648-
void dma_async_client_unregister(struct dma_client *client)
643+
void dmaengine_put(void)
649644
{
650645
struct dma_device *device;
651646
struct dma_chan *chan;
652647

653-
if (!client)
654-
return;
655-
656648
mutex_lock(&dma_list_mutex);
657649
dmaengine_ref_count--;
658650
BUG_ON(dmaengine_ref_count < 0);
@@ -663,11 +655,9 @@ void dma_async_client_unregister(struct dma_client *client)
663655
list_for_each_entry(chan, &device->channels, device_node)
664656
dma_chan_put(chan);
665657
}
666-
667-
list_del(&client->global_node);
668658
mutex_unlock(&dma_list_mutex);
669659
}
670-
EXPORT_SYMBOL(dma_async_client_unregister);
660+
EXPORT_SYMBOL(dmaengine_put);
671661

672662
/**
673663
* dma_async_client_chan_request - send all available channels to the

‎include/linux/dmaengine.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ struct dma_device {
318318

319319
/* --- public DMA engine API --- */
320320

321-
void dma_async_client_register(struct dma_client *client);
322-
void dma_async_client_unregister(struct dma_client *client);
321+
void dmaengine_get(void);
322+
void dmaengine_put(void);
323323
void dma_async_client_chan_request(struct dma_client *client);
324324
dma_cookie_t dma_async_memcpy_buf_to_buf(struct dma_chan *chan,
325325
void *dest, void *src, size_t len);

‎net/core/dev.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4894,8 +4894,7 @@ static int __init netdev_dma_register(void)
48944894
}
48954895
spin_lock_init(&net_dma.lock);
48964896
dma_cap_set(DMA_MEMCPY, net_dma.client.cap_mask);
4897-
dma_async_client_register(&net_dma.client);
4898-
dma_async_client_chan_request(&net_dma.client);
4897+
dmaengine_get();
48994898
return 0;
49004899
}
49014900

0 commit comments

Comments
 (0)