remove wrapper functions

This commit is contained in:
IncompententPirate
2024-09-26 22:34:55 +00:00
committed by Jeremy Soller
parent 14eb140f7a
commit fc5d246b30
22 changed files with 96 additions and 154 deletions
+4 -4
View File
@@ -70,7 +70,7 @@ impl GenericAddressStructure {
pub unsafe fn init(&self, mapper: &mut KernelMapper) {
use crate::paging::{Page, VirtualAddress};
let frame = Frame::containing_address(PhysicalAddress::new(self.address as usize));
let frame = Frame::containing(PhysicalAddress::new(self.address as usize));
let page = Page::containing_address(VirtualAddress::new(crate::HPET_OFFSET));
mapper
@@ -80,7 +80,7 @@ impl GenericAddressStructure {
)
.map_phys(
page.start_address(),
frame.start_address(),
frame.base(),
PageFlags::new()
.write(true)
.custom_flag(EntryFlags::NO_CACHE.bits(), true),
@@ -101,14 +101,14 @@ impl GenericAddressStructure {
#[cfg(not(target_arch = "x86"))]
impl GenericAddressStructure {
pub unsafe fn init(&self, mapper: &mut KernelMapper) {
let frame = Frame::containing_address(PhysicalAddress::new(self.address as usize));
let frame = Frame::containing(PhysicalAddress::new(self.address as usize));
let (_, result) = mapper
.get_mut()
.expect(
"KernelMapper locked re-entrant while mapping memory for GenericAddressStructure",
)
.map_linearly(
frame.start_address(),
frame.base(),
PageFlags::new()
.write(true)
.custom_flag(EntryFlags::NO_CACHE.bits(), true),
+3 -3
View File
@@ -57,7 +57,7 @@ impl Madt {
if cfg!(feature = "multi_core") {
// Map trampoline
let trampoline_frame = Frame::containing_address(PhysicalAddress::new(TRAMPOLINE));
let trampoline_frame = Frame::containing(PhysicalAddress::new(TRAMPOLINE));
let trampoline_page = Page::containing_address(VirtualAddress::new(TRAMPOLINE));
let (result, page_table_physaddr) = unsafe {
//TODO: do not have writable and executable!
@@ -66,7 +66,7 @@ impl Madt {
let result = mapper
.get_mut()
.expect("expected kernel page table not to be recursively locked while initializing MADT")
.map_phys(trampoline_page.start_address(), trampoline_frame.start_address(), PageFlags::new().execute(true).write(true))
.map_phys(trampoline_page.start_address(), trampoline_frame.base(), PageFlags::new().execute(true).write(true))
.expect("failed to map trampoline");
(result, mapper.table().phys().data())
@@ -95,7 +95,7 @@ impl Madt {
// Allocate a stack
let stack_start = allocate_p2frame(4)
.expect("no more frames in acpi stack_start")
.start_address()
.base()
.data()
+ crate::PHYS_OFFSET;
let stack_end = stack_start + (PAGE_SIZE << 4);
+4 -9
View File
@@ -40,20 +40,15 @@ impl RSDP {
// Map all of the ACPI RSDP space
{
let start_frame = Frame::containing_address(PhysicalAddress::new(start_addr));
let end_frame = Frame::containing_address(PhysicalAddress::new(end_addr));
let start_frame = Frame::containing(PhysicalAddress::new(start_addr));
let end_frame = Frame::containing(PhysicalAddress::new(end_addr));
for frame in Frame::range_inclusive(start_frame, end_frame) {
let page =
Page::containing_address(VirtualAddress::new(frame.start_address().data()));
let page = Page::containing_address(VirtualAddress::new(frame.base().data()));
let result = unsafe {
mapper
.get_mut()
.expect("KernelMapper locked re-entrant while locating RSDPs")
.map_phys(
page.start_address(),
frame.start_address(),
PageFlags::new(),
)
.map_phys(page.start_address(), frame.base(), PageFlags::new())
.expect("failed to map page while searching for RSDP")
};
result.flush();
+4 -4
View File
@@ -23,19 +23,19 @@ impl Pl031rtc {
unsafe fn init(&mut self) {
let mut mapper = KernelMapper::lock();
let start_frame = Frame::containing_address(PhysicalAddress::new(0x09010000));
let end_frame = Frame::containing_address(PhysicalAddress::new(0x09010000 + 0x1000 - 1));
let start_frame = Frame::containing(PhysicalAddress::new(0x09010000));
let end_frame = Frame::containing(PhysicalAddress::new(0x09010000 + 0x1000 - 1));
for frame in Frame::range_inclusive(start_frame, end_frame) {
let page = Page::containing_address(VirtualAddress::new(
frame.start_address().data() + crate::PHYS_OFFSET,
frame.base().data() + crate::PHYS_OFFSET,
));
mapper
.get_mut()
.expect("failed to access KernelMapper for mapping RTC")
.map_phys(
page.start_address(),
frame.start_address(),
frame.base(),
PageFlags::new().write(true),
)
.expect("failed to map RTC")
+1 -1
View File
@@ -13,7 +13,7 @@ impl PercpuBlock {
#[cold]
pub unsafe fn init(cpu_id: LogicalCpuId) {
let frame = crate::memory::allocate_frame().expect("failed to allocate percpu memory");
let virt = RmmA::phys_to_virt(frame.start_address()).data() as *mut PercpuBlock;
let virt = RmmA::phys_to_virt(frame.base()).data() as *mut PercpuBlock;
virt.write(PercpuBlock::init(cpu_id));
+1 -1
View File
@@ -180,7 +180,7 @@ pub unsafe extern "C" fn kstart(args_ptr: *const KernelArgs) -> ! {
BSP_READY.store(true, Ordering::SeqCst);
crate::Bootstrap {
base: crate::memory::Frame::containing_address(crate::paging::PhysicalAddress::new(
base: crate::memory::Frame::containing(crate::paging::PhysicalAddress::new(
args.bootstrap_base,
)),
page_count: args.bootstrap_size / crate::memory::PAGE_SIZE,
+1 -2
View File
@@ -187,8 +187,7 @@ pub unsafe fn init_paging(stack_offset: usize, cpu_id: LogicalCpuId) {
.trailing_zeros();
let pcr_frame =
crate::memory::allocate_p2frame(alloc_order).expect("failed to allocate PCR frame");
let pcr =
&mut *(RmmA::phys_to_virt(pcr_frame.start_address()).data() as *mut ProcessorControlRegion);
let pcr = &mut *(RmmA::phys_to_virt(pcr_frame.base()).data() as *mut ProcessorControlRegion);
pcr.self_ref = pcr as *const _ as usize;
pcr.gdt = BASE_GDT;
+1 -1
View File
@@ -203,7 +203,7 @@ pub unsafe extern "C" fn kstart(args_ptr: *const KernelArgs) -> ! {
BSP_READY.store(true, Ordering::SeqCst);
crate::Bootstrap {
base: crate::memory::Frame::containing_address(crate::paging::PhysicalAddress::new(
base: crate::memory::Frame::containing(crate::paging::PhysicalAddress::new(
args.bootstrap_base as usize,
)),
page_count: (args.bootstrap_size as usize) / crate::memory::PAGE_SIZE,
+1 -2
View File
@@ -207,8 +207,7 @@ pub unsafe fn init_paging(stack_offset: usize, cpu_id: LogicalCpuId) {
.next_power_of_two()
.trailing_zeros();
let pcr_frame = crate::memory::allocate_p2frame(alloc_order).expect("failed to allocate PCR");
let pcr =
&mut *(RmmA::phys_to_virt(pcr_frame.start_address()).data() as *mut ProcessorControlRegion);
let pcr = &mut *(RmmA::phys_to_virt(pcr_frame.base()).data() as *mut ProcessorControlRegion);
pcr.self_ref = pcr as *mut ProcessorControlRegion as usize;
+1 -1
View File
@@ -214,7 +214,7 @@ pub unsafe extern "C" fn kstart(args_ptr: *const KernelArgs) -> ! {
BSP_READY.store(true, Ordering::SeqCst);
crate::Bootstrap {
base: crate::memory::Frame::containing_address(crate::paging::PhysicalAddress::new(
base: crate::memory::Frame::containing(crate::paging::PhysicalAddress::new(
args.bootstrap_base as usize,
)),
page_count: (args.bootstrap_size as usize) / crate::memory::PAGE_SIZE,
+3 -3
View File
@@ -233,11 +233,11 @@ pub fn src_overrides() -> &'static [Override] {
pub unsafe fn handle_ioapic(mapper: &mut KernelMapper, madt_ioapic: &'static MadtIoApic) {
// map the I/O APIC registers
let frame = Frame::containing_address(PhysicalAddress::new(madt_ioapic.address as usize));
let frame = Frame::containing(PhysicalAddress::new(madt_ioapic.address as usize));
#[cfg(target_arch = "x86")]
let page = Page::containing_address(rmm::VirtualAddress::new(crate::IOAPIC_OFFSET));
#[cfg(target_arch = "x86_64")]
let page = Page::containing_address(RmmA::phys_to_virt(frame.start_address()));
let page = Page::containing_address(RmmA::phys_to_virt(frame.base()));
assert!(mapper.translate(page.start_address()).is_none());
@@ -246,7 +246,7 @@ pub unsafe fn handle_ioapic(mapper: &mut KernelMapper, madt_ioapic: &'static Mad
.expect("expected KernelMapper not to be locked re-entrant while mapping I/O APIC memory")
.map_phys(
page.start_address(),
frame.start_address(),
frame.base(),
PageFlags::new()
.write(true)
.custom_flag(EntryFlags::NO_CACHE.bits(), true),
+1 -2
View File
@@ -28,8 +28,7 @@ pub unsafe fn init() {
let mut active_table = ActivePageTable::new();
let page = Page::containing_address(VirtualAddress::new(address));
let frame =
Frame::containing_address(PhysicalAddress::new(address - crate::PHYS_OFFSET));
let frame = Frame::containing(PhysicalAddress::new(address - crate::PHYS_OFFSET));
let result = active_table.map_to(
page,
frame,
+3 -6
View File
@@ -130,12 +130,9 @@ pub unsafe fn init() -> bool {
.contains(KvmFeatureBits::CLOCKSOURCE2 | KvmFeatureBits::CLOCKSOURCE_STABLE)
{
let frame = allocate_frame().expect("failed to allocate timer page");
x86::msr::wrmsr(
MSR_KVM_SYSTEM_TIME_NEW,
(frame.start_address().data() as u64) | 1,
);
let ptr = crate::paging::RmmA::phys_to_virt(frame.start_address()).data()
as *const PvclockVcpuTimeInfo;
x86::msr::wrmsr(MSR_KVM_SYSTEM_TIME_NEW, (frame.base().data() as u64) | 1);
let ptr =
crate::paging::RmmA::phys_to_virt(frame.base()).data() as *const PvclockVcpuTimeInfo;
PercpuBlock::current()
.misc_arch_info
.tsc_info
+1 -1
View File
@@ -205,7 +205,7 @@ pub unsafe fn init_generic(cpu_id: LogicalCpuId, idt: &mut Idt) {
use crate::paging::{RmmA, RmmArch};
// Physical pages are mapped linearly. So is the linearly mapped virtual memory.
let base_address = RmmA::phys_to_virt(frames.start_address());
let base_address = RmmA::phys_to_virt(frames.base());
// Stack always grows downwards.
let address = base_address.data() + BACKUP_STACK_SIZE;
+2 -2
View File
@@ -39,7 +39,7 @@ pub unsafe fn map() {
//
// // Map kernel heap
// let address = active_table.p4()[::KERNEL_HEAP_PML4].address();
// let frame = Frame::containing_address(address);
// let frame = Frame::containing(address);
// let mut flags = active_table.p4()[::KERNEL_HEAP_PML4].flags();
// flags.remove(EntryFlags::PRESENT);
// active_table.p4_mut()[::KERNEL_HEAP_PML4].set(frame, flags);
@@ -69,7 +69,7 @@ pub unsafe extern "C" fn unmap() {
//
// // Unmap kernel heap
// let address = active_table.p4()[::KERNEL_HEAP_PML4].address();
// let frame = Frame::containing_address(address);
// let frame = Frame::containing(address);
// let mut flags = active_table.p4()[::KERNEL_HEAP_PML4].flags();
// flags.insert(EntryFlags::PRESENT);
// active_table.p4_mut()[::KERNEL_HEAP_PML4].set(frame, flags);
+7 -23
View File
@@ -448,13 +448,11 @@ impl Context {
check(sig.threadctl_off);
let for_thread = unsafe {
&*(RmmA::phys_to_virt(sig.thread_control.get().start_address()).data()
as *const Sigcontrol)
&*(RmmA::phys_to_virt(sig.thread_control.get().base()).data() as *const Sigcontrol)
.byte_add(usize::from(sig.threadctl_off))
};
let for_proc = unsafe {
&*(RmmA::phys_to_virt(sig.proc_control.get().start_address()).data()
as *const SigProcControl)
&*(RmmA::phys_to_virt(sig.proc_control.get().base()).data() as *const SigProcControl)
.byte_add(usize::from(sig.procctl_off))
};
@@ -495,26 +493,14 @@ impl BorrowedHtBuf {
}
pub fn buf(&self) -> &[u8; PAGE_SIZE] {
unsafe {
&*(RmmA::phys_to_virt(
self.inner
.as_ref()
.expect("must succeed")
.get()
.start_address(),
)
.data() as *const [u8; PAGE_SIZE])
&*(RmmA::phys_to_virt(self.inner.as_ref().expect("must succeed").get().base()).data()
as *const [u8; PAGE_SIZE])
}
}
pub fn buf_mut(&mut self) -> &mut [u8; PAGE_SIZE] {
unsafe {
&mut *(RmmA::phys_to_virt(
self.inner
.as_mut()
.expect("must succeed")
.get()
.start_address(),
)
.data() as *mut [u8; PAGE_SIZE])
&mut *(RmmA::phys_to_virt(self.inner.as_mut().expect("must succeed").get().base())
.data() as *mut [u8; PAGE_SIZE])
}
}
pub fn frame(&self) -> Frame {
@@ -572,9 +558,7 @@ impl Kstack {
})
}
pub fn initial_top(&self) -> *mut u8 {
unsafe {
(RmmA::phys_to_virt(self.base.start_address()).data() as *mut u8).add(PAGE_SIZE << 4)
}
unsafe { (RmmA::phys_to_virt(self.base.base()).data() as *mut u8).add(PAGE_SIZE << 4) }
}
pub fn len(&self) -> usize {
PAGE_SIZE << 4
+38 -55
View File
@@ -1127,7 +1127,7 @@ impl Grant {
unsafe {
mapper
.map_phys(page.start_address(), frame.start_address(), flags)
.map_phys(page.start_address(), frame.base(), flags)
.ok_or(Error::new(ENOMEM))?
.ignore();
@@ -1166,11 +1166,9 @@ impl Grant {
for (i, page) in span.pages().enumerate().take(MAX_EAGER_PAGES) {
let frame = phys.next_by(i);
unsafe {
let Some(result) = mapper.map_phys(
page.start_address(),
frame.start_address(),
flags.write(false),
) else {
let Some(result) =
mapper.map_phys(page.start_address(), frame.base(), flags.write(false))
else {
break;
};
result.ignore();
@@ -1212,7 +1210,7 @@ impl Grant {
unsafe {
let result = mapper
.map_phys(page.start_address(), frame.start_address(), flags)
.map_phys(page.start_address(), frame.base(), flags)
.expect("TODO: page table OOM");
result.ignore();
@@ -1254,11 +1252,9 @@ impl Grant {
.add_ref(RefKind::Cow)
.expect("the static zeroed frame cannot be shared!");
let Some(result) = mapper.map_phys(
page.start_address(),
the_frame.start_address(),
flags.write(false),
) else {
let Some(result) =
mapper.map_phys(page.start_address(), the_frame.base(), flags.write(false))
else {
break;
};
result.ignore();
@@ -1337,7 +1333,7 @@ impl Grant {
.utable
.translate(src_page.start_address())
{
Some((phys, _)) => Frame::containing_address(phys),
Some((phys, _)) => Frame::containing(phys),
// TODO: ensure the correct context is hardblocked, if necessary
None => {
let (frame, _, new_guard) = correct_inner(
@@ -1361,7 +1357,7 @@ impl Grant {
.utable
.remap_with(src_page.start_address(), |flags| flags.write(false))
{
Some((_, phys, _)) => Frame::containing_address(phys),
Some((_, phys, _)) => Frame::containing(phys),
// TODO: ensure the correct context is hardblocked, if necessary
None => {
let (frame, _, new_guard) = correct_inner(
@@ -1396,7 +1392,7 @@ impl Grant {
.table
.utable
.remap_with_full(src_page.start_address(), |_, flags| {
(new_cow_frame.start_address(), flags)
(new_cow_frame.base(), flags)
})
.expect("page did exist");
@@ -1436,7 +1432,7 @@ impl Grant {
let flush = mapper
.map_phys(
dst_page.start_address(),
frame.start_address(),
frame.base(),
new_flags.write(new_flags.has_write() && !is_cow),
)
.unwrap();
@@ -1547,7 +1543,7 @@ impl Grant {
continue;
};
let writable = match get_page_info(Frame::containing_address(phys)) {
let writable = match get_page_info(Frame::containing(phys)) {
None => true,
Some(i) => {
if i.add_ref(RefKind::Shared).is_err() {
@@ -1569,7 +1565,7 @@ impl Grant {
flush.ignore();
dst_flusher.queue(
Frame::containing_address(phys),
Frame::containing(phys),
None,
TlbShootdownActions::NEW_MAPPING,
);
@@ -1627,23 +1623,19 @@ impl Grant {
unsafe {
flush.ignore();
}
let frame = Frame::containing_address(phys);
let frame = Frame::containing(phys);
src_flusher.queue(frame, None, TlbShootdownActions::REVOKE_WRITE);
frame
}
RefKind::Shared => {
if let Some((phys, _)) = src_mapper.translate(src_page.start_address()) {
Frame::containing_address(phys)
Frame::containing(phys)
} else {
// TODO: Omit the unnecessary subsequent add_ref call.
let new_frame = init_frame(RefCount::One).expect("TODO: handle OOM");
let src_flush = unsafe {
src_mapper
.map_phys(
src_page.start_address(),
new_frame.start_address(),
flags,
)
.map_phys(src_page.start_address(), new_frame.base(), flags)
.expect("TODO: handle OOM")
};
unsafe {
@@ -1675,7 +1667,7 @@ impl Grant {
unsafe {
if let Some((_flags, phys, flush)) = src_mapper
.remap_with_full(src_page.start_address(), |_, f| {
(new_frame.start_address(), f)
(new_frame.base(), f)
})
{
// TODO: flush.ignore() is correct, but seems to be amplifying a
@@ -1686,7 +1678,7 @@ impl Grant {
// FIXME: Is MOVE correct?
src_flusher.queue(
Frame::containing_address(phys),
Frame::containing(phys),
None,
TlbShootdownActions::MOVE,
);
@@ -1720,7 +1712,7 @@ impl Grant {
let Some(map_result) = (unsafe {
dst_mapper.map_phys(
dst_page,
src_frame.start_address(),
src_frame.base(),
flags.write(flags.has_write() && allows_writable),
)
}) else {
@@ -1777,11 +1769,7 @@ impl Grant {
unsafe {
flush.ignore();
}
src_flusher.queue(
Frame::containing_address(phys),
None,
TlbShootdownActions::MOVE,
);
src_flusher.queue(Frame::containing(phys), None, TlbShootdownActions::MOVE);
let dst_mapper = dst_mapper.as_deref_mut().unwrap_or(&mut *src_mapper);
@@ -1795,7 +1783,7 @@ impl Grant {
flush.ignore();
}
dst_flusher.queue(
Frame::containing_address(phys),
Frame::containing(phys),
None,
TlbShootdownActions::NEW_MAPPING,
);
@@ -1823,9 +1811,9 @@ impl Grant {
continue;
};
flush.ignore();
//log::info!("Remapped page {:?} (frame {:?})", page, Frame::containing_address(mapper.translate(page.start_address()).unwrap().0));
//log::info!("Remapped page {:?} (frame {:?})", page, Frame::containing(mapper.translate(page.start_address()).unwrap().0));
flusher.queue(
Frame::containing_address(phys),
Frame::containing(phys),
None,
TlbShootdownActions::change_of_flags(old_flags, flags),
);
@@ -1888,7 +1876,7 @@ impl Grant {
if is_phys_contiguous {
let (phys_base, _) = mapper.translate(self.base.start_address()).unwrap();
let base_frame = Frame::containing_address(phys_base);
let base_frame = Frame::containing(phys_base);
for i in 0..self.info.page_count {
unsafe {
@@ -1897,7 +1885,7 @@ impl Grant {
.expect("all physborrowed grants must be fully Present in the page tables");
flush.ignore();
assert_eq!(phys, base_frame.next_by(i).start_address());
assert_eq!(phys, base_frame.next_by(i).base());
}
}
@@ -1918,11 +1906,7 @@ impl Grant {
flush.ignore();
}
flusher.queue(
Frame::containing_address(phys),
None,
TlbShootdownActions::FREE,
);
flusher.queue(Frame::containing(phys), None, TlbShootdownActions::FREE);
}
}
@@ -2269,7 +2253,7 @@ impl Drop for Table {
}
}
unsafe {
deallocate_frame(Frame::containing_address(self.utable.table().phys()));
deallocate_frame(Frame::containing(self.utable.table().phys()));
}
}
}
@@ -2435,7 +2419,7 @@ fn map_zeroed(
unsafe {
mapper
.map_phys(page.start_address(), new_frame.start_address(), page_flags)
.map_phys(page.start_address(), new_frame.base(), page_flags)
.ok_or(PfError::Oom)?
.ignore();
}
@@ -2449,8 +2433,8 @@ pub unsafe fn copy_frame_to_frame_directly(dst: Frame, src: Frame) {
// TODO: For new frames, when the kernel's linear phys=>virt mappings are 4k, this is almost
// guaranteed to cause either one (or two) TLB misses.
let dst = unsafe { RmmA::phys_to_virt(dst.start_address()).data() as *mut u8 };
let src = unsafe { RmmA::phys_to_virt(src.start_address()).data() as *const u8 };
let dst = unsafe { RmmA::phys_to_virt(dst.base()).data() as *mut u8 };
let src = unsafe { RmmA::phys_to_virt(src.base()).data() as *const u8 };
unsafe {
dst.copy_from_nonoverlapping(src, PAGE_SIZE);
@@ -2511,7 +2495,7 @@ fn correct_inner<'l>(
.table
.utable
.translate(faulting_page.start_address())
.map(|(phys, _page_flags)| Frame::containing_address(phys));
.map(|(phys, _page_flags)| Frame::containing(phys));
let faulting_pageinfo_opt = faulting_frame_opt.map(|frame| (frame, get_page_info(frame)));
// TODO: Aligned readahead? AMD Zen3+ CPUs can smash 4 4k pages that are 16k-aligned, into a
@@ -2594,7 +2578,7 @@ fn correct_inner<'l>(
let src_frame = if let Some((phys, _)) =
guard.table.utable.translate(src_page.start_address())
{
Frame::containing_address(phys)
Frame::containing(phys)
} else {
// Grant was valid (TODO check), but we need to correct the underlying page.
// TODO: Access mode
@@ -2654,7 +2638,7 @@ fn correct_inner<'l>(
.table
.utable
.remap_with_full(src_page.start_address(), |_, f| {
(new_frame.start_address(), f)
(new_frame.base(), f)
});
}
@@ -2731,11 +2715,10 @@ fn correct_inner<'l>(
let new_flags = grant_flags.write(grant_flags.has_write() && allow_writable);
let Some(flush) = (unsafe {
addr_space.table.utable.map_phys(
faulting_page.start_address(),
frame.start_address(),
new_flags,
)
addr_space
.table
.utable
.map_phys(faulting_page.start_address(), frame.base(), new_flags)
}) else {
// TODO
return Err(PfError::Oom);
+1 -1
View File
@@ -441,7 +441,7 @@ pub unsafe fn check_consistency(
| Provider::External { .. }
| Provider::FmapBorrowed { .. }
);
let frame = Frame::containing_address(physaddr);
let frame = Frame::containing(physaddr);
if new_as {
tree.entry(frame).or_insert((0, p)).0 += 1;
}
+16 -30
View File
@@ -120,11 +120,10 @@ pub fn allocate_p2frame_complex(
drop(freelist);
unsafe {
(RmmA::phys_to_virt(frame.start_address()).data() as *mut u8)
.write_bytes(0, PAGE_SIZE << min_order);
(RmmA::phys_to_virt(frame.base()).data() as *mut u8).write_bytes(0, PAGE_SIZE << min_order);
}
debug_assert!(frame.start_address().data() >= unsafe { ALLOCATOR_DATA.abs_off });
debug_assert!(frame.base().data() >= unsafe { ALLOCATOR_DATA.abs_off });
Some((frame, PAGE_SIZE << min_order))
}
@@ -141,8 +140,8 @@ pub unsafe fn deallocate_p2frame(orig_frame: Frame, order: u32) {
// 2^addrwidth - 1. However, allocation and deallocation must be synchronized (the "next"
// word of the PageInfo).
let sibling = Frame::containing_address(PhysicalAddress::new(
current.start_address().data() ^ (PAGE_SIZE << merge_order),
let sibling = Frame::containing(PhysicalAddress::new(
current.base().data() ^ (PAGE_SIZE << merge_order),
));
let Some(_cur_info) = get_page_info(current) else {
@@ -186,8 +185,8 @@ pub unsafe fn deallocate_p2frame(orig_frame: Frame, order: u32) {
get_free_alloc_page_info(sib_next).set_prev(sib_info.prev());
}
current = Frame::containing_address(PhysicalAddress::new(
current.start_address().data() & !(PAGE_SIZE << merge_order),
current = Frame::containing(PhysicalAddress::new(
current.base().data() & !(PAGE_SIZE << merge_order),
));
largest_order = merge_order + 1;
@@ -258,26 +257,11 @@ impl core::fmt::Debug for P2Frame {
impl core::fmt::Debug for Frame {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(
f,
"[frame at {:p}]",
self.start_address().data() as *const u8
)
write!(f, "[frame at {:p}]", self.base().data() as *const u8)
}
}
impl Frame {
/// Get the address of this frame
// TODO: Remove
pub fn start_address(&self) -> PhysicalAddress {
self.base()
}
/// Create a frame containing `address`
// TODO: Remove
pub fn containing_address(address: PhysicalAddress) -> Frame {
Self::containing(address)
}
/// Create a frame containing `address`
pub fn containing(address: PhysicalAddress) -> Frame {
Frame {
@@ -285,6 +269,8 @@ impl Frame {
.expect("frame 0x0 is reserved"),
}
}
/// Get the address of this frame
pub fn base(self) -> PhysicalAddress {
PhysicalAddress::new(self.physaddr.get())
}
@@ -316,7 +302,7 @@ impl Frame {
/ PAGE_SIZE
}
pub fn is_aligned_to_order(self, order: u32) -> bool {
self.start_address().data() % (PAGE_SIZE << order) == 0
self.base().data() % (PAGE_SIZE << order) == 0
}
}
@@ -546,12 +532,12 @@ fn init_sections(mut allocator: BumpAllocator<RmmA>) {
);
let mut pages_left = memory_map_area.size.div_floor(PAGE_SIZE);
let mut base = Frame::containing_address(memory_map_area.base);
let mut base = Frame::containing(memory_map_area.base);
while pages_left > 0 {
let page_info_max_count = core::cmp::min(pages_left, MAX_SECTION_PAGE_COUNT);
let pages_to_next_section =
(MAX_SECTION_SIZE - (base.start_address().data() % MAX_SECTION_SIZE)) / PAGE_SIZE;
(MAX_SECTION_SIZE - (base.base().data() % MAX_SECTION_SIZE)) / PAGE_SIZE;
let page_info_count = core::cmp::min(page_info_max_count, pages_to_next_section);
let page_info_array_size_pages =
@@ -590,7 +576,7 @@ fn init_sections(mut allocator: BumpAllocator<RmmA>) {
'sections: for section in &*sections {
for (off, page_info) in section.frames.iter().enumerate() {
let frame = section.base.next_by(off);
if frame.start_address() >= allocator.abs_offset() {
if frame.base() >= allocator.abs_offset() {
break 'sections;
}
//log::info!("MARKING {frame:?} AS USED");
@@ -608,7 +594,7 @@ fn init_sections(mut allocator: BumpAllocator<RmmA>) {
let mut append_page = |page: Frame, info: &'static PageInfo, order| {
let this_page = (page, info);
if page.start_address() < allocator.abs_offset() {
if page.base() < allocator.abs_offset() {
return;
}
debug_assert!(info.as_free().is_some());
@@ -1030,11 +1016,11 @@ pub struct TheFrameAllocator;
impl FrameAllocator for TheFrameAllocator {
unsafe fn allocate(&mut self, count: FrameCount) -> Option<PhysicalAddress> {
let order = count.data().next_power_of_two().trailing_zeros();
allocate_p2frame(order).map(|f| f.start_address())
allocate_p2frame(order).map(|f| f.base())
}
unsafe fn free(&mut self, address: PhysicalAddress, count: FrameCount) {
let order = count.data().next_power_of_two().trailing_zeros();
deallocate_p2frame(Frame::containing_address(address), order)
deallocate_p2frame(Frame::containing(address), order)
}
unsafe fn usage(&self) -> FrameUsage {
FrameUsage::new(
+1 -1
View File
@@ -165,7 +165,7 @@ impl MemoryScheme {
}
Grant::physmap(
Frame::containing_address(PhysicalAddress::new(physical_address)),
Frame::containing(PhysicalAddress::new(physical_address)),
PageSpan::new(dst_page, page_count.get()),
page_flags,
dst_mapper,
+1 -1
View File
@@ -1038,7 +1038,7 @@ impl UserInner {
} => context.status = Status::Runnable,
_ => (),
}
context.fmap_ret = Some(Frame::containing_address(frame));
context.fmap_ret = Some(Frame::containing(frame));
}
ParsedCqe::TriggerFevent { number, flags } => {
event::trigger(self.scheme_id, number, flags)
+1 -1
View File
@@ -880,7 +880,7 @@ pub unsafe fn usermode_bootstrap(bootstrap: &Bootstrap) {
pub unsafe fn bootstrap_mem(bootstrap: &crate::Bootstrap) -> &'static [u8] {
core::slice::from_raw_parts(
CurrentRmmArch::phys_to_virt(bootstrap.base.start_address()).data() as *const u8,
CurrentRmmArch::phys_to_virt(bootstrap.base.base()).data() as *const u8,
bootstrap.page_count * PAGE_SIZE,
)
}