2007-06-27 14:17:57 +08:00
|
|
|
/*
|
|
|
|
* Contains common pci routines for ALL ppc platform
|
2007-06-29 11:56:24 +08:00
|
|
|
* (based on pci_32.c and pci_64.c)
|
|
|
|
*
|
|
|
|
* Port for PPC64 David Engebretsen, IBM Corp.
|
|
|
|
* Contains common pci routines for ppc64 platform, pSeries and iSeries brands.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 Anton Blanchard <anton@au.ibm.com>, IBM
|
|
|
|
* Rework, based on alpha PCI code.
|
|
|
|
*
|
|
|
|
* Common pmac/prep/chrp pci routines. -- Cort
|
2007-06-27 14:17:57 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/init.h>
|
2014-04-24 16:00:24 +08:00
|
|
|
#include <linux/delay.h>
|
2011-05-27 22:46:24 +08:00
|
|
|
#include <linux/export.h>
|
2010-07-30 01:49:01 +08:00
|
|
|
#include <linux/of_address.h>
|
2011-01-24 12:28:55 +08:00
|
|
|
#include <linux/of_pci.h>
|
2007-06-27 14:17:57 +08:00
|
|
|
#include <linux/mm.h>
|
2017-02-25 06:59:36 +08:00
|
|
|
#include <linux/shmem_fs.h>
|
2007-06-27 14:17:57 +08:00
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/syscalls.h>
|
|
|
|
#include <linux/irq.h>
|
|
|
|
#include <linux/vmalloc.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2013-04-08 11:05:10 +08:00
|
|
|
#include <linux/vgaarb.h>
|
2007-06-27 14:17:57 +08:00
|
|
|
|
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/prom.h>
|
|
|
|
#include <asm/pci-bridge.h>
|
|
|
|
#include <asm/byteorder.h>
|
|
|
|
#include <asm/machdep.h>
|
|
|
|
#include <asm/ppc-pci.h>
|
2008-10-28 03:48:37 +08:00
|
|
|
#include <asm/eeh.h>
|
2007-06-27 14:17:57 +08:00
|
|
|
|
2016-06-30 02:14:22 +08:00
|
|
|
/* hose_spinlock protects accesses to the the phb_bitmap. */
|
2007-06-28 02:09:43 +08:00
|
|
|
static DEFINE_SPINLOCK(hose_spinlock);
|
2009-01-08 10:19:46 +08:00
|
|
|
LIST_HEAD(hose_list);
|
2007-06-28 02:09:43 +08:00
|
|
|
|
2016-06-30 02:14:22 +08:00
|
|
|
/* For dynamic PHB numbering on get_phb_number(): max number of PHBs. */
|
|
|
|
#define MAX_PHBS 0x10000
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For dynamic PHB numbering: used/free PHBs tracking bitmap.
|
|
|
|
* Accesses to this bitmap should be protected by hose_spinlock.
|
|
|
|
*/
|
|
|
|
static DECLARE_BITMAP(phb_bitmap, MAX_PHBS);
|
2007-06-28 02:09:43 +08:00
|
|
|
|
2007-12-11 11:48:17 +08:00
|
|
|
/* ISA Memory physical address */
|
|
|
|
resource_size_t isa_mem_base;
|
2016-01-14 12:33:46 +08:00
|
|
|
EXPORT_SYMBOL(isa_mem_base);
|
2007-12-11 11:48:17 +08:00
|
|
|
|
2007-06-28 02:09:43 +08:00
|
|
|
|
2017-01-21 05:04:01 +08:00
|
|
|
static const struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
|
powerpc: Merge 32 and 64-bit dma code
We essentially adopt the 64-bit dma code, with some changes to support
32-bit systems, including HIGHMEM. dma functions on 32-bit are now
invoked via accessor functions which call the correct op for a device based
on archdata dma_ops. If there is no archdata dma_ops, this defaults
to dma_direct_ops.
In addition, the dma_map/unmap_page functions are added to dma_ops
because we can't just fall back on map/unmap_single when HIGHMEM is
enabled. In the case of dma_direct_*, we stop using map/unmap_single
and just use the page version - this saves a lot of ugly
ifdeffing. We leave map/unmap_single in the dma_ops definition,
though, because they are needed by the iommu code, which does not
implement map/unmap_page. Ideally, going forward, we will completely
eliminate map/unmap_single and just have map/unmap_page, if it's
workable for 64-bit.
Signed-off-by: Becky Bruce <becky.bruce@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2008-09-12 18:34:46 +08:00
|
|
|
|
2017-01-21 05:04:01 +08:00
|
|
|
void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
|
powerpc: Merge 32 and 64-bit dma code
We essentially adopt the 64-bit dma code, with some changes to support
32-bit systems, including HIGHMEM. dma functions on 32-bit are now
invoked via accessor functions which call the correct op for a device based
on archdata dma_ops. If there is no archdata dma_ops, this defaults
to dma_direct_ops.
In addition, the dma_map/unmap_page functions are added to dma_ops
because we can't just fall back on map/unmap_single when HIGHMEM is
enabled. In the case of dma_direct_*, we stop using map/unmap_single
and just use the page version - this saves a lot of ugly
ifdeffing. We leave map/unmap_single in the dma_ops definition,
though, because they are needed by the iommu code, which does not
implement map/unmap_page. Ideally, going forward, we will completely
eliminate map/unmap_single and just have map/unmap_page, if it's
workable for 64-bit.
Signed-off-by: Becky Bruce <becky.bruce@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2008-09-12 18:34:46 +08:00
|
|
|
{
|
|
|
|
pci_dma_ops = dma_ops;
|
|
|
|
}
|
|
|
|
|
2017-01-21 05:04:01 +08:00
|
|
|
const struct dma_map_ops *get_pci_dma_ops(void)
|
powerpc: Merge 32 and 64-bit dma code
We essentially adopt the 64-bit dma code, with some changes to support
32-bit systems, including HIGHMEM. dma functions on 32-bit are now
invoked via accessor functions which call the correct op for a device based
on archdata dma_ops. If there is no archdata dma_ops, this defaults
to dma_direct_ops.
In addition, the dma_map/unmap_page functions are added to dma_ops
because we can't just fall back on map/unmap_single when HIGHMEM is
enabled. In the case of dma_direct_*, we stop using map/unmap_single
and just use the page version - this saves a lot of ugly
ifdeffing. We leave map/unmap_single in the dma_ops definition,
though, because they are needed by the iommu code, which does not
implement map/unmap_page. Ideally, going forward, we will completely
eliminate map/unmap_single and just have map/unmap_page, if it's
workable for 64-bit.
Signed-off-by: Becky Bruce <becky.bruce@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2008-09-12 18:34:46 +08:00
|
|
|
{
|
|
|
|
return pci_dma_ops;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(get_pci_dma_ops);
|
|
|
|
|
2016-06-30 02:14:22 +08:00
|
|
|
/*
|
|
|
|
* This function should run under locking protection, specifically
|
|
|
|
* hose_spinlock.
|
|
|
|
*/
|
|
|
|
static int get_phb_number(struct device_node *dn)
|
|
|
|
{
|
|
|
|
int ret, phb_id = -1;
|
2016-08-05 14:40:56 +08:00
|
|
|
u32 prop_32;
|
2016-06-30 02:14:22 +08:00
|
|
|
u64 prop;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try fixed PHB numbering first, by checking archs and reading
|
|
|
|
* the respective device-tree properties. Firstly, try powernv by
|
|
|
|
* reading "ibm,opal-phbid", only present in OPAL environment.
|
|
|
|
*/
|
|
|
|
ret = of_property_read_u64(dn, "ibm,opal-phbid", &prop);
|
2016-08-05 14:40:56 +08:00
|
|
|
if (ret) {
|
|
|
|
ret = of_property_read_u32_index(dn, "reg", 1, &prop_32);
|
|
|
|
prop = prop_32;
|
|
|
|
}
|
2016-06-30 02:14:22 +08:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
phb_id = (int)(prop & (MAX_PHBS - 1));
|
|
|
|
|
|
|
|
/* We need to be sure to not use the same PHB number twice. */
|
|
|
|
if ((phb_id >= 0) && !test_and_set_bit(phb_id, phb_bitmap))
|
|
|
|
return phb_id;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If not pseries nor powernv, or if fixed PHB numbering tried to add
|
|
|
|
* the same PHB number twice, then fallback to dynamic PHB numbering.
|
|
|
|
*/
|
|
|
|
phb_id = find_first_zero_bit(phb_bitmap, MAX_PHBS);
|
|
|
|
BUG_ON(phb_id >= MAX_PHBS);
|
|
|
|
set_bit(phb_id, phb_bitmap);
|
|
|
|
|
|
|
|
return phb_id;
|
|
|
|
}
|
|
|
|
|
2007-12-11 08:02:07 +08:00
|
|
|
struct pci_controller *pcibios_alloc_controller(struct device_node *dev)
|
2007-06-28 02:09:43 +08:00
|
|
|
{
|
|
|
|
struct pci_controller *phb;
|
|
|
|
|
2007-12-11 08:02:07 +08:00
|
|
|
phb = zalloc_maybe_bootmem(sizeof(struct pci_controller), GFP_KERNEL);
|
2007-06-28 02:09:43 +08:00
|
|
|
if (phb == NULL)
|
|
|
|
return NULL;
|
2007-12-11 08:02:07 +08:00
|
|
|
spin_lock(&hose_spinlock);
|
2016-06-30 02:14:22 +08:00
|
|
|
phb->global_number = get_phb_number(dev);
|
2007-12-11 08:02:07 +08:00
|
|
|
list_add_tail(&phb->list_node, &hose_list);
|
|
|
|
spin_unlock(&hose_spinlock);
|
2007-12-10 11:33:21 +08:00
|
|
|
phb->dn = dev;
|
2015-03-30 11:10:37 +08:00
|
|
|
phb->is_dynamic = slab_is_available();
|
2007-06-28 02:09:43 +08:00
|
|
|
#ifdef CONFIG_PPC64
|
|
|
|
if (dev) {
|
|
|
|
int nid = of_node_to_nid(dev);
|
|
|
|
|
|
|
|
if (nid < 0 || !node_online(nid))
|
|
|
|
nid = -1;
|
|
|
|
|
|
|
|
PHB_SET_NODE(phb, nid);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return phb;
|
|
|
|
}
|
2015-05-27 14:06:56 +08:00
|
|
|
EXPORT_SYMBOL_GPL(pcibios_alloc_controller);
|
2007-06-28 02:09:43 +08:00
|
|
|
|
|
|
|
void pcibios_free_controller(struct pci_controller *phb)
|
|
|
|
{
|
|
|
|
spin_lock(&hose_spinlock);
|
2016-06-30 02:14:22 +08:00
|
|
|
|
|
|
|
/* Clear bit of phb_bitmap to allow reuse of this PHB number. */
|
|
|
|
if (phb->global_number < MAX_PHBS)
|
|
|
|
clear_bit(phb->global_number, phb_bitmap);
|
|
|
|
|
2007-06-28 02:09:43 +08:00
|
|
|
list_del(&phb->list_node);
|
|
|
|
spin_unlock(&hose_spinlock);
|
|
|
|
|
|
|
|
if (phb->is_dynamic)
|
|
|
|
kfree(phb);
|
|
|
|
}
|
2015-09-10 14:28:34 +08:00
|
|
|
EXPORT_SYMBOL_GPL(pcibios_free_controller);
|
2007-06-28 02:09:43 +08:00
|
|
|
|
powerpc/pseries: use pci_host_bridge.release_fn() to kfree(phb)
This patch leverages 'struct pci_host_bridge' from the PCI subsystem
in order to free the pci_controller only after the last reference to
its devices is dropped (avoiding an oops in pcibios_release_device()
if the last reference is dropped after pcibios_free_controller()).
The patch relies on pci_host_bridge.release_fn() (and .release_data),
which is called automatically by the PCI subsystem when the root bus
is released (i.e., the last reference is dropped). Those fields are
set via pci_set_host_bridge_release() (e.g. in the platform-specific
implementation of pcibios_root_bridge_prepare()).
It introduces the 'pcibios_free_controller_deferred()' .release_fn()
and it expects .release_data to hold a pointer to the pci_controller.
The function implictly calls 'pcibios_free_controller()', so an user
must *NOT* explicitly call it if using the new _deferred() callback.
The functionality is enabled for pseries (although it isn't platform
specific, and may be used by cxl).
Details on not-so-elegant design choices:
- Use 'pci_host_bridge.release_data' field as pointer to associated
'struct pci_controller' so *not* to 'pci_bus_to_host(bridge->bus)'
in pcibios_free_controller_deferred().
That's because pci_remove_root_bus() sets 'host_bridge->bus = NULL'
(so, if the last reference is released after pci_remove_root_bus()
runs, which eventually reaches pcibios_free_controller_deferred(),
that would hit a null pointer dereference).
The cxl/vphb.c code calls pci_remove_root_bus(), and the cxl folks
are interested in this fix.
Test-case #1 (hold references)
# ls -ld /sys/block/sd* | grep -m1 0021:01:00.0
<...> /sys/block/sdaa -> ../devices/pci0021:01/0021:01:00.0/<...>
# ls -ld /sys/block/sd* | grep -m1 0021:01:00.1
<...> /sys/block/sdab -> ../devices/pci0021:01/0021:01:00.1/<...>
# cat >/dev/sdaa & pid1=$!
# cat >/dev/sdab & pid2=$!
# drmgr -w 5 -d 1 -c phb -s 'PHB 33' -r
Validating PHB DLPAR capability...yes.
[ 594.306719] pci_hp_remove_devices: PCI: Removing devices on bus 0021:01
[ 594.306738] pci_hp_remove_devices: Removing 0021:01:00.0...
...
[ 598.236381] pci_hp_remove_devices: Removing 0021:01:00.1...
...
[ 611.972077] pci_bus 0021:01: busn_res: [bus 01-ff] is released
[ 611.972140] rpadlpar_io: slot PHB 33 removed
# kill -9 $pid1
# kill -9 $pid2
[ 632.918088] pcibios_free_controller_deferred: domain 33, dynamic 1
Test-case #2 (don't hold references)
# drmgr -w 5 -d 1 -c phb -s 'PHB 33' -r
Validating PHB DLPAR capability...yes.
[ 916.357363] pci_hp_remove_devices: PCI: Removing devices on bus 0021:01
[ 916.357386] pci_hp_remove_devices: Removing 0021:01:00.0...
...
[ 920.566527] pci_hp_remove_devices: Removing 0021:01:00.1...
...
[ 933.955873] pci_bus 0021:01: busn_res: [bus 01-ff] is released
[ 933.955977] pcibios_free_controller_deferred: domain 33, dynamic 1
[ 933.955999] rpadlpar_io: slot PHB 33 removed
Suggested-By: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Mauricio Faria de Oliveira <mauricfo@linux.vnet.ibm.com>
Reviewed-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Tested-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> # cxl
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2016-08-12 04:25:40 +08:00
|
|
|
/*
|
|
|
|
* This function is used to call pcibios_free_controller()
|
|
|
|
* in a deferred manner: a callback from the PCI subsystem.
|
|
|
|
*
|
|
|
|
* _*DO NOT*_ call pcibios_free_controller() explicitly if
|
|
|
|
* this is used (or it may access an invalid *phb pointer).
|
|
|
|
*
|
|
|
|
* The callback occurs when all references to the root bus
|
|
|
|
* are dropped (e.g., child buses/devices and their users).
|
|
|
|
*
|
|
|
|
* It's called as .release_fn() of 'struct pci_host_bridge'
|
|
|
|
* which is associated with the 'struct pci_controller.bus'
|
|
|
|
* (root bus) - it expects .release_data to hold a pointer
|
|
|
|
* to 'struct pci_controller'.
|
|
|
|
*
|
|
|
|
* In order to use it, register .release_fn()/release_data
|
|
|
|
* like this:
|
|
|
|
*
|
|
|
|
* pci_set_host_bridge_release(bridge,
|
|
|
|
* pcibios_free_controller_deferred
|
|
|
|
* (void *) phb);
|
|
|
|
*
|
|
|
|
* e.g. in the pcibios_root_bridge_prepare() callback from
|
|
|
|
* pci_create_root_bus().
|
|
|
|
*/
|
|
|
|
void pcibios_free_controller_deferred(struct pci_host_bridge *bridge)
|
|
|
|
{
|
|
|
|
struct pci_controller *phb = (struct pci_controller *)
|
|
|
|
bridge->release_data;
|
|
|
|
|
|
|
|
pr_debug("domain %d, dynamic %d\n", phb->global_number, phb->is_dynamic);
|
|
|
|
|
|
|
|
pcibios_free_controller(phb);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pcibios_free_controller_deferred);
|
|
|
|
|
2012-09-12 06:59:46 +08:00
|
|
|
/*
|
|
|
|
* The function is used to return the minimal alignment
|
|
|
|
* for memory or I/O windows of the associated P2P bridge.
|
|
|
|
* By default, 4KiB alignment for I/O windows and 1MiB for
|
|
|
|
* memory windows.
|
|
|
|
*/
|
|
|
|
resource_size_t pcibios_window_alignment(struct pci_bus *bus,
|
|
|
|
unsigned long type)
|
|
|
|
{
|
2015-03-31 13:00:56 +08:00
|
|
|
struct pci_controller *phb = pci_bus_to_host(bus);
|
|
|
|
|
|
|
|
if (phb->controller_ops.window_alignment)
|
|
|
|
return phb->controller_ops.window_alignment(bus, type);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PCI core will figure out the default
|
|
|
|
* alignment: 4KiB for I/O and 1MiB for
|
|
|
|
* memory window.
|
|
|
|
*/
|
|
|
|
return 1;
|
2012-09-12 06:59:46 +08:00
|
|
|
}
|
|
|
|
|
2016-05-20 14:41:26 +08:00
|
|
|
void pcibios_setup_bridge(struct pci_bus *bus, unsigned long type)
|
|
|
|
{
|
|
|
|
struct pci_controller *hose = pci_bus_to_host(bus);
|
|
|
|
|
|
|
|
if (hose->controller_ops.setup_bridge)
|
|
|
|
hose->controller_ops.setup_bridge(bus, type);
|
|
|
|
}
|
|
|
|
|
2014-04-24 16:00:24 +08:00
|
|
|
void pcibios_reset_secondary_bus(struct pci_dev *dev)
|
|
|
|
{
|
2015-03-31 13:00:56 +08:00
|
|
|
struct pci_controller *phb = pci_bus_to_host(dev->bus);
|
|
|
|
|
|
|
|
if (phb->controller_ops.reset_secondary_bus) {
|
|
|
|
phb->controller_ops.reset_secondary_bus(dev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pci_reset_secondary_bus(dev);
|
2014-04-24 16:00:24 +08:00
|
|
|
}
|
|
|
|
|
2017-04-10 19:58:13 +08:00
|
|
|
resource_size_t pcibios_default_alignment(void)
|
|
|
|
{
|
|
|
|
if (ppc_md.pcibios_default_alignment)
|
|
|
|
return ppc_md.pcibios_default_alignment();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-25 16:23:56 +08:00
|
|
|
#ifdef CONFIG_PCI_IOV
|
|
|
|
resource_size_t pcibios_iov_resource_alignment(struct pci_dev *pdev, int resno)
|
|
|
|
{
|
|
|
|
if (ppc_md.pcibios_iov_resource_alignment)
|
|
|
|
return ppc_md.pcibios_iov_resource_alignment(pdev, resno);
|
|
|
|
|
|
|
|
return pci_iov_resource_size(pdev, resno);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_PCI_IOV */
|
|
|
|
|
2009-01-08 10:19:46 +08:00
|
|
|
static resource_size_t pcibios_io_size(const struct pci_controller *hose)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_PPC64
|
|
|
|
return hose->pci_io_size;
|
|
|
|
#else
|
2011-06-10 00:13:32 +08:00
|
|
|
return resource_size(&hose->io_resource);
|
2009-01-08 10:19:46 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-07-26 12:07:13 +08:00
|
|
|
int pcibios_vaddr_is_ioport(void __iomem *address)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct pci_controller *hose;
|
2009-01-08 10:19:46 +08:00
|
|
|
resource_size_t size;
|
2007-07-26 12:07:13 +08:00
|
|
|
|
|
|
|
spin_lock(&hose_spinlock);
|
|
|
|
list_for_each_entry(hose, &hose_list, list_node) {
|
2009-01-08 10:19:46 +08:00
|
|
|
size = pcibios_io_size(hose);
|
2007-07-26 12:07:13 +08:00
|
|
|
if (address >= hose->io_base_virt &&
|
|
|
|
address < (hose->io_base_virt + size)) {
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock(&hose_spinlock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-01-08 10:19:46 +08:00
|
|
|
unsigned long pci_address_to_pio(phys_addr_t address)
|
|
|
|
{
|
|
|
|
struct pci_controller *hose;
|
|
|
|
resource_size_t size;
|
|
|
|
unsigned long ret = ~0;
|
|
|
|
|
|
|
|
spin_lock(&hose_spinlock);
|
|
|
|
list_for_each_entry(hose, &hose_list, list_node) {
|
|
|
|
size = pcibios_io_size(hose);
|
|
|
|
if (address >= hose->io_base_phys &&
|
|
|
|
address < (hose->io_base_phys + size)) {
|
|
|
|
unsigned long base =
|
|
|
|
(unsigned long)hose->io_base_virt - _IO_BASE;
|
|
|
|
ret = base + (address - hose->io_base_phys);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock(&hose_spinlock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pci_address_to_pio);
|
|
|
|
|
2007-06-27 14:17:57 +08:00
|
|
|
/*
|
|
|
|
* Return the domain number for this bus.
|
|
|
|
*/
|
|
|
|
int pci_domain_nr(struct pci_bus *bus)
|
|
|
|
{
|
2007-12-06 23:04:33 +08:00
|
|
|
struct pci_controller *hose = pci_bus_to_host(bus);
|
2007-06-27 14:17:57 +08:00
|
|
|
|
2007-12-06 23:04:33 +08:00
|
|
|
return hose->global_number;
|
2007-06-27 14:17:57 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(pci_domain_nr);
|
2007-06-28 00:07:51 +08:00
|
|
|
|
2007-06-28 02:09:43 +08:00
|
|
|
/* This routine is meant to be used early during boot, when the
|
|
|
|
* PCI bus numbers have not yet been assigned, and you need to
|
|
|
|
* issue PCI config cycles to an OF device.
|
|
|
|
* It could also be used to "fix" RTAS config cycles if you want
|
|
|
|
* to set pci_assign_all_buses to 1 and still use RTAS for PCI
|
|
|
|
* config cycles.
|
|
|
|
*/
|
|
|
|
struct pci_controller* pci_find_hose_for_OF_device(struct device_node* node)
|
|
|
|
{
|
|
|
|
while(node) {
|
|
|
|
struct pci_controller *hose, *tmp;
|
|
|
|
list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
|
2007-12-10 11:33:21 +08:00
|
|
|
if (hose->dn == node)
|
2007-06-28 02:09:43 +08:00
|
|
|
return hose;
|
|
|
|
node = node->parent;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-06-28 00:07:51 +08:00
|
|
|
/*
|
|
|
|
* Reads the interrupt pin to determine if interrupt is use by card.
|
|
|
|
* If the interrupt is used, then gets the interrupt line from the
|
|
|
|
* openfirmware and sets it in the pci_dev and pci_config line.
|
|
|
|
*/
|
2011-11-30 04:16:25 +08:00
|
|
|
static int pci_read_irq_line(struct pci_dev *pci_dev)
|
2007-06-28 00:07:51 +08:00
|
|
|
{
|
2013-09-15 23:39:11 +08:00
|
|
|
struct of_phandle_args oirq;
|
2007-06-28 00:07:51 +08:00
|
|
|
unsigned int virq;
|
|
|
|
|
2008-10-28 03:48:22 +08:00
|
|
|
pr_debug("PCI: Try to map irq for %s...\n", pci_name(pci_dev));
|
2007-06-28 00:07:51 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
memset(&oirq, 0xff, sizeof(oirq));
|
|
|
|
#endif
|
|
|
|
/* Try to get a mapping from the device-tree */
|
2013-09-20 00:22:36 +08:00
|
|
|
if (of_irq_parse_pci(pci_dev, &oirq)) {
|
2007-06-28 00:07:51 +08:00
|
|
|
u8 line, pin;
|
|
|
|
|
|
|
|
/* If that fails, lets fallback to what is in the config
|
|
|
|
* space and map that through the default controller. We
|
|
|
|
* also set the type to level low since that's what PCI
|
|
|
|
* interrupts are. If your platform does differently, then
|
|
|
|
* either provide a proper interrupt tree or don't use this
|
|
|
|
* function.
|
|
|
|
*/
|
|
|
|
if (pci_read_config_byte(pci_dev, PCI_INTERRUPT_PIN, &pin))
|
|
|
|
return -1;
|
|
|
|
if (pin == 0)
|
|
|
|
return -1;
|
|
|
|
if (pci_read_config_byte(pci_dev, PCI_INTERRUPT_LINE, &line) ||
|
2007-12-20 12:10:02 +08:00
|
|
|
line == 0xff || line == 0) {
|
2007-06-28 00:07:51 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2008-10-28 03:48:22 +08:00
|
|
|
pr_debug(" No map ! Using line %d (pin %d) from PCI config\n",
|
|
|
|
line, pin);
|
2007-06-28 00:07:51 +08:00
|
|
|
|
|
|
|
virq = irq_create_mapping(NULL, line);
|
2016-09-06 19:53:24 +08:00
|
|
|
if (virq)
|
2011-03-25 23:45:20 +08:00
|
|
|
irq_set_irq_type(virq, IRQ_TYPE_LEVEL_LOW);
|
2007-06-28 00:07:51 +08:00
|
|
|
} else {
|
2017-08-21 23:16:47 +08:00
|
|
|
pr_debug(" Got one, spec %d cells (0x%08x 0x%08x...) on %pOF\n",
|
|
|
|
oirq.args_count, oirq.args[0], oirq.args[1], oirq.np);
|
2007-06-28 00:07:51 +08:00
|
|
|
|
2013-09-15 23:55:53 +08:00
|
|
|
virq = irq_create_of_mapping(&oirq);
|
2007-06-28 00:07:51 +08:00
|
|
|
}
|
2016-09-06 19:53:24 +08:00
|
|
|
|
|
|
|
if (!virq) {
|
2008-10-28 03:48:22 +08:00
|
|
|
pr_debug(" Failed to map !\n");
|
2007-06-28 00:07:51 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-10-28 03:48:22 +08:00
|
|
|
pr_debug(" Mapped to linux irq %d\n", virq);
|
2007-06-28 00:07:51 +08:00
|
|
|
|
|
|
|
pci_dev->irq = virq;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Platform support for /proc/bus/pci/X/Y mmap()s,
|
|
|
|
* modelled on the sparc64 implementation by Dave Miller.
|
|
|
|
* -- paulus.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Adjust vm_pgoff of VMA such that it is the physical page offset
|
|
|
|
* corresponding to the 32-bit pci bus offset for DEV requested by the user.
|
|
|
|
*
|
|
|
|
* Basically, the user finds the base address for his device which he wishes
|
|
|
|
* to mmap. They read the 32-bit value from the config space base register,
|
|
|
|
* add whatever PAGE_SIZE multiple offset they wish, and feed this into the
|
|
|
|
* offset parameter of mmap on /proc/bus/pci/XXX for that device.
|
|
|
|
*
|
|
|
|
* Returns negative error code on failure, zero on success.
|
|
|
|
*/
|
|
|
|
static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
|
|
|
|
resource_size_t *offset,
|
|
|
|
enum pci_mmap_state mmap_state)
|
|
|
|
{
|
|
|
|
struct pci_controller *hose = pci_bus_to_host(dev->bus);
|
|
|
|
unsigned long io_offset = 0;
|
|
|
|
int i, res_bit;
|
|
|
|
|
2013-08-07 00:01:24 +08:00
|
|
|
if (hose == NULL)
|
2007-06-28 00:07:51 +08:00
|
|
|
return NULL; /* should never happen */
|
|
|
|
|
|
|
|
/* If memory, add on the PCI bridge address offset */
|
|
|
|
if (mmap_state == pci_mmap_mem) {
|
|
|
|
#if 0 /* See comment in pci_resource_to_user() for why this is disabled */
|
|
|
|
*offset += hose->pci_mem_offset;
|
|
|
|
#endif
|
|
|
|
res_bit = IORESOURCE_MEM;
|
|
|
|
} else {
|
|
|
|
io_offset = (unsigned long)hose->io_base_virt - _IO_BASE;
|
|
|
|
*offset += io_offset;
|
|
|
|
res_bit = IORESOURCE_IO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that the offset requested corresponds to one of the
|
|
|
|
* resources of the device.
|
|
|
|
*/
|
|
|
|
for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
|
|
|
|
struct resource *rp = &dev->resource[i];
|
|
|
|
int flags = rp->flags;
|
|
|
|
|
|
|
|
/* treat ROM as memory (should be already) */
|
|
|
|
if (i == PCI_ROM_RESOURCE)
|
|
|
|
flags |= IORESOURCE_MEM;
|
|
|
|
|
|
|
|
/* Active and same type? */
|
|
|
|
if ((flags & res_bit) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* In the range of this resource? */
|
|
|
|
if (*offset < (rp->start & PAGE_MASK) || *offset > rp->end)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* found it! construct the final physical address */
|
|
|
|
if (mmap_state == pci_mmap_io)
|
|
|
|
*offset += hose->io_base_phys - io_offset;
|
|
|
|
return rp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This one is used by /dev/mem and fbdev who have no clue about the
|
|
|
|
* PCI device, it tries to find the PCI device first and calls the
|
|
|
|
* above routine
|
|
|
|
*/
|
|
|
|
pgprot_t pci_phys_mem_access_prot(struct file *file,
|
|
|
|
unsigned long pfn,
|
|
|
|
unsigned long size,
|
2008-12-19 03:13:51 +08:00
|
|
|
pgprot_t prot)
|
2007-06-28 00:07:51 +08:00
|
|
|
{
|
|
|
|
struct pci_dev *pdev = NULL;
|
|
|
|
struct resource *found = NULL;
|
2008-10-01 23:30:04 +08:00
|
|
|
resource_size_t offset = ((resource_size_t)pfn) << PAGE_SHIFT;
|
2007-06-28 00:07:51 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (page_is_ram(pfn))
|
2008-12-19 03:13:51 +08:00
|
|
|
return prot;
|
2007-06-28 00:07:51 +08:00
|
|
|
|
2008-12-19 03:13:51 +08:00
|
|
|
prot = pgprot_noncached(prot);
|
2007-06-28 00:07:51 +08:00
|
|
|
for_each_pci_dev(pdev) {
|
|
|
|
for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
|
|
|
|
struct resource *rp = &pdev->resource[i];
|
|
|
|
int flags = rp->flags;
|
|
|
|
|
|
|
|
/* Active and same type? */
|
|
|
|
if ((flags & IORESOURCE_MEM) == 0)
|
|
|
|
continue;
|
|
|
|
/* In the range of this resource? */
|
|
|
|
if (offset < (rp->start & PAGE_MASK) ||
|
|
|
|
offset > rp->end)
|
|
|
|
continue;
|
|
|
|
found = rp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (found)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
if (found->flags & IORESOURCE_PREFETCH)
|
2008-12-19 03:13:51 +08:00
|
|
|
prot = pgprot_noncached_wc(prot);
|
2007-06-28 00:07:51 +08:00
|
|
|
pci_dev_put(pdev);
|
|
|
|
}
|
|
|
|
|
2008-10-28 03:48:22 +08:00
|
|
|
pr_debug("PCI: Non-PCI map for %llx, prot: %lx\n",
|
2008-12-19 03:13:51 +08:00
|
|
|
(unsigned long long)offset, pgprot_val(prot));
|
2007-06-28 00:07:51 +08:00
|
|
|
|
2008-12-19 03:13:51 +08:00
|
|
|
return prot;
|
2007-06-28 00:07:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform the actual remap of the pages for a PCI device mapping, as
|
|
|
|
* appropriate for this architecture. The region in the process to map
|
|
|
|
* is described by vm_start and vm_end members of VMA, the base physical
|
|
|
|
* address is found in vm_pgoff.
|
|
|
|
* The pci device structure is provided so that architectures may make mapping
|
|
|
|
* decisions on a per-device or per-bus basis.
|
|
|
|
*
|
|
|
|
* Returns a negative error code on failure, zero on success.
|
|
|
|
*/
|
2017-04-12 20:25:58 +08:00
|
|
|
int pci_mmap_page_range(struct pci_dev *dev, int bar,
|
|
|
|
struct vm_area_struct *vma,
|
2007-06-28 00:07:51 +08:00
|
|
|
enum pci_mmap_state mmap_state, int write_combine)
|
|
|
|
{
|
2008-10-01 23:30:04 +08:00
|
|
|
resource_size_t offset =
|
|
|
|
((resource_size_t)vma->vm_pgoff) << PAGE_SHIFT;
|
2007-06-28 00:07:51 +08:00
|
|
|
struct resource *rp;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
rp = __pci_mmap_make_offset(dev, &offset, mmap_state);
|
|
|
|
if (rp == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
vma->vm_pgoff = offset >> PAGE_SHIFT;
|
2016-06-18 03:43:33 +08:00
|
|
|
if (write_combine)
|
|
|
|
vma->vm_page_prot = pgprot_noncached_wc(vma->vm_page_prot);
|
|
|
|
else
|
|
|
|
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
|
2007-06-28 00:07:51 +08:00
|
|
|
|
|
|
|
ret = remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
|
|
|
|
vma->vm_end - vma->vm_start, vma->vm_page_prot);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-10-14 08:55:31 +08:00
|
|
|
/* This provides legacy IO read access on a bus */
|
|
|
|
int pci_legacy_read(struct pci_bus *bus, loff_t port, u32 *val, size_t size)
|
|
|
|
{
|
|
|
|
unsigned long offset;
|
|
|
|
struct pci_controller *hose = pci_bus_to_host(bus);
|
|
|
|
struct resource *rp = &hose->io_resource;
|
|
|
|
void __iomem *addr;
|
|
|
|
|
|
|
|
/* Check if port can be supported by that bus. We only check
|
|
|
|
* the ranges of the PHB though, not the bus itself as the rules
|
|
|
|
* for forwarding legacy cycles down bridges are not our problem
|
|
|
|
* here. So if the host bridge supports it, we do it.
|
|
|
|
*/
|
|
|
|
offset = (unsigned long)hose->io_base_virt - _IO_BASE;
|
|
|
|
offset += port;
|
|
|
|
|
|
|
|
if (!(rp->flags & IORESOURCE_IO))
|
|
|
|
return -ENXIO;
|
|
|
|
if (offset < rp->start || (offset + size) > rp->end)
|
|
|
|
return -ENXIO;
|
|
|
|
addr = hose->io_base_virt + port;
|
|
|
|
|
|
|
|
switch(size) {
|
|
|
|
case 1:
|
|
|
|
*((u8 *)val) = in_8(addr);
|
|
|
|
return 1;
|
|
|
|
case 2:
|
|
|
|
if (port & 1)
|
|
|
|
return -EINVAL;
|
|
|
|
*((u16 *)val) = in_le16(addr);
|
|
|
|
return 2;
|
|
|
|
case 4:
|
|
|
|
if (port & 3)
|
|
|
|
return -EINVAL;
|
|
|
|
*((u32 *)val) = in_le32(addr);
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This provides legacy IO write access on a bus */
|
|
|
|
int pci_legacy_write(struct pci_bus *bus, loff_t port, u32 val, size_t size)
|
|
|
|
{
|
|
|
|
unsigned long offset;
|
|
|
|
struct pci_controller *hose = pci_bus_to_host(bus);
|
|
|
|
struct resource *rp = &hose->io_resource;
|
|
|
|
void __iomem *addr;
|
|
|
|
|
|
|
|
/* Check if port can be supported by that bus. We only check
|
|
|
|
* the ranges of the PHB though, not the bus itself as the rules
|
|
|
|
* for forwarding legacy cycles down bridges are not our problem
|
|
|
|
* here. So if the host bridge supports it, we do it.
|
|
|
|
*/
|
|
|
|
offset = (unsigned long)hose->io_base_virt - _IO_BASE;
|
|
|
|
offset += port;
|
|
|
|
|
|
|
|
if (!(rp->flags & IORESOURCE_IO))
|
|
|
|
return -ENXIO;
|
|
|
|
if (offset < rp->start || (offset + size) > rp->end)
|
|
|
|
return -ENXIO;
|
|
|
|
addr = hose->io_base_virt + port;
|
|
|
|
|
|
|
|
/* WARNING: The generic code is idiotic. It gets passed a pointer
|
|
|
|
* to what can be a 1, 2 or 4 byte quantity and always reads that
|
|
|
|
* as a u32, which means that we have to correct the location of
|
|
|
|
* the data read within those 32 bits for size 1 and 2
|
|
|
|
*/
|
|
|
|
switch(size) {
|
|
|
|
case 1:
|
|
|
|
out_8(addr, val >> 24);
|
|
|
|
return 1;
|
|
|
|
case 2:
|
|
|
|
if (port & 1)
|
|
|
|
return -EINVAL;
|
|
|
|
out_le16(addr, val >> 16);
|
|
|
|
return 2;
|
|
|
|
case 4:
|
|
|
|
if (port & 3)
|
|
|
|
return -EINVAL;
|
|
|
|
out_le32(addr, val);
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This provides legacy IO or memory mmap access on a bus */
|
|
|
|
int pci_mmap_legacy_page_range(struct pci_bus *bus,
|
|
|
|
struct vm_area_struct *vma,
|
|
|
|
enum pci_mmap_state mmap_state)
|
|
|
|
{
|
|
|
|
struct pci_controller *hose = pci_bus_to_host(bus);
|
|
|
|
resource_size_t offset =
|
|
|
|
((resource_size_t)vma->vm_pgoff) << PAGE_SHIFT;
|
|
|
|
resource_size_t size = vma->vm_end - vma->vm_start;
|
|
|
|
struct resource *rp;
|
|
|
|
|
|
|
|
pr_debug("pci_mmap_legacy_page_range(%04x:%02x, %s @%llx..%llx)\n",
|
|
|
|
pci_domain_nr(bus), bus->number,
|
|
|
|
mmap_state == pci_mmap_mem ? "MEM" : "IO",
|
|
|
|
(unsigned long long)offset,
|
|
|
|
(unsigned long long)(offset + size - 1));
|
|
|
|
|
|
|
|
if (mmap_state == pci_mmap_mem) {
|
2009-02-08 22:27:21 +08:00
|
|
|
/* Hack alert !
|
|
|
|
*
|
|
|
|
* Because X is lame and can fail starting if it gets an error trying
|
|
|
|
* to mmap legacy_mem (instead of just moving on without legacy memory
|
|
|
|
* access) we fake it here by giving it anonymous memory, effectively
|
|
|
|
* behaving just like /dev/zero
|
|
|
|
*/
|
|
|
|
if ((offset + size) > hose->isa_mem_size) {
|
|
|
|
printk(KERN_DEBUG
|
|
|
|
"Process %s (pid:%d) mapped non-existing PCI legacy memory for 0%04x:%02x\n",
|
|
|
|
current->comm, current->pid, pci_domain_nr(bus), bus->number);
|
|
|
|
if (vma->vm_flags & VM_SHARED)
|
|
|
|
return shmem_zero_setup(vma);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-10-14 08:55:31 +08:00
|
|
|
offset += hose->isa_mem_phys;
|
|
|
|
} else {
|
|
|
|
unsigned long io_offset = (unsigned long)hose->io_base_virt - _IO_BASE;
|
|
|
|
unsigned long roffset = offset + io_offset;
|
|
|
|
rp = &hose->io_resource;
|
|
|
|
if (!(rp->flags & IORESOURCE_IO))
|
|
|
|
return -ENXIO;
|
|
|
|
if (roffset < rp->start || (roffset + size) > rp->end)
|
|
|
|
return -ENXIO;
|
|
|
|
offset += hose->io_base_phys;
|
|
|
|
}
|
|
|
|
pr_debug(" -> mapping phys %llx\n", (unsigned long long)offset);
|
|
|
|
|
|
|
|
vma->vm_pgoff = offset >> PAGE_SHIFT;
|
2008-12-19 03:13:51 +08:00
|
|
|
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
|
2008-10-14 08:55:31 +08:00
|
|
|
return remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
|
|
|
|
vma->vm_end - vma->vm_start,
|
|
|
|
vma->vm_page_prot);
|
|
|
|
}
|
|
|
|
|
2007-06-28 00:07:51 +08:00
|
|
|
void pci_resource_to_user(const struct pci_dev *dev, int bar,
|
|
|
|
const struct resource *rsrc,
|
|
|
|
resource_size_t *start, resource_size_t *end)
|
|
|
|
{
|
2016-06-18 03:43:34 +08:00
|
|
|
struct pci_bus_region region;
|
2007-06-28 00:07:51 +08:00
|
|
|
|
2016-06-18 03:43:34 +08:00
|
|
|
if (rsrc->flags & IORESOURCE_IO) {
|
|
|
|
pcibios_resource_to_bus(dev->bus, ®ion,
|
|
|
|
(struct resource *) rsrc);
|
|
|
|
*start = region.start;
|
|
|
|
*end = region.end;
|
2007-06-28 00:07:51 +08:00
|
|
|
return;
|
2016-06-18 03:43:34 +08:00
|
|
|
}
|
2007-06-28 00:07:51 +08:00
|
|
|
|
2016-06-18 03:43:34 +08:00
|
|
|
/* We pass a CPU physical address to userland for MMIO instead of a
|
|
|
|
* BAR value because X is lame and expects to be able to use that
|
|
|
|
* to pass to /dev/mem!
|
2007-06-28 00:07:51 +08:00
|
|
|
*
|
2016-06-18 03:43:34 +08:00
|
|
|
* That means we may have 64-bit values where some apps only expect
|
|
|
|
* 32 (like X itself since it thinks only Sparc has 64-bit MMIO).
|
2007-06-28 00:07:51 +08:00
|
|
|
*/
|
2016-06-18 03:43:34 +08:00
|
|
|
*start = rsrc->start;
|
|
|
|
*end = rsrc->end;
|
2007-06-28 00:07:51 +08:00
|
|
|
}
|
2007-12-11 11:48:18 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* pci_process_bridge_OF_ranges - Parse PCI bridge resources from device tree
|
|
|
|
* @hose: newly allocated pci_controller to be setup
|
|
|
|
* @dev: device node of the host bridge
|
|
|
|
* @primary: set if primary bus (32 bits only, soon to be deprecated)
|
|
|
|
*
|
|
|
|
* This function will parse the "ranges" property of a PCI host bridge device
|
|
|
|
* node and setup the resource mapping of a pci controller based on its
|
|
|
|
* content.
|
|
|
|
*
|
|
|
|
* Life would be boring if it wasn't for a few issues that we have to deal
|
|
|
|
* with here:
|
|
|
|
*
|
|
|
|
* - We can only cope with one IO space range and up to 3 Memory space
|
|
|
|
* ranges. However, some machines (thanks Apple !) tend to split their
|
|
|
|
* space into lots of small contiguous ranges. So we have to coalesce.
|
|
|
|
*
|
|
|
|
* - Some busses have IO space not starting at 0, which causes trouble with
|
|
|
|
* the way we do our IO resource renumbering. The code somewhat deals with
|
|
|
|
* it for 64 bits but I would expect problems on 32 bits.
|
|
|
|
*
|
|
|
|
* - Some 32 bits platforms such as 4xx can have physical space larger than
|
|
|
|
* 32 bits so we need to use 64 bits values for the parsing
|
|
|
|
*/
|
2012-12-22 06:04:10 +08:00
|
|
|
void pci_process_bridge_OF_ranges(struct pci_controller *hose,
|
|
|
|
struct device_node *dev, int primary)
|
2007-12-11 11:48:18 +08:00
|
|
|
{
|
2013-05-17 04:58:42 +08:00
|
|
|
int memno = 0;
|
2007-12-11 11:48:18 +08:00
|
|
|
struct resource *res;
|
2014-02-25 14:32:11 +08:00
|
|
|
struct of_pci_range range;
|
|
|
|
struct of_pci_range_parser parser;
|
2007-12-11 11:48:18 +08:00
|
|
|
|
2017-08-21 23:16:47 +08:00
|
|
|
printk(KERN_INFO "PCI host bridge %pOF %s ranges:\n",
|
|
|
|
dev, primary ? "(primary)" : "");
|
2007-12-11 11:48:18 +08:00
|
|
|
|
2014-02-25 14:32:11 +08:00
|
|
|
/* Check for ranges property */
|
|
|
|
if (of_pci_range_parser_init(&parser, dev))
|
2007-12-11 11:48:18 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Parse it */
|
2014-02-25 14:32:11 +08:00
|
|
|
for_each_of_pci_range(&parser, &range) {
|
2008-10-14 08:55:31 +08:00
|
|
|
/* If we failed translation or got a zero-sized region
|
|
|
|
* (some FW try to feed us with non sensical zero sized regions
|
|
|
|
* such as power3 which look like some kind of attempt at exposing
|
|
|
|
* the VGA memory hole)
|
|
|
|
*/
|
2014-02-25 14:32:11 +08:00
|
|
|
if (range.cpu_addr == OF_BAD_ADDR || range.size == 0)
|
2007-12-11 11:48:18 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Act based on address space type */
|
|
|
|
res = NULL;
|
2014-02-25 14:32:11 +08:00
|
|
|
switch (range.flags & IORESOURCE_TYPE_BITS) {
|
|
|
|
case IORESOURCE_IO:
|
2007-12-11 11:48:18 +08:00
|
|
|
printk(KERN_INFO
|
|
|
|
" IO 0x%016llx..0x%016llx -> 0x%016llx\n",
|
2014-02-25 14:32:11 +08:00
|
|
|
range.cpu_addr, range.cpu_addr + range.size - 1,
|
|
|
|
range.pci_addr);
|
2007-12-11 11:48:18 +08:00
|
|
|
|
|
|
|
/* We support only one IO range */
|
|
|
|
if (hose->pci_io_size) {
|
|
|
|
printk(KERN_INFO
|
|
|
|
" \\--> Skipped (too many) !\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#ifdef CONFIG_PPC32
|
|
|
|
/* On 32 bits, limit I/O space to 16MB */
|
2014-02-25 14:32:11 +08:00
|
|
|
if (range.size > 0x01000000)
|
|
|
|
range.size = 0x01000000;
|
2007-12-11 11:48:18 +08:00
|
|
|
|
|
|
|
/* 32 bits needs to map IOs here */
|
2014-02-25 14:32:11 +08:00
|
|
|
hose->io_base_virt = ioremap(range.cpu_addr,
|
|
|
|
range.size);
|
2007-12-11 11:48:18 +08:00
|
|
|
|
|
|
|
/* Expect trouble if pci_addr is not 0 */
|
|
|
|
if (primary)
|
|
|
|
isa_io_base =
|
|
|
|
(unsigned long)hose->io_base_virt;
|
|
|
|
#endif /* CONFIG_PPC32 */
|
|
|
|
/* pci_io_size and io_base_phys always represent IO
|
|
|
|
* space starting at 0 so we factor in pci_addr
|
|
|
|
*/
|
2014-02-25 14:32:11 +08:00
|
|
|
hose->pci_io_size = range.pci_addr + range.size;
|
|
|
|
hose->io_base_phys = range.cpu_addr - range.pci_addr;
|
2007-12-11 11:48:18 +08:00
|
|
|
|
|
|
|
/* Build resource */
|
|
|
|
res = &hose->io_resource;
|
2014-02-25 14:32:11 +08:00
|
|
|
range.cpu_addr = range.pci_addr;
|
2007-12-11 11:48:18 +08:00
|
|
|
break;
|
2014-02-25 14:32:11 +08:00
|
|
|
case IORESOURCE_MEM:
|
2007-12-11 11:48:18 +08:00
|
|
|
printk(KERN_INFO
|
|
|
|
" MEM 0x%016llx..0x%016llx -> 0x%016llx %s\n",
|
2014-02-25 14:32:11 +08:00
|
|
|
range.cpu_addr, range.cpu_addr + range.size - 1,
|
|
|
|
range.pci_addr,
|
|
|
|
(range.pci_space & 0x40000000) ?
|
|
|
|
"Prefetch" : "");
|
2007-12-11 11:48:18 +08:00
|
|
|
|
|
|
|
/* We support only 3 memory ranges */
|
|
|
|
if (memno >= 3) {
|
|
|
|
printk(KERN_INFO
|
|
|
|
" \\--> Skipped (too many) !\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Handles ISA memory hole space here */
|
2014-02-25 14:32:11 +08:00
|
|
|
if (range.pci_addr == 0) {
|
2007-12-11 11:48:18 +08:00
|
|
|
if (primary || isa_mem_base == 0)
|
2014-02-25 14:32:11 +08:00
|
|
|
isa_mem_base = range.cpu_addr;
|
|
|
|
hose->isa_mem_phys = range.cpu_addr;
|
|
|
|
hose->isa_mem_size = range.size;
|
2007-12-11 11:48:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Build resource */
|
2014-02-25 14:32:11 +08:00
|
|
|
hose->mem_offset[memno] = range.cpu_addr -
|
|
|
|
range.pci_addr;
|
2007-12-11 11:48:18 +08:00
|
|
|
res = &hose->mem_resources[memno++];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (res != NULL) {
|
2014-10-16 09:29:46 +08:00
|
|
|
res->name = dev->full_name;
|
|
|
|
res->flags = range.flags;
|
|
|
|
res->start = range.cpu_addr;
|
|
|
|
res->end = range.cpu_addr + range.size - 1;
|
|
|
|
res->parent = res->child = res->sibling = NULL;
|
2007-12-11 11:48:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-12-20 11:54:49 +08:00
|
|
|
|
|
|
|
/* Decide whether to display the domain number in /proc */
|
|
|
|
int pci_proc_domain(struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
struct pci_controller *hose = pci_bus_to_host(bus);
|
2008-10-02 22:12:51 +08:00
|
|
|
|
2011-07-12 22:25:51 +08:00
|
|
|
if (!pci_has_flag(PCI_ENABLE_PROC_DOMAINS))
|
2007-12-20 11:54:49 +08:00
|
|
|
return 0;
|
2011-07-12 22:25:51 +08:00
|
|
|
if (pci_has_flag(PCI_COMPAT_DOMAIN_0))
|
2007-12-20 11:54:49 +08:00
|
|
|
return hose->global_number != 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-05-03 20:43:12 +08:00
|
|
|
int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
|
|
|
|
{
|
|
|
|
if (ppc_md.pcibios_root_bridge_prepare)
|
|
|
|
return ppc_md.pcibios_root_bridge_prepare(bridge);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-20 11:54:51 +08:00
|
|
|
/* This header fixup will do the resource fixup for all devices as they are
|
|
|
|
* probed, but not for bridge ranges
|
|
|
|
*/
|
2012-12-22 06:04:10 +08:00
|
|
|
static void pcibios_fixup_resources(struct pci_dev *dev)
|
2007-12-20 11:54:51 +08:00
|
|
|
{
|
|
|
|
struct pci_controller *hose = pci_bus_to_host(dev->bus);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!hose) {
|
|
|
|
printk(KERN_ERR "No host bridge for PCI dev %s !\n",
|
|
|
|
pci_name(dev));
|
|
|
|
return;
|
|
|
|
}
|
powerpc/pci: Don't unset PCI resources for VFs
Flag PCI_REASSIGN_ALL_RSRC is used to ignore resources information setup by
firmware, so that kernel would re-assign all resources of pci devices.
On powerpc arch, this happens in a header fixup function
pcibios_fixup_resources(), which will clean up the resources if this flag
is set. This works fine for PFs, since after clean up, kernel will
re-assign the resources in pcibios_resource_survey().
Below is a simple call flow on how it works:
pcibios_init
pcibios_scan_phb
pci_scan_child_bus
...
pci_device_add
pci_fixup_device(pci_fixup_header)
pcibios_fixup_resources # header fixup
for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
dev->resource[i].start = 0
pcibios_resource_survey # re-assign
pcibios_allocate_resources
However, the VF resources won't be re-assigned, since the VF resources are
completely determined by the PF resources, and the PF resources have
already been reassigned. This means we need to leave VF's resources
un-cleared in pcibios_fixup_resources().
In this patch, we skip the resource unset process in
pcibios_fixup_resources(), if the pci_dev is a VF.
Signed-off-by: Wei Yang <weiyang@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2015-03-25 16:23:53 +08:00
|
|
|
|
|
|
|
if (dev->is_virtfn)
|
|
|
|
return;
|
|
|
|
|
2007-12-20 11:54:51 +08:00
|
|
|
for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
|
|
|
|
struct resource *res = dev->resource + i;
|
2013-06-05 10:26:51 +08:00
|
|
|
struct pci_bus_region reg;
|
2007-12-20 11:54:51 +08:00
|
|
|
if (!res->flags)
|
|
|
|
continue;
|
2011-11-07 02:55:58 +08:00
|
|
|
|
|
|
|
/* If we're going to re-assign everything, we mark all resources
|
|
|
|
* as unset (and 0-base them). In addition, we mark BARs starting
|
|
|
|
* at 0 as unset as well, except if PCI_PROBE_ONLY is also set
|
|
|
|
* since in that case, we don't want to re-assign anything
|
2008-02-29 11:58:03 +08:00
|
|
|
*/
|
PCI: Convert pcibios_resource_to_bus() to take a pci_bus, not a pci_dev
These interfaces:
pcibios_resource_to_bus(struct pci_dev *dev, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_dev *dev, *resource, *bus_region)
took a pci_dev, but they really depend only on the pci_bus. And we want to
use them in resource allocation paths where we have the bus but not a
device, so this patch converts them to take the pci_bus instead of the
pci_dev:
pcibios_resource_to_bus(struct pci_bus *bus, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_bus *bus, *resource, *bus_region)
In fact, with standard PCI-PCI bridges, they only depend on the host
bridge, because that's the only place address translation occurs, but
we aren't going that far yet.
[bhelgaas: changelog]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-12-10 14:54:40 +08:00
|
|
|
pcibios_resource_to_bus(dev->bus, ®, res);
|
2011-11-07 02:55:58 +08:00
|
|
|
if (pci_has_flag(PCI_REASSIGN_ALL_RSRC) ||
|
2013-06-05 10:26:51 +08:00
|
|
|
(reg.start == 0 && !pci_has_flag(PCI_PROBE_ONLY))) {
|
2011-11-07 02:55:58 +08:00
|
|
|
/* Only print message if not re-assigning */
|
|
|
|
if (!pci_has_flag(PCI_REASSIGN_ALL_RSRC))
|
2015-06-12 10:26:37 +08:00
|
|
|
pr_debug("PCI:%s Resource %d %pR is unassigned\n",
|
|
|
|
pci_name(dev), i, res);
|
2007-12-20 11:54:51 +08:00
|
|
|
res->end -= res->start;
|
|
|
|
res->start = 0;
|
|
|
|
res->flags |= IORESOURCE_UNSET;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-06-12 10:26:37 +08:00
|
|
|
pr_debug("PCI:%s Resource %d %pR\n", pci_name(dev), i, res);
|
2007-12-20 11:54:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Call machine specific resource fixup */
|
|
|
|
if (ppc_md.pcibios_fixup_resources)
|
|
|
|
ppc_md.pcibios_fixup_resources(dev);
|
|
|
|
}
|
|
|
|
DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pcibios_fixup_resources);
|
|
|
|
|
2008-10-13 21:56:31 +08:00
|
|
|
/* This function tries to figure out if a bridge resource has been initialized
|
|
|
|
* by the firmware or not. It doesn't have to be absolutely bullet proof, but
|
|
|
|
* things go more smoothly when it gets it right. It should covers cases such
|
|
|
|
* as Apple "closed" bridge resources and bare-metal pSeries unassigned bridges
|
|
|
|
*/
|
2012-12-22 06:04:10 +08:00
|
|
|
static int pcibios_uninitialized_bridge_resource(struct pci_bus *bus,
|
|
|
|
struct resource *res)
|
2007-12-20 11:54:51 +08:00
|
|
|
{
|
2007-12-20 11:55:04 +08:00
|
|
|
struct pci_controller *hose = pci_bus_to_host(bus);
|
2007-12-20 11:54:51 +08:00
|
|
|
struct pci_dev *dev = bus->self;
|
2008-10-13 21:56:31 +08:00
|
|
|
resource_size_t offset;
|
2013-05-06 11:40:40 +08:00
|
|
|
struct pci_bus_region region;
|
2008-10-13 21:56:31 +08:00
|
|
|
u16 command;
|
|
|
|
int i;
|
2007-12-20 11:54:51 +08:00
|
|
|
|
2008-10-13 21:56:31 +08:00
|
|
|
/* We don't do anything if PCI_PROBE_ONLY is set */
|
2011-07-12 22:25:51 +08:00
|
|
|
if (pci_has_flag(PCI_PROBE_ONLY))
|
2008-10-13 21:56:31 +08:00
|
|
|
return 0;
|
2007-12-20 11:54:51 +08:00
|
|
|
|
2008-10-13 21:56:31 +08:00
|
|
|
/* Job is a bit different between memory and IO */
|
|
|
|
if (res->flags & IORESOURCE_MEM) {
|
PCI: Convert pcibios_resource_to_bus() to take a pci_bus, not a pci_dev
These interfaces:
pcibios_resource_to_bus(struct pci_dev *dev, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_dev *dev, *resource, *bus_region)
took a pci_dev, but they really depend only on the pci_bus. And we want to
use them in resource allocation paths where we have the bus but not a
device, so this patch converts them to take the pci_bus instead of the
pci_dev:
pcibios_resource_to_bus(struct pci_bus *bus, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_bus *bus, *resource, *bus_region)
In fact, with standard PCI-PCI bridges, they only depend on the host
bridge, because that's the only place address translation occurs, but
we aren't going that far yet.
[bhelgaas: changelog]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-12-10 14:54:40 +08:00
|
|
|
pcibios_resource_to_bus(dev->bus, ®ion, res);
|
2013-05-06 11:40:40 +08:00
|
|
|
|
|
|
|
/* If the BAR is non-0 then it's probably been initialized */
|
|
|
|
if (region.start != 0)
|
2008-10-13 21:56:31 +08:00
|
|
|
return 0;
|
2007-12-20 11:54:51 +08:00
|
|
|
|
2008-10-13 21:56:31 +08:00
|
|
|
/* The BAR is 0, let's check if memory decoding is enabled on
|
|
|
|
* the bridge. If not, we consider it unassigned
|
|
|
|
*/
|
|
|
|
pci_read_config_word(dev, PCI_COMMAND, &command);
|
|
|
|
if ((command & PCI_COMMAND_MEMORY) == 0)
|
|
|
|
return 1;
|
2007-12-20 11:55:04 +08:00
|
|
|
|
2008-10-13 21:56:31 +08:00
|
|
|
/* Memory decoding is enabled and the BAR is 0. If any of the bridge
|
|
|
|
* resources covers that starting address (0 then it's good enough for
|
2013-05-06 11:40:40 +08:00
|
|
|
* us for memory space)
|
2008-10-13 21:56:31 +08:00
|
|
|
*/
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
if ((hose->mem_resources[i].flags & IORESOURCE_MEM) &&
|
2013-05-06 11:40:40 +08:00
|
|
|
hose->mem_resources[i].start == hose->mem_offset[i])
|
2008-10-13 21:56:31 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Well, it starts at 0 and we know it will collide so we may as
|
|
|
|
* well consider it as unassigned. That covers the Apple case.
|
|
|
|
*/
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
/* If the BAR is non-0, then we consider it assigned */
|
|
|
|
offset = (unsigned long)hose->io_base_virt - _IO_BASE;
|
|
|
|
if (((res->start - offset) & 0xfffffffful) != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Here, we are a bit different than memory as typically IO space
|
|
|
|
* starting at low addresses -is- valid. What we do instead if that
|
|
|
|
* we consider as unassigned anything that doesn't have IO enabled
|
|
|
|
* in the PCI command register, and that's it.
|
|
|
|
*/
|
|
|
|
pci_read_config_word(dev, PCI_COMMAND, &command);
|
|
|
|
if (command & PCI_COMMAND_IO)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* It's starting at 0 and IO is disabled in the bridge, consider
|
|
|
|
* it unassigned
|
|
|
|
*/
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fixup resources of a PCI<->PCI bridge */
|
2012-12-22 06:04:10 +08:00
|
|
|
static void pcibios_fixup_bridge(struct pci_bus *bus)
|
2008-10-13 21:56:31 +08:00
|
|
|
{
|
|
|
|
struct resource *res;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
struct pci_dev *dev = bus->self;
|
|
|
|
|
2010-02-24 01:24:31 +08:00
|
|
|
pci_bus_for_each_resource(bus, res, i) {
|
|
|
|
if (!res || !res->flags)
|
2008-10-13 21:56:31 +08:00
|
|
|
continue;
|
|
|
|
if (i >= 3 && bus->self->transparent)
|
|
|
|
continue;
|
|
|
|
|
2012-06-04 06:15:25 +08:00
|
|
|
/* If we're going to reassign everything, we can
|
|
|
|
* shrink the P2P resource to have size as being
|
|
|
|
* of 0 in order to save space.
|
2011-11-07 02:55:58 +08:00
|
|
|
*/
|
|
|
|
if (pci_has_flag(PCI_REASSIGN_ALL_RSRC)) {
|
|
|
|
res->flags |= IORESOURCE_UNSET;
|
|
|
|
res->start = 0;
|
2012-06-04 06:15:25 +08:00
|
|
|
res->end = -1;
|
2011-11-07 02:55:58 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-06-12 10:26:37 +08:00
|
|
|
pr_debug("PCI:%s Bus rsrc %d %pR\n", pci_name(dev), i, res);
|
2007-12-20 11:54:51 +08:00
|
|
|
|
2008-10-13 21:56:31 +08:00
|
|
|
/* Try to detect uninitialized P2P bridge resources,
|
|
|
|
* and clear them out so they get re-assigned later
|
|
|
|
*/
|
|
|
|
if (pcibios_uninitialized_bridge_resource(bus, res)) {
|
|
|
|
res->flags = 0;
|
|
|
|
pr_debug("PCI:%s (unassigned)\n", pci_name(dev));
|
2007-12-20 11:54:51 +08:00
|
|
|
}
|
|
|
|
}
|
2008-10-13 21:56:31 +08:00
|
|
|
}
|
|
|
|
|
2012-12-22 06:04:10 +08:00
|
|
|
void pcibios_setup_bus_self(struct pci_bus *bus)
|
2008-10-28 03:48:37 +08:00
|
|
|
{
|
2015-03-31 13:00:56 +08:00
|
|
|
struct pci_controller *phb;
|
|
|
|
|
2008-10-28 03:48:56 +08:00
|
|
|
/* Fix up the bus resources for P2P bridges */
|
2008-10-28 03:48:37 +08:00
|
|
|
if (bus->self != NULL)
|
|
|
|
pcibios_fixup_bridge(bus);
|
|
|
|
|
|
|
|
/* Platform specific bus fixups. This is currently only used
|
2008-10-28 03:48:56 +08:00
|
|
|
* by fsl_pci and I'm hoping to get rid of it at some point
|
2008-10-28 03:48:37 +08:00
|
|
|
*/
|
|
|
|
if (ppc_md.pcibios_fixup_bus)
|
|
|
|
ppc_md.pcibios_fixup_bus(bus);
|
|
|
|
|
|
|
|
/* Setup bus DMA mappings */
|
2015-03-31 13:00:56 +08:00
|
|
|
phb = pci_bus_to_host(bus);
|
|
|
|
if (phb->controller_ops.dma_bus_setup)
|
|
|
|
phb->controller_ops.dma_bus_setup(bus);
|
2008-10-28 03:48:37 +08:00
|
|
|
}
|
|
|
|
|
powerpc/pci: Improve device hotplug initialization
Commit 37f02195b (powerpc/pci: fix PCI-e devices rescan issue on powerpc
platform) fixes a problem with interrupt and DMA initialization on hot
plugged devices. With this commit, interrupt and DMA initialization for
hot plugged devices is handled in the pci device enable function.
This approach has a couple of drawbacks. First, it creates two code paths
for device initialization, one for hot plugged devices and another for devices
known during the initial PCI scan. Second, the initialization code for hot
plugged devices is only called when the device is enabled, ie typically
in the probe function. Also, the platform specific setup code is called each
time pci_enable_device() is called, not only once during device discovery,
meaning it is actually called multiple times, once for devices discovered
during the initial scan and again each time a driver is re-loaded.
The visible result is that interrupt pins are only assigned to hot plugged
devices when the device driver is loaded. Effectively this changes the PCI
probe API, since pci_dev->irq and the device's dma configuration will now
only be valid after pci_enable() was called at least once. A more subtle
change is that platform specific PCI device setup is moved from device
discovery into the driver's probe function, more specifically into the
pci_enable_device() call.
To fix the inconsistencies, add new function pcibios_add_device.
Call pcibios_setup_device from pcibios_setup_bus_devices if device setup
is not complete, and from pcibios_add_device if bus setup is complete.
With this change, device setup code is moved back into device initialization,
and called exactly once for both static and hot plugged devices.
[ This also fixes a regression introduced by the above patch which
causes dev->irq to be overwritten under some cirumstances after
MSIs have been enabled for the device which leads to crashes due
to the MSI core "hijacking" dev->irq to store the base MSI number
and not the LSI. --BenH
]
Cc: Yuanquan Chen <Yuanquan.Chen@freescale.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Hiroo Matsumoto <matsumoto.hiroo@jp.fujitsu.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-06-11 01:18:08 +08:00
|
|
|
static void pcibios_setup_device(struct pci_dev *dev)
|
2013-04-02 09:26:54 +08:00
|
|
|
{
|
2015-03-31 13:00:56 +08:00
|
|
|
struct pci_controller *phb;
|
2013-04-02 09:26:54 +08:00
|
|
|
/* Fixup NUMA node as it may not be setup yet by the generic
|
|
|
|
* code and is needed by the DMA init
|
|
|
|
*/
|
|
|
|
set_dev_node(&dev->dev, pcibus_to_node(dev->bus));
|
|
|
|
|
|
|
|
/* Hook up default DMA ops */
|
|
|
|
set_dma_ops(&dev->dev, pci_dma_ops);
|
|
|
|
set_dma_offset(&dev->dev, PCI_DRAM_OFFSET);
|
|
|
|
|
|
|
|
/* Additional platform DMA/iommu setup */
|
2015-03-31 13:00:56 +08:00
|
|
|
phb = pci_bus_to_host(dev->bus);
|
|
|
|
if (phb->controller_ops.dma_dev_setup)
|
|
|
|
phb->controller_ops.dma_dev_setup(dev);
|
2013-04-02 09:26:54 +08:00
|
|
|
|
|
|
|
/* Read default IRQs and fixup if necessary */
|
|
|
|
pci_read_irq_line(dev);
|
|
|
|
if (ppc_md.pci_irq_fixup)
|
|
|
|
ppc_md.pci_irq_fixup(dev);
|
|
|
|
}
|
|
|
|
|
powerpc/pci: Improve device hotplug initialization
Commit 37f02195b (powerpc/pci: fix PCI-e devices rescan issue on powerpc
platform) fixes a problem with interrupt and DMA initialization on hot
plugged devices. With this commit, interrupt and DMA initialization for
hot plugged devices is handled in the pci device enable function.
This approach has a couple of drawbacks. First, it creates two code paths
for device initialization, one for hot plugged devices and another for devices
known during the initial PCI scan. Second, the initialization code for hot
plugged devices is only called when the device is enabled, ie typically
in the probe function. Also, the platform specific setup code is called each
time pci_enable_device() is called, not only once during device discovery,
meaning it is actually called multiple times, once for devices discovered
during the initial scan and again each time a driver is re-loaded.
The visible result is that interrupt pins are only assigned to hot plugged
devices when the device driver is loaded. Effectively this changes the PCI
probe API, since pci_dev->irq and the device's dma configuration will now
only be valid after pci_enable() was called at least once. A more subtle
change is that platform specific PCI device setup is moved from device
discovery into the driver's probe function, more specifically into the
pci_enable_device() call.
To fix the inconsistencies, add new function pcibios_add_device.
Call pcibios_setup_device from pcibios_setup_bus_devices if device setup
is not complete, and from pcibios_add_device if bus setup is complete.
With this change, device setup code is moved back into device initialization,
and called exactly once for both static and hot plugged devices.
[ This also fixes a regression introduced by the above patch which
causes dev->irq to be overwritten under some cirumstances after
MSIs have been enabled for the device which leads to crashes due
to the MSI core "hijacking" dev->irq to store the base MSI number
and not the LSI. --BenH
]
Cc: Yuanquan Chen <Yuanquan.Chen@freescale.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Hiroo Matsumoto <matsumoto.hiroo@jp.fujitsu.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-06-11 01:18:08 +08:00
|
|
|
int pcibios_add_device(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We can only call pcibios_setup_device() after bus setup is complete,
|
|
|
|
* since some of the platform specific DMA setup code depends on it.
|
|
|
|
*/
|
|
|
|
if (dev->bus->is_added)
|
|
|
|
pcibios_setup_device(dev);
|
2015-03-25 16:23:55 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_PCI_IOV
|
|
|
|
if (ppc_md.pcibios_fixup_sriov)
|
|
|
|
ppc_md.pcibios_fixup_sriov(dev);
|
|
|
|
#endif /* CONFIG_PCI_IOV */
|
|
|
|
|
powerpc/pci: Improve device hotplug initialization
Commit 37f02195b (powerpc/pci: fix PCI-e devices rescan issue on powerpc
platform) fixes a problem with interrupt and DMA initialization on hot
plugged devices. With this commit, interrupt and DMA initialization for
hot plugged devices is handled in the pci device enable function.
This approach has a couple of drawbacks. First, it creates two code paths
for device initialization, one for hot plugged devices and another for devices
known during the initial PCI scan. Second, the initialization code for hot
plugged devices is only called when the device is enabled, ie typically
in the probe function. Also, the platform specific setup code is called each
time pci_enable_device() is called, not only once during device discovery,
meaning it is actually called multiple times, once for devices discovered
during the initial scan and again each time a driver is re-loaded.
The visible result is that interrupt pins are only assigned to hot plugged
devices when the device driver is loaded. Effectively this changes the PCI
probe API, since pci_dev->irq and the device's dma configuration will now
only be valid after pci_enable() was called at least once. A more subtle
change is that platform specific PCI device setup is moved from device
discovery into the driver's probe function, more specifically into the
pci_enable_device() call.
To fix the inconsistencies, add new function pcibios_add_device.
Call pcibios_setup_device from pcibios_setup_bus_devices if device setup
is not complete, and from pcibios_add_device if bus setup is complete.
With this change, device setup code is moved back into device initialization,
and called exactly once for both static and hot plugged devices.
[ This also fixes a regression introduced by the above patch which
causes dev->irq to be overwritten under some cirumstances after
MSIs have been enabled for the device which leads to crashes due
to the MSI core "hijacking" dev->irq to store the base MSI number
and not the LSI. --BenH
]
Cc: Yuanquan Chen <Yuanquan.Chen@freescale.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Hiroo Matsumoto <matsumoto.hiroo@jp.fujitsu.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-06-11 01:18:08 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-22 06:04:10 +08:00
|
|
|
void pcibios_setup_bus_devices(struct pci_bus *bus)
|
2008-10-28 03:48:56 +08:00
|
|
|
{
|
|
|
|
struct pci_dev *dev;
|
|
|
|
|
|
|
|
pr_debug("PCI: Fixup bus devices %d (%s)\n",
|
|
|
|
bus->number, bus->self ? pci_name(bus->self) : "PHB");
|
|
|
|
|
|
|
|
list_for_each_entry(dev, &bus->devices, bus_list) {
|
2009-12-09 14:52:13 +08:00
|
|
|
/* Cardbus can call us to add new devices to a bus, so ignore
|
|
|
|
* those who are already fully discovered
|
|
|
|
*/
|
|
|
|
if (dev->is_added)
|
|
|
|
continue;
|
|
|
|
|
2013-04-02 09:26:54 +08:00
|
|
|
pcibios_setup_device(dev);
|
2008-10-28 03:48:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-29 05:48:03 +08:00
|
|
|
void pcibios_set_master(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
/* No special bus mastering setup handling */
|
|
|
|
}
|
|
|
|
|
2012-12-22 06:04:10 +08:00
|
|
|
void pcibios_fixup_bus(struct pci_bus *bus)
|
2007-12-20 11:54:51 +08:00
|
|
|
{
|
PCI: Revert "PCI: Call pci_read_bridge_bases() from core instead of arch code"
Revert dff22d2054b5 ("PCI: Call pci_read_bridge_bases() from core instead
of arch code").
Reading PCI bridge windows is not arch-specific in itself, but there is PCI
core code that doesn't work correctly if we read them too early. For
example, Hannes found this case on an ARM Freescale i.mx6 board:
pci_bus 0000:00: root bus resource [mem 0x01000000-0x01efffff]
pci 0000:00:00.0: PCI bridge to [bus 01-ff]
pci 0000:00:00.0: BAR 8: no space for [mem size 0x01000000] (mem window)
pci 0000:01:00.0: BAR 2: failed to assign [mem size 0x00200000]
pci 0000:01:00.0: BAR 1: failed to assign [mem size 0x00004000]
pci 0000:01:00.0: BAR 0: failed to assign [mem size 0x00000100]
The 00:00.0 mem window needs to be at least 3MB: the 01:00.0 device needs
0x204100 of space, and mem windows are megabyte-aligned.
Bus sizing can increase a bridge window size, but never *decrease* it (see
d65245c3297a ("PCI: don't shrink bridge resources")). Prior to
dff22d2054b5, ARM didn't read bridge windows at all, so the "original size"
was zero, and we assigned a 3MB window.
After dff22d2054b5, we read the bridge windows before sizing the bus. The
firmware programmed a 16MB window (size 0x01000000) in 00:00.0, and since
we never decrease the size, we kept 16MB even though we only needed 3MB.
But 16MB doesn't fit in the host bridge aperture, so we failed to assign
space for the window and the downstream devices.
I think this is a defect in the PCI core: we shouldn't rely on the firmware
to assign sensible windows.
Ray reported a similar problem, also on ARM, with Broadcom iProc.
Issues like this are too hard to fix right now, so revert dff22d2054b5.
Reported-by: Hannes <oe5hpm@gmail.com>
Reported-by: Ray Jui <rjui@broadcom.com>
Link: http://lkml.kernel.org/r/CAAa04yFQEUJm7Jj1qMT57-LG7ZGtnhNDBe=PpSRa70Mj+XhW-A@mail.gmail.com
Link: http://lkml.kernel.org/r/55F75BB8.4070405@broadcom.com
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
2015-09-16 02:18:04 +08:00
|
|
|
/* When called from the generic PCI probe, read PCI<->PCI bridge
|
|
|
|
* bases. This is -not- called when generating the PCI tree from
|
|
|
|
* the OF device-tree.
|
|
|
|
*/
|
|
|
|
pci_read_bridge_bases(bus);
|
|
|
|
|
|
|
|
/* Now fixup the bus bus */
|
2008-10-28 03:48:37 +08:00
|
|
|
pcibios_setup_bus_self(bus);
|
|
|
|
|
|
|
|
/* Now fixup devices on that bus */
|
|
|
|
pcibios_setup_bus_devices(bus);
|
2007-12-20 11:54:51 +08:00
|
|
|
}
|
2008-10-28 03:48:37 +08:00
|
|
|
EXPORT_SYMBOL(pcibios_fixup_bus);
|
2007-12-20 11:54:53 +08:00
|
|
|
|
2012-12-22 06:04:10 +08:00
|
|
|
void pci_fixup_cardbus(struct pci_bus *bus)
|
2009-12-09 14:52:13 +08:00
|
|
|
{
|
|
|
|
/* Now fixup devices on that bus */
|
|
|
|
pcibios_setup_bus_devices(bus);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-20 11:54:53 +08:00
|
|
|
static int skip_isa_ioresource_align(struct pci_dev *dev)
|
|
|
|
{
|
2011-07-12 22:25:51 +08:00
|
|
|
if (pci_has_flag(PCI_CAN_SKIP_ISA_ALIGN) &&
|
2007-12-20 11:54:53 +08:00
|
|
|
!(dev->bus->bridge_ctl & PCI_BRIDGE_CTL_ISA))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to avoid collisions with `mirrored' VGA ports
|
|
|
|
* and other strange ISA hardware, so we always want the
|
|
|
|
* addresses to be allocated in the 0x000-0x0ff region
|
|
|
|
* modulo 0x400.
|
|
|
|
*
|
|
|
|
* Why? Because some silly external IO cards only decode
|
|
|
|
* the low 10 bits of the IO address. The 0x00-0xff region
|
|
|
|
* is reserved for motherboard devices that decode all 16
|
|
|
|
* bits, so it's ok to allocate at, say, 0x2800-0x28ff,
|
|
|
|
* but we want to try to avoid allocating at 0x2900-0x2bff
|
|
|
|
* which might have be mirrored at 0x0100-0x03ff..
|
|
|
|
*/
|
2010-01-02 00:40:50 +08:00
|
|
|
resource_size_t pcibios_align_resource(void *data, const struct resource *res,
|
2007-12-20 11:54:53 +08:00
|
|
|
resource_size_t size, resource_size_t align)
|
|
|
|
{
|
|
|
|
struct pci_dev *dev = data;
|
2010-01-02 00:40:49 +08:00
|
|
|
resource_size_t start = res->start;
|
2007-12-20 11:54:53 +08:00
|
|
|
|
|
|
|
if (res->flags & IORESOURCE_IO) {
|
|
|
|
if (skip_isa_ioresource_align(dev))
|
2010-01-02 00:40:49 +08:00
|
|
|
return start;
|
|
|
|
if (start & 0x300)
|
2007-12-20 11:54:53 +08:00
|
|
|
start = (start + 0x3ff) & ~0x3ff;
|
|
|
|
}
|
2010-01-02 00:40:49 +08:00
|
|
|
|
|
|
|
return start;
|
2007-12-20 11:54:53 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(pcibios_align_resource);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reparent resource children of pr that conflict with res
|
|
|
|
* under res, and make res replace those children.
|
|
|
|
*/
|
2009-09-24 10:45:14 +08:00
|
|
|
static int reparent_resources(struct resource *parent,
|
2007-12-20 11:54:53 +08:00
|
|
|
struct resource *res)
|
|
|
|
{
|
|
|
|
struct resource *p, **pp;
|
|
|
|
struct resource **firstpp = NULL;
|
|
|
|
|
|
|
|
for (pp = &parent->child; (p = *pp) != NULL; pp = &p->sibling) {
|
|
|
|
if (p->end < res->start)
|
|
|
|
continue;
|
|
|
|
if (res->end < p->start)
|
|
|
|
break;
|
|
|
|
if (p->start < res->start || p->end > res->end)
|
|
|
|
return -1; /* not completely contained */
|
|
|
|
if (firstpp == NULL)
|
|
|
|
firstpp = pp;
|
|
|
|
}
|
|
|
|
if (firstpp == NULL)
|
|
|
|
return -1; /* didn't find any conflicting entries? */
|
|
|
|
res->parent = parent;
|
|
|
|
res->child = *firstpp;
|
|
|
|
res->sibling = *pp;
|
|
|
|
*firstpp = res;
|
|
|
|
*pp = NULL;
|
|
|
|
for (p = res->child; p != NULL; p = p->sibling) {
|
|
|
|
p->parent = res;
|
2015-06-12 10:26:37 +08:00
|
|
|
pr_debug("PCI: Reparented %s %pR under %s\n",
|
|
|
|
p->name, p, res->name);
|
2007-12-20 11:54:53 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle resources of PCI devices. If the world were perfect, we could
|
|
|
|
* just allocate all the resource regions and do nothing more. It isn't.
|
|
|
|
* On the other hand, we cannot just re-allocate all devices, as it would
|
|
|
|
* require us to know lots of host bridge internals. So we attempt to
|
|
|
|
* keep as much of the original configuration as possible, but tweak it
|
|
|
|
* when it's found to be wrong.
|
|
|
|
*
|
|
|
|
* Known BIOS problems we have to work around:
|
|
|
|
* - I/O or memory regions not configured
|
|
|
|
* - regions configured, but not enabled in the command register
|
|
|
|
* - bogus I/O addresses above 64K used
|
|
|
|
* - expansion ROMs left enabled (this may sound harmless, but given
|
|
|
|
* the fact the PCI specs explicitly allow address decoders to be
|
|
|
|
* shared between expansion ROMs and other resource regions, it's
|
|
|
|
* at least dangerous)
|
|
|
|
*
|
|
|
|
* Our solution:
|
|
|
|
* (1) Allocate resources for all buses behind PCI-to-PCI bridges.
|
|
|
|
* This gives us fixed barriers on where we can allocate.
|
|
|
|
* (2) Allocate resources for all enabled devices. If there is
|
|
|
|
* a collision, just mark the resource as unallocated. Also
|
|
|
|
* disable expansion ROMs during this step.
|
|
|
|
* (3) Try to allocate resources for disabled devices. If the
|
|
|
|
* resources were assigned correctly, everything goes well,
|
|
|
|
* if they weren't, they won't disturb allocation of other
|
|
|
|
* resources.
|
|
|
|
* (4) Assign new addresses to resources which were either
|
|
|
|
* not configured at all or misconfigured. If explicitly
|
|
|
|
* requested by the user, configure expansion ROM address
|
|
|
|
* as well.
|
|
|
|
*/
|
|
|
|
|
2014-08-20 06:55:18 +08:00
|
|
|
static void pcibios_allocate_bus_resources(struct pci_bus *bus)
|
2007-12-20 11:54:53 +08:00
|
|
|
{
|
2008-10-28 03:48:17 +08:00
|
|
|
struct pci_bus *b;
|
2007-12-20 11:54:53 +08:00
|
|
|
int i;
|
|
|
|
struct resource *res, *pr;
|
|
|
|
|
2008-10-28 03:48:44 +08:00
|
|
|
pr_debug("PCI: Allocating bus resources for %04x:%02x...\n",
|
|
|
|
pci_domain_nr(bus), bus->number);
|
|
|
|
|
2010-02-24 01:24:31 +08:00
|
|
|
pci_bus_for_each_resource(bus, res, i) {
|
|
|
|
if (!res || !res->flags || res->start > res->end || res->parent)
|
2008-10-28 03:48:17 +08:00
|
|
|
continue;
|
2011-11-07 02:55:58 +08:00
|
|
|
|
|
|
|
/* If the resource was left unset at this point, we clear it */
|
|
|
|
if (res->flags & IORESOURCE_UNSET)
|
|
|
|
goto clear_resource;
|
|
|
|
|
2008-10-28 03:48:17 +08:00
|
|
|
if (bus->parent == NULL)
|
|
|
|
pr = (res->flags & IORESOURCE_IO) ?
|
|
|
|
&ioport_resource : &iomem_resource;
|
|
|
|
else {
|
|
|
|
pr = pci_find_parent_resource(bus->self, res);
|
|
|
|
if (pr == res) {
|
|
|
|
/* this happens when the generic PCI
|
|
|
|
* code (wrongly) decides that this
|
|
|
|
* bridge is transparent -- paulus
|
2007-12-20 11:54:53 +08:00
|
|
|
*/
|
2008-10-28 03:48:17 +08:00
|
|
|
continue;
|
2007-12-20 11:54:53 +08:00
|
|
|
}
|
2008-10-28 03:48:17 +08:00
|
|
|
}
|
2007-12-20 11:54:53 +08:00
|
|
|
|
2015-06-12 10:26:37 +08:00
|
|
|
pr_debug("PCI: %s (bus %d) bridge rsrc %d: %pR, parent %p (%s)\n",
|
|
|
|
bus->self ? pci_name(bus->self) : "PHB", bus->number,
|
|
|
|
i, res, pr, (pr && pr->name) ? pr->name : "nil");
|
2008-10-28 03:48:17 +08:00
|
|
|
|
|
|
|
if (pr && !(pr->flags & IORESOURCE_UNSET)) {
|
2015-01-16 06:21:51 +08:00
|
|
|
struct pci_dev *dev = bus->self;
|
|
|
|
|
2008-10-28 03:48:17 +08:00
|
|
|
if (request_resource(pr, res) == 0)
|
|
|
|
continue;
|
|
|
|
/*
|
|
|
|
* Must be a conflict with an existing entry.
|
|
|
|
* Move that entry (or entries) under the
|
|
|
|
* bridge resource and try again.
|
|
|
|
*/
|
|
|
|
if (reparent_resources(pr, res) == 0)
|
|
|
|
continue;
|
2015-01-16 06:21:51 +08:00
|
|
|
|
|
|
|
if (dev && i < PCI_BRIDGE_RESOURCE_NUM &&
|
|
|
|
pci_claim_bridge_resource(dev,
|
|
|
|
i + PCI_BRIDGE_RESOURCES) == 0)
|
|
|
|
continue;
|
2007-12-20 11:54:53 +08:00
|
|
|
}
|
2011-11-07 02:55:58 +08:00
|
|
|
pr_warning("PCI: Cannot allocate resource region "
|
|
|
|
"%d of PCI bridge %d, will remap\n", i, bus->number);
|
|
|
|
clear_resource:
|
2012-06-04 06:15:25 +08:00
|
|
|
/* The resource might be figured out when doing
|
|
|
|
* reassignment based on the resources required
|
|
|
|
* by the downstream PCI devices. Here we set
|
|
|
|
* the size of the resource to be 0 in order to
|
|
|
|
* save more space.
|
|
|
|
*/
|
|
|
|
res->start = 0;
|
|
|
|
res->end = -1;
|
2008-10-28 03:48:17 +08:00
|
|
|
res->flags = 0;
|
2007-12-20 11:54:53 +08:00
|
|
|
}
|
2008-10-28 03:48:17 +08:00
|
|
|
|
|
|
|
list_for_each_entry(b, &bus->children, node)
|
|
|
|
pcibios_allocate_bus_resources(b);
|
2007-12-20 11:54:53 +08:00
|
|
|
}
|
|
|
|
|
2012-12-22 06:04:10 +08:00
|
|
|
static inline void alloc_resource(struct pci_dev *dev, int idx)
|
2007-12-20 11:54:53 +08:00
|
|
|
{
|
|
|
|
struct resource *pr, *r = &dev->resource[idx];
|
|
|
|
|
2015-06-12 10:26:37 +08:00
|
|
|
pr_debug("PCI: Allocating %s: Resource %d: %pR\n",
|
|
|
|
pci_name(dev), idx, r);
|
2007-12-20 11:54:53 +08:00
|
|
|
|
|
|
|
pr = pci_find_parent_resource(dev, r);
|
|
|
|
if (!pr || (pr->flags & IORESOURCE_UNSET) ||
|
|
|
|
request_resource(pr, r) < 0) {
|
|
|
|
printk(KERN_WARNING "PCI: Cannot allocate resource region %d"
|
|
|
|
" of device %s, will remap\n", idx, pci_name(dev));
|
|
|
|
if (pr)
|
2015-06-12 10:26:37 +08:00
|
|
|
pr_debug("PCI: parent is %p: %pR\n", pr, pr);
|
2007-12-20 11:54:53 +08:00
|
|
|
/* We'll assign a new address later */
|
|
|
|
r->flags |= IORESOURCE_UNSET;
|
|
|
|
r->end -= r->start;
|
|
|
|
r->start = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init pcibios_allocate_resources(int pass)
|
|
|
|
{
|
|
|
|
struct pci_dev *dev = NULL;
|
|
|
|
int idx, disabled;
|
|
|
|
u16 command;
|
|
|
|
struct resource *r;
|
|
|
|
|
|
|
|
for_each_pci_dev(dev) {
|
|
|
|
pci_read_config_word(dev, PCI_COMMAND, &command);
|
2009-05-15 04:16:47 +08:00
|
|
|
for (idx = 0; idx <= PCI_ROM_RESOURCE; idx++) {
|
2007-12-20 11:54:53 +08:00
|
|
|
r = &dev->resource[idx];
|
|
|
|
if (r->parent) /* Already allocated */
|
|
|
|
continue;
|
|
|
|
if (!r->flags || (r->flags & IORESOURCE_UNSET))
|
|
|
|
continue; /* Not assigned at all */
|
2009-05-15 04:16:47 +08:00
|
|
|
/* We only allocate ROMs on pass 1 just in case they
|
|
|
|
* have been screwed up by firmware
|
|
|
|
*/
|
|
|
|
if (idx == PCI_ROM_RESOURCE )
|
|
|
|
disabled = 1;
|
2007-12-20 11:54:53 +08:00
|
|
|
if (r->flags & IORESOURCE_IO)
|
|
|
|
disabled = !(command & PCI_COMMAND_IO);
|
|
|
|
else
|
|
|
|
disabled = !(command & PCI_COMMAND_MEMORY);
|
2007-12-31 07:04:15 +08:00
|
|
|
if (pass == disabled)
|
|
|
|
alloc_resource(dev, idx);
|
2007-12-20 11:54:53 +08:00
|
|
|
}
|
|
|
|
if (pass)
|
|
|
|
continue;
|
|
|
|
r = &dev->resource[PCI_ROM_RESOURCE];
|
2009-05-15 04:16:47 +08:00
|
|
|
if (r->flags) {
|
2007-12-20 11:54:53 +08:00
|
|
|
/* Turn the ROM off, leave the resource region,
|
|
|
|
* but keep it unregistered.
|
|
|
|
*/
|
|
|
|
u32 reg;
|
|
|
|
pci_read_config_dword(dev, dev->rom_base_reg, ®);
|
2009-05-15 04:16:47 +08:00
|
|
|
if (reg & PCI_ROM_ADDRESS_ENABLE) {
|
|
|
|
pr_debug("PCI: Switching off ROM of %s\n",
|
|
|
|
pci_name(dev));
|
|
|
|
r->flags &= ~IORESOURCE_ROM_ENABLE;
|
|
|
|
pci_write_config_dword(dev, dev->rom_base_reg,
|
|
|
|
reg & ~PCI_ROM_ADDRESS_ENABLE);
|
|
|
|
}
|
2007-12-20 11:54:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-12 01:45:52 +08:00
|
|
|
static void __init pcibios_reserve_legacy_regions(struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
struct pci_controller *hose = pci_bus_to_host(bus);
|
|
|
|
resource_size_t offset;
|
|
|
|
struct resource *res, *pres;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
pr_debug("Reserving legacy ranges for domain %04x\n", pci_domain_nr(bus));
|
|
|
|
|
|
|
|
/* Check for IO */
|
|
|
|
if (!(hose->io_resource.flags & IORESOURCE_IO))
|
|
|
|
goto no_io;
|
|
|
|
offset = (unsigned long)hose->io_base_virt - _IO_BASE;
|
|
|
|
res = kzalloc(sizeof(struct resource), GFP_KERNEL);
|
|
|
|
BUG_ON(res == NULL);
|
|
|
|
res->name = "Legacy IO";
|
|
|
|
res->flags = IORESOURCE_IO;
|
|
|
|
res->start = offset;
|
|
|
|
res->end = (offset + 0xfff) & 0xfffffffful;
|
|
|
|
pr_debug("Candidate legacy IO: %pR\n", res);
|
|
|
|
if (request_resource(&hose->io_resource, res)) {
|
|
|
|
printk(KERN_DEBUG
|
|
|
|
"PCI %04x:%02x Cannot reserve Legacy IO %pR\n",
|
|
|
|
pci_domain_nr(bus), bus->number, res);
|
|
|
|
kfree(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
no_io:
|
|
|
|
/* Check for memory */
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
pres = &hose->mem_resources[i];
|
2013-05-06 11:40:40 +08:00
|
|
|
offset = hose->mem_offset[i];
|
2008-11-12 01:45:52 +08:00
|
|
|
if (!(pres->flags & IORESOURCE_MEM))
|
|
|
|
continue;
|
|
|
|
pr_debug("hose mem res: %pR\n", pres);
|
|
|
|
if ((pres->start - offset) <= 0xa0000 &&
|
|
|
|
(pres->end - offset) >= 0xbffff)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i >= 3)
|
|
|
|
return;
|
|
|
|
res = kzalloc(sizeof(struct resource), GFP_KERNEL);
|
|
|
|
BUG_ON(res == NULL);
|
|
|
|
res->name = "Legacy VGA memory";
|
|
|
|
res->flags = IORESOURCE_MEM;
|
|
|
|
res->start = 0xa0000 + offset;
|
|
|
|
res->end = 0xbffff + offset;
|
|
|
|
pr_debug("Candidate VGA memory: %pR\n", res);
|
|
|
|
if (request_resource(pres, res)) {
|
|
|
|
printk(KERN_DEBUG
|
|
|
|
"PCI %04x:%02x Cannot reserve VGA memory %pR\n",
|
|
|
|
pci_domain_nr(bus), bus->number, res);
|
|
|
|
kfree(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-20 11:54:53 +08:00
|
|
|
void __init pcibios_resource_survey(void)
|
|
|
|
{
|
2008-10-28 03:48:17 +08:00
|
|
|
struct pci_bus *b;
|
|
|
|
|
2011-11-07 02:55:58 +08:00
|
|
|
/* Allocate and assign resources */
|
2008-10-28 03:48:17 +08:00
|
|
|
list_for_each_entry(b, &pci_root_buses, node)
|
|
|
|
pcibios_allocate_bus_resources(b);
|
2016-07-08 14:37:18 +08:00
|
|
|
if (!pci_has_flag(PCI_REASSIGN_ALL_RSRC)) {
|
|
|
|
pcibios_allocate_resources(0);
|
|
|
|
pcibios_allocate_resources(1);
|
|
|
|
}
|
2007-12-20 11:54:53 +08:00
|
|
|
|
2008-11-12 01:45:52 +08:00
|
|
|
/* Before we start assigning unassigned resource, we try to reserve
|
|
|
|
* the low IO area and the VGA memory area if they intersect the
|
|
|
|
* bus available resources to avoid allocating things on top of them
|
|
|
|
*/
|
2011-07-12 22:25:51 +08:00
|
|
|
if (!pci_has_flag(PCI_PROBE_ONLY)) {
|
2008-11-12 01:45:52 +08:00
|
|
|
list_for_each_entry(b, &pci_root_buses, node)
|
|
|
|
pcibios_reserve_legacy_regions(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, if the platform didn't decide to blindly trust the firmware,
|
|
|
|
* we proceed to assigning things that were left unassigned
|
|
|
|
*/
|
2011-07-12 22:25:51 +08:00
|
|
|
if (!pci_has_flag(PCI_PROBE_ONLY)) {
|
2009-03-09 14:39:01 +08:00
|
|
|
pr_debug("PCI: Assigning unassigned resources...\n");
|
2007-12-20 11:54:53 +08:00
|
|
|
pci_assign_unassigned_resources();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call machine dependent fixup */
|
|
|
|
if (ppc_md.pcibios_fixup)
|
|
|
|
ppc_md.pcibios_fixup();
|
|
|
|
}
|
|
|
|
|
2008-10-28 03:48:52 +08:00
|
|
|
/* This is used by the PCI hotplug driver to allocate resource
|
2007-12-20 11:54:53 +08:00
|
|
|
* of newly plugged busses. We can try to consolidate with the
|
2008-10-28 03:48:52 +08:00
|
|
|
* rest of the code later, for now, keep it as-is as our main
|
|
|
|
* resource allocation function doesn't deal with sub-trees yet.
|
2007-12-20 11:54:53 +08:00
|
|
|
*/
|
2009-06-01 22:53:53 +08:00
|
|
|
void pcibios_claim_one_bus(struct pci_bus *bus)
|
2007-12-20 11:54:53 +08:00
|
|
|
{
|
|
|
|
struct pci_dev *dev;
|
|
|
|
struct pci_bus *child_bus;
|
|
|
|
|
|
|
|
list_for_each_entry(dev, &bus->devices, bus_list) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < PCI_NUM_RESOURCES; i++) {
|
|
|
|
struct resource *r = &dev->resource[i];
|
|
|
|
|
|
|
|
if (r->parent || !r->start || !r->flags)
|
|
|
|
continue;
|
2008-10-28 03:48:52 +08:00
|
|
|
|
2015-06-12 10:26:37 +08:00
|
|
|
pr_debug("PCI: Claiming %s: Resource %d: %pR\n",
|
|
|
|
pci_name(dev), i, r);
|
2008-10-28 03:48:52 +08:00
|
|
|
|
2015-01-16 06:21:51 +08:00
|
|
|
if (pci_claim_resource(dev, i) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pci_claim_bridge_resource(dev, i);
|
2007-12-20 11:54:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry(child_bus, &bus->children, node)
|
|
|
|
pcibios_claim_one_bus(child_bus);
|
|
|
|
}
|
2015-05-27 14:06:56 +08:00
|
|
|
EXPORT_SYMBOL_GPL(pcibios_claim_one_bus);
|
2008-10-28 03:48:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* pcibios_finish_adding_to_bus
|
|
|
|
*
|
|
|
|
* This is to be called by the hotplug code after devices have been
|
|
|
|
* added to a bus, this include calling it for a PHB that is just
|
|
|
|
* being added
|
|
|
|
*/
|
|
|
|
void pcibios_finish_adding_to_bus(struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
pr_debug("PCI: Finishing adding to hotplug bus %04x:%02x\n",
|
|
|
|
pci_domain_nr(bus), bus->number);
|
|
|
|
|
|
|
|
/* Allocate bus and devices resources */
|
|
|
|
pcibios_allocate_bus_resources(bus);
|
|
|
|
pcibios_claim_one_bus(bus);
|
2016-05-20 14:41:36 +08:00
|
|
|
if (!pci_has_flag(PCI_PROBE_ONLY)) {
|
|
|
|
if (bus->self)
|
|
|
|
pci_assign_unassigned_bridge_resources(bus->self);
|
|
|
|
else
|
|
|
|
pci_assign_unassigned_bus_resources(bus);
|
|
|
|
}
|
2008-10-28 03:48:52 +08:00
|
|
|
|
2012-12-28 17:13:19 +08:00
|
|
|
/* Fixup EEH */
|
|
|
|
eeh_add_device_tree_late(bus);
|
|
|
|
|
2008-10-28 03:48:52 +08:00
|
|
|
/* Add new devices to global lists. Register in proc, sysfs. */
|
|
|
|
pci_bus_add_devices(bus);
|
|
|
|
|
2012-12-28 17:13:19 +08:00
|
|
|
/* sysfs files should only be added after devices are added */
|
|
|
|
eeh_add_sysfs_files(bus);
|
2008-10-28 03:48:52 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pcibios_finish_adding_to_bus);
|
|
|
|
|
2007-12-20 11:54:57 +08:00
|
|
|
int pcibios_enable_device(struct pci_dev *dev, int mask)
|
|
|
|
{
|
2015-03-31 13:00:56 +08:00
|
|
|
struct pci_controller *phb = pci_bus_to_host(dev->bus);
|
|
|
|
|
|
|
|
if (phb->controller_ops.enable_device_hook)
|
|
|
|
if (!phb->controller_ops.enable_device_hook(dev))
|
|
|
|
return -EINVAL;
|
2007-12-20 11:54:57 +08:00
|
|
|
|
2008-03-05 02:56:56 +08:00
|
|
|
return pci_enable_resources(dev, mask);
|
2007-12-20 11:54:57 +08:00
|
|
|
}
|
2008-10-28 03:48:29 +08:00
|
|
|
|
2015-05-27 14:07:00 +08:00
|
|
|
void pcibios_disable_device(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
struct pci_controller *phb = pci_bus_to_host(dev->bus);
|
|
|
|
|
|
|
|
if (phb->controller_ops.disable_device)
|
|
|
|
phb->controller_ops.disable_device(dev);
|
|
|
|
}
|
|
|
|
|
2012-03-17 07:48:09 +08:00
|
|
|
resource_size_t pcibios_io_space_offset(struct pci_controller *hose)
|
|
|
|
{
|
|
|
|
return (unsigned long) hose->io_base_virt - _IO_BASE;
|
|
|
|
}
|
|
|
|
|
2012-12-22 06:04:10 +08:00
|
|
|
static void pcibios_setup_phb_resources(struct pci_controller *hose,
|
|
|
|
struct list_head *resources)
|
2008-10-28 03:48:29 +08:00
|
|
|
{
|
|
|
|
struct resource *res;
|
2013-05-06 11:40:40 +08:00
|
|
|
resource_size_t offset;
|
2008-10-28 03:48:29 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Hookup PHB IO resource */
|
2011-10-29 06:27:43 +08:00
|
|
|
res = &hose->io_resource;
|
2008-10-28 03:48:29 +08:00
|
|
|
|
|
|
|
if (!res->flags) {
|
2016-06-22 15:23:07 +08:00
|
|
|
pr_debug("PCI: I/O resource not set for host"
|
2017-08-21 23:16:47 +08:00
|
|
|
" bridge %pOF (domain %d)\n",
|
|
|
|
hose->dn, hose->global_number);
|
2013-05-06 11:40:40 +08:00
|
|
|
} else {
|
|
|
|
offset = pcibios_io_space_offset(hose);
|
|
|
|
|
2015-06-12 10:26:37 +08:00
|
|
|
pr_debug("PCI: PHB IO resource = %pR off 0x%08llx\n",
|
|
|
|
res, (unsigned long long)offset);
|
2013-05-06 11:40:40 +08:00
|
|
|
pci_add_resource_offset(resources, res, offset);
|
2013-05-04 22:22:57 +08:00
|
|
|
}
|
2008-10-28 03:48:29 +08:00
|
|
|
|
|
|
|
/* Hookup PHB Memory resources */
|
|
|
|
for (i = 0; i < 3; ++i) {
|
|
|
|
res = &hose->mem_resources[i];
|
2017-02-08 11:11:03 +08:00
|
|
|
if (!res->flags)
|
2013-05-06 11:40:40 +08:00
|
|
|
continue;
|
|
|
|
|
2017-02-08 11:11:03 +08:00
|
|
|
offset = hose->mem_offset[i];
|
2015-06-12 10:26:37 +08:00
|
|
|
pr_debug("PCI: PHB MEM resource %d = %pR off 0x%08llx\n", i,
|
|
|
|
res, (unsigned long long)offset);
|
2013-05-06 11:40:40 +08:00
|
|
|
|
|
|
|
pci_add_resource_offset(resources, res, offset);
|
|
|
|
}
|
2008-10-28 03:48:29 +08:00
|
|
|
}
|
2009-08-26 00:20:45 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Null PCI config access functions, for the case when we can't
|
|
|
|
* find a hose.
|
|
|
|
*/
|
|
|
|
#define NULL_PCI_OP(rw, size, type) \
|
|
|
|
static int \
|
|
|
|
null_##rw##_config_##size(struct pci_dev *dev, int offset, type val) \
|
|
|
|
{ \
|
|
|
|
return PCIBIOS_DEVICE_NOT_FOUND; \
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
null_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
|
|
|
|
int len, u32 *val)
|
|
|
|
{
|
|
|
|
return PCIBIOS_DEVICE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
null_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
|
|
|
|
int len, u32 val)
|
|
|
|
{
|
|
|
|
return PCIBIOS_DEVICE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct pci_ops null_pci_ops =
|
|
|
|
{
|
|
|
|
.read = null_read_config,
|
|
|
|
.write = null_write_config,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These functions are used early on before PCI scanning is done
|
|
|
|
* and all of the pci_dev and pci_bus structures have been created.
|
|
|
|
*/
|
|
|
|
static struct pci_bus *
|
|
|
|
fake_pci_bus(struct pci_controller *hose, int busnr)
|
|
|
|
{
|
|
|
|
static struct pci_bus bus;
|
|
|
|
|
2013-08-07 00:01:24 +08:00
|
|
|
if (hose == NULL) {
|
2009-08-26 00:20:45 +08:00
|
|
|
printk(KERN_ERR "Can't find hose for PCI bus %d!\n", busnr);
|
|
|
|
}
|
|
|
|
bus.number = busnr;
|
|
|
|
bus.sysdata = hose;
|
|
|
|
bus.ops = hose? hose->ops: &null_pci_ops;
|
|
|
|
return &bus;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define EARLY_PCI_OP(rw, size, type) \
|
|
|
|
int early_##rw##_config_##size(struct pci_controller *hose, int bus, \
|
|
|
|
int devfn, int offset, type value) \
|
|
|
|
{ \
|
|
|
|
return pci_bus_##rw##_config_##size(fake_pci_bus(hose, bus), \
|
|
|
|
devfn, offset, value); \
|
|
|
|
}
|
|
|
|
|
|
|
|
EARLY_PCI_OP(read, byte, u8 *)
|
|
|
|
EARLY_PCI_OP(read, word, u16 *)
|
|
|
|
EARLY_PCI_OP(read, dword, u32 *)
|
|
|
|
EARLY_PCI_OP(write, byte, u8)
|
|
|
|
EARLY_PCI_OP(write, word, u16)
|
|
|
|
EARLY_PCI_OP(write, dword, u32)
|
|
|
|
|
|
|
|
int early_find_capability(struct pci_controller *hose, int bus, int devfn,
|
|
|
|
int cap)
|
|
|
|
{
|
|
|
|
return pci_bus_find_capability(fake_pci_bus(hose, bus), devfn, cap);
|
|
|
|
}
|
2009-08-28 16:58:16 +08:00
|
|
|
|
2011-04-11 09:37:07 +08:00
|
|
|
struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
struct pci_controller *hose = bus->sysdata;
|
|
|
|
|
|
|
|
return of_node_get(hose->dn);
|
|
|
|
}
|
|
|
|
|
2009-08-28 16:58:16 +08:00
|
|
|
/**
|
|
|
|
* pci_scan_phb - Given a pci_controller, setup and scan the PCI bus
|
|
|
|
* @hose: Pointer to the PCI host controller instance structure
|
|
|
|
*/
|
2012-12-22 06:04:10 +08:00
|
|
|
void pcibios_scan_phb(struct pci_controller *hose)
|
2009-08-28 16:58:16 +08:00
|
|
|
{
|
2011-10-29 06:27:43 +08:00
|
|
|
LIST_HEAD(resources);
|
2009-08-28 16:58:16 +08:00
|
|
|
struct pci_bus *bus;
|
|
|
|
struct device_node *node = hose->dn;
|
|
|
|
int mode;
|
|
|
|
|
2017-08-21 23:16:47 +08:00
|
|
|
pr_debug("PCI: Scanning PHB %pOF\n", node);
|
2009-08-28 16:58:16 +08:00
|
|
|
|
2011-10-29 06:27:43 +08:00
|
|
|
/* Get some IO space for the new PHB */
|
|
|
|
pcibios_setup_phb_io_space(hose);
|
|
|
|
|
|
|
|
/* Wire up PHB bus resources */
|
|
|
|
pcibios_setup_phb_resources(hose, &resources);
|
|
|
|
|
2012-05-18 09:51:12 +08:00
|
|
|
hose->busn.start = hose->first_busno;
|
|
|
|
hose->busn.end = hose->last_busno;
|
|
|
|
hose->busn.flags = IORESOURCE_BUS;
|
|
|
|
pci_add_resource(&resources, &hose->busn);
|
|
|
|
|
2009-08-28 16:58:16 +08:00
|
|
|
/* Create an empty bus for the toplevel */
|
2011-10-29 06:27:43 +08:00
|
|
|
bus = pci_create_root_bus(hose->parent, hose->first_busno,
|
|
|
|
hose->ops, hose, &resources);
|
2009-08-28 16:58:16 +08:00
|
|
|
if (bus == NULL) {
|
|
|
|
pr_err("Failed to create bus for PCI domain %04x\n",
|
|
|
|
hose->global_number);
|
2011-10-29 06:27:43 +08:00
|
|
|
pci_free_resource_list(&resources);
|
2009-08-28 16:58:16 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
hose->bus = bus;
|
|
|
|
|
|
|
|
/* Get probe mode and perform scan */
|
|
|
|
mode = PCI_PROBE_NORMAL;
|
2015-03-31 13:00:56 +08:00
|
|
|
if (node && hose->controller_ops.probe_mode)
|
|
|
|
mode = hose->controller_ops.probe_mode(bus);
|
2009-08-28 16:58:16 +08:00
|
|
|
pr_debug(" probe mode: %d\n", mode);
|
2012-05-18 09:51:12 +08:00
|
|
|
if (mode == PCI_PROBE_DEVTREE)
|
2009-08-28 16:58:16 +08:00
|
|
|
of_scan_bus(node, bus);
|
|
|
|
|
2012-05-18 09:51:12 +08:00
|
|
|
if (mode == PCI_PROBE_NORMAL) {
|
|
|
|
pci_bus_update_busn_res_end(bus, 255);
|
|
|
|
hose->last_busno = pci_scan_child_bus(bus);
|
|
|
|
pci_bus_update_busn_res_end(bus, hose->last_busno);
|
|
|
|
}
|
2011-09-20 01:44:50 +08:00
|
|
|
|
2011-11-07 02:55:57 +08:00
|
|
|
/* Platform gets a chance to do some global fixups before
|
|
|
|
* we proceed to resource allocation
|
|
|
|
*/
|
|
|
|
if (ppc_md.pcibios_fixup_phb)
|
|
|
|
ppc_md.pcibios_fixup_phb(hose);
|
|
|
|
|
2011-09-20 01:44:50 +08:00
|
|
|
/* Configure PCI Express settings */
|
2011-09-26 12:22:39 +08:00
|
|
|
if (bus && !pci_has_flag(PCI_PROBE_ONLY)) {
|
2011-09-20 01:44:50 +08:00
|
|
|
struct pci_bus *child;
|
2013-08-22 11:24:44 +08:00
|
|
|
list_for_each_entry(child, &bus->children, node)
|
|
|
|
pcie_bus_configure_settings(child);
|
2011-09-20 01:44:50 +08:00
|
|
|
}
|
2009-08-28 16:58:16 +08:00
|
|
|
}
|
2015-05-27 14:06:56 +08:00
|
|
|
EXPORT_SYMBOL_GPL(pcibios_scan_phb);
|
2011-05-20 11:26:18 +08:00
|
|
|
|
|
|
|
static void fixup_hide_host_resource_fsl(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
int i, class = dev->class >> 8;
|
2011-10-28 16:08:00 +08:00
|
|
|
/* When configured as agent, programing interface = 1 */
|
|
|
|
int prog_if = dev->class & 0xf;
|
2011-05-20 11:26:18 +08:00
|
|
|
|
|
|
|
if ((class == PCI_CLASS_PROCESSOR_POWERPC ||
|
|
|
|
class == PCI_CLASS_BRIDGE_OTHER) &&
|
|
|
|
(dev->hdr_type == PCI_HEADER_TYPE_NORMAL) &&
|
2011-10-28 16:08:00 +08:00
|
|
|
(prog_if == 0) &&
|
2011-05-20 11:26:18 +08:00
|
|
|
(dev->bus->parent == NULL)) {
|
|
|
|
for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
|
|
|
|
dev->resource[i].start = 0;
|
|
|
|
dev->resource[i].end = 0;
|
|
|
|
dev->resource[i].flags = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MOTOROLA, PCI_ANY_ID, fixup_hide_host_resource_fsl);
|
|
|
|
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_FREESCALE, PCI_ANY_ID, fixup_hide_host_resource_fsl);
|