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 u8 data
[2] = { tf
->data
, tf
->hob_data
};
96 ide_output_data(drive
, cmd
, data
, 2);
99 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_FEATURE
)
100 tf_outb(tf
->hob_feature
, io_ports
->feature_addr
);
101 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_NSECT
)
102 tf_outb(tf
->hob_nsect
, io_ports
->nsect_addr
);
103 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_LBAL
)
104 tf_outb(tf
->hob_lbal
, io_ports
->lbal_addr
);
105 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_LBAM
)
106 tf_outb(tf
->hob_lbam
, io_ports
->lbam_addr
);
107 if (cmd
->tf_flags
& IDE_TFLAG_OUT_HOB_LBAH
)
108 tf_outb(tf
->hob_lbah
, io_ports
->lbah_addr
);
110 if (cmd
->tf_flags
& IDE_TFLAG_OUT_FEATURE
)
111 tf_outb(tf
->feature
, io_ports
->feature_addr
);
112 if (cmd
->tf_flags
& IDE_TFLAG_OUT_NSECT
)
113 tf_outb(tf
->nsect
, io_ports
->nsect_addr
);
114 if (cmd
->tf_flags
& IDE_TFLAG_OUT_LBAL
)
115 tf_outb(tf
->lbal
, io_ports
->lbal_addr
);
116 if (cmd
->tf_flags
& IDE_TFLAG_OUT_LBAM
)
117 tf_outb(tf
->lbam
, io_ports
->lbam_addr
);
118 if (cmd
->tf_flags
& IDE_TFLAG_OUT_LBAH
)
119 tf_outb(tf
->lbah
, io_ports
->lbah_addr
);
121 if (cmd
->tf_flags
& IDE_TFLAG_OUT_DEVICE
)
122 tf_outb((tf
->device
& HIHI
) | drive
->select
,
123 io_ports
->device_addr
);
125 EXPORT_SYMBOL_GPL(ide_tf_load
);
127 void ide_tf_read(ide_drive_t
*drive
, struct ide_cmd
*cmd
)
129 ide_hwif_t
*hwif
= drive
->hwif
;
130 struct ide_io_ports
*io_ports
= &hwif
->io_ports
;
131 struct ide_taskfile
*tf
= &cmd
->tf
;
132 void (*tf_outb
)(u8 addr
, unsigned long port
);
133 u8 (*tf_inb
)(unsigned long port
);
134 u8 mmio
= (hwif
->host_flags
& IDE_HFLAG_MMIO
) ? 1 : 0;
137 tf_outb
= ide_mm_outb
;
144 if (cmd
->ftf_flags
& IDE_FTFLAG_IN_DATA
) {
147 ide_input_data(drive
, cmd
, data
, 2);
150 tf
->hob_data
= data
[1];
153 /* be sure we're looking at the low order bits */
154 tf_outb(ATA_DEVCTL_OBS
, io_ports
->ctl_addr
);
156 if (cmd
->tf_flags
& IDE_TFLAG_IN_ERROR
)
157 tf
->error
= tf_inb(io_ports
->feature_addr
);
158 if (cmd
->tf_flags
& IDE_TFLAG_IN_NSECT
)
159 tf
->nsect
= tf_inb(io_ports
->nsect_addr
);
160 if (cmd
->tf_flags
& IDE_TFLAG_IN_LBAL
)
161 tf
->lbal
= tf_inb(io_ports
->lbal_addr
);
162 if (cmd
->tf_flags
& IDE_TFLAG_IN_LBAM
)
163 tf
->lbam
= tf_inb(io_ports
->lbam_addr
);
164 if (cmd
->tf_flags
& IDE_TFLAG_IN_LBAH
)
165 tf
->lbah
= tf_inb(io_ports
->lbah_addr
);
166 if (cmd
->tf_flags
& IDE_TFLAG_IN_DEVICE
)
167 tf
->device
= tf_inb(io_ports
->device_addr
);
169 if (cmd
->tf_flags
& IDE_TFLAG_LBA48
) {
170 tf_outb(ATA_HOB
| ATA_DEVCTL_OBS
, io_ports
->ctl_addr
);
172 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_ERROR
)
173 tf
->hob_error
= tf_inb(io_ports
->feature_addr
);
174 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_NSECT
)
175 tf
->hob_nsect
= tf_inb(io_ports
->nsect_addr
);
176 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_LBAL
)
177 tf
->hob_lbal
= tf_inb(io_ports
->lbal_addr
);
178 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_LBAM
)
179 tf
->hob_lbam
= tf_inb(io_ports
->lbam_addr
);
180 if (cmd
->tf_flags
& IDE_TFLAG_IN_HOB_LBAH
)
181 tf
->hob_lbah
= tf_inb(io_ports
->lbah_addr
);
184 EXPORT_SYMBOL_GPL(ide_tf_read
);
187 * Some localbus EIDE interfaces require a special access sequence
188 * when using 32-bit I/O instructions to transfer data. We call this
189 * the "vlb_sync" sequence, which consists of three successive reads
190 * of the sector count register location, with interrupts disabled
191 * to ensure that the reads all happen together.
193 static void ata_vlb_sync(unsigned long port
)
201 * This is used for most PIO data transfers *from* the IDE interface
203 * These routines will round up any request for an odd number of bytes,
204 * so if an odd len is specified, be sure that there's at least one
205 * extra byte allocated for the buffer.
207 void ide_input_data(ide_drive_t
*drive
, struct ide_cmd
*cmd
, void *buf
,
210 ide_hwif_t
*hwif
= drive
->hwif
;
211 struct ide_io_ports
*io_ports
= &hwif
->io_ports
;
212 unsigned long data_addr
= io_ports
->data_addr
;
213 unsigned int words
= (len
+ 1) >> 1;
214 u8 io_32bit
= drive
->io_32bit
;
215 u8 mmio
= (hwif
->host_flags
& IDE_HFLAG_MMIO
) ? 1 : 0;
218 unsigned long uninitialized_var(flags
);
220 if ((io_32bit
& 2) && !mmio
) {
221 local_irq_save(flags
);
222 ata_vlb_sync(io_ports
->nsect_addr
);
227 __ide_mm_insl((void __iomem
*)data_addr
, buf
, words
);
229 insl(data_addr
, buf
, words
);
231 if ((io_32bit
& 2) && !mmio
)
232 local_irq_restore(flags
);
234 if (((len
+ 1) & 3) < 2)
242 __ide_mm_insw((void __iomem
*)data_addr
, buf
, words
);
244 insw(data_addr
, buf
, words
);
246 EXPORT_SYMBOL_GPL(ide_input_data
);
249 * This is used for most PIO data transfers *to* the IDE interface
251 void ide_output_data(ide_drive_t
*drive
, struct ide_cmd
*cmd
, void *buf
,
254 ide_hwif_t
*hwif
= drive
->hwif
;
255 struct ide_io_ports
*io_ports
= &hwif
->io_ports
;
256 unsigned long data_addr
= io_ports
->data_addr
;
257 unsigned int words
= (len
+ 1) >> 1;
258 u8 io_32bit
= drive
->io_32bit
;
259 u8 mmio
= (hwif
->host_flags
& IDE_HFLAG_MMIO
) ? 1 : 0;
262 unsigned long uninitialized_var(flags
);
264 if ((io_32bit
& 2) && !mmio
) {
265 local_irq_save(flags
);
266 ata_vlb_sync(io_ports
->nsect_addr
);
271 __ide_mm_outsl((void __iomem
*)data_addr
, buf
, words
);
273 outsl(data_addr
, buf
, words
);
275 if ((io_32bit
& 2) && !mmio
)
276 local_irq_restore(flags
);
278 if (((len
+ 1) & 3) < 2)
286 __ide_mm_outsw((void __iomem
*)data_addr
, buf
, words
);
288 outsw(data_addr
, buf
, words
);
290 EXPORT_SYMBOL_GPL(ide_output_data
);
292 const struct ide_tp_ops default_tp_ops
= {
293 .exec_command
= ide_exec_command
,
294 .read_status
= ide_read_status
,
295 .read_altstatus
= ide_read_altstatus
,
296 .write_devctl
= ide_write_devctl
,
298 .tf_load
= ide_tf_load
,
299 .tf_read
= ide_tf_read
,
301 .input_data
= ide_input_data
,
302 .output_data
= ide_output_data
,