| 
 | 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__ */  | 
0 commit comments