summaryrefslogtreecommitdiffstats
path: root/ui/udmabuf.c
diff options
context:
space:
mode:
authorVivek Kasireddy2021-05-27 01:14:16 +0200
committerGerd Hoffmann2021-05-27 12:06:01 +0200
commit87f12216d9268ed90e6114a22cbc3f53b0fd8457 (patch)
treed63c5588b99b1f856f7d4ee9438fef50b6d58771 /ui/udmabuf.c
parenthw/display/qxl: Set pci rom address aligned with page size (diff)
downloadqemu-87f12216d9268ed90e6114a22cbc3f53b0fd8457.tar.gz
qemu-87f12216d9268ed90e6114a22cbc3f53b0fd8457.tar.xz
qemu-87f12216d9268ed90e6114a22cbc3f53b0fd8457.zip
ui: Get the fd associated with udmabuf driver
Try to open the udmabuf dev node for the first time or return the fd if the device was previously opened. Based-on-patch-by: Gerd Hoffmann <kraxel@redhat.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com> Message-Id: <20210526231429.1045476-2-vivek.kasireddy@intel.com> [ kraxel: fixup fcntl.h include ] Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'ui/udmabuf.c')
-rw-r--r--ui/udmabuf.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/ui/udmabuf.c b/ui/udmabuf.c
new file mode 100644
index 0000000000..23abe1e7eb
--- /dev/null
+++ b/ui/udmabuf.c
@@ -0,0 +1,40 @@
+/*
+ * udmabuf helper functions.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "ui/console.h"
+
+#ifdef CONFIG_LINUX
+
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+int udmabuf_fd(void)
+{
+ static bool first = true;
+ static int udmabuf;
+
+ if (!first) {
+ return udmabuf;
+ }
+ first = false;
+
+ udmabuf = open("/dev/udmabuf", O_RDWR);
+ if (udmabuf < 0) {
+ warn_report("open /dev/udmabuf: %s", strerror(errno));
+ }
+ return udmabuf;
+}
+
+#else
+
+int udmabuf_fd(void)
+{
+ return -1;
+}
+
+#endif