ide-generic.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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[MAX_HWIFS], *hws[MAX_HWIFS];
  116. struct ide_host *host;
  117. unsigned long io_addr;
  118. int i, rc, primary = 0, secondary = 0;
  119. #ifdef CONFIG_MIPS
  120. if (!ide_probe_legacy())
  121. return -ENODEV;
  122. #endif
  123. ide_generic_check_pci_legacy_iobases(&primary, &secondary);
  124. if (!probe_mask) {
  125. printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" "
  126. "module parameter for probing all legacy ISA IDE ports\n");
  127. if (primary == 0)
  128. probe_mask |= 0x1;
  129. if (secondary == 0)
  130. probe_mask |= 0x2;
  131. } else
  132. printk(KERN_INFO DRV_NAME ": enforcing probing of I/O ports "
  133. "upon user request\n");
  134. memset(hws, 0, sizeof(hw_regs_t *) * MAX_HWIFS);
  135. for (i = 0; i < ARRAY_SIZE(legacy_bases); i++) {
  136. io_addr = legacy_bases[i];
  137. hws[i] = NULL;
  138. if ((probe_mask & (1 << i)) && io_addr) {
  139. if (!request_region(io_addr, 8, DRV_NAME)) {
  140. printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX "
  141. "not free.\n",
  142. DRV_NAME, io_addr, io_addr + 7);
  143. continue;
  144. }
  145. if (!request_region(io_addr + 0x206, 1, DRV_NAME)) {
  146. printk(KERN_ERR "%s: I/O resource 0x%lX "
  147. "not free.\n",
  148. DRV_NAME, io_addr + 0x206);
  149. release_region(io_addr, 8);
  150. continue;
  151. }
  152. memset(&hw[i], 0, sizeof(hw[i]));
  153. ide_std_init_ports(&hw[i], io_addr, io_addr + 0x206);
  154. #ifdef CONFIG_IA64
  155. hw[i].irq = isa_irq_to_vector(legacy_irqs[i]);
  156. #else
  157. hw[i].irq = legacy_irqs[i];
  158. #endif
  159. hw[i].chipset = ide_generic;
  160. hws[i] = &hw[i];
  161. }
  162. }
  163. host = ide_host_alloc_all(NULL, hws);
  164. if (host == NULL) {
  165. rc = -ENOMEM;
  166. goto err;
  167. }
  168. rc = ide_host_register(host, NULL, hws);
  169. if (rc)
  170. goto err_free;
  171. if (ide_generic_sysfs_init())
  172. printk(KERN_ERR DRV_NAME ": failed to create ide_generic "
  173. "class\n");
  174. return 0;
  175. err_free:
  176. ide_host_free(host);
  177. err:
  178. for (i = 0; i < MAX_HWIFS; i++) {
  179. if (hws[i] == NULL)
  180. continue;
  181. io_addr = hws[i]->io_ports.data_addr;
  182. release_region(io_addr + 0x206, 1);
  183. release_region(io_addr, 8);
  184. }
  185. return rc;
  186. }
  187. module_init(ide_generic_init);
  188. MODULE_LICENSE("GPL");