amdgpu_bo_helper.h revision 24b90cf4
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 void amdgpu_pixmap_clear(PixmapPtr pixmap);
33
34extern Bool amdgpu_bo_get_handle(struct amdgpu_buffer *bo, uint32_t *handle);
35
36extern uint64_t amdgpu_pixmap_get_tiling_info(PixmapPtr pixmap);
37
38extern Bool amdgpu_pixmap_get_handle(PixmapPtr pixmap, uint32_t *handle);
39
40extern int amdgpu_bo_map(ScrnInfoPtr pScrn, struct amdgpu_buffer *bo);
41
42extern void amdgpu_bo_unmap(struct amdgpu_buffer *bo);
43
44extern Bool
45amdgpu_set_shared_pixmap_backing(PixmapPtr ppix, void *fd_handle);
46
47/* helper function to allocate memory to be used for GPU operations
48 *
49 * \param	pDev		- \c [in] device handle
50 * \param	alloc_size	- \c [in] allocation size
51 * \param	phys_alignment	- \c [in] requested alignment. 0 means no alignment requirement
52 * \param	domains		- \c [in] GEM domains
53 *
54 * \return	pointer to amdgpu_buffer on success
55 *		NULL on failure
56*/
57extern struct amdgpu_buffer *amdgpu_bo_open(amdgpu_device_handle pDev,
58					      uint32_t alloc_size,
59					      uint32_t phys_alignment,
60					      uint32_t domains);
61
62/* helper function to add the ref_count of a amdgpu_buffer
63 * \param	buffer	- \c [in] amdgpu_buffer
64*/
65extern void amdgpu_bo_ref(struct amdgpu_buffer *buffer);
66
67/* helper function to dec the ref_count of a amdgpu_buffer
68 * \param	buffer	- \c [in] amdgpu_buffer
69*/
70extern void amdgpu_bo_unref(struct amdgpu_buffer **buffer);
71
72/* helper function to query the buffer size
73 * \param	buf_handle	- \c [in] amdgpu bo handle
74 * \param	size		- \c [out] pointer to buffer size
75 *
76 * \return	0 on success
77		>0 - AMD specific error code \n
78		<0 - Negative POSIX error code
79*/
80int amdgpu_query_bo_size(amdgpu_bo_handle buf_handle, uint32_t *size);
81
82/* helper function to query the heap information
83 * \param	pDev		- \c [in] amdgpu device handle
84 * \param 	heap		- \c [in] heap type
85 * \param	heap_size	- \c [out] theoretical max available memory
86 * \param	max_allcoation	- \c [out] theoretical possible max. size of buffer
87 *
88 * \return 	0 on success
89		>0 - AMD specific error code \n
90		<0 - Negative POSIX error code
91*/
92int amdgpu_query_heap_size(amdgpu_device_handle pDev,
93                            uint32_t heap,
94                            uint64_t *heap_size,
95                            uint64_t *max_allocation);
96
97/* helper function to convert a DMA buf handle to a KMS handle
98 * \param	pDev		- \c [in] amdgpu device handle
99 * \param	fd_handle 	- \c [in] dma-buf fd handle
100 * \size	size		- \c [in] buffer size
101 *
102 * \return	pointer to amdgpu_buffer on success
103		NULL on failure
104*/
105struct amdgpu_buffer *amdgpu_gem_bo_open_prime(amdgpu_device_handle pDev,
106                                                 int fd_handle,
107                                                 uint32_t size);
108
109/**
110 * get_drawable_pixmap() returns the backing pixmap for a given drawable.
111 *
112 * @param drawable the drawable being requested.
113 *
114 * This function returns the backing pixmap for a drawable, whether it is a
115 * redirected window, unredirected window, or already a pixmap.
116 */
117static inline PixmapPtr get_drawable_pixmap(DrawablePtr drawable)
118{
119	if (drawable->type == DRAWABLE_PIXMAP)
120		return (PixmapPtr)drawable;
121	else
122		return drawable->pScreen->GetWindowPixmap((WindowPtr)drawable);
123}
124
125#endif /* AMDGPU_BO_HELPER_H */
126