2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #define _FILE_OFFSET_BITS 64
27 #include "r600_priv.h"
28 #include "util/u_hash_table.h"
29 #include "util/u_memory.h"
30 #include "radeon_drm.h"
35 int radeon_bo_fixed_map(struct radeon
*radeon
, struct radeon_bo
*bo
)
37 struct drm_radeon_gem_mmap args
;
41 /* Zero out args to make valgrind happy */
42 memset(&args
, 0, sizeof(args
));
43 args
.handle
= bo
->handle
;
45 args
.size
= (uint64_t)bo
->size
;
46 r
= drmCommandWriteRead(radeon
->info
.fd
, DRM_RADEON_GEM_MMAP
,
49 fprintf(stderr
, "error mapping %p 0x%08X (error = %d)\n",
53 ptr
= mmap(0, args
.size
, PROT_READ
|PROT_WRITE
, MAP_SHARED
, radeon
->info
.fd
, args
.addr_ptr
);
54 if (ptr
== MAP_FAILED
) {
55 fprintf(stderr
, "%s failed to map bo\n", __func__
);
64 static void radeon_bo_fixed_unmap(struct radeon
*radeon
, struct radeon_bo
*bo
)
67 munmap(bo
->data
, bo
->size
);
72 #include "state_tracker/drm_driver.h"
74 struct radeon_bo
*radeon_bo(struct radeon
*radeon
, unsigned handle
,
75 unsigned size
, unsigned alignment
, unsigned bind
,
76 unsigned initial_domain
)
79 struct winsys_handle whandle
= {};
80 whandle
.handle
= handle
;
82 bo
= calloc(1, sizeof(*bo
));
86 pipe_reference_init(&bo
->reference
, 1);
89 bo
->buf
= radeon
->ws
->buffer_from_handle(radeon
->ws
, &whandle
, NULL
, &size
);
91 bo
->buf
= radeon
->ws
->buffer_create(radeon
->ws
, size
, alignment
, bind
, initial_domain
);
97 bo
->cs_buf
= radeon
->ws
->buffer_get_cs_handle(bo
->buf
);
98 bo
->handle
= radeon
->ws
->trans_get_buffer_handle(bo
->buf
);
103 static void radeon_bo_destroy(struct radeon
*radeon
, struct radeon_bo
*bo
)
105 radeon_bo_fixed_unmap(radeon
, bo
);
106 pb_reference(&bo
->buf
, NULL
);
110 void radeon_bo_reference(struct radeon
*radeon
,
111 struct radeon_bo
**dst
,
112 struct radeon_bo
*src
)
114 struct radeon_bo
*old
= *dst
;
115 if (pipe_reference(&(*dst
)->reference
, &src
->reference
)) {
116 radeon_bo_destroy(radeon
, old
);
121 int radeon_bo_wait(struct radeon
*radeon
, struct radeon_bo
*bo
)
123 struct drm_radeon_gem_wait_idle args
;
126 /* Zero out args to make valgrind happy */
127 memset(&args
, 0, sizeof(args
));
128 args
.handle
= bo
->handle
;
130 ret
= drmCommandWriteRead(radeon
->info
.fd
, DRM_RADEON_GEM_WAIT_IDLE
,
131 &args
, sizeof(args
));
132 } while (ret
== -EBUSY
);
136 int radeon_bo_busy(struct radeon
*radeon
, struct radeon_bo
*bo
, uint32_t *domain
)
138 struct drm_radeon_gem_busy args
;
141 memset(&args
, 0, sizeof(args
));
142 args
.handle
= bo
->handle
;
145 ret
= drmCommandWriteRead(radeon
->info
.fd
, DRM_RADEON_GEM_BUSY
,
146 &args
, sizeof(args
));
148 *domain
= args
.domain
;
152 int radeon_bo_get_tiling_flags(struct radeon
*radeon
,
153 struct radeon_bo
*bo
,
154 uint32_t *tiling_flags
)
156 struct drm_radeon_gem_get_tiling args
= {};
159 args
.handle
= bo
->handle
;
160 ret
= drmCommandWriteRead(radeon
->info
.fd
, DRM_RADEON_GEM_GET_TILING
,
161 &args
, sizeof(args
));
165 *tiling_flags
= args
.tiling_flags
;
169 int radeon_bo_get_name(struct radeon
*radeon
,
170 struct radeon_bo
*bo
,
173 struct drm_gem_flink flink
;
176 flink
.handle
= bo
->handle
;
177 ret
= drmIoctl(radeon
->info
.fd
, DRM_IOCTL_GEM_FLINK
, &flink
);