Struct vm_superio::i8042::I8042Device

source ·
pub struct I8042Device<T: Trigger> { /* private fields */ }
Expand description

An i8042 PS/2 controller that emulates just enough to shutdown the machine.

A Trigger object is used for notifying the VMM about the CPU reset event.

§Example


struct EventFdTrigger(EventFd);
impl Trigger for EventFdTrigger {
    type E = Error;

    fn trigger(&self) -> Result<()> {
        self.write(1)
    }
}
impl Deref for EventFdTrigger {
    type Target = EventFd;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
impl EventFdTrigger {
    pub fn new(flag: i32) -> Self {
        EventFdTrigger(EventFd::new(flag).unwrap())
    }
}

let reset_evt = EventFdTrigger::new(libc::EFD_NONBLOCK);
let mut i8042 = I8042Device::new(reset_evt);

// Check read/write operations.
assert_eq!(i8042.read(0), 0);
i8042.write(4, 0xFE).unwrap();

Implementations§

source§

impl<T: Trigger> I8042Device<T>

source

pub fn new(reset_evt: T) -> I8042Device<T>

Constructs an i8042 device that will signal the given event when the guest requests it.

§Arguments
  • reset_evt - A Trigger object that will be used to notify the driver about the reset event.
§Example

You can see an example of how to use this function in the Example section from I8042Device.

source

pub fn reset_evt(&self) -> &T

Provides a reference to the reset event object.

source

pub fn read(&mut self, _offset: u8) -> u8

Handles a read request from the driver at _offset offset from the base I/O address.

Returns the read value, which at this moment is 0x00, since we’re not interested in an i8042 operation other than CPU reset.

§Arguments
  • _offset - The offset that will be added to the base address for writing to a specific register.
§Example

You can see an example of how to use this function in the Example section from I8042Device.

source

pub fn write(&mut self, offset: u8, value: u8) -> Result<(), T::E>

Handles a write request from the driver at offset offset from the base I/O address.

§Arguments
  • offset - The offset that will be added to the base address for writing to a specific register.
  • value - The byte that should be written.
§Example

You can see an example of how to use this function in the Example section from I8042Device.

Trait Implementations§

source§

impl<T: Debug + Trigger> Debug for I8042Device<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for I8042Device<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for I8042Device<T>
where T: RefUnwindSafe,

§

impl<T> Send for I8042Device<T>
where T: Send,

§

impl<T> Sync for I8042Device<T>
where T: Sync,

§

impl<T> Unpin for I8042Device<T>
where T: Unpin,

§

impl<T> UnwindSafe for I8042Device<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.