Skip to content

Commit

Permalink
[feature] Added ethernet driver: fxmac for PhytiumPi
Browse files Browse the repository at this point in the history
  • Loading branch information
elliott10 committed Jan 23, 2025
1 parent d9bbf6c commit c227818
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 3 deletions.
1 change: 1 addition & 0 deletions api/axfeat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ bus-mmio = ["axdriver?/bus-mmio"]
bus-pci = ["axdriver?/bus-pci"]
driver-ramdisk = ["axdriver?/ramdisk", "axfs?/use-ramdisk"]
driver-ixgbe = ["axdriver?/ixgbe"]
driver-fxmac = ["axdriver?/fxmac"] # fxmac ethernet driver for PhytiumPi
driver-bcm2835-sdhci = ["axdriver?/bcm2835-sdhci"]

# Logging
Expand Down
2 changes: 1 addition & 1 deletion configs/platforms/aarch64-phytium-pi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ gicd-paddr = 0x3088_0000 # uint
psci-method = "smc" # str

# CPU Hardware ID list
cpu-id-list = [0x0, 0x100, 0x200, 0x201]
cpu-id-list = [0x200, 0x201, 0x00, 0x100]
3 changes: 2 additions & 1 deletion modules/axdriver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ virtio-gpu = ["display", "virtio", "axdriver_virtio/gpu"]
ramdisk = ["block", "axdriver_block/ramdisk"]
bcm2835-sdhci = ["block", "axdriver_block/bcm2835-sdhci"]
ixgbe = ["net", "axdriver_net/ixgbe", "dep:axalloc", "dep:axhal", "dep:axdma"]
fxmac = ["net", "axdriver_net/fxmac", "dep:axalloc", "dep:axhal", "dep:axdma"]
# more devices example: e1000 = ["net", "axdriver_net/e1000"]

default = ["bus-pci"]
Expand All @@ -43,4 +44,4 @@ axdriver_virtio = { git = "https://github.com/arceos-org/axdriver_crates.git", t
axalloc = { workspace = true, optional = true }
axhal = { workspace = true, optional = true }
axconfig = { workspace = true, optional = true }
axdma = { workspace = true, optional = true }
axdma = { workspace = true, optional = true }
2 changes: 1 addition & 1 deletion modules/axdriver/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const NET_DEV_FEATURES: &[&str] = &["ixgbe", "virtio-net"];
const NET_DEV_FEATURES: &[&str] = &["fxmac", "ixgbe", "virtio-net"];
const BLOCK_DEV_FEATURES: &[&str] = &["ramdisk", "bcm2835-sdhci", "virtio-blk"];
const DISPLAY_DEV_FEATURES: &[&str] = &["virtio-gpu"];

Expand Down
46 changes: 46 additions & 0 deletions modules/axdriver/src/drivers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,49 @@ 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()
}

#[unsafe(no_mangle)]
pub fn phys_to_virt_fxmac(addr: usize) -> usize {
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())
}

#[unsafe(no_mangle)]
fn dma_free_coherent_fxmac(vaddr: usize, pages: usize) {
global_allocator().dealloc_pages(vaddr, pages);
}

register_net_driver!(FXmacDriver, axdriver_net::fxmac::FXmacNic);

pub struct FXmacDriver;
impl DriverProbe for FXmacDriver {
fn probe_global() -> Option<AxDeviceEnum> {
info!("fxmac for phytiumpi probe global");
axdriver_net::fxmac::FXmacNic::init(0).ok().map(AxDeviceEnum::from_net)
}
}
}
}
5 changes: 5 additions & 0 deletions modules/axdriver/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,10 @@ macro_rules! for_each_drivers {
type $drv_type = crate::drivers::IxgbeDriver;
$code
}
#[cfg(net_dev = "fxmac")]
{
type $drv_type = crate::drivers::FXmacDriver;
$code
}
}};
}
9 changes: 9 additions & 0 deletions scripts/make/platform.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ else
endif
ARCH := $(_arch)
endif

ifeq ($(PLATFORM), aarch64-phytium-pi)
_uboot_img := arceos-phtpi.uImage
_kernel_base := $(subst _,,$(shell axconfig-gen configs/platforms/$(PLATFORM).toml -r plat.kernel-base-paddr))
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}'
endif
1 change: 1 addition & 0 deletions ulib/axstd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ bus-mmio = ["axfeat/bus-mmio"]
bus-pci = ["axfeat/bus-pci"]
driver-ramdisk = ["axfeat/driver-ramdisk"]
driver-ixgbe = ["axfeat/driver-ixgbe"]
driver-fxmac = ["axfeat/driver-fxmac"]
driver-bcm2835-sdhci = ["axfeat/driver-bcm2835-sdhci"]

# Logging
Expand Down

0 comments on commit c227818

Please sign in to comment.