Skip to content

Add device IO trait #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 23, 2019
Merged

Add device IO trait #10

merged 3 commits into from
Oct 23, 2019

Conversation

sameo
Copy link

@sameo sameo commented Oct 22, 2019

No description provided.

@sameo sameo requested a review from a team October 22, 2019 13:31
@ghost ghost requested review from jennymankin and jiangliu and removed request for a team October 22, 2019 13:31
alxiord
alxiord previously approved these changes Oct 22, 2019
Samuel Ortiz added 2 commits October 22, 2019 17:41
- Add the rust-vmm-ci submodule.
- Add the JSON coverage file.

Signed-off-by: Samuel Ortiz <[email protected]>
Signed-off-by: Samuel Ortiz <[email protected]>
@sameo sameo force-pushed the topic/io-trait branch 2 times, most recently from 98a7819 to af70dfb Compare October 22, 2019 14:52
alexandruag
alexandruag previously approved these changes Oct 22, 2019
/// register itself against the different IO type ranges it handles.
/// The VMM will then dispatch IO (PIO or MMIO) VM exits by calling into the
/// registered devices read or write method from this trait.
pub trait DeviceIo: Send {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also the option of having one trait for each type of I/O, i.e. PortIoDevice and MmioDevice traits or something along those lines. That seems a bit nicer, especially if there are only going to be two variants in the IoType enum. Also, FWIW, GuestAddresses are a bit jarring to use semantically for port IO.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This design may cause some obstacles to the Bus/DeviceManager design, we need to explicitly distinguish between Arc and Arc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jiangliu Although I think the Device Manager could be implemented with that approach, it would make for a duplicated API: We'd need to have the same API (register_device, unregister_device, etc) duplicated for each of the variants @alexandruag is proposing. So I think the current proposal is cleaner.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it clear, I agree with current design with an "io_type: IoType" parameter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it clear, I agree with current design with an "io_type: IoType" parameter.

Yep. And I prefer the io_type approach as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To address Andreea concern, we may enhance the io_type enum as:
enum IoType {
Pio(u16),
Mmio(GuestAddress),
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jiangliu You mean something like that:

/// IO Addresses.
#[derive(Debug, Copy, Clone)]
pub enum IoAddress {
    /// Port I/O address.
    Pio(u16),

    /// Memory mapped I/O address.
    Mmio(GuestAddress),
}

/// Device IO trait.
/// A device supporting memory based I/O should implement this trait, then
/// register itself against the different IO type ranges it handles.
/// The VMM will then dispatch IO (PIO or MMIO) VM exits by calling into the
/// registered devices read or write method from this trait.
pub trait DeviceIo: Send {
    /// Read from the guest physical address `addr` to `data`.
    fn read(&self, addr: IoAddress, data: &mut [u8]);

    /// Write `data` to the guest physical address `addr`.
    fn write(&self, addr: IoAddress, data: &[u8]);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly:)

jiangliu
jiangliu previously approved these changes Oct 23, 2019
Any device that supports memory based I/O needs to implement that trait
in order for the VMM to be able to properly dispatch VM exits to the
address ranges said device handles.

Signed-off-by: Samuel Ortiz <[email protected]>
@sameo sameo merged commit 21910a1 into rust-vmm:master Oct 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants