Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ x86_64 = "=0.14.10"
riscv = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/riscv.git", rev = "4241a97", features = [
"s-mode",
] }
byte-slice-cast = { version = "1.2.2", default-features = false }
sbi-rt = { version = "=0.0.3", features = ["legacy"] }

# target为loongarch64时,使用下面的依赖
Expand Down
1 change: 1 addition & 0 deletions kernel/src/arch/riscv64/driver/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod of;
pub mod sbi;
pub mod vf2;
26 changes: 17 additions & 9 deletions kernel/src/arch/riscv64/driver/sbi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@ use core::ptr::addr_of;
/// console_putstr(message);
/// ```
pub fn console_putstr(s: &[u8]) {
if SbiDriver::extensions().contains(SBIExtensions::CONSOLE) {
for c in s {
sbi_rt::console_write_byte(*c);
}
return;
} else {
for c in s {
#[allow(deprecated)]
sbi_rt::legacy::console_putchar(*c as usize);
// 原本的是适配opensbi的, 但是对rustsbi的适配存在问题, 不能正确的解析'\r'
for &c in s {
match c {
b'\n' => {
#[allow(deprecated)]
sbi_rt::legacy::console_putchar(b'\r' as usize);
#[allow(deprecated)]
sbi_rt::legacy::console_putchar(b'\n' as usize);
}
b'\r' => {
#[allow(deprecated)]
sbi_rt::legacy::console_putchar(b'\r' as usize);
}
_ => {
#[allow(deprecated)]
sbi_rt::legacy::console_putchar(c as usize);
}
}
}
}
Expand Down
63 changes: 63 additions & 0 deletions kernel/src/arch/riscv64/driver/vf2/dw_mshc/dma.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use bitfield_struct::bitfield;

#[bitfield(u32)]
pub struct DES0 {
_reserved0: bool,
disable_interrupt_on_completion: bool,
last_decriptor: bool,
first_descriptor: bool,
second_address_chained: bool,
end_of_ring: bool,
#[bits(24)]
_reserved1: usize,
card_error_summary: bool,

// Is owned by the card.
own: bool,
}
#[bitfield(u32)]
pub struct DES1 {
#[bits(13)]
buffer_1_size: usize,
#[bits(13)]
buffer_2_size: usize,
#[bits(6)]
_reserved0: usize,
}
#[bitfield(u32)]
pub struct DES2 {
#[bits(32)]
pub buffer_addr1: usize,
}
#[bitfield(u32)]
pub struct DES3 {
#[bits(32)]
pub buffer_addr2: usize,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Descriptor {
pub des0: DES0,
pub des1: DES1,
pub des2: DES2,
pub des3: DES3,
}

#[allow(dead_code)]
impl Descriptor {
pub fn new(size: usize, buffer_paddr: usize, next_paddr: usize) -> Self {
Descriptor {
des0: DES0::new().with_second_address_chained(true).with_own(true),
des1: DES1::new().with_buffer_1_size(size),
des2: DES2::new().with_buffer_addr1(buffer_paddr),
des3: DES3::new().with_buffer_addr2(next_paddr),
}
}
pub fn own_by_card(&self) -> bool {
self.des0.own()
}
pub fn set_own_by_card(&mut self) {
self.des0.set_own(true);
}
}
Loading