]>
Commit | Line | Data |
---|---|---|
1574cf6c BZ |
1 | |
2 | #include <linux/kernel.h> | |
3 | #include <linux/ide.h> | |
4 | ||
15a453a9 BZ |
5 | #if defined(CONFIG_ARM) || defined(CONFIG_M68K) || defined(CONFIG_MIPS) || \ |
6 | defined(CONFIG_PARISC) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) | |
7 | #include <asm/ide.h> | |
8 | #else | |
9 | #include <asm-generic/ide_iops.h> | |
10 | #endif | |
11 | ||
1574cf6c BZ |
12 | /* |
13 | * Conventional PIO operations for ATA devices | |
14 | */ | |
15 | ||
16 | static u8 ide_inb(unsigned long port) | |
17 | { | |
18 | return (u8) inb(port); | |
19 | } | |
20 | ||
21 | static void ide_outb(u8 val, unsigned long port) | |
22 | { | |
23 | outb(val, port); | |
24 | } | |
25 | ||
26 | /* | |
27 | * MMIO operations, typically used for SATA controllers | |
28 | */ | |
29 | ||
30 | static u8 ide_mm_inb(unsigned long port) | |
31 | { | |
32 | return (u8) readb((void __iomem *) port); | |
33 | } | |
34 | ||
35 | static void ide_mm_outb(u8 value, unsigned long port) | |
36 | { | |
37 | writeb(value, (void __iomem *) port); | |
38 | } | |
39 | ||
40 | void ide_exec_command(ide_hwif_t *hwif, u8 cmd) | |
41 | { | |
42 | if (hwif->host_flags & IDE_HFLAG_MMIO) | |
43 | writeb(cmd, (void __iomem *)hwif->io_ports.command_addr); | |
44 | else | |
45 | outb(cmd, hwif->io_ports.command_addr); | |
46 | } | |
47 | EXPORT_SYMBOL_GPL(ide_exec_command); | |
48 | ||
49 | u8 ide_read_status(ide_hwif_t *hwif) | |
50 | { | |
51 | if (hwif->host_flags & IDE_HFLAG_MMIO) | |
52 | return readb((void __iomem *)hwif->io_ports.status_addr); | |
53 | else | |
54 | return inb(hwif->io_ports.status_addr); | |
55 | } | |
56 | EXPORT_SYMBOL_GPL(ide_read_status); | |
57 | ||
58 | u8 ide_read_altstatus(ide_hwif_t *hwif) | |
59 | { | |
60 | if (hwif->host_flags & IDE_HFLAG_MMIO) | |
61 | return readb((void __iomem *)hwif->io_ports.ctl_addr); | |
62 | else | |
63 | return inb(hwif->io_ports.ctl_addr); | |
64 | } | |
65 | EXPORT_SYMBOL_GPL(ide_read_altstatus); | |
66 | ||
67 | void ide_set_irq(ide_hwif_t *hwif, int on) | |
68 | { | |
69 | u8 ctl = ATA_DEVCTL_OBS; | |
70 | ||
71 | if (on == 4) { /* hack for SRST */ | |
72 | ctl |= 4; | |
73 | on &= ~4; | |
74 | } | |
75 | ||
76 | ctl |= on ? 0 : 2; | |
77 | ||
78 | if (hwif->host_flags & IDE_HFLAG_MMIO) | |
79 | writeb(ctl, (void __iomem *)hwif->io_ports.ctl_addr); | |
80 | else | |
81 | outb(ctl, hwif->io_ports.ctl_addr); | |
82 | } | |
83 | EXPORT_SYMBOL_GPL(ide_set_irq); | |
84 | ||
22aa4b32 | 85 | void ide_tf_load(ide_drive_t *drive, struct ide_cmd *cmd) |
1574cf6c BZ |
86 | { |
87 | ide_hwif_t *hwif = drive->hwif; | |
88 | struct ide_io_ports *io_ports = &hwif->io_ports; | |
22aa4b32 | 89 | struct ide_taskfile *tf = &cmd->tf; |
1574cf6c BZ |
90 | void (*tf_outb)(u8 addr, unsigned long port); |
91 | u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; | |
22aa4b32 | 92 | u8 HIHI = (cmd->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF; |
1574cf6c BZ |
93 | |
94 | if (mmio) | |
95 | tf_outb = ide_mm_outb; | |
96 | else | |
97 | tf_outb = ide_outb; | |
98 | ||
22aa4b32 | 99 | if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED) |
1574cf6c BZ |
100 | HIHI = 0xFF; |
101 | ||
22aa4b32 | 102 | if (cmd->ftf_flags & IDE_FTFLAG_OUT_DATA) { |
1574cf6c BZ |
103 | u16 data = (tf->hob_data << 8) | tf->data; |
104 | ||
105 | if (mmio) | |
106 | writew(data, (void __iomem *)io_ports->data_addr); | |
107 | else | |
108 | outw(data, io_ports->data_addr); | |
109 | } | |
110 | ||
22aa4b32 | 111 | if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE) |
1574cf6c | 112 | tf_outb(tf->hob_feature, io_ports->feature_addr); |
22aa4b32 | 113 | if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT) |
1574cf6c | 114 | tf_outb(tf->hob_nsect, io_ports->nsect_addr); |
22aa4b32 | 115 | if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAL) |
1574cf6c | 116 | tf_outb(tf->hob_lbal, io_ports->lbal_addr); |
22aa4b32 | 117 | if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAM) |
1574cf6c | 118 | tf_outb(tf->hob_lbam, io_ports->lbam_addr); |
22aa4b32 | 119 | if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAH) |
1574cf6c BZ |
120 | tf_outb(tf->hob_lbah, io_ports->lbah_addr); |
121 | ||
22aa4b32 | 122 | if (cmd->tf_flags & IDE_TFLAG_OUT_FEATURE) |
1574cf6c | 123 | tf_outb(tf->feature, io_ports->feature_addr); |
22aa4b32 | 124 | if (cmd->tf_flags & IDE_TFLAG_OUT_NSECT) |
1574cf6c | 125 | tf_outb(tf->nsect, io_ports->nsect_addr); |
22aa4b32 | 126 | if (cmd->tf_flags & IDE_TFLAG_OUT_LBAL) |
1574cf6c | 127 | tf_outb(tf->lbal, io_ports->lbal_addr); |
22aa4b32 | 128 | if (cmd->tf_flags & IDE_TFLAG_OUT_LBAM) |
1574cf6c | 129 | tf_outb(tf->lbam, io_ports->lbam_addr); |
22aa4b32 | 130 | if (cmd->tf_flags & IDE_TFLAG_OUT_LBAH) |
1574cf6c BZ |
131 | tf_outb(tf->lbah, io_ports->lbah_addr); |
132 | ||
22aa4b32 | 133 | if (cmd->tf_flags & IDE_TFLAG_OUT_DEVICE) |
1574cf6c BZ |
134 | tf_outb((tf->device & HIHI) | drive->select, |
135 | io_ports->device_addr); | |
136 | } | |
137 | EXPORT_SYMBOL_GPL(ide_tf_load); | |
138 | ||
22aa4b32 | 139 | void ide_tf_read(ide_drive_t *drive, struct ide_cmd *cmd) |
1574cf6c BZ |
140 | { |
141 | ide_hwif_t *hwif = drive->hwif; | |
142 | struct ide_io_ports *io_ports = &hwif->io_ports; | |
22aa4b32 | 143 | struct ide_taskfile *tf = &cmd->tf; |
1574cf6c BZ |
144 | void (*tf_outb)(u8 addr, unsigned long port); |
145 | u8 (*tf_inb)(unsigned long port); | |
146 | u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; | |
147 | ||
148 | if (mmio) { | |
149 | tf_outb = ide_mm_outb; | |
150 | tf_inb = ide_mm_inb; | |
151 | } else { | |
152 | tf_outb = ide_outb; | |
153 | tf_inb = ide_inb; | |
154 | } | |
155 | ||
22aa4b32 | 156 | if (cmd->ftf_flags & IDE_FTFLAG_IN_DATA) { |
1574cf6c BZ |
157 | u16 data; |
158 | ||
159 | if (mmio) | |
160 | data = readw((void __iomem *)io_ports->data_addr); | |
161 | else | |
162 | data = inw(io_ports->data_addr); | |
163 | ||
164 | tf->data = data & 0xff; | |
165 | tf->hob_data = (data >> 8) & 0xff; | |
166 | } | |
167 | ||
168 | /* be sure we're looking at the low order bits */ | |
4d74c3fc | 169 | tf_outb(ATA_DEVCTL_OBS, io_ports->ctl_addr); |
1574cf6c | 170 | |
22aa4b32 | 171 | if (cmd->tf_flags & IDE_TFLAG_IN_FEATURE) |
1574cf6c | 172 | tf->feature = tf_inb(io_ports->feature_addr); |
22aa4b32 | 173 | if (cmd->tf_flags & IDE_TFLAG_IN_NSECT) |
1574cf6c | 174 | tf->nsect = tf_inb(io_ports->nsect_addr); |
22aa4b32 | 175 | if (cmd->tf_flags & IDE_TFLAG_IN_LBAL) |
1574cf6c | 176 | tf->lbal = tf_inb(io_ports->lbal_addr); |
22aa4b32 | 177 | if (cmd->tf_flags & IDE_TFLAG_IN_LBAM) |
1574cf6c | 178 | tf->lbam = tf_inb(io_ports->lbam_addr); |
22aa4b32 | 179 | if (cmd->tf_flags & IDE_TFLAG_IN_LBAH) |
1574cf6c | 180 | tf->lbah = tf_inb(io_ports->lbah_addr); |
22aa4b32 | 181 | if (cmd->tf_flags & IDE_TFLAG_IN_DEVICE) |
1574cf6c BZ |
182 | tf->device = tf_inb(io_ports->device_addr); |
183 | ||
22aa4b32 | 184 | if (cmd->tf_flags & IDE_TFLAG_LBA48) { |
4d74c3fc | 185 | tf_outb(ATA_HOB | ATA_DEVCTL_OBS, io_ports->ctl_addr); |
1574cf6c | 186 | |
22aa4b32 | 187 | if (cmd->tf_flags & IDE_TFLAG_IN_HOB_FEATURE) |
1574cf6c | 188 | tf->hob_feature = tf_inb(io_ports->feature_addr); |
22aa4b32 | 189 | if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT) |
1574cf6c | 190 | tf->hob_nsect = tf_inb(io_ports->nsect_addr); |
22aa4b32 | 191 | if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL) |
1574cf6c | 192 | tf->hob_lbal = tf_inb(io_ports->lbal_addr); |
22aa4b32 | 193 | if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM) |
1574cf6c | 194 | tf->hob_lbam = tf_inb(io_ports->lbam_addr); |
22aa4b32 | 195 | if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH) |
1574cf6c BZ |
196 | tf->hob_lbah = tf_inb(io_ports->lbah_addr); |
197 | } | |
198 | } | |
199 | EXPORT_SYMBOL_GPL(ide_tf_read); | |
200 | ||
201 | /* | |
202 | * Some localbus EIDE interfaces require a special access sequence | |
203 | * when using 32-bit I/O instructions to transfer data. We call this | |
204 | * the "vlb_sync" sequence, which consists of three successive reads | |
205 | * of the sector count register location, with interrupts disabled | |
206 | * to ensure that the reads all happen together. | |
207 | */ | |
208 | static void ata_vlb_sync(unsigned long port) | |
209 | { | |
210 | (void)inb(port); | |
211 | (void)inb(port); | |
212 | (void)inb(port); | |
213 | } | |
214 | ||
215 | /* | |
216 | * This is used for most PIO data transfers *from* the IDE interface | |
217 | * | |
218 | * These routines will round up any request for an odd number of bytes, | |
219 | * so if an odd len is specified, be sure that there's at least one | |
220 | * extra byte allocated for the buffer. | |
221 | */ | |
adb1af98 | 222 | void ide_input_data(ide_drive_t *drive, struct ide_cmd *cmd, void *buf, |
1574cf6c BZ |
223 | unsigned int len) |
224 | { | |
225 | ide_hwif_t *hwif = drive->hwif; | |
226 | struct ide_io_ports *io_ports = &hwif->io_ports; | |
227 | unsigned long data_addr = io_ports->data_addr; | |
228 | u8 io_32bit = drive->io_32bit; | |
229 | u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; | |
230 | ||
231 | len++; | |
232 | ||
233 | if (io_32bit) { | |
234 | unsigned long uninitialized_var(flags); | |
235 | ||
236 | if ((io_32bit & 2) && !mmio) { | |
237 | local_irq_save(flags); | |
238 | ata_vlb_sync(io_ports->nsect_addr); | |
239 | } | |
240 | ||
241 | if (mmio) | |
242 | __ide_mm_insl((void __iomem *)data_addr, buf, len / 4); | |
243 | else | |
244 | insl(data_addr, buf, len / 4); | |
245 | ||
246 | if ((io_32bit & 2) && !mmio) | |
247 | local_irq_restore(flags); | |
248 | ||
249 | if ((len & 3) >= 2) { | |
250 | if (mmio) | |
251 | __ide_mm_insw((void __iomem *)data_addr, | |
252 | (u8 *)buf + (len & ~3), 1); | |
253 | else | |
254 | insw(data_addr, (u8 *)buf + (len & ~3), 1); | |
255 | } | |
256 | } else { | |
257 | if (mmio) | |
258 | __ide_mm_insw((void __iomem *)data_addr, buf, len / 2); | |
259 | else | |
260 | insw(data_addr, buf, len / 2); | |
261 | } | |
262 | } | |
263 | EXPORT_SYMBOL_GPL(ide_input_data); | |
264 | ||
265 | /* | |
266 | * This is used for most PIO data transfers *to* the IDE interface | |
267 | */ | |
adb1af98 | 268 | void ide_output_data(ide_drive_t *drive, struct ide_cmd *cmd, void *buf, |
1574cf6c BZ |
269 | unsigned int len) |
270 | { | |
271 | ide_hwif_t *hwif = drive->hwif; | |
272 | struct ide_io_ports *io_ports = &hwif->io_ports; | |
273 | unsigned long data_addr = io_ports->data_addr; | |
274 | u8 io_32bit = drive->io_32bit; | |
275 | u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; | |
276 | ||
277 | len++; | |
278 | ||
279 | if (io_32bit) { | |
280 | unsigned long uninitialized_var(flags); | |
281 | ||
282 | if ((io_32bit & 2) && !mmio) { | |
283 | local_irq_save(flags); | |
284 | ata_vlb_sync(io_ports->nsect_addr); | |
285 | } | |
286 | ||
287 | if (mmio) | |
288 | __ide_mm_outsl((void __iomem *)data_addr, buf, len / 4); | |
289 | else | |
290 | outsl(data_addr, buf, len / 4); | |
291 | ||
292 | if ((io_32bit & 2) && !mmio) | |
293 | local_irq_restore(flags); | |
294 | ||
295 | if ((len & 3) >= 2) { | |
296 | if (mmio) | |
297 | __ide_mm_outsw((void __iomem *)data_addr, | |
298 | (u8 *)buf + (len & ~3), 1); | |
299 | else | |
300 | outsw(data_addr, (u8 *)buf + (len & ~3), 1); | |
301 | } | |
302 | } else { | |
303 | if (mmio) | |
304 | __ide_mm_outsw((void __iomem *)data_addr, buf, len / 2); | |
305 | else | |
306 | outsw(data_addr, buf, len / 2); | |
307 | } | |
308 | } | |
309 | EXPORT_SYMBOL_GPL(ide_output_data); | |
310 | ||
311 | const struct ide_tp_ops default_tp_ops = { | |
312 | .exec_command = ide_exec_command, | |
313 | .read_status = ide_read_status, | |
314 | .read_altstatus = ide_read_altstatus, | |
315 | ||
316 | .set_irq = ide_set_irq, | |
317 | ||
318 | .tf_load = ide_tf_load, | |
319 | .tf_read = ide_tf_read, | |
320 | ||
321 | .input_data = ide_input_data, | |
322 | .output_data = ide_output_data, | |
323 | }; |