ide-generic.c 5.0 KB

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