pat.txt 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. PAT (Page Attribute Table)
  2. x86 Page Attribute Table (PAT) allows for setting the memory attribute at the
  3. page level granularity. PAT is complementary to the MTRR settings which allows
  4. for setting of memory types over physical address ranges. However, PAT is
  5. more flexible than MTRR due to its capability to set attributes at page level
  6. and also due to the fact that there are no hardware limitations on number of
  7. such attribute settings allowed. Added flexibility comes with guidelines for
  8. not having memory type aliasing for the same physical memory with multiple
  9. virtual addresses.
  10. PAT allows for different types of memory attributes. The most commonly used
  11. ones that will be supported at this time are Write-back, Uncached,
  12. Write-combined and Uncached Minus.
  13. PAT APIs
  14. --------
  15. There are many different APIs in the kernel that allows setting of memory
  16. attributes at the page level. In order to avoid aliasing, these interfaces
  17. should be used thoughtfully. Below is a table of interfaces available,
  18. their intended usage and their memory attribute relationships. Internally,
  19. these APIs use a reserve_memtype()/free_memtype() interface on the physical
  20. address range to avoid any aliasing.
  21. -------------------------------------------------------------------
  22. API | RAM | ACPI,... | Reserved/Holes |
  23. -----------------------|----------|------------|------------------|
  24. | | | |
  25. ioremap | -- | UC- | UC- |
  26. | | | |
  27. ioremap_cache | -- | WB | WB |
  28. | | | |
  29. ioremap_nocache | -- | UC- | UC- |
  30. | | | |
  31. ioremap_wc | -- | -- | WC |
  32. | | | |
  33. set_memory_uc | UC- | -- | -- |
  34. set_memory_wb | | | |
  35. | | | |
  36. set_memory_wc | WC | -- | -- |
  37. set_memory_wb | | | |
  38. | | | |
  39. pci sysfs resource | -- | -- | UC- |
  40. | | | |
  41. pci sysfs resource_wc | -- | -- | WC |
  42. is IORESOURCE_PREFETCH| | | |
  43. | | | |
  44. pci proc | -- | -- | UC- |
  45. !PCIIOC_WRITE_COMBINE | | | |
  46. | | | |
  47. pci proc | -- | -- | WC |
  48. PCIIOC_WRITE_COMBINE | | | |
  49. | | | |
  50. /dev/mem | -- | WB/WC/UC- | WB/WC/UC- |
  51. read-write | | | |
  52. | | | |
  53. /dev/mem | -- | UC- | UC- |
  54. mmap SYNC flag | | | |
  55. | | | |
  56. /dev/mem | -- | WB/WC/UC- | WB/WC/UC- |
  57. mmap !SYNC flag | |(from exist-| (from exist- |
  58. and | | ing alias)| ing alias) |
  59. any alias to this area| | | |
  60. | | | |
  61. /dev/mem | -- | WB | WB |
  62. mmap !SYNC flag | | | |
  63. no alias to this area | | | |
  64. and | | | |
  65. MTRR says WB | | | |
  66. | | | |
  67. /dev/mem | -- | -- | UC- |
  68. mmap !SYNC flag | | | |
  69. no alias to this area | | | |
  70. and | | | |
  71. MTRR says !WB | | | |
  72. | | | |
  73. -------------------------------------------------------------------
  74. Notes:
  75. -- in the above table mean "Not suggested usage for the API". Some of the --'s
  76. are strictly enforced by the kernel. Some others are not really enforced
  77. today, but may be enforced in future.
  78. For ioremap and pci access through /sys or /proc - The actual type returned
  79. can be more restrictive, in case of any existing aliasing for that address.
  80. For example: If there is an existing uncached mapping, a new ioremap_wc can
  81. return uncached mapping in place of write-combine requested.
  82. set_memory_[uc|wc] and set_memory_wb should be used in pairs, where driver will
  83. first make a region uc or wc and switch it back to wb after use.
  84. Over time writes to /proc/mtrr will be deprecated in favor of using PAT based
  85. interfaces. Users writing to /proc/mtrr are suggested to use above interfaces.
  86. Drivers should use ioremap_[uc|wc] to access PCI BARs with [uc|wc] access
  87. types.
  88. Drivers should use set_memory_[uc|wc] to set access type for RAM ranges.
  89. PAT debugging
  90. -------------
  91. With CONFIG_DEBUG_FS enabled, PAT memtype list can be examined by
  92. # mount -t debugfs debugfs /sys/kernel/debug
  93. # cat /sys/kernel/debug/x86/pat_memtype_list
  94. PAT memtype list:
  95. uncached-minus @ 0x7fadf000-0x7fae0000
  96. uncached-minus @ 0x7fb19000-0x7fb1a000
  97. uncached-minus @ 0x7fb1a000-0x7fb1b000
  98. uncached-minus @ 0x7fb1b000-0x7fb1c000
  99. uncached-minus @ 0x7fb1c000-0x7fb1d000
  100. uncached-minus @ 0x7fb1d000-0x7fb1e000
  101. uncached-minus @ 0x7fb1e000-0x7fb25000
  102. uncached-minus @ 0x7fb25000-0x7fb26000
  103. uncached-minus @ 0x7fb26000-0x7fb27000
  104. uncached-minus @ 0x7fb27000-0x7fb28000
  105. uncached-minus @ 0x7fb28000-0x7fb2e000
  106. uncached-minus @ 0x7fb2e000-0x7fb2f000
  107. uncached-minus @ 0x7fb2f000-0x7fb30000
  108. uncached-minus @ 0x7fb31000-0x7fb32000
  109. uncached-minus @ 0x80000000-0x90000000
  110. This list shows physical address ranges and various PAT settings used to
  111. access those physical address ranges.
  112. Another, more verbose way of getting PAT related debug messages is with
  113. "debugpat" boot parameter. With this parameter, various debug messages are
  114. printed to dmesg log.