isa.c 4.9 KB

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