1 /*
2 * Copyright © 2008 Dave Airlie
3 * Copyright © 2008 Jérôme Glisse
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
18 * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * The above copyright notice and this permission notice (including the
24 * next paragraph) shall be included in all copies or substantial portions
25 * of the Software.
26 */
27 /*
28 * Authors:
29 * Dave Airlie
30 * Jérôme Glisse <glisse@freedesktop.org>
31 */
32 #include <libdrm_macros.h>
33 #include <radeon_bo.h>
34 #include <radeon_bo_int.h>
35
radeon_bo_debug(struct radeon_bo * bo,const char * op)36 void radeon_bo_debug(struct radeon_bo *bo, const char *op)
37 {
38 struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
39
40 fprintf(stderr, "%s %p 0x%08X 0x%08X 0x%08X\n",
41 op, bo, bo->handle, boi->size, boi->cref);
42 }
43
44 struct radeon_bo *
radeon_bo_open(struct radeon_bo_manager * bom,uint32_t handle,uint32_t size,uint32_t alignment,uint32_t domains,uint32_t flags)45 radeon_bo_open(struct radeon_bo_manager *bom, uint32_t handle, uint32_t size,
46 uint32_t alignment, uint32_t domains, uint32_t flags)
47 {
48 struct radeon_bo *bo;
49 bo = bom->funcs->bo_open(bom, handle, size, alignment, domains, flags);
50 return bo;
51 }
52
radeon_bo_ref(struct radeon_bo * bo)53 void radeon_bo_ref(struct radeon_bo *bo)
54 {
55 struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
56 boi->cref++;
57 boi->bom->funcs->bo_ref(boi);
58 }
59
radeon_bo_unref(struct radeon_bo * bo)60 struct radeon_bo *radeon_bo_unref(struct radeon_bo *bo)
61 {
62 struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
63 if (bo == NULL)
64 return NULL;
65
66 boi->cref--;
67 return boi->bom->funcs->bo_unref(boi);
68 }
69
radeon_bo_map(struct radeon_bo * bo,int write)70 int radeon_bo_map(struct radeon_bo *bo, int write)
71 {
72 struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
73 return boi->bom->funcs->bo_map(boi, write);
74 }
75
radeon_bo_unmap(struct radeon_bo * bo)76 int radeon_bo_unmap(struct radeon_bo *bo)
77 {
78 struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
79 return boi->bom->funcs->bo_unmap(boi);
80 }
81
radeon_bo_wait(struct radeon_bo * bo)82 int radeon_bo_wait(struct radeon_bo *bo)
83 {
84 struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
85 if (!boi->bom->funcs->bo_wait)
86 return 0;
87 return boi->bom->funcs->bo_wait(boi);
88 }
89
radeon_bo_is_busy(struct radeon_bo * bo,uint32_t * domain)90 int radeon_bo_is_busy(struct radeon_bo *bo, uint32_t *domain)
91 {
92 struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
93 return boi->bom->funcs->bo_is_busy(boi, domain);
94 }
95
96 int
radeon_bo_set_tiling(struct radeon_bo * bo,uint32_t tiling_flags,uint32_t pitch)97 radeon_bo_set_tiling(struct radeon_bo *bo,
98 uint32_t tiling_flags, uint32_t pitch)
99 {
100 struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
101 return boi->bom->funcs->bo_set_tiling(boi, tiling_flags, pitch);
102 }
103
104 int
radeon_bo_get_tiling(struct radeon_bo * bo,uint32_t * tiling_flags,uint32_t * pitch)105 radeon_bo_get_tiling(struct radeon_bo *bo,
106 uint32_t *tiling_flags, uint32_t *pitch)
107 {
108 struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
109 return boi->bom->funcs->bo_get_tiling(boi, tiling_flags, pitch);
110 }
111
radeon_bo_is_static(struct radeon_bo * bo)112 int radeon_bo_is_static(struct radeon_bo *bo)
113 {
114 struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
115 if (boi->bom->funcs->bo_is_static)
116 return boi->bom->funcs->bo_is_static(boi);
117 return 0;
118 }
119
120 int
radeon_bo_is_referenced_by_cs(struct radeon_bo * bo,struct radeon_cs * cs)121 radeon_bo_is_referenced_by_cs(struct radeon_bo *bo, struct radeon_cs *cs)
122 {
123 struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
124 return boi->cref > 1;
125 }
126
radeon_bo_get_handle(struct radeon_bo * bo)127 uint32_t radeon_bo_get_handle(struct radeon_bo *bo)
128 {
129 return bo->handle;
130 }
131
radeon_bo_get_src_domain(struct radeon_bo * bo)132 uint32_t radeon_bo_get_src_domain(struct radeon_bo *bo)
133 {
134 struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
135 uint32_t src_domain;
136
137 src_domain = boi->space_accounted & 0xffff;
138 if (!src_domain)
139 src_domain = boi->space_accounted >> 16;
140
141 return src_domain;
142 }
143