1 /* sbus.c: SBus support routines.
3 * Copyright (C) 1995, 2006 David S. Miller (davem@davemloft.net)
6 #include <linux/kernel.h>
7 #include <linux/slab.h>
8 #include <linux/init.h>
9 #include <linux/device.h>
10 #include <linux/of_device.h>
12 #include <asm/system.h>
15 #include <asm/oplib.h>
20 show_sbusobppath_attr(struct device * dev, struct device_attribute * attr, char * buf)
22 struct sbus_dev *sbus;
24 sbus = to_sbus_device(dev);
26 return snprintf (buf, PAGE_SIZE, "%s\n", sbus->ofdev.node->full_name);
29 static DEVICE_ATTR(obppath, S_IRUSR | S_IRGRP | S_IROTH, show_sbusobppath_attr, NULL);
31 struct sbus_bus *sbus_root;
33 static void __init fill_sbus_device_iommu(struct sbus_dev *sdev)
35 struct of_device *op = of_find_device_by_node(sdev->ofdev.node);
36 struct dev_archdata *sd, *bus_sd;
37 struct sbus_bus *sbus;
40 bus_sd = &sbus->ofdev.dev.archdata;
42 sd = &sdev->ofdev.dev.archdata;
43 sd->iommu = bus_sd->iommu;
44 sd->stc = bus_sd->stc;
46 sd = &op->dev.archdata;
47 sd->iommu = bus_sd->iommu;
48 sd->stc = bus_sd->stc;
51 static void __init fill_sbus_device(struct device_node *dp, struct sbus_dev *sdev)
53 struct dev_archdata *sd;
56 sdev->prom_node = dp->node;
57 strcpy(sdev->prom_name, dp->name);
59 sd = &sdev->ofdev.dev.archdata;
61 sd->op = &sdev->ofdev;
63 sdev->ofdev.node = dp;
65 sdev->ofdev.dev.parent = &sdev->parent->ofdev.dev;
67 sdev->ofdev.dev.parent = &sdev->bus->ofdev.dev;
68 sdev->ofdev.dev.bus = &sbus_bus_type;
69 dev_set_name(&sdev->ofdev.dev, "sbus[%08x]", dp->node);
71 if (of_device_register(&sdev->ofdev) != 0)
72 printk(KERN_DEBUG "sbus: device registration error for %s!\n",
73 dp->path_component_name);
75 /* WE HAVE BEEN INVADED BY ALIENS! */
76 err = sysfs_create_file(&sdev->ofdev.dev.kobj, &dev_attr_obppath.attr);
78 fill_sbus_device_iommu(sdev);
81 /* We preserve the "probe order" of these bus and device lists to give
82 * the same ordering as the old code.
84 static void __init sbus_insert(struct sbus_bus *sbus, struct sbus_bus **root)
87 root = &(*root)->next;
92 static void __init sdev_insert(struct sbus_dev *sdev, struct sbus_dev **root)
95 root = &(*root)->next;
100 static void __init walk_children(struct device_node *dp, struct sbus_dev *parent, struct sbus_bus *sbus)
104 struct sbus_dev *sdev;
106 sdev = kzalloc(sizeof(struct sbus_dev), GFP_ATOMIC);
108 sdev_insert(sdev, &parent->child);
111 sdev->parent = parent;
113 fill_sbus_device(dp, sdev);
115 walk_children(dp, sdev, sbus);
121 static void __init build_one_sbus(struct device_node *dp, int num_sbus)
123 struct sbus_bus *sbus;
124 unsigned int sbus_clock;
125 struct device_node *dev_dp;
127 sbus = kzalloc(sizeof(struct sbus_bus), GFP_ATOMIC);
131 sbus_insert(sbus, &sbus_root);
132 sbus->prom_node = dp->node;
134 sbus_setup_iommu(sbus, dp);
136 printk("sbus%d: ", num_sbus);
138 sbus_clock = of_getintprop_default(dp, "clock-frequency",
140 sbus->clock_freq = sbus_clock;
142 printk("Clock %d.%d MHz\n", (int) ((sbus_clock/1000)/1000),
143 (int) (((sbus_clock/1000)%1000 != 0) ?
144 (((sbus_clock/1000)%1000) + 1000) : 0));
146 strcpy(sbus->prom_name, dp->name);
148 sbus->ofdev.node = dp;
149 sbus->ofdev.dev.parent = NULL;
150 sbus->ofdev.dev.bus = &sbus_bus_type;
151 dev_set_name(&sbus->ofdev.dev, "sbus%d", num_sbus);
153 if (of_device_register(&sbus->ofdev) != 0)
154 printk(KERN_DEBUG "sbus: device registration error for %s!\n",
155 dev_name(&sbus->ofdev.dev));
159 struct sbus_dev *sdev;
161 sdev = kzalloc(sizeof(struct sbus_dev), GFP_ATOMIC);
163 sdev_insert(sdev, &sbus->devices);
167 sdev->ofdev.dev.archdata.iommu =
168 sbus->ofdev.dev.archdata.iommu;
169 sdev->ofdev.dev.archdata.stc =
170 sbus->ofdev.dev.archdata.stc;
172 fill_sbus_device(dev_dp, sdev);
174 walk_children(dev_dp, sdev, sbus);
176 dev_dp = dev_dp->sibling;
180 static int __init sbus_init(void)
182 struct device_node *dp;
183 const char *sbus_name = "sbus";
186 if (sbus_arch_preinit())
189 if (sparc_cpu_model == sun4d)
192 for_each_node_by_name(dp, sbus_name) {
193 build_one_sbus(dp, num_sbus);
198 sbus_arch_postinit();
203 subsys_initcall(sbus_init);