1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Contains common pci routines for ALL ppc platform
4*4882a593Smuzhiyun * (based on pci_32.c and pci_64.c)
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Port for PPC64 David Engebretsen, IBM Corp.
7*4882a593Smuzhiyun * Contains common pci routines for ppc64 platform, pSeries and iSeries brands.
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * Copyright (C) 2003 Anton Blanchard <anton@au.ibm.com>, IBM
10*4882a593Smuzhiyun * Rework, based on alpha PCI code.
11*4882a593Smuzhiyun *
12*4882a593Smuzhiyun * Common pmac/prep/chrp pci routines. -- Cort
13*4882a593Smuzhiyun */
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun #include <linux/kernel.h>
16*4882a593Smuzhiyun #include <linux/pci.h>
17*4882a593Smuzhiyun #include <linux/string.h>
18*4882a593Smuzhiyun #include <linux/init.h>
19*4882a593Smuzhiyun #include <linux/memblock.h>
20*4882a593Smuzhiyun #include <linux/mm.h>
21*4882a593Smuzhiyun #include <linux/shmem_fs.h>
22*4882a593Smuzhiyun #include <linux/list.h>
23*4882a593Smuzhiyun #include <linux/syscalls.h>
24*4882a593Smuzhiyun #include <linux/irq.h>
25*4882a593Smuzhiyun #include <linux/vmalloc.h>
26*4882a593Smuzhiyun #include <linux/slab.h>
27*4882a593Smuzhiyun #include <linux/of.h>
28*4882a593Smuzhiyun #include <linux/of_address.h>
29*4882a593Smuzhiyun #include <linux/of_irq.h>
30*4882a593Smuzhiyun #include <linux/of_pci.h>
31*4882a593Smuzhiyun #include <linux/export.h>
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun #include <asm/processor.h>
34*4882a593Smuzhiyun #include <linux/io.h>
35*4882a593Smuzhiyun #include <asm/pci-bridge.h>
36*4882a593Smuzhiyun #include <asm/byteorder.h>
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun static DEFINE_SPINLOCK(hose_spinlock);
39*4882a593Smuzhiyun LIST_HEAD(hose_list);
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun /* XXX kill that some day ... */
42*4882a593Smuzhiyun static int global_phb_number; /* Global phb counter */
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun /* ISA Memory physical address */
45*4882a593Smuzhiyun resource_size_t isa_mem_base;
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun unsigned long isa_io_base;
48*4882a593Smuzhiyun EXPORT_SYMBOL(isa_io_base);
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun static int pci_bus_count;
51*4882a593Smuzhiyun
pcibios_alloc_controller(struct device_node * dev)52*4882a593Smuzhiyun struct pci_controller *pcibios_alloc_controller(struct device_node *dev)
53*4882a593Smuzhiyun {
54*4882a593Smuzhiyun struct pci_controller *phb;
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun phb = zalloc_maybe_bootmem(sizeof(struct pci_controller), GFP_KERNEL);
57*4882a593Smuzhiyun if (!phb)
58*4882a593Smuzhiyun return NULL;
59*4882a593Smuzhiyun spin_lock(&hose_spinlock);
60*4882a593Smuzhiyun phb->global_number = global_phb_number++;
61*4882a593Smuzhiyun list_add_tail(&phb->list_node, &hose_list);
62*4882a593Smuzhiyun spin_unlock(&hose_spinlock);
63*4882a593Smuzhiyun phb->dn = dev;
64*4882a593Smuzhiyun phb->is_dynamic = mem_init_done;
65*4882a593Smuzhiyun return phb;
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun
pcibios_free_controller(struct pci_controller * phb)68*4882a593Smuzhiyun void pcibios_free_controller(struct pci_controller *phb)
69*4882a593Smuzhiyun {
70*4882a593Smuzhiyun spin_lock(&hose_spinlock);
71*4882a593Smuzhiyun list_del(&phb->list_node);
72*4882a593Smuzhiyun spin_unlock(&hose_spinlock);
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun if (phb->is_dynamic)
75*4882a593Smuzhiyun kfree(phb);
76*4882a593Smuzhiyun }
77*4882a593Smuzhiyun
pcibios_io_size(const struct pci_controller * hose)78*4882a593Smuzhiyun static resource_size_t pcibios_io_size(const struct pci_controller *hose)
79*4882a593Smuzhiyun {
80*4882a593Smuzhiyun return resource_size(&hose->io_resource);
81*4882a593Smuzhiyun }
82*4882a593Smuzhiyun
pcibios_vaddr_is_ioport(void __iomem * address)83*4882a593Smuzhiyun int pcibios_vaddr_is_ioport(void __iomem *address)
84*4882a593Smuzhiyun {
85*4882a593Smuzhiyun int ret = 0;
86*4882a593Smuzhiyun struct pci_controller *hose;
87*4882a593Smuzhiyun resource_size_t size;
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun spin_lock(&hose_spinlock);
90*4882a593Smuzhiyun list_for_each_entry(hose, &hose_list, list_node) {
91*4882a593Smuzhiyun size = pcibios_io_size(hose);
92*4882a593Smuzhiyun if (address >= hose->io_base_virt &&
93*4882a593Smuzhiyun address < (hose->io_base_virt + size)) {
94*4882a593Smuzhiyun ret = 1;
95*4882a593Smuzhiyun break;
96*4882a593Smuzhiyun }
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun spin_unlock(&hose_spinlock);
99*4882a593Smuzhiyun return ret;
100*4882a593Smuzhiyun }
101*4882a593Smuzhiyun
pci_address_to_pio(phys_addr_t address)102*4882a593Smuzhiyun unsigned long pci_address_to_pio(phys_addr_t address)
103*4882a593Smuzhiyun {
104*4882a593Smuzhiyun struct pci_controller *hose;
105*4882a593Smuzhiyun resource_size_t size;
106*4882a593Smuzhiyun unsigned long ret = ~0;
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun spin_lock(&hose_spinlock);
109*4882a593Smuzhiyun list_for_each_entry(hose, &hose_list, list_node) {
110*4882a593Smuzhiyun size = pcibios_io_size(hose);
111*4882a593Smuzhiyun if (address >= hose->io_base_phys &&
112*4882a593Smuzhiyun address < (hose->io_base_phys + size)) {
113*4882a593Smuzhiyun unsigned long base =
114*4882a593Smuzhiyun (unsigned long)hose->io_base_virt - _IO_BASE;
115*4882a593Smuzhiyun ret = base + (address - hose->io_base_phys);
116*4882a593Smuzhiyun break;
117*4882a593Smuzhiyun }
118*4882a593Smuzhiyun }
119*4882a593Smuzhiyun spin_unlock(&hose_spinlock);
120*4882a593Smuzhiyun
121*4882a593Smuzhiyun return ret;
122*4882a593Smuzhiyun }
123*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(pci_address_to_pio);
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun /* This routine is meant to be used early during boot, when the
126*4882a593Smuzhiyun * PCI bus numbers have not yet been assigned, and you need to
127*4882a593Smuzhiyun * issue PCI config cycles to an OF device.
128*4882a593Smuzhiyun * It could also be used to "fix" RTAS config cycles if you want
129*4882a593Smuzhiyun * to set pci_assign_all_buses to 1 and still use RTAS for PCI
130*4882a593Smuzhiyun * config cycles.
131*4882a593Smuzhiyun */
pci_find_hose_for_OF_device(struct device_node * node)132*4882a593Smuzhiyun struct pci_controller *pci_find_hose_for_OF_device(struct device_node *node)
133*4882a593Smuzhiyun {
134*4882a593Smuzhiyun while (node) {
135*4882a593Smuzhiyun struct pci_controller *hose, *tmp;
136*4882a593Smuzhiyun list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
137*4882a593Smuzhiyun if (hose->dn == node)
138*4882a593Smuzhiyun return hose;
139*4882a593Smuzhiyun node = node->parent;
140*4882a593Smuzhiyun }
141*4882a593Smuzhiyun return NULL;
142*4882a593Smuzhiyun }
143*4882a593Smuzhiyun
pcibios_set_master(struct pci_dev * dev)144*4882a593Smuzhiyun void pcibios_set_master(struct pci_dev *dev)
145*4882a593Smuzhiyun {
146*4882a593Smuzhiyun /* No special bus mastering setup handling */
147*4882a593Smuzhiyun }
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun /*
150*4882a593Smuzhiyun * Platform support for /proc/bus/pci/X/Y mmap()s.
151*4882a593Smuzhiyun */
152*4882a593Smuzhiyun
pci_iobar_pfn(struct pci_dev * pdev,int bar,struct vm_area_struct * vma)153*4882a593Smuzhiyun int pci_iobar_pfn(struct pci_dev *pdev, int bar, struct vm_area_struct *vma)
154*4882a593Smuzhiyun {
155*4882a593Smuzhiyun struct pci_controller *hose = pci_bus_to_host(pdev->bus);
156*4882a593Smuzhiyun resource_size_t ioaddr = pci_resource_start(pdev, bar);
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun if (!hose)
159*4882a593Smuzhiyun return -EINVAL; /* should never happen */
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun /* Convert to an offset within this PCI controller */
162*4882a593Smuzhiyun ioaddr -= (unsigned long)hose->io_base_virt - _IO_BASE;
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun vma->vm_pgoff += (ioaddr + hose->io_base_phys) >> PAGE_SHIFT;
165*4882a593Smuzhiyun return 0;
166*4882a593Smuzhiyun }
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun /*
169*4882a593Smuzhiyun * This one is used by /dev/mem and fbdev who have no clue about the
170*4882a593Smuzhiyun * PCI device, it tries to find the PCI device first and calls the
171*4882a593Smuzhiyun * above routine
172*4882a593Smuzhiyun */
pci_phys_mem_access_prot(struct file * file,unsigned long pfn,unsigned long size,pgprot_t prot)173*4882a593Smuzhiyun pgprot_t pci_phys_mem_access_prot(struct file *file,
174*4882a593Smuzhiyun unsigned long pfn,
175*4882a593Smuzhiyun unsigned long size,
176*4882a593Smuzhiyun pgprot_t prot)
177*4882a593Smuzhiyun {
178*4882a593Smuzhiyun struct pci_dev *pdev = NULL;
179*4882a593Smuzhiyun struct resource *found = NULL;
180*4882a593Smuzhiyun resource_size_t offset = ((resource_size_t)pfn) << PAGE_SHIFT;
181*4882a593Smuzhiyun int i;
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun if (page_is_ram(pfn))
184*4882a593Smuzhiyun return prot;
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun prot = pgprot_noncached(prot);
187*4882a593Smuzhiyun for_each_pci_dev(pdev) {
188*4882a593Smuzhiyun for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
189*4882a593Smuzhiyun struct resource *rp = &pdev->resource[i];
190*4882a593Smuzhiyun int flags = rp->flags;
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun /* Active and same type? */
193*4882a593Smuzhiyun if ((flags & IORESOURCE_MEM) == 0)
194*4882a593Smuzhiyun continue;
195*4882a593Smuzhiyun /* In the range of this resource? */
196*4882a593Smuzhiyun if (offset < (rp->start & PAGE_MASK) ||
197*4882a593Smuzhiyun offset > rp->end)
198*4882a593Smuzhiyun continue;
199*4882a593Smuzhiyun found = rp;
200*4882a593Smuzhiyun break;
201*4882a593Smuzhiyun }
202*4882a593Smuzhiyun if (found)
203*4882a593Smuzhiyun break;
204*4882a593Smuzhiyun }
205*4882a593Smuzhiyun if (found) {
206*4882a593Smuzhiyun if (found->flags & IORESOURCE_PREFETCH)
207*4882a593Smuzhiyun prot = pgprot_noncached_wc(prot);
208*4882a593Smuzhiyun pci_dev_put(pdev);
209*4882a593Smuzhiyun }
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun pr_debug("PCI: Non-PCI map for %llx, prot: %lx\n",
212*4882a593Smuzhiyun (unsigned long long)offset, pgprot_val(prot));
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun return prot;
215*4882a593Smuzhiyun }
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun /* This provides legacy IO read access on a bus */
pci_legacy_read(struct pci_bus * bus,loff_t port,u32 * val,size_t size)218*4882a593Smuzhiyun int pci_legacy_read(struct pci_bus *bus, loff_t port, u32 *val, size_t size)
219*4882a593Smuzhiyun {
220*4882a593Smuzhiyun unsigned long offset;
221*4882a593Smuzhiyun struct pci_controller *hose = pci_bus_to_host(bus);
222*4882a593Smuzhiyun struct resource *rp = &hose->io_resource;
223*4882a593Smuzhiyun void __iomem *addr;
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun /* Check if port can be supported by that bus. We only check
226*4882a593Smuzhiyun * the ranges of the PHB though, not the bus itself as the rules
227*4882a593Smuzhiyun * for forwarding legacy cycles down bridges are not our problem
228*4882a593Smuzhiyun * here. So if the host bridge supports it, we do it.
229*4882a593Smuzhiyun */
230*4882a593Smuzhiyun offset = (unsigned long)hose->io_base_virt - _IO_BASE;
231*4882a593Smuzhiyun offset += port;
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun if (!(rp->flags & IORESOURCE_IO))
234*4882a593Smuzhiyun return -ENXIO;
235*4882a593Smuzhiyun if (offset < rp->start || (offset + size) > rp->end)
236*4882a593Smuzhiyun return -ENXIO;
237*4882a593Smuzhiyun addr = hose->io_base_virt + port;
238*4882a593Smuzhiyun
239*4882a593Smuzhiyun switch (size) {
240*4882a593Smuzhiyun case 1:
241*4882a593Smuzhiyun *((u8 *)val) = in_8(addr);
242*4882a593Smuzhiyun return 1;
243*4882a593Smuzhiyun case 2:
244*4882a593Smuzhiyun if (port & 1)
245*4882a593Smuzhiyun return -EINVAL;
246*4882a593Smuzhiyun *((u16 *)val) = in_le16(addr);
247*4882a593Smuzhiyun return 2;
248*4882a593Smuzhiyun case 4:
249*4882a593Smuzhiyun if (port & 3)
250*4882a593Smuzhiyun return -EINVAL;
251*4882a593Smuzhiyun *((u32 *)val) = in_le32(addr);
252*4882a593Smuzhiyun return 4;
253*4882a593Smuzhiyun }
254*4882a593Smuzhiyun return -EINVAL;
255*4882a593Smuzhiyun }
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun /* This provides legacy IO write access on a bus */
pci_legacy_write(struct pci_bus * bus,loff_t port,u32 val,size_t size)258*4882a593Smuzhiyun int pci_legacy_write(struct pci_bus *bus, loff_t port, u32 val, size_t size)
259*4882a593Smuzhiyun {
260*4882a593Smuzhiyun unsigned long offset;
261*4882a593Smuzhiyun struct pci_controller *hose = pci_bus_to_host(bus);
262*4882a593Smuzhiyun struct resource *rp = &hose->io_resource;
263*4882a593Smuzhiyun void __iomem *addr;
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun /* Check if port can be supported by that bus. We only check
266*4882a593Smuzhiyun * the ranges of the PHB though, not the bus itself as the rules
267*4882a593Smuzhiyun * for forwarding legacy cycles down bridges are not our problem
268*4882a593Smuzhiyun * here. So if the host bridge supports it, we do it.
269*4882a593Smuzhiyun */
270*4882a593Smuzhiyun offset = (unsigned long)hose->io_base_virt - _IO_BASE;
271*4882a593Smuzhiyun offset += port;
272*4882a593Smuzhiyun
273*4882a593Smuzhiyun if (!(rp->flags & IORESOURCE_IO))
274*4882a593Smuzhiyun return -ENXIO;
275*4882a593Smuzhiyun if (offset < rp->start || (offset + size) > rp->end)
276*4882a593Smuzhiyun return -ENXIO;
277*4882a593Smuzhiyun addr = hose->io_base_virt + port;
278*4882a593Smuzhiyun
279*4882a593Smuzhiyun /* WARNING: The generic code is idiotic. It gets passed a pointer
280*4882a593Smuzhiyun * to what can be a 1, 2 or 4 byte quantity and always reads that
281*4882a593Smuzhiyun * as a u32, which means that we have to correct the location of
282*4882a593Smuzhiyun * the data read within those 32 bits for size 1 and 2
283*4882a593Smuzhiyun */
284*4882a593Smuzhiyun switch (size) {
285*4882a593Smuzhiyun case 1:
286*4882a593Smuzhiyun out_8(addr, val >> 24);
287*4882a593Smuzhiyun return 1;
288*4882a593Smuzhiyun case 2:
289*4882a593Smuzhiyun if (port & 1)
290*4882a593Smuzhiyun return -EINVAL;
291*4882a593Smuzhiyun out_le16(addr, val >> 16);
292*4882a593Smuzhiyun return 2;
293*4882a593Smuzhiyun case 4:
294*4882a593Smuzhiyun if (port & 3)
295*4882a593Smuzhiyun return -EINVAL;
296*4882a593Smuzhiyun out_le32(addr, val);
297*4882a593Smuzhiyun return 4;
298*4882a593Smuzhiyun }
299*4882a593Smuzhiyun return -EINVAL;
300*4882a593Smuzhiyun }
301*4882a593Smuzhiyun
302*4882a593Smuzhiyun /* This provides legacy IO or memory mmap access on a bus */
pci_mmap_legacy_page_range(struct pci_bus * bus,struct vm_area_struct * vma,enum pci_mmap_state mmap_state)303*4882a593Smuzhiyun int pci_mmap_legacy_page_range(struct pci_bus *bus,
304*4882a593Smuzhiyun struct vm_area_struct *vma,
305*4882a593Smuzhiyun enum pci_mmap_state mmap_state)
306*4882a593Smuzhiyun {
307*4882a593Smuzhiyun struct pci_controller *hose = pci_bus_to_host(bus);
308*4882a593Smuzhiyun resource_size_t offset =
309*4882a593Smuzhiyun ((resource_size_t)vma->vm_pgoff) << PAGE_SHIFT;
310*4882a593Smuzhiyun resource_size_t size = vma->vm_end - vma->vm_start;
311*4882a593Smuzhiyun struct resource *rp;
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun pr_debug("pci_mmap_legacy_page_range(%04x:%02x, %s @%llx..%llx)\n",
314*4882a593Smuzhiyun pci_domain_nr(bus), bus->number,
315*4882a593Smuzhiyun mmap_state == pci_mmap_mem ? "MEM" : "IO",
316*4882a593Smuzhiyun (unsigned long long)offset,
317*4882a593Smuzhiyun (unsigned long long)(offset + size - 1));
318*4882a593Smuzhiyun
319*4882a593Smuzhiyun if (mmap_state == pci_mmap_mem) {
320*4882a593Smuzhiyun /* Hack alert !
321*4882a593Smuzhiyun *
322*4882a593Smuzhiyun * Because X is lame and can fail starting if it gets an error
323*4882a593Smuzhiyun * trying to mmap legacy_mem (instead of just moving on without
324*4882a593Smuzhiyun * legacy memory access) we fake it here by giving it anonymous
325*4882a593Smuzhiyun * memory, effectively behaving just like /dev/zero
326*4882a593Smuzhiyun */
327*4882a593Smuzhiyun if ((offset + size) > hose->isa_mem_size) {
328*4882a593Smuzhiyun #ifdef CONFIG_MMU
329*4882a593Smuzhiyun pr_debug("Process %s (pid:%d) mapped non-existing PCI",
330*4882a593Smuzhiyun current->comm, current->pid);
331*4882a593Smuzhiyun pr_debug("legacy memory for 0%04x:%02x\n",
332*4882a593Smuzhiyun pci_domain_nr(bus), bus->number);
333*4882a593Smuzhiyun #endif
334*4882a593Smuzhiyun if (vma->vm_flags & VM_SHARED)
335*4882a593Smuzhiyun return shmem_zero_setup(vma);
336*4882a593Smuzhiyun return 0;
337*4882a593Smuzhiyun }
338*4882a593Smuzhiyun offset += hose->isa_mem_phys;
339*4882a593Smuzhiyun } else {
340*4882a593Smuzhiyun unsigned long io_offset = (unsigned long)hose->io_base_virt -
341*4882a593Smuzhiyun _IO_BASE;
342*4882a593Smuzhiyun unsigned long roffset = offset + io_offset;
343*4882a593Smuzhiyun rp = &hose->io_resource;
344*4882a593Smuzhiyun if (!(rp->flags & IORESOURCE_IO))
345*4882a593Smuzhiyun return -ENXIO;
346*4882a593Smuzhiyun if (roffset < rp->start || (roffset + size) > rp->end)
347*4882a593Smuzhiyun return -ENXIO;
348*4882a593Smuzhiyun offset += hose->io_base_phys;
349*4882a593Smuzhiyun }
350*4882a593Smuzhiyun pr_debug(" -> mapping phys %llx\n", (unsigned long long)offset);
351*4882a593Smuzhiyun
352*4882a593Smuzhiyun vma->vm_pgoff = offset >> PAGE_SHIFT;
353*4882a593Smuzhiyun vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
354*4882a593Smuzhiyun return remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
355*4882a593Smuzhiyun vma->vm_end - vma->vm_start,
356*4882a593Smuzhiyun vma->vm_page_prot);
357*4882a593Smuzhiyun }
358*4882a593Smuzhiyun
pci_resource_to_user(const struct pci_dev * dev,int bar,const struct resource * rsrc,resource_size_t * start,resource_size_t * end)359*4882a593Smuzhiyun void pci_resource_to_user(const struct pci_dev *dev, int bar,
360*4882a593Smuzhiyun const struct resource *rsrc,
361*4882a593Smuzhiyun resource_size_t *start, resource_size_t *end)
362*4882a593Smuzhiyun {
363*4882a593Smuzhiyun struct pci_bus_region region;
364*4882a593Smuzhiyun
365*4882a593Smuzhiyun if (rsrc->flags & IORESOURCE_IO) {
366*4882a593Smuzhiyun pcibios_resource_to_bus(dev->bus, ®ion,
367*4882a593Smuzhiyun (struct resource *) rsrc);
368*4882a593Smuzhiyun *start = region.start;
369*4882a593Smuzhiyun *end = region.end;
370*4882a593Smuzhiyun return;
371*4882a593Smuzhiyun }
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun /* We pass a CPU physical address to userland for MMIO instead of a
374*4882a593Smuzhiyun * BAR value because X is lame and expects to be able to use that
375*4882a593Smuzhiyun * to pass to /dev/mem!
376*4882a593Smuzhiyun *
377*4882a593Smuzhiyun * That means we may have 64-bit values where some apps only expect
378*4882a593Smuzhiyun * 32 (like X itself since it thinks only Sparc has 64-bit MMIO).
379*4882a593Smuzhiyun */
380*4882a593Smuzhiyun *start = rsrc->start;
381*4882a593Smuzhiyun *end = rsrc->end;
382*4882a593Smuzhiyun }
383*4882a593Smuzhiyun
384*4882a593Smuzhiyun /**
385*4882a593Smuzhiyun * pci_process_bridge_OF_ranges - Parse PCI bridge resources from device tree
386*4882a593Smuzhiyun * @hose: newly allocated pci_controller to be setup
387*4882a593Smuzhiyun * @dev: device node of the host bridge
388*4882a593Smuzhiyun * @primary: set if primary bus (32 bits only, soon to be deprecated)
389*4882a593Smuzhiyun *
390*4882a593Smuzhiyun * This function will parse the "ranges" property of a PCI host bridge device
391*4882a593Smuzhiyun * node and setup the resource mapping of a pci controller based on its
392*4882a593Smuzhiyun * content.
393*4882a593Smuzhiyun *
394*4882a593Smuzhiyun * Life would be boring if it wasn't for a few issues that we have to deal
395*4882a593Smuzhiyun * with here:
396*4882a593Smuzhiyun *
397*4882a593Smuzhiyun * - We can only cope with one IO space range and up to 3 Memory space
398*4882a593Smuzhiyun * ranges. However, some machines (thanks Apple !) tend to split their
399*4882a593Smuzhiyun * space into lots of small contiguous ranges. So we have to coalesce.
400*4882a593Smuzhiyun *
401*4882a593Smuzhiyun * - We can only cope with all memory ranges having the same offset
402*4882a593Smuzhiyun * between CPU addresses and PCI addresses. Unfortunately, some bridges
403*4882a593Smuzhiyun * are setup for a large 1:1 mapping along with a small "window" which
404*4882a593Smuzhiyun * maps PCI address 0 to some arbitrary high address of the CPU space in
405*4882a593Smuzhiyun * order to give access to the ISA memory hole.
406*4882a593Smuzhiyun * The way out of here that I've chosen for now is to always set the
407*4882a593Smuzhiyun * offset based on the first resource found, then override it if we
408*4882a593Smuzhiyun * have a different offset and the previous was set by an ISA hole.
409*4882a593Smuzhiyun *
410*4882a593Smuzhiyun * - Some busses have IO space not starting at 0, which causes trouble with
411*4882a593Smuzhiyun * the way we do our IO resource renumbering. The code somewhat deals with
412*4882a593Smuzhiyun * it for 64 bits but I would expect problems on 32 bits.
413*4882a593Smuzhiyun *
414*4882a593Smuzhiyun * - Some 32 bits platforms such as 4xx can have physical space larger than
415*4882a593Smuzhiyun * 32 bits so we need to use 64 bits values for the parsing
416*4882a593Smuzhiyun */
pci_process_bridge_OF_ranges(struct pci_controller * hose,struct device_node * dev,int primary)417*4882a593Smuzhiyun void pci_process_bridge_OF_ranges(struct pci_controller *hose,
418*4882a593Smuzhiyun struct device_node *dev, int primary)
419*4882a593Smuzhiyun {
420*4882a593Smuzhiyun int memno = 0, isa_hole = -1;
421*4882a593Smuzhiyun unsigned long long isa_mb = 0;
422*4882a593Smuzhiyun struct resource *res;
423*4882a593Smuzhiyun struct of_pci_range range;
424*4882a593Smuzhiyun struct of_pci_range_parser parser;
425*4882a593Smuzhiyun
426*4882a593Smuzhiyun pr_info("PCI host bridge %pOF %s ranges:\n",
427*4882a593Smuzhiyun dev, primary ? "(primary)" : "");
428*4882a593Smuzhiyun
429*4882a593Smuzhiyun /* Check for ranges property */
430*4882a593Smuzhiyun if (of_pci_range_parser_init(&parser, dev))
431*4882a593Smuzhiyun return;
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun pr_debug("Parsing ranges property...\n");
434*4882a593Smuzhiyun for_each_of_pci_range(&parser, &range) {
435*4882a593Smuzhiyun /* Read next ranges element */
436*4882a593Smuzhiyun
437*4882a593Smuzhiyun /* If we failed translation or got a zero-sized region
438*4882a593Smuzhiyun * (some FW try to feed us with non sensical zero sized regions
439*4882a593Smuzhiyun * such as power3 which look like some kind of attempt
440*4882a593Smuzhiyun * at exposing the VGA memory hole)
441*4882a593Smuzhiyun */
442*4882a593Smuzhiyun if (range.cpu_addr == OF_BAD_ADDR || range.size == 0)
443*4882a593Smuzhiyun continue;
444*4882a593Smuzhiyun
445*4882a593Smuzhiyun /* Act based on address space type */
446*4882a593Smuzhiyun res = NULL;
447*4882a593Smuzhiyun switch (range.flags & IORESOURCE_TYPE_BITS) {
448*4882a593Smuzhiyun case IORESOURCE_IO:
449*4882a593Smuzhiyun pr_info(" IO 0x%016llx..0x%016llx -> 0x%016llx\n",
450*4882a593Smuzhiyun range.cpu_addr, range.cpu_addr + range.size - 1,
451*4882a593Smuzhiyun range.pci_addr);
452*4882a593Smuzhiyun
453*4882a593Smuzhiyun /* We support only one IO range */
454*4882a593Smuzhiyun if (hose->pci_io_size) {
455*4882a593Smuzhiyun pr_info(" \\--> Skipped (too many) !\n");
456*4882a593Smuzhiyun continue;
457*4882a593Smuzhiyun }
458*4882a593Smuzhiyun /* On 32 bits, limit I/O space to 16MB */
459*4882a593Smuzhiyun if (range.size > 0x01000000)
460*4882a593Smuzhiyun range.size = 0x01000000;
461*4882a593Smuzhiyun
462*4882a593Smuzhiyun /* 32 bits needs to map IOs here */
463*4882a593Smuzhiyun hose->io_base_virt = ioremap(range.cpu_addr,
464*4882a593Smuzhiyun range.size);
465*4882a593Smuzhiyun
466*4882a593Smuzhiyun /* Expect trouble if pci_addr is not 0 */
467*4882a593Smuzhiyun if (primary)
468*4882a593Smuzhiyun isa_io_base =
469*4882a593Smuzhiyun (unsigned long)hose->io_base_virt;
470*4882a593Smuzhiyun /* pci_io_size and io_base_phys always represent IO
471*4882a593Smuzhiyun * space starting at 0 so we factor in pci_addr
472*4882a593Smuzhiyun */
473*4882a593Smuzhiyun hose->pci_io_size = range.pci_addr + range.size;
474*4882a593Smuzhiyun hose->io_base_phys = range.cpu_addr - range.pci_addr;
475*4882a593Smuzhiyun
476*4882a593Smuzhiyun /* Build resource */
477*4882a593Smuzhiyun res = &hose->io_resource;
478*4882a593Smuzhiyun range.cpu_addr = range.pci_addr;
479*4882a593Smuzhiyun
480*4882a593Smuzhiyun break;
481*4882a593Smuzhiyun case IORESOURCE_MEM:
482*4882a593Smuzhiyun pr_info(" MEM 0x%016llx..0x%016llx -> 0x%016llx %s\n",
483*4882a593Smuzhiyun range.cpu_addr, range.cpu_addr + range.size - 1,
484*4882a593Smuzhiyun range.pci_addr,
485*4882a593Smuzhiyun (range.flags & IORESOURCE_PREFETCH) ?
486*4882a593Smuzhiyun "Prefetch" : "");
487*4882a593Smuzhiyun
488*4882a593Smuzhiyun /* We support only 3 memory ranges */
489*4882a593Smuzhiyun if (memno >= 3) {
490*4882a593Smuzhiyun pr_info(" \\--> Skipped (too many) !\n");
491*4882a593Smuzhiyun continue;
492*4882a593Smuzhiyun }
493*4882a593Smuzhiyun /* Handles ISA memory hole space here */
494*4882a593Smuzhiyun if (range.pci_addr == 0) {
495*4882a593Smuzhiyun isa_mb = range.cpu_addr;
496*4882a593Smuzhiyun isa_hole = memno;
497*4882a593Smuzhiyun if (primary || isa_mem_base == 0)
498*4882a593Smuzhiyun isa_mem_base = range.cpu_addr;
499*4882a593Smuzhiyun hose->isa_mem_phys = range.cpu_addr;
500*4882a593Smuzhiyun hose->isa_mem_size = range.size;
501*4882a593Smuzhiyun }
502*4882a593Smuzhiyun
503*4882a593Smuzhiyun /* We get the PCI/Mem offset from the first range or
504*4882a593Smuzhiyun * the, current one if the offset came from an ISA
505*4882a593Smuzhiyun * hole. If they don't match, bugger.
506*4882a593Smuzhiyun */
507*4882a593Smuzhiyun if (memno == 0 ||
508*4882a593Smuzhiyun (isa_hole >= 0 && range.pci_addr != 0 &&
509*4882a593Smuzhiyun hose->pci_mem_offset == isa_mb))
510*4882a593Smuzhiyun hose->pci_mem_offset = range.cpu_addr -
511*4882a593Smuzhiyun range.pci_addr;
512*4882a593Smuzhiyun else if (range.pci_addr != 0 &&
513*4882a593Smuzhiyun hose->pci_mem_offset != range.cpu_addr -
514*4882a593Smuzhiyun range.pci_addr) {
515*4882a593Smuzhiyun pr_info(" \\--> Skipped (offset mismatch) !\n");
516*4882a593Smuzhiyun continue;
517*4882a593Smuzhiyun }
518*4882a593Smuzhiyun
519*4882a593Smuzhiyun /* Build resource */
520*4882a593Smuzhiyun res = &hose->mem_resources[memno++];
521*4882a593Smuzhiyun break;
522*4882a593Smuzhiyun }
523*4882a593Smuzhiyun if (res != NULL) {
524*4882a593Smuzhiyun res->name = dev->full_name;
525*4882a593Smuzhiyun res->flags = range.flags;
526*4882a593Smuzhiyun res->start = range.cpu_addr;
527*4882a593Smuzhiyun res->end = range.cpu_addr + range.size - 1;
528*4882a593Smuzhiyun res->parent = res->child = res->sibling = NULL;
529*4882a593Smuzhiyun }
530*4882a593Smuzhiyun }
531*4882a593Smuzhiyun
532*4882a593Smuzhiyun /* If there's an ISA hole and the pci_mem_offset is -not- matching
533*4882a593Smuzhiyun * the ISA hole offset, then we need to remove the ISA hole from
534*4882a593Smuzhiyun * the resource list for that brige
535*4882a593Smuzhiyun */
536*4882a593Smuzhiyun if (isa_hole >= 0 && hose->pci_mem_offset != isa_mb) {
537*4882a593Smuzhiyun unsigned int next = isa_hole + 1;
538*4882a593Smuzhiyun pr_info(" Removing ISA hole at 0x%016llx\n", isa_mb);
539*4882a593Smuzhiyun if (next < memno)
540*4882a593Smuzhiyun memmove(&hose->mem_resources[isa_hole],
541*4882a593Smuzhiyun &hose->mem_resources[next],
542*4882a593Smuzhiyun sizeof(struct resource) * (memno - next));
543*4882a593Smuzhiyun hose->mem_resources[--memno].flags = 0;
544*4882a593Smuzhiyun }
545*4882a593Smuzhiyun }
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun /* Display the domain number in /proc */
pci_proc_domain(struct pci_bus * bus)548*4882a593Smuzhiyun int pci_proc_domain(struct pci_bus *bus)
549*4882a593Smuzhiyun {
550*4882a593Smuzhiyun return pci_domain_nr(bus);
551*4882a593Smuzhiyun }
552*4882a593Smuzhiyun
553*4882a593Smuzhiyun /* This header fixup will do the resource fixup for all devices as they are
554*4882a593Smuzhiyun * probed, but not for bridge ranges
555*4882a593Smuzhiyun */
pcibios_fixup_resources(struct pci_dev * dev)556*4882a593Smuzhiyun static void pcibios_fixup_resources(struct pci_dev *dev)
557*4882a593Smuzhiyun {
558*4882a593Smuzhiyun struct pci_controller *hose = pci_bus_to_host(dev->bus);
559*4882a593Smuzhiyun int i;
560*4882a593Smuzhiyun
561*4882a593Smuzhiyun if (!hose) {
562*4882a593Smuzhiyun pr_err("No host bridge for PCI dev %s !\n",
563*4882a593Smuzhiyun pci_name(dev));
564*4882a593Smuzhiyun return;
565*4882a593Smuzhiyun }
566*4882a593Smuzhiyun for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
567*4882a593Smuzhiyun struct resource *res = dev->resource + i;
568*4882a593Smuzhiyun if (!res->flags)
569*4882a593Smuzhiyun continue;
570*4882a593Smuzhiyun if (res->start == 0) {
571*4882a593Smuzhiyun pr_debug("PCI:%s Resource %d %016llx-%016llx [%x]",
572*4882a593Smuzhiyun pci_name(dev), i,
573*4882a593Smuzhiyun (unsigned long long)res->start,
574*4882a593Smuzhiyun (unsigned long long)res->end,
575*4882a593Smuzhiyun (unsigned int)res->flags);
576*4882a593Smuzhiyun pr_debug("is unassigned\n");
577*4882a593Smuzhiyun res->end -= res->start;
578*4882a593Smuzhiyun res->start = 0;
579*4882a593Smuzhiyun res->flags |= IORESOURCE_UNSET;
580*4882a593Smuzhiyun continue;
581*4882a593Smuzhiyun }
582*4882a593Smuzhiyun
583*4882a593Smuzhiyun pr_debug("PCI:%s Resource %d %016llx-%016llx [%x]\n",
584*4882a593Smuzhiyun pci_name(dev), i,
585*4882a593Smuzhiyun (unsigned long long)res->start,
586*4882a593Smuzhiyun (unsigned long long)res->end,
587*4882a593Smuzhiyun (unsigned int)res->flags);
588*4882a593Smuzhiyun }
589*4882a593Smuzhiyun }
590*4882a593Smuzhiyun DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pcibios_fixup_resources);
591*4882a593Smuzhiyun
pcibios_add_device(struct pci_dev * dev)592*4882a593Smuzhiyun int pcibios_add_device(struct pci_dev *dev)
593*4882a593Smuzhiyun {
594*4882a593Smuzhiyun dev->irq = of_irq_parse_and_map_pci(dev, 0, 0);
595*4882a593Smuzhiyun
596*4882a593Smuzhiyun return 0;
597*4882a593Smuzhiyun }
598*4882a593Smuzhiyun EXPORT_SYMBOL(pcibios_add_device);
599*4882a593Smuzhiyun
600*4882a593Smuzhiyun /*
601*4882a593Smuzhiyun * Reparent resource children of pr that conflict with res
602*4882a593Smuzhiyun * under res, and make res replace those children.
603*4882a593Smuzhiyun */
reparent_resources(struct resource * parent,struct resource * res)604*4882a593Smuzhiyun static int __init reparent_resources(struct resource *parent,
605*4882a593Smuzhiyun struct resource *res)
606*4882a593Smuzhiyun {
607*4882a593Smuzhiyun struct resource *p, **pp;
608*4882a593Smuzhiyun struct resource **firstpp = NULL;
609*4882a593Smuzhiyun
610*4882a593Smuzhiyun for (pp = &parent->child; (p = *pp) != NULL; pp = &p->sibling) {
611*4882a593Smuzhiyun if (p->end < res->start)
612*4882a593Smuzhiyun continue;
613*4882a593Smuzhiyun if (res->end < p->start)
614*4882a593Smuzhiyun break;
615*4882a593Smuzhiyun if (p->start < res->start || p->end > res->end)
616*4882a593Smuzhiyun return -1; /* not completely contained */
617*4882a593Smuzhiyun if (firstpp == NULL)
618*4882a593Smuzhiyun firstpp = pp;
619*4882a593Smuzhiyun }
620*4882a593Smuzhiyun if (firstpp == NULL)
621*4882a593Smuzhiyun return -1; /* didn't find any conflicting entries? */
622*4882a593Smuzhiyun res->parent = parent;
623*4882a593Smuzhiyun res->child = *firstpp;
624*4882a593Smuzhiyun res->sibling = *pp;
625*4882a593Smuzhiyun *firstpp = res;
626*4882a593Smuzhiyun *pp = NULL;
627*4882a593Smuzhiyun for (p = res->child; p != NULL; p = p->sibling) {
628*4882a593Smuzhiyun p->parent = res;
629*4882a593Smuzhiyun pr_debug("PCI: Reparented %s [%llx..%llx] under %s\n",
630*4882a593Smuzhiyun p->name,
631*4882a593Smuzhiyun (unsigned long long)p->start,
632*4882a593Smuzhiyun (unsigned long long)p->end, res->name);
633*4882a593Smuzhiyun }
634*4882a593Smuzhiyun return 0;
635*4882a593Smuzhiyun }
636*4882a593Smuzhiyun
637*4882a593Smuzhiyun /*
638*4882a593Smuzhiyun * Handle resources of PCI devices. If the world were perfect, we could
639*4882a593Smuzhiyun * just allocate all the resource regions and do nothing more. It isn't.
640*4882a593Smuzhiyun * On the other hand, we cannot just re-allocate all devices, as it would
641*4882a593Smuzhiyun * require us to know lots of host bridge internals. So we attempt to
642*4882a593Smuzhiyun * keep as much of the original configuration as possible, but tweak it
643*4882a593Smuzhiyun * when it's found to be wrong.
644*4882a593Smuzhiyun *
645*4882a593Smuzhiyun * Known BIOS problems we have to work around:
646*4882a593Smuzhiyun * - I/O or memory regions not configured
647*4882a593Smuzhiyun * - regions configured, but not enabled in the command register
648*4882a593Smuzhiyun * - bogus I/O addresses above 64K used
649*4882a593Smuzhiyun * - expansion ROMs left enabled (this may sound harmless, but given
650*4882a593Smuzhiyun * the fact the PCI specs explicitly allow address decoders to be
651*4882a593Smuzhiyun * shared between expansion ROMs and other resource regions, it's
652*4882a593Smuzhiyun * at least dangerous)
653*4882a593Smuzhiyun *
654*4882a593Smuzhiyun * Our solution:
655*4882a593Smuzhiyun * (1) Allocate resources for all buses behind PCI-to-PCI bridges.
656*4882a593Smuzhiyun * This gives us fixed barriers on where we can allocate.
657*4882a593Smuzhiyun * (2) Allocate resources for all enabled devices. If there is
658*4882a593Smuzhiyun * a collision, just mark the resource as unallocated. Also
659*4882a593Smuzhiyun * disable expansion ROMs during this step.
660*4882a593Smuzhiyun * (3) Try to allocate resources for disabled devices. If the
661*4882a593Smuzhiyun * resources were assigned correctly, everything goes well,
662*4882a593Smuzhiyun * if they weren't, they won't disturb allocation of other
663*4882a593Smuzhiyun * resources.
664*4882a593Smuzhiyun * (4) Assign new addresses to resources which were either
665*4882a593Smuzhiyun * not configured at all or misconfigured. If explicitly
666*4882a593Smuzhiyun * requested by the user, configure expansion ROM address
667*4882a593Smuzhiyun * as well.
668*4882a593Smuzhiyun */
669*4882a593Smuzhiyun
pcibios_allocate_bus_resources(struct pci_bus * bus)670*4882a593Smuzhiyun static void pcibios_allocate_bus_resources(struct pci_bus *bus)
671*4882a593Smuzhiyun {
672*4882a593Smuzhiyun struct pci_bus *b;
673*4882a593Smuzhiyun int i;
674*4882a593Smuzhiyun struct resource *res, *pr;
675*4882a593Smuzhiyun
676*4882a593Smuzhiyun pr_debug("PCI: Allocating bus resources for %04x:%02x...\n",
677*4882a593Smuzhiyun pci_domain_nr(bus), bus->number);
678*4882a593Smuzhiyun
679*4882a593Smuzhiyun pci_bus_for_each_resource(bus, res, i) {
680*4882a593Smuzhiyun if (!res || !res->flags
681*4882a593Smuzhiyun || res->start > res->end || res->parent)
682*4882a593Smuzhiyun continue;
683*4882a593Smuzhiyun if (bus->parent == NULL)
684*4882a593Smuzhiyun pr = (res->flags & IORESOURCE_IO) ?
685*4882a593Smuzhiyun &ioport_resource : &iomem_resource;
686*4882a593Smuzhiyun else {
687*4882a593Smuzhiyun /* Don't bother with non-root busses when
688*4882a593Smuzhiyun * re-assigning all resources. We clear the
689*4882a593Smuzhiyun * resource flags as if they were colliding
690*4882a593Smuzhiyun * and as such ensure proper re-allocation
691*4882a593Smuzhiyun * later.
692*4882a593Smuzhiyun */
693*4882a593Smuzhiyun pr = pci_find_parent_resource(bus->self, res);
694*4882a593Smuzhiyun if (pr == res) {
695*4882a593Smuzhiyun /* this happens when the generic PCI
696*4882a593Smuzhiyun * code (wrongly) decides that this
697*4882a593Smuzhiyun * bridge is transparent -- paulus
698*4882a593Smuzhiyun */
699*4882a593Smuzhiyun continue;
700*4882a593Smuzhiyun }
701*4882a593Smuzhiyun }
702*4882a593Smuzhiyun
703*4882a593Smuzhiyun pr_debug("PCI: %s (bus %d) bridge rsrc %d: %016llx-%016llx ",
704*4882a593Smuzhiyun bus->self ? pci_name(bus->self) : "PHB",
705*4882a593Smuzhiyun bus->number, i,
706*4882a593Smuzhiyun (unsigned long long)res->start,
707*4882a593Smuzhiyun (unsigned long long)res->end);
708*4882a593Smuzhiyun pr_debug("[0x%x], parent %p (%s)\n",
709*4882a593Smuzhiyun (unsigned int)res->flags,
710*4882a593Smuzhiyun pr, (pr && pr->name) ? pr->name : "nil");
711*4882a593Smuzhiyun
712*4882a593Smuzhiyun if (pr && !(pr->flags & IORESOURCE_UNSET)) {
713*4882a593Smuzhiyun struct pci_dev *dev = bus->self;
714*4882a593Smuzhiyun
715*4882a593Smuzhiyun if (request_resource(pr, res) == 0)
716*4882a593Smuzhiyun continue;
717*4882a593Smuzhiyun /*
718*4882a593Smuzhiyun * Must be a conflict with an existing entry.
719*4882a593Smuzhiyun * Move that entry (or entries) under the
720*4882a593Smuzhiyun * bridge resource and try again.
721*4882a593Smuzhiyun */
722*4882a593Smuzhiyun if (reparent_resources(pr, res) == 0)
723*4882a593Smuzhiyun continue;
724*4882a593Smuzhiyun
725*4882a593Smuzhiyun if (dev && i < PCI_BRIDGE_RESOURCE_NUM &&
726*4882a593Smuzhiyun pci_claim_bridge_resource(dev,
727*4882a593Smuzhiyun i + PCI_BRIDGE_RESOURCES) == 0)
728*4882a593Smuzhiyun continue;
729*4882a593Smuzhiyun
730*4882a593Smuzhiyun }
731*4882a593Smuzhiyun pr_warn("PCI: Cannot allocate resource region ");
732*4882a593Smuzhiyun pr_cont("%d of PCI bridge %d, will remap\n", i, bus->number);
733*4882a593Smuzhiyun res->start = res->end = 0;
734*4882a593Smuzhiyun res->flags = 0;
735*4882a593Smuzhiyun }
736*4882a593Smuzhiyun
737*4882a593Smuzhiyun list_for_each_entry(b, &bus->children, node)
738*4882a593Smuzhiyun pcibios_allocate_bus_resources(b);
739*4882a593Smuzhiyun }
740*4882a593Smuzhiyun
alloc_resource(struct pci_dev * dev,int idx)741*4882a593Smuzhiyun static inline void alloc_resource(struct pci_dev *dev, int idx)
742*4882a593Smuzhiyun {
743*4882a593Smuzhiyun struct resource *pr, *r = &dev->resource[idx];
744*4882a593Smuzhiyun
745*4882a593Smuzhiyun pr_debug("PCI: Allocating %s: Resource %d: %016llx..%016llx [%x]\n",
746*4882a593Smuzhiyun pci_name(dev), idx,
747*4882a593Smuzhiyun (unsigned long long)r->start,
748*4882a593Smuzhiyun (unsigned long long)r->end,
749*4882a593Smuzhiyun (unsigned int)r->flags);
750*4882a593Smuzhiyun
751*4882a593Smuzhiyun pr = pci_find_parent_resource(dev, r);
752*4882a593Smuzhiyun if (!pr || (pr->flags & IORESOURCE_UNSET) ||
753*4882a593Smuzhiyun request_resource(pr, r) < 0) {
754*4882a593Smuzhiyun pr_warn("PCI: Cannot allocate resource region %d ", idx);
755*4882a593Smuzhiyun pr_cont("of device %s, will remap\n", pci_name(dev));
756*4882a593Smuzhiyun if (pr)
757*4882a593Smuzhiyun pr_debug("PCI: parent is %p: %016llx-%016llx [%x]\n",
758*4882a593Smuzhiyun pr,
759*4882a593Smuzhiyun (unsigned long long)pr->start,
760*4882a593Smuzhiyun (unsigned long long)pr->end,
761*4882a593Smuzhiyun (unsigned int)pr->flags);
762*4882a593Smuzhiyun /* We'll assign a new address later */
763*4882a593Smuzhiyun r->flags |= IORESOURCE_UNSET;
764*4882a593Smuzhiyun r->end -= r->start;
765*4882a593Smuzhiyun r->start = 0;
766*4882a593Smuzhiyun }
767*4882a593Smuzhiyun }
768*4882a593Smuzhiyun
pcibios_allocate_resources(int pass)769*4882a593Smuzhiyun static void __init pcibios_allocate_resources(int pass)
770*4882a593Smuzhiyun {
771*4882a593Smuzhiyun struct pci_dev *dev = NULL;
772*4882a593Smuzhiyun int idx, disabled;
773*4882a593Smuzhiyun u16 command;
774*4882a593Smuzhiyun struct resource *r;
775*4882a593Smuzhiyun
776*4882a593Smuzhiyun for_each_pci_dev(dev) {
777*4882a593Smuzhiyun pci_read_config_word(dev, PCI_COMMAND, &command);
778*4882a593Smuzhiyun for (idx = 0; idx <= PCI_ROM_RESOURCE; idx++) {
779*4882a593Smuzhiyun r = &dev->resource[idx];
780*4882a593Smuzhiyun if (r->parent) /* Already allocated */
781*4882a593Smuzhiyun continue;
782*4882a593Smuzhiyun if (!r->flags || (r->flags & IORESOURCE_UNSET))
783*4882a593Smuzhiyun continue; /* Not assigned at all */
784*4882a593Smuzhiyun /* We only allocate ROMs on pass 1 just in case they
785*4882a593Smuzhiyun * have been screwed up by firmware
786*4882a593Smuzhiyun */
787*4882a593Smuzhiyun if (idx == PCI_ROM_RESOURCE)
788*4882a593Smuzhiyun disabled = 1;
789*4882a593Smuzhiyun if (r->flags & IORESOURCE_IO)
790*4882a593Smuzhiyun disabled = !(command & PCI_COMMAND_IO);
791*4882a593Smuzhiyun else
792*4882a593Smuzhiyun disabled = !(command & PCI_COMMAND_MEMORY);
793*4882a593Smuzhiyun if (pass == disabled)
794*4882a593Smuzhiyun alloc_resource(dev, idx);
795*4882a593Smuzhiyun }
796*4882a593Smuzhiyun if (pass)
797*4882a593Smuzhiyun continue;
798*4882a593Smuzhiyun r = &dev->resource[PCI_ROM_RESOURCE];
799*4882a593Smuzhiyun if (r->flags) {
800*4882a593Smuzhiyun /* Turn the ROM off, leave the resource region,
801*4882a593Smuzhiyun * but keep it unregistered.
802*4882a593Smuzhiyun */
803*4882a593Smuzhiyun u32 reg;
804*4882a593Smuzhiyun pci_read_config_dword(dev, dev->rom_base_reg, ®);
805*4882a593Smuzhiyun if (reg & PCI_ROM_ADDRESS_ENABLE) {
806*4882a593Smuzhiyun pr_debug("PCI: Switching off ROM of %s\n",
807*4882a593Smuzhiyun pci_name(dev));
808*4882a593Smuzhiyun r->flags &= ~IORESOURCE_ROM_ENABLE;
809*4882a593Smuzhiyun pci_write_config_dword(dev, dev->rom_base_reg,
810*4882a593Smuzhiyun reg & ~PCI_ROM_ADDRESS_ENABLE);
811*4882a593Smuzhiyun }
812*4882a593Smuzhiyun }
813*4882a593Smuzhiyun }
814*4882a593Smuzhiyun }
815*4882a593Smuzhiyun
pcibios_reserve_legacy_regions(struct pci_bus * bus)816*4882a593Smuzhiyun static void __init pcibios_reserve_legacy_regions(struct pci_bus *bus)
817*4882a593Smuzhiyun {
818*4882a593Smuzhiyun struct pci_controller *hose = pci_bus_to_host(bus);
819*4882a593Smuzhiyun resource_size_t offset;
820*4882a593Smuzhiyun struct resource *res, *pres;
821*4882a593Smuzhiyun int i;
822*4882a593Smuzhiyun
823*4882a593Smuzhiyun pr_debug("Reserving legacy ranges for domain %04x\n",
824*4882a593Smuzhiyun pci_domain_nr(bus));
825*4882a593Smuzhiyun
826*4882a593Smuzhiyun /* Check for IO */
827*4882a593Smuzhiyun if (!(hose->io_resource.flags & IORESOURCE_IO))
828*4882a593Smuzhiyun goto no_io;
829*4882a593Smuzhiyun offset = (unsigned long)hose->io_base_virt - _IO_BASE;
830*4882a593Smuzhiyun res = kzalloc(sizeof(struct resource), GFP_KERNEL);
831*4882a593Smuzhiyun BUG_ON(res == NULL);
832*4882a593Smuzhiyun res->name = "Legacy IO";
833*4882a593Smuzhiyun res->flags = IORESOURCE_IO;
834*4882a593Smuzhiyun res->start = offset;
835*4882a593Smuzhiyun res->end = (offset + 0xfff) & 0xfffffffful;
836*4882a593Smuzhiyun pr_debug("Candidate legacy IO: %pR\n", res);
837*4882a593Smuzhiyun if (request_resource(&hose->io_resource, res)) {
838*4882a593Smuzhiyun pr_debug("PCI %04x:%02x Cannot reserve Legacy IO %pR\n",
839*4882a593Smuzhiyun pci_domain_nr(bus), bus->number, res);
840*4882a593Smuzhiyun kfree(res);
841*4882a593Smuzhiyun }
842*4882a593Smuzhiyun
843*4882a593Smuzhiyun no_io:
844*4882a593Smuzhiyun /* Check for memory */
845*4882a593Smuzhiyun offset = hose->pci_mem_offset;
846*4882a593Smuzhiyun pr_debug("hose mem offset: %016llx\n", (unsigned long long)offset);
847*4882a593Smuzhiyun for (i = 0; i < 3; i++) {
848*4882a593Smuzhiyun pres = &hose->mem_resources[i];
849*4882a593Smuzhiyun if (!(pres->flags & IORESOURCE_MEM))
850*4882a593Smuzhiyun continue;
851*4882a593Smuzhiyun pr_debug("hose mem res: %pR\n", pres);
852*4882a593Smuzhiyun if ((pres->start - offset) <= 0xa0000 &&
853*4882a593Smuzhiyun (pres->end - offset) >= 0xbffff)
854*4882a593Smuzhiyun break;
855*4882a593Smuzhiyun }
856*4882a593Smuzhiyun if (i >= 3)
857*4882a593Smuzhiyun return;
858*4882a593Smuzhiyun res = kzalloc(sizeof(struct resource), GFP_KERNEL);
859*4882a593Smuzhiyun BUG_ON(res == NULL);
860*4882a593Smuzhiyun res->name = "Legacy VGA memory";
861*4882a593Smuzhiyun res->flags = IORESOURCE_MEM;
862*4882a593Smuzhiyun res->start = 0xa0000 + offset;
863*4882a593Smuzhiyun res->end = 0xbffff + offset;
864*4882a593Smuzhiyun pr_debug("Candidate VGA memory: %pR\n", res);
865*4882a593Smuzhiyun if (request_resource(pres, res)) {
866*4882a593Smuzhiyun pr_debug("PCI %04x:%02x Cannot reserve VGA memory %pR\n",
867*4882a593Smuzhiyun pci_domain_nr(bus), bus->number, res);
868*4882a593Smuzhiyun kfree(res);
869*4882a593Smuzhiyun }
870*4882a593Smuzhiyun }
871*4882a593Smuzhiyun
pcibios_resource_survey(void)872*4882a593Smuzhiyun void __init pcibios_resource_survey(void)
873*4882a593Smuzhiyun {
874*4882a593Smuzhiyun struct pci_bus *b;
875*4882a593Smuzhiyun
876*4882a593Smuzhiyun /* Allocate and assign resources. If we re-assign everything, then
877*4882a593Smuzhiyun * we skip the allocate phase
878*4882a593Smuzhiyun */
879*4882a593Smuzhiyun list_for_each_entry(b, &pci_root_buses, node)
880*4882a593Smuzhiyun pcibios_allocate_bus_resources(b);
881*4882a593Smuzhiyun
882*4882a593Smuzhiyun pcibios_allocate_resources(0);
883*4882a593Smuzhiyun pcibios_allocate_resources(1);
884*4882a593Smuzhiyun
885*4882a593Smuzhiyun /* Before we start assigning unassigned resource, we try to reserve
886*4882a593Smuzhiyun * the low IO area and the VGA memory area if they intersect the
887*4882a593Smuzhiyun * bus available resources to avoid allocating things on top of them
888*4882a593Smuzhiyun */
889*4882a593Smuzhiyun list_for_each_entry(b, &pci_root_buses, node)
890*4882a593Smuzhiyun pcibios_reserve_legacy_regions(b);
891*4882a593Smuzhiyun
892*4882a593Smuzhiyun /* Now proceed to assigning things that were left unassigned */
893*4882a593Smuzhiyun pr_debug("PCI: Assigning unassigned resources...\n");
894*4882a593Smuzhiyun pci_assign_unassigned_resources();
895*4882a593Smuzhiyun }
896*4882a593Smuzhiyun
pcibios_setup_phb_resources(struct pci_controller * hose,struct list_head * resources)897*4882a593Smuzhiyun static void pcibios_setup_phb_resources(struct pci_controller *hose,
898*4882a593Smuzhiyun struct list_head *resources)
899*4882a593Smuzhiyun {
900*4882a593Smuzhiyun unsigned long io_offset;
901*4882a593Smuzhiyun struct resource *res;
902*4882a593Smuzhiyun int i;
903*4882a593Smuzhiyun
904*4882a593Smuzhiyun /* Hookup PHB IO resource */
905*4882a593Smuzhiyun res = &hose->io_resource;
906*4882a593Smuzhiyun
907*4882a593Smuzhiyun /* Fixup IO space offset */
908*4882a593Smuzhiyun io_offset = (unsigned long)hose->io_base_virt - isa_io_base;
909*4882a593Smuzhiyun res->start = (res->start + io_offset) & 0xffffffffu;
910*4882a593Smuzhiyun res->end = (res->end + io_offset) & 0xffffffffu;
911*4882a593Smuzhiyun
912*4882a593Smuzhiyun if (!res->flags) {
913*4882a593Smuzhiyun pr_warn("PCI: I/O resource not set for host ");
914*4882a593Smuzhiyun pr_cont("bridge %pOF (domain %d)\n",
915*4882a593Smuzhiyun hose->dn, hose->global_number);
916*4882a593Smuzhiyun /* Workaround for lack of IO resource only on 32-bit */
917*4882a593Smuzhiyun res->start = (unsigned long)hose->io_base_virt - isa_io_base;
918*4882a593Smuzhiyun res->end = res->start + IO_SPACE_LIMIT;
919*4882a593Smuzhiyun res->flags = IORESOURCE_IO;
920*4882a593Smuzhiyun }
921*4882a593Smuzhiyun pci_add_resource_offset(resources, res,
922*4882a593Smuzhiyun (__force resource_size_t)(hose->io_base_virt - _IO_BASE));
923*4882a593Smuzhiyun
924*4882a593Smuzhiyun pr_debug("PCI: PHB IO resource = %016llx-%016llx [%lx]\n",
925*4882a593Smuzhiyun (unsigned long long)res->start,
926*4882a593Smuzhiyun (unsigned long long)res->end,
927*4882a593Smuzhiyun (unsigned long)res->flags);
928*4882a593Smuzhiyun
929*4882a593Smuzhiyun /* Hookup PHB Memory resources */
930*4882a593Smuzhiyun for (i = 0; i < 3; ++i) {
931*4882a593Smuzhiyun res = &hose->mem_resources[i];
932*4882a593Smuzhiyun if (!res->flags) {
933*4882a593Smuzhiyun if (i > 0)
934*4882a593Smuzhiyun continue;
935*4882a593Smuzhiyun pr_err("PCI: Memory resource 0 not set for ");
936*4882a593Smuzhiyun pr_cont("host bridge %pOF (domain %d)\n",
937*4882a593Smuzhiyun hose->dn, hose->global_number);
938*4882a593Smuzhiyun
939*4882a593Smuzhiyun /* Workaround for lack of MEM resource only on 32-bit */
940*4882a593Smuzhiyun res->start = hose->pci_mem_offset;
941*4882a593Smuzhiyun res->end = (resource_size_t)-1LL;
942*4882a593Smuzhiyun res->flags = IORESOURCE_MEM;
943*4882a593Smuzhiyun
944*4882a593Smuzhiyun }
945*4882a593Smuzhiyun pci_add_resource_offset(resources, res, hose->pci_mem_offset);
946*4882a593Smuzhiyun
947*4882a593Smuzhiyun pr_debug("PCI: PHB MEM resource %d = %016llx-%016llx [%lx]\n",
948*4882a593Smuzhiyun i, (unsigned long long)res->start,
949*4882a593Smuzhiyun (unsigned long long)res->end,
950*4882a593Smuzhiyun (unsigned long)res->flags);
951*4882a593Smuzhiyun }
952*4882a593Smuzhiyun
953*4882a593Smuzhiyun pr_debug("PCI: PHB MEM offset = %016llx\n",
954*4882a593Smuzhiyun (unsigned long long)hose->pci_mem_offset);
955*4882a593Smuzhiyun pr_debug("PCI: PHB IO offset = %08lx\n",
956*4882a593Smuzhiyun (unsigned long)hose->io_base_virt - _IO_BASE);
957*4882a593Smuzhiyun }
958*4882a593Smuzhiyun
pcibios_scan_phb(struct pci_controller * hose)959*4882a593Smuzhiyun static void pcibios_scan_phb(struct pci_controller *hose)
960*4882a593Smuzhiyun {
961*4882a593Smuzhiyun LIST_HEAD(resources);
962*4882a593Smuzhiyun struct pci_bus *bus;
963*4882a593Smuzhiyun struct device_node *node = hose->dn;
964*4882a593Smuzhiyun
965*4882a593Smuzhiyun pr_debug("PCI: Scanning PHB %pOF\n", node);
966*4882a593Smuzhiyun
967*4882a593Smuzhiyun pcibios_setup_phb_resources(hose, &resources);
968*4882a593Smuzhiyun
969*4882a593Smuzhiyun bus = pci_scan_root_bus(hose->parent, hose->first_busno,
970*4882a593Smuzhiyun hose->ops, hose, &resources);
971*4882a593Smuzhiyun if (bus == NULL) {
972*4882a593Smuzhiyun pr_err("Failed to create bus for PCI domain %04x\n",
973*4882a593Smuzhiyun hose->global_number);
974*4882a593Smuzhiyun pci_free_resource_list(&resources);
975*4882a593Smuzhiyun return;
976*4882a593Smuzhiyun }
977*4882a593Smuzhiyun bus->busn_res.start = hose->first_busno;
978*4882a593Smuzhiyun hose->bus = bus;
979*4882a593Smuzhiyun
980*4882a593Smuzhiyun hose->last_busno = bus->busn_res.end;
981*4882a593Smuzhiyun }
982*4882a593Smuzhiyun
pcibios_init(void)983*4882a593Smuzhiyun static int __init pcibios_init(void)
984*4882a593Smuzhiyun {
985*4882a593Smuzhiyun struct pci_controller *hose, *tmp;
986*4882a593Smuzhiyun int next_busno = 0;
987*4882a593Smuzhiyun
988*4882a593Smuzhiyun pr_info("PCI: Probing PCI hardware\n");
989*4882a593Smuzhiyun
990*4882a593Smuzhiyun /* Scan all of the recorded PCI controllers. */
991*4882a593Smuzhiyun list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
992*4882a593Smuzhiyun hose->last_busno = 0xff;
993*4882a593Smuzhiyun pcibios_scan_phb(hose);
994*4882a593Smuzhiyun if (next_busno <= hose->last_busno)
995*4882a593Smuzhiyun next_busno = hose->last_busno + 1;
996*4882a593Smuzhiyun }
997*4882a593Smuzhiyun pci_bus_count = next_busno;
998*4882a593Smuzhiyun
999*4882a593Smuzhiyun /* Call common code to handle resource allocation */
1000*4882a593Smuzhiyun pcibios_resource_survey();
1001*4882a593Smuzhiyun list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
1002*4882a593Smuzhiyun if (hose->bus)
1003*4882a593Smuzhiyun pci_bus_add_devices(hose->bus);
1004*4882a593Smuzhiyun }
1005*4882a593Smuzhiyun
1006*4882a593Smuzhiyun return 0;
1007*4882a593Smuzhiyun }
1008*4882a593Smuzhiyun
1009*4882a593Smuzhiyun subsys_initcall(pcibios_init);
1010*4882a593Smuzhiyun
pci_bus_to_hose(int bus)1011*4882a593Smuzhiyun static struct pci_controller *pci_bus_to_hose(int bus)
1012*4882a593Smuzhiyun {
1013*4882a593Smuzhiyun struct pci_controller *hose, *tmp;
1014*4882a593Smuzhiyun
1015*4882a593Smuzhiyun list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
1016*4882a593Smuzhiyun if (bus >= hose->first_busno && bus <= hose->last_busno)
1017*4882a593Smuzhiyun return hose;
1018*4882a593Smuzhiyun return NULL;
1019*4882a593Smuzhiyun }
1020*4882a593Smuzhiyun
1021*4882a593Smuzhiyun /* Provide information on locations of various I/O regions in physical
1022*4882a593Smuzhiyun * memory. Do this on a per-card basis so that we choose the right
1023*4882a593Smuzhiyun * root bridge.
1024*4882a593Smuzhiyun * Note that the returned IO or memory base is a physical address
1025*4882a593Smuzhiyun */
1026*4882a593Smuzhiyun
sys_pciconfig_iobase(long which,unsigned long bus,unsigned long devfn)1027*4882a593Smuzhiyun long sys_pciconfig_iobase(long which, unsigned long bus, unsigned long devfn)
1028*4882a593Smuzhiyun {
1029*4882a593Smuzhiyun struct pci_controller *hose;
1030*4882a593Smuzhiyun long result = -EOPNOTSUPP;
1031*4882a593Smuzhiyun
1032*4882a593Smuzhiyun hose = pci_bus_to_hose(bus);
1033*4882a593Smuzhiyun if (!hose)
1034*4882a593Smuzhiyun return -ENODEV;
1035*4882a593Smuzhiyun
1036*4882a593Smuzhiyun switch (which) {
1037*4882a593Smuzhiyun case IOBASE_BRIDGE_NUMBER:
1038*4882a593Smuzhiyun return (long)hose->first_busno;
1039*4882a593Smuzhiyun case IOBASE_MEMORY:
1040*4882a593Smuzhiyun return (long)hose->pci_mem_offset;
1041*4882a593Smuzhiyun case IOBASE_IO:
1042*4882a593Smuzhiyun return (long)hose->io_base_phys;
1043*4882a593Smuzhiyun case IOBASE_ISA_IO:
1044*4882a593Smuzhiyun return (long)isa_io_base;
1045*4882a593Smuzhiyun case IOBASE_ISA_MEM:
1046*4882a593Smuzhiyun return (long)isa_mem_base;
1047*4882a593Smuzhiyun }
1048*4882a593Smuzhiyun
1049*4882a593Smuzhiyun return result;
1050*4882a593Smuzhiyun }
1051*4882a593Smuzhiyun
1052*4882a593Smuzhiyun /*
1053*4882a593Smuzhiyun * Null PCI config access functions, for the case when we can't
1054*4882a593Smuzhiyun * find a hose.
1055*4882a593Smuzhiyun */
1056*4882a593Smuzhiyun #define NULL_PCI_OP(rw, size, type) \
1057*4882a593Smuzhiyun static int \
1058*4882a593Smuzhiyun null_##rw##_config_##size(struct pci_dev *dev, int offset, type val) \
1059*4882a593Smuzhiyun { \
1060*4882a593Smuzhiyun return PCIBIOS_DEVICE_NOT_FOUND; \
1061*4882a593Smuzhiyun }
1062*4882a593Smuzhiyun
1063*4882a593Smuzhiyun static int
null_read_config(struct pci_bus * bus,unsigned int devfn,int offset,int len,u32 * val)1064*4882a593Smuzhiyun null_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
1065*4882a593Smuzhiyun int len, u32 *val)
1066*4882a593Smuzhiyun {
1067*4882a593Smuzhiyun return PCIBIOS_DEVICE_NOT_FOUND;
1068*4882a593Smuzhiyun }
1069*4882a593Smuzhiyun
1070*4882a593Smuzhiyun static int
null_write_config(struct pci_bus * bus,unsigned int devfn,int offset,int len,u32 val)1071*4882a593Smuzhiyun null_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
1072*4882a593Smuzhiyun int len, u32 val)
1073*4882a593Smuzhiyun {
1074*4882a593Smuzhiyun return PCIBIOS_DEVICE_NOT_FOUND;
1075*4882a593Smuzhiyun }
1076*4882a593Smuzhiyun
1077*4882a593Smuzhiyun static struct pci_ops null_pci_ops = {
1078*4882a593Smuzhiyun .read = null_read_config,
1079*4882a593Smuzhiyun .write = null_write_config,
1080*4882a593Smuzhiyun };
1081*4882a593Smuzhiyun
1082*4882a593Smuzhiyun /*
1083*4882a593Smuzhiyun * These functions are used early on before PCI scanning is done
1084*4882a593Smuzhiyun * and all of the pci_dev and pci_bus structures have been created.
1085*4882a593Smuzhiyun */
1086*4882a593Smuzhiyun static struct pci_bus *
fake_pci_bus(struct pci_controller * hose,int busnr)1087*4882a593Smuzhiyun fake_pci_bus(struct pci_controller *hose, int busnr)
1088*4882a593Smuzhiyun {
1089*4882a593Smuzhiyun static struct pci_bus bus;
1090*4882a593Smuzhiyun
1091*4882a593Smuzhiyun if (!hose)
1092*4882a593Smuzhiyun pr_err("Can't find hose for PCI bus %d!\n", busnr);
1093*4882a593Smuzhiyun
1094*4882a593Smuzhiyun bus.number = busnr;
1095*4882a593Smuzhiyun bus.sysdata = hose;
1096*4882a593Smuzhiyun bus.ops = hose ? hose->ops : &null_pci_ops;
1097*4882a593Smuzhiyun return &bus;
1098*4882a593Smuzhiyun }
1099*4882a593Smuzhiyun
1100*4882a593Smuzhiyun #define EARLY_PCI_OP(rw, size, type) \
1101*4882a593Smuzhiyun int early_##rw##_config_##size(struct pci_controller *hose, int bus, \
1102*4882a593Smuzhiyun int devfn, int offset, type value) \
1103*4882a593Smuzhiyun { \
1104*4882a593Smuzhiyun return pci_bus_##rw##_config_##size(fake_pci_bus(hose, bus), \
1105*4882a593Smuzhiyun devfn, offset, value); \
1106*4882a593Smuzhiyun }
1107*4882a593Smuzhiyun
EARLY_PCI_OP(read,byte,u8 *)1108*4882a593Smuzhiyun EARLY_PCI_OP(read, byte, u8 *)
1109*4882a593Smuzhiyun EARLY_PCI_OP(read, word, u16 *)
1110*4882a593Smuzhiyun EARLY_PCI_OP(read, dword, u32 *)
1111*4882a593Smuzhiyun EARLY_PCI_OP(write, byte, u8)
1112*4882a593Smuzhiyun EARLY_PCI_OP(write, word, u16)
1113*4882a593Smuzhiyun EARLY_PCI_OP(write, dword, u32)
1114*4882a593Smuzhiyun
1115*4882a593Smuzhiyun int early_find_capability(struct pci_controller *hose, int bus, int devfn,
1116*4882a593Smuzhiyun int cap)
1117*4882a593Smuzhiyun {
1118*4882a593Smuzhiyun return pci_bus_find_capability(fake_pci_bus(hose, bus), devfn, cap);
1119*4882a593Smuzhiyun }
1120