1d722e3fbSopenharmony_ci/* 2d722e3fbSopenharmony_ci * Copyright © 2008 Intel Corporation 3d722e3fbSopenharmony_ci * 4d722e3fbSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5d722e3fbSopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6d722e3fbSopenharmony_ci * to deal in the Software without restriction, including without limitation 7d722e3fbSopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8d722e3fbSopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9d722e3fbSopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10d722e3fbSopenharmony_ci * 11d722e3fbSopenharmony_ci * The above copyright notice and this permission notice (including the next 12d722e3fbSopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13d722e3fbSopenharmony_ci * Software. 14d722e3fbSopenharmony_ci * 15d722e3fbSopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16d722e3fbSopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17d722e3fbSopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18d722e3fbSopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19d722e3fbSopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20d722e3fbSopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21d722e3fbSopenharmony_ci * IN THE SOFTWARE. 22d722e3fbSopenharmony_ci * 23d722e3fbSopenharmony_ci * Authors: 24d722e3fbSopenharmony_ci * Eric Anholt <eric@anholt.net> 25d722e3fbSopenharmony_ci * 26d722e3fbSopenharmony_ci */ 27d722e3fbSopenharmony_ci 28d722e3fbSopenharmony_ci/** 29d722e3fbSopenharmony_ci * @file intel_bufmgr_priv.h 30d722e3fbSopenharmony_ci * 31d722e3fbSopenharmony_ci * Private definitions of Intel-specific bufmgr functions and structures. 32d722e3fbSopenharmony_ci */ 33d722e3fbSopenharmony_ci 34d722e3fbSopenharmony_ci#ifndef INTEL_BUFMGR_PRIV_H 35d722e3fbSopenharmony_ci#define INTEL_BUFMGR_PRIV_H 36d722e3fbSopenharmony_ci 37d722e3fbSopenharmony_ci/** 38d722e3fbSopenharmony_ci * Context for a buffer manager instance. 39d722e3fbSopenharmony_ci * 40d722e3fbSopenharmony_ci * Contains public methods followed by private storage for the buffer manager. 41d722e3fbSopenharmony_ci */ 42d722e3fbSopenharmony_cistruct _drm_intel_bufmgr { 43d722e3fbSopenharmony_ci /** 44d722e3fbSopenharmony_ci * Allocate a buffer object. 45d722e3fbSopenharmony_ci * 46d722e3fbSopenharmony_ci * Buffer objects are not necessarily initially mapped into CPU virtual 47d722e3fbSopenharmony_ci * address space or graphics device aperture. They must be mapped 48d722e3fbSopenharmony_ci * using bo_map() or drm_intel_gem_bo_map_gtt() to be used by the CPU. 49d722e3fbSopenharmony_ci */ 50d722e3fbSopenharmony_ci drm_intel_bo *(*bo_alloc) (drm_intel_bufmgr *bufmgr, const char *name, 51d722e3fbSopenharmony_ci unsigned long size, unsigned int alignment); 52d722e3fbSopenharmony_ci 53d722e3fbSopenharmony_ci /** 54d722e3fbSopenharmony_ci * Allocate a buffer object, hinting that it will be used as a 55d722e3fbSopenharmony_ci * render target. 56d722e3fbSopenharmony_ci * 57d722e3fbSopenharmony_ci * This is otherwise the same as bo_alloc. 58d722e3fbSopenharmony_ci */ 59d722e3fbSopenharmony_ci drm_intel_bo *(*bo_alloc_for_render) (drm_intel_bufmgr *bufmgr, 60d722e3fbSopenharmony_ci const char *name, 61d722e3fbSopenharmony_ci unsigned long size, 62d722e3fbSopenharmony_ci unsigned int alignment); 63d722e3fbSopenharmony_ci 64d722e3fbSopenharmony_ci /** 65d722e3fbSopenharmony_ci * Allocate a buffer object from an existing user accessible 66d722e3fbSopenharmony_ci * address malloc'd with the provided size. 67d722e3fbSopenharmony_ci * Alignment is used when mapping to the gtt. 68d722e3fbSopenharmony_ci * Flags may be I915_VMAP_READ_ONLY or I915_USERPTR_UNSYNCHRONIZED 69d722e3fbSopenharmony_ci */ 70d722e3fbSopenharmony_ci drm_intel_bo *(*bo_alloc_userptr)(drm_intel_bufmgr *bufmgr, 71d722e3fbSopenharmony_ci const char *name, void *addr, 72d722e3fbSopenharmony_ci uint32_t tiling_mode, uint32_t stride, 73d722e3fbSopenharmony_ci unsigned long size, 74d722e3fbSopenharmony_ci unsigned long flags); 75d722e3fbSopenharmony_ci 76d722e3fbSopenharmony_ci /** 77d722e3fbSopenharmony_ci * Allocate a tiled buffer object. 78d722e3fbSopenharmony_ci * 79d722e3fbSopenharmony_ci * Alignment for tiled objects is set automatically; the 'flags' 80d722e3fbSopenharmony_ci * argument provides a hint about how the object will be used initially. 81d722e3fbSopenharmony_ci * 82d722e3fbSopenharmony_ci * Valid tiling formats are: 83d722e3fbSopenharmony_ci * I915_TILING_NONE 84d722e3fbSopenharmony_ci * I915_TILING_X 85d722e3fbSopenharmony_ci * I915_TILING_Y 86d722e3fbSopenharmony_ci * 87d722e3fbSopenharmony_ci * Note the tiling format may be rejected; callers should check the 88d722e3fbSopenharmony_ci * 'tiling_mode' field on return, as well as the pitch value, which 89d722e3fbSopenharmony_ci * may have been rounded up to accommodate for tiling restrictions. 90d722e3fbSopenharmony_ci */ 91d722e3fbSopenharmony_ci drm_intel_bo *(*bo_alloc_tiled) (drm_intel_bufmgr *bufmgr, 92d722e3fbSopenharmony_ci const char *name, 93d722e3fbSopenharmony_ci int x, int y, int cpp, 94d722e3fbSopenharmony_ci uint32_t *tiling_mode, 95d722e3fbSopenharmony_ci unsigned long *pitch, 96d722e3fbSopenharmony_ci unsigned long flags); 97d722e3fbSopenharmony_ci 98d722e3fbSopenharmony_ci /** Takes a reference on a buffer object */ 99d722e3fbSopenharmony_ci void (*bo_reference) (drm_intel_bo *bo); 100d722e3fbSopenharmony_ci 101d722e3fbSopenharmony_ci /** 102d722e3fbSopenharmony_ci * Releases a reference on a buffer object, freeing the data if 103d722e3fbSopenharmony_ci * no references remain. 104d722e3fbSopenharmony_ci */ 105d722e3fbSopenharmony_ci void (*bo_unreference) (drm_intel_bo *bo); 106d722e3fbSopenharmony_ci 107d722e3fbSopenharmony_ci /** 108d722e3fbSopenharmony_ci * Maps the buffer into userspace. 109d722e3fbSopenharmony_ci * 110d722e3fbSopenharmony_ci * This function will block waiting for any existing execution on the 111d722e3fbSopenharmony_ci * buffer to complete, first. The resulting mapping is available at 112d722e3fbSopenharmony_ci * buf->virtual. 113d722e3fbSopenharmony_ci */ 114d722e3fbSopenharmony_ci int (*bo_map) (drm_intel_bo *bo, int write_enable); 115d722e3fbSopenharmony_ci 116d722e3fbSopenharmony_ci /** 117d722e3fbSopenharmony_ci * Reduces the refcount on the userspace mapping of the buffer 118d722e3fbSopenharmony_ci * object. 119d722e3fbSopenharmony_ci */ 120d722e3fbSopenharmony_ci int (*bo_unmap) (drm_intel_bo *bo); 121d722e3fbSopenharmony_ci 122d722e3fbSopenharmony_ci /** 123d722e3fbSopenharmony_ci * Write data into an object. 124d722e3fbSopenharmony_ci * 125d722e3fbSopenharmony_ci * This is an optional function, if missing, 126d722e3fbSopenharmony_ci * drm_intel_bo will map/memcpy/unmap. 127d722e3fbSopenharmony_ci */ 128d722e3fbSopenharmony_ci int (*bo_subdata) (drm_intel_bo *bo, unsigned long offset, 129d722e3fbSopenharmony_ci unsigned long size, const void *data); 130d722e3fbSopenharmony_ci 131d722e3fbSopenharmony_ci /** 132d722e3fbSopenharmony_ci * Read data from an object 133d722e3fbSopenharmony_ci * 134d722e3fbSopenharmony_ci * This is an optional function, if missing, 135d722e3fbSopenharmony_ci * drm_intel_bo will map/memcpy/unmap. 136d722e3fbSopenharmony_ci */ 137d722e3fbSopenharmony_ci int (*bo_get_subdata) (drm_intel_bo *bo, unsigned long offset, 138d722e3fbSopenharmony_ci unsigned long size, void *data); 139d722e3fbSopenharmony_ci 140d722e3fbSopenharmony_ci /** 141d722e3fbSopenharmony_ci * Waits for rendering to an object by the GPU to have completed. 142d722e3fbSopenharmony_ci * 143d722e3fbSopenharmony_ci * This is not required for any access to the BO by bo_map, 144d722e3fbSopenharmony_ci * bo_subdata, etc. It is merely a way for the driver to implement 145d722e3fbSopenharmony_ci * glFinish. 146d722e3fbSopenharmony_ci */ 147d722e3fbSopenharmony_ci void (*bo_wait_rendering) (drm_intel_bo *bo); 148d722e3fbSopenharmony_ci 149d722e3fbSopenharmony_ci /** 150d722e3fbSopenharmony_ci * Tears down the buffer manager instance. 151d722e3fbSopenharmony_ci */ 152d722e3fbSopenharmony_ci void (*destroy) (drm_intel_bufmgr *bufmgr); 153d722e3fbSopenharmony_ci 154d722e3fbSopenharmony_ci /** 155d722e3fbSopenharmony_ci * Indicate if the buffer can be placed anywhere in the full ppgtt 156d722e3fbSopenharmony_ci * address range (2^48). 157d722e3fbSopenharmony_ci * 158d722e3fbSopenharmony_ci * Any resource used with flat/heapless (0x00000000-0xfffff000) 159d722e3fbSopenharmony_ci * General State Heap (GSH) or Instructions State Heap (ISH) must 160d722e3fbSopenharmony_ci * be in a 32-bit range. 48-bit range will only be used when explicitly 161d722e3fbSopenharmony_ci * requested. 162d722e3fbSopenharmony_ci * 163d722e3fbSopenharmony_ci * \param bo Buffer to set the use_48b_address_range flag. 164d722e3fbSopenharmony_ci * \param enable The flag value. 165d722e3fbSopenharmony_ci */ 166d722e3fbSopenharmony_ci void (*bo_use_48b_address_range) (drm_intel_bo *bo, uint32_t enable); 167d722e3fbSopenharmony_ci 168d722e3fbSopenharmony_ci /** 169d722e3fbSopenharmony_ci * Add relocation entry in reloc_buf, which will be updated with the 170d722e3fbSopenharmony_ci * target buffer's real offset on on command submission. 171d722e3fbSopenharmony_ci * 172d722e3fbSopenharmony_ci * Relocations remain in place for the lifetime of the buffer object. 173d722e3fbSopenharmony_ci * 174d722e3fbSopenharmony_ci * \param bo Buffer to write the relocation into. 175d722e3fbSopenharmony_ci * \param offset Byte offset within reloc_bo of the pointer to 176d722e3fbSopenharmony_ci * target_bo. 177d722e3fbSopenharmony_ci * \param target_bo Buffer whose offset should be written into the 178d722e3fbSopenharmony_ci * relocation entry. 179d722e3fbSopenharmony_ci * \param target_offset Constant value to be added to target_bo's 180d722e3fbSopenharmony_ci * offset in relocation entry. 181d722e3fbSopenharmony_ci * \param read_domains GEM read domains which the buffer will be 182d722e3fbSopenharmony_ci * read into by the command that this relocation 183d722e3fbSopenharmony_ci * is part of. 184d722e3fbSopenharmony_ci * \param write_domains GEM read domains which the buffer will be 185d722e3fbSopenharmony_ci * dirtied in by the command that this 186d722e3fbSopenharmony_ci * relocation is part of. 187d722e3fbSopenharmony_ci */ 188d722e3fbSopenharmony_ci int (*bo_emit_reloc) (drm_intel_bo *bo, uint32_t offset, 189d722e3fbSopenharmony_ci drm_intel_bo *target_bo, uint32_t target_offset, 190d722e3fbSopenharmony_ci uint32_t read_domains, uint32_t write_domain); 191d722e3fbSopenharmony_ci int (*bo_emit_reloc_fence)(drm_intel_bo *bo, uint32_t offset, 192d722e3fbSopenharmony_ci drm_intel_bo *target_bo, 193d722e3fbSopenharmony_ci uint32_t target_offset, 194d722e3fbSopenharmony_ci uint32_t read_domains, 195d722e3fbSopenharmony_ci uint32_t write_domain); 196d722e3fbSopenharmony_ci 197d722e3fbSopenharmony_ci /** Executes the command buffer pointed to by bo. */ 198d722e3fbSopenharmony_ci int (*bo_exec) (drm_intel_bo *bo, int used, 199d722e3fbSopenharmony_ci drm_clip_rect_t *cliprects, int num_cliprects, 200d722e3fbSopenharmony_ci int DR4); 201d722e3fbSopenharmony_ci 202d722e3fbSopenharmony_ci /** Executes the command buffer pointed to by bo on the selected 203d722e3fbSopenharmony_ci * ring buffer 204d722e3fbSopenharmony_ci */ 205d722e3fbSopenharmony_ci int (*bo_mrb_exec) (drm_intel_bo *bo, int used, 206d722e3fbSopenharmony_ci drm_clip_rect_t *cliprects, int num_cliprects, 207d722e3fbSopenharmony_ci int DR4, unsigned flags); 208d722e3fbSopenharmony_ci 209d722e3fbSopenharmony_ci /** 210d722e3fbSopenharmony_ci * Pin a buffer to the aperture and fix the offset until unpinned 211d722e3fbSopenharmony_ci * 212d722e3fbSopenharmony_ci * \param buf Buffer to pin 213d722e3fbSopenharmony_ci * \param alignment Required alignment for aperture, in bytes 214d722e3fbSopenharmony_ci */ 215d722e3fbSopenharmony_ci int (*bo_pin) (drm_intel_bo *bo, uint32_t alignment); 216d722e3fbSopenharmony_ci 217d722e3fbSopenharmony_ci /** 218d722e3fbSopenharmony_ci * Unpin a buffer from the aperture, allowing it to be removed 219d722e3fbSopenharmony_ci * 220d722e3fbSopenharmony_ci * \param buf Buffer to unpin 221d722e3fbSopenharmony_ci */ 222d722e3fbSopenharmony_ci int (*bo_unpin) (drm_intel_bo *bo); 223d722e3fbSopenharmony_ci 224d722e3fbSopenharmony_ci /** 225d722e3fbSopenharmony_ci * Ask that the buffer be placed in tiling mode 226d722e3fbSopenharmony_ci * 227d722e3fbSopenharmony_ci * \param buf Buffer to set tiling mode for 228d722e3fbSopenharmony_ci * \param tiling_mode desired, and returned tiling mode 229d722e3fbSopenharmony_ci */ 230d722e3fbSopenharmony_ci int (*bo_set_tiling) (drm_intel_bo *bo, uint32_t * tiling_mode, 231d722e3fbSopenharmony_ci uint32_t stride); 232d722e3fbSopenharmony_ci 233d722e3fbSopenharmony_ci /** 234d722e3fbSopenharmony_ci * Get the current tiling (and resulting swizzling) mode for the bo. 235d722e3fbSopenharmony_ci * 236d722e3fbSopenharmony_ci * \param buf Buffer to get tiling mode for 237d722e3fbSopenharmony_ci * \param tiling_mode returned tiling mode 238d722e3fbSopenharmony_ci * \param swizzle_mode returned swizzling mode 239d722e3fbSopenharmony_ci */ 240d722e3fbSopenharmony_ci int (*bo_get_tiling) (drm_intel_bo *bo, uint32_t * tiling_mode, 241d722e3fbSopenharmony_ci uint32_t * swizzle_mode); 242d722e3fbSopenharmony_ci 243d722e3fbSopenharmony_ci /** 244d722e3fbSopenharmony_ci * Set the offset at which this buffer will be softpinned 245d722e3fbSopenharmony_ci * \param bo Buffer to set the softpin offset for 246d722e3fbSopenharmony_ci * \param offset Softpin offset 247d722e3fbSopenharmony_ci */ 248d722e3fbSopenharmony_ci int (*bo_set_softpin_offset) (drm_intel_bo *bo, uint64_t offset); 249d722e3fbSopenharmony_ci 250d722e3fbSopenharmony_ci /** 251d722e3fbSopenharmony_ci * Create a visible name for a buffer which can be used by other apps 252d722e3fbSopenharmony_ci * 253d722e3fbSopenharmony_ci * \param buf Buffer to create a name for 254d722e3fbSopenharmony_ci * \param name Returned name 255d722e3fbSopenharmony_ci */ 256d722e3fbSopenharmony_ci int (*bo_flink) (drm_intel_bo *bo, uint32_t * name); 257d722e3fbSopenharmony_ci 258d722e3fbSopenharmony_ci /** 259d722e3fbSopenharmony_ci * Returns 1 if mapping the buffer for write could cause the process 260d722e3fbSopenharmony_ci * to block, due to the object being active in the GPU. 261d722e3fbSopenharmony_ci */ 262d722e3fbSopenharmony_ci int (*bo_busy) (drm_intel_bo *bo); 263d722e3fbSopenharmony_ci 264d722e3fbSopenharmony_ci /** 265d722e3fbSopenharmony_ci * Specify the volatility of the buffer. 266d722e3fbSopenharmony_ci * \param bo Buffer to create a name for 267d722e3fbSopenharmony_ci * \param madv The purgeable status 268d722e3fbSopenharmony_ci * 269d722e3fbSopenharmony_ci * Use I915_MADV_DONTNEED to mark the buffer as purgeable, and it will be 270d722e3fbSopenharmony_ci * reclaimed under memory pressure. If you subsequently require the buffer, 271d722e3fbSopenharmony_ci * then you must pass I915_MADV_WILLNEED to mark the buffer as required. 272d722e3fbSopenharmony_ci * 273d722e3fbSopenharmony_ci * Returns 1 if the buffer was retained, or 0 if it was discarded whilst 274d722e3fbSopenharmony_ci * marked as I915_MADV_DONTNEED. 275d722e3fbSopenharmony_ci */ 276d722e3fbSopenharmony_ci int (*bo_madvise) (drm_intel_bo *bo, int madv); 277d722e3fbSopenharmony_ci 278d722e3fbSopenharmony_ci int (*check_aperture_space) (drm_intel_bo ** bo_array, int count); 279d722e3fbSopenharmony_ci 280d722e3fbSopenharmony_ci /** 281d722e3fbSopenharmony_ci * Disable buffer reuse for buffers which will be shared in some way, 282d722e3fbSopenharmony_ci * as with scanout buffers. When the buffer reference count goes to 283d722e3fbSopenharmony_ci * zero, it will be freed and not placed in the reuse list. 284d722e3fbSopenharmony_ci * 285d722e3fbSopenharmony_ci * \param bo Buffer to disable reuse for 286d722e3fbSopenharmony_ci */ 287d722e3fbSopenharmony_ci int (*bo_disable_reuse) (drm_intel_bo *bo); 288d722e3fbSopenharmony_ci 289d722e3fbSopenharmony_ci /** 290d722e3fbSopenharmony_ci * Query whether a buffer is reusable. 291d722e3fbSopenharmony_ci * 292d722e3fbSopenharmony_ci * \param bo Buffer to query 293d722e3fbSopenharmony_ci */ 294d722e3fbSopenharmony_ci int (*bo_is_reusable) (drm_intel_bo *bo); 295d722e3fbSopenharmony_ci 296d722e3fbSopenharmony_ci /** 297d722e3fbSopenharmony_ci * 298d722e3fbSopenharmony_ci * Return the pipe associated with a crtc_id so that vblank 299d722e3fbSopenharmony_ci * synchronization can use the correct data in the request. 300d722e3fbSopenharmony_ci * This is only supported for KMS and gem at this point, when 301d722e3fbSopenharmony_ci * unsupported, this function returns -1 and leaves the decision 302d722e3fbSopenharmony_ci * of what to do in that case to the caller 303d722e3fbSopenharmony_ci * 304d722e3fbSopenharmony_ci * \param bufmgr the associated buffer manager 305d722e3fbSopenharmony_ci * \param crtc_id the crtc identifier 306d722e3fbSopenharmony_ci */ 307d722e3fbSopenharmony_ci int (*get_pipe_from_crtc_id) (drm_intel_bufmgr *bufmgr, int crtc_id); 308d722e3fbSopenharmony_ci 309d722e3fbSopenharmony_ci /** Returns true if target_bo is in the relocation tree rooted at bo. */ 310d722e3fbSopenharmony_ci int (*bo_references) (drm_intel_bo *bo, drm_intel_bo *target_bo); 311d722e3fbSopenharmony_ci 312d722e3fbSopenharmony_ci /**< Enables verbose debugging printouts */ 313d722e3fbSopenharmony_ci int debug; 314d722e3fbSopenharmony_ci}; 315d722e3fbSopenharmony_ci 316d722e3fbSopenharmony_cistruct _drm_intel_context { 317d722e3fbSopenharmony_ci unsigned int ctx_id; 318d722e3fbSopenharmony_ci struct _drm_intel_bufmgr *bufmgr; 319d722e3fbSopenharmony_ci}; 320d722e3fbSopenharmony_ci 321d722e3fbSopenharmony_ci#define ALIGN(value, alignment) ((value + alignment - 1) & ~(alignment - 1)) 322d722e3fbSopenharmony_ci#define ROUND_UP_TO(x, y) (((x) + (y) - 1) / (y) * (y)) 323d722e3fbSopenharmony_ci#define ROUND_UP_TO_MB(x) ROUND_UP_TO((x), 1024*1024) 324d722e3fbSopenharmony_ci 325d722e3fbSopenharmony_ci#endif /* INTEL_BUFMGR_PRIV_H */ 326