Skip to contentSkip to conversation

Support for Tegra 2D hardware

RFC Superseded Terje Bergstrom 11 participants 145 messages Nov 26, 2012 – Jan 15, 2013

Subsystems (6)

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v2 cover Support for Tegra 2D hardware

This set of patches adds support for Tegra20 and Tegra30 host1x and 2D. It is based on Thierry Reding's tegra/next branch. We still have unresolved issues, so I don't expect these patches to be merged, but act as a way to get the code out for public review.

The first version was sent only to [email protected]. The second version has the following changes:
* nvhost split into smaller pieces
* "graphics host" and "grhost" renamed to host1x
* patch to tegradrm exit is removed
* nvhost mem_mgr usage dropped
* public power management API prefix changed to host1x
* fixed some other code style issues

nvhost is the driver that controls host1x hardware. It supports host1x command channels, synchronization, run-time power management and memory management. It is sectioned into logical driver under drivers/video/tegra/host and physical driver under drivers/video/tegra/host/host1x. The physical driver is compiled with the hardware headers of the particular host1x version.

The hardware units are described (briefly) in the Tegra2 TRM.

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 other files.

The patch set adds 2D driver to tegradrm, which uses nvhost 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 nvhost and tegradrm separate.

The patch set also adds user space API to tegradrm for accessing host1d and 2D. We are preparing also patches to libdrm, but they are not yet in condition that they could be sent out.

TODO:
* tegradrm IOMMU support has been disabled
* Prime support is still tegradrm specific - to be generalized when we find a way for dma mapping API to handle double mapping
* Find a home for the data in auxdata if they are troublesome
* nvhost is still called nvhost - there's a request to rename to host1x to reflect the hardware name
* Write an article about host1x and how we use it
* Send out 2D user space code
* Rebase on linux-next

Arto Merilainen (2):
gpu: drm: tegra: Remove redundant host1x
gpu: drm: tegra: Prime support

Terje Bergstrom (6):
video: tegra: Add nvhost driver
video: tegra: Add syncpoint wait and interrupts
video: tegra: host: Add channel and client support
video: tegra: Add debug support
ARM: tegra: Add auxiliary data for nvhost
drm: tegra: Add gr2d device

 arch/arm/mach-tegra/board-dt-tegra20.c             |   38 +-
 arch/arm/mach-tegra/board-dt-tegra30.c             |   38 +-
 arch/arm/mach-tegra/tegra20_clocks_data.c          |    8 +-
 arch/arm/mach-tegra/tegra30_clocks_data.c          |    2 +
 drivers/gpu/drm/tegra/Kconfig                      |    8 +-
 drivers/gpu/drm/tegra/Makefile                     |    4 +-
 drivers/gpu/drm/tegra/dc.c                         |   22 +-
 drivers/gpu/drm/tegra/dmabuf.c                     |  150 ++++++
 drivers/gpu/drm/tegra/drm.c                        |  445 ++++++++++++++++--
 drivers/gpu/drm/tegra/drm.h                        |   89 ++--
 drivers/gpu/drm/tegra/dsi.c                        |   24 +-
 drivers/gpu/drm/tegra/fb.c                         |   26 +-
 drivers/gpu/drm/tegra/gr2d.c                       |  224 +++++++++
 drivers/gpu/drm/tegra/hdmi.c                       |   24 +-
 drivers/gpu/drm/tegra/host1x.c                     |  343 --------------
 drivers/gpu/drm/tegra/tvo.c                        |   33 +-
 drivers/video/Kconfig                              |    2 +
 drivers/video/Makefile                             |    2 +
 drivers/video/tegra/host/Kconfig                   |    5 +
 drivers/video/tegra/host/Makefile                  |   18 +
 drivers/video/tegra/host/bus_client.c              |   97 ++++
 drivers/video/tegra/host/chip_support.c            |   48 ++
 drivers/video/tegra/host/chip_support.h            |  149 ++++++
 drivers/video/tegra/host/debug.c                   |  252 ++++++++++
 drivers/video/tegra/host/debug.h                   |   50 ++
 drivers/video/tegra/host/dev.c                     |  170 +++++++
 drivers/video/tegra/host/dev.h                     |   33 ++
 drivers/video/tegra/host/dmabuf.c                  |  151 ++++++
 drivers/video/tegra/host/dmabuf.h                  |   45 ++
 drivers/video/tegra/host/host1x/Makefile           |    7 +
 drivers/video/tegra/host/host1x/host1x.c           |  257 +++++++++++
 drivers/video/tegra/host/host1x/host1x.h           |   86 ++++
 drivers/video/tegra/host/host1x/host1x01.c         |   70 +++
 drivers/video/tegra/host/host1x/host1x01.h         |   29 ++
 .../video/tegra/host/host1x/host1x01_hardware.h    |  157 +++++++
 drivers/video/tegra/host/host1x/host1x_cdma.c      |  486 ++++++++++++++++++++
 drivers/video/tegra/host/host1x/host1x_cdma.h      |   39 ++
 drivers/video/tegra/host/host1x/host1x_channel.c   |  150 ++++++
 drivers/video/tegra/host/host1x/host1x_debug.c     |  405 ++++++++++++++++
 drivers/video/tegra/host/host1x/host1x_intr.c      |  263 +++++++++++
 drivers/video/tegra/host/host1x/host1x_syncpt.c    |  168 +++++++
 .../video/tegra/host/host1x/hw_host1x01_channel.h  |  182 ++++++++
 drivers/video/tegra/host/host1x/hw_host1x01_sync.h |  398 ++++++++++++++++
 .../video/tegra/host/host1x/hw_host1x01_uclass.h   |  474 +++++++++++++++++++
 drivers/video/tegra/host/nvhost_acm.c              |  481 +++++++++++++++++++
 drivers/video/tegra/host/nvhost_acm.h              |   45 ++
 drivers/video/tegra/host/nvhost_cdma.c             |  430 +++++++++++++++++
 drivers/video/tegra/host/nvhost_cdma.h             |  109 +++++
 drivers/video/tegra/host/nvhost_channel.c          |  126 +++++
 drivers/video/tegra/host/nvhost_channel.h          |   65 +++
 drivers/video/tegra/host/nvhost_intr.c             |  384 ++++++++++++++++
 drivers/video/tegra/host/nvhost_intr.h             |  110 +++++
 drivers/video/tegra/host/nvhost_job.c              |  390 ++++++++++++++++
 drivers/video/tegra/host/nvhost_memmgr.c           |  160 +++++++
 drivers/video/tegra/host/nvhost_memmgr.h           |   65 +++
 drivers/video/tegra/host/nvhost_syncpt.c           |  452 ++++++++++++++++++
 drivers/video/tegra/host/nvhost_syncpt.h           |  148 ++++++
 include/drm/tegra_drm.h                            |  129 ++++++
 include/linux/nvhost.h                             |  294 ++++++++++++
 59 files changed, 8549 insertions(+), 510 deletions(-)
 create mode 100644 drivers/gpu/drm/tegra/dmabuf.c
 create mode 100644 drivers/gpu/drm/tegra/gr2d.c
 delete mode 100644 drivers/gpu/drm/tegra/host1x.c
 create mode 100644 drivers/video/tegra/host/Kconfig
 create mode 100644 drivers/video/tegra/host/Makefile
 create mode 100644 drivers/video/tegra/host/bus_client.c
 create mode 100644 drivers/video/tegra/host/chip_support.c
 create mode 100644 drivers/video/tegra/host/chip_support.h
 create mode 100644 drivers/video/tegra/host/debug.c
 create mode 100644 drivers/video/tegra/host/debug.h
 create mode 100644 drivers/video/tegra/host/dev.c
 create mode 100644 drivers/video/tegra/host/dev.h
 create mode 100644 drivers/video/tegra/host/dmabuf.c
 create mode 100644 drivers/video/tegra/host/dmabuf.h
 create mode 100644 drivers/video/tegra/host/host1x/Makefile
 create mode 100644 drivers/video/tegra/host/host1x/host1x.c
 create mode 100644 drivers/video/tegra/host/host1x/host1x.h
 create mode 100644 drivers/video/tegra/host/host1x/host1x01.c
 create mode 100644 drivers/video/tegra/host/host1x/host1x01.h
 create mode 100644 drivers/video/tegra/host/host1x/host1x01_hardware.h
 create mode 100644 drivers/video/tegra/host/host1x/host1x_cdma.c
 create mode 100644 drivers/video/tegra/host/host1x/host1x_cdma.h
 create mode 100644 drivers/video/tegra/host/host1x/host1x_channel.c
 create mode 100644 drivers/video/tegra/host/host1x/host1x_debug.c
 create mode 100644 drivers/video/tegra/host/host1x/host1x_intr.c
 create mode 100644 drivers/video/tegra/host/host1x/host1x_syncpt.c
 create mode 100644 drivers/video/tegra/host/host1x/hw_host1x01_channel.h
 create mode 100644 drivers/video/tegra/host/host1x/hw_host1x01_sync.h
 create mode 100644 drivers/video/tegra/host/host1x/hw_host1x01_uclass.h
 create mode 100644 drivers/video/tegra/host/nvhost_acm.c
 create mode 100644 drivers/video/tegra/host/nvhost_acm.h
 create mode 100644 drivers/video/tegra/host/nvhost_cdma.c
 create mode 100644 drivers/video/tegra/host/nvhost_cdma.h
 create mode 100644 drivers/video/tegra/host/nvhost_channel.c
 create mode 100644 drivers/video/tegra/host/nvhost_channel.h
 create mode 100644 drivers/video/tegra/host/nvhost_intr.c
 create mode 100644 drivers/video/tegra/host/nvhost_intr.h
 create mode 100644 drivers/video/tegra/host/nvhost_job.c
 create mode 100644 drivers/video/tegra/host/nvhost_memmgr.c
 create mode 100644 drivers/video/tegra/host/nvhost_memmgr.h
 create mode 100644 drivers/video/tegra/host/nvhost_syncpt.c
 create mode 100644 drivers/video/tegra/host/nvhost_syncpt.h
 create mode 100644 include/drm/tegra_drm.h
 create mode 100644 include/linux/nvhost.h
Signature · 1 line
1.7.9.5
#38 lore raw

RFC v2 2/8 video: tegra: Add syncpoint wait and interrupts

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

---
 drivers/video/tegra/host/Makefile             |    1 +
 drivers/video/tegra/host/chip_support.h       |   17 ++
 drivers/video/tegra/host/dev.c                |    7 +
 drivers/video/tegra/host/host1x/host1x.c      |   33 +++
 drivers/video/tegra/host/host1x/host1x.h      |    2 +
 drivers/video/tegra/host/host1x/host1x01.c    |    2 +
 drivers/video/tegra/host/host1x/host1x_intr.c |  263 ++++++++++++++++++
 drivers/video/tegra/host/nvhost_intr.c        |  363 +++++++++++++++++++++++++
 drivers/video/tegra/host/nvhost_intr.h        |  102 +++++++
 drivers/video/tegra/host/nvhost_syncpt.c      |  111 ++++++++
 drivers/video/tegra/host/nvhost_syncpt.h      |   10 +
 include/linux/nvhost.h                        |    2 +
 12 files changed, 913 insertions(+)
 create mode 100644 drivers/video/tegra/host/host1x/host1x_intr.c
 create mode 100644 drivers/video/tegra/host/nvhost_intr.c
 create mode 100644 drivers/video/tegra/host/nvhost_intr.h
drivers/video/tegra/host/Makefile +1 -0
index 3edab4a..24acccc 100644
@@ -3,6 +3,7 @@ ccflags-y = -Idrivers/video/tegra/host
 nvhost-objs = \
 	nvhost_acm.o \
 	nvhost_syncpt.o \
+	nvhost_intr.o \
 	dev.o \
 	chip_support.o
 
drivers/video/tegra/host/chip_support.h +17 -0
index acfa2f1..5c8f49f 100644
@@ -25,6 +25,7 @@
 struct output;
 
 struct nvhost_master;
+struct nvhost_intr;
 struct nvhost_syncpt;
 struct platform_device;
 
@@ -38,14 +39,30 @@ struct nvhost_syncpt_ops {
 	const char * (*name)(struct nvhost_syncpt *, u32 id);
 };
 
+struct nvhost_intr_ops {
+	void (*init_host_sync)(struct nvhost_intr *);
+	void (*set_host_clocks_per_usec)(
+		struct nvhost_intr *, u32 clocks);
+	void (*set_syncpt_threshold)(
+		struct nvhost_intr *, u32 id, u32 thresh);
+	void (*enable_syncpt_intr)(struct nvhost_intr *, u32 id);
+	void (*disable_syncpt_intr)(struct nvhost_intr *, u32 id);
+	void (*disable_all_syncpt_intrs)(struct nvhost_intr *);
+	int  (*request_host_general_irq)(struct nvhost_intr *);
+	void (*free_host_general_irq)(struct nvhost_intr *);
+	int (*free_syncpt_irq)(struct nvhost_intr *);
+};
+
 struct nvhost_chip_support {
 	const char *soc_name;
 	struct nvhost_syncpt_ops syncpt;
+	struct nvhost_intr_ops intr;
 };
 
 struct nvhost_chip_support *nvhost_get_chip_ops(void);
 
 #define syncpt_op()		(nvhost_get_chip_ops()->syncpt)
+#define intr_op()		(nvhost_get_chip_ops()->intr)
 
 int nvhost_init_chip_support(struct nvhost_master *host);
 
drivers/video/tegra/host/dev.c +7 -0
index 98c9c9f..025a820 100644
@@ -43,6 +43,13 @@ u32 host1x_syncpt_read(u32 id)
 }
 EXPORT_SYMBOL(host1x_syncpt_read);
 
+int host1x_syncpt_wait(u32 id, u32 thresh, u32 timeout, u32 *value)
+{
+	struct nvhost_syncpt *sp = &nvhost->syncpt;
+	return nvhost_syncpt_wait_timeout(sp, id, thresh, timeout, value);
+}
+EXPORT_SYMBOL(host1x_syncpt_wait);
+
 bool host1x_powered(struct platform_device *dev)
 {
 	bool ret = 0;
drivers/video/tegra/host/host1x/host1x.c +33 -0
index 77ff00b..766931b 100644
@@ -52,8 +52,24 @@ static int power_off_host(struct platform_device *dev)
 	return 0;
 }
 
+static void clock_on_host(struct platform_device *dev)
+{
+	struct nvhost_device_data *pdata = platform_get_drvdata(dev);
+	struct nvhost_master *host = nvhost_get_private_data(dev);
+	nvhost_intr_start(&host->intr, clk_get_rate(pdata->clk[0]));
+}
+
+static int clock_off_host(struct platform_device *dev)
+{
+	struct nvhost_master *host = nvhost_get_private_data(dev);
+	nvhost_intr_stop(&host->intr);
+	return 0;
+}
+
 static void nvhost_free_resources(struct nvhost_master *host)
 {
+	kfree(host->intr.syncpt);
+	host->intr.syncpt = 0;
 }
 
 static int __devinit nvhost_alloc_resources(struct nvhost_master *host)
@@ -64,6 +80,16 @@ static int __devinit nvhost_alloc_resources(struct nvhost_master *host)
 	if (err)
 		return err;
 
+	host->intr.syncpt = devm_kzalloc(&host->dev->dev,
+			sizeof(struct nvhost_intr_syncpt) *
+			nvhost_syncpt_nb_pts(&host->syncpt),
+			GFP_KERNEL);
+
+	if (!host->intr.syncpt) {
+		/* frees happen in the support removal phase */
+		return -ENOMEM;
+	}
+
 	return 0;
 }
 
@@ -99,6 +125,8 @@ static int __devinit nvhost_probe(struct platform_device *dev)
 
 	pdata->finalize_poweron = power_on_host;
 	pdata->prepare_poweroff = power_off_host;
+	pdata->prepare_clockoff = clock_off_host;
+	pdata->finalize_clockon = clock_on_host;
 
 	pdata->pdev = dev;
 
@@ -125,6 +153,10 @@ static int __devinit nvhost_probe(struct platform_device *dev)
 	if (err)
 		goto fail;
 
+	err = nvhost_intr_init(&host->intr, intr1->start, intr0->start);
+	if (err)
+		goto fail;
+
 	err = nvhost_module_init(dev);
 	if (err)
 		goto fail;
@@ -148,6 +180,7 @@ fail:
 static int __exit nvhost_remove(struct platform_device *dev)
 {
 	struct nvhost_master *host = nvhost_get_private_data(dev);
+	nvhost_intr_deinit(&host->intr);
 	nvhost_syncpt_deinit(&host->syncpt);
 	nvhost_module_deinit(dev);
 	nvhost_free_resources(host);
drivers/video/tegra/host/host1x/host1x.h +2 -0
index 76748ac..af9bfef 100644
@@ -25,6 +25,7 @@
 #include <linux/nvhost.h>
 
 #include "nvhost_syncpt.h"
+#include "nvhost_intr.h"
 
 #define TRACE_MAX_LENGTH	128U
 #define IFACE_NAME		"nvhost"
@@ -33,6 +34,7 @@ struct nvhost_master {
 	void __iomem *aperture;
 	void __iomem *sync_aperture;
 	struct nvhost_syncpt syncpt;
+	struct nvhost_intr intr;
 	struct platform_device *dev;
 	struct host1x_device_info info;
 };
drivers/video/tegra/host/host1x/host1x01.c +2 -0
index d53302d..5bf0e6e 100644
@@ -26,12 +26,14 @@
 #include "chip_support.h"
 
 #include "host1x/host1x_syncpt.c"
+#include "host1x/host1x_intr.c"
 
 int nvhost_init_host1x01_support(struct nvhost_master *host,
 	struct nvhost_chip_support *op)
 {
 	host->sync_aperture = host->aperture + HOST1X_CHANNEL_SYNC_REG_BASE;
 	op->syncpt = host1x_syncpt_ops;
+	op->intr = host1x_intr_ops;
 
 	return 0;
 }
drivers/video/tegra/host/host1x/host1x_intr.c new file +263 -0

263 lines not on this page · raw message

drivers/video/tegra/host/nvhost_intr.c new file +363 -0

363 lines not on this page · raw message

drivers/video/tegra/host/nvhost_intr.h new file +102 -0

102 lines not on this page · raw message

drivers/video/tegra/host/nvhost_syncpt.c +111 -0

117 lines not on this page · raw message

drivers/video/tegra/host/nvhost_syncpt.h +10 -0
index b883442..dbd3890 100644
@@ -126,6 +126,16 @@ u32 nvhost_syncpt_read_wait_base(struct nvhost_syncpt *sp, u32 id);
 
 void nvhost_syncpt_incr(struct nvhost_syncpt *sp, u32 id);
 
+int nvhost_syncpt_wait_timeout(struct nvhost_syncpt *sp, u32 id, u32 thresh,
+			u32 timeout, u32 *value);
+
+static inline int nvhost_syncpt_wait(struct nvhost_syncpt *sp,
+		u32 id, u32 thresh)
+{
+	return nvhost_syncpt_wait_timeout(sp, id, thresh,
+					  MAX_SCHEDULE_TIMEOUT, NULL);
+}
+
 void nvhost_syncpt_debug(struct nvhost_syncpt *sp);
 
 static inline int nvhost_syncpt_is_valid(struct nvhost_syncpt *sp, u32 id)
include/linux/nvhost.h +2 -0
index 20ba2a5..745f31c 100644
@@ -35,6 +35,7 @@ struct nvhost_device_power_attr;
 #define NVHOST_DEFAULT_CLOCKGATE_DELAY		.clockgate_delay = 25
 #define NVHOST_NAME_SIZE			24
 #define NVSYNCPT_INVALID			(-1)
+#define NVHOST_NO_TIMEOUT			(-1)
 
 enum nvhost_power_sysfs_attributes {
 	NVHOST_POWER_SYSFS_ATTRIB_CLOCKGATE_DELAY = 0,
@@ -139,5 +140,6 @@ void host1x_idle(struct platform_device *dev);
 u32 host1x_syncpt_incr_max(u32 id, u32 incrs);
 void host1x_syncpt_incr(u32 id);
 u32 host1x_syncpt_read(u32 id);
+int host1x_syncpt_wait(u32 id, u32 thresh, u32 timeout, u32 *value);
 
 #endif
Signature · 1 line
1.7.9.5
#58 lore raw

RFC v2 6/8 gpu: 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.

This modification introduces a regression: Because there is no general framework for attaching separate devices into the same address space, this patch removes the ability to use IOMMU in tegradrm.

---
 drivers/gpu/drm/tegra/Kconfig  |    8 +-
 drivers/gpu/drm/tegra/Makefile |    2 +-
 drivers/gpu/drm/tegra/dc.c     |   22 +--
 drivers/gpu/drm/tegra/drm.c    |  207 +++++++++++++++++++-----
 drivers/gpu/drm/tegra/drm.h    |   55 ++-----
 drivers/gpu/drm/tegra/dsi.c    |   24 ++-
 drivers/gpu/drm/tegra/fb.c     |   26 ++-
 drivers/gpu/drm/tegra/hdmi.c   |   24 ++-
 drivers/gpu/drm/tegra/host1x.c |  343 ----------------------------------------
 drivers/gpu/drm/tegra/tvo.c    |   33 ++--
 10 files changed, 246 insertions(+), 498 deletions(-)
 delete mode 100644 drivers/gpu/drm/tegra/host1x.c
drivers/gpu/drm/tegra/Kconfig +1 -7
index affd741..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
@@ -20,10 +20,4 @@ config DRM_TEGRA_DEBUG
 	help
 	  Say yes here to enable debugging support.
 
-config DRM_TEGRA_IOMMU
-	bool "NVIDIA Tegra DRM IOMMU support"
-	help
-	  Say yes here to enable the use of the IOMMU to allocate and
-	  map memory buffers.
-
 endif
drivers/gpu/drm/tegra/Makefile +1 -1
index e6e96af..57a334d 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 tvo.o dsi.o
 tegra-drm-y += plane.o
 
drivers/gpu/drm/tegra/dc.c +11 -11
index 3a16e93..1779008 100644
@@ -12,6 +12,7 @@
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
+#include <linux/nvhost.h>
 
 #include <mach/clk.h>
 
@@ -673,10 +674,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;
@@ -712,9 +713,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);
@@ -734,14 +735,13 @@ 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;
@@ -791,13 +791,14 @@ static int tegra_dc_probe(struct platform_device *pdev)
 		return err;
 	}
 
-	err = host1x_register_client(host1x, &dc->client);
+	err = tegra_drm_register_client(&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;
 	}
 
+	host1x_busy(pdev);
 	platform_set_drvdata(pdev, dc);
 
 	return 0;
@@ -805,13 +806,12 @@ 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);
 	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 +168 -39

240 lines not on this page · raw message

drivers/gpu/drm/tegra/drm.h +14 -41

88 lines not on this page · raw message

drivers/gpu/drm/tegra/dsi.c +11 -13
index 156b3753..4f4c709 100644
@@ -15,7 +15,7 @@
 #include "drm.h"
 
 struct tegra_dsi {
-	struct host1x_client client;
+	struct tegra_drm_client client;
 	struct tegra_output output;
 
 	void __iomem *regs;
@@ -23,7 +23,7 @@ struct tegra_dsi {
 };
 
 static inline struct tegra_dsi *
-host1x_client_to_dsi(struct host1x_client *client)
+tegra_drm_client_to_dsi(struct tegra_drm_client *client)
 {
 	return container_of(client, struct tegra_dsi, client);
 }
@@ -59,10 +59,10 @@ static const struct tegra_output_ops dsi_ops = {
 	.disable = tegra_output_dsi_disable,
 };
 
-static int tegra_dsi_drm_init(struct host1x_client *client,
+static int tegra_dsi_drm_init(struct tegra_drm_client *client,
 			      struct drm_device *drm)
 {
-	struct tegra_dsi *dsi = host1x_client_to_dsi(client);
+	struct tegra_dsi *dsi = tegra_drm_client_to_dsi(client);
 	int err;
 
 	dsi->output.type = TEGRA_OUTPUT_DSI;
@@ -78,9 +78,9 @@ static int tegra_dsi_drm_init(struct host1x_client *client,
 	return 0;
 }
 
-static int tegra_dsi_drm_exit(struct host1x_client *client)
+static int tegra_dsi_drm_exit(struct tegra_drm_client *client)
 {
-	struct tegra_dsi *dsi = host1x_client_to_dsi(client);
+	struct tegra_dsi *dsi = tegra_drm_client_to_dsi(client);
 	int err;
 
 	err = tegra_output_exit(&dsi->output);
@@ -92,14 +92,13 @@ static int tegra_dsi_drm_exit(struct host1x_client *client)
 	return 0;
 }
 
-static const struct host1x_client_ops dsi_client_ops = {
+static const struct tegra_drm_client_ops dsi_client_ops = {
 	.drm_init = tegra_dsi_drm_init,
 	.drm_exit = tegra_dsi_drm_exit,
 };
 
 static int tegra_dsi_probe(struct platform_device *pdev)
 {
-	struct host1x *host1x = dev_get_drvdata(pdev->dev.parent);
 	struct tegra_dsi *dsi;
 	struct resource *regs;
 	int err;
@@ -126,9 +125,9 @@ static int tegra_dsi_probe(struct platform_device *pdev)
 	INIT_LIST_HEAD(&dsi->client.list);
 	dsi->client.dev = &pdev->dev;
 
-	err = host1x_register_client(host1x, &dsi->client);
+	err = tegra_drm_register_client(&dsi->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;
 	}
@@ -140,13 +139,12 @@ static int tegra_dsi_probe(struct platform_device *pdev)
 
 static int tegra_dsi_remove(struct platform_device *pdev)
 {
-	struct host1x *host1x = dev_get_drvdata(pdev->dev.parent);
 	struct tegra_dsi *dsi = platform_get_drvdata(pdev);
 	int err;
 
-	err = host1x_unregister_client(host1x, &dsi->client);
+	err = tegra_drm_unregister_client(&dsi->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/fb.c +12 -14
index 97993c6..d6f44fa 100644
@@ -9,11 +9,11 @@
 
 #include "drm.h"
 
+static struct drm_fbdev_cma *tegra_fbdev;
+
 static void tegra_drm_fb_output_poll_changed(struct drm_device *drm)
 {
-	struct host1x *host1x = drm->dev_private;
-
-	drm_fbdev_cma_hotplug_event(host1x->fbdev);
+	drm_fbdev_cma_hotplug_event(tegra_fbdev);
 }
 
 static const struct drm_mode_config_funcs tegra_drm_mode_funcs = {
@@ -23,9 +23,6 @@ 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 drm_fbdev_cma *fbdev;
-
 	drm->mode_config.min_width = 0;
 	drm->mode_config.min_height = 0;
 
@@ -34,23 +31,24 @@ int tegra_drm_fb_init(struct drm_device *drm)
 
 	drm->mode_config.funcs = &tegra_drm_mode_funcs;
 
-	fbdev = drm_fbdev_cma_init(drm, 32, drm->mode_config.num_crtc,
+	tegra_fbdev = drm_fbdev_cma_init(drm, 32, drm->mode_config.num_crtc,
 				   drm->mode_config.num_connector);
-	if (IS_ERR(fbdev))
-		return PTR_ERR(fbdev);
+	if (IS_ERR(tegra_fbdev))
+		return PTR_ERR(tegra_fbdev);
 
 #ifndef CONFIG_FRAMEBUFFER_CONSOLE
-	drm_fbdev_cma_restore_mode(fbdev);
+	drm_fbdev_cma_restore_mode(tegra_fbdev);
 #endif
 
-	host1x->fbdev = fbdev;
-
 	return 0;
 }
 
 void tegra_drm_fb_exit(struct drm_device *drm)
 {
-	struct host1x *host1x = drm->dev_private;
+	drm_fbdev_cma_fini(tegra_fbdev);
+}
 
-	drm_fbdev_cma_fini(host1x->fbdev);
+void tegra_drm_fb_restore(struct drm_device *drm)
+{
+	drm_fbdev_cma_restore_mode(tegra_fbdev);
 }
drivers/gpu/drm/tegra/hdmi.c +11 -13
index 58f55dc..b2b8e58 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,14 +1204,13 @@ 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;
@@ -1286,9 +1285,9 @@ static int tegra_hdmi_probe(struct platform_device *pdev)
 	INIT_LIST_HEAD(&hdmi->client.list);
 	hdmi->client.dev = &pdev->dev;
 
-	err = host1x_register_client(host1x, &hdmi->client);
+	err = tegra_drm_register_client(&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 +1299,12 @@ 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);
 	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 -343

343 lines not on this page · raw message

drivers/gpu/drm/tegra/tvo.c +17 -16
index a67bd28..01ac356 100644
@@ -15,7 +15,7 @@
 #include "drm.h"
 
 struct tegra_tvo {
-	struct host1x_client client;
+	struct tegra_drm_client client;
 	struct tegra_output output;
 
 	void __iomem *regs;
@@ -24,7 +24,7 @@ struct tegra_tvo {
 };
 
 static inline struct tegra_tvo *
-host1x_client_to_tvo(struct host1x_client *client)
+tegra_drm_client_to_tvo(struct tegra_drm_client *client)
 {
 	return container_of(client, struct tegra_tvo, client);
 }
@@ -60,10 +60,10 @@ static const struct tegra_output_ops tvo_ops = {
 	.disable = tegra_output_tvo_disable,
 };
 
-static int tegra_tvo_drm_init(struct host1x_client *client,
+static int tegra_tvo_drm_init(struct tegra_drm_client *client,
 			      struct drm_device *drm)
 {
-	struct tegra_tvo *tvo = host1x_client_to_tvo(client);
+	struct tegra_tvo *tvo = tegra_drm_client_to_tvo(client);
 	int err;
 
 	tvo->output.type = TEGRA_OUTPUT_TVO;
@@ -79,9 +79,9 @@ static int tegra_tvo_drm_init(struct host1x_client *client,
 	return 0;
 }
 
-static int tegra_tvo_drm_exit(struct host1x_client *client)
+static int tegra_tvo_drm_exit(struct tegra_drm_client *client)
 {
-	struct tegra_tvo *tvo = host1x_client_to_tvo(client);
+	struct tegra_tvo *tvo = tegra_drm_client_to_tvo(client);
 	int err;
 
 	err = tegra_output_exit(&tvo->output);
@@ -93,14 +93,13 @@ static int tegra_tvo_drm_exit(struct host1x_client *client)
 	return err;
 }
 
-static const struct host1x_client_ops tvo_client_ops = {
+static const struct tegra_drm_client_ops tvo_client_ops = {
 	.drm_init = tegra_tvo_drm_init,
 	.drm_exit = tegra_tvo_drm_exit,
 };
 
 static int tegra_tvo_probe(struct platform_device *pdev)
 {
-	struct host1x *host1x = dev_get_drvdata(pdev->dev.parent);
 	struct tegra_tvo *tvo;
 	struct resource *regs;
 	int err;
@@ -120,22 +119,25 @@ static int tegra_tvo_probe(struct platform_device *pdev)
 		return -ENXIO;
 
 	err = platform_get_irq(pdev, 0);
-	if (err < 0)
+	if (err < 0) {
+		dev_err(&pdev->dev, "failed to get tvo irq\n");
 		return err;
-
+	}
 	tvo->irq = err;
 
 	tvo->regs = devm_request_and_ioremap(&pdev->dev, regs);
-	if (!tvo->regs)
+	if (!tvo->regs) {
+		dev_err(&pdev->dev, "failed to request tvo regs\n");
 		return -EADDRNOTAVAIL;
+	}
 
 	tvo->client.ops = &tvo_client_ops;
 	INIT_LIST_HEAD(&tvo->client.list);
 	tvo->client.dev = &pdev->dev;
 
-	err = host1x_register_client(host1x, &tvo->client);
+	err = tegra_drm_register_client(&tvo->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;
 	}
@@ -147,13 +149,12 @@ static int tegra_tvo_probe(struct platform_device *pdev)
 
 static int tegra_tvo_remove(struct platform_device *pdev)
 {
-	struct host1x *host1x = dev_get_drvdata(pdev->dev.parent);
 	struct tegra_tvo *tvo = platform_get_drvdata(pdev);
 	int err;
 
-	err = host1x_unregister_client(host1x, &tvo->client);
+	err = tegra_drm_unregister_client(&tvo->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;
 	}
Signature · 1 line
1.7.9.5
#46 lore raw

RFC v2 3/8 video: tegra: host: Add channel and client 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 dmabuf buffers, so add support for dmabuf memory management, too.

---
 drivers/video/tegra/host/Makefile                  |    8 +-
 drivers/video/tegra/host/bus_client.c              |   94 ++++
 drivers/video/tegra/host/chip_support.c            |    2 +-
 drivers/video/tegra/host/chip_support.h            |   64 +++
 drivers/video/tegra/host/dev.c                     |   67 +++
 drivers/video/tegra/host/dev.h                     |   33 ++
 drivers/video/tegra/host/dmabuf.c                  |  151 ++++++
 drivers/video/tegra/host/dmabuf.h                  |   45 ++
 drivers/video/tegra/host/host1x/host1x.c           |   17 +
 drivers/video/tegra/host/host1x/host1x.h           |    6 +
 drivers/video/tegra/host/host1x/host1x01.c         |   29 ++
 .../video/tegra/host/host1x/host1x01_hardware.h    |  121 +++++
 drivers/video/tegra/host/host1x/host1x_cdma.c      |  483 ++++++++++++++++++++
 drivers/video/tegra/host/host1x/host1x_cdma.h      |   39 ++
 drivers/video/tegra/host/host1x/host1x_channel.c   |  150 ++++++
 drivers/video/tegra/host/host1x/host1x_syncpt.c    |   11 +
 .../video/tegra/host/host1x/hw_host1x01_channel.h  |  182 ++++++++
 .../video/tegra/host/host1x/hw_host1x01_uclass.h   |  474 +++++++++++++++++++
 drivers/video/tegra/host/nvhost_cdma.c             |  429 +++++++++++++++++
 drivers/video/tegra/host/nvhost_cdma.h             |  109 +++++
 drivers/video/tegra/host/nvhost_channel.c          |  126 +++++
 drivers/video/tegra/host/nvhost_channel.h          |   65 +++
 drivers/video/tegra/host/nvhost_intr.c             |   23 +-
 drivers/video/tegra/host/nvhost_intr.h             |    8 +
 drivers/video/tegra/host/nvhost_job.c              |  390 ++++++++++++++++
 drivers/video/tegra/host/nvhost_memmgr.c           |  160 +++++++
 drivers/video/tegra/host/nvhost_memmgr.h           |   65 +++
 drivers/video/tegra/host/nvhost_syncpt.c           |    6 +
 drivers/video/tegra/host/nvhost_syncpt.h           |    2 +
 include/linux/nvhost.h                             |  149 ++++++
 30 files changed, 3505 insertions(+), 3 deletions(-)
 create mode 100644 drivers/video/tegra/host/bus_client.c
 create mode 100644 drivers/video/tegra/host/dev.h
 create mode 100644 drivers/video/tegra/host/dmabuf.c
 create mode 100644 drivers/video/tegra/host/dmabuf.h
 create mode 100644 drivers/video/tegra/host/host1x/host1x_cdma.c
 create mode 100644 drivers/video/tegra/host/host1x/host1x_cdma.h
 create mode 100644 drivers/video/tegra/host/host1x/host1x_channel.c
 create mode 100644 drivers/video/tegra/host/host1x/hw_host1x01_channel.h
 create mode 100644 drivers/video/tegra/host/host1x/hw_host1x01_uclass.h
 create mode 100644 drivers/video/tegra/host/nvhost_cdma.c
 create mode 100644 drivers/video/tegra/host/nvhost_cdma.h
 create mode 100644 drivers/video/tegra/host/nvhost_channel.c
 create mode 100644 drivers/video/tegra/host/nvhost_channel.h
 create mode 100644 drivers/video/tegra/host/nvhost_job.c
 create mode 100644 drivers/video/tegra/host/nvhost_memmgr.c
 create mode 100644 drivers/video/tegra/host/nvhost_memmgr.h
drivers/video/tegra/host/Makefile +7 -1
index 24acccc..128ad03 100644
@@ -3,9 +3,15 @@ ccflags-y = -Idrivers/video/tegra/host
 nvhost-objs = \
 	nvhost_acm.o \
 	nvhost_syncpt.o \
+	nvhost_cdma.o \
 	nvhost_intr.o \
+	nvhost_channel.o \
+	nvhost_job.o \
 	dev.o \
-	chip_support.o
+	bus_client.o \
+	chip_support.o \
+	nvhost_memmgr.o \
+	dmabuf.o
 
 obj-$(CONFIG_TEGRA_HOST1X) += host1x/
 obj-$(CONFIG_TEGRA_HOST1X) += nvhost.o
drivers/video/tegra/host/bus_client.c new file +94 -0

94 lines not on this page · raw message

drivers/video/tegra/host/chip_support.c +1 -1
index 5a44147..8765c83 100644
@@ -25,7 +25,7 @@
 #include "chip_support.h"
 #include "host1x/host1x01.h"
 
-struct nvhost_chip_support *nvhost_chip_ops;
+static struct nvhost_chip_support *nvhost_chip_ops;
 
 struct nvhost_chip_support *nvhost_get_chip_ops(void)
 {
drivers/video/tegra/host/chip_support.h +64 -0

94 lines not on this page · raw message

drivers/video/tegra/host/dev.c +67 -0

79 lines not on this page · raw message

drivers/video/tegra/host/dev.h new file +33 -0
new file mode 100644
index 0000000..12dfda5
@@ -0,0 +1,33 @@
+/*
+ * drivers/video/tegra/host/dev.h
+ *
+ * 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 NVHOST_DEV_H
+#define NVHOST_DEV_H
+
+#include "host1x/host1x.h"
+
+struct platform_device;
+
+void nvhost_device_list_init(void);
+int nvhost_device_list_add(struct platform_device *pdev);
+void nvhost_device_list_for_all(void *data,
+	int (*fptr)(struct platform_device *pdev, void *fdata));
+struct platform_device *nvhost_device_list_match_by_id(u32 id);
+void nvhost_device_list_remove(struct platform_device *pdev);
+
+#endif
drivers/video/tegra/host/dmabuf.c new file +151 -0

151 lines not on this page · raw message

drivers/video/tegra/host/dmabuf.h new file +45 -0

45 lines not on this page · raw message

drivers/video/tegra/host/host1x/host1x.c +17 -0
index 766931b..8033b2d 100644
@@ -29,8 +29,10 @@
 #include <linux/of.h>
 #include <linux/nvhost.h>
 
+#include "dev.h"
 #include "host1x/host1x.h"
 #include "nvhost_acm.h"
+#include "nvhost_channel.h"
 #include "chip_support.h"
 
 #define DRIVER_NAME		"tegra-host1x"
@@ -66,6 +68,16 @@ static int clock_off_host(struct platform_device *dev)
 	return 0;
 }
 
+struct nvhost_channel *nvhost_alloc_channel(struct platform_device *dev)
+{
+	return host_device_op().alloc_nvhost_channel(dev);
+}
+
+void nvhost_free_channel(struct nvhost_channel *ch)
+{
+	host_device_op().free_nvhost_channel(ch);
+}
+
 static void nvhost_free_resources(struct nvhost_master *host)
 {
 	kfree(host->intr.syncpt);
@@ -167,6 +179,11 @@ static int __devinit nvhost_probe(struct platform_device *dev)
 	for (i = 0; i < pdata->num_clks; i++)
 		clk_disable_unprepare(pdata->clk[i]);
 
+	nvhost_device_list_init();
+	err = nvhost_device_list_add(dev);
+	if (err)
+		goto fail;
+
 	dev_info(&dev->dev, "initialized\n");
 
 	return 0;
drivers/video/tegra/host/host1x/host1x.h +6 -0
index af9bfef..28ec916 100644
@@ -30,17 +30,23 @@
 #define TRACE_MAX_LENGTH	128U
 #define IFACE_NAME		"nvhost"
 
+struct nvhost_channel;
+
 struct nvhost_master {
 	void __iomem *aperture;
 	void __iomem *sync_aperture;
 	struct nvhost_syncpt syncpt;
 	struct nvhost_intr intr;
 	struct platform_device *dev;
+	atomic_t clientid;
 	struct host1x_device_info info;
 };
 
 extern struct nvhost_master *nvhost;
 
+struct nvhost_channel *nvhost_alloc_channel(struct platform_device *dev);
+void nvhost_free_channel(struct nvhost_channel *ch);
+
 static inline void *nvhost_get_private_data(struct platform_device *_dev)
 {
 	struct nvhost_device_data *pdata =
drivers/video/tegra/host/host1x/host1x01.c +29 -0
index 5bf0e6e..cd97339 100644
@@ -18,22 +18,51 @@
  * 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/nvhost.h>
 
 #include "host1x/host1x01.h"
 #include "host1x/host1x.h"
+#include "nvhost_channel.h"
 #include "host1x/host1x01_hardware.h"
 #include "chip_support.h"
 
+static int t20_num_alloc_channels;
+
+static void t20_free_nvhost_channel(struct nvhost_channel *ch)
+{
+	nvhost_free_channel_internal(ch, &t20_num_alloc_channels);
+}
+
+static
+struct nvhost_channel *t20_alloc_nvhost_channel(struct platform_device *dev)
+{
+	struct nvhost_device_data *pdata = platform_get_drvdata(dev);
+	return nvhost_alloc_channel_internal(pdata->index,
+		nvhost_get_host(dev)->info.nb_channels,
+		&t20_num_alloc_channels);
+}
+
+#include "host1x/host1x_channel.c"
+#include "host1x/host1x_cdma.c"
 #include "host1x/host1x_syncpt.c"
 #include "host1x/host1x_intr.c"
 
 int nvhost_init_host1x01_support(struct nvhost_master *host,
 	struct nvhost_chip_support *op)
 {
+	op->channel = host1x_channel_ops;
+	op->cdma = host1x_cdma_ops;
+	op->push_buffer = host1x_pushbuffer_ops;
 	host->sync_aperture = host->aperture + HOST1X_CHANNEL_SYNC_REG_BASE;
 	op->syncpt = host1x_syncpt_ops;
 	op->intr = host1x_intr_ops;
 
+	op->nvhost_dev.alloc_nvhost_channel = t20_alloc_nvhost_channel;
+	op->nvhost_dev.free_nvhost_channel = t20_free_nvhost_channel;
+
 	return 0;
 }
drivers/video/tegra/host/host1x/host1x01_hardware.h +121 -0

132 lines not on this page · raw message

drivers/video/tegra/host/host1x/host1x_cdma.c new file +483 -0

483 lines not on this page · raw message

drivers/video/tegra/host/host1x/host1x_cdma.h new file +39 -0
new file mode 100644
index 0000000..dc0d0b0
@@ -0,0 +1,39 @@
+/*
+ * drivers/video/tegra/host/host1x/host1x_cdma.h
+ *
+ * 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 __NVHOST_HOST1X_HOST1X_CDMA_H
+#define __NVHOST_HOST1X_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 NVHOST_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 NVHOST_GATHER_QUEUE_SIZE 512
+
+/* 8 bytes per slot. (This number does not include the final RESTART.) */
+#define PUSH_BUFFER_SIZE (NVHOST_GATHER_QUEUE_SIZE * 8)
+
+/* 4K page containing GATHERed methods to increment channel syncpts
+ * and replaces the original timed out contexts GATHER slots */
+#define SYNCPT_INCR_BUFFER_SIZE_WORDS   (4096 / sizeof(u32))
+
+#endif
drivers/video/tegra/host/host1x/host1x_channel.c new file +150 -0

150 lines not on this page · raw message

drivers/video/tegra/host/host1x/host1x_syncpt.c +11 -0
index 57cc1b1..e47bd71 100644
@@ -107,6 +107,16 @@ static void host1x_syncpt_cpu_incr(struct nvhost_syncpt *sp, u32 id)
 	wmb();
 }
 
+/* remove a wait pointed to by patch_addr */
+static int host1x_syncpt_patch_wait(struct nvhost_syncpt *sp,
+		void *patch_addr)
+{
+	u32 override = nvhost_class_host_wait_syncpt(
+			NVSYNCPT_GRAPHICS_HOST, 0);
+	__raw_writel(override, patch_addr);
+	return 0;
+}
+
 static const char *host1x_syncpt_name(struct nvhost_syncpt *sp, u32 id)
 {
 	struct host1x_device_info *info = &syncpt_to_dev(sp)->info;
@@ -151,6 +161,7 @@ static const struct nvhost_syncpt_ops host1x_syncpt_ops = {
 	.read_wait_base = host1x_syncpt_read_wait_base,
 	.update_min = host1x_syncpt_update_min,
 	.cpu_incr = host1x_syncpt_cpu_incr,
+	.patch_wait = host1x_syncpt_patch_wait,
 	.debug = host1x_syncpt_debug,
 	.name = host1x_syncpt_name,
 };
drivers/video/tegra/host/host1x/hw_host1x01_channel.h new file +182 -0

182 lines not on this page · raw message

drivers/video/tegra/host/host1x/hw_host1x01_uclass.h new file +474 -0

474 lines not on this page · raw message

drivers/video/tegra/host/nvhost_cdma.c new file +429 -0

429 lines not on this page · raw message

drivers/video/tegra/host/nvhost_cdma.h new file +109 -0

109 lines not on this page · raw message

drivers/video/tegra/host/nvhost_channel.c new file +126 -0

126 lines not on this page · raw message

drivers/video/tegra/host/nvhost_channel.h new file +65 -0

65 lines not on this page · raw message

drivers/video/tegra/host/nvhost_intr.c +22 -1
index 35dd7bb..0b451c8 100644
@@ -23,6 +23,7 @@
 #include <linux/interrupt.h>
 #include <linux/slab.h>
 #include <linux/irq.h>
+#include "nvhost_channel.h"
 #include "chip_support.h"
 #include "host1x/host1x.h"
 
@@ -78,7 +79,7 @@ static void remove_completed_waiters(struct list_head *head, u32 sync,
 			struct list_head completed[NVHOST_INTR_ACTION_COUNT])
 {
 	struct list_head *dest;
-	struct nvhost_waitlist *waiter, *next;
+	struct nvhost_waitlist *waiter, *next, *prev;
 
 	list_for_each_entry_safe(waiter, next, head, list) {
 		if ((s32)(waiter->thresh - sync) > 0)
@@ -86,6 +87,17 @@ static void remove_completed_waiters(struct list_head *head, u32 sync,
 
 		dest = completed + waiter->action;
 
+		/* consolidate submit cleanups */
+		if (waiter->action == NVHOST_INTR_ACTION_SUBMIT_COMPLETE
+			&& !list_empty(dest)) {
+			prev = list_entry(dest->prev,
+					struct nvhost_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);
@@ -107,6 +119,14 @@ void reset_threshold_interrupt(struct nvhost_intr *intr,
 	intr_op().enable_syncpt_intr(intr, id);
 }
 
+static void action_submit_complete(struct nvhost_waitlist *waiter)
+{
+	struct nvhost_channel *channel = waiter->data;
+	int nr_completed = waiter->count;
+
+	nvhost_cdma_update(&channel->cdma);
+	nvhost_module_idle_mult(channel->dev, nr_completed);
+}
 
 static void action_wakeup(struct nvhost_waitlist *waiter)
 {
@@ -125,6 +145,7 @@ static void action_wakeup_interruptible(struct nvhost_waitlist *waiter)
 typedef void (*action_handler)(struct nvhost_waitlist *waiter);
 
 static action_handler action_handlers[NVHOST_INTR_ACTION_COUNT] = {
+	action_submit_complete,
 	action_wakeup,
 	action_wakeup_interruptible,
 };
drivers/video/tegra/host/nvhost_intr.h +8 -0
index 31b0a38..601ea64 100644
@@ -26,8 +26,16 @@
 #include <linux/interrupt.h>
 #include <linux/workqueue.h>
 
+struct nvhost_channel;
+
 enum nvhost_intr_action {
 	/**
+	 * Perform cleanup after a submit has completed.
+	 * 'data' points to a channel
+	 */
+	NVHOST_INTR_ACTION_SUBMIT_COMPLETE = 0,
+
+	/**
 	 * Wake up a  task.
 	 * 'data' points to a wait_queue_head_t
 	 */
drivers/video/tegra/host/nvhost_job.c new file +390 -0

88 lines not on this page · raw message

drivers/video/tegra/host/nvhost_memmgr.c new file +160 -0

160 lines not on this page · raw message

drivers/video/tegra/host/nvhost_memmgr.h new file +65 -0

65 lines not on this page · raw message

drivers/video/tegra/host/nvhost_syncpt.c +6 -0
index 6ef0ba4..f61b924 100644

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

drivers/video/tegra/host/nvhost_syncpt.h +2 -0
index dbd3890..93ec123 100644

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

include/linux/nvhost.h +149 -0

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

#108 lore raw

RFC v2 8/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    |  231 +++++++++++++++++++++++++++++++++++++++-
 drivers/gpu/drm/tegra/drm.h    |   42 ++++++--
 drivers/gpu/drm/tegra/gr2d.c   |  224 ++++++++++++++++++++++++++++++++++++++
 include/drm/tegra_drm.h        |  129 ++++++++++++++++++++++
 5 files changed, 615 insertions(+), 13 deletions(-)
 create mode 100644 drivers/gpu/drm/tegra/gr2d.c
 create mode 100644 include/drm/tegra_drm.h
drivers/gpu/drm/tegra/Makefile +1 -1
index 53ea383..5e85042 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 tvo.o dsi.o
 tegra-drm-y += plane.o dmabuf.o
 
drivers/gpu/drm/tegra/drm.c +229 -2

273 lines not on this page · raw message

drivers/gpu/drm/tegra/drm.h +32 -10

74 lines not on this page · raw message

drivers/gpu/drm/tegra/gr2d.c new file +224 -0

224 lines not on this page · raw message

include/drm/tegra_drm.h new file +129 -0

129 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#107 lore raw

RFC v2 7/8 gpu: drm: tegra: Prime support

In reply to Terje Bergstrom

From: Arto Merilainen <[email protected]>

This patch introduces support for exporting allocated memory as dmabuf objects. Exported buffers are used for delivering data to nvhost driver.

---
 drivers/gpu/drm/tegra/Makefile |    2 +-
 drivers/gpu/drm/tegra/dmabuf.c |  150 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/tegra/drm.c    |    9 ++-
 drivers/gpu/drm/tegra/drm.h    |    6 ++
 4 files changed, 165 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/tegra/dmabuf.c
drivers/gpu/drm/tegra/Makefile +1 -1
index 57a334d..53ea383 100644
@@ -3,6 +3,6 @@ ccflags-$(CONFIG_DRM_TEGRA_DEBUG) += -DDEBUG
 
 tegra-drm-y := drm.o fb.o dc.o
 tegra-drm-y += output.o rgb.o hdmi.o tvo.o dsi.o
-tegra-drm-y += plane.o
+tegra-drm-y += plane.o dmabuf.o
 
 obj-$(CONFIG_DRM_TEGRA) += tegra-drm.o
drivers/gpu/drm/tegra/dmabuf.c new file +150 -0

150 lines not on this page · raw message

drivers/gpu/drm/tegra/drm.c +8 -1
index cba2d1d..f78a31b 100644
@@ -251,7 +251,8 @@ static const struct file_operations tegra_drm_fops = {
 };
 
 struct drm_driver tegra_drm_driver = {
-	.driver_features = DRIVER_BUS_PLATFORM | DRIVER_MODESET | DRIVER_GEM,
+	.driver_features = DRIVER_BUS_PLATFORM | DRIVER_MODESET | DRIVER_GEM |
+		DRIVER_PRIME,
 	.load = tegra_drm_load,
 	.unload = tegra_drm_unload,
 	.open = tegra_drm_open,
@@ -267,6 +268,12 @@ struct drm_driver tegra_drm_driver = {
 	.num_ioctls = ARRAY_SIZE(tegra_drm_ioctls),
 	.fops = &tegra_drm_fops,
 
+	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
+	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
+
+	.gem_prime_export = tegra_dmabuf_export,
+	.gem_prime_import = tegra_dmabuf_import,
+
 	.name = DRIVER_NAME,
 	.desc = DRIVER_DESC,
 	.date = DRIVER_DATE,
drivers/gpu/drm/tegra/drm.h +6 -0
index b2f9f10..1267a38 100644
@@ -227,4 +227,10 @@ extern struct platform_driver tegra_dsi_driver;
 extern struct platform_driver tegra_dc_driver;
 extern struct drm_driver tegra_drm_driver;
 
+/* from dmabuf.c */
+struct dma_buf *tegra_dmabuf_export(struct drm_device *drm_dev,
+				struct drm_gem_object *obj, int flags);
+struct drm_gem_object *tegra_dmabuf_import(struct drm_device *drm_dev,
+					struct dma_buf *dmabuf);
+
 #endif /* TEGRA_DRM_H */
Signature · 1 line
1.7.9.5
#53 lore raw

RFC v2 4/8 video: tegra: 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 submit.

---
 drivers/video/tegra/host/Makefile               |    1 +
 drivers/video/tegra/host/bus_client.c           |    3 +
 drivers/video/tegra/host/chip_support.h         |   16 +
 drivers/video/tegra/host/debug.c                |  252 ++++++++++++++
 drivers/video/tegra/host/debug.h                |   50 +++
 drivers/video/tegra/host/host1x/host1x.c        |    3 +
 drivers/video/tegra/host/host1x/host1x01.c      |    2 +
 drivers/video/tegra/host/host1x/host1x_cdma.c   |    3 +
 drivers/video/tegra/host/host1x/host1x_debug.c  |  405 +++++++++++++++++++++++
 drivers/video/tegra/host/host1x/host1x_syncpt.c |    1 +
 drivers/video/tegra/host/nvhost_cdma.c          |    1 +
 drivers/video/tegra/host/nvhost_syncpt.c        |    2 +
 12 files changed, 739 insertions(+)
 create mode 100644 drivers/video/tegra/host/debug.c
 create mode 100644 drivers/video/tegra/host/debug.h
 create mode 100644 drivers/video/tegra/host/host1x/host1x_debug.c
drivers/video/tegra/host/Makefile +1 -0
index 128ad03..9553b3a 100644
@@ -8,6 +8,7 @@ nvhost-objs = \
 	nvhost_channel.o \
 	nvhost_job.o \
 	dev.o \
+	debug.o \
 	bus_client.o \
 	chip_support.o \
 	nvhost_memmgr.o \
drivers/video/tegra/host/bus_client.c +3 -0
index 3986185..1b02836 100644
@@ -35,6 +35,7 @@
 
 #include <linux/nvhost.h>
 
+#include "debug.h"
 #include "dev.h"
 #include "nvhost_memmgr.h"
 #include "chip_support.h"
@@ -68,6 +69,8 @@ int nvhost_client_device_init(struct platform_device *dev)
 	if (err)
 		goto fail;
 
+	nvhost_device_debug_init(dev);
+
 	dev_info(&dev->dev, "initialized\n");
 
 	return 0;
drivers/video/tegra/host/chip_support.h +16 -0
index ff141ed..efc8c10 100644
@@ -76,6 +76,21 @@ struct nvhost_pushbuffer_ops {
 	u32 (*putptr)(struct push_buffer *);
 };
 
+struct nvhost_debug_ops {
+	void (*debug_init)(struct dentry *de);
+	void (*show_channel_cdma)(struct nvhost_master *,
+				  struct nvhost_channel *,
+				  struct output *,
+				  int chid);
+	void (*show_channel_fifo)(struct nvhost_master *,
+				  struct nvhost_channel *,
+				  struct output *,
+				  int chid);
+	void (*show_mlocks)(struct nvhost_master *m,
+			    struct output *o);
+
+};
+
 struct nvhost_syncpt_ops {
 	void (*reset)(struct nvhost_syncpt *, u32 id);
 	void (*reset_wait_base)(struct nvhost_syncpt *, u32 id);
@@ -113,6 +128,7 @@ struct nvhost_chip_support {
 	struct nvhost_channel_ops channel;
 	struct nvhost_cdma_ops cdma;
 	struct nvhost_pushbuffer_ops push_buffer;
+	struct nvhost_debug_ops debug;
 	struct nvhost_syncpt_ops syncpt;
 	struct nvhost_intr_ops intr;
 	struct nvhost_dev_ops nvhost_dev;
drivers/video/tegra/host/debug.c new file +252 -0

252 lines not on this page · raw message

drivers/video/tegra/host/debug.h new file +50 -0

50 lines not on this page · raw message

drivers/video/tegra/host/host1x/host1x.c +3 -0
index 8033b2d..fb2a0d2 100644
@@ -31,6 +31,7 @@
 
 #include "dev.h"
 #include "host1x/host1x.h"
+#include "debug.h"
 #include "nvhost_acm.h"
 #include "nvhost_channel.h"
 #include "chip_support.h"
@@ -184,6 +185,8 @@ static int __devinit nvhost_probe(struct platform_device *dev)
 	if (err)
 		goto fail;
 
+	nvhost_debug_init(host);
+
 	dev_info(&dev->dev, "initialized\n");
 
 	return 0;
drivers/video/tegra/host/host1x/host1x01.c +2 -0
index cd97339..2c69200 100644
@@ -48,6 +48,7 @@ struct nvhost_channel *t20_alloc_nvhost_channel(struct platform_device *dev)
 
 #include "host1x/host1x_channel.c"
 #include "host1x/host1x_cdma.c"
+#include "host1x/host1x_debug.c"
 #include "host1x/host1x_syncpt.c"
 #include "host1x/host1x_intr.c"
 
@@ -57,6 +58,7 @@ int nvhost_init_host1x01_support(struct nvhost_master *host,
 	op->channel = host1x_channel_ops;
 	op->cdma = host1x_cdma_ops;
 	op->push_buffer = host1x_pushbuffer_ops;
+	op->debug = host1x_debug_ops;
 	host->sync_aperture = host->aperture + HOST1X_CHANNEL_SYNC_REG_BASE;
 	op->syncpt = host1x_syncpt_ops;
 	op->intr = host1x_intr_ops;
drivers/video/tegra/host/host1x/host1x_cdma.c +3 -0
index 07f0758..bbc021e 100644
@@ -25,6 +25,7 @@
 #include "nvhost_cdma.h"
 #include "nvhost_channel.h"
 #include "dev.h"
+#include "debug.h"
 #include "chip_support.h"
 #include "nvhost_memmgr.h"
 
@@ -413,6 +414,8 @@ static void cdma_timeout_handler(struct work_struct *work)
 	sp = &dev->syncpt;
 	ch = cdma_to_channel(cdma);
 
+	nvhost_debug_dump(cdma_to_dev(cdma));
+
 	mutex_lock(&cdma->lock);
 
 	if (!cdma->timeout.clientid) {
drivers/video/tegra/host/host1x/host1x_debug.c new file +405 -0

405 lines not on this page · raw message

drivers/video/tegra/host/host1x/host1x_syncpt.c +1 -0
index e47bd71..eadb8cf 100644
@@ -100,6 +100,7 @@ static void host1x_syncpt_cpu_incr(struct nvhost_syncpt *sp, u32 id)
 		dev_err(&syncpt_to_dev(sp)->dev->dev,
 			"Trying to increment syncpoint id %d beyond max\n",
 			id);
+		nvhost_debug_dump(syncpt_to_dev(sp));
 		return;
 	}
 	writel(BIT_MASK(id), dev->sync_aperture +
drivers/video/tegra/host/nvhost_cdma.c +1 -0
index e581836..50b1e7d 100644
@@ -21,6 +21,7 @@
 #include "nvhost_cdma.h"
 #include "nvhost_channel.h"
 #include "dev.h"
+#include "debug.h"
 #include "nvhost_memmgr.h"
 #include "chip_support.h"
 #include <asm/cacheflush.h>
drivers/video/tegra/host/nvhost_syncpt.c +2 -0
index f61b924..fc1c19c 100644
@@ -24,6 +24,7 @@
 #include "nvhost_syncpt.h"
 #include "nvhost_acm.h"
 #include "host1x/host1x.h"
+#include "debug.h"
 #include "chip_support.h"
 
 #define MAX_SYNCPT_LENGTH	5
@@ -222,6 +223,7 @@ int nvhost_syncpt_wait_timeout(struct nvhost_syncpt *sp, u32 id,
 						"is timeout %d too low?\n",
 						low_timeout);
 				}
+				nvhost_debug_dump(syncpt_to_dev(sp));
 			}
 			check_count++;
 		}
Signature · 1 line
1.7.9.5
#1 lore raw

RFC v2 1/8 video: tegra: Add nvhost driver

In reply to Terje Bergstrom

Add nvhost, the driver for host1x. This patch adds support for reading and incrementing sync points and dynamic power management.

---
 drivers/video/Kconfig                              |    2 +
 drivers/video/Makefile                             |    2 +
 drivers/video/tegra/host/Kconfig                   |    5 +
 drivers/video/tegra/host/Makefile                  |   10 +
 drivers/video/tegra/host/chip_support.c            |   48 ++
 drivers/video/tegra/host/chip_support.h            |   52 +++
 drivers/video/tegra/host/dev.c                     |   96 ++++
 drivers/video/tegra/host/host1x/Makefile           |    7 +
 drivers/video/tegra/host/host1x/host1x.c           |  204 +++++++++
 drivers/video/tegra/host/host1x/host1x.h           |   78 ++++
 drivers/video/tegra/host/host1x/host1x01.c         |   37 ++
 drivers/video/tegra/host/host1x/host1x01.h         |   29 ++
 .../video/tegra/host/host1x/host1x01_hardware.h    |   36 ++
 drivers/video/tegra/host/host1x/host1x_syncpt.c    |  156 +++++++
 drivers/video/tegra/host/host1x/hw_host1x01_sync.h |  398 ++++++++++++++++
 drivers/video/tegra/host/nvhost_acm.c              |  481 ++++++++++++++++++++
 drivers/video/tegra/host/nvhost_acm.h              |   45 ++
 drivers/video/tegra/host/nvhost_syncpt.c           |  333 ++++++++++++++
 drivers/video/tegra/host/nvhost_syncpt.h           |  136 ++++++
 include/linux/nvhost.h                             |  143 ++++++
 20 files changed, 2298 insertions(+)
 create mode 100644 drivers/video/tegra/host/Kconfig
 create mode 100644 drivers/video/tegra/host/Makefile
 create mode 100644 drivers/video/tegra/host/chip_support.c
 create mode 100644 drivers/video/tegra/host/chip_support.h
 create mode 100644 drivers/video/tegra/host/dev.c
 create mode 100644 drivers/video/tegra/host/host1x/Makefile
 create mode 100644 drivers/video/tegra/host/host1x/host1x.c
 create mode 100644 drivers/video/tegra/host/host1x/host1x.h
 create mode 100644 drivers/video/tegra/host/host1x/host1x01.c
 create mode 100644 drivers/video/tegra/host/host1x/host1x01.h
 create mode 100644 drivers/video/tegra/host/host1x/host1x01_hardware.h
 create mode 100644 drivers/video/tegra/host/host1x/host1x_syncpt.c
 create mode 100644 drivers/video/tegra/host/host1x/hw_host1x01_sync.h
 create mode 100644 drivers/video/tegra/host/nvhost_acm.c
 create mode 100644 drivers/video/tegra/host/nvhost_acm.h
 create mode 100644 drivers/video/tegra/host/nvhost_syncpt.c
 create mode 100644 drivers/video/tegra/host/nvhost_syncpt.h
 create mode 100644 include/linux/nvhost.h
drivers/video/Kconfig +2 -0
index fb9a14e..94c861b 100644
@@ -2463,4 +2463,6 @@ config FB_SH_MOBILE_MERAM
 	  Up to 4 memory channels can be configured, allowing 4 RGB or
 	  2 YCbCr framebuffers to be configured.
 
+source "drivers/video/tegra/host/Kconfig"
+
 endmenu
drivers/video/Makefile +2 -0
index b936b00..61a4287 100644
@@ -17,6 +17,8 @@ obj-y				  += backlight/
 
 obj-$(CONFIG_EXYNOS_VIDEO)     += exynos/
 
+obj-$(CONFIG_TEGRA_HOST1X)     += tegra/host/
+
 obj-$(CONFIG_FB_CFB_FILLRECT)  += cfbfillrect.o
 obj-$(CONFIG_FB_CFB_COPYAREA)  += cfbcopyarea.o
 obj-$(CONFIG_FB_CFB_IMAGEBLIT) += cfbimgblt.o
drivers/video/tegra/host/Kconfig new file +5 -0
new file mode 100644
index 0000000..ebe9bbc
@@ -0,0 +1,5 @@
+config TEGRA_HOST1X
+	tristate "Tegra host1x driver"
+	help
+	  Driver for the Tegra host1x hardware.
+
drivers/video/tegra/host/Makefile new file +10 -0
new file mode 100644
index 0000000..3edab4a
@@ -0,0 +1,10 @@
+ccflags-y = -Idrivers/video/tegra/host
+
+nvhost-objs = \
+	nvhost_acm.o \
+	nvhost_syncpt.o \
+	dev.o \
+	chip_support.o
+
+obj-$(CONFIG_TEGRA_HOST1X) += host1x/
+obj-$(CONFIG_TEGRA_HOST1X) += nvhost.o
drivers/video/tegra/host/chip_support.c new file +48 -0

48 lines not on this page · raw message

drivers/video/tegra/host/chip_support.h new file +52 -0

52 lines not on this page · raw message

drivers/video/tegra/host/dev.c new file +96 -0

96 lines not on this page · raw message

drivers/video/tegra/host/host1x/Makefile new file +7 -0
new file mode 100644
index 0000000..330d507
@@ -0,0 +1,7 @@
+ccflags-y = -Idrivers/video/tegra/host
+
+nvhost-host1x-objs  = \
+	host1x.o \
+	host1x01.o
+
+obj-$(CONFIG_TEGRA_HOST1X) += nvhost-host1x.o
drivers/video/tegra/host/host1x/host1x.c new file +204 -0

204 lines not on this page · raw message

drivers/video/tegra/host/host1x/host1x.h new file +78 -0

78 lines not on this page · raw message

drivers/video/tegra/host/host1x/host1x01.c new file +37 -0
new file mode 100644
index 0000000..d53302d
@@ -0,0 +1,37 @@
+/*
+ * drivers/video/tegra/host/host1x01.c
+ *
+ * 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/nvhost.h>
+
+#include "host1x/host1x01.h"
+#include "host1x/host1x.h"
+#include "host1x/host1x01_hardware.h"
+#include "chip_support.h"
+
+#include "host1x/host1x_syncpt.c"
+
+int nvhost_init_host1x01_support(struct nvhost_master *host,
+	struct nvhost_chip_support *op)
+{
+	host->sync_aperture = host->aperture + HOST1X_CHANNEL_SYNC_REG_BASE;
+	op->syncpt = host1x_syncpt_ops;
+
+	return 0;
+}
drivers/video/tegra/host/host1x/host1x01.h new file +29 -0
new file mode 100644
index 0000000..91624d66
@@ -0,0 +1,29 @@
+/*
+ * drivers/video/tegra/host/host1x01.h
+ *
+ * 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 NVHOST_HOST1X01_H
+#define NVHOST_HOST1X01_H
+
+struct nvhost_master;
+struct nvhost_chip_support;
+
+int nvhost_init_host1x01_support(struct nvhost_master *,
+	struct nvhost_chip_support *);
+
+#endif /* NVHOST_HOST1X01_H_ */
drivers/video/tegra/host/host1x/host1x01_hardware.h new file +36 -0
new file mode 100644
index 0000000..0da7e06
@@ -0,0 +1,36 @@
+/*
+ * drivers/video/tegra/host/host1x/host1x01_hardware.h
+ *
+ * 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 __NVHOST_HOST1X01_HARDWARE_H
+#define __NVHOST_HOST1X01_HARDWARE_H
+
+#include <linux/types.h>
+#include <linux/bitops.h>
+#include "hw_host1x01_sync.h"
+
+/* channel registers */
+#define NV_HOST1X_CHANNEL_MAP_SIZE_BYTES 16384
+#define NV_HOST1X_SYNC_MLOCK_NUM 16
+
+/* sync registers */
+#define HOST1X_CHANNEL_SYNC_REG_BASE   0x3000
+#define NV_HOST1X_NB_MLOCKS 16
+
+#endif
drivers/video/tegra/host/host1x/host1x_syncpt.c new file +156 -0

156 lines not on this page · raw message

drivers/video/tegra/host/host1x/hw_host1x01_sync.h new file +398 -0

398 lines not on this page · raw message

drivers/video/tegra/host/nvhost_acm.c new file +481 -0

481 lines not on this page · raw message

drivers/video/tegra/host/nvhost_acm.h new file +45 -0

45 lines not on this page · raw message

drivers/video/tegra/host/nvhost_syncpt.c new file +333 -0

333 lines not on this page · raw message

drivers/video/tegra/host/nvhost_syncpt.h new file +136 -0

136 lines not on this page · raw message

include/linux/nvhost.h new file +143 -0

143 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#54 lore raw

RFC v2 5/8 ARM: tegra: Add auxiliary data for nvhost

In reply to Terje Bergstrom

Add SoC specific auxiliary data to host1x and gr2d. nvhost uses this data.

---
 arch/arm/mach-tegra/board-dt-tegra20.c    |   38 ++++++++++++++++++++++++++++-
 arch/arm/mach-tegra/board-dt-tegra30.c    |   38 ++++++++++++++++++++++++++++-
 arch/arm/mach-tegra/tegra20_clocks_data.c |    8 +++---
 arch/arm/mach-tegra/tegra30_clocks_data.c |    2 ++
 4 files changed, 80 insertions(+), 6 deletions(-)
arch/arm/mach-tegra/board-dt-tegra20.c +37 -1
index 1d30eac..c695392 100644
@@ -33,6 +33,7 @@
 #include <linux/i2c.h>
 #include <linux/i2c-tegra.h>
 #include <linux/usb/tegra_usb_phy.h>
+#include <linux/nvhost.h>
 
 #include <asm/hardware/gic.h>
 #include <asm/mach-types.h>
@@ -45,6 +46,38 @@
 #include "common.h"
 #include "iomap.h"
 
+static const char *host1x_syncpt_names[32] = {
+	[0] = "gfx_host",
+	[NVSYNCPT_2D_0] = "2d_0",
+	[NVSYNCPT_2D_1] = "2d_1",
+	[NVSYNCPT_VBLANK0] = "vblank0",
+	[NVSYNCPT_VBLANK1] = "vblank1",
+};
+
+static struct host1x_device_info host1x_info = {
+	.nb_channels	= 8,
+	.nb_pts		= 32,
+	.nb_mlocks	= 16,
+	.nb_bases	= 8,
+	.syncpt_names	= host1x_syncpt_names,
+	.client_managed	= NVSYNCPTS_CLIENT_MANAGED,
+};
+
+static struct nvhost_device_data tegra_host1x_info = {
+	.clocks = { {"host1x", UINT_MAX} },
+	NVHOST_MODULE_NO_POWERGATE_IDS,
+	.private_data = &host1x_info,
+};
+
+static struct nvhost_device_data tegra_gr2d_info = {
+	.index		= 2,
+	.syncpts	= BIT(NVSYNCPT_2D_0) | BIT(NVSYNCPT_2D_1),
+	.clocks		= { {"gr2d", UINT_MAX, true}, {"epp", UINT_MAX, true} },
+	NVHOST_MODULE_NO_POWERGATE_IDS,
+	.clockgate_delay = 0,
+	.serialize	= true,
+};
+
 struct tegra_ehci_platform_data tegra_ehci1_pdata = {
 	.operating_mode = TEGRA_USB_OTG,
 	.power_down_on_bus_suspend = 1,
@@ -94,13 +127,16 @@ struct of_dev_auxdata tegra20_auxdata_lookup[] __initdata = {
 	OF_DEV_AUXDATA("nvidia,tegra20-slink", 0x7000D600, "spi_tegra.1", NULL),
 	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-host1x", 0x50000000, "host1x",
+			&tegra_host1x_info),
 	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),
 	OF_DEV_AUXDATA("nvidia,tegra20-dsi", 0x54300000, "dsi", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra20-tvo", 0x542c0000, "tvo", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra20-nand", 0x70008000, "tegra-nand", NULL),
+	OF_DEV_AUXDATA("nvidia,tegra20-gr2d", 0x54140000, "tegra-gr2d",
+		       &tegra_gr2d_info),
 	{}
 };
 
arch/arm/mach-tegra/board-dt-tegra30.c +37 -1
index 6497d12..1afa68b 100644
@@ -29,6 +29,7 @@
 #include <linux/of_fdt.h>
 #include <linux/of_irq.h>
 #include <linux/of_platform.h>
+#include <linux/nvhost.h>
 
 #include <asm/mach/arch.h>
 #include <asm/hardware/gic.h>
@@ -38,6 +39,38 @@
 #include "common.h"
 #include "iomap.h"
 
+static const char *host1x_syncpt_names[32] = {
+	[0] = "gfx_host",
+	[NVSYNCPT_2D_0] = "2d_0",
+	[NVSYNCPT_2D_1] = "2d_1",
+	[NVSYNCPT_VBLANK0] = "vblank0",
+	[NVSYNCPT_VBLANK1] = "vblank1",
+};
+
+static struct host1x_device_info host1x_info = {
+	.nb_channels	= 8,
+	.nb_pts		= 32,
+	.nb_mlocks	= 16,
+	.nb_bases	= 8,
+	.syncpt_names	= host1x_syncpt_names,
+	.client_managed	= NVSYNCPTS_CLIENT_MANAGED,
+};
+
+static struct nvhost_device_data tegra_host1x_info = {
+	.clocks = { {"host1x", UINT_MAX} },
+	NVHOST_MODULE_NO_POWERGATE_IDS,
+	.private_data = &host1x_info,
+};
+
+static struct nvhost_device_data tegra_gr2d_info = {
+	.index		= 2,
+	.syncpts	= BIT(NVSYNCPT_2D_0) | BIT(NVSYNCPT_2D_1),
+	.clocks		= { {"gr2d", UINT_MAX, true}, {"epp", UINT_MAX, true} },
+	NVHOST_MODULE_NO_POWERGATE_IDS,
+	.clockgate_delay = 0,
+	.serialize	= true,
+};
+
 struct of_dev_auxdata tegra30_auxdata_lookup[] __initdata = {
 	OF_DEV_AUXDATA("nvidia,tegra20-sdhci", 0x78000000, "sdhci-tegra.0", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra20-sdhci", 0x78000200, "sdhci-tegra.1", NULL),
@@ -57,12 +90,15 @@ struct of_dev_auxdata tegra30_auxdata_lookup[] __initdata = {
 	OF_DEV_AUXDATA("nvidia,tegra30-slink", 0x7000DA00, "spi_tegra.3", NULL),
 	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-host1x", 0x50000000, "host1x",
+			&tegra_host1x_info),
 	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),
 	OF_DEV_AUXDATA("nvidia,tegra30-dsi", 0x54300000, "dsi", NULL),
 	OF_DEV_AUXDATA("nvidia,tegra30-tvo", 0x542c0000, "tvo", NULL),
+	OF_DEV_AUXDATA("nvidia,tegra30-gr2d", 0x54140000, "gr2d",
+		       &tegra_gr2d_info),
 	{}
 };
 
arch/arm/mach-tegra/tegra20_clocks_data.c +4 -4
index 7f049ac..3314e50 100644
@@ -1041,10 +1041,10 @@ 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("3d",	"tegra_grhost",	"gr3d"),
-	CLK_DUPLICATE("epp",	"tegra_grhost",	"epp"),
-	CLK_DUPLICATE("mpe",	"tegra_grhost",	"mpe"),
+	CLK_DUPLICATE("2d",	NULL,		"gr2d"),
+	CLK_DUPLICATE("3d",	NULL,		"gr3d"),
+	CLK_DUPLICATE("epp",	NULL,		"epp"),
+	CLK_DUPLICATE("mpe",	NULL,		"mpe"),
 	CLK_DUPLICATE("cop",	"tegra-avp",	"cop"),
 	CLK_DUPLICATE("vde",	"tegra-aes",	"vde"),
 	CLK_DUPLICATE("cclk",	NULL,		"cpu"),
arch/arm/mach-tegra/tegra30_clocks_data.c +2 -0
index 6942c7a..f30bd54 100644
@@ -1338,6 +1338,8 @@ 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", NULL, "gr2d"),
+	CLK_DUPLICATE("epp", NULL, "epp"),
 };
 
 struct clk *tegra_ptr_clks[] = {
Signature · 1 line
1.7.9.5
#109 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

In reply to Terje Bergstrom

include/drm/tegra_drm.h line 94

Quoted 3 lines · Terje Bergstrom
include/drm/tegra_drm.h new file +2 -0
+struct tegra_drm_submit_args {
+       void *context;

Just a quick comment..

You shouldn't really use ptr here, but instead use a 64bit type so that you don't run into issues later for armv8/64bit. Same comment applies in a few other places too.

I'll try and spend a bit more time going through this in more detail in the coming days

BR,
-R

Quoted 16 lines
include/drm/tegra_drm.h new file +16 -0
+       __u32 num_syncpt_incrs;
+       __u32 num_cmdbufs;
+       __u32 num_relocs;
+       __u32 submit_version;
+       __u32 num_waitchks;
+       __u32 waitchk_mask;
+       __u32 timeout;
+       struct tegra_drm_syncpt_incrs *syncpt_incrs;
+       struct tegra_drm_cmdbuf *cmdbufs;
+       struct tegra_drm_reloc *relocs;
+       struct tegra_drm_waitchk *waitchks;
+
+       __u32 pad[5];           /* future expansion */
+       __u32 fence;            /* Return value */
+};
+
maintainer
#110 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

In reply to Terje Bergstrom

drivers/gpu/drm/tegra/drm.c static int tegra_drm_unload(struct drm_device *drm) · line 192

Quoted 13 lines

static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp) {

drivers/gpu/drm/tegra/drm.c +10 -1
-       return 0;
+       struct tegra_drm_fpriv *fpriv;
+       int err = 0;
+
+       fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL);
+       if (!fpriv)
+               return -ENOMEM;
+
+       INIT_LIST_HEAD(&fpriv->contexts);
+       filp->driver_priv = fpriv;
+

who frees this?

include/drm/tegra_drm.h line 46

Quoted 3 lines
include/drm/tegra_drm.h new file +3 -0
+struct tegra_drm_syncpt_incr_args {
+       __u32 id;
+};

add 32-bits of padding here

include/drm/tegra_drm.h line 59

Quoted 13 lines
include/drm/tegra_drm.h new file +13 -0
+
+struct tegra_drm_syncpt_wait_args {
+       __u32 id;
+       __u32 thresh;
+       __s32 timeout;
+       __u32 value;
+};
+
+#define DRM_TEGRA_NO_TIMEOUT   (-1)
+
+struct tegra_drm_open_channel_args {
+       __u32 class;
+       void *context;

no pointers use u64, align them to 64-bits, so 32-bits of padding,

include/drm/tegra_drm.h line 64

Quoted 5 lines
include/drm/tegra_drm.h new file +5 -0
+};
+
+struct tegra_drm_get_channel_param_args {
+       void *context;
+       __u32 value;

Same padding + uint64_t for void *

include/drm/tegra_drm.h line 76

Quoted 12 lines
include/drm/tegra_drm.h new file +12 -0
+};
+
+struct tegra_drm_syncpt_incr {
+       __u32 syncpt_id;
+       __u32 syncpt_incrs;
+};
+
+struct tegra_drm_cmdbuf {
+       __u32 mem;
+       __u32 offset;
+       __u32 words;
+};

add padding

include/drm/tegra_drm.h line 84

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

add padding

Quoted 15 lines
include/drm/tegra_drm.h new file +15 -0
+
+struct tegra_drm_waitchk {
+       __u32 mem;
+       __u32 offset;
+       __u32 syncpt_id;
+       __u32 thresh;
+};
+
+struct tegra_drm_submit_args {
+       void *context;
+       __u32 num_syncpt_incrs;
+       __u32 num_cmdbufs;
+       __u32 num_relocs;
+       __u32 submit_version;
+       __u32 num_waitchks;

include/drm/tegra_drm.h line 109

Quoted 10 lines
include/drm/tegra_drm.h new file +10 -0
+       __u32 waitchk_mask;
+       __u32 timeout;
+       struct tegra_drm_syncpt_incrs *syncpt_incrs;
+       struct tegra_drm_cmdbuf *cmdbufs;
+       struct tegra_drm_reloc *relocs;
+       struct tegra_drm_waitchk *waitchks;
+
+       __u32 pad[5];           /* future expansion */
+       __u32 fence;            /* Return value */
+};

lose all the pointers for 64-bit aligned uint64_t.

Probably should align all of these on __u64 and __u32 usage if possible.

i'll look at the rest of the patches, but I need to know what commands can be submitted via this interface and what are the security implications of it.

Dave.

#55 lore raw

Re: [RFC v2 5/8] ARM: tegra: Add auxiliary data for nvhost

In reply to Terje Bergstrom
Quoted 5 lines · Terje Bergstrom

Add SoC specific auxiliary data to host1x and gr2d. nvhost uses this data.

Arto's S-o-b really should be first and yours last since you're (Terje) the one who touched the patches last.

arch/arm/mach-tegra/board-dt-tegra20.c

Quoted 1 line
arch/arm/mach-tegra/board-dt-tegra20.c +0 -0

I think none of the changes the board-dt-tegra*.c should be made.

AUXDATA is a temporary measure to keep things working during the transition to device tree. We want to remove entries from the AUXDATA tables rather than add them. The only thing that's stopping us from doing so right now is the lack of DT-based clock lookups, which hence require devices to have a specific name.

arch/arm/mach-tegra/board-dt-tegra20.c line 75

Quoted 5 lines
arch/arm/mach-tegra/board-dt-tegra20.c +4 -0
+static struct nvhost_device_data tegra_host1x_info = {
+	.clocks = { {"host1x", UINT_MAX} },
 
+static struct nvhost_device_data tegra_gr2d_info = {
+	.clocks		= { {"gr2d", UINT_MAX, true}, {"epp", UINT_MAX, true} },

Clock names shouldn't be passed in platform data; instead, clk_get() should be passed the device object and device-relative (i.e. not global) clock name. I expect if the driver is fixed to make this change, the changes to tegra*_clocks_data.c won't be needed either.

#56 lore raw

Re: [RFC v2 5/8] ARM: tegra: Add auxiliary data for nvhost

Quoted 4 lines · Stephen Warren

Clock names shouldn't be passed in platform data; instead, clk_get() should be passed the device object and device-relative (i.e. not global) clock name. I expect if the driver is fixed to make this change, the changes to tegra*_clocks_data.c won't be needed either.

Isn't this code doing exactly that - getting a device relative clock, nvhost_module_init() in nvhost.acm.c:

(...)

	/* initialize clocks to known state */
	while (pdata->clocks[i].name && i < NVHOST_MODULE_MAX_CLOCKS) {
		long rate = pdata->clocks[i].default_rate;
		struct clk *c;

		c = devm_clk_get(&dev->dev, pdata->clocks[i].name);
		if (IS_ERR_OR_NULL(c)) {
			dev_err(&dev->dev, "Cannot get clock %s\n",
					pdata->clocks[i].name);
			return -ENODEV;
		}

		rate = clk_round_rate(c, rate);
		clk_prepare_enable(c);
		clk_set_rate(c, rate);
		clk_disable_unprepare(c);
		pdata->clk[i] = c;
		i++;
	}

(...)

Without the clock changes, the clocks in board files are now assigned to devid "tegra_grhost". I guess the correct way to do this would be to assign them to "tegra-gr2d" (2d, epp) and "host1x" - except if we also want to drop "tegra-" from the device name.

Terje

#111 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

In reply to Dave Airlie
Quoted 7 lines · Dave Airlie
Quoted 7 lines

static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp) {

drivers/gpu/drm/tegra/drm.c +4 -1
-       return 0;
+       struct tegra_drm_fpriv *fpriv;
+       int err = 0;
+
+       fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL);
Quoted 8 lines

drivers/gpu/drm/tegra/drm.c static int tegra_drm_unload(struct drm_device *drm) · line 192

Quoted 6 lines
drivers/gpu/drm/tegra/drm.c +6 -0
+       if (!fpriv)
+               return -ENOMEM;
+
+       INIT_LIST_HEAD(&fpriv->contexts);
+       filp->driver_priv = fpriv;
+

who frees this?

Probably nobody. Will fix.

Quoted 6 lines

include/drm/tegra_drm.h line 46

Quoted 3 lines
include/drm/tegra_drm.h new file +3 -0
+struct tegra_drm_syncpt_incr_args {
+       __u32 id;
+};

add 32-bits of padding here

Quoted 15 lines

include/drm/tegra_drm.h line 59

Quoted 13 lines
include/drm/tegra_drm.h new file +13 -0
+
+struct tegra_drm_syncpt_wait_args {
+       __u32 id;
+       __u32 thresh;
+       __s32 timeout;
+       __u32 value;
+};
+
+#define DRM_TEGRA_NO_TIMEOUT   (-1)
+
+struct tegra_drm_open_channel_args {
+       __u32 class;
+       void *context;

no pointers use u64, align them to 64-bits, so 32-bits of padding,

I'll add the paddings and change pointers to u64's to all of the structs in this file.

Quoted 3 lines

i'll look at the rest of the patches, but I need to know what commands can be submitted via this interface and what are the security implications of it.

All of the commands are memory operations (copy, clear, rotate, etc) involving either one or two memory regions that are defined via dmabuf fd's and offsets. The commands can also contain plain device virtual addresses and 2D would be happy to oblige as long as the memory is mapped to it.

There are a few ways to help the situation. None of them are perfect.

On Tegra30 we could allocate an address space per process. This would mean that max 3 processes would be able to use the 2D unit at one time, assuming that other devices are find using the one remaining address space. On Tegra20 this is not an option.

Second would be using device permissions - only allow selected processes to access 2D.

Third would be having a firewall in 2D driver checking the stream and ensuring all registers that accept addresses are written by values derived from dmabufs. I haven't tried implementing this, but it'd involve a lookup table in kernel and CPU reading through the command stream. Offsets and sizes would also need to be validated. There would be a performance hit.

Fourth would be to move the creation of streams to kernel space. That'd mean moving the whole 2D driver and host1x command stream handling to kernel space and quite a lot of time spent in kernel. I'm not too keen on this for obvious reasons.

Other ideas are obviously welcome.

Thanks!

Terje

maintainer
#112 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

Quoted 7 lines

Third would be having a firewall in 2D driver checking the stream and ensuring all registers that accept addresses are written by values derived from dmabufs. I haven't tried implementing this, but it'd involve a lookup table in kernel and CPU reading through the command stream. Offsets and sizes would also need to be validated. There would be a performance hit.

This is the standard mechanism, and what exynos does as well.

The per process VM method is also used as an extension to this on some hw.

Dave.

#113 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

Quoted 10 lines · Dave Airlie
Quoted 6 lines

Third would be having a firewall in 2D driver checking the stream and ensuring all registers that accept addresses are written by values derived from dmabufs. I haven't tried implementing this, but it'd involve a lookup table in kernel and CPU reading through the command stream. Offsets and sizes would also need to be validated. There would be a performance hit.

This is the standard mechanism, and what exynos does as well.

The per process VM method is also used as an extension to this on some hw.

Hi,

Thanks for the pointer, I looked at exynos code. It indeed checks the registers written to, but it doesn't prevent overrun by checking sizes of buffers and compare against requests.

Based on my experience with Tegra graphics stack, going through command streams in kernel is bad for performance. For 2D operations this is probably ok as the command streams are pretty simple. Anything more complex is going to cause severe degradation of performance, but it's also outside the scope of this patch set.

If this is the way to go, I'll put the firewall behind a Kconfig flag so that system integrator can decide if his system needs it.

Terje

maintainer
#114 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

Quoted 10 lines · Terje Bergström
Quoted 9 lines · Dave Airlie
Quoted 6 lines

Third would be having a firewall in 2D driver checking the stream and ensuring all registers that accept addresses are written by values derived from dmabufs. I haven't tried implementing this, but it'd involve a lookup table in kernel and CPU reading through the command stream. Offsets and sizes would also need to be validated. There would be a performance hit.

This is the standard mechanism, and what exynos does as well.

Quoted 7 lines
Quoted 1 line

The per process VM method is also used as an extension to this on some hw.

Hi,

Thanks for the pointer, I looked at exynos code. It indeed checks the registers written to, but it doesn't prevent overrun by checking sizes of buffers and compare against requests.

They probably need to add that, its not as important as the base addresses, unless it takes negative strides, generally base addresses means you can target current->uid quite easily!

Quoted 8 lines

Based on my experience with Tegra graphics stack, going through command streams in kernel is bad for performance. For 2D operations this is probably ok as the command streams are pretty simple. Anything more complex is going to cause severe degradation of performance, but it's also outside the scope of this patch set.

If this is the way to go, I'll put the firewall behind a Kconfig flag so that system integrator can decide if his system needs it.

We don't generally make security like this optional :-)

If you do that you should restrict the drm device to root users only, and never let a user with a browser anywhere near it.

Like I know what you guys get away with in closed source world, but here we don't write root holes into our driver deliberately.

Dave.

#115 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

Quoted 7 lines · Dave Airlie
Quoted 3 lines · Terje Bergström

Thanks for the pointer, I looked at exynos code. It indeed checks the registers written to, but it doesn't prevent overrun by checking sizes of buffers and compare against requests.

They probably need to add that, its not as important as the base addresses, unless it takes negative strides, generally base addresses means you can target current->uid quite easily!

Ok. We'll implement the firewall, unless we come up with even a better choice.

Quoted 6 lines
Quoted 2 lines

If this is the way to go, I'll put the firewall behind a Kconfig flag so that system integrator can decide if his system needs it.

We don't generally make security like this optional :-)

If you do that you should restrict the drm device to root users only, and never let a user with a browser anywhere near it.

My thinking was that the system integrator can decide how much he trusts the binaries (incl. browser plugins) in the system. If he trusts the binaries, the firewall can be turned off.

Quoted 2 lines

Like I know what you guys get away with in closed source world, but here we don't write root holes into our driver deliberately.

Duly noted. :-)

Terje

#116 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

Am Dienstag, den 27.11.2012, 10:45 +0200 schrieb Terje Bergström:

Quoted 5 lines · Dave Airlie
Quoted 4 lines · Terje Bergström
Quoted 3 lines

Thanks for the pointer, I looked at exynos code. It indeed checks the registers written to, but it doesn't prevent overrun by checking sizes of buffers and compare against requests.

Quoted 14 lines
Quoted 3 lines

They probably need to add that, its not as important as the base addresses, unless it takes negative strides, generally base addresses means you can target current->uid quite easily!

Ok. We'll implement the firewall, unless we come up with even a better choice.

Quoted 6 lines
Quoted 2 lines

If this is the way to go, I'll put the firewall behind a Kconfig flag so that system integrator can decide if his system needs it.

We don't generally make security like this optional :-)

If you do that you should restrict the drm device to root users only, and never let a user with a browser anywhere near it.

Personally I would never trust any binary, but that's just my personal opinion.

But I'm in favour of having the command stream checking optional, simply backed by the fact that we are likely to use the same 2D driver infrastructure for Tegra 2 and 3. On Tegra 3 we can most likely go without in-depth command stream checking as the graphics core there sits behind the IOMMU, which can provide an appropriate level of security.

Regards,
Lucas

#117 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

Quoted 20 lines · Lucas Stach

Am Dienstag, den 27.11.2012, 10:45 +0200 schrieb Terje Bergström:

Quoted 5 lines · Dave Airlie
Quoted 4 lines · Terje Bergström
Quoted 3 lines

Thanks for the pointer, I looked at exynos code. It indeed checks the registers written to, but it doesn't prevent overrun by checking sizes of buffers and compare against requests.

Quoted 14 lines
Quoted 3 lines

They probably need to add that, its not as important as the base addresses, unless it takes negative strides, generally base addresses means you can target current->uid quite easily!

Ok. We'll implement the firewall, unless we come up with even a better choice.

Quoted 6 lines
Quoted 2 lines

If this is the way to go, I'll put the firewall behind a Kconfig flag so that system integrator can decide if his system needs it.

We don't generally make security like this optional :-)

If you do that you should restrict the drm device to root users only, and never let a user with a browser anywhere near it.

Quoted 8 lines

Personally I would never trust any binary, but that's just my personal opinion.

But I'm in favour of having the command stream checking optional, simply backed by the fact that we are likely to use the same 2D driver infrastructure for Tegra 2 and 3. On Tegra 3 we can most likely go without in-depth command stream checking as the graphics core there sits behind the IOMMU, which can provide an appropriate level of security.

But in that case it should be made mandatory at first until proper IOMMU support is enabled on Tegra30. Then it can be checked at driver probe time whether or not to enable the extra checks. That way we don't need a special Kconfig option and we still get all the security that we need, right?

Thierry

#2 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Terje Bergstrom

Review

Quoted 2 lines · Terje Bergstrom
(quoted diff) +2 -0
+
+struct nvhost_chip_support *nvhost_chip_ops;

should be static?

drivers/video/tegra/host/host1x/host1x.c line 67

Quoted 9 lines
drivers/video/tegra/host/host1x/host1x.c new file +9 -0
+static int __devinit nvhost_alloc_resources(struct nvhost_master *host)
+{
+       int err;
+
+       err = nvhost_init_chip_support(host);
+       if (err)
+               return err;
+
+       return 0;

nit: why not just return err - the 'if(err)' is unnecessary)?

drivers/video/tegra/host/host1x/host1x.c line 91

Quoted 2 lines
drivers/video/tegra/host/host1x/host1x.c new file +2 -0
+
+       nvhost = host;

I think this should be delayed until the init is complete as this variable is not cleared if there is a failure during init. Also I feel that the name nvhost is a bit short for an exported variable.

Quoted 10 lines
drivers/video/tegra/host/nvhost_acm.c new file +10 -0
+static void to_state_running_locked(struct platform_device *dev)
+{
+       struct nvhost_device_data *pdata = platform_get_drvdata(dev);
+       int prev_state = pdata->powerstate;
+
+       if (pdata->powerstate == NVHOST_POWER_STATE_POWERGATED)
+               to_state_clockgated_locked(dev);
+
+       if (pdata->powerstate == NVHOST_POWER_STATE_CLOCKGATED) {
+               int i;

drivers/video/tegra/host/nvhost_acm.c line 98

Quoted 10 lines
drivers/video/tegra/host/nvhost_acm.c new file +10 -0
+
+               if (dev->dev.parent)
+                       nvhost_module_busy(to_platform_device(dev->dev.parent));
+
+               for (i = 0; i < pdata->num_clks; i++) {
+                       int err = clk_prepare_enable(pdata->clk[i]);
+                       if (err) {
+                               dev_err(&dev->dev, "Cannot turn on clock %s",
+                                       pdata->clocks[i].name);
+                               return;

In case of an error, returning here leaves some clocks turned on.

Sivaram

#39 lore raw

Re: [RFC v2 2/8] video: tegra: Add syncpoint wait and interrupts

In reply to Terje Bergstrom
Quoted 18 lines · Terje Bergstrom
drivers/video/tegra/host/nvhost_intr.c new file +18 -0
+void nvhost_intr_stop(struct nvhost_intr *intr)
+{
+       unsigned int id;
+       struct nvhost_intr_syncpt *syncpt;
+       u32 nb_pts = nvhost_syncpt_nb_pts(&intr_to_dev(intr)->syncpt);
+
+       mutex_lock(&intr->mutex);
+
+       intr_op().disable_all_syncpt_intrs(intr);
+
+       for (id = 0, syncpt = intr->syncpt;
+            id < nb_pts;
+            ++id, ++syncpt) {
+               struct nvhost_waitlist *waiter, *next;
+               list_for_each_entry_safe(waiter, next,
+                               &syncpt->wait_head, list) {
+                       if (atomic_cmpxchg(&waiter->state,
+                                               WLS_CANCELLED, WLS_HANDLED)

drivers/video/tegra/host/nvhost_intr.c line 355

Quoted 10 lines
drivers/video/tegra/host/nvhost_intr.c new file +10 -0
+                               == WLS_CANCELLED) {
+                               list_del(&waiter->list);
+                               kref_put(&waiter->refcount, waiter_release);
+                       }
+               }
+
+               if (!list_empty(&syncpt->wait_head)) {  /* output diagnostics */
+                       pr_warn("%s cannot stop syncpt intr id=%d\n",
+                                       __func__, id);
+                       return;

mutex_unlock() missing before return.

-Sivaram

#118 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

In reply to Thierry Reding
Quoted 5 lines · Thierry Reding

But in that case it should be made mandatory at first until proper IOMMU support is enabled on Tegra30. Then it can be checked at driver probe time whether or not to enable the extra checks. That way we don't need a special Kconfig option and we still get all the security that we need, right?

I guess it depends on the level of security.

If we want to only protect kernel and user space memory, this would be sufficient and no firewall is needed if IOMMU is turned on.

If we want to protect 2D buffers from each other, this is not sufficient.

Terje

#119 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

Am Dienstag, den 27.11.2012, 13:31 +0200 schrieb Terje Bergström:

Quoted 7 lines · Thierry Reding
Quoted 5 lines

But in that case it should be made mandatory at first until proper IOMMU support is enabled on Tegra30. Then it can be checked at driver probe time whether or not to enable the extra checks. That way we don't need a special Kconfig option and we still get all the security that we need, right?

Quoted 7 lines

I guess it depends on the level of security.

If we want to only protect kernel and user space memory, this would be sufficient and no firewall is needed if IOMMU is turned on.

If we want to protect 2D buffers from each other, this is not sufficient.

I guess we could change IOMMU address spaces for the graphics units depending on the active channel. This would still be a bit of a performance hit, because of the necessary TLB flushing and so on, but should be much better than checking the whole command stream. This way you at least get security on a process level, as no process is able to corrupt another processes graphics resources.

This is the same level of security as provided by the nouveau driver. But to do so all memory management has to be done in kernel and from the current submissions of the 2D infrastructure I fear that the current architecture does too much of that in userspace, but I'll hold back with any judgement until we actually get to see the userspace parts.

Also to implement this strategy you have to take ownership of the graphics address space on a much lower level than the DMA API. This might take some work together with the IOMMU guys.

Regards,
Lucas

#120 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

Quoted 6 lines · Lucas Stach

I guess we could change IOMMU address spaces for the graphics units depending on the active channel. This would still be a bit of a performance hit, because of the necessary TLB flushing and so on, but should be much better than checking the whole command stream. This way you at least get security on a process level, as no process is able to corrupt another processes graphics resources.

One physical channel is shared with all users of the 2D unit. Each job is just added to the queue, and host1x will happily cross from one job to the next without intervention from CPU. This is done to keep CPU overhead down to improve power and performance.

This also means that we cannot change the IOMMU settings between jobs from different processes, unless we pause the channel after every job.

This is still an interesting thought - can we postpone binding of a buffer to address space until submit time, and give each process its own address space? We would have a limit of "submits from three processes going on at once" instead of "three processes can open 2D channel at once". That's a limitation we could live with.

Naturally, Tegra2 is still left in the cold.

Quoted 5 lines

This is the same level of security as provided by the nouveau driver. But to do so all memory management has to be done in kernel and from the current submissions of the 2D infrastructure I fear that the current architecture does too much of that in userspace, but I'll hold back with any judgement until we actually get to see the userspace parts.

User space allocates buffer, exports as dmabuf fd, and passes the fd in submits to kernel, and frees the buffer. No other memory management is done in user space.

Quoted 3 lines

Also to implement this strategy you have to take ownership of the graphics address space on a much lower level than the DMA API. This might take some work together with the IOMMU guys.

I'll go through this with Hiroshi, who knows that area.

Terje

#57 lore raw

Re: [RFC v2 5/8] ARM: tegra: Add auxiliary data for nvhost

In reply to Terje Bergström
Quoted 9 lines · Terje Bergström
Quoted 4 lines · Stephen Warren

Clock names shouldn't be passed in platform data; instead, clk_get() should be passed the device object and device-relative (i.e. not global) clock name. I expect if the driver is fixed to make this change, the changes to tegra*_clocks_data.c won't be needed either.

Isn't this code doing exactly that - getting a device relative clock, nvhost_module_init() in nvhost.acm.c:

Quoted 7 lines

(...)

	/* initialize clocks to known state */
	while (pdata->clocks[i].name && i < NVHOST_MODULE_MAX_CLOCKS) {
		long rate = pdata->clocks[i].default_rate;
		struct clk *c;

		c = devm_clk_get(&dev->dev, pdata->clocks[i].name);

The line above is getting the (device-relative) clock name from platform data, rather than using some fixed name as it should be.

maintainer
#121 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

In reply to Terje Bergström
Quoted 7 lines · Terje Bergström
Quoted 5 lines · Thierry Reding

But in that case it should be made mandatory at first until proper IOMMU support is enabled on Tegra30. Then it can be checked at driver probe time whether or not to enable the extra checks. That way we don't need a special Kconfig option and we still get all the security that we need, right?

Quoted 6 lines

I guess it depends on the level of security.

If we want to only protect kernel and user space memory, this would be sufficient and no firewall is needed if IOMMU is turned on.

If we want to protect 2D buffers from each other, this is not sufficient.

We generally aim for the first, to stop the gpu from reading/writing any memory it hasn't been granted access to,
the second is nice to have though, but really requires a GPU with VM to implement properly.

Dave.

#122 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

Quoted 4 lines · Dave Airlie

We generally aim for the first, to stop the gpu from reading/writing any memory it hasn't been granted access to,
the second is nice to have though, but really requires a GPU with VM to implement properly.

I wonder if we should aim at root only access on Tegra20, and force IOMMU on Tegra30 and fix the remaining issues we have with IOMMU. The firewall turns out to be more complicated than I wished.

Biggest problem is that we aim at zero-copy for everything possible, including command streams. Kernel gets a handle to a command stream, but the command stream is allocated by the user space process. So the user space can tamper with the stream once it's been written to the host1x 2D channel.

Copying with firewall is one option, but that would again kill the performance. One option would be user space unmapping the command buffer when it's sent to kernel, and kernel checking that it's unmapped before it agrees to send the stream to hardware.

On Tegra30 with IOMMU turned on things are ok without any checks, because all access would go via MMU, which makes kernel memory inaccessible.

Of course, better ideas are welcome.

Terje

#123 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

Am Mittwoch, den 28.11.2012, 15:17 +0200 schrieb Terje Bergström:

Quoted 10 lines · Dave Airlie
Quoted 4 lines

We generally aim for the first, to stop the gpu from reading/writing any memory it hasn't been granted access to,
the second is nice to have though, but really requires a GPU with VM to implement properly.

I wonder if we should aim at root only access on Tegra20, and force IOMMU on Tegra30 and fix the remaining issues we have with IOMMU. The firewall turns out to be more complicated than I wished.

Quoted 6 lines

Biggest problem is that we aim at zero-copy for everything possible, including command streams. Kernel gets a handle to a command stream, but the command stream is allocated by the user space process. So the user space can tamper with the stream once it's been written to the host1x 2D channel.

So this is obviously wrong. Userspace has to allocate a pushbuffer from the kernel just as every other buffer, then map it into it's own address space to push in commands. At submit time of the pushbuf kernel has to make sure that userspace is not able to access the memory any more, i.e. kernel shoots down the vma or pagetable of the vma. To keep overhead low and not do any blocking you can just keep some pushbufs around for one channel and switch over the pagetable entries to the next free buffer, just make sure that userspace is never able to tamper with a buffer as long as the gpu isn't done with it.

Regards,
Lucas

#124 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

Quoted 9 lines · Lucas Stach

So this is obviously wrong. Userspace has to allocate a pushbuffer from the kernel just as every other buffer, then map it into it's own address space to push in commands. At submit time of the pushbuf kernel has to make sure that userspace is not able to access the memory any more, i.e. kernel shoots down the vma or pagetable of the vma. To keep overhead low and not do any blocking you can just keep some pushbufs around for one channel and switch over the pagetable entries to the next free buffer, just make sure that userspace is never able to tamper with a buffer as long as the gpu isn't done with it.

That's really not something dma-buf APIs are equipped to handle. We need something to ensure user space doesn't have the buffer mapped (either return error if has, or zap the mapping), something to ensure user space cannot mmap the buffer, and something to revert this all once we're done.

We could add these as special ops to tegradrm dmabuf code for now, and assume that command streams are always allocated by tegradrm. Now we allow any dmabuf to be used as buffers for command streams.

And, with IOMMU I don't think we would need any of this. I guess we need to press the gas pedal on figuring out how to enable that for tegradrm on Tegra30.

We already allocate multiple buffers to be able to fill in the next buffer once we've send one to kernel, so that part is ok. We reuse only once we know that the operations contained are done.

Terje

#125 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

Am Mittwoch, den 28.11.2012, 15:57 +0200 schrieb Terje Bergström:

Quoted 11 lines · Lucas Stach
Quoted 9 lines

So this is obviously wrong. Userspace has to allocate a pushbuffer from the kernel just as every other buffer, then map it into it's own address space to push in commands. At submit time of the pushbuf kernel has to make sure that userspace is not able to access the memory any more, i.e. kernel shoots down the vma or pagetable of the vma. To keep overhead low and not do any blocking you can just keep some pushbufs around for one channel and switch over the pagetable entries to the next free buffer, just make sure that userspace is never able to tamper with a buffer as long as the gpu isn't done with it.

Quoted 9 lines

That's really not something dma-buf APIs are equipped to handle. We need something to ensure user space doesn't have the buffer mapped (either return error if has, or zap the mapping), something to ensure user space cannot mmap the buffer, and something to revert this all once we're done.

We could add these as special ops to tegradrm dmabuf code for now, and assume that command streams are always allocated by tegradrm. Now we allow any dmabuf to be used as buffers for command streams.

Why do even need/use dma-buf for this use case? This is all one DRM device, even if we separate host1x and gr2d as implementation modules.

So standard way of doing this is:
1. create gem object for pushbuffer
2. create fake mmap offset for gem obj
3. map pushbuf using the fake offset on the drm device
4. at submit time zap the mapping

You need this logic anyway, as normally we don't rely on userspace to sync gpu and cpu, but use the kernel to handle the concurrency issues.

Regards,
Lucas

#126 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

Quoted 2 lines · Lucas Stach

Why do even need/use dma-buf for this use case? This is all one DRM device, even if we separate host1x and gr2d as implementation modules.

I didn't want to implement dependency to drm gem objects in nvhost, but we have thought about doing that. dma-buf brings quite a lot of overhead, so implementing support for gem buffers would make the sequence a bit leaner.

nvhost already has infra to support multiple memory managers.

Quoted 8 lines

So standard way of doing this is:
1. create gem object for pushbuffer
2. create fake mmap offset for gem obj
3. map pushbuf using the fake offset on the drm device
4. at submit time zap the mapping

You need this logic anyway, as normally we don't rely on userspace to sync gpu and cpu, but use the kernel to handle the concurrency issues.

Taking a step back - 2D streams are actually very short, in the order of <100 bytes. Just copying them to kernel space would actually be faster than doing MMU operations.

I think for Tegra20 and non-IOMMU case, we just need to copy the command stream to kernel buffer. In Tegra30 IOMMU case reference to user space buffers are fine, as tampering the streams doesn't have any ill effects.

Terje

#127 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

Am Mittwoch, den 28.11.2012, 16:45 +0200 schrieb Terje Bergström:

Quoted 11 lines · Lucas Stach
Quoted 2 lines

Why do even need/use dma-buf for this use case? This is all one DRM device, even if we separate host1x and gr2d as implementation modules.

I didn't want to implement dependency to drm gem objects in nvhost, but we have thought about doing that. dma-buf brings quite a lot of overhead, so implementing support for gem buffers would make the sequence a bit leaner.

nvhost already has infra to support multiple memory managers.

To be honest I still don't grok all of this, but nonetheless I try my best.

Anyway, shouldn't nvhost be something like an allocator used by host1x clients? With the added ability to do relocs/binding of buffers into client address spaces, refcounting buffers and import/export dma-bufs? In this case nvhost objects would just be used to back DRM GEM objects. If using GEM objects in the DRM driver introduces any cross dependencies with nvhost, you should take a step back and ask yourself if the current design is the right way to go.

Quoted 6 lines
Quoted 6 lines

So standard way of doing this is:
1. create gem object for pushbuffer
2. create fake mmap offset for gem obj
3. map pushbuf using the fake offset on the drm device
4. at submit time zap the mapping

Quoted 7 lines
Quoted 2 lines

You need this logic anyway, as normally we don't rely on userspace to sync gpu and cpu, but use the kernel to handle the concurrency issues.

Taking a step back - 2D streams are actually very short, in the order of <100 bytes. Just copying them to kernel space would actually be faster than doing MMU operations.

Is this always the case because of the limited abilities of the gr2d engine, or is it just your current driver flushing the stream very often?

Quoted 4 lines

I think for Tegra20 and non-IOMMU case, we just need to copy the command stream to kernel buffer. In Tegra30 IOMMU case reference to user space buffers are fine, as tampering the streams doesn't have any ill effects.

In which way is it a good design choice to let the CPU happily alter _any_ buffer the GPU is busy processing without getting the concurrency right?

Please keep in mind that the interfaces you are now trying to introduce have to be supported for virtually unlimited time. You might not be able to scrub your mistakes later on without going through a lot of hassles.

To avoid a lot of those mistakes it might be a good idea to look at how other drivers use the DRM infrastructure and only part from those proven schemes where really necessary/worthwhile.

Regards,
Lucas

#128 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

Quoted 2 lines · Lucas Stach

To be honest I still don't grok all of this, but nonetheless I try my best.

Sorry. I promised in another thread a write-up explaining the design. I still owe you guys that.

Quoted 7 lines

Anyway, shouldn't nvhost be something like an allocator used by host1x clients? With the added ability to do relocs/binding of buffers into client address spaces, refcounting buffers and import/export dma-bufs? In this case nvhost objects would just be used to back DRM GEM objects. If using GEM objects in the DRM driver introduces any cross dependencies with nvhost, you should take a step back and ask yourself if the current design is the right way to go.

tegradrm has the GEM allocator, and tegradrm contains the 2D kernel interface. tegradrm contains a dma-buf exporter for the tegradrm GEM objects.

nvhost accepts jobs from tegradrm's 2D driver. nvhost increments refcounts and maps the command stream and target memories to devices, maps the command streams to kernel memory, replaces the placeholders in command streams with addresses with device virtual addresses, and unmaps the buffer from kernel memory. nvhost uses dma buf APIs for all of the memory operations, and relies on dmabuf for refcounting. After all this the command streams are pushed to host1x push buffer as GATHER (kind of a "gosub") opcodes, which reference to the command streams.

Once the job is done, nvhost decrements refcounts and updates pushbuffer pointers.

The design is done so that nvhost won't be DRM specific. I want to enable creating V4L2 etc interfaces that talk to other host1x clients. V4L2 (yeah, I know nothing of V4L2) could pass frames via nvhost to EPP for pixel format conversion or 2D for rotation and write result to frame buffer.

Do you think there's some fundamental problem with this design?

Quoted 7 lines
Quoted 4 lines

Taking a step back - 2D streams are actually very short, in the order of <100 bytes. Just copying them to kernel space would actually be faster than doing MMU operations.

Is this always the case because of the limited abilities of the gr2d engine, or is it just your current driver flushing the stream very often?

It's because of limited abilities of the hardware. It just doesn't take that many operations to invoke 2D.

The libdrm user space we're created flushes probably a bit too often now, but even in downstream the streams are not much longer. It takes still at least a week to get the user space code out for you to look at.

Quoted 3 lines

In which way is it a good design choice to let the CPU happily alter _any_ buffer the GPU is busy processing without getting the concurrency right?

Concurrency is handled with sync points. User space will know when a command stream is processed and can be reused by comparing the current sync point value, and the fence that 2D driver returned to user space. User space can have a pool of buffers and can recycle when it knows it can do so. But, this is not enforced by kernel.

The difference with your proposal and what I posted is the level of control user space has over its command stream management. But as said, 2D streams are so short that my guess is that there's not too much penalty copying it to kernel managed host1x push buffer directly instead of inserting a GATHER reference.

Quoted 7 lines

Please keep in mind that the interfaces you are now trying to introduce have to be supported for virtually unlimited time. You might not be able to scrub your mistakes later on without going through a lot of hassles.

To avoid a lot of those mistakes it might be a good idea to look at how other drivers use the DRM infrastructure and only part from those proven schemes where really necessary/worthwhile.

Yep, as the owner of this driver downstream, I'm also leveraging my experience with the graphics stack in our downstream software stack that is accessible via f.ex. L4T.

This is exactly the discussion we should be having, and I'm learning all the time, so let's continue tossing around ideas until we're both happy with the result.

Terje

#136 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

In reply to Terje Bergström
Quoted 17 lines · Terje Bergström
Quoted 2 lines · Lucas Stach

Why do even need/use dma-buf for this use case? This is all one DRM device, even if we separate host1x and gr2d as implementation modules.

I didn't want to implement dependency to drm gem objects in nvhost, but we have thought about doing that. dma-buf brings quite a lot of overhead, so implementing support for gem buffers would make the sequence a bit leaner.

nvhost already has infra to support multiple memory managers.

Quoted 6 lines

So standard way of doing this is:
1. create gem object for pushbuffer
2. create fake mmap offset for gem obj
3. map pushbuf using the fake offset on the drm device
4. at submit time zap the mapping

Quoted 6 lines
Quoted 2 lines

You need this logic anyway, as normally we don't rely on userspace to sync gpu and cpu, but use the kernel to handle the concurrency issues.

Taking a step back - 2D streams are actually very short, in the order of <100 bytes. Just copying them to kernel space would actually be faster than doing MMU operations.

I'm not sure it's a good idea to have one buffer submission mechanism for the 2D class and another for the 3D/... class, nor to bet that 2D streams will always be short.

#129 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

In reply to Terje Bergström

Am Mittwoch, den 28.11.2012, 18:23 +0200 schrieb Terje Bergström:

Quoted 7 lines · Lucas Stach
Quoted 2 lines

To be honest I still don't grok all of this, but nonetheless I try my best.

Sorry. I promised in another thread a write-up explaining the design. I still owe you guys that.

That would be really nice to have. I'm also particularly interested in how you plan to do synchronization of command streams to different engines working together, if that's not too much to ask for now. Like userspace uploading a texture in a buffer, 2D engine doing mipmap generation, 3D engine using mipmapped texture.

Quoted 24 lines
Quoted 7 lines

Anyway, shouldn't nvhost be something like an allocator used by host1x clients? With the added ability to do relocs/binding of buffers into client address spaces, refcounting buffers and import/export dma-bufs? In this case nvhost objects would just be used to back DRM GEM objects. If using GEM objects in the DRM driver introduces any cross dependencies with nvhost, you should take a step back and ask yourself if the current design is the right way to go.

tegradrm has the GEM allocator, and tegradrm contains the 2D kernel interface. tegradrm contains a dma-buf exporter for the tegradrm GEM objects.

nvhost accepts jobs from tegradrm's 2D driver. nvhost increments refcounts and maps the command stream and target memories to devices, maps the command streams to kernel memory, replaces the placeholders in command streams with addresses with device virtual addresses, and unmaps the buffer from kernel memory. nvhost uses dma buf APIs for all of the memory operations, and relies on dmabuf for refcounting. After all this the command streams are pushed to host1x push buffer as GATHER (kind of a "gosub") opcodes, which reference to the command streams.

Once the job is done, nvhost decrements refcounts and updates pushbuffer pointers.

Quoted 8 lines

The design is done so that nvhost won't be DRM specific. I want to enable creating V4L2 etc interfaces that talk to other host1x clients. V4L2 (yeah, I know nothing of V4L2) could pass frames via nvhost to EPP for pixel format conversion or 2D for rotation and write result to frame buffer.

Do you think there's some fundamental problem with this design?

Ah yes I see. So if we consider nvhost to be the central entity in charge of controlling all host1x clients and tegradrm as the interface that happens to bundle display, 2d and 3d engine functionality into it's interface we should probably aim for two things:
1. Move everything needed by all engines down into nvhost (I especially see the allocator falling under this point, I'll explain why this would be beneficial a bit later)

2. Move the exposed DRM interface more in line with other DRM drivers. Please take a look at how for example the GEM_EXECBUF ioctl works on other drivers to get a feeling of what I'm talking about. Everything using the display, 2D and maybe later on the 3D engine should only deal with GEM handles. I really don't like the idea of having a single userspace application, which uses engines with similar and known requirements (DDX) dealing with dma-buf handles or other similar high overhead stuff to do the most basic tasks.

If we move down the allocator into nvhost we can use buffers allocated from this to back GEM or V4L2 buffers transparently. The ioctl to allocate a GEM buffer shouldn't do much more than wrapping the nvhost buffer.
This may also solve your problem with having multiple mappings of the same buffer into the very same address space, as nvhost is the single instance that manages all host1x client address spaces. If the buffer is originating from there you can easily check if it's already mapped. For Tegra 3 to do things in an efficient way we likely have to move away from dealing with the DMA API to dealing with the IOMMU API, this gets a _lot_ easier_ if you have a single point where you manage memory allocation and address space.

dma-buf should only be used where userspace is dealing with devices that get controlled by different interfaces, like pointing a display plane to some camera buffer. And even then with a single allocator for the host1x clients an dma-buf import is nothing more than realizing that the fd is one of the fds you exported yourself, so you can go and look it up and then depending on the device you are on just pointing the engine at the memory location or fixing up the iommu mapping.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Taking a step back - 2D streams are actually very short, in the order of <100 bytes. Just copying them to kernel space would actually be faster than doing MMU operations.

Is this always the case because of the limited abilities of the gr2d engine, or is it just your current driver flushing the stream very often?

Quoted 7 lines

It's because of limited abilities of the hardware. It just doesn't take that many operations to invoke 2D.

The libdrm user space we're created flushes probably a bit too often now, but even in downstream the streams are not much longer. It takes still at least a week to get the user space code out for you to look at.

That's no problem, as I may not be able to do in-depth reviews of any code until next week.

Quoted 10 lines
Quoted 3 lines

In which way is it a good design choice to let the CPU happily alter _any_ buffer the GPU is busy processing without getting the concurrency right?

Concurrency is handled with sync points. User space will know when a command stream is processed and can be reused by comparing the current sync point value, and the fence that 2D driver returned to user space. User space can have a pool of buffers and can recycle when it knows it can do so. But, this is not enforced by kernel.

This is the point where we have differ: You have to deal with syncpts in kernel anyway, otherwise you don't know when it's safe to destroy a buffer. And no, userspace should not have the ability to destroy a buffer itself, userspace should always just be able to free it's reference to the buffer. Remember: never trust the userspace. And if you are dealing with syncpts in kernel anyway, you can just go ahead and enforce some sane concurrency rules. There may be some corener cases related to userspace suballocating a kernel buffer, which might need some more thought still, but that's not a valid excuse to not do any concurrency validation in kernel.

Quoted 6 lines

The difference with your proposal and what I posted is the level of control user space has over its command stream management. But as said, 2D streams are so short that my guess is that there's not too much penalty copying it to kernel managed host1x push buffer directly instead of inserting a GATHER reference.

This an implementation detail. Whether you shoot down the old pushbuf mapping and insert a new one pointing to free backing memory (which may be the way to go for 3D) or do an immediate copy of the channel pushbuf contents to the host1x pushbuf (which may be beneficial for very small pushs) is all the same. Both methods implicitly guarantee that the memory mapped by userspace always points to a location the CPU can write to without interfering with the GPU.

Quoted 8 lines
Quoted 7 lines

Please keep in mind that the interfaces you are now trying to introduce have to be supported for virtually unlimited time. You might not be able to scrub your mistakes later on without going through a lot of hassles.

To avoid a lot of those mistakes it might be a good idea to look at how other drivers use the DRM infrastructure and only part from those proven schemes where really necessary/worthwhile.

Quoted 8 lines

Yep, as the owner of this driver downstream, I'm also leveraging my experience with the graphics stack in our downstream software stack that is accessible via f.ex. L4T.

This is exactly the discussion we should be having, and I'm learning all the time, so let's continue tossing around ideas until we're both happy with the result.

I really enjoyed the discussion so far and hope we can get to the point where we have a nice design/interface, working together.

Regards,
Lucas

#137 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

In reply to Lucas Stach
Quoted 16 lines · Lucas Stach

Am Mittwoch, den 28.11.2012, 15:17 +0200 schrieb Terje Bergström:

Quoted 9 lines · Dave Airlie
Quoted 4 lines

We generally aim for the first, to stop the gpu from reading/writing any memory it hasn't been granted access to,
the second is nice to have though, but really requires a GPU with VM to implement properly.

I wonder if we should aim at root only access on Tegra20, and force IOMMU on Tegra30 and fix the remaining issues we have with IOMMU. The firewall turns out to be more complicated than I wished.

Quoted 6 lines

Biggest problem is that we aim at zero-copy for everything possible, including command streams. Kernel gets a handle to a command stream, but the command stream is allocated by the user space process. So the user space can tamper with the stream once it's been written to the host1x 2D channel.

Quoted 5 lines

So this is obviously wrong. Userspace has to allocate a pushbuffer from the kernel just as every other buffer, then map it into it's own address space to push in commands. At submit time of the pushbuf kernel has to make sure that userspace is not able to access the memory any more, i.e. kernel shoots down the vma or pagetable of the vma.

To me this sounds very expensive. Zapping the page table requires a CPU TLB flush on all cores that have touched the buffer, not to mention the kernel calls required to set up the page table once the buffer is reused.

If this usage scheme then is combined with a command verifier or "firewall" that reads from a *write-combined* pushbuffer performance will be bad. Really bad.

In such situations I think one should consider copy-from-user while validating, and let user-space set up the command buffer in malloced memory.

/Thomas

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Terje Bergstrom

On Mon, Nov 26, 2012 at 03:19:07PM +0200, Terje Bergstrom wrote:
[...]

drivers/video/Kconfig config FB_SH_MOBILE_MERAM · line 2467

Quoted 10 lines
drivers/video/Kconfig +2 -0
index fb9a14e..94c861b 100644
@@ -2463,4 +2463,6 @@ config FB_SH_MOBILE_MERAM
 	  Up to 4 memory channels can be configured, allowing 4 RGB or
 	  2 YCbCr framebuffers to be configured.
 
+source "drivers/video/tegra/host/Kconfig"
+

This could be problematic. Since drivers/video and drivers/gpu/drm are separate trees, this would entail a continuous burden on keeping both trees synchronized. While I realize that eventually it might be better to put the host1x driver in a separate place to accomodate for its use by other subsystems, I'm not sure moving it here right away is the best approach.

I'm not sure drivers/video is the best location either. Perhaps drivers/bus would be better? Or maybe we need a new subdirectory for this kind of device.

drivers/video/tegra/host/chip_support.c line 2

Quoted 8 lines
drivers/video/tegra/host/chip_support.c new file +2 -0
new file mode 100644
index 0000000..5a44147
@@ -0,0 +1,48 @@
+/*
+ * drivers/video/tegra/host/chip_support.c

I think the general nowadays is to no longer use filenames in comments.

[...]

drivers/video/tegra/host/chip_support.c line 33

Quoted 6 lines
drivers/video/tegra/host/chip_support.c new file +6 -0
+struct nvhost_chip_support *nvhost_chip_ops;
+
+struct nvhost_chip_support *nvhost_get_chip_ops(void)
+{
+	return nvhost_chip_ops;
+}

This seems like it should be more tightly coupled to the host1x device. And it shouldn't be a global variable.

Quoted 5 lines
drivers/video/tegra/host/chip_support.c new file +5 -0
+
+int nvhost_init_chip_support(struct nvhost_master *host)
+{
+	if (nvhost_chip_ops == NULL) {
+		nvhost_chip_ops = kzalloc(sizeof(*nvhost_chip_ops), GFP_KERNEL);

drivers/video/tegra/host/chip_support.c line 48

Quoted 10 lines
drivers/video/tegra/host/chip_support.c new file +10 -0
+		if (nvhost_chip_ops == NULL) {
+			pr_err("%s: Cannot allocate nvhost_chip_support\n",
+				__func__);
+			return -ENOMEM;
+		}
+	}
+
+	nvhost_init_host1x01_support(host, nvhost_chip_ops);
+	return 0;
+}

We also don't need this. This should really be done by the central host1x device's initialization.

Quoted 1 line
drivers/video/tegra/host/chip_support.h +0 -0

[...]

Quoted 1 line

+struct output;

What's this? It doesn't seem to be used anywhere.

Quoted 1 line

+struct nvhost_master;

Why do you suffix this with _master? The whole point of host1x is to be the "master" so you can just as well call it nvhost, right? Ideally you'd call it host1x, but I'm repeating myself. =)

drivers/video/tegra/host/chip_support.h line 39

Quoted 12 lines
drivers/video/tegra/host/chip_support.h +12 -0
+struct nvhost_syncpt;
+struct platform_device;
+
+struct nvhost_syncpt_ops {
+	void (*reset)(struct nvhost_syncpt *, u32 id);
+	void (*reset_wait_base)(struct nvhost_syncpt *, u32 id);
+	void (*read_wait_base)(struct nvhost_syncpt *, u32 id);
+	u32 (*update_min)(struct nvhost_syncpt *, u32 id);
+	void (*cpu_incr)(struct nvhost_syncpt *, u32 id);
+	void (*debug)(struct nvhost_syncpt *);
+	const char * (*name)(struct nvhost_syncpt *, u32 id);
+};

Why are these even defined as ops structure? Tegra20 and Tegra30 seem to be compatible when it comes to handling syncpoints. I thought they would even be compatible in all other aspects as well, so why even have this?

drivers/video/tegra/host/chip_support.h line 48

Quoted 9 lines
drivers/video/tegra/host/chip_support.h +9 -0
+
+struct nvhost_chip_support {
+	const char *soc_name;
+	struct nvhost_syncpt_ops syncpt;
+};
+
+struct nvhost_chip_support *nvhost_get_chip_ops(void);
+
+#define syncpt_op()		(nvhost_get_chip_ops()->syncpt)

You really shouldn't be doing this, but rather use explicit accesses for these structures. If you're design doesn't scatter these definitions across several files then it isn't difficult to obtain the correct pointers and you don't need these "shortcuts".

Quoted 1 line
drivers/video/tegra/host/dev.c +0 -0

[...]

drivers/video/tegra/host/dev.c line 30

Quoted 6 lines
drivers/video/tegra/host/dev.c +6 -0
+u32 host1x_syncpt_incr_max(u32 id, u32 incrs)
+{
+	struct nvhost_syncpt *sp = &nvhost->syncpt;
+	return nvhost_syncpt_incr_max(sp, id, incrs);
+}
+EXPORT_SYMBOL(host1x_syncpt_incr_max);

This API looks odd. Should syncpoints not be considered as regular resources, much like interrupts? In that case it would be easier to abstract them away behind an opaque type. It looks like you already use the struct nvhost_syncpt to refer to the set of syncpoints associated with a host1x device.

How about you use nvhost/host1x_syncpt to refer to individual syncpoints instead. You could export an array of those from your host1x device and implement a basic resource allocation mechanism on top, similar to how other resources are handled in the kernel.

So a host1x client device could call host1x_request_syncpt() to allocate a syncpoint from it's host1x parent dynamically along with passing a name and a syncpoint handler to it.

drivers/video/tegra/host/dev.c line 37

Quoted 7 lines
drivers/video/tegra/host/dev.c +7 -0
+
+void host1x_syncpt_incr(u32 id)
+{
+	struct nvhost_syncpt *sp = &nvhost->syncpt;
+	nvhost_syncpt_incr(sp, id);
+}
+EXPORT_SYMBOL(host1x_syncpt_incr);

Similarly, instead of passing an integer here, host1x clients would pass a pointer to the requested syncpoint instead.

Quoted 2 lines
drivers/video/tegra/host/dev.c +2 -0
+bool host1x_powered(struct platform_device *dev)
+{

[...]

Quoted 5 lines
drivers/video/tegra/host/dev.c +5 -0
+}
+EXPORT_SYMBOL(host1x_powered);
+
+void host1x_busy(struct platform_device *dev)
+{

[...]

Quoted 5 lines
drivers/video/tegra/host/dev.c +5 -0
+}
+EXPORT_SYMBOL(host1x_busy);
+
+void host1x_idle(struct platform_device *dev)
+{

[...]

drivers/video/tegra/host/dev.c

Quoted 2 lines
drivers/video/tegra/host/dev.c +2 -0
+}
+EXPORT_SYMBOL(host1x_idle);

These look like a reimplementation of the runtime power-management framework.

Quoted 1 line
drivers/video/tegra/host/host1x/host1x.c +0 -0

[...]

Quoted 1 line

+struct nvhost_master *nvhost;

Bad habbit. I know that this is a popular shortcut. However this also leads to very bad designs because you're allowed to reuse this pointer from wherever you like.

When I wrote the tegra-drm code I explicitly made sure to not use any such global variable. In the end it forces you to clean up the driver design.

As a bonus you automatically get support for any number of host1x devices on the same SoC. Now you will probably tell me that this is never going to happen. People also used to think that a computers would never use more than a single CPU...

Quoted 4 lines
drivers/video/tegra/host/host1x/host1x.c +4 -0
+static void power_on_host(struct platform_device *dev)
+{
+	struct nvhost_master *host = nvhost_get_private_data(dev);
+

drivers/video/tegra/host/host1x/host1x.c line 53

Quoted 10 lines
drivers/video/tegra/host/host1x/host1x.c +10 -0
+	nvhost_syncpt_reset(&host->syncpt);
+}
+
+static int power_off_host(struct platform_device *dev)
+{
+	struct nvhost_master *host = nvhost_get_private_data(dev);
+
+	nvhost_syncpt_save(&host->syncpt);
+	return 0;
+}

These seem like possible candidates for runtime PM.

drivers/video/tegra/host/host1x/host1x.c line 57

Quoted 4 lines
drivers/video/tegra/host/host1x/host1x.c +4 -0
+
+static void nvhost_free_resources(struct nvhost_master *host)
+{
+}

This should be removed since it's empty.

drivers/video/tegra/host/host1x/host1x.c line 68

Quoted 11 lines
drivers/video/tegra/host/host1x/host1x.c +11 -0
+
+static int __devinit nvhost_alloc_resources(struct nvhost_master *host)
+{
+	int err;
+
+	err = nvhost_init_chip_support(host);
+	if (err)
+		return err;
+
+	return 0;
+}

Again, this chip support concept is not useful, so this function can go away as well. Also nvhost_init_chip_support() doesn't allocate any resources so it shouldn't be called from this function in the first place.

drivers/video/tegra/host/host1x/host1x.c line 76

Quoted 8 lines
drivers/video/tegra/host/host1x/host1x.c +8 -0
+
+static int __devinit nvhost_probe(struct platform_device *dev)
+{
+	struct nvhost_master *host;
+	struct resource *regs, *intr0, *intr1;
+	int i, err;
+	struct nvhost_device_data *pdata =
+		(struct nvhost_device_data *)dev->dev.platform_data;

Platform data should not be used. Tegra is DT only.

drivers/video/tegra/host/host1x/host1x.c line 82

Quoted 5 lines
drivers/video/tegra/host/host1x/host1x.c +5 -0
+	regs = platform_get_resource(dev, IORESOURCE_MEM, 0);
+	intr0 = platform_get_resource(dev, IORESOURCE_IRQ, 0);
+	intr1 = platform_get_resource(dev, IORESOURCE_IRQ, 1);
+
+	if (!regs || !intr0 || !intr1) {

I prefer to have these checked for explicitly, one by one for readability and potentially more useful diagnostics.

Also you should be using platform_get_irq() for interrupts. Furthermore the host1x DT node (and the TRM) name the interrupts "syncpt" and "general", so maybe those would be more useful variable names than "intr0" and "intr1".

But since you don't use them anyway they shouldn't be part of this patch.

drivers/video/tegra/host/host1x/host1x.c line 96

Quoted 10 lines
drivers/video/tegra/host/host1x/host1x.c +10 -0
+	host = devm_kzalloc(&dev->dev, sizeof(*host), GFP_KERNEL);
+	if (!host)
+		return -ENOMEM;
+
+	nvhost = host;
+
+	host->dev = dev;
+
+	/* Copy host1x parameters. The private_data gets replaced
+	 * by nvhost_master later */

Multiline comments should be in this format:

	/*
	 * foo
	 */

drivers/video/tegra/host/host1x/host1x.c line 98

Quoted 2 lines
drivers/video/tegra/host/host1x/host1x.c +2 -0
+	memcpy(&host->info, pdata->private_data,
+			sizeof(struct host1x_device_info));

I don't think passing data in this way shouldn't be necessary as discussed in the subthread on the Tegra AUXDATA.

Quoted 4 lines
drivers/video/tegra/host/host1x/host1x.c +4 -0
+
+	pdata->finalize_poweron = power_on_host;
+	pdata->prepare_poweroff = power_off_host;
+

drivers/video/tegra/host/host1x/host1x.c line 112

Quoted 10 lines
drivers/video/tegra/host/host1x/host1x.c +10 -0
+	pdata->pdev = dev;
+
+	/* set common host1x device data */
+	platform_set_drvdata(dev, pdata);
+
+	/* set private host1x device data */
+	nvhost_set_private_data(dev, host);
+
+	host->aperture = devm_request_and_ioremap(&dev->dev, regs);
+	if (!host->aperture) {

aperture is confusing as it is typically used for GTT-type memory regions, so it may be mistaken for the GART found on Tegra 2. Why not call it "regs" instead?

drivers/video/tegra/host/host1x/host1x.c line 113

Quoted 1 line
drivers/video/tegra/host/host1x/host1x.c +1 -0
+		dev_err(&dev->dev, "failed to remap host registers\n");

This is unnecessary. devm_request_and_ioremap() already prints an error message on failure.

drivers/video/tegra/host/host1x/host1x.c line 136

Quoted 5 lines
drivers/video/tegra/host/host1x/host1x.c +5 -0
+	for (i = 0; i < pdata->num_clks; i++)
+		clk_prepare_enable(pdata->clk[i]);
+	nvhost_syncpt_reset(&host->syncpt);
+	for (i = 0; i < pdata->num_clks; i++)
+		clk_disable_unprepare(pdata->clk[i]);

Stephen already hinted at this when discussing the AUXDATA. You should explicitly request the clocks.

Quoted 1 line

+static int __exit nvhost_remove(struct platform_device *dev)

This should really be __devexit to allow the driver to be built as a module. However, __dev* are deprecated and in the process of being removed so you can just drop __exit as well.

Quoted 1 line

+static struct of_device_id host1x_match[] __devinitdata = {

__devinitdata can be dropped.

drivers/video/tegra/host/host1x/host1x.c line 182

Quoted 8 lines
drivers/video/tegra/host/host1x/host1x.c +8 -0
+	{ .compatible = "nvidia,tegra20-host1x", },
+	{ .compatible = "nvidia,tegra30-host1x", },
+	{ },
+};
+
+static struct platform_driver platform_driver = {
+	.probe = nvhost_probe,
+	.remove = __exit_p(nvhost_remove),

__exit_p also.

drivers/video/tegra/host/host1x/host1x.c line 188

Quoted 6 lines
drivers/video/tegra/host/host1x/host1x.c +6 -0
+	.suspend = nvhost_suspend,
+	.resume = nvhost_resume,
+	.driver = {
+		.owner = THIS_MODULE,
+		.name = DRIVER_NAME,
+		.of_match_table = of_match_ptr(host1x_match),

No need for of_match_ptr().

drivers/video/tegra/host/host1x/host1x.c line 203

Quoted 12 lines
drivers/video/tegra/host/host1x/host1x.c +12 -0
+static int __init nvhost_mod_init(void)
+{
+	return platform_driver_register(&platform_driver);
+}
+
+static void __exit nvhost_mod_exit(void)
+{
+	platform_driver_unregister(&platform_driver);
+}
+
+module_init(nvhost_mod_init);
+module_exit(nvhost_mod_exit);

Use module_platform_driver().

Quoted 1 line
drivers/video/tegra/host/host1x/host1x.h +0 -0

[...]

drivers/video/tegra/host/host1x/host1x.h line 30

Quoted 2 lines
drivers/video/tegra/host/host1x/host1x.h +2 -0
+#define TRACE_MAX_LENGTH	128U
+#define IFACE_NAME		"nvhost"

None of these seem to be used.

Quoted 7 lines
drivers/video/tegra/host/host1x/host1x.h +7 -0
+static inline void *nvhost_get_private_data(struct platform_device *_dev)
+{
+	struct nvhost_device_data *pdata =
+		(struct nvhost_device_data *)platform_get_drvdata(_dev);
+	WARN_ON(!pdata);
+	return (pdata && pdata->private_data) ? pdata->private_data : NULL;
+}

drivers/video/tegra/host/host1x/host1x.h line 58

Quoted 10 lines
drivers/video/tegra/host/host1x/host1x.h +10 -0
+
+static inline void nvhost_set_private_data(struct platform_device *_dev,
+	void *priv_data)
+{
+	struct nvhost_device_data *pdata =
+		(struct nvhost_device_data *)platform_get_drvdata(_dev);
+	WARN_ON(!pdata);
+	if (pdata)
+		pdata->private_data = priv_data;
+}

You should need none of these. Instead put all the data you need into you struct host1x and associate that with the platform device using platform_set_drvdata().

Quoted 7 lines
drivers/video/tegra/host/host1x/host1x.h +7 -0
+static inline
+struct nvhost_master *nvhost_get_host(struct platform_device *_dev)
+{
+	struct platform_device *pdev;
+
+	if (_dev->dev.parent) {
+		pdev = to_platform_device(_dev->dev.parent);

drivers/video/tegra/host/host1x/host1x.h line 76

Quoted 10 lines
drivers/video/tegra/host/host1x/host1x.h +10 -0
+		return nvhost_get_private_data(pdev);
+	} else
+		return nvhost_get_private_data(_dev);
+}
+
+static inline
+struct platform_device *nvhost_get_parent(struct platform_device *_dev)
+{
+	return _dev->dev.parent ? to_platform_device(_dev->dev.parent) : NULL;
+}

These don't seem to be used.

Quoted 29 lines
drivers/video/tegra/host/host1x/host1x01.c new file +23 -0
new file mode 100644
index 0000000..d53302d
@@ -0,0 +1,37 @@
+/*
+ * drivers/video/tegra/host/host1x01.c
+ *
+ * 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/nvhost.h>
+
+#include "host1x/host1x01.h"

drivers/video/tegra/host/host1x/host1x01.c line 33

Quoted 10 lines
drivers/video/tegra/host/host1x/host1x01.c new file +10 -0
+#include "host1x/host1x.h"
+#include "host1x/host1x01_hardware.h"
+#include "chip_support.h"
+
+#include "host1x/host1x_syncpt.c"
+
+int nvhost_init_host1x01_support(struct nvhost_master *host,
+	struct nvhost_chip_support *op)
+{
+	host->sync_aperture = host->aperture + HOST1X_CHANNEL_SYNC_REG_BASE;

Usually you don't keep separate variables for subregions. This can equally well be done with just adding a corresponding offset.

Then again, I already said that this whole chip support concept is unnecessary and can be dropped.

Quoted 1 line
drivers/video/tegra/host/host1x/host1x_syncpt.c +0 -0

[...]

drivers/video/tegra/host/host1x/host1x_syncpt.c line 35

Quoted 9 lines
drivers/video/tegra/host/host1x/host1x_syncpt.c +9 -0
+/**
+ * Write the current syncpoint value back to hw.
+ */
+static void host1x_syncpt_reset(struct nvhost_syncpt *sp, u32 id)
+{
+	struct nvhost_master *dev = syncpt_to_dev(sp);
+	int min = nvhost_syncpt_read_min(sp, id);
+	writel(min, dev->sync_aperture + (host1x_sync_syncpt_0_r() + id * 4));
+}

Again, better to represent individual syncpoints with opaque pointers and dereference them here. Obviously this file will need access to the structure definition.

Quoted 16 lines
drivers/video/tegra/host/host1x/host1x_syncpt.c +16 -0
+static void host1x_syncpt_debug(struct nvhost_syncpt *sp)
+{
+	u32 i;
+	for (i = 0; i < nvhost_syncpt_nb_pts(sp); i++) {
+		u32 max = nvhost_syncpt_read_max(sp, i);
+		u32 min = nvhost_syncpt_update_min(sp, i);
+		if (!max && !min)
+			continue;
+		dev_info(&syncpt_to_dev(sp)->dev->dev,
+			"id %d (%s) min %d max %d\n",
+			i, syncpt_op().name(sp, i),
+			min, max);
+
+	}
+
+	for (i = 0; i < nvhost_syncpt_nb_bases(sp); i++) {

drivers/video/tegra/host/host1x/host1x_syncpt.c line 146

Quoted 10 lines
drivers/video/tegra/host/host1x/host1x_syncpt.c +10 -0
+		u32 base_val;
+		host1x_syncpt_read_wait_base(sp, i);
+		base_val = sp->base_val[i];
+		if (base_val)
+			dev_info(&syncpt_to_dev(sp)->dev->dev,
+					"waitbase id %d val %d\n",
+					i, base_val);
+
+	}
+}

This should probably be integrated with debugfs.

drivers/video/tegra/host/host1x/hw_host1x01_sync.h

Quoted 1 line
drivers/video/tegra/host/host1x/hw_host1x01_sync.h +0 -0

Autogenerated files are generally not acceptable. And I already mentioned before that you should be using #define instead of static inline functions for register and bit definitions.

drivers/video/tegra/host/nvhost_acm.c

Quoted 1 line
drivers/video/tegra/host/nvhost_acm.c +0 -0

[...]

This whole file largely looks like a reimplementation of runtime PM. You should investigate if you can't reuse the existing infrastructure.

Quoted 38 lines
drivers/video/tegra/host/nvhost_acm.c +38 -0
+	/* Init the power sysfs attributes for this device */
+	pdata->power_attrib = devm_kzalloc(&dev->dev,
+			sizeof(struct nvhost_device_power_attr),
+		GFP_KERNEL);
+	if (!pdata->power_attrib) {
+		dev_err(&dev->dev, "Unable to allocate sysfs attributes\n");
+		return -ENOMEM;
+	}
+	pdata->power_attrib->ndev = dev;
+
+	pdata->power_kobj = kobject_create_and_add("acm", &dev->dev.kobj);
+	if (!pdata->power_kobj) {
+		dev_err(&dev->dev, "Could not add dir 'power'\n");
+		err = -EIO;
+		goto fail_attrib_alloc;
+	}
+
+	attr = &pdata->power_attrib->power_attr[NVHOST_POWER_SYSFS_ATTRIB_CLOCKGATE_DELAY];
+	attr->attr.name = "clockgate_delay";
+	attr->attr.mode = S_IWUSR | S_IRUGO;
+	attr->show = clockgate_delay_show;
+	attr->store = clockgate_delay_store;
+	if (sysfs_create_file(pdata->power_kobj, &attr->attr)) {
+		dev_err(&dev->dev, "Could not create sysfs attribute clockgate_delay\n");
+		err = -EIO;
+		goto fail_clockdelay;
+	}
+
+	attr = &pdata->power_attrib->power_attr[NVHOST_POWER_SYSFS_ATTRIB_POWERGATE_DELAY];
+	attr->attr.name = "powergate_delay";
+	attr->attr.mode = S_IWUSR | S_IRUGO;
+	attr->show = powergate_delay_show;
+	attr->store = powergate_delay_store;
+	if (sysfs_create_file(pdata->power_kobj, &attr->attr)) {
+		dev_err(&dev->dev, "Could not create sysfs attribute powergate_delay\n");
+		err = -EIO;
+		goto fail_powergatedelay;
+	}

drivers/video/tegra/host/nvhost_acm.c line 413

Quoted 10 lines
drivers/video/tegra/host/nvhost_acm.c +10 -0
+
+	attr = &pdata->power_attrib->power_attr[NVHOST_POWER_SYSFS_ATTRIB_REFCOUNT];
+	attr->attr.name = "refcount";
+	attr->attr.mode = S_IRUGO;
+	attr->show = refcount_show;
+	if (sysfs_create_file(pdata->power_kobj, &attr->attr)) {
+		dev_err(&dev->dev, "Could not create sysfs attribute refcount\n");
+		err = -EIO;
+		goto fail_refcount;
+	}

This is a very funky way of creating sysfs attributes. What you probably want here are device attributes. See Documentation/filesystems/sysfs.txt and include/linux/sysfs.h.

But if you can replace this by runtime PM, you'll get similar functionality for free anyway.

Quoted 1 line
drivers/video/tegra/host/nvhost_syncpt.c +0 -0

[...]

drivers/video/tegra/host/nvhost_syncpt.c line 135

Quoted 11 lines
drivers/video/tegra/host/nvhost_syncpt.c +11 -0
+/**
+ * Returns true if syncpoint is expired, false if we may need to wait
+ */
+bool nvhost_syncpt_is_expired(
+	struct nvhost_syncpt *sp,
+	u32 id,
+	u32 thresh)
+{
+	u32 current_val;
+	u32 future_val;
+	smp_rmb();

What do you need a read memory barrier for?

Quoted 12 lines
drivers/video/tegra/host/nvhost_syncpt.c +12 -0
+/* Displays the current value of the sync point via sysfs */
+static ssize_t syncpt_min_show(struct kobject *kobj,
+		struct kobj_attribute *attr, char *buf)
+{
+	struct nvhost_syncpt_attr *syncpt_attr =
+		container_of(attr, struct nvhost_syncpt_attr, attr);
+
+	return snprintf(buf, PAGE_SIZE, "%u",
+			nvhost_syncpt_read(&syncpt_attr->host->syncpt,
+				syncpt_attr->id));
+}
+

drivers/video/tegra/host/nvhost_syncpt.c line 212

Quoted 10 lines
drivers/video/tegra/host/nvhost_syncpt.c +10 -0
+static ssize_t syncpt_max_show(struct kobject *kobj,
+		struct kobj_attribute *attr, char *buf)
+{
+	struct nvhost_syncpt_attr *syncpt_attr =
+		container_of(attr, struct nvhost_syncpt_attr, attr);
+
+	return snprintf(buf, PAGE_SIZE, "%u",
+			nvhost_syncpt_read_max(&syncpt_attr->host->syncpt,
+				syncpt_attr->id));
+}

This looks like it belongs in debugfs.

Quoted 7 lines
drivers/video/tegra/host/nvhost_syncpt.c +7 -0
+int nvhost_syncpt_init(struct platform_device *dev,
+		struct nvhost_syncpt *sp)
+{
+	int i;
+	struct nvhost_master *host = syncpt_to_dev(sp);
+	int err = 0;
+

drivers/video/tegra/host/nvhost_syncpt.c line 230

Quoted 10 lines
drivers/video/tegra/host/nvhost_syncpt.c +10 -0
+	/* Allocate structs for min, max and base values */
+	sp->min_val = kzalloc(sizeof(atomic_t) * nvhost_syncpt_nb_pts(sp),
+			GFP_KERNEL);
+	sp->max_val = kzalloc(sizeof(atomic_t) * nvhost_syncpt_nb_pts(sp),
+			GFP_KERNEL);
+	sp->base_val = kzalloc(sizeof(u32) * nvhost_syncpt_nb_bases(sp),
+			GFP_KERNEL);
+	sp->lock_counts =
+		kzalloc(sizeof(atomic_t) * nvhost_syncpt_nb_mlocks(sp),
+			GFP_KERNEL);

Again, I really think that syncpoints should be objects with corresponding attributes instead of keeping them in these arrays.

Quoted 1 line
include/linux/nvhost.h +0 -0

[...]

Quoted 58 lines
include/linux/nvhost.h +58 -0
+struct host1x_device_info {
+	int		nb_channels;	/* host1x: num channels supported */
+	int		nb_pts;		/* host1x: num syncpoints supported */
+	int		nb_bases;	/* host1x: num syncpoints supported */
+	u32		client_managed; /* host1x: client managed syncpts */
+	int		nb_mlocks;	/* host1x: number of mlocks */
+	const char	**syncpt_names;	/* names of sync points */
+};
+
+struct nvhost_device_data {
+	int		version;	/* ip version number of device */
+	int		id;		/* Separates clients of same hw */
+	int		index;		/* Hardware channel number */
+	void __iomem	*aperture;	/* Iomem mapped to kernel */
+
+	u32		syncpts;	/* Bitfield of sync points used */
+	u32		modulemutexes;	/* Bit field of module mutexes */
+
+	u32		class;		/* Device class */
+	bool		serialize;	/* Serialize submits in the channel */
+
+	int		powergate_ids[NVHOST_MODULE_MAX_POWERGATE_IDS];
+	bool		can_powergate;	/* True if module can be power gated */
+	int		clockgate_delay;/* Delay before clock gated */
+	int		powergate_delay;/* Delay before power gated */
+	struct nvhost_clock clocks[NVHOST_MODULE_MAX_CLOCKS];/* Clock names */
+
+	struct delayed_work powerstate_down;/* Power state management */
+	int		num_clks;	/* Number of clocks opened for dev */
+	struct clk	*clk[NVHOST_MODULE_MAX_CLOCKS];
+	struct mutex	lock;		/* Power management lock */
+	int		powerstate;	/* Current power state */
+	int		refcount;	/* Number of tasks active */
+	wait_queue_head_t idle_wq;	/* Work queue for idle */
+
+	struct nvhost_channel *channel;	/* Channel assigned for the module */
+	struct kobject *power_kobj;	/* kobj to hold power sysfs entries */
+	struct nvhost_device_power_attr *power_attrib;	/* sysfs attributes */
+	struct dentry *debugfs;		/* debugfs directory */
+
+	void *private_data;		/* private platform data */
+	struct platform_device *pdev;	/* owner platform_device */
+
+	/* Finalize power on. Can be used for context restore. */
+	void (*finalize_poweron)(struct platform_device *dev);
+
+	/* Device is busy. */
+	void (*busy)(struct platform_device *);
+
+	/* Device is idle. */
+	void (*idle)(struct platform_device *);
+
+	/* Device is going to be suspended */
+	void (*suspend_ndev)(struct platform_device *);
+
+	/* Device is initialized */
+	void (*init)(struct platform_device *dev);
+

include/linux/nvhost.h line 126

Quoted 10 lines
include/linux/nvhost.h +10 -0
+	/* Device is de-initialized. */
+	void (*deinit)(struct platform_device *dev);
+
+	/* Preparing for power off. Used for context save. */
+	int (*prepare_poweroff)(struct platform_device *dev);
+
+	/* Clock gating callbacks */
+	int (*prepare_clockoff)(struct platform_device *dev);
+	void (*finalize_clockon)(struct platform_device *dev);
+};

A lot of this can be removed if you use existing infrastructure and simplify the design a bit. Most of it can probably move into the main struct host1x to avoid needless indirections that make the code hard to follow and maintain.

Thierry

#141 lore raw

Re: [RFC,v2,8/8] drm: tegra: Add gr2d device

In reply to Terje Bergstrom
Quoted 7 lines · Terje Bergström

Add client driver for 2D device.

---

[...]

Quoted 8 lines
drivers/gpu/drm/tegra/drm.c +8 -0
+
+static int
+tegra_drm_ioctl_open_channel(struct drm_device *drm, void *data,
+			 struct drm_file *file_priv)
+{
+	struct tegra_drm_open_channel_args *args = data;
+	struct tegra_drm_client *client;
+	struct tegra_drm_context *context;

drivers/gpu/drm/tegra/drm.c MODULE_AUTHOR("Thierry Reding <[email protected]>"); · line 309

Quoted 10 lines
drivers/gpu/drm/tegra/drm.c +10 -0
+	struct tegra_drm_fpriv *fpriv = tegra_drm_fpriv(file_priv);
+	int err = 0;
+
+	dev_dbg(drm->dev, "> %s(fpriv=%p, class=%x)\n", __func__,
+			fpriv, args->class);
+
+	context = kzalloc(sizeof(*context), GFP_KERNEL);
+	if (!context) {
+		err = -ENOMEM;
+		goto out;

Change to "return -ENOMEM". Otherwise the NULL "context" will be kfree.

Quoted 27 lines
drivers/gpu/drm/tegra/drm.c +27 -0
+	}
+
+	list_for_each_entry(client, &tegra_drm_subdrv_list, list) {
+		if (client->class == args->class) {
+			dev_dbg(drm->dev, "opening client %x\n", args->class);
+			context->client = client;
+			err = client->ops->open_channel(client, context);
+			if (err)
+				goto out;
+
+			dev_dbg(drm->dev, "context %p\n", context);
+			list_add(&context->list, &fpriv->contexts);
+			args->context = context;
+			goto out;
+		}
+	}
+	err = -ENODEV;
+
+out:
+	if (err)
+		kfree(context);
+
+	dev_dbg(drm->dev, "< %s() = %d\n", __func__, err);
+	return err;
+}
+
+static int

drivers/gpu/drm/tegra/drm.c MODULE_AUTHOR("Thierry Reding <[email protected]>"); · line 346

Quoted 10 lines
drivers/gpu/drm/tegra/drm.c +10 -0
+tegra_drm_ioctl_close_channel(struct drm_device *drm, void *data,
+			 struct drm_file *file_priv)
+{
+	struct tegra_drm_open_channel_args *args = data;
+	struct tegra_drm_context *context;
+	struct tegra_drm_fpriv *fpriv = tegra_drm_fpriv(file_priv);
+	int err = 0;
+
+	dev_dbg(drm->dev, "> %s(fpriv=%p)\n", __func__, fpriv);
+	list_for_each_entry(context, &fpriv->contexts, list) {

Consider "list_for_each_entry_safe" cause you remove list members during the loop.

Quoted 14 lines
drivers/gpu/drm/tegra/drm.c +14 -0
+		if (context == args->context) {
+			context->client->ops->close_channel(context);
+			list_del(&context->list);
+			kfree(context);
+			goto out;
+		}
+	}
+	err = -EINVAL;
+
+out:
+	dev_dbg(drm->dev, "< %s() = %d\n", __func__, err);
+	return err;
+}
+

[...]

drivers/gpu/drm/tegra/gr2d.c line 72

Quoted 3 lines
drivers/gpu/drm/tegra/gr2d.c new file +3 -0
+
+static int gr2d_submit(struct tegra_drm_context *context,
+		struct tegra_drm_submit_args *args)

I'm still in the middle of code reading of job submit, so I'll get you back if I find something.

[...]

drivers/gpu/drm/tegra/gr2d.c line 208

Quoted 4 lines
drivers/gpu/drm/tegra/gr2d.c new file +4 -0
+
+static struct of_device_id gr2d_match[] __devinitdata = {
+	{ .compatible = "nvidia,tegra20-gr2d", },
+	{ .compatible = "nvidia,tegra30-gr2d", },

Just as swarren mentioned, you'd better place "nvidia,tegra30-gr2d" in the front of "nvidia,tegra20-gr2d"...

[...]

include/drm/tegra_drm.h line 38

Quoted 6 lines
include/drm/tegra_drm.h new file +6 -0
+
+#define DRM_TEGRA_GEM_CREATE		0x00
+
+#define DRM_IOCTL_TEGRA_GEM_CREATE	DRM_IOWR(DRM_COMMAND_BASE + \
+		DRM_TEGRA_GEM_CREATE, struct tegra_gem_create)
+

Just a very minor suggestion: could you put them at the end of this file? I mean, stay with other IOCTLs like SYNCPT_READ, SYNCPT_WAIT...

[...]

Quoted 21 lines
include/drm/tegra_drm.h new file +20 -0
+
+#define DRM_TEGRA_DRM_SYNCPT_READ 0x01
+#define DRM_TEGRA_DRM_SYNCPT_INCR 0x02
+#define DRM_TEGRA_DRM_SYNCPT_WAIT 0x03
+#define DRM_TEGRA_DRM_OPEN_CHANNEL 0x04
+#define DRM_TEGRA_DRM_CLOSE_CHANNEL 0x05
+#define DRM_TEGRA_DRM_GET_SYNCPOINTS 0x06
+#define DRM_TEGRA_DRM_GET_MODMUTEXES 0x07
+#define DRM_TEGRA_DRM_SUBMIT 0x08
+
+#define DRM_IOCTL_TEGRA_DRM_SYNCPT_READ DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_SYNCPT_READ, struct tegra_drm_syncpt_read_args)
+#define DRM_IOCTL_TEGRA_DRM_SYNCPT_INCR DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_SYNCPT_INCR, struct tegra_drm_syncpt_incr_args)
+#define DRM_IOCTL_TEGRA_DRM_SYNCPT_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_SYNCPT_WAIT, struct tegra_drm_syncpt_wait_args)
+#define DRM_IOCTL_TEGRA_DRM_OPEN_CHANNEL DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_OPEN_CHANNEL, struct tegra_drm_open_channel_args)
+#define DRM_IOCTL_TEGRA_DRM_CLOSE_CHANNEL DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_CLOSE_CHANNEL, struct tegra_drm_open_channel_args)
+#define DRM_IOCTL_TEGRA_DRM_GET_SYNCPOINTS DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_GET_SYNCPOINTS, struct tegra_drm_get_channel_param_args)
+#define DRM_IOCTL_TEGRA_DRM_GET_MODMUTEXES DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_GET_MODMUTEXES, struct tegra_drm_get_channel_param_args)
+#define DRM_IOCTL_TEGRA_DRM_SUBMIT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_DRM_SUBMIT, struct tegra_drm_submit_args)
+
+#endif
#130 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

In reply to Lucas Stach
Quoted 8 lines · Lucas Stach

Am Mittwoch, den 28.11.2012, 18:23 +0200 schrieb Terje Bergström:

Quoted 2 lines

Sorry. I promised in another thread a write-up explaining the design. I still owe you guys that.

That would be really nice to have. I'm also particularly interested in how you plan to do synchronization of command streams to different engines working together, if that's not too much to ask for now. Like userspace uploading a texture in a buffer, 2D engine doing mipmap generation, 3D engine using mipmapped texture.

I can briefly explain (and then copy-paste to a coherent text once I get to it) how inter-engine synchronization is done. It's not specifically for 2D or 3D, but generic to any host1x client.

Sync point register is a counter that can only increase. It starts from 0 and is incremented by a host1x client or CPU. host1x can freeze a channel until a sync point value is reached, and it can trigger an interrupt upon reaching a threshold. On Tegra2 and Tegra3 we have 32 sync points.

host1x clients all implement a method for incrementing a sync point based on a condition, and on all of them (well, not entirely true) the register is number 0. The most used condition is op_done, telling the client to increment sync point once the previous operations are done.

In kernel, we keep track of the active range of sync point values, i.e. ones we expect to be reached with the active jobs. Active range's minimum is the current value read from hw and shadowed in memory. At job submit time, kernel increments the maximum by the number of sync points the stream announces it will perform. After performing the increment, we have a number, which the sync point is supposed to reach at the end of submit. That number is the the fence and it is recorded in kernel and returned to user space.

So, when user space flushes, it receives a fence. It can insert the fence into another command stream as parameter to a host1x channel wait. This makes that channel freeze until an operation in another channel is finished. That's how different host1x clients can synchronize without using CPU.

Kernel's sync point wait essentially puts the process into sleep until host1x sends an interrupt and we determine the value that a process is waiting for, has been reached.

On top of this, we guard against wrapping issues by nulling out any sync point waits (CPU or inside stream) that are waiting for values outside the active range, and we have a timeout for jobs so that we can kick out misbehaving command streams.

Quoted 7 lines

Ah yes I see. So if we consider nvhost to be the central entity in charge of controlling all host1x clients and tegradrm as the interface that happens to bundle display, 2d and 3d engine functionality into it's interface we should probably aim for two things:
1. Move everything needed by all engines down into nvhost (I especially see the allocator falling under this point, I'll explain why this would be beneficial a bit later)

Ok. This is almost the current design, except for the allocator.

Quoted 4 lines

2. Move the exposed DRM interface more in line with other DRM drivers. Please take a look at how for example the GEM_EXECBUF ioctl works on other drivers to get a feeling of what I'm talking about. Everything using the display, 2D and maybe later on the 3D engine should only deal

Quoted 8 lines

with GEM handles. I really don't like the idea of having a single userspace application, which uses engines with similar and known requirements (DDX) dealing with dma-buf handles or other similar high overhead stuff to do the most basic tasks.
If we move down the allocator into nvhost we can use buffers allocated from this to back GEM or V4L2 buffers transparently. The ioctl to allocate a GEM buffer shouldn't do much more than wrapping the nvhost buffer.

Ok, this is actually what we do downstream. We use dma-buf handles only for purposes where they're really needed (in fact, none yet), and use our downstream allocator handles for the rest. I did this, because benchmarks were showing that memory management overhead shoot through the roof if I tried doing everything via dma-buf.

We can move support for allocating GEM handles to nvhost, and GEM handles can be treated just as another memory handle type in nvhost. tegradrm would then call nvhost for allocation.

Quoted 8 lines

This may also solve your problem with having multiple mappings of the same buffer into the very same address space, as nvhost is the single instance that manages all host1x client address spaces. If the buffer is originating from there you can easily check if it's already mapped. For Tegra 3 to do things in an efficient way we likely have to move away from dealing with the DMA API to dealing with the IOMMU API, this gets a _lot_ easier_ if you have a single point where you manage memory allocation and address space.

Yep, this would definitely simplify our IOMMU problem. But, I thought the canonical way of dealing with device memory is DMA API, and you're saying that we should just bypass it and call IOMMU directly?

Quoted 6 lines
Quoted 6 lines

Concurrency is handled with sync points. User space will know when a command stream is processed and can be reused by comparing the current sync point value, and the fence that 2D driver returned to user space. User space can have a pool of buffers and can recycle when it knows it can do so. But, this is not enforced by kernel.

Quoted 10 lines

This is the point where we have differ: You have to deal with syncpts in kernel anyway, otherwise you don't know when it's safe to destroy a buffer. And no, userspace should not have the ability to destroy a buffer itself, userspace should always just be able to free it's reference to the buffer. Remember: never trust the userspace. And if you are dealing with syncpts in kernel anyway, you can just go ahead and enforce some sane concurrency rules. There may be some corener cases related to userspace suballocating a kernel buffer, which might need some more thought still, but that's not a valid excuse to not do any concurrency validation in kernel.

nvhost is already dealing with sync points, and protecting memory from being freed if it's used. We use refcounting to do that. When a job is sent to hw, we get reference to all memory (command stream & surfaces). When job is done (fence reached), nvhost unreferences them. User space can free the memory it has allocated, but kernel would hold on to it until it's safe to actually release the memory.

Quoted 6 lines
Quoted 6 lines

The difference with your proposal and what I posted is the level of control user space has over its command stream management. But as said, 2D streams are so short that my guess is that there's not too much penalty copying it to kernel managed host1x push buffer directly instead of inserting a GATHER reference.

Quoted 7 lines

This an implementation detail. Whether you shoot down the old pushbuf mapping and insert a new one pointing to free backing memory (which may be the way to go for 3D) or do an immediate copy of the channel pushbuf contents to the host1x pushbuf (which may be beneficial for very small pushs) is all the same. Both methods implicitly guarantee that the memory mapped by userspace always points to a location the CPU can write to without interfering with the GPU.

Ok. Based on this, I propose the way to go for cases without IOMMU support and all Tegra20 cases (as Tegra20's GART can't provide memory protection) is to copy the stream to host1x push buffer. In Tegra30 with IOMMU support we can just reference the buffer. This way we don't have to do expensive MMU operations.

Quoted 2 lines

I really enjoyed the discussion so far and hope we can get to the point where we have a nice design/interface, working together.

Thanks. I don't have a strict deadline for upstreaming, so I'm fine continuing with discussion until we're settled, and then doing the needed changes.

My goal is to end up with something that we can take advantage of in upstream with tegradrm and 2D, but also downstream with the rest of the downstream stack. That way there's no technical barrier to us moving in downstream to use the upstream code.

Terje
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#40 lore raw

Re: [RFC v2 2/8] video: tegra: Add syncpoint wait and interrupts

In reply to Terje Bergstrom

On Mon, Nov 26, 2012 at 03:19:08PM +0200, Terje Bergstrom wrote:
[...]

Quoted 1 line
drivers/video/tegra/host/chip_support.h +0 -0

[...]

Quoted 17 lines
drivers/video/tegra/host/chip_support.h +14 -0
+struct nvhost_intr_ops {
+	void (*init_host_sync)(struct nvhost_intr *);
+	void (*set_host_clocks_per_usec)(
+		struct nvhost_intr *, u32 clocks);
+	void (*set_syncpt_threshold)(
+		struct nvhost_intr *, u32 id, u32 thresh);
+	void (*enable_syncpt_intr)(struct nvhost_intr *, u32 id);
+	void (*disable_syncpt_intr)(struct nvhost_intr *, u32 id);
+	void (*disable_all_syncpt_intrs)(struct nvhost_intr *);
+	int  (*request_host_general_irq)(struct nvhost_intr *);
+	void (*free_host_general_irq)(struct nvhost_intr *);
+	int (*free_syncpt_irq)(struct nvhost_intr *);
+};
+
 struct nvhost_chip_support {
 	const char *soc_name;

drivers/video/tegra/host/chip_support.h struct nvhost_syncpt_ops { · line 67

Quoted 10 lines
drivers/video/tegra/host/chip_support.h +2 -0
 	struct nvhost_syncpt_ops syncpt;
+	struct nvhost_intr_ops intr;
 };
 
 struct nvhost_chip_support *nvhost_get_chip_ops(void);
 
 #define syncpt_op()		(nvhost_get_chip_ops()->syncpt)
+#define intr_op()		(nvhost_get_chip_ops()->intr)
 
 int nvhost_init_chip_support(struct nvhost_master *host);

The same comments apply as for patch 1. Reducing the number of indirections here make things a lot easier.

drivers/video/tegra/host/dev.c u32 host1x_syncpt_read(u32 id) · line 46

Quoted 9 lines
drivers/video/tegra/host/dev.c +1 -0
index 98c9c9f..025a820 100644
@@ -43,6 +43,13 @@ u32 host1x_syncpt_read(u32 id)
 }
 EXPORT_SYMBOL(host1x_syncpt_read);
 
+int host1x_syncpt_wait(u32 id, u32 thresh, u32 timeout, u32 *value)

The choice of data types is odd here. id refers to a syncpt so a better choice would have been unsigned int because the size of the variable doesn't actually matter. But as I already said in my reply to patch 1, these are resources and should therefore better be abstracted through an opaque pointer anyway.

timeout is usually signed long, so this function should reflect that. As for the value this is probably fine as it will effectively be set from a register value. Though you also cache them in software using atomics.

drivers/video/tegra/host/dev.c u32 host1x_syncpt_read(u32 id)

Quoted 13 lines
drivers/video/tegra/host/dev.c +13 -0
+static void clock_on_host(struct platform_device *dev)
+{
+	struct nvhost_device_data *pdata = platform_get_drvdata(dev);
+	struct nvhost_master *host = nvhost_get_private_data(dev);
+	nvhost_intr_start(&host->intr, clk_get_rate(pdata->clk[0]));
+}
+
+static int clock_off_host(struct platform_device *dev)
+{
+	struct nvhost_master *host = nvhost_get_private_data(dev);
+	nvhost_intr_stop(&host->intr);
+	return 0;
+}

This is a good example of why these indirections are wasteful. You constantly need to look up the host pointer just to call another function on it. With some modifications to the structure layouts it should be possible to make this a lot more straightforward.

Quoted 29 lines
drivers/video/tegra/host/host1x/host1x.h +2 -0
index 76748ac..af9bfef 100644
@@ -25,6 +25,7 @@
 #include <linux/nvhost.h>
 
 #include "nvhost_syncpt.h"
+#include "nvhost_intr.h"
 
 #define TRACE_MAX_LENGTH	128U
 #define IFACE_NAME		"nvhost"
@@ -33,6 +34,7 @@ struct nvhost_master {
 	void __iomem *aperture;
 	void __iomem *sync_aperture;
 	struct nvhost_syncpt syncpt;
+	struct nvhost_intr intr;
 	struct platform_device *dev;
 	struct host1x_device_info info;
 };
drivers/video/tegra/host/host1x/host1x01.c +1 -0
index d53302d..5bf0e6e 100644
@@ -26,12 +26,14 @@
 #include "chip_support.h"
 
 #include "host1x/host1x_syncpt.c"
+#include "host1x/host1x_intr.c"

drivers/video/tegra/host/host1x/host1x01.c line 39

Quoted 10 lines
drivers/video/tegra/host/host1x/host1x01.c +1 -0
 
 int nvhost_init_host1x01_support(struct nvhost_master *host,
 	struct nvhost_chip_support *op)
 {
 	host->sync_aperture = host->aperture + HOST1X_CHANNEL_SYNC_REG_BASE;
 	op->syncpt = host1x_syncpt_ops;
+	op->intr = host1x_intr_ops;
 
 	return 0;
 }

Also you need to touch a lot of files just to add this new feature. This makes maintenance needlessly difficult.

Quoted 1 line
drivers/video/tegra/host/host1x/host1x_intr.c +0 -0

[...]

drivers/video/tegra/host/host1x/host1x_intr.c line 31

Quoted 10 lines
drivers/video/tegra/host/host1x/host1x_intr.c +10 -0
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/io.h>
+#include <asm/mach/irq.h>
+
+#include "nvhost_intr.h"
+#include "host1x/host1x.h"
+
+/* Spacing between sync registers */
+#define REGISTER_STRIDE 4

Erm... no. The usual way you should be doing this is either make the register definitions account for the stride or use accessors that apply the stride. You should be doing the latter anyway to make accesses. For example:

	static inline void host1x_syncpt_writel(struct host1x *host1x,
						unsigned long value,
						unsigned long offset)
	{
		writel(value, host1x->regs + SYNCPT_BASE + offset);
	}

	static inline unsigned long host1x_syncpt_readl(struct host1x *host1x,
							unsigned long offset)
	{
		return readl(host1x->regs + SYNCPT_BASE + offset);
	}

Alternatively, if you want to pass the register index instead of the offset, you can use just multiply the offset in that function:

	writel(value, host1x->regs + SYNCPT_BASE + (offset << 2));

The same can also be done with the non-syncpt registers.

Quoted 12 lines
drivers/video/tegra/host/host1x/host1x_intr.c +12 -0
+static irqreturn_t syncpt_thresh_cascade_isr(int irq, void *dev_id)
+{
+	struct nvhost_master *dev = dev_id;
+	void __iomem *sync_regs = dev->sync_aperture;
+	struct nvhost_intr *intr = &dev->intr;
+	unsigned long reg;
+	int i, id;
+
+	for (i = 0; i < dev->info.nb_pts / BITS_PER_LONG; i++) {
+		reg = readl(sync_regs +
+				host1x_sync_syncpt_thresh_cpu0_int_status_r() +
+				i * REGISTER_STRIDE);

drivers/video/tegra/host/host1x/host1x_intr.c line 63

Quoted 10 lines
drivers/video/tegra/host/host1x/host1x_intr.c +10 -0
+		for_each_set_bit(id, &reg, BITS_PER_LONG) {
+			struct nvhost_intr_syncpt *sp =
+				intr->syncpt + (i * BITS_PER_LONG + id);
+			host1x_intr_syncpt_thresh_isr(sp);
+			queue_work(intr->wq, &sp->work);
+		}
+	}
+
+	return IRQ_HANDLED;
+}

Maybe it would be better to call the syncpt handlers in interrupt context and let them schedule work if they want to. I'm thinking about the display controllers which may want to use syncpoints for VBLANK support.

Quoted 10 lines
drivers/video/tegra/host/host1x/host1x_intr.c +10 -0
+static void host1x_intr_init_host_sync(struct nvhost_intr *intr)
+{
+	struct nvhost_master *dev = intr_to_dev(intr);
+	void __iomem *sync_regs = dev->sync_aperture;
+	int i, err, irq;
+
+	writel(0xffffffffUL,
+		sync_regs + host1x_sync_syncpt_thresh_int_disable_r());
+	writel(0xffffffffUL,
+		sync_regs + host1x_sync_syncpt_thresh_cpu0_int_status_r());

drivers/video/tegra/host/host1x/host1x_intr.c line 84

Quoted 10 lines
drivers/video/tegra/host/host1x/host1x_intr.c +10 -0
+
+	for (i = 0; i < dev->info.nb_pts; i++)
+		INIT_WORK(&intr->syncpt[i].work, syncpt_thresh_cascade_fn);
+
+	irq = platform_get_irq(dev->dev, 0);
+	WARN_ON(IS_ERR_VALUE(irq));
+	err = devm_request_irq(&dev->dev->dev, irq,
+				syncpt_thresh_cascade_isr,
+				IRQF_SHARED, "host_syncpt", dev);
+	WARN_ON(IS_ERR_VALUE(err));

You should be handling this properly and propagate these errors to the corresponding .probe().

Quoted 8 lines
drivers/video/tegra/host/host1x/host1x_intr.c +8 -0
+/**
+ * Sync point threshold interrupt service function
+ * Handles sync point threshold triggers, in interrupt context
+ */
+static void host1x_intr_syncpt_thresh_isr(struct nvhost_intr_syncpt *syncpt)
+{
+	unsigned int id = syncpt->id;
+	struct nvhost_intr *intr = intr_syncpt_to_intr(syncpt);

drivers/video/tegra/host/host1x/host1x_intr.c line 173

Quoted 10 lines
drivers/video/tegra/host/host1x/host1x_intr.c +10 -0
+
+	void __iomem *sync_regs = intr_to_dev(intr)->sync_aperture;
+
+	u32 reg = BIT_WORD(id) * REGISTER_STRIDE;
+
+	writel(BIT_MASK(id), sync_regs +
+		host1x_sync_syncpt_thresh_int_disable_r() + reg);
+	writel(BIT_MASK(id), sync_regs +
+		host1x_sync_syncpt_thresh_cpu0_int_status_r() + reg);
+}

So this disables all interrupts and is called from the syncpt interrupt handler. Where are the interrupts reenabled? Do host1x clients have to do that manually?

Quoted 21 lines
drivers/video/tegra/host/host1x/host1x_intr.c +21 -0
+static int host1x_intr_request_host_general_irq(struct nvhost_intr *intr)
+{
+	void __iomem *sync_regs = intr_to_dev(intr)->sync_aperture;
+	int err;
+
+	/* master disable for general (not syncpt) host interrupts */
+	writel(0, sync_regs + host1x_sync_intmask_r());
+
+	/* clear status & extstatus */
+	writel(0xfffffffful, sync_regs + host1x_sync_hintstatus_ext_r());
+	writel(0xfffffffful, sync_regs + host1x_sync_hintstatus_r());
+
+	err = request_irq(intr->host_general_irq, host1x_intr_host1x_isr, 0,
+			"host_status", intr);
+	if (err)
+		return err;
+
+	/* enable extra interrupt sources IP_READ_INT and IP_WRITE_INT */
+	writel(BIT(30) | BIT(31), sync_regs + host1x_sync_hintmask_ext_r());
+
+	/* enable extra interrupt sources */

drivers/video/tegra/host/host1x/host1x_intr.c line 235

Quoted 10 lines
drivers/video/tegra/host/host1x/host1x_intr.c +10 -0
+	writel(BIT(12) | BIT(31), sync_regs + host1x_sync_hintmask_r());
+
+	/* enable host module interrupt to CPU0 */
+	writel(BIT(0), sync_regs + host1x_sync_intc0mask_r());
+
+	/* master enable for general (not syncpt) host interrupts */
+	writel(BIT(0), sync_regs + host1x_sync_intmask_r());
+
+	return err;
+}

You should add defines for these bits, which will likely make the comments redundant.

Quoted 1 line
drivers/video/tegra/host/nvhost_intr.c +0 -0

[...]

drivers/video/tegra/host/nvhost_intr.c line 108

Quoted 10 lines
drivers/video/tegra/host/nvhost_intr.c +10 -0
+void reset_threshold_interrupt(struct nvhost_intr *intr,
+			       struct list_head *head,
+			       unsigned int id)
+{
+	u32 thresh = list_first_entry(head,
+				struct nvhost_waitlist, list)->thresh;
+
+	intr_op().set_syncpt_threshold(intr, id, thresh);
+	intr_op().enable_syncpt_intr(intr, id);
+}

Okay, so this is where syncpoint interrupts are reenabled. The rest of this whole wait queue code looks overly complex. I'll need to go through that separately and more thoroughly.

drivers/video/tegra/host/nvhost_intr.c line 257

Quoted 5 lines
drivers/video/tegra/host/nvhost_intr.c +5 -0
+void *nvhost_intr_alloc_waiter()
+{
+	return kzalloc(sizeof(struct nvhost_waitlist),
+			GFP_KERNEL|__GFP_REPEAT);
+}

I don't think we need __GFP_REPEAT here.

drivers/video/tegra/host/nvhost_intr.c line 279

Quoted 3 lines
drivers/video/tegra/host/nvhost_intr.c +3 -0
+/*** Init & shutdown ***/
+
+int nvhost_intr_init(struct nvhost_intr *intr, u32 irq_gen, u32 irq_sync)

Again, using u32 for interrupt numbers is unusual.

drivers/video/tegra/host/nvhost_intr.c line 288

Quoted 9 lines
drivers/video/tegra/host/nvhost_intr.c +9 -0
+{
+	unsigned int id;
+	struct nvhost_intr_syncpt *syncpt;
+	struct nvhost_master *host = intr_to_dev(intr);
+	u32 nb_pts = nvhost_syncpt_nb_pts(&host->syncpt);
+
+	mutex_init(&intr->mutex);
+	intr->host_syncpt_irq_base = irq_sync;
+	intr->wq = create_workqueue("host_syncpt");

What if create_workqueue() fails?

drivers/video/tegra/host/nvhost_intr.c line 295

Quoted 7 lines
drivers/video/tegra/host/nvhost_intr.c +7 -0
+	intr_op().init_host_sync(intr);
+	intr->host_general_irq = irq_gen;
+	intr_op().request_host_general_irq(intr);
+
+	for (id = 0, syncpt = intr->syncpt;
+	     id < nb_pts;
+	     ++id, ++syncpt) {

This fits perfectly well on a single line, no need to wrap it. Also you could instead of incrementing syncpt, move it into the loop and assign it based on id.

	for (id = 0; id < nb_pts; id++) {
		struct nvhost_intr_syncpt *syncpt = &intr->syncpt[id];
		...
	}

drivers/video/tegra/host/nvhost_intr.c line 321

Quoted 7 lines
drivers/video/tegra/host/nvhost_intr.c +7 -0
+void nvhost_intr_start(struct nvhost_intr *intr, u32 hz)
+{
+	mutex_lock(&intr->mutex);
+
+	intr_op().init_host_sync(intr);
+	intr_op().set_host_clocks_per_usec(intr,
+					       (hz + 1000000 - 1)/1000000);

DIV_ROUND_UP(hz)?

Quoted 1 line
drivers/video/tegra/host/nvhost_syncpt.h +0 -0

[...]

Quoted 25 lines

index b883442..dbd3890 100644

drivers/video/tegra/host/nvhost_syncpt.h +10 -0
@@ -126,6 +126,16 @@ u32 nvhost_syncpt_read_wait_base(struct nvhost_syncpt *sp, u32 id);
 
 void nvhost_syncpt_incr(struct nvhost_syncpt *sp, u32 id);
 
+int nvhost_syncpt_wait_timeout(struct nvhost_syncpt *sp, u32 id, u32 thresh,
+			u32 timeout, u32 *value);
+
+static inline int nvhost_syncpt_wait(struct nvhost_syncpt *sp,
+		u32 id, u32 thresh)
+{
+	return nvhost_syncpt_wait_timeout(sp, id, thresh,
+					  MAX_SCHEDULE_TIMEOUT, NULL);
+}
+
 void nvhost_syncpt_debug(struct nvhost_syncpt *sp);
 
 static inline int nvhost_syncpt_is_valid(struct nvhost_syncpt *sp, u32 id)
include/linux/nvhost.h +0 -0
index 20ba2a5..745f31c 100644

include/linux/nvhost.h struct nvhost_device_power_attr; · line 38

Quoted 4 lines
include/linux/nvhost.h +1 -0
@@ -35,6 +35,7 @@ struct nvhost_device_power_attr;
 #define NVHOST_DEFAULT_CLOCKGATE_DELAY		.clockgate_delay = 25
 #define NVHOST_NAME_SIZE			24
 #define NVSYNCPT_INVALID			(-1)
+#define NVHOST_NO_TIMEOUT			(-1)

Couldn't you reuse MAX_SCHEDULE_TIMEOUT instead? You already use it as the value for the timeout parameter in nvhost_syncpt_wait().

Thierry

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#131 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

In reply to Terje Bergström

Am Donnerstag, den 29.11.2012, 10:17 +0200 schrieb Terje Bergström:

Quoted 10 lines · Lucas Stach
Quoted 8 lines

Am Mittwoch, den 28.11.2012, 18:23 +0200 schrieb Terje Bergström:

Quoted 2 lines

Sorry. I promised in another thread a write-up explaining the design. I still owe you guys that.

That would be really nice to have. I'm also particularly interested in how you plan to do synchronization of command streams to different engines working together, if that's not too much to ask for now. Like userspace uploading a texture in a buffer, 2D engine doing mipmap generation, 3D engine using mipmapped texture.

Quoted 3 lines

I can briefly explain (and then copy-paste to a coherent text once I get to it) how inter-engine synchronization is done. It's not specifically for 2D or 3D, but generic to any host1x client.

[...]
Thanks for that.
[...]

Quoted 19 lines
Quoted 4 lines

2. Move the exposed DRM interface more in line with other DRM drivers. Please take a look at how for example the GEM_EXECBUF ioctl works on other drivers to get a feeling of what I'm talking about. Everything using the display, 2D and maybe later on the 3D engine should only deal

Quoted 8 lines

with GEM handles. I really don't like the idea of having a single userspace application, which uses engines with similar and known requirements (DDX) dealing with dma-buf handles or other similar high overhead stuff to do the most basic tasks.
If we move down the allocator into nvhost we can use buffers allocated from this to back GEM or V4L2 buffers transparently. The ioctl to allocate a GEM buffer shouldn't do much more than wrapping the nvhost buffer.

Ok, this is actually what we do downstream. We use dma-buf handles only for purposes where they're really needed (in fact, none yet), and use our downstream allocator handles for the rest. I did this, because benchmarks were showing that memory management overhead shoot through the roof if I tried doing everything via dma-buf.

Quoted 4 lines

We can move support for allocating GEM handles to nvhost, and GEM handles can be treated just as another memory handle type in nvhost. tegradrm would then call nvhost for allocation.

We should aim for a clean split here. GEM handles are something which is really specific to how DRM works and as such should be constructed by tegradrm. nvhost should really just manage allocations/virtual address space and provide something that is able to back all the GEM handle operations.

nvhost has really no reason at all to even know about GEM handles. If you back a GEM object by a nvhost object you can just peel out the nvhost handles from the GEM wrapper in the tegradrm submit ioctl handler and queue the job to nvhost using it's native handles.

This way you would also be able to construct different handles (like GEM obj or V4L2 buffers) from the same backing nvhost object. Note that I'm not sure how useful this would be, but it seems like a reasonable design to me being able to do so.

Quoted 9 lines
Quoted 8 lines

This may also solve your problem with having multiple mappings of the same buffer into the very same address space, as nvhost is the single instance that manages all host1x client address spaces. If the buffer is originating from there you can easily check if it's already mapped. For Tegra 3 to do things in an efficient way we likely have to move away from dealing with the DMA API to dealing with the IOMMU API, this gets a _lot_ easier_ if you have a single point where you manage memory allocation and address space.

Quoted 4 lines

Yep, this would definitely simplify our IOMMU problem. But, I thought the canonical way of dealing with device memory is DMA API, and you're saying that we should just bypass it and call IOMMU directly?

This is true for all standard devices. But we should not consider this as something set in stone and then building some crufty design around it. If we can manage to make our design a lot cleaner by managing DMA memory and the corresponding IOMMU address spaces for the host1x devices ourselves, I think this is the way to go. All other graphics drivers in the Linux kernel have to deal with their GTT in some way, we just happen to do so by using a shared system IOMMU and not something that is exclusive to the graphics devices.

This is more work on the side of nvhost, but IMHO the benefits make it look worthwhile.

What we should avoid is something that completely escapes the standard ways of dealing with memory used in the Linux kernel, like using carveout areas, but I think this is already consensus among us all.

[...]

Quoted 8 lines
Quoted 7 lines

This an implementation detail. Whether you shoot down the old pushbuf mapping and insert a new one pointing to free backing memory (which may be the way to go for 3D) or do an immediate copy of the channel pushbuf contents to the host1x pushbuf (which may be beneficial for very small pushs) is all the same. Both methods implicitly guarantee that the memory mapped by userspace always points to a location the CPU can write to without interfering with the GPU.

Quoted 6 lines

Ok. Based on this, I propose the way to go for cases without IOMMU support and all Tegra20 cases (as Tegra20's GART can't provide memory protection) is to copy the stream to host1x push buffer. In Tegra30 with IOMMU support we can just reference the buffer. This way we don't have to do expensive MMU operations.

Sounds like a plan.

Regards,
Lucas

#36 lore raw

Re: [RFC,v2,1/8] video: tegra: Add nvhost driver

In reply to Terje Bergstrom
Quoted 27 lines · Terje Bergström

Add nvhost, the driver for host1x. This patch adds support for reading and incrementing sync points and dynamic power management.

---
drivers/video/Kconfig | 2 +

 drivers/video/Makefile                             |    2 +
 drivers/video/tegra/host/Kconfig                   |    5 +
 drivers/video/tegra/host/Makefile                  |   10 +
 drivers/video/tegra/host/chip_support.c            |   48 ++
 drivers/video/tegra/host/chip_support.h            |   52 +++
 drivers/video/tegra/host/dev.c                     |   96 ++++
 drivers/video/tegra/host/host1x/Makefile           |    7 +
 drivers/video/tegra/host/host1x/host1x.c           |  204 +++++++++
 drivers/video/tegra/host/host1x/host1x.h           |   78 ++++
 drivers/video/tegra/host/host1x/host1x01.c         |   37 ++
 drivers/video/tegra/host/host1x/host1x01.h         |   29 ++
 .../video/tegra/host/host1x/host1x01_hardware.h    |   36 ++
 drivers/video/tegra/host/host1x/host1x_syncpt.c    |  156 +++++++
 drivers/video/tegra/host/host1x/hw_host1x01_sync.h |  398 ++++++++++++++++
 drivers/video/tegra/host/nvhost_acm.c              |  481 ++++++++++++++++++++
 drivers/video/tegra/host/nvhost_acm.h              |   45 ++
 drivers/video/tegra/host/nvhost_syncpt.c           |  333 ++++++++++++++
 drivers/video/tegra/host/nvhost_syncpt.h           |  136 ++++++
 include/linux/nvhost.h                             |  143 ++++++
 20 files changed, 2298 insertions(+)

[...]

drivers/video/tegra/host/chip_support.c line 33

Quoted 10 lines
drivers/video/tegra/host/chip_support.c +9 -0
+#include "chip_support.h"
+#include "host1x/host1x01.h"
+
+struct nvhost_chip_support *nvhost_chip_ops;
+
+struct nvhost_chip_support *nvhost_get_chip_ops(void)
+{
+	return nvhost_chip_ops;
+}

If you wanna hide "nvhost_chip_ops" from other source files, declare it as "static". So this is not a static member which means other files is able to touch it by "extern" but we also define a function to get it, and this looks redundant.

[...]

drivers/video/tegra/host/host1x/Makefile line 5

Quoted 11 lines
drivers/video/tegra/host/host1x/Makefile new file +5 -0
new file mode 100644
index 0000000..330d507
@@ -0,0 +1,7 @@
+ccflags-y = -Idrivers/video/tegra/host
+
+nvhost-host1x-objs  = \
+	host1x.o \
+	host1x01.o

Can we rename this "host1x01.c"? I just really don't like this kind of variables/files, I mean, I can't imagine the purpose of the file according to it's name...

[...]

drivers/video/tegra/host/host1x/Makefile

Quoted 11 lines
drivers/video/tegra/host/host1x/Makefile new file +11 -0
+
+static int __devinit nvhost_alloc_resources(struct nvhost_master *host)
+{
+	int err;
+
+	err = nvhost_init_chip_support(host);
+	if (err)
+		return err;
+
+	return 0;
+}

Just "return nvhost_init_chip_support(host)" is enough. If so, do we still need this function?

[...]

Quoted 3 lines
drivers/video/tegra/host/host1x/Makefile new file +3 -0
+
+static int __devinit nvhost_probe(struct platform_device *dev)
+

[...]

drivers/video/tegra/host/host1x/Makefile

Quoted 5 lines
drivers/video/tegra/host/host1x/Makefile new file +5 -0
+	dev_info(&dev->dev, "initialized\n");
+
+	return 0;
+
+fail:

Add more "free" codes here. Actually, "nvhost_free_resources" frees the host->intr.syncpt which is not needed to free manually. Seems at least we need to add "nvhost_syncpt_deinit" here.

[...]

drivers/video/tegra/host/host1x/Makefile

Quoted 4 lines
drivers/video/tegra/host/host1x/Makefile new file +4 -0
+
+static struct of_device_id host1x_match[] __devinitdata = {
+	{ .compatible = "nvidia,tegra20-host1x", },
+	{ .compatible = "nvidia,tegra30-host1x", },

Again, place tegra30-host1x before tegra20-host1x.

[...]

Quoted 15 lines
drivers/video/tegra/host/host1x/Makefile new file +15 -0
+
+/**
+ * Write a cpu syncpoint increment to the hardware, without touching
+ * the cache. Caller is responsible for host being powered.
+ */
+static void host1x_syncpt_cpu_incr(struct nvhost_syncpt *sp, u32 id)
+{
+	struct nvhost_master *dev = syncpt_to_dev(sp);
+	u32 reg_offset = id / 32;
+
+	if (!nvhost_module_powered(dev->dev)) {
+		dev_err(&syncpt_to_dev(sp)->dev->dev,
+			"Trying to access host1x when it's off");
+		return;
+	}

drivers/video/tegra/host/host1x/Makefile

Quoted 10 lines
drivers/video/tegra/host/host1x/Makefile new file +10 -0
+
+	if (!nvhost_syncpt_client_managed(sp, id)
+			&& nvhost_syncpt_min_eq_max(sp, id)) {
+		dev_err(&syncpt_to_dev(sp)->dev->dev,
+			"Trying to increment syncpoint id %d beyond max\n",
+			id);
+		return;
+	}
+	writel(BIT_MASK(id), dev->sync_aperture +
+			host1x_sync_syncpt_cpu_incr_r() + reg_offset * 4);

I have a stupid question: According to the name and the context of this function, seems it increases the syncpt value which specified by param "id". So how does this "writel" increase the value? I don't know much about host1x/syncpt reg operations, so could you explain a little bit or I just completely have a wrong understanding?

[...]

Quoted 15 lines
drivers/video/tegra/host/host1x/Makefile new file +15 -0
+
+static ssize_t powergate_delay_store(struct kobject *kobj,
+	struct kobj_attribute *attr, const char *buf, size_t count)
+{
+	int powergate_delay = 0, ret = 0;
+	struct nvhost_device_power_attr *power_attribute =
+		container_of(attr, struct nvhost_device_power_attr,
+			power_attr[NVHOST_POWER_SYSFS_ATTRIB_POWERGATE_DELAY]);
+	struct platform_device *dev = power_attribute->ndev;
+	struct nvhost_device_data *pdata = platform_get_drvdata(dev);
+
+	if (!pdata->can_powergate) {
+		dev_info(&dev->dev, "does not support power-gating\n");
+		return count;
+	}

drivers/video/tegra/host/host1x/Makefile

Quoted 10 lines
drivers/video/tegra/host/host1x/Makefile new file +10 -0
+
+	mutex_lock(&pdata->lock);
+	ret = sscanf(buf, "%d", &powergate_delay);
+	if (ret == 1 && powergate_delay >= 0)
+		pdata->powergate_delay = powergate_delay;
+	else
+		dev_err(&dev->dev, "Invalid powergate delay\n");
+	mutex_unlock(&pdata->lock);
+
+	return count;

Why we need to return an unchanged param? Seems param "count" doesn't make sense here.

[...]

Quoted 26 lines
drivers/video/tegra/host/host1x/Makefile new file +26 -0
+
+int nvhost_module_init(struct platform_device *dev)
+{
+	int i = 0, err = 0;
+	struct kobj_attribute *attr = NULL;
+	struct nvhost_device_data *pdata = platform_get_drvdata(dev);
+
+	/* initialize clocks to known state */
+	while (pdata->clocks[i].name && i < NVHOST_MODULE_MAX_CLOCKS) {
+		long rate = pdata->clocks[i].default_rate;
+		struct clk *c;
+
+		c = devm_clk_get(&dev->dev, pdata->clocks[i].name);
+		if (IS_ERR_OR_NULL(c)) {
+			dev_err(&dev->dev, "Cannot get clock %s\n",
+					pdata->clocks[i].name);
+			return -ENODEV;
+		}
+
+		rate = clk_round_rate(c, rate);
+		clk_prepare_enable(c);
+		clk_set_rate(c, rate);
+		clk_disable_unprepare(c);
+		pdata->clk[i] = c;
+		i++;
+	}

drivers/video/tegra/host/host1x/Makefile

Quoted 10 lines
drivers/video/tegra/host/host1x/Makefile new file +10 -0
+	pdata->num_clks = i;
+
+	mutex_init(&pdata->lock);
+	init_waitqueue_head(&pdata->idle_wq);
+	INIT_DELAYED_WORK(&pdata->powerstate_down, powerstate_down_handler);
+
+	/* power gate units that we can power gate */
+	if (pdata->can_powergate) {
+		do_powergate_locked(pdata->powergate_ids[0]);
+		do_powergate_locked(pdata->powergate_ids[1]);

Seems we don't set these 2 powergate_ids. Does this mean we have not enabled power management feature in this version?

[...]

Quoted 4 lines
drivers/video/tegra/host/host1x/Makefile new file +4 -0
+
+int nvhost_module_suspend(struct platform_device *dev)
+{
+	int ret;

drivers/video/tegra/host/host1x/Makefile

Quoted 10 lines
drivers/video/tegra/host/host1x/Makefile new file +10 -0
+	struct nvhost_device_data *pdata = platform_get_drvdata(dev);
+
+	ret = wait_event_timeout(pdata->idle_wq, is_module_idle(dev),
+			ACM_SUSPEND_WAIT_FOR_IDLE_TIMEOUT);
+	if (ret == 0) {
+		dev_info(&dev->dev, "%s prevented suspend\n",
+				dev_name(&dev->dev));
+		return -EBUSY;
+	}
+

I'm not sure whether there is a race condition here. We wait until this module is idle(refcount == 0), then try to powergate it next. But the wait queue function "powerstate_down_handler" might already powergate it. So we need to either "cancel_delayed_work(&pdate->powerstate_down)" before waiting the module to idle state or add some protection codes in "to_state_powergated_locked".

Quoted 11 lines
drivers/video/tegra/host/host1x/Makefile new file +11 -0
+	mutex_lock(&pdata->lock);
+	cancel_delayed_work(&pdata->powerstate_down);
+	to_state_powergated_locked(dev);
+	mutex_unlock(&pdata->lock);
+
+	if (pdata->suspend_ndev)
+		pdata->suspend_ndev(dev);
+
+	return 0;
+}
+

[...]

Quoted 39 lines
drivers/video/tegra/host/host1x/Makefile new file +39 -0
+
+int nvhost_syncpt_init(struct platform_device *dev,
+		struct nvhost_syncpt *sp)
+{
+	int i;
+	struct nvhost_master *host = syncpt_to_dev(sp);
+	int err = 0;
+
+	/* Allocate structs for min, max and base values */
+	sp->min_val = kzalloc(sizeof(atomic_t) * nvhost_syncpt_nb_pts(sp),
+			GFP_KERNEL);
+	sp->max_val = kzalloc(sizeof(atomic_t) * nvhost_syncpt_nb_pts(sp),
+			GFP_KERNEL);
+	sp->base_val = kzalloc(sizeof(u32) * nvhost_syncpt_nb_bases(sp),
+			GFP_KERNEL);
+	sp->lock_counts =
+		kzalloc(sizeof(atomic_t) * nvhost_syncpt_nb_mlocks(sp),
+			GFP_KERNEL);
+
+	if (!(sp->min_val && sp->max_val && sp->base_val && sp->lock_counts)) {
+		/* frees happen in the deinit */
+		err = -ENOMEM;
+		goto fail;
+	}
+
+	sp->kobj = kobject_create_and_add("syncpt", &dev->dev.kobj);
+	if (!sp->kobj) {
+		err = -EIO;
+		goto fail;
+	}
+
+	/* Allocate two attributes for each sync point: min and max */
+	sp->syncpt_attrs = kzalloc(sizeof(*sp->syncpt_attrs)
+			* nvhost_syncpt_nb_pts(sp) * 2, GFP_KERNEL);
+	if (!sp->syncpt_attrs) {
+		err = -ENOMEM;
+		goto fail;
+	}
+

drivers/video/tegra/host/host1x/Makefile

Quoted 10 lines
drivers/video/tegra/host/host1x/Makefile new file +10 -0
+	/* Fill in the attributes */
+	for (i = 0; i < nvhost_syncpt_nb_pts(sp); i++) {
+		char name[MAX_SYNCPT_LENGTH];
+		struct kobject *kobj;
+		struct nvhost_syncpt_attr *min = &sp->syncpt_attrs[i*2];
+		struct nvhost_syncpt_attr *max = &sp->syncpt_attrs[i*2+1];
+
+		/* Create one directory per sync point */
+		snprintf(name, sizeof(name), "%d", i);
+		kobj = kobject_create_and_add(name, sp->kobj);

Where do we "kobject_put" this kobj?

[...]

Quoted 33 lines
drivers/video/tegra/host/host1x/Makefile new file +33 -0
+		if (!kobj) {
+			err = -EIO;
+			goto fail;
+		}
+
+		min->id = i;
+		min->host = host;
+		min->attr.attr.name = min_name;
+		min->attr.attr.mode = S_IRUGO;
+		min->attr.show = syncpt_min_show;
+		if (sysfs_create_file(kobj, &min->attr.attr)) {
+			err = -EIO;
+			goto fail;
+		}
+
+		max->id = i;
+		max->host = host;
+		max->attr.attr.name = max_name;
+		max->attr.attr.mode = S_IRUGO;
+		max->attr.show = syncpt_max_show;
+		if (sysfs_create_file(kobj, &max->attr.attr)) {
+			err = -EIO;
+			goto fail;
+		}
+	}
+
+	return err;
+
+fail:
+	nvhost_syncpt_deinit(sp);
+	return err;
+}
+

[...]

drivers/video/tegra/host/host1x/Makefile

Quoted 7 lines
drivers/video/tegra/host/host1x/Makefile new file +6 -0
+/* public host1x sync-point management APIs */
+u32 host1x_syncpt_incr_max(u32 id, u32 incrs);
+void host1x_syncpt_incr(u32 id);
+u32 host1x_syncpt_read(u32 id);
+
+#endif

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#47 lore raw

Re: [RFC,v2,3/8] video: tegra: host: Add channel and client support

In reply to Terje Bergstrom
Quoted 3 lines · Terje Bergström

Add support for host1x client modules, and host1x channels to submit work to the clients. The work is submitted in dmabuf buffers, so add support for dmabuf memory management, too.

[...]

Quoted 1 line
drivers/video/tegra/host/bus_client.c +0 -0

[...]

Quoted 22 lines
drivers/video/tegra/host/bus_client.c +22 -0
+int nvhost_client_device_init(struct platform_device *dev)
+{
+	int err;
+	struct nvhost_master *nvhost_master = nvhost_get_host(dev);
+	struct nvhost_channel *ch;
+	struct nvhost_device_data *pdata = platform_get_drvdata(dev);
+
+	ch = nvhost_alloc_channel(dev);
+	if (ch == NULL)
+		return -ENODEV;
+
+	/* store the pointer to this device for channel */
+	ch->dev = dev;
+
+	err = nvhost_channel_init(ch, nvhost_master, pdata->index);
+	if (err)
+		goto fail;
+
+	err = nvhost_module_init(dev);
+	if (err)
+		goto fail;
+

drivers/video/tegra/host/bus_client.c line 76

Quoted 10 lines
drivers/video/tegra/host/bus_client.c +10 -0
+	err = nvhost_device_list_add(dev);
+	if (err)
+		goto fail;
+
+	dev_info(&dev->dev, "initialized\n");
+
+	return 0;
+
+fail:
+	/* Add clean-up */

Yes, add "nvhost_module_deinit" here?

Quoted 6 lines
drivers/video/tegra/host/bus_client.c +6 -0
+	nvhost_free_channel(ch);
+	return err;
+}
+EXPORT_SYMBOL(nvhost_client_device_init);
+
+int nvhost_client_device_suspend(struct platform_device *dev)

drivers/video/tegra/host/bus_client.c line 92

Quoted 10 lines
drivers/video/tegra/host/bus_client.c +10 -0
+{
+	int ret = 0;
+	struct nvhost_device_data *pdata = platform_get_drvdata(dev);
+
+	ret = nvhost_channel_suspend(pdata->channel);
+	dev_info(&dev->dev, "suspend status: %d\n", ret);
+	if (ret)
+		return ret;
+
+	return ret;

Minor issue: just "return ret" is OK. That "if" doesn't make sense.

drivers/video/tegra/host/chip_support.c line 29

Quoted 13 lines
drivers/video/tegra/host/bus_client.c +2 -0
+}
+EXPORT_SYMBOL(nvhost_client_device_suspend);
drivers/video/tegra/host/chip_support.c +1 -1
index 5a44147..8765c83 100644
@@ -25,7 +25,7 @@
 #include "chip_support.h"
 #include "host1x/host1x01.h"
 
-struct nvhost_chip_support *nvhost_chip_ops;
+static struct nvhost_chip_support *nvhost_chip_ops;
 

All right, already fixed here. Sorry, so just ignore what I said about this in my reply to your patch 1.

[...]

drivers/video/tegra/host/chip_support.c

Quoted 13 lines
drivers/video/tegra/host/chip_support.c +13 -0
+
+struct mem_handle *nvhost_dmabuf_get(u32 id, struct platform_device *dev)
+{
+	struct mem_handle *h;
+	struct dma_buf *buf;
+
+	buf = dma_buf_get(to_dmabuf_fd(id));
+	if (IS_ERR_OR_NULL(buf))
+		return (struct mem_handle *)buf;
+
+	h = (struct mem_handle *)dma_buf_attach(buf, &dev->dev);
+	if (IS_ERR_OR_NULL(h))
+		dma_buf_put(buf);

Return an error here.

Quoted 4 lines
drivers/video/tegra/host/chip_support.c +4 -0
+
+	return (struct mem_handle *) ((u32)h | mem_mgr_type_dmabuf);
+}
+

[...]

drivers/video/tegra/host/chip_support.c

Quoted 13 lines

int nvhost_init_host1x01_support(struct nvhost_master *host,

drivers/video/tegra/host/chip_support.c +6 -0
 	struct nvhost_chip_support *op)
 {
+	op->channel = host1x_channel_ops;
+	op->cdma = host1x_cdma_ops;
+	op->push_buffer = host1x_pushbuffer_ops;
 	host->sync_aperture = host->aperture + HOST1X_CHANNEL_SYNC_REG_BASE;
 	op->syncpt = host1x_syncpt_ops;
 	op->intr = host1x_intr_ops;
 
+	op->nvhost_dev.alloc_nvhost_channel = t20_alloc_nvhost_channel;
+	op->nvhost_dev.free_nvhost_channel = t20_free_nvhost_channel;
+

I recall in previous version, there is t30-related alloc_nvhost_channel & free_nvhost_channel. Why remove them?

Quoted 2 lines

return 0;
}

[...]

Quoted 6 lines
drivers/video/tegra/host/chip_support.c +6 -0
+static int push_buffer_init(struct push_buffer *pb)
+{
+	struct nvhost_cdma *cdma = pb_to_cdma(pb);
+	struct nvhost_master *master = cdma_to_dev(cdma);
+	pb->mapped = NULL;
+	pb->phys = 0;

drivers/video/tegra/host/chip_support.c

Quoted 10 lines
drivers/video/tegra/host/chip_support.c +10 -0
+	pb->handle = NULL;
+
+	cdma_pb_op().reset(pb);
+
+	/* allocate and map pushbuffer memory */
+	pb->mapped = dma_alloc_writecombine(&master->dev->dev,
+			PUSH_BUFFER_SIZE + 4, &pb->phys, GFP_KERNEL);
+	if (IS_ERR_OR_NULL(pb->mapped)) {
+		pb->mapped = NULL;
+		goto fail;

Return directly here. "goto fail" makes "push_buffer_destroy" get called.

drivers/video/tegra/host/chip_support.c

Quoted 10 lines
drivers/video/tegra/host/chip_support.c +10 -0
+	}
+
+	/* memory for storing mem client and handles for each opcode pair */
+	pb->handle = kzalloc(NVHOST_GATHER_QUEUE_SIZE *
+				sizeof(struct mem_handle *),
+			GFP_KERNEL);
+	if (!pb->handle)
+		goto fail;
+
+	/* put the restart at the end of pushbuffer memory */

Just for curious, why "pb->mapped + 1K" is the end of a 4K pushbuffer?

Quoted 10 lines
drivers/video/tegra/host/chip_support.c +10 -0
+	*(pb->mapped + (PUSH_BUFFER_SIZE >> 2)) =
+		nvhost_opcode_restart(pb->phys);
+
+	return 0;
+
+fail:
+	push_buffer_destroy(pb);
+	return -ENOMEM;
+}
+

[...]

Quoted 19 lines
drivers/video/tegra/host/chip_support.c +19 -0
+
+/**
+ * Sleep (if necessary) until the requested event happens
+ *   - CDMA_EVENT_SYNC_QUEUE_EMPTY : sync queue is completely empty.
+ *     - Returns 1
+ *   - CDMA_EVENT_PUSH_BUFFER_SPACE : there is space in the push buffer
+ *     - Return the amount of space (> 0)
+ * Must be called with the cdma lock held.
+ */
+unsigned int nvhost_cdma_wait_locked(struct nvhost_cdma *cdma,
+		enum cdma_event event)
+{
+	for (;;) {
+		unsigned int space = cdma_status_locked(cdma, event);
+		if (space)
+			return space;
+
+		/* If somebody has managed to already start waiting, yield */
+		if (cdma->event != CDMA_EVENT_NONE) {

drivers/video/tegra/host/chip_support.c

Quoted 10 lines
drivers/video/tegra/host/chip_support.c +10 -0
+			mutex_unlock(&cdma->lock);
+			schedule();
+			mutex_lock(&cdma->lock);
+			continue;
+		}
+		cdma->event = event;
+
+		mutex_unlock(&cdma->lock);
+		down(&cdma->sem);
+		mutex_lock(&cdma->lock);

I'm newbie of nvhost but I feel here is very tricky, about the lock and unlock of this mutex: cdma->lock. Does it require this mutex is locked before calling this function? And do we need to unlock it before the
code: "return space;" above? IMHO, this is not a good design and can we find out a better solution?

Quoted 3 lines
drivers/video/tegra/host/chip_support.c +3 -0
+	}
+	return 0;
+}

[...]

Quoted 7 lines
drivers/video/tegra/host/chip_support.c +5 -0
+/*
+ * Dump contents of job to debug output.
+ */
+void nvhost_job_dump(struct device *dev, struct nvhost_job *job);
+
 #endif
#50 lore raw

Re: [RFC v2 3/8] video: tegra: host: Add channel and client support

In reply to Terje Bergstrom

On Mon, Nov 26, 2012 at 03:19:09PM +0200, Terje Bergstrom wrote:

I've skipped a lot of code here that I need more time to review.

[...]

Quoted 1 line
drivers/video/tegra/host/nvhost_intr.c +0 -0

[...]

Quoted 19 lines
drivers/video/tegra/host/nvhost_intr.c +9 -0
+static void action_submit_complete(struct nvhost_waitlist *waiter)
+{
+	struct nvhost_channel *channel = waiter->data;
+	int nr_completed = waiter->count;
+
+	nvhost_cdma_update(&channel->cdma);
+	nvhost_module_idle_mult(channel->dev, nr_completed);
+}
 
 static void action_wakeup(struct nvhost_waitlist *waiter)
 {
@@ -125,6 +145,7 @@ static void action_wakeup_interruptible(struct nvhost_waitlist *waiter)
 typedef void (*action_handler)(struct nvhost_waitlist *waiter);
 
 static action_handler action_handlers[NVHOST_INTR_ACTION_COUNT] = {
+	action_submit_complete,
 	action_wakeup,
 	action_wakeup_interruptible,
 };

[...]

Quoted 1 line
drivers/video/tegra/host/nvhost_intr.h +0 -0

[...]

drivers/video/tegra/host/nvhost_intr.h line 41

Quoted 11 lines

enum nvhost_intr_action {

drivers/video/tegra/host/nvhost_intr.h +6 -0
 	/**
+	 * Perform cleanup after a submit has completed.
+	 * 'data' points to a channel
+	 */
+	NVHOST_INTR_ACTION_SUBMIT_COMPLETE = 0,
+
+	/**
 	 * Wake up a  task.
 	 * 'data' points to a wait_queue_head_t
 	 */

Looking some more at how this is used, I'm starting to think that it might be easier to export the various handlers and allow them to be passed to the nvhost_intr_add_action() explicitly.

Quoted 1 line
drivers/video/tegra/host/nvhost_job.c +0 -0

[...]

drivers/video/tegra/host/nvhost_job.c line 35

Quoted 2 lines
drivers/video/tegra/host/nvhost_job.c +2 -0
+/* Magic to use to fill freed handle slots */
+#define BAD_MAGIC 0xdeadbeef

This isn't currently used.

Quoted 37 lines
drivers/video/tegra/host/nvhost_job.c +37 -0
+static size_t job_size(u32 num_cmdbufs, u32 num_relocs, u32 num_waitchks)
+{
+	u32 num_unpins = num_cmdbufs + num_relocs;
+	s64 total;
+
+	if (num_relocs < 0 || num_waitchks < 0 || num_cmdbufs < 0)
+		return 0;
+
+	total = sizeof(struct nvhost_job)
+			+ num_relocs * sizeof(struct nvhost_reloc)
+			+ num_unpins * sizeof(struct nvhost_job_unpin_data)
+			+ num_waitchks * sizeof(struct nvhost_waitchk)
+			+ num_cmdbufs * sizeof(struct nvhost_job_gather);
+
+	if (total > ULONG_MAX)
+		return 0;
+	return (size_t)total;
+}
+
+
+static void init_fields(struct nvhost_job *job,
+		u32 num_cmdbufs, u32 num_relocs, u32 num_waitchks)
+{
+	u32 num_unpins = num_cmdbufs + num_relocs;
+	void *mem = job;
+
+	/* First init state to zero */
+
+	/*
+	 * Redistribute memory to the structs.
+	 * Overflows and negative conditions have
+	 * already been checked in job_alloc().
+	 */
+	mem += sizeof(struct nvhost_job);
+	job->relocarray = num_relocs ? mem : NULL;
+	mem += num_relocs * sizeof(struct nvhost_reloc);
+	job->unpins = num_unpins ? mem : NULL;

drivers/video/tegra/host/nvhost_job.c line 83

Quoted 10 lines
drivers/video/tegra/host/nvhost_job.c +10 -0
+	mem += num_unpins * sizeof(struct nvhost_job_unpin_data);
+	job->waitchk = num_waitchks ? mem : NULL;
+	mem += num_waitchks * sizeof(struct nvhost_waitchk);
+	job->gathers = num_cmdbufs ? mem : NULL;
+	mem += num_cmdbufs * sizeof(struct nvhost_job_gather);
+	job->addr_phys = (num_cmdbufs || num_relocs) ? mem : NULL;
+
+	job->reloc_addr_phys = job->addr_phys;
+	job->gather_addr_phys = &job->addr_phys[num_relocs];
+}

I wouldn't bother splitting out the above two functions.

drivers/video/tegra/host/nvhost_job.c line 93

Quoted 10 lines
drivers/video/tegra/host/nvhost_job.c +10 -0
+
+struct nvhost_job *nvhost_job_alloc(struct nvhost_channel *ch,
+		int num_cmdbufs, int num_relocs, int num_waitchks)
+{
+	struct nvhost_job *job = NULL;
+	size_t size = job_size(num_cmdbufs, num_relocs, num_waitchks);
+
+	if (!size)
+		return NULL;
+	job = vzalloc(size);

Why vzalloc()?

drivers/video/tegra/host/nvhost_job.c line 134

Quoted 10 lines
drivers/video/tegra/host/nvhost_job.c +10 -0
+void nvhost_job_add_gather(struct nvhost_job *job,
+		u32 mem_id, u32 words, u32 offset)
+{
+	struct nvhost_job_gather *cur_gather =
+			&job->gathers[job->num_gathers];
+
+	cur_gather->words = words;
+	cur_gather->mem_id = mem_id;
+	cur_gather->offset = offset;
+	job->num_gathers += 1;

job->num_gathers++

drivers/video/tegra/host/nvhost_job.c line 208

Quoted 9 lines
drivers/video/tegra/host/nvhost_job.c +9 -0
+static int pin_job_mem(struct nvhost_job *job)
+{
+	int i;
+	int count = 0;
+	int result;
+	long unsigned *ids =
+			kmalloc(sizeof(u32 *) *
+				(job->num_relocs + job->num_gathers),
+				GFP_KERNEL);

Maybe this should be allocated along with the nvhost_job and the other fields to avoid having to allocate, and potentially fail, here?

Quoted 26 lines
drivers/video/tegra/host/nvhost_job.c +26 -0
+static int do_relocs(struct nvhost_job *job,
+		u32 cmdbuf_mem, struct mem_handle *h)
+{
+	int i = 0;
+	int last_page = -1;
+	void *cmdbuf_page_addr = NULL;
+
+	/* pin & patch the relocs for one gather */
+	while (i < job->num_relocs) {
+		struct nvhost_reloc *reloc = &job->relocarray[i];
+
+		/* skip all other gathers */
+		if (cmdbuf_mem != reloc->cmdbuf_mem) {
+			i++;
+			continue;
+		}
+
+		if (last_page != reloc->cmdbuf_offset >> PAGE_SHIFT) {
+			if (cmdbuf_page_addr)
+				nvhost_memmgr_kunmap(h, last_page, cmdbuf_page_addr);
+
+			cmdbuf_page_addr = nvhost_memmgr_kmap(h,
+					reloc->cmdbuf_offset >> PAGE_SHIFT);
+			last_page = reloc->cmdbuf_offset >> PAGE_SHIFT;
+
+			if (unlikely(!cmdbuf_page_addr)) {

drivers/video/tegra/host/nvhost_job.c line 272

Quoted 10 lines
drivers/video/tegra/host/nvhost_job.c +10 -0
+				pr_err("Couldn't map cmdbuf for relocation\n");
+				return -ENOMEM;
+			}
+		}
+
+		__raw_writel(
+			(job->reloc_addr_phys[i] +
+				reloc->target_offset) >> reloc->shift,
+			(cmdbuf_page_addr +
+				(reloc->cmdbuf_offset & ~PAGE_MASK)));

You're not writing to I/O memory, so you shouldn't be using __raw_writel() here.

drivers/video/tegra/host/nvhost_job.c line 302

Quoted 5 lines
drivers/video/tegra/host/nvhost_job.c +5 -0
+int nvhost_job_pin(struct nvhost_job *job, struct platform_device *pdev)
+{
+	int err = 0, i = 0, j = 0;
+	struct nvhost_syncpt *sp = &nvhost_get_host(pdev)->syncpt;
+	unsigned long waitchk_mask[nvhost_syncpt_nb_pts(sp) / BITS_PER_LONG];

You should use a bitmap instead. See DECLARE_BITMAP in linux/types.h...

drivers/video/tegra/host/nvhost_job.c line 304

Quoted 2 lines
drivers/video/tegra/host/nvhost_job.c +2 -0
+
+	memset(&waitchk_mask[0], 0, sizeof(waitchk_mask));

and run bitmap_zero() here...

drivers/video/tegra/host/nvhost_job.c line 309

Quoted 5 lines
drivers/video/tegra/host/nvhost_job.c +5 -0
+	for (i = 0; i < job->num_waitchk; i++) {
+		u32 syncpt_id = job->waitchk[i].syncpt_id;
+		if (syncpt_id < nvhost_syncpt_nb_pts(sp))
+			waitchk_mask[BIT_WORD(syncpt_id)] |=
+				BIT_MASK(syncpt_id);

and use _set_bit here.

drivers/video/tegra/host/nvhost_job.c line 314

Quoted 5 lines
drivers/video/tegra/host/nvhost_job.c +5 -0
+	}
+
+	/* get current syncpt values for waitchk */
+	for_each_set_bit(i, &waitchk_mask[0], sizeof(waitchk_mask))
+		nvhost_syncpt_update_min(sp, i);

Or since you only use the mask here, why not move the nvhost_syncpt_update_min() into the above loop?

Quoted 24 lines
drivers/video/tegra/host/nvhost_job.c +24 -0
+	/* patch gathers */
+	for (i = 0; i < job->num_gathers; i++) {
+		struct nvhost_job_gather *g = &job->gathers[i];
+
+		/* process each gather mem only once */
+		if (!g->ref) {
+			g->ref = nvhost_memmgr_get(g->mem_id, job->ch->dev);
+			if (IS_ERR(g->ref)) {
+				err = PTR_ERR(g->ref);
+				g->ref = NULL;
+				break;
+			}
+
+			g->mem_base = job->gather_addr_phys[i];
+
+			for (j = 0; j < job->num_gathers; j++) {
+				struct nvhost_job_gather *tmp =
+					&job->gathers[j];
+				if (!tmp->ref && tmp->mem_id == g->mem_id) {
+					tmp->ref = g->ref;
+					tmp->mem_base = g->mem_base;
+				}
+			}
+			err = do_relocs(job, g->mem_id,  g->ref);

drivers/video/tegra/host/nvhost_job.c line 354

Quoted 10 lines
drivers/video/tegra/host/nvhost_job.c +10 -0
+			if (!err)
+				err = do_waitchks(job, sp,
+						g->mem_id, g->ref);
+			nvhost_memmgr_put(g->ref);
+			if (err)
+				break;
+		}
+	}
+fail:
+	wmb();

What do you need this write barrier for?

Quoted 45 lines
drivers/video/tegra/host/nvhost_memmgr.c new file +39 -0
new file mode 100644
index 0000000..bdceb74
@@ -0,0 +1,160 @@
+/*
+ * drivers/video/tegra/host/nvhost_memmgr.c
+ *
+ * Tegra host1x Memory Management Abstraction
+ *
+ * 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/kernel.h>
+#include <linux/err.h>
+
+#include "nvhost_memmgr.h"
+#include "dmabuf.h"
+#include "chip_support.h"
+
+struct mem_handle *nvhost_memmgr_alloc(size_t size, size_t align, int flags)
+{
+	struct mem_handle *h = NULL;
+	h = nvhost_dmabuf_alloc(size, align, flags);
+
+	return h;
+}
+
+struct mem_handle *nvhost_memmgr_get(u32 id, struct platform_device *dev)
+{
+	struct mem_handle *h = NULL;
+

drivers/video/tegra/host/nvhost_memmgr.c line 49

Quoted 10 lines
drivers/video/tegra/host/nvhost_memmgr.c new file +10 -0
+	switch (nvhost_memmgr_type(id)) {
+	case mem_mgr_type_dmabuf:
+		h = (struct mem_handle *) nvhost_dmabuf_get(id, dev);
+		break;
+	default:
+		break;
+	}
+
+	return h;
+}

Heh, this would actually be a case where I'd argue in favour of an ops structure. But Lucas already mentioned that we may want to revise how the memory manager works and ideally we'd only have a single type of buffers anyway so this would largely become obsolete anyway.

Quoted 1 line
include/linux/nvhost.h +0 -0

[...]

include/linux/nvhost.h struct nvhost_device_power_attr; · line 54

Quoted 13 lines
include/linux/nvhost.h +12 -0
+#define NVSYNCPT_2D_0		(18)
+#define NVSYNCPT_2D_1		(19)
+#define NVSYNCPT_VBLANK0	(26)
+#define NVSYNCPT_VBLANK1	(27)
 
+/* sync points that are wholly managed by the client */
+#define NVSYNCPTS_CLIENT_MANAGED (\
+	BIT(NVSYNCPT_VBLANK0) | \
+	BIT(NVSYNCPT_VBLANK1) | \
+	BIT(NVSYNCPT_2D_1))
+
+#define NVWAITBASE_2D_0 (1)
+#define NVWAITBASE_2D_1 (2)

I think we already agreed that we want to do dynamic allocation of syncpoints so these definitions can go away.

include/linux/nvhost.h void host1x_syncpt_incr(u32 id); · line 161

Quoted 9 lines

enum nvhost_power_sysfs_attributes {

include/linux/nvhost.h +2 -0
 	NVHOST_POWER_SYSFS_ATTRIB_CLOCKGATE_DELAY = 0,
 	NVHOST_POWER_SYSFS_ATTRIB_POWERGATE_DELAY,
@@ -142,4 +157,138 @@ void host1x_syncpt_incr(u32 id);
 u32 host1x_syncpt_read(u32 id);
 int host1x_syncpt_wait(u32 id, u32 thresh, u32 timeout, u32 *value);
 
+/* Register device */
+int nvhost_client_device_init(struct platform_device *dev);

Again, I think this should be made easier on the clients. Ideally there'd be a single call to register a client with host1x which would already initialize the appropriate fields. There can be other, separate functions for resource allocations such as syncpoints and channels, though.

include/linux/nvhost.h void host1x_syncpt_incr(u32 id); · line 162

Quoted 1 line
include/linux/nvhost.h +1 -0
+int nvhost_client_device_suspend(struct platform_device *dev);

Again, I think this should be handled via runtime PM.

include/linux/nvhost.h void host1x_syncpt_incr(u32 id); · line 164

Quoted 2 lines
include/linux/nvhost.h +2 -0
+struct nvhost_channel *nvhost_getchannel(struct nvhost_channel *ch);
+void nvhost_putchannel(struct nvhost_channel *ch);

These are oddly named. Better names would be nvhost_channel_get() or nvhost_channel_put().

include/linux/nvhost.h void host1x_syncpt_incr(u32 id); · line 170

Quoted 6 lines
include/linux/nvhost.h +6 -0
+int nvhost_channel_submit(struct nvhost_job *job);
+
+enum host1x_class {
+	NV_HOST1X_CLASS_ID		= 0x1,
+	NV_GRAPHICS_2D_CLASS_ID		= 0x51,
+};

Maybe this enumeration should be made more consistent, somewhat along the lines of:

	enum host1x_class {
		HOST1X_CLASS_HOST1X = 0x01,
		HOST1X_CLASS_2D = 0x51,
	};

Again, I'll need more time to go over the rest of the code but the good news is that I'm starting to form a better picture of how things work.

Thierry

#4 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Thierry Reding
Quoted 6 lines · Thierry Reding

This could be problematic. Since drivers/video and drivers/gpu/drm are separate trees, this would entail a continuous burden on keeping both trees synchronized. While I realize that eventually it might be better to put the host1x driver in a separate place to accomodate for its use by other subsystems, I'm not sure moving it here right away is the best approach.

I understand your point, but I hope also that we'd end up with something that can be used as basis for the downstream kernel to migrate to upstream stack.

The key point here is to make the API between nvhost and tegradrm as small and robust to changes as possible.

Quoted 3 lines

I'm not sure drivers/video is the best location either. Perhaps drivers/bus would be better? Or maybe we need a new subdirectory for this kind of device.

This is a question I don't have an answer to. I'm perfectly ok moving it wherever the public opinion leads it to.

Quoted 1 line

I think the general nowadays is to no longer use filenames in comments.

Ok, I hadn't noticed that. I'll remove them. It's redundant information anyway.

Quoted 9 lines

drivers/video/tegra/host/chip_support.c line 33

Quoted 6 lines
drivers/video/tegra/host/chip_support.c new file +6 -0
+struct nvhost_chip_support *nvhost_chip_ops;
+
+struct nvhost_chip_support *nvhost_get_chip_ops(void)
+{
+     return nvhost_chip_ops;
+}

This seems like it should be more tightly coupled to the host1x device. And it shouldn't be a global variable.

Yeah, I will figure out a better way to handle the chip ops. I'm not too happy with it. Give me a bit of time to come up with a good solution.

Quoted 3 lines
Quoted 1 line

+struct output;

What's this? It doesn't seem to be used anywhere.

It's just a mistake. The struct is used in debug code, but not referred to in this file so the forward declaration is not needed.

Quoted 5 lines
Quoted 1 line

+struct nvhost_master;

Why do you suffix this with _master? The whole point of host1x is to be the "master" so you can just as well call it nvhost, right? Ideally you'd call it host1x, but I'm repeating myself. =)

Yes, the name is just a historic relict and I'm blind to them as I've been staring at the code for so long. I think "host1x" would be a good name for the struct.

Quoted 5 lines
Quoted 5 lines
drivers/video/tegra/host/chip_support.h new file +5 -0
+struct nvhost_syncpt_ops {
+     void (*reset)(struct nvhost_syncpt *, u32 id);
+     void (*reset_wait_base)(struct nvhost_syncpt *, u32 id);
+     void (*read_wait_base)(struct nvhost_syncpt *, u32 id);
+     u32 (*update_min)(struct nvhost_syncpt *, u32 id);
Quoted 8 lines

drivers/video/tegra/host/chip_support.h line 39

Quoted 4 lines
drivers/video/tegra/host/chip_support.h new file +4 -0
+     void (*cpu_incr)(struct nvhost_syncpt *, u32 id);
+     void (*debug)(struct nvhost_syncpt *);
+     const char * (*name)(struct nvhost_syncpt *, u32 id);
+};

Why are these even defined as ops structure? Tegra20 and Tegra30 seem to be compatible when it comes to handling syncpoints. I thought they would even be compatible in all other aspects as well, so why even have this?

Tegra20 and Tegra30 are compatible, but future chips are not. I was hoping we would be ready in upstream kernel for future chips.

Quoted 6 lines
Quoted 1 line

+#define syncpt_op() (nvhost_get_chip_ops()->syncpt)

You really shouldn't be doing this, but rather use explicit accesses for these structures. If you're design doesn't scatter these definitions across several files then it isn't difficult to obtain the correct pointers and you don't need these "shortcuts".

Do you mean that I would move the ops to be part of f.ex. nvhost_syncpt or nvhost_intr structs?

Quoted 6 lines

This API looks odd. Should syncpoints not be considered as regular resources, much like interrupts? In that case it would be easier to abstract them away behind an opaque type. It looks like you already use the struct nvhost_syncpt to refer to the set of syncpoints associated with a host1x device.

Quoted 8 lines

How about you use nvhost/host1x_syncpt to refer to individual syncpoints instead. You could export an array of those from your host1x device and implement a basic resource allocation mechanism on top, similar to how other resources are handled in the kernel.

So a host1x client device could call host1x_request_syncpt() to allocate a syncpoint from it's host1x parent dynamically along with passing a name and a syncpoint handler to it.

That might work. I'll think about that - thanks.

Quoted 15 lines
Quoted 2 lines
(quoted diff) +2 -0
+bool host1x_powered(struct platform_device *dev)
+{

[...]

Quoted 5 lines
drivers/video/tegra/host/dev.c new file +5 -0
+}
+EXPORT_SYMBOL(host1x_powered);
+
+void host1x_busy(struct platform_device *dev)
+{

[...]

Quoted 5 lines
drivers/video/tegra/host/dev.c new file +5 -0
+}
+EXPORT_SYMBOL(host1x_busy);
+
+void host1x_idle(struct platform_device *dev)
+{

[...]

Quoted 5 lines

Review

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

These look like a reimplementation of the runtime power-management framework.

Yes, we at some point tried to move to use runtime PM. The first attempt was thwarted by runtime PM and system suspend conflicting with each other. I believe this is pretty much fixed in later versions of kernel.

Also, the problem was that runtime PM doesn't support multiple power states. In downstream kernel, we support clock gating and power gating. When we moved to runtime PM and implemented power gating on top of that, we ended up with more code than just using the current ACM code.

I have a developer starting to look into how we could take runtime PM again into use with proper power gating support. It'll take a while to get that right. It might be best to rip the dynamic power management out from this patch set, and introduce it later when we have a proper runtime PM solution.

I'll skip the other comments about ACM because of this.

Quoted 7 lines
Quoted 1 line
drivers/video/tegra/host/host1x/host1x.c +0 -0

[...]

Quoted 1 line

+struct nvhost_master *nvhost;

Bad habbit. I know that this is a popular shortcut. However this also leads to very bad designs because you're allowed to reuse this pointer from wherever you like.

Quoted 8 lines

When I wrote the tegra-drm code I explicitly made sure to not use any such global variable. In the end it forces you to clean up the driver design.

As a bonus you automatically get support for any number of host1x devices on the same SoC. Now you will probably tell me that this is never going to happen. People also used to think that a computers would never use more than a single CPU...

I think this might get cleaned up at the same time with cleaning up the auxdata/chip_ops design. We used to have this struct set as driver private data, but as we started using that for another purpose, we moved this variable out.

Quoted 6 lines

drivers/video/tegra/host/host1x/host1x.c line 57

Quoted 4 lines
drivers/video/tegra/host/host1x/host1x.c +4 -0
+
+static void nvhost_free_resources(struct nvhost_master *host)
+{
+}

This should be removed since it's empty.

True. I wonder how that happened - there was content since recently, but I guess I deleted the code without noticing that the function needs to go, too.

Quoted 8 lines

drivers/video/tegra/host/host1x/host1x.c line 82

Quoted 5 lines
drivers/video/tegra/host/host1x/host1x.c +5 -0
+     regs = platform_get_resource(dev, IORESOURCE_MEM, 0);
+     intr0 = platform_get_resource(dev, IORESOURCE_IRQ, 0);
+     intr1 = platform_get_resource(dev, IORESOURCE_IRQ, 1);
+
+     if (!regs || !intr0 || !intr1) {

I prefer to have these checked for explicitly, one by one for readability and potentially more useful diagnostics.

Can do.

Quoted 7 lines

Also you should be using platform_get_irq() for interrupts. Furthermore the host1x DT node (and the TRM) name the interrupts "syncpt" and "general", so maybe those would be more useful variable names than "intr0" and "intr1".

But since you don't use them anyway they shouldn't be part of this patch.

True. I might also as well delete the general interrupt altogether, as we don't use it for any real purpose.

Quoted 8 lines

drivers/video/tegra/host/host1x/host1x.c line 96

Quoted 2 lines
drivers/video/tegra/host/host1x/host1x.c +2 -0
+     /* Copy host1x parameters. The private_data gets replaced
+      * by nvhost_master later */

Multiline comments should be in this format:

        /*
         * foo
         */

Ok.

Quoted 6 lines

drivers/video/tegra/host/host1x/host1x.c line 112

Quoted 2 lines
drivers/video/tegra/host/host1x/host1x.c +2 -0
+     host->aperture = devm_request_and_ioremap(&dev->dev, regs);
+     if (!host->aperture) {

aperture is confusing as it is typically used for GTT-type memory regions, so it may be mistaken for the GART found on Tegra 2. Why not call it "regs" instead?

Can do.

Quoted 5 lines
Quoted 2 lines

+ dev_err(&dev->dev, "failed to remap host registers\n");

This is unnecessary. devm_request_and_ioremap() already prints an error message on failure.

I'll remove that, thanks.

Quoted 9 lines

drivers/video/tegra/host/host1x/host1x.c line 136

Quoted 6 lines
drivers/video/tegra/host/host1x/host1x.c +5 -0
+     for (i = 0; i < pdata->num_clks; i++)
+             clk_prepare_enable(pdata->clk[i]);
+     nvhost_syncpt_reset(&host->syncpt);
+     for (i = 0; i < pdata->num_clks; i++)
+             clk_disable_unprepare(pdata->clk[i]);

Stephen already hinted at this when discussing the AUXDATA. You should explicitly request the clocks.

I'm not too happy about that idea. The clock management code is generic for all modules, and that's why it's driven by a data structure. Now Stephen and you ask me to unroll the loops and make copies of the code to facilitate different modules and different SoCs.

Quoted 8 lines
Quoted 1 line

+static int __exit nvhost_remove(struct platform_device *dev)

This should really be __devexit to allow the driver to be built as a module. However, __dev* are deprecated and in the process of being removed so you can just drop __exit as well.

Quoted 1 line

+static struct of_device_id host1x_match[] __devinitdata = {

__devinitdata can be dropped.

Quoted 10 lines

drivers/video/tegra/host/host1x/host1x.c line 182

Quoted 8 lines
drivers/video/tegra/host/host1x/host1x.c +8 -0
+     { .compatible = "nvidia,tegra20-host1x", },
+     { .compatible = "nvidia,tegra30-host1x", },
+     { },
+};
+
+static struct platform_driver platform_driver = {
+     .probe = nvhost_probe,
+     .remove = __exit_p(nvhost_remove),

__exit_p also.

Ok.

Quoted 3 lines
Quoted 1 line

+ .of_match_table = of_match_ptr(host1x_match),

No need for of_match_ptr().

Will remove.

Quoted 4 lines

drivers/video/tegra/host/host1x/host1x.c line 203

Quoted 2 lines
drivers/video/tegra/host/host1x/host1x.c +2 -0
+module_init(nvhost_mod_init);
+module_exit(nvhost_mod_exit);

Use module_platform_driver().

Ok.

Quoted 7 lines
Quoted 2 lines
drivers/video/tegra/host/host1x/host1x.h +0 -0

[...]

drivers/video/tegra/host/host1x/host1x.h line 30

Quoted 2 lines
drivers/video/tegra/host/host1x/host1x.h +2 -0
+#define TRACE_MAX_LENGTH     128U
+#define IFACE_NAME           "nvhost"

None of these seem to be used.

Will remove.

Quoted 13 lines
Quoted 13 lines
drivers/video/tegra/host/host1x/host1x.h +13 -0
+static inline void *nvhost_get_private_data(struct platform_device *_dev)
+{
+     struct nvhost_device_data *pdata =
+             (struct nvhost_device_data *)platform_get_drvdata(_dev);
+     WARN_ON(!pdata);
+     return (pdata && pdata->private_data) ? pdata->private_data : NULL;
+}
+
+static inline void nvhost_set_private_data(struct platform_device *_dev,
+     void *priv_data)
+{
+     struct nvhost_device_data *pdata =
+             (struct nvhost_device_data *)platform_get_drvdata(_dev);
Quoted 8 lines

drivers/video/tegra/host/host1x/host1x.h line 58

Quoted 4 lines
drivers/video/tegra/host/host1x/host1x.h +4 -0
+     WARN_ON(!pdata);
+     if (pdata)
+             pdata->private_data = priv_data;
+}

You should need none of these. Instead put all the data you need into you struct host1x and associate that with the platform device using platform_set_drvdata().

I need to actually find a way to do this for both host1x itself, and the 2D module. But as said, I'll try to remove the auxdata and come up with something better.

Quoted 11 lines
Quoted 11 lines
drivers/video/tegra/host/host1x/host1x.h +11 -0
+static inline
+struct nvhost_master *nvhost_get_host(struct platform_device *_dev)
+{
+     struct platform_device *pdev;
+
+     if (_dev->dev.parent) {
+             pdev = to_platform_device(_dev->dev.parent);
+             return nvhost_get_private_data(pdev);
+     } else
+             return nvhost_get_private_data(_dev);
+}
Quoted 8 lines

drivers/video/tegra/host/host1x/host1x.h line 76

Quoted 6 lines
drivers/video/tegra/host/host1x/host1x.h +6 -0
+
+static inline
+struct platform_device *nvhost_get_parent(struct platform_device *_dev)
+{
+     return _dev->dev.parent ? to_platform_device(_dev->dev.parent) : NULL;
+}

These don't seem to be used.

nvhost_get_host() is used in a subsequent patch, but getting parent doesn't seem to be.

Quoted 2 lines

Usually you don't keep separate variables for subregions. This can equally well be done with just adding a corresponding offset.

Hmm, ok, I could do that, but it just sounds logical to have only one piece of code that finds the sync reg base. I don't really understand why it needs to be duplicate for every access.

Quoted 20 lines
Quoted 20 lines
drivers/video/tegra/host/host1x/host1x.h +20 -0
+static void host1x_syncpt_debug(struct nvhost_syncpt *sp)
+{
+     u32 i;
+     for (i = 0; i < nvhost_syncpt_nb_pts(sp); i++) {
+             u32 max = nvhost_syncpt_read_max(sp, i);
+             u32 min = nvhost_syncpt_update_min(sp, i);
+             if (!max && !min)
+                     continue;
+             dev_info(&syncpt_to_dev(sp)->dev->dev,
+                     "id %d (%s) min %d max %d\n",
+                     i, syncpt_op().name(sp, i),
+                     min, max);
+
+     }
+
+     for (i = 0; i < nvhost_syncpt_nb_bases(sp); i++) {
+             u32 base_val;
+             host1x_syncpt_read_wait_base(sp, i);
+             base_val = sp->base_val[i];
+             if (base_val)
Quoted 8 lines

drivers/video/tegra/host/host1x/host1x.h

Quoted 6 lines
drivers/video/tegra/host/host1x/host1x.h +6 -0
+                     dev_info(&syncpt_to_dev(sp)->dev->dev,
+                                     "waitbase id %d val %d\n",
+                                     i, base_val);
+
+     }
+}

This should probably be integrated with debugfs.

I could move this to debug.c, but it's debugging aid when a command stream is misbehaving and it spews this to UART when sync point wait is timing out. So not debugfs stuff.

Quoted 5 lines

drivers/video/tegra/host/host1x/hw_host1x01_sync.h

Quoted 1 line
drivers/video/tegra/host/host1x/hw_host1x01_sync.h +0 -0

Autogenerated files are generally not acceptable. And I already mentioned before that you should be using #define instead of static inline functions for register and bit definitions.

What's the root cause for autogenerated files not being acceptable? I'm autogenerating them from definitions I get from hardware, which makes the results reliable.

I like static inline because I get the benefit of compiler type checking, and gcov shows me which register definitions have been used in different tests.

#defines are always messy and I pretty much hate them. But if the general request is to use #define's, even though I don't agree, I can accommodate. It's simple to write a sed script to do the conversion.

Quoted 3 lines

This is a very funky way of creating sysfs attributes. What you probably want here are device attributes. See Documentation/filesystems/sysfs.txt and include/linux/sysfs.h.

Thanks for the pointers, looks like device attributes could be used.

Quoted 10 lines

drivers/video/tegra/host/host1x/hw_host1x01_sync.h

Quoted 8 lines
drivers/video/tegra/host/host1x/hw_host1x01_sync.h +8 -0
+bool nvhost_syncpt_is_expired(
+     struct nvhost_syncpt *sp,
+     u32 id,
+     u32 thresh)
+{
+     u32 current_val;
+     u32 future_val;
+     smp_rmb();

What do you need a read memory barrier for?

I'll test without that. I can't see any valid reason, and I have a couple of other similar problems.

Quoted 16 lines
Quoted 16 lines
drivers/video/tegra/host/host1x/hw_host1x01_sync.h +16 -0
+/* Displays the current value of the sync point via sysfs */
+static ssize_t syncpt_min_show(struct kobject *kobj,
+             struct kobj_attribute *attr, char *buf)
+{
+     struct nvhost_syncpt_attr *syncpt_attr =
+             container_of(attr, struct nvhost_syncpt_attr, attr);
+
+     return snprintf(buf, PAGE_SIZE, "%u",
+                     nvhost_syncpt_read(&syncpt_attr->host->syncpt,
+                             syncpt_attr->id));
+}
+
+static ssize_t syncpt_max_show(struct kobject *kobj,
+             struct kobj_attribute *attr, char *buf)
+{
+     struct nvhost_syncpt_attr *syncpt_attr =
Quoted 8 lines

drivers/video/tegra/host/host1x/hw_host1x01_sync.h

Quoted 6 lines
drivers/video/tegra/host/host1x/hw_host1x01_sync.h +6 -0
+             container_of(attr, struct nvhost_syncpt_attr, attr);
+
+     return snprintf(buf, PAGE_SIZE, "%u",
+                     nvhost_syncpt_read_max(&syncpt_attr->host->syncpt,
+                             syncpt_attr->id));
+}

This looks like it belongs in debugfs.

This is actually the only interface to read the max value to user space, which can be useful for doing some comparisons that take wrapping into account. But we could just add IOCTLs and remove the sysfs entries.

Quoted 67 lines
Quoted 1 line
include/linux/nvhost.h +0 -0

[...]

Quoted 65 lines
include/linux/nvhost.h +65 -0
+struct host1x_device_info {
+     int             nb_channels;    /* host1x: num channels supported */
+     int             nb_pts;         /* host1x: num syncpoints supported */
+     int             nb_bases;       /* host1x: num syncpoints supported */
+     u32             client_managed; /* host1x: client managed syncpts */
+     int             nb_mlocks;      /* host1x: number of mlocks */
+     const char      **syncpt_names; /* names of sync points */
+};
+
+struct nvhost_device_data {
+     int             version;        /* ip version number of device */
+     int             id;             /* Separates clients of same hw */
+     int             index;          /* Hardware channel number */
+     void __iomem    *aperture;      /* Iomem mapped to kernel */
+
+     u32             syncpts;        /* Bitfield of sync points used */
+     u32             modulemutexes;  /* Bit field of module mutexes */
+
+     u32             class;          /* Device class */
+     bool            serialize;      /* Serialize submits in the channel */
+
+     int             powergate_ids[NVHOST_MODULE_MAX_POWERGATE_IDS];
+     bool            can_powergate;  /* True if module can be power gated */
+     int             clockgate_delay;/* Delay before clock gated */
+     int             powergate_delay;/* Delay before power gated */
+     struct nvhost_clock clocks[NVHOST_MODULE_MAX_CLOCKS];/* Clock names */
+
+     struct delayed_work powerstate_down;/* Power state management */
+     int             num_clks;       /* Number of clocks opened for dev */
+     struct clk      *clk[NVHOST_MODULE_MAX_CLOCKS];
+     struct mutex    lock;           /* Power management lock */
+     int             powerstate;     /* Current power state */
+     int             refcount;       /* Number of tasks active */
+     wait_queue_head_t idle_wq;      /* Work queue for idle */
+
+     struct nvhost_channel *channel; /* Channel assigned for the module */
+     struct kobject *power_kobj;     /* kobj to hold power sysfs entries */
+     struct nvhost_device_power_attr *power_attrib;  /* sysfs attributes */
+     struct dentry *debugfs;         /* debugfs directory */
+
+     void *private_data;             /* private platform data */
+     struct platform_device *pdev;   /* owner platform_device */
+
+     /* Finalize power on. Can be used for context restore. */
+     void (*finalize_poweron)(struct platform_device *dev);
+
+     /* Device is busy. */
+     void (*busy)(struct platform_device *);
+
+     /* Device is idle. */
+     void (*idle)(struct platform_device *);
+
+     /* Device is going to be suspended */
+     void (*suspend_ndev)(struct platform_device *);
+
+     /* Device is initialized */
+     void (*init)(struct platform_device *dev);
+
+     /* Device is de-initialized. */
+     void (*deinit)(struct platform_device *dev);
+
+     /* Preparing for power off. Used for context save. */
+     int (*prepare_poweroff)(struct platform_device *dev);
+
+     /* Clock gating callbacks */
Quoted 8 lines

include/linux/nvhost.h line 126

Quoted 3 lines
include/linux/nvhost.h +3 -0
+     int (*prepare_clockoff)(struct platform_device *dev);
+     void (*finalize_clockon)(struct platform_device *dev);
+};

A lot of this can be removed if you use existing infrastructure and simplify the design a bit. Most of it can probably move into the main struct host1x to avoid needless indirections that make the code hard to follow and maintain.

Actually, this struct is generic for host1x and host1x clients, so they cannot be moved to host1x. I do also realize that I'm not using them in the patch sets I sent for 2D.

Terje

#41 lore raw

Re: [RFC v2 2/8] video: tegra: Add syncpoint wait and interrupts

In reply to Thierry Reding
Quoted 16 lines · Thierry Reding

drivers/video/tegra/host/dev.c u32 host1x_syncpt_read(u32 id) · line 46

Quoted 9 lines
drivers/video/tegra/host/dev.c +1 -0
index 98c9c9f..025a820 100644
@@ -43,6 +43,13 @@ u32 host1x_syncpt_read(u32 id)
 }
 EXPORT_SYMBOL(host1x_syncpt_read);
 
+int host1x_syncpt_wait(u32 id, u32 thresh, u32 timeout, u32 *value)

The choice of data types is odd here. id refers to a syncpt so a better choice would have been unsigned int because the size of the variable doesn't actually matter. But as I already said in my reply to patch 1, these are resources and should therefore better be abstracted through an opaque pointer anyway.

Quoted 3 lines

timeout is usually signed long, so this function should reflect that. As for the value this is probably fine as it will effectively be set from a register value. Though you also cache them in software using atomics.

32-bits is an architectural limit for the sync point id, so that's why I used it here. But you're right - it doesn't really matter and could be changed to unsigned long.

thresh and *value reflects that sync point value is 32-bit, and I'd keep that as is.

Timeout should be unsigned long, yes.

Quoted 31 lines
Quoted 1 line
drivers/video/tegra/host/host1x/host1x_intr.c +0 -0

[...]

drivers/video/tegra/host/host1x/host1x_intr.c line 31

Quoted 10 lines
drivers/video/tegra/host/host1x/host1x_intr.c +10 -0
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/io.h>
+#include <asm/mach/irq.h>
+
+#include "nvhost_intr.h"
+#include "host1x/host1x.h"
+
+/* Spacing between sync registers */
+#define REGISTER_STRIDE 4

Erm... no. The usual way you should be doing this is either make the register definitions account for the stride or use accessors that apply the stride. You should be doing the latter anyway to make accesses. For example:

        static inline void host1x_syncpt_writel(struct host1x *host1x,
                                                unsigned long value,
                                                unsigned long offset)
        {
                writel(value, host1x->regs + SYNCPT_BASE + offset);
        }

        static inline unsigned long host1x_syncpt_readl(struct host1x *host1x,
                                                        unsigned long offset)
        {
                return readl(host1x->regs + SYNCPT_BASE + offset);
        }
Quoted 6 lines

Alternatively, if you want to pass the register index instead of the offset, you can use just multiply the offset in that function:

        writel(value, host1x->regs + SYNCPT_BASE + (offset << 2));

The same can also be done with the non-syncpt registers.

The register number has a stride of 4 when doing writes, and 1 when adding to command streams. This is why I've kept the register definitions as is.

I could add helper functions. Just as a side note, the sync register space has other definitions than just the syncpt registers, so the naming should be changed a bit.

Quoted 19 lines
Quoted 19 lines
drivers/video/tegra/host/host1x/host1x_intr.c +19 -0
+static irqreturn_t syncpt_thresh_cascade_isr(int irq, void *dev_id)
+{
+     struct nvhost_master *dev = dev_id;
+     void __iomem *sync_regs = dev->sync_aperture;
+     struct nvhost_intr *intr = &dev->intr;
+     unsigned long reg;
+     int i, id;
+
+     for (i = 0; i < dev->info.nb_pts / BITS_PER_LONG; i++) {
+             reg = readl(sync_regs +
+                             host1x_sync_syncpt_thresh_cpu0_int_status_r() +
+                             i * REGISTER_STRIDE);
+             for_each_set_bit(id, &reg, BITS_PER_LONG) {
+                     struct nvhost_intr_syncpt *sp =
+                             intr->syncpt + (i * BITS_PER_LONG + id);
+                     host1x_intr_syncpt_thresh_isr(sp);
+                     queue_work(intr->wq, &sp->work);
+             }
+     }
Quoted 8 lines

drivers/video/tegra/host/host1x/host1x_intr.c line 63

Quoted 3 lines
drivers/video/tegra/host/host1x/host1x_intr.c +3 -0
+
+     return IRQ_HANDLED;
+}

Maybe it would be better to call the syncpt handlers in interrupt context and let them schedule work if they want to. I'm thinking about the display controllers which may want to use syncpoints for VBLANK support.

Display controller can use the APIs to read, increment and wait for sync point.

We could do more in isr, but then again, we've noticed that the current design already gives pretty good latency, so we haven't seen the need to move code from thread to isr.

Quoted 15 lines
Quoted 15 lines
drivers/video/tegra/host/host1x/host1x_intr.c +15 -0
+static void host1x_intr_init_host_sync(struct nvhost_intr *intr)
+{
+     struct nvhost_master *dev = intr_to_dev(intr);
+     void __iomem *sync_regs = dev->sync_aperture;
+     int i, err, irq;
+
+     writel(0xffffffffUL,
+             sync_regs + host1x_sync_syncpt_thresh_int_disable_r());
+     writel(0xffffffffUL,
+             sync_regs + host1x_sync_syncpt_thresh_cpu0_int_status_r());
+
+     for (i = 0; i < dev->info.nb_pts; i++)
+             INIT_WORK(&intr->syncpt[i].work, syncpt_thresh_cascade_fn);
+
+     irq = platform_get_irq(dev->dev, 0);
Quoted 8 lines

drivers/video/tegra/host/host1x/host1x_intr.c line 84

Quoted 5 lines
drivers/video/tegra/host/host1x/host1x_intr.c +5 -0
+     WARN_ON(IS_ERR_VALUE(irq));
+     err = devm_request_irq(&dev->dev->dev, irq,
+                             syncpt_thresh_cascade_isr,
+                             IRQF_SHARED, "host_syncpt", dev);
+     WARN_ON(IS_ERR_VALUE(err));

You should be handling this properly and propagate these errors to the corresponding .probe().

Yes, will do. And the strange part is that nvhost_intr actually already contains the irq number, so actually there's no need to retrieve it from platform_device.

Quoted 14 lines
Quoted 14 lines
drivers/video/tegra/host/host1x/host1x_intr.c +14 -0
+/**
+ * Sync point threshold interrupt service function
+ * Handles sync point threshold triggers, in interrupt context
+ */
+static void host1x_intr_syncpt_thresh_isr(struct nvhost_intr_syncpt *syncpt)
+{
+     unsigned int id = syncpt->id;
+     struct nvhost_intr *intr = intr_syncpt_to_intr(syncpt);
+
+     void __iomem *sync_regs = intr_to_dev(intr)->sync_aperture;
+
+     u32 reg = BIT_WORD(id) * REGISTER_STRIDE;
+
+     writel(BIT_MASK(id), sync_regs +
Quoted 8 lines

drivers/video/tegra/host/host1x/host1x_intr.c line 173

Quoted 4 lines
drivers/video/tegra/host/host1x/host1x_intr.c +4 -0
+             host1x_sync_syncpt_thresh_int_disable_r() + reg);
+     writel(BIT_MASK(id), sync_regs +
+             host1x_sync_syncpt_thresh_cpu0_int_status_r() + reg);
+}

So this disables all interrupts and is called from the syncpt interrupt handler. Where are the interrupts reenabled? Do host1x clients have to do that manually?

The thread re-enables once it's done. It checks the next value we're interested in, and programs that to host1x syncpt threshold.

Quoted 9 lines
Quoted 9 lines
drivers/video/tegra/host/host1x/host1x_intr.c +9 -0
+     /* enable extra interrupt sources IP_READ_INT and IP_WRITE_INT */
+     writel(BIT(30) | BIT(31), sync_regs + host1x_sync_hintmask_ext_r());
+
+     /* enable extra interrupt sources */
+     writel(BIT(12) | BIT(31), sync_regs + host1x_sync_hintmask_r());
+
+     /* enable host module interrupt to CPU0 */
+     writel(BIT(0), sync_regs + host1x_sync_intc0mask_r());
+
Quoted 8 lines

drivers/video/tegra/host/host1x/host1x_intr.c line 235

Quoted 5 lines
drivers/video/tegra/host/host1x/host1x_intr.c +5 -0
+     /* master enable for general (not syncpt) host interrupts */
+     writel(BIT(0), sync_regs + host1x_sync_intmask_r());
+
+     return err;
+}

You should add defines for these bits, which will likely make the comments redundant.

I'm actually thinking that I might just remove the generic interrupts. We have no use for it in upstream kernel.

Quoted 3 lines

Okay, so this is where syncpoint interrupts are reenabled. The rest of this whole wait queue code looks overly complex. I'll need to go through that separately and more thoroughly.

Thanks.

Quoted 7 lines

drivers/video/tegra/host/host1x/host1x_intr.c

Quoted 5 lines
drivers/video/tegra/host/host1x/host1x_intr.c +5 -0
+void *nvhost_intr_alloc_waiter()
+{
+     return kzalloc(sizeof(struct nvhost_waitlist),
+                     GFP_KERNEL|__GFP_REPEAT);
+}

I don't think we need __GFP_REPEAT here.

This used to be called from code where failed alloc was fatal, but not anymore, so __GFP_REPEAT isn't needed anymore.

Quoted 5 lines

drivers/video/tegra/host/host1x/host1x_intr.c

Quoted 3 lines
drivers/video/tegra/host/host1x/host1x_intr.c +3 -0
+/*** Init & shutdown ***/
+
+int nvhost_intr_init(struct nvhost_intr *intr, u32 irq_gen, u32 irq_sync)

Again, using u32 for interrupt numbers is unusual.

Ok.

Quoted 5 lines

drivers/video/tegra/host/host1x/host1x_intr.c

Quoted 3 lines
drivers/video/tegra/host/host1x/host1x_intr.c +3 -0
+     mutex_init(&intr->mutex);
+     intr->host_syncpt_irq_base = irq_sync;
+     intr->wq = create_workqueue("host_syncpt");

What if create_workqueue() fails?

Hmm, we panic? Not good.

Quoted 9 lines

drivers/video/tegra/host/host1x/host1x_intr.c

Quoted 8 lines
drivers/video/tegra/host/host1x/host1x_intr.c +7 -0
+     intr_op().init_host_sync(intr);
+     intr->host_general_irq = irq_gen;
+     intr_op().request_host_general_irq(intr);
+
+     for (id = 0, syncpt = intr->syncpt;
+          id < nb_pts;
+          ++id, ++syncpt) {
Quoted 8 lines

This fits perfectly well on a single line, no need to wrap it. Also you could instead of incrementing syncpt, move it into the loop and assign it based on id.

        for (id = 0; id < nb_pts; id++) {
                struct nvhost_intr_syncpt *syncpt = &intr->syncpt[id];
                ...
        }

Looks better, yes.

Quoted 9 lines

drivers/video/tegra/host/host1x/host1x_intr.c

Quoted 7 lines
drivers/video/tegra/host/host1x/host1x_intr.c +7 -0
+void nvhost_intr_start(struct nvhost_intr *intr, u32 hz)
+{
+     mutex_lock(&intr->mutex);
+
+     intr_op().init_host_sync(intr);
+     intr_op().set_host_clocks_per_usec(intr,
+                                            (hz + 1000000 - 1)/1000000);

DIV_ROUND_UP(hz)?

Yes, that's what we should use. I didn't know we have that.

Quoted 4 lines
Quoted 1 line

+#define NVHOST_NO_TIMEOUT (-1)

Couldn't you reuse MAX_SCHEDULE_TIMEOUT instead? You already use it as the value for the timeout parameter in nvhost_syncpt_wait().

I guess NVHOST_NO_TIMEOUT is anyway a bad idea, and I could just remove it. The caller can just pass LONG_MAX if it wants to wait for a _really_ long time, but having no timeout is not good.

Terje

#48 lore raw

Re: [RFC,v2,3/8] video: tegra: host: Add channel and client support

In reply to Mark Zhang
Quoted 4 lines · Mark Zhang

drivers/video/tegra/host/bus_client.c line 76

Quoted 2 lines
drivers/video/tegra/host/bus_client.c new file +2 -0
+fail:
+	/* Add clean-up */

Yes, add "nvhost_module_deinit" here?

Sounds good.

Quoted 5 lines
Quoted 5 lines
drivers/video/tegra/host/bus_client.c new file +5 -0
+int nvhost_client_device_suspend(struct platform_device *dev)
+{
+	int ret = 0;
+	struct nvhost_device_data *pdata = platform_get_drvdata(dev);
+
Quoted 8 lines

drivers/video/tegra/host/bus_client.c line 92

Quoted 6 lines
drivers/video/tegra/host/bus_client.c new file +6 -0
+	ret = nvhost_channel_suspend(pdata->channel);
+	dev_info(&dev->dev, "suspend status: %d\n", ret);
+	if (ret)
+		return ret;
+
+	return ret;

Minor issue: just "return ret" is OK. That "if" doesn't make sense.

Yes, must be some snafu when doing changes in code.

Quoted 6 lines

drivers/video/tegra/host/chip_support.c line 28

Quoted 3 lines
drivers/video/tegra/host/chip_support.c +1 -1
-struct nvhost_chip_support *nvhost_chip_ops;
+static struct nvhost_chip_support *nvhost_chip_ops;

All right, already fixed here. Sorry, so just ignore what I said about this in my reply to your patch 1.

I was wondering about this, because I thought I did make it static. But it looks like I added that to the wrong commit. Anyway, this needs rethinking.

Quoted 6 lines
Quoted 6 lines
drivers/video/tegra/host/dmabuf.c new file +6 -0
+struct mem_handle *nvhost_dmabuf_get(u32 id, struct platform_device *dev)
+{
+	struct mem_handle *h;
+	struct dma_buf *buf;
+
+	buf = dma_buf_get(to_dmabuf_fd(id));
Quoted 8 lines

drivers/video/tegra/host/dmabuf.c line 98

Quoted 6 lines
drivers/video/tegra/host/dmabuf.c new file +6 -0
+	if (IS_ERR_OR_NULL(buf))
+		return (struct mem_handle *)buf;
+
+	h = (struct mem_handle *)dma_buf_attach(buf, &dev->dev);
+	if (IS_ERR_OR_NULL(h))
+		dma_buf_put(buf);

Return an error here.

Will do.

Quoted 6 lines

drivers/video/tegra/host/host1x/host1x01.c line 66

Quoted 3 lines
drivers/video/tegra/host/host1x/host1x01.c +3 -0
+	op->nvhost_dev.alloc_nvhost_channel = t20_alloc_nvhost_channel;
+	op->nvhost_dev.free_nvhost_channel = t20_free_nvhost_channel;
+

I recall in previous version, there is t30-related alloc_nvhost_channel & free_nvhost_channel. Why remove them?

I could actually refactor these all into one alloc channel. We already store the number of channels in a data type, so a generic channel allocator would be better than having a chip specific one.

Quoted 10 lines
Quoted 10 lines
drivers/video/tegra/host/host1x/host1x_cdma.c new file +10 -0
+static int push_buffer_init(struct push_buffer *pb)
+{
+	struct nvhost_cdma *cdma = pb_to_cdma(pb);
+	struct nvhost_master *master = cdma_to_dev(cdma);
+	pb->mapped = NULL;
+	pb->phys = 0;
+	pb->handle = NULL;
+
+	cdma_pb_op().reset(pb);
+
Quoted 8 lines

drivers/video/tegra/host/host1x/host1x_cdma.c line 79

Quoted 6 lines
drivers/video/tegra/host/host1x/host1x_cdma.c new file +6 -0
+	/* allocate and map pushbuffer memory */
+	pb->mapped = dma_alloc_writecombine(&master->dev->dev,
+			PUSH_BUFFER_SIZE + 4, &pb->phys, GFP_KERNEL);
+	if (IS_ERR_OR_NULL(pb->mapped)) {
+		pb->mapped = NULL;
+		goto fail;

Return directly here. "goto fail" makes "push_buffer_destroy" get called.

Will do.

Quoted 13 lines

drivers/video/tegra/host/host1x/host1x_cdma.c line 89

Quoted 11 lines
drivers/video/tegra/host/host1x/host1x_cdma.c new file +10 -0
+	}
+
+	/* memory for storing mem client and handles for each opcode pair */
+	pb->handle = kzalloc(NVHOST_GATHER_QUEUE_SIZE *
+				sizeof(struct mem_handle *),
+			GFP_KERNEL);
+	if (!pb->handle)
+		goto fail;
+
+	/* put the restart at the end of pushbuffer memory */

Just for curious, why "pb->mapped + 1K" is the end of a 4K pushbuffer?

pb->mapped is u32 *, so compiler will take care of multiplying by sizeof(u32).

Quoted 18 lines
Quoted 18 lines
drivers/video/tegra/host/nvhost_cdma.c new file +18 -0
+unsigned int nvhost_cdma_wait_locked(struct nvhost_cdma *cdma,
+		enum cdma_event event)
+{
+	for (;;) {
+		unsigned int space = cdma_status_locked(cdma, event);
+		if (space)
+			return space;
+
+		/* If somebody has managed to already start waiting, yield */
+		if (cdma->event != CDMA_EVENT_NONE) {
+			mutex_unlock(&cdma->lock);
+			schedule();
+			mutex_lock(&cdma->lock);
+			continue;
+		}
+		cdma->event = event;
+
+		mutex_unlock(&cdma->lock);
Quoted 8 lines

drivers/video/tegra/host/nvhost_cdma.c line 108

Quoted 2 lines
drivers/video/tegra/host/nvhost_cdma.c new file +2 -0
+		down(&cdma->sem);
+		mutex_lock(&cdma->lock);

I'm newbie of nvhost but I feel here is very tricky, about the lock and unlock of this mutex: cdma->lock. Does it require this mutex is locked before calling this function? And do we need to unlock it before the
code: "return space;" above? IMHO, this is not a good design and can we find out a better solution?

Yeah, it's not perfect and good solutions are welcome. cdma_status_locked() must be called with a mutex. But, what we generally wait for is for space in push buffer. The cleanup code cannot run if we keep cdma->lock, so I release it.

The two ways to loop are because there was a race between two processes waiting for space. One of them set cdma->event to indicate what it's waiting for and can go to sleep, but the other has to keep spinning.

Terje

#51 lore raw

Re: [RFC v2 3/8] video: tegra: host: Add channel and client support

In reply to Thierry Reding
Quoted 5 lines · Thierry Reding

* PGP Signed by an unknown key

On Mon, Nov 26, 2012 at 03:19:09PM +0200, Terje Bergstrom wrote:

I've skipped a lot of code here that I need more time to review.

Thanks already for the very good comments! It's great getting comments on the code from fresh eyes.

Quoted 3 lines

Looking some more at how this is used, I'm starting to think that it might be easier to export the various handlers and allow them to be passed to the nvhost_intr_add_action() explicitly.

Oh, so you mean like "nvhost_intr_add_action(intr, id, threshold, nvhost_intr_action_submit_complete, channel, waiter, priv), and nvhost_intr_action_submit_complete is the function pointer?

There's one case to take care of: we merge the waits for the jobs into one waiter to save us from having too many irq calls. Perhaps that could be handled by a flag, or something like that.

Quoted 4 lines

drivers/video/tegra/host/nvhost_job.c line 35

Quoted 2 lines
drivers/video/tegra/host/nvhost_job.c new file +2 -0
+/* Magic to use to fill freed handle slots */
+#define BAD_MAGIC 0xdeadbeef

This isn't currently used.

Will remove.

Quoted 42 lines
Quoted 42 lines
drivers/video/tegra/host/nvhost_job.c new file +41 -0
+static size_t job_size(u32 num_cmdbufs, u32 num_relocs, u32 num_waitchks)
+{
+     u32 num_unpins = num_cmdbufs + num_relocs;
+     s64 total;
+
+     if (num_relocs < 0 || num_waitchks < 0 || num_cmdbufs < 0)
+             return 0;
+
+     total = sizeof(struct nvhost_job)
+                     + num_relocs * sizeof(struct nvhost_reloc)
+                     + num_unpins * sizeof(struct nvhost_job_unpin_data)
+                     + num_waitchks * sizeof(struct nvhost_waitchk)
+                     + num_cmdbufs * sizeof(struct nvhost_job_gather);
+
+     if (total > ULONG_MAX)
+             return 0;
+     return (size_t)total;
+}
+
+
+static void init_fields(struct nvhost_job *job,
+             u32 num_cmdbufs, u32 num_relocs, u32 num_waitchks)
+{
+     u32 num_unpins = num_cmdbufs + num_relocs;
+     void *mem = job;
+
+     /* First init state to zero */
+
+     /*
+      * Redistribute memory to the structs.
+      * Overflows and negative conditions have
+      * already been checked in job_alloc().
+      */
+     mem += sizeof(struct nvhost_job);
+     job->relocarray = num_relocs ? mem : NULL;
+     mem += num_relocs * sizeof(struct nvhost_reloc);
+     job->unpins = num_unpins ? mem : NULL;
+     mem += num_unpins * sizeof(struct nvhost_job_unpin_data);
+     job->waitchk = num_waitchks ? mem : NULL;
+     mem += num_waitchks * sizeof(struct nvhost_waitchk);
+     job->gathers = num_cmdbufs ? mem : NULL;
Quoted 8 lines

drivers/video/tegra/host/nvhost_job.c line 83

Quoted 6 lines
drivers/video/tegra/host/nvhost_job.c new file +6 -0
+     mem += num_cmdbufs * sizeof(struct nvhost_job_gather);
+     job->addr_phys = (num_cmdbufs || num_relocs) ? mem : NULL;
+
+     job->reloc_addr_phys = job->addr_phys;
+     job->gather_addr_phys = &job->addr_phys[num_relocs];
+}

I wouldn't bother splitting out the above two functions.

You're right, I'll merge them back in. There was a historical reason for the split, but not anymore.

Quoted 13 lines

drivers/video/tegra/host/nvhost_job.c line 93

Quoted 11 lines
drivers/video/tegra/host/nvhost_job.c new file +10 -0
+
+struct nvhost_job *nvhost_job_alloc(struct nvhost_channel *ch,
+             int num_cmdbufs, int num_relocs, int num_waitchks)
+{
+     struct nvhost_job *job = NULL;
+     size_t size = job_size(num_cmdbufs, num_relocs, num_waitchks);
+
+     if (!size)
+             return NULL;
+     job = vzalloc(size);

Why vzalloc()?

I guess it's basically moot, but we tried that when we had some memory fragmentation issues and it was left even though we did find out it's not needed.

Quoted 4 lines
Quoted 4 lines
drivers/video/tegra/host/nvhost_job.c new file +4 -0
+void nvhost_job_add_gather(struct nvhost_job *job,
+             u32 mem_id, u32 words, u32 offset)
+{
+     struct nvhost_job_gather *cur_gather =
Quoted 8 lines

drivers/video/tegra/host/nvhost_job.c line 134

Quoted 6 lines
drivers/video/tegra/host/nvhost_job.c new file +6 -0
+                     &job->gathers[job->num_gathers];
+
+     cur_gather->words = words;
+     cur_gather->mem_id = mem_id;
+     cur_gather->offset = offset;
+     job->num_gathers += 1;

job->num_gathers++

OK.

Quoted 4 lines
Quoted 4 lines
drivers/video/tegra/host/nvhost_job.c new file +4 -0
+static int pin_job_mem(struct nvhost_job *job)
+{
+     int i;
+     int count = 0;
Quoted 8 lines

drivers/video/tegra/host/nvhost_job.c line 208

Quoted 5 lines
drivers/video/tegra/host/nvhost_job.c new file +5 -0
+     int result;
+     long unsigned *ids =
+                     kmalloc(sizeof(u32 *) *
+                             (job->num_relocs + job->num_gathers),
+                             GFP_KERNEL);

Maybe this should be allocated along with the nvhost_job and the other fields to avoid having to allocate, and potentially fail, here?

Yes, you're right.

Quoted 8 lines

drivers/video/tegra/host/nvhost_job.c line 272

Quoted 5 lines
drivers/video/tegra/host/nvhost_job.c new file +5 -0
+             __raw_writel(
+                     (job->reloc_addr_phys[i] +
+                             reloc->target_offset) >> reloc->shift,
+                     (cmdbuf_page_addr +
+                             (reloc->cmdbuf_offset & ~PAGE_MASK)));

You're not writing to I/O memory, so you shouldn't be using __raw_writel() here.

Will change.

Quoted 8 lines

drivers/video/tegra/host/nvhost_job.c line 302

Quoted 6 lines
drivers/video/tegra/host/nvhost_job.c new file +5 -0
+int nvhost_job_pin(struct nvhost_job *job, struct platform_device *pdev)
+{
+     int err = 0, i = 0, j = 0;
+     struct nvhost_syncpt *sp = &nvhost_get_host(pdev)->syncpt;
+     unsigned long waitchk_mask[nvhost_syncpt_nb_pts(sp) / BITS_PER_LONG];

You should use a bitmap instead. See DECLARE_BITMAP in linux/types.h...

Oh, nice. Will do.

Quoted 6 lines

drivers/video/tegra/host/nvhost_job.c line 304

Quoted 3 lines
drivers/video/tegra/host/nvhost_job.c new file +2 -0
+
+     memset(&waitchk_mask[0], 0, sizeof(waitchk_mask));

and run bitmap_zero() here...

Quoted 7 lines

drivers/video/tegra/host/nvhost_job.c line 309

Quoted 5 lines
drivers/video/tegra/host/nvhost_job.c new file +5 -0
+     for (i = 0; i < job->num_waitchk; i++) {
+             u32 syncpt_id = job->waitchk[i].syncpt_id;
+             if (syncpt_id < nvhost_syncpt_nb_pts(sp))
+                     waitchk_mask[BIT_WORD(syncpt_id)] |=
+                             BIT_MASK(syncpt_id);

and use _set_bit here.

Will do.

Quoted 9 lines

drivers/video/tegra/host/nvhost_job.c line 314

Quoted 6 lines
drivers/video/tegra/host/nvhost_job.c new file +5 -0
+     }
+
+     /* get current syncpt values for waitchk */
+     for_each_set_bit(i, &waitchk_mask[0], sizeof(waitchk_mask))
+             nvhost_syncpt_update_min(sp, i);

Or since you only use the mask here, why not move the nvhost_syncpt_update_min() into the above loop?

I want to call nvhost_syncpt_update_min() only once per syncpt register. If the job has 100 sync point increments for 2D sync point, I'd read the value from hardware 100 times, which is expensive.

Quoted 28 lines
Quoted 28 lines
drivers/video/tegra/host/nvhost_job.c new file +28 -0
+     /* patch gathers */
+     for (i = 0; i < job->num_gathers; i++) {
+             struct nvhost_job_gather *g = &job->gathers[i];
+
+             /* process each gather mem only once */
+             if (!g->ref) {
+                     g->ref = nvhost_memmgr_get(g->mem_id, job->ch->dev);
+                     if (IS_ERR(g->ref)) {
+                             err = PTR_ERR(g->ref);
+                             g->ref = NULL;
+                             break;
+                     }
+
+                     g->mem_base = job->gather_addr_phys[i];
+
+                     for (j = 0; j < job->num_gathers; j++) {
+                             struct nvhost_job_gather *tmp =
+                                     &job->gathers[j];
+                             if (!tmp->ref && tmp->mem_id == g->mem_id) {
+                                     tmp->ref = g->ref;
+                                     tmp->mem_base = g->mem_base;
+                             }
+                     }
+                     err = do_relocs(job, g->mem_id,  g->ref);
+                     if (!err)
+                             err = do_waitchks(job, sp,
+                                             g->mem_id, g->ref);
+                     nvhost_memmgr_put(g->ref);
Quoted 8 lines

drivers/video/tegra/host/nvhost_job.c line 354

Quoted 6 lines
drivers/video/tegra/host/nvhost_job.c new file +6 -0
+                     if (err)
+                             break;
+             }
+     }
+fail:
+     wmb();

What do you need this write barrier for?

A good question. It looks we've sprinkled barriers around the code with no proper reason.

Quoted 53 lines
Quoted 53 lines
drivers/video/tegra/host/nvhost_memmgr.c new file +46 -0
new file mode 100644
index 0000000..bdceb74
@@ -0,0 +1,160 @@
+/*
+ * drivers/video/tegra/host/nvhost_memmgr.c
+ *
+ * Tegra host1x Memory Management Abstraction
+ *
+ * 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/kernel.h>
+#include <linux/err.h>
+
+#include "nvhost_memmgr.h"
+#include "dmabuf.h"
+#include "chip_support.h"
+
+struct mem_handle *nvhost_memmgr_alloc(size_t size, size_t align, int flags)
+{
+     struct mem_handle *h = NULL;
+     h = nvhost_dmabuf_alloc(size, align, flags);
+
+     return h;
+}
+
+struct mem_handle *nvhost_memmgr_get(u32 id, struct platform_device *dev)
+{
+     struct mem_handle *h = NULL;
+
+     switch (nvhost_memmgr_type(id)) {
+     case mem_mgr_type_dmabuf:
+             h = (struct mem_handle *) nvhost_dmabuf_get(id, dev);
+             break;
+     default:
+             break;
+     }
Quoted 8 lines

drivers/video/tegra/host/nvhost_memmgr.c line 34

Quoted 3 lines
drivers/video/tegra/host/nvhost_memmgr.c new file +3 -0
+
+     return h;
+}

Heh, this would actually be a case where I'd argue in favour of an ops structure. But Lucas already mentioned that we may want to revise how the memory manager works and ideally we'd only have a single type of buffers anyway so this would largely become obsolete anyway.

Hmm, damn, and I've spent actually significant amount of time of bypassing the ops here. Actually downstream memory manager uses ops indirection. :-) I started removing it when I noticed that the ops should actually be per handle, and not per SoC as the mem_ops() was.

We did discuss with Arto and he proposed that we'd just import dma_buf fds into CMA GEM objects. That'd allow us to only support CMA GEM objects inside nvhost. He started already by implementing CMA GEM buffer support in nvhost as a new buffer type.

I'm not sure if importing is better than just supporting both CMA GEM and dma_buf handles, but I guess we'll find out by trying it.

Quoted 2 lines

I think we already agreed that we want to do dynamic allocation of syncpoints so these definitions can go away.

Yep.

Quoted 8 lines
Quoted 8 lines
drivers/video/tegra/host/nvhost_memmgr.c new file +0 -0
 enum nvhost_power_sysfs_attributes {
      NVHOST_POWER_SYSFS_ATTRIB_CLOCKGATE_DELAY = 0,
      NVHOST_POWER_SYSFS_ATTRIB_POWERGATE_DELAY,
@@ -142,4 +157,138 @@ void host1x_syncpt_incr(u32 id);
 u32 host1x_syncpt_read(u32 id);
 int host1x_syncpt_wait(u32 id, u32 thresh, u32 timeout, u32 *value);
 
Quoted 8 lines

drivers/video/tegra/host/nvhost_memmgr.c void host1x_syncpt_incr(u32 id); · line 161

Quoted 2 lines
drivers/video/tegra/host/nvhost_memmgr.c new file +2 -0
+/* Register device */
+int nvhost_client_device_init(struct platform_device *dev);

Again, I think this should be made easier on the clients. Ideally there'd be a single call to register a client with host1x which would already initialize the appropriate fields. There can be other, separate functions for resource allocations such as syncpoints and channels, though.

I'll try to cook up something to make this clearer.

Quoted 2 lines

drivers/video/tegra/host/nvhost_memmgr.c void host1x_syncpt_incr(u32 id); · line 162

Quoted 1 line
drivers/video/tegra/host/nvhost_memmgr.c new file +1 -0
+int nvhost_client_device_suspend(struct platform_device *dev);

Again, I think this should be handled via runtime PM.

Referring to my previous comment.

Quoted 6 lines

drivers/video/tegra/host/nvhost_memmgr.c void host1x_syncpt_incr(u32 id); · line 164

Quoted 3 lines
drivers/video/tegra/host/nvhost_memmgr.c new file +2 -0
+struct nvhost_channel *nvhost_getchannel(struct nvhost_channel *ch);
+void nvhost_putchannel(struct nvhost_channel *ch);

These are oddly named. Better names would be nvhost_channel_get() or nvhost_channel_put().

Sounds good to me.

Quoted 10 lines

drivers/video/tegra/host/nvhost_memmgr.c void host1x_syncpt_incr(u32 id); · line 170

Quoted 6 lines
drivers/video/tegra/host/nvhost_memmgr.c new file +6 -0
+int nvhost_channel_submit(struct nvhost_job *job);
+
+enum host1x_class {
+     NV_HOST1X_CLASS_ID              = 0x1,
+     NV_GRAPHICS_2D_CLASS_ID         = 0x51,
+};

Maybe this enumeration should be made more consistent, somewhat along the lines of:

Quoted 4 lines
        enum host1x_class {
                HOST1X_CLASS_HOST1X = 0x01,
                HOST1X_CLASS_2D = 0x51,
        };

Sure.

Quoted 2 lines

Again, I'll need more time to go over the rest of the code but the good news is that I'm starting to form a better picture of how things work.

Thanks. I've collected a massive amount of feedback already. v3 will take quite a while to appear after we've finished all the reviews of v2.

Terje

#5 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

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

This could be problematic. Since drivers/video and drivers/gpu/drm are separate trees, this would entail a continuous burden on keeping both trees synchronized. While I realize that eventually it might be better to put the host1x driver in a separate place to accomodate for its use by other subsystems, I'm not sure moving it here right away is the best approach.

Quoted 6 lines

I understand your point, but I hope also that we'd end up with something that can be used as basis for the downstream kernel to migrate to upstream stack.

The key point here is to make the API between nvhost and tegradrm as small and robust to changes as possible.

I agree. But I also fear that there will be changes eventually and having both go in via different tree requires those trees to be merged in a specific order to avoid breakage should the API change. This will be particularly ugly in linux-next.

That's why I explicitly proposed to take this into drivers/gpu/drm/tegra for the time being, until we can be reasonably sure that the API is fixed. Then I'm fine with moving it wherever seems the best fit. Even then there might be the occasional dependency, but they should get fewer and fewer as the code matures.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/video/tegra/host/chip_support.h new file +5 -0
+struct nvhost_syncpt_ops {
+     void (*reset)(struct nvhost_syncpt *, u32 id);
+     void (*reset_wait_base)(struct nvhost_syncpt *, u32 id);
+     void (*read_wait_base)(struct nvhost_syncpt *, u32 id);
+     u32 (*update_min)(struct nvhost_syncpt *, u32 id);
Quoted 8 lines

drivers/video/tegra/host/chip_support.h line 39

Quoted 4 lines
drivers/video/tegra/host/chip_support.h new file +4 -0
+     void (*cpu_incr)(struct nvhost_syncpt *, u32 id);
+     void (*debug)(struct nvhost_syncpt *);
+     const char * (*name)(struct nvhost_syncpt *, u32 id);
+};

Why are these even defined as ops structure? Tegra20 and Tegra30 seem to be compatible when it comes to handling syncpoints. I thought they would even be compatible in all other aspects as well, so why even have this?

Quoted 2 lines

Tegra20 and Tegra30 are compatible, but future chips are not. I was hoping we would be ready in upstream kernel for future chips.

I think we should ignore that problem for now. Generally planning for any possible combination of incompatibilities leads to overgeneralized designs that require precisely these kinds of indirections.

Once some documentation for Tegra 40 materializes we can start thinking about how to encapsulate the incompatible code.

Quoted 9 lines
Quoted 6 lines
Quoted 1 line

+#define syncpt_op() (nvhost_get_chip_ops()->syncpt)

You really shouldn't be doing this, but rather use explicit accesses for these structures. If you're design doesn't scatter these definitions across several files then it isn't difficult to obtain the correct pointers and you don't need these "shortcuts".

Do you mean that I would move the ops to be part of f.ex. nvhost_syncpt or nvhost_intr structs?

Not quite. What I'm saying is that unless there is a reason to encapsulate the functions into an ops structure (for instance because of incompatibilities across chip generations) they shouldn't be pointers in a struct at all.

For that matter I don't think you need the nvhost_syncpt and nvhost_intr structures either.

Quoted 30 lines
Quoted 15 lines
Quoted 2 lines
(quoted diff) +2 -0
+bool host1x_powered(struct platform_device *dev)
+{

[...]

Quoted 5 lines
drivers/video/tegra/host/dev.c new file +5 -0
+}
+EXPORT_SYMBOL(host1x_powered);
+
+void host1x_busy(struct platform_device *dev)
+{

[...]

Quoted 5 lines
drivers/video/tegra/host/dev.c new file +5 -0
+}
+EXPORT_SYMBOL(host1x_busy);
+
+void host1x_idle(struct platform_device *dev)
+{

[...]

Quoted 5 lines

Review

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

These look like a reimplementation of the runtime power-management framework.

Yes, we at some point tried to move to use runtime PM. The first attempt was thwarted by runtime PM and system suspend conflicting with each other. I believe this is pretty much fixed in later versions of kernel.

Also, the problem was that runtime PM doesn't support multiple power states. In downstream kernel, we support clock gating and power gating. When we moved to runtime PM and implemented power gating on top of that, we ended up with more code than just using the current ACM code.

Quoted 5 lines

I have a developer starting to look into how we could take runtime PM again into use with proper power gating support. It'll take a while to get that right. It might be best to rip the dynamic power management out from this patch set, and introduce it later when we have a proper runtime PM solution.

Okay, sounds like a plan. Even if it turns out that the current runtime PM implementation doesn't provide every functionality that you need, we should try to get these changes into the existing frameworks instead of copying large chunks of code.

Quoted 9 lines
Quoted 5 lines

drivers/video/tegra/host/host1x/host1x.c line 57

Quoted 3 lines
drivers/video/tegra/host/host1x/host1x.c new file +3 -0
+static void nvhost_free_resources(struct nvhost_master *host)
+{
+}

This should be removed since it's empty.

True. I wonder how that happened - there was content since recently, but I guess I deleted the code without noticing that the function needs to go, too.

I noticed that it was filled with content in one of the subsequent patches. Depending on how this gets merged eventually you could postpone adding the function until the later patch. But perhaps once the code has been properly reviewed we can just squash the patches again. We'll see.

Quoted 10 lines
Quoted 7 lines

Also you should be using platform_get_irq() for interrupts. Furthermore the host1x DT node (and the TRM) name the interrupts "syncpt" and "general", so maybe those would be more useful variable names than "intr0" and "intr1".

But since you don't use them anyway they shouldn't be part of this patch.

True. I might also as well delete the general interrupt altogether, as we don't use it for any real purpose.

I think it might still be useful for diagnostics. It seems to be used when writes time out. That could still be helpful information when debugging problems.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/video/tegra/host/host1x/host1x.c new file +5 -0
+     for (i = 0; i < pdata->num_clks; i++)
+             clk_prepare_enable(pdata->clk[i]);
+     nvhost_syncpt_reset(&host->syncpt);
+     for (i = 0; i < pdata->num_clks; i++)
+             clk_disable_unprepare(pdata->clk[i]);
Quoted 7 lines
Quoted 2 lines

Stephen already hinted at this when discussing the AUXDATA. You should explicitly request the clocks.

I'm not too happy about that idea. The clock management code is generic for all modules, and that's why it's driven by a data structure. Now Stephen and you ask me to unroll the loops and make copies of the code to facilitate different modules and different SoCs.

Making this generic for all modules may not be what we want as it doesn't allow devices to handle things themselves if necessary. Clock management is just part of the boiler plate that every driver is supposed to cope with. Also the number of clocks is usually not higher than 2 or 3, so the pain is manageable. =)

Furthermore doing this in loops may not work for all modules. Some may require additional delays between enabling the clocks, others may be able to selectively disable one clock but not the other(s).

Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
drivers/video/tegra/host/host1x/host1x.h new file +13 -0
+static inline void *nvhost_get_private_data(struct platform_device *_dev)
+{
+     struct nvhost_device_data *pdata =
+             (struct nvhost_device_data *)platform_get_drvdata(_dev);
+     WARN_ON(!pdata);
+     return (pdata && pdata->private_data) ? pdata->private_data : NULL;
+}
+
+static inline void nvhost_set_private_data(struct platform_device *_dev,
+     void *priv_data)
+{
+     struct nvhost_device_data *pdata =
+             (struct nvhost_device_data *)platform_get_drvdata(_dev);
Quoted 8 lines

drivers/video/tegra/host/host1x/host1x.h line 58

Quoted 4 lines
drivers/video/tegra/host/host1x/host1x.h new file +4 -0
+     WARN_ON(!pdata);
+     if (pdata)
+             pdata->private_data = priv_data;
+}

You should need none of these. Instead put all the data you need into you struct host1x and associate that with the platform device using platform_set_drvdata().

Quoted 3 lines

I need to actually find a way to do this for both host1x itself, and the 2D module. But as said, I'll try to remove the auxdata and come up with something better.

The existing host1x and DRM code could serve as an example since I explicitly wrote them to behave properly.

Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
drivers/video/tegra/host/host1x/host1x.h new file +11 -0
+static inline
+struct nvhost_master *nvhost_get_host(struct platform_device *_dev)
+{
+     struct platform_device *pdev;
+
+     if (_dev->dev.parent) {
+             pdev = to_platform_device(_dev->dev.parent);
+             return nvhost_get_private_data(pdev);
+     } else
+             return nvhost_get_private_data(_dev);
+}
Quoted 8 lines

drivers/video/tegra/host/host1x/host1x.h line 76

Quoted 6 lines
drivers/video/tegra/host/host1x/host1x.h new file +6 -0
+
+static inline
+struct platform_device *nvhost_get_parent(struct platform_device *_dev)
+{
+     return _dev->dev.parent ? to_platform_device(_dev->dev.parent) : NULL;
+}

These don't seem to be used.

Quoted 2 lines

nvhost_get_host() is used in a subsequent patch, but getting parent doesn't seem to be.

Again, if you look at the existing tegra-drm code, the client modules already use something a bit more explicit to obtain a reference to the host1x:

	struct host1x *host1x = dev_get_drvdata(pdev->dev.parent);

The good thing about it is that it very clearly says where the host1x pointer should be coming from. Explicitness is good.

Quoted 6 lines
Quoted 2 lines

Usually you don't keep separate variables for subregions. This can equally well be done with just adding a corresponding offset.

Hmm, ok, I could do that, but it just sounds logical to have only one piece of code that finds the sync reg base. I don't really understand why it needs to be duplicate for every access.

You wouldn't actually be duplicating it. Rather you'd just add another offset. But I commented on this more explicitly in a reply to one of the other patches.

Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
drivers/video/tegra/host/host1x/host1x_syncpt.c new file +20 -0
+static void host1x_syncpt_debug(struct nvhost_syncpt *sp)
+{
+     u32 i;
+     for (i = 0; i < nvhost_syncpt_nb_pts(sp); i++) {
+             u32 max = nvhost_syncpt_read_max(sp, i);
+             u32 min = nvhost_syncpt_update_min(sp, i);
+             if (!max && !min)
+                     continue;
+             dev_info(&syncpt_to_dev(sp)->dev->dev,
+                     "id %d (%s) min %d max %d\n",
+                     i, syncpt_op().name(sp, i),
+                     min, max);
+
+     }
+
+     for (i = 0; i < nvhost_syncpt_nb_bases(sp); i++) {
+             u32 base_val;
+             host1x_syncpt_read_wait_base(sp, i);
+             base_val = sp->base_val[i];
+             if (base_val)
Quoted 8 lines

drivers/video/tegra/host/host1x/host1x_syncpt.c line 146

Quoted 6 lines
drivers/video/tegra/host/host1x/host1x_syncpt.c new file +6 -0
+                     dev_info(&syncpt_to_dev(sp)->dev->dev,
+                                     "waitbase id %d val %d\n",
+                                     i, base_val);
+
+     }
+}

This should probably be integrated with debugfs.

Quoted 3 lines

I could move this to debug.c, but it's debugging aid when a command stream is misbehaving and it spews this to UART when sync point wait is timing out. So not debugfs stuff.

Okay, in that case it should stay in. Perhaps convert dev_info() to dev_dbg(). Perhaps wrapping it in some #ifdef CONFIG_TEGRA_HOST1X_DEBUG guards would also be useful. Maybe not.

Quoted 9 lines
Quoted 5 lines

drivers/video/tegra/host/host1x/hw_host1x01_sync.h

Quoted 1 line
drivers/video/tegra/host/host1x/hw_host1x01_sync.h +0 -0

Autogenerated files are generally not acceptable. And I already mentioned before that you should be using #define instead of static inline functions for register and bit definitions.

What's the root cause for autogenerated files not being acceptable? I'm autogenerating them from definitions I get from hardware, which makes the results reliable.

The problem is not with autogenerated files in general. The means by which they are generated are less important. However, autogenerated files often contain a lot of unneeded definitions and contain things such as "autogenerated - do not edit" lines.

So generally if you generate the content using some scripts to make sure it corresponds to what engineering gave you, that's okay as long as you make sure it has the correct form and doesn't contain any cruft.

Quoted 3 lines

I like static inline because I get the benefit of compiler type checking, and gcov shows me which register definitions have been used in different tests.

Type checking shouldn't be necessary for simple defines. And I wasn't aware that you could get the Linux kernel to write out data to be fed to gcov.

Quoted 3 lines

#defines are always messy and I pretty much hate them. But if the general request is to use #define's, even though I don't agree, I can accommodate. It's simple to write a sed script to do the conversion.

There are a lot of opportunities to abuse #defines but they are harmless for register definitions. The Linux kernel is full of them and I haven't yet seen any code that uses static inline functions for this purpose.

What you need to consider as well is that many people that work with the Linux kernel expect code to be in a certain style. Register accesses of the form

	writel(value, base + OFFSET);

are very common and expected to look a certain way, so if you write code that doesn't comply with these guidelines you make it extra hard for people to read the code. And that'll cost extra time, which people don't usually have in excess.

Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
drivers/video/tegra/host/host1x/hw_host1x01_sync.h +16 -0
+/* Displays the current value of the sync point via sysfs */
+static ssize_t syncpt_min_show(struct kobject *kobj,
+             struct kobj_attribute *attr, char *buf)
+{
+     struct nvhost_syncpt_attr *syncpt_attr =
+             container_of(attr, struct nvhost_syncpt_attr, attr);
+
+     return snprintf(buf, PAGE_SIZE, "%u",
+                     nvhost_syncpt_read(&syncpt_attr->host->syncpt,
+                             syncpt_attr->id));
+}
+
+static ssize_t syncpt_max_show(struct kobject *kobj,
+             struct kobj_attribute *attr, char *buf)
+{
+     struct nvhost_syncpt_attr *syncpt_attr =
Quoted 8 lines

drivers/video/tegra/host/host1x/hw_host1x01_sync.h

Quoted 6 lines
drivers/video/tegra/host/host1x/hw_host1x01_sync.h +6 -0
+             container_of(attr, struct nvhost_syncpt_attr, attr);
+
+     return snprintf(buf, PAGE_SIZE, "%u",
+                     nvhost_syncpt_read_max(&syncpt_attr->host->syncpt,
+                             syncpt_attr->id));
+}

This looks like it belongs in debugfs.

Quoted 3 lines

This is actually the only interface to read the max value to user space, which can be useful for doing some comparisons that take wrapping into account. But we could just add IOCTLs and remove the sysfs entries.

Maybe you can explain the usefulness of this some more. Why would it be easier to look at them in sysfs than in debugfs? You could be providing a simple list of syncpoints along with min/max, name, requested status, etc. in debugfs and it should be as easy to parse for both humans and machines as sysfs. I don't think IOCTLs would be any gain as they tend to have higher ABI stability requirements than debugfs (which doesn't have very strong requirements) or sysfs (which is often considered as a public ABI as well and therefore needs to be stable).

Quoted 76 lines
Quoted 67 lines
Quoted 1 line
include/linux/nvhost.h +0 -0

[...]

Quoted 65 lines
include/linux/nvhost.h +65 -0
+struct host1x_device_info {
+     int             nb_channels;    /* host1x: num channels supported */
+     int             nb_pts;         /* host1x: num syncpoints supported */
+     int             nb_bases;       /* host1x: num syncpoints supported */
+     u32             client_managed; /* host1x: client managed syncpts */
+     int             nb_mlocks;      /* host1x: number of mlocks */
+     const char      **syncpt_names; /* names of sync points */
+};
+
+struct nvhost_device_data {
+     int             version;        /* ip version number of device */
+     int             id;             /* Separates clients of same hw */
+     int             index;          /* Hardware channel number */
+     void __iomem    *aperture;      /* Iomem mapped to kernel */
+
+     u32             syncpts;        /* Bitfield of sync points used */
+     u32             modulemutexes;  /* Bit field of module mutexes */
+
+     u32             class;          /* Device class */
+     bool            serialize;      /* Serialize submits in the channel */
+
+     int             powergate_ids[NVHOST_MODULE_MAX_POWERGATE_IDS];
+     bool            can_powergate;  /* True if module can be power gated */
+     int             clockgate_delay;/* Delay before clock gated */
+     int             powergate_delay;/* Delay before power gated */
+     struct nvhost_clock clocks[NVHOST_MODULE_MAX_CLOCKS];/* Clock names */
+
+     struct delayed_work powerstate_down;/* Power state management */
+     int             num_clks;       /* Number of clocks opened for dev */
+     struct clk      *clk[NVHOST_MODULE_MAX_CLOCKS];
+     struct mutex    lock;           /* Power management lock */
+     int             powerstate;     /* Current power state */
+     int             refcount;       /* Number of tasks active */
+     wait_queue_head_t idle_wq;      /* Work queue for idle */
+
+     struct nvhost_channel *channel; /* Channel assigned for the module */
+     struct kobject *power_kobj;     /* kobj to hold power sysfs entries */
+     struct nvhost_device_power_attr *power_attrib;  /* sysfs attributes */
+     struct dentry *debugfs;         /* debugfs directory */
+
+     void *private_data;             /* private platform data */
+     struct platform_device *pdev;   /* owner platform_device */
+
+     /* Finalize power on. Can be used for context restore. */
+     void (*finalize_poweron)(struct platform_device *dev);
+
+     /* Device is busy. */
+     void (*busy)(struct platform_device *);
+
+     /* Device is idle. */
+     void (*idle)(struct platform_device *);
+
+     /* Device is going to be suspended */
+     void (*suspend_ndev)(struct platform_device *);
+
+     /* Device is initialized */
+     void (*init)(struct platform_device *dev);
+
+     /* Device is de-initialized. */
+     void (*deinit)(struct platform_device *dev);
+
+     /* Preparing for power off. Used for context save. */
+     int (*prepare_poweroff)(struct platform_device *dev);
+
+     /* Clock gating callbacks */
Quoted 8 lines

include/linux/nvhost.h line 126

Quoted 3 lines
include/linux/nvhost.h +3 -0
+     int (*prepare_clockoff)(struct platform_device *dev);
+     void (*finalize_clockon)(struct platform_device *dev);
+};

A lot of this can be removed if you use existing infrastructure and simplify the design a bit. Most of it can probably move into the main struct host1x to avoid needless indirections that make the code hard to follow and maintain.

Quoted 3 lines

Actually, this struct is generic for host1x and host1x clients, so they cannot be moved to host1x. I do also realize that I'm not using them in the patch sets I sent for 2D.

I've said this before, and I think that this tries to be overly generic. Display controllers for instance work quite well without an attached nvhost_channel.

Thierry

#132 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

In reply to Lucas Stach
Quoted 47 lines · Lucas Stach

Am Donnerstag, den 29.11.2012, 10:17 +0200 schrieb Terje Bergström:

Quoted 10 lines · Lucas Stach
Quoted 8 lines

Am Mittwoch, den 28.11.2012, 18:23 +0200 schrieb Terje Bergström:

Quoted 2 lines

Sorry. I promised in another thread a write-up explaining the design. I still owe you guys that.

That would be really nice to have. I'm also particularly interested in how you plan to do synchronization of command streams to different engines working together, if that's not too much to ask for now. Like userspace uploading a texture in a buffer, 2D engine doing mipmap generation, 3D engine using mipmapped texture.

Quoted 3 lines

I can briefly explain (and then copy-paste to a coherent text once I get to it) how inter-engine synchronization is done. It's not specifically for 2D or 3D, but generic to any host1x client.

[...]
Thanks for that.
[...]

Quoted 19 lines
Quoted 4 lines

2. Move the exposed DRM interface more in line with other DRM drivers. Please take a look at how for example the GEM_EXECBUF ioctl works on other drivers to get a feeling of what I'm talking about. Everything using the display, 2D and maybe later on the 3D engine should only deal

Quoted 8 lines

with GEM handles. I really don't like the idea of having a single userspace application, which uses engines with similar and known requirements (DDX) dealing with dma-buf handles or other similar high overhead stuff to do the most basic tasks.
If we move down the allocator into nvhost we can use buffers allocated from this to back GEM or V4L2 buffers transparently. The ioctl to allocate a GEM buffer shouldn't do much more than wrapping the nvhost buffer.

Ok, this is actually what we do downstream. We use dma-buf handles only for purposes where they're really needed (in fact, none yet), and use our downstream allocator handles for the rest. I did this, because benchmarks were showing that memory management overhead shoot through the roof if I tried doing everything via dma-buf.

Quoted 4 lines

We can move support for allocating GEM handles to nvhost, and GEM handles can be treated just as another memory handle type in nvhost. tegradrm would then call nvhost for allocation.

We should aim for a clean split here. GEM handles are something which is really specific to how DRM works and as such should be constructed by tegradrm. nvhost should really just manage allocations/virtual address space and provide something that is able to back all the GEM handle operations.

Quoted 4 lines

nvhost has really no reason at all to even know about GEM handles. If you back a GEM object by a nvhost object you can just peel out the nvhost handles from the GEM wrapper in the tegradrm submit ioctl handler and queue the job to nvhost using it's native handles.

That certainly sounds sensible to me. We would obviously no longer be able to reuse the CMA GEM helpers, but if it makes things easier to handle in general that's definitely something we can live with.

If I understand this correctly it would also allow us to do the buffer management within host1x and therefore allow the differences between Tegra20 (CMA) and Tegra30 (IOMMU) allocations to be handled in one central place. That would indeed make things a lot easier in the host1x client drivers.

Quoted 4 lines

This way you would also be able to construct different handles (like GEM obj or V4L2 buffers) from the same backing nvhost object. Note that I'm not sure how useful this would be, but it seems like a reasonable design to me being able to do so.

Wouldn't that be useful for sharing buffers between DRM and V4L2 using dma-buf? I'm not very familiar with how exactly importing and exporting work with dma-buf, so maybe I need to read up some more.

Thierry

#135 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

In reply to Lucas Stach
Quoted 11 lines · Lucas Stach

We should aim for a clean split here. GEM handles are something which is really specific to how DRM works and as such should be constructed by tegradrm. nvhost should really just manage allocations/virtual address space and provide something that is able to back all the GEM handle operations.

nvhost has really no reason at all to even know about GEM handles. If you back a GEM object by a nvhost object you can just peel out the nvhost handles from the GEM wrapper in the tegradrm submit ioctl handler and queue the job to nvhost using it's native handles.

Quoted 4 lines

This way you would also be able to construct different handles (like GEM obj or V4L2 buffers) from the same backing nvhost object. Note that I'm not sure how useful this would be, but it seems like a reasonable design to me being able to do so.

Ok, I must say that I got totally surprised by this and almost fell off the bench of the bus while commuting to home and reading this mail. On the technical side, what you wrote makes perfect sense and we'll go through this idea very carefully, so don't take me wrong.

What surprised me was that we had always assumed that nvmap, the allocator we use in downstream kernel, would never be something that would be accepted upstream, so we haven't done work at all on cleaning it up and refactoring it for upstreaming, and cutting ties between nvhost and nvmap. We assumed that we need to provide something that fit into tegradrm and interacts with dma_buf and GEM, so we've written something small that fulfills this need.

Now what you're suggesting is akin to getting a subset of nvmap into picture. In downstream kernel it already takes care of all memory management problems we've discussed wrt IOMMU (duplicate management, different memory architectures, etc). But, it has a lot more than what we need for now, so we'd need to decide if we go for importing parts of nvmap as nvhost allocator, or use the allocator in the patchset I sent earlier as basis.

Quoted 13 lines
Quoted 4 lines

Yep, this would definitely simplify our IOMMU problem. But, I thought the canonical way of dealing with device memory is DMA API, and you're saying that we should just bypass it and call IOMMU directly?

This is true for all standard devices. But we should not consider this as something set in stone and then building some crufty design around it. If we can manage to make our design a lot cleaner by managing DMA memory and the corresponding IOMMU address spaces for the host1x devices ourselves, I think this is the way to go. All other graphics drivers in the Linux kernel have to deal with their GTT in some way, we just happen to do so by using a shared system IOMMU and not something that is exclusive to the graphics devices.

Quoted 5 lines

This is more work on the side of nvhost, but IMHO the benefits make it look worthwhile.
What we should avoid is something that completely escapes the standard ways of dealing with memory used in the Linux kernel, like using carveout areas, but I think this is already consensus among us all.

Makes perfect sense. I'll need to hash out a proposal on how to go about this.

Terje

#33 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Terje Bergström
Quoted 1 line · Terje Bergström

On 28.11.2012 23:23, Thierry Reding wrote:

...

Quoted 16 lines
Quoted 8 lines

drivers/video/tegra/host/host1x/host1x.c line 82

Quoted 5 lines
drivers/video/tegra/host/host1x/host1x.c new file +5 -0
+     regs = platform_get_resource(dev, IORESOURCE_MEM, 0);
+     intr0 = platform_get_resource(dev, IORESOURCE_IRQ, 0);
+     intr1 = platform_get_resource(dev, IORESOURCE_IRQ, 1);
+
+     if (!regs || !intr0 || !intr1) {

I prefer to have these checked for explicitly, one by one for readability and potentially more useful diagnostics.

Can do.

Quoted 5 lines

Also you should be using platform_get_irq() for interrupts. Furthermore the host1x DT node (and the TRM) name the interrupts "syncpt" and "general", so maybe those would be more useful variable names than "intr0" and "intr1".

Quoted 5 lines
Quoted 2 lines

But since you don't use them anyway they shouldn't be part of this patch.

True. I might also as well delete the general interrupt altogether, as we don't use it for any real purpose.

Do make sure the interrupts still are part of the DT binding though, so that the binding fully describes the HW, and the interrupt is available to retrieve if we ever do use it in the future.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/video/tegra/host/host1x/host1x.c new file +5 -0
+     for (i = 0; i < pdata->num_clks; i++)
+             clk_prepare_enable(pdata->clk[i]);
+     nvhost_syncpt_reset(&host->syncpt);
+     for (i = 0; i < pdata->num_clks; i++)
+             clk_disable_unprepare(pdata->clk[i]);
Quoted 7 lines
Quoted 2 lines

Stephen already hinted at this when discussing the AUXDATA. You should explicitly request the clocks.

I'm not too happy about that idea. The clock management code is generic for all modules, and that's why it's driven by a data structure. Now Stephen and you ask me to unroll the loops and make copies of the code to facilitate different modules and different SoCs.

You can still create tables of clocks inside the driver and loop over them. So, loop unrolling isn't related to my comments at least. It's just that clk_get() shouldn't take its parameters from platform data.

But if these are clocks for (arbitrary) child modules (that may or may not exist dynamically), why aren't the drivers for the child modules managing them?

#6 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Thierry Reding
Quoted 22 lines · Thierry Reding
Quoted 9 lines · Terje Bergström
Quoted 7 lines · Thierry Reding

This could be problematic. Since drivers/video and drivers/gpu/drm are separate trees, this would entail a continuous burden on keeping both trees synchronized. While I realize that eventually it might be better to put the host1x driver in a separate place to accomodate for its use by other subsystems, I'm not sure moving it here right away is the best approach.

Quoted 6 lines

I understand your point, but I hope also that we'd end up with something that can be used as basis for the downstream kernel to migrate to upstream stack.

The key point here is to make the API between nvhost and tegradrm as small and robust to changes as possible.

I agree. But I also fear that there will be changes eventually and having both go in via different tree requires those trees to be merged in a specific order to avoid breakage should the API change. This will be particularly ugly in linux-next.

Quoted 6 lines

That's why I explicitly proposed to take this into drivers/gpu/drm/tegra for the time being, until we can be reasonably sure that the API is fixed. Then I'm fine with moving it wherever seems the best fit. Even then there might be the occasional dependency, but they should get fewer and fewer as the code matures.

It is acceptable for one maintainer to ack patches, and another maintainer to merge a series that touches both "their own" code and code owned by another tree. This should of course only be needed when inter-module APIs change; changes to code within a module shouldn't require this.

#44 lore raw

Re: [RFC v2 2/8] video: tegra: Add syncpoint wait and interrupts

In reply to Thierry Reding
Quoted 20 lines · Thierry Reding
Quoted 2 lines · Terje Bergstrom
drivers/video/tegra/host/host1x/host1x_intr.c +0 -0

[...]

Quoted 1 line

+/* Spacing between sync registers */ +#define REGISTER_STRIDE 4

Erm... no. The usual way you should be doing this is either make the register definitions account for the stride or use accessors that apply the stride. You should be doing the latter anyway to make accesses. For example:

static inline void host1x_syncpt_writel(struct host1x *host1x, unsigned long value, unsigned long offset) { writel(value, host1x->regs + SYNCPT_BASE + offset); }

static inline unsigned long host1x_syncpt_readl(struct host1x *host1x, unsigned long offset) { return readl(host1x->regs + SYNCPT_BASE + offset); }

Quoted 6 lines

Alternatively, if you want to pass the register index instead of the offset, you can use just multiply the offset in that function:

writel(value, host1x->regs + SYNCPT_BASE + (offset << 2));

The same can also be done with the non-syncpt registers.

It seems like reasonable documentation to replace "<< 2" with "* REGISTER_STRIDE" here.

#49 lore raw

Re: [RFC,v2,3/8] video: tegra: host: Add channel and client support

In reply to Terje Bergström
Quoted 7 lines · Terje Bergström
Quoted 2 lines · Mark Zhang

Just for curious, why "pb->mapped + 1K" is the end of a 4K pushbuffer?

pb->mapped is u32 *, so compiler will take care of multiplying by sizeof(u32).

Ah, yes. Sorry, I must be insane at that time. :)

Quoted 27 lines
Quoted 18 lines
Quoted 18 lines
drivers/video/tegra/host/nvhost_cdma.c new file +18 -0
+unsigned int nvhost_cdma_wait_locked(struct nvhost_cdma *cdma,
+		enum cdma_event event)
+{
+	for (;;) {
+		unsigned int space = cdma_status_locked(cdma, event);
+		if (space)
+			return space;
+
+		/* If somebody has managed to already start waiting, yield */
+		if (cdma->event != CDMA_EVENT_NONE) {
+			mutex_unlock(&cdma->lock);
+			schedule();
+			mutex_lock(&cdma->lock);
+			continue;
+		}
+		cdma->event = event;
+
+		mutex_unlock(&cdma->lock);
Quoted 8 lines

drivers/video/tegra/host/nvhost_cdma.c line 108

Quoted 2 lines
drivers/video/tegra/host/nvhost_cdma.c new file +2 -0
+		down(&cdma->sem);
+		mutex_lock(&cdma->lock);

I'm newbie of nvhost but I feel here is very tricky, about the lock and unlock of this mutex: cdma->lock. Does it require this mutex is locked before calling this function? And do we need to unlock it before the
code: "return space;" above? IMHO, this is not a good design and can we find out a better solution?

Quoted 9 lines

Yeah, it's not perfect and good solutions are welcome. cdma_status_locked() must be called with a mutex. But, what we generally wait for is for space in push buffer. The cleanup code cannot run if we keep cdma->lock, so I release it.

The two ways to loop are because there was a race between two processes waiting for space. One of them set cdma->event to indicate what it's waiting for and can go to sleep, but the other has to keep spinning.

Alright. I just feel this mutex operations is complicated and error-prone, but I just get the big picture of nvhost and still don't know much about a lot of details. So I'll let you know if I find some better solutions.

Quoted 2 lines

Terje

#34 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Stephen Warren
Quoted 7 lines · Stephen Warren
Quoted 2 lines · Terje Bergström

True. I might also as well delete the general interrupt altogether, as we don't use it for any real purpose.

Do make sure the interrupts still are part of the DT binding though, so that the binding fully describes the HW, and the interrupt is available to retrieve if we ever do use it in the future.

Sure, I will just not use the generic irq in DT, but it won't require any changes in DT bindings.

Quoted 7 lines

You can still create tables of clocks inside the driver and loop over them. So, loop unrolling isn't related to my comments at least. It's just that clk_get() shouldn't take its parameters from platform data.

But if these are clocks for (arbitrary) child modules (that may or may not exist dynamically), why aren't the drivers for the child modules managing them?

There are actually two things here that I mixed, and because of that I probably confused everybody else.

Let's rip out the ACM. ACM is generic to all modules, and in nvhost owns the clocks. That's why list of clocks and their frequency policies have been part of the device description in nvhost. ACM is being replaced with runtime PM in downstream kernel, but it still requires rigorous testing and analysis of power profile before we can move to it.

Then, the second thing is that nvhost_probe() has had its own loop to go through the clocks of host1x module. It's copy-paste of what ACM did, which is just bad design. That's easily replaceable with static code, as nvhost_probe() is just for host1x. I'll do that, and as I rip out the generic power management code, I'll also make 2D and host1x drivers enable the clocks at probe with static code.

So I think we have a solution that resonates with all proposals.

Best regards,
Terje

#7 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Stephen Warren
Quoted 30 lines · Stephen Warren
Quoted 22 lines · Thierry Reding
Quoted 9 lines · Terje Bergström
Quoted 7 lines · Thierry Reding

This could be problematic. Since drivers/video and drivers/gpu/drm are separate trees, this would entail a continuous burden on keeping both trees synchronized. While I realize that eventually it might be better to put the host1x driver in a separate place to accomodate for its use by other subsystems, I'm not sure moving it here right away is the best approach.

Quoted 6 lines

I understand your point, but I hope also that we'd end up with something that can be used as basis for the downstream kernel to migrate to upstream stack.

The key point here is to make the API between nvhost and tegradrm as small and robust to changes as possible.

I agree. But I also fear that there will be changes eventually and having both go in via different tree requires those trees to be merged in a specific order to avoid breakage should the API change. This will be particularly ugly in linux-next.

Quoted 6 lines

That's why I explicitly proposed to take this into drivers/gpu/drm/tegra for the time being, until we can be reasonably sure that the API is fixed. Then I'm fine with moving it wherever seems the best fit. Even then there might be the occasional dependency, but they should get fewer and fewer as the code matures.

Quoted 5 lines

It is acceptable for one maintainer to ack patches, and another maintainer to merge a series that touches both "their own" code and code owned by another tree. This should of course only be needed when inter-module APIs change; changes to code within a module shouldn't require this.

Yes, that's true. But it still makes things more complicated since each of the maintainers will have to do extra work to test the changes. Anyway we'll see how this plays out. The ideal case would of course be to get the API right from the start. =)

Thierry

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#35 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Terje Bergström
Quoted 29 lines · Terje Bergström
Quoted 7 lines · Stephen Warren
Quoted 2 lines · Terje Bergström

True. I might also as well delete the general interrupt altogether, as we don't use it for any real purpose.

Do make sure the interrupts still are part of the DT binding though, so that the binding fully describes the HW, and the interrupt is available to retrieve if we ever do use it in the future.

Sure, I will just not use the generic irq in DT, but it won't require any changes in DT bindings.

Quoted 7 lines

You can still create tables of clocks inside the driver and loop over them. So, loop unrolling isn't related to my comments at least. It's just that clk_get() shouldn't take its parameters from platform data.

But if these are clocks for (arbitrary) child modules (that may or may not exist dynamically), why aren't the drivers for the child modules managing them?

There are actually two things here that I mixed, and because of that I probably confused everybody else.

Let's rip out the ACM. ACM is generic to all modules, and in nvhost owns the clocks. That's why list of clocks and their frequency policies have been part of the device description in nvhost. ACM is being replaced with runtime PM in downstream kernel, but it still requires rigorous testing and analysis of power profile before we can move to it.

Quoted 8 lines

Then, the second thing is that nvhost_probe() has had its own loop to go through the clocks of host1x module. It's copy-paste of what ACM did, which is just bad design. That's easily replaceable with static code, as nvhost_probe() is just for host1x. I'll do that, and as I rip out the generic power management code, I'll also make 2D and host1x drivers enable the clocks at probe with static code.

So I think we have a solution that resonates with all proposals.

Yes, that sounds good to me.

Thierry

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#42 lore raw

Re: [RFC v2 2/8] video: tegra: Add syncpoint wait and interrupts

In reply to Terje Bergström
Quoted 17 lines · Terje Bergström
Quoted 16 lines · Thierry Reding

drivers/video/tegra/host/dev.c u32 host1x_syncpt_read(u32 id) · line 46

Quoted 9 lines
drivers/video/tegra/host/dev.c +1 -0
index 98c9c9f..025a820 100644
@@ -43,6 +43,13 @@ u32 host1x_syncpt_read(u32 id)
 }
 EXPORT_SYMBOL(host1x_syncpt_read);
 
+int host1x_syncpt_wait(u32 id, u32 thresh, u32 timeout, u32 *value)

The choice of data types is odd here. id refers to a syncpt so a better choice would have been unsigned int because the size of the variable doesn't actually matter. But as I already said in my reply to patch 1, these are resources and should therefore better be abstracted through an opaque pointer anyway.

Quoted 6 lines
Quoted 3 lines

timeout is usually signed long, so this function should reflect that. As for the value this is probably fine as it will effectively be set from a register value. Though you also cache them in software using atomics.

32-bits is an architectural limit for the sync point id, so that's why I used it here.

But given that there are only 32 syncpoints they look rather costly, so I don't expect more than a few hundred to ever be used in hardware, right?

Quoted 2 lines

But you're right - it doesn't really matter and could be changed to unsigned long.

I'd still opt for unsigned int. For no other reason than that it is how other types of resources are enumerated.

Quoted 2 lines

thresh and *value reflects that sync point value is 32-bit, and I'd keep that as is.

Yes, that makes sense.

Quoted 1 line

Timeout should be unsigned long, yes.

It should actually be signed long to match the type used for timeouts in the various wait_*() functions.

Quoted 34 lines
Quoted 34 lines
Quoted 1 line
drivers/video/tegra/host/host1x/host1x_intr.c +0 -0

[...]

drivers/video/tegra/host/host1x/host1x_intr.c line 31

Quoted 10 lines
drivers/video/tegra/host/host1x/host1x_intr.c +10 -0
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/io.h>
+#include <asm/mach/irq.h>
+
+#include "nvhost_intr.h"
+#include "host1x/host1x.h"
+
+/* Spacing between sync registers */
+#define REGISTER_STRIDE 4

Erm... no. The usual way you should be doing this is either make the register definitions account for the stride or use accessors that apply the stride. You should be doing the latter anyway to make accesses. For example:

        static inline void host1x_syncpt_writel(struct host1x *host1x,
                                                unsigned long value,
                                                unsigned long offset)
        {
                writel(value, host1x->regs + SYNCPT_BASE + offset);
        }

        static inline unsigned long host1x_syncpt_readl(struct host1x *host1x,
                                                        unsigned long offset)
        {
                return readl(host1x->regs + SYNCPT_BASE + offset);
        }

Alternatively, if you want to pass the register index instead of the offset, you can use just multiply the offset in that function:

Quoted 7 lines
Quoted 3 lines
        writel(value, host1x->regs + SYNCPT_BASE + (offset << 2));

The same can also be done with the non-syncpt registers.

The register number has a stride of 4 when doing writes, and 1 when adding to command streams. This is why I've kept the register definitions as is.

Yes, that's why it makes sense to use such helpers. It allows you to reuse the register definitions for both direct and indirect access but doesn't require you to repeat the stride multiplication every time.

Quoted 3 lines

I could add helper functions. Just as a side note, the sync register space has other definitions than just the syncpt registers, so the naming should be changed a bit.

The TRM refers to them as SYNC registers, so SYNC_BASE should be fine.

Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
drivers/video/tegra/host/host1x/host1x_intr.c +19 -0
+static irqreturn_t syncpt_thresh_cascade_isr(int irq, void *dev_id)
+{
+     struct nvhost_master *dev = dev_id;
+     void __iomem *sync_regs = dev->sync_aperture;
+     struct nvhost_intr *intr = &dev->intr;
+     unsigned long reg;
+     int i, id;
+
+     for (i = 0; i < dev->info.nb_pts / BITS_PER_LONG; i++) {
+             reg = readl(sync_regs +
+                             host1x_sync_syncpt_thresh_cpu0_int_status_r() +
+                             i * REGISTER_STRIDE);
+             for_each_set_bit(id, &reg, BITS_PER_LONG) {
+                     struct nvhost_intr_syncpt *sp =
+                             intr->syncpt + (i * BITS_PER_LONG + id);
+                     host1x_intr_syncpt_thresh_isr(sp);
+                     queue_work(intr->wq, &sp->work);
+             }
+     }
Quoted 8 lines

drivers/video/tegra/host/host1x/host1x_intr.c line 63

Quoted 3 lines
drivers/video/tegra/host/host1x/host1x_intr.c +3 -0
+
+     return IRQ_HANDLED;
+}

Maybe it would be better to call the syncpt handlers in interrupt context and let them schedule work if they want to. I'm thinking about the display controllers which may want to use syncpoints for VBLANK support.

Quoted 2 lines

Display controller can use the APIs to read, increment and wait for sync point.

Actually for the display controller we want just a notification when the VBLANK happens. I'm not sure if we want to do that with syncpoints at all since it works quite well using regular interrupts.

Quoted 3 lines

We could do more in isr, but then again, we've noticed that the current design already gives pretty good latency, so we haven't seen the need to move code from thread to isr.

What I'm proposing is to leave it up to each host1x client how they want to handle this. For display controllers it may be enough to have their callback run in interrupt context but other clients may need to do more work so they can queue it themselves.

I know that this looks like it might be more work, but if it turns out that many drivers need to do the exact same thing, that functionality can be factored out into a helper. But it may just as well turn out that the requirements for each module are slightly different that forcing a workqueue on them could result in ugly workarounds because it doesn't quite work for them.

Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
drivers/video/tegra/host/host1x/host1x_intr.c +14 -0
+/**
+ * Sync point threshold interrupt service function
+ * Handles sync point threshold triggers, in interrupt context
+ */
+static void host1x_intr_syncpt_thresh_isr(struct nvhost_intr_syncpt *syncpt)
+{
+     unsigned int id = syncpt->id;
+     struct nvhost_intr *intr = intr_syncpt_to_intr(syncpt);
+
+     void __iomem *sync_regs = intr_to_dev(intr)->sync_aperture;
+
+     u32 reg = BIT_WORD(id) * REGISTER_STRIDE;
+
+     writel(BIT_MASK(id), sync_regs +
Quoted 8 lines

drivers/video/tegra/host/host1x/host1x_intr.c line 173

Quoted 4 lines
drivers/video/tegra/host/host1x/host1x_intr.c +4 -0
+             host1x_sync_syncpt_thresh_int_disable_r() + reg);
+     writel(BIT_MASK(id), sync_regs +
+             host1x_sync_syncpt_thresh_cpu0_int_status_r() + reg);
+}

So this disables all interrupts and is called from the syncpt interrupt handler. Where are the interrupts reenabled? Do host1x clients have to do that manually?

Quoted 2 lines

The thread re-enables once it's done. It checks the next value we're interested in, and programs that to host1x syncpt threshold.

Okay, that does make sense now. I think I'm indeed beginning to understand how the hardware works...

Quoted 5 lines
Quoted 3 lines

Okay, so this is where syncpoint interrupts are reenabled. The rest of this whole wait queue code looks overly complex. I'll need to go through that separately and more thoroughly.

Thanks.

If we move responsibility of managing the workqueue out of host1x as I proposed above, maybe a lot of this code can be removed. Maybe you can explain a bit what they are used for exactly in your write-up.

Thierry

#45 lore raw

Re: [RFC v2 2/8] video: tegra: Add syncpoint wait and interrupts

In reply to Stephen Warren
Quoted 24 lines · Stephen Warren
Quoted 23 lines · Thierry Reding
Quoted 2 lines · Terje Bergstrom
drivers/video/tegra/host/host1x/host1x_intr.c +0 -0

[...]

Quoted 1 line

+/* Spacing between sync registers */ +#define REGISTER_STRIDE 4

Erm... no. The usual way you should be doing this is either make the register definitions account for the stride or use accessors that apply the stride. You should be doing the latter anyway to make accesses. For example:

static inline void host1x_syncpt_writel(struct host1x *host1x, unsigned long value, unsigned long offset) { writel(value, host1x->regs + SYNCPT_BASE + offset); }

static inline unsigned long host1x_syncpt_readl(struct host1x *host1x, unsigned long offset) { return readl(host1x->regs + SYNCPT_BASE + offset); }

Alternatively, if you want to pass the register index instead of the offset, you can use just multiply the offset in that function:

Quoted 6 lines
Quoted 3 lines

writel(value, host1x->regs + SYNCPT_BASE + (offset << 2));

The same can also be done with the non-syncpt registers.

It seems like reasonable documentation to replace "<< 2" with "* REGISTER_STRIDE" here.

Given that it is a very common pattern, << 2 seems enough documentation to me, but sure, if you prefer to be extra explicit that's fine with me.

Thierry

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#43 lore raw

Re: [RFC v2 2/8] video: tegra: Add syncpoint wait and interrupts

In reply to Thierry Reding

Just replying to part of your mail.

Quoted 3 lines · Thierry Reding

Actually for the display controller we want just a notification when the VBLANK happens. I'm not sure if we want to do that with syncpoints at all since it works quite well using regular interrupts.

VBLANK isn't actually a very good example of dc's use of sync points. That can easily be done with regular interrupts, as you mention.

More important is when we have double buffering enabled. When you draw something to a surface, and flip it to display, you want DC to notify when the flip has been done and rendering can continue to the back buffer.

So, what you can do is return a fence from DC when initiating a flip, and place that fence into 2D stream as a host wait so that 2D will patiently wait for buffer to become free before it renders.

Quoted 4 lines

What I'm proposing is to leave it up to each host1x client how they want to handle this. For display controllers it may be enough to have their callback run in interrupt context but other clients may need to do more work so they can queue it themselves.

DC doesn't need to worry about host1x interrupts at all. It's all internal to the host1x driver, so we're now just talking about the internal implementation of host1x.

We have two scenarios for the syncpt interrupts. One is that a job got finished and we need to clean up the queue and free up resources. This must be done in threads. Other is releasing a thread that is blocked by a syncpt wait.

It's simpler if both of these are handled with the same infrastructure, and we've shown that latency is very good even if we handle all events in a thread.

Quoted 6 lines

I know that this looks like it might be more work, but if it turns out that many drivers need to do the exact same thing, that functionality can be factored out into a helper. But it may just as well turn out that the requirements for each module are slightly different that forcing a workqueue on them could result in ugly workarounds because it doesn't quite work for them.

This is just driver internal, so there's no need for other drivers to access this part.

Quoted 3 lines

If we move responsibility of managing the workqueue out of host1x as I proposed above, maybe a lot of this code can be removed. Maybe you can explain a bit what they are used for exactly in your write-up.

It's going to be a big bad boy. :-)

Terje

#133 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

In reply to Thierry Reding
Quoted 9 lines · Thierry Reding
Quoted 4 lines · Lucas Stach

This way you would also be able to construct different handles (like GEM obj or V4L2 buffers) from the same backing nvhost object. Note that I'm not sure how useful this would be, but it seems like a reasonable design to me being able to do so.

Wouldn't that be useful for sharing buffers between DRM and V4L2 using dma-buf? I'm not very familiar with how exactly importing and exporting work with dma-buf, so maybe I need to read up some more.

I would still preserve the dma-buf support, for exactly this purpose.

Terje

#52 lore raw

Re: [RFC v2 3/8] video: tegra: host: Add channel and client support

In reply to Terje Bergström
Quoted 5 lines · Terje Bergström
Quoted 3 lines · Thierry Reding

Looking some more at how this is used, I'm starting to think that it might be easier to export the various handlers and allow them to be passed to the nvhost_intr_add_action() explicitly.

Quoted 7 lines

Oh, so you mean like "nvhost_intr_add_action(intr, id, threshold, nvhost_intr_action_submit_complete, channel, waiter, priv), and nvhost_intr_action_submit_complete is the function pointer?

There's one case to take care of: we merge the waits for the jobs into one waiter to save us from having too many irq calls. Perhaps that could be handled by a flag, or something like that.

Yes, something like ACTION_MERGE or something should work fine. Alternatively you could handle it by providing two public functions, one which adds to the list of jobs that can be merged, the other that adds to the list that cannot be merged.

Quoted 12 lines
Quoted 11 lines

drivers/video/tegra/host/nvhost_job.c line 93

Quoted 9 lines
drivers/video/tegra/host/nvhost_job.c new file +9 -0
+struct nvhost_job *nvhost_job_alloc(struct nvhost_channel *ch,
+             int num_cmdbufs, int num_relocs, int num_waitchks)
+{
+     struct nvhost_job *job = NULL;
+     size_t size = job_size(num_cmdbufs, num_relocs, num_waitchks);
+
+     if (!size)
+             return NULL;
+     job = vzalloc(size);

Why vzalloc()?

Quoted 3 lines

I guess it's basically moot, but we tried that when we had some memory fragmentation issues and it was left even though we did find out it's not needed.

I think kzalloc() would be a better choice here. Also, while at it you may want to make the num_* parameters unsigned.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/video/tegra/host/nvhost_job.c new file +5 -0
+     }
+
+     /* get current syncpt values for waitchk */
+     for_each_set_bit(i, &waitchk_mask[0], sizeof(waitchk_mask))
+             nvhost_syncpt_update_min(sp, i);
Quoted 6 lines
Quoted 2 lines

Or since you only use the mask here, why not move the nvhost_syncpt_update_min() into the above loop?

I want to call nvhost_syncpt_update_min() only once per syncpt register. If the job has 100 sync point increments for 2D sync point, I'd read the value from hardware 100 times, which is expensive.

Right, hadn't thought about the fact that you can have multiple waits for a single syncpoint in the job.

Looking at the code again, I see that you use sizeof(waitchk_mask) as the third parameter to the for_each_set_bit() macro. However the size parameter is to be specified in bits, not bytes.

Also the name nvhost_syncpt_update_min() has had me confused. So say it is used to update the value that you've cached in software from the real value in the register. However I interpret update_min() as "update the minimum value in the register". Maybe something like *_load_min() would be clearer.

Quoted 2 lines

Thanks. I've collected a massive amount of feedback already. v3 will take quite a while to appear after we've finished all the reviews of v2.

Yes, that should keep you busy for quite a while. =) But I also think we've made good progress so far.

Thierry

#134 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

In reply to Terje Bergström

Am Freitag, den 30.11.2012, 09:44 +0200 schrieb Terje Bergström:

Quoted 7 lines · Thierry Reding
Quoted 6 lines · Lucas Stach
Quoted 4 lines

This way you would also be able to construct different handles (like GEM obj or V4L2 buffers) from the same backing nvhost object. Note that I'm not sure how useful this would be, but it seems like a reasonable design to me being able to do so.

Quoted 6 lines
Quoted 3 lines

Wouldn't that be useful for sharing buffers between DRM and V4L2 using dma-buf? I'm not very familiar with how exactly importing and exporting work with dma-buf, so maybe I need to read up some more.

I would still preserve the dma-buf support, for exactly this purpose.

dma-buf is useful and should be preserved, as some userspace like gstreamer might rely on us being able to import/export dma-buf handles at some time. At the very latest we'll need it if someone wants to run a UDL device to scanout a buffer rendered to by the internal GPU.

What I'm saying is just that with a common allocator we could cut down a lot on the usage of dma-buf, where not really necessary. Also you might be able to do some optimisations based on the fact that a dma-buf handle exported for some V4L2 buffer, which gets imported into DRM to construct a GEM object, is the very same nvhost object in the end.

Regards,
Lucas

#8 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Stephen Warren

Am Donnerstag, den 29.11.2012, 11:38 -0700 schrieb Stephen Warren:

Quoted 13 lines · Thierry Reding
Quoted 11 lines

I agree. But I also fear that there will be changes eventually and having both go in via different tree requires those trees to be merged in a specific order to avoid breakage should the API change. This will be particularly ugly in linux-next.

That's why I explicitly proposed to take this into drivers/gpu/drm/tegra for the time being, until we can be reasonably sure that the API is fixed. Then I'm fine with moving it wherever seems the best fit. Even then there might be the occasional dependency, but they should get fewer and fewer as the code matures.

Quoted 6 lines

It is acceptable for one maintainer to ack patches, and another maintainer to merge a series that touches both "their own" code and code owned by another tree. This should of course only be needed when inter-module APIs change; changes to code within a module shouldn't require this.

I'm with Thierry here. I think there is a fair chance that we won't get the API right from the start, even when trying to come up with something that sounds sane to everyone. It's also not desirable to delay gr2d going into mainline until we are all completely satisfied with the API.

I also fail to see how host1x module being in the DRM directory hinders any downstream development. So I'm in favour of keeping host1x besides the other DRM components to lower the burden for API changes and move it out into some more generic directory, once we feel confident that the API is reasonable stable.

Regards,
Lucas

#19 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Thierry Reding
Quoted 10 lines · Thierry Reding
Quoted 2 lines · Terje Bergström

Tegra20 and Tegra30 are compatible, but future chips are not. I was hoping we would be ready in upstream kernel for future chips.

I think we should ignore that problem for now. Generally planning for any possible combination of incompatibilities leads to overgeneralized designs that require precisely these kinds of indirections.

Once some documentation for Tegra 40 materializes we can start thinking about how to encapsulate the incompatible code.

I think here our perspectives differ a lot. That is natural considering the company I work for and company you work for, so let's try to sync the perspective.

In my reality, whatever is in market is old news and I barely work on them anymore. Upstreaming activity is the exception. 90% of my time is spent dealing with future chips which I know cannot be handled without this split to logical and physical driver parts.

For you, Tegra2 and Tegra3 are the reality.

If we move nvhost in upstream a bit incompatible, that's fine, like ripping out features or adding new new stuff, like a new memory type. All of this I can support with a good diff tool to get all the patches flowing between upstream and downstream.

If we do fundamental changes that prevent bringing the code back to downstream, like removing this abstraction, the whole process of upstream and downstream converging hits a brick wall. We wouldn't have proper continuing co-operation, but just pushing code out and being done with it.

Quoted 4 lines

I noticed that it was filled with content in one of the subsequent patches. Depending on how this gets merged eventually you could postpone adding the function until the later patch. But perhaps once the code has been properly reviewed we can just squash the patches again. We'll see.

Ok, thanks.

Quoted 6 lines
Quoted 2 lines

True. I might also as well delete the general interrupt altogether, as we don't use it for any real purpose.

I think it might still be useful for diagnostics. It seems to be used when writes time out. That could still be helpful information when debugging problems.

It's actually a stale comment. The client units are not signaling anything useful with the interrupt. There's use for it in downstream, but that's irrelevant here.

Quoted 9 lines

Making this generic for all modules may not be what we want as it doesn't allow devices to handle things themselves if necessary. Clock management is just part of the boiler plate that every driver is supposed to cope with. Also the number of clocks is usually not higher than 2 or 3, so the pain is manageable. =)

Furthermore doing this in loops may not work for all modules. Some may require additional delays between enabling the clocks, others may be able to selectively disable one clock but not the other(s).

Yes, but I'll just rip the power management code out, so we can postpone this until we have validated and verified the runtime PM mechanism downstream.

Quoted 7 lines
Quoted 3 lines

I could move this to debug.c, but it's debugging aid when a command stream is misbehaving and it spews this to UART when sync point wait is timing out. So not debugfs stuff.

Okay, in that case it should stay in. Perhaps convert dev_info() to dev_dbg(). Perhaps wrapping it in some #ifdef CONFIG_TEGRA_HOST1X_DEBUG guards would also be useful. Maybe not.

I could do that for upstream. In downstream it cannot depend on DEBUG flag, as these spews are an important part of how we debug problems with customer devices and the DEBUG flag is never on in customer builds.

Quoted 8 lines

The problem is not with autogenerated files in general. The means by which they are generated are less important. However, autogenerated files often contain a lot of unneeded definitions and contain things such as "autogenerated - do not edit" lines.

So generally if you generate the content using some scripts to make sure it corresponds to what engineering gave you, that's okay as long as you make sure it has the correct form and doesn't contain any cruft.

I can remove the boilerplate, that's not a problem. In general, we have tried to be very selective about what we generate, so that it matches what we're using.

Quoted 8 lines
Quoted 3 lines

I like static inline because I get the benefit of compiler type checking, and gcov shows me which register definitions have been used in different tests.

Type checking shouldn't be necessary for simple defines. And I wasn't aware that you could get the Linux kernel to write out data to be fed to gcov.

Quoted 7 lines
Quoted 3 lines

#defines are always messy and I pretty much hate them. But if the general request is to use #define's, even though I don't agree, I can accommodate. It's simple to write a sed script to do the conversion.

There are a lot of opportunities to abuse #defines but they are harmless for register definitions. The Linux kernel is full of them and I haven't yet seen any code that uses static inline functions for this purpose.

My problem is just that I know that the code generated is the same. What we're talking about is that should we let the preprocessor or compiler take care of this.

My take is that using preprocessor is not wise - it's the last resort if there's no other proper way of doing things. Preprocessor requires all sorts of extra parenthesis to protect against its deficiencies, and it it merely a tool to do search-and-replace. Even multi-line needs special treatment.

Quoted 10 lines

What you need to consider as well is that many people that work with the Linux kernel expect code to be in a certain style. Register accesses of the form

        writel(value, base + OFFSET);

are very common and expected to look a certain way, so if you write code that doesn't comply with these guidelines you make it extra hard for people to read the code. And that'll cost extra time, which people don't usually have in excess.

But this has nothing to do with static inline vs. #define anymore, right?

Quoted 8 lines

Maybe you can explain the usefulness of this some more. Why would it be easier to look at them in sysfs than in debugfs? You could be providing a simple list of syncpoints along with min/max, name, requested status, etc. in debugfs and it should be as easy to parse for both humans and machines as sysfs. I don't think IOCTLs would be any gain as they tend to have higher ABI stability requirements than debugfs (which doesn't have very strong requirements) or sysfs (which is often considered as a public ABI as well and therefore needs to be stable).

debugfs is just a debugging tool, and user space cannot rely on it. Only developers can rely on existence of debugfs, as they have the means to enable it.

sysfs is a place for actual APIs as you mention, and user space can rely on them as proper APIs. That's what the values were exported for.

Quoted 3 lines

I've said this before, and I think that this tries to be overly generic. Display controllers for instance work quite well without an attached nvhost_channel.

Yes, these structures aren't meant to be used by anything else than units that are controlled by the host1x driver. DC, for example, wouldn't have this.

Terje
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#20 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

Quoted 16 lines · Terje Bergström
Quoted 10 lines · Thierry Reding
Quoted 2 lines · Terje Bergström

Tegra20 and Tegra30 are compatible, but future chips are not. I was hoping we would be ready in upstream kernel for future chips.

I think we should ignore that problem for now. Generally planning for any possible combination of incompatibilities leads to overgeneralized designs that require precisely these kinds of indirections.

Once some documentation for Tegra 40 materializes we can start thinking about how to encapsulate the incompatible code.

I think here our perspectives differ a lot. That is natural considering the company I work for and company you work for, so let's try to sync the perspective.

Quoted 6 lines

In my reality, whatever is in market is old news and I barely work on them anymore. Upstreaming activity is the exception. 90% of my time is spent dealing with future chips which I know cannot be handled without this split to logical and physical driver parts.

For you, Tegra2 and Tegra3 are the reality.

To be fair, Tegra2 and Tegra3 are the reality for *everyone* *outside* NVIDIA.

It's great that you spend most of your time working with future chips, but unless you submit the code for inclusion or review nobody upstream needs to be concerned about the implications. Most people don't have time to waste so we naturally try to keep the maintenance burden to a minimum.

The above implies that when you submit code it shouldn't contain pieces that prepare for possible future extensions which may or may not be submitted (the exception being if such changes are part of a series where subsequent patches actually use them). The outcome is that the amount of cruft in the mainline kernel is kept to a minimum. And that's a very good thing.

Quoted 10 lines

If we move nvhost in upstream a bit incompatible, that's fine, like ripping out features or adding new new stuff, like a new memory type. All of this I can support with a good diff tool to get all the patches flowing between upstream and downstream.

If we do fundamental changes that prevent bringing the code back to downstream, like removing this abstraction, the whole process of upstream and downstream converging hits a brick wall. We wouldn't have proper continuing co-operation, but just pushing code out and being done with it.

Generally upstream doesn't concern itself with downstream. However we still willingly accept code that is submitted for upstream inclusion independent of where it comes from. The only requirements are that the code conforms to the established standards and has gone through an appropriate amount of review. Downstream maintenance is up to you. If you need to maintain code that doesn't meet the above requirements or that you don't want to submit or haven't got around to yet that's your problem.

If you're serious about wanting to derive your downstream kernel from a mainline kernel, then the only realistic way for you to reduce your amount of work is to push your code upstream. And typically the earlier you do so, the better.

Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

I could move this to debug.c, but it's debugging aid when a command stream is misbehaving and it spews this to UART when sync point wait is timing out. So not debugfs stuff.

Okay, in that case it should stay in. Perhaps convert dev_info() to dev_dbg(). Perhaps wrapping it in some #ifdef CONFIG_TEGRA_HOST1X_DEBUG guards would also be useful. Maybe not.

I could do that for upstream. In downstream it cannot depend on DEBUG flag, as these spews are an important part of how we debug problems with customer devices and the DEBUG flag is never on in customer builds.

So I've just looked through these patches once more and I can't find where this functionality is actually used. The host1x_syncpt_debug() function is assigned to the nvhost_syncpt_ops.debug member, which in turn is only used by nvhost_syncpt_debug(). The latter, however is never used (not even by the debug infrastructure introduced in patch 4).

Quoted 20 lines
Quoted 8 lines
Quoted 3 lines

I like static inline because I get the benefit of compiler type checking, and gcov shows me which register definitions have been used in different tests.

Type checking shouldn't be necessary for simple defines. And I wasn't aware that you could get the Linux kernel to write out data to be fed to gcov.

Quoted 7 lines
Quoted 3 lines

#defines are always messy and I pretty much hate them. But if the general request is to use #define's, even though I don't agree, I can accommodate. It's simple to write a sed script to do the conversion.

There are a lot of opportunities to abuse #defines but they are harmless for register definitions. The Linux kernel is full of them and I haven't yet seen any code that uses static inline functions for this purpose.

My problem is just that I know that the code generated is the same. What we're talking about is that should we let the preprocessor or compiler take care of this.

Quoted 5 lines

My take is that using preprocessor is not wise - it's the last resort if there's no other proper way of doing things. Preprocessor requires all sorts of extra parenthesis to protect against its deficiencies, and it it merely a tool to do search-and-replace. Even multi-line needs special treatment.

Okay, so what you're saying here is that a huge number of people haven't been wise in using the preprocessor for register definitions all these years. That's a pretty bold statement. Now I obviously haven't looked at every single line in the kernel, but I have never come across this usage for static inline functions used for this. So, to be honest, I don't think this is really up for discussion. Of course if you come up with an example where this is done in a similar way I could be persuaded otherwise.

Quoted 4 lines
Quoted 4 lines

What you need to consider as well is that many people that work with the Linux kernel expect code to be in a certain style. Register accesses of the form

Quoted 8 lines
Quoted 6 lines
        writel(value, base + OFFSET);

are very common and expected to look a certain way, so if you write code that doesn't comply with these guidelines you make it extra hard for people to read the code. And that'll cost extra time, which people don't usually have in excess.

But this has nothing to do with static inline vs. #define anymore, right?

Of course it has. With the way you've chosen to define registers the code will look like this:

writel(value, base + offset_r())

Maybe it's just me, but when I read code like that I need additional time to parse it as opposed to the canonical form.

Quoted 9 lines
Quoted 8 lines

Maybe you can explain the usefulness of this some more. Why would it be easier to look at them in sysfs than in debugfs? You could be providing a simple list of syncpoints along with min/max, name, requested status, etc. in debugfs and it should be as easy to parse for both humans and machines as sysfs. I don't think IOCTLs would be any gain as they tend to have higher ABI stability requirements than debugfs (which doesn't have very strong requirements) or sysfs (which is often considered as a public ABI as well and therefore needs to be stable).

Quoted 6 lines

debugfs is just a debugging tool, and user space cannot rely on it. Only developers can rely on existence of debugfs, as they have the means to enable it.

sysfs is a place for actual APIs as you mention, and user space can rely on them as proper APIs. That's what the values were exported for.

But I don't see how that's relevant here. Let me quote what you said originally:

Quoted 3 lines

This is actually the only interface to read the max value to user space, which can be useful for doing some comparisons that take wrapping into account. But we could just add IOCTLs and remove the sysfs entries.

To me that sounded like it was only used for debugging purposes. If you actually need to access this from a userspace driver then, as opposed to what I said earlier, this should be handled by some IOCTL.

Thierry

#21 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

Quoted 7 lines · Thierry Reding

* PGP Signed by an unknown key
The above implies that when you submit code it shouldn't contain pieces that prepare for possible future extensions which may or may not be submitted (the exception being if such changes are part of a series where subsequent patches actually use them). The outcome is that the amount of cruft in the mainline kernel is kept to a minimum. And that's a very good thing.

We're now talking about actually a separation of logical and physical driver. I can't see why that's a bad thing. Especially considering that it's standard practice in well written drivers. Let's try to find a technical clean solution instead of debating politics. The latter should never be part of Linux kernel reviews.

Quoted 10 lines
Quoted 3 lines

I could do that for upstream. In downstream it cannot depend on DEBUG flag, as these spews are an important part of how we debug problems with customer devices and the DEBUG flag is never on in customer builds.

So I've just looked through these patches once more and I can't find where this functionality is actually used. The host1x_syncpt_debug() function is assigned to the nvhost_syncpt_ops.debug member, which in turn is only used by nvhost_syncpt_debug(). The latter, however is never used (not even by the debug infrastructure introduced in patch 4).

I have accidentally used the syncpt_op().debug() version directly. I'll fix that.

Quoted 8 lines

Okay, so what you're sayingCan here is that a huge number of people haven't been wise in using the preprocessor for register definitions all these years. That's a pretty bold statement. Now I obviously haven't looked at every single line in the kernel, but I have never come across this usage for static inline functions used for this. So, to be honest, I don't think this is really up for discussion. Of course if you come up with an example where this is done in a similar way I could be persuaded otherwise.

We must've talked about a bit different things. For pure register defs, I can accommodate changing to #defines. We'd lose the code coverage analysis, though, but if the parentheses are a make-or-break question to upstreaming, I can change.

I was thinking of definitions like this:

static inline u32 host1x_sync_cfpeek_ctrl_cfpeek_addr_f(u32 v)

{
	return (v & 0x1ff) << 0;
}

versus

#define host1x_sync_cfpeek_ctrl_cfpeek_addr_f(v) ((v) >> 16) & 0x3ff

Both of these produce the same machine code and have same usage, but the latter has type checking and code coverage analysis and the former is (in my eyes) clearer. In both of these cases the usage is like this:

writel(host1x_sync_cfpeek_ctrl_cfpeek_ena_f(1)

		| host1x_sync_cfpeek_ctrl_cfpeek_channr_f(chid)
		| host1x_sync_cfpeek_ctrl_cfpeek_addr_f(rd_ptr),
	m->sync_aperture + host1x_sync_cfpeek_ctrl_r());
Quoted 10 lines

But I don't see how that's relevant here. Let me quote what you said originally:

Quoted 3 lines

This is actually the only interface to read the max value to user space, which can be useful for doing some comparisons that take wrapping into account. But we could just add IOCTLs and remove the sysfs entries.

To me that sounded like it was only used for debugging purposes. If you actually need to access this from a userspace driver then, as opposed to what I said earlier, this should be handled by some IOCTL.

There's a use for production code to know both the max and min, but I think we can just scope that use out from this patch sest.

User space can use these two for checking if one of their fences has already passed by comparing if the current value is between min and fence, taking wrapping into account. In these cases user space can f.ex. leave a host1x wait out from a command stream.

Terje

#9 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Lucas Stach
Quoted 10 lines · Lucas Stach

I'm with Thierry here. I think there is a fair chance that we won't get the API right from the start, even when trying to come up with something that sounds sane to everyone. It's also not desirable to delay gr2d going into mainline until we are all completely satisfied with the API.

I also fail to see how host1x module being in the DRM directory hinders any downstream development. So I'm in favour of keeping host1x besides the other DRM components to lower the burden for API changes and move it out into some more generic directory, once we feel confident that the API is reasonable stable.

host1x module being in DRM directory hinders using nvhost from anywhere outside DRM in both upstream and downstream. I also don't like first putting the driver in one place, and then moving it with a huge commit to another place. We'd just postpone exactly the problems that were indicated earlier: we'd need to synchronize two trees to remove code in one and add in another at the same time so that there wouldn't be conflicting host1x drivers. I'd rather just add it in final place once, and be done with it.

But if it's a make-it-or-brake-it for upstreaming, I can move it to be a subdirectory under drivers/gpu/drm/tegra. Would this mean that we'd modify the MAINTAINER's file so that the tegradrm entry excludes host1x sub-directory, and I'd add another one which included only the host1x sub-directory? The host1x part would be Supported, whereas rest of tegradrm is Maintained.

Best regards,
Terje

#22 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Terje Bergström
Quoted 4 lines · Terje Bergström

We must've talked about a bit different things. For pure register defs, I can accommodate changing to #defines. We'd lose the code coverage analysis, though, but if the parentheses are a make-or-break question to upstreaming, I can change.

Out of sheer curiosity: What are you using the coverage data of these register definitions for? When I looked into coverage analysis the resulting data seemed rather useless to me, since the important thing is how well we cover the entire dynamic state space of the hw+sw (e.g. crap left behind by the bios ...) and coverage seemed to be a poor proxy for that. Hence why I wonder what you're doing with this data
...
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#142 lore raw
In reply to Terje Bergstrom

On Mon, Nov 26, 2012 at 03:19:06PM +0200, Terje Bergstrom wrote:
[...]

Quoted 3 lines

The patch set also adds user space API to tegradrm for accessing host1d and 2D. We are preparing also patches to libdrm, but they are not yet in condition that they could be sent out.

I did some prototyping on how a libdrm API could look like a few weeks back. I should clean the patches up some and push them to a public repository or to the mailing lists for review.

There isn't actually much more than a bit of framework along with two IOCTLs that allow creating and looking up a Tegra-specific GEM. The related kernel patches aren't available anywhere since I didn't deem them ready yet. At that time I wasn't even sure if we'd need special allocations other than what the dumb BO infrastructure provides. They implement some parts of what you've implemented in this series as well, with some slight differences.

Currently these still use the CMA-backed GEM objects but it should be easy to switch to something backed by the host1x infrastructure once that's in good shape.

While I can't find the quote right now, I seem to remember that you said at some point that you were planning on adding some 2D acceleration bits to libdrm. I don't think that's the right place. That code should rather go into the DDX. libdrm should instead provide a thin layer on top of the DRM IOCTLs to manage buffers and submit command streams. I hope I can finish the cleanup of my libdrm patches over the weekend and push them out so this may become clearer. Maybe I can even get the corresponding kernel patches pushed out.

Thierry

#24 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Terje Bergström
Quoted 9 lines · Terje Bergström
Quoted 7 lines · Thierry Reding

* PGP Signed by an unknown key
The above implies that when you submit code it shouldn't contain pieces that prepare for possible future extensions which may or may not be submitted (the exception being if such changes are part of a series where subsequent patches actually use them). The outcome is that the amount of cruft in the mainline kernel is kept to a minimum. And that's a very good thing.

Quoted 5 lines

We're now talking about actually a separation of logical and physical driver. I can't see why that's a bad thing. Especially considering that it's standard practice in well written drivers. Let's try to find a technical clean solution instead of debating politics. The latter should never be part of Linux kernel reviews.

I don't know where you see politics in what I said. All I'm saying is that we shouldn't be making things needlessly complex. In my experience the technically cleanest solution is usually the one with the least complexity.

Quoted 25 lines
Quoted 8 lines

Okay, so what you're sayingCan here is that a huge number of people haven't been wise in using the preprocessor for register definitions all these years. That's a pretty bold statement. Now I obviously haven't looked at every single line in the kernel, but I have never come across this usage for static inline functions used for this. So, to be honest, I don't think this is really up for discussion. Of course if you come up with an example where this is done in a similar way I could be persuaded otherwise.

We must've talked about a bit different things. For pure register defs, I can accommodate changing to #defines. We'd lose the code coverage analysis, though, but if the parentheses are a make-or-break question to upstreaming, I can change.

I was thinking of definitions like this:

static inline u32 host1x_sync_cfpeek_ctrl_cfpeek_addr_f(u32 v)

{
	return (v & 0x1ff) << 0;
}

versus

#define host1x_sync_cfpeek_ctrl_cfpeek_addr_f(v) ((v) >> 16) & 0x3ff

Quoted 8 lines

Both of these produce the same machine code and have same usage, but the latter has type checking and code coverage analysis and the former is (in my eyes) clearer. In both of these cases the usage is like this:

writel(host1x_sync_cfpeek_ctrl_cfpeek_ena_f(1)

		| host1x_sync_cfpeek_ctrl_cfpeek_channr_f(chid)
		| host1x_sync_cfpeek_ctrl_cfpeek_addr_f(rd_ptr),
	m->sync_aperture + host1x_sync_cfpeek_ctrl_r());

Again there's no precedent for doing this with static inline functions. You can do the same with macros. Type checking isn't an issue in these cases since we're talking about bitfields for which no proper type exists.

Two other things about the examples above: the definitions should be all caps and it would be nice if they could be made a bit shorter.

Quoted 11 lines
Quoted 10 lines

But I don't see how that's relevant here. Let me quote what you said originally:

Quoted 3 lines

This is actually the only interface to read the max value to user space, which can be useful for doing some comparisons that take wrapping into account. But we could just add IOCTLs and remove the sysfs entries.

To me that sounded like it was only used for debugging purposes. If you actually need to access this from a userspace driver then, as opposed to what I said earlier, this should be handled by some IOCTL.

Quoted 7 lines

There's a use for production code to know both the max and min, but I think we can just scope that use out from this patch sest.

User space can use these two for checking if one of their fences has already passed by comparing if the current value is between min and fence, taking wrapping into account. In these cases user space can f.ex. leave a host1x wait out from a command stream.

But you already have extra code in the kernel to patch out expired sync- points. Is it really worth the added effort to burden userspace with this? If so I still think some kind of generic IOCTL to retrieve information about a syncpoint would be better than a sysfs interface.

Thierry

#10 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Terje Bergström
Quoted 6 lines · Terje Bergström
Quoted 5 lines · Lucas Stach

I'm with Thierry here. I think there is a fair chance that we won't get the API right from the start, even when trying to come up with something that sounds sane to everyone. It's also not desirable to delay gr2d going into mainline until we are all completely satisfied with the API.

Quoted 8 lines
Quoted 5 lines

I also fail to see how host1x module being in the DRM directory hinders any downstream development. So I'm in favour of keeping host1x besides the other DRM components to lower the burden for API changes and move it out into some more generic directory, once we feel confident that the API is reasonable stable.

host1x module being in DRM directory hinders using nvhost from anywhere outside DRM in both upstream and downstream.

That's not true. Nothing keeps the rest of the kernel from using an API exported by the tegra-drm driver.

Quoted 2 lines

I also don't like first putting the driver in one place, and then moving it with a huge commit to another place.

Hehe, you're doing exactly that in this patch series. =)

Quoted 5 lines

We'd just postpone exactly the problems that were indicated earlier:
we'd need to synchronize two trees to remove code in one and add in another at the same time so that there wouldn't be conflicting host1x drivers. I'd rather just add it in final place once, and be done with it.

Yes, there would be a certain amount of synchronization needed, but as Stephen correctly pointed out we could do that move through one tree with the Acked-by of the other maintainer. The point is that we need to do this once instead of everytime the API changes.

Quoted 6 lines

But if it's a make-it-or-brake-it for upstreaming, I can move it to be a subdirectory under drivers/gpu/drm/tegra. Would this mean that we'd modify the MAINTAINER's file so that the tegradrm entry excludes host1x sub-directory, and I'd add another one which included only the host1x sub-directory? The host1x part would be Supported, whereas rest of tegradrm is Maintained.

An entry for drivers/gpu/drm/tegra/host1x would override an entry for drivers/gpu/drm/tegra so no need to exclude it. That said, there's no way to exclude an subdirectory in MAINTAINERS that I know of.

My main point for keeping host1x within tegra-drm for now was that it could possibly help speed up the inclusion of the host1x code. Seeing that there's still a substantial amount of work to be done and a need for discussion I'm not sure if rushing this is the best way. In that case there may be justification for putting it in a separate location from the start.

Thierry

#23 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Daniel Vetter
Quoted 6 lines · Daniel Vetter

Out of sheer curiosity: What are you using the coverage data of these register definitions for? When I looked into coverage analysis the resulting data seemed rather useless to me, since the important thing is how well we cover the entire dynamic state space of the hw+sw (e.g. crap left behind by the bios ...) and coverage seemed to be a poor proxy for that. Hence why I wonder what you're doing with this data

Yes, it's a poor proxy. But still, I use it to determine how big portions of hardware address space and fields I'm touching when running host1x tests. It's interesting data for planning tests, but not much more.

Best regards,
Terje

#11 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Thierry Reding
Quoted 6 lines · Thierry Reding
Quoted 2 lines · Terje Bergström

host1x module being in DRM directory hinders using nvhost from anywhere outside DRM in both upstream and downstream.

That's not true. Nothing keeps the rest of the kernel from using an API exported by the tegra-drm driver.

Right, it's just a directory. I was actually thinking that it'd be weird if a V4L2 driver would use something from inside drivers/gpu/drm/tegra (V4L use DRM? Oh nooooo!).

Shoot the idea down if it's crazy, but please think about it first. :-)

I started thinking about this and we are constrained by the Linux kernel subsystems that have a complete different architecture than hardware. This leads to awkward design as DRM design as it conflicts with the way hardware works.

Placing host1x driver in one place, DRM driver in another and XYZ driver in yet another is not ideal either. We're exposing a public API which needs to be strictly maintained, because we maintain drivers in different trees, but then again, the list of users is very static and well-defined, so public API is an overshoot.

How about if we look at this from the hardware architecture point of view? You mentioned that perhaps drivers/bus/host1x would be the best place for host1x driver.

What if we put also all host1x client modules under that same directory? drivers/bus/host1x/drm would be for DRM interface, and all other host1x client module drivers could be placed similarly. This way we could keep the host1x API private to host1x and the client module drivers, and it's easy to understand how host1x is used by just following the directory structure.

Naturally, we could also think if we want to have sub-components per host1x client (dc, 2d, etc) and a drm sub-component that implements the DRM interface, and a V4L2 sub-component that implements V4L2 interface (when/if I can convince people that camera should go upstream).

Quoted 4 lines
Quoted 2 lines

I also don't like first putting the driver in one place, and then moving it with a huge commit to another place.

Hehe, you're doing exactly that in this patch series. =)

True, I guess it's just a matter of determining what's the best time.

Quoted 4 lines

Yes, there would be a certain amount of synchronization needed, but as Stephen correctly pointed out we could do that move through one tree with the Acked-by of the other maintainer. The point is that we need to do this once instead of everytime the API changes.

Yep, inter-tree synchronization is possible, so not a show stopper.

Quoted 3 lines

An entry for drivers/gpu/drm/tegra/host1x would override an entry for drivers/gpu/drm/tegra so no need to exclude it. That said, there's no way to exclude an subdirectory in MAINTAINERS that I know of.

I saw tag X: in MAINTAINERS file, so that could be used. There's documentation for it, but also some examples like:

IBM Power Virtual SCSI/FC Device Drivers
M: Robert Jennings <[email protected]>
L: [email protected]
S: Supported
F: drivers/scsi/ibmvscsi/
X: drivers/scsi/ibmvscsi/ibmvstgt.c

Quoted 6 lines

My main point for keeping host1x within tegra-drm for now was that it could possibly help speed up the inclusion of the host1x code. Seeing that there's still a substantial amount of work to be done and a need for discussion I'm not sure if rushing this is the best way. In that case there may be justification for putting it in a separate location from the start.

I'm not in a hurry, so let's try to figure the best design first. Biggest architectural unsolved problem is the memory management and relationship between tegradrm and host1x driver. What Lucas proposed about memory management makes sense, but it'll take a while to implement it.

The rest of the unsolved questions are more about differences in opinion, and solvable.

Terje

#143 lore raw
In reply to Thierry Reding
Quoted 3 lines · Thierry Reding

I did some prototyping on how a libdrm API could look like a few weeks back. I should clean the patches up some and push them to a public repository or to the mailing lists for review.

Ok. Sorry about the delay - I recently learned I need separate permission for user space contribution, so I'm pushing to get that permission.

Quoted 7 lines

There isn't actually much more than a bit of framework along with two IOCTLs that allow creating and looking up a Tegra-specific GEM. The related kernel patches aren't available anywhere since I didn't deem them ready yet. At that time I wasn't even sure if we'd need special allocations other than what the dumb BO infrastructure provides. They implement some parts of what you've implemented in this series as well, with some slight differences.

Ok, the BO infra is still under flux as we're designing the best place and work split.

Quoted 3 lines

Currently these still use the CMA-backed GEM objects but it should be easy to switch to something backed by the host1x infrastructure once that's in good shape.

Sounds good.

Quoted 8 lines

While I can't find the quote right now, I seem to remember that you said at some point that you were planning on adding some 2D acceleration bits to libdrm. I don't think that's the right place. That code should rather go into the DDX. libdrm should instead provide a thin layer on top of the DRM IOCTLs to manage buffers and submit command streams. I hope I can finish the cleanup of my libdrm patches over the weekend and push them out so this may become clearer. Maybe I can even get the corresponding kernel patches pushed out.

Yep, that's exactly what I actually posed as a question in one of the earlier mails. We also agree that 2D bits should not stay in libdrm. That's why we've kept the 2D bits design-wise separate from the host1x stream generation.

We don't yet have any other place to put 2D functions in, so we'll probably post them as part of patch series to libdrm. We'll just add a disclaimer that the 2D code won't remain in libdrm, and wanted to get the code out to review as a code example. We can put the 2D code either to a separate library or to DDX, whichever is preferred.

The host1x command stream generation would still remain in libdrm. That seems to be the pattern with other hardware.

Best regards,
Terje

#25 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Thierry Reding
Quoted 4 lines · Thierry Reding

I don't know where you see politics in what I said. All I'm saying is that we shouldn't be making things needlessly complex. In my experience the technically cleanest solution is usually the one with the least complexity.

Let me come up with a proposal and let's then see where to go next.

Quoted 4 lines

But you already have extra code in the kernel to patch out expired sync- points. Is it really worth the added effort to burden userspace with this? If so I still think some kind of generic IOCTL to retrieve information about a syncpoint would be better than a sysfs interface.

That's exactly why I mentioned that it's not useful to upstream. There are some cases where user space might want to check if a fence has passed without waiting for it, but that's marginal and could be handled even with waits with zero timeout.

Terje

#12 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Terje Bergström

Am Samstag, den 01.12.2012, 18:55 +0200 schrieb Terje Bergström:

Quoted 5 lines · Thierry Reding
Quoted 4 lines · Terje Bergström
Quoted 2 lines

host1x module being in DRM directory hinders using nvhost from anywhere outside DRM in both upstream and downstream.

Quoted 7 lines
Quoted 2 lines

That's not true. Nothing keeps the rest of the kernel from using an API exported by the tegra-drm driver.

Right, it's just a directory. I was actually thinking that it'd be weird if a V4L2 driver would use something from inside drivers/gpu/drm/tegra (V4L use DRM? Oh nooooo!).

Yes it _is_ weird to have V4L using something which resides inside DRM, but see below.

Quoted 17 lines

Shoot the idea down if it's crazy, but please think about it first. :-)

I started thinking about this and we are constrained by the Linux kernel subsystems that have a complete different architecture than hardware. This leads to awkward design as DRM design as it conflicts with the way hardware works.

Placing host1x driver in one place, DRM driver in another and XYZ driver in yet another is not ideal either. We're exposing a public API which needs to be strictly maintained, because we maintain drivers in different trees, but then again, the list of users is very static and well-defined, so public API is an overshoot.

How about if we look at this from the hardware architecture point of view? You mentioned that perhaps drivers/bus/host1x would be the best place for host1x driver.

Quoted 7 lines

What if we put also all host1x client modules under that same directory? drivers/bus/host1x/drm would be for DRM interface, and all other host1x client module drivers could be placed similarly. This way we could keep the host1x API private to host1x and the client module drivers, and it's easy to understand how host1x is used by just following the directory structure.

This would certainly make life easier, but personally I don't think it's the right thing to do. The separation of the Linux kernel into different subsystems was done for a reason and just because the specific hardware at hands happens to work a bit different is no valid reason to break with the standard rules of the kernel.

So I think there is no way around handling the different drivers that use host1x in different trees. For the time being there is _only_ tegra-drm using host1x in the upstream kernel. We have to make sure to come up with some API which is reasonably stable, so we don't run into big problems later. That's why I'm really in favour to keep host1x and tegra-drm side by side in the current upstream, to make sure we can change the API without jumping through too much hoops.

Your downstream V4L would have to use host1x from the DRM directory, but
really: is your downstream such a nice, clean codebase that you are not able to cope with the slight ugliness of this solution?

Quoted 5 lines

Naturally, we could also think if we want to have sub-components per host1x client (dc, 2d, etc) and a drm sub-component that implements the DRM interface, and a V4L2 sub-component that implements V4L2 interface (when/if I can convince people that camera should go upstream).

To me this sound as if V4L upstream support is still a fair time away. IMHO the right time to move out host1x is exactly the point when a second user starts appearing upstream. This will give us some time to fiddle with the API until we have to commit to it as being stable.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

I also don't like first putting the driver in one place, and then moving it with a huge commit to another place.

Hehe, you're doing exactly that in this patch series. =)

True, I guess it's just a matter of determining what's the best time.

See above.

[...]

Quoted 4 lines

I'm not in a hurry, so let's try to figure the best design first. Biggest architectural unsolved problem is the memory management and relationship between tegradrm and host1x driver. What Lucas proposed about memory management makes sense, but it'll take a while to implement it.

Please make sure to remove any unnecessary cruft from host1x in the process and don't try to make too big of a step at once. We only need one type of memory within host1x: native host1x objects, no need to plan for support of anything else. Also taking over ownership of the IOMMU address space might take some more work in the IOMMU API. We can leave this out completely for a start. Both Tegra 2 and 3 should be able to work with CMA backed objects just fine.

Regards,
Lucas

#144 lore raw
In reply to Terje Bergström
Quoted 8 lines · Terje Bergström
Quoted 3 lines · Thierry Reding

I did some prototyping on how a libdrm API could look like a few weeks back. I should clean the patches up some and push them to a public repository or to the mailing lists for review.

Ok. Sorry about the delay - I recently learned I need separate permission for user space contribution, so I'm pushing to get that permission.

Oh dear. Doesn't sound like fun. =)

Quoted 10 lines
Quoted 7 lines

There isn't actually much more than a bit of framework along with two IOCTLs that allow creating and looking up a Tegra-specific GEM. The related kernel patches aren't available anywhere since I didn't deem them ready yet. At that time I wasn't even sure if we'd need special allocations other than what the dumb BO infrastructure provides. They implement some parts of what you've implemented in this series as well, with some slight differences.

Ok, the BO infra is still under flux as we're designing the best place and work split.

Yes, I've put the prototype under a --enable-tegra-experimental-api switch, which has been used in the past for helpers that weren't finalized yet.

Quoted 14 lines
Quoted 8 lines

While I can't find the quote right now, I seem to remember that you said at some point that you were planning on adding some 2D acceleration bits to libdrm. I don't think that's the right place. That code should rather go into the DDX. libdrm should instead provide a thin layer on top of the DRM IOCTLs to manage buffers and submit command streams. I hope I can finish the cleanup of my libdrm patches over the weekend and push them out so this may become clearer. Maybe I can even get the corresponding kernel patches pushed out.

Yep, that's exactly what I actually posed as a question in one of the earlier mails. We also agree that 2D bits should not stay in libdrm. That's why we've kept the 2D bits design-wise separate from the host1x stream generation.

Quoted 5 lines

We don't yet have any other place to put 2D functions in, so we'll probably post them as part of patch series to libdrm. We'll just add a disclaimer that the 2D code won't remain in libdrm, and wanted to get the code out to review as a code example. We can put the 2D code either to a separate library or to DDX, whichever is preferred.

FWIW, I've done some work on an initial DDX, which is basically a fork of xf86-video-modesetting rebranded and with some cleanup like ripping out the PCI support. I wanted to do some testing before pushing it out and I think I can get that done on Monday.

Posting the code early is exactly the right thing to do. We still have to figure out quite a number of things and we can always move code between the various components of the whole stack.

Quoted 2 lines

The host1x command stream generation would still remain in libdrm. That seems to be the pattern with other hardware.

Yes, I fully agree.

Thierry

#13 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Lucas Stach
Quoted 14 lines · Lucas Stach

This would certainly make life easier, but personally I don't think it's the right thing to do. The separation of the Linux kernel into different subsystems was done for a reason and just because the specific hardware at hands happens to work a bit different is no valid reason to break with the standard rules of the kernel.

So I think there is no way around handling the different drivers that use host1x in different trees. For the time being there is _only_ tegra-drm using host1x in the upstream kernel. We have to make sure to come up with some API which is reasonably stable, so we don't run into big problems later. That's why I'm really in favour to keep host1x and tegra-drm side by side in the current upstream, to make sure we can change the API without jumping through too much hoops.

Quoted 3 lines

Your downstream V4L would have to use host1x from the DRM directory, but
really: is your downstream such a nice, clean codebase that you are not able to cope with the slight ugliness of this solution?

Ok, can do. I'll move the code base to drivers/gpu/drm/tegra/host1x. For downstream, the host1x driver implements all user space APIs (no drm, no v4l, etc) so the directory is of no consequence. If we immersed host1x driver totally with tegra-drm, that'd be a problem, but if I can keep a separation, that's fine.

Quoted 7 lines

Please make sure to remove any unnecessary cruft from host1x in the process and don't try to make too big of a step at once. We only need one type of memory within host1x: native host1x objects, no need to plan for support of anything else. Also taking over ownership of the IOMMU address space might take some more work in the IOMMU API. We can leave this out completely for a start. Both Tegra 2 and 3 should be able to work with CMA backed objects just fine.

Ok, that simplifies the process. I'll just implement firewall and copy the strema over to kernel space unconditionally.

Terje

maintainer
#14 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

Guys I think you guys might be overthniking things here.

I know you have some sort of upstream/downstream split, but really in the upstream kernel, we don't care about that, so don't make it our problem.

There is no need for any sort of stable API between host1x and the sub drivers, we change APIs in the kernel the whole time it isn't a problem.

If you need to change the API, submit a single patch changing it across all the drivers in the tree, collecting Acks or not as needed. We do this the whole time, I've never had or seen a problem with it.

We don't do separate subsystems APIs set in stone bullshit, and all subsystem maintainers are used to dealing with these sort of issues. You get an ack from one maintainer and the other one sticks it in his tree with a note to Linus.

You can put the code where you want, maybe just under drivers/gpu instead of drivers/video or drivers/gpu/drm, just make sure you have a path for it into the kernel.

And I have an non-upstream precedent for v4l sitting on drm, some radeon GPUs have capture tuners, and the only way to implement that would be to stick a v4l driver in the radeon drm driver. Not a problem, just never finished writing the code.

Dave.

#15 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

Quoted 9 lines · Dave Airlie

Guys I think you guys might be overthniking things here.

I know you have some sort of upstream/downstream split, but really in the upstream kernel, we don't care about that, so don't make it our problem.

There is no need for any sort of stable API between host1x and the sub drivers, we change APIs in the kernel the whole time it isn't a problem.

Point taken. I was primarily concerned about needless churn during early development. But given the latest discussions it has become clear that there's no need to rush things and therefore we should be able to resolve any potential issues that could result in churn before the first patches are merged.

Quoted 3 lines

You can put the code where you want, maybe just under drivers/gpu instead of drivers/video or drivers/gpu/drm, just make sure you have a path for it into the kernel.

drivers/gpu/host1x sounds like a good location to me. Does that still go in via your tree?

Thierry

#16 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Dave Airlie
Quoted 5 lines · Dave Airlie

Guys I think you guys might be overthniking things here.

I know you have some sort of upstream/downstream split, but really in the upstream kernel, we don't care about that, so don't make it our problem.

I am not trying to make anything your problem. Most of the issues we have already worked out with a good solution that all active participants have agreed with. We have only a couple of disagreements with Thierry.

My goal is to get a good open source co-operation and trying to prevent a code fork while still maintaining good design. That way everybody wins. The way to do that is to base our BSP on upstream kernel.

I'm not trying to here throw code over the fence and flee. This is a genuine attempt to work together. I want to prevent the "we" (kernel community excluding NVIDIA) and "you" (NVIDIA) that a split code base would cause in the long run. I'd like to just talk about "we" including NVIDIA.

Quoted 8 lines

There is no need for any sort of stable API between host1x and the sub drivers, we change APIs in the kernel the whole time it isn't a problem.

If you need to change the API, submit a single patch changing it across all the drivers in the tree, collecting Acks or not as needed. We do this the whole time, I've never had or seen a problem with it.

Quoted 8 lines

We don't do separate subsystems APIs set in stone bullshit, and all subsystem maintainers are used to dealing with these sort of issues. You get an ack from one maintainer and the other one sticks it in his tree with a note to Linus.

You can put the code where you want, maybe just under drivers/gpu instead of drivers/video or drivers/gpu/drm, just make sure you have a path for it into the kernel.

Follows exactly my thinking, as the location of host1x driver has no practical consequence to me.

Thierry proposed drivers/gpu/host1x. I'd like to see a couple of comments on that proposal, and if it sticks, follow that.

Thierry, did you mean that host1x driver would be in drivers/gpu/host1x, and tegradrm in drivers/gpu/drm/tegra, or would we put both in same directory?

Quoted 4 lines

And I have an non-upstream precedent for v4l sitting on drm, some radeon GPUs have capture tuners, and the only way to implement that would be to stick a v4l driver in the radeon drm driver. Not a problem, just never finished writing the code.

Yes, I just mentioned that as awkward, but I have no problem with any path.

Terje

#17 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

Quoted 7 lines · Terje Bergström
Quoted 5 lines · Dave Airlie

Guys I think you guys might be overthniking things here.

I know you have some sort of upstream/downstream split, but really in the upstream kernel, we don't care about that, so don't make it our problem.

Quoted 8 lines

I am not trying to make anything your problem. Most of the issues we have already worked out with a good solution that all active participants have agreed with. We have only a couple of disagreements with Thierry.

My goal is to get a good open source co-operation and trying to prevent a code fork while still maintaining good design. That way everybody wins. The way to do that is to base our BSP on upstream kernel.

Yes, that's exactly what you should be doing.

Quoted 5 lines

I'm not trying to here throw code over the fence and flee. This is a genuine attempt to work together. I want to prevent the "we" (kernel community excluding NVIDIA) and "you" (NVIDIA) that a split code base would cause in the long run. I'd like to just talk about "we" including NVIDIA.

FWIW I'm convinced that you're genuinely trying to make this work and nobody welcomes this more than me. However it is only natural if you dump such a large body of code on the community that people will disagree with some of the design decisions.

So when I comment on the design or patches in general, it is not my intention to exclude you or NVIDIA in any way. All I'm trying to do is spot problematic or unclear parts that will make working with the code any more difficult than it has to be.

Quoted 20 lines
Quoted 8 lines

There is no need for any sort of stable API between host1x and the sub drivers, we change APIs in the kernel the whole time it isn't a problem.

If you need to change the API, submit a single patch changing it across all the drivers in the tree, collecting Acks or not as needed. We do this the whole time, I've never had or seen a problem with it.

Quoted 8 lines

We don't do separate subsystems APIs set in stone bullshit, and all subsystem maintainers are used to dealing with these sort of issues. You get an ack from one maintainer and the other one sticks it in his tree with a note to Linus.

You can put the code where you want, maybe just under drivers/gpu instead of drivers/video or drivers/gpu/drm, just make sure you have a path for it into the kernel.

Follows exactly my thinking, as the location of host1x driver has no practical consequence to me.

Quoted 6 lines

Thierry proposed drivers/gpu/host1x. I'd like to see a couple of comments on that proposal, and if it sticks, follow that.

Thierry, did you mean that host1x driver would be in drivers/gpu/host1x, and tegradrm in drivers/gpu/drm/tegra, or would we put both in same directory?

Since tegra-drm is a DRM driver it should stay in drivers/gpu/drm. I can also live with the host1x driver staying in drivers/video, but I don't think it's the proper location and drivers/gpu/host1x seems like a much better fit.

Thierry

#18 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

Quoted 9 lines · Thierry Reding

FWIW I'm convinced that you're genuinely trying to make this work and nobody welcomes this more than me. However it is only natural if you dump such a large body of code on the community that people will disagree with some of the design decisions.

So when I comment on the design or patches in general, it is not my intention to exclude you or NVIDIA in any way. All I'm trying to do is spot problematic or unclear parts that will make working with the code any more difficult than it has to be.

Thanks, I know it'a a large dump and you've made great comments about the code, and hit most of the sore spots I've had with the driver, too. I appreciate your effort - this process is making the driver better.

It's good to hear that our goals are aligned. So now that we got that out of the system, let's get back to business. :-)

Quoted 4 lines

Since tegra-drm is a DRM driver it should stay in drivers/gpu/drm. I can also live with the host1x driver staying in drivers/video, but I don't think it's the proper location and drivers/gpu/host1x seems like a much better fit.

That sounds like a plan to me.

Terje

#138 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

In reply to Dave Airlie

Hi Dave:

I'm new in kernel development. Could you tell me or give me some materials to read that why we need to align the size of IOCTL structures to 64bit? I can understand if we're working in a 64bit kernel but why we need to do this if we're in a 32bit arm kernel? Besides, why the pointers in IOCTL structure should be declared as u64?

Mark

Quoted 110 lines · Dave Airlie

drivers/gpu/drm/tegra/drm.c static int tegra_drm_unload(struct drm_device *drm) · line 192

Quoted 13 lines

static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp) {

drivers/gpu/drm/tegra/drm.c +10 -1
-       return 0;
+       struct tegra_drm_fpriv *fpriv;
+       int err = 0;
+
+       fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL);
+       if (!fpriv)
+               return -ENOMEM;
+
+       INIT_LIST_HEAD(&fpriv->contexts);
+       filp->driver_priv = fpriv;
+

who frees this?

include/drm/tegra_drm.h line 46

Quoted 3 lines
include/drm/tegra_drm.h new file +3 -0
+struct tegra_drm_syncpt_incr_args {
+       __u32 id;
+};

add 32-bits of padding here

include/drm/tegra_drm.h line 59

Quoted 13 lines
include/drm/tegra_drm.h new file +13 -0
+
+struct tegra_drm_syncpt_wait_args {
+       __u32 id;
+       __u32 thresh;
+       __s32 timeout;
+       __u32 value;
+};
+
+#define DRM_TEGRA_NO_TIMEOUT   (-1)
+
+struct tegra_drm_open_channel_args {
+       __u32 class;
+       void *context;

no pointers use u64, align them to 64-bits, so 32-bits of padding,

include/drm/tegra_drm.h line 64

Quoted 5 lines
include/drm/tegra_drm.h new file +5 -0
+};
+
+struct tegra_drm_get_channel_param_args {
+       void *context;
+       __u32 value;

Same padding + uint64_t for void *

include/drm/tegra_drm.h line 76

Quoted 12 lines
include/drm/tegra_drm.h new file +12 -0
+};
+
+struct tegra_drm_syncpt_incr {
+       __u32 syncpt_id;
+       __u32 syncpt_incrs;
+};
+
+struct tegra_drm_cmdbuf {
+       __u32 mem;
+       __u32 offset;
+       __u32 words;
+};

add padding

include/drm/tegra_drm.h line 84

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

add padding

Quoted 15 lines
include/drm/tegra_drm.h new file +15 -0
+
+struct tegra_drm_waitchk {
+       __u32 mem;
+       __u32 offset;
+       __u32 syncpt_id;
+       __u32 thresh;
+};
+
+struct tegra_drm_submit_args {
+       void *context;
+       __u32 num_syncpt_incrs;
+       __u32 num_cmdbufs;
+       __u32 num_relocs;
+       __u32 submit_version;
+       __u32 num_waitchks;

include/drm/tegra_drm.h line 109

Quoted 10 lines
include/drm/tegra_drm.h new file +10 -0
+       __u32 waitchk_mask;
+       __u32 timeout;
+       struct tegra_drm_syncpt_incrs *syncpt_incrs;
+       struct tegra_drm_cmdbuf *cmdbufs;
+       struct tegra_drm_reloc *relocs;
+       struct tegra_drm_waitchk *waitchks;
+
+       __u32 pad[5];           /* future expansion */
+       __u32 fence;            /* Return value */
+};

lose all the pointers for 64-bit aligned uint64_t.

Probably should align all of these on __u64 and __u32 usage if possible.

i'll look at the rest of the patches, but I need to know what commands can be submitted via this interface and what are the security implications of it.

Dave.
--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#139 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

Quoted 5 lines · Mark Zhang

I'm new in kernel development. Could you tell me or give me some materials to read that why we need to align the size of IOCTL structures to 64bit? I can understand if we're working in a 64bit kernel but why we need to do this if we're in a 32bit arm kernel? Besides, why the pointers in IOCTL structure should be declared as u64?

Because in a few years/months you'll have arm64, but still the same driver with the same ioctls ... and if the ioctls are not _exactly_ the same you get to write compat ioctl code which copies the old 32bit struct into the 64bit struct the kernel understands. Hence your ioctl must be laid out exactly the same for both 32bit and 64bit, which happens if you naturally align/pad everything to 64bits and only use fixed-sized integers and no pointers.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#28 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Thierry Reding
Quoted 37 lines · Thierry Reding
Quoted 19 lines · Terje Bergström
Quoted 6 lines · Thierry Reding
Quoted 3 lines · Terje Bergström

Tegra20 and Tegra30 are compatible, but future chips are not. I was hoping we would be ready in upstream kernel for future chips.

Quoted 7 lines

I think we should ignore that problem for now. Generally planning for any possible combination of incompatibilities leads to overgeneralized designs that require precisely these kinds of indirections.

Once some documentation for Tegra 40 materializes we can start thinking about how to encapsulate the incompatible code.

I think here our perspectives differ a lot. That is natural considering the company I work for and company you work for, so let's try to sync the perspective.

Quoted 7 lines

In my reality, whatever is in market is old news and I barely work on them anymore. Upstreaming activity is the exception. 90% of my time is spent dealing with future chips which I know cannot be handled without this split to logical and physical driver parts.

For you, Tegra2 and Tegra3 are the reality.

To be fair, Tegra2 and Tegra3 are the reality for *everyone* *outside* NVIDIA.

It's great that you spend most of your time working with future chips, but unless you submit the code for inclusion or review nobody upstream needs to be concerned about the implications. Most people don't have time to waste so we naturally try to keep the maintenance burden to a minimum.

Quoted 6 lines

The above implies that when you submit code it shouldn't contain pieces that prepare for possible future extensions which may or may not be submitted (the exception being if such changes are part of a series where subsequent patches actually use them). The outcome is that the amount of cruft in the mainline kernel is kept to a minimum. And that's a very good thing.

I think there's room for letting Terje's complete knowledge of future chips guide the design of the current code that's sent upstream. Certainly we shouldn't add a ton of unnecessary abstraction layers right now that aren't needed for Tegra20/30, but if there's some decision that doesn't affect the bloat, opaqueness, ... of the current code but one choice is better for future development without serious negatives for the current code, it's pretty reasonable to make that decision rather than the other.

(That all said, I haven't really followed the details of this particular point, so I can't say how my comment applies to any decisions being made right now - just that we shouldn't blanket reject future knowledge when making decisions)

After all, making the right decision now will reduce the number/size of patches later, and hence reduce code churn and reviewer load.

#26 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Thierry Reding
Quoted 1 line · Thierry Reding

On Sat, Dec 01, 2012 at 01:31:02PM +0200, Terje Bergström wrote:

...

Quoted 20 lines
Quoted 15 lines

I was thinking of definitions like this:

static inline u32 host1x_sync_cfpeek_ctrl_cfpeek_addr_f(u32 v) { return (v & 0x1ff) << 0; }

versus

#define host1x_sync_cfpeek_ctrl_cfpeek_addr_f(v) ((v) >> 16) & 0x3ff

Both of these produce the same machine code and have same usage, but the latter has type checking and code coverage analysis and the former is (in my eyes) clearer. In both of these cases the usage is like this:

Quoted 4 lines

writel(host1x_sync_cfpeek_ctrl_cfpeek_ena_f(1) | host1x_sync_cfpeek_ctrl_cfpeek_channr_f(chid) | host1x_sync_cfpeek_ctrl_cfpeek_addr_f(rd_ptr), m->sync_aperture + host1x_sync_cfpeek_ctrl_r());

Quoted 4 lines

Again there's no precedent for doing this with static inline functions. You can do the same with macros. Type checking isn't an issue in these cases since we're talking about bitfields for which no proper type exists.

I suspect the inline functions could encode signed-vs-unsigned fields, perhaps catch u8 variables when they should have been u32, etc.?

#29 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Stephen Warren
Quoted 45 lines · Stephen Warren
Quoted 37 lines · Thierry Reding
Quoted 19 lines · Terje Bergström
Quoted 6 lines · Thierry Reding
Quoted 3 lines · Terje Bergström

Tegra20 and Tegra30 are compatible, but future chips are not. I was hoping we would be ready in upstream kernel for future chips.

Quoted 7 lines

I think we should ignore that problem for now. Generally planning for any possible combination of incompatibilities leads to overgeneralized designs that require precisely these kinds of indirections.

Once some documentation for Tegra 40 materializes we can start thinking about how to encapsulate the incompatible code.

I think here our perspectives differ a lot. That is natural considering the company I work for and company you work for, so let's try to sync the perspective.

Quoted 7 lines

In my reality, whatever is in market is old news and I barely work on them anymore. Upstreaming activity is the exception. 90% of my time is spent dealing with future chips which I know cannot be handled without this split to logical and physical driver parts.

For you, Tegra2 and Tegra3 are the reality.

To be fair, Tegra2 and Tegra3 are the reality for *everyone* *outside* NVIDIA.

It's great that you spend most of your time working with future chips, but unless you submit the code for inclusion or review nobody upstream needs to be concerned about the implications. Most people don't have time to waste so we naturally try to keep the maintenance burden to a minimum.

Quoted 6 lines

The above implies that when you submit code it shouldn't contain pieces that prepare for possible future extensions which may or may not be submitted (the exception being if such changes are part of a series where subsequent patches actually use them). The outcome is that the amount of cruft in the mainline kernel is kept to a minimum. And that's a very good thing.

Quoted 8 lines

I think there's room for letting Terje's complete knowledge of future chips guide the design of the current code that's sent upstream. Certainly we shouldn't add a ton of unnecessary abstraction layers right now that aren't needed for Tegra20/30, but if there's some decision that doesn't affect the bloat, opaqueness, ... of the current code but one choice is better for future development without serious negatives for the current code, it's pretty reasonable to make that decision rather than the other.

The original point was that the current design stashes every function of host1x into an ops structure and you have to go through those ops to get at the functionality. I can understand the need to add an ops structure to cope with incompatibilities between versions, but as you say there should to be a reason for them being introduced. If such reasons exists, then I think they at least warrant a comment somewhere.

Furthermore this is usually best handled by wrapping the ops accesses in a public API, so that the ops structure can be hidden within the driver. For example, submitting a job to a channel should have a public API such as:

	int host1x_channel_submit(struct host1x_channel *channel,
				  struct host1x_job *job)
	{
		...
	}

An initial implementation would just add the code into this function. If it turns out some future version requires special incantations to submit a job, only then should we introduce an ops structure, with only the one function:

	struct host1x_channel_ops {
		int (*submit)(struct host1x_channel *channel,
			      struct host1x_job *job);
	};

But since only the public API above has been used, access to the special implementation can be hidden from the user. So the public function could be modified in this way:

	int host1x_channel_submit(struct hostx1_channel *channel,
				  struct host1x_job *job)
	{
		if (channel->ops && channel->ops->submit)
			return channel->ops->submit(channel, job);

		...
	}

And then you have two choices: either you keep the code for previous generations after the if block or you provide a separate ops structure for older generations as well and handle them via the same code path.

One other thing that such a design can help with is refactoring common code or parameterizing code. Maybe newer generations are not compatible but can easily be made to work with existing code by introducing a variable such as register stride or something.

What's really difficult to follow is if an ops structure is accessed via some global macro. It also breaks encapsulation because you have a global ops structure. That may even work fine for now, but it will break once you have more than a single host1x in a system. I know this will never happen, but all of a sudden it happens anyway and the code breaks. Doing this right isn't very hard and it will lead to a better design and is less likely to break at some point.

Thierry

#140 lore raw

Re: [RFC v2 8/8] drm: tegra: Add gr2d device

In reply to Daniel Vetter
Quoted 7 lines · Daniel Vetter
Quoted 5 lines · Mark Zhang

I'm new in kernel development. Could you tell me or give me some materials to read that why we need to align the size of IOCTL structures to 64bit? I can understand if we're working in a 64bit kernel but why we need to do this if we're in a 32bit arm kernel? Besides, why the pointers in IOCTL structure should be declared as u64?

Quoted 7 lines

Because in a few years/months you'll have arm64, but still the same driver with the same ioctls ... and if the ioctls are not _exactly_ the same you get to write compat ioctl code which copies the old 32bit struct into the 64bit struct the kernel understands. Hence your ioctl must be laid out exactly the same for both 32bit and 64bit, which happens if you naturally align/pad everything to 64bits and only use fixed-sized integers and no pointers.

Ah, I see. Thanks. Yes, u64 still works as 32 bit pointer.

Mark

Quoted 2 lines

-Daniel

#30 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Thierry Reding

On 12/04/2012 05:03 AM, Thierry Reding wrote:
[...]

Quoted 41 lines
Quoted 8 lines

I think there's room for letting Terje's complete knowledge of future chips guide the design of the current code that's sent upstream. Certainly we shouldn't add a ton of unnecessary abstraction layers right now that aren't needed for Tegra20/30, but if there's some decision that doesn't affect the bloat, opaqueness, ... of the current code but one choice is better for future development without serious negatives for the current code, it's pretty reasonable to make that decision rather than the other.

The original point was that the current design stashes every function of host1x into an ops structure and you have to go through those ops to get at the functionality. I can understand the need to add an ops structure to cope with incompatibilities between versions, but as you say there should to be a reason for them being introduced. If such reasons exists, then I think they at least warrant a comment somewhere.

Furthermore this is usually best handled by wrapping the ops accesses in a public API, so that the ops structure can be hidden within the driver. For example, submitting a job to a channel should have a public API such as:

	int host1x_channel_submit(struct host1x_channel *channel,
				  struct host1x_job *job)
	{
		...
	}

An initial implementation would just add the code into this function. If it turns out some future version requires special incantations to submit a job, only then should we introduce an ops structure, with only the one function:

	struct host1x_channel_ops {
		int (*submit)(struct host1x_channel *channel,
			      struct host1x_job *job);
	};

But since only the public API above has been used, access to the special implementation can be hidden from the user. So the public function could be modified in this way:

Quoted 9 lines
	int host1x_channel_submit(struct hostx1_channel *channel,
				  struct host1x_job *job)
	{
		if (channel->ops && channel->ops->submit)
			return channel->ops->submit(channel, job);

		...
	}

I guess we do this in exactly this way at the beginning. Then we realized that we need to define callbacks to make different tegra has different logics. So that's why we see the codes have lots of function ops right now.

If so, this will make Terje modify the code back to the original version, and this is not an interesting work.

Just my personal guess, no offence.

Mark

Quoted 26 lines

And then you have two choices: either you keep the code for previous generations after the if block or you provide a separate ops structure for older generations as well and handle them via the same code path.

One other thing that such a design can help with is refactoring common code or parameterizing code. Maybe newer generations are not compatible but can easily be made to work with existing code by introducing a variable such as register stride or something.

What's really difficult to follow is if an ops structure is accessed via some global macro. It also breaks encapsulation because you have a global ops structure. That may even work fine for now, but it will break once you have more than a single host1x in a system. I know this will never happen, but all of a sudden it happens anyway and the code breaks. Doing this right isn't very hard and it will lead to a better design and is less likely to break at some point.

Thierry

_______________________________________________
dri-devel mailing list [email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#31 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Thierry Reding

On 12/04/2012 05:03 AM, Thierry Reding wrote:
[...]

Quoted 6 lines

One other thing that such a design can help with is refactoring common code or parameterizing code. Maybe newer generations are not compatible but can easily be made to work with existing code by introducing a variable such as register stride or something.

Quoted 8 lines

What's really difficult to follow is if an ops structure is accessed via some global macro. It also breaks encapsulation because you have a global ops structure. That may even work fine for now, but it will break once you have more than a single host1x in a system. I know this will never happen, but all of a sudden it happens anyway and the code breaks. Doing this right isn't very hard and it will lead to a better design and is less likely to break at some point.

Sorry I forget to reply this in last mail...

Agree. Even for userspace programs, we should avoid using global variables as possible as we can. So we need to think about this and try to reduce the number of global vars.

Mark

Quoted 9 lines

Thierry

_______________________________________________
dri-devel mailing list [email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#32 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Thierry Reding
Quoted 7 lines · Thierry Reding

What's really difficult to follow is if an ops structure is accessed via some global macro. It also breaks encapsulation because you have a global ops structure. That may even work fine for now, but it will break once you have more than a single host1x in a system. I know this will never happen, but all of a sudden it happens anyway and the code breaks. Doing this right isn't very hard and it will lead to a better design and is less likely to break at some point.

I agree that the chip ops access goes through too much indirection and macro magic (which I already declared I hate), so we're going to design something simpler.

Terje

#27 lore raw

Re: [RFC v2 1/8] video: tegra: Add nvhost driver

In reply to Stephen Warren
Quoted 23 lines · Stephen Warren
Quoted 1 line · Thierry Reding

On Sat, Dec 01, 2012 at 01:31:02PM +0200, Terje Bergström wrote:

...

Quoted 20 lines
Quoted 19 lines

I was thinking of definitions like this:

static inline u32 host1x_sync_cfpeek_ctrl_cfpeek_addr_f(u32 v) { return (v & 0x1ff) << 0; }

versus

#define host1x_sync_cfpeek_ctrl_cfpeek_addr_f(v) ((v) >> 16) & 0x3ff

Both of these produce the same machine code and have same usage, but the latter has type checking and code coverage analysis and the former is (in my eyes) clearer. In both of these cases the usage is like this:

writel(host1x_sync_cfpeek_ctrl_cfpeek_ena_f(1) | host1x_sync_cfpeek_ctrl_cfpeek_channr_f(chid) | host1x_sync_cfpeek_ctrl_cfpeek_addr_f(rd_ptr), m->sync_aperture + host1x_sync_cfpeek_ctrl_r());

Quoted 7 lines
Quoted 4 lines

Again there's no precedent for doing this with static inline functions. You can do the same with macros. Type checking isn't an issue in these cases since we're talking about bitfields for which no proper type exists.

I suspect the inline functions could encode signed-vs-unsigned fields, perhaps catch u8 variables when they should have been u32, etc.?

I don't see how this would be relevant here. These definitions are only used in the driver internally and not a public API, therefore none of those checks should really be needed. If somebody writes code for this driver and uses the register definitions, they better know what they're doing. Or at least wrong usage should be filtered out through review.

In my opinion the consistency with how other drivers are written far outweigh the benefits provided by inline functions. That said, I'm out of arguments and I don't have a final say anyway, so if it is decided to stick with inline functions I can find a way to live with them.

Thierry

#59 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

In reply to Terje Bergstrom
Quoted 5 lines · 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.

Quoted 7 lines

This modification introduces a regression: Because there is no general framework for attaching separate devices into the same address space, this patch removes the ability to use IOMMU in tegradrm.

I've been thinking about this some more and came to the conclusion that since we will already have a tight coupling between host1x and tegra-drm we may just as well keep the client registration code in host1x. The way I imagine this to work would be to export a public API from tegra-drm, say tegra_drm_init() and tegra_drm_exit(), that could be called in place of drm_platform_init() and drm_platform_exit() in the current code.

tegra_drm_init() could then be passed the host1x platform device to bind to. The only thing that would need to be done is move the fields in the host1x structure specific to DRM into a separate structure. host1x would have to export host1x_drm_init/exit() which the DRM can invoke to have all DRM clients register to the DRM subsystem.

From a hierarchical point of view this makes sense, with host1x being the parent of all DRM subdevices. It allows us to reuse the current code from tegra-drm that has been tested and works properly even for module unload/reload. We also get to keep the proper encapsulation and the switch to the separate host1x driver will require a much smaller patch.

Does anybody see a disadvantage in this approach?

Thierry

#60 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 13 lines · Thierry Reding

I've been thinking about this some more and came to the conclusion that since we will already have a tight coupling between host1x and tegra-drm we may just as well keep the client registration code in host1x. The way I imagine this to work would be to export a public API from tegra-drm, say tegra_drm_init() and tegra_drm_exit(), that could be called in place of drm_platform_init() and drm_platform_exit() in the current code.

tegra_drm_init() could then be passed the host1x platform device to bind to. The only thing that would need to be done is move the fields in the host1x structure specific to DRM into a separate structure. host1x would have to export host1x_drm_init/exit() which the DRM can invoke to have all DRM clients register to the DRM subsystem.

Quoted 7 lines

From a hierarchical point of view this makes sense, with host1x being the parent of all DRM subdevices. It allows us to reuse the current code from tegra-drm that has been tested and works properly even for module unload/reload. We also get to keep the proper encapsulation and the switch to the separate host1x driver will require a much smaller patch.

Does anybody see a disadvantage in this approach?

I'm a bit confused about the scope. You mention host1x several times, but I'm not sure if you mean the file drivers/gpu/drm/tegra/host1x.c or the host1x driver. So I might be babbling when I answer this. Could you please clarify that?

host1x hardware access must be encapsulated in host1x driver (drivers/gpu/host1x if that's the location we prefer). As for the management of the list of DRM clients, we proposed the move to drm.c, because host1x hardware would anyway be controlled by a different driver. Having file called host1x.c in tegradrm didn't sound logical, as its not really controlling host1x, and its probe wouldn't be called.

If your proposal is that we'd move the management of the list of host1x devices from tegradrm to host1x driver, we'd have a tight circular dependency between two drivers and that's almost always a bad idea. So far all ideas have revolved around tegradrm calling host1x, and host1x calling a bit of DRM (for CMA, would be fixed in later version) but not host1x calling tegradrm.

host1x driver itself has only little use for the list of clients. Basically we need only a list of channels, and platform devices associated with channels, to be able to dump host1x channel state.

Mind you, I believe nvhost driver as part of our BSP has had quite many more hours of runtime than tegradrm. :-)

Terje

#61 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 20 lines · Terje Bergström
Quoted 19 lines · Thierry Reding

I've been thinking about this some more and came to the conclusion that since we will already have a tight coupling between host1x and tegra-drm we may just as well keep the client registration code in host1x. The way I imagine this to work would be to export a public API from tegra-drm, say tegra_drm_init() and tegra_drm_exit(), that could be called in place of drm_platform_init() and drm_platform_exit() in the current code.

tegra_drm_init() could then be passed the host1x platform device to bind to. The only thing that would need to be done is move the fields in the host1x structure specific to DRM into a separate structure. host1x would have to export host1x_drm_init/exit() which the DRM can invoke to have all DRM clients register to the DRM subsystem.

From a hierarchical point of view this makes sense, with host1x being the parent of all DRM subdevices. It allows us to reuse the current code from tegra-drm that has been tested and works properly even for module unload/reload. We also get to keep the proper encapsulation and the switch to the separate host1x driver will require a much smaller patch.

Quoted 6 lines
Quoted 1 line

Does anybody see a disadvantage in this approach?

I'm a bit confused about the scope. You mention host1x several times, but I'm not sure if you mean the file drivers/gpu/drm/tegra/host1x.c or the host1x driver. So I might be babbling when I answer this. Could you please clarify that?

What I propose is to move the client registration code that is currently in drivers/gpu/drm/tegra/host1x.c to the host1x driver, which may or may not end up in drivers/gpu/host1x.

Quoted 6 lines

host1x hardware access must be encapsulated in host1x driver (drivers/gpu/host1x if that's the location we prefer). As for the management of the list of DRM clients, we proposed the move to drm.c, because host1x hardware would anyway be controlled by a different driver. Having file called host1x.c in tegradrm didn't sound logical, as its not really controlling host1x, and its probe wouldn't be called.

Oh well, at the time nobody from NVIDIA was involved so I wrote that code in preparation for proper host1x support that I thought I would have to add myself at some point. I'm more than glad that I don't have to do this all by myself. However the patch proposed in this series breaks a number of requirements such as proper encapsulation, which I already mentioned in more detail in another mail.

Quoted 6 lines

If your proposal is that we'd move the management of the list of host1x devices from tegradrm to host1x driver, we'd have a tight circular dependency between two drivers and that's almost always a bad idea. So far all ideas have revolved around tegradrm calling host1x, and host1x calling a bit of DRM (for CMA, would be fixed in later version) but not host1x calling tegradrm.

The problem that this solves is that the DRM driver needs to be bound to a specific platform device. None of the DRM subdevices are suitable because they are only part of the whole DRM device. I think that host1x is the only device that fits here.

Note that this is only an administrative problem. It shouldn't interfere with the way host1x works. The goal is that the DRM device is registered at the proper hierarchical location.

The circular dependency is indeed a problem, though. Quite frankly I have no idea how to solve this. However the approach taken in the current patch will break several other requirements as I already explained.

Thierry

#62 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 3 lines · Thierry Reding

What I propose is to move the client registration code that is currently in drivers/gpu/drm/tegra/host1x.c to the host1x driver, which may or may not end up in drivers/gpu/host1x.

Ok.

Quoted 8 lines
Quoted 7 lines

host1x hardware access must be encapsulated in host1x driver (drivers/gpu/host1x if that's the location we prefer). As for the management of the list of DRM clients, we proposed the move to drm.c, because host1x hardware would anyway be controlled by a different driver. Having file called host1x.c in tegradrm didn't sound logical, as its not really controlling host1x, and its probe wouldn't be called.

Quoted 6 lines

Oh well, at the time nobody from NVIDIA was involved so I wrote that code in preparation for proper host1x support that I thought I would have to add myself at some point. I'm more than glad that I don't have to do this all by myself. However the patch proposed in this series breaks a number of requirements such as proper encapsulation, which I already mentioned in more detail in another mail.

Hmm, I'm not sure if I remember that you refer to by the proper encapsulation. Is that the fact that we bind DRM to a sub-client?

Quoted 5 lines

The problem that this solves is that the DRM driver needs to be bound to a specific platform device. None of the DRM subdevices are suitable because they are only part of the whole DRM device. I think that host1x is the only device that fits here.

Quoted 8 lines

Note that this is only an administrative problem. It shouldn't interfere with the way host1x works. The goal is that the DRM device is registered at the proper hierarchical location.

The circular dependency is indeed a problem, though. Quite frankly I have no idea how to solve this. However the approach taken in the current patch will break several other requirements as I already explained.

The problem with doing drm_platform_init() with host1x device as parameter is that drm_get_platform_dev() will take control of drvdata. We'd need to put host1x specific struct host1x pointer to some other place and I'm not sure what that place could be.

You're right in that binding to a sub-device is not a nice way. DRM framework just needs a "struct device" to bind to. exynos seems to solve this by introducing a virtual device and bind to that. I'm not sure if this is the best way, but worth considering?

Terje

#63 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Am Mittwoch, den 05.12.2012, 13:47 +0200 schrieb Terje Bergström:
[...]

Quoted 20 lines
Quoted 6 lines

The problem that this solves is that the DRM driver needs to be bound to a specific platform device. None of the DRM subdevices are suitable because they are only part of the whole DRM device. I think that host1x is the only device that fits here.

Quoted 8 lines

Note that this is only an administrative problem. It shouldn't interfere with the way host1x works. The goal is that the DRM device is registered at the proper hierarchical location.

The circular dependency is indeed a problem, though. Quite frankly I have no idea how to solve this. However the approach taken in the current patch will break several other requirements as I already explained.

The problem with doing drm_platform_init() with host1x device as parameter is that drm_get_platform_dev() will take control of drvdata. We'd need to put host1x specific struct host1x pointer to some other place and I'm not sure what that place could be.

Quoted 5 lines

You're right in that binding to a sub-device is not a nice way. DRM framework just needs a "struct device" to bind to. exynos seems to solve this by introducing a virtual device and bind to that. I'm not sure if this is the best way, but worth considering?

I also think the introduction of a dummy platform device to aggregate the various DRM devices would be the best way to keep a clean interface between host1x and the tegradrm parts.

But I haven't thought through how to instantiate such a dummy device without clobbering the device tree and sprinkling global data all over the driver. Perhaps the host1x driver could instantiate such a device and only provide a single API entry point to make this dummy-drm-device known to it's subdevices. This way we don't have to move all the drm specific aggregation of devices into host1x and could keep the API a bit leaner. Obviously this solution would not get around the circular dependency completely, but would cut down on it a bit.

Regards,
Lucas

#64 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

In reply to Terje Bergström
Quoted 4 lines · Terje Bergström

You're right in that binding to a sub-device is not a nice way. DRM framework just needs a "struct device" to bind to. exynos seems to solve this by introducing a virtual device and bind to that. I'm not sure if this is the best way, but worth considering?

Note that I'm not too happy about the fact that drm wants a struct device to register a drm device. This all made a lot of sense back in the days when drm drivers this this fancy shadow attaching to allow drm to use a driver for rendering cooperatively with a fbdev driver. Today there's not much reason for that anymore imo, and I'd welcome patches to allow drivers to simply register a drm device (and remove all the newer registration functions for usb/platform/whatever drivers, moving the device handling into drivers). Note that it's a bit work, since not-really-required abstraction (which was useful back when the drm drivers have been shared with *BSD, but pointless now) like the drm irq support needs to be moved away to a pci-dev legacy thing only - it doesn't really buy a kms driver anything above&beyond calling request_irq() itself.

So feel free to burn this down, I'll be happy to carry wood to the pyre in the from of reviews (not much time for more right now ...).

Cheers, Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#71 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

In reply to Terje Bergström
Quoted 1 line · Terje Bergström

On 05.12.2012 13:13, Thierry Reding wrote:

[...]

Quoted 9 lines
Quoted 6 lines

Oh well, at the time nobody from NVIDIA was involved so I wrote that code in preparation for proper host1x support that I thought I would have to add myself at some point. I'm more than glad that I don't have to do this all by myself. However the patch proposed in this series breaks a number of requirements such as proper encapsulation, which I already mentioned in more detail in another mail.

Hmm, I'm not sure if I remember that you refer to by the proper encapsulation. Is that the fact that we bind DRM to a sub-client?

Yes, but there's more. For instance I went to great lengths to make sure there's no global data whatsoever. So all the data is bound to the host1x device in the current code. I know many other drivers like to take a shortcut and just put these things into global variables but I didn't want to.

Quoted 14 lines
Quoted 5 lines

The problem that this solves is that the DRM driver needs to be bound to a specific platform device. None of the DRM subdevices are suitable because they are only part of the whole DRM device. I think that host1x is the only device that fits here.

Quoted 8 lines

Note that this is only an administrative problem. It shouldn't interfere with the way host1x works. The goal is that the DRM device is registered at the proper hierarchical location.

The circular dependency is indeed a problem, though. Quite frankly I have no idea how to solve this. However the approach taken in the current patch will break several other requirements as I already explained.

Quoted 4 lines

The problem with doing drm_platform_init() with host1x device as parameter is that drm_get_platform_dev() will take control of drvdata. We'd need to put host1x specific struct host1x pointer to some other place and I'm not sure what that place could be.

Not anymore. I submitted a patch so that it no longer does that. The patch was merged about a month and a half ago.

Quoted 4 lines

You're right in that binding to a sub-device is not a nice way. DRM framework just needs a "struct device" to bind to. exynos seems to solve this by introducing a virtual device and bind to that. I'm not sure if this is the best way, but worth considering?

That was discussed a few months back already and nobody seemed to like the idea. In fact it was as a result of that discussion that Stephen brought up the idea to register the DRM driver from a central host1x driver (it may also have been part of a discussion on IRC, I don't remember exactly).

At the time I spent some time on a patch that introduced drm_soc_init() to solve this by creating a dummy struct device and registering the driver on top of that. But I abandoned it in favour of fixing the DRM platform support code. The approach also didn't provide for the proper encapsulation.

Thierry

#65 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

In reply to Daniel Vetter
Quoted 20 lines · Daniel Vetter
Quoted 4 lines · Terje Bergström

You're right in that binding to a sub-device is not a nice way. DRM framework just needs a "struct device" to bind to. exynos seems to solve this by introducing a virtual device and bind to that. I'm not sure if this is the best way, but worth considering?

Note that I'm not too happy about the fact that drm wants a struct device to register a drm device. This all made a lot of sense back in the days when drm drivers this this fancy shadow attaching to allow drm to use a driver for rendering cooperatively with a fbdev driver. Today there's not much reason for that anymore imo, and I'd welcome patches to allow drivers to simply register a drm device (and remove all the newer registration functions for usb/platform/whatever drivers, moving the device handling into drivers). Note that it's a bit work, since not-really-required abstraction (which was useful back when the drm drivers have been shared with *BSD, but pointless now) like the drm irq support needs to be moved away to a pci-dev legacy thing only - it doesn't really buy a kms driver anything above&beyond calling request_irq() itself.

Quoted 2 lines

So feel free to burn this down, I'll be happy to carry wood to the pyre in the from of reviews (not much time for more right now ...).

Part of the reasons I haven't tackled this is that for drm/i915 we can't use this alone (since we still need to support the shadow attach for old ums), but I regard it as a smaller part of the general midlayer/inversion of control problem in the drm driver setup/teardown sequence. Which all results in ridiculous amounts of races between the interfaces regsiter in the drm core (dev node, sysfs files, debugfs files) and the driver itself. Especially module unload is totally broken.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#66 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

In reply to Daniel Vetter
Quoted 20 lines · Daniel Vetter
Quoted 4 lines · Terje Bergström

You're right in that binding to a sub-device is not a nice way. DRM framework just needs a "struct device" to bind to. exynos seems to solve this by introducing a virtual device and bind to that. I'm not sure if this is the best way, but worth considering?

Note that I'm not too happy about the fact that drm wants a struct device to register a drm device. This all made a lot of sense back in the days when drm drivers this this fancy shadow attaching to allow drm to use a driver for rendering cooperatively with a fbdev driver. Today there's not much reason for that anymore imo, and I'd welcome patches to allow drivers to simply register a drm device (and remove all the newer registration functions for usb/platform/whatever drivers, moving the device handling into drivers). Note that it's a bit work, since not-really-required abstraction (which was useful back when the drm drivers have been shared with *BSD, but pointless now) like the drm irq support needs to be moved away to a pci-dev legacy thing only - it doesn't really buy a kms driver anything above&beyond calling request_irq() itself.

Quoted 2 lines

So feel free to burn this down, I'll be happy to carry wood to the pyre in the from of reviews (not much time for more right now ...).

This wouldn't solve the problem at hand, though, since we'd still need to instantiate the DRM driver somehow. Currently this is triggered ultimately by the host1x's .probe().

Maybe something more elaborate could help, though. Suppose we add functionality to DRM to instantiate a DRM device. We could call such a function from the host1x driver to add a device which the tegra-drm driver could bind to. This would entail something like a small bus implementation for DRM that would allow matching DRM devices to DRM drivers much like the platform or PCI busses. This could automatically take care of registering the DRM device with the proper parent so that host1x clients can lookup the host1x via dev->parent.

Perhaps something as simple as

	int drm_device_register(struct device *parent, const char *name, int id);

could work. Or something more elaborate such as allocating a device with

	struct drm_device *drm_device_alloc(const char *name, int id);

paired with

	int drm_device_register(struct drm_device *dev);

would be more flexible in that drivers could modify the DRM device in between the two calls.

Thierry

#67 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 15 lines · Thierry Reding

Maybe something more elaborate could help, though. Suppose we add functionality to DRM to instantiate a DRM device. We could call such a function from the host1x driver to add a device which the tegra-drm driver could bind to. This would entail something like a small bus implementation for DRM that would allow matching DRM devices to DRM drivers much like the platform or PCI busses. This could automatically take care of registering the DRM device with the proper parent so that host1x clients can lookup the host1x via dev->parent.

Perhaps something as simple as

        int drm_device_register(struct device *parent, const char *name, int id);

could work. Or something more elaborate such as allocating a device with

Quoted 8 lines
        struct drm_device *drm_device_alloc(const char *name, int id);

paired with

        int drm_device_register(struct drm_device *dev);

would be more flexible in that drivers could modify the DRM device in between the two calls.

Imo that's worse, since now drm manages even more of the driver->hw binding process. In my dream world the drm driver just registers a normal driver at module load time directly with whatever bus it's interested in, and then, from it the bus' ->probe callback setups up the entire driver, calling down into drm to setup up interfaces to userspace (dev node, sysfs, and whatever is required to implement the ioctls) and uses the various helper libraries provided. So host1x providing a virtual device that tegradrm can match sounds much better (if that helps in decoupling from host1x).

Or simply call the tegradrm setup from host1x directly, creating a depency on the tegradrm module. When trying to unload host1x it can then also call down into tegradrm to tear down the drm device. Afterwards you should be able to unload tegradrm without fuzz. And if the hard dependcy is an issue for other host1x clients this setup/teardown could be wrapped into an #ifdef CONFIG_TEGRADRM. -Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#68 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 26 lines · Daniel Vetter
Quoted 15 lines · Thierry Reding

Maybe something more elaborate could help, though. Suppose we add functionality to DRM to instantiate a DRM device. We could call such a function from the host1x driver to add a device which the tegra-drm driver could bind to. This would entail something like a small bus implementation for DRM that would allow matching DRM devices to DRM drivers much like the platform or PCI busses. This could automatically take care of registering the DRM device with the proper parent so that host1x clients can lookup the host1x via dev->parent.

Perhaps something as simple as

        int drm_device_register(struct device *parent, const char *name, int id);

could work. Or something more elaborate such as allocating a device with

Quoted 8 lines
        struct drm_device *drm_device_alloc(const char *name, int id);

paired with

        int drm_device_register(struct drm_device *dev);

would be more flexible in that drivers could modify the DRM device in between the two calls.

Quoted 9 lines

Imo that's worse, since now drm manages even more of the driver->hw binding process. In my dream world the drm driver just registers a normal driver at module load time directly with whatever bus it's interested in, and then, from it the bus' ->probe callback setups up the entire driver, calling down into drm to setup up interfaces to userspace (dev node, sysfs, and whatever is required to implement the ioctls) and uses the various helper libraries provided. So host1x providing a virtual device that tegradrm can match sounds much better (if that helps in decoupling from host1x).

Okay, now I see where you're going. You want to replace the various drm_*_init() functions with something more fine-grained that does the initialization manually in each driver. Is that it? The obvious disadvantage is that a lot of code would have to be duplicated, though that can presumably be factored out into further helpers if necessary.

On that note, I just noticed that drm_platform_init() actually binds a single platform_device to the drm_driver, which isn't going to work very well in case there are two devices that want to use the same driver. It would be nice to get rid of that limitation as well while at it.

Quoted 6 lines

Or simply call the tegradrm setup from host1x directly, creating a depency on the tegradrm module. When trying to unload host1x it can then also call down into tegradrm to tear down the drm device. Afterwards you should be able to unload tegradrm without fuzz. And if the hard dependcy is an issue for other host1x clients this setup/teardown could be wrapped into an #ifdef CONFIG_TEGRADRM.

This is what I originally proposed. However, since tegra-drm will need to call functions provided by host1x we have a cyclic dependency. Wouldn't that prevent either module from being unloaded?

Thierry

#72 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

In reply to Thierry Reding
Quoted 6 lines · Thierry Reding

On Wed, Dec 05, 2012 at 01:47:38PM +0200, Terje Bergström wrote:
Yes, but there's more. For instance I went to great lengths to make sure there's no global data whatsoever. So all the data is bound to the host1x device in the current code. I know many other drivers like to take a shortcut and just put these things into global variables but I didn't want to.

Sure, that feedback is in the todo list. For some parts I already have a proposed solution, but for chip ops not yet.

Quoted 7 lines
Quoted 4 lines

The problem with doing drm_platform_init() with host1x device as parameter is that drm_get_platform_dev() will take control of drvdata. We'd need to put host1x specific struct host1x pointer to some other place and I'm not sure what that place could be.

Not anymore. I submitted a patch so that it no longer does that. The patch was merged about a month and a half ago.

Oops, I must've checked the status from a stale tree. Thanks for that. In this case there's no technical reason why host1x couldn't act as the device to register for drm, as drm wouldn't touch host1x device data in any way.

How about if we treat the host1x driver as utility library, and move the code for host1x probe altogether to tegradrm/host1x.c? I haven't yet checked how bad the dependencies between host1x's driver's host1x.c and the rest of the driver are, so I'm not sure if it's feasible and if there would be a clear design. Just tossing in ideas.

That would solve the circular dependency problem. I've already committed to contents of host1x.c being very different in downstream and upstream, so this change would just emphasize that.

Terje

#69 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

In reply to Thierry Reding
Quoted 16 lines · Thierry Reding
Quoted 9 lines

Imo that's worse, since now drm manages even more of the driver->hw binding process. In my dream world the drm driver just registers a normal driver at module load time directly with whatever bus it's interested in, and then, from it the bus' ->probe callback setups up the entire driver, calling down into drm to setup up interfaces to userspace (dev node, sysfs, and whatever is required to implement the ioctls) and uses the various helper libraries provided. So host1x providing a virtual device that tegradrm can match sounds much better (if that helps in decoupling from host1x).

Okay, now I see where you're going. You want to replace the various drm_*_init() functions with something more fine-grained that does the initialization manually in each driver. Is that it? The obvious disadvantage is that a lot of code would have to be duplicated, though that can presumably be factored out into further helpers if necessary.

Quoted 4 lines

On that note, I just noticed that drm_platform_init() actually binds a single platform_device to the drm_driver, which isn't going to work very well in case there are two devices that want to use the same driver. It would be nice to get rid of that limitation as well while at it.

Yeah, it's the lack of generality that irks me, and writing driver init code is one giant sequence of setup function calls anyway - sprinkling 1-2 more doesn't really matter, but helps a lot if it results in the driver being in full control (e.g. if you need to reorder due to some special requirement, that's much easier to do then than with the current hoop-jumping). But like I've said, a bit a bigger fish to fry, just wanted to point you into that direction ...

Quoted 10 lines
Quoted 6 lines

Or simply call the tegradrm setup from host1x directly, creating a depency on the tegradrm module. When trying to unload host1x it can then also call down into tegradrm to tear down the drm device. Afterwards you should be able to unload tegradrm without fuzz. And if the hard dependcy is an issue for other host1x clients this setup/teardown could be wrapped into an #ifdef CONFIG_TEGRADRM.

This is what I originally proposed. However, since tegra-drm will need to call functions provided by host1x we have a cyclic dependency. Wouldn't that prevent either module from being unloaded?

You could pass down a host1x interface struct with a vtable to tegradrm (plus some static inline helpers to make those not a pain to call). The other possibility (and I'm not proud at all of that code) which we've used in the intel-ips driver is to use symbol_get at runtime - but there the requirement was explicitly that intel-ips needs to work on server systems without the drm/i915 driver loaded, but still always have the support for interacting with it compiled in (to make distros happy). It's all rather awkward though ... -Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#70 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 23 lines · Daniel Vetter
Quoted 16 lines · Thierry Reding
Quoted 9 lines

Imo that's worse, since now drm manages even more of the driver->hw binding process. In my dream world the drm driver just registers a normal driver at module load time directly with whatever bus it's interested in, and then, from it the bus' ->probe callback setups up the entire driver, calling down into drm to setup up interfaces to userspace (dev node, sysfs, and whatever is required to implement the ioctls) and uses the various helper libraries provided. So host1x providing a virtual device that tegradrm can match sounds much better (if that helps in decoupling from host1x).

Okay, now I see where you're going. You want to replace the various drm_*_init() functions with something more fine-grained that does the initialization manually in each driver. Is that it? The obvious disadvantage is that a lot of code would have to be duplicated, though that can presumably be factored out into further helpers if necessary.

Quoted 4 lines

On that note, I just noticed that drm_platform_init() actually binds a single platform_device to the drm_driver, which isn't going to work very well in case there are two devices that want to use the same driver. It would be nice to get rid of that limitation as well while at it.

Quoted 7 lines

Yeah, it's the lack of generality that irks me, and writing driver init code is one giant sequence of setup function calls anyway - sprinkling 1-2 more doesn't really matter, but helps a lot if it results in the driver being in full control (e.g. if you need to reorder due to some special requirement, that's much easier to do then than with the current hoop-jumping). But like I've said, a bit a bigger fish to fry, just wanted to point you into that direction ...

I have quite a number of things to finish up myself and this sounds like quite a bit of work.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Or simply call the tegradrm setup from host1x directly, creating a depency on the tegradrm module. When trying to unload host1x it can then also call down into tegradrm to tear down the drm device. Afterwards you should be able to unload tegradrm without fuzz. And if the hard dependcy is an issue for other host1x clients this setup/teardown could be wrapped into an #ifdef CONFIG_TEGRADRM.

Quoted 7 lines
Quoted 3 lines

This is what I originally proposed. However, since tegra-drm will need to call functions provided by host1x we have a cyclic dependency. Wouldn't that prevent either module from being unloaded?

You could pass down a host1x interface struct with a vtable to tegradrm (plus some static inline helpers to make those not a pain to call).

That sounds very interesting. It's also in line with what Terje proposed earlier, making the host1x into a helper library, only the registration part would remain with host1x. So in this kind of setup, the host1x driver would initialize tegra-drm with something like:

	int tegra_drm_init(struct device *parent, const struct host1x_ops *ops)
	{
		struct platform_device *pdev = to_platform_device(parent);
		int err;

		err = drm_platform_init(&tegra_drm_driver, pdev);
		...
	}

The DRM driver's .load() callback would of course have to be passed the ops pointer. Either that or indeed some kind of custom setup function is needed instead of calling drm_platform_init().

Maybe I should go and give such an implementation a shot, see where it ends up.

Quoted 6 lines

The other possibility (and I'm not proud at all of that code) which we've used in the intel-ips driver is to use symbol_get at runtime - but there the requirement was explicitly that intel-ips needs to work on server systems without the drm/i915 driver loaded, but still always have the support for interacting with it compiled in (to make distros happy). It's all rather awkward though ...

Hehe, indeed. Adding a dummy platform device suddenly doesn't sound that bad. =)

Thierry

#37 lore raw

Re: [RFC,v2,1/8] video: tegra: Add nvhost driver

In reply to Mark Zhang
Quoted 23 lines · Mark Zhang
Quoted 23 lines
drivers/video/tegra/host/host1x/host1x_syncpt.c new file +23 -0
+
+/**
+ * Write a cpu syncpoint increment to the hardware, without touching
+ * the cache. Caller is responsible for host being powered.
+ */
+static void host1x_syncpt_cpu_incr(struct nvhost_syncpt *sp, u32 id)
+{
+     struct nvhost_master *dev = syncpt_to_dev(sp);
+     u32 reg_offset = id / 32;
+
+     if (!nvhost_module_powered(dev->dev)) {
+             dev_err(&syncpt_to_dev(sp)->dev->dev,
+                     "Trying to access host1x when it's off");
+             return;
+     }
+
+     if (!nvhost_syncpt_client_managed(sp, id)
+                     && nvhost_syncpt_min_eq_max(sp, id)) {
+             dev_err(&syncpt_to_dev(sp)->dev->dev,
+                     "Trying to increment syncpoint id %d beyond max\n",
+                     id);
+             return;
+     }
Quoted 8 lines

drivers/video/tegra/host/host1x/host1x_syncpt.c line 106

Quoted 2 lines
drivers/video/tegra/host/host1x/host1x_syncpt.c new file +2 -0
+     writel(BIT_MASK(id), dev->sync_aperture +
+                     host1x_sync_syncpt_cpu_incr_r() + reg_offset * 4);

I have a stupid question: According to the name and the context of this function, seems it increases the syncpt value which specified by param "id". So how does this "writel" increase the value? I don't know much about host1x/syncpt reg operations, so could you explain a little bit or I just completely have a wrong understanding?

I believe I've implemented most of the requests in this mail, but I seem to have missed answering this question.

writel() to that register invokes a method in host1x, which increments the sync point indicated by the value of the register by one.

Best regards,
Terje

#73 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

In reply to Thierry Reding
Quoted 12 lines · Thierry Reding
Quoted 4 lines · Terje Bergström

You're right in that binding to a sub-device is not a nice way. DRM framework just needs a "struct device" to bind to. exynos seems to solve this by introducing a virtual device and bind to that. I'm not sure if this is the best way, but worth considering?

That was discussed a few months back already and nobody seemed to like the idea. In fact it was as a result of that discussion that Stephen brought up the idea to register the DRM driver from a central host1x driver (it may also have been part of a discussion on IRC, I don't remember exactly).

Quoted 5 lines

At the time I spent some time on a patch that introduced drm_soc_init() to solve this by creating a dummy struct device and registering the driver on top of that. But I abandoned it in favour of fixing the DRM platform support code. The approach also didn't provide for the proper encapsulation.

I've managed to go through all the other feedback and implement a solution to most of them, so now I have some slack to actually think about the initialization. Sorry about this, but you (meaning all the reviewers) did give us a _lot_ to do. :-) Fortunately, the driver actually became a lot better, too.

Back to the topic of tegradrm init. The root cause of the problem is that DRM framework needs some device to assign itself to. The problem is that this device doesn't have any physical counterpart, as it's only for storing a pointer in DRM framework. Please correct me if this is wrong.

Moving the client registration to ping pong between DRM and host1x has its problems. host1x driver itself has no use for a list of client devices. It can just iterate its children in case it needs them. In tegradrm, you need a list of devices under tegradrm control, which might or might not be the same as list of devices under host1x hardware.

The solutions that many other DRM drivers seem to employ are the virtual devices. Exynos and OMAP drivers do this, as does SH Mobile DRM driver. So I think I'd still go this way, as it's the path of minimum resistance, least amount of code and most localized change. I know it's not ideal, but I'd also not like to get stuck in this.

Terje

#74 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 36 lines · Terje Bergström
Quoted 12 lines · Thierry Reding
Quoted 4 lines · Terje Bergström

You're right in that binding to a sub-device is not a nice way. DRM framework just needs a "struct device" to bind to. exynos seems to solve this by introducing a virtual device and bind to that. I'm not sure if this is the best way, but worth considering?

That was discussed a few months back already and nobody seemed to like the idea. In fact it was as a result of that discussion that Stephen brought up the idea to register the DRM driver from a central host1x driver (it may also have been part of a discussion on IRC, I don't remember exactly).

Quoted 5 lines

At the time I spent some time on a patch that introduced drm_soc_init() to solve this by creating a dummy struct device and registering the driver on top of that. But I abandoned it in favour of fixing the DRM platform support code. The approach also didn't provide for the proper encapsulation.

I've managed to go through all the other feedback and implement a solution to most of them, so now I have some slack to actually think about the initialization. Sorry about this, but you (meaning all the reviewers) did give us a _lot_ to do. :-) Fortunately, the driver actually became a lot better, too.

Back to the topic of tegradrm init. The root cause of the problem is that DRM framework needs some device to assign itself to. The problem is that this device doesn't have any physical counterpart, as it's only for storing a pointer in DRM framework. Please correct me if this is wrong.

Moving the client registration to ping pong between DRM and host1x has its problems. host1x driver itself has no use for a list of client devices. It can just iterate its children in case it needs them. In tegradrm, you need a list of devices under tegradrm control, which might or might not be the same as list of devices under host1x hardware.

Quoted 5 lines

The solutions that many other DRM drivers seem to employ are the virtual devices. Exynos and OMAP drivers do this, as does SH Mobile DRM driver. So I think I'd still go this way, as it's the path of minimum resistance, least amount of code and most localized change. I know it's not ideal, but I'd also not like to get stuck in this.

I've briefly discussed this with Stephen on IRC because I thought I had remembered him objecting to the idea of adding a dummy device just for this purpose. It turns out, however, that what he didn't like was to add a dummy node to the DT just to make this happen, but he has no (strong) objections to a dummy platform device.

While I'm not very happy about that solution, I've been going over it for a week now and haven't come up with any better alternative that doesn't have its own disadvantages. So perhaps we should go ahead and implement that. For the host1x driver this really just means creating a platform device and adding it to the system, with some of the fields tweaked to make things work.

Is this something that you can take care of in your patch series? I could also implement this on top of the current driver and then all your patch series would have to do is remove host1x.c from tegra-drm and instantiate the platform device itself.

Thierry

#75 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 6 lines · Thierry Reding

I've briefly discussed this with Stephen on IRC because I thought I had remembered him objecting to the idea of adding a dummy device just for this purpose. It turns out, however, that what he didn't like was to add a dummy node to the DT just to make this happen, but he has no (strong) objections to a dummy platform device.

Quoted 6 lines

While I'm not very happy about that solution, I've been going over it for a week now and haven't come up with any better alternative that doesn't have its own disadvantages. So perhaps we should go ahead and implement that. For the host1x driver this really just means creating a platform device and adding it to the system, with some of the fields tweaked to make things work.

This sounds ok. Considering that the DRM driver is a virtual driver, attaching it to a virtual device sounds ok -- ish.

Quoted 4 lines

Is this something that you can take care of in your patch series? I could also implement this on top of the current driver and then all your patch series would have to do is remove host1x.c from tegra-drm and instantiate the platform device itself.

We're about to post patches for both host1x driver and libdrm. This is the last big rock unturned, so let me take a stab at this first. I'd like to get the updated patches out tomorrow or on Friday, so I'll try to either get it done for that or leave it to the TODO list.

Terje

#76 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

In reply to Thierry Reding
Quoted 6 lines · Thierry Reding

I've briefly discussed this with Stephen on IRC because I thought I had remembered him objecting to the idea of adding a dummy device just for this purpose. It turns out, however, that what he didn't like was to add a dummy node to the DT just to make this happen, but he has no (strong) objections to a dummy platform device.

Quoted 6 lines

While I'm not very happy about that solution, I've been going over it for a week now and haven't come up with any better alternative that doesn't have its own disadvantages. So perhaps we should go ahead and implement that. For the host1x driver this really just means creating a platform device and adding it to the system, with some of the fields tweaked to make things work.

Even the virtual device is not too beautiful. The problem is that the virtual device is not physical parent for DC, HDMI, etc, so dev_get_drvdata(pdev->dev.parent) returns the data from host1x device, not the virtual device.

We'll post with something that goes around this, but it's not going to be too pretty. Let's try to find the solution once we get the code out.

Terje

#77 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

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

I've briefly discussed this with Stephen on IRC because I thought I had remembered him objecting to the idea of adding a dummy device just for this purpose. It turns out, however, that what he didn't like was to add a dummy node to the DT just to make this happen, but he has no (strong) objections to a dummy platform device.

Quoted 6 lines

While I'm not very happy about that solution, I've been going over it for a week now and haven't come up with any better alternative that doesn't have its own disadvantages. So perhaps we should go ahead and implement that. For the host1x driver this really just means creating a platform device and adding it to the system, with some of the fields tweaked to make things work.

Quoted 7 lines

Even the virtual device is not too beautiful. The problem is that the virtual device is not physical parent for DC, HDMI, etc, so dev_get_drvdata(pdev->dev.parent) returns the data from host1x device, not the virtual device.

We'll post with something that goes around this, but it's not going to be too pretty. Let's try to find the solution once we get the code out.

After some more discussion with Stephen on IRC we came to the conclusion that the easiest might be to have tegra-drm call into host1x with something like:

	void host1x_set_drm_device(struct host1x *host1x, struct device *dev);

Once the dummy device has been properly set up and have each client use

	struct device *host1x_get_drm_device(struct host1x *host1x);

to obtain a pointer to the dummy device, such that it can receive the driver-private data using dev_get_drvdata() on the returned device. As long as tegra-drm hasn't registered with host1x yet, the above function could return ERR_PTR(-EPROBE_DEFER), so that dependencies are automatically handled. This is required because, tegra-drm not being the parent of the child devices, it can be guaranteed that it is probed before any of the children.

That way we should be able to get around any circular dependencies, since we only call into host1x from tegra-drm but not the other way around.

Thierry

#78 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 26 lines · Thierry Reding
Quoted 16 lines · Terje Bergström
Quoted 7 lines · Thierry Reding

I've briefly discussed this with Stephen on IRC because I thought I had remembered him objecting to the idea of adding a dummy device just for this purpose. It turns out, however, that what he didn't like was to add a dummy node to the DT just to make this happen, but he has no (strong) objections to a dummy platform device.

Quoted 7 lines

While I'm not very happy about that solution, I've been going over it for a week now and haven't come up with any better alternative that doesn't have its own disadvantages. So perhaps we should go ahead and implement that. For the host1x driver this really just means creating a platform device and adding it to the system, with some of the fields tweaked to make things work.

Quoted 8 lines

Even the virtual device is not too beautiful. The problem is that the virtual device is not physical parent for DC, HDMI, etc, so dev_get_drvdata(pdev->dev.parent) returns the data from host1x device, not the virtual device.

We'll post with something that goes around this, but it's not going to be too pretty. Let's try to find the solution once we get the code out.

Quoted 6 lines

After some more discussion with Stephen on IRC we came to the conclusion that the easiest might be to have tegra-drm call into host1x with something like:

void host1x_set_drm_device(struct host1x *host1x, struct device *dev);

If host1x is registering the dummy device that causes tegradrm to be instantiated, then presumably there's no need for the API above, since host1x will already have the struct device * for tegradrm, since it created it?

Quoted 16 lines

Once the dummy device has been properly set up and have each client use

struct device *host1x_get_drm_device(struct host1x *host1x);

to obtain a pointer to the dummy device, such that it can receive the driver-private data using dev_get_drvdata() on the returned device. As long as tegra-drm hasn't registered with host1x yet, the above function could return ERR_PTR(-EPROBE_DEFER), so that dependencies are automatically handled. This is required because, tegra-drm not being the parent of the child devices, it can be guaranteed that it is probed before any of the children.

That way we should be able to get around any circular dependencies, since we only call into host1x from tegra-drm but not the other way around.

#79 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 31 lines · Stephen Warren
Quoted 30 lines · Thierry Reding
Quoted 16 lines · Terje Bergström
Quoted 7 lines · Thierry Reding

I've briefly discussed this with Stephen on IRC because I thought I had remembered him objecting to the idea of adding a dummy device just for this purpose. It turns out, however, that what he didn't like was to add a dummy node to the DT just to make this happen, but he has no (strong) objections to a dummy platform device.

Quoted 7 lines

While I'm not very happy about that solution, I've been going over it for a week now and haven't come up with any better alternative that doesn't have its own disadvantages. So perhaps we should go ahead and implement that. For the host1x driver this really just means creating a platform device and adding it to the system, with some of the fields tweaked to make things work.

Quoted 8 lines

Even the virtual device is not too beautiful. The problem is that the virtual device is not physical parent for DC, HDMI, etc, so dev_get_drvdata(pdev->dev.parent) returns the data from host1x device, not the virtual device.

We'll post with something that goes around this, but it's not going to be too pretty. Let's try to find the solution once we get the code out.

After some more discussion with Stephen on IRC we came to the conclusion that the easiest might be to have tegra-drm call into host1x with something like:

Quoted 7 lines
Quoted 2 lines

void host1x_set_drm_device(struct host1x *host1x, struct device *dev);

If host1x is registering the dummy device that causes tegradrm to be instantiated, then presumably there's no need for the API above, since host1x will already have the struct device * for tegradrm, since it created it?

Right, that won't be necessary of course. As long as the driver-private data of the device stays NULL until tegra-drm is ready (has finished probing) just getting the struct device from the clients and looking at that should be enough.

Thierry

#80 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

In reply to Stephen Warren
Quoted 5 lines · Stephen Warren
Quoted 4 lines · Thierry Reding

After some more discussion with Stephen on IRC we came to the conclusion that the easiest might be to have tegra-drm call into host1x with something like:

Quoted 7 lines
Quoted 2 lines

void host1x_set_drm_device(struct host1x *host1x, struct device *dev);

If host1x is registering the dummy device that causes tegradrm to be instantiated, then presumably there's no need for the API above, since host1x will already have the struct device * for tegradrm, since it created it?

I didn't add the dummy device in my latest patch set. I first set out to add it, and moved the drm global data to be drvdata of that device. Then I noticed that it doesn't actually help at all.

The critical accesses to the global data are from probes of DC, HDMI, etc. They want to get the global data by getting drvdata of their parent. The dummy device is not their parent - host1x is. There's no connection between the dummy and the real client devices. So there's no logical way for DC and HDMI to find the the dummy device, except perhaps by searching for "tegradrm" device from platform bus. But then again, that'd break encapsulation so it's as bad as a global variable - only with a lot more code to do the same thing.

Accesses after probing can happen via drm->dev_private, so post-probe we're fine.

Another problem arouse (already mentioned it) when I used the dummy device to call to drm_platform_init(). It called back into tegradrm, which calls the CMA FB helper to allocate memory. Unfortunately the memory is allocated for the dummy device, and it's not initialized to do do that. I ended up with failed frame buffer allocation. That needs host1x allocator to fix.

host1x itself shouldn't need any DRM specific calls or callbacks. The device model already allows traversing through list of host1x children. The list of drm clients and devices is something that tegradrm needs to be able to initialize DRM at appropriate time. I also took that into use for storing the channel and class data. So we should try to keep the list maintenance as local to tegradrm as we can.

In my latest patch set, I kept the list management inside tegradrm, and put all DRM global data into struct tegradrm, which is accessed via a global. I guess global in tegradrm is not as bad as global in host1x, because one DRM driver can handle multiple devices, so there's no reason to have multiple tegradrm's trampling on each others data. But if you can come up with a better solution, I'm all ears.

Terje

#81 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 14 lines · Terje Bergström
Quoted 5 lines · Stephen Warren
Quoted 4 lines · Thierry Reding

After some more discussion with Stephen on IRC we came to the conclusion that the easiest might be to have tegra-drm call into host1x with something like:

Quoted 7 lines
Quoted 2 lines

void host1x_set_drm_device(struct host1x *host1x, struct device *dev);

If host1x is registering the dummy device that causes tegradrm to be instantiated, then presumably there's no need for the API above, since host1x will already have the struct device * for tegradrm, since it created it?

Quoted 6 lines

I didn't add the dummy device in my latest patch set. I first set out to add it, and moved the drm global data to be drvdata of that device. Then I noticed that it doesn't actually help at all.

The critical accesses to the global data are from probes of DC, HDMI, etc.

OK

Quoted 1 line

They want to get the global data by getting drvdata of their parent.

There's no reason that /has/ to be so; they can get any information from wherever it is, rather than trying to require it to be somewhere it isn't.

Quoted 2 lines

The dummy device is not their parent - host1x is. There's no connection between the dummy and the real client devices.

It's quite possible for the client devices to ask their actual parent (host1x) for the tegradrm struct device *, by calling a host1x API, and have host1x implement that API by returning the dummy/virtual device that it created. That should be just 1-2 lines of code to implement in host1x, plus maybe a couple more to correctly return -EPROBE_DEFERRED when appropriate.

#82 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 5 lines · Stephen Warren
Quoted 1 line · Terje Bergström

They want to get the global data by getting drvdata of their parent.

There's no reason that /has/ to be so; they can get any information from wherever it is, rather than trying to require it to be somewhere it isn't.

Exactly, this was also my solution.

Quoted 9 lines
Quoted 2 lines

The dummy device is not their parent - host1x is. There's no connection between the dummy and the real client devices.

It's quite possible for the client devices to ask their actual parent (host1x) for the tegradrm struct device *, by calling a host1x API, and have host1x implement that API by returning the dummy/virtual device that it created. That should be just 1-2 lines of code to implement in host1x, plus maybe a couple more to correctly return -EPROBE_DEFERRED when appropriate.

My solution was to just have one global, and an getter for the global. Instead of drvdata, the pointer is retrieved with the getter. No need for dummy device, or passing points between host1x and tegradrm.

Terje

#83 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 19 lines · Terje Bergström
Quoted 5 lines · Stephen Warren
Quoted 1 line · Terje Bergström

They want to get the global data by getting drvdata of their parent.

There's no reason that /has/ to be so; they can get any information from wherever it is, rather than trying to require it to be somewhere it isn't.

Exactly, this was also my solution.

Quoted 9 lines
Quoted 2 lines

The dummy device is not their parent - host1x is. There's no connection between the dummy and the real client devices.

It's quite possible for the client devices to ask their actual parent (host1x) for the tegradrm struct device *, by calling a host1x API, and have host1x implement that API by returning the dummy/virtual device that it created. That should be just 1-2 lines of code to implement in host1x, plus maybe a couple more to correctly return -EPROBE_DEFERRED when appropriate.

Quoted 3 lines

My solution was to just have one global, and an getter for the global. Instead of drvdata, the pointer is retrieved with the getter. No need for dummy device, or passing points between host1x and tegradrm.

Okay, so we're back on the topic of using globals. I need to assert again that this is not an option. If we were to use globals, then we could just as well leave out the dummy device and just do all of that in the tegra-drm driver's initialization function.

The whole point of all this is to link the host1x and it's particular tegra-drm instance. I will see if I can find the time to implement this in the existing driver, so that the host1x code that you want to remove registers the tegra-drm dummy device and the tegra-drm devices use the accessors as discussed previously to access host1x and the dummy device. Once that is implemented, removing the original host1x implementation should be much easier since you will only have to keep the dummy device instantiation along with the one or two accessor functions.

Thierry

#84 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 4 lines · Thierry Reding

Okay, so we're back on the topic of using globals. I need to assert again that this is not an option. If we were to use globals, then we could just as well leave out the dummy device and just do all of that in the tegra-drm driver's initialization function.

Quoted 8 lines

The whole point of all this is to link the host1x and it's particular tegra-drm instance. I will see if I can find the time to implement this in the existing driver, so that the host1x code that you want to remove registers the tegra-drm dummy device and the tegra-drm devices use the accessors as discussed previously to access host1x and the dummy device. Once that is implemented, removing the original host1x implementation should be much easier since you will only have to keep the dummy device instantiation along with the one or two accessor functions.

I'm not sure what you have discussed with Stephen, so I might be missing the reason why this is a problem that needs to be solved with new dependency between tegradrm and host1x instead of locally in tegradrm driver itself.

As far I remember, we had two reasons for discussing the dummy device. First reason is for DC, HDMI probe calls to find the global data. Second is giving something to DRM framework's drm_platform_init().

The easiest way to solve the probe problem is just to have a tegradrm accessor for the global data in the way I proposed in the patchset. Dummy device doesn't help there, as the dummy device is in no relationship to DC and HDMI. Sure we could tell DC to ask its parent (host1x), and call host1x driver with platform_device pointer found that way, and host1x would return a pointer to tegradrm's data. Hanging the data onto host1x driver is just a more complicated way of implementing global data, and it's breaking the responsibility split between host1x driver and tegradrm. To me, host1x driver is responsible of host1x, and tegradrm is responsible of the DRM interface and everything related to that.

All other parts of code use drm_device->dev_private for getting the global data, so the access problem is only for the probe calls.

drm_platform_init() needing a device is another problem. drm_platform_init() leads to a call to the CMA FB helper. That again needed the coherent_dma_mask set for the device give to it. I guess that problem can be solved by just setting the mask to 0xffffffff. But that is still something that can be handled inside tegradrm without involving the host1x driver.

Terje

#85 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

On 12/16/2012 09:37 AM, Terje Bergström wrote:
...

Quoted 5 lines

... Sure we could tell DC to ask its parent
(host1x), and call host1x driver with platform_device pointer found that way, and host1x would return a pointer to tegradrm's data. Hanging the data onto host1x driver is just a more complicated way of implementing global data

No it's not; at that point, the data is no longer global, but specific to the driver instance.

#86 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 10 lines · Stephen Warren

On 12/16/2012 09:37 AM, Terje Bergström wrote:
...

Quoted 5 lines

... Sure we could tell DC to ask its parent
(host1x), and call host1x driver with platform_device pointer found that way, and host1x would return a pointer to tegradrm's data. Hanging the data onto host1x driver is just a more complicated way of implementing global data

No it's not; at that point, the data is no longer global, but specific to the driver instance.

We have only one tegradrm, so the advantage is theoretical - the one driver gets the same pointer in both cases.

If we use static pointer with an accessor function, we can keep the solution contained to one source code file and the ownership of data is clear - tegradrm allocates and deallocates the object and is the sole user. Code is already in the patchset I sent.

Shared responsibility with host1x and tegradrm would work probably something like this:

tegradrm creates an object, and passes the reference to host1x (host1x_set_drm_pdata(host1x_platform_dev, object). host1x sets the pdata to a member in struct host1x. A getter host1x_get_drm_pdata() allows retrieving the object. DC would call it with "host1x_get_drm_pdata(to_platform_device(pdev->dev.parent))".

This assumes that tegradrm would keep ownership of the data and free it before host1x gets unloaded.

To me this sounds like a steep price and I fail to see the advantage.

Dummy device is something that would come then on top of this mechanism.

Terje

#87 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

In reply to Thierry Reding
Quoted 4 lines · Thierry Reding

Okay, so we're back on the topic of using globals. I need to assert again that this is not an option. If we were to use globals, then we could just as well leave out the dummy device and just do all of that in the tegra-drm driver's initialization function.

I found a way of dropping the global in a straightforward way, and introduce dummy device for drm_platform_init().

I added dummy device and driver, and moved the tegradrm global (previously called struct host1x *host1x) allocation to happen in the probe. In addition, probe calls device tree node traversal to do the tegra_drm_add_client() calls. The dummy device is owner for this global.

I changed the device tree node traversal so that it goes actually through each host1x child, checks if it's supported by tegradrm, and if so, sets its drvdata to point to the tegradrm data.

Each probe will add the client with tegra_drm_register_client(), and that will find the global via dev_get_drvdata(). In the end of probe, each driver will replace the drvdata with its own data.

I am also setting the coherent_dma_mask for dummy device so that it can be used with CMA FB helper.

Would this be ok for you? I could send a patchset with this implemented by tomorrow and let it simmer for 2-3 weeks due to my and everybody elses' holidays. I'm hoping we would have 2D acceleration in Linux kernel 3.9.

Terje

#88 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 9 lines · Terje Bergström
Quoted 4 lines · Thierry Reding

Okay, so we're back on the topic of using globals. I need to assert again that this is not an option. If we were to use globals, then we could just as well leave out the dummy device and just do all of that in the tegra-drm driver's initialization function.

I found a way of dropping the global in a straightforward way, and introduce dummy device for drm_platform_init().

Quoted 8 lines

I added dummy device and driver, and moved the tegradrm global (previously called struct host1x *host1x) allocation to happen in the probe. In addition, probe calls device tree node traversal to do the tegra_drm_add_client() calls. The dummy device is owner for this global.

I changed the device tree node traversal so that it goes actually through each host1x child, checks if it's supported by tegradrm, and if so, sets its drvdata to point to the tegradrm data.

I'm not sure that sounds right. drvdata is something that a driver should manage itself.

What's wrong with just having each device ask the host1x (its parent) for a pointer to the (dummy) tegradrm device. That seems extremely simple, and doesn't require abusing existing stuff like drvdata for non-standard purposes.

#89 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 7 lines · Stephen Warren

I'm not sure that sounds right. drvdata is something that a driver should manage itself.

What's wrong with just having each device ask the host1x (its parent) for a pointer to the (dummy) tegradrm device. That seems extremely simple, and doesn't require abusing existing stuff like drvdata for non-standard purposes.

This is tegradrm's own data, and it's tegradrm which accesses the pointer. So it's entirely something that the driver takes care of itself.

It's simplest if tegradrm takes care of its own data. That way there's no chance of confusion of ownership or lifecycle of the data. The only places which needs this access are the probe functions, and adding an API contract between two components just for these few calls sounds too much. All code after that anyway access drm_device->dev_private to get the pointer.

Terje

#90 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 11 lines · Terje Bergström
Quoted 7 lines · Stephen Warren

I'm not sure that sounds right. drvdata is something that a driver should manage itself.

What's wrong with just having each device ask the host1x (its parent) for a pointer to the (dummy) tegradrm device. That seems extremely simple, and doesn't require abusing existing stuff like drvdata for non-standard purposes.

This is tegradrm's own data, and it's tegradrm which accesses the pointer. So it's entirely something that the driver takes care of itself.

So it's fine for the tegradrm driver to manipulate the tegradrm (virtual) device's drvdata pointer.

It's not fine for tegradrm to manipulate the drvdata pointer of other devices; the host1x children. The drvdata pointer for other devices is reserved for those devices' driver's use only.

#91 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 6 lines · Stephen Warren

So it's fine for the tegradrm driver to manipulate the tegradrm (virtual) device's drvdata pointer.

It's not fine for tegradrm to manipulate the drvdata pointer of other devices; the host1x children. The drvdata pointer for other devices is reserved for those devices' driver's use only.

They're all tegradrm drivers, so tegradrm can manipulate its drvdata. The other simple way is global pointer. Let's aim now for a simple solution, and if later we find out it causes problems, let's fix it then.

Terje

#92 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 11 lines · Terje Bergström
Quoted 6 lines · Stephen Warren

So it's fine for the tegradrm driver to manipulate the tegradrm (virtual) device's drvdata pointer.

It's not fine for tegradrm to manipulate the drvdata pointer of other devices; the host1x children. The drvdata pointer for other devices is reserved for those devices' driver's use only.

They're all tegradrm drivers, so tegradrm can manipulate its drvdata. The other simple way is global pointer. Let's aim now for a simple solution, and if later we find out it causes problems, let's fix it then.

The problem with your proposed solution is that, even any of Stephen's valid objections aside, it won't work. Once the tegra-drm module is unloaded, the driver's data will be left in the current state and the link to the dummy device will be lost.

I don't think waiting for things to fail is the right option here. If we can make out this problem now, then now is the time to fix it. No excuses.

And quite frankly given how all the various host1x components are interlinked I think having a single function that gets the DRM dummy device for DRM-related clients isn't that bad.

Thierry

#93 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 4 lines · Thierry Reding

The problem with your proposed solution is that, even any of Stephen's valid objections aside, it won't work. Once the tegra-drm module is unloaded, the driver's data will be left in the current state and the link to the dummy device will be lost.

The dummy device is created by tegradrm's module init, because it's used only by tegradrm. When tegradrm is unloaded, all the tegradrm devices and drivers are unloaded and freed, including the dummy one.

Quoted 3 lines

I don't think waiting for things to fail is the right option here. If we can make out this problem now, then now is the time to fix it. No excuses.

Of course not. If we know of something that fails now, let's not do that.

Quoted 3 lines

And quite frankly given how all the various host1x components are interlinked I think having a single function that gets the DRM dummy device for DRM-related clients isn't that bad.

I like clear responsibilities. tegradrm is responsible for the DRM interface, and host1x driver is responsible for host1x. tegradrm owns its data, and can pass its pointers to the functions that need it.

But fine, I still don't like it, but I'll add host1x_set_tegradrm() and host1x_get_tegradrm(), which act as setter and getter for tegradrm's global data. I still think it's a solution to a problem we don't have, but we've wasted an order of magnitude more time debating it than it takes to implement.

Terje

#94 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 9 lines · Terje Bergström
Quoted 4 lines · Thierry Reding

The problem with your proposed solution is that, even any of Stephen's valid objections aside, it won't work. Once the tegra-drm module is unloaded, the driver's data will be left in the current state and the link to the dummy device will be lost.

The dummy device is created by tegradrm's module init, because it's used only by tegradrm. When tegradrm is unloaded, all the tegradrm devices and drivers are unloaded and freed, including the dummy one.

No, the children platform devices of host1x are not freed, so their driver data will still contain the data set by the previous call to their driver's .probe() function.

But reading what you said again, you were proposing to set the children driver data from the tegra-drm dummy device's .probe(). In that case it would probably work.

Quoted 8 lines
Quoted 3 lines

And quite frankly given how all the various host1x components are interlinked I think having a single function that gets the DRM dummy device for DRM-related clients isn't that bad.

I like clear responsibilities. tegradrm is responsible for the DRM interface, and host1x driver is responsible for host1x. tegradrm owns its data, and can pass its pointers to the functions that need it.

Quoted 5 lines

But fine, I still don't like it, but I'll add host1x_set_tegradrm() and host1x_get_tegradrm(), which act as setter and getter for tegradrm's global data. I still think it's a solution to a problem we don't have, but we've wasted an order of magnitude more time debating it than it takes to implement.

As Stephen already pointed out, since the host1x driver will already instantiate the dummy device, there's no point in adding a function to set the pointer to that device.

Adding a getter should be enough. And it should return a pointer to the dummy platform devices .dev field. Calling it host1x_get_drm_device() may make it more obvious about what it returns.

Thierry

#96 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

In reply to Terje Bergström
Quoted 7 lines · Terje Bergström
Quoted 4 lines · Thierry Reding

The problem with your proposed solution is that, even any of Stephen's valid objections aside, it won't work. Once the tegra-drm module is unloaded, the driver's data will be left in the current state and the link to the dummy device will be lost.

The dummy device is created by tegradrm's module init, because it's used

No, the tegradrm driver object might be registered by tegradrm's module init, but the dummy tegradrm platform device would need to be created/registered by host1x's probe. Otherwise, the device would get created even if there was no host1x/... in the system (disabled for some reason, multi-SoC kernel, ...)

#95 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

In reply to Thierry Reding
Quoted 13 lines · Thierry Reding
Quoted 11 lines · Terje Bergström
Quoted 5 lines · Thierry Reding

The problem with your proposed solution is that, even any of Stephen's valid objections aside, it won't work. Once the tegra-drm module is unloaded, the driver's data will be left in the current state and the link to the dummy device will be lost.

The dummy device is created by tegradrm's module init, because it's used only by tegradrm. When tegradrm is unloaded, all the tegradrm devices and drivers are unloaded and freed, including the dummy one.

Quoted 7 lines

No, the children platform devices of host1x are not freed, so their driver data will still contain the data set by the previous call to their driver's .probe() function.

But reading what you said again, you were proposing to set the children driver data from the tegra-drm dummy device's .probe(). In that case it would probably work.

Many things would work, but since tegradrm isn't (or at least should not be) the driver for the platform devices which are host1x's children, it shouldn't be randomly screwing around with those devices' drvdata fields.

#97 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

In reply to Stephen Warren
Quoted 7 lines · Stephen Warren
Quoted 6 lines · Terje Bergström
Quoted 4 lines · Thierry Reding

The problem with your proposed solution is that, even any of Stephen's valid objections aside, it won't work. Once the tegra-drm module is unloaded, the driver's data will be left in the current state and the link to the dummy device will be lost.

Quoted 7 lines
Quoted 1 line

The dummy device is created by tegradrm's module init, because it's used

No, the tegradrm driver object might be registered by tegradrm's module init, but the dummy tegradrm platform device would need to be created/registered by host1x's probe. Otherwise, the device would get created even if there was no host1x/... in the system (disabled for some reason, multi-SoC kernel, ...)

Oh. I was all the time thinking that dummy device needs to be created by tegradrm, because it's only used by tegradrm. But as we're mixing the responsibilities, we might then just as well go all the way.

Terje

#98 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

In reply to Stephen Warren
Quoted 4 lines · Stephen Warren

What's wrong with just having each device ask the host1x (its parent) for a pointer to the (dummy) tegradrm device. That seems extremely

We are talking about creating a dummy device because:
- we need to give something for drm_platform_init(),
- drm related data should be stored somewhere,
- some data must be passed to all driver probe() functions. This is not hw-related data, but just some lists that are used to ensure that all drivers have been initialised before calling drm_platform_init().

All these issues are purely tegra-drm related and solving them elsewhere (in host1x) would be just wrong! host1x would not even use the dummy device for anything so creating it there seems bizarre.

- Arto

#99 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 9 lines · Arto Merilainen
Quoted 4 lines · Stephen Warren

What's wrong with just having each device ask the host1x (its parent) for a pointer to the (dummy) tegradrm device. That seems extremely

We are talking about creating a dummy device because:
- we need to give something for drm_platform_init(),
- drm related data should be stored somewhere,

Yes to those too, I believe.

Quoted 3 lines

- some data must be passed to all driver probe() functions. This is not hw-related data, but just some lists that are used to ensure that all drivers have been initialised before calling drm_platform_init().

I haven't really thought through /when/ host1x would create the dummy device. I guess if tegradrm really must initialize after all the devices that it uses (rather than using something like deferred probe) then the above may be true.

Quoted 3 lines

All these issues are purely tegra-drm related and solving them elsewhere (in host1x) would be just wrong! host1x would not even use the dummy device for anything so creating it there seems bizarre.

I see the situation more like:

* There's host1x hardware.

* There's a low-level driver just for host1x itself; the host1x driver.

* There's a high-level driver for the entire host1x complex of devices. That is tegradrm. There may be more high-level drivers in the future (e.g. v4l2 camera driver if it needs to aggregate a bunch of host1x sub-devices liek tegradrm does).

* The presence of the host1x DT node logically implies that both the two drivers in the previous two points should be instantiated.

* Linux instantiates a single device per DT node.

* So, it's host1x's responsibility to instantiate the other device(s). I think it's reasonable for the host1x driver to know exactly what features the host1x HW complex supports; raw host1x access being one, and the higher level concept of a tegradrm being another. So, it's reasonable for host1x to trigger the instantiation of tegradrm.

* If DRM core didn't stomp on the device object's drvdata (or whichever field it is), I would recommend not creating a dummy device at all, but rather having the host1x driver directly implement multiple driver interfaces. There are many examples like this already in the kernel, e.g. combined GPIO+IRQ driver, combined GPIO+IRQ+pinctrl driver, etc.

#100 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 8 lines · Stephen Warren

* There's host1x hardware.

* There's a low-level driver just for host1x itself; the host1x driver.

* There's a high-level driver for the entire host1x complex of devices. That is tegradrm. There may be more high-level drivers in the future (e.g. v4l2 camera driver if it needs to aggregate a bunch of host1x sub-devices liek tegradrm does).

tegradrm is a driver for a couple of the host1x clients, namely DC and HDMI, and now adding 2D.

Quoted 10 lines

* The presence of the host1x DT node logically implies that both the two drivers in the previous two points should be instantiated.

* Linux instantiates a single device per DT node.

* So, it's host1x's responsibility to instantiate the other device(s). I think it's reasonable for the host1x driver to know exactly what features the host1x HW complex supports; raw host1x access being one, and the higher level concept of a tegradrm being another. So, it's reasonable for host1x to trigger the instantiation of tegradrm.

tegradrm has drivers for each device that it controls, so tegradrm via kernel device-driver model instantiates them. host1x driver doesn't need to do that.

Quoted 5 lines

* If DRM core didn't stomp on the device object's drvdata (or whichever field it is), I would recommend not creating a dummy device at all, but rather having the host1x driver directly implement multiple driver interfaces. There are many examples like this already in the kernel, e.g. combined GPIO+IRQ driver, combined GPIO+IRQ+pinctrl driver, etc.

This is the architecture that would imply host1x instantiating everything, and DRM being a subcomponent of host1x driver. But we didn't choose to go there. We agreed to have tegradrm and host1x drivers separate.

Terje

#101 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

In reply to Stephen Warren
Quoted 22 lines · Stephen Warren

I see the situation more like:

* There's host1x hardware.

* There's a low-level driver just for host1x itself; the host1x driver.

* There's a high-level driver for the entire host1x complex of devices. That is tegradrm. There may be more high-level drivers in the future (e.g. v4l2 camera driver if it needs to aggregate a bunch of host1x sub-devices liek tegradrm does).

* The presence of the host1x DT node logically implies that both the two drivers in the previous two points should be instantiated.

* Linux instantiates a single device per DT node.

* So, it's host1x's responsibility to instantiate the other device(s). I think it's reasonable for the host1x driver to know exactly what features the host1x HW complex supports; raw host1x access being one, and the higher level concept of a tegradrm being another. So, it's reasonable for host1x to trigger the instantiation of tegradrm.

Quoted 5 lines

* If DRM core didn't stomp on the device object's drvdata (or whichever field it is), I would recommend not creating a dummy device at all, but rather having the host1x driver directly implement multiple driver interfaces. There are many examples like this already in the kernel, e.g. combined GPIO+IRQ driver, combined GPIO+IRQ+pinctrl driver, etc.

We had a phone call with Stephen yesterday, and I finally understood why unbroken chain from DT to tegra-drm is important. The goals are to be able to modprobe tegra-drm without ill effects, and to auto-load tegra-drm module. I had been chasing a totally different goal.

Sorry about all the churn.

I think we have now two ways to go forward with cons and pros:
1) Keep host1x and tegra-drm as separate driver
+ Code almost done
- we need dummy device and dummy driver
- extra code and API when host1x creates dummy device and its passed
to tegra-drm
- tegra-drm device would need to be a child of host1x device. Having
virtual and real devices as host1x children sounds weird.

2) Merge host1x and tegra-drm into one module. drm is a subcomponent,
and whatever other personalities we wish would also be subcomponents of host1x. host1x calls tegra-drm directly to handle preparation for drm initialization. As they're in the same module, circular dependency is ok.
+ Simpler conceptually (no dummy device/driver)
+ Less code
- Proposal doesn't yet exist

Thierry, what do you think? I'd prefer option 2, as that keeps things simple and still fulfills the requirements. We probably would redo the patch "Remove redundant host1x" to actually move drm under host1x, and adds calls from host1x to parse_dt() directly. We'd probably leave the code otherwise mostly as it is now, so we'll drop whatever modifications we've done so far in my proposals. You can later pick up some things from our proposals if you want, but it's then up to you.

We could also later think about generalizing some of the list management to belong to host1x, but that'd be a follow-up and we can decide that later.

Terje

#102 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

On 01/04/2013 03:09 AM, Terje Bergström wrote:
...

Quoted 6 lines

I think we have now two ways to go forward with cons and pros:
1) Keep host1x and tegra-drm as separate driver
+ Code almost done
- we need dummy device and dummy driver
- extra code and API when host1x creates dummy device and its passed
to tegra-drm

Just to play devil's advocate:

I suspect that's only a few lines of code.

Quoted 2 lines

- tegra-drm device would need to be a child of host1x device. Having
virtual and real devices as host1x children sounds weird.

And I doubt that would cause problems.

Quoted 7 lines

2) Merge host1x and tegra-drm into one module. drm is a subcomponent,
and whatever other personalities we wish would also be subcomponents of host1x. host1x calls tegra-drm directly to handle preparation for drm initialization. As they're in the same module, circular dependency is ok.
+ Simpler conceptually (no dummy device/driver)
+ Less code
- Proposal doesn't yet exist

But that said, I agree this approach would be very reasonable; it seems to me that host1x really is the main HW behind a DRM driver or a V4L2 driver or ... As such, it seems quite reasonable for a single struct device to exist that represents host1x, and for the driver for that device to register both a DRM and a V4L2 driver etc. The code could physically be organized into separate modules, and under different Kconfig options for configurability etc.

But either way, I'll let you (Thierry and Terje) work out which way to go.

#103 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 9 lines · Stephen Warren

On 01/04/2013 03:09 AM, Terje Bergström wrote:
...

Quoted 6 lines

I think we have now two ways to go forward with cons and pros:
1) Keep host1x and tegra-drm as separate driver
+ Code almost done
- we need dummy device and dummy driver
- extra code and API when host1x creates dummy device and its passed
to tegra-drm

Quoted 3 lines

Just to play devil's advocate:

I suspect that's only a few lines of code.

Yes, that's true. There's some overhead, but there's not too many actual code lines.

Quoted 4 lines
Quoted 2 lines

- tegra-drm device would need to be a child of host1x device. Having
virtual and real devices as host1x children sounds weird.

And I doubt that would cause problems.

True. It could become a problem if the driver just assumed that all host1x children are actual hardware, but we could avoid that.

Quoted 16 lines
Quoted 7 lines

2) Merge host1x and tegra-drm into one module. drm is a subcomponent,
and whatever other personalities we wish would also be subcomponents of host1x. host1x calls tegra-drm directly to handle preparation for drm initialization. As they're in the same module, circular dependency is ok.
+ Simpler conceptually (no dummy device/driver)
+ Less code
- Proposal doesn't yet exist

But that said, I agree this approach would be very reasonable; it seems to me that host1x really is the main HW behind a DRM driver or a V4L2 driver or ... As such, it seems quite reasonable for a single struct device to exist that represents host1x, and for the driver for that device to register both a DRM and a V4L2 driver etc. The code could physically be organized into separate modules, and under different Kconfig options for configurability etc.

Quoted 1 line

But either way, I'll let you (Thierry and Terje) work out which way to go.

If we want separate modules, we'd need the dummy device & dummy driver binding between them. We could also just put them in the same module. It'd make DRM a requirement to host1x driver, but given the current structure, I think that'd be reasonable. We could later make it more configurable if needed. Does this now make tegra-drm and host1x too dependent on each other? I'm not sure.

I also like the fact that we don't have to export APIs to include, but we can (if we so choose) keep all tegra-drm-host1x-APIs in local header files. As we have noted, the two drivers are tightly interconnected, changing the APIs is easier if we can just work on the same directory hierarchy.

Terje

#104 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 9 lines · Terje Bergström
Quoted 8 lines · Stephen Warren

On 01/04/2013 03:09 AM, Terje Bergström wrote:
...

Quoted 6 lines

I think we have now two ways to go forward with cons and pros:
1) Keep host1x and tegra-drm as separate driver
+ Code almost done
- we need dummy device and dummy driver
- extra code and API when host1x creates dummy device and its passed
to tegra-drm

...

Quoted 16 lines
Quoted 16 lines
Quoted 7 lines

2) Merge host1x and tegra-drm into one module. drm is a subcomponent,
and whatever other personalities we wish would also be subcomponents of host1x. host1x calls tegra-drm directly to handle preparation for drm initialization. As they're in the same module, circular dependency is ok.
+ Simpler conceptually (no dummy device/driver)
+ Less code
- Proposal doesn't yet exist

But that said, I agree this approach would be very reasonable; it seems to me that host1x really is the main HW behind a DRM driver or a V4L2 driver or ... As such, it seems quite reasonable for a single struct device to exist that represents host1x, and for the driver for that device to register both a DRM and a V4L2 driver etc. The code could physically be organized into separate modules, and under different Kconfig options for configurability etc.

Quoted 4 lines
Quoted 1 line

But either way, I'll let you (Thierry and Terje) work out which way to go.

If we want separate modules, we'd need the dummy device & dummy driver binding between them.

I haven't really thought it through, but I don't think so; I was thinking separate modules more just to allow linking smaller chunks of code at once rather than allowing optional functionality via loading (or not) various modules. Hence, simple function calls between the files/modules. Still, there may well be no need at all to split it into separate modules.

#105 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

In reply to Stephen Warren
Quoted 34 lines · Stephen Warren

On 01/04/2013 03:09 AM, Terje Bergström wrote:
...

Quoted 6 lines

I think we have now two ways to go forward with cons and pros:
1) Keep host1x and tegra-drm as separate driver
+ Code almost done
- we need dummy device and dummy driver
- extra code and API when host1x creates dummy device and its passed
to tegra-drm

Just to play devil's advocate:

I suspect that's only a few lines of code.

Quoted 2 lines

- tegra-drm device would need to be a child of host1x device. Having
virtual and real devices as host1x children sounds weird.

And I doubt that would cause problems.

Quoted 7 lines

2) Merge host1x and tegra-drm into one module. drm is a subcomponent,
and whatever other personalities we wish would also be subcomponents of host1x. host1x calls tegra-drm directly to handle preparation for drm initialization. As they're in the same module, circular dependency is ok.
+ Simpler conceptually (no dummy device/driver)
+ Less code
- Proposal doesn't yet exist

But that said, I agree this approach would be very reasonable; it seems to me that host1x really is the main HW behind a DRM driver or a V4L2 driver or ... As such, it seems quite reasonable for a single struct device to exist that represents host1x, and for the driver for that device to register both a DRM and a V4L2 driver etc. The code could physically be organized into separate modules, and under different Kconfig options for configurability etc.

Quoted 1 line

But either way, I'll let you (Thierry and Terje) work out which way to go.

Sorry for not getting back to you on this earlier. I just remembered this thread when I saw Terje's latest patch series.

I agree that having everything in one location will make things a lot easier, even if it means we have to add the tegra-drm driver to a new location. In the long run I think this will pay off, though.

That said, I see that Terje has chosen this approach in his latest series, so it's all good.

Thierry

#106 lore raw

Re: [RFC v2 6/8] gpu: drm: tegra: Remove redundant host1x

Quoted 9 lines · Thierry Reding

Sorry for not getting back to you on this earlier. I just remembered this thread when I saw Terje's latest patch series.

I agree that having everything in one location will make things a lot easier, even if it means we have to add the tegra-drm driver to a new location. In the long run I think this will pay off, though.

That said, I see that Terje has chosen this approach in his latest series, so it's all good.

*whew* Thanks Thierry. I'm not entirely sure that drivers/gpu/host1x is the correct location, though - host1x looks pretty lonely there. If anybody has a strong opinion about the location, I'm willing to adjust.

Terje