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_tf_load(ide_drive_t
*drive
, struct ide_cmd
*cmd
)
78 ide_hwif_t
*hwif
= drive
->hwif
;
79 struct ide_io_ports
*io_ports
= &hwif
->io_ports
;
80 struct ide_taskfile
*tf
= &cmd
->tf
;
81 void (*tf_outb
)(u8 addr
, unsigned long port
);
82 u8 mmio
= (hwif
->host_flags
& IDE_HFLAG_MMIO
) ? 1 : 0;
83 u8 HIHI
= (cmd
->tf_flags
& IDE_TFLAG_LBA48
) ? 0xE0 : 0xEF;
86 tf_outb
= ide_mm_outb
;
90 if (cmd
->ftf_flags
& IDE_FTFLAG_FLAGGED
)
93 if (cmd
->ftf_flags
& IDE_FTFLAG_OUT_DATA
) {
94 u16 data
= (tf
->hob_data
<< 8) | tf
->data
;
97 writew(data
, (void __iomem
*)io_ports
->data_addr
);
99 outw(data
, io_ports
->data_addr
);
102 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_FEATURE
)
103 tf_outb(tf
->hob_feature
, io_ports
->feature_addr
);
104 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_NSECT
)
105 tf_outb(tf
->hob_nsect
, io_ports
->nsect_addr
);
106 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_LBAL
)
107 tf_outb(tf
->hob_lbal
, io_ports
->lbal_addr
);
108 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_LBAM
)
109 tf_outb(tf
->hob_lbam
, io_ports
->lbam_addr
);
110 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_LBAH
)
111 tf_outb(tf
->hob_lbah
, io_ports
->lbah_addr
);
113 if (cmd
->tf_flags
& IDE_TFLAG_OUT_FEATURE
)
114 tf_outb(tf
->feature
, io_ports
->feature_addr
);
115 if (cmd
->tf_flags
& IDE_TFLAG_OUT_NSECT
)
116 tf_outb(tf
->nsect
, io_ports
->nsect_addr
);
117 if (cmd
->tf_flags
& IDE_TFLAG_OUT_LBAL
)
118 tf_outb(tf
->lbal
, io_ports
->lbal_addr
);
119 if (cmd
->tf_flags
& IDE_TFLAG_OUT_LBAM
)
120 tf_outb(tf
->lbam
, io_ports
->lbam_addr
);
121 if (cmd
->tf_flags
& IDE_TFLAG_OUT_LBAH
)
122 tf_outb(tf
->lbah
, io_ports
->lbah_addr
);
124 if (cmd
->tf_flags
& IDE_TFLAG_OUT_DEVICE
)
125 tf_outb((tf
->device
& HIHI
) | drive
->select
,
126 io_ports
->device_addr
);
128 EXPORT_SYMBOL_GPL(ide_tf_load
);
130 void ide_tf_read(ide_drive_t
*drive
, struct ide_cmd
*cmd
)
132 ide_hwif_t
*hwif
= drive
->hwif
;
133 struct ide_io_ports
*io_ports
= &hwif
->io_ports
;
134 struct ide_taskfile
*tf
= &cmd
->tf
;
135 void (*tf_outb
)(u8 addr
, unsigned long port
);
136 u8 (*tf_inb
)(unsigned long port
);
137 u8 mmio
= (hwif
->host_flags
& IDE_HFLAG_MMIO
) ? 1 : 0;
140 tf_outb
= ide_mm_outb
;
147 if (cmd
->ftf_flags
& IDE_FTFLAG_IN_DATA
) {
151 data
= readw((void __iomem
*)io_ports
->data_addr
);
153 data
= inw(io_ports
->data_addr
);
155 tf
->data
= data
& 0xff;
156 tf
->hob_data
= (data
>> 8) & 0xff;
159 /* be sure we're looking at the low order bits */
160 tf_outb(ATA_DEVCTL_OBS
, io_ports
->ctl_addr
);
162 if (cmd
->tf_flags
& IDE_TFLAG_IN_ERROR
)
163 tf
->error
= tf_inb(io_ports
->feature_addr
);
164 if (cmd
->tf_flags
& IDE_TFLAG_IN_NSECT
)
165 tf
->nsect
= tf_inb(io_ports
->nsect_addr
);
166 if (cmd
->tf_flags
& IDE_TFLAG_IN_LBAL
)
167 tf
->lbal
= tf_inb(io_ports
->lbal_addr
);
168 if (cmd
->tf_flags
& IDE_TFLAG_IN_LBAM
)
169 tf
->lbam
= tf_inb(io_ports
->lbam_addr
);
170 if (cmd
->tf_flags
& IDE_TFLAG_IN_LBAH
)
171 tf
->lbah
= tf_inb(io_ports
->lbah_addr
);
172 if (cmd
->tf_flags
& IDE_TFLAG_IN_DEVICE
)
173 tf
->device
= tf_inb(io_ports
->device_addr
);
175 if (cmd
->tf_flags
& IDE_TFLAG_LBA48
) {
176 tf_outb(ATA_HOB
| ATA_DEVCTL_OBS
, io_ports
->ctl_addr
);
178 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_ERROR
)
179 tf
->hob_error
= tf_inb(io_ports
->feature_addr
);
180 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_NSECT
)
181 tf
->hob_nsect
= tf_inb(io_ports
->nsect_addr
);
182 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_LBAL
)
183 tf
->hob_lbal
= tf_inb(io_ports
->lbal_addr
);
184 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_LBAM
)
185 tf
->hob_lbam
= tf_inb(io_ports
->lbam_addr
);
186 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_LBAH
)
187 tf
->hob_lbah
= tf_inb(io_ports
->lbah_addr
);
190 EXPORT_SYMBOL_GPL(ide_tf_read
);
193 * Some localbus EIDE interfaces require a special access sequence
194 * when using 32-bit I/O instructions to transfer data. We call this
195 * the "vlb_sync" sequence, which consists of three successive reads
196 * of the sector count register location, with interrupts disabled
197 * to ensure that the reads all happen together.
199 static void ata_vlb_sync(unsigned long port
)
207 * This is used for most PIO data transfers *from* the IDE interface
209 * These routines will round up any request for an odd number of bytes,
210 * so if an odd len is specified, be sure that there's at least one
211 * extra byte allocated for the buffer.
213 void ide_input_data(ide_drive_t
*drive
, struct ide_cmd
*cmd
, void *buf
,
216 ide_hwif_t
*hwif
= drive
->hwif
;
217 struct ide_io_ports
*io_ports
= &hwif
->io_ports
;
218 unsigned long data_addr
= io_ports
->data_addr
;
219 unsigned int words
= (len
+ 1) >> 1;
220 u8 io_32bit
= drive
->io_32bit
;
221 u8 mmio
= (hwif
->host_flags
& IDE_HFLAG_MMIO
) ? 1 : 0;
224 unsigned long uninitialized_var(flags
);
226 if ((io_32bit
& 2) && !mmio
) {
227 local_irq_save(flags
);
228 ata_vlb_sync(io_ports
->nsect_addr
);
233 __ide_mm_insl((void __iomem
*)data_addr
, buf
, words
);
235 insl(data_addr
, buf
, words
);
237 if ((io_32bit
& 2) && !mmio
)
238 local_irq_restore(flags
);
240 if (((len
+ 1) & 3) < 2)
248 __ide_mm_insw((void __iomem
*)data_addr
, buf
, words
);
250 insw(data_addr
, buf
, words
);
252 EXPORT_SYMBOL_GPL(ide_input_data
);
255 * This is used for most PIO data transfers *to* the IDE interface
257 void ide_output_data(ide_drive_t
*drive
, struct ide_cmd
*cmd
, void *buf
,
260 ide_hwif_t
*hwif
= drive
->hwif
;
261 struct ide_io_ports
*io_ports
= &hwif
->io_ports
;
262 unsigned long data_addr
= io_ports
->data_addr
;
263 unsigned int words
= (len
+ 1) >> 1;
264 u8 io_32bit
= drive
->io_32bit
;
265 u8 mmio
= (hwif
->host_flags
& IDE_HFLAG_MMIO
) ? 1 : 0;
268 unsigned long uninitialized_var(flags
);
270 if ((io_32bit
& 2) && !mmio
) {
271 local_irq_save(flags
);
272 ata_vlb_sync(io_ports
->nsect_addr
);
277 __ide_mm_outsl((void __iomem
*)data_addr
, buf
, words
);
279 outsl(data_addr
, buf
, words
);
281 if ((io_32bit
& 2) && !mmio
)
282 local_irq_restore(flags
);
284 if (((len
+ 1) & 3) < 2)
292 __ide_mm_outsw((void __iomem
*)data_addr
, buf
, words
);
294 outsw(data_addr
, buf
, words
);
296 EXPORT_SYMBOL_GPL(ide_output_data
);
298 const struct ide_tp_ops default_tp_ops
= {
299 .exec_command
= ide_exec_command
,
300 .read_status
= ide_read_status
,
301 .read_altstatus
= ide_read_altstatus
,
302 .write_devctl
= ide_write_devctl
,
304 .tf_load
= ide_tf_load
,
305 .tf_read
= ide_tf_read
,
307 .input_data
= ide_input_data
,
308 .output_data
= ide_output_data
,