Module: Mesa
Branch: main
Commit: b4015a189405a1b23b2c11ec11201331f0d1614b
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=b4015a189405a1b23b2c11ec11201331f0d1614b

Author: Job Noorman <jnoor...@igalia.com>
Date:   Fri Jan 12 11:52:37 2024 +0100

tu: support l1 dcache size on musl

musl doesn't support _SC_LEVEL1_DCACHE_LINESIZE so calculate the size
manually like on Bionic.

Signed-off-by: Job Noorman <jnoor...@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27031>

---

 src/freedreno/vulkan/tu_knl.cc | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/src/freedreno/vulkan/tu_knl.cc b/src/freedreno/vulkan/tu_knl.cc
index 422a65b4600..24acbd237b7 100644
--- a/src/freedreno/vulkan/tu_knl.cc
+++ b/src/freedreno/vulkan/tu_knl.cc
@@ -180,6 +180,25 @@ tu_enumerate_devices(struct vk_instance *vk_instance)
 #endif
 }
 
+static long
+l1_dcache_size()
+{
+   if (!(DETECT_ARCH_AARCH64 || DETECT_ARCH_X86 || DETECT_ARCH_X86_64))
+      return 0;
+
+#if DETECT_ARCH_AARCH64 &&                                                   \
+   (!defined(_SC_LEVEL1_DCACHE_LINESIZE) || defined(ANDROID))
+   /* Bionic does not implement _SC_LEVEL1_DCACHE_LINESIZE properly: */
+   uint64_t ctr_el0;
+   asm("mrs\t%x0, ctr_el0" : "=r"(ctr_el0));
+   return 4 << ((ctr_el0 >> 16) & 0xf);
+#elif defined(_SC_LEVEL1_DCACHE_LINESIZE)
+   return sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+#else
+   return 0;
+#endif
+}
+
 /**
  * Enumeration entrypoint for drm devices
  */
@@ -239,21 +258,8 @@ tu_physical_device_try_create(struct vk_instance 
*vk_instance,
 
    assert(device);
 
-#ifdef _SC_LEVEL1_DCACHE_LINESIZE
-   if (DETECT_ARCH_AARCH64 || DETECT_ARCH_X86 || DETECT_ARCH_X86_64) {
-      long l1_dcache;
-#if defined(ANDROID) && DETECT_ARCH_AARCH64
-      /* Bionic does not implement _SC_LEVEL1_DCACHE_LINESIZE properly: */
-      uint64_t ctr_el0;
-      asm("mrs\t%x0, ctr_el0" : "=r"(ctr_el0));
-      l1_dcache = 4 << ((ctr_el0 >> 16) & 0xf);
-#else
-      l1_dcache = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
-#endif
-      device->has_cached_non_coherent_memory = l1_dcache > 0;
-      device->level1_dcache_size = l1_dcache;
-   }
-#endif
+   device->level1_dcache_size = l1_dcache_size();
+   device->has_cached_non_coherent_memory = device->level1_dcache_size > 0;
 
    if (instance->vk.enabled_extensions.KHR_display) {
       master_fd = open(primary_path, O_RDWR | O_CLOEXEC);

Reply via email to