mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-08 10:15:03 +00:00
parent
634349e0eb
commit
bd70d2d1f4
21
.github/workflows/cache-toolchain.yml
vendored
21
.github/workflows/cache-toolchain.yml
vendored
@ -51,17 +51,17 @@ jobs:
|
||||
|
||||
cargo install cargo-binutils
|
||||
rustup toolchain install nightly-x86_64-unknown-linux-gnu
|
||||
rustup toolchain install nightly-2023-01-21-x86_64-unknown-linux-gnu
|
||||
rustup toolchain install nightly-2024-07-23-x86_64-unknown-linux-gnu
|
||||
rustup toolchain install nightly-2023-08-15-x86_64-unknown-linux-gnu
|
||||
rustup component add rust-src --toolchain nightly-2023-01-21-x86_64-unknown-linux-gnu
|
||||
rustup component add rust-src --toolchain nightly-2024-07-23-x86_64-unknown-linux-gnu
|
||||
rustup component add rust-src --toolchain nightly-2023-08-15-x86_64-unknown-linux-gnu
|
||||
rustup target add x86_64-unknown-none --toolchain nightly-2023-01-21-x86_64-unknown-linux-gnu
|
||||
rustup target add x86_64-unknown-none --toolchain nightly-2024-07-23-x86_64-unknown-linux-gnu
|
||||
rustup target add x86_64-unknown-none --toolchain nightly-2023-08-15-x86_64-unknown-linux-gnu
|
||||
|
||||
rustup toolchain install nightly-2023-01-21-riscv64gc-unknown-linux-gnu --force-non-host
|
||||
rustup toolchain install nightly-2024-07-23-riscv64gc-unknown-linux-gnu --force-non-host
|
||||
rustup toolchain install nightly-2023-08-15-riscv64gc-unknown-linux-gnu --force-non-host
|
||||
rustup target add riscv64gc-unknown-none-elf --toolchain nightly-2023-01-21-riscv64gc-unknown-linux-gnu
|
||||
rustup target add riscv64imac-unknown-none-elf --toolchain nightly-2023-01-21-riscv64gc-unknown-linux-gnu
|
||||
rustup target add riscv64gc-unknown-none-elf --toolchain nightly-2024-07-23-riscv64gc-unknown-linux-gnu
|
||||
rustup target add riscv64imac-unknown-none-elf --toolchain nightly-2024-07-23-riscv64gc-unknown-linux-gnu
|
||||
rustup target add riscv64gc-unknown-none-elf --toolchain nightly-2023-08-15-riscv64gc-unknown-linux-gnu
|
||||
rustup target add riscv64imac-unknown-none-elf --toolchain nightly-2023-08-15-riscv64gc-unknown-linux-gnu
|
||||
|
||||
@ -71,12 +71,12 @@ jobs:
|
||||
|
||||
rustup component add rustfmt
|
||||
rustup component add rustfmt --toolchain nightly-x86_64-unknown-linux-gnu
|
||||
rustup component add rustfmt --toolchain nightly-2023-01-21-x86_64-unknown-linux-gnu
|
||||
rustup component add rustfmt --toolchain nightly-2024-07-23-x86_64-unknown-linux-gnu
|
||||
rustup component add rustfmt --toolchain nightly-2023-08-15-x86_64-unknown-linux-gnu
|
||||
rustup component add rustfmt --toolchain nightly-2023-01-21-riscv64gc-unknown-linux-gnu
|
||||
rustup component add rustfmt --toolchain nightly-2024-07-23-riscv64gc-unknown-linux-gnu
|
||||
rustup component add rustfmt --toolchain nightly-2023-08-15-riscv64gc-unknown-linux-gnu
|
||||
|
||||
rustup default nightly
|
||||
rustup default nightly-2024-07-23
|
||||
|
||||
cargo install dadk --version 0.1.11
|
||||
|
||||
@ -86,6 +86,9 @@ jobs:
|
||||
rustup toolchain install ${userapp_musl_toolchain}
|
||||
rustup component add --toolchain ${userapp_musl_toolchain} rust-src
|
||||
rustup target add --toolchain ${userapp_musl_toolchain} x86_64-unknown-linux-musl
|
||||
|
||||
rustup target add x86_64-unknown-linux-musl --toolchain nightly-2024-07-23-x86_64-unknown-linux-gnu
|
||||
rustup component add rust-src --toolchain nightly-2024-07-23-x86_64-unknown-linux-gnu
|
||||
|
||||
|
||||
|
||||
|
@ -5,4 +5,4 @@ fmt:
|
||||
clean:
|
||||
@cargo clean
|
||||
check:
|
||||
@cargo +nightly-2023-08-15 check --workspace $(CARGO_ZBUILD) --message-format=json
|
||||
@cargo +nightly-2024-07-23 check --workspace $(CARGO_ZBUILD) --message-format=json
|
||||
|
@ -1,5 +1,3 @@
|
||||
#![feature(cfg_target_abi)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
extern crate cc;
|
||||
|
@ -5,4 +5,9 @@
|
||||
[target.'cfg(target_os = "none")']
|
||||
runner = "bootimage runner"
|
||||
|
||||
[build]
|
||||
# '-Zlinker-features=-lld' 禁用rustlld(20240723),因为它与linkme0.3版本冲突
|
||||
rustflags = ["-Zlinker-features=-lld"]
|
||||
rustdocflags = ["-Zlinker-features=-lld"]
|
||||
|
||||
[env]
|
||||
|
@ -12,16 +12,18 @@ crate-type = ["staticlib"]
|
||||
[workspace]
|
||||
members = [
|
||||
"crates/*",
|
||||
"src/libs/intertrait"
|
||||
]
|
||||
|
||||
[features]
|
||||
default = ["backtrace", "kvm"]
|
||||
default = ["backtrace", "kvm", "fatfs", "fatfs-secure"]
|
||||
# 内核栈回溯
|
||||
backtrace = []
|
||||
# kvm
|
||||
kvm = []
|
||||
|
||||
fatfs = []
|
||||
fatfs-secure = ["fatfs"]
|
||||
|
||||
|
||||
# 运行时依赖项
|
||||
[dependencies]
|
||||
@ -37,10 +39,10 @@ driver_base_macros = { "path" = "crates/driver_base_macros" }
|
||||
elf = { version = "=0.7.2", default-features = false }
|
||||
hashbrown = "=0.13.2"
|
||||
ida = { path = "src/libs/ida" }
|
||||
intertrait = { path = "src/libs/intertrait" }
|
||||
intertrait = { path = "crates/intertrait" }
|
||||
kdepends = { path = "crates/kdepends" }
|
||||
klog_types = { path = "crates/klog_types" }
|
||||
linkme = "=0.2"
|
||||
linkme = "=0.3.27"
|
||||
num = { version = "=0.4.0", default-features = false }
|
||||
num-derive = "=0.3"
|
||||
num-traits = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/num-traits.git", rev="1597c1c", default-features = false }
|
||||
|
@ -36,12 +36,12 @@ check: ECHO
|
||||
# @echo "Checking kernel... ARCH=$(ARCH)"
|
||||
# @exit 1
|
||||
ifeq ($(ARCH), x86_64)
|
||||
@cargo +nightly-2023-08-15 check --workspace $(CARGO_ZBUILD) --message-format=json --target ./src/$(TARGET_JSON)
|
||||
@cargo +nightly-2024-07-23 check --workspace $(CARGO_ZBUILD) --message-format=json --target ./src/$(TARGET_JSON)
|
||||
else ifeq ($(ARCH), riscv64)
|
||||
@cargo +nightly-2023-08-15 check --workspace $(CARGO_ZBUILD) --message-format=json --target $(TARGET_JSON)
|
||||
@cargo +nightly-2024-07-23 check --workspace $(CARGO_ZBUILD) --message-format=json --target $(TARGET_JSON)
|
||||
endif
|
||||
|
||||
test:
|
||||
# 测试内核库
|
||||
@cargo +nightly-2023-08-15 test --workspace --exclude dragonos_kernel
|
||||
@cargo +nightly-2024-07-23 test --workspace --exclude dragonos_kernel
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#![feature(core_intrinsics)]
|
||||
#![allow(incomplete_features)] // for const generics
|
||||
#![feature(generic_const_exprs)]
|
||||
#![allow(internal_features)]
|
||||
#![allow(clippy::needless_return)]
|
||||
|
||||
#[macro_use]
|
||||
|
@ -14,6 +14,15 @@ where
|
||||
core: BitMapCore<usize>,
|
||||
}
|
||||
|
||||
impl<const N: usize> Default for StaticBitmap<N>
|
||||
where
|
||||
[(); (N + usize::BITS as usize - 1) / (usize::BITS as usize)]:,
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N: usize> StaticBitmap<N>
|
||||
where
|
||||
[(); (N + usize::BITS as usize - 1) / (usize::BITS as usize)]:,
|
||||
|
@ -182,11 +182,6 @@ macro_rules! bitops_for {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
fn to_hex(bits: &Self) -> String {
|
||||
format!("{:x}", bits)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn bit_size() -> usize {
|
||||
<$target>::BITS as usize
|
||||
|
@ -14,7 +14,7 @@ include = ["src/**/*", "Cargo.toml", "LICENSE-*", "README.md"]
|
||||
|
||||
|
||||
[dependencies]
|
||||
linkme = "0.2"
|
||||
linkme = "=0.3.27"
|
||||
hashbrown = "0.13.2"
|
||||
intertrait-macros = { version = "=0.2.2", path = "macros" }
|
||||
|
@ -23,7 +23,7 @@ Add the following two dependencies to your `Cargo.toml`:
|
||||
```toml
|
||||
[dependencies]
|
||||
intertrait = "0.2"
|
||||
linkme = "0.2"
|
||||
linkme = "=0.3.27"
|
||||
```
|
||||
|
||||
The `linkme` dependency is required due to the use of `linkme` macro in the output of `intertrait` macros.
|
@ -20,4 +20,4 @@ uuid = { version = "0.8", features = ["v4"] }
|
||||
|
||||
[dev-dependencies]
|
||||
intertrait = { version = "=0.2.2", path = ".." }
|
||||
linkme = "0.2"
|
||||
linkme = "=0.3.27"
|
@ -175,6 +175,12 @@ impl MMLogCycle {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for MMLogCycle {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl kdepends::thingbuf::Recycle<AllocatorLog> for MMLogCycle {
|
||||
fn new_element(&self) -> AllocatorLog {
|
||||
AllocatorLog::zeroed()
|
||||
|
@ -38,7 +38,7 @@ impl Bitfield for [AtomicU64] {
|
||||
fn initialize(&mut self, for_size: usize, capacity: usize) {
|
||||
// Set everything to allocated
|
||||
for bitmap in self.iter_mut() {
|
||||
*bitmap = AtomicU64::new(u64::max_value());
|
||||
*bitmap = AtomicU64::new(u64::MAX);
|
||||
}
|
||||
|
||||
// Mark actual slots as free
|
||||
@ -64,7 +64,7 @@ impl Bitfield for [AtomicU64] {
|
||||
|
||||
for (base_idx, b) in self.iter().enumerate() {
|
||||
let bitval = b.load(Ordering::Relaxed);
|
||||
if bitval == u64::max_value() {
|
||||
if bitval == u64::MAX {
|
||||
continue;
|
||||
} else {
|
||||
let negated = !bitval;
|
||||
@ -125,7 +125,7 @@ impl Bitfield for [AtomicU64] {
|
||||
#[inline(always)]
|
||||
fn is_full(&self) -> bool {
|
||||
self.iter()
|
||||
.filter(|&x| x.load(Ordering::Relaxed) != u64::max_value())
|
||||
.filter(|&x| x.load(Ordering::Relaxed) != u64::MAX)
|
||||
.count()
|
||||
== 0
|
||||
}
|
||||
@ -410,6 +410,7 @@ impl<'a, T: AllocablePage> PageList<'a, T> {
|
||||
}
|
||||
|
||||
/// Removes `slab_page` from the list.
|
||||
#[allow(clippy::manual_inspect)]
|
||||
pub(crate) fn pop<'b>(&'b mut self) -> Option<&'a mut T> {
|
||||
match self.head {
|
||||
None => None,
|
||||
@ -453,6 +454,7 @@ impl<'a, P: AllocablePage + 'a> Iterator for ObjectPageIterMut<'a, P> {
|
||||
type Item = &'a mut P;
|
||||
|
||||
#[inline]
|
||||
#[allow(clippy::manual_inspect)]
|
||||
fn next(&mut self) -> Option<&'a mut P> {
|
||||
unsafe {
|
||||
self.head.resolve_mut().map(|next| {
|
||||
|
@ -10,5 +10,5 @@ path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
unified-init-macros = { path = "macros" }
|
||||
linkme = "0.2"
|
||||
linkme = "=0.3.27"
|
||||
system_error = { path = "../system_error" }
|
@ -16,5 +16,5 @@ uuid = { version = "0.8", features = ["v4"] }
|
||||
|
||||
[dev-dependencies]
|
||||
unified-init = { path = ".." }
|
||||
linkme = "0.2"
|
||||
linkme = "=0.3.27"
|
||||
system_error = { path = "../../system_error" }
|
||||
|
@ -1,3 +1,3 @@
|
||||
[toolchain]
|
||||
channel = "nightly-2023-08-15"
|
||||
channel = "nightly-2024-07-23"
|
||||
components = ["rust-src", "clippy"]
|
@ -21,7 +21,7 @@ ifeq ($(ARCH), x86_64)
|
||||
endif
|
||||
endif
|
||||
|
||||
RUSTFLAGS = $(RUSTFLAGS_UNWIND)
|
||||
RUSTFLAGS += $(RUSTFLAGS_UNWIND)
|
||||
|
||||
CFLAGS = $(GLOBAL_CFLAGS) -fno-pie $(CFLAGS_UNWIND) -I $(shell pwd) -I $(shell pwd)/include
|
||||
|
||||
@ -40,7 +40,7 @@ kernel_subdirs := common driver debug syscall libs
|
||||
|
||||
|
||||
kernel_rust:
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo +nightly-2023-08-15 $(CARGO_ZBUILD) build --release --target $(TARGET_JSON)
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo +nightly-2024-07-23 $(CARGO_ZBUILD) build --release --target $(TARGET_JSON)
|
||||
|
||||
|
||||
all: kernel
|
||||
|
@ -1,4 +1,5 @@
|
||||
/// 每个架构都需要实现的IO接口
|
||||
#[allow(unused)]
|
||||
pub trait PortIOArch {
|
||||
unsafe fn in8(port: u16) -> u8;
|
||||
unsafe fn in16(port: u16) -> u16;
|
||||
|
@ -156,6 +156,7 @@ impl LocalApicTimerIntrController {
|
||||
local_apic_timer.start_current();
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn disable(&self) {
|
||||
let cpu_id = smp_get_processor_id();
|
||||
let local_apic_timer = local_apic_timer_instance_mut(cpu_id);
|
||||
|
@ -179,6 +179,7 @@ bitflags! {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn irq_msi_compose_msg(cfg: &HardwareIrqConfig, msg: &mut MsiMsg, dmar: bool) {
|
||||
*msg = MsiMsg::new_zeroed();
|
||||
|
||||
|
@ -35,6 +35,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[allow(static_mut_refs)]
|
||||
unsafe extern "C" fn kernel_main(
|
||||
mb2_info: u64,
|
||||
mb2_magic: u64,
|
||||
@ -66,6 +67,7 @@ unsafe extern "C" fn kernel_main(
|
||||
|
||||
/// 在内存管理初始化之前的架构相关的早期初始化
|
||||
#[inline(never)]
|
||||
#[allow(static_mut_refs)]
|
||||
pub fn early_setup_arch() -> Result<(), SystemError> {
|
||||
let stack_start = unsafe { *(head_stack_start as *const u64) } as usize;
|
||||
debug!("head_stack_start={:#x}\n", stack_start);
|
||||
|
@ -564,6 +564,7 @@ pub unsafe fn set_system_trap_gate(irq: u32, ist: u8, vaddr: VirtAddr) {
|
||||
set_gate(idt_entry, 0xEF, ist, vaddr);
|
||||
}
|
||||
|
||||
#[allow(static_mut_refs)]
|
||||
unsafe fn get_idt_entry(irq: u32) -> &'static mut [u64] {
|
||||
assert!(irq < 256);
|
||||
let mut idt_vaddr =
|
||||
|
@ -26,6 +26,7 @@ pub struct X86MsiDataNormal {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[allow(dead_code)]
|
||||
pub struct X86MsiDataDmar {
|
||||
pub dmar_subhandle: u32,
|
||||
}
|
||||
|
@ -396,6 +396,7 @@ impl SigContext {
|
||||
}
|
||||
}
|
||||
/// @brief 信号处理备用栈的信息
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct SigStack {
|
||||
pub sp: *mut c_void,
|
||||
|
@ -42,6 +42,7 @@ pub struct MSRBitmap {
|
||||
pub data: [u8; PAGE_SIZE],
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
pub struct VcpuData {
|
||||
/// The virtual and physical address of the Vmxon naturally aligned 4-KByte region of memory
|
||||
@ -73,6 +74,7 @@ pub enum VcpuState {
|
||||
Act = 2,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
pub struct VmxVcpu {
|
||||
pub vcpu_id: u32,
|
||||
@ -318,13 +320,13 @@ impl VmxVcpu {
|
||||
)?;
|
||||
vmx_vmwrite(
|
||||
VmcsFields::HOST_GDTR_BASE as u32,
|
||||
pseudo_descriptpr.base.to_bits() as u64,
|
||||
pseudo_descriptpr.base as usize as u64,
|
||||
)?;
|
||||
vmx_vmwrite(VmcsFields::HOST_IDTR_BASE as u32, unsafe {
|
||||
let mut pseudo_descriptpr: x86::dtables::DescriptorTablePointer<u64> =
|
||||
Default::default();
|
||||
x86::dtables::sidt(&mut pseudo_descriptpr);
|
||||
pseudo_descriptpr.base.to_bits() as u64
|
||||
pseudo_descriptpr.base as usize as u64
|
||||
})?;
|
||||
|
||||
// fast entry into the kernel
|
||||
|
@ -64,10 +64,10 @@ pub fn vmx_vmlaunch() -> Result<(), SystemError> {
|
||||
"push rsi",
|
||||
"push rdi",
|
||||
"vmwrite {0:r}, rsp",
|
||||
"lea rax, 1f[rip]",
|
||||
"lea rax, 2f[rip]",
|
||||
"vmwrite {1:r}, rax",
|
||||
"vmlaunch",
|
||||
"1:",
|
||||
"2:",
|
||||
"pop rdi",
|
||||
"pop rsi",
|
||||
"pop rdx",
|
||||
|
@ -30,6 +30,7 @@ pub use interrupt::X86_64InterruptArch as CurrentIrqArch;
|
||||
pub use crate::arch::asm::pio::X86_64PortIOArch as CurrentPortIOArch;
|
||||
pub use kvm::X86_64KVMArch as KVMArch;
|
||||
|
||||
#[allow(unused_imports)]
|
||||
pub use crate::arch::ipc::signal::X86_64SignalArch as CurrentSignalArch;
|
||||
pub use crate::arch::time::X86_64TimeArch as CurrentTimeArch;
|
||||
|
||||
|
@ -42,9 +42,8 @@ impl KernelThreadMechanism {
|
||||
frame.rip = kernel_thread_bootstrap_stage1 as usize as u64;
|
||||
|
||||
// fork失败的话,子线程不会执行。否则将导致内存安全问题。
|
||||
let pid = ProcessManager::fork(&frame, clone_flags).map_err(|e| {
|
||||
let pid = ProcessManager::fork(&frame, clone_flags).inspect_err(|_e| {
|
||||
unsafe { KernelThreadCreateInfo::parse_unsafe_arc_ptr(create_info) };
|
||||
e
|
||||
})?;
|
||||
|
||||
ProcessManager::find(pid)
|
||||
|
@ -59,6 +59,7 @@ impl TSSManager {
|
||||
x86::task::load_tr(selector);
|
||||
}
|
||||
|
||||
#[allow(static_mut_refs)]
|
||||
unsafe fn set_tss_descriptor(index: u16, vaddr: VirtAddr) {
|
||||
const LIMIT: u64 = 103;
|
||||
let gdt_vaddr = VirtAddr::new(&GDT_Table as *const _ as usize);
|
||||
|
@ -259,6 +259,7 @@ impl X86_64SMPArch {
|
||||
}
|
||||
|
||||
impl SmpCpuManager {
|
||||
#[allow(static_mut_refs)]
|
||||
pub fn arch_init(_boot_cpu: ProcessorId) {
|
||||
assert!(smp_get_processor_id().data() == 0);
|
||||
// 写入APU_START_CR3,这个值会在AP处理器启动时设置到CR3寄存器
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"llvm-target": "x86_64-unknown-none",
|
||||
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
|
||||
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
|
||||
"arch": "x86_64",
|
||||
"target-endian": "little",
|
||||
"target-pointer-width": "64",
|
||||
|
@ -111,6 +111,7 @@ impl Bus for AcpiBus {
|
||||
///
|
||||
///
|
||||
/// 参考 https://code.dragonos.org.cn/xref/linux-6.1.9/include/acpi/acpi_bus.h#364
|
||||
#[allow(unused)]
|
||||
pub trait AcpiDevice: Device {}
|
||||
|
||||
/// Acpi驱动应当实现的trait
|
||||
@ -120,4 +121,5 @@ pub trait AcpiDevice: Device {}
|
||||
/// todo: 仿照linux的acpi_driver去设计这个trait
|
||||
///
|
||||
/// 参考 https://code.dragonos.org.cn/xref/linux-6.1.9/include/acpi/acpi_bus.h#163
|
||||
#[allow(unused)]
|
||||
pub trait AcpiDriver: Driver {}
|
||||
|
@ -478,9 +478,8 @@ impl BusManager {
|
||||
|
||||
driver_manager()
|
||||
.create_attr_file(driver, &DriverAttrBind)
|
||||
.map_err(|e| {
|
||||
.inspect_err(|_e| {
|
||||
driver_manager().remove_attr_file(driver, &DriverAttrUnbind);
|
||||
e
|
||||
})?;
|
||||
|
||||
return Ok(());
|
||||
|
@ -142,6 +142,7 @@ impl DeviceManager {
|
||||
/// - Ok(true): 匹配成功
|
||||
/// - Ok(false): 没有匹配成功
|
||||
/// - Err(SystemError): 匹配过程中出现意外错误,没有匹配成功
|
||||
///
|
||||
/// 参考 https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/base/dd.c#899
|
||||
fn do_device_attach_driver(
|
||||
&self,
|
||||
@ -484,17 +485,15 @@ impl DriverManager {
|
||||
|
||||
sysfs_instance()
|
||||
.create_link(Some(&device_kobj), &driver_kobj, "driver".to_string())
|
||||
.map_err(|e| {
|
||||
.inspect_err(|_e| {
|
||||
fail_rm_dev_link();
|
||||
e
|
||||
})?;
|
||||
|
||||
device_manager()
|
||||
.create_file(device, &DeviceAttrCoredump)
|
||||
.map_err(|e| {
|
||||
.inspect_err(|_e| {
|
||||
sysfs_instance().remove_link(&device_kobj, "driver".to_string());
|
||||
fail_rm_dev_link();
|
||||
e
|
||||
})?;
|
||||
|
||||
return Ok(());
|
||||
|
@ -213,10 +213,10 @@ impl DriverManager {
|
||||
|
||||
bus_manager().add_driver(&driver)?;
|
||||
|
||||
self.add_groups(&driver, driver.groups()).map_err(|e| {
|
||||
bus_manager().remove_driver(&driver);
|
||||
e
|
||||
})?;
|
||||
self.add_groups(&driver, driver.groups())
|
||||
.inspect_err(|_e| {
|
||||
bus_manager().remove_driver(&driver);
|
||||
})?;
|
||||
|
||||
// todo: 发送uevent
|
||||
|
||||
|
@ -646,18 +646,16 @@ impl DeviceManager {
|
||||
let parent_kobj = parent.clone() as Arc<dyn KObject>;
|
||||
sysfs_instance()
|
||||
.create_link(Some(&dev_kobj), &parent_kobj, "device".to_string())
|
||||
.map_err(|e| {
|
||||
.inspect_err(|_e| {
|
||||
err_remove_subsystem(&dev_kobj);
|
||||
e
|
||||
})?;
|
||||
}
|
||||
|
||||
sysfs_instance()
|
||||
.create_link(Some(&subsys_kobj), &dev_kobj, dev.name())
|
||||
.map_err(|e| {
|
||||
.inspect_err(|_e| {
|
||||
err_remove_device(&dev_kobj);
|
||||
err_remove_subsystem(&dev_kobj);
|
||||
e
|
||||
})?;
|
||||
|
||||
return Ok(());
|
||||
@ -695,18 +693,16 @@ impl DeviceManager {
|
||||
// 添加kobj_type的属性文件
|
||||
if let Some(kobj_type) = dev.kobj_type() {
|
||||
self.add_groups(dev, kobj_type.attribute_groups().unwrap_or(&[]))
|
||||
.map_err(|e| {
|
||||
.inspect_err(|_e| {
|
||||
err_remove_class_groups(dev);
|
||||
e
|
||||
})?;
|
||||
}
|
||||
|
||||
// 添加设备本身的属性文件
|
||||
self.add_groups(dev, dev.attribute_groups().unwrap_or(&[]))
|
||||
.map_err(|e| {
|
||||
.inspect_err(|_e| {
|
||||
err_remove_kobj_type_groups(dev);
|
||||
err_remove_class_groups(dev);
|
||||
e
|
||||
})?;
|
||||
|
||||
return Ok(());
|
||||
|
@ -64,6 +64,7 @@ pub trait PlatformDevice: Device {
|
||||
/// @brief: 判断设备是否初始化
|
||||
/// @parameter: None
|
||||
/// @return: 如果已经初始化,返回true,否则,返回false
|
||||
#[allow(dead_code)]
|
||||
fn is_initialized(&self) -> bool;
|
||||
|
||||
/// @brief: 设置设备状态
|
||||
|
@ -16,6 +16,7 @@ use super::{platform_bus, platform_device::PlatformDevice};
|
||||
///
|
||||
/// 应当在所有实现这个trait的结构体上方,添加 `#[cast_to([sync] PlatformDriver)]`,
|
||||
/// 否则运行时将报错“该对象不是PlatformDriver”
|
||||
#[allow(dead_code)]
|
||||
pub trait PlatformDriver: Driver {
|
||||
/// 检测设备是否能绑定到这个驱动
|
||||
///
|
||||
|
@ -16,6 +16,7 @@ static mut CMAPPER: Option<LockedCacheMapper> = None;
|
||||
/// 该结构体向外提供BlockCache服务
|
||||
pub struct BlockCache;
|
||||
|
||||
#[allow(static_mut_refs)]
|
||||
unsafe fn mapper() -> Result<&'static mut LockedCacheMapper, BlockCacheError> {
|
||||
unsafe {
|
||||
match &mut CMAPPER {
|
||||
@ -25,6 +26,7 @@ unsafe fn mapper() -> Result<&'static mut LockedCacheMapper, BlockCacheError> {
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(static_mut_refs)]
|
||||
unsafe fn space() -> Result<&'static mut LockedCacheSpace, BlockCacheError> {
|
||||
unsafe {
|
||||
match &mut CSPACE {
|
||||
|
@ -195,9 +195,8 @@ impl AhciDisk {
|
||||
return Err(SystemError::EIO);
|
||||
}
|
||||
}
|
||||
|
||||
if kbuf.is_some() {
|
||||
buf.copy_from_slice(kbuf.as_ref().unwrap());
|
||||
if let Some(kbuf) = &kbuf {
|
||||
buf.copy_from_slice(kbuf);
|
||||
}
|
||||
|
||||
compiler_fence(Ordering::SeqCst);
|
||||
|
@ -43,6 +43,7 @@ pub enum HbaPortType {
|
||||
|
||||
/// 声明了 HBA 的所有属性
|
||||
#[repr(packed)]
|
||||
#[allow(dead_code)]
|
||||
pub struct HbaPort {
|
||||
pub clb: u64, // 0x00, command list base address, 1K-byte aligned
|
||||
pub fb: u64, // 0x08, FIS base address, 256-byte aligned
|
||||
@ -65,6 +66,7 @@ pub struct HbaPort {
|
||||
|
||||
/// 全称 HBA Memory Register,是HBA的寄存器在内存中的映射
|
||||
#[repr(packed)]
|
||||
#[allow(dead_code)]
|
||||
pub struct HbaMem {
|
||||
pub cap: u32, // 0x00, Host capability
|
||||
pub ghc: u32, // 0x04, Global host control
|
||||
@ -94,6 +96,7 @@ pub struct HbaPrdtEntry {
|
||||
/// HAB Command Table
|
||||
/// 每个 Port 一个 Table,主机和设备的交互都靠这个数据结构
|
||||
#[repr(packed)]
|
||||
#[allow(dead_code)]
|
||||
pub struct HbaCmdTable {
|
||||
// 0x00
|
||||
pub cfis: [u8; 64], // Command FIS
|
||||
@ -262,6 +265,7 @@ pub enum FisType {
|
||||
}
|
||||
|
||||
#[repr(packed)]
|
||||
#[allow(dead_code)]
|
||||
pub struct FisRegH2D {
|
||||
// DWORD 0
|
||||
pub fis_type: u8, // FIS_TYPE_REG_H2D
|
||||
|
@ -168,9 +168,8 @@ fn uefi_init(system_table: PhysAddr) -> Result<(), SystemError> {
|
||||
let st_ptr = st_vaddr.data() as *const uefi_raw::table::system::SystemTable;
|
||||
efi_manager()
|
||||
.check_system_table_header(unsafe { &st_ptr.as_ref().unwrap().header }, 2)
|
||||
.map_err(|e| {
|
||||
.inspect_err(|_| {
|
||||
err_unmap_systable(st_vaddr);
|
||||
e
|
||||
})?;
|
||||
|
||||
let st_ref = unsafe { st_ptr.as_ref().unwrap() };
|
||||
|
@ -1,4 +1,5 @@
|
||||
use crate::driver::{base::device::Device, input::serio::serio_device::SerioDevice};
|
||||
|
||||
// todo: https://code.dragonos.org.cn/xref/linux-6.1.9/include/linux/libps2.h#33
|
||||
#[allow(unused)]
|
||||
pub trait Ps2Device: Device + SerioDevice {}
|
||||
|
@ -387,6 +387,7 @@ impl Ps2MouseDevice {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn wait_for_read(&self) -> Result<(), SystemError> {
|
||||
let timeout = 100_000;
|
||||
for _ in 0..timeout {
|
||||
|
@ -47,14 +47,16 @@ pub fn i8042_init() -> Result<(), SystemError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// TODO: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/i8042.c#441
|
||||
/// TODO: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/i8042.c#441
|
||||
#[allow(dead_code)]
|
||||
pub fn i8042_start(_serio: &Arc<dyn SerioDevice>) -> Result<(), SystemError> {
|
||||
todo!()
|
||||
todo!("i8042_start")
|
||||
}
|
||||
|
||||
// TODO: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/i8042.c#471
|
||||
/// TODO: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/i8042.c#471
|
||||
#[allow(dead_code)]
|
||||
pub fn i8042_stop(_serio: &Arc<dyn SerioDevice>) -> Result<(), SystemError> {
|
||||
todo!()
|
||||
todo!("i8042_stop")
|
||||
}
|
||||
|
||||
/// # 函数的功能
|
||||
|
@ -8,6 +8,7 @@ use super::serio_bus;
|
||||
/// 串行设备,实现该trait的设备实例挂载在serio总线上,同时应该实现Device trait
|
||||
///
|
||||
/// 参考: https://code.dragonos.org.cn/xref/linux-6.1.9/include/linux/serio.h#20
|
||||
#[allow(dead_code)]
|
||||
pub trait SerioDevice: Device {
|
||||
/// # 函数功能
|
||||
///
|
||||
|
@ -11,6 +11,7 @@ use super::{serio_bus, serio_device::SerioDevice};
|
||||
/// 实现该trait的设备驱动实例应挂载在serio总线上,同时应该实现Driver trait
|
||||
///
|
||||
/// 参考: https://code.dragonos.org.cn/xref/linux-6.1.9/include/linux/serio.h#67
|
||||
#[allow(dead_code)]
|
||||
pub trait SerioDriver: Driver {
|
||||
// 写入时唤醒设备
|
||||
fn write_wakeup(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>;
|
||||
|
@ -780,7 +780,8 @@ const E1000E_TXD_CMD_EOP: u8 = 1 << 0;
|
||||
const E1000E_TXD_CMD_IFCS: u8 = 1 << 1;
|
||||
const E1000E_TXD_CMD_RS: u8 = 1 << 3;
|
||||
|
||||
// E1000E驱动初始化过程中可能的错误
|
||||
/// E1000E驱动初始化过程中可能的错误
|
||||
#[allow(dead_code)]
|
||||
pub enum E1000EPciError {
|
||||
// 获取到错误类型的BAR(IO BAR)
|
||||
// An IO BAR was provided rather than a memory BAR.
|
||||
|
@ -15,7 +15,6 @@ use alloc::sync::{Arc, Weak};
|
||||
use alloc::vec::Vec;
|
||||
use core::cell::UnsafeCell;
|
||||
use core::ops::{Deref, DerefMut};
|
||||
use log::debug;
|
||||
use smoltcp::wire::HardwareAddress;
|
||||
use smoltcp::{
|
||||
phy::{self},
|
||||
|
@ -13,7 +13,7 @@ pub mod e1000e;
|
||||
pub mod irq_handle;
|
||||
pub mod loopback;
|
||||
pub mod virtio_net;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub trait NetDevice: Device {
|
||||
/// @brief 获取网卡的MAC地址
|
||||
fn mac(&self) -> EthernetAddress;
|
||||
|
@ -468,8 +468,7 @@ fn read_cell(reg_value: &[u8], base_index: usize, cells: usize) -> (u64, usize)
|
||||
1 => {
|
||||
return (
|
||||
u32::from_be_bytes(reg_value[base_index..base_index + 4].try_into().unwrap())
|
||||
.try_into()
|
||||
.unwrap(),
|
||||
.into(),
|
||||
next_base_index,
|
||||
);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ use super::{dev_id::PciDeviceID, device::PciDevice, subsys::pci_bus};
|
||||
/// Pci驱动应该实现的trait
|
||||
///
|
||||
/// 参考 https://code.dragonos.org.cn/xref/linux-6.1.9/include/linux/pci.h#907
|
||||
#[allow(dead_code)]
|
||||
pub trait PciDriver: Driver {
|
||||
/// # 函数的功能
|
||||
/// 对设备进行probe操作
|
||||
|
@ -47,6 +47,7 @@ pub trait RtcDevice: Device {
|
||||
fn class_ops(&self) -> &'static dyn RtcClassOps;
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub trait RtcClassOps: Send + Sync + Debug {
|
||||
fn read_time(&self, dev: &Arc<dyn RtcDevice>) -> Result<RtcTime, SystemError>;
|
||||
fn set_time(&self, dev: &Arc<dyn RtcDevice>, time: &RtcTime) -> Result<(), SystemError>;
|
||||
|
@ -9,6 +9,7 @@ use self::serial8250::serial8250_manager;
|
||||
|
||||
pub mod serial8250;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub trait UartDriver: Debug + Send + Sync {
|
||||
fn device_number(&self) -> DeviceNumber;
|
||||
|
||||
@ -21,6 +22,7 @@ pub trait UartDriver: Debug + Send + Sync {
|
||||
/// 串口端口应当实现的trait
|
||||
///
|
||||
/// 参考 https://code.dragonos.org.cn/xref/linux-6.1.9/include/linux/serial_core.h#428
|
||||
#[allow(dead_code)]
|
||||
pub trait UartPort {
|
||||
fn iobase(&self) -> Option<usize> {
|
||||
None
|
||||
|
@ -141,6 +141,7 @@ impl Serial8250Manager {
|
||||
}
|
||||
|
||||
/// 所有的8250串口设备都应该实现的trait
|
||||
#[allow(dead_code)]
|
||||
trait Serial8250Port: UartPort {
|
||||
fn device(&self) -> Option<Arc<Serial8250ISADevices>> {
|
||||
None
|
||||
|
@ -20,6 +20,7 @@ static mut PIO_PORTS: [Option<Serial8250PIOPort>; 8] =
|
||||
[None, None, None, None, None, None, None, None];
|
||||
|
||||
impl Serial8250Manager {
|
||||
#[allow(static_mut_refs)]
|
||||
pub(super) fn bind_pio_ports(
|
||||
&self,
|
||||
uart_driver: &Arc<Serial8250ISADriver>,
|
||||
@ -251,6 +252,7 @@ impl Serial8250PIOPortInner {
|
||||
Self { device: None }
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn device(&self) -> Option<Arc<Serial8250ISADevices>> {
|
||||
if let Some(device) = self.device.as_ref() {
|
||||
return device.upgrade();
|
||||
|
@ -10,6 +10,7 @@ pub trait ConsoleSwitch: Sync + Send {
|
||||
fn con_init(&self, vc_data: &mut VirtualConsoleData, init: bool) -> Result<(), SystemError>;
|
||||
|
||||
/// 进行释放等系列操作,目前未使用
|
||||
#[allow(dead_code)]
|
||||
fn con_deinit(&self) -> Result<(), SystemError>;
|
||||
|
||||
/// ## 清空console的一片区域
|
||||
|
@ -7,7 +7,6 @@ use alloc::{
|
||||
collections::LinkedList,
|
||||
string::String,
|
||||
sync::{Arc, Weak},
|
||||
vec::Vec,
|
||||
};
|
||||
use system_error::SystemError;
|
||||
|
||||
@ -277,14 +276,6 @@ pub struct TtyContorlInfo {
|
||||
pub packet: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct TtyCoreWriteData {
|
||||
/// 写缓冲区
|
||||
pub write_buf: Vec<u8>,
|
||||
/// 写入数量
|
||||
pub write_cnt: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct TtyFlowState {
|
||||
/// 表示流控是否被停止
|
||||
@ -465,9 +456,6 @@ impl TtyCoreData {
|
||||
}
|
||||
}
|
||||
|
||||
/// TTY 核心接口,不同的tty需要各自实现这个trait
|
||||
pub trait TtyCoreFuncs: Debug + Send + Sync {}
|
||||
|
||||
impl TtyOperation for TtyCore {
|
||||
#[inline]
|
||||
fn open(&self, tty: &TtyCoreData) -> Result<(), SystemError> {
|
||||
|
@ -1344,7 +1344,7 @@ impl NTtyData {
|
||||
tty.write(core, &[8], 1)?;
|
||||
}
|
||||
if tty.put_char(tty.core(), b' ').is_err() {
|
||||
tty.write(core, &[b' '], 1)?;
|
||||
tty.write(core, b" ", 1)?;
|
||||
}
|
||||
self.cursor_column -= 1;
|
||||
space -= 1;
|
||||
@ -1357,7 +1357,7 @@ impl NTtyData {
|
||||
}
|
||||
|
||||
if tty.put_char(tty.core(), b'^').is_err() {
|
||||
tty.write(core, &[b'^'], 1)?;
|
||||
tty.write(core, b"^", 1)?;
|
||||
}
|
||||
|
||||
if tty.put_char(tty.core(), ch ^ 0o100).is_err() {
|
||||
|
@ -132,7 +132,6 @@ pub struct VirtualConsoleData {
|
||||
pub utf_char: u32,
|
||||
/// 构建utf时需要的参数,表示目前接收了多少个字节的数据来构建utf字符
|
||||
pub npar: u32,
|
||||
///
|
||||
pub par: [u32; NPAR],
|
||||
|
||||
/// 字符转换表 用于将输入字符映射到特定的字符
|
||||
@ -1786,6 +1785,7 @@ impl VirtualConsoleData {
|
||||
draw.size = 0;
|
||||
}
|
||||
|
||||
#[allow(clippy::manual_rotate)]
|
||||
fn build_attr(
|
||||
&self,
|
||||
color: u8,
|
||||
|
@ -341,12 +341,12 @@ impl Attribute for AttrCursorBlink {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[allow(dead_code)]
|
||||
pub struct FrameBufferConsoleData {
|
||||
/// 光标闪烁间隔
|
||||
pub cursor_blink_jiffies: i64,
|
||||
/// 是否刷新光标
|
||||
pub cursor_flash: bool,
|
||||
///
|
||||
pub display: FbConsoleDisplay,
|
||||
/// 光标状态
|
||||
pub cursor_state: FbCursor,
|
||||
|
@ -301,6 +301,7 @@ impl FrameBufferInfoData {
|
||||
}
|
||||
|
||||
/// 帧缓冲区信息
|
||||
#[allow(dead_code)]
|
||||
pub trait FrameBufferInfo: FrameBufferOps {
|
||||
fn framebuffer_info_data(&self) -> &RwLock<FrameBufferInfoData>;
|
||||
|
||||
@ -377,6 +378,7 @@ pub trait FrameBufferInfo: FrameBufferOps {
|
||||
/// 帧缓冲区操作
|
||||
///
|
||||
/// 参考 https://code.dragonos.org.cn/xref/linux-6.1.9/include/linux/fb.h#237
|
||||
#[allow(dead_code)]
|
||||
pub trait FrameBufferOps {
|
||||
fn fb_open(&self, user: bool);
|
||||
fn fb_release(&self, user: bool);
|
||||
@ -1063,6 +1065,7 @@ pub enum FbAccel {
|
||||
// Add other accelerators here
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct BootTimeScreenInfo {
|
||||
pub origin_x: u8,
|
||||
|
@ -18,6 +18,7 @@ pub mod virtio_impl;
|
||||
/// virtio 设备厂商ID
|
||||
pub const VIRTIO_VENDOR_ID: u16 = 0x1af4;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub trait VirtIODevice: Device {
|
||||
fn handle_irq(&self, _irq: IrqNumber) -> Result<IrqReturn, SystemError>;
|
||||
|
||||
|
@ -35,6 +35,7 @@ use super::{
|
||||
};
|
||||
|
||||
/// 参考 https://code.dragonos.org.cn/xref/linux-6.1.9/include/linux/irq.h#506
|
||||
#[allow(dead_code)]
|
||||
pub trait IrqChip: Sync + Send + Any + Debug {
|
||||
fn name(&self) -> &'static str;
|
||||
/// start up the interrupt (defaults to ->enable if ENOSYS)
|
||||
@ -127,6 +128,7 @@ pub trait IrqChip: Sync + Send + Any + Debug {
|
||||
}
|
||||
|
||||
/// enable/disable power management wake-on of an interrupt
|
||||
#[allow(dead_code)]
|
||||
fn irq_set_wake(&self, _irq_data: &Arc<IrqData>, _on: bool) -> Result<(), SystemError> {
|
||||
Err(SystemError::ENOSYS)
|
||||
}
|
||||
@ -281,6 +283,7 @@ struct InnerIrqChipGeneric {
|
||||
chip_types: Vec<IrqChipType>,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub trait IrqChipGenericOps: Debug + Send + Sync {
|
||||
/// Alternate I/O accessor (defaults to readl if NULL)
|
||||
unsafe fn reg_readl(&self, addr: VirtAddr) -> u32;
|
||||
|
@ -644,6 +644,7 @@ pub enum IrqDomainBusToken {
|
||||
/// 参考 https://code.dragonos.org.cn/xref/linux-6.1.9/include/linux/irqdomain.h#107
|
||||
pub trait IrqDomainOps: Debug + Send + Sync {
|
||||
/// 匹配一个中断控制器设备节点到一个主机。
|
||||
#[allow(dead_code)]
|
||||
fn match_node(
|
||||
&self,
|
||||
_irq_domain: &Arc<IrqDomain>,
|
||||
@ -667,6 +668,7 @@ pub trait IrqDomainOps: Debug + Send + Sync {
|
||||
}
|
||||
|
||||
/// 删除一个虚拟中断号与一个硬件中断号之间的映射。
|
||||
#[allow(dead_code)]
|
||||
fn unmap(&self, irq_domain: &Arc<IrqDomain>, virq: IrqNumber);
|
||||
|
||||
fn activate(
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user