1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * arch/xtensa/kernel/pci.c
5 * PCI bios-type initialisation for PCI machines
7 * Copyright (C) 2001-2005 Tensilica Inc.
9 * Based largely on work from Cort (ppc/kernel/pci.c)
10 * IO functions copied from sparc.
12 * Chris Zankel <chris@zankel.net>
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>
24 #include <asm/pci-bridge.h>
25 #include <asm/platform.h>
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
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..
41 pcibios_align_resource(void *data
, const struct resource
*res
,
42 resource_size_t size
, resource_size_t align
)
44 struct pci_dev
*dev
= data
;
45 resource_size_t start
= res
->start
;
47 if (res
->flags
& IORESOURCE_IO
) {
49 pr_err("PCI: I/O Region %s/%d too large (%u bytes)\n",
50 pci_name(dev
), dev
->resource
- res
,
55 start
= (start
+ 0x3ff) & ~0x3ff;
61 void pcibios_fixup_bus(struct pci_bus
*bus
)
64 /* This is a subordinate bridge */
65 pci_read_bridge_bases(bus
);
70 * Platform support for /proc/bus/pci/X/Y mmap()s.
74 int pci_iobar_pfn(struct pci_dev
*pdev
, int bar
, struct vm_area_struct
*vma
)
76 struct pci_controller
*pci_ctrl
= (struct pci_controller
*) pdev
->sysdata
;
77 resource_size_t ioaddr
= pci_resource_start(pdev
, bar
);
80 return -EINVAL
; /* should never happen */
82 /* Convert to an offset within this PCI controller */
83 ioaddr
-= (unsigned long)pci_ctrl
->io_space
.base
;
85 vma
->vm_pgoff
+= (ioaddr
+ pci_ctrl
->io_space
.start
) >> PAGE_SHIFT
;