1- // #![deny(missing_docs)]
1+ #![ deny( missing_docs) ]
22
33use crate :: apic;
44use crate :: boot_info:: BootInfo ;
@@ -18,7 +18,6 @@ use crate::virtdev::{
1818use alloc:: boxed:: Box ;
1919use alloc:: collections:: BTreeMap ;
2020use alloc:: string:: String ;
21- use alloc:: vec:: Vec ;
2221use arraydeque:: ArrayDeque ;
2322use arrayvec:: ArrayVec ;
2423use core:: default:: Default ;
@@ -48,6 +47,8 @@ const MAX_DYNAMIC_VIRTUAL_DEVICES: usize = 32;
4847
4948const MAX_PENDING_MSG : usize = 100 ;
5049
50+ const MAX_IMAGE_MAPPING_PER_VM : usize = 16 ;
51+
5152/// Initialize the global VirtualMachineSet
5253///
5354/// This method must be called before calling 'virtual_machines'
@@ -348,13 +349,22 @@ pub struct HostPhysicalDevices {
348349
349350/// A configuration for a `VirtualMachine`
350351pub struct VirtualMachineConfig {
352+ /// The cores assigned as part of this configuration
351353 pub cpus : ArrayVec < [ percore:: CoreId ; MAX_PER_VM_CORE_COUNT ] > ,
352- pub images : Vec < ( String , GuestPhysAddr ) > ,
354+
355+ /// The images that will be mapped into the address space of this virtual machine
356+ pub images : ArrayVec < [ ( String , GuestPhysAddr ) ; MAX_IMAGE_MAPPING_PER_VM ] > ,
357+
358+ /// The 'dnyamic' virtual devices assigned to this virtual machine
353359 pub virtual_devices : ArrayVec <
354360 [ RwLock < virtdev:: DynamicVirtualDevice > ; MAX_DYNAMIC_VIRTUAL_DEVICES ] ,
355361 > ,
362+
363+ /// The host physical devices assigned to this virtual machine
356364 pub host_devices : HostPhysicalDevices ,
357- pub memory : u64 , // in MB
365+
366+ /// The size of this machines physical address space in MiB
367+ pub memory : u64 ,
358368}
359369
360370impl VirtualMachineConfig {
@@ -373,7 +383,7 @@ impl VirtualMachineConfig {
373383 cpu_array. try_extend_from_slice ( cpus) ?;
374384 Ok ( VirtualMachineConfig {
375385 cpus : cpu_array,
376- images : vec ! [ ] ,
386+ images : ArrayVec :: new ( ) ,
377387 virtual_devices : ArrayVec :: new ( ) ,
378388 host_devices : physical_devices,
379389 memory : memory,
@@ -531,8 +541,21 @@ impl VirtualMachine {
531541 let dev = match self . virtual_device_map . find_device ( ident) {
532542 Some ( dev) => dev,
533543 None => {
534- // warn!("Unable to dispatch event");
535- return Ok ( ( ) ) ;
544+ // TODO(alschwalm): port operations can produce GP faults
545+ return match kind {
546+ DeviceEvent :: PortRead ( _, mut req) => {
547+ // Port reads from unknown devices return 0
548+ req. copy_from_u32 ( 0 ) ;
549+ Ok ( ( ) )
550+ }
551+ DeviceEvent :: PortWrite ( _, _) => {
552+ // Just ignore writes to unknown ports
553+ Ok ( ( ) )
554+ }
555+ _ => Err ( Error :: MissingDevice (
556+ "Unable to dispatch event" . into ( ) ,
557+ ) ) ,
558+ } ;
536559 }
537560 } ;
538561
0 commit comments