isa.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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/prom.h>
  7. #include <asm/of_device.h>
  8. #include <asm/isa.h>
  9. struct sparc_isa_bridge *isa_chain;
  10. static void __init fatal_err(const char *reason)
  11. {
  12. prom_printf("ISA: fatal error, %s.\n", reason);
  13. }
  14. static void __init report_dev(struct sparc_isa_device *isa_dev, int child)
  15. {
  16. if (child)
  17. printk(" (%s)", isa_dev->prom_node->name);
  18. else
  19. printk(" [%s", isa_dev->prom_node->name);
  20. }
  21. static void __init isa_dev_get_resource(struct sparc_isa_device *isa_dev)
  22. {
  23. struct linux_prom_registers *pregs;
  24. unsigned long base, len;
  25. int prop_len;
  26. pregs = of_get_property(isa_dev->prom_node, "reg", &prop_len);
  27. if (!pregs)
  28. return;
  29. /* Only the first one is interesting. */
  30. len = pregs[0].reg_size;
  31. base = (((unsigned long)pregs[0].which_io << 32) |
  32. (unsigned long)pregs[0].phys_addr);
  33. base += isa_dev->bus->parent->io_space.start;
  34. isa_dev->resource.start = base;
  35. isa_dev->resource.end = (base + len - 1UL);
  36. isa_dev->resource.flags = IORESOURCE_IO;
  37. isa_dev->resource.name = isa_dev->prom_node->name;
  38. request_resource(&isa_dev->bus->parent->io_space,
  39. &isa_dev->resource);
  40. }
  41. static void __init isa_dev_get_irq(struct sparc_isa_device *isa_dev)
  42. {
  43. struct of_device *op = of_find_device_by_node(isa_dev->prom_node);
  44. if (!op || !op->num_irqs) {
  45. isa_dev->irq = PCI_IRQ_NONE;
  46. } else {
  47. isa_dev->irq = op->irqs[0];
  48. }
  49. }
  50. static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev)
  51. {
  52. struct device_node *dp = parent_isa_dev->prom_node->child;
  53. if (!dp)
  54. return;
  55. printk(" ->");
  56. while (dp) {
  57. struct sparc_isa_device *isa_dev;
  58. isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL);
  59. if (!isa_dev) {
  60. fatal_err("cannot allocate child isa_dev");
  61. prom_halt();
  62. }
  63. /* Link it in to parent. */
  64. isa_dev->next = parent_isa_dev->child;
  65. parent_isa_dev->child = isa_dev;
  66. isa_dev->bus = parent_isa_dev->bus;
  67. isa_dev->prom_node = dp;
  68. isa_dev_get_resource(isa_dev);
  69. isa_dev_get_irq(isa_dev);
  70. report_dev(isa_dev, 1);
  71. dp = dp->sibling;
  72. }
  73. }
  74. static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
  75. {
  76. struct device_node *dp = isa_br->prom_node->child;
  77. while (dp) {
  78. struct sparc_isa_device *isa_dev;
  79. isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL);
  80. if (!isa_dev) {
  81. printk(KERN_DEBUG "ISA: cannot allocate isa_dev");
  82. return;
  83. }
  84. isa_dev->ofdev.node = dp;
  85. isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev;
  86. isa_dev->ofdev.dev.bus = &isa_bus_type;
  87. sprintf(isa_dev->ofdev.dev.bus_id, "isa[%08x]", dp->node);
  88. /* Register with core */
  89. if (of_device_register(&isa_dev->ofdev) != 0) {
  90. printk(KERN_DEBUG "isa: device registration error for %s!\n",
  91. dp->path_component_name);
  92. kfree(isa_dev);
  93. goto next_sibling;
  94. }
  95. /* Link it in. */
  96. isa_dev->next = NULL;
  97. if (isa_br->devices == NULL) {
  98. isa_br->devices = isa_dev;
  99. } else {
  100. struct sparc_isa_device *tmp = isa_br->devices;
  101. while (tmp->next)
  102. tmp = tmp->next;
  103. tmp->next = isa_dev;
  104. }
  105. isa_dev->bus = isa_br;
  106. isa_dev->prom_node = dp;
  107. isa_dev_get_resource(isa_dev);
  108. isa_dev_get_irq(isa_dev);
  109. report_dev(isa_dev, 0);
  110. isa_fill_children(isa_dev);
  111. printk("]");
  112. next_sibling:
  113. dp = dp->sibling;
  114. }
  115. }
  116. void __init isa_init(void)
  117. {
  118. struct pci_dev *pdev;
  119. unsigned short vendor, device;
  120. int index = 0;
  121. vendor = PCI_VENDOR_ID_AL;
  122. device = PCI_DEVICE_ID_AL_M1533;
  123. pdev = NULL;
  124. while ((pdev = pci_get_device(vendor, device, pdev)) != NULL) {
  125. struct pcidev_cookie *pdev_cookie;
  126. struct pci_pbm_info *pbm;
  127. struct sparc_isa_bridge *isa_br;
  128. struct device_node *dp;
  129. pdev_cookie = pdev->sysdata;
  130. if (!pdev_cookie) {
  131. printk("ISA: Warning, ISA bridge ignored due to "
  132. "lack of OBP data.\n");
  133. continue;
  134. }
  135. pbm = pdev_cookie->pbm;
  136. dp = pdev_cookie->prom_node;
  137. isa_br = kzalloc(sizeof(*isa_br), GFP_KERNEL);
  138. if (!isa_br) {
  139. printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge");
  140. return;
  141. }
  142. isa_br->ofdev.node = dp;
  143. isa_br->ofdev.dev.parent = &pdev->dev;
  144. isa_br->ofdev.dev.bus = &isa_bus_type;
  145. sprintf(isa_br->ofdev.dev.bus_id, "isa%d", index);
  146. /* Register with core */
  147. if (of_device_register(&isa_br->ofdev) != 0) {
  148. printk(KERN_DEBUG "isa: device registration error for %s!\n",
  149. dp->path_component_name);
  150. kfree(isa_br);
  151. return;
  152. }
  153. /* Link it in. */
  154. isa_br->next = isa_chain;
  155. isa_chain = isa_br;
  156. isa_br->parent = pbm;
  157. isa_br->self = pdev;
  158. isa_br->index = index++;
  159. isa_br->prom_node = pdev_cookie->prom_node;
  160. printk("isa%d:", isa_br->index);
  161. isa_fill_devices(isa_br);
  162. printk("\n");
  163. }
  164. }