1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Permission is hereby granted, free of charge, to any person 5 * obtaining a copy of this software and associated documentation 6 * files (the "Software"), to deal in the Software without 7 * restriction, including without limitation the rights to use, copy, 8 * modify, merge, publish, distribute, sublicense, and/or sell copies 9 * of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 */ 24 25 #ifndef TRUSTY_TRUSTY_DEV_H_ 26 #define TRUSTY_TRUSTY_DEV_H_ 27 28 #include <trusty/sysdeps.h> 29 30 typedef uint64_t trusty_shared_mem_id_t; 31 32 /* 33 * Architecture specific Trusty device struct. 34 * 35 * @priv_data: system dependent data, may be unused 36 * @api_version: TIPC version 37 */ 38 struct trusty_dev { 39 void* priv_data; 40 uint32_t api_version; 41 uint16_t ffa_local_id; 42 uint16_t ffa_remote_id; 43 void* ffa_tx; 44 void* ffa_rx; 45 }; 46 47 /* 48 * Initializes @dev with @priv, and gets the API version by calling 49 * into Trusty. Returns negative on error. 50 */ 51 int trusty_dev_init(struct trusty_dev* dev, void* priv); 52 53 /* 54 * Cleans up anything related to @dev. Returns negative on error. 55 */ 56 int trusty_dev_shutdown(struct trusty_dev* dev); 57 58 /* 59 * Enter trusty on cpus that are not in an ipc call 60 */ 61 int trusty_dev_nop(struct trusty_dev* dev); 62 63 /* 64 * Initialize the interrupt controller 65 */ 66 int arch_gic_init(int cpu); 67 68 /* 69 * Invokes creation of queueless Trusty IPC device on the secure side. 70 * @buf will be mapped into Trusty's address space. 71 * 72 * @dev: trusty device, initialized with trusty_dev_init 73 * @buf: physical address info of buffer to share with Trusty 74 * @buf_size: size of @buf 75 */ 76 int trusty_dev_init_ipc(struct trusty_dev* dev, 77 trusty_shared_mem_id_t buf_id, 78 uint32_t buf_size); 79 /* 80 * Invokes execution of command on the secure side. 81 * 82 * @dev: trusty device, initialized with trusty_dev_init 83 * @buf: physical address info of shared buffer containing command 84 * @buf_size: size of command data 85 */ 86 int trusty_dev_exec_ipc(struct trusty_dev* dev, 87 trusty_shared_mem_id_t buf_id, 88 uint32_t buf_size); 89 90 int trusty_dev_exec_fc_ipc(struct trusty_dev* dev, 91 trusty_shared_mem_id_t buf_id, 92 uint32_t buf_size); 93 94 /* 95 * Invokes deletion of queueless Trusty IPC device on the secure side. 96 * @buf is unmapped, and all open channels are closed. 97 * 98 * @dev: trusty device, initialized with trusty_dev_init 99 * @buf: physical address info of shared buffer 100 * @buf_size: size of @buf 101 */ 102 int trusty_dev_shutdown_ipc(struct trusty_dev* dev, 103 trusty_shared_mem_id_t buf_id, 104 uint32_t buf_size); 105 106 /** 107 * trusty_dev_share_memory - Share a contiguous memory region 108 * @dev: trusty device, initialized with trusty_dev_init. 109 * @idp: pointer to return shared memory object id in. 110 * @pinfo: physical address and memory attributes 111 * @page_count: number of 4k pages to share. 112 */ 113 int trusty_dev_share_memory(struct trusty_dev* dev, 114 trusty_shared_mem_id_t* idp, 115 struct ns_mem_page_info* pinfo, 116 size_t page_count); 117 118 /** 119 * trusty_dev_reclaim_memory - Reclaim a contiguous memory region 120 * @dev: trusty device, initialized with trusty_dev_init. 121 * @id: shared memory object id returned from trusty_dev_share_memory. 122 */ 123 int trusty_dev_reclaim_memory(struct trusty_dev* dev, 124 trusty_shared_mem_id_t id); 125 126 #endif /* TRUSTY_TRUSTY_DEV_H_ */ 127