| From 989e8454e2ee6195ae93660cc0f86836292f7048 Mon Sep 17 00:00:00 2001 | |
| From: Zach Reizner <zachr@google.com> | |
| Date: Mon, 14 Aug 2017 17:16:55 -0700 | |
| Subject: [PATCH] CHROMIUM: virtwl: add virtwl driver | |
| TEST=emerge-tatl chromeos-kernel-4_4 | |
| BUG=chromium:738638 | |
| Change-Id: I6e8e128a5548c915a9561938cbb066edc8c42747 | |
| Reviewed-on: https://chromium-review.googlesource.com/567299 | |
| Commit-Ready: Zach Reizner <zachr@chromium.org> | |
| Tested-by: Zach Reizner <zachr@chromium.org> | |
| Reviewed-by: Zach Reizner <zachr@chromium.org> | |
| --- | |
| include/uapi/linux/virtio_ids.h | 1 + | |
| include/uapi/linux/virtio_wl.h | 89 +++++++++++++++++++++++++++++++++ | |
| include/uapi/linux/virtwl.h | 60 ++++++++++++++++++++++ | |
| 3 files changed, 150 insertions(+) | |
| create mode 100644 include/uapi/linux/virtio_wl.h | |
| create mode 100644 include/uapi/linux/virtwl.h | |
| diff --git a/include/uapi/linux/virtio_ids.h b/include/uapi/linux/virtio_ids.h | |
| index 6d5c3b2d4f4d..293872af086b 100644 | |
| --- a/include/uapi/linux/virtio_ids.h | |
| +++ b/include/uapi/linux/virtio_ids.h | |
| @@ -43,5 +43,6 @@ | |
| #define VIRTIO_ID_INPUT 18 /* virtio input */ | |
| #define VIRTIO_ID_VSOCK 19 /* virtio vsock transport */ | |
| #define VIRTIO_ID_CRYPTO 20 /* virtio crypto */ | |
| +#define VIRTIO_ID_WL 30 /* virtio wayland */ | |
| #endif /* _LINUX_VIRTIO_IDS_H */ | |
| diff --git a/include/uapi/linux/virtio_wl.h b/include/uapi/linux/virtio_wl.h | |
| new file mode 100644 | |
| index 000000000000..41380d018e0e | |
| --- /dev/null | |
| +++ b/include/uapi/linux/virtio_wl.h | |
| @@ -0,0 +1,89 @@ | |
| +#ifndef _LINUX_VIRTIO_WL_H | |
| +#define _LINUX_VIRTIO_WL_H | |
| +/* This header is BSD licensed so anyone can use the definitions to implement | |
| + * compatible drivers/servers. */ | |
| +#include <linux/virtio_ids.h> | |
| +#include <linux/virtio_config.h> | |
| +#include <linux/virtwl.h> | |
| + | |
| + | |
| +#define VIRTWL_IN_BUFFER_SIZE 4096 | |
| +#define VIRTWL_OUT_BUFFER_SIZE 4096 | |
| +#define VIRTWL_VQ_IN 0 | |
| +#define VIRTWL_VQ_OUT 1 | |
| +#define VIRTWL_QUEUE_COUNT 2 | |
| +#define VIRTWL_MAX_ALLOC 0x800 | |
| +#define VIRTWL_PFN_SHIFT 12 | |
| + | |
| +struct virtio_wl_config { | |
| + | |
| +}; | |
| + | |
| +/* | |
| + * The structure of each of these is virtio_wl_ctrl_hdr or one of its subclasses | |
| + * where noted. */ | |
| +enum virtio_wl_ctrl_type { | |
| + VIRTIO_WL_CMD_VFD_NEW = 0x100, /* virtio_wl_ctrl_vfd_new */ | |
| + VIRTIO_WL_CMD_VFD_CLOSE, /* virtio_wl_ctrl_vfd */ | |
| + VIRTIO_WL_CMD_VFD_SEND, /* virtio_wl_ctrl_vfd_send + data */ | |
| + VIRTIO_WL_CMD_VFD_RECV, /* virtio_wl_ctrl_vfd_recv + data */ | |
| + VIRTIO_WL_CMD_VFD_NEW_CTX, /* virtio_wl_ctrl_vfd */ | |
| + VIRTIO_WL_CMD_VFD_NEW_CTX, /* virtio_wl_ctrl_vfd_new */ | |
| + VIRTIO_WL_CMD_VFD_NEW_PIPE, /* virtio_wl_ctrl_vfd_new */ | |
| + | |
| + VIRTIO_WL_RESP_OK = 0x1000, | |
| + VIRTIO_WL_RESP_VFD_NEW = 0x1001, /* virtio_wl_ctrl_vfd_new */ | |
| + | |
| + VIRTIO_WL_RESP_ERR = 0x1100, | |
| + VIRTIO_WL_RESP_OUT_OF_MEMORY, | |
| + VIRTIO_WL_RESP_INVALID_ID, | |
| + VIRTIO_WL_RESP_INVALID_TYPE, | |
| + VIRTIO_WL_RESP_INVALID_FLAGS, | |
| + VIRTIO_WL_RESP_INVALID_CMD, | |
| +}; | |
| + | |
| +struct virtio_wl_ctrl_hdr { | |
| + __le32 type; /* one of virtio_wl_ctrl_type */ | |
| + __le32 flags; /* always 0 */ | |
| +}; | |
| + | |
| +enum virtio_wl_vfd_flags { | |
| + VIRTIO_WL_VFD_WRITE = 0x1, /* intended to be written by guest */ | |
| + VIRTIO_WL_VFD_READ = 0x2, /* intended to be read by guest */ | |
| +}; | |
| + | |
| +struct virtio_wl_ctrl_vfd { | |
| + struct virtio_wl_ctrl_hdr hdr; | |
| + __le32 vfd_id; | |
| +}; | |
| + | |
| +/* | |
| + * If this command is sent to the guest, it indicates that the VFD has been | |
| + * created and the fields indicate the properties of the VFD being offered. | |
| + * | |
| + * If this command is sent to the host, it represents a request to create a VFD | |
| + * of the given properties. The pfn field is ignored by the host. | |
| + */ | |
| +struct virtio_wl_ctrl_vfd_new { | |
| + struct virtio_wl_ctrl_hdr hdr; | |
| + __le32 vfd_id; /* MSB indicates device allocated vfd */ | |
| + __le32 flags; /* virtio_wl_vfd_flags */ | |
| + __le64 pfn; /* first guest physical page frame number if VIRTIO_WL_VFD_MAP */ | |
| + __le32 size; /* size in bytes if VIRTIO_WL_VFD_MAP */ | |
| +}; | |
| + | |
| +struct virtio_wl_ctrl_vfd_send { | |
| + struct virtio_wl_ctrl_hdr hdr; | |
| + __le32 vfd_id; | |
| + __le32 vfd_count; /* struct is followed by this many IDs */ | |
| + /* the remainder is raw data */ | |
| +}; | |
| + | |
| +struct virtio_wl_ctrl_vfd_recv { | |
| + struct virtio_wl_ctrl_hdr hdr; | |
| + __le32 vfd_id; | |
| + __le32 vfd_count; /* struct is followed by this many IDs */ | |
| + /* the remainder is raw data */ | |
| +}; | |
| + | |
| +#endif /* _LINUX_VIRTIO_WL_H */ | |
| diff --git a/include/uapi/linux/virtwl.h b/include/uapi/linux/virtwl.h | |
| new file mode 100644 | |
| index 000000000000..3318717dbc07 | |
| --- /dev/null | |
| +++ b/include/uapi/linux/virtwl.h | |
| @@ -0,0 +1,60 @@ | |
| +#ifndef _LINUX_VIRTWL_H | |
| +#define _LINUX_VIRTWL_H | |
| + | |
| +#include <asm/ioctl.h> | |
| +#include <linux/types.h> | |
| + | |
| +#define VIRTWL_SEND_MAX_ALLOCS 28 | |
| + | |
| +#define VIRTWL_IOCTL_BASE 'w' | |
| +#define VIRTWL_IO(nr) _IO(VIRTWL_IOCTL_BASE,nr) | |
| +#define VIRTWL_IOR(nr,type) _IOR(VIRTWL_IOCTL_BASE,nr,type) | |
| +#define VIRTWL_IOW(nr,type) _IOW(VIRTWL_IOCTL_BASE,nr,type) | |
| +#define VIRTWL_IOWR(nr,type) _IOWR(VIRTWL_IOCTL_BASE,nr,type) | |
| + | |
| +enum virtwl_ioctl_new_type { | |
| + VIRTWL_IOCTL_NEW_CTX, /* open a new wayland connection context */ | |
| + VIRTWL_IOCTL_NEW_ALLOC, /* create a new virtwl shm allocation */ | |
| + VIRTWL_IOCTL_NEW_PIPE_READ, /* create a new virtwl pipe that is readable via the returned fd */ | |
| + VIRTWL_IOCTL_NEW_PIPE_WRITE, /* create a new virtwl pipe that is writable via the returned fd */ | |
| + VIRTWL_IOCTL_NEW_DMABUF, /* create a new virtwl dmabuf that is writable via the returned fd */ | |
| +}; | |
| + | |
| +struct virtwl_ioctl_new { | |
| + __u32 type; /* VIRTWL_IOCTL_NEW_* */ | |
| + int fd; /* return fd */ | |
| + __u32 flags; /* currently always 0 */ | |
| + union { | |
| + __u32 size; /* size of allocation if type == VIRTWL_IOCTL_NEW_ALLOC */ | |
| + struct { | |
| + __u32 width; /* width in pixels */ | |
| + __u32 height; /* height in pixels */ | |
| + __u32 format; /* fourcc format */ | |
| + __u32 stride0; /* return stride0 */ | |
| + __u32 stride1; /* return stride1 */ | |
| + __u32 stride2; /* return stride2 */ | |
| + __u32 offset0; /* return offset0 */ | |
| + __u32 offset1; /* return offset1 */ | |
| + __u32 offset2; /* return offset2 */ | |
| + } dmabuf; | |
| + }; | |
| +}; | |
| + | |
| +struct virtwl_ioctl_txn { | |
| + int fds[VIRTWL_SEND_MAX_ALLOCS]; | |
| + __u32 len; | |
| + __u8 data[0]; | |
| +}; | |
| + | |
| +struct virtwl_ioctl_dmabuf_sync { | |
| + __u32 flags; /* synchronization flags (see dma-buf.h) */ | |
| +}; | |
| + | |
| +#define VIRTWL_IOCTL_NEW VIRTWL_IOWR(0x00, struct virtwl_ioctl_new) | |
| +#define VIRTWL_IOCTL_SEND VIRTWL_IOR(0x01, struct virtwl_ioctl_txn) | |
| +#define VIRTWL_IOCTL_RECV VIRTWL_IOW(0x02, struct virtwl_ioctl_txn) | |
| +#define VIRTWL_IOCTL_DMABUF_SYNC VIRTWL_IOR(0x03, \ | |
| + struct virtwl_ioctl_dmabuf_sync) | |
| + | |
| + | |
| +#endif /* _LINUX_VIRTWL_H */ | |
| -- | |
| 2.22.0.657.g960e92d24f-goog | |