Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 1 | |
| 2 | #include <linux/kernel.h> |
| 3 | #include <linux/ide.h> |
| 4 | |
Bartlomiej Zolnierkiewicz | 15a453a | 2009-03-27 12:46:26 +0100 | [diff] [blame] | 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 | |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 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 | |
Sergei Shtylyov | ecf3a31 | 2009-03-31 20:15:30 +0200 | [diff] [blame] | 67 | void ide_write_devctl(ide_hwif_t *hwif, u8 ctl) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 68 | { |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 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 | } |
Sergei Shtylyov | ecf3a31 | 2009-03-31 20:15:30 +0200 | [diff] [blame] | 74 | EXPORT_SYMBOL_GPL(ide_write_devctl); |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 75 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 76 | void ide_tf_load(ide_drive_t *drive, struct ide_cmd *cmd) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 77 | { |
| 78 | ide_hwif_t *hwif = drive->hwif; |
| 79 | struct ide_io_ports *io_ports = &hwif->io_ports; |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 80 | struct ide_taskfile *tf = &cmd->tf; |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 81 | void (*tf_outb)(u8 addr, unsigned long port); |
| 82 | u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 83 | u8 HIHI = (cmd->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF; |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 84 | |
| 85 | if (mmio) |
| 86 | tf_outb = ide_mm_outb; |
| 87 | else |
| 88 | tf_outb = ide_outb; |
| 89 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 90 | if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 91 | HIHI = 0xFF; |
| 92 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 93 | if (cmd->ftf_flags & IDE_FTFLAG_OUT_DATA) { |
Sergei Shtylyov | bac08ce | 2009-03-31 20:15:31 +0200 | [diff] [blame^] | 94 | u8 data[2] = { tf->data, tf->hob_data }; |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 95 | |
Sergei Shtylyov | bac08ce | 2009-03-31 20:15:31 +0200 | [diff] [blame^] | 96 | ide_output_data(drive, cmd, data, 2); |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 97 | } |
| 98 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 99 | if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 100 | tf_outb(tf->hob_feature, io_ports->feature_addr); |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 101 | if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 102 | tf_outb(tf->hob_nsect, io_ports->nsect_addr); |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 103 | if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAL) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 104 | tf_outb(tf->hob_lbal, io_ports->lbal_addr); |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 105 | if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAM) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 106 | tf_outb(tf->hob_lbam, io_ports->lbam_addr); |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 107 | if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAH) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 108 | tf_outb(tf->hob_lbah, io_ports->lbah_addr); |
| 109 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 110 | if (cmd->tf_flags & IDE_TFLAG_OUT_FEATURE) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 111 | tf_outb(tf->feature, io_ports->feature_addr); |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 112 | if (cmd->tf_flags & IDE_TFLAG_OUT_NSECT) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 113 | tf_outb(tf->nsect, io_ports->nsect_addr); |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 114 | if (cmd->tf_flags & IDE_TFLAG_OUT_LBAL) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 115 | tf_outb(tf->lbal, io_ports->lbal_addr); |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 116 | if (cmd->tf_flags & IDE_TFLAG_OUT_LBAM) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 117 | tf_outb(tf->lbam, io_ports->lbam_addr); |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 118 | if (cmd->tf_flags & IDE_TFLAG_OUT_LBAH) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 119 | tf_outb(tf->lbah, io_ports->lbah_addr); |
| 120 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 121 | if (cmd->tf_flags & IDE_TFLAG_OUT_DEVICE) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 122 | tf_outb((tf->device & HIHI) | drive->select, |
| 123 | io_ports->device_addr); |
| 124 | } |
| 125 | EXPORT_SYMBOL_GPL(ide_tf_load); |
| 126 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 127 | void ide_tf_read(ide_drive_t *drive, struct ide_cmd *cmd) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 128 | { |
| 129 | ide_hwif_t *hwif = drive->hwif; |
| 130 | struct ide_io_ports *io_ports = &hwif->io_ports; |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 131 | struct ide_taskfile *tf = &cmd->tf; |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 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; |
| 135 | |
| 136 | if (mmio) { |
| 137 | tf_outb = ide_mm_outb; |
| 138 | tf_inb = ide_mm_inb; |
| 139 | } else { |
| 140 | tf_outb = ide_outb; |
| 141 | tf_inb = ide_inb; |
| 142 | } |
| 143 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 144 | if (cmd->ftf_flags & IDE_FTFLAG_IN_DATA) { |
Sergei Shtylyov | bac08ce | 2009-03-31 20:15:31 +0200 | [diff] [blame^] | 145 | u8 data[2]; |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 146 | |
Sergei Shtylyov | bac08ce | 2009-03-31 20:15:31 +0200 | [diff] [blame^] | 147 | ide_input_data(drive, cmd, data, 2); |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 148 | |
Sergei Shtylyov | bac08ce | 2009-03-31 20:15:31 +0200 | [diff] [blame^] | 149 | tf->data = data[0]; |
| 150 | tf->hob_data = data[1]; |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /* be sure we're looking at the low order bits */ |
Sergei Shtylyov | 4d74c3f | 2009-03-31 20:15:29 +0200 | [diff] [blame] | 154 | tf_outb(ATA_DEVCTL_OBS, io_ports->ctl_addr); |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 155 | |
Sergei Shtylyov | 6762511 | 2009-03-31 20:15:30 +0200 | [diff] [blame] | 156 | if (cmd->tf_flags & IDE_TFLAG_IN_ERROR) |
| 157 | tf->error = tf_inb(io_ports->feature_addr); |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 158 | if (cmd->tf_flags & IDE_TFLAG_IN_NSECT) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 159 | tf->nsect = tf_inb(io_ports->nsect_addr); |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 160 | if (cmd->tf_flags & IDE_TFLAG_IN_LBAL) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 161 | tf->lbal = tf_inb(io_ports->lbal_addr); |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 162 | if (cmd->tf_flags & IDE_TFLAG_IN_LBAM) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 163 | tf->lbam = tf_inb(io_ports->lbam_addr); |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 164 | if (cmd->tf_flags & IDE_TFLAG_IN_LBAH) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 165 | tf->lbah = tf_inb(io_ports->lbah_addr); |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 166 | if (cmd->tf_flags & IDE_TFLAG_IN_DEVICE) |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 167 | tf->device = tf_inb(io_ports->device_addr); |
| 168 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 169 | if (cmd->tf_flags & IDE_TFLAG_LBA48) { |
Sergei Shtylyov | 4d74c3f | 2009-03-31 20:15:29 +0200 | [diff] [blame] | 170 | tf_outb(ATA_HOB | ATA_DEVCTL_OBS, io_ports->ctl_addr); |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 171 | |
Sergei Shtylyov | 6762511 | 2009-03-31 20:15:30 +0200 | [diff] [blame] | 172 | if (cmd->tf_flags & IDE_TFLAG_IN_HOB_ERROR) |
| 173 | tf->hob_error = tf_inb(io_ports->feature_addr); |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 174 | if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT) |
Sergei Shtylyov | 6762511 | 2009-03-31 20:15:30 +0200 | [diff] [blame] | 175 | tf->hob_nsect = tf_inb(io_ports->nsect_addr); |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 176 | if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL) |
Sergei Shtylyov | 6762511 | 2009-03-31 20:15:30 +0200 | [diff] [blame] | 177 | tf->hob_lbal = tf_inb(io_ports->lbal_addr); |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 178 | if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM) |
Sergei Shtylyov | 6762511 | 2009-03-31 20:15:30 +0200 | [diff] [blame] | 179 | tf->hob_lbam = tf_inb(io_ports->lbam_addr); |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 180 | if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH) |
Sergei Shtylyov | 6762511 | 2009-03-31 20:15:30 +0200 | [diff] [blame] | 181 | tf->hob_lbah = tf_inb(io_ports->lbah_addr); |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | EXPORT_SYMBOL_GPL(ide_tf_read); |
| 185 | |
| 186 | /* |
| 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. |
| 192 | */ |
| 193 | static void ata_vlb_sync(unsigned long port) |
| 194 | { |
| 195 | (void)inb(port); |
| 196 | (void)inb(port); |
| 197 | (void)inb(port); |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | * This is used for most PIO data transfers *from* the IDE interface |
| 202 | * |
| 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. |
| 206 | */ |
Bartlomiej Zolnierkiewicz | adb1af9 | 2009-03-27 12:46:38 +0100 | [diff] [blame] | 207 | void ide_input_data(ide_drive_t *drive, struct ide_cmd *cmd, void *buf, |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 208 | unsigned int len) |
| 209 | { |
| 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; |
Sergei Shtylyov | deae17f | 2009-03-31 20:15:31 +0200 | [diff] [blame] | 213 | unsigned int words = (len + 1) >> 1; |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 214 | u8 io_32bit = drive->io_32bit; |
| 215 | u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; |
| 216 | |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 217 | if (io_32bit) { |
| 218 | unsigned long uninitialized_var(flags); |
| 219 | |
| 220 | if ((io_32bit & 2) && !mmio) { |
| 221 | local_irq_save(flags); |
| 222 | ata_vlb_sync(io_ports->nsect_addr); |
| 223 | } |
| 224 | |
Sergei Shtylyov | deae17f | 2009-03-31 20:15:31 +0200 | [diff] [blame] | 225 | words >>= 1; |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 226 | if (mmio) |
Sergei Shtylyov | deae17f | 2009-03-31 20:15:31 +0200 | [diff] [blame] | 227 | __ide_mm_insl((void __iomem *)data_addr, buf, words); |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 228 | else |
Sergei Shtylyov | deae17f | 2009-03-31 20:15:31 +0200 | [diff] [blame] | 229 | insl(data_addr, buf, words); |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 230 | |
| 231 | if ((io_32bit & 2) && !mmio) |
| 232 | local_irq_restore(flags); |
| 233 | |
Sergei Shtylyov | deae17f | 2009-03-31 20:15:31 +0200 | [diff] [blame] | 234 | if (((len + 1) & 3) < 2) |
| 235 | return; |
| 236 | |
| 237 | buf += len & ~3; |
| 238 | words = 1; |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 239 | } |
Sergei Shtylyov | deae17f | 2009-03-31 20:15:31 +0200 | [diff] [blame] | 240 | |
| 241 | if (mmio) |
| 242 | __ide_mm_insw((void __iomem *)data_addr, buf, words); |
| 243 | else |
| 244 | insw(data_addr, buf, words); |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 245 | } |
| 246 | EXPORT_SYMBOL_GPL(ide_input_data); |
| 247 | |
| 248 | /* |
| 249 | * This is used for most PIO data transfers *to* the IDE interface |
| 250 | */ |
Bartlomiej Zolnierkiewicz | adb1af9 | 2009-03-27 12:46:38 +0100 | [diff] [blame] | 251 | void ide_output_data(ide_drive_t *drive, struct ide_cmd *cmd, void *buf, |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 252 | unsigned int len) |
| 253 | { |
| 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; |
Sergei Shtylyov | deae17f | 2009-03-31 20:15:31 +0200 | [diff] [blame] | 257 | unsigned int words = (len + 1) >> 1; |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 258 | u8 io_32bit = drive->io_32bit; |
| 259 | u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; |
| 260 | |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 261 | if (io_32bit) { |
| 262 | unsigned long uninitialized_var(flags); |
| 263 | |
| 264 | if ((io_32bit & 2) && !mmio) { |
| 265 | local_irq_save(flags); |
| 266 | ata_vlb_sync(io_ports->nsect_addr); |
| 267 | } |
| 268 | |
Sergei Shtylyov | deae17f | 2009-03-31 20:15:31 +0200 | [diff] [blame] | 269 | words >>= 1; |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 270 | if (mmio) |
Sergei Shtylyov | deae17f | 2009-03-31 20:15:31 +0200 | [diff] [blame] | 271 | __ide_mm_outsl((void __iomem *)data_addr, buf, words); |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 272 | else |
Sergei Shtylyov | deae17f | 2009-03-31 20:15:31 +0200 | [diff] [blame] | 273 | outsl(data_addr, buf, words); |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 274 | |
| 275 | if ((io_32bit & 2) && !mmio) |
| 276 | local_irq_restore(flags); |
| 277 | |
Sergei Shtylyov | deae17f | 2009-03-31 20:15:31 +0200 | [diff] [blame] | 278 | if (((len + 1) & 3) < 2) |
| 279 | return; |
| 280 | |
| 281 | buf += len & ~3; |
| 282 | words = 1; |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 283 | } |
Sergei Shtylyov | deae17f | 2009-03-31 20:15:31 +0200 | [diff] [blame] | 284 | |
| 285 | if (mmio) |
| 286 | __ide_mm_outsw((void __iomem *)data_addr, buf, words); |
| 287 | else |
| 288 | outsw(data_addr, buf, words); |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 289 | } |
| 290 | EXPORT_SYMBOL_GPL(ide_output_data); |
| 291 | |
| 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, |
Sergei Shtylyov | ecf3a31 | 2009-03-31 20:15:30 +0200 | [diff] [blame] | 296 | .write_devctl = ide_write_devctl, |
Bartlomiej Zolnierkiewicz | 1574cf6 | 2009-03-24 23:22:46 +0100 | [diff] [blame] | 297 | |
| 298 | .tf_load = ide_tf_load, |
| 299 | .tf_read = ide_tf_read, |
| 300 | |
| 301 | .input_data = ide_input_data, |
| 302 | .output_data = ide_output_data, |
| 303 | }; |