replace all F_DUPFD_CLOEXEC with os_dupfd_cloexec()
[mesa.git] / src / gallium / winsys / vc4 / drm / vc4_drm_winsys.c
index b2ffa90fe19e8c4f1aa09e6933156c4c8a27ed63..a507821a940d51ca2d92ea5b97a18cbe4180043b 100644 (file)
 
 #include <unistd.h>
 #include <fcntl.h>
+#include <sys/ioctl.h>
+
+#include "util/os_file.h"
 
 #include "renderonly/renderonly.h"
+#include "kmsro/drm/kmsro_drm_public.h"
 #include "vc4_drm_public.h"
 #include "vc4/vc4_screen.h"
+#include "drm-uapi/vc4_drm.h"
 
 struct pipe_screen *
-vc4_drm_screen_create(int fd)
+vc4_drm_screen_create(int fd, const struct pipe_screen_config *config)
 {
-   return vc4_screen_create(fcntl(fd, F_DUPFD_CLOEXEC, 3), NULL);
+   bool v3d_present = true;
+
+#ifndef USE_VC4_SIMULATOR
+   struct drm_vc4_get_param ident0 = {
+      .param = DRM_VC4_PARAM_V3D_IDENT0,
+   };
+
+   int ret = ioctl(fd, DRM_IOCTL_VC4_GET_PARAM, &ident0);
+   v3d_present = ret == 0;
+#endif
+
+   if (v3d_present)
+      return vc4_screen_create(os_dupfd_cloexec(fd), NULL);
+
+#ifdef GALLIUM_KMSRO
+   return kmsro_drm_screen_create(fd, config);
+#endif
+
+   return NULL;
 }
 
 struct pipe_screen *
-vc4_drm_screen_create_renderonly(struct renderonly *ro)
+vc4_drm_screen_create_renderonly(struct renderonly *ro,
+                                 const struct pipe_screen_config *config)
 {
-   return vc4_screen_create(fcntl(ro->gpu_fd, F_DUPFD_CLOEXEC, 3), ro);
+   return vc4_screen_create(ro->gpu_fd, ro);
 }