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