AnilKumar Chimata | e5e6051 | 2017-05-03 14:06:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014, 2017 The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 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 | |
AnilKumar Chimata | e78789a | 2017-04-07 12:18:46 -0700 | [diff] [blame] | 14 | #ifndef _UAPI_COMPAT_QCEDEV__H |
| 15 | #define _UAPI_COMPAT_QCEDEV__H |
| 16 | |
| 17 | #include <linux/types.h> |
| 18 | #include <linux/ioctl.h> |
| 19 | |
| 20 | #if IS_ENABLED(CONFIG_COMPAT) |
| 21 | #include <linux/compat.h> |
| 22 | |
| 23 | /** |
| 24 | * struct compat_buf_info - Buffer information |
| 25 | * @offset: Offset from the base address of the buffer |
| 26 | * (Used when buffer is allocated using PMEM) |
| 27 | * @vaddr: Virtual buffer address pointer |
| 28 | * @len: Size of the buffer |
| 29 | */ |
| 30 | struct compat_buf_info { |
| 31 | union { |
| 32 | compat_ulong_t offset; |
| 33 | compat_uptr_t vaddr; |
| 34 | }; |
| 35 | compat_ulong_t len; |
| 36 | }; |
| 37 | |
| 38 | /** |
| 39 | * struct compat_qcedev_vbuf_info - Source and destination Buffer information |
| 40 | * @src: Array of buf_info for input/source |
| 41 | * @dst: Array of buf_info for output/destination |
| 42 | */ |
| 43 | struct compat_qcedev_vbuf_info { |
| 44 | struct compat_buf_info src[QCEDEV_MAX_BUFFERS]; |
| 45 | struct compat_buf_info dst[QCEDEV_MAX_BUFFERS]; |
| 46 | }; |
| 47 | |
| 48 | /** |
| 49 | * struct compat_qcedev_pmem_info - Stores PMEM buffer information |
| 50 | * @fd_src: Handle to /dev/adsp_pmem used to allocate |
| 51 | * memory for input/src buffer |
| 52 | * @src: Array of buf_info for input/source |
| 53 | * @fd_dst: Handle to /dev/adsp_pmem used to allocate |
| 54 | * memory for output/dst buffer |
| 55 | * @dst: Array of buf_info for output/destination |
| 56 | * @pmem_src_offset: The offset from input/src buffer |
| 57 | * (allocated by PMEM) |
| 58 | */ |
| 59 | struct compat_qcedev_pmem_info { |
| 60 | compat_int_t fd_src; |
| 61 | struct compat_buf_info src[QCEDEV_MAX_BUFFERS]; |
| 62 | compat_int_t fd_dst; |
| 63 | struct compat_buf_info dst[QCEDEV_MAX_BUFFERS]; |
| 64 | }; |
| 65 | |
| 66 | /** |
| 67 | * struct compat_qcedev_cipher_op_req - Holds the ciphering request information |
| 68 | * @use_pmem (IN): Flag to indicate if buffer source is PMEM |
| 69 | * QCEDEV_USE_PMEM/QCEDEV_NO_PMEM |
| 70 | * @pmem (IN): Stores PMEM buffer information. |
| 71 | * Refer struct qcedev_pmem_info |
| 72 | * @vbuf (IN/OUT): Stores Source and destination Buffer information |
| 73 | * Refer to struct qcedev_vbuf_info |
| 74 | * @data_len (IN): Total Length of input/src and output/dst in bytes |
| 75 | * @in_place_op (IN): Indicates whether the operation is inplace where |
| 76 | * source == destination |
| 77 | * When using PMEM allocated memory, must set this to 1 |
| 78 | * @enckey (IN): 128 bits of confidentiality key |
| 79 | * enckey[0] bit 127-120, enckey[1] bit 119-112,.. |
| 80 | * enckey[15] bit 7-0 |
| 81 | * @encklen (IN): Length of the encryption key(set to 128 bits/16 |
| 82 | * bytes in the driver) |
| 83 | * @iv (IN/OUT): Initialization vector data |
| 84 | * This is updated by the driver, incremented by |
| 85 | * number of blocks encrypted/decrypted. |
| 86 | * @ivlen (IN): Length of the IV |
| 87 | * @byteoffset (IN): Offset in the Cipher BLOCK (applicable and to be set |
| 88 | * for AES-128 CTR mode only) |
| 89 | * @alg (IN): Type of ciphering algorithm: AES/DES/3DES |
| 90 | * @mode (IN): Mode use when using AES algorithm: ECB/CBC/CTR |
| 91 | * Applicable when using AES algorithm only |
| 92 | * @op (IN): Type of operation: QCEDEV_OPER_DEC/QCEDEV_OPER_ENC or |
| 93 | * QCEDEV_OPER_ENC_NO_KEY/QCEDEV_OPER_DEC_NO_KEY |
| 94 | * |
| 95 | * If use_pmem is set to 0, the driver assumes that memory was not allocated |
| 96 | * via PMEM, and kernel will need to allocate memory and copy data from user |
| 97 | * space buffer (data_src/dta_dst) and process accordingly and copy data back |
| 98 | * to the user space buffer |
| 99 | * |
| 100 | * If use_pmem is set to 1, the driver assumes that memory was allocated via |
| 101 | * PMEM. |
| 102 | * The kernel driver will use the fd_src to determine the kernel virtual address |
| 103 | * base that maps to the user space virtual address base for the buffer |
| 104 | * allocated in user space. |
| 105 | * The final input/src and output/dst buffer pointer will be determined |
| 106 | * by adding the offsets to the kernel virtual addr. |
| 107 | * |
| 108 | * If use of hardware key is supported in the target, user can configure the |
| 109 | * key parameters (encklen, enckey) to use the hardware key. |
| 110 | * In order to use the hardware key, set encklen to 0 and set the enckey |
| 111 | * data array to 0. |
| 112 | */ |
| 113 | struct compat_qcedev_cipher_op_req { |
| 114 | uint8_t use_pmem; |
| 115 | union { |
| 116 | struct compat_qcedev_pmem_info pmem; |
| 117 | struct compat_qcedev_vbuf_info vbuf; |
| 118 | }; |
| 119 | compat_ulong_t entries; |
| 120 | compat_ulong_t data_len; |
| 121 | uint8_t in_place_op; |
| 122 | uint8_t enckey[QCEDEV_MAX_KEY_SIZE]; |
| 123 | compat_ulong_t encklen; |
| 124 | uint8_t iv[QCEDEV_MAX_IV_SIZE]; |
| 125 | compat_ulong_t ivlen; |
| 126 | compat_ulong_t byteoffset; |
| 127 | enum qcedev_cipher_alg_enum alg; |
| 128 | enum qcedev_cipher_mode_enum mode; |
| 129 | enum qcedev_oper_enum op; |
| 130 | }; |
| 131 | |
| 132 | /** |
| 133 | * struct qcedev_sha_op_req - Holds the hashing request information |
| 134 | * @data (IN): Array of pointers to the data to be hashed |
| 135 | * @entries (IN): Number of buf_info entries in the data array |
| 136 | * @data_len (IN): Length of data to be hashed |
| 137 | * @digest (IN/OUT): Returns the hashed data information |
| 138 | * @diglen (OUT): Size of the hashed/digest data |
| 139 | * @authkey (IN): Pointer to authentication key for HMAC |
| 140 | * @authklen (IN): Size of the authentication key |
| 141 | * @alg (IN): Secure Hash algorithm |
| 142 | */ |
| 143 | struct compat_qcedev_sha_op_req { |
| 144 | struct compat_buf_info data[QCEDEV_MAX_BUFFERS]; |
| 145 | compat_ulong_t entries; |
| 146 | compat_ulong_t data_len; |
| 147 | uint8_t digest[QCEDEV_MAX_SHA_DIGEST]; |
| 148 | compat_ulong_t diglen; |
| 149 | compat_uptr_t authkey; |
| 150 | compat_ulong_t authklen; |
| 151 | enum qcedev_sha_alg_enum alg; |
| 152 | }; |
| 153 | |
| 154 | struct file; |
| 155 | extern long compat_qcedev_ioctl(struct file *file, |
| 156 | unsigned int cmd, unsigned long arg); |
| 157 | |
| 158 | #define COMPAT_QCEDEV_IOCTL_ENC_REQ \ |
| 159 | _IOWR(QCEDEV_IOC_MAGIC, 1, struct compat_qcedev_cipher_op_req) |
| 160 | #define COMPAT_QCEDEV_IOCTL_DEC_REQ \ |
| 161 | _IOWR(QCEDEV_IOC_MAGIC, 2, struct compat_qcedev_cipher_op_req) |
| 162 | #define COMPAT_QCEDEV_IOCTL_SHA_INIT_REQ \ |
| 163 | _IOWR(QCEDEV_IOC_MAGIC, 3, struct compat_qcedev_sha_op_req) |
| 164 | #define COMPAT_QCEDEV_IOCTL_SHA_UPDATE_REQ \ |
| 165 | _IOWR(QCEDEV_IOC_MAGIC, 4, struct compat_qcedev_sha_op_req) |
| 166 | #define COMPAT_QCEDEV_IOCTL_SHA_FINAL_REQ \ |
| 167 | _IOWR(QCEDEV_IOC_MAGIC, 5, struct compat_qcedev_sha_op_req) |
| 168 | #define COMPAT_QCEDEV_IOCTL_GET_SHA_REQ \ |
| 169 | _IOWR(QCEDEV_IOC_MAGIC, 6, struct compat_qcedev_sha_op_req) |
| 170 | #define COMPAT_QCEDEV_IOCTL_LOCK_CE \ |
| 171 | _IO(QCEDEV_IOC_MAGIC, 7) |
| 172 | #define COMPAT_QCEDEV_IOCTL_UNLOCK_CE \ |
| 173 | _IO(QCEDEV_IOC_MAGIC, 8) |
| 174 | #define COMPAT_QCEDEV_IOCTL_GET_CMAC_REQ \ |
| 175 | _IOWR(QCEDEV_IOC_MAGIC, 9, struct compat_qcedev_sha_op_req) |
| 176 | |
| 177 | #endif /* CONFIG_COMPAT */ |
| 178 | #endif /* _UAPI_COMPAT_QCEDEV__H */ |