tpu_sg2002/kernel_fns.rs
1//! Kernel function abstractions for TPU device layer.
2
3/// Physical address type.
4pub type PhysAddr = u64;
5
6/// Time type for timestamps (microseconds).
7pub type TimeStamp = u64;
8
9/// Log levels.
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum LogLevel {
12 Error,
13 Warn,
14 Info,
15 Debug,
16}
17
18/// Kernel functions required by the TPU device layer.
19pub trait KernelFns {
20 /// Sleep for the given number of milliseconds.
21 ///
22 /// Optional hook. The current SG2002 fast path no longer relies on this,
23 /// but it is retained for portability and future backoff strategies.
24 fn sleep_ms(&self, _ms: u32) {}
25
26 /// Return a monotonic timestamp in microseconds.
27 fn now_us(&self) -> TimeStamp;
28
29 /// Logging hook.
30 fn log(&self, level: LogLevel, msg: &str);
31
32 /// Enable TPU clocks.
33 fn enable_clocks(&self) {}
34
35 /// Disable TPU clocks.
36 fn disable_clocks(&self) {}
37
38 /// Reset TPU hardware.
39 fn reset(&self) {}
40
41 /// Clean data cache for DMA buffer before device access.
42 fn dma_sync_for_device(&self, _paddr: PhysAddr, _size: usize) {}
43
44 /// Invalidate data cache for DMA buffer after device access.
45 fn dma_sync_for_cpu(&self, _paddr: PhysAddr, _size: usize) {}
46}