1 /* 2 * Copyright (C) 2022 Huawei Technologies Co., Ltd. 3 * 4 * This software is licensed under the terms of the GNU General Public 5 * License version 2, as published by the Free Software Foundation, and 6 * may be copied, distributed, and modified under those terms. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 */ 13 14 #ifndef SHARED_MEM_H 15 #define SHARED_MEM_H 16 17 #include <linux/types.h> 18 #include <linux/of.h> 19 20 #ifdef CONFIG_512K_LOG_PAGES_MEM 21 #define PAGES_LOG_MEM_LEN (512 * SZ_1K) /* mem size: 512 k */ 22 #else 23 #define PAGES_LOG_MEM_LEN (256 * SZ_1K) /* mem size: 256 k */ 24 #endif 25 26 #ifndef CONFIG_SHARED_MEM_RESERVED 27 typedef struct page mailbox_page_t; 28 #else 29 typedef uintptr_t mailbox_page_t; 30 #endif 31 32 uint64_t get_reserved_cmd_vaddr_of(phys_addr_t cmd_phys, uint64_t cmd_size); 33 int load_tz_shared_mem(struct device_node *np); 34 35 mailbox_page_t *mailbox_alloc_pages(int order); 36 void mailbox_free_pages(mailbox_page_t *pages, int order); 37 uintptr_t mailbox_page_address(mailbox_page_t *page); 38 mailbox_page_t *mailbox_virt_to_page(uint64_t ptr); 39 uint64_t get_operation_vaddr(void); 40 void free_operation(uint64_t op_vaddr); 41 42 uint64_t get_log_mem_vaddr(void); 43 uint64_t get_log_mem_paddr(uint64_t log_vaddr); 44 uint64_t get_log_mem_size(void); 45 void free_log_mem(uint64_t log_vaddr); 46 47 uint64_t get_cmd_mem_vaddr(void); 48 uint64_t get_cmd_mem_paddr(uint64_t cmd_vaddr); 49 void free_cmd_mem(uint64_t cmd_vaddr); 50 51 uint64_t get_spi_mem_vaddr(void); 52 uint64_t get_spi_mem_paddr(uintptr_t spi_vaddr); 53 void free_spi_mem(uint64_t spi_vaddr); 54 #endif 55