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_cmd
*cmd
)
90 ide_hwif_t
*hwif
= drive
->hwif
;
91 struct ide_io_ports
*io_ports
= &hwif
->io_ports
;
92 struct ide_taskfile
*tf
= &cmd
->tf
;
93 void (*tf_outb
)(u8 addr
, unsigned long port
);
94 u8 valid
= cmd
->valid
.out
.hob
;
95 u8 mmio
= (hwif
->host_flags
& IDE_HFLAG_MMIO
) ? 1 : 0;
96 u8 HIHI
= (cmd
->tf_flags
& IDE_TFLAG_LBA48
) ? 0xE0 : 0xEF;
99 tf_outb
= ide_mm_outb
;
103 if (cmd
->ftf_flags
& IDE_FTFLAG_FLAGGED
)
106 if (valid
& IDE_VALID_FEATURE
)
107 tf_outb(tf
->hob_feature
, io_ports
->feature_addr
);
108 if (valid
& IDE_VALID_NSECT
)
109 tf_outb(tf
->hob_nsect
, io_ports
->nsect_addr
);
110 if (valid
& IDE_VALID_LBAL
)
111 tf_outb(tf
->hob_lbal
, io_ports
->lbal_addr
);
112 if (valid
& IDE_VALID_LBAM
)
113 tf_outb(tf
->hob_lbam
, io_ports
->lbam_addr
);
114 if (valid
& IDE_VALID_LBAH
)
115 tf_outb(tf
->hob_lbah
, io_ports
->lbah_addr
);
117 valid
= cmd
->valid
.out
.tf
;
119 if (valid
& IDE_VALID_FEATURE
)
120 tf_outb(tf
->feature
, io_ports
->feature_addr
);
121 if (valid
& IDE_VALID_NSECT
)
122 tf_outb(tf
->nsect
, io_ports
->nsect_addr
);
123 if (valid
& IDE_VALID_LBAL
)
124 tf_outb(tf
->lbal
, io_ports
->lbal_addr
);
125 if (valid
& IDE_VALID_LBAM
)
126 tf_outb(tf
->lbam
, io_ports
->lbam_addr
);
127 if (valid
& IDE_VALID_LBAH
)
128 tf_outb(tf
->lbah
, io_ports
->lbah_addr
);
130 if (valid
& IDE_VALID_DEVICE
)
131 tf_outb((tf
->device
& HIHI
) | drive
->select
,
132 io_ports
->device_addr
);
134 EXPORT_SYMBOL_GPL(ide_tf_load
);
136 void ide_tf_read(ide_drive_t
*drive
, struct ide_cmd
*cmd
)
138 ide_hwif_t
*hwif
= drive
->hwif
;
139 struct ide_io_ports
*io_ports
= &hwif
->io_ports
;
140 struct ide_taskfile
*tf
= &cmd
->tf
;
141 void (*tf_outb
)(u8 addr
, unsigned long port
);
142 u8 (*tf_inb
)(unsigned long port
);
143 u8 valid
= cmd
->valid
.in
.tf
;
144 u8 mmio
= (hwif
->host_flags
& IDE_HFLAG_MMIO
) ? 1 : 0;
147 tf_outb
= ide_mm_outb
;
154 /* be sure we're looking at the low order bits */
155 tf_outb(ATA_DEVCTL_OBS
, io_ports
->ctl_addr
);
157 if (valid
& IDE_VALID_ERROR
)
158 tf
->error
= tf_inb(io_ports
->feature_addr
);
159 if (valid
& IDE_VALID_NSECT
)
160 tf
->nsect
= tf_inb(io_ports
->nsect_addr
);
161 if (valid
& IDE_VALID_LBAL
)
162 tf
->lbal
= tf_inb(io_ports
->lbal_addr
);
163 if (valid
& IDE_VALID_LBAM
)
164 tf
->lbam
= tf_inb(io_ports
->lbam_addr
);
165 if (valid
& IDE_VALID_LBAH
)
166 tf
->lbah
= tf_inb(io_ports
->lbah_addr
);
167 if (valid
& IDE_VALID_DEVICE
)
168 tf
->device
= tf_inb(io_ports
->device_addr
);
170 if (cmd
->tf_flags
& IDE_TFLAG_LBA48
) {
171 tf_outb(ATA_HOB
| ATA_DEVCTL_OBS
, io_ports
->ctl_addr
);
173 valid
= cmd
->valid
.in
.hob
;
175 if (valid
& IDE_VALID_ERROR
)
176 tf
->hob_error
= tf_inb(io_ports
->feature_addr
);
177 if (valid
& IDE_VALID_NSECT
)
178 tf
->hob_nsect
= tf_inb(io_ports
->nsect_addr
);
179 if (valid
& IDE_VALID_LBAL
)
180 tf
->hob_lbal
= tf_inb(io_ports
->lbal_addr
);
181 if (valid
& IDE_VALID_LBAM
)
182 tf
->hob_lbam
= tf_inb(io_ports
->lbam_addr
);
183 if (valid
& IDE_VALID_LBAH
)
184 tf
->hob_lbah
= tf_inb(io_ports
->lbah_addr
);
187 EXPORT_SYMBOL_GPL(ide_tf_read
);
190 * Some localbus EIDE interfaces require a special access sequence
191 * when using 32-bit I/O instructions to transfer data. We call this
192 * the "vlb_sync" sequence, which consists of three successive reads
193 * of the sector count register location, with interrupts disabled
194 * to ensure that the reads all happen together.
196 static void ata_vlb_sync(unsigned long port
)
204 * This is used for most PIO data transfers *from* the IDE interface
206 * These routines will round up any request for an odd number of bytes,
207 * so if an odd len is specified, be sure that there's at least one
208 * extra byte allocated for the buffer.
210 void ide_input_data(ide_drive_t
*drive
, struct ide_cmd
*cmd
, void *buf
,
213 ide_hwif_t
*hwif
= drive
->hwif
;
214 struct ide_io_ports
*io_ports
= &hwif
->io_ports
;
215 unsigned long data_addr
= io_ports
->data_addr
;
216 unsigned int words
= (len
+ 1) >> 1;
217 u8 io_32bit
= drive
->io_32bit
;
218 u8 mmio
= (hwif
->host_flags
& IDE_HFLAG_MMIO
) ? 1 : 0;
221 unsigned long uninitialized_var(flags
);
223 if ((io_32bit
& 2) && !mmio
) {
224 local_irq_save(flags
);
225 ata_vlb_sync(io_ports
->nsect_addr
);
230 __ide_mm_insl((void __iomem
*)data_addr
, buf
, words
);
232 insl(data_addr
, buf
, words
);
234 if ((io_32bit
& 2) && !mmio
)
235 local_irq_restore(flags
);
237 if (((len
+ 1) & 3) < 2)
245 __ide_mm_insw((void __iomem
*)data_addr
, buf
, words
);
247 insw(data_addr
, buf
, words
);
249 EXPORT_SYMBOL_GPL(ide_input_data
);
252 * This is used for most PIO data transfers *to* the IDE interface
254 void ide_output_data(ide_drive_t
*drive
, struct ide_cmd
*cmd
, void *buf
,
257 ide_hwif_t
*hwif
= drive
->hwif
;
258 struct ide_io_ports
*io_ports
= &hwif
->io_ports
;
259 unsigned long data_addr
= io_ports
->data_addr
;
260 unsigned int words
= (len
+ 1) >> 1;
261 u8 io_32bit
= drive
->io_32bit
;
262 u8 mmio
= (hwif
->host_flags
& IDE_HFLAG_MMIO
) ? 1 : 0;
265 unsigned long uninitialized_var(flags
);
267 if ((io_32bit
& 2) && !mmio
) {
268 local_irq_save(flags
);
269 ata_vlb_sync(io_ports
->nsect_addr
);
274 __ide_mm_outsl((void __iomem
*)data_addr
, buf
, words
);
276 outsl(data_addr
, buf
, words
);
278 if ((io_32bit
& 2) && !mmio
)
279 local_irq_restore(flags
);
281 if (((len
+ 1) & 3) < 2)
289 __ide_mm_outsw((void __iomem
*)data_addr
, buf
, words
);
291 outsw(data_addr
, buf
, words
);
293 EXPORT_SYMBOL_GPL(ide_output_data
);
295 const struct ide_tp_ops default_tp_ops
= {
296 .exec_command
= ide_exec_command
,
297 .read_status
= ide_read_status
,
298 .read_altstatus
= ide_read_altstatus
,
299 .write_devctl
= ide_write_devctl
,
301 .dev_select
= ide_dev_select
,
302 .tf_load
= ide_tf_load
,
303 .tf_read
= ide_tf_read
,
305 .input_data
= ide_input_data
,
306 .output_data
= ide_output_data
,