Skip to contentSkip to conversation

Add udmabuf misc device

PATCH Superseded Gerd Hoffmann 1 participant 1 message May 30, 2018

Subsystems (4)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Gerd Hoffmann

author maintainer
#0 lore raw

PATCH v4 1/1 Add udmabuf misc device

A driver to let userspace turn memfd regions into dma-bufs.

Use case: Allows qemu create dmabufs for the vga framebuffer or virtio-gpu ressources. Then they can be passed around to display those guest things on the host. To spice client for classic full framebuffer display, and hopefully some day to wayland server for seamless guest window display.

qemu test branch:
https://git.kraxel.org/cgit/qemu/log/?h=sirius/udmabuf

Cc David Airlie <[email protected]>
Cc Tomeu Vizoso <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 include/uapi/linux/udmabuf.h                      |  33 ++
 drivers/dma-buf/udmabuf.c                         | 362 ++++++++++++++++++++++
 tools/testing/selftests/drivers/dma-buf/udmabuf.c |  95 ++++++
 drivers/dma-buf/Kconfig                           |   7 +
 drivers/dma-buf/Makefile                          |   1 +
 tools/testing/selftests/drivers/dma-buf/Makefile  |   5 +
 6 files changed, 503 insertions(+)
 create mode 100644 include/uapi/linux/udmabuf.h
 create mode 100644 drivers/dma-buf/udmabuf.c
 create mode 100644 tools/testing/selftests/drivers/dma-buf/udmabuf.c
 create mode 100644 tools/testing/selftests/drivers/dma-buf/Makefile
include/uapi/linux/udmabuf.h new file +33 -0
new file mode 100644
index 0000000000..831a66f972
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _UAPI_LINUX_UDMABUF_H
+#define _UAPI_LINUX_UDMABUF_H
+
+#include <linux/types.h>
+#include <linux/ioctl.h>
+
+#define UDMABUF_FLAGS_CLOEXEC	0x01
+
+struct udmabuf_create {
+	__u32 memfd;
+	__u32 flags;
+	__u64 offset;
+	__u64 size;
+};
+
+struct udmabuf_create_item {
+	__u32 memfd;
+	__u32 __pad;
+	__u64 offset;
+	__u64 size;
+};
+
+struct udmabuf_create_list {
+	__u32 flags;
+	__u32 count;
+	struct udmabuf_create_item list[];
+};
+
+#define UDMABUF_CREATE       _IOW(0x42, 0x23, struct udmabuf_create)
+#define UDMABUF_CREATE_LIST  _IOW(0x42, 0x24, struct udmabuf_create_list)
+
+#endif /* _UAPI_LINUX_UDMABUF_H */
drivers/dma-buf/udmabuf.c new file +362 -0

362 lines not on this page · raw message

tools/testing/selftests/drivers/dma-buf/udmabuf.c new file +95 -0

95 lines not on this page · raw message

drivers/dma-buf/Kconfig +7 -0
index ed3b785bae..19be3ec62d 100644
@@ -30,4 +30,11 @@ config SW_SYNC
 	  WARNING: improper use of this can result in deadlocking kernel
 	  drivers from userspace. Intended for test and debug only.
 
+config UDMABUF
+	bool "userspace dmabuf misc driver"
+	default n
+	depends on DMA_SHARED_BUFFER
+	---help---
+	  A driver to let userspace turn iovs into dma-bufs.
+
 endmenu
drivers/dma-buf/Makefile +1 -0
index c33bf88631..0913a6ccab 100644
@@ -1,3 +1,4 @@
 obj-y := dma-buf.o dma-fence.o dma-fence-array.o reservation.o seqno-fence.o
 obj-$(CONFIG_SYNC_FILE)		+= sync_file.o
 obj-$(CONFIG_SW_SYNC)		+= sw_sync.o sync_debug.o
+obj-$(CONFIG_UDMABUF)		+= udmabuf.o
tools/testing/selftests/drivers/dma-buf/Makefile new file +5 -0
new file mode 100644
index 0000000000..4154c3d7aa
@@ -0,0 +1,5 @@
+CFLAGS += -I../../../../../usr/include/
+
+TEST_GEN_PROGS := udmabuf
+
+include ../../lib.mk
Signature · 1 line
2.9.3