Skip to contentSkip to conversation

Support for Tegra 2D hardware

PATCH Superseded Terje Bergstrom 6 participants 35 messages Dec 21, 2012 – Jan 3, 2013

Subsystems (7)

v4 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#18 lore raw

PATCH v4 6/8 ARM: tegra: Add board data and 2D clocks

In reply to Terje Bergstrom

Add a driver alias gr2d for Tegra 2D device, and assign a duplicate of 2D clock to that driver alias.

---
 arch/arm/mach-tegra/board-dt-tegra20.c    |    1 +
 arch/arm/mach-tegra/board-dt-tegra30.c    |    1 +
 arch/arm/mach-tegra/tegra20_clocks_data.c |    2 +-
 arch/arm/mach-tegra/tegra30_clocks_data.c |    1 +
 4 files changed, 4 insertions(+), 1 deletion(-)
arch/arm/mach-tegra/board-dt-tegra20.c +1 -0
index 734d9cc..2b7a3c2 100644
@@ -95,6 +95,7 @@ struct of_dev_auxdata tegra20_auxdata_lookup[] __initdata = {
 	OF_DEV_AUXDATA("nvidia,tegra20-slink", 0x7000D800, "spi_tegra.2", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra20-slink", 0x7000DA00, "spi_tegra.3", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra20-host1x", 0x50000000, "host1x", NULL),
+	OF_DEV_AUXDATA("nvidia,tegra20-gr2d", 0x54140000, "gr2d", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra20-dc", 0x54200000, "tegradc.0", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra20-dc", 0x54240000, "tegradc.1", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra20-hdmi", 0x54280000, "hdmi", NULL),
arch/arm/mach-tegra/board-dt-tegra30.c +1 -0
index 6497d12..6a9e6cb 100644
@@ -58,6 +58,7 @@ struct of_dev_auxdata tegra30_auxdata_lookup[] __initdata = {
 	OF_DEV_AUXDATA("nvidia,tegra30-slink", 0x7000DC00, "spi_tegra.4", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra30-slink", 0x7000DE00, "spi_tegra.5", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra30-host1x", 0x50000000, "host1x", NULL),
+	OF_DEV_AUXDATA("nvidia,tegra30-gr2d", 0x54140000, "gr2d", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra30-dc", 0x54200000, "tegradc.0", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra30-dc", 0x54240000, "tegradc.1", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra30-hdmi", 0x54280000, "hdmi", NULL),
arch/arm/mach-tegra/tegra20_clocks_data.c +1 -1
index a23a073..15d440a 100644
@@ -1041,7 +1041,7 @@ static struct clk_duplicate tegra_clk_duplicates[] = {
 	CLK_DUPLICATE("usbd",	"utmip-pad",	NULL),
 	CLK_DUPLICATE("usbd",	"tegra-ehci.0",	NULL),
 	CLK_DUPLICATE("usbd",	"tegra-otg",	NULL),
-	CLK_DUPLICATE("2d",	"tegra_grhost",	"gr2d"),
+	CLK_DUPLICATE("2d",	"gr2d",	"gr2d"),
 	CLK_DUPLICATE("3d",	"tegra_grhost",	"gr3d"),
 	CLK_DUPLICATE("epp",	"tegra_grhost",	"epp"),
 	CLK_DUPLICATE("mpe",	"tegra_grhost",	"mpe"),
arch/arm/mach-tegra/tegra30_clocks_data.c +1 -0
index 6942c7a..5787865 100644
@@ -1338,6 +1338,7 @@ struct clk_duplicate tegra_clk_duplicates[] = {
 	CLK_DUPLICATE("pll_p", "tegradc.0", "parent"),
 	CLK_DUPLICATE("pll_p", "tegradc.1", "parent"),
 	CLK_DUPLICATE("pll_d2_out0", "hdmi", "parent"),
+	CLK_DUPLICATE("2d", "gr2d", "gr2d"),
 };
 
 struct clk *tegra_ptr_clks[] = {
Signature · 1 line
1.7.9.5
#0 lore raw

v4 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-20121220.

The fourth version has only few changes compared to previous version:
* Fixed some sparse warnings
* Fixed host1x Makefile to allow building as module
* Fixed host1x module unload
* Fixed tegradrm unload sequence
* host1x creates DRM dummy device and tegradrm uses it for storing DRM related data.

Some of the issues left open:
* Register definitions still use static inline. There has been a debate about code style versus ability to use compiler type checking and code coverage analysis. There was no conclusion, so I left it as was.
* Uses still CMA helpers. IOMMU support will replace CMA with host1x specific allocator.

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 https://gitorious.org/linux-tegra-drm/pages/Host1xIntroduction
also contains a short description of the functionality.

The patch set removes responsibility of host1x from tegradrm. At the same time, it moves all drm related infrastructure in drivers/gpu/drm/tegra/host1x.c to drm.c. To replace the host1x central device, host1x creates a dummy device for tegradrm to hang global data to. This is a break in responsibility split of tegradrm taking care of DRM and host1x driver taking care of host1x and clients, but this structure was insisted. I've kept creation of dummy device as a separate patch to illustrate the alternatives. It can be later squashed into other patches.

The patch set adds 2D driver to tegradrm, which uses host1x for communicating with host1x to access sync points and channels. We expect to use the same infrastructure for other host1x clients, so we have kept host1x and tegradrm separate.

The patch set also adds user space API to tegradrm for accessing host1x and 2D.

Arto Merilainen (1):
drm: tegra: Remove redundant host1x

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
ARM: tegra: Add board data and 2D clocks
drm: tegra: Add gr2d device
gpu: host1x: Register DRM dummy device

 arch/arm/mach-tegra/board-dt-tegra20.c      |    1 +
 arch/arm/mach-tegra/board-dt-tegra30.c      |    1 +
 arch/arm/mach-tegra/tegra20_clocks_data.c   |    2 +-
 arch/arm/mach-tegra/tegra30_clocks_data.c   |    1 +
 drivers/gpu/Makefile                        |    1 +
 drivers/gpu/drm/tegra/Kconfig               |    2 +-
 drivers/gpu/drm/tegra/Makefile              |    2 +-
 drivers/gpu/drm/tegra/dc.c                  |   26 +-
 drivers/gpu/drm/tegra/drm.c                 |  433 ++++++++++++++++++-
 drivers/gpu/drm/tegra/drm.h                 |   72 ++--
 drivers/gpu/drm/tegra/fb.c                  |   17 +-
 drivers/gpu/drm/tegra/gr2d.c                |  309 ++++++++++++++
 drivers/gpu/drm/tegra/hdmi.c                |   30 +-
 drivers/gpu/drm/tegra/host1x.c              |  325 --------------
 drivers/gpu/host1x/Kconfig                  |   28 ++
 drivers/gpu/host1x/Makefile                 |   17 +
 drivers/gpu/host1x/cdma.c                   |  475 ++++++++++++++++++++
 drivers/gpu/host1x/cdma.h                   |  107 +++++
 drivers/gpu/host1x/channel.c                |  137 ++++++
 drivers/gpu/host1x/channel.h                |   64 +++
 drivers/gpu/host1x/cma.c                    |  117 +++++
 drivers/gpu/host1x/cma.h                    |   43 ++
 drivers/gpu/host1x/debug.c                  |  207 +++++++++
 drivers/gpu/host1x/debug.h                  |   49 +++
 drivers/gpu/host1x/dev.c                    |  242 +++++++++++
 drivers/gpu/host1x/dev.h                    |  167 ++++++++
 drivers/gpu/host1x/drm.c                    |   51 +++
 drivers/gpu/host1x/drm.h                    |   25 ++
 drivers/gpu/host1x/hw/Makefile              |    6 +
 drivers/gpu/host1x/hw/cdma_hw.c             |  480 +++++++++++++++++++++
 drivers/gpu/host1x/hw/cdma_hw.h             |   37 ++
 drivers/gpu/host1x/hw/channel_hw.c          |  147 +++++++
 drivers/gpu/host1x/hw/debug_hw.c            |  399 +++++++++++++++++
 drivers/gpu/host1x/hw/host1x01.c            |   46 ++
 drivers/gpu/host1x/hw/host1x01.h            |   25 ++
 drivers/gpu/host1x/hw/host1x01_hardware.h   |  150 +++++++
 drivers/gpu/host1x/hw/hw_host1x01_channel.h |   98 +++++
 drivers/gpu/host1x/hw/hw_host1x01_sync.h    |  179 ++++++++
 drivers/gpu/host1x/hw/hw_host1x01_uclass.h  |  130 ++++++
 drivers/gpu/host1x/hw/intr_hw.c             |  178 ++++++++
 drivers/gpu/host1x/hw/syncpt_hw.c           |  157 +++++++
 drivers/gpu/host1x/intr.c                   |  377 ++++++++++++++++
 drivers/gpu/host1x/intr.h                   |  106 +++++
 drivers/gpu/host1x/job.c                    |  618 +++++++++++++++++++++++++++
 drivers/gpu/host1x/memmgr.c                 |  174 ++++++++
 drivers/gpu/host1x/memmgr.h                 |   53 +++
 drivers/gpu/host1x/syncpt.c                 |  398 +++++++++++++++++
 drivers/gpu/host1x/syncpt.h                 |  134 ++++++
 drivers/video/Kconfig                       |    2 +
 include/drm/tegra_drm.h                     |  131 ++++++
 include/linux/host1x.h                      |  217 ++++++++++
 include/trace/events/host1x.h               |  296 +++++++++++++
 52 files changed, 7095 insertions(+), 394 deletions(-)
 create mode 100644 drivers/gpu/drm/tegra/gr2d.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/cma.c
 create mode 100644 drivers/gpu/host1x/cma.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
 create mode 100644 drivers/gpu/host1x/drm.c
 create mode 100644 drivers/gpu/host1x/drm.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/cdma_hw.h
 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/memmgr.c
 create mode 100644 drivers/gpu/host1x/memmgr.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/linux/host1x.h
 create mode 100644 include/trace/events/host1x.h
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v4 1/8 gpu: host1x: Add host1x driver

Add host1x, the driver for host1x and its client unit 2D.

---
 drivers/gpu/Makefile                      |    1 +
 drivers/gpu/host1x/Kconfig                |    6 +
 drivers/gpu/host1x/Makefile               |    8 +
 drivers/gpu/host1x/dev.c                  |  182 +++++++++++++++++++++++
 drivers/gpu/host1x/dev.h                  |   79 ++++++++++
 drivers/gpu/host1x/hw/Makefile            |    6 +
 drivers/gpu/host1x/hw/host1x01.c          |   36 +++++
 drivers/gpu/host1x/hw/host1x01.h          |   25 ++++
 drivers/gpu/host1x/hw/host1x01_hardware.h |   26 ++++
 drivers/gpu/host1x/hw/hw_host1x01_sync.h  |   66 +++++++++
 drivers/gpu/host1x/hw/syncpt_hw.c         |  146 +++++++++++++++++++
 drivers/gpu/host1x/syncpt.c               |  227 +++++++++++++++++++++++++++++
 drivers/gpu/host1x/syncpt.h               |  128 ++++++++++++++++
 drivers/video/Kconfig                     |    2 +
 include/linux/host1x.h                    |   41 ++++++
 include/trace/events/host1x.h             |   61 ++++++++
 16 files changed, 1040 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/linux/host1x.h
 create mode 100644 include/trace/events/host1x.h
drivers/gpu/Makefile +1 -0
index cc92778..7fa2f68 100644
@@ -1 +1,2 @@
+obj-$(CONFIG_TEGRA_HOST1X)	+= host1x/
 obj-y			+= drm/ vga/ stub/
drivers/gpu/host1x/Kconfig new file +6 -0
new file mode 100644
index 0000000..e89fb2b
@@ -0,0 +1,6 @@
+config TEGRA_HOST1X
+	tristate "Tegra host1x driver"
+	help
+	  Driver for the Tegra host1x hardware.
+
+	  Required for enabling tegradrm.
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 +182 -0

182 lines not on this page · raw message

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

79 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 +36 -0
new file mode 100644
index 0000000..59176ba
@@ -0,0 +1,36 @@
+/*
+ * Host1x init for T20 and T30 Architecture Chips
+ *
+ * Copyright (c) 2011-2012, 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 <linux/init.h>
+#include <linux/clk.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/host1x.h>
+
+#include "hw/host1x01.h"
+#include "dev.h"
+#include "hw/host1x01_hardware.h"
+
+#include "hw/syncpt_hw.c"
+
+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..177725b
@@ -0,0 +1,25 @@
+/*
+ * Host1x init for T20 and T30 Architecture Chips
+ *
+ * Copyright (c) 2011-2012, 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 *);
+
+#endif /* HOST1X_HOST1X01_H_ */
drivers/gpu/host1x/hw/host1x01_hardware.h new file +26 -0
new file mode 100644
index 0000000..4e57f21
@@ -0,0 +1,26 @@
+/*
+ * Tegra host1x Register Offsets for Tegra20 and Tegra30
+ *
+ * Copyright (c) 2010-2012 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 +66 -0

66 lines not on this page · raw message

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

146 lines not on this page · raw message

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

227 lines not on this page · raw message

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

128 lines not on this page · raw message

drivers/video/Kconfig +2 -0
index e7068c5..09b3762 100644
@@ -19,6 +19,8 @@ source "drivers/char/agp/Kconfig"
 
 source "drivers/gpu/vga/Kconfig"
 
+source "drivers/gpu/host1x/Kconfig"
+
 source "drivers/gpu/drm/Kconfig"
 
 source "drivers/gpu/stub/Kconfig"
include/linux/host1x.h new file +41 -0

41 lines not on this page · raw message

include/trace/events/host1x.h new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#11 lore raw

PATCH v4 5/8 drm: tegra: Remove redundant host1x

In reply to Terje Bergstrom

From: Arto Merilainen <[email protected]>

This patch removes the redundant host1x driver from tegradrm and makes necessary bindings to the separate host driver.

The infrastructure for drm client lists is merged to drm.c.

The patch simplifies driver initialization; The original driver had two lists for registered devices (clients and drm_active). The clients list included references to all registered devices whereas the drm_active list included only the devices that the tegradrm driver itself supported. host1x is separated into a driver of its own and hence there should be no need to support registration of external drivers. Therefore, only the drm_active list is reserved. Removal of the list also simplifies the driver unregistration.

---
 drivers/gpu/drm/tegra/Kconfig  |    2 +-
 drivers/gpu/drm/tegra/Makefile |    2 +-
 drivers/gpu/drm/tegra/dc.c     |   23 +--
 drivers/gpu/drm/tegra/drm.c    |  231 ++++++++++++++++++++++++++--
 drivers/gpu/drm/tegra/drm.h    |   43 +++---
 drivers/gpu/drm/tegra/fb.c     |   17 ++-
 drivers/gpu/drm/tegra/hdmi.c   |   27 ++--
 drivers/gpu/drm/tegra/host1x.c |  325 ----------------------------------------
 include/drm/tegra_drm.h        |   20 +++
 9 files changed, 298 insertions(+), 392 deletions(-)
 delete mode 100644 drivers/gpu/drm/tegra/host1x.c
 create mode 100644 include/drm/tegra_drm.h
drivers/gpu/drm/tegra/Kconfig +1 -1
index be1daf7..4a0290e 100644
@@ -1,6 +1,6 @@
 config DRM_TEGRA
 	tristate "NVIDIA Tegra DRM"
-	depends on DRM && OF && ARCH_TEGRA
+	depends on DRM && OF && ARCH_TEGRA && TEGRA_HOST1X
 	select DRM_KMS_HELPER
 	select DRM_GEM_CMA_HELPER
 	select DRM_KMS_CMA_HELPER
drivers/gpu/drm/tegra/Makefile +1 -1
index 80f73d1..f4c05bb 100644
@@ -1,7 +1,7 @@
 ccflags-y := -Iinclude/drm
 ccflags-$(CONFIG_DRM_TEGRA_DEBUG) += -DDEBUG
 
-tegra-drm-y := drm.o fb.o dc.o host1x.o
+tegra-drm-y := drm.o fb.o dc.o
 tegra-drm-y += output.o rgb.o hdmi.o
 
 obj-$(CONFIG_DRM_TEGRA) += tegra-drm.o
drivers/gpu/drm/tegra/dc.c +12 -11
index 0744103..24bcd06 100644
@@ -673,10 +673,10 @@ static int tegra_dc_debugfs_exit(struct tegra_dc *dc)
 	return 0;
 }
 
-static int tegra_dc_drm_init(struct host1x_client *client,
+static int tegra_dc_drm_init(struct tegra_drm_client *client,
 			     struct drm_device *drm)
 {
-	struct tegra_dc *dc = host1x_client_to_dc(client);
+	struct tegra_dc *dc = tegra_drm_client_to_dc(client);
 	int err;
 
 	dc->pipe = drm->mode_config.num_crtc;
@@ -708,9 +708,9 @@ static int tegra_dc_drm_init(struct host1x_client *client,
 	return 0;
 }
 
-static int tegra_dc_drm_exit(struct host1x_client *client)
+static int tegra_dc_drm_exit(struct tegra_drm_client *client)
 {
-	struct tegra_dc *dc = host1x_client_to_dc(client);
+	struct tegra_dc *dc = tegra_drm_client_to_dc(client);
 	int err;
 
 	devm_free_irq(dc->dev, dc->irq, dc);
@@ -730,17 +730,17 @@ static int tegra_dc_drm_exit(struct host1x_client *client)
 	return 0;
 }
 
-static const struct host1x_client_ops dc_client_ops = {
+static const struct tegra_drm_client_ops dc_client_ops = {
 	.drm_init = tegra_dc_drm_init,
 	.drm_exit = tegra_dc_drm_exit,
 };
 
 static int tegra_dc_probe(struct platform_device *pdev)
 {
-	struct host1x *host1x = dev_get_drvdata(pdev->dev.parent);
 	struct resource *regs;
 	struct tegra_dc *dc;
 	int err;
+	struct tegradrm *tegradrm = platform_get_drvdata(pdev);
 
 	dc = devm_kzalloc(&pdev->dev, sizeof(*dc), GFP_KERNEL);
 	if (!dc)
@@ -780,6 +780,7 @@ static int tegra_dc_probe(struct platform_device *pdev)
 	INIT_LIST_HEAD(&dc->client.list);
 	dc->client.ops = &dc_client_ops;
 	dc->client.dev = &pdev->dev;
+	dc->client.tegradrm = tegradrm;
 
 	err = tegra_dc_rgb_probe(dc);
 	if (err < 0 && err != -ENODEV) {
@@ -787,9 +788,9 @@ static int tegra_dc_probe(struct platform_device *pdev)
 		return err;
 	}
 
-	err = host1x_register_client(host1x, &dc->client);
+	err = tegra_drm_register_client(tegradrm, &dc->client);
 	if (err < 0) {
-		dev_err(&pdev->dev, "failed to register host1x client: %d\n",
+		dev_err(&pdev->dev, "failed to register tegra drm client: %d\n",
 			err);
 		return err;
 	}
@@ -801,13 +802,13 @@ 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 tegra_dc *dc = platform_get_drvdata(pdev);
 	int err;
 
-	err = host1x_unregister_client(host1x, &dc->client);
+	err = tegra_drm_unregister_client(dc->client.tegradrm,
+			&dc->client);
 	if (err < 0) {
-		dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
+		dev_err(&pdev->dev, "failed to unregister tegra_drm client: %d\n",
 			err);
 		return err;
 	}
drivers/gpu/drm/tegra/drm.c +221 -10

270 lines not on this page · raw message

drivers/gpu/drm/tegra/drm.h +18 -25

92 lines not on this page · raw message

drivers/gpu/drm/tegra/fb.c +11 -6
index 97993c6..7c686d8 100644
@@ -11,9 +11,9 @@
 
 static void tegra_drm_fb_output_poll_changed(struct drm_device *drm)
 {
-	struct host1x *host1x = drm->dev_private;
+	struct tegradrm *tegradrm = drm->dev_private;
 
-	drm_fbdev_cma_hotplug_event(host1x->fbdev);
+	drm_fbdev_cma_hotplug_event(tegradrm->fbdev);
 }
 
 static const struct drm_mode_config_funcs tegra_drm_mode_funcs = {
@@ -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 tegradrm *tegradrm = drm->dev_private;
 	struct drm_fbdev_cma *fbdev;
 
 	drm->mode_config.min_width = 0;
@@ -43,14 +43,19 @@ int tegra_drm_fb_init(struct drm_device *drm)
 	drm_fbdev_cma_restore_mode(fbdev);
 #endif
 
-	host1x->fbdev = fbdev;
+	tegradrm->fbdev = fbdev;
 
 	return 0;
 }
 
 void tegra_drm_fb_exit(struct drm_device *drm)
 {
-	struct host1x *host1x = drm->dev_private;
+	struct tegradrm *tegradrm = drm->dev_private;
+	drm_fbdev_cma_fini(tegradrm->fbdev);
+}
 
-	drm_fbdev_cma_fini(host1x->fbdev);
+void tegra_drm_fb_restore(struct drm_device *drm)
+{
+	struct tegradrm *tegradrm = drm->dev_private;
+	drm_fbdev_cma_restore_mode(tegradrm->fbdev);
 }
drivers/gpu/drm/tegra/hdmi.c +14 -13
index ab40164..fce3e66 100644
@@ -22,7 +22,7 @@
 #include "dc.h"
 
 struct tegra_hdmi {
-	struct host1x_client client;
+	struct tegra_drm_client client;
 	struct tegra_output output;
 	struct device *dev;
 
@@ -46,7 +46,7 @@ struct tegra_hdmi {
 };
 
 static inline struct tegra_hdmi *
-host1x_client_to_hdmi(struct host1x_client *client)
+tegra_drm_client_to_hdmi(struct tegra_drm_client *client)
 {
 	return container_of(client, struct tegra_hdmi, client);
 }
@@ -1152,10 +1152,10 @@ static int tegra_hdmi_debugfs_exit(struct tegra_hdmi *hdmi)
 	return 0;
 }
 
-static int tegra_hdmi_drm_init(struct host1x_client *client,
+static int tegra_hdmi_drm_init(struct tegra_drm_client *client,
 			       struct drm_device *drm)
 {
-	struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
+	struct tegra_hdmi *hdmi = tegra_drm_client_to_hdmi(client);
 	int err;
 
 	hdmi->output.type = TEGRA_OUTPUT_HDMI;
@@ -1177,9 +1177,9 @@ static int tegra_hdmi_drm_init(struct host1x_client *client,
 	return 0;
 }
 
-static int tegra_hdmi_drm_exit(struct host1x_client *client)
+static int tegra_hdmi_drm_exit(struct tegra_drm_client *client)
 {
-	struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
+	struct tegra_hdmi *hdmi = tegra_drm_client_to_hdmi(client);
 	int err;
 
 	if (IS_ENABLED(CONFIG_DEBUG_FS)) {
@@ -1204,17 +1204,17 @@ static int tegra_hdmi_drm_exit(struct host1x_client *client)
 	return 0;
 }
 
-static const struct host1x_client_ops hdmi_client_ops = {
+static const struct tegra_drm_client_ops hdmi_client_ops = {
 	.drm_init = tegra_hdmi_drm_init,
 	.drm_exit = tegra_hdmi_drm_exit,
 };
 
 static int tegra_hdmi_probe(struct platform_device *pdev)
 {
-	struct host1x *host1x = dev_get_drvdata(pdev->dev.parent);
 	struct tegra_hdmi *hdmi;
 	struct resource *regs;
 	int err;
+	struct tegradrm *tegradrm = platform_get_drvdata(pdev);
 
 	hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
 	if (!hdmi)
@@ -1285,10 +1285,11 @@ static int tegra_hdmi_probe(struct platform_device *pdev)
 	hdmi->client.ops = &hdmi_client_ops;
 	INIT_LIST_HEAD(&hdmi->client.list);
 	hdmi->client.dev = &pdev->dev;
+	hdmi->client.tegradrm = tegradrm;
 
-	err = host1x_register_client(host1x, &hdmi->client);
+	err = tegra_drm_register_client(tegradrm, &hdmi->client);
 	if (err < 0) {
-		dev_err(&pdev->dev, "failed to register host1x client: %d\n",
+		dev_err(&pdev->dev, "failed to register tegra drm client: %d\n",
 			err);
 		return err;
 	}
@@ -1300,13 +1301,13 @@ 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 tegra_hdmi *hdmi = platform_get_drvdata(pdev);
 	int err;
 
-	err = host1x_unregister_client(host1x, &hdmi->client);
+	err = tegra_drm_unregister_client(hdmi->client.tegradrm,
+			&hdmi->client);
 	if (err < 0) {
-		dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
+		dev_err(&pdev->dev, "failed to unregister tegra drm client: %d\n",
 			err);
 		return err;
 	}
drivers/gpu/drm/tegra/host1x.c deleted +0 -325

325 lines not on this page · raw message

include/drm/tegra_drm.h new file +20 -0
new file mode 100644
index 0000000..8632f49
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
+ *
+ * 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 _TEGRA_DRM_H_
+#define _TEGRA_DRM_H_
+
+#endif
Signature · 1 line
1.7.9.5
#20 lore raw

PATCH v4 8/8 gpu: host1x: Register DRM dummy device

In reply to Terje Bergstrom

Register a dummy device for tegradrm, and provide a getter to access the device.

---
 drivers/gpu/drm/tegra/dc.c   |    5 ++++-
 drivers/gpu/drm/tegra/drm.c  |   11 +--------
 drivers/gpu/drm/tegra/gr2d.c |    4 +++-
 drivers/gpu/drm/tegra/hdmi.c |    5 ++++-
 drivers/gpu/host1x/Makefile  |    3 ++-
 drivers/gpu/host1x/dev.c     |    9 ++++++++
 drivers/gpu/host1x/dev.h     |    2 ++
 drivers/gpu/host1x/drm.c     |   51 ++++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/host1x/drm.h     |   25 +++++++++++++++++++++
 include/linux/host1x.h       |    2 ++
 10 files changed, 103 insertions(+), 14 deletions(-)
 create mode 100644 drivers/gpu/host1x/drm.c
 create mode 100644 drivers/gpu/host1x/drm.h
drivers/gpu/drm/tegra/dc.c +4 -1
index 24bcd06..d01be50 100644
@@ -12,6 +12,7 @@
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
+#include <linux/host1x.h>
 
 #include <mach/clk.h>
 
@@ -740,7 +741,9 @@ static int tegra_dc_probe(struct platform_device *pdev)
 	struct resource *regs;
 	struct tegra_dc *dc;
 	int err;
-	struct tegradrm *tegradrm = platform_get_drvdata(pdev);
+	struct platform_device *drm_device =
+		host1x_drm_device(to_platform_device(pdev->dev.parent));
+	struct tegradrm *tegradrm = platform_get_drvdata(drm_device);
 
 	dc = devm_kzalloc(&pdev->dev, sizeof(*dc), GFP_KERNEL);
 	if (!dc)
drivers/gpu/drm/tegra/drm.c +1 -10
index 637b621..d64935d 100644
@@ -56,7 +56,6 @@ static int tegra_drm_add_client(struct device *dev, void *data)
 			client->np = of_node_get(dev->of_node);
 
 			list_add_tail(&client->list, &tegradrm->drm_clients);
-			dev_set_drvdata(dev, tegradrm);
 		}
 	}
 
@@ -258,16 +257,10 @@ static struct platform_driver tegra_drm_platform_driver = {
 static int __init tegra_drm_init(void)
 {
 	int err;
-	struct platform_device *drm_device;
-
-	drm_device = platform_device_register_simple("tegradrm", -1, NULL, 0);
-	if (!drm_device)
-		return -ENOMEM;
-	dma_set_coherent_mask(&drm_device->dev, DMA_BIT_MASK(32));
 
 	err = platform_driver_register(&tegra_drm_platform_driver);
 	if (err < 0)
-		goto unregister_tegra_dev;
+		return err;
 
 	err = platform_driver_register(&tegra_dc_driver);
 	if (err < 0)
@@ -288,8 +281,6 @@ unregister_dc:
 	platform_driver_unregister(&tegra_dc_driver);
 unregister_tegra_drv:
 	platform_driver_unregister(&tegra_drm_platform_driver);
-unregister_tegra_dev:
-	platform_device_unregister(drm_device);
 	return err;
 }
 module_init(tegra_drm_init);
drivers/gpu/drm/tegra/gr2d.c +3 -1
index 8865099..a936902 100644
@@ -247,7 +247,9 @@ static int __devinit gr2d_probe(struct platform_device *dev)
 {
 	int err;
 	struct gr2d *gr2d = NULL;
-	struct tegradrm *tegradrm = platform_get_drvdata(dev);
+	struct platform_device *drm_device =
+		host1x_drm_device(to_platform_device(dev->dev.parent));
+	struct tegradrm *tegradrm = platform_get_drvdata(drm_device);
 
 	gr2d = devm_kzalloc(&dev->dev, sizeof(*gr2d), GFP_KERNEL);
 	if (!gr2d)
drivers/gpu/drm/tegra/hdmi.c +4 -1
index fce3e66..a90a76f 100644
@@ -14,6 +14,7 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/regulator/consumer.h>
+#include <linux/host1x.h>
 
 #include <mach/clk.h>
 
@@ -1214,7 +1215,9 @@ static int tegra_hdmi_probe(struct platform_device *pdev)
 	struct tegra_hdmi *hdmi;
 	struct resource *regs;
 	int err;
-	struct tegradrm *tegradrm = platform_get_drvdata(pdev);
+	struct platform_device *drm_device =
+		host1x_drm_device(to_platform_device(pdev->dev.parent));
+	struct tegradrm *tegradrm = platform_get_drvdata(drm_device);
 
 	hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
 	if (!hdmi)
drivers/gpu/host1x/Makefile +2 -1
index 049c07a..f8749fb 100644
@@ -10,7 +10,8 @@ host1x-y = \
 	job.o \
 	debug.o \
 	memmgr.o \
-	hw/host1x01.o
+	hw/host1x01.o \
+	drm.o
 
 host1x-$(CONFIG_TEGRA_HOST1X_CMA) += cma.o
 obj-$(CONFIG_TEGRA_HOST1X) += host1x.o
drivers/gpu/host1x/dev.c +9 -0
index 8d710ef..07e8813 100644
@@ -25,6 +25,7 @@
 #include <linux/clk.h>
 #include <linux/io.h>
 #include "dev.h"
+#include "drm.h"
 #include "intr.h"
 #include "channel.h"
 #include "debug.h"
@@ -145,6 +146,12 @@ static int host1x_probe(struct platform_device *dev)
 
 	/* set common host1x device data */
 	platform_set_drvdata(dev, host);
+
+	/* Alloc DRM device */
+	err = host1x_register_drm_device(host);
+	if (err)
+		goto fail;
+
 	host->regs = devm_request_and_ioremap(&dev->dev, regs);
 	if (!host->regs) {
 		dev_err(&dev->dev, "failed to remap host registers\n");
@@ -203,6 +210,7 @@ static int host1x_probe(struct platform_device *dev)
 
 fail:
 	host1x_syncpt_free(host->nop_sp);
+	host1x_unregister_drm_device(host);
 	kfree(host);
 	return err;
 }
@@ -212,6 +220,7 @@ static int __exit host1x_remove(struct platform_device *dev)
 	struct host1x *host = platform_get_drvdata(dev);
 	host1x_intr_deinit(&host->intr);
 	host1x_syncpt_deinit(host);
+	host1x_unregister_drm_device(host);
 	clk_disable_unprepare(host->clk);
 	return 0;
 }
drivers/gpu/host1x/dev.h +2 -0
index aa5182e..05f8544 100644
@@ -143,6 +143,8 @@ struct host1x {
 	int allocated_channels;
 
 	struct dentry *debugfs;
+
+	struct platform_device *drm_device;
 };
 
 static inline
drivers/gpu/host1x/drm.c new file +51 -0

51 lines not on this page · raw message

drivers/gpu/host1x/drm.h new file +25 -0
new file mode 100644
index 0000000..84a827e
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2012, 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_DRM_H
+#define HOST1X_DRM_H
+
+struct host1x;
+
+int host1x_register_drm_device(struct host1x *host1x);
+void host1x_unregister_drm_device(struct host1x *host1x);
+
+#endif
include/linux/host1x.h +2 -0
index a58c798..0906c19f 100644
@@ -212,4 +212,6 @@ struct host1x_syncpt *host1x_syncpt_alloc(struct platform_device *pdev,
 		int client_managed);
 void host1x_syncpt_free(struct host1x_syncpt *sp);
 
+struct platform_device *host1x_drm_device(struct platform_device *pdev);
+
 #endif
Signature · 1 line
1.7.9.5
#10 lore raw

PATCH v4 4/8 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                   |   37 +++
 drivers/gpu/host1x/debug.c                  |  207 ++++++++++++++
 drivers/gpu/host1x/debug.h                  |   49 ++++
 drivers/gpu/host1x/dev.c                    |    3 +
 drivers/gpu/host1x/dev.h                    |   17 ++
 drivers/gpu/host1x/hw/cdma_hw.c             |    3 +
 drivers/gpu/host1x/hw/debug_hw.c            |  399 +++++++++++++++++++++++++++
 drivers/gpu/host1x/hw/host1x01.c            |    2 +
 drivers/gpu/host1x/hw/hw_host1x01_channel.h |   12 +
 drivers/gpu/host1x/hw/hw_host1x01_sync.h    |   77 ++++++
 drivers/gpu/host1x/hw/syncpt_hw.c           |    1 +
 drivers/gpu/host1x/syncpt.c                 |    3 +
 13 files changed, 811 insertions(+)
 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 59ecd82..049c07a 100644
@@ -8,6 +8,7 @@ host1x-y = \
 	intr.o \
 	channel.o \
 	job.o \
+	debug.o \
 	memmgr.o \
 	hw/host1x01.o
 
drivers/gpu/host1x/cdma.c +37 -0
index 1193fea..b924f23 100644
@@ -19,6 +19,7 @@
 #include "cdma.h"
 #include "channel.h"
 #include "dev.h"
+#include "debug.h"
 #include "memmgr.h"
 #include <asm/cacheflush.h>
 
@@ -369,12 +370,45 @@ int host1x_cdma_begin(struct host1x_cdma *cdma, struct host1x_job *job)
 	return 0;
 }
 
+static void trace_write_gather(struct host1x_cdma *cdma,
+		struct mem_handle *ref,
+		u32 offset, u32 words)
+{
+	void *mem = NULL;
+
+	if (host1x_debug_trace_cmdbuf) {
+		mem = host1x_memmgr_mmap(ref);
+		if (IS_ERR_OR_NULL(mem))
+			mem = NULL;
+	};
+
+	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(
+				cdma_to_channel(cdma)->dev->name,
+				(u32)ref,
+				min(words - i, TRACE_MAX_LENGTH),
+				offset + i * sizeof(u32),
+				mem);
+		}
+		host1x_memmgr_munmap(ref, mem);
+	}
+}
+
 /*
  * Push two words into a push buffer slot
  * Blocks as necessary if the push buffer is full.
  */
 void host1x_cdma_push(struct host1x_cdma *cdma, u32 op1, u32 op2)
 {
+	if (host1x_debug_trace_cmdbuf)
+		trace_host1x_cdma_push(cdma_to_channel(cdma)->dev->name,
+				op1, op2);
 	host1x_cdma_push_gather(cdma, NULL, 0, op1, op2);
 }
 
@@ -390,6 +424,9 @@ void host1x_cdma_push_gather(struct host1x_cdma *cdma,
 	u32 slots_free = cdma->slots_free;
 	struct push_buffer *pb = &cdma->push_buffer;
 
+	if (handle)
+		trace_write_gather(cdma, handle, offset, op1 & 0xffff);
+
 	if (slots_free == 0) {
 		host1x->cdma_op.kick(cdma);
 		slots_free = host1x_cdma_wait_locked(cdma,
drivers/gpu/host1x/debug.c new file +207 -0

207 lines not on this page · raw message

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

49 lines not on this page · raw message

drivers/gpu/host1x/dev.c +3 -0
index 6b4f623..8d710ef 100644
@@ -27,6 +27,7 @@
 #include "dev.h"
 #include "intr.h"
 #include "channel.h"
+#include "debug.h"
 #include "hw/host1x01.h"
 
 #define CREATE_TRACE_POINTS
@@ -192,6 +193,8 @@ static int host1x_probe(struct platform_device *dev)
 
 	host1x_intr_start(&host->intr, clk_get_rate(host->clk));
 
+	host1x_debug_init(host);
+
 	host1x = host;
 
 	dev_info(&dev->dev, "initialized\n");
drivers/gpu/host1x/dev.h +17 -0
index 093ac85..aa5182e 100644
@@ -33,6 +33,7 @@ struct push_buffer;
 struct dentry;
 struct mem_handle;
 struct platform_device;
+struct output;
 
 struct host1x_channel_ops {
 	const char *soc_name;
@@ -72,6 +73,21 @@ struct host1x_pushbuffer_ops {
 	u32 (*putptr)(struct push_buffer *);
 };
 
+struct host1x_debug_ops {
+	void (*debug_init)(struct dentry *de);
+	void (*show_channel_cdma)(struct host1x *,
+				  struct host1x_channel *,
+				  struct output *,
+				  int chid);
+	void (*show_channel_fifo)(struct host1x *,
+				  struct host1x_channel *,
+				  struct output *,
+				  int chid);
+	void (*show_mlocks)(struct host1x *m,
+			    struct output *o);
+
+};
+
 struct host1x_syncpt_ops {
 	void (*reset)(struct host1x_syncpt *);
 	void (*reset_wait_base)(struct host1x_syncpt *);
@@ -119,6 +135,7 @@ struct host1x {
 	struct host1x_channel_ops channel_op;
 	struct host1x_cdma_ops cdma_op;
 	struct host1x_pushbuffer_ops cdma_pb_op;
+	struct host1x_debug_ops debug_op;
 	struct host1x_syncpt_ops syncpt_op;
 	struct host1x_intr_ops intr_op;
 
drivers/gpu/host1x/hw/cdma_hw.c +3 -0
index c8fea1e..d4ad43e 100644
@@ -22,6 +22,7 @@
 #include "cdma.h"
 #include "channel.h"
 #include "dev.h"
+#include "debug.h"
 #include "memmgr.h"
 
 #include "cdma_hw.h"
@@ -409,6 +410,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.clientid) {
drivers/gpu/host1x/hw/debug_hw.c new file +399 -0

399 lines not on this page · raw message

drivers/gpu/host1x/hw/host1x01.c +2 -0
index 3f41619..7a26e96 100644
@@ -29,6 +29,7 @@
 
 #include "hw/channel_hw.c"
 #include "hw/cdma_hw.c"
+#include "hw/debug_hw.c"
 #include "hw/syncpt_hw.c"
 #include "hw/intr_hw.c"
 
@@ -37,6 +38,7 @@ 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->debug_op = host1x_debug_ops;
 	host->syncpt_op = host1x_syncpt_ops;
 	host->intr_op = host1x_intr_ops;
 
drivers/gpu/host1x/hw/hw_host1x01_channel.h +12 -0
index 3a23d57..29f0ddc0 100644
@@ -51,6 +51,14 @@
 #ifndef __hw_host1x_channel_host1x_h__
 #define __hw_host1x_channel_host1x_h__
 
+static inline u32 host1x_channel_fifostat_r(void)
+{
+	return 0x0;
+}
+static inline u32 host1x_channel_fifostat_cfempty_v(u32 r)
+{
+	return (r >> 10) & 0x1;
+}
 static inline u32 host1x_channel_dmastart_r(void)
 {
 	return 0x14;
@@ -75,6 +83,10 @@ static inline u32 host1x_channel_dmactrl_dmastop_f(u32 v)
 {
 	return (v & 0x1) << 0;
 }
+static inline u32 host1x_channel_dmactrl_dmastop_v(u32 r)
+{
+	return (r >> 0) & 0x1;
+}
 static inline u32 host1x_channel_dmactrl_dmagetrst_f(u32 v)
 {
 	return (v & 0x1) << 1;
drivers/gpu/host1x/hw/hw_host1x01_sync.h +77 -0

93 lines not on this page · raw message

drivers/gpu/host1x/hw/syncpt_hw.c +1 -0
index a070473..09a21d2 100644
@@ -90,6 +90,7 @@ static void syncpt_cpu_incr(struct host1x_syncpt *sp)
 		dev_err(&dev->dev->dev,
 			"Trying to increment syncpoint id %d beyond max\n",
 			sp->id);
+		host1x_debug_dump(sp->dev);
 		return;
 	}
 	host1x_sync_writel(dev, BIT_MASK(sp->id),
drivers/gpu/host1x/syncpt.c +3 -0
index c1d78f6..07cbca5 100644
@@ -23,6 +23,7 @@
 #include "syncpt.h"
 #include "dev.h"
 #include "intr.h"
+#include "debug.h"
 #include <trace/events/host1x.h>
 
 #define MAX_SYNCPT_LENGTH	5
@@ -219,6 +220,8 @@ int host1x_syncpt_wait(struct host1x_syncpt *sp,
 				 current->comm, sp->id, sp->name,
 				 thresh, timeout);
 			sp->dev->syncpt_op.debug(sp);
+			if (check_count == MAX_STUCK_CHECK_COUNT)
+				host1x_debug_dump(sp->dev);
 			check_count++;
 		}
 	}
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v4 3/8 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. The work is submitted in GEM CMA buffers, so this patch adds support for them.

---
 drivers/gpu/host1x/Kconfig                  |   24 +-
 drivers/gpu/host1x/Makefile                 |    5 +
 drivers/gpu/host1x/cdma.c                   |  438 +++++++++++++++++++
 drivers/gpu/host1x/cdma.h                   |  107 +++++
 drivers/gpu/host1x/channel.c                |  137 ++++++
 drivers/gpu/host1x/channel.h                |   64 +++
 drivers/gpu/host1x/cma.c                    |  117 +++++
 drivers/gpu/host1x/cma.h                    |   43 ++
 drivers/gpu/host1x/dev.c                    |   13 +
 drivers/gpu/host1x/dev.h                    |   54 +++
 drivers/gpu/host1x/hw/cdma_hw.c             |  477 +++++++++++++++++++++
 drivers/gpu/host1x/hw/cdma_hw.h             |   37 ++
 drivers/gpu/host1x/hw/channel_hw.c          |  147 +++++++
 drivers/gpu/host1x/hw/host1x01.c            |    6 +
 drivers/gpu/host1x/hw/host1x01_hardware.h   |  124 ++++++
 drivers/gpu/host1x/hw/hw_host1x01_channel.h |   86 ++++
 drivers/gpu/host1x/hw/hw_host1x01_sync.h    |    8 +
 drivers/gpu/host1x/hw/hw_host1x01_uclass.h  |  130 ++++++
 drivers/gpu/host1x/hw/syncpt_hw.c           |   10 +
 drivers/gpu/host1x/intr.c                   |   29 +-
 drivers/gpu/host1x/intr.h                   |    6 +
 drivers/gpu/host1x/job.c                    |  618 +++++++++++++++++++++++++++
 drivers/gpu/host1x/memmgr.c                 |  174 ++++++++
 drivers/gpu/host1x/memmgr.h                 |   53 +++
 drivers/gpu/host1x/syncpt.c                 |    6 +
 drivers/gpu/host1x/syncpt.h                 |    2 +
 include/linux/host1x.h                      |  173 ++++++++
 include/trace/events/host1x.h               |  235 ++++++++++
 28 files changed, 3321 insertions(+), 2 deletions(-)
 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/cma.c
 create mode 100644 drivers/gpu/host1x/cma.h
 create mode 100644 drivers/gpu/host1x/hw/cdma_hw.c
 create mode 100644 drivers/gpu/host1x/hw/cdma_hw.h
 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/memmgr.c
 create mode 100644 drivers/gpu/host1x/memmgr.h
drivers/gpu/host1x/Kconfig +23 -1
index e89fb2b..61e7ba3 100644
@@ -3,4 +3,26 @@ config TEGRA_HOST1X
 	help
 	  Driver for the Tegra host1x hardware.
 
-	  Required for enabling tegradrm.
+	  Required for enabling tegradrm and 2D acceleration.
+
+if TEGRA_HOST1X
+
+config TEGRA_HOST1X_CMA
+	bool "Support DRM CMA buffers"
+	depends on DRM
+	select DRM_GEM_CMA_HELPER
+	select DRM_KMS_CMA_HELPER
+	help
+	  Say yes if you wish to use DRM CMA buffers.
+
+	  If unsure, choose Y.
+
+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 +5 -0
index d3eb3b4..59ecd82 100644
@@ -4,6 +4,11 @@ host1x-y = \
 	syncpt.o \
 	dev.o \
 	intr.o \
+	cdma.o \
+	intr.o \
+	channel.o \
+	job.o \
+	memmgr.o \
 	hw/host1x01.o
 
 host1x-$(CONFIG_TEGRA_HOST1X_CMA) += cma.o
drivers/gpu/host1x/cdma.c new file +438 -0

438 lines not on this page · raw message

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

107 lines not on this page · raw message

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

137 lines not on this page · raw message

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

64 lines not on this page · raw message

drivers/gpu/host1x/cma.c new file +117 -0

117 lines not on this page · raw message

drivers/gpu/host1x/cma.h new file +43 -0

43 lines not on this page · raw message

drivers/gpu/host1x/dev.c +13 -0
index f441b6c..6b4f623 100644
@@ -26,6 +26,7 @@
 #include <linux/io.h>
 #include "dev.h"
 #include "intr.h"
+#include "channel.h"
 #include "hw/host1x01.h"
 
 #define CREATE_TRACE_POINTS
@@ -70,6 +71,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 int host1x_alloc_resources(struct host1x *host)
 {
 	host->intr.syncpt = devm_kzalloc(&host->dev->dev,
@@ -177,6 +188,8 @@ static int host1x_probe(struct platform_device *dev)
 
 	host1x_syncpt_reset(host);
 
+	host1x_channel_list_init(host);
+
 	host1x_intr_start(&host->intr, clk_get_rate(host->clk));
 
 	host1x = host;
drivers/gpu/host1x/dev.h +54 -0

81 lines not on this page · raw message

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

477 lines not on this page · raw message

drivers/gpu/host1x/hw/cdma_hw.h new file +37 -0
new file mode 100644
index 0000000..4ce2f43
@@ -0,0 +1,37 @@
+/*
+ * Tegra host1x Command DMA
+ *
+ * Copyright (c) 2011-2012, 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_CDMA_H
+#define __HOST1X_CDMA_H
+
+/*
+ * Size of the sync queue. If it is too small, we won't be able to queue up
+ * many command buffers. If it is too large, we waste memory.
+ */
+#define HOST1X_SYNC_QUEUE_SIZE 512
+
+/*
+ * Number of gathers we allow to be queued up per channel. Must be a
+ * power of two. Currently sized such that pushbuffer is 4KB (512*8B).
+ */
+#define HOST1X_GATHER_QUEUE_SIZE 512
+
+/* 8 bytes per slot. (This number does not include the final RESTART.) */
+#define PUSH_BUFFER_SIZE (HOST1X_GATHER_QUEUE_SIZE * 8)
+
+#endif
drivers/gpu/host1x/hw/channel_hw.c new file +147 -0

147 lines not on this page · raw message

drivers/gpu/host1x/hw/host1x01.c +6 -0
index c5c55a3..3f41619 100644
@@ -24,13 +24,19 @@
 
 #include "hw/host1x01.h"
 #include "dev.h"
+#include "channel.h"
 #include "hw/host1x01_hardware.h"
 
+#include "hw/channel_hw.c"
+#include "hw/cdma_hw.c"
 #include "hw/syncpt_hw.c"
 #include "hw/intr_hw.c"
 
 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 +124 -0

130 lines not on this page · raw message

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

86 lines not on this page · raw message

drivers/gpu/host1x/hw/hw_host1x01_sync.h +8 -0
index b06a2c5..c9342da 100644
@@ -63,6 +63,14 @@ static inline u32 host1x_sync_syncpt_thresh_int_enable_cpu0_r(void)
 {
 	return 0x68;
 }
+static inline u32 host1x_sync_cmdproc_stop_r(void)
+{
+	return 0xac;
+}
+static inline u32 host1x_sync_ch_teardown_r(void)
+{
+	return 0xb0;
+}
 static inline u32 host1x_sync_usec_clk_r(void)
 {
 	return 0x1a4;
drivers/gpu/host1x/hw/hw_host1x01_uclass.h new file +130 -0

130 lines not on this page · raw message

drivers/gpu/host1x/hw/syncpt_hw.c +10 -0
index 44a10b0..a070473 100644
@@ -97,6 +97,15 @@ 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(
+			NVSYNCPT_GRAPHICS_HOST, 0);
+	__raw_writel(override, patch_addr);
+	return 0;
+}
+
 static const char *syncpt_name(struct host1x_syncpt *sp)
 {
 	struct host1x_device_info *info = &sp->dev->info;
@@ -141,6 +150,7 @@ static const struct host1x_syncpt_ops host1x_syncpt_ops = {
 	.read_wait_base = syncpt_read_wait_base,
 	.load_min = syncpt_load_min,
 	.cpu_incr = syncpt_cpu_incr,
+	.patch_wait = syncpt_patch_wait,
 	.debug = syncpt_debug,
 	.name = syncpt_name,
 };
drivers/gpu/host1x/intr.c +28 -1
index bc51e4d..efcb9be 100644
@@ -20,6 +20,8 @@
 #include <linux/interrupt.h>
 #include <linux/slab.h>
 #include <linux/irq.h>
+#include <trace/events/host1x.h>
+#include "channel.h"
 #include "dev.h"
 
 /* Wait list management */
@@ -74,7 +76,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)
@@ -82,6 +84,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);
@@ -104,6 +117,19 @@ static void reset_threshold_interrupt(struct host1x_intr *intr,
 	host1x->intr_op.enable_syncpt_intr(intr, id);
 }
 
+static void action_submit_complete(struct host1x_waitlist *waiter)
+{
+	struct host1x_channel *channel = waiter->data;
+	int nr_completed = waiter->count;
+
+	host1x_cdma_update(&channel->cdma);
+
+	/*  Add nr_completed to trace */
+	trace_host1x_channel_submit_complete(channel->dev->name,
+			nr_completed, waiter->thresh);
+
+}
+
 static void action_wakeup(struct host1x_waitlist *waiter)
 {
 	wait_queue_head_t *wq = waiter->data;
@@ -121,6 +147,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 3625bf3..fa4b2c4 100644
@@ -28,6 +28,12 @@ struct host1x_channel;
 
 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 +618 -0

618 lines not on this page · raw message

drivers/gpu/host1x/memmgr.c new file +174 -0

174 lines not on this page · raw message

drivers/gpu/host1x/memmgr.h new file +53 -0

19 lines not on this page · raw message

drivers/gpu/host1x/syncpt.c +6 -0
index adf439f..c1d78f6 100644

Lines of this file are not shown. View the raw message.

drivers/gpu/host1x/syncpt.h +2 -0
index d4d1f3f..24d4846 100644

Lines of this file are not shown. View the raw message.

include/linux/host1x.h +173 -0

173 lines not on this page · raw message

include/trace/events/host1x.h +235 -0

235 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.

#2 lore raw

PATCH v4 2/8 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              |    2 +
 drivers/gpu/host1x/dev.c                 |   37 +++-
 drivers/gpu/host1x/dev.h                 |   15 ++
 drivers/gpu/host1x/hw/host1x01.c         |    2 +
 drivers/gpu/host1x/hw/hw_host1x01_sync.h |   30 ++-
 drivers/gpu/host1x/hw/intr_hw.c          |  178 +++++++++++++++
 drivers/gpu/host1x/intr.c                |  350 ++++++++++++++++++++++++++++++
 drivers/gpu/host1x/intr.h                |  100 +++++++++
 drivers/gpu/host1x/syncpt.c              |  164 +++++++++++++-
 drivers/gpu/host1x/syncpt.h              |    4 +
 include/linux/host1x.h                   |    1 +
 11 files changed, 880 insertions(+), 3 deletions(-)
 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 +2 -0
index 363e6ab..d3eb3b4 100644
@@ -3,6 +3,8 @@ ccflags-y = -Idrivers/gpu/host1x
 host1x-y = \
 	syncpt.o \
 	dev.o \
+	intr.o \
 	hw/host1x01.o
 
+host1x-$(CONFIG_TEGRA_HOST1X_CMA) += cma.o
 obj-$(CONFIG_TEGRA_HOST1X) += host1x.o
drivers/gpu/host1x/dev.c +36 -1
index b0d630d..f441b6c 100644
@@ -25,6 +25,7 @@
 #include <linux/clk.h>
 #include <linux/io.h>
 #include "dev.h"
+#include "intr.h"
 #include "hw/host1x01.h"
 
 #define CREATE_TRACE_POINTS
@@ -48,6 +49,13 @@ u32 host1x_syncpt_read_byid(u32 id)
 }
 EXPORT_SYMBOL(host1x_syncpt_read_byid);
 
+int host1x_syncpt_wait_byid(u32 id, u32 thresh, long timeout, u32 *value)
+{
+	struct host1x_syncpt *sp = host1x->syncpt + id;
+	return host1x_syncpt_wait(sp, thresh, timeout, value);
+}
+EXPORT_SYMBOL(host1x_syncpt_wait_byid);
+
 void host1x_sync_writel(struct host1x *host1x, u32 v, u32 r)
 {
 	void __iomem *sync_regs = host1x->regs + host1x->info.sync_offset;
@@ -62,6 +70,21 @@ u32 host1x_sync_readl(struct host1x *host1x, u32 r)
 	return readl(sync_regs + r);
 }
 
+static int host1x_alloc_resources(struct host1x *host)
+{
+	host->intr.syncpt = devm_kzalloc(&host->dev->dev,
+			sizeof(struct host1x_intr_syncpt) *
+			host->info.nb_pts,
+			GFP_KERNEL);
+
+	if (!host->intr.syncpt) {
+		/* frees happen in the support removal phase */
+		return -ENOMEM;
+	}
+
+	return 0;
+}
+
 static struct host1x_device_info host1x_info = {
 	.nb_channels	= 8,
 	.nb_pts		= 32,
@@ -110,7 +133,6 @@ static int host1x_probe(struct platform_device *dev)
 
 	/* set common host1x device data */
 	platform_set_drvdata(dev, host);
-
 	host->regs = devm_request_and_ioremap(&dev->dev, regs);
 	if (!host->regs) {
 		dev_err(&dev->dev, "failed to remap host registers\n");
@@ -118,6 +140,12 @@ static int host1x_probe(struct platform_device *dev)
 		goto fail;
 	}
 
+	err = host1x_alloc_resources(host);
+	if (err) {
+		dev_err(&dev->dev, "failed to init chip support\n");
+		goto fail;
+	}
+
 	if (host->info.init) {
 		err = host->info.init(host);
 		if (err)
@@ -132,6 +160,10 @@ static int host1x_probe(struct platform_device *dev)
 	if (!host->nop_sp)
 		goto fail;
 
+	err = host1x_intr_init(&host->intr, syncpt_irq);
+	if (err)
+		goto fail;
+
 	host->clk = devm_clk_get(&dev->dev, NULL);
 	if (IS_ERR(host->clk)) {
 		dev_err(&dev->dev, "failed to get clock\n");
@@ -145,6 +177,8 @@ static int host1x_probe(struct platform_device *dev)
 
 	host1x_syncpt_reset(host);
 
+	host1x_intr_start(&host->intr, clk_get_rate(host->clk));
+
 	host1x = host;
 
 	dev_info(&dev->dev, "initialized\n");
@@ -160,6 +194,7 @@ fail:
 static int __exit host1x_remove(struct platform_device *dev)
 {
 	struct host1x *host = platform_get_drvdata(dev);
+	host1x_intr_deinit(&host->intr);
 	host1x_syncpt_deinit(host);
 	clk_disable_unprepare(host->clk);
 	return 0;
drivers/gpu/host1x/dev.h +15 -0
index 8245e24..a1622bb 100644
@@ -20,6 +20,7 @@
 #include <linux/host1x.h>
 
 #include "syncpt.h"
+#include "intr.h"
 
 struct host1x;
 struct host1x_syncpt;
@@ -36,6 +37,18 @@ struct host1x_syncpt_ops {
 	const char * (*name)(struct host1x_syncpt *);
 };
 
+struct host1x_intr_ops {
+	void (*init_host_sync)(struct host1x_intr *);
+	void (*set_host_clocks_per_usec)(
+		struct host1x_intr *, u32 clocks);
+	void (*set_syncpt_threshold)(
+		struct host1x_intr *, u32 id, u32 thresh);
+	void (*enable_syncpt_intr)(struct host1x_intr *, u32 id);
+	void (*disable_syncpt_intr)(struct host1x_intr *, u32 id);
+	void (*disable_all_syncpt_intrs)(struct host1x_intr *);
+	int (*free_syncpt_irq)(struct host1x_intr *);
+};
+
 struct host1x_device_info {
 	int	nb_channels;		/* host1x: num channels supported */
 	int	nb_pts;			/* host1x: num syncpoints supported */
@@ -48,6 +61,7 @@ struct host1x_device_info {
 struct host1x {
 	void __iomem *regs;
 	struct host1x_syncpt *syncpt;
+	struct host1x_intr intr;
 	struct platform_device *dev;
 	atomic_t clientid;
 	struct host1x_device_info info;
@@ -57,6 +71,7 @@ struct host1x {
 
 	const char *soc_name;
 	struct host1x_syncpt_ops syncpt_op;
+	struct host1x_intr_ops intr_op;
 
 	struct dentry *debugfs;
 };
drivers/gpu/host1x/hw/host1x01.c +2 -0
index 59176ba..c5c55a3 100644
@@ -27,10 +27,12 @@
 #include "hw/host1x01_hardware.h"
 
 #include "hw/syncpt_hw.c"
+#include "hw/intr_hw.c"
 
 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 +29 -1
index 63a71c8..b06a2c5 100644
@@ -51,10 +51,38 @@
 #ifndef __hw_host1x_sync_h__
 #define __hw_host1x_sync_h__
 
+static inline u32 host1x_sync_syncpt_thresh_cpu0_int_status_r(void)
+{
+	return 0x40;
+}
+static inline u32 host1x_sync_syncpt_thresh_int_disable_r(void)
+{
+	return 0x60;
+}
+static inline u32 host1x_sync_syncpt_thresh_int_enable_cpu0_r(void)
+{
+	return 0x68;
+}
+static inline u32 host1x_sync_usec_clk_r(void)
+{
+	return 0x1a4;
+}
+static inline u32 host1x_sync_ctxsw_timeout_cfg_r(void)
+{
+	return 0x1a8;
+}
+static inline u32 host1x_sync_ip_busy_timeout_r(void)
+{
+	return 0x1bc;
+}
 static inline u32 host1x_sync_syncpt_0_r(void)
 {
 	return 0x400;
 }
+static inline u32 host1x_sync_syncpt_int_thresh_0_r(void)
+{
+	return 0x500;
+}
 static inline u32 host1x_sync_syncpt_base_0_r(void)
 {
 	return 0x600;
@@ -63,4 +91,4 @@ static inline u32 host1x_sync_syncpt_cpu_incr_r(void)
 {
 	return 0x700;
 }
-#endif /* __hw_host1x_host1x_h__ */
+#endif /* __hw_host1x_sync_h__ */
drivers/gpu/host1x/hw/intr_hw.c new file +178 -0

178 lines not on this page · raw message

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

350 lines not on this page · raw message

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

100 lines not on this page · raw message

drivers/gpu/host1x/syncpt.c +163 -1

182 lines not on this page · raw message

drivers/gpu/host1x/syncpt.h +4 -0
index 4f7777b..d4d1f3f 100644
@@ -106,6 +106,7 @@ struct host1x_syncpt *host1x_syncpt_get(struct host1x *dev, u32 id);
 void host1x_syncpt_cpu_incr(struct host1x_syncpt *sp);
 
 u32 host1x_syncpt_load_min(struct host1x_syncpt *sp);
+bool host1x_syncpt_is_expired(struct host1x_syncpt *sp, u32 thresh);
 
 void host1x_syncpt_save(struct host1x *dev);
 
@@ -117,6 +118,9 @@ u32 host1x_syncpt_read_wait_base(struct host1x_syncpt *sp);
 void host1x_syncpt_incr(struct host1x_syncpt *sp);
 u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
 
+int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh,
+			long timeout, u32 *value);
+
 void host1x_syncpt_debug(struct host1x_syncpt *sp);
 
 static inline int host1x_syncpt_is_valid(struct host1x_syncpt *sp)
include/linux/host1x.h +1 -0
index 6c2cc8a..00060ee 100644
@@ -33,6 +33,7 @@ struct host1x_syncpt;
 u32 host1x_syncpt_id(struct host1x_syncpt *sp);
 void host1x_syncpt_incr_byid(u32 id);
 u32 host1x_syncpt_read_byid(u32 id);
+int host1x_syncpt_wait_byid(u32 id, u32 thresh, long timeout, u32 *value);
 
 struct host1x_syncpt *host1x_syncpt_alloc(struct platform_device *pdev,
 		int client_managed);
Signature · 1 line
1.7.9.5
#19 lore raw

PATCH v4 7/8 drm: tegra: Add gr2d device

In reply to Terje Bergstrom

Add client driver for 2D device.

---
 drivers/gpu/drm/tegra/Makefile |    2 +-
 drivers/gpu/drm/tegra/drm.c    |  211 ++++++++++++++++++++++++++-
 drivers/gpu/drm/tegra/drm.h    |   29 ++++
 drivers/gpu/drm/tegra/gr2d.c   |  307 ++++++++++++++++++++++++++++++++++++++++
 include/drm/tegra_drm.h        |  111 +++++++++++++++
 5 files changed, 658 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/tegra/gr2d.c
drivers/gpu/drm/tegra/Makefile +1 -1
index f4c05bb..2661f41 100644
@@ -1,7 +1,7 @@
 ccflags-y := -Iinclude/drm
 ccflags-$(CONFIG_DRM_TEGRA_DEBUG) += -DDEBUG
 
-tegra-drm-y := drm.o fb.o dc.o
+tegra-drm-y := drm.o fb.o dc.o gr2d.o
 tegra-drm-y += output.o rgb.o hdmi.o
 
 obj-$(CONFIG_DRM_TEGRA) += tegra-drm.o
drivers/gpu/drm/tegra/drm.c +210 -1

251 lines not on this page · raw message

drivers/gpu/drm/tegra/drm.h +29 -0
index 34cc3a1..06100d7 100644
@@ -44,17 +44,45 @@ struct tegradrm {
 
 struct tegra_drm_client;
 
+struct tegra_drm_context {
+	struct tegra_drm_client *client;
+	struct host1x_channel *channel;
+	struct list_head list;
+};
+
 struct tegra_drm_client_ops {
 	int (*drm_init)(struct tegra_drm_client *, struct drm_device *);
 	int (*drm_exit)(struct tegra_drm_client *);
+	int (*open_channel)(struct tegra_drm_client *,
+			struct tegra_drm_context *);
+	void (*close_channel)(struct tegra_drm_context *);
+	u32 (*get_syncpoint)(struct tegra_drm_context *, int index);
+	int (*submit)(struct tegra_drm_context *,
+			struct tegra_drm_submit_args *,
+			struct drm_device *,
+			struct drm_file *);
+};
+
+
+struct tegra_drm_fpriv {
+	struct list_head contexts;
 };
 
+static inline struct tegra_drm_fpriv *
+tegra_drm_fpriv(struct drm_file *file_priv)
+{
+	return file_priv ? file_priv->driver_priv : NULL;
+}
+
 struct tegra_drm_client {
 	struct tegradrm *tegradrm;
 	struct device *dev;
 
 	const struct tegra_drm_client_ops *ops;
 
+	u32 class;
+	struct host1x_channel *channel;
+
 	struct list_head list;
 
 };
@@ -222,6 +250,7 @@ extern void tegra_drm_fb_restore(struct drm_device *drm);
 
 extern struct platform_driver tegra_hdmi_driver;
 extern struct platform_driver tegra_dc_driver;
+extern struct platform_driver tegra_gr2d_driver;
 extern struct drm_driver tegra_drm_driver;
 
 #endif /* TEGRA_DRM_H */
drivers/gpu/drm/tegra/gr2d.c new file +307 -0

307 lines not on this page · raw message

include/drm/tegra_drm.h +111 -0

115 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#23 lore raw
In reply to Terje Bergstrom

Am Freitag, den 21.12.2012, 13:39 +0200 schrieb Terje Bergstrom:

Quoted 11 lines

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

The fourth version has only few changes compared to previous version:
* Fixed some sparse warnings
* Fixed host1x Makefile to allow building as module
* Fixed host1x module unload
* Fixed tegradrm unload sequence
* host1x creates DRM dummy device and tegradrm uses it for storing DRM related data.

Quoted 5 lines

Some of the issues left open:
* Register definitions still use static inline. There has been a debate about code style versus ability to use compiler type checking and code coverage analysis. There was no conclusion, so I left it as was.

This has to be resolved before merging. Personally I'm in favour of keeping reg access patterns close to what is done in other parts of the kernel.

Quoted 2 lines

* Uses still CMA helpers. IOMMU support will replace CMA with host1x specific allocator.

I really want the allocator issue resolved before talking about merging those patches. Proper IOMMU support will require a bit of rework of the current upstream IOMMU API, so it will still be a bit out.

But if you don't mind I'll try to implement the host1x allocator over the holidays and provide an incremental patch.

Regards,
Lucas

#24 lore raw
Quoted 3 lines · Lucas Stach

This has to be resolved before merging. Personally I'm in favour of keeping reg access patterns close to what is done in other parts of the kernel.

I haven't so far received comments from too many people, so that's why I left it as is.

Quoted 9 lines
Quoted 2 lines

* Uses still CMA helpers. IOMMU support will replace CMA with host1x specific allocator.

I really want the allocator issue resolved before talking about merging those patches. Proper IOMMU support will require a bit of rework of the current upstream IOMMU API, so it will still be a bit out.

But if you don't mind I'll try to implement the host1x allocator over the holidays and provide an incremental patch.

Do you mean host1x CMA allocator using dma mapping API? That'd be great if you could help out. I've just tried to concentrate on getting ok for base essentials before doing any extra work.

Terje

#21 lore raw

Re: [PATCHv4 8/8] gpu: host1x: Register DRM dummy device

In reply to Terje Bergstrom

Am Freitag, den 21.12.2012, 13:39 +0200 schrieb Terje Bergstrom:

Quoted 5 lines

Register a dummy device for tegradrm, and provide a getter to access the device.

---

[...]

Quoted 29 lines
drivers/gpu/host1x/drm.c new file +23 -0
new file mode 100644
index 0000000..eaaaeed
@@ -0,0 +1,51 @@
+/*
+ * Tegra host1x driver DRM dummy device
+ *
+ * Copyright (c) 2012, 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 <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/module.h>
+#include "drm.h"
+#include "dev.h"

drivers/gpu/host1x/drm.c line 33

Quoted 10 lines
drivers/gpu/host1x/drm.c new file +10 -0
+
+int host1x_register_drm_device(struct host1x *host1x)
+{
+	struct platform_device *drm_device;
+
+	drm_device = platform_device_register_simple("tegradrm", -1, NULL, 0);
+	if (!drm_device)
+		return -ENOMEM;
+	dma_set_coherent_mask(&drm_device->dev, DMA_BIT_MASK(32));
+

This might not be necessary once we move the allocator to host1x.

Quoted 8 lines
drivers/gpu/host1x/drm.c new file +8 -0
+	host1x->drm_device = drm_device;
+	return 0;
+}
+EXPORT_SYMBOL(host1x_register_drm_device);
+
+void host1x_unregister_drm_device(struct host1x *host1x)
+{
+	if (host1x->drm_device)

drivers/gpu/host1x/drm.c line 51

Quoted 10 lines
drivers/gpu/host1x/drm.c new file +10 -0
+		platform_device_unregister(host1x->drm_device);
+}
+EXPORT_SYMBOL(host1x_unregister_drm_device);
+
+struct platform_device *host1x_drm_device(struct platform_device *pdev)
+{
+	struct host1x *host = platform_get_drvdata(pdev);
+	return host->drm_device;
+}
+EXPORT_SYMBOL(host1x_drm_device);

This should be called host1x_get_drm_device

#25 lore raw
In reply to Terje Bergström

Am Freitag, den 21.12.2012, 15:57 +0200 schrieb Terje Bergström:

Quoted 15 lines · Lucas Stach
Quoted 3 lines

This has to be resolved before merging. Personally I'm in favour of keeping reg access patterns close to what is done in other parts of the kernel.

I haven't so far received comments from too many people, so that's why I left it as is.

Quoted 7 lines
Quoted 2 lines

* Uses still CMA helpers. IOMMU support will replace CMA with host1x specific allocator.

I really want the allocator issue resolved before talking about merging those patches. Proper IOMMU support will require a bit of rework of the current upstream IOMMU API, so it will still be a bit out.

Quoted 7 lines
Quoted 2 lines

But if you don't mind I'll try to implement the host1x allocator over the holidays and provide an incremental patch.

Do you mean host1x CMA allocator using dma mapping API? That'd be great if you could help out. I've just tried to concentrate on getting ok for base essentials before doing any extra work.

Yes, exactly that.

I'll provide comments to the other patches when I find time to do so. Digging in the code might help with this.

Regards,
Lucas

#22 lore raw

Re: [PATCHv4 8/8] gpu: host1x: Register DRM dummy device

In reply to Lucas Stach
Quoted 1 line · Lucas Stach

Am Freitag, den 21.12.2012, 13:39 +0200 schrieb Terje Bergstrom:

[...]

Quoted 6 lines
Quoted 6 lines
drivers/gpu/host1x/drm.c new file +6 -0
+void host1x_unregister_drm_device(struct host1x *host1x)
+{
+	if (host1x->drm_device)
+		platform_device_unregister(host1x->drm_device);
+}
+EXPORT_SYMBOL(host1x_unregister_drm_device);
Quoted 8 lines

drivers/gpu/host1x/drm.c line 51

Quoted 7 lines
drivers/gpu/host1x/drm.c new file +7 -0
+
+struct platform_device *host1x_drm_device(struct platform_device *pdev)
+{
+	struct host1x *host = platform_get_drvdata(pdev);
+	return host->drm_device;
+}
+EXPORT_SYMBOL(host1x_drm_device);

This should be called host1x_get_drm_device

Or maybe even host1x_drm_get_device() to make it more obvious that it doesn't return a struct drm_device. Also I think it would be better to make it take a struct device * and return a struct device * instead. Users of the API will probably call this like so:

	struct device *dummy = host1x_drm_get_device(pdev->dev.parent);
	struct drm_device *drm = dev_get_drvdata(dummy);

So we save ourselves some needless up-casting.

Thierry

#12 lore raw

Re: [PATCHv4 5/8] drm: tegra: Remove redundant host1x

In reply to Terje Bergstrom
Quoted 1 line · Terje Bergstrom

From: Arto Merilainen <[email protected]>

[...]

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

[...]

Quoted 14 lines
drivers/gpu/drm/tegra/drm.c +14 -0
+static int tegra_drm_add_client(struct device *dev, void *data)
+{
+	static const char * const compat[] = {
+		"nvidia,tegra20-dc",
+		"nvidia,tegra20-hdmi",
+		"nvidia,tegra30-dc",
+		"nvidia,tegra30-hdmi",
+	};
+	struct tegradrm *tegradrm = data;
+	struct tegra_drm_client_entry *client;
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(compat); i++) {
+		if (of_device_is_compatible(dev->of_node, compat[i]) &&

drivers/gpu/drm/tegra/drm.c line 57

Quoted 10 lines
drivers/gpu/drm/tegra/drm.c +10 -0
+		    of_device_is_available(dev->of_node)) {
+			client = kzalloc(sizeof(*client), GFP_KERNEL);
+			if (!client)
+				return -ENOMEM;
+
+			INIT_LIST_HEAD(&client->list);
+			client->np = of_node_get(dev->of_node);
+
+			list_add_tail(&client->list, &tegradrm->drm_clients);
+			dev_set_drvdata(dev, tegradrm);

This should go away now that we have an accessor for this, right?

Quoted 6 lines
drivers/gpu/drm/tegra/drm.c +6 -0
+static int tegra_drm_parse_dt(struct tegradrm *tegradrm)
+{
+	int err;
+	struct device *dev;
+
+	/* host1x is parent of all devices */

drivers/gpu/drm/tegra/drm.c line 79

Quoted 10 lines
drivers/gpu/drm/tegra/drm.c +10 -0
+	dev = bus_find_device_by_name(&platform_bus_type, NULL, "host1x");
+	if (!dev)
+		return -ENODEV;
+
+	/* find devices that are available and add them into the 'required'
+	 * list */
+	err = device_for_each_child(dev, tegradrm, tegra_drm_add_client);
+
+	return err;
+}

I don't see why we can't keep the original code here. The problem with your approach is that you'll match on a global device host1x, regardless of it's relationship to tegra-drm. Instead what you should be doing is use the hierarchical information that you have to make this work. So the dummy device should be registered as a child device of host1x, because that allows the host1x device to be obtained from the dummy's parent. In that way you can use the host1x device's of_node to search through the devicetree. That's precisely what the existing code does and I see no reason to change that.

drivers/gpu/drm/tegra/drm.c static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp) · line 193

Quoted 5 lines
drivers/gpu/drm/tegra/drm.c +5 -0
+static void tegra_drm_close(struct drm_device *drm, struct drm_file *filp)
+{
+
+}
+

This can be removed, right?

drivers/gpu/drm/tegra/drm.c static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp) · line 232

Quoted 3 lines
drivers/gpu/drm/tegra/drm.c +3 -0
+static struct platform_driver tegra_drm_platform_driver = {
+	.driver = {
+		.name = "tegradrm",

This should be "tegra-drm" to match the module name.

Quoted 1 line
drivers/gpu/drm/tegra/drm.h +0 -0

[...]

Quoted 12 lines

index 3a843a7..34cc3a1 100644

drivers/gpu/drm/tegra/drm.h +1 -0
@@ -17,6 +17,7 @@
 #include <drm/drm_gem_cma_helper.h>
 #include <drm/drm_fb_cma_helper.h>
 #include <drm/drm_fixed.h>
+#include <drm/tegra_drm.h>
 
 struct tegra_framebuffer {
 	struct drm_framebuffer base;

drivers/gpu/drm/tegra/drm.h static inline struct tegra_framebuffer *to_tegra_fb(struct drm_framebuffer *fb) · line 32

Quoted 6 lines
drivers/gpu/drm/tegra/drm.h +1 -2
@@ -28,17 +29,11 @@ static inline struct tegra_framebuffer *to_tegra_fb(struct drm_framebuffer *fb)
 	return container_of(fb, struct tegra_framebuffer, base);
 }
 
-struct host1x {
-	struct drm_device *drm;
+struct tegradrm {

Similarly, this should be tegra_drm.

drivers/gpu/drm/tegra/drm.h struct host1x { · line 45

Quoted 2 lines
drivers/gpu/drm/tegra/drm.h +1 -1
-struct host1x_client;
+struct tegra_drm_client;

I don't see the point in renaming this. All of the devices are still host1x clients, right? This patch would be a whole shorter if we didn't rename these. None of these symbols are exported either so there's not much chance for them to clash with anything.

drivers/gpu/drm/tegra/drm.h static inline struct tegra_framebuffer *to_tegra_fb(struct drm_framebuffer *fb) · line 39

Quoted 7 lines
drivers/gpu/drm/tegra/drm.h +1 -1
 static int tegra_hdmi_probe(struct platform_device *pdev)
 {
-	struct host1x *host1x = dev_get_drvdata(pdev->dev.parent);
 	struct tegra_hdmi *hdmi;
 	struct resource *regs;
 	int err;
+	struct tegradrm *tegradrm = platform_get_drvdata(pdev);

I think we all agreed already that you shouldn't be mucking with the driver private data in this way.

Quoted 16 lines
include/drm/tegra_drm.h new file +10 -0
new file mode 100644
index 0000000..8632f49
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
+ *
+ * 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

include/drm/tegra_drm.h line 20

Quoted 10 lines
include/drm/tegra_drm.h new file +10 -0
+ * 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 _TEGRA_DRM_H_
+#define _TEGRA_DRM_H_
+
+#endif

This can be removed as well.

Thierry

maintainer
#4 lore raw

Re: [PATCHv4 3/8] gpu: host1x: Add channel support

In reply to Terje Bergstrom
Quoted 41 lines · Terje Bergstrom
include/trace/events/host1x.h +33 -0
index d98d74c..e087910 100644
@@ -37,6 +37,214 @@ DECLARE_EVENT_CLASS(host1x,
 	TP_printk("name=%s", __entry->name)
 );
 
+DEFINE_EVENT(host1x, host1x_channel_open,
+	TP_PROTO(const char *name),
+	TP_ARGS(name)
+);
+
+DEFINE_EVENT(host1x, host1x_channel_release,
+	TP_PROTO(const char *name),
+	TP_ARGS(name)
+);
+
+TRACE_EVENT(host1x_cdma_begin,
+	TP_PROTO(const char *name),
+
+	TP_ARGS(name),
+
+	TP_STRUCT__entry(
+		__field(const char *, name)
+	),
+
+	TP_fast_assign(
+		__entry->name = name;
+	),
+
+	TP_printk("name=%s",
+		__entry->name)
+);
+
+TRACE_EVENT(host1x_cdma_end,
+	TP_PROTO(const char *name),
+
+	TP_ARGS(name),
+
+	TP_STRUCT__entry(

include/trace/events/host1x.h DECLARE_EVENT_CLASS(host1x, · line 82

Quoted 10 lines
include/trace/events/host1x.h +10 -0
+		__field(const char *, name)
+	),
+
+	TP_fast_assign(
+		__entry->name = name;
+	),
+
+	TP_printk("name=%s",
+		__entry->name)
+);

The above two should be combined into a DECLARE_EVENT_CLASS() and DEFINE_EVENT()s. Saves text and data space that way.

Quoted 188 lines
include/trace/events/host1x.h +181 -0
+
+TRACE_EVENT(host1x_cdma_flush,
+	TP_PROTO(const char *name, int timeout),
+
+	TP_ARGS(name, timeout),
+
+	TP_STRUCT__entry(
+		__field(const char *, name)
+		__field(int, timeout)
+	),
+
+	TP_fast_assign(
+		__entry->name = name;
+		__entry->timeout = timeout;
+	),
+
+	TP_printk("name=%s, timeout=%d",
+		__entry->name, __entry->timeout)
+);
+
+TRACE_EVENT(host1x_cdma_push,
+	TP_PROTO(const char *name, u32 op1, u32 op2),
+
+	TP_ARGS(name, op1, op2),
+
+	TP_STRUCT__entry(
+		__field(const char *, name)
+		__field(u32, op1)
+		__field(u32, op2)
+	),
+
+	TP_fast_assign(
+		__entry->name = name;
+		__entry->op1 = op1;
+		__entry->op2 = op2;
+	),
+
+	TP_printk("name=%s, op1=%08x, op2=%08x",
+		__entry->name, __entry->op1, __entry->op2)
+);
+
+TRACE_EVENT(host1x_cdma_push_gather,
+	TP_PROTO(const char *name, u32 mem_id,
+			u32 words, u32 offset, void *cmdbuf),
+
+	TP_ARGS(name, mem_id, words, offset, cmdbuf),
+
+	TP_STRUCT__entry(
+		__field(const char *, name)
+		__field(u32, mem_id)
+		__field(u32, words)
+		__field(u32, offset)
+		__field(bool, cmdbuf)
+		__dynamic_array(u32, cmdbuf, words)
+	),
+
+	TP_fast_assign(
+		if (cmdbuf) {
+			memcpy(__get_dynamic_array(cmdbuf), cmdbuf+offset,
+					words * sizeof(u32));
+		}
+		__entry->cmdbuf = cmdbuf;
+		__entry->name = name;
+		__entry->mem_id = mem_id;
+		__entry->words = words;
+		__entry->offset = offset;
+	),
+
+	TP_printk("name=%s, mem_id=%08x, words=%u, offset=%d, contents=[%s]",
+	  __entry->name, __entry->mem_id,
+	  __entry->words, __entry->offset,
+	  __print_hex(__get_dynamic_array(cmdbuf),
+		  __entry->cmdbuf ? __entry->words * 4 : 0))
+);
+
+TRACE_EVENT(host1x_channel_submit,
+	TP_PROTO(const char *name, u32 cmdbufs, u32 relocs, u32 waitchks,
+			u32 syncpt_id, u32 syncpt_incrs),
+
+	TP_ARGS(name, cmdbufs, relocs, waitchks, syncpt_id, syncpt_incrs),
+
+	TP_STRUCT__entry(
+		__field(const char *, name)
+		__field(u32, cmdbufs)
+		__field(u32, relocs)
+		__field(u32, waitchks)
+		__field(u32, syncpt_id)
+		__field(u32, syncpt_incrs)
+	),
+
+	TP_fast_assign(
+		__entry->name = name;
+		__entry->cmdbufs = cmdbufs;
+		__entry->relocs = relocs;
+		__entry->waitchks = waitchks;
+		__entry->syncpt_id = syncpt_id;
+		__entry->syncpt_incrs = syncpt_incrs;
+	),
+
+	TP_printk("name=%s, cmdbufs=%u, relocs=%u, waitchks=%d,"
+		"syncpt_id=%u, syncpt_incrs=%u",
+	  __entry->name, __entry->cmdbufs, __entry->relocs, __entry->waitchks,
+	  __entry->syncpt_id, __entry->syncpt_incrs)
+);
+
+TRACE_EVENT(host1x_channel_submitted,
+	TP_PROTO(const char *name, u32 syncpt_base, u32 syncpt_max),
+
+	TP_ARGS(name, syncpt_base, syncpt_max),
+
+	TP_STRUCT__entry(
+		__field(const char *, name)
+		__field(u32, syncpt_base)
+		__field(u32, syncpt_max)
+	),
+
+	TP_fast_assign(
+		__entry->name = name;
+		__entry->syncpt_base = syncpt_base;
+		__entry->syncpt_max = syncpt_max;
+	),
+
+	TP_printk("name=%s, syncpt_base=%d, syncpt_max=%d",
+		__entry->name, __entry->syncpt_base, __entry->syncpt_max)
+);
+
+TRACE_EVENT(host1x_channel_submit_complete,
+	TP_PROTO(const char *name, int count, u32 thresh),
+
+	TP_ARGS(name, count, thresh),
+
+	TP_STRUCT__entry(
+		__field(const char *, name)
+		__field(int, count)
+		__field(u32, thresh)
+	),
+
+	TP_fast_assign(
+		__entry->name = name;
+		__entry->count = count;
+		__entry->thresh = thresh;
+	),
+
+	TP_printk("name=%s, count=%d, thresh=%d",
+		__entry->name, __entry->count, __entry->thresh)
+);
+
+TRACE_EVENT(host1x_wait_cdma,
+	TP_PROTO(const char *name, u32 eventid),
+
+	TP_ARGS(name, eventid),
+
+	TP_STRUCT__entry(
+		__field(const char *, name)
+		__field(u32, eventid)
+	),
+
+	TP_fast_assign(
+		__entry->name = name;
+		__entry->eventid = eventid;
+	),
+
+	TP_printk("name=%s, event=%d", __entry->name, __entry->eventid)
+);
+
 TRACE_EVENT(host1x_syncpt_load_min,
 	TP_PROTO(u32 id, u32 val),
 
@@ -55,6 +263,33 @@ TRACE_EVENT(host1x_syncpt_load_min,
 	TP_printk("id=%d, val=%d", __entry->id, __entry->val)
 );
 
+TRACE_EVENT(host1x_syncpt_wait_check,
+	TP_PROTO(u32 mem_id, u32 offset, u32 syncpt_id, u32 thresh, u32 min),
+
+	TP_ARGS(mem_id, offset, syncpt_id, thresh, min),
+
+	TP_STRUCT__entry(
+		__field(u32, mem_id)
+		__field(u32, offset)
+		__field(u32, syncpt_id)
+		__field(u32, thresh)
+		__field(u32, min)
+	),
+
+	TP_fast_assign(
+		__entry->mem_id = mem_id;
+		__entry->offset = offset;

include/trace/events/host1x.h TRACE_EVENT(host1x_syncpt_load_min, · line 291

Quoted 10 lines
include/trace/events/host1x.h +10 -0
+		__entry->syncpt_id = syncpt_id;
+		__entry->thresh = thresh;
+		__entry->min = min;
+	),
+
+	TP_printk("mem_id=%08x, offset=%05x, id=%d, thresh=%d, current=%d",
+		__entry->mem_id, __entry->offset,
+		__entry->syncpt_id, __entry->thresh,
+		__entry->min)
+);

If you can combine any of these others into DECLARE_EVENT_CLASS() and DEFINE_EVENT()s, please do.

Thanks,

-- Steve

Quoted 4 lines
include/trace/events/host1x.h +1 -0
+
 #endif /*  _TRACE_HOST1X_H */
 
 /* This part must be outside protection */
#13 lore raw

Re: [PATCHv4 5/8] drm: tegra: Remove redundant host1x

In reply to Thierry Reding
Quoted 6 lines · Thierry Reding

drivers/gpu/drm/tegra/drm.c static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp) · line 232

Quoted 3 lines · Terje Bergstrom
drivers/gpu/drm/tegra/drm.c +3 -0
+static struct platform_driver tegra_drm_platform_driver = {
+	.driver = {
+		.name = "tegradrm",

This should be "tegra-drm" to match the module name.

We've actually created two problems.

First is that the device name should match driver name which should match module name. But host1x doesn't know the module name of tegradrm.

Second problem is that host1x driver creates tegradrm device even if tegradrm isn't loaded to system.

These mean that the device has to be created in tegra-drm module to have access to the module name. So instead of just getter, we need a getter and a setter.

Terje

#14 lore raw

Re: [PATCHv4 5/8] drm: tegra: Remove redundant host1x

Quoted 8 lines · Terje Bergström
Quoted 6 lines · Thierry Reding

drivers/gpu/drm/tegra/drm.c static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp) · line 232

Quoted 3 lines · Terje Bergstrom
drivers/gpu/drm/tegra/drm.c +3 -0
+static struct platform_driver tegra_drm_platform_driver = {
+	.driver = {
+		.name = "tegradrm",

This should be "tegra-drm" to match the module name.

Quoted 4 lines

We've actually created two problems.

First is that the device name should match driver name which should match module name. But host1x doesn't know the module name of tegradrm.

There's no hard requirement for the device/driver name to match the module name. It's good thing to do, but nothing will blow up if it don't (modules can use MODULE_ALIAS() to declare which drivers they expose).

But, what's the problem with host1x knowing the driver name; the host1x driver and tegradrm driver are both part of the same code-base, so this seems trivial to achieve.

Quoted 2 lines

Second problem is that host1x driver creates tegradrm device even if tegradrm isn't loaded to system.

That's fine. If there's no driver, the device simply won't be probe()d. That's just like a device node existing in device tree, but the driver for it not being enabled in the kernel, or the relevant module not being inserted.

Quoted 1 line

These mean that the device has to be created in tegra-drm module to have

I definitely disagree here.

#27 lore raw
In reply to Terje Bergstrom

Hi Terje,

I applied your patches on top of upstream 1224 kernel. Then I read the codes. So here is my review comments(I use "git diff" to print out, check below). I admit it's easy for me to not need to find the corresponding lines in your 8 patch mails, but I've no idea whether it is ok for you. If this makes you not feeling good, I'll do this in old ways. Basically, I think in this diff output, there are filename/line number/function name, so it should not be a hard work for you to understand my comments.

P.S: I haven't finished the review so here is what I found today.

drivers/gpu/drm/tegra/gr2d.c +0 -0
index a936902..28954b3 100644
@@ -247,6 +247,10 @@ static int __devinit gr2d_probe(struct

platform_device *dev)
{
int err;
struct gr2d *gr2d = NULL;
+ /* Cause drm_device is created in host1x driver. So

+	   if host1x drivers loads after tegradrm, then in this
+	   gr2d_probe function, this "drm_device" will be NULL.
+	   How can we handle this? Defer driver probe? */

struct platform_device *drm_device =
host1x_drm_device(to_platform_device(dev->dev.parent));
struct tegradrm *tegradrm = platform_get_drvdata(drm_device);
@@ -273,6 +277,11 @@ static int __devinit gr2d_probe(struct platform_device *dev)

gr2d->syncpt = host1x_syncpt_alloc(dev, 0); if (!gr2d->syncpt) {
+ /* Do we really need this?

+		   After "host1x_channel_alloc", the refcount of this
+		   channel is 0. So calling host1x_channel_put here will
+		   make the refcount going to negative.
+		   I suppose we should call "host1x_free_channel" here. */

host1x_channel_put(gr2d->channel); return -ENOMEM;
}
@@ -284,6 +293,7 @@ static int __devinit gr2d_probe(struct platform_device *dev)

err = tegra_drm_register_client(tegradrm, &gr2d->client); if (err)
+ /* Add "host1x_free_channel" */
return err;

platform_set_drvdata(dev, gr2d);

drivers/gpu/host1x/channel.c +0 -0
index 3705cae..ed83b9e 100644
@@ -95,6 +95,9 @@ struct host1x_channel *host1x_channel_alloc(struct

platform_device *pdev)
int max_channels = host1x->info.nb_channels; int err;

+ /* Is it necessary to add mutex protection here?
+ I'm just wondering in a smp system, multiple host1x clients
+ may try to alloc their channels simultaneously... */
if (chindex > max_channels)
return NULL;

drivers/gpu/host1x/debug.c +0 -0
index 86d5c70..f2bd5aa 100644
@@ -164,6 +164,10 @@ static const struct file_operations

host1x_debug_fops = {

void host1x_debug_init(struct host1x *host1x)
{
+ /* I think it's better to set this directory name the same with

+	   the driver's name -- defined in dev.c:
+	   #define DRIVER_NAME	"tegra-host1x"
+	   */

struct dentry *de = debugfs_create_dir("tegra_host", NULL);

if (!de)

drivers/gpu/host1x/dev.c +17 -1
index 07e8813..01ed10d 100644
@@ -38,6 +38,7 @@
 
 struct host1x *host1x;
 
+/* Called by drm unlocked ioctl function. So do we need a lock here? */
 void host1x_syncpt_incr_byid(u32 id)
 {
 	struct host1x_syncpt *sp = host1x->syncpt + id;
@@ -52,6 +53,7 @@ u32 host1x_syncpt_read_byid(u32 id)
 }
 EXPORT_SYMBOL(host1x_syncpt_read_byid);
 
+/* Called by drm unlocked ioctl function. So do we need a lock here? */
 int host1x_syncpt_wait_byid(u32 id, u32 thresh, long timeout, u32 *value)
 {
 	struct host1x_syncpt *sp = host1x->syncpt + id;
@@ -161,6 +163,8 @@ static int host1x_probe(struct platform_device *dev)
 
 	err = host1x_alloc_resources(host);
 	if (err) {
+		/* We don't have chip_ops right now, so here the
+		   error message is somewhat improper */
 		dev_err(&dev->dev, "failed to init chip support\n");
 		goto fail;
 	}
@@ -175,6 +179,14 @@ static int host1x_probe(struct platform_device *dev)
 	if (!host->syncpt)
 		goto fail;
 
+	/* I suggest create a dedicate function for initializing nop sp.
+	   First this "_host1x_syncpt_alloc" looks like an internal/static
+	   function.
+	   Then actually "host1x_syncpt_alloc" & "_host1x_syncpt_alloc" all
+	   serve host1x client(e.g: gr2d) so it's not suitable to use them
+	   for nop sp.
+	   Just create a wrapper function to call _host1x_syncpt_alloc is OK.
+	   This will make the code more readable. */
 	host->nop_sp = _host1x_syncpt_alloc(host, NULL, 0);
 	if (!host->nop_sp)
 		goto fail;
@@ -191,6 +203,7 @@ static int host1x_probe(struct platform_device *dev)
 	}
 
 	err = clk_prepare_enable(host->clk);
+	/* Add a dev_err here */
 	if (err < 0)
 		goto fail;
 
@@ -209,9 +222,12 @@ static int host1x_probe(struct platform_device *dev)
 	return 0;
 
 fail:
+	/* host1x->syncpt isn't released here... */
+	/* host1x->intr isn't release here... */
+	/* Remove debugfs stuffs? */
 	host1x_syncpt_free(host->nop_sp);
 	host1x_unregister_drm_device(host);
-	kfree(host);
+	kfree(host); /* not necessary*/
 	return err;
 }
 
@@ -222,6 +238,7 @@ static int __exit host1x_remove(struct

platform_device *dev)
host1x_syncpt_deinit(host);
host1x_unregister_drm_device(host);
clk_disable_unprepare(host->clk);
+ /* Remove debugfs stuffs? */
return 0;
}

drivers/gpu/host1x/dev.h +8 -0
index 05f8544..58f4c71 100644
@@ -36,6 +36,7 @@ struct platform_device;
 struct output;
 
 struct host1x_channel_ops {
+	/* Seems no one uses this member. Remove it. */
 	const char *soc_name;
 	int (*init)(struct host1x_channel *,
 		    struct host1x *,
@@ -125,12 +126,18 @@ struct host1x {
 	struct host1x_syncpt *syncpt;
 	struct host1x_intr intr;
 	struct platform_device *dev;
+
+	/* Seems no one uses this. Remove it. */
 	atomic_t clientid;
 	struct host1x_device_info info;
 	struct clk *clk;
 
+	/* Put some comments for this member.
+	   For guys who're not familiar with nop sp, I think they'll
+	   definitely get confused about this. */
 	struct host1x_syncpt *nop_sp;
 
+	/* Seems no one uses this member. Remove it. */
 	const char *soc_name;
 	struct host1x_channel_ops channel_op;
 	struct host1x_cdma_ops cdma_op;
@@ -140,6 +147,7 @@ struct host1x {
 	struct host1x_intr_ops intr_op;
 
 	struct host1x_channel chlist;
+
 	int allocated_channels;
 
 	struct dentry *debugfs;
drivers/gpu/host1x/intr.c +5 -0
index efcb9be..e112001 100644
@@ -329,8 +329,13 @@ void host1x_intr_deinit(struct host1x_intr *intr)
 void host1x_intr_start(struct host1x_intr *intr, u32 hz)
 {
 	struct host1x *host1x = intr_to_host1x(intr);
+
+	/* Why we need to lock here? Seems like this function is
+	   called by host1x's probe only. */
 	mutex_lock(&intr->mutex);
 
+	/* "init_host_sync" has already been called in function
+	   host1x_intr_init. Remove this line. */
 	host1x->intr_op.init_host_sync(intr);
 	host1x->intr_op.set_host_clocks_per_usec(intr,
 			DIV_ROUND_UP(hz, 1000000));
drivers/gpu/host1x/syncpt.c +0 -0
index 07cbca5..9a234ad 100644
@@ -309,6 +309,8 @@ struct host1x_syncpt *host1x_syncpt_init(struct

host1x *host)
struct host1x_syncpt *syncpt, *sp;
int i;

+ /* Consider devm_kzalloc here. Then you can forget the release
+ stuffs about this "syncpt". */
syncpt = sp = kzalloc(sizeof(struct host1x_syncpt) * host->info.nb_pts,
GFP_KERNEL);
if (!syncpt)

Mark

Quoted 152 lines · Terje Bergstrom

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

The fourth version has only few changes compared to previous version:
* Fixed some sparse warnings
* Fixed host1x Makefile to allow building as module
* Fixed host1x module unload
* Fixed tegradrm unload sequence
* host1x creates DRM dummy device and tegradrm uses it for storing DRM related data.

Some of the issues left open:
* Register definitions still use static inline. There has been a debate about code style versus ability to use compiler type checking and code coverage analysis. There was no conclusion, so I left it as was.
* Uses still CMA helpers. IOMMU support will replace CMA with host1x specific allocator.

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 https://gitorious.org/linux-tegra-drm/pages/Host1xIntroduction
also contains a short description of the functionality.

The patch set removes responsibility of host1x from tegradrm. At the same time, it moves all drm related infrastructure in drivers/gpu/drm/tegra/host1x.c to drm.c. To replace the host1x central device, host1x creates a dummy device for tegradrm to hang global data to. This is a break in responsibility split of tegradrm taking care of DRM and host1x driver taking care of host1x and clients, but this structure was insisted. I've kept creation of dummy device as a separate patch to illustrate the alternatives. It can be later squashed into other patches.

The patch set adds 2D driver to tegradrm, which uses host1x for communicating with host1x to access sync points and channels. We expect to use the same infrastructure for other host1x clients, so we have kept host1x and tegradrm separate.

The patch set also adds user space API to tegradrm for accessing host1x and 2D.

Arto Merilainen (1):
drm: tegra: Remove redundant host1x

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
ARM: tegra: Add board data and 2D clocks
drm: tegra: Add gr2d device
gpu: host1x: Register DRM dummy device

 arch/arm/mach-tegra/board-dt-tegra20.c      |    1 +
 arch/arm/mach-tegra/board-dt-tegra30.c      |    1 +
 arch/arm/mach-tegra/tegra20_clocks_data.c   |    2 +-
 arch/arm/mach-tegra/tegra30_clocks_data.c   |    1 +
 drivers/gpu/Makefile                        |    1 +
 drivers/gpu/drm/tegra/Kconfig               |    2 +-
 drivers/gpu/drm/tegra/Makefile              |    2 +-
 drivers/gpu/drm/tegra/dc.c                  |   26 +-
 drivers/gpu/drm/tegra/drm.c                 |  433 ++++++++++++++++++-
 drivers/gpu/drm/tegra/drm.h                 |   72 ++--
 drivers/gpu/drm/tegra/fb.c                  |   17 +-
 drivers/gpu/drm/tegra/gr2d.c                |  309 ++++++++++++++
 drivers/gpu/drm/tegra/hdmi.c                |   30 +-
 drivers/gpu/drm/tegra/host1x.c              |  325 --------------
 drivers/gpu/host1x/Kconfig                  |   28 ++
 drivers/gpu/host1x/Makefile                 |   17 +
 drivers/gpu/host1x/cdma.c                   |  475 ++++++++++++++++++++
 drivers/gpu/host1x/cdma.h                   |  107 +++++
 drivers/gpu/host1x/channel.c                |  137 ++++++
 drivers/gpu/host1x/channel.h                |   64 +++
 drivers/gpu/host1x/cma.c                    |  117 +++++
 drivers/gpu/host1x/cma.h                    |   43 ++
 drivers/gpu/host1x/debug.c                  |  207 +++++++++
 drivers/gpu/host1x/debug.h                  |   49 +++
 drivers/gpu/host1x/dev.c                    |  242 +++++++++++
 drivers/gpu/host1x/dev.h                    |  167 ++++++++
 drivers/gpu/host1x/drm.c                    |   51 +++
 drivers/gpu/host1x/drm.h                    |   25 ++
 drivers/gpu/host1x/hw/Makefile              |    6 +
 drivers/gpu/host1x/hw/cdma_hw.c             |  480 +++++++++++++++++++++
 drivers/gpu/host1x/hw/cdma_hw.h             |   37 ++
 drivers/gpu/host1x/hw/channel_hw.c          |  147 +++++++
 drivers/gpu/host1x/hw/debug_hw.c            |  399 +++++++++++++++++
 drivers/gpu/host1x/hw/host1x01.c            |   46 ++
 drivers/gpu/host1x/hw/host1x01.h            |   25 ++
 drivers/gpu/host1x/hw/host1x01_hardware.h   |  150 +++++++
 drivers/gpu/host1x/hw/hw_host1x01_channel.h |   98 +++++
 drivers/gpu/host1x/hw/hw_host1x01_sync.h    |  179 ++++++++
 drivers/gpu/host1x/hw/hw_host1x01_uclass.h  |  130 ++++++
 drivers/gpu/host1x/hw/intr_hw.c             |  178 ++++++++
 drivers/gpu/host1x/hw/syncpt_hw.c           |  157 +++++++
 drivers/gpu/host1x/intr.c                   |  377 ++++++++++++++++
 drivers/gpu/host1x/intr.h                   |  106 +++++
 drivers/gpu/host1x/job.c                    |  618 +++++++++++++++++++++++++++
 drivers/gpu/host1x/memmgr.c                 |  174 ++++++++
 drivers/gpu/host1x/memmgr.h                 |   53 +++
 drivers/gpu/host1x/syncpt.c                 |  398 +++++++++++++++++
 drivers/gpu/host1x/syncpt.h                 |  134 ++++++
 drivers/video/Kconfig                       |    2 +
 include/drm/tegra_drm.h                     |  131 ++++++
 include/linux/host1x.h                      |  217 ++++++++++
 include/trace/events/host1x.h               |  296 +++++++++++++
 52 files changed, 7095 insertions(+), 394 deletions(-)
 create mode 100644 drivers/gpu/drm/tegra/gr2d.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/cma.c
 create mode 100644 drivers/gpu/host1x/cma.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
 create mode 100644 drivers/gpu/host1x/drm.c
 create mode 100644 drivers/gpu/host1x/drm.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/cdma_hw.h
 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/memmgr.c
 create mode 100644 drivers/gpu/host1x/memmgr.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/linux/host1x.h
 create mode 100644 include/trace/events/host1x.h
#30 lore raw
In reply to Terje Bergstrom

Hi Terje,

Here is the second part comments. I admit I still haven't finished reading the codes... really too many codes. :)
Anyway I'll keep doing this when I have free slots.

drivers/gpu/drm/tegra/gr2d.c +0 -0
index a936902..c3ded60 100644
@@ -131,6 +131,14 @@ static int gr2d_submit(struct tegra_drm_context

*context,

                if (err)
                        goto fail;

+ /* We define CMA as an temporary solution in host1x driver.

+                  That's also why we have a CMA kernel config in it.
+                  But seems here, in tegradrm, we hardcode the CMA here.
+                  So what do you do when host1x change to IOMMU?
+                  Do we also need to define a CMA config in tegradrm
driver,
+                  then after host1x changes to IOMMU, we add another IOMMU
+                  config in tegradrm? Or we should invent another more
+                  generic wrapper layer here? */
                cmdbuf.mem = handle_cma_to_host1x(drm, file_priv,
cmdbuf.mem);
                if (!cmdbuf.mem)
                        goto fail;
drivers/gpu/host1x/job.c +0 -0
index cc8ca2f..0867b72 100644
@@ -82,6 +82,26 @@ struct host1x_job *host1x_job_alloc(struct

host1x_channel *ch,

        mem += num_unpins * sizeof(dma_addr_t);
        job->pin_ids = num_unpins ? mem : NULL;

+ /* I think this is a somewhat ugly design.

+          Actually "addr_phys" is consisted by "reloc_addr_phys" and
+          "gather_addr_phys".
+          Why don't we just declare "reloc_addr_phys" and

"gather_addr_phys"?
+ In current design, let's say if one nvhost newbie changes the
order
+ of these 2 blocks of code in function "pin_job_mem":
+
+ for (i = 0; i < job->num_relocs; i++) {

+               struct host1x_reloc *reloc = &job->relocarray[i];
+               job->pin_ids[count] = reloc->target;
+               count++;
+          }
+
+          for (i = 0; i < job->num_gathers; i++) {
+               struct host1x_job_gather *g = &job->gathers[i];
+               job->pin_ids[count] = g->mem_id;
+               count++;
+          }
+
+          Then likely something weird occurs... */
        job->reloc_addr_phys = job->addr_phys;
        job->gather_addr_phys = &job->addr_phys[num_relocs];

@@ -252,6 +272,10 @@ static int do_relocs(struct host1x_job *job,

                        }
                }

+ /* I have question here. Does this mean the address info

+                  which need to be relocated(according to the libdrm codes,
+                  seems this address is "0xDEADBEEF") always staying at the
+                  beginning of a page? */
                __raw_writel(
                        (job->reloc_addr_phys[i] +
                                reloc->target_offset) >> reloc->shift,
@@ -565,6 +589,7 @@ int host1x_job_pin(struct host1x_job *job, struct
platform_device *pdev)
                }
        }

+ /* if (host1x_firewall && !err) { */

        if (host1x_firewall) {
                err = copy_gathers(job, pdev);
                if (err) {
@@ -573,6 +598,9 @@ int host1x_job_pin(struct host1x_job *job, struct
platform_device *pdev)
                }
        }

+/* Rename this label to "out" or something else.
+ Because if everything goes right, the codes under this label also
+ get executed. */
fail:

        wmb();
drivers/gpu/host1x/memmgr.c +0 -0
index f3954f7..bb5763d 100644
@@ -156,6 +156,9 @@ int host1x_memmgr_pin_array_ids(struct

platform_device *dev,

                        count, &unpin_data[pin_count],
                        phys_addr);

+ /* I don't think the current "host1x_cma_pin_array_ids"
+ is able to return a negative value. So this "if" doesn't
+ make sense...*/

                if (cma_count < 0) {
                        /* clean up previous handles */
                        while (pin_count) {

Mark

Quoted 152 lines · Terje Bergstrom

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

The fourth version has only few changes compared to previous version:
* Fixed some sparse warnings
* Fixed host1x Makefile to allow building as module
* Fixed host1x module unload
* Fixed tegradrm unload sequence
* host1x creates DRM dummy device and tegradrm uses it for storing DRM related data.

Some of the issues left open:
* Register definitions still use static inline. There has been a debate about code style versus ability to use compiler type checking and code coverage analysis. There was no conclusion, so I left it as was.
* Uses still CMA helpers. IOMMU support will replace CMA with host1x specific allocator.

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 https://gitorious.org/linux-tegra-drm/pages/Host1xIntroduction
also contains a short description of the functionality.

The patch set removes responsibility of host1x from tegradrm. At the same time, it moves all drm related infrastructure in drivers/gpu/drm/tegra/host1x.c to drm.c. To replace the host1x central device, host1x creates a dummy device for tegradrm to hang global data to. This is a break in responsibility split of tegradrm taking care of DRM and host1x driver taking care of host1x and clients, but this structure was insisted. I've kept creation of dummy device as a separate patch to illustrate the alternatives. It can be later squashed into other patches.

The patch set adds 2D driver to tegradrm, which uses host1x for communicating with host1x to access sync points and channels. We expect to use the same infrastructure for other host1x clients, so we have kept host1x and tegradrm separate.

The patch set also adds user space API to tegradrm for accessing host1x and 2D.

Arto Merilainen (1):
drm: tegra: Remove redundant host1x

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
ARM: tegra: Add board data and 2D clocks
drm: tegra: Add gr2d device
gpu: host1x: Register DRM dummy device

 arch/arm/mach-tegra/board-dt-tegra20.c      |    1 +
 arch/arm/mach-tegra/board-dt-tegra30.c      |    1 +
 arch/arm/mach-tegra/tegra20_clocks_data.c   |    2 +-
 arch/arm/mach-tegra/tegra30_clocks_data.c   |    1 +
 drivers/gpu/Makefile                        |    1 +
 drivers/gpu/drm/tegra/Kconfig               |    2 +-
 drivers/gpu/drm/tegra/Makefile              |    2 +-
 drivers/gpu/drm/tegra/dc.c                  |   26 +-
 drivers/gpu/drm/tegra/drm.c                 |  433 ++++++++++++++++++-
 drivers/gpu/drm/tegra/drm.h                 |   72 ++--
 drivers/gpu/drm/tegra/fb.c                  |   17 +-
 drivers/gpu/drm/tegra/gr2d.c                |  309 ++++++++++++++
 drivers/gpu/drm/tegra/hdmi.c                |   30 +-
 drivers/gpu/drm/tegra/host1x.c              |  325 --------------
 drivers/gpu/host1x/Kconfig                  |   28 ++
 drivers/gpu/host1x/Makefile                 |   17 +
 drivers/gpu/host1x/cdma.c                   |  475 ++++++++++++++++++++
 drivers/gpu/host1x/cdma.h                   |  107 +++++
 drivers/gpu/host1x/channel.c                |  137 ++++++
 drivers/gpu/host1x/channel.h                |   64 +++
 drivers/gpu/host1x/cma.c                    |  117 +++++
 drivers/gpu/host1x/cma.h                    |   43 ++
 drivers/gpu/host1x/debug.c                  |  207 +++++++++
 drivers/gpu/host1x/debug.h                  |   49 +++
 drivers/gpu/host1x/dev.c                    |  242 +++++++++++
 drivers/gpu/host1x/dev.h                    |  167 ++++++++
 drivers/gpu/host1x/drm.c                    |   51 +++
 drivers/gpu/host1x/drm.h                    |   25 ++
 drivers/gpu/host1x/hw/Makefile              |    6 +
 drivers/gpu/host1x/hw/cdma_hw.c             |  480 +++++++++++++++++++++
 drivers/gpu/host1x/hw/cdma_hw.h             |   37 ++
 drivers/gpu/host1x/hw/channel_hw.c          |  147 +++++++
 drivers/gpu/host1x/hw/debug_hw.c            |  399 +++++++++++++++++
 drivers/gpu/host1x/hw/host1x01.c            |   46 ++
 drivers/gpu/host1x/hw/host1x01.h            |   25 ++
 drivers/gpu/host1x/hw/host1x01_hardware.h   |  150 +++++++
 drivers/gpu/host1x/hw/hw_host1x01_channel.h |   98 +++++
 drivers/gpu/host1x/hw/hw_host1x01_sync.h    |  179 ++++++++
 drivers/gpu/host1x/hw/hw_host1x01_uclass.h  |  130 ++++++
 drivers/gpu/host1x/hw/intr_hw.c             |  178 ++++++++
 drivers/gpu/host1x/hw/syncpt_hw.c           |  157 +++++++
 drivers/gpu/host1x/intr.c                   |  377 ++++++++++++++++
 drivers/gpu/host1x/intr.h                   |  106 +++++
 drivers/gpu/host1x/job.c                    |  618 +++++++++++++++++++++++++++
 drivers/gpu/host1x/memmgr.c                 |  174 ++++++++
 drivers/gpu/host1x/memmgr.h                 |   53 +++
 drivers/gpu/host1x/syncpt.c                 |  398 +++++++++++++++++
 drivers/gpu/host1x/syncpt.h                 |  134 ++++++
 drivers/video/Kconfig                       |    2 +
 include/drm/tegra_drm.h                     |  131 ++++++
 include/linux/host1x.h                      |  217 ++++++++++
 include/trace/events/host1x.h               |  296 +++++++++++++
 52 files changed, 7095 insertions(+), 394 deletions(-)
 create mode 100644 drivers/gpu/drm/tegra/gr2d.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/cma.c
 create mode 100644 drivers/gpu/host1x/cma.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
 create mode 100644 drivers/gpu/host1x/drm.c
 create mode 100644 drivers/gpu/host1x/drm.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/cdma_hw.h
 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/memmgr.c
 create mode 100644 drivers/gpu/host1x/memmgr.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/linux/host1x.h
 create mode 100644 include/trace/events/host1x.h
#15 lore raw

Re: [PATCHv4 5/8] drm: tegra: Remove redundant host1x

In reply to Stephen Warren
Quoted 14 lines · Stephen Warren
Quoted 8 lines · Terje Bergström
Quoted 6 lines · Thierry Reding

drivers/gpu/drm/tegra/drm.c static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp) · line 232

Quoted 3 lines · Terje Bergstrom
drivers/gpu/drm/tegra/drm.c +3 -0
+static struct platform_driver tegra_drm_platform_driver = {
+	.driver = {
+		.name = "tegradrm",

This should be "tegra-drm" to match the module name.

Quoted 4 lines

We've actually created two problems.

First is that the device name should match driver name which should match module name. But host1x doesn't know the module name of tegradrm.

Quoted 7 lines

There's no hard requirement for the device/driver name to match the module name. It's good thing to do, but nothing will blow up if it don't (modules can use MODULE_ALIAS() to declare which drivers they expose).

But, what's the problem with host1x knowing the driver name; the host1x driver and tegradrm driver are both part of the same code-base, so this seems trivial to achieve.

Indeed. If we define the name to match the tegra-drm module name, then just changing the above line is fine. This doesn't need to be automatic. Making sure that both strings match in both drivers is enough.

Quoted 11 lines
Quoted 2 lines

Second problem is that host1x driver creates tegradrm device even if tegradrm isn't loaded to system.

That's fine. If there's no driver, the device simply won't be probe()d. That's just like a device node existing in device tree, but the driver for it not being enabled in the kernel, or the relevant module not being inserted.

Quoted 1 line

These mean that the device has to be created in tegra-drm module to have

I definitely disagree here.

Instead of going over this back and forth, I've decided to rewrite this patch from scratch the way I think it should be done. Maybe that'll make things clearer. I haven't tested it on real hardware yet because I don't have access over the holidays, but I'll post the patch once I've verified that it actually works. The code is based on patches 1-4 of this series and is meant to replace patch 5.

Thierry

#16 lore raw

Re: [PATCHv4 5/8] drm: tegra: Remove redundant host1x

Quoted 6 lines · Thierry Reding

Instead of going over this back and forth, I've decided to rewrite this patch from scratch the way I think it should be done. Maybe that'll make things clearer. I haven't tested it on real hardware yet because I don't have access over the holidays, but I'll post the patch once I've verified that it actually works. The code is based on patches 1-4 of this series and is meant to replace patch 5.

I'm still not happy that host1x needs to know about drm. That's just a wrong dependency, and wrong dependencies always end up biting back. We need to figure out solution that satisfies both mine and your requirements and reduce complexity.

DC/HDMI/GR2D probes are using the global data only for managing the lists "drm_clients" and "clients". "clients" list is only required after tegra_drm_load(). "drm_clients" is required to establish driver load order.

With dummy device, we can determine the registration (and probe) order. tegra-drm can register the drivers for DC/HDMI/GR2D devices first, and as last the device and driver for tegra-drm.

tegra-drm probe will allocate the global data, enumerate all drivers and add them to the clients list. If one driver is not initialized, it'll return with -EPROBE_DEFER and will be called again later. When all this is successful, it'll call drm_platform_init().

The advantages:
* No management of drm_clients list
* No mucking with drvdata
* host1x doesn't need to know about drm
* The global data is allocated and deallocated by tegra-drm probe and
remove, and accessed only via drm_device->dev_private
* Much less code

Something like the attached patch - not tested, as I don't have access to hw now, but it shows the idea. It's based on patches 1-5 in the series, and could replace patch 5.

Terje

Quoted 1 line

From a97d475d65e68ce37c345924171dc57c5e7729ee Mon Sep 17 00:00:00 2001

From: Terje Bergstrom <[email protected]>
Date: Sat, 29 Dec 2012 11:43:54 +0200
Subject: [PATCH] drm: tegra: Postpone usage of global data

Change-Id Ibfd1d4eeb267ac185de4508a1547fb009b80e93a
---
 drivers/gpu/drm/tegra/dc.c   |   18 -----
 drivers/gpu/drm/tegra/drm.c  |  151 +++++++++++++-----------------------------
 drivers/gpu/drm/tegra/drm.h  |    1 -
 drivers/gpu/drm/tegra/gr2d.c |    7 --
 drivers/gpu/drm/tegra/hdmi.c |   18 -----
 5 files changed, 47 insertions(+), 148 deletions(-)
drivers/gpu/drm/tegra/dc.c +0 -18
index 24bcd06..73056b7 100644
@@ -740,7 +740,6 @@ static int tegra_dc_probe(struct platform_device *pdev)
 	struct resource *regs;
 	struct tegra_dc *dc;
 	int err;
-	struct tegradrm *tegradrm = platform_get_drvdata(pdev);
 
 	dc = devm_kzalloc(&pdev->dev, sizeof(*dc), GFP_KERNEL);
 	if (!dc)
@@ -780,7 +779,6 @@ static int tegra_dc_probe(struct platform_device *pdev)
 	INIT_LIST_HEAD(&dc->client.list);
 	dc->client.ops = &dc_client_ops;
 	dc->client.dev = &pdev->dev;
-	dc->client.tegradrm = tegradrm;
 
 	err = tegra_dc_rgb_probe(dc);
 	if (err < 0 && err != -ENODEV) {
@@ -788,13 +786,6 @@ static int tegra_dc_probe(struct platform_device *pdev)
 		return err;
 	}
 
-	err = tegra_drm_register_client(tegradrm, &dc->client);
-	if (err < 0) {
-		dev_err(&pdev->dev, "failed to register tegra drm client: %d\n",
-			err);
-		return err;
-	}
-
 	platform_set_drvdata(pdev, dc);
 
 	return 0;
@@ -803,15 +794,6 @@ static int tegra_dc_probe(struct platform_device *pdev)
 static int tegra_dc_remove(struct platform_device *pdev)
 {
 	struct tegra_dc *dc = platform_get_drvdata(pdev);
-	int err;
-
-	err = tegra_drm_unregister_client(dc->client.tegradrm,
-			&dc->client);
-	if (err < 0) {
-		dev_err(&pdev->dev, "failed to unregister tegra_drm client: %d\n",
-			err);
-		return err;
-	}
 
 	clk_disable_unprepare(dc->clk);
 
drivers/gpu/drm/tegra/drm.c +47 -104

226 lines not on this page · raw message

drivers/gpu/drm/tegra/drm.h +0 -1
index 06100d7..34ec9d2 100644
@@ -75,7 +75,6 @@ tegra_drm_fpriv(struct drm_file *file_priv)
 }
 
 struct tegra_drm_client {
-	struct tegradrm *tegradrm;
 	struct device *dev;
 
 	const struct tegra_drm_client_ops *ops;
drivers/gpu/drm/tegra/gr2d.c +0 -7
index 8865099..f39fef2 100644
@@ -247,7 +247,6 @@ static int __devinit gr2d_probe(struct platform_device *dev)
 {
 	int err;
 	struct gr2d *gr2d = NULL;
-	struct tegradrm *tegradrm = platform_get_drvdata(dev);
 
 	gr2d = devm_kzalloc(&dev->dev, sizeof(*gr2d), GFP_KERNEL);
 	if (!gr2d)
@@ -278,11 +277,6 @@ static int __devinit gr2d_probe(struct platform_device *dev)
 	gr2d->client.ops = &gr2d_client_ops;
 	gr2d->client.dev = &dev->dev;
 	gr2d->client.class = NV_GRAPHICS_2D_CLASS_ID;
-	gr2d->client.tegradrm = tegradrm;
-
-	err = tegra_drm_register_client(tegradrm, &gr2d->client);
-	if (err)
-		return err;
 
 	platform_set_drvdata(dev, gr2d);
 	return 0;
@@ -292,7 +286,6 @@ static int __exit gr2d_remove(struct platform_device *dev)
 {
 	struct gr2d *gr2d = platform_get_drvdata(dev);
 	host1x_syncpt_free(gr2d->syncpt);
-	tegra_drm_unregister_client(gr2d->client.tegradrm, &gr2d->client);
 	return 0;
 }
 
drivers/gpu/drm/tegra/hdmi.c +0 -18
index fce3e66..d987510 100644
@@ -1214,7 +1214,6 @@ static int tegra_hdmi_probe(struct platform_device *pdev)
 	struct tegra_hdmi *hdmi;
 	struct resource *regs;
 	int err;
-	struct tegradrm *tegradrm = platform_get_drvdata(pdev);
 
 	hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
 	if (!hdmi)
@@ -1285,14 +1284,6 @@ static int tegra_hdmi_probe(struct platform_device *pdev)
 	hdmi->client.ops = &hdmi_client_ops;
 	INIT_LIST_HEAD(&hdmi->client.list);
 	hdmi->client.dev = &pdev->dev;
-	hdmi->client.tegradrm = tegradrm;
-
-	err = tegra_drm_register_client(tegradrm, &hdmi->client);
-	if (err < 0) {
-		dev_err(&pdev->dev, "failed to register tegra drm client: %d\n",
-			err);
-		return err;
-	}
 
 	platform_set_drvdata(pdev, hdmi);
 
@@ -1302,15 +1293,6 @@ static int tegra_hdmi_probe(struct platform_device *pdev)
 static int tegra_hdmi_remove(struct platform_device *pdev)
 {
 	struct tegra_hdmi *hdmi = platform_get_drvdata(pdev);
-	int err;
-
-	err = tegra_drm_unregister_client(hdmi->client.tegradrm,
-			&hdmi->client);
-	if (err < 0) {
-		dev_err(&pdev->dev, "failed to unregister tegra drm client: %d\n",
-			err);
-		return err;
-	}
 
 	clk_unprepare(hdmi->clk_parent);
 	clk_unprepare(hdmi->clk);
Signature · 1 line
1.7.9.5
#6 lore raw

Re: [PATCHv4 3/8] gpu: host1x: Add channel support

In reply to Terje Bergstrom

Just one minor issue. Check below.

Quoted 6 lines · Terje Bergstrom

Add support for host1x client modules, and host1x channels to submit work to the clients. The work is submitted in GEM CMA buffers, so this patch adds support for them.

---

[...]

Quoted 19 lines
drivers/gpu/host1x/cdma.c new file +19 -0
+/*
+ * Begin a cdma submit
+ */
+int host1x_cdma_begin(struct host1x_cdma *cdma, struct host1x_job *job)
+{
+	struct host1x *host1x = cdma_to_host1x(cdma);
+
+	mutex_lock(&cdma->lock);
+
+	if (job->timeout) {
+		/* init state on first submit with timeout value */
+		if (!cdma->timeout.initialized) {
+			int err;
+			err = host1x->cdma_op.timeout_init(cdma,
+					job->syncpt_id);
+			if (err) {
+				mutex_unlock(&cdma->lock);
+				return err;
+			}

drivers/gpu/host1x/cdma.c line 368

Quoted 10 lines
drivers/gpu/host1x/cdma.c new file +10 -0
+		}
+	}
+	if (!cdma->running)
+		host1x->cdma_op.start(cdma);
+
+	cdma->slots_free = 0;
+	cdma->slots_used = 0;
+	cdma->first_get = host1x->cdma_pb_op.putptr(&cdma->push_buffer);
+
+	trace_host1x_cdma_begin(job->ch->dev->name);

Seems missing "mutex_unlock(&cdma->lock);" here.

Quoted 2 lines
(quoted diff) +2 -0
+	return 0;
+}

[...]

Quoted 5 lines

+
#endif /* _TRACE_HOST1X_H */

/* This part must be outside protection */

#28 lore raw
In reply to Mark Zhang

drivers/gpu/drm/tegra/gr2d.c static int __devinit gr2d_probe(struct · line 254

Quoted 13 lines · Mark Zhang
drivers/gpu/drm/tegra/gr2d.c +4 -0
index a936902..28954b3 100644
@@ -247,6 +247,10 @@ static int __devinit gr2d_probe(struct
 platform_device *dev)
 {
        int err;
        struct gr2d *gr2d = NULL;
+       /* Cause drm_device is created in host1x driver. So
+          if host1x drivers loads after tegradrm, then in this
+          gr2d_probe function, this "drm_device" will be NULL.
+          How can we handle this? Defer driver probe? */

I will push a new proposal about how the devices & drivers get probed.

drivers/gpu/drm/tegra/gr2d.c static int __devinit gr2d_probe(struct · line 285

Quoted 13 lines
drivers/gpu/drm/tegra/gr2d.c +0 -0
        struct platform_device *drm_device =
                host1x_drm_device(to_platform_device(dev->dev.parent));
        struct tegradrm *tegradrm = platform_get_drvdata(drm_device);
drivers/gpu/drm/tegra/gr2d.c +5 -0
@@ -273,6 +277,11 @@ static int __devinit gr2d_probe(struct
 platform_device *dev)
 
        gr2d->syncpt = host1x_syncpt_alloc(dev, 0);
        if (!gr2d->syncpt) {
+               /* Do we really need this?
+                  After "host1x_channel_alloc", the refcount of this
+                  channel is 0. So calling host1x_channel_put here will
+                  make the refcount going to negative.
+                  I suppose we should call "host1x_free_channel" here. */

True. I need to also export host1x_channel_free (I will change the name, too).

drivers/gpu/drm/tegra/gr2d.c static int __devinit gr2d_probe(struct · line 297

Quoted 9 lines
drivers/gpu/drm/tegra/gr2d.c +0 -0
                host1x_channel_put(gr2d->channel);
                return -ENOMEM;
        }
drivers/gpu/drm/tegra/gr2d.c +1 -0
@@ -284,6 +293,7 @@ static int __devinit gr2d_probe(struct
 platform_device *dev)
 
        err = tegra_drm_register_client(tegradrm, &gr2d->client);
        if (err)
+               /* Add "host1x_free_channel" */

Will do.

Quoted 8 lines
drivers/gpu/drm/tegra/gr2d.c +0 -0
                return err;
 
        platform_set_drvdata(dev, gr2d);
drivers/gpu/host1x/channel.c +0 -0
index 3705cae..ed83b9e 100644

drivers/gpu/host1x/channel.c struct host1x_channel *host1x_channel_alloc(struct · line 101

Quoted 7 lines
drivers/gpu/host1x/channel.c +3 -0
@@ -95,6 +95,9 @@ struct host1x_channel *host1x_channel_alloc(struct
 platform_device *pdev)
        int max_channels = host1x->info.nb_channels;
        int err;
 
+       /* Is it necessary to add mutex protection here?
+          I'm just wondering in a smp system, multiple host1x clients
+          may try to alloc their channels simultaneously... */

I'll add locking.

Quoted 8 lines
drivers/gpu/host1x/channel.c +0 -0
        if (chindex > max_channels)
                return NULL;
drivers/gpu/host1x/debug.c +0 -0
index 86d5c70..f2bd5aa 100644

drivers/gpu/host1x/debug.c static const struct file_operations · line 172

Quoted 9 lines
drivers/gpu/host1x/debug.c +4 -0
@@ -164,6 +164,10 @@ static const struct file_operations
 host1x_debug_fops = {
 
 void host1x_debug_init(struct host1x *host1x)
 {
+       /* I think it's better to set this directory name the same with
+          the driver's name -- defined in dev.c:
+          #define DRIVER_NAME  "tegra-host1x"
+          */
        struct dentry *de = debugfs_create_dir("tegra_host", NULL);

Will do.

drivers/gpu/host1x/dev.c line 42

Quoted 12 lines
drivers/gpu/host1x/debug.c +0 -0
        if (!de)
drivers/gpu/host1x/dev.c +1 -0
index 07e8813..01ed10d 100644
@@ -38,6 +38,7 @@
 
 struct host1x *host1x;
 
+/* Called by drm unlocked ioctl function. So do we need a lock here? */
 void host1x_syncpt_incr_byid(u32 id)

No, host1x_syncpt_incr_byid is SMP safe.

drivers/gpu/host1x/dev.c u32 host1x_syncpt_read_byid(u32 id) · line 57

Quoted 8 lines
drivers/gpu/host1x/dev.c +1 -0
 {
        struct host1x_syncpt *sp = host1x->syncpt + id;
@@ -52,6 +53,7 @@ u32 host1x_syncpt_read_byid(u32 id)
 }
 EXPORT_SYMBOL(host1x_syncpt_read_byid);
 
+/* Called by drm unlocked ioctl function. So do we need a lock here? */
 int host1x_syncpt_wait_byid(u32 id, u32 thresh, long timeout, u32 *value)

Same here, SMP safe.

drivers/gpu/host1x/dev.c static int host1x_probe(struct platform_device *dev) · line 170

Quoted 11 lines
drivers/gpu/host1x/dev.c +2 -0
 {
        struct host1x_syncpt *sp = host1x->syncpt + id;
@@ -161,6 +163,8 @@ static int host1x_probe(struct platform_device *dev)
 
        err = host1x_alloc_resources(host);
        if (err) {
+               /* We don't have chip_ops right now, so here the
+                  error message is somewhat improper */
                dev_err(&dev->dev, "failed to init chip support\n");
                goto fail;
        }

Actually, alloc_resources only allocates intr->syncpt, so I the code to host1x_intr_init().

drivers/gpu/host1x/dev.c static int host1x_probe(struct platform_device *dev) · line 190

Quoted 13 lines
drivers/gpu/host1x/dev.c +8 -0
@@ -175,6 +179,14 @@ static int host1x_probe(struct platform_device *dev)
        if (!host->syncpt)
                goto fail;
 
+       /* I suggest create a dedicate function for initializing nop sp.
+          First this "_host1x_syncpt_alloc" looks like an internal/static
+          function.
+          Then actually "host1x_syncpt_alloc" & "_host1x_syncpt_alloc" all
+          serve host1x client(e.g: gr2d) so it's not suitable to use them
+          for nop sp.
+          Just create a wrapper function to call _host1x_syncpt_alloc is OK.
+          This will make the code more readable. */
        host->nop_sp = _host1x_syncpt_alloc(host, NULL, 0);

_host1x_syncpt_alloc is an internal function, not exported. host1x_syncpt_alloc is exported. I think it's even better if I just move allocation of nop_sp to happen in host1x_syncpt_init.

Quoted 13 lines
drivers/gpu/host1x/dev.c +1 -0
        if (!host->nop_sp)
                goto fail;
@@ -191,6 +203,7 @@ static int host1x_probe(struct platform_device *dev)
        }
 
        err = clk_prepare_enable(host->clk);
+       /* Add a dev_err here */
        if (err < 0)
                goto fail;
 
@@ -209,9 +222,12 @@ static int host1x_probe(struct platform_device *dev)
        return 0;
 

drivers/gpu/host1x/dev.c static int host1x_probe(struct platform_device *dev) · line 232

Quoted 10 lines
drivers/gpu/host1x/dev.c +4 -1
 fail:
+       /* host1x->syncpt isn't released here... */
+       /* host1x->intr isn't release here... */
+       /* Remove debugfs stuffs? */
        host1x_syncpt_free(host->nop_sp);
        host1x_unregister_drm_device(host);
-       kfree(host);
+       kfree(host); /* not necessary*/
        return err;
 }

I added a few other dev_err()'s and checked the deinitialization on error, too.

drivers/gpu/host1x/dev.c static int __exit host1x_remove(struct · line 244

Quoted 9 lines
drivers/gpu/host1x/dev.c +1 -0
@@ -222,6 +238,7 @@ static int __exit host1x_remove(struct
 platform_device *dev)
        host1x_syncpt_deinit(host);
        host1x_unregister_drm_device(host);
        clk_disable_unprepare(host->clk);
+       /* Remove debugfs stuffs? */
        return 0;
 }

Will do.

Quoted 33 lines
drivers/gpu/host1x/dev.h +7 -0
index 05f8544..58f4c71 100644
@@ -36,6 +36,7 @@ struct platform_device;
 struct output;
 
 struct host1x_channel_ops {
+       /* Seems no one uses this member. Remove it. */
        const char *soc_name;
        int (*init)(struct host1x_channel *,
                    struct host1x *,
@@ -125,12 +126,18 @@ struct host1x {
        struct host1x_syncpt *syncpt;
        struct host1x_intr intr;
        struct platform_device *dev;
+
+       /* Seems no one uses this. Remove it. */
        atomic_t clientid;
        struct host1x_device_info info;
        struct clk *clk;
 
+       /* Put some comments for this member.
+          For guys who're not familiar with nop sp, I think they'll
+          definitely get confused about this. */
        struct host1x_syncpt *nop_sp;
 
+       /* Seems no one uses this member. Remove it. */
        const char *soc_name;
        struct host1x_channel_ops channel_op;
        struct host1x_cdma_ops cdma_op;

drivers/gpu/host1x/dev.h struct host1x { · line 153

Quoted 7 lines
drivers/gpu/host1x/dev.h +1 -0
@@ -140,6 +147,7 @@ struct host1x {
        struct host1x_intr_ops intr_op;
 
        struct host1x_channel chlist;
+
        int allocated_channels;
 
        struct dentry *debugfs;

I removed the extra entries, and I added a short comment about nop_sp.

Quoted 8 lines
drivers/gpu/host1x/intr.c +0 -0
index efcb9be..e112001 100644
@@ -329,8 +329,13 @@ void host1x_intr_deinit(struct host1x_intr *intr)
 void host1x_intr_start(struct host1x_intr *intr, u32 hz)
 {
        struct host1x *host1x = intr_to_host1x(intr);

drivers/gpu/host1x/intr.c void host1x_intr_deinit(struct host1x_intr *intr) · line 341

Quoted 10 lines
drivers/gpu/host1x/intr.c +5 -0
+
+       /* Why we need to lock here? Seems like this function is
+          called by host1x's probe only. */
        mutex_lock(&intr->mutex);
 
+       /* "init_host_sync" has already been called in function
+          host1x_intr_init. Remove this line. */
        host1x->intr_op.init_host_sync(intr);
        host1x->intr_op.set_host_clocks_per_usec(intr,
                        DIV_ROUND_UP(hz, 1000000));

In future, we'll call host1x_intr_start() whenever host1x is turned on. Thus we need locking.

init_host_sync() should actually be called from host1x_intr_start(), not _init().

Quoted 13 lines
drivers/gpu/host1x/syncpt.c +2 -0
index 07cbca5..9a234ad 100644
@@ -309,6 +309,8 @@ struct host1x_syncpt *host1x_syncpt_init(struct
 host1x *host)
        struct host1x_syncpt *syncpt, *sp;
        int i;
 
+       /* Consider devm_kzalloc here. Then you can forget the release
+          stuffs about this "syncpt". */
        syncpt = sp = kzalloc(sizeof(struct host1x_syncpt) * host->info.nb_pts,
                GFP_KERNEL);
Quoted 1 line

if (!syncpt)

Will do.

Thanks!

Terje

#5 lore raw

Re: [PATCHv4 3/8] gpu: host1x: Add channel support

In reply to Steven Rostedt
Quoted 29 lines · Steven Rostedt
Quoted 28 lines · Terje Bergstrom
include/trace/events/host1x.h +28 -0
+TRACE_EVENT(host1x_cdma_begin,
+	TP_PROTO(const char *name),
+
+	TP_ARGS(name),
+
+	TP_STRUCT__entry(
+		__field(const char *, name)
+	),
+
+	TP_fast_assign(
+		__entry->name = name;
+	),
+
+	TP_printk("name=%s",
+		__entry->name)
+);
+
+TRACE_EVENT(host1x_cdma_end,
+	TP_PROTO(const char *name),
+
+	TP_ARGS(name),
+
+	TP_STRUCT__entry(
+		__field(const char *, name)
+	),
+
+	TP_fast_assign(
+		__entry->name = name;
Quoted 8 lines

include/trace/events/host1x.h DECLARE_EVENT_CLASS(host1x, · line 65

Quoted 5 lines
include/trace/events/host1x.h +5 -0
+	),
+
+	TP_printk("name=%s",
+		__entry->name)
+);

The above two should be combined into a DECLARE_EVENT_CLASS() and DEFINE_EVENT()s. Saves text and data space that way.

Will do.

(...)

Quoted 2 lines

If you can combine any of these others into DECLARE_EVENT_CLASS() and DEFINE_EVENT()s, please do.

I didn't find others with same parameters.

Thanks!

Terje

#7 lore raw

Re: [PATCHv4 3/8] gpu: host1x: Add channel support

In reply to Mark Zhang
Quoted 31 lines · Mark Zhang
Quoted 6 lines · Terje Bergstrom

Add support for host1x client modules, and host1x channels to submit work to the clients. The work is submitted in GEM CMA buffers, so this patch adds support for them.

---

[...]

Quoted 23 lines
drivers/gpu/host1x/cdma.c new file +23 -0
+/*
+ * Begin a cdma submit
+ */
+int host1x_cdma_begin(struct host1x_cdma *cdma, struct host1x_job *job)
+{
+	struct host1x *host1x = cdma_to_host1x(cdma);
+
+	mutex_lock(&cdma->lock);
+
+	if (job->timeout) {
+		/* init state on first submit with timeout value */
+		if (!cdma->timeout.initialized) {
+			int err;
+			err = host1x->cdma_op.timeout_init(cdma,
+					job->syncpt_id);
+			if (err) {
+				mutex_unlock(&cdma->lock);
+				return err;
+			}
+		}
+	}
+	if (!cdma->running)
+		host1x->cdma_op.start(cdma);
Quoted 8 lines

drivers/gpu/host1x/cdma.c line 368

Quoted 6 lines
drivers/gpu/host1x/cdma.c new file +6 -0
+
+	cdma->slots_free = 0;
+	cdma->slots_used = 0;
+	cdma->first_get = host1x->cdma_pb_op.putptr(&cdma->push_buffer);
+
+	trace_host1x_cdma_begin(job->ch->dev->name);

Seems missing "mutex_unlock(&cdma->lock);" here.

That's intentional. Writing a job to channel is atomic, so lock is taken from host1x_cdma_begin() until host1x_cdma_end().

Terje

#8 lore raw

Re: [PATCHv4 3/8] gpu: host1x: Add channel support

Quoted 41 lines · Terje Bergström
Quoted 31 lines · Mark Zhang
Quoted 6 lines · Terje Bergstrom

Add support for host1x client modules, and host1x channels to submit work to the clients. The work is submitted in GEM CMA buffers, so this patch adds support for them.

---

[...]

Quoted 23 lines
drivers/gpu/host1x/cdma.c new file +23 -0
+/*
+ * Begin a cdma submit
+ */
+int host1x_cdma_begin(struct host1x_cdma *cdma, struct host1x_job *job)
+{
+	struct host1x *host1x = cdma_to_host1x(cdma);
+
+	mutex_lock(&cdma->lock);
+
+	if (job->timeout) {
+		/* init state on first submit with timeout value */
+		if (!cdma->timeout.initialized) {
+			int err;
+			err = host1x->cdma_op.timeout_init(cdma,
+					job->syncpt_id);
+			if (err) {
+				mutex_unlock(&cdma->lock);
+				return err;
+			}
+		}
+	}
+	if (!cdma->running)
+		host1x->cdma_op.start(cdma);
Quoted 8 lines

drivers/gpu/host1x/cdma.c line 368

Quoted 6 lines
drivers/gpu/host1x/cdma.c new file +6 -0
+
+	cdma->slots_free = 0;
+	cdma->slots_used = 0;
+	cdma->first_get = host1x->cdma_pb_op.putptr(&cdma->push_buffer);
+
+	trace_host1x_cdma_begin(job->ch->dev->name);

Seems missing "mutex_unlock(&cdma->lock);" here.

Quoted 3 lines

That's intentional. Writing a job to channel is atomic, so lock is taken from host1x_cdma_begin() until host1x_cdma_end().

Okay. So can we consider that lock and unlock this mutex in the function which calls host1x_cdma_begin and host1x_cdma_end, that means, in current implementation, function "channel_submit"?

Mark

Quoted 2 lines

Terje

#31 lore raw
In reply to Mark Zhang
Quoted 19 lines · Mark Zhang
drivers/gpu/drm/tegra/gr2d.c +8 -0
index a936902..c3ded60 100644
@@ -131,6 +131,14 @@ static int gr2d_submit(struct tegra_drm_context
 *context,
                if (err)
                        goto fail;
 
+               /* We define CMA as an temporary solution in host1x driver.
+                  That's also why we have a CMA kernel config in it.
+                  But seems here, in tegradrm, we hardcode the CMA here.
+                  So what do you do when host1x change to IOMMU?
+                  Do we also need to define a CMA config in tegradrm
 driver,
+                  then after host1x changes to IOMMU, we add another IOMMU
+                  config in tegradrm? Or we should invent another more
+                  generic wrapper layer here? */
                cmdbuf.mem = handle_cma_to_host1x(drm, file_priv,
Quoted 1 line

cmdbuf.mem);

Lucas is working on host1x allocator, so let's defer this comment until we have Lucas' code.

Quoted 21 lines
drivers/gpu/host1x/job.c +4 -0
index cc8ca2f..0867b72 100644
@@ -82,6 +82,26 @@ struct host1x_job *host1x_job_alloc(struct
 host1x_channel *ch,
        mem += num_unpins * sizeof(dma_addr_t);
        job->pin_ids = num_unpins ? mem : NULL;
 
+       /* I think this is a somewhat ugly design.
+          Actually "addr_phys" is consisted by "reloc_addr_phys" and
+          "gather_addr_phys".
+          Why don't we just declare "reloc_addr_phys" and

"gather_addr_phys"?
+ In current design, let's say if one nvhost newbie changes the
order

drivers/gpu/host1x/job.c +5 -0
+          of these 2 blocks of code in function "pin_job_mem":
+
+          for (i = 0; i < job->num_relocs; i++) {
+               struct host1x_reloc *reloc = &job->relocarray[i];
+               job->pin_ids[count] = reloc->target;

drivers/gpu/host1x/job.c

Quoted 10 lines
drivers/gpu/host1x/job.c +10 -0
+               count++;
+          }
+
+          for (i = 0; i < job->num_gathers; i++) {
+               struct host1x_job_gather *g = &job->gathers[i];
+               job->pin_ids[count] = g->mem_id;
+               count++;
+          }
+
+          Then likely something weird occurs... */

We do this because this way we can implement batch pinning of memory handles. This way we can decrease memory handle management a lot as we need to do locking only once per submit.

Decreasing memory management overhead is really important, because in complex graphics cases, there are might be a hundreds of buffer references per submit, and several submits per frame. Any extra overhead relates directly to reduced performance.

Quoted 4 lines
        job->reloc_addr_phys = job->addr_phys;
        job->gather_addr_phys = &job->addr_phys[num_relocs];

drivers/gpu/host1x/job.c static int do_relocs(struct host1x_job *job, · line 281

Quoted 10 lines
drivers/gpu/host1x/job.c +4 -0
@@ -252,6 +272,10 @@ static int do_relocs(struct host1x_job *job,
                        }
                }
 
+               /* I have question here. Does this mean the address info
+                  which need to be relocated(according to the libdrm codes,
+                  seems this address is "0xDEADBEEF") always staying at the
+                  beginning of a page? */
                __raw_writel(
                        (job->reloc_addr_phys[i] +
                                reloc->target_offset) >> reloc->shift,

No - the slot can be anywhere. That's why we have cmdbuf_offset in the reloc struct.

Quoted 9 lines
drivers/gpu/host1x/job.c +1 -0
@@ -565,6 +589,7 @@ int host1x_job_pin(struct host1x_job *job, struct
 platform_device *pdev)
                }
        }
 
+       /* if (host1x_firewall && !err) { */
        if (host1x_firewall) {
                err = copy_gathers(job, pdev);
                if (err) {

Will add.

drivers/gpu/host1x/job.c int host1x_job_pin(struct host1x_job *job, struct · line 606

Quoted 10 lines
drivers/gpu/host1x/job.c +3 -0
@@ -573,6 +598,9 @@ int host1x_job_pin(struct host1x_job *job, struct
 platform_device *pdev)
                }
        }
 
+/* Rename this label to "out" or something else.
+   Because if everything goes right, the codes under this label also
+   get executed. */
 fail:
        wmb();

Will do.

Quoted 15 lines
drivers/gpu/host1x/memmgr.c +3 -0
index f3954f7..bb5763d 100644
@@ -156,6 +156,9 @@ int host1x_memmgr_pin_array_ids(struct
 platform_device *dev,
                        count, &unpin_data[pin_count],
                        phys_addr);
 
+               /* I don't think the current "host1x_cma_pin_array_ids"
+                  is able to return a negative value. So this "if" doesn't
+                  make sense...*/
                if (cma_count < 0) {
                        /* clean up previous handles */
Quoted 1 line
                        while (pin_count) {

It should return negative in case of error.

Terje

#9 lore raw

Re: [PATCHv4 3/8] gpu: host1x: Add channel support

In reply to Mark Zhang
Quoted 8 lines · Mark Zhang
Quoted 3 lines · Terje Bergström

That's intentional. Writing a job to channel is atomic, so lock is taken from host1x_cdma_begin() until host1x_cdma_end().

Okay. So can we consider that lock and unlock this mutex in the function which calls host1x_cdma_begin and host1x_cdma_end, that means, in current implementation, function "channel_submit"?

Yes, exactly.

Terje

#29 lore raw
In reply to Terje Bergström
Quoted 1 line · Terje Bergström

On 26.12.2012 11:42, Mark Zhang wrote:

[...]

Quoted 9 lines
Quoted 9 lines

        if (!de)
drivers/gpu/host1x/dev.c +0 -0
index 07e8813..01ed10d 100644
@@ -38,6 +38,7 @@
 
Quoted 6 lines

drivers/gpu/host1x/dev.c line 42

Quoted 4 lines
drivers/gpu/host1x/dev.c +1 -0
 struct host1x *host1x;
 
+/* Called by drm unlocked ioctl function. So do we need a lock here? */
 void host1x_syncpt_incr_byid(u32 id)

No, host1x_syncpt_incr_byid is SMP safe.

Correct. Lock is unnecessary.

Quoted 31 lines

drivers/gpu/host1x/dev.c u32 host1x_syncpt_read_byid(u32 id) · line 57

Quoted 9 lines
drivers/gpu/host1x/dev.c +1 -0
 {
        struct host1x_syncpt *sp = host1x->syncpt + id;
@@ -52,6 +53,7 @@ u32 host1x_syncpt_read_byid(u32 id)
 }
 EXPORT_SYMBOL(host1x_syncpt_read_byid);
 
+/* Called by drm unlocked ioctl function. So do we need a lock here? */
 int host1x_syncpt_wait_byid(u32 id, u32 thresh, long timeout, u32 *value)

Same here, SMP safe.

drivers/gpu/host1x/dev.c static int host1x_probe(struct platform_device *dev) · line 170

Quoted 11 lines
drivers/gpu/host1x/dev.c +2 -0
 {
        struct host1x_syncpt *sp = host1x->syncpt + id;
@@ -161,6 +163,8 @@ static int host1x_probe(struct platform_device *dev)
 
        err = host1x_alloc_resources(host);
        if (err) {
+               /* We don't have chip_ops right now, so here the
+                  error message is somewhat improper */
                dev_err(&dev->dev, "failed to init chip support\n");
                goto fail;
        }

Actually, alloc_resources only allocates intr->syncpt, so I the code to host1x_intr_init().

Quoted 4 lines
drivers/gpu/host1x/dev.c +0 -0
@@ -175,6 +179,14 @@ static int host1x_probe(struct platform_device *dev)
        if (!host->syncpt)
                goto fail;
 
Quoted 14 lines

drivers/gpu/host1x/dev.c static int host1x_probe(struct platform_device *dev) · line 190

Quoted 9 lines
drivers/gpu/host1x/dev.c +8 -0
+       /* I suggest create a dedicate function for initializing nop sp.
+          First this "_host1x_syncpt_alloc" looks like an internal/static
+          function.
+          Then actually "host1x_syncpt_alloc" & "_host1x_syncpt_alloc" all
+          serve host1x client(e.g: gr2d) so it's not suitable to use them
+          for nop sp.
+          Just create a wrapper function to call _host1x_syncpt_alloc is OK.
+          This will make the code more readable. */
        host->nop_sp = _host1x_syncpt_alloc(host, NULL, 0);

_host1x_syncpt_alloc is an internal function, not exported. host1x_syncpt_alloc is exported. I think it's even better if I just move allocation of nop_sp to happen in host1x_syncpt_init.

Agree.

Quoted 2 lines
Quoted 2 lines
drivers/gpu/host1x/dev.c +0 -0
        if (!host->nop_sp)
                goto fail;

[...]

Quoted 23 lines
Quoted 9 lines
drivers/gpu/host1x/intr.c +0 -0
index efcb9be..e112001 100644
@@ -329,8 +329,13 @@ void host1x_intr_deinit(struct host1x_intr *intr)
 void host1x_intr_start(struct host1x_intr *intr, u32 hz)
 {
        struct host1x *host1x = intr_to_host1x(intr);

drivers/gpu/host1x/intr.c void host1x_intr_deinit(struct host1x_intr *intr) · line 341

Quoted 10 lines
drivers/gpu/host1x/intr.c +5 -0
+
+       /* Why we need to lock here? Seems like this function is
+          called by host1x's probe only. */
        mutex_lock(&intr->mutex);
 
+       /* "init_host_sync" has already been called in function
+          host1x_intr_init. Remove this line. */
        host1x->intr_op.init_host_sync(intr);
        host1x->intr_op.set_host_clocks_per_usec(intr,
                        DIV_ROUND_UP(hz, 1000000));

In future, we'll call host1x_intr_start() whenever host1x is turned on. Thus we need locking.

Quoted 3 lines

init_host_sync() should actually be called from host1x_intr_start(), not _init().

Got it. Thanks for explanation.

Quoted 21 lines
Quoted 13 lines
drivers/gpu/host1x/syncpt.c +2 -0
index 07cbca5..9a234ad 100644
@@ -309,6 +309,8 @@ struct host1x_syncpt *host1x_syncpt_init(struct
 host1x *host)
        struct host1x_syncpt *syncpt, *sp;
        int i;
 
+       /* Consider devm_kzalloc here. Then you can forget the release
+          stuffs about this "syncpt". */
        syncpt = sp = kzalloc(sizeof(struct host1x_syncpt) * host->info.nb_pts,
                GFP_KERNEL);
Quoted 1 line

if (!syncpt)

Will do.

Thanks!

Terje

#32 lore raw
In reply to Terje Bergström
Quoted 10 lines · Terje Bergström
Quoted 9 lines · Mark Zhang
drivers/gpu/drm/tegra/gr2d.c +0 -0
index a936902..c3ded60 100644
@@ -131,6 +131,14 @@ static int gr2d_submit(struct tegra_drm_context
 *context,
                if (err)
                        goto fail;
 
Quoted 15 lines
Quoted 11 lines
drivers/gpu/drm/tegra/gr2d.c +8 -0
+               /* We define CMA as an temporary solution in host1x driver.
+                  That's also why we have a CMA kernel config in it.
+                  But seems here, in tegradrm, we hardcode the CMA here.
+                  So what do you do when host1x change to IOMMU?
+                  Do we also need to define a CMA config in tegradrm
 driver,
+                  then after host1x changes to IOMMU, we add another IOMMU
+                  config in tegradrm? Or we should invent another more
+                  generic wrapper layer here? */
                cmdbuf.mem = handle_cma_to_host1x(drm, file_priv,

cmdbuf.mem);

Lucas is working on host1x allocator, so let's defer this comment until we have Lucas' code.

OK.

Quoted 27 lines
Quoted 27 lines
drivers/gpu/host1x/job.c +4 -0
index cc8ca2f..0867b72 100644
@@ -82,6 +82,26 @@ struct host1x_job *host1x_job_alloc(struct
 host1x_channel *ch,
        mem += num_unpins * sizeof(dma_addr_t);
        job->pin_ids = num_unpins ? mem : NULL;
 
+       /* I think this is a somewhat ugly design.
+          Actually "addr_phys" is consisted by "reloc_addr_phys" and
+          "gather_addr_phys".
+          Why don't we just declare "reloc_addr_phys" and

"gather_addr_phys"?
+ In current design, let's say if one nvhost newbie changes the
order

drivers/gpu/host1x/job.c +11 -0
+          of these 2 blocks of code in function "pin_job_mem":
+
+          for (i = 0; i < job->num_relocs; i++) {
+               struct host1x_reloc *reloc = &job->relocarray[i];
+               job->pin_ids[count] = reloc->target;
+               count++;
+          }
+
+          for (i = 0; i < job->num_gathers; i++) {
+               struct host1x_job_gather *g = &job->gathers[i];
+               job->pin_ids[count] = g->mem_id;
Quoted 9 lines

drivers/gpu/host1x/job.c

Quoted 4 lines
drivers/gpu/host1x/job.c +4 -0
+               count++;
+          }
+
+          Then likely something weird occurs... */

We do this because this way we can implement batch pinning of memory handles. This way we can decrease memory handle management a lot as we need to do locking only once per submit.

Sorry I didn't get it. Yes, in current design, you can pin all mem handles in one time but I haven't found anything related with "locking only once per submit".

My idea is:
- remove "job->addr_phys"
- assign "job->reloc_addr_phys" & "job->gather_addr_phys" separately
- In "pin_job_mem", just call "host1x_memmgr_pin_array_ids" twice to fill the "reloc_addr_phy" & "gather_addr_phys".

Anything I misunderstood?

Quoted 12 lines

Decreasing memory management overhead is really important, because in complex graphics cases, there are might be a hundreds of buffer references per submit, and several submits per frame. Any extra overhead relates directly to reduced performance.

Quoted 7 lines
        job->reloc_addr_phys = job->addr_phys;
        job->gather_addr_phys = &job->addr_phys[num_relocs];
drivers/gpu/host1x/job.c +0 -0
@@ -252,6 +272,10 @@ static int do_relocs(struct host1x_job *job,
                        }
                }
 
Quoted 11 lines

drivers/gpu/host1x/job.c static int do_relocs(struct host1x_job *job, · line 281

Quoted 7 lines
drivers/gpu/host1x/job.c +4 -0
+               /* I have question here. Does this mean the address info
+                  which need to be relocated(according to the libdrm codes,
+                  seems this address is "0xDEADBEEF") always staying at the
+                  beginning of a page? */
                __raw_writel(
                        (job->reloc_addr_phys[i] +
                                reloc->target_offset) >> reloc->shift,

No - the slot can be anywhere. That's why we have cmdbuf_offset in the reloc struct.

Yes. Sorry I must misread the code before.

Quoted 35 lines
Quoted 9 lines
drivers/gpu/host1x/job.c +1 -0
@@ -565,6 +589,7 @@ int host1x_job_pin(struct host1x_job *job, struct
 platform_device *pdev)
                }
        }
 
+       /* if (host1x_firewall && !err) { */
        if (host1x_firewall) {
                err = copy_gathers(job, pdev);
                if (err) {

Will add.

drivers/gpu/host1x/job.c int host1x_job_pin(struct host1x_job *job, struct · line 606

Quoted 10 lines
drivers/gpu/host1x/job.c +3 -0
@@ -573,6 +598,9 @@ int host1x_job_pin(struct host1x_job *job, struct
 platform_device *pdev)
                }
        }
 
+/* Rename this label to "out" or something else.
+   Because if everything goes right, the codes under this label also
+   get executed. */
 fail:
        wmb();

Will do.

Quoted 10 lines
drivers/gpu/host1x/memmgr.c +0 -0
index f3954f7..bb5763d 100644
@@ -156,6 +156,9 @@ int host1x_memmgr_pin_array_ids(struct
 platform_device *dev,
                        count, &unpin_data[pin_count],
                        phys_addr);
 
Quoted 9 lines
Quoted 6 lines
drivers/gpu/host1x/memmgr.c +3 -0
+               /* I don't think the current "host1x_cma_pin_array_ids"
+                  is able to return a negative value. So this "if" doesn't
+                  make sense...*/
                if (cma_count < 0) {
                        /* clean up previous handles */
                        while (pin_count) {

It should return negative in case of error.

"host1x_cma_pin_array_ids" doesn't return negative value right now, so maybe you need to take a look at it.

Quoted 2 lines

Terje

#33 lore raw
Quoted 11 lines · Mark Zhang

Sorry I didn't get it. Yes, in current design, you can pin all mem handles in one time but I haven't found anything related with "locking only once per submit".

My idea is:
- remove "job->addr_phys"
- assign "job->reloc_addr_phys" & "job->gather_addr_phys" separately
- In "pin_job_mem", just call "host1x_memmgr_pin_array_ids" twice to fill the "reloc_addr_phy" & "gather_addr_phys".

Anything I misunderstood?

The current design uses CMA, which makes pinning basically a no-op. When we have IOMMU support, pinning requires calling into IOMMU. Updating SMMU tables requires locking, and probably maintenance before SMMU code also requires its own locked data tables. For example, preventing duplicate pinning might require a global table of handles.

Putting all of the handles in one table allows doing duplicate detection across cmdbuf and reloc tables. This allows pinning each buffer exactly once, which reduces number of calls to IOMMU.

Quoted 2 lines

"host1x_cma_pin_array_ids" doesn't return negative value right now, so maybe you need to take a look at it.

True, and also a consequence of using CMA: pinning can never fail. With IOMMU, pinning can fail.

Terje

#34 lore raw
Quoted 19 lines · Terje Bergström
Quoted 11 lines · Mark Zhang

Sorry I didn't get it. Yes, in current design, you can pin all mem handles in one time but I haven't found anything related with "locking only once per submit".

My idea is:
- remove "job->addr_phys"
- assign "job->reloc_addr_phys" & "job->gather_addr_phys" separately
- In "pin_job_mem", just call "host1x_memmgr_pin_array_ids" twice to fill the "reloc_addr_phy" & "gather_addr_phys".

Anything I misunderstood?

The current design uses CMA, which makes pinning basically a no-op. When we have IOMMU support, pinning requires calling into IOMMU. Updating SMMU tables requires locking, and probably maintenance before SMMU code also requires its own locked data tables. For example, preventing duplicate pinning might require a global table of handles.

Quoted 4 lines

Putting all of the handles in one table allows doing duplicate detection across cmdbuf and reloc tables. This allows pinning each buffer exactly once, which reduces number of calls to IOMMU.

Thanks Terje. Yes, I understand IOMMU will bring in more operations. But I'm not convinced that separating 2 arrays have lots of overheads than putting them into one array.

But it doesn't matter, after the IOMMU support version released, I can read this part of codes again. Let's talk about this at that time.

Quoted 5 lines
Quoted 2 lines

"host1x_cma_pin_array_ids" doesn't return negative value right now, so maybe you need to take a look at it.

True, and also a consequence of using CMA: pinning can never fail. With IOMMU, pinning can fail.

Got it. Agree.

Quoted 3 lines

Terje

#26 lore raw
In reply to Lucas Stach
Quoted 9 lines · Lucas Stach

Am Freitag, den 21.12.2012, 13:39 +0200 schrieb Terje Bergstrom:

Quoted 5 lines

Some of the issues left open:
* Register definitions still use static inline. There has been a debate about code style versus ability to use compiler type checking and code coverage analysis. There was no conclusion, so I left it as was.

This has to be resolved before merging. Personally I'm in favour of keeping reg access patterns close to what is done in other parts of the kernel.

How about if I define inline functions, and #defines to proxy to them? Something like:

static inline u32 host1x_sync_cfpeek_ctrl_r(void)

{
	return 0x74c;
}
#define HOST1X_SYNC_CFPEEK_CTRL \
	host1x_sync_cfpeek_ctrl_r()

static inline u32 host1x_sync_cfpeek_ctrl_cfpeek_ena_f(u32 v)

{
	return (v & 0x1) << 31;
}

#define HOST1X_SYNC_CFPEEK_CTRL_CFPEEK_ENA_F(v) \
host1x_sync_cfpeek_ctrl_cfpeek_ena_f(v)

I'd use the macros in .c files. That way the references will look familiar to reader of .c files, but we can still get the benefits of compiler processing (type checking, better error codes etc) and gcov coverage tracking.

Terje

#17 lore raw

Re: [PATCHv4 5/8] drm: tegra: Remove redundant host1x

In reply to Thierry Reding
Quoted 8 lines · Thierry Reding

drivers/gpu/drm/tegra/drm.c static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp) · line 193

Quoted 5 lines · Terje Bergstrom
drivers/gpu/drm/tegra/drm.c +5 -0
+static void tegra_drm_close(struct drm_device *drm, struct drm_file *filp)
+{
+
+}
+

This can be removed, right?

Yes, done.

Quoted 6 lines

drivers/gpu/drm/tegra/drm.c static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp) · line 232

Quoted 4 lines
drivers/gpu/drm/tegra/drm.c +3 -0
+static struct platform_driver tegra_drm_platform_driver = {
+	.driver = {
+		.name = "tegradrm",

This should be "tegra-drm" to match the module name.

Done.

Quoted 7 lines

drivers/gpu/drm/tegra/drm.h struct host1x { · line 45

Quoted 2 lines
drivers/gpu/drm/tegra/drm.h +1 -1
-struct host1x_client;
+struct tegra_drm_client;

I don't see the point in renaming this. All of the devices are still host1x clients, right? This patch would be a whole shorter if we didn't rename these. None of these symbols are exported either so there's not much chance for them to clash with anything.

Yep, we renamed it back to make the patch smaller.

Quoted 20 lines
Quoted 20 lines
include/drm/tegra_drm.h new file +14 -0
new file mode 100644
index 0000000..8632f49
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
+ *
+ * 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/>.
Quoted 8 lines

include/drm/tegra_drm.h line 20

Quoted 6 lines
include/drm/tegra_drm.h new file +6 -0
+ */
+
+#ifndef _TEGRA_DRM_H_
+#define _TEGRA_DRM_H_
+
+#endif

This can be removed as well.

Removed.

I posted another proposal on how to handle initialization in tegradrm. It removes a lot of code and relies more on platform_bus keeping track of devices. Have you had time to look into it?

Terje