]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #include <linux/kernel.h> |
2 | #include <linux/init.h> | |
3 | #include <linux/pci.h> | |
4 | #include <linux/slab.h> | |
5 | #include <asm/oplib.h> | |
2b1e5978 DM |
6 | #include <asm/prom.h> |
7 | #include <asm/of_device.h> | |
1da177e4 LT |
8 | #include <asm/isa.h> |
9 | ||
10 | struct sparc_isa_bridge *isa_chain; | |
11 | ||
12 | static void __init fatal_err(const char *reason) | |
13 | { | |
14 | prom_printf("ISA: fatal error, %s.\n", reason); | |
15 | } | |
16 | ||
17 | static void __init report_dev(struct sparc_isa_device *isa_dev, int child) | |
18 | { | |
19 | if (child) | |
690c8fd3 | 20 | printk(" (%s)", isa_dev->prom_node->name); |
1da177e4 | 21 | else |
690c8fd3 | 22 | printk(" [%s", isa_dev->prom_node->name); |
1da177e4 LT |
23 | } |
24 | ||
f4060c0d | 25 | static void __init isa_dev_get_resource(struct sparc_isa_device *isa_dev) |
1da177e4 | 26 | { |
deb66c45 | 27 | struct of_device *op = of_find_device_by_node(isa_dev->prom_node); |
1da177e4 | 28 | |
deb66c45 | 29 | memcpy(&isa_dev->resource, &op->resource[0], sizeof(struct resource)); |
1da177e4 LT |
30 | } |
31 | ||
f4060c0d | 32 | static void __init isa_dev_get_irq(struct sparc_isa_device *isa_dev) |
1da177e4 | 33 | { |
2b1e5978 | 34 | struct of_device *op = of_find_device_by_node(isa_dev->prom_node); |
1da177e4 | 35 | |
2b1e5978 DM |
36 | if (!op || !op->num_irqs) { |
37 | isa_dev->irq = PCI_IRQ_NONE; | |
1da177e4 | 38 | } else { |
2b1e5978 | 39 | isa_dev->irq = op->irqs[0]; |
1da177e4 | 40 | } |
1da177e4 LT |
41 | } |
42 | ||
43 | static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev) | |
44 | { | |
690c8fd3 | 45 | struct device_node *dp = parent_isa_dev->prom_node->child; |
1da177e4 | 46 | |
690c8fd3 | 47 | if (!dp) |
1da177e4 LT |
48 | return; |
49 | ||
50 | printk(" ->"); | |
690c8fd3 | 51 | while (dp) { |
1da177e4 | 52 | struct sparc_isa_device *isa_dev; |
1da177e4 | 53 | |
982c2064 | 54 | isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL); |
1da177e4 LT |
55 | if (!isa_dev) { |
56 | fatal_err("cannot allocate child isa_dev"); | |
57 | prom_halt(); | |
58 | } | |
59 | ||
1da177e4 LT |
60 | /* Link it in to parent. */ |
61 | isa_dev->next = parent_isa_dev->child; | |
62 | parent_isa_dev->child = isa_dev; | |
63 | ||
64 | isa_dev->bus = parent_isa_dev->bus; | |
690c8fd3 | 65 | isa_dev->prom_node = dp; |
1da177e4 | 66 | |
f4060c0d DM |
67 | isa_dev_get_resource(isa_dev); |
68 | isa_dev_get_irq(isa_dev); | |
1da177e4 LT |
69 | |
70 | report_dev(isa_dev, 1); | |
71 | ||
690c8fd3 | 72 | dp = dp->sibling; |
1da177e4 LT |
73 | } |
74 | } | |
75 | ||
76 | static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br) | |
77 | { | |
690c8fd3 | 78 | struct device_node *dp = isa_br->prom_node->child; |
1da177e4 | 79 | |
690c8fd3 | 80 | while (dp) { |
1da177e4 | 81 | struct sparc_isa_device *isa_dev; |
3d6e4702 | 82 | struct dev_archdata *sd; |
1da177e4 | 83 | |
982c2064 | 84 | isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL); |
1da177e4 | 85 | if (!isa_dev) { |
a2bd4fd1 DM |
86 | printk(KERN_DEBUG "ISA: cannot allocate isa_dev"); |
87 | return; | |
1da177e4 LT |
88 | } |
89 | ||
3d6e4702 DM |
90 | sd = &isa_dev->ofdev.dev.archdata; |
91 | sd->prom_node = dp; | |
92 | sd->op = &isa_dev->ofdev; | |
93 | ||
a2bd4fd1 DM |
94 | isa_dev->ofdev.node = dp; |
95 | isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev; | |
96 | isa_dev->ofdev.dev.bus = &isa_bus_type; | |
f5ef9d11 | 97 | sprintf(isa_dev->ofdev.dev.bus_id, "isa[%08x]", dp->node); |
a2bd4fd1 DM |
98 | |
99 | /* Register with core */ | |
100 | if (of_device_register(&isa_dev->ofdev) != 0) { | |
101 | printk(KERN_DEBUG "isa: device registration error for %s!\n", | |
f5ef9d11 | 102 | dp->path_component_name); |
a2bd4fd1 DM |
103 | kfree(isa_dev); |
104 | goto next_sibling; | |
105 | } | |
106 | ||
1da177e4 LT |
107 | /* Link it in. */ |
108 | isa_dev->next = NULL; | |
109 | if (isa_br->devices == NULL) { | |
110 | isa_br->devices = isa_dev; | |
111 | } else { | |
112 | struct sparc_isa_device *tmp = isa_br->devices; | |
113 | ||
114 | while (tmp->next) | |
115 | tmp = tmp->next; | |
116 | ||
117 | tmp->next = isa_dev; | |
118 | } | |
119 | ||
120 | isa_dev->bus = isa_br; | |
690c8fd3 | 121 | isa_dev->prom_node = dp; |
1da177e4 | 122 | |
f4060c0d DM |
123 | isa_dev_get_resource(isa_dev); |
124 | isa_dev_get_irq(isa_dev); | |
1da177e4 LT |
125 | |
126 | report_dev(isa_dev, 0); | |
127 | ||
128 | isa_fill_children(isa_dev); | |
129 | ||
130 | printk("]"); | |
131 | ||
a2bd4fd1 | 132 | next_sibling: |
690c8fd3 | 133 | dp = dp->sibling; |
1da177e4 LT |
134 | } |
135 | } | |
136 | ||
137 | void __init isa_init(void) | |
138 | { | |
139 | struct pci_dev *pdev; | |
140 | unsigned short vendor, device; | |
141 | int index = 0; | |
142 | ||
143 | vendor = PCI_VENDOR_ID_AL; | |
144 | device = PCI_DEVICE_ID_AL_M1533; | |
145 | ||
146 | pdev = NULL; | |
147 | while ((pdev = pci_get_device(vendor, device, pdev)) != NULL) { | |
1da177e4 | 148 | struct sparc_isa_bridge *isa_br; |
a2bd4fd1 | 149 | struct device_node *dp; |
1da177e4 | 150 | |
deb66c45 | 151 | dp = pci_device_to_OF_node(pdev); |
1da177e4 | 152 | |
982c2064 | 153 | isa_br = kzalloc(sizeof(*isa_br), GFP_KERNEL); |
1da177e4 | 154 | if (!isa_br) { |
a2bd4fd1 DM |
155 | printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge"); |
156 | return; | |
1da177e4 LT |
157 | } |
158 | ||
a2bd4fd1 DM |
159 | isa_br->ofdev.node = dp; |
160 | isa_br->ofdev.dev.parent = &pdev->dev; | |
161 | isa_br->ofdev.dev.bus = &isa_bus_type; | |
f5ef9d11 | 162 | sprintf(isa_br->ofdev.dev.bus_id, "isa%d", index); |
a2bd4fd1 DM |
163 | |
164 | /* Register with core */ | |
165 | if (of_device_register(&isa_br->ofdev) != 0) { | |
166 | printk(KERN_DEBUG "isa: device registration error for %s!\n", | |
f5ef9d11 | 167 | dp->path_component_name); |
a2bd4fd1 DM |
168 | kfree(isa_br); |
169 | return; | |
170 | } | |
171 | ||
1da177e4 LT |
172 | /* Link it in. */ |
173 | isa_br->next = isa_chain; | |
174 | isa_chain = isa_br; | |
175 | ||
1da177e4 LT |
176 | isa_br->self = pdev; |
177 | isa_br->index = index++; | |
deb66c45 | 178 | isa_br->prom_node = dp; |
690c8fd3 | 179 | |
1da177e4 LT |
180 | printk("isa%d:", isa_br->index); |
181 | ||
182 | isa_fill_devices(isa_br); | |
183 | ||
184 | printk("\n"); | |
185 | } | |
186 | } |