amdgpu_bo_helper.h revision 504d986f
1/* 2 * Copyright 2012 Advanced Micro Devices, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 23#ifndef AMDGPU_BO_HELPER_H 24#define AMDGPU_BO_HELPER_H 1 25 26#include "amdgpu_drv.h" 27 28extern struct amdgpu_buffer *amdgpu_alloc_pixmap_bo(ScrnInfoPtr pScrn, int width, 29 int height, int depth, int usage_hint, 30 int bitsPerPixel, int *new_pitch); 31 32extern Bool amdgpu_bo_get_handle(struct amdgpu_buffer *bo, uint32_t *handle); 33 34extern uint64_t amdgpu_pixmap_get_tiling_info(PixmapPtr pixmap); 35 36extern Bool amdgpu_pixmap_get_handle(PixmapPtr pixmap, uint32_t *handle); 37 38extern int amdgpu_bo_map(ScrnInfoPtr pScrn, struct amdgpu_buffer *bo); 39 40extern void amdgpu_bo_unmap(struct amdgpu_buffer *bo); 41 42extern Bool 43amdgpu_set_shared_pixmap_backing(PixmapPtr ppix, void *fd_handle); 44 45/* helper function to allocate memory to be used for GPU operations 46 * 47 * \param pDev - \c [in] device handle 48 * \param alloc_size - \c [in] allocation size 49 * \param phys_alignment - \c [in] requested alignment. 0 means no alignment requirement 50 * \param domains - \c [in] GEM domains 51 * 52 * \return pointer to amdgpu_buffer on success 53 * NULL on failure 54*/ 55extern struct amdgpu_buffer *amdgpu_bo_open(amdgpu_device_handle pDev, 56 uint32_t alloc_size, 57 uint32_t phys_alignment, 58 uint32_t domains); 59 60/* helper function to add the ref_count of a amdgpu_buffer 61 * \param buffer - \c [in] amdgpu_buffer 62*/ 63extern void amdgpu_bo_ref(struct amdgpu_buffer *buffer); 64 65/* helper function to dec the ref_count of a amdgpu_buffer 66 * \param buffer - \c [in] amdgpu_buffer 67*/ 68extern void amdgpu_bo_unref(struct amdgpu_buffer **buffer); 69 70/* helper function to query the buffer size 71 * \param buf_handle - \c [in] amdgpu bo handle 72 * \param size - \c [out] pointer to buffer size 73 * 74 * \return 0 on success 75 >0 - AMD specific error code \n 76 <0 - Negative POSIX error code 77*/ 78int amdgpu_query_bo_size(amdgpu_bo_handle buf_handle, uint32_t *size); 79 80/* helper function to query the heap information 81 * \param pDev - \c [in] amdgpu device handle 82 * \param heap - \c [in] heap type 83 * \param heap_size - \c [out] theoretical max available memory 84 * \param max_allcoation - \c [out] theoretical possible max. size of buffer 85 * 86 * \return 0 on success 87 >0 - AMD specific error code \n 88 <0 - Negative POSIX error code 89*/ 90int amdgpu_query_heap_size(amdgpu_device_handle pDev, 91 uint32_t heap, 92 uint64_t *heap_size, 93 uint64_t *max_allocation); 94 95/* helper function to convert a DMA buf handle to a KMS handle 96 * \param pDev - \c [in] amdgpu device handle 97 * \param fd_handle - \c [in] dma-buf fd handle 98 * \size size - \c [in] buffer size 99 * 100 * \return pointer to amdgpu_buffer on success 101 NULL on failure 102*/ 103struct amdgpu_buffer *amdgpu_gem_bo_open_prime(amdgpu_device_handle pDev, 104 int fd_handle, 105 uint32_t size); 106 107/** 108 * get_drawable_pixmap() returns the backing pixmap for a given drawable. 109 * 110 * @param drawable the drawable being requested. 111 * 112 * This function returns the backing pixmap for a drawable, whether it is a 113 * redirected window, unredirected window, or already a pixmap. 114 */ 115static inline PixmapPtr get_drawable_pixmap(DrawablePtr drawable) 116{ 117 if (drawable->type == DRAWABLE_PIXMAP) 118 return (PixmapPtr)drawable; 119 else 120 return drawable->pScreen->GetWindowPixmap((WindowPtr)drawable); 121} 122 123#endif /* AMDGPU_BO_HELPER_H */ 124