-
Notifications
You must be signed in to change notification settings - Fork 22
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
Conversation
- 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]>
98a7819
to
af70dfb
Compare
/// 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 { |
There was a problem hiding this comment.
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, GuestAddress
es are a bit jarring to use semantically for port IO.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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),
}
There was a problem hiding this comment.
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]);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exactly:)
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]>
No description provided.