ata_generic.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * ata_generic.c - Generic PATA/SATA controller driver.
  3. * Copyright 2005 Red Hat Inc <alan@redhat.com>, 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.13"
  28. /*
  29. * A generic parallel ATA driver using libata
  30. */
  31. /**
  32. * generic_set_mode - mode setting
  33. * @link: link to set up
  34. * @unused: returned device on error
  35. *
  36. * Use a non standard set_mode function. We don't want to be tuned.
  37. * The BIOS configured everything. Our job is not to fiddle. We
  38. * read the dma enabled bits from the PCI configuration of the device
  39. * and respect them.
  40. */
  41. static int generic_set_mode(struct ata_link *link, struct ata_device **unused)
  42. {
  43. struct ata_port *ap = link->ap;
  44. int dma_enabled = 0;
  45. struct ata_device *dev;
  46. /* Bits 5 and 6 indicate if DMA is active on master/slave */
  47. if (ap->ioaddr.bmdma_addr)
  48. dma_enabled = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
  49. ata_link_for_each_dev(dev, link) {
  50. if (!ata_dev_enabled(dev))
  51. continue;
  52. /* We don't really care */
  53. dev->pio_mode = XFER_PIO_0;
  54. dev->dma_mode = XFER_MW_DMA_0;
  55. /* We do need the right mode information for DMA or PIO
  56. and this comes from the current configuration flags */
  57. if (dma_enabled & (1 << (5 + dev->devno))) {
  58. unsigned int xfer_mask = ata_id_xfermask(dev->id);
  59. const char *name;
  60. if (xfer_mask & (ATA_MASK_MWDMA | ATA_MASK_UDMA))
  61. name = ata_mode_string(xfer_mask);
  62. else {
  63. /* SWDMA perhaps? */
  64. name = "DMA";
  65. xfer_mask |= ata_xfer_mode2mask(XFER_MW_DMA_0);
  66. }
  67. ata_dev_printk(dev, KERN_INFO, "configured for %s\n",
  68. name);
  69. dev->xfer_mode = ata_xfer_mask2mode(xfer_mask);
  70. dev->xfer_shift = ata_xfer_mode2shift(dev->xfer_mode);
  71. dev->flags &= ~ATA_DFLAG_PIO;
  72. } else {
  73. ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
  74. dev->xfer_mode = XFER_PIO_0;
  75. dev->xfer_shift = ATA_SHIFT_PIO;
  76. dev->flags |= ATA_DFLAG_PIO;
  77. }
  78. }
  79. return 0;
  80. }
  81. static struct scsi_host_template generic_sht = {
  82. .module = THIS_MODULE,
  83. .name = DRV_NAME,
  84. .ioctl = ata_scsi_ioctl,
  85. .queuecommand = ata_scsi_queuecmd,
  86. .can_queue = ATA_DEF_QUEUE,
  87. .this_id = ATA_SHT_THIS_ID,
  88. .sg_tablesize = LIBATA_MAX_PRD,
  89. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  90. .emulated = ATA_SHT_EMULATED,
  91. .use_clustering = ATA_SHT_USE_CLUSTERING,
  92. .proc_name = DRV_NAME,
  93. .dma_boundary = ATA_DMA_BOUNDARY,
  94. .slave_configure = ata_scsi_slave_config,
  95. .slave_destroy = ata_scsi_slave_destroy,
  96. .bios_param = ata_std_bios_param,
  97. };
  98. static struct ata_port_operations generic_port_ops = {
  99. .set_mode = generic_set_mode,
  100. .tf_load = ata_tf_load,
  101. .tf_read = ata_tf_read,
  102. .check_status = ata_check_status,
  103. .exec_command = ata_exec_command,
  104. .dev_select = ata_std_dev_select,
  105. .bmdma_setup = ata_bmdma_setup,
  106. .bmdma_start = ata_bmdma_start,
  107. .bmdma_stop = ata_bmdma_stop,
  108. .bmdma_status = ata_bmdma_status,
  109. .data_xfer = ata_data_xfer,
  110. .freeze = ata_bmdma_freeze,
  111. .thaw = ata_bmdma_thaw,
  112. .error_handler = ata_bmdma_error_handler,
  113. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  114. .cable_detect = ata_cable_unknown,
  115. .qc_prep = ata_qc_prep,
  116. .qc_issue = ata_qc_issue_prot,
  117. .irq_handler = ata_interrupt,
  118. .irq_clear = ata_bmdma_irq_clear,
  119. .irq_on = ata_irq_on,
  120. .port_start = ata_sff_port_start,
  121. };
  122. static int all_generic_ide; /* Set to claim all devices */
  123. /**
  124. * ata_generic_init - attach generic IDE
  125. * @dev: PCI device found
  126. * @id: match entry
  127. *
  128. * Called each time a matching IDE interface is found. We check if the
  129. * interface is one we wish to claim and if so we perform any chip
  130. * specific hacks then let the ATA layer do the heavy lifting.
  131. */
  132. static int ata_generic_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  133. {
  134. u16 command;
  135. static const struct ata_port_info info = {
  136. .sht = &generic_sht,
  137. .flags = ATA_FLAG_SLAVE_POSS,
  138. .pio_mask = 0x1f,
  139. .mwdma_mask = 0x07,
  140. .udma_mask = ATA_UDMA5,
  141. .port_ops = &generic_port_ops
  142. };
  143. const struct ata_port_info *ppi[] = { &info, NULL };
  144. /* Don't use the generic entry unless instructed to do so */
  145. if (id->driver_data == 1 && all_generic_ide == 0)
  146. return -ENODEV;
  147. /* Devices that need care */
  148. if (dev->vendor == PCI_VENDOR_ID_UMC &&
  149. dev->device == PCI_DEVICE_ID_UMC_UM8886A &&
  150. (!(PCI_FUNC(dev->devfn) & 1)))
  151. return -ENODEV;
  152. if (dev->vendor == PCI_VENDOR_ID_OPTI &&
  153. dev->device == PCI_DEVICE_ID_OPTI_82C558 &&
  154. (!(PCI_FUNC(dev->devfn) & 1)))
  155. return -ENODEV;
  156. /* Don't re-enable devices in generic mode or we will break some
  157. motherboards with disabled and unused IDE controllers */
  158. pci_read_config_word(dev, PCI_COMMAND, &command);
  159. if (!(command & PCI_COMMAND_IO))
  160. return -ENODEV;
  161. if (dev->vendor == PCI_VENDOR_ID_AL)
  162. ata_pci_clear_simplex(dev);
  163. return ata_pci_init_one(dev, ppi);
  164. }
  165. static struct pci_device_id ata_generic[] = {
  166. { PCI_DEVICE(PCI_VENDOR_ID_PCTECH, PCI_DEVICE_ID_PCTECH_SAMURAI_IDE), },
  167. { PCI_DEVICE(PCI_VENDOR_ID_HOLTEK, PCI_DEVICE_ID_HOLTEK_6565), },
  168. { PCI_DEVICE(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8673F), },
  169. { PCI_DEVICE(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886A), },
  170. { PCI_DEVICE(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886BF), },
  171. { PCI_DEVICE(PCI_VENDOR_ID_HINT, PCI_DEVICE_ID_HINT_VXPROII_IDE), },
  172. { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C561), },
  173. { PCI_DEVICE(PCI_VENDOR_ID_OPTI, PCI_DEVICE_ID_OPTI_82C558), },
  174. { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO), },
  175. { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1), },
  176. { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2), },
  177. /* Must come last. If you add entries adjust this table appropriately */
  178. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL, 1},
  179. { 0, },
  180. };
  181. static struct pci_driver ata_generic_pci_driver = {
  182. .name = DRV_NAME,
  183. .id_table = ata_generic,
  184. .probe = ata_generic_init_one,
  185. .remove = ata_pci_remove_one,
  186. #ifdef CONFIG_PM
  187. .suspend = ata_pci_device_suspend,
  188. .resume = ata_pci_device_resume,
  189. #endif
  190. };
  191. static int __init ata_generic_init(void)
  192. {
  193. return pci_register_driver(&ata_generic_pci_driver);
  194. }
  195. static void __exit ata_generic_exit(void)
  196. {
  197. pci_unregister_driver(&ata_generic_pci_driver);
  198. }
  199. MODULE_AUTHOR("Alan Cox");
  200. MODULE_DESCRIPTION("low-level driver for generic ATA");
  201. MODULE_LICENSE("GPL");
  202. MODULE_DEVICE_TABLE(pci, ata_generic);
  203. MODULE_VERSION(DRV_VERSION);
  204. module_init(ata_generic_init);
  205. module_exit(ata_generic_exit);
  206. module_param(all_generic_ide, int, 0);