aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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--arch/microblaze/pci/pci-common.c20
-rw-r--r--arch/powerpc/kernel/pci-common.c20
-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/x86/kernel/aperture_64.c59
-rw-r--r--arch/x86/pci/broadcom_bus.c4
-rw-r--r--arch/x86/pci/fixup.c14
-rw-r--r--arch/x86/pci/i386.c27
-rw-r--r--drivers/base/dma-coherent.c10
-rw-r--r--drivers/base/dma-mapping.c6
-rw-r--r--drivers/iommu/exynos-iommu.c14
-rw-r--r--drivers/pci/msi.c79
-rw-r--r--drivers/pci/pci-sysfs.c28
-rw-r--r--drivers/pci/probe.c48
-rw-r--r--drivers/pci/quirks.c8
-rw-r--r--drivers/pci/setup-bus.c222
-rw-r--r--drivers/pci/setup-res.c41
-rw-r--r--include/asm-generic/dma-coherent.h13
-rw-r--r--include/linux/dma-mapping.h13
-rw-r--r--include/linux/pci.h6
-rw-r--r--include/linux/types.h1
-rw-r--r--kernel/resource.c7
27 files changed, 613 insertions, 465 deletions
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/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/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/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/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/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..ef334a003f3c 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)
@@ -526,6 +527,19 @@ static void sb600_disable_hpet_bar(struct pci_dev *dev)
526} 527}
527DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATI, 0x4385, sb600_disable_hpet_bar); 528DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATI, 0x4385, sb600_disable_hpet_bar);
528 529
530#ifdef CONFIG_HPET_TIMER
531static void sb600_hpet_quirk(struct pci_dev *dev)
532{
533 struct resource *r = &dev->resource[1];
534
535 if (r->flags & IORESOURCE_MEM && r->start == hpet_address) {
536 r->flags |= IORESOURCE_PCI_FIXED;
537 dev_info(&dev->dev, "reg 0x14 contains HPET; making it immovable\n");
538 }
539}
540DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, 0x4385, sb600_hpet_quirk);
541#endif
542
529/* 543/*
530 * Twinhead H12Y needs us to block out a region otherwise we map devices 544 * Twinhead H12Y needs us to block out a region otherwise we map devices
531 * there and any access kills the box. 545 * 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/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/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/pci/msi.c b/drivers/pci/msi.c
index 275585c2dee2..27a7e67ddfe4 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -878,50 +878,6 @@ int pci_msi_vec_count(struct pci_dev *dev)
878} 878}
879EXPORT_SYMBOL(pci_msi_vec_count); 879EXPORT_SYMBOL(pci_msi_vec_count);
880 880
881/**
882 * pci_enable_msi_block - configure device's MSI capability structure
883 * @dev: device to configure
884 * @nvec: number of interrupts to configure
885 *
886 * Allocate IRQs for a device with the MSI capability.
887 * This function returns a negative errno if an error occurs. If it
888 * is unable to allocate the number of interrupts requested, it returns
889 * the number of interrupts it might be able to allocate. If it successfully
890 * allocates at least the number of interrupts requested, it returns 0 and
891 * updates the @dev's irq member to the lowest new interrupt number; the
892 * other interrupt numbers allocated to this device are consecutive.
893 */
894int pci_enable_msi_block(struct pci_dev *dev, int nvec)
895{
896 int status, maxvec;
897
898 if (dev->current_state != PCI_D0)
899 return -EINVAL;
900
901 maxvec = pci_msi_vec_count(dev);
902 if (maxvec < 0)
903 return maxvec;
904 if (nvec > maxvec)
905 return maxvec;
906
907 status = pci_msi_check_device(dev, nvec, PCI_CAP_ID_MSI);
908 if (status)
909 return status;
910
911 WARN_ON(!!dev->msi_enabled);
912
913 /* Check whether driver already requested MSI-X irqs */
914 if (dev->msix_enabled) {
915 dev_info(&dev->dev, "can't enable MSI "
916 "(MSI-X already enabled)\n");
917 return -EINVAL;
918 }
919
920 status = msi_capability_init(dev, nvec);
921 return status;
922}
923EXPORT_SYMBOL(pci_enable_msi_block);
924
925void pci_msi_shutdown(struct pci_dev *dev) 881void pci_msi_shutdown(struct pci_dev *dev)
926{ 882{
927 struct msi_desc *desc; 883 struct msi_desc *desc;
@@ -1127,14 +1083,45 @@ void pci_msi_init_pci_dev(struct pci_dev *dev)
1127 **/ 1083 **/
1128int 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)
1129{ 1085{
1130 int nvec = maxvec; 1086 int nvec;
1131 int rc; 1087 int rc;
1132 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
1133 if (maxvec < minvec) 1101 if (maxvec < minvec)
1134 return -ERANGE; 1102 return -ERANGE;
1135 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
1136 do { 1123 do {
1137 rc = pci_enable_msi_block(dev, nvec); 1124 rc = msi_capability_init(dev, nvec);
1138 if (rc < 0) { 1125 if (rc < 0) {
1139 return rc; 1126 return rc;
1140 } else if (rc > 0) { 1127 } else if (rc > 0) {
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 4e0acefb7565..b7333fa5f80d 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,
@@ -521,6 +536,9 @@ static struct attribute *pci_dev_attrs[] = {
521#if defined(CONFIG_PM_RUNTIME) && defined(CONFIG_ACPI) 536#if defined(CONFIG_PM_RUNTIME) && defined(CONFIG_ACPI)
522 &dev_attr_d3cold_allowed.attr, 537 &dev_attr_d3cold_allowed.attr,
523#endif 538#endif
539#ifdef CONFIG_OF
540 &dev_attr_devspec.attr,
541#endif
524 NULL, 542 NULL,
525}; 543};
526 544
@@ -1255,11 +1273,6 @@ static struct bin_attribute pcie_config_attr = {
1255 .write = pci_write_config, 1273 .write = pci_write_config,
1256}; 1274};
1257 1275
1258int __weak pcibios_add_platform_entries(struct pci_dev *dev)
1259{
1260 return 0;
1261}
1262
1263static ssize_t reset_store(struct device *dev, 1276static ssize_t reset_store(struct device *dev,
1264 struct device_attribute *attr, const char *buf, 1277 struct device_attribute *attr, const char *buf,
1265 size_t count) 1278 size_t count)
@@ -1375,11 +1388,6 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
1375 pdev->rom_attr = attr; 1388 pdev->rom_attr = attr;
1376 } 1389 }
1377 1390
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 */ 1391 /* add sysfs entries for various capabilities */
1384 retval = pci_create_capabilities_sysfs(pdev); 1392 retval = pci_create_capabilities_sysfs(pdev);
1385 if (retval) 1393 if (retval)
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 490031fd2108..52d05e054cd8 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,
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 9825ad01d812..92e68c7747f7 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -2992,6 +2992,14 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_CHELSIO, 0x0030,
2992 quirk_broken_intx_masking); 2992 quirk_broken_intx_masking);
2993DECLARE_PCI_FIXUP_HEADER(0x1814, 0x0601, /* Ralink RT2800 802.11n PCI */ 2993DECLARE_PCI_FIXUP_HEADER(0x1814, 0x0601, /* Ralink RT2800 802.11n PCI */
2994 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);
2995 3003
2996static 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,
2997 struct pci_fixup *end) 3005 struct pci_fixup *end)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index d219d44709b2..d9fdcea4412a 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)
@@ -1116,8 +1126,10 @@ handle_done:
1116void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) 1126void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
1117{ 1127{
1118 struct pci_dev *dev; 1128 struct pci_dev *dev;
1119 unsigned long mask, prefmask; 1129 unsigned long mask, prefmask, type2 = 0, type3 = 0;
1120 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;
1121 1133
1122 list_for_each_entry(dev, &bus->devices, bus_list) { 1134 list_for_each_entry(dev, &bus->devices, bus_list) {
1123 struct pci_bus *b = dev->subordinate; 1135 struct pci_bus *b = dev->subordinate;
@@ -1151,26 +1163,78 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
1151 additional_io_size = pci_hotplug_io_size; 1163 additional_io_size = pci_hotplug_io_size;
1152 additional_mem_size = pci_hotplug_mem_size; 1164 additional_mem_size = pci_hotplug_mem_size;
1153 } 1165 }
1154 /* 1166 /* Fall through */
1155 * Follow thru
1156 */
1157 default: 1167 default:
1158 pbus_size_io(bus, realloc_head ? 0 : additional_io_size, 1168 pbus_size_io(bus, realloc_head ? 0 : additional_io_size,
1159 additional_io_size, realloc_head); 1169 additional_io_size, realloc_head);
1160 /* If the bridge supports prefetchable range, size it 1170
1161 separately. If it doesn't, or its prefetchable window 1171 /*
1162 has already been allocated by arch code, try 1172 * If there's a 64-bit prefetchable MMIO window, compute
1163 non-prefetchable range for both types of PCI memory 1173 * the size required to put all 64-bit prefetchable
1164 resources. */ 1174 * resources in it.
1175 */
1176 b_res = &bus->self->resource[PCI_BRIDGE_RESOURCES];
1165 mask = IORESOURCE_MEM; 1177 mask = IORESOURCE_MEM;
1166 prefmask = IORESOURCE_MEM | IORESOURCE_PREFETCH; 1178 prefmask = IORESOURCE_MEM | IORESOURCE_PREFETCH;
1167 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,
1168 realloc_head ? 0 : additional_mem_size, 1183 realloc_head ? 0 : additional_mem_size,
1169 additional_mem_size, realloc_head)) 1184 additional_mem_size, realloc_head);
1170 mask = prefmask; /* Success, size non-prefetch only. */ 1185
1171 else 1186 /*
1172 additional_mem_size += additional_mem_size; 1187 * If successful, all non-prefetchable resources
1173 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,
1174 realloc_head ? 0 : additional_mem_size, 1238 realloc_head ? 0 : additional_mem_size,
1175 additional_mem_size, realloc_head); 1239 additional_mem_size, realloc_head);
1176 break; 1240 break;
@@ -1256,42 +1320,66 @@ static void __pci_bridge_assign_resources(const struct pci_dev *bridge,
1256static void pci_bridge_release_resources(struct pci_bus *bus, 1320static void pci_bridge_release_resources(struct pci_bus *bus,
1257 unsigned long type) 1321 unsigned long type)
1258{ 1322{
1259 int idx; 1323 struct pci_dev *dev = bus->self;
1260 bool changed = false;
1261 struct pci_dev *dev;
1262 struct resource *r; 1324 struct resource *r;
1263 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM | 1325 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
1264 IORESOURCE_PREFETCH; 1326 IORESOURCE_PREFETCH | IORESOURCE_MEM_64;
1327 unsigned old_flags = 0;
1328 struct resource *b_res;
1329 int idx = 1;
1265 1330
1266 dev = bus->self; 1331 b_res = &dev->resource[PCI_BRIDGE_RESOURCES];
1267 for (idx = PCI_BRIDGE_RESOURCES; idx <= PCI_BRIDGE_RESOURCE_END; 1332
1268 idx++) { 1333 /*
1269 r = &dev->resource[idx]; 1334 * 1. if there is io port assign fail, will release bridge
1270 if ((r->flags & type_mask) != type) 1335 * io port.
1271 continue; 1336 * 2. if there is non pref mmio assign fail, release bridge
1272 if (!r->parent) 1337 * nonpref mmio.
1273 continue; 1338 * 3. if there is 64bit pref mmio assign fail, and bridge pref
1274 /* 1339 * is 64bit, release bridge pref mmio.
1275 * if there are children under that, we should release them 1340 * 4. if there is pref mmio assign fail, and bridge pref is
1276 * all 1341 * 32bit mmio, release bridge pref mmio
1277 */ 1342 * 5. if there is pref mmio assign fail, and bridge pref is not
1278 release_child_resources(r); 1343 * assigned, release bridge nonpref mmio.
1279 if (!release_resource(r)) { 1344 */
1280 dev_printk(KERN_DEBUG, &dev->dev, 1345 if (type & IORESOURCE_IO)
1281 "resource %d %pR released\n", idx, r); 1346 idx = 0;
1282 /* keep the old size */ 1347 else if (!(type & IORESOURCE_PREFETCH))
1283 r->end = resource_size(r) - 1; 1348 idx = 1;
1284 r->start = 0; 1349 else if ((type & IORESOURCE_MEM_64) &&
1285 r->flags = 0; 1350 (b_res[2].flags & IORESOURCE_MEM_64))
1286 changed = true; 1351 idx = 2;
1287 } 1352 else if (!(b_res[2].flags & IORESOURCE_MEM_64) &&
1288 } 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;
1289 1376
1290 if (changed) {
1291 /* avoiding touch the one without PREF */ 1377 /* avoiding touch the one without PREF */
1292 if (type & IORESOURCE_PREFETCH) 1378 if (type & IORESOURCE_PREFETCH)
1293 type = IORESOURCE_PREFETCH; 1379 type = IORESOURCE_PREFETCH;
1294 __pci_setup_bridge(bus, type); 1380 __pci_setup_bridge(bus, type);
1381 /* for next child res under same bridge */
1382 r->flags = old_flags;
1295 } 1383 }
1296} 1384}
1297 1385
@@ -1470,7 +1558,7 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)
1470 LIST_HEAD(fail_head); 1558 LIST_HEAD(fail_head);
1471 struct pci_dev_resource *fail_res; 1559 struct pci_dev_resource *fail_res;
1472 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM | 1560 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
1473 IORESOURCE_PREFETCH; 1561 IORESOURCE_PREFETCH | IORESOURCE_MEM_64;
1474 int pci_try_num = 1; 1562 int pci_try_num = 1;
1475 enum enable_type enable_local; 1563 enum enable_type enable_local;
1476 1564
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 1e37c590a183..33f9e32d94d0 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -208,21 +208,42 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,
208 208
209 min = (res->flags & IORESOURCE_IO) ? PCIBIOS_MIN_IO : PCIBIOS_MIN_MEM; 209 min = (res->flags & IORESOURCE_IO) ? PCIBIOS_MIN_IO : PCIBIOS_MIN_MEM;
210 210
211 /* 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 */
212 ret = pci_bus_alloc_resource(bus, res, size, align, min, 218 ret = pci_bus_alloc_resource(bus, res, size, align, min,
213 IORESOURCE_PREFETCH, 219 IORESOURCE_PREFETCH | IORESOURCE_MEM_64,
214 pcibios_align_resource, dev); 220 pcibios_align_resource, dev);
221 if (ret == 0)
222 return 0;
215 223
216 if (ret < 0 && (res->flags & IORESOURCE_PREFETCH)) { 224 /*
217 /* 225 * If the prefetchable window is only 32 bits wide, we can put
218 * That failed. 226 * 64-bit prefetchable resources in it.
219 * 227 */
220 * But a prefetching area can handle a non-prefetching 228 if ((res->flags & (IORESOURCE_PREFETCH | IORESOURCE_MEM_64)) ==
221 * window (it will just not perform as well). 229 (IORESOURCE_PREFETCH | IORESOURCE_MEM_64)) {
222 */ 230 ret = pci_bus_alloc_resource(bus, res, size, align, min,
223 ret = pci_bus_alloc_resource(bus, res, size, align, min, 0, 231 IORESOURCE_PREFETCH,
224 pcibios_align_resource, dev); 232 pcibios_align_resource, dev);
233 if (ret == 0)
234 return 0;
225 } 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
226 return ret; 247 return ret;
227} 248}
228 249
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 a95aac7ad37f..5dbd15422b55 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1158,7 +1158,6 @@ struct msix_entry {
1158 1158
1159#ifdef CONFIG_PCI_MSI 1159#ifdef CONFIG_PCI_MSI
1160int pci_msi_vec_count(struct pci_dev *dev); 1160int 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); 1161void pci_msi_shutdown(struct pci_dev *dev);
1163void pci_disable_msi(struct pci_dev *dev); 1162void pci_disable_msi(struct pci_dev *dev);
1164int pci_msix_vec_count(struct pci_dev *dev); 1163int pci_msix_vec_count(struct pci_dev *dev);
@@ -1188,8 +1187,6 @@ static inline int pci_enable_msix_exact(struct pci_dev *dev,
1188} 1187}
1189#else 1188#else
1190static inline int pci_msi_vec_count(struct pci_dev *dev) { return -ENOSYS; } 1189static 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) { } 1190static inline void pci_msi_shutdown(struct pci_dev *dev) { }
1194static inline void pci_disable_msi(struct pci_dev *dev) { } 1191static inline void pci_disable_msi(struct pci_dev *dev) { }
1195static inline int pci_msix_vec_count(struct pci_dev *dev) { return -ENOSYS; } 1192static inline int pci_msix_vec_count(struct pci_dev *dev) { return -ENOSYS; }
@@ -1244,7 +1241,7 @@ static inline void pcie_set_ecrc_checking(struct pci_dev *dev) { }
1244static inline void pcie_ecrc_get_policy(char *str) { } 1241static inline void pcie_ecrc_get_policy(char *str) { }
1245#endif 1242#endif
1246 1243
1247#define pci_enable_msi(pdev) pci_enable_msi_block(pdev, 1) 1244#define pci_enable_msi(pdev) pci_enable_msi_exact(pdev, 1)
1248 1245
1249#ifdef CONFIG_HT_IRQ 1246#ifdef CONFIG_HT_IRQ
1250/* The functions a driver should call */ 1247/* The functions a driver should call */
@@ -1572,7 +1569,6 @@ extern unsigned long pci_hotplug_io_size;
1572extern unsigned long pci_hotplug_mem_size; 1569extern unsigned long pci_hotplug_mem_size;
1573 1570
1574/* Architecture-specific versions may override these (weak) */ 1571/* Architecture-specific versions may override these (weak) */
1575int pcibios_add_platform_entries(struct pci_dev *dev);
1576void pcibios_disable_device(struct pci_dev *dev); 1572void pcibios_disable_device(struct pci_dev *dev);
1577void pcibios_set_master(struct pci_dev *dev); 1573void pcibios_set_master(struct pci_dev *dev);
1578int pcibios_set_pcie_reset_state(struct pci_dev *dev, 1574int pcibios_set_pcie_reset_state(struct pci_dev *dev,
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 }