1 /* 2 * Copyright 2020-2024 NXP 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef RPMSG_PLATFORM_H_ 8 #define RPMSG_PLATFORM_H_ 9 10 #include <stdint.h> 11 #include "virtio_ring.h" 12 13 /* 14 * No need to align the VRING as defined in Linux because kw45b41 is not intended 15 * to run the Linux 16 */ 17 #ifndef VRING_ALIGN 18 #define VRING_ALIGN (0x10U) 19 #endif 20 21 /* contains pool of descriptors and two circular buffers */ 22 #ifndef VRING_SIZE 23 /* set VRING_SIZE based on number of used buffers as calculated in vring_init */ 24 #define VRING_DESC_SIZE (((RL_BUFFER_COUNT * sizeof(struct vring_desc)) + VRING_ALIGN - 1UL) & ~(VRING_ALIGN - 1UL)) 25 #define VRING_AVAIL_SIZE \ 26 (((sizeof(struct vring_avail) + (RL_BUFFER_COUNT * sizeof(uint16_t)) + sizeof(uint16_t)) + VRING_ALIGN - 1UL) & \ 27 ~(VRING_ALIGN - 1UL)) 28 #define VRING_USED_SIZE \ 29 (((sizeof(struct vring_used) + (RL_BUFFER_COUNT * sizeof(struct vring_used_elem)) + sizeof(uint16_t)) + \ 30 VRING_ALIGN - 1UL) & \ 31 ~(VRING_ALIGN - 1UL)) 32 #define VRING_SIZE (VRING_DESC_SIZE + VRING_AVAIL_SIZE + VRING_USED_SIZE) 33 #endif 34 35 /* define shared memory space for VRINGS per one channel */ 36 #define RL_VRING_OVERHEAD (2UL * VRING_SIZE) 37 38 #define RL_GET_VQ_ID(link_id, queue_id) (((queue_id)&0x1U) | (((link_id) << 1U) & 0xFFFFFFFEU)) 39 #define RL_GET_LINK_ID(id) (((id)&0xFFFFFFFEU) >> 1U) 40 #define RL_GET_Q_ID(id) ((id)&0x1U) 41 42 #define RL_PLATFORM_KW45B41_LINK_ID (0U) 43 #define RL_PLATFORM_HIGHEST_LINK_ID (0U) 44 45 typedef struct rpmsg_platform_shmem_config 46 { 47 uint32_t buffer_payload_size; /* custom buffer payload size setting that overwrites RL_BUFFER_PAYLOAD_SIZE global 48 config, must be equal to (240, 496, 1008, ...) [2^n - 16] */ 49 uint16_t buffer_count; /* custom buffer count setting that overwrites RL_BUFFER_COUNT global config, must be power 50 of two (2, 4, ...) */ 51 uint32_t vring_size; /* custom vring size */ 52 uint32_t vring_align; /* custom vring alignment */ 53 } rpmsg_platform_shmem_config_t; 54 55 /* platform interrupt related functions */ 56 int32_t platform_init_interrupt(uint32_t vector_id, void *isr_data); 57 int32_t platform_deinit_interrupt(uint32_t vector_id); 58 int32_t platform_interrupt_enable(uint32_t vector_id); 59 int32_t platform_interrupt_disable(uint32_t vector_id); 60 int32_t platform_in_isr(void); 61 void platform_notify(uint32_t vector_id); 62 63 /* platform low-level time-delay (busy loop) */ 64 void platform_time_delay(uint32_t num_msec); 65 66 /* platform memory functions */ 67 void platform_map_mem_region(uint32_t vrt_addr, uint32_t phy_addr, uint32_t size, uint32_t flags); 68 void platform_cache_all_flush_invalidate(void); 69 void platform_cache_disable(void); 70 uintptr_t platform_vatopa(void *addr); 71 void *platform_patova(uintptr_t addr); 72 73 /* platform init/deinit */ 74 int32_t platform_init(void); 75 int32_t platform_deinit(void); 76 77 /*! 78 * \brief Set static shared memory configuration from application core in SMU2 to be accessible from nbu later. 79 * 80 */ 81 void platform_set_static_shmem_config(void); 82 83 /*! 84 * \brief API used when RL_ALLOW_CUSTOM_SHMEM_CONFIG is set to 1 in rpmsg_lite.c. 85 * \details On this platform we set the macro on nbu side to take the same config of application core previously 86 * set in platform_set_static_shmem_config(). 87 * 88 * \param[in] link_id NOT USED on this platform 89 * \param[out] *config shared memory configuration 90 * 91 * \return int 0 if success, other if error. 92 */ 93 uint32_t platform_get_custom_shmem_config(uint32_t link_id, rpmsg_platform_shmem_config_t *config); 94 95 #endif /* RPMSG_PLATFORM_H_ */ 96