drm/tegra: Add 3D support
cover drm/tegra: Add 3D support
This small series of patches adds support for the 3D engine found on NVIDIA Tegra SoCs. It builds on top of Terje's and Arto's host1x and gr2d patches. A couple of things still need to be done before this can be merged, though.
Patch 1 is the central piece of the series. It adds support for using the gr3d engine via the same DRM IOCTLs that gr2d uses. A very basic set of programs to test this can be found here[0].
Patch 2 adds support for the XBGR8888 format, which seems to be what most gr3d programs use. It also adds the RGB565 as a format supported by planes. This latter part could be moved to a separate patch, but I didn't think that was necessary.
Patch 3 finally allows buffer objects to be marked as tiled so that the display controller can scan them out appropriately.
Thierry
[0]: https://github.com/organizations/grate-driver
Thierry Reding (3):
WIP: drm/tegra: Add 3D support
drm/tegra: Support the XBGR8888 pixelformat
drm/tegra: Add support for tiled buffer objects
drivers/gpu/host1x/Makefile | 1 + drivers/gpu/host1x/dev.c | 7 + drivers/gpu/host1x/dev.h | 1 + drivers/gpu/host1x/drm/dc.c | 16 +++ drivers/gpu/host1x/drm/dc.h | 4 + drivers/gpu/host1x/drm/drm.c | 4 +- drivers/gpu/host1x/drm/drm.h | 2 + drivers/gpu/host1x/drm/fb.c | 12 +- drivers/gpu/host1x/drm/gem.c | 20 ++- drivers/gpu/host1x/drm/gem.h | 13 +- drivers/gpu/host1x/drm/gr3d.c | 289 ++++++++++++++++++++++++++++++++++++++++++ drivers/gpu/host1x/host1x.h | 3 +- include/uapi/drm/tegra_drm.h | 2 + 13 files changed, 360 insertions(+), 14 deletions(-) create mode 100644 drivers/gpu/host1x/drm/gr3d.c
Signature · 1 line
1.8.2
A message that is not in the archive (sent off-list or not yet received): 1365084560-11069-1-git-send-email-thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org
RFC 1/3 WIP: drm/tegra: Add 3D support
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
--- 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
drivers/gpu/host1x/Makefile +1 -0
@@ -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
drivers/gpu/host1x/dev.c +7 -0
@@ -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);
drivers/gpu/host1x/dev.h +1 -0
@@ -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
drivers/gpu/host1x/drm/drm.c +2 -0
@@ -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;
drivers/gpu/host1x/drm/gr3d.c new file +289 -0
289 lines not on this page · raw message
drivers/gpu/host1x/host1x.h +2 -1
@@ -24,7 +24,8 @@enum host1x_class {HOST1X_CLASS_HOST1X =0x1 ,HOST1X_CLASS_GR2D =0x51 , -HOST1X_CLASS_GR2D_SB =0x52 +HOST1X_CLASS_GR2D_SB =0x52 , +HOST1X_CLASS_GR3D =0x60 , };#endif
Signature · 1 line
1.8.2
RFC 2/3 drm/tegra: Support the XBGR8888 pixelformat
In reply to a message not in the archiveWhile at it, also include the RGB565 pixelformat in the list of formats supported by overlays.
--- drivers/gpu/host1x/drm/dc.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/host1x/drm/dc.c +5 -0
@@ -108,7 +108,9 @@ static const struct drm_plane_funcs tegra_plane_funcs = { };static const uint32_t plane_formats[] = { +DRM_FORMAT_XBGR8888 ,DRM_FORMAT_XRGB8888 , +DRM_FORMAT_RGB565 ,DRM_FORMAT_UYVY ,DRM_FORMAT_YUV420 ,DRM_FORMAT_YUV422 ,
@@ -546,6 +548,9 @@ int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,unsigned int tegra_dc_format (uint32_t format) {switch (format) { +case DRM_FORMAT_XBGR8888 : +return WIN_COLOR_DEPTH_R8G8B8A8 ; +case DRM_FORMAT_XRGB8888 :return WIN_COLOR_DEPTH_B8G8R8A8 ;
Signature · 1 line
1.8.2
RFC 3/3 drm/tegra: Add support for tiled buffer objects
In reply to a message not in the archiveThe gr2d and gr3d engines work more efficiently on buffers with a tiled memory layout. Allow created buffers to be marked as tiled so that the display controller can scan them out properly.
--- drivers/gpu/host1x/drm/dc.c | 11 +++++++++++ drivers/gpu/host1x/drm/dc.h | 4 ++++ drivers/gpu/host1x/drm/drm.c | 2 +- drivers/gpu/host1x/drm/drm.h | 2 ++ drivers/gpu/host1x/drm/fb.c | 12 +++++++++++- drivers/gpu/host1x/drm/gem.c | 20 +++++++++++++------- drivers/gpu/host1x/drm/gem.h | 13 +++++++++---- include/uapi/drm/tegra_drm.h | 2 ++ 8 files changed, 53 insertions(+), 13 deletions(-)
drivers/gpu/host1x/drm/dc.c +11 -0
@@ -51,6 +51,7 @@ static int tegra_plane_update(struct drm_plane *plane, struct drm_crtc *crtc, window.dst.h = crtc_h; window.format =tegra_dc_format (fb->pixel_format); window.bits_per_pixel = fb->bits_per_pixel; + window.tiled =tegra_fb_is_tiled (fb);for (i =0 ; i <drm_format_num_planes (fb->pixel_format); i++) {struct tegra_bo *bo =tegra_fb_get_plane (fb, i);
@@ -492,6 +493,16 @@ int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,tegra_dc_writel (dc, h_offset,DC_WINBUF_ADDR_H_OFFSET );tegra_dc_writel (dc, v_offset,DC_WINBUF_ADDR_V_OFFSET ); +if (window->tiled) { + value =DC_WIN_BUFFER_ADDR_MODE_TILE_UV | +DC_WIN_BUFFER_ADDR_MODE_TILE ; + }else { + value =DC_WIN_BUFFER_ADDR_MODE_LINEAR_UV | +DC_WIN_BUFFER_ADDR_MODE_LINEAR ; + } + +tegra_dc_writel (dc, value,DC_WIN_BUFFER_ADDR_MODE ); + value =WIN_ENABLE ;if (yuv) {
drivers/gpu/host1x/drm/dc.h +4 -0
@@ -365,6 +365,10 @@#define DC_WIN_BUF_STRIDE 0x70b#define DC_WIN_UV_BUF_STRIDE 0x70c#define DC_WIN_BUFFER_ADDR_MODE 0x70d +#define DC_WIN_BUFFER_ADDR_MODE_LINEAR (0 << 0) +#define DC_WIN_BUFFER_ADDR_MODE_TILE (1 << 0) +#define DC_WIN_BUFFER_ADDR_MODE_LINEAR_UV (0 << 16) +#define DC_WIN_BUFFER_ADDR_MODE_TILE_UV (1 << 16)#define DC_WIN_DV_CONTROL 0x70e#define DC_WIN_BLEND_NOKEY 0x70f
drivers/gpu/host1x/drm/drm.c +1 -1
@@ -328,7 +328,7 @@ static int tegra_gem_create(struct drm_device *drm, void *data,struct drm_tegra_gem_create *args = data;struct tegra_bo *bo; - bo =tegra_bo_create_with_handle (file, drm, args->size, + bo =tegra_bo_create_with_handle (file, drm, args->size, args->flags, &args->handle);if (IS_ERR (bo))return PTR_ERR (bo);
drivers/gpu/host1x/drm/drm.h +2 -0
@@ -162,6 +162,7 @@ struct tegra_dc_window {unsigned int format;unsigned int stride[2 ];unsigned long base[3 ]; +bool tiled; };/* from dc.c */
@@ -262,6 +263,7 @@ extern int tegra_output_exit(struct tegra_output *output);/* from fb.c */ struct tegra_bo *tegra_fb_get_plane (struct drm_framebuffer *framebuffer,unsigned int index); +bool tegra_fb_is_tiled (struct drm_framebuffer *framebuffer);extern int tegra_drm_fb_init (struct drm_device *drm);extern void tegra_drm_fb_exit (struct drm_device *drm);extern void tegra_fbdev_restore_mode (struct tegra_fbdev *fbdev);
drivers/gpu/host1x/drm/fb.c +11 -1
@@ -34,6 +34,16 @@ struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,return fb->planes[index]; } +bool tegra_fb_is_tiled (struct drm_framebuffer *framebuffer) +{ +struct tegra_fb *fb =to_tegra_fb (framebuffer); + +if (fb->planes[0 ]->flags &TEGRA_BO_TILED ) +return true; + +return false; +} +static void tegra_fb_destroy (struct drm_framebuffer *framebuffer) {struct tegra_fb *fb =to_tegra_fb (framebuffer);
@@ -188,7 +198,7 @@ static int tegra_fbdev_probe(struct drm_fb_helper *helper, size = cmd.pitches[0 ] * cmd.height; - bo =tegra_bo_create (drm, size); + bo =tegra_bo_create (drm, size,0 );if (IS_ERR (bo))return PTR_ERR (bo);
drivers/gpu/host1x/drm/gem.c +13 -7
@@ -24,6 +24,7 @@#include <linux/export.h> #include <linux/dma-mapping.h> +#include <drm/tegra_drm.h> #include <drm/drmP.h> #include <drm/drm.h>
@@ -111,7 +112,8 @@ unsigned int tegra_bo_get_mmap_offset(struct tegra_bo *bo)return (unsigned int )bo->gem.map_list.hash.key <<PAGE_SHIFT ; } -struct tegra_bo *tegra_bo_create (struct drm_device *drm,unsigned int size) +struct tegra_bo *tegra_bo_create (struct drm_device *drm,unsigned int size, +unsigned long flags) {struct tegra_bo *bo;int err;
@@ -140,6 +142,9 @@ struct tegra_bo *tegra_bo_create(struct drm_device *drm, unsigned int size)if (err) goto err_mmap; +if (flags &DRM_TEGRA_GEM_CREATE_TILED ) + bo->flags |=TEGRA_BO_TILED ; +return bo; err_mmap:
@@ -154,14 +159,15 @@ err_dma: }struct tegra_bo *tegra_bo_create_with_handle (struct drm_file *file, -struct drm_device *drm, -unsigned int size, -unsigned int *handle) +struct drm_device *drm, +unsigned int size, +unsigned long flags, +unsigned int *handle) {struct tegra_bo *bo;int ret; - bo =tegra_bo_create (drm, size); + bo =tegra_bo_create (drm, size, flags);if (IS_ERR (bo))return bo;
@@ -203,8 +209,8 @@ int tegra_bo_dumb_create(struct drm_file *file, struct drm_device *drm,if (args->size < args->pitch * args->height) args->size = args->pitch * args->height; - bo =tegra_bo_create_with_handle (file, drm, args->size, - &args->handle); + bo =tegra_bo_create_with_handle (file, drm, args->size,0 , + &args->handle);if (IS_ERR (bo))return PTR_ERR (bo);
drivers/gpu/host1x/drm/gem.h +9 -4
@@ -24,9 +24,12 @@#include "host1x_bo.h" +#define TEGRA_BO_TILED (1 << 0) +struct tegra_bo {struct drm_gem_object gem;struct host1x_bo base; +unsigned long flags;dma_addr_t paddr;void *vaddr; };
@@ -38,11 +41,13 @@ static inline struct tegra_bo *to_tegra_bo(struct drm_gem_object *gem)extern const struct host1x_bo_ops tegra_bo_ops; -struct tegra_bo *tegra_bo_create (struct drm_device *drm,unsigned int size); +struct tegra_bo *tegra_bo_create (struct drm_device *drm,unsigned int size, +unsigned long flags);struct tegra_bo *tegra_bo_create_with_handle (struct drm_file *file, -struct drm_device *drm, -unsigned int size, -unsigned int *handle); +struct drm_device *drm, +unsigned int size, +unsigned long flags, +unsigned int *handle);void tegra_bo_free_object (struct drm_gem_object *gem);unsigned int tegra_bo_get_mmap_offset (struct tegra_bo *bo); int tegra_bo_dumb_create(struct drm_file *file, struct drm_device *drm,
include/uapi/drm/tegra_drm.h +2 -0
@@ -17,6 +17,8 @@ #ifndef _UAPI_TEGRA_DRM_H_ #define _UAPI_TEGRA_DRM_H_ +#define DRM_TEGRA_GEM_CREATE_TILED (1 << 0) + struct drm_tegra_gem_create { __u64 size; __u32 flags;
Signature · 1 line
1.8.2
On Thu, Apr 04, 2013 at 04:09:17PM +0200, Thierry Reding wrote:
[...]
Quoted 1 line
This apparently redirects to github.com unless you're a member of the grate-driver organization. So the correct link should actually be:
https://github.com/grate-driver
Thanks Rob for pointing this out!
Thierry