ata_generic.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * ata_generic.c - Generic PATA/SATA controller driver.
  3. * Copyright 2005 Red Hat Inc, all rights reserved.
  4. *
  5. * Elements from ide/pci/generic.c
  6. * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
  7. * Portions (C) Copyright 2002 Red Hat Inc <alan@redhat.com>
  8. *
  9. * May be copied or modified under the terms of the GNU General Public License
  10. *
  11. * Driver for PCI IDE interfaces implementing the standard bus mastering
  12. * interface functionality. This assumes the BIOS did the drive set up and
  13. * tuning for us. By default we do not grab all IDE class devices as they
  14. * may have other drivers or need fixups to avoid problems. Instead we keep
  15. * a default list of stuff without documentation/driver that appears to
  16. * work.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/pci.h>
  21. #include <linux/init.h>
  22. #include <linux/blkdev.h>
  23. #include <linux/delay.h>
  24. #include <scsi/scsi_host.h>
  25. #include <linux/libata.h>
  26. #define DRV_NAME "ata_generic"
  27. #define DRV_VERSION "0.2.15"
  28. /*
  29. * A generic parallel ATA driver using libata
  30. */
  31. enum {
  32. ATA_GEN_CLASS_MATCH = (1 << 0),
  33. ATA_GEN_FORCE_DMA = (1 << 1),
  34. ATA_GEN_INTEL_IDER = (1 << 2),
  35. };
  36. /**
  37. * generic_set_mode - mode setting
  38. * @link: link to set up
  39. * @unused: returned device on error
  40. *
  41. * Use a non standard set_mode function. We don't want to be tuned.
  42. * The BIOS configured everything. Our job is not to fiddle. We
  43. * read the dma enabled bits from the PCI configuration of the device
  44. * and respect them.
  45. */
  46. static int generic_set_mode(struct ata_link *link, struct ata_device **unused)
  47. {
  48. struct ata_port *ap = link->ap;
  49. const struct pci_device_id *id = ap->host->private_data;
  50. int dma_enabled = 0;
  51. struct ata_device *dev;
  52. if (id->driver_data & ATA_GEN_FORCE_DMA) {
  53. dma_enabled = 0xff;
  54. } else if (ap->ioaddr.bmdma_addr) {
  55. /* Bits 5 and 6 indicate if DMA is active on master/slave */
  56. dma_enabled = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
  57. }
  58. ata_for_each_dev(dev, link, ENABLED) {
  59. /* We don't really care */
  60. dev->pio_mode = XFER_PIO_0;
  61. dev->dma_mode = XFER_MW_DMA_0;
  62. /* We do need the right mode information for DMA or PIO
  63. and this comes from the current configuration flags */
  64. if (dma_enabled & (1 << (5 + dev->devno))) {
  65. unsigned int xfer_mask = ata_id_xfermask(dev->id);
  66. const char *name;
  67. if (xfer_mask & (ATA_MASK_MWDMA | ATA_MASK_UDMA))
  68. name = ata_mode_string(xfer_mask);
  69. else {
  70. /* SWDMA perhaps? */
  71. name = "DMA";
  72. xfer_mask |= ata_xfer_mode2mask(XFER_MW_DMA_0);
  73. }
  74. ata_dev_info(dev, "configured for %s\n", name);
  75. dev->xfer_mode = ata_xfer_mask2mode(xfer_mask);
  76. dev->xfer_shift = ata_xfer_mode2shift(dev->xfer_mode);
  77. dev->flags &= ~ATA_DFLAG_PIO;
  78. } else {
  79. ata_dev_info(dev, "configured for PIO\n");
  80. dev->xfer_mode = XFER_PIO_0;
  81. dev->xfer_shift = ATA_SHIFT_PIO;
  82. dev->flags |= ATA_DFLAG_PIO;
  83. }
  84. }
  85. return 0;
  86. }
  87. static struct scsi_host_template generic_sht = {
  88. ATA_BMDMA_SHT(DRV_NAME),
  89. };
  90. static struct ata_port_operations generic_port_ops = {
  91. .inherits = &ata_bmdma_port_ops,
  92. .cable_detect = ata_cable_unknown,
  93. .set_mode = generic_set_mode,
  94. };
  95. static int all_generic_ide; /* Set to claim all devices */
  96. /**
  97. * is_intel_ider - identify intel IDE-R devices
  98. * @dev: PCI device
  99. *
  100. * Distinguish Intel IDE-R controller devices from other Intel IDE
  101. * devices. IDE-R devices have no timing registers and are in
  102. * most respects virtual. They should be driven by the ata_generic
  103. * driver.
  104. *
  105. * IDE-R devices have PCI offset 0xF8.L as zero, later Intel ATA has
  106. * it non zero. All Intel ATA has 0x40 writable (timing), but it is
  107. * not writable on IDE-R devices (this is guaranteed).
  108. */
  109. static int is_intel_ider(struct pci_dev *dev)
  110. {
  111. /* For Intel IDE the value at 0xF8 is only zero on IDE-R
  112. interfaces */
  113. u32 r;
  114. u16 t;
  115. /* Check the manufacturing ID, it will be zero for IDE-R */
  116. pci_read_config_dword(dev, 0xF8, &r);
  117. /* Not IDE-R: punt so that ata_(old)piix gets it */
  118. if (r != 0)
  119. return 0;
  120. /* 0xF8 will also be zero on some early Intel IDE devices
  121. but they will have a sane timing register */
  122. pci_read_config_word(dev, 0x40, &t);
  123. if (t != 0)
  124. return 0;
  125. /* Finally check if the timing register is writable so that
  126. we eliminate any early devices hot-docked in a docking
  127. station */
  128. pci_write_config_word(dev, 0x40, 1);
  129. pci_read_config_word(dev, 0x40, &t);
  130. if (t) {
  131. pci_write_config_word(dev, 0x40, 0);
  132. return 0;
  133. }
  134. return 1;
  135. }
  136. /**
  137. * ata_generic_init - attach generic IDE
  138. * @dev: PCI device found
  139. * @id: match entry
  140. *
  141. * Called each time a matching IDE interface is found. We check if the
  142. * interface is one we wish to claim and if so we perform any chip
  143. * specific hacks then let the ATA layer do the heavy lifting.
  144. */
  145. static int ata_generic_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  146. {
  147. u16 command;
  148. static const struct ata_port_info info = {
  149. .flags = ATA_FLAG_SLAVE_POSS,
  150. .pio_mask = ATA_PIO4,
  151. .mwdma_mask = ATA_MWDMA2,
  152. .udma_mask = ATA_UDMA5,
  153. .port_ops = &generic_port_ops
  154. };
  155. const struct ata_port_info *ppi[] = { &info, NULL };
  156. /* Don't use the generic entry unless instructed to do so */
  157. if ((id->driver_data & ATA_GEN_CLASS_MATCH) && all_generic_ide == 0)
  158. return -ENODEV;
  159. if (id->driver_data & ATA_GEN_INTEL_IDER)
  160. if (!is_intel_ider(dev))
  161. return -ENODEV;
  162. /* Devices that need care */
  163. if (dev->vendor == PCI_VENDOR_ID_UMC &&
  164. dev->device == PCI_DEVICE_ID_UMC_UM8886A &&
  165. (!(PCI_FUNC(dev->devfn) & 1)))
  166. return -ENODEV;
  167. if (dev->vendor == PCI_VENDOR_ID_OPTI &&
  168. dev->device == PCI_DEVICE_ID_OPTI_82C558 &&
  169. (!(PCI_FUNC(dev->devfn) & 1)))
  170. return -ENODEV;
  171. /* Don't re-enable devices in generic mode or we will break some
  172. motherboards with disabled and unused IDE controllers */
  173. pci_read_config_word(dev, PCI_COMMAND, &command);
  174. if (!(command & PCI_COMMAND_IO))
  175. return -ENODEV;
  176. if (dev->vendor == PCI_VENDOR_ID_AL)
  177. ata_pci_bmdma_clear_simplex(dev);
  178. if (dev->vendor == PCI_VENDOR_ID_ATI) {
  179. int rc = pcim_enable_device(dev);
  180. if (rc < 0)
  181. return rc;
  182. pcim_pin_device(dev);
  183. }
  184. return ata_pci_bmdma_init_one(dev, ppi, &generic_sht, (void *)id, 0);
  185. }
  186. static struct pci_device_id ata_generic[] = {
  187. { PCI_DEVICE(PCI_VENDOR_ID_PCTECH, PCI_DEVICE_ID_PCTECH_SAMURAI_IDE), },
  188. { PCI_DEVICE(PCI_VENDOR_ID_HOLTEK, PCI_DEVICE_ID_HOLTEK_6565), },
  189. { PCI_DEVICE(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8673F), },
  190. { PCI_DEVICE(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886A), },
  191. { PCI_DEVICE(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886BF), },
  192. { PCI_DEVICE(PCI_VENDOR_ID_HINT, PCI_DEVICE_ID_HINT_VXPROII_IDE), },
  193. { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C561), },
  194. { PCI_DEVICE(PCI_VENDOR_ID_OPTI, PCI_DEVICE_ID_OPTI_82C558), },
  195. { PCI_DEVICE(PCI_VENDOR_ID_CENATEK,PCI_DEVICE_ID_CENATEK_IDE),
  196. .driver_data = ATA_GEN_FORCE_DMA },
  197. /*
  198. * For some reason, MCP89 on MacBook 7,1 doesn't work with
  199. * ahci, use ata_generic instead.
  200. */
  201. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP89_SATA,
  202. PCI_VENDOR_ID_APPLE, 0xcb89,
  203. .driver_data = ATA_GEN_FORCE_DMA },
  204. #if !defined(CONFIG_PATA_TOSHIBA) && !defined(CONFIG_PATA_TOSHIBA_MODULE)
  205. { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1), },
  206. { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2), },
  207. { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_3), },
  208. { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_5), },
  209. #endif
  210. /* Intel, IDE class device */
  211. { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  212. PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL,
  213. .driver_data = ATA_GEN_INTEL_IDER },
  214. /* Must come last. If you add entries adjust this table appropriately */
  215. { PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL),
  216. .driver_data = ATA_GEN_CLASS_MATCH },
  217. { 0, },
  218. };
  219. static struct pci_driver ata_generic_pci_driver = {
  220. .name = DRV_NAME,
  221. .id_table = ata_generic,
  222. .probe = ata_generic_init_one,
  223. .remove = ata_pci_remove_one,
  224. #ifdef CONFIG_PM
  225. .suspend = ata_pci_device_suspend,
  226. .resume = ata_pci_device_resume,
  227. #endif
  228. };
  229. static int __init ata_generic_init(void)
  230. {
  231. return pci_register_driver(&ata_generic_pci_driver);
  232. }
  233. static void __exit ata_generic_exit(void)
  234. {
  235. pci_unregister_driver(&ata_generic_pci_driver);
  236. }
  237. MODULE_AUTHOR("Alan Cox");
  238. MODULE_DESCRIPTION("low-level driver for generic ATA");
  239. MODULE_LICENSE("GPL");
  240. MODULE_DEVICE_TABLE(pci, ata_generic);
  241. MODULE_VERSION(DRV_VERSION);
  242. module_init(ata_generic_init);
  243. module_exit(ata_generic_exit);
  244. module_param(all_generic_ide, int, 0);