Skip to contentSkip to conversation

Support for Tegra 2D hardware

PATCH Superseded Terje Bergstrom 2 participants 14 messages Mar 13, 2013 – Mar 19, 2013

Subsystems (6)

v7 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v7 cover Support for Tegra 2D hardware

This set of patches adds support for Tegra20 and Tegra30 host1x and 2D. It is based on linux-next-20130307.

Changes in this version:
* host1x memory data structures refactored
* Some "nvhost" leftovers renamed to host1x

Changes in previous version 6:
* Rebased on latest tegradrm
* Renamed tegradrm's host1x to host1x_drm
* Indentation and line split fixed to follow tegradrm convention
* Pointers to platform_device replaced with pointers to device
* Added host1x allocator, and wired it in
* Debug spew code fixed to access mem handles from host1x_job
* CDMA code doesn't keep the mem handles anymore
* Push buffer ops have been made generic code
* Removed the pin_array optimization in host1x_job to simplify code
* Large number of smaller changes

The driver implements an allocator using the DRM CMA helper. Each buffer is assigned an ops structure to operate on it. In future the DRM CMA helper will be replaced with an own allocator to implement IOMMU support.

host1x is the driver that controls host1x hardware. It supports host1x command channels, synchronization, and memory management. It is sectioned into logical driver under drivers/gpu/host1x and physical driver under drivers/host1x/hw. The physical driver is compiled with the hardware headers of the particular host1x version.

The hardware units are described (briefly) in the Tegra2 TRM. Wiki page http://http.download.nvidia.com/tegra-public-appnotes/host1x.html
also contains a short description of the functionality.

The patch set merges tegradrm into host1x and adds 2D driver, which uses host1x channels and sync points. The patch set also adds user space API to tegradrm for accessing host1x and 2D.

The changes to add support to libdrm are in
[email protected]:linux-host1x/libdrm-host1x.git

Arto Merilainen (3):
gpu: drm: Support CMA object preallocation
gpu: host1x: drm: Rename host1x to host1x_drm
gpu: host1x: drm: Add CMA ops for host1x driver

Terje Bergstrom (7):
gpu: host1x: Add host1x driver
gpu: host1x: Add syncpoint wait and interrupts
gpu: host1x: Add channel support
gpu: host1x: Add debug support
drm: tegra: Move drm to live under host1x
gpu: host1x: Remove second host1x driver
drm: tegra: Add gr2d device

 drivers/gpu/Makefile                           |    1 +
 drivers/gpu/drm/Kconfig                        |    2 -
 drivers/gpu/drm/Makefile                       |    1 -
 drivers/gpu/drm/drm_gem_cma_helper.c           |   78 ++-
 drivers/gpu/drm/tegra/Makefile                 |    7 -
 drivers/gpu/drm/tegra/drm.c                    |  217 --------
 drivers/gpu/drm/tegra/host1x.c                 |  327 ------------
 drivers/gpu/host1x/Kconfig                     |   23 +
 drivers/gpu/host1x/Makefile                    |   20 +
 drivers/gpu/host1x/cdma.c                      |  491 +++++++++++++++++
 drivers/gpu/host1x/cdma.h                      |  100 ++++
 drivers/gpu/host1x/channel.c                   |  120 +++++
 drivers/gpu/host1x/channel.h                   |   52 ++
 drivers/gpu/host1x/debug.c                     |  210 ++++++++
 drivers/gpu/host1x/debug.h                     |   51 ++
 drivers/gpu/host1x/dev.c                       |  248 +++++++++
 drivers/gpu/host1x/dev.h                       |  316 +++++++++++
 drivers/gpu/{drm/tegra => host1x/drm}/Kconfig  |    2 +-
 drivers/gpu/host1x/drm/cma.c                   |   93 ++++
 drivers/gpu/host1x/drm/cma.h                   |   35 ++
 drivers/gpu/{drm/tegra => host1x/drm}/dc.c     |    5 +-
 drivers/gpu/{drm/tegra => host1x/drm}/dc.h     |    0
 drivers/gpu/host1x/drm/drm.c                   |  673 ++++++++++++++++++++++++
 drivers/gpu/{drm/tegra => host1x/drm}/drm.h    |   51 +-
 drivers/gpu/{drm/tegra => host1x/drm}/fb.c     |    6 +-
 drivers/gpu/host1x/drm/gr2d.c                  |  330 ++++++++++++
 drivers/gpu/{drm/tegra => host1x/drm}/hdmi.c   |    5 +-
 drivers/gpu/{drm/tegra => host1x/drm}/hdmi.h   |    0
 drivers/gpu/{drm/tegra => host1x/drm}/output.c |    0
 drivers/gpu/{drm/tegra => host1x/drm}/rgb.c    |    0
 drivers/gpu/host1x/host1x.h                    |   29 +
 drivers/gpu/host1x/host1x_bo.h                 |   92 ++++
 drivers/gpu/host1x/host1x_client.h             |   35 ++
 drivers/gpu/host1x/hw/Makefile                 |    6 +
 drivers/gpu/host1x/hw/cdma_hw.c                |  326 ++++++++++++
 drivers/gpu/host1x/hw/channel_hw.c             |  167 ++++++
 drivers/gpu/host1x/hw/debug_hw.c               |  322 ++++++++++++
 drivers/gpu/host1x/hw/host1x01.c               |   42 ++
 drivers/gpu/host1x/hw/host1x01.h               |   25 +
 drivers/gpu/host1x/hw/host1x01_hardware.h      |  143 +++++
 drivers/gpu/host1x/hw/hw_host1x01_channel.h    |  120 +++++
 drivers/gpu/host1x/hw/hw_host1x01_sync.h       |  243 +++++++++
 drivers/gpu/host1x/hw/hw_host1x01_uclass.h     |  174 ++++++
 drivers/gpu/host1x/hw/intr_hw.c                |  143 +++++
 drivers/gpu/host1x/hw/syncpt_hw.c              |  114 ++++
 drivers/gpu/host1x/intr.c                      |  354 +++++++++++++
 drivers/gpu/host1x/intr.h                      |  102 ++++
 drivers/gpu/host1x/job.c                       |  597 +++++++++++++++++++++
 drivers/gpu/host1x/job.h                       |  157 ++++++
 drivers/gpu/host1x/syncpt.c                    |  387 ++++++++++++++
 drivers/gpu/host1x/syncpt.h                    |  165 ++++++
 drivers/video/Kconfig                          |    2 +
 include/drm/drm_gem_cma_helper.h               |    9 +
 include/drm/tegra_drm.h                        |  131 +++++
 include/trace/events/host1x.h                  |  272 ++++++++++
 55 files changed, 7022 insertions(+), 599 deletions(-)
 delete mode 100644 drivers/gpu/drm/tegra/Makefile
 delete mode 100644 drivers/gpu/drm/tegra/drm.c
 delete mode 100644 drivers/gpu/drm/tegra/host1x.c
 create mode 100644 drivers/gpu/host1x/Kconfig
 create mode 100644 drivers/gpu/host1x/Makefile
 create mode 100644 drivers/gpu/host1x/cdma.c
 create mode 100644 drivers/gpu/host1x/cdma.h
 create mode 100644 drivers/gpu/host1x/channel.c
 create mode 100644 drivers/gpu/host1x/channel.h
 create mode 100644 drivers/gpu/host1x/debug.c
 create mode 100644 drivers/gpu/host1x/debug.h
 create mode 100644 drivers/gpu/host1x/dev.c
 create mode 100644 drivers/gpu/host1x/dev.h
 rename drivers/gpu/{drm/tegra => host1x/drm}/Kconfig (94%)
 create mode 100644 drivers/gpu/host1x/drm/cma.c
 create mode 100644 drivers/gpu/host1x/drm/cma.h
 rename drivers/gpu/{drm/tegra => host1x/drm}/dc.c (99%)
 rename drivers/gpu/{drm/tegra => host1x/drm}/dc.h (100%)
 create mode 100644 drivers/gpu/host1x/drm/drm.c
 rename drivers/gpu/{drm/tegra => host1x/drm}/drm.h (82%)
 rename drivers/gpu/{drm/tegra => host1x/drm}/fb.c (89%)
 create mode 100644 drivers/gpu/host1x/drm/gr2d.c
 rename drivers/gpu/{drm/tegra => host1x/drm}/hdmi.c (99%)
 rename drivers/gpu/{drm/tegra => host1x/drm}/hdmi.h (100%)
 rename drivers/gpu/{drm/tegra => host1x/drm}/output.c (100%)
 rename drivers/gpu/{drm/tegra => host1x/drm}/rgb.c (100%)
 create mode 100644 drivers/gpu/host1x/host1x.h
 create mode 100644 drivers/gpu/host1x/host1x_bo.h
 create mode 100644 drivers/gpu/host1x/host1x_client.h
 create mode 100644 drivers/gpu/host1x/hw/Makefile
 create mode 100644 drivers/gpu/host1x/hw/cdma_hw.c
 create mode 100644 drivers/gpu/host1x/hw/channel_hw.c
 create mode 100644 drivers/gpu/host1x/hw/debug_hw.c
 create mode 100644 drivers/gpu/host1x/hw/host1x01.c
 create mode 100644 drivers/gpu/host1x/hw/host1x01.h
 create mode 100644 drivers/gpu/host1x/hw/host1x01_hardware.h
 create mode 100644 drivers/gpu/host1x/hw/hw_host1x01_channel.h
 create mode 100644 drivers/gpu/host1x/hw/hw_host1x01_sync.h
 create mode 100644 drivers/gpu/host1x/hw/hw_host1x01_uclass.h
 create mode 100644 drivers/gpu/host1x/hw/intr_hw.c
 create mode 100644 drivers/gpu/host1x/hw/syncpt_hw.c
 create mode 100644 drivers/gpu/host1x/intr.c
 create mode 100644 drivers/gpu/host1x/intr.h
 create mode 100644 drivers/gpu/host1x/job.c
 create mode 100644 drivers/gpu/host1x/job.h
 create mode 100644 drivers/gpu/host1x/syncpt.c
 create mode 100644 drivers/gpu/host1x/syncpt.h
 create mode 100644 include/drm/tegra_drm.h
 create mode 100644 include/trace/events/host1x.h
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v7 1/10 gpu: drm: Support CMA object preallocation

From: Arto Merilainen <[email protected]>

This patch adds helper functions drm_gem_cma_init() and drm_gem_cma_deinit() for handling CMA structures that already have been allocated. This allows embedding the CMA structure inside other structures.

---
 drivers/gpu/drm/drm_gem_cma_helper.c |   78 ++++++++++++++++++++++++----------
 include/drm/drm_gem_cma_helper.h     |    9 ++++
 2 files changed, 64 insertions(+), 23 deletions(-)
drivers/gpu/drm/drm_gem_cma_helper.c +55 -23
index 0a7e011..3b14280 100644
@@ -2,6 +2,7 @@
  * drm gem CMA (contiguous memory allocator) helper functions
  *
  * Copyright (C) 2012 Sascha Hauer, Pengutronix
+ * Copyright (C) 2013 NVIDIA CORPORATION, All rights reserved.
  *
  * Based on Samsung Exynos code
  *
@@ -40,30 +41,25 @@ static void drm_gem_cma_buf_destroy(struct drm_device *drm,
 }
 
 /*
- * drm_gem_cma_create - allocate an object with the given size
+ * drm_gem_cma_object_init - allocate buffer and initialize given cma object
  *
- * returns a struct drm_gem_cma_object* on success or ERR_PTR values
- * on failure.
+ * this function allocates memory for a cma buffer and initializes the given
+ * cma object to use the allocated buffer.
  */
-struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm,
-		unsigned int size)
+
+int drm_gem_cma_object_init(struct drm_device *drm,
+		struct drm_gem_cma_object *cma_obj, unsigned int size)
 {
-	struct drm_gem_cma_object *cma_obj;
 	struct drm_gem_object *gem_obj;
 	int ret;
 
 	size = round_up(size, PAGE_SIZE);
 
-	cma_obj = kzalloc(sizeof(*cma_obj), GFP_KERNEL);
-	if (!cma_obj)
-		return ERR_PTR(-ENOMEM);
-
 	cma_obj->vaddr = dma_alloc_writecombine(drm->dev, size,
 			&cma_obj->paddr, GFP_KERNEL | __GFP_NOWARN);
 	if (!cma_obj->vaddr) {
 		dev_err(drm->dev, "failed to allocate buffer with size %d\n", size);
-		ret = -ENOMEM;
-		goto err_dma_alloc;
+		return -ENOMEM;
 	}
 
 	gem_obj = &cma_obj->base;
@@ -76,7 +72,7 @@ struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm,
 	if (ret)
 		goto err_create_mmap_offset;
 
-	return cma_obj;
+	return 0;
 
 err_create_mmap_offset:
 	drm_gem_object_release(gem_obj);
@@ -84,10 +80,36 @@ err_create_mmap_offset:
 err_obj_init:
 	drm_gem_cma_buf_destroy(drm, cma_obj);
 
-err_dma_alloc:
-	kfree(cma_obj);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(drm_gem_cma_object_init);
+
+/*
+ * drm_gem_cma_create - allocate an object with the given size
+ *
+ * returns a struct drm_gem_cma_object* on success or ERR_PTR values
+ * on failure.
+ */
+struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm,
+		unsigned int size)
+{
+	struct drm_gem_cma_object *cma_obj;
+	int ret;
+
+	size = round_up(size, PAGE_SIZE);
+
+	cma_obj = kzalloc(sizeof(*cma_obj), GFP_KERNEL);
+	if (!cma_obj)
+		return ERR_PTR(-ENOMEM);
+
+	ret = drm_gem_cma_object_init(drm, cma_obj, size);
+	if (ret) {
+		kfree(cma_obj);
+		return ERR_PTR(ret);
+	}
+
+	return cma_obj;
 
-	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(drm_gem_cma_create);
 
@@ -133,22 +155,32 @@ err_handle_create:
 }
 
 /*
- * drm_gem_cma_free_object - (struct drm_driver)->gem_free_object callback
- * function
+ * drm_gem_cma_deinit_object - deinitialize cma object
+ *
+ * this function deinitializes the given cma object without releasing the
+ * object memory. this function is a counterpart for the function
+ * drm_gem_cma_object_init().
  */
-void drm_gem_cma_free_object(struct drm_gem_object *gem_obj)
+void drm_gem_cma_object_deinit(struct drm_gem_object *gem_obj)
 {
-	struct drm_gem_cma_object *cma_obj;
+	struct drm_gem_cma_object *cma_obj = to_drm_gem_cma_obj(gem_obj);
 
 	if (gem_obj->map_list.map)
 		drm_gem_free_mmap_offset(gem_obj);
 
 	drm_gem_object_release(gem_obj);
-
-	cma_obj = to_drm_gem_cma_obj(gem_obj);
-
 	drm_gem_cma_buf_destroy(gem_obj->dev, cma_obj);
+}
+EXPORT_SYMBOL_GPL(drm_gem_cma_object_deinit);
 
+/*
+ * drm_gem_cma_free_object - (struct drm_driver)->gem_free_object callback
+ * function
+ */
+void drm_gem_cma_free_object(struct drm_gem_object *gem_obj)
+{
+	struct drm_gem_cma_object *cma_obj = to_drm_gem_cma_obj(gem_obj);
+	drm_gem_cma_object_deinit(gem_obj);
 	kfree(cma_obj);
 }
 EXPORT_SYMBOL_GPL(drm_gem_cma_free_object);
include/drm/drm_gem_cma_helper.h +9 -0
index 63397ce..5fdccb3 100644
@@ -13,6 +13,10 @@ to_drm_gem_cma_obj(struct drm_gem_object *gem_obj)
 	return container_of(gem_obj, struct drm_gem_cma_object, base);
 }
 
+/* deinitialize gem object and release the buffer. this variant does not
+ * release the cma object memory */
+void drm_gem_cma_object_deinit(struct drm_gem_object *gem_obj);
+
 /* free gem object. */
 void drm_gem_cma_free_object(struct drm_gem_object *gem_obj);
 
@@ -35,6 +39,11 @@ int drm_gem_cma_mmap(struct file *filp, struct vm_area_struct *vma);
 int drm_gem_cma_dumb_destroy(struct drm_file *file_priv,
 		struct drm_device *drm, unsigned int handle);
 
+/* allocate physical memory for a buffer and initialize already allocated
+ * to use the buffer */
+int drm_gem_cma_object_init(struct drm_device *drm,
+		struct drm_gem_cma_object *cma_obj, unsigned int size);
+
 /* allocate physical memory. */
 struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm,
 		unsigned int size);
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v7 2/10 gpu: host1x: Add host1x driver

In reply to Terje Bergstrom

Add host1x, the driver for host1x and its client unit 2D. The Tegra host1x module is the DMA engine for register access to Tegra's graphics- and multimedia-related modules. The modules served by host1x are referred to as clients. host1x includes some other functionality, such as synchronization.

---
 drivers/gpu/Makefile                      |    1 +
 drivers/gpu/host1x/Kconfig                |    9 ++
 drivers/gpu/host1x/Makefile               |    8 ++
 drivers/gpu/host1x/dev.c                  |  155 +++++++++++++++++++++
 drivers/gpu/host1x/dev.h                  |  104 ++++++++++++++
 drivers/gpu/host1x/hw/Makefile            |    6 +
 drivers/gpu/host1x/hw/host1x01.c          |   33 +++++
 drivers/gpu/host1x/hw/host1x01.h          |   25 ++++
 drivers/gpu/host1x/hw/host1x01_hardware.h |   27 ++++
 drivers/gpu/host1x/hw/hw_host1x01_sync.h  |   74 ++++++++++
 drivers/gpu/host1x/hw/syncpt_hw.c         |  102 ++++++++++++++
 drivers/gpu/host1x/syncpt.c               |  212 +++++++++++++++++++++++++++++
 drivers/gpu/host1x/syncpt.h               |  147 ++++++++++++++++++++
 drivers/video/Kconfig                     |    2 +
 include/trace/events/host1x.h             |   61 +++++++++
 15 files changed, 966 insertions(+)
 create mode 100644 drivers/gpu/host1x/Kconfig
 create mode 100644 drivers/gpu/host1x/Makefile
 create mode 100644 drivers/gpu/host1x/dev.c
 create mode 100644 drivers/gpu/host1x/dev.h
 create mode 100644 drivers/gpu/host1x/hw/Makefile
 create mode 100644 drivers/gpu/host1x/hw/host1x01.c
 create mode 100644 drivers/gpu/host1x/hw/host1x01.h
 create mode 100644 drivers/gpu/host1x/hw/host1x01_hardware.h
 create mode 100644 drivers/gpu/host1x/hw/hw_host1x01_sync.h
 create mode 100644 drivers/gpu/host1x/hw/syncpt_hw.c
 create mode 100644 drivers/gpu/host1x/syncpt.c
 create mode 100644 drivers/gpu/host1x/syncpt.h
 create mode 100644 include/trace/events/host1x.h
drivers/gpu/Makefile +1 -0
index 30879df..d8a22c2 100644
@@ -1 +1,2 @@
 obj-y			+= drm/ vga/
+obj-$(CONFIG_TEGRA_HOST1X)	+= host1x/
drivers/gpu/host1x/Kconfig new file +9 -0
new file mode 100644
index 0000000..c01c450
@@ -0,0 +1,9 @@
+config TEGRA_HOST1X
+	tristate "NVIDIA Tegra host1x driver"
+	help
+	  Driver for the NVIDIA Tegra host1x hardware.
+
+	  The Tegra host1x module is the DMA engine for register access to
+	  Tegra's graphics- and multimedia-related modules. The modules served
+	  by host1x are referred to as clients. host1x includes some other
+	  functionality, such as synchronization.
drivers/gpu/host1x/Makefile new file +8 -0
new file mode 100644
index 0000000..363e6ab
@@ -0,0 +1,8 @@
+ccflags-y = -Idrivers/gpu/host1x
+
+host1x-y = \
+	syncpt.o \
+	dev.o \
+	hw/host1x01.o
+
+obj-$(CONFIG_TEGRA_HOST1X) += host1x.o
drivers/gpu/host1x/dev.c new file +155 -0

155 lines not on this page · raw message

drivers/gpu/host1x/dev.h new file +104 -0

104 lines not on this page · raw message

drivers/gpu/host1x/hw/Makefile new file +6 -0
new file mode 100644
index 0000000..9b50863
@@ -0,0 +1,6 @@
+ccflags-y = -Idrivers/gpu/host1x
+
+host1x-hw-objs  = \
+	host1x01.o
+
+obj-$(CONFIG_TEGRA_HOST1X) += host1x-hw.o
drivers/gpu/host1x/hw/host1x01.c new file +33 -0
new file mode 100644
index 0000000..612b457
@@ -0,0 +1,33 @@
+/*
+ * Host1x init for T20 and T30 Architecture Chips
+ *
+ * Copyright (c) 2011-2013, NVIDIA Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* include hw specification */
+#include "hw/host1x01.h"
+#include "hw/host1x01_hardware.h"
+
+/* include code */
+#include "hw/syncpt_hw.c"
+
+#include "dev.h"
+
+int host1x01_init(struct host1x *host)
+{
+	host->syncpt_op = &host1x_syncpt_ops;
+
+	return 0;
+}
drivers/gpu/host1x/hw/host1x01.h new file +25 -0
new file mode 100644
index 0000000..2706b67
@@ -0,0 +1,25 @@
+/*
+ * Host1x init for T20 and T30 Architecture Chips
+ *
+ * Copyright (c) 2011-2013, NVIDIA Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef HOST1X_HOST1X01_H
+#define HOST1X_HOST1X01_H
+
+struct host1x;
+
+int host1x01_init(struct host1x *host);
+
+#endif /* HOST1X_HOST1X01_H_ */
drivers/gpu/host1x/hw/host1x01_hardware.h new file +27 -0
new file mode 100644
index 0000000..8cecbee
@@ -0,0 +1,27 @@
+/*
+ * Tegra host1x Register Offsets for Tegra20 and Tegra30
+ *
+ * Copyright (c) 2010-2013 NVIDIA Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __HOST1X_HOST1X01_HARDWARE_H
+#define __HOST1X_HOST1X01_HARDWARE_H
+
+#include <linux/types.h>
+#include <linux/bitops.h>
+
+#include "hw_host1x01_sync.h"
+
+#endif
drivers/gpu/host1x/hw/hw_host1x01_sync.h new file +74 -0

74 lines not on this page · raw message

drivers/gpu/host1x/hw/syncpt_hw.c new file +102 -0

102 lines not on this page · raw message

drivers/gpu/host1x/syncpt.c new file +212 -0

212 lines not on this page · raw message

drivers/gpu/host1x/syncpt.h new file +147 -0

147 lines not on this page · raw message

drivers/video/Kconfig +2 -0
index 4c1546f..3e0e3f0 100644
@@ -21,6 +21,8 @@ source "drivers/gpu/vga/Kconfig"
 
 source "drivers/gpu/drm/Kconfig"
 
+source "drivers/gpu/host1x/Kconfig"
+
 config VGASTATE
        tristate
        default n
include/trace/events/host1x.h new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v7 3/10 gpu: host1x: Add syncpoint wait and interrupts

In reply to Terje Bergstrom

Add support for sync point interrupts, and sync point wait. Sync point wait used interrupts for unblocking wait.

---
 drivers/gpu/host1x/Makefile              |    1 +
 drivers/gpu/host1x/dev.c                 |   12 ++
 drivers/gpu/host1x/dev.h                 |   51 +++++
 drivers/gpu/host1x/hw/host1x01.c         |    2 +
 drivers/gpu/host1x/hw/hw_host1x01_sync.h |   42 ++++
 drivers/gpu/host1x/hw/intr_hw.c          |  143 +++++++++++++
 drivers/gpu/host1x/intr.c                |  328 ++++++++++++++++++++++++++++++
 drivers/gpu/host1x/intr.h                |   96 +++++++++
 drivers/gpu/host1x/syncpt.c              |  159 +++++++++++++++
 drivers/gpu/host1x/syncpt.h              |   14 +-
 10 files changed, 847 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/host1x/hw/intr_hw.c
 create mode 100644 drivers/gpu/host1x/intr.c
 create mode 100644 drivers/gpu/host1x/intr.h
drivers/gpu/host1x/Makefile +1 -0
index 363e6ab..5ef47ff 100644
@@ -3,6 +3,7 @@ ccflags-y = -Idrivers/gpu/host1x
 host1x-y = \
 	syncpt.o \
 	dev.o \
+	intr.o \
 	hw/host1x01.o
 
 obj-$(CONFIG_TEGRA_HOST1X) += host1x.o
drivers/gpu/host1x/dev.c +12 -0
index d95a9b2..4421e28 100644
@@ -28,6 +28,7 @@
 #include <trace/events/host1x.h>
 
 #include "dev.h"
+#include "intr.h"
 #include "hw/host1x01.h"
 
 void host1x_sync_writel(struct host1x *host1x, u32 v, u32 r)
@@ -127,12 +128,23 @@ static int host1x_probe(struct platform_device *pdev)
 		return err;
 	}
 
+	err = host1x_intr_init(host, syncpt_irq);
+	if (err) {
+		dev_err(dev, "failed to init irq");
+		goto fail_deinit_syncpt;
+	}
+
 	return 0;
+
+fail_deinit_syncpt:
+	host1x_syncpt_deinit(host);
+	return err;
 }
 
 static int __exit host1x_remove(struct platform_device *pdev)
 {
 	struct host1x *host = platform_get_drvdata(pdev);
+	host1x_intr_deinit(host);
 	host1x_syncpt_deinit(host);
 	clk_disable_unprepare(host->clk);
 	return 0;
drivers/gpu/host1x/dev.h +51 -0

74 lines not on this page · raw message

drivers/gpu/host1x/hw/host1x01.c +2 -0
index 612b457..f5c35fa 100644
@@ -21,6 +21,7 @@
 #include "hw/host1x01_hardware.h"
 
 /* include code */
+#include "hw/intr_hw.c"
 #include "hw/syncpt_hw.c"
 
 #include "dev.h"
@@ -28,6 +29,7 @@
 int host1x01_init(struct host1x *host)
 {
 	host->syncpt_op = &host1x_syncpt_ops;
+	host->intr_op = &host1x_intr_ops;
 
 	return 0;
 }
drivers/gpu/host1x/hw/hw_host1x01_sync.h +42 -0

48 lines not on this page · raw message

drivers/gpu/host1x/hw/intr_hw.c new file +143 -0

143 lines not on this page · raw message

drivers/gpu/host1x/intr.c new file +328 -0

328 lines not on this page · raw message

drivers/gpu/host1x/intr.h new file +96 -0

96 lines not on this page · raw message

drivers/gpu/host1x/syncpt.c +159 -0

171 lines not on this page · raw message

drivers/gpu/host1x/syncpt.h +13 -1
index 119ccd5..17c1616 100644
@@ -19,9 +19,11 @@
 #ifndef __HOST1X_SYNCPT_H
 #define __HOST1X_SYNCPT_H
 
+#include <linux/atomic.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
-#include <linux/atomic.h>
+
+#include "intr.h"
 
 struct host1x;
 
@@ -34,6 +36,9 @@ struct host1x_syncpt {
 	int client_managed;
 	struct host1x *host;
 	struct device *dev;
+
+	/* interrupt data */
+	struct host1x_syncpt_intr intr;
 };
 
 /* Initialize sync point array  */
@@ -113,6 +118,9 @@ void host1x_syncpt_cpu_incr(struct host1x_syncpt *sp);
 /* Load current value from hardware to the shadow register. */
 u32 host1x_syncpt_load(struct host1x_syncpt *sp);
 
+/* Check if the given syncpoint value has already passed */
+bool host1x_syncpt_is_expired(struct host1x_syncpt *sp, u32 thresh);
+
 /* Save host1x sync point state into shadow registers. */
 void host1x_syncpt_save(struct host1x *host);
 
@@ -128,6 +136,10 @@ void host1x_syncpt_incr(struct host1x_syncpt *sp);
 /* Indicate future operations by incrementing the sync point max. */
 u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
 
+/* Wait until sync point reaches a threshold value, or a timeout. */
+int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh,
+			long timeout, u32 *value);
+
 /* Check if sync point id is valid. */
 static inline int host1x_syncpt_is_valid(struct host1x_syncpt *sp)
 {
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH v7 4/10 gpu: host1x: Add channel support

In reply to Terje Bergstrom

Add support for host1x client modules, and host1x channels to submit work to the clients.

---
 drivers/gpu/host1x/Kconfig                  |   12 +
 drivers/gpu/host1x/Makefile                 |    3 +
 drivers/gpu/host1x/cdma.c                   |  487 ++++++++++++++++++++++
 drivers/gpu/host1x/cdma.h                   |  100 +++++
 drivers/gpu/host1x/channel.c                |  120 ++++++
 drivers/gpu/host1x/channel.h                |   52 +++
 drivers/gpu/host1x/dev.c                    |   17 +
 drivers/gpu/host1x/dev.h                    |  113 +++++
 drivers/gpu/host1x/host1x.h                 |   28 ++
 drivers/gpu/host1x/host1x_bo.h              |   92 +++++
 drivers/gpu/host1x/hw/cdma_hw.c             |  324 +++++++++++++++
 drivers/gpu/host1x/hw/channel_hw.c          |  143 +++++++
 drivers/gpu/host1x/hw/host1x01.c            |    5 +
 drivers/gpu/host1x/hw/host1x01_hardware.h   |  116 ++++++
 drivers/gpu/host1x/hw/hw_host1x01_channel.h |  102 +++++
 drivers/gpu/host1x/hw/hw_host1x01_sync.h    |   12 +
 drivers/gpu/host1x/hw/hw_host1x01_uclass.h  |  168 ++++++++
 drivers/gpu/host1x/hw/syncpt_hw.c           |   11 +
 drivers/gpu/host1x/intr.c                   |   28 +-
 drivers/gpu/host1x/intr.h                   |    6 +
 drivers/gpu/host1x/job.c                    |  597 +++++++++++++++++++++++++++
 drivers/gpu/host1x/job.h                    |  157 +++++++
 drivers/gpu/host1x/syncpt.c                 |   11 +
 drivers/gpu/host1x/syncpt.h                 |    6 +
 include/trace/events/host1x.h               |  211 ++++++++++
 25 files changed, 2920 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/host1x/cdma.c
 create mode 100644 drivers/gpu/host1x/cdma.h
 create mode 100644 drivers/gpu/host1x/channel.c
 create mode 100644 drivers/gpu/host1x/channel.h
 create mode 100644 drivers/gpu/host1x/host1x.h
 create mode 100644 drivers/gpu/host1x/host1x_bo.h
 create mode 100644 drivers/gpu/host1x/hw/cdma_hw.c
 create mode 100644 drivers/gpu/host1x/hw/channel_hw.c
 create mode 100644 drivers/gpu/host1x/hw/hw_host1x01_channel.h
 create mode 100644 drivers/gpu/host1x/hw/hw_host1x01_uclass.h
 create mode 100644 drivers/gpu/host1x/job.c
 create mode 100644 drivers/gpu/host1x/job.h
drivers/gpu/host1x/Kconfig +12 -0
index c01c450..00f0859 100644
@@ -7,3 +7,15 @@ config TEGRA_HOST1X
 	  Tegra's graphics- and multimedia-related modules. The modules served
 	  by host1x are referred to as clients. host1x includes some other
 	  functionality, such as synchronization.
+
+if TEGRA_HOST1X
+
+config TEGRA_HOST1X_FIREWALL
+	bool "Enable HOST1X security firewall"
+	default y
+	help
+	  Say yes if kernel should protect command streams from tampering.
+
+	  If unsure, choose Y.
+
+endif
drivers/gpu/host1x/Makefile +3 -0
index 5ef47ff..06a995b 100644
@@ -4,6 +4,9 @@ host1x-y = \
 	syncpt.o \
 	dev.o \
 	intr.o \
+	cdma.o \
+	channel.o \
+	job.o \
 	hw/host1x01.o
 
 obj-$(CONFIG_TEGRA_HOST1X) += host1x.o
drivers/gpu/host1x/cdma.c new file +487 -0

487 lines not on this page · raw message

drivers/gpu/host1x/cdma.h new file +100 -0

100 lines not on this page · raw message

drivers/gpu/host1x/channel.c new file +120 -0

120 lines not on this page · raw message

drivers/gpu/host1x/channel.h new file +52 -0

52 lines not on this page · raw message

drivers/gpu/host1x/dev.c +17 -0
index 4421e28..bedd37b 100644
@@ -29,6 +29,7 @@
 
 #include "dev.h"
 #include "intr.h"
+#include "channel.h"
 #include "hw/host1x01.h"
 
 void host1x_sync_writel(struct host1x *host1x, u32 v, u32 r)
@@ -45,6 +46,16 @@ u32 host1x_sync_readl(struct host1x *host1x, u32 r)
 	return readl(sync_regs + r);
 }
 
+void host1x_ch_writel(struct host1x_channel *ch, u32 v, u32 r)
+{
+	writel(v, ch->regs + r);
+}
+
+u32 host1x_ch_readl(struct host1x_channel *ch, u32 r)
+{
+	return readl(ch->regs + r);
+}
+
 static const struct host1x_info host1x01_info = {
 	.nb_channels	= 8,
 	.nb_pts		= 32,
@@ -116,6 +127,12 @@ static int host1x_probe(struct platform_device *pdev)
 		return err;
 	}
 
+	err = host1x_channel_list_init(host);
+	if (err) {
+		dev_err(dev, "failed to init channel");
+		return err;
+	}
+
 	err = clk_prepare_enable(host->clk);
 	if (err < 0) {
 		dev_err(dev, "failed to enable clock\n");
drivers/gpu/host1x/dev.h +113 -0

140 lines not on this page · raw message

drivers/gpu/host1x/host1x.h new file +28 -0
new file mode 100644
index 0000000..bca6563
@@ -0,0 +1,28 @@
+/*
+ * Tegra host1x driver
+ *
+ * Copyright (c) 2009-2013, NVIDIA Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef __LINUX_HOST1X_H
+#define __LINUX_HOST1X_H
+
+enum host1x_class {
+	HOST1X_CLASS_HOST1X	= 0x1
+};
+
+#endif
drivers/gpu/host1x/host1x_bo.h new file +92 -0

92 lines not on this page · raw message

drivers/gpu/host1x/hw/cdma_hw.c new file +324 -0

324 lines not on this page · raw message

drivers/gpu/host1x/hw/channel_hw.c new file +143 -0

143 lines not on this page · raw message

drivers/gpu/host1x/hw/host1x01.c +5 -0
index f5c35fa..013ff38 100644
@@ -21,6 +21,8 @@
 #include "hw/host1x01_hardware.h"
 
 /* include code */
+#include "hw/cdma_hw.c"
+#include "hw/channel_hw.c"
 #include "hw/intr_hw.c"
 #include "hw/syncpt_hw.c"
 
@@ -28,6 +30,9 @@
 
 int host1x01_init(struct host1x *host)
 {
+	host->channel_op = &host1x_channel_ops;
+	host->cdma_op = &host1x_cdma_ops;
+	host->cdma_pb_op = &host1x_pushbuffer_ops;
 	host->syncpt_op = &host1x_syncpt_ops;
 	host->intr_op = &host1x_intr_ops;
 
drivers/gpu/host1x/hw/host1x01_hardware.h +116 -0

122 lines not on this page · raw message

drivers/gpu/host1x/hw/hw_host1x01_channel.h new file +102 -0

102 lines not on this page · raw message

drivers/gpu/host1x/hw/hw_host1x01_sync.h +12 -0
index eea0bb0..8f2a246 100644
@@ -77,6 +77,18 @@ static inline u32 host1x_sync_syncpt_thresh_int_enable_cpu0_r(unsigned int id)
 }
 #define HOST1X_SYNC_SYNCPT_THRESH_INT_ENABLE_CPU0(id) \
 	host1x_sync_syncpt_thresh_int_enable_cpu0_r(id)
+static inline u32 host1x_sync_cmdproc_stop_r(void)
+{
+	return 0xac;
+}
+#define HOST1X_SYNC_CMDPROC_STOP \
+	host1x_sync_cmdproc_stop_r()
+static inline u32 host1x_sync_ch_teardown_r(void)
+{
+	return 0xb0;
+}
+#define HOST1X_SYNC_CH_TEARDOWN \
+	host1x_sync_ch_teardown_r()
 static inline u32 host1x_sync_usec_clk_r(void)
 {
 	return 0x1a4;
drivers/gpu/host1x/hw/hw_host1x01_uclass.h new file +168 -0

168 lines not on this page · raw message

drivers/gpu/host1x/hw/syncpt_hw.c +11 -0
index 885b257..2c1f4af 100644
@@ -93,10 +93,21 @@ static void syncpt_cpu_incr(struct host1x_syncpt *sp)
 	wmb();
 }
 
+/* remove a wait pointed to by patch_addr */
+static int syncpt_patch_wait(struct host1x_syncpt *sp, void *patch_addr)
+{
+	u32 override = host1x_class_host_wait_syncpt(
+		HOST1X_SYNCPT_RESERVED, 0);
+
+	*((u32 *)patch_addr) = override;
+	return 0;
+}
+
 static const struct host1x_syncpt_ops host1x_syncpt_ops = {
 	.restore = syncpt_restore,
 	.restore_wait_base = syncpt_restore_wait_base,
 	.load_wait_base = syncpt_read_wait_base,
 	.load = syncpt_load,
 	.cpu_incr = syncpt_cpu_incr,
+	.patch_wait = syncpt_patch_wait,
 };
drivers/gpu/host1x/intr.c +27 -1
index b1b5a80..2491bf8 100644
@@ -21,6 +21,8 @@
 #include <linux/slab.h>
 #include <linux/irq.h>
 
+#include <trace/events/host1x.h>
+#include "channel.h"
 #include "dev.h"
 #include "intr.h"
 
@@ -66,7 +68,7 @@ static void remove_completed_waiters(struct list_head *head, u32 sync,
 			struct list_head completed[HOST1X_INTR_ACTION_COUNT])
 {
 	struct list_head *dest;
-	struct host1x_waitlist *waiter, *next;
+	struct host1x_waitlist *waiter, *next, *prev;
 
 	list_for_each_entry_safe(waiter, next, head, list) {
 		if ((s32)(waiter->thresh - sync) > 0)
@@ -74,6 +76,17 @@ static void remove_completed_waiters(struct list_head *head, u32 sync,
 
 		dest = completed + waiter->action;
 
+		/* consolidate submit cleanups */
+		if (waiter->action == HOST1X_INTR_ACTION_SUBMIT_COMPLETE &&
+		    !list_empty(dest)) {
+			prev = list_entry(dest->prev,
+					  struct host1x_waitlist, list);
+			if (prev->data == waiter->data) {
+				prev->count++;
+				dest = NULL;
+			}
+		}
+
 		/* PENDING->REMOVED or CANCELLED->HANDLED */
 		if (atomic_inc_return(&waiter->state) == WLS_HANDLED || !dest) {
 			list_del(&waiter->list);
@@ -94,6 +107,18 @@ static void reset_threshold_interrupt(struct host1x *host,
 	host1x_hw_intr_enable_syncpt_intr(host, id);
 }
 
+static void action_submit_complete(struct host1x_waitlist *waiter)
+{
+	struct host1x_channel *channel = waiter->data;
+
+	host1x_cdma_update(&channel->cdma);
+
+	/*  Add nr_completed to trace */
+	trace_host1x_channel_submit_complete(dev_name(channel->dev),
+					     waiter->count, waiter->thresh);
+
+}
+
 static void action_wakeup(struct host1x_waitlist *waiter)
 {
 	wait_queue_head_t *wq = waiter->data;
@@ -109,6 +134,7 @@ static void action_wakeup_interruptible(struct host1x_waitlist *waiter)
 typedef void (*action_handler)(struct host1x_waitlist *waiter);
 
 static action_handler action_handlers[HOST1X_INTR_ACTION_COUNT] = {
+	action_submit_complete,
 	action_wakeup,
 	action_wakeup_interruptible,
 };
drivers/gpu/host1x/intr.h +6 -0
index a3f06ab..2b8adf0 100644
@@ -26,6 +26,12 @@ struct host1x;
 
 enum host1x_intr_action {
 	/*
+	 * Perform cleanup after a submit has completed.
+	 * 'data' points to a channel
+	 */
+	HOST1X_INTR_ACTION_SUBMIT_COMPLETE = 0,
+
+	/*
 	 * Wake up a  task.
 	 * 'data' points to a wait_queue_head_t
 	 */
drivers/gpu/host1x/job.c new file +597 -0

597 lines not on this page · raw message

drivers/gpu/host1x/job.h new file +157 -0

157 lines not on this page · raw message

drivers/gpu/host1x/syncpt.c +11 -0
index a8613eb..ac172dc 100644
@@ -300,6 +300,12 @@ bool host1x_syncpt_is_expired(struct host1x_syncpt *sp, u32 thresh)
 		return (s32)(current_val - thresh) >= 0;
 }
 
+/* remove a wait pointed to by patch_addr */
+int host1x_syncpt_patch_wait(struct host1x_syncpt *sp, void *patch_addr)
+{
+	return host1x_hw_syncpt_patch_wait(sp->host, sp, patch_addr);
+}
+
 int host1x_syncpt_init(struct host1x *host)
 {
 	struct host1x_syncpt *syncpt;
@@ -319,6 +325,11 @@ int host1x_syncpt_init(struct host1x *host)
 
 	host1x_syncpt_restore(host);
 
+	/* Allocate sync point to use for clearing waits for expired fences */
+	host->nop_sp = _host1x_syncpt_alloc(host, NULL, 0);
+	if (!host->nop_sp)
+		return -ENOMEM;
+
 	return 0;
 }
 
drivers/gpu/host1x/syncpt.h +6 -0
index 17c1616..c998061 100644
@@ -27,6 +27,9 @@
 
 struct host1x;
 
+/* Reserved for replacing an expired wait with a NOP */
+#define HOST1X_SYNCPT_RESERVED			0
+
 struct host1x_syncpt {
 	int id;
 	atomic_t min_val;
@@ -146,6 +149,9 @@ static inline int host1x_syncpt_is_valid(struct host1x_syncpt *sp)
 	return sp->id < host1x_syncpt_nb_pts(sp->host);
 }
 
+/* Patch a wait by replacing it with a wait for syncpt 0 value 0 */
+int host1x_syncpt_patch_wait(struct host1x_syncpt *sp, void *patch_addr);
+
 /* Return id of the sync point */
 u32 host1x_syncpt_id(struct host1x_syncpt *sp);
 
include/trace/events/host1x.h +211 -0

142 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.9.5

Part of the diff is not shown here. View the raw message.

#5 lore raw

PATCH v7 5/10 gpu: host1x: Add debug support

In reply to Terje Bergstrom

Add support for host1x debugging. Adds debugfs entries, and dumps channel state to UART in case of stuck job.

---
 drivers/gpu/host1x/Makefile                 |    1 +
 drivers/gpu/host1x/cdma.c                   |    4 +
 drivers/gpu/host1x/debug.c                  |  210 +++++++++++++++++
 drivers/gpu/host1x/debug.h                  |   51 +++++
 drivers/gpu/host1x/dev.c                    |    3 +
 drivers/gpu/host1x/dev.h                    |   42 ++++
 drivers/gpu/host1x/hw/cdma_hw.c             |    2 +
 drivers/gpu/host1x/hw/channel_hw.c          |   26 ++-
 drivers/gpu/host1x/hw/debug_hw.c            |  322 +++++++++++++++++++++++++++
 drivers/gpu/host1x/hw/host1x01.c            |    2 +
 drivers/gpu/host1x/hw/hw_host1x01_channel.h |   18 ++
 drivers/gpu/host1x/hw/hw_host1x01_sync.h    |  115 ++++++++++
 drivers/gpu/host1x/hw/hw_host1x01_uclass.h  |    6 +
 drivers/gpu/host1x/hw/syncpt_hw.c           |    1 +
 drivers/gpu/host1x/syncpt.c                 |    5 +
 15 files changed, 807 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/host1x/debug.c
 create mode 100644 drivers/gpu/host1x/debug.h
 create mode 100644 drivers/gpu/host1x/hw/debug_hw.c
drivers/gpu/host1x/Makefile +1 -0
index 06a995b..49fd580 100644
@@ -7,6 +7,7 @@ host1x-y = \
 	cdma.o \
 	channel.o \
 	job.o \
+	debug.o \
 	hw/host1x01.o
 
 obj-$(CONFIG_TEGRA_HOST1X) += host1x.o
drivers/gpu/host1x/cdma.c +4 -0
index 33935de..de72172 100644
@@ -439,6 +439,10 @@ void host1x_cdma_push(struct host1x_cdma *cdma, u32 op1, u32 op2)
 	struct push_buffer *pb = &cdma->push_buffer;
 	u32 slots_free = cdma->slots_free;
 
+	if (host1x_debug_trace_cmdbuf)
+		trace_host1x_cdma_push(dev_name(cdma_to_channel(cdma)->dev),
+				       op1, op2);
+
 	if (slots_free == 0) {
 		host1x_hw_cdma_flush(host1x, cdma);
 		slots_free = host1x_cdma_wait_locked(cdma,
drivers/gpu/host1x/debug.c new file +210 -0

210 lines not on this page · raw message

drivers/gpu/host1x/debug.h new file +51 -0

51 lines not on this page · raw message

drivers/gpu/host1x/dev.c +3 -0
index bedd37b..d7c6e3e 100644
@@ -30,6 +30,7 @@
 #include "dev.h"
 #include "intr.h"
 #include "channel.h"
+#include "debug.h"
 #include "hw/host1x01.h"
 
 void host1x_sync_writel(struct host1x *host1x, u32 v, u32 r)
@@ -151,6 +152,8 @@ static int host1x_probe(struct platform_device *pdev)
 		goto fail_deinit_syncpt;
 	}
 
+	host1x_debug_init(host);
+
 	return 0;
 
 fail_deinit_syncpt:
drivers/gpu/host1x/dev.h +42 -0

70 lines not on this page · raw message

drivers/gpu/host1x/hw/cdma_hw.c +2 -0
index 4eb22ef..590b69d 100644
@@ -244,6 +244,8 @@ static void cdma_timeout_handler(struct work_struct *work)
 	host1x = cdma_to_host1x(cdma);
 	ch = cdma_to_channel(cdma);
 
+	host1x_debug_dump(cdma_to_host1x(cdma));
+
 	mutex_lock(&cdma->lock);
 
 	if (!cdma->timeout.client) {
drivers/gpu/host1x/hw/channel_hw.c +25 -1
index bf85a8e..3dbde65 100644
@@ -29,6 +29,30 @@
 #define HOST1X_CHANNEL_SIZE 16384
 #define TRACE_MAX_LENGTH 128U
 
+static void trace_write_gather(struct host1x_cdma *cdma, struct host1x_bo *bo,
+			       u32 offset, u32 words)
+{
+	void *mem = NULL;
+
+	if (host1x_debug_trace_cmdbuf)
+		mem = host1x_bo_mmap(bo);
+
+	if (mem) {
+		u32 i;
+		/*
+		 * Write in batches of 128 as there seems to be a limit
+		 * of how much you can output to ftrace at once.
+		 */
+		for (i = 0; i < words; i += TRACE_MAX_LENGTH) {
+			trace_host1x_cdma_push_gather(
+				dev_name(cdma_to_channel(cdma)->dev),
+				(u32)bo, min(words - i, TRACE_MAX_LENGTH),
+				offset + i * sizeof(u32), mem);
+		}
+		host1x_bo_munmap(bo, mem);
+	}
+}
+
 static void submit_gathers(struct host1x_job *job)
 {
 	struct host1x_cdma *cdma = &job->channel->cdma;
@@ -38,6 +62,7 @@ static void submit_gathers(struct host1x_job *job)
 		struct host1x_job_gather *g = &job->gathers[i];
 		u32 op1 = host1x_opcode_gather(g->words);
 		u32 op2 = g->mem_base + g->offset;
+		trace_write_gather(cdma, g->mem_id, g->offset, op1 & 0xffff);
 		host1x_cdma_push(cdma, op1, op2);
 	}
 }
@@ -51,7 +76,6 @@ static int channel_submit(struct host1x_job *job)
 	u32 syncval;
 	int err;
 	struct host1x_waitlist *completed_waiter = NULL;
-
 	sp = host1x_get_host(job->channel->dev)->syncpt + job->syncpt_id;
 	trace_host1x_channel_submit(dev_name(ch->dev),
 				    job->num_gathers, job->num_relocs,
drivers/gpu/host1x/hw/debug_hw.c new file +322 -0

322 lines not on this page · raw message

drivers/gpu/host1x/hw/host1x01.c +2 -0
index 013ff38..a14e91c 100644
@@ -23,6 +23,7 @@
 /* include code */
 #include "hw/cdma_hw.c"
 #include "hw/channel_hw.c"
+#include "hw/debug_hw.c"
 #include "hw/intr_hw.c"
 #include "hw/syncpt_hw.c"
 
@@ -35,6 +36,7 @@ int host1x01_init(struct host1x *host)
 	host->cdma_pb_op = &host1x_pushbuffer_ops;
 	host->syncpt_op = &host1x_syncpt_ops;
 	host->intr_op = &host1x_intr_ops;
+	host->debug_op = &host1x_debug_ops;
 
 	return 0;
 }
drivers/gpu/host1x/hw/hw_host1x01_channel.h +18 -0
index 9ba1332..b4bc7ca 100644
@@ -51,6 +51,18 @@
 #ifndef __hw_host1x_channel_host1x_h__
 #define __hw_host1x_channel_host1x_h__
 
+static inline u32 host1x_channel_fifostat_r(void)
+{
+	return 0x0;
+}
+#define HOST1X_CHANNEL_FIFOSTAT \
+	host1x_channel_fifostat_r()
+static inline u32 host1x_channel_fifostat_cfempty_v(u32 r)
+{
+	return (r >> 10) & 0x1;
+}
+#define HOST1X_CHANNEL_FIFOSTAT_CFEMPTY_V(r) \
+	host1x_channel_fifostat_cfempty_v(r)
 static inline u32 host1x_channel_dmastart_r(void)
 {
 	return 0x14;
@@ -87,6 +99,12 @@ static inline u32 host1x_channel_dmactrl_dmastop(void)
 }
 #define HOST1X_CHANNEL_DMACTRL_DMASTOP \
 	host1x_channel_dmactrl_dmastop()
+static inline u32 host1x_channel_dmactrl_dmastop_v(u32 r)
+{
+	return (r >> 0) & 0x1;
+}
+#define HOST1X_CHANNEL_DMACTRL_DMASTOP_V(r) \
+	host1x_channel_dmactrl_dmastop_v(r)
 static inline u32 host1x_channel_dmactrl_dmagetrst(void)
 {
 	return 1 << 1;
drivers/gpu/host1x/hw/hw_host1x01_sync.h +115 -0

131 lines not on this page · raw message

drivers/gpu/host1x/hw/hw_host1x01_uclass.h +6 -0
index 7af6609..42f3ce1 100644
@@ -87,6 +87,12 @@ static inline u32 host1x_uclass_wait_syncpt_thresh_f(u32 v)
 }
 #define HOST1X_UCLASS_WAIT_SYNCPT_THRESH_F(v) \
 	host1x_uclass_wait_syncpt_thresh_f(v)
+static inline u32 host1x_uclass_wait_syncpt_base_r(void)
+{
+	return 0x9;
+}
+#define HOST1X_UCLASS_WAIT_SYNCPT_BASE \
+	host1x_uclass_wait_syncpt_base_r()
 static inline u32 host1x_uclass_wait_syncpt_base_indx_f(u32 v)
 {
 	return (v & 0xff) << 24;
drivers/gpu/host1x/hw/syncpt_hw.c +1 -0
index 2c1f4af..6117499 100644
@@ -86,6 +86,7 @@ static void syncpt_cpu_incr(struct host1x_syncpt *sp)
 	    host1x_syncpt_idle(sp)) {
 		dev_err(host->dev, "Trying to increment syncpoint id %d beyond max\n",
 			sp->id);
+		host1x_debug_dump(sp->host);
 		return;
 	}
 	host1x_sync_writel(host, BIT_MASK(sp->id),
drivers/gpu/host1x/syncpt.c +5 -0
index ac172dc..7390af8 100644
@@ -25,6 +25,7 @@
 #include "syncpt.h"
 #include "dev.h"
 #include "intr.h"
+#include "debug.h"
 
 #define SYNCPT_CHECK_PERIOD (2 * HZ)
 #define MAX_STUCK_CHECK_COUNT 15
@@ -231,6 +232,10 @@ int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
 				"%s: syncpoint id %d (%s) stuck waiting %d, timeout=%ld\n",
 				 current->comm, sp->id, sp->name,
 				 thresh, timeout);
+
+			host1x_debug_dump_syncpts(sp->host);
+			if (check_count == MAX_STUCK_CHECK_COUNT)
+				host1x_debug_dump(sp->host);
 			check_count++;
 		}
 	}
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH v7 6/10 drm: tegra: Move drm to live under host1x

In reply to Terje Bergstrom

Make drm part of host1x driver.

---
 drivers/gpu/drm/Kconfig                        |    2 --
 drivers/gpu/drm/Makefile                       |    1 -
 drivers/gpu/drm/tegra/Makefile                 |    7 -------
 drivers/gpu/host1x/Kconfig                     |    2 ++
 drivers/gpu/host1x/Makefile                    |    5 +++++
 drivers/gpu/{drm/tegra => host1x/drm}/Kconfig  |    0
 drivers/gpu/{drm/tegra => host1x/drm}/dc.c     |    0
 drivers/gpu/{drm/tegra => host1x/drm}/dc.h     |    0
 drivers/gpu/{drm/tegra => host1x/drm}/drm.c    |    0
 drivers/gpu/{drm/tegra => host1x/drm}/drm.h    |    6 +++---
 drivers/gpu/{drm/tegra => host1x/drm}/fb.c     |    0
 drivers/gpu/{drm/tegra => host1x/drm}/hdmi.c   |    0
 drivers/gpu/{drm/tegra => host1x/drm}/hdmi.h   |    0
 drivers/gpu/{drm/tegra => host1x/drm}/host1x.c |    0
 drivers/gpu/{drm/tegra => host1x/drm}/output.c |    0
 drivers/gpu/{drm/tegra => host1x/drm}/rgb.c    |    0
 16 files changed, 10 insertions(+), 13 deletions(-)
 delete mode 100644 drivers/gpu/drm/tegra/Makefile
 rename drivers/gpu/{drm/tegra => host1x/drm}/Kconfig (100%)
 rename drivers/gpu/{drm/tegra => host1x/drm}/dc.c (100%)
 rename drivers/gpu/{drm/tegra => host1x/drm}/dc.h (100%)
 rename drivers/gpu/{drm/tegra => host1x/drm}/drm.c (100%)
 rename drivers/gpu/{drm/tegra => host1x/drm}/drm.h (98%)
 rename drivers/gpu/{drm/tegra => host1x/drm}/fb.c (100%)
 rename drivers/gpu/{drm/tegra => host1x/drm}/hdmi.c (100%)
 rename drivers/gpu/{drm/tegra => host1x/drm}/hdmi.h (100%)
 rename drivers/gpu/{drm/tegra => host1x/drm}/host1x.c (100%)
 rename drivers/gpu/{drm/tegra => host1x/drm}/output.c (100%)
 rename drivers/gpu/{drm/tegra => host1x/drm}/rgb.c (100%)
drivers/gpu/drm/Kconfig +0 -2
index 1e82882..9031bb7 100644
@@ -215,8 +215,6 @@ source "drivers/gpu/drm/cirrus/Kconfig"
 
 source "drivers/gpu/drm/shmobile/Kconfig"
 
-source "drivers/gpu/drm/tegra/Kconfig"
-
 source "drivers/gpu/drm/omapdrm/Kconfig"
 
 source "drivers/gpu/drm/tilcdc/Kconfig"
drivers/gpu/drm/Makefile +0 -1
index 0d59b24..847b830 100644
@@ -49,7 +49,6 @@ obj-$(CONFIG_DRM_GMA500) += gma500/
 obj-$(CONFIG_DRM_UDL) += udl/
 obj-$(CONFIG_DRM_AST) += ast/
 obj-$(CONFIG_DRM_SHMOBILE) +=shmobile/
-obj-$(CONFIG_DRM_TEGRA) += tegra/
 obj-$(CONFIG_DRM_OMAP)	+= omapdrm/
 obj-$(CONFIG_DRM_TILCDC)	+= tilcdc/
 obj-y			+= i2c/
drivers/gpu/drm/tegra/Makefile deleted +0 -7
deleted file mode 100644
index 80f73d1..0000000
@@ -1,7 +0,0 @@
-ccflags-y := -Iinclude/drm
-ccflags-$(CONFIG_DRM_TEGRA_DEBUG) += -DDEBUG
-
-tegra-drm-y := drm.o fb.o dc.o host1x.o
-tegra-drm-y += output.o rgb.o hdmi.o
-
-obj-$(CONFIG_DRM_TEGRA) += tegra-drm.o
drivers/gpu/host1x/Kconfig +2 -0
index 00f0859..ee3af1e 100644
@@ -18,4 +18,6 @@ config TEGRA_HOST1X_FIREWALL
 
 	  If unsure, choose Y.
 
+source "drivers/gpu/host1x/drm/Kconfig"
+
 endif
drivers/gpu/host1x/Makefile +5 -0
index 49fd580..4761e8a 100644
@@ -10,4 +10,9 @@ host1x-y = \
 	debug.o \
 	hw/host1x01.o
 
+ccflags-y += -Iinclude/drm
+ccflags-$(CONFIG_DRM_TEGRA_DEBUG) += -DDEBUG
+
+host1x-$(CONFIG_DRM_TEGRA) += drm/drm.o drm/fb.o drm/dc.o drm/host1x.o
+host1x-$(CONFIG_DRM_TEGRA) += drm/output.o drm/rgb.o drm/hdmi.o
 obj-$(CONFIG_TEGRA_HOST1X) += host1x.o
drivers/gpu/host1x/drm/Kconfig renamed from drivers/gpu/drm/tegra/Kconfig +0 -0
similarity index 100%
rename from drivers/gpu/drm/tegra/Kconfig
rename to drivers/gpu/host1x/drm/Kconfig
drivers/gpu/host1x/drm/dc.c renamed from drivers/gpu/drm/tegra/dc.c +0 -0
similarity index 100%
rename from drivers/gpu/drm/tegra/dc.c
rename to drivers/gpu/host1x/drm/dc.c
drivers/gpu/host1x/drm/dc.h renamed from drivers/gpu/drm/tegra/dc.h +0 -0
similarity index 100%
rename from drivers/gpu/drm/tegra/dc.h
rename to drivers/gpu/host1x/drm/dc.h
drivers/gpu/host1x/drm/drm.c renamed from drivers/gpu/drm/tegra/drm.c +0 -0
similarity index 100%
rename from drivers/gpu/drm/tegra/drm.c
rename to drivers/gpu/host1x/drm/drm.c
drivers/gpu/host1x/drm/drm.h renamed from drivers/gpu/drm/tegra/drm.h +3 -3
similarity index 98%
rename from drivers/gpu/drm/tegra/drm.h
rename to drivers/gpu/host1x/drm/drm.h
index 6dd75a2..a6c011d 100644
@@ -7,8 +7,8 @@
  * published by the Free Software Foundation.
  */
 
-#ifndef TEGRA_DRM_H
-#define TEGRA_DRM_H 1
+#ifndef HOST1X_DRM_H
+#define HOST1X_DRM_H 1
 
 #include <drm/drmP.h>
 #include <drm/drm_crtc_helper.h>
@@ -234,4 +234,4 @@ extern struct platform_driver tegra_hdmi_driver;
 extern struct platform_driver tegra_dc_driver;
 extern struct drm_driver tegra_drm_driver;
 
-#endif /* TEGRA_DRM_H */
+#endif /* HOST1X_DRM_H */
drivers/gpu/host1x/drm/fb.c renamed from drivers/gpu/drm/tegra/fb.c +0 -0
similarity index 100%
rename from drivers/gpu/drm/tegra/fb.c
rename to drivers/gpu/host1x/drm/fb.c
drivers/gpu/host1x/drm/hdmi.c renamed from drivers/gpu/drm/tegra/hdmi.c +0 -0
similarity index 100%
rename from drivers/gpu/drm/tegra/hdmi.c
rename to drivers/gpu/host1x/drm/hdmi.c
drivers/gpu/host1x/drm/hdmi.h renamed from drivers/gpu/drm/tegra/hdmi.h +0 -0
similarity index 100%
rename from drivers/gpu/drm/tegra/hdmi.h
rename to drivers/gpu/host1x/drm/hdmi.h
drivers/gpu/host1x/drm/host1x.c renamed from drivers/gpu/drm/tegra/host1x.c +0 -0
similarity index 100%
rename from drivers/gpu/drm/tegra/host1x.c
rename to drivers/gpu/host1x/drm/host1x.c
drivers/gpu/host1x/drm/output.c renamed from drivers/gpu/drm/tegra/output.c +0 -0
similarity index 100%
rename from drivers/gpu/drm/tegra/output.c
rename to drivers/gpu/host1x/drm/output.c
drivers/gpu/host1x/drm/rgb.c renamed from drivers/gpu/drm/tegra/rgb.c +0 -0
similarity index 100%
rename from drivers/gpu/drm/tegra/rgb.c
rename to drivers/gpu/host1x/drm/rgb.c
Signature · 1 line
1.7.9.5
#7 lore raw

PATCH v7 7/10 gpu: host1x: drm: Rename host1x to host1x_drm

In reply to Terje Bergstrom

From: Arto Merilainen <[email protected]>

Both host1x and drm drivers have host1x structures. This patch renames the host1x structure under drm to follow name host1x_drm.

---
 drivers/gpu/host1x/drm/dc.c     |    4 ++--
 drivers/gpu/host1x/drm/drm.c    |    4 ++--
 drivers/gpu/host1x/drm/drm.h    |   14 +++++++-------
 drivers/gpu/host1x/drm/fb.c     |    6 +++---
 drivers/gpu/host1x/drm/hdmi.c   |    4 ++--
 drivers/gpu/host1x/drm/host1x.c |   22 ++++++++++++----------
 6 files changed, 28 insertions(+), 26 deletions(-)
drivers/gpu/host1x/drm/dc.c +2 -2
index de94707..d1f6609 100644
@@ -1097,7 +1097,7 @@ static const struct host1x_client_ops dc_client_ops = {
 
 static int tegra_dc_probe(struct platform_device *pdev)
 {
-	struct host1x *host1x = dev_get_drvdata(pdev->dev.parent);
+	struct host1x_drm *host1x = dev_get_drvdata(pdev->dev.parent);
 	struct resource *regs;
 	struct tegra_dc *dc;
 	int err;
@@ -1160,7 +1160,7 @@ static int tegra_dc_probe(struct platform_device *pdev)
 
 static int tegra_dc_remove(struct platform_device *pdev)
 {
-	struct host1x *host1x = dev_get_drvdata(pdev->dev.parent);
+	struct host1x_drm *host1x = dev_get_drvdata(pdev->dev.parent);
 	struct tegra_dc *dc = platform_get_drvdata(pdev);
 	int err;
 
drivers/gpu/host1x/drm/drm.c +2 -2
index 9d452df..6c59bcd 100644
@@ -26,7 +26,7 @@
 static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 {
 	struct device *dev = drm->dev;
-	struct host1x *host1x;
+	struct host1x_drm *host1x;
 	int err;
 
 	host1x = dev_get_drvdata(dev);
@@ -69,7 +69,7 @@ static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp)
 
 static void tegra_drm_lastclose(struct drm_device *drm)
 {
-	struct host1x *host1x = drm->dev_private;
+	struct host1x_drm *host1x = drm->dev_private;
 
 	drm_fbdev_cma_restore_mode(host1x->fbdev);
 }
drivers/gpu/host1x/drm/drm.h +7 -7
index a6c011d..7fedb6c 100644
@@ -18,7 +18,7 @@
 #include <drm/drm_fb_cma_helper.h>
 #include <drm/drm_fixed.h>
 
-struct host1x {
+struct host1x_drm {
 	struct drm_device *drm;
 	struct device *dev;
 	void __iomem *regs;
@@ -44,7 +44,7 @@ struct host1x_client_ops {
 };
 
 struct host1x_client {
-	struct host1x *host1x;
+	struct host1x_drm *host1x;
 	struct device *dev;
 
 	const struct host1x_client_ops *ops;
@@ -52,12 +52,12 @@ struct host1x_client {
 	struct list_head list;
 };
 
-extern int host1x_drm_init(struct host1x *host1x, struct drm_device *drm);
-extern int host1x_drm_exit(struct host1x *host1x);
+extern int host1x_drm_init(struct host1x_drm *host1x, struct drm_device *drm);
+extern int host1x_drm_exit(struct host1x_drm *host1x);
 
-extern int host1x_register_client(struct host1x *host1x,
+extern int host1x_register_client(struct host1x_drm *host1x,
 				  struct host1x_client *client);
-extern int host1x_unregister_client(struct host1x *host1x,
+extern int host1x_unregister_client(struct host1x_drm *host1x,
 				    struct host1x_client *client);
 
 struct tegra_output;
@@ -66,7 +66,7 @@ struct tegra_dc {
 	struct host1x_client client;
 	spinlock_t lock;
 
-	struct host1x *host1x;
+	struct host1x_drm *host1x;
 	struct device *dev;
 
 	struct drm_crtc base;
drivers/gpu/host1x/drm/fb.c +3 -3
index 0391495..6ed885a 100644
@@ -11,7 +11,7 @@
 
 static void tegra_drm_fb_output_poll_changed(struct drm_device *drm)
 {
-	struct host1x *host1x = drm->dev_private;
+	struct host1x_drm *host1x = drm->dev_private;
 
 	drm_fbdev_cma_hotplug_event(host1x->fbdev);
 }
@@ -23,7 +23,7 @@ static const struct drm_mode_config_funcs tegra_drm_mode_funcs = {
 
 int tegra_drm_fb_init(struct drm_device *drm)
 {
-	struct host1x *host1x = drm->dev_private;
+	struct host1x_drm *host1x = drm->dev_private;
 	struct drm_fbdev_cma *fbdev;
 
 	drm->mode_config.min_width = 0;
@@ -46,7 +46,7 @@ int tegra_drm_fb_init(struct drm_device *drm)
 
 void tegra_drm_fb_exit(struct drm_device *drm)
 {
-	struct host1x *host1x = drm->dev_private;
+	struct host1x_drm *host1x = drm->dev_private;
 
 	drm_fbdev_cma_fini(host1x->fbdev);
 }
drivers/gpu/host1x/drm/hdmi.c +2 -2
index bb747f6..f438f80 100644
@@ -1189,7 +1189,7 @@ static const struct host1x_client_ops hdmi_client_ops = {
 
 static int tegra_hdmi_probe(struct platform_device *pdev)
 {
-	struct host1x *host1x = dev_get_drvdata(pdev->dev.parent);
+	struct host1x_drm *host1x = dev_get_drvdata(pdev->dev.parent);
 	struct tegra_hdmi *hdmi;
 	struct resource *regs;
 	int err;
@@ -1278,7 +1278,7 @@ static int tegra_hdmi_probe(struct platform_device *pdev)
 
 static int tegra_hdmi_remove(struct platform_device *pdev)
 {
-	struct host1x *host1x = dev_get_drvdata(pdev->dev.parent);
+	struct host1x_drm *host1x = dev_get_drvdata(pdev->dev.parent);
 	struct tegra_hdmi *hdmi = platform_get_drvdata(pdev);
 	int err;
 
drivers/gpu/host1x/drm/host1x.c +12 -10
index 92e25a7..c3d8ee5 100644
@@ -21,7 +21,8 @@ struct host1x_drm_client {
 	struct list_head list;
 };
 
-static int host1x_add_drm_client(struct host1x *host1x, struct device_node *np)
+static int host1x_add_drm_client(struct host1x_drm *host1x,
+				 struct device_node *np)
 {
 	struct host1x_drm_client *client;
 
@@ -37,7 +38,7 @@ static int host1x_add_drm_client(struct host1x *host1x, struct device_node *np)
 	return 0;
 }
 
-static int host1x_activate_drm_client(struct host1x *host1x,
+static int host1x_activate_drm_client(struct host1x_drm *host1x,
 				      struct host1x_drm_client *drm,
 				      struct host1x_client *client)
 {
@@ -50,7 +51,7 @@ static int host1x_activate_drm_client(struct host1x *host1x,
 	return 0;
 }
 
-static int host1x_remove_drm_client(struct host1x *host1x,
+static int host1x_remove_drm_client(struct host1x_drm *host1x,
 				    struct host1x_drm_client *client)
 {
 	mutex_lock(&host1x->drm_clients_lock);
@@ -63,7 +64,7 @@ static int host1x_remove_drm_client(struct host1x *host1x,
 	return 0;
 }
 
-static int host1x_parse_dt(struct host1x *host1x)
+static int host1x_parse_dt(struct host1x_drm *host1x)
 {
 	static const char * const compat[] = {
 		"nvidia,tegra20-dc",
@@ -92,7 +93,7 @@ static int host1x_parse_dt(struct host1x *host1x)
 
 static int tegra_host1x_probe(struct platform_device *pdev)
 {
-	struct host1x *host1x;
+	struct host1x_drm *host1x;
 	struct resource *regs;
 	int err;
 
@@ -156,14 +157,14 @@ err:
 
 static int tegra_host1x_remove(struct platform_device *pdev)
 {
-	struct host1x *host1x = platform_get_drvdata(pdev);
+	struct host1x_drm *host1x = platform_get_drvdata(pdev);
 
 	clk_disable_unprepare(host1x->clk);
 
 	return 0;
 }
 
-int host1x_drm_init(struct host1x *host1x, struct drm_device *drm)
+int host1x_drm_init(struct host1x_drm *host1x, struct drm_device *drm)
 {
 	struct host1x_client *client;
 
@@ -186,7 +187,7 @@ int host1x_drm_init(struct host1x *host1x, struct drm_device *drm)
 	return 0;
 }
 
-int host1x_drm_exit(struct host1x *host1x)
+int host1x_drm_exit(struct host1x_drm *host1x)
 {
 	struct platform_device *pdev = to_platform_device(host1x->dev);
 	struct host1x_client *client;
@@ -216,7 +217,8 @@ int host1x_drm_exit(struct host1x *host1x)
 	return 0;
 }
 
-int host1x_register_client(struct host1x *host1x, struct host1x_client *client)
+int host1x_register_client(struct host1x_drm *host1x,
+			   struct host1x_client *client)
 {
 	struct host1x_drm_client *drm, *tmp;
 	int err;
@@ -244,7 +246,7 @@ int host1x_register_client(struct host1x *host1x, struct host1x_client *client)
 	return 0;
 }
 
-int host1x_unregister_client(struct host1x *host1x,
+int host1x_unregister_client(struct host1x_drm *host1x,
 			     struct host1x_client *client)
 {
 	struct host1x_drm_client *drm, *tmp;
Signature · 1 line
1.7.9.5
#8 lore raw

PATCH v7 8/10 gpu: host1x: Remove second host1x driver

In reply to Terje Bergstrom

Remove second host1x driver, and bind tegra-drm to the new host1x driver. The logic to parse device tree and track clients is moved to drm.c.

---
 drivers/gpu/host1x/Makefile        |    2 +-
 drivers/gpu/host1x/dev.c           |   58 ++++++-
 drivers/gpu/host1x/dev.h           |    6 +
 drivers/gpu/host1x/drm/Kconfig     |    2 +-
 drivers/gpu/host1x/drm/dc.c        |    5 +-
 drivers/gpu/host1x/drm/drm.c       |  217 +++++++++++++++++++++++-
 drivers/gpu/host1x/drm/drm.h       |    3 -
 drivers/gpu/host1x/drm/hdmi.c      |    5 +-
 drivers/gpu/host1x/drm/host1x.c    |  329 ------------------------------------
 drivers/gpu/host1x/host1x_client.h |   35 ++++
 10 files changed, 318 insertions(+), 344 deletions(-)
 delete mode 100644 drivers/gpu/host1x/drm/host1x.c
 create mode 100644 drivers/gpu/host1x/host1x_client.h
drivers/gpu/host1x/Makefile +1 -1
index 4761e8a..9a6fc76 100644
@@ -13,6 +13,6 @@ host1x-y = \
 ccflags-y += -Iinclude/drm
 ccflags-$(CONFIG_DRM_TEGRA_DEBUG) += -DDEBUG
 
-host1x-$(CONFIG_DRM_TEGRA) += drm/drm.o drm/fb.o drm/dc.o drm/host1x.o
+host1x-$(CONFIG_DRM_TEGRA) += drm/drm.o drm/fb.o drm/dc.o
 host1x-$(CONFIG_DRM_TEGRA) += drm/output.o drm/rgb.o drm/hdmi.o
 obj-$(CONFIG_TEGRA_HOST1X) += host1x.o
drivers/gpu/host1x/dev.c +56 -2

83 lines not on this page · raw message

drivers/gpu/host1x/dev.h +6 -0
index 4a56233..ca2ba8a 100644
@@ -124,6 +124,8 @@ struct host1x {
 	unsigned int num_allocated_channels;
 
 	struct dentry *debugfs;
+
+	void *drm_data;
 };
 
 static inline struct host1x *host1x_get_host(struct device *dev)
@@ -307,4 +309,8 @@ static inline void host1x_hw_show_mlocks(struct host1x *host, struct output *o)
 	host->debug_op->show_mlocks(host, o);
 }
 
+extern struct platform_driver tegra_hdmi_driver;
+extern struct platform_driver tegra_dc_driver;
+extern struct platform_driver tegra_gr2d_driver;
+
 #endif
drivers/gpu/host1x/drm/Kconfig +1 -1
index c92955d..8fb6545 100644
@@ -1,5 +1,5 @@
 config DRM_TEGRA
-	tristate "NVIDIA Tegra DRM"
+	bool "NVIDIA Tegra DRM"
 	depends on DRM && OF && ARCH_TEGRA
 	select DRM_KMS_HELPER
 	select DRM_GEM_CMA_HELPER
drivers/gpu/host1x/drm/dc.c +3 -2
index d1f6609..29a79b6 100644
@@ -16,6 +16,7 @@
 
 #include "drm.h"
 #include "dc.h"
+#include "host1x_client.h"
 
 struct tegra_plane {
 	struct drm_plane base;
@@ -1097,7 +1098,7 @@ static const struct host1x_client_ops dc_client_ops = {
 
 static int tegra_dc_probe(struct platform_device *pdev)
 {
-	struct host1x_drm *host1x = dev_get_drvdata(pdev->dev.parent);
+	struct host1x_drm *host1x = host1x_get_drm_data(pdev->dev.parent);
 	struct resource *regs;
 	struct tegra_dc *dc;
 	int err;
@@ -1160,7 +1161,7 @@ static int tegra_dc_probe(struct platform_device *pdev)
 
 static int tegra_dc_remove(struct platform_device *pdev)
 {
-	struct host1x_drm *host1x = dev_get_drvdata(pdev->dev.parent);
+	struct host1x_drm *host1x = host1x_get_drm_data(pdev->dev.parent);
 	struct tegra_dc *dc = platform_get_drvdata(pdev);
 	int err;
 
drivers/gpu/host1x/drm/drm.c +213 -4

240 lines not on this page · raw message

drivers/gpu/host1x/drm/drm.h +0 -3
index 7fedb6c..0b8738f 100644
@@ -229,9 +229,6 @@ extern int tegra_output_exit(struct tegra_output *output);
 extern int tegra_drm_fb_init(struct drm_device *drm);
 extern void tegra_drm_fb_exit(struct drm_device *drm);
 
-extern struct platform_driver tegra_host1x_driver;
-extern struct platform_driver tegra_hdmi_driver;
-extern struct platform_driver tegra_dc_driver;
 extern struct drm_driver tegra_drm_driver;
 
 #endif /* HOST1X_DRM_H */
drivers/gpu/host1x/drm/hdmi.c +3 -2
index f438f80..01097da 100644
@@ -22,6 +22,7 @@
 #include "hdmi.h"
 #include "drm.h"
 #include "dc.h"
+#include "host1x_client.h"
 
 struct tegra_hdmi {
 	struct host1x_client client;
@@ -1189,7 +1190,7 @@ static const struct host1x_client_ops hdmi_client_ops = {
 
 static int tegra_hdmi_probe(struct platform_device *pdev)
 {
-	struct host1x_drm *host1x = dev_get_drvdata(pdev->dev.parent);
+	struct host1x_drm *host1x = host1x_get_drm_data(pdev->dev.parent);
 	struct tegra_hdmi *hdmi;
 	struct resource *regs;
 	int err;
@@ -1278,7 +1279,7 @@ static int tegra_hdmi_probe(struct platform_device *pdev)
 
 static int tegra_hdmi_remove(struct platform_device *pdev)
 {
-	struct host1x_drm *host1x = dev_get_drvdata(pdev->dev.parent);
+	struct host1x_drm *host1x = host1x_get_drm_data(pdev->dev.parent);
 	struct tegra_hdmi *hdmi = platform_get_drvdata(pdev);
 	int err;
 
drivers/gpu/host1x/drm/host1x.c deleted +0 -329

329 lines not on this page · raw message

drivers/gpu/host1x/host1x_client.h new file +35 -0
new file mode 100644
index 0000000..9b85f10
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2013, NVIDIA Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef HOST1X_CLIENT_H
+#define HOST1X_CLIENT_H
+
+struct device;
+struct platform_device;
+
+#ifdef CONFIG_DRM_TEGRA
+int host1x_drm_alloc(struct platform_device *pdev);
+#else
+static inline int host1x_drm_alloc(struct platform_device *pdev)
+{
+	return 0;
+}
+#endif
+
+void host1x_set_drm_data(struct device *dev, void *data);
+void *host1x_get_drm_data(struct device *dev);
+
+#endif
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH v7 9/10 gpu: host1x: drm: Add CMA ops for host1x driver

In reply to Terje Bergstrom

From: Arto Merilainen <[email protected]>

This patch implements a CMA memory handler for the host1x driver.

---
 drivers/gpu/host1x/Makefile  |    1 +
 drivers/gpu/host1x/drm/cma.c |   93 ++++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/host1x/drm/cma.h |   35 ++++++++++++++++
 3 files changed, 129 insertions(+)
 create mode 100644 drivers/gpu/host1x/drm/cma.c
 create mode 100644 drivers/gpu/host1x/drm/cma.h
drivers/gpu/host1x/Makefile +1 -0
index 9a6fc76..e85db5a 100644
@@ -15,4 +15,5 @@ ccflags-$(CONFIG_DRM_TEGRA_DEBUG) += -DDEBUG
 
 host1x-$(CONFIG_DRM_TEGRA) += drm/drm.o drm/fb.o drm/dc.o
 host1x-$(CONFIG_DRM_TEGRA) += drm/output.o drm/rgb.o drm/hdmi.o
+host1x-$(CONFIG_DRM_TEGRA) += drm/cma.o
 obj-$(CONFIG_TEGRA_HOST1X) += host1x.o
drivers/gpu/host1x/drm/cma.c new file +93 -0

93 lines not on this page · raw message

drivers/gpu/host1x/drm/cma.h new file +35 -0
new file mode 100644
index 0000000..f35cebd
@@ -0,0 +1,35 @@
+/*
+ * Tegra host1x cma memory manager
+ *
+ * Copyright (c) 2012-2013, NVIDIA Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __HOST1X_CMA_H
+#define __HOST1X_CMA_H
+
+#include <drm/drm.h>
+#include <drm/drmP.h>
+#include <drm/drm_gem_cma_helper.h>
+
+#include "host1x_bo.h"
+
+struct tegra_drm_bo {
+	struct host1x_bo base;
+	struct drm_gem_cma_object cma_obj;
+};
+
+extern const struct host1x_bo_ops tegra_drm_bo_ops;
+
+#endif
Signature · 1 line
1.7.9.5
#10 lore raw

PATCH v7 10/10 drm: tegra: Add gr2d device

In reply to Terje Bergstrom

Add client driver for 2D device, and IOCTLs to pass work to host1x channel for 2D.

Also adds functions that can be called to access sync points from DRM.

---
 drivers/gpu/host1x/Makefile   |    1 +
 drivers/gpu/host1x/dev.c      |    7 +
 drivers/gpu/host1x/drm/drm.c  |  251 ++++++++++++++++++++++++++++++-
 drivers/gpu/host1x/drm/drm.h  |   28 +++-
 drivers/gpu/host1x/drm/gr2d.c |  330 +++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/host1x/host1x.h   |    3 +-
 include/drm/tegra_drm.h       |  131 ++++++++++++++++
 7 files changed, 747 insertions(+), 4 deletions(-)
 create mode 100644 drivers/gpu/host1x/drm/gr2d.c
 create mode 100644 include/drm/tegra_drm.h
drivers/gpu/host1x/Makefile +1 -0
index e85db5a..29c0c6b 100644
@@ -16,4 +16,5 @@ ccflags-$(CONFIG_DRM_TEGRA_DEBUG) += -DDEBUG
 host1x-$(CONFIG_DRM_TEGRA) += drm/drm.o drm/fb.o drm/dc.o
 host1x-$(CONFIG_DRM_TEGRA) += drm/output.o drm/rgb.o drm/hdmi.o
 host1x-$(CONFIG_DRM_TEGRA) += drm/cma.o
+host1x-$(CONFIG_DRM_TEGRA) += drm/gr2d.o
 obj-$(CONFIG_TEGRA_HOST1X) += host1x.o
drivers/gpu/host1x/dev.c +7 -0
index 6af8081..0091632 100644
@@ -211,11 +211,17 @@ static int __init tegra_host1x_init(void)
 	err = platform_driver_register(&tegra_hdmi_driver);
 	if (err < 0)
 		goto unregister_dc;
+
+	err = platform_driver_register(&tegra_gr2d_driver);
+	if (err < 0)
+		goto unregister_hdmi;
 #endif
 
 	return 0;
 
 #ifdef CONFIG_DRM_TEGRA
+unregister_hdmi:
+	platform_driver_unregister(&tegra_hdmi_driver);
 unregister_dc:
 	platform_driver_unregister(&tegra_dc_driver);
 unregister_host1x:
@@ -228,6 +234,7 @@ module_init(tegra_host1x_init);
 static void __exit tegra_host1x_exit(void)
 {
 #ifdef CONFIG_DRM_TEGRA
+	platform_driver_unregister(&tegra_gr2d_driver);
 	platform_driver_unregister(&tegra_hdmi_driver);
 	platform_driver_unregister(&tegra_dc_driver);
 #endif
drivers/gpu/host1x/drm/drm.c +249 -2

309 lines not on this page · raw message

drivers/gpu/host1x/drm/drm.h +27 -1
index 0b8738f..6a8d7e3 100644
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2012 Avionic Design GmbH
- * Copyright (C) 2012 NVIDIA CORPORATION.  All rights reserved.
+ * Copyright (C) 2012-2013 NVIDIA CORPORATION.  All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -17,6 +17,9 @@
 #include <drm/drm_gem_cma_helper.h>
 #include <drm/drm_fb_cma_helper.h>
 #include <drm/drm_fixed.h>
+#include <drm/tegra_drm.h>
+
+#include "host1x.h"
 
 struct host1x_drm {
 	struct drm_device *drm;
@@ -38,9 +41,26 @@ struct host1x_drm {
 
 struct host1x_client;
 
+struct host1x_drm_context {
+	struct host1x_client *client;
+	struct host1x_channel *channel;
+	struct list_head list;
+};
+
 struct host1x_client_ops {
 	int (*drm_init)(struct host1x_client *client, struct drm_device *drm);
 	int (*drm_exit)(struct host1x_client *client);
+	int (*open_channel)(struct host1x_client *client,
+			struct host1x_drm_context *context);
+	void (*close_channel)(struct host1x_drm_context *context);
+	int (*submit)(struct host1x_drm_context *context,
+			struct tegra_drm_submit_args *args,
+			struct drm_device *drm,
+			struct drm_file *file_priv);
+};
+
+struct host1x_drm_file {
+	struct list_head contexts;
 };
 
 struct host1x_client {
@@ -49,6 +69,12 @@ struct host1x_client {
 
 	const struct host1x_client_ops *ops;
 
+	enum host1x_class class;
+	struct host1x_channel *channel;
+
+	struct host1x_syncpt **syncpts;
+	unsigned int num_syncpts;
+
 	struct list_head list;
 };
 
drivers/gpu/host1x/drm/gr2d.c new file +330 -0

330 lines not on this page · raw message

drivers/gpu/host1x/host1x.h +2 -1
index bca6563..128cc9e 100644
@@ -22,7 +22,8 @@
 #define __LINUX_HOST1X_H
 
 enum host1x_class {
-	HOST1X_CLASS_HOST1X	= 0x1
+	HOST1X_CLASS_HOST1X	= 0x1,
+	HOST1X_CLASS_GR2D	= 0x51
 };
 
 #endif
include/drm/tegra_drm.h new file +131 -0

131 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#11 lore raw

Re: [PATCHv7 10/10] drm: tegra: Add gr2d device

On Wed, Mar 13, 2013 at 02:36:26PM +0200, Terje Bergstrom wrote:
[...]

Quoted 1 line
drivers/gpu/host1x/drm/drm.c +0 -0

[...]

drivers/gpu/host1x/drm/drm.c static void tegra_drm_lastclose(struct drm_device *drm) · line 363

Quoted 11 lines
drivers/gpu/host1x/drm/drm.c +11 -0
+static inline struct host1x_drm_context *tegra_drm_get_context(
+					struct list_head *contexts,
+					struct host1x_drm_context *_ctx)
+{
+	struct host1x_drm_context *ctx;
+
+	list_for_each_entry(ctx, contexts, list)
+		if (ctx == _ctx)
+			return ctx;
+	return NULL;
+}

Maybe make this a little more high-level, such as:

static bool host1x_drm_file_owns_context(struct host1x_drm_file *file,
struct host1x_drm_context *context)

?

Quoted 7 lines
drivers/gpu/host1x/drm/drm.c +7 -0
+static int tegra_drm_ioctl_open_channel(struct drm_device *drm, void *data,
+					struct drm_file *file_priv)
+{
+	struct tegra_drm_open_channel_args *args = data;
+	struct host1x_client *client;
+	struct host1x_drm_context *context;
+	struct host1x_drm_file *fpriv = file_priv->driver_priv;

drivers/gpu/host1x/drm/drm.c static void tegra_drm_lastclose(struct drm_device *drm) · line 381

Quoted 10 lines
drivers/gpu/host1x/drm/drm.c +10 -0
+	struct host1x_drm *host1x = drm->dev_private;
+	int err = -ENODEV;
+
+	context = kzalloc(sizeof(*context), GFP_KERNEL);
+	if (!context)
+		return -ENOMEM;
+
+	list_for_each_entry(client, &host1x->clients, list)
+		if (client->class == args->class) {
+			context->client = client;

Why do you assign this here? Should it perhaps be assigned only when the opening of the channel succeeds? The .open_channel() already receives a pointer to the client as parameter, so it doesn't have to be associated with the context.

drivers/gpu/host1x/drm/drm.c static void tegra_drm_lastclose(struct drm_device *drm) · line 424

Quoted 13 lines
drivers/gpu/host1x/drm/drm.c +13 -0
+static int tegra_drm_ioctl_get_syncpoint(struct drm_device *drm, void *data,
+					 struct drm_file *file_priv)
+{
+	struct tegra_drm_get_syncpoint *args = data;
+	struct host1x_drm_file *fpriv = file_priv->driver_priv;
+	struct host1x_drm_context *context =
+		(struct host1x_drm_context *)(uintptr_t)args->context;
+
+	if (!tegra_drm_get_context(&fpriv->contexts, context))
+		return -ENODEV;
+
+	if (context->client->num_syncpts < args->param)
+		return -ENODEV;

I think this might be easier to read as:

	if (args->param >= context->client->num_syncpts)
		return -ENODEV;

drivers/gpu/host1x/drm/drm.c static void tegra_drm_lastclose(struct drm_device *drm) · line 426

Quoted 1 line
drivers/gpu/host1x/drm/drm.c +1 -0
+	args->value = host1x_syncpt_id(context->client->syncpts[args->param]);

This could use a temporary variable "syncpt" to make it easier to read.

drivers/gpu/host1x/drm/drm.c

Quoted 2 lines
drivers/gpu/host1x/drm/drm.c +2 -0
+static int tegra_drm_gem_create_ioctl(struct drm_device *drm, void *data,
+				      struct drm_file *file_priv)

tegra_drm_ioctl_gem_create()?

drivers/gpu/host1x/drm/drm.c static void tegra_drm_lastclose(struct drm_device *drm) · line 450

Quoted 4 lines
drivers/gpu/host1x/drm/drm.c +4 -0
+{
+	struct tegra_drm_create *args = data;
+	struct drm_gem_cma_object *cma_obj;
+	struct tegra_drm_bo *cma_bo;

These can probably just be named "cma"/"gem" and "bo" instead.

drivers/gpu/host1x/drm/drm.c static void tegra_drm_lastclose(struct drm_device *drm) · line 480

Quoted 2 lines
drivers/gpu/host1x/drm/drm.c +2 -0
+static int tegra_drm_ioctl_get_offset(struct drm_device *drm, void *data,
+				      struct drm_file *file_priv)

I think this might be more generically named tegra_drm_ioctl_mmap() which might come in handy if we ever need to do something more than just retrieve the offset.

drivers/gpu/host1x/drm/drm.c static void tegra_drm_lastclose(struct drm_device *drm) · line 489

Quoted 9 lines
drivers/gpu/host1x/drm/drm.c +9 -0
+{
+	struct tegra_drm_get_offset *args = data;
+	struct drm_gem_cma_object *cma_obj;
+	struct drm_gem_object *obj;
+
+	obj = drm_gem_object_lookup(drm, file_priv, args->handle);
+	if (!obj)
+		return -EINVAL;
+	cma_obj = to_drm_gem_cma_obj(obj);

The above two lines should be separated by a blank line.

drivers/gpu/host1x/drm/drm.c

Quoted 2 lines
drivers/gpu/host1x/drm/drm.c +2 -0
+
+	args->offset = cma_obj->base.map_list.hash.key << PAGE_SHIFT;

Perhaps a better way would be to export the get_gem_mmap_offset() from drivers/gpu/drm/drm_gem_cma_helper.c and reuse that.

Quoted 10 lines

static struct drm_ioctl_desc tegra_drm_ioctls[] = {

drivers/gpu/host1x/drm/drm.c +9 -0
+	DRM_IOCTL_DEF_DRV(TEGRA_DRM_GEM_CREATE,
+			tegra_drm_gem_create_ioctl, DRM_UNLOCKED | DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(TEGRA_DRM_SYNCPT_READ,
+			tegra_drm_ioctl_syncpt_read, DRM_UNLOCKED),
+	DRM_IOCTL_DEF_DRV(TEGRA_DRM_SYNCPT_INCR,
+			tegra_drm_ioctl_syncpt_incr, DRM_UNLOCKED),
+	DRM_IOCTL_DEF_DRV(TEGRA_DRM_SYNCPT_WAIT,
+			tegra_drm_ioctl_syncpt_wait, DRM_UNLOCKED),
+	DRM_IOCTL_DEF_DRV(TEGRA_DRM_OPEN_CHANNEL,

drivers/gpu/host1x/drm/drm.c static void tegra_drm_lastclose(struct drm_device *drm) · line 527

Quoted 10 lines
drivers/gpu/host1x/drm/drm.c +9 -0
+			tegra_drm_ioctl_open_channel, DRM_UNLOCKED),
+	DRM_IOCTL_DEF_DRV(TEGRA_DRM_CLOSE_CHANNEL,
+			tegra_drm_ioctl_close_channel, DRM_UNLOCKED),
+	DRM_IOCTL_DEF_DRV(TEGRA_DRM_GET_SYNCPOINT,
+			tegra_drm_ioctl_get_syncpoint, DRM_UNLOCKED),
+	DRM_IOCTL_DEF_DRV(TEGRA_DRM_SUBMIT,
+			tegra_drm_ioctl_submit, DRM_UNLOCKED),
+	DRM_IOCTL_DEF_DRV(TEGRA_DRM_GEM_GET_OFFSET,
+			tegra_drm_ioctl_get_offset, DRM_UNLOCKED),
 };

Maybe resort these to put the GEM-specific IOCTLs closer together?

Quoted 5 lines

static const struct file_operations tegra_drm_fops = {

drivers/gpu/host1x/drm/drm.c +0 -0
@@ -345,10 +585,17 @@ static void tegra_drm_disable_vblank(struct drm_device *drm, int pipe)
 
 static void tegra_drm_preclose(struct drm_device *drm, struct drm_file *file)
 {

drivers/gpu/host1x/drm/drm.c static void tegra_drm_disable_vblank(struct drm_device *drm, int pipe) · line 597

Quoted 10 lines
drivers/gpu/host1x/drm/drm.c +6 -0
+	struct host1x_drm_file *fpriv = file->driver_priv;
+	struct host1x_drm_context *context, *tmp;
 	struct drm_crtc *crtc;
 
 	list_for_each_entry(crtc, &drm->mode_config.crtc_list, head)
 		tegra_dc_cancel_page_flip(crtc, file);
+
+	list_for_each_entry_safe(context, tmp, &fpriv->contexts, list)
+		host1x_drm_context_free(context);
+	kfree(fpriv);

Another missing blank line between these.

Quoted 1 line
drivers/gpu/host1x/drm/gr2d.c +0 -0

[...]

Quoted 11 lines
drivers/gpu/host1x/drm/gr2d.c +11 -0
+static struct host1x_bo *handle_cma_to_host1x(struct drm_device *drm,
+					      struct drm_file *file_priv,
+					      u32 gem_handle)
+{
+	struct drm_gem_object *gem_obj;
+	struct drm_gem_cma_object *cma_obj;
+	struct tegra_drm_bo *cma_bo;
+
+	gem_obj = drm_gem_object_lookup(drm, file_priv, gem_handle);
+	if (!gem_obj)
+		return 0;

drivers/gpu/host1x/drm/gr2d.c line 93

Quoted 10 lines
drivers/gpu/host1x/drm/gr2d.c +10 -0
+
+	mutex_lock(&drm->struct_mutex);
+	drm_gem_object_unreference(gem_obj);
+	mutex_unlock(&drm->struct_mutex);
+
+	cma_obj = to_drm_gem_cma_obj(gem_obj);
+	cma_bo = container_of(cma_obj, struct tegra_drm_bo, cma_obj);
+
+	return &cma_bo->base;
+}

Maybe rename this to host1x_bo_lookup()? *_to_* are usually used for up- and downcasting; this function does a lot more.

Quoted 27 lines
drivers/gpu/host1x/drm/gr2d.c +27 -0
+static int gr2d_submit(struct host1x_drm_context *context,
+		       struct tegra_drm_submit_args *args,
+		       struct drm_device *drm,
+		       struct drm_file *file_priv)
+{
+	struct host1x_job *job;
+	int num_cmdbufs = args->num_cmdbufs;
+	int num_relocs = args->num_relocs;
+	int num_waitchks = args->num_waitchks;
+	struct tegra_drm_cmdbuf __user *cmdbufs =
+		(void * __user)(uintptr_t)args->cmdbufs;
+	struct tegra_drm_reloc __user *relocs =
+		(void * __user)(uintptr_t)args->relocs;
+	struct tegra_drm_waitchk __user *waitchks =
+		(void * __user)(uintptr_t)args->waitchks;
+	struct tegra_drm_syncpt_incr syncpt_incr;
+	int err;
+
+	/* We don't yet support other than one syncpt_incr struct per submit */
+	if (args->num_syncpt_incrs != 1)
+		return -EINVAL;
+
+	job = host1x_job_alloc(context->channel, args->num_cmdbufs,
+			       args->num_relocs, args->num_waitchks);
+	if (!job)
+		return -ENOMEM;
+

drivers/gpu/host1x/drm/gr2d.c line 131

Quoted 10 lines
drivers/gpu/host1x/drm/gr2d.c +10 -0
+	job->num_relocs = args->num_relocs;
+	job->num_waitchk = args->num_waitchks;
+	job->client = (u32)args->context;
+	job->class = context->client->class;
+	job->serialize = true;
+
+	while (num_cmdbufs) {
+		struct tegra_drm_cmdbuf cmdbuf;
+		struct host1x_bo *mem_handle;
+		err = copy_from_user(&cmdbuf, cmdbufs, sizeof(cmdbuf));

Could use an blank line to separate variable declarations from the code. Also maybe rename mem_handle to bo which is much shorter.

Quoted 7 lines
drivers/gpu/host1x/drm/gr2d.c +7 -0
+		goto fail;
+
+	err = host1x_job_pin(job, context->client->dev);
+	if (err)
+		goto fail;
+
+	err = copy_from_user(&syncpt_incr,

drivers/gpu/host1x/drm/gr2d.c line 182

Quoted 10 lines
drivers/gpu/host1x/drm/gr2d.c +10 -0
+			     (void * __user)(uintptr_t)args->syncpt_incrs,
+			     sizeof(syncpt_incr));
+	if (err)
+		goto fail;
+
+	job->syncpt_id = syncpt_incr.id;
+	job->syncpt_incrs = syncpt_incr.incrs;
+	job->timeout = 10000;
+	job->is_addr_reg = gr2d_is_addr_reg;
+	if (args->timeout && args->timeout < 10000)

Another missing blank line.

Also you now create a lookup table (or bitfield actually) as we discussed but you still pass around a function to check the lookup table against. What I originally intended was to not pass a function around at all but directly use the lookup table/bitfield. However I think we can leave this as-is for now and change it later if required.

drivers/gpu/host1x/drm/gr2d.c line 255

Quoted 7 lines
drivers/gpu/host1x/drm/gr2d.c +7 -0
+static int gr2d_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct host1x_drm *host1x = host1x_get_drm_data(dev->parent);
+	int err;
+	struct gr2d *gr2d = NULL;
+	struct host1x_syncpt **syncpts;

I don't think there's a need for this temporary variable. You could just use gr2d->client.syncpts directly.

Quoted 35 lines
drivers/gpu/host1x/drm/gr2d.c +35 -0
+	gr2d = devm_kzalloc(dev, sizeof(*gr2d), GFP_KERNEL);
+	if (!gr2d)
+		return -ENOMEM;
+
+	syncpts = devm_kzalloc(dev, sizeof(*syncpts), GFP_KERNEL);
+	if (!syncpts)
+		return -ENOMEM;
+
+	gr2d->clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(gr2d->clk)) {
+		dev_err(dev, "cannot get clock\n");
+		return PTR_ERR(gr2d->clk);
+	}
+
+	err = clk_prepare_enable(gr2d->clk);
+	if (err) {
+		dev_err(dev, "cannot turn on clock\n");
+		return err;
+	}
+
+	gr2d->channel = host1x_channel_alloc(dev);
+	if (!gr2d->channel)
+		return -ENOMEM;
+
+	*syncpts = host1x_syncpt_request(dev, 0);
+	if (!(*syncpts)) {
+		host1x_channel_free(gr2d->channel);
+		return -ENOMEM;
+	}
+
+	gr2d->client.ops = &gr2d_client_ops;
+	gr2d->client.dev = dev;
+	gr2d->client.class = HOST1X_CLASS_GR2D;
+	gr2d->client.syncpts = syncpts;
+	gr2d->client.num_syncpts = 1;

drivers/gpu/host1x/drm/gr2d.c line 301

Quoted 10 lines
drivers/gpu/host1x/drm/gr2d.c +10 -0
+
+	err = host1x_register_client(host1x, &gr2d->client);
+	if (err < 0) {
+		dev_err(dev, "failed to register host1x client: %d\n", err);
+		return err;
+	}
+
+	gr2d_init_addr_reg_map(dev, gr2d);
+
+	dev_set_drvdata(dev, gr2d);

Nit: I think it'd be nicer to use platform_set_drvdata() here to mirror the platform_get_drvdata() from gr2d_remove().

Quoted 1 line
include/drm/tegra_drm.h +0 -0

[...]

Quoted 1 line

+struct tegra_drm_create {

struct tegra_drm_gem_create?

include/drm/tegra_drm.h line 25

Quoted 5 lines
include/drm/tegra_drm.h +5 -0
+	__u64 size;
+	u32 flags;
+	u32 handle;
+	u32 offset;
+	u32 padding;

Also since we have a separate IOCTL for this, I think you can leave out the offset field (and also padding since it isn't required anymore).

include/drm/tegra_drm.h line 31

Quoted 4 lines
include/drm/tegra_drm.h +4 -0
+struct tegra_drm_get_offset {
+	__u32 handle;
+	__u32 offset;
+};

struct tegra_drm_gem_mmap to go along with the name change of the IOCTL.

include/drm/tegra_drm.h line 41

Quoted 4 lines
include/drm/tegra_drm.h +4 -0
+struct tegra_drm_syncpt_incr_args {
+	__u32 id;
+	__u32 pad;
+};

Shouldn't this second field be something like "value" to allow this IOCTL to increment by more than 1?

Quoted 1 line

+#define DRM_TEGRA_NO_TIMEOUT (0xffffffff)

No need for the parentheses.

include/drm/tegra_drm.h line 83

Quoted 8 lines
include/drm/tegra_drm.h +8 -0
+struct tegra_drm_reloc {
+	__u32 cmdbuf_mem;
+	__u32 cmdbuf_offset;
+	__u32 target;
+	__u32 target_offset;
+	__u32 shift;
+	__u32 pad;
+};

I've found this to be a little inconsistent. Why does the cmdbuf_mem have the _mem suffix, but not the target field? Given that this will eventually be used by userspace software once merged it will be fixed forever. I had noticed the same for the in-kernel structures but didn't think it important enough to hold up the patches. In this case I think we should make them consistent, though.

Quoted 9 lines
include/drm/tegra_drm.h +9 -0
+#define DRM_TEGRA_DRM_GEM_CREATE	0x00
+#define DRM_TEGRA_DRM_SYNCPT_READ	0x01
+#define DRM_TEGRA_DRM_SYNCPT_INCR	0x02
+#define DRM_TEGRA_DRM_SYNCPT_WAIT	0x03
+#define DRM_TEGRA_DRM_OPEN_CHANNEL	0x04
+#define DRM_TEGRA_DRM_CLOSE_CHANNEL	0x05
+#define DRM_TEGRA_DRM_GET_SYNCPOINT	0x06
+#define DRM_TEGRA_DRM_SUBMIT		0x08
+#define DRM_TEGRA_DRM_GEM_GET_OFFSET	0x09

include/drm/tegra_drm.h line 129

Quoted 10 lines
include/drm/tegra_drm.h +10 -0
+
+#define DRM_IOCTL_TEGRA_DRM_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_GEM_CREATE, struct tegra_drm_create)
+#define DRM_IOCTL_TEGRA_DRM_SYNCPT_READ DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_SYNCPT_READ, struct tegra_drm_syncpt_read_args)
+#define DRM_IOCTL_TEGRA_DRM_SYNCPT_INCR DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_SYNCPT_INCR, struct tegra_drm_syncpt_incr_args)
+#define DRM_IOCTL_TEGRA_DRM_SYNCPT_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_SYNCPT_WAIT, struct tegra_drm_syncpt_wait_args)
+#define DRM_IOCTL_TEGRA_DRM_OPEN_CHANNEL DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_OPEN_CHANNEL, struct tegra_drm_open_channel_args)
+#define DRM_IOCTL_TEGRA_DRM_CLOSE_CHANNEL DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_CLOSE_CHANNEL, struct tegra_drm_open_channel_args)
+#define DRM_IOCTL_TEGRA_DRM_GET_SYNCPOINT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_GET_SYNCPOINT, struct tegra_drm_get_syncpoint)
+#define DRM_IOCTL_TEGRA_DRM_SUBMIT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_SUBMIT, struct tegra_drm_submit_args)
+#define DRM_IOCTL_TEGRA_DRM_GEM_GET_OFFSET DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_GEM_GET_OFFSET, struct tegra_drm_get_offset)

Same comment regarding reordering and GET_OFFSET -> MMAP rename.

Thierry

#12 lore raw

Re: [PATCHv7 10/10] drm: tegra: Add gr2d device

Quoted 18 lines · Thierry Reding

On Wed, Mar 13, 2013 at 02:36:26PM +0200, Terje Bergstrom wrote:
[...]

Quoted 1 line
drivers/gpu/host1x/drm/drm.c +0 -0

[...]

drivers/gpu/host1x/drm/drm.c static void tegra_drm_lastclose(struct drm_device *drm) · line 363

Quoted 11 lines
drivers/gpu/host1x/drm/drm.c +11 -0
+static inline struct host1x_drm_context *tegra_drm_get_context(
+                                     struct list_head *contexts,
+                                     struct host1x_drm_context *_ctx)
+{
+     struct host1x_drm_context *ctx;
+
+     list_for_each_entry(ctx, contexts, list)
+             if (ctx == _ctx)
+                     return ctx;
+     return NULL;
+}

Maybe make this a little more high-level, such as:

Quoted 4 lines

static bool host1x_drm_file_owns_context(struct host1x_drm_file *file,
struct host1x_drm_context *context)

?

We only need the true/false value, so changing signature makes sense.

Quoted 15 lines
Quoted 15 lines
drivers/gpu/host1x/drm/drm.c +14 -0
+static int tegra_drm_ioctl_open_channel(struct drm_device *drm, void *data,
+                                     struct drm_file *file_priv)
+{
+     struct tegra_drm_open_channel_args *args = data;
+     struct host1x_client *client;
+     struct host1x_drm_context *context;
+     struct host1x_drm_file *fpriv = file_priv->driver_priv;
+     struct host1x_drm *host1x = drm->dev_private;
+     int err = -ENODEV;
+
+     context = kzalloc(sizeof(*context), GFP_KERNEL);
+     if (!context)
+             return -ENOMEM;
+
Quoted 8 lines

drivers/gpu/host1x/drm/drm.c static void tegra_drm_lastclose(struct drm_device *drm) · line 381

Quoted 3 lines
drivers/gpu/host1x/drm/drm.c +3 -0
+     list_for_each_entry(client, &host1x->clients, list)
+             if (client->class == args->class) {
+                     context->client = client;

Why do you assign this here? Should it perhaps be assigned only when the opening of the channel succeeds? The .open_channel() already receives a pointer to the client as parameter, so it doesn't have to be associated with the context.

True, we can move the assignment to happen after checking the open_channel result.

Quoted 17 lines
Quoted 4 lines
drivers/gpu/host1x/drm/drm.c +3 -0
+static int tegra_drm_ioctl_get_syncpoint(struct drm_device *drm, void *data,
+                                      struct drm_file *file_priv)
+{

drivers/gpu/host1x/drm/drm.c static void tegra_drm_lastclose(struct drm_device *drm) · line 424

Quoted 10 lines
drivers/gpu/host1x/drm/drm.c +10 -0
+     struct tegra_drm_get_syncpoint *args = data;
+     struct host1x_drm_file *fpriv = file_priv->driver_priv;
+     struct host1x_drm_context *context =
+             (struct host1x_drm_context *)(uintptr_t)args->context;
+
+     if (!tegra_drm_get_context(&fpriv->contexts, context))
+             return -ENODEV;
+
+     if (context->client->num_syncpts < args->param)
+             return -ENODEV;

I think this might be easier to read as:

Quoted 2 lines
        if (args->param >= context->client->num_syncpts)
                return -ENODEV;

Ok, will do.

Quoted 4 lines
Quoted 2 lines

+ args->value = host1x_syncpt_id(context->client->syncpts[args->param]);

This could use a temporary variable "syncpt" to make it easier to read.

Ok.

Quoted 5 lines

drivers/gpu/host1x/drm/drm.c

Quoted 3 lines
drivers/gpu/host1x/drm/drm.c +2 -0
+static int tegra_drm_gem_create_ioctl(struct drm_device *drm, void *data,
+                                   struct drm_file *file_priv)

tegra_drm_ioctl_gem_create()?

Sure.

Quoted 7 lines

drivers/gpu/host1x/drm/drm.c static void tegra_drm_lastclose(struct drm_device *drm) · line 450

Quoted 5 lines
drivers/gpu/host1x/drm/drm.c +4 -0
+{
+     struct tegra_drm_create *args = data;
+     struct drm_gem_cma_object *cma_obj;
+     struct tegra_drm_bo *cma_bo;

These can probably just be named "cma"/"gem" and "bo" instead.

Ok.

Quoted 7 lines

drivers/gpu/host1x/drm/drm.c static void tegra_drm_lastclose(struct drm_device *drm) · line 480

Quoted 3 lines
drivers/gpu/host1x/drm/drm.c +2 -0
+static int tegra_drm_ioctl_get_offset(struct drm_device *drm, void *data,
+                                   struct drm_file *file_priv)

I think this might be more generically named tegra_drm_ioctl_mmap() which might come in handy if we ever need to do something more than just retrieve the offset.

Yeah, that changes the API semantics a bit, but in general there shouldn't be a need to just get the offset without doing the actual mmap.

Quoted 12 lines

drivers/gpu/host1x/drm/drm.c static void tegra_drm_lastclose(struct drm_device *drm) · line 489

Quoted 10 lines
drivers/gpu/host1x/drm/drm.c +9 -0
+{
+     struct tegra_drm_get_offset *args = data;
+     struct drm_gem_cma_object *cma_obj;
+     struct drm_gem_object *obj;
+
+     obj = drm_gem_object_lookup(drm, file_priv, args->handle);
+     if (!obj)
+             return -EINVAL;
+     cma_obj = to_drm_gem_cma_obj(obj);

The above two lines should be separated by a blank line.

Ok.

Quoted 6 lines

drivers/gpu/host1x/drm/drm.c

Quoted 3 lines
drivers/gpu/host1x/drm/drm.c +2 -0
+
+     args->offset = cma_obj->base.map_list.hash.key << PAGE_SHIFT;

Perhaps a better way would be to export the get_gem_mmap_offset() from drivers/gpu/drm/drm_gem_cma_helper.c and reuse that.

Ok, we'll add that as a patch to the series.

Quoted 22 lines
Quoted 11 lines

static struct drm_ioctl_desc tegra_drm_ioctls[] = {

drivers/gpu/host1x/drm/drm.c +9 -0
+     DRM_IOCTL_DEF_DRV(TEGRA_DRM_GEM_CREATE,
+                     tegra_drm_gem_create_ioctl, DRM_UNLOCKED | DRM_AUTH),
+     DRM_IOCTL_DEF_DRV(TEGRA_DRM_SYNCPT_READ,
+                     tegra_drm_ioctl_syncpt_read, DRM_UNLOCKED),
+     DRM_IOCTL_DEF_DRV(TEGRA_DRM_SYNCPT_INCR,
+                     tegra_drm_ioctl_syncpt_incr, DRM_UNLOCKED),
+     DRM_IOCTL_DEF_DRV(TEGRA_DRM_SYNCPT_WAIT,
+                     tegra_drm_ioctl_syncpt_wait, DRM_UNLOCKED),
+     DRM_IOCTL_DEF_DRV(TEGRA_DRM_OPEN_CHANNEL,

drivers/gpu/host1x/drm/drm.c static void tegra_drm_lastclose(struct drm_device *drm) · line 527

Quoted 10 lines
drivers/gpu/host1x/drm/drm.c +9 -0
+                     tegra_drm_ioctl_open_channel, DRM_UNLOCKED),
+     DRM_IOCTL_DEF_DRV(TEGRA_DRM_CLOSE_CHANNEL,
+                     tegra_drm_ioctl_close_channel, DRM_UNLOCKED),
+     DRM_IOCTL_DEF_DRV(TEGRA_DRM_GET_SYNCPOINT,
+                     tegra_drm_ioctl_get_syncpoint, DRM_UNLOCKED),
+     DRM_IOCTL_DEF_DRV(TEGRA_DRM_SUBMIT,
+                     tegra_drm_ioctl_submit, DRM_UNLOCKED),
+     DRM_IOCTL_DEF_DRV(TEGRA_DRM_GEM_GET_OFFSET,
+                     tegra_drm_ioctl_get_offset, DRM_UNLOCKED),
 };
Quoted 1 line

Maybe resort these to put the GEM-specific IOCTLs closer together?

Ok.

Quoted 10 lines
Quoted 10 lines

static const struct file_operations tegra_drm_fops = {

drivers/gpu/host1x/drm/drm.c +2 -0
@@ -345,10 +585,17 @@ static void tegra_drm_disable_vblank(struct drm_device *drm, int pipe)
 
 static void tegra_drm_preclose(struct drm_device *drm, struct drm_file *file)
 {
+     struct host1x_drm_file *fpriv = file->driver_priv;
+     struct host1x_drm_context *context, *tmp;
      struct drm_crtc *crtc;
 
Quoted 8 lines

drivers/gpu/host1x/drm/drm.c static void tegra_drm_disable_vblank(struct drm_device *drm, int pipe) · line 597

Quoted 6 lines
drivers/gpu/host1x/drm/drm.c +4 -0
      list_for_each_entry(crtc, &drm->mode_config.crtc_list, head)
              tegra_dc_cancel_page_flip(crtc, file);
+
+     list_for_each_entry_safe(context, tmp, &fpriv->contexts, list)
+             host1x_drm_context_free(context);
+     kfree(fpriv);

Another missing blank line between these.

Will fix.

Quoted 19 lines
Quoted 2 lines
drivers/gpu/host1x/drm/gr2d.c +0 -0

[...]

Quoted 16 lines
drivers/gpu/host1x/drm/gr2d.c +16 -0
+static struct host1x_bo *handle_cma_to_host1x(struct drm_device *drm,
+                                           struct drm_file *file_priv,
+                                           u32 gem_handle)
+{
+     struct drm_gem_object *gem_obj;
+     struct drm_gem_cma_object *cma_obj;
+     struct tegra_drm_bo *cma_bo;
+
+     gem_obj = drm_gem_object_lookup(drm, file_priv, gem_handle);
+     if (!gem_obj)
+             return 0;
+
+     mutex_lock(&drm->struct_mutex);
+     drm_gem_object_unreference(gem_obj);
+     mutex_unlock(&drm->struct_mutex);
+
Quoted 8 lines

drivers/gpu/host1x/drm/gr2d.c line 93

Quoted 5 lines
drivers/gpu/host1x/drm/gr2d.c +5 -0
+     cma_obj = to_drm_gem_cma_obj(gem_obj);
+     cma_bo = container_of(cma_obj, struct tegra_drm_bo, cma_obj);
+
+     return &cma_bo->base;
+}

Maybe rename this to host1x_bo_lookup()? *_to_* are usually used for up- and downcasting; this function does a lot more.

Yep, will do.

Quoted 33 lines
Quoted 33 lines
drivers/gpu/host1x/drm/gr2d.c +32 -0
+static int gr2d_submit(struct host1x_drm_context *context,
+                    struct tegra_drm_submit_args *args,
+                    struct drm_device *drm,
+                    struct drm_file *file_priv)
+{
+     struct host1x_job *job;
+     int num_cmdbufs = args->num_cmdbufs;
+     int num_relocs = args->num_relocs;
+     int num_waitchks = args->num_waitchks;
+     struct tegra_drm_cmdbuf __user *cmdbufs =
+             (void * __user)(uintptr_t)args->cmdbufs;
+     struct tegra_drm_reloc __user *relocs =
+             (void * __user)(uintptr_t)args->relocs;
+     struct tegra_drm_waitchk __user *waitchks =
+             (void * __user)(uintptr_t)args->waitchks;
+     struct tegra_drm_syncpt_incr syncpt_incr;
+     int err;
+
+     /* We don't yet support other than one syncpt_incr struct per submit */
+     if (args->num_syncpt_incrs != 1)
+             return -EINVAL;
+
+     job = host1x_job_alloc(context->channel, args->num_cmdbufs,
+                            args->num_relocs, args->num_waitchks);
+     if (!job)
+             return -ENOMEM;
+
+     job->num_relocs = args->num_relocs;
+     job->num_waitchk = args->num_waitchks;
+     job->client = (u32)args->context;
+     job->class = context->client->class;
+     job->serialize = true;
Quoted 8 lines

drivers/gpu/host1x/drm/gr2d.c line 131

Quoted 5 lines
drivers/gpu/host1x/drm/gr2d.c +5 -0
+
+     while (num_cmdbufs) {
+             struct tegra_drm_cmdbuf cmdbuf;
+             struct host1x_bo *mem_handle;
+             err = copy_from_user(&cmdbuf, cmdbufs, sizeof(cmdbuf));

Could use an blank line to separate variable declarations from the code. Also maybe rename mem_handle to bo which is much shorter.

Sure, mem_handle is anyway legacy naming.

Quoted 21 lines
Quoted 8 lines
drivers/gpu/host1x/drm/gr2d.c +7 -0
+             goto fail;
+
+     err = host1x_job_pin(job, context->client->dev);
+     if (err)
+             goto fail;
+
+     err = copy_from_user(&syncpt_incr,

drivers/gpu/host1x/drm/gr2d.c line 182

Quoted 10 lines
drivers/gpu/host1x/drm/gr2d.c +10 -0
+                          (void * __user)(uintptr_t)args->syncpt_incrs,
+                          sizeof(syncpt_incr));
+     if (err)
+             goto fail;
+
+     job->syncpt_id = syncpt_incr.id;
+     job->syncpt_incrs = syncpt_incr.incrs;
+     job->timeout = 10000;
+     job->is_addr_reg = gr2d_is_addr_reg;
+     if (args->timeout && args->timeout < 10000)

Another missing blank line.

Quoted 5 lines

Also you now create a lookup table (or bitfield actually) as we discussed but you still pass around a function to check the lookup table against. What I originally intended was to not pass a function around at all but directly use the lookup table/bitfield. However I think we can leave this as-is for now and change it later if required.

Oops, the intention was to pass the table around, but I and Arto both missed that. We'll fix that.

Quoted 11 lines

drivers/gpu/host1x/drm/gr2d.c line 255

Quoted 8 lines
drivers/gpu/host1x/drm/gr2d.c +7 -0
+static int gr2d_probe(struct platform_device *pdev)
+{
+     struct device *dev = &pdev->dev;
+     struct host1x_drm *host1x = host1x_get_drm_data(dev->parent);
+     int err;
+     struct gr2d *gr2d = NULL;
+     struct host1x_syncpt **syncpts;

I don't think there's a need for this temporary variable. You could just use gr2d->client.syncpts directly.

Ok, it might make a bit longer lines, but it doesn't look too bad.

Quoted 41 lines
Quoted 41 lines
drivers/gpu/host1x/drm/gr2d.c +40 -0
+     gr2d = devm_kzalloc(dev, sizeof(*gr2d), GFP_KERNEL);
+     if (!gr2d)
+             return -ENOMEM;
+
+     syncpts = devm_kzalloc(dev, sizeof(*syncpts), GFP_KERNEL);
+     if (!syncpts)
+             return -ENOMEM;
+
+     gr2d->clk = devm_clk_get(dev, NULL);
+     if (IS_ERR(gr2d->clk)) {
+             dev_err(dev, "cannot get clock\n");
+             return PTR_ERR(gr2d->clk);
+     }
+
+     err = clk_prepare_enable(gr2d->clk);
+     if (err) {
+             dev_err(dev, "cannot turn on clock\n");
+             return err;
+     }
+
+     gr2d->channel = host1x_channel_alloc(dev);
+     if (!gr2d->channel)
+             return -ENOMEM;
+
+     *syncpts = host1x_syncpt_request(dev, 0);
+     if (!(*syncpts)) {
+             host1x_channel_free(gr2d->channel);
+             return -ENOMEM;
+     }
+
+     gr2d->client.ops = &gr2d_client_ops;
+     gr2d->client.dev = dev;
+     gr2d->client.class = HOST1X_CLASS_GR2D;
+     gr2d->client.syncpts = syncpts;
+     gr2d->client.num_syncpts = 1;
+
+     err = host1x_register_client(host1x, &gr2d->client);
+     if (err < 0) {
+             dev_err(dev, "failed to register host1x client: %d\n", err);
+             return err;
Quoted 8 lines

drivers/gpu/host1x/drm/gr2d.c line 301

Quoted 5 lines
drivers/gpu/host1x/drm/gr2d.c +5 -0
+     }
+
+     gr2d_init_addr_reg_map(dev, gr2d);
+
+     dev_set_drvdata(dev, gr2d);

Nit: I think it'd be nicer to use platform_set_drvdata() here to mirror the platform_get_drvdata() from gr2d_remove().

Yeah, we'll fix that.

Quoted 6 lines
Quoted 2 lines
include/drm/tegra_drm.h +0 -0

[...]

Quoted 1 line

+struct tegra_drm_create {

struct tegra_drm_gem_create?

Yep.

Quoted 9 lines

include/drm/tegra_drm.h line 25

Quoted 6 lines
include/drm/tegra_drm.h +5 -0
+     __u64 size;
+     u32 flags;
+     u32 handle;
+     u32 offset;
+     u32 padding;

Also since we have a separate IOCTL for this, I think you can leave out the offset field (and also padding since it isn't required anymore).

This is a genuine mistake, offset should've been dropped.

Quoted 7 lines

include/drm/tegra_drm.h line 31

Quoted 5 lines
include/drm/tegra_drm.h +4 -0
+struct tegra_drm_get_offset {
+     __u32 handle;
+     __u32 offset;
+};

struct tegra_drm_gem_mmap to go along with the name change of the IOCTL.

Ok.

Quoted 8 lines

include/drm/tegra_drm.h line 41

Quoted 5 lines
include/drm/tegra_drm.h +4 -0
+struct tegra_drm_syncpt_incr_args {
+     __u32 id;
+     __u32 pad;
+};

Shouldn't this second field be something like "value" to allow this IOCTL to increment by more than 1?

This is actually an IOCTL that normally shouldn't be used. It's still there for testing.

The intention with this is that user space can submit a job that waits for a sync point value. The user space can then investigate the state of the channel to verify that host1x driver is working correctly. After investigation, user space can increment the sync point to unblock the channel.

It's a bit tricky to find out the correct sync point value to wait for, but for test cases we can usually hack it together by just shutting down all other users of host1x and reading current value.

Quoted 3 lines
Quoted 1 line

+#define DRM_TEGRA_NO_TIMEOUT (0xffffffff)

No need for the parentheses.

Sure, will remove.

Quoted 16 lines

include/drm/tegra_drm.h line 83

Quoted 9 lines
include/drm/tegra_drm.h +8 -0
+struct tegra_drm_reloc {
+     __u32 cmdbuf_mem;
+     __u32 cmdbuf_offset;
+     __u32 target;
+     __u32 target_offset;
+     __u32 shift;
+     __u32 pad;
+};

I've found this to be a little inconsistent. Why does the cmdbuf_mem have the _mem suffix, but not the target field? Given that this will eventually be used by userspace software once merged it will be fixed forever. I had noticed the same for the in-kernel structures but didn't think it important enough to hold up the patches. In this case I think we should make them consistent, though.

Ok. I propose we rename target to target_mem. We could also rename tegra_drm_waitchk.mem to cmdbuf_mem and tegra_drm_waitchk.offset to cmdbuf_offset for consistency.

Quoted 14 lines
Quoted 14 lines
include/drm/tegra_drm.h +13 -0
+#define DRM_TEGRA_DRM_GEM_CREATE     0x00
+#define DRM_TEGRA_DRM_SYNCPT_READ    0x01
+#define DRM_TEGRA_DRM_SYNCPT_INCR    0x02
+#define DRM_TEGRA_DRM_SYNCPT_WAIT    0x03
+#define DRM_TEGRA_DRM_OPEN_CHANNEL   0x04
+#define DRM_TEGRA_DRM_CLOSE_CHANNEL  0x05
+#define DRM_TEGRA_DRM_GET_SYNCPOINT  0x06
+#define DRM_TEGRA_DRM_SUBMIT         0x08
+#define DRM_TEGRA_DRM_GEM_GET_OFFSET 0x09
+
+#define DRM_IOCTL_TEGRA_DRM_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_GEM_CREATE, struct tegra_drm_create)
+#define DRM_IOCTL_TEGRA_DRM_SYNCPT_READ DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_SYNCPT_READ, struct tegra_drm_syncpt_read_args)
+#define DRM_IOCTL_TEGRA_DRM_SYNCPT_INCR DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_SYNCPT_INCR, struct tegra_drm_syncpt_incr_args)
Quoted 8 lines

include/drm/tegra_drm.h line 129

Quoted 6 lines
include/drm/tegra_drm.h +6 -0
+#define DRM_IOCTL_TEGRA_DRM_SYNCPT_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_SYNCPT_WAIT, struct tegra_drm_syncpt_wait_args)
+#define DRM_IOCTL_TEGRA_DRM_OPEN_CHANNEL DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_OPEN_CHANNEL, struct tegra_drm_open_channel_args)
+#define DRM_IOCTL_TEGRA_DRM_CLOSE_CHANNEL DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_CLOSE_CHANNEL, struct tegra_drm_open_channel_args)
+#define DRM_IOCTL_TEGRA_DRM_GET_SYNCPOINT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_GET_SYNCPOINT, struct tegra_drm_get_syncpoint)
+#define DRM_IOCTL_TEGRA_DRM_SUBMIT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_SUBMIT, struct tegra_drm_submit_args)
+#define DRM_IOCTL_TEGRA_DRM_GEM_GET_OFFSET DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_GEM_GET_OFFSET, struct tegra_drm_get_offset)

Same comment regarding reordering and GET_OFFSET -> MMAP rename.

Ok.

Terje

#13 lore raw

Re: [PATCHv7 10/10] drm: tegra: Add gr2d device

In reply to Thierry Reding
Quoted 5 lines · Thierry Reding

Also you now create a lookup table (or bitfield actually) as we discussed but you still pass around a function to check the lookup table against. What I originally intended was to not pass a function around at all but directly use the lookup table/bitfield. However I think we can leave this as-is for now and change it later if required.

Yeah, I think it's better if we leave this as is now. We should actually have one table for host1x and one for 2D. The host1x one should be shared between the drivers, but the table for client unit should be local to the driver.

Let's take this up again when we have another driver.

Quoted 11 lines

drivers/gpu/host1x/drm/gr2d.c line 255

Quoted 8 lines
drivers/gpu/host1x/drm/gr2d.c new file +7 -0
+static int gr2d_probe(struct platform_device *pdev)
+{
+     struct device *dev = &pdev->dev;
+     struct host1x_drm *host1x = host1x_get_drm_data(dev->parent);
+     int err;
+     struct gr2d *gr2d = NULL;
+     struct host1x_syncpt **syncpts;

I don't think there's a need for this temporary variable. You could just use gr2d->client.syncpts directly.

I actually ended up with pretty long lines when I tried this, so I hope it's ok to leave as is.

Quoted 6 lines

drivers/gpu/host1x/drm/gr2d.c line 261

Quoted 6 lines
drivers/gpu/host1x/drm/gr2d.c new file +5 -0
+     gr2d = devm_kzalloc(dev, sizeof(*gr2d), GFP_KERNEL);
+     if (!gr2d)
+             return -ENOMEM;
+
+     syncpts = devm_kzalloc(dev, sizeof(*syncpts), GFP_KERNEL);

F.ex. this line would split two two lines.

Otherwise the changes should be now pretty much ok. You sent a bunch of changes (thanks) that I merged to my tree. I'll just need to do some testing and re-split the patches and send v8.

Terje