Re: [PATCH] drm: rcar-du: Drop leftovers variables from Makefile

2022-08-28 Thread Geert Uytterhoeven
On Sat, Aug 27, 2022 at 2:50 AM Laurent Pinchart
 wrote:
> Commit 841281fe52a7 ("drm: rcar-du: Drop LVDS device tree backward
> compatibility") has removed device tree overlay sources used for
> backward compatibility with old bindings, but forgot to remove related
> variables from the Makefile. Fix it.
>
> Fixes: 841281fe52a7 ("drm: rcar-du: Drop LVDS device tree backward 
> compatibility")
> Signed-off-by: Laurent Pinchart 

Reviewed-by: Geert Uytterhoeven 

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


Re: [PTACH v3] drm/ast: add dmabuf/prime buffer sharing support

2022-08-28 Thread Christian König

Am 27.08.22 um 11:10 schrieb oushixiong:

This patch adds ast specific codes for DRM prime feature, this is to
allow for offloading of rending in one direction and outputs in other.

This patch is designed to solve the problem that the AST is not displayed
when the server plug in a discrete graphics graphics card at the same time.
We call the dirty callback function to copy the rendering results of the
discrete graphics card to the ast side by dma-buf.

v1->v2:
   - Fix the comment.
v2->v3:
   - we remove the gem_prime_import_sg_table callback and use the 
gem_prime_import
 callback, becuase it just map and access the buffer with the CPU. and do 
not
 to pin the buffer.

Signed-off-by: oushixiong 


Thomas should probably comment as well, I think at least the memcpy_toio 
usage can still be made cleaner.


But from the DMA-buf side I think that looks good now, feel free to add 
an Acked-by: Christian König 


Regards,
Christian.


---
  drivers/gpu/drm/ast/ast_drv.c  |  27 +++
  drivers/gpu/drm/ast/ast_mode.c | 125 -
  2 files changed, 151 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/ast/ast_drv.c b/drivers/gpu/drm/ast/ast_drv.c
index 7465c4f0156a..107383a56ca7 100644
--- a/drivers/gpu/drm/ast/ast_drv.c
+++ b/drivers/gpu/drm/ast/ast_drv.c
@@ -28,6 +28,7 @@
  
  #include 

  #include 
+#include 
  
  #include 

  #include 
@@ -50,6 +51,29 @@ module_param_named(modeset, ast_modeset, int, 0400);
  
  DEFINE_DRM_GEM_FOPS(ast_fops);
  
+struct drm_gem_object *ast_gem_prime_import(struct drm_device *dev,

+   struct dma_buf *dma_buf)
+{
+   struct drm_gem_vram_object *gbo;
+
+   gbo = drm_gem_vram_of_gem(dma_buf->priv);
+   if (gbo->bo.base.dev == dev) {
+   /*
+   * Importing dmabuf exported from out own gem increases
+   * refcount on gem itself instead of f_count of dmabuf.
+   */
+   drm_gem_object_get(&gbo->bo.base);
+   return &gbo->bo.base;
+   }
+
+   gbo = drm_gem_vram_create(dev, dma_buf->size, 0);
+   if (IS_ERR(gbo))
+   return NULL;
+
+   get_dma_buf(dma_buf);
+   return &gbo->bo.base;
+}
+
  static const struct drm_driver ast_driver = {
.driver_features = DRIVER_ATOMIC |
   DRIVER_GEM |
@@ -63,6 +87,9 @@ static const struct drm_driver ast_driver = {
.minor = DRIVER_MINOR,
.patchlevel = DRIVER_PATCHLEVEL,
  
+	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,

+   .gem_prime_import = ast_gem_prime_import,
+
DRM_GEM_VRAM_DRIVER
  };
  
diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c

index 45b56b39ad47..65a4342c5622 100644
--- a/drivers/gpu/drm/ast/ast_mode.c
+++ b/drivers/gpu/drm/ast/ast_mode.c
@@ -48,6 +48,8 @@
  #include "ast_drv.h"
  #include "ast_tables.h"
  
+MODULE_IMPORT_NS(DMA_BUF);

+
  static inline void ast_load_palette_index(struct ast_private *ast,
 u8 index, u8 red, u8 green,
 u8 blue)
@@ -1535,8 +1537,129 @@ static const struct drm_mode_config_helper_funcs 
ast_mode_config_helper_funcs =
.atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
  };
  
+static int ast_handle_damage(struct drm_framebuffer *fb, int x, int y,

+   int width, int height)
+{
+   struct drm_gem_vram_object *dst_bo = NULL;
+   void *dst = NULL;
+   int ret = 0, i;
+   unsigned long offset = 0;
+   bool unmap = false;
+   unsigned int bytesPerPixel;
+   struct iosys_map map;
+   struct iosys_map dmabuf_map;
+
+   bytesPerPixel = fb->format->cpp[0];
+
+   if (!fb->obj[0]->dma_buf)
+   return -EINVAL;
+
+   if (!fb->obj[0]->dma_buf->vmap_ptr.vaddr) {
+   ret = dma_buf_vmap(fb->obj[0]->dma_buf, &dmabuf_map);
+   if (ret)
+   return ret;
+   } else
+   dmabuf_map.vaddr = fb->obj[0]->dma_buf->vmap_ptr.vaddr;
+
+   dst_bo = drm_gem_vram_of_gem(fb->obj[0]);
+
+   ret = drm_gem_vram_pin(dst_bo, 0);
+   if (ret) {
+   DRM_ERROR("ast_bo_pin failed\n");
+   return ret;
+   }
+
+   if (!dst_bo->map.vaddr) {
+   ret = drm_gem_vram_vmap(dst_bo, &map);
+   if (ret) {
+   drm_gem_vram_unpin(dst_bo);
+   DRM_ERROR("failed to vmap fbcon\n");
+   return ret;
+   }
+   unmap = true;
+   }
+   dst = dst_bo->map.vaddr;
+
+   for (i = y; i < y + height; i++) {
+   offset = i * fb->pitches[0] + (x * bytesPerPixel);
+   memcpy_toio(dst + offset, dmabuf_map.vaddr + offset,
+   width * bytesPerPixel);
+   }
+
+   if (unmap)
+   drm_gem_vram_vunmap(dst_bo, &map);
+
+   drm_gem_vra

Re: [PATCH 4/4] vfio/pci: Allow MMIO regions to be exported through dma-buf

2022-08-28 Thread Yan Zhao
On Wed, Aug 17, 2022 at 01:11:42PM -0300, Jason Gunthorpe wrote:
> dma-buf has become a way to safely acquire a handle to non-struct page
> memory that can still have lifetime controlled by the exporter. Notably
> RDMA can now import dma-buf FDs and build them into MRs which allows for
> PCI P2P operations. Extend this to allow vfio-pci to export MMIO memory
> from PCI device BARs.
> 
> The patch design loosely follows the pattern in commit
> db1a8dd916aa ("habanalabs: add support for dma-buf exporter") except this
> does not support pinning.
> 
> Instead, this implements what, in the past, we've called a revocable
> attachment using move. In normal situations the attachment is pinned, as a
> BAR does not change physical address. However when the VFIO device is
> closed, or a PCI reset is issued, access to the MMIO memory is revoked.
> 
> Revoked means that move occurs, but an attempt to immediately re-map the
> memory will fail. In the reset case a future move will be triggered when
> MMIO access returns. As both close and reset are under userspace control
> it is expected that userspace will suspend use of the dma-buf before doing
> these operations, the revoke is purely for kernel self-defense against a
> hostile userspace.
> 
> Signed-off-by: Jason Gunthorpe 
> ---
>  drivers/vfio/pci/Makefile   |   1 +
>  drivers/vfio/pci/vfio_pci_config.c  |   8 +-
>  drivers/vfio/pci/vfio_pci_core.c|  28 ++-
>  drivers/vfio/pci/vfio_pci_dma_buf.c | 265 
>  drivers/vfio/pci/vfio_pci_priv.h|  23 +++
>  include/linux/vfio_pci_core.h   |   1 +
>  include/uapi/linux/vfio.h   |  18 ++
>  7 files changed, 336 insertions(+), 8 deletions(-)
>  create mode 100644 drivers/vfio/pci/vfio_pci_dma_buf.c
> 
> diff --git a/drivers/vfio/pci/Makefile b/drivers/vfio/pci/Makefile
> index 24c524224da5a3..81006a157cde14 100644
> --- a/drivers/vfio/pci/Makefile
> +++ b/drivers/vfio/pci/Makefile
> @@ -2,6 +2,7 @@
>  
>  vfio-pci-core-y := vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o 
> vfio_pci_config.o
>  vfio-pci-core-$(CONFIG_VFIO_PCI_ZDEV_KVM) += vfio_pci_zdev.o
> +vfio-pci-core-$(CONFIG_DMA_SHARED_BUFFER) += vfio_pci_dma_buf.o
>  obj-$(CONFIG_VFIO_PCI_CORE) += vfio-pci-core.o
>  
>  vfio-pci-y := vfio_pci.o
> diff --git a/drivers/vfio/pci/vfio_pci_config.c 
> b/drivers/vfio/pci/vfio_pci_config.c
> index d22921efa25987..f8a9c24d04aeb7 100644
> --- a/drivers/vfio/pci/vfio_pci_config.c
> +++ b/drivers/vfio/pci/vfio_pci_config.c
> @@ -584,10 +584,12 @@ static int vfio_basic_config_write(struct 
> vfio_pci_core_device *vdev, int pos,
>   virt_mem = !!(le16_to_cpu(*virt_cmd) & PCI_COMMAND_MEMORY);
>   new_mem = !!(new_cmd & PCI_COMMAND_MEMORY);
>  
> - if (!new_mem)
> + if (!new_mem) {
>   vfio_pci_zap_and_down_write_memory_lock(vdev);
> - else
> + vfio_pci_dma_buf_move(vdev, true);
> + } else {
>   down_write(&vdev->memory_lock);
> + }
>  
>   /*
>* If the user is writing mem/io enable (new_mem/io) and we
> @@ -622,6 +624,8 @@ static int vfio_basic_config_write(struct 
> vfio_pci_core_device *vdev, int pos,
>   *virt_cmd &= cpu_to_le16(~mask);
>   *virt_cmd |= cpu_to_le16(new_cmd & mask);
>  
> + if (__vfio_pci_memory_enabled(vdev))
> + vfio_pci_dma_buf_move(vdev, false);
>   up_write(&vdev->memory_lock);
>   }
>  
> diff --git a/drivers/vfio/pci/vfio_pci_core.c 
> b/drivers/vfio/pci/vfio_pci_core.c
> index d13e22021860cc..206f159c480e42 100644
> --- a/drivers/vfio/pci/vfio_pci_core.c
> +++ b/drivers/vfio/pci/vfio_pci_core.c
> @@ -504,6 +504,8 @@ void vfio_pci_core_close_device(struct vfio_device 
> *core_vdev)
>   vfio_spapr_pci_eeh_release(vdev->pdev);
>   vfio_pci_core_disable(vdev);
>  
> + vfio_pci_dma_buf_cleanup(vdev);
> +
>   mutex_lock(&vdev->igate);
>   if (vdev->err_trigger) {
>   eventfd_ctx_put(vdev->err_trigger);
> @@ -980,7 +982,10 @@ int vfio_pci_try_reset_function(struct 
> vfio_pci_core_device *vdev)
>*/
>   vfio_pci_set_power_state(vdev, PCI_D0);
>  
> + vfio_pci_dma_buf_move(vdev, true);
>   ret = pci_try_reset_function(vdev->pdev);
> + if (__vfio_pci_memory_enabled(vdev))
> + vfio_pci_dma_buf_move(vdev, false);
>   up_write(&vdev->memory_lock);
>  
>   return ret;
> @@ -1210,11 +1215,10 @@ long vfio_pci_core_ioctl(struct vfio_device 
> *core_vdev, unsigned int cmd,
>  }
>  EXPORT_SYMBOL_GPL(vfio_pci_core_ioctl);
>  
> -static int vfio_pci_core_feature_token(struct vfio_device *device, u32 flags,
> -uuid_t __user *arg, size_t argsz)
> +static int vfio_pci_core_feature_token(struct vfio_pci_core_device *vdev,
> +u32 flags, uuid_t __user *arg,
> + 

Re: [PTACH v3] drm/ast: add dmabuf/prime buffer sharing support

2022-08-28 Thread kernel test robot
Hi oushixiong,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on drm/drm-next drm-intel/for-linux-next 
drm-tip/drm-tip linus/master v6.0-rc3 next-20220826]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/oushixiong/drm-ast-add-dmabuf-prime-buffer-sharing-support/20220829-084713
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
config: i386-randconfig-a013 
(https://download.01.org/0day-ci/archive/20220829/202208291132.rqqpjzo1-...@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project 
f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# 
https://github.com/intel-lab-lkp/linux/commit/da31884b8b7e33af5cd8aa750dea30fde59d52aa
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review 
oushixiong/drm-ast-add-dmabuf-prime-buffer-sharing-support/20220829-084713
git checkout da31884b8b7e33af5cd8aa750dea30fde59d52aa
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 
O=build_dir ARCH=i386 SHELL=/bin/bash drivers/gpu/drm/ast/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot 

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/ast/ast_drv.c:54:24: warning: no previous prototype for 
>> function 'ast_gem_prime_import' [-Wmissing-prototypes]
   struct drm_gem_object *ast_gem_prime_import(struct drm_device *dev,
  ^
   drivers/gpu/drm/ast/ast_drv.c:54:1: note: declare 'static' if the function 
is not intended to be used outside of this translation unit
   struct drm_gem_object *ast_gem_prime_import(struct drm_device *dev,
   ^
   static 
   1 warning generated.


vim +/ast_gem_prime_import +54 drivers/gpu/drm/ast/ast_drv.c

53  
  > 54  struct drm_gem_object *ast_gem_prime_import(struct drm_device *dev,
55  struct dma_buf *dma_buf)
56  {
57  struct drm_gem_vram_object *gbo;
58  
59  gbo = drm_gem_vram_of_gem(dma_buf->priv);
60  if (gbo->bo.base.dev == dev) {
61  /*
62  * Importing dmabuf exported from out own gem increases
63  * refcount on gem itself instead of f_count of dmabuf.
64  */
65  drm_gem_object_get(&gbo->bo.base);
66  return &gbo->bo.base;
67  }
68  
69  gbo = drm_gem_vram_create(dev, dma_buf->size, 0);
70  if (IS_ERR(gbo))
71  return NULL;
72  
73  get_dma_buf(dma_buf);
74  return &gbo->bo.base;
75  }
76  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp


Re: [PATCH 3/3] drm: omapdrm: Do no allocate non-scanout GEMs through DMM/TILER

2022-08-28 Thread Yongqin Liu
Hi, Ivaylo

Sorry for the late response, and Thanks very much for the detailed explanations!

On Thu, 18 Aug 2022 at 18:23, Ivaylo Dimitrov
 wrote:
>
> Hi,
>
> On 17.08.22 г. 7:52 ч., Yongqin Liu wrote:
> > Hi, Ivaylo
> >
> > On Mon, 15 Aug 2022 at 14:23, Ivaylo Dimitrov
> >  wrote:
> >>
> >> Hi Liu,
> >>
> >> On 14.08.22 г. 17:27 ч., Yongqin Liu wrote:
> >>> Hi, IvayIo
> >>>
> >>> Thanks very much for the reply!
> >>>
> >>> On Sat, 13 Aug 2022 at 14:58, Ivaylo Dimitrov
> >>>  wrote:
> 
>  Hi Liu,
> 
>  On 12.08.22 г. 7:35 ч., Yongqin Liu wrote:
> > Hi, Ivaylo, Tomi
> >
> > We have one X15 Android AOSP master build, it could not have the home
> > screen displayed
> > on the hdmi monitor connected with this change, with the following
> > message printed on the serial console
> >[  607.404205] omapdrm omapdrm.0: Failed to setup plane plane-0
> >[  607.410522] omapdrm omapdrm.0: Failed to setup plane plane-1
> >[  607.416381] omapdrm omapdrm.0: Failed to setup plane plane-2
> >[  607.422088] omapdrm omapdrm.0: Failed to setup plane plane-3
> >
> >   # for details, please check the link here: http://ix.io/47m1
> >
> > It will work with home screen displayed on the hdmi monitor if this
> > change is reverted.
> >
> > Is this the broken problem you talked about here?
> >
> > And could you please give some suggestions on how to have the x15
> > Android build work with this change?
> >
> 
>  Make sure scanout (i.e. those to be displayed) buffers are actually
>  allocated as such - OMAP_BO_SCANOUT flag must be set when calling
>  omap_bo_new().
> >>>
> >>> I am not familiar with this area, I am sorry if I asked quite silly 
> >>> questions:(
> >>> I googled omap_bo_new, and found it's a function of libdrm here[1], is
> >>> it what you meant here?
> >>>
> >>
> >> Yes, calling this function from userspace ends in kernel code the
> >> $subject patch is part of.
> >>
> >>> If it's the omap_bo_new that we should pass OMAP_BO_SCANOUT when it is 
> >>> called,
> >>> then is it the correct way to update omap_bo_new to add the 
> >>> OMAP_BO_SCANOUT flag
> >>> before it calls omap_bo_new_impl?
> >>>
> >>
> >> omap_bo_new() is fine and does not need any updates/fixes, it is the
> >> code that uses it (whoever it is, I am not familiar with the userspace
> >> you are using) that shall pass correct flags (third parameter) when
> >> calling it.
> >
> > Sorry, I do not get the point here.
> > Like you said, the code that calls omap_bo_new needs to pass 
> > OMAP_BO_SCANOUT,
> > then IMO omap_bo_new should be the best place to add the OMAP_BO_SCANOUT 
> > flag,
> > (like via flags = flags | OMAP_BO_SCANOUT), that could help avoid
> > missing the flag by some code,
> > and also avoids hacks/changes on the possible blob binaries.
> >
> > Do I misunderstand somewhere?
> > Or is there some case that OMAP_BO_SCANOUT shouldn't be passed when
> > omap_bo_new is called?
> >
>
> Exactly. You need to pass OMAP_BO_SCANOUT only when you want your
> buffers to be 'scanout' buffers(i.e. buffers that can be displayed on
> screen), which is not always the case - there is no need offscreen
> buffers or pixmaps to be scanout capable, for example. There are more
> cases like that.
>
> The problem is that scanout buffer on OMAP4 allocate additional
> resources in DMM/TILER (a piece of hardware) and those resources are
> limited. Not only that, but DMM/TILER memory space eventually gets
> fragmented over time (if you have lots of allocataoins/deallocations)
> and you will start getting ENOMEM (or similar) errors.
>
> Ofc, in your particular use case you may never hit such issues.

Thanks, I understand the cases now.


> >> BTW you shall really find who and how uses OMAP BO API, in theory it
> >> might use ioctls directly and not call omap_bo_xxx functions.
> >
> > Do you mean the DRM_OMAP_GEM_NEW ioctl api?
> > There is no place in the AOSP tree to call that except the
> > omap_bo_new_impl function,
> > which is called by the omap_bo_new and omap_bo_new_tiled functions.
> > The omap_bo_new should not be called with the OMAP_BO_TILED flag,
> > while the omap_bo_new_tiled should be called with the OMAP_BO_TILED flag
> >
> > Regarding to the omap_bo_new function, there are 2 places call it in
> > the AOSP tree:
> > #1 ./external/libkmsxx/kms++/src/omap/omapframebuffer.cpp
> > #2 ./device/ti/beagle_x15/gpu/gralloc.am57x.so
> >
> > #1 seems not used in AOSP yet, and #2 is one blob binary we do not
> > have the source for.
> >
>
> I would bet on gralloc.am57x.so.
yeah, that's my guess as well.

> >> strace
> >> would be your friend there. or gdb, or whatever tools are used on
> >> android. Or put some printfs() in omap_bo_new() that output the PID of
> >> the calling process, etc.
> >
> > Thanks a lot for these great suggestions! Will use them when possible.
> >
> >>> And another question is that, since the 

Re: [PATCH 1/4] dt-bindings: display: imx: add binding for i.MX8MP HDMI TX

2022-08-28 Thread Rob Herring
On Fri, 26 Aug 2022 21:24:21 +0200, Lucas Stach wrote:
> The HDMI TX controller on the i.MX8MP SoC is a Synopsys designware IP
> core with a little bit of SoC integration around it.
> 
> Signed-off-by: Lucas Stach 
> Tested-by: Marek Vasut 
> ---
>  .../bindings/display/imx/fsl,imx8mp-hdmi.yaml | 74 +++
>  1 file changed, 74 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/display/imx/fsl,imx8mp-hdmi.yaml
> 

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/display/imx/fsl,imx8mp-hdmi.example.dtb:
 hdmi@32fd8000: clock-names:2: 'cec' was expected
From schema: 
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/display/imx/fsl,imx8mp-hdmi.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/display/imx/fsl,imx8mp-hdmi.example.dtb:
 hdmi@32fd8000: clock-names:3: 'pix' was expected
From schema: 
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/display/imx/fsl,imx8mp-hdmi.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/display/imx/fsl,imx8mp-hdmi.example.dtb:
 hdmi@32fd8000: clock-names:4: 'fdcc' was expected
From schema: 
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/display/imx/fsl,imx8mp-hdmi.yaml

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/

This check can fail if there are any dependencies. The base for a patch
series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit.



[PTACH v3] drm/ast: add dmabuf/prime buffer sharing support

2022-08-28 Thread oushixiong
This patch adds ast specific codes for DRM prime feature, this is to
allow for offloading of rending in one direction and outputs in other.

This patch is designed to solve the problem that the AST is not displayed
when the server plug in a discrete graphics graphics card at the same time.
We call the dirty callback function to copy the rendering results of the
discrete graphics card to the ast side by dma-buf.

v1->v2:
  - Fix the comment.
v2->v3:
  - we remove the gem_prime_import_sg_table callback and use the 
gem_prime_import
callback, becuase it just map and access the buffer with the CPU. and do not
to pin the buffer.

Signed-off-by: oushixiong 
---
 drivers/gpu/drm/ast/ast_drv.c  |  27 +++
 drivers/gpu/drm/ast/ast_mode.c | 125 -
 2 files changed, 151 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/ast/ast_drv.c b/drivers/gpu/drm/ast/ast_drv.c
index 7465c4f0156a..107383a56ca7 100644
--- a/drivers/gpu/drm/ast/ast_drv.c
+++ b/drivers/gpu/drm/ast/ast_drv.c
@@ -28,6 +28,7 @@
 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -50,6 +51,29 @@ module_param_named(modeset, ast_modeset, int, 0400);
 
 DEFINE_DRM_GEM_FOPS(ast_fops);
 
+struct drm_gem_object *ast_gem_prime_import(struct drm_device *dev,
+   struct dma_buf *dma_buf)
+{
+   struct drm_gem_vram_object *gbo;
+
+   gbo = drm_gem_vram_of_gem(dma_buf->priv);
+   if (gbo->bo.base.dev == dev) {
+   /*
+   * Importing dmabuf exported from out own gem increases
+   * refcount on gem itself instead of f_count of dmabuf.
+   */
+   drm_gem_object_get(&gbo->bo.base);
+   return &gbo->bo.base;
+   }
+
+   gbo = drm_gem_vram_create(dev, dma_buf->size, 0);
+   if (IS_ERR(gbo))
+   return NULL;
+
+   get_dma_buf(dma_buf);
+   return &gbo->bo.base;
+}
+
 static const struct drm_driver ast_driver = {
.driver_features = DRIVER_ATOMIC |
   DRIVER_GEM |
@@ -63,6 +87,9 @@ static const struct drm_driver ast_driver = {
.minor = DRIVER_MINOR,
.patchlevel = DRIVER_PATCHLEVEL,
 
+   .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
+   .gem_prime_import = ast_gem_prime_import,
+
DRM_GEM_VRAM_DRIVER
 };
 
diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
index 45b56b39ad47..65a4342c5622 100644
--- a/drivers/gpu/drm/ast/ast_mode.c
+++ b/drivers/gpu/drm/ast/ast_mode.c
@@ -48,6 +48,8 @@
 #include "ast_drv.h"
 #include "ast_tables.h"
 
+MODULE_IMPORT_NS(DMA_BUF);
+
 static inline void ast_load_palette_index(struct ast_private *ast,
 u8 index, u8 red, u8 green,
 u8 blue)
@@ -1535,8 +1537,129 @@ static const struct drm_mode_config_helper_funcs 
ast_mode_config_helper_funcs =
.atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
 };
 
+static int ast_handle_damage(struct drm_framebuffer *fb, int x, int y,
+   int width, int height)
+{
+   struct drm_gem_vram_object *dst_bo = NULL;
+   void *dst = NULL;
+   int ret = 0, i;
+   unsigned long offset = 0;
+   bool unmap = false;
+   unsigned int bytesPerPixel;
+   struct iosys_map map;
+   struct iosys_map dmabuf_map;
+
+   bytesPerPixel = fb->format->cpp[0];
+
+   if (!fb->obj[0]->dma_buf)
+   return -EINVAL;
+
+   if (!fb->obj[0]->dma_buf->vmap_ptr.vaddr) {
+   ret = dma_buf_vmap(fb->obj[0]->dma_buf, &dmabuf_map);
+   if (ret)
+   return ret;
+   } else
+   dmabuf_map.vaddr = fb->obj[0]->dma_buf->vmap_ptr.vaddr;
+
+   dst_bo = drm_gem_vram_of_gem(fb->obj[0]);
+
+   ret = drm_gem_vram_pin(dst_bo, 0);
+   if (ret) {
+   DRM_ERROR("ast_bo_pin failed\n");
+   return ret;
+   }
+
+   if (!dst_bo->map.vaddr) {
+   ret = drm_gem_vram_vmap(dst_bo, &map);
+   if (ret) {
+   drm_gem_vram_unpin(dst_bo);
+   DRM_ERROR("failed to vmap fbcon\n");
+   return ret;
+   }
+   unmap = true;
+   }
+   dst = dst_bo->map.vaddr;
+
+   for (i = y; i < y + height; i++) {
+   offset = i * fb->pitches[0] + (x * bytesPerPixel);
+   memcpy_toio(dst + offset, dmabuf_map.vaddr + offset,
+   width * bytesPerPixel);
+   }
+
+   if (unmap)
+   drm_gem_vram_vunmap(dst_bo, &map);
+
+   drm_gem_vram_unpin(dst_bo);
+
+   return 0;
+}
+
+
+static int ast_user_framebuffer_dirty(struct drm_framebuffer *fb,
+   struct drm_file *file,
+   unsigned int flags,
+   unsigned int color,
+   struct 

[PATCH i-g-t v2 4/4] tests: DRM selftests: switch to KUnit

2022-08-28 Thread Isabella Basso
As the DRM selftests are now using KUnit [1], update IGT tests as well.

[1] - https://lore.kernel.org/all/20220708203052.236290-1-maira.ca...@usp.br/

Signed-off-by: Isabella Basso 
---
 tests/drm_buddy.c|  7 ---
 tests/drm_mm.c   |  7 ---
 tests/kms_selftest.c | 12 +---
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/tests/drm_buddy.c b/tests/drm_buddy.c
index 06876e0c..74c06dce 100644
--- a/tests/drm_buddy.c
+++ b/tests/drm_buddy.c
@@ -6,9 +6,10 @@
 #include "igt.h"
 #include "igt_kmod.h"
 
-IGT_TEST_DESCRIPTION("Basic sanity check of DRM's buddy allocator (struct 
drm_buddy)");
+IGT_TEST_DESCRIPTION("Basic sanity check of DRM's buddy allocator (struct \
+ drm_buddy) using KUnit");
 
-igt_main
+igt_simple_main
 {
-   igt_kselftests("test-drm_buddy", NULL, NULL, NULL);
+   igt_kunit("drm_buddy_test", NULL);
 }
diff --git a/tests/drm_mm.c b/tests/drm_mm.c
index 2052b115..75fc6682 100644
--- a/tests/drm_mm.c
+++ b/tests/drm_mm.c
@@ -24,9 +24,10 @@
 #include "igt.h"
 #include "igt_kmod.h"
 
-IGT_TEST_DESCRIPTION("Basic sanity check of DRM's range manager (struct 
drm_mm)");
+IGT_TEST_DESCRIPTION("Basic sanity check of DRM's range manager (struct 
drm_mm)\
+using KUnit");
 
-igt_main
+igt_simple_main
 {
-   igt_kselftests("test-drm_mm", NULL, NULL, NULL);
+   igt_kunit("drm_mm_test", NULL);
 }
diff --git a/tests/kms_selftest.c b/tests/kms_selftest.c
index abc4bfe9..bbf24c2b 100644
--- a/tests/kms_selftest.c
+++ b/tests/kms_selftest.c
@@ -24,9 +24,15 @@
 #include "igt.h"
 #include "igt_kmod.h"
 
-IGT_TEST_DESCRIPTION("Basic sanity check of KMS selftests.");
+IGT_TEST_DESCRIPTION("Basic sanity check of KMS selftests using KUnit");
 
-igt_main
+igt_simple_main
 {
-   igt_kselftests("test-drm_modeset", NULL, NULL, NULL);
+   igt_kunit("drm_cmdline_parser_test", NULL);
+   igt_kunit("drm_damage_helper_test", NULL);
+   igt_kunit("drm_dp_mst_helper_test", NULL);
+   igt_kunit("drm_format_helper_test", NULL);
+   igt_kunit("drm_format_test", NULL);
+   igt_kunit("drm_framebuffer_test", NULL);
+   igt_kunit("drm_plane_helper_test", NULL);
 }
-- 
2.37.2



[PATCH i-g-t v2 3/4] lib/igt_kmod: add compatibility for KUnit

2022-08-28 Thread Isabella Basso
This adds functions for both executing the tests as well as parsing (K)TAP
kmsg output, as per the KTAP spec [1].

[1] https://www.kernel.org/doc/html/latest/dev-tools/ktap.html

Signed-off-by: Isabella Basso 
---
 lib/igt_kmod.c | 290 +
 lib/igt_kmod.h |   2 +
 2 files changed, 292 insertions(+)

diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index 97cac7f5..93cdfcc5 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "igt_aux.h"
 #include "igt_core.h"
@@ -32,6 +33,8 @@
 #include "igt_sysfs.h"
 #include "igt_taints.h"
 
+#define BUF_LEN 4096
+
 /**
  * SECTION:igt_kmod
  * @short_description: Wrappers around libkmod for module loading/unloading
@@ -713,6 +716,293 @@ void igt_kselftest_get_tests(struct kmod_module *kmod,
kmod_module_info_free_list(pre);
 }
 
+/**
+ * lookup_value:
+ * @haystack: the string to search in
+ * @needle: the string to search for
+ *
+ * Returns: the value of the needle in the haystack, or -1 if not found.
+ */
+static long lookup_value(const char *haystack, const char *needle)
+{
+   const char *needle_rptr;
+   char *needle_end;
+   long num;
+
+   needle_rptr = strcasestr(haystack, needle);
+
+   if (needle_rptr == NULL)
+   return -1;
+
+   /* skip search string and whitespaces after it */
+   needle_rptr += strlen(needle);
+
+   num = strtol(needle_rptr, &needle_end, 10);
+
+   if (needle_rptr == needle_end)
+   return -1;
+
+   if (num == LONG_MIN || num == LONG_MAX)
+   return 0;
+
+   return num > 0 ? num : 0;
+}
+
+static int find_next_tap_subtest(char *record, char *test_name,
+bool is_subtest)
+{
+   const char *name_lookup_str,
+ *lend, *version_rptr, *name_rptr;
+   long test_count;
+
+   name_lookup_str = "test: ";
+
+   version_rptr = strcasestr(record, "TAP version ");
+   name_rptr = strcasestr(record, name_lookup_str);
+
+   /*
+* total test count will almost always appear as 0..N at the beginning
+* of a run, so we use it as indication of a run
+*/
+   test_count = lookup_value(record, "..");
+
+   /* no count found, so this is probably not starting a (sub)test */
+   if (test_count < 0) {
+   if (name_rptr != NULL) {
+   if (test_name[0] == '\0')
+   strncpy(test_name,
+   name_rptr + strlen(name_lookup_str),
+   BUF_LEN);
+   else if (strcmp(test_name, name_rptr + 
strlen(name_lookup_str)) == 0)
+   return 0;
+   else
+   test_name[0] = '\0';
+
+   }
+   return -1;
+   }
+
+   /*
+* "(K)TAP version XX" should be the first line on all (sub)tests as per
+* 
https://www.kernel.org/doc/html/latest/dev-tools/ktap.html#version-lines
+* but actually isn't, as it currently depends on whoever writes the
+* test to print this info
+*/
+   if (version_rptr == NULL)
+   igt_info("Missing test version string\n");
+
+   if (name_rptr == NULL) {
+   /* we have to keep track of the name string, as it might be
+* contained in a line read previously */
+   if (test_name[0] == '\0') {
+   igt_info("Missing test name string\n");
+
+   if (is_subtest)
+   igt_info("Running %ld subtests...\n", 
test_count);
+   else
+   igt_info("Running %ld tests...\n", test_count);
+   } else {
+   lend = strchrnul(test_name, '\n');
+
+   if (*lend == '\0') {
+   if (is_subtest)
+   igt_info("Executing %ld subtests in: 
%s\n",
+test_count, test_name);
+   else
+   igt_info("Executing %ld tests in: %s\n",
+test_count, test_name);
+   return test_count;
+   }
+
+   if (is_subtest)
+   igt_info("Executing %ld subtests in: %.*s\n",
+test_count, (int)(lend - test_name),
+test_name);
+   else
+   igt_info("Executing %ld tests in: %.*s\n",
+test_count, (int)(lend - test_name),
+test_name);
+   test_name[0] = '\0';
+   }
+   } el

[PATCH i-g-t v2 1/4] lib/igt_kmod: rename kselftest functions to ktest

2022-08-28 Thread Isabella Basso
This aims at making IGT's structure more general to different kernel
testing frameworks such as KUnit, as they use a lot of the same
functionality.

Signed-off-by: Isabella Basso 
---
 lib/igt_kmod.c | 22 +++---
 lib/igt_kmod.h | 12 ++--
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index bcf7dfeb..bb6cb7bb 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -718,8 +718,8 @@ static int open_parameters(const char *module_name)
return open(path, O_RDONLY);
 }
 
-int igt_kselftest_init(struct igt_kselftest *tst,
-  const char *module_name)
+int igt_ktest_init(struct igt_ktest *tst,
+  const char *module_name)
 {
int err;
 
@@ -738,7 +738,7 @@ int igt_kselftest_init(struct igt_kselftest *tst,
return 0;
 }
 
-int igt_kselftest_begin(struct igt_kselftest *tst)
+int igt_ktest_begin(struct igt_ktest *tst)
 {
int err;
 
@@ -753,7 +753,7 @@ int igt_kselftest_begin(struct igt_kselftest *tst)
return 0;
 }
 
-int igt_kselftest_execute(struct igt_kselftest *tst,
+int igt_kselftest_execute(struct igt_ktest *tst,
  struct igt_kselftest_list *tl,
  const char *options,
  const char *result)
@@ -791,13 +791,13 @@ int igt_kselftest_execute(struct igt_kselftest *tst,
return err;
 }
 
-void igt_kselftest_end(struct igt_kselftest *tst)
+void igt_ktest_end(struct igt_ktest *tst)
 {
kmod_module_remove_module(tst->kmod, KMOD_REMOVE_FORCE);
close(tst->kmsg);
 }
 
-void igt_kselftest_fini(struct igt_kselftest *tst)
+void igt_ktest_fini(struct igt_ktest *tst)
 {
free(tst->module_name);
kmod_module_unref(tst->kmod);
@@ -820,15 +820,15 @@ void igt_kselftests(const char *module_name,
const char *result,
const char *filter)
 {
-   struct igt_kselftest tst;
+   struct igt_ktest tst;
IGT_LIST_HEAD(tests);
struct igt_kselftest_list *tl, *tn;
 
-   if (igt_kselftest_init(&tst, module_name) != 0)
+   if (igt_ktest_init(&tst, module_name) != 0)
return;
 
igt_fixture
-   igt_require(igt_kselftest_begin(&tst) == 0);
+   igt_require(igt_ktest_begin(&tst) == 0);
 
igt_kselftest_get_tests(tst.kmod, filter, &tests);
igt_subtest_with_dynamic(filter ?: "all") {
@@ -847,9 +847,9 @@ void igt_kselftests(const char *module_name,
}
 
igt_fixture {
-   igt_kselftest_end(&tst);
+   igt_ktest_end(&tst);
igt_require(!igt_list_empty(&tests));
}
 
-   igt_kselftest_fini(&tst);
+   igt_ktest_fini(&tst);
 }
diff --git a/lib/igt_kmod.h b/lib/igt_kmod.h
index f98dd29f..ceb10cd0 100644
--- a/lib/igt_kmod.h
+++ b/lib/igt_kmod.h
@@ -50,7 +50,7 @@ void igt_kselftests(const char *module_name,
const char *result_option,
const char *filter);
 
-struct igt_kselftest {
+struct igt_ktest {
struct kmod_module *kmod;
char *module_name;
int kmsg;
@@ -63,19 +63,19 @@ struct igt_kselftest_list {
char param[];
 };
 
-int igt_kselftest_init(struct igt_kselftest *tst,
+int igt_ktest_init(struct igt_ktest *tst,
   const char *module_name);
-int igt_kselftest_begin(struct igt_kselftest *tst);
+int igt_ktest_begin(struct igt_ktest *tst);
 
 void igt_kselftest_get_tests(struct kmod_module *kmod,
 const char *filter,
 struct igt_list_head *tests);
-int igt_kselftest_execute(struct igt_kselftest *tst,
+int igt_kselftest_execute(struct igt_ktest *tst,
  struct igt_kselftest_list *tl,
  const char *module_options,
  const char *result);
 
-void igt_kselftest_end(struct igt_kselftest *tst);
-void igt_kselftest_fini(struct igt_kselftest *tst);
+void igt_ktest_end(struct igt_ktest *tst);
+void igt_ktest_fini(struct igt_ktest *tst);
 
 #endif /* IGT_KMOD_H */
-- 
2.37.2



[PATCH i-g-t v2 2/4] lib/igt_kmod.c: check if module is builtin before attempting to unload it

2022-08-28 Thread Isabella Basso
This change makes `igt_module_unload_r` safer as it checks whether the
module can be unloaded before attempting it.

Signed-off-by: Isabella Basso 
---
 lib/igt_kmod.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index bb6cb7bb..97cac7f5 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -256,6 +256,9 @@ static int igt_kmod_unload_r(struct kmod_module *kmod, 
unsigned int flags)
struct kmod_list *holders, *pos;
int err = 0;
 
+   if (kmod_module_get_initstate(kmod) == KMOD_MODULE_BUILTIN)
+   return err;
+
holders = kmod_module_get_holders(kmod);
kmod_list_foreach(pos, holders) {
struct kmod_module *it = kmod_module_get_module(pos);
-- 
2.37.2



[PATCH i-g-t v2 0/4] Add support for KUnit tests

2022-08-28 Thread Isabella Basso
This patch series was first developed as part of the LKCamp hackathon
that happened last year[1], mainly focusing on refactoring DRM tests to
use KUnit.

KUnit[2][3] is a unified test framework that provides helper tools,
simplifying their development and execution. Using an x86-64 machine
it's possible to run tests in the host's kernel natively using user-mode
Linux[4] (aka UML), which simplifies usage in a wide variety of
scenarios, including integration to CI.

As the tool's adoption widens into graphics testing territory, I and
LKCamp members figured it would be important to support it in IGT, as
it's a core tool for GPU drivers maintainers.

I have then added KUnit support into IGT mainly following the KTAP
specs, and it can be tested using patch 4/4 in this series together with
a DRM selftests patch series available at [5].

Changes since v1:
- Major rework of parsing function structure:
  - It is not longer recursive
  - Adapt kselftests functions and structs to be used with KUnit
- Switch DRM selftests to KUnit parsing as they're updated in the kernel
- Replace AMD KUnit tests by DRM selftests

[1]: https://groups.google.com/g/kunit-dev/c/YqFR1q2uZvk/m/IbvItSfHBAAJ
[2]: https://kunit.dev
[3]: https://docs.kernel.org/dev-tools/kunit/index.html
[4]: http://user-mode-linux.sourceforge.net
[5]: https://lore.kernel.org/all/20220708203052.236290-1-maira.ca...@usp.br/

Isabella Basso (4):
  lib/igt_kmod: rename kselftest functions to ktest
  lib/igt_kmod.c: check if module is builtin before attempting to unload
it
  lib/igt_kmod: add compatibility for KUnit
  tests: DRM selftests: switch to KUnit

 lib/igt_kmod.c   | 315 +--
 lib/igt_kmod.h   |  14 +-
 tests/drm_buddy.c|   7 +-
 tests/drm_mm.c   |   7 +-
 tests/kms_selftest.c |  12 +-
 5 files changed, 329 insertions(+), 26 deletions(-)

-- 
2.37.2



[PATCH v2] Documentation: fb: udlfb: clean up text and formatting

2022-08-28 Thread Randy Dunlap
Clean up punctuation, spelling, and formatting for command line usage
and modprobe config file usage in udlfb.rst.

Signed-off-by: Randy Dunlap 
Cc: Bernie Thompson 
Cc: linux-fb...@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
Cc: Helge Deller 
Cc: Jonathan Corbet 
Cc: linux-...@vger.kernel.org
Cc: Bagas Sanjaya 
---
v2: use some text suggestions from Bagas Sanjaya (Thanks);
add a '.' at the end of a sentence.

 Documentation/fb/udlfb.rst |   23 +++
 1 file changed, 15 insertions(+), 8 deletions(-)

--- a/Documentation/fb/udlfb.rst
+++ b/Documentation/fb/udlfb.rst
@@ -86,17 +86,24 @@ Module Options
 Special configuration for udlfb is usually unnecessary. There are a few
 options, however.
 
-From the command line, pass options to modprobe
-modprobe udlfb fb_defio=0 console=1 shadow=1
+From the command line, pass options to modprobe::
 
-Or modify options on the fly at /sys/module/udlfb/parameters directory via
-sudo nano fb_defio
-change the parameter in place, and save the file.
+  modprobe udlfb fb_defio=0 console=1 shadow=1
 
-Unplug/replug USB device to apply with new settings
+Or change options on the fly by editing
+/sys/module/udlfb/parameters/PARAMETER_NAME ::
 
-Or for permanent option, create file like /etc/modprobe.d/udlfb.conf with text
-options udlfb fb_defio=0 console=1 shadow=1
+  cd /sys/module/udlfb/parameters
+  ls # to see a list of parameter names
+  sudo nano PARAMETER_NAME
+  # change the parameter in place, and save the file.
+
+Unplug/replug USB device to apply with new settings.
+
+Or to apply options permanently, create a modprobe configuration file
+like /etc/modprobe.d/udlfb.conf with text::
+
+  options udlfb fb_defio=0 console=1 shadow=1
 
 Accepted boolean options:
 


[PATCH v5 6/6] arm64: dts: qcom: sc7280: Add Reset support for gpu

2022-08-28 Thread Akhil P Oommen
Add support for Reset using GPUCC driver for GPU. This helps to ensure
that GPU state is reset by making sure that CX head switch is collapsed.

Signed-off-by: Akhil P Oommen 
---

(no changes since v1)

 arch/arm64/boot/dts/qcom/sc7280.dtsi | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sc7280.dtsi 
b/arch/arm64/boot/dts/qcom/sc7280.dtsi
index e66fc67..f5257d6 100644
--- a/arch/arm64/boot/dts/qcom/sc7280.dtsi
+++ b/arch/arm64/boot/dts/qcom/sc7280.dtsi
@@ -2243,6 +2243,9 @@
nvmem-cells = <&gpu_speed_bin>;
nvmem-cell-names = "speed_bin";
 
+   resets = <&gpucc GPU_CX_COLLAPSE>;
+   reset-names = "cx_collapse";
+
gpu_opp_table: opp-table {
compatible = "operating-points-v2";
 
-- 
2.7.4



[PATCH v5 4/6] clk: qcom: gpucc-sc7280: Add cx collapse reset support

2022-08-28 Thread Akhil P Oommen
Allow a consumer driver to poll for cx gdsc collapse through Reset
framework.

Signed-off-by: Akhil P Oommen 
Reviewed-by: Dmitry Baryshkov 
---

(no changes since v3)

Changes in v3:
- Convert 'struct qcom_reset_ops cx_gdsc_reset' to 'static const' (Krzysztof)

Changes in v2:
- Minor update to use the updated custom reset ops implementation

 drivers/clk/qcom/gpucc-sc7280.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/clk/qcom/gpucc-sc7280.c b/drivers/clk/qcom/gpucc-sc7280.c
index 9a832f2..fece3f4 100644
--- a/drivers/clk/qcom/gpucc-sc7280.c
+++ b/drivers/clk/qcom/gpucc-sc7280.c
@@ -433,12 +433,22 @@ static const struct regmap_config 
gpu_cc_sc7280_regmap_config = {
.fast_io = true,
 };
 
+static const struct qcom_reset_ops cx_gdsc_reset = {
+   .reset = gdsc_wait_for_collapse,
+};
+
+static const struct qcom_reset_map gpucc_sc7280_resets[] = {
+   [GPU_CX_COLLAPSE] = { .ops = &cx_gdsc_reset, .priv = &cx_gdsc },
+};
+
 static const struct qcom_cc_desc gpu_cc_sc7280_desc = {
.config = &gpu_cc_sc7280_regmap_config,
.clks = gpu_cc_sc7280_clocks,
.num_clks = ARRAY_SIZE(gpu_cc_sc7280_clocks),
.gdscs = gpu_cc_sc7180_gdscs,
.num_gdscs = ARRAY_SIZE(gpu_cc_sc7180_gdscs),
+   .resets = gpucc_sc7280_resets,
+   .num_resets = ARRAY_SIZE(gpucc_sc7280_resets),
 };
 
 static const struct of_device_id gpu_cc_sc7280_match_table[] = {
-- 
2.7.4



[PATCH v5 5/6] dt-bindings: drm/msm/gpu: Add optional resets

2022-08-28 Thread Akhil P Oommen
Add an optional reference to GPUCC reset which can be used to ensure cx
gdsc collapse during gpu recovery.

Signed-off-by: Akhil P Oommen 
Acked-by: Rob Herring 
---

Changes in v5:
- Nit: Remove a duplicate blank line (Krzysztof)

Changes in v4:
- New patch in v4

 Documentation/devicetree/bindings/display/msm/gpu.yaml | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/display/msm/gpu.yaml 
b/Documentation/devicetree/bindings/display/msm/gpu.yaml
index 3397bc3..408ed97 100644
--- a/Documentation/devicetree/bindings/display/msm/gpu.yaml
+++ b/Documentation/devicetree/bindings/display/msm/gpu.yaml
@@ -109,6 +109,12 @@ properties:
   For GMU attached devices a phandle to the GMU device that will
   control the power for the GPU.
 
+  resets:
+maxItems: 1
+
+  reset-names:
+items:
+  - const: cx_collapse
 
 required:
   - compatible
-- 
2.7.4



[PATCH v5 1/6] dt-bindings: clk: qcom: Support gpu cx gdsc reset

2022-08-28 Thread Akhil P Oommen
Add necessary definitions in gpucc bindings to ensure gpu cx gdsc collapse
through 'reset' framework for SC7280.

Signed-off-by: Akhil P Oommen 
Acked-by: Krzysztof Kozlowski 
---

(no changes since v1)

 include/dt-bindings/clock/qcom,gpucc-sc7280.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/dt-bindings/clock/qcom,gpucc-sc7280.h 
b/include/dt-bindings/clock/qcom,gpucc-sc7280.h
index 669b23b..843a31b 100644
--- a/include/dt-bindings/clock/qcom,gpucc-sc7280.h
+++ b/include/dt-bindings/clock/qcom,gpucc-sc7280.h
@@ -32,4 +32,7 @@
 #define GPU_CC_CX_GDSC 0
 #define GPU_CC_GX_GDSC 1
 
+/* GPU_CC reset IDs */
+#define GPU_CX_COLLAPSE0
+
 #endif
-- 
2.7.4



[PATCH v5 3/6] clk: qcom: gdsc: Add a reset op to poll gdsc collapse

2022-08-28 Thread Akhil P Oommen
Add a reset op compatible function to poll for gdsc collapse.

Signed-off-by: Akhil P Oommen 
Reviewed-by: Dmitry Baryshkov 
---

(no changes since v2)

Changes in v2:
- Minor update to function prototype

 drivers/clk/qcom/gdsc.c | 23 +++
 drivers/clk/qcom/gdsc.h |  7 +++
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c
index 44520ef..2d0f1d1 100644
--- a/drivers/clk/qcom/gdsc.c
+++ b/drivers/clk/qcom/gdsc.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include "gdsc.h"
+#include "reset.h"
 
 #define PWR_ON_MASKBIT(31)
 #define EN_REST_WAIT_MASK  GENMASK_ULL(23, 20)
@@ -116,7 +117,8 @@ static int gdsc_hwctrl(struct gdsc *sc, bool en)
return regmap_update_bits(sc->regmap, sc->gdscr, HW_CONTROL_MASK, val);
 }
 
-static int gdsc_poll_status(struct gdsc *sc, enum gdsc_status status)
+static int gdsc_poll_status(struct gdsc *sc, enum gdsc_status status,
+   s64 timeout_us, unsigned int interval_ms)
 {
ktime_t start;
 
@@ -124,7 +126,9 @@ static int gdsc_poll_status(struct gdsc *sc, enum 
gdsc_status status)
do {
if (gdsc_check_status(sc, status))
return 0;
-   } while (ktime_us_delta(ktime_get(), start) < TIMEOUT_US);
+   if (interval_ms)
+   msleep(interval_ms);
+   } while (ktime_us_delta(ktime_get(), start) < timeout_us);
 
if (gdsc_check_status(sc, status))
return 0;
@@ -172,7 +176,7 @@ static int gdsc_toggle_logic(struct gdsc *sc, enum 
gdsc_status status)
udelay(1);
}
 
-   ret = gdsc_poll_status(sc, status);
+   ret = gdsc_poll_status(sc, status, TIMEOUT_US, 0);
WARN(ret, "%s status stuck at 'o%s'", sc->pd.name, status ? "ff" : "n");
 
if (!ret && status == GDSC_OFF && sc->rsupply) {
@@ -343,7 +347,7 @@ static int _gdsc_disable(struct gdsc *sc)
 */
udelay(1);
 
-   ret = gdsc_poll_status(sc, GDSC_ON);
+   ret = gdsc_poll_status(sc, GDSC_ON, TIMEOUT_US, 0);
if (ret)
return ret;
}
@@ -565,3 +569,14 @@ int gdsc_gx_do_nothing_enable(struct generic_pm_domain 
*domain)
return 0;
 }
 EXPORT_SYMBOL_GPL(gdsc_gx_do_nothing_enable);
+
+int gdsc_wait_for_collapse(void *priv)
+{
+   struct gdsc *sc = priv;
+   int ret;
+
+   ret = gdsc_poll_status(sc, GDSC_OFF, 50, 5);
+   WARN(ret, "%s status stuck at 'on'", sc->pd.name);
+   return ret;
+}
+EXPORT_SYMBOL_GPL(gdsc_wait_for_collapse);
diff --git a/drivers/clk/qcom/gdsc.h b/drivers/clk/qcom/gdsc.h
index ad313d7..d484bdb 100644
--- a/drivers/clk/qcom/gdsc.h
+++ b/drivers/clk/qcom/gdsc.h
@@ -12,6 +12,7 @@
 struct regmap;
 struct regulator;
 struct reset_controller_dev;
+struct qcom_reset_map;
 
 /**
  * struct gdsc - Globally Distributed Switch Controller
@@ -79,6 +80,7 @@ int gdsc_register(struct gdsc_desc *desc, struct 
reset_controller_dev *,
  struct regmap *);
 void gdsc_unregister(struct gdsc_desc *desc);
 int gdsc_gx_do_nothing_enable(struct generic_pm_domain *domain);
+int gdsc_wait_for_collapse(void *priv);
 #else
 static inline int gdsc_register(struct gdsc_desc *desc,
struct reset_controller_dev *rcdev,
@@ -88,5 +90,10 @@ static inline int gdsc_register(struct gdsc_desc *desc,
 }
 
 static inline void gdsc_unregister(struct gdsc_desc *desc) {};
+
+static int gdsc_wait_for_collapse(void *priv)
+{
+   return  -ENOSYS;
+}
 #endif /* CONFIG_QCOM_GDSC */
 #endif /* __QCOM_GDSC_H__ */
-- 
2.7.4



[PATCH v5 2/6] clk: qcom: Allow custom reset ops

2022-08-28 Thread Akhil P Oommen
Allow soc specific clk drivers to specify a custom reset operation. We
will use this in an upcoming patch to allow gpucc driver to specify a
differet reset operation for cx_gdsc.

Signed-off-by: Akhil P Oommen 
Reviewed-by: Dmitry Baryshkov 
---

(no changes since v3)

Changes in v3:
- Use pointer to const for "struct qcom_reset_ops" in qcom_reset_map (Krzysztof)

Changes in v2:
- Return error when a particular custom reset op is not implemented. (Dmitry)

 drivers/clk/qcom/reset.c | 27 +++
 drivers/clk/qcom/reset.h |  8 
 2 files changed, 35 insertions(+)

diff --git a/drivers/clk/qcom/reset.c b/drivers/clk/qcom/reset.c
index 819d194..b7ae4a3 100644
--- a/drivers/clk/qcom/reset.c
+++ b/drivers/clk/qcom/reset.c
@@ -13,6 +13,21 @@
 
 static int qcom_reset(struct reset_controller_dev *rcdev, unsigned long id)
 {
+   struct qcom_reset_controller *rst;
+   const struct qcom_reset_map *map;
+
+   rst = to_qcom_reset_controller(rcdev);
+   map = &rst->reset_map[id];
+
+   if (map->ops && map->ops->reset)
+   return map->ops->reset(map->priv);
+   /*
+* If custom ops is implemented but just not this callback, return
+* error
+*/
+   else if (map->ops)
+   return -EOPNOTSUPP;
+
rcdev->ops->assert(rcdev, id);
udelay(1);
rcdev->ops->deassert(rcdev, id);
@@ -28,6 +43,12 @@ qcom_reset_assert(struct reset_controller_dev *rcdev, 
unsigned long id)
 
rst = to_qcom_reset_controller(rcdev);
map = &rst->reset_map[id];
+
+   if (map->ops && map->ops->assert)
+   return map->ops->assert(map->priv);
+   else if (map->ops)
+   return -EOPNOTSUPP;
+
mask = BIT(map->bit);
 
return regmap_update_bits(rst->regmap, map->reg, mask, mask);
@@ -42,6 +63,12 @@ qcom_reset_deassert(struct reset_controller_dev *rcdev, 
unsigned long id)
 
rst = to_qcom_reset_controller(rcdev);
map = &rst->reset_map[id];
+
+   if (map->ops && map->ops->deassert)
+   return map->ops->deassert(map->priv);
+   else if (map->ops)
+   return -EOPNOTSUPP;
+
mask = BIT(map->bit);
 
return regmap_update_bits(rst->regmap, map->reg, mask, 0);
diff --git a/drivers/clk/qcom/reset.h b/drivers/clk/qcom/reset.h
index 2a08b5e..f3147eb 100644
--- a/drivers/clk/qcom/reset.h
+++ b/drivers/clk/qcom/reset.h
@@ -8,9 +8,17 @@
 
 #include 
 
+struct qcom_reset_ops {
+   int (*reset)(void *priv);
+   int (*assert)(void *priv);
+   int (*deassert)(void *priv);
+};
+
 struct qcom_reset_map {
unsigned int reg;
u8 bit;
+   const struct qcom_reset_ops *ops;
+   void *priv;
 };
 
 struct regmap;
-- 
2.7.4



[PATCH v5 0/6] clk/qcom: Support gdsc collapse polling using 'reset' interface

2022-08-28 Thread Akhil P Oommen


Some clients like adreno gpu driver would like to ensure that its gdsc
is collapsed at hardware during a gpu reset sequence. This is because it
has a votable gdsc which could be ON due to a vote from another subsystem
like tz, hyp etc or due to an internal hardware signal. To allow
this, gpucc driver can expose an interface to the client driver using
reset framework. Using this the client driver can trigger a polling within
the gdsc driver.

This series is rebased on top of linus's master branch.

Related discussion: https://patchwork.freedesktop.org/patch/493144/

Changes in v5:
- Nit: Remove a duplicate blank line (Krzysztof)

Changes in v4:
- Update gpu dt-binding schema
- Typo fix in commit text

Changes in v3:
- Use pointer to const for "struct qcom_reset_ops" in qcom_reset_map (Krzysztof)

Changes in v2:
- Return error when a particular custom reset op is not implemented. (Dmitry)

Akhil P Oommen (6):
  dt-bindings: clk: qcom: Support gpu cx gdsc reset
  clk: qcom: Allow custom reset ops
  clk: qcom: gdsc: Add a reset op to poll gdsc collapse
  clk: qcom: gpucc-sc7280: Add cx collapse reset support
  dt-bindings: drm/msm/gpu: Add optional resets
  arm64: dts: qcom: sc7280: Add Reset support for gpu

 .../devicetree/bindings/display/msm/gpu.yaml   |  6 +
 arch/arm64/boot/dts/qcom/sc7280.dtsi   |  3 +++
 drivers/clk/qcom/gdsc.c| 23 ++
 drivers/clk/qcom/gdsc.h|  7 ++
 drivers/clk/qcom/gpucc-sc7280.c| 10 
 drivers/clk/qcom/reset.c   | 27 ++
 drivers/clk/qcom/reset.h   |  8 +++
 include/dt-bindings/clock/qcom,gpucc-sc7280.h  |  3 +++
 8 files changed, 83 insertions(+), 4 deletions(-)

-- 
2.7.4



[PATCH] drm/mm: Reduce stack frame usage in __igt_reserve

2022-08-28 Thread Maíra Canal
The struct drm_mm is being allocated on the stack, which is causing the
following -Wframe-larger-than warning on ARM:

../drivers/gpu/drm/tests/drm_mm_test.c:344:12: error: stack frame size
(1064) exceeds limit (1024) in '__igt_reserve' [-Werror,-Wframe-larger-than]

static int __igt_reserve(struct kunit *test, unsigned int count, u64 size)
   ^
1 error generated.

So, fix this warning by dynamically allocating the struct drm_mm.

Fixes: fc8d29e298cf ("drm: selftest: convert drm_mm selftest to KUnit")
Reported-by: kernel test robot 
Signed-off-by: Maíra Canal 
---
 drivers/gpu/drm/tests/drm_mm_test.c | 33 -
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/tests/drm_mm_test.c 
b/drivers/gpu/drm/tests/drm_mm_test.c
index 1e2c1aa524bd..fbd8dcbc12ee 100644
--- a/drivers/gpu/drm/tests/drm_mm_test.c
+++ b/drivers/gpu/drm/tests/drm_mm_test.c
@@ -344,7 +344,7 @@ static bool check_reserve_boundaries(struct kunit *test, 
struct drm_mm *mm,
 static int __igt_reserve(struct kunit *test, unsigned int count, u64 size)
 {
DRM_RND_STATE(prng, random_seed);
-   struct drm_mm mm;
+   struct drm_mm *mm;
struct drm_mm_node tmp, *nodes, *node, *next;
unsigned int *order, n, m, o = 0;
int ret, err;
@@ -366,17 +366,20 @@ static int __igt_reserve(struct kunit *test, unsigned int 
count, u64 size)
nodes = vzalloc(array_size(count, sizeof(*nodes)));
KUNIT_ASSERT_TRUE(test, nodes);
 
+   mm = kunit_kzalloc(test, sizeof(struct drm_mm), GFP_KERNEL);
+   KUNIT_ASSERT_NOT_NULL(test, mm);
+
ret = -EINVAL;
-   drm_mm_init(&mm, 0, count * size);
+   drm_mm_init(mm, 0, count * size);
 
-   if (!check_reserve_boundaries(test, &mm, count, size))
+   if (!check_reserve_boundaries(test, mm, count, size))
goto out;
 
for (n = 0; n < count; n++) {
nodes[n].start = order[n] * size;
nodes[n].size = size;
 
-   err = drm_mm_reserve_node(&mm, &nodes[n]);
+   err = drm_mm_reserve_node(mm, &nodes[n]);
if (err) {
KUNIT_FAIL(test, "reserve failed, step %d, start 
%llu\n",
   n, nodes[n].start);
@@ -390,23 +393,23 @@ static int __igt_reserve(struct kunit *test, unsigned int 
count, u64 size)
goto out;
}
 
-   if (!expect_reserve_fail(test, &mm, &nodes[n]))
+   if (!expect_reserve_fail(test, mm, &nodes[n]))
goto out;
}
 
/* After random insertion the nodes should be in order */
-   if (!assert_continuous(test, &mm, size))
+   if (!assert_continuous(test, mm, size))
goto out;
 
/* Repeated use should then fail */
drm_random_reorder(order, count, &prng);
for (n = 0; n < count; n++) {
-   if (!expect_reserve_fail(test, &mm, set_node(&tmp, order[n] * 
size, 1)))
+   if (!expect_reserve_fail(test, mm, set_node(&tmp, order[n] * 
size, 1)))
goto out;
 
/* Remove and reinsert should work */
drm_mm_remove_node(&nodes[order[n]]);
-   err = drm_mm_reserve_node(&mm, &nodes[order[n]]);
+   err = drm_mm_reserve_node(mm, &nodes[order[n]]);
if (err) {
KUNIT_FAIL(test, "reserve failed, step %d, start 
%llu\n",
   n, nodes[n].start);
@@ -415,16 +418,16 @@ static int __igt_reserve(struct kunit *test, unsigned int 
count, u64 size)
}
}
 
-   if (!assert_continuous(test, &mm, size))
+   if (!assert_continuous(test, mm, size))
goto out;
 
/* Overlapping use should then fail */
for (n = 0; n < count; n++) {
-   if (!expect_reserve_fail(test, &mm, set_node(&tmp, 0, size * 
count)))
+   if (!expect_reserve_fail(test, mm, set_node(&tmp, 0, size * 
count)))
goto out;
}
for (n = 0; n < count; n++) {
-   if (!expect_reserve_fail(test, &mm, set_node(&tmp, size * n, 
size * (count - n
+   if (!expect_reserve_fail(test, mm, set_node(&tmp, size * n, 
size * (count - n
goto out;
}
 
@@ -437,7 +440,7 @@ static int __igt_reserve(struct kunit *test, unsigned int 
count, u64 size)
 
for (m = 0; m < n; m++) {
node = &nodes[order[(o + m) % count]];
-   err = drm_mm_reserve_node(&mm, node);
+   err = drm_mm_reserve_node(mm, node);
if (err) {
KUNIT_FAIL(test, "reserve failed, step %d/%d, 
start %llu\n",
   m, n, node->start);
@@ -448,15 +451,15 @@ static int __igt_reserve(struct kunit *test, unsigned int 
count, 

Re: [PATCH v1 32/35] drm/sun4i: tv: Convert to the new TV mode property

2022-08-28 Thread Noralf Trønnes



Den 29.07.2022 18.35, skrev Maxime Ripard:
> Now that the core can deal fine with analog TV modes, let's convert the
> sun4i TV driver to leverage those new features.
> 
> Signed-off-by: Maxime Ripard 
> 
> diff --git a/drivers/gpu/drm/sun4i/sun4i_tv.c 
> b/drivers/gpu/drm/sun4i/sun4i_tv.c
> index 74ff5ad6a8b9..bed52423776e 100644
> --- a/drivers/gpu/drm/sun4i/sun4i_tv.c
> +++ b/drivers/gpu/drm/sun4i/sun4i_tv.c

> @@ -586,8 +524,17 @@ static int sun4i_tv_bind(struct device *dev, struct 
> device *master,
>  
>   drm_connector_attach_encoder(&tv->connector, &tv->encoder);
>  
> + ret = drm_mode_create_tv_properties(drm,
> + DRM_MODE_TV_NORM_NTSC_M |
> + DRM_MODE_TV_NORM_PAL_B,
> + 0, NULL);
> + if (ret)
> + goto err_cleanup_connector;
> +

Looks like you have forgotten to attach the property?

Noralf.

>   return 0;
>  
> +err_cleanup_connector:
> + drm_connector_cleanup(&tv->connector);
>  err_cleanup_encoder:
>   drm_encoder_cleanup(&tv->encoder);
>  err_disable_clk:
> 


Re: [PATCH v1 34/35] drm/modes: Introduce the tv_mode property as a command-line option

2022-08-28 Thread Noralf Trønnes



Den 26.08.2022 08.46, skrev Maxime Ripard:
> On Thu, Aug 25, 2022 at 02:41:27PM +0200, Noralf Trønnes wrote:
>> Den 24.08.2022 17.45, skrev Maxime Ripard:
>>> Hi Noralf,
>>>
>>> On Sat, Aug 20, 2022 at 10:18:47PM +0200, Noralf Trønnes wrote:
 Den 29.07.2022 18.35, skrev Maxime Ripard:
> Our new tv mode option allows to specify the TV mode from a property.
> However, it can still be useful, for example to avoid any boot time
> artifact, to set that property directly from the kernel command line.
>
> Let's add some code to allow it, and some unit tests to exercise that 
> code.
>
> Signed-off-by: Maxime Ripard 
>

 In the subject it says "tv_mode property", but the property is called
 "tv norm", so the option should be tv_norm?
>>>
>>> Yeah... I don't know. mode is taken but it's obviously the best name. So
>>> I went with norm to avoid the (internal) conflict but I left mode for
>>> the user facing property.
>>>
>>> I'm not sure what's best here, or maybe we can pick another name entirely?
>>>
>>
>> Why not just call it "tv mode" or even better "TV Mode". The state
>> member can be called tv_mode, but the mode_config member will need a
>> temporary name until the "mode" property is removed. tv_tv_mode or maybe
>> connector_tv_mode?
> 
> Yeah, that seems like a good idea. Would legacy_tv_mode work for you?
> 

Oh yeah, renaming the "mode" property, that works fine.

Noralf.


[PATCH v3 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_xrgb2101010()

2022-08-28 Thread José Expósito
Extend the existing test cases to test the conversion from XRGB to
XRGB2101010.

In order to be able to call drm_fb_xrgb_to_xrgb2101010() when
compiling CONFIG_DRM_KMS_HELPER as a module export the symbol.

Tested-by: Maíra Canal 
Reviewed-by: David Gow 
Signed-off-by: José Expósito 
---
 drivers/gpu/drm/drm_format_helper.c   |  1 +
 .../gpu/drm/tests/drm_format_helper_test.c| 63 +++
 2 files changed, 64 insertions(+)

diff --git a/drivers/gpu/drm/drm_format_helper.c 
b/drivers/gpu/drm/drm_format_helper.c
index 56642816fdff..b9a9fea0f6f1 100644
--- a/drivers/gpu/drm/drm_format_helper.c
+++ b/drivers/gpu/drm/drm_format_helper.c
@@ -553,6 +553,7 @@ void drm_fb_xrgb_to_xrgb2101010(struct iosys_map *dst, 
const unsigned int *d
drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false,
drm_fb_xrgb_to_xrgb2101010_line);
 }
+EXPORT_SYMBOL(drm_fb_xrgb_to_xrgb2101010);
 
 static void drm_fb_xrgb_to_gray8_line(void *dbuf, const void *sbuf, 
unsigned int pixels)
 {
diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c 
b/drivers/gpu/drm/tests/drm_format_helper_test.c
index 08d08e7ab19a..d8536db4de1e 100644
--- a/drivers/gpu/drm/tests/drm_format_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
@@ -32,6 +32,11 @@ struct convert_to_rgb888_result {
const u8 expected[TEST_BUF_SIZE];
 };
 
+struct convert_to_xrgb2101010_result {
+   unsigned int dst_pitch;
+   const u32 expected[TEST_BUF_SIZE];
+};
+
 struct convert_xrgb_case {
const char *name;
unsigned int pitch;
@@ -40,6 +45,7 @@ struct convert_xrgb_case {
struct convert_to_rgb332_result rgb332_result;
struct convert_to_rgb565_result rgb565_result;
struct convert_to_rgb888_result rgb888_result;
+   struct convert_to_xrgb2101010_result xrgb2101010_result;
 };
 
 static struct convert_xrgb_case convert_xrgb_cases[] = {
@@ -61,6 +67,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] 
= {
.dst_pitch = 0,
.expected = { 0x00, 0x00, 0xFF },
},
+   .xrgb2101010_result = {
+   .dst_pitch = 0,
+   .expected = { 0x3FF0 },
+   },
},
{
.name = "single_pixel_clip_rectangle",
@@ -83,6 +93,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] 
= {
.dst_pitch = 0,
.expected = { 0x00, 0x00, 0xFF },
},
+   .xrgb2101010_result = {
+   .dst_pitch = 0,
+   .expected = { 0x3FF0 },
+   },
},
{
/* Well known colors: White, black, red, green, blue, magenta,
@@ -132,6 +146,15 @@ static struct convert_xrgb_case 
convert_xrgb_cases[] = {
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
},
},
+   .xrgb2101010_result = {
+   .dst_pitch = 0,
+   .expected = {
+   0x3FFF, 0x,
+   0x3FF0, 0x000FFC00,
+   0x03FF, 0x3FF003FF,
+   0x3C00, 0x000F,
+   },
+   },
},
{
/* Randomly picked colors. Full buffer within the clip area. */
@@ -175,6 +198,14 @@ static struct convert_xrgb_case 
convert_xrgb_cases[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
},
+   .xrgb2101010_result = {
+   .dst_pitch = 20,
+   .expected = {
+   0x03844672, 0x0444D414, 0x2A20300C, 0x, 
0x,
+   0x1B1705CD, 0x03844672, 0x0444D414, 0x, 
0x,
+   0x2A20300C, 0x1B1705CD, 0x03844672, 0x, 
0x,
+   },
+   },
},
 };
 
@@ -319,10 +350,42 @@ static void xrgb_to_rgb888_test(struct kunit *test)
KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);
 }
 
+static void xrgb_to_xrgb2101010_test(struct kunit *test)
+{
+   const struct convert_xrgb_case *params = test->param_value;
+   const struct convert_to_xrgb2101010_result *result = 
¶ms->xrgb2101010_result;
+   size_t dst_size;
+   __u32 *buf = NULL;
+   __u32 *xrgb = NULL;
+   struct iosys_map dst, src;
+
+   struct drm_framebuffer fb = {
+   .format = drm_format_info(DRM_FORMAT_XRGB),
+   .pitches = { params->pitch, 0, 0 },
+   };
+
+   dst_size = conversion_buf_size(DRM_FORMAT_XRGB2101010,
+  result->dst_pitch, ¶ms->c

[PATCH v3 3/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_gray8()

2022-08-28 Thread José Expósito
Extend the existing test cases to test the conversion from XRGB to
grayscale.

Tested-by: Maíra Canal 
Reviewed-by: David Gow 
Signed-off-by: José Expósito 
---
 .../gpu/drm/tests/drm_format_helper_test.c| 62 +++
 1 file changed, 62 insertions(+)

diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c 
b/drivers/gpu/drm/tests/drm_format_helper_test.c
index d8536db4de1e..2f548aa51a30 100644
--- a/drivers/gpu/drm/tests/drm_format_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
@@ -37,6 +37,11 @@ struct convert_to_xrgb2101010_result {
const u32 expected[TEST_BUF_SIZE];
 };
 
+struct convert_to_gray8_result {
+   unsigned int dst_pitch;
+   const u8 expected[TEST_BUF_SIZE];
+};
+
 struct convert_xrgb_case {
const char *name;
unsigned int pitch;
@@ -46,6 +51,7 @@ struct convert_xrgb_case {
struct convert_to_rgb565_result rgb565_result;
struct convert_to_rgb888_result rgb888_result;
struct convert_to_xrgb2101010_result xrgb2101010_result;
+   struct convert_to_gray8_result gray8_result;
 };
 
 static struct convert_xrgb_case convert_xrgb_cases[] = {
@@ -71,6 +77,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] 
= {
.dst_pitch = 0,
.expected = { 0x3FF0 },
},
+   .gray8_result = {
+   .dst_pitch = 0,
+   .expected = { 0x4C },
+   },
},
{
.name = "single_pixel_clip_rectangle",
@@ -97,6 +107,10 @@ static struct convert_xrgb_case 
convert_xrgb_cases[] = {
.dst_pitch = 0,
.expected = { 0x3FF0 },
},
+   .gray8_result = {
+   .dst_pitch = 0,
+   .expected = { 0x4C },
+   },
},
{
/* Well known colors: White, black, red, green, blue, magenta,
@@ -155,6 +169,15 @@ static struct convert_xrgb_case 
convert_xrgb_cases[] = {
0x3C00, 0x000F,
},
},
+   .gray8_result = {
+   .dst_pitch = 0,
+   .expected = {
+   0xFF, 0x00,
+   0x4C, 0x99,
+   0x19, 0x66,
+   0xE5, 0xB2,
+   },
+   },
},
{
/* Randomly picked colors. Full buffer within the clip area. */
@@ -206,6 +229,14 @@ static struct convert_xrgb_case 
convert_xrgb_cases[] = {
0x2A20300C, 0x1B1705CD, 0x03844672, 0x, 
0x,
},
},
+   .gray8_result = {
+   .dst_pitch = 5,
+   .expected = {
+   0x3C, 0x33, 0x34, 0x00, 0x00,
+   0x6F, 0x3C, 0x33, 0x00, 0x00,
+   0x34, 0x6F, 0x3C, 0x00, 0x00,
+   },
+   },
},
 };
 
@@ -381,11 +412,42 @@ static void xrgb_to_xrgb2101010_test(struct kunit 
*test)
KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);
 }
 
+static void xrgb_to_gray8_test(struct kunit *test)
+{
+   const struct convert_xrgb_case *params = test->param_value;
+   const struct convert_to_gray8_result *result = ¶ms->gray8_result;
+   size_t dst_size;
+   __u8 *buf = NULL;
+   __u32 *xrgb = NULL;
+   struct iosys_map dst, src;
+
+   struct drm_framebuffer fb = {
+   .format = drm_format_info(DRM_FORMAT_XRGB),
+   .pitches = { params->pitch, 0, 0 },
+   };
+
+   dst_size = conversion_buf_size(DRM_FORMAT_R8, result->dst_pitch,
+  ¶ms->clip);
+   KUNIT_ASSERT_GT(test, dst_size, 0);
+
+   buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
+   KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
+   iosys_map_set_vaddr(&dst, buf);
+
+   xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE);
+   KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb);
+   iosys_map_set_vaddr(&src, xrgb);
+
+   drm_fb_xrgb_to_gray8(&dst, &result->dst_pitch, &src, &fb, 
¶ms->clip);
+   KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);
+}
+
 static struct kunit_case drm_format_helper_test_cases[] = {
KUNIT_CASE_PARAM(xrgb_to_rgb332_test, convert_xrgb_gen_params),
KUNIT_CASE_PARAM(xrgb_to_rgb565_test, convert_xrgb_gen_params),
KUNIT_CASE_PARAM(xrgb_to_rgb888_test, convert_xrgb_gen_params),
KUNIT_CASE_PARAM(xrgb_to_xrgb2101010_test, 
convert_xrgb_gen_params),
+   KUNIT_CASE_PARAM(xrgb_to_gray8_test, convert_x

[PATCH v3 1/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb888()

2022-08-28 Thread José Expósito
Extend the existing test cases to test the conversion from XRGB to
RGB888.

Tested-by: Maíra Canal 
Reviewed-by: David Gow 
Signed-off-by: José Expósito 
---
 .../gpu/drm/tests/drm_format_helper_test.c| 65 +++
 1 file changed, 65 insertions(+)

diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c 
b/drivers/gpu/drm/tests/drm_format_helper_test.c
index 828487071796..08d08e7ab19a 100644
--- a/drivers/gpu/drm/tests/drm_format_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
@@ -27,6 +27,11 @@ struct convert_to_rgb565_result {
const u16 expected_swab[TEST_BUF_SIZE];
 };
 
+struct convert_to_rgb888_result {
+   unsigned int dst_pitch;
+   const u8 expected[TEST_BUF_SIZE];
+};
+
 struct convert_xrgb_case {
const char *name;
unsigned int pitch;
@@ -34,6 +39,7 @@ struct convert_xrgb_case {
const u32 xrgb[TEST_BUF_SIZE];
struct convert_to_rgb332_result rgb332_result;
struct convert_to_rgb565_result rgb565_result;
+   struct convert_to_rgb888_result rgb888_result;
 };
 
 static struct convert_xrgb_case convert_xrgb_cases[] = {
@@ -51,6 +57,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] 
= {
.expected = { 0xF800 },
.expected_swab = { 0x00F8 },
},
+   .rgb888_result = {
+   .dst_pitch = 0,
+   .expected = { 0x00, 0x00, 0xFF },
+   },
},
{
.name = "single_pixel_clip_rectangle",
@@ -69,6 +79,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] 
= {
.expected = { 0xF800 },
.expected_swab = { 0x00F8 },
},
+   .rgb888_result = {
+   .dst_pitch = 0,
+   .expected = { 0x00, 0x00, 0xFF },
+   },
},
{
/* Well known colors: White, black, red, green, blue, magenta,
@@ -109,6 +123,15 @@ static struct convert_xrgb_case 
convert_xrgb_cases[] = {
0xE0FF, 0xFF07,
},
},
+   .rgb888_result = {
+   .dst_pitch = 0,
+   .expected = {
+   0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00,
+   0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF,
+   0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
+   },
+   },
},
{
/* Randomly picked colors. Full buffer within the clip area. */
@@ -141,6 +164,17 @@ static struct convert_xrgb_case 
convert_xrgb_cases[] = {
0x00A8, 0x8E6B, 0x330A, 0x, 0x,
},
},
+   .rgb888_result = {
+   .dst_pitch = 15,
+   .expected = {
+   0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11, 0x03, 0x03, 
0xA8,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x73, 0x70, 0x6C, 0x9C, 0x44, 0x0E, 0x05, 0x4D, 
0x11,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x03, 0x03, 0xA8, 0x73, 0x70, 0x6C, 0x9C, 0x44, 
0x0E,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   },
+   },
},
 };
 
@@ -255,9 +289,40 @@ static void xrgb_to_rgb565_test(struct kunit *test)
KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected_swab, dst_size), 0);
 }
 
+static void xrgb_to_rgb888_test(struct kunit *test)
+{
+   const struct convert_xrgb_case *params = test->param_value;
+   const struct convert_to_rgb888_result *result = ¶ms->rgb888_result;
+   size_t dst_size;
+   __u8 *buf = NULL;
+   __u32 *xrgb = NULL;
+   struct iosys_map dst, src;
+
+   struct drm_framebuffer fb = {
+   .format = drm_format_info(DRM_FORMAT_XRGB),
+   .pitches = { params->pitch, 0, 0 },
+   };
+
+   dst_size = conversion_buf_size(DRM_FORMAT_RGB888, result->dst_pitch,
+  ¶ms->clip);
+   KUNIT_ASSERT_GT(test, dst_size, 0);
+
+   buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
+   KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
+   iosys_map_set_vaddr(&dst, buf);
+
+   xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE);
+   KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb);
+   iosys_map_set_vaddr(&src, xrgb);
+
+   drm_fb_xrgb_to_rgb888(&dst, &result->dst_pitch, &src, &fb, 
¶ms->clip);
+   KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);
+}
+
 static struct kunit_case drm_format_helper_test_cases[] = {

[PATCH v3 0/3] KUnit tests for RGB888, XRGB2101010 and grayscale

2022-08-28 Thread José Expósito
Hello everyone,

This series is a follow up on my work adding KUnit test to the XRGB
conversion functions. This time RGB888, XRGB2101010 and gray8 are added.

Best wishes,
Jose

v1 -> v2:

Tested-by: Maíra Canal 
Reviewed-by: David Gow 

v2 -> v3:

Export symbol drm_fb_xrgb_to_xrgb2101010()

José Expósito (3):
  drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb888()
  drm/format-helper: Add KUnit tests for
drm_fb_xrgb_to_xrgb2101010()
  drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_gray8()

 drivers/gpu/drm/drm_format_helper.c   |   1 +
 .../gpu/drm/tests/drm_format_helper_test.c| 190 ++
 2 files changed, 191 insertions(+)


base-commit: 61a9fa154d217c13eea90aa5bc635bc4b1fcb66e
-- 
2.25.1



[PATCH] drm/ssd130x: Replace simple display helpers with the atomic helpers

2022-08-28 Thread Javier Martinez Canillas
The simple display pipeline is a set of helpers that can be used by DRM
drivers to avoid dealing with all the needed components and just define
a few functions to operate a simple display device with one full-screen
scanout buffer feeding a single output.

But it is arguable that this provides the correct level of abstraction
for simple drivers, and recently some have been ported from using these
simple display helpers to use the regular atomic helpers instead.

The rationale for this is that the simple display pipeline helpers don't
hide that much of the DRM complexity, while adding an indirection layer
that conflates the concepts of CRTCs and planes. This makes the helpers
less flexible and harder to be reused among different graphics drivers.

Also, for simple drivers, using the full atomic helpers doesn't require
a lot of additional code. So adding a simple display pipeline layer may
not be worth it.

For these reasons, let's follow that trend and make ssd130x a plain DRM
driver that creates its own primary plane, CRTC, enconder and connector.

Suggested-by: Thomas Zimmermann 
Signed-off-by: Javier Martinez Canillas 
---

 drivers/gpu/drm/solomon/ssd130x.c | 258 +-
 drivers/gpu/drm/solomon/ssd130x.h |   9 +-
 2 files changed, 187 insertions(+), 80 deletions(-)

diff --git a/drivers/gpu/drm/solomon/ssd130x.c 
b/drivers/gpu/drm/solomon/ssd130x.c
index f87f5443e714..0ae17fcceb7c 100644
--- a/drivers/gpu/drm/solomon/ssd130x.c
+++ b/drivers/gpu/drm/solomon/ssd130x.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -564,61 +565,56 @@ static int ssd130x_fb_blit_rect(struct drm_framebuffer 
*fb, const struct iosys_m
return ret;
 }
 
-static int ssd130x_display_pipe_mode_valid(struct drm_simple_display_pipe 
*pipe,
-  const struct drm_display_mode *mode)
+static int ssd130x_primary_plane_helper_atomic_check(struct drm_plane *plane,
+struct drm_atomic_state 
*new_state)
 {
-   struct ssd130x_device *ssd130x = drm_to_ssd130x(pipe->crtc.dev);
+   struct drm_plane_state *new_plane_state = 
drm_atomic_get_new_plane_state(new_state, plane);
+   struct drm_crtc *new_crtc = new_plane_state->crtc;
+   struct drm_crtc_state *new_crtc_state = NULL;
 
-   if (mode->hdisplay != ssd130x->mode.hdisplay &&
-   mode->vdisplay != ssd130x->mode.vdisplay)
-   return MODE_ONE_SIZE;
-
-   if (mode->hdisplay != ssd130x->mode.hdisplay)
-   return MODE_ONE_WIDTH;
-
-   if (mode->vdisplay != ssd130x->mode.vdisplay)
-   return MODE_ONE_HEIGHT;
+   if (new_crtc)
+   new_crtc_state = drm_atomic_get_new_crtc_state(new_state, 
new_crtc);
 
-   return MODE_OK;
+   return drm_atomic_helper_check_plane_state(new_plane_state, 
new_crtc_state,
+  DRM_PLANE_NO_SCALING,
+  DRM_PLANE_NO_SCALING,
+  false, false);
 }
 
-static void ssd130x_display_pipe_enable(struct drm_simple_display_pipe *pipe,
-   struct drm_crtc_state *crtc_state,
-   struct drm_plane_state *plane_state)
+static void ssd130x_primary_plane_helper_atomic_update(struct drm_plane *plane,
+  struct drm_atomic_state 
*old_state)
 {
-   struct ssd130x_device *ssd130x = drm_to_ssd130x(pipe->crtc.dev);
+   struct drm_plane_state *plane_state = plane->state;
+   struct drm_plane_state *old_plane_state = 
drm_atomic_get_old_plane_state(old_state, plane);
struct drm_shadow_plane_state *shadow_plane_state = 
to_drm_shadow_plane_state(plane_state);
-   struct drm_device *drm = &ssd130x->drm;
-   int idx, ret;
+   struct drm_framebuffer *fb = plane_state->fb;
+   struct drm_device *drm = plane->dev;
+   struct drm_rect src_clip, dst_clip;
+   int idx;
 
-   ret = ssd130x_power_on(ssd130x);
-   if (ret)
+   if (!fb)
return;
 
-   ret = ssd130x_init(ssd130x);
-   if (ret)
-   goto out_power_off;
-
-   if (!drm_dev_enter(drm, &idx))
-   goto out_power_off;
+   if (!drm_atomic_helper_damage_merged(old_plane_state, plane_state, 
&src_clip))
+   return;
 
-   ssd130x_fb_blit_rect(plane_state->fb, &shadow_plane_state->data[0], 
&plane_state->dst);
+   dst_clip = plane_state->dst;
+   if (!drm_rect_intersect(&dst_clip, &src_clip))
+   return;
 
-   ssd130x_write_cmd(ssd130x, 1, SSD130X_DISPLAY_ON);
+   if (!drm_dev_enter(drm, &idx))
+   return;
 
-   backlight_enable(ssd130x->bl_dev);
+   ssd130x_fb_blit_rect(plane_state->fb, &shadow_plane_state->data[0], 
&dst_clip);
 
drm_dev_exit(idx);
-
-   r

Re: [PATCH v3] gpu/drm/bridge/cadence: avoid flush_scheduled_work() usage

2022-08-28 Thread Tetsuo Handa
No response since 2022-06-10. Can somebody take this patch?

On 2022/07/28 10:40, Tetsuo Handa wrote:
> Like commit c4f135d643823a86 ("workqueue: Wrap flush_workqueue() using a
> macro") says, flush_scheduled_work() is dangerous and will be forbidden.
> We are on the way for removing all flush_scheduled_work() callers from
> the kernel, and this patch is for removing flush_scheduled_work() call
>  from cadence driver.



Re: [PATCH v2 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_xrgb2101010()

2022-08-28 Thread kernel test robot
Hi "José,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on 61a9fa154d217c13eea90aa5bc635bc4b1fcb66e]

url:
https://github.com/intel-lab-lkp/linux/commits/Jos-Exp-sito/KUnit-tests-for-RGB888-XRGB2101010-and-grayscale/20220828-170347
base:   61a9fa154d217c13eea90aa5bc635bc4b1fcb66e
config: hexagon-randconfig-r014-20220828 
(https://download.01.org/0day-ci/archive/20220828/202208282022.9682were-...@intel.com/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 
a2100daf12fb980a29fd1a9c85ccf8eaaaf79730)
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# 
https://github.com/intel-lab-lkp/linux/commit/5b513d5c5cc6ccf62c7b8d72f431079041ce69d7
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review 
Jos-Exp-sito/KUnit-tests-for-RGB888-XRGB2101010-and-grayscale/20220828-170347
git checkout 5b513d5c5cc6ccf62c7b8d72f431079041ce69d7
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 
O=build_dir ARCH=hexagon SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot 

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "drm_fb_xrgb_to_xrgb2101010" 
>> [drivers/gpu/drm/tests/drm_format_helper_test.ko] undefined!

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp


[PATCH v2 3/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_gray8()

2022-08-28 Thread José Expósito
Extend the existing test cases to test the conversion from XRGB to
grayscale.

Tested-by: Maíra Canal 
Reviewed-by: David Gow 
Signed-off-by: José Expósito 
---
 .../gpu/drm/tests/drm_format_helper_test.c| 62 +++
 1 file changed, 62 insertions(+)

diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c 
b/drivers/gpu/drm/tests/drm_format_helper_test.c
index d8536db4de1e..2f548aa51a30 100644
--- a/drivers/gpu/drm/tests/drm_format_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
@@ -37,6 +37,11 @@ struct convert_to_xrgb2101010_result {
const u32 expected[TEST_BUF_SIZE];
 };
 
+struct convert_to_gray8_result {
+   unsigned int dst_pitch;
+   const u8 expected[TEST_BUF_SIZE];
+};
+
 struct convert_xrgb_case {
const char *name;
unsigned int pitch;
@@ -46,6 +51,7 @@ struct convert_xrgb_case {
struct convert_to_rgb565_result rgb565_result;
struct convert_to_rgb888_result rgb888_result;
struct convert_to_xrgb2101010_result xrgb2101010_result;
+   struct convert_to_gray8_result gray8_result;
 };
 
 static struct convert_xrgb_case convert_xrgb_cases[] = {
@@ -71,6 +77,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] 
= {
.dst_pitch = 0,
.expected = { 0x3FF0 },
},
+   .gray8_result = {
+   .dst_pitch = 0,
+   .expected = { 0x4C },
+   },
},
{
.name = "single_pixel_clip_rectangle",
@@ -97,6 +107,10 @@ static struct convert_xrgb_case 
convert_xrgb_cases[] = {
.dst_pitch = 0,
.expected = { 0x3FF0 },
},
+   .gray8_result = {
+   .dst_pitch = 0,
+   .expected = { 0x4C },
+   },
},
{
/* Well known colors: White, black, red, green, blue, magenta,
@@ -155,6 +169,15 @@ static struct convert_xrgb_case 
convert_xrgb_cases[] = {
0x3C00, 0x000F,
},
},
+   .gray8_result = {
+   .dst_pitch = 0,
+   .expected = {
+   0xFF, 0x00,
+   0x4C, 0x99,
+   0x19, 0x66,
+   0xE5, 0xB2,
+   },
+   },
},
{
/* Randomly picked colors. Full buffer within the clip area. */
@@ -206,6 +229,14 @@ static struct convert_xrgb_case 
convert_xrgb_cases[] = {
0x2A20300C, 0x1B1705CD, 0x03844672, 0x, 
0x,
},
},
+   .gray8_result = {
+   .dst_pitch = 5,
+   .expected = {
+   0x3C, 0x33, 0x34, 0x00, 0x00,
+   0x6F, 0x3C, 0x33, 0x00, 0x00,
+   0x34, 0x6F, 0x3C, 0x00, 0x00,
+   },
+   },
},
 };
 
@@ -381,11 +412,42 @@ static void xrgb_to_xrgb2101010_test(struct kunit 
*test)
KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);
 }
 
+static void xrgb_to_gray8_test(struct kunit *test)
+{
+   const struct convert_xrgb_case *params = test->param_value;
+   const struct convert_to_gray8_result *result = ¶ms->gray8_result;
+   size_t dst_size;
+   __u8 *buf = NULL;
+   __u32 *xrgb = NULL;
+   struct iosys_map dst, src;
+
+   struct drm_framebuffer fb = {
+   .format = drm_format_info(DRM_FORMAT_XRGB),
+   .pitches = { params->pitch, 0, 0 },
+   };
+
+   dst_size = conversion_buf_size(DRM_FORMAT_R8, result->dst_pitch,
+  ¶ms->clip);
+   KUNIT_ASSERT_GT(test, dst_size, 0);
+
+   buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
+   KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
+   iosys_map_set_vaddr(&dst, buf);
+
+   xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE);
+   KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb);
+   iosys_map_set_vaddr(&src, xrgb);
+
+   drm_fb_xrgb_to_gray8(&dst, &result->dst_pitch, &src, &fb, 
¶ms->clip);
+   KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);
+}
+
 static struct kunit_case drm_format_helper_test_cases[] = {
KUNIT_CASE_PARAM(xrgb_to_rgb332_test, convert_xrgb_gen_params),
KUNIT_CASE_PARAM(xrgb_to_rgb565_test, convert_xrgb_gen_params),
KUNIT_CASE_PARAM(xrgb_to_rgb888_test, convert_xrgb_gen_params),
KUNIT_CASE_PARAM(xrgb_to_xrgb2101010_test, 
convert_xrgb_gen_params),
+   KUNIT_CASE_PARAM(xrgb_to_gray8_test, convert_x

[PATCH v2 2/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_xrgb2101010()

2022-08-28 Thread José Expósito
Extend the existing test cases to test the conversion from XRGB to
XRGB2101010.

Tested-by: Maíra Canal 
Reviewed-by: David Gow 
Signed-off-by: José Expósito 
---
 .../gpu/drm/tests/drm_format_helper_test.c| 63 +++
 1 file changed, 63 insertions(+)

diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c 
b/drivers/gpu/drm/tests/drm_format_helper_test.c
index 08d08e7ab19a..d8536db4de1e 100644
--- a/drivers/gpu/drm/tests/drm_format_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
@@ -32,6 +32,11 @@ struct convert_to_rgb888_result {
const u8 expected[TEST_BUF_SIZE];
 };
 
+struct convert_to_xrgb2101010_result {
+   unsigned int dst_pitch;
+   const u32 expected[TEST_BUF_SIZE];
+};
+
 struct convert_xrgb_case {
const char *name;
unsigned int pitch;
@@ -40,6 +45,7 @@ struct convert_xrgb_case {
struct convert_to_rgb332_result rgb332_result;
struct convert_to_rgb565_result rgb565_result;
struct convert_to_rgb888_result rgb888_result;
+   struct convert_to_xrgb2101010_result xrgb2101010_result;
 };
 
 static struct convert_xrgb_case convert_xrgb_cases[] = {
@@ -61,6 +67,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] 
= {
.dst_pitch = 0,
.expected = { 0x00, 0x00, 0xFF },
},
+   .xrgb2101010_result = {
+   .dst_pitch = 0,
+   .expected = { 0x3FF0 },
+   },
},
{
.name = "single_pixel_clip_rectangle",
@@ -83,6 +93,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] 
= {
.dst_pitch = 0,
.expected = { 0x00, 0x00, 0xFF },
},
+   .xrgb2101010_result = {
+   .dst_pitch = 0,
+   .expected = { 0x3FF0 },
+   },
},
{
/* Well known colors: White, black, red, green, blue, magenta,
@@ -132,6 +146,15 @@ static struct convert_xrgb_case 
convert_xrgb_cases[] = {
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
},
},
+   .xrgb2101010_result = {
+   .dst_pitch = 0,
+   .expected = {
+   0x3FFF, 0x,
+   0x3FF0, 0x000FFC00,
+   0x03FF, 0x3FF003FF,
+   0x3C00, 0x000F,
+   },
+   },
},
{
/* Randomly picked colors. Full buffer within the clip area. */
@@ -175,6 +198,14 @@ static struct convert_xrgb_case 
convert_xrgb_cases[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
},
+   .xrgb2101010_result = {
+   .dst_pitch = 20,
+   .expected = {
+   0x03844672, 0x0444D414, 0x2A20300C, 0x, 
0x,
+   0x1B1705CD, 0x03844672, 0x0444D414, 0x, 
0x,
+   0x2A20300C, 0x1B1705CD, 0x03844672, 0x, 
0x,
+   },
+   },
},
 };
 
@@ -319,10 +350,42 @@ static void xrgb_to_rgb888_test(struct kunit *test)
KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);
 }
 
+static void xrgb_to_xrgb2101010_test(struct kunit *test)
+{
+   const struct convert_xrgb_case *params = test->param_value;
+   const struct convert_to_xrgb2101010_result *result = 
¶ms->xrgb2101010_result;
+   size_t dst_size;
+   __u32 *buf = NULL;
+   __u32 *xrgb = NULL;
+   struct iosys_map dst, src;
+
+   struct drm_framebuffer fb = {
+   .format = drm_format_info(DRM_FORMAT_XRGB),
+   .pitches = { params->pitch, 0, 0 },
+   };
+
+   dst_size = conversion_buf_size(DRM_FORMAT_XRGB2101010,
+  result->dst_pitch, ¶ms->clip);
+   KUNIT_ASSERT_GT(test, dst_size, 0);
+
+   buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
+   KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
+   iosys_map_set_vaddr(&dst, buf);
+
+   xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE);
+   KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb);
+   iosys_map_set_vaddr(&src, xrgb);
+
+   drm_fb_xrgb_to_xrgb2101010(&dst, &result->dst_pitch, &src, &fb, 
¶ms->clip);
+   buf = le32buf_to_cpu(test, buf, TEST_BUF_SIZE);
+   KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);
+}
+
 static struct kunit_case drm_format_helper_test_cases[] = {
KUNIT_CASE_PARAM(xrgb_to_rgb332_test, convert_xrgb_gen_params),
KUNIT_CASE_PARAM(xrgb_to_r

[PATCH v2 1/3] drm/format-helper: Add KUnit tests for drm_fb_xrgb8888_to_rgb888()

2022-08-28 Thread José Expósito
Extend the existing test cases to test the conversion from XRGB to
RGB888.

Tested-by: Maíra Canal 
Reviewed-by: David Gow 
Signed-off-by: José Expósito 
---
 .../gpu/drm/tests/drm_format_helper_test.c| 65 +++
 1 file changed, 65 insertions(+)

diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c 
b/drivers/gpu/drm/tests/drm_format_helper_test.c
index 828487071796..08d08e7ab19a 100644
--- a/drivers/gpu/drm/tests/drm_format_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
@@ -27,6 +27,11 @@ struct convert_to_rgb565_result {
const u16 expected_swab[TEST_BUF_SIZE];
 };
 
+struct convert_to_rgb888_result {
+   unsigned int dst_pitch;
+   const u8 expected[TEST_BUF_SIZE];
+};
+
 struct convert_xrgb_case {
const char *name;
unsigned int pitch;
@@ -34,6 +39,7 @@ struct convert_xrgb_case {
const u32 xrgb[TEST_BUF_SIZE];
struct convert_to_rgb332_result rgb332_result;
struct convert_to_rgb565_result rgb565_result;
+   struct convert_to_rgb888_result rgb888_result;
 };
 
 static struct convert_xrgb_case convert_xrgb_cases[] = {
@@ -51,6 +57,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] 
= {
.expected = { 0xF800 },
.expected_swab = { 0x00F8 },
},
+   .rgb888_result = {
+   .dst_pitch = 0,
+   .expected = { 0x00, 0x00, 0xFF },
+   },
},
{
.name = "single_pixel_clip_rectangle",
@@ -69,6 +79,10 @@ static struct convert_xrgb_case convert_xrgb_cases[] 
= {
.expected = { 0xF800 },
.expected_swab = { 0x00F8 },
},
+   .rgb888_result = {
+   .dst_pitch = 0,
+   .expected = { 0x00, 0x00, 0xFF },
+   },
},
{
/* Well known colors: White, black, red, green, blue, magenta,
@@ -109,6 +123,15 @@ static struct convert_xrgb_case 
convert_xrgb_cases[] = {
0xE0FF, 0xFF07,
},
},
+   .rgb888_result = {
+   .dst_pitch = 0,
+   .expected = {
+   0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00,
+   0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF,
+   0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
+   },
+   },
},
{
/* Randomly picked colors. Full buffer within the clip area. */
@@ -141,6 +164,17 @@ static struct convert_xrgb_case 
convert_xrgb_cases[] = {
0x00A8, 0x8E6B, 0x330A, 0x, 0x,
},
},
+   .rgb888_result = {
+   .dst_pitch = 15,
+   .expected = {
+   0x9C, 0x44, 0x0E, 0x05, 0x4D, 0x11, 0x03, 0x03, 
0xA8,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x73, 0x70, 0x6C, 0x9C, 0x44, 0x0E, 0x05, 0x4D, 
0x11,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x03, 0x03, 0xA8, 0x73, 0x70, 0x6C, 0x9C, 0x44, 
0x0E,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   },
+   },
},
 };
 
@@ -255,9 +289,40 @@ static void xrgb_to_rgb565_test(struct kunit *test)
KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected_swab, dst_size), 0);
 }
 
+static void xrgb_to_rgb888_test(struct kunit *test)
+{
+   const struct convert_xrgb_case *params = test->param_value;
+   const struct convert_to_rgb888_result *result = ¶ms->rgb888_result;
+   size_t dst_size;
+   __u8 *buf = NULL;
+   __u32 *xrgb = NULL;
+   struct iosys_map dst, src;
+
+   struct drm_framebuffer fb = {
+   .format = drm_format_info(DRM_FORMAT_XRGB),
+   .pitches = { params->pitch, 0, 0 },
+   };
+
+   dst_size = conversion_buf_size(DRM_FORMAT_RGB888, result->dst_pitch,
+  ¶ms->clip);
+   KUNIT_ASSERT_GT(test, dst_size, 0);
+
+   buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
+   KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
+   iosys_map_set_vaddr(&dst, buf);
+
+   xrgb = le32buf_to_cpu(test, params->xrgb, TEST_BUF_SIZE);
+   KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb);
+   iosys_map_set_vaddr(&src, xrgb);
+
+   drm_fb_xrgb_to_rgb888(&dst, &result->dst_pitch, &src, &fb, 
¶ms->clip);
+   KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);
+}
+
 static struct kunit_case drm_format_helper_test_cases[] = {

[PATCH v2 0/3] KUnit tests for RGB888, XRGB2101010 and grayscale

2022-08-28 Thread José Expósito
Hello everyone,

This series is a follow up on my work adding KUnit test to the XRGB
conversion functions. This time RGB888, XRGB2101010 and gray8 are added.

Best wishes,
Jose

v1 -> v2:

Tested-by: Maíra Canal 
Reviewed-by: David Gow 

José Expósito (3):
  drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb888()
  drm/format-helper: Add KUnit tests for
drm_fb_xrgb_to_xrgb2101010()
  drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_gray8()

 .../gpu/drm/tests/drm_format_helper_test.c| 190 ++
 1 file changed, 190 insertions(+)


base-commit: 61a9fa154d217c13eea90aa5bc635bc4b1fcb66e
-- 
2.25.1



Re: [PATCH 0/3] KUnit tests for RGB888, XRGB2101010 and grayscale

2022-08-28 Thread José Expósito
On Tue, Aug 16, 2022 at 10:37:49AM -0300, Maíra Canal wrote:
> Hi José,
> 
> Tested the whole series on UML, x86, i386 and PPC. All looks fine!
> 
> Tested-by: Maíra Canal 
> 
> Best Regards,
> - Maíra Canal
> 
> On 8/16/22 07:29, José Expósito wrote:
> > Hello everyone,
> > 
> > This series is a follow up on my work adding KUnit test to the XRGB
> > conversion functions. This time RGB888, XRGB2101010 and gray8 are added.
> > 
> > Best wishes,
> > Jose
> > 
> > José Expósito (3):
> >drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_rgb888()
> >drm/format-helper: Add KUnit tests for
> >  drm_fb_xrgb_to_xrgb2101010()
> >drm/format-helper: Add KUnit tests for drm_fb_xrgb_to_gray8()
> > 
> >   .../gpu/drm/tests/drm_format_helper_test.c| 190 ++
> >   1 file changed, 190 insertions(+)
> > 

Thanks a lot for testing the series Maíra and for the code review
David.

I added a note to my ToDo list to use KUNIT_EXPECT_MEMEQ once it gets
merged.

For the moment, I'll send v2 :)

Best wishes,
Jose


Re: [RFC] drm/kms: control display brightness through drm_connector properties

2022-08-28 Thread Hans de Goede
Hi,

On 8/25/22 23:40, Yusuf Khan wrote:
> Perhaps the Kconfig modifications could be postponed to stage 2
> since for people running distros that suddenly decide to disable
> /sys/class/backlight/ it may be impractical for them to recompile
> their kernels and such.

In step 1, the Kconfig option is just there to select the default
setting of the kernel commandline parameter. So when a distro
defaults that to disabling /sys/class/backlight (or making it
read-only) then the user can simple override it on the kernel
commandline. No re-compiling of kernels needed.

> Also stage 2 should probably take ~2 decades
> until it comes into being, for reference fbdev SPECIFIC drivers
> were removed from fedora just recently and because of that there
> were some issues with some user's systems. I understand it's much
> easier to change from the /sys/class/backlight/ interface to the one
> you have proposed than to change from fbdev to KMS though.

Yes chances are we will be stuck with the old sysfs API for a long
time to come. Note that since in some cases the backlight driver
is not part of the GPU driver, but rather part of e.g. dell-laptop
we will need the backlight-device abstraction in the kernel going
forward regardless of what happens with /sys/class/backlight.

So the cleanup resulting from removing it completely will not
be that big as the backlight-device abstraction will stay it
will only be the sysfs interface which disappears.

As such just having a kernel cmdline parameter to hide/unhide
it might be good enough.

Regards,

Hans



> 
> On Thu, Aug 25, 2022 at 3:27 AM Hans de Goede  > wrote:
> 
> Hi Yusuf,
> 
> On 8/24/22 04:18, Yusuf Khan wrote:
> > Sorry for the necro-bump, I hadnt seen this go by
> 
> No problem.
> 
> > My main concern with this proposal is the phasing out of 
> /sys/class/backlight/.
> > Currently on the user(user, not userland) level its easier for me to 
> just modify
> > the file and be done with it. xbacklight doesnt tell me when its failed,
> > brightnessctl doesnt make assumptions about what device is what, and
> > other brightness setting applications ive seen are much worse than them.
> > Someone needs to create a userland application thats less inconvenient
> > than `echo`ing into /sys/class/backlight with a name that human beings 
> can
> > actually remember before I stop using the sysfs, perhaps "setbrightness"
> > could be the binary's name? Also I dont think its wise to disable or 
> make it
> > read only though Kconfig as older apps may depend on it, maybe add a
> > kernel param that disables the old interface so bigger distros can 
> pressure
> > app makers into changing the interface? As a big draw for DDC/CI is that
> > many displays support it as a way to change brightness(even if you arent
> > doing anything special that would break the old interface) perhaps it 
> could
> > be an early adopter to that kernel parameter?
> 
> Right, so deprecating the /sys/class/backlight API definitely is the last
> step and probably is years away. As you say hiding / making it read-only
> should probably be a kernel-parameter at first, with maybe a Kconfig
> option to set the default. So the depcration would go like this:
> 
> 1. Add:
> A kernel-parameter to allow hiding or read-only-ing the sysfs interface +
> Kconfig to select the default +
> dev_warn_once() when the old API is used
> 
> 2. (much later) Drop the Kconfig option and default to hiding/read-only
> 
> 3. (even later) Maybe completely remove the sysfs interface?
> 
> Note the hiding vs read-only thing is to be decided. ATM I'm rather more
> focused on getting the new API in place then on deprecating the old one :)
> 
> Anyways I fully agree that we need to do the deprecation carefully and
> slowly. This is likely going to take multiple years and then some ...
> 
> Regards,
> 
> Hans
> 
> 
> 
> >
> > On Thu, Apr 7, 2022 at 10:39 AM Hans de Goede    >> wrote:
> >
> >     As discussed already several times in the past:
> >      https://www.x.org/wiki/Events/XDC2014/XDC2014GoedeBacklight/ 
>  
>  >
> >      
> https://lore.kernel.org/all/4b17ba08-39f3-57dd-5aad-d37d844b0...@linux.intel.com/
>  
> 
>  
>   
> >
> >
> >     The current userspace API for brightness control offered by
> >     /sys/class/backligh