-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[target.aarch64-unknown-linux-musl] | ||
rustflags = [ "-C", "target-feature=+crt-static", "-C", "link-arg=-lgcc" ] | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "rust-vmm-ci"] | ||
path = rust-vmm-ci | ||
url = https://github.com/rust-vmm/rust-vmm-ci.git |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"coverage_score": 0, | ||
"exclude_path": "", | ||
"crate_features": "" | ||
} |
Submodule rust-vmm-ci
added at
bb1cd1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,31 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
fn it_works() { | ||
assert_eq!(2 + 2, 4); | ||
} | ||
// Copyright © 2019 Intel Corporation. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause | ||
|
||
//! rust-vmm device model. | ||
|
||
extern crate vm_memory; | ||
|
||
use vm_memory::GuestAddress; | ||
|
||
/// 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(&mut self, addr: IoAddress, data: &mut [u8]); | ||
|
||
/// Write `data` to the guest physical address `addr`. | ||
fn write(&mut self, addr: IoAddress, data: &[u8]); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andMmioDevice
traits or something along those lines. That seems a bit nicer, especially if there are only going to be two variants in theIoType
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.
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:
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:)