Add `MemoryRegionType::is_physical`
This commit is contained in:
parent
22b12c2cef
commit
66e293e989
|
|
@ -32,6 +32,21 @@ pub enum MemoryRegionType {
|
|||
Usable = 8,
|
||||
}
|
||||
|
||||
impl MemoryRegionType {
|
||||
/// Returns whether the memory region corresponds to physical memory.
|
||||
///
|
||||
/// The linear mapping will cover memory addresses up to the top of the physical memory.
|
||||
/// Therefore, if this method returns `false`, the memory region may not be included in the
|
||||
/// linear mapping.
|
||||
pub fn is_physical(self) -> bool {
|
||||
// Bad memory or I/O memory is not physical. All other memory should be physical.
|
||||
!matches!(
|
||||
self,
|
||||
Self::BadMemory | Self::Unknown | Self::Reserved | Self::Framebuffer
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// The information of initial memory regions that are needed by the kernel.
|
||||
/// The sections are **not** guaranteed to not overlap. The region must be page aligned.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
|
|
|
|||
|
|
@ -458,12 +458,7 @@ pub(crate) unsafe fn init() -> Segment<MetaPageMeta> {
|
|||
let regions = &crate::boot::EARLY_INFO.get().unwrap().memory_regions;
|
||||
regions
|
||||
.iter()
|
||||
.filter(|r| {
|
||||
matches!(
|
||||
r.typ(),
|
||||
MemoryRegionType::Usable | MemoryRegionType::Reclaimable
|
||||
)
|
||||
})
|
||||
.filter(|r| r.typ().is_physical())
|
||||
.map(|r| r.base() + r.len())
|
||||
.max()
|
||||
.unwrap()
|
||||
|
|
@ -592,11 +587,7 @@ macro_rules! mark_ranges {
|
|||
fn mark_unusable_ranges() {
|
||||
let regions = &crate::boot::EARLY_INFO.get().unwrap().memory_regions;
|
||||
|
||||
for region in regions
|
||||
.iter()
|
||||
.rev()
|
||||
.skip_while(|r| r.typ() != MemoryRegionType::Usable)
|
||||
{
|
||||
for region in regions.iter().rev().skip_while(|r| !r.typ().is_physical()) {
|
||||
match region.typ() {
|
||||
MemoryRegionType::BadMemory => mark_ranges!(region, UnusableMemoryMeta),
|
||||
MemoryRegionType::Unknown => mark_ranges!(region, ReservedMemoryMeta),
|
||||
|
|
|
|||
Loading…
Reference in New Issue