ide-io-std.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. #include <linux/kernel.h>
  2. #include <linux/ide.h>
  3. #if defined(CONFIG_ARM) || defined(CONFIG_M68K) || defined(CONFIG_MIPS) || \
  4. defined(CONFIG_PARISC) || defined(CONFIG_PPC) || defined(CONFIG_SPARC)
  5. #include <asm/ide.h>
  6. #else
  7. #include <asm-generic/ide_iops.h>
  8. #endif
  9. /*
  10. * Conventional PIO operations for ATA devices
  11. */
  12. static u8 ide_inb(unsigned long port)
  13. {
  14. return (u8) inb(port);
  15. }
  16. static void ide_outb(u8 val, unsigned long port)
  17. {
  18. outb(val, port);
  19. }
  20. /*
  21. * MMIO operations, typically used for SATA controllers
  22. */
  23. static u8 ide_mm_inb(unsigned long port)
  24. {
  25. return (u8) readb((void __iomem *) port);
  26. }
  27. static void ide_mm_outb(u8 value, unsigned long port)
  28. {
  29. writeb(value, (void __iomem *) port);
  30. }
  31. void ide_exec_command(ide_hwif_t *hwif, u8 cmd)
  32. {
  33. if (hwif->host_flags & IDE_HFLAG_MMIO)
  34. writeb(cmd, (void __iomem *)hwif->io_ports.command_addr);
  35. else
  36. outb(cmd, hwif->io_ports.command_addr);
  37. }
  38. EXPORT_SYMBOL_GPL(ide_exec_command);
  39. u8 ide_read_status(ide_hwif_t *hwif)
  40. {
  41. if (hwif->host_flags & IDE_HFLAG_MMIO)
  42. return readb((void __iomem *)hwif->io_ports.status_addr);
  43. else
  44. return inb(hwif->io_ports.status_addr);
  45. }
  46. EXPORT_SYMBOL_GPL(ide_read_status);
  47. u8 ide_read_altstatus(ide_hwif_t *hwif)
  48. {
  49. if (hwif->host_flags & IDE_HFLAG_MMIO)
  50. return readb((void __iomem *)hwif->io_ports.ctl_addr);
  51. else
  52. return inb(hwif->io_ports.ctl_addr);
  53. }
  54. EXPORT_SYMBOL_GPL(ide_read_altstatus);
  55. void ide_write_devctl(ide_hwif_t *hwif, u8 ctl)
  56. {
  57. if (hwif->host_flags & IDE_HFLAG_MMIO)
  58. writeb(ctl, (void __iomem *)hwif->io_ports.ctl_addr);
  59. else
  60. outb(ctl, hwif->io_ports.ctl_addr);
  61. }
  62. EXPORT_SYMBOL_GPL(ide_write_devctl);
  63. void ide_dev_select(ide_drive_t *drive)
  64. {
  65. ide_hwif_t *hwif = drive->hwif;
  66. u8 select = drive->select | ATA_DEVICE_OBS;
  67. if (hwif->host_flags & IDE_HFLAG_MMIO)
  68. writeb(select, (void __iomem *)hwif->io_ports.device_addr);
  69. else
  70. outb(select, hwif->io_ports.device_addr);
  71. }
  72. EXPORT_SYMBOL_GPL(ide_dev_select);
  73. void ide_tf_load(ide_drive_t *drive, struct ide_taskfile *tf, u8 valid)
  74. {
  75. ide_hwif_t *hwif = drive->hwif;
  76. struct ide_io_ports *io_ports = &hwif->io_ports;
  77. void (*tf_outb)(u8 addr, unsigned long port);
  78. u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
  79. if (mmio)
  80. tf_outb = ide_mm_outb;
  81. else
  82. tf_outb = ide_outb;
  83. if (valid & IDE_VALID_FEATURE)
  84. tf_outb(tf->feature, io_ports->feature_addr);
  85. if (valid & IDE_VALID_NSECT)
  86. tf_outb(tf->nsect, io_ports->nsect_addr);
  87. if (valid & IDE_VALID_LBAL)
  88. tf_outb(tf->lbal, io_ports->lbal_addr);
  89. if (valid & IDE_VALID_LBAM)
  90. tf_outb(tf->lbam, io_ports->lbam_addr);
  91. if (valid & IDE_VALID_LBAH)
  92. tf_outb(tf->lbah, io_ports->lbah_addr);
  93. if (valid & IDE_VALID_DEVICE)
  94. tf_outb(tf->device, io_ports->device_addr);
  95. }
  96. EXPORT_SYMBOL_GPL(ide_tf_load);
  97. void ide_tf_read(ide_drive_t *drive, struct ide_taskfile *tf, u8 valid)
  98. {
  99. ide_hwif_t *hwif = drive->hwif;
  100. struct ide_io_ports *io_ports = &hwif->io_ports;
  101. u8 (*tf_inb)(unsigned long port);
  102. u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
  103. if (mmio)
  104. tf_inb = ide_mm_inb;
  105. else
  106. tf_inb = ide_inb;
  107. if (valid & IDE_VALID_ERROR)
  108. tf->error = tf_inb(io_ports->feature_addr);
  109. if (valid & IDE_VALID_NSECT)
  110. tf->nsect = tf_inb(io_ports->nsect_addr);
  111. if (valid & IDE_VALID_LBAL)
  112. tf->lbal = tf_inb(io_ports->lbal_addr);
  113. if (valid & IDE_VALID_LBAM)
  114. tf->lbam = tf_inb(io_ports->lbam_addr);
  115. if (valid & IDE_VALID_LBAH)
  116. tf->lbah = tf_inb(io_ports->lbah_addr);
  117. if (valid & IDE_VALID_DEVICE)
  118. tf->device = tf_inb(io_ports->device_addr);
  119. }
  120. EXPORT_SYMBOL_GPL(ide_tf_read);
  121. /*
  122. * Some localbus EIDE interfaces require a special access sequence
  123. * when using 32-bit I/O instructions to transfer data. We call this
  124. * the "vlb_sync" sequence, which consists of three successive reads
  125. * of the sector count register location, with interrupts disabled
  126. * to ensure that the reads all happen together.
  127. */
  128. static void ata_vlb_sync(unsigned long port)
  129. {
  130. (void)inb(port);
  131. (void)inb(port);
  132. (void)inb(port);
  133. }
  134. /*
  135. * This is used for most PIO data transfers *from* the IDE interface
  136. *
  137. * These routines will round up any request for an odd number of bytes,
  138. * so if an odd len is specified, be sure that there's at least one
  139. * extra byte allocated for the buffer.
  140. */
  141. void ide_input_data(ide_drive_t *drive, struct ide_cmd *cmd, void *buf,
  142. unsigned int len)
  143. {
  144. ide_hwif_t *hwif = drive->hwif;
  145. struct ide_io_ports *io_ports = &hwif->io_ports;
  146. unsigned long data_addr = io_ports->data_addr;
  147. unsigned int words = (len + 1) >> 1;
  148. u8 io_32bit = drive->io_32bit;
  149. u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
  150. if (io_32bit) {
  151. unsigned long uninitialized_var(flags);
  152. if ((io_32bit & 2) && !mmio) {
  153. local_irq_save(flags);
  154. ata_vlb_sync(io_ports->nsect_addr);
  155. }
  156. words >>= 1;
  157. if (mmio)
  158. __ide_mm_insl((void __iomem *)data_addr, buf, words);
  159. else
  160. insl(data_addr, buf, words);
  161. if ((io_32bit & 2) && !mmio)
  162. local_irq_restore(flags);
  163. if (((len + 1) & 3) < 2)
  164. return;
  165. buf += len & ~3;
  166. words = 1;
  167. }
  168. if (mmio)
  169. __ide_mm_insw((void __iomem *)data_addr, buf, words);
  170. else
  171. insw(data_addr, buf, words);
  172. }
  173. EXPORT_SYMBOL_GPL(ide_input_data);
  174. /*
  175. * This is used for most PIO data transfers *to* the IDE interface
  176. */
  177. void ide_output_data(ide_drive_t *drive, struct ide_cmd *cmd, void *buf,
  178. unsigned int len)
  179. {
  180. ide_hwif_t *hwif = drive->hwif;
  181. struct ide_io_ports *io_ports = &hwif->io_ports;
  182. unsigned long data_addr = io_ports->data_addr;
  183. unsigned int words = (len + 1) >> 1;
  184. u8 io_32bit = drive->io_32bit;
  185. u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
  186. if (io_32bit) {
  187. unsigned long uninitialized_var(flags);
  188. if ((io_32bit & 2) && !mmio) {
  189. local_irq_save(flags);
  190. ata_vlb_sync(io_ports->nsect_addr);
  191. }
  192. words >>= 1;
  193. if (mmio)
  194. __ide_mm_outsl((void __iomem *)data_addr, buf, words);
  195. else
  196. outsl(data_addr, buf, words);
  197. if ((io_32bit & 2) && !mmio)
  198. local_irq_restore(flags);
  199. if (((len + 1) & 3) < 2)
  200. return;
  201. buf += len & ~3;
  202. words = 1;
  203. }
  204. if (mmio)
  205. __ide_mm_outsw((void __iomem *)data_addr, buf, words);
  206. else
  207. outsw(data_addr, buf, words);
  208. }
  209. EXPORT_SYMBOL_GPL(ide_output_data);
  210. const struct ide_tp_ops default_tp_ops = {
  211. .exec_command = ide_exec_command,
  212. .read_status = ide_read_status,
  213. .read_altstatus = ide_read_altstatus,
  214. .write_devctl = ide_write_devctl,
  215. .dev_select = ide_dev_select,
  216. .tf_load = ide_tf_load,
  217. .tf_read = ide_tf_read,
  218. .input_data = ide_input_data,
  219. .output_data = ide_output_data,
  220. };