lkml.org 
[lkml]   [2017]   [Dec]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH 37/60] hyper_dmabuf: implementation of query ioctl
Date
List of queries is re-defined. Now it supports following
items:

enum hyper_dmabuf_query {
DMABUF_QUERY_TYPE = 0x10,
DMABUF_QUERY_EXPORTER,
DMABUF_QUERY_IMPORTER,
DMABUF_QUERY_SIZE,
DMABUF_QUERY_BUSY,
DMABUF_QUERY_UNEXPORTED,
DMABUF_QUERY_DELAYED_UNEXPORTED,
};

Also, actual querying part of the function is moved to hyper_dmabuf_query.c

Signed-off-by: Dongwon Kim <dongwon.kim@intel.com>
---
drivers/xen/hyper_dmabuf/Makefile | 1 +
drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c | 111 ++++++++++---------------
drivers/xen/hyper_dmabuf/hyper_dmabuf_query.c | 115 ++++++++++++++++++++++++++
drivers/xen/hyper_dmabuf/hyper_dmabuf_query.h | 38 +--------
include/uapi/xen/hyper_dmabuf.h | 17 ++++
5 files changed, 179 insertions(+), 103 deletions(-)
create mode 100644 drivers/xen/hyper_dmabuf/hyper_dmabuf_query.c

diff --git a/drivers/xen/hyper_dmabuf/Makefile b/drivers/xen/hyper_dmabuf/Makefile
index d90cfc3..8865f50 100644
--- a/drivers/xen/hyper_dmabuf/Makefile
+++ b/drivers/xen/hyper_dmabuf/Makefile
@@ -11,6 +11,7 @@ ifneq ($(KERNELRELEASE),)
hyper_dmabuf_msg.o \
hyper_dmabuf_id.o \
hyper_dmabuf_remote_sync.o \
+ hyper_dmabuf_query.o \

ifeq ($(CONFIG_XEN), y)
$(TARGET_MODULE)-objs += xen/hyper_dmabuf_xen_comm.o \
diff --git a/drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c b/drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c
index 375b664..12f7ce4 100644
--- a/drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c
+++ b/drivers/xen/hyper_dmabuf/hyper_dmabuf_ioctl.c
@@ -31,7 +31,7 @@
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/miscdevice.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
#include <linux/dma-buf.h>
#include <linux/delay.h>
#include <linux/list.h>
@@ -46,7 +46,7 @@

extern struct hyper_dmabuf_private hyper_dmabuf_private;

-static int hyper_dmabuf_tx_ch_setup(struct file *filp, void *data)
+static int hyper_dmabuf_tx_ch_setup_ioctl(struct file *filp, void *data)
{
struct ioctl_hyper_dmabuf_tx_ch_setup *tx_ch_attr;
struct hyper_dmabuf_backend_ops *ops = hyper_dmabuf_private.backend_ops;
@@ -63,7 +63,7 @@ static int hyper_dmabuf_tx_ch_setup(struct file *filp, void *data)
return ret;
}

-static int hyper_dmabuf_rx_ch_setup(struct file *filp, void *data)
+static int hyper_dmabuf_rx_ch_setup_ioctl(struct file *filp, void *data)
{
struct ioctl_hyper_dmabuf_rx_ch_setup *rx_ch_attr;
struct hyper_dmabuf_backend_ops *ops = hyper_dmabuf_private.backend_ops;
@@ -81,7 +81,7 @@ static int hyper_dmabuf_rx_ch_setup(struct file *filp, void *data)
return ret;
}

-static int hyper_dmabuf_export_remote(struct file *filp, void *data)
+static int hyper_dmabuf_export_remote_ioctl(struct file *filp, void *data)
{
struct ioctl_hyper_dmabuf_export_remote *export_remote_attr;
struct hyper_dmabuf_backend_ops *ops = hyper_dmabuf_private.backend_ops;
@@ -514,7 +514,7 @@ static void hyper_dmabuf_delayed_unexport(struct work_struct *work)

/* Schedules unexport of dmabuf.
*/
-static int hyper_dmabuf_unexport(struct file *filp, void *data)
+static int hyper_dmabuf_unexport_ioctl(struct file *filp, void *data)
{
struct ioctl_hyper_dmabuf_unexport *unexport_attr;
struct hyper_dmabuf_sgt_info *sgt_info;
@@ -554,11 +554,11 @@ static int hyper_dmabuf_unexport(struct file *filp, void *data)
return 0;
}

-static int hyper_dmabuf_query(struct file *filp, void *data)
+static int hyper_dmabuf_query_ioctl(struct file *filp, void *data)
{
struct ioctl_hyper_dmabuf_query *query_attr;
- struct hyper_dmabuf_sgt_info *sgt_info;
- struct hyper_dmabuf_imported_sgt_info *imported_sgt_info;
+ struct hyper_dmabuf_sgt_info *sgt_info = NULL;
+ struct hyper_dmabuf_imported_sgt_info *imported_sgt_info = NULL;
int ret = 0;

if (!data) {
@@ -568,71 +568,46 @@ static int hyper_dmabuf_query(struct file *filp, void *data)

query_attr = (struct ioctl_hyper_dmabuf_query *)data;

- sgt_info = hyper_dmabuf_find_exported(query_attr->hid);
- imported_sgt_info = hyper_dmabuf_find_imported(query_attr->hid);
-
- /* if dmabuf can't be found in both lists, return */
- if (!(sgt_info && imported_sgt_info)) {
- dev_err(hyper_dmabuf_private.device, "can't find entry anywhere\n");
- return -ENOENT;
- }
-
- /* not considering the case where a dmabuf is found on both queues
- * in one domain */
- switch (query_attr->item)
- {
- case DMABUF_QUERY_TYPE_LIST:
- if (sgt_info) {
- query_attr->info = EXPORTED;
- } else {
- query_attr->info = IMPORTED;
- }
- break;
-
- /* exporting domain of this specific dmabuf*/
- case DMABUF_QUERY_EXPORTER:
- if (sgt_info) {
- query_attr->info = 0xFFFFFFFF; /* myself */
- } else {
- query_attr->info = HYPER_DMABUF_DOM_ID(imported_sgt_info->hid);
- }
- break;
-
- /* importing domain of this specific dmabuf */
- case DMABUF_QUERY_IMPORTER:
- if (sgt_info) {
- query_attr->info = sgt_info->hyper_dmabuf_rdomain;
- } else {
-#if 0 /* TODO: a global variable, current_domain does not exist yet*/
- query_attr->info = current_domain;
-#endif
- }
- break;
-
- /* size of dmabuf in byte */
- case DMABUF_QUERY_SIZE:
- if (sgt_info) {
-#if 0 /* TODO: hyper_dmabuf_buf_size is not implemented yet */
- query_attr->info = hyper_dmabuf_buf_size(sgt_info->sgt);
-#endif
- } else {
- query_attr->info = imported_sgt_info->nents * 4096 -
- imported_sgt_info->frst_ofst - 4096 +
- imported_sgt_info->last_len;
- }
- break;
+ if (HYPER_DMABUF_DOM_ID(query_attr->hid) == hyper_dmabuf_private.domid) {
+ /* query for exported dmabuf */
+ sgt_info = hyper_dmabuf_find_exported(query_attr->hid);
+ if (sgt_info) {
+ ret = hyper_dmabuf_query_exported(sgt_info, query_attr->item);
+ if (ret != -EINVAL)
+ query_attr->info = ret;
+ } else {
+ dev_err(hyper_dmabuf_private.device,
+ "DMA BUF {id:%d key:%d %d %d} can't be found in the export list\n",
+ query_attr->hid.id, query_attr->hid.rng_key[0], query_attr->hid.rng_key[1],
+ query_attr->hid.rng_key[2]);
+ return -ENOENT;
+ }
+ } else {
+ /* query for imported dmabuf */
+ imported_sgt_info = hyper_dmabuf_find_imported(query_attr->hid);
+ if (imported_sgt_info) {
+ ret = hyper_dmabuf_query_imported(imported_sgt_info, query_attr->item);
+ if (ret != -EINVAL)
+ query_attr->info = ret;
+ } else {
+ dev_err(hyper_dmabuf_private.device,
+ "DMA BUF {id:%d key:%d %d %d} can't be found in the imported list\n",
+ query_attr->hid.id, query_attr->hid.rng_key[0], query_attr->hid.rng_key[1],
+ query_attr->hid.rng_key[2]);
+ return -ENOENT;
+ }
}

- return ret;
+ return 0;
}

static const struct hyper_dmabuf_ioctl_desc hyper_dmabuf_ioctls[] = {
- HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_TX_CH_SETUP, hyper_dmabuf_tx_ch_setup, 0),
- HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_RX_CH_SETUP, hyper_dmabuf_rx_ch_setup, 0),
- HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_EXPORT_REMOTE, hyper_dmabuf_export_remote, 0),
+ HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_TX_CH_SETUP, hyper_dmabuf_tx_ch_setup_ioctl, 0),
+ HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_RX_CH_SETUP, hyper_dmabuf_rx_ch_setup_ioctl, 0),
+ HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_EXPORT_REMOTE, hyper_dmabuf_export_remote_ioctl, 0),
HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_EXPORT_FD, hyper_dmabuf_export_fd_ioctl, 0),
- HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_UNEXPORT, hyper_dmabuf_unexport, 0),
- HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_QUERY, hyper_dmabuf_query, 0),
+ HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_UNEXPORT, hyper_dmabuf_unexport_ioctl, 0),
+ HYPER_DMABUF_IOCTL_DEF(IOCTL_HYPER_DMABUF_QUERY, hyper_dmabuf_query_ioctl, 0),
};

static long hyper_dmabuf_ioctl(struct file *filp,
@@ -731,7 +706,7 @@ static void hyper_dmabuf_emergency_release(struct hyper_dmabuf_sgt_info* sgt_inf
unexport_attr.hid = sgt_info->hid;
unexport_attr.delay_ms = 0;

- hyper_dmabuf_unexport(filp, &unexport_attr);
+ hyper_dmabuf_unexport_ioctl(filp, &unexport_attr);
}
}

diff --git a/drivers/xen/hyper_dmabuf/hyper_dmabuf_query.c b/drivers/xen/hyper_dmabuf/hyper_dmabuf_query.c
new file mode 100644
index 0000000..2a5201b
--- /dev/null
+++ b/drivers/xen/hyper_dmabuf/hyper_dmabuf_query.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright © 2017 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ * Dongwon Kim <dongwon.kim@intel.com>
+ * Mateusz Polrola <mateuszx.potrola@intel.com>
+ *
+ */
+
+#include <linux/dma-buf.h>
+#include "hyper_dmabuf_drv.h"
+#include "hyper_dmabuf_struct.h"
+#include "hyper_dmabuf_id.h"
+
+extern struct hyper_dmabuf_private hyper_dmabuf_private;
+
+#define HYPER_DMABUF_SIZE(nents, first_offset, last_len) \
+ ((nents)*PAGE_SIZE - (first_offset) - PAGE_SIZE + (last_len))
+
+int hyper_dmabuf_query_exported(struct hyper_dmabuf_sgt_info *sgt_info, int query)
+{
+ switch (query)
+ {
+ case HYPER_DMABUF_QUERY_TYPE:
+ return EXPORTED;
+
+ /* exporting domain of this specific dmabuf*/
+ case HYPER_DMABUF_QUERY_EXPORTER:
+ return HYPER_DMABUF_DOM_ID(sgt_info->hid);
+
+ /* importing domain of this specific dmabuf */
+ case HYPER_DMABUF_QUERY_IMPORTER:
+ return sgt_info->hyper_dmabuf_rdomain;
+
+ /* size of dmabuf in byte */
+ case HYPER_DMABUF_QUERY_SIZE:
+ return sgt_info->dma_buf->size;
+
+ /* whether the buffer is used by importer */
+ case HYPER_DMABUF_QUERY_BUSY:
+ return (sgt_info->importer_exported == 0) ? false : true;
+
+ /* whether the buffer is unexported */
+ case HYPER_DMABUF_QUERY_UNEXPORTED:
+ return !sgt_info->valid;
+
+ /* whether the buffer is scheduled to be unexported */
+ case HYPER_DMABUF_QUERY_DELAYED_UNEXPORTED:
+ return !sgt_info->unexport_scheduled;
+ }
+
+ return -EINVAL;
+}
+
+
+int hyper_dmabuf_query_imported(struct hyper_dmabuf_imported_sgt_info *imported_sgt_info, int query)
+{
+ switch (query)
+ {
+ case HYPER_DMABUF_QUERY_TYPE:
+ return IMPORTED;
+
+ /* exporting domain of this specific dmabuf*/
+ case HYPER_DMABUF_QUERY_EXPORTER:
+ return HYPER_DMABUF_DOM_ID(imported_sgt_info->hid);
+
+ /* importing domain of this specific dmabuf */
+ case HYPER_DMABUF_QUERY_IMPORTER:
+ return hyper_dmabuf_private.domid;
+
+ /* size of dmabuf in byte */
+ case HYPER_DMABUF_QUERY_SIZE:
+ if (imported_sgt_info->dma_buf) {
+ /* if local dma_buf is created (if it's ever mapped),
+ * retrieve it directly from struct dma_buf *
+ */
+ return imported_sgt_info->dma_buf->size;
+ } else {
+ /* calcuate it from given nents, frst_ofst and last_len */
+ return HYPER_DMABUF_SIZE(imported_sgt_info->nents,
+ imported_sgt_info->frst_ofst,
+ imported_sgt_info->last_len);
+ }
+
+ /* whether the buffer is used or not */
+ case HYPER_DMABUF_QUERY_BUSY:
+ /* checks if it's used by importer */
+ return (imported_sgt_info->num_importers > 0) ? true : false;
+
+ /* whether the buffer is unexported */
+ case HYPER_DMABUF_QUERY_UNEXPORTED:
+ return !imported_sgt_info->valid;
+ }
+
+ return -EINVAL;
+}
diff --git a/drivers/xen/hyper_dmabuf/hyper_dmabuf_query.h b/drivers/xen/hyper_dmabuf/hyper_dmabuf_query.h
index 6cf5b2d..295e923 100644
--- a/drivers/xen/hyper_dmabuf/hyper_dmabuf_query.h
+++ b/drivers/xen/hyper_dmabuf/hyper_dmabuf_query.h
@@ -1,40 +1,8 @@
-/*
- * Copyright © 2017 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- *
- */
-
#ifndef __HYPER_DMABUF_QUERY_H__
#define __HYPER_DMABUF_QUERY_H__

-enum hyper_dmabuf_query {
- DMABUF_QUERY_TYPE_LIST = 0x10,
- DMABUF_QUERY_EXPORTER,
- DMABUF_QUERY_IMPORTER,
- DMABUF_QUERY_SIZE
-};
+int hyper_dmabuf_query_imported(struct hyper_dmabuf_imported_sgt_info *imported_sgt_info, int query);

-enum hyper_dmabuf_status {
- EXPORTED = 0x01,
- IMPORTED
-};
+int hyper_dmabuf_query_exported(struct hyper_dmabuf_sgt_info *sgt_info, int query);

-#endif /* __HYPER_DMABUF_QUERY_H__ */
+#endif // __HYPER_DMABUF_QUERY_H__
diff --git a/include/uapi/xen/hyper_dmabuf.h b/include/uapi/xen/hyper_dmabuf.h
index 992a542..bee0f86 100644
--- a/include/uapi/xen/hyper_dmabuf.h
+++ b/include/uapi/xen/hyper_dmabuf.h
@@ -98,4 +98,21 @@ struct ioctl_hyper_dmabuf_query {
int info;
};

+/* DMABUF query */
+
+enum hyper_dmabuf_query {
+ HYPER_DMABUF_QUERY_TYPE = 0x10,
+ HYPER_DMABUF_QUERY_EXPORTER,
+ HYPER_DMABUF_QUERY_IMPORTER,
+ HYPER_DMABUF_QUERY_SIZE,
+ HYPER_DMABUF_QUERY_BUSY,
+ HYPER_DMABUF_QUERY_UNEXPORTED,
+ HYPER_DMABUF_QUERY_DELAYED_UNEXPORTED,
+};
+
+enum hyper_dmabuf_status {
+ EXPORTED= 0x01,
+ IMPORTED,
+};
+
#endif //__LINUX_PUBLIC_HYPER_DMABUF_H__
--
2.7.4
\
 
 \ /
  Last update: 2017-12-19 20:44    [W:0.243 / U:0.004 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site