xref: /openbmc/linux/arch/parisc/include/asm/floppy.h (revision 4313a249)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*    Architecture specific parts of the Floppy driver
3  *
4  *    Linux/PA-RISC Project (http://www.parisc-linux.org/)
5  *    Copyright (C) 2000 Matthew Wilcox (willy a debian . org)
6  *    Copyright (C) 2000 Dave Kennedy
7  */
8 #ifndef __ASM_PARISC_FLOPPY_H
9 #define __ASM_PARISC_FLOPPY_H
10 
11 #include <linux/vmalloc.h>
12 
13 
14 /*
15  * The DMA channel used by the floppy controller cannot access data at
16  * addresses >= 16MB
17  *
18  * Went back to the 1MB limit, as some people had problems with the floppy
19  * driver otherwise. It doesn't matter much for performance anyway, as most
20  * floppy accesses go through the track buffer.
21  */
22 #define _CROSS_64KB(a,s,vdma) \
23 (!(vdma) && ((unsigned long)(a)/K_64 != ((unsigned long)(a) + (s) - 1) / K_64))
24 
25 #define CROSS_64KB(a,s) _CROSS_64KB(a,s,use_virtual_dma & 1)
26 
27 
28 #define SW fd_routine[use_virtual_dma&1]
29 #define CSW fd_routine[can_use_virtual_dma & 1]
30 
31 
32 #define fd_inb(base, reg)		readb((base) + (reg))
33 #define fd_outb(value, base, reg)	writeb(value, (base) + (reg))
34 
35 #define fd_request_dma()        CSW._request_dma(FLOPPY_DMA,"floppy")
36 #define fd_free_dma()           CSW._free_dma(FLOPPY_DMA)
37 #define fd_enable_irq()         enable_irq(FLOPPY_IRQ)
38 #define fd_disable_irq()        disable_irq(FLOPPY_IRQ)
39 #define fd_free_irq()		free_irq(FLOPPY_IRQ, NULL)
40 #define fd_get_dma_residue()    SW._get_dma_residue(FLOPPY_DMA)
41 #define fd_dma_mem_alloc(size)	SW._dma_mem_alloc(size)
42 #define fd_dma_setup(addr, size, mode, io) SW._dma_setup(addr, size, mode, io)
43 
44 #define FLOPPY_CAN_FALLBACK_ON_NODMA
45 
46 static int virtual_dma_count=0;
47 static int virtual_dma_residue=0;
48 static char *virtual_dma_addr=0;
49 static int virtual_dma_mode=0;
50 static int doing_pdma=0;
51 
floppy_hardint(int irq,void * dev_id,struct pt_regs * regs)52 static void floppy_hardint(int irq, void *dev_id, struct pt_regs * regs)
53 {
54 	register unsigned char st;
55 
56 #undef TRACE_FLPY_INT
57 
58 #ifdef TRACE_FLPY_INT
59 	static int calls=0;
60 	static int bytes=0;
61 	static int dma_wait=0;
62 #endif
63 	if (!doing_pdma) {
64 		floppy_interrupt(irq, dev_id, regs);
65 		return;
66 	}
67 
68 #ifdef TRACE_FLPY_INT
69 	if(!calls)
70 		bytes = virtual_dma_count;
71 #endif
72 
73 	{
74 		register int lcount;
75 		register char *lptr = virtual_dma_addr;
76 
77 		for (lcount = virtual_dma_count; lcount; lcount--) {
78 			st = fd_inb(virtual_dma_port, FD_STATUS);
79 			st &= STATUS_DMA | STATUS_READY;
80 			if (st != (STATUS_DMA | STATUS_READY))
81 				break;
82 			if (virtual_dma_mode) {
83 				fd_outb(*lptr, virtual_dma_port, FD_DATA);
84 			} else {
85 				*lptr = fd_inb(virtual_dma_port, FD_DATA);
86 			}
87 			lptr++;
88 		}
89 		virtual_dma_count = lcount;
90 		virtual_dma_addr = lptr;
91 		st = fd_inb(virtual_dma_port, FD_STATUS);
92 	}
93 
94 #ifdef TRACE_FLPY_INT
95 	calls++;
96 #endif
97 	if (st == STATUS_DMA)
98 		return;
99 	if (!(st & STATUS_DMA)) {
100 		virtual_dma_residue += virtual_dma_count;
101 		virtual_dma_count = 0;
102 #ifdef TRACE_FLPY_INT
103 		printk("count=%x, residue=%x calls=%d bytes=%d dma_wait=%d\n",
104 		       virtual_dma_count, virtual_dma_residue, calls, bytes,
105 		       dma_wait);
106 		calls = 0;
107 		dma_wait=0;
108 #endif
109 		doing_pdma = 0;
110 		floppy_interrupt(irq, dev_id, regs);
111 		return;
112 	}
113 #ifdef TRACE_FLPY_INT
114 	if (!virtual_dma_count)
115 		dma_wait++;
116 #endif
117 }
118 
fd_disable_dma(void)119 static void fd_disable_dma(void)
120 {
121 	if(! (can_use_virtual_dma & 1))
122 		disable_dma(FLOPPY_DMA);
123 	doing_pdma = 0;
124 	virtual_dma_residue += virtual_dma_count;
125 	virtual_dma_count=0;
126 }
127 
vdma_request_dma(unsigned int dmanr,const char * device_id)128 static int vdma_request_dma(unsigned int dmanr, const char * device_id)
129 {
130 	return 0;
131 }
132 
vdma_nop(unsigned int dummy)133 static void vdma_nop(unsigned int dummy)
134 {
135 }
136 
137 
vdma_get_dma_residue(unsigned int dummy)138 static int vdma_get_dma_residue(unsigned int dummy)
139 {
140 	return virtual_dma_count + virtual_dma_residue;
141 }
142 
143 
fd_request_irq(void)144 static int fd_request_irq(void)
145 {
146 	if(can_use_virtual_dma)
147 		return request_irq(FLOPPY_IRQ, floppy_hardint,
148 				   0, "floppy", NULL);
149 	else
150 		return request_irq(FLOPPY_IRQ, floppy_interrupt,
151 				   0, "floppy", NULL);
152 }
153 
dma_mem_alloc(unsigned long size)154 static unsigned long dma_mem_alloc(unsigned long size)
155 {
156 	return __get_dma_pages(GFP_KERNEL, get_order(size));
157 }
158 
159 
vdma_mem_alloc(unsigned long size)160 static unsigned long vdma_mem_alloc(unsigned long size)
161 {
162 	return (unsigned long) vmalloc(size);
163 
164 }
165 
166 #define nodma_mem_alloc(size) vdma_mem_alloc(size)
167 
_fd_dma_mem_free(unsigned long addr,unsigned long size)168 static void _fd_dma_mem_free(unsigned long addr, unsigned long size)
169 {
170 	if((unsigned int) addr >= (unsigned int) high_memory)
171 		return vfree((void *)addr);
172 	else
173 		free_pages(addr, get_order(size));
174 }
175 
176 #define fd_dma_mem_free(addr, size)  _fd_dma_mem_free(addr, size)
177 
_fd_chose_dma_mode(char * addr,unsigned long size)178 static void _fd_chose_dma_mode(char *addr, unsigned long size)
179 {
180 	if(can_use_virtual_dma == 2) {
181 		if((unsigned int) addr >= (unsigned int) high_memory ||
182 		   virt_to_phys(addr) >= 0x1000000 ||
183 		   _CROSS_64KB(addr, size, 0))
184 			use_virtual_dma = 1;
185 		else
186 			use_virtual_dma = 0;
187 	} else {
188 		use_virtual_dma = can_use_virtual_dma & 1;
189 	}
190 }
191 
192 #define fd_chose_dma_mode(addr, size) _fd_chose_dma_mode(addr, size)
193 
194 
vdma_dma_setup(char * addr,unsigned long size,int mode,int io)195 static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
196 {
197 	doing_pdma = 1;
198 	virtual_dma_port = io;
199 	virtual_dma_mode = (mode  == DMA_MODE_WRITE);
200 	virtual_dma_addr = addr;
201 	virtual_dma_count = size;
202 	virtual_dma_residue = 0;
203 	return 0;
204 }
205 
hard_dma_setup(char * addr,unsigned long size,int mode,int io)206 static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
207 {
208 #ifdef FLOPPY_SANITY_CHECK
209 	if (CROSS_64KB(addr, size)) {
210 		printk("DMA crossing 64-K boundary %p-%p\n", addr, addr+size);
211 		return -1;
212 	}
213 #endif
214 	/* actual, physical DMA */
215 	doing_pdma = 0;
216 	clear_dma_ff(FLOPPY_DMA);
217 	set_dma_mode(FLOPPY_DMA,mode);
218 	set_dma_addr(FLOPPY_DMA,virt_to_phys(addr));
219 	set_dma_count(FLOPPY_DMA,size);
220 	enable_dma(FLOPPY_DMA);
221 	return 0;
222 }
223 
224 static struct fd_routine_l {
225 	int (*_request_dma)(unsigned int dmanr, const char * device_id);
226 	void (*_free_dma)(unsigned int dmanr);
227 	int (*_get_dma_residue)(unsigned int dummy);
228 	unsigned long (*_dma_mem_alloc) (unsigned long size);
229 	int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
230 } fd_routine[] = {
231 	{
232 		request_dma,
233 		free_dma,
234 		get_dma_residue,
235 		dma_mem_alloc,
236 		hard_dma_setup
237 	},
238 	{
239 		vdma_request_dma,
240 		vdma_nop,
241 		vdma_get_dma_residue,
242 		vdma_mem_alloc,
243 		vdma_dma_setup
244 	}
245 };
246 
247 
248 static int FDC1 = 0x3f0; /* Lies.  Floppy controller is memory mapped, not io mapped */
249 static int FDC2 = -1;
250 
251 #define FLOPPY0_TYPE	0
252 #define FLOPPY1_TYPE	0
253 
254 #define N_FDC 1
255 #define N_DRIVE 8
256 
257 #define EXTRA_FLOPPY_PARAMS
258 
259 #endif /* __ASM_PARISC_FLOPPY_H */
260