sbus.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. sdev->prom_node = dp->node;
  43. strcpy(sdev->prom_name, dp->name);
  44. sd = &sdev->ofdev.dev.archdata;
  45. sd->prom_node = dp;
  46. sd->op = &sdev->ofdev;
  47. sdev->ofdev.node = dp;
  48. if (sdev->parent)
  49. sdev->ofdev.dev.parent = &sdev->parent->ofdev.dev;
  50. else
  51. sdev->ofdev.dev.parent = &sdev->bus->ofdev.dev;
  52. sdev->ofdev.dev.bus = &sbus_bus_type;
  53. dev_set_name(&sdev->ofdev.dev, "sbus[%08x]", dp->node);
  54. if (of_device_register(&sdev->ofdev) != 0)
  55. printk(KERN_DEBUG "sbus: device registration error for %s!\n",
  56. dp->path_component_name);
  57. /* WE HAVE BEEN INVADED BY ALIENS! */
  58. err = sysfs_create_file(&sdev->ofdev.dev.kobj, &dev_attr_obppath.attr);
  59. fill_sbus_device_iommu(sdev);
  60. }
  61. static void __init sdev_insert(struct sbus_dev *sdev, struct sbus_dev **root)
  62. {
  63. while (*root)
  64. root = &(*root)->next;
  65. *root = sdev;
  66. sdev->next = NULL;
  67. }
  68. static void __init walk_children(struct device_node *dp, struct sbus_dev *parent, struct sbus_bus *sbus)
  69. {
  70. dp = dp->child;
  71. while (dp) {
  72. struct sbus_dev *sdev;
  73. sdev = kzalloc(sizeof(struct sbus_dev), GFP_ATOMIC);
  74. if (sdev) {
  75. sdev_insert(sdev, &parent->child);
  76. sdev->bus = sbus;
  77. sdev->parent = parent;
  78. fill_sbus_device(dp, sdev);
  79. walk_children(dp, sdev, sbus);
  80. }
  81. dp = dp->sibling;
  82. }
  83. }
  84. static void __init build_one_sbus(struct device_node *dp, int num_sbus)
  85. {
  86. struct sbus_bus *sbus;
  87. unsigned int sbus_clock;
  88. struct device_node *dev_dp;
  89. sbus = kzalloc(sizeof(struct sbus_bus), GFP_ATOMIC);
  90. if (!sbus)
  91. return;
  92. sbus->prom_node = dp->node;
  93. sbus_setup_iommu(sbus, dp);
  94. printk("sbus%d: ", num_sbus);
  95. sbus_clock = of_getintprop_default(dp, "clock-frequency",
  96. (25*1000*1000));
  97. sbus->clock_freq = sbus_clock;
  98. printk("Clock %d.%d MHz\n", (int) ((sbus_clock/1000)/1000),
  99. (int) (((sbus_clock/1000)%1000 != 0) ?
  100. (((sbus_clock/1000)%1000) + 1000) : 0));
  101. strcpy(sbus->prom_name, dp->name);
  102. sbus->ofdev.node = dp;
  103. sbus->ofdev.dev.parent = NULL;
  104. sbus->ofdev.dev.bus = &sbus_bus_type;
  105. dev_set_name(&sbus->ofdev.dev, "sbus%d", num_sbus);
  106. if (of_device_register(&sbus->ofdev) != 0)
  107. printk(KERN_DEBUG "sbus: device registration error for %s!\n",
  108. dev_name(&sbus->ofdev.dev));
  109. dev_dp = dp->child;
  110. while (dev_dp) {
  111. struct sbus_dev *sdev;
  112. sdev = kzalloc(sizeof(struct sbus_dev), GFP_ATOMIC);
  113. if (sdev) {
  114. sdev_insert(sdev, &sbus->devices);
  115. sdev->bus = sbus;
  116. sdev->parent = NULL;
  117. sdev->ofdev.dev.archdata.iommu =
  118. sbus->ofdev.dev.archdata.iommu;
  119. sdev->ofdev.dev.archdata.stc =
  120. sbus->ofdev.dev.archdata.stc;
  121. fill_sbus_device(dev_dp, sdev);
  122. walk_children(dev_dp, sdev, sbus);
  123. }
  124. dev_dp = dev_dp->sibling;
  125. }
  126. }
  127. static int __init sbus_init(void)
  128. {
  129. struct device_node *dp;
  130. const char *sbus_name = "sbus";
  131. int num_sbus = 0;
  132. if (sbus_arch_preinit())
  133. return 0;
  134. if (sparc_cpu_model == sun4d)
  135. sbus_name = "sbi";
  136. for_each_node_by_name(dp, sbus_name) {
  137. build_one_sbus(dp, num_sbus);
  138. num_sbus++;
  139. }
  140. sbus_arch_postinit();
  141. return 0;
  142. }
  143. subsys_initcall(sbus_init);