2 * Copyright © 2009 Corbin Simpson
3 * Copyright © 2011 Marek Olšák <maraeo@gmail.com>
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:
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.
23 * The above copyright notice and this permission notice (including the
24 * next paragraph) shall be included in all copies or substantial portions
29 * Corbin Simpson <MostAwesomeDude@gmail.com>
30 * Joakim Sindholt <opensource@zhasha.com>
31 * Marek Olšák <maraeo@gmail.com>
34 #include "radeon_drm_bo.h"
35 #include "radeon_drm_cs.h"
36 #include "radeon_drm_public.h"
38 #include "pipebuffer/pb_bufmgr.h"
39 #include "util/u_memory.h"
40 #include "util/u_hash_table.h"
44 #include <sys/types.h>
47 #include <radeon_surface.h>
49 #ifndef RADEON_INFO_ACTIVE_CU_COUNT
50 #define RADEON_INFO_ACTIVE_CU_COUNT 0x20
53 #ifndef RADEON_INFO_CURRENT_GPU_TEMP
54 #define RADEON_INFO_CURRENT_GPU_TEMP 0x21
55 #define RADEON_INFO_CURRENT_GPU_SCLK 0x22
56 #define RADEON_INFO_CURRENT_GPU_MCLK 0x23
57 #define RADEON_INFO_READ_REG 0x24
60 #define RADEON_INFO_VA_UNMAP_WORKING 0x25
62 #ifndef RADEON_INFO_GPU_RESET_COUNTER
63 #define RADEON_INFO_GPU_RESET_COUNTER 0x26
66 static struct util_hash_table
*fd_tab
= NULL
;
67 pipe_static_mutex(fd_tab_mutex
);
69 /* Enable/disable feature access for one command stream.
70 * If enable == TRUE, return TRUE on success.
71 * Otherwise, return FALSE.
73 * We basically do the same thing kernel does, because we have to deal
74 * with multiple contexts (here command streams) backed by one winsys. */
75 static boolean
radeon_set_fd_access(struct radeon_drm_cs
*applier
,
76 struct radeon_drm_cs
**owner
,
78 unsigned request
, const char *request_name
,
81 struct drm_radeon_info info
;
82 unsigned value
= enable
? 1 : 0;
84 memset(&info
, 0, sizeof(info
));
86 pipe_mutex_lock(*mutex
);
88 /* Early exit if we are sure the request will fail. */
91 pipe_mutex_unlock(*mutex
);
95 if (*owner
!= applier
) {
96 pipe_mutex_unlock(*mutex
);
101 /* Pass through the request to the kernel. */
102 info
.value
= (unsigned long)&value
;
103 info
.request
= request
;
104 if (drmCommandWriteRead(applier
->ws
->fd
, DRM_RADEON_INFO
,
105 &info
, sizeof(info
)) != 0) {
106 pipe_mutex_unlock(*mutex
);
110 /* Update the rights in the winsys. */
114 pipe_mutex_unlock(*mutex
);
121 pipe_mutex_unlock(*mutex
);
125 static boolean
radeon_get_drm_value(int fd
, unsigned request
,
126 const char *errname
, uint32_t *out
)
128 struct drm_radeon_info info
;
131 memset(&info
, 0, sizeof(info
));
133 info
.value
= (unsigned long)out
;
134 info
.request
= request
;
136 retval
= drmCommandWriteRead(fd
, DRM_RADEON_INFO
, &info
, sizeof(info
));
139 fprintf(stderr
, "radeon: Failed to get %s, error number %d\n",
147 /* Helper function to do the ioctls needed for setup and init. */
148 static boolean
do_winsys_init(struct radeon_drm_winsys
*ws
)
150 struct drm_radeon_gem_info gem_info
;
152 drmVersionPtr version
;
154 memset(&gem_info
, 0, sizeof(gem_info
));
156 /* We do things in a specific order here.
158 * DRM version first. We need to be sure we're running on a KMS chipset.
159 * This is also for some features.
161 * Then, the PCI ID. This is essential and should return usable numbers
162 * for all Radeons. If this fails, we probably got handed an FD for some
165 * The GEM info is actually bogus on the kernel side, as well as our side
166 * (see radeon_gem_info_ioctl in radeon_gem.c) but that's alright because
167 * we don't actually use the info for anything yet.
169 * The GB and Z pipe requests should always succeed, but they might not
170 * return sensical values for all chipsets, but that's alright because
171 * the pipe drivers already know that.
174 /* Get DRM version. */
175 version
= drmGetVersion(ws
->fd
);
176 if (version
->version_major
!= 2 ||
177 version
->version_minor
< 3) {
178 fprintf(stderr
, "%s: DRM version is %d.%d.%d but this driver is "
179 "only compatible with 2.3.x (kernel 2.6.34) or later.\n",
181 version
->version_major
,
182 version
->version_minor
,
183 version
->version_patchlevel
);
184 drmFreeVersion(version
);
188 ws
->info
.drm_major
= version
->version_major
;
189 ws
->info
.drm_minor
= version
->version_minor
;
190 ws
->info
.drm_patchlevel
= version
->version_patchlevel
;
191 drmFreeVersion(version
);
194 if (!radeon_get_drm_value(ws
->fd
, RADEON_INFO_DEVICE_ID
, "PCI ID",
199 switch (ws
->info
.pci_id
) {
200 #define CHIPSET(pci_id, name, cfamily) case pci_id: ws->info.family = CHIP_##cfamily; ws->gen = DRV_R300; break;
201 #include "pci_ids/r300_pci_ids.h"
204 #define CHIPSET(pci_id, name, cfamily) case pci_id: ws->info.family = CHIP_##cfamily; ws->gen = DRV_R600; break;
205 #include "pci_ids/r600_pci_ids.h"
208 #define CHIPSET(pci_id, name, cfamily) case pci_id: ws->info.family = CHIP_##cfamily; ws->gen = DRV_SI; break;
209 #include "pci_ids/radeonsi_pci_ids.h"
213 fprintf(stderr
, "radeon: Invalid PCI ID.\n");
217 switch (ws
->info
.family
) {
220 fprintf(stderr
, "radeon: Unknown family.\n");
230 ws
->info
.chip_class
= R300
;
232 case CHIP_R420
: /* R4xx-based cores. */
241 ws
->info
.chip_class
= R400
;
243 case CHIP_RV515
: /* R5xx-based cores. */
249 ws
->info
.chip_class
= R500
;
259 ws
->info
.chip_class
= R600
;
265 ws
->info
.chip_class
= R700
;
278 ws
->info
.chip_class
= EVERGREEN
;
282 ws
->info
.chip_class
= CAYMAN
;
289 ws
->info
.chip_class
= SI
;
296 ws
->info
.chip_class
= CIK
;
301 ws
->info
.has_sdma
= FALSE
;
302 /* DMA is disabled on R700. There is IB corruption and hangs. */
303 if (ws
->info
.chip_class
>= EVERGREEN
&& ws
->info
.drm_minor
>= 27) {
304 ws
->info
.has_sdma
= TRUE
;
307 /* Check for UVD and VCE */
308 ws
->info
.has_uvd
= FALSE
;
309 ws
->info
.vce_fw_version
= 0x00000000;
310 if (ws
->info
.drm_minor
>= 32) {
311 uint32_t value
= RADEON_CS_RING_UVD
;
312 if (radeon_get_drm_value(ws
->fd
, RADEON_INFO_RING_WORKING
,
313 "UVD Ring working", &value
))
314 ws
->info
.has_uvd
= value
;
316 value
= RADEON_CS_RING_VCE
;
317 if (radeon_get_drm_value(ws
->fd
, RADEON_INFO_RING_WORKING
,
318 NULL
, &value
) && value
) {
320 if (radeon_get_drm_value(ws
->fd
, RADEON_INFO_VCE_FW_VERSION
,
321 "VCE FW version", &value
))
322 ws
->info
.vce_fw_version
= value
;
326 /* Check for userptr support. */
328 struct drm_radeon_gem_userptr args
= {0};
330 /* If the ioctl doesn't exist, -EINVAL is returned.
332 * If the ioctl exists, it should return -EACCES
333 * if RADEON_GEM_USERPTR_READONLY or RADEON_GEM_USERPTR_REGISTER
336 ws
->info
.has_userptr
=
337 drmCommandWriteRead(ws
->fd
, DRM_RADEON_GEM_USERPTR
,
338 &args
, sizeof(args
)) == -EACCES
;
342 retval
= drmCommandWriteRead(ws
->fd
, DRM_RADEON_GEM_INFO
,
343 &gem_info
, sizeof(gem_info
));
345 fprintf(stderr
, "radeon: Failed to get MM info, error number %d\n",
349 ws
->info
.gart_size
= gem_info
.gart_size
;
350 ws
->info
.vram_size
= gem_info
.vram_size
;
352 /* Get max clock frequency info and convert it to MHz */
353 radeon_get_drm_value(ws
->fd
, RADEON_INFO_MAX_SCLK
, NULL
,
354 &ws
->info
.max_shader_clock
);
355 ws
->info
.max_shader_clock
/= 1000;
357 radeon_get_drm_value(ws
->fd
, RADEON_INFO_SI_BACKEND_ENABLED_MASK
, NULL
,
358 &ws
->info
.enabled_rb_mask
);
360 ws
->num_cpus
= sysconf(_SC_NPROCESSORS_ONLN
);
362 /* Generation-specific queries. */
363 if (ws
->gen
== DRV_R300
) {
364 if (!radeon_get_drm_value(ws
->fd
, RADEON_INFO_NUM_GB_PIPES
,
366 &ws
->info
.r300_num_gb_pipes
))
369 if (!radeon_get_drm_value(ws
->fd
, RADEON_INFO_NUM_Z_PIPES
,
371 &ws
->info
.r300_num_z_pipes
))
374 else if (ws
->gen
>= DRV_R600
) {
375 if (ws
->info
.drm_minor
>= 9 &&
376 !radeon_get_drm_value(ws
->fd
, RADEON_INFO_NUM_BACKENDS
,
378 &ws
->info
.num_render_backends
))
381 /* get the GPU counter frequency, failure is not fatal */
382 radeon_get_drm_value(ws
->fd
, RADEON_INFO_CLOCK_CRYSTAL_FREQ
, NULL
,
383 &ws
->info
.clock_crystal_freq
);
385 radeon_get_drm_value(ws
->fd
, RADEON_INFO_TILING_CONFIG
, NULL
,
386 &ws
->info
.r600_tiling_config
);
388 if (ws
->info
.drm_minor
>= 11) {
389 radeon_get_drm_value(ws
->fd
, RADEON_INFO_NUM_TILE_PIPES
, NULL
,
390 &ws
->info
.num_tile_pipes
);
392 if (radeon_get_drm_value(ws
->fd
, RADEON_INFO_BACKEND_MAP
, NULL
,
393 &ws
->info
.r600_gb_backend_map
))
394 ws
->info
.r600_gb_backend_map_valid
= TRUE
;
396 ws
->info
.num_tile_pipes
=
397 ws
->info
.chip_class
>= EVERGREEN
?
398 1 << (ws
->info
.r600_tiling_config
& 0xf) :
399 1 << ((ws
->info
.r600_tiling_config
& 0xe) >> 1);
402 ws
->info
.has_virtual_memory
= FALSE
;
403 if (ws
->info
.drm_minor
>= 13) {
404 uint32_t ib_vm_max_size
;
406 ws
->info
.has_virtual_memory
= TRUE
;
407 if (!radeon_get_drm_value(ws
->fd
, RADEON_INFO_VA_START
, NULL
,
409 ws
->info
.has_virtual_memory
= FALSE
;
410 if (!radeon_get_drm_value(ws
->fd
, RADEON_INFO_IB_VM_MAX_SIZE
, NULL
,
412 ws
->info
.has_virtual_memory
= FALSE
;
413 radeon_get_drm_value(ws
->fd
, RADEON_INFO_VA_UNMAP_WORKING
, NULL
,
414 &ws
->va_unmap_working
);
416 if (ws
->gen
== DRV_R600
&& !debug_get_bool_option("RADEON_VA", FALSE
))
417 ws
->info
.has_virtual_memory
= FALSE
;
420 /* Get max pipes, this is only needed for compute shaders. All evergreen+
421 * chips have at least 2 pipes, so we use 2 as a default. */
422 ws
->info
.r600_max_quad_pipes
= 2;
423 radeon_get_drm_value(ws
->fd
, RADEON_INFO_MAX_PIPES
, NULL
,
424 &ws
->info
.r600_max_quad_pipes
);
426 /* All GPUs have at least one compute unit */
427 ws
->info
.num_good_compute_units
= 1;
428 radeon_get_drm_value(ws
->fd
, RADEON_INFO_ACTIVE_CU_COUNT
, NULL
,
429 &ws
->info
.num_good_compute_units
);
431 radeon_get_drm_value(ws
->fd
, RADEON_INFO_MAX_SE
, NULL
,
434 if (!ws
->info
.max_se
) {
435 switch (ws
->info
.family
) {
454 radeon_get_drm_value(ws
->fd
, RADEON_INFO_MAX_SH_PER_SE
, NULL
,
455 &ws
->info
.max_sh_per_se
);
457 radeon_get_drm_value(ws
->fd
, RADEON_INFO_ACCEL_WORKING2
, NULL
,
458 &ws
->accel_working2
);
459 if (ws
->info
.family
== CHIP_HAWAII
&& ws
->accel_working2
< 2) {
460 fprintf(stderr
, "radeon: GPU acceleration for Hawaii disabled, "
461 "returned accel_working2 value %u is smaller than 2. "
462 "Please install a newer kernel.\n",
467 if (radeon_get_drm_value(ws
->fd
, RADEON_INFO_SI_TILE_MODE_ARRAY
, NULL
,
468 ws
->info
.si_tile_mode_array
)) {
469 ws
->info
.si_tile_mode_array_valid
= TRUE
;
472 if (radeon_get_drm_value(ws
->fd
, RADEON_INFO_CIK_MACROTILE_MODE_ARRAY
, NULL
,
473 ws
->info
.cik_macrotile_mode_array
)) {
474 ws
->info
.cik_macrotile_mode_array_valid
= TRUE
;
477 /* Hawaii with old firmware needs type2 nop packet.
478 * accel_working2 with value 3 indicates the new firmware.
480 ws
->info
.gfx_ib_pad_with_type2
= ws
->info
.chip_class
<= SI
||
481 (ws
->info
.family
== CHIP_HAWAII
&&
482 ws
->accel_working2
< 3);
487 static void radeon_winsys_destroy(struct radeon_winsys
*rws
)
489 struct radeon_drm_winsys
*ws
= (struct radeon_drm_winsys
*)rws
;
493 pipe_semaphore_signal(&ws
->cs_queued
);
494 pipe_thread_wait(ws
->thread
);
496 pipe_semaphore_destroy(&ws
->cs_queued
);
498 pipe_mutex_destroy(ws
->hyperz_owner_mutex
);
499 pipe_mutex_destroy(ws
->cmask_owner_mutex
);
500 pipe_mutex_destroy(ws
->cs_stack_lock
);
502 pb_cache_deinit(&ws
->bo_cache
);
504 if (ws
->gen
>= DRV_R600
) {
505 radeon_surface_manager_free(ws
->surf_man
);
508 util_hash_table_destroy(ws
->bo_names
);
509 util_hash_table_destroy(ws
->bo_handles
);
510 util_hash_table_destroy(ws
->bo_vas
);
511 pipe_mutex_destroy(ws
->bo_handles_mutex
);
512 pipe_mutex_destroy(ws
->bo_va_mutex
);
520 static void radeon_query_info(struct radeon_winsys
*rws
,
521 struct radeon_info
*info
)
523 *info
= ((struct radeon_drm_winsys
*)rws
)->info
;
526 static boolean
radeon_cs_request_feature(struct radeon_winsys_cs
*rcs
,
527 enum radeon_feature_id fid
,
530 struct radeon_drm_cs
*cs
= radeon_drm_cs(rcs
);
533 case RADEON_FID_R300_HYPERZ_ACCESS
:
534 return radeon_set_fd_access(cs
, &cs
->ws
->hyperz_owner
,
535 &cs
->ws
->hyperz_owner_mutex
,
536 RADEON_INFO_WANT_HYPERZ
, "Hyper-Z",
539 case RADEON_FID_R300_CMASK_ACCESS
:
540 return radeon_set_fd_access(cs
, &cs
->ws
->cmask_owner
,
541 &cs
->ws
->cmask_owner_mutex
,
542 RADEON_INFO_WANT_CMASK
, "AA optimizations",
548 static uint64_t radeon_query_value(struct radeon_winsys
*rws
,
549 enum radeon_value_id value
)
551 struct radeon_drm_winsys
*ws
= (struct radeon_drm_winsys
*)rws
;
555 case RADEON_REQUESTED_VRAM_MEMORY
:
556 return ws
->allocated_vram
;
557 case RADEON_REQUESTED_GTT_MEMORY
:
558 return ws
->allocated_gtt
;
559 case RADEON_BUFFER_WAIT_TIME_NS
:
560 return ws
->buffer_wait_time
;
561 case RADEON_TIMESTAMP
:
562 if (ws
->info
.drm_minor
< 20 || ws
->gen
< DRV_R600
) {
567 radeon_get_drm_value(ws
->fd
, RADEON_INFO_TIMESTAMP
, "timestamp",
570 case RADEON_NUM_CS_FLUSHES
:
571 return ws
->num_cs_flushes
;
572 case RADEON_NUM_BYTES_MOVED
:
573 radeon_get_drm_value(ws
->fd
, RADEON_INFO_NUM_BYTES_MOVED
,
574 "num-bytes-moved", (uint32_t*)&retval
);
576 case RADEON_VRAM_USAGE
:
577 radeon_get_drm_value(ws
->fd
, RADEON_INFO_VRAM_USAGE
,
578 "vram-usage", (uint32_t*)&retval
);
580 case RADEON_GTT_USAGE
:
581 radeon_get_drm_value(ws
->fd
, RADEON_INFO_GTT_USAGE
,
582 "gtt-usage", (uint32_t*)&retval
);
584 case RADEON_GPU_TEMPERATURE
:
585 radeon_get_drm_value(ws
->fd
, RADEON_INFO_CURRENT_GPU_TEMP
,
586 "gpu-temp", (uint32_t*)&retval
);
588 case RADEON_CURRENT_SCLK
:
589 radeon_get_drm_value(ws
->fd
, RADEON_INFO_CURRENT_GPU_SCLK
,
590 "current-gpu-sclk", (uint32_t*)&retval
);
592 case RADEON_CURRENT_MCLK
:
593 radeon_get_drm_value(ws
->fd
, RADEON_INFO_CURRENT_GPU_MCLK
,
594 "current-gpu-mclk", (uint32_t*)&retval
);
596 case RADEON_GPU_RESET_COUNTER
:
597 radeon_get_drm_value(ws
->fd
, RADEON_INFO_GPU_RESET_COUNTER
,
598 "gpu-reset-counter", (uint32_t*)&retval
);
604 static bool radeon_read_registers(struct radeon_winsys
*rws
,
606 unsigned num_registers
, uint32_t *out
)
608 struct radeon_drm_winsys
*ws
= (struct radeon_drm_winsys
*)rws
;
611 for (i
= 0; i
< num_registers
; i
++) {
612 uint32_t reg
= reg_offset
+ i
*4;
614 if (!radeon_get_drm_value(ws
->fd
, RADEON_INFO_READ_REG
, NULL
, ®
))
621 static unsigned hash_fd(void *key
)
623 int fd
= pointer_to_intptr(key
);
627 return stat
.st_dev
^ stat
.st_ino
^ stat
.st_rdev
;
630 static int compare_fd(void *key1
, void *key2
)
632 int fd1
= pointer_to_intptr(key1
);
633 int fd2
= pointer_to_intptr(key2
);
634 struct stat stat1
, stat2
;
638 return stat1
.st_dev
!= stat2
.st_dev
||
639 stat1
.st_ino
!= stat2
.st_ino
||
640 stat1
.st_rdev
!= stat2
.st_rdev
;
643 void radeon_drm_ws_queue_cs(struct radeon_drm_winsys
*ws
, struct radeon_drm_cs
*cs
)
646 pipe_mutex_lock(ws
->cs_stack_lock
);
647 if (ws
->ncs
>= RING_LAST
) {
648 /* no room left for a flush */
649 pipe_mutex_unlock(ws
->cs_stack_lock
);
652 ws
->cs_stack
[ws
->ncs
++] = cs
;
653 pipe_mutex_unlock(ws
->cs_stack_lock
);
654 pipe_semaphore_signal(&ws
->cs_queued
);
657 static PIPE_THREAD_ROUTINE(radeon_drm_cs_emit_ioctl
, param
)
659 struct radeon_drm_winsys
*ws
= (struct radeon_drm_winsys
*)param
;
660 struct radeon_drm_cs
*cs
;
664 pipe_semaphore_wait(&ws
->cs_queued
);
668 pipe_mutex_lock(ws
->cs_stack_lock
);
669 cs
= ws
->cs_stack
[0];
670 for (i
= 1; i
< ws
->ncs
; i
++)
671 ws
->cs_stack
[i
- 1] = ws
->cs_stack
[i
];
672 ws
->cs_stack
[--ws
->ncs
] = NULL
;
673 pipe_mutex_unlock(ws
->cs_stack_lock
);
676 radeon_drm_cs_emit_ioctl_oneshot(cs
, cs
->cst
);
677 pipe_semaphore_signal(&cs
->flush_completed
);
680 pipe_mutex_lock(ws
->cs_stack_lock
);
681 for (i
= 0; i
< ws
->ncs
; i
++) {
682 pipe_semaphore_signal(&ws
->cs_stack
[i
]->flush_completed
);
683 ws
->cs_stack
[i
] = NULL
;
686 pipe_mutex_unlock(ws
->cs_stack_lock
);
690 DEBUG_GET_ONCE_BOOL_OPTION(thread
, "RADEON_THREAD", TRUE
)
691 static PIPE_THREAD_ROUTINE(radeon_drm_cs_emit_ioctl
, param
);
693 static bool radeon_winsys_unref(struct radeon_winsys
*ws
)
695 struct radeon_drm_winsys
*rws
= (struct radeon_drm_winsys
*)ws
;
698 /* When the reference counter drops to zero, remove the fd from the table.
699 * This must happen while the mutex is locked, so that
700 * radeon_drm_winsys_create in another thread doesn't get the winsys
701 * from the table when the counter drops to 0. */
702 pipe_mutex_lock(fd_tab_mutex
);
704 destroy
= pipe_reference(&rws
->reference
, NULL
);
705 if (destroy
&& fd_tab
)
706 util_hash_table_remove(fd_tab
, intptr_to_pointer(rws
->fd
));
708 pipe_mutex_unlock(fd_tab_mutex
);
712 #define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x)))
714 static unsigned handle_hash(void *key
)
716 return PTR_TO_UINT(key
);
719 static int handle_compare(void *key1
, void *key2
)
721 return PTR_TO_UINT(key1
) != PTR_TO_UINT(key2
);
724 PUBLIC
struct radeon_winsys
*
725 radeon_drm_winsys_create(int fd
, radeon_screen_create_t screen_create
)
727 struct radeon_drm_winsys
*ws
;
729 pipe_mutex_lock(fd_tab_mutex
);
731 fd_tab
= util_hash_table_create(hash_fd
, compare_fd
);
734 ws
= util_hash_table_get(fd_tab
, intptr_to_pointer(fd
));
736 pipe_reference(NULL
, &ws
->reference
);
737 pipe_mutex_unlock(fd_tab_mutex
);
741 ws
= CALLOC_STRUCT(radeon_drm_winsys
);
743 pipe_mutex_unlock(fd_tab_mutex
);
749 if (!do_winsys_init(ws
))
752 pb_cache_init(&ws
->bo_cache
, 500000, 2.0f
, 0,
753 MIN2(ws
->info
.vram_size
, ws
->info
.gart_size
),
755 radeon_bo_can_reclaim
);
757 if (ws
->gen
>= DRV_R600
) {
758 ws
->surf_man
= radeon_surface_manager_new(ws
->fd
);
764 pipe_reference_init(&ws
->reference
, 1);
767 ws
->base
.unref
= radeon_winsys_unref
;
768 ws
->base
.destroy
= radeon_winsys_destroy
;
769 ws
->base
.query_info
= radeon_query_info
;
770 ws
->base
.cs_request_feature
= radeon_cs_request_feature
;
771 ws
->base
.query_value
= radeon_query_value
;
772 ws
->base
.read_registers
= radeon_read_registers
;
774 radeon_drm_bo_init_functions(ws
);
775 radeon_drm_cs_init_functions(ws
);
776 radeon_surface_init_functions(ws
);
778 pipe_mutex_init(ws
->hyperz_owner_mutex
);
779 pipe_mutex_init(ws
->cmask_owner_mutex
);
780 pipe_mutex_init(ws
->cs_stack_lock
);
782 ws
->bo_names
= util_hash_table_create(handle_hash
, handle_compare
);
783 ws
->bo_handles
= util_hash_table_create(handle_hash
, handle_compare
);
784 ws
->bo_vas
= util_hash_table_create(handle_hash
, handle_compare
);
785 pipe_mutex_init(ws
->bo_handles_mutex
);
786 pipe_mutex_init(ws
->bo_va_mutex
);
787 ws
->va_offset
= ws
->va_start
;
788 list_inithead(&ws
->va_holes
);
790 /* TTM aligns the BO size to the CPU page size */
791 ws
->size_align
= sysconf(_SC_PAGESIZE
);
794 pipe_semaphore_init(&ws
->cs_queued
, 0);
795 if (ws
->num_cpus
> 1 && debug_get_option_thread())
796 ws
->thread
= pipe_thread_create(radeon_drm_cs_emit_ioctl
, ws
);
798 /* Create the screen at the end. The winsys must be initialized
801 * Alternatively, we could create the screen based on "ws->gen"
802 * and link all drivers into one binary blob. */
803 ws
->base
.screen
= screen_create(&ws
->base
);
804 if (!ws
->base
.screen
) {
805 radeon_winsys_destroy(&ws
->base
);
806 pipe_mutex_unlock(fd_tab_mutex
);
810 util_hash_table_set(fd_tab
, intptr_to_pointer(ws
->fd
), ws
);
812 /* We must unlock the mutex once the winsys is fully initialized, so that
813 * other threads attempting to create the winsys from the same fd will
814 * get a fully initialized winsys and not just half-way initialized. */
815 pipe_mutex_unlock(fd_tab_mutex
);
820 pb_cache_deinit(&ws
->bo_cache
);
822 pipe_mutex_unlock(fd_tab_mutex
);
824 radeon_surface_manager_free(ws
->surf_man
);