Skip to content

Commit 99fe2a9

Browse files
committed
ref(core/remio): replace Remote I/O ID by a bind key
Since the unique identifier is solely used to connect the Remote I/O device frontend with its corresponding backend, a named link bind key is more appropriate than an ID for this purpose. Signed-off-by: João Peixoto <[email protected]>
1 parent efef183 commit 99fe2a9

File tree

4 files changed

+50
-51
lines changed

4 files changed

+50
-51
lines changed

src/core/inc/remio.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ enum REMIO_DEV_TYPE {
4141
* @note The device can be either a frontend (driver) or a backend (device)
4242
*/
4343
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_id_t id; /**< Remote I/O ID */
48-
enum REMIO_DEV_TYPE type; /**< Type of the Remote I/O device */
49-
struct remio_shmem shmem; /**< Shared memory region */
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 */
5050
};
5151

5252
/**

src/core/inc/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ typedef unsigned irqid_t;
4848

4949
typedef unsigned deviceid_t;
5050

51-
typedef size_t remio_id_t;
51+
typedef size_t remio_bind_key_t;
5252

5353
typedef size_t objpool_id_t;
5454

src/core/remio.c

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ enum REMIO_STATE {
6262
*/
6363
union remio_cpu_msg_data {
6464
struct {
65-
uint8_t remio_id; /**< Remote I/O ID */
66-
uint8_t request_id; /**< Remote I/O request ID */
67-
uint8_t interrupt; /**< Interrupt ID */
65+
uint8_t remio_bind_key; /**< Remote I/O bind key */
66+
uint8_t request_id; /**< Remote I/O request ID */
67+
uint8_t interrupt; /**< Interrupt ID */
6868
};
69-
uint64_t raw; /**< Raw data */
69+
uint64_t raw; /**< Raw data */
7070
};
7171

7272
/**
@@ -118,7 +118,7 @@ struct remio_device_config {
118118
*/
119119
struct remio_device {
120120
node_t node; /**< Node */
121-
remio_id_t id; /**< Remote I/O device ID */
121+
remio_bind_key_t bind_key; /**< Remote I/O bind key */
122122
struct remio_device_config config; /**< Remote I/O device configuration */
123123
struct list request_event_list; /**< List of pending I/O requests events */
124124
struct remio_request requests[REMIO_VCPU_NUM]; /**< Array of Remote I/O requests */
@@ -280,15 +280,15 @@ static inline size_t remio_get_request_event_count(struct remio_device* device)
280280
}
281281

282282
/**
283-
* @brief Finds the Remote I/O device based on the Remote I/O device ID
284-
* @param id Remote I/O device ID
283+
* @brief Finds the Remote I/O device based on the Remote I/O bind key
284+
* @param bind_key Remote I/O bind key
285285
* @return Returns the Remote I/O device or NULL if the device was not found
286286
*/
287-
static struct remio_device* remio_find_dev_by_id(remio_id_t id)
287+
static struct remio_device* remio_find_dev_by_bind_key(remio_bind_key_t bind_key)
288288
{
289289
struct remio_device* device = NULL;
290290
list_foreach (remio_device_list, struct remio_device, dev) {
291-
if (id == dev->id) {
291+
if (bind_key == dev->bind_key) {
292292
device = dev;
293293
break;
294294
}
@@ -297,21 +297,21 @@ static struct remio_device* remio_find_dev_by_id(remio_id_t id)
297297
}
298298

299299
/**
300-
* @brief Finds the Remote I/O device associated with a VM based on the Remote I/O device ID
300+
* @brief Finds the Remote I/O device associated with a VM based on the Remote I/O bind key
301301
* @param vm Pointer to the VM structure
302-
* @param id Remote I/O device ID
302+
* @param bind_key Remote I/O bind key
303303
* @return Returns the Remote I/O device or NULL if the device was not found
304304
*/
305-
static struct remio_device* remio_find_vm_dev_by_id(struct vm* vm, unsigned long id)
305+
static struct remio_device* remio_find_vm_dev_by_bind_key(struct vm* vm, unsigned long bind_key)
306306
{
307307
struct remio_dev* dev = NULL;
308308
struct remio_device* device = NULL;
309309

310-
/** Find the Remote I/O device VM configuration based on the Remote I/O device ID */
310+
/** Find the Remote I/O device VM configuration based on the Remote I/O bind key */
311311
struct vm_config* vm_config = &config.vmlist[vm->id];
312312
for (size_t i = 0; i < vm_config->platform.remio_dev_num; i++) {
313313
dev = &vm_config->platform.remio_devs[i];
314-
if (dev->id == id) {
314+
if (dev->bind_key == bind_key) {
315315
break;
316316
}
317317
}
@@ -320,8 +320,8 @@ static struct remio_device* remio_find_vm_dev_by_id(struct vm* vm, unsigned long
320320
return NULL;
321321
}
322322

323-
/** Find the Remote I/O device based on the Remote I/O device ID */
324-
device = remio_find_dev_by_id(id);
323+
/** Find the Remote I/O device based on the Remote I/O bind key */
324+
device = remio_find_dev_by_bind_key(bind_key);
325325
if (device == NULL) {
326326
return NULL;
327327
}
@@ -360,22 +360,22 @@ static struct remio_device* remio_find_vm_dev_by_addr(struct vm* vm, unsigned lo
360360
return NULL;
361361
}
362362

363-
return remio_find_vm_dev_by_id(vm, dev->id);
363+
return remio_find_vm_dev_by_bind_key(vm, dev->bind_key);
364364
}
365365

366366
/**
367367
* @brief Sends a Remote I/O CPU message to the target CPU
368368
* @param event Message event (REMIO_CPU_MSG_*)
369369
* @param target_cpu Target CPU ID
370-
* @param remio_id Remote I/O device ID
370+
* @param remio_bind_key Remote I/O bind key
371371
* @param request_id Remote I/O request ID
372372
* @param interrupt Interrupt ID
373373
*/
374374
static void remio_cpu_send_msg(enum REMIO_CPU_MSG_EVENT event, unsigned long target_cpu,
375-
unsigned long remio_id, unsigned long request_id, unsigned long interrupt)
375+
unsigned long remio_bind_key, unsigned long request_id, unsigned long interrupt)
376376
{
377377
union remio_cpu_msg_data data = {
378-
.remio_id = (uint8_t)remio_id,
378+
.remio_bind_key = (uint8_t)remio_bind_key,
379379
.request_id = (uint8_t)request_id,
380380
.interrupt = (uint8_t)interrupt,
381381
};
@@ -410,26 +410,26 @@ void remio_init(void)
410410
struct vm_config* vm_config = &config.vmlist[vm_id];
411411
for (size_t i = 0; i < vm_config->platform.remio_dev_num; i++) {
412412
struct remio_dev* dev = &vm_config->platform.remio_devs[i];
413-
if (devices[dev->id][dev->type] != REMIO_DEVICE_UNINITIALIZED) {
413+
if (devices[dev->bind_key][dev->type] != REMIO_DEVICE_UNINITIALIZED) {
414414
ERROR("Failed to link backend to the frontend, more than one %s was "
415415
"atributed to the Remote I/O device %d",
416-
dev->type == REMIO_DEV_BACKEND ? "backend" : "frontend", dev->id);
416+
dev->type == REMIO_DEV_BACKEND ? "backend" : "frontend", dev->bind_key);
417417
}
418418
if (dev->type == REMIO_DEV_BACKEND) {
419419
struct remio_device* device = objpool_alloc(&remio_device_pool);
420420
if (device == NULL) {
421421
ERROR("Failed allocating Remote I/O device node");
422422
}
423-
device->id = dev->id;
423+
device->bind_key = dev->bind_key;
424424
list_init(&device->request_event_list);
425425
list_push(&remio_device_list, (node_t*)device);
426426
backend_cnt++;
427-
devices[dev->id][REMIO_DEV_BACKEND] = (int)vm_id;
428-
shmem[dev->id][REMIO_DEV_BACKEND] = dev->shmem;
427+
devices[dev->bind_key][REMIO_DEV_BACKEND] = (int)vm_id;
428+
shmem[dev->bind_key][REMIO_DEV_BACKEND] = dev->shmem;
429429
} else if (dev->type == REMIO_DEV_FRONTEND) {
430430
frontend_cnt++;
431-
devices[dev->id][REMIO_DEV_FRONTEND] = (int)vm_id;
432-
shmem[dev->id][REMIO_DEV_FRONTEND] = dev->shmem;
431+
devices[dev->bind_key][REMIO_DEV_FRONTEND] = (int)vm_id;
432+
shmem[dev->bind_key][REMIO_DEV_FRONTEND] = dev->shmem;
433433
} else {
434434
ERROR("Unknown Remote I/O device type");
435435
}
@@ -460,9 +460,9 @@ void remio_init(void)
460460
struct vm_config* vm_config = &config.vmlist[vm_id];
461461
for (size_t i = 0; i < vm_config->platform.remio_dev_num; i++) {
462462
struct remio_dev* dev = &vm_config->platform.remio_devs[i];
463-
struct remio_device* device = remio_find_dev_by_id(dev->id);
463+
struct remio_device* device = remio_find_dev_by_bind_key(dev->bind_key);
464464
if (device == NULL) {
465-
ERROR("Failed to find Remote I/O device %d", dev->id);
465+
ERROR("Failed to find Remote I/O device %d", dev->bind_key);
466466
}
467467
if (dev->type == REMIO_DEV_BACKEND) {
468468
device->config.backend.vm_id = vm_id;
@@ -565,13 +565,13 @@ static bool remio_handle_rw(unsigned long value, unsigned long request_id,
565565
* @note This function is executed by the frontend VM and is responsible for updating the
566566
* vCPU register in case of a read operation and activating the frontend vCPU
567567
* @param event Message event (REMIO_CPU_MSG_*)
568-
* @param remio_id Remote I/O device ID
568+
* @param remio_bind_key Remote I/O bind key
569569
* @param request_id Remote I/O request ID
570570
* @return Returns true if the operation was successful, false otherwise
571571
*/
572-
static bool remio_cpu_post_work(uint32_t event, uint8_t remio_id, uint8_t request_id)
572+
static bool remio_cpu_post_work(uint32_t event, uint8_t remio_bind_key, uint8_t request_id)
573573
{
574-
struct remio_device* device = remio_find_dev_by_id(remio_id);
574+
struct remio_device* device = remio_find_dev_by_bind_key(remio_bind_key);
575575

576576
if (remio_get_request_state(device, request_id) != REMIO_STATE_COMPLETE) {
577577
return false;
@@ -602,30 +602,29 @@ static bool remio_cpu_post_work(uint32_t event, uint8_t remio_id, uint8_t reques
602602
long int remio_hypercall(unsigned long arg0, unsigned long arg1, unsigned long arg2)
603603
{
604604
long int ret = -HC_E_SUCCESS;
605-
unsigned long virt_remio_dev_id = arg0;
605+
unsigned long dm_id = arg0;
606606
unsigned long addr = arg1;
607607
unsigned long op = arg2;
608608
unsigned long value = vcpu_readreg(cpu()->vcpu, HYPCALL_IN_ARG_REG(3));
609609
unsigned long request_id = vcpu_readreg(cpu()->vcpu, HYPCALL_IN_ARG_REG(4));
610610
struct remio_device* device = NULL;
611611
struct vm* vm = cpu()->vcpu->vm;
612612

613-
/** Check if the virtual Remote I/O device ID is within the valid range */
614-
if (virt_remio_dev_id >= config.vmlist[vm->id].platform.remio_dev_num) {
615-
ERROR("Remote I/O ID (%d) exceeds the valid range for backend VM (%d)", virt_remio_dev_id,
616-
vm->id);
613+
/** Check if the device model ID is within the valid range */
614+
if (dm_id >= config.vmlist[vm->id].platform.remio_dev_num) {
615+
ERROR("Device model ID (%d) exceeds the valid range for backend VM (%d)", dm_id, vm->id);
617616
return -HC_E_FAILURE;
618617
}
619618

620-
/** Get the Remote I/O device ID based on the virtual Remote I/O device ID */
621-
unsigned long remio_dev_id = config.vmlist[vm->id].platform.remio_devs[virt_remio_dev_id].id;
619+
/** Get the Remote I/O bind key based on the device model ID */
620+
unsigned long remio_dev_bind_key = config.vmlist[vm->id].platform.remio_devs[dm_id].bind_key;
622621

623622
/** Find the Remote I/O device associated with the current backend VM */
624-
device = remio_find_vm_dev_by_id(vm, remio_dev_id);
623+
device = remio_find_vm_dev_by_bind_key(vm, remio_dev_bind_key);
625624
if (device == NULL) {
626625
ERROR("The Remote I/O backend device (%d) is not associated with the current backend VM "
627626
"(%d)",
628-
virt_remio_dev_id, vm->id);
627+
dm_id, vm->id);
629628
return -HC_E_FAILURE;
630629
}
631630

@@ -637,7 +636,7 @@ long int remio_hypercall(unsigned long arg0, unsigned long arg1, unsigned long a
637636
} else {
638637
/** Send a CPU message to the backend VM to execute the post work */
639638
remio_cpu_send_msg(op == REMIO_HYP_WRITE ? REMIO_CPU_MSG_WRITE : REMIO_CPU_MSG_READ,
640-
device->requests[request_id].cpu_id, remio_dev_id, request_id, 0);
639+
device->requests[request_id].cpu_id, remio_dev_bind_key, request_id, 0);
641640
}
642641
break;
643642
case REMIO_HYP_ASK:
@@ -695,7 +694,7 @@ static void remio_cpu_handler(uint32_t event, uint64_t data)
695694
switch (event) {
696695
case REMIO_CPU_MSG_WRITE:
697696
case REMIO_CPU_MSG_READ:
698-
if (!remio_cpu_post_work(event, msg.remio_id, msg.request_id)) {
697+
if (!remio_cpu_post_work(event, msg.remio_bind_key, msg.request_id)) {
699698
ERROR("Failed to perform the post work after the completion of the I/O request");
700699
}
701700
break;

src/core/vm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static void vm_init_remio_dev(struct vm* vm, struct remio_dev* remio_dev)
233233
struct shmem* shmem = shmem_get(remio_dev->shmem.shmem_id);
234234
if (shmem == NULL) {
235235
ERROR("Invalid shmem id (%d) in the Remote I/O device (%d) configuration",
236-
remio_dev->shmem.shmem_id, remio_dev->id);
236+
remio_dev->shmem.shmem_id, remio_dev->bind_key);
237237
}
238238
size_t shmem_size = remio_dev->shmem.size;
239239
if (shmem_size > shmem->size) {

0 commit comments

Comments
 (0)