MCPcopy Create free account
hub / github.com/F-Stack/f-stack / pmap_init_pat

Function pmap_init_pat

freebsd/amd64/amd64/pmap.c:1937–1998  ·  view source on GitHub ↗

* Setup the PAT MSR. */

Source from the content-addressed store, hash-verified

1935 * Setup the PAT MSR.
1936 */
1937void
1938pmap_init_pat(void)
1939{
1940 uint64_t pat_msr;
1941 u_long cr0, cr4;
1942 int i;
1943
1944 /* Bail if this CPU doesn't implement PAT. */
1945 if ((cpu_feature & CPUID_PAT) == 0)
1946 panic("no PAT??");
1947
1948 /* Set default PAT index table. */
1949 for (i = 0; i < PAT_INDEX_SIZE; i++)
1950 pat_index[i] = -1;
1951 pat_index[PAT_WRITE_BACK] = 0;
1952 pat_index[PAT_WRITE_THROUGH] = 1;
1953 pat_index[PAT_UNCACHEABLE] = 3;
1954 pat_index[PAT_WRITE_COMBINING] = 6;
1955 pat_index[PAT_WRITE_PROTECTED] = 5;
1956 pat_index[PAT_UNCACHED] = 2;
1957
1958 /*
1959 * Initialize default PAT entries.
1960 * Leave the indices 0-3 at the default of WB, WT, UC-, and UC.
1961 * Program 5 and 6 as WP and WC.
1962 *
1963 * Leave 4 and 7 as WB and UC. Note that a recursive page table
1964 * mapping for a 2M page uses a PAT value with the bit 3 set due
1965 * to its overload with PG_PS.
1966 */
1967 pat_msr = PAT_VALUE(0, PAT_WRITE_BACK) |
1968 PAT_VALUE(1, PAT_WRITE_THROUGH) |
1969 PAT_VALUE(2, PAT_UNCACHED) |
1970 PAT_VALUE(3, PAT_UNCACHEABLE) |
1971 PAT_VALUE(4, PAT_WRITE_BACK) |
1972 PAT_VALUE(5, PAT_WRITE_PROTECTED) |
1973 PAT_VALUE(6, PAT_WRITE_COMBINING) |
1974 PAT_VALUE(7, PAT_UNCACHEABLE);
1975
1976 /* Disable PGE. */
1977 cr4 = rcr4();
1978 load_cr4(cr4 & ~CR4_PGE);
1979
1980 /* Disable caches (CD = 1, NW = 0). */
1981 cr0 = rcr0();
1982 load_cr0((cr0 & ~CR0_NW) | CR0_CD);
1983
1984 /* Flushes caches and TLBs. */
1985 wbinvd();
1986 invltlb();
1987
1988 /* Update PAT and index table. */
1989 wrmsr(MSR_PAT, pat_msr);
1990
1991 /* Flush caches and TLBs again. */
1992 wbinvd();
1993 invltlb();
1994

Callers 4

pmap_bootstrapFunction · 0.70
acpi_wakeup_machdepFunction · 0.50
init_secondary_tailFunction · 0.50
cpususpend_handlerFunction · 0.50

Calls 8

panicFunction · 0.50
rcr4Function · 0.50
load_cr4Function · 0.50
rcr0Function · 0.50
load_cr0Function · 0.50
wbinvdFunction · 0.50
invltlbFunction · 0.50
wrmsrFunction · 0.50

Tested by

no test coverage detected