isa.c 4.7 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <asm/oplib.h>
6 7
#include <asm/prom.h>
#include <asm/of_device.h>
L
Linus Torvalds 已提交
8 9 10 11 12 13 14 15 16 17 18 19
#include <asm/isa.h>

struct sparc_isa_bridge *isa_chain;

static void __init fatal_err(const char *reason)
{
	prom_printf("ISA: fatal error, %s.\n", reason);
}

static void __init report_dev(struct sparc_isa_device *isa_dev, int child)
{
	if (child)
20
		printk(" (%s)", isa_dev->prom_node->name);
L
Linus Torvalds 已提交
21
	else
22
		printk(" [%s", isa_dev->prom_node->name);
L
Linus Torvalds 已提交
23 24
}

25 26
static struct linux_prom_registers * __init
isa_dev_get_resource(struct sparc_isa_device *isa_dev)
L
Linus Torvalds 已提交
27
{
28
	struct linux_prom_registers *pregs;
L
Linus Torvalds 已提交
29 30 31
	unsigned long base, len;
	int prop_len;

32
	pregs = of_get_property(isa_dev->prom_node, "reg", &prop_len);
L
Linus Torvalds 已提交
33 34 35 36 37 38 39 40 41 42

	/* Only the first one is interesting. */
	len = pregs[0].reg_size;
	base = (((unsigned long)pregs[0].which_io << 32) |
		(unsigned long)pregs[0].phys_addr);
	base += isa_dev->bus->parent->io_space.start;

	isa_dev->resource.start = base;
	isa_dev->resource.end   = (base + len - 1UL);
	isa_dev->resource.flags = IORESOURCE_IO;
43
	isa_dev->resource.name  = isa_dev->prom_node->name;
L
Linus Torvalds 已提交
44 45 46

	request_resource(&isa_dev->bus->parent->io_space,
			 &isa_dev->resource);
47 48

	return pregs;
L
Linus Torvalds 已提交
49 50 51 52 53
}

static void __init isa_dev_get_irq(struct sparc_isa_device *isa_dev,
				   struct linux_prom_registers *pregs)
{
54
	struct of_device *op = of_find_device_by_node(isa_dev->prom_node);
L
Linus Torvalds 已提交
55

56 57
	if (!op || !op->num_irqs) {
		isa_dev->irq = PCI_IRQ_NONE;
L
Linus Torvalds 已提交
58
	} else {
59
		isa_dev->irq = op->irqs[0];
L
Linus Torvalds 已提交
60 61 62 63 64
	}
}

static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev)
{
65
	struct device_node *dp = parent_isa_dev->prom_node->child;
L
Linus Torvalds 已提交
66

67
	if (!dp)
L
Linus Torvalds 已提交
68 69 70
		return;

	printk(" ->");
71 72
	while (dp) {
		struct linux_prom_registers *regs;
L
Linus Torvalds 已提交
73 74
		struct sparc_isa_device *isa_dev;

75
		isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL);
L
Linus Torvalds 已提交
76 77 78 79 80 81 82 83 84 85
		if (!isa_dev) {
			fatal_err("cannot allocate child isa_dev");
			prom_halt();
		}

		/* Link it in to parent. */
		isa_dev->next = parent_isa_dev->child;
		parent_isa_dev->child = isa_dev;

		isa_dev->bus = parent_isa_dev->bus;
86
		isa_dev->prom_node = dp;
L
Linus Torvalds 已提交
87

88
		regs = isa_dev_get_resource(isa_dev);
L
Linus Torvalds 已提交
89 90 91 92
		isa_dev_get_irq(isa_dev, regs);

		report_dev(isa_dev, 1);

93
		dp = dp->sibling;
L
Linus Torvalds 已提交
94 95 96 97 98
	}
}

static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
{
99
	struct device_node *dp = isa_br->prom_node->child;
L
Linus Torvalds 已提交
100

101 102
	while (dp) {
		struct linux_prom_registers *regs;
L
Linus Torvalds 已提交
103 104
		struct sparc_isa_device *isa_dev;

105
		isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL);
L
Linus Torvalds 已提交
106
		if (!isa_dev) {
107 108
			printk(KERN_DEBUG "ISA: cannot allocate isa_dev");
			return;
L
Linus Torvalds 已提交
109 110
		}

111 112 113
		isa_dev->ofdev.node = dp;
		isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev;
		isa_dev->ofdev.dev.bus = &isa_bus_type;
114
		sprintf(isa_dev->ofdev.dev.bus_id, "isa[%08x]", dp->node);
115 116 117 118

		/* Register with core */
		if (of_device_register(&isa_dev->ofdev) != 0) {
			printk(KERN_DEBUG "isa: device registration error for %s!\n",
119
			       dp->path_component_name);
120 121 122 123
			kfree(isa_dev);
			goto next_sibling;
		}

L
Linus Torvalds 已提交
124 125 126 127 128 129 130 131 132 133 134 135 136 137
		/* Link it in. */
		isa_dev->next = NULL;
		if (isa_br->devices == NULL) {
			isa_br->devices = isa_dev;
		} else {
			struct sparc_isa_device *tmp = isa_br->devices;

			while (tmp->next)
				tmp = tmp->next;

			tmp->next = isa_dev;
		}

		isa_dev->bus = isa_br;
138
		isa_dev->prom_node = dp;
L
Linus Torvalds 已提交
139

140
		regs = isa_dev_get_resource(isa_dev);
L
Linus Torvalds 已提交
141 142 143 144 145 146 147 148
		isa_dev_get_irq(isa_dev, regs);

		report_dev(isa_dev, 0);

		isa_fill_children(isa_dev);

		printk("]");

149
	next_sibling:
150
		dp = dp->sibling;
L
Linus Torvalds 已提交
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
	}
}

void __init isa_init(void)
{
	struct pci_dev *pdev;
	unsigned short vendor, device;
	int index = 0;

	vendor = PCI_VENDOR_ID_AL;
	device = PCI_DEVICE_ID_AL_M1533;

	pdev = NULL;
	while ((pdev = pci_get_device(vendor, device, pdev)) != NULL) {
		struct pcidev_cookie *pdev_cookie;
		struct pci_pbm_info *pbm;
		struct sparc_isa_bridge *isa_br;
168
		struct device_node *dp;
L
Linus Torvalds 已提交
169 170 171 172 173 174 175 176

		pdev_cookie = pdev->sysdata;
		if (!pdev_cookie) {
			printk("ISA: Warning, ISA bridge ignored due to "
			       "lack of OBP data.\n");
			continue;
		}
		pbm = pdev_cookie->pbm;
177
		dp = pdev_cookie->prom_node;
L
Linus Torvalds 已提交
178

179
		isa_br = kzalloc(sizeof(*isa_br), GFP_KERNEL);
L
Linus Torvalds 已提交
180
		if (!isa_br) {
181 182
			printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge");
			return;
L
Linus Torvalds 已提交
183 184
		}

185 186 187
		isa_br->ofdev.node = dp;
		isa_br->ofdev.dev.parent = &pdev->dev;
		isa_br->ofdev.dev.bus = &isa_bus_type;
188
		sprintf(isa_br->ofdev.dev.bus_id, "isa%d", index);
189 190 191 192

		/* Register with core */
		if (of_device_register(&isa_br->ofdev) != 0) {
			printk(KERN_DEBUG "isa: device registration error for %s!\n",
193
			       dp->path_component_name);
194 195 196 197
			kfree(isa_br);
			return;
		}

L
Linus Torvalds 已提交
198 199 200 201 202 203 204
		/* Link it in. */
		isa_br->next = isa_chain;
		isa_chain = isa_br;

		isa_br->parent = pbm;
		isa_br->self = pdev;
		isa_br->index = index++;
205 206
		isa_br->prom_node = pdev_cookie->prom_node;

L
Linus Torvalds 已提交
207 208 209 210 211 212 213
		printk("isa%d:", isa_br->index);

		isa_fill_devices(isa_br);

		printk("\n");
	}
}