1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use crate::PAGE_SIZE;
pub type PhysAddr = usize;
pub type VirtAddr = usize;
pub type DevVAddr = usize;
pub const fn align_down(addr: usize) -> usize {
addr & !(PAGE_SIZE - 1)
}
pub const fn align_up(addr: usize) -> usize {
(addr + PAGE_SIZE - 1) & !(PAGE_SIZE - 1)
}
pub const fn is_aligned(addr: usize) -> bool {
page_offset(addr) == 0
}
pub const fn page_count(size: usize) -> usize {
align_up(size) / PAGE_SIZE
}
pub const fn page_offset(addr: usize) -> usize {
addr & (PAGE_SIZE - 1)
}