ide-generic.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * generic/default IDE host driver
  3. *
  4. * Copyright (C) 2004, 2008-2009 Bartlomiej Zolnierkiewicz
  5. * This code was split off from ide.c. See it for original copyrights.
  6. *
  7. * May be copied or modified under the terms of the GNU General Public License.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <linux/module.h>
  12. #include <linux/ide.h>
  13. #include <linux/pci_ids.h>
  14. /* FIXME: convert arm to use ide_platform host driver */
  15. #ifdef CONFIG_ARM
  16. #include <asm/irq.h>
  17. #endif
  18. #define DRV_NAME "ide_generic"
  19. static int probe_mask;
  20. module_param(probe_mask, int, 0);
  21. MODULE_PARM_DESC(probe_mask, "probe mask for legacy ISA IDE ports");
  22. static const struct ide_port_info ide_generic_port_info = {
  23. .host_flags = IDE_HFLAG_NO_DMA,
  24. .chipset = ide_generic,
  25. };
  26. #ifdef CONFIG_ARM
  27. static const u16 legacy_bases[] = { 0x1f0 };
  28. static const int legacy_irqs[] = { IRQ_HARDDISK };
  29. #elif defined(CONFIG_ALPHA)
  30. static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168 };
  31. static const int legacy_irqs[] = { 14, 15, 11, 10 };
  32. #else
  33. static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168, 0x1e0, 0x160 };
  34. static const int legacy_irqs[] = { 14, 15, 11, 10, 8, 12 };
  35. #endif
  36. static void ide_generic_check_pci_legacy_iobases(int *primary, int *secondary)
  37. {
  38. #ifdef CONFIG_PCI
  39. struct pci_dev *p = NULL;
  40. u16 val;
  41. for_each_pci_dev(p) {
  42. if (pci_resource_start(p, 0) == 0x1f0)
  43. *primary = 1;
  44. if (pci_resource_start(p, 2) == 0x170)
  45. *secondary = 1;
  46. /* Cyrix CS55{1,2}0 pre SFF MWDMA ATA on the bridge */
  47. if (p->vendor == PCI_VENDOR_ID_CYRIX &&
  48. (p->device == PCI_DEVICE_ID_CYRIX_5510 ||
  49. p->device == PCI_DEVICE_ID_CYRIX_5520))
  50. *primary = *secondary = 1;
  51. /* Intel MPIIX - PIO ATA on non PCI side of bridge */
  52. if (p->vendor == PCI_VENDOR_ID_INTEL &&
  53. p->device == PCI_DEVICE_ID_INTEL_82371MX) {
  54. pci_read_config_word(p, 0x6C, &val);
  55. if (val & 0x8000) {
  56. /* ATA port enabled */
  57. if (val & 0x4000)
  58. *secondary = 1;
  59. else
  60. *primary = 1;
  61. }
  62. }
  63. }
  64. #endif
  65. }
  66. static int __init ide_generic_init(void)
  67. {
  68. struct ide_hw hw, *hws[] = { &hw };
  69. unsigned long io_addr;
  70. int i, rc = 0, primary = 0, secondary = 0;
  71. ide_generic_check_pci_legacy_iobases(&primary, &secondary);
  72. if (!probe_mask) {
  73. printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" "
  74. "module parameter for probing all legacy ISA IDE ports\n");
  75. if (primary == 0)
  76. probe_mask |= 0x1;
  77. if (secondary == 0)
  78. probe_mask |= 0x2;
  79. } else
  80. printk(KERN_INFO DRV_NAME ": enforcing probing of I/O ports "
  81. "upon user request\n");
  82. for (i = 0; i < ARRAY_SIZE(legacy_bases); i++) {
  83. io_addr = legacy_bases[i];
  84. if ((probe_mask & (1 << i)) && io_addr) {
  85. if (!request_region(io_addr, 8, DRV_NAME)) {
  86. printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX "
  87. "not free.\n",
  88. DRV_NAME, io_addr, io_addr + 7);
  89. rc = -EBUSY;
  90. continue;
  91. }
  92. if (!request_region(io_addr + 0x206, 1, DRV_NAME)) {
  93. printk(KERN_ERR "%s: I/O resource 0x%lX "
  94. "not free.\n",
  95. DRV_NAME, io_addr + 0x206);
  96. release_region(io_addr, 8);
  97. rc = -EBUSY;
  98. continue;
  99. }
  100. memset(&hw, 0, sizeof(hw));
  101. ide_std_init_ports(&hw, io_addr, io_addr + 0x206);
  102. #ifdef CONFIG_IA64
  103. hw.irq = isa_irq_to_vector(legacy_irqs[i]);
  104. #else
  105. hw.irq = legacy_irqs[i];
  106. #endif
  107. rc = ide_host_add(&ide_generic_port_info, hws, 1, NULL);
  108. if (rc) {
  109. release_region(io_addr + 0x206, 1);
  110. release_region(io_addr, 8);
  111. }
  112. }
  113. }
  114. return rc;
  115. }
  116. module_init(ide_generic_init);
  117. MODULE_LICENSE("GPL");