clean
[linux-2.4.21-pre4.git] / include / asm-sparc64 / ide.h
1 /* $Id: ide.h,v 1.1.1.1 2005/04/11 02:50:57 jack Exp $
2  * ide.h: Ultra/PCI specific IDE glue.
3  *
4  * Copyright (C) 1997  David S. Miller (davem@caip.rutgers.edu)
5  * Copyright (C) 1998  Eddie C. Dost   (ecd@skynet.be)
6  */
7
8 #ifndef _SPARC64_IDE_H
9 #define _SPARC64_IDE_H
10
11 #ifdef __KERNEL__
12
13 #include <linux/config.h>
14 #include <asm/pgalloc.h>
15 #include <asm/io.h>
16 #include <asm/hdreg.h>
17 #include <asm/page.h>
18 #include <asm/spitfire.h>
19
20 #undef  MAX_HWIFS
21 #define MAX_HWIFS       2
22
23 static __inline__ int ide_default_irq(ide_ioreg_t base)
24 {
25         return 0;
26 }
27
28 static __inline__ ide_ioreg_t ide_default_io_base(int index)
29 {
30         return 0;
31 }
32
33 static __inline__ void ide_init_hwif_ports(hw_regs_t *hw, ide_ioreg_t data_port, ide_ioreg_t ctrl_port, int *irq)
34 {
35         ide_ioreg_t reg =  data_port;
36         int i;
37
38         for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
39                 hw->io_ports[i] = reg;
40                 reg += 1;
41         }
42         if (ctrl_port) {
43                 hw->io_ports[IDE_CONTROL_OFFSET] = ctrl_port;
44         } else {
45                 hw->io_ports[IDE_CONTROL_OFFSET] = 0;
46         }
47         if (irq != NULL)
48                 *irq = 0;
49         hw->io_ports[IDE_IRQ_OFFSET] = 0;
50 }
51
52 /*
53  * This registers the standard ports for this architecture with the IDE
54  * driver.
55  */
56 static __inline__ void ide_init_default_hwifs(void)
57 {
58 #ifndef CONFIG_BLK_DEV_IDEPCI
59         hw_regs_t hw;
60         int index;
61
62         for (index = 0; index < MAX_HWIFS; index++) {
63                 ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, NULL);
64                 hw.irq = ide_default_irq(ide_default_io_base(index));
65                 ide_register_hw(&hw, NULL);
66         }
67 #endif /* CONFIG_BLK_DEV_IDEPCI */
68 }
69
70 #undef  SUPPORT_SLOW_DATA_PORTS
71 #define SUPPORT_SLOW_DATA_PORTS 0
72
73 #undef  SUPPORT_VLB_SYNC
74 #define SUPPORT_VLB_SYNC 0
75
76 #undef  HD_DATA
77 #define HD_DATA ((ide_ioreg_t)0)
78
79 #define __ide_insl(data_reg, buffer, wcount) \
80         __ide_insw(data_reg, buffer, (wcount)<<1)
81 #define __ide_outsl(data_reg, buffer, wcount) \
82         __ide_outsw(data_reg, buffer, (wcount)<<1)
83
84 /* On sparc64, I/O ports and MMIO registers are accessed identically.  */
85 #define __ide_mm_insw   __ide_insw
86 #define __ide_mm_insl   __ide_insl
87 #define __ide_mm_outsw  __ide_outsw
88 #define __ide_mm_outsl  __ide_outsl
89
90 static __inline__ unsigned int inw_be(unsigned long addr)
91 {
92         unsigned int ret;
93
94         __asm__ __volatile__("lduha [%1] %2, %0"
95                              : "=r" (ret)
96                              : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
97
98         return ret;
99 }
100
101 static __inline__ void __ide_insw(unsigned long port,
102                                   void *dst,
103                                   u32 count)
104 {
105 #if (L1DCACHE_SIZE > PAGE_SIZE)         /* is there D$ aliasing problem */
106         unsigned long end = (unsigned long)dst + (count << 1);
107 #endif
108         u16 *ps = dst;
109         u32 *pi;
110
111         if(((u64)ps) & 0x2) {
112                 *ps++ = inw_be(port);
113                 count--;
114         }
115         pi = (u32 *)ps;
116         while(count >= 2) {
117                 u32 w;
118
119                 w  = inw_be(port) << 16;
120                 w |= inw_be(port);
121                 *pi++ = w;
122                 count -= 2;
123         }
124         ps = (u16 *)pi;
125         if(count)
126                 *ps++ = inw_be(port);
127
128 #if (L1DCACHE_SIZE > PAGE_SIZE)         /* is there D$ aliasing problem */
129         __flush_dcache_range((unsigned long)dst, end);
130 #endif
131 }
132
133 static __inline__ void outw_be(unsigned short w, unsigned long addr)
134 {
135         __asm__ __volatile__("stha %0, [%1] %2"
136                              : /* no outputs */
137                              : "r" (w), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
138 }
139
140 static __inline__ void __ide_outsw(unsigned long port,
141                                    void *src,
142                                    u32 count)
143 {
144 #if (L1DCACHE_SIZE > PAGE_SIZE)         /* is there D$ aliasing problem */
145         unsigned long end = (unsigned long)src + (count << 1);
146 #endif
147         const u16 *ps = src;
148         const u32 *pi;
149
150         if(((u64)src) & 0x2) {
151                 outw_be(*ps++, port);
152                 count--;
153         }
154         pi = (const u32 *)ps;
155         while(count >= 2) {
156                 u32 w;
157
158                 w = *pi++;
159                 outw_be((w >> 16), port);
160                 outw_be(w, port);
161                 count -= 2;
162         }
163         ps = (const u16 *)pi;
164         if(count)
165                 outw_be(*ps, port);
166
167 #if (L1DCACHE_SIZE > PAGE_SIZE)         /* is there D$ aliasing problem */
168         __flush_dcache_range((unsigned long)src, end);
169 #endif
170 }
171
172 #endif /* __KERNEL__ */
173
174 #endif /* _SPARC64_IDE_H */