Trait uacpi::kernel_api::KernelApi
source · pub trait KernelApi {
Show 37 methods
// Required methods
unsafe fn raw_memory_read(
&self,
phys: PhysAddr,
byte_width: u8,
) -> Result<u64, Status>;
unsafe fn raw_memory_write(
&self,
phys: PhysAddr,
byte_width: u8,
val: u64,
) -> Result<(), Status>;
unsafe fn raw_io_read(
&self,
addr: IOAddr,
byte_width: u8,
) -> Result<u64, Status>;
unsafe fn raw_io_write(
&self,
addr: IOAddr,
byte_width: u8,
val: u64,
) -> Result<(), Status>;
unsafe fn pci_read(
&self,
address: PCIAddress,
offset: usize,
byte_width: u8,
) -> Result<u64, Status>;
unsafe fn pci_write(
&self,
address: PCIAddress,
offset: usize,
byte_width: u8,
val: u64,
) -> Result<(), Status>;
unsafe fn io_map(&self, base: IOAddr, len: usize) -> Result<Handle, Status>;
unsafe fn io_unmap(&self, handle: Handle);
unsafe fn io_read(
&self,
handle: Handle,
offset: usize,
byte_width: u8,
) -> Result<u64, Status>;
unsafe fn io_write(
&self,
handle: Handle,
offset: usize,
byte_width: u8,
val: u64,
) -> Result<(), Status>;
unsafe fn map(&self, phys: PhysAddr, len: usize) -> *mut c_void;
unsafe fn unmap(&self, addr: *mut c_void, len: usize);
fn get_ticks(&self) -> u64;
fn stall(&self, usec: u8);
fn sleep(&self, msec: u8);
fn create_mutex(&self) -> Handle;
fn destroy_mutex(&self, mutex: Handle);
fn acquire_mutex(&self, mutex: Handle, timeout: u16) -> bool;
fn release_mutex(&self, mutex: Handle);
fn create_spinlock(&self) -> Handle;
fn destroy_spinlock(&self, lock: Handle);
fn acquire_spinlock(&self, lock: Handle) -> CpuFlags;
fn release_spinlock(&self, lock: Handle, cpu_flags: CpuFlags);
fn create_event(&self) -> Handle;
fn destroy_event(&self, event: Handle);
fn wait_for_event(&self, event: Handle, timeout: u16) -> bool;
fn signal_event(&self, event: Handle);
fn reset_event(&self, event: Handle);
fn get_thread_id(&self) -> ThreadId;
fn firmware_request(&self, req: FirmwareRequest) -> Result<(), Status>;
fn install_interrupt_handler(
&self,
irq: u32,
handler: Box<dyn Fn()>,
) -> Result<Handle, Status>;
fn uninstall_interrupt_handler(&self, handle: Handle) -> Result<(), Status>;
fn schedule_work(
&self,
work_type: WorkType,
handler: Box<dyn Fn()>,
) -> Result<(), Status>;
fn wait_for_work_completion(&self) -> Result<(), Status>;
// Provided methods
unsafe fn alloc(&self, layout: Layout) -> *mut u8 { ... }
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { ... }
fn log(&self, log_level: LogLevel, string: &str) { ... }
}Required Methods§
sourceunsafe fn raw_memory_read(
&self,
phys: PhysAddr,
byte_width: u8,
) -> Result<u64, Status>
unsafe fn raw_memory_read( &self, phys: PhysAddr, byte_width: u8, ) -> Result<u64, Status>
Reads a value of the specified byte width (1, 2, 4 or 8) from memory.
sourceunsafe fn raw_memory_write(
&self,
phys: PhysAddr,
byte_width: u8,
val: u64,
) -> Result<(), Status>
unsafe fn raw_memory_write( &self, phys: PhysAddr, byte_width: u8, val: u64, ) -> Result<(), Status>
Writes a value of the specified byte width (1, 2, 4 or 8) to memory.
sourceunsafe fn raw_io_read(
&self,
addr: IOAddr,
byte_width: u8,
) -> Result<u64, Status>
unsafe fn raw_io_read( &self, addr: IOAddr, byte_width: u8, ) -> Result<u64, Status>
Reads a value of the specified byte width (1, 2 or 4) from io.
sourceunsafe fn raw_io_write(
&self,
addr: IOAddr,
byte_width: u8,
val: u64,
) -> Result<(), Status>
unsafe fn raw_io_write( &self, addr: IOAddr, byte_width: u8, val: u64, ) -> Result<(), Status>
Writes a value of the specified byte width (1, 2 or 4) to io.
sourceunsafe fn pci_read(
&self,
address: PCIAddress,
offset: usize,
byte_width: u8,
) -> Result<u64, Status>
unsafe fn pci_read( &self, address: PCIAddress, offset: usize, byte_width: u8, ) -> Result<u64, Status>
Reads a value of the specified byte width (1, 2 or 4) from a 0-based offset within the pci configuration space. Since PCI registers are 32 bits wide this must be able to handle e.g. 1-byte access by reading at the nearest 4-byte aligned offset below, then masking the value to select the target byte.
sourceunsafe fn pci_write(
&self,
address: PCIAddress,
offset: usize,
byte_width: u8,
val: u64,
) -> Result<(), Status>
unsafe fn pci_write( &self, address: PCIAddress, offset: usize, byte_width: u8, val: u64, ) -> Result<(), Status>
Writes a value of the specified byte width (1, 2 or 4) to a 0-based offset within the pci configuration space. Since PCI registers are 32 bits wide this must be able to handle e.g. 1-byte access by reading at the nearest 4-byte aligned offset below, then masking everything except the target byte and writing that value with the value put in the target byte back.
sourceunsafe fn io_map(&self, base: IOAddr, len: usize) -> Result<Handle, Status>
unsafe fn io_map(&self, base: IOAddr, len: usize) -> Result<Handle, Status>
Maps a SystemIO address at [base, base + len] and return a handle that can be used for reading and writing to the IO range.
sourceunsafe fn io_read(
&self,
handle: Handle,
offset: usize,
byte_width: u8,
) -> Result<u64, Status>
unsafe fn io_read( &self, handle: Handle, offset: usize, byte_width: u8, ) -> Result<u64, Status>
Reads a value of the specified byte width (1, 2 or 4) from a 0-based offset within a mapped IO range.
sourceunsafe fn io_write(
&self,
handle: Handle,
offset: usize,
byte_width: u8,
val: u64,
) -> Result<(), Status>
unsafe fn io_write( &self, handle: Handle, offset: usize, byte_width: u8, val: u64, ) -> Result<(), Status>
writes a value of the specified byte width (1, 2 or 4) to a 0-based offset within a mapped IO range.
sourceunsafe fn map(&self, phys: PhysAddr, len: usize) -> *mut c_void
unsafe fn map(&self, phys: PhysAddr, len: usize) -> *mut c_void
Creates a mapping used to access the physical range [phys, phys + len].
sourceunsafe fn unmap(&self, addr: *mut c_void, len: usize)
unsafe fn unmap(&self, addr: *mut c_void, len: usize)
Unmaps a mapping previously returned from map.
sourcefn get_ticks(&self) -> u64
fn get_ticks(&self) -> u64
Returns the monotonic count of 100 nanosecond ticks elapsed since boot.
sourcefn create_mutex(&self) -> Handle
fn create_mutex(&self) -> Handle
Creates a non-recursive kernel mutex.
sourcefn destroy_mutex(&self, mutex: Handle)
fn destroy_mutex(&self, mutex: Handle)
Destroys a mutex previously created by create_mutex.
sourcefn acquire_mutex(&self, mutex: Handle, timeout: u16) -> bool
fn acquire_mutex(&self, mutex: Handle, timeout: u16) -> bool
Tries to acquire a mutex with a millisecond timeout. A timeout value of 0xFFFF implies infinite wait.
sourcefn release_mutex(&self, mutex: Handle)
fn release_mutex(&self, mutex: Handle)
Releases a previously acquired mutex.
sourcefn create_spinlock(&self) -> Handle
fn create_spinlock(&self) -> Handle
Creates a spinlock.
sourcefn destroy_spinlock(&self, lock: Handle)
fn destroy_spinlock(&self, lock: Handle)
Destroys a spinlock previously created by create_spinlock.
sourcefn acquire_spinlock(&self, lock: Handle) -> CpuFlags
fn acquire_spinlock(&self, lock: Handle) -> CpuFlags
Disables interrupts and acquires a spinlock. Returns the previous state of cpu flags that can be used to restore the interrupt state when the lock is released.
sourcefn release_spinlock(&self, lock: Handle, cpu_flags: CpuFlags)
fn release_spinlock(&self, lock: Handle, cpu_flags: CpuFlags)
Releases a spinlock and restores the previous interrupt state.
sourcefn create_event(&self) -> Handle
fn create_event(&self) -> Handle
Creates a semaphore-line event object.
sourcefn destroy_event(&self, event: Handle)
fn destroy_event(&self, event: Handle)
Destroys an event previously created by create_event.
sourcefn wait_for_event(&self, event: Handle, timeout: u16) -> bool
fn wait_for_event(&self, event: Handle, timeout: u16) -> bool
Waits for an event (counter > 0) with a millisecond timeout. A timeout value of 0xFFFF implies infinite wait. The internal counter is decremented by 1 if the wait was successful. A successful wait is indicated by returning true.
sourcefn signal_event(&self, event: Handle)
fn signal_event(&self, event: Handle)
Signals an event by incrementing its internal counter by 1. This functions may be used in interrupt contexts.
sourcefn reset_event(&self, event: Handle)
fn reset_event(&self, event: Handle)
Resets an event by setting its internal counter to 0.
sourcefn get_thread_id(&self) -> ThreadId
fn get_thread_id(&self) -> ThreadId
Returns a unique identifier of the currently executing thread.
sourcefn firmware_request(&self, req: FirmwareRequest) -> Result<(), Status>
fn firmware_request(&self, req: FirmwareRequest) -> Result<(), Status>
Handles a firmware request.
sourcefn install_interrupt_handler(
&self,
irq: u32,
handler: Box<dyn Fn()>,
) -> Result<Handle, Status>
fn install_interrupt_handler( &self, irq: u32, handler: Box<dyn Fn()>, ) -> Result<Handle, Status>
Installs an interrupt handler for irq.
The returned handle can be used to refer to this handler from other API.
sourcefn uninstall_interrupt_handler(&self, handle: Handle) -> Result<(), Status>
fn uninstall_interrupt_handler(&self, handle: Handle) -> Result<(), Status>
Uninstalls an interrupt handler previously installed with install_interrupt_handler.
sourcefn schedule_work(
&self,
work_type: WorkType,
handler: Box<dyn Fn()>,
) -> Result<(), Status>
fn schedule_work( &self, work_type: WorkType, handler: Box<dyn Fn()>, ) -> Result<(), Status>
Schedules deferred work for execution. Might be invoked from an interrupt context.
sourcefn wait_for_work_completion(&self) -> Result<(), Status>
fn wait_for_work_completion(&self) -> Result<(), Status>
Blocks until all scheduled work is complete and the work queue is empty.