sbus.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* sbus.c: SBus support routines.
  2. *
  3. * Copyright (C) 1995, 2006 David S. Miller (davem@davemloft.net)
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/slab.h>
  7. #include <linux/init.h>
  8. #include <linux/device.h>
  9. #include <linux/of_device.h>
  10. #include <asm/system.h>
  11. #include <asm/sbus.h>
  12. #include <asm/dma.h>
  13. #include <asm/oplib.h>
  14. #include <asm/prom.h>
  15. #include <asm/irq.h>
  16. static ssize_t
  17. show_sbusobppath_attr(struct device * dev, struct device_attribute * attr, char * buf)
  18. {
  19. struct sbus_dev *sbus;
  20. sbus = to_sbus_device(dev);
  21. return snprintf (buf, PAGE_SIZE, "%s\n", sbus->ofdev.node->full_name);
  22. }
  23. static DEVICE_ATTR(obppath, S_IRUSR | S_IRGRP | S_IROTH, show_sbusobppath_attr, NULL);
  24. static void __init fill_sbus_device_iommu(struct sbus_dev *sdev)
  25. {
  26. struct of_device *op = of_find_device_by_node(sdev->ofdev.node);
  27. struct dev_archdata *sd, *bus_sd;
  28. struct sbus_bus *sbus;
  29. sbus = sdev->bus;
  30. bus_sd = &sbus->ofdev.dev.archdata;
  31. sd = &sdev->ofdev.dev.archdata;
  32. sd->iommu = bus_sd->iommu;
  33. sd->stc = bus_sd->stc;
  34. sd = &op->dev.archdata;
  35. sd->iommu = bus_sd->iommu;
  36. sd->stc = bus_sd->stc;
  37. }
  38. static void __init fill_sbus_device(struct device_node *dp, struct sbus_dev *sdev)
  39. {
  40. struct dev_archdata *sd;
  41. int err;
  42. sd = &sdev->ofdev.dev.archdata;
  43. sd->prom_node = dp;
  44. sd->op = &sdev->ofdev;
  45. sdev->ofdev.node = dp;
  46. if (sdev->parent)
  47. sdev->ofdev.dev.parent = &sdev->parent->ofdev.dev;
  48. else
  49. sdev->ofdev.dev.parent = &sdev->bus->ofdev.dev;
  50. sdev->ofdev.dev.bus = &sbus_bus_type;
  51. dev_set_name(&sdev->ofdev.dev, "sbus[%08x]", dp->node);
  52. if (of_device_register(&sdev->ofdev) != 0)
  53. printk(KERN_DEBUG "sbus: device registration error for %s!\n",
  54. dp->path_component_name);
  55. /* WE HAVE BEEN INVADED BY ALIENS! */
  56. err = sysfs_create_file(&sdev->ofdev.dev.kobj, &dev_attr_obppath.attr);
  57. fill_sbus_device_iommu(sdev);
  58. }
  59. static void __init sdev_insert(struct sbus_dev *sdev, struct sbus_dev **root)
  60. {
  61. while (*root)
  62. root = &(*root)->next;
  63. *root = sdev;
  64. sdev->next = NULL;
  65. }
  66. static void __init walk_children(struct device_node *dp, struct sbus_dev *parent, struct sbus_bus *sbus)
  67. {
  68. dp = dp->child;
  69. while (dp) {
  70. struct sbus_dev *sdev;
  71. sdev = kzalloc(sizeof(struct sbus_dev), GFP_ATOMIC);
  72. if (sdev) {
  73. sdev_insert(sdev, &parent->child);
  74. sdev->bus = sbus;
  75. sdev->parent = parent;
  76. fill_sbus_device(dp, sdev);
  77. walk_children(dp, sdev, sbus);
  78. }
  79. dp = dp->sibling;
  80. }
  81. }
  82. static void __init build_one_sbus(struct device_node *dp, int num_sbus)
  83. {
  84. struct device_node *dev_dp;
  85. struct sbus_bus *sbus;
  86. sbus = kzalloc(sizeof(struct sbus_bus), GFP_ATOMIC);
  87. if (!sbus)
  88. return;
  89. sbus_setup_iommu(sbus, dp);
  90. printk("sbus%d: ", num_sbus);
  91. sbus->ofdev.node = dp;
  92. sbus->ofdev.dev.parent = NULL;
  93. sbus->ofdev.dev.bus = &sbus_bus_type;
  94. dev_set_name(&sbus->ofdev.dev, "sbus%d", num_sbus);
  95. if (of_device_register(&sbus->ofdev) != 0)
  96. printk(KERN_DEBUG "sbus: device registration error for %s!\n",
  97. dev_name(&sbus->ofdev.dev));
  98. dev_dp = dp->child;
  99. while (dev_dp) {
  100. struct sbus_dev *sdev;
  101. sdev = kzalloc(sizeof(struct sbus_dev), GFP_ATOMIC);
  102. if (sdev) {
  103. sdev_insert(sdev, &sbus->devices);
  104. sdev->bus = sbus;
  105. sdev->parent = NULL;
  106. sdev->ofdev.dev.archdata.iommu =
  107. sbus->ofdev.dev.archdata.iommu;
  108. sdev->ofdev.dev.archdata.stc =
  109. sbus->ofdev.dev.archdata.stc;
  110. fill_sbus_device(dev_dp, sdev);
  111. walk_children(dev_dp, sdev, sbus);
  112. }
  113. dev_dp = dev_dp->sibling;
  114. }
  115. }
  116. static int __init sbus_init(void)
  117. {
  118. struct device_node *dp;
  119. const char *sbus_name = "sbus";
  120. int num_sbus = 0;
  121. if (sparc_cpu_model == sun4d)
  122. sbus_name = "sbi";
  123. for_each_node_by_name(dp, sbus_name) {
  124. build_one_sbus(dp, num_sbus);
  125. num_sbus++;
  126. }
  127. sbus_arch_postinit();
  128. return 0;
  129. }
  130. subsys_initcall(sbus_init);