1 /* 2 * Copyright (c) 2021 Carlo Caione <ccaione@baylibre.com> 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_INCLUDE_IPC_SERVICE_IPC_STATIC_VRINGS_H_ 8 #define ZEPHYR_INCLUDE_IPC_SERVICE_IPC_STATIC_VRINGS_H_ 9 10 #include <zephyr/ipc/ipc_service.h> 11 #include <openamp/open_amp.h> 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 /** 18 * @brief IPC service static VRINGs API 19 * @defgroup ipc_service_static_vrings_api IPC service static VRINGs API 20 * @ingroup ipc 21 * @{ 22 */ 23 24 /** Number of used VRING buffers. */ 25 #define VRING_COUNT (2) 26 27 /** 28 * Memory alignment. 29 * 30 * This should take into account the cache line if the cache is enabled, otherwise 31 * it should be naturally aligned to the machine word size. 32 */ 33 #define MEM_ALIGNMENT CONFIG_IPC_SERVICE_STATIC_VRINGS_MEM_ALIGNMENT 34 35 /** 36 * @typedef ipc_notify_cb 37 * @brief Define the notify callback. 38 * 39 * This callback is defined at instance level and it is called on virtqueue notify. 40 * 41 * @param vq Virtqueue. 42 * @param priv Priv data. 43 */ 44 typedef void (*ipc_notify_cb)(struct virtqueue *vq, void *priv); 45 46 /** @brief Static VRINGs structure. 47 * 48 * Struct used to represent and carry information about static allocation of VRINGs. 49 */ 50 struct ipc_static_vrings { 51 /** virtIO device. */ 52 struct virtio_device vdev; 53 54 /** SHM physmap. */ 55 metal_phys_addr_t shm_physmap[1]; 56 57 /** SHM and addresses. */ 58 uintptr_t status_reg_addr; 59 60 /** TX VRING address. */ 61 uintptr_t tx_addr; 62 63 /** RX VRING address. */ 64 uintptr_t rx_addr; 65 66 /** VRING size. */ 67 size_t vring_size; 68 69 /** Shared memory region address. */ 70 uintptr_t shm_addr; 71 72 /** Share memory region size. */ 73 size_t shm_size; 74 75 /** SHM IO region. */ 76 struct metal_io_region shm_io; 77 78 /** VRINGs */ 79 struct virtio_vring_info rvrings[VRING_COUNT]; 80 81 /** Virtqueues. */ 82 struct virtqueue *vq[VRING_COUNT]; 83 84 /** Private data to be passed to the notify callback. */ 85 void *priv; 86 87 /** Notify callback. */ 88 ipc_notify_cb notify_cb; 89 }; 90 91 /** @brief Init the static VRINGs. 92 * 93 * Init VRINGs and Virtqueues of an OpenAMP / RPMsg instance. 94 * 95 * @param vr Pointer to the VRINGs instance struct. 96 * @param role Host / Remote role. 97 * 98 * @retval -EINVAL When some parameter is missing. 99 * @retval -ENOMEM When memory is not enough for VQs allocation. 100 * @retval 0 If successful. 101 * @retval Other errno codes depending on the OpenAMP implementation. 102 */ 103 int ipc_static_vrings_init(struct ipc_static_vrings *vr, unsigned int role); 104 105 /** @brief Deinitialise the static VRINGs. 106 * 107 * Deinitialise VRINGs and Virtqueues of an OpenAMP / RPMsg instance. 108 * 109 * @param vr Pointer to the VRINGs instance struct. 110 * @param role Host / Remote role. 111 * 112 * @retval 0 If successful. 113 * @retval Other errno codes depending on the OpenAMP implementation. 114 */ 115 int ipc_static_vrings_deinit(struct ipc_static_vrings *vr, unsigned int role); 116 117 /** 118 * @} 119 */ 120 121 #ifdef __cplusplus 122 } 123 #endif 124 125 #endif /* ZEPHYR_INCLUDE_IPC_SERVICE_IPC_STATIC_VRINGS_H_ */ 126