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