isa.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. #include <linux/kernel.h>
  2. #include <linux/init.h>
  3. #include <linux/pci.h>
  4. #include <linux/slab.h>
  5. #include <asm/oplib.h>
  6. #include <asm/isa.h>
  7. struct sparc_isa_bridge *isa_chain;
  8. static void __init fatal_err(const char *reason)
  9. {
  10. prom_printf("ISA: fatal error, %s.\n", reason);
  11. }
  12. static void __init report_dev(struct sparc_isa_device *isa_dev, int child)
  13. {
  14. if (child)
  15. printk(" (%s)", isa_dev->prom_node->name);
  16. else
  17. printk(" [%s", isa_dev->prom_node->name);
  18. }
  19. static struct linux_prom_registers * __init
  20. isa_dev_get_resource(struct sparc_isa_device *isa_dev)
  21. {
  22. struct linux_prom_registers *pregs;
  23. unsigned long base, len;
  24. int prop_len;
  25. pregs = of_get_property(isa_dev->prom_node, "reg", &prop_len);
  26. /* Only the first one is interesting. */
  27. len = pregs[0].reg_size;
  28. base = (((unsigned long)pregs[0].which_io << 32) |
  29. (unsigned long)pregs[0].phys_addr);
  30. base += isa_dev->bus->parent->io_space.start;
  31. isa_dev->resource.start = base;
  32. isa_dev->resource.end = (base + len - 1UL);
  33. isa_dev->resource.flags = IORESOURCE_IO;
  34. isa_dev->resource.name = isa_dev->prom_node->name;
  35. request_resource(&isa_dev->bus->parent->io_space,
  36. &isa_dev->resource);
  37. return pregs;
  38. }
  39. /* I can't believe they didn't put a real INO in the isa device
  40. * interrupts property. The whole point of the OBP properties
  41. * is to shield the kernel from IRQ routing details.
  42. *
  43. * The P1275 standard for ISA devices seems to also have been
  44. * totally ignored.
  45. *
  46. * On later systems, an interrupt-map and interrupt-map-mask scheme
  47. * akin to EBUS is used.
  48. */
  49. static struct {
  50. int obp_irq;
  51. int pci_ino;
  52. } grover_irq_table[] = {
  53. { 1, 0x00 }, /* dma, unknown ino at this point */
  54. { 2, 0x27 }, /* floppy */
  55. { 3, 0x22 }, /* parallel */
  56. { 4, 0x2b }, /* serial */
  57. { 5, 0x25 }, /* acpi power management */
  58. { 0, 0x00 } /* end of table */
  59. };
  60. static int __init isa_dev_get_irq_using_imap(struct sparc_isa_device *isa_dev,
  61. struct sparc_isa_bridge *isa_br,
  62. int *interrupt,
  63. struct linux_prom_registers *reg)
  64. {
  65. struct linux_prom_ebus_intmap *imap;
  66. struct linux_prom_ebus_intmap *imask;
  67. unsigned int hi, lo, irq;
  68. int i, len, n_imap;
  69. imap = of_get_property(isa_br->prom_node, "interrupt-map", &len);
  70. if (!imap)
  71. return 0;
  72. n_imap = len / sizeof(imap[0]);
  73. imask = of_get_property(isa_br->prom_node, "interrupt-map-mask", NULL);
  74. if (!imask)
  75. return 0;
  76. hi = reg->which_io & imask->phys_hi;
  77. lo = reg->phys_addr & imask->phys_lo;
  78. irq = *interrupt & imask->interrupt;
  79. for (i = 0; i < n_imap; i++) {
  80. if ((imap[i].phys_hi == hi) &&
  81. (imap[i].phys_lo == lo) &&
  82. (imap[i].interrupt == irq)) {
  83. *interrupt = imap[i].cinterrupt;
  84. return 0;
  85. }
  86. }
  87. return -1;
  88. }
  89. static void __init isa_dev_get_irq(struct sparc_isa_device *isa_dev,
  90. struct linux_prom_registers *pregs)
  91. {
  92. int irq_prop;
  93. irq_prop = of_getintprop_default(isa_dev->prom_node,
  94. "interrupts", -1);
  95. if (irq_prop <= 0) {
  96. goto no_irq;
  97. } else {
  98. struct pci_controller_info *pcic;
  99. struct pci_pbm_info *pbm;
  100. int i;
  101. if (of_find_property(isa_dev->bus->prom_node,
  102. "interrupt-map", NULL)) {
  103. if (!isa_dev_get_irq_using_imap(isa_dev,
  104. isa_dev->bus,
  105. &irq_prop,
  106. pregs))
  107. goto route_irq;
  108. }
  109. for (i = 0; grover_irq_table[i].obp_irq != 0; i++) {
  110. if (grover_irq_table[i].obp_irq == irq_prop) {
  111. int ino = grover_irq_table[i].pci_ino;
  112. if (ino == 0)
  113. goto no_irq;
  114. irq_prop = ino;
  115. goto route_irq;
  116. }
  117. }
  118. goto no_irq;
  119. route_irq:
  120. pbm = isa_dev->bus->parent;
  121. pcic = pbm->parent;
  122. isa_dev->irq = pcic->irq_build(pbm, NULL, irq_prop);
  123. return;
  124. }
  125. no_irq:
  126. isa_dev->irq = PCI_IRQ_NONE;
  127. }
  128. static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev)
  129. {
  130. struct device_node *dp = parent_isa_dev->prom_node->child;
  131. if (!dp)
  132. return;
  133. printk(" ->");
  134. while (dp) {
  135. struct linux_prom_registers *regs;
  136. struct sparc_isa_device *isa_dev;
  137. isa_dev = kmalloc(sizeof(*isa_dev), GFP_KERNEL);
  138. if (!isa_dev) {
  139. fatal_err("cannot allocate child isa_dev");
  140. prom_halt();
  141. }
  142. memset(isa_dev, 0, sizeof(*isa_dev));
  143. /* Link it in to parent. */
  144. isa_dev->next = parent_isa_dev->child;
  145. parent_isa_dev->child = isa_dev;
  146. isa_dev->bus = parent_isa_dev->bus;
  147. isa_dev->prom_node = dp;
  148. regs = isa_dev_get_resource(isa_dev);
  149. isa_dev_get_irq(isa_dev, regs);
  150. report_dev(isa_dev, 1);
  151. dp = dp->sibling;
  152. }
  153. }
  154. static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
  155. {
  156. struct device_node *dp = isa_br->prom_node->child;
  157. while (dp) {
  158. struct linux_prom_registers *regs;
  159. struct sparc_isa_device *isa_dev;
  160. isa_dev = kmalloc(sizeof(*isa_dev), GFP_KERNEL);
  161. if (!isa_dev) {
  162. printk(KERN_DEBUG "ISA: cannot allocate isa_dev");
  163. return;
  164. }
  165. memset(isa_dev, 0, sizeof(*isa_dev));
  166. isa_dev->ofdev.node = dp;
  167. isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev;
  168. isa_dev->ofdev.dev.bus = &isa_bus_type;
  169. strcpy(isa_dev->ofdev.dev.bus_id, dp->path_component_name);
  170. /* Register with core */
  171. if (of_device_register(&isa_dev->ofdev) != 0) {
  172. printk(KERN_DEBUG "isa: device registration error for %s!\n",
  173. isa_dev->ofdev.dev.bus_id);
  174. kfree(isa_dev);
  175. goto next_sibling;
  176. }
  177. /* Link it in. */
  178. isa_dev->next = NULL;
  179. if (isa_br->devices == NULL) {
  180. isa_br->devices = isa_dev;
  181. } else {
  182. struct sparc_isa_device *tmp = isa_br->devices;
  183. while (tmp->next)
  184. tmp = tmp->next;
  185. tmp->next = isa_dev;
  186. }
  187. isa_dev->bus = isa_br;
  188. isa_dev->prom_node = dp;
  189. regs = isa_dev_get_resource(isa_dev);
  190. isa_dev_get_irq(isa_dev, regs);
  191. report_dev(isa_dev, 0);
  192. isa_fill_children(isa_dev);
  193. printk("]");
  194. next_sibling:
  195. dp = dp->sibling;
  196. }
  197. }
  198. void __init isa_init(void)
  199. {
  200. struct pci_dev *pdev;
  201. unsigned short vendor, device;
  202. int index = 0;
  203. vendor = PCI_VENDOR_ID_AL;
  204. device = PCI_DEVICE_ID_AL_M1533;
  205. pdev = NULL;
  206. while ((pdev = pci_get_device(vendor, device, pdev)) != NULL) {
  207. struct pcidev_cookie *pdev_cookie;
  208. struct pci_pbm_info *pbm;
  209. struct sparc_isa_bridge *isa_br;
  210. struct device_node *dp;
  211. pdev_cookie = pdev->sysdata;
  212. if (!pdev_cookie) {
  213. printk("ISA: Warning, ISA bridge ignored due to "
  214. "lack of OBP data.\n");
  215. continue;
  216. }
  217. pbm = pdev_cookie->pbm;
  218. dp = pdev_cookie->prom_node;
  219. isa_br = kmalloc(sizeof(*isa_br), GFP_KERNEL);
  220. if (!isa_br) {
  221. printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge");
  222. return;
  223. }
  224. memset(isa_br, 0, sizeof(*isa_br));
  225. isa_br->ofdev.node = dp;
  226. isa_br->ofdev.dev.parent = &pdev->dev;
  227. isa_br->ofdev.dev.bus = &isa_bus_type;
  228. strcpy(isa_br->ofdev.dev.bus_id, dp->path_component_name);
  229. /* Register with core */
  230. if (of_device_register(&isa_br->ofdev) != 0) {
  231. printk(KERN_DEBUG "isa: device registration error for %s!\n",
  232. isa_br->ofdev.dev.bus_id);
  233. kfree(isa_br);
  234. return;
  235. }
  236. /* Link it in. */
  237. isa_br->next = isa_chain;
  238. isa_chain = isa_br;
  239. isa_br->parent = pbm;
  240. isa_br->self = pdev;
  241. isa_br->index = index++;
  242. isa_br->prom_node = pdev_cookie->prom_node;
  243. printk("isa%d:", isa_br->index);
  244. isa_fill_devices(isa_br);
  245. printk("\n");
  246. }
  247. }