ide-generic.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 and m32r to use ide_platform host driver */
  15. #ifdef CONFIG_ARM
  16. #include <asm/irq.h>
  17. #endif
  18. #ifdef CONFIG_M32R
  19. #include <asm/m32r.h>
  20. #endif
  21. #define DRV_NAME "ide_generic"
  22. static int probe_mask;
  23. module_param(probe_mask, int, 0);
  24. MODULE_PARM_DESC(probe_mask, "probe mask for legacy ISA IDE ports");
  25. static const struct ide_port_info ide_generic_port_info = {
  26. .host_flags = IDE_HFLAG_NO_DMA,
  27. .chipset = ide_generic,
  28. };
  29. #ifdef CONFIG_ARM
  30. static const u16 legacy_bases[] = { 0x1f0 };
  31. static const int legacy_irqs[] = { IRQ_HARDDISK };
  32. #elif defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_MAPPI2) || \
  33. defined(CONFIG_PLAT_OPSPUT)
  34. static const u16 legacy_bases[] = { 0x1f0 };
  35. static const int legacy_irqs[] = { PLD_IRQ_CFIREQ };
  36. #elif defined(CONFIG_PLAT_MAPPI3)
  37. static const u16 legacy_bases[] = { 0x1f0, 0x170 };
  38. static const int legacy_irqs[] = { PLD_IRQ_CFIREQ, PLD_IRQ_IDEIREQ };
  39. #elif defined(CONFIG_ALPHA)
  40. static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168 };
  41. static const int legacy_irqs[] = { 14, 15, 11, 10 };
  42. #else
  43. static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168, 0x1e0, 0x160 };
  44. static const int legacy_irqs[] = { 14, 15, 11, 10, 8, 12 };
  45. #endif
  46. static void ide_generic_check_pci_legacy_iobases(int *primary, int *secondary)
  47. {
  48. #ifdef CONFIG_PCI
  49. struct pci_dev *p = NULL;
  50. u16 val;
  51. for_each_pci_dev(p) {
  52. if (pci_resource_start(p, 0) == 0x1f0)
  53. *primary = 1;
  54. if (pci_resource_start(p, 2) == 0x170)
  55. *secondary = 1;
  56. /* Cyrix CS55{1,2}0 pre SFF MWDMA ATA on the bridge */
  57. if (p->vendor == PCI_VENDOR_ID_CYRIX &&
  58. (p->device == PCI_DEVICE_ID_CYRIX_5510 ||
  59. p->device == PCI_DEVICE_ID_CYRIX_5520))
  60. *primary = *secondary = 1;
  61. /* Intel MPIIX - PIO ATA on non PCI side of bridge */
  62. if (p->vendor == PCI_VENDOR_ID_INTEL &&
  63. p->device == PCI_DEVICE_ID_INTEL_82371MX) {
  64. pci_read_config_word(p, 0x6C, &val);
  65. if (val & 0x8000) {
  66. /* ATA port enabled */
  67. if (val & 0x4000)
  68. *secondary = 1;
  69. else
  70. *primary = 1;
  71. }
  72. }
  73. }
  74. #endif
  75. }
  76. static int __init ide_generic_init(void)
  77. {
  78. struct ide_hw hw, *hws[] = { &hw };
  79. unsigned long io_addr;
  80. int i, rc = 0, primary = 0, secondary = 0;
  81. ide_generic_check_pci_legacy_iobases(&primary, &secondary);
  82. if (!probe_mask) {
  83. printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" "
  84. "module parameter for probing all legacy ISA IDE ports\n");
  85. if (primary == 0)
  86. probe_mask |= 0x1;
  87. if (secondary == 0)
  88. probe_mask |= 0x2;
  89. } else
  90. printk(KERN_INFO DRV_NAME ": enforcing probing of I/O ports "
  91. "upon user request\n");
  92. for (i = 0; i < ARRAY_SIZE(legacy_bases); i++) {
  93. io_addr = legacy_bases[i];
  94. if ((probe_mask & (1 << i)) && io_addr) {
  95. if (!request_region(io_addr, 8, DRV_NAME)) {
  96. printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX "
  97. "not free.\n",
  98. DRV_NAME, io_addr, io_addr + 7);
  99. rc = -EBUSY;
  100. continue;
  101. }
  102. if (!request_region(io_addr + 0x206, 1, DRV_NAME)) {
  103. printk(KERN_ERR "%s: I/O resource 0x%lX "
  104. "not free.\n",
  105. DRV_NAME, io_addr + 0x206);
  106. release_region(io_addr, 8);
  107. rc = -EBUSY;
  108. continue;
  109. }
  110. memset(&hw, 0, sizeof(hw));
  111. ide_std_init_ports(&hw, io_addr, io_addr + 0x206);
  112. #ifdef CONFIG_IA64
  113. hw.irq = isa_irq_to_vector(legacy_irqs[i]);
  114. #else
  115. hw.irq = legacy_irqs[i];
  116. #endif
  117. rc = ide_host_add(&ide_generic_port_info, hws, 1, NULL);
  118. if (rc) {
  119. release_region(io_addr + 0x206, 1);
  120. release_region(io_addr, 8);
  121. }
  122. }
  123. }
  124. return rc;
  125. }
  126. module_init(ide_generic_init);
  127. MODULE_LICENSE("GPL");