Skip to content

Commit d56ef75

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 f7bd8bc commit d56ef75

File tree

11 files changed

+897
-1
lines changed

11 files changed

+897
-1
lines changed

scripts/config_defs_gen.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@
66
#include <stdio.h>
77
#include <config.h>
88

9+
static size_t remio_dev_num(void)
10+
{
11+
size_t dev_num = 0;
12+
for (size_t vm_id = 0; vm_id < config.vmlist_size; vm_id++) {
13+
struct vm_config* vm_config = &config.vmlist[vm_id];
14+
for (size_t i = 0; i < vm_config->platform.remio_dev_num; i++) {
15+
struct remio_dev* dev = &vm_config->platform.remio_devs[i];
16+
if (dev->type == REMIO_DEV_BACKEND) {
17+
dev_num++;
18+
}
19+
}
20+
}
21+
return dev_num;
22+
}
23+
924
int main() {
1025
size_t vcpu_num = 0;
1126
for (size_t i = 0; i < config.vmlist_size; i++) {
@@ -21,5 +36,7 @@ int main() {
2136
printf("#define CONFIG_HYP_BASE_ADDR PLAT_BASE_ADDR\n");
2237
}
2338

39+
printf("#define CONFIG_REMIO_DEV_NUM %ld\n", remio_dev_num());
40+
2441
return 0;
2542
}

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_REMIO:
24+
ret = remio_hypercall(arg0, arg1, arg2);
25+
break;
2326
default:
2427
WARNING("Unknown hypercall id %d", id);
2528
}

src/core/inc/config_defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define CONFIG_VCPU_NUM 1
1212
#define CONFIG_VM_NUM 1
1313
#define CONFIG_HYP_BASE_ADDR 0
14+
#define CONFIG_REMIO_DEV_NUM 0
1415

1516
#else /* GENERATING_DEFS */
1617

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_REMIO = 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/remio.h

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

src/core/inc/types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ typedef unsigned deviceid_t;
5050

5151
typedef size_t objpool_id_t;
5252

53+
typedef size_t remio_bind_key_t;
54+
5355
typedef enum AS_SEC {
5456
/*--- HYP AS SECTIONS -----*/
5557
SEC_HYP_GLOBAL = 0,

src/core/inc/vm.h

Lines changed: 4 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 <remio.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 remio_dev_num;
52+
struct remio_dev* remio_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

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+=remio.o

0 commit comments

Comments
 (0)