|
@@ -2,7 +2,7 @@ use super::*;
|
|
|
use alloc::boxed::Box;
|
|
|
use bitflags::*;
|
|
|
use log::*;
|
|
|
-use volatile::Volatile;
|
|
|
+use volatile::{ReadOnly, WriteOnly};
|
|
|
|
|
|
/// Virtual human interface devices such as keyboards, mice and tablets.
|
|
|
///
|
|
@@ -28,10 +28,6 @@ impl<'a> VirtIOInput<'a> {
|
|
|
(features & supported_features).bits()
|
|
|
});
|
|
|
|
|
|
- // read configuration space
|
|
|
- let config = unsafe { &mut *(header.config_space() as *mut Config) };
|
|
|
- info!("Config: {:?}", config);
|
|
|
-
|
|
|
let mut event_queue = VirtQueue::new(header, QUEUE_EVENT, QUEUE_SIZE as u16)?;
|
|
|
let status_queue = VirtQueue::new(header, QUEUE_STATUS, QUEUE_SIZE as u16)?;
|
|
|
for (i, event) in event_buf.as_mut().iter_mut().enumerate() {
|
|
@@ -65,28 +61,57 @@ impl<'a> VirtIOInput<'a> {
|
|
|
}
|
|
|
None
|
|
|
}
|
|
|
+
|
|
|
+ /// Query a specific piece of information by `select` and `subsel`, and write
|
|
|
+ /// result to `out`, return the result size.
|
|
|
+ pub fn query_config_select(
|
|
|
+ &mut self,
|
|
|
+ select: InputConfigSelect,
|
|
|
+ subsel: u8,
|
|
|
+ out: &mut [u8],
|
|
|
+ ) -> u8 {
|
|
|
+ let config = unsafe { &mut *(self.header.config_space() as *mut Config) };
|
|
|
+ config.select.write(select as u8);
|
|
|
+ config.subsel.write(subsel);
|
|
|
+ let size = config.size.read();
|
|
|
+ let data = config.data.read();
|
|
|
+ out[..size as usize].copy_from_slice(&data[..size as usize]);
|
|
|
+ size
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+/// Select value used for [`VirtIOInput::query_config_select()`].
|
|
|
#[repr(u8)]
|
|
|
-#[derive(Debug)]
|
|
|
-enum Cfg {
|
|
|
- Unset = 0x00,
|
|
|
+#[derive(Debug, Clone, Copy)]
|
|
|
+pub enum InputConfigSelect {
|
|
|
+ /// Returns the name of the device, in u.string. subsel is zero.
|
|
|
IdName = 0x01,
|
|
|
+ /// Returns the serial number of the device, in u.string. subsel is zero.
|
|
|
IdSerial = 0x02,
|
|
|
+ /// Returns ID information of the device, in u.ids. subsel is zero.
|
|
|
IdDevids = 0x03,
|
|
|
+ /// Returns input properties of the device, in u.bitmap. subsel is zero.
|
|
|
+ /// Individual bits in the bitmap correspond to INPUT_PROP_* constants used
|
|
|
+ /// by the underlying evdev implementation.
|
|
|
PropBits = 0x10,
|
|
|
+ /// subsel specifies the event type using EV_* constants in the underlying
|
|
|
+ /// evdev implementation. If size is non-zero the event type is supported
|
|
|
+ /// and a bitmap of supported event codes is returned in u.bitmap. Individual
|
|
|
+ /// bits in the bitmap correspond to implementation-defined input event codes,
|
|
|
+ /// for example keys or pointing device axes.
|
|
|
EvBits = 0x11,
|
|
|
+ /// subsel specifies the absolute axis using ABS_* constants in the underlying
|
|
|
+ /// evdev implementation. Information about the axis will be returned in u.abs.
|
|
|
AbsInfo = 0x12,
|
|
|
}
|
|
|
|
|
|
#[repr(C)]
|
|
|
-#[derive(Debug)]
|
|
|
struct Config {
|
|
|
- select: Volatile<u8>,
|
|
|
- subsel: Volatile<u8>,
|
|
|
- size: u8,
|
|
|
- reversed: [u8; 5],
|
|
|
- data: [u8; 32],
|
|
|
+ select: WriteOnly<u8>,
|
|
|
+ subsel: WriteOnly<u8>,
|
|
|
+ size: ReadOnly<u8>,
|
|
|
+ _reversed: [ReadOnly<u8>; 5],
|
|
|
+ data: ReadOnly<[u8; 128]>,
|
|
|
}
|
|
|
|
|
|
#[repr(C)]
|