2
2
* Copyright © 2009 Corbin Simpson
3
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
5
* SPDX-License-Identifier: MIT
28
8
#include "radeon_drm_bo.h"
29
9
#include "radeon_drm_cs.h"
31
11
#include "util/os_file.h"
12
#include "util/simple_mtx.h"
32
13
#include "util/u_cpu_detect.h"
33
14
#include "util/u_memory.h"
34
15
#include "util/u_hash_table.h"
43
24
#include <radeon_surface.h>
45
26
static struct hash_table *fd_tab = NULL;
46
static mtx_t fd_tab_mutex = _MTX_INITIALIZER_NP;
27
static simple_mtx_t fd_tab_mutex = SIMPLE_MTX_INITIALIZER;
48
29
/* Enable/disable feature access for one command stream.
49
30
* If enable == true, return true on success.
585
566
ws->info.spi_cu_en_has_effect = false;
586
567
ws->info.spi_cu_en = 0xffff;
587
568
ws->info.never_stop_sq_perf_counters = false;
569
ws->info.num_rb = util_bitcount64(ws->info.enabled_rb_mask);
570
ws->info.max_gflops = 128 * ws->info.num_cu * ws->info.max_gpu_freq_mhz / 1000;
571
ws->info.num_tcc_blocks = ws->info.max_tcc_blocks;
572
ws->info.tcp_cache_size = 16 * 1024;
573
ws->info.num_simd_per_compute_unit = 4;
574
ws->info.min_sgpr_alloc = 8;
575
ws->info.max_sgpr_alloc = 104;
576
ws->info.sgpr_alloc_granularity = 8;
577
ws->info.min_wave64_vgpr_alloc = 4;
578
ws->info.max_vgpr_alloc = 256;
579
ws->info.wave64_vgpr_alloc_granularity = 4;
581
for (unsigned se = 0; se < ws->info.max_se; se++) {
582
for (unsigned sa = 0; sa < ws->info.max_sa_per_se; sa++)
583
ws->info.cu_mask[se][sa] = BITFIELD_MASK(ws->info.max_good_cu_per_sa);
589
586
/* The maximum number of scratch waves. The number is only a function of the number of CUs.
590
587
* It should be large enough to hold at least 1 threadgroup. Use the minimum per-SA CU count.
593
590
ws->info.max_scratch_waves = MAX2(32 * ws->info.min_good_cu_per_sa * ws->info.max_sa_per_se *
594
591
ws->info.num_se, max_waves_per_tg);
593
switch (ws->info.family) {
599
ws->info.l2_cache_size = ws->info.num_tcc_blocks * 64 * 1024;
605
ws->info.l2_cache_size = ws->info.num_tcc_blocks * 128 * 1024;
610
ws->info.ip[AMD_IP_GFX].num_queues = 1;
612
switch (ws->info.gfx_level) {
616
ws->info.ip[AMD_IP_GFX].ver_major = 2;
620
ws->info.ip[AMD_IP_GFX].ver_major = 3;
623
ws->info.ip[AMD_IP_GFX].ver_major = 4;
626
ws->info.ip[AMD_IP_GFX].ver_major = 5;
629
ws->info.ip[AMD_IP_GFX].ver_major = 6;
632
ws->info.ip[AMD_IP_GFX].ver_major = 7;
596
637
ws->check_vm = strstr(debug_get_option("R600_DEBUG", ""), "check_vm") != NULL ||
597
638
strstr(debug_get_option("AMD_DEBUG", ""), "check_vm") != NULL;
598
639
ws->noop_cs = debug_get_bool_option("RADEON_NOOP", false);
766
807
* This must happen while the mutex is locked, so that
767
808
* radeon_drm_winsys_create in another thread doesn't get the winsys
768
809
* from the table when the counter drops to 0. */
769
mtx_lock(&fd_tab_mutex);
810
simple_mtx_lock(&fd_tab_mutex);
771
812
destroy = pipe_reference(&rws->reference, NULL);
772
813
if (destroy && fd_tab) {
825
866
ws = util_hash_table_get(fd_tab, intptr_to_pointer(fd));
827
868
pipe_reference(NULL, &ws->reference);
828
mtx_unlock(&fd_tab_mutex);
869
simple_mtx_unlock(&fd_tab_mutex);
829
870
return &ws->base;
832
873
ws = CALLOC_STRUCT(radeon_drm_winsys);
834
mtx_unlock(&fd_tab_mutex);
875
simple_mtx_unlock(&fd_tab_mutex);
907
948
if (ws->va_start > 8 * 1024 * 1024) {
908
949
/* Not enough 32-bit address space. */
909
950
radeon_winsys_destroy(&ws->base);
910
mtx_unlock(&fd_tab_mutex);
951
simple_mtx_unlock(&fd_tab_mutex);
932
973
ws->base.screen = screen_create(&ws->base, config);
933
974
if (!ws->base.screen) {
934
975
radeon_winsys_destroy(&ws->base);
935
mtx_unlock(&fd_tab_mutex);
976
simple_mtx_unlock(&fd_tab_mutex);
941
982
/* We must unlock the mutex once the winsys is fully initialized, so that
942
983
* other threads attempting to create the winsys from the same fd will
943
984
* get a fully initialized winsys and not just half-way initialized. */
944
mtx_unlock(&fd_tab_mutex);
985
simple_mtx_unlock(&fd_tab_mutex);
946
987
return &ws->base;