1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* Architecture specific parts of the Floppy driver
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
8 #ifndef __ASM_PARISC_FLOPPY_H
9 #define __ASM_PARISC_FLOPPY_H
11 #include <linux/vmalloc.h>
15 * The DMA channel used by the floppy controller cannot access data at
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.
22 #define _CROSS_64KB(a,s,vdma) \
23 (!(vdma) && ((unsigned long)(a)/K_64 != ((unsigned long)(a) + (s) - 1) / K_64))
25 #define CROSS_64KB(a,s) _CROSS_64KB(a,s,use_virtual_dma & 1)
28 #define SW fd_routine[use_virtual_dma&1]
29 #define CSW fd_routine[can_use_virtual_dma & 1]
32 #define fd_inb(port) readb(port)
33 #define fd_outb(value, port) writeb(value, port)
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)
44 #define FLOPPY_CAN_FALLBACK_ON_NODMA
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;
52 static void floppy_hardint(int irq
, void *dev_id
, struct pt_regs
* regs
)
54 register unsigned char st
;
61 static int dma_wait
=0;
64 floppy_interrupt(irq
, dev_id
, regs
);
70 bytes
= virtual_dma_count
;
75 register char *lptr
= virtual_dma_addr
;
77 for (lcount
= virtual_dma_count
; lcount
; lcount
--) {
78 st
= fd_inb(virtual_dma_port
+4) & 0xa0 ;
81 if (virtual_dma_mode
) {
82 fd_outb(*lptr
, virtual_dma_port
+5);
84 *lptr
= fd_inb(virtual_dma_port
+5);
88 virtual_dma_count
= lcount
;
89 virtual_dma_addr
= lptr
;
90 st
= fd_inb(virtual_dma_port
+4);
99 virtual_dma_residue
+= virtual_dma_count
;
100 virtual_dma_count
= 0;
101 #ifdef TRACE_FLPY_INT
102 printk("count=%x, residue=%x calls=%d bytes=%d dma_wait=%d\n",
103 virtual_dma_count
, virtual_dma_residue
, calls
, bytes
,
109 floppy_interrupt(irq
, dev_id
, regs
);
112 #ifdef TRACE_FLPY_INT
113 if (!virtual_dma_count
)
118 static void fd_disable_dma(void)
120 if(! (can_use_virtual_dma
& 1))
121 disable_dma(FLOPPY_DMA
);
123 virtual_dma_residue
+= virtual_dma_count
;
127 static int vdma_request_dma(unsigned int dmanr
, const char * device_id
)
132 static void vdma_nop(unsigned int dummy
)
137 static int vdma_get_dma_residue(unsigned int dummy
)
139 return virtual_dma_count
+ virtual_dma_residue
;
143 static int fd_request_irq(void)
145 if(can_use_virtual_dma
)
146 return request_irq(FLOPPY_IRQ
, floppy_hardint
,
149 return request_irq(FLOPPY_IRQ
, floppy_interrupt
,
153 static unsigned long dma_mem_alloc(unsigned long size
)
155 return __get_dma_pages(GFP_KERNEL
, get_order(size
));
159 static unsigned long vdma_mem_alloc(unsigned long size
)
161 return (unsigned long) vmalloc(size
);
165 #define nodma_mem_alloc(size) vdma_mem_alloc(size)
167 static void _fd_dma_mem_free(unsigned long addr
, unsigned long size
)
169 if((unsigned int) addr
>= (unsigned int) high_memory
)
170 return vfree((void *)addr
);
172 free_pages(addr
, get_order(size
));
175 #define fd_dma_mem_free(addr, size) _fd_dma_mem_free(addr, size)
177 static void _fd_chose_dma_mode(char *addr
, unsigned long size
)
179 if(can_use_virtual_dma
== 2) {
180 if((unsigned int) addr
>= (unsigned int) high_memory
||
181 virt_to_bus(addr
) >= 0x1000000 ||
182 _CROSS_64KB(addr
, size
, 0))
187 use_virtual_dma
= can_use_virtual_dma
& 1;
191 #define fd_chose_dma_mode(addr, size) _fd_chose_dma_mode(addr, size)
194 static int vdma_dma_setup(char *addr
, unsigned long size
, int mode
, int io
)
197 virtual_dma_port
= io
;
198 virtual_dma_mode
= (mode
== DMA_MODE_WRITE
);
199 virtual_dma_addr
= addr
;
200 virtual_dma_count
= size
;
201 virtual_dma_residue
= 0;
205 static int hard_dma_setup(char *addr
, unsigned long size
, int mode
, int io
)
207 #ifdef FLOPPY_SANITY_CHECK
208 if (CROSS_64KB(addr
, size
)) {
209 printk("DMA crossing 64-K boundary %p-%p\n", addr
, addr
+size
);
213 /* actual, physical DMA */
215 clear_dma_ff(FLOPPY_DMA
);
216 set_dma_mode(FLOPPY_DMA
,mode
);
217 set_dma_addr(FLOPPY_DMA
,virt_to_bus(addr
));
218 set_dma_count(FLOPPY_DMA
,size
);
219 enable_dma(FLOPPY_DMA
);
223 static struct fd_routine_l
{
224 int (*_request_dma
)(unsigned int dmanr
, const char * device_id
);
225 void (*_free_dma
)(unsigned int dmanr
);
226 int (*_get_dma_residue
)(unsigned int dummy
);
227 unsigned long (*_dma_mem_alloc
) (unsigned long size
);
228 int (*_dma_setup
)(char *addr
, unsigned long size
, int mode
, int io
);
240 vdma_get_dma_residue
,
247 static int FDC1
= 0x3f0; /* Lies. Floppy controller is memory mapped, not io mapped */
248 static int FDC2
= -1;
250 #define FLOPPY0_TYPE 0
251 #define FLOPPY1_TYPE 0
256 #define EXTRA_FLOPPY_PARAMS
258 #endif /* __ASM_PARISC_FLOPPY_H */