Skip to content

Commit 38d7db2

Browse files
committed
feat(core/remote_io): add Remote I/O infrastructure
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]>
1 parent f3b87e3 commit 38d7db2

File tree

8 files changed

+654
-1
lines changed

8 files changed

+654
-1
lines changed

src/core/hypercall.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ long int hypercall(unsigned long id)
2020
case HC_IPC:
2121
ret = ipc_hypercall(arg0, arg1, arg2);
2222
break;
23+
case HC_REMOTE_IO:
24+
ret = remote_io_hypercall(arg0, arg1, arg2);
25+
break;
2326
default:
2427
WARNING("Unknown hypercall id %d", id);
2528
}

src/core/inc/hypercall.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <bao.h>
1010
#include <arch/hypercall.h>
1111

12-
enum { HC_INVAL = 0, HC_IPC = 1 };
12+
enum { HC_INVAL = 0, HC_IPC = 1, HC_REMOTE_IO = 2 };
1313

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

src/core/inc/remote_io.h

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright (c) Bao Project and Contributors. All rights reserved.
4+
*/
5+
6+
/**
7+
* @file remote_io.h
8+
* @brief This header file contains the Remote I/O device interface
9+
*/
10+
11+
#ifndef __REMOTE_IO_H__
12+
#define __REMOTE_IO_H__
13+
14+
#include <bao.h>
15+
#include <emul.h>
16+
#include <list.h>
17+
#include <vm.h>
18+
19+
/**
20+
* @struct remote_io_shmem
21+
* @brief This structure represents a shared memory region used by a Remote I/O device
22+
*/
23+
struct remote_io_shmem {
24+
paddr_t base; /**< Shared memory base address */
25+
size_t size; /**< Shared memory size */
26+
size_t shmem_id; /**< Shared memory ID */
27+
};
28+
29+
/**
30+
* @struct remote_io_dev
31+
* @brief This structure represents a Remote I/O device
32+
* @note The device can be either a frontend (driver) or a backend (device)
33+
*/
34+
struct remote_io_dev {
35+
vaddr_t va; /**< Frontend MMIO base virtual address */
36+
size_t size; /**< Frontend MMIO size */
37+
irqid_t interrupt; /**< Frontend/backend interrupt number */
38+
uint64_t id; /**< Remote I/O ID */
39+
bool is_backend; /**< True if the device is a backend */
40+
struct remote_io_shmem shmem; /**< Shared memory region */
41+
};
42+
43+
/**
44+
* @brief Remote I/O device initialization routine
45+
* @note Executed only once by the master CPU
46+
*/
47+
void remote_io_init(void);
48+
49+
/**
50+
* @brief Remote I/O device CPU assignment routine
51+
* @note Executed by each VM that holds a Remote I/O device, it is responsible for
52+
* assigning the frontend or backend CPU ID for the respective Remote I/O device
53+
* If the VM was alloacted with more than one CPU the assigned CPU will be the
54+
* one with the lowest ID, since it is only required one CPU for VM interrupt injecting
55+
* @param vm Pointer to the VM structure
56+
*/
57+
void remote_io_assign_cpus(struct vm* vm);
58+
59+
/**
60+
* @brief Remote I/O hypercall callback
61+
* @note Used to exchange information between the Remote I/O system and the backend VM
62+
* @param arg0 First argument of the hypercall
63+
* @param arg1 Second argument of the hypercall
64+
* @param arg2 Third argument of the hypercall
65+
* @return Returns the number of pending I/O requests
66+
*/
67+
long int remote_io_hypercall(unsigned long arg0, unsigned long arg1, unsigned long arg2);
68+
69+
/**
70+
* @brief Remote I/O MMIO emulation handler
71+
* @note Executed by the frontend VM when a MMIO access is performed
72+
* @param emul_access Holds the information about the MMIO access
73+
* @return Returns true if handled successfully, false otherwise
74+
*/
75+
bool remote_io_mmio_emul_handler(struct emul_access* emul_access);
76+
77+
#endif /* __REMOTE_IO_H__ */

src/core/inc/vm.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <bitmap.h>
1818
#include <io.h>
1919
#include <ipc.h>
20+
#include <remote_io.h>
2021

2122
struct vm_mem_region {
2223
paddr_t base;
@@ -47,6 +48,9 @@ struct vm_platform {
4748
size_t dev_num;
4849
struct vm_dev_region* devs;
4950

51+
size_t remote_io_dev_num;
52+
struct remote_io_dev* remote_io_devs;
53+
5054
// /**
5155
// * In MPU-based platforms which might also support virtual memory
5256
// * (i.e. aarch64 cortex-r) the hypervisor sets up the VM using an MPU by
@@ -84,6 +88,9 @@ struct vm {
8488

8589
size_t ipc_num;
8690
struct ipc* ipcs;
91+
92+
size_t remote_io_dev_num;
93+
struct remote_io_dev* remote_io_devs;
8794
};
8895

8996
struct vcpu {

src/core/objects.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ core-objs-y+=ipc.o
1414
core-objs-y+=objpool.o
1515
core-objs-y+=hypercall.o
1616
core-objs-y+=shmem.o
17+
core-objs-y+=remote_io.o

0 commit comments

Comments
 (0)