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

Author: Dennis Bonke <den...@managarm.org>
Date:   Sun Apr 16 20:33:01 2023 +0200

mesa: add managarm support

Co-authored-by: Alexander Richards <electrod...@gmail.com>
Signed-off-by: Alexander Richards <electrod...@gmail.com>
Signed-off-by: Dennis Bonke <den...@managarm.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25818>

---

 include/drm-uapi/dma-buf.h            | 2 +-
 include/drm-uapi/drm.h                | 2 +-
 meson.build                           | 4 ++--
 src/gallium/auxiliary/util/u_screen.c | 2 +-
 src/util/detect_os.h                  | 8 ++++++++
 src/util/futex.h                      | 2 +-
 src/util/os_misc.c                    | 4 ++--
 src/util/os_time.c                    | 2 +-
 src/util/u_thread.c                   | 4 ++--
 9 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/include/drm-uapi/dma-buf.h b/include/drm-uapi/dma-buf.h
index 37c448e2bcb..b7eb4ffbcfa 100644
--- a/include/drm-uapi/dma-buf.h
+++ b/include/drm-uapi/dma-buf.h
@@ -20,7 +20,7 @@
 #ifndef _DMA_BUF_UAPI_H_
 #define _DMA_BUF_UAPI_H_
 
-#if defined(__linux__)
+#if defined(__linux__) || defined(__managarm__)
 
 #include <linux/types.h>
 
diff --git a/include/drm-uapi/drm.h b/include/drm-uapi/drm.h
index 02540248deb..60e8161aea9 100644
--- a/include/drm-uapi/drm.h
+++ b/include/drm-uapi/drm.h
@@ -35,7 +35,7 @@
 #ifndef _DRM_H_
 #define _DRM_H_
 
-#if   defined(__linux__)
+#if   defined(__linux__) || defined(__managarm__)
 
 #include <linux/types.h>
 #include <asm/ioctl.h>
diff --git a/meson.build b/meson.build
index 04d89987311..73ce657a144 100644
--- a/meson.build
+++ b/meson.build
@@ -128,7 +128,7 @@ with_any_opengl = with_opengl or with_gles1 or with_gles2
 # Only build shared_glapi if at least one OpenGL API is enabled
 with_shared_glapi = with_shared_glapi and with_any_opengl
 
-system_has_kms_drm = ['openbsd', 'netbsd', 'freebsd', 'gnu/kfreebsd', 
'dragonfly', 'linux', 'sunos', 'android'].contains(host_machine.system())
+system_has_kms_drm = ['openbsd', 'netbsd', 'freebsd', 'gnu/kfreebsd', 
'dragonfly', 'linux', 'sunos', 'android', 
'managarm'].contains(host_machine.system())
 
 gallium_drivers = get_option('gallium-drivers')
 if gallium_drivers.contains('auto')
@@ -962,7 +962,7 @@ if cc.has_function('fmemopen')
 endif
 
 # TODO: this is very incomplete
-if ['linux', 'cygwin', 'gnu', 'freebsd', 'gnu/kfreebsd', 'haiku', 
'android'].contains(host_machine.system())
+if ['linux', 'cygwin', 'gnu', 'freebsd', 'gnu/kfreebsd', 'haiku', 'android', 
'managarm'].contains(host_machine.system())
   pre_args += '-D_GNU_SOURCE'
 elif host_machine.system() == 'sunos'
   pre_args += '-D__EXTENSIONS__'
diff --git a/src/gallium/auxiliary/util/u_screen.c 
b/src/gallium/auxiliary/util/u_screen.c
index 6ce7179c218..66efbddf04c 100644
--- a/src/gallium/auxiliary/util/u_screen.c
+++ b/src/gallium/auxiliary/util/u_screen.c
@@ -440,7 +440,7 @@ u_pipe_screen_get_param_defaults(struct pipe_screen 
*pscreen,
       return 0;
 
    case PIPE_CAP_DMABUF:
-#if defined(HAVE_LIBDRM) && (DETECT_OS_LINUX || DETECT_OS_BSD)
+#if defined(HAVE_LIBDRM) && (DETECT_OS_LINUX || DETECT_OS_BSD || 
DETECT_OS_MANAGARM)
       fd = pscreen->get_screen_fd(pscreen);
       if (fd != -1 && (drmGetCap(fd, DRM_CAP_PRIME, &cap) == 0))
          return cap;
diff --git a/src/util/detect_os.h b/src/util/detect_os.h
index 6506948e035..469b502bbd9 100644
--- a/src/util/detect_os.h
+++ b/src/util/detect_os.h
@@ -81,6 +81,11 @@
 #define DETECT_OS_UNIX 1
 #endif
 
+#if defined(__managarm__)
+#define DETECT_OS_MANAGARM 1
+#define DETECT_OS_UNIX 1
+#endif
+
 
 /*
  * Make sure DETECT_OS_* are always defined, so that they can be used with #if
@@ -127,5 +132,8 @@
 #ifndef DETECT_OS_WINDOWS
 #define DETECT_OS_WINDOWS 0
 #endif
+#ifndef DETECT_OS_MANAGARM
+#define DETECT_OS_MANAGARM 0
+#endif
 
 #endif /* DETECT_OS_H */
diff --git a/src/util/futex.h b/src/util/futex.h
index c39750798e5..995c1e25e30 100644
--- a/src/util/futex.h
+++ b/src/util/futex.h
@@ -24,7 +24,7 @@
 #ifndef UTIL_FUTEX_H
 #define UTIL_FUTEX_H
 
-#if defined(HAVE_LINUX_FUTEX_H)
+#if defined(HAVE_LINUX_FUTEX_H) && defined(__linux__)
 #define UTIL_FUTEX_SUPPORTED 1
 #elif defined(__FreeBSD__)
 #define UTIL_FUTEX_SUPPORTED 1
diff --git a/src/util/os_misc.c b/src/util/os_misc.c
index c378a9e919f..02286121542 100644
--- a/src/util/os_misc.c
+++ b/src/util/os_misc.c
@@ -57,7 +57,7 @@
 #  include <unistd.h>
 #  include <log/log.h>
 #  include <cutils/properties.h>
-#elif DETECT_OS_LINUX || DETECT_OS_CYGWIN || DETECT_OS_SOLARIS || 
DETECT_OS_HURD
+#elif DETECT_OS_LINUX || DETECT_OS_CYGWIN || DETECT_OS_SOLARIS || 
DETECT_OS_HURD || DETECT_OS_MANAGARM
 #  include <unistd.h>
 #elif DETECT_OS_OPENBSD || DETECT_OS_FREEBSD
 #  include <sys/resource.h>
@@ -248,7 +248,7 @@ exit_mutex:
 bool
 os_get_total_physical_memory(uint64_t *size)
 {
-#if DETECT_OS_LINUX || DETECT_OS_CYGWIN || DETECT_OS_SOLARIS || DETECT_OS_HURD
+#if DETECT_OS_LINUX || DETECT_OS_CYGWIN || DETECT_OS_SOLARIS || DETECT_OS_HURD 
|| DETECT_OS_MANAGARM
    const long phys_pages = sysconf(_SC_PHYS_PAGES);
    const long page_size = sysconf(_SC_PAGE_SIZE);
 
diff --git a/src/util/os_time.c b/src/util/os_time.c
index 7fb31342bb3..37548a8544b 100644
--- a/src/util/os_time.c
+++ b/src/util/os_time.c
@@ -65,7 +65,7 @@ os_time_get_nano(void)
 void
 os_time_sleep(int64_t usecs)
 {
-#if DETECT_OS_LINUX
+#if DETECT_OS_LINUX || DETECT_OS_MANAGARM
    struct timespec time;
    time.tv_sec = usecs / 1000000;
    time.tv_nsec = (usecs % 1000000) * 1000;
diff --git a/src/util/u_thread.c b/src/util/u_thread.c
index 55b6b68589c..c5087338bc9 100644
--- a/src/util/u_thread.c
+++ b/src/util/u_thread.c
@@ -75,7 +75,7 @@ int u_thread_create(thrd_t *thrd, int (*routine)(void *), 
void *param)
 void u_thread_setname( const char *name )
 {
 #if defined(HAVE_PTHREAD)
-#if DETECT_OS_LINUX || DETECT_OS_CYGWIN || DETECT_OS_SOLARIS || 
defined(__GLIBC__)
+#if DETECT_OS_LINUX || DETECT_OS_CYGWIN || DETECT_OS_SOLARIS || 
defined(__GLIBC__) || DETECT_OS_MANAGARM
    int ret = pthread_setname_np(pthread_self(), name);
    if (ret == ERANGE) {
       char buf[16];
@@ -154,7 +154,7 @@ util_set_thread_affinity(thrd_t thread,
 int64_t
 util_thread_get_time_nano(thrd_t thread)
 {
-#if defined(HAVE_PTHREAD) && !defined(__APPLE__) && !defined(__HAIKU__)
+#if defined(HAVE_PTHREAD) && !defined(__APPLE__) && !defined(__HAIKU__) && 
!defined(__managarm__)
    struct timespec ts;
    clockid_t cid;
 

Reply via email to