io-mapping.rst 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ========================
  2. The io_mapping functions
  3. ========================
  4. API
  5. ===
  6. The io_mapping functions in linux/io-mapping.h provide an abstraction for
  7. efficiently mapping small regions of an I/O device to the CPU. The initial
  8. usage is to support the large graphics aperture on 32-bit processors where
  9. ioremap_wc cannot be used to statically map the entire aperture to the CPU
  10. as it would consume too much of the kernel address space.
  11. A mapping object is created during driver initialization using::
  12. struct io_mapping *io_mapping_create_wc(unsigned long base,
  13. unsigned long size)
  14. 'base' is the bus address of the region to be made
  15. mappable, while 'size' indicates how large a mapping region to
  16. enable. Both are in bytes.
  17. This _wc variant provides a mapping which may only be used
  18. with the io_mapping_map_atomic_wc or io_mapping_map_wc.
  19. With this mapping object, individual pages can be mapped either atomically
  20. or not, depending on the necessary scheduling environment. Of course, atomic
  21. maps are more efficient::
  22. void *io_mapping_map_atomic_wc(struct io_mapping *mapping,
  23. unsigned long offset)
  24. 'offset' is the offset within the defined mapping region.
  25. Accessing addresses beyond the region specified in the
  26. creation function yields undefined results. Using an offset
  27. which is not page aligned yields an undefined result. The
  28. return value points to a single page in CPU address space.
  29. This _wc variant returns a write-combining map to the
  30. page and may only be used with mappings created by
  31. io_mapping_create_wc
  32. Note that the task may not sleep while holding this page
  33. mapped.
  34. ::
  35. void io_mapping_unmap_atomic(void *vaddr)
  36. 'vaddr' must be the value returned by the last
  37. io_mapping_map_atomic_wc call. This unmaps the specified
  38. page and allows the task to sleep once again.
  39. If you need to sleep while holding the lock, you can use the non-atomic
  40. variant, although they may be significantly slower.
  41. ::
  42. void *io_mapping_map_wc(struct io_mapping *mapping,
  43. unsigned long offset)
  44. This works like io_mapping_map_atomic_wc except it allows
  45. the task to sleep while holding the page mapped.
  46. ::
  47. void io_mapping_unmap(void *vaddr)
  48. This works like io_mapping_unmap_atomic, except it is used
  49. for pages mapped with io_mapping_map_wc.
  50. At driver close time, the io_mapping object must be freed::
  51. void io_mapping_free(struct io_mapping *mapping)
  52. Current Implementation
  53. ======================
  54. The initial implementation of these functions uses existing mapping
  55. mechanisms and so provides only an abstraction layer and no new
  56. functionality.
  57. On 64-bit processors, io_mapping_create_wc calls ioremap_wc for the whole
  58. range, creating a permanent kernel-visible mapping to the resource. The
  59. map_atomic and map functions add the requested offset to the base of the
  60. virtual address returned by ioremap_wc.
  61. On 32-bit processors with HIGHMEM defined, io_mapping_map_atomic_wc uses
  62. kmap_atomic_pfn to map the specified page in an atomic fashion;
  63. kmap_atomic_pfn isn't really supposed to be used with device pages, but it
  64. provides an efficient mapping for this usage.
  65. On 32-bit processors without HIGHMEM defined, io_mapping_map_atomic_wc and
  66. io_mapping_map_wc both use ioremap_wc, a terribly inefficient function which
  67. performs an IPI to inform all processors about the new mapping. This results
  68. in a significant performance penalty.