blob: 04ea6c2eb7a13cbaac5dd2c060cdcc5dabffc8c7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: pci.c,v 1.39 2002/01/05 01:13:43 davem Exp $
2 * pci.c: UltraSparc PCI controller support.
3 *
4 * Copyright (C) 1997, 1998, 1999 David S. Miller (davem@redhat.com)
5 * Copyright (C) 1998, 1999 Eddie C. Dost (ecd@skynet.be)
6 * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz)
7 */
8
9#include <linux/config.h>
10#include <linux/module.h>
11#include <linux/kernel.h>
12#include <linux/string.h>
13#include <linux/sched.h>
14#include <linux/capability.h>
15#include <linux/errno.h>
16#include <linux/smp_lock.h>
17#include <linux/init.h>
18
19#include <asm/uaccess.h>
20#include <asm/pbm.h>
21#include <asm/pgtable.h>
22#include <asm/irq.h>
23#include <asm/ebus.h>
24#include <asm/isa.h>
David S. Millere87dc352006-06-21 18:18:47 -070025#include <asm/prom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27unsigned long pci_memspace_mask = 0xffffffffUL;
28
29#ifndef CONFIG_PCI
30/* A "nop" PCI implementation. */
31asmlinkage int sys_pciconfig_read(unsigned long bus, unsigned long dfn,
32 unsigned long off, unsigned long len,
33 unsigned char *buf)
34{
35 return 0;
36}
37asmlinkage int sys_pciconfig_write(unsigned long bus, unsigned long dfn,
38 unsigned long off, unsigned long len,
39 unsigned char *buf)
40{
41 return 0;
42}
43#else
44
45/* List of all PCI controllers found in the system. */
46struct pci_controller_info *pci_controller_root = NULL;
47
48/* Each PCI controller found gets a unique index. */
49int pci_num_controllers = 0;
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051volatile int pci_poke_in_progress;
52volatile int pci_poke_cpu = -1;
53volatile int pci_poke_faulted;
54
55static DEFINE_SPINLOCK(pci_poke_lock);
56
57void pci_config_read8(u8 *addr, u8 *ret)
58{
59 unsigned long flags;
60 u8 byte;
61
62 spin_lock_irqsave(&pci_poke_lock, flags);
63 pci_poke_cpu = smp_processor_id();
64 pci_poke_in_progress = 1;
65 pci_poke_faulted = 0;
66 __asm__ __volatile__("membar #Sync\n\t"
67 "lduba [%1] %2, %0\n\t"
68 "membar #Sync"
69 : "=r" (byte)
70 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
71 : "memory");
72 pci_poke_in_progress = 0;
73 pci_poke_cpu = -1;
74 if (!pci_poke_faulted)
75 *ret = byte;
76 spin_unlock_irqrestore(&pci_poke_lock, flags);
77}
78
79void pci_config_read16(u16 *addr, u16 *ret)
80{
81 unsigned long flags;
82 u16 word;
83
84 spin_lock_irqsave(&pci_poke_lock, flags);
85 pci_poke_cpu = smp_processor_id();
86 pci_poke_in_progress = 1;
87 pci_poke_faulted = 0;
88 __asm__ __volatile__("membar #Sync\n\t"
89 "lduha [%1] %2, %0\n\t"
90 "membar #Sync"
91 : "=r" (word)
92 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
93 : "memory");
94 pci_poke_in_progress = 0;
95 pci_poke_cpu = -1;
96 if (!pci_poke_faulted)
97 *ret = word;
98 spin_unlock_irqrestore(&pci_poke_lock, flags);
99}
100
101void pci_config_read32(u32 *addr, u32 *ret)
102{
103 unsigned long flags;
104 u32 dword;
105
106 spin_lock_irqsave(&pci_poke_lock, flags);
107 pci_poke_cpu = smp_processor_id();
108 pci_poke_in_progress = 1;
109 pci_poke_faulted = 0;
110 __asm__ __volatile__("membar #Sync\n\t"
111 "lduwa [%1] %2, %0\n\t"
112 "membar #Sync"
113 : "=r" (dword)
114 : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
115 : "memory");
116 pci_poke_in_progress = 0;
117 pci_poke_cpu = -1;
118 if (!pci_poke_faulted)
119 *ret = dword;
120 spin_unlock_irqrestore(&pci_poke_lock, flags);
121}
122
123void pci_config_write8(u8 *addr, u8 val)
124{
125 unsigned long flags;
126
127 spin_lock_irqsave(&pci_poke_lock, flags);
128 pci_poke_cpu = smp_processor_id();
129 pci_poke_in_progress = 1;
130 pci_poke_faulted = 0;
131 __asm__ __volatile__("membar #Sync\n\t"
132 "stba %0, [%1] %2\n\t"
133 "membar #Sync"
134 : /* no outputs */
135 : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
136 : "memory");
137 pci_poke_in_progress = 0;
138 pci_poke_cpu = -1;
139 spin_unlock_irqrestore(&pci_poke_lock, flags);
140}
141
142void pci_config_write16(u16 *addr, u16 val)
143{
144 unsigned long flags;
145
146 spin_lock_irqsave(&pci_poke_lock, flags);
147 pci_poke_cpu = smp_processor_id();
148 pci_poke_in_progress = 1;
149 pci_poke_faulted = 0;
150 __asm__ __volatile__("membar #Sync\n\t"
151 "stha %0, [%1] %2\n\t"
152 "membar #Sync"
153 : /* no outputs */
154 : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
155 : "memory");
156 pci_poke_in_progress = 0;
157 pci_poke_cpu = -1;
158 spin_unlock_irqrestore(&pci_poke_lock, flags);
159}
160
161void pci_config_write32(u32 *addr, u32 val)
162{
163 unsigned long flags;
164
165 spin_lock_irqsave(&pci_poke_lock, flags);
166 pci_poke_cpu = smp_processor_id();
167 pci_poke_in_progress = 1;
168 pci_poke_faulted = 0;
169 __asm__ __volatile__("membar #Sync\n\t"
170 "stwa %0, [%1] %2\n\t"
171 "membar #Sync"
172 : /* no outputs */
173 : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
174 : "memory");
175 pci_poke_in_progress = 0;
176 pci_poke_cpu = -1;
177 spin_unlock_irqrestore(&pci_poke_lock, flags);
178}
179
180/* Probe for all PCI controllers in the system. */
David S. Millere87dc352006-06-21 18:18:47 -0700181extern void sabre_init(struct device_node *, const char *);
182extern void psycho_init(struct device_node *, const char *);
183extern void schizo_init(struct device_node *, const char *);
184extern void schizo_plus_init(struct device_node *, const char *);
185extern void tomatillo_init(struct device_node *, const char *);
186extern void sun4v_pci_init(struct device_node *, const char *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188static struct {
189 char *model_name;
David S. Millere87dc352006-06-21 18:18:47 -0700190 void (*init)(struct device_node *, const char *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191} pci_controller_table[] __initdata = {
192 { "SUNW,sabre", sabre_init },
193 { "pci108e,a000", sabre_init },
194 { "pci108e,a001", sabre_init },
195 { "SUNW,psycho", psycho_init },
196 { "pci108e,8000", psycho_init },
197 { "SUNW,schizo", schizo_init },
198 { "pci108e,8001", schizo_init },
199 { "SUNW,schizo+", schizo_plus_init },
200 { "pci108e,8002", schizo_plus_init },
201 { "SUNW,tomatillo", tomatillo_init },
202 { "pci108e,a801", tomatillo_init },
David S. Miller8f6a93a2006-02-09 21:32:07 -0800203 { "SUNW,sun4v-pci", sun4v_pci_init },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204};
205#define PCI_NUM_CONTROLLER_TYPES (sizeof(pci_controller_table) / \
206 sizeof(pci_controller_table[0]))
207
David S. Millere87dc352006-06-21 18:18:47 -0700208static int __init pci_controller_init(const char *model_name, int namelen, struct device_node *dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
210 int i;
211
212 for (i = 0; i < PCI_NUM_CONTROLLER_TYPES; i++) {
213 if (!strncmp(model_name,
214 pci_controller_table[i].model_name,
215 namelen)) {
David S. Millere87dc352006-06-21 18:18:47 -0700216 pci_controller_table[i].init(dp, model_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 return 1;
218 }
219 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221 return 0;
222}
223
David S. Millere87dc352006-06-21 18:18:47 -0700224static int __init pci_is_controller(const char *model_name, int namelen, struct device_node *dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
226 int i;
227
228 for (i = 0; i < PCI_NUM_CONTROLLER_TYPES; i++) {
229 if (!strncmp(model_name,
230 pci_controller_table[i].model_name,
231 namelen)) {
232 return 1;
233 }
234 }
235 return 0;
236}
237
David S. Millere87dc352006-06-21 18:18:47 -0700238static int __init pci_controller_scan(int (*handler)(const char *, int, struct device_node *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239{
David S. Millere87dc352006-06-21 18:18:47 -0700240 struct device_node *dp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 int count = 0;
242
David S. Millere87dc352006-06-21 18:18:47 -0700243 for_each_node_by_name(dp, "pci") {
244 struct property *prop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 int len;
246
David S. Millere87dc352006-06-21 18:18:47 -0700247 prop = of_find_property(dp, "model", &len);
248 if (!prop)
249 prop = of_find_property(dp, "compatible", &len);
250
251 if (prop) {
252 const char *model = prop->value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 int item_len = 0;
254
255 /* Our value may be a multi-valued string in the
256 * case of some compatible properties. For sanity,
David S. Millere87dc352006-06-21 18:18:47 -0700257 * only try the first one.
258 */
259 while (model[item_len] && len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 len--;
261 item_len++;
262 }
263
David S. Millere87dc352006-06-21 18:18:47 -0700264 if (handler(model, item_len, dp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 count++;
266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 }
268
269 return count;
270}
271
272
273/* Is there some PCI controller in the system? */
274int __init pcic_present(void)
275{
276 return pci_controller_scan(pci_is_controller);
277}
278
David S. Miller8f6a93a2006-02-09 21:32:07 -0800279struct pci_iommu_ops *pci_iommu_ops;
280EXPORT_SYMBOL(pci_iommu_ops);
281
282extern struct pci_iommu_ops pci_sun4u_iommu_ops,
283 pci_sun4v_iommu_ops;
284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285/* Find each controller in the system, attach and initialize
286 * software state structure for each and link into the
287 * pci_controller_root. Setup the controller enough such
288 * that bus scanning can be done.
289 */
290static void __init pci_controller_probe(void)
291{
David S. Miller8f6a93a2006-02-09 21:32:07 -0800292 if (tlb_type == hypervisor)
293 pci_iommu_ops = &pci_sun4v_iommu_ops;
294 else
295 pci_iommu_ops = &pci_sun4u_iommu_ops;
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 printk("PCI: Probing for controllers.\n");
298
299 pci_controller_scan(pci_controller_init);
300}
301
302static void __init pci_scan_each_controller_bus(void)
303{
304 struct pci_controller_info *p;
305
306 for (p = pci_controller_root; p; p = p->next)
307 p->scan_bus(p);
308}
309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310extern void power_init(void);
311
312static int __init pcibios_init(void)
313{
314 pci_controller_probe();
315 if (pci_controller_root == NULL)
316 return 0;
317
318 pci_scan_each_controller_bus();
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 isa_init();
321 ebus_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 power_init();
323
324 return 0;
325}
326
327subsys_initcall(pcibios_init);
328
329void pcibios_fixup_bus(struct pci_bus *pbus)
330{
331 struct pci_pbm_info *pbm = pbus->sysdata;
332
333 /* Generic PCI bus probing sets these to point at
334 * &io{port,mem}_resouce which is wrong for us.
335 */
336 pbus->resource[0] = &pbm->io_space;
337 pbus->resource[1] = &pbm->mem_space;
338}
339
David S. Miller085ae412005-08-08 13:19:08 -0700340struct resource *pcibios_select_root(struct pci_dev *pdev, struct resource *r)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
342 struct pci_pbm_info *pbm = pdev->bus->sysdata;
David S. Miller085ae412005-08-08 13:19:08 -0700343 struct resource *root = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
David S. Miller085ae412005-08-08 13:19:08 -0700345 if (r->flags & IORESOURCE_IO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 root = &pbm->io_space;
David S. Miller085ae412005-08-08 13:19:08 -0700347 if (r->flags & IORESOURCE_MEM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 root = &pbm->mem_space;
349
David S. Miller085ae412005-08-08 13:19:08 -0700350 return root;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351}
352
353void pcibios_update_irq(struct pci_dev *pdev, int irq)
354{
355}
356
357void pcibios_align_resource(void *data, struct resource *res,
Greg Kroah-Hartmane31dd6e2006-06-12 17:06:02 -0700358 resource_size_t size, resource_size_t align)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
360}
361
362int pcibios_enable_device(struct pci_dev *pdev, int mask)
363{
364 return 0;
365}
366
367void pcibios_resource_to_bus(struct pci_dev *pdev, struct pci_bus_region *region,
368 struct resource *res)
369{
370 struct pci_pbm_info *pbm = pdev->bus->sysdata;
371 struct resource zero_res, *root;
372
373 zero_res.start = 0;
374 zero_res.end = 0;
375 zero_res.flags = res->flags;
376
377 if (res->flags & IORESOURCE_IO)
378 root = &pbm->io_space;
379 else
380 root = &pbm->mem_space;
381
382 pbm->parent->resource_adjust(pdev, &zero_res, root);
383
384 region->start = res->start - zero_res.start;
385 region->end = res->end - zero_res.start;
386}
David S. Miller5fdfd422006-04-17 13:34:44 -0700387EXPORT_SYMBOL(pcibios_resource_to_bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
389void pcibios_bus_to_resource(struct pci_dev *pdev, struct resource *res,
390 struct pci_bus_region *region)
391{
392 struct pci_pbm_info *pbm = pdev->bus->sysdata;
393 struct resource *root;
394
395 res->start = region->start;
396 res->end = region->end;
397
398 if (res->flags & IORESOURCE_IO)
399 root = &pbm->io_space;
400 else
401 root = &pbm->mem_space;
402
403 pbm->parent->resource_adjust(pdev, res, root);
404}
Keith Owens41290c12005-08-24 16:06:25 +1000405EXPORT_SYMBOL(pcibios_bus_to_resource);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
407char * __init pcibios_setup(char *str)
408{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 return str;
410}
411
412/* Platform support for /proc/bus/pci/X/Y mmap()s. */
413
414/* If the user uses a host-bridge as the PCI device, he may use
415 * this to perform a raw mmap() of the I/O or MEM space behind
416 * that controller.
417 *
418 * This can be useful for execution of x86 PCI bios initialization code
419 * on a PCI card, like the xfree86 int10 stuff does.
420 */
421static int __pci_mmap_make_offset_bus(struct pci_dev *pdev, struct vm_area_struct *vma,
422 enum pci_mmap_state mmap_state)
423{
424 struct pcidev_cookie *pcp = pdev->sysdata;
425 struct pci_pbm_info *pbm;
426 struct pci_controller_info *p;
427 unsigned long space_size, user_offset, user_size;
428
429 if (!pcp)
430 return -ENXIO;
431 pbm = pcp->pbm;
432 if (!pbm)
433 return -ENXIO;
434
435 p = pbm->parent;
436 if (p->pbms_same_domain) {
437 unsigned long lowest, highest;
438
439 lowest = ~0UL; highest = 0UL;
440 if (mmap_state == pci_mmap_io) {
441 if (p->pbm_A.io_space.flags) {
442 lowest = p->pbm_A.io_space.start;
443 highest = p->pbm_A.io_space.end + 1;
444 }
445 if (p->pbm_B.io_space.flags) {
446 if (lowest > p->pbm_B.io_space.start)
447 lowest = p->pbm_B.io_space.start;
448 if (highest < p->pbm_B.io_space.end + 1)
449 highest = p->pbm_B.io_space.end + 1;
450 }
451 space_size = highest - lowest;
452 } else {
453 if (p->pbm_A.mem_space.flags) {
454 lowest = p->pbm_A.mem_space.start;
455 highest = p->pbm_A.mem_space.end + 1;
456 }
457 if (p->pbm_B.mem_space.flags) {
458 if (lowest > p->pbm_B.mem_space.start)
459 lowest = p->pbm_B.mem_space.start;
460 if (highest < p->pbm_B.mem_space.end + 1)
461 highest = p->pbm_B.mem_space.end + 1;
462 }
463 space_size = highest - lowest;
464 }
465 } else {
466 if (mmap_state == pci_mmap_io) {
467 space_size = (pbm->io_space.end -
468 pbm->io_space.start) + 1;
469 } else {
470 space_size = (pbm->mem_space.end -
471 pbm->mem_space.start) + 1;
472 }
473 }
474
475 /* Make sure the request is in range. */
476 user_offset = vma->vm_pgoff << PAGE_SHIFT;
477 user_size = vma->vm_end - vma->vm_start;
478
479 if (user_offset >= space_size ||
480 (user_offset + user_size) > space_size)
481 return -EINVAL;
482
483 if (p->pbms_same_domain) {
484 unsigned long lowest = ~0UL;
485
486 if (mmap_state == pci_mmap_io) {
487 if (p->pbm_A.io_space.flags)
488 lowest = p->pbm_A.io_space.start;
489 if (p->pbm_B.io_space.flags &&
490 lowest > p->pbm_B.io_space.start)
491 lowest = p->pbm_B.io_space.start;
492 } else {
493 if (p->pbm_A.mem_space.flags)
494 lowest = p->pbm_A.mem_space.start;
495 if (p->pbm_B.mem_space.flags &&
496 lowest > p->pbm_B.mem_space.start)
497 lowest = p->pbm_B.mem_space.start;
498 }
499 vma->vm_pgoff = (lowest + user_offset) >> PAGE_SHIFT;
500 } else {
501 if (mmap_state == pci_mmap_io) {
502 vma->vm_pgoff = (pbm->io_space.start +
503 user_offset) >> PAGE_SHIFT;
504 } else {
505 vma->vm_pgoff = (pbm->mem_space.start +
506 user_offset) >> PAGE_SHIFT;
507 }
508 }
509
510 return 0;
511}
512
513/* Adjust vm_pgoff of VMA such that it is the physical page offset corresponding
514 * to the 32-bit pci bus offset for DEV requested by the user.
515 *
516 * Basically, the user finds the base address for his device which he wishes
517 * to mmap. They read the 32-bit value from the config space base register,
518 * add whatever PAGE_SIZE multiple offset they wish, and feed this into the
519 * offset parameter of mmap on /proc/bus/pci/XXX for that device.
520 *
521 * Returns negative error code on failure, zero on success.
522 */
523static int __pci_mmap_make_offset(struct pci_dev *dev, struct vm_area_struct *vma,
524 enum pci_mmap_state mmap_state)
525{
526 unsigned long user_offset = vma->vm_pgoff << PAGE_SHIFT;
527 unsigned long user32 = user_offset & pci_memspace_mask;
528 unsigned long largest_base, this_base, addr32;
529 int i;
530
531 if ((dev->class >> 8) == PCI_CLASS_BRIDGE_HOST)
532 return __pci_mmap_make_offset_bus(dev, vma, mmap_state);
533
534 /* Figure out which base address this is for. */
535 largest_base = 0UL;
536 for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
537 struct resource *rp = &dev->resource[i];
538
539 /* Active? */
540 if (!rp->flags)
541 continue;
542
543 /* Same type? */
544 if (i == PCI_ROM_RESOURCE) {
545 if (mmap_state != pci_mmap_mem)
546 continue;
547 } else {
548 if ((mmap_state == pci_mmap_io &&
549 (rp->flags & IORESOURCE_IO) == 0) ||
550 (mmap_state == pci_mmap_mem &&
551 (rp->flags & IORESOURCE_MEM) == 0))
552 continue;
553 }
554
555 this_base = rp->start;
556
557 addr32 = (this_base & PAGE_MASK) & pci_memspace_mask;
558
559 if (mmap_state == pci_mmap_io)
560 addr32 &= 0xffffff;
561
562 if (addr32 <= user32 && this_base > largest_base)
563 largest_base = this_base;
564 }
565
566 if (largest_base == 0UL)
567 return -EINVAL;
568
569 /* Now construct the final physical address. */
570 if (mmap_state == pci_mmap_io)
571 vma->vm_pgoff = (((largest_base & ~0xffffffUL) | user32) >> PAGE_SHIFT);
572 else
573 vma->vm_pgoff = (((largest_base & ~(pci_memspace_mask)) | user32) >> PAGE_SHIFT);
574
575 return 0;
576}
577
578/* Set vm_flags of VMA, as appropriate for this architecture, for a pci device
579 * mapping.
580 */
581static void __pci_mmap_set_flags(struct pci_dev *dev, struct vm_area_struct *vma,
582 enum pci_mmap_state mmap_state)
583{
584 vma->vm_flags |= (VM_IO | VM_RESERVED);
585}
586
587/* Set vm_page_prot of VMA, as appropriate for this architecture, for a pci
588 * device mapping.
589 */
590static void __pci_mmap_set_pgprot(struct pci_dev *dev, struct vm_area_struct *vma,
591 enum pci_mmap_state mmap_state)
592{
David S. Millera7a6cac2005-09-01 21:51:26 -0700593 /* Our io_remap_pfn_range takes care of this, do nothing. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594}
595
596/* Perform the actual remap of the pages for a PCI device mapping, as appropriate
597 * for this architecture. The region in the process to map is described by vm_start
598 * and vm_end members of VMA, the base physical address is found in vm_pgoff.
599 * The pci device structure is provided so that architectures may make mapping
600 * decisions on a per-device or per-bus basis.
601 *
602 * Returns a negative error code on failure, zero on success.
603 */
604int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
605 enum pci_mmap_state mmap_state,
606 int write_combine)
607{
608 int ret;
609
610 ret = __pci_mmap_make_offset(dev, vma, mmap_state);
611 if (ret < 0)
612 return ret;
613
614 __pci_mmap_set_flags(dev, vma, mmap_state);
615 __pci_mmap_set_pgprot(dev, vma, mmap_state);
616
David S. Miller14778d92006-03-21 02:29:39 -0800617 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 ret = io_remap_pfn_range(vma, vma->vm_start,
619 vma->vm_pgoff,
620 vma->vm_end - vma->vm_start,
621 vma->vm_page_prot);
622 if (ret)
623 return ret;
624
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 return 0;
626}
627
628/* Return the domain nuber for this pci bus */
629
630int pci_domain_nr(struct pci_bus *pbus)
631{
632 struct pci_pbm_info *pbm = pbus->sysdata;
633 int ret;
634
635 if (pbm == NULL || pbm->parent == NULL) {
636 ret = -ENXIO;
637 } else {
638 struct pci_controller_info *p = pbm->parent;
639
640 ret = p->index;
641 if (p->pbms_same_domain == 0)
642 ret = ((ret << 1) +
643 ((pbm == &pbm->parent->pbm_B) ? 1 : 0));
644 }
645
646 return ret;
647}
648EXPORT_SYMBOL(pci_domain_nr);
649
650int pcibios_prep_mwi(struct pci_dev *dev)
651{
652 /* We set correct PCI_CACHE_LINE_SIZE register values for every
653 * device probed on this platform. So there is nothing to check
654 * and this always succeeds.
655 */
656 return 0;
657}
658
659#endif /* !(CONFIG_PCI) */