Skip to content

Commit 2aab152

Browse files
committed
Merge remote-tracking branch 'origin/main' into dyn
2 parents 9dfbde0 + fcaed05 commit 2aab152

File tree

21 files changed

+95
-71
lines changed

21 files changed

+95
-71
lines changed

axplat/src/mem.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use core::{fmt, ops::Range};
44

5-
use memory_addr::PhysAddr;
5+
use memory_addr::{PhysAddr, VirtAddr};
66

77
bitflags::bitflags! {
88
/// The flags of a physical memory region.
@@ -115,6 +115,12 @@ pub trait MemIf {
115115

116116
/// Returns all device memory (MMIO) ranges on the platform.
117117
fn mmio_ranges() -> &'static [RawRange];
118+
119+
/// Translates a physical address to a virtual address.
120+
fn phys_to_virt(paddr: PhysAddr) -> VirtAddr;
121+
122+
/// Translates a virtual address to a physical address.
123+
fn virt_to_phys(vaddr: VirtAddr) -> PhysAddr;
118124
}
119125

120126
/// Returns the total size of physical memory (RAM) on the platform.

platforms/axplat-aarch64-bsta1000b/src/mem.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,10 @@ use crate::config::plat::{PHYS_MEMORY_BASE, PHYS_MEMORY_SIZE, PHYS_VIRT_OFFSET};
66

77
struct MemIfImpl;
88

9-
#[allow(dead_code)]
10-
pub const fn phys_to_virt(paddr: PhysAddr) -> VirtAddr {
9+
pub(crate) const fn phys_to_virt(paddr: PhysAddr) -> VirtAddr {
1110
va!(paddr.as_usize() + PHYS_VIRT_OFFSET)
1211
}
1312

14-
#[allow(dead_code)]
15-
pub const fn virt_to_phys(vaddr: VirtAddr) -> PhysAddr {
16-
pa!(vaddr.as_usize() - PHYS_VIRT_OFFSET)
17-
}
18-
1913
#[impl_plat_interface]
2014
impl MemIf for MemIfImpl {
2115
/// Returns all physical memory (RAM) ranges on the platform.
@@ -41,4 +35,14 @@ impl MemIf for MemIfImpl {
4135
fn mmio_ranges() -> &'static [RawRange] {
4236
&MMIO_RANGES
4337
}
38+
39+
/// Translates a physical address to a virtual address.
40+
fn phys_to_virt(paddr: PhysAddr) -> VirtAddr {
41+
phys_to_virt(paddr)
42+
}
43+
44+
/// Translates a virtual address to a physical address.
45+
fn virt_to_phys(vaddr: VirtAddr) -> PhysAddr {
46+
pa!(vaddr.as_usize() - PHYS_VIRT_OFFSET)
47+
}
4448
}

platforms/axplat-aarch64-bsta1000b/src/mp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::config::plat::CPU_ID_LIST;
2-
use crate::mem::virt_to_phys;
2+
use axplat::mem::virt_to_phys;
33
use memory_addr::PhysAddr;
44

55
/// Starts the given secondary CPU with its boot stack.

platforms/axplat-aarch64-phytium-pi/src/init.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use axplat::init::InitIf;
22

33
#[allow(unused_imports)]
44
use crate::config::devices::{GICC_PADDR, GICD_PADDR, TIMER_IRQ, UART_IRQ, UART_PADDR};
5-
use crate::{config::plat::PSCI_METHOD, mem::phys_to_virt};
5+
use crate::config::plat::PSCI_METHOD;
6+
use axplat::mem::phys_to_virt;
67

78
struct InitIfImpl;
89

platforms/axplat-aarch64-phytium-pi/src/mem.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ use crate::config::plat::{PHYS_MEMORY_BASE, PHYS_MEMORY_SIZE, PHYS_VIRT_OFFSET};
66

77
struct MemIfImpl;
88

9-
pub const fn phys_to_virt(paddr: PhysAddr) -> VirtAddr {
10-
va!(paddr.as_usize() + PHYS_VIRT_OFFSET)
11-
}
12-
13-
#[allow(dead_code)]
14-
pub const fn virt_to_phys(vaddr: VirtAddr) -> PhysAddr {
15-
pa!(vaddr.as_usize() - PHYS_VIRT_OFFSET)
16-
}
17-
189
#[impl_plat_interface]
1910
impl MemIf for MemIfImpl {
2011
/// Returns all physical memory (RAM) ranges on the platform.
@@ -40,4 +31,14 @@ impl MemIf for MemIfImpl {
4031
fn mmio_ranges() -> &'static [RawRange] {
4132
&MMIO_RANGES
4233
}
34+
35+
/// Translates a physical address to a virtual address.
36+
fn phys_to_virt(paddr: PhysAddr) -> VirtAddr {
37+
va!(paddr.as_usize() + PHYS_VIRT_OFFSET)
38+
}
39+
40+
/// Translates a virtual address to a physical address.
41+
fn virt_to_phys(vaddr: VirtAddr) -> PhysAddr {
42+
pa!(vaddr.as_usize() - PHYS_VIRT_OFFSET)
43+
}
4344
}

platforms/axplat-aarch64-phytium-pi/src/power.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl PowerIf for PowerImpl {
1313
#[cfg(feature = "smp")]
1414
{
1515
use crate::config::plat::CPU_ID_LIST;
16-
use crate::mem::virt_to_phys;
16+
use axplat::mem::virt_to_phys;
1717

1818
let entry = virt_to_phys(va!(crate::boot::_start_secondary as usize));
1919
axplat_aarch64_common::psci::cpu_on(

platforms/axplat-aarch64-qemu-virt/src/init.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use axplat::init::InitIf;
33
#[allow(unused_imports)]
44
use crate::config::devices::{GICC_PADDR, GICD_PADDR, RTC_PADDR, TIMER_IRQ, UART_IRQ, UART_PADDR};
55
use crate::config::plat::PSCI_METHOD;
6-
use crate::mem::phys_to_virt;
6+
use axplat::mem::phys_to_virt;
77

88
struct InitIfImpl;
99

@@ -36,7 +36,6 @@ impl InitIf for InitIfImpl {
3636
fn init_later(_cpu_id: usize, _dtb: usize) {
3737
#[cfg(feature = "irq")]
3838
{
39-
use crate::mem::phys_to_virt;
4039
axplat_aarch64_common::gic::init_gicd(
4140
phys_to_virt(pa!(GICD_PADDR)),
4241
phys_to_virt(pa!(GICC_PADDR)),

platforms/axplat-aarch64-qemu-virt/src/mem.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ use crate::config::plat::{PHYS_MEMORY_BASE, PHYS_MEMORY_SIZE, PHYS_VIRT_OFFSET};
66

77
struct MemIfImpl;
88

9-
pub const fn phys_to_virt(paddr: PhysAddr) -> VirtAddr {
10-
va!(paddr.as_usize() + PHYS_VIRT_OFFSET)
11-
}
12-
13-
#[allow(dead_code)]
14-
pub const fn virt_to_phys(vaddr: VirtAddr) -> PhysAddr {
15-
pa!(vaddr.as_usize() - PHYS_VIRT_OFFSET)
16-
}
17-
189
#[impl_plat_interface]
1910
impl MemIf for MemIfImpl {
2011
/// Returns all physical memory (RAM) ranges on the platform.
@@ -40,4 +31,14 @@ impl MemIf for MemIfImpl {
4031
fn mmio_ranges() -> &'static [RawRange] {
4132
&MMIO_RANGES
4233
}
34+
35+
/// Translates a physical address to a virtual address.
36+
fn phys_to_virt(paddr: PhysAddr) -> VirtAddr {
37+
va!(paddr.as_usize() + PHYS_VIRT_OFFSET)
38+
}
39+
40+
/// Translates a virtual address to a physical address.
41+
fn virt_to_phys(vaddr: VirtAddr) -> PhysAddr {
42+
pa!(vaddr.as_usize() - PHYS_VIRT_OFFSET)
43+
}
4344
}

platforms/axplat-aarch64-qemu-virt/src/power.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ impl PowerIf for PowerImpl {
1212
fn cpu_boot(cpu_id: usize, stack_top_paddr: usize) {
1313
#[cfg(feature = "smp")]
1414
{
15-
let entry_paddr = crate::mem::virt_to_phys(va!(crate::boot::_start_secondary as usize));
15+
let entry_paddr =
16+
axplat::mem::virt_to_phys(va!(crate::boot::_start_secondary as usize));
1617
axplat_aarch64_common::psci::cpu_on(cpu_id, entry_paddr.as_usize(), stack_top_paddr);
1718
}
1819
#[cfg(not(feature = "smp"))]

platforms/axplat-aarch64-raspi/src/init.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use axplat::init::InitIf;
33
use crate::config::devices::UART_PADDR;
44
#[cfg(feature = "irq")]
55
use crate::config::devices::{GICC_PADDR, GICD_PADDR, TIMER_IRQ, UART_IRQ};
6-
use crate::mem::phys_to_virt;
6+
use axplat::mem::phys_to_virt;
77

88
struct InitIfImpl;
99

@@ -33,7 +33,6 @@ impl InitIf for InitIfImpl {
3333
fn init_later(_cpu_id: usize, _dtb: usize) {
3434
#[cfg(feature = "irq")]
3535
{
36-
use crate::mem::phys_to_virt;
3736
axplat_aarch64_common::gic::init_gicd(
3837
phys_to_virt(pa!(GICD_PADDR)),
3938
phys_to_virt(pa!(GICC_PADDR)),

0 commit comments

Comments
 (0)