1 /************************************************************************** 2 * 3 * Copyright 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA 4 * All Rights Reserved. 5 * Copyright (c) 2009 VMware, Inc., Palo Alto, CA., USA 6 * All Rights Reserved. 7 * 8 * This program is free software; you can redistribute it and/or modify it 9 * under the terms and conditions of the GNU General Public License, 10 * version 2, as published by the Free Software Foundation. 11 * 12 * This program is distributed in the hope it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15 * more details. 16 * 17 * You should have received a copy of the GNU General Public License along with 18 * this program; if not, write to the Free Software Foundation, Inc., 19 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 **************************************************************************/ 22 /* 23 * Authors 24 * Thomas Hellstrm <thomas-at-tungstengraphics-dot-com> 25 */ 26 27 #ifndef _TTM_PLACEMENT_USER_H_ 28 #define _TTM_PLACEMENT_USER_H_ 29 30 #if !defined(__KERNEL__) && !defined(_KERNEL) 31 #include <stdint.h> 32 #else 33 #include <linux/kernel.h> 34 #endif 35 36 #include "ttm/ttm_placement.h" 37 38 #define TTM_PLACEMENT_MAJOR 0 39 #define TTM_PLACEMENT_MINOR 1 40 #define TTM_PLACEMENT_PL 0 41 #define TTM_PLACEMENT_DATE "080819" 42 43 /** 44 * struct ttm_pl_create_req 45 * 46 * @size: The buffer object size. 47 * @placement: Flags that indicate initial acceptable 48 * placement. 49 * @page_alignment: Required alignment in pages. 50 * 51 * Input to the TTM_BO_CREATE ioctl. 52 */ 53 54 struct ttm_pl_create_req { 55 uint64_t size; 56 uint32_t placement; 57 uint32_t page_alignment; 58 }; 59 60 /** 61 * struct ttm_pl_create_ub_req 62 * 63 * @size: The buffer object size. 64 * @user_address: User-space address of the memory area that 65 * should be used to back the buffer object cast to 64-bit. 66 * @placement: Flags that indicate initial acceptable 67 * placement. 68 * @page_alignment: Required alignment in pages. 69 * 70 * Input to the TTM_BO_CREATE_UB ioctl. 71 */ 72 73 struct ttm_pl_create_ub_req { 74 uint64_t size; 75 uint64_t user_address; 76 uint32_t placement; 77 uint32_t page_alignment; 78 }; 79 80 /** 81 * struct ttm_pl_rep 82 * 83 * @gpu_offset: The current offset into the memory region used. 84 * This can be used directly by the GPU if there are no 85 * additional GPU mapping procedures used by the driver. 86 * 87 * @bo_size: Actual buffer object size. 88 * 89 * @map_handle: Offset into the device address space. 90 * Used for map, seek, read, write. This will never change 91 * during the lifetime of an object. 92 * 93 * @placement: Flag indicating the placement status of 94 * the buffer object using the TTM_PL flags above. 95 * 96 * @sync_object_arg: Used for user-space synchronization and 97 * depends on the synchronization model used. If fences are 98 * used, this is the buffer_object::fence_type_mask 99 * 100 * Output from the TTM_PL_CREATE and TTM_PL_REFERENCE, and 101 * TTM_PL_SETSTATUS ioctls. 102 */ 103 104 struct ttm_pl_rep { 105 uint64_t gpu_offset; 106 uint64_t bo_size; 107 uint64_t map_handle; 108 uint32_t placement; 109 uint32_t handle; 110 uint32_t sync_object_arg; 111 uint32_t pad64; 112 }; 113 114 /** 115 * struct ttm_pl_setstatus_req 116 * 117 * @set_placement: Placement flags to set. 118 * 119 * @clr_placement: Placement flags to clear. 120 * 121 * @handle: The object handle 122 * 123 * Input to the TTM_PL_SETSTATUS ioctl. 124 */ 125 126 struct ttm_pl_setstatus_req { 127 uint32_t set_placement; 128 uint32_t clr_placement; 129 uint32_t handle; 130 uint32_t pad64; 131 }; 132 133 /** 134 * struct ttm_pl_reference_req 135 * 136 * @handle: The object to put a reference on. 137 * 138 * Input to the TTM_PL_REFERENCE and the TTM_PL_UNREFERENCE ioctls. 139 */ 140 141 struct ttm_pl_reference_req { 142 uint32_t handle; 143 uint32_t pad64; 144 }; 145 146 /* 147 * ACCESS mode flags for SYNCCPU. 148 * 149 * TTM_SYNCCPU_MODE_READ will guarantee that the GPU is not 150 * writing to the buffer. 151 * 152 * TTM_SYNCCPU_MODE_WRITE will guarantee that the GPU is not 153 * accessing the buffer. 154 * 155 * TTM_SYNCCPU_MODE_NO_BLOCK makes sure the call does not wait 156 * for GPU accesses to finish but return -EBUSY. 157 * 158 * TTM_SYNCCPU_MODE_TRYCACHED Try to place the buffer in cacheable 159 * memory while synchronized for CPU. 160 */ 161 162 #define TTM_PL_SYNCCPU_MODE_READ TTM_ACCESS_READ 163 #define TTM_PL_SYNCCPU_MODE_WRITE TTM_ACCESS_WRITE 164 #define TTM_PL_SYNCCPU_MODE_NO_BLOCK (1 << 2) 165 #define TTM_PL_SYNCCPU_MODE_TRYCACHED (1 << 3) 166 167 /** 168 * struct ttm_pl_synccpu_arg 169 * 170 * @handle: The object to synchronize. 171 * 172 * @access_mode: access mode indicated by the 173 * TTM_SYNCCPU_MODE flags. 174 * 175 * @op: indicates whether to grab or release the 176 * buffer for cpu usage. 177 * 178 * Input to the TTM_PL_SYNCCPU ioctl. 179 */ 180 181 struct ttm_pl_synccpu_arg { 182 uint32_t handle; 183 uint32_t access_mode; 184 enum { 185 TTM_PL_SYNCCPU_OP_GRAB, 186 TTM_PL_SYNCCPU_OP_RELEASE 187 } op; 188 uint32_t pad64; 189 }; 190 191 /* 192 * Waiting mode flags for the TTM_BO_WAITIDLE ioctl. 193 * 194 * TTM_WAITIDLE_MODE_LAZY: Allow for sleeps during polling 195 * wait. 196 * 197 * TTM_WAITIDLE_MODE_NO_BLOCK: Don't block waiting for GPU, 198 * but return -EBUSY if the buffer is busy. 199 */ 200 201 #define TTM_PL_WAITIDLE_MODE_LAZY (1 << 0) 202 #define TTM_PL_WAITIDLE_MODE_NO_BLOCK (1 << 1) 203 204 /** 205 * struct ttm_waitidle_arg 206 * 207 * @handle: The object to synchronize. 208 * 209 * @mode: wait mode indicated by the 210 * TTM_SYNCCPU_MODE flags. 211 * 212 * Argument to the TTM_BO_WAITIDLE ioctl. 213 */ 214 215 struct ttm_pl_waitidle_arg { 216 uint32_t handle; 217 uint32_t mode; 218 }; 219 220 union ttm_pl_create_arg { 221 struct ttm_pl_create_req req; 222 struct ttm_pl_rep rep; 223 }; 224 225 union ttm_pl_reference_arg { 226 struct ttm_pl_reference_req req; 227 struct ttm_pl_rep rep; 228 }; 229 230 union ttm_pl_setstatus_arg { 231 struct ttm_pl_setstatus_req req; 232 struct ttm_pl_rep rep; 233 }; 234 235 union ttm_pl_create_ub_arg { 236 struct ttm_pl_create_ub_req req; 237 struct ttm_pl_rep rep; 238 }; 239 240 /* 241 * Ioctl offsets. 242 */ 243 244 #define TTM_PL_CREATE 0x00 245 #define TTM_PL_REFERENCE 0x01 246 #define TTM_PL_UNREF 0x02 247 #define TTM_PL_SYNCCPU 0x03 248 #define TTM_PL_WAITIDLE 0x04 249 #define TTM_PL_SETSTATUS 0x05 250 #define TTM_PL_CREATE_UB 0x06 251 252 #endif 253