@@ -9,6 +9,8 @@ address range, IRQ number, etc)
99
1010## Design
1111
12+ ### I/O
13+
1214The virtual device model is built around four traits, ` DevicePio ` and
1315` MutDevicePio ` for
1416[ Programmed I/O] ( https://en.wikipedia.org/wiki/Programmed_input%E2%80%93output )
@@ -42,8 +44,38 @@ that there’s a virtual device registered on the bus for the requested address,
4244and finally sends the request to that device.
4345![ vm-device] ( https://user-images.githubusercontent.com/241037/143853115-b1526028-6836-4845-a311-71cf989c60ef.png )
4446
47+ ### Interrupts
48+
49+ Interrupt delivery and configuration is built around the ` Interrupt ` and
50+ ` InterruptSourceGroup ` traits. These traits allow devices that are developped in
51+ separate crates from the VMM to trigger and configure interrupt delivery to the
52+ guest VM without having a dependency on the implementation of the interrupt
53+ mechanism.
54+
55+ The ` Interrupt ` trait provides methods that are used by devices to trigger,
56+ enable and disable interrupts. Access to additional interrupt properties
57+ is defined in new super-traits. ` ConfigurableInterrupt ` allows for devices to
58+ send or receive interrupt configuration parameters to/from the implementation
59+ inside the VMM. This is useful when devices need to specify custom data that
60+ the VMM will use when delivering the interrupt (e.g. MSI device id, PCI
61+ INTx pin etc).
62+ ` MaskableInterrupt ` is also defined as a supertrait for use with interrupts
63+ that can be masked/unmasked.
64+ Using super-traits for these properties allows further extension in the future.
65+
66+ An ` InterruptSourceGroup ` stores a collection of interrupts of the same type and
67+ is the interface through which a device may request or release interrupts and
68+ perform group related actions like enabling or disabling all interrupts at once.
69+ Each device that generates interrupts can be assigned one or more
70+ ` InterruptSourceGroup ` s (depending on the types of interrupts it uses or logical
71+ grouping.) The following diagram depincts the interaction between the components
72+ that use the interrupt interface:
73+
74+ ![ vm-device-interrupts] ( https://user-images.githubusercontent.com/86006646/148783015-fea49a7c-cff8-4ec7-8766-00b0baed41c5.png )
75+
4576## Usage
4677
78+ ### I/O
4779A device is usually attached to a particular bus and thus needs to implement a
4880trait of only one type. For example, serial port on x86 is a PIO device, while
4981VirtIO devices use MMIO. It’s also possible for a device to implement both. Once
@@ -67,6 +99,26 @@ address range to the device. The requests are dispatched by the client code, for
6799example when handling VM exits, using ` IoManager ` 's methods ` pio_read ` ,
68100` pio_write ` , ` mmio_read ` and ` mmio_write ` .
69101
102+ ### Interrupts
103+
104+ To allow a device to use interrupts, a VMM must implement the ` Interrupt ` and
105+ ` InterruptSourceGroup ` traits for the interrupt mechanisms that the device requires.
106+ Implementation is machine or VMM speciffic and may depend on the types and number
107+ of IRQ chips that the machine has or interrupt delivery mechanisms (e.g. ` EventFd ` s).
108+ The device generally does not concern itself with the actual implementation of
109+ the interrupts and will be initialized with one or more ` InterruptSourceGroup ` s
110+ by the VMM.
111+
112+ The device may define constraints for the types of interrupts that it needs
113+ (e.g. it needs a ` ConfigurableInterrupt ` that can receive the ` LegacyIrqConfig `
114+ configuration struct).
115+ The device may also define constraints regarding the type of ` NotifierType ` that the
116+ ` Interrupt ` is using. This type defines the interrupt delivery mechanism and is
117+ specific to the Hypervisor (e.g. KVM irqfd, Xen evtchn etc).
118+ One example of this requirement is the development of a VFIO device. Since VFIO
119+ can trigger a KVM irqfd directly, the VFIO device would need to get access to the
120+ underlying irqfd in order to register it with VFIO.
121+
70122## Examples
71123
72124### Implementing a simple log PIO device
@@ -119,3 +171,4 @@ This project is licensed under either of:
119171
120172- [ Apache License] ( http://www.apache.org/licenses/LICENSE-2.0 ) , Version 2.0
121173- [ BSD-3-Clause License] ( https://opensource.org/licenses/BSD-3-Clause )
174+
0 commit comments