rmk's Dove DRM/TDA19988 Cubox driver
Subsystems (3)
v2 cover rmk's Dove DRM/TDA19988 Cubox driver
This is version 2 of my DRM driver. Changes since the previous version:
1. It's now called Armada not Dove, because the "LCD controllers" aka CRTCs are found in Armada 16x as well as Armada 510 Dove. The Armada 16x is preliminary work.
2. Cursor support is now a separate patch. I've tried several formats, and 64x32 ARGB is the one I've settled on for the time being, though the driver will permit 32x64 as well. This, however, is not available with Armada 16x hardware. This patch will be a separate follow-up to this. The reason for this is it's in a separate branch which conflicts with this (and my NXP-TDA19988 output driver branch.) The value of this is still questionable due to the restrictions in the hardware meaning the entire cursor has to be reloaded near the edge of the screen.
This also may interfere with the interlaced support; however the DRM i2c TDA998x driver seems incapable of supporting interlace at present. (It works with the CEA mode number programmed but not if you program with mode timings.)
3. A slave encoder output encoder which contains nothing specific to TDA19988 nor Cubox. This data is now in the top level driver, and can be provided using whatever method is desirable (eg, from DT.)
What *can't* be done without a rewrite of the DRM slave encoder backend is to have the TDA998x I2C device provided by DT. There are mumblings about redoing the slave encoder API, hopefully this will be fixed there.
4. Finished off the page flip support, which now gets used on mode changes as well. Page flip as a whole still isn't tested.
5. Removal of default mode and reporting of unknown connector status. The kernel side will select 1024x768 if no connectors are connected - this will cause problems if your display reports that it supports 1024x768 but it doesn't actually. Xorg will do similar too.
What is not in this patch set yet, but I have patches for:
1. Pulled the clock stuff out of the armada_crtc.c file into the top level. Armada 16x has different clocking options to Armada 510, and certain bits in the clock configuration register are different. This needs to be dealt with like we do in AMBA devices with "variant" support. So in a DT environment, we'd have:
compatible = "marvell,armada510-lcd"; or compatible = "marvell,armada16x-lcd";
and the driver adjusts according to that.
2. Sebastian's additional patches
RFC PATCH 2/8 DRM: Armada: Add Armada DRM driver
This patch adds support for the pair of LCD controllers on the Marvell Armada 510 SoCs. This driver supports:
- multiple contiguous scanout buffers for video and graphics
- shm backed cacheable buffer objects for X pixmaps for Vivante GPU acceleration
- dual lcd0 and lcd1 crt operation
- video overlay on each LCD crt
- page flipping of the main scanout buffers
Included in this commit is the core driver with no output support; output support is platform and encoder driver dependent.
--- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/armada/Kconfig | 15 + drivers/gpu/drm/armada/Makefile | 6 + drivers/gpu/drm/armada/armada_crtc.c | 766 +++++++++++++++++++++++++++++++ drivers/gpu/drm/armada/armada_crtc.h | 75 +++ drivers/gpu/drm/armada/armada_debugfs.c | 186 ++++++++ drivers/gpu/drm/armada/armada_drm.h | 62 +++ drivers/gpu/drm/armada/armada_drv.c | 326 +++++++++++++ drivers/gpu/drm/armada/armada_fb.c | 156 +++++++ drivers/gpu/drm/armada/armada_fb.h | 21 + drivers/gpu/drm/armada/armada_fbdev.c | 210 +++++++++ drivers/gpu/drm/armada/armada_gem.c | 420 +++++++++++++++++ drivers/gpu/drm/armada/armada_gem.h | 41 ++ drivers/gpu/drm/armada/armada_hw.h | 295 ++++++++++++ drivers/gpu/drm/armada/armada_ioctl.h | 128 +++++ drivers/gpu/drm/armada/armada_ioctlP.h | 22 + drivers/gpu/drm/armada/armada_output.c | 159 +++++++ drivers/gpu/drm/armada/armada_output.h | 38 ++ drivers/gpu/drm/armada/armada_overlay.c | 514 +++++++++++++++++++++ drivers/gpu/drm/armada/armada_slave.c | 138 ++++++ drivers/gpu/drm/armada/armada_slave.h | 26 + drivers/gpu/drm/armada/drm_helper.h | 31 ++ 23 files changed, 3638 insertions(+), 0 deletions(-) create mode 100644 drivers/gpu/drm/armada/Kconfig create mode 100644 drivers/gpu/drm/armada/Makefile create mode 100644 drivers/gpu/drm/armada/armada_crtc.c create mode 100644 drivers/gpu/drm/armada/armada_crtc.h create mode 100644 drivers/gpu/drm/armada/armada_debugfs.c create mode 100644 drivers/gpu/drm/armada/armada_drm.h create mode 100644 drivers/gpu/drm/armada/armada_drv.c create mode 100644 drivers/gpu/drm/armada/armada_fb.c create mode 100644 drivers/gpu/drm/armada/armada_fb.h create mode 100644 drivers/gpu/drm/armada/armada_fbdev.c create mode 100644 drivers/gpu/drm/armada/armada_gem.c create mode 100644 drivers/gpu/drm/armada/armada_gem.h create mode 100644 drivers/gpu/drm/armada/armada_hw.h create mode 100644 drivers/gpu/drm/armada/armada_ioctl.h create mode 100644 drivers/gpu/drm/armada/armada_ioctlP.h create mode 100644 drivers/gpu/drm/armada/armada_output.c create mode 100644 drivers/gpu/drm/armada/armada_output.h create mode 100644 drivers/gpu/drm/armada/armada_overlay.c create mode 100644 drivers/gpu/drm/armada/armada_slave.c create mode 100644 drivers/gpu/drm/armada/armada_slave.h create mode 100644 drivers/gpu/drm/armada/drm_helper.h
drivers/gpu/drm/Kconfig +2 -0
@@ -213,6 +213,8 @@ source "drivers/gpu/drm/mgag200/Kconfig" source "drivers/gpu/drm/cirrus/Kconfig" +source "drivers/gpu/drm/armada/Kconfig" + source "drivers/gpu/drm/shmobile/Kconfig" source "drivers/gpu/drm/tegra/Kconfig"
drivers/gpu/drm/Makefile +1 -0
@@ -48,6 +48,7 @@ obj-$(CONFIG_DRM_EXYNOS) +=exynos/ obj-$(CONFIG_DRM_GMA500) += gma500/ obj-$(CONFIG_DRM_UDL) += udl/ obj-$(CONFIG_DRM_AST) += ast/ +obj-$(CONFIG_DRM_ARMADA) += armada/ obj-$(CONFIG_DRM_SHMOBILE) +=shmobile/ obj-$(CONFIG_DRM_TEGRA) += tegra/ obj-$(CONFIG_DRM_OMAP) += omapdrm/
drivers/gpu/drm/armada/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +config DRM_ARMADA + tristate "DRM support for Marvell Armada SoCs" + depends on DRM && HAVE_CLK + select FB_CFB_FILLRECT + select FB_CFB_COPYAREA + select FB_CFB_IMAGEBLIT + select DRM_KMS_HELPER + help + Support the "LCD" controllers found on the Marvell Armada 510 + devices. There are two controllers on the device, each controller + supports graphics and video overlays. + + This driver provides no built-in acceleration; acceleration is + performed by other IP found on the SoC. This driver provides + kernel mode setting and buffer management to userspace.
drivers/gpu/drm/armada/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +armada-y := armada_crtc.o armada_drv.o armada_fb.o armada_fbdev.o \ + armada_gem.o armada_output.o armada_overlay.o \ + armada_slave.o +armada-$(CONFIG_DEBUG_FS) += armada_debugfs.o + +obj-$(CONFIG_DRM_ARMADA) := armada.o
drivers/gpu/drm/armada/armada_crtc.c new file +766 -0
766 lines not on this page · raw message
drivers/gpu/drm/armada/armada_crtc.h new file +75 -0
75 lines not on this page · raw message
drivers/gpu/drm/armada/armada_debugfs.c new file +186 -0
186 lines not on this page · raw message
drivers/gpu/drm/armada/armada_drm.h new file +62 -0
62 lines not on this page · raw message
drivers/gpu/drm/armada/armada_drv.c new file +326 -0
326 lines not on this page · raw message
drivers/gpu/drm/armada/armada_fb.c new file +156 -0
156 lines not on this page · raw message
drivers/gpu/drm/armada/armada_fb.h new file +21 -0
@@ -0,0 +1,21 @@ +/* +* Copyright (C) 2012 Russell King +* +* 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. +*/ +#ifndef ARMADA_FB_H +#define ARMADA_FB_H + +struct armada_framebuffer { +struct drm_framebuffer fb; +struct armada_gem_object *obj; +}; +#define drm_fb_to_armada_fb (dfb) container_of(dfb, struct armada_framebuffer, fb) +#define drm_fb_obj (fb) drm_fb_to_armada_fb(fb)->obj + +int armada_framebuffer_create (struct drm_device *,struct armada_framebuffer **, +struct drm_mode_fb_cmd2 *,struct armada_gem_object *); + +#endif
drivers/gpu/drm/armada/armada_fbdev.c new file +210 -0
210 lines not on this page · raw message
drivers/gpu/drm/armada/armada_gem.c new file +420 -0
420 lines not on this page · raw message
drivers/gpu/drm/armada/armada_gem.h new file +41 -0
41 lines not on this page · raw message
drivers/gpu/drm/armada/armada_hw.h new file +295 -0
295 lines not on this page · raw message
drivers/gpu/drm/armada/armada_ioctl.h new file +128 -0
128 lines not on this page · raw message
drivers/gpu/drm/armada/armada_ioctlP.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2012 Russell King +* +* 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. +*/ +#ifndef ARMADA_IOCTLP_H +#define ARMADA_IOCTLP_H + +#define ARMADA_IOCTL_PROTO (name)\ +extern int armada_##name##_ioctl(struct drm_device *, void *, struct drm_file *) + +ARMADA_IOCTL_PROTO (gem_create); +ARMADA_IOCTL_PROTO (gem_create_phys); +ARMADA_IOCTL_PROTO (gem_mmap); +ARMADA_IOCTL_PROTO (gem_prop); +ARMADA_IOCTL_PROTO (gem_pwrite); +ARMADA_IOCTL_PROTO (overlay_put_image); +ARMADA_IOCTL_PROTO (overlay_attrs); + +#endif
drivers/gpu/drm/armada/armada_output.c new file +159 -0
159 lines not on this page · raw message
drivers/gpu/drm/armada/armada_output.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* Copyright (C) 2012 Russell King +* +* 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. +*/ +#ifndef ARMADA_CONNETOR_H +#define ARMADA_CONNETOR_H + +#define encoder_helper_funcs (encoder) \ + ((struct drm_encoder_helper_funcs *)encoder->helper_private) + +struct armada_output_type { +int connector_type; +enum drm_connector_status (*detect)(struct drm_connector *,bool ); +int (*create)(struct drm_connector *,const void *); +int (*set_property)(struct drm_connector *,struct drm_property *,uint64_t ); +}; + +struct drm_encoder *armada_drm_connector_encoder (struct drm_connector *conn); + +void armada_drm_encoder_prepare (struct drm_encoder *encoder); +void armada_drm_encoder_commit (struct drm_encoder *encoder); + +bool armada_drm_encoder_mode_fixup (struct drm_encoder *encoder, +const struct drm_display_mode *mode,struct drm_display_mode *adj); + +int armada_drm_slave_encoder_mode_valid (struct drm_connector *conn, +struct drm_display_mode *mode); + +int armada_drm_slave_encoder_set_property (struct drm_connector *conn, +struct drm_property *property,uint64_t value); + +int armada_output_create (struct drm_device *dev, +const struct armada_output_type *type,const void *data); + +#endif
drivers/gpu/drm/armada/armada_overlay.c new file +514 -0
59 lines not on this page · raw message
drivers/gpu/drm/armada/armada_slave.c new file +138 -0
138 lines not on this page · raw message
drivers/gpu/drm/armada/armada_slave.h new file +26 -0
Lines of this file are not shown. View the raw message.
drivers/gpu/drm/armada/drm_helper.h new file +31 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.4.4
Part of the diff is not shown here. View the raw message.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 14 lines · Russell King
This patch adds support for the pair of LCD controllers on the Marvell Armada 510 SoCs. This driver supports:
- multiple contiguous scanout buffers for video and graphics
- shm backed cacheable buffer objects for X pixmaps for Vivante GPU acceleration
- dual lcd0 and lcd1 crt operation
- video overlay on each LCD crt
- page flipping of the main scanout buffersIncluded in this commit is the core driver with no output support; output support is platform and encoder driver dependent.
Signed-off-by Russell King <[email protected]>---
[...]
Quoted 14 lines
drivers/gpu/drm/armada/armada_crtc.c new file +8
-0@@ -0,0 +1,766 @@ +/* +* Copyright (C) 2012 Russell King +* Rewritten from the dovefb driver, and Armada510 manuals. +* +* 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. +*/
[...]
Quoted 16 lines
drivers/gpu/drm/armada/armada_crtc.c new file +16
-0+static void armada_drm_crtc_update (struct armada_crtc *dcrtc) +{ +uint32_t dumb_ctrl; + + dumb_ctrl = dcrtc->cfg_dumb_ctrl; + +if (!dpms_blanked (dcrtc->dpms)) + dumb_ctrl |=CFG_DUMB_ENA ; + +/* +* When a dumb interface isn't under 24bit, it might be +* under SPI or GPIO. If set to 7, this will force +* LCD_D[23:0] to output blank color and damage GPIO +* and SPI behaviour. So leave it as-is unless in +* DUMB24_RGB888_0 mode. +*/
drivers/gpu/drm/armada/armada_crtc.c line 130
Quoted 10 lines
drivers/gpu/drm/armada/armada_crtc.c new file +10
-0+if (dpms_blanked (dcrtc->dpms) && + (dumb_ctrl &DUMB_MASK ) ==DUMB24_RGB888_0 ) { + dumb_ctrl &= ~DUMB_MASK ; + dumb_ctrl |=DUMB_BLANK ; + } + +/* +* The spec is unclear about the polarities of the syncs. +* We assume their non-inverted state is active high. +*/
nit: "We confirmed their non-inverted state is active high."
Quoted 12 lines
drivers/gpu/drm/armada/armada_crtc.c new file +12
-0+if (dcrtc->crtc.mode.flags &DRM_MODE_FLAG_NCSYNC ) + dumb_ctrl |=CFG_INV_CSYNC ; +if (dcrtc->crtc.mode.flags &DRM_MODE_FLAG_NHSYNC ) + dumb_ctrl |=CFG_INV_HSYNC ; +if (dcrtc->crtc.mode.flags &DRM_MODE_FLAG_NVSYNC ) + dumb_ctrl |=CFG_INV_VSYNC ; + +if (dcrtc->dumb_ctrl != dumb_ctrl) { + dcrtc->dumb_ctrl = dumb_ctrl; +writel_relaxed (dumb_ctrl, dcrtc->base +LCD_SPU_DUMB_CTRL ); + } +}
[...]
Quoted 31 lines
drivers/gpu/drm/armada/armada_drv.c new file +25
-0@@ -0,0 +1,326 @@ +/* +* Copyright (C) 2012 Russell King +* +* 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 <drm/drmP.h> +#include <drm/drm_crtc_helper.h> +#include "armada_crtc.h" +#include "armada_drm.h" +#include "armada_gem.h" +#include "armada_hw.h" +#include "armada_ioctl.h" +#include "armada_ioctlP.h" + +static int armada_drm_load (struct drm_device *dev,unsigned long flags) +{ +struct armada_private *priv; +struct resource *res[ARRAY_SIZE (priv->dcrtc)]; +struct resource *mem =NULL ; +int ret, n, i; +
drivers/gpu/drm/armada/armada_drv.c line 35
Quoted 10 lines
drivers/gpu/drm/armada/armada_drv.c new file +10
-0+memset (res,0 ,sizeof (res)); + +for (n = i =0 ; ; n++) { +struct resource *r =platform_get_resource (dev->platformdev, +IORESOURCE_MEM , n); +if (!r) +break ; + +if (resource_size (r) >SZ_4K ) + mem = r;
nit again: The register address window of Dove LCD is 64k although you are right an no more than 512B are used. Also a comment would be nice, that everything above 4k (64k) is interpreted as gfx mem.
Quoted 30 lines
drivers/gpu/drm/armada/armada_drv.c new file +30
-0+else if (i <ARRAY_SIZE (priv->dcrtc)) + res[i++] = r; +else +return -EINVAL ; + } + +if (!res[0 ] || !mem) +return -ENXIO ; + +if (!devm_request_mem_region (dev->dev, mem->start, +resource_size (mem),"armada-drm" )) +return -EBUSY ; + + priv =devm_kzalloc (dev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) { +DRM_ERROR ("failed to allocate private\n" ); + ret = -ENOMEM ; + goto err_buf; + } + + dev->dev_private = priv; + +/* Mode setting support */ +drm_mode_config_init (dev); + dev->mode_config.min_width =0 ; + dev->mode_config.min_height =0 ; + dev->mode_config.max_width =2048 ; + dev->mode_config.max_height =2048 ; + dev->mode_config.preferred_depth =24 ; + dev->mode_config.funcs = &armada_drm_mode_config_funcs;
drivers/gpu/drm/armada/armada_drv.c line 75
Quoted 10 lines
drivers/gpu/drm/armada/armada_drv.c new file +10
-0+drm_mm_init (&priv->linear, mem->start,resource_size (mem)); + +/* Create all LCD controllers */ +for (n =0 ; n <ARRAY_SIZE (priv->dcrtc); n++) { +struct clk *clk; + +if (!res[n]) +break ; + + clk =clk_get_sys ("dovefb.0" ,"extclk" );
To be precise: the above should have the index at extclk as there is two extclk inputs that can be used for both lcdcs. So currently, as armada_crtc is hard-coding extclk0 input it should be "armadafb.%d", "extclk0".
But I know, clocking in general will work-out with parent select for clk-mux and DT support.
[...]
Quoted 14 lines
drivers/gpu/drm/armada/armada_overlay.c new file +8
-0@@ -0,0 +1,514 @@ +/* +* Copyright (C) 2012 Russell King +* Rewritten from the dovefb driver, and Armada510 manuals. +* +* 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. +*/
[...]
Quoted 22 lines
drivers/gpu/drm/armada/armada_overlay.c new file +22
-0+int armada_overlay_put_image_ioctl (struct drm_device *dev,void *data, +struct drm_file *file) +{ +struct drm_armada_overlay_put_image *args = data; +struct armada_private *priv = dev->dev_private; +struct armada_overlay *ovl = priv->overlay; +struct armada_gem_object *obj; +struct armada_crtc *dcrtc; +uint32_t stride_uv, stride_yc, src_hw, dst_hw, dst_yx; +bool planar = false; +int ret, idx; + +if (!ovl) { +DRM_DEBUG_DRIVER ("no overlay" ); +return -ENODEV ; + } + +if (!(args->flags &ARMADA_OVERLAY_ENABLE )) { +mutex_lock (&dev->mode_config.mutex); +mutex_lock (&dev->struct_mutex); + +armada_drm_overlay_off (dev, ovl);
drivers/gpu/drm/armada/armada_overlay.c line 308
Quoted 10 lines
drivers/gpu/drm/armada/armada_overlay.c new file +10
-0+ +mutex_unlock (&dev->struct_mutex); +mutex_unlock (&dev->mode_config.mutex); + +return 0 ; + } + +// DRM_DEBUG_DRIVER("flags %x handle %x src %dx%d dst %dx%d+%d+%d\n", +// args->flags, args->bo_handle, args->src_scan_width, args->src_scan_height, +// args->dst_width, args->dst_height, args->dst_x, args->dst_y);
nit: Reminder for a hopefully soon to surface non-RFC patch.
[...]
Quoted 14 lines
drivers/gpu/drm/armada/armada_slave.c new file +8
-0@@ -0,0 +1,138 @@ +/* +* Copyright (C) 2012 Russell King +* Rewritten from the dovefb driver, and Armada510 manuals. +* +* 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. +*/
[...]
Quoted 54 lines
drivers/gpu/drm/armada/armada_slave.c new file +54
-0+static int armada_drm_conn_slave_create (struct drm_connector *conn,const void *data) +{ +const struct armada_drm_slave_config *config = data; +struct drm_encoder_slave *slave; +struct i2c_adapter *adap; +int ret; + + conn->interlace_allowed = config->interlace_allowed; + conn->doublescan_allowed = config->doublescan_allowed; + conn->polled = config->polled; + +drm_connector_helper_add (conn, &armada_drm_slave_helper_funcs); + + slave =kzalloc (sizeof (*slave),GFP_KERNEL ); +if (!slave) +return -ENOMEM ; + + slave->base.possible_crtcs = config->crtcs; + + adap =i2c_get_adapter (config->i2c_adapter_id); +if (!adap) { +kfree (slave); +return -EPROBE_DEFER ; + } + + ret =drm_encoder_init (conn->dev, &slave->base, + &armada_drm_slave_encoder_funcs, +DRM_MODE_ENCODER_TMDS ); +if (ret) { +DRM_ERROR ("unable to init encoder\n" ); +i2c_put_adapter (adap); +kfree (slave); +return ret; + } + + ret =drm_i2c_encoder_init (conn->dev, slave, adap, &config->info); +i2c_put_adapter (adap); +if (ret) { +DRM_ERROR ("unable to init encoder slave\n" ); +armada_drm_slave_destroy (&slave->base); +return ret; + } + +drm_encoder_helper_add (&slave->base, &drm_slave_encoder_helpers); + + ret = slave->slave_funcs->create_resources (&slave->base, conn); +if (ret) { +armada_drm_slave_destroy (&slave->base); +return ret; + } + + ret =drm_mode_connector_attach_encoder (conn, &slave->base); +if (ret) { +armada_drm_slave_destroy (&slave->base);
drivers/gpu/drm/armada/armada_slave.c line 129
Quoted 10 lines
drivers/gpu/drm/armada/armada_slave.c new file +10
-0+return ret; + } + + conn->encoder = &slave->base; + +return ret; +} + +static const struct armada_output_type armada_drm_conn_slave = { + .connector_type =DRM_MODE_CONNECTOR_HDMIA ,
For a rework of DRM slave encoder API, there should also be some way to get .connector_type and .encoder_type above from that slave encoder. IMHO it should be up to the slave encoder to determine connector and encoder type.
[...]
Quoted 6 lines
drivers/gpu/drm/armada/armada_slave.h new file +0
-0
drivers/gpu/drm/armada/armada_slave.h line 9
Quoted 9 lines
drivers/gpu/drm/armada/armada_slave.h new file +9
-0@@ -0,0 +1,26 @@ +/* +* Copyright (C) 2012 Russell King +* +* 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. +*/ +#ifndef ARMADA_TDA19988_H +#define ARMADA_TDA19988_H
nit: ARMADA_SLAVE_H
Quoted 7 lines
drivers/gpu/drm/armada/armada_slave.h new file +7
-0+ +#include <linux/i2c.h> +#include <drm/drmP.h> + +struct armada_drm_slave_config { +int i2c_adapter_id; +uint32_t crtcs;
drivers/gpu/drm/armada/armada_slave.h line 26
Quoted 10 lines
drivers/gpu/drm/armada/armada_slave.h new file +10
-0+uint8_t polled; +bool interlace_allowed; +bool doublescan_allowed; + struct i2c_board_info info; +}; + +int armada_drm_connector_slave_create (struct drm_device *dev, +const struct armada_drm_slave_config *); + +#endif
Thanks again for sharing the driver as RFC! Will test soon and post promised tda998x sync patches.
Sebastian
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 7 lines · Sebastian Hesselbarth
drivers/gpu/drm/armada/armada_crtc.c line 130
Quoted 4 lines · Russell King
drivers/gpu/drm/armada/armada_crtc.c new file +4
-0+/* +* The spec is unclear about the polarities of the syncs. +* We assume their non-inverted state is active high. +*/ nit: "We confirmed their non-inverted state is active high."
Thanks, it's been a while since I looked at this so I had forgotten to update the comment. Now done.
Quoted 6 lines
drivers/gpu/drm/armada/armada_drv.c line 35
Quoted 2 lines
drivers/gpu/drm/armada/armada_drv.c new file +2
-0+if (resource_size (r) >SZ_4K ) + mem = r;nit again: The register address window of Dove LCD is 64k although you are right an no more than 512B are used. Also a comment would be nice, that everything above 4k (64k) is interpreted as gfx mem.
Fixed and comment added.
Quoted 14 lines
drivers/gpu/drm/armada/armada_drv.c line 75
Quoted 8 lines
drivers/gpu/drm/armada/armada_drv.c new file +8
-0+/* Create all LCD controllers */ +for (n =0 ; n <ARRAY_SIZE (priv->dcrtc); n++) { +struct clk *clk; + +if (!res[n]) +break ; + + clk =clk_get_sys ("dovefb.0" ,"extclk" );To be precise: the above should have the index at extclk as there is two extclk inputs that can be used for both lcdcs. So currently, as
armada_crtcis hard-coding extclk0 input it should be "armadafb.%d", "extclk0".
Quoted 2 lines
But I know, clocking in general will work-out with parent select for clk-mux and DT support.
I've sorted that out, but I'd forgotten there were three additional patches on top of what I've posted sorting that stuff out - the second one in particular:
4a5e9b7 DRM: armada: store kernel address for gem objects f760c94 DRM: Dove: alternative variant based clocking
2e051fd DRM: Armada: convert hardware cursor support to 64x32 or 32x64 ARGB
Because they're scattered in other branches (the h/w cursor stuff is separate) it's not trivial to generate a single series from git for these.
Quoted 7 lines
drivers/gpu/drm/armada/armada_slave.c line 129
Quoted 2 lines
drivers/gpu/drm/armada/armada_slave.c new file +2
-0+static const struct armada_output_type armada_drm_conn_slave = { + .connector_type =DRM_MODE_CONNECTOR_HDMIA ,For a rework of DRM slave encoder API, there should also be some way to get .connector_type and .encoder_type above from that slave encoder. IMHO it should be up to the slave encoder to determine connector and encoder type.
Encoder type - yes, but connector type doesn't seem sensible. It's possible for the TDA998x to be connected to a DVI connector - how would the slave encoder know that?
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/armada/armada_slave.h new file +3
-0@@ -0,0 +1,26 @@ +/* +* Copyright (C) 2012 Russell King +*
Quoted 8 lines
drivers/gpu/drm/armada/armada_slave.h line 9
Quoted 6 lines
drivers/gpu/drm/armada/armada_slave.h new file +6
-0+* 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. +*/ +#ifndef ARMADA_TDA19988_H +#define ARMADA_TDA19988_H nit:
ARMADA_SLAVE_H
Nobbled. :)
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 10 lines · Russell King - ARM Linux
Quoted 8 lines · Sebastian Hesselbarth
drivers/gpu/drm/armada/armada_slave.c line 129
Quoted 2 lines · Russell King
drivers/gpu/drm/armada/armada_slave.c new file +2
-0+static const struct armada_output_type armada_drm_conn_slave = { + .connector_type =DRM_MODE_CONNECTOR_HDMIA ,For a rework of DRM slave encoder API, there should also be some way to get .connector_type and .encoder_type above from that slave encoder. IMHO it should be up to the slave encoder to determine connector and encoder type.
Quoted 3 lines
Encoder type - yes, but connector type doesn't seem sensible. It's possible for the TDA998x to be connected to a DVI connector - how would the slave encoder know that?
True. But how should Armada DRM driver know? Actually, it is not important where we put that information. IMHO it is more likely to be known by TDA998x as by the corresponding master encoder. With DT I'd suggest to have a property for TDA998x that sets either HDMI A/B/C or DVI.
Not related to CuBox setup, but with DisplayPort it can even get worse, e.g. consider a dumb LCDC connected to some DP++ (HDMI protocol over DP electrical) encoder connected to a TMDS level shifter. Where do you put the (final) connector type if not in the last encoder connected to that chain?
Sebastian
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
In reply to Russell KingQuoted 7 lines · Russell King
This patch adds support for the pair of LCD controllers on the Marvell Armada 510 SoCs. This driver supports:
- multiple contiguous scanout buffers for video and graphics
- shm backed cacheable buffer objects for X pixmaps for Vivante GPU acceleration
- dual lcd0 and lcd1 crt operation
- video overlay on each LCD crt
Any particular reason for not exposing the overlays as drm_plane's? That is probably something that should change before merging the driver.
Other than that, it looks reasonably good, with just a few (mostly minor) comments below.
Quoted 7 lines
- page flipping of the main scanout buffers
Included in this commit is the core driver with no output support; output support is platform and encoder driver dependent.
Signed-off-by Russell King <[email protected]>---
[snip]
Quoted 67 lines
drivers/gpu/drm/armada/armada_crtc.c new file +61
-0@@ -0,0 +1,766 @@ +/* +* Copyright (C) 2012 Russell King +* Rewritten from the dovefb driver, and Armada510 manuals. +* +* 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 <drm/drmP.h> +#include <drm/drm_crtc_helper.h> +#include "armada_crtc.h" +#include "armada_drm.h" +#include "armada_fb.h" +#include "armada_gem.h" +#include "armada_hw.h" + +struct armada_frame_work { +struct drm_pending_vblank_event *event; +struct armada_regs regs[4 ]; +struct drm_gem_object *old_fb_obj; +struct work_struct work; +}; + +/* +* A note about interlacing. Let's consider HDMI 1920x1080i. +* The timing parameters we have from X are: +* Hact HsyA HsyI Htot Vact VsyA VsyI Vtot +* 1920 2448 2492 2640 1080 1084 1094 1125 +* Which get translated to: +* Hact HsyA HsyI Htot Vact VsyA VsyI Vtot +* 1920 2448 2492 2640 540 542 547 562 +* +* This is how it is defined by CEA-861-D - line and pixel numbers are +* referenced to the rising edge of VSYNC and HSYNC. Total clocks per +* line: 2640. The odd frame, the first active line is at line 21, and +* the even frame, the first active line is 584. +* +* LN: 560 561 562 563 567 568 569 +* DE: ~~~|____________________________//__________________________ +* HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____ +* VSYNC: _________________________|~~~~~~//~~~~~~~~~~~~~~~|__________ +* 22 blanking lines. VSYNC at 1320 (referenced to the HSYNC rising edge). +* +* LN: 1123 1124 1125 1 5 6 7 +* DE: ~~~|____________________________//__________________________ +* HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____ +* VSYNC: ____________________|~~~~~~~~~~~//~~~~~~~~~~|_______________ +* 23 blanking lines +* +* The Armada LCD Controller line and pixel numbers are, like X timings, +* referenced to the top left of the active frame. +* +* So, translating these to our LCD controller: +* Odd frame, 563 total lines, VSYNC at line 543-548, pixel 1128. +* Even frame, 562 total lines, VSYNC at line 542-547, pixel 2448. +* Note: Vsync front porch remains constant! +* +* if (odd_frame) { +* vtotal = mode->crtc_vtotal + 1; +* vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay + 1;
drivers/gpu/drm/armada/armada_crtc.c line 71
Quoted 10 lines
drivers/gpu/drm/armada/armada_crtc.c new file +10
-0+* vhorizpos = mode->crtc_hsync_start - mode->crtc_htotal / 2 +* } else { +* vtotal = mode->crtc_vtotal; +* vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay; +* vhorizpos = mode->crtc_hsync_start; +* } +* vfrontporch = mode->crtc_vtotal - mode->crtc_vsync_end; +* +* So, we need to reprogram these registers on each vsync event: +* LCD_SPU_V_PORCH, LCD_SPU_ADV_REG, LCD_SPUT_V_H_TOTAL
ouch, proof that some hw designers must really hate driver writers ;-)
[snip]
Quoted 6 lines
drivers/gpu/drm/armada/armada_crtc.c new file +6
-0+/* The mode_config.mutex will be held for this call */ +static int armada_drm_crtc_mode_set_base (struct drm_crtc *crtc,int x,int y, +struct drm_framebuffer *old_fb) +{ +struct armada_crtc *dcrtc =drm_to_armada_crtc (crtc); +struct armada_regs regs[4 ];
drivers/gpu/drm/armada/armada_crtc.c line 582
Quoted 10 lines
drivers/gpu/drm/armada/armada_crtc.c new file +10
-0+unsigned i; + + i =armada_drm_crtc_calc_fb (crtc->fb, crtc->x, crtc->y, regs, dcrtc->interlaced); +armada_reg_queue_end (regs, i); + +/* Wait for pending flips to complete */ +wait_event (dcrtc->frame_wait, !dcrtc->frame_work); + +/* Take a reference to the new fb as we're using it */ +drm_gem_object_reference (&drm_fb_obj (crtc->fb)->obj);
note that you probably want to ref/unref the fb (and let the fb hold a ref to the gem bo).. that will make life easier for planar formats too (as the fb should hold ref's to the bo for each plane)
[snip]
Quoted 1 line
drivers/gpu/drm/armada/armada_drv.c +0
-0
[snip]
drivers/gpu/drm/armada/armada_drv.c line 231
Quoted 4 lines
drivers/gpu/drm/armada/armada_drv.c +4
-0+ +static struct drm_ioctl_desc armada_ioctls[] = { +DRM_IOCTL_DEF_DRV (ARMADA_GEM_CREATE , armada_gem_create_ioctl,DRM_UNLOCKED ), +DRM_IOCTL_DEF_DRV (ARMADA_GEM_CREATE_PHYS , armada_gem_create_phys_ioctl,DRM_UNLOCKED ),
you might want just a single ioctl for creating gem objects, with a 'scanout' flag.. perhaps some future version of the hw doesn't need phys contig for scanout, and this would probably be easier to handle with a single ioctl that has an 'if (flags & SCANOUT && device_needs_phys_contig_scanout()) .. '
[snip]
Quoted 1 line
drivers/gpu/drm/armada/armada_gem.c +0
-0
[snip]
Quoted 23 lines
drivers/gpu/drm/armada/armada_gem.c +23
-0+int armada_gem_linear_back (struct drm_device *dev,struct armada_gem_object *obj) +{ +struct armada_private *priv = dev->dev_private; +size_t size = obj->obj.size; + +if (obj->page || obj->linear) +return 0 ; + +/* If it is a small allocation, try to get it from the system */ +if (size <1048576 ) { +unsigned int order =get_order (size); +struct page *p =alloc_pages (GFP_KERNEL , order); + +if (p) { +unsigned sz = (size +31 ) & ~31 ; +uintptr_t ptr; + + obj->phys_addr =page_to_phys (p); + obj->dev_addr = obj->phys_addr; + +/* FIXME: Hack around dirty cache */ + ptr = (uintptr_t )phys_to_virt (obj->phys_addr); +memset ((void *)ptr,0 ,PAGE_ALIGN (size));
drivers/gpu/drm/armada/armada_gem.c line 105
Quoted 10 lines
drivers/gpu/drm/armada/armada_gem.c +10
-0+while (sz) { + asmvolatile ("mcr p15, 0, %0, c7, c14, 1" : :"r" (ptr)); + ptr +=32 ; + sz -=32 ; + } +dsb (); + + obj->page = p; + } + }
maybe leave out the small size case until there is a better way to deal with cache, since this seems like just an optimization..
although I wonder why not just use CMA? (Other than maybe performance.. but I guess this is only for allocating scanout buffers, in which case all the bazillion of temporary pixmaps that X11 creates/deletes won't be hitting this path..)
Quoted 32 lines
drivers/gpu/drm/armada/armada_gem.c +32
-0+/* Otherwise, grab it from our linear allocation */ +if (!obj->page) { +struct drm_mm_node *free; +unsigned align =min_t (unsigned, size,SZ_2M ); +void __iomem *ptr; + + free =drm_mm_search_free (&priv->linear, size, align,0 ); +if (free) + obj->linear =drm_mm_get_block (free, size, align); +if (!obj->linear) +return -ENOSPC ; + +/* Ensure that the memory we're returning is cleared. */ + ptr =ioremap_wc (obj->linear->start, size); +if (!ptr) { +drm_mm_put_block (obj->linear); + obj->linear =NULL ; +return -ENOMEM ; + } + +memset_io (ptr,0 , size); +iounmap (ptr); + + obj->phys_addr = obj->linear->start; + obj->dev_addr = obj->linear->start; + } + +DRM_DEBUG_DRIVER ("obj %p phys %#x dev %#x\n" , + obj, obj->phys_addr, obj->dev_addr); + +return 0 ; +}
[snip]
Quoted 8 lines
drivers/gpu/drm/armada/armada_gem.c +8
-0+int armada_gem_prop_ioctl (struct drm_device *dev,void *data, +struct drm_file *file) +{ +struct drm_armada_gem_prop *arg = data; +struct armada_gem_object *dobj; +int ret; + + ret =mutex_lock_interruptible (&dev->struct_mutex);
drivers/gpu/drm/armada/armada_gem.c line 361
Quoted 10 lines
drivers/gpu/drm/armada/armada_gem.c +10
-0+if (ret) +return ret; + + dobj =armada_gem_object_lookup (dev, file, arg->handle); +if (dobj ==NULL ) { + ret = -ENOENT ; + goto unlock; + } + + arg->phys = dobj->phys_addr;
ugg, do you really need to expose phys addr to userspace? Any chance to just teach the gpu bits about dmabuf instead?
Quoted 8 lines
drivers/gpu/drm/armada/armada_gem.c +8
-0+ ret =0 ; +drm_gem_object_unreference (&dobj->obj); + + unlock: +mutex_unlock (&dev->struct_mutex); + +return ret; +}
[snip]
Quoted 22 lines
drivers/gpu/drm/armada/armada_ioctl.h new file +16
-0@@ -0,0 +1,128 @@ +/* +* Copyright (C) 2012 Russell King +* With inspiration from the i915 driver +* +* 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. +*/ +#ifndef DRM_ARMADA_IOCTL_H +#define DRM_ARMADA_IOCTL_H + +#define DRM_ARMADA_GEM_CREATE 0x00 +#define DRM_ARMADA_GEM_CREATE_PHYS 0x01 +#define DRM_ARMADA_GEM_MMAP 0x02 +#define DRM_ARMADA_GEM_PWRITE 0x03 +#define DRM_ARMADA_GEM_PROP 0x04
drivers/gpu/drm/armada/armada_ioctl.h line 26
Quoted 10 lines
drivers/gpu/drm/armada/armada_ioctl.h new file +10
-0+#define DRM_ARMADA_OVERLAY_PUT_IMAGE 0x06 +#define DRM_ARMADA_OVERLAY_ATTRS 0x07 + +#define ARMADA_IOCTL (dir,name,str) \ + DRM_##dir(DRM_COMMAND_BASE + DRM_ARMADA_##name, struct drm_armada_##str) + +struct drm_armada_gem_create { +uint32_t height; +uint32_t width; +uint32_t bpp;
just fwiw, typically height/width/bpp are properties of the fb but not the bo.. (except in some cases where kernel needs to know this to setup GTT correctly for tiled buffers)
Quoted 19 lines
drivers/gpu/drm/armada/armada_ioctl.h new file +19
-0+uint32_t handle; +uint32_t pitch; +uint32_t size; +}; +#define DRM_IOCTL_ARMADA_GEM_CREATE \ + ARMADA_IOCTL(IOWR, GEM_CREATE, gem_create) + +struct drm_armada_gem_create_phys { +uint32_t size; +uint32_t handle; +uint64_t phys; +}; +#define DRM_IOCTL_ARMADA_GEM_CREATE_PHYS \ + ARMADA_IOCTL(IOWR, GEM_CREATE_PHYS, gem_create_phys) + +struct drm_armada_gem_mmap { +uint32_t handle; +uint32_t pad; +uint64_t offset;
drivers/gpu/drm/armada/armada_ioctl.h line 55
Quoted 10 lines
drivers/gpu/drm/armada/armada_ioctl.h new file +10
-0+uint64_t size; +uint64_t addr; +}; +#define DRM_IOCTL_ARMADA_GEM_MMAP \ + ARMADA_IOCTL(IOWR, GEM_MMAP, gem_mmap) + +struct drm_armada_gem_pwrite { +uint32_t handle; +uint32_t offset; +uint32_t size;
probably want a uint32_t padding here, or move the uint64_t up in the struct to avoid 32 vs 64b alignment differences.
Quoted 5 lines
drivers/gpu/drm/armada/armada_ioctl.h new file +5
-0+uint64_t ptr; +}; +#define DRM_IOCTL_ARMADA_GEM_PWRITE \ + ARMADA_IOCTL(IOW, GEM_PWRITE, gem_pwrite) +
[snip]
Quoted 1 line
drivers/gpu/drm/armada/armada_output.c +0
-0
[snip]
Quoted 1 line
+/* Shouldn't this be a generic helper function? */
I didn't bother making it a generic helper, because in tilcdc I also needed to check some crtc constraints. Although if there is >1 other drivers that don't need to, we can easily make it a helper.
Quoted 14 lines
drivers/gpu/drm/armada/armada_output.c +14
-0+int armada_drm_slave_encoder_mode_valid (struct drm_connector *conn, +struct drm_display_mode *mode) +{ +struct drm_encoder *encoder =armada_drm_connector_encoder (conn); +int valid =MODE_BAD ; + +if (encoder) { +struct drm_encoder_slave *slave =to_encoder_slave (encoder); + + valid = slave->slave_funcs->mode_valid (encoder, mode); + } +return valid; +} +
[snip]
Quoted 8 lines
drivers/gpu/drm/armada/drm_helper.h new file +2
-0@@ -0,0 +1,31 @@ +/* +* Copyright (C) 2012 Russell King
drivers/gpu/drm/armada/drm_helper.h line 12
Quoted 10 lines
drivers/gpu/drm/armada/drm_helper.h new file +10
-0+* +* 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. +*/ +#ifndef DRM_HELPER_H +#define DRM_HELPER_H + +/* Useful helpers I wish the DRM core would provide */ +
yeah, we should probably just add these in core
BR,
-R
Quoted 22 lines
drivers/gpu/drm/armada/drm_helper.h new file +19
-1+#include <drm/drmP.h> + +static inline struct drm_crtc *drm_crtc_find (struct drm_device *dev, +uint32_t id) +{ +struct drm_mode_object *mo; + mo =drm_mode_object_find (dev, id,DRM_MODE_OBJECT_CRTC ); +return mo ?obj_to_crtc (mo) :NULL ; +} + +static inline struct drm_encoder *drm_encoder_find (struct drm_device *dev, +uint32_t id) +{ +struct drm_mode_object *mo; + mo =drm_mode_object_find (dev, id,DRM_MODE_OBJECT_ENCODER ); +return mo ?obj_to_encoder (mo) :NULL ; +} + +#endif --1.7.4.4
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 10 lines · Rob Clark
Quoted 7 lines · Russell King
This patch adds support for the pair of LCD controllers on the Marvell Armada 510 SoCs. This driver supports:
- multiple contiguous scanout buffers for video and graphics
- shm backed cacheable buffer objects for X pixmaps for Vivante GPU acceleration
- dual lcd0 and lcd1 crt operation
- video overlay on each LCD crt
Quoted 3 lines
Any particular reason for not exposing the overlays as drm_plane's? That is probably something that should change before merging the driver.
Only through not understanding much of DRM when I started this. Provided DRM planes can do everything that I'm already doing with the overlay support, then yes. Otherwise, I want to stick with this which is modelled after the i915 overlay interface.
The big question that this brings up is that the plane stuff looks a lot more heavyweight in terms of the computation done. I'm already concerned that I'm doing too much with the overlay code - it occasionally misses getting the next frame of video ready before the VBLANK event in certain circumstances which I haven't been able to quantify. I'd rather avoid adding too much additional work here, which would then make overlay pretty useless for what it's meant for - video playback.
... and it looks to me like it can't - because I sometimes get blocks of physical memory with the YUV data already in appropriately formatted for scanout that I really would like to avoid having to expensively copy.
Quoted 81 lines
Quoted 7 lines
- page flipping of the main scanout buffers
Included in this commit is the core driver with no output support; output support is platform and encoder driver dependent.
Signed-off-by Russell King <[email protected]>---
[snip]
Quoted 71 lines
drivers/gpu/drm/armada/armada_crtc.c new file +65
-0@@ -0,0 +1,766 @@ +/* +* Copyright (C) 2012 Russell King +* Rewritten from the dovefb driver, and Armada510 manuals. +* +* 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 <drm/drmP.h> +#include <drm/drm_crtc_helper.h> +#include "armada_crtc.h" +#include "armada_drm.h" +#include "armada_fb.h" +#include "armada_gem.h" +#include "armada_hw.h" + +struct armada_frame_work { +struct drm_pending_vblank_event *event; +struct armada_regs regs[4 ]; +struct drm_gem_object *old_fb_obj; +struct work_struct work; +}; + +/* +* A note about interlacing. Let's consider HDMI 1920x1080i. +* The timing parameters we have from X are: +* Hact HsyA HsyI Htot Vact VsyA VsyI Vtot +* 1920 2448 2492 2640 1080 1084 1094 1125 +* Which get translated to: +* Hact HsyA HsyI Htot Vact VsyA VsyI Vtot +* 1920 2448 2492 2640 540 542 547 562 +* +* This is how it is defined by CEA-861-D - line and pixel numbers are +* referenced to the rising edge of VSYNC and HSYNC. Total clocks per +* line: 2640. The odd frame, the first active line is at line 21, and +* the even frame, the first active line is 584. +* +* LN: 560 561 562 563 567 568 569 +* DE: ~~~|____________________________//__________________________ +* HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____ +* VSYNC: _________________________|~~~~~~//~~~~~~~~~~~~~~~|__________ +* 22 blanking lines. VSYNC at 1320 (referenced to the HSYNC rising edge). +* +* LN: 1123 1124 1125 1 5 6 7 +* DE: ~~~|____________________________//__________________________ +* HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____ +* VSYNC: ____________________|~~~~~~~~~~~//~~~~~~~~~~|_______________ +* 23 blanking lines +* +* The Armada LCD Controller line and pixel numbers are, like X timings, +* referenced to the top left of the active frame. +* +* So, translating these to our LCD controller: +* Odd frame, 563 total lines, VSYNC at line 543-548, pixel 1128. +* Even frame, 562 total lines, VSYNC at line 542-547, pixel 2448. +* Note: Vsync front porch remains constant! +* +* if (odd_frame) { +* vtotal = mode->crtc_vtotal + 1; +* vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay + 1; +* vhorizpos = mode->crtc_hsync_start - mode->crtc_htotal / 2 +* } else { +* vtotal = mode->crtc_vtotal; +* vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay;
Quoted 8 lines
drivers/gpu/drm/armada/armada_crtc.c line 71
Quoted 6 lines
drivers/gpu/drm/armada/armada_crtc.c new file +6
-0+* vhorizpos = mode->crtc_hsync_start; +* } +* vfrontporch = mode->crtc_vtotal - mode->crtc_vsync_end; +* +* So, we need to reprogram these registers on each vsync event: +* LCD_SPU_V_PORCH, LCD_SPU_ADV_REG, LCD_SPUT_V_H_TOTAL ouch, proof that some hw designers must really hate driver writers ;-)
Yep - and interlace support is not something that can be done in a stable way with the way the Linux kernel deals with interrupts (iow, with no priority and strictly single-threaded.) The problem is to do this properly, you need the LCD interrupt able to interrupt any other interrupt handler so you can reprogram the LCD controller within a very tight timeframe (less than one display field.)
It works, but occasionally you will get a hiccup (mainly that's the fault of the USB stack taking 2.25ms over some of its keyboard/mouse interrupts!)
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/armada/armada_crtc.c new file +12
-0+/* The mode_config.mutex will be held for this call */ +static int armada_drm_crtc_mode_set_base (struct drm_crtc *crtc,int x,int y, +struct drm_framebuffer *old_fb) +{ +struct armada_crtc *dcrtc =drm_to_armada_crtc (crtc); +struct armada_regs regs[4 ]; +unsigned i; + + i =armada_drm_crtc_calc_fb (crtc->fb, crtc->x, crtc->y, regs, dcrtc->interlaced); +armada_reg_queue_end (regs, i); + +/* Wait for pending flips to complete */
Quoted 8 lines
drivers/gpu/drm/armada/armada_crtc.c line 582
Quoted 4 lines
drivers/gpu/drm/armada/armada_crtc.c new file +4
-0+wait_event (dcrtc->frame_wait, !dcrtc->frame_work); + +/* Take a reference to the new fb as we're using it */ +drm_gem_object_reference (&drm_fb_obj (crtc->fb)->obj);note that you probably want to ref/unref the fb (and let the fb hold a ref to the gem bo).. that will make life easier for planar formats too (as the fb should hold ref's to the bo for each plane)
I'll look into it, but it will take some time as the refcounting is far from trivial or obvious in DRM...
Quoted 1 line
From what I can see there's no intrinsic refcounting between the fb
and the gem bo.
Quoted 12 lines
Quoted 1 line
drivers/gpu/drm/armada/armada_drv.c +0
-0[snip]
drivers/gpu/drm/armada/armada_drv.c line 231
Quoted 4 lines
drivers/gpu/drm/armada/armada_drv.c +4
-0+ +static struct drm_ioctl_desc armada_ioctls[] = { +DRM_IOCTL_DEF_DRV (ARMADA_GEM_CREATE , armada_gem_create_ioctl,DRM_UNLOCKED ), +DRM_IOCTL_DEF_DRV (ARMADA_GEM_CREATE_PHYS , armada_gem_create_phys_ioctl,DRM_UNLOCKED ),you might want just a single ioctl for creating gem objects, with a 'scanout' flag.. perhaps some future version of the hw doesn't need phys contig for scanout, and this would probably be easier to handle with a single ioctl that has an 'if (flags & SCANOUT &&
device_needs_phys_contig_scanout()) .. '
The purposes of these two ioctls are quite different. ARMADA_GEM_CREATE is to create any gem buffer object that needs shmem backing - eg, non-scanout pixmaps and the like.
ARMADA_GEM_CREATE_PHYS is to deal with creating a gem buffer object for a chunk of physical memory allocated by other means (eg, the Vmeta stuff.) This allows my X server to remain compatible with the XF86 Dove driver, which permits the passing of the physical address of the video frame to the X server (otherwise we're into rewriting a whole load more code than is really desirable - and I really don't have time to rewrite bits of gstreamer and other stuff.)
Lastly, the DUMB stuff is used for the graphics scanout buffer.
Quoted 39 lines
Quoted 1 line
drivers/gpu/drm/armada/armada_gem.c +0
-0[snip]
Quoted 23 lines
drivers/gpu/drm/armada/armada_gem.c +23
-0+int armada_gem_linear_back (struct drm_device *dev,struct armada_gem_object *obj) +{ +struct armada_private *priv = dev->dev_private; +size_t size = obj->obj.size; + +if (obj->page || obj->linear) +return 0 ; + +/* If it is a small allocation, try to get it from the system */ +if (size <1048576 ) { +unsigned int order =get_order (size); +struct page *p =alloc_pages (GFP_KERNEL , order); + +if (p) { +unsigned sz = (size +31 ) & ~31 ; +uintptr_t ptr; + + obj->phys_addr =page_to_phys (p); + obj->dev_addr = obj->phys_addr; + +/* FIXME: Hack around dirty cache */ + ptr = (uintptr_t )phys_to_virt (obj->phys_addr); +memset ((void *)ptr,0 ,PAGE_ALIGN (size));drivers/gpu/drm/armada/armada_gem.c line 105
Quoted 10 lines
drivers/gpu/drm/armada/armada_gem.c +10
-0+while (sz) { + asmvolatile ("mcr p15, 0, %0, c7, c14, 1" : :"r" (ptr)); + ptr +=32 ; + sz -=32 ; + } +dsb (); + + obj->page = p; + } + }maybe leave out the small size case until there is a better way to deal with cache, since this seems like just an optimization..
Quoted 4 lines
although I wonder why not just use CMA? (Other than maybe performance.. but I guess this is only for allocating scanout buffers, in which case all the bazillion of temporary pixmaps that X11 creates/deletes won't be hitting this path..)
Those won't hit this path anyway. Anyone with a shred of sanity wouldn't create something like that for such a hotpath. Calling into the kernel isn't cheap, certainly calling into the kernel memory allocators isn't. Maybe this is telling:
root@cubox:~# uptime 17:32:35 up 4 days, 6:16, 2 users, load average: 0.00, 0.01, 0.05 root@cubox:~# cat /sys/kernel/debug/dri/0/clients a dev pid uid magic ioctls
y 0 1180 0 0 102829
root@cubox:~# ps aux | grep 1180 root 1180 0.1 3.2 39916 23564 tty7 Ss+ Jun06 6:43 /usr/bin/X :0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
I cache the pixmaps in userspace for up to three seconds, which means X's temporary pixmaps are not constantly allocated and freed... much like the Intel i915 driver does.
Last point here - this path is _never_ used for X pixmaps. The only things which it's used for are the DUMB gem objects, so the scanout buffer and the cursor pixmap. So yes, the above could be removed, which would place the cursor pixmap into the linear memory.
Why not CMA? Apart from my violent distaste of that thing, and that it ignores all the issues I brought up about multiple different mappings... I refuse to use CMA.
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/armada/armada_gem.c +13
-0+int armada_gem_prop_ioctl (struct drm_device *dev,void *data, +struct drm_file *file) +{ +struct drm_armada_gem_prop *arg = data; +struct armada_gem_object *dobj; +int ret; + + ret =mutex_lock_interruptible (&dev->struct_mutex); +if (ret) +return ret; + + dobj =armada_gem_object_lookup (dev, file, arg->handle); +if (dobj ==NULL ) {
Quoted 8 lines
drivers/gpu/drm/armada/armada_gem.c line 361
Quoted 5 lines
drivers/gpu/drm/armada/armada_gem.c +5
-0+ ret = -ENOENT ; + goto unlock; + } + + arg->phys = dobj->phys_addr;ugg, do you really need to expose phys addr to userspace? Any chance to just teach the gpu bits about dmabuf instead?
Thankfully its usage is limited - and no, I'm not going to investigate yet another chunk of massive DRM code called dmabuf. The above is needed to provide the physical address of the GEM buffers to the Vivante GPU libraries and back into the kernel galcore driver. Especially important for proper fencing.
Quoted 8 lines
drivers/gpu/drm/armada/armada_gem.c
Quoted 4 lines
drivers/gpu/drm/armada/armada_gem.c +4
-0+struct drm_armada_gem_create { +uint32_t height; +uint32_t width; +uint32_t bpp;just fwiw, typically height/width/bpp are properties of the fb but not the bo.. (except in some cases where kernel needs to know this to setup GTT correctly for tiled buffers)
This was there originally because it is required that these objects be a certain pitch. I've since moved that logic into the userspace buffer manager, so the above three aren't used in my latest userspace. I didn't want to change the API yet again before all the RFC's were done, but this will be gone.
Quoted 24 lines
Quoted 24 lines
drivers/gpu/drm/armada/armada_gem.c +24
-0+uint32_t handle; +uint32_t pitch; +uint32_t size; +}; +#define DRM_IOCTL_ARMADA_GEM_CREATE \ + ARMADA_IOCTL(IOWR, GEM_CREATE, gem_create) + +struct drm_armada_gem_create_phys { +uint32_t size; +uint32_t handle; +uint64_t phys; +}; +#define DRM_IOCTL_ARMADA_GEM_CREATE_PHYS \ + ARMADA_IOCTL(IOWR, GEM_CREATE_PHYS, gem_create_phys) + +struct drm_armada_gem_mmap { +uint32_t handle; +uint32_t pad; +uint64_t offset; +uint64_t size; +uint64_t addr; +}; +#define DRM_IOCTL_ARMADA_GEM_MMAP \ + ARMADA_IOCTL(IOWR, GEM_MMAP, gem_mmap)
Quoted 8 lines
drivers/gpu/drm/armada/armada_gem.c
Quoted 5 lines
drivers/gpu/drm/armada/armada_gem.c +5
-0+ +struct drm_armada_gem_pwrite { +uint32_t handle; +uint32_t offset; +uint32_t size;probably want a
uint32_tpadding here, or move theuint64_tup in the struct to avoid 32 vs 64b alignment differences.
Yes.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 28 lines · Russell King - ARM Linux
Quoted 10 lines · Rob Clark
Quoted 7 lines · Russell King
This patch adds support for the pair of LCD controllers on the Marvell Armada 510 SoCs. This driver supports:
- multiple contiguous scanout buffers for video and graphics
- shm backed cacheable buffer objects for X pixmaps for Vivante GPU acceleration
- dual lcd0 and lcd1 crt operation
- video overlay on each LCD crtQuoted 3 lines
Any particular reason for not exposing the overlays as drm_plane's? That is probably something that should change before merging the driver.
Only through not understanding much of DRM when I started this. Provided DRM planes can do everything that I'm already doing with the overlay support, then yes. Otherwise, I want to stick with this which is modelled after the i915 overlay interface.
The big question that this brings up is that the plane stuff looks a lot more heavyweight in terms of the computation done. I'm already concerned that I'm doing too much with the overlay code - it occasionally misses getting the next frame of video ready before the VBLANK event in certain circumstances which I haven't been able to quantify. I'd rather avoid adding too much additional work here, which would then make overlay pretty useless for what it's meant for - video playback.
Quoted 4 lines
... and it looks to me like it can't - because I sometimes get blocks of physical memory with the YUV data already in appropriately formatted for scanout that I really would like to avoid having to expensively copy.
I guess I'm not entirely sure that I understand your concern here.. all that planes require is a drm fb to scan out. The GEM bo(s) that make up the backing store for that fb can be anything (phys contig if you need, etc). You could keep your putimage ioctl to dma into an fb.
Or if the decoder can decode directly into something that could be
scanned out, you can do that too.
I don't think anything about drm plane is computationally expensive. It should be about on par w/ pageflip ioctl (ie. handful of error checks, and then call into the driver).
Quoted 97 lines
Quoted 81 lines
Quoted 7 lines
- page flipping of the main scanout buffers
Included in this commit is the core driver with no output support; output support is platform and encoder driver dependent.
Signed-off-by Russell King <[email protected]>---
[snip]
Quoted 71 lines
drivers/gpu/drm/armada/armada_crtc.c new file +65
-0@@ -0,0 +1,766 @@ +/* +* Copyright (C) 2012 Russell King +* Rewritten from the dovefb driver, and Armada510 manuals. +* +* 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 <drm/drmP.h> +#include <drm/drm_crtc_helper.h> +#include "armada_crtc.h" +#include "armada_drm.h" +#include "armada_fb.h" +#include "armada_gem.h" +#include "armada_hw.h" + +struct armada_frame_work { +struct drm_pending_vblank_event *event; +struct armada_regs regs[4 ]; +struct drm_gem_object *old_fb_obj; +struct work_struct work; +}; + +/* +* A note about interlacing. Let's consider HDMI 1920x1080i. +* The timing parameters we have from X are: +* Hact HsyA HsyI Htot Vact VsyA VsyI Vtot +* 1920 2448 2492 2640 1080 1084 1094 1125 +* Which get translated to: +* Hact HsyA HsyI Htot Vact VsyA VsyI Vtot +* 1920 2448 2492 2640 540 542 547 562 +* +* This is how it is defined by CEA-861-D - line and pixel numbers are +* referenced to the rising edge of VSYNC and HSYNC. Total clocks per +* line: 2640. The odd frame, the first active line is at line 21, and +* the even frame, the first active line is 584. +* +* LN: 560 561 562 563 567 568 569 +* DE: ~~~|____________________________//__________________________ +* HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____ +* VSYNC: _________________________|~~~~~~//~~~~~~~~~~~~~~~|__________ +* 22 blanking lines. VSYNC at 1320 (referenced to the HSYNC rising edge). +* +* LN: 1123 1124 1125 1 5 6 7 +* DE: ~~~|____________________________//__________________________ +* HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____ +* VSYNC: ____________________|~~~~~~~~~~~//~~~~~~~~~~|_______________ +* 23 blanking lines +* +* The Armada LCD Controller line and pixel numbers are, like X timings, +* referenced to the top left of the active frame. +* +* So, translating these to our LCD controller: +* Odd frame, 563 total lines, VSYNC at line 543-548, pixel 1128. +* Even frame, 562 total lines, VSYNC at line 542-547, pixel 2448. +* Note: Vsync front porch remains constant! +* +* if (odd_frame) { +* vtotal = mode->crtc_vtotal + 1; +* vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay + 1; +* vhorizpos = mode->crtc_hsync_start - mode->crtc_htotal / 2 +* } else { +* vtotal = mode->crtc_vtotal; +* vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay; Quoted 8 lines
drivers/gpu/drm/armada/armada_crtc.c line 71
Quoted 6 lines
drivers/gpu/drm/armada/armada_crtc.c new file +6
-0+* vhorizpos = mode->crtc_hsync_start; +* } +* vfrontporch = mode->crtc_vtotal - mode->crtc_vsync_end; +* +* So, we need to reprogram these registers on each vsync event: +* LCD_SPU_V_PORCH, LCD_SPU_ADV_REG, LCD_SPUT_V_H_TOTAL ouch, proof that some hw designers must really hate driver writers ;-)
Yep - and interlace support is not something that can be done in a stable way with the way the Linux kernel deals with interrupts (iow, with no priority and strictly single-threaded.) The problem is to do this properly, you need the LCD interrupt able to interrupt any other interrupt handler so you can reprogram the LCD controller within a very tight timeframe (less than one display field.)
Quoted 3 lines
It works, but occasionally you will get a hiccup (mainly that's the fault of the USB stack taking 2.25ms over some of its keyboard/mouse interrupts!)
sounds like a job for fiq
Quoted 44 lines
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/armada/armada_crtc.c new file +12
-0+/* The mode_config.mutex will be held for this call */ +static int armada_drm_crtc_mode_set_base (struct drm_crtc *crtc,int x,int y, +struct drm_framebuffer *old_fb) +{ +struct armada_crtc *dcrtc =drm_to_armada_crtc (crtc); +struct armada_regs regs[4 ]; +unsigned i; + + i =armada_drm_crtc_calc_fb (crtc->fb, crtc->x, crtc->y, regs, dcrtc->interlaced); +armada_reg_queue_end (regs, i); + +/* Wait for pending flips to complete */ Quoted 8 lines
drivers/gpu/drm/armada/armada_crtc.c line 582
Quoted 4 lines
drivers/gpu/drm/armada/armada_crtc.c new file +4
-0+wait_event (dcrtc->frame_wait, !dcrtc->frame_work); + +/* Take a reference to the new fb as we're using it */ +drm_gem_object_reference (&drm_fb_obj (crtc->fb)->obj);note that you probably want to ref/unref the fb (and let the fb hold a ref to the gem bo).. that will make life easier for planar formats too (as the fb should hold ref's to the bo for each plane)
I'll look into it, but it will take some time as the refcounting is far from trivial or obvious in DRM...
From what I can see there's no intrinsic refcounting between the fb and the gem bo.
Quoted 12 lines
Quoted 1 line
drivers/gpu/drm/armada/armada_drv.c +0
-0[snip]
drivers/gpu/drm/armada/armada_drv.c line 231
Quoted 4 lines
drivers/gpu/drm/armada/armada_drv.c +4
-0+ +static struct drm_ioctl_desc armada_ioctls[] = { +DRM_IOCTL_DEF_DRV (ARMADA_GEM_CREATE , armada_gem_create_ioctl,DRM_UNLOCKED ), +DRM_IOCTL_DEF_DRV (ARMADA_GEM_CREATE_PHYS , armada_gem_create_phys_ioctl,DRM_UNLOCKED ),you might want just a single ioctl for creating gem objects, with a 'scanout' flag.. perhaps some future version of the hw doesn't need phys contig for scanout, and this would probably be easier to handle with a single ioctl that has an 'if (flags & SCANOUT &&
device_needs_phys_contig_scanout()) .. 'The purposes of these two ioctls are quite different.
ARMADA_GEM_CREATEis to create any gem buffer object that needs shmem backing - eg, non-scanout pixmaps and the like.
Quoted 7 lines
ARMADA_GEM_CREATE_PHYSis to deal with creating a gem buffer object for a chunk of physical memory allocated by other means (eg, the Vmeta stuff.) This allows my X server to remain compatible with the XF86 Dove driver, which permits the passing of the physical address of the video frame to the X server (otherwise we're into rewriting a whole load more code than is really desirable - and I really don't have time to rewrite bits of gstreamer and other stuff.)
ahh, gotcha.. and, ugg, that is even worse..
I'm not hugely a fan of giving userspace a way to dma into arbitrary phys addresses (ie. create_phys + put_image). But I don't need to explain what you already know ;-)
Is there a pre-defined carveout pool that you can at least bounds check against? Otherwise put this ioctl inside a #if CONFIG_CRAZY_SOC_VENDOR_HOLE_TO_DRIVE_A_TRUCK_THROUGH / #endif..
Quoted 95 lines
Lastly, the DUMB stuff is used for the graphics scanout buffer.
Quoted 39 lines
Quoted 1 line
drivers/gpu/drm/armada/armada_gem.c +0
-0[snip]
Quoted 23 lines
drivers/gpu/drm/armada/armada_gem.c +23
-0+int armada_gem_linear_back (struct drm_device *dev,struct armada_gem_object *obj) +{ +struct armada_private *priv = dev->dev_private; +size_t size = obj->obj.size; + +if (obj->page || obj->linear) +return 0 ; + +/* If it is a small allocation, try to get it from the system */ +if (size <1048576 ) { +unsigned int order =get_order (size); +struct page *p =alloc_pages (GFP_KERNEL , order); + +if (p) { +unsigned sz = (size +31 ) & ~31 ; +uintptr_t ptr; + + obj->phys_addr =page_to_phys (p); + obj->dev_addr = obj->phys_addr; + +/* FIXME: Hack around dirty cache */ + ptr = (uintptr_t )phys_to_virt (obj->phys_addr); +memset ((void *)ptr,0 ,PAGE_ALIGN (size));drivers/gpu/drm/armada/armada_gem.c line 105
Quoted 10 lines
drivers/gpu/drm/armada/armada_gem.c +10
-0+while (sz) { + asmvolatile ("mcr p15, 0, %0, c7, c14, 1" : :"r" (ptr)); + ptr +=32 ; + sz -=32 ; + } +dsb (); + + obj->page = p; + } + }maybe leave out the small size case until there is a better way to deal with cache, since this seems like just an optimization..
Quoted 4 lines
although I wonder why not just use CMA? (Other than maybe performance.. but I guess this is only for allocating scanout buffers, in which case all the bazillion of temporary pixmaps that X11 creates/deletes won't be hitting this path..)
Those won't hit this path anyway. Anyone with a shred of sanity wouldn't create something like that for such a hotpath. Calling into the kernel isn't cheap, certainly calling into the kernel memory allocators isn't. Maybe this is telling:
root@cubox:~# uptime 17:32:35 up 4 days, 6:16, 2 users, load average: 0.00, 0.01, 0.05 root@cubox:~# cat /sys/kernel/debug/dri/0/clients a dev pid uid magic ioctlsy 0 1180 0 0 102829
root@cubox:~# ps aux | grep 1180 root 1180 0.1 3.2 39916 23564 tty7 Ss+ Jun06 6:43 /usr/bin/X :0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitchI cache the pixmaps in userspace for up to three seconds, which means X's temporary pixmaps are not constantly allocated and freed... much like the Intel i915 driver does.
Last point here - this path is _never_ used for X pixmaps. The only things which it's used for are the DUMB gem objects, so the scanout buffer and the cursor pixmap. So yes, the above could be removed, which would place the cursor pixmap into the linear memory.
Why not CMA? Apart from my violent distaste of that thing, and that it ignores all the issues I brought up about multiple different mappings... I refuse to use CMA.
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/armada/armada_gem.c +13
-0+int armada_gem_prop_ioctl (struct drm_device *dev,void *data, +struct drm_file *file) +{ +struct drm_armada_gem_prop *arg = data; +struct armada_gem_object *dobj; +int ret; + + ret =mutex_lock_interruptible (&dev->struct_mutex); +if (ret) +return ret; + + dobj =armada_gem_object_lookup (dev, file, arg->handle); +if (dobj ==NULL ) {Quoted 8 lines
drivers/gpu/drm/armada/armada_gem.c line 361
Quoted 5 lines
drivers/gpu/drm/armada/armada_gem.c +5
-0+ ret = -ENOENT ; + goto unlock; + } + + arg->phys = dobj->phys_addr;ugg, do you really need to expose phys addr to userspace? Any chance to just teach the gpu bits about dmabuf instead?
Quoted 5 lines
Thankfully its usage is limited - and no, I'm not going to investigate yet another chunk of massive DRM code called dmabuf. The above is needed to provide the physical address of the GEM buffers to the Vivante GPU libraries and back into the kernel galcore driver. Especially important for proper fencing.
hmm, well dmabuf isn't too bad (drm core takes care of a lot of it for you).. I don't know how much the impact would be to add dmabuf support in the various other drivers that you have to care about. Maybe '#if CONFIG_CRAZY_SOC_VENDOR_HOLE_TO_DRIVE_A_TRUCK_THROUGH' it.. or at least keep it a patch on top of the upstream driver since it is the sort of thing that you'd want to get rid of if the other marvel drivers eventually give you a way to do dmabuf?
I'm not really sure what others think, but I am uneasy about this and the create_phys ioctl.
Quoted 9 lines
Quoted 8 lines
drivers/gpu/drm/armada/armada_gem.c
Quoted 4 lines
drivers/gpu/drm/armada/armada_gem.c +4
-0+struct drm_armada_gem_create { +uint32_t height; +uint32_t width; +uint32_t bpp;just fwiw, typically height/width/bpp are properties of the fb but not the bo.. (except in some cases where kernel needs to know this to setup GTT correctly for tiled buffers)
Quoted 5 lines
This was there originally because it is required that these objects be a certain pitch. I've since moved that logic into the userspace buffer manager, so the above three aren't used in my latest userspace. I didn't want to change the API yet again before all the RFC's were done, but this will be gone.
sure, no prob. Probably worth mentioning in the commit msg, though ;-)
BR,
-R
Quoted 34 lines
Quoted 24 lines
Quoted 24 lines
drivers/gpu/drm/armada/armada_gem.c +24
-0+uint32_t handle; +uint32_t pitch; +uint32_t size; +}; +#define DRM_IOCTL_ARMADA_GEM_CREATE \ + ARMADA_IOCTL(IOWR, GEM_CREATE, gem_create) + +struct drm_armada_gem_create_phys { +uint32_t size; +uint32_t handle; +uint64_t phys; +}; +#define DRM_IOCTL_ARMADA_GEM_CREATE_PHYS \ + ARMADA_IOCTL(IOWR, GEM_CREATE_PHYS, gem_create_phys) + +struct drm_armada_gem_mmap { +uint32_t handle; +uint32_t pad; +uint64_t offset; +uint64_t size; +uint64_t addr; +}; +#define DRM_IOCTL_ARMADA_GEM_MMAP \ + ARMADA_IOCTL(IOWR, GEM_MMAP, gem_mmap)Quoted 8 lines
drivers/gpu/drm/armada/armada_gem.c
Quoted 5 lines
drivers/gpu/drm/armada/armada_gem.c +5
-0+ +struct drm_armada_gem_pwrite { +uint32_t handle; +uint32_t offset; +uint32_t size;probably want a
uint32_tpadding here, or move theuint64_tup in the struct to avoid 32 vs 64b alignment differences.Yes.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 12 lines · Rob Clark
Quoted 7 lines · Russell King - ARM Linux
ARMADA_GEM_CREATE_PHYSis to deal with creating a gem buffer object for a chunk of physical memory allocated by other means (eg, the Vmeta stuff.) This allows my X server to remain compatible with the XF86 Dove driver, which permits the passing of the physical address of the video frame to the X server (otherwise we're into rewriting a whole load more code than is really desirable - and I really don't have time to rewrite bits of gstreamer and other stuff.)ahh, gotcha.. and, ugg, that is even worse..
Quoted 7 lines
I'm not hugely a fan of giving userspace a way to dma into arbitrary phys addresses (ie.
create_phys+put_image). But I don't need to explain what you already know ;-)Is there a pre-defined carveout pool that you can at least bounds check against? Otherwise put this ioctl inside a #if
CONFIG_CRAZY_SOC_VENDOR_HOLE_TO_DRIVE_A_TRUCK_THROUGH/ #endif..
This driver is _not_ about supporting the GPU natively as part of the DRM, but providing the foundations for:
(a) a properly functional interface to HDMI TVs (fbdev doesn't hack that) with hotplug
(b) providing sufficient infrastructure to allow video playback to work.
What this is not about is fixing the crappy userspace GPU libraries and video decoding so that it's "secure" - not only is that way beyond my abilities, it would also be a violation of the closed source license to reverse engineer them so that were possible.
It is something that continues to be a problem and I'm making no claims that I'm fixing that. So no, I will not put such a config option around it for the simple reason that by doing so, turning such an option off renders userspace utterly useless and the driver might as well not exist.
If that means you want to NACK the patch, then fine; I'll just maintain it out of tree. I did the driver mostly for my own personal benefit to get the Cubox to the point where I can boot it with or without the TV connected and have it work. But it would be a shame if that meant that others could not benefit from about 8 solid months of my work on this and have to put up with crappy a fbdev driver.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 21 lines · Russell King - ARM Linux
Quoted 12 lines · Rob Clark
Quoted 7 lines · Russell King - ARM Linux
ARMADA_GEM_CREATE_PHYSis to deal with creating a gem buffer object for a chunk of physical memory allocated by other means (eg, the Vmeta stuff.) This allows my X server to remain compatible with the XF86 Dove driver, which permits the passing of the physical address of the video frame to the X server (otherwise we're into rewriting a whole load more code than is really desirable - and I really don't have time to rewrite bits of gstreamer and other stuff.)ahh, gotcha.. and, ugg, that is even worse..
Quoted 7 lines
I'm not hugely a fan of giving userspace a way to dma into arbitrary phys addresses (ie.
create_phys+put_image). But I don't need to explain what you already know ;-)Is there a pre-defined carveout pool that you can at least bounds check against? Otherwise put this ioctl inside a #if
CONFIG_CRAZY_SOC_VENDOR_HOLE_TO_DRIVE_A_TRUCK_THROUGH/ #endif..
Quoted 6 lines
This driver is _not_ about supporting the GPU natively as part of the DRM, but providing the foundations for:
(a) a properly functional interface to HDMI TVs (fbdev doesn't hack that) with hotplug
(b) providing sufficient infrastructure to allow video playback to work.
sure, but even omitting the phys ioctls gives you (a), which seems like it is useful on it's own. And would, I expect, be pretty useful for the etnaviv folks working on r/e the gpu.
Quoted 4 lines
What this is not about is fixing the crappy userspace GPU libraries and video decoding so that it's "secure" - not only is that way beyond my abilities, it would also be a violation of the closed source license to reverse engineer them so that were possible.
yeah, once you add the vendor gpu/etc drivers, if they are also giving you a way to pass a phys addr, then plugging the holes in the drm/kms driver won't do any good. But in a way that is some other non-upstream driver's problem.
Quoted 11 lines
It is something that continues to be a problem and I'm making no claims that I'm fixing that. So no, I will not put such a config option around it for the simple reason that by doing so, turning such an option off renders userspace utterly useless and the driver might as well not exist.
If that means you want to NACK the patch, then fine; I'll just maintain it out of tree. I did the driver mostly for my own personal benefit to get the Cubox to the point where I can boot it with or without the TV connected and have it work. But it would be a shame if that meant that others could not benefit from about 8 solid months of my work on this and have to put up with crappy a fbdev driver.
I would like to get at least some of the driver upstream. I'd hate for it to have to live completely out of tree. I can think of a couple possibilities.
1) the best would be, if there was some way for the drm driver to know the upper/lower bounds of the carveout, then it could bounds-check against this. And then in worst case, userspace can just screw up other "graphics" buffers
2) if #1 weren't possible, then maybe just keep the phys ioctls as a small patch on top of upstream. The at least out of the box you get modesetting. I had to do something like this w/ omapdrm for gluing it together w/ sgx/pvr stuff. I re-arranged the code a bit to group all the non-upstream bits together to avoid merge/rebase conflicts.
BR,
-R
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 8 lines · Rob Clark
I would like to get at least some of the driver upstream. I'd hate for it to have to live completely out of tree. I can think of a couple possibilities.
1) the best would be, if there was some way for the drm driver to know the upper/lower bounds of the carveout, then it could bounds-check against this. And then in worst case, userspace can just screw up other "graphics" buffers
The bounds check does what? Check that the buffer object's physical address is within another driver's range? Fine, but all that it's doing is preventing it being associated with a buffer object which can _only_ be used for _read_ access by the LCD controller. There is no write access to the GEM objects by anything that this DRM driver talks to.
So all it'll do is prevent you passing rogue addresses to the LCD controller for scanout.
And how do we get that information into the driver from other random drivers? Hack in random inter-driver specific APIs to do it? Come up with yet another different way to try and identify whether a particular resource is a block of reserved memory for this driver's usage as a linear region or one of the others? How. Really, please think about the problem.
The benefit vs the complexity involved really isn't worth it.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 10 lines · Russell King - ARM Linux
Quoted 8 lines · Rob Clark
I would like to get at least some of the driver upstream. I'd hate for it to have to live completely out of tree. I can think of a couple possibilities.
1) the best would be, if there was some way for the drm driver to know the upper/lower bounds of the carveout, then it could bounds-check against this. And then in worst case, userspace can just screw up other "graphics" buffers
Quoted 6 lines
The bounds check does what? Check that the buffer object's physical address is within another driver's range? Fine, but all that it's doing is preventing it being associated with a buffer object which can _only_ be used for _read_ access by the LCD controller. There is no write access to the GEM objects by anything that this DRM driver talks to.
I was assuming there was a global carveout pool, so it would be just one upper/lower check. But from what you said and looking at the allocation code in your driver, I guess this is not actually the case.
Quoted 11 lines
So all it'll do is prevent you passing rogue addresses to the LCD controller for scanout.
And how do we get that information into the driver from other random drivers? Hack in random inter-driver specific APIs to do it? Come up with yet another different way to try and identify whether a particular resource is a block of reserved memory for this driver's usage as a linear region or one of the others? How. Really, please think about the problem.
The benefit vs the complexity involved really isn't worth it.
yeah, that suggestion was based on a wrong assumption about how the phys contig buffers are allocated and passed. So disregard it.
I guess in the short term, the best I can think is keep those phys ioctls as a small patch on top of the upstream driver. It is ok to leave place-holder ioctl #'s in the upstream driver so that the ioctl #'s don't shift when you rebase. And then try to get the vendor to add support for dmabuf so that the patch on top of upstream can eventually be dropped. Maybe someone else has a better suggestion, but I don't think we can merge those phys ioctls upstream, and I'd really hate to 'throw the baby out with the bathwater' in this case and not at least get the modesetting part of the driver merged.
BR,
-R
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 9 lines · Rob Clark
I guess in the short term, the best I can think is keep those phys ioctls as a small patch on top of the upstream driver. It is ok to leave place-holder ioctl #'s in the upstream driver so that the ioctl #'s don't shift when you rebase. And then try to get the vendor to add support for dmabuf so that the patch on top of upstream can eventually be dropped. Maybe someone else has a better suggestion, but I don't think we can merge those phys ioctls upstream, and I'd really hate to 'throw the baby out with the bathwater' in this case and not at least get the modesetting part of the driver merged.
What you're saying is basically:
1. Throw out DRM_ARMADA_GEM_CREATE_PHYS, which cripples video playback on existing gstreamer, xbmc and other implementations without someone rewriting all that code.
2. Throw out DRM_ARMADA_GEM_PROP, which prevents any form of passing the GEM objects to the GPU libraries in userspace, thereby preventing any kind of GPU based acceleration.
That makes the driver just be a dumb scanout only driver. Sorry, that *really* does not interest me one bit, because the CPU doing framebuffer accesses is pig slow.
There's really no point in such a driver; people might as well just use the standard fbdev driver instead.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 17 lines · Russell King - ARM Linux
Quoted 9 lines · Rob Clark
I guess in the short term, the best I can think is keep those phys ioctls as a small patch on top of the upstream driver. It is ok to leave place-holder ioctl #'s in the upstream driver so that the ioctl #'s don't shift when you rebase. And then try to get the vendor to add support for dmabuf so that the patch on top of upstream can eventually be dropped. Maybe someone else has a better suggestion, but I don't think we can merge those phys ioctls upstream, and I'd really hate to 'throw the baby out with the bathwater' in this case and not at least get the modesetting part of the driver merged.
What you're saying is basically:
1. Throw out
DRM_ARMADA_GEM_CREATE_PHYS, which cripples video playback on existing gstreamer, xbmc and other implementations without someone rewriting all that code.
Quoted 7 lines
2. Throw out
DRM_ARMADA_GEM_PROP, which prevents any form of passing the GEM objects to the GPU libraries in userspace, thereby preventing any kind of GPU based acceleration.That makes the driver just be a dumb scanout only driver. Sorry, that *really* does not interest me one bit, because the CPU doing framebuffer accesses is pig slow.
Well, yes that is basically what I am saying, unless we can find a different way (dmabuf? if there is some way to pass it through the blob bits you don't have src code for?)
The problem is that we really can't merge something upstream that lets you dma to arbitrary physical address. Maybe in staging, perhaps? Or otherwise if there is no other way, I hope someone will at least pick up the modesetting parts of it and get that merged upstream. The rest of the driver is looking pretty good, and I think it would be useful to have upstream.
BR,
-R
Quoted 2 lines
There's really no point in such a driver; people might as well just use the standard fbdev driver instead.
Dave Airlie
maintainerRe: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 9 lines
Quoted 4 lines
That makes the driver just be a dumb scanout only driver. Sorry, that *really* does not interest me one bit, because the CPU doing framebuffer accesses is pig slow.
Well, yes that is basically what I am saying, unless we can find a different way (dmabuf? if there is some way to pass it through the blob bits you don't have src code for?)
Quoted 6 lines
The problem is that we really can't merge something upstream that lets you dma to arbitrary physical address. Maybe in staging, perhaps? Or otherwise if there is no other way, I hope someone will at least pick up the modesetting parts of it and get that merged upstream. The rest of the driver is looking pretty good, and I think it would be useful to have upstream.
Totally what he said.
upstream shouldn't be restricted by the bad decisions of others, and adding security bypasses is one of them.
I'd like to see all the ARM based drivers based on CMA if it can meet their requirements
and using close to standard GEM/dma-buf interfaces. Otherwise it'll be come an unmaintainable
nightmare for everyone, but mostly for me.
Merging the base dumb KMS driver, then working out acceptable ways to provide the extra
features is definitely the nicest way to do things.
Dave.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 16 lines · Dave Airlie
Quoted 9 lines
Quoted 4 lines
That makes the driver just be a dumb scanout only driver. Sorry, that *really* does not interest me one bit, because the CPU doing framebuffer accesses is pig slow.
Well, yes that is basically what I am saying, unless we can find a different way (dmabuf? if there is some way to pass it through the blob bits you don't have src code for?)
Quoted 6 lines
The problem is that we really can't merge something upstream that lets you dma to arbitrary physical address. Maybe in staging, perhaps? Or otherwise if there is no other way, I hope someone will at least pick up the modesetting parts of it and get that merged upstream. The rest of the driver is looking pretty good, and I think it would be useful to have upstream.
Quoted 7 lines
Totally what he said.
upstream shouldn't be restricted by the bad decisions of others, and adding security bypasses is one of them.
I'd like to see all the ARM based drivers based on CMA if it can meet their requirements
afaiu CMA has issues w/ changing cache attributes of pages on older architectures like Russell is using. Although perhaps on older arm CMA should just be a straight carveout pool and not try to recycle the unused pages. At least then it would be the same API for the drivers.
BR,
-R
Quoted 9 lines
and using close to standard GEM/dma-buf interfaces. Otherwise it'll be come an unmaintainable
nightmare for everyone, but mostly for me.Merging the base dumb KMS driver, then working out acceptable ways to provide the extra
features is definitely the nicest way to do things.Dave.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
In reply to Dave AirlieQuoted 5 lines · Dave Airlie
I'd like to see all the ARM based drivers based on CMA if it can meet their requirements
and using close to standard GEM/dma-buf interfaces. Otherwise it'll be come an unmaintainable
nightmare for everyone, but mostly for me.
I am *not* using the CMA layer - that layer is just plain broken in DRM. It forces every single gem object to be a CMA allocated object, which means I can't have cacheable pixmaps in X. And that makes X suck.
Okay, I'm pulling this and I'm going to keep it in my private cubox tree; I'm not persuing pushing this driver or any other Armada 510 driver into mainline anymore. It's just too much fscking hastle dealing with people who don't like various stuff.
I've done my best to clean a lot of the crap up, and the problem is that no matter how much I clean up, it remains unacceptable. Only the 100% perfect solution seems to be acceptable. That is unacceptable given that this stuff has already consumed something like 8 months solid of my time.
So no, I'm not wasting any further time on this crap.
Dave Airlie
maintainerRe: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 17 lines · Russell King - ARM Linux
Quoted 5 lines · Dave Airlie
I'd like to see all the ARM based drivers based on CMA if it can meet their requirements
and using close to standard GEM/dma-buf interfaces. Otherwise it'll be come an unmaintainable
nightmare for everyone, but mostly for me.I am *not* using the CMA layer - that layer is just plain broken in DRM. It forces every single gem object to be a CMA allocated object, which means I can't have cacheable pixmaps in X. And that makes X suck.
Okay, I'm pulling this and I'm going to keep it in my private cubox tree; I'm not persuing pushing this driver or any other Armada 510 driver into mainline anymore. It's just too much fscking hastle dealing with people who don't like various stuff.
Quoted 5 lines
I've done my best to clean a lot of the crap up, and the problem is that no matter how much I clean up, it remains unacceptable. Only the 100% perfect solution seems to be acceptable. That is unacceptable given that this stuff has already consumed something like 8 months solid of my time.
Russell, aren't you a kernel maintainer, because for fuck sake get real.
I'm not merging bullshit into my tree that has a completely broken API that has to be maintained for ever. You of all people should understand we don't break Linux
userspace APIs, and adding a phys addr one is wrong, wrong, wrong, its not cleanups, its just broken, and I'll never merge it.
Dave.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 25 lines · Dave Airlie
Quoted 17 lines · Russell King - ARM Linux
Quoted 5 lines · Dave Airlie
I'd like to see all the ARM based drivers based on CMA if it can meet their requirements
and using close to standard GEM/dma-buf interfaces. Otherwise it'll be come an unmaintainable
nightmare for everyone, but mostly for me.I am *not* using the CMA layer - that layer is just plain broken in DRM. It forces every single gem object to be a CMA allocated object, which means I can't have cacheable pixmaps in X. And that makes X suck.
Okay, I'm pulling this and I'm going to keep it in my private cubox tree; I'm not persuing pushing this driver or any other Armada 510 driver into mainline anymore. It's just too much fscking hastle dealing with people who don't like various stuff.
Quoted 5 lines
I've done my best to clean a lot of the crap up, and the problem is that no matter how much I clean up, it remains unacceptable. Only the 100% perfect solution seems to be acceptable. That is unacceptable given that this stuff has already consumed something like 8 months solid of my time.
Quoted 7 lines
Russell, aren't you a kernel maintainer, because for fuck sake get real.
I'm not merging bullshit into my tree that has a completely broken API that has to be maintained for ever. You of all people should understand we don't break Linux
userspace APIs, and adding a phys addr one is wrong, wrong, wrong, its not cleanups, its just broken, and I'll never merge it.
As I say, I'm no longer interested in pushing this into mainline. I've said my piece above, and I'm not changing that. I'm not spending years trying to sort this stuff out, by which time the platforms using it will be long since obsolete. The "8 months" is not an exaggeration. That's the time taken to sort out the kernel side, the libdrm stuff, the X server driver, and get video decode working on these platforms with vlc.
It works for me, and that's really at this point all I care about.
And yes, I'm a kernel maintainer. A FUCKING busy one right now at that. I haven't stopped working since 9am today yet, and it's now 1am. Do the maths. I really wish I had some time to myself now to think about some of these bigger issues which this has brought up, but I don't.
And no, I *never* said that adding a phys address was a cleanup.
Sheesh why don't you read my emails properly. Another reason why I won't be continuing this discussion much further.
I said that _this_ amount of effort is a result of doing *LOTS* of cleanups. A DRM driver for this hardware *didn't* exist until I wrote it. There was a fbdev driver before, which was passed phys addresses there for the overlay, and passed phys addresses back out after the overlay frame has been replaced.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
In reply to Dave AirlieQuoted 25 lines · Dave Airlie
Quoted 17 lines · Russell King - ARM Linux
Quoted 5 lines · Dave Airlie
I'd like to see all the ARM based drivers based on CMA if it can meet their requirements
and using close to standard GEM/dma-buf interfaces. Otherwise it'll be come an unmaintainable
nightmare for everyone, but mostly for me.I am *not* using the CMA layer - that layer is just plain broken in DRM. It forces every single gem object to be a CMA allocated object, which means I can't have cacheable pixmaps in X. And that makes X suck.
Okay, I'm pulling this and I'm going to keep it in my private cubox tree; I'm not persuing pushing this driver or any other Armada 510 driver into mainline anymore. It's just too much fscking hastle dealing with people who don't like various stuff.
Quoted 5 lines
I've done my best to clean a lot of the crap up, and the problem is that no matter how much I clean up, it remains unacceptable. Only the 100% perfect solution seems to be acceptable. That is unacceptable given that this stuff has already consumed something like 8 months solid of my time.
Quoted 7 lines
Russell, aren't you a kernel maintainer, because for fuck sake get real.
I'm not merging bullshit into my tree that has a completely broken API that has to be maintained for ever. You of all people should understand we don't break Linux
userspace APIs, and adding a phys addr one is wrong, wrong, wrong, its not cleanups, its just broken, and I'll never merge it.
And having thought about this driver, DRM some more, I'm now of the opinion that DRM is not suitable for driving hardware where the GPU is an entirely separate IP block from the display side.
DRM is modelled after the PC setup where your "graphics card" does everything - it has the GPU, display and connectors all integrated together. This is not the case on embedded SoCs, which can be a collection of different IPs all integrated together.
DRM is based on the assumption that you have a single card and everything is known about that card. Again, this is not the case with embedded SoCs, which is why Sebastian is having a hard time with the DRM slave encoder stuff.
If DRM is going to be usable on SoCs, it needs to become more modular in nature, allowing the same scanout stuff to be used with different GPUs and providing _kernel_ side interfaces to allow different GPUs to be plugged in to a scanout implementation, or vice versa (the reverse is probably easier because the scanout interface is nicely abstracted).
Or we go off and write an entirely new subsystem which *does* suit the needs of modular SoC implementations.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 34 lines · Russell King - ARM Linux
Quoted 25 lines · Dave Airlie
Quoted 17 lines · Russell King - ARM Linux
Quoted 5 lines · Dave Airlie
I'd like to see all the ARM based drivers based on CMA if it can meet their requirements
and using close to standard GEM/dma-buf interfaces. Otherwise it'll be come an unmaintainable
nightmare for everyone, but mostly for me.I am *not* using the CMA layer - that layer is just plain broken in DRM. It forces every single gem object to be a CMA allocated object, which means I can't have cacheable pixmaps in X. And that makes X suck.
Okay, I'm pulling this and I'm going to keep it in my private cubox tree; I'm not persuing pushing this driver or any other Armada 510 driver into mainline anymore. It's just too much fscking hastle dealing with people who don't like various stuff.
Quoted 5 lines
I've done my best to clean a lot of the crap up, and the problem is that no matter how much I clean up, it remains unacceptable. Only the 100% perfect solution seems to be acceptable. That is unacceptable given that this stuff has already consumed something like 8 months solid of my time.
Quoted 7 lines
Russell, aren't you a kernel maintainer, because for fuck sake get real.
I'm not merging bullshit into my tree that has a completely broken API that has to be maintained for ever. You of all people should understand we don't break Linux
userspace APIs, and adding a phys addr one is wrong, wrong, wrong, its not cleanups, its just broken, and I'll never merge it.
Quoted 8 lines
And having thought about this driver, DRM some more, I'm now of the opinion that DRM is not suitable for driving hardware where the GPU is an entirely separate IP block from the display side.
DRM is modelled after the PC setup where your "graphics card" does everything - it has the GPU, display and connectors all integrated together. This is not the case on embedded SoCs, which can be a collection of different IPs all integrated together.
actually it isn't even the case on desktop/laptop anymore, where you can have one gpu with scanout and a second one without (or just with display controller not hooked up to anything, etc, etc)
That is the point of dmabuf and the upcoming fence/reservation stuff.
BR,
-R
Quoted 13 lines
DRM is based on the assumption that you have a single card and everything is known about that card. Again, this is not the case with embedded SoCs, which is why Sebastian is having a hard time with the DRM slave encoder stuff.
If DRM is going to be usable on SoCs, it needs to become more modular in nature, allowing the same scanout stuff to be used with different GPUs and providing _kernel_ side interfaces to allow different GPUs to be plugged in to a scanout implementation, or vice versa (the reverse is probably easier because the scanout interface is nicely abstracted).
Or we go off and write an entirely new subsystem which *does* suit the needs of modular SoC implementations.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 11 lines · Rob Clark
Quoted 8 lines · Russell King - ARM Linux
And having thought about this driver, DRM some more, I'm now of the opinion that DRM is not suitable for driving hardware where the GPU is an entirely separate IP block from the display side.
DRM is modelled after the PC setup where your "graphics card" does everything - it has the GPU, display and connectors all integrated together. This is not the case on embedded SoCs, which can be a collection of different IPs all integrated together.
Quoted 5 lines
actually it isn't even the case on desktop/laptop anymore, where you can have one gpu with scanout and a second one without (or just with display controller not hooked up to anything, etc, etc)
That is the point of dmabuf and the upcoming fence/reservation stuff.
Okay, but dmabuf really needs to be fixed, because as it stands this API is really quite broken wrt the DMA API. dma_map_sg() is (a) not supposed to have its return value ignored - mappings can fail, and (b) the returned number indicates how many entries are valid for the _mapped_ version of the scatterlist.
Both these points are important if your DMA API implementation uses an IOMMU, which may coalesce the scatterlist array when creating mappings - much as described in Documentation/DMA-API.txt and Documentation/DMA-API-HOWTO.txt.
That is not all DRMs fault - (a) is attributable to DRM's prime implementation:
sgt = obj->dev->driver->gem_prime_get_sg_table(obj);
if (!IS_ERR_OR_NULL(sgt))
dma_map_sg(attach->dev, sgt->sgl, sgt->nents, dir);and quite why it does the dma_map_sg() beneath the struct_mutex is beyond me - if the array of pages isn't safe without the mutex being held, then it isn't safe after the dma_map_sg() operation has completed and the mutex has been released.
However, (b) is more a problem for dmabuf (which I just rather aptly mistyped as dmabug) because either dmabuf's .map_dma_buf method needs to return the value from dma_map_sg(), or it needs to stop requiring this of the .map_dma_buf method and have it done by the caller of this method so the caller can have access to that returned value.
Added Sumit Semwal to this email for the dmabuf issue.
Thankfully, this being correct isn't a requirement for me, but it's something which _should_ be fixed.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 48 lines · Russell King - ARM Linux
Quoted 11 lines · Rob Clark
Quoted 8 lines · Russell King - ARM Linux
And having thought about this driver, DRM some more, I'm now of the opinion that DRM is not suitable for driving hardware where the GPU is an entirely separate IP block from the display side.
DRM is modelled after the PC setup where your "graphics card" does everything - it has the GPU, display and connectors all integrated together. This is not the case on embedded SoCs, which can be a collection of different IPs all integrated together.
Quoted 5 lines
actually it isn't even the case on desktop/laptop anymore, where you can have one gpu with scanout and a second one without (or just with display controller not hooked up to anything, etc, etc)
That is the point of dmabuf and the upcoming fence/reservation stuff.
Okay, but dmabuf really needs to be fixed, because as it stands this API is really quite broken wrt the DMA API.
dma_map_sg()is (a) not supposed to have its return value ignored - mappings can fail, and (b) the returned number indicates how many entries are valid for the _mapped_ version of the scatterlist.Both these points are important if your DMA API implementation uses an IOMMU, which may coalesce the scatterlist array when creating mappings - much as described in
Documentation/DMA-API.txtandDocumentation/DMA-API-HOWTO.txt.That is not all DRMs fault - (a) is attributable to DRM's prime implementation:
sgt = obj->dev->driver->gem_prime_get_sg_table(obj); if (!IS_ERR_OR_NULL(sgt)) dma_map_sg(attach->dev, sgt->sgl, sgt->nents, dir);and quite why it does the
dma_map_sg()beneath thestruct_mutexis beyond me - if the array of pages isn't safe without the mutex being held, then it isn't safe after thedma_map_sg()operation has completed and the mutex has been released.However, (b) is more a problem for dmabuf (which I just rather aptly mistyped as dmabug) because either dmabuf's .map_dma_buf method needs to return the value from
dma_map_sg(), or it needs to stop requiring this of the .map_dma_buf method and have it done by the caller of this method so the caller can have access to that returned value.
Quoted 4 lines
Added Sumit Semwal to this email for the dmabuf issue.
Thankfully, this being correct isn't a requirement for me, but it's something which _should_ be fixed.
Okay, so Sumit Semwal has been a victim of TI's cuts, so don't expect dma_buf to get sorted by the original author...
Now we come to this:
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c: return dma_buf_export(exynos_gem_obj, &exynos_dmabuf_ops,drivers/gpu/drm/exynos/exynos_drm_dmabuf.c- exynos_gem_obj->base.size, flags);drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c: return dma_buf_export(obj, &omap_dmabuf_ops, obj->size, flags);drivers/gpu/drm/drm_prime.c: return dma_buf_export(obj, &drm_gem_prime_dmabuf_ops, obj->size,drivers/gpu/drm/drm_prime.c- 0600);drivers/gpu/drm/i915/i915_gem_dmabuf.c: return dma_buf_export(obj, &i915_dmabuf_ops, obj->base.size, flags);
Of the three implementations which don't use the generic version, they all pass 'flags' to dma_buf_export. drm_prime.c doesn't, it passes a fixed file mode. What's the correct version, or is flags | 0600 actually the right one (as flags only contains O_CLOEXEC)?
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 49 lines · Russell King - ARM Linux
Quoted 48 lines · Russell King - ARM Linux
Quoted 11 lines · Rob Clark
Quoted 8 lines · Russell King - ARM Linux
And having thought about this driver, DRM some more, I'm now of the opinion that DRM is not suitable for driving hardware where the GPU is an entirely separate IP block from the display side.
DRM is modelled after the PC setup where your "graphics card" does everything - it has the GPU, display and connectors all integrated together. This is not the case on embedded SoCs, which can be a collection of different IPs all integrated together.
Quoted 5 lines
actually it isn't even the case on desktop/laptop anymore, where you can have one gpu with scanout and a second one without (or just with display controller not hooked up to anything, etc, etc)
That is the point of dmabuf and the upcoming fence/reservation stuff.
Okay, but dmabuf really needs to be fixed, because as it stands this API is really quite broken wrt the DMA API.
dma_map_sg()is (a) not supposed to have its return value ignored - mappings can fail, and (b) the returned number indicates how many entries are valid for the _mapped_ version of the scatterlist.Both these points are important if your DMA API implementation uses an IOMMU, which may coalesce the scatterlist array when creating mappings - much as described in
Documentation/DMA-API.txtandDocumentation/DMA-API-HOWTO.txt.That is not all DRMs fault - (a) is attributable to DRM's prime implementation:
sgt = obj->dev->driver->gem_prime_get_sg_table(obj); if (!IS_ERR_OR_NULL(sgt)) dma_map_sg(attach->dev, sgt->sgl, sgt->nents, dir);and quite why it does the
dma_map_sg()beneath thestruct_mutexis beyond me - if the array of pages isn't safe without the mutex being held, then it isn't safe after thedma_map_sg()operation has completed and the mutex has been released.However, (b) is more a problem for dmabuf (which I just rather aptly mistyped as dmabug) because either dmabuf's .map_dma_buf method needs to return the value from
dma_map_sg(), or it needs to stop requiring this of the .map_dma_buf method and have it done by the caller of this method so the caller can have access to that returned value.
Quoted 7 lines
Quoted 4 lines
Added Sumit Semwal to this email for the dmabuf issue.
Thankfully, this being correct isn't a requirement for me, but it's something which _should_ be fixed.
Okay, so Sumit Semwal has been a victim of TI's cuts, so don't expect
dma_bufto get sorted by the original author...
And now the next muckup in dma-buf/drm_prime - though it's arguably the fault of IS_ERR_OR_NULL existing in the first place:
drm_gem_prime_import()
{
sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
if (IS_ERR_OR_NULL(sgt)) {
ret = PTR_ERR(sgt);
goto fail_detach;
}
fail_detach:
dma_buf_detach(dma_buf, attach);
return ERR_PTR(ret);
}What happens if sgt is NULL here? What value does ret get? What does drm_gem_prime_import() return? How is that interpreted by drm_gem_prime_fd_to_handle() ?
I can probably oops a kernel running DRM through this if I can manipulate a dma_buf_map_attachment() to return NULL (there probably is a driver which is capable of doing so.)
APIs which use IS_ERR_OR_NULL() are problems waiting to happen; we've already reached some concensus a while back to get rid of this helper, if only it wasn't soo prolific (like its errors are.)
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
And here's another one - look carefully at this path:
buf = dev->driver->gem_prime_export(dev, obj, flags);
if (IS_ERR(buf)) {
/* normally the created dma-buf takes ownership of the ref,
* but if that fails then drop the ref
*/
drm_gem_object_unreference_unlocked(obj);
mutex_unlock(&file_priv->prime.lock);
return PTR_ERR(buf);
}
obj->export_dma_buf = buf;
*prime_fd = dma_buf_fd(buf, flags);
}
/* if we've exported this buffer the cheat and add it to the import list
* so we get the correct handle back
*/
ret = drm_prime_add_imported_buf_handle(&file_priv->prime,
obj->export_dma_buf, handle);
if (ret) {
drm_gem_object_unreference_unlocked(obj);
mutex_unlock(&file_priv->prime.lock);
return ret;
}So in the event of drm_prime_add_imported_buf_handle() returning an error, we return that error to our caller (which will eventually be userspace) saying that we failed.
However, we've already setup the export and obtained an fd for it, which we resultingly now leak in that situation.
Now, second problem here - consider what happens if you ask for the same object to be exported a second (or more) times. Note that obj->export_dma_buf will now be set, so we take a different path through this code:
if (obj->export_dma_buf) {
get_dma_buf(obj->export_dma_buf);
*prime_fd = dma_buf_fd(obj->export_dma_buf, flags);
drm_gem_object_unreference_unlocked(obj);
} else {
}
/* if we've exported this buffer the cheat and add it to the import list
* so we get the correct handle back
*/
ret = drm_prime_add_imported_buf_handle(&file_priv->prime,
obj->export_dma_buf, handle);
if (ret) {
drm_gem_object_unreference_unlocked(obj);
mutex_unlock(&file_priv->prime.lock);
return ret;
}Now, if I in a loop in userspace doing this:
do {
drmPrimeHandleToFD(..., &fd);
close(fd);
} while (1);How long do you think it might take to exhaust the kmalloc() inside drm_prime_add_imported_buf_handle() ?
It's not even trivially fixable, because drm_gem_dmabuf_release() doesn't call drm_prime_remove_imported_buf_handle() because it has no knowledge of the drm_prime_file_private structure to search for these things...
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 25 lines · Russell King - ARM Linux
And here's another one - look carefully at this path:
buf = dev->driver->gem_prime_export(dev, obj, flags); if (IS_ERR(buf)) { /* normally the created dma-buf takes ownership of the ref, * but if that fails then drop the ref */ drm_gem_object_unreference_unlocked(obj); mutex_unlock(&file_priv->prime.lock); return PTR_ERR(buf); } obj->export_dma_buf = buf; *prime_fd = dma_buf_fd(buf, flags); } /* if we've exported this buffer the cheat and add it to the import list * so we get the correct handle back */ ret = drm_prime_add_imported_buf_handle(&file_priv->prime, obj->export_dma_buf, handle); if (ret) { drm_gem_object_unreference_unlocked(obj); mutex_unlock(&file_priv->prime.lock); return ret; }
Quoted 6 lines
So in the event of
drm_prime_add_imported_buf_handle()returning an error, we return that error to our caller (which will eventually be userspace) saying that we failed.However, we've already setup the export and obtained an fd for it, which we resultingly now leak in that situation.
well, it is a semi-leak, I believe. The gem object won't leak, but we do leak an fd. We don't end up with an extra reference to the gem bo, so when it is eventually destroyed, the dmabuf/file will be cleaned up. I'm not quite sure off the top of my head what ends up happening if you have an open fd and destroy the flie. That might not be terribly good.
I do think it would be better to immediately clean up and destroy the dmabuf and fd.
Quoted 29 lines
Now, second problem here - consider what happens if you ask for the same object to be exported a second (or more) times. Note that
obj->export_dma_bufwill now be set, so we take a different path through this code:if (obj->export_dma_buf) { get_dma_buf(obj->export_dma_buf); *prime_fd = dma_buf_fd(obj->export_dma_buf, flags); drm_gem_object_unreference_unlocked(obj); } else { } /* if we've exported this buffer the cheat and add it to the import list * so we get the correct handle back */ ret = drm_prime_add_imported_buf_handle(&file_priv->prime, obj->export_dma_buf, handle); if (ret) { drm_gem_object_unreference_unlocked(obj); mutex_unlock(&file_priv->prime.lock); return ret; }Now, if I in a loop in userspace doing this:
do { drmPrimeHandleToFD(..., &fd); close(fd); } while (1);
Quoted 6 lines
How long do you think it might take to exhaust the
kmalloc()insidedrm_prime_add_imported_buf_handle()?It's not even trivially fixable, because
drm_gem_dmabuf_release()doesn't calldrm_prime_remove_imported_buf_handle()because it has no knowledge of thedrm_prime_file_privatestructure to search for these things...
Do you mind having a look at the latest? This has changed recently so we don't re-add to the import list, so I don't believe your userspace loop would cause any issue.
BR,
-R
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
In reply to Russell King - ARM LinuxAnd another issue...
What is drm_crtc_helper_set_mode() passed as the fb argument? Is it the old fb, or the new fb?
bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
struct drm_display_mode *mode, int x, int y,
struct drm_framebuffer *old_fb)
...
int drm_crtc_helper_set_config(struct drm_mode_set *set) {
...
save_set.fb = set->crtc->fb;
...
old_fb = set->crtc->fb;
set->crtc->fb = set->fb;
if (!drm_crtc_helper_set_mode(set->crtc, set->mode,
set->x, set->y,
old_fb)) {
...
/* Try to restore the config */
if (mode_changed &&
!drm_crtc_helper_set_mode(save_set.crtc, save_set.mode, save_set.x,
save_set.y, save_set.fb))
}...
int drm_helper_resume_force_mode(struct drm_device *dev) {
...
ret = drm_crtc_helper_set_mode(crtc, &crtc->mode,
crtc->x, crtc->y, crtc->fb);The function prototype implies it's the old fb, as does the first use. The second and third uses of it clearly show it being the fb which we wish to be displayed.
The deeper I look, the more bugs there seem to be in this DRM stuff, and I'm continuing to look because I'm chasing a framebuffer refcount bug.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 3 lines · Russell King - ARM Linux
The deeper I look, the more bugs there seem to be in this DRM stuff, and I'm continuing to look because I'm chasing a framebuffer refcount bug.
So, this refcount bug - I think I've just found it. This is the flow of references to the new fb on mode set:
drm_mode_setcrtc():
fb = drm_framebuffer_lookup(dev, crtc_req->fb_id);
set.fb = fb;
ret = drm_mode_set_config_internal(&set);
drm_mode_set_config_internal():
fb = set->fb;
ret = crtc->funcs->set_config(set);
drm_crtc_helper_set_config():
old_fb = set->crtc->fb;
set->crtc->fb = set->fb;
if (!drm_crtc_helper_set_mode(set->crtc, set->mode,
set->x, set->y,
old_fb)) {
drm_helper_disable_unused_functions(dev);
drm_helper_disable_unused_functions():
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
crtc->enabled = drm_helper_crtc_in_use(crtc);
if (!crtc->enabled) {
crtc->fb = NULL;
}
}
back to drm_mode_set_config_internal():
if (ret == 0) {
if (fb)
drm_framebuffer_reference(fb);
back to drm_mode_setcrtc():
if (fb)
drm_framebuffer_unreference(fb);Assuming success all the way through, what happens when a CRTC is unused is:
1. We obtain a reference in drm_mode_setcrtc() via the lookup.
2. We set the mode
3. In trying to set the mode, we discover that all connectors for the CRTC are in the disconnected state, and so we disable the CRTC
4. We set crtc->fb to NULL
5. back in drm_mode_set_config_internal(), we take a reference on the framebuffer irrespective of this.
6. back in drm_mode_setcrtc(), we drop the original reference caused by the lookup.
We now have a framebuffer with a reference count incremented by one but no actual reference to it - the CRTC's reference is completely lost by the action of drm_helper_disable_unused_functions().
You could argue that it's something the driver should deal with - fine, but what if it only implements the DPMS method? Should it drop a reference to the framebuffer when DPMS instructs it to turn off? Surely not, because that means when DPMS turns stuff back on you're missing a refcount.
Are drivers required to implement a disable function and cater for the imbalance in the upper layers of code? If so, this is not a clean design.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 60 lines · Russell King - ARM Linux
Quoted 3 lines · Russell King - ARM Linux
The deeper I look, the more bugs there seem to be in this DRM stuff, and I'm continuing to look because I'm chasing a framebuffer refcount bug.
So, this refcount bug - I think I've just found it. This is the flow of references to the new fb on mode set:
drm_mode_setcrtc():fb = drm_framebuffer_lookup(dev, crtc_req->fb_id); set.fb = fb; ret = drm_mode_set_config_internal(&set); drm_mode_set_config_internal(): fb = set->fb; ret = crtc->funcs->set_config(set); drm_crtc_helper_set_config(): old_fb = set->crtc->fb; set->crtc->fb = set->fb; if (!drm_crtc_helper_set_mode(set->crtc, set->mode, set->x, set->y, old_fb)) { drm_helper_disable_unused_functions(dev); drm_helper_disable_unused_functions(): list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { crtc->enabled = drm_helper_crtc_in_use(crtc); if (!crtc->enabled) { crtc->fb = NULL; } } back to drm_mode_set_config_internal(): if (ret == 0) { if (fb) drm_framebuffer_reference(fb); back to drm_mode_setcrtc(): if (fb) drm_framebuffer_unreference(fb);Assuming success all the way through, what happens when a CRTC is unused is:
1. We obtain a reference in
drm_mode_setcrtc()via the lookup.
2. We set the mode
3. In trying to set the mode, we discover that all connectors for the CRTC are in the disconnected state, and so we disable the CRTC
4. We setcrtc->fbto NULL
5. back indrm_mode_set_config_internal(), we take a reference on the framebuffer irrespective of this.
6. back indrm_mode_setcrtc(), we drop the original reference caused by the lookup.We now have a framebuffer with a reference count incremented by one but no actual reference to it - the CRTC's reference is completely lost by the action of
drm_helper_disable_unused_functions().You could argue that it's something the driver should deal with - fine, but what if it only implements the DPMS method? Should it drop a reference to the framebuffer when DPMS instructs it to turn off? Surely not, because that means when DPMS turns stuff back on you're missing a refcount.
Quoted 3 lines
Are drivers required to implement a disable function and cater for the imbalance in the upper layers of code? If so, this is not a clean design.
There's a bigger issue here - if it's possible for drm_crtc_helper_set_config() to be called with set->fb set but set->mode NULL, then we overwrite set->fb to NULL. Again, that results in a lost reference.
For the time being, I'm using this patch, which solves my dropped refcount problem, and marks the other possible dropped reference. Either that check needs to be removed or it needs to properly drop the refcount on the fb before 'losing' the reference to it.
drivers/gpu/drm/drm_crtc.c +4 -1
@@ -2014,13 +2014,16 @@ int drm_mode_set_config_internal(struct drm_mode_set *set) old_fb = crtc->fb; fb = set->fb; +if (fb) +drm_framebuffer_reference (fb); ret = crtc->funcs->set_config (set);if (ret ==0 ) {if (old_fb)drm_framebuffer_unreference (old_fb); + }else {if (fb) -drm_framebuffer_reference (fb); +drm_framebuffer_unreference (fb); }return ret;
drivers/gpu/drm/drm_crtc_helper.c +3 -0
@@ -299,6 +299,8 @@ void drm_helper_disable_unused_functions(struct drm_device *dev) (*crtc_funcs->disable)(crtc); else (*crtc_funcs->dpms)(crtc,DRM_MODE_DPMS_OFF ); +if (crtc->fb) +drm_framebuffer_unreference (crtc->fb); crtc->fb =NULL ; } }
@@ -573,6 +575,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set) crtc_funcs = set->crtc->helper_private; +/* FIXME: this loses a refcount on the fb */ if (!set->mode) set->fb =NULL ;
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 65 lines · Russell King - ARM Linux
Quoted 60 lines · Russell King - ARM Linux
Quoted 3 lines · Russell King - ARM Linux
The deeper I look, the more bugs there seem to be in this DRM stuff, and I'm continuing to look because I'm chasing a framebuffer refcount bug.
So, this refcount bug - I think I've just found it. This is the flow of references to the new fb on mode set:
drm_mode_setcrtc():fb = drm_framebuffer_lookup(dev, crtc_req->fb_id); set.fb = fb; ret = drm_mode_set_config_internal(&set); drm_mode_set_config_internal(): fb = set->fb; ret = crtc->funcs->set_config(set); drm_crtc_helper_set_config(): old_fb = set->crtc->fb; set->crtc->fb = set->fb; if (!drm_crtc_helper_set_mode(set->crtc, set->mode, set->x, set->y, old_fb)) { drm_helper_disable_unused_functions(dev); drm_helper_disable_unused_functions(): list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { crtc->enabled = drm_helper_crtc_in_use(crtc); if (!crtc->enabled) { crtc->fb = NULL; } } back to drm_mode_set_config_internal(): if (ret == 0) { if (fb) drm_framebuffer_reference(fb); back to drm_mode_setcrtc(): if (fb) drm_framebuffer_unreference(fb);Assuming success all the way through, what happens when a CRTC is unused is:
1. We obtain a reference in
drm_mode_setcrtc()via the lookup.
2. We set the mode
3. In trying to set the mode, we discover that all connectors for the CRTC are in the disconnected state, and so we disable the CRTC
4. We setcrtc->fbto NULL
5. back indrm_mode_set_config_internal(), we take a reference on the framebuffer irrespective of this.
6. back indrm_mode_setcrtc(), we drop the original reference caused by the lookup.We now have a framebuffer with a reference count incremented by one but no actual reference to it - the CRTC's reference is completely lost by the action of
drm_helper_disable_unused_functions().You could argue that it's something the driver should deal with - fine, but what if it only implements the DPMS method? Should it drop a reference to the framebuffer when DPMS instructs it to turn off? Surely not, because that means when DPMS turns stuff back on you're missing a refcount.
Quoted 3 lines
Are drivers required to implement a disable function and cater for the imbalance in the upper layers of code? If so, this is not a clean design.
Quoted 8 lines
There's a bigger issue here - if it's possible for
drm_crtc_helper_set_config()to be called withset->fbset butset->modeNULL, then we overwriteset->fbto NULL. Again, that results in a lost reference.For the time being, I'm using this patch, which solves my dropped refcount problem, and marks the other possible dropped reference. Either that check needs to be removed or it needs to properly drop the refcount on the fb before 'losing' the reference to it.
Scrap my other mail, I see now where the leaking happens. One of them is interface abuse which is now fixed (and i915 has a bunch of BUG_ONs to enforce them). The other one is indeed a real case that eluded me when I've done the refcountification for drm_framebuffers. I'll hack up some patches, since this seems to be a good excuse to port some of the i915 modeset improvements back to the crtc helpers. -Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 11 lines · Daniel Vetter
Quoted 8 lines · Russell King - ARM Linux
There's a bigger issue here - if it's possible for
drm_crtc_helper_set_config()to be called withset->fbset butset->modeNULL, then we overwriteset->fbto NULL. Again, that results in a lost reference.For the time being, I'm using this patch, which solves my dropped refcount problem, and marks the other possible dropped reference. Either that check needs to be removed or it needs to properly drop the refcount on the fb before 'losing' the reference to it.
Quoted 6 lines
Scrap my other mail, I see now where the leaking happens. One of them is interface abuse which is now fixed (and i915 has a bunch of
BUG_ONsto enforce them). The other one is indeed a real case that eluded me when I've done the refcountification fordrm_framebuffers. I'll hack up some patches, since this seems to be a good excuse to port some of the i915 modeset improvements back to the crtc helpers.
If you're happy with the patch I supplied, that's probably the minimal fix which should go to stable kernels (I'm using 3.9 here) - this also counts as a "user visible bug". It's something I've tripped over which causes exhausts memory and can prevent the X server from starting up.
If you want me to package the patch up with a commit message and sign-off...
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 19 lines · Russell King - ARM Linux
Quoted 11 lines · Daniel Vetter
Quoted 8 lines · Russell King - ARM Linux
There's a bigger issue here - if it's possible for
drm_crtc_helper_set_config()to be called withset->fbset butset->modeNULL, then we overwriteset->fbto NULL. Again, that results in a lost reference.For the time being, I'm using this patch, which solves my dropped refcount problem, and marks the other possible dropped reference. Either that check needs to be removed or it needs to properly drop the refcount on the fb before 'losing' the reference to it.
Quoted 6 lines
Scrap my other mail, I see now where the leaking happens. One of them is interface abuse which is now fixed (and i915 has a bunch of
BUG_ONsto enforce them). The other one is indeed a real case that eluded me when I've done the refcountification fordrm_framebuffers. I'll hack up some patches, since this seems to be a good excuse to port some of the i915 modeset improvements back to the crtc helpers.
Quoted 6 lines
If you're happy with the patch I supplied, that's probably the minimal fix which should go to stable kernels (I'm using 3.9 here) - this also counts as a "user visible bug". It's something I've tripped over which causes exhausts memory and can prevent the X server from starting up.
If you want me to package the patch up with a commit message and sign-off..
Your patch doesn't fix drm/i915 (since we don't use the crtc helpers any more). And I don't think it's good to have the refcounting partially in the drm core and partially in drivers. I've also thrown a few more things on top just to port a few of the i915 cleanups to the crtc helper. I'll submit my patches asap (need to test them a bit more first).
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 7 lines · Daniel Vetter
Quoted 5 lines · Russell King - ARM Linux
If you're happy with the patch I supplied, that's probably the minimal fix which should go to stable kernels (I'm using 3.9 here) - this also counts as a "user visible bug". It's something I've tripped over which causes exhausts memory and can prevent the X server from starting up.
Quoted 5 lines
Quoted 1 line
If you want me to package the patch up with a commit message and sign-off..
Your patch doesn't fix drm/i915 (since we don't use the crtc helpers any more). And I don't think it's good to have the refcounting partially in the drm core and partially in drivers.
Let me check what you mean by that. I hope you mean that the drm core, drm helpers and drivers are individually responsible for dropping any refcount that they obtain on any object.
In other words, if the drm core takes a refcount on object X, then the DRM core must be the code base which drops that refcount.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 14 lines · Russell King - ARM Linux
Quoted 7 lines · Daniel Vetter
Quoted 5 lines · Russell King - ARM Linux
If you're happy with the patch I supplied, that's probably the minimal fix which should go to stable kernels (I'm using 3.9 here) - this also counts as a "user visible bug". It's something I've tripped over which causes exhausts memory and can prevent the X server from starting up.
Quoted 5 lines
Quoted 1 line
If you want me to package the patch up with a commit message and sign-off..
Your patch doesn't fix drm/i915 (since we don't use the crtc helpers any more). And I don't think it's good to have the refcounting partially in the drm core and partially in drivers.
Quoted 6 lines
Let me check what you mean by that. I hope you mean that the drm core, drm helpers and drivers are individually responsible for dropping any refcount that they obtain on any object.
In other words, if the drm core takes a refcount on object X, then the DRM core must be the code base which drops that refcount.
Yeah, that's the idea. But since with the currently quirky drm core ->set_config callback the drivers need to drop the reference if any other crtc loses all its connectors. My patch also drops the ref for that fb in the drm core functions. The reason for that is that we want to switch to a global ->set_config function anyway (usually called atomic modeset) to push the configuration for all the crtcs into the hw in one step (or fail it completely ofc). The current approach leads to too much flickering and some funny hacks in drivers ...
Of course such gradual transitions over mutliple kernel release (we're shuffling backend code in drm/i915 since about 3.7 for this) leaves a few ugly intermediat states. But I prefer to move into the overall right direction with a bit of ugliness than doing such big transitions in one big swoop.
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
In reply to Russell King - ARM LinuxQuoted 60 lines · Russell King - ARM Linux
Quoted 3 lines · Russell King - ARM Linux
The deeper I look, the more bugs there seem to be in this DRM stuff, and I'm continuing to look because I'm chasing a framebuffer refcount bug.
So, this refcount bug - I think I've just found it. This is the flow of references to the new fb on mode set:
drm_mode_setcrtc():fb = drm_framebuffer_lookup(dev, crtc_req->fb_id); set.fb = fb; ret = drm_mode_set_config_internal(&set); drm_mode_set_config_internal(): fb = set->fb; ret = crtc->funcs->set_config(set); drm_crtc_helper_set_config(): old_fb = set->crtc->fb; set->crtc->fb = set->fb; if (!drm_crtc_helper_set_mode(set->crtc, set->mode, set->x, set->y, old_fb)) { drm_helper_disable_unused_functions(dev); drm_helper_disable_unused_functions(): list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { crtc->enabled = drm_helper_crtc_in_use(crtc); if (!crtc->enabled) { crtc->fb = NULL; } } back to drm_mode_set_config_internal(): if (ret == 0) { if (fb) drm_framebuffer_reference(fb); back to drm_mode_setcrtc(): if (fb) drm_framebuffer_unreference(fb);Assuming success all the way through, what happens when a CRTC is unused is:
1. We obtain a reference in
drm_mode_setcrtc()via the lookup.
2. We set the mode
3. In trying to set the mode, we discover that all connectors for the CRTC are in the disconnected state, and so we disable the CRTC
4. We setcrtc->fbto NULL
5. back indrm_mode_set_config_internal(), we take a reference on the framebuffer irrespective of this.
6. back indrm_mode_setcrtc(), we drop the original reference caused by the lookup.We now have a framebuffer with a reference count incremented by one but no actual reference to it - the CRTC's reference is completely lost by the action of
drm_helper_disable_unused_functions().You could argue that it's something the driver should deal with - fine, but what if it only implements the DPMS method? Should it drop a reference to the framebuffer when DPMS instructs it to turn off? Surely not, because that means when DPMS turns stuff back on you're missing a refcount.
Quoted 3 lines
Are drivers required to implement a disable function and cater for the imbalance in the upper layers of code? If so, this is not a clean design.
Yep, if your driver grabs additional references (underlying gem object, pinning, whatever) you need to wire up your own ->disable hook to drop those. Note that for truly dumb kms drivers which only ever allocate an fb, the upper layer actually _does_ take care of all the refcounting.
Also note the crtc helpers in drm_crtc_helper.c are purely optional. The real drm core -> driver interface is all contained in drm_crtc.c. And crtc helpers do make a few critical design assumptions about how your hw works (and there's a bit room for api cleanup, I agree on that). So if they simply don't work out for you no one will get upset if you roll your own modeset infrastructure. And in drm/i915 we've had to do just that since the impedance mismatch between crtc helper assumptions and what our hw needed grew to big (and in really fundamental ways, not just a bit of interface ugliness like you're seeing here).
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 61 lines · Daniel Vetter
Quoted 60 lines · Russell King - ARM Linux
Quoted 3 lines · Russell King - ARM Linux
The deeper I look, the more bugs there seem to be in this DRM stuff, and I'm continuing to look because I'm chasing a framebuffer refcount bug.
So, this refcount bug - I think I've just found it. This is the flow of references to the new fb on mode set:
drm_mode_setcrtc():fb = drm_framebuffer_lookup(dev, crtc_req->fb_id); set.fb = fb; ret = drm_mode_set_config_internal(&set); drm_mode_set_config_internal(): fb = set->fb; ret = crtc->funcs->set_config(set); drm_crtc_helper_set_config(): old_fb = set->crtc->fb; set->crtc->fb = set->fb; if (!drm_crtc_helper_set_mode(set->crtc, set->mode, set->x, set->y, old_fb)) { drm_helper_disable_unused_functions(dev); drm_helper_disable_unused_functions(): list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { crtc->enabled = drm_helper_crtc_in_use(crtc); if (!crtc->enabled) { crtc->fb = NULL; } } back to drm_mode_set_config_internal(): if (ret == 0) { if (fb) drm_framebuffer_reference(fb); back to drm_mode_setcrtc(): if (fb) drm_framebuffer_unreference(fb);Assuming success all the way through, what happens when a CRTC is unused is:
1. We obtain a reference in
drm_mode_setcrtc()via the lookup.
2. We set the mode
3. In trying to set the mode, we discover that all connectors for the CRTC are in the disconnected state, and so we disable the CRTC
4. We setcrtc->fbto NULL
5. back indrm_mode_set_config_internal(), we take a reference on the framebuffer irrespective of this.
6. back indrm_mode_setcrtc(), we drop the original reference caused by the lookup.We now have a framebuffer with a reference count incremented by one but no actual reference to it - the CRTC's reference is completely lost by the action of
drm_helper_disable_unused_functions().You could argue that it's something the driver should deal with - fine, but what if it only implements the DPMS method? Should it drop a reference to the framebuffer when DPMS instructs it to turn off? Surely not, because that means when DPMS turns stuff back on you're missing a refcount.
Quoted 8 lines
Quoted 3 lines
Are drivers required to implement a disable function and cater for the imbalance in the upper layers of code? If so, this is not a clean design.
Yep, if your driver grabs additional references (underlying gem object, pinning, whatever) you need to wire up your own ->disable hook to drop those. Note that for truly dumb kms drivers which only ever allocate an fb, the upper layer actually _does_ take care of all the refcounting.
Look again at what I said above - that is _not_ the case. My above analysis is totally without considering any refcounting that the driver itself may or may not do. If the driver does no refcounting on the framebuffer object, then the leak is present.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
In reply to Russell King - ARM LinuxQuoted 30 lines · Russell King - ARM Linux
And another issue...
What is
drm_crtc_helper_set_mode()passed as the fb argument? Is it the old fb, or the new fb?bool drm_crtc_helper_set_mode(struct
drm_crtc*crtc,
structdrm_display_mode*mode, int x, int y,
structdrm_framebuffer*old_fb)
...
intdrm_crtc_helper_set_config(struct drm_mode_set *set){
...save_set.fb = set->crtc->fb; ... old_fb = set->crtc->fb; set->crtc->fb = set->fb; if (!drm_crtc_helper_set_mode(set->crtc, set->mode, set->x, set->y, old_fb)) { ... /* Try to restore the config */ if (mode_changed && !drm_crtc_helper_set_mode(save_set.crtc, save_set.mode, save_set.x, save_set.y, save_set.fb)) }...
intdrm_helper_resume_force_mode(struct drm_device *dev){
...
Quoted 6 lines
ret = drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->fb);The function prototype implies it's the old fb, as does the first use. The second and third uses of it clearly show it being the fb which we wish to be displayed.
most of the embedded drivers should ignore the old_fb.. the API is a bit odd but the purpose is to help drivers that need to pin/unpin the gem objects backing the fb. The ones that do, do something like:
foo_pin(new_fb); foo_unpin(old_fb);
if the two are the same, it works out.
Note that even for the non error paths, new_fb and old_fb could be the same.
Possibly something worth clarifying in the docs.
BR,
-R
Quoted 3 lines
The deeper I look, the more bugs there seem to be in this DRM stuff, and I'm continuing to look because I'm chasing a framebuffer refcount bug.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 4 lines · Rob Clark
most of the embedded drivers should ignore the
old_fb.. the API is a bit odd but the purpose is to help drivers that need to pin/unpin the gem objects backing the fb. The ones that do, do something like:
Quoted 8 lines
foo_pin(new_fb); foo_unpin(old_fb);if the two are the same, it works out.
Note that even for the non error paths,
new_fbandold_fbcould be the same.Possibly something worth clarifying in the docs.
One implication this has is that the crtc helper assumes that the driver modeset callbacks only fail before the driver internally has done the pin/unpin dance. If the new fb is already the one which should be unpinned and the modeset fails after that point, then we'll leak stuff.
So drivers need to ensure that they undo any pin/unpins (and other fb refcounted resource handling) if they're ->modeset callback fails.
In the new shiny drm/i915 modeset helper code we've flipped around those semantics, but imo for the crtc helper it does fit into the larger assumptions of the crtc helper code:
- crtc helper code assumes that all ->disable callbacks are stateless
- hence it can put the _new_ requested state into the sw tracking structures before the modeset starts so that ->mode_fixup callbacks could e.g. check the pixel format of the new fb.
Flipping that around would remove one of the cornerstones of the crtc helpers, so imo doesn't make much sense. But as i915.ko demonstrates with a bit of effort it's no problem to have a completely different modeset sequence driver infrastructure.
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
In reply to Russell King - ARM LinuxQuoted 49 lines · Russell King - ARM Linux
Quoted 48 lines · Russell King - ARM Linux
Quoted 11 lines · Rob Clark
Quoted 8 lines · Russell King - ARM Linux
And having thought about this driver, DRM some more, I'm now of the opinion that DRM is not suitable for driving hardware where the GPU is an entirely separate IP block from the display side.
DRM is modelled after the PC setup where your "graphics card" does everything - it has the GPU, display and connectors all integrated together. This is not the case on embedded SoCs, which can be a collection of different IPs all integrated together.
Quoted 5 lines
actually it isn't even the case on desktop/laptop anymore, where you can have one gpu with scanout and a second one without (or just with display controller not hooked up to anything, etc, etc)
That is the point of dmabuf and the upcoming fence/reservation stuff.
Okay, but dmabuf really needs to be fixed, because as it stands this API is really quite broken wrt the DMA API.
dma_map_sg()is (a) not supposed to have its return value ignored - mappings can fail, and (b) the returned number indicates how many entries are valid for the _mapped_ version of the scatterlist.Both these points are important if your DMA API implementation uses an IOMMU, which may coalesce the scatterlist array when creating mappings - much as described in
Documentation/DMA-API.txtandDocumentation/DMA-API-HOWTO.txt.That is not all DRMs fault - (a) is attributable to DRM's prime implementation:
sgt = obj->dev->driver->gem_prime_get_sg_table(obj); if (!IS_ERR_OR_NULL(sgt)) dma_map_sg(attach->dev, sgt->sgl, sgt->nents, dir);and quite why it does the
dma_map_sg()beneath thestruct_mutexis beyond me - if the array of pages isn't safe without the mutex being held, then it isn't safe after thedma_map_sg()operation has completed and the mutex has been released.However, (b) is more a problem for dmabuf (which I just rather aptly mistyped as dmabug) because either dmabuf's .map_dma_buf method needs to return the value from
dma_map_sg(), or it needs to stop requiring this of the .map_dma_buf method and have it done by the caller of this method so the caller can have access to that returned value.
Quoted 4 lines
Quoted 4 lines
Added Sumit Semwal to this email for the dmabuf issue.
Thankfully, this being correct isn't a requirement for me, but it's something which _should_ be fixed.
(just some quick answers.. I'll read rest of thread a bit later when I have some time)
Quoted 2 lines
Okay, so Sumit Semwal has been a victim of TI's cuts, so don't expect
dma_bufto get sorted by the original author...
Sumit is at linaro, and should still be caring for dma_buf (although w/ different email addr)
Quoted 8 lines
Now we come to this:
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c: return dma_buf_export(exynos_gem_obj,&exynos_dmabuf_ops,drivers/gpu/drm/exynos/exynos_drm_dmabuf.c-exynos_gem_obj->base.size, flags);drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c: returndma_buf_export(obj, &omap_dmabuf_ops, obj->size, flags);drivers/gpu/drm/drm_prime.c: return dma_buf_export(obj,&drm_gem_prime_dmabuf_ops,obj->size,drivers/gpu/drm/drm_prime.c-0600);drivers/gpu/drm/i915/i915_gem_dmabuf.c: returndma_buf_export(obj, &i915_dmabuf_ops, obj->base.size, flags);
the drm_prime.c version was a more recent addition of "dmabuf helpers".. not all the drivers use 'em (which seems to be a good thing)
Quoted 4 lines
Of the three implementations which don't use the generic version, they all pass 'flags' to
dma_buf_export.drm_prime.cdoesn't, it passes a fixed file mode. What's the correct version, or is flags | 0600 actually the right one (as flags only containsO_CLOEXEC)?
the drm_prime version is wrong.. the O_CLOEXEC flag should have been passed along from what userspace requested when exporting the dmabuf
BR,
-R
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
In reply to Rob ClarkQuoted 27 lines · Rob Clark
Quoted 17 lines · Russell King - ARM Linux
Quoted 9 lines · Rob Clark
I guess in the short term, the best I can think is keep those phys ioctls as a small patch on top of the upstream driver. It is ok to leave place-holder ioctl #'s in the upstream driver so that the ioctl #'s don't shift when you rebase. And then try to get the vendor to add support for dmabuf so that the patch on top of upstream can eventually be dropped. Maybe someone else has a better suggestion, but I don't think we can merge those phys ioctls upstream, and I'd really hate to 'throw the baby out with the bathwater' in this case and not at least get the modesetting part of the driver merged.
What you're saying is basically:
1. Throw out
DRM_ARMADA_GEM_CREATE_PHYS, which cripples video playback on existing gstreamer, xbmc and other implementations without someone rewriting all that code.Quoted 7 lines
2. Throw out
DRM_ARMADA_GEM_PROP, which prevents any form of passing the GEM objects to the GPU libraries in userspace, thereby preventing any kind of GPU based acceleration.That makes the driver just be a dumb scanout only driver. Sorry, that *really* does not interest me one bit, because the CPU doing framebuffer accesses is pig slow.
Quoted 6 lines
Well, yes that is basically what I am saying, unless we can find a different way (dmabuf? if there is some way to pass it through the blob bits you don't have src code for?)
The problem is that we really can't merge something upstream that lets you dma to arbitrary physical address. Maybe in staging, perhaps? Or
Which bit of "THIS DRIVER DOESN'T DMA _TO_ ANY ADDRESS" did you not yet?
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 28 lines · Russell King - ARM Linux
Quoted 27 lines · Rob Clark
Quoted 24 lines · Russell King - ARM Linux
Quoted 9 lines · Rob Clark
I guess in the short term, the best I can think is keep those phys ioctls as a small patch on top of the upstream driver. It is ok to leave place-holder ioctl #'s in the upstream driver so that the ioctl #'s don't shift when you rebase. And then try to get the vendor to add support for dmabuf so that the patch on top of upstream can eventually be dropped. Maybe someone else has a better suggestion, but I don't think we can merge those phys ioctls upstream, and I'd really hate to 'throw the baby out with the bathwater' in this case and not at least get the modesetting part of the driver merged.
What you're saying is basically:
1. Throw out
DRM_ARMADA_GEM_CREATE_PHYS, which cripples video playback on existing gstreamer, xbmc and other implementations without someone rewriting all that code.2. Throw out
DRM_ARMADA_GEM_PROP, which prevents any form of passing the GEM objects to the GPU libraries in userspace, thereby preventing any kind of GPU based acceleration.That makes the driver just be a dumb scanout only driver. Sorry, that *really* does not interest me one bit, because the CPU doing framebuffer accesses is pig slow.
Quoted 8 lines
Quoted 6 lines
Well, yes that is basically what I am saying, unless we can find a different way (dmabuf? if there is some way to pass it through the blob bits you don't have src code for?)
The problem is that we really can't merge something upstream that lets you dma to arbitrary physical address. Maybe in staging, perhaps? Or
Which bit of "THIS DRIVER DOESN'T DMA _TO_ ANY ADDRESS" did you not yet?
ok, I see the 'put_image' ioctl is a non-destructive overlay (ie. not a blit to memory). In which case it is limited to letting you just scan out arbitrary memory. Which is still not awesome, but not nearly as bad.
And fwiw, CMA is not a blocker point for me. Although it seems like a good idea into trying to talk someone into making CMA do something sane on older arm's so that at some point armada driver can use it.
You probably can't use the drm cma helpers (since that wouldn't let you do cached buffers), so the change to use dma_alloc_* from your driver at a later date would be pretty small. Fwiw, omapdrm and I think also exynos both use CMA for some buffers (for example, omap3 or anything without dmm/tiler would use cma for scanout buffers).
BR,
-R
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
In reply to Rob ClarkQuoted 13 lines · Rob Clark
Quoted 11 lines · Russell King - ARM Linux
Quoted 10 lines · Rob Clark
Quoted 7 lines · Russell King
This patch adds support for the pair of LCD controllers on the Marvell Armada 510 SoCs. This driver supports:
- multiple contiguous scanout buffers for video and graphics
- shm backed cacheable buffer objects for X pixmaps for Vivante GPU acceleration
- dual lcd0 and lcd1 crt operation
- video overlay on each LCD crt
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Any particular reason for not exposing the overlays as drm_plane's? That is probably something that should change before merging the driver.
Only through not understanding much of DRM when I started this. Provided DRM planes can do everything that I'm already doing with the overlay support, then yes. Otherwise, I want to stick with this which is modelled after the i915 overlay interface.
Oh i915 overlays aren't a good reason ;-) I've done those way back when drm didn't have any plane infrastructure and pretty much as my very contribution. So totally lacked any clue.
If I can scrap together a bit of time I want to port the legacy overlay code over to drm planes (and remap the current ioctl interface to the drm plane interface for backwards compat). But atm that's crushed under a giant pile of other todo items.
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 23 lines · Daniel Vetter
Quoted 13 lines · Rob Clark
Quoted 11 lines · Russell King - ARM Linux
Quoted 10 lines · Rob Clark
Quoted 7 lines · Russell King
This patch adds support for the pair of LCD controllers on the Marvell Armada 510 SoCs. This driver supports:
- multiple contiguous scanout buffers for video and graphics
- shm backed cacheable buffer objects for X pixmaps for Vivante GPU acceleration
- dual lcd0 and lcd1 crt operation
- video overlay on each LCD crtQuoted 8 lines
Quoted 8 lines
Quoted 3 lines
Any particular reason for not exposing the overlays as drm_plane's? That is probably something that should change before merging the driver.
Only through not understanding much of DRM when I started this. Provided DRM planes can do everything that I'm already doing with the overlay support, then yes. Otherwise, I want to stick with this which is modelled after the i915 overlay interface.
Quoted 8 lines
Oh i915 overlays aren't a good reason ;-) I've done those way back when drm didn't have any plane infrastructure and pretty much as my very contribution. So totally lacked any clue.
If I can scrap together a bit of time I want to port the legacy overlay code over to drm planes (and remap the current ioctl interface to the drm plane interface for backwards compat). But atm that's crushed under a giant pile of other todo items.
Aren't we all :( The amount of time I have to touch this has reduced substantially over the last couple of months, which is why there's been a few weeks between the RFC's for this.
The issue here is that with the overlay interface, all I have to do with one of these pass-by-phys-address things which the X server gets is to:
1. associate the phys address with a gem object
2. pass it in via the overlay interface
With the DRM plane stuff, this gets more complicated:
1. associate the phys address with a gem object
2. call another driver private ioctl to bind the gem object to a framebuffer (there is no support for this in the generic ioctl API afaics) which has to allocate and setup a framebuffer
3. use setplane to update the plane
That all increases the expense of overlay, and adds further memory allocations to the path (and frees when the previous framebuffer is discarded.)
That all makes for higher load due to more CPU expense.
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
Quoted 52 lines · Russell King - ARM Linux
Quoted 23 lines · Daniel Vetter
Quoted 13 lines · Rob Clark
Quoted 11 lines · Russell King - ARM Linux
Quoted 10 lines · Rob Clark
Quoted 7 lines · Russell King
This patch adds support for the pair of LCD controllers on the Marvell Armada 510 SoCs. This driver supports:
- multiple contiguous scanout buffers for video and graphics
- shm backed cacheable buffer objects for X pixmaps for Vivante GPU acceleration
- dual lcd0 and lcd1 crt operation
- video overlay on each LCD crtQuoted 8 lines
Quoted 8 lines
Quoted 3 lines
Any particular reason for not exposing the overlays as drm_plane's? That is probably something that should change before merging the driver.
Only through not understanding much of DRM when I started this. Provided DRM planes can do everything that I'm already doing with the overlay support, then yes. Otherwise, I want to stick with this which is modelled after the i915 overlay interface.
Quoted 8 lines
Oh i915 overlays aren't a good reason ;-) I've done those way back when drm didn't have any plane infrastructure and pretty much as my very contribution. So totally lacked any clue.
If I can scrap together a bit of time I want to port the legacy overlay code over to drm planes (and remap the current ioctl interface to the drm plane interface for backwards compat). But atm that's crushed under a giant pile of other todo items.
Aren't we all :( The amount of time I have to touch this has reduced substantially over the last couple of months, which is why there's been a few weeks between the RFC's for this.
The issue here is that with the overlay interface, all I have to do with one of these pass-by-phys-address things which the X server gets is to:
1. associate the phys address with a gem object
2. pass it in via the overlay interfaceWith the DRM plane stuff, this gets more complicated:
1. associate the phys address with a gem object
2. call another driver private ioctl to bind the gem object to a framebuffer (there is no support for this in the generic ioctl API afaics) which has to allocate and setup a framebuffer
3. use setplane to update the plane
Quoted 5 lines
That all increases the expense of overlay, and adds further memory allocations to the path (and frees when the previous framebuffer is discarded.)
That all makes for higher load due to more CPU expense.
Nothing prevents you from having a driver private ioctl on top of drm plane to combine this all into one ioctl in addition to supporting the standard plane interface
BR,
-R
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
In reply to Russell King - ARM LinuxQuoted 44 lines · Russell King - ARM Linux
Quoted 23 lines · Daniel Vetter
Quoted 13 lines · Rob Clark
Quoted 11 lines · Russell King - ARM Linux
Quoted 10 lines · Rob Clark
Quoted 7 lines · Russell King
This patch adds support for the pair of LCD controllers on the Marvell Armada 510 SoCs. This driver supports:
- multiple contiguous scanout buffers for video and graphics
- shm backed cacheable buffer objects for X pixmaps for Vivante GPU acceleration
- dual lcd0 and lcd1 crt operation
- video overlay on each LCD crtQuoted 8 lines
Quoted 8 lines
Quoted 3 lines
Any particular reason for not exposing the overlays as drm_plane's? That is probably something that should change before merging the driver.
Only through not understanding much of DRM when I started this. Provided DRM planes can do everything that I'm already doing with the overlay support, then yes. Otherwise, I want to stick with this which is modelled after the i915 overlay interface.
Quoted 8 lines
Oh i915 overlays aren't a good reason ;-) I've done those way back when drm didn't have any plane infrastructure and pretty much as my very contribution. So totally lacked any clue.
If I can scrap together a bit of time I want to port the legacy overlay code over to drm planes (and remap the current ioctl interface to the drm plane interface for backwards compat). But atm that's crushed under a giant pile of other todo items.
Aren't we all :( The amount of time I have to touch this has reduced substantially over the last couple of months, which is why there's been a few weeks between the RFC's for this.
The issue here is that with the overlay interface, all I have to do with one of these pass-by-phys-address things which the X server gets is to:
1. associate the phys address with a gem object
2. pass it in via the overlay interface
Quoted 6 lines
With the DRM plane stuff, this gets more complicated:
1. associate the phys address with a gem object
2. call another driver private ioctl to bind the gem object to a framebuffer (there is no support for this in the generic ioctl API afaics) which has to allocate and setup a framebuffer
drm_mode_addfb2 is the ioctl which packs up a bunch of driver objects (lookup is done in the driver callback, so could in theory be something else than gem) and wraps them up into a fb with a pile of metadata (per-plane stride&offset, fourcc code, ...). drm_mode_addfb is the legacy ioctl for simple packed rgb formats. The drm core has helpers to map between the two kinds of metadata (as far as possible).
Quoted 7 lines
3. use setplane to update the plane
That all increases the expense of overlay, and adds further memory allocations to the path (and frees when the previous framebuffer is discarded.)
That all makes for higher load due to more CPU expense.
CPU load won't kill you for these, the problem was more that up to 3.8 the locking was a bit b0rked and background probing (e.g. the output poll work reading an edid) could block framebuffer creation and pageflips. That should be all fixed no in 3.9 (with the execption of set_planes, for those I'd like to use the ww mutexes ... but could also be fixed now with a few hacks).
The addfb overhead should also be easy to amortize (if it really hurts you) as long as you keep a queue of buffers around (like X/wayland do). Then it's even better for planar since you avoid to do per-plane lookup ;-)
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
In reply to Daniel VetterQuoted 23 lines · Daniel Vetter
Quoted 13 lines · Rob Clark
Quoted 11 lines · Russell King - ARM Linux
Quoted 10 lines · Rob Clark
Quoted 7 lines · Russell King
This patch adds support for the pair of LCD controllers on the Marvell Armada 510 SoCs. This driver supports:
- multiple contiguous scanout buffers for video and graphics
- shm backed cacheable buffer objects for X pixmaps for Vivante GPU acceleration
- dual lcd0 and lcd1 crt operation
- video overlay on each LCD crtQuoted 8 lines
Quoted 8 lines
Quoted 3 lines
Any particular reason for not exposing the overlays as drm_plane's? That is probably something that should change before merging the driver.
Only through not understanding much of DRM when I started this. Provided DRM planes can do everything that I'm already doing with the overlay support, then yes. Otherwise, I want to stick with this which is modelled after the i915 overlay interface.
Quoted 8 lines
Oh i915 overlays aren't a good reason ;-) I've done those way back when drm didn't have any plane infrastructure and pretty much as my very contribution. So totally lacked any clue.
If I can scrap together a bit of time I want to port the legacy overlay code over to drm planes (and remap the current ioctl interface to the drm plane interface for backwards compat). But atm that's crushed under a giant pile of other todo items.
I hope you remember the mdfld overlay code I posted a long time ago:
http://lists.freedesktop.org/archives/intel-gfx/2012-September/020479.html
I don't think it's too far from being operational on gen.
Signature · 2 lines
Ville Syrjälä Intel OTC
Re: [PATCH RFC 2/8] DRM: Armada: Add Armada DRM driver
In reply to Rob ClarkQuoted 14 lines · Rob Clark
Quoted 12 lines · Russell King
drivers/gpu/drm/armada/armada_crtc.c new file +12
-0+/* The mode_config.mutex will be held for this call */ +static int armada_drm_crtc_mode_set_base (struct drm_crtc *crtc,int x,int y, +struct drm_framebuffer *old_fb) +{ +struct armada_crtc *dcrtc =drm_to_armada_crtc (crtc); +struct armada_regs regs[4 ]; +unsigned i; + + i =armada_drm_crtc_calc_fb (crtc->fb, crtc->x, crtc->y, regs, dcrtc->interlaced); +armada_reg_queue_end (regs, i); + +/* Wait for pending flips to complete */
Quoted 8 lines
drivers/gpu/drm/armada/armada_crtc.c line 582
Quoted 4 lines
drivers/gpu/drm/armada/armada_crtc.c new file +4
-0+wait_event (dcrtc->frame_wait, !dcrtc->frame_work); + +/* Take a reference to the new fb as we're using it */ +drm_gem_object_reference (&drm_fb_obj (crtc->fb)->obj);note that you probably want to ref/unref the fb (and let the fb hold a ref to the gem bo).. that will make life easier for planar formats too (as the fb should hold ref's to the bo for each plane)
Now changed - and it looks from my debug of gem_linear that it's working correctly (iow, not leaking).
Quoted 8 lines
drivers/gpu/drm/armada/armada_ioctl.h line 26
Quoted 4 lines
drivers/gpu/drm/armada/armada_ioctl.h new file +4
-0+struct drm_armada_gem_create { +uint32_t height; +uint32_t width; +uint32_t bpp;just fwiw, typically height/width/bpp are properties of the fb but not the bo.. (except in some cases where kernel needs to know this to setup GTT correctly for tiled buffers)
Also fixed.
Quoted 7 lines
drivers/gpu/drm/armada/armada_ioctl.h line 55
Quoted 4 lines
drivers/gpu/drm/armada/armada_ioctl.h new file +4
-0+struct drm_armada_gem_pwrite { +uint32_t handle; +uint32_t offset; +uint32_t size;probably want a
uint32_tpadding here, or move theuint64_tup in the struct to avoid 32 vs 64b alignment differences.
And also fixed.
RFC PATCH 3/8 drm/i2c: nxp-tda998x: fix EDID reading on TDA19988 devices
In reply to Russell King - ARM LinuxTDA19988 devices need their RAM enabled in order to read EDID information. Add support for this.
--- drivers/gpu/drm/i2c/tda998x_drv.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-)
drivers/gpu/drm/i2c/tda998x_drv.c +13 -1
@@ -229,6 +229,8 @@ struct tda998x_priv {/* Page 12h: HDCP and OTP */ #define REG_TX3 REG(0x12, 0x9a)/* read/write */ +#define REG_TX4 REG(0x12, 0x9b)/* read/write */ +# define TX4_PD_RAM (1 << 1)#define REG_TX33 REG(0x12, 0xb8)/* read/write */ # define TX33_HDMI (1 << 1)
@@ -673,6 +675,7 @@ read_edid_block(struct drm_encoder *encoder, uint8_t *buf, int blk)static uint8_t *do_get_edid (struct drm_encoder *encoder) { +struct tda998x_priv *priv =to_tda998x_priv (encoder);int j =0 , valid_extensions =0 ;uint8_t *block, *new;bool print_bad_edid = drm_debug &DRM_UT_KMS ;
@@ -680,6 +683,9 @@ do_get_edid(struct drm_encoder *encoder)if ((block =kmalloc (EDID_LENGTH ,GFP_KERNEL )) ==NULL )return NULL ; +if (priv->rev ==TDA19988 ) +reg_clear (encoder,REG_TX4 ,TX4_PD_RAM ); +/* base block fetch */ if (read_edid_block (encoder, block,0 )) goto fail;
@@ -689,7 +695,7 @@ do_get_edid(struct drm_encoder *encoder)/* if there's no extensions, we're done */ if (block[0x7e ] ==0 ) -return block; + goto done; new =krealloc (block, (block[0x7e ] +1 ) *EDID_LENGTH ,GFP_KERNEL );if (!new)
@@ -716,9 +722,15 @@ do_get_edid(struct drm_encoder *encoder) block = new; } +done: +if (priv->rev ==TDA19988 ) +reg_set (encoder,REG_TX4 ,TX4_PD_RAM ); +return block; fail: +if (priv->rev ==TDA19988 ) +reg_set (encoder,REG_TX4 ,TX4_PD_RAM );dev_warn (encoder->dev->dev,"failed to read EDID\n" );kfree (block);return NULL ;
Signature · 1 line
1.7.4.4
RFC PATCH 4/8 drm/i2c: nxp-tda998x: ensure VIP output mux is properly set
In reply to Russell King - ARM LinuxWhen switching between various drivers for this device, it's possible that some critical registers are left containing values which affect the device operation. One such case encountered is the VIP output mux register. This defaults to 0x24 on powerup, but other drivers may set this to 0x12. This results in incorrect colours.
Fix this by ensuring that the register is always set to the power on default setting.
--- drivers/gpu/drm/i2c/tda998x_drv.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/gpu/drm/i2c/tda998x_drv.c +4 -0
@@ -110,6 +110,7 @@ struct tda998x_priv {#define REG_VIP_CNTRL_5 REG(0x00, 0x25)/* write */ # define VIP_CNTRL_5_CKCASE (1 << 0)# define VIP_CNTRL_5_SP_CNT (x) (((x) & 3) << 1) +#define REG_MUX_VP_VIP_OUT REG(0x00, 0x27)/* read/write */ #define REG_MAT_CONTRL REG(0x00, 0x80)/* write */ # define MAT_CONTRL_MAT_SC (x) (((x) & 3) << 0)# define MAT_CONTRL_MAT_BP (1 << 2)
@@ -415,6 +416,9 @@ tda998x_reset(struct drm_encoder *encoder)reg_write (encoder,REG_PLL_SCGR1 ,0x5b );reg_write (encoder,REG_PLL_SCGR2 ,0x00 );reg_write (encoder,REG_PLL_SCG2 ,0x10 ); + +/* Ensure VP output bus muxes result in no swapping */ +reg_write (encoder,REG_MUX_VP_VIP_OUT ,0x24 ); }/* DRM encoder functions */
Signature · 1 line
1.7.4.4
RFC PATCH 5/8 drm/i2c: nxp-tda998x: fix npix/nline programming
In reply to Russell King - ARM LinuxThe npix/nline registers are supposed to be programmed with the total number of pixels/lines, not the displayed pixels/lines, and not minus one either.
--- drivers/gpu/drm/i2c/tda998x_drv.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i2c/tda998x_drv.c +2 -2
@@ -587,8 +587,8 @@ tda998x_encoder_mode_set(struct drm_encoder *encoder,reg_set (encoder,REG_VIP_CNTRL_3 ,VIP_CNTRL_3_H_TGL );reg_write (encoder,REG_VIDFORMAT ,0x00 ); -reg_write16 (encoder,REG_NPIX_MSB , mode->hdisplay -1 ); -reg_write16 (encoder,REG_NLINE_MSB , mode->vdisplay -1 ); +reg_write16 (encoder,REG_NPIX_MSB , mode->htotal); +reg_write16 (encoder,REG_NLINE_MSB , mode->vtotal);reg_write16 (encoder,REG_VS_LINE_STRT_1_MSB , line_start);reg_write16 (encoder,REG_VS_LINE_END_1_MSB , line_end);reg_write16 (encoder,REG_VS_PIX_STRT_1_MSB , hs_start);
Signature · 1 line
1.7.4.4
Re: [PATCH RFC 5/8] drm/i2c: nxp-tda998x: fix npix/nline programming
Quoted 6 lines · Russell King
The npix/nline registers are supposed to be programmed with the total number of pixels/lines, not the displayed pixels/lines, and not minus one either.
Signed-off-by Russell King<[email protected]>---
Russell, Rob,
I have patches fixing TDA998x sync generation for progressive video. They are based on TDA9983b datasheet [1]. TDA998x expects ITU-style sync with positive hblank/vblank (or VESA-style hsync/vsync plus refpix/refline). The patches make TDA998x behave as transparent as possible, i.e. invert input sync signals as required and revert for output sync as requested by EDID. I have measured a bunch of modes with an oszilloscope near-end (TDA998x input) and far-end (DVI receiver output) and they are pixel- and line-true.
Unfortunately, I have no receiver allowing me to also fix interlaced sync generation but with progressive working, that shouldn't be that hard to implement.
Will clean-up patches next week and rebase on Russell's RFC.
Sebastian
[1]
http://pdf1.alldatasheet.com/datasheet-pdf/view/347888/NXP/TDA9983B.html
RFC PATCH 6/8 drm/i2c: nxp-tda998x: prepare for video input configuration
In reply to Russell King - ARM Linux--- drivers/gpu/drm/i2c/tda998x_drv.c | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-)
drivers/gpu/drm/i2c/tda998x_drv.c +10 -6
@@ -32,6 +32,9 @@ struct tda998x_priv {uint16_t rev;uint8_t current_page;int dpms; +u8 vip_cntrl_0; +u8 vip_cntrl_1; +u8 vip_cntrl_2; };#define to_tda998x_priv (x) ((struct tda998x_priv *)to_encoder_slave(x)->slave_priv)
@@ -448,12 +451,9 @@ tda998x_encoder_dpms(struct drm_encoder *encoder, int mode)reg_write (encoder,REG_ENA_VP_1 ,0xff );reg_write (encoder,REG_ENA_VP_2 ,0xff );/* set muxing after enabling ports: */ -reg_write (encoder,REG_VIP_CNTRL_0 , -VIP_CNTRL_0_SWAP_A (2 ) |VIP_CNTRL_0_SWAP_B (3 )); -reg_write (encoder,REG_VIP_CNTRL_1 , -VIP_CNTRL_1_SWAP_C (0 ) |VIP_CNTRL_1_SWAP_D (1 )); -reg_write (encoder,REG_VIP_CNTRL_2 , -VIP_CNTRL_2_SWAP_E (4 ) |VIP_CNTRL_2_SWAP_F (5 )); +reg_write (encoder,REG_VIP_CNTRL_0 , priv->vip_cntrl_0); +reg_write (encoder,REG_VIP_CNTRL_1 , priv->vip_cntrl_1); +reg_write (encoder,REG_VIP_CNTRL_2 , priv->vip_cntrl_2);break ;case DRM_MODE_DPMS_OFF :/* disable audio and video ports */
@@ -823,6 +823,10 @@ tda998x_encoder_init(struct i2c_client *client,if (!priv)return -ENOMEM ; + priv->vip_cntrl_0 =VIP_CNTRL_0_SWAP_A (2 ) |VIP_CNTRL_0_SWAP_B (3 ); + priv->vip_cntrl_1 =VIP_CNTRL_1_SWAP_C (0 ) |VIP_CNTRL_1_SWAP_D (1 ); + priv->vip_cntrl_2 =VIP_CNTRL_2_SWAP_E (4 ) |VIP_CNTRL_2_SWAP_F (5 ); + priv->current_page =0 ; priv->cec =i2c_new_dummy (client->adapter,0x34 ); priv->dpms =DRM_MODE_DPMS_OFF ;
Signature · 1 line
1.7.4.4
RFC PATCH 7/8 drm/i2c: nxp-tda998x: add video and audio input configuration
In reply to Russell King - ARM Linux--- drivers/gpu/drm/i2c/tda998x_drv.c | 308 ++++++++++++++++++++++++++++++++++++- include/drm/i2c/tda998x.h | 30 ++++ 2 files changed, 331 insertions(+), 7 deletions(-) create mode 100644 include/drm/i2c/tda998x.h
drivers/gpu/drm/i2c/tda998x_drv.c +301 -7
@@ -23,7 +23,7 @@#include <drm/drm_crtc_helper.h> #include <drm/drm_encoder_slave.h> #include <drm/drm_edid.h> - +#include <drm/i2c/tda998x.h> #define DBG (fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
@@ -32,9 +32,11 @@ struct tda998x_priv {uint16_t rev;uint8_t current_page;int dpms; +bool is_hdmi_sink;u8 vip_cntrl_0;u8 vip_cntrl_1;u8 vip_cntrl_2; +struct tda998x_encoder_params params; };#define to_tda998x_priv (x) ((struct tda998x_priv *)to_encoder_slave(x)->slave_priv)
@@ -71,10 +73,13 @@ struct tda998x_priv {# define I2C_MASTER_DIS_MM (1 << 0)# define I2C_MASTER_DIS_FILT (1 << 1)# define I2C_MASTER_APP_STRT_LAT (1 << 2) +#define REG_FEAT_POWERDOWN REG(0x00, 0x0e)/* read/write */ +# define FEAT_POWERDOWN_SPDIF (1 << 3)#define REG_INT_FLAGS_0 REG(0x00, 0x0f)/* read/write */ #define REG_INT_FLAGS_1 REG(0x00, 0x10)/* read/write */ #define REG_INT_FLAGS_2 REG(0x00, 0x11)/* read/write */ # define INT_FLAGS_2_EDID_BLK_RD (1 << 1) +#define REG_ENA_ACLK REG(0x00, 0x16)/* read/write */ #define REG_ENA_VP_0 REG(0x00, 0x18)/* read/write */ #define REG_ENA_VP_1 REG(0x00, 0x19)/* read/write */ #define REG_ENA_VP_2 REG(0x00, 0x1a)/* read/write */
@@ -113,6 +118,7 @@ struct tda998x_priv {#define REG_VIP_CNTRL_5 REG(0x00, 0x25)/* write */ # define VIP_CNTRL_5_CKCASE (1 << 0)# define VIP_CNTRL_5_SP_CNT (x) (((x) & 3) << 1) +#define REG_MUX_AP REG(0x00, 0x26)/* read/write */ #define REG_MUX_VP_VIP_OUT REG(0x00, 0x27)/* read/write */ #define REG_MAT_CONTRL REG(0x00, 0x80)/* write */ # define MAT_CONTRL_MAT_SC (x) (((x) & 3) << 0)
@@ -175,6 +181,12 @@ struct tda998x_priv {# define HVF_CNTRL_1_PAD (x) (((x) & 3) << 4)# define HVF_CNTRL_1_SEMI_PLANAR (1 << 6)#define REG_RPT_CNTRL REG(0x00, 0xf0)/* write */ +#define REG_I2S_FORMAT REG(0x00, 0xfc)/* read/write */ +# define I2S_FORMAT (x) (((x) & 3) << 0) +#define REG_AIP_CLKSEL REG(0x00, 0xfd)/* write */ +# define AIP_CLKSEL_FS (x) (((x) & 3) << 0) +# define AIP_CLKSEL_CLK_POL (x) (((x) & 1) << 2) +# define AIP_CLKSEL_AIP (x) (((x) & 7) << 3)/* Page 02h: PLL settings */
@@ -216,6 +228,11 @@ struct tda998x_priv {/* Page 10h: information frames and packets */ +#define REG_IF1_HB0 REG(0x10, 0x20)/* read/write */ +#define REG_IF2_HB0 REG(0x10, 0x40)/* read/write */ +#define REG_IF3_HB0 REG(0x10, 0x60)/* read/write */ +#define REG_IF4_HB0 REG(0x10, 0x80)/* read/write */ +#define REG_IF5_HB0 REG(0x10, 0xa0)/* read/write */ /* Page 11h: audio settings and content info packets */
@@ -225,10 +242,33 @@ struct tda998x_priv {# define AIP_CNTRL_0_LAYOUT (1 << 2)# define AIP_CNTRL_0_ACR_MAN (1 << 5)# define AIP_CNTRL_0_RST_CTS (1 << 6) +#define REG_CA_I2S REG(0x11, 0x01)/* read/write */ +# define CA_I2S_CA_I2S (x) (((x) & 31) << 0) +# define CA_I2S_HBR_CHSTAT (1 << 6) +#define REG_LATENCY_RD REG(0x11, 0x04)/* read/write */ +#define REG_ACR_CTS_0 REG(0x11, 0x05)/* read/write */ +#define REG_ACR_CTS_1 REG(0x11, 0x06)/* read/write */ +#define REG_ACR_CTS_2 REG(0x11, 0x07)/* read/write */ +#define REG_ACR_N_0 REG(0x11, 0x08)/* read/write */ +#define REG_ACR_N_1 REG(0x11, 0x09)/* read/write */ +#define REG_ACR_N_2 REG(0x11, 0x0a)/* read/write */ +#define REG_CTS_N REG(0x11, 0x0c)/* read/write */ +# define CTS_N_K (x) (((x) & 7) << 0) +# define CTS_N_M (x) (((x) & 3) << 4)#define REG_ENC_CNTRL REG(0x11, 0x0d)/* read/write */ # define ENC_CNTRL_RST_ENC (1 << 0)# define ENC_CNTRL_RST_SEL (1 << 1)# define ENC_CNTRL_CTL_CODE (x) (((x) & 3) << 2) +#define REG_DIP_FLAGS REG(0x11, 0x0e)/* read/write */ +# define DIP_FLAGS_ACR (1 << 0) +# define DIP_FLAGS_GC (1 << 1) +#define REG_DIP_IF_FLAGS REG(0x11, 0x0f)/* read/write */ +# define DIP_IF_FLAGS_IF1 (1 << 1) +# define DIP_IF_FLAGS_IF2 (1 << 2) +# define DIP_IF_FLAGS_IF3 (1 << 3) +# define DIP_IF_FLAGS_IF4 (1 << 4) +# define DIP_IF_FLAGS_IF5 (1 << 5) +#define REG_CH_STAT_B (x) REG(0x11, 0x14 + (x))/* read/write */ /* Page 12h: HDCP and OTP */
@@ -344,6 +384,23 @@ reg_read_range(struct drm_encoder *encoder, uint16_t reg, char *buf, int cnt)return ret; } +static void +reg_write_range (struct drm_encoder *encoder,uint16_t reg,uint8_t *p,int cnt) +{ +struct i2c_client *client =drm_i2c_encoder_get_client (encoder); +uint8_t buf[cnt+1 ]; +int ret; + + buf[0 ] =REG2ADDR (reg); +memcpy (&buf[1 ], p, cnt); + +set_page (encoder, reg); + + ret =i2c_master_send (client, buf, cnt +1 ); +if (ret <0 ) +dev_err (&client->dev,"Error %d writing to 0x%x\n" , ret, reg); +} +static uint8_t reg_read (struct drm_encoder *encoder,uint16_t reg) {
@@ -424,11 +481,192 @@ tda998x_reset(struct drm_encoder *encoder)reg_write (encoder,REG_MUX_VP_VIP_OUT ,0x24 ); } +static uint8_t tda998x_cksum (uint8_t *buf,size_t bytes) +{ +uint8_t sum =0 ; + +while (bytes--) + sum += *buf++; +return (255 - sum) +1 ; +} + +#define HB (x) (x) +#define PB (x) (HB(2) + 1 + (x)) + +static void +tda998x_write_if (struct drm_encoder *encoder,uint8_t bit,uint16_t addr, +uint8_t *buf,size_t size) +{ + buf[PB (0 )] =tda998x_cksum (buf, size); + +reg_clear (encoder,REG_DIP_IF_FLAGS , bit); +reg_write_range (encoder, addr, buf, size); +reg_set (encoder,REG_DIP_IF_FLAGS , bit); +} + +static void +tda998x_write_aif (struct drm_encoder *encoder,struct tda998x_encoder_params *p) +{ +uint8_t buf[PB (5 ) +1 ]; + + buf[HB (0 )] =0x84 ; + buf[HB (1 )] =0x01 ; + buf[HB (2 )] =10 ; + buf[PB (0 )] =0 ; + buf[PB (1 )] = p->audio_frame[1 ] &0x07 ;/* CC */ + buf[PB (2 )] = p->audio_frame[2 ] &0x1c ;/* SF */ + buf[PB (4 )] = p->audio_frame[4 ]; + buf[PB (5 )] = p->audio_frame[5 ] &0xf8 ;/* DM_INH + LSV */ + +tda998x_write_if (encoder,DIP_IF_FLAGS_IF4 ,REG_IF4_HB0 , buf, +sizeof (buf)); +} + +static void +tda998x_write_avi (struct drm_encoder *encoder,struct drm_display_mode *mode) +{ +uint8_t buf[PB (13 ) +1 ]; + +memset (buf,0 ,sizeof (buf)); + buf[HB (0 )] =0x82 ; + buf[HB (1 )] =0x02 ; + buf[HB (2 )] =13 ; + buf[PB (4 )] =drm_match_cea_mode (mode); + +tda998x_write_if (encoder,DIP_IF_FLAGS_IF2 ,REG_IF2_HB0 , buf, +sizeof (buf)); +} + +static void tda998x_audio_mute (struct drm_encoder *encoder,bool on) +{ +if (on) { +reg_set (encoder,REG_SOFTRESET ,SOFTRESET_AUDIO ); +reg_clear (encoder,REG_SOFTRESET ,SOFTRESET_AUDIO ); +reg_set (encoder,REG_AIP_CNTRL_0 ,AIP_CNTRL_0_RST_FIFO ); + }else { +reg_clear (encoder,REG_AIP_CNTRL_0 ,AIP_CNTRL_0_RST_FIFO ); + } +} + +static void +tda998x_configure_audio (struct drm_encoder *encoder,struct tda998x_encoder_params *p) +{ +uint8_t buf[6 ], clksel_aip, clksel_fs, ca_i2s, cts_n; +uint32_t n; + +/* SetAudioPortConfig */ +reg_write (encoder,REG_ENA_AP , p->audio_cfg); +/* SetAudioClockPortConfig */ +reg_write (encoder,REG_ENA_ACLK , p->audio_clk_cfg); + +/* +* layout = channelAllocation ? 1 : 0; +* AudioInSetConfig(format, i2sFormat, channelAllocation, +* HDMITX_CHAN_NO_CHANGE, HDMITX_CLKPOLDSD_NO_CHANGE, +* HDMITX_SWAPDSD_NO_CHANGE, layout, HDMITX_LATENCY_CURRENT, +* dstRate) +*/ +switch (p->audio_format) { +case AFMT_SPDIF : +reg_write (encoder,REG_MUX_AP ,0x40 ); + clksel_aip =AIP_CLKSEL_AIP (0 ); +/* FS64SPDIF */ + clksel_fs =AIP_CLKSEL_FS (2 ); + cts_n =CTS_N_M (3 ) |CTS_N_K (3 ); + ca_i2s =0 ; +break ; + +case AFMT_I2S : +reg_write (encoder,REG_MUX_AP ,0x64 ); + clksel_aip =AIP_CLKSEL_AIP (1 ); +/* ACLK */ + clksel_fs =AIP_CLKSEL_FS (0 ); + cts_n =CTS_N_M (3 ) |CTS_N_K (3 ); + ca_i2s =CA_I2S_CA_I2S (0 /* channel allocation */ ); +break ; + } + +reg_write (encoder,REG_AIP_CLKSEL , clksel_aip); +// reg_write(encoder, REG_CA_I2S, ca_i2s); +// reg_write(encoder, REG_I2S_FORMAT, I2S_FORMAT(0 /* i2s format */)); +reg_clear (encoder,REG_AIP_CNTRL_0 ,AIP_CNTRL_0_LAYOUT ); +/* latency? */ + +/* get video format */ + +/* +* ctsRef = HDMITX_CTSREF_FS64SPDIF, uCtsX = HDMITX_CTSX_64 +* AudioInSetCts(ctsRef, rate, VidFmt, vOutFreq, +* HDMITX_CTS_AUTO, uCtsX, HDMITX_CTSK_USE_CTSX, +* HDMITX_CTSMTS_USE_CTSX, dstRate) +*/ +/* Auto CTS */ +reg_clear (encoder,REG_AIP_CNTRL_0 ,AIP_CNTRL_0_ACR_MAN ); +reg_write (encoder,REG_CTS_N , cts_n); +reg_write (encoder,REG_AUDIO_DIV ,3 ); + +/* +* This is the approximate value of N, which happens to be +* the recommended values for non-coherent clocks. +*/ + n =128 * p->audio_sample_rate /1000 ; + +/* Write the CTS and N values */ + buf[0 ] =0x44 ; + buf[1 ] =0x42 ; + buf[2 ] =0x01 ; + buf[3 ] = n; + buf[4 ] = n >>8 ; + buf[5 ] = n >>16 ; +reg_write_range (encoder,REG_ACR_CTS_0 , buf,6 ); + +/* Set CTS clock reference */ +reg_write (encoder,REG_AIP_CLKSEL , clksel_aip | clksel_fs); + +/* Reset CTS generator */ +reg_set (encoder,REG_AIP_CNTRL_0 ,AIP_CNTRL_0_RST_CTS ); +reg_clear (encoder,REG_AIP_CNTRL_0 ,AIP_CNTRL_0_RST_CTS ); + +/* Write the channel status */ + buf[0 ] =0x04 ; + buf[1 ] =0x00 ; + buf[2 ] =0x00 ; + buf[3 ] =0xf1 ; +reg_write_range (encoder,REG_CH_STAT_B (0 ), buf,4 ); + +tda998x_audio_mute (encoder, true); +mdelay (20 ); +tda998x_audio_mute (encoder, false); + +/* Write the audio information packet */ +tda998x_write_aif (encoder, p); +} +/* DRM encoder functions */ static void tda998x_encoder_set_config (struct drm_encoder *encoder,void *params) { +struct tda998x_priv *priv =to_tda998x_priv (encoder); +struct tda998x_encoder_params *p = params; + + priv->vip_cntrl_0 =VIP_CNTRL_0_SWAP_A (p->swap_a) | + (p->mirr_a ?VIP_CNTRL_0_MIRR_A :0 ) | +VIP_CNTRL_0_SWAP_B (p->swap_b) | + (p->mirr_b ?VIP_CNTRL_0_MIRR_B :0 ); + priv->vip_cntrl_1 =VIP_CNTRL_1_SWAP_C (p->swap_c) | + (p->mirr_c ?VIP_CNTRL_1_MIRR_C :0 ) | +VIP_CNTRL_1_SWAP_D (p->swap_d) | + (p->mirr_d ?VIP_CNTRL_1_MIRR_D :0 ); + priv->vip_cntrl_2 =VIP_CNTRL_2_SWAP_E (p->swap_e) | + (p->mirr_e ?VIP_CNTRL_2_MIRR_E :0 ) | +VIP_CNTRL_2_SWAP_F (p->swap_f) | + (p->mirr_f ?VIP_CNTRL_2_MIRR_F :0 ); + + priv->params = *p; + +if (p->audio_cfg) +tda998x_configure_audio (encoder, p); } static void
@@ -446,7 +684,8 @@ tda998x_encoder_dpms(struct drm_encoder *encoder, int mode)switch (mode) {case DRM_MODE_DPMS_ON :/* enable audio and video ports */ -reg_write (encoder,REG_ENA_AP ,0xff ); +// reg_write(encoder, REG_ENA_AP, priv->ena_ap); +// reg_write(encoder, REG_ENA_ACLK, priv->ena_aclk); reg_write (encoder,REG_ENA_VP_0 ,0xff );reg_write (encoder,REG_ENA_VP_1 ,0xff );reg_write (encoder,REG_ENA_VP_2 ,0xff );
@@ -457,7 +696,7 @@ tda998x_encoder_dpms(struct drm_encoder *encoder, int mode)break ;case DRM_MODE_DPMS_OFF :/* disable audio and video ports */ -reg_write (encoder,REG_ENA_AP ,0x00 ); +// reg_write(encoder, REG_ENA_AP, 0x00); reg_write (encoder,REG_ENA_VP_0 ,0x00 );reg_write (encoder,REG_ENA_VP_1 ,0x00 );reg_write (encoder,REG_ENA_VP_2 ,0x00 );
@@ -608,17 +847,31 @@ tda998x_encoder_mode_set(struct drm_encoder *encoder,reg_write16 (encoder,REG_REFPIX_MSB , ref_pix);reg_write16 (encoder,REG_REFLINE_MSB , ref_line); - reg =TBG_CNTRL_1_VHX_EXT_DE | -TBG_CNTRL_1_VHX_EXT_HS | -TBG_CNTRL_1_VHX_EXT_VS | -TBG_CNTRL_1_DWIN_DIS |/* HDCP off */ + reg =TBG_CNTRL_1_DWIN_DIS |/* HDCP off */ TBG_CNTRL_1_VH_TGL_2 ; +/* +* It is questionable whether this is correct - the nxp driver +* does not set VH_TGL_2 and the below for all display modes. +*/ if (mode->flags & (DRM_MODE_FLAG_NVSYNC |DRM_MODE_FLAG_NHSYNC )) reg |=TBG_CNTRL_1_VH_TGL_0 ;reg_set (encoder,REG_TBG_CNTRL_1 , reg);/* must be last register set: */ reg_clear (encoder,REG_TBG_CNTRL_0 ,TBG_CNTRL_0_SYNC_ONCE ); + +/* Only setup the info frames if the sink is HDMI */ +if (priv->is_hdmi_sink) { +/* We need to turn HDMI HDCP stuff on to get audio through */ +reg_clear (encoder,REG_TBG_CNTRL_1 ,TBG_CNTRL_1_DWIN_DIS ); +reg_write (encoder,REG_ENC_CNTRL ,ENC_CNTRL_CTL_CODE (1 )); +reg_set (encoder,REG_TX33 ,TX33_HDMI ); + +tda998x_write_avi (encoder, adjusted_mode); + +if (priv->params.audio_cfg) +tda998x_configure_audio (encoder, &priv->params); + } } static enum drm_connector_status
@@ -744,12 +997,14 @@ static int tda998x_encoder_get_modes(struct drm_encoder *encoder, struct drm_connector *connector) { + struct tda998x_priv *priv = to_tda998x_priv(encoder);struct edid *edid = (struct edid *)do_get_edid (encoder);int n =0 ;if (edid) {drm_mode_connector_update_edid_property (connector, edid); n =drm_add_edid_modes (connector, edid); + priv->is_hdmi_sink =drm_detect_hdmi_monitor (edid);kfree (edid); }
@@ -811,6 +1066,40 @@ tda998x_remove(struct i2c_client *client)return 0 ; } +static ssize_t i2c_read_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t size) +{ +struct drm_encoder *encoder =dev_get_drvdata (dev); +unsigned int page, addr; +unsigned char val; + +sscanf (buf,"%x %x" , &page, &addr); + + val =reg_read (encoder,REG (page, addr)); + +printk ("i2c read %02x @ page:%02x address:%02x\n" , val, page, addr); +return size; +} + +static ssize_t i2c_write_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t size) +{ +struct drm_encoder *encoder =dev_get_drvdata (dev); +unsigned int page, addr, mask, val; +unsigned char rval; + +sscanf (buf,"%x %x %x %x" , &page, &addr, &mask, &val); + + rval =reg_read (encoder,REG (page, addr)); + rval &= ~mask; + rval |= val & mask; +reg_write (encoder,REG (page, addr), rval); + +printk ("i2c write %02x @ page:%02x address:%02x\n" , rval, page, addr); +return size; +} + +static DEVICE_ATTR(i2c_read, S_IWUSR, NULL, i2c_read_store); +static DEVICE_ATTR(i2c_write, S_IWUSR, NULL, i2c_write_store); + static int tda998x_encoder_init(struct i2c_client *client, struct drm_device *dev,
@@ -818,6 +1107,11 @@ tda998x_encoder_init(struct i2c_client *client, {struct drm_encoder *encoder = &encoder_slave->base;struct tda998x_priv *priv; +/* debug */ +device_create_file (&client->dev, &dev_attr_i2c_read); +device_create_file (&client->dev, &dev_attr_i2c_write); +dev_set_drvdata (&client->dev, encoder); +/* debug end */ priv =kzalloc (sizeof (*priv),GFP_KERNEL );if (!priv)
include/drm/i2c/tda998x.h new file +30 -0
@@ -0,0 +1,30 @@ +#ifndef __DRM_I2C_TDA998X_H__ +#define __DRM_I2C_TDA998X_H__ + +struct tda998x_encoder_params { +u8 swap_b:3 ; +u8 mirr_b:1 ; +u8 swap_a:3 ; +u8 mirr_a:1 ; +u8 swap_d:3 ; +u8 mirr_d:1 ; +u8 swap_c:3 ; +u8 mirr_c:1 ; +u8 swap_f:3 ; +u8 mirr_f:1 ; +u8 swap_e:3 ; +u8 mirr_e:1 ; + +u8 audio_cfg; +u8 audio_clk_cfg; +u8 audio_frame[6 ]; + +enum { +AFMT_SPDIF , +AFMT_I2S + } audio_format; + +unsigned audio_sample_rate; +}; + +#endif
Signature · 1 line
1.7.4.4
RFC PATCH 8/8 DRM: Armada: add support for drm tda19988 driver
In reply to Russell King - ARM Linux--- drivers/gpu/drm/armada/Kconfig | 9 +++++++ drivers/gpu/drm/armada/armada_drv.c | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 0 deletions(-)
drivers/gpu/drm/armada/Kconfig +9 -0
@@ -13,3 +13,12 @@ config DRM_ARMADA This driver provides no built-in acceleration; acceleration is performed by other IP found on the SoC. This driver provides kernel mode setting and buffer management to userspace. + +config DRM_ARMADA_TDA1998X + bool "Support TDA1998X HDMI output" + depends on DRM_ARMADA != n + depends on I2C && DRM_I2C_NXP_TDA998X = y + default y + help + Support the TDA1998x HDMI output device found on the Solid-Run + CuBox.
drivers/gpu/drm/armada/armada_drv.c +42 -0
54 lines not on this page · raw message
Signature · 1 line
1.7.4.4
Quoted 1 line · Russell King - ARM Linux
This is version 2 of my DRM driver. Changes since the previous version:
Okay, patch 1 got removed from this set, so some people won't see it (it shouldn't have been sent). Patch 2 is in moderation, which is probably the more interesting patch because that's got the interesting stuff in.
Okay, so the previous set didn't contain all the updates I wanted. That's partly because of the timespan between making those changes and re-posting the RFC.
This time, the "Add Armada DRM driver" commit contains all the updates it should've had from last time!
However, I'm posting a slightly different branch - it's rooted at the same "Add Armada DRM driver" commit so take patch 1 from this as an update to patch 2 of the previous series.
This looks like:
+ DRM: Armada: Add Armada DRM driver
|\
+ | drm/i2c: nxp-tda998x patches
+ | DRM: Armada: add support for drm tda19988 driver
+ DRM: Armada: Add support for hardware cursors
+ DRM: Armada: convert Armada hardware cursor support to RGB+transparency
+ DRM: Armada: convert hardware cursor support to 64x32 or 32x64 ARGB
Now, the three additional patches where incrementally add hardware cursor support; first my original version. This didn't work very well. Next is my try with the RGB+transparency suggested in the first RFC round. The cursor image looked silly against some windows because you can't sanely translate an alpha channel to transparency.
The last version is what I'm using, and I _am_ using hardware cursors. This seems to be the best solution if we're going to have hardware cursors, even though it means that we don't support 64x64 cursors.
For the first patch (the main large patch) the changes are as per my reply to the previous review comments confirming the updates, and a couple of other changes which should've been in the previous RFC:
1. if we map a gem object in kernel space, store its kernel space address. This avoids use of phys_to_virt() in the cursor code which really wasn't nice.
2. initial variant-based clocking support to support non-Dove implementations.
RFC PATCH v3 1/4 DRM: Armada: Add Armada DRM driver
In reply to Russell King - ARM LinuxThis patch adds support for the pair of LCD controllers on the Marvell Armada 510 SoCs. This driver supports:
- multiple contiguous scanout buffers for video and graphics
- shm backed cacheable buffer objects for X pixmaps for Vivante GPU acceleration
- dual lcd0 and lcd1 crt operation
- video overlay on each LCD crt
- page flipping of the main scanout buffers
Included in this commit is the core driver with no output support; output support is platform and encoder driver dependent.
--- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/armada/Kconfig | 15 + drivers/gpu/drm/armada/Makefile | 6 + drivers/gpu/drm/armada/armada_crtc.c | 766 +++++++++++++++++++++++++++++++ drivers/gpu/drm/armada/armada_crtc.h | 73 +++ drivers/gpu/drm/armada/armada_debugfs.c | 186 ++++++++ drivers/gpu/drm/armada/armada_drm.h | 73 +++ drivers/gpu/drm/armada/armada_drv.c | 389 ++++++++++++++++ drivers/gpu/drm/armada/armada_fb.c | 156 +++++++ drivers/gpu/drm/armada/armada_fb.h | 21 + drivers/gpu/drm/armada/armada_fbdev.c | 210 +++++++++ drivers/gpu/drm/armada/armada_gem.c | 435 ++++++++++++++++++ drivers/gpu/drm/armada/armada_gem.h | 43 ++ drivers/gpu/drm/armada/armada_hw.h | 308 +++++++++++++ drivers/gpu/drm/armada/armada_ioctl.h | 124 +++++ drivers/gpu/drm/armada/armada_ioctlP.h | 22 + drivers/gpu/drm/armada/armada_output.c | 159 +++++++ drivers/gpu/drm/armada/armada_output.h | 38 ++ drivers/gpu/drm/armada/armada_overlay.c | 514 +++++++++++++++++++++ drivers/gpu/drm/armada/armada_slave.c | 138 ++++++ drivers/gpu/drm/armada/armada_slave.h | 26 + drivers/gpu/drm/armada/drm_helper.h | 31 ++ 23 files changed, 3736 insertions(+), 0 deletions(-) create mode 100644 drivers/gpu/drm/armada/Kconfig create mode 100644 drivers/gpu/drm/armada/Makefile create mode 100644 drivers/gpu/drm/armada/armada_crtc.c create mode 100644 drivers/gpu/drm/armada/armada_crtc.h create mode 100644 drivers/gpu/drm/armada/armada_debugfs.c create mode 100644 drivers/gpu/drm/armada/armada_drm.h create mode 100644 drivers/gpu/drm/armada/armada_drv.c create mode 100644 drivers/gpu/drm/armada/armada_fb.c create mode 100644 drivers/gpu/drm/armada/armada_fb.h create mode 100644 drivers/gpu/drm/armada/armada_fbdev.c create mode 100644 drivers/gpu/drm/armada/armada_gem.c create mode 100644 drivers/gpu/drm/armada/armada_gem.h create mode 100644 drivers/gpu/drm/armada/armada_hw.h create mode 100644 drivers/gpu/drm/armada/armada_ioctl.h create mode 100644 drivers/gpu/drm/armada/armada_ioctlP.h create mode 100644 drivers/gpu/drm/armada/armada_output.c create mode 100644 drivers/gpu/drm/armada/armada_output.h create mode 100644 drivers/gpu/drm/armada/armada_overlay.c create mode 100644 drivers/gpu/drm/armada/armada_slave.c create mode 100644 drivers/gpu/drm/armada/armada_slave.h create mode 100644 drivers/gpu/drm/armada/drm_helper.h
drivers/gpu/drm/Kconfig +2 -0
@@ -213,6 +213,8 @@ source "drivers/gpu/drm/mgag200/Kconfig" source "drivers/gpu/drm/cirrus/Kconfig" +source "drivers/gpu/drm/armada/Kconfig" + source "drivers/gpu/drm/shmobile/Kconfig" source "drivers/gpu/drm/tegra/Kconfig"
drivers/gpu/drm/Makefile +1 -0
@@ -48,6 +48,7 @@ obj-$(CONFIG_DRM_EXYNOS) +=exynos/ obj-$(CONFIG_DRM_GMA500) += gma500/ obj-$(CONFIG_DRM_UDL) += udl/ obj-$(CONFIG_DRM_AST) += ast/ +obj-$(CONFIG_DRM_ARMADA) += armada/ obj-$(CONFIG_DRM_SHMOBILE) +=shmobile/ obj-$(CONFIG_DRM_TEGRA) += tegra/ obj-$(CONFIG_DRM_OMAP) += omapdrm/
drivers/gpu/drm/armada/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +config DRM_ARMADA + tristate "DRM support for Marvell Armada SoCs" + depends on DRM && HAVE_CLK + select FB_CFB_FILLRECT + select FB_CFB_COPYAREA + select FB_CFB_IMAGEBLIT + select DRM_KMS_HELPER + help + Support the "LCD" controllers found on the Marvell Armada 510 + devices. There are two controllers on the device, each controller + supports graphics and video overlays. + + This driver provides no built-in acceleration; acceleration is + performed by other IP found on the SoC. This driver provides + kernel mode setting and buffer management to userspace.
drivers/gpu/drm/armada/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +armada-y := armada_crtc.o armada_drv.o armada_fb.o armada_fbdev.o \ + armada_gem.o armada_output.o armada_overlay.o \ + armada_slave.o +armada-$(CONFIG_DEBUG_FS) += armada_debugfs.o + +obj-$(CONFIG_DRM_ARMADA) := armada.o
drivers/gpu/drm/armada/armada_crtc.c new file +766 -0
766 lines not on this page · raw message
drivers/gpu/drm/armada/armada_crtc.h new file +73 -0
73 lines not on this page · raw message
drivers/gpu/drm/armada/armada_debugfs.c new file +186 -0
186 lines not on this page · raw message
drivers/gpu/drm/armada/armada_drm.h new file +73 -0
73 lines not on this page · raw message
drivers/gpu/drm/armada/armada_drv.c new file +389 -0
389 lines not on this page · raw message
drivers/gpu/drm/armada/armada_fb.c new file +156 -0
156 lines not on this page · raw message
drivers/gpu/drm/armada/armada_fb.h new file +21 -0
@@ -0,0 +1,21 @@ +/* +* Copyright (C) 2012 Russell King +* +* 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. +*/ +#ifndef ARMADA_FB_H +#define ARMADA_FB_H + +struct armada_framebuffer { +struct drm_framebuffer fb; +struct armada_gem_object *obj; +}; +#define drm_fb_to_armada_fb (dfb) container_of(dfb, struct armada_framebuffer, fb) +#define drm_fb_obj (fb) drm_fb_to_armada_fb(fb)->obj + +int armada_framebuffer_create (struct drm_device *,struct armada_framebuffer **, +struct drm_mode_fb_cmd2 *,struct armada_gem_object *); + +#endif
drivers/gpu/drm/armada/armada_fbdev.c new file +210 -0
210 lines not on this page · raw message
drivers/gpu/drm/armada/armada_gem.c new file +435 -0
435 lines not on this page · raw message
drivers/gpu/drm/armada/armada_gem.h new file +43 -0
43 lines not on this page · raw message
drivers/gpu/drm/armada/armada_hw.h new file +308 -0
308 lines not on this page · raw message
drivers/gpu/drm/armada/armada_ioctl.h new file +124 -0
124 lines not on this page · raw message
drivers/gpu/drm/armada/armada_ioctlP.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2012 Russell King +* +* 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. +*/ +#ifndef ARMADA_IOCTLP_H +#define ARMADA_IOCTLP_H + +#define ARMADA_IOCTL_PROTO (name)\ +extern int armada_##name##_ioctl(struct drm_device *, void *, struct drm_file *) + +ARMADA_IOCTL_PROTO (gem_create); +ARMADA_IOCTL_PROTO (gem_create_phys); +ARMADA_IOCTL_PROTO (gem_mmap); +ARMADA_IOCTL_PROTO (gem_prop); +ARMADA_IOCTL_PROTO (gem_pwrite); +ARMADA_IOCTL_PROTO (overlay_put_image); +ARMADA_IOCTL_PROTO (overlay_attrs); + +#endif
drivers/gpu/drm/armada/armada_output.c new file +159 -0
158 lines not on this page · raw message
drivers/gpu/drm/armada/armada_output.h new file +38 -0
Lines of this file are not shown. View the raw message.
drivers/gpu/drm/armada/armada_overlay.c new file +514 -0
514 lines not on this page · raw message
drivers/gpu/drm/armada/armada_slave.c new file +138 -0
138 lines not on this page · raw message
drivers/gpu/drm/armada/armada_slave.h new file +26 -0
Lines of this file are not shown. View the raw message.
drivers/gpu/drm/armada/drm_helper.h new file +31 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.4.4
Part of the diff is not shown here. View the raw message.
RFC PATCH v3 2/4 DRM: Armada: Add support for hardware cursors
In reply to Russell King - ARM LinuxThis patch adds hardware cursor support to the DRM driver for the Marvell Armada SoCs.
--- drivers/gpu/drm/armada/Kconfig | 7 + drivers/gpu/drm/armada/armada_crtc.c | 201 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/armada/armada_crtc.h | 8 ++ 3 files changed, 216 insertions(+), 0 deletions(-)
drivers/gpu/drm/armada/Kconfig +7 -0
@@ -13,3 +13,10 @@ config DRM_ARMADA This driver provides no built-in acceleration; acceleration is performed by other IP found on the SoC. This driver provides kernel mode setting and buffer management to userspace. + +config DRM_ARMADA_CURSOR + bool "Enable hardware cursor support for Marvell Armada DRM" + depends on DRM_ARMADA != n + help + Add support for hardware cursor support on the Marvell + Armada devices.
drivers/gpu/drm/armada/armada_crtc.c +201 -0
218 lines not on this page · raw message
drivers/gpu/drm/armada/armada_crtc.h +8 -0
@@ -48,6 +48,14 @@ struct armada_crtc {struct armada_overlay *overlay; +struct armada_gem_object *cursor_obj; +int cursor_x; +int cursor_y; +uint32_t cursor_w; +uint32_t cursor_h; +uint32_t cursor_lw; +uint32_t cursor_lh; +int dpms;uint32_t cfg_dma_ctrl0;uint32_t cfg_dumb_ctrl;
Signature · 1 line
1.7.4.4
RFC PATCH v3 3/4 DRM: Armada: convert Armada hardware cursor support to RGB+transparency
In reply to Russell King - ARM Linux--- drivers/gpu/drm/armada/Kconfig | 6 +- drivers/gpu/drm/armada/armada_crtc.c | 186 +++++++++++++++++++++++---------- drivers/gpu/drm/armada/armada_crtc.h | 5 +- 3 files changed, 135 insertions(+), 62 deletions(-)
drivers/gpu/drm/armada/Kconfig +3 -3
@@ -15,8 +15,8 @@ config DRM_ARMADA kernel mode setting and buffer management to userspace. config DRM_ARMADA_CURSOR - bool "Enable hardware cursor support for Marvell Armada DRM" + bool "Enable hardware RGB+T cursor support for Marvell Armada DRM" depends on DRM_ARMADA != n help - Add support for hardware cursor support on the Marvell - Armada devices. + Add support for RGB+transparency hardware cursor support on + the Marvell Armada devices.
drivers/gpu/drm/armada/armada_crtc.c +129 -57
225 lines not on this page · raw message
drivers/gpu/drm/armada/armada_crtc.h +3 -2
@@ -45,16 +45,17 @@ struct armada_crtc {uint32_t spu_adv_reg; } v[2 ];bool interlaced; +bool cursor_update;struct armada_overlay *overlay;struct armada_gem_object *cursor_obj;int cursor_x;int cursor_y; +uint32_t cursor_hw_pos; +uint32_t cursor_hw_sz;uint32_t cursor_w;uint32_t cursor_h; -uint32_t cursor_lw; -uint32_t cursor_lh;int dpms;uint32_t cfg_dma_ctrl0;
Signature · 1 line
1.7.4.4
RFC PATCH v3 4/4 DRM: Armada: convert hardware cursor support to 64x32 or 32x64 ARGB
In reply to Russell King - ARM Linux--- drivers/gpu/drm/armada/armada_crtc.c | 125 +++++++++++----------------------- drivers/gpu/drm/armada/armada_hw.h | 6 +- 2 files changed, 43 insertions(+), 88 deletions(-)
drivers/gpu/drm/armada/armada_crtc.c +39 -86
@@ -493,7 +493,8 @@ static int armada_drm_crtc_mode_set(struct drm_crtc *crtc, dcrtc->v[1 ].spu_adv_reg = val <<20 | val;/* Always enable RGB hardware cursor mode */ - dcrtc->v[1 ].spu_adv_reg |=ADV_HWC32ENABLE ; + dcrtc->v[1 ].spu_adv_reg |=ADV_HWC32ENABLE | +ADV_HWC32ARGB |ADV_HWC32BLEND ;if (interlaced) {/* Odd interlaced frame */
@@ -641,100 +642,46 @@ static const struct drm_crtc_helper_funcs armada_crtc_helper_funcs = { };#ifdef CONFIG_DRM_ARMADA_CURSOR -static void armada_load_cursor_rgb (void __iomem *base,uint32_t *pix, +static void armada_load_cursor_argb (void __iomem *base,uint32_t *pix,unsigned stride,unsigned width,unsigned height) { -uint32_t r, g, b, addr; -unsigned y, n; +uint32_t addr; +unsigned y; -for (r = g = b = addr = n = y =0 ; y < height; y++) { + addr =SRAM_HWC32_RAM1 ; +for (y =0 ; y < height; y++) {uint32_t *p = &pix[y * stride];unsigned x;for (x =0 ; x < width; x++, p++) { - r >>=8 ; - r |=0xff000000 & (*p <<8 ); - g >>=8 ; - g |=0xff000000 & (*p <<16 ); - b >>=8 ; - b |=0xff000000 & (*p <<24 ); -if (x ==0 || y ==0 ) { - b |=0xff000000 ; - g |=0xff000000 ; - r &= ~0xff000000 ; - } -if (++n ==4 ) { -writel_relaxed (r, - base +LCD_SPU_SRAM_WRDAT ); -writel_relaxed (addr | -SRAM_WRITE |SRAM_HWC32_RAMR , - base +LCD_SPU_SRAM_CTRL ); -writel_relaxed (g, - base +LCD_SPU_SRAM_WRDAT ); -writel_relaxed (addr | -SRAM_WRITE |SRAM_HWC32_RAMG , - base +LCD_SPU_SRAM_CTRL ); -writel_relaxed (b, - base +LCD_SPU_SRAM_WRDAT ); -writel_relaxed (addr | -SRAM_WRITE |SRAM_HWC32_RAMB , - base +LCD_SPU_SRAM_CTRL ); - addr +=1 ; -if ((addr &255 ) ==0 ) - addr +=0xf00 ; - n =0 ; - } +uint32_t val = *p; + + val = (val &0xff00ff00 ) | + (val &0x000000ff ) <<16 | + (val &0x00ff0000 ) >>16 ; + +writel_relaxed (val, + base +LCD_SPU_SRAM_WRDAT ); +writel_relaxed (addr |SRAM_WRITE , + base +LCD_SPU_SRAM_CTRL ); + addr +=1 ; +if ((addr &0x00ff ) ==0 ) + addr +=0xf00 ; +if ((addr &0x30ff ) ==0 ) + addr =SRAM_HWC32_RAM2 ; } } -if (n) { - r >>=8 * (4 - n); - g >>=8 * (4 - n); - b >>=8 * (4 - n); -writel_relaxed (r, base +LCD_SPU_SRAM_WRDAT ); -writel_relaxed (addr |SRAM_WRITE |SRAM_HWC32_RAMR , - base +LCD_SPU_SRAM_CTRL ); -writel_relaxed (g, base +LCD_SPU_SRAM_WRDAT ); -writel_relaxed (addr |SRAM_WRITE |SRAM_HWC32_RAMG , - base +LCD_SPU_SRAM_CTRL ); -writel_relaxed (b, base +LCD_SPU_SRAM_WRDAT ); -writel_relaxed (addr |SRAM_WRITE |SRAM_HWC32_RAMB , - base +LCD_SPU_SRAM_CTRL ); - } } -static void armada_load_cursor_alpha (void __iomem *base,uint32_t *pix, -unsigned stride,unsigned width,unsigned height) +static void armada_drm_crtc_cursor_tran (void __iomem *base) { -uint32_t data, addr, ram_cmd =SRAM_WRITE |SRAM_HWC32_TRAN ; -unsigned y, n; +unsigned addr; -for (data = addr = n = y =0 ; y < height; y++) { -uint32_t *p = &pix[y * stride]; -unsigned x; - -for (x =0 ; x < width; x++, p++) { - data >>=2 ; -if (*p >=0x80000000 ) - data |=0x40000000 ; -if (x ==0 || y ==0 ) - data |=0x40000000 ; -if (++n ==16 ) { -writel_relaxed (data, - base +LCD_SPU_SRAM_WRDAT ); -writel_relaxed (addr | -SRAM_WRITE |SRAM_HWC32_TRAN , - base +LCD_SPU_SRAM_CTRL ); - addr +=1 ; -if ((addr &255 ) ==0 ) - addr +=0xf00 ; - n =0 ; - } - } - } -if (n) { - data >>=2 * (16 - n); -writel_relaxed (data, base +LCD_SPU_SRAM_WRDAT ); -writel_relaxed (addr | ram_cmd, base +LCD_SPU_SRAM_CTRL ); +for (addr =0 ; addr <256 ; addr++) { +/* write the default value */ +writel_relaxed (0x55555555 , base +LCD_SPU_SRAM_WRDAT ); +writel_relaxed (addr |SRAM_WRITE |SRAM_HWC32_TRAN , + base +LCD_SPU_SRAM_CTRL ); } }
@@ -742,6 +689,7 @@ static int armada_drm_crtc_cursor_update(struct armada_crtc *dcrtc, bool reload) {uint32_t xoff, xscr, w = dcrtc->cursor_w, s;uint32_t yoff, yscr, h = dcrtc->cursor_h; +uint32_t para1;/* * Calculate the visible width and height of the cursor,
@@ -790,9 +738,14 @@ static int armada_drm_crtc_cursor_update(struct armada_crtc *dcrtc, bool reload)return 0 ; } + para1 =readl_relaxed (dcrtc->base +LCD_SPU_SRAM_PARA1 );armada_updatel (CFG_CSB_256x32, CFG_PDWN256x32, dcrtc->base +LCD_SPU_SRAM_PARA1 ); +/* Initialize the transparency if the SRAM was powered down */ +if (!(para1 & CFG_CSB_256x32)) +armada_drm_crtc_cursor_tran (dcrtc->base); +if (dcrtc->cursor_hw_sz != (h <<16 | w) || reload) {struct armada_gem_object *obj = dcrtc->cursor_obj;uint32_t *pix;
@@ -806,8 +759,7 @@ static int armada_drm_crtc_cursor_update(struct armada_crtc *dcrtc, bool reload)/* Set the top-left corner of the cursor image */ pix = obj->addr; pix += yoff * s + xoff; -armada_load_cursor_rgb (dcrtc->base, pix, s, w, h); -armada_load_cursor_alpha (dcrtc->base, pix, s, w, h); +armada_load_cursor_argb (dcrtc->base, pix, s, w, h); }/* Reload the cursor position, size and enable in the IRQ handler */
@@ -835,8 +787,8 @@ static int armada_drm_crtc_cursor_set(struct drm_crtc *crtc,int ret;if (handle && w >0 && h >0 ) { -/* maximum size is 64x64 */ -if (w >64 || h >64 ) +/* maximum size is 64x32 or 32x64 */ +if (w >64 || h >64 || (w >32 && h >32 ))return -ENOMEM ; obj =armada_gem_object_lookup (dev, file, handle);
@@ -1023,6 +975,7 @@ int armada_drm_crtc_create(struct drm_device *dev, unsigned num,writel_relaxed (0x0000e000 , dcrtc->base +LCD_SPU_SRAM_PARA1 );writel_relaxed (0x2032ff81 , dcrtc->base +LCD_SPU_DMA_CTRL1 );writel_relaxed (0x00000000 , dcrtc->base +LCD_SPU_GRA_OVSA_HPXL_VLN ); +writel_relaxed (CFG_PDWN256x32, dcrtc->base +LCD_SPU_SRAM_PARA1 );/* Lower the watermark so to eliminate jitter at higher bandwidths */ armada_updatel (0x20 , (1 <<11 ) |0xff , dcrtc->base +LCD_CFG_RDREG4F );
drivers/gpu/drm/armada/armada_hw.h +4 -2
@@ -171,8 +171,10 @@ enum {SRAM_READ =0 <<14 ,SRAM_WRITE =2 <<14 ,SRAM_INIT =3 <<14 , -SRAM_HWC32_RAMR =0xc <<8 , -SRAM_HWC32_RAMG =0xd <<8 , +SRAM_HWC32_RAM1 =0xc <<8 , +SRAM_HWC32_RAM2 =0xd <<8 , +SRAM_HWC32_RAMR =SRAM_HWC32_RAM1 , +SRAM_HWC32_RAMG =SRAM_HWC32_RAM2 ,SRAM_HWC32_RAMB =0xe <<8 ,SRAM_HWC32_TRAN =0xf <<8 , SRAM_HWC = 0xf << 8,
Signature · 1 line
1.7.4.4