Skip to content

Commit

Permalink
virtio-snd: add WFI handling to VMMs
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Brown <[email protected]>
  • Loading branch information
alexandermbrown committed Apr 29, 2024
1 parent 0339540 commit 6f2772c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion examples/virtio-snd/client_vmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ void notified(microkit_channel ch) {
* the VMM to handle.
*/
void fault(microkit_id id, microkit_msginfo msginfo) {
bool success = fault_handle(id, msginfo);
bool wfi = false;
bool success = fault_handle(id, msginfo, &wfi);
if (success) {
/* Now that we have handled the fault successfully, we reply to it so
* that the guest can resume execution. */
Expand Down
19 changes: 18 additions & 1 deletion examples/virtio-snd/snd_driver_vmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ uintptr_t guest_ram_vaddr;
#define MAX_IRQ_CH 63
int passthrough_irq_map[MAX_IRQ_CH];

bool suspended;
size_t suspend_pc;

#define SERIAL_MUX_TX_CH 1
#define SERIAL_MUX_RX_CH 2
Expand Down Expand Up @@ -204,13 +206,21 @@ void init(void) {
#error Need to define passthrough IRQs
#endif

suspended = false;
suspend_pc = 0;
/* Finally start the guest */
guest_start(GUEST_VCPU_ID, kernel_pc, GUEST_DTB_VADDR, GUEST_INIT_RAM_DISK_VADDR);
}

void notified(microkit_channel ch) {
bool success;

if (suspended) {
LOG_VMM("waking\n");
microkit_vm_restart(GUEST_VCPU_ID, suspend_pc);
suspended = false;
}

switch (ch) {
case SERIAL_MUX_RX_CH: {
/* We have received an event from the serial multiplexer, so we
Expand Down Expand Up @@ -243,8 +253,15 @@ void notified(microkit_channel ch) {
* the VMM to handle.
*/
void fault(microkit_id id, microkit_msginfo msginfo) {
bool success = fault_handle(id, msginfo);
bool wfi = false;
bool success = fault_handle(id, msginfo, &wfi);
if (success) {
if (wfi) {
LOG_VMM("sleeping\n");
microkit_vm_stop(GUEST_VCPU_ID);
suspend_pc = microkit_mr_get(seL4_VMFault_IP);
suspended = true;
}
/* Now that we have handled the fault successfully, we reply to it so
* that the guest can resume execution. */
microkit_fault_reply(microkit_msginfo_new(0, 0));
Expand Down

0 comments on commit 6f2772c

Please sign in to comment.