[VSP-Tests PATCH 6/7] vsp-lib: Support late queuing of buffers in yavta

2018-12-04 Thread Kieran Bingham
Provide the pass-through option of --queue-late to vsp-runner, to request
that yavta will queue frames after the stream has started.

Signed-off-by: Kieran Bingham 
---
 scripts/vsp-lib.sh | 4 
 1 file changed, 4 insertions(+)

diff --git a/scripts/vsp-lib.sh b/scripts/vsp-lib.sh
index 9140254c7459..3d2792707d24 100755
--- a/scripts/vsp-lib.sh
+++ b/scripts/vsp-lib.sh
@@ -898,6 +898,7 @@ vsp_runner() {
local count=10
local pause=
local skip=7
+   local queue_late=
 
for option in $* ; do
case $option in
@@ -916,6 +917,8 @@ vsp_runner() {
--skip=*)
skip=${option/--skip=/}
;;
+   --queue-late)
+   queue_late=queue-late
 
*)
return 1
@@ -959,6 +962,7 @@ vsp_runner() {
 
$yavta -c$count -n $buffers ${format:+-f $format} ${size:+-s $size} \
${skip:+--skip $skip} ${file:+--file=$file} ${pause:+-p$pause} \
+   ${queue_late:+--$queue_late} \
$videodev | ./logger.sh $entity >> $logfile
 }
 
-- 
2.17.1



[VSP-Tests PATCH 4/7] vsp-lib: trivial: Fix spelling of Reference

2018-12-04 Thread Kieran Bingham
Signed-off-by: Kieran Bingham 
---
 scripts/vsp-lib.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/vsp-lib.sh b/scripts/vsp-lib.sh
index 56969606382f..cf15a045ea8c 100755
--- a/scripts/vsp-lib.sh
+++ b/scripts/vsp-lib.sh
@@ -95,7 +95,7 @@ vsp1_set_control() {
 }
 
 # -
-# Referance frame generation
+# Reference frame generation
 #
 
 reference_frame() {
-- 
2.17.1



[VSP-Tests PATCH 2/7] tests: Provide copy test to validate 1xN streams

2018-12-04 Thread Kieran Bingham
Validate that a 1xN stream can be read through the RPF and written
through the WPF.

The test framework does not currently support processing images where
the stride does not match the output width - so the testing is currently
limited to testing only the vertical direction in this aspect.

Signed-off-by: Kieran Bingham 
---
 tests/vsp-unit-test-0025.sh | 45 +
 1 file changed, 45 insertions(+)
 create mode 100755 tests/vsp-unit-test-0025.sh

diff --git a/tests/vsp-unit-test-0025.sh b/tests/vsp-unit-test-0025.sh
new file mode 100755
index ..57a1fac6e369
--- /dev/null
+++ b/tests/vsp-unit-test-0025.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+#
+# Test pipelines which have a single pixel dimension. Use a RPF -> WPF
+# pipeline with identical input and output formats to generate our output.
+#
+
+. ./vsp-lib.sh
+
+features="rpf.0 uds wpf.0"
+formats="RGB24 ARGB32"
+
+# Input is directly copied to the output. No change in format or size.
+test_copy() {
+   local format=$1
+   local insize=$2
+
+   test_start "copying $insize in $format"
+
+   pipe_configure rpf-wpf 0 0
+   format_configure rpf-wpf 0 0 $format $insize $format
+
+   vsp_runner rpf.0 &
+   vsp_runner wpf.0
+
+   local result=$(compare_frames)
+
+   test_complete $result
+}
+
+test_main() {
+   local format
+
+   for format in $formats ; do
+   test_copy $format 1024x768
+   test_copy $format 128x128
+   test_copy $format 128x1
+
+   # Skipped : Test framework does not yet support strides != width
+   #test_copy $format 1x128
+   done
+}
+
+test_init $0 "$features"
+test_run
-- 
2.17.1



[VSP-Tests PATCH 5/7] vsp-lib: Allow forcing pixel perfect comparisons

2018-12-04 Thread Kieran Bingham
Provide a means for the tester to request pixel perfect matches on tests.
This can be either through setting the environment variable VSP_PIXEL_PERFECT, 
or
by passing either '-p' or '--pixel-perfect' on the test command line.

Signed-off-by: Kieran Bingham 
---
 scripts/vsp-lib.sh | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/scripts/vsp-lib.sh b/scripts/vsp-lib.sh
index cf15a045ea8c..9140254c7459 100755
--- a/scripts/vsp-lib.sh
+++ b/scripts/vsp-lib.sh
@@ -287,7 +287,11 @@ compare_frames() {
params=${params//)/_}
params=$pipe-$in_fmt-$out_fmt-$size$params
 
-   if [ x$__vsp_pixel_perfect != xtrue ] ; then
+   # The system can hint when pixel-perfection is not supported,
+   # however the user can override to force this requirement with
+   # VSP_PIXEL_PERFECT=1 in the environment or by passing -p, or
+   # --pixel-perfect on the commandline.
+   if [ x$__vsp_pixel_perfect != xtrue -a x$VSP_PIXEL_PERFECT != x1 ] ; 
then
method=fuzzy
fi
 
@@ -1113,10 +1117,15 @@ case $1 in
export VSP_KEEP_FRAMES=1
shift
;;
+   -p|--pixel-perfect)
+   export VSP_PIXEL_PERFECT=1
+   shift
+   ;;
-h|--help)
echo "$(basename $0): VSP Test library"
echo "  -x|--debug  enable shell debug"
echo "  -k|--keep-frameskeep generated and captured frames"
+   echo "  -p|--pixel-perfect  frames must match with pixel 
perfection"
echo "  -h|--help   this help"
exit
shift
-- 
2.17.1



[VSP-Tests PATCH 3/7] vsp-lib: Provide command line argument parsing

2018-12-04 Thread Kieran Bingham
Extend the vsp-lib to support command line parsing for all tests.  The
arguments parsed here should be common to all tests, and initially
provide shell level verbose debug output, and the option to easily keep
frames output by the VSP1.

Signed-off-by: Kieran Bingham 
---
 scripts/vsp-lib.sh | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/scripts/vsp-lib.sh b/scripts/vsp-lib.sh
index 0f3992a7827e..56969606382f 100755
--- a/scripts/vsp-lib.sh
+++ b/scripts/vsp-lib.sh
@@ -1094,3 +1094,37 @@ test_complete() {
 test_run() {
test_main | ./logger.sh error >> $logfile
 }
+
+# 
--
+# Common argument parsing
+#
+# non-recognised arguments are restored, to allow tests to implement their own
+# parsing if necessary.
+
+POSITIONAL=()
+while [[ $# -gt 0 ]]
+do
+case $1 in
+   -x|--debug)
+   set -x;
+   shift
+   ;;
+   -k|--keep-frames)
+   export VSP_KEEP_FRAMES=1
+   shift
+   ;;
+   -h|--help)
+   echo "$(basename $0): VSP Test library"
+   echo "  -x|--debug  enable shell debug"
+   echo "  -k|--keep-frameskeep generated and captured frames"
+   echo "  -h|--help   this help"
+   exit
+   shift
+   ;;
+   *)# unknown option
+   POSITIONAL+=("$1") # save it in an array for later
+   shift # past argument
+   ;;
+esac
+done
+set -- "${POSITIONAL[@]}" # restore positional parameters
-- 
2.17.1



[VSP-Tests PATCH 7/7] vsp-lib: Reset controls to defaults on each test run

2018-12-04 Thread Kieran Bingham
Some of our tests set flipping and rotation controls, and the VSP cell
can be used again by later tests. If these controls are not reset, then
that operation is applied to later tests incorrectly causing that test
to fail.

In an ideal world, tests should clean up after themselves, and leave the
system in a known state. However the world is not ideal and we would not
be able to guarantee any previous system state before a test was run
anyway. Therefore it is more effective to reset state at the beginning
of a test.

To repair this - reset all control values to their defaults at the start
of every test during test_init()

Signed-off-by: Kieran Bingham 
---
 scripts/vsp-lib.sh | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/scripts/vsp-lib.sh b/scripts/vsp-lib.sh
index 3d2792707d24..33442816f208 100755
--- a/scripts/vsp-lib.sh
+++ b/scripts/vsp-lib.sh
@@ -94,6 +94,14 @@ vsp1_set_control() {
$yavta --no-query -w "$control $value" $subdev | ./logger.sh "$entity" 
>> $logfile
 }
 
+vsp1_reset_controls() {
+   local entity=$1
+   local subdev=$(vsp1_entity_subdev $entity)
+
+   echo "Resetting controls on $subdev" | ./logger.sh "$entity" >> $logfile
+   $yavta --no-query --reset-controls $subdev | ./logger.sh "$entity" >> 
$logfile
+}
+
 # -
 # Reference frame generation
 #
@@ -1082,6 +1090,9 @@ test_init() {
dev=$(vsp1_device $mdev)
echo "Using device $mdev ($dev)" | ./logger.sh config >> $logfile
 
+   # Reset any rotation or flipping controls
+   vsp1_reset_controls wpf.0
+
vsp_runner=./vsp-runner.sh
 }
 
-- 
2.17.1



[VSP-Tests PATCH 1/7] tests: add pseudo platform test

2018-12-04 Thread Kieran Bingham
Provide an initial test which can run as part of the test suite.
This test will report the platform and kernel version, along with
the identified paths of required utilities.

This will aid in ensuring that required tools are available on a
running platform - and report the kernel and platform details in
any test suite output for clarification of results.

Signed-off-by: Kieran Bingham 
---
 tests/vsp-unit-test-.sh | 20 
 1 file changed, 20 insertions(+)
 create mode 100755 tests/vsp-unit-test-.sh

diff --git a/tests/vsp-unit-test-.sh b/tests/vsp-unit-test-.sh
new file mode 100755
index ..144cfc677b32
--- /dev/null
+++ b/tests/vsp-unit-test-.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+# Report testing conditions
+
+model=`cat /sys/firmware/devicetree/base/model`
+
+echo "Test Conditions:"
+
+function check_all() {
+   echo "  Platform: " "$model"
+   echo "  Kernel release: " `uname -r`
+   echo "  convert: " `which convert`
+   echo "  compare: " `which compare`
+   echo "  killall: " `which killall`
+   echo "  raw2rgbpnm: " `which raw2rgbpnm`
+   echo "  stress: " `which stress`
+   echo "  yavta: " `which yavta`
+}
+
+check_all | column -ts ":"
-- 
2.17.1



[VSP-Tests PATCH 0/7] Reset controls and unloved patches

2018-12-04 Thread Kieran Bingham
Update the VSP-Test suite library to use yavta's (new) --reset-controls
feature to ensure each test starts with a clean environment.

This prevents tests being affected by previous settings to controls such
as rotate or flip.

Also, the series reposts other unloved patches which have gone either
un-reviewed or are still not yet integrated.


Kieran Bingham (7):
  tests: add pseudo platform test
  tests: Provide copy test to validate 1xN streams
  vsp-lib: Provide command line argument parsing
  vsp-lib: trivial: Fix spelling of Reference
  vsp-lib: Allow forcing pixel perfect comparisons
  vsp-lib: Support late queuing of buffers in yavta
  vsp-lib: Reset controls to defaults on each test run

 scripts/vsp-lib.sh  | 62 +++--
 tests/vsp-unit-test-.sh | 20 
 tests/vsp-unit-test-0025.sh | 45 +++
 3 files changed, 125 insertions(+), 2 deletions(-)
 create mode 100755 tests/vsp-unit-test-.sh
 create mode 100755 tests/vsp-unit-test-0025.sh

-- 
2.17.1



Re: [GIT PULL FOR renesas-drivers] pinchartl-media/v4l2/vsp1/next

2018-09-14 Thread Kieran Bingham
Hi Geert,

On 14/09/18 21:50, Kieran Bingham wrote:
> Hi Geert,
> 
> Please consider including this release in renesas-drivers.
> 
> --
> Regards
> 
> Kieran
> 
> The following changes since commit 78cf8c842c111df656c63b5d04997ea4e40ef26a:
> 
>   media: drxj: fix spelling mistake in fall-through annotations (2018-09-12 
> 11:21:52 -0400)
> 
> are available in the Git repository at:
> 
>   git://linuxtv.org/pinchartl/media.git pinchartl-media/v4l2/vsp1/next

Sorry - my local reference to laurent's branch snuck in there.

This should of course be:

   git://linuxtv.org/pinchartl/media.git v4l2/vsp1/next

> 
> for you to fetch changes up to 4a6fcd855184d0d928bb833f1062bd19a0c9b57a:
> 
>   media: vsp1: Document max_width restriction on UDS (2018-09-14 17:35:25 
> +0300)
> 
> --------
> Kieran Bingham (5):
>   MAINTAINERS: VSP1: Add co-maintainer
>   media: vsp1: Remove artificial minimum width/height limitation
>   media: vsp1: use periods at the end of comment sentences
>   media: vsp1: Document max_width restriction on SRU
>   media: vsp1: Document max_width restriction on UDS
> 
> Koji Matsuoka (1):
>   media: vsp1: Fix YCbCr planar formats pitch calculation
> 
> Laurent Pinchart (2):
>   media: vsp1: Fix vsp1_regs.h license header
>   media: vsp1: Update LIF buffer thresholds
> 
>  MAINTAINERS   |  1 +
>  drivers/media/platform/vsp1/vsp1_brx.c|  4 ++--
>  drivers/media/platform/vsp1/vsp1_drm.c| 11 ++-
>  drivers/media/platform/vsp1/vsp1_drv.c|  6 +++---
>  drivers/media/platform/vsp1/vsp1_entity.c |  2 +-
>  drivers/media/platform/vsp1/vsp1_lif.c| 29 +
>  drivers/media/platform/vsp1/vsp1_regs.h   |  2 +-
>  drivers/media/platform/vsp1/vsp1_rpf.c|  4 ++--
>  drivers/media/platform/vsp1/vsp1_sru.c|  7 ++-
>  drivers/media/platform/vsp1/vsp1_uds.c| 14 +++---
>  drivers/media/platform/vsp1/vsp1_video.c  |  9 +++--
>  drivers/media/platform/vsp1/vsp1_wpf.c|  2 +-
>  include/media/vsp1.h  |  2 +-
>  13 files changed, 67 insertions(+), 26 deletions(-)
> 

-- 
Regards
--
Kieran


[GIT PULL FOR renesas-drivers] du/2018q3

2018-09-14 Thread Kieran Bingham
Hi Geert,

Please consider including this release in renesas-drivers.

Please note - unlike the previous VSP1 pull request, which is a direct request
of Laurent's v4l2/vsp1/next, this one is actually a branch on my tree. 

This pull request covers both Laurent's drm/du/next and one extra commit in my
tree. It's a temporary fix. I expect either Laurent will pick up the revert, or
we may have a better fix by the time you do a renesas-drivers release.

Please feel free to drop this and use Laurent's updated drm/du/next branch as
necessary.


--
Regards

Kieran

The following changes since commit 2dc7bad71cd310dc94d1c9907909324dd2b0618f:

  Merge tag 'drm-misc-next-2018-09-13' of 
git://anongit.freedesktop.org/drm/drm-misc into drm-next (2018-09-14 09:43:16 
+1000)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/kbingham/rcar.git du/2018q3

for you to fetch changes up to ebf4cb8acd5fff350500dae25a8e868c79e25b40:

  drm: rcar-du: Revert "drm: rcar-du: Use __drm_atomic_helper_plane_reset 
instead of copying the logic" (2018-09-14 20:50:19 +0100)


Jacopo Mondi (3):
  drm: rcar-du: Improve non-DPLL clock selection
  drm: rcar-du: Rename and document dpll_ch field
  drm: rcar-du: Write ESCR and OTAR as CRTC registers

Kieran Bingham (7):
  MAINTAINERS: rcar-du: Add co-maintainer
  drm: rcar-du: Support interlaced video output through vsp1
  drm: rcar-du: Refactor Feature and Quirk definitions
  drm: rcar-du: Add interlaced feature flag
  drm: rcar-du: Update Gen3 output limitations
  drm: rcar-du: Remove packed VYUY support
  drm: rcar-du: Revert "drm: rcar-du: Use __drm_atomic_helper_plane_reset 
instead of copying the logic"

Koji Matsuoka (1):
  drm: rcar-du: Add support for missing pixel formats

Kuninori Morimoto (3):
  drm: shmobile: convert to SPDX identifiers
  drm: panel-lvds: convert to SPDX identifiers
  drm: rcar-du: Convert to SPDX identifiers

Laurent Pinchart (3):
  MAINTAINERS: Update tree location for the Renesas DRM drivers
  drm: rcar-du: Rework clock configuration based on hardware limits
  drm: rcar-du: Update framebuffer pitch and alignment limits for Gen3

Sergei Shtylyov (3):
  dt-bindings: display: renesas: du: document R8A77980 bindings
  dt-bindings: display: renesas: lvds: document R8A77980 bindings
  drm: rcar-du: lvds: add R8A77980 support

 .../bindings/display/bridge/renesas,lvds.txt   |   1 +
 .../devicetree/bindings/display/renesas,du.txt |   2 +
 MAINTAINERS|   3 +-
 drivers/gpu/drm/panel/panel-lvds.c |   6 +-
 drivers/gpu/drm/rcar-du/Kconfig|   1 +
 drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 181 +
 drivers/gpu/drm/rcar-du/rcar_du_crtc.h |   6 +-
 drivers/gpu/drm/rcar-du/rcar_du_drv.c  |  44 ++---
 drivers/gpu/drm/rcar-du/rcar_du_drv.h  |  18 +-
 drivers/gpu/drm/rcar-du/rcar_du_encoder.c  |   6 +-
 drivers/gpu/drm/rcar-du/rcar_du_encoder.h  |   6 +-
 drivers/gpu/drm/rcar-du/rcar_du_group.c|   6 +-
 drivers/gpu/drm/rcar-du/rcar_du_group.h|   6 +-
 drivers/gpu/drm/rcar-du/rcar_du_kms.c  |  87 +++---
 drivers/gpu/drm/rcar-du/rcar_du_kms.h  |   6 +-
 drivers/gpu/drm/rcar-du/rcar_du_plane.c|  12 +-
 drivers/gpu/drm/rcar-du/rcar_du_plane.h|   6 +-
 drivers/gpu/drm/rcar-du/rcar_du_regs.h |  13 +-
 drivers/gpu/drm/rcar-du/rcar_du_vsp.c  |  14 +-
 drivers/gpu/drm/rcar-du/rcar_du_vsp.h  |   6 +-
 drivers/gpu/drm/rcar-du/rcar_dw_hdmi.c |   6 +-
 drivers/gpu/drm/rcar-du/rcar_lvds.c|   1 +
 drivers/gpu/drm/rcar-du/rcar_lvds_regs.h   |   5 +-
 drivers/gpu/drm/shmobile/Kconfig   |   1 +
 drivers/gpu/drm/shmobile/shmob_drm_backlight.c |   6 +-
 drivers/gpu/drm/shmobile/shmob_drm_backlight.h |   6 +-
 drivers/gpu/drm/shmobile/shmob_drm_crtc.c  |   6 +-
 drivers/gpu/drm/shmobile/shmob_drm_crtc.h  |   6 +-
 drivers/gpu/drm/shmobile/shmob_drm_drv.c   |   6 +-
 drivers/gpu/drm/shmobile/shmob_drm_drv.h   |   6 +-
 drivers/gpu/drm/shmobile/shmob_drm_kms.c   |   6 +-
 drivers/gpu/drm/shmobile/shmob_drm_kms.h   |   6 +-
 drivers/gpu/drm/shmobile/shmob_drm_plane.c |   6 +-
 drivers/gpu/drm/shmobile/shmob_drm_plane.h |   6 +-
 drivers/gpu/drm/shmobile/shmob_drm_regs.h  |   6 +-
 include/linux/platform_data/shmob_drm.h|   6 +-
 36 files changed, 261 insertions(+), 254 deletions(-)


[GIT PULL FOR renesas-drivers] pinchartl-media/v4l2/vsp1/next

2018-09-14 Thread Kieran Bingham
Hi Geert,

Please consider including this release in renesas-drivers.

--
Regards

Kieran

The following changes since commit 78cf8c842c111df656c63b5d04997ea4e40ef26a:

  media: drxj: fix spelling mistake in fall-through annotations (2018-09-12 
11:21:52 -0400)

are available in the Git repository at:

  git://linuxtv.org/pinchartl/media.git pinchartl-media/v4l2/vsp1/next

for you to fetch changes up to 4a6fcd855184d0d928bb833f1062bd19a0c9b57a:

  media: vsp1: Document max_width restriction on UDS (2018-09-14 17:35:25 +0300)


Kieran Bingham (5):
  MAINTAINERS: VSP1: Add co-maintainer
  media: vsp1: Remove artificial minimum width/height limitation
  media: vsp1: use periods at the end of comment sentences
  media: vsp1: Document max_width restriction on SRU
  media: vsp1: Document max_width restriction on UDS

Koji Matsuoka (1):
  media: vsp1: Fix YCbCr planar formats pitch calculation

Laurent Pinchart (2):
  media: vsp1: Fix vsp1_regs.h license header
  media: vsp1: Update LIF buffer thresholds

 MAINTAINERS   |  1 +
 drivers/media/platform/vsp1/vsp1_brx.c|  4 ++--
 drivers/media/platform/vsp1/vsp1_drm.c| 11 ++-
 drivers/media/platform/vsp1/vsp1_drv.c|  6 +++---
 drivers/media/platform/vsp1/vsp1_entity.c |  2 +-
 drivers/media/platform/vsp1/vsp1_lif.c| 29 +
 drivers/media/platform/vsp1/vsp1_regs.h   |  2 +-
 drivers/media/platform/vsp1/vsp1_rpf.c|  4 ++--
 drivers/media/platform/vsp1/vsp1_sru.c|  7 ++-
 drivers/media/platform/vsp1/vsp1_uds.c| 14 +++---
 drivers/media/platform/vsp1/vsp1_video.c  |  9 +++--
 drivers/media/platform/vsp1/vsp1_wpf.c|  2 +-
 include/media/vsp1.h  |  2 +-
 13 files changed, 67 insertions(+), 26 deletions(-)


Re: [PATCH 2/3] drm: rcar-du: Add pixel format support

2018-09-14 Thread Kieran Bingham
Hi Laurent,

On 14/09/18 12:11, Laurent Pinchart wrote:
> Hi Kieran,
> 
> Thank you for the patch.
> 
> How about renaming the subject line to "Add support for missing pixel 
> formats" 
> ?
> 

Ack.

> On Friday, 31 August 2018 21:12:58 EEST Kieran Bingham wrote:
>> From: Koji Matsuoka 
>>
>> This patch supports pixel format of RGB332, ARGB, XRGB,
>> BGR888, RGB888, BGRA, BGRX and YVYU.
>> VYUY pixel format is not supported by H/W specification.
>>
>> Signed-off-by: Koji Matsuoka 
>> Signed-off-by: Kieran Bingham 
>>
>> ---
>>
>> This patch does not remove existing support for multiplanar YVUY, even
>> though the hardware does not explicitly provide it, because we support
>> it through software by swapping the plane buffers.
>>
>>  drivers/gpu/drm/rcar-du/rcar_du_kms.c | 32 +++
>>  1 file changed, 32 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.c
>> b/drivers/gpu/drm/rcar-du/rcar_du_kms.c index 7c7aff8cdf77..d1bd174ec893
>> 100644
>> --- a/drivers/gpu/drm/rcar-du/rcar_du_kms.c
>> +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.c
>> @@ -124,6 +124,38 @@ static const struct rcar_du_format_info
>> rcar_du_format_infos[] = { .fourcc = DRM_FORMAT_YVU444,
>>  .bpp = 24,
>>  .planes = 3,
>> +}, {
>> +.fourcc = DRM_FORMAT_RGB332,
>> +.bpp = 8,
>> +.planes = 1,
>> +}, {
>> +.fourcc = DRM_FORMAT_ARGB,
>> +.bpp = 16,
>> +.planes = 1,
>> +}, {
>> +.fourcc = DRM_FORMAT_XRGB,
>> +.bpp = 16,
>> +.planes = 1,
>> +}, {
>> +.fourcc = DRM_FORMAT_BGR888,
>> +.bpp = 24,
>> +.planes = 1,
>> +}, {
>> +.fourcc = DRM_FORMAT_RGB888,
>> +.bpp = 24,
>> +.planes = 1,
>> +}, {
>> +.fourcc = DRM_FORMAT_BGRA,
>> +.bpp = 32,
>> +.planes = 1,
>> +}, {
>> +.fourcc = DRM_FORMAT_BGRX,
>> +.bpp = 32,
>> +.planes = 1,
>> +}, {
>> +.fourcc = DRM_FORMAT_YVYU,
>> +.bpp = 16,
>> +.planes = 1,
>>  },
>>  };
> 
> I would list the RGB formats first, followed by the packed YUV format, and 
> then the multiplanar YUV formats. With this changed,
> 
Ack.

> Reviewed-by: Laurent Pinchart 
> 
> If you're fine with the changes there's no need to resubmit.


That's fine by me.

Thanks

--
Kieran




Salvator-XS-M3N SRU/HGT/COPY test fail

2018-08-31 Thread Kieran Bingham
Hi Laurent,

I've had some interesting failures on the VSP1 tests on the M3-N board.

- vsp-unit-test-0015.sh
Testing SRU scaling from 1024x768 to 1024x768 in RGB24: fail
Testing SRU scaling from 1024x768 to 2048x1536 in RGB24: fail
Testing SRU scaling from 1024x768 to 1024x768 in YUV444M: fail
Testing SRU scaling from 1024x768 to 2048x1536 in YUV444M: fail

- vsp-unit-test-0023.sh
Testing histogram HGT with hue areas
0,255,255,255,255,255,255,255,255,255,255,255: fail
Testing histogram HGT with hue areas
0,40,40,80,80,120,120,160,160,200,200,255: fail
Testing histogram HGT with hue areas
220,40,40,80,80,120,120,160,160,200,200,220: fail
Testing histogram HGT with hue areas
0,10,50,60,100,110,150,160,200,210,250,255: fail
Testing histogram HGT with hue areas
10,20,50,60,100,110,150,160,200,210,230,240: fail
Testing histogram HGT with hue areas
240,20,60,80,100,120,140,160,180,200,210,220: fail
- vsp-unit-test-0025.sh
Testing copying 1024x768 in RGB24: fail
Testing copying 128x128 in RGB24: fail
Testing copying 128x1 in RGB24: diff: /tmp/frame-*.bin: No such file or
directory
mv: cannot stat '/tmp/frame-*.bin': No such file or directory
fail
Testing copying 1024x768 in ARGB32: fail
Testing copying 128x128 in ARGB32: fail
Testing copying 128x1 in ARGB32: diff: /tmp/frame-*.bin: No such file or
directory
mv: cannot stat '/tmp/frame-*.bin': No such file or directory
fail


The frames on test 15 are 'flipped' vertically, while on test 25, they
are rotated.

Please see the reference image and resulting output at:
https://ibb.co/fjPpkK
https://ibb.co/mfybXz

I'm sure I haven't seen this issue on the H3, so this could be an M3-N
specific issue.

Oddly, a later test (25, which I've posted earlier today) fails, because
the images are rotated 90* to the left ... So it seems like there is
certainly some uninitialised or confused state on the ROT bits somehow.

For reference, this is on my branch du/2018q3 on my rcar.git repo.
Commit 889e6d80c9f0eef433cfa1828c9a9d32a78479c2 which is based upon your
drm/du/next branch.


-- 
Regards
--
Kieran


[VSP-Tests: PATCH v2] tests: Provide copy test to validate 1xN streams

2018-08-31 Thread Kieran Bingham
Validate that a 1xN stream can be read through the RPF and written
through the WPF.

The test framework does not currently support processing images where
the stride does not match the output width - so the testing is currently
limited to testing only the vertical direction in this aspect.

Signed-off-by: Kieran Bingham 
---
 tests/vsp-unit-test-0025.sh | 45 +
 1 file changed, 45 insertions(+)
 create mode 100755 tests/vsp-unit-test-0025.sh

diff --git a/tests/vsp-unit-test-0025.sh b/tests/vsp-unit-test-0025.sh
new file mode 100755
index ..57a1fac6e369
--- /dev/null
+++ b/tests/vsp-unit-test-0025.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+#
+# Test pipelines which have a single pixel dimension. Use a RPF -> WPF
+# pipeline with identical input and output formats to generate our output.
+#
+
+. ./vsp-lib.sh
+
+features="rpf.0 uds wpf.0"
+formats="RGB24 ARGB32"
+
+# Input is directly copied to the output. No change in format or size.
+test_copy() {
+   local format=$1
+   local insize=$2
+
+   test_start "copying $insize in $format"
+
+   pipe_configure rpf-wpf 0 0
+   format_configure rpf-wpf 0 0 $format $insize $format
+
+   vsp_runner rpf.0 &
+   vsp_runner wpf.0
+
+   local result=$(compare_frames)
+
+   test_complete $result
+}
+
+test_main() {
+   local format
+
+   for format in $formats ; do
+   test_copy $format 1024x768
+   test_copy $format 128x128
+   test_copy $format 128x1
+
+   # Skipped : Test framework does not yet support strides != width
+   #test_copy $format 1x128
+   done
+}
+
+test_init $0 "$features"
+test_run
-- 
2.17.1



[VSP-Tests: PATCH] vsp-lib: Provide command line argument parsing

2018-08-31 Thread Kieran Bingham
Extend the vsp-lib to support command line parsing for all tests.  The
arguments parsed here should be common to all tests, and initially
provide shell level verbose debug output, and the option to easily keep
frames output by the VSP1.

Signed-off-by: Kieran Bingham 
---
 scripts/vsp-lib.sh | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/scripts/vsp-lib.sh b/scripts/vsp-lib.sh
index 0f3992a7827e..6a0f4af5eaf5 100755
--- a/scripts/vsp-lib.sh
+++ b/scripts/vsp-lib.sh
@@ -1094,3 +1094,37 @@ test_complete() {
 test_run() {
test_main | ./logger.sh error >> $logfile
 }
+
+# 
--
+# Common argument parsing
+#
+# non-recognised arguements are restored, to allow tests
+# to implement their own parsing if necessary.
+
+POSITIONAL=()
+while [[ $# -gt 0 ]]
+do
+case $1 in
+   -x|--debug)
+   set -x;
+   shift
+   ;;
+   -k|--keep-frames)
+   export VSP_KEEP_FRAMES=1
+   shift
+   ;;
+   -h|--help)
+   echo "$(basename $0): VSP Test library"
+   echo "  -x|--debug  enable shell debug"
+   echo "  -k|--keep-frameskeep generated and captured frames"
+   echo "  -h|--help   this help"
+   exit
+   shift
+   ;;
+   *)# unknown option
+   POSITIONAL+=("$1") # save it in an array for later
+   shift # past argument
+   ;;
+esac
+done
+set -- "${POSITIONAL[@]}" # restore positional parameters
-- 
2.17.1



[VSP-Tests: PATCH] tests: Provide copy test to validate 1xN streams

2018-08-31 Thread Kieran Bingham
Validate that a 1xN stream can be read through the RPF and written
through the WPF.

The test framework does not currently support processing images where
the stride does not match the output width - so the testing is currently
limited to testing only the vertical direction in this aspect.

Signed-off-by: Kieran Bingham 
---
 tests/vsp-unit-test-0025.sh | 45 +
 1 file changed, 45 insertions(+)
 create mode 100755 tests/vsp-unit-test-0025.sh

diff --git a/tests/vsp-unit-test-0025.sh b/tests/vsp-unit-test-0025.sh
new file mode 100755
index ..5c8980c40d89
--- /dev/null
+++ b/tests/vsp-unit-test-0025.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+#
+# Test pipelines which have a single pixel dimension. Use a RPF -> UDS -> WPF
+# pipeline with identical input and output formats to generate our output.
+#
+
+. ./vsp-lib.sh
+
+features="rpf.0 uds wpf.0"
+formats="RGB24 ARGB32"
+
+# Input is directly copied to the output. No change in format or size.
+test_copy() {
+   local format=$1
+   local insize=$2
+
+   test_start "copying $insize in $format"
+
+   pipe_configure rpf-wpf 0 0
+   format_configure rpf-wpf 0 0 $format $insize $format
+
+   vsp_runner rpf.0 &
+   vsp_runner wpf.0
+
+   local result=$(compare_frames)
+
+   test_complete $result
+}
+
+test_main() {
+   local format
+
+   for format in $formats ; do
+   test_copy $format 1024x768
+   test_copy $format 128x128
+   test_copy $format 128x1
+
+   # Skipped : Test framework does not yet support strides != width
+   #test_copy $format 1x128
+   done
+}
+
+test_init $0 "$features"
+test_run
-- 
2.17.1



[VSP-Tests: PATCH] tests: add pseudo platform test

2018-08-31 Thread Kieran Bingham
From: Kieran Bingham 

Provide an initial test which can run as part of the test suite.
This test will report the platform and kernel version, along with
the identified paths of required utilities.

This will aid in ensuring that required tools are available on a
running platform - and report the kernel and platform details in
any test suite output for clarification of results.

Signed-off-by: Kieran Bingham 
---

This addition allows extra information to be recorded about the system
when running the tests in a batch (or in future automated testing)

Ideally - we would report the version of each tool as well, allowing any
issues to be fully recreated.


 tests/vsp-unit-test-.sh | 20 
 1 file changed, 20 insertions(+)
 create mode 100755 tests/vsp-unit-test-.sh

diff --git a/tests/vsp-unit-test-.sh b/tests/vsp-unit-test-.sh
new file mode 100755
index ..144cfc677b32
--- /dev/null
+++ b/tests/vsp-unit-test-.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+# Report testing conditions
+
+model=`cat /sys/firmware/devicetree/base/model`
+
+echo "Test Conditions:"
+
+function check_all() {
+   echo "  Platform: " "$model"
+   echo "  Kernel release: " `uname -r`
+   echo "  convert: " `which convert`
+   echo "  compare: " `which compare`
+   echo "  killall: " `which killall`
+   echo "  raw2rgbpnm: " `which raw2rgbpnm`
+   echo "  stress: " `which stress`
+   echo "  yavta: " `which yavta`
+}
+
+check_all | column -ts ":"
-- 
2.17.1



Re: Regarding VIN test(cvbs capture:- PAL resolution)

2018-08-29 Thread Kieran Bingham
Hi Biju,

On 29/08/18 12:19, Biju Das wrote:
> Hi Kieran,
> 
> Thanks for the feedback.
> 



>> Could you check to see the output of any of the following is correct:
>>
>> media-ctl -d /dev/media1 --get-v4l2 "'adv748x 4-0070 afe':0"
>> .. (and 1,2,3,4,5,6 if necessary)
>> media-ctl -d /dev/media1 --get-v4l2 "'adv748x 4-0070 afe':7"
> 
> Please find the output.
> 
> root@salvator-x:~# media-ctl -d /dev/media1 --get-v4l2 "'adv748x 4-0070 
> afe':0"
> root@salvator-x:~# media-ctl -d /dev/media1 --get-v4l2 "'adv748x 4-0070 
> afe':1"
> root@salvator-x:~# media-ctl -d /dev/media1 --get-v4l2 "'adv748x 4-0070 
> afe':2"
> root@salvator-x:~# media-ctl -d /dev/media1 --get-v4l2 "'adv748x 4-0070 
> afe':3"
> root@salvator-x:~# media-ctl -d /dev/media1 --get-v4l2 "'adv748x 4-0070 
> afe':4"
> root@salvator-x:~# media-ctl -d /dev/media1 --get-v4l2 "'adv748x 4-0070 
> afe':5"
> root@salvator-x:~# media-ctl -d /dev/media1 --get-v4l2 "'adv748x 4-0070 
> afe':6"
> root@salvator-x:~# media-ctl -d /dev/media1 --get-v4l2 "'adv748x 4-0070 
> afe':7"
> root@salvator-x:~# media-ctl -d /dev/media1 --get-v4l2 "'adv748x 4-0070 
> afe':8"
> [ 2589.712578] ##afe->curr_norm=1000 V4L2_STD_525_60=f900
> [fmt:UYVY8_2X8/720x240 field:alternate]
> 


Aha - OK - I'm sorry - I was telling you the wrong way to detect.

Please see Niklas' recent e-mail :)

--
Kieran


Re: Regarding VIN test(cvbs capture:- PAL resolution)

2018-08-29 Thread Kieran Bingham
Hi Biju,

On 29/08/18 11:41, Biju Das wrote:
> Hi All,
> 
>  
> 
> I started testing vin on R-Car Gen3(CVBS  input from DVD player
> connected to R-Car M3-W,kernel:-renesas-devel-20180827-4.19-rc1)
> 
> based on the information present in https://elinux.org/R-Car/Tests:rcar-vin.
> 
>  
> 
> Looks like PAL is not supported.
> 
> When i execute the command, "media-ctl -d /dev/media1 --get-v4l2
> "'adv748x 4-0070 afe':8"" on target
> 

This looks like a bug in the documentation at
https://elinux.org/R-Car/Tests:rcar-vin. It's 'getting' the format of
the source pad of the AFE.


> , i get "[fmt:UYVY8_2X8/720x240 field:alternate]" instead of
> "[fmt:UYVY8_2X8/720x288 field:alternate]"

Hrm ... this is getting the format of the source pad of the AFE - which
is manually set, but the get_fmt should be done on the SINK pad of the
AFE. (ideally on the correct input port)

Could you check to see the output of any of the following is correct:

media-ctl -d /dev/media1 --get-v4l2 "'adv748x 4-0070 afe':0"
.. (and 1,2,3,4,5,6 if necessary)
media-ctl -d /dev/media1 --get-v4l2 "'adv748x 4-0070 afe':7"


I don't recall which pad is used on the Salvator-XS - and the media
control output doesn't make that clear - so we should improve that.


Anyway, then - Could you try setting the PAL format manually ?

>  media-ctl -d /dev/media0 -V "'adv748x 4-0070 afe':8 [fmt:UYVY8_2X8/720x288 
> field:alternate]"
>  media-ctl -d /dev/media0 -V "'rcar_csi2 fea8.csi2':1 
> [fmt:UYVY8_2X8/720x288 field:alternate]"

I thought the ADV748x can tell the difference between PAL/NTSC and so it
should have detected it, so perhaps there is a bug there - but you do
have to manually propagate the format you want regardless.



> 
> root@salvator-x:~# media-ctl -d /dev/media1 --get-v4l2 "'adv748x 4-0070
> afe':8"
> 
> [   28.708110] ##afe->curr_norm=1000 V4L2_STD_525_60=f900
> 
>     [fmt:UYVY8_2X8/720x240 field:alternate]
> 
>  
> 
> Q1) Have any one observed this issue?
> 

I thought most of my testing was on PAL actually. - But it's a long time
since I've tested the ADV748x CVBS input.


> So I created a patch[2], based on [1]. With this, I get proper PAL
> resolution(720x576)
> 
>  
> 
> root@salvator-x:~# media-ctl -d /dev/media1 --get-v4l2 "'adv748x 4-0070
> afe':8"
> 
> [   42.472582] ##afe->curr_norm=ff V4L2_STD_525_60=f900
> 
>     [fmt:UYVY8_2X8/720x288 field:alternate]
> 
>  
> 
> Q2) Is there any reason for not upstreaming the patch [1]?

Yes, unfortunately - the V4L2 spec does not allow us to automatically
detect and then set the format.

The choice of which format to set must belong to userspace.


> [1]
> https://kernel.googlesource.com/pub/scm/linux/kernel/git/horms/renesas-bsp/+/e0740949ae6b964da8bf1e88b504405276652aa7%5E%21/#F0
> 
>  
> 
> [2]
> 
> --- a/drivers/media/i2c/adv748x/adv748x-afe.c
> 
> +++ b/drivers/media/i2c/adv748x/adv748x-afe.c
> 
>  
> 
> @ -352,6 +353,7 @@ static int adv748x_afe_get_format(struct v4l2_subdev *sd,
> 
> {
> 
>     struct adv748x_afe *afe = adv748x_sd_to_afe(sd);
> 
>     struct v4l2_mbus_framefmt *mbusformat;
> 
> +   v4l2_std_id std = 0;
> 
> /* It makes no sense to get the format of the analog sink pads */
> 
>     if (sdformat->pad != ADV748X_AFE_SOURCE)
> 
> @@ -361,6 +363,9 @@ static int adv748x_afe_get_format(struct v4l2_subdev
> *sd,
> 
>     mbusformat = v4l2_subdev_get_try_format(sd, cfg,
> sdformat->pad);
> 
>     sdformat->format = *mbusformat;
> 
>     } else {
> 
> +   /* Set std_id automatically */
> 
> +   adv748x_afe_querystd(sd, );
> 
> +   adv748x_afe_s_std(sd, std);
> 
>     adv748x_afe_fill_format(afe, >format);
> 
>     adv748x_afe_propagate_pixelrate(afe);
> 
>    
> 
>  
> 
> Regards,
> 
> Biju
> 
> 
> 
> 
> Renesas Electronics Europe Ltd, Dukes Meadow, Millboard Road, Bourne
> End, Buckinghamshire, SL8 5FH, UK. Registered in England & Wales under
> Registered No. 04586709.
> 



Re: [PATCH v2 5/7] arm64: dts: renesas: r8a77965: Add CAN{0,1} placeholder nodes

2018-08-23 Thread Kieran Bingham
Hi Eugeniu,

On 23/08/18 18:14, Eugeniu Rosca wrote:
> Dear reviewers,
> 
> On Thu, Aug 23, 2018 at 11:01:46AM +0200, Geert Uytterhoeven wrote:
>> Hi Sergei,
>>
>> On Thu, Aug 23, 2018 at 10:56 AM Sergei Shtylyov
>>  wrote:
>>> On 8/23/2018 11:52 AM, Geert Uytterhoeven wrote:
>> According to R-Car Gen3 HW manual rev1.00, R-Car M3-N has two CAN
>> interfaces, similar to H3, M3-W and other SoCs from the same family.
>>
>> Add CAN placeholder nodes to avoid below DTC errors:
>> Error: arch/arm64/boot/dts/renesas/ulcb-kf.dtsi:19.1-6 Label or path 
>> can0 not found
>> Error: arch/arm64/boot/dts/renesas/ulcb-kf.dtsi:25.1-6 Label or path 
>> can1 not found
>>
>> These errors occur *after* the addition of r8a77965-m3nulcb-kf.dts.
>> Fix them beforehand.
>>
>> CAN support is inspired from below commits:
>>   - v4.7 commit 308b7e4ba62e ("arm64: dts: r8a7795: Add CAN support")
>>   - v4.11 commit 909c16252415 ("arm64: dts: r8a7796: Add CAN support")
>>   - v4.12 commit bec0948e810f ("arm64: dts: r8a7796: Add reset control 
>> properties")
>>
>> Signed-off-by: Eugeniu Rosca 
>>
>> --- a/arch/arm64/boot/dts/renesas/r8a77965.dtsi
>> +++ b/arch/arm64/boot/dts/renesas/r8a77965.dtsi
>> @@ -656,6 +656,22 @@
>>status = "disabled";
>>};
>>
>> + can0: can@e6c3 {
>> + compatible = "renesas,can-r8a77965",
>> +  "renesas,rcar-gen3-can";
>> + reg = <0 0xe6c3 0 0x1000>;
>> + /* placeholder */
>> + status = "disabled";
>> + };
>
> This is probably more detail than is needed for a placeholder, but it
> looks correct so I think this is fine.

 Indeed. Adding the "compatible" properties means they're no longer
 placeholders, and will be probed by the driver, possibly leading to
 undefined behavior.
>>>
>>> I don't think the disabled device nodes are actually probed.
>>
>> They will be by ulcb-kf.dtsi, after the addition of
>> r8a77965-m3nulcb-kf.dts, cfr.
>> the errors and rationale documented in the commit message.
> 
> I took some time to examine the "52. Controller Area Network Interface
> (CAN interface)" chapter of HW SoC manual rev1.00 in detail and there is
> no difference mentioned between the SoCs (H3, M3-W, M3-N, D3, E3) which
> implement the two CAN (non-FD) interfaces. This is confirmed by the
> perfectly symmetrical can{0,1} configuration present in the H3,
> M3-W and D3 device tree sources:
> 
> $ git grep -l can0 -- arch/arm64/boot/dts/renesas/r8*dtsi
> arch/arm64/boot/dts/renesas/r8a7795.dtsi
> arch/arm64/boot/dts/renesas/r8a7796.dtsi
> arch/arm64/boot/dts/renesas/r8a77995.dtsi


The problem is, until it's tested - we don't actually know it works.
Even 'identical' chips can have different changes between the revisions.



> So, to be honest, in my opinion, besides consuming time arguing about
> what a placeholder DTS node is (btw, commits [1] and [2] do include a
> compatible string while adding a "placeholder" node),

[1] is a special case. It's not actually going to probe a driver.

sources/linux$ git grep secure-ram
arch/arm/boot/dts/dra7.dtsi:  compatible = "ti,secure-ram";




[2] is also a different case:

You can see in the patch that the 'placeholder' is used in the same
commit by sun9i-a80-cubieboard4.dts and sun9i-a80-optimus.dts



> we also force
> users to 'git blame' multiple times to reconstruct the history of CAN
> controller nodes on M3-N, while for H3, M3-W and D3 a single commit was
> enough to add the functionality.
> 
> That said, I don't see any dmesg differences on M3NULCB between having
> and not having the compatible string in the can{0,1} nodes.
> 
>> Hence please limit the placeholders to the absolute required minimum,
>> and thus drop the "compatible" and "status" properties.
> 
> My understanding is that the lack of status is equivalent with
> 'status = "okay"' (i.e. enable the node), so I don't really see why
> 'status = "disabled"' should hurt for a placeholder, especially seeing
> a high number of commits [3] using 'status = "disabled"' by default. 

It's not so much the 'status' field that hurts in this patch, but the
compatible matching.

The file r8a7795.dtsi is a SoC level description. It tries to describe
all the features provided by that SoC. But all of those features may not
be brought out on the "board", and so many are disabled by default.

 - Essentially 'status = "disabled";'
is like saying - This node is good - but don't use it.


It's then up to the board file (Salvator-XS.dtb, ULCB.dtb
YourBoardHere.dtb ...) to enable the features that are available.

That's the case here in the KingFisher board.

The ulcb-kf.dtsi will override the CAN nodes and set 'status = Okay' to
enable the devices available on the KF board:

>  {
> 

Re: [PATCH v2 2/7] dt-bindings: can: rcar_can: document r8a77965 can support

2018-08-17 Thread Kieran Bingham
Hi Eugeniu,

On 17/08/18 16:56, Eugeniu Rosca wrote:
> Hello Kieran,
> 
> On Fri, Aug 17, 2018 at 02:44:25PM +0100, Kieran Bingham wrote:
>> Hi Eugeniu
>>
>> Thank you for the patch.
>>
>> On 12/08/18 14:31, Eugeniu Rosca wrote:
>>> Document the support for rcar_can on R8A77965 SoC devices.
>>> Add R8A77965 to the list of SoCs which require the "assigned-clocks" and
>>> "assigned-clock-rates" properties (thanks, Sergei). Rewrap text.
>>
>> I don't think you needed to say you rewrapped the text in the commit log
>> - but it's fine :)
> 
> IMHO "Rewrap text" is pretty much from the same category as "no
> functional change was intended".

Indeed, but in this instance - there was a functional change. You
modified the paragraph.  In fact, mentioning that you have rewrapped the
text, thus implying that you have made no functional change might cause
a reviewer not to look deeper at the actual differences?


> As a reviewer, I would take these
> details in the commit description any day (and sometimes I would NAK a
> patch which lacks these details), since they precisely express the goals
> set by the author and make reviewer's life easier.
> 
> But, of course, preferences vary and therefore I won't elaborate on that
> too much.

If this was a separate hunk, which you had re-wrapped without making a
change to - I would absolutely agree with you here. The 'rewrapping'
should be mentioned in the commit message, but this in relation to a
paragraph which you had modified.

IMO - if you modify a paragraph of text, rewrapping to make sure it fits
the constraints is part of that modification ... but ... yes we are
debating minor details and preferences here ;) - I have no objection to
you mentioning it.

Regards

Kieran

> 
>>
>>> Signed-off-by: Eugeniu Rosca 
>>
>> Reviewed-by: Kieran Bingham 
>>
> 
> Best regards,
> Eugeniu.
> 



Re: [PATCH v2 5/7] arm64: dts: renesas: r8a77965: Add CAN{0,1} placeholder nodes

2018-08-17 Thread Kieran Bingham
Hi Eugeniu,

Thank you for the patch,

On 12/08/18 14:31, Eugeniu Rosca wrote:
> According to R-Car Gen3 HW manual rev1.00, R-Car M3-N has two CAN
> interfaces, similar to H3, M3-W and other SoCs from the same family.
> 
> Add CAN placeholder nodes to avoid below DTC errors:
> Error: arch/arm64/boot/dts/renesas/ulcb-kf.dtsi:19.1-6 Label or path can0 not 
> found
> Error: arch/arm64/boot/dts/renesas/ulcb-kf.dtsi:25.1-6 Label or path can1 not 
> found
> 
> These errors occur *after* the addition of r8a77965-m3nulcb-kf.dts.
> Fix them beforehand.
> 
> CAN support is inspired from below commits:
>  - v4.7 commit 308b7e4ba62e ("arm64: dts: r8a7795: Add CAN support")
>  - v4.11 commit 909c16252415 ("arm64: dts: r8a7796: Add CAN support")
>  - v4.12 commit bec0948e810f ("arm64: dts: r8a7796: Add reset control 
> properties")
> 
> Signed-off-by: Eugeniu Rosca 

Reviewed-by: Kieran Bingham 


> ---
> Changes in v2:
>  - [Kieran Bingham] Improved commit description:
>- Referenced the newer HW manual rev1.00 instead of rev0.55E.
>- Kept the "true story" behind the patch. Just made it more clear.
>  - [Geert Uytterhoeven] Replaced CAN0 and CAN1 nodes with placeholders
>(no CAN testing was done to validate the DTS configuration).
> ---
>  arch/arm64/boot/dts/renesas/r8a77965.dtsi | 16 
>  1 file changed, 16 insertions(+)
> 
> diff --git a/arch/arm64/boot/dts/renesas/r8a77965.dtsi 
> b/arch/arm64/boot/dts/renesas/r8a77965.dtsi
> index 486aecacb22a..4da479d3c226 100644
> --- a/arch/arm64/boot/dts/renesas/r8a77965.dtsi
> +++ b/arch/arm64/boot/dts/renesas/r8a77965.dtsi
> @@ -656,6 +656,22 @@
>   status = "disabled";
>   };
>  
> + can0: can@e6c3 {
> + compatible = "renesas,can-r8a77965",
> +  "renesas,rcar-gen3-can";
> + reg = <0 0xe6c3 0 0x1000>;
> + /* placeholder */
> + status = "disabled";
> + };

This is probably more detail than is needed for a placeholder, but it
looks correct so I think this is fine.

--
Kieran



> +
> + can1: can@e6c38000 {
> + compatible = "renesas,can-r8a77965",
> +  "renesas,rcar-gen3-can";
> + reg = <0 0xe6c38000 0 0x1000>;
> + /* placeholder */
> + status = "disabled";
> + };
> +
>   pwm0: pwm@e6e3 {
>   compatible = "renesas,pwm-r8a77965", "renesas,pwm-rcar";
>   reg = <0 0xe6e3 0 8>;
> 



Re: [PATCH 12/14] arm64: dts: renesas: r8a77965: add CAN support

2018-08-17 Thread Kieran Bingham
Hi Eugeniu,

On 06/08/18 21:14, Eugeniu Rosca wrote:
> Hi Kieran,
> 
> On Mon, Aug 06, 2018 at 12:11:22PM +0100, Kieran Bingham wrote:
>> Hi Eugeniu,
>>
>> On 05/08/18 00:11, Eugeniu Rosca wrote:
>>> According to R-Car Gen3 HW manual rev0.55E, R-Car M3-N has two CAN
>>
>> rev 0.55E sounds like rather an old version of this document. Do you
>> have access to the later rev1.00 release?
> 
> Thanks for this feedback. I was able to find the newer version.
> 
>>
>> (Not an issue for this patch itself, I can confirm that revision 1.00
>> still confirms M3-N CAN support)
>>
>>> interfaces, similar to H3, M3-W and other SoCs from the same family.
>>>
>>> Add CAN nodes to avoid below r8a77965-ulcb-kf.dtb build failure:
>>> Error: arch/arm64/boot/dts/renesas/ulcb-kf.dtsi:19.1-6 Label or path can0 
>>> not found
>>> Error: arch/arm64/boot/dts/renesas/ulcb-kf.dtsi:25.1-6 Label or path can1 
>>> not found
>>
>> Again, this is somewhat referencing the future, as (in patch sequence)
>> the file "r8a77965-ulcb-kf.dts" does not yet exist, so does not really
>> need to be mentioned here.
> 
> Will remove the "r8a77965-ulcb-kf.dtb" line from commit description.
> 
>>
>>
>>> CAN support is inspired from below commits:
>>>  - v4.7 commit 308b7e4ba62e ("arm64: dts: r8a7795: Add CAN support")
>>>  - v4.11 commit 909c16252415 ("arm64: dts: r8a7796: Add CAN support")
>>>  - v4.12 commit bec0948e810f ("arm64: dts: r8a7796: Add reset control 
>>> properties")
>>>
>>> Signed-off-by: Eugeniu Rosca 
>>> ---
>>>  arch/arm64/boot/dts/renesas/r8a77965.dtsi | 32 
>>> 
>>>  1 file changed, 32 insertions(+)
>>>
>>> diff --git a/arch/arm64/boot/dts/renesas/r8a77965.dtsi 
>>> b/arch/arm64/boot/dts/renesas/r8a77965.dtsi
>>> index 486aecacb22a..cb8f8573d9ef 100644
>>> --- a/arch/arm64/boot/dts/renesas/r8a77965.dtsi
>>> +++ b/arch/arm64/boot/dts/renesas/r8a77965.dtsi
>>> @@ -656,6 +656,38 @@
>>> status = "disabled";
>>> };
>>>  
>>> +   can0: can@e6c3 {
>>> +   compatible = "renesas,can-r8a77965",
>>> +"renesas,rcar-gen3-can";
>>> +   reg = <0 0xe6c3 0 0x1000>;
>>> +   interrupts = ;
>>> +   clocks = < CPG_MOD 916>,
>>> +  < CPG_CORE R8A77965_CLK_CANFD>,
>>> +  <_clk>;
>>> +   clock-names = "clkp1", "clkp2", "can_clk";
>>> +   assigned-clocks = < CPG_CORE R8A77965_CLK_CANFD>;
>>> +   assigned-clock-rates = <4000>;
>>
>> This doesn't look right. Sections 52A.2 has a note stating:
>>
>> CANFD? must be set as follows.
>> R-Car H3, R-Car M3-W, R-Car M3-N, R-Car V3M, R-Car V3H, R-Car E3: 80 (MHz)
>>
>> R-Car D3: 40 (MHz)
>>
>>
>> Could you verify / check in case this value should be 80MHz?
> 
> Are you sure section "52A. CAN-FD" is the right one for describing the
> CAN (non-FD) nodes? For non-FD CAN there is another chapter called
> "52. Controller Area Network Interface (CAN interface)". Since the
> latter doesn't point out any differences between M3-W and M3-N, I
> re-used the M3-W (r8A7796.dtsi) configuration.

My apologies - It looks like I had got the wrong section.

> 
> FWIW, r8a7795 (H3), r8a7796 (M3) and r8a77995 (D3) all currently
> (v4.18-rc8) use the same "assigned-clock-rates" value for can0
> and can1 nodes:
> 
> $ git grep -E -A 10 "can[01]:" -- arch/arm64/boot/dts/renesas | grep 
> assigned-clock-rates
> arch/arm64/boot/dts/renesas/r8a7795.dtsi- assigned-clock-rates = 
> <4000>;
> arch/arm64/boot/dts/renesas/r8a7795.dtsi- assigned-clock-rates = 
> <4000>;
> arch/arm64/boot/dts/renesas/r8a7796.dtsi- assigned-clock-rates = 
> <4000>;
> arch/arm64/boot/dts/renesas/r8a7796.dtsi- assigned-clock-rates = 
> <4000>;
> arch/arm64/boot/dts/renesas/r8a77995.dtsi-assigned-clock-rates = 
> <4000>;
> arch/arm64/boot/dts/renesas/r8a77995.dtsi-assigned-clock-rates = 
> <4000>;
> 
> Anyway, given that this patch only intended to avoid the "make dtbs"
> failure and given that any CAN test

Re: [PATCH v2 2/7] dt-bindings: can: rcar_can: document r8a77965 can support

2018-08-17 Thread Kieran Bingham
Hi Eugeniu

Thank you for the patch.

On 12/08/18 14:31, Eugeniu Rosca wrote:
> Document the support for rcar_can on R8A77965 SoC devices.
> Add R8A77965 to the list of SoCs which require the "assigned-clocks" and
> "assigned-clock-rates" properties (thanks, Sergei). Rewrap text.

I don't think you needed to say you rewrapped the text in the commit log
- but it's fine :)


> Signed-off-by: Eugeniu Rosca 

Reviewed-by: Kieran Bingham 

> ---
> Changes in v2:
>  - [Kieran Bingham] Simplified commit description. Rewrapped text.
>  - [Sergei Shtylyov] Replaced footnotes with inline text.
>  - Pushed all dt-bindings patches to the beginning of the series.
> ---
>  Documentation/devicetree/bindings/net/can/rcar_can.txt | 10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/net/can/rcar_can.txt 
> b/Documentation/devicetree/bindings/net/can/rcar_can.txt
> index 94a7f33ac5e9..60daa878c9a2 100644
> --- a/Documentation/devicetree/bindings/net/can/rcar_can.txt
> +++ b/Documentation/devicetree/bindings/net/can/rcar_can.txt
> @@ -13,6 +13,7 @@ Required properties:
> "renesas,can-r8a7794" if CAN controller is a part of R8A7794 SoC.
> "renesas,can-r8a7795" if CAN controller is a part of R8A7795 SoC.
> "renesas,can-r8a7796" if CAN controller is a part of R8A7796 SoC.
> +   "renesas,can-r8a77965" if CAN controller is a part of R8A77965 
> SoC.
> "renesas,rcar-gen1-can" for a generic R-Car Gen1 compatible 
> device.
> "renesas,rcar-gen2-can" for a generic R-Car Gen2 or RZ/G1
> compatible device.
> @@ -28,11 +29,10 @@ Required properties:
>  - pinctrl-0: pin control group to be used for this controller.
>  - pinctrl-names: must be "default".
>  
> -Required properties for "renesas,can-r8a7795" and "renesas,can-r8a7796"
> -compatible:
> -In R8A7795 and R8A7796 SoCs, "clkp2" can be CANFD clock. This is a div6 clock
> -and can be used by both CAN and CAN FD controller at the same time. It needs 
> to
> -be scaled to maximum frequency if any of these controllers use it. This is 
> done
> +Required properties for R8A7795, R8A7796 and R8A77965:
> +For the denoted SoCs, "clkp2" can be CANFD clock. This is a div6 clock and 
> can
> +be used by both CAN and CAN FD controller at the same time. It needs to be
> +scaled to maximum frequency if any of these controllers use it. This is done
>  using the below properties:
>  
>  - assigned-clocks: phandle of clkp2(CANFD) clock.
> 



Re: [PATCH] arm64: dts: renesas: salvator-common: adv748x: Override secondary addresses

2018-08-10 Thread Kieran Bingham
Hi Simon,

On 10/08/18 13:01, Simon Horman wrote:
> On Tue, Aug 07, 2018 at 04:59:33PM +0100, Kieran Bingham wrote:
>> Ensure that the ADV748x device addresses do not conflict, and group them
>> together (visually in i2cdetect)
> 
> Hi Kieran,
> 
> could you help me out with some pointers on how to correlate this
> with the HW documentation?

Not easily :) - Except for the 'main' address (0x70), these are not
addresses documented by the datasheet. . The driver supports the DT providing the slave pages to
allocate. One day the I2C framework might allow us to 'request' an
unused page :D

I performed a scan on the Salvator-X, (i2cdetect -r -y 4) and identified
a region of unused I2C address space to allocate the 12 pages so that
they did not conflict.

In particular, the address <0x30> which is the default for the CBUS page
conflicts with the default address of the OV10635 used by the GMSL
cameras on the same bus, and so I needed to move that one.

To make the effects clear, (and the i2cdetect reporting more obvious) I
chose to reassign all of the movable pages so that it is clear they are
from the same device.

Rather annoyingly it's difficult to map a slave page back to it's driver
due to the fact that it gets registered as a 'dummy' driver, so keeping
the related addresses together is quite valuable.

As soon as I get some free cycles, I plan to look at being able to map
extra driver information to dummy I2C registrations to make it easier to
identify who owns the address :)

--
Regards

Kieran





>>
>> Signed-off-by: Kieran Bingham 
>> ---
>>  arch/arm64/boot/dts/renesas/salvator-common.dtsi | 5 -
>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/arm64/boot/dts/renesas/salvator-common.dtsi 
>> b/arch/arm64/boot/dts/renesas/salvator-common.dtsi
>> index 5cfb9b99de89..2eba743c5c3f 100644
>> --- a/arch/arm64/boot/dts/renesas/salvator-common.dtsi
>> +++ b/arch/arm64/boot/dts/renesas/salvator-common.dtsi
>> @@ -414,7 +414,10 @@
>>  
>>  video-receiver@70 {
>>  compatible = "adi,adv7482";
>> -reg = <0x70>;
>> +reg = <0x70 0x71 0x72 0x73 0x74 0x75
>> +   0x60 0x61 0x62 0x63 0x64 0x65>;
>> +reg-names = "main", "dpll", "cp", "hdmi", "edid", "repeater",
>> +"infoframe", "cbus", "cec", "sdp", "txa", "txb" ;
>>  
>>  #address-cells = <1>;
>>  #size-cells = <0>;
>> -- 
>> 2.17.1
>>

-- 
Regards
--
Kieran


[PATCH] arm64: dts: renesas: salvator-common: adv748x: Override secondary addresses

2018-08-07 Thread Kieran Bingham
Ensure that the ADV748x device addresses do not conflict, and group them
together (visually in i2cdetect)

Signed-off-by: Kieran Bingham 
---
 arch/arm64/boot/dts/renesas/salvator-common.dtsi | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/renesas/salvator-common.dtsi 
b/arch/arm64/boot/dts/renesas/salvator-common.dtsi
index 5cfb9b99de89..2eba743c5c3f 100644
--- a/arch/arm64/boot/dts/renesas/salvator-common.dtsi
+++ b/arch/arm64/boot/dts/renesas/salvator-common.dtsi
@@ -414,7 +414,10 @@
 
video-receiver@70 {
compatible = "adi,adv7482";
-   reg = <0x70>;
+   reg = <0x70 0x71 0x72 0x73 0x74 0x75
+  0x60 0x61 0x62 0x63 0x64 0x65>;
+   reg-names = "main", "dpll", "cp", "hdmi", "edid", "repeater",
+   "infoframe", "cbus", "cec", "sdp", "txa", "txb" ;
 
#address-cells = <1>;
#size-cells = <0>;
-- 
2.17.1



Re: [GIT PULL FOR renesas-drivers] gmsl/for-renesas-drivers

2018-08-07 Thread Kieran Bingham
Hi Geert

On 07/08/18 13:04, Geert Uytterhoeven wrote:
> Hi Kieran,
> 
> On Tue, Aug 7, 2018 at 1:25 PM Kieran Bingham
>  wrote:
>> Please consider including this release in renesas-drivers.
>>
>> This brings in our GMSL developments for inclusion in renesas-drivers, but 
>> does
>> not by default enable any FAKRA overlays. Anyone wishing to try out the GMSL
>> work must manually configure their specific camera configuration.
>>
>> Please note, this branch is based on a merge commit of linux-media/master and
>> Sakari's VC branch, and includes Niklas' conversions for adv748x to support 
>> VC
>> which are still in development as a pre-requisite.
>>
>> --
>> Regards
>>
>> Kieran
>>
>> The following changes since commit 12f336c88090fb8004736fd4329184326a49673b:
>>
>>   media: sh_mobile_ceu: convert to SPDX identifiers (2018-08-03 16:06:08 
>> -0400)
>>
>> are available in the Git repository at:
>>
>>   git://git.kernel.org/pub/scm/linux/kernel/git/kbingham/rcar.git 
>> gmsl/for-renesas-drivers
>>
>> for you to fetch changes up to a6764190f2671dbcf86a59d42957bbcf56bb9301:
>>
>>   media: i2c: max9286: [POC] Power down GPIO lines to enable the V3M cameras 
>> (2018-08-07 12:08:12 +0100)
> 
> Thank you, this merges cleanly into today's linux-next.

\o/

> 
> Let's see how that works out in two weeks ;-)

Well - I'm sure it'll be fine .. unless Sakari updates his branch...
then it won't be fine ... :)


> Gr{oetje,eeting}s,
> 
> Geert
> 

-- 
Regards
--
Kieran


[GIT PULL FOR renesas-drivers] gmsl/for-renesas-drivers

2018-08-07 Thread Kieran Bingham
Hi Geert,

Please consider including this release in renesas-drivers.

This brings in our GMSL developments for inclusion in renesas-drivers, but does
not by default enable any FAKRA overlays. Anyone wishing to try out the GMSL
work must manually configure their specific camera configuration.

Please note, this branch is based on a merge commit of linux-media/master and
Sakari's VC branch, and includes Niklas' conversions for adv748x to support VC
which are still in development as a pre-requisite.

--
Regards

Kieran

The following changes since commit 12f336c88090fb8004736fd4329184326a49673b:

  media: sh_mobile_ceu: convert to SPDX identifiers (2018-08-03 16:06:08 -0400)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/kbingham/rcar.git 
gmsl/for-renesas-drivers

for you to fetch changes up to a6764190f2671dbcf86a59d42957bbcf56bb9301:

  media: i2c: max9286: [POC] Power down GPIO lines to enable the V3M cameras 
(2018-08-07 12:08:12 +0100)


Jacopo Mondi (1):
  dt-bindings: media: i2c: Add bindings for IMI RDACM20

Kieran Bingham (6):
  Merge remote-tracking branch 'sailus/vc' into gmsl/base
  media: i2c: Add MAX9286 driver
  media: i2c: Add RDACM20 driver
  arm64: dts: renesas: eagle: Provide MAX9286 GMSL deserialiser
  arm64: dts: renesas: eagle: Provide Eagle FAKRA dynamic overlay
  media: i2c: max9286: [POC] Power down GPIO lines to enable the V3M cameras

Laurent Pinchart (6):
  media: entity: Add has_route entity operation
  media: entity: Add media_has_route() function
  media: entity: Use routing information during graph traversal
  v4l: subdev: Add [GS]_ROUTING subdev ioctls and operations
  dt-bindings: media: i2c: Add bindings for Maxim Integrated MAX9286
  arm64: dts: renesas: salvator-x: Add MAX9286 expansion board

Niklas Söderlund (10):
  rcar-vin: use pad as the starting point for a pipeline
  rcar-csi2: use frame description information to configure CSI-2 bus
  rcar-csi2: add get_routing support
  adv748x: csi2: add module param for virtual channel
  adv748x: csi2: add translation from pixelcode to CSI-2 datatype
  adv748x: csi2: implement get_frame_desc
  adv748x: csi2: only allow formats on sink pads
  adv748x: csi2: add get_routing support
  adv748x: afe: add routing support
  arm64: dts: renesas: eagle: enable VIN

Sakari Ailus (26):
  media: entity: Use pad as a starting point for graph walk
  media: entity: Use pads instead of entities in the media graph walk stack
  media: entity: Walk the graph based on pads
  v4l: mc: Start walk from a specific pad in use count calculation
  media: entity: Move the pipeline from entity to pads
  media: entity: Use pad as the starting point for a pipeline
  media: entity: Swap pads if route is checked from source to sink
  media: entity: Skip link validation for pads to which there is no route to
  media: entity: Add an iterator helper for connected pads
  media: entity: Add only connected pads to the pipeline
  media: entity: Add debug information in graph walk route check
  media: entity: Look for indirect routes
  v4l: subdev: compat: Implement handling for VIDIOC_SUBDEV_[GS]_ROUTING
  v4l: subdev: Take routing information into account in link validation
  v4l: subdev: Improve link format validation debug messages
  v4l: mc: Add an S_ROUTING helper function for power state changes
  v4l: Add bus type to frame descriptors
  v4l: Add CSI-2 bus configuration to frame descriptors
  v4l: Add stream to frame descriptor
  smiapp: Add MIPI CSI-2 data type definitions
  smiapp: Add smiapp_has_quirk() to tell whether a quirk is implemented
  media: Add media bus codes for 8-bit SMIAPP embedded data
  v4l: Add format definitions for 8-, 10-, 12- and 14-bit SMIA embedded data
  smiapp: Support frame descriptors
  smiapp: Provide a way to differentiate sub-device ops
  smiapp: Add MUX and metadata sub-devices for embedded data

 .../devicetree/bindings/media/i2c/imi,rdacm20.txt  |   62 +
 .../bindings/media/i2c/maxim,max9286.txt   |  180 +++
 .../devicetree/bindings/vendor-prefixes.txt|1 +
 Documentation/media/kapi/mc-core.rst   |   15 +-
 MAINTAINERS|   20 +
 arch/arm64/boot/dts/renesas/eagle-fakra.dtsi   |  131 +++
 arch/arm64/boot/dts/renesas/r8a77970-eagle.dts |  136 +++
 .../arm64/boot/dts/renesas/salvator-x-max9286.dtsi |  391 +++
 drivers/media/i2c/Kconfig  |   22 +
 drivers/media/i2c/Makefile |2 +
 drivers/media/i2c/adv748x/adv748x-afe.c|   65 ++
 drivers/media/i2c/adv748x/adv748x-core.c   |   10 +
 drivers/media/i2c/adv748x/adv748x-csi2.c   |   80 +-
 drivers/media/i2c/adv748x/adv748x.h

Re: [PATCH 12/14] arm64: dts: renesas: r8a77965: add CAN support

2018-08-06 Thread Kieran Bingham
Hi Eugeniu,

On 05/08/18 00:11, Eugeniu Rosca wrote:
> According to R-Car Gen3 HW manual rev0.55E, R-Car M3-N has two CAN

rev 0.55E sounds like rather an old version of this document. Do you
have access to the later rev1.00 release?

(Not an issue for this patch itself, I can confirm that revision 1.00
still confirms M3-N CAN support)

> interfaces, similar to H3, M3-W and other SoCs from the same family.
> 
> Add CAN nodes to avoid below r8a77965-ulcb-kf.dtb build failure:
> Error: arch/arm64/boot/dts/renesas/ulcb-kf.dtsi:19.1-6 Label or path can0 not 
> found
> Error: arch/arm64/boot/dts/renesas/ulcb-kf.dtsi:25.1-6 Label or path can1 not 
> found

Again, this is somewhat referencing the future, as (in patch sequence)
the file "r8a77965-ulcb-kf.dts" does not yet exist, so does not really
need to be mentioned here.


> CAN support is inspired from below commits:
>  - v4.7 commit 308b7e4ba62e ("arm64: dts: r8a7795: Add CAN support")
>  - v4.11 commit 909c16252415 ("arm64: dts: r8a7796: Add CAN support")
>  - v4.12 commit bec0948e810f ("arm64: dts: r8a7796: Add reset control 
> properties")
> 
> Signed-off-by: Eugeniu Rosca 
> ---
>  arch/arm64/boot/dts/renesas/r8a77965.dtsi | 32 
> 
>  1 file changed, 32 insertions(+)
> 
> diff --git a/arch/arm64/boot/dts/renesas/r8a77965.dtsi 
> b/arch/arm64/boot/dts/renesas/r8a77965.dtsi
> index 486aecacb22a..cb8f8573d9ef 100644
> --- a/arch/arm64/boot/dts/renesas/r8a77965.dtsi
> +++ b/arch/arm64/boot/dts/renesas/r8a77965.dtsi
> @@ -656,6 +656,38 @@
>   status = "disabled";
>   };
>  
> + can0: can@e6c3 {
> + compatible = "renesas,can-r8a77965",
> +  "renesas,rcar-gen3-can";
> + reg = <0 0xe6c3 0 0x1000>;
> + interrupts = ;
> + clocks = < CPG_MOD 916>,
> +< CPG_CORE R8A77965_CLK_CANFD>,
> +<_clk>;
> + clock-names = "clkp1", "clkp2", "can_clk";
> + assigned-clocks = < CPG_CORE R8A77965_CLK_CANFD>;
> + assigned-clock-rates = <4000>;

This doesn't look right. Sections 52A.2 has a note stating:

CANFD? must be set as follows.
R-Car H3, R-Car M3-W, R-Car M3-N, R-Car V3M, R-Car V3H, R-Car E3: 80 (MHz)

R-Car D3: 40 (MHz)


Could you verify / check in case this value should be 80MHz?

> + power-domains = < R8A77965_PD_ALWAYS_ON>;
> + resets = < 916>;
> + status = "disabled";
> + };
> +
> + can1: can@e6c38000 {
> + compatible = "renesas,can-r8a77965",
> +  "renesas,rcar-gen3-can";
> + reg = <0 0xe6c38000 0 0x1000>;
> + interrupts = ;
> + clocks = < CPG_MOD 915>,
> +< CPG_CORE R8A77965_CLK_CANFD>,
> +<_clk>;
> + clock-names = "clkp1", "clkp2", "can_clk";
> + assigned-clocks = < CPG_CORE R8A77965_CLK_CANFD>;
> + assigned-clock-rates = <4000>;

Same here of course.


> + power-domains = < R8A77965_PD_ALWAYS_ON>;
> + resets = < 915>;
> + status = "disabled";
> + };
> +
>   pwm0: pwm@e6e3 {
>   compatible = "renesas,pwm-r8a77965", "renesas,pwm-rcar";
>   reg = <0 0xe6e3 0 8>;
> 



Re: [PATCH 11/14] dt-bindings: can: rcar_can: document r8a77965 can support

2018-08-06 Thread Kieran Bingham
Hi Eugeniu

On 05/08/18 00:11, Eugeniu Rosca wrote:
> After adding CAN support to arch/arm64/boot/dts/renesas/r8a77965.dtsi,
> checkpatch complained that the new compatible string
> "renesas,can-r8a77965" is not documented. Fix the warning.
> 

Thanks to the correct ordering of your patches, (you have this one
*before* adding the CAN support to r8a77965) This commit message seems
to be predicting the future somewhat.

Perhaps just a simpler commit message would suffice:

"Document the support for rcar_can on R8A77965 SoC devices."


> Signed-off-by: Eugeniu Rosca 
> ---
>  Documentation/devicetree/bindings/net/can/rcar_can.txt | 10 +++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/net/can/rcar_can.txt 
> b/Documentation/devicetree/bindings/net/can/rcar_can.txt
> index 94a7f33ac5e9..23264451a5a4 100644
> --- a/Documentation/devicetree/bindings/net/can/rcar_can.txt
> +++ b/Documentation/devicetree/bindings/net/can/rcar_can.txt
> @@ -13,6 +13,7 @@ Required properties:
> "renesas,can-r8a7794" if CAN controller is a part of R8A7794 SoC.
> "renesas,can-r8a7795" if CAN controller is a part of R8A7795 SoC.
> "renesas,can-r8a7796" if CAN controller is a part of R8A7796 SoC.
> +   "renesas,can-r8a77965" if CAN controller is a part of R8A77965 
> SoC.
> "renesas,rcar-gen1-can" for a generic R-Car Gen1 compatible 
> device.
> "renesas,rcar-gen2-can" for a generic R-Car Gen2 or RZ/G1
> compatible device.
> @@ -28,9 +29,8 @@ Required properties:
>  - pinctrl-0: pin control group to be used for this controller.
>  - pinctrl-names: must be "default".
>  
> -Required properties for "renesas,can-r8a7795" and "renesas,can-r8a7796"
> -compatible:
> -In R8A7795 and R8A7796 SoCs, "clkp2" can be CANFD clock. This is a div6 clock
> +Required properties for compatibles [A], [B] and [C]:
> +For the denoted SoCs, "clkp2" can be CANFD clock. This is a div6 clock


This paragraph could be rewrapped...

>  and can be used by both CAN and CAN FD controller at the same time. It needs 
> to
>  be scaled to maximum frequency if any of these controllers use it. This is 
> done
>  using the below properties:
> @@ -38,6 +38,10 @@ using the below properties:
>  - assigned-clocks: phandle of clkp2(CANFD) clock.
>  - assigned-clock-rates: maximum frequency of this clock.
>  
> +[A] "renesas,can-r8a7795"
> +[B] "renesas,can-r8a7796"
> +[C] "renesas,can-r8a77965"
> +>  Optional properties:
>  - renesas,can-clock-select: R-Car CAN Clock Source Select. Valid values are:
>   <0x0> (default) : Peripheral clock (clkp1)
> 



Re: [PATCH 04/14] arm64: dts: renesas: r8a7795-es1: ulcb-kf: Use "renesas,ulcb" compatible

2018-08-06 Thread Kieran Bingham
On 06/08/18 11:45, Kieran Bingham wrote:
> Hi Laurent, Eugeniu,
> 
> On 06/08/18 11:42, Laurent Pinchart wrote:
>> Hi Eugeniu,
>>
>> Thank you for the patch.
>>
>> On Sunday, 5 August 2018 02:11:04 EEST Eugeniu Rosca wrote:
>>> Following the recent change in dt-bindings [1], switch from
>>> "renesas,h3ulcb" to "renesas,ulcb" compatible string.
>>>
>>> [1] Documentation/devicetree/bindings/arm/shmobile.txt
>>>
>>> Signed-off-by: Eugeniu Rosca 
>>> ---
>>>  arch/arm64/boot/dts/renesas/r8a7795-es1-ulcb-kf.dts | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/arch/arm64/boot/dts/renesas/r8a7795-es1-ulcb-kf.dts
>>> b/arch/arm64/boot/dts/renesas/r8a7795-es1-ulcb-kf.dts index
>>> 06deb67c36c8..7a5b1dc64090 100644
>>> --- a/arch/arm64/boot/dts/renesas/r8a7795-es1-ulcb-kf.dts
>>> +++ b/arch/arm64/boot/dts/renesas/r8a7795-es1-ulcb-kf.dts
>>> @@ -14,6 +14,6 @@
>>>
>>>  / {
>>> model = "Renesas H3ULCB Kingfisher board based on r8a7795 ES1.x";
>>> -   compatible = "shimafuji,kingfisher", "renesas,h3ulcb",
>>> +   compatible = "shimafuji,kingfisher", "renesas,ulcb",
>>>  "renesas,r8a7795";
>>
>> This is unrelated to your patch, but due to the reason explained in my 
>> review 
>> of 02/14, I think "shimafuji,kingfisher" should include the SoC name.
>>
>> This brings up the topic of how to describe boards that are made of an SoC 
>> "module" board plugged into an expansion "motherboard".
> 
> Isn't it the point that the shimafuji board is agnostic to the SoC on
> the ULCB?
> 
> I presume the Kingfisher board is just the expansion board which would
> be identical regardless of if it was put on an H3 ULCB, or an M3 ULCB?


In fact possibly the interesting point is that the kingfisher as an
expansion board is surely an 'overlay', rather than the board itself ?

>>
>>>  };


Regards

Kieran



Re: [PATCH 04/14] arm64: dts: renesas: r8a7795-es1: ulcb-kf: Use "renesas,ulcb" compatible

2018-08-06 Thread Kieran Bingham
Hi Laurent, Eugeniu,

On 06/08/18 11:42, Laurent Pinchart wrote:
> Hi Eugeniu,
> 
> Thank you for the patch.
> 
> On Sunday, 5 August 2018 02:11:04 EEST Eugeniu Rosca wrote:
>> Following the recent change in dt-bindings [1], switch from
>> "renesas,h3ulcb" to "renesas,ulcb" compatible string.
>>
>> [1] Documentation/devicetree/bindings/arm/shmobile.txt
>>
>> Signed-off-by: Eugeniu Rosca 
>> ---
>>  arch/arm64/boot/dts/renesas/r8a7795-es1-ulcb-kf.dts | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/arm64/boot/dts/renesas/r8a7795-es1-ulcb-kf.dts
>> b/arch/arm64/boot/dts/renesas/r8a7795-es1-ulcb-kf.dts index
>> 06deb67c36c8..7a5b1dc64090 100644
>> --- a/arch/arm64/boot/dts/renesas/r8a7795-es1-ulcb-kf.dts
>> +++ b/arch/arm64/boot/dts/renesas/r8a7795-es1-ulcb-kf.dts
>> @@ -14,6 +14,6 @@
>>
>>  / {
>>  model = "Renesas H3ULCB Kingfisher board based on r8a7795 ES1.x";
>> -compatible = "shimafuji,kingfisher", "renesas,h3ulcb",
>> +compatible = "shimafuji,kingfisher", "renesas,ulcb",
>>   "renesas,r8a7795";
> 
> This is unrelated to your patch, but due to the reason explained in my review 
> of 02/14, I think "shimafuji,kingfisher" should include the SoC name.
> 
> This brings up the topic of how to describe boards that are made of an SoC 
> "module" board plugged into an expansion "motherboard".

Isn't it the point that the shimafuji board is agnostic to the SoC on
the ULCB?

I presume the Kingfisher board is just the expansion board which would
be identical regardless of if it was put on an H3 ULCB, or an M3 ULCB?


> 
>>  };
> 

Regards

Kieran


[PATCH] [HACK] serial: sh-sci: Hard code SCIF clocks

2018-06-15 Thread Kieran Bingham
Hard code the clock rates for the SCI_FCK clock to allow
development of serial passthrough within virtualisation environments
without clock support.

Signed-off-by: Kieran Bingham 
---
 drivers/tty/serial/sh-sci.c | 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index b46b146524ce..729326d25056 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -510,8 +510,27 @@ static void sci_port_enable(struct sci_port *sci_port)
for (i = 0; i < SCI_NUM_CLKS; i++) {
clk_prepare_enable(sci_port->clks[i]);
sci_port->clk_rates[i] = clk_get_rate(sci_port->clks[i]);
+
+   pr_err("sci_port->clk_rates[%u] = %lu\n", i , 
sci_port->clk_rates[i]);
}
-   sci_port->port.uartclk = sci_port->clk_rates[SCI_FCK];
+
+   /*
+[   62.482432] sh-sci e6e68000.serial: BRG: 9600+0 bps using DL 96 SR 32
+[   62.491553] sh-sci e6e68000.serial: Using clk scif for 9600+0 bps
+[   62.500304] sci_port->clk_rates[0] = 6656
+[   62.507276] sci_port->clk_rates[1] = 0
+[   62.513596] sci_port->clk_rates[2] = 26624
+[   62.520570] sci_port->clk_rates[3] = 14745600
+[   62.527720] sh-sci e6e68000.serial: BRG: 115200+0 bps using DL 8 SR 32
+[   62.536802] sh-sci e6e68000.serial: Using clk scif for 115200+0 bps
+[   62.545613] sci_port->clk_rates[0] = 6656
+[   62.552463] sci_port->clk_rates[1] = 0
+[   62.558689] sci_port->clk_rates[2] = 26624
+[   62.565594] sci_port->clk_rates[3] = 14745600
+*/
+
+   // Temporary Hardcode
+   sci_port->port.uartclk = sci_port->clk_rates[SCI_FCK] = 6656;
 }
 
 static void sci_port_disable(struct sci_port *sci_port)
-- 
2.17.1



[PATCH] media: vsp1: Document vsp1_dl_body refcnt

2018-05-28 Thread Kieran Bingham
In commit 2d9445db0ee9 ("media: vsp1: Use reference counting for
bodies"), a new field was introduced to the vsp1_dl_body structure to
account for usage tracking of the body.

Document the newly added field in the kerneldoc.

Signed-off-by: Kieran Bingham <kieran.bing...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_dl.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index d9b9cdd8fbe2..10a24bde2299 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -43,6 +43,7 @@ struct vsp1_dl_entry {
  * struct vsp1_dl_body - Display list body
  * @list: entry in the display list list of bodies
  * @free: entry in the pool free body list
+ * @refcnt: reference tracking for the body
  * @pool: pool to which this body belongs
  * @vsp1: the VSP1 device
  * @entries: array of entries
-- 
2.17.0



Re: [PATCH 2/2] tests: suspend/resume: Increase number of processed frames

2018-05-21 Thread Kieran Bingham
On 21/05/18 10:09, Laurent Pinchart wrote:
> Hi Kieran,
> 
> On Monday, 21 May 2018 11:58:44 EEST Kieran Bingham wrote:
>> On 21/05/18 09:51, Laurent Pinchart wrote:
>>> On Monday, 21 May 2018 11:16:05 EEST Kieran Bingham wrote:
>>>> On 19/05/18 21:34, Laurent Pinchart wrote:
>>>>> The suspend/resume test starts a run of 300 frames and suspends the
>>>>> system one second later. On some SoCs (namely H3 ES2.0) the VSP
>>>>> bandwidth is high enough to complete processing of 300 frames in less
>>>>> than a second. The test thus suspends and resumes the system with the
>>>>> VSP idle instead of running, defeating the purpose of the test.
>>>>>
>>>>> Fix this by increasing the number of frames to process to 1000. The
>>>>> frame count is now passed as an argument to the
>>>>> test_extended_wpf_packing function to ease future changes.
>>>>
>>>> Great idea, to make it easy to update and re-use.
>>>>
>>>>> Signed-off-by: Laurent Pinchart <laurent.pinch...@ideasonboard.com>
>>>>
>>>> Reviewed-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
>>>>
>>>>> ---
>>>>>
>>>>>  tests/vsp-unit-test-0020.sh | 15 ---
>>>>>  1 file changed, 8 insertions(+), 7 deletions(-)
>>>>>
>>>>> diff --git a/tests/vsp-unit-test-0020.sh b/tests/vsp-unit-test-0020.sh
>>>>> index 91f6b167f22e..950c1bebbf2f 100755
>>>>> --- a/tests/vsp-unit-test-0020.sh
>>>>> +++ b/tests/vsp-unit-test-0020.sh
> 
> [snip]
> 
>>>>>  test_hw_pipe() {
>>>>> - test_extended_wpf_packing RGB24
>>>>> + # Run the pipeline for 1000 frames. The suspend action occurs
>>>>> between
>>>>> + # frame #500~#600
>>>>
>>>> I'm not sure it's worth stating when the suspend action occurs, as it's
>>>> variable depending upon the performance of the SoC ... but I'll not
>>>> object to this.
>>>
>>> I agree with you, I'll remove that.
>>>
>>> I think it would make sense to run the pipeline without a limit in the
>>> frame count, and stop streaming after resume. Feel free to give it a try
>>> if you want :-)
>>
>> The question here will be how to we get the frame verification to occur on
>> the 'last N frames'
>>
>> For this, wouldn't we need to extend yavta to support some kind of signal to
>> perform a stream validation at an earlier point and shutdown the stream
>> (probably leaving the count/skip, as maximum durations to run...) And then
>> making sure we knew which frames were actually written out ...
>>
>> I'll leave this ticking in the back of my mind for now :D
> 
> Maybe it will be easier to address when we'll rewrite the tests in Python ? 
> :-)

Possibly - I need to look at Niklas' updates to his vin-tests.

I'm sure there is a lot of potential code - reuse between testing the VIN and
the VSP!.

--
Kieran



>>>>> + test_extended_wpf_packing RGB24 1000
>>>>>  }
> 



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 2/2] tests: suspend/resume: Increase number of processed frames

2018-05-21 Thread Kieran Bingham
On 21/05/18 09:51, Laurent Pinchart wrote:
> Hi Kieran,
> 
> On Monday, 21 May 2018 11:16:05 EEST Kieran Bingham wrote:
>> Hi Laurent,
>>
>> Thank you for the patch,
>>
>> On 19/05/18 21:34, Laurent Pinchart wrote:
>>> The suspend/resume test starts a run of 300 frames and suspends the
>>> system one second later. On some SoCs (namely H3 ES2.0) the VSP
>>> bandwidth is high enough to complete processing of 300 frames in less
>>> than a second. The test thus suspends and resumes the system with the
>>> VSP idle instead of running, defeating the purpose of the test.
>>>
>>> Fix this by increasing the number of frames to process to 1000. The
>>> frame count is now passed as an argument to the
>>> test_extended_wpf_packing function to ease future changes.
>>
>> Great idea, to make it easy to update and re-use.
>>
>>> Signed-off-by: Laurent Pinchart <laurent.pinch...@ideasonboard.com>
>>
>> Reviewed-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
>>
>>> ---
>>>
>>>  tests/vsp-unit-test-0020.sh | 15 ---
>>>  1 file changed, 8 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/tests/vsp-unit-test-0020.sh b/tests/vsp-unit-test-0020.sh
>>> index 91f6b167f22e..950c1bebbf2f 100755
>>> --- a/tests/vsp-unit-test-0020.sh
>>> +++ b/tests/vsp-unit-test-0020.sh
>>> @@ -15,25 +15,26 @@ features="rpf.0 wpf.0"
>>>
>>>  # These can be extracted from /sys/power/pm_test
>>>  suspend_modes="freezer devices platform processors core"
>>>
>>> -# This extended function performs the same
>>> -# as it's non-extended name-sake - but runs the pipeline
>>> -# for 300 frames. The suspend action occurs between frame #150~#200
>>> -
>>> +# This extended function performs the same as it's non-extended
>>> name-sake, but
>>> +# runs the pipeline for a configurable number of frames.
>>>
>>>  test_extended_wpf_packing() {
>>> local format=$1
>>> +   local num_frames=$2
>>>
>>> pipe_configure rpf-wpf 0 0
>>> format_configure rpf-wpf 0 0 ARGB32 1024x768 $format
>>>
>>> -   vsp_runner rpf.0 --count=300 &
>>> -   vsp_runner wpf.0 --count=300 --skip=297
>>> +   vsp_runner rpf.0 --count=$num_frames &
>>> +   vsp_runner wpf.0 --count=$num_frames --skip=$((num_frames-1))
>>
>> The original test compared up to 3 frames... But I guess as long as one
>> frame matches we're good on this test. We just need to know the pipeline
>> was still running... and 3 frames doesn't provide much more information
>> than one.
> 
> That's an oversight. num_frames-3 is what I meant. 
> 
>>> local result=$(compare_frames)
>>> [ x$result == xpass ] && return 0 || return 1
>>>  
>>>  }
>>>  
>>>  test_hw_pipe() {
>>>
>>> -   test_extended_wpf_packing RGB24
>>> +   # Run the pipeline for 1000 frames. The suspend action occurs between
>>> +   # frame #500~#600
>>
>> I'm not sure it's worth stating when the suspend action occurs, as it's
>> variable depending upon the performance of the SoC ... but I'll not object
>> to this.
> 
> I agree with you, I'll remove that.
> 
> I think it would make sense to run the pipeline without a limit in the frame 
> count, and stop streaming after resume. Feel free to give it a try if you 
> want 
> :-)

The question here will be how to we get the frame verification to occur on the
'last N frames'

For this, wouldn't we need to extend yavta to support some kind of signal to
perform a stream validation at an earlier point and shutdown the stream
(probably leaving the count/skip, as maximum durations to run...) And then
making sure we knew which frames were actually written out ...

I'll leave this ticking in the back of my mind for now :D

> 
>>> +   test_extended_wpf_packing RGB24 1000
>>>  }
>>>  
>>>  test_suspend_resume() {
> 



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 2/2] tests: suspend/resume: Increase number of processed frames

2018-05-21 Thread Kieran Bingham
Hi Laurent,

Thank you for the patch,

On 19/05/18 21:34, Laurent Pinchart wrote:
> The suspend/resume test starts a run of 300 frames and suspends the
> system one second later. On some SoCs (namely H3 ES2.0) the VSP
> bandwidth is high enough to complete processing of 300 frames in less
> than a second. The test thus suspends and resumes the system with the
> VSP idle instead of running, defeating the purpose of the test.
> 
> Fix this by increasing the number of frames to process to 1000. The
> frame count is now passed as an argument to the
> test_extended_wpf_packing function to ease future changes.

Great idea, to make it easy to update and re-use.

> Signed-off-by: Laurent Pinchart <laurent.pinch...@ideasonboard.com>

Reviewed-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

> ---
>  tests/vsp-unit-test-0020.sh | 15 ---
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/tests/vsp-unit-test-0020.sh b/tests/vsp-unit-test-0020.sh
> index 91f6b167f22e..950c1bebbf2f 100755
> --- a/tests/vsp-unit-test-0020.sh
> +++ b/tests/vsp-unit-test-0020.sh
> @@ -15,25 +15,26 @@ features="rpf.0 wpf.0"
>  # These can be extracted from /sys/power/pm_test
>  suspend_modes="freezer devices platform processors core"
>  
> -# This extended function performs the same
> -# as it's non-extended name-sake - but runs the pipeline
> -# for 300 frames. The suspend action occurs between frame #150~#200
> -
> +# This extended function performs the same as it's non-extended name-sake, 
> but
> +# runs the pipeline for a configurable number of frames.
>  test_extended_wpf_packing() {
>   local format=$1
> + local num_frames=$2
>  
>   pipe_configure rpf-wpf 0 0
>   format_configure rpf-wpf 0 0 ARGB32 1024x768 $format
>  
> - vsp_runner rpf.0 --count=300 &
> - vsp_runner wpf.0 --count=300 --skip=297
> + vsp_runner rpf.0 --count=$num_frames &
> + vsp_runner wpf.0 --count=$num_frames --skip=$((num_frames-1))

The original test compared up to 3 frames... But I guess as long as one frame
matches we're good on this test. We just need to know the pipeline was still
running... and 3 frames doesn't provide much more information than one.

>  
>   local result=$(compare_frames)
>   [ x$result == xpass ] && return 0 || return 1
>  }
>  
>  test_hw_pipe() {
> - test_extended_wpf_packing RGB24
> + # Run the pipeline for 1000 frames. The suspend action occurs between
> + # frame #500~#600

I'm not sure it's worth stating when the suspend action occurs, as it's variable
depending upon the performance of the SoC ... but I'll not object to this.

> + test_extended_wpf_packing RGB24 1000
>  }
>  
>  test_suspend_resume() {
> 



signature.asc
Description: OpenPGP digital signature


Re: [PATCH v11 01/10] media: v4l: vsp1: Release buffers for each video node

2018-05-18 Thread Kieran Bingham

On 18/05/18 21:53, Laurent Pinchart wrote:
> Hi Kieran,
> 
> Thank you for the patch.
> 
> On Friday, 18 May 2018 23:41:54 EEST Kieran Bingham wrote:
>> From: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
>>
>> Commit 372b2b0399fc ("media: v4l: vsp1: Release buffers in
>> start_streaming error path") introduced a helper to clean up buffers on
>> error paths, but inadvertently changed the code such that only the
>> output WPF buffers were cleaned, rather than the video node being
>> operated on.
>>
>> Since then vsp1_video_cleanup_pipeline() has grown to perform both video
>> node cleanup, as well as pipeline cleanup. Split the implementation into
>> two distinct functions that perform the required work, so that each
>> video node can release it's buffers correctly on streamoff. The pipe
> 
> s/it's/its/
> 
>> cleanup that was performed in the vsp1_video_stop_streaming() (releasing
>> the pipe->dl) is moved to the function for clarity.
>>
>> Fixes: 372b2b0399fc ("media: v4l: vsp1: Release buffers in start_streaming
>> error path")
>> Cc: sta...@vger.kernel.org # v4.13+
> 
> Commit 372b2b0399fc was introduced in v4.14, should this be v4.14+ ?

Yes, thank you - that's me mis-interpreting my own scripts to get the version
for fixes.


>>
>> Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
> 
> Reviewed-by: Laurent Pinchart <laurent.pinch...@ideasonboard.com>
> 
> No need to resubmit for this, I'll fix the commit message when applying.

Great.

--
Kieran

> 
>> ---
>>  drivers/media/platform/vsp1/vsp1_video.c | 21 +
>>  1 file changed, 13 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/media/platform/vsp1/vsp1_video.c
>> b/drivers/media/platform/vsp1/vsp1_video.c index c8c12223a267..ba89dd176a13
>> 100644
>> --- a/drivers/media/platform/vsp1/vsp1_video.c
>> +++ b/drivers/media/platform/vsp1/vsp1_video.c
>> @@ -842,9 +842,8 @@ static int vsp1_video_setup_pipeline(struct
>> vsp1_pipeline *pipe) return 0;
>>  }
>>
>> -static void vsp1_video_cleanup_pipeline(struct vsp1_pipeline *pipe)
>> +static void vsp1_video_release_buffers(struct vsp1_video *video)
>>  {
>> -struct vsp1_video *video = pipe->output->video;
>>  struct vsp1_vb2_buffer *buffer;
>>  unsigned long flags;
>>
>> @@ -854,12 +853,18 @@ static void vsp1_video_cleanup_pipeline(struct
>> vsp1_pipeline *pipe) vb2_buffer_done(>buf.vb2_buf,
>> VB2_BUF_STATE_ERROR);
>>  INIT_LIST_HEAD(>irqqueue);
>>  spin_unlock_irqrestore(>irqlock, flags);
>> +}
>> +
>> +static void vsp1_video_cleanup_pipeline(struct vsp1_pipeline *pipe)
>> +{
>> +lockdep_assert_held(>lock);
>>
>>  /* Release our partition table allocation */
>> -mutex_lock(>lock);
>>  kfree(pipe->part_table);
>>  pipe->part_table = NULL;
>> -mutex_unlock(>lock);
>> +
>> +vsp1_dl_list_put(pipe->dl);
>> +pipe->dl = NULL;
>>  }
>>
>>  static int vsp1_video_start_streaming(struct vb2_queue *vq, unsigned int
>> count) @@ -874,8 +879,9 @@ static int vsp1_video_start_streaming(struct
>> vb2_queue *vq, unsigned int count) if (pipe->stream_count ==
>> pipe->num_inputs) {
>>  ret = vsp1_video_setup_pipeline(pipe);
>>  if (ret < 0) {
>> -mutex_unlock(>lock);
>> +vsp1_video_release_buffers(video);
>>  vsp1_video_cleanup_pipeline(pipe);
>> +mutex_unlock(>lock);
>>  return ret;
>>  }
>>
>> @@ -925,13 +931,12 @@ static void vsp1_video_stop_streaming(struct vb2_queue
>> *vq) if (ret == -ETIMEDOUT)
>>  dev_err(video->vsp1->dev, "pipeline stop timeout\n");
>>
>> -vsp1_dl_list_put(pipe->dl);
>> -pipe->dl = NULL;
>> +vsp1_video_cleanup_pipeline(pipe);
>>  }
>>  mutex_unlock(>lock);
>>
>>  media_pipeline_stop(>video.entity);
>> -vsp1_video_cleanup_pipeline(pipe);
>> +vsp1_video_release_buffers(video);
>>  vsp1_video_pipeline_put(pipe);
>>  }
> 


[PATCH v11 04/10] media: vsp1: Protect bodies against overflow

2018-05-18 Thread Kieran Bingham
From: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

The body write function relies on the code never asking it to write more
than the entries available in the list.

Currently with each list body containing 256 entries, this is fine, but
we can reduce this number greatly saving memory. In preparation of this
add a level of protection to catch any buffer overflows.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinch...@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_dl.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index 083da4f05c20..51965c30dec2 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -46,6 +46,7 @@ struct vsp1_dl_entry {
  * @dma: DMA address of the entries
  * @size: size of the DMA memory in bytes
  * @num_entries: number of stored entries
+ * @max_entries: number of entries available
  */
 struct vsp1_dl_body {
struct list_head list;
@@ -56,6 +57,7 @@ struct vsp1_dl_body {
size_t size;
 
unsigned int num_entries;
+   unsigned int max_entries;
 };
 
 /**
@@ -138,6 +140,7 @@ static int vsp1_dl_body_init(struct vsp1_device *vsp1,
 
dlb->vsp1 = vsp1;
dlb->size = size;
+   dlb->max_entries = num_entries;
 
dlb->entries = dma_alloc_wc(vsp1->bus_master, dlb->size, >dma,
GFP_KERNEL);
@@ -219,6 +222,10 @@ void vsp1_dl_body_free(struct vsp1_dl_body *dlb)
  */
 void vsp1_dl_body_write(struct vsp1_dl_body *dlb, u32 reg, u32 data)
 {
+   if (WARN_ONCE(dlb->num_entries >= dlb->max_entries,
+ "DLB size exceeded (max %u)", dlb->max_entries))
+   return;
+
dlb->entries[dlb->num_entries].addr = reg;
dlb->entries[dlb->num_entries].data = data;
dlb->num_entries++;
-- 
git-series 0.9.1


[PATCH v11 05/10] media: vsp1: Provide a body pool

2018-05-18 Thread Kieran Bingham
From: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

Each display list allocates a body to store register values in a dma
accessible buffer from a dma_alloc_wc() allocation. Each of these
results in an entry in the IOMMU TLB, and a large number of display list
allocations adds pressure to this resource.

Reduce TLB pressure on the IPMMUs by allocating multiple display list
bodies in a single allocation, and providing these to the display list
through a 'body pool'. A pool can be allocated by the display list
manager or entities which require their own body allocations.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_dl.c | 163 +++-
 drivers/media/platform/vsp1/vsp1_dl.h |   8 +-
 2 files changed, 171 insertions(+)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index 51965c30dec2..41ace89a585b 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -41,6 +41,8 @@ struct vsp1_dl_entry {
 /**
  * struct vsp1_dl_body - Display list body
  * @list: entry in the display list list of bodies
+ * @free: entry in the pool free body list
+ * @pool: pool to which this body belongs
  * @vsp1: the VSP1 device
  * @entries: array of entries
  * @dma: DMA address of the entries
@@ -50,6 +52,9 @@ struct vsp1_dl_entry {
  */
 struct vsp1_dl_body {
struct list_head list;
+   struct list_head free;
+
+   struct vsp1_dl_body_pool *pool;
struct vsp1_device *vsp1;
 
struct vsp1_dl_entry *entries;
@@ -61,6 +66,30 @@ struct vsp1_dl_body {
 };
 
 /**
+ * struct vsp1_dl_body_pool - display list body pool
+ * @dma: DMA address of the entries
+ * @size: size of the full DMA memory pool in bytes
+ * @mem: CPU memory pointer for the pool
+ * @bodies: Array of DLB structures for the pool
+ * @free: List of free DLB entries
+ * @lock: Protects the free list
+ * @vsp1: the VSP1 device
+ */
+struct vsp1_dl_body_pool {
+   /* DMA allocation */
+   dma_addr_t dma;
+   size_t size;
+   void *mem;
+
+   /* Body management */
+   struct vsp1_dl_body *bodies;
+   struct list_head free;
+   spinlock_t lock;
+
+   struct vsp1_device *vsp1;
+};
+
+/**
  * struct vsp1_dl_list - Display list
  * @list: entry in the display list manager lists
  * @dlm: the display list manager
@@ -104,6 +133,7 @@ enum vsp1_dl_mode {
  * @active: list currently being processed (loaded) by hardware
  * @queued: list queued to the hardware (written to the DL registers)
  * @pending: list waiting to be queued to the hardware
+ * @pool: body pool for the display list bodies
  * @gc_work: bodies garbage collector work struct
  * @gc_bodies: array of display list bodies waiting to be freed
  */
@@ -119,6 +149,8 @@ struct vsp1_dl_manager {
struct vsp1_dl_list *queued;
struct vsp1_dl_list *pending;
 
+   struct vsp1_dl_body_pool *pool;
+
struct work_struct gc_work;
struct list_head gc_bodies;
 };
@@ -127,6 +159,137 @@ struct vsp1_dl_manager {
  * Display List Body Management
  */
 
+/**
+ * vsp1_dl_body_pool_create - Create a pool of bodies from a single allocation
+ * @vsp1: The VSP1 device
+ * @num_bodies: The number of bodies to allocate
+ * @num_entries: The maximum number of entries that a body can contain
+ * @extra_size: Extra allocation provided for the bodies
+ *
+ * Allocate a pool of display list bodies each with enough memory to contain 
the
+ * requested number of entries plus the @extra_size.
+ *
+ * Return a pointer to a pool on success or NULL if memory can't be allocated.
+ */
+struct vsp1_dl_body_pool *
+vsp1_dl_body_pool_create(struct vsp1_device *vsp1, unsigned int num_bodies,
+unsigned int num_entries, size_t extra_size)
+{
+   struct vsp1_dl_body_pool *pool;
+   size_t dlb_size;
+   unsigned int i;
+
+   pool = kzalloc(sizeof(*pool), GFP_KERNEL);
+   if (!pool)
+   return NULL;
+
+   pool->vsp1 = vsp1;
+
+   /*
+* TODO: 'extra_size' is only used by vsp1_dlm_create(), to allocate
+* extra memory for the display list header. We need only one header per
+* display list, not per display list body, thus this allocation is
+* extraneous and should be reworked in the future.
+*/
+   dlb_size = num_entries * sizeof(struct vsp1_dl_entry) + extra_size;
+   pool->size = dlb_size * num_bodies;
+
+   pool->bodies = kcalloc(num_bodies, sizeof(*pool->bodies), GFP_KERNEL);
+   if (!pool->bodies) {
+   kfree(pool);
+   return NULL;
+   }
+
+   pool->mem = dma_alloc_wc(vsp1->bus_master, pool->size, >dma,
+

[PATCH v11 09/10] media: vsp1: Adapt entities to configure into a body

2018-05-18 Thread Kieran Bingham
From: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

Currently the entities store their configurations into a display list.
Adapt this such that the code can be configured into a body directly,
allowing greater flexibility and control of the content.

All users of vsp1_dl_list_write() are removed in this process, thus it
too is removed.

A helper, vsp1_dl_list_get_body0() is provided to access the internal body0
from the display list.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
[Don't remove blank line unnecessarily]
Reviewed-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_brx.c| 22 ++--
 drivers/media/platform/vsp1/vsp1_clu.c| 23 ++---
 drivers/media/platform/vsp1/vsp1_dl.c | 12 ++-
 drivers/media/platform/vsp1/vsp1_dl.h |  2 +-
 drivers/media/platform/vsp1/vsp1_drm.c| 12 ---
 drivers/media/platform/vsp1/vsp1_entity.c | 22 ++--
 drivers/media/platform/vsp1/vsp1_entity.h | 18 ++
 drivers/media/platform/vsp1/vsp1_hgo.c| 16 -
 drivers/media/platform/vsp1/vsp1_hgt.c| 18 +-
 drivers/media/platform/vsp1/vsp1_hsit.c   | 10 +++---
 drivers/media/platform/vsp1/vsp1_lif.c| 15 
 drivers/media/platform/vsp1/vsp1_lut.c| 23 ++---
 drivers/media/platform/vsp1/vsp1_pipe.c   |  4 +-
 drivers/media/platform/vsp1/vsp1_pipe.h   |  3 +-
 drivers/media/platform/vsp1/vsp1_rpf.c| 43 
 drivers/media/platform/vsp1/vsp1_sru.c| 14 
 drivers/media/platform/vsp1/vsp1_uds.c| 25 +++---
 drivers/media/platform/vsp1/vsp1_uds.h|  2 +-
 drivers/media/platform/vsp1/vsp1_uif.c| 21 ++--
 drivers/media/platform/vsp1/vsp1_video.c  | 16 ++---
 drivers/media/platform/vsp1/vsp1_wpf.c| 42 ---
 21 files changed, 194 insertions(+), 169 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_brx.c 
b/drivers/media/platform/vsp1/vsp1_brx.c
index 011edac5ebc1..359917b5d842 100644
--- a/drivers/media/platform/vsp1/vsp1_brx.c
+++ b/drivers/media/platform/vsp1/vsp1_brx.c
@@ -26,10 +26,10 @@
  * Device Access
  */
 
-static inline void vsp1_brx_write(struct vsp1_brx *brx, struct vsp1_dl_list 
*dl,
- u32 reg, u32 data)
+static inline void vsp1_brx_write(struct vsp1_brx *brx,
+ struct vsp1_dl_body *dlb, u32 reg, u32 data)
 {
-   vsp1_dl_list_write(dl, brx->base + reg, data);
+   vsp1_dl_body_write(dlb, brx->base + reg, data);
 }
 
 /* 
-
@@ -283,7 +283,7 @@ static const struct v4l2_subdev_ops brx_ops = {
 
 static void brx_configure_stream(struct vsp1_entity *entity,
 struct vsp1_pipeline *pipe,
-struct vsp1_dl_list *dl)
+struct vsp1_dl_body *dlb)
 {
struct vsp1_brx *brx = to_brx(>subdev);
struct v4l2_mbus_framefmt *format;
@@ -305,7 +305,7 @@ static void brx_configure_stream(struct vsp1_entity *entity,
 * format at the pipeline output is premultiplied.
 */
flags = pipe->output ? pipe->output->format.flags : 0;
-   vsp1_brx_write(brx, dl, VI6_BRU_INCTRL,
+   vsp1_brx_write(brx, dlb, VI6_BRU_INCTRL,
   flags & V4L2_PIX_FMT_FLAG_PREMUL_ALPHA ?
   0 : VI6_BRU_INCTRL_NRM);
 
@@ -313,12 +313,12 @@ static void brx_configure_stream(struct vsp1_entity 
*entity,
 * Set the background position to cover the whole output image and
 * configure its color.
 */
-   vsp1_brx_write(brx, dl, VI6_BRU_VIRRPF_SIZE,
+   vsp1_brx_write(brx, dlb, VI6_BRU_VIRRPF_SIZE,
   (format->width << VI6_BRU_VIRRPF_SIZE_HSIZE_SHIFT) |
   (format->height << VI6_BRU_VIRRPF_SIZE_VSIZE_SHIFT));
-   vsp1_brx_write(brx, dl, VI6_BRU_VIRRPF_LOC, 0);
+   vsp1_brx_write(brx, dlb, VI6_BRU_VIRRPF_LOC, 0);
 
-   vsp1_brx_write(brx, dl, VI6_BRU_VIRRPF_COL, brx->bgcolor |
+   vsp1_brx_write(brx, dlb, VI6_BRU_VIRRPF_COL, brx->bgcolor |
   (0xff << VI6_BRU_VIRRPF_COL_A_SHIFT));
 
/*
@@ -328,7 +328,7 @@ static void brx_configure_stream(struct vsp1_entity *entity,
 * unit.
 */
if (entity->type == VSP1_ENTITY_BRU)
-   vsp1_brx_write(brx, dl, VI6_BRU_ROP,
+   vsp1_brx_write(brx, dlb, VI6_BRU_ROP,
   VI6_BRU_ROP_DSTSEL_BRUIN(1) |
   VI6_BRU_ROP_CROP(VI6_ROP_NOP) |
   VI6_BRU_ROP_AROP(VI6_ROP_NOP));
@@ -370,7 +370,7 @@ static void brx_configure_stream(struct vsp1_entity *entity,
   

[PATCH v11 07/10] media: vsp1: Use reference counting for bodies

2018-05-18 Thread Kieran Bingham
From: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

Extend the display list body with a reference count, allowing bodies to
be kept as long as a reference is maintained. This provides the ability
to keep a cached copy of bodies which will not change, so that they can
be re-applied to multiple display lists.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_clu.c |  7 ++-
 drivers/media/platform/vsp1/vsp1_dl.c  | 16 ++--
 drivers/media/platform/vsp1/vsp1_lut.c |  7 ++-
 3 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_clu.c 
b/drivers/media/platform/vsp1/vsp1_clu.c
index 8efa12f5e53f..ea83f1b7d125 100644
--- a/drivers/media/platform/vsp1/vsp1_clu.c
+++ b/drivers/media/platform/vsp1/vsp1_clu.c
@@ -212,8 +212,13 @@ static void clu_configure(struct vsp1_entity *entity,
clu->clu = NULL;
spin_unlock_irqrestore(>lock, flags);
 
-   if (dlb)
+   if (dlb) {
vsp1_dl_list_add_body(dl, dlb);
+
+   /* Release our local reference. */
+   vsp1_dl_body_put(dlb);
+   }
+
break;
}
 }
diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index 617c46a03dec..1407c90c6880 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -54,6 +55,8 @@ struct vsp1_dl_body {
struct list_head list;
struct list_head free;
 
+   refcount_t refcnt;
+
struct vsp1_dl_body_pool *pool;
struct vsp1_device *vsp1;
 
@@ -258,6 +261,7 @@ struct vsp1_dl_body *vsp1_dl_body_get(struct 
vsp1_dl_body_pool *pool)
if (!list_empty(>free)) {
dlb = list_first_entry(>free, struct vsp1_dl_body, free);
list_del(>free);
+   refcount_set(>refcnt, 1);
}
 
spin_unlock_irqrestore(>lock, flags);
@@ -278,6 +282,9 @@ void vsp1_dl_body_put(struct vsp1_dl_body *dlb)
if (!dlb)
return;
 
+   if (!refcount_dec_and_test(>refcnt))
+   return;
+
dlb->num_entries = 0;
 
spin_lock_irqsave(>pool->lock, flags);
@@ -463,8 +470,11 @@ void vsp1_dl_list_write(struct vsp1_dl_list *dl, u32 reg, 
u32 data)
  * which bodies are added.
  *
  * Adding a body to a display list passes ownership of the body to the list. 
The
- * caller must not touch the body after this call, and must not release it
- * explicitly with vsp1_dl_body_put().
+ * caller retains its reference to the fragment when adding it to the display
+ * list, but is not allowed to add new entries to the body.
+ *
+ * The reference must be explicitly released by a call to vsp1_dl_body_put()
+ * when the body isn't needed anymore.
  *
  * Additional bodies are only usable for display lists in header mode.
  * Attempting to add a body to a header-less display list will return an error.
@@ -475,6 +485,8 @@ int vsp1_dl_list_add_body(struct vsp1_dl_list *dl, struct 
vsp1_dl_body *dlb)
if (dl->dlm->mode != VSP1_DL_MODE_HEADER)
return -EINVAL;
 
+   refcount_inc(>refcnt);
+
list_add_tail(>list, >bodies);
 
return 0;
diff --git a/drivers/media/platform/vsp1/vsp1_lut.c 
b/drivers/media/platform/vsp1/vsp1_lut.c
index 6b358617ce15..b3ea90172439 100644
--- a/drivers/media/platform/vsp1/vsp1_lut.c
+++ b/drivers/media/platform/vsp1/vsp1_lut.c
@@ -168,8 +168,13 @@ static void lut_configure(struct vsp1_entity *entity,
lut->lut = NULL;
spin_unlock_irqrestore(>lock, flags);
 
-   if (dlb)
+   if (dlb) {
vsp1_dl_list_add_body(dl, dlb);
+
+   /* Release our local reference. */
+   vsp1_dl_body_put(dlb);
+   }
+
break;
}
 }
-- 
git-series 0.9.1


[PATCH v11 10/10] media: vsp1: Move video configuration to a cached dlb

2018-05-18 Thread Kieran Bingham
From: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

We are now able to configure a pipeline directly into a local display
list body. Take advantage of this fact, and create a cacheable body to
store the configuration of the pipeline in the video object.

vsp1_video_pipeline_run() is now the last user of the pipe->dl object.
Convert this function to use the cached video->config body and obtain a
local display list reference.

Attach the video->stream_config body to the display list when needed
before committing to hardware.

Use a flag 'configured' to know when we should attach our stream_config
to the next outgoing display list to reconfigure the hardware in the
event of our first frame, or the first frame following a suspend/resume
cycle.

Our video DL usage now looks like the below output:

dl->body0 contains our disposable runtime configuration. Max 41.
dl_child->body0 is our partition specific configuration. Max 12.
dl->bodies shows our constant configuration and LUTs.

  These two are LUT/CLU:
 * dl->bodies[x]->num_entries 256 / max 256
 * dl->bodies[x]->num_entries 4914 / max 4914

Which shows that our 'constant' configuration cache is currently
utilised to a maximum of 64 entries.

trace-cmd report | \
grep max | sed 's/.*vsp1_dl_list_commit://g' | sort | uniq;

  dl->body0->num_entries 13 / max 128
  dl->body0->num_entries 14 / max 128
  dl->body0->num_entries 16 / max 128
  dl->body0->num_entries 20 / max 128
  dl->body0->num_entries 27 / max 128
  dl->body0->num_entries 34 / max 128
  dl->body0->num_entries 41 / max 128
  dl_child->body0->num_entries 10 / max 128
  dl_child->body0->num_entries 12 / max 128
  dl->bodies[x]->num_entries 15 / max 128
  dl->bodies[x]->num_entries 16 / max 128
  dl->bodies[x]->num_entries 17 / max 128
  dl->bodies[x]->num_entries 18 / max 128
  dl->bodies[x]->num_entries 20 / max 128
  dl->bodies[x]->num_entries 21 / max 128
  dl->bodies[x]->num_entries 256 / max 256
  dl->bodies[x]->num_entries 31 / max 128
  dl->bodies[x]->num_entries 32 / max 128
  dl->bodies[x]->num_entries 39 / max 128
  dl->bodies[x]->num_entries 40 / max 128
  dl->bodies[x]->num_entries 47 / max 128
  dl->bodies[x]->num_entries 48 / max 128
  dl->bodies[x]->num_entries 4914 / max 4914
  dl->bodies[x]->num_entries 55 / max 128
  dl->bodies[x]->num_entries 56 / max 128
  dl->bodies[x]->num_entries 63 / max 128
  dl->bodies[x]->num_entries 64 / max 128

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
v11:
 - Remove dlbs pool from video object.
   Utilise the DLM pool for video->stream_config
 - Improve comments
 - clear the video->stream_config after it is released
   object.
 - stream_config and configured flag return to the pipe object.

v10:
 - Removed pipe->configured flag, and use
   pipe->state == VSP1_PIPELINE_STOPPED instead.

v8:
 - Fix comments
 - Rename video->pipe_config -> video->stream_config

v4:
 - Adjust pipe configured flag to be reset on resume rather than suspend
 - rename dl_child, dl_next

v3:
 - 's/fragment/body/', 's/fragments/bodies/'
 - video dlb cache allocation increased from 2 to 3 dlbs

 drivers/media/platform/vsp1/vsp1_dl.c| 10 +++-
 drivers/media/platform/vsp1/vsp1_dl.h|  1 +-
 drivers/media/platform/vsp1/vsp1_pipe.h  |  6 +-
 drivers/media/platform/vsp1/vsp1_video.c | 69 +++--
 4 files changed, 56 insertions(+), 30 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index c7fa1cb088cd..0f97305de965 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -813,6 +813,11 @@ void vsp1_dlm_reset(struct vsp1_dl_manager *dlm)
dlm->pending = NULL;
 }
 
+struct vsp1_dl_body *vsp1_dlm_dl_body_get(struct vsp1_dl_manager *dlm)
+{
+   return vsp1_dl_body_get(dlm->pool);
+}
+
 struct vsp1_dl_manager *vsp1_dlm_create(struct vsp1_device *vsp1,
unsigned int index,
unsigned int prealloc)
@@ -838,13 +843,14 @@ struct vsp1_dl_manager *vsp1_dlm_create(struct 
vsp1_device *vsp1,
 * Initialize the display list body and allocate DMA memory for the body
 * and the optional header. Both are allocated together to avoid memory
 * fragmentation, with the header located right after the body in
-* memory.
+* memory. An extra body is allocated on top of the prealloc to account
+* for the cached body used by the vsp1_video object.
 */
header_size = dlm->mode == VSP1_DL_MODE_HEADER
? ALIGN(sizeof(struct vsp1_dl_header), 8)
: 0;
 
-   dlm->pool = vsp1_dl_body_pool_create(vsp1, prealloc,
+

[PATCH v11 00/10] vsp1: TLB optimisation and DL caching

2018-05-18 Thread Kieran Bingham
From: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

Each display list currently allocates an area of DMA memory to store register
settings for the VSP1 to process. Each of these allocations adds pressure to
the IPMMU TLB entries.

We can reduce the pressure by pre-allocating larger areas and dividing the area
across multiple bodies represented as a pool.

With this reconfiguration of bodies, we can adapt the configuration code to
separate out constant hardware configuration and cache it for re-use.

The patches provided in this series can be found at:
  git://git.kernel.org/pub/scm/linux/kernel/git/kbingham/rcar.git  
tags/vsp1/tlb-optimise/v11

Changelog:
--
v11:
 - Introduce two new patches as fixes to the VSP1.
  * media: v4l: vsp1: Release buffers for each video node
  * media: vsp1: Move video suspend resume handling to video object

 - media: vsp1: Move video configuration to a cached dlb
   - Now uses dlb's from the DLM pool
   - clears the pipe->stream_config after it is released
   - moves stream_config and configured flags to pipe objects.

v10:
 - Rebase to latest linux-media/master
 - Remove pipe->configured flag, as pipe->state is suitable for the
   same purpose, as:
(!pipe->configured) == (pipe->state == VSP1_PIPELINE_STOPPED)

v9:
 - Pass the DL through configure_partition() calls
 - Remove redundant reference to gc_bodies

v8:
 - Fix formatting and white space
 - Reword vsp1_dl_list_add_body() documentation
 - Update commit message on "Provide a body pool"
 - No longer pass unnecessary dlm->pool through vsp1_dl_list_alloc()
 - Add support for the new UIF entity
 - Fix comment location for clu_configure_stream()
 - Implement configure_partition separation
 - Rename video->pipe_config to video->stream_config

v7:
 - Rebased on to linux-media/master (v4.16-rc4)
 - Clean up the formatting of the vsp1_dl_list_add_body()
 - Fix formatting and white space
 -  s/prepare/configure_stream/
 -  s/configure/configure_frame/

v6:
 - Rebased on to linux-media/master (v4.16-rc1)
 - Removed DRM/UIF (DISCOM/ColorKey) updates

v5:
 - Rebased on to renesas-drivers-2018-01-09-v4.15-rc7 to fix conflicts
   with DRM and UIF updates on VSP1 driver

v4:
 - Rebased to v4.14
 * v4l: vsp1: Use reference counting for bodies
   - Fix up reference handling comments

 * v4l: vsp1: Provide a body pool
   - Provide comment explaining extra allocation on body pool
 highlighting area for optimisation later.

 * v4l: vsp1: Refactor display list configure operations
   - Fix up comment to describe yuv_mode caching rather than format

 * vsp1: Adapt entities to configure into a body
   - Rename vsp1_dl_list_get_body() to vsp1_dl_list_get_body0()

 * v4l: vsp1: Move video configuration to a cached dlb
   - Adjust pipe configured flag to be reset on resume rather than suspend
   - rename dl_child, dl_next

Testing:

The VSP unit tests have been run on this patch set with the following results:

root@Ubuntu-ARM64:~/vsp-tests# ./vsp-tests.sh
--- Test loop 1 ---
- vsp-unit-test-.sh
Test Conditions:
  Platform  Renesas Salvator-X 2nd version board based on r8a7795 ES2.0+
  Kernel release4.17.0-rc4-arm64-renesas-00397-g3d2f6f2901b0
  convert   /usr/bin/convert
  compare   /usr/bin/compare
  killall   /usr/bin/killall
  raw2rgbpnm/usr/bin/raw2rgbpnm
  stress/usr/bin/stress
  yavta /usr/bin/yavta
- vsp-unit-test-0001.sh
Testing WPF packing in RGB332: pass
Testing WPF packing in ARGB555: pass
Testing WPF packing in XRGB555: pass
Testing WPF packing in RGB565: pass
Testing WPF packing in BGR24: pass
Testing WPF packing in RGB24: pass
Testing WPF packing in ABGR32: pass
Testing WPF packing in ARGB32: pass
Testing WPF packing in XBGR32: pass
Testing WPF packing in XRGB32: pass
- vsp-unit-test-0002.sh
Testing WPF packing in NV12M: pass
Testing WPF packing in NV16M: pass
Testing WPF packing in NV21M: pass
Testing WPF packing in NV61M: pass
Testing WPF packing in UYVY: pass
Testing WPF packing in VYUY: skip
Testing WPF packing in YUV420M: pass
Testing WPF packing in YUV422M: pass
Testing WPF packing in YUV444M: pass
Testing WPF packing in YVU420M: pass
Testing WPF packing in YVU422M: pass
Testing WPF packing in YVU444M: pass
Testing WPF packing in YUYV: pass
Testing WPF packing in YVYU: pass
- vsp-unit-test-0003.sh
Testing scaling from 640x640 to 640x480 in RGB24: pass
Testing scaling from 1024x768 to 640x480 in RGB24: pass
Testing scaling from 640x480 to 1024x768 in RGB24: pass
Testing scaling from 640x640 to 640x480 in YUV444M: pass
Testing scaling from 1024x768 to 640x480 in YUV444M: pass
Testing scaling from 640x480 to 1024x768 in YUV444M: pass
- vsp-unit-test-0004.sh
Testing histogram in RGB24: pass
Testing histogram in YUV444M: pass
- vsp-unit-test-0005.sh
Testing RPF.0: pass
Testing RPF.1: pass
Testing RPF.2: pass
Testing RPF.3: pass
Testing RPF.4: pass
- vsp-unit-test-0006.sh
Testing in

[PATCH v11 02/10] media: vsp1: Move video suspend resume handling to video object

2018-05-18 Thread Kieran Bingham
From: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

The suspend and resume handlers are only utilised by video pipelines,
yet the functions currently reside in the vsp1_pipe object.

This causes an issue with resume, as the functions incorrectly call
vsp1_pipeline_run() directly instead of processing the video object
through vsp1_video_pipeline_run().

Move the functions to the video object, renaming accordingly and update
the resume handler to call vsp1_video_pipeline_run() as appropriate.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_drv.c   |  4 +-
 drivers/media/platform/vsp1/vsp1_pipe.c  | 70 +---
 drivers/media/platform/vsp1/vsp1_pipe.h  |  3 +-
 drivers/media/platform/vsp1/vsp1_video.c | 75 +-
 drivers/media/platform/vsp1/vsp1_video.h |  3 +-
 5 files changed, 80 insertions(+), 75 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_drv.c 
b/drivers/media/platform/vsp1/vsp1_drv.c
index d29f9c4baebe..5d82f6ee56ea 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -589,7 +589,7 @@ static int __maybe_unused vsp1_pm_suspend(struct device 
*dev)
 * restarted explicitly by the DU.
 */
if (!vsp1->drm)
-   vsp1_pipelines_suspend(vsp1);
+   vsp1_video_suspend(vsp1);
 
pm_runtime_force_suspend(vsp1->dev);
 
@@ -607,7 +607,7 @@ static int __maybe_unused vsp1_pm_resume(struct device *dev)
 * restarted explicitly by the DU.
 */
if (!vsp1->drm)
-   vsp1_pipelines_resume(vsp1);
+   vsp1_video_resume(vsp1);
 
return 0;
 }
diff --git a/drivers/media/platform/vsp1/vsp1_pipe.c 
b/drivers/media/platform/vsp1/vsp1_pipe.c
index 6fde4c0b9844..da21f1a7cd75 100644
--- a/drivers/media/platform/vsp1/vsp1_pipe.c
+++ b/drivers/media/platform/vsp1/vsp1_pipe.c
@@ -386,73 +386,3 @@ void vsp1_pipeline_propagate_partition(struct 
vsp1_pipeline *pipe,
}
 }
 
-void vsp1_pipelines_suspend(struct vsp1_device *vsp1)
-{
-   unsigned long flags;
-   unsigned int i;
-   int ret;
-
-   /*
-* To avoid increasing the system suspend time needlessly, loop over the
-* pipelines twice, first to set them all to the stopping state, and
-* then to wait for the stop to complete.
-*/
-   for (i = 0; i < vsp1->info->wpf_count; ++i) {
-   struct vsp1_rwpf *wpf = vsp1->wpf[i];
-   struct vsp1_pipeline *pipe;
-
-   if (wpf == NULL)
-   continue;
-
-   pipe = wpf->entity.pipe;
-   if (pipe == NULL)
-   continue;
-
-   spin_lock_irqsave(>irqlock, flags);
-   if (pipe->state == VSP1_PIPELINE_RUNNING)
-   pipe->state = VSP1_PIPELINE_STOPPING;
-   spin_unlock_irqrestore(>irqlock, flags);
-   }
-
-   for (i = 0; i < vsp1->info->wpf_count; ++i) {
-   struct vsp1_rwpf *wpf = vsp1->wpf[i];
-   struct vsp1_pipeline *pipe;
-
-   if (wpf == NULL)
-   continue;
-
-   pipe = wpf->entity.pipe;
-   if (pipe == NULL)
-   continue;
-
-   ret = wait_event_timeout(pipe->wq, vsp1_pipeline_stopped(pipe),
-msecs_to_jiffies(500));
-   if (ret == 0)
-   dev_warn(vsp1->dev, "pipeline %u stop timeout\n",
-wpf->entity.index);
-   }
-}
-
-void vsp1_pipelines_resume(struct vsp1_device *vsp1)
-{
-   unsigned long flags;
-   unsigned int i;
-
-   /* Resume all running pipelines. */
-   for (i = 0; i < vsp1->info->wpf_count; ++i) {
-   struct vsp1_rwpf *wpf = vsp1->wpf[i];
-   struct vsp1_pipeline *pipe;
-
-   if (wpf == NULL)
-   continue;
-
-   pipe = wpf->entity.pipe;
-   if (pipe == NULL)
-   continue;
-
-   spin_lock_irqsave(>irqlock, flags);
-   if (vsp1_pipeline_ready(pipe))
-   vsp1_pipeline_run(pipe);
-   spin_unlock_irqrestore(>irqlock, flags);
-   }
-}
diff --git a/drivers/media/platform/vsp1/vsp1_pipe.h 
b/drivers/media/platform/vsp1/vsp1_pipe.h
index 663d7fed7929..69858ba6cb31 100644
--- a/drivers/media/platform/vsp1/vsp1_pipe.h
+++ b/drivers/media/platform/vsp1/vsp1_pipe.h
@@ -164,9 +164,6 @@ void vsp1_pipeline_propagate_partition(struct vsp1_pipeline 
*pipe,
   unsigned int index,
   struct vsp1_partition_window *window);
 
-void vsp1_pipelines_suspend(struct vsp1_device *vsp1);
-void vsp1_pipelines_resume(str

[PATCH v11 01/10] media: v4l: vsp1: Release buffers for each video node

2018-05-18 Thread Kieran Bingham
From: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

Commit 372b2b0399fc ("media: v4l: vsp1: Release buffers in
start_streaming error path") introduced a helper to clean up buffers on
error paths, but inadvertently changed the code such that only the
output WPF buffers were cleaned, rather than the video node being
operated on.

Since then vsp1_video_cleanup_pipeline() has grown to perform both video
node cleanup, as well as pipeline cleanup. Split the implementation into
two distinct functions that perform the required work, so that each
video node can release it's buffers correctly on streamoff. The pipe
cleanup that was performed in the vsp1_video_stop_streaming() (releasing
the pipe->dl) is moved to the function for clarity.

Fixes: 372b2b0399fc ("media: v4l: vsp1: Release buffers in start_streaming 
error path")
Cc: sta...@vger.kernel.org # v4.13+

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_video.c | 21 +
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_video.c 
b/drivers/media/platform/vsp1/vsp1_video.c
index c8c12223a267..ba89dd176a13 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -842,9 +842,8 @@ static int vsp1_video_setup_pipeline(struct vsp1_pipeline 
*pipe)
return 0;
 }
 
-static void vsp1_video_cleanup_pipeline(struct vsp1_pipeline *pipe)
+static void vsp1_video_release_buffers(struct vsp1_video *video)
 {
-   struct vsp1_video *video = pipe->output->video;
struct vsp1_vb2_buffer *buffer;
unsigned long flags;
 
@@ -854,12 +853,18 @@ static void vsp1_video_cleanup_pipeline(struct 
vsp1_pipeline *pipe)
vb2_buffer_done(>buf.vb2_buf, VB2_BUF_STATE_ERROR);
INIT_LIST_HEAD(>irqqueue);
spin_unlock_irqrestore(>irqlock, flags);
+}
+
+static void vsp1_video_cleanup_pipeline(struct vsp1_pipeline *pipe)
+{
+   lockdep_assert_held(>lock);
 
/* Release our partition table allocation */
-   mutex_lock(>lock);
kfree(pipe->part_table);
pipe->part_table = NULL;
-   mutex_unlock(>lock);
+
+   vsp1_dl_list_put(pipe->dl);
+   pipe->dl = NULL;
 }
 
 static int vsp1_video_start_streaming(struct vb2_queue *vq, unsigned int count)
@@ -874,8 +879,9 @@ static int vsp1_video_start_streaming(struct vb2_queue *vq, 
unsigned int count)
if (pipe->stream_count == pipe->num_inputs) {
ret = vsp1_video_setup_pipeline(pipe);
if (ret < 0) {
-   mutex_unlock(>lock);
+   vsp1_video_release_buffers(video);
vsp1_video_cleanup_pipeline(pipe);
+   mutex_unlock(>lock);
return ret;
}
 
@@ -925,13 +931,12 @@ static void vsp1_video_stop_streaming(struct vb2_queue 
*vq)
if (ret == -ETIMEDOUT)
dev_err(video->vsp1->dev, "pipeline stop timeout\n");
 
-   vsp1_dl_list_put(pipe->dl);
-   pipe->dl = NULL;
+   vsp1_video_cleanup_pipeline(pipe);
}
mutex_unlock(>lock);
 
media_pipeline_stop(>video.entity);
-   vsp1_video_cleanup_pipeline(pipe);
+   vsp1_video_release_buffers(video);
vsp1_video_pipeline_put(pipe);
 }
 
-- 
git-series 0.9.1


Re: [PATCH v10 8/8] media: vsp1: Move video configuration to a cached dlb

2018-05-18 Thread Kieran Bingham
Hi Laurent,

On 17/05/18 20:57, Laurent Pinchart wrote:
> Hi Kieran,
> 
> Thank you for the patch.
> 
> On Thursday, 17 May 2018 20:24:01 EEST Kieran Bingham wrote:
>> We are now able to configure a pipeline directly into a local display
>> list body. Take advantage of this fact, and create a cacheable body to
>> store the configuration of the pipeline in the video object.
>>
>> vsp1_video_pipeline_run() is now the last user of the pipe->dl object.
>> Convert this function to use the cached video->config body and obtain a
>> local display list reference.
>>
>> Attach the video->config body to the display list when needed before
>> committing to hardware.
>>
>> The pipe object is marked as un-configured when resuming from a suspend.
> 
> Is this comment still valid ?

Nope :D

Updated in latest local patch.

> 
>> This ensures that when the hardware is reset - our cached configuration
>> will be re-attached to the next committed DL.
>>
>> Our video DL usage now looks like the below output:
>>
>> dl->body0 contains our disposable runtime configuration. Max 41.
>> dl_child->body0 is our partition specific configuration. Max 12.
>> dl->bodies shows our constant configuration and LUTs.
>>
>>   These two are LUT/CLU:
>>  * dl->bodies[x]->num_entries 256 / max 256
>>  * dl->bodies[x]->num_entries 4914 / max 4914
>>
>> Which shows that our 'constant' configuration cache is currently
>> utilised to a maximum of 64 entries.
>>
>> trace-cmd report | \
>> grep max | sed 's/.*vsp1_dl_list_commit://g' | sort | uniq;
>>
>>   dl->body0->num_entries 13 / max 128
>>   dl->body0->num_entries 14 / max 128
>>   dl->body0->num_entries 16 / max 128
>>   dl->body0->num_entries 20 / max 128
>>   dl->body0->num_entries 27 / max 128
>>   dl->body0->num_entries 34 / max 128
>>   dl->body0->num_entries 41 / max 128
>>   dl_child->body0->num_entries 10 / max 128
>>   dl_child->body0->num_entries 12 / max 128
>>   dl->bodies[x]->num_entries 15 / max 128
>>   dl->bodies[x]->num_entries 16 / max 128
>>   dl->bodies[x]->num_entries 17 / max 128
>>   dl->bodies[x]->num_entries 18 / max 128
>>   dl->bodies[x]->num_entries 20 / max 128
>>   dl->bodies[x]->num_entries 21 / max 128
>>   dl->bodies[x]->num_entries 256 / max 256
>>   dl->bodies[x]->num_entries 31 / max 128
>>   dl->bodies[x]->num_entries 32 / max 128
>>   dl->bodies[x]->num_entries 39 / max 128
>>   dl->bodies[x]->num_entries 40 / max 128
>>   dl->bodies[x]->num_entries 47 / max 128
>>   dl->bodies[x]->num_entries 48 / max 128
>>   dl->bodies[x]->num_entries 4914 / max 4914
>>   dl->bodies[x]->num_entries 55 / max 128
>>   dl->bodies[x]->num_entries 56 / max 128
>>   dl->bodies[x]->num_entries 63 / max 128
>>   dl->bodies[x]->num_entries 64 / max 128
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
>> ---
>> v10:
>>  - Removed pipe->configured flag, and use
>>pipe->state == VSP1_PIPELINE_STOPPED instead.
>>
>> v8:
>>  - Fix comments
>>  - Rename video->pipe_config -> video->stream_config
>>
>> v4:
>>  - Adjust pipe configured flag to be reset on resume rather than suspend
>>  - rename dl_child, dl_next
>>
>> v3:
>>  - 's/fragment/body/', 's/fragments/bodies/'
>>  - video dlb cache allocation increased from 2 to 3 dlbs
>>
>>  drivers/media/platform/vsp1/vsp1_pipe.h  |  3 +-
>>  drivers/media/platform/vsp1/vsp1_video.c | 67 +++--
>>  drivers/media/platform/vsp1/vsp1_video.h |  2 +-
>>  3 files changed, 43 insertions(+), 29 deletions(-)
>>
>> diff --git a/drivers/media/platform/vsp1/vsp1_pipe.h
>> b/drivers/media/platform/vsp1/vsp1_pipe.h index e00010693eef..be6ecab3cbed
>> 100644
>> --- a/drivers/media/platform/vsp1/vsp1_pipe.h
>> +++ b/drivers/media/platform/vsp1/vsp1_pipe.h
>> @@ -102,7 +102,6 @@ struct vsp1_partition {
>>   * @uds: UDS entity, if present
>>   * @uds_input: entity at the input of the UDS, if the UDS is present
>>   * @entities: list of entities in the pipeline
>> - * @dl: display list associated with the pipeline
>>   * @partitions: The number of partitions used to process one frame
>>   * @partition: The current partition for configuration to process
>>   * @part_table: The pre-calculated partitions use

[PATCH v10 2/8] media: vsp1: Protect bodies against overflow

2018-05-17 Thread Kieran Bingham
The body write function relies on the code never asking it to write more
than the entries available in the list.

Currently with each list body containing 256 entries, this is fine, but
we can reduce this number greatly saving memory. In preparation of this
add a level of protection to catch any buffer overflows.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinch...@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_dl.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index 083da4f05c20..51965c30dec2 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -46,6 +46,7 @@ struct vsp1_dl_entry {
  * @dma: DMA address of the entries
  * @size: size of the DMA memory in bytes
  * @num_entries: number of stored entries
+ * @max_entries: number of entries available
  */
 struct vsp1_dl_body {
struct list_head list;
@@ -56,6 +57,7 @@ struct vsp1_dl_body {
size_t size;
 
unsigned int num_entries;
+   unsigned int max_entries;
 };
 
 /**
@@ -138,6 +140,7 @@ static int vsp1_dl_body_init(struct vsp1_device *vsp1,
 
dlb->vsp1 = vsp1;
dlb->size = size;
+   dlb->max_entries = num_entries;
 
dlb->entries = dma_alloc_wc(vsp1->bus_master, dlb->size, >dma,
GFP_KERNEL);
@@ -219,6 +222,10 @@ void vsp1_dl_body_free(struct vsp1_dl_body *dlb)
  */
 void vsp1_dl_body_write(struct vsp1_dl_body *dlb, u32 reg, u32 data)
 {
+   if (WARN_ONCE(dlb->num_entries >= dlb->max_entries,
+ "DLB size exceeded (max %u)", dlb->max_entries))
+   return;
+
dlb->entries[dlb->num_entries].addr = reg;
dlb->entries[dlb->num_entries].data = data;
dlb->num_entries++;
-- 
git-series 0.9.1


[PATCH v10 0/8] vsp1: TLB optimisation and DL caching

2018-05-17 Thread Kieran Bingham
esting active pipeline suspend/resume in suspend:core: pass
- vsp-unit-test-0021.sh
Testing WPF packing in RGB332 during stress testing: pass
Testing WPF packing in ARGB555 during stress testing: pass
Testing WPF packing in XRGB555 during stress testing: pass
Testing WPF packing in RGB565 during stress testing: pass
Testing WPF packing in BGR24 during stress testing: pass
Testing WPF packing in RGB24 during stress testing: pass
Testing WPF packing in ABGR32 during stress testing: pass
Testing WPF packing in ARGB32 during stress testing: pass
Testing WPF packing in XBGR32 during stress testing: pass
Testing WPF packing in XRGB32 during stress testing: pass
./vsp-unit-test-0021.sh: line 34: 25075 Killed  stress --cpu 8 
--io 4 --vm 2 --vm-bytes 128M
- vsp-unit-test-0022.sh
Testing long duration pipelines under stress: pass
./vsp-unit-test-0022.sh: line 38: 27041 Killed  stress --cpu 8 
--io 4 --vm 2 --vm-bytes 128M
- vsp-unit-test-0023.sh
Testing histogram HGT with hue areas 
0,255,255,255,255,255,255,255,255,255,255,255: pass
Testing histogram HGT with hue areas 0,40,40,80,80,120,120,160,160,200,200,255: 
pass
Testing histogram HGT with hue areas 
220,40,40,80,80,120,120,160,160,200,200,220: pass
Testing histogram HGT with hue areas 
0,10,50,60,100,110,150,160,200,210,250,255: pass
Testing histogram HGT with hue areas 
10,20,50,60,100,110,150,160,200,210,230,240: pass
Testing histogram HGT with hue areas 
240,20,60,80,100,120,140,160,180,200,210,220: pass
- vsp-unit-test-0024.sh
Test requires unavailable feature set `rpf.0 rpf.1 brs wpf.0': skipped
168 tests: 147 passed, 0 failed, 3 skipped

Kieran Bingham (8):
  media: vsp1: Reword uses of 'fragment' as 'body'
  media: vsp1: Protect bodies against overflow
  media: vsp1: Provide a body pool
  media: vsp1: Convert display lists to use new body pool
  media: vsp1: Use reference counting for bodies
  media: vsp1: Refactor display list configure operations
  media: vsp1: Adapt entities to configure into a body
  media: vsp1: Move video configuration to a cached dlb

 drivers/media/platform/vsp1/vsp1_brx.c|  32 +--
 drivers/media/platform/vsp1/vsp1_clu.c| 113 ---
 drivers/media/platform/vsp1/vsp1_clu.h|   1 +-
 drivers/media/platform/vsp1/vsp1_dl.c | 388 +--
 drivers/media/platform/vsp1/vsp1_dl.h |  20 +-
 drivers/media/platform/vsp1/vsp1_drm.c|  18 +-
 drivers/media/platform/vsp1/vsp1_entity.c |  34 +-
 drivers/media/platform/vsp1/vsp1_entity.h |  45 +--
 drivers/media/platform/vsp1/vsp1_hgo.c|  26 +--
 drivers/media/platform/vsp1/vsp1_hgt.c|  28 +--
 drivers/media/platform/vsp1/vsp1_hsit.c   |  20 +-
 drivers/media/platform/vsp1/vsp1_lif.c|  25 +-
 drivers/media/platform/vsp1/vsp1_lut.c|  80 +++--
 drivers/media/platform/vsp1/vsp1_lut.h|   1 +-
 drivers/media/platform/vsp1/vsp1_pipe.c   |   4 +-
 drivers/media/platform/vsp1/vsp1_pipe.h   |   6 +-
 drivers/media/platform/vsp1/vsp1_rpf.c| 189 +--
 drivers/media/platform/vsp1/vsp1_sru.c|  24 +-
 drivers/media/platform/vsp1/vsp1_uds.c|  73 ++--
 drivers/media/platform/vsp1/vsp1_uds.h|   2 +-
 drivers/media/platform/vsp1/vsp1_uif.c|  35 +--
 drivers/media/platform/vsp1/vsp1_video.c  |  89 ++---
 drivers/media/platform/vsp1/vsp1_video.h  |   2 +-
 drivers/media/platform/vsp1/vsp1_wpf.c| 326 ++-
 24 files changed, 870 insertions(+), 711 deletions(-)

base-commit: 7e6b6b945272c20f6b78d319e07f27897a8373c9
-- 
git-series 0.9.1


[PATCH v10 5/8] media: vsp1: Use reference counting for bodies

2018-05-17 Thread Kieran Bingham
Extend the display list body with a reference count, allowing bodies to
be kept as long as a reference is maintained. This provides the ability
to keep a cached copy of bodies which will not change, so that they can
be re-applied to multiple display lists.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_clu.c |  7 ++-
 drivers/media/platform/vsp1/vsp1_dl.c  | 16 ++--
 drivers/media/platform/vsp1/vsp1_lut.c |  7 ++-
 3 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_clu.c 
b/drivers/media/platform/vsp1/vsp1_clu.c
index 8efa12f5e53f..ea83f1b7d125 100644
--- a/drivers/media/platform/vsp1/vsp1_clu.c
+++ b/drivers/media/platform/vsp1/vsp1_clu.c
@@ -212,8 +212,13 @@ static void clu_configure(struct vsp1_entity *entity,
clu->clu = NULL;
spin_unlock_irqrestore(>lock, flags);
 
-   if (dlb)
+   if (dlb) {
vsp1_dl_list_add_body(dl, dlb);
+
+   /* Release our local reference. */
+   vsp1_dl_body_put(dlb);
+   }
+
break;
}
 }
diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index 617c46a03dec..1407c90c6880 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -54,6 +55,8 @@ struct vsp1_dl_body {
struct list_head list;
struct list_head free;
 
+   refcount_t refcnt;
+
struct vsp1_dl_body_pool *pool;
struct vsp1_device *vsp1;
 
@@ -258,6 +261,7 @@ struct vsp1_dl_body *vsp1_dl_body_get(struct 
vsp1_dl_body_pool *pool)
if (!list_empty(>free)) {
dlb = list_first_entry(>free, struct vsp1_dl_body, free);
list_del(>free);
+   refcount_set(>refcnt, 1);
}
 
spin_unlock_irqrestore(>lock, flags);
@@ -278,6 +282,9 @@ void vsp1_dl_body_put(struct vsp1_dl_body *dlb)
if (!dlb)
return;
 
+   if (!refcount_dec_and_test(>refcnt))
+   return;
+
dlb->num_entries = 0;
 
spin_lock_irqsave(>pool->lock, flags);
@@ -463,8 +470,11 @@ void vsp1_dl_list_write(struct vsp1_dl_list *dl, u32 reg, 
u32 data)
  * which bodies are added.
  *
  * Adding a body to a display list passes ownership of the body to the list. 
The
- * caller must not touch the body after this call, and must not release it
- * explicitly with vsp1_dl_body_put().
+ * caller retains its reference to the fragment when adding it to the display
+ * list, but is not allowed to add new entries to the body.
+ *
+ * The reference must be explicitly released by a call to vsp1_dl_body_put()
+ * when the body isn't needed anymore.
  *
  * Additional bodies are only usable for display lists in header mode.
  * Attempting to add a body to a header-less display list will return an error.
@@ -475,6 +485,8 @@ int vsp1_dl_list_add_body(struct vsp1_dl_list *dl, struct 
vsp1_dl_body *dlb)
if (dl->dlm->mode != VSP1_DL_MODE_HEADER)
return -EINVAL;
 
+   refcount_inc(>refcnt);
+
list_add_tail(>list, >bodies);
 
return 0;
diff --git a/drivers/media/platform/vsp1/vsp1_lut.c 
b/drivers/media/platform/vsp1/vsp1_lut.c
index 6b358617ce15..b3ea90172439 100644
--- a/drivers/media/platform/vsp1/vsp1_lut.c
+++ b/drivers/media/platform/vsp1/vsp1_lut.c
@@ -168,8 +168,13 @@ static void lut_configure(struct vsp1_entity *entity,
lut->lut = NULL;
spin_unlock_irqrestore(>lock, flags);
 
-   if (dlb)
+   if (dlb) {
vsp1_dl_list_add_body(dl, dlb);
+
+   /* Release our local reference. */
+   vsp1_dl_body_put(dlb);
+   }
+
break;
}
 }
-- 
git-series 0.9.1


[PATCH v10 7/8] media: vsp1: Adapt entities to configure into a body

2018-05-17 Thread Kieran Bingham
Currently the entities store their configurations into a display list.
Adapt this such that the code can be configured into a body directly,
allowing greater flexibility and control of the content.

All users of vsp1_dl_list_write() are removed in this process, thus it
too is removed.

A helper, vsp1_dl_list_get_body0() is provided to access the internal body0
from the display list.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
[Don't remove blank line unnecessarily]
Reviewed-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_brx.c| 22 ++--
 drivers/media/platform/vsp1/vsp1_clu.c| 23 ++---
 drivers/media/platform/vsp1/vsp1_dl.c | 12 ++-
 drivers/media/platform/vsp1/vsp1_dl.h |  2 +-
 drivers/media/platform/vsp1/vsp1_drm.c| 12 ---
 drivers/media/platform/vsp1/vsp1_entity.c | 22 ++--
 drivers/media/platform/vsp1/vsp1_entity.h | 18 ++
 drivers/media/platform/vsp1/vsp1_hgo.c| 16 -
 drivers/media/platform/vsp1/vsp1_hgt.c| 18 +-
 drivers/media/platform/vsp1/vsp1_hsit.c   | 10 +++---
 drivers/media/platform/vsp1/vsp1_lif.c| 15 
 drivers/media/platform/vsp1/vsp1_lut.c| 23 ++---
 drivers/media/platform/vsp1/vsp1_pipe.c   |  4 +-
 drivers/media/platform/vsp1/vsp1_pipe.h   |  3 +-
 drivers/media/platform/vsp1/vsp1_rpf.c| 43 
 drivers/media/platform/vsp1/vsp1_sru.c| 14 
 drivers/media/platform/vsp1/vsp1_uds.c| 25 +++---
 drivers/media/platform/vsp1/vsp1_uds.h|  2 +-
 drivers/media/platform/vsp1/vsp1_uif.c| 21 ++--
 drivers/media/platform/vsp1/vsp1_video.c  | 16 ++---
 drivers/media/platform/vsp1/vsp1_wpf.c| 42 ---
 21 files changed, 194 insertions(+), 169 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_brx.c 
b/drivers/media/platform/vsp1/vsp1_brx.c
index 011edac5ebc1..359917b5d842 100644
--- a/drivers/media/platform/vsp1/vsp1_brx.c
+++ b/drivers/media/platform/vsp1/vsp1_brx.c
@@ -26,10 +26,10 @@
  * Device Access
  */
 
-static inline void vsp1_brx_write(struct vsp1_brx *brx, struct vsp1_dl_list 
*dl,
- u32 reg, u32 data)
+static inline void vsp1_brx_write(struct vsp1_brx *brx,
+ struct vsp1_dl_body *dlb, u32 reg, u32 data)
 {
-   vsp1_dl_list_write(dl, brx->base + reg, data);
+   vsp1_dl_body_write(dlb, brx->base + reg, data);
 }
 
 /* 
-
@@ -283,7 +283,7 @@ static const struct v4l2_subdev_ops brx_ops = {
 
 static void brx_configure_stream(struct vsp1_entity *entity,
 struct vsp1_pipeline *pipe,
-struct vsp1_dl_list *dl)
+struct vsp1_dl_body *dlb)
 {
struct vsp1_brx *brx = to_brx(>subdev);
struct v4l2_mbus_framefmt *format;
@@ -305,7 +305,7 @@ static void brx_configure_stream(struct vsp1_entity *entity,
 * format at the pipeline output is premultiplied.
 */
flags = pipe->output ? pipe->output->format.flags : 0;
-   vsp1_brx_write(brx, dl, VI6_BRU_INCTRL,
+   vsp1_brx_write(brx, dlb, VI6_BRU_INCTRL,
   flags & V4L2_PIX_FMT_FLAG_PREMUL_ALPHA ?
   0 : VI6_BRU_INCTRL_NRM);
 
@@ -313,12 +313,12 @@ static void brx_configure_stream(struct vsp1_entity 
*entity,
 * Set the background position to cover the whole output image and
 * configure its color.
 */
-   vsp1_brx_write(brx, dl, VI6_BRU_VIRRPF_SIZE,
+   vsp1_brx_write(brx, dlb, VI6_BRU_VIRRPF_SIZE,
   (format->width << VI6_BRU_VIRRPF_SIZE_HSIZE_SHIFT) |
   (format->height << VI6_BRU_VIRRPF_SIZE_VSIZE_SHIFT));
-   vsp1_brx_write(brx, dl, VI6_BRU_VIRRPF_LOC, 0);
+   vsp1_brx_write(brx, dlb, VI6_BRU_VIRRPF_LOC, 0);
 
-   vsp1_brx_write(brx, dl, VI6_BRU_VIRRPF_COL, brx->bgcolor |
+   vsp1_brx_write(brx, dlb, VI6_BRU_VIRRPF_COL, brx->bgcolor |
   (0xff << VI6_BRU_VIRRPF_COL_A_SHIFT));
 
/*
@@ -328,7 +328,7 @@ static void brx_configure_stream(struct vsp1_entity *entity,
 * unit.
 */
if (entity->type == VSP1_ENTITY_BRU)
-   vsp1_brx_write(brx, dl, VI6_BRU_ROP,
+   vsp1_brx_write(brx, dlb, VI6_BRU_ROP,
   VI6_BRU_ROP_DSTSEL_BRUIN(1) |
   VI6_BRU_ROP_CROP(VI6_ROP_NOP) |
   VI6_BRU_ROP_AROP(VI6_ROP_NOP));
@@ -370,7 +370,7 @@ static void brx_configure_stream(struct vsp1_entity *entity,
if (!(entity->type == VSP1_ENTITY_BRU && i == 1))
  

[PATCH v10 3/8] media: vsp1: Provide a body pool

2018-05-17 Thread Kieran Bingham
Each display list allocates a body to store register values in a dma
accessible buffer from a dma_alloc_wc() allocation. Each of these
results in an entry in the IOMMU TLB, and a large number of display list
allocations adds pressure to this resource.

Reduce TLB pressure on the IPMMUs by allocating multiple display list
bodies in a single allocation, and providing these to the display list
through a 'body pool'. A pool can be allocated by the display list
manager or entities which require their own body allocations.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_dl.c | 163 +++-
 drivers/media/platform/vsp1/vsp1_dl.h |   8 +-
 2 files changed, 171 insertions(+)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index 51965c30dec2..41ace89a585b 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -41,6 +41,8 @@ struct vsp1_dl_entry {
 /**
  * struct vsp1_dl_body - Display list body
  * @list: entry in the display list list of bodies
+ * @free: entry in the pool free body list
+ * @pool: pool to which this body belongs
  * @vsp1: the VSP1 device
  * @entries: array of entries
  * @dma: DMA address of the entries
@@ -50,6 +52,9 @@ struct vsp1_dl_entry {
  */
 struct vsp1_dl_body {
struct list_head list;
+   struct list_head free;
+
+   struct vsp1_dl_body_pool *pool;
struct vsp1_device *vsp1;
 
struct vsp1_dl_entry *entries;
@@ -61,6 +66,30 @@ struct vsp1_dl_body {
 };
 
 /**
+ * struct vsp1_dl_body_pool - display list body pool
+ * @dma: DMA address of the entries
+ * @size: size of the full DMA memory pool in bytes
+ * @mem: CPU memory pointer for the pool
+ * @bodies: Array of DLB structures for the pool
+ * @free: List of free DLB entries
+ * @lock: Protects the free list
+ * @vsp1: the VSP1 device
+ */
+struct vsp1_dl_body_pool {
+   /* DMA allocation */
+   dma_addr_t dma;
+   size_t size;
+   void *mem;
+
+   /* Body management */
+   struct vsp1_dl_body *bodies;
+   struct list_head free;
+   spinlock_t lock;
+
+   struct vsp1_device *vsp1;
+};
+
+/**
  * struct vsp1_dl_list - Display list
  * @list: entry in the display list manager lists
  * @dlm: the display list manager
@@ -104,6 +133,7 @@ enum vsp1_dl_mode {
  * @active: list currently being processed (loaded) by hardware
  * @queued: list queued to the hardware (written to the DL registers)
  * @pending: list waiting to be queued to the hardware
+ * @pool: body pool for the display list bodies
  * @gc_work: bodies garbage collector work struct
  * @gc_bodies: array of display list bodies waiting to be freed
  */
@@ -119,6 +149,8 @@ struct vsp1_dl_manager {
struct vsp1_dl_list *queued;
struct vsp1_dl_list *pending;
 
+   struct vsp1_dl_body_pool *pool;
+
struct work_struct gc_work;
struct list_head gc_bodies;
 };
@@ -127,6 +159,137 @@ struct vsp1_dl_manager {
  * Display List Body Management
  */
 
+/**
+ * vsp1_dl_body_pool_create - Create a pool of bodies from a single allocation
+ * @vsp1: The VSP1 device
+ * @num_bodies: The number of bodies to allocate
+ * @num_entries: The maximum number of entries that a body can contain
+ * @extra_size: Extra allocation provided for the bodies
+ *
+ * Allocate a pool of display list bodies each with enough memory to contain 
the
+ * requested number of entries plus the @extra_size.
+ *
+ * Return a pointer to a pool on success or NULL if memory can't be allocated.
+ */
+struct vsp1_dl_body_pool *
+vsp1_dl_body_pool_create(struct vsp1_device *vsp1, unsigned int num_bodies,
+unsigned int num_entries, size_t extra_size)
+{
+   struct vsp1_dl_body_pool *pool;
+   size_t dlb_size;
+   unsigned int i;
+
+   pool = kzalloc(sizeof(*pool), GFP_KERNEL);
+   if (!pool)
+   return NULL;
+
+   pool->vsp1 = vsp1;
+
+   /*
+* TODO: 'extra_size' is only used by vsp1_dlm_create(), to allocate
+* extra memory for the display list header. We need only one header per
+* display list, not per display list body, thus this allocation is
+* extraneous and should be reworked in the future.
+*/
+   dlb_size = num_entries * sizeof(struct vsp1_dl_entry) + extra_size;
+   pool->size = dlb_size * num_bodies;
+
+   pool->bodies = kcalloc(num_bodies, sizeof(*pool->bodies), GFP_KERNEL);
+   if (!pool->bodies) {
+   kfree(pool);
+   return NULL;
+   }
+
+   pool->mem = dma_alloc_wc(vsp1->bus_master, pool->size, >dma,
+GFP_KERNEL);
+   if (!pool->mem) {
+  

[PATCH v10 8/8] media: vsp1: Move video configuration to a cached dlb

2018-05-17 Thread Kieran Bingham
We are now able to configure a pipeline directly into a local display
list body. Take advantage of this fact, and create a cacheable body to
store the configuration of the pipeline in the video object.

vsp1_video_pipeline_run() is now the last user of the pipe->dl object.
Convert this function to use the cached video->config body and obtain a
local display list reference.

Attach the video->config body to the display list when needed before
committing to hardware.

The pipe object is marked as un-configured when resuming from a suspend.
This ensures that when the hardware is reset - our cached configuration
will be re-attached to the next committed DL.

Our video DL usage now looks like the below output:

dl->body0 contains our disposable runtime configuration. Max 41.
dl_child->body0 is our partition specific configuration. Max 12.
dl->bodies shows our constant configuration and LUTs.

  These two are LUT/CLU:
 * dl->bodies[x]->num_entries 256 / max 256
 * dl->bodies[x]->num_entries 4914 / max 4914

Which shows that our 'constant' configuration cache is currently
utilised to a maximum of 64 entries.

trace-cmd report | \
grep max | sed 's/.*vsp1_dl_list_commit://g' | sort | uniq;

  dl->body0->num_entries 13 / max 128
  dl->body0->num_entries 14 / max 128
  dl->body0->num_entries 16 / max 128
  dl->body0->num_entries 20 / max 128
  dl->body0->num_entries 27 / max 128
  dl->body0->num_entries 34 / max 128
  dl->body0->num_entries 41 / max 128
  dl_child->body0->num_entries 10 / max 128
  dl_child->body0->num_entries 12 / max 128
  dl->bodies[x]->num_entries 15 / max 128
  dl->bodies[x]->num_entries 16 / max 128
  dl->bodies[x]->num_entries 17 / max 128
  dl->bodies[x]->num_entries 18 / max 128
  dl->bodies[x]->num_entries 20 / max 128
  dl->bodies[x]->num_entries 21 / max 128
  dl->bodies[x]->num_entries 256 / max 256
  dl->bodies[x]->num_entries 31 / max 128
  dl->bodies[x]->num_entries 32 / max 128
  dl->bodies[x]->num_entries 39 / max 128
  dl->bodies[x]->num_entries 40 / max 128
  dl->bodies[x]->num_entries 47 / max 128
  dl->bodies[x]->num_entries 48 / max 128
  dl->bodies[x]->num_entries 4914 / max 4914
  dl->bodies[x]->num_entries 55 / max 128
  dl->bodies[x]->num_entries 56 / max 128
  dl->bodies[x]->num_entries 63 / max 128
  dl->bodies[x]->num_entries 64 / max 128

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
v10:
 - Removed pipe->configured flag, and use
   pipe->state == VSP1_PIPELINE_STOPPED instead.

v8:
 - Fix comments
 - Rename video->pipe_config -> video->stream_config

v4:
 - Adjust pipe configured flag to be reset on resume rather than suspend
 - rename dl_child, dl_next

v3:
 - 's/fragment/body/', 's/fragments/bodies/'
 - video dlb cache allocation increased from 2 to 3 dlbs

 drivers/media/platform/vsp1/vsp1_pipe.h  |  3 +-
 drivers/media/platform/vsp1/vsp1_video.c | 67 +++--
 drivers/media/platform/vsp1/vsp1_video.h |  2 +-
 3 files changed, 43 insertions(+), 29 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_pipe.h 
b/drivers/media/platform/vsp1/vsp1_pipe.h
index e00010693eef..be6ecab3cbed 100644
--- a/drivers/media/platform/vsp1/vsp1_pipe.h
+++ b/drivers/media/platform/vsp1/vsp1_pipe.h
@@ -102,7 +102,6 @@ struct vsp1_partition {
  * @uds: UDS entity, if present
  * @uds_input: entity at the input of the UDS, if the UDS is present
  * @entities: list of entities in the pipeline
- * @dl: display list associated with the pipeline
  * @partitions: The number of partitions used to process one frame
  * @partition: The current partition for configuration to process
  * @part_table: The pre-calculated partitions used by the pipeline
@@ -139,8 +138,6 @@ struct vsp1_pipeline {
 */
struct list_head entities;
 
-   struct vsp1_dl_list *dl;
-
unsigned int partitions;
struct vsp1_partition *partition;
struct vsp1_partition *part_table;
diff --git a/drivers/media/platform/vsp1/vsp1_video.c 
b/drivers/media/platform/vsp1/vsp1_video.c
index 72f29773eb1c..f2bc26d28396 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -390,44 +390,48 @@ static void vsp1_video_pipeline_run_partition(struct 
vsp1_pipeline *pipe,
 static void vsp1_video_pipeline_run(struct vsp1_pipeline *pipe)
 {
struct vsp1_device *vsp1 = pipe->output->entity.vsp1;
+   struct vsp1_video *video = pipe->output->video;
struct vsp1_entity *entity;
struct vsp1_dl_body *dlb;
+   struct vsp1_dl_list *dl;
unsigned int partition;
 
-   if (!pipe->dl)
-   pipe->dl = vsp1_dl_list_get(pipe->output->dlm);
+   dl = vsp1_dl_list_get(pipe->output->dlm);
+
+   /* 

[PATCH v10 4/8] media: vsp1: Convert display lists to use new body pool

2018-05-17 Thread Kieran Bingham
Adapt the dl->body0 object to use an object from the body pool. This
greatly reduces the pressure on the TLB for IPMMU use cases, as all of
the lists use a single allocation for the main body.

The CLU and LUT objects pre-allocate a pool containing three bodies,
allowing a userspace update before the hardware has committed a previous
set of tables.

Bodies are no longer 'freed' in interrupt context, but instead released
back to their respective pools. This allows us to remove the garbage
collector in the DLM.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_clu.c |  27 ++-
 drivers/media/platform/vsp1/vsp1_clu.h |   1 +-
 drivers/media/platform/vsp1/vsp1_dl.c  | 221 ++
 drivers/media/platform/vsp1/vsp1_dl.h  |   3 +-
 drivers/media/platform/vsp1/vsp1_lut.c |  27 ++-
 drivers/media/platform/vsp1/vsp1_lut.h |   1 +-
 6 files changed, 100 insertions(+), 180 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_clu.c 
b/drivers/media/platform/vsp1/vsp1_clu.c
index ebfbb915dcdc..8efa12f5e53f 100644
--- a/drivers/media/platform/vsp1/vsp1_clu.c
+++ b/drivers/media/platform/vsp1/vsp1_clu.c
@@ -19,6 +19,8 @@
 #define CLU_MIN_SIZE   4U
 #define CLU_MAX_SIZE   8190U
 
+#define CLU_SIZE   (17 * 17 * 17)
+
 /* 
-
  * Device Access
  */
@@ -43,19 +45,19 @@ static int clu_set_table(struct vsp1_clu *clu, struct 
v4l2_ctrl *ctrl)
struct vsp1_dl_body *dlb;
unsigned int i;
 
-   dlb = vsp1_dl_body_alloc(clu->entity.vsp1, 1 + 17 * 17 * 17);
+   dlb = vsp1_dl_body_get(clu->pool);
if (!dlb)
return -ENOMEM;
 
vsp1_dl_body_write(dlb, VI6_CLU_ADDR, 0);
-   for (i = 0; i < 17 * 17 * 17; ++i)
+   for (i = 0; i < CLU_SIZE; ++i)
vsp1_dl_body_write(dlb, VI6_CLU_DATA, ctrl->p_new.p_u32[i]);
 
spin_lock_irq(>lock);
swap(clu->clu, dlb);
spin_unlock_irq(>lock);
 
-   vsp1_dl_body_free(dlb);
+   vsp1_dl_body_put(dlb);
return 0;
 }
 
@@ -216,8 +218,16 @@ static void clu_configure(struct vsp1_entity *entity,
}
 }
 
+static void clu_destroy(struct vsp1_entity *entity)
+{
+   struct vsp1_clu *clu = to_clu(>subdev);
+
+   vsp1_dl_body_pool_destroy(clu->pool);
+}
+
 static const struct vsp1_entity_operations clu_entity_ops = {
.configure = clu_configure,
+   .destroy = clu_destroy,
 };
 
 /* 
-
@@ -243,6 +253,17 @@ struct vsp1_clu *vsp1_clu_create(struct vsp1_device *vsp1)
if (ret < 0)
return ERR_PTR(ret);
 
+   /*
+* Pre-allocate a body pool, with 3 bodies allowing a userspace update
+* before the hardware has committed a previous set of tables, handling
+* both the queued and pending dl entries. One extra entry is added to
+* the CLU_SIZE to allow for the VI6_CLU_ADDR header.
+*/
+   clu->pool = vsp1_dl_body_pool_create(clu->entity.vsp1, 3, CLU_SIZE + 1,
+0);
+   if (!clu->pool)
+   return ERR_PTR(-ENOMEM);
+
/* Initialize the control handler. */
v4l2_ctrl_handler_init(>ctrls, 2);
v4l2_ctrl_new_custom(>ctrls, _table_control, NULL);
diff --git a/drivers/media/platform/vsp1/vsp1_clu.h 
b/drivers/media/platform/vsp1/vsp1_clu.h
index c45e6e707592..cef2f44481ba 100644
--- a/drivers/media/platform/vsp1/vsp1_clu.h
+++ b/drivers/media/platform/vsp1/vsp1_clu.h
@@ -32,6 +32,7 @@ struct vsp1_clu {
spinlock_t lock;
unsigned int mode;
struct vsp1_dl_body *clu;
+   struct vsp1_dl_body_pool *pool;
 };
 
 static inline struct vsp1_clu *to_clu(struct v4l2_subdev *subdev)
diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index 41ace89a585b..617c46a03dec 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -108,7 +108,7 @@ struct vsp1_dl_list {
struct vsp1_dl_header *header;
dma_addr_t dma;
 
-   struct vsp1_dl_body body0;
+   struct vsp1_dl_body *body0;
struct list_head bodies;
 
bool has_chain;
@@ -128,14 +128,12 @@ enum vsp1_dl_mode {
  * @mode: display list operation mode (header or headerless)
  * @singleshot: execute the display list in single-shot mode
  * @vsp1: the VSP1 device
- * @lock: protects the free, active, queued, pending and gc_bodies lists
+ * @lock: protects the free, active, queued, and pending lists
  * @free: array of all free display lists
  * @active: list cu

[PATCH v10 6/8] media: vsp1: Refactor display list configure operations

2018-05-17 Thread Kieran Bingham
The entities provide a single .configure operation which configures the
object into the target display list, based on the vsp1_entity_params
selection.

Split the configure function into three parts, '.configure_stream()',
'.configure_frame()', and '.configure_partition()' to facilitate
splitting the configuration of each parameter class into separate
display list bodies.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
[Blank line reformatting, remote unneeded local variable initialization]
Reviewed-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_brx.c|  12 +-
 drivers/media/platform/vsp1/vsp1_clu.c|  78 ++
 drivers/media/platform/vsp1/vsp1_drm.c|  12 +-
 drivers/media/platform/vsp1/vsp1_entity.c |  24 ++-
 drivers/media/platform/vsp1/vsp1_entity.h |  39 +--
 drivers/media/platform/vsp1/vsp1_hgo.c|  12 +-
 drivers/media/platform/vsp1/vsp1_hgt.c|  12 +-
 drivers/media/platform/vsp1/vsp1_hsit.c   |  12 +-
 drivers/media/platform/vsp1/vsp1_lif.c|  12 +-
 drivers/media/platform/vsp1/vsp1_lut.c|  47 +---
 drivers/media/platform/vsp1/vsp1_rpf.c| 168 ++---
 drivers/media/platform/vsp1/vsp1_sru.c|  12 +-
 drivers/media/platform/vsp1/vsp1_uds.c|  56 ++--
 drivers/media/platform/vsp1/vsp1_uif.c|  16 +-
 drivers/media/platform/vsp1/vsp1_video.c  |  28 +--
 drivers/media/platform/vsp1/vsp1_wpf.c| 302 ---
 16 files changed, 422 insertions(+), 420 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_brx.c 
b/drivers/media/platform/vsp1/vsp1_brx.c
index 3beec18fd863..011edac5ebc1 100644
--- a/drivers/media/platform/vsp1/vsp1_brx.c
+++ b/drivers/media/platform/vsp1/vsp1_brx.c
@@ -281,19 +281,15 @@ static const struct v4l2_subdev_ops brx_ops = {
  * VSP1 Entity Operations
  */
 
-static void brx_configure(struct vsp1_entity *entity,
- struct vsp1_pipeline *pipe,
- struct vsp1_dl_list *dl,
- enum vsp1_entity_params params)
+static void brx_configure_stream(struct vsp1_entity *entity,
+struct vsp1_pipeline *pipe,
+struct vsp1_dl_list *dl)
 {
struct vsp1_brx *brx = to_brx(>subdev);
struct v4l2_mbus_framefmt *format;
unsigned int flags;
unsigned int i;
 
-   if (params != VSP1_ENTITY_PARAMS_INIT)
-   return;
-
format = vsp1_entity_get_pad_format(>entity, brx->entity.config,
brx->entity.source_pad);
 
@@ -400,7 +396,7 @@ static void brx_configure(struct vsp1_entity *entity,
 }
 
 static const struct vsp1_entity_operations brx_entity_ops = {
-   .configure = brx_configure,
+   .configure_stream = brx_configure_stream,
 };
 
 /* 
-
diff --git a/drivers/media/platform/vsp1/vsp1_clu.c 
b/drivers/media/platform/vsp1/vsp1_clu.c
index ea83f1b7d125..34f17a82ac1f 100644
--- a/drivers/media/platform/vsp1/vsp1_clu.c
+++ b/drivers/media/platform/vsp1/vsp1_clu.c
@@ -169,57 +169,50 @@ static const struct v4l2_subdev_ops clu_ops = {
  * VSP1 Entity Operations
  */
 
-static void clu_configure(struct vsp1_entity *entity,
- struct vsp1_pipeline *pipe,
- struct vsp1_dl_list *dl,
- enum vsp1_entity_params params)
+static void clu_configure_stream(struct vsp1_entity *entity,
+struct vsp1_pipeline *pipe,
+struct vsp1_dl_list *dl)
+{
+   struct vsp1_clu *clu = to_clu(>subdev);
+   struct v4l2_mbus_framefmt *format;
+
+   /*
+* The yuv_mode can't be changed during streaming. Cache it internally
+* for future runtime configuration calls.
+*/
+   format = vsp1_entity_get_pad_format(>entity,
+   clu->entity.config,
+   CLU_PAD_SINK);
+   clu->yuv_mode = format->code == MEDIA_BUS_FMT_AYUV8_1X32;
+}
+
+static void clu_configure_frame(struct vsp1_entity *entity,
+   struct vsp1_pipeline *pipe,
+   struct vsp1_dl_list *dl)
 {
struct vsp1_clu *clu = to_clu(>subdev);
struct vsp1_dl_body *dlb;
unsigned long flags;
u32 ctrl = VI6_CLU_CTRL_AAI | VI6_CLU_CTRL_MVS | VI6_CLU_CTRL_EN;
 
-   switch (params) {
-   case VSP1_ENTITY_PARAMS_INIT: {
-   /*
-* The format can't be changed during streaming, only verify it
-* at setup time and store the information internally for future
-* runtime configuration calls.
-*/
-   struct v4l2

[PATCH v10 1/8] media: vsp1: Reword uses of 'fragment' as 'body'

2018-05-17 Thread Kieran Bingham
Throughout the codebase, the term 'fragment' is used to represent a
display list body. This term duplicates the 'body' which is already in
use.

The datasheet references these objects as a body, therefore replace all
mentions of a fragment with a body, along with the corresponding
pluralised terms.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_clu.c |  10 +-
 drivers/media/platform/vsp1/vsp1_dl.c  | 111 --
 drivers/media/platform/vsp1/vsp1_dl.h  |  13 +--
 drivers/media/platform/vsp1/vsp1_lut.c |   8 +-
 4 files changed, 70 insertions(+), 72 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_clu.c 
b/drivers/media/platform/vsp1/vsp1_clu.c
index 96a448e1504c..ebfbb915dcdc 100644
--- a/drivers/media/platform/vsp1/vsp1_clu.c
+++ b/drivers/media/platform/vsp1/vsp1_clu.c
@@ -43,19 +43,19 @@ static int clu_set_table(struct vsp1_clu *clu, struct 
v4l2_ctrl *ctrl)
struct vsp1_dl_body *dlb;
unsigned int i;
 
-   dlb = vsp1_dl_fragment_alloc(clu->entity.vsp1, 1 + 17 * 17 * 17);
+   dlb = vsp1_dl_body_alloc(clu->entity.vsp1, 1 + 17 * 17 * 17);
if (!dlb)
return -ENOMEM;
 
-   vsp1_dl_fragment_write(dlb, VI6_CLU_ADDR, 0);
+   vsp1_dl_body_write(dlb, VI6_CLU_ADDR, 0);
for (i = 0; i < 17 * 17 * 17; ++i)
-   vsp1_dl_fragment_write(dlb, VI6_CLU_DATA, ctrl->p_new.p_u32[i]);
+   vsp1_dl_body_write(dlb, VI6_CLU_DATA, ctrl->p_new.p_u32[i]);
 
spin_lock_irq(>lock);
swap(clu->clu, dlb);
spin_unlock_irq(>lock);
 
-   vsp1_dl_fragment_free(dlb);
+   vsp1_dl_body_free(dlb);
return 0;
 }
 
@@ -211,7 +211,7 @@ static void clu_configure(struct vsp1_entity *entity,
spin_unlock_irqrestore(>lock, flags);
 
if (dlb)
-   vsp1_dl_list_add_fragment(dl, dlb);
+   vsp1_dl_list_add_body(dl, dlb);
break;
}
 }
diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index 801dea475740..083da4f05c20 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -65,7 +65,7 @@ struct vsp1_dl_body {
  * @header: display list header, NULL for headerless lists
  * @dma: DMA address for the header
  * @body0: first display list body
- * @fragments: list of extra display list bodies
+ * @bodies: list of extra display list bodies
  * @has_chain: if true, indicates that there's a partition chain
  * @chain: entry in the display list partition chain
  * @internal: whether the display list is used for internal purpose
@@ -78,7 +78,7 @@ struct vsp1_dl_list {
dma_addr_t dma;
 
struct vsp1_dl_body body0;
-   struct list_head fragments;
+   struct list_head bodies;
 
bool has_chain;
struct list_head chain;
@@ -97,13 +97,13 @@ enum vsp1_dl_mode {
  * @mode: display list operation mode (header or headerless)
  * @singleshot: execute the display list in single-shot mode
  * @vsp1: the VSP1 device
- * @lock: protects the free, active, queued, pending and gc_fragments lists
+ * @lock: protects the free, active, queued, pending and gc_bodies lists
  * @free: array of all free display lists
  * @active: list currently being processed (loaded) by hardware
  * @queued: list queued to the hardware (written to the DL registers)
  * @pending: list waiting to be queued to the hardware
- * @gc_work: fragments garbage collector work struct
- * @gc_fragments: array of display list fragments waiting to be freed
+ * @gc_work: bodies garbage collector work struct
+ * @gc_bodies: array of display list bodies waiting to be freed
  */
 struct vsp1_dl_manager {
unsigned int index;
@@ -118,7 +118,7 @@ struct vsp1_dl_manager {
struct vsp1_dl_list *pending;
 
struct work_struct gc_work;
-   struct list_head gc_fragments;
+   struct list_head gc_bodies;
 };
 
 /* 
-
@@ -156,18 +156,17 @@ static void vsp1_dl_body_cleanup(struct vsp1_dl_body *dlb)
 }
 
 /**
- * vsp1_dl_fragment_alloc - Allocate a display list fragment
+ * vsp1_dl_body_alloc - Allocate a display list body
  * @vsp1: The VSP1 device
- * @num_entries: The maximum number of entries that the fragment can contain
+ * @num_entries: The maximum number of entries that the body can contain
  *
- * Allocate a display list fragment with enough memory to contain the requested
+ * Allocate a display list body with enough memory to contain the requested
  * number of entries.
  *
- * Return a pointer to a fragment on success or NULL if memory can't be
- * allocated.
+ * Return a pointer to a body on success or NU

Re: [PATCH v7 8/8] media: vsp1: Move video configuration to a cached dlb

2018-05-17 Thread Kieran Bingham
Hi Laurent,

On 17/05/18 15:35, Laurent Pinchart wrote:
> Hi Kieran,
> 
> On Monday, 30 April 2018 20:48:03 EEST Kieran Bingham wrote:
>> On 07/04/18 01:23, Laurent Pinchart wrote:
>>> On Thursday, 8 March 2018 02:05:31 EEST Kieran Bingham wrote:
>>>> We are now able to configure a pipeline directly into a local display
>>>> list body. Take advantage of this fact, and create a cacheable body to
>>>> store the configuration of the pipeline in the video object.
>>>>
>>>> vsp1_video_pipeline_run() is now the last user of the pipe->dl object.
>>>> Convert this function to use the cached video->config body and obtain a
>>>> local display list reference.
>>>>
>>>> Attach the video->config body to the display list when needed before
>>>> committing to hardware.
>>>>
>>>> The pipe object is marked as un-configured when resuming from a suspend.
>>>> This ensures that when the hardware is reset - our cached configuration
>>>> will be re-attached to the next committed DL.
>>>>
>>>> Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
>>>> ---
>>>>
>>>> v3:
>>>>  - 's/fragment/body/', 's/fragments/bodies/'
>>>>  - video dlb cache allocation increased from 2 to 3 dlbs
>>>>
>>>> Our video DL usage now looks like the below output:
>>>>
>>>> dl->body0 contains our disposable runtime configuration. Max 41.
>>>> dl_child->body0 is our partition specific configuration. Max 12.
>>>> dl->bodies shows our constant configuration and LUTs.
>>>>
>>>>   These two are LUT/CLU:
>>>>  * dl->bodies[x]->num_entries 256 / max 256
>>>>  * dl->bodies[x]->num_entries 4914 / max 4914
>>>>
>>>> Which shows that our 'constant' configuration cache is currently
>>>> utilised to a maximum of 64 entries.
>>>>
>>>> trace-cmd report | \
>>>>
>>>> grep max | sed 's/.*vsp1_dl_list_commit://g' | sort | uniq;
>>>>   
>>>>   dl->body0->num_entries 13 / max 128
>>>>   dl->body0->num_entries 14 / max 128
>>>>   dl->body0->num_entries 16 / max 128
>>>>   dl->body0->num_entries 20 / max 128
>>>>   dl->body0->num_entries 27 / max 128
>>>>   dl->body0->num_entries 34 / max 128
>>>>   dl->body0->num_entries 41 / max 128
>>>>   dl_child->body0->num_entries 10 / max 128
>>>>   dl_child->body0->num_entries 12 / max 128
>>>>   dl->bodies[x]->num_entries 15 / max 128
>>>>   dl->bodies[x]->num_entries 16 / max 128
>>>>   dl->bodies[x]->num_entries 17 / max 128
>>>>   dl->bodies[x]->num_entries 18 / max 128
>>>>   dl->bodies[x]->num_entries 20 / max 128
>>>>   dl->bodies[x]->num_entries 21 / max 128
>>>>   dl->bodies[x]->num_entries 256 / max 256
>>>>   dl->bodies[x]->num_entries 31 / max 128
>>>>   dl->bodies[x]->num_entries 32 / max 128
>>>>   dl->bodies[x]->num_entries 39 / max 128
>>>>   dl->bodies[x]->num_entries 40 / max 128
>>>>   dl->bodies[x]->num_entries 47 / max 128
>>>>   dl->bodies[x]->num_entries 48 / max 128
>>>>   dl->bodies[x]->num_entries 4914 / max 4914
>>>>   dl->bodies[x]->num_entries 55 / max 128
>>>>   dl->bodies[x]->num_entries 56 / max 128
>>>>   dl->bodies[x]->num_entries 63 / max 128
>>>>   dl->bodies[x]->num_entries 64 / max 128
>>>
>>> This might be useful to capture in the main part of the commit message.
>>>
>>>> v4:
>>>>  - Adjust pipe configured flag to be reset on resume rather than suspend
>>>>  - rename dl_child, dl_next
>>>>  
>>>>  drivers/media/platform/vsp1/vsp1_pipe.c  |  7 +++-
>>>>  drivers/media/platform/vsp1/vsp1_pipe.h  |  4 +-
>>>>  drivers/media/platform/vsp1/vsp1_video.c | 67 -
>>>>  drivers/media/platform/vsp1/vsp1_video.h |  2 +-
>>>>  4 files changed, 54 insertions(+), 26 deletions(-)
>>>>
>>>> diff --git a/drivers/media/platform/vsp1/vsp1_pipe.c
>>>> b/drivers/media/platform/vsp1/vsp1_pipe.c index
>>>> 5012643583b6..fa445b1a2e38
>>>> 100644
>>>> --

Re: [PATCH v9 6/8] media: vsp1: Refactor display list configure operations

2018-05-17 Thread Kieran Bingham
Hi Laurent,

Thanks for the review,

On 17/05/18 10:41, Laurent Pinchart wrote:
> Hi Kieran,
> 
> Thank you for the patch.
> 
> On Thursday, 3 May 2018 16:35:45 EEST Kieran Bingham wrote:
>> The entities provide a single .configure operation which configures the
>> object into the target display list, based on the vsp1_entity_params
>> selection.
>>
>> Split the configure function into three parts, '.configure_stream()',
>> '.configure_frame()', and '.configure_partition()' to facilitate
>> splitting the configuration of each parameter class into separate
>> display list bodies.
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
>>
>> ---
>> The checkpatch warning:
>>
>> WARNING: function definition argument 'struct vsp1_dl_list *' should
>> also have an identifier name
>>
>> has been ignored to match the existing code style.
>>
>> v8:
>>  - Add support for the UIF
>>  - Remove unrelated whitespace change
>>  - Fix comment location for clu_configure_stream()
>>  - Update configure documentations
>>  - Implement configure_partition separation.
>>
>> v7
>>  - Fix formatting and white space
>>  - s/prepare/configure_stream/
>>  - s/configure/configure_frame/
>> ---
>>  drivers/media/platform/vsp1/vsp1_brx.c|  12 +-
>>  drivers/media/platform/vsp1/vsp1_clu.c|  77 ++
>>  drivers/media/platform/vsp1/vsp1_drm.c|  12 +-
>>  drivers/media/platform/vsp1/vsp1_entity.c |  24 ++-
>>  drivers/media/platform/vsp1/vsp1_entity.h |  39 +--
>>  drivers/media/platform/vsp1/vsp1_hgo.c|  12 +-
>>  drivers/media/platform/vsp1/vsp1_hgt.c|  12 +-
>>  drivers/media/platform/vsp1/vsp1_hsit.c   |  12 +-
>>  drivers/media/platform/vsp1/vsp1_lif.c|  12 +-
>>  drivers/media/platform/vsp1/vsp1_lut.c|  47 +---
>>  drivers/media/platform/vsp1/vsp1_rpf.c| 168 ++---
>>  drivers/media/platform/vsp1/vsp1_sru.c|  12 +-
>>  drivers/media/platform/vsp1/vsp1_uds.c|  56 ++--
>>  drivers/media/platform/vsp1/vsp1_uif.c|  16 +-
>>  drivers/media/platform/vsp1/vsp1_video.c  |  28 +--
>>  drivers/media/platform/vsp1/vsp1_wpf.c| 303 ---
>>  16 files changed, 422 insertions(+), 420 deletions(-)
> 
> [snip]
> 
>> diff --git a/drivers/media/platform/vsp1/vsp1_clu.c
>> b/drivers/media/platform/vsp1/vsp1_clu.c index ea83f1b7d125..0a978980d447
>> 100644
>> --- a/drivers/media/platform/vsp1/vsp1_clu.c
>> +++ b/drivers/media/platform/vsp1/vsp1_clu.c
>> @@ -168,58 +168,50 @@ static const struct v4l2_subdev_ops clu_ops = {
>>  /* 
>>   * VSP1 Entity Operations
>>   */
>> +static void clu_configure_stream(struct vsp1_entity *entity,
>> + struct vsp1_pipeline *pipe,
>> + struct vsp1_dl_list *dl)
>> +{
>> +struct vsp1_clu *clu = to_clu(>subdev);
>> +struct v4l2_mbus_framefmt *format;
>>
> 
> I would have kept this blank line before the function.

I would have thought I would too :)

> 
>> -static void clu_configure(struct vsp1_entity *entity,
>> -  struct vsp1_pipeline *pipe,
>> -  struct vsp1_dl_list *dl,
>> -  enum vsp1_entity_params params)
>> +/*
>> + * The yuv_mode can't be changed during streaming. Cache it internally
>> + * for future runtime configuration calls.
>> + */
>> +format = vsp1_entity_get_pad_format(>entity,
>> +clu->entity.config,
>> +CLU_PAD_SINK);
>> +clu->yuv_mode = format->code == MEDIA_BUS_FMT_AYUV8_1X32;
>> +}
> 
> [snip]
> 
>> diff --git a/drivers/media/platform/vsp1/vsp1_wpf.c
>> b/drivers/media/platform/vsp1/vsp1_wpf.c index 65ed2f849551..da287c27b324
>> 100644
>> --- a/drivers/media/platform/vsp1/vsp1_wpf.c
>> +++ b/drivers/media/platform/vsp1/vsp1_wpf.c
> 
> [snip]
> 
>> +static void wpf_configure_frame(struct vsp1_entity *entity,
>> +struct vsp1_pipeline *pipe,
>> +struct vsp1_dl_list *dl)
>> +{
>> +struct vsp1_rwpf *wpf = to_rwpf(>subdev);
>> +unsigned long flags;
>> +u32 outfmt = 0;
> 
> No need to initialize outfmt to 0.

Ah yes, indeed!.

>> +
> 
> This blank line isn't needed.
> 
>> +const unsigned int mask = BIT(WPF_CTRL_VFLIP)
>&

Re: [PATCH] drm: rcar-du: Fix rcar_du_of_init() stub

2018-05-15 Thread Kieran Bingham
Hi Laurent

Thanks for identifying this fault and posting the fix.

(+linux-renesas-soc)

On 15/05/18 16:57, Laurent Pinchart wrote:
> The rcar_du_of_init() function is supposed to be defined as a stub when
> CONFIG_DRM_RCAR_LVDS is disabled as the rcar_du_of.c file isn't compiled
> in that case. However, a bug in the configuration option check makes it
> a stub when CONFIG_DRM_RCAR_LVDS=m as well, which prevents legacy DTs
> from being fixed at boot time. Fix the configuration option check by
> using IS_ENABLED.
> 
> Fixes: 81c0e3dd8292 ("drm: rcar-du: Fix legacy DT to create LVDS encoder 
> nodes")
> Signed-off-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>

Reviewed-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

> ---
>  drivers/gpu/drm/rcar-du/rcar_du_of.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/rcar-du/rcar_du_of.h 
> b/drivers/gpu/drm/rcar-du/rcar_du_of.h
> index c2e65a727e91..8dd3fbe96650 100644
> --- a/drivers/gpu/drm/rcar-du/rcar_du_of.h
> +++ b/drivers/gpu/drm/rcar-du/rcar_du_of.h
> @@ -11,7 +11,7 @@
>  
>  struct of_device_id;
>  
> -#ifdef CONFIG_DRM_RCAR_LVDS
> +#if IS_ENABLED(CONFIG_DRM_RCAR_LVDS)
>  void __init rcar_du_of_init(const struct of_device_id *of_ids);
>  #else
>  static inline void rcar_du_of_init(const struct of_device_id *of_ids) { }
> 



signature.asc
Description: OpenPGP digital signature


Re: [PATCH v2 1/2] Revert "media: rcar-vin: enable field toggle after a set number of lines for Gen3"

2018-05-15 Thread Kieran Bingham
Hi Niklas,

On 11/05/18 15:41, Niklas Söderlund wrote:
> The offending commit was an attempt to fix the issue of writing outside
> the capture buffer for VIN Gen3. Unfortunately it only fixed the symptom
> of the problem to such a degree I could no longer reproduce it. Revert
> the offending commit before a proper fix can be added in a follow-up
> patch.
> 
> This reverts commit 015060cb7795eac34454696cc9c9f8b76926a401.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund+rene...@ragnatech.se>

Acked-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

> ---
>  drivers/media/platform/rcar-vin/rcar-dma.c | 20 +---
>  1 file changed, 5 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
> b/drivers/media/platform/rcar-vin/rcar-dma.c
> index b41ba9a4a2b3ac90..ac07f99e3516a620 100644
> --- a/drivers/media/platform/rcar-vin/rcar-dma.c
> +++ b/drivers/media/platform/rcar-vin/rcar-dma.c
> @@ -124,9 +124,7 @@
>  #define VNDMR2_VPS   (1 << 30)
>  #define VNDMR2_HPS   (1 << 29)
>  #define VNDMR2_FTEV  (1 << 17)
> -#define VNDMR2_FTEH  (1 << 16)
>  #define VNDMR2_VLV(n)((n & 0xf) << 12)
> -#define VNDMR2_HLV(n)((n) & 0xfff)
>  
>  /* Video n CSI2 Interface Mode Register (Gen3) */
>  #define VNCSI_IFMD_DES1  (1 << 26)
> @@ -614,9 +612,8 @@ void rvin_crop_scale_comp(struct rvin_dev *vin)
>  
>  static int rvin_setup(struct rvin_dev *vin)
>  {
> - u32 vnmc, dmr, dmr2, interrupts, lines;
> + u32 vnmc, dmr, dmr2, interrupts;
>   bool progressive = false, output_is_yuv = false, input_is_yuv = false;
> - bool halfsize = false;
>  
>   switch (vin->format.field) {
>   case V4L2_FIELD_TOP:
> @@ -631,15 +628,12 @@ static int rvin_setup(struct rvin_dev *vin)
>   /* Use BT if video standard can be read and is 60 Hz format */
>   if (!vin->info->use_mc && vin->std & V4L2_STD_525_60)
>   vnmc = VNMC_IM_FULL | VNMC_FOC;
> - halfsize = true;
>   break;
>   case V4L2_FIELD_INTERLACED_TB:
>   vnmc = VNMC_IM_FULL;
> - halfsize = true;
>   break;
>   case V4L2_FIELD_INTERLACED_BT:
>   vnmc = VNMC_IM_FULL | VNMC_FOC;
> - halfsize = true;
>   break;
>   case V4L2_FIELD_NONE:
>   vnmc = VNMC_IM_ODD_EVEN;
> @@ -682,15 +676,11 @@ static int rvin_setup(struct rvin_dev *vin)
>   break;
>   }
>  
> - if (vin->info->model == RCAR_GEN3) {
> - /* Enable HSYNC Field Toggle mode after height HSYNC inputs. */
> - lines = vin->format.height / (halfsize ? 2 : 1);
> - dmr2 = VNDMR2_FTEH | VNDMR2_HLV(lines);
> - vin_dbg(vin, "Field Toogle after %u lines\n", lines);
> - } else {
> - /* Enable VSYNC Field Toogle mode after one VSYNC input. */
> + /* Enable VSYNC Field Toogle mode after one VSYNC input */
> + if (vin->info->model == RCAR_GEN3)
> + dmr2 = VNDMR2_FTEV;
> + else
>   dmr2 = VNDMR2_FTEV | VNDMR2_VLV(1);
> - }
>  
>   /* Hsync Signal Polarity Select */
>   if (!(vin->mbus_cfg.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW))
> 


Re: [PATCH v2 2/2] rcar-vin: fix crop and compose handling for Gen3

2018-05-15 Thread Kieran Bingham
Hi Niklas,

This looks like quite the improvement :D

On 11/05/18 15:41, Niklas Söderlund wrote:
> When refactoring the Gen3 enablement series crop and compose handling
> where broken. This went unnoticed but can result in writing out side the

As well as Sergei's 'where/were', 'out side' is one word in this context.

'outside of the capture buffer'

> capture buffer. Fix this by restoring the crop and compose to reflect
> the format dimensions as we have not yet enabled the scaler for Gen3.
> 
> Fixes: 5e7c623632fcf8f5 ("media: rcar-vin: use different v4l2 operations in 
> media controller mode")
> Reported-by: Jacopo Mondi <jacopo+rene...@jmondi.org>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+rene...@ragnatech.se>

Reviewed-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

> ---
>  drivers/media/platform/rcar-vin/rcar-v4l2.c | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
> b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> index 2fb8587116f25a4f..e78fba84d59028ef 100644
> --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> @@ -702,6 +702,12 @@ static int rvin_mc_s_fmt_vid_cap(struct file *file, void 
> *priv,
>  
>   vin->format = f->fmt.pix;
>  
> + vin->crop.top = 0;
> + vin->crop.left = 0;
> + vin->crop.width = vin->format.width;
> + vin->crop.height = vin->format.height;
> + vin->compose = vin->crop;
> +
>   return 0;
>  }
>  
> 


Re: [GIT PULL FOR renesas-drivers] drm/du/m3n

2018-05-14 Thread Kieran Bingham


On 14/05/18 13:52, Geert Uytterhoeven wrote:
> Hi Kieran,
> 
> On Sat, May 12, 2018 at 10:09 AM, Kieran Bingham
> <kieran.bingham+rene...@ideasonboard.com> wrote:
>> Please consider including this release in renesas-drivers.
>>
>> --
>> Regards
>>
>> Kieran
>>
>> The following changes since commit 6d08b06e67cd117f6992c46611dfb4ce267cd71e:
>>
>>   Linux 4.17-rc2 (2018-04-22 19:20:09 -0700)
>>
>> are available in the Git repository at:
>>
>>   git://git.kernel.org/pub/scm/linux/kernel/git/kbingham/rcar.git 
>> tags/drm/du/m3n
>>
>> for you to fetch changes up to f1e9a22ac3cff749077f40bf1a149aaaf587ae2d:
>>
>>   drm: rcar-du: Add R8A77965 support (2018-05-05 17:11:20 +0300)
> 
> Thanks, merged clealy into today's linux-next.

Great, thanks.

> 
>> 
>> drm: rcar-du: Provide support for the M3-N
>>
>> The M3-N has non linear addressing of it's group objects, which was not
> 
> non-linear?

Probably :)

> its

Definitely !



> 
>> supported by the rcar-du driver implementation due to asumptions on the

Hrm ... also s/asumptions/assumptions/

--
Thanks

Kieran

>> match between a CRTC index, and the hardware indexes.
>>
>> Implement support to remove this assumption and enable the M3-N
> 
> Gr{oetje,eeting}s,
> 
> Geert
> 


[GIT PULL FOR renesas-drivers] drm/du/m3n

2018-05-12 Thread Kieran Bingham
Hi Geert,

Please consider including this release in renesas-drivers.

--
Regards

Kieran

The following changes since commit 6d08b06e67cd117f6992c46611dfb4ce267cd71e:

  Linux 4.17-rc2 (2018-04-22 19:20:09 -0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/kbingham/rcar.git 
tags/drm/du/m3n

for you to fetch changes up to f1e9a22ac3cff749077f40bf1a149aaaf587ae2d:

  drm: rcar-du: Add R8A77965 support (2018-05-05 17:11:20 +0300)


drm: rcar-du: Provide support for the M3-N

The M3-N has non linear addressing of it's group objects, which was not
supported by the rcar-du driver implementation due to asumptions on the
match between a CRTC index, and the hardware indexes.

Implement support to remove this assumption and enable the M3-N


Kieran Bingham (9):
  drm: rcar-du: of: Include header to define prototypes
  drm: rcar-du: Use NULL for table initialisation
  dt-bindings: display: renesas: du: Increase indent in output table
  dt-bindings: display: renesas: du: Document the r8a77965 bindings
  drm: rcar-du: Use the correct naming for ODPM fields in DEFR6
  dt-bindings: display: renesas: Add R-Car M3-N HDMI TX DT bindings
  drm: rcar-du: Split CRTC handling to support hardware indexing
  drm: rcar-du: Allow DU groups to work with hardware indexing
  drm: rcar-du: Add R8A77965 support

Laurent Pinchart (1):
  drm: rcar-du: Zero-out sg_tables when duplicating plane state

 .../bindings/display/bridge/renesas,dw-hdmi.txt|  1 +
 .../devicetree/bindings/display/renesas,du.txt | 28 ++--
 drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 26 ++-
 drivers/gpu/drm/rcar-du/rcar_du_crtc.h |  3 +-
 drivers/gpu/drm/rcar-du/rcar_du_drv.c  | 51 +-
 drivers/gpu/drm/rcar-du/rcar_du_drv.h  |  4 +-
 drivers/gpu/drm/rcar-du/rcar_du_group.c| 16 ---
 drivers/gpu/drm/rcar-du/rcar_du_group.h|  2 +
 drivers/gpu/drm/rcar-du/rcar_du_kms.c  | 25 ---
 drivers/gpu/drm/rcar-du/rcar_du_of.c   |  1 +
 drivers/gpu/drm/rcar-du/rcar_du_regs.h | 16 +++
 drivers/gpu/drm/rcar-du/rcar_du_vsp.c  |  5 +--
 12 files changed, 115 insertions(+), 63 deletions(-)


Re: [PATCH v2] media: i2c: adv748x: Fix pixel rate values

2018-05-12 Thread Kieran Bingham
Hi Niklas, Laurent,

Thanks for the updated patch and detailed investigation to get this right.

On 11/05/18 15:04, Niklas Söderlund wrote:
> From: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
> 
> The pixel rate, as reported by the V4L2_CID_PIXEL_RATE control, must
> include both horizontal and vertical blanking. Both the AFE and HDMI
> receiver program it incorrectly:
> 
> - The HDMI receiver goes to the trouble of removing blanking to compute
> the rate of active pixels. This is easy to fix by removing the
> computation and returning the incoming pixel clock rate directly.
> 
> - The AFE performs similar calculation, while it should simply return
> the fixed pixel rate for analog sources, mandated by the ADV748x to be
> 14.3180180 MHz.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
> [Niklas: Update AFE fixed pixel rate]
> Signed-off-by: Niklas Söderlund <niklas.soderlund+rene...@ragnatech.se>

Reviewed-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

Does this still require changes to the CSI2 driver to be synchronised?
(or does it not matter as the CSI2 isn't upstream yet)...

--
Kieran


> ---
> 
> * Changes since v1
> - Update AFE fixed pixel rate.
> ---
>  drivers/media/i2c/adv748x/adv748x-afe.c  | 12 ++--
>  drivers/media/i2c/adv748x/adv748x-hdmi.c |  8 +---
>  2 files changed, 7 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/media/i2c/adv748x/adv748x-afe.c 
> b/drivers/media/i2c/adv748x/adv748x-afe.c
> index 61514bae7e5ceb42..edd25e895e5dec3c 100644
> --- a/drivers/media/i2c/adv748x/adv748x-afe.c
> +++ b/drivers/media/i2c/adv748x/adv748x-afe.c
> @@ -321,17 +321,17 @@ static const struct v4l2_subdev_video_ops 
> adv748x_afe_video_ops = {
>  static int adv748x_afe_propagate_pixelrate(struct adv748x_afe *afe)
>  {
>   struct v4l2_subdev *tx;
> - unsigned int width, height, fps;
>  
>   tx = adv748x_get_remote_sd(>pads[ADV748X_AFE_SOURCE]);
>   if (!tx)
>   return -ENOLINK;
>  
> - width = 720;
> - height = afe->curr_norm & V4L2_STD_525_60 ? 480 : 576;
> - fps = afe->curr_norm & V4L2_STD_525_60 ? 30 : 25;
> -
> - return adv748x_csi2_set_pixelrate(tx, width * height * fps);
> + /*
> +  * The ADV748x ADC sampling frequency is twice the externally supplied
> +  * clock whose frequency is required to be 28.63636 MHz. It oversamples
> +  * with a factor of 4 resulting in a pixel rate of 14.3180180 MHz.
> +  */
> + return adv748x_csi2_set_pixelrate(tx, 14318180);
>  }
>  
>  static int adv748x_afe_enum_mbus_code(struct v4l2_subdev *sd,
> diff --git a/drivers/media/i2c/adv748x/adv748x-hdmi.c 
> b/drivers/media/i2c/adv748x/adv748x-hdmi.c
> index 10d229a4f08868f7..aecc2a84dfecbec8 100644
> --- a/drivers/media/i2c/adv748x/adv748x-hdmi.c
> +++ b/drivers/media/i2c/adv748x/adv748x-hdmi.c
> @@ -402,8 +402,6 @@ static int adv748x_hdmi_propagate_pixelrate(struct 
> adv748x_hdmi *hdmi)
>  {
>   struct v4l2_subdev *tx;
>   struct v4l2_dv_timings timings;
> - struct v4l2_bt_timings *bt = 
> - unsigned int fps;
>  
>   tx = adv748x_get_remote_sd(>pads[ADV748X_HDMI_SOURCE]);
>   if (!tx)
> @@ -411,11 +409,7 @@ static int adv748x_hdmi_propagate_pixelrate(struct 
> adv748x_hdmi *hdmi)
>  
>   adv748x_hdmi_query_dv_timings(>sd, );
>  
> - fps = DIV_ROUND_CLOSEST_ULL(bt->pixelclock,
> - V4L2_DV_BT_FRAME_WIDTH(bt) *
> - V4L2_DV_BT_FRAME_HEIGHT(bt));
> -
> - return adv748x_csi2_set_pixelrate(tx, bt->width * bt->height * fps);
> + return adv748x_csi2_set_pixelrate(tx, timings.bt.pixelclock);
>  }
>  
>  static int adv748x_hdmi_enum_mbus_code(struct v4l2_subdev *sd,
> 



signature.asc
Description: OpenPGP digital signature


Re: [PATCH v3 10/11] media: vsp1: Support Interlaced display pipelines

2018-05-03 Thread Kieran Bingham
Hi Laurent,

On 03/05/18 12:13, Laurent Pinchart wrote:
> Hi Kieran,



>>> +   } else {
>>> +   vsp1_rpf_write(rpf, dlb, VI6_RPF_SRCM_ADDR_Y, mem.addr[0]);
>>> +   vsp1_rpf_write(rpf, dlb, VI6_RPF_SRCM_ADDR_C0, mem.addr[1]);
>>> +   vsp1_rpf_write(rpf, dlb, VI6_RPF_SRCM_ADDR_C1, mem.addr[2]);
>>> +   }
>>>  }
>>> +
>>>  static void rpf_partition(struct vsp1_entity *entity,
>>>   struct vsp1_pipeline *pipe,
>>>   struct vsp1_partition *partition,
>>> diff --git a/drivers/media/platform/vsp1/vsp1_rwpf.h
>>> b/drivers/media/platform/vsp1/vsp1_rwpf.h index
>>> 70742ecf766f..8d6e42f27908 100644
>>> --- a/drivers/media/platform/vsp1/vsp1_rwpf.h
>>> +++ b/drivers/media/platform/vsp1/vsp1_rwpf.h
>>> @@ -42,6 +42,7 @@ struct vsp1_rwpf {
>>> struct v4l2_pix_format_mplane format;
>>> const struct vsp1_format_info *fmtinfo;
>>> unsigned int brx_input;
>>> +   bool interlaced;
> 
> kerneldoc might be nice :-)

There's no existing kerneldoc on struct vsp1_rwpf ?

>>>
>>> unsigned int alpha;
>>>
> 
> [snip]
> 
>>> diff --git a/include/media/vsp1.h b/include/media/vsp1.h
>>> index 678c24de1ac6..c10883f30980 100644
>>> --- a/include/media/vsp1.h
>>> +++ b/include/media/vsp1.h
>>> @@ -50,6 +50,7 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int
>>> pipe_index,> 
>>>   * @dst: destination rectangle on the display (integer coordinates)
>>>   * @alpha: alpha value (0: fully transparent, 255: fully opaque)
>>>   * @zpos: Z position of the plane (from 0 to number of planes minus 1)
>>> + * @interlaced: true for interlaced pipelines
> 
> Maybe "true if the pipeline outputs an interlaced stream" ?

That's fine - but I've neglected to incorporate this into my v4 repost :-(

If by any magic - v4 is suitable for integration already, and you're happy to
take it into your tree - please feel free to update this comment.

Otherwise it will be in any next update.

--
KB


[PATCH v4 06/11] media: vsp1: Provide VSP1 feature helper macro

2018-05-03 Thread Kieran Bingham
The VSP1 devices define their specific capabilities through features
marked in their device info structure. Various parts of the code read
this info structure to infer if the features are available.

Wrap this into a more readable vsp1_feature(vsp1, f) macro to ensure
that usage is consistent throughout the driver.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1.h |  2 ++
 drivers/media/platform/vsp1/vsp1_drv.c | 16 
 drivers/media/platform/vsp1/vsp1_wpf.c |  6 +++---
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1.h 
b/drivers/media/platform/vsp1/vsp1.h
index 33f632331474..f0d21cc8e9ab 100644
--- a/drivers/media/platform/vsp1/vsp1.h
+++ b/drivers/media/platform/vsp1/vsp1.h
@@ -68,6 +68,8 @@ struct vsp1_device_info {
bool uapi;
 };
 
+#define vsp1_feature(vsp1, f) ((vsp1)->info->features & (f))
+
 struct vsp1_device {
struct device *dev;
const struct vsp1_device_info *info;
diff --git a/drivers/media/platform/vsp1/vsp1_drv.c 
b/drivers/media/platform/vsp1/vsp1_drv.c
index d29f9c4baebe..0fc388bf5a33 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -265,7 +265,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
}
 
/* Instantiate all the entities. */
-   if (vsp1->info->features & VSP1_HAS_BRS) {
+   if (vsp1_feature(vsp1, VSP1_HAS_BRS)) {
vsp1->brs = vsp1_brx_create(vsp1, VSP1_ENTITY_BRS);
if (IS_ERR(vsp1->brs)) {
ret = PTR_ERR(vsp1->brs);
@@ -275,7 +275,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
list_add_tail(>brs->entity.list_dev, >entities);
}
 
-   if (vsp1->info->features & VSP1_HAS_BRU) {
+   if (vsp1_feature(vsp1, VSP1_HAS_BRU)) {
vsp1->bru = vsp1_brx_create(vsp1, VSP1_ENTITY_BRU);
if (IS_ERR(vsp1->bru)) {
ret = PTR_ERR(vsp1->bru);
@@ -285,7 +285,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
list_add_tail(>bru->entity.list_dev, >entities);
}
 
-   if (vsp1->info->features & VSP1_HAS_CLU) {
+   if (vsp1_feature(vsp1, VSP1_HAS_CLU)) {
vsp1->clu = vsp1_clu_create(vsp1);
if (IS_ERR(vsp1->clu)) {
ret = PTR_ERR(vsp1->clu);
@@ -311,7 +311,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
 
list_add_tail(>hst->entity.list_dev, >entities);
 
-   if (vsp1->info->features & VSP1_HAS_HGO && vsp1->info->uapi) {
+   if (vsp1_feature(vsp1, VSP1_HAS_HGO) && vsp1->info->uapi) {
vsp1->hgo = vsp1_hgo_create(vsp1);
if (IS_ERR(vsp1->hgo)) {
ret = PTR_ERR(vsp1->hgo);
@@ -322,7 +322,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
  >entities);
}
 
-   if (vsp1->info->features & VSP1_HAS_HGT && vsp1->info->uapi) {
+   if (vsp1_feature(vsp1, VSP1_HAS_HGT) && vsp1->info->uapi) {
vsp1->hgt = vsp1_hgt_create(vsp1);
if (IS_ERR(vsp1->hgt)) {
ret = PTR_ERR(vsp1->hgt);
@@ -353,7 +353,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
}
}
 
-   if (vsp1->info->features & VSP1_HAS_LUT) {
+   if (vsp1_feature(vsp1, VSP1_HAS_LUT)) {
vsp1->lut = vsp1_lut_create(vsp1);
if (IS_ERR(vsp1->lut)) {
ret = PTR_ERR(vsp1->lut);
@@ -387,7 +387,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
}
}
 
-   if (vsp1->info->features & VSP1_HAS_SRU) {
+   if (vsp1_feature(vsp1, VSP1_HAS_SRU)) {
vsp1->sru = vsp1_sru_create(vsp1);
if (IS_ERR(vsp1->sru)) {
ret = PTR_ERR(vsp1->sru);
@@ -537,7 +537,7 @@ static int vsp1_device_init(struct vsp1_device *vsp1)
vsp1_write(vsp1, VI6_DPR_HSI_ROUTE, VI6_DPR_NODE_UNUSED);
vsp1_write(vsp1, VI6_DPR_BRU_ROUTE, VI6_DPR_NODE_UNUSED);
 
-   if (vsp1->info->features & VSP1_HAS_BRS)
+   if (vsp1_feature(vsp1, VSP1_HAS_BRS))
vsp1_write(vsp1, VI6_DPR_ILV_BRS_ROUTE, VI6_DPR_NODE_UNUSED);
 
vsp1_write(vsp1, VI6_DPR_HGO_SMPPT, (7 << VI6_DPR_SMPPT_TGW_SHIFT) |
diff --git a/drivers/media/platform/vsp1/vsp1_wpf.c 
b/drivers/media/platform/vsp1/vsp1_wpf.c
index 2edea361eee4..ea1d226371b2 100644
--- a/drivers/media/platform/vsp1/vsp1_wpf.c
+++ b/drivers/media/platform/vsp1/vsp1_wpf.c
@@ -141,13 +141,13 @@ static int wpf_init_contro

[PATCH v4 02/11] media: vsp1: Remove packed attributes from aligned structures

2018-05-03 Thread Kieran Bingham
The use of the packed attribute can cause a performance penalty for
all accesses to the struct members, as the compiler will assume that the
structure has the potential to have an unaligned base.

These structures are all correctly aligned and contain no holes, thus
the attribute is redundant and negatively impacts performance, so we
remove the attributes entirely.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
v2
 - Remove attributes entirely
---
 drivers/media/platform/vsp1/vsp1_dl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index c7fa1cb088cd..f4cede9b9b43 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -25,19 +25,19 @@
 struct vsp1_dl_header_list {
u32 num_bytes;
u32 addr;
-} __attribute__((__packed__));
+};
 
 struct vsp1_dl_header {
u32 num_lists;
struct vsp1_dl_header_list lists[8];
u32 next_header;
u32 flags;
-} __attribute__((__packed__));
+};
 
 struct vsp1_dl_entry {
u32 addr;
u32 data;
-} __attribute__((__packed__));
+};
 
 /**
  * struct vsp1_dl_body - Display list body
-- 
git-series 0.9.1


[PATCH v4 11/11] drm: rcar-du: Support interlaced video output through vsp1

2018-05-03 Thread Kieran Bingham
Use the newly exposed VSP1 interface to enable interlaced frame support
through the VSP1 lif pipelines.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
 drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 1 +
 drivers/gpu/drm/rcar-du/rcar_du_vsp.c  | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c 
b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
index d71d709fe3d9..206532959ec9 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
@@ -289,6 +289,7 @@ static void rcar_du_crtc_set_display_timing(struct 
rcar_du_crtc *rcrtc)
/* Signal polarities */
value = ((mode->flags & DRM_MODE_FLAG_PVSYNC) ? DSMR_VSL : 0)
  | ((mode->flags & DRM_MODE_FLAG_PHSYNC) ? DSMR_HSL : 0)
+ | ((mode->flags & DRM_MODE_FLAG_INTERLACE) ? DSMR_ODEV : 0)
  | DSMR_DIPM_DISP | DSMR_CSPM;
rcar_du_crtc_write(rcrtc, DSMR, value);
 
diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c 
b/drivers/gpu/drm/rcar-du/rcar_du_vsp.c
index af7822a66dee..c7b37232ee91 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp.c
@@ -186,6 +186,9 @@ static void rcar_du_vsp_plane_setup(struct 
rcar_du_vsp_plane *plane)
};
unsigned int i;
 
+   cfg.interlaced = !!(plane->plane.state->crtc->mode.flags
+   & DRM_MODE_FLAG_INTERLACE);
+
cfg.src.left = state->state.src.x1 >> 16;
cfg.src.top = state->state.src.y1 >> 16;
cfg.src.width = drm_rect_width(>state.src) >> 16;
-- 
git-series 0.9.1


[PATCH v4 03/11] media: vsp1: Rename dl_child to dl_next

2018-05-03 Thread Kieran Bingham
Both vsp1_dl_list_commit() and __vsp1_dl_list_put() walk the display
list chain referencing the nodes as children, when in reality they are
siblings.

Update the terminology to 'dl_next' to be consistent with the
vsp1_video_pipeline_run() usage.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_dl.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index f4cede9b9b43..ec6fc21fabe0 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -398,7 +398,7 @@ struct vsp1_dl_list *vsp1_dl_list_get(struct 
vsp1_dl_manager *dlm)
 /* This function must be called with the display list manager lock held.*/
 static void __vsp1_dl_list_put(struct vsp1_dl_list *dl)
 {
-   struct vsp1_dl_list *dl_child;
+   struct vsp1_dl_list *dl_next;
 
if (!dl)
return;
@@ -408,8 +408,8 @@ static void __vsp1_dl_list_put(struct vsp1_dl_list *dl)
 * hardware operation.
 */
if (dl->has_chain) {
-   list_for_each_entry(dl_child, >chain, chain)
-   __vsp1_dl_list_put(dl_child);
+   list_for_each_entry(dl_next, >chain, chain)
+   __vsp1_dl_list_put(dl_next);
}
 
dl->has_chain = false;
@@ -673,17 +673,17 @@ static void vsp1_dl_list_commit_singleshot(struct 
vsp1_dl_list *dl)
 void vsp1_dl_list_commit(struct vsp1_dl_list *dl, bool internal)
 {
struct vsp1_dl_manager *dlm = dl->dlm;
-   struct vsp1_dl_list *dl_child;
+   struct vsp1_dl_list *dl_next;
unsigned long flags;
 
if (dlm->mode == VSP1_DL_MODE_HEADER) {
/* Fill the header for the head and chained display lists. */
vsp1_dl_list_fill_header(dl, list_empty(>chain));
 
-   list_for_each_entry(dl_child, >chain, chain) {
-   bool last = list_is_last(_child->chain, >chain);
+   list_for_each_entry(dl_next, >chain, chain) {
+   bool last = list_is_last(_next->chain, >chain);
 
-   vsp1_dl_list_fill_header(dl_child, last);
+   vsp1_dl_list_fill_header(dl_next, last);
}
}
 
-- 
git-series 0.9.1


[PATCH v4 08/11] media: vsp1: Add support for extended display list headers

2018-05-03 Thread Kieran Bingham
Extended display list headers allow pre and post command lists to be
executed by the VSP pipeline. This provides the base support for
features such as AUTO_FLD (for interlaced support) and AUTO_DISP (for
supporting continuous camera preview pipelines.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

---

v2:
 - remove __packed attributes
---
 drivers/media/platform/vsp1/vsp1.h  |  1 +-
 drivers/media/platform/vsp1/vsp1_dl.c   | 83 +-
 drivers/media/platform/vsp1/vsp1_dl.h   | 29 -
 drivers/media/platform/vsp1/vsp1_drv.c  |  7 +-
 drivers/media/platform/vsp1/vsp1_regs.h |  5 +-
 5 files changed, 116 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1.h 
b/drivers/media/platform/vsp1/vsp1.h
index f0d21cc8e9ab..56c62122a81a 100644
--- a/drivers/media/platform/vsp1/vsp1.h
+++ b/drivers/media/platform/vsp1/vsp1.h
@@ -53,6 +53,7 @@ struct vsp1_uif;
 #define VSP1_HAS_HGO   (1 << 7)
 #define VSP1_HAS_HGT   (1 << 8)
 #define VSP1_HAS_BRS   (1 << 9)
+#define VSP1_HAS_EXT_DL(1 << 10)
 
 struct vsp1_device_info {
u32 version;
diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index 56514cd51c51..b64d32535edc 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -22,6 +22,9 @@
 #define VSP1_DLH_INT_ENABLE(1 << 1)
 #define VSP1_DLH_AUTO_START(1 << 0)
 
+#define VSP1_DLH_EXT_PRE_CMD_EXEC  (1 << 9)
+#define VSP1_DLH_EXT_POST_CMD_EXEC (1 << 8)
+
 struct vsp1_dl_header_list {
u32 num_bytes;
u32 addr;
@@ -34,11 +37,34 @@ struct vsp1_dl_header {
u32 flags;
 };
 
+struct vsp1_dl_ext_header {
+   u32 reserved0;  /* alignment padding */
+
+   u16 pre_ext_cmd_qty;
+   u16 flags;
+   u32 pre_ext_cmd_plist;
+
+   u32 post_ext_cmd_qty;
+   u32 post_ext_cmd_plist;
+};
+
+struct vsp1_dl_header_extended {
+   struct vsp1_dl_header header;
+   struct vsp1_dl_ext_header ext;
+};
+
 struct vsp1_dl_entry {
u32 addr;
u32 data;
 };
 
+struct vsp1_dl_ext_cmd_header {
+   u32 cmd;
+   u32 flags;
+   u32 data;
+   u32 reserved;
+};
+
 /**
  * struct vsp1_dl_body - Display list body
  * @list: entry in the display list list of bodies
@@ -95,9 +121,12 @@ struct vsp1_dl_body_pool {
  * @list: entry in the display list manager lists
  * @dlm: the display list manager
  * @header: display list header
+ * @extended: extended display list header. NULL for normal lists
  * @dma: DMA address for the header
  * @body0: first display list body
  * @bodies: list of extra display list bodies
+ * @pre_cmd: pre cmd to be issued through extended dl header
+ * @post_cmd: post cmd to be issued through extended dl header
  * @has_chain: if true, indicates that there's a partition chain
  * @chain: entry in the display list partition chain
  * @internal: whether the display list is used for internal purpose
@@ -107,11 +136,15 @@ struct vsp1_dl_list {
struct vsp1_dl_manager *dlm;
 
struct vsp1_dl_header *header;
+   struct vsp1_dl_ext_header *extended;
dma_addr_t dma;
 
struct vsp1_dl_body *body0;
struct list_head bodies;
 
+   struct vsp1_dl_ext_cmd *pre_cmd;
+   struct vsp1_dl_ext_cmd *post_cmd;
+
bool has_chain;
struct list_head chain;
 
@@ -496,6 +529,14 @@ int vsp1_dl_list_add_chain(struct vsp1_dl_list *head,
return 0;
 }
 
+static void vsp1_dl_ext_cmd_fill_header(struct vsp1_dl_ext_cmd *cmd)
+{
+   cmd->cmds[0].cmd = cmd->cmd_opcode;
+   cmd->cmds[0].flags = cmd->flags;
+   cmd->cmds[0].data = cmd->data_dma;
+   cmd->cmds[0].reserved = 0;
+}
+
 static void vsp1_dl_list_fill_header(struct vsp1_dl_list *dl, bool is_last)
 {
struct vsp1_dl_manager *dlm = dl->dlm;
@@ -548,6 +589,27 @@ static void vsp1_dl_list_fill_header(struct vsp1_dl_list 
*dl, bool is_last)
 */
dl->header->flags = VSP1_DLH_INT_ENABLE;
}
+
+   if (!dl->extended)
+   return;
+
+   dl->extended->flags = 0;
+
+   if (dl->pre_cmd) {
+   dl->extended->pre_ext_cmd_plist = dl->pre_cmd->cmd_dma;
+   dl->extended->pre_ext_cmd_qty = dl->pre_cmd->num_cmds;
+   dl->extended->flags |= VSP1_DLH_EXT_PRE_CMD_EXEC;
+
+   vsp1_dl_ext_cmd_fill_header(dl->pre_cmd);
+   }
+
+   if (dl->post_cmd) {
+   dl->extended->pre_ext_cmd_plist = dl->post_cmd->cmd_dma;
+   dl->extended->pre_ext_cmd_qty = dl->post_cmd->num_cmds;
+   dl->extended->flags |= VSP1_DLH_EXT_POST_CMD_EXEC;
+
+   vsp1_dl_ext_cmd_fill_header(dl->pre_cmd);
+   }
 }
 
 static bool 

[PATCH v4 07/11] media: vsp1: Use header display lists for all WPF outputs linked to the DU

2018-05-03 Thread Kieran Bingham
Header mode display lists are now supported on all WPF outputs. To
support extended headers and auto-fld capabilities for interlaced mode
handling only header mode display lists can be used.

Disable the headerless display list configuration, and remove the dead
code.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_dl.c | 107 ++-
 1 file changed, 27 insertions(+), 80 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index fbffbd407b29..56514cd51c51 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -94,7 +94,7 @@ struct vsp1_dl_body_pool {
  * struct vsp1_dl_list - Display list
  * @list: entry in the display list manager lists
  * @dlm: the display list manager
- * @header: display list header, NULL for headerless lists
+ * @header: display list header
  * @dma: DMA address for the header
  * @body0: first display list body
  * @bodies: list of extra display list bodies
@@ -118,15 +118,9 @@ struct vsp1_dl_list {
bool internal;
 };
 
-enum vsp1_dl_mode {
-   VSP1_DL_MODE_HEADER,
-   VSP1_DL_MODE_HEADERLESS,
-};
-
 /**
  * struct vsp1_dl_manager - Display List manager
  * @index: index of the related WPF
- * @mode: display list operation mode (header or headerless)
  * @singleshot: execute the display list in single-shot mode
  * @vsp1: the VSP1 device
  * @lock: protects the free, active, queued, and pending lists
@@ -138,7 +132,6 @@ enum vsp1_dl_mode {
  */
 struct vsp1_dl_manager {
unsigned int index;
-   enum vsp1_dl_mode mode;
bool singleshot;
struct vsp1_device *vsp1;
 
@@ -318,6 +311,7 @@ void vsp1_dl_body_write(struct vsp1_dl_body *dlb, u32 reg, 
u32 data)
 static struct vsp1_dl_list *vsp1_dl_list_alloc(struct vsp1_dl_manager *dlm)
 {
struct vsp1_dl_list *dl;
+   size_t header_offset;
 
dl = kzalloc(sizeof(*dl), GFP_KERNEL);
if (!dl)
@@ -330,16 +324,15 @@ static struct vsp1_dl_list *vsp1_dl_list_alloc(struct 
vsp1_dl_manager *dlm)
dl->body0 = vsp1_dl_body_get(dlm->pool);
if (!dl->body0)
return NULL;
-   if (dlm->mode == VSP1_DL_MODE_HEADER) {
-   size_t header_offset = dl->body0->max_entries
-* sizeof(*dl->body0->entries);
 
-   dl->header = ((void *)dl->body0->entries) + header_offset;
-   dl->dma = dl->body0->dma + header_offset;
+   header_offset = dl->body0->max_entries
+* sizeof(*dl->body0->entries);
 
-   memset(dl->header, 0, sizeof(*dl->header));
-   dl->header->lists[0].addr = dl->body0->dma;
-   }
+   dl->header = ((void *)dl->body0->entries) + header_offset;
+   dl->dma = dl->body0->dma + header_offset;
+
+   memset(dl->header, 0, sizeof(*dl->header));
+   dl->header->lists[0].addr = dl->body0->dma;
 
return dl;
 }
@@ -471,16 +464,9 @@ struct vsp1_dl_body *vsp1_dl_list_get_body0(struct 
vsp1_dl_list *dl)
  *
  * The reference must be explicitly released by a call to vsp1_dl_body_put()
  * when the body isn't needed anymore.
- *
- * Additional bodies are only usable for display lists in header mode.
- * Attempting to add a body to a header-less display list will return an error.
  */
 int vsp1_dl_list_add_body(struct vsp1_dl_list *dl, struct vsp1_dl_body *dlb)
 {
-   /* Multi-body lists are only available in header mode. */
-   if (dl->dlm->mode != VSP1_DL_MODE_HEADER)
-   return -EINVAL;
-
refcount_inc(>refcnt);
 
list_add_tail(>list, >bodies);
@@ -501,17 +487,10 @@ int vsp1_dl_list_add_body(struct vsp1_dl_list *dl, struct 
vsp1_dl_body *dlb)
  * Adding a display list to a chain passes ownership of the display list to
  * the head display list item. The chain is released when the head dl item is
  * put back with __vsp1_dl_list_put().
- *
- * Chained display lists are only usable in header mode. Attempts to add a
- * display list to a chain in header-less mode will return an error.
  */
 int vsp1_dl_list_add_chain(struct vsp1_dl_list *head,
   struct vsp1_dl_list *dl)
 {
-   /* Chained lists are only available in header mode. */
-   if (head->dlm->mode != VSP1_DL_MODE_HEADER)
-   return -EINVAL;
-
head->has_chain = true;
list_add_tail(>chain, >chain);
return 0;
@@ -579,17 +558,10 @@ static bool vsp1_dl_list_hw_update_pending(struct 
vsp1_dl_manager *dlm)
return false;
 
/*
-* Check whether the VSP1 has taken the update. In headerless mode the
-* hardware indicates this by clearing the UPD bit in the DL_BODY_SIZE
-* register, and in header mode by clear

[PATCH v4 09/11] media: vsp1: Provide support for extended command pools

2018-05-03 Thread Kieran Bingham
VSPD and VSP-DL devices can provide extended display lists supporting
extended command display list objects.

These extended commands require their own dma memory areas for a header
and body specific to the command type.

Implement a command pool to allocate all necessary memory in a single
DMA allocation to reduce pressure on the TLB, and provide convenient
re-usable command objects for the entities to utilise.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

---

v2:
 - Fix spelling typo in commit message
 - constify, and staticify the instantiation of vsp1_extended_commands
 - s/autfld_cmds/autofld_cmds/
 - staticify cmd pool functions (Thanks kbuild-bot)
---
 drivers/media/platform/vsp1/vsp1_dl.c | 191 +++-
 drivers/media/platform/vsp1/vsp1_dl.h |   3 +-
 2 files changed, 194 insertions(+)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index b64d32535edc..d33ae5f125bd 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -117,6 +117,30 @@ struct vsp1_dl_body_pool {
 };
 
 /**
+ * struct vsp1_cmd_pool - display list body pool
+ * @dma: DMA address of the entries
+ * @size: size of the full DMA memory pool in bytes
+ * @mem: CPU memory pointer for the pool
+ * @bodies: Array of DLB structures for the pool
+ * @free: List of free DLB entries
+ * @lock: Protects the pool and free list
+ * @vsp1: the VSP1 device
+ */
+struct vsp1_dl_cmd_pool {
+   /* DMA allocation */
+   dma_addr_t dma;
+   size_t size;
+   void *mem;
+
+   struct vsp1_dl_ext_cmd *cmds;
+   struct list_head free;
+
+   spinlock_t lock;
+
+   struct vsp1_device *vsp1;
+};
+
+/**
  * struct vsp1_dl_list - Display list
  * @list: entry in the display list manager lists
  * @dlm: the display list manager
@@ -162,6 +186,7 @@ struct vsp1_dl_list {
  * @queued: list queued to the hardware (written to the DL registers)
  * @pending: list waiting to be queued to the hardware
  * @pool: body pool for the display list bodies
+ * @autofld_cmds: command pool to support auto-fld interlaced mode
  */
 struct vsp1_dl_manager {
unsigned int index;
@@ -175,6 +200,7 @@ struct vsp1_dl_manager {
struct vsp1_dl_list *pending;
 
struct vsp1_dl_body_pool *pool;
+   struct vsp1_dl_cmd_pool *autofld_cmds;
 };
 
 /* 
-
@@ -338,6 +364,140 @@ void vsp1_dl_body_write(struct vsp1_dl_body *dlb, u32 
reg, u32 data)
 }
 
 /* 
-
+ * Display List Extended Command Management
+ */
+
+enum vsp1_extcmd_type {
+   VSP1_EXTCMD_AUTODISP,
+   VSP1_EXTCMD_AUTOFLD,
+};
+
+struct vsp1_extended_command_info {
+   u16 opcode;
+   size_t body_size;
+} static const vsp1_extended_commands[] = {
+   [VSP1_EXTCMD_AUTODISP] = { 0x02, 96 },
+   [VSP1_EXTCMD_AUTOFLD]  = { 0x03, 160 },
+};
+
+/**
+ * vsp1_dl_cmd_pool_create - Create a pool of commands from a single allocation
+ * @vsp1: The VSP1 device
+ * @type: The command pool type
+ * @num_commands: The quantity of commands to allocate
+ *
+ * Allocate a pool of commands each with enough memory to contain the private
+ * data of each command. The allocation sizes are dependent upon the command
+ * type.
+ *
+ * Return a pointer to a pool on success or NULL if memory can't be allocated.
+ */
+static struct vsp1_dl_cmd_pool *
+vsp1_dl_cmd_pool_create(struct vsp1_device *vsp1, enum vsp1_extcmd_type type,
+   unsigned int num_cmds)
+{
+   struct vsp1_dl_cmd_pool *pool;
+   unsigned int i;
+   size_t cmd_size;
+
+   pool = kzalloc(sizeof(*pool), GFP_KERNEL);
+   if (!pool)
+   return NULL;
+
+   pool->cmds = kcalloc(num_cmds, sizeof(*pool->cmds), GFP_KERNEL);
+   if (!pool->cmds) {
+   kfree(pool);
+   return NULL;
+   }
+
+   cmd_size = sizeof(struct vsp1_dl_ext_cmd_header) +
+  vsp1_extended_commands[type].body_size;
+   cmd_size = ALIGN(cmd_size, 16);
+
+   pool->size = cmd_size * num_cmds;
+   pool->mem = dma_alloc_wc(vsp1->bus_master, pool->size, >dma,
+GFP_KERNEL);
+   if (!pool->mem) {
+   kfree(pool->cmds);
+   kfree(pool);
+   return NULL;
+   }
+
+   spin_lock_init(>lock);
+   INIT_LIST_HEAD(>free);
+
+   for (i = 0; i < num_cmds; ++i) {
+   struct vsp1_dl_ext_cmd *cmd = >cmds[i];
+   size_t cmd_offset = i * cmd_size;
+   size_t data_offset = sizeof(struct vsp1_dl_ext_cmd_header) +
+cmd_offset;
+
+   cmd->pool = pool;
+   cmd->cmd_opcode = vsp1_extended_commands[type].opcode;
+
+   /* TOD

[PATCH v4 04/11] media: vsp1: Remove unused display list structure field

2018-05-03 Thread Kieran Bingham
The vsp1 reference in the vsp1_dl_body structure is not used.
Remove it.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_dl.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index ec6fc21fabe0..b23e88cda49f 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -44,7 +44,6 @@ struct vsp1_dl_entry {
  * @list: entry in the display list list of bodies
  * @free: entry in the pool free body list
  * @pool: pool to which this body belongs
- * @vsp1: the VSP1 device
  * @entries: array of entries
  * @dma: DMA address of the entries
  * @size: size of the DMA memory in bytes
@@ -58,7 +57,6 @@ struct vsp1_dl_body {
refcount_t refcnt;
 
struct vsp1_dl_body_pool *pool;
-   struct vsp1_device *vsp1;
 
struct vsp1_dl_entry *entries;
dma_addr_t dma;
-- 
git-series 0.9.1


[PATCH v4 05/11] media: vsp1: Clean up DLM objects on error

2018-05-03 Thread Kieran Bingham
If there is an error allocating a display list within a DLM object
the existing display lists are not free'd, and neither is the DL body
pool.

Use the existing vsp1_dlm_destroy() function to clean up on error.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_dl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index b23e88cda49f..fbffbd407b29 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -851,8 +851,10 @@ struct vsp1_dl_manager *vsp1_dlm_create(struct vsp1_device 
*vsp1,
struct vsp1_dl_list *dl;
 
dl = vsp1_dl_list_alloc(dlm);
-   if (!dl)
+   if (!dl) {
+   vsp1_dlm_destroy(dlm);
return NULL;
+   }
 
list_add_tail(>list, >free);
}
-- 
git-series 0.9.1


[PATCH v4 01/11] media: vsp1: drm: Fix minor grammar error

2018-05-03 Thread Kieran Bingham
The pixel format is 'unsupported'. Fix the small debug message which
incorrectly declares this.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_drm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/vsp1/vsp1_drm.c 
b/drivers/media/platform/vsp1/vsp1_drm.c
index ef0148082bf7..2c3db8b8adce 100644
--- a/drivers/media/platform/vsp1/vsp1_drm.c
+++ b/drivers/media/platform/vsp1/vsp1_drm.c
@@ -806,7 +806,7 @@ int vsp1_du_atomic_update(struct device *dev, unsigned int 
pipe_index,
 */
fmtinfo = vsp1_get_format_info(vsp1, cfg->pixelformat);
if (!fmtinfo) {
-   dev_dbg(vsp1->dev, "Unsupport pixel format %08x for RPF\n",
+   dev_dbg(vsp1->dev, "Unsupported pixel format %08x for RPF\n",
cfg->pixelformat);
return -EINVAL;
}
-- 
git-series 0.9.1


[PATCH v4 10/11] media: vsp1: Support Interlaced display pipelines

2018-05-03 Thread Kieran Bingham
Calculate the top and bottom fields for the interlaced frames and
utilise the extended display list command feature to implement the
auto-field operations. This allows the DU to update the VSP2 registers
dynamically based upon the currently processing field.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

---
v3:
 - Pass DL through partition calls to allow autocmd's to be retrieved
 - Document interlaced field in struct vsp1_du_atomic_config

v2:
 - fix erroneous BIT value which enabled interlaced
 - fix field handling at frame_end interrupt
---
 drivers/media/platform/vsp1/vsp1_dl.c   | 10 -
 drivers/media/platform/vsp1/vsp1_drm.c  | 11 -
 drivers/media/platform/vsp1/vsp1_regs.h |  1 +-
 drivers/media/platform/vsp1/vsp1_rpf.c  | 71 --
 drivers/media/platform/vsp1/vsp1_rwpf.h |  1 +-
 include/media/vsp1.h|  2 +-
 6 files changed, 93 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index d33ae5f125bd..bbe9f3006f71 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -906,6 +906,8 @@ void vsp1_dl_list_commit(struct vsp1_dl_list *dl, bool 
internal)
  */
 unsigned int vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm)
 {
+   struct vsp1_device *vsp1 = dlm->vsp1;
+   u32 status = vsp1_read(vsp1, VI6_STATUS);
unsigned int flags = 0;
 
spin_lock(>lock);
@@ -931,6 +933,14 @@ unsigned int vsp1_dlm_irq_frame_end(struct vsp1_dl_manager 
*dlm)
goto done;
 
/*
+* Progressive streams report only TOP fields. If we have a BOTTOM
+* field, we are interlaced, and expect the frame to complete on the
+* next frame end interrupt.
+*/
+   if (status & VI6_STATUS_FLD_STD(dlm->index))
+   goto done;
+
+   /*
 * The device starts processing the queued display list right after the
 * frame end interrupt. The display list thus becomes active.
 */
diff --git a/drivers/media/platform/vsp1/vsp1_drm.c 
b/drivers/media/platform/vsp1/vsp1_drm.c
index 2c3db8b8adce..cc29c9d96bb7 100644
--- a/drivers/media/platform/vsp1/vsp1_drm.c
+++ b/drivers/media/platform/vsp1/vsp1_drm.c
@@ -811,6 +811,17 @@ int vsp1_du_atomic_update(struct device *dev, unsigned int 
pipe_index,
return -EINVAL;
}
 
+   if (!(vsp1_feature(vsp1, VSP1_HAS_EXT_DL)) && cfg->interlaced) {
+   /*
+* Interlaced support requires extended display lists to
+* provide the auto-fld feature with the DU.
+*/
+   dev_dbg(vsp1->dev, "Interlaced unsupported on this output\n");
+   return -EINVAL;
+   }
+
+   rpf->interlaced = cfg->interlaced;
+
rpf->fmtinfo = fmtinfo;
rpf->format.num_planes = fmtinfo->planes;
rpf->format.plane_fmt[0].bytesperline = cfg->pitch;
diff --git a/drivers/media/platform/vsp1/vsp1_regs.h 
b/drivers/media/platform/vsp1/vsp1_regs.h
index d054767570c1..a2ac65cc5155 100644
--- a/drivers/media/platform/vsp1/vsp1_regs.h
+++ b/drivers/media/platform/vsp1/vsp1_regs.h
@@ -28,6 +28,7 @@
 #define VI6_SRESET_SRTS(n) (1 << (n))
 
 #define VI6_STATUS 0x0038
+#define VI6_STATUS_FLD_STD(n)  (1 << ((n) + 28))
 #define VI6_STATUS_SYS_ACT(n)  (1 << ((n) + 8))
 
 #define VI6_WPF_IRQ_ENB(n) (0x0048 + (n) * 12)
diff --git a/drivers/media/platform/vsp1/vsp1_rpf.c 
b/drivers/media/platform/vsp1/vsp1_rpf.c
index 8fae7c485642..511b2e127820 100644
--- a/drivers/media/platform/vsp1/vsp1_rpf.c
+++ b/drivers/media/platform/vsp1/vsp1_rpf.c
@@ -20,6 +20,20 @@
 #define RPF_MAX_WIDTH  8190
 #define RPF_MAX_HEIGHT 8190
 
+/* Pre extended display list command data structure */
+struct vsp1_extcmd_auto_fld_body {
+   u32 top_y0;
+   u32 bottom_y0;
+   u32 top_c0;
+   u32 bottom_c0;
+   u32 top_c1;
+   u32 bottom_c1;
+   u32 reserved0;
+   u32 reserved1;
+} __packed;
+
+#define VSP1_DL_EXT_AUTOFLD_INTBIT(0)
+
 /* 
-
  * Device Access
  */
@@ -64,6 +78,14 @@ static void rpf_configure_stream(struct vsp1_entity *entity,
pstride |= format->plane_fmt[1].bytesperline
<< VI6_RPF_SRCM_PSTRIDE_C_SHIFT;
 
+   /*
+* pstride has both STRIDE_Y and STRIDE_C, but multiplying the whole
+* of pstride by 2 is conveniently OK here as we are multiplying both
+* values.
+*/
+   if (rpf->interlaced)
+   pstride *= 2;
+
vsp1_rpf_write(rpf, dlb, VI6_RPF_SRCM_PSTRIDE, pstride);
 
/* Format */
@@ -100,6 +122,9 @@ s

[PATCH v4 00/11] R-Car DU Interlaced support through VSP1

2018-05-03 Thread Kieran Bingham
The Gen3 R-Car DU devices make use of the VSP to handle frame processing.

In this series we implement support for handling interlaced pipelines by using
the auto-fld feature of the VSP hardware.

The implementation is preceded by some cleanup work and refactoring, through
patches 1 to 6. These are trivial and could be collected earlier and
independently if this series requires further revisions.

Patch 7 makes a key distinctive change to remove all existing support for
headerless display lists throughout the VSP1 driver, and ensures that all
pipelines use the same code path. This simplifies the code and reduces
opportunity for untested code paths to exist.

Patches 8, 9 and 10 implement the relevant support in the VSP1 driver, before
patch 11 finally enables the feature through the drm R-Car DU driver.

This series is based upon my previous TLB optimise and body rework (v9), and is
available from the following URL:

  git://git.kernel.org/pub/scm/linux/kernel/git/kbingham/rcar.git
  tags/vsp1/du/interlaced/v4

ChangeLog:

v4:
 - Move configure_partition() call changes into tlb-optimise-v9

v3:
 - Rebased on top of TLB Optimise rework v8
 - Added the DL parameter back into the configure_partition() calls.
   - This change could be moved into the TLB-Optimise series.
 - Document interlaced field in struct vsp1_du_atomic_config

v2:
 - media: vsp1: use kernel __packed for structures
became:
   media: vsp1: Remove packed attributes from aligned structures

 - media: vsp1: Add support for extended display list headers
   - No longer declares structs __packed

 - media: vsp1: Provide support for extended command pools
   - Fix spelling typo in commit message
   - constify, and staticify the instantiation of vsp1_extended_commands
   - s/autfld_cmds/autofld_cmds/
   - staticify cmd pool functions (Thanks kbuild-bot)

 - media: vsp1: Support Interlaced display pipelines
   - fix erroneous BIT value which enabled interlaced
   - fix field handling at frame_end interrupt

Kieran Bingham (11):
  media: vsp1: drm: Fix minor grammar error
  media: vsp1: Remove packed attributes from aligned structures
  media: vsp1: Rename dl_child to dl_next
  media: vsp1: Remove unused display list structure field
  media: vsp1: Clean up DLM objects on error
  media: vsp1: Provide VSP1 feature helper macro
  media: vsp1: Use header display lists for all WPF outputs linked to the DU
  media: vsp1: Add support for extended display list headers
  media: vsp1: Provide support for extended command pools
  media: vsp1: Support Interlaced display pipelines
  drm: rcar-du: Support interlaced video output through vsp1

 drivers/gpu/drm/rcar-du/rcar_du_crtc.c  |   1 +-
 drivers/gpu/drm/rcar-du/rcar_du_vsp.c   |   3 +-
 drivers/media/platform/vsp1/vsp1.h  |   3 +-
 drivers/media/platform/vsp1/vsp1_dl.c   | 407 +++--
 drivers/media/platform/vsp1/vsp1_dl.h   |  32 +-
 drivers/media/platform/vsp1/vsp1_drm.c  |  13 +-
 drivers/media/platform/vsp1/vsp1_drv.c  |  23 +-
 drivers/media/platform/vsp1/vsp1_regs.h |   6 +-
 drivers/media/platform/vsp1/vsp1_rpf.c  |  71 +++-
 drivers/media/platform/vsp1/vsp1_rwpf.h |   1 +-
 drivers/media/platform/vsp1/vsp1_wpf.c  |   6 +-
 include/media/vsp1.h|   2 +-
 12 files changed, 456 insertions(+), 112 deletions(-)

base-commit: de53826416ea9c22ee985d1f0291aab7d7ea94ce
-- 
git-series 0.9.1


[PATCH v9 6/8] media: vsp1: Refactor display list configure operations

2018-05-03 Thread Kieran Bingham
The entities provide a single .configure operation which configures the
object into the target display list, based on the vsp1_entity_params
selection.

Split the configure function into three parts, '.configure_stream()',
'.configure_frame()', and '.configure_partition()' to facilitate
splitting the configuration of each parameter class into separate
display list bodies.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

---
The checkpatch warning:

WARNING: function definition argument 'struct vsp1_dl_list *' should
also have an identifier name

has been ignored to match the existing code style.

v8:
 - Add support for the UIF
 - Remove unrelated whitespace change
 - Fix comment location for clu_configure_stream()
 - Update configure documentations
 - Implement configure_partition separation.

v7
 - Fix formatting and white space
 - s/prepare/configure_stream/
 - s/configure/configure_frame/
---
 drivers/media/platform/vsp1/vsp1_brx.c|  12 +-
 drivers/media/platform/vsp1/vsp1_clu.c|  77 ++
 drivers/media/platform/vsp1/vsp1_drm.c|  12 +-
 drivers/media/platform/vsp1/vsp1_entity.c |  24 ++-
 drivers/media/platform/vsp1/vsp1_entity.h |  39 +--
 drivers/media/platform/vsp1/vsp1_hgo.c|  12 +-
 drivers/media/platform/vsp1/vsp1_hgt.c|  12 +-
 drivers/media/platform/vsp1/vsp1_hsit.c   |  12 +-
 drivers/media/platform/vsp1/vsp1_lif.c|  12 +-
 drivers/media/platform/vsp1/vsp1_lut.c|  47 +---
 drivers/media/platform/vsp1/vsp1_rpf.c| 168 ++---
 drivers/media/platform/vsp1/vsp1_sru.c|  12 +-
 drivers/media/platform/vsp1/vsp1_uds.c|  56 ++--
 drivers/media/platform/vsp1/vsp1_uif.c|  16 +-
 drivers/media/platform/vsp1/vsp1_video.c  |  28 +--
 drivers/media/platform/vsp1/vsp1_wpf.c| 303 ---
 16 files changed, 422 insertions(+), 420 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_brx.c 
b/drivers/media/platform/vsp1/vsp1_brx.c
index 3beec18fd863..011edac5ebc1 100644
--- a/drivers/media/platform/vsp1/vsp1_brx.c
+++ b/drivers/media/platform/vsp1/vsp1_brx.c
@@ -281,19 +281,15 @@ static const struct v4l2_subdev_ops brx_ops = {
  * VSP1 Entity Operations
  */
 
-static void brx_configure(struct vsp1_entity *entity,
- struct vsp1_pipeline *pipe,
- struct vsp1_dl_list *dl,
- enum vsp1_entity_params params)
+static void brx_configure_stream(struct vsp1_entity *entity,
+struct vsp1_pipeline *pipe,
+struct vsp1_dl_list *dl)
 {
struct vsp1_brx *brx = to_brx(>subdev);
struct v4l2_mbus_framefmt *format;
unsigned int flags;
unsigned int i;
 
-   if (params != VSP1_ENTITY_PARAMS_INIT)
-   return;
-
format = vsp1_entity_get_pad_format(>entity, brx->entity.config,
brx->entity.source_pad);
 
@@ -400,7 +396,7 @@ static void brx_configure(struct vsp1_entity *entity,
 }
 
 static const struct vsp1_entity_operations brx_entity_ops = {
-   .configure = brx_configure,
+   .configure_stream = brx_configure_stream,
 };
 
 /* 
-
diff --git a/drivers/media/platform/vsp1/vsp1_clu.c 
b/drivers/media/platform/vsp1/vsp1_clu.c
index ea83f1b7d125..0a978980d447 100644
--- a/drivers/media/platform/vsp1/vsp1_clu.c
+++ b/drivers/media/platform/vsp1/vsp1_clu.c
@@ -168,58 +168,50 @@ static const struct v4l2_subdev_ops clu_ops = {
 /* 
-
  * VSP1 Entity Operations
  */
+static void clu_configure_stream(struct vsp1_entity *entity,
+struct vsp1_pipeline *pipe,
+struct vsp1_dl_list *dl)
+{
+   struct vsp1_clu *clu = to_clu(>subdev);
+   struct v4l2_mbus_framefmt *format;
 
-static void clu_configure(struct vsp1_entity *entity,
- struct vsp1_pipeline *pipe,
- struct vsp1_dl_list *dl,
- enum vsp1_entity_params params)
+   /*
+* The yuv_mode can't be changed during streaming. Cache it internally
+* for future runtime configuration calls.
+*/
+   format = vsp1_entity_get_pad_format(>entity,
+   clu->entity.config,
+   CLU_PAD_SINK);
+   clu->yuv_mode = format->code == MEDIA_BUS_FMT_AYUV8_1X32;
+}
+
+static void clu_configure_frame(struct vsp1_entity *entity,
+   struct vsp1_pipeline *pipe,
+   struct vsp1_dl_list *dl)
 {
struct vsp1_clu *clu = to_clu(>subdev);
struct vsp1_dl_body *dlb;
unsigned long flags;
u32 ctrl = VI6_CLU_CTRL_AAI | VI6_CLU_CTRL_MVS | VI6_CLU_CTRL_EN;
 
- 

[PATCH v9 7/8] media: vsp1: Adapt entities to configure into a body

2018-05-03 Thread Kieran Bingham
Currently the entities store their configurations into a display list.
Adapt this such that the code can be configured into a body directly,
allowing greater flexibility and control of the content.

All users of vsp1_dl_list_write() are removed in this process, thus it
too is removed.

A helper, vsp1_dl_list_get_body0() is provided to access the internal body0
from the display list.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
---
v9:
 - Pass the DL through configure_partition() calls

v8:
 - Fixed comment style and indentation
 - Supported UIF
 - Supported new configure_partition() functionality

v7:
 - Rebase
 - s/prepare/configure_stream/
 - s/configure/configure_frame/
---
 drivers/media/platform/vsp1/vsp1_brx.c| 22 ++--
 drivers/media/platform/vsp1/vsp1_clu.c| 23 ++---
 drivers/media/platform/vsp1/vsp1_dl.c | 12 ++-
 drivers/media/platform/vsp1/vsp1_dl.h |  2 +-
 drivers/media/platform/vsp1/vsp1_drm.c| 12 ---
 drivers/media/platform/vsp1/vsp1_entity.c | 22 ++--
 drivers/media/platform/vsp1/vsp1_entity.h | 18 ++
 drivers/media/platform/vsp1/vsp1_hgo.c| 16 -
 drivers/media/platform/vsp1/vsp1_hgt.c| 18 +-
 drivers/media/platform/vsp1/vsp1_hsit.c   | 10 ++---
 drivers/media/platform/vsp1/vsp1_lif.c| 15 
 drivers/media/platform/vsp1/vsp1_lut.c| 23 ++---
 drivers/media/platform/vsp1/vsp1_pipe.c   |  4 +-
 drivers/media/platform/vsp1/vsp1_pipe.h   |  3 +-
 drivers/media/platform/vsp1/vsp1_rpf.c| 44 
 drivers/media/platform/vsp1/vsp1_sru.c| 14 
 drivers/media/platform/vsp1/vsp1_uds.c| 25 +++---
 drivers/media/platform/vsp1/vsp1_uds.h|  2 +-
 drivers/media/platform/vsp1/vsp1_uif.c| 21 +--
 drivers/media/platform/vsp1/vsp1_video.c  | 16 ++---
 drivers/media/platform/vsp1/vsp1_wpf.c| 42 ---
 21 files changed, 194 insertions(+), 170 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_brx.c 
b/drivers/media/platform/vsp1/vsp1_brx.c
index 011edac5ebc1..359917b5d842 100644
--- a/drivers/media/platform/vsp1/vsp1_brx.c
+++ b/drivers/media/platform/vsp1/vsp1_brx.c
@@ -26,10 +26,10 @@
  * Device Access
  */
 
-static inline void vsp1_brx_write(struct vsp1_brx *brx, struct vsp1_dl_list 
*dl,
- u32 reg, u32 data)
+static inline void vsp1_brx_write(struct vsp1_brx *brx,
+ struct vsp1_dl_body *dlb, u32 reg, u32 data)
 {
-   vsp1_dl_list_write(dl, brx->base + reg, data);
+   vsp1_dl_body_write(dlb, brx->base + reg, data);
 }
 
 /* 
-
@@ -283,7 +283,7 @@ static const struct v4l2_subdev_ops brx_ops = {
 
 static void brx_configure_stream(struct vsp1_entity *entity,
 struct vsp1_pipeline *pipe,
-struct vsp1_dl_list *dl)
+struct vsp1_dl_body *dlb)
 {
struct vsp1_brx *brx = to_brx(>subdev);
struct v4l2_mbus_framefmt *format;
@@ -305,7 +305,7 @@ static void brx_configure_stream(struct vsp1_entity *entity,
 * format at the pipeline output is premultiplied.
 */
flags = pipe->output ? pipe->output->format.flags : 0;
-   vsp1_brx_write(brx, dl, VI6_BRU_INCTRL,
+   vsp1_brx_write(brx, dlb, VI6_BRU_INCTRL,
   flags & V4L2_PIX_FMT_FLAG_PREMUL_ALPHA ?
   0 : VI6_BRU_INCTRL_NRM);
 
@@ -313,12 +313,12 @@ static void brx_configure_stream(struct vsp1_entity 
*entity,
 * Set the background position to cover the whole output image and
 * configure its color.
 */
-   vsp1_brx_write(brx, dl, VI6_BRU_VIRRPF_SIZE,
+   vsp1_brx_write(brx, dlb, VI6_BRU_VIRRPF_SIZE,
   (format->width << VI6_BRU_VIRRPF_SIZE_HSIZE_SHIFT) |
   (format->height << VI6_BRU_VIRRPF_SIZE_VSIZE_SHIFT));
-   vsp1_brx_write(brx, dl, VI6_BRU_VIRRPF_LOC, 0);
+   vsp1_brx_write(brx, dlb, VI6_BRU_VIRRPF_LOC, 0);
 
-   vsp1_brx_write(brx, dl, VI6_BRU_VIRRPF_COL, brx->bgcolor |
+   vsp1_brx_write(brx, dlb, VI6_BRU_VIRRPF_COL, brx->bgcolor |
   (0xff << VI6_BRU_VIRRPF_COL_A_SHIFT));
 
/*
@@ -328,7 +328,7 @@ static void brx_configure_stream(struct vsp1_entity *entity,
 * unit.
 */
if (entity->type == VSP1_ENTITY_BRU)
-   vsp1_brx_write(brx, dl, VI6_BRU_ROP,
+   vsp1_brx_write(brx, dlb, VI6_BRU_ROP,
   VI6_BRU_ROP_DSTSEL_BRUIN(1) |
   VI6_BRU_ROP_CROP(VI6_ROP_NOP) |
   VI6_BRU_ROP_AROP(VI6_ROP_NOP));
@@ -370,7 +370,7 @@ static void brx_config

[PATCH v9 8/8] media: vsp1: Move video configuration to a cached dlb

2018-05-03 Thread Kieran Bingham
We are now able to configure a pipeline directly into a local display
list body. Take advantage of this fact, and create a cacheable body to
store the configuration of the pipeline in the video object.

vsp1_video_pipeline_run() is now the last user of the pipe->dl object.
Convert this function to use the cached video->config body and obtain a
local display list reference.

Attach the video->config body to the display list when needed before
committing to hardware.

The pipe object is marked as un-configured when resuming from a suspend.
This ensures that when the hardware is reset - our cached configuration
will be re-attached to the next committed DL.

Our video DL usage now looks like the below output:

dl->body0 contains our disposable runtime configuration. Max 41.
dl_child->body0 is our partition specific configuration. Max 12.
dl->bodies shows our constant configuration and LUTs.

  These two are LUT/CLU:
 * dl->bodies[x]->num_entries 256 / max 256
 * dl->bodies[x]->num_entries 4914 / max 4914

Which shows that our 'constant' configuration cache is currently
utilised to a maximum of 64 entries.

trace-cmd report | \
grep max | sed 's/.*vsp1_dl_list_commit://g' | sort | uniq;

  dl->body0->num_entries 13 / max 128
  dl->body0->num_entries 14 / max 128
  dl->body0->num_entries 16 / max 128
  dl->body0->num_entries 20 / max 128
  dl->body0->num_entries 27 / max 128
  dl->body0->num_entries 34 / max 128
  dl->body0->num_entries 41 / max 128
  dl_child->body0->num_entries 10 / max 128
  dl_child->body0->num_entries 12 / max 128
  dl->bodies[x]->num_entries 15 / max 128
  dl->bodies[x]->num_entries 16 / max 128
  dl->bodies[x]->num_entries 17 / max 128
  dl->bodies[x]->num_entries 18 / max 128
  dl->bodies[x]->num_entries 20 / max 128
  dl->bodies[x]->num_entries 21 / max 128
  dl->bodies[x]->num_entries 256 / max 256
  dl->bodies[x]->num_entries 31 / max 128
  dl->bodies[x]->num_entries 32 / max 128
  dl->bodies[x]->num_entries 39 / max 128
  dl->bodies[x]->num_entries 40 / max 128
  dl->bodies[x]->num_entries 47 / max 128
  dl->bodies[x]->num_entries 48 / max 128
  dl->bodies[x]->num_entries 4914 / max 4914
  dl->bodies[x]->num_entries 55 / max 128
  dl->bodies[x]->num_entries 56 / max 128
  dl->bodies[x]->num_entries 63 / max 128
  dl->bodies[x]->num_entries 64 / max 128

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
v8:
 - Fix comments
 - Rename video->pipe_config -> video->stream_config

v3:
 - 's/fragment/body/', 's/fragments/bodies/'
 - video dlb cache allocation increased from 2 to 3 dlbs

v4:
 - Adjust pipe configured flag to be reset on resume rather than suspend
 - rename dl_child, dl_next
---
 drivers/media/platform/vsp1/vsp1_pipe.c  |  9 +++-
 drivers/media/platform/vsp1/vsp1_pipe.h  |  5 +--
 drivers/media/platform/vsp1/vsp1_video.c | 72 +++--
 drivers/media/platform/vsp1/vsp1_video.h |  2 +-
 4 files changed, 59 insertions(+), 29 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_pipe.c 
b/drivers/media/platform/vsp1/vsp1_pipe.c
index d06ffa01027c..70af6c9fc97f 100644
--- a/drivers/media/platform/vsp1/vsp1_pipe.c
+++ b/drivers/media/platform/vsp1/vsp1_pipe.c
@@ -230,6 +230,7 @@ void vsp1_pipeline_run(struct vsp1_pipeline *pipe)
vsp1_write(vsp1, VI6_CMD(pipe->output->entity.index),
   VI6_CMD_STRCMD);
pipe->state = VSP1_PIPELINE_RUNNING;
+   pipe->configured = true;
}
 
pipe->buffers_ready = 0;
@@ -295,6 +296,8 @@ int vsp1_pipeline_stop(struct vsp1_pipeline *pipe)
 
v4l2_subdev_call(>output->entity.subdev, video, s_stream, 0);
 
+   pipe->configured = false;
+
return ret;
 }
 
@@ -451,6 +454,12 @@ void vsp1_pipelines_resume(struct vsp1_device *vsp1)
continue;
 
spin_lock_irqsave(>irqlock, flags);
+   /*
+* The hardware may have been reset during a suspend and will
+* need a full reconfiguration.
+*/
+   pipe->configured = false;
+
if (vsp1_pipeline_ready(pipe))
vsp1_pipeline_run(pipe);
spin_unlock_irqrestore(>irqlock, flags);
diff --git a/drivers/media/platform/vsp1/vsp1_pipe.h 
b/drivers/media/platform/vsp1/vsp1_pipe.h
index e00010693eef..7c8b30018aac 100644
--- a/drivers/media/platform/vsp1/vsp1_pipe.h
+++ b/drivers/media/platform/vsp1/vsp1_pipe.h
@@ -86,6 +86,7 @@ struct vsp1_partition {
  * @irqlock: protects the pipeline state
  * @state: current state
  * @wq: wait queue to wait for state change completion
+ * @configured: flag determining if the hardware has run since reset
  * @frame_end: frame end interrupt

[PATCH v9 5/8] media: vsp1: Use reference counting for bodies

2018-05-03 Thread Kieran Bingham
Extend the display list body with a reference count, allowing bodies to
be kept as long as a reference is maintained. This provides the ability
to keep a cached copy of bodies which will not change, so that they can
be re-applied to multiple display lists.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
---
This could be squashed into the body update code, but it's not a
straightforward squash as the refcounts will affect both:
  v4l: vsp1: Provide a body pool
and
  v4l: vsp1: Convert display lists to use new body pool
therefore, I have kept this separate to prevent breaking bisectability
of the vsp-tests.

v3:
 - 's/fragment/body/'

v4:
 - Fix up reference handling comments.

Changes since v7:

- Fix comment style
---
 drivers/media/platform/vsp1/vsp1_clu.c |  7 ++-
 drivers/media/platform/vsp1/vsp1_dl.c  | 16 ++--
 drivers/media/platform/vsp1/vsp1_lut.c |  7 ++-
 3 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_clu.c 
b/drivers/media/platform/vsp1/vsp1_clu.c
index 8efa12f5e53f..ea83f1b7d125 100644
--- a/drivers/media/platform/vsp1/vsp1_clu.c
+++ b/drivers/media/platform/vsp1/vsp1_clu.c
@@ -212,8 +212,13 @@ static void clu_configure(struct vsp1_entity *entity,
clu->clu = NULL;
spin_unlock_irqrestore(>lock, flags);
 
-   if (dlb)
+   if (dlb) {
vsp1_dl_list_add_body(dl, dlb);
+
+   /* Release our local reference. */
+   vsp1_dl_body_put(dlb);
+   }
+
break;
}
 }
diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index 617c46a03dec..1407c90c6880 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -54,6 +55,8 @@ struct vsp1_dl_body {
struct list_head list;
struct list_head free;
 
+   refcount_t refcnt;
+
struct vsp1_dl_body_pool *pool;
struct vsp1_device *vsp1;
 
@@ -258,6 +261,7 @@ struct vsp1_dl_body *vsp1_dl_body_get(struct 
vsp1_dl_body_pool *pool)
if (!list_empty(>free)) {
dlb = list_first_entry(>free, struct vsp1_dl_body, free);
list_del(>free);
+   refcount_set(>refcnt, 1);
}
 
spin_unlock_irqrestore(>lock, flags);
@@ -278,6 +282,9 @@ void vsp1_dl_body_put(struct vsp1_dl_body *dlb)
if (!dlb)
return;
 
+   if (!refcount_dec_and_test(>refcnt))
+   return;
+
dlb->num_entries = 0;
 
spin_lock_irqsave(>pool->lock, flags);
@@ -463,8 +470,11 @@ void vsp1_dl_list_write(struct vsp1_dl_list *dl, u32 reg, 
u32 data)
  * which bodies are added.
  *
  * Adding a body to a display list passes ownership of the body to the list. 
The
- * caller must not touch the body after this call, and must not release it
- * explicitly with vsp1_dl_body_put().
+ * caller retains its reference to the fragment when adding it to the display
+ * list, but is not allowed to add new entries to the body.
+ *
+ * The reference must be explicitly released by a call to vsp1_dl_body_put()
+ * when the body isn't needed anymore.
  *
  * Additional bodies are only usable for display lists in header mode.
  * Attempting to add a body to a header-less display list will return an error.
@@ -475,6 +485,8 @@ int vsp1_dl_list_add_body(struct vsp1_dl_list *dl, struct 
vsp1_dl_body *dlb)
if (dl->dlm->mode != VSP1_DL_MODE_HEADER)
return -EINVAL;
 
+   refcount_inc(>refcnt);
+
list_add_tail(>list, >bodies);
 
return 0;
diff --git a/drivers/media/platform/vsp1/vsp1_lut.c 
b/drivers/media/platform/vsp1/vsp1_lut.c
index 6b358617ce15..b3ea90172439 100644
--- a/drivers/media/platform/vsp1/vsp1_lut.c
+++ b/drivers/media/platform/vsp1/vsp1_lut.c
@@ -168,8 +168,13 @@ static void lut_configure(struct vsp1_entity *entity,
lut->lut = NULL;
spin_unlock_irqrestore(>lock, flags);
 
-   if (dlb)
+   if (dlb) {
vsp1_dl_list_add_body(dl, dlb);
+
+   /* Release our local reference. */
+   vsp1_dl_body_put(dlb);
+   }
+
break;
}
 }
-- 
git-series 0.9.1


[PATCH v9 2/8] media: vsp1: Protect bodies against overflow

2018-05-03 Thread Kieran Bingham
The body write function relies on the code never asking it to write more
than the entries available in the list.

Currently with each list body containing 256 entries, this is fine, but
we can reduce this number greatly saving memory. In preparation of this
add a level of protection to catch any buffer overflows.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinch...@ideasonboard.com>

---

v3:
 - adapt for new 'body' terminology
 - simplify WARN_ON macro usage
---
 drivers/media/platform/vsp1/vsp1_dl.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index 083da4f05c20..51965c30dec2 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -46,6 +46,7 @@ struct vsp1_dl_entry {
  * @dma: DMA address of the entries
  * @size: size of the DMA memory in bytes
  * @num_entries: number of stored entries
+ * @max_entries: number of entries available
  */
 struct vsp1_dl_body {
struct list_head list;
@@ -56,6 +57,7 @@ struct vsp1_dl_body {
size_t size;
 
unsigned int num_entries;
+   unsigned int max_entries;
 };
 
 /**
@@ -138,6 +140,7 @@ static int vsp1_dl_body_init(struct vsp1_device *vsp1,
 
dlb->vsp1 = vsp1;
dlb->size = size;
+   dlb->max_entries = num_entries;
 
dlb->entries = dma_alloc_wc(vsp1->bus_master, dlb->size, >dma,
GFP_KERNEL);
@@ -219,6 +222,10 @@ void vsp1_dl_body_free(struct vsp1_dl_body *dlb)
  */
 void vsp1_dl_body_write(struct vsp1_dl_body *dlb, u32 reg, u32 data)
 {
+   if (WARN_ONCE(dlb->num_entries >= dlb->max_entries,
+ "DLB size exceeded (max %u)", dlb->max_entries))
+   return;
+
dlb->entries[dlb->num_entries].addr = reg;
dlb->entries[dlb->num_entries].data = data;
dlb->num_entries++;
-- 
git-series 0.9.1


[PATCH v9 3/8] media: vsp1: Provide a body pool

2018-05-03 Thread Kieran Bingham
Each display list allocates a body to store register values in a dma
accessible buffer from a dma_alloc_wc() allocation. Each of these
results in an entry in the IOMMU TLB, and a large number of display list
allocations adds pressure to this resource.

Reduce TLB pressure on the IPMMUs by allocating multiple display list
bodies in a single allocation, and providing these to the display list
through a 'body pool'. A pool can be allocated by the display list
manager or entities which require their own body allocations.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

---
v8:
 - Update commit message
 - Fix comments and descriptions

v4:
 - Provide comment explaining extra allocation on body pool
   highlighting area for optimisation later.

v3:
 - s/fragment/body/, s/fragments/bodies/
 - qty -> num_bodies
 - indentation fix
 - s/vsp1_dl_body_pool_{alloc,free}/vsp1_dl_body_pool_{create,destroy}/'
 - Add kerneldoc to non-static functions

v2:
 - assign dlb->dma correctly
---
 drivers/media/platform/vsp1/vsp1_dl.c | 163 +++-
 drivers/media/platform/vsp1/vsp1_dl.h |   8 +-
 2 files changed, 171 insertions(+)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index 51965c30dec2..41ace89a585b 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -41,6 +41,8 @@ struct vsp1_dl_entry {
 /**
  * struct vsp1_dl_body - Display list body
  * @list: entry in the display list list of bodies
+ * @free: entry in the pool free body list
+ * @pool: pool to which this body belongs
  * @vsp1: the VSP1 device
  * @entries: array of entries
  * @dma: DMA address of the entries
@@ -50,6 +52,9 @@ struct vsp1_dl_entry {
  */
 struct vsp1_dl_body {
struct list_head list;
+   struct list_head free;
+
+   struct vsp1_dl_body_pool *pool;
struct vsp1_device *vsp1;
 
struct vsp1_dl_entry *entries;
@@ -61,6 +66,30 @@ struct vsp1_dl_body {
 };
 
 /**
+ * struct vsp1_dl_body_pool - display list body pool
+ * @dma: DMA address of the entries
+ * @size: size of the full DMA memory pool in bytes
+ * @mem: CPU memory pointer for the pool
+ * @bodies: Array of DLB structures for the pool
+ * @free: List of free DLB entries
+ * @lock: Protects the free list
+ * @vsp1: the VSP1 device
+ */
+struct vsp1_dl_body_pool {
+   /* DMA allocation */
+   dma_addr_t dma;
+   size_t size;
+   void *mem;
+
+   /* Body management */
+   struct vsp1_dl_body *bodies;
+   struct list_head free;
+   spinlock_t lock;
+
+   struct vsp1_device *vsp1;
+};
+
+/**
  * struct vsp1_dl_list - Display list
  * @list: entry in the display list manager lists
  * @dlm: the display list manager
@@ -104,6 +133,7 @@ enum vsp1_dl_mode {
  * @active: list currently being processed (loaded) by hardware
  * @queued: list queued to the hardware (written to the DL registers)
  * @pending: list waiting to be queued to the hardware
+ * @pool: body pool for the display list bodies
  * @gc_work: bodies garbage collector work struct
  * @gc_bodies: array of display list bodies waiting to be freed
  */
@@ -119,6 +149,8 @@ struct vsp1_dl_manager {
struct vsp1_dl_list *queued;
struct vsp1_dl_list *pending;
 
+   struct vsp1_dl_body_pool *pool;
+
struct work_struct gc_work;
struct list_head gc_bodies;
 };
@@ -127,6 +159,137 @@ struct vsp1_dl_manager {
  * Display List Body Management
  */
 
+/**
+ * vsp1_dl_body_pool_create - Create a pool of bodies from a single allocation
+ * @vsp1: The VSP1 device
+ * @num_bodies: The number of bodies to allocate
+ * @num_entries: The maximum number of entries that a body can contain
+ * @extra_size: Extra allocation provided for the bodies
+ *
+ * Allocate a pool of display list bodies each with enough memory to contain 
the
+ * requested number of entries plus the @extra_size.
+ *
+ * Return a pointer to a pool on success or NULL if memory can't be allocated.
+ */
+struct vsp1_dl_body_pool *
+vsp1_dl_body_pool_create(struct vsp1_device *vsp1, unsigned int num_bodies,
+unsigned int num_entries, size_t extra_size)
+{
+   struct vsp1_dl_body_pool *pool;
+   size_t dlb_size;
+   unsigned int i;
+
+   pool = kzalloc(sizeof(*pool), GFP_KERNEL);
+   if (!pool)
+   return NULL;
+
+   pool->vsp1 = vsp1;
+
+   /*
+* TODO: 'extra_size' is only used by vsp1_dlm_create(), to allocate
+* extra memory for the display list header. We need only one header per
+* display list, not per display list body, thus this allocation is
+* extraneous and should be reworked in the future.
+*/
+   dlb_size = num_entries * sizeof(struct vsp1_dl_entry) + extra_size;
+   pool->size = dlb_size * num_bodies;
+
+   pool->bodies = kcalloc(num_bodies, sizeof(*pool->bodies), GFP_KERNEL);
+   if (!pool->bodies) {

[PATCH v9 4/8] media: vsp1: Convert display lists to use new body pool

2018-05-03 Thread Kieran Bingham
Adapt the dl->body0 object to use an object from the body pool. This
greatly reduces the pressure on the TLB for IPMMU use cases, as all of
the lists use a single allocation for the main body.

The CLU and LUT objects pre-allocate a pool containing three bodies,
allowing a userspace update before the hardware has committed a previous
set of tables.

Bodies are no longer 'freed' in interrupt context, but instead released
back to their respective pools. This allows us to remove the garbage
collector in the DLM.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

---
v9:
 - Remove redundant reference to gc_bodies

v8:
 - Don't pass dlm->pool through vsp1_dl_list_alloc()  as it's already in the 
dlm.
 - Fix up comments

v4-v7:
 - No changes (except rebases)

v3:
 - 's/fragment/body', 's/fragments/bodies/'
 - CLU/LUT now allocate 3 bodies
 - vsp1_dl_list_fragments_free -> vsp1_dl_list_bodies_put

v2:
 - Use dl->body0->max_entries to determine header offset, instead of the
   global constant VSP1_DL_NUM_ENTRIES which is incorrect.
 - squash updates for LUT, CLU, and fragment cleanup into single patch.
   (Not fully bisectable when separated)
---
 drivers/media/platform/vsp1/vsp1_clu.c |  27 ++-
 drivers/media/platform/vsp1/vsp1_clu.h |   1 +-
 drivers/media/platform/vsp1/vsp1_dl.c  | 221 ++
 drivers/media/platform/vsp1/vsp1_dl.h  |   3 +-
 drivers/media/platform/vsp1/vsp1_lut.c |  27 ++-
 drivers/media/platform/vsp1/vsp1_lut.h |   1 +-
 6 files changed, 100 insertions(+), 180 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_clu.c 
b/drivers/media/platform/vsp1/vsp1_clu.c
index ebfbb915dcdc..8efa12f5e53f 100644
--- a/drivers/media/platform/vsp1/vsp1_clu.c
+++ b/drivers/media/platform/vsp1/vsp1_clu.c
@@ -19,6 +19,8 @@
 #define CLU_MIN_SIZE   4U
 #define CLU_MAX_SIZE   8190U
 
+#define CLU_SIZE   (17 * 17 * 17)
+
 /* 
-
  * Device Access
  */
@@ -43,19 +45,19 @@ static int clu_set_table(struct vsp1_clu *clu, struct 
v4l2_ctrl *ctrl)
struct vsp1_dl_body *dlb;
unsigned int i;
 
-   dlb = vsp1_dl_body_alloc(clu->entity.vsp1, 1 + 17 * 17 * 17);
+   dlb = vsp1_dl_body_get(clu->pool);
if (!dlb)
return -ENOMEM;
 
vsp1_dl_body_write(dlb, VI6_CLU_ADDR, 0);
-   for (i = 0; i < 17 * 17 * 17; ++i)
+   for (i = 0; i < CLU_SIZE; ++i)
vsp1_dl_body_write(dlb, VI6_CLU_DATA, ctrl->p_new.p_u32[i]);
 
spin_lock_irq(>lock);
swap(clu->clu, dlb);
spin_unlock_irq(>lock);
 
-   vsp1_dl_body_free(dlb);
+   vsp1_dl_body_put(dlb);
return 0;
 }
 
@@ -216,8 +218,16 @@ static void clu_configure(struct vsp1_entity *entity,
}
 }
 
+static void clu_destroy(struct vsp1_entity *entity)
+{
+   struct vsp1_clu *clu = to_clu(>subdev);
+
+   vsp1_dl_body_pool_destroy(clu->pool);
+}
+
 static const struct vsp1_entity_operations clu_entity_ops = {
.configure = clu_configure,
+   .destroy = clu_destroy,
 };
 
 /* 
-
@@ -243,6 +253,17 @@ struct vsp1_clu *vsp1_clu_create(struct vsp1_device *vsp1)
if (ret < 0)
return ERR_PTR(ret);
 
+   /*
+* Pre-allocate a body pool, with 3 bodies allowing a userspace update
+* before the hardware has committed a previous set of tables, handling
+* both the queued and pending dl entries. One extra entry is added to
+* the CLU_SIZE to allow for the VI6_CLU_ADDR header.
+*/
+   clu->pool = vsp1_dl_body_pool_create(clu->entity.vsp1, 3, CLU_SIZE + 1,
+0);
+   if (!clu->pool)
+   return ERR_PTR(-ENOMEM);
+
/* Initialize the control handler. */
v4l2_ctrl_handler_init(>ctrls, 2);
v4l2_ctrl_new_custom(>ctrls, _table_control, NULL);
diff --git a/drivers/media/platform/vsp1/vsp1_clu.h 
b/drivers/media/platform/vsp1/vsp1_clu.h
index c45e6e707592..cef2f44481ba 100644
--- a/drivers/media/platform/vsp1/vsp1_clu.h
+++ b/drivers/media/platform/vsp1/vsp1_clu.h
@@ -32,6 +32,7 @@ struct vsp1_clu {
spinlock_t lock;
unsigned int mode;
struct vsp1_dl_body *clu;
+   struct vsp1_dl_body_pool *pool;
 };
 
 static inline struct vsp1_clu *to_clu(struct v4l2_subdev *subdev)
diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index 41ace89a585b..617c46a03dec 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -108,7 +108,7 @@ struct vsp1_dl_list {
struct vsp1_dl_header *header;
dma_addr_t dma;
 
-   struct vsp1_dl_body body0;
+   struct vsp1_dl_body *body0;

[PATCH v9 0/8] vsp1: TLB optimisation and DL caching

2018-05-03 Thread Kieran Bingham
ng in RGB565 during stress testing: pass
Testing WPF packing in BGR24 during stress testing: pass
Testing WPF packing in RGB24 during stress testing: pass
Testing WPF packing in ABGR32 during stress testing: pass
Testing WPF packing in ARGB32 during stress testing: pass
Testing WPF packing in XBGR32 during stress testing: pass
Testing WPF packing in XRGB32 during stress testing: pass
./vsp-unit-test-0021.sh: line 34: 14785 Killed  stress --cpu 8 
--io 4 --vm 2 --vm-bytes 128M
- vsp-unit-test-0022.sh
Testing long duration pipelines under stress: pass
./vsp-unit-test-0022.sh: line 38: 16751 Killed  stress --cpu 8 
--io 4 --vm 2 --vm-bytes 128M
- vsp-unit-test-0023.sh
Testing histogram HGT with hue areas 
0,255,255,255,255,255,255,255,255,255,255,255: pass
Testing histogram HGT with hue areas 0,40,40,80,80,120,120,160,160,200,200,255: 
pass
Testing histogram HGT with hue areas 
220,40,40,80,80,120,120,160,160,200,200,220: pass
Testing histogram HGT with hue areas 
0,10,50,60,100,110,150,160,200,210,250,255: pass
Testing histogram HGT with hue areas 
10,20,50,60,100,110,150,160,200,210,230,240: pass
Testing histogram HGT with hue areas 
240,20,60,80,100,120,140,160,180,200,210,220: pass
- vsp-unit-test-0024.sh
Test requires unavailable feature set `rpf.0 rpf.1 brs wpf.0': skipped
168 tests: 147 passed, 0 failed, 3 skipped

Kieran Bingham (8):
  media: vsp1: Reword uses of 'fragment' as 'body'
  media: vsp1: Protect bodies against overflow
  media: vsp1: Provide a body pool
  media: vsp1: Convert display lists to use new body pool
  media: vsp1: Use reference counting for bodies
  media: vsp1: Refactor display list configure operations
  media: vsp1: Adapt entities to configure into a body
  media: vsp1: Move video configuration to a cached dlb

 drivers/media/platform/vsp1/vsp1_brx.c|  32 +--
 drivers/media/platform/vsp1/vsp1_clu.c| 112 ---
 drivers/media/platform/vsp1/vsp1_clu.h|   1 +-
 drivers/media/platform/vsp1/vsp1_dl.c | 388 +--
 drivers/media/platform/vsp1/vsp1_dl.h |  20 +-
 drivers/media/platform/vsp1/vsp1_drm.c|  18 +-
 drivers/media/platform/vsp1/vsp1_entity.c |  34 +-
 drivers/media/platform/vsp1/vsp1_entity.h |  45 +--
 drivers/media/platform/vsp1/vsp1_hgo.c|  26 +--
 drivers/media/platform/vsp1/vsp1_hgt.c|  28 +--
 drivers/media/platform/vsp1/vsp1_hsit.c   |  20 +-
 drivers/media/platform/vsp1/vsp1_lif.c|  25 +-
 drivers/media/platform/vsp1/vsp1_lut.c|  80 +++--
 drivers/media/platform/vsp1/vsp1_lut.h|   1 +-
 drivers/media/platform/vsp1/vsp1_pipe.c   |  13 +-
 drivers/media/platform/vsp1/vsp1_pipe.h   |   8 +-
 drivers/media/platform/vsp1/vsp1_rpf.c| 188 +--
 drivers/media/platform/vsp1/vsp1_sru.c|  24 +-
 drivers/media/platform/vsp1/vsp1_uds.c|  73 ++--
 drivers/media/platform/vsp1/vsp1_uds.h|   2 +-
 drivers/media/platform/vsp1/vsp1_uif.c|  35 +--
 drivers/media/platform/vsp1/vsp1_video.c  |  92 ++---
 drivers/media/platform/vsp1/vsp1_video.h  |   2 +-
 drivers/media/platform/vsp1/vsp1_wpf.c| 327 ++-
 24 files changed, 884 insertions(+), 710 deletions(-)

base-commit: 22cf3c24e08f6ebff46c3e733991548a5dab25ed
-- 
git-series 0.9.1


[PATCH v9 1/8] media: vsp1: Reword uses of 'fragment' as 'body'

2018-05-03 Thread Kieran Bingham
Throughout the codebase, the term 'fragment' is used to represent a
display list body. This term duplicates the 'body' which is already in
use.

The datasheet references these objects as a body, therefore replace all
mentions of a fragment with a body, along with the corresponding
pluralised terms.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>
---
Changes since v7:

- Fix indentation
- Reword vsp1_dl_list_add_body() documentation

Changes since v6:

- Clean up the formatting of the vsp1_dl_list_add_body()
---
 drivers/media/platform/vsp1/vsp1_clu.c |  10 +-
 drivers/media/platform/vsp1/vsp1_dl.c  | 111 --
 drivers/media/platform/vsp1/vsp1_dl.h  |  13 +--
 drivers/media/platform/vsp1/vsp1_lut.c |   8 +-
 4 files changed, 70 insertions(+), 72 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_clu.c 
b/drivers/media/platform/vsp1/vsp1_clu.c
index 96a448e1504c..ebfbb915dcdc 100644
--- a/drivers/media/platform/vsp1/vsp1_clu.c
+++ b/drivers/media/platform/vsp1/vsp1_clu.c
@@ -43,19 +43,19 @@ static int clu_set_table(struct vsp1_clu *clu, struct 
v4l2_ctrl *ctrl)
struct vsp1_dl_body *dlb;
unsigned int i;
 
-   dlb = vsp1_dl_fragment_alloc(clu->entity.vsp1, 1 + 17 * 17 * 17);
+   dlb = vsp1_dl_body_alloc(clu->entity.vsp1, 1 + 17 * 17 * 17);
if (!dlb)
return -ENOMEM;
 
-   vsp1_dl_fragment_write(dlb, VI6_CLU_ADDR, 0);
+   vsp1_dl_body_write(dlb, VI6_CLU_ADDR, 0);
for (i = 0; i < 17 * 17 * 17; ++i)
-   vsp1_dl_fragment_write(dlb, VI6_CLU_DATA, ctrl->p_new.p_u32[i]);
+   vsp1_dl_body_write(dlb, VI6_CLU_DATA, ctrl->p_new.p_u32[i]);
 
spin_lock_irq(>lock);
swap(clu->clu, dlb);
spin_unlock_irq(>lock);
 
-   vsp1_dl_fragment_free(dlb);
+   vsp1_dl_body_free(dlb);
return 0;
 }
 
@@ -211,7 +211,7 @@ static void clu_configure(struct vsp1_entity *entity,
spin_unlock_irqrestore(>lock, flags);
 
if (dlb)
-   vsp1_dl_list_add_fragment(dl, dlb);
+   vsp1_dl_list_add_body(dl, dlb);
break;
}
 }
diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index 801dea475740..083da4f05c20 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -65,7 +65,7 @@ struct vsp1_dl_body {
  * @header: display list header, NULL for headerless lists
  * @dma: DMA address for the header
  * @body0: first display list body
- * @fragments: list of extra display list bodies
+ * @bodies: list of extra display list bodies
  * @has_chain: if true, indicates that there's a partition chain
  * @chain: entry in the display list partition chain
  * @internal: whether the display list is used for internal purpose
@@ -78,7 +78,7 @@ struct vsp1_dl_list {
dma_addr_t dma;
 
struct vsp1_dl_body body0;
-   struct list_head fragments;
+   struct list_head bodies;
 
bool has_chain;
struct list_head chain;
@@ -97,13 +97,13 @@ enum vsp1_dl_mode {
  * @mode: display list operation mode (header or headerless)
  * @singleshot: execute the display list in single-shot mode
  * @vsp1: the VSP1 device
- * @lock: protects the free, active, queued, pending and gc_fragments lists
+ * @lock: protects the free, active, queued, pending and gc_bodies lists
  * @free: array of all free display lists
  * @active: list currently being processed (loaded) by hardware
  * @queued: list queued to the hardware (written to the DL registers)
  * @pending: list waiting to be queued to the hardware
- * @gc_work: fragments garbage collector work struct
- * @gc_fragments: array of display list fragments waiting to be freed
+ * @gc_work: bodies garbage collector work struct
+ * @gc_bodies: array of display list bodies waiting to be freed
  */
 struct vsp1_dl_manager {
unsigned int index;
@@ -118,7 +118,7 @@ struct vsp1_dl_manager {
struct vsp1_dl_list *pending;
 
struct work_struct gc_work;
-   struct list_head gc_fragments;
+   struct list_head gc_bodies;
 };
 
 /* 
-
@@ -156,18 +156,17 @@ static void vsp1_dl_body_cleanup(struct vsp1_dl_body *dlb)
 }
 
 /**
- * vsp1_dl_fragment_alloc - Allocate a display list fragment
+ * vsp1_dl_body_alloc - Allocate a display list body
  * @vsp1: The VSP1 device
- * @num_entries: The maximum number of entries that the fragment can contain
+ * @num_entries: The maximum number of entries that the body can contain
  *
- * Allocate a display list fragment with enough memory to contain the requested
+ * Allocate a display list body with enough memory to contain the requested
  * number of entries.
  *
- * Return a pointer to a fragment on success o

Re: [PATCH v3 10/11] media: vsp1: Support Interlaced display pipelines

2018-05-03 Thread Kieran Bingham
Hi Reviewers ...

Comments inline ...

On 03/05/18 09:44, Kieran Bingham wrote:
> Calculate the top and bottom fields for the interlaced frames and
> utilise the extended display list command feature to implement the
> auto-field operations. This allows the DU to update the VSP2 registers
> dynamically based upon the currently processing field.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
> 
> ---
> v3:
>  - Pass DL through partition calls to allow autocmd's to be retrieved

This change itself could actually be folded into the TLB-Optimise series, but I
posted this in v3 here to show why it is necessary (currently).

I'll take suggestions on alternative implementations here too ...


>  - Document interlaced field in struct vsp1_du_atomic_config
> 
> v2:
>  - fix erroneous BIT value which enabled interlaced
>  - fix field handling at frame_end interrupt
> 
>  drivers/media/platform/vsp1/vsp1_dl.c | 10 +++-
>  drivers/media/platform/vsp1/vsp1_drm.c| 13 +++-
>  drivers/media/platform/vsp1/vsp1_entity.c |  3 +-
>  drivers/media/platform/vsp1/vsp1_entity.h |  2 +-
>  drivers/media/platform/vsp1/vsp1_regs.h   |  1 +-
>  drivers/media/platform/vsp1/vsp1_rpf.c| 73 +++-
>  drivers/media/platform/vsp1/vsp1_rwpf.h   |  1 +-
>  drivers/media/platform/vsp1/vsp1_uds.c|  1 +-
>  drivers/media/platform/vsp1/vsp1_video.c  |  2 +-
>  drivers/media/platform/vsp1/vsp1_wpf.c|  1 +-
>  include/media/vsp1.h  |  2 +-
>  11 files changed, 103 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
> b/drivers/media/platform/vsp1/vsp1_dl.c
> index 6366a1fc92b9..f3e75cff5ab3 100644
> --- a/drivers/media/platform/vsp1/vsp1_dl.c
> +++ b/drivers/media/platform/vsp1/vsp1_dl.c
> @@ -906,6 +906,8 @@ void vsp1_dl_list_commit(struct vsp1_dl_list *dl, bool 
> internal)
>   */
>  unsigned int vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm)
>  {
> + struct vsp1_device *vsp1 = dlm->vsp1;
> + u32 status = vsp1_read(vsp1, VI6_STATUS);
>   unsigned int flags = 0;
>  
>   spin_lock(>lock);
> @@ -931,6 +933,14 @@ unsigned int vsp1_dlm_irq_frame_end(struct 
> vsp1_dl_manager *dlm)
>   goto done;
>  
>   /*
> +  * Progressive streams report only TOP fields. If we have a BOTTOM
> +  * field, we are interlaced, and expect the frame to complete on the
> +  * next frame end interrupt.
> +  */
> + if (status & VI6_STATUS_FLD_STD(dlm->index))
> + goto done;
> +
> + /*
>* The device starts processing the queued display list right after the
>* frame end interrupt. The display list thus becomes active.
>*/
> diff --git a/drivers/media/platform/vsp1/vsp1_drm.c 
> b/drivers/media/platform/vsp1/vsp1_drm.c
> index 7714be7f50af..cc29c9d96bb7 100644
> --- a/drivers/media/platform/vsp1/vsp1_drm.c
> +++ b/drivers/media/platform/vsp1/vsp1_drm.c
> @@ -556,7 +556,7 @@ static void vsp1_du_pipeline_configure(struct 
> vsp1_pipeline *pipe)
>   vsp1_entity_route_setup(entity, pipe, dlb);
>   vsp1_entity_configure_stream(entity, pipe, dlb);
>   vsp1_entity_configure_frame(entity, pipe, dl, dlb);
> - vsp1_entity_configure_partition(entity, pipe, dlb);
> + vsp1_entity_configure_partition(entity, pipe, dl, dlb);

This change, and other changes to vsp1_entity_configure_partition() could be
performed in tlb-optimise when the corresponding change is made to
vsp1_entity_configure_frame()

>   }
>  
>   vsp1_dl_list_commit(dl, drm_pipe->force_brx_release);
> @@ -811,6 +811,17 @@ int vsp1_du_atomic_update(struct device *dev, unsigned 
> int pipe_index,
>   return -EINVAL;
>   }
>  
> + if (!(vsp1_feature(vsp1, VSP1_HAS_EXT_DL)) && cfg->interlaced) {
> + /*
> +  * Interlaced support requires extended display lists to
> +  * provide the auto-fld feature with the DU.
> +  */
> + dev_dbg(vsp1->dev, "Interlaced unsupported on this output\n");
> + return -EINVAL;
> + }
> +
> + rpf->interlaced = cfg->interlaced;
> +
>   rpf->fmtinfo = fmtinfo;
>   rpf->format.num_planes = fmtinfo->planes;
>   rpf->format.plane_fmt[0].bytesperline = cfg->pitch;
> diff --git a/drivers/media/platform/vsp1/vsp1_entity.c 
> b/drivers/media/platform/vsp1/vsp1_entity.c
> index 7b29ef3532fc..da276a85aa95 100644
> --- a/drivers/media/platform/vsp1/vsp1_entity.c
> +++ b/drivers/media/platform/vsp1/vsp1_entity.c
> @@ -88,10 +88,11 @@ void vsp1_entity_con

[PATCH v3 03/11] media: vsp1: Rename dl_child to dl_next

2018-05-03 Thread Kieran Bingham
Both vsp1_dl_list_commit() and __vsp1_dl_list_put() walk the display
list chain referencing the nodes as children, when in reality they are
siblings.

Update the terminology to 'dl_next' to be consistent with the
vsp1_video_pipeline_run() usage.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_dl.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index b6288ead24ae..09c29a4ed118 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -398,7 +398,7 @@ struct vsp1_dl_list *vsp1_dl_list_get(struct 
vsp1_dl_manager *dlm)
 /* This function must be called with the display list manager lock held.*/
 static void __vsp1_dl_list_put(struct vsp1_dl_list *dl)
 {
-   struct vsp1_dl_list *dl_child;
+   struct vsp1_dl_list *dl_next;
 
if (!dl)
return;
@@ -408,8 +408,8 @@ static void __vsp1_dl_list_put(struct vsp1_dl_list *dl)
 * hardware operation.
 */
if (dl->has_chain) {
-   list_for_each_entry(dl_child, >chain, chain)
-   __vsp1_dl_list_put(dl_child);
+   list_for_each_entry(dl_next, >chain, chain)
+   __vsp1_dl_list_put(dl_next);
}
 
dl->has_chain = false;
@@ -673,17 +673,17 @@ static void vsp1_dl_list_commit_singleshot(struct 
vsp1_dl_list *dl)
 void vsp1_dl_list_commit(struct vsp1_dl_list *dl, bool internal)
 {
struct vsp1_dl_manager *dlm = dl->dlm;
-   struct vsp1_dl_list *dl_child;
+   struct vsp1_dl_list *dl_next;
unsigned long flags;
 
if (dlm->mode == VSP1_DL_MODE_HEADER) {
/* Fill the header for the head and chained display lists. */
vsp1_dl_list_fill_header(dl, list_empty(>chain));
 
-   list_for_each_entry(dl_child, >chain, chain) {
-   bool last = list_is_last(_child->chain, >chain);
+   list_for_each_entry(dl_next, >chain, chain) {
+   bool last = list_is_last(_next->chain, >chain);
 
-   vsp1_dl_list_fill_header(dl_child, last);
+   vsp1_dl_list_fill_header(dl_next, last);
}
}
 
-- 
git-series 0.9.1


[PATCH v3 07/11] media: vsp1: Use header display lists for all WPF outputs linked to the DU

2018-05-03 Thread Kieran Bingham
Header mode display lists are now supported on all WPF outputs. To
support extended headers and auto-fld capabilities for interlaced mode
handling only header mode display lists can be used.

Disable the headerless display list configuration, and remove the dead
code.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_dl.c | 107 ++-
 1 file changed, 27 insertions(+), 80 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index 07ebadec5639..eafe93a3b4d9 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -94,7 +94,7 @@ struct vsp1_dl_body_pool {
  * struct vsp1_dl_list - Display list
  * @list: entry in the display list manager lists
  * @dlm: the display list manager
- * @header: display list header, NULL for headerless lists
+ * @header: display list header
  * @dma: DMA address for the header
  * @body0: first display list body
  * @bodies: list of extra display list bodies
@@ -118,15 +118,9 @@ struct vsp1_dl_list {
bool internal;
 };
 
-enum vsp1_dl_mode {
-   VSP1_DL_MODE_HEADER,
-   VSP1_DL_MODE_HEADERLESS,
-};
-
 /**
  * struct vsp1_dl_manager - Display List manager
  * @index: index of the related WPF
- * @mode: display list operation mode (header or headerless)
  * @singleshot: execute the display list in single-shot mode
  * @vsp1: the VSP1 device
  * @lock: protects the free, active, queued, pending and gc_bodies lists
@@ -138,7 +132,6 @@ enum vsp1_dl_mode {
  */
 struct vsp1_dl_manager {
unsigned int index;
-   enum vsp1_dl_mode mode;
bool singleshot;
struct vsp1_device *vsp1;
 
@@ -318,6 +311,7 @@ void vsp1_dl_body_write(struct vsp1_dl_body *dlb, u32 reg, 
u32 data)
 static struct vsp1_dl_list *vsp1_dl_list_alloc(struct vsp1_dl_manager *dlm)
 {
struct vsp1_dl_list *dl;
+   size_t header_offset;
 
dl = kzalloc(sizeof(*dl), GFP_KERNEL);
if (!dl)
@@ -330,16 +324,15 @@ static struct vsp1_dl_list *vsp1_dl_list_alloc(struct 
vsp1_dl_manager *dlm)
dl->body0 = vsp1_dl_body_get(dlm->pool);
if (!dl->body0)
return NULL;
-   if (dlm->mode == VSP1_DL_MODE_HEADER) {
-   size_t header_offset = dl->body0->max_entries
-* sizeof(*dl->body0->entries);
 
-   dl->header = ((void *)dl->body0->entries) + header_offset;
-   dl->dma = dl->body0->dma + header_offset;
+   header_offset = dl->body0->max_entries
+* sizeof(*dl->body0->entries);
 
-   memset(dl->header, 0, sizeof(*dl->header));
-   dl->header->lists[0].addr = dl->body0->dma;
-   }
+   dl->header = ((void *)dl->body0->entries) + header_offset;
+   dl->dma = dl->body0->dma + header_offset;
+
+   memset(dl->header, 0, sizeof(*dl->header));
+   dl->header->lists[0].addr = dl->body0->dma;
 
return dl;
 }
@@ -471,16 +464,9 @@ struct vsp1_dl_body *vsp1_dl_list_get_body0(struct 
vsp1_dl_list *dl)
  *
  * The reference must be explicitly released by a call to vsp1_dl_body_put()
  * when the body isn't needed anymore.
- *
- * Additional bodies are only usable for display lists in header mode.
- * Attempting to add a body to a header-less display list will return an error.
  */
 int vsp1_dl_list_add_body(struct vsp1_dl_list *dl, struct vsp1_dl_body *dlb)
 {
-   /* Multi-body lists are only available in header mode. */
-   if (dl->dlm->mode != VSP1_DL_MODE_HEADER)
-   return -EINVAL;
-
refcount_inc(>refcnt);
 
list_add_tail(>list, >bodies);
@@ -501,17 +487,10 @@ int vsp1_dl_list_add_body(struct vsp1_dl_list *dl, struct 
vsp1_dl_body *dlb)
  * Adding a display list to a chain passes ownership of the display list to
  * the head display list item. The chain is released when the head dl item is
  * put back with __vsp1_dl_list_put().
- *
- * Chained display lists are only usable in header mode. Attempts to add a
- * display list to a chain in header-less mode will return an error.
  */
 int vsp1_dl_list_add_chain(struct vsp1_dl_list *head,
   struct vsp1_dl_list *dl)
 {
-   /* Chained lists are only available in header mode. */
-   if (head->dlm->mode != VSP1_DL_MODE_HEADER)
-   return -EINVAL;
-
head->has_chain = true;
list_add_tail(>chain, >chain);
return 0;
@@ -579,17 +558,10 @@ static bool vsp1_dl_list_hw_update_pending(struct 
vsp1_dl_manager *dlm)
return false;
 
/*
-* Check whether the VSP1 has taken the update. In headerless mode the
-* hardware indicates this by clearing the UPD bit in the DL_BODY_SIZE
-* register, and 

[PATCH v3 02/11] media: vsp1: Remove packed attributes from aligned structures

2018-05-03 Thread Kieran Bingham
The use of the packed attribute can cause a performance penalty for
all accesses to the struct members, as the compiler will assume that the
structure has the potential to have an unaligned base.

These structures are all correctly aligned and contain no holes, thus
the attribute is redundant and negatively impacts performance, so we
remove the attributes entirely.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
v2
 - Remove attributes entirely

 drivers/media/platform/vsp1/vsp1_dl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index ce6cb210adcd..b6288ead24ae 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -25,19 +25,19 @@
 struct vsp1_dl_header_list {
u32 num_bytes;
u32 addr;
-} __attribute__((__packed__));
+};
 
 struct vsp1_dl_header {
u32 num_lists;
struct vsp1_dl_header_list lists[8];
u32 next_header;
u32 flags;
-} __attribute__((__packed__));
+};
 
 struct vsp1_dl_entry {
u32 addr;
u32 data;
-} __attribute__((__packed__));
+};
 
 /**
  * struct vsp1_dl_body - Display list body
-- 
git-series 0.9.1


[PATCH v3 05/11] media: vsp1: Clean up DLM objects on error

2018-05-03 Thread Kieran Bingham
If there is an error allocating a display list within a DLM object
the existing display lists are not free'd, and neither is the DL body
pool.

Use the existing vsp1_dlm_destroy() function to clean up on error.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_dl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index 459da9f2c906..07ebadec5639 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -851,8 +851,10 @@ struct vsp1_dl_manager *vsp1_dlm_create(struct vsp1_device 
*vsp1,
struct vsp1_dl_list *dl;
 
dl = vsp1_dl_list_alloc(dlm);
-   if (!dl)
+   if (!dl) {
+   vsp1_dlm_destroy(dlm);
return NULL;
+   }
 
list_add_tail(>list, >free);
}
-- 
git-series 0.9.1


[PATCH v3 09/11] media: vsp1: Provide support for extended command pools

2018-05-03 Thread Kieran Bingham
VSPD and VSP-DL devices can provide extended display lists supporting
extended command display list objects.

These extended commands require their own dma memory areas for a header
and body specific to the command type.

Implement a command pool to allocate all necessary memory in a single
DMA allocation to reduce pressure on the TLB, and provide convenient
re-usable command objects for the entities to utilise.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

---

v2:
 - Fix spelling typo in commit message
 - constify, and staticify the instantiation of vsp1_extended_commands
 - s/autfld_cmds/autofld_cmds/
 - staticify cmd pool functions (Thanks kbuild-bot)

 drivers/media/platform/vsp1/vsp1_dl.c | 191 +++-
 drivers/media/platform/vsp1/vsp1_dl.h |   3 +-
 2 files changed, 194 insertions(+)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index 82556f0f0a9a..6366a1fc92b9 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -117,6 +117,30 @@ struct vsp1_dl_body_pool {
 };
 
 /**
+ * struct vsp1_cmd_pool - display list body pool
+ * @dma: DMA address of the entries
+ * @size: size of the full DMA memory pool in bytes
+ * @mem: CPU memory pointer for the pool
+ * @bodies: Array of DLB structures for the pool
+ * @free: List of free DLB entries
+ * @lock: Protects the pool and free list
+ * @vsp1: the VSP1 device
+ */
+struct vsp1_dl_cmd_pool {
+   /* DMA allocation */
+   dma_addr_t dma;
+   size_t size;
+   void *mem;
+
+   struct vsp1_dl_ext_cmd *cmds;
+   struct list_head free;
+
+   spinlock_t lock;
+
+   struct vsp1_device *vsp1;
+};
+
+/**
  * struct vsp1_dl_list - Display list
  * @list: entry in the display list manager lists
  * @dlm: the display list manager
@@ -162,6 +186,7 @@ struct vsp1_dl_list {
  * @queued: list queued to the hardware (written to the DL registers)
  * @pending: list waiting to be queued to the hardware
  * @pool: body pool for the display list bodies
+ * @autofld_cmds: command pool to support auto-fld interlaced mode
  */
 struct vsp1_dl_manager {
unsigned int index;
@@ -175,6 +200,7 @@ struct vsp1_dl_manager {
struct vsp1_dl_list *pending;
 
struct vsp1_dl_body_pool *pool;
+   struct vsp1_dl_cmd_pool *autofld_cmds;
 };
 
 /* 
-
@@ -338,6 +364,140 @@ void vsp1_dl_body_write(struct vsp1_dl_body *dlb, u32 
reg, u32 data)
 }
 
 /* 
-
+ * Display List Extended Command Management
+ */
+
+enum vsp1_extcmd_type {
+   VSP1_EXTCMD_AUTODISP,
+   VSP1_EXTCMD_AUTOFLD,
+};
+
+struct vsp1_extended_command_info {
+   u16 opcode;
+   size_t body_size;
+} static const vsp1_extended_commands[] = {
+   [VSP1_EXTCMD_AUTODISP] = { 0x02, 96 },
+   [VSP1_EXTCMD_AUTOFLD]  = { 0x03, 160 },
+};
+
+/**
+ * vsp1_dl_cmd_pool_create - Create a pool of commands from a single allocation
+ * @vsp1: The VSP1 device
+ * @type: The command pool type
+ * @num_commands: The quantity of commands to allocate
+ *
+ * Allocate a pool of commands each with enough memory to contain the private
+ * data of each command. The allocation sizes are dependent upon the command
+ * type.
+ *
+ * Return a pointer to a pool on success or NULL if memory can't be allocated.
+ */
+static struct vsp1_dl_cmd_pool *
+vsp1_dl_cmd_pool_create(struct vsp1_device *vsp1, enum vsp1_extcmd_type type,
+   unsigned int num_cmds)
+{
+   struct vsp1_dl_cmd_pool *pool;
+   unsigned int i;
+   size_t cmd_size;
+
+   pool = kzalloc(sizeof(*pool), GFP_KERNEL);
+   if (!pool)
+   return NULL;
+
+   pool->cmds = kcalloc(num_cmds, sizeof(*pool->cmds), GFP_KERNEL);
+   if (!pool->cmds) {
+   kfree(pool);
+   return NULL;
+   }
+
+   cmd_size = sizeof(struct vsp1_dl_ext_cmd_header) +
+  vsp1_extended_commands[type].body_size;
+   cmd_size = ALIGN(cmd_size, 16);
+
+   pool->size = cmd_size * num_cmds;
+   pool->mem = dma_alloc_wc(vsp1->bus_master, pool->size, >dma,
+GFP_KERNEL);
+   if (!pool->mem) {
+   kfree(pool->cmds);
+   kfree(pool);
+   return NULL;
+   }
+
+   spin_lock_init(>lock);
+   INIT_LIST_HEAD(>free);
+
+   for (i = 0; i < num_cmds; ++i) {
+   struct vsp1_dl_ext_cmd *cmd = >cmds[i];
+   size_t cmd_offset = i * cmd_size;
+   size_t data_offset = sizeof(struct vsp1_dl_ext_cmd_header) +
+cmd_offset;
+
+   cmd->pool = pool;
+   cmd->cmd_opcode = vsp1_extended_commands[type].opcode;
+
+   /* TOD

[PATCH v3 04/11] media: vsp1: Remove unused display list structure field

2018-05-03 Thread Kieran Bingham
The vsp1 reference in the vsp1_dl_body structure is not used.
Remove it.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_dl.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index 09c29a4ed118..459da9f2c906 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -44,7 +44,6 @@ struct vsp1_dl_entry {
  * @list: entry in the display list list of bodies
  * @free: entry in the pool free body list
  * @pool: pool to which this body belongs
- * @vsp1: the VSP1 device
  * @entries: array of entries
  * @dma: DMA address of the entries
  * @size: size of the DMA memory in bytes
@@ -58,7 +57,6 @@ struct vsp1_dl_body {
refcount_t refcnt;
 
struct vsp1_dl_body_pool *pool;
-   struct vsp1_device *vsp1;
 
struct vsp1_dl_entry *entries;
dma_addr_t dma;
-- 
git-series 0.9.1


[PATCH v3 01/11] media: vsp1: drm: Fix minor grammar error

2018-05-03 Thread Kieran Bingham
The pixel format is 'unsupported'. Fix the small debug message which
incorrectly declares this.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_drm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/vsp1/vsp1_drm.c 
b/drivers/media/platform/vsp1/vsp1_drm.c
index ed612f84e5f1..7714be7f50af 100644
--- a/drivers/media/platform/vsp1/vsp1_drm.c
+++ b/drivers/media/platform/vsp1/vsp1_drm.c
@@ -806,7 +806,7 @@ int vsp1_du_atomic_update(struct device *dev, unsigned int 
pipe_index,
 */
fmtinfo = vsp1_get_format_info(vsp1, cfg->pixelformat);
if (!fmtinfo) {
-   dev_dbg(vsp1->dev, "Unsupport pixel format %08x for RPF\n",
+   dev_dbg(vsp1->dev, "Unsupported pixel format %08x for RPF\n",
cfg->pixelformat);
return -EINVAL;
}
-- 
git-series 0.9.1


[PATCH v3 00/11] R-Car DU Interlaced support through VSP1

2018-05-03 Thread Kieran Bingham
The Gen3 R-Car DU devices make use of the VSP to handle frame processing.

In this series we implement support for handling interlaced pipelines by using
the auto-fld feature of the VSP hardware.

The implementation is preceded by some cleanup work and refactoring, through
patches 1 to 6. These are trivial and could be collected earlier and
independently if this series requires further revisions.

Patch 7 makes a key distinctive change to remove all existing support for
headerless display lists throughout the VSP1 driver, and ensures that all
pipelines use the same code path. This simplifies the code and reduces
opportunity for untested code paths to exist.

Patches 8, 9 and 10 implement the relevant support in the VSP1 driver, before
patch 11 finally enables the feature through the drm R-Car DU driver.

This series is based upon my previous TLB optimise and body rework (v8), and is
available from the following URL:

  git://git.kernel.org/pub/scm/linux/kernel/git/kbingham/rcar.git
  tags/vsp1/du/interlaced/v8

ChangeLog:

v3:
 - Rebased on top of TLB Optimise rework v8
 - Added the DL parameter back into the configure_partition() calls.
   - This change could be moved into the TLB-Optimise series.
 - Document interlaced field in struct vsp1_du_atomic_config

v2:
 - media: vsp1: use kernel __packed for structures
became:
   media: vsp1: Remove packed attributes from aligned structures

 - media: vsp1: Add support for extended display list headers
   - No longer declares structs __packed

 - media: vsp1: Provide support for extended command pools
   - Fix spelling typo in commit message
   - constify, and staticify the instantiation of vsp1_extended_commands
   - s/autfld_cmds/autofld_cmds/
   - staticify cmd pool functions (Thanks kbuild-bot)

 - media: vsp1: Support Interlaced display pipelines
   - fix erroneous BIT value which enabled interlaced
   - fix field handling at frame_end interrupt

Kieran Bingham (11):
  media: vsp1: drm: Fix minor grammar error
  media: vsp1: Remove packed attributes from aligned structures
  media: vsp1: Rename dl_child to dl_next
  media: vsp1: Remove unused display list structure field
  media: vsp1: Clean up DLM objects on error
  media: vsp1: Provide VSP1 feature helper macro
  media: vsp1: Use header display lists for all WPF outputs linked to the DU
  media: vsp1: Add support for extended display list headers
  media: vsp1: Provide support for extended command pools
  media: vsp1: Support Interlaced display pipelines
  drm: rcar-du: Support interlaced video output through vsp1

 drivers/gpu/drm/rcar-du/rcar_du_crtc.c|   1 +-
 drivers/gpu/drm/rcar-du/rcar_du_vsp.c |   3 +-
 drivers/media/platform/vsp1/vsp1.h|   3 +-
 drivers/media/platform/vsp1/vsp1_dl.c | 407 +--
 drivers/media/platform/vsp1/vsp1_dl.h |  32 +-
 drivers/media/platform/vsp1/vsp1_drm.c|  15 +-
 drivers/media/platform/vsp1/vsp1_drv.c|  23 +-
 drivers/media/platform/vsp1/vsp1_entity.c |   3 +-
 drivers/media/platform/vsp1/vsp1_entity.h |   2 +-
 drivers/media/platform/vsp1/vsp1_regs.h   |   6 +-
 drivers/media/platform/vsp1/vsp1_rpf.c|  73 +++-
 drivers/media/platform/vsp1/vsp1_rwpf.h   |   1 +-
 drivers/media/platform/vsp1/vsp1_uds.c|   1 +-
 drivers/media/platform/vsp1/vsp1_video.c  |   2 +-
 drivers/media/platform/vsp1/vsp1_wpf.c|   7 +-
 include/media/vsp1.h  |   2 +-
 16 files changed, 466 insertions(+), 115 deletions(-)

base-commit: c482f86329d5dcca0021e341ff8a80f7a1e99e96
-- 
git-series 0.9.1


[PATCH v3 11/11] drm: rcar-du: Support interlaced video output through vsp1

2018-05-03 Thread Kieran Bingham
Use the newly exposed VSP1 interface to enable interlaced frame support
through the VSP1 lif pipelines.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
 drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 1 +
 drivers/gpu/drm/rcar-du/rcar_du_vsp.c  | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c 
b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
index d71d709fe3d9..206532959ec9 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
@@ -289,6 +289,7 @@ static void rcar_du_crtc_set_display_timing(struct 
rcar_du_crtc *rcrtc)
/* Signal polarities */
value = ((mode->flags & DRM_MODE_FLAG_PVSYNC) ? DSMR_VSL : 0)
  | ((mode->flags & DRM_MODE_FLAG_PHSYNC) ? DSMR_HSL : 0)
+ | ((mode->flags & DRM_MODE_FLAG_INTERLACE) ? DSMR_ODEV : 0)
  | DSMR_DIPM_DISP | DSMR_CSPM;
rcar_du_crtc_write(rcrtc, DSMR, value);
 
diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c 
b/drivers/gpu/drm/rcar-du/rcar_du_vsp.c
index af7822a66dee..c7b37232ee91 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_vsp.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_vsp.c
@@ -186,6 +186,9 @@ static void rcar_du_vsp_plane_setup(struct 
rcar_du_vsp_plane *plane)
};
unsigned int i;
 
+   cfg.interlaced = !!(plane->plane.state->crtc->mode.flags
+   & DRM_MODE_FLAG_INTERLACE);
+
cfg.src.left = state->state.src.x1 >> 16;
cfg.src.top = state->state.src.y1 >> 16;
cfg.src.width = drm_rect_width(>state.src) >> 16;
-- 
git-series 0.9.1


[PATCH v3 06/11] media: vsp1: Provide VSP1 feature helper macro

2018-05-03 Thread Kieran Bingham
The VSP1 devices define their specific capabilities through features
marked in their device info structure. Various parts of the code read
this info structure to infer if the features are available.

Wrap this into a more readable vsp1_feature(vsp1, f) macro to ensure
that usage is consistent throughout the driver.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1.h |  2 ++
 drivers/media/platform/vsp1/vsp1_drv.c | 16 
 drivers/media/platform/vsp1/vsp1_wpf.c |  6 +++---
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1.h 
b/drivers/media/platform/vsp1/vsp1.h
index 33f632331474..f0d21cc8e9ab 100644
--- a/drivers/media/platform/vsp1/vsp1.h
+++ b/drivers/media/platform/vsp1/vsp1.h
@@ -68,6 +68,8 @@ struct vsp1_device_info {
bool uapi;
 };
 
+#define vsp1_feature(vsp1, f) ((vsp1)->info->features & (f))
+
 struct vsp1_device {
struct device *dev;
const struct vsp1_device_info *info;
diff --git a/drivers/media/platform/vsp1/vsp1_drv.c 
b/drivers/media/platform/vsp1/vsp1_drv.c
index d29f9c4baebe..0fc388bf5a33 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -265,7 +265,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
}
 
/* Instantiate all the entities. */
-   if (vsp1->info->features & VSP1_HAS_BRS) {
+   if (vsp1_feature(vsp1, VSP1_HAS_BRS)) {
vsp1->brs = vsp1_brx_create(vsp1, VSP1_ENTITY_BRS);
if (IS_ERR(vsp1->brs)) {
ret = PTR_ERR(vsp1->brs);
@@ -275,7 +275,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
list_add_tail(>brs->entity.list_dev, >entities);
}
 
-   if (vsp1->info->features & VSP1_HAS_BRU) {
+   if (vsp1_feature(vsp1, VSP1_HAS_BRU)) {
vsp1->bru = vsp1_brx_create(vsp1, VSP1_ENTITY_BRU);
if (IS_ERR(vsp1->bru)) {
ret = PTR_ERR(vsp1->bru);
@@ -285,7 +285,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
list_add_tail(>bru->entity.list_dev, >entities);
}
 
-   if (vsp1->info->features & VSP1_HAS_CLU) {
+   if (vsp1_feature(vsp1, VSP1_HAS_CLU)) {
vsp1->clu = vsp1_clu_create(vsp1);
if (IS_ERR(vsp1->clu)) {
ret = PTR_ERR(vsp1->clu);
@@ -311,7 +311,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
 
list_add_tail(>hst->entity.list_dev, >entities);
 
-   if (vsp1->info->features & VSP1_HAS_HGO && vsp1->info->uapi) {
+   if (vsp1_feature(vsp1, VSP1_HAS_HGO) && vsp1->info->uapi) {
vsp1->hgo = vsp1_hgo_create(vsp1);
if (IS_ERR(vsp1->hgo)) {
ret = PTR_ERR(vsp1->hgo);
@@ -322,7 +322,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
  >entities);
}
 
-   if (vsp1->info->features & VSP1_HAS_HGT && vsp1->info->uapi) {
+   if (vsp1_feature(vsp1, VSP1_HAS_HGT) && vsp1->info->uapi) {
vsp1->hgt = vsp1_hgt_create(vsp1);
if (IS_ERR(vsp1->hgt)) {
ret = PTR_ERR(vsp1->hgt);
@@ -353,7 +353,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
}
}
 
-   if (vsp1->info->features & VSP1_HAS_LUT) {
+   if (vsp1_feature(vsp1, VSP1_HAS_LUT)) {
vsp1->lut = vsp1_lut_create(vsp1);
if (IS_ERR(vsp1->lut)) {
ret = PTR_ERR(vsp1->lut);
@@ -387,7 +387,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
}
}
 
-   if (vsp1->info->features & VSP1_HAS_SRU) {
+   if (vsp1_feature(vsp1, VSP1_HAS_SRU)) {
vsp1->sru = vsp1_sru_create(vsp1);
if (IS_ERR(vsp1->sru)) {
ret = PTR_ERR(vsp1->sru);
@@ -537,7 +537,7 @@ static int vsp1_device_init(struct vsp1_device *vsp1)
vsp1_write(vsp1, VI6_DPR_HSI_ROUTE, VI6_DPR_NODE_UNUSED);
vsp1_write(vsp1, VI6_DPR_BRU_ROUTE, VI6_DPR_NODE_UNUSED);
 
-   if (vsp1->info->features & VSP1_HAS_BRS)
+   if (vsp1_feature(vsp1, VSP1_HAS_BRS))
vsp1_write(vsp1, VI6_DPR_ILV_BRS_ROUTE, VI6_DPR_NODE_UNUSED);
 
vsp1_write(vsp1, VI6_DPR_HGO_SMPPT, (7 << VI6_DPR_SMPPT_TGW_SHIFT) |
diff --git a/drivers/media/platform/vsp1/vsp1_wpf.c 
b/drivers/media/platform/vsp1/vsp1_wpf.c
index 80b4f8ba141e..b61d05aaadf2 100644
--- a/drivers/media/platform/vsp1/vsp1_wpf.c
+++ b/drivers/media/platform/vsp1/vsp1_wpf.c
@@ -141,13 +141,13 @@ static int wpf_init_contro

[PATCH v3 08/11] media: vsp1: Add support for extended display list headers

2018-05-03 Thread Kieran Bingham
Extended display list headers allow pre and post command lists to be
executed by the VSP pipeline. This provides the base support for
features such as AUTO_FLD (for interlaced support) and AUTO_DISP (for
supporting continuous camera preview pipelines.

Signed-off-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

---

v2:
 - remove __packed attributes

 drivers/media/platform/vsp1/vsp1.h  |  1 +-
 drivers/media/platform/vsp1/vsp1_dl.c   | 83 +-
 drivers/media/platform/vsp1/vsp1_dl.h   | 29 -
 drivers/media/platform/vsp1/vsp1_drv.c  |  7 +-
 drivers/media/platform/vsp1/vsp1_regs.h |  5 +-
 5 files changed, 116 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1.h 
b/drivers/media/platform/vsp1/vsp1.h
index f0d21cc8e9ab..56c62122a81a 100644
--- a/drivers/media/platform/vsp1/vsp1.h
+++ b/drivers/media/platform/vsp1/vsp1.h
@@ -53,6 +53,7 @@ struct vsp1_uif;
 #define VSP1_HAS_HGO   (1 << 7)
 #define VSP1_HAS_HGT   (1 << 8)
 #define VSP1_HAS_BRS   (1 << 9)
+#define VSP1_HAS_EXT_DL(1 << 10)
 
 struct vsp1_device_info {
u32 version;
diff --git a/drivers/media/platform/vsp1/vsp1_dl.c 
b/drivers/media/platform/vsp1/vsp1_dl.c
index eafe93a3b4d9..82556f0f0a9a 100644
--- a/drivers/media/platform/vsp1/vsp1_dl.c
+++ b/drivers/media/platform/vsp1/vsp1_dl.c
@@ -22,6 +22,9 @@
 #define VSP1_DLH_INT_ENABLE(1 << 1)
 #define VSP1_DLH_AUTO_START(1 << 0)
 
+#define VSP1_DLH_EXT_PRE_CMD_EXEC  (1 << 9)
+#define VSP1_DLH_EXT_POST_CMD_EXEC (1 << 8)
+
 struct vsp1_dl_header_list {
u32 num_bytes;
u32 addr;
@@ -34,11 +37,34 @@ struct vsp1_dl_header {
u32 flags;
 };
 
+struct vsp1_dl_ext_header {
+   u32 reserved0;  /* alignment padding */
+
+   u16 pre_ext_cmd_qty;
+   u16 flags;
+   u32 pre_ext_cmd_plist;
+
+   u32 post_ext_cmd_qty;
+   u32 post_ext_cmd_plist;
+};
+
+struct vsp1_dl_header_extended {
+   struct vsp1_dl_header header;
+   struct vsp1_dl_ext_header ext;
+};
+
 struct vsp1_dl_entry {
u32 addr;
u32 data;
 };
 
+struct vsp1_dl_ext_cmd_header {
+   u32 cmd;
+   u32 flags;
+   u32 data;
+   u32 reserved;
+};
+
 /**
  * struct vsp1_dl_body - Display list body
  * @list: entry in the display list list of bodies
@@ -95,9 +121,12 @@ struct vsp1_dl_body_pool {
  * @list: entry in the display list manager lists
  * @dlm: the display list manager
  * @header: display list header
+ * @extended: extended display list header. NULL for normal lists
  * @dma: DMA address for the header
  * @body0: first display list body
  * @bodies: list of extra display list bodies
+ * @pre_cmd: pre cmd to be issued through extended dl header
+ * @post_cmd: post cmd to be issued through extended dl header
  * @has_chain: if true, indicates that there's a partition chain
  * @chain: entry in the display list partition chain
  * @internal: whether the display list is used for internal purpose
@@ -107,11 +136,15 @@ struct vsp1_dl_list {
struct vsp1_dl_manager *dlm;
 
struct vsp1_dl_header *header;
+   struct vsp1_dl_ext_header *extended;
dma_addr_t dma;
 
struct vsp1_dl_body *body0;
struct list_head bodies;
 
+   struct vsp1_dl_ext_cmd *pre_cmd;
+   struct vsp1_dl_ext_cmd *post_cmd;
+
bool has_chain;
struct list_head chain;
 
@@ -496,6 +529,14 @@ int vsp1_dl_list_add_chain(struct vsp1_dl_list *head,
return 0;
 }
 
+static void vsp1_dl_ext_cmd_fill_header(struct vsp1_dl_ext_cmd *cmd)
+{
+   cmd->cmds[0].cmd = cmd->cmd_opcode;
+   cmd->cmds[0].flags = cmd->flags;
+   cmd->cmds[0].data = cmd->data_dma;
+   cmd->cmds[0].reserved = 0;
+}
+
 static void vsp1_dl_list_fill_header(struct vsp1_dl_list *dl, bool is_last)
 {
struct vsp1_dl_manager *dlm = dl->dlm;
@@ -548,6 +589,27 @@ static void vsp1_dl_list_fill_header(struct vsp1_dl_list 
*dl, bool is_last)
 */
dl->header->flags = VSP1_DLH_INT_ENABLE;
}
+
+   if (!dl->extended)
+   return;
+
+   dl->extended->flags = 0;
+
+   if (dl->pre_cmd) {
+   dl->extended->pre_ext_cmd_plist = dl->pre_cmd->cmd_dma;
+   dl->extended->pre_ext_cmd_qty = dl->pre_cmd->num_cmds;
+   dl->extended->flags |= VSP1_DLH_EXT_PRE_CMD_EXEC;
+
+   vsp1_dl_ext_cmd_fill_header(dl->pre_cmd);
+   }
+
+   if (dl->post_cmd) {
+   dl->extended->pre_ext_cmd_plist = dl->post_cmd->cmd_dma;
+   dl->extended->pre_ext_cmd_qty = dl->post_cmd->num_cmds;
+   dl->extended->flags |= VSP1_DLH_EXT_POST_CMD_EXEC;
+
+   vsp1_dl_ext_cmd_fill_header(dl->pre_cmd);
+   }
 }
 
 static bool vsp1_d

Re: [PATCH v3 0/5] drm: rcar-du: r8a77965 DU support

2018-05-02 Thread Kieran Bingham
Hi Geert

On 02/05/18 09:59, Geert Uytterhoeven wrote:
> Hi Laurent,
> 
> On Sat, Apr 28, 2018 at 12:43 AM, Laurent Pinchart
> <laurent.pinch...@ideasonboard.com> wrote:
>> On Saturday, 28 April 2018 01:21:49 EEST Kieran Bingham wrote:
>>> The r8a77965 M3-N platform supports a DPAD, HDMI and LVDS output, along
>>> 3 DU channels. However, DU2 is not available in the hardware, with the
>>> DPAD instead being routed through DU3.
>>>
>>> Provide support for this non-linear indexing with updates to the rcar-du
>>> driver, before adding the device info structure for the r8a77965.
>>>
>>>
>>> Kieran Bingham (5):
>>>   dt-bindings: display: renesas: Add R-Car M3-N HDMI TX DT bindings
>>>   pinctrl: sh-pfc: r8a77965: Add DU RGB output pins, groups and
>>> functions
>>>   drm: rcar-du: Split CRTC handling to support hardware indexing
>>>   drm: rcar-du: Allow DU groups to work with hardware indexing
>>>   drm: rcar-du: Add R8A77965 support
>>
>> I've taken the whole series in my tree for v4.18.
> 
> Shouldn't patch #2 go through sh-pfc?

Yes :-)

Sorry, It looks like I should have split it out from the series.

--
Kieran


> Gr{oetje,eeting}s,
> 
> Geert
> 


Re: [PATCH 3/3] v4l: rcar_fdp1: Fix indentation oddities

2018-05-01 Thread Kieran Bingham
Hi Laurent,

Thanks for the fixes.

On 22/04/18 11:28, Laurent Pinchart wrote:
> Indentation is odd in several places, especially when printing messages
> to the kernel log. Fix it to match the usual coding style.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart+rene...@ideasonboard.com>

Reviewed-by: Kieran Bingham <kieran.bingham+rene...@ideasonboard.com>

> ---
>  drivers/media/platform/rcar_fdp1.c | 28 ++--
>  1 file changed, 14 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/media/platform/rcar_fdp1.c 
> b/drivers/media/platform/rcar_fdp1.c
> index b13dec3081e5..81e8a761b924 100644
> --- a/drivers/media/platform/rcar_fdp1.c
> +++ b/drivers/media/platform/rcar_fdp1.c
> @@ -949,7 +949,7 @@ static void fdp1_configure_wpf(struct fdp1_ctx *ctx,
>   u32 rndctl;
>  
>   pstride = q_data->format.plane_fmt[0].bytesperline
> - << FD1_WPF_PSTRIDE_Y_SHIFT;
> + << FD1_WPF_PSTRIDE_Y_SHIFT;
>  
>   if (q_data->format.num_planes > 1)
>   pstride |= q_data->format.plane_fmt[1].bytesperline
> @@ -1143,8 +1143,8 @@ static int fdp1_m2m_job_ready(void *priv)
>   int dstbufs = 1;
>  
>   dprintk(ctx->fdp1, "+ Src: %d : Dst: %d\n",
> - v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx),
> - v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx));
> + v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx),
> + v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx));
>  
>   /* One output buffer is required for each field */
>   if (V4L2_FIELD_HAS_BOTH(src_q_data->format.field))
> @@ -1282,7 +1282,7 @@ static void fdp1_m2m_device_run(void *priv)
>  
>   fdp1_queue_field(ctx, fbuf);
>   dprintk(fdp1, "Queued Buffer [%d] last_field:%d\n",
> - i, fbuf->last_field);
> + i, fbuf->last_field);
>   }
>  
>   /* Queue as many jobs as our data provides for */
> @@ -1341,7 +1341,7 @@ static void device_frame_end(struct fdp1_dev *fdp1,
>   fdp1_job_free(fdp1, job);
>  
>   dprintk(fdp1, "curr_ctx->num_processed %d curr_ctx->translen %d\n",
> - ctx->num_processed, ctx->translen);
> + ctx->num_processed, ctx->translen);
>  
>   if (ctx->num_processed == ctx->translen ||
>   ctx->aborting) {
> @@ -1366,7 +1366,7 @@ static int fdp1_vidioc_querycap(struct file *file, void 
> *priv,
>   strlcpy(cap->driver, DRIVER_NAME, sizeof(cap->driver));
>   strlcpy(cap->card, DRIVER_NAME, sizeof(cap->card));
>   snprintf(cap->bus_info, sizeof(cap->bus_info),
> - "platform:%s", DRIVER_NAME);
> +  "platform:%s", DRIVER_NAME);
>   return 0;
>  }
>  
> @@ -1997,13 +1997,13 @@ static void fdp1_stop_streaming(struct vb2_queue *q)
>   /* Free smsk_data */
>   if (ctx->smsk_cpu) {
>   dma_free_coherent(ctx->fdp1->dev, ctx->smsk_size,
> - ctx->smsk_cpu, ctx->smsk_addr[0]);
> +   ctx->smsk_cpu, ctx->smsk_addr[0]);
>   ctx->smsk_addr[0] = ctx->smsk_addr[1] = 0;
>   ctx->smsk_cpu = NULL;
>   }
>  
>   WARN(!list_empty(>fields_queue),
> - "Buffer queue not empty");
> +  "Buffer queue not empty");
>   } else {
>   /* Empty Capture queues (Jobs) */
>   struct fdp1_job *job;
> @@ -2025,10 +2025,10 @@ static void fdp1_stop_streaming(struct vb2_queue *q)
>   fdp1_field_complete(ctx, ctx->previous);
>  
>   WARN(!list_empty(>fdp1->queued_job_list),
> - "Queued Job List not empty");
> +  "Queued Job List not empty");
>  
>   WARN(!list_empty(>fdp1->hw_job_list),
> - "HW Job list not empty");
> +  "HW Job list not empty");
>   }
>  }
>  
> @@ -2114,7 +2114,7 @@ static int fdp1_open(struct file *file)
>fdp1_ctrl_deint_menu);
>  
>   ctrl = v4l2_ctrl_new_std(>hdl, _ctrl_ops,
> - V4L2_CID_MIN_BUFFERS_FOR_CAPTURE, 1, 2, 1, 1);
> +  V4L2_CID_MIN_BUFFERS_FOR_CAPTURE, 1, 2, 1, 1);
>   if (ctrl)
>   ctrl->flags |= V4L2_CTRL_FL

  1   2   3   4   5   6   7   8   9   >