1 /* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. 2 * 3 * This program is free software; you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License version 2 and 5 * only version 2 as published by the Free Software Foundation. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 */ 12 13 #ifndef _SPCOM_H_ 14 #define _SPCOM_H_ 15 16 #include <linux/types.h> /* uint32_t, bool */ 17 #ifndef BIT 18 #define BIT(x) (1 << x) 19 #endif 20 #ifndef PAGE_SIZE 21 #define PAGE_SIZE 4096 22 #endif 23 24 /** 25 * @brief - Secure Processor Communication interface to user space spcomlib. 26 * 27 * Sending data and control commands by write() file operation. 28 * Receiving data by read() file operation. 29 * Getting the next request size by read() file operation, 30 * with special size SPCOM_GET_NEXT_REQUEST_SIZE. 31 */ 32 33 /* 34 * Maximum number of channel between Secure Processor and HLOS. 35 * including predefined channels, like "sp_kernel". 36 */ 37 #define SPCOM_MAX_CHANNELS 0x20 38 39 /* Maximum size (including null) for channel names */ 40 #define SPCOM_CHANNEL_NAME_SIZE 32 41 42 /* 43 * file read(fd, buf, size) with this size, 44 * hints the kernel that user space wants to read the next-req-size. 45 * This size is bigger than both SPCOM_MAX_REQUEST_SIZE and 46 * SPCOM_MAX_RESPONSE_SIZE , so it is not a valid data size. 47 */ 48 #define SPCOM_GET_NEXT_REQUEST_SIZE (PAGE_SIZE-1) 49 50 /* Command Id between spcomlib and spcom driver, on write() */ 51 enum spcom_cmd_id { 52 SPCOM_CMD_LOAD_APP = 0x4C4F4144, /* "LOAD" = 0x4C4F4144 */ 53 SPCOM_CMD_RESET_SP = 0x52455354, /* "REST" = 0x52455354 */ 54 SPCOM_CMD_SEND = 0x53454E44, /* "SEND" = 0x53454E44 */ 55 SPCOM_CMD_SEND_MODIFIED = 0x534E444D, /* "SNDM" = 0x534E444D */ 56 SPCOM_CMD_LOCK_ION_BUF = 0x4C4F434B, /* "LOCK" = 0x4C4F434B */ 57 SPCOM_CMD_UNLOCK_ION_BUF = 0x554C434B, /* "ULCK" = 0x4C4F434B */ 58 SPCOM_CMD_FSSR = 0x46535352, /* "FSSR" = 0x46535352 */ 59 SPCOM_CMD_CREATE_CHANNEL = 0x43524554, /* "CRET" = 0x43524554 */ 60 }; 61 62 /* 63 * @note: Event types that are always implicitly polled: 64 * POLLERR=0x08 | POLLHUP=0x10 | POLLNVAL=0x20 65 * so bits 3,4,5 can't be used 66 */ 67 enum spcom_poll_events { 68 SPCOM_POLL_LINK_STATE = BIT(1), 69 SPCOM_POLL_CH_CONNECT = BIT(2), 70 SPCOM_POLL_READY_FLAG = BIT(14), /* output */ 71 SPCOM_POLL_WAIT_FLAG = BIT(15), /* if set , wait for the event */ 72 }; 73 74 /* Common Command structure between User Space and spcom driver, on write() */ 75 struct spcom_user_command { 76 enum spcom_cmd_id cmd_id; 77 uint32_t arg; 78 } __attribute__((packed)); 79 80 /* Command structure between User Space and spcom driver, on write() */ 81 struct spcom_send_command { 82 enum spcom_cmd_id cmd_id; 83 uint32_t timeout_msec; 84 uint32_t buf_size; 85 char buf[0]; /* Variable buffer size - must be last field */ 86 } __attribute__((packed)); 87 88 /* Command structure between userspace spcomlib and spcom driver, on write() */ 89 struct spcom_user_create_channel_command { 90 enum spcom_cmd_id cmd_id; 91 char ch_name[SPCOM_CHANNEL_NAME_SIZE]; 92 } __attribute__((packed)); 93 94 /* maximum ION buf for send-modfied-command */ 95 #define SPCOM_MAX_ION_BUF 4 96 97 struct spcom_ion_info { 98 int32_t fd; /* ION buffer File Descriptor, set -1 for invalid fd */ 99 uint32_t buf_offset; /* virtual address offset in request/response */ 100 }; 101 102 /* Pass this FD to unlock all ION buffer for the specific channel */ 103 #define SPCOM_ION_FD_UNLOCK_ALL 0xFFFF 104 105 struct spcom_ion_handle { 106 int32_t fd; /* File Descriptor associated with the buffer */ 107 }; 108 109 /* Command structure between User Space and spcom driver, on write() */ 110 struct spcom_user_send_modified_command { 111 enum spcom_cmd_id cmd_id; 112 struct spcom_ion_info ion_info[SPCOM_MAX_ION_BUF]; 113 uint32_t timeout_msec; 114 uint32_t buf_size; 115 char buf[0]; /* Variable buffer size - must be last field */ 116 } __attribute__((packed)); 117 118 119 #endif /* _SPCOM_H_ */ 120