ide: replace IDE_TFLAG_* flags by IDE_VALID_*
[deliverable/linux.git] / drivers / ide / ide-io-std.c
CommitLineData
1574cf6c
BZ
1
2#include <linux/kernel.h>
3#include <linux/ide.h>
4
15a453a9
BZ
5#if defined(CONFIG_ARM) || defined(CONFIG_M68K) || defined(CONFIG_MIPS) || \
6 defined(CONFIG_PARISC) || defined(CONFIG_PPC) || defined(CONFIG_SPARC)
7#include <asm/ide.h>
8#else
9#include <asm-generic/ide_iops.h>
10#endif
11
1574cf6c
BZ
12/*
13 * Conventional PIO operations for ATA devices
14 */
15
16static u8 ide_inb(unsigned long port)
17{
18 return (u8) inb(port);
19}
20
21static void ide_outb(u8 val, unsigned long port)
22{
23 outb(val, port);
24}
25
26/*
27 * MMIO operations, typically used for SATA controllers
28 */
29
30static u8 ide_mm_inb(unsigned long port)
31{
32 return (u8) readb((void __iomem *) port);
33}
34
35static void ide_mm_outb(u8 value, unsigned long port)
36{
37 writeb(value, (void __iomem *) port);
38}
39
40void ide_exec_command(ide_hwif_t *hwif, u8 cmd)
41{
42 if (hwif->host_flags & IDE_HFLAG_MMIO)
43 writeb(cmd, (void __iomem *)hwif->io_ports.command_addr);
44 else
45 outb(cmd, hwif->io_ports.command_addr);
46}
47EXPORT_SYMBOL_GPL(ide_exec_command);
48
49u8 ide_read_status(ide_hwif_t *hwif)
50{
51 if (hwif->host_flags & IDE_HFLAG_MMIO)
52 return readb((void __iomem *)hwif->io_ports.status_addr);
53 else
54 return inb(hwif->io_ports.status_addr);
55}
56EXPORT_SYMBOL_GPL(ide_read_status);
57
58u8 ide_read_altstatus(ide_hwif_t *hwif)
59{
60 if (hwif->host_flags & IDE_HFLAG_MMIO)
61 return readb((void __iomem *)hwif->io_ports.ctl_addr);
62 else
63 return inb(hwif->io_ports.ctl_addr);
64}
65EXPORT_SYMBOL_GPL(ide_read_altstatus);
66
ecf3a31d 67void ide_write_devctl(ide_hwif_t *hwif, u8 ctl)
1574cf6c 68{
1574cf6c
BZ
69 if (hwif->host_flags & IDE_HFLAG_MMIO)
70 writeb(ctl, (void __iomem *)hwif->io_ports.ctl_addr);
71 else
72 outb(ctl, hwif->io_ports.ctl_addr);
73}
ecf3a31d 74EXPORT_SYMBOL_GPL(ide_write_devctl);
1574cf6c 75
abb596b2
SS
76void ide_dev_select(ide_drive_t *drive)
77{
78 ide_hwif_t *hwif = drive->hwif;
79 u8 select = drive->select | ATA_DEVICE_OBS;
80
81 if (hwif->host_flags & IDE_HFLAG_MMIO)
82 writeb(select, (void __iomem *)hwif->io_ports.device_addr);
83 else
84 outb(select, hwif->io_ports.device_addr);
85}
86EXPORT_SYMBOL_GPL(ide_dev_select);
87
22aa4b32 88void ide_tf_load(ide_drive_t *drive, struct ide_cmd *cmd)
1574cf6c
BZ
89{
90 ide_hwif_t *hwif = drive->hwif;
91 struct ide_io_ports *io_ports = &hwif->io_ports;
22aa4b32 92 struct ide_taskfile *tf = &cmd->tf;
1574cf6c 93 void (*tf_outb)(u8 addr, unsigned long port);
60f85019 94 u8 valid = cmd->valid.out.hob;
1574cf6c 95 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
22aa4b32 96 u8 HIHI = (cmd->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF;
1574cf6c
BZ
97
98 if (mmio)
99 tf_outb = ide_mm_outb;
100 else
101 tf_outb = ide_outb;
102
22aa4b32 103 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED)
1574cf6c
BZ
104 HIHI = 0xFF;
105
60f85019 106 if (valid & IDE_VALID_FEATURE)
1574cf6c 107 tf_outb(tf->hob_feature, io_ports->feature_addr);
60f85019 108 if (valid & IDE_VALID_NSECT)
1574cf6c 109 tf_outb(tf->hob_nsect, io_ports->nsect_addr);
60f85019 110 if (valid & IDE_VALID_LBAL)
1574cf6c 111 tf_outb(tf->hob_lbal, io_ports->lbal_addr);
60f85019 112 if (valid & IDE_VALID_LBAM)
1574cf6c 113 tf_outb(tf->hob_lbam, io_ports->lbam_addr);
60f85019 114 if (valid & IDE_VALID_LBAH)
1574cf6c
BZ
115 tf_outb(tf->hob_lbah, io_ports->lbah_addr);
116
60f85019
SS
117 valid = cmd->valid.out.tf;
118
119 if (valid & IDE_VALID_FEATURE)
1574cf6c 120 tf_outb(tf->feature, io_ports->feature_addr);
60f85019 121 if (valid & IDE_VALID_NSECT)
1574cf6c 122 tf_outb(tf->nsect, io_ports->nsect_addr);
60f85019 123 if (valid & IDE_VALID_LBAL)
1574cf6c 124 tf_outb(tf->lbal, io_ports->lbal_addr);
60f85019 125 if (valid & IDE_VALID_LBAM)
1574cf6c 126 tf_outb(tf->lbam, io_ports->lbam_addr);
60f85019 127 if (valid & IDE_VALID_LBAH)
1574cf6c
BZ
128 tf_outb(tf->lbah, io_ports->lbah_addr);
129
60f85019 130 if (valid & IDE_VALID_DEVICE)
1574cf6c
BZ
131 tf_outb((tf->device & HIHI) | drive->select,
132 io_ports->device_addr);
133}
134EXPORT_SYMBOL_GPL(ide_tf_load);
135
22aa4b32 136void ide_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
1574cf6c
BZ
137{
138 ide_hwif_t *hwif = drive->hwif;
139 struct ide_io_ports *io_ports = &hwif->io_ports;
22aa4b32 140 struct ide_taskfile *tf = &cmd->tf;
1574cf6c
BZ
141 void (*tf_outb)(u8 addr, unsigned long port);
142 u8 (*tf_inb)(unsigned long port);
60f85019 143 u8 valid = cmd->valid.in.tf;
1574cf6c
BZ
144 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
145
146 if (mmio) {
147 tf_outb = ide_mm_outb;
148 tf_inb = ide_mm_inb;
149 } else {
150 tf_outb = ide_outb;
151 tf_inb = ide_inb;
152 }
153
1574cf6c 154 /* be sure we're looking at the low order bits */
4d74c3fc 155 tf_outb(ATA_DEVCTL_OBS, io_ports->ctl_addr);
1574cf6c 156
60f85019 157 if (valid & IDE_VALID_ERROR)
67625119 158 tf->error = tf_inb(io_ports->feature_addr);
60f85019 159 if (valid & IDE_VALID_NSECT)
1574cf6c 160 tf->nsect = tf_inb(io_ports->nsect_addr);
60f85019 161 if (valid & IDE_VALID_LBAL)
1574cf6c 162 tf->lbal = tf_inb(io_ports->lbal_addr);
60f85019 163 if (valid & IDE_VALID_LBAM)
1574cf6c 164 tf->lbam = tf_inb(io_ports->lbam_addr);
60f85019 165 if (valid & IDE_VALID_LBAH)
1574cf6c 166 tf->lbah = tf_inb(io_ports->lbah_addr);
60f85019 167 if (valid & IDE_VALID_DEVICE)
1574cf6c
BZ
168 tf->device = tf_inb(io_ports->device_addr);
169
22aa4b32 170 if (cmd->tf_flags & IDE_TFLAG_LBA48) {
4d74c3fc 171 tf_outb(ATA_HOB | ATA_DEVCTL_OBS, io_ports->ctl_addr);
1574cf6c 172
60f85019
SS
173 valid = cmd->valid.in.hob;
174
175 if (valid & IDE_VALID_ERROR)
67625119 176 tf->hob_error = tf_inb(io_ports->feature_addr);
60f85019 177 if (valid & IDE_VALID_NSECT)
67625119 178 tf->hob_nsect = tf_inb(io_ports->nsect_addr);
60f85019 179 if (valid & IDE_VALID_LBAL)
67625119 180 tf->hob_lbal = tf_inb(io_ports->lbal_addr);
60f85019 181 if (valid & IDE_VALID_LBAM)
67625119 182 tf->hob_lbam = tf_inb(io_ports->lbam_addr);
60f85019 183 if (valid & IDE_VALID_LBAH)
67625119 184 tf->hob_lbah = tf_inb(io_ports->lbah_addr);
1574cf6c
BZ
185 }
186}
187EXPORT_SYMBOL_GPL(ide_tf_read);
188
189/*
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.
195 */
196static void ata_vlb_sync(unsigned long port)
197{
198 (void)inb(port);
199 (void)inb(port);
200 (void)inb(port);
201}
202
203/*
204 * This is used for most PIO data transfers *from* the IDE interface
205 *
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.
209 */
adb1af98 210void ide_input_data(ide_drive_t *drive, struct ide_cmd *cmd, void *buf,
1574cf6c
BZ
211 unsigned int len)
212{
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;
deae17fd 216 unsigned int words = (len + 1) >> 1;
1574cf6c
BZ
217 u8 io_32bit = drive->io_32bit;
218 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
219
1574cf6c
BZ
220 if (io_32bit) {
221 unsigned long uninitialized_var(flags);
222
223 if ((io_32bit & 2) && !mmio) {
224 local_irq_save(flags);
225 ata_vlb_sync(io_ports->nsect_addr);
226 }
227
deae17fd 228 words >>= 1;
1574cf6c 229 if (mmio)
deae17fd 230 __ide_mm_insl((void __iomem *)data_addr, buf, words);
1574cf6c 231 else
deae17fd 232 insl(data_addr, buf, words);
1574cf6c
BZ
233
234 if ((io_32bit & 2) && !mmio)
235 local_irq_restore(flags);
236
deae17fd
SS
237 if (((len + 1) & 3) < 2)
238 return;
239
240 buf += len & ~3;
241 words = 1;
1574cf6c 242 }
deae17fd
SS
243
244 if (mmio)
245 __ide_mm_insw((void __iomem *)data_addr, buf, words);
246 else
247 insw(data_addr, buf, words);
1574cf6c
BZ
248}
249EXPORT_SYMBOL_GPL(ide_input_data);
250
251/*
252 * This is used for most PIO data transfers *to* the IDE interface
253 */
adb1af98 254void ide_output_data(ide_drive_t *drive, struct ide_cmd *cmd, void *buf,
1574cf6c
BZ
255 unsigned int len)
256{
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;
deae17fd 260 unsigned int words = (len + 1) >> 1;
1574cf6c
BZ
261 u8 io_32bit = drive->io_32bit;
262 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
263
1574cf6c
BZ
264 if (io_32bit) {
265 unsigned long uninitialized_var(flags);
266
267 if ((io_32bit & 2) && !mmio) {
268 local_irq_save(flags);
269 ata_vlb_sync(io_ports->nsect_addr);
270 }
271
deae17fd 272 words >>= 1;
1574cf6c 273 if (mmio)
deae17fd 274 __ide_mm_outsl((void __iomem *)data_addr, buf, words);
1574cf6c 275 else
deae17fd 276 outsl(data_addr, buf, words);
1574cf6c
BZ
277
278 if ((io_32bit & 2) && !mmio)
279 local_irq_restore(flags);
280
deae17fd
SS
281 if (((len + 1) & 3) < 2)
282 return;
283
284 buf += len & ~3;
285 words = 1;
1574cf6c 286 }
deae17fd
SS
287
288 if (mmio)
289 __ide_mm_outsw((void __iomem *)data_addr, buf, words);
290 else
291 outsw(data_addr, buf, words);
1574cf6c
BZ
292}
293EXPORT_SYMBOL_GPL(ide_output_data);
294
295const 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,
ecf3a31d 299 .write_devctl = ide_write_devctl,
1574cf6c 300
abb596b2 301 .dev_select = ide_dev_select,
1574cf6c
BZ
302 .tf_load = ide_tf_load,
303 .tf_read = ide_tf_read,
304
305 .input_data = ide_input_data,
306 .output_data = ide_output_data,
307};
This page took 0.053294 seconds and 5 git commands to generate.