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