-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from arceos-hypervisor/guoweikang_init
Add Axvmdevice for vm
- Loading branch information
Showing
4 changed files
with
138 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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,16 @@ | ||
use alloc::vec::Vec; | ||
use axdevice_base::EmulatedDeviceConfig; | ||
|
||
/// The vector of DeviceConfig | ||
pub struct AxVmDeviceConfig { | ||
/// The vector of EmulatedDeviceConfig | ||
pub emu_configs: Vec<EmulatedDeviceConfig>, | ||
} | ||
|
||
/// The implemention for AxVmDeviceConfig | ||
impl AxVmDeviceConfig { | ||
/// The new function for AxVmDeviceConfig | ||
pub fn new(emu_configs: Vec<EmulatedDeviceConfig>) -> Self { | ||
Self { emu_configs } | ||
} | ||
} |
This file contains 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,93 @@ | ||
use crate::AxVmDeviceConfig; | ||
|
||
use alloc::sync::Arc; | ||
use alloc::vec::Vec; | ||
|
||
use axaddrspace::GuestPhysAddr; | ||
use axdevice_base::EmulatedDeviceConfig; | ||
use axdevice_base::{BaseDeviceOps, EmuDeviceType}; | ||
use axerrno::AxResult; | ||
|
||
/// represent A vm own devices | ||
pub struct AxVmDevices { | ||
/// emu devices | ||
emu_devices: Vec<Arc<dyn BaseDeviceOps>>, | ||
// TODO passthrough devices or other type devices ... | ||
} | ||
|
||
/// The implemention for AxVmDevices | ||
impl AxVmDevices { | ||
/// According AxVmDeviceConfig to init the AxVmDevices | ||
pub fn new(config: AxVmDeviceConfig) -> Self { | ||
let mut this = Self { | ||
emu_devices: Vec::new(), | ||
}; | ||
|
||
Self::init(&mut this, &config.emu_configs); | ||
this | ||
} | ||
|
||
/// According the emu_configs to init every specific device | ||
fn init(this: &mut Self, emu_configs: &Vec<EmulatedDeviceConfig>) { | ||
/* | ||
for config in emu_configs { | ||
let dev = match EmuDeviceType::from_usize(config.emu_type) { | ||
// todo call specific initialization function of devcise | ||
EmuDeviceType::EmuDeviceTConsole => , | ||
EmuDeviceType::EmuDeviceTGicdV2 => , | ||
EmuDeviceType::EmuDeviceTGPPT => , | ||
EmuDeviceType::EmuDeviceTVirtioBlk => , | ||
EmuDeviceType::EmuDeviceTVirtioNet => , | ||
EmuDeviceType::EmuDeviceTVirtioConsole => , | ||
EmuDeviceType::EmuDeviceTIOMMU => , | ||
EmuDeviceType::EmuDeviceTICCSRE => , | ||
EmuDeviceType::EmuDeviceTSGIR => , | ||
EmuDeviceType::EmuDeviceTGICR => , | ||
EmuDeviceType::EmuDeviceTMeta => , | ||
_ => panic!("emu type: {} is still not supported", config.emu_type), | ||
}; | ||
if let Ok(emu_dev) = dev { | ||
this.emu_devices.push(emu_dev) | ||
} | ||
} | ||
*/ | ||
} | ||
|
||
/// Find specific device by ipa | ||
pub fn find_dev(&self, ipa: GuestPhysAddr) -> Option<Arc<dyn BaseDeviceOps>> { | ||
self.emu_devices | ||
.iter() | ||
.find(|&dev| dev.address_range().contains(ipa)) | ||
.cloned() | ||
} | ||
|
||
/// Handle the MMIO read by GuestPhysAddr and data width, return the value of the guest want to read | ||
pub fn handle_mmio_read(&self, addr: GuestPhysAddr, width: usize) -> AxResult<usize> { | ||
if let Some(emu_dev) = self.find_dev(addr) { | ||
info!( | ||
"emu: {:?} handler read ipa {:#x}", | ||
emu_dev.address_range(), | ||
addr | ||
); | ||
return emu_dev.handle_read(addr, width); | ||
} | ||
panic!("emu_handle: no emul handler for data abort ipa {:#x}", addr); | ||
} | ||
|
||
/// Handle the MMIO write by GuestPhysAddr, data width and the value need to write, call specific device to write the value | ||
pub fn handle_mmio_write(&self, addr: GuestPhysAddr, width: usize, val: usize) { | ||
if let Some(emu_dev) = self.find_dev(addr) { | ||
info!( | ||
"emu: {:?} handler write ipa {:#x}", | ||
emu_dev.address_range(), | ||
addr | ||
); | ||
emu_dev.handle_write(addr, width, val); | ||
return; | ||
} | ||
panic!( | ||
"emu_handler: no emul handler for data abort ipa {:#x}", | ||
addr | ||
); | ||
} | ||
} |
This file contains 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,14 +1,19 @@ | ||
pub fn add(left: u64, right: u64) -> u64 { | ||
left + right | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn it_works() { | ||
let result = add(2, 2); | ||
assert_eq!(result, 4); | ||
} | ||
} | ||
#![no_std] | ||
|
||
//! This module is designed for an environment where the standard library is not available (`no_std`). | ||
//! | ||
//! The `alloc` crate is used to enable dynamic memory allocation in the absence of the standard library. | ||
//! | ||
//! The `log` crate is included for logging purposes, with macros being imported globally. | ||
//! | ||
//! The module is structured into two main parts: `config` and `device`, which manage the configuration and handling of AxVm devices respectively. | ||
extern crate alloc; | ||
#[macro_use] | ||
extern crate log; | ||
|
||
mod config; | ||
mod device; | ||
|
||
pub use config::AxVmDeviceConfig; | ||
pub use device::AxVmDevices; |