pub struct BusSchemeServer {
drivers: Vec<(String, Box<dyn BusDriver>)>,
port_handle: u64,
handles: BTreeMap<u64, OpenHandle>,
next_id: u64,
pci_cache: Vec<PciDeviceInfo>,
find_cache: BTreeMap<(u16, u16), Vec<u8>>,
name_to_idx: BTreeMap<String, usize>,
}Fields§
§drivers: Vec<(String, Box<dyn BusDriver>)>§port_handle: u64§handles: BTreeMap<u64, OpenHandle>§next_id: u64§pci_cache: Vec<PciDeviceInfo>§find_cache: BTreeMap<(u16, u16), Vec<u8>>Rendered pci/find/<vid>/<did> results, keyed by (vendor, device).
Each read of a find file used to re-run the pci_enum syscall and
re-render the whole listing; sequential reads of a long result were
O(reads × devices). The cache is invalidated on every rescan so
results stay coherent with pci/inventory.
name_to_idx: BTreeMap<String, usize>Driver-name → index into drivers, built once at construction.
Path resolution is O(log n) instead of a linear scan over all driver names on every open/existence check : significant with the 100–1000 drivers this server is expected to host.
Implementations§
Source§impl BusSchemeServer
impl BusSchemeServer
Sourcepub fn new(drivers: Vec<(String, Box<dyn BusDriver>)>, port_handle: u64) -> Self
pub fn new(drivers: Vec<(String, Box<dyn BusDriver>)>, port_handle: u64) -> Self
Creates a new instance.
Sourcepub fn refresh_pci_cache(&mut self) -> Result<usize, ()>
pub fn refresh_pci_cache(&mut self) -> Result<usize, ()>
Performs the refresh pci cache operation.
Returns Ok(count) with the number of devices found, or Err(()) if the
underlying pci_enum syscall failed (cache remains unchanged).
fn ok_reply(sender: u64) -> IpcMessage
fn err_reply(sender: u64, code: usize) -> IpcMessage
fn alloc_id(&mut self) -> Option<u64>
Sourcefn count_handles_of(&self, sender: u64) -> usize
fn count_handles_of(&self, sender: u64) -> usize
Count open handles belonging to sender.
Sourcefn resolve_driver_path<'a>(&self, path: &'a str) -> Option<(usize, &'a str)>
fn resolve_driver_path<'a>(&self, path: &'a str) -> Option<(usize, &'a str)>
Split a normalised path into a driver index + sub-path, or detect PCI / root.
fn is_pci_path(path: &str) -> bool
fn path_exists(&self, path: &str) -> bool
fn parse_reg_offset(path: &str) -> Option<usize>
Sourcefn parse_hex_usize(s: &str) -> Option<usize>
fn parse_hex_usize(s: &str) -> Option<usize>
Parse an unsigned hex value, rejecting inputs from_str_radix
would otherwise accept:
- sign prefixes (
"+1f","-1f"), - repeated
0xprefixes ("0x0x10", previously stripped in a loop).
fn parse_hex_u8(s: &str) -> Option<u8>
fn parse_hex_u16(s: &str) -> Option<u16>
Sourcefn parse_firewall_id(sub_path: &str) -> Option<u32>
fn parse_firewall_id(sub_path: &str) -> Option<u32>
Parses the peripheral id of a firewall/<grant|release>/<id> path.
fn handle_open(&mut self, sender: u64, payload: &[u8]) -> IpcMessage
fn handle_read(&mut self, sender: u64, payload: &[u8]) -> IpcMessage
fn generate_read_content(&mut self, kind: &HandleKind, offset: usize) -> Vec<u8> ⓘ
fn read_pci_content(&mut self, path: &str) -> Vec<u8> ⓘ
fn read_driver_content( &self, driver: &Box<dyn BusDriver>, name: &str, sub_path: &str, ) -> Vec<u8> ⓘ
fn handle_write(&mut self, sender: u64, payload: &[u8]) -> IpcMessage
fn handle_close(&mut self, sender: u64, payload: &[u8]) -> IpcMessage
fn handle_readdir(&self, sender: u64, payload: &[u8]) -> IpcMessage
Sourcepub fn dispatch(
&mut self,
msg_type: u32,
sender: u64,
payload: &[u8],
) -> IpcMessage
pub fn dispatch( &mut self, msg_type: u32, sender: u64, payload: &[u8], ) -> IpcMessage
Dispatches one request and returns the reply message.
Public so that the scheme contract can be exercised by host-side integration tests without a live kernel IPC transport.
Sourcefn normalize_path(path: &str) -> Option<String>
fn normalize_path(path: &str) -> Option<String>
Normalise a client-supplied path for the /bus namespace:
- collapses repeated
/, - drops
.segments, - resolves
..lexically (returnsNoneif it escapes the root).
The root is the empty string. Without this, a path such as
pci/../<driver>/reg/x could bypass naive prefix matching if
sub-tree resolution ever becomes recursive.