vserver 1.9.3
[linux-2.6.git] / arch / sparc64 / kernel / pci.c
1 /* $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/irq.h>
22 #include <asm/ebus.h>
23 #include <asm/isa.h>
24
25 unsigned long pci_memspace_mask = 0xffffffffUL;
26
27 #ifndef CONFIG_PCI
28 /* A "nop" PCI implementation. */
29 asmlinkage int sys_pciconfig_read(unsigned long bus, unsigned long dfn,
30                                   unsigned long off, unsigned long len,
31                                   unsigned char *buf)
32 {
33         return 0;
34 }
35 asmlinkage int sys_pciconfig_write(unsigned long bus, unsigned long dfn,
36                                    unsigned long off, unsigned long len,
37                                    unsigned char *buf)
38 {
39         return 0;
40 }
41 #else
42
43 /* List of all PCI controllers found in the system. */
44 struct pci_controller_info *pci_controller_root = NULL;
45
46 /* Each PCI controller found gets a unique index. */
47 int pci_num_controllers = 0;
48
49 /* At boot time the user can give the kernel a command
50  * line option which controls if and how PCI devices
51  * are reordered at PCI bus probing time.
52  */
53 int pci_device_reorder = 0;
54
55 volatile int pci_poke_in_progress;
56 volatile int pci_poke_cpu = -1;
57 volatile int pci_poke_faulted;
58
59 static spinlock_t pci_poke_lock = SPIN_LOCK_UNLOCKED;
60
61 void pci_config_read8(u8 *addr, u8 *ret)
62 {
63         unsigned long flags;
64         u8 byte;
65
66         spin_lock_irqsave(&pci_poke_lock, flags);
67         pci_poke_cpu = smp_processor_id();
68         pci_poke_in_progress = 1;
69         pci_poke_faulted = 0;
70         __asm__ __volatile__("membar #Sync\n\t"
71                              "lduba [%1] %2, %0\n\t"
72                              "membar #Sync"
73                              : "=r" (byte)
74                              : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
75                              : "memory");
76         pci_poke_in_progress = 0;
77         pci_poke_cpu = -1;
78         if (!pci_poke_faulted)
79                 *ret = byte;
80         spin_unlock_irqrestore(&pci_poke_lock, flags);
81 }
82
83 void pci_config_read16(u16 *addr, u16 *ret)
84 {
85         unsigned long flags;
86         u16 word;
87
88         spin_lock_irqsave(&pci_poke_lock, flags);
89         pci_poke_cpu = smp_processor_id();
90         pci_poke_in_progress = 1;
91         pci_poke_faulted = 0;
92         __asm__ __volatile__("membar #Sync\n\t"
93                              "lduha [%1] %2, %0\n\t"
94                              "membar #Sync"
95                              : "=r" (word)
96                              : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
97                              : "memory");
98         pci_poke_in_progress = 0;
99         pci_poke_cpu = -1;
100         if (!pci_poke_faulted)
101                 *ret = word;
102         spin_unlock_irqrestore(&pci_poke_lock, flags);
103 }
104
105 void pci_config_read32(u32 *addr, u32 *ret)
106 {
107         unsigned long flags;
108         u32 dword;
109
110         spin_lock_irqsave(&pci_poke_lock, flags);
111         pci_poke_cpu = smp_processor_id();
112         pci_poke_in_progress = 1;
113         pci_poke_faulted = 0;
114         __asm__ __volatile__("membar #Sync\n\t"
115                              "lduwa [%1] %2, %0\n\t"
116                              "membar #Sync"
117                              : "=r" (dword)
118                              : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
119                              : "memory");
120         pci_poke_in_progress = 0;
121         pci_poke_cpu = -1;
122         if (!pci_poke_faulted)
123                 *ret = dword;
124         spin_unlock_irqrestore(&pci_poke_lock, flags);
125 }
126
127 void pci_config_write8(u8 *addr, u8 val)
128 {
129         unsigned long flags;
130
131         spin_lock_irqsave(&pci_poke_lock, flags);
132         pci_poke_cpu = smp_processor_id();
133         pci_poke_in_progress = 1;
134         pci_poke_faulted = 0;
135         __asm__ __volatile__("membar #Sync\n\t"
136                              "stba %0, [%1] %2\n\t"
137                              "membar #Sync"
138                              : /* no outputs */
139                              : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
140                              : "memory");
141         pci_poke_in_progress = 0;
142         pci_poke_cpu = -1;
143         spin_unlock_irqrestore(&pci_poke_lock, flags);
144 }
145
146 void pci_config_write16(u16 *addr, u16 val)
147 {
148         unsigned long flags;
149
150         spin_lock_irqsave(&pci_poke_lock, flags);
151         pci_poke_cpu = smp_processor_id();
152         pci_poke_in_progress = 1;
153         pci_poke_faulted = 0;
154         __asm__ __volatile__("membar #Sync\n\t"
155                              "stha %0, [%1] %2\n\t"
156                              "membar #Sync"
157                              : /* no outputs */
158                              : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
159                              : "memory");
160         pci_poke_in_progress = 0;
161         pci_poke_cpu = -1;
162         spin_unlock_irqrestore(&pci_poke_lock, flags);
163 }
164
165 void pci_config_write32(u32 *addr, u32 val)
166 {
167         unsigned long flags;
168
169         spin_lock_irqsave(&pci_poke_lock, flags);
170         pci_poke_cpu = smp_processor_id();
171         pci_poke_in_progress = 1;
172         pci_poke_faulted = 0;
173         __asm__ __volatile__("membar #Sync\n\t"
174                              "stwa %0, [%1] %2\n\t"
175                              "membar #Sync"
176                              : /* no outputs */
177                              : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
178                              : "memory");
179         pci_poke_in_progress = 0;
180         pci_poke_cpu = -1;
181         spin_unlock_irqrestore(&pci_poke_lock, flags);
182 }
183
184 /* Probe for all PCI controllers in the system. */
185 extern void sabre_init(int, char *);
186 extern void psycho_init(int, char *);
187 extern void schizo_init(int, char *);
188 extern void schizo_plus_init(int, char *);
189 extern void tomatillo_init(int, char *);
190
191 static struct {
192         char *model_name;
193         void (*init)(int, char *);
194 } pci_controller_table[] __initdata = {
195         { "SUNW,sabre", sabre_init },
196         { "pci108e,a000", sabre_init },
197         { "pci108e,a001", sabre_init },
198         { "SUNW,psycho", psycho_init },
199         { "pci108e,8000", psycho_init },
200         { "SUNW,schizo", schizo_init },
201         { "pci108e,8001", schizo_init },
202         { "SUNW,schizo+", schizo_plus_init },
203         { "pci108e,8002", schizo_plus_init },
204         { "SUNW,tomatillo", tomatillo_init },
205         { "pci108e,a801", tomatillo_init },
206 };
207 #define PCI_NUM_CONTROLLER_TYPES (sizeof(pci_controller_table) / \
208                                   sizeof(pci_controller_table[0]))
209
210 static int __init pci_controller_init(char *model_name, int namelen, int node)
211 {
212         int i;
213
214         for (i = 0; i < PCI_NUM_CONTROLLER_TYPES; i++) {
215                 if (!strncmp(model_name,
216                              pci_controller_table[i].model_name,
217                              namelen)) {
218                         pci_controller_table[i].init(node, model_name);
219                         return 1;
220                 }
221         }
222         printk("PCI: Warning unknown controller, model name [%s]\n",
223                model_name);
224         printk("PCI: Ignoring controller...\n");
225
226         return 0;
227 }
228
229 static int __init pci_is_controller(char *model_name, int namelen, int node)
230 {
231         int i;
232
233         for (i = 0; i < PCI_NUM_CONTROLLER_TYPES; i++) {
234                 if (!strncmp(model_name,
235                              pci_controller_table[i].model_name,
236                              namelen)) {
237                         return 1;
238                 }
239         }
240         return 0;
241 }
242
243 static int __init pci_controller_scan(int (*handler)(char *, int, int))
244 {
245         char namebuf[64];
246         int node;
247         int count = 0;
248
249         node = prom_getchild(prom_root_node);
250         while ((node = prom_searchsiblings(node, "pci")) != 0) {
251                 int len;
252
253                 if ((len = prom_getproperty(node, "model", namebuf, sizeof(namebuf))) > 0 ||
254                     (len = prom_getproperty(node, "compatible", namebuf, sizeof(namebuf))) > 0) {
255                         int item_len = 0;
256
257                         /* Our value may be a multi-valued string in the
258                          * case of some compatible properties. For sanity,
259                          * only try the first one. */
260
261                         while (namebuf[item_len] && len) {
262                                 len--;
263                                 item_len++;
264                         }
265
266                         if (handler(namebuf, item_len, node))
267                                 count++;
268                 }
269
270                 node = prom_getsibling(node);
271                 if (!node)
272                         break;
273         }
274
275         return count;
276 }
277
278
279 /* Is there some PCI controller in the system?  */
280 int __init pcic_present(void)
281 {
282         return pci_controller_scan(pci_is_controller);
283 }
284
285 /* 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  */
290 static void __init pci_controller_probe(void)
291 {
292         printk("PCI: Probing for controllers.\n");
293
294         pci_controller_scan(pci_controller_init);
295 }
296
297 static void __init pci_scan_each_controller_bus(void)
298 {
299         struct pci_controller_info *p;
300
301         for (p = pci_controller_root; p; p = p->next)
302                 p->scan_bus(p);
303 }
304
305 /* Reorder the pci_dev chain, so that onboard devices come first
306  * and then come the pluggable cards.
307  */
308 static void __init pci_reorder_devs(void)
309 {
310         struct list_head *pci_onboard = &pci_devices;
311         struct list_head *walk = pci_onboard->next;
312
313         while (walk != pci_onboard) {
314                 struct pci_dev *pdev = pci_dev_g(walk);
315                 struct list_head *walk_next = walk->next;
316
317                 if (pdev->irq && (__irq_ino(pdev->irq) & 0x20)) {
318                         list_del(walk);
319                         list_add(walk, pci_onboard);
320                 }
321
322                 walk = walk_next;
323         }
324 }
325
326 extern void clock_probe(void);
327 extern void power_init(void);
328
329 static int __init pcibios_init(void)
330 {
331         pci_controller_probe();
332         if (pci_controller_root == NULL)
333                 return 0;
334
335         pci_scan_each_controller_bus();
336
337         if (pci_device_reorder)
338                 pci_reorder_devs();
339
340         isa_init();
341         ebus_init();
342         clock_probe();
343         power_init();
344
345         return 0;
346 }
347
348 subsys_initcall(pcibios_init);
349
350 void pcibios_fixup_bus(struct pci_bus *pbus)
351 {
352         struct pci_pbm_info *pbm = pbus->sysdata;
353
354         /* Generic PCI bus probing sets these to point at
355          * &io{port,mem}_resouce which is wrong for us.
356          */
357         pbus->resource[0] = &pbm->io_space;
358         pbus->resource[1] = &pbm->mem_space;
359 }
360
361 int pci_claim_resource(struct pci_dev *pdev, int resource)
362 {
363         struct pci_pbm_info *pbm = pdev->bus->sysdata;
364         struct resource *res = &pdev->resource[resource];
365         struct resource *root;
366
367         if (!pbm)
368                 return -EINVAL;
369
370         if (res->flags & IORESOURCE_IO)
371                 root = &pbm->io_space;
372         else
373                 root = &pbm->mem_space;
374
375         pbm->parent->resource_adjust(pdev, res, root);
376
377         return request_resource(root, res);
378 }
379
380 /*
381  * Given the PCI bus a device resides on, try to
382  * find an acceptable resource allocation for a
383  * specific device resource..
384  */
385 static int pci_assign_bus_resource(const struct pci_bus *bus,
386         struct pci_dev *dev,
387         struct resource *res,
388         unsigned long size,
389         unsigned long min,
390         int resno)
391 {
392         unsigned int type_mask;
393         int i;
394
395         type_mask = IORESOURCE_IO | IORESOURCE_MEM;
396         for (i = 0 ; i < 4; i++) {
397                 struct resource *r = bus->resource[i];
398                 if (!r)
399                         continue;
400
401                 /* type_mask must match */
402                 if ((res->flags ^ r->flags) & type_mask)
403                         continue;
404
405                 /* Ok, try it out.. */
406                 if (allocate_resource(r, res, size, min, -1, size, NULL, NULL) < 0)
407                         continue;
408
409                 /* PCI config space updated by caller.  */
410                 return 0;
411         }
412         return -EBUSY;
413 }
414
415 int pci_assign_resource(struct pci_dev *pdev, int resource)
416 {
417         struct pcidev_cookie *pcp = pdev->sysdata;
418         struct pci_pbm_info *pbm = pcp->pbm;
419         struct resource *res = &pdev->resource[resource];
420         unsigned long min, size;
421         int err;
422
423         if (res->flags & IORESOURCE_IO)
424                 min = pbm->io_space.start + 0x400UL;
425         else
426                 min = pbm->mem_space.start;
427
428         size = res->end - res->start + 1;
429
430         err = pci_assign_bus_resource(pdev->bus, pdev, res, size, min, resource);
431
432         if (err < 0) {
433                 printk("PCI: Failed to allocate resource %d for %s\n",
434                        resource, pci_name(pdev));
435         } else {
436                 /* Update PCI config space. */
437                 pbm->parent->base_address_update(pdev, resource);
438         }
439
440         return err;
441 }
442
443 /* Sort resources by alignment */
444 void pdev_sort_resources(struct pci_dev *dev, struct resource_list *head)
445 {
446         int i;
447
448         for (i = 0; i < PCI_NUM_RESOURCES; i++) {
449                 struct resource *r;
450                 struct resource_list *list, *tmp;
451                 unsigned long r_align;
452
453                 r = &dev->resource[i];
454                 r_align = r->end - r->start;
455                 
456                 if (!(r->flags) || r->parent)
457                         continue;
458                 if (!r_align) {
459                         printk(KERN_WARNING "PCI: Ignore bogus resource %d "
460                                             "[%lx:%lx] of %s\n",
461                                             i, r->start, r->end, pci_name(dev));
462                         continue;
463                 }
464                 r_align = (i < PCI_BRIDGE_RESOURCES) ? r_align + 1 : r->start;
465                 for (list = head; ; list = list->next) {
466                         unsigned long align = 0;
467                         struct resource_list *ln = list->next;
468                         int idx;
469
470                         if (ln) {
471                                 idx = ln->res - &ln->dev->resource[0];
472                                 align = (idx < PCI_BRIDGE_RESOURCES) ?
473                                         ln->res->end - ln->res->start + 1 :
474                                         ln->res->start;
475                         }
476                         if (r_align > align) {
477                                 tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
478                                 if (!tmp)
479                                         panic("pdev_sort_resources(): "
480                                               "kmalloc() failed!\n");
481                                 tmp->next = ln;
482                                 tmp->res = r;
483                                 tmp->dev = dev;
484                                 list->next = tmp;
485                                 break;
486                         }
487                 }
488         }
489 }
490
491 void pcibios_update_irq(struct pci_dev *pdev, int irq)
492 {
493 }
494
495 void pcibios_align_resource(void *data, struct resource *res,
496                             unsigned long size, unsigned long align)
497 {
498 }
499
500 int pcibios_enable_device(struct pci_dev *pdev, int mask)
501 {
502         return 0;
503 }
504
505 void pcibios_resource_to_bus(struct pci_dev *pdev, struct pci_bus_region *region,
506                              struct resource *res)
507 {
508         struct pci_pbm_info *pbm = pdev->bus->sysdata;
509         struct resource zero_res, *root;
510
511         zero_res.start = 0;
512         zero_res.end = 0;
513         zero_res.flags = res->flags;
514
515         if (res->flags & IORESOURCE_IO)
516                 root = &pbm->io_space;
517         else
518                 root = &pbm->mem_space;
519
520         pbm->parent->resource_adjust(pdev, &zero_res, root);
521
522         region->start = res->start - zero_res.start;
523         region->end = res->end - zero_res.start;
524 }
525
526 void pcibios_bus_to_resource(struct pci_dev *pdev, struct resource *res,
527                              struct pci_bus_region *region)
528 {
529         struct pci_pbm_info *pbm = pdev->bus->sysdata;
530         struct resource *root;
531
532         res->start = region->start;
533         res->end = region->end;
534
535         if (res->flags & IORESOURCE_IO)
536                 root = &pbm->io_space;
537         else
538                 root = &pbm->mem_space;
539
540         pbm->parent->resource_adjust(pdev, res, root);
541 }
542
543 char * __init pcibios_setup(char *str)
544 {
545         if (!strcmp(str, "onboardfirst")) {
546                 pci_device_reorder = 1;
547                 return NULL;
548         }
549         if (!strcmp(str, "noreorder")) {
550                 pci_device_reorder = 0;
551                 return NULL;
552         }
553         return str;
554 }
555
556 /* Platform support for /proc/bus/pci/X/Y mmap()s. */
557
558 /* If the user uses a host-bridge as the PCI device, he may use
559  * this to perform a raw mmap() of the I/O or MEM space behind
560  * that controller.
561  *
562  * This can be useful for execution of x86 PCI bios initialization code
563  * on a PCI card, like the xfree86 int10 stuff does.
564  */
565 static int __pci_mmap_make_offset_bus(struct pci_dev *pdev, struct vm_area_struct *vma,
566                                       enum pci_mmap_state mmap_state)
567 {
568         struct pcidev_cookie *pcp = pdev->sysdata;
569         struct pci_pbm_info *pbm;
570         struct pci_controller_info *p;
571         unsigned long space_size, user_offset, user_size;
572
573         if (!pcp)
574                 return -ENXIO;
575         pbm = pcp->pbm;
576         if (!pbm)
577                 return -ENXIO;
578
579         p = pbm->parent;
580         if (p->pbms_same_domain) {
581                 unsigned long lowest, highest;
582
583                 lowest = ~0UL; highest = 0UL;
584                 if (mmap_state == pci_mmap_io) {
585                         if (p->pbm_A.io_space.flags) {
586                                 lowest = p->pbm_A.io_space.start;
587                                 highest = p->pbm_A.io_space.end + 1;
588                         }
589                         if (p->pbm_B.io_space.flags) {
590                                 if (lowest > p->pbm_B.io_space.start)
591                                         lowest = p->pbm_B.io_space.start;
592                                 if (highest < p->pbm_B.io_space.end + 1)
593                                         highest = p->pbm_B.io_space.end + 1;
594                         }
595                         space_size = highest - lowest;
596                 } else {
597                         if (p->pbm_A.mem_space.flags) {
598                                 lowest = p->pbm_A.mem_space.start;
599                                 highest = p->pbm_A.mem_space.end + 1;
600                         }
601                         if (p->pbm_B.mem_space.flags) {
602                                 if (lowest > p->pbm_B.mem_space.start)
603                                         lowest = p->pbm_B.mem_space.start;
604                                 if (highest < p->pbm_B.mem_space.end + 1)
605                                         highest = p->pbm_B.mem_space.end + 1;
606                         }
607                         space_size = highest - lowest;
608                 }
609         } else {
610                 if (mmap_state == pci_mmap_io) {
611                         space_size = (pbm->io_space.end -
612                                       pbm->io_space.start) + 1;
613                 } else {
614                         space_size = (pbm->mem_space.end -
615                                       pbm->mem_space.start) + 1;
616                 }
617         }
618
619         /* Make sure the request is in range. */
620         user_offset = vma->vm_pgoff << PAGE_SHIFT;
621         user_size = vma->vm_end - vma->vm_start;
622
623         if (user_offset >= space_size ||
624             (user_offset + user_size) > space_size)
625                 return -EINVAL;
626
627         if (p->pbms_same_domain) {
628                 unsigned long lowest = ~0UL;
629
630                 if (mmap_state == pci_mmap_io) {
631                         if (p->pbm_A.io_space.flags)
632                                 lowest = p->pbm_A.io_space.start;
633                         if (p->pbm_B.io_space.flags &&
634                             lowest > p->pbm_B.io_space.start)
635                                 lowest = p->pbm_B.io_space.start;
636                 } else {
637                         if (p->pbm_A.mem_space.flags)
638                                 lowest = p->pbm_A.mem_space.start;
639                         if (p->pbm_B.mem_space.flags &&
640                             lowest > p->pbm_B.mem_space.start)
641                                 lowest = p->pbm_B.mem_space.start;
642                 }
643                 vma->vm_pgoff = (lowest + user_offset) >> PAGE_SHIFT;
644         } else {
645                 if (mmap_state == pci_mmap_io) {
646                         vma->vm_pgoff = (pbm->io_space.start +
647                                          user_offset) >> PAGE_SHIFT;
648                 } else {
649                         vma->vm_pgoff = (pbm->mem_space.start +
650                                          user_offset) >> PAGE_SHIFT;
651                 }
652         }
653
654         return 0;
655 }
656
657 /* Adjust vm_pgoff of VMA such that it is the physical page offset corresponding
658  * to the 32-bit pci bus offset for DEV requested by the user.
659  *
660  * Basically, the user finds the base address for his device which he wishes
661  * to mmap.  They read the 32-bit value from the config space base register,
662  * add whatever PAGE_SIZE multiple offset they wish, and feed this into the
663  * offset parameter of mmap on /proc/bus/pci/XXX for that device.
664  *
665  * Returns negative error code on failure, zero on success.
666  */
667 static int __pci_mmap_make_offset(struct pci_dev *dev, struct vm_area_struct *vma,
668                                   enum pci_mmap_state mmap_state)
669 {
670         unsigned long user_offset = vma->vm_pgoff << PAGE_SHIFT;
671         unsigned long user32 = user_offset & pci_memspace_mask;
672         unsigned long largest_base, this_base, addr32;
673         int i;
674
675         if ((dev->class >> 8) == PCI_CLASS_BRIDGE_HOST)
676                 return __pci_mmap_make_offset_bus(dev, vma, mmap_state);
677
678         /* Figure out which base address this is for. */
679         largest_base = 0UL;
680         for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
681                 struct resource *rp = &dev->resource[i];
682
683                 /* Active? */
684                 if (!rp->flags)
685                         continue;
686
687                 /* Same type? */
688                 if (i == PCI_ROM_RESOURCE) {
689                         if (mmap_state != pci_mmap_mem)
690                                 continue;
691                 } else {
692                         if ((mmap_state == pci_mmap_io &&
693                              (rp->flags & IORESOURCE_IO) == 0) ||
694                             (mmap_state == pci_mmap_mem &&
695                              (rp->flags & IORESOURCE_MEM) == 0))
696                                 continue;
697                 }
698
699                 this_base = rp->start;
700
701                 addr32 = (this_base & PAGE_MASK) & pci_memspace_mask;
702
703                 if (mmap_state == pci_mmap_io)
704                         addr32 &= 0xffffff;
705
706                 if (addr32 <= user32 && this_base > largest_base)
707                         largest_base = this_base;
708         }
709
710         if (largest_base == 0UL)
711                 return -EINVAL;
712
713         /* Now construct the final physical address. */
714         if (mmap_state == pci_mmap_io)
715                 vma->vm_pgoff = (((largest_base & ~0xffffffUL) | user32) >> PAGE_SHIFT);
716         else
717                 vma->vm_pgoff = (((largest_base & ~(pci_memspace_mask)) | user32) >> PAGE_SHIFT);
718
719         return 0;
720 }
721
722 /* Set vm_flags of VMA, as appropriate for this architecture, for a pci device
723  * mapping.
724  */
725 static void __pci_mmap_set_flags(struct pci_dev *dev, struct vm_area_struct *vma,
726                                             enum pci_mmap_state mmap_state)
727 {
728         vma->vm_flags |= (VM_SHM | VM_LOCKED);
729 }
730
731 /* Set vm_page_prot of VMA, as appropriate for this architecture, for a pci
732  * device mapping.
733  */
734 static void __pci_mmap_set_pgprot(struct pci_dev *dev, struct vm_area_struct *vma,
735                                              enum pci_mmap_state mmap_state)
736 {
737         /* Our io_remap_page_range takes care of this, do nothing. */
738 }
739
740 extern int io_remap_page_range(struct vm_area_struct *vma, unsigned long from, unsigned long offset,
741                                unsigned long size, pgprot_t prot, int space);
742
743 /* Perform the actual remap of the pages for a PCI device mapping, as appropriate
744  * for this architecture.  The region in the process to map is described by vm_start
745  * and vm_end members of VMA, the base physical address is found in vm_pgoff.
746  * The pci device structure is provided so that architectures may make mapping
747  * decisions on a per-device or per-bus basis.
748  *
749  * Returns a negative error code on failure, zero on success.
750  */
751 int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
752                         enum pci_mmap_state mmap_state,
753                         int write_combine)
754 {
755         int ret;
756
757         ret = __pci_mmap_make_offset(dev, vma, mmap_state);
758         if (ret < 0)
759                 return ret;
760
761         __pci_mmap_set_flags(dev, vma, mmap_state);
762         __pci_mmap_set_pgprot(dev, vma, mmap_state);
763
764         ret = io_remap_page_range(vma, vma->vm_start,
765                                   (vma->vm_pgoff << PAGE_SHIFT |
766                                    (write_combine ? 0x1UL : 0x0UL)),
767                                   vma->vm_end - vma->vm_start, vma->vm_page_prot, 0);
768         if (ret)
769                 return ret;
770
771         vma->vm_flags |= VM_IO;
772         return 0;
773 }
774
775 /* Return the domain nuber for this pci bus */
776
777 int pci_domain_nr(struct pci_bus *pbus)
778 {
779         struct pci_pbm_info *pbm = pbus->sysdata;
780         int ret;
781
782         if (pbm == NULL || pbm->parent == NULL) {
783                 ret = -ENXIO;
784         } else {
785                 struct pci_controller_info *p = pbm->parent;
786
787                 ret = p->index;
788                 if (p->pbms_same_domain == 0)
789                         ret = ((ret << 1) +
790                                ((pbm == &pbm->parent->pbm_B) ? 1 : 0));
791         }
792
793         return ret;
794 }
795 EXPORT_SYMBOL(pci_domain_nr);
796
797 int pci_name_bus(char *name, struct pci_bus *bus)
798 {
799         sprintf(name, "%04x:%02x", pci_domain_nr(bus), bus->number);
800         return 0;
801 }
802
803 int pcibios_prep_mwi(struct pci_dev *dev)
804 {
805         /* We set correct PCI_CACHE_LINE_SIZE register values for every
806          * device probed on this platform.  So there is nothing to check
807          * and this always succeeds.
808          */
809         return 0;
810 }
811
812 #endif /* !(CONFIG_PCI) */