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_set_irq(ide_hwif_t
*hwif
, int on
)
69 u8 ctl
= ATA_DEVCTL_OBS
;
71 if (on
== 4) { /* hack for SRST */
78 if (hwif
->host_flags
& IDE_HFLAG_MMIO
)
79 writeb(ctl
, (void __iomem
*)hwif
->io_ports
.ctl_addr
);
81 outb(ctl
, hwif
->io_ports
.ctl_addr
);
83 EXPORT_SYMBOL_GPL(ide_set_irq
);
85 void ide_tf_load(ide_drive_t
*drive
, struct ide_cmd
*cmd
)
87 ide_hwif_t
*hwif
= drive
->hwif
;
88 struct ide_io_ports
*io_ports
= &hwif
->io_ports
;
89 struct ide_taskfile
*tf
= &cmd
->tf
;
90 void (*tf_outb
)(u8 addr
, unsigned long port
);
91 u8 mmio
= (hwif
->host_flags
& IDE_HFLAG_MMIO
) ? 1 : 0;
92 u8 HIHI
= (cmd
->tf_flags
& IDE_TFLAG_LBA48
) ? 0xE0 : 0xEF;
95 tf_outb
= ide_mm_outb
;
99 if (cmd
->ftf_flags
& IDE_FTFLAG_FLAGGED
)
102 if (cmd
->ftf_flags
& IDE_FTFLAG_OUT_DATA
) {
103 u16 data
= (tf
->hob_data
<< 8) | tf
->data
;
106 writew(data
, (void __iomem
*)io_ports
->data_addr
);
108 outw(data
, io_ports
->data_addr
);
111 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_FEATURE
)
112 tf_outb(tf
->hob_feature
, io_ports
->feature_addr
);
113 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_NSECT
)
114 tf_outb(tf
->hob_nsect
, io_ports
->nsect_addr
);
115 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_LBAL
)
116 tf_outb(tf
->hob_lbal
, io_ports
->lbal_addr
);
117 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_LBAM
)
118 tf_outb(tf
->hob_lbam
, io_ports
->lbam_addr
);
119 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_LBAH
)
120 tf_outb(tf
->hob_lbah
, io_ports
->lbah_addr
);
122 if (cmd
->tf_flags
& IDE_TFLAG_OUT_FEATURE
)
123 tf_outb(tf
->feature
, io_ports
->feature_addr
);
124 if (cmd
->tf_flags
& IDE_TFLAG_OUT_NSECT
)
125 tf_outb(tf
->nsect
, io_ports
->nsect_addr
);
126 if (cmd
->tf_flags
& IDE_TFLAG_OUT_LBAL
)
127 tf_outb(tf
->lbal
, io_ports
->lbal_addr
);
128 if (cmd
->tf_flags
& IDE_TFLAG_OUT_LBAM
)
129 tf_outb(tf
->lbam
, io_ports
->lbam_addr
);
130 if (cmd
->tf_flags
& IDE_TFLAG_OUT_LBAH
)
131 tf_outb(tf
->lbah
, io_ports
->lbah_addr
);
133 if (cmd
->tf_flags
& IDE_TFLAG_OUT_DEVICE
)
134 tf_outb((tf
->device
& HIHI
) | drive
->select
,
135 io_ports
->device_addr
);
137 EXPORT_SYMBOL_GPL(ide_tf_load
);
139 void ide_tf_read(ide_drive_t
*drive
, struct ide_cmd
*cmd
)
141 ide_hwif_t
*hwif
= drive
->hwif
;
142 struct ide_io_ports
*io_ports
= &hwif
->io_ports
;
143 struct ide_taskfile
*tf
= &cmd
->tf
;
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;
149 tf_outb
= ide_mm_outb
;
156 if (cmd
->ftf_flags
& IDE_FTFLAG_IN_DATA
) {
160 data
= readw((void __iomem
*)io_ports
->data_addr
);
162 data
= inw(io_ports
->data_addr
);
164 tf
->data
= data
& 0xff;
165 tf
->hob_data
= (data
>> 8) & 0xff;
168 /* be sure we're looking at the low order bits */
169 tf_outb(ATA_DEVCTL_OBS
& ~0x80, io_ports
->ctl_addr
);
171 if (cmd
->tf_flags
& IDE_TFLAG_IN_FEATURE
)
172 tf
->feature
= tf_inb(io_ports
->feature_addr
);
173 if (cmd
->tf_flags
& IDE_TFLAG_IN_NSECT
)
174 tf
->nsect
= tf_inb(io_ports
->nsect_addr
);
175 if (cmd
->tf_flags
& IDE_TFLAG_IN_LBAL
)
176 tf
->lbal
= tf_inb(io_ports
->lbal_addr
);
177 if (cmd
->tf_flags
& IDE_TFLAG_IN_LBAM
)
178 tf
->lbam
= tf_inb(io_ports
->lbam_addr
);
179 if (cmd
->tf_flags
& IDE_TFLAG_IN_LBAH
)
180 tf
->lbah
= tf_inb(io_ports
->lbah_addr
);
181 if (cmd
->tf_flags
& IDE_TFLAG_IN_DEVICE
)
182 tf
->device
= tf_inb(io_ports
->device_addr
);
184 if (cmd
->tf_flags
& IDE_TFLAG_LBA48
) {
185 tf_outb(ATA_DEVCTL_OBS
| 0x80, io_ports
->ctl_addr
);
187 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_FEATURE
)
188 tf
->hob_feature
= tf_inb(io_ports
->feature_addr
);
189 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_NSECT
)
190 tf
->hob_nsect
= tf_inb(io_ports
->nsect_addr
);
191 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_LBAL
)
192 tf
->hob_lbal
= tf_inb(io_ports
->lbal_addr
);
193 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_LBAM
)
194 tf
->hob_lbam
= tf_inb(io_ports
->lbam_addr
);
195 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_LBAH
)
196 tf
->hob_lbah
= tf_inb(io_ports
->lbah_addr
);
199 EXPORT_SYMBOL_GPL(ide_tf_read
);
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.
208 static void ata_vlb_sync(unsigned long port
)
216 * This is used for most PIO data transfers *from* the IDE interface
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.
222 void ide_input_data(ide_drive_t
*drive
, struct request
*rq
, void *buf
,
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;
234 unsigned long uninitialized_var(flags
);
236 if ((io_32bit
& 2) && !mmio
) {
237 local_irq_save(flags
);
238 ata_vlb_sync(io_ports
->nsect_addr
);
242 __ide_mm_insl((void __iomem
*)data_addr
, buf
, len
/ 4);
244 insl(data_addr
, buf
, len
/ 4);
246 if ((io_32bit
& 2) && !mmio
)
247 local_irq_restore(flags
);
249 if ((len
& 3) >= 2) {
251 __ide_mm_insw((void __iomem
*)data_addr
,
252 (u8
*)buf
+ (len
& ~3), 1);
254 insw(data_addr
, (u8
*)buf
+ (len
& ~3), 1);
258 __ide_mm_insw((void __iomem
*)data_addr
, buf
, len
/ 2);
260 insw(data_addr
, buf
, len
/ 2);
263 EXPORT_SYMBOL_GPL(ide_input_data
);
266 * This is used for most PIO data transfers *to* the IDE interface
268 void ide_output_data(ide_drive_t
*drive
, struct request
*rq
, void *buf
,
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;
280 unsigned long uninitialized_var(flags
);
282 if ((io_32bit
& 2) && !mmio
) {
283 local_irq_save(flags
);
284 ata_vlb_sync(io_ports
->nsect_addr
);
288 __ide_mm_outsl((void __iomem
*)data_addr
, buf
, len
/ 4);
290 outsl(data_addr
, buf
, len
/ 4);
292 if ((io_32bit
& 2) && !mmio
)
293 local_irq_restore(flags
);
295 if ((len
& 3) >= 2) {
297 __ide_mm_outsw((void __iomem
*)data_addr
,
298 (u8
*)buf
+ (len
& ~3), 1);
300 outsw(data_addr
, (u8
*)buf
+ (len
& ~3), 1);
304 __ide_mm_outsw((void __iomem
*)data_addr
, buf
, len
/ 2);
306 outsw(data_addr
, buf
, len
/ 2);
309 EXPORT_SYMBOL_GPL(ide_output_data
);
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
,
316 .set_irq
= ide_set_irq
,
318 .tf_load
= ide_tf_load
,
319 .tf_read
= ide_tf_read
,
321 .input_data
= ide_input_data
,
322 .output_data
= ide_output_data
,