PageRenderTime 23ms CodeModel.GetById 6ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 1ms

/arch/arm26/machine/dma.c

https://bitbucket.org/evzijst/gittest
C | 215 lines | 163 code | 31 blank | 21 comment | 11 complexity | 261a500c89aed31417446773d0c049a8 MD5 | raw file
  1/*
  2 *  linux/arch/arm26/kernel/dma.c
  3 *
  4 *  Copyright (C) 1998-1999 Dave Gilbert / Russell King
  5 *  Copyright (C) 2003 Ian Molton
  6 *
  7 * This program is free software; you can redistribute it and/or modify
  8 * it under the terms of the GNU General Public License version 2 as
  9 * published by the Free Software Foundation.
 10 *
 11 *  DMA functions specific to Archimedes and A5000 architecture
 12 */
 13#include <linux/config.h>
 14#include <linux/sched.h>
 15#include <linux/init.h>
 16
 17#include <asm/dma.h>
 18#include <asm/fiq.h>
 19#include <asm/irq.h>
 20#include <asm/io.h>
 21#include <asm/hardware.h>
 22#include <asm/mach-types.h>
 23
 24#define DPRINTK(x...) printk(KERN_DEBUG x)
 25
 26#if defined(CONFIG_BLK_DEV_FD1772) || defined(CONFIG_BLK_DEV_FD1772_MODULE)
 27
 28extern unsigned char fdc1772_dma_read, fdc1772_dma_read_end;
 29extern unsigned char fdc1772_dma_write, fdc1772_dma_write_end;
 30extern void fdc1772_setupdma(unsigned int count,unsigned int addr);
 31
 32static void arc_floppy_data_enable_dma(dmach_t channel, dma_t *dma)
 33{
 34	DPRINTK("arc_floppy_data_enable_dma\n");
 35
 36	if (dma->using_sg)
 37		BUG();
 38
 39	switch (dma->dma_mode) {
 40	case DMA_MODE_READ: { /* read */
 41		unsigned long flags;
 42		DPRINTK("enable_dma fdc1772 data read\n");
 43		local_save_flags_cli(flags);
 44		clf();
 45			
 46		memcpy ((void *)0x1c, (void *)&fdc1772_dma_read,
 47			&fdc1772_dma_read_end - &fdc1772_dma_read);
 48		fdc1772_setupdma(dma->buf.length, dma->buf.__address); /* Sets data pointer up */
 49		enable_fiq(FIQ_FLOPPYDATA);
 50		local_irq_restore(flags);
 51	   }
 52	   break;
 53
 54	case DMA_MODE_WRITE: { /* write */
 55		unsigned long flags;
 56		DPRINTK("enable_dma fdc1772 data write\n");
 57		local_save_flags_cli(flags);
 58		clf();
 59		memcpy ((void *)0x1c, (void *)&fdc1772_dma_write,
 60			&fdc1772_dma_write_end - &fdc1772_dma_write);
 61		fdc1772_setupdma(dma->buf.length, dma->buf.__address); /* Sets data pointer up */
 62		enable_fiq(FIQ_FLOPPYDATA);
 63
 64		local_irq_restore(flags);
 65	    }
 66	    break;
 67	default:
 68		printk ("enable_dma: dma%d not initialised\n", channel);
 69	}
 70}
 71
 72static int arc_floppy_data_get_dma_residue(dmach_t channel, dma_t *dma)
 73{
 74	extern unsigned int fdc1772_bytestogo;
 75
 76	/* 10/1/1999 DAG - I presume its the number of bytes left? */
 77	return fdc1772_bytestogo;
 78}
 79
 80static void arc_floppy_cmdend_enable_dma(dmach_t channel, dma_t *dma)
 81{
 82	/* Need to build a branch at the FIQ address */
 83	extern void fdc1772_comendhandler(void);
 84	unsigned long flags;
 85
 86	DPRINTK("arc_floppy_cmdend_enable_dma\n");
 87	/*printk("enable_dma fdc1772 command end FIQ\n");*/
 88	save_flags(flags);
 89	clf();
 90	
 91	/* B fdc1772_comendhandler */
 92	*((unsigned int *)0x1c)=0xea000000 |
 93			(((unsigned int)fdc1772_comendhandler-(0x1c+8))/4);
 94
 95	local_irq_restore(flags);
 96}
 97
 98static int arc_floppy_cmdend_get_dma_residue(dmach_t channel, dma_t *dma)
 99{
100	/* 10/1/1999 DAG - Presume whether there is an outstanding command? */
101	extern unsigned int fdc1772_fdc_int_done;
102
103	/* Explicit! If the int done is 0 then 1 int to go */
104	return (fdc1772_fdc_int_done==0)?1:0;
105}
106
107static void arc_disable_dma(dmach_t channel, dma_t *dma)
108{
109	disable_fiq(dma->dma_irq);
110}
111
112static struct dma_ops arc_floppy_data_dma_ops = {
113	.type		= "FIQDMA",
114	.enable		= arc_floppy_data_enable_dma,
115	.disable	= arc_disable_dma,
116	.residue	= arc_floppy_data_get_dma_residue,
117};
118
119static struct dma_ops arc_floppy_cmdend_dma_ops = {
120	.type		= "FIQCMD",
121	.enable		= arc_floppy_cmdend_enable_dma,
122	.disable	= arc_disable_dma,
123	.residue	= arc_floppy_cmdend_get_dma_residue,
124};
125#endif
126
127#ifdef CONFIG_ARCH_A5K
128static struct fiq_handler fh = {
129	.name	= "floppydata"
130};
131
132static int a5k_floppy_get_dma_residue(dmach_t channel, dma_t *dma)
133{
134	struct pt_regs regs;
135	get_fiq_regs(&regs);
136	return regs.ARM_r9;
137}
138
139static void a5k_floppy_enable_dma(dmach_t channel, dma_t *dma)
140{
141	struct pt_regs regs;
142	void *fiqhandler_start;
143	unsigned int fiqhandler_length;
144	extern void floppy_fiqsetup(unsigned long len, unsigned long addr,
145				     unsigned long port);
146
147	if (dma->using_sg)
148		BUG();
149
150	if (dma->dma_mode == DMA_MODE_READ) {
151		extern unsigned char floppy_fiqin_start, floppy_fiqin_end;
152		fiqhandler_start = &floppy_fiqin_start;
153		fiqhandler_length = &floppy_fiqin_end - &floppy_fiqin_start;
154	} else {
155		extern unsigned char floppy_fiqout_start, floppy_fiqout_end;
156		fiqhandler_start = &floppy_fiqout_start;
157		fiqhandler_length = &floppy_fiqout_end - &floppy_fiqout_start;
158	}
159	if (claim_fiq(&fh)) {
160		printk("floppydma: couldn't claim FIQ.\n");
161		return;
162	}
163	memcpy((void *)0x1c, fiqhandler_start, fiqhandler_length);
164	regs.ARM_r9 = dma->buf.length;
165	regs.ARM_r10 = (unsigned long)dma->buf.__address;
166	regs.ARM_fp = FLOPPYDMA_BASE;
167	set_fiq_regs(&regs);
168	enable_fiq(dma->dma_irq);
169}
170
171static void a5k_floppy_disable_dma(dmach_t channel, dma_t *dma)
172{
173	disable_fiq(dma->dma_irq);
174	release_fiq(&fh);
175}
176
177static struct dma_ops a5k_floppy_dma_ops = {
178	.type		= "FIQDMA",
179	.enable		= a5k_floppy_enable_dma,
180	.disable	= a5k_floppy_disable_dma,
181	.residue	= a5k_floppy_get_dma_residue,
182};
183#endif
184
185/*
186 * This is virtual DMA - we don't need anything here
187 */
188static void sound_enable_disable_dma(dmach_t channel, dma_t *dma)
189{
190}
191
192static struct dma_ops sound_dma_ops = {
193	.type		= "VIRTUAL",
194	.enable		= sound_enable_disable_dma,
195	.disable	= sound_enable_disable_dma,
196};
197
198void __init arch_dma_init(dma_t *dma)
199{
200#if defined(CONFIG_BLK_DEV_FD1772) || defined(CONFIG_BLK_DEV_FD1772_MODULE)
201	if (machine_is_archimedes()) {
202		dma[DMA_VIRTUAL_FLOPPY0].dma_irq = FIQ_FLOPPYDATA;
203		dma[DMA_VIRTUAL_FLOPPY0].d_ops   = &arc_floppy_data_dma_ops;
204		dma[DMA_VIRTUAL_FLOPPY1].dma_irq = 1;
205		dma[DMA_VIRTUAL_FLOPPY1].d_ops   = &arc_floppy_cmdend_dma_ops;
206	}
207#endif
208#ifdef CONFIG_ARCH_A5K
209	if (machine_is_a5k()) {
210		dma[DMA_VIRTUAL_FLOPPY0].dma_irq = FIQ_FLOPPYDATA;
211		dma[DMA_VIRTUAL_FLOPPY0].d_ops   = &a5k_floppy_dma_ops;
212	}
213#endif
214	dma[DMA_VIRTUAL_SOUND].d_ops = &sound_dma_ops;
215}