From patchwork Tue Aug 21 12:05:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 960216 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41vqSf3kBfz9s78 for ; Tue, 21 Aug 2018 22:17:54 +1000 (AEST) Received: from localhost ([::1]:52744 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fs5bc-0002c0-3e for incoming@patchwork.ozlabs.org; Tue, 21 Aug 2018 08:17:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58298) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fs5Xp-0007Iu-6W for qemu-devel@nongnu.org; Tue, 21 Aug 2018 08:13:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fs5Q0-0008P5-RH for qemu-devel@nongnu.org; Tue, 21 Aug 2018 08:05:57 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60964 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 1fs5Q0-0008Of-K2 for qemu-devel@nongnu.org; Tue, 21 Aug 2018 08:05:52 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4B2ED7D84D for ; Tue, 21 Aug 2018 12:05:52 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-184.ams2.redhat.com [10.36.116.184]) by smtp.corp.redhat.com (Postfix) with ESMTP id A86AE2026D64; Tue, 21 Aug 2018 12:05:49 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id D56869B2FF; Tue, 21 Aug 2018 14:05:42 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 21 Aug 2018 14:05:42 +0200 Message-Id: <20180821120542.22610-13-kraxel@redhat.com> In-Reply-To: <20180821120542.22610-1-kraxel@redhat.com> References: <20180821120542.22610-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 21 Aug 2018 12:05:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 21 Aug 2018 12:05:52 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kraxel@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 12/12] util: promote qemu_egl_rendernode_open() to libqemuutil X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: libvir-list@redhat.com, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau vhost-user-gpu will share the same code to open a DRM node. Signed-off-by: Marc-André Lureau Message-Id: <20180713130916.4153-20-marcandre.lureau@redhat.com> Signed-off-by: Gerd Hoffmann --- 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 71b6a97bd1..4f475142fc 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" @@ -147,57 +145,12 @@ int qemu_egl_rn_fd; struct gbm_device *qemu_egl_rn_gbm_dev; EGLContext qemu_egl_rn_ctx; -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_NONBLOCK); - } - - dir = opendir("/dev/dri"); - if (!dir) { - return -1; - } - - fd = -1; - while ((e = readdir(dir))) { - if (e->d_type != DT_CHR) { - continue; - } - - if (strncmp(e->d_name, "renderD", 7)) { - continue; - } - - p = g_strdup_printf("/dev/dri/%s", e->d_name); - - r = open(p, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK); - if (r < 0) { - g_free(p); - continue; - } - fd = r; - g_free(p); - break; - } - - closedir(dir); - if (fd < 0) { - return -1; - } - return fd; -} - int egl_rendernode_init(const char *rendernode, DisplayGLMode mode) { qemu_egl_rn_fd = -1; int rc; - qemu_egl_rn_fd = qemu_egl_rendernode_open(rendernode); + qemu_egl_rn_fd = qemu_drm_rendernode_open(rendernode); if (qemu_egl_rn_fd == -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_NONBLOCK); + } + + dir = opendir("/dev/dri"); + if (!dir) { + return -1; + } + + fd = -1; + while ((e = readdir(dir))) { + if (e->d_type != DT_CHR) { + continue; + } + + if (strncmp(e->d_name, "renderD", 7)) { + continue; + } + + p = g_strdup_printf("/dev/dri/%s", e->d_name); + + r = open(p, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK); + if (r < 0) { + g_free(p); + continue; + } + fd = r; + g_free(p); + break; + } + + closedir(dir); + if (fd < 0) { + return -1; + } + return fd; +} diff --git a/MAINTAINERS b/MAINTAINERS index 6902a568f4..282d6a8ae5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1566,6 +1566,7 @@ S: Odd Fixes F: ui/ F: include/ui/ F: qapi/ui.json +F: util/drm.c 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 += stats64.o util-obj-y += systemd.o util-obj-y += iova-tree.o util-obj-$(CONFIG_LINUX) += vfio-helpers.o +util-obj-$(CONFIG_LINUX) += drm.o