From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUwrE-0002EX-BD for qemu-devel@nongnu.org; Mon, 18 Jun 2018 12:18:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fUwrA-0005DO-0H for qemu-devel@nongnu.org; Mon, 18 Jun 2018 12:18:20 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44994 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fUwr9-0005DE-R7 for qemu-devel@nongnu.org; Mon, 18 Jun 2018 12:18:15 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7A375401EF03 for ; Mon, 18 Jun 2018 16:18:15 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Mon, 18 Jun 2018 18:17:21 +0200 Message-Id: <20180618161729.334-19-marcandre.lureau@redhat.com> In-Reply-To: <20180618161729.334-1-marcandre.lureau@redhat.com> References: <20180618161729.334-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v3 18/26] util: promote qemu_egl_rendernode_open() to libqemuutil List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: berrange@redhat.com, kraxel@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= vhost-user-gpu will share the same code to open a DRM node. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/qemu/drm.h | 6 +++++ ui/egl-helpers.c | 51 ++--------------------------------- util/drm.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + util/Makefile.objs | 1 + 5 files changed, 76 insertions(+), 49 deletions(-) create mode 100644 include/qemu/drm.h create mode 100644 util/drm.c diff --git a/include/qemu/drm.h b/include/qemu/drm.h new file mode 100644 index 0000000000..4c3e622f5c --- /dev/null +++ b/include/qemu/drm.h @@ -0,0 +1,6 @@ +#ifndef QEMU_DRM_H_ +#define QEMU_DRM_H_ + +int qemu_drm_rendernode_open(const char *rendernode); + +#endif diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c index 16dc3ded36..472a8aa5f0 100644 --- a/ui/egl-helpers.c +++ b/ui/egl-helpers.c @@ -15,9 +15,7 @@ * License along with this library; if not, see . */ #include "qemu/osdep.h" -#include -#include - +#include "qemu/drm.h" #include "qemu/error-report.h" #include "ui/console.h" #include "ui/egl-helpers.h" @@ -146,57 +144,12 @@ int qemu_egl_rn_fd; struct gbm_device *qemu_egl_rn_gbm_dev; EGLContext qemu_egl_rn_ctx; =20 -static int qemu_egl_rendernode_open(const char *rendernode) -{ - DIR *dir; - struct dirent *e; - int r, fd; - char *p; - - if (rendernode) { - return open(rendernode, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLO= CK); - } - - dir =3D opendir("/dev/dri"); - if (!dir) { - return -1; - } - - fd =3D -1; - while ((e =3D readdir(dir))) { - if (e->d_type !=3D DT_CHR) { - continue; - } - - if (strncmp(e->d_name, "renderD", 7)) { - continue; - } - - p =3D g_strdup_printf("/dev/dri/%s", e->d_name); - - r =3D open(p, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK); - if (r < 0) { - g_free(p); - continue; - } - fd =3D r; - g_free(p); - break; - } - - closedir(dir); - if (fd < 0) { - return -1; - } - return fd; -} - int egl_rendernode_init(const char *rendernode) { qemu_egl_rn_fd =3D -1; int rc; =20 - qemu_egl_rn_fd =3D qemu_egl_rendernode_open(rendernode); + qemu_egl_rn_fd =3D qemu_drm_rendernode_open(rendernode); if (qemu_egl_rn_fd =3D=3D -1) { error_report("egl: no drm render node available"); goto err; diff --git a/util/drm.c b/util/drm.c new file mode 100644 index 0000000000..a23ff24538 --- /dev/null +++ b/util/drm.c @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2015-2016 Gerd Hoffmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ +#include "qemu/osdep.h" +#include "qemu/drm.h" + +#include +#include + +int qemu_drm_rendernode_open(const char *rendernode) +{ + DIR *dir; + struct dirent *e; + int r, fd; + char *p; + + if (rendernode) { + return open(rendernode, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLO= CK); + } + + dir =3D opendir("/dev/dri"); + if (!dir) { + return -1; + } + + fd =3D -1; + while ((e =3D readdir(dir))) { + if (e->d_type !=3D DT_CHR) { + continue; + } + + if (strncmp(e->d_name, "renderD", 7)) { + continue; + } + + p =3D g_strdup_printf("/dev/dri/%s", e->d_name); + + r =3D open(p, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK); + if (r < 0) { + g_free(p); + continue; + } + fd =3D r; + g_free(p); + break; + } + + closedir(dir); + if (fd < 0) { + return -1; + } + return fd; +} diff --git a/MAINTAINERS b/MAINTAINERS index e5dee15967..42a5d46acd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1533,6 +1533,7 @@ S: Odd Fixes F: ui/ F: include/ui/ F: qapi/ui.json +F: util/drm.c =20 Cocoa graphics M: Peter Maydell diff --git a/util/Makefile.objs b/util/Makefile.objs index e1c3fed4dc..1810f970ef 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -49,3 +49,4 @@ util-obj-y +=3D stats64.o util-obj-y +=3D systemd.o util-obj-y +=3D iova-tree.o util-obj-$(CONFIG_LINUX) +=3D vfio-helpers.o +util-obj-$(CONFIG_LINUX) +=3D drm.o --=20 2.18.0.rc1