Skip to content

Commit 2f757f2

Browse files
Russell KingRussell King
authored andcommitted
[ARM] dma: rejig DMA initialization
Rather than having the central DMA multiplexer call the architecture specific DMA initialization function, have each architecture DMA initialization function use core_initcall(), and register each DMA channel separately with the multiplexer. This removes the array of dma structures in the central multiplexer, replacing it with an array of pointers instead; this is more flexible since it allows the drivers to wrap the DMA structure (eventually allowing us to transition non-ISA DMA drivers away.) Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 3afb6e9 commit 2f757f2

6 files changed

Lines changed: 88 additions & 47 deletions

File tree

‎arch/arm/include/asm/mach/dma.h‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ struct dma_struct {
4848
struct dma_ops *d_ops;
4949
};
5050

51-
/* Prototype: void arch_dma_init(dma)
52-
* Purpose : Initialise architecture specific DMA
53-
* Params : dma - pointer to array of DMA structures
51+
/*
52+
* isa_dma_add - add an ISA-style DMA channel
5453
*/
55-
extern void arch_dma_init(dma_t *dma);
54+
extern int isa_dma_add(unsigned int, dma_t *dma);
5655

57-
extern void isa_init_dma(dma_t *dma);
56+
/*
57+
* Add the ISA DMA controller. Always takes channels 0-7.
58+
*/
59+
extern void isa_init_dma(void);

‎arch/arm/kernel/dma-isa.c‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,12 @@ static struct resource dma_resources[] = { {
160160
.end = 0x048f
161161
} };
162162

163-
void __init isa_init_dma(dma_t *dma)
163+
static dma_t isa_dma[8];
164+
165+
/*
166+
* ISA DMA always starts at channel 0
167+
*/
168+
void __init isa_init_dma(void)
164169
{
165170
/*
166171
* Try to autodetect presence of an ISA DMA controller.
@@ -178,10 +183,10 @@ void __init isa_init_dma(dma_t *dma)
178183
outb(0xaa, 0x00);
179184

180185
if (inb(0) == 0x55 && inb(0) == 0xaa) {
181-
int chan, i;
186+
unsigned int chan, i;
182187

183188
for (chan = 0; chan < 8; chan++) {
184-
dma[chan].d_ops = &isa_dma_ops;
189+
isa_dma[chan].d_ops = &isa_dma_ops;
185190
isa_disable_dma(chan, NULL);
186191
}
187192

@@ -217,5 +222,12 @@ void __init isa_init_dma(dma_t *dma)
217222

218223
for (i = 0; i < ARRAY_SIZE(dma_resources); i++)
219224
request_resource(&ioport_resource, dma_resources + i);
225+
226+
for (chan = 0; chan < 8; chan++) {
227+
int ret = isa_dma_add(chan, &isa_dma[chan]);
228+
if (ret)
229+
printk(KERN_ERR "ISADMA%u: unable to register: %d\n",
230+
chan, ret);
231+
}
220232
}
221233
}

‎arch/arm/kernel/dma.c‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,24 @@
2323
DEFINE_SPINLOCK(dma_spin_lock);
2424
EXPORT_SYMBOL(dma_spin_lock);
2525

26-
static dma_t dma_chan[MAX_DMA_CHANNELS];
26+
static dma_t *dma_chan[MAX_DMA_CHANNELS];
2727

2828
static inline dma_t *dma_channel(unsigned int chan)
2929
{
30-
dma_t *dma = dma_chan + chan;
31-
32-
if (chan >= MAX_DMA_CHANNELS || !dma->d_ops)
30+
if (chan >= MAX_DMA_CHANNELS)
3331
return NULL;
3432

35-
return dma;
33+
return dma_chan[chan];
34+
}
35+
36+
int __init isa_dma_add(unsigned int chan, dma_t *dma)
37+
{
38+
if (!dma->d_ops)
39+
return -EINVAL;
40+
if (dma_chan[chan])
41+
return -EBUSY;
42+
dma_chan[chan] = dma;
43+
return 0;
3644
}
3745

3846
/*
@@ -252,10 +260,3 @@ int get_dma_residue(unsigned int chan)
252260
return ret;
253261
}
254262
EXPORT_SYMBOL(get_dma_residue);
255-
256-
static int __init init_dma(void)
257-
{
258-
arch_dma_init(dma_chan);
259-
return 0;
260-
}
261-
core_initcall(init_dma);

‎arch/arm/mach-footbridge/dma.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ static struct dma_ops fb_dma_ops = {
4141
};
4242
#endif
4343

44-
void __init arch_dma_init(dma_t *dma)
44+
static int __init fb_dma_init(void)
4545
{
4646
#if 0
4747
dma[_DC21285_DMA(0)].d_ops = &fb_dma_ops;
4848
dma[_DC21285_DMA(1)].d_ops = &fb_dma_ops;
4949
#endif
5050
#ifdef CONFIG_ISA_DMA
5151
if (footbridge_cfn_mode())
52-
isa_init_dma(dma + _ISA_DMA(0));
52+
isa_init_dma();
5353
#endif
54+
return 0;
5455
}
56+
core_initcall(fb_dma_init);

‎arch/arm/mach-rpc/dma.c‎

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -302,40 +302,62 @@ static struct dma_ops sound_dma_ops = {
302302
.disable = sound_enable_disable_dma,
303303
};
304304

305-
void __init arch_dma_init(dma_t *dma)
305+
static dma_t iomd_dma[6];
306+
307+
static dma_t floppy_dma = {
308+
.dma_irq = FIQ_FLOPPYDATA,
309+
.d_ops = &floppy_dma_ops,
310+
};
311+
312+
static dma_t sound_dma = {
313+
.d_ops = &sound_dma_ops,
314+
};
315+
316+
static int __init rpc_dma_init(void)
306317
{
318+
unsigned int i;
319+
int ret;
320+
307321
iomd_writeb(0, IOMD_IO0CR);
308322
iomd_writeb(0, IOMD_IO1CR);
309323
iomd_writeb(0, IOMD_IO2CR);
310324
iomd_writeb(0, IOMD_IO3CR);
311325

312326
iomd_writeb(0xa0, IOMD_DMATCR);
313327

314-
dma[DMA_0].dma_base = IOMD_IO0CURA;
315-
dma[DMA_0].dma_irq = IRQ_DMA0;
316-
dma[DMA_0].d_ops = &iomd_dma_ops;
317-
dma[DMA_1].dma_base = IOMD_IO1CURA;
318-
dma[DMA_1].dma_irq = IRQ_DMA1;
319-
dma[DMA_1].d_ops = &iomd_dma_ops;
320-
dma[DMA_2].dma_base = IOMD_IO2CURA;
321-
dma[DMA_2].dma_irq = IRQ_DMA2;
322-
dma[DMA_2].d_ops = &iomd_dma_ops;
323-
dma[DMA_3].dma_base = IOMD_IO3CURA;
324-
dma[DMA_3].dma_irq = IRQ_DMA3;
325-
dma[DMA_3].d_ops = &iomd_dma_ops;
326-
dma[DMA_S0].dma_base = IOMD_SD0CURA;
327-
dma[DMA_S0].dma_irq = IRQ_DMAS0;
328-
dma[DMA_S0].d_ops = &iomd_dma_ops;
329-
dma[DMA_S1].dma_base = IOMD_SD1CURA;
330-
dma[DMA_S1].dma_irq = IRQ_DMAS1;
331-
dma[DMA_S1].d_ops = &iomd_dma_ops;
332-
dma[DMA_VIRTUAL_FLOPPY].dma_irq = FIQ_FLOPPYDATA;
333-
dma[DMA_VIRTUAL_FLOPPY].d_ops = &floppy_dma_ops;
334-
dma[DMA_VIRTUAL_SOUND].d_ops = &sound_dma_ops;
335-
336328
/*
337329
* Setup DMA channels 2,3 to be for podules
338330
* and channels 0,1 for internal devices
339331
*/
340332
iomd_writeb(DMA_EXT_IO3|DMA_EXT_IO2, IOMD_DMAEXT);
333+
334+
iomd_dma[DMA_0].dma_base = IOMD_IO0CURA;
335+
iomd_dma[DMA_0].dma_irq = IRQ_DMA0;
336+
iomd_dma[DMA_1].dma_base = IOMD_IO1CURA;
337+
iomd_dma[DMA_1].dma_irq = IRQ_DMA1;
338+
iomd_dma[DMA_2].dma_base = IOMD_IO2CURA;
339+
iomd_dma[DMA_2].dma_irq = IRQ_DMA2;
340+
iomd_dma[DMA_3].dma_base = IOMD_IO3CURA;
341+
iomd_dma[DMA_3].dma_irq = IRQ_DMA3;
342+
iomd_dma[DMA_S0].dma_base = IOMD_SD0CURA;
343+
iomd_dma[DMA_S0].dma_irq = IRQ_DMAS0;
344+
iomd_dma[DMA_S1].dma_base = IOMD_SD1CURA;
345+
iomd_dma[DMA_S1].dma_irq = IRQ_DMAS1;
346+
347+
for (i = DMA_0; i <= DMA_S1; i++) {
348+
iomd_dma[i].d_ops = &iomd_dma_ops;
349+
350+
ret = isa_dma_add(i, &iomd_dma[i]);
351+
if (ret)
352+
printk("IOMDDMA%u: unable to register: %d\n", i, ret);
353+
}
354+
355+
ret = isa_dma_add(DMA_VIRTUAL_FLOPPY, &floppy_dma);
356+
if (ret)
357+
printk("IOMDFLOPPY: unable to register: %d\n", ret);
358+
ret = isa_dma_add(DMA_VIRTUAL_SOUND, &sound_dma);
359+
if (ret)
360+
printk("IOMDSOUND: unable to register: %d\n", ret);
361+
return 0;
341362
}
363+
core_initcall(rpc_dma_init);

‎arch/arm/mach-shark/dma.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
#include <asm/dma.h>
1414
#include <asm/mach/dma.h>
1515

16-
void __init arch_dma_init(dma_t *dma)
16+
static int __init shark_dma_init(void)
1717
{
1818
#ifdef CONFIG_ISA_DMA
19-
isa_init_dma(dma);
19+
isa_init_dma();
2020
#endif
21+
return 0;
2122
}
23+
core_initcall(shark_dma_init);

0 commit comments

Comments
 (0)