ata_generic.c 6.8 KB

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