[RFC 1/3] WIP: drm/tegra: Add 3D support

2013-04-04 Thread Thierry Reding
This is a preliminary patch that adds support for 3D support on top of
Terje's and Arto's host1x and gr2d patches.

There are a few things that still need to be resolved before this can be
applied. I haven't been able to test Tegra30 support so it'd be good if
somebody with hardware could give it a try. I can probably arrange to
test it on a CardHu if nobody else steps up, but it'll take a while
until I get that setup. Looking at the downstream kernels indicates that
Tegra30 has a second clock and powergate domain and if those really are
required then this patch won't work on Tegra30.

One other important piece that is missing is a list of address registers
to feed to the firewall so that submitted command streams can be checked
for validity. I've already talked to Terje about that, but it seems like
it may turn out to be problematic. What with NVIDIA not wanting to
provide the register descriptions and all that. We'll need to resolve
this in some way before this patch can be merged.

Finally I want to refactor some of the commonalities between gr2d and
gr3d so that they can share more code.

If people want to give this a spin, there are some very basic test
programs available here[0]. The tests from the grate repository are
probably the most useful right now since they test both the gr2d and
gr3d modules and therefore can be used to verify that this patch
actually works.

[0]: https://github.com/organizations/grate-driver

Signed-off-by: Thierry Reding 
---
 drivers/gpu/host1x/Makefile   |   1 +
 drivers/gpu/host1x/dev.c  |   7 +
 drivers/gpu/host1x/dev.h  |   1 +
 drivers/gpu/host1x/drm/drm.c  |   2 +
 drivers/gpu/host1x/drm/gr3d.c | 289 ++
 drivers/gpu/host1x/host1x.h   |   3 +-
 6 files changed, 302 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/host1x/drm/gr3d.c

diff --git a/drivers/gpu/host1x/Makefile b/drivers/gpu/host1x/Makefile
index 3b037b6..5802e1b 100644
--- a/drivers/gpu/host1x/Makefile
+++ b/drivers/gpu/host1x/Makefile
@@ -17,4 +17,5 @@ host1x-$(CONFIG_DRM_TEGRA) += drm/drm.o drm/fb.o drm/dc.o
 host1x-$(CONFIG_DRM_TEGRA) += drm/output.o drm/rgb.o drm/hdmi.o
 host1x-$(CONFIG_DRM_TEGRA) += drm/gem.o
 host1x-$(CONFIG_DRM_TEGRA) += drm/gr2d.o
+host1x-$(CONFIG_DRM_TEGRA) += drm/gr3d.o
 obj-$(CONFIG_TEGRA_HOST1X) += host1x.o
diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c
index 28e28a2..6daa3be 100644
--- a/drivers/gpu/host1x/dev.c
+++ b/drivers/gpu/host1x/dev.c
@@ -213,11 +213,17 @@ static int __init tegra_host1x_init(void)
err = platform_driver_register(_gr2d_driver);
if (err < 0)
goto unregister_hdmi;
+
+   err = platform_driver_register(_gr3d_driver);
+   if (err < 0)
+   goto unregister_gr2d;
 #endif

return 0;

 #ifdef CONFIG_DRM_TEGRA
+unregister_gr2d:
+   platform_driver_unregister(_gr2d_driver);
 unregister_hdmi:
platform_driver_unregister(_hdmi_driver);
 unregister_dc:
@@ -232,6 +238,7 @@ module_init(tegra_host1x_init);
 static void __exit tegra_host1x_exit(void)
 {
 #ifdef CONFIG_DRM_TEGRA
+   platform_driver_unregister(_gr3d_driver);
platform_driver_unregister(_gr2d_driver);
platform_driver_unregister(_hdmi_driver);
platform_driver_unregister(_dc_driver);
diff --git a/drivers/gpu/host1x/dev.h b/drivers/gpu/host1x/dev.h
index a1607d6..406237a 100644
--- a/drivers/gpu/host1x/dev.h
+++ b/drivers/gpu/host1x/dev.h
@@ -304,5 +304,6 @@ static inline void host1x_hw_show_mlocks(struct host1x 
*host, struct output *o)
 extern struct platform_driver tegra_hdmi_driver;
 extern struct platform_driver tegra_dc_driver;
 extern struct platform_driver tegra_gr2d_driver;
+extern struct platform_driver tegra_gr3d_driver;

 #endif
diff --git a/drivers/gpu/host1x/drm/drm.c b/drivers/gpu/host1x/drm/drm.c
index 2b561c9..298c5f0 100644
--- a/drivers/gpu/host1x/drm/drm.c
+++ b/drivers/gpu/host1x/drm/drm.c
@@ -85,9 +85,11 @@ static int host1x_parse_dt(struct host1x_drm *host1x)
"nvidia,tegra20-dc",
"nvidia,tegra20-hdmi",
"nvidia,tegra20-gr2d",
+   "nvidia,tegra20-gr3d",
"nvidia,tegra30-dc",
"nvidia,tegra30-hdmi",
"nvidia,tegra30-gr2d",
+   "nvidia,tegra30-gr3d",
};
unsigned int i;
int err;
diff --git a/drivers/gpu/host1x/drm/gr3d.c b/drivers/gpu/host1x/drm/gr3d.c
new file mode 100644
index 000..58fe791
--- /dev/null
+++ b/drivers/gpu/host1x/drm/gr3d.c
@@ -0,0 +1,289 @@
+/*
+ * Copyright (C) 2013 Avionic Design GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "host1x_client.h"
+#include "channel.h"
+#include "drm.h"
+#include "gem.h"
+#include "job.h"
+#include "syncpt.h"
+
+struct 

[RFC 1/3] WIP: drm/tegra: Add 3D support

2013-04-04 Thread Thierry Reding
This is a preliminary patch that adds support for 3D support on top of
Terje's and Arto's host1x and gr2d patches.

There are a few things that still need to be resolved before this can be
applied. I haven't been able to test Tegra30 support so it'd be good if
somebody with hardware could give it a try. I can probably arrange to
test it on a CardHu if nobody else steps up, but it'll take a while
until I get that setup. Looking at the downstream kernels indicates that
Tegra30 has a second clock and powergate domain and if those really are
required then this patch won't work on Tegra30.

One other important piece that is missing is a list of address registers
to feed to the firewall so that submitted command streams can be checked
for validity. I've already talked to Terje about that, but it seems like
it may turn out to be problematic. What with NVIDIA not wanting to
provide the register descriptions and all that. We'll need to resolve
this in some way before this patch can be merged.

Finally I want to refactor some of the commonalities between gr2d and
gr3d so that they can share more code.

If people want to give this a spin, there are some very basic test
programs available here[0]. The tests from the grate repository are
probably the most useful right now since they test both the gr2d and
gr3d modules and therefore can be used to verify that this patch
actually works.

[0]: https://github.com/organizations/grate-driver

Signed-off-by: Thierry Reding thierry.red...@avionic-design.de
---
 drivers/gpu/host1x/Makefile   |   1 +
 drivers/gpu/host1x/dev.c  |   7 +
 drivers/gpu/host1x/dev.h  |   1 +
 drivers/gpu/host1x/drm/drm.c  |   2 +
 drivers/gpu/host1x/drm/gr3d.c | 289 ++
 drivers/gpu/host1x/host1x.h   |   3 +-
 6 files changed, 302 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/host1x/drm/gr3d.c

diff --git a/drivers/gpu/host1x/Makefile b/drivers/gpu/host1x/Makefile
index 3b037b6..5802e1b 100644
--- a/drivers/gpu/host1x/Makefile
+++ b/drivers/gpu/host1x/Makefile
@@ -17,4 +17,5 @@ host1x-$(CONFIG_DRM_TEGRA) += drm/drm.o drm/fb.o drm/dc.o
 host1x-$(CONFIG_DRM_TEGRA) += drm/output.o drm/rgb.o drm/hdmi.o
 host1x-$(CONFIG_DRM_TEGRA) += drm/gem.o
 host1x-$(CONFIG_DRM_TEGRA) += drm/gr2d.o
+host1x-$(CONFIG_DRM_TEGRA) += drm/gr3d.o
 obj-$(CONFIG_TEGRA_HOST1X) += host1x.o
diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c
index 28e28a2..6daa3be 100644
--- a/drivers/gpu/host1x/dev.c
+++ b/drivers/gpu/host1x/dev.c
@@ -213,11 +213,17 @@ static int __init tegra_host1x_init(void)
err = platform_driver_register(tegra_gr2d_driver);
if (err  0)
goto unregister_hdmi;
+
+   err = platform_driver_register(tegra_gr3d_driver);
+   if (err  0)
+   goto unregister_gr2d;
 #endif
 
return 0;
 
 #ifdef CONFIG_DRM_TEGRA
+unregister_gr2d:
+   platform_driver_unregister(tegra_gr2d_driver);
 unregister_hdmi:
platform_driver_unregister(tegra_hdmi_driver);
 unregister_dc:
@@ -232,6 +238,7 @@ module_init(tegra_host1x_init);
 static void __exit tegra_host1x_exit(void)
 {
 #ifdef CONFIG_DRM_TEGRA
+   platform_driver_unregister(tegra_gr3d_driver);
platform_driver_unregister(tegra_gr2d_driver);
platform_driver_unregister(tegra_hdmi_driver);
platform_driver_unregister(tegra_dc_driver);
diff --git a/drivers/gpu/host1x/dev.h b/drivers/gpu/host1x/dev.h
index a1607d6..406237a 100644
--- a/drivers/gpu/host1x/dev.h
+++ b/drivers/gpu/host1x/dev.h
@@ -304,5 +304,6 @@ static inline void host1x_hw_show_mlocks(struct host1x 
*host, struct output *o)
 extern struct platform_driver tegra_hdmi_driver;
 extern struct platform_driver tegra_dc_driver;
 extern struct platform_driver tegra_gr2d_driver;
+extern struct platform_driver tegra_gr3d_driver;
 
 #endif
diff --git a/drivers/gpu/host1x/drm/drm.c b/drivers/gpu/host1x/drm/drm.c
index 2b561c9..298c5f0 100644
--- a/drivers/gpu/host1x/drm/drm.c
+++ b/drivers/gpu/host1x/drm/drm.c
@@ -85,9 +85,11 @@ static int host1x_parse_dt(struct host1x_drm *host1x)
nvidia,tegra20-dc,
nvidia,tegra20-hdmi,
nvidia,tegra20-gr2d,
+   nvidia,tegra20-gr3d,
nvidia,tegra30-dc,
nvidia,tegra30-hdmi,
nvidia,tegra30-gr2d,
+   nvidia,tegra30-gr3d,
};
unsigned int i;
int err;
diff --git a/drivers/gpu/host1x/drm/gr3d.c b/drivers/gpu/host1x/drm/gr3d.c
new file mode 100644
index 000..58fe791
--- /dev/null
+++ b/drivers/gpu/host1x/drm/gr3d.c
@@ -0,0 +1,289 @@
+/*
+ * Copyright (C) 2013 Avionic Design GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include linux/clk.h
+#include linux/module.h
+#include linux/platform_device.h
+#include linux/tegra-powergate.h
+