[PATCH v2 17/32] drm/via: Add via_ioctl.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Kevin Brace <kevinbrace@xxxxxxxxxxxxxxxxxxxx>

Signed-off-by: Kevin Brace <kevinbrace@xxxxxxxxxxxxxxxxxxxx>
---
 drivers/gpu/drm/via/via_ioctl.c | 122 ++++++++++++++++++++++++++++++++
 1 file changed, 122 insertions(+)
 create mode 100644 drivers/gpu/drm/via/via_ioctl.c

diff --git a/drivers/gpu/drm/via/via_ioctl.c b/drivers/gpu/drm/via/via_ioctl.c
new file mode 100644
index 000000000000..24d72bf4d53a
--- /dev/null
+++ b/drivers/gpu/drm/via/via_ioctl.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright © 2020 Kevin Brace.
+ *
+ * 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, sub license,
+ * 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 NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) 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.
+ *
+ * Author(s):
+ * Kevin Brace <kevinbrace@xxxxxxxxxxxxxxxxxxxx>
+ */
+
+#include <drm/drm_gem.h>
+#include <drm/drm_ioctl.h>
+
+#include <drm/ttm/ttm_bo_api.h>
+
+#include <uapi/drm/via_drm.h>
+
+#include "via_drv.h"
+
+
+static int via_gem_create_ioctl(struct drm_device *dev,
+					void *data,
+					struct drm_file *file_priv)
+{
+	struct drm_via_gem_create *args = data;
+	struct ttm_buffer_object *ttm_bo;
+	struct via_drm_priv *dev_priv = to_via_drm_priv(dev);
+	struct via_bo *bo;
+	uint32_t handle;
+	int ret;
+
+	DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+	ret = via_bo_create(dev, &dev_priv->bdev, args->size,
+				ttm_bo_type_device, args->domain, false, &bo);
+	if (ret) {
+		goto exit;
+	}
+
+	ttm_bo = &bo->ttm_bo;
+
+	ret = drm_gem_handle_create(file_priv, &ttm_bo->base, &handle);
+	drm_gem_object_put(&ttm_bo->base);
+	if (ret) {
+		via_bo_destroy(bo, false);
+		goto exit;
+	}
+
+	args->size	= ttm_bo->base.size;
+	args->domain	= ttm_bo->resource->placement;
+	args->handle	= handle;
+	args->offset	= ttm_bo->resource->start << PAGE_SHIFT;
+exit:
+	DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+	return ret;
+}
+
+static int via_gem_map_ioctl(struct drm_device *dev,
+					void *data,
+					struct drm_file *file_priv)
+{
+	struct drm_via_gem_map *args = data;
+	struct drm_gem_object *gem;
+	struct ttm_buffer_object *ttm_bo;
+	int ret = 0;
+
+	DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+	gem = drm_gem_object_lookup(file_priv, args->handle);
+	if (!gem) {
+		ret = -EINVAL;
+		goto exit;
+	}
+
+	ttm_bo = container_of(gem, struct ttm_buffer_object, base);
+
+	args->map_offset = drm_vma_node_offset_addr(&ttm_bo->base.vma_node);
+exit:
+	DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+	return ret;
+}
+
+static int via_gem_unmap_ioctl(struct drm_device *dev,
+				void *data,
+				struct drm_file *file_priv)
+{
+	struct drm_via_gem_unmap *args = data;
+	int ret;
+
+	DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+	ret = drm_gem_handle_delete(file_priv, args->handle);
+
+	DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+	return ret;
+}
+
+
+const struct drm_ioctl_desc via_driver_ioctls[] = {
+	DRM_IOCTL_DEF_DRV(VIA_GEM_CREATE, via_gem_create_ioctl, DRM_AUTH | DRM_UNLOCKED),
+	DRM_IOCTL_DEF_DRV(VIA_GEM_MAP, via_gem_map_ioctl, DRM_AUTH | DRM_UNLOCKED),
+	DRM_IOCTL_DEF_DRV(VIA_GEM_UNMAP, via_gem_unmap_ioctl, DRM_AUTH | DRM_UNLOCKED),
+};
+
+
+int via_driver_num_ioctls = ARRAY_SIZE(via_driver_ioctls);
--
2.35.1





[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux