Kineret Berger | 5bb4742 | 2017-02-09 11:51:32 +0200 | [diff] [blame] | 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 _UAPI_SPCOM_H_ |
| 14 | #define _UAPI_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 | /* Maximum size (including null) for channel names */ |
| 34 | #define SPCOM_CHANNEL_NAME_SIZE 32 |
| 35 | |
| 36 | /* |
| 37 | * file read(fd, buf, size) with this size, |
| 38 | * hints the kernel that user space wants to read the next-req-size. |
| 39 | * This size is bigger than both SPCOM_MAX_REQUEST_SIZE and |
| 40 | * SPCOM_MAX_RESPONSE_SIZE , so it is not a valid data size. |
| 41 | */ |
| 42 | #define SPCOM_GET_NEXT_REQUEST_SIZE (PAGE_SIZE-1) |
| 43 | |
| 44 | /* Command Id between spcomlib and spcom driver, on write() */ |
| 45 | enum spcom_cmd_id { |
| 46 | SPCOM_CMD_LOAD_APP = 0x4C4F4144, /* "LOAD" = 0x4C4F4144 */ |
| 47 | SPCOM_CMD_RESET_SP = 0x52455354, /* "REST" = 0x52455354 */ |
| 48 | SPCOM_CMD_SEND = 0x53454E44, /* "SEND" = 0x53454E44 */ |
| 49 | SPCOM_CMD_SEND_MODIFIED = 0x534E444D, /* "SNDM" = 0x534E444D */ |
| 50 | SPCOM_CMD_LOCK_ION_BUF = 0x4C4F434B, /* "LOCK" = 0x4C4F434B */ |
| 51 | SPCOM_CMD_UNLOCK_ION_BUF = 0x554C434B, /* "ULCK" = 0x4C4F434B */ |
| 52 | SPCOM_CMD_FSSR = 0x46535352, /* "FSSR" = 0x46535352 */ |
| 53 | SPCOM_CMD_CREATE_CHANNEL = 0x43524554, /* "CRET" = 0x43524554 */ |
| 54 | }; |
| 55 | |
| 56 | /* |
| 57 | * @note: Event types that are always implicitly polled: |
| 58 | * POLLERR=0x08 | POLLHUP=0x10 | POLLNVAL=0x20 |
| 59 | * so bits 3,4,5 can't be used |
| 60 | */ |
| 61 | enum spcom_poll_events { |
| 62 | SPCOM_POLL_LINK_STATE = BIT(1), |
| 63 | SPCOM_POLL_CH_CONNECT = BIT(2), |
| 64 | SPCOM_POLL_READY_FLAG = BIT(14), /* output */ |
| 65 | SPCOM_POLL_WAIT_FLAG = BIT(15), /* if set , wait for the event */ |
| 66 | }; |
| 67 | |
| 68 | /* Common Command structure between User Space and spcom driver, on write() */ |
| 69 | struct spcom_user_command { |
| 70 | enum spcom_cmd_id cmd_id; |
| 71 | uint32_t arg; |
| 72 | } __packed; |
| 73 | |
| 74 | /* Command structure between User Space and spcom driver, on write() */ |
| 75 | struct spcom_send_command { |
| 76 | enum spcom_cmd_id cmd_id; |
| 77 | uint32_t timeout_msec; |
| 78 | uint32_t buf_size; |
| 79 | char buf[0]; /* Variable buffer size - must be last field */ |
| 80 | } __packed; |
| 81 | |
| 82 | /* Command structure between userspace spcomlib and spcom driver, on write() */ |
| 83 | struct spcom_user_create_channel_command { |
| 84 | enum spcom_cmd_id cmd_id; |
| 85 | char ch_name[SPCOM_CHANNEL_NAME_SIZE]; |
| 86 | } __packed; |
| 87 | |
| 88 | /* maximum ION buf for send-modfied-command */ |
| 89 | #define SPCOM_MAX_ION_BUF 4 |
| 90 | |
| 91 | struct spcom_ion_info { |
| 92 | int32_t fd; /* ION buffer File Descriptor, set -1 for invalid fd */ |
| 93 | uint32_t buf_offset; /* virtual address offset in request/response */ |
| 94 | }; |
| 95 | |
| 96 | /* Pass this FD to unlock all ION buffer for the specific channel */ |
| 97 | #define SPCOM_ION_FD_UNLOCK_ALL 0xFFFF |
| 98 | |
| 99 | struct spcom_ion_handle { |
| 100 | int32_t fd; /* File Descriptor associated with the buffer */ |
| 101 | }; |
| 102 | |
| 103 | /* Command structure between User Space and spcom driver, on write() */ |
| 104 | struct spcom_user_send_modified_command { |
| 105 | enum spcom_cmd_id cmd_id; |
| 106 | struct spcom_ion_info ion_info[SPCOM_MAX_ION_BUF]; |
| 107 | uint32_t timeout_msec; |
| 108 | uint32_t buf_size; |
| 109 | char buf[0]; /* Variable buffer size - must be last field */ |
| 110 | } __packed; |
| 111 | |
| 112 | |
| 113 | #endif /* _UAPI_SPCOM_H_ */ |