~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/gallium/winsys/radeon/drm/radeon_drm_winsys.c

  • Committer: mmach
  • Date: 2023-11-02 21:31:35 UTC
  • Revision ID: netbit73@gmail.com-20231102213135-18d4tzh7tj0uz752
2023-11-02 22:11:57

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Copyright © 2009 Corbin Simpson
3
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.
 
4
 *
 
5
 * SPDX-License-Identifier: MIT
26
6
 */
27
7
 
28
8
#include "radeon_drm_bo.h"
29
9
#include "radeon_drm_cs.h"
30
10
 
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>
44
25
 
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;
47
28
 
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;
 
580
 
 
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);
 
584
   }
588
585
 
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);
595
592
 
 
593
   switch (ws->info.family) {
 
594
   case CHIP_TAHITI:
 
595
   case CHIP_PITCAIRN:
 
596
   case CHIP_OLAND:
 
597
   case CHIP_HAWAII:
 
598
   case CHIP_KABINI:
 
599
      ws->info.l2_cache_size = ws->info.num_tcc_blocks * 64 * 1024;
 
600
      break;
 
601
   case CHIP_VERDE:
 
602
   case CHIP_HAINAN:
 
603
   case CHIP_BONAIRE:
 
604
   case CHIP_KAVERI:
 
605
      ws->info.l2_cache_size = ws->info.num_tcc_blocks * 128 * 1024;
 
606
      break;
 
607
   default:;
 
608
   }
 
609
 
 
610
   ws->info.ip[AMD_IP_GFX].num_queues = 1;
 
611
 
 
612
   switch (ws->info.gfx_level) {
 
613
   case R300:
 
614
   case R400:
 
615
   case R500:
 
616
      ws->info.ip[AMD_IP_GFX].ver_major = 2;
 
617
      break;
 
618
   case R600:
 
619
   case R700:
 
620
      ws->info.ip[AMD_IP_GFX].ver_major = 3;
 
621
      break;
 
622
   case EVERGREEN:
 
623
      ws->info.ip[AMD_IP_GFX].ver_major = 4;
 
624
      break;
 
625
   case CAYMAN:
 
626
      ws->info.ip[AMD_IP_GFX].ver_major = 5;
 
627
      break;
 
628
   case GFX6:
 
629
      ws->info.ip[AMD_IP_GFX].ver_major = 6;
 
630
      break;
 
631
   case GFX7:
 
632
      ws->info.ip[AMD_IP_GFX].ver_major = 7;
 
633
      break;
 
634
   default:;
 
635
   }
 
636
 
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);
770
811
 
771
812
   destroy = pipe_reference(&rws->reference, NULL);
772
813
   if (destroy && fd_tab) {
777
818
      }
778
819
   }
779
820
 
780
 
   mtx_unlock(&fd_tab_mutex);
 
821
   simple_mtx_unlock(&fd_tab_mutex);
781
822
   return destroy;
782
823
}
783
824
 
817
858
{
818
859
   struct radeon_drm_winsys *ws;
819
860
 
820
 
   mtx_lock(&fd_tab_mutex);
 
861
   simple_mtx_lock(&fd_tab_mutex);
821
862
   if (!fd_tab) {
822
863
      fd_tab = util_hash_table_create_fd_keys();
823
864
   }
825
866
   ws = util_hash_table_get(fd_tab, intptr_to_pointer(fd));
826
867
   if (ws) {
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;
830
871
   }
831
872
 
832
873
   ws = CALLOC_STRUCT(radeon_drm_winsys);
833
874
   if (!ws) {
834
 
      mtx_unlock(&fd_tab_mutex);
 
875
      simple_mtx_unlock(&fd_tab_mutex);
835
876
      return NULL;
836
877
   }
837
878
 
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);
911
952
      return NULL;
912
953
   }
913
954
 
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);
936
977
      return NULL;
937
978
   }
938
979
 
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);
945
986
 
946
987
   return &ws->base;
947
988
 
951
992
fail_cache:
952
993
   pb_cache_deinit(&ws->bo_cache);
953
994
fail1:
954
 
   mtx_unlock(&fd_tab_mutex);
 
995
   simple_mtx_unlock(&fd_tab_mutex);
955
996
   if (ws->surf_man)
956
997
      radeon_surface_manager_free(ws->surf_man);
957
998
   if (ws->fd >= 0)