Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branches 'dma-api', 'pci/virtualization', 'pci/msi', 'pci/misc' and 'pci/resource' into next

* dma-api:
iommu/exynos: Remove unnecessary "&" from function pointers
DMA-API: Update dma_pool_create ()and dma_pool_alloc() descriptions
DMA-API: Fix duplicated word in DMA-API-HOWTO.txt
DMA-API: Capitalize "CPU" consistently
sh/PCI: Pass GAPSPCI_DMA_BASE CPU & bus address to dma_declare_coherent_memory()
DMA-API: Change dma_declare_coherent_memory() CPU address to phys_addr_t
DMA-API: Clarify physical/bus address distinction

* pci/virtualization:
PCI: Mark RTL8110SC INTx masking as broken

* pci/msi:
PCI/MSI: Remove pci_enable_msi_block()

* pci/misc:
PCI: Remove pcibios_add_platform_entries()
s390/pci: use pdev->dev.groups for attribute creation
PCI: Move Open Firmware devspec attribute to PCI common code

* pci/resource:
PCI: Add resource allocation comments
PCI: Simplify __pci_assign_resource() coding style
PCI: Change pbus_size_mem() return values to be more conventional
PCI: Restrict 64-bit prefetchable bridge windows to 64-bit resources
PCI: Support BAR sizes up to 8GB
resources: Clarify sanity check message
PCI: Don't add disabled subtractive decode bus resources
PCI: Don't print anything while decoding is disabled
PCI: Don't set BAR to zero if dma_addr_t is too small
PCI: Don't convert BAR address to resource if dma_addr_t is too small
PCI: Reject BAR above 4GB if dma_addr_t is too small
PCI: Fail safely if we can't handle BARs larger than 4GB
x86/gart: Tidy messages and add bridge device info
x86/gart: Replace printk() with pr_info()
x86/PCI: Move pcibios_assign_resources() annotation to definition
x86/PCI: Mark ATI SBx00 HPET BAR as IORESOURCE_PCI_FIXED
x86/PCI: Don't try to move IORESOURCE_PCI_FIXED resources
x86/PCI: Fix Broadcom CNB20LE unintended sign extension

+612 -464
+132 -78
Documentation/DMA-API-HOWTO.txt
··· 9 9 with example pseudo-code. For a concise description of the API, see 10 10 DMA-API.txt. 11 11 12 - Most of the 64bit platforms have special hardware that translates bus 13 - addresses (DMA addresses) into physical addresses. This is similar to 14 - how page tables and/or a TLB translates virtual addresses to physical 15 - addresses on a CPU. This is needed so that e.g. PCI devices can 16 - access with a Single Address Cycle (32bit DMA address) any page in the 17 - 64bit physical address space. Previously in Linux those 64bit 18 - platforms had to set artificial limits on the maximum RAM size in the 19 - system, so that the virt_to_bus() static scheme works (the DMA address 20 - translation tables were simply filled on bootup to map each bus 21 - address to the physical page __pa(bus_to_virt())). 12 + CPU and DMA addresses 13 + 14 + There are several kinds of addresses involved in the DMA API, and it's 15 + important to understand the differences. 16 + 17 + The kernel normally uses virtual addresses. Any address returned by 18 + kmalloc(), vmalloc(), and similar interfaces is a virtual address and can 19 + be stored in a "void *". 20 + 21 + The virtual memory system (TLB, page tables, etc.) translates virtual 22 + addresses to CPU physical addresses, which are stored as "phys_addr_t" or 23 + "resource_size_t". The kernel manages device resources like registers as 24 + physical addresses. These are the addresses in /proc/iomem. The physical 25 + address is not directly useful to a driver; it must use ioremap() to map 26 + the space and produce a virtual address. 27 + 28 + I/O devices use a third kind of address: a "bus address" or "DMA address". 29 + If a device has registers at an MMIO address, or if it performs DMA to read 30 + or write system memory, the addresses used by the device are bus addresses. 31 + In some systems, bus addresses are identical to CPU physical addresses, but 32 + in general they are not. IOMMUs and host bridges can produce arbitrary 33 + mappings between physical and bus addresses. 34 + 35 + Here'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 + 59 + During the enumeration process, the kernel learns about I/O devices and 60 + their MMIO space and the host bridges that connect them to the system. For 61 + example, if a PCI device has a BAR, the kernel reads the bus address (A) 62 + from the BAR and converts it to a CPU physical address (B). The address B 63 + is stored in a struct resource and usually exposed via /proc/iomem. When a 64 + driver claims a device, it typically uses ioremap() to map physical address 65 + B at a virtual address (C). It can then use, e.g., ioread32(C), to access 66 + the device registers at bus address A. 67 + 68 + If the device supports DMA, the driver sets up a buffer using kmalloc() or 69 + a similar interface, which returns a virtual address (X). The virtual 70 + memory system maps X to a physical address (Y) in system RAM. The driver 71 + can use virtual address X to access the buffer, but the device itself 72 + cannot because DMA doesn't go through the CPU virtual memory system. 73 + 74 + In some simple systems, the device can do DMA directly to physical address 75 + Y. But in many others, there is IOMMU hardware that translates bus 76 + addresses to physical addresses, e.g., it translates Z to Y. This is part 77 + of the reason for the DMA API: the driver can give a virtual address X to 78 + an interface like dma_map_single(), which sets up any required IOMMU 79 + mapping and returns the bus address Z. The driver then tells the device to 80 + do DMA to Z, and the IOMMU maps it to the buffer at address Y in system 81 + RAM. 22 82 23 83 So that Linux can use the dynamic DMA mapping, it needs some help from the 24 84 drivers, namely it has to take into account that DMA addresses should be ··· 89 29 hardware exists. 90 30 91 31 Note that the DMA API works with any bus independent of the underlying 92 - microprocessor architecture. You should use the DMA API rather than 93 - the bus specific DMA API (e.g. pci_dma_*). 32 + microprocessor architecture. You should use the DMA API rather than the 33 + bus-specific DMA API, i.e., use the dma_map_*() interfaces rather than the 34 + pci_map_*() interfaces. 94 35 95 36 First of all, you should make sure 96 37 97 38 #include <linux/dma-mapping.h> 98 39 99 - is in your driver. This file will obtain for you the definition of the 100 - dma_addr_t (which can hold any valid DMA address for the platform) 101 - type which should be used everywhere you hold a DMA (bus) address 102 - returned from the DMA mapping functions. 40 + is in your driver, which provides the definition of dma_addr_t. This type 41 + can hold any valid DMA or bus address for the platform and should be used 42 + everywhere you hold a DMA address returned from the DMA mapping functions. 103 43 104 44 What memory is DMA'able? 105 45 ··· 183 123 is a bit mask describing which bits of an address your device 184 124 supports. It returns zero if your card can perform DMA properly on 185 125 the machine given the address mask you provided. In general, the 186 - device struct of your device is embedded in the bus specific device 187 - struct of your device. For example, a pointer to the device struct of 188 - your PCI device is pdev->dev (pdev is a pointer to the PCI device 126 + device struct of your device is embedded in the bus-specific device 127 + struct of your device. For example, &pdev->dev is a pointer to the 128 + device struct of a PCI device (pdev is a pointer to the PCI device 189 129 struct of your device). 190 130 191 131 If it returns non-zero, your device cannot perform DMA properly on ··· 207 147 The standard 32-bit addressing device would do something like this: 208 148 209 149 if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32))) { 210 - printk(KERN_WARNING 211 - "mydev: No suitable DMA available.\n"); 150 + dev_warn(dev, "mydev: No suitable DMA available\n"); 212 151 goto ignore_this_device; 213 152 } 214 153 ··· 229 170 } else if (!dma_set_mask(dev, DMA_BIT_MASK(32))) { 230 171 using_dac = 0; 231 172 } else { 232 - printk(KERN_WARNING 233 - "mydev: No suitable DMA available.\n"); 173 + dev_warn(dev, "mydev: No suitable DMA available\n"); 234 174 goto ignore_this_device; 235 175 } 236 176 ··· 245 187 using_dac = 0; 246 188 consistent_using_dac = 0; 247 189 } else { 248 - printk(KERN_WARNING 249 - "mydev: No suitable DMA available.\n"); 190 + dev_warn(dev, "mydev: No suitable DMA available\n"); 250 191 goto ignore_this_device; 251 192 } 252 193 253 - The coherent coherent mask will always be able to set the same or a 254 - smaller mask as the streaming mask. However for the rare case that a 255 - device driver only uses consistent allocations, one would have to 256 - check the return value from dma_set_coherent_mask(). 194 + The coherent mask will always be able to set the same or a smaller mask as 195 + the streaming mask. However for the rare case that a device driver only 196 + uses consistent allocations, one would have to check the return value from 197 + dma_set_coherent_mask(). 257 198 258 199 Finally, if your device can only drive the low 24-bits of 259 200 address you might do something like: 260 201 261 202 if (dma_set_mask(dev, DMA_BIT_MASK(24))) { 262 - printk(KERN_WARNING 263 - "mydev: 24-bit DMA addressing not available.\n"); 203 + dev_warn(dev, "mydev: 24-bit DMA addressing not available\n"); 264 204 goto ignore_this_device; 265 205 } 266 206 ··· 288 232 card->playback_enabled = 1; 289 233 } else { 290 234 card->playback_enabled = 0; 291 - printk(KERN_WARNING "%s: Playback disabled due to DMA limitations.\n", 235 + dev_warn(dev, "%s: Playback disabled due to DMA limitations\n", 292 236 card->name); 293 237 } 294 238 if (!dma_set_mask(dev, RECORD_ADDRESS_BITS)) { 295 239 card->record_enabled = 1; 296 240 } else { 297 241 card->record_enabled = 0; 298 - printk(KERN_WARNING "%s: Record disabled due to DMA limitations.\n", 242 + dev_warn(dev, "%s: Record disabled due to DMA limitations\n", 299 243 card->name); 300 244 } 301 245 ··· 387 331 Size is the length of the region you want to allocate, in bytes. 388 332 389 333 This routine will allocate RAM for that region, so it acts similarly to 390 - __get_free_pages (but takes size instead of a page order). If your 334 + __get_free_pages() (but takes size instead of a page order). If your 391 335 driver needs regions sized smaller than a page, you may prefer using 392 336 the dma_pool interface, described below. 393 337 ··· 399 343 dma_set_coherent_mask(). This is true of the dma_pool interface as 400 344 well. 401 345 402 - dma_alloc_coherent returns two values: the virtual address which you 346 + dma_alloc_coherent() returns two values: the virtual address which you 403 347 can use to access it from the CPU and dma_handle which you pass to the 404 348 card. 405 349 406 - The cpu return address and the DMA bus master address are both 350 + The CPU virtual address and the DMA bus address are both 407 351 guaranteed to be aligned to the smallest PAGE_SIZE order which 408 352 is greater than or equal to the requested size. This invariant 409 353 exists (for example) to guarantee that if you allocate a chunk ··· 415 359 dma_free_coherent(dev, size, cpu_addr, dma_handle); 416 360 417 361 where dev, size are the same as in the above call and cpu_addr and 418 - dma_handle are the values dma_alloc_coherent returned to you. 362 + dma_handle are the values dma_alloc_coherent() returned to you. 419 363 This function may not be called in interrupt context. 420 364 421 365 If your driver needs lots of smaller memory regions, you can write 422 - custom code to subdivide pages returned by dma_alloc_coherent, 366 + custom code to subdivide pages returned by dma_alloc_coherent(), 423 367 or you can use the dma_pool API to do that. A dma_pool is like 424 - a kmem_cache, but it uses dma_alloc_coherent not __get_free_pages. 368 + a kmem_cache, but it uses dma_alloc_coherent(), not __get_free_pages(). 425 369 Also, it understands common hardware constraints for alignment, 426 370 like queue heads needing to be aligned on N byte boundaries. 427 371 ··· 429 373 430 374 struct dma_pool *pool; 431 375 432 - pool = dma_pool_create(name, dev, size, align, alloc); 376 + pool = dma_pool_create(name, dev, size, align, boundary); 433 377 434 378 The "name" is for diagnostics (like a kmem_cache name); dev and size 435 379 are as above. The device's hardware alignment requirement for this 436 380 type of data is "align" (which is expressed in bytes, and must be a 437 381 power of two). If your device has no boundary crossing restrictions, 438 - pass 0 for alloc; passing 4096 says memory allocated from this pool 382 + pass 0 for boundary; passing 4096 says memory allocated from this pool 439 383 must not cross 4KByte boundaries (but at that time it may be better to 440 - go for dma_alloc_coherent directly instead). 384 + use dma_alloc_coherent() directly instead). 441 385 442 - Allocate memory from a dma pool like this: 386 + Allocate memory from a DMA pool like this: 443 387 444 388 cpu_addr = dma_pool_alloc(pool, flags, &dma_handle); 445 389 446 - flags are SLAB_KERNEL if blocking is permitted (not in_interrupt nor 447 - holding SMP locks), SLAB_ATOMIC otherwise. Like dma_alloc_coherent, 390 + flags are GFP_KERNEL if blocking is permitted (not in_interrupt nor 391 + holding SMP locks), GFP_ATOMIC otherwise. Like dma_alloc_coherent(), 448 392 this returns two values, cpu_addr and dma_handle. 449 393 450 394 Free memory that was allocated from a dma_pool like this: 451 395 452 396 dma_pool_free(pool, cpu_addr, dma_handle); 453 397 454 - where pool is what you passed to dma_pool_alloc, and cpu_addr and 455 - dma_handle are the values dma_pool_alloc returned. This function 398 + where pool is what you passed to dma_pool_alloc(), and cpu_addr and 399 + dma_handle are the values dma_pool_alloc() returned. This function 456 400 may be called in interrupt context. 457 401 458 402 Destroy a dma_pool by calling: 459 403 460 404 dma_pool_destroy(pool); 461 405 462 - Make sure you've called dma_pool_free for all memory allocated 406 + Make sure you've called dma_pool_free() for all memory allocated 463 407 from a pool before you destroy the pool. This function may not 464 408 be called in interrupt context. 465 409 ··· 474 418 DMA_FROM_DEVICE 475 419 DMA_NONE 476 420 477 - One should provide the exact DMA direction if you know it. 421 + You should provide the exact DMA direction if you know it. 478 422 479 423 DMA_TO_DEVICE means "from main memory to the device" 480 424 DMA_FROM_DEVICE means "from the device to main memory" ··· 545 489 dma_unmap_single(dev, dma_handle, size, direction); 546 490 547 491 You should call dma_mapping_error() as dma_map_single() could fail and return 548 - error. Not all dma implementations support dma_mapping_error() interface. 492 + error. Not all DMA implementations support the dma_mapping_error() interface. 549 493 However, it is a good practice to call dma_mapping_error() interface, which 550 494 will invoke the generic mapping error check interface. Doing so will ensure 551 - that the mapping code will work correctly on all dma implementations without 495 + that the mapping code will work correctly on all DMA implementations without 552 496 any dependency on the specifics of the underlying implementation. Using the 553 497 returned address without checking for errors could result in failures ranging 554 498 from panics to silent data corruption. A couple of examples of incorrect ways 555 - to check for errors that make assumptions about the underlying dma 499 + to check for errors that make assumptions about the underlying DMA 556 500 implementation are as follows and these are applicable to dma_map_page() as 557 501 well. 558 502 ··· 572 516 goto map_error; 573 517 } 574 518 575 - You should call dma_unmap_single when the DMA activity is finished, e.g. 519 + You should call dma_unmap_single() when the DMA activity is finished, e.g., 576 520 from the interrupt which told you that the DMA transfer is done. 577 521 578 - Using cpu pointers like this for single mappings has a disadvantage, 522 + Using CPU pointers like this for single mappings has a disadvantage: 579 523 you cannot reference HIGHMEM memory in this way. Thus, there is a 580 - map/unmap interface pair akin to dma_{map,unmap}_single. These 581 - interfaces deal with page/offset pairs instead of cpu pointers. 524 + map/unmap interface pair akin to dma_{map,unmap}_single(). These 525 + interfaces deal with page/offset pairs instead of CPU pointers. 582 526 Specifically: 583 527 584 528 struct device *dev = &my_dev->dev; ··· 606 550 You should call dma_mapping_error() as dma_map_page() could fail and return 607 551 error as outlined under the dma_map_single() discussion. 608 552 609 - You should call dma_unmap_page when the DMA activity is finished, e.g. 553 + You should call dma_unmap_page() when the DMA activity is finished, e.g., 610 554 from the interrupt which told you that the DMA transfer is done. 611 555 612 556 With scatterlists, you map a region gathered from several regions by: ··· 644 588 it should _NOT_ be the 'count' value _returned_ from the 645 589 dma_map_sg call. 646 590 647 - Every dma_map_{single,sg} call should have its dma_unmap_{single,sg} 648 - counterpart, because the bus address space is a shared resource (although 649 - in some ports the mapping is per each BUS so less devices contend for the 650 - same bus address space) and you could render the machine unusable by eating 651 - all bus addresses. 591 + Every dma_map_{single,sg}() call should have its dma_unmap_{single,sg}() 592 + counterpart, because the bus address space is a shared resource and 593 + you could render the machine unusable by consuming all bus addresses. 652 594 653 595 If you need to use the same streaming DMA region multiple times and touch 654 596 the data in between the DMA transfers, the buffer needs to be synced 655 - properly in order for the cpu and device to see the most uptodate and 597 + properly in order for the CPU and device to see the most up-to-date and 656 598 correct copy of the DMA buffer. 657 599 658 - So, firstly, just map it with dma_map_{single,sg}, and after each DMA 600 + So, firstly, just map it with dma_map_{single,sg}(), and after each DMA 659 601 transfer call either: 660 602 661 603 dma_sync_single_for_cpu(dev, dma_handle, size, direction); ··· 665 611 as appropriate. 666 612 667 613 Then, if you wish to let the device get at the DMA area again, 668 - finish accessing the data with the cpu, and then before actually 614 + finish accessing the data with the CPU, and then before actually 669 615 giving the buffer to the hardware call either: 670 616 671 617 dma_sync_single_for_device(dev, dma_handle, size, direction); ··· 677 623 as appropriate. 678 624 679 625 After the last DMA transfer call one of the DMA unmap routines 680 - dma_unmap_{single,sg}. If you don't touch the data from the first dma_map_* 681 - call till dma_unmap_*, then you don't have to call the dma_sync_* 682 - routines at all. 626 + dma_unmap_{single,sg}(). If you don't touch the data from the first 627 + dma_map_*() call till dma_unmap_*(), then you don't have to call the 628 + dma_sync_*() routines at all. 683 629 684 630 Here is pseudo code which shows a situation in which you would need 685 631 to use the dma_sync_*() interfaces. ··· 744 690 } 745 691 } 746 692 747 - Drivers converted fully to this interface should not use virt_to_bus any 748 - longer, nor should they use bus_to_virt. Some drivers have to be changed a 749 - little bit, because there is no longer an equivalent to bus_to_virt in the 693 + Drivers converted fully to this interface should not use virt_to_bus() any 694 + longer, nor should they use bus_to_virt(). Some drivers have to be changed a 695 + little bit, because there is no longer an equivalent to bus_to_virt() in the 750 696 dynamic DMA mapping scheme - you have to always store the DMA addresses 751 - returned by the dma_alloc_coherent, dma_pool_alloc, and dma_map_single 752 - calls (dma_map_sg stores them in the scatterlist itself if the platform 697 + returned by the dma_alloc_coherent(), dma_pool_alloc(), and dma_map_single() 698 + calls (dma_map_sg() stores them in the scatterlist itself if the platform 753 699 supports dynamic DMA mapping in hardware) in your driver structures and/or 754 700 in the card registers. 755 701 ··· 763 709 DMA address space is limited on some architectures and an allocation 764 710 failure can be determined by: 765 711 766 - - checking if dma_alloc_coherent returns NULL or dma_map_sg returns 0 712 + - checking if dma_alloc_coherent() returns NULL or dma_map_sg returns 0 767 713 768 - - checking the returned dma_addr_t of dma_map_single and dma_map_page 714 + - checking the dma_addr_t returned from dma_map_single() and dma_map_page() 769 715 by using dma_mapping_error(): 770 716 771 717 dma_addr_t dma_handle; ··· 848 794 dma_unmap_single(array[i].dma_addr); 849 795 } 850 796 851 - Networking drivers must call dev_kfree_skb to free the socket buffer 797 + Networking drivers must call dev_kfree_skb() to free the socket buffer 852 798 and return NETDEV_TX_OK if the DMA mapping fails on the transmit hook 853 799 (ndo_start_xmit). This means that the socket buffer is just dropped in 854 800 the failure case. ··· 885 831 DEFINE_DMA_UNMAP_LEN(len); 886 832 }; 887 833 888 - 2) Use dma_unmap_{addr,len}_set to set these values. 834 + 2) Use dma_unmap_{addr,len}_set() to set these values. 889 835 Example, before: 890 836 891 837 ringp->mapping = FOO; ··· 896 842 dma_unmap_addr_set(ringp, mapping, FOO); 897 843 dma_unmap_len_set(ringp, len, BAR); 898 844 899 - 3) Use dma_unmap_{addr,len} to access these values. 845 + 3) Use dma_unmap_{addr,len}() to access these values. 900 846 Example, before: 901 847 902 848 dma_unmap_single(dev, ringp->mapping, ringp->len,
+76 -72
Documentation/DMA-API.txt
··· 4 4 James E.J. Bottomley <James.Bottomley@HansenPartnership.com> 5 5 6 6 This document describes the DMA API. For a more gentle introduction 7 - of the API (and actual examples) see 8 - Documentation/DMA-API-HOWTO.txt. 7 + of the API (and actual examples), see Documentation/DMA-API-HOWTO.txt. 9 8 10 - This API is split into two pieces. Part I describes the API. Part II 11 - describes the extensions to the API for supporting non-consistent 12 - memory machines. Unless you know that your driver absolutely has to 13 - support non-consistent platforms (this is usually only legacy 14 - platforms) you should only use the API described in part I. 9 + This API is split into two pieces. Part I describes the basic API. 10 + Part II describes extensions for supporting non-consistent memory 11 + machines. Unless you know that your driver absolutely has to support 12 + non-consistent platforms (this is usually only legacy platforms) you 13 + should only use the API described in part I. 15 14 16 15 Part I - dma_ API 17 16 ------------------------------------- 18 17 19 - To get the dma_ API, you must #include <linux/dma-mapping.h> 18 + To get the dma_ API, you must #include <linux/dma-mapping.h>. This 19 + provides dma_addr_t and the interfaces described below. 20 20 21 + A dma_addr_t can hold any valid DMA or bus address for the platform. It 22 + can be given to a device to use as a DMA source or target. A CPU cannot 23 + reference a dma_addr_t directly because there may be translation between 24 + its physical address space and the bus address space. 21 25 22 - Part Ia - Using large dma-coherent buffers 26 + Part Ia - Using large DMA-coherent buffers 23 27 ------------------------------------------ 24 28 25 29 void * ··· 37 33 devices to read that memory.) 38 34 39 35 This routine allocates a region of <size> bytes of consistent memory. 40 - It also returns a <dma_handle> which may be cast to an unsigned 41 - integer the same width as the bus and used as the physical address 42 - base of the region. 43 36 44 - Returns: a pointer to the allocated region (in the processor's virtual 37 + It returns a pointer to the allocated region (in the processor's virtual 45 38 address space) or NULL if the allocation failed. 39 + 40 + It also returns a <dma_handle> which may be cast to an unsigned integer the 41 + same width as the bus and given to the device as the bus address base of 42 + the region. 46 43 47 44 Note: consistent memory can be expensive on some platforms, and the 48 45 minimum allocation length may be as big as a page, so you should 49 46 consolidate your requests for consistent memory as much as possible. 50 47 The simplest way to do that is to use the dma_pool calls (see below). 51 48 52 - The flag parameter (dma_alloc_coherent only) allows the caller to 53 - specify the GFP_ flags (see kmalloc) for the allocation (the 49 + The flag parameter (dma_alloc_coherent() only) allows the caller to 50 + specify the GFP_ flags (see kmalloc()) for the allocation (the 54 51 implementation may choose to ignore flags that affect the location of 55 52 the returned memory, like GFP_DMA). 56 53 ··· 66 61 dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, 67 62 dma_addr_t dma_handle) 68 63 69 - Free the region of consistent memory you previously allocated. dev, 70 - size and dma_handle must all be the same as those passed into the 71 - consistent allocate. cpu_addr must be the virtual address returned by 72 - the consistent allocate. 64 + Free a region of consistent memory you previously allocated. dev, 65 + size and dma_handle must all be the same as those passed into 66 + dma_alloc_coherent(). cpu_addr must be the virtual address returned by 67 + the dma_alloc_coherent(). 73 68 74 69 Note that unlike their sibling allocation calls, these routines 75 70 may only be called with IRQs enabled. 76 71 77 72 78 - Part Ib - Using small dma-coherent buffers 73 + Part Ib - Using small DMA-coherent buffers 79 74 ------------------------------------------ 80 75 81 76 To get this part of the dma_ API, you must #include <linux/dmapool.h> 82 77 83 - Many drivers need lots of small dma-coherent memory regions for DMA 78 + Many drivers need lots of small DMA-coherent memory regions for DMA 84 79 descriptors or I/O buffers. Rather than allocating in units of a page 85 80 or more using dma_alloc_coherent(), you can use DMA pools. These work 86 - much like a struct kmem_cache, except that they use the dma-coherent allocator, 81 + much like a struct kmem_cache, except that they use the DMA-coherent allocator, 87 82 not __get_free_pages(). Also, they understand common hardware constraints 88 83 for alignment, like queue heads needing to be aligned on N-byte boundaries. 89 84 ··· 92 87 dma_pool_create(const char *name, struct device *dev, 93 88 size_t size, size_t align, size_t alloc); 94 89 95 - The pool create() routines initialize a pool of dma-coherent buffers 90 + dma_pool_create() initializes a pool of DMA-coherent buffers 96 91 for use with a given device. It must be called in a context which 97 92 can sleep. 98 93 ··· 107 102 void *dma_pool_alloc(struct dma_pool *pool, gfp_t gfp_flags, 108 103 dma_addr_t *dma_handle); 109 104 110 - This allocates memory from the pool; the returned memory will meet the size 111 - and alignment requirements specified at creation time. Pass GFP_ATOMIC to 112 - prevent blocking, or if it's permitted (not in_interrupt, not holding SMP locks), 113 - pass GFP_KERNEL to allow blocking. Like dma_alloc_coherent(), this returns 114 - two values: an address usable by the cpu, and the dma address usable by the 115 - pool's device. 105 + This allocates memory from the pool; the returned memory will meet the 106 + size and alignment requirements specified at creation time. Pass 107 + GFP_ATOMIC to prevent blocking, or if it's permitted (not 108 + in_interrupt, not holding SMP locks), pass GFP_KERNEL to allow 109 + blocking. Like dma_alloc_coherent(), this returns two values: an 110 + address usable by the CPU, and the DMA address usable by the pool's 111 + device. 116 112 117 113 118 114 void dma_pool_free(struct dma_pool *pool, void *vaddr, 119 115 dma_addr_t addr); 120 116 121 117 This puts memory back into the pool. The pool is what was passed to 122 - the pool allocation routine; the cpu (vaddr) and dma addresses are what 118 + dma_pool_alloc(); the CPU (vaddr) and DMA addresses are what 123 119 were returned when that routine allocated the memory being freed. 124 120 125 121 126 122 void dma_pool_destroy(struct dma_pool *pool); 127 123 128 - The pool destroy() routines free the resources of the pool. They must be 124 + dma_pool_destroy() frees the resources of the pool. It must be 129 125 called in a context which can sleep. Make sure you've freed all allocated 130 126 memory back to the pool before you destroy it. 131 127 ··· 193 187 enum dma_data_direction direction) 194 188 195 189 Maps a piece of processor virtual memory so it can be accessed by the 196 - device and returns the physical handle of the memory. 190 + device and returns the bus address of the memory. 197 191 198 - The direction for both api's may be converted freely by casting. 192 + The direction for both APIs may be converted freely by casting. 199 193 However the dma_ API uses a strongly typed enumerator for its 200 194 direction: 201 195 ··· 204 198 DMA_FROM_DEVICE data is coming from the device to the memory 205 199 DMA_BIDIRECTIONAL direction isn't known 206 200 207 - Notes: Not all memory regions in a machine can be mapped by this 208 - API. Further, regions that appear to be physically contiguous in 209 - kernel virtual space may not be contiguous as physical memory. Since 210 - this API does not provide any scatter/gather capability, it will fail 211 - if the user tries to map a non-physically contiguous piece of memory. 212 - For this reason, it is recommended that memory mapped by this API be 213 - obtained only from sources which guarantee it to be physically contiguous 214 - (like kmalloc). 201 + Notes: Not all memory regions in a machine can be mapped by this API. 202 + Further, contiguous kernel virtual space may not be contiguous as 203 + physical memory. Since this API does not provide any scatter/gather 204 + capability, it will fail if the user tries to map a non-physically 205 + contiguous piece of memory. For this reason, memory to be mapped by 206 + this API should be obtained from sources which guarantee it to be 207 + physically contiguous (like kmalloc). 215 208 216 - Further, the physical address of the memory must be within the 217 - dma_mask of the device (the dma_mask represents a bit mask of the 218 - addressable region for the device. I.e., if the physical address of 219 - the memory anded with the dma_mask is still equal to the physical 220 - address, then the device can perform DMA to the memory). In order to 209 + Further, the bus address of the memory must be within the 210 + dma_mask of the device (the dma_mask is a bit mask of the 211 + addressable region for the device, i.e., if the bus address of 212 + the memory ANDed with the dma_mask is still equal to the bus 213 + address, then the device can perform DMA to the memory). To 221 214 ensure that the memory allocated by kmalloc is within the dma_mask, 222 215 the driver may specify various platform-dependent flags to restrict 223 - the physical memory range of the allocation (e.g. on x86, GFP_DMA 224 - guarantees to be within the first 16Mb of available physical memory, 216 + the bus address range of the allocation (e.g., on x86, GFP_DMA 217 + guarantees to be within the first 16MB of available bus addresses, 225 218 as required by ISA devices). 226 219 227 220 Note also that the above constraints on physical contiguity and 228 221 dma_mask may not apply if the platform has an IOMMU (a device which 229 - supplies a physical to virtual mapping between the I/O memory bus and 230 - the device). However, to be portable, device driver writers may *not* 231 - assume that such an IOMMU exists. 222 + maps an I/O bus address to a physical memory address). However, to be 223 + portable, device driver writers may *not* assume that such an IOMMU 224 + exists. 232 225 233 226 Warnings: Memory coherency operates at a granularity called the cache 234 227 line width. In order for memory mapped by this API to operate ··· 286 281 int 287 282 dma_mapping_error(struct device *dev, dma_addr_t dma_addr) 288 283 289 - In some circumstances dma_map_single and dma_map_page will fail to create 284 + In some circumstances dma_map_single() and dma_map_page() will fail to create 290 285 a mapping. A driver can check for these errors by testing the returned 291 - dma address with dma_mapping_error(). A non-zero return value means the mapping 286 + DMA address with dma_mapping_error(). A non-zero return value means the mapping 292 287 could not be created and the driver should take appropriate action (e.g. 293 288 reduce current DMA mapping usage or delay and try again later). 294 289 ··· 296 291 dma_map_sg(struct device *dev, struct scatterlist *sg, 297 292 int nents, enum dma_data_direction direction) 298 293 299 - Returns: the number of physical segments mapped (this may be shorter 294 + Returns: the number of bus address segments mapped (this may be shorter 300 295 than <nents> passed in if some elements of the scatter/gather list are 301 296 physically or virtually adjacent and an IOMMU maps them with a single 302 297 entry). ··· 304 299 Please note that the sg cannot be mapped again if it has been mapped once. 305 300 The mapping process is allowed to destroy information in the sg. 306 301 307 - As with the other mapping interfaces, dma_map_sg can fail. When it 302 + As with the other mapping interfaces, dma_map_sg() can fail. When it 308 303 does, 0 is returned and a driver must take appropriate action. It is 309 304 critical that the driver do something, in the case of a block driver 310 305 aborting the request or even oopsing is better than doing nothing and ··· 340 335 API. 341 336 342 337 Note: <nents> must be the number you passed in, *not* the number of 343 - physical entries returned. 338 + bus address entries returned. 344 339 345 340 void 346 341 dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size, ··· 355 350 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems, 356 351 enum dma_data_direction direction) 357 352 358 - Synchronise a single contiguous or scatter/gather mapping for the cpu 353 + Synchronise a single contiguous or scatter/gather mapping for the CPU 359 354 and device. With the sync_sg API, all the parameters must be the same 360 355 as those passed into the single mapping API. With the sync_single API, 361 356 you can use dma_handle and size parameters that aren't identical to ··· 396 391 without the _attrs suffixes, except that they pass an optional 397 392 struct dma_attrs*. 398 393 399 - struct dma_attrs encapsulates a set of "dma attributes". For the 394 + struct dma_attrs encapsulates a set of "DMA attributes". For the 400 395 definition of struct dma_attrs see linux/dma-attrs.h. 401 396 402 - The interpretation of dma attributes is architecture-specific, and 397 + The interpretation of DMA attributes is architecture-specific, and 403 398 each attribute should be documented in Documentation/DMA-attributes.txt. 404 399 405 400 If struct dma_attrs* is NULL, the semantics of each of these ··· 463 458 guarantee that the sync points become nops. 464 459 465 460 Warning: Handling non-consistent memory is a real pain. You should 466 - only ever use this API if you positively know your driver will be 461 + only use this API if you positively know your driver will be 467 462 required to work on one of the rare (usually non-PCI) architectures 468 463 that simply cannot make consistent memory. 469 464 ··· 497 492 boundaries when doing this. 498 493 499 494 int 500 - dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, 495 + dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, 501 496 dma_addr_t device_addr, size_t size, int 502 497 flags) 503 498 504 - Declare region of memory to be handed out by dma_alloc_coherent when 499 + Declare region of memory to be handed out by dma_alloc_coherent() when 505 500 it's asked for coherent memory for this device. 506 501 507 - bus_addr is the physical address to which the memory is currently 508 - assigned in the bus responding region (this will be used by the 509 - platform to perform the mapping). 502 + phys_addr is the CPU physical address to which the memory is currently 503 + assigned (this will be ioremapped so the CPU can access the region). 510 504 511 - device_addr is the physical address the device needs to be programmed 512 - with actually to address this memory (this will be handed out as the 505 + device_addr is the bus address the device needs to be programmed 506 + with to actually address this memory (this will be handed out as the 513 507 dma_addr_t in dma_alloc_coherent()). 514 508 515 509 size is the size of the area (must be multiples of PAGE_SIZE). 516 510 517 - flags can be or'd together and are: 511 + flags can be ORed together and are: 518 512 519 513 DMA_MEMORY_MAP - request that the memory returned from 520 514 dma_alloc_coherent() be directly writable. 521 515 522 516 DMA_MEMORY_IO - request that the memory returned from 523 - dma_alloc_coherent() be addressable using read/write/memcpy_toio etc. 517 + dma_alloc_coherent() be addressable using read()/write()/memcpy_toio() etc. 524 518 525 519 One or both of these flags must be present. 526 520 ··· 576 572 Part III - Debug drivers use of the DMA-API 577 573 ------------------------------------------- 578 574 579 - The DMA-API as described above as some constraints. DMA addresses must be 575 + The DMA-API as described above has some constraints. DMA addresses must be 580 576 released with the corresponding function with the same size for example. With 581 577 the advent of hardware IOMMUs it becomes more and more important that drivers 582 578 do not violate those constraints. In the worst case such a violation can ··· 694 690 void debug_dmap_mapping_error(struct device *dev, dma_addr_t dma_addr); 695 691 696 692 dma-debug interface debug_dma_mapping_error() to debug drivers that fail 697 - to check dma mapping errors on addresses returned by dma_map_single() and 693 + to check DMA mapping errors on addresses returned by dma_map_single() and 698 694 dma_map_page() interfaces. This interface clears a flag set by 699 695 debug_dma_map_page() to indicate that dma_mapping_error() has been called by 700 696 the driver. When driver does unmap, debug_dma_unmap() checks the flag and if 701 697 this flag is still set, prints warning message that includes call trace that 702 698 leads up to the unmap. This interface can be called from dma_mapping_error() 703 - routines to enable dma mapping error check debugging. 699 + routines to enable DMA mapping error check debugging. 704 700
+2 -2
Documentation/DMA-ISA-LPC.txt
··· 16 16 #include <asm/dma.h> 17 17 18 18 The first is the generic DMA API used to convert virtual addresses to 19 - physical addresses (see Documentation/DMA-API.txt for details). 19 + bus addresses (see Documentation/DMA-API.txt for details). 20 20 21 21 The second contains the routines specific to ISA DMA transfers. Since 22 22 this is not present on all platforms make sure you construct your ··· 50 50 Part III - Address translation 51 51 ------------------------------ 52 52 53 - To translate the virtual address to a physical use the normal DMA 53 + To translate the virtual address to a bus address, use the normal DMA 54 54 API. Do _not_ use isa_virt_to_phys() even though it does the same 55 55 thing. The reason for this is that the function isa_virt_to_phys() 56 56 will require a Kconfig dependency to ISA, not just ISA_DMA_API which
-20
arch/microblaze/pci/pci-common.c
··· 168 168 return NULL; 169 169 } 170 170 171 - static 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 - } 183 - static DEVICE_ATTR(devspec, S_IRUGO, pci_show_devspec, NULL); 184 - 185 - /* Add sysfs properties */ 186 - int pcibios_add_platform_entries(struct pci_dev *pdev) 187 - { 188 - return device_create_file(&pdev->dev, &dev_attr_devspec); 189 - } 190 - 191 171 void pcibios_set_master(struct pci_dev *dev) 192 172 { 193 173 /* No special bus mastering setup handling */
-20
arch/powerpc/kernel/pci-common.c
··· 201 201 return NULL; 202 202 } 203 203 204 - static 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 - } 216 - static DEVICE_ATTR(devspec, S_IRUGO, pci_show_devspec, NULL); 217 - 218 - /* Add sysfs properties */ 219 - int pcibios_add_platform_entries(struct pci_dev *pdev) 220 - { 221 - return device_create_file(&pdev->dev, &dev_attr_devspec); 222 - } 223 - 224 204 /* 225 205 * Reads the interrupt pin to determine if interrupt is use by card. 226 206 * If the interrupt is used, then gets the interrupt line from the
+2 -4
arch/s390/include/asm/pci.h
··· 120 120 return (zdev->fh & (1UL << 31)) ? true : false; 121 121 } 122 122 123 + extern const struct attribute_group *zpci_attr_groups[]; 124 + 123 125 /* ----------------------------------------------------------------------------- 124 126 Prototypes 125 127 ----------------------------------------------------------------------------- */ ··· 167 165 /* Helpers */ 168 166 struct zpci_dev *get_zdev(struct pci_dev *); 169 167 struct zpci_dev *get_zdev_by_fid(u32); 170 - 171 - /* sysfs */ 172 - int zpci_sysfs_add_device(struct device *); 173 - void zpci_sysfs_remove_device(struct device *); 174 168 175 169 /* DMA */ 176 170 int zpci_dma_init(void);
+1 -5
arch/s390/pci/pci.c
··· 530 530 } 531 531 } 532 532 533 - int pcibios_add_platform_entries(struct pci_dev *pdev) 534 - { 535 - return zpci_sysfs_add_device(&pdev->dev); 536 - } 537 - 538 533 static int __init zpci_irq_init(void) 539 534 { 540 535 int rc; ··· 666 671 int i; 667 672 668 673 zdev->pdev = pdev; 674 + pdev->dev.groups = zpci_attr_groups; 669 675 zpci_map_resources(zdev); 670 676 671 677 for (i = 0; i < PCI_BAR_COUNT; i++) {
+13 -31
arch/s390/pci/pci_sysfs.c
··· 72 72 } 73 73 static DEVICE_ATTR(recover, S_IWUSR, NULL, store_recover); 74 74 75 - static struct device_attribute *zpci_dev_attrs[] = { 76 - &dev_attr_function_id, 77 - &dev_attr_function_handle, 78 - &dev_attr_pchid, 79 - &dev_attr_pfgid, 80 - &dev_attr_recover, 75 + static struct attribute *zpci_dev_attrs[] = { 76 + &dev_attr_function_id.attr, 77 + &dev_attr_function_handle.attr, 78 + &dev_attr_pchid.attr, 79 + &dev_attr_pfgid.attr, 80 + &dev_attr_recover.attr, 81 81 NULL, 82 82 }; 83 - 84 - int 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 - 95 - error: 96 - while (--i >= 0) 97 - device_remove_file(dev, zpci_dev_attrs[i]); 98 - return rc; 99 - } 100 - 101 - void 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 - } 83 + static struct attribute_group zpci_attr_group = { 84 + .attrs = zpci_dev_attrs, 85 + }; 86 + const struct attribute_group *zpci_attr_groups[] = { 87 + &zpci_attr_group, 88 + NULL, 89 + };
+15 -3
arch/sh/drivers/pci/fixups-dreamcast.c
··· 31 31 static void gapspci_fixup_resources(struct pci_dev *dev) 32 32 { 33 33 struct pci_channel *p = dev->sysdata; 34 + struct resource res; 35 + struct pci_bus_region region; 34 36 35 37 printk(KERN_NOTICE "PCI: Fixing up device %s\n", pci_name(dev)); 36 38 ··· 52 50 53 51 /* 54 52 * Redirect dma memory allocations to special memory window. 53 + * 54 + * If this GAPSPCI region were mapped by a BAR, the CPU 55 + * phys_addr_t would be pci_resource_start(), and the bus 56 + * address would be pci_bus_address(pci_resource_start()). 57 + * But apparently there's no BAR mapping it, so we just 58 + * "know" its CPU address is GAPSPCI_DMA_BASE. 55 59 */ 60 + res.start = GAPSPCI_DMA_BASE; 61 + res.end = GAPSPCI_DMA_BASE + GAPSPCI_DMA_SIZE - 1; 62 + res.flags = IORESOURCE_MEM; 63 + pcibios_resource_to_bus(dev->bus, &region, &res); 56 64 BUG_ON(!dma_declare_coherent_memory(&dev->dev, 57 - GAPSPCI_DMA_BASE, 58 - GAPSPCI_DMA_BASE, 59 - GAPSPCI_DMA_SIZE, 65 + res.start, 66 + region.start, 67 + resource_size(&res), 60 68 DMA_MEMORY_MAP | 61 69 DMA_MEMORY_EXCLUSIVE)); 62 70 break;
+31 -28
arch/x86/kernel/aperture_64.c
··· 10 10 * 11 11 * Copyright 2002 Andi Kleen, SuSE Labs. 12 12 */ 13 + #define pr_fmt(fmt) "AGP: " fmt 14 + 13 15 #include <linux/kernel.h> 14 16 #include <linux/types.h> 15 17 #include <linux/init.h> ··· 77 75 addr = memblock_find_in_range(GART_MIN_ADDR, GART_MAX_ADDR, 78 76 aper_size, aper_size); 79 77 if (!addr) { 80 - printk(KERN_ERR 81 - "Cannot allocate aperture memory hole (%lx,%uK)\n", 82 - addr, aper_size>>10); 78 + pr_err("Cannot allocate aperture memory hole [mem %#010lx-%#010lx] (%uKB)\n", 79 + addr, addr + aper_size - 1, aper_size >> 10); 83 80 return 0; 84 81 } 85 82 memblock_reserve(addr, aper_size); 86 - printk(KERN_INFO "Mapping aperture over %d KB of RAM @ %lx\n", 87 - aper_size >> 10, addr); 83 + pr_info("Mapping aperture over RAM [mem %#010lx-%#010lx] (%uKB)\n", 84 + addr, addr + aper_size - 1, aper_size >> 10); 88 85 register_nosave_region(addr >> PAGE_SHIFT, 89 86 (addr+aper_size) >> PAGE_SHIFT); 90 87 ··· 127 126 u64 aper; 128 127 u32 old_order; 129 128 130 - printk(KERN_INFO "AGP bridge at %02x:%02x:%02x\n", bus, slot, func); 129 + pr_info("pci 0000:%02x:%02x:%02x: AGP bridge\n", bus, slot, func); 131 130 apsizereg = read_pci_config_16(bus, slot, func, cap + 0x14); 132 131 if (apsizereg == 0xffffffff) { 133 - printk(KERN_ERR "APSIZE in AGP bridge unreadable\n"); 132 + pr_err("pci 0000:%02x:%02x.%d: APSIZE unreadable\n", 133 + bus, slot, func); 134 134 return 0; 135 135 } 136 136 ··· 155 153 * On some sick chips, APSIZE is 0. It means it wants 4G 156 154 * so let double check that order, and lets trust AMD NB settings: 157 155 */ 158 - printk(KERN_INFO "Aperture from AGP @ %Lx old size %u MB\n", 159 - aper, 32 << old_order); 156 + pr_info("pci 0000:%02x:%02x.%d: AGP aperture [bus addr %#010Lx-%#010Lx] (old size %uMB)\n", 157 + bus, slot, func, aper, aper + (32ULL << (old_order + 20)) - 1, 158 + 32 << old_order); 160 159 if (aper + (32ULL<<(20 + *order)) > 0x100000000ULL) { 161 - printk(KERN_INFO "Aperture size %u MB (APSIZE %x) is not right, using settings from NB\n", 162 - 32 << *order, apsizereg); 160 + pr_info("pci 0000:%02x:%02x.%d: AGP aperture size %uMB (APSIZE %#x) is not right, using settings from NB\n", 161 + bus, slot, func, 32 << *order, apsizereg); 163 162 *order = old_order; 164 163 } 165 164 166 - printk(KERN_INFO "Aperture from AGP @ %Lx size %u MB (APSIZE %x)\n", 167 - aper, 32 << *order, apsizereg); 165 + pr_info("pci 0000:%02x:%02x.%d: AGP aperture [bus addr %#010Lx-%#010Lx] (%uMB, APSIZE %#x)\n", 166 + bus, slot, func, aper, aper + (32ULL << (*order + 20)) - 1, 167 + 32 << *order, apsizereg); 168 168 169 169 if (!aperture_valid(aper, (32*1024*1024) << *order, 32<<20)) 170 170 return 0; ··· 222 218 } 223 219 } 224 220 } 225 - printk(KERN_INFO "No AGP bridge found\n"); 221 + pr_info("No AGP bridge found\n"); 226 222 227 223 return 0; 228 224 } ··· 314 310 if (e820_any_mapped(aper_base, aper_base + aper_size, 315 311 E820_RAM)) { 316 312 /* reserve it, so we can reuse it in second kernel */ 317 - printk(KERN_INFO "update e820 for GART\n"); 313 + pr_info("e820: reserve [mem %#010Lx-%#010Lx] for GART\n", 314 + aper_base, aper_base + aper_size - 1); 318 315 e820_add_region(aper_base, aper_size, E820_RESERVED); 319 316 update_e820(); 320 317 } ··· 359 354 !early_pci_allowed()) 360 355 return -ENODEV; 361 356 362 - printk(KERN_INFO "Checking aperture...\n"); 357 + pr_info("Checking aperture...\n"); 363 358 364 359 if (!fallback_aper_force) 365 360 agp_aper_base = search_agp_bridge(&agp_aper_order, &valid_agp); ··· 400 395 aper_base = read_pci_config(bus, slot, 3, AMD64_GARTAPERTUREBASE) & 0x7fff; 401 396 aper_base <<= 25; 402 397 403 - printk(KERN_INFO "Node %d: aperture @ %Lx size %u MB\n", 404 - node, aper_base, aper_size >> 20); 398 + pr_info("Node %d: aperture [bus addr %#010Lx-%#010Lx] (%uMB)\n", 399 + node, aper_base, aper_base + aper_size - 1, 400 + aper_size >> 20); 405 401 node++; 406 402 407 403 if (!aperture_valid(aper_base, aper_size, 64<<20)) { ··· 413 407 if (!no_iommu && 414 408 max_pfn > MAX_DMA32_PFN && 415 409 !printed_gart_size_msg) { 416 - printk(KERN_ERR "you are using iommu with agp, but GART size is less than 64M\n"); 417 - printk(KERN_ERR "please increase GART size in your BIOS setup\n"); 418 - printk(KERN_ERR "if BIOS doesn't have that option, contact your HW vendor!\n"); 410 + pr_err("you are using iommu with agp, but GART size is less than 64MB\n"); 411 + pr_err("please increase GART size in your BIOS setup\n"); 412 + pr_err("if BIOS doesn't have that option, contact your HW vendor!\n"); 419 413 printed_gart_size_msg = 1; 420 414 } 421 415 } else { ··· 452 446 force_iommu || 453 447 valid_agp || 454 448 fallback_aper_force) { 455 - printk(KERN_INFO 456 - "Your BIOS doesn't leave a aperture memory hole\n"); 457 - printk(KERN_INFO 458 - "Please enable the IOMMU option in the BIOS setup\n"); 459 - printk(KERN_INFO 460 - "This costs you %d MB of RAM\n", 461 - 32 << fallback_aper_order); 449 + pr_info("Your BIOS doesn't leave a aperture memory hole\n"); 450 + pr_info("Please enable the IOMMU option in the BIOS setup\n"); 451 + pr_info("This costs you %dMB of RAM\n", 452 + 32 << fallback_aper_order); 462 453 463 454 aper_order = fallback_aper_order; 464 455 aper_alloc = allocate_aperture();
+2 -2
arch/x86/pci/broadcom_bus.c
··· 60 60 word1 = read_pci_config_16(bus, slot, func, 0xc4); 61 61 word2 = read_pci_config_16(bus, slot, func, 0xc6); 62 62 if (word1 != word2) { 63 - res.start = (word1 << 16) | 0x0000; 64 - res.end = (word2 << 16) | 0xffff; 63 + res.start = ((resource_size_t) word1 << 16) | 0x0000; 64 + res.end = ((resource_size_t) word2 << 16) | 0xffff; 65 65 res.flags = IORESOURCE_MEM | IORESOURCE_PREFETCH; 66 66 update_res(info, res.start, res.end, res.flags, 0); 67 67 }
+14
arch/x86/pci/fixup.c
··· 6 6 #include <linux/dmi.h> 7 7 #include <linux/pci.h> 8 8 #include <linux/vgaarb.h> 9 + #include <asm/hpet.h> 9 10 #include <asm/pci_x86.h> 10 11 11 12 static void pci_fixup_i450nx(struct pci_dev *d) ··· 526 525 } 527 526 } 528 527 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATI, 0x4385, sb600_disable_hpet_bar); 528 + 529 + #ifdef CONFIG_HPET_TIMER 530 + static void sb600_hpet_quirk(struct pci_dev *dev) 531 + { 532 + struct resource *r = &dev->resource[1]; 533 + 534 + if (r->flags & IORESOURCE_MEM && r->start == hpet_address) { 535 + r->flags |= IORESOURCE_PCI_FIXED; 536 + dev_info(&dev->dev, "reg 0x14 contains HPET; making it immovable\n"); 537 + } 538 + } 539 + DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, 0x4385, sb600_hpet_quirk); 540 + #endif 529 541 530 542 /* 531 543 * Twinhead H12Y needs us to block out a region otherwise we map devices
+16 -11
arch/x86/pci/i386.c
··· 271 271 "BAR %d: reserving %pr (d=%d, p=%d)\n", 272 272 idx, r, disabled, pass); 273 273 if (pci_claim_resource(dev, idx) < 0) { 274 - /* We'll assign a new address later */ 275 - pcibios_save_fw_addr(dev, 276 - idx, r->start); 277 - r->end -= r->start; 278 - r->start = 0; 274 + if (r->flags & IORESOURCE_PCI_FIXED) { 275 + dev_info(&dev->dev, "BAR %d %pR is immovable\n", 276 + idx, r); 277 + } else { 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 } ··· 361 356 return 0; 362 357 } 363 358 359 + /** 360 + * called in fs_initcall (one below subsys_initcall), 361 + * give a chance for motherboard reserve resources 362 + */ 363 + fs_initcall(pcibios_assign_resources); 364 + 364 365 void pcibios_resource_survey_bus(struct pci_bus *bus) 365 366 { 366 367 dev_printk(KERN_DEBUG, &bus->dev, "Allocating resources\n"); ··· 402 391 */ 403 392 ioapic_insert_resources(); 404 393 } 405 - 406 - /** 407 - * called in fs_initcall (one below subsys_initcall), 408 - * give a chance for motherboard reserve resources 409 - */ 410 - fs_initcall(pcibios_assign_resources); 411 394 412 395 static const struct vm_operations_struct pci_mmap_ops = { 413 396 .access = generic_access_phys,
+5 -5
drivers/base/dma-coherent.c
··· 10 10 struct dma_coherent_mem { 11 11 void *virt_base; 12 12 dma_addr_t device_base; 13 - phys_addr_t pfn_base; 13 + unsigned long pfn_base; 14 14 int size; 15 15 int flags; 16 16 unsigned long *bitmap; 17 17 }; 18 18 19 - int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, 19 + int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, 20 20 dma_addr_t device_addr, size_t size, int flags) 21 21 { 22 22 void __iomem *mem_base = NULL; ··· 32 32 33 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 36 if (!mem_base) 37 37 goto out; 38 38 ··· 45 45 46 46 dev->dma_mem->virt_base = mem_base; 47 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 49 dev->dma_mem->size = pages; 50 50 dev->dma_mem->flags = flags; 51 51 ··· 208 208 209 209 *ret = -ENXIO; 210 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 212 *ret = remap_pfn_range(vma, vma->vm_start, pfn, 213 213 user_count << PAGE_SHIFT, 214 214 vma->vm_page_prot);
+3 -3
drivers/base/dma-mapping.c
··· 175 175 /** 176 176 * dmam_declare_coherent_memory - Managed dma_declare_coherent_memory() 177 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 179 * @device_addr: Device address of coherent memory to be declared 180 180 * @size: Size of coherent memory to be declared 181 181 * @flags: Flags ··· 185 185 * RETURNS: 186 186 * 0 on success, -errno on failure. 187 187 */ 188 - int dmam_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, 188 + int dmam_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, 189 189 dma_addr_t device_addr, size_t size, int flags) 190 190 { 191 191 void *res; ··· 195 195 if (!res) 196 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 199 flags); 200 200 if (rc == 0) 201 201 devres_add(dev, res);
+7 -7
drivers/iommu/exynos-iommu.c
··· 1011 1011 } 1012 1012 1013 1013 static struct iommu_ops exynos_iommu_ops = { 1014 - .domain_init = &exynos_iommu_domain_init, 1015 - .domain_destroy = &exynos_iommu_domain_destroy, 1016 - .attach_dev = &exynos_iommu_attach_device, 1017 - .detach_dev = &exynos_iommu_detach_device, 1018 - .map = &exynos_iommu_map, 1019 - .unmap = &exynos_iommu_unmap, 1020 - .iova_to_phys = &exynos_iommu_iova_to_phys, 1014 + .domain_init = exynos_iommu_domain_init, 1015 + .domain_destroy = exynos_iommu_domain_destroy, 1016 + .attach_dev = exynos_iommu_attach_device, 1017 + .detach_dev = exynos_iommu_detach_device, 1018 + .map = exynos_iommu_map, 1019 + .unmap = exynos_iommu_unmap, 1020 + .iova_to_phys = exynos_iommu_iova_to_phys, 1021 1021 .pgsize_bitmap = SECT_SIZE | LPAGE_SIZE | SPAGE_SIZE, 1022 1022 }; 1023 1023
+33 -46
drivers/pci/msi.c
··· 878 878 } 879 879 EXPORT_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 - */ 894 - int 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 - } 923 - EXPORT_SYMBOL(pci_enable_msi_block); 924 - 925 881 void pci_msi_shutdown(struct pci_dev *dev) 926 882 { 927 883 struct msi_desc *desc; ··· 1083 1127 **/ 1084 1128 int pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec) 1085 1129 { 1086 - int nvec = maxvec; 1130 + int nvec; 1087 1131 int rc; 1132 + 1133 + if (dev->current_state != PCI_D0) 1134 + return -EINVAL; 1135 + 1136 + WARN_ON(!!dev->msi_enabled); 1137 + 1138 + /* Check whether driver already requested MSI-X irqs */ 1139 + if (dev->msix_enabled) { 1140 + dev_info(&dev->dev, 1141 + "can't enable MSI (MSI-X already enabled)\n"); 1142 + return -EINVAL; 1143 + } 1088 1144 1089 1145 if (maxvec < minvec) 1090 1146 return -ERANGE; 1091 1147 1148 + nvec = pci_msi_vec_count(dev); 1149 + if (nvec < 0) 1150 + return nvec; 1151 + else if (nvec < minvec) 1152 + return -EINVAL; 1153 + else if (nvec > maxvec) 1154 + nvec = maxvec; 1155 + 1092 1156 do { 1093 - rc = pci_enable_msi_block(dev, nvec); 1157 + rc = pci_msi_check_device(dev, nvec, PCI_CAP_ID_MSI); 1158 + if (rc < 0) { 1159 + return rc; 1160 + } else if (rc > 0) { 1161 + if (rc < minvec) 1162 + return -ENOSPC; 1163 + nvec = rc; 1164 + } 1165 + } while (rc); 1166 + 1167 + do { 1168 + rc = msi_capability_init(dev, nvec); 1094 1169 if (rc < 0) { 1095 1170 return rc; 1096 1171 } else if (rc > 0) {
+18 -10
drivers/pci/pci-sysfs.c
··· 29 29 #include <linux/slab.h> 30 30 #include <linux/vgaarb.h> 31 31 #include <linux/pm_runtime.h> 32 + #include <linux/of.h> 32 33 #include "pci.h" 33 34 34 35 static int sysfs_initialized; /* = 0 */ ··· 417 416 static DEVICE_ATTR_RW(d3cold_allowed); 418 417 #endif 419 418 419 + #ifdef CONFIG_OF 420 + static ssize_t devspec_show(struct device *dev, 421 + struct device_attribute *attr, char *buf) 422 + { 423 + struct pci_dev *pdev = to_pci_dev(dev); 424 + struct device_node *np = pci_device_to_OF_node(pdev); 425 + 426 + if (np == NULL || np->full_name == NULL) 427 + return 0; 428 + return sprintf(buf, "%s", np->full_name); 429 + } 430 + static DEVICE_ATTR_RO(devspec); 431 + #endif 432 + 420 433 #ifdef CONFIG_PCI_IOV 421 434 static ssize_t sriov_totalvfs_show(struct device *dev, 422 435 struct device_attribute *attr, ··· 535 520 &dev_attr_msi_bus.attr, 536 521 #if defined(CONFIG_PM_RUNTIME) && defined(CONFIG_ACPI) 537 522 &dev_attr_d3cold_allowed.attr, 523 + #endif 524 + #ifdef CONFIG_OF 525 + &dev_attr_devspec.attr, 538 526 #endif 539 527 NULL, 540 528 }; ··· 1273 1255 .write = pci_write_config, 1274 1256 }; 1275 1257 1276 - int __weak pcibios_add_platform_entries(struct pci_dev *dev) 1277 - { 1278 - return 0; 1279 - } 1280 - 1281 1258 static ssize_t reset_store(struct device *dev, 1282 1259 struct device_attribute *attr, const char *buf, 1283 1260 size_t count) ··· 1387 1374 } 1388 1375 pdev->rom_attr = attr; 1389 1376 } 1390 - 1391 - /* add platform-specific attributes */ 1392 - retval = pcibios_add_platform_entries(pdev); 1393 - if (retval) 1394 - goto err_rom_file; 1395 1377 1396 1378 /* add sysfs entries for various capabilities */ 1397 1379 retval = pci_create_capabilities_sysfs(pdev);
+29 -19
drivers/pci/probe.c
··· 171 171 struct resource *res, unsigned int pos) 172 172 { 173 173 u32 l, sz, mask; 174 + u64 l64, sz64, mask64; 174 175 u16 orig_cmd; 175 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 179 mask = type ? PCI_ROM_ADDRESS_MASK : ~0; 179 180 ··· 227 226 } 228 227 229 228 if (res->flags & IORESOURCE_MEM_64) { 230 - u64 l64 = l; 231 - u64 sz64 = sz; 232 - u64 mask64 = mask | (u64)~0 << 32; 229 + l64 = l; 230 + sz64 = sz; 231 + mask64 = mask | (u64)~0 << 32; 233 232 234 233 pci_read_config_dword(dev, pos + 4, &l); 235 234 pci_write_config_dword(dev, pos + 4, ~0); ··· 244 243 if (!sz64) 245 244 goto fail; 246 245 247 - if ((sizeof(resource_size_t) < 8) && (sz64 > 0x100000000ULL)) { 246 + if ((sizeof(dma_addr_t) < 8 || sizeof(resource_size_t) < 8) && 247 + sz64 > 0x100000000ULL) { 248 + res->flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED; 249 + res->start = 0; 250 + res->end = 0; 248 251 bar_too_big = true; 249 - goto fail; 252 + goto out; 250 253 } 251 254 252 - if ((sizeof(resource_size_t) < 8) && l) { 253 - /* Address above 32-bit boundary; disable the BAR */ 254 - pci_write_config_dword(dev, pos, 0); 255 - pci_write_config_dword(dev, pos + 4, 0); 255 + if ((sizeof(dma_addr_t) < 8) && l) { 256 + /* Above 32-bit boundary; try to reallocate */ 256 257 res->flags |= IORESOURCE_UNSET; 257 - region.start = 0; 258 - region.end = sz64; 259 - bar_disabled = true; 258 + res->start = 0; 259 + res->end = sz64; 260 + bar_too_high = true; 261 + goto out; 260 262 } else { 261 263 region.start = l64; 262 264 region.end = l64 + sz64; ··· 289 285 * be claimed by the device. 290 286 */ 291 287 if (inverted_region.start != region.start) { 292 - dev_info(&dev->dev, "reg 0x%x: initial BAR value %pa invalid; forcing reassignment\n", 293 - pos, &region.start); 294 288 res->flags |= IORESOURCE_UNSET; 295 - res->end -= res->start; 296 289 res->start = 0; 290 + res->end = region.end - region.start; 291 + bar_invalid = true; 297 292 } 298 293 299 294 goto out; ··· 306 303 pci_write_config_word(dev, PCI_COMMAND, orig_cmd); 307 304 308 305 if (bar_too_big) 309 - dev_err(&dev->dev, "reg 0x%x: can't handle 64-bit BAR\n", pos); 310 - if (res->flags && !bar_disabled) 306 + dev_err(&dev->dev, "reg 0x%x: can't handle BAR larger than 4GB (size %#010llx)\n", 307 + pos, (unsigned long long) sz64); 308 + if (bar_too_high) 309 + dev_info(&dev->dev, "reg 0x%x: can't handle BAR above 4G (bus address %#010llx)\n", 310 + pos, (unsigned long long) l64); 311 + if (bar_invalid) 312 + dev_info(&dev->dev, "reg 0x%x: initial BAR value %#010llx invalid\n", 313 + pos, (unsigned long long) region.start); 314 + if (res->flags) 311 315 dev_printk(KERN_DEBUG, &dev->dev, "reg 0x%x: %pR\n", pos, res); 312 316 313 317 return (res->flags & IORESOURCE_MEM_64) ? 1 : 0; ··· 475 465 476 466 if (dev->transparent) { 477 467 pci_bus_for_each_resource(child->parent, res, i) { 478 - if (res) { 468 + if (res && res->flags) { 479 469 pci_bus_add_resource(child, res, 480 470 PCI_SUBTRACTIVE_DECODE); 481 471 dev_printk(KERN_DEBUG, &dev->dev,
+8
drivers/pci/quirks.c
··· 2992 2992 quirk_broken_intx_masking); 2993 2993 DECLARE_PCI_FIXUP_HEADER(0x1814, 0x0601, /* Ralink RT2800 802.11n PCI */ 2994 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 + */ 3001 + DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_REALTEK, 0x8169, 3002 + quirk_broken_intx_masking); 2995 3003 2996 3004 static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f, 2997 3005 struct pci_fixup *end)
+155 -67
drivers/pci/setup-bus.c
··· 713 713 bus resource of a given type. Note: we intentionally skip 714 714 the bus resources which have already been assigned (that is, 715 715 have non-NULL parent resource). */ 716 - static struct resource *find_free_bus_resource(struct pci_bus *bus, unsigned long type) 716 + static struct resource *find_free_bus_resource(struct pci_bus *bus, 717 + unsigned long type_mask, unsigned long type) 717 718 { 718 719 int i; 719 720 struct resource *r; 720 - unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM | 721 - IORESOURCE_PREFETCH; 722 721 723 722 pci_bus_for_each_resource(bus, r, i) { 724 723 if (r == &ioport_resource || r == &iomem_resource) ··· 814 815 resource_size_t add_size, struct list_head *realloc_head) 815 816 { 816 817 struct pci_dev *dev; 817 - struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO); 818 + struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO, 819 + IORESOURCE_IO); 818 820 resource_size_t size = 0, size0 = 0, size1 = 0; 819 821 resource_size_t children_add_size = 0; 820 822 resource_size_t min_align, align; ··· 907 907 * @bus : the bus 908 908 * @mask: mask the resource flag, then compare it with type 909 909 * @type: the type of free resource from bridge 910 + * @type2: second match type 911 + * @type3: third match type 910 912 * @min_size : the minimum memory window that must to be allocated 911 913 * @add_size : additional optional memory window 912 914 * @realloc_head : track the additional memory window on this list 913 915 * 914 916 * Calculate the size of the bus and minimal alignment which 915 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 */ 917 923 static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, 918 - unsigned long type, resource_size_t min_size, 919 - resource_size_t add_size, 920 - struct list_head *realloc_head) 924 + unsigned long type, unsigned long type2, 925 + unsigned long type3, 926 + resource_size_t min_size, resource_size_t add_size, 927 + struct list_head *realloc_head) 921 928 { 922 929 struct pci_dev *dev; 923 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 932 int order, max_order; 926 - struct resource *b_res = find_free_bus_resource(bus, type); 927 - unsigned int mem64_mask = 0; 933 + struct resource *b_res = find_free_bus_resource(bus, 934 + mask | IORESOURCE_PREFETCH, type); 928 935 resource_size_t children_add_size = 0; 929 936 930 937 if (!b_res) 931 - return 0; 938 + return -ENOSPC; 932 939 933 940 memset(aligns, 0, sizeof(aligns)); 934 941 max_order = 0; 935 942 size = 0; 936 - 937 - mem64_mask = b_res->flags & IORESOURCE_MEM_64; 938 - b_res->flags &= ~IORESOURCE_MEM_64; 939 943 940 944 list_for_each_entry(dev, &bus->devices, bus_list) { 941 945 int i; ··· 948 944 struct resource *r = &dev->resource[i]; 949 945 resource_size_t r_size; 950 946 951 - if (r->parent || (r->flags & mask) != type) 947 + if (r->parent || ((r->flags & mask) != type && 948 + (r->flags & mask) != type2 && 949 + (r->flags & mask) != type3)) 952 950 continue; 953 951 r_size = resource_size(r); 954 952 #ifdef CONFIG_PCI_IOV ··· 963 957 continue; 964 958 } 965 959 #endif 966 - /* For bridges size != alignment */ 960 + /* 961 + * aligns[0] is for 1MB (since bridge memory 962 + * windows are always at least 1MB aligned), so 963 + * keep "order" from being negative for smaller 964 + * resources. 965 + */ 967 966 align = pci_resource_alignment(dev, r); 968 967 order = __ffs(align) - 20; 969 - if (order > 11) { 968 + if (order < 0) 969 + order = 0; 970 + if (order >= ARRAY_SIZE(aligns)) { 970 971 dev_warn(&dev->dev, "disabling BAR %d: %pR " 971 972 "(bad alignment %#llx)\n", i, r, 972 973 (unsigned long long) align); ··· 981 968 continue; 982 969 } 983 970 size += r_size; 984 - if (order < 0) 985 - order = 0; 986 971 /* Exclude ranges with size > align from 987 972 calculation of the alignment. */ 988 973 if (r_size == align) 989 974 aligns[order] += align; 990 975 if (order > max_order) 991 976 max_order = order; 992 - mem64_mask &= r->flags & IORESOURCE_MEM_64; 993 977 994 978 if (realloc_head) 995 979 children_add_size += get_res_add_size(realloc_head, r); ··· 1007 997 "%pR to %pR (unused)\n", b_res, 1008 998 &bus->busn_res); 1009 999 b_res->flags = 0; 1010 - return 1; 1000 + return 0; 1011 1001 } 1012 1002 b_res->start = min_align; 1013 1003 b_res->end = size0 + min_align - 1; 1014 - b_res->flags |= IORESOURCE_STARTALIGN | mem64_mask; 1004 + b_res->flags |= IORESOURCE_STARTALIGN; 1015 1005 if (size1 > size0 && realloc_head) { 1016 1006 add_to_list(realloc_head, bus->self, b_res, size1-size0, min_align); 1017 1007 dev_printk(KERN_DEBUG, &bus->self->dev, "bridge window " 1018 1008 "%pR to %pR add_size %llx\n", b_res, 1019 1009 &bus->busn_res, (unsigned long long)size1-size0); 1020 1010 } 1021 - return 1; 1011 + return 0; 1022 1012 } 1023 1013 1024 1014 unsigned long pci_cardbus_resource_alignment(struct resource *res) ··· 1126 1116 void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) 1127 1117 { 1128 1118 struct pci_dev *dev; 1129 - unsigned long mask, prefmask; 1119 + unsigned long mask, prefmask, type2 = 0, type3 = 0; 1130 1120 resource_size_t additional_mem_size = 0, additional_io_size = 0; 1121 + struct resource *b_res; 1122 + int ret; 1131 1123 1132 1124 list_for_each_entry(dev, &bus->devices, bus_list) { 1133 1125 struct pci_bus *b = dev->subordinate; ··· 1163 1151 additional_io_size = pci_hotplug_io_size; 1164 1152 additional_mem_size = pci_hotplug_mem_size; 1165 1153 } 1166 - /* 1167 - * Follow thru 1168 - */ 1154 + /* Fall through */ 1169 1155 default: 1170 1156 pbus_size_io(bus, realloc_head ? 0 : additional_io_size, 1171 1157 additional_io_size, realloc_head); 1172 - /* If the bridge supports prefetchable range, size it 1173 - separately. If it doesn't, or its prefetchable window 1174 - has already been allocated by arch code, try 1175 - non-prefetchable range for both types of PCI memory 1176 - resources. */ 1158 + 1159 + /* 1160 + * If there's a 64-bit prefetchable MMIO window, compute 1161 + * the size required to put all 64-bit prefetchable 1162 + * resources in it. 1163 + */ 1164 + b_res = &bus->self->resource[PCI_BRIDGE_RESOURCES]; 1177 1165 mask = IORESOURCE_MEM; 1178 1166 prefmask = IORESOURCE_MEM | IORESOURCE_PREFETCH; 1179 - if (pbus_size_mem(bus, prefmask, prefmask, 1167 + if (b_res[2].flags & IORESOURCE_MEM_64) { 1168 + prefmask |= IORESOURCE_MEM_64; 1169 + ret = pbus_size_mem(bus, prefmask, prefmask, 1170 + prefmask, prefmask, 1180 1171 realloc_head ? 0 : additional_mem_size, 1181 - additional_mem_size, realloc_head)) 1182 - mask = prefmask; /* Success, size non-prefetch only. */ 1183 - else 1184 - additional_mem_size += additional_mem_size; 1185 - pbus_size_mem(bus, mask, IORESOURCE_MEM, 1172 + additional_mem_size, realloc_head); 1173 + 1174 + /* 1175 + * If successful, all non-prefetchable resources 1176 + * and any 32-bit prefetchable resources will go in 1177 + * the non-prefetchable window. 1178 + */ 1179 + if (ret == 0) { 1180 + mask = prefmask; 1181 + type2 = prefmask & ~IORESOURCE_MEM_64; 1182 + type3 = prefmask & ~IORESOURCE_PREFETCH; 1183 + } 1184 + } 1185 + 1186 + /* 1187 + * If there is no 64-bit prefetchable window, compute the 1188 + * size required to put all prefetchable resources in the 1189 + * 32-bit prefetchable window (if there is one). 1190 + */ 1191 + if (!type2) { 1192 + prefmask &= ~IORESOURCE_MEM_64; 1193 + ret = pbus_size_mem(bus, prefmask, prefmask, 1194 + prefmask, prefmask, 1195 + realloc_head ? 0 : additional_mem_size, 1196 + additional_mem_size, realloc_head); 1197 + 1198 + /* 1199 + * If successful, only non-prefetchable resources 1200 + * will go in the non-prefetchable window. 1201 + */ 1202 + if (ret == 0) 1203 + mask = prefmask; 1204 + else 1205 + additional_mem_size += additional_mem_size; 1206 + 1207 + type2 = type3 = IORESOURCE_MEM; 1208 + } 1209 + 1210 + /* 1211 + * Compute the size required to put everything else in the 1212 + * non-prefetchable window. This includes: 1213 + * 1214 + * - all non-prefetchable resources 1215 + * - 32-bit prefetchable resources if there's a 64-bit 1216 + * prefetchable window or no prefetchable window at all 1217 + * - 64-bit prefetchable resources if there's no 1218 + * prefetchable window at all 1219 + * 1220 + * Note that the strategy in __pci_assign_resource() must 1221 + * match that used here. Specifically, we cannot put a 1222 + * 32-bit prefetchable resource in a 64-bit prefetchable 1223 + * window. 1224 + */ 1225 + pbus_size_mem(bus, mask, IORESOURCE_MEM, type2, type3, 1186 1226 realloc_head ? 0 : additional_mem_size, 1187 1227 additional_mem_size, realloc_head); 1188 1228 break; ··· 1320 1256 static void pci_bridge_release_resources(struct pci_bus *bus, 1321 1257 unsigned long type) 1322 1258 { 1323 - int idx; 1324 - bool changed = false; 1325 - struct pci_dev *dev; 1259 + struct pci_dev *dev = bus->self; 1326 1260 struct resource *r; 1327 1261 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM | 1328 - IORESOURCE_PREFETCH; 1262 + IORESOURCE_PREFETCH | IORESOURCE_MEM_64; 1263 + unsigned old_flags = 0; 1264 + struct resource *b_res; 1265 + int idx = 1; 1329 1266 1330 - dev = bus->self; 1331 - for (idx = PCI_BRIDGE_RESOURCES; idx <= PCI_BRIDGE_RESOURCE_END; 1332 - idx++) { 1333 - r = &dev->resource[idx]; 1334 - if ((r->flags & type_mask) != type) 1335 - continue; 1336 - if (!r->parent) 1337 - continue; 1338 - /* 1339 - * if there are children under that, we should release them 1340 - * all 1341 - */ 1342 - release_child_resources(r); 1343 - if (!release_resource(r)) { 1344 - dev_printk(KERN_DEBUG, &dev->dev, 1345 - "resource %d %pR released\n", idx, r); 1346 - /* keep the old size */ 1347 - r->end = resource_size(r) - 1; 1348 - r->start = 0; 1349 - r->flags = 0; 1350 - changed = true; 1351 - } 1352 - } 1267 + b_res = &dev->resource[PCI_BRIDGE_RESOURCES]; 1353 1268 1354 - if (changed) { 1269 + /* 1270 + * 1. if there is io port assign fail, will release bridge 1271 + * io port. 1272 + * 2. if there is non pref mmio assign fail, release bridge 1273 + * nonpref mmio. 1274 + * 3. if there is 64bit pref mmio assign fail, and bridge pref 1275 + * is 64bit, release bridge pref mmio. 1276 + * 4. if there is pref mmio assign fail, and bridge pref is 1277 + * 32bit mmio, release bridge pref mmio 1278 + * 5. if there is pref mmio assign fail, and bridge pref is not 1279 + * assigned, release bridge nonpref mmio. 1280 + */ 1281 + if (type & IORESOURCE_IO) 1282 + idx = 0; 1283 + else if (!(type & IORESOURCE_PREFETCH)) 1284 + idx = 1; 1285 + else if ((type & IORESOURCE_MEM_64) && 1286 + (b_res[2].flags & IORESOURCE_MEM_64)) 1287 + idx = 2; 1288 + else if (!(b_res[2].flags & IORESOURCE_MEM_64) && 1289 + (b_res[2].flags & IORESOURCE_PREFETCH)) 1290 + idx = 2; 1291 + else 1292 + idx = 1; 1293 + 1294 + r = &b_res[idx]; 1295 + 1296 + if (!r->parent) 1297 + return; 1298 + 1299 + /* 1300 + * if there are children under that, we should release them 1301 + * all 1302 + */ 1303 + release_child_resources(r); 1304 + if (!release_resource(r)) { 1305 + type = old_flags = r->flags & type_mask; 1306 + dev_printk(KERN_DEBUG, &dev->dev, "resource %d %pR released\n", 1307 + PCI_BRIDGE_RESOURCES + idx, r); 1308 + /* keep the old size */ 1309 + r->end = resource_size(r) - 1; 1310 + r->start = 0; 1311 + r->flags = 0; 1312 + 1355 1313 /* avoiding touch the one without PREF */ 1356 1314 if (type & IORESOURCE_PREFETCH) 1357 1315 type = IORESOURCE_PREFETCH; 1358 1316 __pci_setup_bridge(bus, type); 1317 + /* for next child res under same bridge */ 1318 + r->flags = old_flags; 1359 1319 } 1360 1320 } 1361 1321 ··· 1558 1470 LIST_HEAD(fail_head); 1559 1471 struct pci_dev_resource *fail_res; 1560 1472 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM | 1561 - IORESOURCE_PREFETCH; 1473 + IORESOURCE_PREFETCH | IORESOURCE_MEM_64; 1562 1474 int pci_try_num = 1; 1563 1475 enum enable_type enable_local; 1564 1476
+31 -10
drivers/pci/setup-res.c
··· 208 208 209 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 218 ret = pci_bus_alloc_resource(bus, res, size, align, min, 213 - IORESOURCE_PREFETCH, 219 + IORESOURCE_PREFETCH | IORESOURCE_MEM_64, 214 220 pcibios_align_resource, dev); 221 + if (ret == 0) 222 + return 0; 215 223 216 - if (ret < 0 && (res->flags & IORESOURCE_PREFETCH)) { 217 - /* 218 - * That failed. 219 - * 220 - * But a prefetching area can handle a non-prefetching 221 - * window (it will just not perform as well). 222 - */ 224 + /* 225 + * If the prefetchable window is only 32 bits wide, we can put 226 + * 64-bit prefetchable resources in it. 227 + */ 228 + if ((res->flags & (IORESOURCE_PREFETCH | IORESOURCE_MEM_64)) == 229 + (IORESOURCE_PREFETCH | IORESOURCE_MEM_64)) { 230 + ret = pci_bus_alloc_resource(bus, res, size, align, min, 231 + IORESOURCE_PREFETCH, 232 + pcibios_align_resource, dev); 233 + if (ret == 0) 234 + return 0; 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)) 223 244 ret = pci_bus_alloc_resource(bus, res, size, align, min, 0, 224 245 pcibios_align_resource, dev); 225 - } 246 + 226 247 return ret; 227 248 } 228 249
+5 -8
include/asm-generic/dma-coherent.h
··· 16 16 * Standard interface 17 17 */ 18 18 #define ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY 19 - extern int 20 - dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, 21 - dma_addr_t device_addr, size_t size, int flags); 19 + int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, 20 + dma_addr_t device_addr, size_t size, int flags); 22 21 23 - extern void 24 - dma_release_declared_memory(struct device *dev); 22 + void dma_release_declared_memory(struct device *dev); 25 23 26 - extern void * 27 - dma_mark_declared_memory_occupied(struct device *dev, 28 - dma_addr_t device_addr, size_t size); 24 + void *dma_mark_declared_memory_occupied(struct device *dev, 25 + dma_addr_t device_addr, size_t size); 29 26 #else 30 27 #define dma_alloc_from_coherent(dev, size, handle, ret) (0) 31 28 #define dma_release_from_coherent(dev, order, vaddr) (0)
+10 -3
include/linux/dma-mapping.h
··· 8 8 #include <linux/dma-direction.h> 9 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 + */ 11 17 struct dma_map_ops { 12 18 void* (*alloc)(struct device *dev, size_t size, 13 19 dma_addr_t *dma_handle, gfp_t gfp, ··· 192 186 193 187 #ifndef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY 194 188 static inline int 195 - dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, 189 + dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, 196 190 dma_addr_t device_addr, size_t size, int flags) 197 191 { 198 192 return 0; ··· 223 217 extern void dmam_free_noncoherent(struct device *dev, size_t size, void *vaddr, 224 218 dma_addr_t dma_handle); 225 219 #ifdef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY 226 - extern int dmam_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, 220 + extern int dmam_declare_coherent_memory(struct device *dev, 221 + phys_addr_t phys_addr, 227 222 dma_addr_t device_addr, size_t size, 228 223 int flags); 229 224 extern void dmam_release_declared_memory(struct device *dev); 230 225 #else /* ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY */ 231 226 static inline int dmam_declare_coherent_memory(struct device *dev, 232 - dma_addr_t bus_addr, dma_addr_t device_addr, 227 + phys_addr_t phys_addr, dma_addr_t device_addr, 233 228 size_t size, gfp_t gfp) 234 229 { 235 230 return 0;
+1 -5
include/linux/pci.h
··· 1158 1158 1159 1159 #ifdef CONFIG_PCI_MSI 1160 1160 int pci_msi_vec_count(struct pci_dev *dev); 1161 - int pci_enable_msi_block(struct pci_dev *dev, int nvec); 1162 1161 void pci_msi_shutdown(struct pci_dev *dev); 1163 1162 void pci_disable_msi(struct pci_dev *dev); 1164 1163 int pci_msix_vec_count(struct pci_dev *dev); ··· 1187 1188 } 1188 1189 #else 1189 1190 static inline int pci_msi_vec_count(struct pci_dev *dev) { return -ENOSYS; } 1190 - static inline int pci_enable_msi_block(struct pci_dev *dev, int nvec) 1191 - { return -ENOSYS; } 1192 1191 static inline void pci_msi_shutdown(struct pci_dev *dev) { } 1193 1192 static inline void pci_disable_msi(struct pci_dev *dev) { } 1194 1193 static inline int pci_msix_vec_count(struct pci_dev *dev) { return -ENOSYS; } ··· 1241 1244 static inline void pcie_ecrc_get_policy(char *str) { } 1242 1245 #endif 1243 1246 1244 - #define pci_enable_msi(pdev) pci_enable_msi_block(pdev, 1) 1247 + #define pci_enable_msi(pdev) pci_enable_msi_exact(pdev, 1) 1245 1248 1246 1249 #ifdef CONFIG_HT_IRQ 1247 1250 /* The functions a driver should call */ ··· 1569 1572 extern unsigned long pci_hotplug_mem_size; 1570 1573 1571 1574 /* Architecture-specific versions may override these (weak) */ 1572 - int pcibios_add_platform_entries(struct pci_dev *dev); 1573 1575 void pcibios_disable_device(struct pci_dev *dev); 1574 1576 void pcibios_set_master(struct pci_dev *dev); 1575 1577 int pcibios_set_pcie_reset_state(struct pci_dev *dev,
+1
include/linux/types.h
··· 142 142 #define pgoff_t unsigned long 143 143 #endif 144 144 145 + /* A dma_addr_t can hold any valid DMA or bus address for the platform */ 145 146 #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT 146 147 typedef u64 dma_addr_t; 147 148 #else
+2 -5
kernel/resource.c
··· 1288 1288 if (p->flags & IORESOURCE_BUSY) 1289 1289 continue; 1290 1290 1291 - printk(KERN_WARNING "resource map sanity check conflict: " 1292 - "0x%llx 0x%llx 0x%llx 0x%llx %s\n", 1291 + printk(KERN_WARNING "resource sanity check: requesting [mem %#010llx-%#010llx], which spans more than %s %pR\n", 1293 1292 (unsigned long long)addr, 1294 1293 (unsigned long long)(addr + size - 1), 1295 - (unsigned long long)p->start, 1296 - (unsigned long long)p->end, 1297 - p->name); 1294 + p->name, p); 1298 1295 err = -1; 1299 1296 break; 1300 1297 }