| 1 | |
| 2 | |
| 3 | * arch/xtensa/kernel/pci.c
|
| 4 | *
|
| 5 | * PCI bios-type initialisation for PCI machines
|
| 6 | *
|
| 7 | * Copyright (C) 2001-2005 Tensilica Inc.
|
| 8 | *
|
| 9 | * Based largely on work from Cort (ppc/kernel/pci.c)
|
| 10 | * IO functions copied from sparc.
|
| 11 | *
|
| 12 | * Chris Zankel <[email protected]>
|
| 13 |
|
| 14 |
|
| 15 | #include <linux/kernel.h>
|
| 16 | #include <linux/pci.h>
|
| 17 | #include <linux/delay.h>
|
| 18 | #include <linux/string.h>
|
| 19 | #include <linux/init.h>
|
| 20 | #include <linux/sched.h>
|
| 21 | #include <linux/errno.h>
|
| 22 | #include <linux/memblock.h>
|
| 23 |
|
| 24 | #include <asm/pci-bridge.h>
|
| 25 | #include <asm/platform.h>
|
| 26 |
|
| 27 | |
| 28 | * We need to avoid collisions with `mirrored' VGA ports
|
| 29 | * and other strange ISA hardware, so we always want the
|
| 30 | * addresses to be allocated in the 0x000-0x0ff region
|
| 31 | * modulo 0x400.
|
| 32 | *
|
| 33 | * Why? Because some silly external IO cards only decode
|
| 34 | * the low 10 bits of the IO address. The 0x00-0xff region
|
| 35 | * is reserved for motherboard devices that decode all 16
|
| 36 | * bits, so it's ok to allocate at, say, 0x2800-0x28ff,
|
| 37 | * but we want to try to avoid allocating at 0x2900-0x2bff
|
| 38 | * which might have be mirrored at 0x0100-0x03ff..
|
| 39 |
|
| 40 | resource_size_t
|
| 41 | pcibios_align_resource(void *data, const struct resource *res,
|
| 42 | const struct resource *empty_res,
|
| 43 | resource_size_t size, resource_size_t align)
|
| 44 | {
|
| 45 | struct pci_dev *dev = data;
|
| 46 | resource_size_t start = res->start;
|
| 47 |
|
| 48 | if (res->flags & IORESOURCE_IO) {
|
| 49 | if (size > 0x100) {
|
| 50 | pr_err("PCI: I/O Region %s/%d too large (%u bytes)\n",
|
| 51 | pci_name(dev), dev->resource - res,
|
| 52 | size);
|
| 53 | }
|
| 54 |
|
| 55 | if (start & 0x300)
|
| 56 | start = (start + 0x3ff) & ~0x3ff;
|
| 57 | } else if (res->flags & IORESOURCE_MEM) {
|
| 58 | start = pci_align_resource(dev, res, empty_res, size, align);
|
| 59 | }
|
| 60 |
|
| 61 | return start;
|
| 62 | }
|
| 63 |
|
| 64 | void pcibios_fixup_bus(struct pci_bus *bus)
|
| 65 | {
|
| 66 | if (bus->parent) {
|
| 67 |
|
| 68 | pci_read_bridge_bases(bus);
|
| 69 | }
|
| 70 | }
|
| 71 |
|
| 72 | |
| 73 | * Platform support for /proc/bus/pci/X/Y mmap()s.
|
| 74 | * -- paulus.
|
| 75 |
|
| 76 |
|
| 77 | int pci_iobar_pfn(struct pci_dev *pdev, int bar, struct vm_area_struct *vma)
|
| 78 | {
|
| 79 | struct pci_controller *pci_ctrl = (struct pci_controller*) pdev->sysdata;
|
| 80 | resource_size_t ioaddr = pci_resource_start(pdev, bar);
|
| 81 |
|
| 82 | if (!pci_ctrl)
|
| 83 | return -EINVAL;
|
| 84 |
|
| 85 |
|
| 86 | ioaddr -= (unsigned long)pci_ctrl->io_space.base;
|
| 87 |
|
| 88 | vma->vm_pgoff += (ioaddr + pci_ctrl->io_space.start) >> PAGE_SHIFT;
|
| 89 | return 0;
|
| 90 | }
|