sbus.c 3.7 KB
Newer Older
1
/* sbus.c: SBus support routines.
L
Linus Torvalds 已提交
2
 *
3
 * Copyright (C) 1995, 2006 David S. Miller (davem@davemloft.net)
L
Linus Torvalds 已提交
4 5 6 7 8
 */

#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/init.h>
9
#include <linux/device.h>
10
#include <linux/of_device.h>
L
Linus Torvalds 已提交
11 12 13 14 15

#include <asm/system.h>
#include <asm/sbus.h>
#include <asm/dma.h>
#include <asm/oplib.h>
16
#include <asm/prom.h>
L
Linus Torvalds 已提交
17 18
#include <asm/irq.h>

19 20 21 22 23 24 25 26 27 28 29 30
static ssize_t
show_sbusobppath_attr(struct device * dev, struct device_attribute * attr, char * buf)
{
	struct sbus_dev *sbus;

	sbus = to_sbus_device(dev);

	return snprintf (buf, PAGE_SIZE, "%s\n", sbus->ofdev.node->full_name);
}

static DEVICE_ATTR(obppath, S_IRUSR | S_IRGRP | S_IROTH, show_sbusobppath_attr, NULL);

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
static void __init fill_sbus_device_iommu(struct sbus_dev *sdev)
{
	struct of_device *op = of_find_device_by_node(sdev->ofdev.node);
	struct dev_archdata *sd, *bus_sd;
	struct sbus_bus *sbus;

	sbus = sdev->bus;
	bus_sd = &sbus->ofdev.dev.archdata;

	sd = &sdev->ofdev.dev.archdata;
	sd->iommu = bus_sd->iommu;
	sd->stc = bus_sd->stc;

	sd = &op->dev.archdata;
	sd->iommu = bus_sd->iommu;
	sd->stc = bus_sd->stc;
}

49
static void __init fill_sbus_device(struct device_node *dp, struct sbus_dev *sdev)
L
Linus Torvalds 已提交
50
{
51
	struct dev_archdata *sd;
52
	int err;
L
Linus Torvalds 已提交
53

54 55 56 57
	sd = &sdev->ofdev.dev.archdata;
	sd->prom_node = dp;
	sd->op = &sdev->ofdev;

58 59 60 61 62 63
	sdev->ofdev.node = dp;
	if (sdev->parent)
		sdev->ofdev.dev.parent = &sdev->parent->ofdev.dev;
	else
		sdev->ofdev.dev.parent = &sdev->bus->ofdev.dev;
	sdev->ofdev.dev.bus = &sbus_bus_type;
64
	dev_set_name(&sdev->ofdev.dev, "sbus[%08x]", dp->node);
65 66 67

	if (of_device_register(&sdev->ofdev) != 0)
		printk(KERN_DEBUG "sbus: device registration error for %s!\n",
68
		       dp->path_component_name);
69 70 71

	/* WE HAVE BEEN INVADED BY ALIENS! */
	err = sysfs_create_file(&sdev->ofdev.dev.kobj, &dev_attr_obppath.attr);
72 73

	fill_sbus_device_iommu(sdev);
L
Linus Torvalds 已提交
74 75
}

76 77 78 79 80 81 82
static void __init sdev_insert(struct sbus_dev *sdev, struct sbus_dev **root)
{
	while (*root)
		root = &(*root)->next;
	*root = sdev;
	sdev->next = NULL;
}
L
Linus Torvalds 已提交
83

84
static void __init walk_children(struct device_node *dp, struct sbus_dev *parent, struct sbus_bus *sbus)
L
Linus Torvalds 已提交
85
{
86 87 88
	dp = dp->child;
	while (dp) {
		struct sbus_dev *sdev;
L
Linus Torvalds 已提交
89

90 91 92
		sdev = kzalloc(sizeof(struct sbus_dev), GFP_ATOMIC);
		if (sdev) {
			sdev_insert(sdev, &parent->child);
L
Linus Torvalds 已提交
93

94 95 96 97 98 99
			sdev->bus = sbus;
			sdev->parent = parent;

			fill_sbus_device(dp, sdev);

			walk_children(dp, sdev, sbus);
L
Linus Torvalds 已提交
100
		}
101
		dp = dp->sibling;
L
Linus Torvalds 已提交
102
	}
103
}
L
Linus Torvalds 已提交
104

105 106 107
static void __init build_one_sbus(struct device_node *dp, int num_sbus)
{
	struct device_node *dev_dp;
108
	struct sbus_bus *sbus;
L
Linus Torvalds 已提交
109

110 111 112
	sbus = kzalloc(sizeof(struct sbus_bus), GFP_ATOMIC);
	if (!sbus)
		return;
L
Linus Torvalds 已提交
113

114
	sbus_setup_iommu(sbus, dp);
L
Linus Torvalds 已提交
115

116
	printk("sbus%d: ", num_sbus);
L
Linus Torvalds 已提交
117

118 119 120
	sbus->ofdev.node = dp;
	sbus->ofdev.dev.parent = NULL;
	sbus->ofdev.dev.bus = &sbus_bus_type;
121
	dev_set_name(&sbus->ofdev.dev, "sbus%d", num_sbus);
122 123 124

	if (of_device_register(&sbus->ofdev) != 0)
		printk(KERN_DEBUG "sbus: device registration error for %s!\n",
125
		       dev_name(&sbus->ofdev.dev));
126 127 128 129 130 131 132 133 134 135 136

	dev_dp = dp->child;
	while (dev_dp) {
		struct sbus_dev *sdev;

		sdev = kzalloc(sizeof(struct sbus_dev), GFP_ATOMIC);
		if (sdev) {
			sdev_insert(sdev, &sbus->devices);

			sdev->bus = sbus;
			sdev->parent = NULL;
137 138 139 140 141
			sdev->ofdev.dev.archdata.iommu =
				sbus->ofdev.dev.archdata.iommu;
			sdev->ofdev.dev.archdata.stc =
				sbus->ofdev.dev.archdata.stc;

142 143 144
			fill_sbus_device(dev_dp, sdev);

			walk_children(dev_dp, sdev, sbus);
L
Linus Torvalds 已提交
145
		}
146 147 148 149 150 151 152 153 154
		dev_dp = dev_dp->sibling;
	}
}

static int __init sbus_init(void)
{
	struct device_node *dp;
	const char *sbus_name = "sbus";
	int num_sbus = 0;
L
Linus Torvalds 已提交
155

156 157 158 159 160
	if (sparc_cpu_model == sun4d)
		sbus_name = "sbi";

	for_each_node_by_name(dp, sbus_name) {
		build_one_sbus(dp, num_sbus);
L
Linus Torvalds 已提交
161 162 163
		num_sbus++;

	}
164 165

	sbus_arch_postinit();
L
Linus Torvalds 已提交
166 167 168 169 170

	return 0;
}

subsys_initcall(sbus_init);