Skip to content

Commit

Permalink
implement fxmac::KernelFunc using crate crate_interface
Browse files Browse the repository at this point in the history
  • Loading branch information
elliott10 committed Feb 18, 2025
1 parent 1c3559d commit 42c5098
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 28 deletions.
16 changes: 14 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@ axdma = { path = "modules/axdma" }

[profile.release]
lto = true

[patch."https://github.com/arceos-org/axdriver_crates.git"]
axdriver_base = { git = "https://github.com/elliott10/axdriver_crates", rev = "52266c70" }
axdriver_net = { git = "https://github.com/elliott10/axdriver_crates", rev = "52266c70" }
1 change: 1 addition & 0 deletions modules/axdriver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ default = ["bus-pci"]
[dependencies]
log = "=0.4.21"
cfg-if = "1.0"
crate_interface = "0.1.4"
axdriver_base = { git = "https://github.com/arceos-org/axdriver_crates.git", tag = "v0.1.0" }
axdriver_block = { git = "https://github.com/arceos-org/axdriver_crates.git", tag = "v0.1.0", optional = true }
axdriver_net = { git = "https://github.com/arceos-org/axdriver_crates.git", tag = "v0.1.0", optional = true }
Expand Down
51 changes: 26 additions & 25 deletions modules/axdriver/src/drivers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,35 +132,36 @@ cfg_if::cfg_if! {
cfg_if::cfg_if! {
if #[cfg(net_dev = "fxmac")]{
use axalloc::global_allocator;
use axhal::mem::{phys_to_virt, virt_to_phys};
const PAGE_SIZE: usize = 4096;

#[unsafe(no_mangle)]
pub fn virt_to_phys_fxmac(addr: usize) -> usize {
virt_to_phys(addr.into()).into()
}
#[crate_interface::impl_interface]
impl axdriver_net::fxmac::KernelFunc for FXmacDriver{
fn virt_to_phys(addr: usize) -> usize {
axhal::mem::virt_to_phys(addr.into()).into()
}

#[unsafe(no_mangle)]
pub fn phys_to_virt_fxmac(addr: usize) -> usize {
phys_to_virt(addr.into()).into()
}
fn phys_to_virt(addr: usize) -> usize {
axhal::mem::phys_to_virt(addr.into()).into()
}

#[unsafe(no_mangle)]
pub fn dma_alloc_coherent_fxmac(pages: usize) -> (usize, usize) {
let vaddr = if let Ok(start_vaddr) = global_allocator().alloc_pages(pages, PAGE_SIZE) {
start_vaddr
} else {
error!("failed to alloc pages");
return (0, 0);
};
let paddr = virt_to_phys((vaddr).into());
debug!("alloc pages @ vaddr={:#x}, paddr={:#x}", vaddr, paddr);
(vaddr, paddr.as_usize())
}
fn dma_alloc_coherent(pages: usize) -> (usize, usize) {
let vaddr = if let Ok(start_vaddr) = global_allocator().alloc_pages(pages, 4096) {
start_vaddr
} else {
error!("failed to alloc pages");
return (0, 0);
};
let paddr = axhal::mem::virt_to_phys((vaddr).into());
debug!("alloc pages @ vaddr={:#x}, paddr={:#x}", vaddr, paddr);
(vaddr, paddr.as_usize())
}

fn dma_free_coherent(vaddr: usize, pages: usize) {
global_allocator().dealloc_pages(vaddr, pages);
}

#[unsafe(no_mangle)]
fn dma_free_coherent_fxmac(vaddr: usize, pages: usize) {
global_allocator().dealloc_pages(vaddr, pages);
fn dma_request_irq(_irq: usize, _handler: fn()) {
warn!("unimplemented dma_request_irq for fxmax");
}
}

register_net_driver!(FXmacDriver, axdriver_net::fxmac::FXmacNic);
Expand Down
2 changes: 1 addition & 1 deletion scripts/make/platform.mk
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ _kernel_base := $(subst _,,$(shell axconfig-gen configs/platforms/$(PLATFORM).to
phtpi: build
@echo 'Create legacy uboot image for PhytiumPi: $(_uboot_img)'
mkimage -A arm64 -O linux -C none -T kernel -a $(_kernel_base) -e $(_kernel_base) -n "ArceOS for PhytiumPi" -d $(OUT_BIN) $(_uboot_img)
echo 'Please boot from uboot> tftpboot $(_kernel_base) $(_uboot_img); bootm $(_kernel_base) - $${fdtcontroladdr}'
@echo 'Please boot from uboot> tftpboot $(_kernel_base) $(_uboot_img); bootm $(_kernel_base) - $${fdtcontroladdr}'
endif

0 comments on commit 42c5098

Please sign in to comment.