drm: mxsfb: Implement LCDIF scanout CRC32 support
Subsystems (4)
Marek Vasut
maintainerPATCH 1/1 drm: mxsfb: Implement LCDIF scanout CRC32 support
The LCDIF controller as present in i.MX28/i.MX6SX/i.MX8M Mini/Nano has CRC_STAT register, which contains CRC32 of the frame as it was clocked out of the DPI interface of the LCDIF. This is most likely meant as a functional safety feature.
Unfortunately, there is zero documentation on how the CRC32 is calculated, there is no documentation of the polynomial, the init value, nor on which data is the checksum applied.
By applying brute-force on 8 pixel / 2 line frame, which is the minimum size LCDIF would work with, it turns out the polynomial is CRC32_POLY_LE 0xedb88320 , init value is 0xffffffff , the input data are bitrev32() of the entire frame and the resulting CRC has to be also bitrev32()ed.
Doing this calculation in kernel for each frame is unrealistic due to the CPU demand, so attach the CRC collected from hardware to a frame instead. The DRM subsystem already has an interface for this purpose and the CRC can be accessed e.g. via debugfs:
"
$ echo auto > /sys/kernel/debug/dri/1/crtc-0/crc/control $ cat /sys/kernel/debug/dri/1/crtc-0/crc/data 0x0000408c 0xa4e5cdd8 0x0000408d 0x72f537b4 " The per-frame CRC can be used by userspace e.g. during automated testing, to verify that whatever buffer was sent to be scanned out was actually scanned out of the LCDIF correctly.
--- drivers/gpu/drm/mxsfb/mxsfb_drv.c | 15 +++++++- drivers/gpu/drm/mxsfb/mxsfb_drv.h | 3 ++ drivers/gpu/drm/mxsfb/mxsfb_kms.c | 59 ++++++++++++++++++++++++++++-- drivers/gpu/drm/mxsfb/mxsfb_regs.h | 1 + 4 files changed, 73 insertions(+), 5 deletions(-)
drivers/gpu/drm/mxsfb/mxsfb_drv.c +13 -2
@@ -9,6 +9,7 @@*/ #include <linux/clk.h> +#include <linux/crc32.h> #include <linux/dma-mapping.h> #include <linux/io.h> #include <linux/module.h>
@@ -52,6 +53,7 @@ static const struct mxsfb_devdata mxsfb_devdata[] = { .hs_wdth_shift = 24, .has_overlay = false, .has_ctrl2 = false, + .has_crc32 = false, }, [MXSFB_V4] = { .transfer_count = LCDC_V4_TRANSFER_COUNT,
@@ -61,6 +63,7 @@ static const struct mxsfb_devdata mxsfb_devdata[] = { .hs_wdth_shift = 18, .has_overlay = false, .has_ctrl2 = true, + .has_crc32 = true, }, [MXSFB_V6] = { .transfer_count = LCDC_V4_TRANSFER_COUNT,
@@ -70,6 +73,7 @@ static const struct mxsfb_devdata mxsfb_devdata[] = { .hs_wdth_shift = 18, .has_overlay = true, .has_ctrl2 = true, + .has_crc32 = true, }, };
@@ -145,12 +149,19 @@ static irqreturn_t mxsfb_irq_handler(int irq, void *data) {struct drm_device *drm = data;struct mxsfb_drm_private *mxsfb = drm->dev_private; -u32 reg; +u32 reg, crc; +u64 vbc; reg =readl (mxsfb->base +LCDC_CTRL1 ); -if (reg &CTRL1_CUR_FRAME_DONE_IRQ ) +if (reg &CTRL1_CUR_FRAME_DONE_IRQ ) {drm_crtc_handle_vblank (&mxsfb->crtc); +if (mxsfb->crc_active) { + crc =readl (mxsfb->base +LCDC_V4_CRC_STAT ); + vbc =drm_crtc_accurate_vblank_count (&mxsfb->crtc); +drm_crtc_add_crc_entry (&mxsfb->crtc, true, vbc, &crc); + } + }writel (CTRL1_CUR_FRAME_DONE_IRQ , mxsfb->base +LCDC_CTRL1 +REG_CLR );
drivers/gpu/drm/mxsfb/mxsfb_drv.h +3 -0
@@ -23,6 +23,7 @@ struct mxsfb_devdata {unsigned int hs_wdth_shift;bool has_overlay;bool has_ctrl2; +bool has_crc32; };struct mxsfb_drm_private {
@@ -44,6 +45,8 @@ struct mxsfb_drm_private {struct drm_encoder encoder;struct drm_connector *connector;struct drm_bridge *bridge; + +bool crc_active; }; static inline struct mxsfb_drm_private *
drivers/gpu/drm/mxsfb/mxsfb_kms.c +56 -3
77 lines not on this page · raw message
drivers/gpu/drm/mxsfb/mxsfb_regs.h +1 -0
@@ -26,6 +26,7 @@#define LCDC_VDCTRL2 0x90#define LCDC_VDCTRL3 0xa0#define LCDC_VDCTRL4 0xb0 +#define LCDC_V4_CRC_STAT 0x1a0#define LCDC_V4_DEBUG0 0x1d0#define LCDC_V3_DEBUG0 0x1f0#define LCDC_AS_CTRL 0x210
Signature · 1 line
2.35.1
Dan Carpenter
build botCC: kbuild-all(a)lists.01.org BCC: lkp(a)intel.com In-Reply-To: <[email protected]> References: <[email protected]> TO: Marek Vasut <[email protected]> TO…
CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
In-Reply-To: <[email protected]>
References: <[email protected]>
TO: Marek Vasut <[email protected]>
TO: dri-devel(a)lists.freedesktop.org
CC: Marek Vasut <[email protected]>
CC: Peng Fan <[email protected]>
CC: Alexander Stein <[email protected]>
CC: robert.foss(a)linaro.org
CC: Laurent Pinchart <[email protected]>
CC: Robby Cai <[email protected]>
CC: Sam Ravnborg <[email protected]>
Hi Marek,
I love your patch! Perhaps something to improve:
[auto build test WARNING on drm/drm-next]
[also build test WARNING on drm-exynos/exynos-drm-next drm-intel/for-linux-next drm-tip/drm-tip tegra-drm/drm/tegra/for-next v5.18-rc1 next-20220408] [cannot apply to airlied/drm-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Marek-Vasut/drm-mxsfb-Implement-LCDIF-scanout-CRC32-support/20220410-071222 base: git://anongit.freedesktop.org/drm/drm drm-next
:::::: branch date: 28 hours ago
:::::: commit date: 28 hours ago
config: i386-randconfig-m021-20220411 (https://download.01.org/0day-ci/archive/20220411/202204111055.ETeht46W-lkp(a)intel.com/config)
compiler: gcc-11 (Debian 11.2.0-19) 11.2.0
If you fix the issue, kindly add following tag as appropriate
smatch warnings:drivers/gpu/drm/mxsfb/mxsfb_kms.c:444 mxsfb_crtc_set_crc_source() warn: variable dereferenced before check 'crtc' (see line 442)
vim +/crtc +444 drivers/gpu/drm/mxsfb/mxsfb_kms.c
ae1ed009328193 Laurent Pinchart 2020-07-27 439
5797982b2ba894 Marek Vasut 2022-04-10 440 static int mxsfb_crtc_set_crc_source(struct drm_crtc *crtc, const char *source)
5797982b2ba894 Marek Vasut 2022-04-10 441 {
5797982b2ba894 Marek Vasut 2022-04-10 @442 struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(crtc->dev);
5797982b2ba894 Marek Vasut 2022-04-10 443
5797982b2ba894 Marek Vasut 2022-04-10 @444 if (!crtc)
5797982b2ba894 Marek Vasut 2022-04-10 445 return -ENODEV;
5797982b2ba894 Marek Vasut 2022-04-10 446
5797982b2ba894 Marek Vasut 2022-04-10 447 if (source && strcmp(source, "auto") == 0)
5797982b2ba894 Marek Vasut 2022-04-10 448 mxsfb->crc_active = true;
5797982b2ba894 Marek Vasut 2022-04-10 449 else if (!source)
5797982b2ba894 Marek Vasut 2022-04-10 450 mxsfb->crc_active = false;
5797982b2ba894 Marek Vasut 2022-04-10 451 else
5797982b2ba894 Marek Vasut 2022-04-10 452 return -EINVAL;
5797982b2ba894 Marek Vasut 2022-04-10 453
5797982b2ba894 Marek Vasut 2022-04-10 454 return 0;
5797982b2ba894 Marek Vasut 2022-04-10 455 }
5797982b2ba894 Marek Vasut 2022-04-10 456 Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp