aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/testing/sysfs-bus-pci21
-rw-r--r--Documentation/DMA-API-HOWTO.txt210
-rw-r--r--Documentation/DMA-API.txt150
-rw-r--r--Documentation/DMA-ISA-LPC.txt4
-rw-r--r--Documentation/devicetree/bindings/pci/host-generic-pci.txt100
-rw-r--r--Documentation/devicetree/bindings/pci/pci-rcar-gen2.txt66
-rw-r--r--Documentation/devicetree/bindings/pci/rcar-pci.txt47
-rw-r--r--MAINTAINERS9
-rw-r--r--arch/alpha/include/asm/pci.h5
-rw-r--r--arch/arm/include/asm/pci.h5
-rw-r--r--arch/arm/kernel/bios32.c12
-rw-r--r--arch/blackfin/include/asm/pci.h5
-rw-r--r--arch/cris/include/asm/pci.h1
-rw-r--r--arch/frv/include/asm/pci.h2
-rw-r--r--arch/frv/mb93090-mb00/pci-irq.c4
-rw-r--r--arch/ia64/include/asm/pci.h6
-rw-r--r--arch/ia64/pci/fixup.c4
-rw-r--r--arch/microblaze/include/asm/pci.h5
-rw-r--r--arch/microblaze/pci/pci-common.c20
-rw-r--r--arch/mips/include/asm/pci.h5
-rw-r--r--arch/mn10300/include/asm/pci.h1
-rw-r--r--arch/mn10300/unit-asb2305/pci-irq.c4
-rw-r--r--arch/parisc/include/asm/pci.h5
-rw-r--r--arch/powerpc/include/asm/pci.h5
-rw-r--r--arch/powerpc/kernel/pci-common.c20
-rw-r--r--arch/powerpc/kernel/pci-hotplug.c3
-rw-r--r--arch/powerpc/kernel/pci_of_scan.c3
-rw-r--r--arch/s390/include/asm/pci.h6
-rw-r--r--arch/s390/pci/pci.c6
-rw-r--r--arch/s390/pci/pci_sysfs.c44
-rw-r--r--arch/sh/drivers/pci/fixups-dreamcast.c18
-rw-r--r--arch/sh/include/asm/pci.h5
-rw-r--r--arch/sparc/include/asm/pci_32.h5
-rw-r--r--arch/sparc/include/asm/pci_64.h5
-rw-r--r--arch/sparc/kernel/pci.c3
-rw-r--r--arch/unicore32/include/asm/pci.h5
-rw-r--r--arch/x86/include/asm/pci.h1
-rw-r--r--arch/x86/kernel/aperture_64.c59
-rw-r--r--arch/x86/pci/acpi.c6
-rw-r--r--arch/x86/pci/amd_bus.c83
-rw-r--r--arch/x86/pci/broadcom_bus.c4
-rw-r--r--arch/x86/pci/fixup.c18
-rw-r--r--arch/x86/pci/i386.c27
-rw-r--r--arch/xtensa/include/asm/pci.h5
-rw-r--r--drivers/base/dma-coherent.c10
-rw-r--r--drivers/base/dma-mapping.c6
-rw-r--r--drivers/block/nvme-core.c11
-rw-r--r--drivers/edac/i82875p_edac.c8
-rw-r--r--drivers/iommu/exynos-iommu.c14
-rw-r--r--drivers/misc/genwqe/card_utils.c2
-rw-r--r--drivers/pci/access.c12
-rw-r--r--drivers/pci/bus.c11
-rw-r--r--drivers/pci/host-bridge.c1
-rw-r--r--drivers/pci/host/Kconfig13
-rw-r--r--drivers/pci/host/Makefile2
-rw-r--r--drivers/pci/host/pci-exynos.c11
-rw-r--r--drivers/pci/host/pci-host-generic.c388
-rw-r--r--drivers/pci/host/pci-imx6.c147
-rw-r--r--drivers/pci/host/pci-rcar-gen2.c31
-rw-r--r--drivers/pci/host/pcie-designware.c6
-rw-r--r--drivers/pci/host/pcie-designware.h2
-rw-r--r--drivers/pci/host/pcie-rcar.c1008
-rw-r--r--drivers/pci/hotplug-pci.c2
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c6
-rw-r--r--drivers/pci/hotplug/cpci_hotplug_pci.c5
-rw-r--r--drivers/pci/hotplug/cpqphp_ctrl.c3
-rw-r--r--drivers/pci/hotplug/cpqphp_nvram.c1
-rw-r--r--drivers/pci/hotplug/pciehp.h2
-rw-r--r--drivers/pci/hotplug/pciehp_hpc.c2
-rw-r--r--drivers/pci/hotplug/pciehp_pci.c3
-rw-r--r--drivers/pci/hotplug/pcihp_slot.c3
-rw-r--r--drivers/pci/hotplug/rpadlpar_core.c3
-rw-r--r--drivers/pci/hotplug/rpaphp_core.c15
-rw-r--r--drivers/pci/hotplug/s390_pci_hpc.c1
-rw-r--r--drivers/pci/hotplug/shpchp_pci.c5
-rw-r--r--drivers/pci/iov.c2
-rw-r--r--drivers/pci/msi.c96
-rw-r--r--drivers/pci/pci-acpi.c8
-rw-r--r--drivers/pci/pci-driver.c58
-rw-r--r--drivers/pci/pci-sysfs.c68
-rw-r--r--drivers/pci/pci.c34
-rw-r--r--drivers/pci/pci.h10
-rw-r--r--drivers/pci/pcie/portdrv_core.c9
-rw-r--r--drivers/pci/probe.c101
-rw-r--r--drivers/pci/quirks.c11
-rw-r--r--drivers/pci/search.c1
-rw-r--r--drivers/pci/setup-bus.c251
-rw-r--r--drivers/pci/setup-irq.c1
-rw-r--r--drivers/pci/setup-res.c42
-rw-r--r--drivers/pcmcia/cardbus.c3
-rw-r--r--drivers/platform/x86/asus-wmi.c3
-rw-r--r--drivers/platform/x86/eeepc-laptop.c3
-rw-r--r--include/asm-generic/dma-coherent.h13
-rw-r--r--include/linux/dma-mapping.h13
-rw-r--r--include/linux/pci.h40
-rw-r--r--include/linux/pci_ids.h3
-rw-r--r--include/linux/types.h1
-rw-r--r--kernel/resource.c7
98 files changed, 2710 insertions, 824 deletions
diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci
index ab8d76dfaa80..6615fda0abfb 100644
--- a/Documentation/ABI/testing/sysfs-bus-pci
+++ b/Documentation/ABI/testing/sysfs-bus-pci
@@ -250,3 +250,24 @@ Description:
250 valid. For example, writing a 2 to this file when sriov_numvfs 250 valid. For example, writing a 2 to this file when sriov_numvfs
251 is not 0 and not 2 already will return an error. Writing a 10 251 is not 0 and not 2 already will return an error. Writing a 10
252 when the value of sriov_totalvfs is 8 will return an error. 252 when the value of sriov_totalvfs is 8 will return an error.
253
254What: /sys/bus/pci/devices/.../driver_override
255Date: April 2014
256Contact: Alex Williamson <alex.williamson@redhat.com>
257Description:
258 This file allows the driver for a device to be specified which
259 will override standard static and dynamic ID matching. When
260 specified, only a driver with a name matching the value written
261 to driver_override will have an opportunity to bind to the
262 device. The override is specified by writing a string to the
263 driver_override file (echo pci-stub > driver_override) and
264 may be cleared with an empty string (echo > driver_override).
265 This returns the device to standard matching rules binding.
266 Writing to driver_override does not automatically unbind the
267 device from its current driver or make any attempt to
268 automatically load the specified driver. If no driver with a
269 matching name is currently loaded in the kernel, the device
270 will not bind to any driver. This also allows devices to
271 opt-out of driver binding using a driver_override name such as
272 "none". Only a single driver may be specified in the override,
273 there is no support for parsing delimiters.
diff --git a/Documentation/DMA-API-HOWTO.txt b/Documentation/DMA-API-HOWTO.txt
index 5e983031cc11..dcbbe3602d78 100644
--- a/Documentation/DMA-API-HOWTO.txt
+++ b/Documentation/DMA-API-HOWTO.txt
@@ -9,16 +9,76 @@ This is a guide to device driver writers on how to use the DMA API
9with example pseudo-code. For a concise description of the API, see 9with example pseudo-code. For a concise description of the API, see
10DMA-API.txt. 10DMA-API.txt.
11 11
12Most of the 64bit platforms have special hardware that translates bus 12 CPU and DMA addresses
13addresses (DMA addresses) into physical addresses. This is similar to 13
14how page tables and/or a TLB translates virtual addresses to physical 14There are several kinds of addresses involved in the DMA API, and it's
15addresses on a CPU. This is needed so that e.g. PCI devices can 15important to understand the differences.
16access with a Single Address Cycle (32bit DMA address) any page in the 16
1764bit physical address space. Previously in Linux those 64bit 17The kernel normally uses virtual addresses. Any address returned by
18platforms had to set artificial limits on the maximum RAM size in the 18kmalloc(), vmalloc(), and similar interfaces is a virtual address and can
19system, so that the virt_to_bus() static scheme works (the DMA address 19be stored in a "void *".
20translation tables were simply filled on bootup to map each bus 20
21address to the physical page __pa(bus_to_virt())). 21The virtual memory system (TLB, page tables, etc.) translates virtual
22addresses to CPU physical addresses, which are stored as "phys_addr_t" or
23"resource_size_t". The kernel manages device resources like registers as
24physical addresses. These are the addresses in /proc/iomem. The physical
25address is not directly useful to a driver; it must use ioremap() to map
26the space and produce a virtual address.
27
28I/O devices use a third kind of address: a "bus address" or "DMA address".
29If a device has registers at an MMIO address, or if it performs DMA to read
30or write system memory, the addresses used by the device are bus addresses.
31In some systems, bus addresses are identical to CPU physical addresses, but
32in general they are not. IOMMUs and host bridges can produce arbitrary
33mappings between physical and bus addresses.
34
35Here's a picture and some examples:
36
37 CPU CPU Bus
38 Virtual Physical Address
39 Address Address Space
40 Space Space
41
42 +-------+ +------+ +------+
43 | | |MMIO | Offset | |
44 | | Virtual |Space | applied | |
45 C +-------+ --------> B +------+ ----------> +------+ A
46 | | mapping | | by host | |
47 +-----+ | | | | bridge | | +--------+
48 | | | | +------+ | | | |
49 | CPU | | | | RAM | | | | Device |
50 | | | | | | | | | |
51 +-----+ +-------+ +------+ +------+ +--------+
52 | | Virtual |Buffer| Mapping | |
53 X +-------+ --------> Y +------+ <---------- +------+ Z
54 | | mapping | RAM | by IOMMU
55 | | | |
56 | | | |
57 +-------+ +------+
58
59During the enumeration process, the kernel learns about I/O devices and
60their MMIO space and the host bridges that connect them to the system. For
61example, if a PCI device has a BAR, the kernel reads the bus address (A)
62from the BAR and converts it to a CPU physical address (B). The address B
63is stored in a struct resource and usually exposed via /proc/iomem. When a
64driver claims a device, it typically uses ioremap() to map physical address
65B at a virtual address (C). It can then use, e.g., ioread32(C), to access
66the device registers at bus address A.
67
68If the device supports DMA, the driver sets up a buffer using kmalloc() or
69a similar interface, which returns a virtual address (X). The virtual
70memory system maps X to a physical address (Y) in system RAM. The driver
71can use virtual address X to access the buffer, but the device itself
72cannot because DMA doesn't go through the CPU virtual memory system.
73
74In some simple systems, the device can do DMA directly to physical address
75Y. But in many others, there is IOMMU hardware that translates bus
76addresses to physical addresses, e.g., it translates Z to Y. This is part
77of the reason for the DMA API: the driver can give a virtual address X to
78an interface like dma_map_single(), which sets up any required IOMMU
79mapping and returns the bus address Z. The driver then tells the device to
80do DMA to Z, and the IOMMU maps it to the buffer at address Y in system
81RAM.
22 82
23So that Linux can use the dynamic DMA mapping, it needs some help from the 83So that Linux can use the dynamic DMA mapping, it needs some help from the
24drivers, namely it has to take into account that DMA addresses should be 84drivers, namely it has to take into account that DMA addresses should be
@@ -29,17 +89,17 @@ The following API will work of course even on platforms where no such
29hardware exists. 89hardware exists.
30 90
31Note that the DMA API works with any bus independent of the underlying 91Note that the DMA API works with any bus independent of the underlying
32microprocessor architecture. You should use the DMA API rather than 92microprocessor architecture. You should use the DMA API rather than the
33the bus specific DMA API (e.g. pci_dma_*). 93bus-specific DMA API, i.e., use the dma_map_*() interfaces rather than the
94pci_map_*() interfaces.
34 95
35First of all, you should make sure 96First of all, you should make sure
36 97
37#include <linux/dma-mapping.h> 98#include <linux/dma-mapping.h>
38 99
39is in your driver. This file will obtain for you the definition of the 100is in your driver, which provides the definition of dma_addr_t. This type
40dma_addr_t (which can hold any valid DMA address for the platform) 101can hold any valid DMA or bus address for the platform and should be used
41type which should be used everywhere you hold a DMA (bus) address 102everywhere you hold a DMA address returned from the DMA mapping functions.
42returned from the DMA mapping functions.
43 103
44 What memory is DMA'able? 104 What memory is DMA'able?
45 105
@@ -123,9 +183,9 @@ Here, dev is a pointer to the device struct of your device, and mask
123is a bit mask describing which bits of an address your device 183is a bit mask describing which bits of an address your device
124supports. It returns zero if your card can perform DMA properly on 184supports. It returns zero if your card can perform DMA properly on
125the machine given the address mask you provided. In general, the 185the machine given the address mask you provided. In general, the
126device struct of your device is embedded in the bus specific device 186device struct of your device is embedded in the bus-specific device
127struct of your device. For example, a pointer to the device struct of 187struct of your device. For example, &pdev->dev is a pointer to the
128your PCI device is pdev->dev (pdev is a pointer to the PCI device 188device struct of a PCI device (pdev is a pointer to the PCI device
129struct of your device). 189struct of your device).
130 190
131If it returns non-zero, your device cannot perform DMA properly on 191If it returns non-zero, your device cannot perform DMA properly on
@@ -147,8 +207,7 @@ exactly why.
147The standard 32-bit addressing device would do something like this: 207The standard 32-bit addressing device would do something like this:
148 208
149 if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32))) { 209 if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32))) {
150 printk(KERN_WARNING 210 dev_warn(dev, "mydev: No suitable DMA available\n");
151 "mydev: No suitable DMA available.\n");
152 goto ignore_this_device; 211 goto ignore_this_device;
153 } 212 }
154 213
@@ -170,8 +229,7 @@ all 64-bits when accessing streaming DMA:
170 } else if (!dma_set_mask(dev, DMA_BIT_MASK(32))) { 229 } else if (!dma_set_mask(dev, DMA_BIT_MASK(32))) {
171 using_dac = 0; 230 using_dac = 0;
172 } else { 231 } else {
173 printk(KERN_WARNING 232 dev_warn(dev, "mydev: No suitable DMA available\n");
174 "mydev: No suitable DMA available.\n");
175 goto ignore_this_device; 233 goto ignore_this_device;
176 } 234 }
177 235
@@ -187,22 +245,20 @@ the case would look like this:
187 using_dac = 0; 245 using_dac = 0;
188 consistent_using_dac = 0; 246 consistent_using_dac = 0;
189 } else { 247 } else {
190 printk(KERN_WARNING 248 dev_warn(dev, "mydev: No suitable DMA available\n");
191 "mydev: No suitable DMA available.\n");
192 goto ignore_this_device; 249 goto ignore_this_device;
193 } 250 }
194 251
195The coherent coherent mask will always be able to set the same or a 252The coherent mask will always be able to set the same or a smaller mask as
196smaller mask as the streaming mask. However for the rare case that a 253the streaming mask. However for the rare case that a device driver only
197device driver only uses consistent allocations, one would have to 254uses consistent allocations, one would have to check the return value from
198check the return value from dma_set_coherent_mask(). 255dma_set_coherent_mask().
199 256
200Finally, if your device can only drive the low 24-bits of 257Finally, if your device can only drive the low 24-bits of
201address you might do something like: 258address you might do something like:
202 259
203 if (dma_set_mask(dev, DMA_BIT_MASK(24))) { 260 if (dma_set_mask(dev, DMA_BIT_MASK(24))) {
204 printk(KERN_WARNING 261 dev_warn(dev, "mydev: 24-bit DMA addressing not available\n");
205 "mydev: 24-bit DMA addressing not available.\n");
206 goto ignore_this_device; 262 goto ignore_this_device;
207 } 263 }
208 264
@@ -232,14 +288,14 @@ Here is pseudo-code showing how this might be done:
232 card->playback_enabled = 1; 288 card->playback_enabled = 1;
233 } else { 289 } else {
234 card->playback_enabled = 0; 290 card->playback_enabled = 0;
235 printk(KERN_WARNING "%s: Playback disabled due to DMA limitations.\n", 291 dev_warn(dev, "%s: Playback disabled due to DMA limitations\n",
236 card->name); 292 card->name);
237 } 293 }
238 if (!dma_set_mask(dev, RECORD_ADDRESS_BITS)) { 294 if (!dma_set_mask(dev, RECORD_ADDRESS_BITS)) {
239 card->record_enabled = 1; 295 card->record_enabled = 1;
240 } else { 296 } else {
241 card->record_enabled = 0; 297 card->record_enabled = 0;
242 printk(KERN_WARNING "%s: Record disabled due to DMA limitations.\n", 298 dev_warn(dev, "%s: Record disabled due to DMA limitations\n",
243 card->name); 299 card->name);
244 } 300 }
245 301
@@ -331,7 +387,7 @@ context with the GFP_ATOMIC flag.
331Size is the length of the region you want to allocate, in bytes. 387Size is the length of the region you want to allocate, in bytes.
332 388
333This routine will allocate RAM for that region, so it acts similarly to 389This routine will allocate RAM for that region, so it acts similarly to
334__get_free_pages (but takes size instead of a page order). If your 390__get_free_pages() (but takes size instead of a page order). If your
335driver needs regions sized smaller than a page, you may prefer using 391driver needs regions sized smaller than a page, you may prefer using
336the dma_pool interface, described below. 392the dma_pool interface, described below.
337 393
@@ -343,11 +399,11 @@ the consistent DMA mask has been explicitly changed via
343dma_set_coherent_mask(). This is true of the dma_pool interface as 399dma_set_coherent_mask(). This is true of the dma_pool interface as
344well. 400well.
345 401
346dma_alloc_coherent returns two values: the virtual address which you 402dma_alloc_coherent() returns two values: the virtual address which you
347can use to access it from the CPU and dma_handle which you pass to the 403can use to access it from the CPU and dma_handle which you pass to the
348card. 404card.
349 405
350The cpu return address and the DMA bus master address are both 406The CPU virtual address and the DMA bus address are both
351guaranteed to be aligned to the smallest PAGE_SIZE order which 407guaranteed to be aligned to the smallest PAGE_SIZE order which
352is greater than or equal to the requested size. This invariant 408is greater than or equal to the requested size. This invariant
353exists (for example) to guarantee that if you allocate a chunk 409exists (for example) to guarantee that if you allocate a chunk
@@ -359,13 +415,13 @@ To unmap and free such a DMA region, you call:
359 dma_free_coherent(dev, size, cpu_addr, dma_handle); 415 dma_free_coherent(dev, size, cpu_addr, dma_handle);
360 416
361where dev, size are the same as in the above call and cpu_addr and 417where dev, size are the same as in the above call and cpu_addr and
362dma_handle are the values dma_alloc_coherent returned to you. 418dma_handle are the values dma_alloc_coherent() returned to you.
363This function may not be called in interrupt context. 419This function may not be called in interrupt context.
364 420
365If your driver needs lots of smaller memory regions, you can write 421If your driver needs lots of smaller memory regions, you can write
366custom code to subdivide pages returned by dma_alloc_coherent, 422custom code to subdivide pages returned by dma_alloc_coherent(),
367or you can use the dma_pool API to do that. A dma_pool is like 423or you can use the dma_pool API to do that. A dma_pool is like
368a kmem_cache, but it uses dma_alloc_coherent not __get_free_pages. 424a kmem_cache, but it uses dma_alloc_coherent(), not __get_free_pages().
369Also, it understands common hardware constraints for alignment, 425Also, it understands common hardware constraints for alignment,
370like queue heads needing to be aligned on N byte boundaries. 426like queue heads needing to be aligned on N byte boundaries.
371 427
@@ -373,37 +429,37 @@ Create a dma_pool like this:
373 429
374 struct dma_pool *pool; 430 struct dma_pool *pool;
375 431
376 pool = dma_pool_create(name, dev, size, align, alloc); 432 pool = dma_pool_create(name, dev, size, align, boundary);
377 433
378The "name" is for diagnostics (like a kmem_cache name); dev and size 434The "name" is for diagnostics (like a kmem_cache name); dev and size
379are as above. The device's hardware alignment requirement for this 435are as above. The device's hardware alignment requirement for this
380type of data is "align" (which is expressed in bytes, and must be a 436type of data is "align" (which is expressed in bytes, and must be a
381power of two). If your device has no boundary crossing restrictions, 437power of two). If your device has no boundary crossing restrictions,
382pass 0 for alloc; passing 4096 says memory allocated from this pool 438pass 0 for boundary; passing 4096 says memory allocated from this pool
383must not cross 4KByte boundaries (but at that time it may be better to 439must not cross 4KByte boundaries (but at that time it may be better to
384go for dma_alloc_coherent directly instead). 440use dma_alloc_coherent() directly instead).
385 441
386Allocate memory from a dma pool like this: 442Allocate memory from a DMA pool like this:
387 443
388 cpu_addr = dma_pool_alloc(pool, flags, &dma_handle); 444 cpu_addr = dma_pool_alloc(pool, flags, &dma_handle);
389 445
390flags are SLAB_KERNEL if blocking is permitted (not in_interrupt nor 446flags are GFP_KERNEL if blocking is permitted (not in_interrupt nor
391holding SMP locks), SLAB_ATOMIC otherwise. Like dma_alloc_coherent, 447holding SMP locks), GFP_ATOMIC otherwise. Like dma_alloc_coherent(),
392this returns two values, cpu_addr and dma_handle. 448this returns two values, cpu_addr and dma_handle.
393 449
394Free memory that was allocated from a dma_pool like this: 450Free memory that was allocated from a dma_pool like this:
395 451
396 dma_pool_free(pool, cpu_addr, dma_handle); 452 dma_pool_free(pool, cpu_addr, dma_handle);
397 453
398where pool is what you passed to dma_pool_alloc, and cpu_addr and 454where pool is what you passed to dma_pool_alloc(), and cpu_addr and
399dma_handle are the values dma_pool_alloc returned. This function 455dma_handle are the values dma_pool_alloc() returned. This function
400may be called in interrupt context. 456may be called in interrupt context.
401 457
402Destroy a dma_pool by calling: 458Destroy a dma_pool by calling:
403 459
404 dma_pool_destroy(pool); 460 dma_pool_destroy(pool);
405 461
406Make sure you've called dma_pool_free for all memory allocated 462Make sure you've called dma_pool_free() for all memory allocated
407from a pool before you destroy the pool. This function may not 463from a pool before you destroy the pool. This function may not
408be called in interrupt context. 464be called in interrupt context.
409 465
@@ -418,7 +474,7 @@ one of the following values:
418 DMA_FROM_DEVICE 474 DMA_FROM_DEVICE
419 DMA_NONE 475 DMA_NONE
420 476
421One should provide the exact DMA direction if you know it. 477You should provide the exact DMA direction if you know it.
422 478
423DMA_TO_DEVICE means "from main memory to the device" 479DMA_TO_DEVICE means "from main memory to the device"
424DMA_FROM_DEVICE means "from the device to main memory" 480DMA_FROM_DEVICE means "from the device to main memory"
@@ -489,14 +545,14 @@ and to unmap it:
489 dma_unmap_single(dev, dma_handle, size, direction); 545 dma_unmap_single(dev, dma_handle, size, direction);
490 546
491You should call dma_mapping_error() as dma_map_single() could fail and return 547You should call dma_mapping_error() as dma_map_single() could fail and return
492error. Not all dma implementations support dma_mapping_error() interface. 548error. Not all DMA implementations support the dma_mapping_error() interface.
493However, it is a good practice to call dma_mapping_error() interface, which 549However, it is a good practice to call dma_mapping_error() interface, which
494will invoke the generic mapping error check interface. Doing so will ensure 550will invoke the generic mapping error check interface. Doing so will ensure
495that the mapping code will work correctly on all dma implementations without 551that the mapping code will work correctly on all DMA implementations without
496any dependency on the specifics of the underlying implementation. Using the 552any dependency on the specifics of the underlying implementation. Using the
497returned address without checking for errors could result in failures ranging 553returned address without checking for errors could result in failures ranging
498from panics to silent data corruption. A couple of examples of incorrect ways 554from panics to silent data corruption. A couple of examples of incorrect ways
499to check for errors that make assumptions about the underlying dma 555to check for errors that make assumptions about the underlying DMA
500implementation are as follows and these are applicable to dma_map_page() as 556implementation are as follows and these are applicable to dma_map_page() as
501well. 557well.
502 558
@@ -516,13 +572,13 @@ Incorrect example 2:
516 goto map_error; 572 goto map_error;
517 } 573 }
518 574
519You should call dma_unmap_single when the DMA activity is finished, e.g. 575You should call dma_unmap_single() when the DMA activity is finished, e.g.,
520from the interrupt which told you that the DMA transfer is done. 576from the interrupt which told you that the DMA transfer is done.
521 577
522Using cpu pointers like this for single mappings has a disadvantage, 578Using CPU pointers like this for single mappings has a disadvantage:
523you cannot reference HIGHMEM memory in this way. Thus, there is a 579you cannot reference HIGHMEM memory in this way. Thus, there is a
524map/unmap interface pair akin to dma_{map,unmap}_single. These 580map/unmap interface pair akin to dma_{map,unmap}_single(). These
525interfaces deal with page/offset pairs instead of cpu pointers. 581interfaces deal with page/offset pairs instead of CPU pointers.
526Specifically: 582Specifically:
527 583
528 struct device *dev = &my_dev->dev; 584 struct device *dev = &my_dev->dev;
@@ -550,7 +606,7 @@ Here, "offset" means byte offset within the given page.
550You should call dma_mapping_error() as dma_map_page() could fail and return 606You should call dma_mapping_error() as dma_map_page() could fail and return
551error as outlined under the dma_map_single() discussion. 607error as outlined under the dma_map_single() discussion.
552 608
553You should call dma_unmap_page when the DMA activity is finished, e.g. 609You should call dma_unmap_page() when the DMA activity is finished, e.g.,
554from the interrupt which told you that the DMA transfer is done. 610from the interrupt which told you that the DMA transfer is done.
555 611
556With scatterlists, you map a region gathered from several regions by: 612With scatterlists, you map a region gathered from several regions by:
@@ -588,18 +644,16 @@ PLEASE NOTE: The 'nents' argument to the dma_unmap_sg call must be
588 it should _NOT_ be the 'count' value _returned_ from the 644 it should _NOT_ be the 'count' value _returned_ from the
589 dma_map_sg call. 645 dma_map_sg call.
590 646
591Every dma_map_{single,sg} call should have its dma_unmap_{single,sg} 647Every dma_map_{single,sg}() call should have its dma_unmap_{single,sg}()
592counterpart, because the bus address space is a shared resource (although 648counterpart, because the bus address space is a shared resource and
593in some ports the mapping is per each BUS so less devices contend for the 649you could render the machine unusable by consuming all bus addresses.
594same bus address space) and you could render the machine unusable by eating
595all bus addresses.
596 650
597If you need to use the same streaming DMA region multiple times and touch 651If you need to use the same streaming DMA region multiple times and touch
598the data in between the DMA transfers, the buffer needs to be synced 652the data in between the DMA transfers, the buffer needs to be synced
599properly in order for the cpu and device to see the most uptodate and 653properly in order for the CPU and device to see the most up-to-date and
600correct copy of the DMA buffer. 654correct copy of the DMA buffer.
601 655
602So, firstly, just map it with dma_map_{single,sg}, and after each DMA 656So, firstly, just map it with dma_map_{single,sg}(), and after each DMA
603transfer call either: 657transfer call either:
604 658
605 dma_sync_single_for_cpu(dev, dma_handle, size, direction); 659 dma_sync_single_for_cpu(dev, dma_handle, size, direction);
@@ -611,7 +665,7 @@ or:
611as appropriate. 665as appropriate.
612 666
613Then, if you wish to let the device get at the DMA area again, 667Then, if you wish to let the device get at the DMA area again,
614finish accessing the data with the cpu, and then before actually 668finish accessing the data with the CPU, and then before actually
615giving the buffer to the hardware call either: 669giving the buffer to the hardware call either:
616 670
617 dma_sync_single_for_device(dev, dma_handle, size, direction); 671 dma_sync_single_for_device(dev, dma_handle, size, direction);
@@ -623,9 +677,9 @@ or:
623as appropriate. 677as appropriate.
624 678
625After the last DMA transfer call one of the DMA unmap routines 679After the last DMA transfer call one of the DMA unmap routines
626dma_unmap_{single,sg}. If you don't touch the data from the first dma_map_* 680dma_unmap_{single,sg}(). If you don't touch the data from the first
627call till dma_unmap_*, then you don't have to call the dma_sync_* 681dma_map_*() call till dma_unmap_*(), then you don't have to call the
628routines at all. 682dma_sync_*() routines at all.
629 683
630Here is pseudo code which shows a situation in which you would need 684Here is pseudo code which shows a situation in which you would need
631to use the dma_sync_*() interfaces. 685to use the dma_sync_*() interfaces.
@@ -690,12 +744,12 @@ to use the dma_sync_*() interfaces.
690 } 744 }
691 } 745 }
692 746
693Drivers converted fully to this interface should not use virt_to_bus any 747Drivers converted fully to this interface should not use virt_to_bus() any
694longer, nor should they use bus_to_virt. Some drivers have to be changed a 748longer, nor should they use bus_to_virt(). Some drivers have to be changed a
695little bit, because there is no longer an equivalent to bus_to_virt in the 749little bit, because there is no longer an equivalent to bus_to_virt() in the
696dynamic DMA mapping scheme - you have to always store the DMA addresses 750dynamic DMA mapping scheme - you have to always store the DMA addresses
697returned by the dma_alloc_coherent, dma_pool_alloc, and dma_map_single 751returned by the dma_alloc_coherent(), dma_pool_alloc(), and dma_map_single()
698calls (dma_map_sg stores them in the scatterlist itself if the platform 752calls (dma_map_sg() stores them in the scatterlist itself if the platform
699supports dynamic DMA mapping in hardware) in your driver structures and/or 753supports dynamic DMA mapping in hardware) in your driver structures and/or
700in the card registers. 754in the card registers.
701 755
@@ -709,9 +763,9 @@ as it is impossible to correctly support them.
709DMA address space is limited on some architectures and an allocation 763DMA address space is limited on some architectures and an allocation
710failure can be determined by: 764failure can be determined by:
711 765
712- checking if dma_alloc_coherent returns NULL or dma_map_sg returns 0 766- checking if dma_alloc_coherent() returns NULL or dma_map_sg returns 0
713 767
714- checking the returned dma_addr_t of dma_map_single and dma_map_page 768- checking the dma_addr_t returned from dma_map_single() and dma_map_page()
715 by using dma_mapping_error(): 769 by using dma_mapping_error():
716 770
717 dma_addr_t dma_handle; 771 dma_addr_t dma_handle;
@@ -794,7 +848,7 @@ Example 2: (if buffers are allocated in a loop, unmap all mapped buffers when
794 dma_unmap_single(array[i].dma_addr); 848 dma_unmap_single(array[i].dma_addr);
795 } 849 }
796 850
797Networking drivers must call dev_kfree_skb to free the socket buffer 851Networking drivers must call dev_kfree_skb() to free the socket buffer
798and return NETDEV_TX_OK if the DMA mapping fails on the transmit hook 852and return NETDEV_TX_OK if the DMA mapping fails on the transmit hook
799(ndo_start_xmit). This means that the socket buffer is just dropped in 853(ndo_start_xmit). This means that the socket buffer is just dropped in
800the failure case. 854the failure case.
@@ -831,7 +885,7 @@ transform some example code.
831 DEFINE_DMA_UNMAP_LEN(len); 885 DEFINE_DMA_UNMAP_LEN(len);
832 }; 886 };
833 887
8342) Use dma_unmap_{addr,len}_set to set these values. 8882) Use dma_unmap_{addr,len}_set() to set these values.
835 Example, before: 889 Example, before:
836 890
837 ringp->mapping = FOO; 891 ringp->mapping = FOO;
@@ -842,7 +896,7 @@ transform some example code.
842 dma_unmap_addr_set(ringp, mapping, FOO); 896 dma_unmap_addr_set(ringp, mapping, FOO);
843 dma_unmap_len_set(ringp, len, BAR); 897 dma_unmap_len_set(ringp, len, BAR);
844 898
8453) Use dma_unmap_{addr,len} to access these values. 8993) Use dma_unmap_{addr,len}() to access these values.
846 Example, before: 900 Example, before:
847 901
848 dma_unmap_single(dev, ringp->mapping, ringp->len, 902 dma_unmap_single(dev, ringp->mapping, ringp->len,
diff --git a/Documentation/DMA-API.txt b/Documentation/DMA-API.txt
index e865279cec58..52088408668a 100644
--- a/Documentation/DMA-API.txt
+++ b/Documentation/DMA-API.txt
@@ -4,22 +4,26 @@
4 James E.J. Bottomley <James.Bottomley@HansenPartnership.com> 4 James E.J. Bottomley <James.Bottomley@HansenPartnership.com>
5 5
6This document describes the DMA API. For a more gentle introduction 6This document describes the DMA API. For a more gentle introduction
7of the API (and actual examples) see 7of the API (and actual examples), see Documentation/DMA-API-HOWTO.txt.
8Documentation/DMA-API-HOWTO.txt.
9 8
10This API is split into two pieces. Part I describes the API. Part II 9This API is split into two pieces. Part I describes the basic API.
11describes the extensions to the API for supporting non-consistent 10Part II describes extensions for supporting non-consistent memory
12memory machines. Unless you know that your driver absolutely has to 11machines. Unless you know that your driver absolutely has to support
13support non-consistent platforms (this is usually only legacy 12non-consistent platforms (this is usually only legacy platforms) you
14platforms) you should only use the API described in part I. 13should only use the API described in part I.
15 14
16Part I - dma_ API 15Part I - dma_ API
17------------------------------------- 16-------------------------------------
18 17
19To get the dma_ API, you must #include <linux/dma-mapping.h> 18To get the dma_ API, you must #include <linux/dma-mapping.h>. This
19provides dma_addr_t and the interfaces described below.
20 20
21A dma_addr_t can hold any valid DMA or bus address for the platform. It
22can be given to a device to use as a DMA source or target. A CPU cannot
23reference a dma_addr_t directly because there may be translation between
24its physical address space and the bus address space.
21 25
22Part Ia - Using large dma-coherent buffers 26Part Ia - Using large DMA-coherent buffers
23------------------------------------------ 27------------------------------------------
24 28
25void * 29void *
@@ -33,20 +37,21 @@ to make sure to flush the processor's write buffers before telling
33devices to read that memory.) 37devices to read that memory.)
34 38
35This routine allocates a region of <size> bytes of consistent memory. 39This routine allocates a region of <size> bytes of consistent memory.
36It also returns a <dma_handle> which may be cast to an unsigned
37integer the same width as the bus and used as the physical address
38base of the region.
39 40
40Returns: a pointer to the allocated region (in the processor's virtual 41It returns a pointer to the allocated region (in the processor's virtual
41address space) or NULL if the allocation failed. 42address space) or NULL if the allocation failed.
42 43
44It also returns a <dma_handle> which may be cast to an unsigned integer the
45same width as the bus and given to the device as the bus address base of
46the region.
47
43Note: consistent memory can be expensive on some platforms, and the 48Note: consistent memory can be expensive on some platforms, and the
44minimum allocation length may be as big as a page, so you should 49minimum allocation length may be as big as a page, so you should
45consolidate your requests for consistent memory as much as possible. 50consolidate your requests for consistent memory as much as possible.
46The simplest way to do that is to use the dma_pool calls (see below). 51The simplest way to do that is to use the dma_pool calls (see below).
47 52
48The flag parameter (dma_alloc_coherent only) allows the caller to 53The flag parameter (dma_alloc_coherent() only) allows the caller to
49specify the GFP_ flags (see kmalloc) for the allocation (the 54specify the GFP_ flags (see kmalloc()) for the allocation (the
50implementation may choose to ignore flags that affect the location of 55implementation may choose to ignore flags that affect the location of
51the returned memory, like GFP_DMA). 56the returned memory, like GFP_DMA).
52 57
@@ -61,24 +66,24 @@ void
61dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, 66dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
62 dma_addr_t dma_handle) 67 dma_addr_t dma_handle)
63 68
64Free the region of consistent memory you previously allocated. dev, 69Free a region of consistent memory you previously allocated. dev,
65size and dma_handle must all be the same as those passed into the 70size and dma_handle must all be the same as those passed into
66consistent allocate. cpu_addr must be the virtual address returned by 71dma_alloc_coherent(). cpu_addr must be the virtual address returned by
67the consistent allocate. 72the dma_alloc_coherent().
68 73
69Note that unlike their sibling allocation calls, these routines 74Note that unlike their sibling allocation calls, these routines
70may only be called with IRQs enabled. 75may only be called with IRQs enabled.
71 76
72 77
73Part Ib - Using small dma-coherent buffers 78Part Ib - Using small DMA-coherent buffers
74------------------------------------------ 79------------------------------------------
75 80
76To get this part of the dma_ API, you must #include <linux/dmapool.h> 81To get this part of the dma_ API, you must #include <linux/dmapool.h>
77 82
78Many drivers need lots of small dma-coherent memory regions for DMA 83Many drivers need lots of small DMA-coherent memory regions for DMA
79descriptors or I/O buffers. Rather than allocating in units of a page 84descriptors or I/O buffers. Rather than allocating in units of a page
80or more using dma_alloc_coherent(), you can use DMA pools. These work 85or more using dma_alloc_coherent(), you can use DMA pools. These work
81much like a struct kmem_cache, except that they use the dma-coherent allocator, 86much like a struct kmem_cache, except that they use the DMA-coherent allocator,
82not __get_free_pages(). Also, they understand common hardware constraints 87not __get_free_pages(). Also, they understand common hardware constraints
83for alignment, like queue heads needing to be aligned on N-byte boundaries. 88for alignment, like queue heads needing to be aligned on N-byte boundaries.
84 89
@@ -87,7 +92,7 @@ for alignment, like queue heads needing to be aligned on N-byte boundaries.
87 dma_pool_create(const char *name, struct device *dev, 92 dma_pool_create(const char *name, struct device *dev,
88 size_t size, size_t align, size_t alloc); 93 size_t size, size_t align, size_t alloc);
89 94
90The pool create() routines initialize a pool of dma-coherent buffers 95dma_pool_create() initializes a pool of DMA-coherent buffers
91for use with a given device. It must be called in a context which 96for use with a given device. It must be called in a context which
92can sleep. 97can sleep.
93 98
@@ -102,25 +107,26 @@ from this pool must not cross 4KByte boundaries.
102 void *dma_pool_alloc(struct dma_pool *pool, gfp_t gfp_flags, 107 void *dma_pool_alloc(struct dma_pool *pool, gfp_t gfp_flags,
103 dma_addr_t *dma_handle); 108 dma_addr_t *dma_handle);
104 109
105This allocates memory from the pool; the returned memory will meet the size 110This allocates memory from the pool; the returned memory will meet the
106and alignment requirements specified at creation time. Pass GFP_ATOMIC to 111size and alignment requirements specified at creation time. Pass
107prevent blocking, or if it's permitted (not in_interrupt, not holding SMP locks), 112GFP_ATOMIC to prevent blocking, or if it's permitted (not
108pass GFP_KERNEL to allow blocking. Like dma_alloc_coherent(), this returns 113in_interrupt, not holding SMP locks), pass GFP_KERNEL to allow
109two values: an address usable by the cpu, and the dma address usable by the 114blocking. Like dma_alloc_coherent(), this returns two values: an
110pool's device. 115address usable by the CPU, and the DMA address usable by the pool's
116device.
111 117
112 118
113 void dma_pool_free(struct dma_pool *pool, void *vaddr, 119 void dma_pool_free(struct dma_pool *pool, void *vaddr,
114 dma_addr_t addr); 120 dma_addr_t addr);
115 121
116This puts memory back into the pool. The pool is what was passed to 122This puts memory back into the pool. The pool is what was passed to
117the pool allocation routine; the cpu (vaddr) and dma addresses are what 123dma_pool_alloc(); the CPU (vaddr) and DMA addresses are what
118were returned when that routine allocated the memory being freed. 124were returned when that routine allocated the memory being freed.
119 125
120 126
121 void dma_pool_destroy(struct dma_pool *pool); 127 void dma_pool_destroy(struct dma_pool *pool);
122 128
123The pool destroy() routines free the resources of the pool. They must be 129dma_pool_destroy() frees the resources of the pool. It must be
124called in a context which can sleep. Make sure you've freed all allocated 130called in a context which can sleep. Make sure you've freed all allocated
125memory back to the pool before you destroy it. 131memory back to the pool before you destroy it.
126 132
@@ -187,9 +193,9 @@ dma_map_single(struct device *dev, void *cpu_addr, size_t size,
187 enum dma_data_direction direction) 193 enum dma_data_direction direction)
188 194
189Maps a piece of processor virtual memory so it can be accessed by the 195Maps a piece of processor virtual memory so it can be accessed by the
190device and returns the physical handle of the memory. 196device and returns the bus address of the memory.
191 197
192The direction for both api's may be converted freely by casting. 198The direction for both APIs may be converted freely by casting.
193However the dma_ API uses a strongly typed enumerator for its 199However the dma_ API uses a strongly typed enumerator for its
194direction: 200direction:
195 201
@@ -198,31 +204,30 @@ DMA_TO_DEVICE data is going from the memory to the device
198DMA_FROM_DEVICE data is coming from the device to the memory 204DMA_FROM_DEVICE data is coming from the device to the memory
199DMA_BIDIRECTIONAL direction isn't known 205DMA_BIDIRECTIONAL direction isn't known
200 206
201Notes: Not all memory regions in a machine can be mapped by this 207Notes: Not all memory regions in a machine can be mapped by this API.
202API. Further, regions that appear to be physically contiguous in 208Further, contiguous kernel virtual space may not be contiguous as
203kernel virtual space may not be contiguous as physical memory. Since 209physical memory. Since this API does not provide any scatter/gather
204this API does not provide any scatter/gather capability, it will fail 210capability, it will fail if the user tries to map a non-physically
205if the user tries to map a non-physically contiguous piece of memory. 211contiguous piece of memory. For this reason, memory to be mapped by
206For this reason, it is recommended that memory mapped by this API be 212this API should be obtained from sources which guarantee it to be
207obtained only from sources which guarantee it to be physically contiguous 213physically contiguous (like kmalloc).
208(like kmalloc). 214
209 215Further, the bus address of the memory must be within the
210Further, the physical address of the memory must be within the 216dma_mask of the device (the dma_mask is a bit mask of the
211dma_mask of the device (the dma_mask represents a bit mask of the 217addressable region for the device, i.e., if the bus address of
212addressable region for the device. I.e., if the physical address of 218the memory ANDed with the dma_mask is still equal to the bus
213the memory anded with the dma_mask is still equal to the physical 219address, then the device can perform DMA to the memory). To
214address, then the device can perform DMA to the memory). In order to
215ensure that the memory allocated by kmalloc is within the dma_mask, 220ensure that the memory allocated by kmalloc is within the dma_mask,
216the driver may specify various platform-dependent flags to restrict 221the driver may specify various platform-dependent flags to restrict
217the physical memory range of the allocation (e.g. on x86, GFP_DMA 222the bus address range of the allocation (e.g., on x86, GFP_DMA
218guarantees to be within the first 16Mb of available physical memory, 223guarantees to be within the first 16MB of available bus addresses,
219as required by ISA devices). 224as required by ISA devices).
220 225
221Note also that the above constraints on physical contiguity and 226Note also that the above constraints on physical contiguity and
222dma_mask may not apply if the platform has an IOMMU (a device which 227dma_mask may not apply if the platform has an IOMMU (a device which
223supplies a physical to virtual mapping between the I/O memory bus and 228maps an I/O bus address to a physical memory address). However, to be
224the device). However, to be portable, device driver writers may *not* 229portable, device driver writers may *not* assume that such an IOMMU
225assume that such an IOMMU exists. 230exists.
226 231
227Warnings: Memory coherency operates at a granularity called the cache 232Warnings: Memory coherency operates at a granularity called the cache
228line width. In order for memory mapped by this API to operate 233line width. In order for memory mapped by this API to operate
@@ -281,9 +286,9 @@ cache width is.
281int 286int
282dma_mapping_error(struct device *dev, dma_addr_t dma_addr) 287dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
283 288
284In some circumstances dma_map_single and dma_map_page will fail to create 289In some circumstances dma_map_single() and dma_map_page() will fail to create
285a mapping. A driver can check for these errors by testing the returned 290a mapping. A driver can check for these errors by testing the returned
286dma address with dma_mapping_error(). A non-zero return value means the mapping 291DMA address with dma_mapping_error(). A non-zero return value means the mapping
287could not be created and the driver should take appropriate action (e.g. 292could not be created and the driver should take appropriate action (e.g.
288reduce current DMA mapping usage or delay and try again later). 293reduce current DMA mapping usage or delay and try again later).
289 294
@@ -291,7 +296,7 @@ reduce current DMA mapping usage or delay and try again later).
291 dma_map_sg(struct device *dev, struct scatterlist *sg, 296 dma_map_sg(struct device *dev, struct scatterlist *sg,
292 int nents, enum dma_data_direction direction) 297 int nents, enum dma_data_direction direction)
293 298
294Returns: the number of physical segments mapped (this may be shorter 299Returns: the number of bus address segments mapped (this may be shorter
295than <nents> passed in if some elements of the scatter/gather list are 300than <nents> passed in if some elements of the scatter/gather list are
296physically or virtually adjacent and an IOMMU maps them with a single 301physically or virtually adjacent and an IOMMU maps them with a single
297entry). 302entry).
@@ -299,7 +304,7 @@ entry).
299Please note that the sg cannot be mapped again if it has been mapped once. 304Please note that the sg cannot be mapped again if it has been mapped once.
300The mapping process is allowed to destroy information in the sg. 305The mapping process is allowed to destroy information in the sg.
301 306
302As with the other mapping interfaces, dma_map_sg can fail. When it 307As with the other mapping interfaces, dma_map_sg() can fail. When it
303does, 0 is returned and a driver must take appropriate action. It is 308does, 0 is returned and a driver must take appropriate action. It is
304critical that the driver do something, in the case of a block driver 309critical that the driver do something, in the case of a block driver
305aborting the request or even oopsing is better than doing nothing and 310aborting the request or even oopsing is better than doing nothing and
@@ -335,7 +340,7 @@ must be the same as those and passed in to the scatter/gather mapping
335API. 340API.
336 341
337Note: <nents> must be the number you passed in, *not* the number of 342Note: <nents> must be the number you passed in, *not* the number of
338physical entries returned. 343bus address entries returned.
339 344
340void 345void
341dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size, 346dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
@@ -350,7 +355,7 @@ void
350dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems, 355dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
351 enum dma_data_direction direction) 356 enum dma_data_direction direction)
352 357
353Synchronise a single contiguous or scatter/gather mapping for the cpu 358Synchronise a single contiguous or scatter/gather mapping for the CPU
354and device. With the sync_sg API, all the parameters must be the same 359and device. With the sync_sg API, all the parameters must be the same
355as those passed into the single mapping API. With the sync_single API, 360as those passed into the single mapping API. With the sync_single API,
356you can use dma_handle and size parameters that aren't identical to 361you can use dma_handle and size parameters that aren't identical to
@@ -391,10 +396,10 @@ The four functions above are just like the counterpart functions
391without the _attrs suffixes, except that they pass an optional 396without the _attrs suffixes, except that they pass an optional
392struct dma_attrs*. 397struct dma_attrs*.
393 398
394struct dma_attrs encapsulates a set of "dma attributes". For the 399struct dma_attrs encapsulates a set of "DMA attributes". For the
395definition of struct dma_attrs see linux/dma-attrs.h. 400definition of struct dma_attrs see linux/dma-attrs.h.
396 401
397The interpretation of dma attributes is architecture-specific, and 402The interpretation of DMA attributes is architecture-specific, and
398each attribute should be documented in Documentation/DMA-attributes.txt. 403each attribute should be documented in Documentation/DMA-attributes.txt.
399 404
400If struct dma_attrs* is NULL, the semantics of each of these 405If struct dma_attrs* is NULL, the semantics of each of these
@@ -458,7 +463,7 @@ Note: where the platform can return consistent memory, it will
458guarantee that the sync points become nops. 463guarantee that the sync points become nops.
459 464
460Warning: Handling non-consistent memory is a real pain. You should 465Warning: Handling non-consistent memory is a real pain. You should
461only ever use this API if you positively know your driver will be 466only use this API if you positively know your driver will be
462required to work on one of the rare (usually non-PCI) architectures 467required to work on one of the rare (usually non-PCI) architectures
463that simply cannot make consistent memory. 468that simply cannot make consistent memory.
464 469
@@ -492,30 +497,29 @@ continuing on for size. Again, you *must* observe the cache line
492boundaries when doing this. 497boundaries when doing this.
493 498
494int 499int
495dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, 500dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
496 dma_addr_t device_addr, size_t size, int 501 dma_addr_t device_addr, size_t size, int
497 flags) 502 flags)
498 503
499Declare region of memory to be handed out by dma_alloc_coherent when 504Declare region of memory to be handed out by dma_alloc_coherent() when
500it's asked for coherent memory for this device. 505it's asked for coherent memory for this device.
501 506
502bus_addr is the physical address to which the memory is currently 507phys_addr is the CPU physical address to which the memory is currently
503assigned in the bus responding region (this will be used by the 508assigned (this will be ioremapped so the CPU can access the region).
504platform to perform the mapping).
505 509
506device_addr is the physical address the device needs to be programmed 510device_addr is the bus address the device needs to be programmed
507with actually to address this memory (this will be handed out as the 511with to actually address this memory (this will be handed out as the
508dma_addr_t in dma_alloc_coherent()). 512dma_addr_t in dma_alloc_coherent()).
509 513
510size is the size of the area (must be multiples of PAGE_SIZE). 514size is the size of the area (must be multiples of PAGE_SIZE).
511 515
512flags can be or'd together and are: 516flags can be ORed together and are:
513 517
514DMA_MEMORY_MAP - request that the memory returned from 518DMA_MEMORY_MAP - request that the memory returned from
515dma_alloc_coherent() be directly writable. 519dma_alloc_coherent() be directly writable.
516 520
517DMA_MEMORY_IO - request that the memory returned from 521DMA_MEMORY_IO - request that the memory returned from
518dma_alloc_coherent() be addressable using read/write/memcpy_toio etc. 522dma_alloc_coherent() be addressable using read()/write()/memcpy_toio() etc.
519 523
520One or both of these flags must be present. 524One or both of these flags must be present.
521 525
@@ -572,7 +576,7 @@ region is occupied.
572Part III - Debug drivers use of the DMA-API 576Part III - Debug drivers use of the DMA-API
573------------------------------------------- 577-------------------------------------------
574 578
575The DMA-API as described above as some constraints. DMA addresses must be 579The DMA-API as described above has some constraints. DMA addresses must be
576released with the corresponding function with the same size for example. With 580released with the corresponding function with the same size for example. With
577the advent of hardware IOMMUs it becomes more and more important that drivers 581the advent of hardware IOMMUs it becomes more and more important that drivers
578do not violate those constraints. In the worst case such a violation can 582do not violate those constraints. In the worst case such a violation can
@@ -690,11 +694,11 @@ architectural default.
690void debug_dmap_mapping_error(struct device *dev, dma_addr_t dma_addr); 694void debug_dmap_mapping_error(struct device *dev, dma_addr_t dma_addr);
691 695
692dma-debug interface debug_dma_mapping_error() to debug drivers that fail 696dma-debug interface debug_dma_mapping_error() to debug drivers that fail
693to check dma mapping errors on addresses returned by dma_map_single() and 697to check DMA mapping errors on addresses returned by dma_map_single() and
694dma_map_page() interfaces. This interface clears a flag set by 698dma_map_page() interfaces. This interface clears a flag set by
695debug_dma_map_page() to indicate that dma_mapping_error() has been called by 699debug_dma_map_page() to indicate that dma_mapping_error() has been called by
696the driver. When driver does unmap, debug_dma_unmap() checks the flag and if 700the driver. When driver does unmap, debug_dma_unmap() checks the flag and if
697this flag is still set, prints warning message that includes call trace that 701this flag is still set, prints warning message that includes call trace that
698leads up to the unmap. This interface can be called from dma_mapping_error() 702leads up to the unmap. This interface can be called from dma_mapping_error()
699routines to enable dma mapping error check debugging. 703routines to enable DMA mapping error check debugging.
700 704
diff --git a/Documentation/DMA-ISA-LPC.txt b/Documentation/DMA-ISA-LPC.txt
index e767805b4182..b1a19835e907 100644
--- a/Documentation/DMA-ISA-LPC.txt
+++ b/Documentation/DMA-ISA-LPC.txt
@@ -16,7 +16,7 @@ To do ISA style DMA you need to include two headers:
16#include <asm/dma.h> 16#include <asm/dma.h>
17 17
18The first is the generic DMA API used to convert virtual addresses to 18The first is the generic DMA API used to convert virtual addresses to
19physical addresses (see Documentation/DMA-API.txt for details). 19bus addresses (see Documentation/DMA-API.txt for details).
20 20
21The second contains the routines specific to ISA DMA transfers. Since 21The second contains the routines specific to ISA DMA transfers. Since
22this is not present on all platforms make sure you construct your 22this is not present on all platforms make sure you construct your
@@ -50,7 +50,7 @@ early as possible and not release it until the driver is unloaded.)
50Part III - Address translation 50Part III - Address translation
51------------------------------ 51------------------------------
52 52
53To translate the virtual address to a physical use the normal DMA 53To translate the virtual address to a bus address, use the normal DMA
54API. Do _not_ use isa_virt_to_phys() even though it does the same 54API. Do _not_ use isa_virt_to_phys() even though it does the same
55thing. The reason for this is that the function isa_virt_to_phys() 55thing. The reason for this is that the function isa_virt_to_phys()
56will require a Kconfig dependency to ISA, not just ISA_DMA_API which 56will require a Kconfig dependency to ISA, not just ISA_DMA_API which
diff --git a/Documentation/devicetree/bindings/pci/host-generic-pci.txt b/Documentation/devicetree/bindings/pci/host-generic-pci.txt
new file mode 100644
index 000000000000..f0b0436807b4
--- /dev/null
+++ b/Documentation/devicetree/bindings/pci/host-generic-pci.txt
@@ -0,0 +1,100 @@
1* Generic PCI host controller
2
3Firmware-initialised PCI host controllers and PCI emulations, such as the
4virtio-pci implementations found in kvmtool and other para-virtualised
5systems, do not require driver support for complexities such as regulator
6and clock management. In fact, the controller may not even require the
7configuration of a control interface by the operating system, instead
8presenting a set of fixed windows describing a subset of IO, Memory and
9Configuration Spaces.
10
11Such a controller can be described purely in terms of the standardized device
12tree bindings communicated in pci.txt:
13
14
15Properties of the host controller node:
16
17- compatible : Must be "pci-host-cam-generic" or "pci-host-ecam-generic"
18 depending on the layout of configuration space (CAM vs
19 ECAM respectively).
20
21- device_type : Must be "pci".
22
23- ranges : As described in IEEE Std 1275-1994, but must provide
24 at least a definition of non-prefetchable memory. One
25 or both of prefetchable Memory and IO Space may also
26 be provided.
27
28- bus-range : Optional property (also described in IEEE Std 1275-1994)
29 to indicate the range of bus numbers for this controller.
30 If absent, defaults to <0 255> (i.e. all buses).
31
32- #address-cells : Must be 3.
33
34- #size-cells : Must be 2.
35
36- reg : The Configuration Space base address and size, as accessed
37 from the parent bus.
38
39
40Properties of the /chosen node:
41
42- linux,pci-probe-only
43 : Optional property which takes a single-cell argument.
44 If '0', then Linux will assign devices in its usual manner,
45 otherwise it will not try to assign devices and instead use
46 them as they are configured already.
47
48Configuration Space is assumed to be memory-mapped (as opposed to being
49accessed via an ioport) and laid out with a direct correspondence to the
50geography of a PCI bus address by concatenating the various components to
51form an offset.
52
53For CAM, this 24-bit offset is:
54
55 cfg_offset(bus, device, function, register) =
56 bus << 16 | device << 11 | function << 8 | register
57
58Whilst ECAM extends this by 4 bits to accomodate 4k of function space:
59
60 cfg_offset(bus, device, function, register) =
61 bus << 20 | device << 15 | function << 12 | register
62
63Interrupt mapping is exactly as described in `Open Firmware Recommended
64Practice: Interrupt Mapping' and requires the following properties:
65
66- #interrupt-cells : Must be 1
67
68- interrupt-map : <see aforementioned specification>
69
70- interrupt-map-mask : <see aforementioned specification>
71
72
73Example:
74
75pci {
76 compatible = "pci-host-cam-generic"
77 device_type = "pci";
78 #address-cells = <3>;
79 #size-cells = <2>;
80 bus-range = <0x0 0x1>;
81
82 // CPU_PHYSICAL(2) SIZE(2)
83 reg = <0x0 0x40000000 0x0 0x1000000>;
84
85 // BUS_ADDRESS(3) CPU_PHYSICAL(2) SIZE(2)
86 ranges = <0x01000000 0x0 0x01000000 0x0 0x01000000 0x0 0x00010000>,
87 <0x02000000 0x0 0x41000000 0x0 0x41000000 0x0 0x3f000000>;
88
89
90 #interrupt-cells = <0x1>;
91
92 // PCI_DEVICE(3) INT#(1) CONTROLLER(PHANDLE) CONTROLLER_DATA(3)
93 interrupt-map = < 0x0 0x0 0x0 0x1 &gic 0x0 0x4 0x1
94 0x800 0x0 0x0 0x1 &gic 0x0 0x5 0x1
95 0x1000 0x0 0x0 0x1 &gic 0x0 0x6 0x1
96 0x1800 0x0 0x0 0x1 &gic 0x0 0x7 0x1>;
97
98 // PCI_DEVICE(3) INT#(1)
99 interrupt-map-mask = <0xf800 0x0 0x0 0x7>;
100}
diff --git a/Documentation/devicetree/bindings/pci/pci-rcar-gen2.txt b/Documentation/devicetree/bindings/pci/pci-rcar-gen2.txt
new file mode 100644
index 000000000000..d8ef5bf50f11
--- /dev/null
+++ b/Documentation/devicetree/bindings/pci/pci-rcar-gen2.txt
@@ -0,0 +1,66 @@
1Renesas AHB to PCI bridge
2-------------------------
3
4This is the bridge used internally to connect the USB controllers to the
5AHB. There is one bridge instance per USB port connected to the internal
6OHCI and EHCI controllers.
7
8Required properties:
9- compatible: "renesas,pci-r8a7790" for the R8A7790 SoC;
10 "renesas,pci-r8a7791" for the R8A7791 SoC.
11- reg: A list of physical regions to access the device: the first is
12 the operational registers for the OHCI/EHCI controllers and the
13 second is for the bridge configuration and control registers.
14- interrupts: interrupt for the device.
15- clocks: The reference to the device clock.
16- bus-range: The PCI bus number range; as this is a single bus, the range
17 should be specified as the same value twice.
18- #address-cells: must be 3.
19- #size-cells: must be 2.
20- #interrupt-cells: must be 1.
21- interrupt-map: standard property used to define the mapping of the PCI
22 interrupts to the GIC interrupts.
23- interrupt-map-mask: standard property that helps to define the interrupt
24 mapping.
25
26Example SoC configuration:
27
28 pci0: pci@ee090000 {
29 compatible = "renesas,pci-r8a7790";
30 clocks = <&mstp7_clks R8A7790_CLK_EHCI>;
31 reg = <0x0 0xee090000 0x0 0xc00>,
32 <0x0 0xee080000 0x0 0x1100>;
33 interrupts = <0 108 IRQ_TYPE_LEVEL_HIGH>;
34 status = "disabled";
35
36 bus-range = <0 0>;
37 #address-cells = <3>;
38 #size-cells = <2>;
39 #interrupt-cells = <1>;
40 interrupt-map-mask = <0xff00 0 0 0x7>;
41 interrupt-map = <0x0000 0 0 1 &gic 0 108 IRQ_TYPE_LEVEL_HIGH
42 0x0800 0 0 1 &gic 0 108 IRQ_TYPE_LEVEL_HIGH
43 0x1000 0 0 2 &gic 0 108 IRQ_TYPE_LEVEL_HIGH>;
44
45 pci@0,1 {
46 reg = <0x800 0 0 0 0>;
47 device_type = "pci";
48 phys = <&usbphy 0 0>;
49 phy-names = "usb";
50 };
51
52 pci@0,2 {
53 reg = <0x1000 0 0 0 0>;
54 device_type = "pci";
55 phys = <&usbphy 0 0>;
56 phy-names = "usb";
57 };
58 };
59
60Example board setup:
61
62&pci0 {
63 status = "okay";
64 pinctrl-0 = <&usb0_pins>;
65 pinctrl-names = "default";
66};
diff --git a/Documentation/devicetree/bindings/pci/rcar-pci.txt b/Documentation/devicetree/bindings/pci/rcar-pci.txt
new file mode 100644
index 000000000000..29d3b989d3b0
--- /dev/null
+++ b/Documentation/devicetree/bindings/pci/rcar-pci.txt
@@ -0,0 +1,47 @@
1* Renesas RCar PCIe interface
2
3Required properties:
4- compatible: should contain one of the following
5 "renesas,pcie-r8a7779", "renesas,pcie-r8a7790", "renesas,pcie-r8a7791"
6- reg: base address and length of the pcie controller registers.
7- #address-cells: set to <3>
8- #size-cells: set to <2>
9- bus-range: PCI bus numbers covered
10- device_type: set to "pci"
11- ranges: ranges for the PCI memory and I/O regions.
12- dma-ranges: ranges for the inbound memory regions.
13- interrupts: two interrupt sources for MSI interrupts, followed by interrupt
14 source for hardware related interrupts (e.g. link speed change).
15- #interrupt-cells: set to <1>
16- interrupt-map-mask and interrupt-map: standard PCI properties
17 to define the mapping of the PCIe interface to interrupt
18 numbers.
19- clocks: from common clock binding: clock specifiers for the PCIe controller
20 and PCIe bus clocks.
21- clock-names: from common clock binding: should be "pcie" and "pcie_bus".
22
23Example:
24
25SoC specific DT Entry:
26
27 pcie: pcie@fe000000 {
28 compatible = "renesas,pcie-r8a7791";
29 reg = <0 0xfe000000 0 0x80000>;
30 #address-cells = <3>;
31 #size-cells = <2>;
32 bus-range = <0x00 0xff>;
33 device_type = "pci";
34 ranges = <0x01000000 0 0x00000000 0 0xfe100000 0 0x00100000
35 0x02000000 0 0xfe200000 0 0xfe200000 0 0x00200000
36 0x02000000 0 0x30000000 0 0x30000000 0 0x08000000
37 0x42000000 0 0x38000000 0 0x38000000 0 0x08000000>;
38 dma-ranges = <0x42000000 0 0x40000000 0 0x40000000 0 0x40000000
39 0x42000000 2 0x00000000 2 0x00000000 0 0x40000000>;
40 interrupts = <0 116 4>, <0 117 4>, <0 118 4>;
41 #interrupt-cells = <1>;
42 interrupt-map-mask = <0 0 0 0>;
43 interrupt-map = <0 0 0 0 &gic 0 116 4>;
44 clocks = <&mstp3_clks R8A7791_CLK_PCIE>, <&pcie_bus_clk>;
45 clock-names = "pcie", "pcie_bus";
46 status = "disabled";
47 };
diff --git a/MAINTAINERS b/MAINTAINERS
index 672b80aa236c..b82ebe761b30 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6710,6 +6710,7 @@ F: Documentation/PCI/
6710F: drivers/pci/ 6710F: drivers/pci/
6711F: include/linux/pci* 6711F: include/linux/pci*
6712F: arch/x86/pci/ 6712F: arch/x86/pci/
6713F: arch/x86/kernel/quirks.c
6713 6714
6714PCI DRIVER FOR IMX6 6715PCI DRIVER FOR IMX6
6715M: Richard Zhu <r65037@freescale.com> 6716M: Richard Zhu <r65037@freescale.com>
@@ -6757,6 +6758,14 @@ L: linux-pci@vger.kernel.org
6757S: Maintained 6758S: Maintained
6758F: drivers/pci/host/*designware* 6759F: drivers/pci/host/*designware*
6759 6760
6761PCI DRIVER FOR GENERIC OF HOSTS
6762M: Will Deacon <will.deacon@arm.com>
6763L: linux-pci@vger.kernel.org
6764L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
6765S: Maintained
6766F: Documentation/devicetree/bindings/pci/host-generic-pci.txt
6767F: drivers/pci/host/pci-host-generic.c
6768
6760PCMCIA SUBSYSTEM 6769PCMCIA SUBSYSTEM
6761P: Linux PCMCIA Team 6770P: Linux PCMCIA Team
6762L: linux-pcmcia@lists.infradead.org 6771L: linux-pcmcia@lists.infradead.org
diff --git a/arch/alpha/include/asm/pci.h b/arch/alpha/include/asm/pci.h
index d01afb78919c..f7f680f7457d 100644
--- a/arch/alpha/include/asm/pci.h
+++ b/arch/alpha/include/asm/pci.h
@@ -59,11 +59,6 @@ struct pci_controller {
59 59
60extern void pcibios_set_master(struct pci_dev *dev); 60extern void pcibios_set_master(struct pci_dev *dev);
61 61
62extern inline void pcibios_penalize_isa_irq(int irq, int active)
63{
64 /* We don't do dynamic PCI IRQ allocation */
65}
66
67/* IOMMU controls. */ 62/* IOMMU controls. */
68 63
69/* The PCI address space does not equal the physical memory address space. 64/* The PCI address space does not equal the physical memory address space.
diff --git a/arch/arm/include/asm/pci.h b/arch/arm/include/asm/pci.h
index 680a83e94467..7e95d8535e24 100644
--- a/arch/arm/include/asm/pci.h
+++ b/arch/arm/include/asm/pci.h
@@ -31,11 +31,6 @@ static inline int pci_proc_domain(struct pci_bus *bus)
31} 31}
32#endif /* CONFIG_PCI_DOMAINS */ 32#endif /* CONFIG_PCI_DOMAINS */
33 33
34static inline void pcibios_penalize_isa_irq(int irq, int active)
35{
36 /* We don't do dynamic PCI IRQ allocation */
37}
38
39/* 34/*
40 * The PCI address space does equal the physical memory address space. 35 * The PCI address space does equal the physical memory address space.
41 * The networking and block device layers use this boolean for bounce 36 * The networking and block device layers use this boolean for bounce
diff --git a/arch/arm/kernel/bios32.c b/arch/arm/kernel/bios32.c
index 16d43cd45619..17a26c17f7f5 100644
--- a/arch/arm/kernel/bios32.c
+++ b/arch/arm/kernel/bios32.c
@@ -545,6 +545,18 @@ void pci_common_init_dev(struct device *parent, struct hw_pci *hw)
545 */ 545 */
546 pci_bus_add_devices(bus); 546 pci_bus_add_devices(bus);
547 } 547 }
548
549 list_for_each_entry(sys, &head, node) {
550 struct pci_bus *bus = sys->bus;
551
552 /* Configure PCI Express settings */
553 if (bus && !pci_has_flag(PCI_PROBE_ONLY)) {
554 struct pci_bus *child;
555
556 list_for_each_entry(child, &bus->children, node)
557 pcie_bus_configure_settings(child);
558 }
559 }
548} 560}
549 561
550#ifndef CONFIG_PCI_HOST_ITE8152 562#ifndef CONFIG_PCI_HOST_ITE8152
diff --git a/arch/blackfin/include/asm/pci.h b/arch/blackfin/include/asm/pci.h
index 74352c4597d9..c737909fba47 100644
--- a/arch/blackfin/include/asm/pci.h
+++ b/arch/blackfin/include/asm/pci.h
@@ -10,9 +10,4 @@
10#define PCIBIOS_MIN_IO 0x00001000 10#define PCIBIOS_MIN_IO 0x00001000
11#define PCIBIOS_MIN_MEM 0x10000000 11#define PCIBIOS_MIN_MEM 0x10000000
12 12
13static inline void pcibios_penalize_isa_irq(int irq)
14{
15 /* We don't do dynamic PCI IRQ allocation */
16}
17
18#endif /* _ASM_BFIN_PCI_H */ 13#endif /* _ASM_BFIN_PCI_H */
diff --git a/arch/cris/include/asm/pci.h b/arch/cris/include/asm/pci.h
index f666734926d5..cc2399c175e9 100644
--- a/arch/cris/include/asm/pci.h
+++ b/arch/cris/include/asm/pci.h
@@ -20,7 +20,6 @@ void pcibios_config_init(void);
20struct pci_bus * pcibios_scan_root(int bus); 20struct pci_bus * pcibios_scan_root(int bus);
21 21
22void pcibios_set_master(struct pci_dev *dev); 22void pcibios_set_master(struct pci_dev *dev);
23void pcibios_penalize_isa_irq(int irq);
24struct irq_routing_table *pcibios_get_irq_routing_table(void); 23struct irq_routing_table *pcibios_get_irq_routing_table(void);
25int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq); 24int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
26 25
diff --git a/arch/frv/include/asm/pci.h b/arch/frv/include/asm/pci.h
index ef03baf5d89d..2035a4d3f9b9 100644
--- a/arch/frv/include/asm/pci.h
+++ b/arch/frv/include/asm/pci.h
@@ -24,8 +24,6 @@ struct pci_dev;
24 24
25extern void pcibios_set_master(struct pci_dev *dev); 25extern void pcibios_set_master(struct pci_dev *dev);
26 26
27extern void pcibios_penalize_isa_irq(int irq);
28
29#ifdef CONFIG_MMU 27#ifdef CONFIG_MMU
30extern void *consistent_alloc(gfp_t gfp, size_t size, dma_addr_t *dma_handle); 28extern void *consistent_alloc(gfp_t gfp, size_t size, dma_addr_t *dma_handle);
31extern void consistent_free(void *vaddr); 29extern void consistent_free(void *vaddr);
diff --git a/arch/frv/mb93090-mb00/pci-irq.c b/arch/frv/mb93090-mb00/pci-irq.c
index c677b9d81d30..1c35c93f942b 100644
--- a/arch/frv/mb93090-mb00/pci-irq.c
+++ b/arch/frv/mb93090-mb00/pci-irq.c
@@ -55,10 +55,6 @@ void __init pcibios_fixup_irqs(void)
55 } 55 }
56} 56}
57 57
58void __init pcibios_penalize_isa_irq(int irq)
59{
60}
61
62void pcibios_enable_irq(struct pci_dev *dev) 58void pcibios_enable_irq(struct pci_dev *dev)
63{ 59{
64 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq); 60 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
diff --git a/arch/ia64/include/asm/pci.h b/arch/ia64/include/asm/pci.h
index 7d41cc089822..52af5ed9f60b 100644
--- a/arch/ia64/include/asm/pci.h
+++ b/arch/ia64/include/asm/pci.h
@@ -50,12 +50,6 @@ struct pci_dev;
50extern unsigned long ia64_max_iommu_merge_mask; 50extern unsigned long ia64_max_iommu_merge_mask;
51#define PCI_DMA_BUS_IS_PHYS (ia64_max_iommu_merge_mask == ~0UL) 51#define PCI_DMA_BUS_IS_PHYS (ia64_max_iommu_merge_mask == ~0UL)
52 52
53static inline void
54pcibios_penalize_isa_irq (int irq, int active)
55{
56 /* We don't do dynamic PCI IRQ allocation */
57}
58
59#include <asm-generic/pci-dma-compat.h> 53#include <asm-generic/pci-dma-compat.h>
60 54
61#ifdef CONFIG_PCI 55#ifdef CONFIG_PCI
diff --git a/arch/ia64/pci/fixup.c b/arch/ia64/pci/fixup.c
index eee069a0b539..1fe9aa5068ea 100644
--- a/arch/ia64/pci/fixup.c
+++ b/arch/ia64/pci/fixup.c
@@ -49,9 +49,7 @@ static void pci_fixup_video(struct pci_dev *pdev)
49 * type BRIDGE, or CARDBUS. Host to PCI controllers use 49 * type BRIDGE, or CARDBUS. Host to PCI controllers use
50 * PCI header type NORMAL. 50 * PCI header type NORMAL.
51 */ 51 */
52 if (bridge 52 if (bridge && (pci_is_bridge(bridge))) {
53 &&((bridge->hdr_type == PCI_HEADER_TYPE_BRIDGE)
54 ||(bridge->hdr_type == PCI_HEADER_TYPE_CARDBUS))) {
55 pci_read_config_word(bridge, PCI_BRIDGE_CONTROL, 53 pci_read_config_word(bridge, PCI_BRIDGE_CONTROL,
56 &config); 54 &config);
57 if (!(config & PCI_BRIDGE_CTL_VGA)) 55 if (!(config & PCI_BRIDGE_CTL_VGA))
diff --git a/arch/microblaze/include/asm/pci.h b/arch/microblaze/include/asm/pci.h
index 935f9bec414a..335524040fff 100644
--- a/arch/microblaze/include/asm/pci.h
+++ b/arch/microblaze/include/asm/pci.h
@@ -44,11 +44,6 @@ struct pci_dev;
44 */ 44 */
45#define pcibios_assign_all_busses() 0 45#define pcibios_assign_all_busses() 0
46 46
47static inline void pcibios_penalize_isa_irq(int irq, int active)
48{
49 /* We don't do dynamic PCI IRQ allocation */
50}
51
52#ifdef CONFIG_PCI 47#ifdef CONFIG_PCI
53extern void set_pci_dma_ops(struct dma_map_ops *dma_ops); 48extern void set_pci_dma_ops(struct dma_map_ops *dma_ops);
54extern struct dma_map_ops *get_pci_dma_ops(void); 49extern struct dma_map_ops *get_pci_dma_ops(void);
diff --git a/arch/microblaze/pci/pci-common.c b/arch/microblaze/pci/pci-common.c
index 70996cc66aa2..a59de1bc1ce0 100644
--- a/arch/microblaze/pci/pci-common.c
+++ b/arch/microblaze/pci/pci-common.c
@@ -168,26 +168,6 @@ struct pci_controller *pci_find_hose_for_OF_device(struct device_node *node)
168 return NULL; 168 return NULL;
169} 169}
170 170
171static ssize_t pci_show_devspec(struct device *dev,
172 struct device_attribute *attr, char *buf)
173{
174 struct pci_dev *pdev;
175 struct device_node *np;
176
177 pdev = to_pci_dev(dev);
178 np = pci_device_to_OF_node(pdev);
179 if (np == NULL || np->full_name == NULL)
180 return 0;
181 return sprintf(buf, "%s", np->full_name);
182}
183static DEVICE_ATTR(devspec, S_IRUGO, pci_show_devspec, NULL);
184
185/* Add sysfs properties */
186int pcibios_add_platform_entries(struct pci_dev *pdev)
187{
188 return device_create_file(&pdev->dev, &dev_attr_devspec);
189}
190
191void pcibios_set_master(struct pci_dev *dev) 171void pcibios_set_master(struct pci_dev *dev)
192{ 172{
193 /* No special bus mastering setup handling */ 173 /* No special bus mastering setup handling */
diff --git a/arch/mips/include/asm/pci.h b/arch/mips/include/asm/pci.h
index 12d6842962be..974b0e308963 100644
--- a/arch/mips/include/asm/pci.h
+++ b/arch/mips/include/asm/pci.h
@@ -73,11 +73,6 @@ extern unsigned long PCIBIOS_MIN_MEM;
73 73
74extern void pcibios_set_master(struct pci_dev *dev); 74extern void pcibios_set_master(struct pci_dev *dev);
75 75
76static inline void pcibios_penalize_isa_irq(int irq, int active)
77{
78 /* We don't do dynamic PCI IRQ allocation */
79}
80
81#define HAVE_PCI_MMAP 76#define HAVE_PCI_MMAP
82 77
83extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, 78extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
diff --git a/arch/mn10300/include/asm/pci.h b/arch/mn10300/include/asm/pci.h
index 166323824683..5f70af25c7d0 100644
--- a/arch/mn10300/include/asm/pci.h
+++ b/arch/mn10300/include/asm/pci.h
@@ -48,7 +48,6 @@ extern void unit_pci_init(void);
48#define PCIBIOS_MIN_MEM 0xB8000000 48#define PCIBIOS_MIN_MEM 0xB8000000
49 49
50void pcibios_set_master(struct pci_dev *dev); 50void pcibios_set_master(struct pci_dev *dev);
51void pcibios_penalize_isa_irq(int irq);
52 51
53/* Dynamic DMA mapping stuff. 52/* Dynamic DMA mapping stuff.
54 * i386 has everything mapped statically. 53 * i386 has everything mapped statically.
diff --git a/arch/mn10300/unit-asb2305/pci-irq.c b/arch/mn10300/unit-asb2305/pci-irq.c
index 77439da04671..fcb28ceb824d 100644
--- a/arch/mn10300/unit-asb2305/pci-irq.c
+++ b/arch/mn10300/unit-asb2305/pci-irq.c
@@ -40,10 +40,6 @@ void __init pcibios_fixup_irqs(void)
40 } 40 }
41} 41}
42 42
43void __init pcibios_penalize_isa_irq(int irq)
44{
45}
46
47void pcibios_enable_irq(struct pci_dev *dev) 43void pcibios_enable_irq(struct pci_dev *dev)
48{ 44{
49 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq); 45 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
diff --git a/arch/parisc/include/asm/pci.h b/arch/parisc/include/asm/pci.h
index 465154076d23..20df2b04fc09 100644
--- a/arch/parisc/include/asm/pci.h
+++ b/arch/parisc/include/asm/pci.h
@@ -215,11 +215,6 @@ static inline void pci_dma_burst_advice(struct pci_dev *pdev,
215} 215}
216#endif 216#endif
217 217
218static inline void pcibios_penalize_isa_irq(int irq, int active)
219{
220 /* We don't need to penalize isa irq's */
221}
222
223static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel) 218static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel)
224{ 219{
225 return channel ? 15 : 14; 220 return channel ? 15 : 14;
diff --git a/arch/powerpc/include/asm/pci.h b/arch/powerpc/include/asm/pci.h
index 95145a15c708..1b0739bc14b5 100644
--- a/arch/powerpc/include/asm/pci.h
+++ b/arch/powerpc/include/asm/pci.h
@@ -46,11 +46,6 @@ struct pci_dev;
46#define pcibios_assign_all_busses() \ 46#define pcibios_assign_all_busses() \
47 (pci_has_flag(PCI_REASSIGN_ALL_BUS)) 47 (pci_has_flag(PCI_REASSIGN_ALL_BUS))
48 48
49static inline void pcibios_penalize_isa_irq(int irq, int active)
50{
51 /* We don't do dynamic PCI IRQ allocation */
52}
53
54#define HAVE_ARCH_PCI_GET_LEGACY_IDE_IRQ 49#define HAVE_ARCH_PCI_GET_LEGACY_IDE_IRQ
55static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel) 50static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel)
56{ 51{
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
index d9476c1fc959..24d342e91790 100644
--- a/arch/powerpc/kernel/pci-common.c
+++ b/arch/powerpc/kernel/pci-common.c
@@ -201,26 +201,6 @@ struct pci_controller* pci_find_hose_for_OF_device(struct device_node* node)
201 return NULL; 201 return NULL;
202} 202}
203 203
204static ssize_t pci_show_devspec(struct device *dev,
205 struct device_attribute *attr, char *buf)
206{
207 struct pci_dev *pdev;
208 struct device_node *np;
209
210 pdev = to_pci_dev (dev);
211 np = pci_device_to_OF_node(pdev);
212 if (np == NULL || np->full_name == NULL)
213 return 0;
214 return sprintf(buf, "%s", np->full_name);
215}
216static DEVICE_ATTR(devspec, S_IRUGO, pci_show_devspec, NULL);
217
218/* Add sysfs properties */
219int pcibios_add_platform_entries(struct pci_dev *pdev)
220{
221 return device_create_file(&pdev->dev, &dev_attr_devspec);
222}
223
224/* 204/*
225 * Reads the interrupt pin to determine if interrupt is use by card. 205 * Reads the interrupt pin to determine if interrupt is use by card.
226 * If the interrupt is used, then gets the interrupt line from the 206 * If the interrupt is used, then gets the interrupt line from the
diff --git a/arch/powerpc/kernel/pci-hotplug.c b/arch/powerpc/kernel/pci-hotplug.c
index c1e17ae68a08..5b789177aa29 100644
--- a/arch/powerpc/kernel/pci-hotplug.c
+++ b/arch/powerpc/kernel/pci-hotplug.c
@@ -98,8 +98,7 @@ void pcibios_add_pci_devices(struct pci_bus * bus)
98 max = bus->busn_res.start; 98 max = bus->busn_res.start;
99 for (pass = 0; pass < 2; pass++) { 99 for (pass = 0; pass < 2; pass++) {
100 list_for_each_entry(dev, &bus->devices, bus_list) { 100 list_for_each_entry(dev, &bus->devices, bus_list) {
101 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 101 if (pci_is_bridge(dev))
102 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
103 max = pci_scan_bridge(bus, dev, 102 max = pci_scan_bridge(bus, dev,
104 max, pass); 103 max, pass);
105 } 104 }
diff --git a/arch/powerpc/kernel/pci_of_scan.c b/arch/powerpc/kernel/pci_of_scan.c
index 83c26d829991..059e244484fe 100644
--- a/arch/powerpc/kernel/pci_of_scan.c
+++ b/arch/powerpc/kernel/pci_of_scan.c
@@ -362,8 +362,7 @@ static void __of_scan_bus(struct device_node *node, struct pci_bus *bus,
362 362
363 /* Now scan child busses */ 363 /* Now scan child busses */
364 list_for_each_entry(dev, &bus->devices, bus_list) { 364 list_for_each_entry(dev, &bus->devices, bus_list) {
365 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 365 if (pci_is_bridge(dev)) {
366 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
367 of_scan_pci_bridge(dev); 366 of_scan_pci_bridge(dev);
368 } 367 }
369 } 368 }
diff --git a/arch/s390/include/asm/pci.h b/arch/s390/include/asm/pci.h
index 2583466f576b..79b5f0783a30 100644
--- a/arch/s390/include/asm/pci.h
+++ b/arch/s390/include/asm/pci.h
@@ -120,6 +120,8 @@ static inline bool zdev_enabled(struct zpci_dev *zdev)
120 return (zdev->fh & (1UL << 31)) ? true : false; 120 return (zdev->fh & (1UL << 31)) ? true : false;
121} 121}
122 122
123extern const struct attribute_group *zpci_attr_groups[];
124
123/* ----------------------------------------------------------------------------- 125/* -----------------------------------------------------------------------------
124 Prototypes 126 Prototypes
125----------------------------------------------------------------------------- */ 127----------------------------------------------------------------------------- */
@@ -166,10 +168,6 @@ static inline void zpci_exit_slot(struct zpci_dev *zdev) {}
166struct zpci_dev *get_zdev(struct pci_dev *); 168struct zpci_dev *get_zdev(struct pci_dev *);
167struct zpci_dev *get_zdev_by_fid(u32); 169struct zpci_dev *get_zdev_by_fid(u32);
168 170
169/* sysfs */
170int zpci_sysfs_add_device(struct device *);
171void zpci_sysfs_remove_device(struct device *);
172
173/* DMA */ 171/* DMA */
174int zpci_dma_init(void); 172int zpci_dma_init(void);
175void zpci_dma_exit(void); 173void zpci_dma_exit(void);
diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c
index 1df1d29ac81d..bdf02570d1df 100644
--- a/arch/s390/pci/pci.c
+++ b/arch/s390/pci/pci.c
@@ -530,11 +530,6 @@ static void zpci_unmap_resources(struct zpci_dev *zdev)
530 } 530 }
531} 531}
532 532
533int pcibios_add_platform_entries(struct pci_dev *pdev)
534{
535 return zpci_sysfs_add_device(&pdev->dev);
536}
537
538static int __init zpci_irq_init(void) 533static int __init zpci_irq_init(void)
539{ 534{
540 int rc; 535 int rc;
@@ -671,6 +666,7 @@ int pcibios_add_device(struct pci_dev *pdev)
671 int i; 666 int i;
672 667
673 zdev->pdev = pdev; 668 zdev->pdev = pdev;
669 pdev->dev.groups = zpci_attr_groups;
674 zpci_map_resources(zdev); 670 zpci_map_resources(zdev);
675 671
676 for (i = 0; i < PCI_BAR_COUNT; i++) { 672 for (i = 0; i < PCI_BAR_COUNT; i++) {
diff --git a/arch/s390/pci/pci_sysfs.c b/arch/s390/pci/pci_sysfs.c
index ab4a91393005..b56a3958f1a7 100644
--- a/arch/s390/pci/pci_sysfs.c
+++ b/arch/s390/pci/pci_sysfs.c
@@ -72,36 +72,18 @@ static ssize_t store_recover(struct device *dev, struct device_attribute *attr,
72} 72}
73static DEVICE_ATTR(recover, S_IWUSR, NULL, store_recover); 73static DEVICE_ATTR(recover, S_IWUSR, NULL, store_recover);
74 74
75static struct device_attribute *zpci_dev_attrs[] = { 75static struct attribute *zpci_dev_attrs[] = {
76 &dev_attr_function_id, 76 &dev_attr_function_id.attr,
77 &dev_attr_function_handle, 77 &dev_attr_function_handle.attr,
78 &dev_attr_pchid, 78 &dev_attr_pchid.attr,
79 &dev_attr_pfgid, 79 &dev_attr_pfgid.attr,
80 &dev_attr_recover, 80 &dev_attr_recover.attr,
81 NULL,
82};
83static struct attribute_group zpci_attr_group = {
84 .attrs = zpci_dev_attrs,
85};
86const struct attribute_group *zpci_attr_groups[] = {
87 &zpci_attr_group,
81 NULL, 88 NULL,
82}; 89};
83
84int zpci_sysfs_add_device(struct device *dev)
85{
86 int i, rc = 0;
87
88 for (i = 0; zpci_dev_attrs[i]; i++) {
89 rc = device_create_file(dev, zpci_dev_attrs[i]);
90 if (rc)
91 goto error;
92 }
93 return 0;
94
95error:
96 while (--i >= 0)
97 device_remove_file(dev, zpci_dev_attrs[i]);
98 return rc;
99}
100
101void zpci_sysfs_remove_device(struct device *dev)
102{
103 int i;
104
105 for (i = 0; zpci_dev_attrs[i]; i++)
106 device_remove_file(dev, zpci_dev_attrs[i]);
107}
diff --git a/arch/sh/drivers/pci/fixups-dreamcast.c b/arch/sh/drivers/pci/fixups-dreamcast.c
index d6cde700e316..1d1c5a227e50 100644
--- a/arch/sh/drivers/pci/fixups-dreamcast.c
+++ b/arch/sh/drivers/pci/fixups-dreamcast.c
@@ -31,6 +31,8 @@
31static void gapspci_fixup_resources(struct pci_dev *dev) 31static void gapspci_fixup_resources(struct pci_dev *dev)
32{ 32{
33 struct pci_channel *p = dev->sysdata; 33 struct pci_channel *p = dev->sysdata;
34 struct resource res;
35 struct pci_bus_region region;
34 36
35 printk(KERN_NOTICE "PCI: Fixing up device %s\n", pci_name(dev)); 37 printk(KERN_NOTICE "PCI: Fixing up device %s\n", pci_name(dev));
36 38
@@ -50,11 +52,21 @@ static void gapspci_fixup_resources(struct pci_dev *dev)
50 52
51 /* 53 /*
52 * Redirect dma memory allocations to special memory window. 54 * Redirect dma memory allocations to special memory window.
55 *
56 * If this GAPSPCI region were mapped by a BAR, the CPU
57 * phys_addr_t would be pci_resource_start(), and the bus
58 * address would be pci_bus_address(pci_resource_start()).
59 * But apparently there's no BAR mapping it, so we just
60 * "know" its CPU address is GAPSPCI_DMA_BASE.
53 */ 61 */
62 res.start = GAPSPCI_DMA_BASE;
63 res.end = GAPSPCI_DMA_BASE + GAPSPCI_DMA_SIZE - 1;
64 res.flags = IORESOURCE_MEM;
65 pcibios_resource_to_bus(dev->bus, &region, &res);
54 BUG_ON(!dma_declare_coherent_memory(&dev->dev, 66 BUG_ON(!dma_declare_coherent_memory(&dev->dev,
55 GAPSPCI_DMA_BASE, 67 res.start,
56 GAPSPCI_DMA_BASE, 68 region.start,
57 GAPSPCI_DMA_SIZE, 69 resource_size(&res),
58 DMA_MEMORY_MAP | 70 DMA_MEMORY_MAP |
59 DMA_MEMORY_EXCLUSIVE)); 71 DMA_MEMORY_EXCLUSIVE));
60 break; 72 break;
diff --git a/arch/sh/include/asm/pci.h b/arch/sh/include/asm/pci.h
index bff96c2e7d25..5b4511552998 100644
--- a/arch/sh/include/asm/pci.h
+++ b/arch/sh/include/asm/pci.h
@@ -70,11 +70,6 @@ extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
70 enum pci_mmap_state mmap_state, int write_combine); 70 enum pci_mmap_state mmap_state, int write_combine);
71extern void pcibios_set_master(struct pci_dev *dev); 71extern void pcibios_set_master(struct pci_dev *dev);
72 72
73static inline void pcibios_penalize_isa_irq(int irq, int active)
74{
75 /* We don't do dynamic PCI IRQ allocation */
76}
77
78/* Dynamic DMA mapping stuff. 73/* Dynamic DMA mapping stuff.
79 * SuperH has everything mapped statically like x86. 74 * SuperH has everything mapped statically like x86.
80 */ 75 */
diff --git a/arch/sparc/include/asm/pci_32.h b/arch/sparc/include/asm/pci_32.h
index dc503297481f..53e9b4987db0 100644
--- a/arch/sparc/include/asm/pci_32.h
+++ b/arch/sparc/include/asm/pci_32.h
@@ -16,11 +16,6 @@
16 16
17#define PCI_IRQ_NONE 0xffffffff 17#define PCI_IRQ_NONE 0xffffffff
18 18
19static inline void pcibios_penalize_isa_irq(int irq, int active)
20{
21 /* We don't do dynamic PCI IRQ allocation */
22}
23
24/* Dynamic DMA mapping stuff. 19/* Dynamic DMA mapping stuff.
25 */ 20 */
26#define PCI_DMA_BUS_IS_PHYS (0) 21#define PCI_DMA_BUS_IS_PHYS (0)
diff --git a/arch/sparc/include/asm/pci_64.h b/arch/sparc/include/asm/pci_64.h
index 1633b718d3bc..c6c7396e7627 100644
--- a/arch/sparc/include/asm/pci_64.h
+++ b/arch/sparc/include/asm/pci_64.h
@@ -16,11 +16,6 @@
16 16
17#define PCI_IRQ_NONE 0xffffffff 17#define PCI_IRQ_NONE 0xffffffff
18 18
19static inline void pcibios_penalize_isa_irq(int irq, int active)
20{
21 /* We don't do dynamic PCI IRQ allocation */
22}
23
24/* The PCI address space does not equal the physical memory 19/* The PCI address space does not equal the physical memory
25 * address space. The networking and block device layers use 20 * address space. The networking and block device layers use
26 * this boolean for bounce buffer decisions. 21 * this boolean for bounce buffer decisions.
diff --git a/arch/sparc/kernel/pci.c b/arch/sparc/kernel/pci.c
index 1555bbcae1ee..857ad77df9c0 100644
--- a/arch/sparc/kernel/pci.c
+++ b/arch/sparc/kernel/pci.c
@@ -543,8 +543,7 @@ static void pci_of_scan_bus(struct pci_pbm_info *pbm,
543 printk("PCI: dev header type: %x\n", 543 printk("PCI: dev header type: %x\n",
544 dev->hdr_type); 544 dev->hdr_type);
545 545
546 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 546 if (pci_is_bridge(dev))
547 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
548 of_scan_pci_bridge(pbm, child, dev); 547 of_scan_pci_bridge(pbm, child, dev);
549 } 548 }
550} 549}
diff --git a/arch/unicore32/include/asm/pci.h b/arch/unicore32/include/asm/pci.h
index f5e108f4a151..654407e98619 100644
--- a/arch/unicore32/include/asm/pci.h
+++ b/arch/unicore32/include/asm/pci.h
@@ -18,11 +18,6 @@
18#include <asm-generic/pci.h> 18#include <asm-generic/pci.h>
19#include <mach/hardware.h> /* for PCIBIOS_MIN_* */ 19#include <mach/hardware.h> /* for PCIBIOS_MIN_* */
20 20
21static inline void pcibios_penalize_isa_irq(int irq, int active)
22{
23 /* We don't do dynamic PCI IRQ allocation */
24}
25
26#ifdef CONFIG_PCI 21#ifdef CONFIG_PCI
27static inline void pci_dma_burst_advice(struct pci_dev *pdev, 22static inline void pci_dma_burst_advice(struct pci_dev *pdev,
28 enum pci_dma_burst_strategy *strat, 23 enum pci_dma_burst_strategy *strat,
diff --git a/arch/x86/include/asm/pci.h b/arch/x86/include/asm/pci.h
index 96ae4f4040bb..0892ea0e683f 100644
--- a/arch/x86/include/asm/pci.h
+++ b/arch/x86/include/asm/pci.h
@@ -68,7 +68,6 @@ void pcibios_config_init(void);
68void pcibios_scan_root(int bus); 68void pcibios_scan_root(int bus);
69 69
70void pcibios_set_master(struct pci_dev *dev); 70void pcibios_set_master(struct pci_dev *dev);
71void pcibios_penalize_isa_irq(int irq, int active);
72struct irq_routing_table *pcibios_get_irq_routing_table(void); 71struct irq_routing_table *pcibios_get_irq_routing_table(void);
73int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq); 72int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
74 73
diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
index 9fa8aa051f54..76164e173a24 100644
--- a/arch/x86/kernel/aperture_64.c
+++ b/arch/x86/kernel/aperture_64.c
@@ -10,6 +10,8 @@
10 * 10 *
11 * Copyright 2002 Andi Kleen, SuSE Labs. 11 * Copyright 2002 Andi Kleen, SuSE Labs.
12 */ 12 */
13#define pr_fmt(fmt) "AGP: " fmt
14
13#include <linux/kernel.h> 15#include <linux/kernel.h>
14#include <linux/types.h> 16#include <linux/types.h>
15#include <linux/init.h> 17#include <linux/init.h>
@@ -75,14 +77,13 @@ static u32 __init allocate_aperture(void)
75 addr = memblock_find_in_range(GART_MIN_ADDR, GART_MAX_ADDR, 77 addr = memblock_find_in_range(GART_MIN_ADDR, GART_MAX_ADDR,
76 aper_size, aper_size); 78 aper_size, aper_size);
77 if (!addr) { 79 if (!addr) {
78 printk(KERN_ERR 80 pr_err("Cannot allocate aperture memory hole [mem %#010lx-%#010lx] (%uKB)\n",
79 "Cannot allocate aperture memory hole (%lx,%uK)\n", 81 addr, addr + aper_size - 1, aper_size >> 10);
80 addr, aper_size>>10);
81 return 0; 82 return 0;
82 } 83 }
83 memblock_reserve(addr, aper_size); 84 memblock_reserve(addr, aper_size);
84 printk(KERN_INFO "Mapping aperture over %d KB of RAM @ %lx\n", 85 pr_info("Mapping aperture over RAM [mem %#010lx-%#010lx] (%uKB)\n",
85 aper_size >> 10, addr); 86 addr, addr + aper_size - 1, aper_size >> 10);
86 register_nosave_region(addr >> PAGE_SHIFT, 87 register_nosave_region(addr >> PAGE_SHIFT,
87 (addr+aper_size) >> PAGE_SHIFT); 88 (addr+aper_size) >> PAGE_SHIFT);
88 89
@@ -126,10 +127,11 @@ static u32 __init read_agp(int bus, int slot, int func, int cap, u32 *order)
126 u64 aper; 127 u64 aper;
127 u32 old_order; 128 u32 old_order;
128 129
129 printk(KERN_INFO "AGP bridge at %02x:%02x:%02x\n", bus, slot, func); 130 pr_info("pci 0000:%02x:%02x:%02x: AGP bridge\n", bus, slot, func);
130 apsizereg = read_pci_config_16(bus, slot, func, cap + 0x14); 131 apsizereg = read_pci_config_16(bus, slot, func, cap + 0x14);
131 if (apsizereg == 0xffffffff) { 132 if (apsizereg == 0xffffffff) {
132 printk(KERN_ERR "APSIZE in AGP bridge unreadable\n"); 133 pr_err("pci 0000:%02x:%02x.%d: APSIZE unreadable\n",
134 bus, slot, func);
133 return 0; 135 return 0;
134 } 136 }
135 137
@@ -153,16 +155,18 @@ static u32 __init read_agp(int bus, int slot, int func, int cap, u32 *order)
153 * On some sick chips, APSIZE is 0. It means it wants 4G 155 * On some sick chips, APSIZE is 0. It means it wants 4G
154 * so let double check that order, and lets trust AMD NB settings: 156 * so let double check that order, and lets trust AMD NB settings:
155 */ 157 */
156 printk(KERN_INFO "Aperture from AGP @ %Lx old size %u MB\n", 158 pr_info("pci 0000:%02x:%02x.%d: AGP aperture [bus addr %#010Lx-%#010Lx] (old size %uMB)\n",
157 aper, 32 << old_order); 159 bus, slot, func, aper, aper + (32ULL << (old_order + 20)) - 1,
160 32 << old_order);
158 if (aper + (32ULL<<(20 + *order)) > 0x100000000ULL) { 161 if (aper + (32ULL<<(20 + *order)) > 0x100000000ULL) {
159 printk(KERN_INFO "Aperture size %u MB (APSIZE %x) is not right, using settings from NB\n", 162 pr_info("pci 0000:%02x:%02x.%d: AGP aperture size %uMB (APSIZE %#x) is not right, using settings from NB\n",
160 32 << *order, apsizereg); 163 bus, slot, func, 32 << *order, apsizereg);
161 *order = old_order; 164 *order = old_order;
162 } 165 }
163 166
164 printk(KERN_INFO "Aperture from AGP @ %Lx size %u MB (APSIZE %x)\n", 167 pr_info("pci 0000:%02x:%02x.%d: AGP aperture [bus addr %#010Lx-%#010Lx] (%uMB, APSIZE %#x)\n",
165 aper, 32 << *order, apsizereg); 168 bus, slot, func, aper, aper + (32ULL << (*order + 20)) - 1,
169 32 << *order, apsizereg);
166 170
167 if (!aperture_valid(aper, (32*1024*1024) << *order, 32<<20)) 171 if (!aperture_valid(aper, (32*1024*1024) << *order, 32<<20))
168 return 0; 172 return 0;
@@ -218,7 +222,7 @@ static u32 __init search_agp_bridge(u32 *order, int *valid_agp)
218 } 222 }
219 } 223 }
220 } 224 }
221 printk(KERN_INFO "No AGP bridge found\n"); 225 pr_info("No AGP bridge found\n");
222 226
223 return 0; 227 return 0;
224} 228}
@@ -310,7 +314,8 @@ void __init early_gart_iommu_check(void)
310 if (e820_any_mapped(aper_base, aper_base + aper_size, 314 if (e820_any_mapped(aper_base, aper_base + aper_size,
311 E820_RAM)) { 315 E820_RAM)) {
312 /* reserve it, so we can reuse it in second kernel */ 316 /* reserve it, so we can reuse it in second kernel */
313 printk(KERN_INFO "update e820 for GART\n"); 317 pr_info("e820: reserve [mem %#010Lx-%#010Lx] for GART\n",
318 aper_base, aper_base + aper_size - 1);
314 e820_add_region(aper_base, aper_size, E820_RESERVED); 319 e820_add_region(aper_base, aper_size, E820_RESERVED);
315 update_e820(); 320 update_e820();
316 } 321 }
@@ -354,7 +359,7 @@ int __init gart_iommu_hole_init(void)
354 !early_pci_allowed()) 359 !early_pci_allowed())
355 return -ENODEV; 360 return -ENODEV;
356 361
357 printk(KERN_INFO "Checking aperture...\n"); 362 pr_info("Checking aperture...\n");
358 363
359 if (!fallback_aper_force) 364 if (!fallback_aper_force)
360 agp_aper_base = search_agp_bridge(&agp_aper_order, &valid_agp); 365 agp_aper_base = search_agp_bridge(&agp_aper_order, &valid_agp);
@@ -395,8 +400,9 @@ int __init gart_iommu_hole_init(void)
395 aper_base = read_pci_config(bus, slot, 3, AMD64_GARTAPERTUREBASE) & 0x7fff; 400 aper_base = read_pci_config(bus, slot, 3, AMD64_GARTAPERTUREBASE) & 0x7fff;
396 aper_base <<= 25; 401 aper_base <<= 25;
397 402
398 printk(KERN_INFO "Node %d: aperture @ %Lx size %u MB\n", 403 pr_info("Node %d: aperture [bus addr %#010Lx-%#010Lx] (%uMB)\n",
399 node, aper_base, aper_size >> 20); 404 node, aper_base, aper_base + aper_size - 1,
405 aper_size >> 20);
400 node++; 406 node++;
401 407
402 if (!aperture_valid(aper_base, aper_size, 64<<20)) { 408 if (!aperture_valid(aper_base, aper_size, 64<<20)) {
@@ -407,9 +413,9 @@ int __init gart_iommu_hole_init(void)
407 if (!no_iommu && 413 if (!no_iommu &&
408 max_pfn > MAX_DMA32_PFN && 414 max_pfn > MAX_DMA32_PFN &&
409 !printed_gart_size_msg) { 415 !printed_gart_size_msg) {
410 printk(KERN_ERR "you are using iommu with agp, but GART size is less than 64M\n"); 416 pr_err("you are using iommu with agp, but GART size is less than 64MB\n");
411 printk(KERN_ERR "please increase GART size in your BIOS setup\n"); 417 pr_err("please increase GART size in your BIOS setup\n");
412 printk(KERN_ERR "if BIOS doesn't have that option, contact your HW vendor!\n"); 418 pr_err("if BIOS doesn't have that option, contact your HW vendor!\n");
413 printed_gart_size_msg = 1; 419 printed_gart_size_msg = 1;
414 } 420 }
415 } else { 421 } else {
@@ -446,13 +452,10 @@ out:
446 force_iommu || 452 force_iommu ||
447 valid_agp || 453 valid_agp ||
448 fallback_aper_force) { 454 fallback_aper_force) {
449 printk(KERN_INFO 455 pr_info("Your BIOS doesn't leave a aperture memory hole\n");
450 "Your BIOS doesn't leave a aperture memory hole\n"); 456 pr_info("Please enable the IOMMU option in the BIOS setup\n");
451 printk(KERN_INFO 457 pr_info("This costs you %dMB of RAM\n",
452 "Please enable the IOMMU option in the BIOS setup\n"); 458 32 << fallback_aper_order);
453 printk(KERN_INFO
454 "This costs you %d MB of RAM\n",
455 32 << fallback_aper_order);
456 459
457 aper_order = fallback_aper_order; 460 aper_order = fallback_aper_order;
458 aper_alloc = allocate_aperture(); 461 aper_alloc = allocate_aperture();
diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
index 01edac6c5e18..5075371ab593 100644
--- a/arch/x86/pci/acpi.c
+++ b/arch/x86/pci/acpi.c
@@ -489,8 +489,12 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
489 } 489 }
490 490
491 node = acpi_get_node(device->handle); 491 node = acpi_get_node(device->handle);
492 if (node == NUMA_NO_NODE) 492 if (node == NUMA_NO_NODE) {
493 node = x86_pci_root_bus_node(busnum); 493 node = x86_pci_root_bus_node(busnum);
494 if (node != 0 && node != NUMA_NO_NODE)
495 dev_info(&device->dev, FW_BUG "no _PXM; falling back to node %d from hardware (may be inconsistent with ACPI node numbers)\n",
496 node);
497 }
494 498
495 if (node != NUMA_NO_NODE && !node_online(node)) 499 if (node != NUMA_NO_NODE && !node_online(node))
496 node = NUMA_NO_NODE; 500 node = NUMA_NO_NODE;
diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
index e88f4c53d7f6..c20d2cc7ef64 100644
--- a/arch/x86/pci/amd_bus.c
+++ b/arch/x86/pci/amd_bus.c
@@ -11,27 +11,33 @@
11 11
12#include "bus_numa.h" 12#include "bus_numa.h"
13 13
14/* 14#define AMD_NB_F0_NODE_ID 0x60
15 * This discovers the pcibus <-> node mapping on AMD K8. 15#define AMD_NB_F0_UNIT_ID 0x64
16 * also get peer root bus resource for io,mmio 16#define AMD_NB_F1_CONFIG_MAP_REG 0xe0
17 */ 17
18#define RANGE_NUM 16
19#define AMD_NB_F1_CONFIG_MAP_RANGES 4
18 20
19struct pci_hostbridge_probe { 21struct amd_hostbridge {
20 u32 bus; 22 u32 bus;
21 u32 slot; 23 u32 slot;
22 u32 vendor;
23 u32 device; 24 u32 device;
24}; 25};
25 26
26static struct pci_hostbridge_probe pci_probes[] __initdata = { 27/*
27 { 0, 0x18, PCI_VENDOR_ID_AMD, 0x1100 }, 28 * IMPORTANT NOTE:
28 { 0, 0x18, PCI_VENDOR_ID_AMD, 0x1200 }, 29 * hb_probes[] and early_root_info_init() is in maintenance mode.
29 { 0xff, 0, PCI_VENDOR_ID_AMD, 0x1200 }, 30 * It only supports K8, Fam10h, Fam11h, and Fam15h_00h-0fh .
30 { 0, 0x18, PCI_VENDOR_ID_AMD, 0x1300 }, 31 * Future processor will rely on information in ACPI.
32 */
33static struct amd_hostbridge hb_probes[] __initdata = {
34 { 0, 0x18, 0x1100 }, /* K8 */
35 { 0, 0x18, 0x1200 }, /* Family10h */
36 { 0xff, 0, 0x1200 }, /* Family10h */
37 { 0, 0x18, 0x1300 }, /* Family11h */
38 { 0, 0x18, 0x1600 }, /* Family15h */
31}; 39};
32 40
33#define RANGE_NUM 16
34
35static struct pci_root_info __init *find_pci_root_info(int node, int link) 41static struct pci_root_info __init *find_pci_root_info(int node, int link)
36{ 42{
37 struct pci_root_info *info; 43 struct pci_root_info *info;
@@ -45,12 +51,12 @@ static struct pci_root_info __init *find_pci_root_info(int node, int link)
45} 51}
46 52
47/** 53/**
48 * early_fill_mp_bus_to_node() 54 * early_root_info_init()
49 * called before pcibios_scan_root and pci_scan_bus 55 * called before pcibios_scan_root and pci_scan_bus
50 * fills the mp_bus_to_cpumask array based according to the LDT Bus Number 56 * fills the mp_bus_to_cpumask array based according
51 * Registers found in the K8 northbridge 57 * to the LDT Bus Number Registers found in the northbridge.
52 */ 58 */
53static int __init early_fill_mp_bus_info(void) 59static int __init early_root_info_init(void)
54{ 60{
55 int i; 61 int i;
56 unsigned bus; 62 unsigned bus;
@@ -75,19 +81,21 @@ static int __init early_fill_mp_bus_info(void)
75 return -1; 81 return -1;
76 82
77 found = false; 83 found = false;
78 for (i = 0; i < ARRAY_SIZE(pci_probes); i++) { 84 for (i = 0; i < ARRAY_SIZE(hb_probes); i++) {
79 u32 id; 85 u32 id;
80 u16 device; 86 u16 device;
81 u16 vendor; 87 u16 vendor;
82 88
83 bus = pci_probes[i].bus; 89 bus = hb_probes[i].bus;
84 slot = pci_probes[i].slot; 90 slot = hb_probes[i].slot;
85 id = read_pci_config(bus, slot, 0, PCI_VENDOR_ID); 91 id = read_pci_config(bus, slot, 0, PCI_VENDOR_ID);
86
87 vendor = id & 0xffff; 92 vendor = id & 0xffff;
88 device = (id>>16) & 0xffff; 93 device = (id>>16) & 0xffff;
89 if (pci_probes[i].vendor == vendor && 94
90 pci_probes[i].device == device) { 95 if (vendor != PCI_VENDOR_ID_AMD)
96 continue;
97
98 if (hb_probes[i].device == device) {
91 found = true; 99 found = true;
92 break; 100 break;
93 } 101 }
@@ -96,10 +104,16 @@ static int __init early_fill_mp_bus_info(void)
96 if (!found) 104 if (!found)
97 return 0; 105 return 0;
98 106
99 for (i = 0; i < 4; i++) { 107 /*
108 * We should learn topology and routing information from _PXM and
109 * _CRS methods in the ACPI namespace. We extract node numbers
110 * here to work around BIOSes that don't supply _PXM.
111 */
112 for (i = 0; i < AMD_NB_F1_CONFIG_MAP_RANGES; i++) {
100 int min_bus; 113 int min_bus;
101 int max_bus; 114 int max_bus;
102 reg = read_pci_config(bus, slot, 1, 0xe0 + (i << 2)); 115 reg = read_pci_config(bus, slot, 1,
116 AMD_NB_F1_CONFIG_MAP_REG + (i << 2));
103 117
104 /* Check if that register is enabled for bus range */ 118 /* Check if that register is enabled for bus range */
105 if ((reg & 7) != 3) 119 if ((reg & 7) != 3)
@@ -113,10 +127,21 @@ static int __init early_fill_mp_bus_info(void)
113 info = alloc_pci_root_info(min_bus, max_bus, node, link); 127 info = alloc_pci_root_info(min_bus, max_bus, node, link);
114 } 128 }
115 129
130 /*
131 * The following code extracts routing information for use on old
132 * systems where Linux doesn't automatically use host bridge _CRS
133 * methods (or when the user specifies "pci=nocrs").
134 *
135 * We only do this through Fam11h, because _CRS should be enough on
136 * newer systems.
137 */
138 if (boot_cpu_data.x86 > 0x11)
139 return 0;
140
116 /* get the default node and link for left over res */ 141 /* get the default node and link for left over res */
117 reg = read_pci_config(bus, slot, 0, 0x60); 142 reg = read_pci_config(bus, slot, 0, AMD_NB_F0_NODE_ID);
118 def_node = (reg >> 8) & 0x07; 143 def_node = (reg >> 8) & 0x07;
119 reg = read_pci_config(bus, slot, 0, 0x64); 144 reg = read_pci_config(bus, slot, 0, AMD_NB_F0_UNIT_ID);
120 def_link = (reg >> 8) & 0x03; 145 def_link = (reg >> 8) & 0x03;
121 146
122 memset(range, 0, sizeof(range)); 147 memset(range, 0, sizeof(range));
@@ -363,7 +388,7 @@ static int __init pci_io_ecs_init(void)
363 int cpu; 388 int cpu;
364 389
365 /* assume all cpus from fam10h have IO ECS */ 390 /* assume all cpus from fam10h have IO ECS */
366 if (boot_cpu_data.x86 < 0x10) 391 if (boot_cpu_data.x86 < 0x10)
367 return 0; 392 return 0;
368 393
369 /* Try the PCI method first. */ 394 /* Try the PCI method first. */
@@ -387,7 +412,7 @@ static int __init amd_postcore_init(void)
387 if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) 412 if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
388 return 0; 413 return 0;
389 414
390 early_fill_mp_bus_info(); 415 early_root_info_init();
391 pci_io_ecs_init(); 416 pci_io_ecs_init();
392 417
393 return 0; 418 return 0;
diff --git a/arch/x86/pci/broadcom_bus.c b/arch/x86/pci/broadcom_bus.c
index 614392ced7d6..bb461cfd01ab 100644
--- a/arch/x86/pci/broadcom_bus.c
+++ b/arch/x86/pci/broadcom_bus.c
@@ -60,8 +60,8 @@ static void __init cnb20le_res(u8 bus, u8 slot, u8 func)
60 word1 = read_pci_config_16(bus, slot, func, 0xc4); 60 word1 = read_pci_config_16(bus, slot, func, 0xc4);
61 word2 = read_pci_config_16(bus, slot, func, 0xc6); 61 word2 = read_pci_config_16(bus, slot, func, 0xc6);
62 if (word1 != word2) { 62 if (word1 != word2) {
63 res.start = (word1 << 16) | 0x0000; 63 res.start = ((resource_size_t) word1 << 16) | 0x0000;
64 res.end = (word2 << 16) | 0xffff; 64 res.end = ((resource_size_t) word2 << 16) | 0xffff;
65 res.flags = IORESOURCE_MEM | IORESOURCE_PREFETCH; 65 res.flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
66 update_res(info, res.start, res.end, res.flags, 0); 66 update_res(info, res.start, res.end, res.flags, 0);
67 } 67 }
diff --git a/arch/x86/pci/fixup.c b/arch/x86/pci/fixup.c
index 94ae9ae9574f..b5e60268d93f 100644
--- a/arch/x86/pci/fixup.c
+++ b/arch/x86/pci/fixup.c
@@ -6,6 +6,7 @@
6#include <linux/dmi.h> 6#include <linux/dmi.h>
7#include <linux/pci.h> 7#include <linux/pci.h>
8#include <linux/vgaarb.h> 8#include <linux/vgaarb.h>
9#include <asm/hpet.h>
9#include <asm/pci_x86.h> 10#include <asm/pci_x86.h>
10 11
11static void pci_fixup_i450nx(struct pci_dev *d) 12static void pci_fixup_i450nx(struct pci_dev *d)
@@ -337,9 +338,7 @@ static void pci_fixup_video(struct pci_dev *pdev)
337 * type BRIDGE, or CARDBUS. Host to PCI controllers use 338 * type BRIDGE, or CARDBUS. Host to PCI controllers use
338 * PCI header type NORMAL. 339 * PCI header type NORMAL.
339 */ 340 */
340 if (bridge 341 if (bridge && (pci_is_bridge(bridge))) {
341 && ((bridge->hdr_type == PCI_HEADER_TYPE_BRIDGE)
342 || (bridge->hdr_type == PCI_HEADER_TYPE_CARDBUS))) {
343 pci_read_config_word(bridge, PCI_BRIDGE_CONTROL, 342 pci_read_config_word(bridge, PCI_BRIDGE_CONTROL,
344 &config); 343 &config);
345 if (!(config & PCI_BRIDGE_CTL_VGA)) 344 if (!(config & PCI_BRIDGE_CTL_VGA))
@@ -526,6 +525,19 @@ static void sb600_disable_hpet_bar(struct pci_dev *dev)
526} 525}
527DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATI, 0x4385, sb600_disable_hpet_bar); 526DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATI, 0x4385, sb600_disable_hpet_bar);
528 527
528#ifdef CONFIG_HPET_TIMER
529static void sb600_hpet_quirk(struct pci_dev *dev)
530{
531 struct resource *r = &dev->resource[1];
532
533 if (r->flags & IORESOURCE_MEM && r->start == hpet_address) {
534 r->flags |= IORESOURCE_PCI_FIXED;
535 dev_info(&dev->dev, "reg 0x14 contains HPET; making it immovable\n");
536 }
537}
538DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, 0x4385, sb600_hpet_quirk);
539#endif
540
529/* 541/*
530 * Twinhead H12Y needs us to block out a region otherwise we map devices 542 * Twinhead H12Y needs us to block out a region otherwise we map devices
531 * there and any access kills the box. 543 * there and any access kills the box.
diff --git a/arch/x86/pci/i386.c b/arch/x86/pci/i386.c
index db6b1ab43255..a19ed92e74e4 100644
--- a/arch/x86/pci/i386.c
+++ b/arch/x86/pci/i386.c
@@ -271,11 +271,16 @@ static void pcibios_allocate_dev_resources(struct pci_dev *dev, int pass)
271 "BAR %d: reserving %pr (d=%d, p=%d)\n", 271 "BAR %d: reserving %pr (d=%d, p=%d)\n",
272 idx, r, disabled, pass); 272 idx, r, disabled, pass);
273 if (pci_claim_resource(dev, idx) < 0) { 273 if (pci_claim_resource(dev, idx) < 0) {
274 /* We'll assign a new address later */ 274 if (r->flags & IORESOURCE_PCI_FIXED) {
275 pcibios_save_fw_addr(dev, 275 dev_info(&dev->dev, "BAR %d %pR is immovable\n",
276 idx, r->start); 276 idx, r);
277 r->end -= r->start; 277 } else {
278 r->start = 0; 278 /* We'll assign a new address later */
279 pcibios_save_fw_addr(dev,
280 idx, r->start);
281 r->end -= r->start;
282 r->start = 0;
283 }
279 } 284 }
280 } 285 }
281 } 286 }
@@ -356,6 +361,12 @@ static int __init pcibios_assign_resources(void)
356 return 0; 361 return 0;
357} 362}
358 363
364/**
365 * called in fs_initcall (one below subsys_initcall),
366 * give a chance for motherboard reserve resources
367 */
368fs_initcall(pcibios_assign_resources);
369
359void pcibios_resource_survey_bus(struct pci_bus *bus) 370void pcibios_resource_survey_bus(struct pci_bus *bus)
360{ 371{
361 dev_printk(KERN_DEBUG, &bus->dev, "Allocating resources\n"); 372 dev_printk(KERN_DEBUG, &bus->dev, "Allocating resources\n");
@@ -392,12 +403,6 @@ void __init pcibios_resource_survey(void)
392 ioapic_insert_resources(); 403 ioapic_insert_resources();
393} 404}
394 405
395/**
396 * called in fs_initcall (one below subsys_initcall),
397 * give a chance for motherboard reserve resources
398 */
399fs_initcall(pcibios_assign_resources);
400
401static const struct vm_operations_struct pci_mmap_ops = { 406static const struct vm_operations_struct pci_mmap_ops = {
402 .access = generic_access_phys, 407 .access = generic_access_phys,
403}; 408};
diff --git a/arch/xtensa/include/asm/pci.h b/arch/xtensa/include/asm/pci.h
index 614be031a79a..5d52dc43dfe7 100644
--- a/arch/xtensa/include/asm/pci.h
+++ b/arch/xtensa/include/asm/pci.h
@@ -22,11 +22,6 @@
22 22
23extern struct pci_controller* pcibios_alloc_controller(void); 23extern struct pci_controller* pcibios_alloc_controller(void);
24 24
25static inline void pcibios_penalize_isa_irq(int irq)
26{
27 /* We don't do dynamic PCI IRQ allocation */
28}
29
30/* Assume some values. (We should revise them, if necessary) */ 25/* Assume some values. (We should revise them, if necessary) */
31 26
32#define PCIBIOS_MIN_IO 0x2000 27#define PCIBIOS_MIN_IO 0x2000
diff --git a/drivers/base/dma-coherent.c b/drivers/base/dma-coherent.c
index bc256b641027..7d6e84a51424 100644
--- a/drivers/base/dma-coherent.c
+++ b/drivers/base/dma-coherent.c
@@ -10,13 +10,13 @@
10struct dma_coherent_mem { 10struct dma_coherent_mem {
11 void *virt_base; 11 void *virt_base;
12 dma_addr_t device_base; 12 dma_addr_t device_base;
13 phys_addr_t pfn_base; 13 unsigned long pfn_base;
14 int size; 14 int size;
15 int flags; 15 int flags;
16 unsigned long *bitmap; 16 unsigned long *bitmap;
17}; 17};
18 18
19int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, 19int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
20 dma_addr_t device_addr, size_t size, int flags) 20 dma_addr_t device_addr, size_t size, int flags)
21{ 21{
22 void __iomem *mem_base = NULL; 22 void __iomem *mem_base = NULL;
@@ -32,7 +32,7 @@ int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
32 32
33 /* FIXME: this routine just ignores DMA_MEMORY_INCLUDES_CHILDREN */ 33 /* FIXME: this routine just ignores DMA_MEMORY_INCLUDES_CHILDREN */
34 34
35 mem_base = ioremap(bus_addr, size); 35 mem_base = ioremap(phys_addr, size);
36 if (!mem_base) 36 if (!mem_base)
37 goto out; 37 goto out;
38 38
@@ -45,7 +45,7 @@ int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
45 45
46 dev->dma_mem->virt_base = mem_base; 46 dev->dma_mem->virt_base = mem_base;
47 dev->dma_mem->device_base = device_addr; 47 dev->dma_mem->device_base = device_addr;
48 dev->dma_mem->pfn_base = PFN_DOWN(bus_addr); 48 dev->dma_mem->pfn_base = PFN_DOWN(phys_addr);
49 dev->dma_mem->size = pages; 49 dev->dma_mem->size = pages;
50 dev->dma_mem->flags = flags; 50 dev->dma_mem->flags = flags;
51 51
@@ -208,7 +208,7 @@ int dma_mmap_from_coherent(struct device *dev, struct vm_area_struct *vma,
208 208
209 *ret = -ENXIO; 209 *ret = -ENXIO;
210 if (off < count && user_count <= count - off) { 210 if (off < count && user_count <= count - off) {
211 unsigned pfn = mem->pfn_base + start + off; 211 unsigned long pfn = mem->pfn_base + start + off;
212 *ret = remap_pfn_range(vma, vma->vm_start, pfn, 212 *ret = remap_pfn_range(vma, vma->vm_start, pfn,
213 user_count << PAGE_SHIFT, 213 user_count << PAGE_SHIFT,
214 vma->vm_page_prot); 214 vma->vm_page_prot);
diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c
index 0ce39a33b3c2..6cd08e145bfa 100644
--- a/drivers/base/dma-mapping.c
+++ b/drivers/base/dma-mapping.c
@@ -175,7 +175,7 @@ static void dmam_coherent_decl_release(struct device *dev, void *res)
175/** 175/**
176 * dmam_declare_coherent_memory - Managed dma_declare_coherent_memory() 176 * dmam_declare_coherent_memory - Managed dma_declare_coherent_memory()
177 * @dev: Device to declare coherent memory for 177 * @dev: Device to declare coherent memory for
178 * @bus_addr: Bus address of coherent memory to be declared 178 * @phys_addr: Physical address of coherent memory to be declared
179 * @device_addr: Device address of coherent memory to be declared 179 * @device_addr: Device address of coherent memory to be declared
180 * @size: Size of coherent memory to be declared 180 * @size: Size of coherent memory to be declared
181 * @flags: Flags 181 * @flags: Flags
@@ -185,7 +185,7 @@ static void dmam_coherent_decl_release(struct device *dev, void *res)
185 * RETURNS: 185 * RETURNS:
186 * 0 on success, -errno on failure. 186 * 0 on success, -errno on failure.
187 */ 187 */
188int dmam_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, 188int dmam_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
189 dma_addr_t device_addr, size_t size, int flags) 189 dma_addr_t device_addr, size_t size, int flags)
190{ 190{
191 void *res; 191 void *res;
@@ -195,7 +195,7 @@ int dmam_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
195 if (!res) 195 if (!res)
196 return -ENOMEM; 196 return -ENOMEM;
197 197
198 rc = dma_declare_coherent_memory(dev, bus_addr, device_addr, size, 198 rc = dma_declare_coherent_memory(dev, phys_addr, device_addr, size,
199 flags); 199 flags);
200 if (rc == 0) 200 if (rc == 0)
201 devres_add(dev, res); 201 devres_add(dev, res);
diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
index 7c64fa756cce..a842c71dcc21 100644
--- a/drivers/block/nvme-core.c
+++ b/drivers/block/nvme-core.c
@@ -2775,6 +2775,16 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2775 return result; 2775 return result;
2776} 2776}
2777 2777
2778static void nvme_reset_notify(struct pci_dev *pdev, bool prepare)
2779{
2780 struct nvme_dev *dev = pci_get_drvdata(pdev);
2781
2782 if (prepare)
2783 nvme_dev_shutdown(dev);
2784 else
2785 nvme_dev_resume(dev);
2786}
2787
2778static void nvme_shutdown(struct pci_dev *pdev) 2788static void nvme_shutdown(struct pci_dev *pdev)
2779{ 2789{
2780 struct nvme_dev *dev = pci_get_drvdata(pdev); 2790 struct nvme_dev *dev = pci_get_drvdata(pdev);
@@ -2839,6 +2849,7 @@ static const struct pci_error_handlers nvme_err_handler = {
2839 .link_reset = nvme_link_reset, 2849 .link_reset = nvme_link_reset,
2840 .slot_reset = nvme_slot_reset, 2850 .slot_reset = nvme_slot_reset,
2841 .resume = nvme_error_resume, 2851 .resume = nvme_error_resume,
2852 .reset_notify = nvme_reset_notify,
2842}; 2853};
2843 2854
2844/* Move to pci_ids.h later */ 2855/* Move to pci_ids.h later */
diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
index 8d0450b9b9af..64b68320249f 100644
--- a/drivers/edac/i82875p_edac.c
+++ b/drivers/edac/i82875p_edac.c
@@ -275,7 +275,6 @@ static int i82875p_setup_overfl_dev(struct pci_dev *pdev,
275{ 275{
276 struct pci_dev *dev; 276 struct pci_dev *dev;
277 void __iomem *window; 277 void __iomem *window;
278 int err;
279 278
280 *ovrfl_pdev = NULL; 279 *ovrfl_pdev = NULL;
281 *ovrfl_window = NULL; 280 *ovrfl_window = NULL;
@@ -293,13 +292,8 @@ static int i82875p_setup_overfl_dev(struct pci_dev *pdev,
293 if (dev == NULL) 292 if (dev == NULL)
294 return 1; 293 return 1;
295 294
296 err = pci_bus_add_device(dev);
297 if (err) {
298 i82875p_printk(KERN_ERR,
299 "%s(): pci_bus_add_device() Failed\n",
300 __func__);
301 }
302 pci_bus_assign_resources(dev->bus); 295 pci_bus_assign_resources(dev->bus);
296 pci_bus_add_device(dev);
303 } 297 }
304 298
305 *ovrfl_pdev = dev; 299 *ovrfl_pdev = dev;
diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c
index 074018979cdf..2ca0744b0a45 100644
--- a/drivers/iommu/exynos-iommu.c
+++ b/drivers/iommu/exynos-iommu.c
@@ -1011,13 +1011,13 @@ static phys_addr_t exynos_iommu_iova_to_phys(struct iommu_domain *domain,
1011} 1011}
1012 1012
1013static struct iommu_ops exynos_iommu_ops = { 1013static struct iommu_ops exynos_iommu_ops = {
1014 .domain_init = &exynos_iommu_domain_init, 1014 .domain_init = exynos_iommu_domain_init,
1015 .domain_destroy = &exynos_iommu_domain_destroy, 1015 .domain_destroy = exynos_iommu_domain_destroy,
1016 .attach_dev = &exynos_iommu_attach_device, 1016 .attach_dev = exynos_iommu_attach_device,
1017 .detach_dev = &exynos_iommu_detach_device, 1017 .detach_dev = exynos_iommu_detach_device,
1018 .map = &exynos_iommu_map, 1018 .map = exynos_iommu_map,
1019 .unmap = &exynos_iommu_unmap, 1019 .unmap = exynos_iommu_unmap,
1020 .iova_to_phys = &exynos_iommu_iova_to_phys, 1020 .iova_to_phys = exynos_iommu_iova_to_phys,
1021 .pgsize_bitmap = SECT_SIZE | LPAGE_SIZE | SPAGE_SIZE, 1021 .pgsize_bitmap = SECT_SIZE | LPAGE_SIZE | SPAGE_SIZE,
1022}; 1022};
1023 1023
diff --git a/drivers/misc/genwqe/card_utils.c b/drivers/misc/genwqe/card_utils.c
index d049d271699c..c00adfaa6279 100644
--- a/drivers/misc/genwqe/card_utils.c
+++ b/drivers/misc/genwqe/card_utils.c
@@ -718,7 +718,7 @@ int genwqe_set_interrupt_capability(struct genwqe_dev *cd, int count)
718 int rc; 718 int rc;
719 struct pci_dev *pci_dev = cd->pci_dev; 719 struct pci_dev *pci_dev = cd->pci_dev;
720 720
721 rc = pci_enable_msi_block(pci_dev, count); 721 rc = pci_enable_msi_exact(pci_dev, count);
722 if (rc == 0) 722 if (rc == 0)
723 cd->flags |= GENWQE_FLAG_MSI_ENABLED; 723 cd->flags |= GENWQE_FLAG_MSI_ENABLED;
724 return rc; 724 return rc;
diff --git a/drivers/pci/access.c b/drivers/pci/access.c
index 7f8b78c08879..8c148f39e8d7 100644
--- a/drivers/pci/access.c
+++ b/drivers/pci/access.c
@@ -148,7 +148,7 @@ static noinline void pci_wait_cfg(struct pci_dev *dev)
148int pci_user_read_config_##size \ 148int pci_user_read_config_##size \
149 (struct pci_dev *dev, int pos, type *val) \ 149 (struct pci_dev *dev, int pos, type *val) \
150{ \ 150{ \
151 int ret = 0; \ 151 int ret = PCIBIOS_SUCCESSFUL; \
152 u32 data = -1; \ 152 u32 data = -1; \
153 if (PCI_##size##_BAD) \ 153 if (PCI_##size##_BAD) \
154 return -EINVAL; \ 154 return -EINVAL; \
@@ -159,9 +159,7 @@ int pci_user_read_config_##size \
159 pos, sizeof(type), &data); \ 159 pos, sizeof(type), &data); \
160 raw_spin_unlock_irq(&pci_lock); \ 160 raw_spin_unlock_irq(&pci_lock); \
161 *val = (type)data; \ 161 *val = (type)data; \
162 if (ret > 0) \ 162 return pcibios_err_to_errno(ret); \
163 ret = -EINVAL; \
164 return ret; \
165} \ 163} \
166EXPORT_SYMBOL_GPL(pci_user_read_config_##size); 164EXPORT_SYMBOL_GPL(pci_user_read_config_##size);
167 165
@@ -170,7 +168,7 @@ EXPORT_SYMBOL_GPL(pci_user_read_config_##size);
170int pci_user_write_config_##size \ 168int pci_user_write_config_##size \
171 (struct pci_dev *dev, int pos, type val) \ 169 (struct pci_dev *dev, int pos, type val) \
172{ \ 170{ \
173 int ret = -EIO; \ 171 int ret = PCIBIOS_SUCCESSFUL; \
174 if (PCI_##size##_BAD) \ 172 if (PCI_##size##_BAD) \
175 return -EINVAL; \ 173 return -EINVAL; \
176 raw_spin_lock_irq(&pci_lock); \ 174 raw_spin_lock_irq(&pci_lock); \
@@ -179,9 +177,7 @@ int pci_user_write_config_##size \
179 ret = dev->bus->ops->write(dev->bus, dev->devfn, \ 177 ret = dev->bus->ops->write(dev->bus, dev->devfn, \
180 pos, sizeof(type), val); \ 178 pos, sizeof(type), val); \
181 raw_spin_unlock_irq(&pci_lock); \ 179 raw_spin_unlock_irq(&pci_lock); \
182 if (ret > 0) \ 180 return pcibios_err_to_errno(ret); \
183 ret = -EINVAL; \
184 return ret; \
185} \ 181} \
186EXPORT_SYMBOL_GPL(pci_user_write_config_##size); 182EXPORT_SYMBOL_GPL(pci_user_write_config_##size);
187 183
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index fb8aed307c28..447d393725e1 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -13,7 +13,6 @@
13#include <linux/errno.h> 13#include <linux/errno.h>
14#include <linux/ioport.h> 14#include <linux/ioport.h>
15#include <linux/proc_fs.h> 15#include <linux/proc_fs.h>
16#include <linux/init.h>
17#include <linux/slab.h> 16#include <linux/slab.h>
18 17
19#include "pci.h" 18#include "pci.h"
@@ -236,7 +235,7 @@ void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { }
236 * 235 *
237 * This adds add sysfs entries and start device drivers 236 * This adds add sysfs entries and start device drivers
238 */ 237 */
239int pci_bus_add_device(struct pci_dev *dev) 238void pci_bus_add_device(struct pci_dev *dev)
240{ 239{
241 int retval; 240 int retval;
242 241
@@ -253,8 +252,6 @@ int pci_bus_add_device(struct pci_dev *dev)
253 WARN_ON(retval < 0); 252 WARN_ON(retval < 0);
254 253
255 dev->is_added = 1; 254 dev->is_added = 1;
256
257 return 0;
258} 255}
259 256
260/** 257/**
@@ -267,16 +264,12 @@ void pci_bus_add_devices(const struct pci_bus *bus)
267{ 264{
268 struct pci_dev *dev; 265 struct pci_dev *dev;
269 struct pci_bus *child; 266 struct pci_bus *child;
270 int retval;
271 267
272 list_for_each_entry(dev, &bus->devices, bus_list) { 268 list_for_each_entry(dev, &bus->devices, bus_list) {
273 /* Skip already-added devices */ 269 /* Skip already-added devices */
274 if (dev->is_added) 270 if (dev->is_added)
275 continue; 271 continue;
276 retval = pci_bus_add_device(dev); 272 pci_bus_add_device(dev);
277 if (retval)
278 dev_err(&dev->dev, "Error adding device (%d)\n",
279 retval);
280 } 273 }
281 274
282 list_for_each_entry(dev, &bus->devices, bus_list) { 275 list_for_each_entry(dev, &bus->devices, bus_list) {
diff --git a/drivers/pci/host-bridge.c b/drivers/pci/host-bridge.c
index 47aaf22d814e..0e5f3c95af5b 100644
--- a/drivers/pci/host-bridge.c
+++ b/drivers/pci/host-bridge.c
@@ -3,7 +3,6 @@
3 */ 3 */
4 4
5#include <linux/kernel.h> 5#include <linux/kernel.h>
6#include <linux/init.h>
7#include <linux/pci.h> 6#include <linux/pci.h>
8#include <linux/module.h> 7#include <linux/module.h>
9 8
diff --git a/drivers/pci/host/Kconfig b/drivers/pci/host/Kconfig
index a6f67ec8882f..21df477be0c8 100644
--- a/drivers/pci/host/Kconfig
+++ b/drivers/pci/host/Kconfig
@@ -33,4 +33,17 @@ config PCI_RCAR_GEN2
33 There are 3 internal PCI controllers available with a single 33 There are 3 internal PCI controllers available with a single
34 built-in EHCI/OHCI host controller present on each one. 34 built-in EHCI/OHCI host controller present on each one.
35 35
36config PCI_RCAR_GEN2_PCIE
37 bool "Renesas R-Car PCIe controller"
38 depends on ARCH_SHMOBILE || (ARM && COMPILE_TEST)
39 help
40 Say Y here if you want PCIe controller support on R-Car Gen2 SoCs.
41
42config PCI_HOST_GENERIC
43 bool "Generic PCI host controller"
44 depends on ARM && OF
45 help
46 Say Y here if you want to support a simple generic PCI host
47 controller, such as the one emulated by kvmtool.
48
36endmenu 49endmenu
diff --git a/drivers/pci/host/Makefile b/drivers/pci/host/Makefile
index 13fb3333aa05..611ba4b48c94 100644
--- a/drivers/pci/host/Makefile
+++ b/drivers/pci/host/Makefile
@@ -4,3 +4,5 @@ obj-$(CONFIG_PCI_IMX6) += pci-imx6.o
4obj-$(CONFIG_PCI_MVEBU) += pci-mvebu.o 4obj-$(CONFIG_PCI_MVEBU) += pci-mvebu.o
5obj-$(CONFIG_PCI_TEGRA) += pci-tegra.o 5obj-$(CONFIG_PCI_TEGRA) += pci-tegra.o
6obj-$(CONFIG_PCI_RCAR_GEN2) += pci-rcar-gen2.o 6obj-$(CONFIG_PCI_RCAR_GEN2) += pci-rcar-gen2.o
7obj-$(CONFIG_PCI_RCAR_GEN2_PCIE) += pcie-rcar.o
8obj-$(CONFIG_PCI_HOST_GENERIC) += pci-host-generic.o
diff --git a/drivers/pci/host/pci-exynos.c b/drivers/pci/host/pci-exynos.c
index 3de6bfbbe8e9..1632661c5b7f 100644
--- a/drivers/pci/host/pci-exynos.c
+++ b/drivers/pci/host/pci-exynos.c
@@ -415,9 +415,7 @@ static irqreturn_t exynos_pcie_msi_irq_handler(int irq, void *arg)
415{ 415{
416 struct pcie_port *pp = arg; 416 struct pcie_port *pp = arg;
417 417
418 dw_handle_msi_irq(pp); 418 return dw_handle_msi_irq(pp);
419
420 return IRQ_HANDLED;
421} 419}
422 420
423static void exynos_pcie_msi_init(struct pcie_port *pp) 421static void exynos_pcie_msi_init(struct pcie_port *pp)
@@ -511,7 +509,8 @@ static struct pcie_host_ops exynos_pcie_host_ops = {
511 .host_init = exynos_pcie_host_init, 509 .host_init = exynos_pcie_host_init,
512}; 510};
513 511
514static int add_pcie_port(struct pcie_port *pp, struct platform_device *pdev) 512static int __init add_pcie_port(struct pcie_port *pp,
513 struct platform_device *pdev)
515{ 514{
516 int ret; 515 int ret;
517 516
@@ -568,10 +567,8 @@ static int __init exynos_pcie_probe(struct platform_device *pdev)
568 567
569 exynos_pcie = devm_kzalloc(&pdev->dev, sizeof(*exynos_pcie), 568 exynos_pcie = devm_kzalloc(&pdev->dev, sizeof(*exynos_pcie),
570 GFP_KERNEL); 569 GFP_KERNEL);
571 if (!exynos_pcie) { 570 if (!exynos_pcie)
572 dev_err(&pdev->dev, "no memory for exynos pcie\n");
573 return -ENOMEM; 571 return -ENOMEM;
574 }
575 572
576 pp = &exynos_pcie->pp; 573 pp = &exynos_pcie->pp;
577 574
diff --git a/drivers/pci/host/pci-host-generic.c b/drivers/pci/host/pci-host-generic.c
new file mode 100644
index 000000000000..44fe6aa6a43f
--- /dev/null
+++ b/drivers/pci/host/pci-host-generic.c
@@ -0,0 +1,388 @@
1/*
2 * Simple, generic PCI host controller driver targetting firmware-initialised
3 * systems and virtual machines (e.g. the PCI emulation provided by kvmtool).
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright (C) 2014 ARM Limited
18 *
19 * Author: Will Deacon <will.deacon@arm.com>
20 */
21
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/of_address.h>
25#include <linux/of_pci.h>
26#include <linux/platform_device.h>
27
28struct gen_pci_cfg_bus_ops {
29 u32 bus_shift;
30 void __iomem *(*map_bus)(struct pci_bus *, unsigned int, int);
31};
32
33struct gen_pci_cfg_windows {
34 struct resource res;
35 struct resource bus_range;
36 void __iomem **win;
37
38 const struct gen_pci_cfg_bus_ops *ops;
39};
40
41struct gen_pci {
42 struct pci_host_bridge host;
43 struct gen_pci_cfg_windows cfg;
44 struct list_head resources;
45};
46
47static void __iomem *gen_pci_map_cfg_bus_cam(struct pci_bus *bus,
48 unsigned int devfn,
49 int where)
50{
51 struct pci_sys_data *sys = bus->sysdata;
52 struct gen_pci *pci = sys->private_data;
53 resource_size_t idx = bus->number - pci->cfg.bus_range.start;
54
55 return pci->cfg.win[idx] + ((devfn << 8) | where);
56}
57
58static struct gen_pci_cfg_bus_ops gen_pci_cfg_cam_bus_ops = {
59 .bus_shift = 16,
60 .map_bus = gen_pci_map_cfg_bus_cam,
61};
62
63static void __iomem *gen_pci_map_cfg_bus_ecam(struct pci_bus *bus,
64 unsigned int devfn,
65 int where)
66{
67 struct pci_sys_data *sys = bus->sysdata;
68 struct gen_pci *pci = sys->private_data;
69 resource_size_t idx = bus->number - pci->cfg.bus_range.start;
70
71 return pci->cfg.win[idx] + ((devfn << 12) | where);
72}
73
74static struct gen_pci_cfg_bus_ops gen_pci_cfg_ecam_bus_ops = {
75 .bus_shift = 20,
76 .map_bus = gen_pci_map_cfg_bus_ecam,
77};
78
79static int gen_pci_config_read(struct pci_bus *bus, unsigned int devfn,
80 int where, int size, u32 *val)
81{
82 void __iomem *addr;
83 struct pci_sys_data *sys = bus->sysdata;
84 struct gen_pci *pci = sys->private_data;
85
86 addr = pci->cfg.ops->map_bus(bus, devfn, where);
87
88 switch (size) {
89 case 1:
90 *val = readb(addr);
91 break;
92 case 2:
93 *val = readw(addr);
94 break;
95 default:
96 *val = readl(addr);
97 }
98
99 return PCIBIOS_SUCCESSFUL;
100}
101
102static int gen_pci_config_write(struct pci_bus *bus, unsigned int devfn,
103 int where, int size, u32 val)
104{
105 void __iomem *addr;
106 struct pci_sys_data *sys = bus->sysdata;
107 struct gen_pci *pci = sys->private_data;
108
109 addr = pci->cfg.ops->map_bus(bus, devfn, where);
110
111 switch (size) {
112 case 1:
113 writeb(val, addr);
114 break;
115 case 2:
116 writew(val, addr);
117 break;
118 default:
119 writel(val, addr);
120 }
121
122 return PCIBIOS_SUCCESSFUL;
123}
124
125static struct pci_ops gen_pci_ops = {
126 .read = gen_pci_config_read,
127 .write = gen_pci_config_write,
128};
129
130static const struct of_device_id gen_pci_of_match[] = {
131 { .compatible = "pci-host-cam-generic",
132 .data = &gen_pci_cfg_cam_bus_ops },
133
134 { .compatible = "pci-host-ecam-generic",
135 .data = &gen_pci_cfg_ecam_bus_ops },
136
137 { },
138};
139MODULE_DEVICE_TABLE(of, gen_pci_of_match);
140
141static int gen_pci_calc_io_offset(struct device *dev,
142 struct of_pci_range *range,
143 struct resource *res,
144 resource_size_t *offset)
145{
146 static atomic_t wins = ATOMIC_INIT(0);
147 int err, idx, max_win;
148 unsigned int window;
149
150 if (!PAGE_ALIGNED(range->cpu_addr))
151 return -EINVAL;
152
153 max_win = (IO_SPACE_LIMIT + 1) / SZ_64K;
154 idx = atomic_inc_return(&wins);
155 if (idx > max_win)
156 return -ENOSPC;
157
158 window = (idx - 1) * SZ_64K;
159 err = pci_ioremap_io(window, range->cpu_addr);
160 if (err)
161 return err;
162
163 of_pci_range_to_resource(range, dev->of_node, res);
164 res->start = window;
165 res->end = res->start + range->size - 1;
166 *offset = window - range->pci_addr;
167 return 0;
168}
169
170static int gen_pci_calc_mem_offset(struct device *dev,
171 struct of_pci_range *range,
172 struct resource *res,
173 resource_size_t *offset)
174{
175 of_pci_range_to_resource(range, dev->of_node, res);
176 *offset = range->cpu_addr - range->pci_addr;
177 return 0;
178}
179
180static void gen_pci_release_of_pci_ranges(struct gen_pci *pci)
181{
182 struct pci_host_bridge_window *win;
183
184 list_for_each_entry(win, &pci->resources, list)
185 release_resource(win->res);
186
187 pci_free_resource_list(&pci->resources);
188}
189
190static int gen_pci_parse_request_of_pci_ranges(struct gen_pci *pci)
191{
192 struct of_pci_range range;
193 struct of_pci_range_parser parser;
194 int err, res_valid = 0;
195 struct device *dev = pci->host.dev.parent;
196 struct device_node *np = dev->of_node;
197
198 if (of_pci_range_parser_init(&parser, np)) {
199 dev_err(dev, "missing \"ranges\" property\n");
200 return -EINVAL;
201 }
202
203 for_each_of_pci_range(&parser, &range) {
204 struct resource *parent, *res;
205 resource_size_t offset;
206 u32 restype = range.flags & IORESOURCE_TYPE_BITS;
207
208 res = devm_kmalloc(dev, sizeof(*res), GFP_KERNEL);
209 if (!res) {
210 err = -ENOMEM;
211 goto out_release_res;
212 }
213
214 switch (restype) {
215 case IORESOURCE_IO:
216 parent = &ioport_resource;
217 err = gen_pci_calc_io_offset(dev, &range, res, &offset);
218 break;
219 case IORESOURCE_MEM:
220 parent = &iomem_resource;
221 err = gen_pci_calc_mem_offset(dev, &range, res, &offset);
222 res_valid |= !(res->flags & IORESOURCE_PREFETCH || err);
223 break;
224 default:
225 err = -EINVAL;
226 continue;
227 }
228
229 if (err) {
230 dev_warn(dev,
231 "error %d: failed to add resource [type 0x%x, %lld bytes]\n",
232 err, restype, range.size);
233 continue;
234 }
235
236 err = request_resource(parent, res);
237 if (err)
238 goto out_release_res;
239
240 pci_add_resource_offset(&pci->resources, res, offset);
241 }
242
243 if (!res_valid) {
244 dev_err(dev, "non-prefetchable memory resource required\n");
245 err = -EINVAL;
246 goto out_release_res;
247 }
248
249 return 0;
250
251out_release_res:
252 gen_pci_release_of_pci_ranges(pci);
253 return err;
254}
255
256static int gen_pci_parse_map_cfg_windows(struct gen_pci *pci)
257{
258 int err;
259 u8 bus_max;
260 resource_size_t busn;
261 struct resource *bus_range;
262 struct device *dev = pci->host.dev.parent;
263 struct device_node *np = dev->of_node;
264
265 if (of_pci_parse_bus_range(np, &pci->cfg.bus_range))
266 pci->cfg.bus_range = (struct resource) {
267 .name = np->name,
268 .start = 0,
269 .end = 0xff,
270 .flags = IORESOURCE_BUS,
271 };
272
273 err = of_address_to_resource(np, 0, &pci->cfg.res);
274 if (err) {
275 dev_err(dev, "missing \"reg\" property\n");
276 return err;
277 }
278
279 pci->cfg.win = devm_kcalloc(dev, resource_size(&pci->cfg.bus_range),
280 sizeof(*pci->cfg.win), GFP_KERNEL);
281 if (!pci->cfg.win)
282 return -ENOMEM;
283
284 /* Limit the bus-range to fit within reg */
285 bus_max = pci->cfg.bus_range.start +
286 (resource_size(&pci->cfg.res) >> pci->cfg.ops->bus_shift) - 1;
287 pci->cfg.bus_range.end = min_t(resource_size_t, pci->cfg.bus_range.end,
288 bus_max);
289
290 /* Map our Configuration Space windows */
291 if (!devm_request_mem_region(dev, pci->cfg.res.start,
292 resource_size(&pci->cfg.res),
293 "Configuration Space"))
294 return -ENOMEM;
295
296 bus_range = &pci->cfg.bus_range;
297 for (busn = bus_range->start; busn <= bus_range->end; ++busn) {
298 u32 idx = busn - bus_range->start;
299 u32 sz = 1 << pci->cfg.ops->bus_shift;
300
301 pci->cfg.win[idx] = devm_ioremap(dev,
302 pci->cfg.res.start + busn * sz,
303 sz);
304 if (!pci->cfg.win[idx])
305 return -ENOMEM;
306 }
307
308 /* Register bus resource */
309 pci_add_resource(&pci->resources, bus_range);
310 return 0;
311}
312
313static int gen_pci_setup(int nr, struct pci_sys_data *sys)
314{
315 struct gen_pci *pci = sys->private_data;
316 list_splice_init(&pci->resources, &sys->resources);
317 return 1;
318}
319
320static int gen_pci_probe(struct platform_device *pdev)
321{
322 int err;
323 const char *type;
324 const struct of_device_id *of_id;
325 const int *prop;
326 struct device *dev = &pdev->dev;
327 struct device_node *np = dev->of_node;
328 struct gen_pci *pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
329 struct hw_pci hw = {
330 .nr_controllers = 1,
331 .private_data = (void **)&pci,
332 .setup = gen_pci_setup,
333 .map_irq = of_irq_parse_and_map_pci,
334 .ops = &gen_pci_ops,
335 };
336
337 if (!pci)
338 return -ENOMEM;
339
340 type = of_get_property(np, "device_type", NULL);
341 if (!type || strcmp(type, "pci")) {
342 dev_err(dev, "invalid \"device_type\" %s\n", type);
343 return -EINVAL;
344 }
345
346 prop = of_get_property(of_chosen, "linux,pci-probe-only", NULL);
347 if (prop) {
348 if (*prop)
349 pci_add_flags(PCI_PROBE_ONLY);
350 else
351 pci_clear_flags(PCI_PROBE_ONLY);
352 }
353
354 of_id = of_match_node(gen_pci_of_match, np);
355 pci->cfg.ops = of_id->data;
356 pci->host.dev.parent = dev;
357 INIT_LIST_HEAD(&pci->host.windows);
358 INIT_LIST_HEAD(&pci->resources);
359
360 /* Parse our PCI ranges and request their resources */
361 err = gen_pci_parse_request_of_pci_ranges(pci);
362 if (err)
363 return err;
364
365 /* Parse and map our Configuration Space windows */
366 err = gen_pci_parse_map_cfg_windows(pci);
367 if (err) {
368 gen_pci_release_of_pci_ranges(pci);
369 return err;
370 }
371
372 pci_common_init_dev(dev, &hw);
373 return 0;
374}
375
376static struct platform_driver gen_pci_driver = {
377 .driver = {
378 .name = "pci-host-generic",
379 .owner = THIS_MODULE,
380 .of_match_table = gen_pci_of_match,
381 },
382 .probe = gen_pci_probe,
383};
384module_platform_driver(gen_pci_driver);
385
386MODULE_DESCRIPTION("Generic PCI host driver");
387MODULE_AUTHOR("Will Deacon <will.deacon@arm.com>");
388MODULE_LICENSE("GPLv2");
diff --git a/drivers/pci/host/pci-imx6.c b/drivers/pci/host/pci-imx6.c
index ee082509b0ba..a5645ae4aef0 100644
--- a/drivers/pci/host/pci-imx6.c
+++ b/drivers/pci/host/pci-imx6.c
@@ -25,6 +25,7 @@
25#include <linux/resource.h> 25#include <linux/resource.h>
26#include <linux/signal.h> 26#include <linux/signal.h>
27#include <linux/types.h> 27#include <linux/types.h>
28#include <linux/interrupt.h>
28 29
29#include "pcie-designware.h" 30#include "pcie-designware.h"
30 31
@@ -32,13 +33,9 @@
32 33
33struct imx6_pcie { 34struct imx6_pcie {
34 int reset_gpio; 35 int reset_gpio;
35 int power_on_gpio; 36 struct clk *pcie_bus;
36 int wake_up_gpio; 37 struct clk *pcie_phy;
37 int disable_gpio; 38 struct clk *pcie;
38 struct clk *lvds_gate;
39 struct clk *sata_ref_100m;
40 struct clk *pcie_ref_125m;
41 struct clk *pcie_axi;
42 struct pcie_port pp; 39 struct pcie_port pp;
43 struct regmap *iomuxc_gpr; 40 struct regmap *iomuxc_gpr;
44 void __iomem *mem_base; 41 void __iomem *mem_base;
@@ -231,36 +228,27 @@ static int imx6_pcie_deassert_core_reset(struct pcie_port *pp)
231 struct imx6_pcie *imx6_pcie = to_imx6_pcie(pp); 228 struct imx6_pcie *imx6_pcie = to_imx6_pcie(pp);
232 int ret; 229 int ret;
233 230
234 if (gpio_is_valid(imx6_pcie->power_on_gpio))
235 gpio_set_value(imx6_pcie->power_on_gpio, 1);
236
237 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1, 231 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
238 IMX6Q_GPR1_PCIE_TEST_PD, 0 << 18); 232 IMX6Q_GPR1_PCIE_TEST_PD, 0 << 18);
239 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1, 233 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
240 IMX6Q_GPR1_PCIE_REF_CLK_EN, 1 << 16); 234 IMX6Q_GPR1_PCIE_REF_CLK_EN, 1 << 16);
241 235
242 ret = clk_prepare_enable(imx6_pcie->sata_ref_100m); 236 ret = clk_prepare_enable(imx6_pcie->pcie_phy);
243 if (ret) {
244 dev_err(pp->dev, "unable to enable sata_ref_100m\n");
245 goto err_sata_ref;
246 }
247
248 ret = clk_prepare_enable(imx6_pcie->pcie_ref_125m);
249 if (ret) { 237 if (ret) {
250 dev_err(pp->dev, "unable to enable pcie_ref_125m\n"); 238 dev_err(pp->dev, "unable to enable pcie_phy clock\n");
251 goto err_pcie_ref; 239 goto err_pcie_phy;
252 } 240 }
253 241
254 ret = clk_prepare_enable(imx6_pcie->lvds_gate); 242 ret = clk_prepare_enable(imx6_pcie->pcie_bus);
255 if (ret) { 243 if (ret) {
256 dev_err(pp->dev, "unable to enable lvds_gate\n"); 244 dev_err(pp->dev, "unable to enable pcie_bus clock\n");
257 goto err_lvds_gate; 245 goto err_pcie_bus;
258 } 246 }
259 247
260 ret = clk_prepare_enable(imx6_pcie->pcie_axi); 248 ret = clk_prepare_enable(imx6_pcie->pcie);
261 if (ret) { 249 if (ret) {
262 dev_err(pp->dev, "unable to enable pcie_axi\n"); 250 dev_err(pp->dev, "unable to enable pcie clock\n");
263 goto err_pcie_axi; 251 goto err_pcie;
264 } 252 }
265 253
266 /* allow the clocks to stabilize */ 254 /* allow the clocks to stabilize */
@@ -274,13 +262,11 @@ static int imx6_pcie_deassert_core_reset(struct pcie_port *pp)
274 } 262 }
275 return 0; 263 return 0;
276 264
277err_pcie_axi: 265err_pcie:
278 clk_disable_unprepare(imx6_pcie->lvds_gate); 266 clk_disable_unprepare(imx6_pcie->pcie_bus);
279err_lvds_gate: 267err_pcie_bus:
280 clk_disable_unprepare(imx6_pcie->pcie_ref_125m); 268 clk_disable_unprepare(imx6_pcie->pcie_phy);
281err_pcie_ref: 269err_pcie_phy:
282 clk_disable_unprepare(imx6_pcie->sata_ref_100m);
283err_sata_ref:
284 return ret; 270 return ret;
285 271
286} 272}
@@ -329,6 +315,13 @@ static int imx6_pcie_wait_for_link(struct pcie_port *pp)
329 return 0; 315 return 0;
330} 316}
331 317
318static irqreturn_t imx6_pcie_msi_handler(int irq, void *arg)
319{
320 struct pcie_port *pp = arg;
321
322 return dw_handle_msi_irq(pp);
323}
324
332static int imx6_pcie_start_link(struct pcie_port *pp) 325static int imx6_pcie_start_link(struct pcie_port *pp)
333{ 326{
334 struct imx6_pcie *imx6_pcie = to_imx6_pcie(pp); 327 struct imx6_pcie *imx6_pcie = to_imx6_pcie(pp);
@@ -403,6 +396,9 @@ static void imx6_pcie_host_init(struct pcie_port *pp)
403 dw_pcie_setup_rc(pp); 396 dw_pcie_setup_rc(pp);
404 397
405 imx6_pcie_start_link(pp); 398 imx6_pcie_start_link(pp);
399
400 if (IS_ENABLED(CONFIG_PCI_MSI))
401 dw_pcie_msi_init(pp);
406} 402}
407 403
408static void imx6_pcie_reset_phy(struct pcie_port *pp) 404static void imx6_pcie_reset_phy(struct pcie_port *pp)
@@ -487,15 +483,25 @@ static struct pcie_host_ops imx6_pcie_host_ops = {
487 .host_init = imx6_pcie_host_init, 483 .host_init = imx6_pcie_host_init,
488}; 484};
489 485
490static int imx6_add_pcie_port(struct pcie_port *pp, 486static int __init imx6_add_pcie_port(struct pcie_port *pp,
491 struct platform_device *pdev) 487 struct platform_device *pdev)
492{ 488{
493 int ret; 489 int ret;
494 490
495 pp->irq = platform_get_irq(pdev, 0); 491 if (IS_ENABLED(CONFIG_PCI_MSI)) {
496 if (!pp->irq) { 492 pp->msi_irq = platform_get_irq_byname(pdev, "msi");
497 dev_err(&pdev->dev, "failed to get irq\n"); 493 if (pp->msi_irq <= 0) {
498 return -ENODEV; 494 dev_err(&pdev->dev, "failed to get MSI irq\n");
495 return -ENODEV;
496 }
497
498 ret = devm_request_irq(&pdev->dev, pp->msi_irq,
499 imx6_pcie_msi_handler,
500 IRQF_SHARED, "mx6-pcie-msi", pp);
501 if (ret) {
502 dev_err(&pdev->dev, "failed to request MSI irq\n");
503 return -ENODEV;
504 }
499 } 505 }
500 506
501 pp->root_bus_nr = -1; 507 pp->root_bus_nr = -1;
@@ -546,69 +552,26 @@ static int __init imx6_pcie_probe(struct platform_device *pdev)
546 } 552 }
547 } 553 }
548 554
549 imx6_pcie->power_on_gpio = of_get_named_gpio(np, "power-on-gpio", 0);
550 if (gpio_is_valid(imx6_pcie->power_on_gpio)) {
551 ret = devm_gpio_request_one(&pdev->dev,
552 imx6_pcie->power_on_gpio,
553 GPIOF_OUT_INIT_LOW,
554 "PCIe power enable");
555 if (ret) {
556 dev_err(&pdev->dev, "unable to get power-on gpio\n");
557 return ret;
558 }
559 }
560
561 imx6_pcie->wake_up_gpio = of_get_named_gpio(np, "wake-up-gpio", 0);
562 if (gpio_is_valid(imx6_pcie->wake_up_gpio)) {
563 ret = devm_gpio_request_one(&pdev->dev,
564 imx6_pcie->wake_up_gpio,
565 GPIOF_IN,
566 "PCIe wake up");
567 if (ret) {
568 dev_err(&pdev->dev, "unable to get wake-up gpio\n");
569 return ret;
570 }
571 }
572
573 imx6_pcie->disable_gpio = of_get_named_gpio(np, "disable-gpio", 0);
574 if (gpio_is_valid(imx6_pcie->disable_gpio)) {
575 ret = devm_gpio_request_one(&pdev->dev,
576 imx6_pcie->disable_gpio,
577 GPIOF_OUT_INIT_HIGH,
578 "PCIe disable endpoint");
579 if (ret) {
580 dev_err(&pdev->dev, "unable to get disable-ep gpio\n");
581 return ret;
582 }
583 }
584
585 /* Fetch clocks */ 555 /* Fetch clocks */
586 imx6_pcie->lvds_gate = devm_clk_get(&pdev->dev, "lvds_gate"); 556 imx6_pcie->pcie_phy = devm_clk_get(&pdev->dev, "pcie_phy");
587 if (IS_ERR(imx6_pcie->lvds_gate)) { 557 if (IS_ERR(imx6_pcie->pcie_phy)) {
588 dev_err(&pdev->dev,
589 "lvds_gate clock select missing or invalid\n");
590 return PTR_ERR(imx6_pcie->lvds_gate);
591 }
592
593 imx6_pcie->sata_ref_100m = devm_clk_get(&pdev->dev, "sata_ref_100m");
594 if (IS_ERR(imx6_pcie->sata_ref_100m)) {
595 dev_err(&pdev->dev, 558 dev_err(&pdev->dev,
596 "sata_ref_100m clock source missing or invalid\n"); 559 "pcie_phy clock source missing or invalid\n");
597 return PTR_ERR(imx6_pcie->sata_ref_100m); 560 return PTR_ERR(imx6_pcie->pcie_phy);
598 } 561 }
599 562
600 imx6_pcie->pcie_ref_125m = devm_clk_get(&pdev->dev, "pcie_ref_125m"); 563 imx6_pcie->pcie_bus = devm_clk_get(&pdev->dev, "pcie_bus");
601 if (IS_ERR(imx6_pcie->pcie_ref_125m)) { 564 if (IS_ERR(imx6_pcie->pcie_bus)) {
602 dev_err(&pdev->dev, 565 dev_err(&pdev->dev,
603 "pcie_ref_125m clock source missing or invalid\n"); 566 "pcie_bus clock source missing or invalid\n");
604 return PTR_ERR(imx6_pcie->pcie_ref_125m); 567 return PTR_ERR(imx6_pcie->pcie_bus);
605 } 568 }
606 569
607 imx6_pcie->pcie_axi = devm_clk_get(&pdev->dev, "pcie_axi"); 570 imx6_pcie->pcie = devm_clk_get(&pdev->dev, "pcie");
608 if (IS_ERR(imx6_pcie->pcie_axi)) { 571 if (IS_ERR(imx6_pcie->pcie)) {
609 dev_err(&pdev->dev, 572 dev_err(&pdev->dev,
610 "pcie_axi clock source missing or invalid\n"); 573 "pcie clock source missing or invalid\n");
611 return PTR_ERR(imx6_pcie->pcie_axi); 574 return PTR_ERR(imx6_pcie->pcie);
612 } 575 }
613 576
614 /* Grab GPR config register range */ 577 /* Grab GPR config register range */
diff --git a/drivers/pci/host/pci-rcar-gen2.c b/drivers/pci/host/pci-rcar-gen2.c
index 4fe349dcaf59..3ef854f5a5b5 100644
--- a/drivers/pci/host/pci-rcar-gen2.c
+++ b/drivers/pci/host/pci-rcar-gen2.c
@@ -99,6 +99,7 @@ struct rcar_pci_priv {
99 struct resource io_res; 99 struct resource io_res;
100 struct resource mem_res; 100 struct resource mem_res;
101 struct resource *cfg_res; 101 struct resource *cfg_res;
102 unsigned busnr;
102 int irq; 103 int irq;
103 unsigned long window_size; 104 unsigned long window_size;
104}; 105};
@@ -318,8 +319,8 @@ static int rcar_pci_setup(int nr, struct pci_sys_data *sys)
318 pci_add_resource(&sys->resources, &priv->io_res); 319 pci_add_resource(&sys->resources, &priv->io_res);
319 pci_add_resource(&sys->resources, &priv->mem_res); 320 pci_add_resource(&sys->resources, &priv->mem_res);
320 321
321 /* Setup bus number based on platform device id */ 322 /* Setup bus number based on platform device id / of bus-range */
322 sys->busnr = to_platform_device(priv->dev)->id; 323 sys->busnr = priv->busnr;
323 return 1; 324 return 1;
324} 325}
325 326
@@ -372,6 +373,23 @@ static int rcar_pci_probe(struct platform_device *pdev)
372 373
373 priv->window_size = SZ_1G; 374 priv->window_size = SZ_1G;
374 375
376 if (pdev->dev.of_node) {
377 struct resource busnr;
378 int ret;
379
380 ret = of_pci_parse_bus_range(pdev->dev.of_node, &busnr);
381 if (ret < 0) {
382 dev_err(&pdev->dev, "failed to parse bus-range\n");
383 return ret;
384 }
385
386 priv->busnr = busnr.start;
387 if (busnr.end != busnr.start)
388 dev_warn(&pdev->dev, "only one bus number supported\n");
389 } else {
390 priv->busnr = pdev->id;
391 }
392
375 hw_private[0] = priv; 393 hw_private[0] = priv;
376 memset(&hw, 0, sizeof(hw)); 394 memset(&hw, 0, sizeof(hw));
377 hw.nr_controllers = ARRAY_SIZE(hw_private); 395 hw.nr_controllers = ARRAY_SIZE(hw_private);
@@ -383,11 +401,20 @@ static int rcar_pci_probe(struct platform_device *pdev)
383 return 0; 401 return 0;
384} 402}
385 403
404static struct of_device_id rcar_pci_of_match[] = {
405 { .compatible = "renesas,pci-r8a7790", },
406 { .compatible = "renesas,pci-r8a7791", },
407 { },
408};
409
410MODULE_DEVICE_TABLE(of, rcar_pci_of_match);
411
386static struct platform_driver rcar_pci_driver = { 412static struct platform_driver rcar_pci_driver = {
387 .driver = { 413 .driver = {
388 .name = "pci-rcar-gen2", 414 .name = "pci-rcar-gen2",
389 .owner = THIS_MODULE, 415 .owner = THIS_MODULE,
390 .suppress_bind_attrs = true, 416 .suppress_bind_attrs = true,
417 .of_match_table = rcar_pci_of_match,
391 }, 418 },
392 .probe = rcar_pci_probe, 419 .probe = rcar_pci_probe,
393}; 420};
diff --git a/drivers/pci/host/pcie-designware.c b/drivers/pci/host/pcie-designware.c
index c4e373294476..e3bf9e6d5d9a 100644
--- a/drivers/pci/host/pcie-designware.c
+++ b/drivers/pci/host/pcie-designware.c
@@ -156,15 +156,17 @@ static struct irq_chip dw_msi_irq_chip = {
156}; 156};
157 157
158/* MSI int handler */ 158/* MSI int handler */
159void dw_handle_msi_irq(struct pcie_port *pp) 159irqreturn_t dw_handle_msi_irq(struct pcie_port *pp)
160{ 160{
161 unsigned long val; 161 unsigned long val;
162 int i, pos, irq; 162 int i, pos, irq;
163 irqreturn_t ret = IRQ_NONE;
163 164
164 for (i = 0; i < MAX_MSI_CTRLS; i++) { 165 for (i = 0; i < MAX_MSI_CTRLS; i++) {
165 dw_pcie_rd_own_conf(pp, PCIE_MSI_INTR0_STATUS + i * 12, 4, 166 dw_pcie_rd_own_conf(pp, PCIE_MSI_INTR0_STATUS + i * 12, 4,
166 (u32 *)&val); 167 (u32 *)&val);
167 if (val) { 168 if (val) {
169 ret = IRQ_HANDLED;
168 pos = 0; 170 pos = 0;
169 while ((pos = find_next_bit(&val, 32, pos)) != 32) { 171 while ((pos = find_next_bit(&val, 32, pos)) != 32) {
170 irq = irq_find_mapping(pp->irq_domain, 172 irq = irq_find_mapping(pp->irq_domain,
@@ -177,6 +179,8 @@ void dw_handle_msi_irq(struct pcie_port *pp)
177 } 179 }
178 } 180 }
179 } 181 }
182
183 return ret;
180} 184}
181 185
182void dw_pcie_msi_init(struct pcie_port *pp) 186void dw_pcie_msi_init(struct pcie_port *pp)
diff --git a/drivers/pci/host/pcie-designware.h b/drivers/pci/host/pcie-designware.h
index 3063b3594d88..a169d22d517e 100644
--- a/drivers/pci/host/pcie-designware.h
+++ b/drivers/pci/host/pcie-designware.h
@@ -68,7 +68,7 @@ struct pcie_host_ops {
68 68
69int dw_pcie_cfg_read(void __iomem *addr, int where, int size, u32 *val); 69int dw_pcie_cfg_read(void __iomem *addr, int where, int size, u32 *val);
70int dw_pcie_cfg_write(void __iomem *addr, int where, int size, u32 val); 70int dw_pcie_cfg_write(void __iomem *addr, int where, int size, u32 val);
71void dw_handle_msi_irq(struct pcie_port *pp); 71irqreturn_t dw_handle_msi_irq(struct pcie_port *pp);
72void dw_pcie_msi_init(struct pcie_port *pp); 72void dw_pcie_msi_init(struct pcie_port *pp);
73int dw_pcie_link_up(struct pcie_port *pp); 73int dw_pcie_link_up(struct pcie_port *pp);
74void dw_pcie_setup_rc(struct pcie_port *pp); 74void dw_pcie_setup_rc(struct pcie_port *pp);
diff --git a/drivers/pci/host/pcie-rcar.c b/drivers/pci/host/pcie-rcar.c
new file mode 100644
index 000000000000..8e06124aa80f
--- /dev/null
+++ b/drivers/pci/host/pcie-rcar.c
@@ -0,0 +1,1008 @@
1/*
2 * PCIe driver for Renesas R-Car SoCs
3 * Copyright (C) 2014 Renesas Electronics Europe Ltd
4 *
5 * Based on:
6 * arch/sh/drivers/pci/pcie-sh7786.c
7 * arch/sh/drivers/pci/ops-sh7786.c
8 * Copyright (C) 2009 - 2011 Paul Mundt
9 *
10 * This file is licensed under the terms of the GNU General Public
11 * License version 2. This program is licensed "as is" without any
12 * warranty of any kind, whether express or implied.
13 */
14
15#include <linux/clk.h>
16#include <linux/delay.h>
17#include <linux/interrupt.h>
18#include <linux/irq.h>
19#include <linux/irqdomain.h>
20#include <linux/kernel.h>
21#include <linux/module.h>
22#include <linux/msi.h>
23#include <linux/of_address.h>
24#include <linux/of_irq.h>
25#include <linux/of_pci.h>
26#include <linux/of_platform.h>
27#include <linux/pci.h>
28#include <linux/platform_device.h>
29#include <linux/slab.h>
30
31#define DRV_NAME "rcar-pcie"
32
33#define PCIECAR 0x000010
34#define PCIECCTLR 0x000018
35#define CONFIG_SEND_ENABLE (1 << 31)
36#define TYPE0 (0 << 8)
37#define TYPE1 (1 << 8)
38#define PCIECDR 0x000020
39#define PCIEMSR 0x000028
40#define PCIEINTXR 0x000400
41#define PCIEMSITXR 0x000840
42
43/* Transfer control */
44#define PCIETCTLR 0x02000
45#define CFINIT 1
46#define PCIETSTR 0x02004
47#define DATA_LINK_ACTIVE 1
48#define PCIEERRFR 0x02020
49#define UNSUPPORTED_REQUEST (1 << 4)
50#define PCIEMSIFR 0x02044
51#define PCIEMSIALR 0x02048
52#define MSIFE 1
53#define PCIEMSIAUR 0x0204c
54#define PCIEMSIIER 0x02050
55
56/* root port address */
57#define PCIEPRAR(x) (0x02080 + ((x) * 0x4))
58
59/* local address reg & mask */
60#define PCIELAR(x) (0x02200 + ((x) * 0x20))
61#define PCIELAMR(x) (0x02208 + ((x) * 0x20))
62#define LAM_PREFETCH (1 << 3)
63#define LAM_64BIT (1 << 2)
64#define LAR_ENABLE (1 << 1)
65
66/* PCIe address reg & mask */
67#define PCIEPARL(x) (0x03400 + ((x) * 0x20))
68#define PCIEPARH(x) (0x03404 + ((x) * 0x20))
69#define PCIEPAMR(x) (0x03408 + ((x) * 0x20))
70#define PCIEPTCTLR(x) (0x0340c + ((x) * 0x20))
71#define PAR_ENABLE (1 << 31)
72#define IO_SPACE (1 << 8)
73
74/* Configuration */
75#define PCICONF(x) (0x010000 + ((x) * 0x4))
76#define PMCAP(x) (0x010040 + ((x) * 0x4))
77#define EXPCAP(x) (0x010070 + ((x) * 0x4))
78#define VCCAP(x) (0x010100 + ((x) * 0x4))
79
80/* link layer */
81#define IDSETR1 0x011004
82#define TLCTLR 0x011048
83#define MACSR 0x011054
84#define MACCTLR 0x011058
85#define SCRAMBLE_DISABLE (1 << 27)
86
87/* R-Car H1 PHY */
88#define H1_PCIEPHYADRR 0x04000c
89#define WRITE_CMD (1 << 16)
90#define PHY_ACK (1 << 24)
91#define RATE_POS 12
92#define LANE_POS 8
93#define ADR_POS 0
94#define H1_PCIEPHYDOUTR 0x040014
95#define H1_PCIEPHYSR 0x040018
96
97#define INT_PCI_MSI_NR 32
98
99#define RCONF(x) (PCICONF(0)+(x))
100#define RPMCAP(x) (PMCAP(0)+(x))
101#define REXPCAP(x) (EXPCAP(0)+(x))
102#define RVCCAP(x) (VCCAP(0)+(x))
103
104#define PCIE_CONF_BUS(b) (((b) & 0xff) << 24)
105#define PCIE_CONF_DEV(d) (((d) & 0x1f) << 19)
106#define PCIE_CONF_FUNC(f) (((f) & 0x7) << 16)
107
108#define PCI_MAX_RESOURCES 4
109#define MAX_NR_INBOUND_MAPS 6
110
111struct rcar_msi {
112 DECLARE_BITMAP(used, INT_PCI_MSI_NR);
113 struct irq_domain *domain;
114 struct msi_chip chip;
115 unsigned long pages;
116 struct mutex lock;
117 int irq1;
118 int irq2;
119};
120
121static inline struct rcar_msi *to_rcar_msi(struct msi_chip *chip)
122{
123 return container_of(chip, struct rcar_msi, chip);
124}
125
126/* Structure representing the PCIe interface */
127struct rcar_pcie {
128 struct device *dev;
129 void __iomem *base;
130 struct resource res[PCI_MAX_RESOURCES];
131 struct resource busn;
132 int root_bus_nr;
133 struct clk *clk;
134 struct clk *bus_clk;
135 struct rcar_msi msi;
136};
137
138static inline struct rcar_pcie *sys_to_pcie(struct pci_sys_data *sys)
139{
140 return sys->private_data;
141}
142
143static void pci_write_reg(struct rcar_pcie *pcie, unsigned long val,
144 unsigned long reg)
145{
146 writel(val, pcie->base + reg);
147}
148
149static unsigned long pci_read_reg(struct rcar_pcie *pcie, unsigned long reg)
150{
151 return readl(pcie->base + reg);
152}
153
154enum {
155 PCI_ACCESS_READ,
156 PCI_ACCESS_WRITE,
157};
158
159static void rcar_rmw32(struct rcar_pcie *pcie, int where, u32 mask, u32 data)
160{
161 int shift = 8 * (where & 3);
162 u32 val = pci_read_reg(pcie, where & ~3);
163
164 val &= ~(mask << shift);
165 val |= data << shift;
166 pci_write_reg(pcie, val, where & ~3);
167}
168
169static u32 rcar_read_conf(struct rcar_pcie *pcie, int where)
170{
171 int shift = 8 * (where & 3);
172 u32 val = pci_read_reg(pcie, where & ~3);
173
174 return val >> shift;
175}
176
177/* Serialization is provided by 'pci_lock' in drivers/pci/access.c */
178static int rcar_pcie_config_access(struct rcar_pcie *pcie,
179 unsigned char access_type, struct pci_bus *bus,
180 unsigned int devfn, int where, u32 *data)
181{
182 int dev, func, reg, index;
183
184 dev = PCI_SLOT(devfn);
185 func = PCI_FUNC(devfn);
186 reg = where & ~3;
187 index = reg / 4;
188
189 /*
190 * While each channel has its own memory-mapped extended config
191 * space, it's generally only accessible when in endpoint mode.
192 * When in root complex mode, the controller is unable to target
193 * itself with either type 0 or type 1 accesses, and indeed, any
194 * controller initiated target transfer to its own config space
195 * result in a completer abort.
196 *
197 * Each channel effectively only supports a single device, but as
198 * the same channel <-> device access works for any PCI_SLOT()
199 * value, we cheat a bit here and bind the controller's config
200 * space to devfn 0 in order to enable self-enumeration. In this
201 * case the regular ECAR/ECDR path is sidelined and the mangled
202 * config access itself is initiated as an internal bus transaction.
203 */
204 if (pci_is_root_bus(bus)) {
205 if (dev != 0)
206 return PCIBIOS_DEVICE_NOT_FOUND;
207
208 if (access_type == PCI_ACCESS_READ) {
209 *data = pci_read_reg(pcie, PCICONF(index));
210 } else {
211 /* Keep an eye out for changes to the root bus number */
212 if (pci_is_root_bus(bus) && (reg == PCI_PRIMARY_BUS))
213 pcie->root_bus_nr = *data & 0xff;
214
215 pci_write_reg(pcie, *data, PCICONF(index));
216 }
217
218 return PCIBIOS_SUCCESSFUL;
219 }
220
221 if (pcie->root_bus_nr < 0)
222 return PCIBIOS_DEVICE_NOT_FOUND;
223
224 /* Clear errors */
225 pci_write_reg(pcie, pci_read_reg(pcie, PCIEERRFR), PCIEERRFR);
226
227 /* Set the PIO address */
228 pci_write_reg(pcie, PCIE_CONF_BUS(bus->number) | PCIE_CONF_DEV(dev) |
229 PCIE_CONF_FUNC(func) | reg, PCIECAR);
230
231 /* Enable the configuration access */
232 if (bus->parent->number == pcie->root_bus_nr)
233 pci_write_reg(pcie, CONFIG_SEND_ENABLE | TYPE0, PCIECCTLR);
234 else
235 pci_write_reg(pcie, CONFIG_SEND_ENABLE | TYPE1, PCIECCTLR);
236
237 /* Check for errors */
238 if (pci_read_reg(pcie, PCIEERRFR) & UNSUPPORTED_REQUEST)
239 return PCIBIOS_DEVICE_NOT_FOUND;
240
241 /* Check for master and target aborts */
242 if (rcar_read_conf(pcie, RCONF(PCI_STATUS)) &
243 (PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT))
244 return PCIBIOS_DEVICE_NOT_FOUND;
245
246 if (access_type == PCI_ACCESS_READ)
247 *data = pci_read_reg(pcie, PCIECDR);
248 else
249 pci_write_reg(pcie, *data, PCIECDR);
250
251 /* Disable the configuration access */
252 pci_write_reg(pcie, 0, PCIECCTLR);
253
254 return PCIBIOS_SUCCESSFUL;
255}
256
257static int rcar_pcie_read_conf(struct pci_bus *bus, unsigned int devfn,
258 int where, int size, u32 *val)
259{
260 struct rcar_pcie *pcie = sys_to_pcie(bus->sysdata);
261 int ret;
262
263 if ((size == 2) && (where & 1))
264 return PCIBIOS_BAD_REGISTER_NUMBER;
265 else if ((size == 4) && (where & 3))
266 return PCIBIOS_BAD_REGISTER_NUMBER;
267
268 ret = rcar_pcie_config_access(pcie, PCI_ACCESS_READ,
269 bus, devfn, where, val);
270 if (ret != PCIBIOS_SUCCESSFUL) {
271 *val = 0xffffffff;
272 return ret;
273 }
274
275 if (size == 1)
276 *val = (*val >> (8 * (where & 3))) & 0xff;
277 else if (size == 2)
278 *val = (*val >> (8 * (where & 2))) & 0xffff;
279
280 dev_dbg(&bus->dev, "pcie-config-read: bus=%3d devfn=0x%04x "
281 "where=0x%04x size=%d val=0x%08lx\n", bus->number,
282 devfn, where, size, (unsigned long)*val);
283
284 return ret;
285}
286
287/* Serialization is provided by 'pci_lock' in drivers/pci/access.c */
288static int rcar_pcie_write_conf(struct pci_bus *bus, unsigned int devfn,
289 int where, int size, u32 val)
290{
291 struct rcar_pcie *pcie = sys_to_pcie(bus->sysdata);
292 int shift, ret;
293 u32 data;
294
295 if ((size == 2) && (where & 1))
296 return PCIBIOS_BAD_REGISTER_NUMBER;
297 else if ((size == 4) && (where & 3))
298 return PCIBIOS_BAD_REGISTER_NUMBER;
299
300 ret = rcar_pcie_config_access(pcie, PCI_ACCESS_READ,
301 bus, devfn, where, &data);
302 if (ret != PCIBIOS_SUCCESSFUL)
303 return ret;
304
305 dev_dbg(&bus->dev, "pcie-config-write: bus=%3d devfn=0x%04x "
306 "where=0x%04x size=%d val=0x%08lx\n", bus->number,
307 devfn, where, size, (unsigned long)val);
308
309 if (size == 1) {
310 shift = 8 * (where & 3);
311 data &= ~(0xff << shift);
312 data |= ((val & 0xff) << shift);
313 } else if (size == 2) {
314 shift = 8 * (where & 2);
315 data &= ~(0xffff << shift);
316 data |= ((val & 0xffff) << shift);
317 } else
318 data = val;
319
320 ret = rcar_pcie_config_access(pcie, PCI_ACCESS_WRITE,
321 bus, devfn, where, &data);
322
323 return ret;
324}
325
326static struct pci_ops rcar_pcie_ops = {
327 .read = rcar_pcie_read_conf,
328 .write = rcar_pcie_write_conf,
329};
330
331static void rcar_pcie_setup_window(int win, struct resource *res,
332 struct rcar_pcie *pcie)
333{
334 /* Setup PCIe address space mappings for each resource */
335 resource_size_t size;
336 u32 mask;
337
338 pci_write_reg(pcie, 0x00000000, PCIEPTCTLR(win));
339
340 /*
341 * The PAMR mask is calculated in units of 128Bytes, which
342 * keeps things pretty simple.
343 */
344 size = resource_size(res);
345 mask = (roundup_pow_of_two(size) / SZ_128) - 1;
346 pci_write_reg(pcie, mask << 7, PCIEPAMR(win));
347
348 pci_write_reg(pcie, upper_32_bits(res->start), PCIEPARH(win));
349 pci_write_reg(pcie, lower_32_bits(res->start), PCIEPARL(win));
350
351 /* First resource is for IO */
352 mask = PAR_ENABLE;
353 if (res->flags & IORESOURCE_IO)
354 mask |= IO_SPACE;
355
356 pci_write_reg(pcie, mask, PCIEPTCTLR(win));
357}
358
359static int rcar_pcie_setup(int nr, struct pci_sys_data *sys)
360{
361 struct rcar_pcie *pcie = sys_to_pcie(sys);
362 struct resource *res;
363 int i;
364
365 pcie->root_bus_nr = -1;
366
367 /* Setup PCI resources */
368 for (i = 0; i < PCI_MAX_RESOURCES; i++) {
369
370 res = &pcie->res[i];
371 if (!res->flags)
372 continue;
373
374 rcar_pcie_setup_window(i, res, pcie);
375
376 if (res->flags & IORESOURCE_IO)
377 pci_ioremap_io(nr * SZ_64K, res->start);
378 else
379 pci_add_resource(&sys->resources, res);
380 }
381 pci_add_resource(&sys->resources, &pcie->busn);
382
383 return 1;
384}
385
386static void rcar_pcie_add_bus(struct pci_bus *bus)
387{
388 if (IS_ENABLED(CONFIG_PCI_MSI)) {
389 struct rcar_pcie *pcie = sys_to_pcie(bus->sysdata);
390
391 bus->msi = &pcie->msi.chip;
392 }
393}
394
395struct hw_pci rcar_pci = {
396 .setup = rcar_pcie_setup,
397 .map_irq = of_irq_parse_and_map_pci,
398 .ops = &rcar_pcie_ops,
399 .add_bus = rcar_pcie_add_bus,
400};
401
402static void rcar_pcie_enable(struct rcar_pcie *pcie)
403{
404 struct platform_device *pdev = to_platform_device(pcie->dev);
405
406 rcar_pci.nr_controllers = 1;
407 rcar_pci.private_data = (void **)&pcie;
408
409 pci_common_init_dev(&pdev->dev, &rcar_pci);
410#ifdef CONFIG_PCI_DOMAINS
411 rcar_pci.domain++;
412#endif
413}
414
415static int phy_wait_for_ack(struct rcar_pcie *pcie)
416{
417 unsigned int timeout = 100;
418
419 while (timeout--) {
420 if (pci_read_reg(pcie, H1_PCIEPHYADRR) & PHY_ACK)
421 return 0;
422
423 udelay(100);
424 }
425
426 dev_err(pcie->dev, "Access to PCIe phy timed out\n");
427
428 return -ETIMEDOUT;
429}
430
431static void phy_write_reg(struct rcar_pcie *pcie,
432 unsigned int rate, unsigned int addr,
433 unsigned int lane, unsigned int data)
434{
435 unsigned long phyaddr;
436
437 phyaddr = WRITE_CMD |
438 ((rate & 1) << RATE_POS) |
439 ((lane & 0xf) << LANE_POS) |
440 ((addr & 0xff) << ADR_POS);
441
442 /* Set write data */
443 pci_write_reg(pcie, data, H1_PCIEPHYDOUTR);
444 pci_write_reg(pcie, phyaddr, H1_PCIEPHYADRR);
445
446 /* Ignore errors as they will be dealt with if the data link is down */
447 phy_wait_for_ack(pcie);
448
449 /* Clear command */
450 pci_write_reg(pcie, 0, H1_PCIEPHYDOUTR);
451 pci_write_reg(pcie, 0, H1_PCIEPHYADRR);
452
453 /* Ignore errors as they will be dealt with if the data link is down */
454 phy_wait_for_ack(pcie);
455}
456
457static int rcar_pcie_wait_for_dl(struct rcar_pcie *pcie)
458{
459 unsigned int timeout = 10;
460
461 while (timeout--) {
462 if ((pci_read_reg(pcie, PCIETSTR) & DATA_LINK_ACTIVE))
463 return 0;
464
465 msleep(5);
466 }
467
468 return -ETIMEDOUT;
469}
470
471static int rcar_pcie_hw_init(struct rcar_pcie *pcie)
472{
473 int err;
474
475 /* Begin initialization */
476 pci_write_reg(pcie, 0, PCIETCTLR);
477
478 /* Set mode */
479 pci_write_reg(pcie, 1, PCIEMSR);
480
481 /*
482 * Initial header for port config space is type 1, set the device
483 * class to match. Hardware takes care of propagating the IDSETR
484 * settings, so there is no need to bother with a quirk.
485 */
486 pci_write_reg(pcie, PCI_CLASS_BRIDGE_PCI << 16, IDSETR1);
487
488 /*
489 * Setup Secondary Bus Number & Subordinate Bus Number, even though
490 * they aren't used, to avoid bridge being detected as broken.
491 */
492 rcar_rmw32(pcie, RCONF(PCI_SECONDARY_BUS), 0xff, 1);
493 rcar_rmw32(pcie, RCONF(PCI_SUBORDINATE_BUS), 0xff, 1);
494
495 /* Initialize default capabilities. */
496 rcar_rmw32(pcie, REXPCAP(0), 0, PCI_CAP_ID_EXP);
497 rcar_rmw32(pcie, REXPCAP(PCI_EXP_FLAGS),
498 PCI_EXP_FLAGS_TYPE, PCI_EXP_TYPE_ROOT_PORT << 4);
499 rcar_rmw32(pcie, RCONF(PCI_HEADER_TYPE), 0x7f,
500 PCI_HEADER_TYPE_BRIDGE);
501
502 /* Enable data link layer active state reporting */
503 rcar_rmw32(pcie, REXPCAP(PCI_EXP_LNKCAP), 0, PCI_EXP_LNKCAP_DLLLARC);
504
505 /* Write out the physical slot number = 0 */
506 rcar_rmw32(pcie, REXPCAP(PCI_EXP_SLTCAP), PCI_EXP_SLTCAP_PSN, 0);
507
508 /* Set the completion timer timeout to the maximum 50ms. */
509 rcar_rmw32(pcie, TLCTLR+1, 0x3f, 50);
510
511 /* Terminate list of capabilities (Next Capability Offset=0) */
512 rcar_rmw32(pcie, RVCCAP(0), 0xfff0, 0);
513
514 /* Enable MAC data scrambling. */
515 rcar_rmw32(pcie, MACCTLR, SCRAMBLE_DISABLE, 0);
516
517 /* Enable MSI */
518 if (IS_ENABLED(CONFIG_PCI_MSI))
519 pci_write_reg(pcie, 0x101f0000, PCIEMSITXR);
520
521 /* Finish initialization - establish a PCI Express link */
522 pci_write_reg(pcie, CFINIT, PCIETCTLR);
523
524 /* This will timeout if we don't have a link. */
525 err = rcar_pcie_wait_for_dl(pcie);
526 if (err)
527 return err;
528
529 /* Enable INTx interrupts */
530 rcar_rmw32(pcie, PCIEINTXR, 0, 0xF << 8);
531
532 /* Enable slave Bus Mastering */
533 rcar_rmw32(pcie, RCONF(PCI_STATUS), PCI_STATUS_DEVSEL_MASK,
534 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
535 PCI_STATUS_CAP_LIST | PCI_STATUS_DEVSEL_FAST);
536
537 wmb();
538
539 return 0;
540}
541
542static int rcar_pcie_hw_init_h1(struct rcar_pcie *pcie)
543{
544 unsigned int timeout = 10;
545
546 /* Initialize the phy */
547 phy_write_reg(pcie, 0, 0x42, 0x1, 0x0EC34191);
548 phy_write_reg(pcie, 1, 0x42, 0x1, 0x0EC34180);
549 phy_write_reg(pcie, 0, 0x43, 0x1, 0x00210188);
550 phy_write_reg(pcie, 1, 0x43, 0x1, 0x00210188);
551 phy_write_reg(pcie, 0, 0x44, 0x1, 0x015C0014);
552 phy_write_reg(pcie, 1, 0x44, 0x1, 0x015C0014);
553 phy_write_reg(pcie, 1, 0x4C, 0x1, 0x786174A0);
554 phy_write_reg(pcie, 1, 0x4D, 0x1, 0x048000BB);
555 phy_write_reg(pcie, 0, 0x51, 0x1, 0x079EC062);
556 phy_write_reg(pcie, 0, 0x52, 0x1, 0x20000000);
557 phy_write_reg(pcie, 1, 0x52, 0x1, 0x20000000);
558 phy_write_reg(pcie, 1, 0x56, 0x1, 0x00003806);
559
560 phy_write_reg(pcie, 0, 0x60, 0x1, 0x004B03A5);
561 phy_write_reg(pcie, 0, 0x64, 0x1, 0x3F0F1F0F);
562 phy_write_reg(pcie, 0, 0x66, 0x1, 0x00008000);
563
564 while (timeout--) {
565 if (pci_read_reg(pcie, H1_PCIEPHYSR))
566 return rcar_pcie_hw_init(pcie);
567
568 msleep(5);
569 }
570
571 return -ETIMEDOUT;
572}
573
574static int rcar_msi_alloc(struct rcar_msi *chip)
575{
576 int msi;
577
578 mutex_lock(&chip->lock);
579
580 msi = find_first_zero_bit(chip->used, INT_PCI_MSI_NR);
581 if (msi < INT_PCI_MSI_NR)
582 set_bit(msi, chip->used);
583 else
584 msi = -ENOSPC;
585
586 mutex_unlock(&chip->lock);
587
588 return msi;
589}
590
591static void rcar_msi_free(struct rcar_msi *chip, unsigned long irq)
592{
593 mutex_lock(&chip->lock);
594 clear_bit(irq, chip->used);
595 mutex_unlock(&chip->lock);
596}
597
598static irqreturn_t rcar_pcie_msi_irq(int irq, void *data)
599{
600 struct rcar_pcie *pcie = data;
601 struct rcar_msi *msi = &pcie->msi;
602 unsigned long reg;
603
604 reg = pci_read_reg(pcie, PCIEMSIFR);
605
606 /* MSI & INTx share an interrupt - we only handle MSI here */
607 if (!reg)
608 return IRQ_NONE;
609
610 while (reg) {
611 unsigned int index = find_first_bit(&reg, 32);
612 unsigned int irq;
613
614 /* clear the interrupt */
615 pci_write_reg(pcie, 1 << index, PCIEMSIFR);
616
617 irq = irq_find_mapping(msi->domain, index);
618 if (irq) {
619 if (test_bit(index, msi->used))
620 generic_handle_irq(irq);
621 else
622 dev_info(pcie->dev, "unhandled MSI\n");
623 } else {
624 /* Unknown MSI, just clear it */
625 dev_dbg(pcie->dev, "unexpected MSI\n");
626 }
627
628 /* see if there's any more pending in this vector */
629 reg = pci_read_reg(pcie, PCIEMSIFR);
630 }
631
632 return IRQ_HANDLED;
633}
634
635static int rcar_msi_setup_irq(struct msi_chip *chip, struct pci_dev *pdev,
636 struct msi_desc *desc)
637{
638 struct rcar_msi *msi = to_rcar_msi(chip);
639 struct rcar_pcie *pcie = container_of(chip, struct rcar_pcie, msi.chip);
640 struct msi_msg msg;
641 unsigned int irq;
642 int hwirq;
643
644 hwirq = rcar_msi_alloc(msi);
645 if (hwirq < 0)
646 return hwirq;
647
648 irq = irq_create_mapping(msi->domain, hwirq);
649 if (!irq) {
650 rcar_msi_free(msi, hwirq);
651 return -EINVAL;
652 }
653
654 irq_set_msi_desc(irq, desc);
655
656 msg.address_lo = pci_read_reg(pcie, PCIEMSIALR) & ~MSIFE;
657 msg.address_hi = pci_read_reg(pcie, PCIEMSIAUR);
658 msg.data = hwirq;
659
660 write_msi_msg(irq, &msg);
661
662 return 0;
663}
664
665static void rcar_msi_teardown_irq(struct msi_chip *chip, unsigned int irq)
666{
667 struct rcar_msi *msi = to_rcar_msi(chip);
668 struct irq_data *d = irq_get_irq_data(irq);
669
670 rcar_msi_free(msi, d->hwirq);
671}
672
673static struct irq_chip rcar_msi_irq_chip = {
674 .name = "R-Car PCIe MSI",
675 .irq_enable = unmask_msi_irq,
676 .irq_disable = mask_msi_irq,
677 .irq_mask = mask_msi_irq,
678 .irq_unmask = unmask_msi_irq,
679};
680
681static int rcar_msi_map(struct irq_domain *domain, unsigned int irq,
682 irq_hw_number_t hwirq)
683{
684 irq_set_chip_and_handler(irq, &rcar_msi_irq_chip, handle_simple_irq);
685 irq_set_chip_data(irq, domain->host_data);
686 set_irq_flags(irq, IRQF_VALID);
687
688 return 0;
689}
690
691static const struct irq_domain_ops msi_domain_ops = {
692 .map = rcar_msi_map,
693};
694
695static int rcar_pcie_enable_msi(struct rcar_pcie *pcie)
696{
697 struct platform_device *pdev = to_platform_device(pcie->dev);
698 struct rcar_msi *msi = &pcie->msi;
699 unsigned long base;
700 int err;
701
702 mutex_init(&msi->lock);
703
704 msi->chip.dev = pcie->dev;
705 msi->chip.setup_irq = rcar_msi_setup_irq;
706 msi->chip.teardown_irq = rcar_msi_teardown_irq;
707
708 msi->domain = irq_domain_add_linear(pcie->dev->of_node, INT_PCI_MSI_NR,
709 &msi_domain_ops, &msi->chip);
710 if (!msi->domain) {
711 dev_err(&pdev->dev, "failed to create IRQ domain\n");
712 return -ENOMEM;
713 }
714
715 /* Two irqs are for MSI, but they are also used for non-MSI irqs */
716 err = devm_request_irq(&pdev->dev, msi->irq1, rcar_pcie_msi_irq,
717 IRQF_SHARED, rcar_msi_irq_chip.name, pcie);
718 if (err < 0) {
719 dev_err(&pdev->dev, "failed to request IRQ: %d\n", err);
720 goto err;
721 }
722
723 err = devm_request_irq(&pdev->dev, msi->irq2, rcar_pcie_msi_irq,
724 IRQF_SHARED, rcar_msi_irq_chip.name, pcie);
725 if (err < 0) {
726 dev_err(&pdev->dev, "failed to request IRQ: %d\n", err);
727 goto err;
728 }
729
730 /* setup MSI data target */
731 msi->pages = __get_free_pages(GFP_KERNEL, 0);
732 base = virt_to_phys((void *)msi->pages);
733
734 pci_write_reg(pcie, base | MSIFE, PCIEMSIALR);
735 pci_write_reg(pcie, 0, PCIEMSIAUR);
736
737 /* enable all MSI interrupts */
738 pci_write_reg(pcie, 0xffffffff, PCIEMSIIER);
739
740 return 0;
741
742err:
743 irq_domain_remove(msi->domain);
744 return err;
745}
746
747static int rcar_pcie_get_resources(struct platform_device *pdev,
748 struct rcar_pcie *pcie)
749{
750 struct resource res;
751 int err, i;
752
753 err = of_address_to_resource(pdev->dev.of_node, 0, &res);
754 if (err)
755 return err;
756
757 pcie->clk = devm_clk_get(&pdev->dev, "pcie");
758 if (IS_ERR(pcie->clk)) {
759 dev_err(pcie->dev, "cannot get platform clock\n");
760 return PTR_ERR(pcie->clk);
761 }
762 err = clk_prepare_enable(pcie->clk);
763 if (err)
764 goto fail_clk;
765
766 pcie->bus_clk = devm_clk_get(&pdev->dev, "pcie_bus");
767 if (IS_ERR(pcie->bus_clk)) {
768 dev_err(pcie->dev, "cannot get pcie bus clock\n");
769 err = PTR_ERR(pcie->bus_clk);
770 goto fail_clk;
771 }
772 err = clk_prepare_enable(pcie->bus_clk);
773 if (err)
774 goto err_map_reg;
775
776 i = irq_of_parse_and_map(pdev->dev.of_node, 0);
777 if (i < 0) {
778 dev_err(pcie->dev, "cannot get platform resources for msi interrupt\n");
779 err = -ENOENT;
780 goto err_map_reg;
781 }
782 pcie->msi.irq1 = i;
783
784 i = irq_of_parse_and_map(pdev->dev.of_node, 1);
785 if (i < 0) {
786 dev_err(pcie->dev, "cannot get platform resources for msi interrupt\n");
787 err = -ENOENT;
788 goto err_map_reg;
789 }
790 pcie->msi.irq2 = i;
791
792 pcie->base = devm_ioremap_resource(&pdev->dev, &res);
793 if (IS_ERR(pcie->base)) {
794 err = PTR_ERR(pcie->base);
795 goto err_map_reg;
796 }
797
798 return 0;
799
800err_map_reg:
801 clk_disable_unprepare(pcie->bus_clk);
802fail_clk:
803 clk_disable_unprepare(pcie->clk);
804
805 return err;
806}
807
808static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie,
809 struct of_pci_range *range,
810 int *index)
811{
812 u64 restype = range->flags;
813 u64 cpu_addr = range->cpu_addr;
814 u64 cpu_end = range->cpu_addr + range->size;
815 u64 pci_addr = range->pci_addr;
816 u32 flags = LAM_64BIT | LAR_ENABLE;
817 u64 mask;
818 u64 size;
819 int idx = *index;
820
821 if (restype & IORESOURCE_PREFETCH)
822 flags |= LAM_PREFETCH;
823
824 /*
825 * If the size of the range is larger than the alignment of the start
826 * address, we have to use multiple entries to perform the mapping.
827 */
828 if (cpu_addr > 0) {
829 unsigned long nr_zeros = __ffs64(cpu_addr);
830 u64 alignment = 1ULL << nr_zeros;
831 size = min(range->size, alignment);
832 } else {
833 size = range->size;
834 }
835 /* Hardware supports max 4GiB inbound region */
836 size = min(size, 1ULL << 32);
837
838 mask = roundup_pow_of_two(size) - 1;
839 mask &= ~0xf;
840
841 while (cpu_addr < cpu_end) {
842 /*
843 * Set up 64-bit inbound regions as the range parser doesn't
844 * distinguish between 32 and 64-bit types.
845 */
846 pci_write_reg(pcie, lower_32_bits(pci_addr), PCIEPRAR(idx));
847 pci_write_reg(pcie, lower_32_bits(cpu_addr), PCIELAR(idx));
848 pci_write_reg(pcie, lower_32_bits(mask) | flags, PCIELAMR(idx));
849
850 pci_write_reg(pcie, upper_32_bits(pci_addr), PCIEPRAR(idx+1));
851 pci_write_reg(pcie, upper_32_bits(cpu_addr), PCIELAR(idx+1));
852 pci_write_reg(pcie, 0, PCIELAMR(idx+1));
853
854 pci_addr += size;
855 cpu_addr += size;
856 idx += 2;
857
858 if (idx > MAX_NR_INBOUND_MAPS) {
859 dev_err(pcie->dev, "Failed to map inbound regions!\n");
860 return -EINVAL;
861 }
862 }
863 *index = idx;
864
865 return 0;
866}
867
868static int pci_dma_range_parser_init(struct of_pci_range_parser *parser,
869 struct device_node *node)
870{
871 const int na = 3, ns = 2;
872 int rlen;
873
874 parser->node = node;
875 parser->pna = of_n_addr_cells(node);
876 parser->np = parser->pna + na + ns;
877
878 parser->range = of_get_property(node, "dma-ranges", &rlen);
879 if (!parser->range)
880 return -ENOENT;
881
882 parser->end = parser->range + rlen / sizeof(__be32);
883 return 0;
884}
885
886static int rcar_pcie_parse_map_dma_ranges(struct rcar_pcie *pcie,
887 struct device_node *np)
888{
889 struct of_pci_range range;
890 struct of_pci_range_parser parser;
891 int index = 0;
892 int err;
893
894 if (pci_dma_range_parser_init(&parser, np))
895 return -EINVAL;
896
897 /* Get the dma-ranges from DT */
898 for_each_of_pci_range(&parser, &range) {
899 u64 end = range.cpu_addr + range.size - 1;
900 dev_dbg(pcie->dev, "0x%08x 0x%016llx..0x%016llx -> 0x%016llx\n",
901 range.flags, range.cpu_addr, end, range.pci_addr);
902
903 err = rcar_pcie_inbound_ranges(pcie, &range, &index);
904 if (err)
905 return err;
906 }
907
908 return 0;
909}
910
911static const struct of_device_id rcar_pcie_of_match[] = {
912 { .compatible = "renesas,pcie-r8a7779", .data = rcar_pcie_hw_init_h1 },
913 { .compatible = "renesas,pcie-r8a7790", .data = rcar_pcie_hw_init },
914 { .compatible = "renesas,pcie-r8a7791", .data = rcar_pcie_hw_init },
915 {},
916};
917MODULE_DEVICE_TABLE(of, rcar_pcie_of_match);
918
919static int rcar_pcie_probe(struct platform_device *pdev)
920{
921 struct rcar_pcie *pcie;
922 unsigned int data;
923 struct of_pci_range range;
924 struct of_pci_range_parser parser;
925 const struct of_device_id *of_id;
926 int err, win = 0;
927 int (*hw_init_fn)(struct rcar_pcie *);
928
929 pcie = devm_kzalloc(&pdev->dev, sizeof(*pcie), GFP_KERNEL);
930 if (!pcie)
931 return -ENOMEM;
932
933 pcie->dev = &pdev->dev;
934 platform_set_drvdata(pdev, pcie);
935
936 /* Get the bus range */
937 if (of_pci_parse_bus_range(pdev->dev.of_node, &pcie->busn)) {
938 dev_err(&pdev->dev, "failed to parse bus-range property\n");
939 return -EINVAL;
940 }
941
942 if (of_pci_range_parser_init(&parser, pdev->dev.of_node)) {
943 dev_err(&pdev->dev, "missing ranges property\n");
944 return -EINVAL;
945 }
946
947 err = rcar_pcie_get_resources(pdev, pcie);
948 if (err < 0) {
949 dev_err(&pdev->dev, "failed to request resources: %d\n", err);
950 return err;
951 }
952
953 for_each_of_pci_range(&parser, &range) {
954 of_pci_range_to_resource(&range, pdev->dev.of_node,
955 &pcie->res[win++]);
956
957 if (win > PCI_MAX_RESOURCES)
958 break;
959 }
960
961 err = rcar_pcie_parse_map_dma_ranges(pcie, pdev->dev.of_node);
962 if (err)
963 return err;
964
965 if (IS_ENABLED(CONFIG_PCI_MSI)) {
966 err = rcar_pcie_enable_msi(pcie);
967 if (err < 0) {
968 dev_err(&pdev->dev,
969 "failed to enable MSI support: %d\n",
970 err);
971 return err;
972 }
973 }
974
975 of_id = of_match_device(rcar_pcie_of_match, pcie->dev);
976 if (!of_id || !of_id->data)
977 return -EINVAL;
978 hw_init_fn = of_id->data;
979
980 /* Failure to get a link might just be that no cards are inserted */
981 err = hw_init_fn(pcie);
982 if (err) {
983 dev_info(&pdev->dev, "PCIe link down\n");
984 return 0;
985 }
986
987 data = pci_read_reg(pcie, MACSR);
988 dev_info(&pdev->dev, "PCIe x%d: link up\n", (data >> 20) & 0x3f);
989
990 rcar_pcie_enable(pcie);
991
992 return 0;
993}
994
995static struct platform_driver rcar_pcie_driver = {
996 .driver = {
997 .name = DRV_NAME,
998 .owner = THIS_MODULE,
999 .of_match_table = rcar_pcie_of_match,
1000 .suppress_bind_attrs = true,
1001 },
1002 .probe = rcar_pcie_probe,
1003};
1004module_platform_driver(rcar_pcie_driver);
1005
1006MODULE_AUTHOR("Phil Edworthy <phil.edworthy@renesas.com>");
1007MODULE_DESCRIPTION("Renesas R-Car PCIe driver");
1008MODULE_LICENSE("GPLv2");
diff --git a/drivers/pci/hotplug-pci.c b/drivers/pci/hotplug-pci.c
index 6258dc260d9f..c68366cee6b7 100644
--- a/drivers/pci/hotplug-pci.c
+++ b/drivers/pci/hotplug-pci.c
@@ -4,7 +4,7 @@
4#include <linux/export.h> 4#include <linux/export.h>
5#include "pci.h" 5#include "pci.h"
6 6
7int __ref pci_hp_add_bridge(struct pci_dev *dev) 7int pci_hp_add_bridge(struct pci_dev *dev)
8{ 8{
9 struct pci_bus *parent = dev->bus; 9 struct pci_bus *parent = dev->bus;
10 int pass, busnr, start = parent->busn_res.start; 10 int pass, busnr, start = parent->busn_res.start;
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index bccc27ee1030..75e178330215 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -41,7 +41,6 @@
41 41
42#define pr_fmt(fmt) "acpiphp_glue: " fmt 42#define pr_fmt(fmt) "acpiphp_glue: " fmt
43 43
44#include <linux/init.h>
45#include <linux/module.h> 44#include <linux/module.h>
46 45
47#include <linux/kernel.h> 46#include <linux/kernel.h>
@@ -501,7 +500,7 @@ static int acpiphp_rescan_slot(struct acpiphp_slot *slot)
501 * This function should be called per *physical slot*, 500 * This function should be called per *physical slot*,
502 * not per each slot object in ACPI namespace. 501 * not per each slot object in ACPI namespace.
503 */ 502 */
504static void __ref enable_slot(struct acpiphp_slot *slot) 503static void enable_slot(struct acpiphp_slot *slot)
505{ 504{
506 struct pci_dev *dev; 505 struct pci_dev *dev;
507 struct pci_bus *bus = slot->bus; 506 struct pci_bus *bus = slot->bus;
@@ -516,8 +515,7 @@ static void __ref enable_slot(struct acpiphp_slot *slot)
516 if (PCI_SLOT(dev->devfn) != slot->device) 515 if (PCI_SLOT(dev->devfn) != slot->device)
517 continue; 516 continue;
518 517
519 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 518 if (pci_is_bridge(dev)) {
520 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
521 max = pci_scan_bridge(bus, dev, max, pass); 519 max = pci_scan_bridge(bus, dev, max, pass);
522 if (pass && dev->subordinate) { 520 if (pass && dev->subordinate) {
523 check_hotplug_bridge(slot, dev); 521 check_hotplug_bridge(slot, dev);
diff --git a/drivers/pci/hotplug/cpci_hotplug_pci.c b/drivers/pci/hotplug/cpci_hotplug_pci.c
index 8c1464851768..f6ef64c2ccb5 100644
--- a/drivers/pci/hotplug/cpci_hotplug_pci.c
+++ b/drivers/pci/hotplug/cpci_hotplug_pci.c
@@ -250,7 +250,7 @@ int cpci_led_off(struct slot* slot)
250 * Device configuration functions 250 * Device configuration functions
251 */ 251 */
252 252
253int __ref cpci_configure_slot(struct slot *slot) 253int cpci_configure_slot(struct slot *slot)
254{ 254{
255 struct pci_dev *dev; 255 struct pci_dev *dev;
256 struct pci_bus *parent; 256 struct pci_bus *parent;
@@ -289,8 +289,7 @@ int __ref cpci_configure_slot(struct slot *slot)
289 list_for_each_entry(dev, &parent->devices, bus_list) 289 list_for_each_entry(dev, &parent->devices, bus_list)
290 if (PCI_SLOT(dev->devfn) != PCI_SLOT(slot->devfn)) 290 if (PCI_SLOT(dev->devfn) != PCI_SLOT(slot->devfn))
291 continue; 291 continue;
292 if ((dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) || 292 if (pci_is_bridge(dev))
293 (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS))
294 pci_hp_add_bridge(dev); 293 pci_hp_add_bridge(dev);
295 294
296 295
diff --git a/drivers/pci/hotplug/cpqphp_ctrl.c b/drivers/pci/hotplug/cpqphp_ctrl.c
index 11845b796799..f593585f2784 100644
--- a/drivers/pci/hotplug/cpqphp_ctrl.c
+++ b/drivers/pci/hotplug/cpqphp_ctrl.c
@@ -709,7 +709,8 @@ static struct pci_resource *get_max_resource(struct pci_resource **head, u32 siz
709 temp = temp->next; 709 temp = temp->next;
710 } 710 }
711 711
712 temp->next = max->next; 712 if (temp)
713 temp->next = max->next;
713 } 714 }
714 715
715 max->next = NULL; 716 max->next = NULL;
diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
index 76ba8a1c774d..9600a392eaae 100644
--- a/drivers/pci/hotplug/cpqphp_nvram.c
+++ b/drivers/pci/hotplug/cpqphp_nvram.c
@@ -34,7 +34,6 @@
34#include <linux/workqueue.h> 34#include <linux/workqueue.h>
35#include <linux/pci.h> 35#include <linux/pci.h>
36#include <linux/pci_hotplug.h> 36#include <linux/pci_hotplug.h>
37#include <linux/init.h>
38#include <asm/uaccess.h> 37#include <asm/uaccess.h>
39#include "cpqphp.h" 38#include "cpqphp.h"
40#include "cpqphp_nvram.h" 39#include "cpqphp_nvram.h"
diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h
index 8a66866b8cf1..8e9012dca450 100644
--- a/drivers/pci/hotplug/pciehp.h
+++ b/drivers/pci/hotplug/pciehp.h
@@ -127,7 +127,7 @@ struct controller {
127#define HP_SUPR_RM(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_HPS) 127#define HP_SUPR_RM(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_HPS)
128#define EMI(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_EIP) 128#define EMI(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_EIP)
129#define NO_CMD_CMPL(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_NCCS) 129#define NO_CMD_CMPL(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_NCCS)
130#define PSN(ctrl) ((ctrl)->slot_cap >> 19) 130#define PSN(ctrl) (((ctrl)->slot_cap & PCI_EXP_SLTCAP_PSN) >> 19)
131 131
132int pciehp_sysfs_enable_slot(struct slot *slot); 132int pciehp_sysfs_enable_slot(struct slot *slot);
133int pciehp_sysfs_disable_slot(struct slot *slot); 133int pciehp_sysfs_disable_slot(struct slot *slot);
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index d7d058fa19a4..1463412cf7f8 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -159,6 +159,8 @@ static void pcie_write_cmd(struct controller *ctrl, u16 cmd, u16 mask)
159 159
160 pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status); 160 pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status);
161 if (slot_status & PCI_EXP_SLTSTA_CC) { 161 if (slot_status & PCI_EXP_SLTSTA_CC) {
162 pcie_capability_write_word(pdev, PCI_EXP_SLTSTA,
163 PCI_EXP_SLTSTA_CC);
162 if (!ctrl->no_cmd_complete) { 164 if (!ctrl->no_cmd_complete) {
163 /* 165 /*
164 * After 1 sec and CMD_COMPLETED still not set, just 166 * After 1 sec and CMD_COMPLETED still not set, just
diff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c
index 1b533060ce65..b6cb1df67097 100644
--- a/drivers/pci/hotplug/pciehp_pci.c
+++ b/drivers/pci/hotplug/pciehp_pci.c
@@ -62,8 +62,7 @@ int pciehp_configure_device(struct slot *p_slot)
62 } 62 }
63 63
64 list_for_each_entry(dev, &parent->devices, bus_list) 64 list_for_each_entry(dev, &parent->devices, bus_list)
65 if ((dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) || 65 if (pci_is_bridge(dev))
66 (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS))
67 pci_hp_add_bridge(dev); 66 pci_hp_add_bridge(dev);
68 67
69 pci_assign_unassigned_bridge_resources(bridge); 68 pci_assign_unassigned_bridge_resources(bridge);
diff --git a/drivers/pci/hotplug/pcihp_slot.c b/drivers/pci/hotplug/pcihp_slot.c
index 16f920352317..e246a10a0d2c 100644
--- a/drivers/pci/hotplug/pcihp_slot.c
+++ b/drivers/pci/hotplug/pcihp_slot.c
@@ -160,8 +160,7 @@ void pci_configure_slot(struct pci_dev *dev)
160 (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI))) 160 (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI)))
161 return; 161 return;
162 162
163 if (dev->bus) 163 pcie_bus_configure_settings(dev->bus);
164 pcie_bus_configure_settings(dev->bus);
165 164
166 memset(&hpp, 0, sizeof(hpp)); 165 memset(&hpp, 0, sizeof(hpp));
167 ret = pci_get_hp_params(dev, &hpp); 166 ret = pci_get_hp_params(dev, &hpp);
diff --git a/drivers/pci/hotplug/rpadlpar_core.c b/drivers/pci/hotplug/rpadlpar_core.c
index 4fcdeedda31b..7660232ef460 100644
--- a/drivers/pci/hotplug/rpadlpar_core.c
+++ b/drivers/pci/hotplug/rpadlpar_core.c
@@ -157,8 +157,7 @@ static void dlpar_pci_add_bus(struct device_node *dn)
157 } 157 }
158 158
159 /* Scan below the new bridge */ 159 /* Scan below the new bridge */
160 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 160 if (pci_is_bridge(dev))
161 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
162 of_scan_pci_bridge(dev); 161 of_scan_pci_bridge(dev);
163 162
164 /* Map IO space for child bus, which may or may not succeed */ 163 /* Map IO space for child bus, which may or may not succeed */
diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c
index 4796c15fba94..984d708552f6 100644
--- a/drivers/pci/hotplug/rpaphp_core.c
+++ b/drivers/pci/hotplug/rpaphp_core.c
@@ -223,16 +223,16 @@ int rpaphp_get_drc_props(struct device_node *dn, int *drc_index,
223 type_tmp = (char *) &types[1]; 223 type_tmp = (char *) &types[1];
224 224
225 /* Iterate through parent properties, looking for my-drc-index */ 225 /* Iterate through parent properties, looking for my-drc-index */
226 for (i = 0; i < indexes[0]; i++) { 226 for (i = 0; i < be32_to_cpu(indexes[0]); i++) {
227 if ((unsigned int) indexes[i + 1] == *my_index) { 227 if ((unsigned int) indexes[i + 1] == *my_index) {
228 if (drc_name) 228 if (drc_name)
229 *drc_name = name_tmp; 229 *drc_name = name_tmp;
230 if (drc_type) 230 if (drc_type)
231 *drc_type = type_tmp; 231 *drc_type = type_tmp;
232 if (drc_index) 232 if (drc_index)
233 *drc_index = *my_index; 233 *drc_index = be32_to_cpu(*my_index);
234 if (drc_power_domain) 234 if (drc_power_domain)
235 *drc_power_domain = domains[i+1]; 235 *drc_power_domain = be32_to_cpu(domains[i+1]);
236 return 0; 236 return 0;
237 } 237 }
238 name_tmp += (strlen(name_tmp) + 1); 238 name_tmp += (strlen(name_tmp) + 1);
@@ -321,16 +321,19 @@ int rpaphp_add_slot(struct device_node *dn)
321 /* register PCI devices */ 321 /* register PCI devices */
322 name = (char *) &names[1]; 322 name = (char *) &names[1];
323 type = (char *) &types[1]; 323 type = (char *) &types[1];
324 for (i = 0; i < indexes[0]; i++) { 324 for (i = 0; i < be32_to_cpu(indexes[0]); i++) {
325 int index;
325 326
326 slot = alloc_slot_struct(dn, indexes[i + 1], name, power_domains[i + 1]); 327 index = be32_to_cpu(indexes[i + 1]);
328 slot = alloc_slot_struct(dn, index, name,
329 be32_to_cpu(power_domains[i + 1]));
327 if (!slot) 330 if (!slot)
328 return -ENOMEM; 331 return -ENOMEM;
329 332
330 slot->type = simple_strtoul(type, NULL, 10); 333 slot->type = simple_strtoul(type, NULL, 10);
331 334
332 dbg("Found drc-index:0x%x drc-name:%s drc-type:%s\n", 335 dbg("Found drc-index:0x%x drc-name:%s drc-type:%s\n",
333 indexes[i + 1], name, type); 336 index, name, type);
334 337
335 retval = rpaphp_enable_slot(slot); 338 retval = rpaphp_enable_slot(slot);
336 if (!retval) 339 if (!retval)
diff --git a/drivers/pci/hotplug/s390_pci_hpc.c b/drivers/pci/hotplug/s390_pci_hpc.c
index 8d2ce22151eb..d1332d2f8730 100644
--- a/drivers/pci/hotplug/s390_pci_hpc.c
+++ b/drivers/pci/hotplug/s390_pci_hpc.c
@@ -15,7 +15,6 @@
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/pci.h> 16#include <linux/pci.h>
17#include <linux/pci_hotplug.h> 17#include <linux/pci_hotplug.h>
18#include <linux/init.h>
19#include <asm/pci_debug.h> 18#include <asm/pci_debug.h>
20#include <asm/sclp.h> 19#include <asm/sclp.h>
21 20
diff --git a/drivers/pci/hotplug/shpchp_pci.c b/drivers/pci/hotplug/shpchp_pci.c
index 2bf69fe1926c..9202d133485c 100644
--- a/drivers/pci/hotplug/shpchp_pci.c
+++ b/drivers/pci/hotplug/shpchp_pci.c
@@ -34,7 +34,7 @@
34#include "../pci.h" 34#include "../pci.h"
35#include "shpchp.h" 35#include "shpchp.h"
36 36
37int __ref shpchp_configure_device(struct slot *p_slot) 37int shpchp_configure_device(struct slot *p_slot)
38{ 38{
39 struct pci_dev *dev; 39 struct pci_dev *dev;
40 struct controller *ctrl = p_slot->ctrl; 40 struct controller *ctrl = p_slot->ctrl;
@@ -64,8 +64,7 @@ int __ref shpchp_configure_device(struct slot *p_slot)
64 list_for_each_entry(dev, &parent->devices, bus_list) { 64 list_for_each_entry(dev, &parent->devices, bus_list) {
65 if (PCI_SLOT(dev->devfn) != p_slot->device) 65 if (PCI_SLOT(dev->devfn) != p_slot->device)
66 continue; 66 continue;
67 if ((dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) || 67 if (pci_is_bridge(dev))
68 (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS))
69 pci_hp_add_bridge(dev); 68 pci_hp_add_bridge(dev);
70 } 69 }
71 70
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index de7a74782f92..cb6f24740ee3 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -106,7 +106,7 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset)
106 pci_device_add(virtfn, virtfn->bus); 106 pci_device_add(virtfn, virtfn->bus);
107 mutex_unlock(&iov->dev->sriov->lock); 107 mutex_unlock(&iov->dev->sriov->lock);
108 108
109 rc = pci_bus_add_device(virtfn); 109 pci_bus_add_device(virtfn);
110 sprintf(buf, "virtfn%u", id); 110 sprintf(buf, "virtfn%u", id);
111 rc = sysfs_create_link(&dev->dev.kobj, &virtfn->dev.kobj, buf); 111 rc = sysfs_create_link(&dev->dev.kobj, &virtfn->dev.kobj, buf);
112 if (rc) 112 if (rc)
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 955ab7990c5b..27a7e67ddfe4 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -10,7 +10,6 @@
10#include <linux/mm.h> 10#include <linux/mm.h>
11#include <linux/irq.h> 11#include <linux/irq.h>
12#include <linux/interrupt.h> 12#include <linux/interrupt.h>
13#include <linux/init.h>
14#include <linux/export.h> 13#include <linux/export.h>
15#include <linux/ioport.h> 14#include <linux/ioport.h>
16#include <linux/pci.h> 15#include <linux/pci.h>
@@ -544,22 +543,18 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
544 if (!msi_attrs) 543 if (!msi_attrs)
545 return -ENOMEM; 544 return -ENOMEM;
546 list_for_each_entry(entry, &pdev->msi_list, list) { 545 list_for_each_entry(entry, &pdev->msi_list, list) {
547 char *name = kmalloc(20, GFP_KERNEL);
548 if (!name)
549 goto error_attrs;
550
551 msi_dev_attr = kzalloc(sizeof(*msi_dev_attr), GFP_KERNEL); 546 msi_dev_attr = kzalloc(sizeof(*msi_dev_attr), GFP_KERNEL);
552 if (!msi_dev_attr) { 547 if (!msi_dev_attr)
553 kfree(name);
554 goto error_attrs; 548 goto error_attrs;
555 } 549 msi_attrs[count] = &msi_dev_attr->attr;
556 550
557 sprintf(name, "%d", entry->irq);
558 sysfs_attr_init(&msi_dev_attr->attr); 551 sysfs_attr_init(&msi_dev_attr->attr);
559 msi_dev_attr->attr.name = name; 552 msi_dev_attr->attr.name = kasprintf(GFP_KERNEL, "%d",
553 entry->irq);
554 if (!msi_dev_attr->attr.name)
555 goto error_attrs;
560 msi_dev_attr->attr.mode = S_IRUGO; 556 msi_dev_attr->attr.mode = S_IRUGO;
561 msi_dev_attr->show = msi_mode_show; 557 msi_dev_attr->show = msi_mode_show;
562 msi_attrs[count] = &msi_dev_attr->attr;
563 ++count; 558 ++count;
564 } 559 }
565 560
@@ -883,50 +878,6 @@ int pci_msi_vec_count(struct pci_dev *dev)
883} 878}
884EXPORT_SYMBOL(pci_msi_vec_count); 879EXPORT_SYMBOL(pci_msi_vec_count);
885 880
886/**
887 * pci_enable_msi_block - configure device's MSI capability structure
888 * @dev: device to configure
889 * @nvec: number of interrupts to configure
890 *
891 * Allocate IRQs for a device with the MSI capability.
892 * This function returns a negative errno if an error occurs. If it
893 * is unable to allocate the number of interrupts requested, it returns
894 * the number of interrupts it might be able to allocate. If it successfully
895 * allocates at least the number of interrupts requested, it returns 0 and
896 * updates the @dev's irq member to the lowest new interrupt number; the
897 * other interrupt numbers allocated to this device are consecutive.
898 */
899int pci_enable_msi_block(struct pci_dev *dev, int nvec)
900{
901 int status, maxvec;
902
903 if (dev->current_state != PCI_D0)
904 return -EINVAL;
905
906 maxvec = pci_msi_vec_count(dev);
907 if (maxvec < 0)
908 return maxvec;
909 if (nvec > maxvec)
910 return maxvec;
911
912 status = pci_msi_check_device(dev, nvec, PCI_CAP_ID_MSI);
913 if (status)
914 return status;
915
916 WARN_ON(!!dev->msi_enabled);
917
918 /* Check whether driver already requested MSI-X irqs */
919 if (dev->msix_enabled) {
920 dev_info(&dev->dev, "can't enable MSI "
921 "(MSI-X already enabled)\n");
922 return -EINVAL;
923 }
924
925 status = msi_capability_init(dev, nvec);
926 return status;
927}
928EXPORT_SYMBOL(pci_enable_msi_block);
929
930void pci_msi_shutdown(struct pci_dev *dev) 881void pci_msi_shutdown(struct pci_dev *dev)
931{ 882{
932 struct msi_desc *desc; 883 struct msi_desc *desc;
@@ -1132,14 +1083,45 @@ void pci_msi_init_pci_dev(struct pci_dev *dev)
1132 **/ 1083 **/
1133int pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec) 1084int pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec)
1134{ 1085{
1135 int nvec = maxvec; 1086 int nvec;
1136 int rc; 1087 int rc;
1137 1088
1089 if (dev->current_state != PCI_D0)
1090 return -EINVAL;
1091
1092 WARN_ON(!!dev->msi_enabled);
1093
1094 /* Check whether driver already requested MSI-X irqs */
1095 if (dev->msix_enabled) {
1096 dev_info(&dev->dev,
1097 "can't enable MSI (MSI-X already enabled)\n");
1098 return -EINVAL;
1099 }
1100
1138 if (maxvec < minvec) 1101 if (maxvec < minvec)
1139 return -ERANGE; 1102 return -ERANGE;
1140 1103
1104 nvec = pci_msi_vec_count(dev);
1105 if (nvec < 0)
1106 return nvec;
1107 else if (nvec < minvec)
1108 return -EINVAL;
1109 else if (nvec > maxvec)
1110 nvec = maxvec;
1111
1112 do {
1113 rc = pci_msi_check_device(dev, nvec, PCI_CAP_ID_MSI);
1114 if (rc < 0) {
1115 return rc;
1116 } else if (rc > 0) {
1117 if (rc < minvec)
1118 return -ENOSPC;
1119 nvec = rc;
1120 }
1121 } while (rc);
1122
1141 do { 1123 do {
1142 rc = pci_enable_msi_block(dev, nvec); 1124 rc = msi_capability_init(dev, nvec);
1143 if (rc < 0) { 1125 if (rc < 0) {
1144 return rc; 1126 return rc;
1145 } else if (rc > 0) { 1127 } else if (rc > 0) {
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index f49abef88485..ca4927ba8433 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -309,13 +309,7 @@ static struct acpi_device *acpi_pci_find_companion(struct device *dev)
309 bool check_children; 309 bool check_children;
310 u64 addr; 310 u64 addr;
311 311
312 /* 312 check_children = pci_is_bridge(pci_dev);
313 * pci_is_bridge() is not suitable here, because pci_dev->subordinate
314 * is set only after acpi_pci_find_device() has been called for the
315 * given device.
316 */
317 check_children = pci_dev->hdr_type == PCI_HEADER_TYPE_BRIDGE
318 || pci_dev->hdr_type == PCI_HEADER_TYPE_CARDBUS;
319 /* Please ref to ACPI spec for the syntax of _ADR */ 313 /* Please ref to ACPI spec for the syntax of _ADR */
320 addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn); 314 addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
321 return acpi_find_child_device(ACPI_COMPANION(dev->parent), addr, 315 return acpi_find_child_device(ACPI_COMPANION(dev->parent), addr,
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index d911e0c1f359..837d71f5390b 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -107,7 +107,7 @@ store_new_id(struct device_driver *driver, const char *buf, size_t count)
107 subdevice=PCI_ANY_ID, class=0, class_mask=0; 107 subdevice=PCI_ANY_ID, class=0, class_mask=0;
108 unsigned long driver_data=0; 108 unsigned long driver_data=0;
109 int fields=0; 109 int fields=0;
110 int retval; 110 int retval = 0;
111 111
112 fields = sscanf(buf, "%x %x %x %x %x %x %lx", 112 fields = sscanf(buf, "%x %x %x %x %x %x %lx",
113 &vendor, &device, &subvendor, &subdevice, 113 &vendor, &device, &subvendor, &subdevice,
@@ -115,6 +115,26 @@ store_new_id(struct device_driver *driver, const char *buf, size_t count)
115 if (fields < 2) 115 if (fields < 2)
116 return -EINVAL; 116 return -EINVAL;
117 117
118 if (fields != 7) {
119 struct pci_dev *pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
120 if (!pdev)
121 return -ENOMEM;
122
123 pdev->vendor = vendor;
124 pdev->device = device;
125 pdev->subsystem_vendor = subvendor;
126 pdev->subsystem_device = subdevice;
127 pdev->class = class;
128
129 if (pci_match_id(pdrv->id_table, pdev))
130 retval = -EEXIST;
131
132 kfree(pdev);
133
134 if (retval)
135 return retval;
136 }
137
118 /* Only accept driver_data values that match an existing id_table 138 /* Only accept driver_data values that match an existing id_table
119 entry */ 139 entry */
120 if (ids) { 140 if (ids) {
@@ -216,6 +236,13 @@ const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
216 return NULL; 236 return NULL;
217} 237}
218 238
239static const struct pci_device_id pci_device_id_any = {
240 .vendor = PCI_ANY_ID,
241 .device = PCI_ANY_ID,
242 .subvendor = PCI_ANY_ID,
243 .subdevice = PCI_ANY_ID,
244};
245
219/** 246/**
220 * pci_match_device - Tell if a PCI device structure has a matching PCI device id structure 247 * pci_match_device - Tell if a PCI device structure has a matching PCI device id structure
221 * @drv: the PCI driver to match against 248 * @drv: the PCI driver to match against
@@ -229,18 +256,30 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv,
229 struct pci_dev *dev) 256 struct pci_dev *dev)
230{ 257{
231 struct pci_dynid *dynid; 258 struct pci_dynid *dynid;
259 const struct pci_device_id *found_id = NULL;
260
261 /* When driver_override is set, only bind to the matching driver */
262 if (dev->driver_override && strcmp(dev->driver_override, drv->name))
263 return NULL;
232 264
233 /* Look at the dynamic ids first, before the static ones */ 265 /* Look at the dynamic ids first, before the static ones */
234 spin_lock(&drv->dynids.lock); 266 spin_lock(&drv->dynids.lock);
235 list_for_each_entry(dynid, &drv->dynids.list, node) { 267 list_for_each_entry(dynid, &drv->dynids.list, node) {
236 if (pci_match_one_device(&dynid->id, dev)) { 268 if (pci_match_one_device(&dynid->id, dev)) {
237 spin_unlock(&drv->dynids.lock); 269 found_id = &dynid->id;
238 return &dynid->id; 270 break;
239 } 271 }
240 } 272 }
241 spin_unlock(&drv->dynids.lock); 273 spin_unlock(&drv->dynids.lock);
242 274
243 return pci_match_id(drv->id_table, dev); 275 if (!found_id)
276 found_id = pci_match_id(drv->id_table, dev);
277
278 /* driver_override will always match, send a dummy id */
279 if (!found_id && dev->driver_override)
280 found_id = &pci_device_id_any;
281
282 return found_id;
244} 283}
245 284
246struct drv_dev_and_id { 285struct drv_dev_and_id {
@@ -580,14 +619,14 @@ static void pci_pm_default_resume(struct pci_dev *pci_dev)
580{ 619{
581 pci_fixup_device(pci_fixup_resume, pci_dev); 620 pci_fixup_device(pci_fixup_resume, pci_dev);
582 621
583 if (!pci_is_bridge(pci_dev)) 622 if (!pci_has_subordinate(pci_dev))
584 pci_enable_wake(pci_dev, PCI_D0, false); 623 pci_enable_wake(pci_dev, PCI_D0, false);
585} 624}
586 625
587static void pci_pm_default_suspend(struct pci_dev *pci_dev) 626static void pci_pm_default_suspend(struct pci_dev *pci_dev)
588{ 627{
589 /* Disable non-bridge devices without PM support */ 628 /* Disable non-bridge devices without PM support */
590 if (!pci_is_bridge(pci_dev)) 629 if (!pci_has_subordinate(pci_dev))
591 pci_disable_enabled_device(pci_dev); 630 pci_disable_enabled_device(pci_dev);
592} 631}
593 632
@@ -717,7 +756,7 @@ static int pci_pm_suspend_noirq(struct device *dev)
717 756
718 if (!pci_dev->state_saved) { 757 if (!pci_dev->state_saved) {
719 pci_save_state(pci_dev); 758 pci_save_state(pci_dev);
720 if (!pci_is_bridge(pci_dev)) 759 if (!pci_has_subordinate(pci_dev))
721 pci_prepare_to_sleep(pci_dev); 760 pci_prepare_to_sleep(pci_dev);
722 } 761 }
723 762
@@ -971,7 +1010,7 @@ static int pci_pm_poweroff_noirq(struct device *dev)
971 return error; 1010 return error;
972 } 1011 }
973 1012
974 if (!pci_dev->state_saved && !pci_is_bridge(pci_dev)) 1013 if (!pci_dev->state_saved && !pci_has_subordinate(pci_dev))
975 pci_prepare_to_sleep(pci_dev); 1014 pci_prepare_to_sleep(pci_dev);
976 1015
977 /* 1016 /*
@@ -1325,8 +1364,6 @@ static int pci_uevent(struct device *dev, struct kobj_uevent_env *env)
1325 return -ENODEV; 1364 return -ENODEV;
1326 1365
1327 pdev = to_pci_dev(dev); 1366 pdev = to_pci_dev(dev);
1328 if (!pdev)
1329 return -ENODEV;
1330 1367
1331 if (add_uevent_var(env, "PCI_CLASS=%04X", pdev->class)) 1368 if (add_uevent_var(env, "PCI_CLASS=%04X", pdev->class))
1332 return -ENOMEM; 1369 return -ENOMEM;
@@ -1347,6 +1384,7 @@ static int pci_uevent(struct device *dev, struct kobj_uevent_env *env)
1347 (u8)(pdev->class >> 16), (u8)(pdev->class >> 8), 1384 (u8)(pdev->class >> 16), (u8)(pdev->class >> 8),
1348 (u8)(pdev->class))) 1385 (u8)(pdev->class)))
1349 return -ENOMEM; 1386 return -ENOMEM;
1387
1350 return 0; 1388 return 0;
1351} 1389}
1352 1390
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 4e0acefb7565..84c350994b06 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -29,6 +29,7 @@
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/vgaarb.h> 30#include <linux/vgaarb.h>
31#include <linux/pm_runtime.h> 31#include <linux/pm_runtime.h>
32#include <linux/of.h>
32#include "pci.h" 33#include "pci.h"
33 34
34static int sysfs_initialized; /* = 0 */ 35static int sysfs_initialized; /* = 0 */
@@ -416,6 +417,20 @@ static ssize_t d3cold_allowed_show(struct device *dev,
416static DEVICE_ATTR_RW(d3cold_allowed); 417static DEVICE_ATTR_RW(d3cold_allowed);
417#endif 418#endif
418 419
420#ifdef CONFIG_OF
421static ssize_t devspec_show(struct device *dev,
422 struct device_attribute *attr, char *buf)
423{
424 struct pci_dev *pdev = to_pci_dev(dev);
425 struct device_node *np = pci_device_to_OF_node(pdev);
426
427 if (np == NULL || np->full_name == NULL)
428 return 0;
429 return sprintf(buf, "%s", np->full_name);
430}
431static DEVICE_ATTR_RO(devspec);
432#endif
433
419#ifdef CONFIG_PCI_IOV 434#ifdef CONFIG_PCI_IOV
420static ssize_t sriov_totalvfs_show(struct device *dev, 435static ssize_t sriov_totalvfs_show(struct device *dev,
421 struct device_attribute *attr, 436 struct device_attribute *attr,
@@ -499,6 +514,45 @@ static struct device_attribute sriov_numvfs_attr =
499 sriov_numvfs_show, sriov_numvfs_store); 514 sriov_numvfs_show, sriov_numvfs_store);
500#endif /* CONFIG_PCI_IOV */ 515#endif /* CONFIG_PCI_IOV */
501 516
517static ssize_t driver_override_store(struct device *dev,
518 struct device_attribute *attr,
519 const char *buf, size_t count)
520{
521 struct pci_dev *pdev = to_pci_dev(dev);
522 char *driver_override, *old = pdev->driver_override, *cp;
523
524 if (count > PATH_MAX)
525 return -EINVAL;
526
527 driver_override = kstrndup(buf, count, GFP_KERNEL);
528 if (!driver_override)
529 return -ENOMEM;
530
531 cp = strchr(driver_override, '\n');
532 if (cp)
533 *cp = '\0';
534
535 if (strlen(driver_override)) {
536 pdev->driver_override = driver_override;
537 } else {
538 kfree(driver_override);
539 pdev->driver_override = NULL;
540 }
541
542 kfree(old);
543
544 return count;
545}
546
547static ssize_t driver_override_show(struct device *dev,
548 struct device_attribute *attr, char *buf)
549{
550 struct pci_dev *pdev = to_pci_dev(dev);
551
552 return sprintf(buf, "%s\n", pdev->driver_override);
553}
554static DEVICE_ATTR_RW(driver_override);
555
502static struct attribute *pci_dev_attrs[] = { 556static struct attribute *pci_dev_attrs[] = {
503 &dev_attr_resource.attr, 557 &dev_attr_resource.attr,
504 &dev_attr_vendor.attr, 558 &dev_attr_vendor.attr,
@@ -521,6 +575,10 @@ static struct attribute *pci_dev_attrs[] = {
521#if defined(CONFIG_PM_RUNTIME) && defined(CONFIG_ACPI) 575#if defined(CONFIG_PM_RUNTIME) && defined(CONFIG_ACPI)
522 &dev_attr_d3cold_allowed.attr, 576 &dev_attr_d3cold_allowed.attr,
523#endif 577#endif
578#ifdef CONFIG_OF
579 &dev_attr_devspec.attr,
580#endif
581 &dev_attr_driver_override.attr,
524 NULL, 582 NULL,
525}; 583};
526 584
@@ -1255,11 +1313,6 @@ static struct bin_attribute pcie_config_attr = {
1255 .write = pci_write_config, 1313 .write = pci_write_config,
1256}; 1314};
1257 1315
1258int __weak pcibios_add_platform_entries(struct pci_dev *dev)
1259{
1260 return 0;
1261}
1262
1263static ssize_t reset_store(struct device *dev, 1316static ssize_t reset_store(struct device *dev,
1264 struct device_attribute *attr, const char *buf, 1317 struct device_attribute *attr, const char *buf,
1265 size_t count) 1318 size_t count)
@@ -1375,11 +1428,6 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
1375 pdev->rom_attr = attr; 1428 pdev->rom_attr = attr;
1376 } 1429 }
1377 1430
1378 /* add platform-specific attributes */
1379 retval = pcibios_add_platform_entries(pdev);
1380 if (retval)
1381 goto err_rom_file;
1382
1383 /* add sysfs entries for various capabilities */ 1431 /* add sysfs entries for various capabilities */
1384 retval = pci_create_capabilities_sysfs(pdev); 1432 retval = pci_create_capabilities_sysfs(pdev);
1385 if (retval) 1433 if (retval)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 759475ef6ff3..7ae7aa0166b6 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1468,6 +1468,17 @@ void __weak pcibios_release_device(struct pci_dev *dev) {}
1468 */ 1468 */
1469void __weak pcibios_disable_device (struct pci_dev *dev) {} 1469void __weak pcibios_disable_device (struct pci_dev *dev) {}
1470 1470
1471/**
1472 * pcibios_penalize_isa_irq - penalize an ISA IRQ
1473 * @irq: ISA IRQ to penalize
1474 * @active: IRQ active or not
1475 *
1476 * Permits the platform to provide architecture-specific functionality when
1477 * penalizing ISA IRQs. This is the default implementation. Architecture
1478 * implementations can override this.
1479 */
1480void __weak pcibios_penalize_isa_irq(int irq, int active) {}
1481
1471static void do_pci_disable_device(struct pci_dev *dev) 1482static void do_pci_disable_device(struct pci_dev *dev)
1472{ 1483{
1473 u16 pci_command; 1484 u16 pci_command;
@@ -3306,8 +3317,27 @@ static void pci_dev_unlock(struct pci_dev *dev)
3306 pci_cfg_access_unlock(dev); 3317 pci_cfg_access_unlock(dev);
3307} 3318}
3308 3319
3320/**
3321 * pci_reset_notify - notify device driver of reset
3322 * @dev: device to be notified of reset
3323 * @prepare: 'true' if device is about to be reset; 'false' if reset attempt
3324 * completed
3325 *
3326 * Must be called prior to device access being disabled and after device
3327 * access is restored.
3328 */
3329static void pci_reset_notify(struct pci_dev *dev, bool prepare)
3330{
3331 const struct pci_error_handlers *err_handler =
3332 dev->driver ? dev->driver->err_handler : NULL;
3333 if (err_handler && err_handler->reset_notify)
3334 err_handler->reset_notify(dev, prepare);
3335}
3336
3309static void pci_dev_save_and_disable(struct pci_dev *dev) 3337static void pci_dev_save_and_disable(struct pci_dev *dev)
3310{ 3338{
3339 pci_reset_notify(dev, true);
3340
3311 /* 3341 /*
3312 * Wake-up device prior to save. PM registers default to D0 after 3342 * Wake-up device prior to save. PM registers default to D0 after
3313 * reset and a simple register restore doesn't reliably return 3343 * reset and a simple register restore doesn't reliably return
@@ -3329,6 +3359,7 @@ static void pci_dev_save_and_disable(struct pci_dev *dev)
3329static void pci_dev_restore(struct pci_dev *dev) 3359static void pci_dev_restore(struct pci_dev *dev)
3330{ 3360{
3331 pci_restore_state(dev); 3361 pci_restore_state(dev);
3362 pci_reset_notify(dev, false);
3332} 3363}
3333 3364
3334static int pci_dev_reset(struct pci_dev *dev, int probe) 3365static int pci_dev_reset(struct pci_dev *dev, int probe)
@@ -3345,6 +3376,7 @@ static int pci_dev_reset(struct pci_dev *dev, int probe)
3345 3376
3346 return rc; 3377 return rc;
3347} 3378}
3379
3348/** 3380/**
3349 * __pci_reset_function - reset a PCI device function 3381 * __pci_reset_function - reset a PCI device function
3350 * @dev: PCI device to reset 3382 * @dev: PCI device to reset
@@ -4126,7 +4158,7 @@ int pci_set_vga_state(struct pci_dev *dev, bool decode,
4126 u16 cmd; 4158 u16 cmd;
4127 int rc; 4159 int rc;
4128 4160
4129 WARN_ON((flags & PCI_VGA_STATE_CHANGE_DECODES) & (command_bits & ~(PCI_COMMAND_IO|PCI_COMMAND_MEMORY))); 4161 WARN_ON((flags & PCI_VGA_STATE_CHANGE_DECODES) && (command_bits & ~(PCI_COMMAND_IO|PCI_COMMAND_MEMORY)));
4130 4162
4131 /* ARCH specific VGA enables */ 4163 /* ARCH specific VGA enables */
4132 rc = pci_set_vga_state_arch(dev, decode, command_bits, flags); 4164 rc = pci_set_vga_state_arch(dev, decode, command_bits, flags);
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 6bd082299e31..0601890db22d 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -77,7 +77,7 @@ static inline void pci_wakeup_event(struct pci_dev *dev)
77 pm_wakeup_event(&dev->dev, 100); 77 pm_wakeup_event(&dev->dev, 100);
78} 78}
79 79
80static inline bool pci_is_bridge(struct pci_dev *pci_dev) 80static inline bool pci_has_subordinate(struct pci_dev *pci_dev)
81{ 81{
82 return !!(pci_dev->subordinate); 82 return !!(pci_dev->subordinate);
83} 83}
@@ -201,11 +201,11 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
201 struct resource *res, unsigned int reg); 201 struct resource *res, unsigned int reg);
202int pci_resource_bar(struct pci_dev *dev, int resno, enum pci_bar_type *type); 202int pci_resource_bar(struct pci_dev *dev, int resno, enum pci_bar_type *type);
203void pci_configure_ari(struct pci_dev *dev); 203void pci_configure_ari(struct pci_dev *dev);
204void __ref __pci_bus_size_bridges(struct pci_bus *bus, 204void __pci_bus_size_bridges(struct pci_bus *bus,
205 struct list_head *realloc_head); 205 struct list_head *realloc_head);
206void __ref __pci_bus_assign_resources(const struct pci_bus *bus, 206void __pci_bus_assign_resources(const struct pci_bus *bus,
207 struct list_head *realloc_head, 207 struct list_head *realloc_head,
208 struct list_head *fail_head); 208 struct list_head *fail_head);
209 209
210/** 210/**
211 * pci_ari_enabled - query ARI forwarding status 211 * pci_ari_enabled - query ARI forwarding status
diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index 986f8eadfd39..2f0ce668a775 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -99,7 +99,7 @@ static int pcie_port_enable_msix(struct pci_dev *dev, int *vectors, int mask)
99 for (i = 0; i < nr_entries; i++) 99 for (i = 0; i < nr_entries; i++)
100 msix_entries[i].entry = i; 100 msix_entries[i].entry = i;
101 101
102 status = pci_enable_msix(dev, msix_entries, nr_entries); 102 status = pci_enable_msix_exact(dev, msix_entries, nr_entries);
103 if (status) 103 if (status)
104 goto Exit; 104 goto Exit;
105 105
@@ -171,7 +171,7 @@ static int pcie_port_enable_msix(struct pci_dev *dev, int *vectors, int mask)
171 pci_disable_msix(dev); 171 pci_disable_msix(dev);
172 172
173 /* Now allocate the MSI-X vectors for real */ 173 /* Now allocate the MSI-X vectors for real */
174 status = pci_enable_msix(dev, msix_entries, nvec); 174 status = pci_enable_msix_exact(dev, msix_entries, nvec);
175 if (status) 175 if (status)
176 goto Exit; 176 goto Exit;
177 } 177 }
@@ -379,10 +379,13 @@ int pcie_port_device_register(struct pci_dev *dev)
379 /* 379 /*
380 * Initialize service irqs. Don't use service devices that 380 * Initialize service irqs. Don't use service devices that
381 * require interrupts if there is no way to generate them. 381 * require interrupts if there is no way to generate them.
382 * However, some drivers may have a polling mode (e.g. pciehp_poll_mode)
383 * that can be used in the absence of irqs. Allow them to determine
384 * if that is to be used.
382 */ 385 */
383 status = init_service_irqs(dev, irqs, capabilities); 386 status = init_service_irqs(dev, irqs, capabilities);
384 if (status) { 387 if (status) {
385 capabilities &= PCIE_PORT_SERVICE_VC; 388 capabilities &= PCIE_PORT_SERVICE_VC | PCIE_PORT_SERVICE_HP;
386 if (!capabilities) 389 if (!capabilities)
387 goto error_disable; 390 goto error_disable;
388 } 391 }
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index ef09f5f2fe6c..2bbf5221afb3 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -171,9 +171,10 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
171 struct resource *res, unsigned int pos) 171 struct resource *res, unsigned int pos)
172{ 172{
173 u32 l, sz, mask; 173 u32 l, sz, mask;
174 u64 l64, sz64, mask64;
174 u16 orig_cmd; 175 u16 orig_cmd;
175 struct pci_bus_region region, inverted_region; 176 struct pci_bus_region region, inverted_region;
176 bool bar_too_big = false, bar_disabled = false; 177 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
177 178
178 mask = type ? PCI_ROM_ADDRESS_MASK : ~0; 179 mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
179 180
@@ -226,9 +227,9 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
226 } 227 }
227 228
228 if (res->flags & IORESOURCE_MEM_64) { 229 if (res->flags & IORESOURCE_MEM_64) {
229 u64 l64 = l; 230 l64 = l;
230 u64 sz64 = sz; 231 sz64 = sz;
231 u64 mask64 = mask | (u64)~0 << 32; 232 mask64 = mask | (u64)~0 << 32;
232 233
233 pci_read_config_dword(dev, pos + 4, &l); 234 pci_read_config_dword(dev, pos + 4, &l);
234 pci_write_config_dword(dev, pos + 4, ~0); 235 pci_write_config_dword(dev, pos + 4, ~0);
@@ -243,19 +244,22 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
243 if (!sz64) 244 if (!sz64)
244 goto fail; 245 goto fail;
245 246
246 if ((sizeof(resource_size_t) < 8) && (sz64 > 0x100000000ULL)) { 247 if ((sizeof(dma_addr_t) < 8 || sizeof(resource_size_t) < 8) &&
248 sz64 > 0x100000000ULL) {
249 res->flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED;
250 res->start = 0;
251 res->end = 0;
247 bar_too_big = true; 252 bar_too_big = true;
248 goto fail; 253 goto out;
249 } 254 }
250 255
251 if ((sizeof(resource_size_t) < 8) && l) { 256 if ((sizeof(dma_addr_t) < 8) && l) {
252 /* Address above 32-bit boundary; disable the BAR */ 257 /* Above 32-bit boundary; try to reallocate */
253 pci_write_config_dword(dev, pos, 0);
254 pci_write_config_dword(dev, pos + 4, 0);
255 res->flags |= IORESOURCE_UNSET; 258 res->flags |= IORESOURCE_UNSET;
256 region.start = 0; 259 res->start = 0;
257 region.end = sz64; 260 res->end = sz64;
258 bar_disabled = true; 261 bar_too_high = true;
262 goto out;
259 } else { 263 } else {
260 region.start = l64; 264 region.start = l64;
261 region.end = l64 + sz64; 265 region.end = l64 + sz64;
@@ -285,11 +289,10 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
285 * be claimed by the device. 289 * be claimed by the device.
286 */ 290 */
287 if (inverted_region.start != region.start) { 291 if (inverted_region.start != region.start) {
288 dev_info(&dev->dev, "reg 0x%x: initial BAR value %pa invalid; forcing reassignment\n",
289 pos, &region.start);
290 res->flags |= IORESOURCE_UNSET; 292 res->flags |= IORESOURCE_UNSET;
291 res->end -= res->start;
292 res->start = 0; 293 res->start = 0;
294 res->end = region.end - region.start;
295 bar_invalid = true;
293 } 296 }
294 297
295 goto out; 298 goto out;
@@ -303,8 +306,15 @@ out:
303 pci_write_config_word(dev, PCI_COMMAND, orig_cmd); 306 pci_write_config_word(dev, PCI_COMMAND, orig_cmd);
304 307
305 if (bar_too_big) 308 if (bar_too_big)
306 dev_err(&dev->dev, "reg 0x%x: can't handle 64-bit BAR\n", pos); 309 dev_err(&dev->dev, "reg 0x%x: can't handle BAR larger than 4GB (size %#010llx)\n",
307 if (res->flags && !bar_disabled) 310 pos, (unsigned long long) sz64);
311 if (bar_too_high)
312 dev_info(&dev->dev, "reg 0x%x: can't handle BAR above 4G (bus address %#010llx)\n",
313 pos, (unsigned long long) l64);
314 if (bar_invalid)
315 dev_info(&dev->dev, "reg 0x%x: initial BAR value %#010llx invalid\n",
316 pos, (unsigned long long) region.start);
317 if (res->flags)
308 dev_printk(KERN_DEBUG, &dev->dev, "reg 0x%x: %pR\n", pos, res); 318 dev_printk(KERN_DEBUG, &dev->dev, "reg 0x%x: %pR\n", pos, res);
309 319
310 return (res->flags & IORESOURCE_MEM_64) ? 1 : 0; 320 return (res->flags & IORESOURCE_MEM_64) ? 1 : 0;
@@ -465,7 +475,7 @@ void pci_read_bridge_bases(struct pci_bus *child)
465 475
466 if (dev->transparent) { 476 if (dev->transparent) {
467 pci_bus_for_each_resource(child->parent, res, i) { 477 pci_bus_for_each_resource(child->parent, res, i) {
468 if (res) { 478 if (res && res->flags) {
469 pci_bus_add_resource(child, res, 479 pci_bus_add_resource(child, res,
470 PCI_SUBTRACTIVE_DECODE); 480 PCI_SUBTRACTIVE_DECODE);
471 dev_printk(KERN_DEBUG, &dev->dev, 481 dev_printk(KERN_DEBUG, &dev->dev,
@@ -719,7 +729,7 @@ add_dev:
719 return child; 729 return child;
720} 730}
721 731
722struct pci_bus *__ref pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, int busnr) 732struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, int busnr)
723{ 733{
724 struct pci_bus *child; 734 struct pci_bus *child;
725 735
@@ -984,6 +994,43 @@ void set_pcie_hotplug_bridge(struct pci_dev *pdev)
984 994
985 995
986/** 996/**
997 * pci_ext_cfg_is_aliased - is ext config space just an alias of std config?
998 * @dev: PCI device
999 *
1000 * PCI Express to PCI/PCI-X Bridge Specification, rev 1.0, 4.1.4 says that
1001 * when forwarding a type1 configuration request the bridge must check that
1002 * the extended register address field is zero. The bridge is not permitted
1003 * to forward the transactions and must handle it as an Unsupported Request.
1004 * Some bridges do not follow this rule and simply drop the extended register
1005 * bits, resulting in the standard config space being aliased, every 256
1006 * bytes across the entire configuration space. Test for this condition by
1007 * comparing the first dword of each potential alias to the vendor/device ID.
1008 * Known offenders:
1009 * ASM1083/1085 PCIe-to-PCI Reversible Bridge (1b21:1080, rev 01 & 03)
1010 * AMD/ATI SBx00 PCI to PCI Bridge (1002:4384, rev 40)
1011 */
1012static bool pci_ext_cfg_is_aliased(struct pci_dev *dev)
1013{
1014#ifdef CONFIG_PCI_QUIRKS
1015 int pos;
1016 u32 header, tmp;
1017
1018 pci_read_config_dword(dev, PCI_VENDOR_ID, &header);
1019
1020 for (pos = PCI_CFG_SPACE_SIZE;
1021 pos < PCI_CFG_SPACE_EXP_SIZE; pos += PCI_CFG_SPACE_SIZE) {
1022 if (pci_read_config_dword(dev, pos, &tmp) != PCIBIOS_SUCCESSFUL
1023 || header != tmp)
1024 return false;
1025 }
1026
1027 return true;
1028#else
1029 return false;
1030#endif
1031}
1032
1033/**
987 * pci_cfg_space_size - get the configuration space size of the PCI device. 1034 * pci_cfg_space_size - get the configuration space size of the PCI device.
988 * @dev: PCI device 1035 * @dev: PCI device
989 * 1036 *
@@ -1001,7 +1048,7 @@ static int pci_cfg_space_size_ext(struct pci_dev *dev)
1001 1048
1002 if (pci_read_config_dword(dev, pos, &status) != PCIBIOS_SUCCESSFUL) 1049 if (pci_read_config_dword(dev, pos, &status) != PCIBIOS_SUCCESSFUL)
1003 goto fail; 1050 goto fail;
1004 if (status == 0xffffffff) 1051 if (status == 0xffffffff || pci_ext_cfg_is_aliased(dev))
1005 goto fail; 1052 goto fail;
1006 1053
1007 return PCI_CFG_SPACE_EXP_SIZE; 1054 return PCI_CFG_SPACE_EXP_SIZE;
@@ -1215,6 +1262,7 @@ static void pci_release_dev(struct device *dev)
1215 pci_release_of_node(pci_dev); 1262 pci_release_of_node(pci_dev);
1216 pcibios_release_device(pci_dev); 1263 pcibios_release_device(pci_dev);
1217 pci_bus_put(pci_dev->bus); 1264 pci_bus_put(pci_dev->bus);
1265 kfree(pci_dev->driver_override);
1218 kfree(pci_dev); 1266 kfree(pci_dev);
1219} 1267}
1220 1268
@@ -1369,7 +1417,7 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
1369 WARN_ON(ret < 0); 1417 WARN_ON(ret < 0);
1370} 1418}
1371 1419
1372struct pci_dev *__ref pci_scan_single_device(struct pci_bus *bus, int devfn) 1420struct pci_dev *pci_scan_single_device(struct pci_bus *bus, int devfn)
1373{ 1421{
1374 struct pci_dev *dev; 1422 struct pci_dev *dev;
1375 1423
@@ -1617,7 +1665,7 @@ static int pcie_bus_configure_set(struct pci_dev *dev, void *data)
1617 */ 1665 */
1618void pcie_bus_configure_settings(struct pci_bus *bus) 1666void pcie_bus_configure_settings(struct pci_bus *bus)
1619{ 1667{
1620 u8 smpss; 1668 u8 smpss = 0;
1621 1669
1622 if (!bus->self) 1670 if (!bus->self)
1623 return; 1671 return;
@@ -1670,8 +1718,7 @@ unsigned int pci_scan_child_bus(struct pci_bus *bus)
1670 1718
1671 for (pass=0; pass < 2; pass++) 1719 for (pass=0; pass < 2; pass++)
1672 list_for_each_entry(dev, &bus->devices, bus_list) { 1720 list_for_each_entry(dev, &bus->devices, bus_list) {
1673 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 1721 if (pci_is_bridge(dev))
1674 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
1675 max = pci_scan_bridge(bus, dev, max, pass); 1722 max = pci_scan_bridge(bus, dev, max, pass);
1676 } 1723 }
1677 1724
@@ -1958,7 +2005,7 @@ EXPORT_SYMBOL(pci_scan_bus);
1958 * 2005 *
1959 * Returns the max number of subordinate bus discovered. 2006 * Returns the max number of subordinate bus discovered.
1960 */ 2007 */
1961unsigned int __ref pci_rescan_bus_bridge_resize(struct pci_dev *bridge) 2008unsigned int pci_rescan_bus_bridge_resize(struct pci_dev *bridge)
1962{ 2009{
1963 unsigned int max; 2010 unsigned int max;
1964 struct pci_bus *bus = bridge->subordinate; 2011 struct pci_bus *bus = bridge->subordinate;
@@ -1981,7 +2028,7 @@ unsigned int __ref pci_rescan_bus_bridge_resize(struct pci_dev *bridge)
1981 * 2028 *
1982 * Returns the max number of subordinate bus discovered. 2029 * Returns the max number of subordinate bus discovered.
1983 */ 2030 */
1984unsigned int __ref pci_rescan_bus(struct pci_bus *bus) 2031unsigned int pci_rescan_bus(struct pci_bus *bus)
1985{ 2032{
1986 unsigned int max; 2033 unsigned int max;
1987 2034
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index e7292065a1b1..92e68c7747f7 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -2954,6 +2954,7 @@ static void disable_igfx_irq(struct pci_dev *dev)
2954} 2954}
2955DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0102, disable_igfx_irq); 2955DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0102, disable_igfx_irq);
2956DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x010a, disable_igfx_irq); 2956DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x010a, disable_igfx_irq);
2957DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0152, disable_igfx_irq);
2957 2958
2958/* 2959/*
2959 * PCI devices which are on Intel chips can skip the 10ms delay 2960 * PCI devices which are on Intel chips can skip the 10ms delay
@@ -2991,6 +2992,14 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_CHELSIO, 0x0030,
2991 quirk_broken_intx_masking); 2992 quirk_broken_intx_masking);
2992DECLARE_PCI_FIXUP_HEADER(0x1814, 0x0601, /* Ralink RT2800 802.11n PCI */ 2993DECLARE_PCI_FIXUP_HEADER(0x1814, 0x0601, /* Ralink RT2800 802.11n PCI */
2993 quirk_broken_intx_masking); 2994 quirk_broken_intx_masking);
2995/*
2996 * Realtek RTL8169 PCI Gigabit Ethernet Controller (rev 10)
2997 * Subsystem: Realtek RTL8169/8110 Family PCI Gigabit Ethernet NIC
2998 *
2999 * RTL8110SC - Fails under PCI device assignment using DisINTx masking.
3000 */
3001DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_REALTEK, 0x8169,
3002 quirk_broken_intx_masking);
2994 3003
2995static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f, 3004static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f,
2996 struct pci_fixup *end) 3005 struct pci_fixup *end)
@@ -3453,6 +3462,8 @@ static const u16 pci_quirk_intel_pch_acs_ids[] = {
3453 /* Wildcat PCH */ 3462 /* Wildcat PCH */
3454 0x9c90, 0x9c91, 0x9c92, 0x9c93, 0x9c94, 0x9c95, 0x9c96, 0x9c97, 3463 0x9c90, 0x9c91, 0x9c92, 0x9c93, 0x9c94, 0x9c95, 0x9c96, 0x9c97,
3455 0x9c98, 0x9c99, 0x9c9a, 0x9c9b, 3464 0x9c98, 0x9c99, 0x9c9a, 0x9c9b,
3465 /* Patsburg (X79) PCH */
3466 0x1d10, 0x1d12, 0x1d14, 0x1d16, 0x1d18, 0x1d1a, 0x1d1c, 0x1d1e,
3456}; 3467};
3457 3468
3458static bool pci_quirk_intel_pch_acs_match(struct pci_dev *dev) 3469static bool pci_quirk_intel_pch_acs_match(struct pci_dev *dev)
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index 4a1b972efe7f..8e495bda678f 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -7,7 +7,6 @@
7 * Copyright (C) 2003 -- 2004 Greg Kroah-Hartman <greg@kroah.com> 7 * Copyright (C) 2003 -- 2004 Greg Kroah-Hartman <greg@kroah.com>
8 */ 8 */
9 9
10#include <linux/init.h>
11#include <linux/pci.h> 10#include <linux/pci.h>
12#include <linux/slab.h> 11#include <linux/slab.h>
13#include <linux/module.h> 12#include <linux/module.h>
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 138bdd6393be..fd9b545c3cf5 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -713,12 +713,11 @@ static void pci_bridge_check_ranges(struct pci_bus *bus)
713 bus resource of a given type. Note: we intentionally skip 713 bus resource of a given type. Note: we intentionally skip
714 the bus resources which have already been assigned (that is, 714 the bus resources which have already been assigned (that is,
715 have non-NULL parent resource). */ 715 have non-NULL parent resource). */
716static struct resource *find_free_bus_resource(struct pci_bus *bus, unsigned long type) 716static struct resource *find_free_bus_resource(struct pci_bus *bus,
717 unsigned long type_mask, unsigned long type)
717{ 718{
718 int i; 719 int i;
719 struct resource *r; 720 struct resource *r;
720 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
721 IORESOURCE_PREFETCH;
722 721
723 pci_bus_for_each_resource(bus, r, i) { 722 pci_bus_for_each_resource(bus, r, i) {
724 if (r == &ioport_resource || r == &iomem_resource) 723 if (r == &ioport_resource || r == &iomem_resource)
@@ -815,7 +814,8 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
815 resource_size_t add_size, struct list_head *realloc_head) 814 resource_size_t add_size, struct list_head *realloc_head)
816{ 815{
817 struct pci_dev *dev; 816 struct pci_dev *dev;
818 struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO); 817 struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO,
818 IORESOURCE_IO);
819 resource_size_t size = 0, size0 = 0, size1 = 0; 819 resource_size_t size = 0, size0 = 0, size1 = 0;
820 resource_size_t children_add_size = 0; 820 resource_size_t children_add_size = 0;
821 resource_size_t min_align, align; 821 resource_size_t min_align, align;
@@ -907,36 +907,40 @@ static inline resource_size_t calculate_mem_align(resource_size_t *aligns,
907 * @bus : the bus 907 * @bus : the bus
908 * @mask: mask the resource flag, then compare it with type 908 * @mask: mask the resource flag, then compare it with type
909 * @type: the type of free resource from bridge 909 * @type: the type of free resource from bridge
910 * @type2: second match type
911 * @type3: third match type
910 * @min_size : the minimum memory window that must to be allocated 912 * @min_size : the minimum memory window that must to be allocated
911 * @add_size : additional optional memory window 913 * @add_size : additional optional memory window
912 * @realloc_head : track the additional memory window on this list 914 * @realloc_head : track the additional memory window on this list
913 * 915 *
914 * Calculate the size of the bus and minimal alignment which 916 * Calculate the size of the bus and minimal alignment which
915 * guarantees that all child resources fit in this size. 917 * guarantees that all child resources fit in this size.
918 *
919 * Returns -ENOSPC if there's no available bus resource of the desired type.
920 * Otherwise, sets the bus resource start/end to indicate the required
921 * size, adds things to realloc_head (if supplied), and returns 0.
916 */ 922 */
917static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, 923static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
918 unsigned long type, resource_size_t min_size, 924 unsigned long type, unsigned long type2,
919 resource_size_t add_size, 925 unsigned long type3,
920 struct list_head *realloc_head) 926 resource_size_t min_size, resource_size_t add_size,
927 struct list_head *realloc_head)
921{ 928{
922 struct pci_dev *dev; 929 struct pci_dev *dev;
923 resource_size_t min_align, align, size, size0, size1; 930 resource_size_t min_align, align, size, size0, size1;
924 resource_size_t aligns[12]; /* Alignments from 1Mb to 2Gb */ 931 resource_size_t aligns[14]; /* Alignments from 1Mb to 8Gb */
925 int order, max_order; 932 int order, max_order;
926 struct resource *b_res = find_free_bus_resource(bus, type); 933 struct resource *b_res = find_free_bus_resource(bus,
927 unsigned int mem64_mask = 0; 934 mask | IORESOURCE_PREFETCH, type);
928 resource_size_t children_add_size = 0; 935 resource_size_t children_add_size = 0;
929 936
930 if (!b_res) 937 if (!b_res)
931 return 0; 938 return -ENOSPC;
932 939
933 memset(aligns, 0, sizeof(aligns)); 940 memset(aligns, 0, sizeof(aligns));
934 max_order = 0; 941 max_order = 0;
935 size = 0; 942 size = 0;
936 943
937 mem64_mask = b_res->flags & IORESOURCE_MEM_64;
938 b_res->flags &= ~IORESOURCE_MEM_64;
939
940 list_for_each_entry(dev, &bus->devices, bus_list) { 944 list_for_each_entry(dev, &bus->devices, bus_list) {
941 int i; 945 int i;
942 946
@@ -944,7 +948,9 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
944 struct resource *r = &dev->resource[i]; 948 struct resource *r = &dev->resource[i];
945 resource_size_t r_size; 949 resource_size_t r_size;
946 950
947 if (r->parent || (r->flags & mask) != type) 951 if (r->parent || ((r->flags & mask) != type &&
952 (r->flags & mask) != type2 &&
953 (r->flags & mask) != type3))
948 continue; 954 continue;
949 r_size = resource_size(r); 955 r_size = resource_size(r);
950#ifdef CONFIG_PCI_IOV 956#ifdef CONFIG_PCI_IOV
@@ -957,10 +963,17 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
957 continue; 963 continue;
958 } 964 }
959#endif 965#endif
960 /* For bridges size != alignment */ 966 /*
967 * aligns[0] is for 1MB (since bridge memory
968 * windows are always at least 1MB aligned), so
969 * keep "order" from being negative for smaller
970 * resources.
971 */
961 align = pci_resource_alignment(dev, r); 972 align = pci_resource_alignment(dev, r);
962 order = __ffs(align) - 20; 973 order = __ffs(align) - 20;
963 if (order > 11) { 974 if (order < 0)
975 order = 0;
976 if (order >= ARRAY_SIZE(aligns)) {
964 dev_warn(&dev->dev, "disabling BAR %d: %pR " 977 dev_warn(&dev->dev, "disabling BAR %d: %pR "
965 "(bad alignment %#llx)\n", i, r, 978 "(bad alignment %#llx)\n", i, r,
966 (unsigned long long) align); 979 (unsigned long long) align);
@@ -968,15 +981,12 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
968 continue; 981 continue;
969 } 982 }
970 size += r_size; 983 size += r_size;
971 if (order < 0)
972 order = 0;
973 /* Exclude ranges with size > align from 984 /* Exclude ranges with size > align from
974 calculation of the alignment. */ 985 calculation of the alignment. */
975 if (r_size == align) 986 if (r_size == align)
976 aligns[order] += align; 987 aligns[order] += align;
977 if (order > max_order) 988 if (order > max_order)
978 max_order = order; 989 max_order = order;
979 mem64_mask &= r->flags & IORESOURCE_MEM_64;
980 990
981 if (realloc_head) 991 if (realloc_head)
982 children_add_size += get_res_add_size(realloc_head, r); 992 children_add_size += get_res_add_size(realloc_head, r);
@@ -997,18 +1007,18 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
997 "%pR to %pR (unused)\n", b_res, 1007 "%pR to %pR (unused)\n", b_res,
998 &bus->busn_res); 1008 &bus->busn_res);
999 b_res->flags = 0; 1009 b_res->flags = 0;
1000 return 1; 1010 return 0;
1001 } 1011 }
1002 b_res->start = min_align; 1012 b_res->start = min_align;
1003 b_res->end = size0 + min_align - 1; 1013 b_res->end = size0 + min_align - 1;
1004 b_res->flags |= IORESOURCE_STARTALIGN | mem64_mask; 1014 b_res->flags |= IORESOURCE_STARTALIGN;
1005 if (size1 > size0 && realloc_head) { 1015 if (size1 > size0 && realloc_head) {
1006 add_to_list(realloc_head, bus->self, b_res, size1-size0, min_align); 1016 add_to_list(realloc_head, bus->self, b_res, size1-size0, min_align);
1007 dev_printk(KERN_DEBUG, &bus->self->dev, "bridge window " 1017 dev_printk(KERN_DEBUG, &bus->self->dev, "bridge window "
1008 "%pR to %pR add_size %llx\n", b_res, 1018 "%pR to %pR add_size %llx\n", b_res,
1009 &bus->busn_res, (unsigned long long)size1-size0); 1019 &bus->busn_res, (unsigned long long)size1-size0);
1010 } 1020 }
1011 return 1; 1021 return 0;
1012} 1022}
1013 1023
1014unsigned long pci_cardbus_resource_alignment(struct resource *res) 1024unsigned long pci_cardbus_resource_alignment(struct resource *res)
@@ -1113,12 +1123,13 @@ handle_done:
1113 ; 1123 ;
1114} 1124}
1115 1125
1116void __ref __pci_bus_size_bridges(struct pci_bus *bus, 1126void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
1117 struct list_head *realloc_head)
1118{ 1127{
1119 struct pci_dev *dev; 1128 struct pci_dev *dev;
1120 unsigned long mask, prefmask; 1129 unsigned long mask, prefmask, type2 = 0, type3 = 0;
1121 resource_size_t additional_mem_size = 0, additional_io_size = 0; 1130 resource_size_t additional_mem_size = 0, additional_io_size = 0;
1131 struct resource *b_res;
1132 int ret;
1122 1133
1123 list_for_each_entry(dev, &bus->devices, bus_list) { 1134 list_for_each_entry(dev, &bus->devices, bus_list) {
1124 struct pci_bus *b = dev->subordinate; 1135 struct pci_bus *b = dev->subordinate;
@@ -1152,41 +1163,93 @@ void __ref __pci_bus_size_bridges(struct pci_bus *bus,
1152 additional_io_size = pci_hotplug_io_size; 1163 additional_io_size = pci_hotplug_io_size;
1153 additional_mem_size = pci_hotplug_mem_size; 1164 additional_mem_size = pci_hotplug_mem_size;
1154 } 1165 }
1155 /* 1166 /* Fall through */
1156 * Follow thru
1157 */
1158 default: 1167 default:
1159 pbus_size_io(bus, realloc_head ? 0 : additional_io_size, 1168 pbus_size_io(bus, realloc_head ? 0 : additional_io_size,
1160 additional_io_size, realloc_head); 1169 additional_io_size, realloc_head);
1161 /* If the bridge supports prefetchable range, size it 1170
1162 separately. If it doesn't, or its prefetchable window 1171 /*
1163 has already been allocated by arch code, try 1172 * If there's a 64-bit prefetchable MMIO window, compute
1164 non-prefetchable range for both types of PCI memory 1173 * the size required to put all 64-bit prefetchable
1165 resources. */ 1174 * resources in it.
1175 */
1176 b_res = &bus->self->resource[PCI_BRIDGE_RESOURCES];
1166 mask = IORESOURCE_MEM; 1177 mask = IORESOURCE_MEM;
1167 prefmask = IORESOURCE_MEM | IORESOURCE_PREFETCH; 1178 prefmask = IORESOURCE_MEM | IORESOURCE_PREFETCH;
1168 if (pbus_size_mem(bus, prefmask, prefmask, 1179 if (b_res[2].flags & IORESOURCE_MEM_64) {
1180 prefmask |= IORESOURCE_MEM_64;
1181 ret = pbus_size_mem(bus, prefmask, prefmask,
1182 prefmask, prefmask,
1169 realloc_head ? 0 : additional_mem_size, 1183 realloc_head ? 0 : additional_mem_size,
1170 additional_mem_size, realloc_head)) 1184 additional_mem_size, realloc_head);
1171 mask = prefmask; /* Success, size non-prefetch only. */ 1185
1172 else 1186 /*
1173 additional_mem_size += additional_mem_size; 1187 * If successful, all non-prefetchable resources
1174 pbus_size_mem(bus, mask, IORESOURCE_MEM, 1188 * and any 32-bit prefetchable resources will go in
1189 * the non-prefetchable window.
1190 */
1191 if (ret == 0) {
1192 mask = prefmask;
1193 type2 = prefmask & ~IORESOURCE_MEM_64;
1194 type3 = prefmask & ~IORESOURCE_PREFETCH;
1195 }
1196 }
1197
1198 /*
1199 * If there is no 64-bit prefetchable window, compute the
1200 * size required to put all prefetchable resources in the
1201 * 32-bit prefetchable window (if there is one).
1202 */
1203 if (!type2) {
1204 prefmask &= ~IORESOURCE_MEM_64;
1205 ret = pbus_size_mem(bus, prefmask, prefmask,
1206 prefmask, prefmask,
1207 realloc_head ? 0 : additional_mem_size,
1208 additional_mem_size, realloc_head);
1209
1210 /*
1211 * If successful, only non-prefetchable resources
1212 * will go in the non-prefetchable window.
1213 */
1214 if (ret == 0)
1215 mask = prefmask;
1216 else
1217 additional_mem_size += additional_mem_size;
1218
1219 type2 = type3 = IORESOURCE_MEM;
1220 }
1221
1222 /*
1223 * Compute the size required to put everything else in the
1224 * non-prefetchable window. This includes:
1225 *
1226 * - all non-prefetchable resources
1227 * - 32-bit prefetchable resources if there's a 64-bit
1228 * prefetchable window or no prefetchable window at all
1229 * - 64-bit prefetchable resources if there's no
1230 * prefetchable window at all
1231 *
1232 * Note that the strategy in __pci_assign_resource() must
1233 * match that used here. Specifically, we cannot put a
1234 * 32-bit prefetchable resource in a 64-bit prefetchable
1235 * window.
1236 */
1237 pbus_size_mem(bus, mask, IORESOURCE_MEM, type2, type3,
1175 realloc_head ? 0 : additional_mem_size, 1238 realloc_head ? 0 : additional_mem_size,
1176 additional_mem_size, realloc_head); 1239 additional_mem_size, realloc_head);
1177 break; 1240 break;
1178 } 1241 }
1179} 1242}
1180 1243
1181void __ref pci_bus_size_bridges(struct pci_bus *bus) 1244void pci_bus_size_bridges(struct pci_bus *bus)
1182{ 1245{
1183 __pci_bus_size_bridges(bus, NULL); 1246 __pci_bus_size_bridges(bus, NULL);
1184} 1247}
1185EXPORT_SYMBOL(pci_bus_size_bridges); 1248EXPORT_SYMBOL(pci_bus_size_bridges);
1186 1249
1187void __ref __pci_bus_assign_resources(const struct pci_bus *bus, 1250void __pci_bus_assign_resources(const struct pci_bus *bus,
1188 struct list_head *realloc_head, 1251 struct list_head *realloc_head,
1189 struct list_head *fail_head) 1252 struct list_head *fail_head)
1190{ 1253{
1191 struct pci_bus *b; 1254 struct pci_bus *b;
1192 struct pci_dev *dev; 1255 struct pci_dev *dev;
@@ -1218,15 +1281,15 @@ void __ref __pci_bus_assign_resources(const struct pci_bus *bus,
1218 } 1281 }
1219} 1282}
1220 1283
1221void __ref pci_bus_assign_resources(const struct pci_bus *bus) 1284void pci_bus_assign_resources(const struct pci_bus *bus)
1222{ 1285{
1223 __pci_bus_assign_resources(bus, NULL, NULL); 1286 __pci_bus_assign_resources(bus, NULL, NULL);
1224} 1287}
1225EXPORT_SYMBOL(pci_bus_assign_resources); 1288EXPORT_SYMBOL(pci_bus_assign_resources);
1226 1289
1227static void __ref __pci_bridge_assign_resources(const struct pci_dev *bridge, 1290static void __pci_bridge_assign_resources(const struct pci_dev *bridge,
1228 struct list_head *add_head, 1291 struct list_head *add_head,
1229 struct list_head *fail_head) 1292 struct list_head *fail_head)
1230{ 1293{
1231 struct pci_bus *b; 1294 struct pci_bus *b;
1232 1295
@@ -1257,42 +1320,66 @@ static void __ref __pci_bridge_assign_resources(const struct pci_dev *bridge,
1257static void pci_bridge_release_resources(struct pci_bus *bus, 1320static void pci_bridge_release_resources(struct pci_bus *bus,
1258 unsigned long type) 1321 unsigned long type)
1259{ 1322{
1260 int idx; 1323 struct pci_dev *dev = bus->self;
1261 bool changed = false;
1262 struct pci_dev *dev;
1263 struct resource *r; 1324 struct resource *r;
1264 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM | 1325 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
1265 IORESOURCE_PREFETCH; 1326 IORESOURCE_PREFETCH | IORESOURCE_MEM_64;
1327 unsigned old_flags = 0;
1328 struct resource *b_res;
1329 int idx = 1;
1266 1330
1267 dev = bus->self; 1331 b_res = &dev->resource[PCI_BRIDGE_RESOURCES];
1268 for (idx = PCI_BRIDGE_RESOURCES; idx <= PCI_BRIDGE_RESOURCE_END; 1332
1269 idx++) { 1333 /*
1270 r = &dev->resource[idx]; 1334 * 1. if there is io port assign fail, will release bridge
1271 if ((r->flags & type_mask) != type) 1335 * io port.
1272 continue; 1336 * 2. if there is non pref mmio assign fail, release bridge
1273 if (!r->parent) 1337 * nonpref mmio.
1274 continue; 1338 * 3. if there is 64bit pref mmio assign fail, and bridge pref
1275 /* 1339 * is 64bit, release bridge pref mmio.
1276 * if there are children under that, we should release them 1340 * 4. if there is pref mmio assign fail, and bridge pref is
1277 * all 1341 * 32bit mmio, release bridge pref mmio
1278 */ 1342 * 5. if there is pref mmio assign fail, and bridge pref is not
1279 release_child_resources(r); 1343 * assigned, release bridge nonpref mmio.
1280 if (!release_resource(r)) { 1344 */
1281 dev_printk(KERN_DEBUG, &dev->dev, 1345 if (type & IORESOURCE_IO)
1282 "resource %d %pR released\n", idx, r); 1346 idx = 0;
1283 /* keep the old size */ 1347 else if (!(type & IORESOURCE_PREFETCH))
1284 r->end = resource_size(r) - 1; 1348 idx = 1;
1285 r->start = 0; 1349 else if ((type & IORESOURCE_MEM_64) &&
1286 r->flags = 0; 1350 (b_res[2].flags & IORESOURCE_MEM_64))
1287 changed = true; 1351 idx = 2;
1288 } 1352 else if (!(b_res[2].flags & IORESOURCE_MEM_64) &&
1289 } 1353 (b_res[2].flags & IORESOURCE_PREFETCH))
1354 idx = 2;
1355 else
1356 idx = 1;
1357
1358 r = &b_res[idx];
1359
1360 if (!r->parent)
1361 return;
1362
1363 /*
1364 * if there are children under that, we should release them
1365 * all
1366 */
1367 release_child_resources(r);
1368 if (!release_resource(r)) {
1369 type = old_flags = r->flags & type_mask;
1370 dev_printk(KERN_DEBUG, &dev->dev, "resource %d %pR released\n",
1371 PCI_BRIDGE_RESOURCES + idx, r);
1372 /* keep the old size */
1373 r->end = resource_size(r) - 1;
1374 r->start = 0;
1375 r->flags = 0;
1290 1376
1291 if (changed) {
1292 /* avoiding touch the one without PREF */ 1377 /* avoiding touch the one without PREF */
1293 if (type & IORESOURCE_PREFETCH) 1378 if (type & IORESOURCE_PREFETCH)
1294 type = IORESOURCE_PREFETCH; 1379 type = IORESOURCE_PREFETCH;
1295 __pci_setup_bridge(bus, type); 1380 __pci_setup_bridge(bus, type);
1381 /* for next child res under same bridge */
1382 r->flags = old_flags;
1296 } 1383 }
1297} 1384}
1298 1385
@@ -1304,9 +1391,9 @@ enum release_type {
1304 * try to release pci bridge resources that is from leaf bridge, 1391 * try to release pci bridge resources that is from leaf bridge,
1305 * so we can allocate big new one later 1392 * so we can allocate big new one later
1306 */ 1393 */
1307static void __ref pci_bus_release_bridge_resources(struct pci_bus *bus, 1394static void pci_bus_release_bridge_resources(struct pci_bus *bus,
1308 unsigned long type, 1395 unsigned long type,
1309 enum release_type rel_type) 1396 enum release_type rel_type)
1310{ 1397{
1311 struct pci_dev *dev; 1398 struct pci_dev *dev;
1312 bool is_leaf_bridge = true; 1399 bool is_leaf_bridge = true;
@@ -1471,7 +1558,7 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)
1471 LIST_HEAD(fail_head); 1558 LIST_HEAD(fail_head);
1472 struct pci_dev_resource *fail_res; 1559 struct pci_dev_resource *fail_res;
1473 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM | 1560 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
1474 IORESOURCE_PREFETCH; 1561 IORESOURCE_PREFETCH | IORESOURCE_MEM_64;
1475 int pci_try_num = 1; 1562 int pci_try_num = 1;
1476 enum enable_type enable_local; 1563 enum enable_type enable_local;
1477 1564
@@ -1629,9 +1716,7 @@ void pci_assign_unassigned_bus_resources(struct pci_bus *bus)
1629 1716
1630 down_read(&pci_bus_sem); 1717 down_read(&pci_bus_sem);
1631 list_for_each_entry(dev, &bus->devices, bus_list) 1718 list_for_each_entry(dev, &bus->devices, bus_list)
1632 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 1719 if (pci_is_bridge(dev) && pci_has_subordinate(dev))
1633 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
1634 if (dev->subordinate)
1635 __pci_bus_size_bridges(dev->subordinate, 1720 __pci_bus_size_bridges(dev->subordinate,
1636 &add_list); 1721 &add_list);
1637 up_read(&pci_bus_sem); 1722 up_read(&pci_bus_sem);
diff --git a/drivers/pci/setup-irq.c b/drivers/pci/setup-irq.c
index 9bd6864ec5d3..dbc4ffcf42de 100644
--- a/drivers/pci/setup-irq.c
+++ b/drivers/pci/setup-irq.c
@@ -10,7 +10,6 @@
10 */ 10 */
11 11
12 12
13#include <linux/init.h>
14#include <linux/kernel.h> 13#include <linux/kernel.h>
15#include <linux/pci.h> 14#include <linux/pci.h>
16#include <linux/errno.h> 15#include <linux/errno.h>
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 7eed671d5586..33f9e32d94d0 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -16,7 +16,6 @@
16 * Resource sorting 16 * Resource sorting
17 */ 17 */
18 18
19#include <linux/init.h>
20#include <linux/kernel.h> 19#include <linux/kernel.h>
21#include <linux/export.h> 20#include <linux/export.h>
22#include <linux/pci.h> 21#include <linux/pci.h>
@@ -209,21 +208,42 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,
209 208
210 min = (res->flags & IORESOURCE_IO) ? PCIBIOS_MIN_IO : PCIBIOS_MIN_MEM; 209 min = (res->flags & IORESOURCE_IO) ? PCIBIOS_MIN_IO : PCIBIOS_MIN_MEM;
211 210
212 /* First, try exact prefetching match.. */ 211 /*
212 * First, try exact prefetching match. Even if a 64-bit
213 * prefetchable bridge window is below 4GB, we can't put a 32-bit
214 * prefetchable resource in it because pbus_size_mem() assumes a
215 * 64-bit window will contain no 32-bit resources. If we assign
216 * things differently than they were sized, not everything will fit.
217 */
213 ret = pci_bus_alloc_resource(bus, res, size, align, min, 218 ret = pci_bus_alloc_resource(bus, res, size, align, min,
214 IORESOURCE_PREFETCH, 219 IORESOURCE_PREFETCH | IORESOURCE_MEM_64,
215 pcibios_align_resource, dev); 220 pcibios_align_resource, dev);
221 if (ret == 0)
222 return 0;
216 223
217 if (ret < 0 && (res->flags & IORESOURCE_PREFETCH)) { 224 /*
218 /* 225 * If the prefetchable window is only 32 bits wide, we can put
219 * That failed. 226 * 64-bit prefetchable resources in it.
220 * 227 */
221 * But a prefetching area can handle a non-prefetching 228 if ((res->flags & (IORESOURCE_PREFETCH | IORESOURCE_MEM_64)) ==
222 * window (it will just not perform as well). 229 (IORESOURCE_PREFETCH | IORESOURCE_MEM_64)) {
223 */ 230 ret = pci_bus_alloc_resource(bus, res, size, align, min,
224 ret = pci_bus_alloc_resource(bus, res, size, align, min, 0, 231 IORESOURCE_PREFETCH,
225 pcibios_align_resource, dev); 232 pcibios_align_resource, dev);
233 if (ret == 0)
234 return 0;
226 } 235 }
236
237 /*
238 * If we didn't find a better match, we can put any memory resource
239 * in a non-prefetchable window. If this resource is 32 bits and
240 * non-prefetchable, the first call already tried the only possibility
241 * so we don't need to try again.
242 */
243 if (res->flags & (IORESOURCE_PREFETCH | IORESOURCE_MEM_64))
244 ret = pci_bus_alloc_resource(bus, res, size, align, min, 0,
245 pcibios_align_resource, dev);
246
227 return ret; 247 return ret;
228} 248}
229 249
diff --git a/drivers/pcmcia/cardbus.c b/drivers/pcmcia/cardbus.c
index 8bde61952d20..4fe4cc4ae19a 100644
--- a/drivers/pcmcia/cardbus.c
+++ b/drivers/pcmcia/cardbus.c
@@ -78,8 +78,7 @@ int __ref cb_alloc(struct pcmcia_socket *s)
78 max = bus->busn_res.start; 78 max = bus->busn_res.start;
79 for (pass = 0; pass < 2; pass++) 79 for (pass = 0; pass < 2; pass++)
80 list_for_each_entry(dev, &bus->devices, bus_list) 80 list_for_each_entry(dev, &bus->devices, bus_list)
81 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 81 if (pci_is_bridge(dev))
82 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
83 max = pci_scan_bridge(bus, dev, max, pass); 82 max = pci_scan_bridge(bus, dev, max, pass);
84 83
85 /* 84 /*
diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index c5e082fb82fa..91ef69a52263 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -642,8 +642,7 @@ static void asus_rfkill_hotplug(struct asus_wmi *asus)
642 dev = pci_scan_single_device(bus, 0); 642 dev = pci_scan_single_device(bus, 0);
643 if (dev) { 643 if (dev) {
644 pci_bus_assign_resources(bus); 644 pci_bus_assign_resources(bus);
645 if (pci_bus_add_device(dev)) 645 pci_bus_add_device(dev);
646 pr_err("Unable to hotplug wifi\n");
647 } 646 }
648 } else { 647 } else {
649 dev = pci_get_slot(bus, 0); 648 dev = pci_get_slot(bus, 0);
diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
index 399e8c562192..9b0c57cd1d4a 100644
--- a/drivers/platform/x86/eeepc-laptop.c
+++ b/drivers/platform/x86/eeepc-laptop.c
@@ -633,8 +633,7 @@ static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc, acpi_handle handle)
633 dev = pci_scan_single_device(bus, 0); 633 dev = pci_scan_single_device(bus, 0);
634 if (dev) { 634 if (dev) {
635 pci_bus_assign_resources(bus); 635 pci_bus_assign_resources(bus);
636 if (pci_bus_add_device(dev)) 636 pci_bus_add_device(dev);
637 pr_err("Unable to hotplug wifi\n");
638 } 637 }
639 } else { 638 } else {
640 dev = pci_get_slot(bus, 0); 639 dev = pci_get_slot(bus, 0);
diff --git a/include/asm-generic/dma-coherent.h b/include/asm-generic/dma-coherent.h
index 2be8a2dbc868..0297e5875798 100644
--- a/include/asm-generic/dma-coherent.h
+++ b/include/asm-generic/dma-coherent.h
@@ -16,16 +16,13 @@ int dma_mmap_from_coherent(struct device *dev, struct vm_area_struct *vma,
16 * Standard interface 16 * Standard interface
17 */ 17 */
18#define ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY 18#define ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
19extern int 19int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
20dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, 20 dma_addr_t device_addr, size_t size, int flags);
21 dma_addr_t device_addr, size_t size, int flags);
22 21
23extern void 22void dma_release_declared_memory(struct device *dev);
24dma_release_declared_memory(struct device *dev);
25 23
26extern void * 24void *dma_mark_declared_memory_occupied(struct device *dev,
27dma_mark_declared_memory_occupied(struct device *dev, 25 dma_addr_t device_addr, size_t size);
28 dma_addr_t device_addr, size_t size);
29#else 26#else
30#define dma_alloc_from_coherent(dev, size, handle, ret) (0) 27#define dma_alloc_from_coherent(dev, size, handle, ret) (0)
31#define dma_release_from_coherent(dev, order, vaddr) (0) 28#define dma_release_from_coherent(dev, order, vaddr) (0)
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index fd4aee29ad10..0c3eab1e39ac 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -8,6 +8,12 @@
8#include <linux/dma-direction.h> 8#include <linux/dma-direction.h>
9#include <linux/scatterlist.h> 9#include <linux/scatterlist.h>
10 10
11/*
12 * A dma_addr_t can hold any valid DMA or bus address for the platform.
13 * It can be given to a device to use as a DMA source or target. A CPU cannot
14 * reference a dma_addr_t directly because there may be translation between
15 * its physical address space and the bus address space.
16 */
11struct dma_map_ops { 17struct dma_map_ops {
12 void* (*alloc)(struct device *dev, size_t size, 18 void* (*alloc)(struct device *dev, size_t size,
13 dma_addr_t *dma_handle, gfp_t gfp, 19 dma_addr_t *dma_handle, gfp_t gfp,
@@ -186,7 +192,7 @@ static inline int dma_get_cache_alignment(void)
186 192
187#ifndef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY 193#ifndef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
188static inline int 194static inline int
189dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, 195dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
190 dma_addr_t device_addr, size_t size, int flags) 196 dma_addr_t device_addr, size_t size, int flags)
191{ 197{
192 return 0; 198 return 0;
@@ -217,13 +223,14 @@ extern void *dmam_alloc_noncoherent(struct device *dev, size_t size,
217extern void dmam_free_noncoherent(struct device *dev, size_t size, void *vaddr, 223extern void dmam_free_noncoherent(struct device *dev, size_t size, void *vaddr,
218 dma_addr_t dma_handle); 224 dma_addr_t dma_handle);
219#ifdef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY 225#ifdef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
220extern int dmam_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, 226extern int dmam_declare_coherent_memory(struct device *dev,
227 phys_addr_t phys_addr,
221 dma_addr_t device_addr, size_t size, 228 dma_addr_t device_addr, size_t size,
222 int flags); 229 int flags);
223extern void dmam_release_declared_memory(struct device *dev); 230extern void dmam_release_declared_memory(struct device *dev);
224#else /* ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY */ 231#else /* ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY */
225static inline int dmam_declare_coherent_memory(struct device *dev, 232static inline int dmam_declare_coherent_memory(struct device *dev,
226 dma_addr_t bus_addr, dma_addr_t device_addr, 233 phys_addr_t phys_addr, dma_addr_t device_addr,
227 size_t size, gfp_t gfp) 234 size_t size, gfp_t gfp)
228{ 235{
229 return 0; 236 return 0;
diff --git a/include/linux/pci.h b/include/linux/pci.h
index aab57b4abe7f..71d9673c1b2c 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -365,6 +365,7 @@ struct pci_dev {
365#endif 365#endif
366 phys_addr_t rom; /* Physical address of ROM if it's not from the BAR */ 366 phys_addr_t rom; /* Physical address of ROM if it's not from the BAR */
367 size_t romlen; /* Length of ROM if it's not from the BAR */ 367 size_t romlen; /* Length of ROM if it's not from the BAR */
368 char *driver_override; /* Driver name to force a match */
368}; 369};
369 370
370static inline struct pci_dev *pci_physfn(struct pci_dev *dev) 371static inline struct pci_dev *pci_physfn(struct pci_dev *dev)
@@ -477,6 +478,19 @@ static inline bool pci_is_root_bus(struct pci_bus *pbus)
477 return !(pbus->parent); 478 return !(pbus->parent);
478} 479}
479 480
481/**
482 * pci_is_bridge - check if the PCI device is a bridge
483 * @dev: PCI device
484 *
485 * Return true if the PCI device is bridge whether it has subordinate
486 * or not.
487 */
488static inline bool pci_is_bridge(struct pci_dev *dev)
489{
490 return dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
491 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS;
492}
493
480static inline struct pci_dev *pci_upstream_bridge(struct pci_dev *dev) 494static inline struct pci_dev *pci_upstream_bridge(struct pci_dev *dev)
481{ 495{
482 dev = pci_physfn(dev); 496 dev = pci_physfn(dev);
@@ -518,7 +532,7 @@ static inline int pcibios_err_to_errno(int err)
518 case PCIBIOS_FUNC_NOT_SUPPORTED: 532 case PCIBIOS_FUNC_NOT_SUPPORTED:
519 return -ENOENT; 533 return -ENOENT;
520 case PCIBIOS_BAD_VENDOR_ID: 534 case PCIBIOS_BAD_VENDOR_ID:
521 return -EINVAL; 535 return -ENOTTY;
522 case PCIBIOS_DEVICE_NOT_FOUND: 536 case PCIBIOS_DEVICE_NOT_FOUND:
523 return -ENODEV; 537 return -ENODEV;
524 case PCIBIOS_BAD_REGISTER_NUMBER: 538 case PCIBIOS_BAD_REGISTER_NUMBER:
@@ -529,7 +543,7 @@ static inline int pcibios_err_to_errno(int err)
529 return -ENOSPC; 543 return -ENOSPC;
530 } 544 }
531 545
532 return -ENOTTY; 546 return -ERANGE;
533} 547}
534 548
535/* Low-level architecture-dependent routines */ 549/* Low-level architecture-dependent routines */
@@ -603,6 +617,9 @@ struct pci_error_handlers {
603 /* PCI slot has been reset */ 617 /* PCI slot has been reset */
604 pci_ers_result_t (*slot_reset)(struct pci_dev *dev); 618 pci_ers_result_t (*slot_reset)(struct pci_dev *dev);
605 619
620 /* PCI function reset prepare or completed */
621 void (*reset_notify)(struct pci_dev *dev, bool prepare);
622
606 /* Device driver may resume normal operations */ 623 /* Device driver may resume normal operations */
607 void (*resume)(struct pci_dev *dev); 624 void (*resume)(struct pci_dev *dev);
608}; 625};
@@ -680,8 +697,8 @@ struct pci_driver {
680 697
681/** 698/**
682 * PCI_VDEVICE - macro used to describe a specific pci device in short form 699 * PCI_VDEVICE - macro used to describe a specific pci device in short form
683 * @vendor: the vendor name 700 * @vend: the vendor name
684 * @device: the 16 bit PCI Device ID 701 * @dev: the 16 bit PCI Device ID
685 * 702 *
686 * This macro is used to create a struct pci_device_id that matches a 703 * This macro is used to create a struct pci_device_id that matches a
687 * specific PCI device. The subvendor, and subdevice fields will be set 704 * specific PCI device. The subvendor, and subdevice fields will be set
@@ -689,9 +706,9 @@ struct pci_driver {
689 * private data. 706 * private data.
690 */ 707 */
691 708
692#define PCI_VDEVICE(vendor, device) \ 709#define PCI_VDEVICE(vend, dev) \
693 PCI_VENDOR_ID_##vendor, (device), \ 710 .vendor = PCI_VENDOR_ID_##vend, .device = (dev), \
694 PCI_ANY_ID, PCI_ANY_ID, 0, 0 711 .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, 0, 0
695 712
696/* these external functions are only available when PCI support is enabled */ 713/* these external functions are only available when PCI support is enabled */
697#ifdef CONFIG_PCI 714#ifdef CONFIG_PCI
@@ -764,7 +781,7 @@ int pci_scan_slot(struct pci_bus *bus, int devfn);
764struct pci_dev *pci_scan_single_device(struct pci_bus *bus, int devfn); 781struct pci_dev *pci_scan_single_device(struct pci_bus *bus, int devfn);
765void pci_device_add(struct pci_dev *dev, struct pci_bus *bus); 782void pci_device_add(struct pci_dev *dev, struct pci_bus *bus);
766unsigned int pci_scan_child_bus(struct pci_bus *bus); 783unsigned int pci_scan_child_bus(struct pci_bus *bus);
767int __must_check pci_bus_add_device(struct pci_dev *dev); 784void pci_bus_add_device(struct pci_dev *dev);
768void pci_read_bridge_bases(struct pci_bus *child); 785void pci_read_bridge_bases(struct pci_bus *child);
769struct resource *pci_find_parent_resource(const struct pci_dev *dev, 786struct resource *pci_find_parent_resource(const struct pci_dev *dev,
770 struct resource *res); 787 struct resource *res);
@@ -1158,7 +1175,6 @@ struct msix_entry {
1158 1175
1159#ifdef CONFIG_PCI_MSI 1176#ifdef CONFIG_PCI_MSI
1160int pci_msi_vec_count(struct pci_dev *dev); 1177int pci_msi_vec_count(struct pci_dev *dev);
1161int pci_enable_msi_block(struct pci_dev *dev, int nvec);
1162void pci_msi_shutdown(struct pci_dev *dev); 1178void pci_msi_shutdown(struct pci_dev *dev);
1163void pci_disable_msi(struct pci_dev *dev); 1179void pci_disable_msi(struct pci_dev *dev);
1164int pci_msix_vec_count(struct pci_dev *dev); 1180int pci_msix_vec_count(struct pci_dev *dev);
@@ -1188,8 +1204,6 @@ static inline int pci_enable_msix_exact(struct pci_dev *dev,
1188} 1204}
1189#else 1205#else
1190static inline int pci_msi_vec_count(struct pci_dev *dev) { return -ENOSYS; } 1206static inline int pci_msi_vec_count(struct pci_dev *dev) { return -ENOSYS; }
1191static inline int pci_enable_msi_block(struct pci_dev *dev, int nvec)
1192{ return -ENOSYS; }
1193static inline void pci_msi_shutdown(struct pci_dev *dev) { } 1207static inline void pci_msi_shutdown(struct pci_dev *dev) { }
1194static inline void pci_disable_msi(struct pci_dev *dev) { } 1208static inline void pci_disable_msi(struct pci_dev *dev) { }
1195static inline int pci_msix_vec_count(struct pci_dev *dev) { return -ENOSYS; } 1209static inline int pci_msix_vec_count(struct pci_dev *dev) { return -ENOSYS; }
@@ -1244,7 +1258,7 @@ static inline void pcie_set_ecrc_checking(struct pci_dev *dev) { }
1244static inline void pcie_ecrc_get_policy(char *str) { } 1258static inline void pcie_ecrc_get_policy(char *str) { }
1245#endif 1259#endif
1246 1260
1247#define pci_enable_msi(pdev) pci_enable_msi_block(pdev, 1) 1261#define pci_enable_msi(pdev) pci_enable_msi_exact(pdev, 1)
1248 1262
1249#ifdef CONFIG_HT_IRQ 1263#ifdef CONFIG_HT_IRQ
1250/* The functions a driver should call */ 1264/* The functions a driver should call */
@@ -1572,13 +1586,13 @@ extern unsigned long pci_hotplug_io_size;
1572extern unsigned long pci_hotplug_mem_size; 1586extern unsigned long pci_hotplug_mem_size;
1573 1587
1574/* Architecture-specific versions may override these (weak) */ 1588/* Architecture-specific versions may override these (weak) */
1575int pcibios_add_platform_entries(struct pci_dev *dev);
1576void pcibios_disable_device(struct pci_dev *dev); 1589void pcibios_disable_device(struct pci_dev *dev);
1577void pcibios_set_master(struct pci_dev *dev); 1590void pcibios_set_master(struct pci_dev *dev);
1578int pcibios_set_pcie_reset_state(struct pci_dev *dev, 1591int pcibios_set_pcie_reset_state(struct pci_dev *dev,
1579 enum pcie_reset_state state); 1592 enum pcie_reset_state state);
1580int pcibios_add_device(struct pci_dev *dev); 1593int pcibios_add_device(struct pci_dev *dev);
1581void pcibios_release_device(struct pci_dev *dev); 1594void pcibios_release_device(struct pci_dev *dev);
1595void pcibios_penalize_isa_irq(int irq, int active);
1582 1596
1583#ifdef CONFIG_HIBERNATE_CALLBACKS 1597#ifdef CONFIG_HIBERNATE_CALLBACKS
1584extern struct dev_pm_ops pcibios_pm_ops; 1598extern struct dev_pm_ops pcibios_pm_ops;
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index d4de24b4d4c6..7fa31731c854 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -1631,8 +1631,6 @@
1631#define PCI_DEVICE_ID_ATT_VENUS_MODEM 0x480 1631#define PCI_DEVICE_ID_ATT_VENUS_MODEM 0x480
1632 1632
1633#define PCI_VENDOR_ID_SPECIALIX 0x11cb 1633#define PCI_VENDOR_ID_SPECIALIX 0x11cb
1634#define PCI_DEVICE_ID_SPECIALIX_IO8 0x2000
1635#define PCI_DEVICE_ID_SPECIALIX_RIO 0x8000
1636#define PCI_SUBDEVICE_ID_SPECIALIX_SPEED4 0xa004 1634#define PCI_SUBDEVICE_ID_SPECIALIX_SPEED4 0xa004
1637 1635
1638#define PCI_VENDOR_ID_ANALOG_DEVICES 0x11d4 1636#define PCI_VENDOR_ID_ANALOG_DEVICES 0x11d4
@@ -2874,7 +2872,6 @@
2874#define PCI_DEVICE_ID_SCALEMP_VSMP_CTL 0x1010 2872#define PCI_DEVICE_ID_SCALEMP_VSMP_CTL 0x1010
2875 2873
2876#define PCI_VENDOR_ID_COMPUTONE 0x8e0e 2874#define PCI_VENDOR_ID_COMPUTONE 0x8e0e
2877#define PCI_DEVICE_ID_COMPUTONE_IP2EX 0x0291
2878#define PCI_DEVICE_ID_COMPUTONE_PG 0x0302 2875#define PCI_DEVICE_ID_COMPUTONE_PG 0x0302
2879#define PCI_SUBVENDOR_ID_COMPUTONE 0x8e0e 2876#define PCI_SUBVENDOR_ID_COMPUTONE 0x8e0e
2880#define PCI_SUBDEVICE_ID_COMPUTONE_PG4 0x0001 2877#define PCI_SUBDEVICE_ID_COMPUTONE_PG4 0x0001
diff --git a/include/linux/types.h b/include/linux/types.h
index 4d118ba11349..a0bb7048687f 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -142,6 +142,7 @@ typedef unsigned long blkcnt_t;
142#define pgoff_t unsigned long 142#define pgoff_t unsigned long
143#endif 143#endif
144 144
145/* A dma_addr_t can hold any valid DMA or bus address for the platform */
145#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT 146#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
146typedef u64 dma_addr_t; 147typedef u64 dma_addr_t;
147#else 148#else
diff --git a/kernel/resource.c b/kernel/resource.c
index 8957d686e29b..3c2237ac32db 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -1288,13 +1288,10 @@ int iomem_map_sanity_check(resource_size_t addr, unsigned long size)
1288 if (p->flags & IORESOURCE_BUSY) 1288 if (p->flags & IORESOURCE_BUSY)
1289 continue; 1289 continue;
1290 1290
1291 printk(KERN_WARNING "resource map sanity check conflict: " 1291 printk(KERN_WARNING "resource sanity check: requesting [mem %#010llx-%#010llx], which spans more than %s %pR\n",
1292 "0x%llx 0x%llx 0x%llx 0x%llx %s\n",
1293 (unsigned long long)addr, 1292 (unsigned long long)addr,
1294 (unsigned long long)(addr + size - 1), 1293 (unsigned long long)(addr + size - 1),
1295 (unsigned long long)p->start, 1294 p->name, p);
1296 (unsigned long long)p->end,
1297 p->name);
1298 err = -1; 1295 err = -1;
1299 break; 1296 break;
1300 } 1297 }