Commit | Line | Data |
---|---|---|
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 | ||
16 | static u8 ide_inb(unsigned long port) | |
17 | { | |
18 | return (u8) inb(port); | |
19 | } | |
20 | ||
21 | static 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 | ||
30 | static u8 ide_mm_inb(unsigned long port) | |
31 | { | |
32 | return (u8) readb((void __iomem *) port); | |
33 | } | |
34 | ||
35 | static void ide_mm_outb(u8 value, unsigned long port) | |
36 | { | |
37 | writeb(value, (void __iomem *) port); | |
38 | } | |
39 | ||
40 | void 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 | } | |
47 | EXPORT_SYMBOL_GPL(ide_exec_command); | |
48 | ||
49 | u8 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 | } | |
56 | EXPORT_SYMBOL_GPL(ide_read_status); | |
57 | ||
58 | u8 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 | } | |
65 | EXPORT_SYMBOL_GPL(ide_read_altstatus); | |
66 | ||
ecf3a31d | 67 | void 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 | 74 | EXPORT_SYMBOL_GPL(ide_write_devctl); |
1574cf6c | 75 | |
abb596b2 SS |
76 | void 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 | } | |
86 | EXPORT_SYMBOL_GPL(ide_dev_select); | |
87 | ||
22aa4b32 | 88 | void 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 BZ |
93 | void (*tf_outb)(u8 addr, unsigned long port); |
94 | u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; | |
22aa4b32 | 95 | u8 HIHI = (cmd->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF; |
1574cf6c BZ |
96 | |
97 | if (mmio) | |
98 | tf_outb = ide_mm_outb; | |
99 | else | |
100 | tf_outb = ide_outb; | |
101 | ||
22aa4b32 | 102 | if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED) |
1574cf6c BZ |
103 | HIHI = 0xFF; |
104 | ||
22aa4b32 | 105 | if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE) |
1574cf6c | 106 | tf_outb(tf->hob_feature, io_ports->feature_addr); |
22aa4b32 | 107 | if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT) |
1574cf6c | 108 | tf_outb(tf->hob_nsect, io_ports->nsect_addr); |
22aa4b32 | 109 | if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAL) |
1574cf6c | 110 | tf_outb(tf->hob_lbal, io_ports->lbal_addr); |
22aa4b32 | 111 | if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAM) |
1574cf6c | 112 | tf_outb(tf->hob_lbam, io_ports->lbam_addr); |
22aa4b32 | 113 | if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAH) |
1574cf6c BZ |
114 | tf_outb(tf->hob_lbah, io_ports->lbah_addr); |
115 | ||
22aa4b32 | 116 | if (cmd->tf_flags & IDE_TFLAG_OUT_FEATURE) |
1574cf6c | 117 | tf_outb(tf->feature, io_ports->feature_addr); |
22aa4b32 | 118 | if (cmd->tf_flags & IDE_TFLAG_OUT_NSECT) |
1574cf6c | 119 | tf_outb(tf->nsect, io_ports->nsect_addr); |
22aa4b32 | 120 | if (cmd->tf_flags & IDE_TFLAG_OUT_LBAL) |
1574cf6c | 121 | tf_outb(tf->lbal, io_ports->lbal_addr); |
22aa4b32 | 122 | if (cmd->tf_flags & IDE_TFLAG_OUT_LBAM) |
1574cf6c | 123 | tf_outb(tf->lbam, io_ports->lbam_addr); |
22aa4b32 | 124 | if (cmd->tf_flags & IDE_TFLAG_OUT_LBAH) |
1574cf6c BZ |
125 | tf_outb(tf->lbah, io_ports->lbah_addr); |
126 | ||
22aa4b32 | 127 | if (cmd->tf_flags & IDE_TFLAG_OUT_DEVICE) |
1574cf6c BZ |
128 | tf_outb((tf->device & HIHI) | drive->select, |
129 | io_ports->device_addr); | |
130 | } | |
131 | EXPORT_SYMBOL_GPL(ide_tf_load); | |
132 | ||
22aa4b32 | 133 | void ide_tf_read(ide_drive_t *drive, struct ide_cmd *cmd) |
1574cf6c BZ |
134 | { |
135 | ide_hwif_t *hwif = drive->hwif; | |
136 | struct ide_io_ports *io_ports = &hwif->io_ports; | |
22aa4b32 | 137 | struct ide_taskfile *tf = &cmd->tf; |
1574cf6c BZ |
138 | void (*tf_outb)(u8 addr, unsigned long port); |
139 | u8 (*tf_inb)(unsigned long port); | |
140 | u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; | |
141 | ||
142 | if (mmio) { | |
143 | tf_outb = ide_mm_outb; | |
144 | tf_inb = ide_mm_inb; | |
145 | } else { | |
146 | tf_outb = ide_outb; | |
147 | tf_inb = ide_inb; | |
148 | } | |
149 | ||
1574cf6c | 150 | /* be sure we're looking at the low order bits */ |
4d74c3fc | 151 | tf_outb(ATA_DEVCTL_OBS, io_ports->ctl_addr); |
1574cf6c | 152 | |
67625119 SS |
153 | if (cmd->tf_flags & IDE_TFLAG_IN_ERROR) |
154 | tf->error = tf_inb(io_ports->feature_addr); | |
22aa4b32 | 155 | if (cmd->tf_flags & IDE_TFLAG_IN_NSECT) |
1574cf6c | 156 | tf->nsect = tf_inb(io_ports->nsect_addr); |
22aa4b32 | 157 | if (cmd->tf_flags & IDE_TFLAG_IN_LBAL) |
1574cf6c | 158 | tf->lbal = tf_inb(io_ports->lbal_addr); |
22aa4b32 | 159 | if (cmd->tf_flags & IDE_TFLAG_IN_LBAM) |
1574cf6c | 160 | tf->lbam = tf_inb(io_ports->lbam_addr); |
22aa4b32 | 161 | if (cmd->tf_flags & IDE_TFLAG_IN_LBAH) |
1574cf6c | 162 | tf->lbah = tf_inb(io_ports->lbah_addr); |
22aa4b32 | 163 | if (cmd->tf_flags & IDE_TFLAG_IN_DEVICE) |
1574cf6c BZ |
164 | tf->device = tf_inb(io_ports->device_addr); |
165 | ||
22aa4b32 | 166 | if (cmd->tf_flags & IDE_TFLAG_LBA48) { |
4d74c3fc | 167 | tf_outb(ATA_HOB | ATA_DEVCTL_OBS, io_ports->ctl_addr); |
1574cf6c | 168 | |
67625119 SS |
169 | if (cmd->tf_flags & IDE_TFLAG_IN_HOB_ERROR) |
170 | tf->hob_error = tf_inb(io_ports->feature_addr); | |
22aa4b32 | 171 | if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT) |
67625119 | 172 | tf->hob_nsect = tf_inb(io_ports->nsect_addr); |
22aa4b32 | 173 | if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL) |
67625119 | 174 | tf->hob_lbal = tf_inb(io_ports->lbal_addr); |
22aa4b32 | 175 | if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM) |
67625119 | 176 | tf->hob_lbam = tf_inb(io_ports->lbam_addr); |
22aa4b32 | 177 | if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH) |
67625119 | 178 | tf->hob_lbah = tf_inb(io_ports->lbah_addr); |
1574cf6c BZ |
179 | } |
180 | } | |
181 | EXPORT_SYMBOL_GPL(ide_tf_read); | |
182 | ||
183 | /* | |
184 | * Some localbus EIDE interfaces require a special access sequence | |
185 | * when using 32-bit I/O instructions to transfer data. We call this | |
186 | * the "vlb_sync" sequence, which consists of three successive reads | |
187 | * of the sector count register location, with interrupts disabled | |
188 | * to ensure that the reads all happen together. | |
189 | */ | |
190 | static void ata_vlb_sync(unsigned long port) | |
191 | { | |
192 | (void)inb(port); | |
193 | (void)inb(port); | |
194 | (void)inb(port); | |
195 | } | |
196 | ||
197 | /* | |
198 | * This is used for most PIO data transfers *from* the IDE interface | |
199 | * | |
200 | * These routines will round up any request for an odd number of bytes, | |
201 | * so if an odd len is specified, be sure that there's at least one | |
202 | * extra byte allocated for the buffer. | |
203 | */ | |
adb1af98 | 204 | void ide_input_data(ide_drive_t *drive, struct ide_cmd *cmd, void *buf, |
1574cf6c BZ |
205 | unsigned int len) |
206 | { | |
207 | ide_hwif_t *hwif = drive->hwif; | |
208 | struct ide_io_ports *io_ports = &hwif->io_ports; | |
209 | unsigned long data_addr = io_ports->data_addr; | |
deae17fd | 210 | unsigned int words = (len + 1) >> 1; |
1574cf6c BZ |
211 | u8 io_32bit = drive->io_32bit; |
212 | u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; | |
213 | ||
1574cf6c BZ |
214 | if (io_32bit) { |
215 | unsigned long uninitialized_var(flags); | |
216 | ||
217 | if ((io_32bit & 2) && !mmio) { | |
218 | local_irq_save(flags); | |
219 | ata_vlb_sync(io_ports->nsect_addr); | |
220 | } | |
221 | ||
deae17fd | 222 | words >>= 1; |
1574cf6c | 223 | if (mmio) |
deae17fd | 224 | __ide_mm_insl((void __iomem *)data_addr, buf, words); |
1574cf6c | 225 | else |
deae17fd | 226 | insl(data_addr, buf, words); |
1574cf6c BZ |
227 | |
228 | if ((io_32bit & 2) && !mmio) | |
229 | local_irq_restore(flags); | |
230 | ||
deae17fd SS |
231 | if (((len + 1) & 3) < 2) |
232 | return; | |
233 | ||
234 | buf += len & ~3; | |
235 | words = 1; | |
1574cf6c | 236 | } |
deae17fd SS |
237 | |
238 | if (mmio) | |
239 | __ide_mm_insw((void __iomem *)data_addr, buf, words); | |
240 | else | |
241 | insw(data_addr, buf, words); | |
1574cf6c BZ |
242 | } |
243 | EXPORT_SYMBOL_GPL(ide_input_data); | |
244 | ||
245 | /* | |
246 | * This is used for most PIO data transfers *to* the IDE interface | |
247 | */ | |
adb1af98 | 248 | void ide_output_data(ide_drive_t *drive, struct ide_cmd *cmd, void *buf, |
1574cf6c BZ |
249 | unsigned int len) |
250 | { | |
251 | ide_hwif_t *hwif = drive->hwif; | |
252 | struct ide_io_ports *io_ports = &hwif->io_ports; | |
253 | unsigned long data_addr = io_ports->data_addr; | |
deae17fd | 254 | unsigned int words = (len + 1) >> 1; |
1574cf6c BZ |
255 | u8 io_32bit = drive->io_32bit; |
256 | u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; | |
257 | ||
1574cf6c BZ |
258 | if (io_32bit) { |
259 | unsigned long uninitialized_var(flags); | |
260 | ||
261 | if ((io_32bit & 2) && !mmio) { | |
262 | local_irq_save(flags); | |
263 | ata_vlb_sync(io_ports->nsect_addr); | |
264 | } | |
265 | ||
deae17fd | 266 | words >>= 1; |
1574cf6c | 267 | if (mmio) |
deae17fd | 268 | __ide_mm_outsl((void __iomem *)data_addr, buf, words); |
1574cf6c | 269 | else |
deae17fd | 270 | outsl(data_addr, buf, words); |
1574cf6c BZ |
271 | |
272 | if ((io_32bit & 2) && !mmio) | |
273 | local_irq_restore(flags); | |
274 | ||
deae17fd SS |
275 | if (((len + 1) & 3) < 2) |
276 | return; | |
277 | ||
278 | buf += len & ~3; | |
279 | words = 1; | |
1574cf6c | 280 | } |
deae17fd SS |
281 | |
282 | if (mmio) | |
283 | __ide_mm_outsw((void __iomem *)data_addr, buf, words); | |
284 | else | |
285 | outsw(data_addr, buf, words); | |
1574cf6c BZ |
286 | } |
287 | EXPORT_SYMBOL_GPL(ide_output_data); | |
288 | ||
289 | const struct ide_tp_ops default_tp_ops = { | |
290 | .exec_command = ide_exec_command, | |
291 | .read_status = ide_read_status, | |
292 | .read_altstatus = ide_read_altstatus, | |
ecf3a31d | 293 | .write_devctl = ide_write_devctl, |
1574cf6c | 294 | |
abb596b2 | 295 | .dev_select = ide_dev_select, |
1574cf6c BZ |
296 | .tf_load = ide_tf_load, |
297 | .tf_read = ide_tf_read, | |
298 | ||
299 | .input_data = ide_input_data, | |
300 | .output_data = ide_output_data, | |
301 | }; |