twizzler_driver/
controller.rs1use std::sync::Arc;
2
3use twizzler_abi::device::MailboxPriority;
4use twizzler_rt_abi::Result;
5
6use crate::device::{
7 events::{DeviceEventStream, InterruptInfo},
8 Device,
9};
10
11pub struct DeviceController {
13 device: Arc<Device>,
14 events: Arc<DeviceEventStream>,
15}
16
17impl DeviceController {
18 pub fn events(&self) -> &DeviceEventStream {
20 &self.events
21 }
22
23 pub fn device(&self) -> &Device {
25 &self.device
26 }
27
28 pub fn new_from_device(device: Device) -> Self {
30 let device = Arc::new(device);
31 Self {
32 device: device.clone(),
33 events: Arc::new(DeviceEventStream::new(device)),
34 }
35 }
36
37 pub fn allocate_interrupt(&self) -> Result<InterruptInfo> {
39 self.events.allocate_interrupt()
40 }
41
42 pub fn check_mailbox(&self, pri: MailboxPriority) -> Option<u64> {
44 self.events.check_mailbox(pri)
45 }
46
47 pub async fn next_msg(&self, min: MailboxPriority) -> (MailboxPriority, u64) {
49 self.events.next_msg(min).await
50 }
51}