2 #include <linux/kernel.h>
5 #if defined(CONFIG_ARM) || defined(CONFIG_M68K) || defined(CONFIG_MIPS) || \
6 defined(CONFIG_PARISC) || defined(CONFIG_PPC) || defined(CONFIG_SPARC)
9 #include <asm-generic/ide_iops.h>
13 * Conventional PIO operations for ATA devices
16 static u8 ide_inb(unsigned long port)
18 return (u8) inb(port);
21 static void ide_outb(u8 val, unsigned long port)
27 * MMIO operations, typically used for SATA controllers
30 static u8 ide_mm_inb(unsigned long port)
32 return (u8) readb((void __iomem *) port);
35 static void ide_mm_outb(u8 value, unsigned long port)
37 writeb(value, (void __iomem *) port);
40 void ide_exec_command(ide_hwif_t *hwif, u8 cmd)
42 if (hwif->host_flags & IDE_HFLAG_MMIO)
43 writeb(cmd, (void __iomem *)hwif->io_ports.command_addr);
45 outb(cmd, hwif->io_ports.command_addr);
47 EXPORT_SYMBOL_GPL(ide_exec_command);
49 u8 ide_read_status(ide_hwif_t *hwif)
51 if (hwif->host_flags & IDE_HFLAG_MMIO)
52 return readb((void __iomem *)hwif->io_ports.status_addr);
54 return inb(hwif->io_ports.status_addr);
56 EXPORT_SYMBOL_GPL(ide_read_status);
58 u8 ide_read_altstatus(ide_hwif_t *hwif)
60 if (hwif->host_flags & IDE_HFLAG_MMIO)
61 return readb((void __iomem *)hwif->io_ports.ctl_addr);
63 return inb(hwif->io_ports.ctl_addr);
65 EXPORT_SYMBOL_GPL(ide_read_altstatus);
67 void ide_write_devctl(ide_hwif_t *hwif, u8 ctl)
69 if (hwif->host_flags & IDE_HFLAG_MMIO)
70 writeb(ctl, (void __iomem *)hwif->io_ports.ctl_addr);
72 outb(ctl, hwif->io_ports.ctl_addr);
74 EXPORT_SYMBOL_GPL(ide_write_devctl);
76 void ide_dev_select(ide_drive_t *drive)
78 ide_hwif_t *hwif = drive->hwif;
79 u8 select = drive->select | ATA_DEVICE_OBS;
81 if (hwif->host_flags & IDE_HFLAG_MMIO)
82 writeb(select, (void __iomem *)hwif->io_ports.device_addr);
84 outb(select, hwif->io_ports.device_addr);
86 EXPORT_SYMBOL_GPL(ide_dev_select);
88 void ide_tf_load(ide_drive_t *drive, struct ide_taskfile *tf, u8 valid)
90 ide_hwif_t *hwif = drive->hwif;
91 struct ide_io_ports *io_ports = &hwif->io_ports;
92 void (*tf_outb)(u8 addr, unsigned long port);
93 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
96 tf_outb = ide_mm_outb;
100 if (valid & IDE_VALID_FEATURE)
101 tf_outb(tf->feature, io_ports->feature_addr);
102 if (valid & IDE_VALID_NSECT)
103 tf_outb(tf->nsect, io_ports->nsect_addr);
104 if (valid & IDE_VALID_LBAL)
105 tf_outb(tf->lbal, io_ports->lbal_addr);
106 if (valid & IDE_VALID_LBAM)
107 tf_outb(tf->lbam, io_ports->lbam_addr);
108 if (valid & IDE_VALID_LBAH)
109 tf_outb(tf->lbah, io_ports->lbah_addr);
110 if (valid & IDE_VALID_DEVICE)
111 tf_outb(tf->device, io_ports->device_addr);
113 EXPORT_SYMBOL_GPL(ide_tf_load);
115 void ide_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
117 ide_hwif_t *hwif = drive->hwif;
118 struct ide_io_ports *io_ports = &hwif->io_ports;
119 struct ide_taskfile *tf = &cmd->tf;
120 u8 (*tf_inb)(unsigned long port);
121 u8 valid = cmd->valid.in.tf;
122 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
129 /* be sure we're looking at the low order bits */
130 hwif->tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS);
132 if (valid & IDE_VALID_ERROR)
133 tf->error = tf_inb(io_ports->feature_addr);
134 if (valid & IDE_VALID_NSECT)
135 tf->nsect = tf_inb(io_ports->nsect_addr);
136 if (valid & IDE_VALID_LBAL)
137 tf->lbal = tf_inb(io_ports->lbal_addr);
138 if (valid & IDE_VALID_LBAM)
139 tf->lbam = tf_inb(io_ports->lbam_addr);
140 if (valid & IDE_VALID_LBAH)
141 tf->lbah = tf_inb(io_ports->lbah_addr);
142 if (valid & IDE_VALID_DEVICE)
143 tf->device = tf_inb(io_ports->device_addr);
145 if (cmd->tf_flags & IDE_TFLAG_LBA48) {
146 hwif->tp_ops->write_devctl(hwif, ATA_HOB | ATA_DEVCTL_OBS);
149 valid = cmd->valid.in.hob;
151 if (valid & IDE_VALID_ERROR)
152 tf->error = tf_inb(io_ports->feature_addr);
153 if (valid & IDE_VALID_NSECT)
154 tf->nsect = tf_inb(io_ports->nsect_addr);
155 if (valid & IDE_VALID_LBAL)
156 tf->lbal = tf_inb(io_ports->lbal_addr);
157 if (valid & IDE_VALID_LBAM)
158 tf->lbam = tf_inb(io_ports->lbam_addr);
159 if (valid & IDE_VALID_LBAH)
160 tf->lbah = tf_inb(io_ports->lbah_addr);
163 EXPORT_SYMBOL_GPL(ide_tf_read);
166 * Some localbus EIDE interfaces require a special access sequence
167 * when using 32-bit I/O instructions to transfer data. We call this
168 * the "vlb_sync" sequence, which consists of three successive reads
169 * of the sector count register location, with interrupts disabled
170 * to ensure that the reads all happen together.
172 static void ata_vlb_sync(unsigned long port)
180 * This is used for most PIO data transfers *from* the IDE interface
182 * These routines will round up any request for an odd number of bytes,
183 * so if an odd len is specified, be sure that there's at least one
184 * extra byte allocated for the buffer.
186 void ide_input_data(ide_drive_t *drive, struct ide_cmd *cmd, void *buf,
189 ide_hwif_t *hwif = drive->hwif;
190 struct ide_io_ports *io_ports = &hwif->io_ports;
191 unsigned long data_addr = io_ports->data_addr;
192 unsigned int words = (len + 1) >> 1;
193 u8 io_32bit = drive->io_32bit;
194 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
197 unsigned long uninitialized_var(flags);
199 if ((io_32bit & 2) && !mmio) {
200 local_irq_save(flags);
201 ata_vlb_sync(io_ports->nsect_addr);
206 __ide_mm_insl((void __iomem *)data_addr, buf, words);
208 insl(data_addr, buf, words);
210 if ((io_32bit & 2) && !mmio)
211 local_irq_restore(flags);
213 if (((len + 1) & 3) < 2)
221 __ide_mm_insw((void __iomem *)data_addr, buf, words);
223 insw(data_addr, buf, words);
225 EXPORT_SYMBOL_GPL(ide_input_data);
228 * This is used for most PIO data transfers *to* the IDE interface
230 void ide_output_data(ide_drive_t *drive, struct ide_cmd *cmd, void *buf,
233 ide_hwif_t *hwif = drive->hwif;
234 struct ide_io_ports *io_ports = &hwif->io_ports;
235 unsigned long data_addr = io_ports->data_addr;
236 unsigned int words = (len + 1) >> 1;
237 u8 io_32bit = drive->io_32bit;
238 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
241 unsigned long uninitialized_var(flags);
243 if ((io_32bit & 2) && !mmio) {
244 local_irq_save(flags);
245 ata_vlb_sync(io_ports->nsect_addr);
250 __ide_mm_outsl((void __iomem *)data_addr, buf, words);
252 outsl(data_addr, buf, words);
254 if ((io_32bit & 2) && !mmio)
255 local_irq_restore(flags);
257 if (((len + 1) & 3) < 2)
265 __ide_mm_outsw((void __iomem *)data_addr, buf, words);
267 outsw(data_addr, buf, words);
269 EXPORT_SYMBOL_GPL(ide_output_data);
271 const struct ide_tp_ops default_tp_ops = {
272 .exec_command = ide_exec_command,
273 .read_status = ide_read_status,
274 .read_altstatus = ide_read_altstatus,
275 .write_devctl = ide_write_devctl,
277 .dev_select = ide_dev_select,
278 .tf_load = ide_tf_load,
279 .tf_read = ide_tf_read,
281 .input_data = ide_input_data,
282 .output_data = ide_output_data,