ata_generic.c 7.1 KB

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