Skip to content

Commit

Permalink
feat(core/remote_io): add Remote I/O infrastructure
Browse files Browse the repository at this point in the history
This commit introduces the foundational support for VirtIO by implementing
a mechanism to forward VirtIO requests bidirectionally between the
guest VM (or frontend VM) and its associated backend VM.

Signed-off-by: João Peixoto <[email protected]>
  • Loading branch information
joaopeixoto13 committed Sep 19, 2024
1 parent f3b87e3 commit 0afe0bf
Show file tree
Hide file tree
Showing 8 changed files with 654 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/core/hypercall.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ long int hypercall(unsigned long id)
case HC_IPC:
ret = ipc_hypercall(arg0, arg1, arg2);
break;
case HC_REMOTE_IO:
ret = remote_io_hypercall(arg0, arg1, arg2);
break;
default:
WARNING("Unknown hypercall id %d", id);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/inc/hypercall.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <bao.h>
#include <arch/hypercall.h>

enum { HC_INVAL = 0, HC_IPC = 1 };
enum { HC_INVAL = 0, HC_IPC = 1, HC_REMOTE_IO = 2 };

enum { HC_E_SUCCESS = 0, HC_E_FAILURE = 1, HC_E_INVAL_ID = 2, HC_E_INVAL_ARGS = 3 };

Expand Down
77 changes: 77 additions & 0 deletions src/core/inc/remote_io.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) Bao Project and Contributors. All rights reserved.
*/

/**
* @file remote_io.h
* @brief This header file contains the Remote I/O device interface
*/

#ifndef __REMOTE_IO_H__
#define __REMOTE_IO_H__

#include <bao.h>
#include <emul.h>
#include <list.h>
#include <vm.h>

/**
* @struct remote_io_shmem
* @brief This structure represents a shared memory region used by a Remote I/O device
*/
struct remote_io_shmem {
paddr_t base; /**< Shared memory base address */
size_t size; /**< Shared memory size */
size_t shmem_id; /**< Shared memory ID */
};

/**
* @struct remote_io_dev
* @brief This structure represents a Remote I/O device
* @note The device can be either a frontend (driver) or a backend (device)
*/
struct remote_io_dev {
vaddr_t va; /**< Frontend MMIO base virtual address */
size_t size; /**< Frontend MMIO size */
irqid_t interrupt; /**< Frontend/backend interrupt number */
uint64_t id; /**< Remote I/O ID */
bool is_backend; /**< True if the device is a backend */
struct remote_io_shmem shmem; /**< Shared memory region */
};

/**
* @brief Remote I/O device initialization routine
* @note Executed only once by the master CPU
*/
void remote_io_init(void);

/**
* @brief Remote I/O device CPU assignment routine
* @note Executed by each VM that holds a Remote I/O device, it is responsible for
* assigning the frontend or backend CPU ID for the respective Remote I/O device
* If the VM was alloacted with more than one CPU the assigned CPU will be the
* one with the lowest ID, since it is only required one CPU for VM interrupt injecting
* @param vm Pointer to the VM structure
*/
void remote_io_assign_cpus(struct vm* vm);

/**
* @brief Remote I/O hypercall callback
* @note Used to exchange information between the Remote I/O system and the backend VM
* @param arg0 First argument of the hypercall
* @param arg1 Second argument of the hypercall
* @param arg2 Third argument of the hypercall
* @return Returns the number of pending I/O requests
*/
long int remote_io_hypercall(unsigned long arg0, unsigned long arg1, unsigned long arg2);

/**
* @brief Remote I/O MMIO emulation handler
* @note Executed by the frontend VM when a MMIO access is performed
* @param emul_access Holds the information about the MMIO access
* @return Returns true if handled successfully, false otherwise
*/
bool remote_io_mmio_emul_handler(struct emul_access* emul_access);

#endif /* __REMOTE_IO_H__ */
7 changes: 7 additions & 0 deletions src/core/inc/vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <bitmap.h>
#include <io.h>
#include <ipc.h>
#include <remote_io.h>

struct vm_mem_region {
paddr_t base;
Expand Down Expand Up @@ -47,6 +48,9 @@ struct vm_platform {
size_t dev_num;
struct vm_dev_region* devs;

size_t remote_io_dev_num;
struct remote_io_dev* remote_io_devs;

// /**
// * In MPU-based platforms which might also support virtual memory
// * (i.e. aarch64 cortex-r) the hypervisor sets up the VM using an MPU by
Expand Down Expand Up @@ -84,6 +88,9 @@ struct vm {

size_t ipc_num;
struct ipc* ipcs;

size_t remote_io_dev_num;
struct remote_io_dev* remote_io_devs;
};

struct vcpu {
Expand Down
1 change: 1 addition & 0 deletions src/core/objects.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ core-objs-y+=ipc.o
core-objs-y+=objpool.o
core-objs-y+=hypercall.o
core-objs-y+=shmem.o
core-objs-y+=remote_io.o
Loading

0 comments on commit 0afe0bf

Please sign in to comment.