Back to home page

LXR

 
 

    


0001 The io_mapping functions in linux/io-mapping.h provide an abstraction for
0002 efficiently mapping small regions of an I/O device to the CPU. The initial
0003 usage is to support the large graphics aperture on 32-bit processors where
0004 ioremap_wc cannot be used to statically map the entire aperture to the CPU
0005 as it would consume too much of the kernel address space.
0006 
0007 A mapping object is created during driver initialization using
0008 
0009         struct io_mapping *io_mapping_create_wc(unsigned long base,
0010                                                 unsigned long size)
0011 
0012                 'base' is the bus address of the region to be made
0013                 mappable, while 'size' indicates how large a mapping region to
0014                 enable. Both are in bytes.
0015 
0016                 This _wc variant provides a mapping which may only be used
0017                 with the io_mapping_map_atomic_wc or io_mapping_map_wc.
0018 
0019 With this mapping object, individual pages can be mapped either atomically
0020 or not, depending on the necessary scheduling environment. Of course, atomic
0021 maps are more efficient:
0022 
0023         void *io_mapping_map_atomic_wc(struct io_mapping *mapping,
0024                                        unsigned long offset)
0025 
0026                 'offset' is the offset within the defined mapping region.
0027                 Accessing addresses beyond the region specified in the
0028                 creation function yields undefined results. Using an offset
0029                 which is not page aligned yields an undefined result. The
0030                 return value points to a single page in CPU address space.
0031 
0032                 This _wc variant returns a write-combining map to the
0033                 page and may only be used with mappings created by
0034                 io_mapping_create_wc
0035 
0036                 Note that the task may not sleep while holding this page
0037                 mapped.
0038 
0039         void io_mapping_unmap_atomic(void *vaddr)
0040 
0041                 'vaddr' must be the value returned by the last
0042                 io_mapping_map_atomic_wc call. This unmaps the specified
0043                 page and allows the task to sleep once again.
0044 
0045 If you need to sleep while holding the lock, you can use the non-atomic
0046 variant, although they may be significantly slower.
0047 
0048         void *io_mapping_map_wc(struct io_mapping *mapping,
0049                                 unsigned long offset)
0050 
0051                 This works like io_mapping_map_atomic_wc except it allows
0052                 the task to sleep while holding the page mapped.
0053 
0054         void io_mapping_unmap(void *vaddr)
0055 
0056                 This works like io_mapping_unmap_atomic, except it is used
0057                 for pages mapped with io_mapping_map_wc.
0058 
0059 At driver close time, the io_mapping object must be freed:
0060 
0061         void io_mapping_free(struct io_mapping *mapping)
0062 
0063 Current Implementation:
0064 
0065 The initial implementation of these functions uses existing mapping
0066 mechanisms and so provides only an abstraction layer and no new
0067 functionality.
0068 
0069 On 64-bit processors, io_mapping_create_wc calls ioremap_wc for the whole
0070 range, creating a permanent kernel-visible mapping to the resource. The
0071 map_atomic and map functions add the requested offset to the base of the
0072 virtual address returned by ioremap_wc.
0073 
0074 On 32-bit processors with HIGHMEM defined, io_mapping_map_atomic_wc uses
0075 kmap_atomic_pfn to map the specified page in an atomic fashion;
0076 kmap_atomic_pfn isn't really supposed to be used with device pages, but it
0077 provides an efficient mapping for this usage.
0078 
0079 On 32-bit processors without HIGHMEM defined, io_mapping_map_atomic_wc and
0080 io_mapping_map_wc both use ioremap_wc, a terribly inefficient function which
0081 performs an IPI to inform all processors about the new mapping. This results
0082 in a significant performance penalty.