浏览代码

feat(prototyper): add xilinx uartlite driver

Signed-off-by: Woshiluo Luo <[email protected]>
Woshiluo Luo 5 月之前
父节点
当前提交
c9626244aa
共有 3 个文件被更改,包括 51 次插入3 次删除
  1. 31 0
      Cargo.lock
  2. 4 0
      prototyper/Cargo.toml
  3. 16 3
      prototyper/src/board.rs

+ 31 - 0
Cargo.lock

@@ -14,6 +14,12 @@ version = "1.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
 
+[[package]]
+name = "bitflags"
+version = "2.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
+
 [[package]]
 name = "cfg-if"
 version = "1.0.0"
@@ -170,6 +176,7 @@ dependencies = [
  "sifive-test-device",
  "spin",
  "uart16550",
+ "uart_xilinx",
 ]
 
 [[package]]
@@ -286,8 +293,32 @@ version = "0.0.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "939f6f9ccad815fe3efca8fd06f2ec1620c0387fb1bca2b231b61ce710bffb9b"
 
+[[package]]
+name = "uart_xilinx"
+version = "0.2.0"
+source = "git+https://github.com/duskmoon314/uart-rs/#12be91421ad140f2a4bf4179578fd7a8fbc7ff5c"
+dependencies = [
+ "bitflags",
+ "volatile-register",
+]
+
 [[package]]
 name = "unicode-ident"
 version = "1.0.13"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
+
+[[package]]
+name = "vcell"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002"
+
+[[package]]
+name = "volatile-register"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "de437e2a6208b014ab52972a27e59b33fa2920d3e00fe05026167a1c509d19cc"
+dependencies = [
+ "vcell",
+]

+ 4 - 0
prototyper/Cargo.toml

@@ -22,6 +22,7 @@ spin = "0.9.8"
 uart16550 = "0.0.1"
 riscv-decode = "0.2.1"
 fast-trap = { version = "0.0.1", features = ["riscv-m"] }
+uart_xilinx = { git = "https://github.com/duskmoon314/uart-rs/" }
 
 
 [[bin]]
@@ -29,3 +30,6 @@ name = "rustsbi-prototyper"
 test = false
 bench = false
 
+[features]
+nemu = []
+fw_payload = []

+ 16 - 3
prototyper/src/board.rs

@@ -1,13 +1,13 @@
 use aclint::SifiveClint;
 use core::mem::MaybeUninit;
-use core::ptr::null;
 use core::{
-    ptr::null_mut,
+    ptr::{null, null_mut},
     sync::atomic::{AtomicPtr, Ordering::Release},
 };
 use sifive_test_device::SifiveTestDevice;
 use spin::Mutex;
 use uart16550::Uart16550;
+use uart_xilinx::uart_lite::uart::MmioUartAxiLite;
 
 use crate::sbi::console::ConsoleDevice;
 use crate::sbi::ipi::IpiDevice;
@@ -22,6 +22,7 @@ pub(crate) static mut SBI_IMPL: MaybeUninit<
 #[doc(hidden)]
 pub enum MachineConsole {
     Uart16550(*const Uart16550<u8>),
+    UartAxiLte(MmioUartAxiLite),
 }
 
 unsafe impl Send for MachineConsole {}
@@ -31,20 +32,32 @@ impl ConsoleDevice for MachineConsole {
     fn read(&self, buf: &mut [u8]) -> usize {
         match self {
             Self::Uart16550(uart16550) => unsafe { (**uart16550).read(buf) },
+            Self::UartAxiLte(axilite) => axilite.read(buf),
         }
     }
 
     fn write(&self, buf: &[u8]) -> usize {
         match self {
             MachineConsole::Uart16550(uart16550) => unsafe { (**uart16550).write(buf) },
+            Self::UartAxiLte(axilite) => axilite.write(buf),
         }
     }
 }
 
+// TODO: select driver follow fdt
+
 #[doc(hidden)]
+#[cfg(feature = "nemu")]
+pub(crate) static UART: Mutex<MachineConsole> =
+    Mutex::new(MachineConsole::UartAxiLte(MmioUartAxiLite::new(0)));
+#[cfg(not(feature = "nemu"))]
 pub(crate) static UART: Mutex<MachineConsole> = Mutex::new(MachineConsole::Uart16550(null()));
 pub(crate) fn console_dev_init(base: usize) {
-    *UART.lock() = MachineConsole::Uart16550(base as _);
+    let new_console = match *UART.lock() {
+        MachineConsole::Uart16550(_) => MachineConsole::Uart16550(base as _),
+        MachineConsole::UartAxiLte(_) => MachineConsole::UartAxiLte(MmioUartAxiLite::new(base)),
+    };
+    *UART.lock() = new_console;
 }
 
 /// Ipi Device: Sifive Clint