blob: 023af41ad68d99845dc9a4a1f5644d492282d63c [file] [log] [blame]
David S. Millera2fb23a2007-02-28 23:35:04 -08001/* pci.c: UltraSparc PCI controller support.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * Copyright (C) 1997, 1998, 1999 David S. Miller (davem@redhat.com)
4 * Copyright (C) 1998, 1999 Eddie C. Dost (ecd@skynet.be)
5 * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz)
David S. Millera2fb23a2007-02-28 23:35:04 -08006 *
7 * OF tree based PCI bus probing taken from the PowerPC port
8 * with minor modifications, see there for credits.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/module.h>
12#include <linux/kernel.h>
13#include <linux/string.h>
14#include <linux/sched.h>
15#include <linux/capability.h>
16#include <linux/errno.h>
17#include <linux/smp_lock.h>
David S. Miller35a17eb2007-02-10 17:41:02 -080018#include <linux/msi.h>
19#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/init.h>
21
22#include <asm/uaccess.h>
23#include <asm/pbm.h>
24#include <asm/pgtable.h>
25#include <asm/irq.h>
26#include <asm/ebus.h>
27#include <asm/isa.h>
David S. Millere87dc352006-06-21 18:18:47 -070028#include <asm/prom.h>
David S. Miller01f94c42007-03-04 12:53:19 -080029#include <asm/apb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
David S. Miller1e8a8cc2007-02-28 23:38:38 -080031#include "pci_impl.h"
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033unsigned long pci_memspace_mask = 0xffffffffUL;
34
35#ifndef CONFIG_PCI
36/* A "nop" PCI implementation. */
37asmlinkage int sys_pciconfig_read(unsigned long bus, unsigned long dfn,
38 unsigned long off, unsigned long len,
39 unsigned char *buf)
40{
41 return 0;
42}
43asmlinkage int sys_pciconfig_write(unsigned long bus, unsigned long dfn,
44 unsigned long off, unsigned long len,
45 unsigned char *buf)
46{
47 return 0;
48}
49#else
50
51/* List of all PCI controllers found in the system. */
52struct pci_controller_info *pci_controller_root = NULL;
53
54/* Each PCI controller found gets a unique index. */
55int pci_num_controllers = 0;
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057volatile int pci_poke_in_progress;
58volatile int pci_poke_cpu = -1;
59volatile int pci_poke_faulted;
60
61static DEFINE_SPINLOCK(pci_poke_lock);
62
63void pci_config_read8(u8 *addr, u8 *ret)
64{
65 unsigned long flags;
66 u8 byte;
67
68 spin_lock_irqsave(&pci_poke_lock, flags);
69 pci_poke_cpu = smp_processor_id();
70 pci_poke_in_progress = 1;
71 pci_poke_faulted = 0;
72 __asm__ __volatile__("membar #Sync\n\t"
73 "lduba [%1] %2, %0\n\t"
74 "membar #Sync"
75 : "=r" (byte)
76 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
77 : "memory");
78 pci_poke_in_progress = 0;
79 pci_poke_cpu = -1;
80 if (!pci_poke_faulted)
81 *ret = byte;
82 spin_unlock_irqrestore(&pci_poke_lock, flags);
83}
84
85void pci_config_read16(u16 *addr, u16 *ret)
86{
87 unsigned long flags;
88 u16 word;
89
90 spin_lock_irqsave(&pci_poke_lock, flags);
91 pci_poke_cpu = smp_processor_id();
92 pci_poke_in_progress = 1;
93 pci_poke_faulted = 0;
94 __asm__ __volatile__("membar #Sync\n\t"
95 "lduha [%1] %2, %0\n\t"
96 "membar #Sync"
97 : "=r" (word)
98 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
99 : "memory");
100 pci_poke_in_progress = 0;
101 pci_poke_cpu = -1;
102 if (!pci_poke_faulted)
103 *ret = word;
104 spin_unlock_irqrestore(&pci_poke_lock, flags);
105}
106
107void pci_config_read32(u32 *addr, u32 *ret)
108{
109 unsigned long flags;
110 u32 dword;
111
112 spin_lock_irqsave(&pci_poke_lock, flags);
113 pci_poke_cpu = smp_processor_id();
114 pci_poke_in_progress = 1;
115 pci_poke_faulted = 0;
116 __asm__ __volatile__("membar #Sync\n\t"
117 "lduwa [%1] %2, %0\n\t"
118 "membar #Sync"
119 : "=r" (dword)
120 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
121 : "memory");
122 pci_poke_in_progress = 0;
123 pci_poke_cpu = -1;
124 if (!pci_poke_faulted)
125 *ret = dword;
126 spin_unlock_irqrestore(&pci_poke_lock, flags);
127}
128
129void pci_config_write8(u8 *addr, u8 val)
130{
131 unsigned long flags;
132
133 spin_lock_irqsave(&pci_poke_lock, flags);
134 pci_poke_cpu = smp_processor_id();
135 pci_poke_in_progress = 1;
136 pci_poke_faulted = 0;
137 __asm__ __volatile__("membar #Sync\n\t"
138 "stba %0, [%1] %2\n\t"
139 "membar #Sync"
140 : /* no outputs */
141 : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
142 : "memory");
143 pci_poke_in_progress = 0;
144 pci_poke_cpu = -1;
145 spin_unlock_irqrestore(&pci_poke_lock, flags);
146}
147
148void pci_config_write16(u16 *addr, u16 val)
149{
150 unsigned long flags;
151
152 spin_lock_irqsave(&pci_poke_lock, flags);
153 pci_poke_cpu = smp_processor_id();
154 pci_poke_in_progress = 1;
155 pci_poke_faulted = 0;
156 __asm__ __volatile__("membar #Sync\n\t"
157 "stha %0, [%1] %2\n\t"
158 "membar #Sync"
159 : /* no outputs */
160 : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
161 : "memory");
162 pci_poke_in_progress = 0;
163 pci_poke_cpu = -1;
164 spin_unlock_irqrestore(&pci_poke_lock, flags);
165}
166
167void pci_config_write32(u32 *addr, u32 val)
168{
169 unsigned long flags;
170
171 spin_lock_irqsave(&pci_poke_lock, flags);
172 pci_poke_cpu = smp_processor_id();
173 pci_poke_in_progress = 1;
174 pci_poke_faulted = 0;
175 __asm__ __volatile__("membar #Sync\n\t"
176 "stwa %0, [%1] %2\n\t"
177 "membar #Sync"
178 : /* no outputs */
179 : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
180 : "memory");
181 pci_poke_in_progress = 0;
182 pci_poke_cpu = -1;
183 spin_unlock_irqrestore(&pci_poke_lock, flags);
184}
185
186/* Probe for all PCI controllers in the system. */
David S. Millere87dc352006-06-21 18:18:47 -0700187extern void sabre_init(struct device_node *, const char *);
188extern void psycho_init(struct device_node *, const char *);
189extern void schizo_init(struct device_node *, const char *);
190extern void schizo_plus_init(struct device_node *, const char *);
191extern void tomatillo_init(struct device_node *, const char *);
192extern void sun4v_pci_init(struct device_node *, const char *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194static struct {
195 char *model_name;
David S. Millere87dc352006-06-21 18:18:47 -0700196 void (*init)(struct device_node *, const char *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197} pci_controller_table[] __initdata = {
198 { "SUNW,sabre", sabre_init },
199 { "pci108e,a000", sabre_init },
200 { "pci108e,a001", sabre_init },
201 { "SUNW,psycho", psycho_init },
202 { "pci108e,8000", psycho_init },
203 { "SUNW,schizo", schizo_init },
204 { "pci108e,8001", schizo_init },
205 { "SUNW,schizo+", schizo_plus_init },
206 { "pci108e,8002", schizo_plus_init },
207 { "SUNW,tomatillo", tomatillo_init },
208 { "pci108e,a801", tomatillo_init },
David S. Miller8f6a93a2006-02-09 21:32:07 -0800209 { "SUNW,sun4v-pci", sun4v_pci_init },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210};
211#define PCI_NUM_CONTROLLER_TYPES (sizeof(pci_controller_table) / \
212 sizeof(pci_controller_table[0]))
213
David S. Millere87dc352006-06-21 18:18:47 -0700214static int __init pci_controller_init(const char *model_name, int namelen, struct device_node *dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215{
216 int i;
217
218 for (i = 0; i < PCI_NUM_CONTROLLER_TYPES; i++) {
219 if (!strncmp(model_name,
220 pci_controller_table[i].model_name,
221 namelen)) {
David S. Millere87dc352006-06-21 18:18:47 -0700222 pci_controller_table[i].init(dp, model_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 return 1;
224 }
225 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227 return 0;
228}
229
David S. Millere87dc352006-06-21 18:18:47 -0700230static int __init pci_is_controller(const char *model_name, int namelen, struct device_node *dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
232 int i;
233
234 for (i = 0; i < PCI_NUM_CONTROLLER_TYPES; i++) {
235 if (!strncmp(model_name,
236 pci_controller_table[i].model_name,
237 namelen)) {
238 return 1;
239 }
240 }
241 return 0;
242}
243
David S. Millere87dc352006-06-21 18:18:47 -0700244static int __init pci_controller_scan(int (*handler)(const char *, int, struct device_node *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
David S. Millere87dc352006-06-21 18:18:47 -0700246 struct device_node *dp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 int count = 0;
248
David S. Millere87dc352006-06-21 18:18:47 -0700249 for_each_node_by_name(dp, "pci") {
250 struct property *prop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 int len;
252
David S. Millere87dc352006-06-21 18:18:47 -0700253 prop = of_find_property(dp, "model", &len);
254 if (!prop)
255 prop = of_find_property(dp, "compatible", &len);
256
257 if (prop) {
258 const char *model = prop->value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 int item_len = 0;
260
261 /* Our value may be a multi-valued string in the
262 * case of some compatible properties. For sanity,
David S. Millere87dc352006-06-21 18:18:47 -0700263 * only try the first one.
264 */
265 while (model[item_len] && len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 len--;
267 item_len++;
268 }
269
David S. Millere87dc352006-06-21 18:18:47 -0700270 if (handler(model, item_len, dp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 count++;
272 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 }
274
275 return count;
276}
277
278
279/* Is there some PCI controller in the system? */
280int __init pcic_present(void)
281{
282 return pci_controller_scan(pci_is_controller);
283}
284
David S. Millerc6e87562007-03-09 16:58:43 -0800285const struct pci_iommu_ops *pci_iommu_ops;
David S. Miller8f6a93a2006-02-09 21:32:07 -0800286EXPORT_SYMBOL(pci_iommu_ops);
287
David S. Millerc6e87562007-03-09 16:58:43 -0800288extern const struct pci_iommu_ops pci_sun4u_iommu_ops,
David S. Miller8f6a93a2006-02-09 21:32:07 -0800289 pci_sun4v_iommu_ops;
290
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291/* Find each controller in the system, attach and initialize
292 * software state structure for each and link into the
293 * pci_controller_root. Setup the controller enough such
294 * that bus scanning can be done.
295 */
296static void __init pci_controller_probe(void)
297{
David S. Miller8f6a93a2006-02-09 21:32:07 -0800298 if (tlb_type == hypervisor)
299 pci_iommu_ops = &pci_sun4v_iommu_ops;
300 else
301 pci_iommu_ops = &pci_sun4u_iommu_ops;
302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 printk("PCI: Probing for controllers.\n");
304
305 pci_controller_scan(pci_controller_init);
306}
307
David S. Millera2fb23a2007-02-28 23:35:04 -0800308static unsigned long pci_parse_of_flags(u32 addr0)
309{
310 unsigned long flags = 0;
311
312 if (addr0 & 0x02000000) {
313 flags = IORESOURCE_MEM | PCI_BASE_ADDRESS_SPACE_MEMORY;
314 flags |= (addr0 >> 22) & PCI_BASE_ADDRESS_MEM_TYPE_64;
315 flags |= (addr0 >> 28) & PCI_BASE_ADDRESS_MEM_TYPE_1M;
316 if (addr0 & 0x40000000)
317 flags |= IORESOURCE_PREFETCH
318 | PCI_BASE_ADDRESS_MEM_PREFETCH;
319 } else if (addr0 & 0x01000000)
320 flags = IORESOURCE_IO | PCI_BASE_ADDRESS_SPACE_IO;
321 return flags;
322}
323
324/* The of_device layer has translated all of the assigned-address properties
325 * into physical address resources, we only have to figure out the register
326 * mapping.
327 */
328static void pci_parse_of_addrs(struct of_device *op,
329 struct device_node *node,
330 struct pci_dev *dev)
331{
332 struct resource *op_res;
333 const u32 *addrs;
334 int proplen;
335
336 addrs = of_get_property(node, "assigned-addresses", &proplen);
337 if (!addrs)
338 return;
339 printk(" parse addresses (%d bytes) @ %p\n", proplen, addrs);
340 op_res = &op->resource[0];
341 for (; proplen >= 20; proplen -= 20, addrs += 5, op_res++) {
342 struct resource *res;
343 unsigned long flags;
344 int i;
345
346 flags = pci_parse_of_flags(addrs[0]);
347 if (!flags)
348 continue;
349 i = addrs[0] & 0xff;
350 printk(" start: %lx, end: %lx, i: %x\n",
351 op_res->start, op_res->end, i);
352
353 if (PCI_BASE_ADDRESS_0 <= i && i <= PCI_BASE_ADDRESS_5) {
354 res = &dev->resource[(i - PCI_BASE_ADDRESS_0) >> 2];
355 } else if (i == dev->rom_base_reg) {
356 res = &dev->resource[PCI_ROM_RESOURCE];
357 flags |= IORESOURCE_READONLY | IORESOURCE_CACHEABLE;
358 } else {
359 printk(KERN_ERR "PCI: bad cfg reg num 0x%x\n", i);
360 continue;
361 }
362 res->start = op_res->start;
363 res->end = op_res->end;
364 res->flags = flags;
365 res->name = pci_name(dev);
366 }
367}
368
369struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,
370 struct device_node *node,
David S. Miller97b3cf02007-03-11 16:42:53 -0700371 struct pci_bus *bus, int devfn,
372 int host_controller)
David S. Millera2fb23a2007-02-28 23:35:04 -0800373{
374 struct dev_archdata *sd;
375 struct pci_dev *dev;
376 const char *type;
David S. Miller01f94c42007-03-04 12:53:19 -0800377 u32 class;
David S. Millera2fb23a2007-02-28 23:35:04 -0800378
379 dev = kzalloc(sizeof(struct pci_dev), GFP_KERNEL);
380 if (!dev)
381 return NULL;
382
383 sd = &dev->dev.archdata;
384 sd->iommu = pbm->iommu;
385 sd->stc = &pbm->stc;
386 sd->host_controller = pbm;
387 sd->prom_node = node;
388 sd->op = of_find_device_by_node(node);
389 sd->msi_num = 0xffffffff;
390
391 type = of_get_property(node, "device_type", NULL);
392 if (type == NULL)
393 type = "";
394
David S. Miller28f57e72007-03-12 19:40:26 -0700395 printk(" create device, devfn: %x, type: %s hostcontroller(%d)\n",
396 devfn, type, host_controller);
David S. Millera2fb23a2007-02-28 23:35:04 -0800397
398 dev->bus = bus;
399 dev->sysdata = node;
400 dev->dev.parent = bus->bridge;
401 dev->dev.bus = &pci_bus_type;
402 dev->devfn = devfn;
403 dev->multifunction = 0; /* maybe a lie? */
404
David S. Miller97b3cf02007-03-11 16:42:53 -0700405 if (host_controller) {
406 dev->vendor = 0x108e;
407 dev->device = 0x8000;
408 dev->subsystem_vendor = 0x0000;
409 dev->subsystem_device = 0x0000;
410 dev->cfg_size = 256;
David S. Miller28f57e72007-03-12 19:40:26 -0700411 dev->class = PCI_CLASS_BRIDGE_HOST << 8;
412 sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(bus),
413 0x00, PCI_SLOT(devfn), PCI_FUNC(devfn));
David S. Miller97b3cf02007-03-11 16:42:53 -0700414 } else {
415 dev->vendor = of_getintprop_default(node, "vendor-id", 0xffff);
416 dev->device = of_getintprop_default(node, "device-id", 0xffff);
417 dev->subsystem_vendor =
418 of_getintprop_default(node, "subsystem-vendor-id", 0);
419 dev->subsystem_device =
420 of_getintprop_default(node, "subsystem-id", 0);
David S. Millera2fb23a2007-02-28 23:35:04 -0800421
David S. Miller97b3cf02007-03-11 16:42:53 -0700422 dev->cfg_size = pci_cfg_space_size(dev);
David S. Miller01f94c42007-03-04 12:53:19 -0800423
David S. Miller97b3cf02007-03-11 16:42:53 -0700424 /* We can't actually use the firmware value, we have
425 * to read what is in the register right now. One
426 * reason is that in the case of IDE interfaces the
427 * firmware can sample the value before the the IDE
428 * interface is programmed into native mode.
429 */
430 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class);
431 dev->class = class >> 8;
David S. Miller28f57e72007-03-12 19:40:26 -0700432
433 sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(bus),
434 dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
David S. Miller97b3cf02007-03-11 16:42:53 -0700435 }
David S. Miller28f57e72007-03-12 19:40:26 -0700436 printk(" class: 0x%x device name: %s\n",
437 dev->class, pci_name(dev));
David S. Millera2fb23a2007-02-28 23:35:04 -0800438
439 dev->current_state = 4; /* unknown power state */
440 dev->error_state = pci_channel_io_normal;
441
David S. Miller97b3cf02007-03-11 16:42:53 -0700442 if (host_controller) {
David S. Millera2fb23a2007-02-28 23:35:04 -0800443 dev->hdr_type = PCI_HEADER_TYPE_BRIDGE;
444 dev->rom_base_reg = PCI_ROM_ADDRESS1;
David S. Miller97b3cf02007-03-11 16:42:53 -0700445 dev->irq = PCI_IRQ_NONE;
David S. Millera2fb23a2007-02-28 23:35:04 -0800446 } else {
David S. Miller97b3cf02007-03-11 16:42:53 -0700447 if (!strcmp(type, "pci") || !strcmp(type, "pciex")) {
448 /* a PCI-PCI bridge */
449 dev->hdr_type = PCI_HEADER_TYPE_BRIDGE;
450 dev->rom_base_reg = PCI_ROM_ADDRESS1;
451 } else if (!strcmp(type, "cardbus")) {
452 dev->hdr_type = PCI_HEADER_TYPE_CARDBUS;
453 } else {
454 dev->hdr_type = PCI_HEADER_TYPE_NORMAL;
455 dev->rom_base_reg = PCI_ROM_ADDRESS;
David S. Millera2fb23a2007-02-28 23:35:04 -0800456
David S. Miller97b3cf02007-03-11 16:42:53 -0700457 dev->irq = sd->op->irqs[0];
458 if (dev->irq == 0xffffffff)
459 dev->irq = PCI_IRQ_NONE;
460 }
David S. Millera2fb23a2007-02-28 23:35:04 -0800461 }
David S. Millera2fb23a2007-02-28 23:35:04 -0800462 pci_parse_of_addrs(sd->op, node, dev);
463
464 printk(" adding to system ...\n");
465
466 pci_device_add(dev, bus);
467
468 return dev;
469}
470
David S. Miller01f94c42007-03-04 12:53:19 -0800471static void __init apb_calc_first_last(u8 map, u32 *first_p, u32 *last_p)
472{
473 u32 idx, first, last;
474
475 first = 8;
476 last = 0;
477 for (idx = 0; idx < 8; idx++) {
478 if ((map & (1 << idx)) != 0) {
479 if (first > idx)
480 first = idx;
481 if (last < idx)
482 last = idx;
483 }
484 }
485
486 *first_p = first;
487 *last_p = last;
488}
489
David S. Miller0bae5f82007-03-08 22:42:19 -0800490static void __init pci_resource_adjust(struct resource *res,
491 struct resource *root)
492{
493 res->start += root->start;
494 res->end += root->start;
495}
496
David S. Miller01f94c42007-03-04 12:53:19 -0800497/* Cook up fake bus resources for SUNW,simba PCI bridges which lack
498 * a proper 'ranges' property.
499 */
500static void __init apb_fake_ranges(struct pci_dev *dev,
501 struct pci_bus *bus,
502 struct pci_pbm_info *pbm)
503{
504 struct resource *res;
505 u32 first, last;
506 u8 map;
507
508 pci_read_config_byte(dev, APB_IO_ADDRESS_MAP, &map);
509 apb_calc_first_last(map, &first, &last);
510 res = bus->resource[0];
511 res->start = (first << 21);
512 res->end = (last << 21) + ((1 << 21) - 1);
513 res->flags = IORESOURCE_IO;
David S. Miller0bae5f82007-03-08 22:42:19 -0800514 pci_resource_adjust(res, &pbm->io_space);
David S. Miller01f94c42007-03-04 12:53:19 -0800515
516 pci_read_config_byte(dev, APB_MEM_ADDRESS_MAP, &map);
517 apb_calc_first_last(map, &first, &last);
518 res = bus->resource[1];
519 res->start = (first << 21);
520 res->end = (last << 21) + ((1 << 21) - 1);
521 res->flags = IORESOURCE_MEM;
David S. Miller0bae5f82007-03-08 22:42:19 -0800522 pci_resource_adjust(res, &pbm->mem_space);
David S. Miller01f94c42007-03-04 12:53:19 -0800523}
524
David S. Millera2fb23a2007-02-28 23:35:04 -0800525static void __init pci_of_scan_bus(struct pci_pbm_info *pbm,
526 struct device_node *node,
527 struct pci_bus *bus);
528
529#define GET_64BIT(prop, i) ((((u64) (prop)[(i)]) << 32) | (prop)[(i)+1])
530
531void __devinit of_scan_pci_bridge(struct pci_pbm_info *pbm,
532 struct device_node *node,
533 struct pci_dev *dev)
534{
535 struct pci_bus *bus;
536 const u32 *busrange, *ranges;
David S. Miller01f94c42007-03-04 12:53:19 -0800537 int len, i, simba;
David S. Millera2fb23a2007-02-28 23:35:04 -0800538 struct resource *res;
539 unsigned int flags;
540 u64 size;
541
542 printk("of_scan_pci_bridge(%s)\n", node->full_name);
543
544 /* parse bus-range property */
545 busrange = of_get_property(node, "bus-range", &len);
546 if (busrange == NULL || len != 8) {
547 printk(KERN_DEBUG "Can't get bus-range for PCI-PCI bridge %s\n",
548 node->full_name);
549 return;
550 }
551 ranges = of_get_property(node, "ranges", &len);
David S. Miller01f94c42007-03-04 12:53:19 -0800552 simba = 0;
David S. Millera2fb23a2007-02-28 23:35:04 -0800553 if (ranges == NULL) {
David S. Millera165b422007-03-29 01:50:16 -0700554 const char *model = of_get_property(node, "model", NULL);
David S. Miller01f94c42007-03-04 12:53:19 -0800555 if (model && !strcmp(model, "SUNW,simba")) {
556 simba = 1;
557 } else {
558 printk(KERN_DEBUG "Can't get ranges for PCI-PCI bridge %s\n",
559 node->full_name);
560 return;
561 }
David S. Millera2fb23a2007-02-28 23:35:04 -0800562 }
563
564 bus = pci_add_new_bus(dev->bus, dev, busrange[0]);
565 if (!bus) {
566 printk(KERN_ERR "Failed to create pci bus for %s\n",
567 node->full_name);
568 return;
569 }
570
571 bus->primary = dev->bus->number;
572 bus->subordinate = busrange[1];
573 bus->bridge_ctl = 0;
574
David S. Miller01f94c42007-03-04 12:53:19 -0800575 /* parse ranges property, or cook one up by hand for Simba */
David S. Millera2fb23a2007-02-28 23:35:04 -0800576 /* PCI #address-cells == 3 and #size-cells == 2 always */
577 res = &dev->resource[PCI_BRIDGE_RESOURCES];
578 for (i = 0; i < PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES; ++i) {
579 res->flags = 0;
580 bus->resource[i] = res;
581 ++res;
582 }
David S. Miller01f94c42007-03-04 12:53:19 -0800583 if (simba) {
584 apb_fake_ranges(dev, bus, pbm);
585 goto simba_cont;
586 }
David S. Millera2fb23a2007-02-28 23:35:04 -0800587 i = 1;
588 for (; len >= 32; len -= 32, ranges += 8) {
589 struct resource *root;
590
591 flags = pci_parse_of_flags(ranges[0]);
592 size = GET_64BIT(ranges, 6);
593 if (flags == 0 || size == 0)
594 continue;
595 if (flags & IORESOURCE_IO) {
596 res = bus->resource[0];
597 if (res->flags) {
598 printk(KERN_ERR "PCI: ignoring extra I/O range"
599 " for bridge %s\n", node->full_name);
600 continue;
601 }
602 root = &pbm->io_space;
603 } else {
604 if (i >= PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES) {
605 printk(KERN_ERR "PCI: too many memory ranges"
606 " for bridge %s\n", node->full_name);
607 continue;
608 }
609 res = bus->resource[i];
610 ++i;
611 root = &pbm->mem_space;
612 }
613
614 res->start = GET_64BIT(ranges, 1);
615 res->end = res->start + size - 1;
616 res->flags = flags;
617
618 /* Another way to implement this would be to add an of_device
619 * layer routine that can calculate a resource for a given
620 * range property value in a PCI device.
621 */
David S. Miller0bae5f82007-03-08 22:42:19 -0800622 pci_resource_adjust(res, root);
David S. Millera2fb23a2007-02-28 23:35:04 -0800623 }
David S. Miller01f94c42007-03-04 12:53:19 -0800624simba_cont:
David S. Millera2fb23a2007-02-28 23:35:04 -0800625 sprintf(bus->name, "PCI Bus %04x:%02x", pci_domain_nr(bus),
626 bus->number);
627 printk(" bus name: %s\n", bus->name);
628
629 pci_of_scan_bus(pbm, node, bus);
630}
631
632static void __init pci_of_scan_bus(struct pci_pbm_info *pbm,
633 struct device_node *node,
634 struct pci_bus *bus)
635{
636 struct device_node *child;
637 const u32 *reg;
638 int reglen, devfn;
639 struct pci_dev *dev;
640
641 printk("PCI: scan_bus[%s] bus no %d\n",
642 node->full_name, bus->number);
643
644 child = NULL;
645 while ((child = of_get_next_child(node, child)) != NULL) {
646 printk(" * %s\n", child->full_name);
647 reg = of_get_property(child, "reg", &reglen);
648 if (reg == NULL || reglen < 20)
649 continue;
650 devfn = (reg[0] >> 8) & 0xff;
651
652 /* create a new pci_dev for this device */
David S. Miller97b3cf02007-03-11 16:42:53 -0700653 dev = of_create_pci_dev(pbm, child, bus, devfn, 0);
David S. Millera2fb23a2007-02-28 23:35:04 -0800654 if (!dev)
655 continue;
656 printk("PCI: dev header type: %x\n", dev->hdr_type);
657
658 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
659 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
660 of_scan_pci_bridge(pbm, child, dev);
661 }
662}
663
664static ssize_t
665show_pciobppath_attr(struct device * dev, struct device_attribute * attr, char * buf)
666{
667 struct pci_dev *pdev;
668 struct device_node *dp;
669
670 pdev = to_pci_dev(dev);
671 dp = pdev->dev.archdata.prom_node;
672
673 return snprintf (buf, PAGE_SIZE, "%s\n", dp->full_name);
674}
675
676static DEVICE_ATTR(obppath, S_IRUSR | S_IRGRP | S_IROTH, show_pciobppath_attr, NULL);
677
678static void __devinit pci_bus_register_of_sysfs(struct pci_bus *bus)
679{
680 struct pci_dev *dev;
David S. Millera378fd02007-03-01 11:46:13 -0800681 struct pci_bus *child_bus;
David S. Millera2fb23a2007-02-28 23:35:04 -0800682 int err;
683
684 list_for_each_entry(dev, &bus->devices, bus_list) {
685 /* we don't really care if we can create this file or
686 * not, but we need to assign the result of the call
687 * or the world will fall under alien invasion and
688 * everybody will be frozen on a spaceship ready to be
689 * eaten on alpha centauri by some green and jelly
690 * humanoid.
691 */
692 err = sysfs_create_file(&dev->dev.kobj, &dev_attr_obppath.attr);
693 }
David S. Millera378fd02007-03-01 11:46:13 -0800694 list_for_each_entry(child_bus, &bus->children, node)
695 pci_bus_register_of_sysfs(child_bus);
David S. Millera2fb23a2007-02-28 23:35:04 -0800696}
697
David S. Miller97b3cf02007-03-11 16:42:53 -0700698int pci_host_bridge_read_pci_cfg(struct pci_bus *bus_dev,
699 unsigned int devfn,
700 int where, int size,
701 u32 *value)
702{
703 static u8 fake_pci_config[] = {
704 0x8e, 0x10, /* Vendor: 0x108e (Sun) */
705 0x00, 0x80, /* Device: 0x8000 (PBM) */
706 0x46, 0x01, /* Command: 0x0146 (SERR, PARITY, MASTER, MEM) */
707 0xa0, 0x22, /* Status: 0x02a0 (DEVSEL_MED, FB2B, 66MHZ) */
708 0x00, 0x00, 0x00, 0x06, /* Class: 0x06000000 host bridge */
709 0x00, /* Cacheline: 0x00 */
710 0x40, /* Latency: 0x40 */
711 0x00, /* Header-Type: 0x00 normal */
712 };
713
714 *value = 0;
715 if (where >= 0 && where < sizeof(fake_pci_config) &&
716 (where + size) >= 0 &&
717 (where + size) < sizeof(fake_pci_config) &&
718 size <= sizeof(u32)) {
719 while (size--) {
720 *value <<= 8;
721 *value |= fake_pci_config[where + size];
722 }
723 }
724
725 return PCIBIOS_SUCCESSFUL;
726}
727
728int pci_host_bridge_write_pci_cfg(struct pci_bus *bus_dev,
729 unsigned int devfn,
730 int where, int size,
731 u32 value)
732{
733 return PCIBIOS_SUCCESSFUL;
734}
735
David S. Millera2fb23a2007-02-28 23:35:04 -0800736struct pci_bus * __init pci_scan_one_pbm(struct pci_pbm_info *pbm)
737{
738 struct pci_controller_info *p = pbm->parent;
739 struct device_node *node = pbm->prom_node;
David S. Miller97b3cf02007-03-11 16:42:53 -0700740 struct pci_dev *host_pdev;
David S. Millera2fb23a2007-02-28 23:35:04 -0800741 struct pci_bus *bus;
742
743 printk("PCI: Scanning PBM %s\n", node->full_name);
744
745 /* XXX parent device? XXX */
746 bus = pci_create_bus(NULL, pbm->pci_first_busno, p->pci_ops, pbm);
747 if (!bus) {
748 printk(KERN_ERR "Failed to create bus for %s\n",
749 node->full_name);
750 return NULL;
751 }
752 bus->secondary = pbm->pci_first_busno;
753 bus->subordinate = pbm->pci_last_busno;
754
755 bus->resource[0] = &pbm->io_space;
756 bus->resource[1] = &pbm->mem_space;
757
David S. Miller97b3cf02007-03-11 16:42:53 -0700758 /* Create the dummy host bridge and link it in. */
759 host_pdev = of_create_pci_dev(pbm, node, bus, 0x00, 1);
760 bus->self = host_pdev;
761
David S. Millera2fb23a2007-02-28 23:35:04 -0800762 pci_of_scan_bus(pbm, node, bus);
763 pci_bus_add_devices(bus);
764 pci_bus_register_of_sysfs(bus);
765
766 return bus;
767}
768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769static void __init pci_scan_each_controller_bus(void)
770{
771 struct pci_controller_info *p;
772
773 for (p = pci_controller_root; p; p = p->next)
774 p->scan_bus(p);
775}
776
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777extern void power_init(void);
778
779static int __init pcibios_init(void)
780{
781 pci_controller_probe();
782 if (pci_controller_root == NULL)
783 return 0;
784
785 pci_scan_each_controller_bus();
786
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 isa_init();
788 ebus_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 power_init();
790
791 return 0;
792}
793
794subsys_initcall(pcibios_init);
795
Robert Reiff6b45da2007-04-12 13:47:37 -0700796void __devinit pcibios_fixup_bus(struct pci_bus *pbus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797{
798 struct pci_pbm_info *pbm = pbus->sysdata;
799
800 /* Generic PCI bus probing sets these to point at
801 * &io{port,mem}_resouce which is wrong for us.
802 */
803 pbus->resource[0] = &pbm->io_space;
804 pbus->resource[1] = &pbm->mem_space;
805}
806
David S. Miller085ae412005-08-08 13:19:08 -0700807struct resource *pcibios_select_root(struct pci_dev *pdev, struct resource *r)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808{
809 struct pci_pbm_info *pbm = pdev->bus->sysdata;
David S. Miller085ae412005-08-08 13:19:08 -0700810 struct resource *root = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
David S. Miller085ae412005-08-08 13:19:08 -0700812 if (r->flags & IORESOURCE_IO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 root = &pbm->io_space;
David S. Miller085ae412005-08-08 13:19:08 -0700814 if (r->flags & IORESOURCE_MEM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 root = &pbm->mem_space;
816
David S. Miller085ae412005-08-08 13:19:08 -0700817 return root;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818}
819
820void pcibios_update_irq(struct pci_dev *pdev, int irq)
821{
822}
823
824void pcibios_align_resource(void *data, struct resource *res,
Greg Kroah-Hartmane31dd6e2006-06-12 17:06:02 -0700825 resource_size_t size, resource_size_t align)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826{
827}
828
David S. Millera2fb23a2007-02-28 23:35:04 -0800829int pcibios_enable_device(struct pci_dev *dev, int mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830{
David S. Millera2fb23a2007-02-28 23:35:04 -0800831 u16 cmd, oldcmd;
832 int i;
833
834 pci_read_config_word(dev, PCI_COMMAND, &cmd);
835 oldcmd = cmd;
836
837 for (i = 0; i < PCI_NUM_RESOURCES; i++) {
838 struct resource *res = &dev->resource[i];
839
840 /* Only set up the requested stuff */
841 if (!(mask & (1<<i)))
842 continue;
843
844 if (res->flags & IORESOURCE_IO)
845 cmd |= PCI_COMMAND_IO;
846 if (res->flags & IORESOURCE_MEM)
847 cmd |= PCI_COMMAND_MEMORY;
848 }
849
850 if (cmd != oldcmd) {
851 printk(KERN_DEBUG "PCI: Enabling device: (%s), cmd %x\n",
852 pci_name(dev), cmd);
853 /* Enable the appropriate bits in the PCI command register. */
854 pci_write_config_word(dev, PCI_COMMAND, cmd);
855 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 return 0;
857}
858
859void pcibios_resource_to_bus(struct pci_dev *pdev, struct pci_bus_region *region,
860 struct resource *res)
861{
862 struct pci_pbm_info *pbm = pdev->bus->sysdata;
863 struct resource zero_res, *root;
864
865 zero_res.start = 0;
866 zero_res.end = 0;
867 zero_res.flags = res->flags;
868
869 if (res->flags & IORESOURCE_IO)
870 root = &pbm->io_space;
871 else
872 root = &pbm->mem_space;
873
David S. Miller0bae5f82007-03-08 22:42:19 -0800874 pci_resource_adjust(&zero_res, root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
876 region->start = res->start - zero_res.start;
877 region->end = res->end - zero_res.start;
878}
David S. Miller5fdfd422006-04-17 13:34:44 -0700879EXPORT_SYMBOL(pcibios_resource_to_bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
881void pcibios_bus_to_resource(struct pci_dev *pdev, struct resource *res,
882 struct pci_bus_region *region)
883{
884 struct pci_pbm_info *pbm = pdev->bus->sysdata;
885 struct resource *root;
886
887 res->start = region->start;
888 res->end = region->end;
889
890 if (res->flags & IORESOURCE_IO)
891 root = &pbm->io_space;
892 else
893 root = &pbm->mem_space;
894
David S. Miller0bae5f82007-03-08 22:42:19 -0800895 pci_resource_adjust(res, root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896}
Keith Owens41290c12005-08-24 16:06:25 +1000897EXPORT_SYMBOL(pcibios_bus_to_resource);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
Robert Reiff6b45da2007-04-12 13:47:37 -0700899char * __devinit pcibios_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 return str;
902}
903
904/* Platform support for /proc/bus/pci/X/Y mmap()s. */
905
906/* If the user uses a host-bridge as the PCI device, he may use
907 * this to perform a raw mmap() of the I/O or MEM space behind
908 * that controller.
909 *
910 * This can be useful for execution of x86 PCI bios initialization code
911 * on a PCI card, like the xfree86 int10 stuff does.
912 */
913static int __pci_mmap_make_offset_bus(struct pci_dev *pdev, struct vm_area_struct *vma,
914 enum pci_mmap_state mmap_state)
915{
David S. Millera2fb23a2007-02-28 23:35:04 -0800916 struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 struct pci_controller_info *p;
918 unsigned long space_size, user_offset, user_size;
919
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 p = pbm->parent;
David S. Miller3875c5c2007-03-08 22:52:11 -0800921 if (mmap_state == pci_mmap_io) {
922 space_size = (pbm->io_space.end -
923 pbm->io_space.start) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 } else {
David S. Miller3875c5c2007-03-08 22:52:11 -0800925 space_size = (pbm->mem_space.end -
926 pbm->mem_space.start) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 }
928
929 /* Make sure the request is in range. */
930 user_offset = vma->vm_pgoff << PAGE_SHIFT;
931 user_size = vma->vm_end - vma->vm_start;
932
933 if (user_offset >= space_size ||
934 (user_offset + user_size) > space_size)
935 return -EINVAL;
936
David S. Miller3875c5c2007-03-08 22:52:11 -0800937 if (mmap_state == pci_mmap_io) {
938 vma->vm_pgoff = (pbm->io_space.start +
939 user_offset) >> PAGE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 } else {
David S. Miller3875c5c2007-03-08 22:52:11 -0800941 vma->vm_pgoff = (pbm->mem_space.start +
942 user_offset) >> PAGE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 }
944
945 return 0;
946}
947
948/* Adjust vm_pgoff of VMA such that it is the physical page offset corresponding
949 * to the 32-bit pci bus offset for DEV requested by the user.
950 *
951 * Basically, the user finds the base address for his device which he wishes
952 * to mmap. They read the 32-bit value from the config space base register,
953 * add whatever PAGE_SIZE multiple offset they wish, and feed this into the
954 * offset parameter of mmap on /proc/bus/pci/XXX for that device.
955 *
956 * Returns negative error code on failure, zero on success.
957 */
958static int __pci_mmap_make_offset(struct pci_dev *dev, struct vm_area_struct *vma,
959 enum pci_mmap_state mmap_state)
960{
961 unsigned long user_offset = vma->vm_pgoff << PAGE_SHIFT;
962 unsigned long user32 = user_offset & pci_memspace_mask;
963 unsigned long largest_base, this_base, addr32;
964 int i;
965
966 if ((dev->class >> 8) == PCI_CLASS_BRIDGE_HOST)
967 return __pci_mmap_make_offset_bus(dev, vma, mmap_state);
968
969 /* Figure out which base address this is for. */
970 largest_base = 0UL;
971 for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
972 struct resource *rp = &dev->resource[i];
973
974 /* Active? */
975 if (!rp->flags)
976 continue;
977
978 /* Same type? */
979 if (i == PCI_ROM_RESOURCE) {
980 if (mmap_state != pci_mmap_mem)
981 continue;
982 } else {
983 if ((mmap_state == pci_mmap_io &&
984 (rp->flags & IORESOURCE_IO) == 0) ||
985 (mmap_state == pci_mmap_mem &&
986 (rp->flags & IORESOURCE_MEM) == 0))
987 continue;
988 }
989
990 this_base = rp->start;
991
992 addr32 = (this_base & PAGE_MASK) & pci_memspace_mask;
993
994 if (mmap_state == pci_mmap_io)
995 addr32 &= 0xffffff;
996
997 if (addr32 <= user32 && this_base > largest_base)
998 largest_base = this_base;
999 }
1000
1001 if (largest_base == 0UL)
1002 return -EINVAL;
1003
1004 /* Now construct the final physical address. */
1005 if (mmap_state == pci_mmap_io)
1006 vma->vm_pgoff = (((largest_base & ~0xffffffUL) | user32) >> PAGE_SHIFT);
1007 else
1008 vma->vm_pgoff = (((largest_base & ~(pci_memspace_mask)) | user32) >> PAGE_SHIFT);
1009
1010 return 0;
1011}
1012
1013/* Set vm_flags of VMA, as appropriate for this architecture, for a pci device
1014 * mapping.
1015 */
1016static void __pci_mmap_set_flags(struct pci_dev *dev, struct vm_area_struct *vma,
1017 enum pci_mmap_state mmap_state)
1018{
1019 vma->vm_flags |= (VM_IO | VM_RESERVED);
1020}
1021
1022/* Set vm_page_prot of VMA, as appropriate for this architecture, for a pci
1023 * device mapping.
1024 */
1025static void __pci_mmap_set_pgprot(struct pci_dev *dev, struct vm_area_struct *vma,
1026 enum pci_mmap_state mmap_state)
1027{
David S. Millera7a6cac2005-09-01 21:51:26 -07001028 /* Our io_remap_pfn_range takes care of this, do nothing. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029}
1030
1031/* Perform the actual remap of the pages for a PCI device mapping, as appropriate
1032 * for this architecture. The region in the process to map is described by vm_start
1033 * and vm_end members of VMA, the base physical address is found in vm_pgoff.
1034 * The pci device structure is provided so that architectures may make mapping
1035 * decisions on a per-device or per-bus basis.
1036 *
1037 * Returns a negative error code on failure, zero on success.
1038 */
1039int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
1040 enum pci_mmap_state mmap_state,
1041 int write_combine)
1042{
1043 int ret;
1044
1045 ret = __pci_mmap_make_offset(dev, vma, mmap_state);
1046 if (ret < 0)
1047 return ret;
1048
1049 __pci_mmap_set_flags(dev, vma, mmap_state);
1050 __pci_mmap_set_pgprot(dev, vma, mmap_state);
1051
David S. Miller14778d92006-03-21 02:29:39 -08001052 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 ret = io_remap_pfn_range(vma, vma->vm_start,
1054 vma->vm_pgoff,
1055 vma->vm_end - vma->vm_start,
1056 vma->vm_page_prot);
1057 if (ret)
1058 return ret;
1059
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 return 0;
1061}
1062
1063/* Return the domain nuber for this pci bus */
1064
1065int pci_domain_nr(struct pci_bus *pbus)
1066{
1067 struct pci_pbm_info *pbm = pbus->sysdata;
1068 int ret;
1069
1070 if (pbm == NULL || pbm->parent == NULL) {
1071 ret = -ENXIO;
1072 } else {
1073 struct pci_controller_info *p = pbm->parent;
1074
1075 ret = p->index;
David S. Miller3875c5c2007-03-08 22:52:11 -08001076 ret = ((ret << 1) +
1077 ((pbm == &pbm->parent->pbm_B) ? 1 : 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 }
1079
1080 return ret;
1081}
1082EXPORT_SYMBOL(pci_domain_nr);
1083
David S. Miller35a17eb2007-02-10 17:41:02 -08001084#ifdef CONFIG_PCI_MSI
1085int arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
1086{
David S. Millera2fb23a2007-02-28 23:35:04 -08001087 struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller;
David S. Miller35a17eb2007-02-10 17:41:02 -08001088 struct pci_controller_info *p = pbm->parent;
1089 int virt_irq, err;
1090
1091 if (!pbm->msi_num || !p->setup_msi_irq)
1092 return -EINVAL;
1093
1094 err = p->setup_msi_irq(&virt_irq, pdev, desc);
1095 if (err < 0)
1096 return err;
1097
1098 return virt_irq;
1099}
1100
1101void arch_teardown_msi_irq(unsigned int virt_irq)
1102{
David S. Millerabfd3362007-02-26 09:40:34 -08001103 struct msi_desc *entry = get_irq_msi(virt_irq);
David S. Miller35a17eb2007-02-10 17:41:02 -08001104 struct pci_dev *pdev = entry->dev;
David S. Millera2fb23a2007-02-28 23:35:04 -08001105 struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller;
David S. Miller35a17eb2007-02-10 17:41:02 -08001106 struct pci_controller_info *p = pbm->parent;
1107
1108 if (!pbm->msi_num || !p->setup_msi_irq)
1109 return;
1110
1111 return p->teardown_msi_irq(virt_irq, pdev);
1112}
1113#endif /* !(CONFIG_PCI_MSI) */
1114
David S. Millerf6d0f9e2007-03-01 18:09:18 -08001115struct device_node *pci_device_to_OF_node(struct pci_dev *pdev)
1116{
David S. Millera2fb23a2007-02-28 23:35:04 -08001117 return pdev->dev.archdata.prom_node;
David S. Millerf6d0f9e2007-03-01 18:09:18 -08001118}
1119EXPORT_SYMBOL(pci_device_to_OF_node);
1120
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121#endif /* !(CONFIG_PCI) */