coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
pgtbl.c File Reference
#include <cbfs.h>
#include <commonlib/helpers.h>
#include <console/console.h>
#include <arch/cpu.h>
#include <cpu/x86/cr.h>
#include <cpu/x86/msr.h>
#include <cpu/x86/pae.h>
#include <string.h>
#include <symbols.h>
#include <assert.h>
Include dependency graph for pgtbl.c:

Go to the source code of this file.

Data Structures

struct  pde
 
struct  pg_table
 

Macros

#define PDPTE_PRES   (1ULL << 0)
 
#define PDPTE_ADDR_MASK   (~((1ULL << 12) - 1))
 
#define PDE_PRES   (1ULL << 0)
 
#define PDE_RW   (1ULL << 1)
 
#define PDE_US   (1ULL << 2)
 
#define PDE_PWT   (1ULL << 3)
 
#define PDE_PCD   (1ULL << 4)
 
#define PDE_A   (1ULL << 5)
 
#define PDE_D   (1ULL << 6)
 
#define PDE_PS   (1ULL << 7)
 
#define PDE_G   (1ULL << 8)
 
#define PDE_PAT   (1ULL << 12)
 
#define PDE_XD   (1ULL << 63)
 
#define PDE_ADDR_MASK   (~((1ULL << 12) - 1))
 
#define PTE_PRES   (1ULL << 0)
 
#define PTE_RW   (1ULL << 1)
 
#define PTE_US   (1ULL << 2)
 
#define PTE_PWT   (1ULL << 3)
 
#define PTE_PCD   (1ULL << 4)
 
#define PTE_A   (1ULL << 5)
 
#define PTE_D   (1ULL << 6)
 
#define PTE_PAT   (1ULL << 7)
 
#define PTE_G   (1ULL << 8)
 
#define PTE_XD   (1ULL << 63)
 
#define PDPTE_IDX_SHIFT   30
 
#define PDPTE_IDX_MASK   0x3
 
#define PDE_IDX_SHIFT   21
 
#define PDE_IDX_MASK   0x1ff
 
#define PTE_IDX_SHIFT   12
 
#define PTE_IDX_MASK   0x1ff
 
#define OVERLAP(a, b, s, e)   ((b) > (s) && (a) < (e))
 

Functions

void paging_enable_pae_cr3 (uintptr_t cr3)
 
void paging_enable_pae (void)
 
void paging_disable_pae (void)
 
int memset_pae (uint64_t dest, unsigned char pat, uint64_t length, void *pgtbl, void *vmem_addr)
 
void paging_set_nxe (int enable)
 
void paging_set_pat (uint64_t pat)
 
void paging_set_default_pat (void)
 
int paging_enable_for_car (const char *pdpt_name, const char *pt_name)
 
static voidget_pdpt_addr (void)
 
static uint64_t pde_pat_flags (int pat)
 
static uint64_t pde_page_flags (int pat)
 
static uint64_t pte_pat_flags (int pat)
 
static uint64_t pte_page_flags (int pat)
 
static int identity_map_one_page (uintptr_t base, size_t size, int pat, int commit)
 
static int _paging_identity_map_addr (uintptr_t base, size_t size, int pat, int commit)
 
static int paging_is_enabled (void)
 
int paging_identity_map_addr (uintptr_t base, size_t size, int pat)
 

Variables

static const size_t s2MiB = 2 * MiB
 
static const size_t s4KiB = 4 * KiB
 
struct pde __packed
 

Macro Definition Documentation

◆ OVERLAP

#define OVERLAP (   a,
  b,
  s,
 
)    ((b) > (s) && (a) < (e))

Definition at line 50 of file pgtbl.c.

◆ PDE_A

#define PDE_A   (1ULL << 5)

Definition at line 22 of file pgtbl.c.

◆ PDE_ADDR_MASK

#define PDE_ADDR_MASK   (~((1ULL << 12) - 1))

Definition at line 28 of file pgtbl.c.

◆ PDE_D

#define PDE_D   (1ULL << 6)

Definition at line 23 of file pgtbl.c.

◆ PDE_G

#define PDE_G   (1ULL << 8)

Definition at line 25 of file pgtbl.c.

◆ PDE_IDX_MASK

#define PDE_IDX_MASK   0x1ff

Definition at line 45 of file pgtbl.c.

◆ PDE_IDX_SHIFT

#define PDE_IDX_SHIFT   21

Definition at line 44 of file pgtbl.c.

◆ PDE_PAT

#define PDE_PAT   (1ULL << 12)

Definition at line 26 of file pgtbl.c.

◆ PDE_PCD

#define PDE_PCD   (1ULL << 4)

Definition at line 21 of file pgtbl.c.

◆ PDE_PRES

#define PDE_PRES   (1ULL << 0)

Definition at line 17 of file pgtbl.c.

◆ PDE_PS

#define PDE_PS   (1ULL << 7)

Definition at line 24 of file pgtbl.c.

◆ PDE_PWT

#define PDE_PWT   (1ULL << 3)

Definition at line 20 of file pgtbl.c.

◆ PDE_RW

#define PDE_RW   (1ULL << 1)

Definition at line 18 of file pgtbl.c.

◆ PDE_US

#define PDE_US   (1ULL << 2)

Definition at line 19 of file pgtbl.c.

◆ PDE_XD

#define PDE_XD   (1ULL << 63)

Definition at line 27 of file pgtbl.c.

◆ PDPTE_ADDR_MASK

#define PDPTE_ADDR_MASK   (~((1ULL << 12) - 1))

Definition at line 15 of file pgtbl.c.

◆ PDPTE_IDX_MASK

#define PDPTE_IDX_MASK   0x3

Definition at line 42 of file pgtbl.c.

◆ PDPTE_IDX_SHIFT

#define PDPTE_IDX_SHIFT   30

Definition at line 41 of file pgtbl.c.

◆ PDPTE_PRES

#define PDPTE_PRES   (1ULL << 0)

Definition at line 14 of file pgtbl.c.

◆ PTE_A

#define PTE_A   (1ULL << 5)

Definition at line 35 of file pgtbl.c.

◆ PTE_D

#define PTE_D   (1ULL << 6)

Definition at line 36 of file pgtbl.c.

◆ PTE_G

#define PTE_G   (1ULL << 8)

Definition at line 38 of file pgtbl.c.

◆ PTE_IDX_MASK

#define PTE_IDX_MASK   0x1ff

Definition at line 48 of file pgtbl.c.

◆ PTE_IDX_SHIFT

#define PTE_IDX_SHIFT   12

Definition at line 47 of file pgtbl.c.

◆ PTE_PAT

#define PTE_PAT   (1ULL << 7)

Definition at line 37 of file pgtbl.c.

◆ PTE_PCD

#define PTE_PCD   (1ULL << 4)

Definition at line 34 of file pgtbl.c.

◆ PTE_PRES

#define PTE_PRES   (1ULL << 0)

Definition at line 30 of file pgtbl.c.

◆ PTE_PWT

#define PTE_PWT   (1ULL << 3)

Definition at line 33 of file pgtbl.c.

◆ PTE_RW

#define PTE_RW   (1ULL << 1)

Definition at line 31 of file pgtbl.c.

◆ PTE_US

#define PTE_US   (1ULL << 2)

Definition at line 32 of file pgtbl.c.

◆ PTE_XD

#define PTE_XD   (1ULL << 63)

Definition at line 39 of file pgtbl.c.

Function Documentation

◆ _paging_identity_map_addr()

static int _paging_identity_map_addr ( uintptr_t  base,
size_t  size,
int  pat,
int  commit 
)
static

Definition at line 470 of file pgtbl.c.

References base, identity_map_one_page(), IS_ALIGNED, MIN, s2MiB, and s4KiB.

Referenced by paging_identity_map_addr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_pdpt_addr()

static void* get_pdpt_addr ( void  )
static

Definition at line 344 of file pgtbl.c.

References preram_symbols_available(), and read_cr3().

Referenced by identity_map_one_page().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ identity_map_one_page()

static int identity_map_one_page ( uintptr_t  base,
size_t  size,
int  pat,
int  commit 
)
static

Definition at line 409 of file pgtbl.c.

References base, BIOS_ERR, get_pdpt_addr(), PDE_ADDR_MASK, PDE_IDX_MASK, PDE_IDX_SHIFT, pde_page_flags(), PDE_PRES, PDE_PS, PDPTE_ADDR_MASK, PDPTE_IDX_MASK, PDPTE_IDX_SHIFT, PDPTE_PRES, printk, PTE_IDX_MASK, PTE_IDX_SHIFT, pte_page_flags(), s2MiB, and s4KiB.

Referenced by _paging_identity_map_addr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ memset_pae()

int memset_pae ( uint64_t  dest,
unsigned char  pat,
uint64_t  length,
void pgtbl,
void vmem_addr 
)

◆ paging_disable_pae()

void paging_disable_pae ( void  )

Definition at line 87 of file pgtbl.c.

References CR0_PG, CR4_PAE, CRx_TYPE, read_cr0(), read_cr4(), write_cr0(), and write_cr4().

Referenced by memset_pae().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ paging_enable_for_car()

int paging_enable_for_car ( const char *  pdpt_name,
const char *  pt_name 
)

Definition at line 324 of file pgtbl.c.

References BIOS_ERR, cbfs_load(), paging_enable_pae_cr3(), preram_symbols_available(), printk, and REGION_SIZE.

Referenced by bootblock_soc_early_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ paging_enable_pae()

void paging_enable_pae ( void  )

Definition at line 71 of file pgtbl.c.

References CR0_PG, CR4_PAE, CRx_TYPE, read_cr0(), read_cr4(), write_cr0(), and write_cr4().

Referenced by paging_enable_pae_cr3().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ paging_enable_pae_cr3()

void paging_enable_pae_cr3 ( uintptr_t  cr3)

Definition at line 64 of file pgtbl.c.

References paging_enable_pae(), and write_cr3().

Referenced by memset_pae(), and paging_enable_for_car().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ paging_identity_map_addr()

int paging_identity_map_addr ( uintptr_t  base,
size_t  size,
int  pat 
)

Definition at line 494 of file pgtbl.c.

References _paging_identity_map_addr(), base, BIOS_ERR, IS_ALIGNED, paging_is_enabled(), printk, s2MiB, and s4KiB.

Here is the call graph for this function:

◆ paging_is_enabled()

static int paging_is_enabled ( void  )
static

Definition at line 489 of file pgtbl.c.

References CR0_PG, and read_cr0().

Referenced by paging_identity_map_addr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ paging_set_default_pat()

void paging_set_default_pat ( void  )

Definition at line 315 of file pgtbl.c.

References paging_set_pat(), PAT_ENCODE, UC, WB, WC, WP, and WT.

Referenced by bootblock_soc_early_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ paging_set_nxe()

void paging_set_nxe ( int  enable)

Definition at line 279 of file pgtbl.c.

References EFER_NXE, IA32_EFER, msr_struct::lo, rdmsr(), and wrmsr().

Referenced by bootblock_soc_early_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ paging_set_pat()

void paging_set_pat ( uint64_t  pat)

Definition at line 291 of file pgtbl.c.

References msr_struct::hi, IA32_PAT, msr_struct::lo, and wrmsr().

Referenced by paging_set_default_pat().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pde_page_flags()

static uint64_t pde_page_flags ( int  pat)
static

Definition at line 372 of file pgtbl.c.

References PDE_A, PDE_D, pde_pat_flags(), PDE_PRES, PDE_PS, and PDE_RW.

Referenced by identity_map_one_page().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pde_pat_flags()

static uint64_t pde_pat_flags ( int  pat)
static

Definition at line 351 of file pgtbl.c.

References BIOS_ERR, PAT_UC, PAT_UC_MINUS, PAT_WB, PAT_WC, PAT_WP, PAT_WT, PDE_PAT, PDE_PCD, PDE_PWT, and printk.

Referenced by pde_page_flags().

Here is the caller graph for this function:

◆ pte_page_flags()

static uint64_t pte_page_flags ( int  pat)
static

Definition at line 400 of file pgtbl.c.

References PTE_A, PTE_D, pte_pat_flags(), PTE_PRES, and PTE_RW.

Referenced by identity_map_one_page().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pte_pat_flags()

static uint64_t pte_pat_flags ( int  pat)
static

Definition at line 379 of file pgtbl.c.

References BIOS_ERR, PAT_UC, PAT_UC_MINUS, PAT_WB, PAT_WC, PAT_WP, PAT_WT, printk, PTE_PAT, PTE_PCD, and PTE_PWT.

Referenced by pte_page_flags().

Here is the caller graph for this function:

Variable Documentation

◆ __packed

◆ s2MiB

const size_t s2MiB = 2 * MiB
static

◆ s4KiB

const size_t s4KiB = 4 * KiB
static