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)   ((pfn_t) ((frame) -phyframes))
 
#define pfn_phyframe(pfn)   (&phyframes[(pfn)])
 
#define pmm_reserve_address(paddr)   pmm_reserve_frames(ALIGN_DOWN_TO_PAGE(paddr) / MOS_PAGE_SIZE, 1)
 
#define pmm_reserve_addresses(paddr, npages)   pmm_reserve_frames(ALIGN_DOWN_TO_PAGE(paddr) / MOS_PAGE_SIZE, npages)
 
#define pmm_ref(thing, npages)   _Generic((thing), phyframe_t *: _pmm_ref_phyframes, pfn_t: _pmm_ref_pfn_range)(thing, npages)
 
#define pmm_unref(thing, npages)   _Generic((thing), phyframe_t *: _pmm_unref_phyframes, pfn_t: _pmm_unref_pfn_range)(thing, npages)
 
#define pmm_ref_one(thing)   pmm_ref(thing, 1)
 
#define pmm_unref_one(thing)   pmm_unref(thing, 1)
 

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 (size_t max_frames)
 Initialize the physical memory manager.
 
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

◆ pfn_phyframe

◆ pmm_reserve_address

#define pmm_reserve_address ( paddr)    pmm_reserve_frames(ALIGN_DOWN_TO_PAGE(paddr) / MOS_PAGE_SIZE, 1)

Definition at line 112 of file pmm.h.

Referenced by ioapic_init(), and lapic_memory_setup().

◆ pmm_reserve_addresses

#define pmm_reserve_addresses ( paddr,
npages )   pmm_reserve_frames(ALIGN_DOWN_TO_PAGE(paddr) / MOS_PAGE_SIZE, npages)

Definition at line 113 of file pmm.h.

◆ pmm_ref

#define pmm_ref ( thing,
npages )   _Generic((thing), phyframe_t *: _pmm_ref_phyframes, pfn_t: _pmm_ref_pfn_range)(thing, npages)

Definition at line 139 of file pmm.h.

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

◆ pmm_unref

#define pmm_unref ( thing,
npages )   _Generic((thing), phyframe_t *: _pmm_unref_phyframes, pfn_t: _pmm_unref_pfn_range)(thing, npages)

Definition at line 140 of file pmm.h.

◆ pmm_ref_one

#define pmm_ref_one ( thing)    pmm_ref(thing, 1)

◆ pmm_unref_one

#define pmm_unref_one ( thing)    pmm_unref(thing, 1)

Definition at line 143 of file pmm.h.

Referenced by 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 63 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 31 of file pmm.c.

Referenced by pmm_init().

+ Here is the call graph for this function:

◆ pmm_init()

void pmm_init ( size_t max_frames)

Initialize the physical memory manager.

Parameters
max_framesMaximum number of frames that are addressable on the system.

Definition at line 18 of file pmm.c.

Referenced by x86_initialise_phyframes_array().

+ 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 37 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 53 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 67 of file pmm.c.

Referenced by platform_startup_mm(), and x86_initialise_phyframes_array().

+ 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 76 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 96 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 107 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 128 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 134 of file pmm.h.

+ Here is the call graph for this function:

Variable Documentation

◆ phyframes

phyframe_t* phyframes
extern

Definition at line 13 of file pmm.c.

Referenced by x86_initialise_phyframes_array().

◆ pmm_total_frames

◆ pmm_allocated_frames

size_t pmm_allocated_frames

Definition at line 74 of file pmm.h.

Referenced by mmstat_sysfs_stat().

◆ pmm_reserved_frames

size_t pmm_reserved_frames

Definition at line 74 of file pmm.h.

Referenced by mmstat_sysfs_stat().