gallium: Use C11 thread abstractions.
[mesa.git] / src / gallium / winsys / radeon / drm / radeon_drm_winsys.c
1 /*
2 * Copyright © 2009 Corbin Simpson
3 * Copyright © 2011 Marek Olšák <maraeo@gmail.com>
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 * Corbin Simpson <MostAwesomeDude@gmail.com>
30 * Joakim Sindholt <opensource@zhasha.com>
31 * Marek Olšák <maraeo@gmail.com>
32 */
33
34 #include "radeon_drm_bo.h"
35 #include "radeon_drm_cs.h"
36 #include "radeon_drm_public.h"
37
38 #include "pipebuffer/pb_bufmgr.h"
39 #include "util/u_memory.h"
40 #include "util/u_hash_table.h"
41
42 #include <xf86drm.h>
43 #include <stdio.h>
44 #include <sys/types.h>
45 #include <sys/stat.h>
46 #include <unistd.h>
47
48 /*
49 * this are copy from radeon_drm, once an updated libdrm is released
50 * we should bump configure.ac requirement for it and remove the following
51 * field
52 */
53 #ifndef RADEON_INFO_TILING_CONFIG
54 #define RADEON_INFO_TILING_CONFIG 6
55 #endif
56
57 #ifndef RADEON_INFO_WANT_HYPERZ
58 #define RADEON_INFO_WANT_HYPERZ 7
59 #endif
60
61 #ifndef RADEON_INFO_WANT_CMASK
62 #define RADEON_INFO_WANT_CMASK 8
63 #endif
64
65 #ifndef RADEON_INFO_CLOCK_CRYSTAL_FREQ
66 #define RADEON_INFO_CLOCK_CRYSTAL_FREQ 9
67 #endif
68
69 #ifndef RADEON_INFO_NUM_BACKENDS
70 #define RADEON_INFO_NUM_BACKENDS 0xa
71 #endif
72
73 #ifndef RADEON_INFO_NUM_TILE_PIPES
74 #define RADEON_INFO_NUM_TILE_PIPES 0xb
75 #endif
76
77 #ifndef RADEON_INFO_BACKEND_MAP
78 #define RADEON_INFO_BACKEND_MAP 0xd
79 #endif
80
81 #ifndef RADEON_INFO_VA_START
82 /* virtual address start, va < start are reserved by the kernel */
83 #define RADEON_INFO_VA_START 0x0e
84 /* maximum size of ib using the virtual memory cs */
85 #define RADEON_INFO_IB_VM_MAX_SIZE 0x0f
86 #endif
87
88 #ifndef RADEON_INFO_MAX_PIPES
89 #define RADEON_INFO_MAX_PIPES 0x10
90 #endif
91
92 #ifndef RADEON_INFO_TIMESTAMP
93 #define RADEON_INFO_TIMESTAMP 0x11
94 #endif
95
96 #ifndef RADEON_INFO_RING_WORKING
97 #define RADEON_INFO_RING_WORKING 0x15
98 #endif
99
100 #ifndef RADEON_CS_RING_UVD
101 #define RADEON_CS_RING_UVD 3
102 #endif
103
104 static struct util_hash_table *fd_tab = NULL;
105
106 /* Enable/disable feature access for one command stream.
107 * If enable == TRUE, return TRUE on success.
108 * Otherwise, return FALSE.
109 *
110 * We basically do the same thing kernel does, because we have to deal
111 * with multiple contexts (here command streams) backed by one winsys. */
112 static boolean radeon_set_fd_access(struct radeon_drm_cs *applier,
113 struct radeon_drm_cs **owner,
114 pipe_mutex *mutex,
115 unsigned request, const char *request_name,
116 boolean enable)
117 {
118 struct drm_radeon_info info;
119 unsigned value = enable ? 1 : 0;
120
121 memset(&info, 0, sizeof(info));
122
123 pipe_mutex_lock(*mutex);
124
125 /* Early exit if we are sure the request will fail. */
126 if (enable) {
127 if (*owner) {
128 pipe_mutex_unlock(*mutex);
129 return FALSE;
130 }
131 } else {
132 if (*owner != applier) {
133 pipe_mutex_unlock(*mutex);
134 return FALSE;
135 }
136 }
137
138 /* Pass through the request to the kernel. */
139 info.value = (unsigned long)&value;
140 info.request = request;
141 if (drmCommandWriteRead(applier->ws->fd, DRM_RADEON_INFO,
142 &info, sizeof(info)) != 0) {
143 pipe_mutex_unlock(*mutex);
144 return FALSE;
145 }
146
147 /* Update the rights in the winsys. */
148 if (enable) {
149 if (value) {
150 *owner = applier;
151 printf("radeon: Acquired access to %s.\n", request_name);
152 pipe_mutex_unlock(*mutex);
153 return TRUE;
154 }
155 } else {
156 *owner = NULL;
157 printf("radeon: Released access to %s.\n", request_name);
158 }
159
160 pipe_mutex_unlock(*mutex);
161 return FALSE;
162 }
163
164 static boolean radeon_get_drm_value(int fd, unsigned request,
165 const char *errname, uint32_t *out)
166 {
167 struct drm_radeon_info info;
168 int retval;
169
170 memset(&info, 0, sizeof(info));
171
172 info.value = (unsigned long)out;
173 info.request = request;
174
175 retval = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info));
176 if (retval) {
177 if (errname) {
178 fprintf(stderr, "radeon: Failed to get %s, error number %d\n",
179 errname, retval);
180 }
181 return FALSE;
182 }
183 return TRUE;
184 }
185
186 /* Helper function to do the ioctls needed for setup and init. */
187 static boolean do_winsys_init(struct radeon_drm_winsys *ws)
188 {
189 struct drm_radeon_gem_info gem_info;
190 int retval;
191 drmVersionPtr version;
192
193 memset(&gem_info, 0, sizeof(gem_info));
194
195 /* We do things in a specific order here.
196 *
197 * DRM version first. We need to be sure we're running on a KMS chipset.
198 * This is also for some features.
199 *
200 * Then, the PCI ID. This is essential and should return usable numbers
201 * for all Radeons. If this fails, we probably got handed an FD for some
202 * non-Radeon card.
203 *
204 * The GEM info is actually bogus on the kernel side, as well as our side
205 * (see radeon_gem_info_ioctl in radeon_gem.c) but that's alright because
206 * we don't actually use the info for anything yet.
207 *
208 * The GB and Z pipe requests should always succeed, but they might not
209 * return sensical values for all chipsets, but that's alright because
210 * the pipe drivers already know that.
211 */
212
213 /* Get DRM version. */
214 version = drmGetVersion(ws->fd);
215 if (version->version_major != 2 ||
216 version->version_minor < 3) {
217 fprintf(stderr, "%s: DRM version is %d.%d.%d but this driver is "
218 "only compatible with 2.3.x (kernel 2.6.34) or later.\n",
219 __FUNCTION__,
220 version->version_major,
221 version->version_minor,
222 version->version_patchlevel);
223 drmFreeVersion(version);
224 return FALSE;
225 }
226
227 ws->info.drm_major = version->version_major;
228 ws->info.drm_minor = version->version_minor;
229 ws->info.drm_patchlevel = version->version_patchlevel;
230 drmFreeVersion(version);
231
232 /* Get PCI ID. */
233 if (!radeon_get_drm_value(ws->fd, RADEON_INFO_DEVICE_ID, "PCI ID",
234 &ws->info.pci_id))
235 return FALSE;
236
237 /* Check PCI ID. */
238 switch (ws->info.pci_id) {
239 #define CHIPSET(pci_id, name, cfamily) case pci_id: ws->info.family = CHIP_##cfamily; ws->gen = DRV_R300; break;
240 #include "pci_ids/r300_pci_ids.h"
241 #undef CHIPSET
242
243 #define CHIPSET(pci_id, name, cfamily) case pci_id: ws->info.family = CHIP_##cfamily; ws->gen = DRV_R600; break;
244 #include "pci_ids/r600_pci_ids.h"
245 #undef CHIPSET
246
247 #define CHIPSET(pci_id, name, cfamily) case pci_id: ws->info.family = CHIP_##cfamily; ws->gen = DRV_SI; break;
248 #include "pci_ids/radeonsi_pci_ids.h"
249 #undef CHIPSET
250
251 default:
252 fprintf(stderr, "radeon: Invalid PCI ID.\n");
253 return FALSE;
254 }
255
256 switch (ws->info.family) {
257 default:
258 case CHIP_UNKNOWN:
259 fprintf(stderr, "radeon: Unknown family.\n");
260 return FALSE;
261 case CHIP_R300:
262 case CHIP_R350:
263 case CHIP_RV350:
264 case CHIP_RV370:
265 case CHIP_RV380:
266 case CHIP_RS400:
267 case CHIP_RC410:
268 case CHIP_RS480:
269 ws->info.chip_class = R300;
270 break;
271 case CHIP_R420: /* R4xx-based cores. */
272 case CHIP_R423:
273 case CHIP_R430:
274 case CHIP_R480:
275 case CHIP_R481:
276 case CHIP_RV410:
277 case CHIP_RS600:
278 case CHIP_RS690:
279 case CHIP_RS740:
280 ws->info.chip_class = R400;
281 break;
282 case CHIP_RV515: /* R5xx-based cores. */
283 case CHIP_R520:
284 case CHIP_RV530:
285 case CHIP_R580:
286 case CHIP_RV560:
287 case CHIP_RV570:
288 ws->info.chip_class = R500;
289 break;
290 case CHIP_R600:
291 case CHIP_RV610:
292 case CHIP_RV630:
293 case CHIP_RV670:
294 case CHIP_RV620:
295 case CHIP_RV635:
296 case CHIP_RS780:
297 case CHIP_RS880:
298 ws->info.chip_class = R600;
299 break;
300 case CHIP_RV770:
301 case CHIP_RV730:
302 case CHIP_RV710:
303 case CHIP_RV740:
304 ws->info.chip_class = R700;
305 break;
306 case CHIP_CEDAR:
307 case CHIP_REDWOOD:
308 case CHIP_JUNIPER:
309 case CHIP_CYPRESS:
310 case CHIP_HEMLOCK:
311 case CHIP_PALM:
312 case CHIP_SUMO:
313 case CHIP_SUMO2:
314 case CHIP_BARTS:
315 case CHIP_TURKS:
316 case CHIP_CAICOS:
317 ws->info.chip_class = EVERGREEN;
318 break;
319 case CHIP_CAYMAN:
320 case CHIP_ARUBA:
321 ws->info.chip_class = CAYMAN;
322 break;
323 case CHIP_TAHITI:
324 case CHIP_PITCAIRN:
325 case CHIP_VERDE:
326 case CHIP_OLAND:
327 case CHIP_HAINAN:
328 ws->info.chip_class = SI;
329 break;
330 case CHIP_BONAIRE:
331 case CHIP_KAVERI:
332 case CHIP_KABINI:
333 case CHIP_HAWAII:
334 ws->info.chip_class = CIK;
335 break;
336 }
337
338 /* Check for dma */
339 ws->info.r600_has_dma = FALSE;
340 if (ws->info.chip_class >= R700 && ws->info.drm_minor >= 27) {
341 ws->info.r600_has_dma = TRUE;
342 }
343
344 /* Check for UVD */
345 ws->info.has_uvd = FALSE;
346 if (ws->info.drm_minor >= 32) {
347 uint32_t value = RADEON_CS_RING_UVD;
348 if (radeon_get_drm_value(ws->fd, RADEON_INFO_RING_WORKING,
349 "UVD Ring working", &value))
350 ws->info.has_uvd = value;
351 }
352
353 /* Get GEM info. */
354 retval = drmCommandWriteRead(ws->fd, DRM_RADEON_GEM_INFO,
355 &gem_info, sizeof(gem_info));
356 if (retval) {
357 fprintf(stderr, "radeon: Failed to get MM info, error number %d\n",
358 retval);
359 return FALSE;
360 }
361 ws->info.gart_size = gem_info.gart_size;
362 ws->info.vram_size = gem_info.vram_size;
363
364 ws->num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
365
366 /* Generation-specific queries. */
367 if (ws->gen == DRV_R300) {
368 if (!radeon_get_drm_value(ws->fd, RADEON_INFO_NUM_GB_PIPES,
369 "GB pipe count",
370 &ws->info.r300_num_gb_pipes))
371 return FALSE;
372
373 if (!radeon_get_drm_value(ws->fd, RADEON_INFO_NUM_Z_PIPES,
374 "Z pipe count",
375 &ws->info.r300_num_z_pipes))
376 return FALSE;
377 }
378 else if (ws->gen >= DRV_R600) {
379 if (ws->info.drm_minor >= 9 &&
380 !radeon_get_drm_value(ws->fd, RADEON_INFO_NUM_BACKENDS,
381 "num backends",
382 &ws->info.r600_num_backends))
383 return FALSE;
384
385 /* get the GPU counter frequency, failure is not fatal */
386 radeon_get_drm_value(ws->fd, RADEON_INFO_CLOCK_CRYSTAL_FREQ, NULL,
387 &ws->info.r600_clock_crystal_freq);
388
389 radeon_get_drm_value(ws->fd, RADEON_INFO_TILING_CONFIG, NULL,
390 &ws->info.r600_tiling_config);
391
392 if (ws->info.drm_minor >= 11) {
393 radeon_get_drm_value(ws->fd, RADEON_INFO_NUM_TILE_PIPES, NULL,
394 &ws->info.r600_num_tile_pipes);
395
396 if (radeon_get_drm_value(ws->fd, RADEON_INFO_BACKEND_MAP, NULL,
397 &ws->info.r600_backend_map))
398 ws->info.r600_backend_map_valid = TRUE;
399 }
400
401 ws->info.r600_virtual_address = FALSE;
402 if (ws->info.drm_minor >= 13) {
403 ws->info.r600_virtual_address = TRUE;
404 if (!radeon_get_drm_value(ws->fd, RADEON_INFO_VA_START, NULL,
405 &ws->info.r600_va_start))
406 ws->info.r600_virtual_address = FALSE;
407 if (!radeon_get_drm_value(ws->fd, RADEON_INFO_IB_VM_MAX_SIZE, NULL,
408 &ws->info.r600_ib_vm_max_size))
409 ws->info.r600_virtual_address = FALSE;
410 }
411 if (ws->gen == DRV_R600 && !debug_get_bool_option("RADEON_VA", FALSE))
412 ws->info.r600_virtual_address = FALSE;
413 }
414
415 /* Get max pipes, this is only needed for compute shaders. All evergreen+
416 * chips have at least 2 pipes, so we use 2 as a default. */
417 ws->info.r600_max_pipes = 2;
418 radeon_get_drm_value(ws->fd, RADEON_INFO_MAX_PIPES, NULL,
419 &ws->info.r600_max_pipes);
420
421 if (radeon_get_drm_value(ws->fd, RADEON_INFO_SI_TILE_MODE_ARRAY, NULL,
422 ws->info.si_tile_mode_array)) {
423 ws->info.si_tile_mode_array_valid = TRUE;
424 }
425
426 if (radeon_get_drm_value(ws->fd, RADEON_INFO_CIK_MACROTILE_MODE_ARRAY, NULL,
427 ws->info.cik_macrotile_mode_array)) {
428 ws->info.cik_macrotile_mode_array_valid = TRUE;
429 }
430
431 return TRUE;
432 }
433
434 static void radeon_winsys_destroy(struct radeon_winsys *rws)
435 {
436 struct radeon_drm_winsys *ws = (struct radeon_drm_winsys*)rws;
437
438 if (ws->thread) {
439 ws->kill_thread = 1;
440 pipe_semaphore_signal(&ws->cs_queued);
441 pipe_thread_wait(ws->thread);
442 }
443 pipe_semaphore_destroy(&ws->cs_queued);
444
445 pipe_mutex_destroy(ws->hyperz_owner_mutex);
446 pipe_mutex_destroy(ws->cmask_owner_mutex);
447 pipe_mutex_destroy(ws->cs_stack_lock);
448
449 ws->cman->destroy(ws->cman);
450 ws->kman->destroy(ws->kman);
451 if (ws->gen >= DRV_R600) {
452 radeon_surface_manager_free(ws->surf_man);
453 }
454 if (fd_tab) {
455 util_hash_table_remove(fd_tab, intptr_to_pointer(ws->fd));
456 }
457 FREE(rws);
458 }
459
460 static void radeon_query_info(struct radeon_winsys *rws,
461 struct radeon_info *info)
462 {
463 *info = ((struct radeon_drm_winsys *)rws)->info;
464 }
465
466 static boolean radeon_cs_request_feature(struct radeon_winsys_cs *rcs,
467 enum radeon_feature_id fid,
468 boolean enable)
469 {
470 struct radeon_drm_cs *cs = radeon_drm_cs(rcs);
471
472 switch (fid) {
473 case RADEON_FID_R300_HYPERZ_ACCESS:
474 return radeon_set_fd_access(cs, &cs->ws->hyperz_owner,
475 &cs->ws->hyperz_owner_mutex,
476 RADEON_INFO_WANT_HYPERZ, "Hyper-Z",
477 enable);
478
479 case RADEON_FID_R300_CMASK_ACCESS:
480 return radeon_set_fd_access(cs, &cs->ws->cmask_owner,
481 &cs->ws->cmask_owner_mutex,
482 RADEON_INFO_WANT_CMASK, "AA optimizations",
483 enable);
484 }
485 return FALSE;
486 }
487
488 static int radeon_drm_winsys_surface_init(struct radeon_winsys *rws,
489 struct radeon_surface *surf)
490 {
491 struct radeon_drm_winsys *ws = (struct radeon_drm_winsys*)rws;
492
493 return radeon_surface_init(ws->surf_man, surf);
494 }
495
496 static int radeon_drm_winsys_surface_best(struct radeon_winsys *rws,
497 struct radeon_surface *surf)
498 {
499 struct radeon_drm_winsys *ws = (struct radeon_drm_winsys*)rws;
500
501 return radeon_surface_best(ws->surf_man, surf);
502 }
503
504 static uint64_t radeon_query_value(struct radeon_winsys *rws,
505 enum radeon_value_id value)
506 {
507 struct radeon_drm_winsys *ws = (struct radeon_drm_winsys*)rws;
508 uint64_t ts = 0;
509
510 switch (value) {
511 case RADEON_REQUESTED_VRAM_MEMORY:
512 return ws->allocated_vram;
513 case RADEON_REQUESTED_GTT_MEMORY:
514 return ws->allocated_gtt;
515 case RADEON_BUFFER_WAIT_TIME_NS:
516 return ws->buffer_wait_time;
517 case RADEON_TIMESTAMP:
518 if (ws->info.drm_minor < 20 || ws->gen < DRV_R600) {
519 assert(0);
520 return 0;
521 }
522
523 radeon_get_drm_value(ws->fd, RADEON_INFO_TIMESTAMP, "timestamp",
524 (uint32_t*)&ts);
525 return ts;
526 }
527 return 0;
528 }
529
530 static unsigned hash_fd(void *key)
531 {
532 int fd = pointer_to_intptr(key);
533 struct stat stat;
534 fstat(fd, &stat);
535
536 return stat.st_dev ^ stat.st_ino ^ stat.st_rdev;
537 }
538
539 static int compare_fd(void *key1, void *key2)
540 {
541 int fd1 = pointer_to_intptr(key1);
542 int fd2 = pointer_to_intptr(key2);
543 struct stat stat1, stat2;
544 fstat(fd1, &stat1);
545 fstat(fd2, &stat2);
546
547 return stat1.st_dev != stat2.st_dev ||
548 stat1.st_ino != stat2.st_ino ||
549 stat1.st_rdev != stat2.st_rdev;
550 }
551
552 void radeon_drm_ws_queue_cs(struct radeon_drm_winsys *ws, struct radeon_drm_cs *cs)
553 {
554 retry:
555 pipe_mutex_lock(ws->cs_stack_lock);
556 if (ws->ncs >= RING_LAST) {
557 /* no room left for a flush */
558 pipe_mutex_unlock(ws->cs_stack_lock);
559 goto retry;
560 }
561 ws->cs_stack[ws->ncs++] = cs;
562 pipe_mutex_unlock(ws->cs_stack_lock);
563 pipe_semaphore_signal(&ws->cs_queued);
564 }
565
566 static PIPE_THREAD_ROUTINE(radeon_drm_cs_emit_ioctl, param)
567 {
568 struct radeon_drm_winsys *ws = (struct radeon_drm_winsys *)param;
569 struct radeon_drm_cs *cs;
570 unsigned i;
571
572 while (1) {
573 pipe_semaphore_wait(&ws->cs_queued);
574 if (ws->kill_thread)
575 break;
576
577 pipe_mutex_lock(ws->cs_stack_lock);
578 cs = ws->cs_stack[0];
579 for (i = 1; i < ws->ncs; i++)
580 ws->cs_stack[i - 1] = ws->cs_stack[i];
581 ws->cs_stack[--ws->ncs] = NULL;
582 pipe_mutex_unlock(ws->cs_stack_lock);
583
584 if (cs) {
585 radeon_drm_cs_emit_ioctl_oneshot(cs, cs->cst);
586 pipe_semaphore_signal(&cs->flush_completed);
587 }
588 }
589 pipe_mutex_lock(ws->cs_stack_lock);
590 for (i = 0; i < ws->ncs; i++) {
591 pipe_semaphore_signal(&ws->cs_stack[i]->flush_completed);
592 ws->cs_stack[i] = NULL;
593 }
594 ws->ncs = 0;
595 pipe_mutex_unlock(ws->cs_stack_lock);
596 return 0;
597 }
598
599 DEBUG_GET_ONCE_BOOL_OPTION(thread, "RADEON_THREAD", TRUE)
600 static PIPE_THREAD_ROUTINE(radeon_drm_cs_emit_ioctl, param);
601
602 PUBLIC struct radeon_winsys *radeon_drm_winsys_create(int fd)
603 {
604 struct radeon_drm_winsys *ws;
605
606 if (!fd_tab) {
607 fd_tab = util_hash_table_create(hash_fd, compare_fd);
608 }
609
610 ws = util_hash_table_get(fd_tab, intptr_to_pointer(fd));
611 if (ws) {
612 pipe_reference(NULL, &ws->base.reference);
613 return &ws->base;
614 }
615
616 ws = CALLOC_STRUCT(radeon_drm_winsys);
617 if (!ws) {
618 return NULL;
619 }
620 ws->fd = fd;
621 util_hash_table_set(fd_tab, intptr_to_pointer(fd), ws);
622
623 if (!do_winsys_init(ws))
624 goto fail;
625
626 /* Create managers. */
627 ws->kman = radeon_bomgr_create(ws);
628 if (!ws->kman)
629 goto fail;
630 ws->cman = pb_cache_manager_create(ws->kman, 1000000);
631 if (!ws->cman)
632 goto fail;
633
634 if (ws->gen >= DRV_R600) {
635 ws->surf_man = radeon_surface_manager_new(fd);
636 if (!ws->surf_man)
637 goto fail;
638 }
639
640 /* init reference */
641 pipe_reference_init(&ws->base.reference, 1);
642
643 /* Set functions. */
644 ws->base.destroy = radeon_winsys_destroy;
645 ws->base.query_info = radeon_query_info;
646 ws->base.cs_request_feature = radeon_cs_request_feature;
647 ws->base.surface_init = radeon_drm_winsys_surface_init;
648 ws->base.surface_best = radeon_drm_winsys_surface_best;
649 ws->base.query_value = radeon_query_value;
650
651 radeon_bomgr_init_functions(ws);
652 radeon_drm_cs_init_functions(ws);
653
654 pipe_mutex_init(ws->hyperz_owner_mutex);
655 pipe_mutex_init(ws->cmask_owner_mutex);
656 pipe_mutex_init(ws->cs_stack_lock);
657
658 ws->ncs = 0;
659 pipe_semaphore_init(&ws->cs_queued, 0);
660 if (ws->num_cpus > 1 && debug_get_option_thread())
661 ws->thread = pipe_thread_create(radeon_drm_cs_emit_ioctl, ws);
662
663 return &ws->base;
664
665 fail:
666 if (ws->cman)
667 ws->cman->destroy(ws->cman);
668 if (ws->kman)
669 ws->kman->destroy(ws->kman);
670 if (ws->surf_man)
671 radeon_surface_manager_free(ws->surf_man);
672 FREE(ws);
673 return NULL;
674 }