kernel/object/capability/
control.rs

1//! Control operations capability module
2//!
3//! This module provides system calls and traits for ControlOps capability,
4//! which enables device control operations (ioctl-equivalent) on KernelObjects.
5
6use alloc::vec::Vec;
7
8/// Control operations capability
9///
10/// This trait represents the ability to perform control operations
11/// on a resource, similar to ioctl operations in POSIX systems.
12/// Control operations allow querying and modifying device-specific
13/// settings and configurations.
14pub trait ControlOps: Send + Sync {
15    /// Perform a control operation
16    ///
17    /// # Arguments
18    ///
19    /// * `command` - The control command identifier
20    /// * `arg` - Command-specific argument (often a pointer to data)
21    ///
22    /// # Returns
23    ///
24    /// * `Result<i32, &'static str>` - Command-specific return value or error
25    ///
26    /// # Default Implementation
27    ///
28    /// The default implementation returns an error indicating that control
29    /// operations are not supported by this object.
30    fn control(&self, command: u32, arg: usize) -> Result<i32, &'static str> {
31        let _ = (command, arg);
32        Err("Control operation not supported")
33    }
34
35    /// Get a list of supported control commands
36    ///
37    /// # Returns
38    ///
39    /// A vector of tuples containing (command_id, description) for each
40    /// supported control command. This can be used for introspection
41    /// and debugging purposes.
42    ///
43    /// # Default Implementation
44    ///
45    /// The default implementation returns an empty vector, indicating
46    /// no control commands are supported.
47    fn supported_control_commands(&self) -> Vec<(u32, &'static str)> {
48        Vec::new()
49    }
50}