diff --git a/src/core/hypercall.c b/src/core/hypercall.c index afc49280..920be369 100644 --- a/src/core/hypercall.c +++ b/src/core/hypercall.c @@ -20,8 +20,8 @@ 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); + case HC_REMIO: + ret = remio_hypercall(arg0, arg1, arg2); break; default: WARNING("Unknown hypercall id %d", id); diff --git a/src/core/inc/hypercall.h b/src/core/inc/hypercall.h index 58331301..d3962dde 100644 --- a/src/core/inc/hypercall.h +++ b/src/core/inc/hypercall.h @@ -9,7 +9,7 @@ #include #include -enum { HC_INVAL = 0, HC_IPC = 1, HC_REMOTE_IO = 2 }; +enum { HC_INVAL = 0, HC_IPC = 1, HC_REMIO = 2 }; enum { HC_E_SUCCESS = 0, HC_E_FAILURE = 1, HC_E_INVAL_ID = 2, HC_E_INVAL_ARGS = 3 }; diff --git a/src/core/inc/remio.h b/src/core/inc/remio.h index 5af84b55..3f253275 100644 --- a/src/core/inc/remio.h +++ b/src/core/inc/remio.h @@ -18,43 +18,43 @@ #include /** - * @struct remote_io_shmem + * @struct remio_shmem * @brief This structure represents a shared memory region used by a Remote I/O device */ -struct remote_io_shmem { +struct remio_shmem { paddr_t base; /**< Shared memory base address */ size_t size; /**< Shared memory size */ size_t shmem_id; /**< Shared memory ID */ }; /** - * @enum REMOTE_IO_DEV_TYPE + * @enum REMIO_DEV_TYPE * @brief This enum represents the Remote I/O device type */ -enum REMOTE_IO_DEV_TYPE { - REMOTE_IO_DEV_FRONTEND = 0, /**< Remote I/O frontend device */ - REMOTE_IO_DEV_BACKEND /**< Remote I/O backend device */ +enum REMIO_DEV_TYPE { + REMIO_DEV_FRONTEND = 0, /**< Remote I/O frontend device */ + REMIO_DEV_BACKEND /**< Remote I/O backend device */ }; /** - * @struct remote_io_dev + * @struct remio_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 */ - remote_io_id_t id; /**< Remote I/O ID */ - enum REMOTE_IO_DEV_TYPE type; /**< Type of the Remote I/O device */ - struct remote_io_shmem shmem; /**< Shared memory region */ +struct remio_dev { + vaddr_t va; /**< Frontend MMIO base virtual address */ + size_t size; /**< Frontend MMIO size */ + irqid_t interrupt; /**< Frontend/backend interrupt number */ + remio_id_t id; /**< Remote I/O ID */ + enum REMIO_DEV_TYPE type; /**< Type of the Remote I/O device */ + struct remio_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); +void remio_init(void); /** * @brief Remote I/O device VM CPU assignment routine @@ -64,7 +64,7 @@ void remote_io_init(void); * one with the lowest ID, since only one CPU is required to inject VM interrupts * @param vm Pointer to the VM structure */ -void remote_io_assign_vm_cpus(struct vm* vm); +void remio_assign_vm_cpus(struct vm* vm); /** * @brief Remote I/O hypercall callback @@ -74,7 +74,7 @@ void remote_io_assign_vm_cpus(struct vm* vm); * @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); +long int remio_hypercall(unsigned long arg0, unsigned long arg1, unsigned long arg2); /** * @brief Remote I/O MMIO emulation handler @@ -82,6 +82,6 @@ long int remote_io_hypercall(unsigned long arg0, unsigned long arg1, unsigned lo * @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); +bool remio_mmio_emul_handler(struct emul_access* emul_access); #endif /* __REMIO_H__ */ diff --git a/src/core/inc/types.h b/src/core/inc/types.h index f92547c2..e3a35085 100644 --- a/src/core/inc/types.h +++ b/src/core/inc/types.h @@ -47,7 +47,7 @@ typedef unsigned irqid_t; typedef unsigned deviceid_t; -typedef size_t remote_io_id_t; +typedef size_t remio_id_t; typedef enum AS_SEC { /*--- HYP AS SECTIONS -----*/ diff --git a/src/core/inc/vm.h b/src/core/inc/vm.h index 75cf5e51..e65e9532 100644 --- a/src/core/inc/vm.h +++ b/src/core/inc/vm.h @@ -48,8 +48,8 @@ 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; + size_t remio_dev_num; + struct remio_dev* remio_devs; // /** // * In MPU-based platforms which might also support virtual memory @@ -89,8 +89,8 @@ struct vm { size_t ipc_num; struct ipc* ipcs; - size_t remote_io_dev_num; - struct remote_io_dev* remote_io_devs; + size_t remio_dev_num; + struct remio_dev* remio_devs; }; struct vcpu { diff --git a/src/core/remio.c b/src/core/remio.c index 1a7246f7..5465c5ba 100644 --- a/src/core/remio.c +++ b/src/core/remio.c @@ -18,52 +18,52 @@ #include #include -#define REMOTE_IO_MAX_DEVICES 32 -#define REMOTE_IO_DEVICE_UNINITIALIZED -1 -#define REMOTE_IO_CPU_NUM PLAT_CPU_NUM -#define REMOTE_IO_VCPU_NUM PLAT_CPU_NUM -#define REMOTE_IO_NUM_DEV_TYPES (REMOTE_IO_DEV_BACKEND - REMOTE_IO_DEV_FRONTEND + 1) +#define REMIO_MAX_DEVICES 32 +#define REMIO_DEVICE_UNINITIALIZED -1 +#define REMIO_CPU_NUM PLAT_CPU_NUM +#define REMIO_VCPU_NUM PLAT_CPU_NUM +#define REMIO_NUM_DEV_TYPES (REMIO_DEV_BACKEND - REMIO_DEV_FRONTEND + 1) /** - * @enum REMOTE_IO_HYP_EVENT + * @enum REMIO_HYP_EVENT * @brief This enum represents the Remote I/O hypercall events * @note Used by the backend VM to specify the operation to be performed */ -enum REMOTE_IO_HYP_EVENT { - REMOTE_IO_HYP_WRITE, /**< Write operation */ - REMOTE_IO_HYP_READ, /**< Read operation */ - REMOTE_IO_HYP_ASK, /**< Ask operation (used to request a new pending I/O request) */ - REMOTE_IO_HYP_NOTIFY, /**< Notify operation (used buffer or configuration change) */ +enum REMIO_HYP_EVENT { + REMIO_HYP_WRITE, /**< Write operation */ + REMIO_HYP_READ, /**< Read operation */ + REMIO_HYP_ASK, /**< Ask operation (used to request a new pending I/O request) */ + REMIO_HYP_NOTIFY, /**< Notify operation (used buffer or configuration change) */ }; /** - * @enum REMOTE_IO_CPU_MSG_EVENT + * @enum REMIO_CPU_MSG_EVENT * @brief This enum represents the Remote I/O CPU message events */ -enum REMOTE_IO_CPU_MSG_EVENT { - REMOTE_IO_CPU_MSG_WRITE, /**< Write notification */ - REMOTE_IO_CPU_MSG_READ, /**< Read notification */ - REMOTE_IO_CPU_MSG_NOTIFY, /**< Notify notification (used to inject an interrupt into the +enum REMIO_CPU_MSG_EVENT { + REMIO_CPU_MSG_WRITE, /**< Write notification */ + REMIO_CPU_MSG_READ, /**< Read notification */ + REMIO_CPU_MSG_NOTIFY, /**< Notify notification (used to inject an interrupt into the frontend or backend VM) */ }; /** - * @enum REMOTE_IO_STATE + * @enum REMIO_STATE * @brief This enum represents the I/O request states */ -enum REMOTE_IO_STATE { - REMOTE_IO_STATE_FREE, /**< The I/O request slot is free */ - REMOTE_IO_STATE_PENDING, /**< The I/O request is pending to be processed by the backend VM */ - REMOTE_IO_STATE_PROCESSING, /**< The I/O request is being processed by the backend VM */ - REMOTE_IO_STATE_COMPLETE, /**< The I/O request was completed by the backend VM but not yet +enum REMIO_STATE { + REMIO_STATE_FREE, /**< The I/O request slot is free */ + REMIO_STATE_PENDING, /**< The I/O request is pending to be processed by the backend VM */ + REMIO_STATE_PROCESSING, /**< The I/O request is being processed by the backend VM */ + REMIO_STATE_COMPLETE, /**< The I/O request was completed by the backend VM but not yet completed on frontend VM's eyes */ }; /** - * @union remote_io_cpu_msg_data + * @union remio_cpu_msg_data * @brief This union represents the Remote I/O CPU message data */ -union remote_io_cpu_msg_data { +union remio_cpu_msg_data { struct { uint8_t id; /**< Remote I/O ID */ uint8_t cpu_id; /**< Frontend CPU ID */ @@ -74,36 +74,36 @@ union remote_io_cpu_msg_data { }; /** - * @struct remote_io_request + * @struct remio_request * @brief This structure contains the information of a Remote I/O request */ -struct remote_io_request { +struct remio_request { vaddr_t addr; /**< Address of the accessed MMIO Register */ unsigned long access_width; /**< Access width */ unsigned long op; /**< MMIO operation type (read or write) */ unsigned long value; /**< Value to be written or read */ unsigned long reg; /**< vCPU resgiter used during the MMIO access */ - enum REMOTE_IO_STATE state; /**< I/O request state */ + enum REMIO_STATE state; /**< I/O request state */ }; /** - * @struct remote_io_request_event + * @struct remio_request_event * @brief This structure contains the information of a Remote I/O request event * @note This is used to only advertise the backend VM that a new I/O request is available * and the backend VM can ask for it, avoiding the need to iterate over all the * CPUs and vCPUs slots to find the next I/O request to be processed */ -struct remote_io_request_event { +struct remio_request_event { node_t node; /** Node */ cpuid_t cpu_id; /** CPU ID of the frontend VM that issued the I/O request */ vcpuid_t vcpu_id; /** vCPU ID of the frontend VM that issued the I/O request */ }; /** - * @struct remote_io_device_config + * @struct remio_device_config * @brief This structure holds the static information regarding a Remote I/O device */ -struct remote_io_device_config { +struct remio_device_config { struct { cpuid_t cpu_id; /**< Backend VM CPU ID */ vmid_t vm_id; /**< Backend VM ID */ @@ -117,58 +117,58 @@ struct remote_io_device_config { }; /** - * @struct remote_io_device + * @struct remio_device * @brief This structure comprises all the information needed about a Remote I/O device */ -struct remote_io_device { - node_t node; /**< Node */ - remote_io_id_t id; /**< Remote I/O device ID */ - struct remote_io_device_config config; /**< Remote I/O device configuration */ - struct list request_event_list; /**< List of pending I/O requests events */ +struct remio_device { + node_t node; /**< Node */ + remio_id_t id; /**< Remote I/O device ID */ + struct remio_device_config config; /**< Remote I/O device configuration */ + struct list request_event_list; /**< List of pending I/O requests events */ }; /** List of Remote I/O devices */ -struct list remote_io_device_list; +struct list remio_device_list; /** Array of Remote I/O requests */ -struct remote_io_request remote_io_requests[REMOTE_IO_CPU_NUM][REMOTE_IO_VCPU_NUM]; +struct remio_request remio_requests[REMIO_CPU_NUM][REMIO_VCPU_NUM]; /** * @brief Remote I/O CPU message handler - * @param event Message event (REMOTE_IO_CPU_MSG_*) - * @param data Remote I/O CPU message data (remote_io_cpu_msg_data) + * @param event Message event (REMIO_CPU_MSG_*) + * @param data Remote I/O CPU message data (remio_cpu_msg_data) */ -static void remote_io_cpu_handler(uint32_t event, uint64_t data); +static void remio_cpu_handler(uint32_t event, uint64_t data); /** Associate the Remote I/O CPU message handler with a new Remote I/O CPU message ID */ -CPU_MSG_HANDLER(remote_io_cpu_handler, REMOTE_IO_CPUMSG_ID) +CPU_MSG_HANDLER(remio_cpu_handler, REMIO_CPUMSG_ID) /** Object pool to allocate Remote I/O devices */ -OBJPOOL_ALLOC(remote_io_device_pool, struct remote_io_device, sizeof(struct remote_io_device)); +OBJPOOL_ALLOC(remio_device_pool, struct remio_device, sizeof(struct remio_device)); /** Object pool to allocate pending Remote I/O requests events */ -OBJPOOL_ALLOC(remote_io_request_event_pool, struct remote_io_request_event, - sizeof(struct remote_io_request_event)); +OBJPOOL_ALLOC(remio_request_event_pool, struct remio_request_event, + sizeof(struct remio_request_event)); /** * @brief Creates a new Remote I/O request based on the MMIO access information * @param acc Pointer to the emul_access structure containing the MMIO access information * @return Returns the Remote I/O request */ -static struct remote_io_request remote_io_create_request(struct emul_access* acc) +static struct remio_request remio_create_request(struct emul_access* acc) { - struct remote_io_request request; + struct remio_request request; request.addr = acc->addr; request.reg = acc->reg; request.access_width = acc->width; - request.state = REMOTE_IO_STATE_PENDING; + request.state = REMIO_STATE_PENDING; if (acc->write) { long unsigned int value = vcpu_readreg(cpu()->vcpu, acc->reg); - request.op = REMOTE_IO_HYP_WRITE; + request.op = REMIO_HYP_WRITE; request.value = value; } else { - request.op = REMOTE_IO_HYP_READ; + request.op = REMIO_HYP_READ; request.value = 0; } @@ -181,9 +181,9 @@ static struct remote_io_request remote_io_create_request(struct emul_access* acc * @param vcpu_id vCPU ID of the frontend VM that issued the I/O request * @return Returns the Remote I/O request */ -static struct remote_io_request* remote_io_get_request(unsigned long cpu_id, unsigned long vcpu_id) +static struct remio_request* remio_get_request(unsigned long cpu_id, unsigned long vcpu_id) { - return &remote_io_requests[cpu_id][vcpu_id]; + return &remio_requests[cpu_id][vcpu_id]; } /** @@ -192,10 +192,10 @@ static struct remote_io_request* remote_io_get_request(unsigned long cpu_id, uns * @param vcpu_id vCPU ID of the frontend VM that issued the I/O request * @param request Pointer to the Remote I/O request */ -static void remote_io_insert_request(unsigned long cpu_id, unsigned long vcpu_id, - struct remote_io_request* request) +static void remio_insert_request(unsigned long cpu_id, unsigned long vcpu_id, + struct remio_request* request) { - remote_io_requests[cpu_id][vcpu_id] = *request; + remio_requests[cpu_id][vcpu_id] = *request; } /** @@ -204,10 +204,10 @@ static void remote_io_insert_request(unsigned long cpu_id, unsigned long vcpu_id * @param vcpu_id vCPU ID of the frontend VM that issued the I/O request * @param state New state of the I/O request */ -static void remote_io_set_request_state(unsigned long cpu_id, unsigned long vcpu_id, - enum REMOTE_IO_STATE state) +static void remio_set_request_state(unsigned long cpu_id, unsigned long vcpu_id, + enum REMIO_STATE state) { - struct remote_io_request* request = remote_io_get_request(cpu_id, vcpu_id); + struct remio_request* request = remio_get_request(cpu_id, vcpu_id); request->state = state; } @@ -217,9 +217,9 @@ static void remote_io_set_request_state(unsigned long cpu_id, unsigned long vcpu * @param vcpu_id vCPU ID of the frontend VM that issued the I/O request * @return Returns the state of the I/O request */ -static enum REMOTE_IO_STATE remote_io_get_request_state(unsigned long cpu_id, unsigned long vcpu_id) +static enum REMIO_STATE remio_get_request_state(unsigned long cpu_id, unsigned long vcpu_id) { - struct remote_io_request* request = remote_io_get_request(cpu_id, vcpu_id); + struct remio_request* request = remio_get_request(cpu_id, vcpu_id); return request->state; } @@ -229,10 +229,9 @@ static enum REMOTE_IO_STATE remote_io_get_request_state(unsigned long cpu_id, un * @param vcpu_id vCPU ID of the frontend VM that issued the I/O request * @param value New value of the I/O request */ -static void remote_io_set_request_value(unsigned long cpu_id, unsigned long vcpu_id, - unsigned long value) +static void remio_set_request_value(unsigned long cpu_id, unsigned long vcpu_id, unsigned long value) { - struct remote_io_request* request = remote_io_get_request(cpu_id, vcpu_id); + struct remio_request* request = remio_get_request(cpu_id, vcpu_id); request->value = value; } @@ -240,9 +239,9 @@ static void remote_io_set_request_value(unsigned long cpu_id, unsigned long vcpu * @brief Creates a new Remote I/O request event * @return Returns the Remote I/O request event or NULL if the allocation failed */ -static struct remote_io_request_event* remote_io_create_event(void) +static struct remio_request_event* remio_create_event(void) { - struct remote_io_request_event* event = objpool_alloc(&remote_io_request_event_pool); + struct remio_request_event* event = objpool_alloc(&remio_request_event_pool); if (event == NULL) { return NULL; } @@ -259,8 +258,7 @@ static struct remote_io_request_event* remote_io_create_event(void) * @param device Pointer to the Remote I/O device * @param event Pointer to the Remote I/O request event */ -static void remote_io_push_request_event(struct remote_io_device* device, - struct remote_io_request_event* event) +static void remio_push_request_event(struct remio_device* device, struct remio_request_event* event) { list_push(&device->request_event_list, (node_t*)event); } @@ -270,10 +268,10 @@ static void remote_io_push_request_event(struct remote_io_device* device, * @param device Pointer to the Remote I/O device * @return Returns the next pending I/O request event or NULL if there is no pending I/O request */ -static struct remote_io_request_event* remote_io_pop_request_event(struct remote_io_device* device) +static struct remio_request_event* remio_pop_request_event(struct remio_device* device) { - struct remote_io_request_event* event = - (struct remote_io_request_event*)list_pop(&device->request_event_list); + struct remio_request_event* event = + (struct remio_request_event*)list_pop(&device->request_event_list); return event; } @@ -282,53 +280,53 @@ static struct remote_io_request_event* remote_io_pop_request_event(struct remote * @param device Pointer to the Remote I/O device * @return Returns the number of pending I/O requests */ -static size_t remote_io_get_request_event_count(struct remote_io_device* device) +static size_t remio_get_request_event_count(struct remio_device* device) { return list_size(&device->request_event_list); } -void remote_io_init(void) +void remio_init(void) { size_t frontend_cnt = 0, backend_cnt = 0; - int devices[REMOTE_IO_MAX_DEVICES][REMOTE_IO_NUM_DEV_TYPES]; + int devices[REMIO_MAX_DEVICES][REMIO_NUM_DEV_TYPES]; /** Only execute the Remote I/O initialization routine on the master CPU */ if (!cpu_is_master()) { return; } - objpool_init(&remote_io_device_pool); - objpool_init(&remote_io_request_event_pool); - list_init(&remote_io_device_list); + objpool_init(&remio_device_pool); + objpool_init(&remio_request_event_pool); + list_init(&remio_device_list); - for (size_t i = 0; i < REMOTE_IO_MAX_DEVICES; i++) { - devices[i][REMOTE_IO_DEV_FRONTEND] = REMOTE_IO_DEVICE_UNINITIALIZED; - devices[i][REMOTE_IO_DEV_BACKEND] = REMOTE_IO_DEVICE_UNINITIALIZED; + for (size_t i = 0; i < REMIO_MAX_DEVICES; i++) { + devices[i][REMIO_DEV_FRONTEND] = REMIO_DEVICE_UNINITIALIZED; + devices[i][REMIO_DEV_BACKEND] = REMIO_DEVICE_UNINITIALIZED; } /** Create the Remote I/O devices based on the VM configuration */ for (size_t vm_id = 0; vm_id < config.vmlist_size; vm_id++) { struct vm_config* vm_config = &config.vmlist[vm_id]; - for (size_t i = 0; i < vm_config->platform.remote_io_dev_num; i++) { - struct remote_io_dev* dev = &vm_config->platform.remote_io_devs[i]; - if (devices[dev->id][dev->type] != REMOTE_IO_DEVICE_UNINITIALIZED) { + for (size_t i = 0; i < vm_config->platform.remio_dev_num; i++) { + struct remio_dev* dev = &vm_config->platform.remio_devs[i]; + if (devices[dev->id][dev->type] != REMIO_DEVICE_UNINITIALIZED) { ERROR("Failed to link backend to the frontend, more than one %s was " "atributed to the Remote I/O device %d", - dev->type == REMOTE_IO_DEV_BACKEND ? "backend" : "frontend", dev->id); + dev->type == REMIO_DEV_BACKEND ? "backend" : "frontend", dev->id); } - if (dev->type == REMOTE_IO_DEV_BACKEND) { - struct remote_io_device* device = objpool_alloc(&remote_io_device_pool); + if (dev->type == REMIO_DEV_BACKEND) { + struct remio_device* device = objpool_alloc(&remio_device_pool); if (device == NULL) { ERROR("Failed allocating Remote I/O device node"); } device->id = dev->id; list_init(&device->request_event_list); - list_push(&remote_io_device_list, (node_t*)device); + list_push(&remio_device_list, (node_t*)device); backend_cnt++; - devices[dev->id][REMOTE_IO_DEV_BACKEND] = (int)vm_id; + devices[dev->id][REMIO_DEV_BACKEND] = (int)vm_id; } else { frontend_cnt++; - devices[dev->id][REMOTE_IO_DEV_FRONTEND] = (int)vm_id; + devices[dev->id][REMIO_DEV_FRONTEND] = (int)vm_id; } } } @@ -341,11 +339,11 @@ void remote_io_init(void) /** Update the Remote I/O device configuration */ for (size_t vm_id = 0; vm_id < config.vmlist_size; vm_id++) { struct vm_config* vm_config = &config.vmlist[vm_id]; - for (size_t i = 0; i < vm_config->platform.remote_io_dev_num; i++) { - struct remote_io_dev* dev = &vm_config->platform.remote_io_devs[i]; - list_foreach (remote_io_device_list, struct remote_io_device, device) { + for (size_t i = 0; i < vm_config->platform.remio_dev_num; i++) { + struct remio_dev* dev = &vm_config->platform.remio_devs[i]; + list_foreach (remio_device_list, struct remio_device, device) { if (dev->id == device->id) { - if (dev->type == REMOTE_IO_DEV_BACKEND) { + if (dev->type == REMIO_DEV_BACKEND) { device->config.backend.vm_id = vm_id; device->config.backend.interrupt = dev->interrupt; device->config.backend.cpu_id = (cpuid_t)-1; @@ -360,16 +358,16 @@ void remote_io_init(void) } /** Initialize the Remote I/O requests array */ - for (size_t cpu_idx = 0; cpu_idx < REMOTE_IO_CPU_NUM; cpu_idx++) { - for (size_t vcpu_idx = 0; vcpu_idx < REMOTE_IO_VCPU_NUM; vcpu_idx++) { - remote_io_set_request_state(cpu_idx, vcpu_idx, REMOTE_IO_STATE_FREE); + for (size_t cpu_idx = 0; cpu_idx < REMIO_CPU_NUM; cpu_idx++) { + for (size_t vcpu_idx = 0; vcpu_idx < REMIO_VCPU_NUM; vcpu_idx++) { + remio_set_request_state(cpu_idx, vcpu_idx, REMIO_STATE_FREE); } } } -void remote_io_assign_vm_cpus(struct vm* vm) +void remio_assign_vm_cpus(struct vm* vm) { - list_foreach (remote_io_device_list, struct remote_io_device, io_device) { + list_foreach (remio_device_list, struct remio_device, io_device) { if (vm->id == io_device->config.backend.vm_id) { io_device->config.backend.cpu_id = min(io_device->config.backend.cpu_id, cpu()->id); } else if (vm->id == io_device->config.frontend.vm_id) { @@ -384,14 +382,14 @@ void remote_io_assign_vm_cpus(struct vm* vm) * @param id Remote I/O device ID * @return Returns the Remote I/O device or NULL if the device was not found */ -static struct remote_io_device* remote_io_find_vm_io_dev_by_id(struct vm* vm, unsigned long id) +static struct remio_device* remio_find_vm_io_dev_by_id(struct vm* vm, unsigned long id) { - struct remote_io_dev* dev = NULL; - struct remote_io_device* device = NULL; + struct remio_dev* dev = NULL; + struct remio_device* device = NULL; /** Find the Remote I/O device VM configuration based on the Remote I/O device ID */ - for (size_t i = 0; i < vm->remote_io_dev_num; i++) { - dev = &vm->remote_io_devs[i]; + for (size_t i = 0; i < vm->remio_dev_num; i++) { + dev = &vm->remio_devs[i]; if (dev->id == id) { break; } @@ -402,12 +400,12 @@ static struct remote_io_device* remote_io_find_vm_io_dev_by_id(struct vm* vm, un } /** Find the Remote I/O device based on the Remote I/O device ID */ - list_foreach (remote_io_device_list, struct remote_io_device, io_device) { + list_foreach (remio_device_list, struct remio_device, io_device) { if (id == io_device->id) { - if (dev->type == REMOTE_IO_DEV_BACKEND && vm->id == io_device->config.backend.vm_id) { + if (dev->type == REMIO_DEV_BACKEND && vm->id == io_device->config.backend.vm_id) { device = io_device; break; - } else if (dev->type == REMOTE_IO_DEV_FRONTEND && + } else if (dev->type == REMIO_DEV_FRONTEND && vm->id == io_device->config.frontend.vm_id) { device = io_device; break; @@ -425,12 +423,12 @@ static struct remote_io_device* remote_io_find_vm_io_dev_by_id(struct vm* vm, un * @param addr MMIO access address * @return Returns the Remote I/O device or NULL if the device was not found */ -static struct remote_io_device* remote_io_find_vm_io_dev_by_addr(struct vm* vm, unsigned long addr) +static struct remio_device* remio_find_vm_io_dev_by_addr(struct vm* vm, unsigned long addr) { - struct remote_io_dev* dev = NULL; + struct remio_dev* dev = NULL; - for (size_t i = 0; i < vm->remote_io_dev_num; i++) { - dev = &vm->remote_io_devs[i]; + for (size_t i = 0; i < vm->remio_dev_num; i++) { + dev = &vm->remio_devs[i]; if (in_range(addr, dev->va, dev->size)) { break; } @@ -440,28 +438,28 @@ static struct remote_io_device* remote_io_find_vm_io_dev_by_addr(struct vm* vm, return NULL; } - return remote_io_find_vm_io_dev_by_id(vm, dev->id); + return remio_find_vm_io_dev_by_id(vm, dev->id); } /** * @brief Sends a Remote I/O CPU message to the target CPU - * @param event Message event (REMOTE_IO_CPU_MSG_*) + * @param event Message event (REMIO_CPU_MSG_*) * @param target_cpu Target CPU ID * @param id Remote I/O device ID * @param cpu_id CPU ID of the frontend VM that issued the I/O request * @param vcpu_id vCPU ID of the frontend VM that issued the I/O request * @param interrupt Interrupt ID */ -static void remote_io_cpu_send_msg(enum REMOTE_IO_CPU_MSG_EVENT event, unsigned long target_cpu, +static void remio_cpu_send_msg(enum REMIO_CPU_MSG_EVENT event, unsigned long target_cpu, unsigned long id, unsigned long cpu_id, unsigned long long vcpu_id, unsigned long interrupt) { - union remote_io_cpu_msg_data data = { + union remio_cpu_msg_data data = { .id = (uint8_t)id, .cpu_id = (uint8_t)cpu_id, .vcpu_id = (uint8_t)vcpu_id, .interrupt = (uint8_t)interrupt, }; - struct cpu_msg msg = { (uint32_t)REMOTE_IO_CPUMSG_ID, event, data.raw }; + struct cpu_msg msg = { (uint32_t)REMIO_CPUMSG_ID, event, data.raw }; cpu_send_msg(target_cpu, &msg); } @@ -472,8 +470,8 @@ static void remote_io_cpu_send_msg(enum REMOTE_IO_CPU_MSG_EVENT event, unsigned * @param device Pointer to the Remote I/O device * @return Returns the number of pending I/O requests */ -static long int remote_io_handle_ask(unsigned long addr, unsigned long value, - struct remote_io_device* device) +static long int remio_handle_ask(unsigned long addr, unsigned long value, + struct remio_device* device) { long int ret = -HC_E_FAILURE; @@ -482,22 +480,22 @@ static long int remote_io_handle_ask(unsigned long addr, unsigned long value, return ret; } - struct remote_io_request_event* event = remote_io_pop_request_event(device); + struct remio_request_event* event = remio_pop_request_event(device); if (event == NULL) { return ret; } - if (remote_io_get_request_state(event->cpu_id, event->vcpu_id) != REMOTE_IO_STATE_PENDING) { - objpool_free(&remote_io_request_event_pool, event); + if (remio_get_request_state(event->cpu_id, event->vcpu_id) != REMIO_STATE_PENDING) { + objpool_free(&remio_request_event_pool, event); return ret; } /** Calculate the remaining number of pending I/O requests */ - ret = (long int)remote_io_get_request_event_count(device); + ret = (long int)remio_get_request_event_count(device); - remote_io_set_request_state(event->cpu_id, event->vcpu_id, REMOTE_IO_STATE_PROCESSING); + remio_set_request_state(event->cpu_id, event->vcpu_id, REMIO_STATE_PROCESSING); - struct remote_io_request* request = remote_io_get_request(event->cpu_id, event->vcpu_id); + struct remio_request* request = remio_get_request(event->cpu_id, event->vcpu_id); /** Write the I/O request information to the backend VM's vCPU registers */ vcpu_writereg(cpu()->vcpu, HYPCALL_OUT_ARG_REG(0), request->addr); @@ -507,7 +505,7 @@ static long int remote_io_handle_ask(unsigned long addr, unsigned long value, vcpu_writereg(cpu()->vcpu, HYPCALL_OUT_ARG_REG(4), event->cpu_id); vcpu_writereg(cpu()->vcpu, HYPCALL_OUT_ARG_REG(5), event->vcpu_id); - objpool_free(&remote_io_request_event_pool, event); + objpool_free(&remio_request_event_pool, event); return ret; } @@ -519,13 +517,13 @@ static long int remote_io_handle_ask(unsigned long addr, unsigned long value, * @param vcpu_id vCPU ID of the frontend VM that issued the I/O request * @return Returns true if the operation was successful, false otherwise */ -static bool remote_io_handle_rw(unsigned long value, unsigned long cpu_id, unsigned long vcpu_id) +static bool remio_handle_rw(unsigned long value, unsigned long cpu_id, unsigned long vcpu_id) { - if (remote_io_get_request_state(cpu_id, vcpu_id) != REMOTE_IO_STATE_PROCESSING) { + if (remio_get_request_state(cpu_id, vcpu_id) != REMIO_STATE_PROCESSING) { return false; } - remote_io_set_request_value(cpu_id, vcpu_id, value); - remote_io_set_request_state(cpu_id, vcpu_id, REMOTE_IO_STATE_COMPLETE); + remio_set_request_value(cpu_id, vcpu_id, value); + remio_set_request_state(cpu_id, vcpu_id, REMIO_STATE_COMPLETE); return true; } @@ -533,83 +531,82 @@ static bool remote_io_handle_rw(unsigned long value, unsigned long cpu_id, unsig * @brief Performs the post work after the completion of the I/O request * @note This function is executed by the frontend VM and is responsible for updating the * vCPU register in case of a read operation and activating the frontend vCPU - * @param event Message event (REMOTE_IO_CPU_MSG_*) + * @param event Message event (REMIO_CPU_MSG_*) * @param cpu_id CPU ID of the frontend VM that issued the I/O request * @param vcpu_id vCPU ID of the frontend VM that issued the I/O request * @return Returns true if the operation was successful, false otherwise */ -static bool remote_io_cpu_post_work(uint32_t event, uint8_t cpu_id, uint8_t vcpu_id) +static bool remio_cpu_post_work(uint32_t event, uint8_t cpu_id, uint8_t vcpu_id) { - if (remote_io_get_request_state(cpu_id, vcpu_id) != REMOTE_IO_STATE_COMPLETE) { + if (remio_get_request_state(cpu_id, vcpu_id) != REMIO_STATE_COMPLETE) { return false; } - struct remote_io_request* request = remote_io_get_request(cpu_id, vcpu_id); + struct remio_request* request = remio_get_request(cpu_id, vcpu_id); switch (event) { - case REMOTE_IO_CPU_MSG_READ: + case REMIO_CPU_MSG_READ: vcpu_writereg(cpu()->vcpu, request->reg, request->value); break; default: break; } - remote_io_set_request_state(cpu_id, vcpu_id, REMOTE_IO_STATE_FREE); + remio_set_request_state(cpu_id, vcpu_id, REMIO_STATE_FREE); cpu()->vcpu->active = true; return true; } -long int remote_io_hypercall(unsigned long arg0, unsigned long arg1, unsigned long arg2) +long int remio_hypercall(unsigned long arg0, unsigned long arg1, unsigned long arg2) { long int ret = -HC_E_SUCCESS; - unsigned long virt_remote_io_dev_id = arg0; + unsigned long virt_remio_dev_id = arg0; unsigned long addr = arg1; unsigned long op = arg2; unsigned long value = vcpu_readreg(cpu()->vcpu, HYPCALL_IN_ARG_REG(3)); unsigned long cpu_id = vcpu_readreg(cpu()->vcpu, HYPCALL_IN_ARG_REG(4)); unsigned long vcpu_id = vcpu_readreg(cpu()->vcpu, HYPCALL_IN_ARG_REG(5)); - struct remote_io_device* device = NULL; + struct remio_device* device = NULL; struct vm* vm = cpu()->vcpu->vm; /** Check if the virtual Remote I/O device ID is within the valid range */ - if (virt_remote_io_dev_id >= vm->remote_io_dev_num) { - ERROR("Remote I/O ID (%d) exceeds the valid range for backend VM (%d)", - virt_remote_io_dev_id, vm->id); + if (virt_remio_dev_id >= vm->remio_dev_num) { + ERROR("Remote I/O ID (%d) exceeds the valid range for backend VM (%d)", virt_remio_dev_id, + vm->id); return -HC_E_FAILURE; } /** Get the absolute Remote I/O device ID based on the virtual Remote I/O device ID */ - unsigned long abs_remote_io_dev_id = vm->remote_io_devs[virt_remote_io_dev_id].id; + unsigned long abs_remio_dev_id = vm->remio_devs[virt_remio_dev_id].id; /** Find the Remote I/O device associated with the current backend VM */ - device = remote_io_find_vm_io_dev_by_id(vm, abs_remote_io_dev_id); + device = remio_find_vm_io_dev_by_id(vm, abs_remio_dev_id); if (device == NULL) { ERROR("The Remote I/O backend device (%d) is not associated with the current backend VM " "(%d)", - virt_remote_io_dev_id, vm->id); + virt_remio_dev_id, vm->id); return -HC_E_FAILURE; } switch (op) { - case REMOTE_IO_HYP_WRITE: - case REMOTE_IO_HYP_READ: - if (!remote_io_handle_rw(value, cpu_id, vcpu_id)) { + case REMIO_HYP_WRITE: + case REMIO_HYP_READ: + if (!remio_handle_rw(value, cpu_id, vcpu_id)) { ret = -HC_E_FAILURE; } else { /** Send a CPU message to the backend VM to execute the post work */ - remote_io_cpu_send_msg(op == REMOTE_IO_HYP_WRITE ? REMOTE_IO_CPU_MSG_WRITE : - REMOTE_IO_CPU_MSG_READ, - cpu_id, abs_remote_io_dev_id, cpu_id, vcpu_id, 0); + remio_cpu_send_msg(op == REMIO_HYP_WRITE ? REMIO_CPU_MSG_WRITE : REMIO_CPU_MSG_READ, + cpu_id, abs_remio_dev_id, cpu_id, vcpu_id, 0); } break; - case REMOTE_IO_HYP_ASK: - ret = remote_io_handle_ask(addr, value, device); + case REMIO_HYP_ASK: + ret = remio_handle_ask(addr, value, device); break; - case REMOTE_IO_HYP_NOTIFY: + case REMIO_HYP_NOTIFY: /** Send a CPU message to the frontend VM to inject an interrupt */ - remote_io_cpu_send_msg(REMOTE_IO_CPU_MSG_NOTIFY, device->config.frontend.cpu_id, 0, 0, - 0, device->config.frontend.interrupt); + remio_cpu_send_msg(REMIO_CPU_MSG_NOTIFY, device->config.frontend.cpu_id, 0, 0, 0, + device->config.frontend.interrupt); break; default: ret = -HC_E_INVAL_ARGS; @@ -619,30 +616,30 @@ long int remote_io_hypercall(unsigned long arg0, unsigned long arg1, unsigned lo return ret; } -bool remote_io_mmio_emul_handler(struct emul_access* acc) +bool remio_mmio_emul_handler(struct emul_access* acc) { - struct remote_io_device* device = NULL; + struct remio_device* device = NULL; /** Find the Remote I/O device based on the MMIO access address */ - device = remote_io_find_vm_io_dev_by_addr(cpu()->vcpu->vm, acc->addr); + device = remio_find_vm_io_dev_by_addr(cpu()->vcpu->vm, acc->addr); if (device == NULL) { return false; } /** Create a new Remote I/O request based on the MMIO access information */ - struct remote_io_request request = remote_io_create_request(acc); + struct remio_request request = remio_create_request(acc); /** Create a new Remote I/O request event */ - struct remote_io_request_event* event = remote_io_create_event(); + struct remio_request_event* event = remio_create_event(); /** Insert the I/O request into the Remote I/O request array */ - remote_io_insert_request(event->cpu_id, event->vcpu_id, &request); + remio_insert_request(event->cpu_id, event->vcpu_id, &request); /** Push the I/O request event into the Remote I/O device list */ - remote_io_push_request_event(device, event); + remio_push_request_event(device, event); /** Send a CPU message to the backend VM to then inject an interrupt */ - remote_io_cpu_send_msg(REMOTE_IO_CPU_MSG_NOTIFY, device->config.backend.cpu_id, 0, 0, 0, + remio_cpu_send_msg(REMIO_CPU_MSG_NOTIFY, device->config.backend.cpu_id, 0, 0, 0, device->config.backend.interrupt); /** Pause the current vCPU to wait for the MMIO emulation to be completed */ @@ -651,17 +648,17 @@ bool remote_io_mmio_emul_handler(struct emul_access* acc) return true; } -static void remote_io_cpu_handler(uint32_t event, uint64_t data) +static void remio_cpu_handler(uint32_t event, uint64_t data) { - union remote_io_cpu_msg_data ipc_data = { .raw = data }; + union remio_cpu_msg_data ipc_data = { .raw = data }; switch (event) { - case REMOTE_IO_CPU_MSG_WRITE: - case REMOTE_IO_CPU_MSG_READ: - if (!remote_io_cpu_post_work(event, ipc_data.cpu_id, ipc_data.vcpu_id)) { + case REMIO_CPU_MSG_WRITE: + case REMIO_CPU_MSG_READ: + if (!remio_cpu_post_work(event, ipc_data.cpu_id, ipc_data.vcpu_id)) { ERROR("Failed to perform the post work after the completion of the I/O request"); } break; - case REMOTE_IO_CPU_MSG_NOTIFY: + case REMIO_CPU_MSG_NOTIFY: vcpu_inject_hw_irq(cpu()->vcpu, ipc_data.interrupt); break; default: diff --git a/src/core/vm.c b/src/core/vm.c index 7285d1e8..cff6d72b 100644 --- a/src/core/vm.c +++ b/src/core/vm.c @@ -228,23 +228,23 @@ static void vm_init_dev(struct vm* vm, const struct vm_config* vm_config) } } -static void vm_init_remote_io(struct vm* vm, const struct vm_config* vm_config) +static void vm_init_remio(struct vm* vm, const struct vm_config* vm_config) { - if (vm_config->platform.remote_io_dev_num == 0) { + if (vm_config->platform.remio_dev_num == 0) { return; } - vm->remote_io_dev_num = vm_config->platform.remote_io_dev_num; - vm->remote_io_devs = vm_config->platform.remote_io_devs; + vm->remio_dev_num = vm_config->platform.remio_dev_num; + vm->remio_devs = vm_config->platform.remio_devs; - for (size_t i = 0; i < vm_config->platform.remote_io_dev_num; i++) { - struct remote_io_dev* remote_io_dev = &vm_config->platform.remote_io_devs[i]; - struct shmem* shmem = shmem_get(remote_io_dev->shmem.shmem_id); + for (size_t i = 0; i < vm_config->platform.remio_dev_num; i++) { + struct remio_dev* remio_dev = &vm_config->platform.remio_devs[i]; + struct shmem* shmem = shmem_get(remio_dev->shmem.shmem_id); if (shmem == NULL) { WARNING("Invalid shmem id in configuration. Ignored."); continue; } - size_t shmem_size = remote_io_dev->shmem.size; + size_t shmem_size = remio_dev->shmem.size; if (shmem_size > shmem->size) { shmem_size = shmem->size; WARNING("Trying to map region to smaller shared memory. Truncated"); @@ -254,7 +254,7 @@ static void vm_init_remote_io(struct vm* vm, const struct vm_config* vm_config) spin_unlock(&shmem->lock); struct vm_mem_region reg = { - .base = remote_io_dev->shmem.base, + .base = remio_dev->shmem.base, .size = shmem_size, .place_phys = true, .phys = shmem->phys, @@ -263,18 +263,18 @@ static void vm_init_remote_io(struct vm* vm, const struct vm_config* vm_config) vm_map_mem_region(vm, ®); - if (remote_io_dev->type == REMOTE_IO_DEV_FRONTEND) { + if (remio_dev->type == REMIO_DEV_FRONTEND) { struct emul_mem* emu = objpool_alloc(&emul_cache); if (emu == NULL) { ERROR("Failed allocating emulation memory node"); } - emu->va_base = remote_io_dev->va; - emu->size = remote_io_dev->size; - emu->handler = remote_io_mmio_emul_handler; + emu->va_base = remio_dev->va; + emu->size = remio_dev->size; + emu->handler = remio_mmio_emul_handler; vm_emul_add_mem(vm, emu); } } - remote_io_assign_vm_cpus(vm); + remio_assign_vm_cpus(vm); } static struct vm* vm_allocation_init(struct vm_allocation* vm_alloc) @@ -323,7 +323,7 @@ struct vm* vm_init(struct vm_allocation* vm_alloc, const struct vm_config* vm_co vm_init_mem_regions(vm, vm_config); vm_init_dev(vm, vm_config); vm_init_ipc(vm, vm_config); - vm_init_remote_io(vm, vm_config); + vm_init_remio(vm, vm_config); } cpu_sync_and_clear_msgs(&vm->sync); diff --git a/src/core/vmm.c b/src/core/vmm.c index 2634c208..f3ddcc6c 100644 --- a/src/core/vmm.c +++ b/src/core/vmm.c @@ -128,7 +128,7 @@ void vmm_init() vmm_arch_init(); vmm_io_init(); shmem_init(); - remote_io_init(); + remio_init(); cpu_sync_barrier(&cpu_glb_sync);