ide-generic.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * generic/default IDE host driver
  3. *
  4. * Copyright (C) 2004, 2008 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. /*
  10. * For special cases new interfaces may be added using sysfs, i.e.
  11. *
  12. * echo -n "0x168:0x36e:10" > /sys/class/ide_generic/add
  13. *
  14. * will add an interface using I/O ports 0x168-0x16f/0x36e and IRQ 10.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/module.h>
  19. #include <linux/ide.h>
  20. #include <linux/pci_ids.h>
  21. /* FIXME: convert m32r to use ide_platform host driver */
  22. #ifdef CONFIG_M32R
  23. #include <asm/m32r.h>
  24. #endif
  25. #define DRV_NAME "ide_generic"
  26. static int probe_mask;
  27. module_param(probe_mask, int, 0);
  28. MODULE_PARM_DESC(probe_mask, "probe mask for legacy ISA IDE ports");
  29. static ssize_t store_add(struct class *cls, const char *buf, size_t n)
  30. {
  31. unsigned int base, ctl;
  32. int irq, rc;
  33. hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
  34. if (sscanf(buf, "%x:%x:%d", &base, &ctl, &irq) != 3)
  35. return -EINVAL;
  36. memset(&hw, 0, sizeof(hw));
  37. ide_std_init_ports(&hw, base, ctl);
  38. hw.irq = irq;
  39. hw.chipset = ide_generic;
  40. rc = ide_host_add(NULL, hws, NULL);
  41. if (rc)
  42. return rc;
  43. return n;
  44. };
  45. static struct class_attribute ide_generic_class_attrs[] = {
  46. __ATTR(add, S_IWUSR, NULL, store_add),
  47. __ATTR_NULL
  48. };
  49. static void ide_generic_class_release(struct class *cls)
  50. {
  51. kfree(cls);
  52. }
  53. static int __init ide_generic_sysfs_init(void)
  54. {
  55. struct class *cls;
  56. int rc;
  57. cls = kzalloc(sizeof(*cls), GFP_KERNEL);
  58. if (!cls)
  59. return -ENOMEM;
  60. cls->name = DRV_NAME;
  61. cls->owner = THIS_MODULE;
  62. cls->class_release = ide_generic_class_release;
  63. cls->class_attrs = ide_generic_class_attrs;
  64. rc = class_register(cls);
  65. if (rc) {
  66. kfree(cls);
  67. return rc;
  68. }
  69. return 0;
  70. }
  71. #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_MAPPI2) \
  72. || defined(CONFIG_PLAT_OPSPUT)
  73. static const u16 legacy_bases[] = { 0x1f0 };
  74. static const int legacy_irqs[] = { PLD_IRQ_CFIREQ };
  75. #elif defined(CONFIG_PLAT_MAPPI3)
  76. static const u16 legacy_bases[] = { 0x1f0, 0x170 };
  77. static const int legacy_irqs[] = { PLD_IRQ_CFIREQ, PLD_IRQ_IDEIREQ };
  78. #elif defined(CONFIG_ALPHA)
  79. static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168 };
  80. static const int legacy_irqs[] = { 14, 15, 11, 10 };
  81. #else
  82. static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168, 0x1e0, 0x160 };
  83. static const int legacy_irqs[] = { 14, 15, 11, 10, 8, 12 };
  84. #endif
  85. static void ide_generic_check_pci_legacy_iobases(int *primary, int *secondary)
  86. {
  87. struct pci_dev *p = NULL;
  88. u16 val;
  89. for_each_pci_dev(p) {
  90. if (pci_resource_start(p, 0) == 0x1f0)
  91. *primary = 1;
  92. if (pci_resource_start(p, 2) == 0x170)
  93. *secondary = 1;
  94. /* Cyrix CS55{1,2}0 pre SFF MWDMA ATA on the bridge */
  95. if (p->vendor == PCI_VENDOR_ID_CYRIX &&
  96. (p->device == PCI_DEVICE_ID_CYRIX_5510 ||
  97. p->device == PCI_DEVICE_ID_CYRIX_5520))
  98. *primary = *secondary = 1;
  99. /* Intel MPIIX - PIO ATA on non PCI side of bridge */
  100. if (p->vendor == PCI_VENDOR_ID_INTEL &&
  101. p->device == PCI_DEVICE_ID_INTEL_82371MX) {
  102. pci_read_config_word(p, 0x6C, &val);
  103. if (val & 0x8000) {
  104. /* ATA port enabled */
  105. if (val & 0x4000)
  106. *secondary = 1;
  107. else
  108. *primary = 1;
  109. }
  110. }
  111. }
  112. }
  113. static int __init ide_generic_init(void)
  114. {
  115. hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
  116. unsigned long io_addr;
  117. int i, rc = 0, primary = 0, secondary = 0;
  118. ide_generic_check_pci_legacy_iobases(&primary, &secondary);
  119. if (!probe_mask) {
  120. printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" "
  121. "module parameter for probing all legacy ISA IDE ports\n");
  122. if (primary == 0)
  123. probe_mask |= 0x1;
  124. if (secondary == 0)
  125. probe_mask |= 0x2;
  126. } else
  127. printk(KERN_INFO DRV_NAME ": enforcing probing of I/O ports "
  128. "upon user request\n");
  129. for (i = 0; i < ARRAY_SIZE(legacy_bases); i++) {
  130. io_addr = legacy_bases[i];
  131. if ((probe_mask & (1 << i)) && io_addr) {
  132. if (!request_region(io_addr, 8, DRV_NAME)) {
  133. printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX "
  134. "not free.\n",
  135. DRV_NAME, io_addr, io_addr + 7);
  136. continue;
  137. }
  138. if (!request_region(io_addr + 0x206, 1, DRV_NAME)) {
  139. printk(KERN_ERR "%s: I/O resource 0x%lX "
  140. "not free.\n",
  141. DRV_NAME, io_addr + 0x206);
  142. release_region(io_addr, 8);
  143. continue;
  144. }
  145. memset(&hw, 0, sizeof(hw));
  146. ide_std_init_ports(&hw, io_addr, io_addr + 0x206);
  147. #ifdef CONFIG_IA64
  148. hw.irq = isa_irq_to_vector(legacy_irqs[i]);
  149. #else
  150. hw.irq = legacy_irqs[i];
  151. #endif
  152. hw.chipset = ide_generic;
  153. rc = ide_host_add(NULL, hws, NULL);
  154. if (rc) {
  155. release_region(io_addr + 0x206, 1);
  156. release_region(io_addr, 8);
  157. }
  158. }
  159. }
  160. if (ide_generic_sysfs_init())
  161. printk(KERN_ERR DRV_NAME ": failed to create ide_generic "
  162. "class\n");
  163. return rc;
  164. }
  165. module_init(ide_generic_init);
  166. MODULE_LICENSE("GPL");