MOS Source Code
Loading...
Searching...
No Matches
Physical Memory Manager

Allocate/free the physical memory, in the form of physical frames. More...

+ Collaboration diagram for Physical Memory Manager:

Classes

struct  phyframe_t
 
struct  pmm_region_t
 

Macros

#define phyframe_pfn(frame)
 
#define pfn_phyframe(pfn)
 
#define pmm_reserve_address(paddr)
 
#define pmm_reserve_addresses(paddr, npages)
 
#define pmm_ref(thing, npages)
 
#define pmm_unref(thing, npages)
 
#define pmm_ref_one(thing)
 
#define pmm_unref_one(thing)
 

Typedefs

typedef struct phyframe phyframe_t
 

Enumerations

enum  pmm_allocation_flags_t { PMM_ALLOC_NORMAL = 0 }
 

Functions

 MOS_STATIC_ASSERT (sizeof(phyframe_t)==32, "update phyframe_t struct size")
 
void pmm_dump_lists (void)
 Dump the physical memory manager's state, (i.e. the free list and the allocated list).
 
void pmm_init ()
 
phyframe_tpmm_allocate_frames (size_t n_frames, pmm_allocation_flags_t flags)
 Allocate n_frames of contiguous physical memory.
 
void pmm_free_frames (phyframe_t *start_frame, size_t n_pages)
 
pfn_t pmm_reserve_frames (pfn_t pfn, size_t npages)
 Mark a range of physical memory as reserved.
 
pmm_region_tpmm_find_reserved_region (ptr_t needle)
 Find a region in the physical memory manager.
 
phyframe_t_pmm_ref_phyframes (phyframe_t *frame, size_t npages)
 
void _pmm_unref_phyframes (phyframe_t *frame, size_t npages)
 
should_inline pfn_t _pmm_ref_pfn_range (pfn_t pfn_start, size_t npages)
 
should_inline void _pmm_unref_pfn_range (pfn_t pfn_start, size_t npages)
 

Variables

phyframe_tphyframes
 
size_t pmm_total_frames
 
size_t pmm_allocated_frames
 
size_t pmm_reserved_frames
 

Detailed Description

Allocate/free the physical memory, in the form of physical frames.

The physical memory manager is responsible for allocating and freeing physical memory.

Note
The allocated physical memory is not zeroed out, in fact, it does nothing to the real memory content except for marking it as allocated.

Macro Definition Documentation

◆ phyframe_pfn

#define phyframe_pfn ( frame)

◆ pfn_phyframe

◆ pmm_reserve_address

#define pmm_reserve_address ( paddr)
Value:
#define MOS_PAGE_SIZE
Definition autoconf.h:6
pfn_t pmm_reserve_frames(pfn_t pfn, size_t npages)
Mark a range of physical memory as reserved.
Definition pmm.c:122
#define ALIGN_DOWN_TO_PAGE(addr)
Definition mos_global.h:76

Definition at line 116 of file pmm.h.

Referenced by ioapic_init(), and lapic_memory_setup().

◆ pmm_reserve_addresses

#define pmm_reserve_addresses ( paddr,
npages )
Value:

Definition at line 117 of file pmm.h.

◆ pmm_ref

#define pmm_ref ( thing,
npages )
Value:
_Generic((thing), phyframe_t *: _pmm_ref_phyframes, pfn_t: _pmm_ref_pfn_range)(thing, npages)
phyframe_t * _pmm_ref_phyframes(phyframe_t *frame, size_t npages)
Definition pmm.c:151
should_inline pfn_t _pmm_ref_pfn_range(pfn_t pfn_start, size_t npages)
Definition pmm.h:132

Definition at line 143 of file pmm.h.

Referenced by dmabuf_do_allocate(), mos_start_kernel(), register_sysfs_acpi_node(), and register_sysfs_acpi_rsdp().

◆ pmm_unref

#define pmm_unref ( thing,
npages )
Value:
_Generic((thing), phyframe_t *: _pmm_unref_phyframes, pfn_t: _pmm_unref_pfn_range)(thing, npages)
void _pmm_unref_phyframes(phyframe_t *frame, size_t npages)
Definition pmm.c:162
should_inline void _pmm_unref_pfn_range(pfn_t pfn_start, size_t npages)
Definition pmm.h:138

Definition at line 144 of file pmm.h.

◆ pmm_ref_one

#define pmm_ref_one ( thing)
Value:
pmm_ref(thing, 1)
#define pmm_ref(thing, npages)
Definition pmm.h:143

Definition at line 146 of file pmm.h.

Referenced by cpio_fill_cache(), mm_replace_page_locked(), pml1e_do_copy_callback(), pml1e_do_map_callback(), tmpfs_fill_cache(), userfs_inode_cache_fill_cache(), and zero_page().

◆ pmm_unref_one

#define pmm_unref_one ( thing)
Value:
pmm_unref(thing, 1)
#define pmm_unref(thing, npages)
Definition pmm.h:144

Definition at line 147 of file pmm.h.

Referenced by do_flush_and_drop_cached_page(), mm_replace_page_locked(), pml1e_do_copy_callback(), and pml1e_do_unmap_callback().

Typedef Documentation

◆ phyframe_t

typedef struct phyframe phyframe_t

Definition at line 23 of file pmm.h.

Enumeration Type Documentation

◆ pmm_allocation_flags_t

Enumerator
PMM_ALLOC_NORMAL 

allocate normal pages

Definition at line 72 of file pmm.h.

Function Documentation

◆ MOS_STATIC_ASSERT()

MOS_STATIC_ASSERT ( sizeof(phyframe_t) = =32,
"update phyframe_t struct size"  )

◆ pmm_dump_lists()

void pmm_dump_lists ( void )

Dump the physical memory manager's state, (i.e. the free list and the allocated list).

Definition at line 84 of file pmm.c.

+ Here is the call graph for this function:

◆ pmm_init()

void pmm_init ( )

Definition at line 20 of file pmm.c.

Referenced by mos_start_kernel().

+ Here is the call graph for this function:

◆ pmm_allocate_frames()

phyframe_t * pmm_allocate_frames ( size_t n_frames,
pmm_allocation_flags_t flags )

Allocate n_frames of contiguous physical memory.

Parameters
n_framesNumber of frames to allocate.
flagsAllocation flags.
Returns
phyframe_t* Pointer to the first frame of the allocated block.

Definition at line 92 of file pmm.c.

Referenced by dmabuf_do_allocate(), mm_get_free_page_raw(), and mm_get_free_pages().

+ Here is the call graph for this function:

◆ pmm_free_frames()

void pmm_free_frames ( phyframe_t * start_frame,
size_t n_pages )

Definition at line 108 of file pmm.c.

Referenced by _pmm_unref_phyframes(), and dmabuf_unshare().

+ Here is the call graph for this function:

◆ pmm_reserve_frames()

pfn_t pmm_reserve_frames ( pfn_t pfn,
size_t npages )

Mark a range of physical memory as reserved.

Parameters
pfnPhysical frame number of the block to reserve.
npagesNumber of pages to reserve.
Returns
pfn_t Physical frame number of the first frame in the reserved block.
Note
The memory will be marked as PMM_REGION_RESERVED and will be moved to the allocated list.
If the range does not exist in the free list and overlaps with an allocated block, the kernel panics.

Definition at line 122 of file pmm.c.

Referenced by pmm_init().

+ Here is the call graph for this function:

◆ pmm_find_reserved_region()

pmm_region_t * pmm_find_reserved_region ( ptr_t needle)

Find a region in the physical memory manager.

Parameters
needleOne address in the region to find.
Returns
pmm_region_t* The region found, or NULL if not found.

Definition at line 131 of file pmm.c.

Referenced by ioapic_init(), lapic_memory_setup(), and platform_startup_late().

◆ _pmm_ref_phyframes()

phyframe_t * _pmm_ref_phyframes ( phyframe_t * frame,
size_t npages )

Definition at line 151 of file pmm.c.

Referenced by _pmm_ref_pfn_range().

◆ _pmm_unref_phyframes()

void _pmm_unref_phyframes ( phyframe_t * frame,
size_t npages )

Definition at line 162 of file pmm.c.

Referenced by _pmm_unref_pfn_range().

+ Here is the call graph for this function:

◆ _pmm_ref_pfn_range()

should_inline pfn_t _pmm_ref_pfn_range ( pfn_t pfn_start,
size_t npages )

Definition at line 132 of file pmm.h.

+ Here is the call graph for this function:

◆ _pmm_unref_pfn_range()

should_inline void _pmm_unref_pfn_range ( pfn_t pfn_start,
size_t npages )

Definition at line 138 of file pmm.h.

+ Here is the call graph for this function:

Variable Documentation

◆ phyframes

phyframe_t* phyframes
extern

Definition at line 15 of file pmm.c.

Referenced by pmm_init().

◆ pmm_total_frames

◆ pmm_allocated_frames

size_t pmm_allocated_frames

Definition at line 83 of file pmm.h.

Referenced by mmstat_sysfs_stat().

◆ pmm_reserved_frames

size_t pmm_reserved_frames

Definition at line 83 of file pmm.h.

Referenced by mmstat_sysfs_stat().