aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide-iops.c
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2009-03-24 18:22:46 -0400
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2009-03-24 18:22:46 -0400
commit1574cf6cb4800525be769ee6023c567113fa2d18 (patch)
tree402ba6391dbc71d7a143ddba6cf998845530c77c /drivers/ide/ide-iops.c
parent0d6a9754c06e173552b0ad5fad45f69786b6de99 (diff)
ide: move standard I/O code to ide-io-std.c
Acked-by: Sergei Shtylyov <sshtylyov@ru.mvista.com> Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide/ide-iops.c')
-rw-r--r--drivers/ide/ide-iops.c313
1 files changed, 0 insertions, 313 deletions
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index d24add692129..91a49b543bd5 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -27,34 +27,6 @@
27#include <asm/uaccess.h> 27#include <asm/uaccess.h>
28#include <asm/io.h> 28#include <asm/io.h>
29 29
30/*
31 * Conventional PIO operations for ATA devices
32 */
33
34static u8 ide_inb (unsigned long port)
35{
36 return (u8) inb(port);
37}
38
39static void ide_outb (u8 val, unsigned long port)
40{
41 outb(val, port);
42}
43
44/*
45 * MMIO operations, typically used for SATA controllers
46 */
47
48static u8 ide_mm_inb (unsigned long port)
49{
50 return (u8) readb((void __iomem *) port);
51}
52
53static void ide_mm_outb (u8 value, unsigned long port)
54{
55 writeb(value, (void __iomem *) port);
56}
57
58void SELECT_DRIVE (ide_drive_t *drive) 30void SELECT_DRIVE (ide_drive_t *drive)
59{ 31{
60 ide_hwif_t *hwif = drive->hwif; 32 ide_hwif_t *hwif = drive->hwif;
@@ -78,277 +50,6 @@ void SELECT_MASK(ide_drive_t *drive, int mask)
78 port_ops->maskproc(drive, mask); 50 port_ops->maskproc(drive, mask);
79} 51}
80 52
81void ide_exec_command(ide_hwif_t *hwif, u8 cmd)
82{
83 if (hwif->host_flags & IDE_HFLAG_MMIO)
84 writeb(cmd, (void __iomem *)hwif->io_ports.command_addr);
85 else
86 outb(cmd, hwif->io_ports.command_addr);
87}
88EXPORT_SYMBOL_GPL(ide_exec_command);
89
90u8 ide_read_status(ide_hwif_t *hwif)
91{
92 if (hwif->host_flags & IDE_HFLAG_MMIO)
93 return readb((void __iomem *)hwif->io_ports.status_addr);
94 else
95 return inb(hwif->io_ports.status_addr);
96}
97EXPORT_SYMBOL_GPL(ide_read_status);
98
99u8 ide_read_altstatus(ide_hwif_t *hwif)
100{
101 if (hwif->host_flags & IDE_HFLAG_MMIO)
102 return readb((void __iomem *)hwif->io_ports.ctl_addr);
103 else
104 return inb(hwif->io_ports.ctl_addr);
105}
106EXPORT_SYMBOL_GPL(ide_read_altstatus);
107
108void ide_set_irq(ide_hwif_t *hwif, int on)
109{
110 u8 ctl = ATA_DEVCTL_OBS;
111
112 if (on == 4) { /* hack for SRST */
113 ctl |= 4;
114 on &= ~4;
115 }
116
117 ctl |= on ? 0 : 2;
118
119 if (hwif->host_flags & IDE_HFLAG_MMIO)
120 writeb(ctl, (void __iomem *)hwif->io_ports.ctl_addr);
121 else
122 outb(ctl, hwif->io_ports.ctl_addr);
123}
124EXPORT_SYMBOL_GPL(ide_set_irq);
125
126void ide_tf_load(ide_drive_t *drive, ide_task_t *task)
127{
128 ide_hwif_t *hwif = drive->hwif;
129 struct ide_io_ports *io_ports = &hwif->io_ports;
130 struct ide_taskfile *tf = &task->tf;
131 void (*tf_outb)(u8 addr, unsigned long port);
132 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
133 u8 HIHI = (task->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF;
134
135 if (mmio)
136 tf_outb = ide_mm_outb;
137 else
138 tf_outb = ide_outb;
139
140 if (task->tf_flags & IDE_TFLAG_FLAGGED)
141 HIHI = 0xFF;
142
143 if (task->tf_flags & IDE_TFLAG_OUT_DATA) {
144 u16 data = (tf->hob_data << 8) | tf->data;
145
146 if (mmio)
147 writew(data, (void __iomem *)io_ports->data_addr);
148 else
149 outw(data, io_ports->data_addr);
150 }
151
152 if (task->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
153 tf_outb(tf->hob_feature, io_ports->feature_addr);
154 if (task->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
155 tf_outb(tf->hob_nsect, io_ports->nsect_addr);
156 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAL)
157 tf_outb(tf->hob_lbal, io_ports->lbal_addr);
158 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAM)
159 tf_outb(tf->hob_lbam, io_ports->lbam_addr);
160 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAH)
161 tf_outb(tf->hob_lbah, io_ports->lbah_addr);
162
163 if (task->tf_flags & IDE_TFLAG_OUT_FEATURE)
164 tf_outb(tf->feature, io_ports->feature_addr);
165 if (task->tf_flags & IDE_TFLAG_OUT_NSECT)
166 tf_outb(tf->nsect, io_ports->nsect_addr);
167 if (task->tf_flags & IDE_TFLAG_OUT_LBAL)
168 tf_outb(tf->lbal, io_ports->lbal_addr);
169 if (task->tf_flags & IDE_TFLAG_OUT_LBAM)
170 tf_outb(tf->lbam, io_ports->lbam_addr);
171 if (task->tf_flags & IDE_TFLAG_OUT_LBAH)
172 tf_outb(tf->lbah, io_ports->lbah_addr);
173
174 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
175 tf_outb((tf->device & HIHI) | drive->select,
176 io_ports->device_addr);
177}
178EXPORT_SYMBOL_GPL(ide_tf_load);
179
180void ide_tf_read(ide_drive_t *drive, ide_task_t *task)
181{
182 ide_hwif_t *hwif = drive->hwif;
183 struct ide_io_ports *io_ports = &hwif->io_ports;
184 struct ide_taskfile *tf = &task->tf;
185 void (*tf_outb)(u8 addr, unsigned long port);
186 u8 (*tf_inb)(unsigned long port);
187 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
188
189 if (mmio) {
190 tf_outb = ide_mm_outb;
191 tf_inb = ide_mm_inb;
192 } else {
193 tf_outb = ide_outb;
194 tf_inb = ide_inb;
195 }
196
197 if (task->tf_flags & IDE_TFLAG_IN_DATA) {
198 u16 data;
199
200 if (mmio)
201 data = readw((void __iomem *)io_ports->data_addr);
202 else
203 data = inw(io_ports->data_addr);
204
205 tf->data = data & 0xff;
206 tf->hob_data = (data >> 8) & 0xff;
207 }
208
209 /* be sure we're looking at the low order bits */
210 tf_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr);
211
212 if (task->tf_flags & IDE_TFLAG_IN_FEATURE)
213 tf->feature = tf_inb(io_ports->feature_addr);
214 if (task->tf_flags & IDE_TFLAG_IN_NSECT)
215 tf->nsect = tf_inb(io_ports->nsect_addr);
216 if (task->tf_flags & IDE_TFLAG_IN_LBAL)
217 tf->lbal = tf_inb(io_ports->lbal_addr);
218 if (task->tf_flags & IDE_TFLAG_IN_LBAM)
219 tf->lbam = tf_inb(io_ports->lbam_addr);
220 if (task->tf_flags & IDE_TFLAG_IN_LBAH)
221 tf->lbah = tf_inb(io_ports->lbah_addr);
222 if (task->tf_flags & IDE_TFLAG_IN_DEVICE)
223 tf->device = tf_inb(io_ports->device_addr);
224
225 if (task->tf_flags & IDE_TFLAG_LBA48) {
226 tf_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr);
227
228 if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
229 tf->hob_feature = tf_inb(io_ports->feature_addr);
230 if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
231 tf->hob_nsect = tf_inb(io_ports->nsect_addr);
232 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
233 tf->hob_lbal = tf_inb(io_ports->lbal_addr);
234 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
235 tf->hob_lbam = tf_inb(io_ports->lbam_addr);
236 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
237 tf->hob_lbah = tf_inb(io_ports->lbah_addr);
238 }
239}
240EXPORT_SYMBOL_GPL(ide_tf_read);
241
242/*
243 * Some localbus EIDE interfaces require a special access sequence
244 * when using 32-bit I/O instructions to transfer data. We call this
245 * the "vlb_sync" sequence, which consists of three successive reads
246 * of the sector count register location, with interrupts disabled
247 * to ensure that the reads all happen together.
248 */
249static void ata_vlb_sync(unsigned long port)
250{
251 (void)inb(port);
252 (void)inb(port);
253 (void)inb(port);
254}
255
256/*
257 * This is used for most PIO data transfers *from* the IDE interface
258 *
259 * These routines will round up any request for an odd number of bytes,
260 * so if an odd len is specified, be sure that there's at least one
261 * extra byte allocated for the buffer.
262 */
263void ide_input_data(ide_drive_t *drive, struct request *rq, void *buf,
264 unsigned int len)
265{
266 ide_hwif_t *hwif = drive->hwif;
267 struct ide_io_ports *io_ports = &hwif->io_ports;
268 unsigned long data_addr = io_ports->data_addr;
269 u8 io_32bit = drive->io_32bit;
270 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
271
272 len++;
273
274 if (io_32bit) {
275 unsigned long uninitialized_var(flags);
276
277 if ((io_32bit & 2) && !mmio) {
278 local_irq_save(flags);
279 ata_vlb_sync(io_ports->nsect_addr);
280 }
281
282 if (mmio)
283 __ide_mm_insl((void __iomem *)data_addr, buf, len / 4);
284 else
285 insl(data_addr, buf, len / 4);
286
287 if ((io_32bit & 2) && !mmio)
288 local_irq_restore(flags);
289
290 if ((len & 3) >= 2) {
291 if (mmio)
292 __ide_mm_insw((void __iomem *)data_addr,
293 (u8 *)buf + (len & ~3), 1);
294 else
295 insw(data_addr, (u8 *)buf + (len & ~3), 1);
296 }
297 } else {
298 if (mmio)
299 __ide_mm_insw((void __iomem *)data_addr, buf, len / 2);
300 else
301 insw(data_addr, buf, len / 2);
302 }
303}
304EXPORT_SYMBOL_GPL(ide_input_data);
305
306/*
307 * This is used for most PIO data transfers *to* the IDE interface
308 */
309void ide_output_data(ide_drive_t *drive, struct request *rq, void *buf,
310 unsigned int len)
311{
312 ide_hwif_t *hwif = drive->hwif;
313 struct ide_io_ports *io_ports = &hwif->io_ports;
314 unsigned long data_addr = io_ports->data_addr;
315 u8 io_32bit = drive->io_32bit;
316 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
317
318 len++;
319
320 if (io_32bit) {
321 unsigned long uninitialized_var(flags);
322
323 if ((io_32bit & 2) && !mmio) {
324 local_irq_save(flags);
325 ata_vlb_sync(io_ports->nsect_addr);
326 }
327
328 if (mmio)
329 __ide_mm_outsl((void __iomem *)data_addr, buf, len / 4);
330 else
331 outsl(data_addr, buf, len / 4);
332
333 if ((io_32bit & 2) && !mmio)
334 local_irq_restore(flags);
335
336 if ((len & 3) >= 2) {
337 if (mmio)
338 __ide_mm_outsw((void __iomem *)data_addr,
339 (u8 *)buf + (len & ~3), 1);
340 else
341 outsw(data_addr, (u8 *)buf + (len & ~3), 1);
342 }
343 } else {
344 if (mmio)
345 __ide_mm_outsw((void __iomem *)data_addr, buf, len / 2);
346 else
347 outsw(data_addr, buf, len / 2);
348 }
349}
350EXPORT_SYMBOL_GPL(ide_output_data);
351
352u8 ide_read_error(ide_drive_t *drive) 53u8 ide_read_error(ide_drive_t *drive)
353{ 54{
354 ide_task_t task; 55 ide_task_t task;
@@ -362,20 +63,6 @@ u8 ide_read_error(ide_drive_t *drive)
362} 63}
363EXPORT_SYMBOL_GPL(ide_read_error); 64EXPORT_SYMBOL_GPL(ide_read_error);
364 65
365const struct ide_tp_ops default_tp_ops = {
366 .exec_command = ide_exec_command,
367 .read_status = ide_read_status,
368 .read_altstatus = ide_read_altstatus,
369
370 .set_irq = ide_set_irq,
371
372 .tf_load = ide_tf_load,
373 .tf_read = ide_tf_read,
374
375 .input_data = ide_input_data,
376 .output_data = ide_output_data,
377};
378
379void ide_fix_driveid(u16 *id) 66void ide_fix_driveid(u16 *id)
380{ 67{
381#ifndef __LITTLE_ENDIAN 68#ifndef __LITTLE_ENDIAN