|
| 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 "types.h" |
| 15 | +#include <bao.h> |
| 16 | +#include <emul.h> |
| 17 | +#include <list.h> |
| 18 | +#include <vm.h> |
| 19 | + |
| 20 | +/** |
| 21 | + * @struct remio_shmem |
| 22 | + * @brief This structure represents a shared memory region used by a Remote I/O device |
| 23 | + */ |
| 24 | +struct remio_shmem { |
| 25 | + paddr_t base; /**< Shared memory base address */ |
| 26 | + size_t size; /**< Shared memory size */ |
| 27 | + size_t shmem_id; /**< Shared memory ID */ |
| 28 | +}; |
| 29 | + |
| 30 | +/** |
| 31 | + * @enum REMIO_DEV_TYPE |
| 32 | + * @brief This enum represents the Remote I/O device type |
| 33 | + */ |
| 34 | +enum REMIO_DEV_TYPE { |
| 35 | + REMIO_DEV_FRONTEND = 0, /**< Remote I/O frontend device */ |
| 36 | + REMIO_DEV_BACKEND /**< Remote I/O backend device */ |
| 37 | +}; |
| 38 | + |
| 39 | +/** |
| 40 | + * @struct remio_dev |
| 41 | + * @brief This structure represents a Remote I/O device |
| 42 | + * @note The device can be either a frontend (driver) or a backend (device) |
| 43 | + */ |
| 44 | +struct remio_dev { |
| 45 | + vaddr_t va; /**< Frontend MMIO base virtual address */ |
| 46 | + size_t size; /**< Frontend MMIO size */ |
| 47 | + irqid_t interrupt; /**< Frontend/backend interrupt number */ |
| 48 | + remio_id_t id; /**< Remote I/O ID */ |
| 49 | + enum REMIO_DEV_TYPE type; /**< Type of the Remote I/O device */ |
| 50 | + struct remio_shmem shmem; /**< Shared memory region */ |
| 51 | +}; |
| 52 | + |
| 53 | +/** |
| 54 | + * @brief Remote I/O device initialization routine |
| 55 | + * @note Executed only once by the master CPU |
| 56 | + */ |
| 57 | +void remio_init(void); |
| 58 | + |
| 59 | +/** |
| 60 | + * @brief Remote I/O device VM CPU assignment routine |
| 61 | + * @note Executed by each VM that holds a Remote I/O device, it is responsible for |
| 62 | + * assigning the frontend or backend CPU ID for the respective Remote I/O device |
| 63 | + * If the VM was alloacted with more than one CPU the assigned CPU will be the |
| 64 | + * one with the lowest ID, since only one CPU is required to inject VM interrupts |
| 65 | + * @param vm Pointer to the VM structure |
| 66 | + */ |
| 67 | +void remio_assign_vm_cpus(struct vm* vm); |
| 68 | + |
| 69 | +/** |
| 70 | + * @brief Remote I/O hypercall callback |
| 71 | + * @note Used to exchange information between the Remote I/O system and the backend VM |
| 72 | + * @param arg0 First argument of the hypercall |
| 73 | + * @param arg1 Second argument of the hypercall |
| 74 | + * @param arg2 Third argument of the hypercall |
| 75 | + * @return Returns the number of pending I/O requests |
| 76 | + */ |
| 77 | +long int remio_hypercall(unsigned long arg0, unsigned long arg1, unsigned long arg2); |
| 78 | + |
| 79 | +/** |
| 80 | + * @brief Remote I/O MMIO emulation handler |
| 81 | + * @note Executed by the frontend VM when a MMIO access is performed |
| 82 | + * @param emul_access Holds the information about the MMIO access |
| 83 | + * @return Returns true if handled successfully, false otherwise |
| 84 | + */ |
| 85 | +bool remio_mmio_emul_handler(struct emul_access* emul_access); |
| 86 | + |
| 87 | +#endif /* __REMIO_H__ */ |
0 commit comments