maint: migrate to rustc 1.94.0-nightly

This commit is contained in:
2026-01-06 14:41:08 +02:00
parent 3491e1a227
commit 57143f9d8d
325 changed files with 919 additions and 910 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
[package]
name = "yggdrasil-kernel"
version = "0.1.0"
edition = "2021"
edition = "2024"
build = "build.rs"
authors = ["Mark Poliakov <mark@alnyan.me>"]
+1 -1
View File
@@ -1,7 +1,7 @@
[package]
name = "kernel-arch"
version = "0.1.0"
edition = "2021"
edition = "2024"
[target.'cfg(all(target_os = "none", target_arch = "x86_64"))'.dependencies]
kernel-arch-x86_64.path = "x86_64"
+1 -1
View File
@@ -1,7 +1,7 @@
[package]
name = "kernel-arch-aarch64"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]
yggdrasil-abi.workspace = true
+21 -16
View File
@@ -66,7 +66,7 @@ impl FpContext {
///
/// It is up to the caller to ensure `this` is a valid pointer to store the FPU context in.
pub unsafe fn store(this: *mut Self) {
__aarch64_fp_store_context(this as _)
unsafe { __aarch64_fp_store_context(this as _) }
}
/// Loads the FPU with the context stored in `this` pointer.
@@ -75,7 +75,7 @@ impl FpContext {
///
/// It is up to the caller to ensure `this` is a valid pointer to load the FPU context from.
pub unsafe fn restore(this: *const Self) {
__aarch64_fp_restore_context(this as _)
unsafe { __aarch64_fp_restore_context(this as _) }
}
}
@@ -177,7 +177,12 @@ impl<K: KernelTableManager, PA: PhysicalMemoryAllocator<Address = PhysicalAddres
stack.push(entry as _);
stack.push(arg);
setup_common_context(&mut stack, __aarch64_task_enter_kernel as _, 0, 0);
setup_common_context(
&mut stack,
(__aarch64_task_enter_kernel as *const ()).addr(),
0,
0,
);
let sp = stack.build();
@@ -212,7 +217,7 @@ impl<K: KernelTableManager, PA: PhysicalMemoryAllocator<Address = PhysicalAddres
setup_common_context(
&mut stack,
__aarch64_task_enter_user as _,
(__aarch64_task_enter_user as *const ()).addr(),
ttbr0,
context.thread_pointer as _,
);
@@ -231,9 +236,8 @@ impl<K: KernelTableManager, PA: PhysicalMemoryAllocator<Address = PhysicalAddres
}
unsafe fn enter(&self) -> ! {
FpContext::restore(self.fp_context.get());
__aarch64_enter_task(self.inner.get())
unsafe { FpContext::restore(self.fp_context.get()) };
unsafe { __aarch64_enter_task(self.inner.get()) }
}
unsafe fn switch(&self, from: &Self) {
@@ -241,19 +245,20 @@ impl<K: KernelTableManager, PA: PhysicalMemoryAllocator<Address = PhysicalAddres
let src = from.inner.get();
if dst != src {
// Save the old context
FpContext::store(from.fp_context.get());
// Load next context
FpContext::restore(self.fp_context.get());
unsafe {
// Save the old context
FpContext::store(from.fp_context.get());
// Load next context
FpContext::restore(self.fp_context.get());
__aarch64_switch_task(self.inner.get(), from.inner.get())
__aarch64_switch_task(self.inner.get(), from.inner.get())
}
}
}
unsafe fn switch_and_drop(&self, thread: *const ()) {
FpContext::restore(self.fp_context.get());
__aarch64_switch_task_and_drop(self.inner.get(), thread);
unsafe { FpContext::restore(self.fp_context.get()) };
unsafe { __aarch64_switch_task_and_drop(self.inner.get(), thread) };
}
fn set_thread_pointer(&self, _tp: usize) {
@@ -293,7 +298,7 @@ fn setup_common_context(builder: &mut StackBuilder, entry: usize, ttbr0: u64, tp
builder.push(0); // x19
}
extern "C" {
unsafe extern "C" {
fn __aarch64_enter_task(to: *mut TaskContextInner) -> !;
fn __aarch64_switch_task(to: *mut TaskContextInner, from: *mut TaskContextInner);
fn __aarch64_switch_task_and_drop(to: *mut TaskContextInner, thread: *const ()) -> !;
+3 -3
View File
@@ -13,11 +13,11 @@ use aarch64_cpu::{
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use device_api::interrupt::LocalInterruptController;
use kernel_arch_interface::{
Architecture,
cpu::{CpuData, CpuImpl, IpiQueue},
guard::IrqGuard,
task::Scheduler,
util::OneTimeInit,
Architecture,
};
use tock_registers::interfaces::{ReadWriteable, Readable, Writeable};
@@ -25,7 +25,7 @@ pub mod context;
pub mod mem;
pub use context::TaskContextImpl;
pub use mem::{process::ProcessAddressSpaceImpl, KernelTableManagerImpl};
pub use mem::{KernelTableManagerImpl, process::ProcessAddressSpaceImpl};
pub struct ArchitectureImpl;
@@ -101,7 +101,7 @@ impl Architecture for ArchitectureImpl {
let id = (MPIDR_EL1.get() & 0xFF) as u32;
let cpu = Box::leak(Box::new(CpuImpl::<Self, S>::new(id, data)));
cpu.set_local();
unsafe { cpu.set_local() };
}
fn local_cpu() -> *mut () {
+19 -15
View File
@@ -1,7 +1,7 @@
use core::ops::Range;
use aarch64_cpu::registers::{TTBR0_EL1, TTBR1_EL1};
use kernel_arch_interface::{mem::DeviceMemoryAttributes, KERNEL_VIRT_OFFSET};
use kernel_arch_interface::{KERNEL_VIRT_OFFSET, mem::DeviceMemoryAttributes};
use libk_mm_interface::{
address::PhysicalAddress,
device::{DevicePageManager, DevicePageTableLevel},
@@ -10,7 +10,7 @@ use libk_mm_interface::{
use crate::mem::{
auto_lower_address,
table::{PageAttributes, PageEntry, PageTable, L1, L2, L3},
table::{L1, L2, L3, PageAttributes, PageEntry, PageTable},
tlb_flush_range_va,
};
@@ -98,22 +98,26 @@ impl DevicePageTableLevel for L3DeviceMemory {
}
pub unsafe fn setup() {
// 0..IDENTITY_SIZE_L1 -> lower RAM region
for i in 0..IDENTITY_SIZE_L1 {
let phys = PhysicalAddress::from_usize(i << L1::SHIFT);
KERNEL_L1[i] = PageEntry::normal_block(phys, PageAttributes::empty());
}
unsafe {
// 0..IDENTITY_SIZE_L1 -> lower RAM region
for i in 0..IDENTITY_SIZE_L1 {
let phys = PhysicalAddress::from_usize(i << L1::SHIFT);
KERNEL_L1[i] = PageEntry::normal_block(phys, PageAttributes::empty());
}
// DEVICE_L1 -> Device L2 table
// 0..DEVICE_MAPPING_L3_COUNT -> Device L3 tables -> Device L3 pages
// ..512 -> Device L2 pages
for i in 0..DEVICE_MAPPING_L3_COUNT {
// DEVICE_L1 -> Device L2 table
// 0..DEVICE_MAPPING_L3_COUNT -> Device L3 tables -> Device L3 pages
// ..512 -> Device L2 pages
for i in 0..DEVICE_MAPPING_L3_COUNT {
let phys = PhysicalAddress::from_usize(auto_lower_address(
&raw const DEVICE_MEMORY.normal.0[i],
));
DEVICE_MEMORY.large.0[i] = PageEntry::table(phys, PageAttributes::empty());
}
let phys =
PhysicalAddress::from_usize(auto_lower_address(&raw const DEVICE_MEMORY.normal.0[i]));
DEVICE_MEMORY.large.0[i] = PageEntry::table(phys, PageAttributes::empty());
PhysicalAddress::from_usize(auto_lower_address(&raw const DEVICE_MEMORY.large.0));
KERNEL_L1[DEVICE_L1] = PageEntry::table(phys, PageAttributes::empty());
}
let phys = PhysicalAddress::from_usize(auto_lower_address(&raw const DEVICE_MEMORY.large.0));
KERNEL_L1[DEVICE_L1] = PageEntry::table(phys, PageAttributes::empty());
}
pub unsafe fn load() {
+20 -12
View File
@@ -4,9 +4,9 @@ use aarch64_cpu::{
registers::{MAIR_EL1, SCTLR_EL1, TCR_EL1},
};
use kernel_arch_interface::{
KERNEL_VIRT_OFFSET,
mem::{DeviceMemoryAttributes, KernelTableManager, RawDeviceMemoryMapping},
sync::IrqSafeSpinlock,
KERNEL_VIRT_OFFSET,
};
use libk_mm_interface::{address::PhysicalAddress, table::EntryLevel};
use tock_registers::interfaces::{ReadWriteable, Writeable};
@@ -14,7 +14,7 @@ use yggdrasil_abi::error::Error;
pub use intrinsics::*;
use crate::{mem::table::L1, ArchitectureImpl};
use crate::{ArchitectureImpl, mem::table::L1};
pub mod fixed;
pub mod intrinsics;
@@ -52,14 +52,18 @@ impl KernelTableManager for KernelTableManagerImpl {
attrs: DeviceMemoryAttributes,
) -> Result<RawDeviceMemoryMapping<Self>, Error> {
let _lock = KERNEL_MEMORY_LOCK.lock();
#[allow(static_mut_refs)]
fixed::DEVICE_MEMORY.map_device_pages(PhysicalAddress::from_u64(base), count, attrs)
unsafe {
#[allow(static_mut_refs)]
fixed::DEVICE_MEMORY.map_device_pages(PhysicalAddress::from_u64(base), count, attrs)
}
}
unsafe fn unmap_device_pages(mapping: &RawDeviceMemoryMapping<Self>) {
let _lock = KERNEL_MEMORY_LOCK.lock();
#[allow(static_mut_refs)]
fixed::DEVICE_MEMORY.unmap_device_pages(mapping);
unsafe {
#[allow(static_mut_refs)]
fixed::DEVICE_MEMORY.unmap_device_pages(mapping);
}
}
}
@@ -132,15 +136,19 @@ unsafe fn enable_mmu() {
SCTLR_EL1.modify(SCTLR_EL1::M::Enable);
// Enable caches
enable_icache();
enable_dcache();
unsafe {
enable_icache();
enable_dcache();
}
}
pub unsafe fn init_lower(bsp: bool) {
setup_memory_attributes();
if bsp {
fixed::setup();
unsafe {
if bsp {
fixed::setup();
}
fixed::load();
enable_mmu();
}
fixed::load();
enable_mmu();
}
+6 -4
View File
@@ -14,11 +14,11 @@ use libk_mm_interface::{
};
use yggdrasil_abi::error::Error;
use crate::{mem::table::PageEntry, KernelTableManagerImpl};
use crate::{KernelTableManagerImpl, mem::table::PageEntry};
use super::{
dc_cvac, ic_iallu,
table::{PageAttributes, PageTable, L1, L2, L3},
table::{L1, L2, L3, PageAttributes, PageTable},
tlb_flush_asid, tlb_flush_vaae1,
};
@@ -97,8 +97,10 @@ impl<TA: TableAllocator> ProcessAddressSpaceManager<TA> for ProcessAddressSpaceI
}
unsafe fn clear(&mut self) {
self.l1
.drop_range::<TA>(0..((Self::UPPER_LIMIT_PFN * L3::SIZE).page_index::<L1>()));
unsafe {
self.l1
.drop_range::<TA>(0..((Self::UPPER_LIMIT_PFN * L3::SIZE).page_index::<L1>()))
};
}
}
+11 -7
View File
@@ -103,8 +103,8 @@ impl<L: EntryLevel> PageTable<L> {
}
}
pub fn new_zeroed<'a, TA: TableAllocator>(
) -> Result<PhysicalRefMut<'a, Self, KernelTableManagerImpl>, Error> {
pub fn new_zeroed<'a, TA: TableAllocator>()
-> Result<PhysicalRefMut<'a, Self, KernelTableManagerImpl>, Error> {
let physical = TA::allocate_page_table()?;
let mut table =
unsafe { PhysicalRefMut::<'a, Self, KernelTableManagerImpl>::map(physical) };
@@ -132,7 +132,7 @@ impl<L: EntryLevel> PageTable<L> {
return None;
}
let inner = PhysicalRefMut::map(physical);
let inner = unsafe { PhysicalRefMut::map(physical) };
Some(inner)
}
}
@@ -234,12 +234,16 @@ where
let entry = self[index];
if let Some(table) = entry.as_table() {
let mut table_ref: PhysicalRefMut<PageTable<L::NextLevel>, KernelTableManagerImpl> =
PhysicalRefMut::map(table);
unsafe {
let mut table_ref: PhysicalRefMut<
PageTable<L::NextLevel>,
KernelTableManagerImpl,
> = PhysicalRefMut::map(table);
table_ref.drop_all::<TA>();
table_ref.drop_all::<TA>();
TA::free_page_table(table);
TA::free_page_table(table);
}
} else if entry.is_present() {
// Memory must've been cleared beforehand, so no non-table entries must be present
panic!(
+1 -1
View File
@@ -7,12 +7,12 @@ use std::{
use device_api::dma::{DmaAllocation, DmaAllocator};
use kernel_arch_interface::{
Architecture,
cpu::{CpuData, IpiQueue},
mem::{
DeviceMemoryAttributes, KernelTableManager, PhysicalMemoryAllocator, RawDeviceMemoryMapping,
},
task::{Scheduler, TaskContext, UserContextInfo},
Architecture,
};
use libk_mm_interface::{
address::PhysicalAddress,
+1 -1
View File
@@ -7,7 +7,7 @@ use alloc::vec::Vec;
use device_api::interrupt::IpiMessage;
use crate::{
guard::IrqGuard, sync::IrqSafeSpinlock, task::Scheduler, util::OneTimeInit, Architecture,
Architecture, guard::IrqGuard, sync::IrqSafeSpinlock, task::Scheduler, util::OneTimeInit,
};
#[repr(C, align(0x10))]
+1 -1
View File
@@ -6,7 +6,7 @@ use core::{
sync::atomic::{AtomicBool, Ordering},
};
use crate::{guard::IrqGuard, Architecture};
use crate::{Architecture, guard::IrqGuard};
pub struct Spinlock<A: Architecture, T> {
value: UnsafeCell<T>,
+4 -4
View File
@@ -1,9 +1,9 @@
use core::{arch::global_asm, cell::UnsafeCell, marker::PhantomData};
use kernel_arch_interface::{
Architecture,
mem::{KernelTableManager, PhysicalMemoryAllocator},
task::{StackBuilder, TaskContext, UserContextInfo},
Architecture,
};
use libk_mm_interface::address::PhysicalAddress;
use tock_registers::{
@@ -13,9 +13,9 @@ use tock_registers::{
use yggdrasil_abi::error::Error;
use crate::{
ArchitectureImpl, PerCpuData,
mem::{self},
registers::SATP,
ArchitectureImpl, PerCpuData,
};
pub const CONTEXT_SIZE: usize = 14 * size_of::<usize>();
@@ -86,7 +86,7 @@ impl<K: KernelTableManager, PA: PhysicalMemoryAllocator<Address = PhysicalAddres
stack.push(context.entry);
stack.push(context.argument);
setup_common_context(&mut stack, __rv64_task_enter_user as _);
setup_common_context(&mut stack, (__rv64_task_enter_user as *const ()).addr());
let sp = stack.build();
let satp = InMemoryRegister::new(0);
@@ -118,7 +118,7 @@ impl<K: KernelTableManager, PA: PhysicalMemoryAllocator<Address = PhysicalAddres
stack.push(entry as _);
stack.push(arg);
setup_common_context(&mut stack, __rv64_task_enter_kernel as _);
setup_common_context(&mut stack, (__rv64_task_enter_kernel as *const ()).addr());
let sp = stack.build();
+2 -2
View File
@@ -11,18 +11,18 @@ use core::{
use alloc::{boxed::Box, collections::btree_map::BTreeMap, vec::Vec};
use device_api::interrupt::LocalInterruptController;
use kernel_arch_interface::{
Architecture,
cpu::{CpuData, CpuImpl, IpiQueue},
sync::IrqSafeSpinlock,
task::Scheduler,
util::OneTimeInit,
Architecture,
};
use tock_registers::interfaces::{ReadWriteable, Readable};
use registers::SSTATUS;
pub mod mem;
pub use mem::{process::ProcessAddressSpaceImpl, KernelTableManagerImpl};
pub use mem::{KernelTableManagerImpl, process::ProcessAddressSpaceImpl};
pub mod context;
pub use context::TaskContextImpl;
pub mod intrinsics;
+4 -5
View File
@@ -2,12 +2,11 @@ use kernel_arch_interface::sync::IrqSafeSpinlock;
use libk_mm_interface::{address::PhysicalAddress, table::EntryLevel};
use crate::{
mem::{
auto_lower_address,
table::{PageEntry, PageTable, L1},
KERNEL_VIRT_OFFSET,
},
ArchitectureImpl,
mem::{
KERNEL_VIRT_OFFSET, auto_lower_address,
table::{L1, PageEntry, PageTable},
},
};
pub const IDENTITY_SIZE_L1: usize = 64;
+2 -2
View File
@@ -3,13 +3,13 @@ use kernel_arch_interface::mem::{
};
use libk_mm_interface::{
address::PhysicalAddress,
table::{page_index, EntryLevel, EntryLevelExt},
table::{EntryLevel, EntryLevelExt, page_index},
};
use tock_registers::interfaces::Writeable;
use yggdrasil_abi::error::Error;
use crate::{
mem::table::{PageTable, L1, L3},
mem::table::{L1, L3, PageTable},
registers::SATP,
};
+1 -1
View File
@@ -19,8 +19,8 @@ use crate::mem::{
};
use super::{
table::{DroppableRange, PageTable, L1, L2, L3},
KernelTableManagerImpl, USER_BOUNDARY,
table::{DroppableRange, L1, L2, L3, PageTable},
};
pub struct ProcessAddressSpaceImpl<TA: TableAllocator> {
+4 -4
View File
@@ -10,8 +10,8 @@ use libk_mm_interface::{
pointer::{PhysicalRef, PhysicalRefMut},
process::PageAttributeUpdate,
table::{
page_index, EntryLevel, EntryLevelDrop, NextPageTable, NonTerminalEntryLevel,
TableAllocator,
EntryLevel, EntryLevelDrop, NextPageTable, NonTerminalEntryLevel, TableAllocator,
page_index,
},
};
use yggdrasil_abi::error::Error;
@@ -109,8 +109,8 @@ impl<L: EntryLevel> PageTable<L> {
}
}
pub fn new_zeroed<'a, TA: TableAllocator>(
) -> Result<PhysicalRefMut<'a, PageTable<L>, KernelTableManagerImpl>, Error> {
pub fn new_zeroed<'a, TA: TableAllocator>()
-> Result<PhysicalRefMut<'a, PageTable<L>, KernelTableManagerImpl>, Error> {
let physical = TA::allocate_page_table()?;
let mut table =
unsafe { PhysicalRefMut::<'a, Self, KernelTableManagerImpl>::map(physical) };
+1 -5
View File
@@ -78,11 +78,7 @@ unsafe fn sbi_do_call(
);
}
let a0 = a0 as i64;
if a0 == 0 {
Ok(a1)
} else {
Err(a0.into())
}
if a0 == 0 { Ok(a1) } else { Err(a0.into()) }
}
pub fn sbi_hart_start(hart_id: u64, start_addr: u64, opaque: u64) -> Result<(), Error> {
+1 -1
View File
@@ -35,7 +35,7 @@ cfg_if! {
pub use imp::{ArchitectureImpl, KernelTableManagerImpl, ProcessAddressSpaceImpl, TaskContextImpl};
pub use kernel_arch_interface::{guard, mem, sync, task, util, Architecture, KERNEL_VIRT_OFFSET};
pub use kernel_arch_interface::{Architecture, KERNEL_VIRT_OFFSET, guard, mem, sync, task, util};
pub type CpuImpl<S> = kernel_arch_interface::cpu::CpuImpl<ArchitectureImpl, S>;
pub type LocalCpuImpl<'a, S> = kernel_arch_interface::cpu::LocalCpuImpl<'a, ArchitectureImpl, S>;
+1 -1
View File
@@ -1,4 +1,4 @@
#![feature(iter_chain, new_zeroed_alloc, box_as_ptr)]
#![feature(box_as_ptr)]
#![allow(clippy::new_without_default)]
#![no_std]
+4 -4
View File
@@ -4,14 +4,14 @@ use kernel_arch_interface::{
mem::{KernelTableManager, PhysicalMemoryAllocator},
task::{ForkFrame, StackBuilder, TaskContext, TaskFrame, UserContextInfo},
};
use kernel_arch_x86::registers::{FpuContext, CR3, MSR_IA32_FS_BASE};
use kernel_arch_x86::registers::{CR3, FpuContext, MSR_IA32_FS_BASE};
use libk_mm_interface::address::PhysicalAddress;
use tock_registers::interfaces::Writeable;
use yggdrasil_abi::{arch::SavedFrame, error::Error};
use crate::{
mem::{auto_lower_address, fixed},
ArchitectureImpl,
mem::{auto_lower_address, fixed},
};
/// Frame saved onto the stack when taking an IRQ
@@ -445,7 +445,7 @@ impl<K: KernelTableManager, PA: PhysicalMemoryAllocator<Address = PhysicalAddres
stack.push(entry as _);
stack.push(arg);
setup_common_context(&mut stack, __x86_64_task_enter_kernel as _);
setup_common_context(&mut stack, (__x86_64_task_enter_kernel as *const ()).addr());
let sp = stack.build();
@@ -483,7 +483,7 @@ impl<K: KernelTableManager, PA: PhysicalMemoryAllocator<Address = PhysicalAddres
stack.push(context.argument);
stack.push(context.stack_pointer);
setup_common_context(&mut stack, __x86_64_task_enter_user as _);
setup_common_context(&mut stack, (__x86_64_task_enter_user as *const ()).addr());
let sp = stack.build();
let rsp0 = stack_base + USER_TASK_PAGES * 0x1000;
+2 -2
View File
@@ -11,10 +11,10 @@ use core::{
use alloc::{sync::Arc, vec::Vec};
use device_api::interrupt::{LocalInterruptController, MessageInterruptController};
use kernel_arch_interface::{
Architecture,
cpu::{CpuData, CpuImpl, IpiQueue},
task::Scheduler,
util::OneTimeInit,
Architecture,
};
use kernel_arch_x86::{cpuid::CpuFeatures, registers::MSR_IA32_KERNEL_GS_BASE};
use libk_mm_interface::address::PhysicalAddress;
@@ -24,7 +24,7 @@ pub mod context;
pub mod mem;
pub use context::TaskContextImpl;
pub use mem::{process::ProcessAddressSpaceImpl, KernelTableManagerImpl};
pub use mem::{KernelTableManagerImpl, process::ProcessAddressSpaceImpl};
pub struct ArchitectureImpl;
+4 -4
View File
@@ -1,19 +1,19 @@
use core::ops::Range;
use kernel_arch_interface::{mem::DeviceMemoryAttributes, sync::IrqSafeSpinlock, Architecture};
use kernel_arch_interface::{Architecture, mem::DeviceMemoryAttributes, sync::IrqSafeSpinlock};
use kernel_arch_x86::registers::CR3;
use libk_mm_interface::{
address::PhysicalAddress,
device::{DevicePageManager, DevicePageTableLevel},
table::{page_index, EntryLevel},
table::{EntryLevel, page_index},
};
use crate::{
ArchitectureImpl, KERNEL_VIRT_OFFSET,
mem::{
auto_lower_address,
table::{PageAttributes, PageEntry, PageTable, L0, L1, L2, L3},
table::{L0, L1, L2, L3, PageAttributes, PageEntry, PageTable},
},
ArchitectureImpl, KERNEL_VIRT_OFFSET,
};
pub const IDENTITY_SIZE_L1: usize = 64;
+1 -1
View File
@@ -6,7 +6,7 @@ use yggdrasil_abi::error::Error;
use crate::KERNEL_VIRT_OFFSET;
use self::table::{PageTable, L0, L1};
use self::table::{L0, L1, PageTable};
pub mod fixed;
pub mod process;
+1 -1
View File
@@ -15,7 +15,7 @@ use crate::KernelTableManagerImpl;
use super::{
clone_kernel_tables, flush_tlb_entry,
table::{PageEntry, PageTable, L0, L1, L2, L3},
table::{L0, L1, L2, L3, PageEntry, PageTable},
};
/// Represents a process or kernel address space. Because x86-64 does not have cool stuff like
+2 -2
View File
@@ -224,8 +224,8 @@ impl<L: EntryLevel> PageTable<L> {
}
/// Allocates a new page table, filling it with non-preset entries
pub fn new_zeroed<'a, TA: TableAllocator>(
) -> Result<PhysicalRefMut<'a, Self, KernelTableManagerImpl>, Error> {
pub fn new_zeroed<'a, TA: TableAllocator>()
-> Result<PhysicalRefMut<'a, Self, KernelTableManagerImpl>, Error> {
let physical = TA::allocate_page_table()?;
let mut table =
unsafe { PhysicalRefMut::<'a, Self, KernelTableManagerImpl>::map(physical) };
+2 -2
View File
@@ -6,9 +6,9 @@ use std::{
};
use abi_generator::{
abi::{ty::TypeWidth, AbiBuilder},
syntax::UnwrapFancy,
TargetEnv,
abi::{AbiBuilder, ty::TypeWidth},
syntax::UnwrapFancy,
};
fn build_x86_64() {
+2 -2
View File
@@ -7,7 +7,7 @@ use device_api::{
device::Device,
interrupt::{InterruptHandler, Irq, IrqVector},
};
use kernel_arch_x86::{intrinsics, ISA_IRQ_OFFSET};
use kernel_arch_x86::{ISA_IRQ_OFFSET, intrinsics};
use libk::device::external_interrupt_controller;
use libk_mm::{
address::{PhysicalAddress, Virtualize},
@@ -15,8 +15,8 @@ use libk_mm::{
};
use crate::{
mem::{read_memory, write_memory},
ACPI_SYSTEM,
mem::{read_memory, write_memory},
};
#[derive(Clone, Copy)]
+1 -1
View File
@@ -5,7 +5,7 @@ use acpi::AcpiTables;
use acpi_system::{AcpiInterruptMethod, AcpiSleepState, AcpiSystem};
use alloc::boxed::Box;
use libk::error::Error;
use libk_util::{sync::IrqSafeSpinlock, OneTimeInit};
use libk_util::{OneTimeInit, sync::IrqSafeSpinlock};
extern crate alloc;
+2 -2
View File
@@ -1,10 +1,10 @@
use core::mem::{size_of, MaybeUninit};
use core::mem::{MaybeUninit, size_of};
use device_api::dma::DmaAllocator;
use libk::dma::{BusAddress, DmaBuffer, DmaSliceMut};
use tock_registers::register_structs;
use crate::{data::AtaString, error::AhciError, MAX_PRD_SIZE};
use crate::{MAX_PRD_SIZE, data::AtaString, error::AhciError};
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[repr(u8)]
+3 -3
View File
@@ -7,9 +7,9 @@ use libk_util::{ConstAssert, IsTrue};
use static_assertions::const_assert_eq;
use crate::{
MAX_PRD_SIZE,
command::{AtaCommand, AtaIdentify, AtaIdentifyResponse},
error::AhciError,
MAX_PRD_SIZE,
};
pub const COMMAND_LIST_LENGTH: usize = 32;
@@ -20,7 +20,7 @@ const AHCI_FIS_REG_H2D: u8 = 0x27;
#[repr(C)]
pub struct AtaString<const N: usize>
where
ConstAssert<{ N % 2 == 0 }>: IsTrue,
ConstAssert<{ N.is_multiple_of(2) }>: IsTrue,
{
data: [u8; N],
}
@@ -243,7 +243,7 @@ impl AtaIdentifyResponse {
impl<const N: usize> AtaString<N>
where
ConstAssert<{ N % 2 == 0 }>: IsTrue,
ConstAssert<{ N.is_multiple_of(2) }>: IsTrue,
{
#[allow(clippy::inherent_to_string)]
pub fn to_string(&self) -> String {
+3 -3
View File
@@ -15,18 +15,18 @@ use device_api::{
use error::AhciError;
use libk::{device::manager::probe_partitions, dma::DmaBuffer, fs::devfs, task::runtime};
use libk_mm::device::DeviceMemoryIo;
use libk_util::{sync::IrqSafeSpinlock, OneTimeInit};
use libk_util::{OneTimeInit, sync::IrqSafeSpinlock};
use port::AhciPort;
use regs::{PortRegs, Regs};
use tock_registers::interfaces::{ReadWriteable, Readable, Writeable};
use ygg_driver_pci::{
PciCommandRegister, PciConfigurationSpace,
device::{PciDeviceInfo, PreferredInterruptMode},
macros::pci_driver,
PciCommandRegister, PciConfigurationSpace,
};
use yggdrasil_abi::{error::Error, io::FileMode};
use crate::regs::{Version, CAP, GHC, SSTS};
use crate::regs::{CAP, GHC, SSTS, Version};
mod command;
mod data;
+9 -9
View File
@@ -16,18 +16,18 @@ use libk::{
error::Error,
};
use libk_mm::{
address::PhysicalAddress, device::DeviceMemoryIo, table::MapAttributes, OnDemandPage,
PageProvider, VirtualPage,
OnDemandPage, PageProvider, VirtualPage, address::PhysicalAddress, device::DeviceMemoryIo,
table::MapAttributes,
};
use libk_util::{sync::IrqSafeSpinlock, waker::QueueWaker, OneTimeInit};
use libk_util::{OneTimeInit, sync::IrqSafeSpinlock, waker::QueueWaker};
use tock_registers::interfaces::{Readable, Writeable};
use crate::{
command::{AtaCommand, AtaIdentify, AtaReadDmaEx},
data::{CommandListEntry, CommandTable, ReceivedFis, COMMAND_LIST_LENGTH},
error::AhciError,
regs::{PortRegs, CMD_PENDING, CMD_READY, IE, TFD},
AhciController, MAX_COMMANDS, MAX_PRD_SIZE, SECTOR_SIZE,
command::{AtaCommand, AtaIdentify, AtaReadDmaEx},
data::{COMMAND_LIST_LENGTH, CommandListEntry, CommandTable, ReceivedFis},
error::AhciError,
regs::{CMD_PENDING, CMD_READY, IE, PortRegs, TFD},
};
#[derive(Clone, Copy, PartialEq, Debug)]
@@ -319,11 +319,11 @@ impl BlockDevice for AhciPort {
position: u64,
buffer: DmaSliceMut<'_, MaybeUninit<u8>>,
) -> Result<(), Error> {
if buffer.len() % SECTOR_SIZE != 0 {
if !buffer.len().is_multiple_of(SECTOR_SIZE) {
log::warn!("ahci: misaligned buffer size: {}", buffer.len());
return Err(Error::InvalidOperation);
}
if position % SECTOR_SIZE as u64 != 0 {
if !position.is_multiple_of(SECTOR_SIZE as u64) {
log::warn!("ahci: misaligned read");
return Err(Error::InvalidOperation);
}
+1 -1
View File
@@ -1,7 +1,7 @@
[package]
name = "ygg_driver_nvme"
version = "0.1.0"
edition = "2021"
edition = "2024"
authors = ["Mark Poliakov <mark@alnyan.me>"]
[dependencies]
+1 -1
View File
@@ -3,7 +3,7 @@
use core::fmt::{self, Write};
use libk::dma::BusAddress;
use tock_registers::{interfaces::Readable, register_structs, registers::ReadOnly, UIntLike};
use tock_registers::{UIntLike, interfaces::Readable, register_structs, registers::ReadOnly};
use crate::queue::PhysicalRegionPage;
+7 -7
View File
@@ -9,14 +9,14 @@ use libk::{
error::Error,
};
use libk_mm::{
OnDemandPage, PageProvider, PageSlice, VirtualPage,
address::{AsPhysicalAddress, PhysicalAddress},
table::MapAttributes,
OnDemandPage, PageProvider, PageSlice, VirtualPage,
};
use crate::{command::IdentifyNamespaceRequest, register_nvme_namespace, IoDirection};
use crate::{IoDirection, command::IdentifyNamespaceRequest, register_nvme_namespace};
use super::{error::NvmeError, NvmeController};
use super::{NvmeController, error::NvmeError};
#[allow(unused)]
pub struct NvmeNamespace {
@@ -92,10 +92,10 @@ impl BlockDevice for NvmeNamespace {
position: u64,
buffer: DmaSliceMut<'_, MaybeUninit<u8>>,
) -> Result<(), Error> {
if position % self.block_size() as u64 != 0 {
if !position.is_multiple_of(self.block_size() as u64) {
return Err(Error::InvalidOperation);
}
if buffer.len() % self.block_size() != 0 || buffer.is_empty() {
if !buffer.len().is_multiple_of(self.block_size()) || buffer.is_empty() {
return Err(Error::InvalidOperation);
}
let lba = position / self.block_size() as u64;
@@ -115,10 +115,10 @@ impl BlockDevice for NvmeNamespace {
}
async fn write_aligned(&self, position: u64, buffer: DmaSlice<'_, u8>) -> Result<(), Error> {
if position % self.block_size() as u64 != 0 {
if !position.is_multiple_of(self.block_size() as u64) {
return Err(Error::InvalidOperation);
}
if buffer.len() % self.block_size() != 0 || buffer.is_empty() {
if !buffer.len().is_multiple_of(self.block_size()) || buffer.is_empty() {
return Err(Error::InvalidOperation);
}
let lba = position / self.block_size() as u64;
+7 -7
View File
@@ -1,4 +1,4 @@
#![feature(const_trait_impl, let_chains, if_let_guard, maybe_uninit_slice)]
#![feature(const_trait_impl, if_let_guard)]
#![allow(missing_docs)]
#![no_std]
// TODO
@@ -7,7 +7,7 @@
extern crate alloc;
use core::{
mem::{size_of, MaybeUninit},
mem::{MaybeUninit, size_of},
sync::atomic::{AtomicUsize, Ordering},
time::Duration,
};
@@ -27,10 +27,10 @@ use libk::{
fs::devfs,
task::{cpu_count, cpu_index, runtime},
};
use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo, L3_PAGE_SIZE};
use libk_mm::{L3_PAGE_SIZE, address::PhysicalAddress, device::DeviceMemoryIo};
use libk_util::{
sync::{IrqGuard, IrqSafeSpinlock},
OneTimeInit,
sync::{IrqGuard, IrqSafeSpinlock},
};
use queue::PrpList;
use regs::{CAP, CC};
@@ -40,9 +40,9 @@ use tock_registers::{
registers::{ReadOnly, ReadWrite, WriteOnly},
};
use ygg_driver_pci::{
PciCommandRegister, PciConfigurationSpace,
device::{PciDeviceInfo, PreferredInterruptMode},
macros::pci_driver,
PciCommandRegister, PciConfigurationSpace,
};
use yggdrasil_abi::{error::Error, io::FileMode};
@@ -284,8 +284,8 @@ impl NvmeController {
unsafe fn doorbell_pair(&self, idx: usize) -> (*mut u32, *mut u32) {
let regs = self.regs.lock();
let sq_ptr = regs.doorbell_ptr(self.doorbell_shift, false, idx);
let cq_ptr = regs.doorbell_ptr(self.doorbell_shift, true, idx);
let sq_ptr = unsafe { regs.doorbell_ptr(self.doorbell_shift, false, idx) };
let cq_ptr = unsafe { regs.doorbell_ptr(self.doorbell_shift, true, idx) };
(sq_ptr, cq_ptr)
}
}
+1 -1
View File
@@ -112,7 +112,7 @@ impl PrpList {
size: usize,
) -> Result<Self, NvmeError> {
// TODO hardcoded page size
if base.into_u64() % 0x1000 != 0 {
if !base.into_u64().is_multiple_of(0x1000) {
todo!();
}
+5 -5
View File
@@ -1,4 +1,4 @@
#![feature(generic_const_exprs, maybe_uninit_slice)]
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]
#![no_std]
@@ -23,11 +23,11 @@ use libk::{
task::{runtime, sync::AsyncMutex},
};
use libk_mm::{
address::PhysicalAddress, table::MapAttributes, OnDemandPage, PageProvider, VirtualPage,
OnDemandPage, PageProvider, VirtualPage, address::PhysicalAddress, table::MapAttributes,
};
use libk_util::{
sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock},
OneTimeInit,
sync::{IrqSafeSpinlock, spin_rwlock::IrqSafeRwLock},
};
use transport::{ScsiTransport, ScsiTransportWrapper};
use yggdrasil_abi::io::FileMode;
@@ -214,11 +214,11 @@ impl BlockDevice for ScsiUnit {
position: u64,
buffer: DmaSliceMut<'_, MaybeUninit<u8>>,
) -> Result<(), Error> {
if position % self.lba_size as u64 != 0 {
if !position.is_multiple_of(self.lba_size as u64) {
log::warn!("scsi: misaligned read");
return Err(Error::InvalidArgument);
}
if buffer.len() % self.lba_size != 0 {
if !buffer.len().is_multiple_of(self.lba_size) {
log::warn!("scsi: misaligned buffer size");
return Err(Error::InvalidArgument);
}
+2 -2
View File
@@ -3,14 +3,14 @@ use device_api::{
device::{Device, DeviceInitContext},
interrupt::{InterruptHandler, IrqHandle, IrqVector},
};
use device_tree::driver::{device_tree_driver, Node, ProbeContext};
use device_tree::driver::{Node, ProbeContext, device_tree_driver};
use libk::{
debug::DebugSink,
device::manager::DEVICE_REGISTRY,
vfs::{Terminal, TerminalInput, TerminalOutput},
};
use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo};
use libk_util::{sync::IrqSafeSpinlock, OneTimeInit};
use libk_util::{OneTimeInit, sync::IrqSafeSpinlock};
use tock_registers::{
interfaces::{ReadWriteable, Readable, Writeable},
register_bitfields, register_structs,
+1 -1
View File
@@ -1,6 +1,6 @@
use alloc::sync::Arc;
use device_api::device::{Device, DeviceInitContext};
use device_tree::driver::{device_tree_driver, Node, ProbeContext};
use device_tree::driver::{Node, ProbeContext, device_tree_driver};
use libk::{
error::Error,
fs::sysfs::{self, nodes::SysfsRtcNode},
+4 -4
View File
@@ -11,11 +11,11 @@ use device_api::{
interrupt::{InterruptHandler, IrqHandle, IrqVector},
};
use device_tree::{
driver::{
device_tree_driver, util::generic_gpio_config, DeviceTreeGpioPins, DeviceTreePinController,
Node, ProbeContext,
},
DeviceTreePropertyRead, TProp,
driver::{
DeviceTreeGpioPins, DeviceTreePinController, Node, ProbeContext, device_tree_driver,
util::generic_gpio_config,
},
};
use libk::event::signal_gpio_event;
use libk_mm::device::DeviceMemoryIo;
+2 -2
View File
@@ -4,11 +4,11 @@ use device_api::{
device::{Device, DeviceInitContext},
};
use device_tree::{
driver::{device_tree_driver, DeviceTreeClockController, Node, ProbeContext},
DeviceTreePropertyRead, TProp,
driver::{DeviceTreeClockController, Node, ProbeContext, device_tree_driver},
};
use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo};
use libk_util::{sync::IrqSafeSpinlock, OneTimeInit};
use libk_util::{OneTimeInit, sync::IrqSafeSpinlock};
use tock_registers::{
interfaces::ReadWriteable,
register_bitfields, register_structs,
+2 -2
View File
@@ -4,14 +4,14 @@ use device_api::{
device::{Device, DeviceInitContext},
interrupt::{InterruptHandler, IrqHandle, IrqVector},
};
use device_tree::driver::{device_tree_driver, Node, ProbeContext};
use device_tree::driver::{Node, ProbeContext, device_tree_driver};
use libk::{
debug::DebugSink,
device::manager::DEVICE_REGISTRY,
vfs::{Terminal, TerminalInput, TerminalOutput},
};
use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo};
use libk_util::{sync::IrqSafeSpinlock, OneTimeInit};
use libk_util::{OneTimeInit, sync::IrqSafeSpinlock};
use tock_registers::{
interfaces::{ReadWriteable, Readable, Writeable},
register_bitfields, register_structs,
+4 -4
View File
@@ -5,11 +5,11 @@ use device_api::{
interrupt::{InterruptHandler, IrqHandle, IrqVector},
};
use device_tree::{
driver::{
device_tree_driver, util::generic_gpio_config, DeviceTreeGpioPins, DeviceTreePinController,
Node, ProbeContext,
},
DeviceTreePropertyRead, TProp,
driver::{
DeviceTreeGpioPins, DeviceTreePinController, Node, ProbeContext, device_tree_driver,
util::generic_gpio_config,
},
};
use libk_mm::device::DeviceMemoryIo;
use libk_util::sync::IrqSafeSpinlock;
+2 -2
View File
@@ -2,7 +2,7 @@ use core::{cell::UnsafeCell, mem::MaybeUninit};
use alloc::sync::Arc;
use device_api::device::{Device, DeviceInitContext};
use device_tree::driver::{device_tree_driver, Node, ProbeContext};
use device_tree::driver::{Node, ProbeContext, device_tree_driver};
use kernel_arch_aarch64::mem::table::L3;
use libk::device::{
display::{
@@ -11,10 +11,10 @@ use libk::device::{
manager::DEVICE_REGISTRY,
};
use libk_mm::{
OnDemandPage, PageBox, PageProvider, VirtualPage,
address::{AsPhysicalAddress, PhysicalAddress},
device::DeviceMemoryIo,
table::{EntryLevel, MapAttributes},
OnDemandPage, PageBox, PageProvider, VirtualPage,
};
use libk_util::sync::IrqSafeSpinlock;
use tock_registers::{
+7 -7
View File
@@ -6,11 +6,11 @@ use device_api::{
device::{Device, DeviceInitContext},
};
use device_tree::{
driver::{
device_tree_driver, lookup_phandle, DeviceTreeClockController, DeviceTreeResetController,
DeviceTreeSyscon, Node, ProbeContext,
},
DeviceTreePropertyRead, TProp,
driver::{
DeviceTreeClockController, DeviceTreeResetController, DeviceTreeSyscon, Node, ProbeContext,
device_tree_driver, lookup_phandle,
},
};
use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIoMut};
use libk_util::sync::IrqSafeSpinlock;
@@ -171,7 +171,7 @@ trait ClockDefinition {
const CLOCKS: &'static [Option<(&'static str, ClockDef)>];
}
const SYSCRG_CLOCKS: &'static [Option<(&'static str, ClockDef)>] = &const {
const SYSCRG_CLOCKS: &[Option<(&'static str, ClockDef)>] = &const {
use ClockDef::*;
let mut t = [const { None }; SYSCRG_CLOCK_COUNT];
@@ -230,7 +230,7 @@ const SYSCRG_CLOCKS: &'static [Option<(&'static str, ClockDef)>] = &const {
t
};
const AONCRG_CLOCKS: &'static [Option<(&'static str, ClockDef)>] = &const {
const AONCRG_CLOCKS: &[Option<(&'static str, ClockDef)>] = &const {
use ClockDef::*;
let mut t = [const { None }; AONCRG_CLOCK_COUNT];
@@ -262,7 +262,7 @@ const AONCRG_CLOCKS: &'static [Option<(&'static str, ClockDef)>] = &const {
t
};
const STGCRG_CLOCKS: &'static [Option<(&'static str, ClockDef)>] = &const {
const STGCRG_CLOCKS: &[Option<(&'static str, ClockDef)>] = &const {
use ClockDef::*;
let mut t = [const { None }; STGCRG_CLOCK_COUNT];
+1 -1
View File
@@ -1,4 +1,4 @@
#![allow(unsafe_op_in_unsafe_fn)]
#![allow(unsafe_op_in_unsafe_fn, clippy::eq_op, clippy::erasing_op)]
#![no_std]
extern crate alloc;
+5 -6
View File
@@ -8,15 +8,14 @@ use device_api::{
},
};
use device_tree::{
driver::{
device_tree_driver,
util::{generic_gpio_config, GenericPinctrlBiasConfig, GenericPinctrlConfig},
DeviceTreeGpioPins, DeviceTreePinController, Node, ProbeContext,
},
DeviceTreePropertyRead, TProp,
driver::{
DeviceTreeGpioPins, DeviceTreePinController, Node, ProbeContext, device_tree_driver,
util::{GenericPinctrlBiasConfig, GenericPinctrlConfig, generic_gpio_config},
},
};
use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIoMut};
use libk_util::{bit::BitField, sync::IrqSafeSpinlock, OneTimeInit};
use libk_util::{OneTimeInit, bit::BitField, sync::IrqSafeSpinlock};
use yggdrasil_abi::error::Error;
#[derive(Debug)]
+1 -1
View File
@@ -1,6 +1,6 @@
use alloc::sync::Arc;
use device_api::device::{Device, DeviceInitContext};
use device_tree::driver::{device_tree_driver, Node, ProbeContext};
use device_tree::driver::{Node, ProbeContext, device_tree_driver};
use libk::{
error::Error,
fs::sysfs::{self, nodes::SysfsRtcNode},
+4 -4
View File
@@ -7,15 +7,15 @@ use device_api::{
},
};
use device_tree::{
driver::{
device_tree_driver, lookup_phandle, DeviceTreeInterruptController, Node, ProbeContext,
},
DeviceTreePropertyRead, TProp,
driver::{
DeviceTreeInterruptController, Node, ProbeContext, device_tree_driver, lookup_phandle,
},
};
use kernel_arch_riscv64::boot_hart_id;
use libk::{arch::Cpu, device::register_external_interrupt_controller};
use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo};
use libk_util::{sync::spin_rwlock::IrqSafeRwLock, OneTimeInit};
use libk_util::{OneTimeInit, sync::spin_rwlock::IrqSafeRwLock};
use tock_registers::{
interfaces::{Readable, Writeable},
register_structs,
+1 -1
View File
@@ -1,7 +1,7 @@
[package]
name = "ygg_driver_pci"
version = "0.1.0"
edition = "2021"
edition = "2024"
authors = ["Mark Poliakov <mark@alnyan.me>"]
[dependencies]
+1 -1
View File
@@ -498,7 +498,7 @@ impl MsiXVectorTableAccess<'_> {
impl MsiXVectorTable<'_> {
unsafe fn memory_from_raw_parts(base: PhysicalAddress, len: usize) -> Result<Self, Error> {
let vectors = DeviceMemoryIoMut::map_slice(base, len, Default::default())?;
let vectors = unsafe { DeviceMemoryIoMut::map_slice(base, len, Default::default()) }?;
Ok(Self {
access: MsiXVectorTableAccess::Memory(vectors),
len,
+15 -16
View File
@@ -9,13 +9,13 @@ use device_api::{
},
};
use libk::device::external_interrupt_controller;
use libk_util::{sync::spin_rwlock::IrqSafeRwLock, OneTimeInit};
use libk_util::{OneTimeInit, sync::spin_rwlock::IrqSafeRwLock};
use yggdrasil_abi::error::Error;
use crate::{
PciAddress, PciCommandRegister, PciConfigSpace, PciConfigurationSpace, PciSegmentInfo,
capability::{MsiCapability, MsiXCapability, MsiXVectorTable},
driver::PciDriver,
PciAddress, PciCommandRegister, PciConfigSpace, PciConfigurationSpace, PciSegmentInfo,
};
/// Describes a PCI device
@@ -152,22 +152,21 @@ impl PciDeviceInfo {
let mut result = None;
if want_msix
&& let Some(mut msix) = self.config_space.capability::<MsiXCapability>()
&& let Ok(mut vt) = msix.vector_table()
{
if let Ok(mut vt) = msix.vector_table() {
if let Some(mut msi) = self.config_space.capability::<MsiCapability>() {
msi.set_enabled(false);
}
vt.mask_all();
msix.set_function_mask(false);
msix.set_enabled(true);
result = Some(ConfiguredInterruptMode::MsiX(
msi_route.controller.clone(),
vt,
));
if let Some(mut msi) = self.config_space.capability::<MsiCapability>() {
msi.set_enabled(false);
}
vt.mask_all();
msix.set_function_mask(false);
msix.set_enabled(true);
result = Some(ConfiguredInterruptMode::MsiX(
msi_route.controller.clone(),
vt,
));
}
// Fall back to MSI if MSI-x is not available or not requested
+1 -1
View File
@@ -5,8 +5,8 @@ use device_api::interrupt::MessageInterruptController;
use libk::error::Error;
use crate::{
device::{PciInterrupt, PciInterruptRoute, PciMsiRoute},
PciAddress,
device::{PciInterrupt, PciInterruptRoute, PciMsiRoute},
};
#[derive(Debug)]
+3 -3
View File
@@ -1,6 +1,6 @@
//! PCI/PCIe bus interfaces
#![no_std]
#![feature(let_chains, decl_macro)]
#![feature(decl_macro)]
#![allow(clippy::missing_transmute_annotations, clippy::identity_op)]
extern crate alloc;
@@ -20,7 +20,7 @@ use libk::{
fs::sysfs::{self, object::KObject},
};
use libk_mm::address::PhysicalAddress;
use libk_util::{sync::IrqSafeSpinlock, OneTimeInit};
use libk_util::{OneTimeInit, sync::IrqSafeSpinlock};
use space::legacy;
use yggdrasil_abi::{error::Error, primitive_enum};
@@ -36,9 +36,9 @@ mod nodes;
mod space;
pub use space::{
PciConfigSpace, PciConfigurationSpace,
ecam::PciEcam,
legacy::{LegacyPciAccess, PciLegacyConfigurationSpace},
PciConfigSpace, PciConfigurationSpace,
};
bitflags! {
+1 -1
View File
@@ -17,7 +17,7 @@ pub macro pci_driver(
matches: [$($kind:ident $match:tt),+ $(,)?],
driver: $driver:tt
) {
#[link_section = ".init_array"]
#[unsafe(link_section = ".init_array")]
#[used]
static __REGISTER_FN: extern "C" fn() = __register_fn;
+1 -1
View File
@@ -8,7 +8,7 @@ use libk::{
};
use libk_util::sync::IrqSafeSpinlock;
use crate::{device::PciBusDevice, PciBaseAddress, PciCapabilityId, PciConfigurationSpace};
use crate::{PciBaseAddress, PciCapabilityId, PciConfigurationSpace, device::PciBusDevice};
pub(crate) fn make_sysfs_object(
device: PciBusDevice,
+2 -2
View File
@@ -32,7 +32,7 @@ impl PciEcam {
/// regions. The address must be aligned to a 4KiB boundary and be valid for accesses within a
/// 4KiB-sized range.
pub unsafe fn map(phys_addr: PhysicalAddress) -> Result<Self, Error> {
let mapping = DeviceMemoryMapping::map(phys_addr, 0x1000, Default::default())?;
let mapping = unsafe { DeviceMemoryMapping::map(phys_addr, 0x1000, Default::default()) }?;
Ok(Self { mapping })
}
@@ -53,7 +53,7 @@ impl PciEcam {
+ address.function as usize)
* 0x1000,
);
let this = Self::map(phys_addr)?;
let this = unsafe { Self::map(phys_addr) }?;
Ok(if this.is_valid() { Some(this) } else { None })
}
+6 -12
View File
@@ -2,7 +2,7 @@ use alloc::sync::Arc;
use legacy::PciLegacyConfigurationSpace;
use super::{PciAddress, PciBaseAddress, PciCapability, PciCapabilityId, PciEcam};
use crate::{device::PciInterruptPin, PciCommandRegister, PciStatusRegister};
use crate::{PciCommandRegister, PciStatusRegister, device::PciInterruptPin};
pub(super) mod ecam;
pub(super) mod legacy;
@@ -26,9 +26,7 @@ macro_rules! pci_config_field_setter {
$self.write_u32($offset, $value)
};
($self:ident, u16, $offset:expr, $value:expr) => {{
$self.write_u16($offset, $value)
}};
($self:ident, u16, $offset:expr, $value:expr) => {{ $self.write_u16($offset, $value) }};
($self:ident, u8, $offset:expr, $value:expr) => {
$self.write_u8($offset, $value)
@@ -222,11 +220,7 @@ pub trait PciConfigurationSpace {
fn interrupt_line(&self) -> Option<u8> {
let value = self.read_u8(0x3C);
if value < 16 {
Some(value)
} else {
None
}
if value < 16 { Some(value) } else { None }
}
/// # Safety
@@ -248,7 +242,7 @@ pub trait PciConfigurationSpace {
PciBaseAddress::Memory32(_) => PciBaseAddress::Memory32(0xFFFFFFF0),
PciBaseAddress::Memory64(_) => PciBaseAddress::Memory64(0xFFFFFFFFFFFFFFF0),
};
self.set_bar(index, mask_value);
unsafe { self.set_bar(index, mask_value) };
let new_value = self.bar(index).unwrap();
let size = match new_value {
@@ -258,7 +252,7 @@ pub trait PciConfigurationSpace {
_ => 0,
};
self.set_bar(index, orig_value);
unsafe { self.set_bar(index, orig_value) };
self.set_command(cmd);
size
@@ -302,7 +296,7 @@ pub trait PciConfigurationSpace {
fn bar(&self, index: usize) -> Option<PciBaseAddress> {
assert!(index < 6);
if index % 2 == 0 {
if index.is_multiple_of(2) {
let w0 = self.read_u32(0x10 + index * 4);
match w0 & 1 {
+1 -2
View File
@@ -4,9 +4,8 @@ use alloc::{collections::BTreeMap, sync::Arc};
use libk_util::{queue::UnboundedMpmcQueue, sync::spin_rwlock::IrqSafeRwLock};
use crate::{
class_driver,
UsbHostController, class_driver,
device::{UsbBusAddress, UsbDeviceAccess},
UsbHostController,
};
pub struct UsbBusManager {
@@ -7,7 +7,7 @@ use libk::{
dma::{DmaBuffer, DmaSliceMut},
error::Error,
};
use ygg_driver_scsi::{transport::ScsiTransport, ScsiEnclosure};
use ygg_driver_scsi::{ScsiEnclosure, transport::ScsiTransport};
use crate::{
communication::UsbDirection,
+1 -1
View File
@@ -5,6 +5,7 @@ use async_trait::async_trait;
use libk_util::sync::spin_rwlock::{IrqSafeRwLock, IrqSafeRwLockReadGuard};
use crate::{
UsbHostController,
error::UsbError,
info::{
UsbConfigurationInfo, UsbDeviceInfo, UsbEndpointInfo, UsbEndpointType, UsbInterfaceInfo,
@@ -17,7 +18,6 @@ use crate::{
UsbNormalPipeOut,
},
},
UsbHostController,
};
// High-level structures for info provided through descriptors
+2 -3
View File
@@ -1,10 +1,9 @@
#![no_std]
#![allow(clippy::new_without_default)]
#![allow(clippy::new_without_default, incomplete_features)]
#![feature(
generic_const_exprs,
iter_array_chunks,
maybe_uninit_slice,
maybe_uninit_as_bytes,
maybe_uninit_write_slice,
maybe_uninit_fill
)]
+2 -2
View File
@@ -1,5 +1,5 @@
use core::{
mem::{size_of, MaybeUninit},
mem::{MaybeUninit, size_of},
ops::Deref,
};
@@ -66,7 +66,7 @@ impl<U: UsbDescriptorRequest> UsbDeviceRequest for U {
}
fn decode_usb_string(bytes: &[u8]) -> Result<String, UsbError> {
if bytes.len() % 2 != 0 {
if !bytes.len().is_multiple_of(2) {
return Err(UsbError::InvalidDescriptorField);
}
+1 -1
View File
@@ -18,7 +18,7 @@ use libk::{
use walk::{DirentIter, DirentIterMut};
use yggdrasil_abi::io::{DirectoryEntry, FileType};
use crate::{file::RegularNode, inode::InodeAccess, symlink::SymlinkNode, Dirent, Ext2Fs, Inode};
use crate::{Dirent, Ext2Fs, Inode, file::RegularNode, inode::InodeAccess, symlink::SymlinkNode};
mod walk;
+1 -1
View File
@@ -9,7 +9,7 @@ use yggdrasil_abi::{
util::FixedString,
};
use crate::{access::InodeBlock, data::FsRequiredFeatures, Dirent, Ext2Fs};
use crate::{Dirent, Ext2Fs, access::InodeBlock, data::FsRequiredFeatures};
use super::DirentName;
+1 -1
View File
@@ -8,7 +8,7 @@ use libk::{
};
use yggdrasil_abi::io::OpenOptions;
use crate::{inode::InodeAccess, Ext2Fs};
use crate::{Ext2Fs, inode::InodeAccess};
pub struct RegularNode {
fs: Arc<Ext2Fs>,
+2 -2
View File
@@ -15,8 +15,8 @@ use yggdrasil_abi::{
};
use crate::{
access::InodeBlock, data::InodeMode, dir::DirectoryNode, file::RegularNode,
symlink::SymlinkNode, Ext2Fs, Inode,
Ext2Fs, Inode, access::InodeBlock, data::InodeMode, dir::DirectoryNode, file::RegularNode,
symlink::SymlinkNode,
};
pub struct InodeHolder {
+1 -1
View File
@@ -4,8 +4,8 @@ use libk::error::Error;
use yggdrasil_abi::io::FileType;
use crate::{
data::{FsReadonlyFeatures, DIRECT_BLOCK_COUNT},
Ext2Fs, Inode,
data::{DIRECT_BLOCK_COUNT, FsReadonlyFeatures},
};
pub mod cache;
+2 -2
View File
@@ -9,12 +9,12 @@ use core::mem;
use alloc::{boxed::Box, sync::Arc};
use async_trait::async_trait;
use bytemuck::Zeroable;
use data::{FsReadonlyFeatures, FsRequiredFeatures, DIRECT_BLOCK_COUNT};
use data::{DIRECT_BLOCK_COUNT, FsReadonlyFeatures, FsRequiredFeatures};
use dir::DirectoryNode;
use file::RegularNode;
use inode::{InodeAccess, InodeCache};
use libk::{
device::block::{cache::DeviceMapper, BlockDevice},
device::block::{BlockDevice, cache::DeviceMapper},
error::Error,
vfs::{Filesystem, FilesystemMountOption, NodeRef},
};
+1 -1
View File
@@ -8,7 +8,7 @@ use libk::{
};
use libk_util::sync::spin_rwlock::IrqSafeRwLock;
use crate::{inode::InodeAccess, Ext2Fs, Inode};
use crate::{Ext2Fs, Inode, inode::InodeAccess};
pub struct SymlinkNode {
fs: Arc<Ext2Fs>,
+2 -2
View File
@@ -12,7 +12,7 @@ use libk::{
};
use libk_util::{
get_le_u16, get_le_u32,
string::{chars_equal_ignore_case, Utf16LeStr},
string::{Utf16LeStr, chars_equal_ignore_case},
};
use yggdrasil_abi::{
io::{DirectoryEntry, FileMode, GroupId, UserId},
@@ -21,9 +21,9 @@ use yggdrasil_abi::{
};
use crate::{
Fat32Fs,
data::{ClusterNumber, FatStr},
file::FileNode,
Fat32Fs,
};
pub const DIRENT_SIZE: usize = 32;
+1 -1
View File
@@ -9,7 +9,7 @@ use libk::{
};
use yggdrasil_abi::io::OpenOptions;
use crate::{data::ClusterNumber, Fat32Fs};
use crate::{Fat32Fs, data::ClusterNumber};
pub struct FileNode {
pub(crate) fs: Arc<Fat32Fs>,
+1 -1
View File
@@ -5,7 +5,7 @@ use async_trait::async_trait;
use data::{Bpb, ClusterNumber, Fat32Ebpb, Fat32FsInfo};
use directory::DirectoryNode;
use libk::{
device::block::{cache::DeviceMapper, BlockDevice},
device::block::{BlockDevice, cache::DeviceMapper},
error::Error,
vfs::{Filesystem, FilesystemMountOption, Metadata, Node, NodeFlags, NodeRef},
};
+1
View File
@@ -0,0 +1 @@
+1 -1
View File
@@ -1,7 +1,7 @@
//! Block management interfaces and structures
use core::{
marker::PhantomData,
mem::{size_of, MaybeUninit},
mem::{MaybeUninit, size_of},
ops::{Deref, DerefMut},
ptr::NonNull,
};
+3 -3
View File
@@ -3,12 +3,12 @@ use core::sync::atomic::Ordering;
use alloc::sync::Arc;
use libk::vfs::{
impls::fixed_path_symlink_ext, CommonImpl, CreateFileType, CreateInfo, DirectoryImpl,
DirectoryOpenPosition, Metadata, Node, NodeFlags, NodeRef,
CommonImpl, CreateFileType, CreateInfo, DirectoryImpl, DirectoryOpenPosition, Metadata, Node,
NodeFlags, NodeRef, impls::fixed_path_symlink_ext,
};
use yggdrasil_abi::error::Error;
use crate::{block::BlockAllocator, file::FileNode, MemoryFilesystem, INO_COUNTER};
use crate::{INO_COUNTER, MemoryFilesystem, block::BlockAllocator, file::FileNode};
pub(crate) struct DirectoryNode<A: BlockAllocator> {
fs: Arc<MemoryFilesystem<A>>,
+2 -2
View File
@@ -2,10 +2,10 @@ use alloc::sync::Arc;
use core::any::Any;
use libk::vfs::{CommonImpl, InstanceData, Metadata, Node, NodeFlags, NodeRef, RegularImpl};
use libk_util::sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock};
use libk_util::sync::{IrqSafeSpinlock, spin_rwlock::IrqSafeRwLock};
use yggdrasil_abi::{error::Error, io::OpenOptions};
use crate::{block::BlockAllocator, bvec::BVec, MemoryFilesystem};
use crate::{MemoryFilesystem, block::BlockAllocator, bvec::BVec};
pub(crate) struct FileNode<A: BlockAllocator> {
pub(crate) data: IrqSafeSpinlock<BVec<'static, A>>,
+1 -1
View File
@@ -13,7 +13,7 @@ use alloc::sync::Arc;
use block::BlockAllocator;
use dir::DirectoryNode;
use file::FileNode;
use libk::vfs::{impls::fixed_path_symlink, AccessToken, Filename, Filesystem, Metadata, NodeRef};
use libk::vfs::{AccessToken, Filename, Filesystem, Metadata, NodeRef, impls::fixed_path_symlink};
use libk_util::sync::IrqSafeSpinlock;
use tar::TarEntry;
use yggdrasil_abi::{
+1
View File
@@ -0,0 +1 @@
+1 -1
View File
@@ -8,7 +8,7 @@ use alloc::{boxed::Box, sync::Arc};
use async_trait::async_trait;
use device_api::device::Device;
use libk::{device::char::CharDevice, vfs::FileReadiness};
use libk_util::{ring::LossyRingQueue, OneTimeInit};
use libk_util::{OneTimeInit, ring::LossyRingQueue};
use yggdrasil_abi::{error::Error, io::KeyboardKeyEvent};
#[derive(Clone, Copy)]
+1 -1
View File
@@ -1,7 +1,7 @@
[package]
name = "ygg_driver_net_core"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]
yggdrasil-abi = { workspace = true, features = ["serde_kernel", "bytemuck"] }
+2 -2
View File
@@ -5,17 +5,17 @@ use yggdrasil_abi::{
error::Error,
io::{ChannelPublisherId, MessageDestination},
net::{
IpAddr, SubnetAddr,
netconfig::{
InterfaceInfo, InterfaceQuery, NetConfigRequest, NetConfigResult, RouteInfo,
RoutingInfo,
},
IpAddr, SubnetAddr,
},
};
use crate::{
interface::NetworkInterface,
l3::{arp, Route},
l3::{Route, arp},
};
async fn receive_request(
+1 -1
View File
@@ -6,9 +6,9 @@ use libk::dma::DmaBuffer;
use yggdrasil_abi::{
error::Error,
net::{
MacAddress,
protocols::{EtherType, EthernetFrame},
types::NetValueImpl,
MacAddress,
},
};
+4 -4
View File
@@ -1,5 +1,5 @@
use core::{
mem::{size_of, MaybeUninit},
mem::{MaybeUninit, size_of},
net::IpAddr,
sync::atomic::{AtomicU32, AtomicUsize, Ordering},
};
@@ -8,17 +8,17 @@ use alloc::{boxed::Box, collections::BTreeMap, format, sync::Arc};
use libk::dma::DmaBuffer;
// TODO: link state management?
use libk_util::{
sync::spin_rwlock::{IrqSafeRwLock, IrqSafeRwLockReadGuard},
OneTimeInit,
sync::spin_rwlock::{IrqSafeRwLock, IrqSafeRwLockReadGuard},
};
use yggdrasil_abi::{
error::Error,
net::{link::LinkState, protocols::EthernetFrame, MacAddress},
net::{MacAddress, link::LinkState, protocols::EthernetFrame},
};
use crate::{
l3::{arp::ArpTable, Route},
TxPacketBuilder,
l3::{Route, arp::ArpTable},
};
pub trait NetworkDevice: Sync + Send {
+2 -2
View File
@@ -13,13 +13,13 @@ use libk_util::{sync::spin_rwlock::IrqSafeRwLock, waker::QueueWaker};
use yggdrasil_abi::{
error::Error,
net::{
MacAddress,
protocols::{ArpFrame, EtherType},
types::NetValueImpl,
MacAddress,
},
};
use crate::{ethernet, interface::NetworkInterface, L2Packet};
use crate::{L2Packet, ethernet, interface::NetworkInterface};
struct Inner<A: Ord + Eq + Copy> {
entries: BTreeMap<(u32, A), (MacAddress, bool)>,
+1 -1
View File
@@ -12,7 +12,7 @@ use yggdrasil_abi::{
},
};
use crate::{interface::NetworkInterface, L2Packet, L3Packet, ACCEPT_QUEUE};
use crate::{ACCEPT_QUEUE, L2Packet, L3Packet, interface::NetworkInterface};
use super::IpFrame;
+2 -2
View File
@@ -13,13 +13,13 @@ use libk_util::sync::spin_rwlock::{
use yggdrasil_abi::{
error::Error,
net::{
MacAddress, SubnetAddr,
protocols::{EtherType, EthernetFrame, InetChecksum, IpProtocol, Ipv4Frame},
types::NetValueImpl,
MacAddress, SubnetAddr,
},
};
use crate::{interface::NetworkInterface, l4, TxPacketBuilder};
use crate::{TxPacketBuilder, interface::NetworkInterface, l4};
pub mod arp;
pub mod ip;
+3 -3
View File
@@ -6,15 +6,15 @@ use core::{
use yggdrasil_abi::{
error::Error,
net::{
SubnetAddr, SubnetV4Addr,
protocols::{IcmpV4Frame, InetChecksum, IpProtocol},
types::NetValueImpl,
SubnetAddr, SubnetV4Addr,
},
};
use crate::{
l3::{self, Route},
L3Packet,
l3::{self, Route},
};
async fn send_v4_reply(
@@ -29,7 +29,7 @@ async fn send_v4_reply(
rest: icmp_frame.rest,
};
if icmp_data.len() % 2 != 0 {
if !icmp_data.len().is_multiple_of(2) {
return Err(Error::InvalidArgument);
}
+1 -1
View File
@@ -11,7 +11,7 @@ use yggdrasil_abi::{
},
};
use crate::{l3, socket::UdpSocket, L3Packet};
use crate::{L3Packet, l3, socket::UdpSocket};
pub async fn send(
source_port: u16,
+1 -1
View File
@@ -1,4 +1,4 @@
#![feature(map_try_insert, let_chains)]
#![feature(map_try_insert)]
#![allow(clippy::type_complexity, clippy::new_without_default)]
#![no_std]
+5 -5
View File
@@ -14,19 +14,19 @@ use libk::{
use libk_mm::PageBox;
use libk_util::queue::BoundedMpmcQueue;
use yggdrasil_abi::{
abi_serde::{wire, Serialize},
abi_serde::{Serialize, wire},
net::{
MacAddress, MessageHeader, MessageHeaderMut, SocketInterfaceQuery, SubnetAddr,
netconfig::{
InterfaceBinding, InterfaceInfo, NetConfigRequest, NetConfigResult, RouteInfo,
RoutingInfo,
},
MacAddress, MessageHeader, MessageHeaderMut, SocketInterfaceQuery, SubnetAddr,
},
};
use crate::{
interface::NetworkInterface,
l3::{arp, Route},
l3::{Route, arp},
};
pub struct NetConfigSocket {
@@ -71,7 +71,7 @@ impl NetConfigSocket {
None => {
return self.write_response(NetConfigResult::<MacAddress>::Err(
"No such interface",
))
));
}
};
let result = match arp::lookup(iface.id(), query.address, true).await {
@@ -123,7 +123,7 @@ impl NetConfigSocket {
None => {
return self.write_response(NetConfigResult::<MacAddress>::Err(
"No such interface",
))
));
}
};
let result =
@@ -3,7 +3,7 @@ use alloc::sync::Arc;
use libk::{error::Error, task::thread::Thread, vfs::File};
use yggdrasil_abi::{
abi_serde::wire,
net::{types::LocalSocketAddress, AncillaryMessage, MessageHeader, MessageHeaderMut},
net::{AncillaryMessage, MessageHeader, MessageHeaderMut, types::LocalSocketAddress},
};
pub mod packet;
@@ -35,8 +35,7 @@ pub fn read_ancillary(message: &MessageHeader) -> Result<Option<Arc<File>>, Erro
}
let ancillary: AncillaryMessage = wire::from_slice(message.ancillary)?;
#[allow(irrefutable_let_patterns)]
let AncillaryMessage::File(fd) = ancillary
else {
let AncillaryMessage::File(fd) = ancillary else {
log::warn!("local: invalid ancillary message: {ancillary:?}");
return Err(Error::InvalidArgument);
};
@@ -22,7 +22,7 @@ use libk_util::{
queue::BoundedMpmcQueue,
sync::spin_rwlock::{IrqSafeRwLock, IrqSafeRwLockReadGuard},
};
use yggdrasil_abi::net::{types::LocalSocketAddress, MessageHeader, MessageHeaderMut};
use yggdrasil_abi::net::{MessageHeader, MessageHeaderMut, types::LocalSocketAddress};
use super::OwnedAddress;
+2 -6
View File
@@ -1,7 +1,7 @@
use core::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
use alloc::{
collections::{btree_map::Entry, BTreeMap},
collections::{BTreeMap, btree_map::Entry},
sync::Arc,
};
use yggdrasil_abi::error::Error;
@@ -50,11 +50,7 @@ impl<T> TwoWaySocketTable<T> {
const fn next_port_wrapping(port: u16) -> u16 {
let port = port + 1;
if port >= u16::MAX - 1 {
32768
} else {
port
}
if port >= u16::MAX - 1 { 32768 } else { port }
}
fn try_insert_into_range<F: FnMut(u16) -> Result<Arc<T>, Error>, R: Iterator<Item = u16>>(
+2 -2
View File
@@ -17,13 +17,13 @@ use libk_mm::PageBox;
use libk_util::{queue::BoundedMpmcQueue, sync::spin_rwlock::IrqSafeRwLock};
use yggdrasil_abi::{
net::{
options::{self, RawSocketOptionVariant},
MessageHeader, MessageHeaderMut, SocketInterfaceQuery,
options::{self, RawSocketOptionVariant},
},
option::OptionValue,
};
use crate::{ethernet::L2Packet, interface::NetworkInterface, TxPacketBuilder};
use crate::{TxPacketBuilder, ethernet::L2Packet, interface::NetworkInterface};
enum RawPacket {
Ingress(L2Packet),
@@ -9,7 +9,7 @@ use core::{
use alloc::{collections::btree_map::BTreeMap, sync::Arc, vec::Vec};
use libk::error::Error;
use libk_util::{
sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock, IrqSafeSpinlockGuard},
sync::{IrqSafeSpinlock, IrqSafeSpinlockGuard, spin_rwlock::IrqSafeRwLock},
waker::QueueWaker,
};
+1 -1
View File
@@ -16,8 +16,8 @@ use libk::{
use libk_util::sync::spin_rwlock::IrqSafeRwLock;
use yggdrasil_abi::{
net::{
options::{self, TcpSocketOptionVariant},
MessageHeader, MessageHeaderMut,
options::{self, TcpSocketOptionVariant},
},
option::OptionValue,
};

Some files were not shown because too many files have changed in this diff Show More