Re: [PATCH v2 2/2] drm: bridge: adv7511: Add support for ADV7535

2019-08-20 Thread Togorean, Bogdan
On Tue, 2019-08-20 at 10:53 +0200, Daniel Vetter wrote:
> [External]
> 
> On Mon, Aug 19, 2019 at 12:46:16PM +0200, Sam Ravnborg wrote:
> > Hi Bogdan.
> > 
> > > > >   adv7533_detach_dsi(adv7511);
> > > > >   i2c_unregister_device(adv7511->i2c_cec);
> > > > >   if (adv7511->cec_clk)
> > > > > @@ -1266,8 +1278,9 @@ static const struct i2c_device_id
> > > > > adv7511_i2c_ids[] = {
> > > > >   { "adv7511", ADV7511 },
> > > > >   { "adv7511w", ADV7511 },
> > > > >   { "adv7513", ADV7511 },
> > > > > -#ifdef CONFIG_DRM_I2C_ADV7533
> > > > > +#ifdef CONFIG_DRM_I2C_ADV753x
> > > > >   { "adv7533", ADV7533 },
> > > > > + { "adv7535", ADV7535 },
> > > > >  #endif
> > > > 
> > > > This ifdef may not be needed??
> > > > If we did not get this type we will not look it up.
> > > But if we have defined in DT adv7533/5 device but
> > > CONFIG_DRM_I2C_ADV753x not selected probe will fail with ENODEV.
> > > That
> > > would be ok?
> > 
> > What do we gain from this complexity in the end.
> > Why not let the driver always support all variants.
> > 
> > If this result in a simpler driver, and less choices in Kconfig
> > then it is a win-win.
> 
> Yeah in general we don't Kconfig within drivers in drm to disable
> specific
> code-paths. It's not worth the pain.
Ack,
Thank you for clarification. Will remove in V3.
> -Daniel


linux-next: manual merge of the iommu tree with the drm-misc tree

2019-08-20 Thread Stephen Rothwell
Hi all,

Today's linux-next merge of the iommu tree got a conflict in:

  drivers/gpu/drm/panfrost/panfrost_mmu.c

between commit:

  187d2929206e ("drm/panfrost: Add support for GPU heap allocations")

from the drm-misc tree and commit:

  a2d3a382d6c6 ("iommu/io-pgtable: Pass struct iommu_iotlb_gather to ->unmap()")

from the iommu tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc drivers/gpu/drm/panfrost/panfrost_mmu.c
index 842bdd7cf6be,6e8145c36e93..
--- a/drivers/gpu/drm/panfrost/panfrost_mmu.c
+++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c
@@@ -310,18 -222,18 +310,18 @@@ void panfrost_mmu_unmap(struct panfrost
size_t unmapped_page;
size_t pgsize = get_pgsize(iova, len - unmapped_len);
  
 -  unmapped_page = ops->unmap(ops, iova, pgsize, NULL);
 -  if (!unmapped_page)
 -  break;
 -
 -  iova += unmapped_page;
 -  unmapped_len += unmapped_page;
 +  if (ops->iova_to_phys(ops, iova)) {
-   unmapped_page = ops->unmap(ops, iova, pgsize);
++  unmapped_page = ops->unmap(ops, iova, pgsize, NULL);
 +  WARN_ON(unmapped_page != pgsize);
 +  }
 +  iova += pgsize;
 +  unmapped_len += pgsize;
}
  
 -  mmu_hw_do_operation(pfdev, 0, bo->node.start << PAGE_SHIFT,
 +  mmu_hw_do_operation(pfdev, bo->mmu, bo->node.start << PAGE_SHIFT,
bo->node.size << PAGE_SHIFT, AS_COMMAND_FLUSH_PT);
  
 -  mutex_unlock(>mmu->lock);
 +  mutex_unlock(>mmu->lock);
  
pm_runtime_mark_last_busy(pfdev->dev);
pm_runtime_put_autosuspend(pfdev->dev);
@@@ -330,184 -242,35 +330,192 @@@
  
  static void mmu_tlb_inv_context_s1(void *cookie)
  {
 -  struct panfrost_device *pfdev = cookie;
 +  struct panfrost_file_priv *priv = cookie;
  
 -  mmu_hw_do_operation(pfdev, 0, 0, ~0UL, AS_COMMAND_FLUSH_MEM);
 +  mmu_hw_do_operation(priv->pfdev, >mmu, 0, ~0UL, 
AS_COMMAND_FLUSH_MEM);
  }
  
- static void mmu_tlb_inv_range_nosync(unsigned long iova, size_t size,
-size_t granule, bool leaf, void *cookie)
- {}
- 
  static void mmu_tlb_sync_context(void *cookie)
  {
//struct panfrost_device *pfdev = cookie;
// TODO: Wait 1000 GPU cycles for HW_ISSUE_6367/T60X
  }
  
- static const struct iommu_gather_ops mmu_tlb_ops = {
+ static void mmu_tlb_flush_walk(unsigned long iova, size_t size, size_t 
granule,
+  void *cookie)
+ {
+   mmu_tlb_sync_context(cookie);
+ }
+ 
+ static void mmu_tlb_flush_leaf(unsigned long iova, size_t size, size_t 
granule,
+  void *cookie)
+ {
+   mmu_tlb_sync_context(cookie);
+ }
+ 
+ static const struct iommu_flush_ops mmu_tlb_ops = {
.tlb_flush_all  = mmu_tlb_inv_context_s1,
-   .tlb_add_flush  = mmu_tlb_inv_range_nosync,
-   .tlb_sync   = mmu_tlb_sync_context,
+   .tlb_flush_walk = mmu_tlb_flush_walk,
+   .tlb_flush_leaf = mmu_tlb_flush_leaf,
  };
  
 +int panfrost_mmu_pgtable_alloc(struct panfrost_file_priv *priv)
 +{
 +  struct panfrost_mmu *mmu = >mmu;
 +  struct panfrost_device *pfdev = priv->pfdev;
 +
 +  mutex_init(>lock);
 +  INIT_LIST_HEAD(>list);
 +  mmu->as = -1;
 +
 +  mmu->pgtbl_cfg = (struct io_pgtable_cfg) {
 +  .pgsize_bitmap  = SZ_4K | SZ_2M,
 +  .ias= FIELD_GET(0xff, pfdev->features.mmu_features),
 +  .oas= FIELD_GET(0xff00, 
pfdev->features.mmu_features),
 +  .tlb= _tlb_ops,
 +  .iommu_dev  = pfdev->dev,
 +  };
 +
 +  mmu->pgtbl_ops = alloc_io_pgtable_ops(ARM_MALI_LPAE, >pgtbl_cfg,
 +priv);
 +  if (!mmu->pgtbl_ops)
 +  return -EINVAL;
 +
 +  return 0;
 +}
 +
 +void panfrost_mmu_pgtable_free(struct panfrost_file_priv *priv)
 +{
 +  struct panfrost_device *pfdev = priv->pfdev;
 +  struct panfrost_mmu *mmu = >mmu;
 +
 +  spin_lock(>as_lock);
 +  if (mmu->as >= 0) {
 +  clear_bit(mmu->as, >as_alloc_mask);
 +  clear_bit(mmu->as, >as_in_use_mask);
 +  list_del(>list);
 +  }
 +  spin_unlock(>as_lock);
 +
 +  free_io_pgtable_ops(mmu->pgtbl_ops);
 +}
 +
 +static struct drm_mm_node *addr_to_drm_mm_node(struct panfrost_device *pfdev, 
int as, u64 addr)
 +{
 +  struct drm_mm_node *node = NULL;
 +  u64 offset = addr >> PAGE_SHIFT;
 +  struct panfrost_mmu *mmu;
 +
 + 

[PATCH v2 1/4] video/logo: remove unneeded *.o pattern from clean-files

2019-08-20 Thread Masahiro Yamada
The pattern *.o is cleaned up globally by the top Makefile.

Signed-off-by: Masahiro Yamada 
---

Changes in v2: None

 drivers/video/logo/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/logo/Makefile b/drivers/video/logo/Makefile
index 228a89b9bdd1..10b75ce3ce09 100644
--- a/drivers/video/logo/Makefile
+++ b/drivers/video/logo/Makefile
@@ -56,4 +56,4 @@ $(obj)/%_gray256.c: $(src)/%_gray256.pgm $(pnmtologo) FORCE
$(call if_changed,logo)
 
 # Files generated that shall be removed upon make clean
-clean-files := *.o *_mono.c *_vga16.c *_clut224.c *_gray256.c
+clean-files := *_mono.c *_vga16.c *_clut224.c *_gray256.c
-- 
2.17.1



[PATCH v2 2/4] video/logo: do not generate unneeded logo C files

2019-08-20 Thread Masahiro Yamada
Currently, all the logo C files are generated irrespective of the
CONFIG options. Adding them to extra-y is wrong. What we need to do
here is to add them to 'targets' so that if_changed works properly.

Files listed in 'targets' are cleaned, so clean-files is unneeded.

Signed-off-by: Masahiro Yamada 
---

Changes in v2:
  - Fix commit log

 drivers/video/logo/Makefile | 21 ++---
 1 file changed, 2 insertions(+), 19 deletions(-)

diff --git a/drivers/video/logo/Makefile b/drivers/video/logo/Makefile
index 10b75ce3ce09..16f60c1e1766 100644
--- a/drivers/video/logo/Makefile
+++ b/drivers/video/logo/Makefile
@@ -18,23 +18,6 @@ obj-$(CONFIG_SPU_BASE)   += 
logo_spe_clut224.o
 
 # How to generate logo's
 
-# Use logo-cfiles to retrieve list of .c files to be built
-logo-cfiles = $(notdir $(patsubst %.$(2), %.c, \
-  $(wildcard $(srctree)/$(src)/*$(1).$(2
-
-
-# Mono logos
-extra-y += $(call logo-cfiles,_mono,pbm)
-
-# VGA16 logos
-extra-y += $(call logo-cfiles,_vga16,ppm)
-
-# 224 Logos
-extra-y += $(call logo-cfiles,_clut224,ppm)
-
-# Gray 256
-extra-y += $(call logo-cfiles,_gray256,pgm)
-
 pnmtologo := scripts/pnmtologo
 
 # Create commands like "pnmtologo -t mono -n logo_mac_mono -o ..."
@@ -55,5 +38,5 @@ $(obj)/%_clut224.c: $(src)/%_clut224.ppm $(pnmtologo) FORCE
 $(obj)/%_gray256.c: $(src)/%_gray256.pgm $(pnmtologo) FORCE
$(call if_changed,logo)
 
-# Files generated that shall be removed upon make clean
-clean-files := *_mono.c *_vga16.c *_clut224.c *_gray256.c
+# generated C files
+targets += *_mono.c *_vga16.c *_clut224.c *_gray256.c
-- 
2.17.1



[PATCH v2 0/4] video/logo: various fix and cleanups of drivers/video/logo/Makefile

2019-08-20 Thread Masahiro Yamada
Changes in v2:
  - Fix commit log

Masahiro Yamada (4):
  video/logo: remove unneeded *.o pattern from clean-files
  video/logo: do not generate unneeded logo C files
  video/logo: simplify cmd_logo
  video/logo: move pnmtologo tool to drivers/video/logo/ from scripts/

 drivers/video/logo/.gitignore   |  1 +
 drivers/video/logo/Makefile | 36 -
 {scripts => drivers/video/logo}/pnmtologo.c |  0
 scripts/.gitignore  |  1 -
 scripts/Makefile|  2 --
 5 files changed, 8 insertions(+), 32 deletions(-)
 rename {scripts => drivers/video/logo}/pnmtologo.c (100%)

-- 
2.17.1



[PATCH v2 3/4] video/logo: simplify cmd_logo

2019-08-20 Thread Masahiro Yamada
Shorten the code. It still works in the same way.

Signed-off-by: Masahiro Yamada 
---

Changes in v2: None

 drivers/video/logo/Makefile | 13 -
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/video/logo/Makefile b/drivers/video/logo/Makefile
index 16f60c1e1766..7d672d40bf01 100644
--- a/drivers/video/logo/Makefile
+++ b/drivers/video/logo/Makefile
@@ -22,20 +22,15 @@ pnmtologo := scripts/pnmtologo
 
 # Create commands like "pnmtologo -t mono -n logo_mac_mono -o ..."
 quiet_cmd_logo = LOGO$@
-   cmd_logo = $(pnmtologo) \
-   -t $(patsubst $*_%,%,$(notdir $(basename $<))) \
-   -n $(notdir $(basename $<)) -o $@ $<
+  cmd_logo = $(pnmtologo) -t $(lastword $(subst _, ,$*)) -n $* -o $@ $<
 
-$(obj)/%_mono.c: $(src)/%_mono.pbm $(pnmtologo) FORCE
+$(obj)/%.c: $(src)/%.pbm $(pnmtologo) FORCE
$(call if_changed,logo)
 
-$(obj)/%_vga16.c: $(src)/%_vga16.ppm $(pnmtologo) FORCE
+$(obj)/%.c: $(src)/%.ppm $(pnmtologo) FORCE
$(call if_changed,logo)
 
-$(obj)/%_clut224.c: $(src)/%_clut224.ppm $(pnmtologo) FORCE
-   $(call if_changed,logo)
-
-$(obj)/%_gray256.c: $(src)/%_gray256.pgm $(pnmtologo) FORCE
+$(obj)/%.c: $(src)/%.pgm $(pnmtologo) FORCE
$(call if_changed,logo)
 
 # generated C files
-- 
2.17.1



[PATCH v2 4/4] video/logo: move pnmtologo tool to drivers/video/logo/ from scripts/

2019-08-20 Thread Masahiro Yamada
This tool is only used by drivers/video/logo/Makefile. No reason to
keep it in scripts/.

Signed-off-by: Masahiro Yamada 
---

Changes in v2: None

 drivers/video/logo/.gitignore   |  1 +
 drivers/video/logo/Makefile | 10 +-
 {scripts => drivers/video/logo}/pnmtologo.c |  0
 scripts/.gitignore  |  1 -
 scripts/Makefile|  2 --
 5 files changed, 6 insertions(+), 8 deletions(-)
 rename {scripts => drivers/video/logo}/pnmtologo.c (100%)

diff --git a/drivers/video/logo/.gitignore b/drivers/video/logo/.gitignore
index e48355f538fa..9dda1b26b2e4 100644
--- a/drivers/video/logo/.gitignore
+++ b/drivers/video/logo/.gitignore
@@ -5,3 +5,4 @@
 *_vga16.c
 *_clut224.c
 *_gray256.c
+pnmtologo
diff --git a/drivers/video/logo/Makefile b/drivers/video/logo/Makefile
index 7d672d40bf01..bcda657493a4 100644
--- a/drivers/video/logo/Makefile
+++ b/drivers/video/logo/Makefile
@@ -18,19 +18,19 @@ obj-$(CONFIG_SPU_BASE)  += 
logo_spe_clut224.o
 
 # How to generate logo's
 
-pnmtologo := scripts/pnmtologo
+hostprogs-y := pnmtologo
 
 # Create commands like "pnmtologo -t mono -n logo_mac_mono -o ..."
 quiet_cmd_logo = LOGO$@
-  cmd_logo = $(pnmtologo) -t $(lastword $(subst _, ,$*)) -n $* -o $@ $<
+  cmd_logo = $(obj)/pnmtologo -t $(lastword $(subst _, ,$*)) -n $* -o $@ $<
 
-$(obj)/%.c: $(src)/%.pbm $(pnmtologo) FORCE
+$(obj)/%.c: $(src)/%.pbm $(obj)/pnmtologo FORCE
$(call if_changed,logo)
 
-$(obj)/%.c: $(src)/%.ppm $(pnmtologo) FORCE
+$(obj)/%.c: $(src)/%.ppm $(obj)/pnmtologo FORCE
$(call if_changed,logo)
 
-$(obj)/%.c: $(src)/%.pgm $(pnmtologo) FORCE
+$(obj)/%.c: $(src)/%.pgm $(obj)/pnmtologo FORCE
$(call if_changed,logo)
 
 # generated C files
diff --git a/scripts/pnmtologo.c b/drivers/video/logo/pnmtologo.c
similarity index 100%
rename from scripts/pnmtologo.c
rename to drivers/video/logo/pnmtologo.c
diff --git a/scripts/.gitignore b/scripts/.gitignore
index 17f8cef88fa8..4aa1806c59c2 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -4,7 +4,6 @@
 bin2c
 conmakehash
 kallsyms
-pnmtologo
 unifdef
 recordmcount
 sortextable
diff --git a/scripts/Makefile b/scripts/Makefile
index 16bcb8087899..709df809f892 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -4,7 +4,6 @@
 # the kernel for the build process.
 # ---
 # kallsyms:  Find all symbols in vmlinux
-# pnmttologo:Convert pnm files to logo files
 # conmakehash:   Create chartable
 # conmakehash:  Create arrays for initializing the kernel console tables
 
@@ -12,7 +11,6 @@ HOST_EXTRACFLAGS += -I$(srctree)/tools/include
 
 hostprogs-$(CONFIG_BUILD_BIN2C)  += bin2c
 hostprogs-$(CONFIG_KALLSYMS) += kallsyms
-hostprogs-$(CONFIG_LOGO) += pnmtologo
 hostprogs-$(CONFIG_VT)   += conmakehash
 hostprogs-$(BUILD_C_RECORDMCOUNT) += recordmcount
 hostprogs-$(CONFIG_BUILDTIME_EXTABLE_SORT) += sortextable
-- 
2.17.1



Re: [PATCH 2/4] video/logo: fix unneeded generation of font C files

2019-08-20 Thread Masahiro Yamada
On Wed, Aug 21, 2019 at 12:56 PM Masahiro Yamada
 wrote:

I will replace 'font' -> 'logo'.
(My brain was corrupted.)



> Currently, all the font C files are generated irrespective of CONFIG
> options. Adding them to extra-y is wrong. What we need to do here is
> to add them to 'targets' so that if_changed works properly.
>
> All files listed in 'targets' are cleaned, so clean-files is unneeded.
>
> Signed-off-by: Masahiro Yamada 
> ---
>
>  drivers/video/logo/Makefile | 21 ++---
>  1 file changed, 2 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/video/logo/Makefile b/drivers/video/logo/Makefile
> index 10b75ce3ce09..16f60c1e1766 100644
> --- a/drivers/video/logo/Makefile
> +++ b/drivers/video/logo/Makefile
> @@ -18,23 +18,6 @@ obj-$(CONFIG_SPU_BASE)   += 
> logo_spe_clut224.o
>
>  # How to generate logo's
>
> -# Use logo-cfiles to retrieve list of .c files to be built
> -logo-cfiles = $(notdir $(patsubst %.$(2), %.c, \
> -  $(wildcard $(srctree)/$(src)/*$(1).$(2
> -
> -
> -# Mono logos
> -extra-y += $(call logo-cfiles,_mono,pbm)
> -
> -# VGA16 logos
> -extra-y += $(call logo-cfiles,_vga16,ppm)
> -
> -# 224 Logos
> -extra-y += $(call logo-cfiles,_clut224,ppm)
> -
> -# Gray 256
> -extra-y += $(call logo-cfiles,_gray256,pgm)
> -
>  pnmtologo := scripts/pnmtologo
>
>  # Create commands like "pnmtologo -t mono -n logo_mac_mono -o ..."
> @@ -55,5 +38,5 @@ $(obj)/%_clut224.c: $(src)/%_clut224.ppm $(pnmtologo) FORCE
>  $(obj)/%_gray256.c: $(src)/%_gray256.pgm $(pnmtologo) FORCE
> $(call if_changed,logo)
>
> -# Files generated that shall be removed upon make clean
> -clean-files := *_mono.c *_vga16.c *_clut224.c *_gray256.c
> +# generated C files
> +targets += *_mono.c *_vga16.c *_clut224.c *_gray256.c
> --
> 2.17.1
>


-- 
Best Regards
Masahiro Yamada


[PATCH 1/4] video/logo: remove unneeded *.o pattern from clean-files

2019-08-20 Thread Masahiro Yamada
The pattern *.o is cleaned up globally by the top Makefile.

Signed-off-by: Masahiro Yamada 
---

 drivers/video/logo/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/logo/Makefile b/drivers/video/logo/Makefile
index 228a89b9bdd1..10b75ce3ce09 100644
--- a/drivers/video/logo/Makefile
+++ b/drivers/video/logo/Makefile
@@ -56,4 +56,4 @@ $(obj)/%_gray256.c: $(src)/%_gray256.pgm $(pnmtologo) FORCE
$(call if_changed,logo)
 
 # Files generated that shall be removed upon make clean
-clean-files := *.o *_mono.c *_vga16.c *_clut224.c *_gray256.c
+clean-files := *_mono.c *_vga16.c *_clut224.c *_gray256.c
-- 
2.17.1



[PATCH 2/4] video/logo: fix unneeded generation of font C files

2019-08-20 Thread Masahiro Yamada
Currently, all the font C files are generated irrespective of CONFIG
options. Adding them to extra-y is wrong. What we need to do here is
to add them to 'targets' so that if_changed works properly.

All files listed in 'targets' are cleaned, so clean-files is unneeded.

Signed-off-by: Masahiro Yamada 
---

 drivers/video/logo/Makefile | 21 ++---
 1 file changed, 2 insertions(+), 19 deletions(-)

diff --git a/drivers/video/logo/Makefile b/drivers/video/logo/Makefile
index 10b75ce3ce09..16f60c1e1766 100644
--- a/drivers/video/logo/Makefile
+++ b/drivers/video/logo/Makefile
@@ -18,23 +18,6 @@ obj-$(CONFIG_SPU_BASE)   += 
logo_spe_clut224.o
 
 # How to generate logo's
 
-# Use logo-cfiles to retrieve list of .c files to be built
-logo-cfiles = $(notdir $(patsubst %.$(2), %.c, \
-  $(wildcard $(srctree)/$(src)/*$(1).$(2
-
-
-# Mono logos
-extra-y += $(call logo-cfiles,_mono,pbm)
-
-# VGA16 logos
-extra-y += $(call logo-cfiles,_vga16,ppm)
-
-# 224 Logos
-extra-y += $(call logo-cfiles,_clut224,ppm)
-
-# Gray 256
-extra-y += $(call logo-cfiles,_gray256,pgm)
-
 pnmtologo := scripts/pnmtologo
 
 # Create commands like "pnmtologo -t mono -n logo_mac_mono -o ..."
@@ -55,5 +38,5 @@ $(obj)/%_clut224.c: $(src)/%_clut224.ppm $(pnmtologo) FORCE
 $(obj)/%_gray256.c: $(src)/%_gray256.pgm $(pnmtologo) FORCE
$(call if_changed,logo)
 
-# Files generated that shall be removed upon make clean
-clean-files := *_mono.c *_vga16.c *_clut224.c *_gray256.c
+# generated C files
+targets += *_mono.c *_vga16.c *_clut224.c *_gray256.c
-- 
2.17.1



[PATCH 0/4] video/logo: various fix and cleanups of drivers/video/logo/Makefile

2019-08-20 Thread Masahiro Yamada




Masahiro Yamada (4):
  video/logo: remove unneeded *.o pattern from clean-files
  video/logo: fix unneeded generation of font C files
  video/logo: simplify cmd_logo
  video/logo: move pnmtologo tool to drivers/video/logo/ from scripts/

 drivers/video/logo/.gitignore   |  1 +
 drivers/video/logo/Makefile | 36 -
 {scripts => drivers/video/logo}/pnmtologo.c |  0
 scripts/.gitignore  |  1 -
 scripts/Makefile|  2 --
 5 files changed, 8 insertions(+), 32 deletions(-)
 rename {scripts => drivers/video/logo}/pnmtologo.c (100%)

-- 
2.17.1



[PATCH 3/4] video/logo: simplify cmd_logo

2019-08-20 Thread Masahiro Yamada
Shorten the code. It still works in the same way.

Signed-off-by: Masahiro Yamada 
---

 drivers/video/logo/Makefile | 13 -
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/video/logo/Makefile b/drivers/video/logo/Makefile
index 16f60c1e1766..7d672d40bf01 100644
--- a/drivers/video/logo/Makefile
+++ b/drivers/video/logo/Makefile
@@ -22,20 +22,15 @@ pnmtologo := scripts/pnmtologo
 
 # Create commands like "pnmtologo -t mono -n logo_mac_mono -o ..."
 quiet_cmd_logo = LOGO$@
-   cmd_logo = $(pnmtologo) \
-   -t $(patsubst $*_%,%,$(notdir $(basename $<))) \
-   -n $(notdir $(basename $<)) -o $@ $<
+  cmd_logo = $(pnmtologo) -t $(lastword $(subst _, ,$*)) -n $* -o $@ $<
 
-$(obj)/%_mono.c: $(src)/%_mono.pbm $(pnmtologo) FORCE
+$(obj)/%.c: $(src)/%.pbm $(pnmtologo) FORCE
$(call if_changed,logo)
 
-$(obj)/%_vga16.c: $(src)/%_vga16.ppm $(pnmtologo) FORCE
+$(obj)/%.c: $(src)/%.ppm $(pnmtologo) FORCE
$(call if_changed,logo)
 
-$(obj)/%_clut224.c: $(src)/%_clut224.ppm $(pnmtologo) FORCE
-   $(call if_changed,logo)
-
-$(obj)/%_gray256.c: $(src)/%_gray256.pgm $(pnmtologo) FORCE
+$(obj)/%.c: $(src)/%.pgm $(pnmtologo) FORCE
$(call if_changed,logo)
 
 # generated C files
-- 
2.17.1



[Bug 111448] [AMD TAHITI XT] IO_PAGE_FAULT

2019-08-20 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=111448

--- Comment #2 from Sylvain BERTRAND  ---
Created attachment 145108
  --> https://bugs.freedesktop.org/attachment.cgi?id=145108=edit
xorg

-- 
You are receiving this mail because:
You are the assignee for the bug.___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[Bug 111448] [AMD TAHITI XT] IO_PAGE_FAULT

2019-08-20 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=111448

--- Comment #1 from Sylvain BERTRAND  ---
Created attachment 145107
  --> https://bugs.freedesktop.org/attachment.cgi?id=145107=edit
dmesg

-- 
You are receiving this mail because:
You are the assignee for the bug.___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[Bug 111448] [AMD TAHITI XT] IO_PAGE_FAULT

2019-08-20 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=111448

Bug ID: 111448
   Summary: [AMD TAHITI XT] IO_PAGE_FAULT
   Product: DRI
   Version: DRI git
  Hardware: x86-64 (AMD64)
OS: Linux (All)
Status: NEW
  Severity: normal
  Priority: medium
 Component: DRM/AMDgpu
  Assignee: dri-devel@lists.freedesktop.org
  Reporter: sylvain.bertr...@gmail.com

Updated my gfx stack this week, and in the kernel log I get tons of
IO_PAGE_FAULT . Everything git from last sunday/monday.
linux amd-staging-drm-next 6c7a8d5c0772d8a389997cd5e35e8fa83f830f41
drm 14922551aa33e7592d2421cc89cf20a860a65310
llvm c81cf445a3132cf48fbe8f75f0314cbd346d87ab
mesa c550d367a747472ee71ed4c99e210174730aa82b
xserver aed62f8fbea3f618f97ee0105b2d430c8cddf8f5
xf86-video-amdgpu e6fce59a071220967fcd4e2c9e4a262c72870761

-- 
You are receiving this mail because:
You are the assignee for the bug.___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[Bug 111432] [bisected][tonga] Boot failures on agd5f's drm-next branch

2019-08-20 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=111432

--- Comment #7 from Mike Lothian  ---
That's it booting again, thanks

-- 
You are receiving this mail because:
You are the assignee for the bug.___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v2] drm: Bump encoder limit from 32 to 64

2019-08-20 Thread Lyude Paul
Assuming that GPUs would never have even close to 32 separate video
encoders is quite honestly a pretty reasonable assumption. Unfortunately
we do not live in a reasonable world, as it looks like it is actually
possible to find devices that will create more drm_encoder objects then
this. Case in point: the ThinkPad P71's discrete GPU, which exposes 1
eDP port and 5 DP ports. On the P71, nouveau attempts to create one
encoder for the eDP port, and two encoders for each DP++/USB-C port
along with 4 MST encoders for each DP port. This comes out to 35
different encoders. Unfortunately, this can't really be optimized to
make less encoders either.

So, what if we bumped the limit to 64? Unfortunately this has one very
awkward drawback: we already expose 32-bit bitmasks for encoders to
userspace in drm_encoder->possible_clones. Yikes. While cloning is still
(rarely) used in certain modern video hardware, it's mostly used in
situations where memory bandwidth is so limited that it's not possible
to scan out from 2 CRTCs at once.

So, let's try to compromise here: allow encoders with indexes <32 to
have non-zero values in drm_encoder->possible_clones, and don't allow
encoders with higher indexes to set drm_encoder->possible_clones to a
non-zero value. This allows us to avoid breaking UAPI and keep things
working sanely for hardware which still uses cloning, while still being
able to bump up the encoder limit.

This also fixes driver probing for nouveau on the ThinkPad P71.

Changes since v1:
* Move index+possible_clones check out of drm_encoder_init() and into
  drm_encoder_register_all(), since encoder->possible_clones can get
  changed any time before registration - Daniel Vetter
* Update the commit message a bit to accurately reflect modern day usage
  of hardware cloning, which as Daniel Stone pointed out is apparently a
  thing

Signed-off-by: Lyude Paul 
Cc: nouv...@lists.freedesktop.org
---
 drivers/gpu/drm/drm_atomic.c  |  2 +-
 drivers/gpu/drm/drm_encoder.c | 12 ++--
 include/drm/drm_crtc.h|  2 +-
 include/drm/drm_encoder.h | 20 +++-
 4 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 419381abbdd1..27ce988ef0cc 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -392,7 +392,7 @@ static void drm_atomic_crtc_print_state(struct drm_printer 
*p,
drm_printf(p, "\tcolor_mgmt_changed=%d\n", state->color_mgmt_changed);
drm_printf(p, "\tplane_mask=%x\n", state->plane_mask);
drm_printf(p, "\tconnector_mask=%x\n", state->connector_mask);
-   drm_printf(p, "\tencoder_mask=%x\n", state->encoder_mask);
+   drm_printf(p, "\tencoder_mask=%llx\n", state->encoder_mask);
drm_printf(p, "\tmode: " DRM_MODE_FMT "\n", DRM_MODE_ARG(>mode));
 
if (crtc->funcs->atomic_print_state)
diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c
index 7fb47b7b8b44..9d443b45ebba 100644
--- a/drivers/gpu/drm/drm_encoder.c
+++ b/drivers/gpu/drm/drm_encoder.c
@@ -71,6 +71,14 @@ int drm_encoder_register_all(struct drm_device *dev)
int ret = 0;
 
drm_for_each_encoder(encoder, dev) {
+   /*
+* Since possible_clones has been exposed to userspace as a
+* 32bit bitmask, we don't allow creating encoders with an
+* index >=32 which are capable of cloning
+*/
+   if (WARN_ON(encoder->index >= 32 && encoder->possible_clones))
+   return -EINVAL;
+
if (encoder->funcs->late_register)
ret = encoder->funcs->late_register(encoder);
if (ret)
@@ -112,8 +120,8 @@ int drm_encoder_init(struct drm_device *dev,
 {
int ret;
 
-   /* encoder index is used with 32bit bitmasks */
-   if (WARN_ON(dev->mode_config.num_encoder >= 32))
+   /* encoder index is used with 64bit bitmasks */
+   if (WARN_ON(dev->mode_config.num_encoder >= 64))
return -EINVAL;
 
ret = drm_mode_object_add(dev, >base, DRM_MODE_OBJECT_ENCODER);
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 7d14c11bdc0a..fd0b2438c3d5 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -210,7 +210,7 @@ struct drm_crtc_state {
 * @encoder_mask: Bitmask of drm_encoder_mask(encoder) of encoders
 * attached to this CRTC.
 */
-   u32 encoder_mask;
+   u64 encoder_mask;
 
/**
 * @adjusted_mode:
diff --git a/include/drm/drm_encoder.h b/include/drm/drm_encoder.h
index 70cfca03d812..3f9cb65694e1 100644
--- a/include/drm/drm_encoder.h
+++ b/include/drm/drm_encoder.h
@@ -159,7 +159,15 @@ struct drm_encoder {
 * encoders can be used in a cloned configuration, they both should have
 * each another bits set.
 *
-* In reality almost every driver gets this wrong.
+* In reality 

Re: [PATCH v13 00/18] kunit: introduce KUnit, the Linux kernel unit testing framework

2019-08-20 Thread shuah

On 8/20/19 5:23 PM, Brendan Higgins wrote:

On Tue, Aug 20, 2019 at 2:26 PM Brendan Higgins
 wrote:


On Tue, Aug 20, 2019 at 12:08 PM shuah  wrote:


On 8/20/19 12:24 PM, Brendan Higgins wrote:

On Tue, Aug 20, 2019 at 11:24:45AM -0600, shuah wrote:

On 8/13/19 11:50 PM, Brendan Higgins wrote:

## TL;DR

This revision addresses comments from Stephen and Bjorn Helgaas. Most
changes are pretty minor stuff that doesn't affect the API in anyway.
One significant change, however, is that I added support for freeing
kunit_resource managed resources before the test case is finished via
kunit_resource_destroy(). Additionally, Bjorn pointed out that I broke
KUnit on certain configurations (like the default one for x86, whoops).

Based on Stephen's feedback on the previous change, I think we are
pretty close. I am not expecting any significant changes from here on
out.



Hi Brendan,

I found checkpatch errors in one or two patches. Can you fix those and
send v14.


Hi Shuah,

Are you refering to the following errors?

ERROR: Macros with complex values should be enclosed in parentheses
#144: FILE: include/kunit/test.h:456:
+#define KUNIT_BINARY_CLASS \
+   kunit_binary_assert, KUNIT_INIT_BINARY_ASSERT_STRUCT

ERROR: Macros with complex values should be enclosed in parentheses
#146: FILE: include/kunit/test.h:458:
+#define KUNIT_BINARY_PTR_CLASS \
+   kunit_binary_ptr_assert, KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT

These values should *not* be in parentheses. I am guessing checkpatch is
getting confused and thinks that these are complex expressions, when
they are not.

I ignored the errors since I figured checkpatch was complaining
erroneously.

I could refactor the code to remove these macros entirely, but I think
the code is cleaner with them.



Please do. I am not veru sure what value these macros add.


Alright, I will have something for you later today.


I just sent a new revision with the fix.

Cheers



Thanks Brendan. I will get them in.

-- Shuah


Re: [PATCH v13 00/18] kunit: introduce KUnit, the Linux kernel unit testing framework

2019-08-20 Thread Brendan Higgins
On Tue, Aug 20, 2019 at 2:26 PM Brendan Higgins
 wrote:
>
> On Tue, Aug 20, 2019 at 12:08 PM shuah  wrote:
> >
> > On 8/20/19 12:24 PM, Brendan Higgins wrote:
> > > On Tue, Aug 20, 2019 at 11:24:45AM -0600, shuah wrote:
> > >> On 8/13/19 11:50 PM, Brendan Higgins wrote:
> > >>> ## TL;DR
> > >>>
> > >>> This revision addresses comments from Stephen and Bjorn Helgaas. Most
> > >>> changes are pretty minor stuff that doesn't affect the API in anyway.
> > >>> One significant change, however, is that I added support for freeing
> > >>> kunit_resource managed resources before the test case is finished via
> > >>> kunit_resource_destroy(). Additionally, Bjorn pointed out that I broke
> > >>> KUnit on certain configurations (like the default one for x86, whoops).
> > >>>
> > >>> Based on Stephen's feedback on the previous change, I think we are
> > >>> pretty close. I am not expecting any significant changes from here on
> > >>> out.
> > >>>
> > >>
> > >> Hi Brendan,
> > >>
> > >> I found checkpatch errors in one or two patches. Can you fix those and
> > >> send v14.
> > >
> > > Hi Shuah,
> > >
> > > Are you refering to the following errors?
> > >
> > > ERROR: Macros with complex values should be enclosed in parentheses
> > > #144: FILE: include/kunit/test.h:456:
> > > +#define KUNIT_BINARY_CLASS \
> > > +   kunit_binary_assert, KUNIT_INIT_BINARY_ASSERT_STRUCT
> > >
> > > ERROR: Macros with complex values should be enclosed in parentheses
> > > #146: FILE: include/kunit/test.h:458:
> > > +#define KUNIT_BINARY_PTR_CLASS \
> > > +   kunit_binary_ptr_assert, KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT
> > >
> > > These values should *not* be in parentheses. I am guessing checkpatch is
> > > getting confused and thinks that these are complex expressions, when
> > > they are not.
> > >
> > > I ignored the errors since I figured checkpatch was complaining
> > > erroneously.
> > >
> > > I could refactor the code to remove these macros entirely, but I think
> > > the code is cleaner with them.
> > >
> >
> > Please do. I am not veru sure what value these macros add.
>
> Alright, I will have something for you later today.

I just sent a new revision with the fix.

Cheers
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v14 11/18] kunit: test: add the concept of assertions

2019-08-20 Thread Brendan Higgins
Add support for assertions which are like expectations except the test
terminates if the assertion is not satisfied.

The idea with assertions is that you use them to state all the
preconditions for your test. Logically speaking, these are the premises
of the test case, so if a premise isn't true, there is no point in
continuing the test case because there are no conclusions that can be
drawn without the premises. Whereas, the expectation is the thing you
are trying to prove. It is not used universally in x-unit style test
frameworks, but I really like it as a convention.  You could still
express the idea of a premise using the above idiom, but I think
KUNIT_ASSERT_* states the intended idea perfectly.

Signed-off-by: Brendan Higgins 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Logan Gunthorpe 
Reviewed-by: Stephen Boyd 
---
 include/kunit/test.h   | 284 -
 kunit/string-stream-test.c |   2 +-
 kunit/test-test.c  |   7 +-
 3 files changed, 284 insertions(+), 9 deletions(-)

diff --git a/include/kunit/test.h b/include/kunit/test.h
index 390ce02f717b6..db3e7787d8ed6 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -86,9 +86,10 @@ struct kunit;
  * @name: the name of the test case.
  *
  * A test case is a function with the signature, ``void (*)(struct kunit *)``
- * that makes expectations (see KUNIT_EXPECT_TRUE()) about code under test. 
Each
- * test case is associated with a  kunit_suite and will be run after the
- * suite's init function and followed by the suite's exit function.
+ * that makes expectations and assertions (see KUNIT_EXPECT_TRUE() and
+ * KUNIT_ASSERT_TRUE()) about code under test. Each test case is associated 
with
+ * a  kunit_suite and will be run after the suite's init function and
+ * followed by the suite's exit function.
  *
  * A test case should be static and should only be created with the 
KUNIT_CASE()
  * macro; additionally, every array of test cases should be terminated with an
@@ -1201,4 +1202,281 @@ do {
   \
fmt,   \
##__VA_ARGS__)
 
+#define KUNIT_ASSERT_FAILURE(test, fmt, ...) \
+   KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__)
+
+/**
+ * KUNIT_ASSERT_TRUE() - Sets an assertion that @condition is true.
+ * @test: The test context object.
+ * @condition: an arbitrary boolean expression. The test fails and aborts when
+ * this does not evaluate to true.
+ *
+ * This and assertions of the form `KUNIT_ASSERT_*` will cause the test case to
+ * fail *and immediately abort* when the specified condition is not met. Unlike
+ * an expectation failure, it will prevent the test case from continuing to 
run;
+ * this is otherwise known as an *assertion failure*.
+ */
+#define KUNIT_ASSERT_TRUE(test, condition) \
+   KUNIT_TRUE_ASSERTION(test, KUNIT_ASSERTION, condition)
+
+#define KUNIT_ASSERT_TRUE_MSG(test, condition, fmt, ...)  \
+   KUNIT_TRUE_MSG_ASSERTION(test, \
+KUNIT_ASSERTION,  \
+condition,\
+fmt,  \
+##__VA_ARGS__)
+
+/**
+ * KUNIT_ASSERT_FALSE() - Sets an assertion that @condition is false.
+ * @test: The test context object.
+ * @condition: an arbitrary boolean expression.
+ *
+ * Sets an assertion that the value that @condition evaluates to is false. This
+ * is the same as KUNIT_EXPECT_FALSE(), except it causes an assertion failure
+ * (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
+ */
+#define KUNIT_ASSERT_FALSE(test, condition) \
+   KUNIT_FALSE_ASSERTION(test, KUNIT_ASSERTION, condition)
+
+#define KUNIT_ASSERT_FALSE_MSG(test, condition, fmt, ...) \
+   KUNIT_FALSE_MSG_ASSERTION(test,\
+ KUNIT_ASSERTION, \
+ condition,   \
+ fmt, \
+ ##__VA_ARGS__)
+
+/**
+ * KUNIT_ASSERT_EQ() - Sets an assertion that @left and @right are equal.
+ * @test: The test context object.
+ * @left: an arbitrary expression that evaluates to a primitive C type.
+ * @right: an arbitrary expression that evaluates to a primitive C type.
+ *
+ * Sets an assertion that the values that @left and @right evaluate to are
+ * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
+ * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
+ */
+#define KUNIT_ASSERT_EQ(test, left, right) \
+   

[PATCH v14 10/18] kunit: test: add tests for kunit test abort

2019-08-20 Thread Brendan Higgins
Add KUnit tests for the KUnit test abort mechanism (see preceding
commit). Add tests both for general try catch mechanism as well as
non-architecture specific mechanism.

Signed-off-by: Brendan Higgins 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Logan Gunthorpe 
Reviewed-by: Stephen Boyd 
---
 kunit/Makefile|   3 +-
 kunit/test-test.c | 106 ++
 2 files changed, 108 insertions(+), 1 deletion(-)
 create mode 100644 kunit/test-test.c

diff --git a/kunit/Makefile b/kunit/Makefile
index c9176c9c578c6..769d9402b5d3a 100644
--- a/kunit/Makefile
+++ b/kunit/Makefile
@@ -3,6 +3,7 @@ obj-$(CONFIG_KUNIT) +=  test.o \
assert.o \
try-catch.o
 
-obj-$(CONFIG_KUNIT_TEST) +=string-stream-test.o
+obj-$(CONFIG_KUNIT_TEST) +=test-test.o \
+   string-stream-test.o
 
 obj-$(CONFIG_KUNIT_EXAMPLE_TEST) +=example-test.o
diff --git a/kunit/test-test.c b/kunit/test-test.c
new file mode 100644
index 0..06d34d36b1038
--- /dev/null
+++ b/kunit/test-test.c
@@ -0,0 +1,106 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * KUnit test for core test infrastructure.
+ *
+ * Copyright (C) 2019, Google LLC.
+ * Author: Brendan Higgins 
+ */
+#include 
+
+struct kunit_try_catch_test_context {
+   struct kunit_try_catch *try_catch;
+   bool function_called;
+};
+
+static void kunit_test_successful_try(void *data)
+{
+   struct kunit *test = data;
+   struct kunit_try_catch_test_context *ctx = test->priv;
+
+   ctx->function_called = true;
+}
+
+static void kunit_test_no_catch(void *data)
+{
+   struct kunit *test = data;
+
+   KUNIT_FAIL(test, "Catch should not be called\n");
+}
+
+static void kunit_test_try_catch_successful_try_no_catch(struct kunit *test)
+{
+   struct kunit_try_catch_test_context *ctx = test->priv;
+   struct kunit_try_catch *try_catch = ctx->try_catch;
+
+   kunit_try_catch_init(try_catch,
+test,
+kunit_test_successful_try,
+kunit_test_no_catch);
+   kunit_try_catch_run(try_catch, test);
+
+   KUNIT_EXPECT_TRUE(test, ctx->function_called);
+}
+
+static void kunit_test_unsuccessful_try(void *data)
+{
+   struct kunit *test = data;
+   struct kunit_try_catch_test_context *ctx = test->priv;
+   struct kunit_try_catch *try_catch = ctx->try_catch;
+
+   kunit_try_catch_throw(try_catch);
+   KUNIT_FAIL(test, "This line should never be reached\n");
+}
+
+static void kunit_test_catch(void *data)
+{
+   struct kunit *test = data;
+   struct kunit_try_catch_test_context *ctx = test->priv;
+
+   ctx->function_called = true;
+}
+
+static void kunit_test_try_catch_unsuccessful_try_does_catch(struct kunit 
*test)
+{
+   struct kunit_try_catch_test_context *ctx = test->priv;
+   struct kunit_try_catch *try_catch = ctx->try_catch;
+
+   kunit_try_catch_init(try_catch,
+test,
+kunit_test_unsuccessful_try,
+kunit_test_catch);
+   kunit_try_catch_run(try_catch, test);
+
+   KUNIT_EXPECT_TRUE(test, ctx->function_called);
+}
+
+static int kunit_try_catch_test_init(struct kunit *test)
+{
+   struct kunit_try_catch_test_context *ctx;
+
+   ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
+   if (!ctx)
+   return -ENOMEM;
+
+   test->priv = ctx;
+
+   ctx->try_catch = kunit_kmalloc(test,
+  sizeof(*ctx->try_catch),
+  GFP_KERNEL);
+   if (!ctx->try_catch)
+   return -ENOMEM;
+
+   return 0;
+}
+
+static struct kunit_case kunit_try_catch_test_cases[] = {
+   KUNIT_CASE(kunit_test_try_catch_successful_try_no_catch),
+   KUNIT_CASE(kunit_test_try_catch_unsuccessful_try_does_catch),
+   {}
+};
+
+static struct kunit_suite kunit_try_catch_test_suite = {
+   .name = "kunit-try-catch-test",
+   .init = kunit_try_catch_test_init,
+   .test_cases = kunit_try_catch_test_cases,
+};
+kunit_test_suite(kunit_try_catch_test_suite);
-- 
2.23.0.rc1.153.gdeed80330f-goog



[PATCH v14 07/18] kunit: test: add initial tests

2019-08-20 Thread Brendan Higgins
Add a test for string stream along with a simpler example.

Signed-off-by: Brendan Higgins 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Logan Gunthorpe 
Reviewed-by: Stephen Boyd 
---
 kunit/Kconfig  | 21 +
 kunit/Makefile |  4 ++
 kunit/example-test.c   | 88 ++
 kunit/string-stream-test.c | 52 ++
 4 files changed, 165 insertions(+)
 create mode 100644 kunit/example-test.c
 create mode 100644 kunit/string-stream-test.c

diff --git a/kunit/Kconfig b/kunit/Kconfig
index 330ae83527c23..8541ef95b65ad 100644
--- a/kunit/Kconfig
+++ b/kunit/Kconfig
@@ -14,4 +14,25 @@ config KUNIT
  architectures. For more information, please see
  Documentation/dev-tools/kunit/.
 
+config KUNIT_TEST
+   bool "KUnit test for KUnit"
+   depends on KUNIT
+   help
+ Enables the unit tests for the KUnit test framework. These tests test
+ the KUnit test framework itself; the tests are both written using
+ KUnit and test KUnit. This option should only be enabled for testing
+ purposes by developers interested in testing that KUnit works as
+ expected.
+
+config KUNIT_EXAMPLE_TEST
+   bool "Example test for KUnit"
+   depends on KUNIT
+   help
+ Enables an example unit test that illustrates some of the basic
+ features of KUnit. This test only exists to help new users understand
+ what KUnit is and how it is used. Please refer to the example test
+ itself, kunit/example-test.c, for more information. This option is
+ intended for curious hackers who would like to understand how to use
+ KUnit for kernel development.
+
 endmenu
diff --git a/kunit/Makefile b/kunit/Makefile
index 6dcbe309036b8..4e46450bcb3a8 100644
--- a/kunit/Makefile
+++ b/kunit/Makefile
@@ -1,3 +1,7 @@
 obj-$(CONFIG_KUNIT) += test.o \
string-stream.o \
assert.o
+
+obj-$(CONFIG_KUNIT_TEST) +=string-stream-test.o
+
+obj-$(CONFIG_KUNIT_EXAMPLE_TEST) +=example-test.o
diff --git a/kunit/example-test.c b/kunit/example-test.c
new file mode 100644
index 0..f64a829aa441f
--- /dev/null
+++ b/kunit/example-test.c
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Example KUnit test to show how to use KUnit.
+ *
+ * Copyright (C) 2019, Google LLC.
+ * Author: Brendan Higgins 
+ */
+
+#include 
+
+/*
+ * This is the most fundamental element of KUnit, the test case. A test case
+ * makes a set EXPECTATIONs and ASSERTIONs about the behavior of some code; if
+ * any expectations or assertions are not met, the test fails; otherwise, the
+ * test passes.
+ *
+ * In KUnit, a test case is just a function with the signature
+ * `void (*)(struct kunit *)`. `struct kunit` is a context object that stores
+ * information about the current test.
+ */
+static void example_simple_test(struct kunit *test)
+{
+   /*
+* This is an EXPECTATION; it is how KUnit tests things. When you want
+* to test a piece of code, you set some expectations about what the
+* code should do. KUnit then runs the test and verifies that the code's
+* behavior matched what was expected.
+*/
+   KUNIT_EXPECT_EQ(test, 1 + 1, 2);
+}
+
+/*
+ * This is run once before each test case, see the comment on
+ * example_test_suite for more information.
+ */
+static int example_test_init(struct kunit *test)
+{
+   kunit_info(test, "initializing\n");
+
+   return 0;
+}
+
+/*
+ * Here we make a list of all the test cases we want to add to the test suite
+ * below.
+ */
+static struct kunit_case example_test_cases[] = {
+   /*
+* This is a helper to create a test case object from a test case
+* function; its exact function is not important to understand how to
+* use KUnit, just know that this is how you associate test cases with a
+* test suite.
+*/
+   KUNIT_CASE(example_simple_test),
+   {}
+};
+
+/*
+ * This defines a suite or grouping of tests.
+ *
+ * Test cases are defined as belonging to the suite by adding them to
+ * `kunit_cases`.
+ *
+ * Often it is desirable to run some function which will set up things which
+ * will be used by every test; this is accomplished with an `init` function
+ * which runs before each test case is invoked. Similarly, an `exit` function
+ * may be specified which runs after every test case and can be used to for
+ * cleanup. For clarity, running tests in a test suite would behave as follows:
+ *
+ * suite.init(test);
+ * suite.test_case[0](test);
+ * suite.exit(test);
+ * suite.init(test);
+ * suite.test_case[1](test);
+ * suite.exit(test);
+ * ...;
+ */
+static struct kunit_suite example_test_suite = {
+   .name = "example",
+   .init = example_test_init,
+   .test_cases = example_test_cases,
+};
+
+/*
+ * This registers the above 

[PATCH v14 14/18] kunit: defconfig: add defconfigs for building KUnit tests

2019-08-20 Thread Brendan Higgins
Add defconfig for UML and a fragment that can be used to configure other
architectures for building KUnit tests. Add option to kunit_tool to use
a defconfig to create the kunitconfig.

Signed-off-by: Brendan Higgins 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Logan Gunthorpe 
Reviewed-by: Stephen Boyd 
---
 arch/um/configs/kunit_defconfig  |  3 +++
 tools/testing/kunit/configs/all_tests.config |  3 +++
 tools/testing/kunit/kunit.py | 28 +---
 tools/testing/kunit/kunit_kernel.py  |  3 ++-
 4 files changed, 32 insertions(+), 5 deletions(-)
 create mode 100644 arch/um/configs/kunit_defconfig
 create mode 100644 tools/testing/kunit/configs/all_tests.config

diff --git a/arch/um/configs/kunit_defconfig b/arch/um/configs/kunit_defconfig
new file mode 100644
index 0..9235b7d42d389
--- /dev/null
+++ b/arch/um/configs/kunit_defconfig
@@ -0,0 +1,3 @@
+CONFIG_KUNIT=y
+CONFIG_KUNIT_TEST=y
+CONFIG_KUNIT_EXAMPLE_TEST=y
diff --git a/tools/testing/kunit/configs/all_tests.config 
b/tools/testing/kunit/configs/all_tests.config
new file mode 100644
index 0..9235b7d42d389
--- /dev/null
+++ b/tools/testing/kunit/configs/all_tests.config
@@ -0,0 +1,3 @@
+CONFIG_KUNIT=y
+CONFIG_KUNIT_TEST=y
+CONFIG_KUNIT_EXAMPLE_TEST=y
diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index da11bd62a4b82..0944dea5c3211 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -11,6 +11,7 @@ import argparse
 import sys
 import os
 import time
+import shutil
 
 from collections import namedtuple
 from enum import Enum, auto
@@ -21,7 +22,7 @@ import kunit_parser
 
 KunitResult = namedtuple('KunitResult', ['status','result'])
 
-KunitRequest = namedtuple('KunitRequest', ['raw_output','timeout', 'jobs', 
'build_dir'])
+KunitRequest = namedtuple('KunitRequest', ['raw_output','timeout', 'jobs', 
'build_dir', 'defconfig'])
 
 class KunitStatus(Enum):
SUCCESS = auto()
@@ -29,8 +30,16 @@ class KunitStatus(Enum):
BUILD_FAILURE = auto()
TEST_FAILURE = auto()
 
+def create_default_kunitconfig():
+   if not os.path.exists(kunit_kernel.KUNITCONFIG_PATH):
+   shutil.copyfile('arch/um/configs/kunit_defconfig',
+   kunit_kernel.KUNITCONFIG_PATH)
+
 def run_tests(linux: kunit_kernel.LinuxSourceTree,
  request: KunitRequest) -> KunitResult:
+   if request.defconfig:
+   create_default_kunitconfig()
+
config_start = time.time()
success = linux.build_reconfig(request.build_dir)
config_end = time.time()
@@ -72,7 +81,7 @@ def run_tests(linux: kunit_kernel.LinuxSourceTree,
else:
return KunitResult(KunitStatus.SUCCESS, test_result)
 
-def main(argv, linux):
+def main(argv, linux=None):
parser = argparse.ArgumentParser(
description='Helps writing and running KUnit tests.')
subparser = parser.add_subparsers(dest='subcommand')
@@ -99,13 +108,24 @@ def main(argv, linux):
'directory.',
type=str, default=None, metavar='build_dir')
 
+   run_parser.add_argument('--defconfig',
+   help='Uses a default kunitconfig.',
+   action='store_true')
+
cli_args = parser.parse_args(argv)
 
if cli_args.subcommand == 'run':
+   if cli_args.defconfig:
+   create_default_kunitconfig()
+
+   if not linux:
+   linux = kunit_kernel.LinuxSourceTree()
+
request = KunitRequest(cli_args.raw_output,
   cli_args.timeout,
   cli_args.jobs,
-  cli_args.build_dir)
+  cli_args.build_dir,
+  cli_args.defconfig)
result = run_tests(linux, request)
if result.status != KunitStatus.SUCCESS:
sys.exit(1)
@@ -113,4 +133,4 @@ def main(argv, linux):
parser.print_help()
 
 if __name__ == '__main__':
-   main(sys.argv[1:], kunit_kernel.LinuxSourceTree())
+   main(sys.argv[1:])
diff --git a/tools/testing/kunit/kunit_kernel.py 
b/tools/testing/kunit/kunit_kernel.py
index 07c0abf2f47df..bf38768353313 100644
--- a/tools/testing/kunit/kunit_kernel.py
+++ b/tools/testing/kunit/kunit_kernel.py
@@ -14,6 +14,7 @@ import os
 import kunit_config
 
 KCONFIG_PATH = '.config'
+KUNITCONFIG_PATH = 'kunitconfig'
 
 class ConfigError(Exception):
"""Represents an error trying to configure the Linux kernel."""
@@ -81,7 +82,7 @@ class LinuxSourceTree(object):
 
def __init__(self):
self._kconfig = kunit_config.Kconfig()
-   self._kconfig.read_from_file('kunitconfig')
+   

[PATCH v14 17/18] kernel/sysctl-test: Add null pointer test for sysctl.c:proc_dointvec()

2019-08-20 Thread Brendan Higgins
From: Iurii Zaikin 

KUnit tests for initialized data behavior of proc_dointvec that is
explicitly checked in the code. Includes basic parsing tests including
int min/max overflow.

Signed-off-by: Iurii Zaikin 
Signed-off-by: Brendan Higgins 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Logan Gunthorpe 
Acked-by: Luis Chamberlain 
Reviewed-by: Stephen Boyd 
---
 kernel/Makefile  |   2 +
 kernel/sysctl-test.c | 392 +++
 lib/Kconfig.debug|  11 ++
 3 files changed, 405 insertions(+)
 create mode 100644 kernel/sysctl-test.c

diff --git a/kernel/Makefile b/kernel/Makefile
index ef0d95a190b41..63e9ea6122c2c 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -113,6 +113,8 @@ obj-$(CONFIG_TORTURE_TEST) += torture.o
 obj-$(CONFIG_HAS_IOMEM) += iomem.o
 obj-$(CONFIG_RSEQ) += rseq.o
 
+obj-$(CONFIG_SYSCTL_KUNIT_TEST) += sysctl-test.o
+
 obj-$(CONFIG_GCC_PLUGIN_STACKLEAK) += stackleak.o
 KASAN_SANITIZE_stackleak.o := n
 KCOV_INSTRUMENT_stackleak.o := n
diff --git a/kernel/sysctl-test.c b/kernel/sysctl-test.c
new file mode 100644
index 0..2a63241a8453b
--- /dev/null
+++ b/kernel/sysctl-test.c
@@ -0,0 +1,392 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * KUnit test of proc sysctl.
+ */
+
+#include 
+#include 
+
+#define KUNIT_PROC_READ 0
+#define KUNIT_PROC_WRITE 1
+
+static int i_zero;
+static int i_one_hundred = 100;
+
+/*
+ * Test that proc_dointvec will not try to use a NULL .data field even when the
+ * length is non-zero.
+ */
+static void sysctl_test_api_dointvec_null_tbl_data(struct kunit *test)
+{
+   struct ctl_table null_data_table = {
+   .procname = "foo",
+   /*
+* Here we are testing that proc_dointvec behaves correctly when
+* we give it a NULL .data field. Normally this would point to a
+* piece of memory where the value would be stored.
+*/
+   .data   = NULL,
+   .maxlen = sizeof(int),
+   .mode   = 0644,
+   .proc_handler   = proc_dointvec,
+   .extra1 = _zero,
+   .extra2 = _one_hundred,
+   };
+   /*
+* proc_dointvec expects a buffer in user space, so we allocate one. We
+* also need to cast it to __user so sparse doesn't get mad.
+*/
+   void __user *buffer = (void __user *)kunit_kzalloc(test, sizeof(int),
+  GFP_USER);
+   size_t len;
+   loff_t pos;
+
+   /*
+* We don't care what the starting length is since proc_dointvec should
+* not try to read because .data is NULL.
+*/
+   len = 1234;
+   KUNIT_EXPECT_EQ(test, 0, proc_dointvec(_data_table,
+  KUNIT_PROC_READ, buffer, ,
+  ));
+   KUNIT_EXPECT_EQ(test, (size_t)0, len);
+
+   /*
+* See above.
+*/
+   len = 1234;
+   KUNIT_EXPECT_EQ(test, 0, proc_dointvec(_data_table,
+  KUNIT_PROC_WRITE, buffer, ,
+  ));
+   KUNIT_EXPECT_EQ(test, (size_t)0, len);
+}
+
+/*
+ * Similar to the previous test, we create a struct ctrl_table that has a .data
+ * field that proc_dointvec cannot do anything with; however, this time it is
+ * because we tell proc_dointvec that the size is 0.
+ */
+static void sysctl_test_api_dointvec_table_maxlen_unset(struct kunit *test)
+{
+   int data = 0;
+   struct ctl_table data_maxlen_unset_table = {
+   .procname = "foo",
+   .data   = ,
+   /*
+* So .data is no longer NULL, but we tell proc_dointvec its
+* length is 0, so it still shouldn't try to use it.
+*/
+   .maxlen = 0,
+   .mode   = 0644,
+   .proc_handler   = proc_dointvec,
+   .extra1 = _zero,
+   .extra2 = _one_hundred,
+   };
+   void __user *buffer = (void __user *)kunit_kzalloc(test, sizeof(int),
+  GFP_USER);
+   size_t len;
+   loff_t pos;
+
+   /*
+* As before, we don't care what buffer length is because proc_dointvec
+* cannot do anything because its internal .data buffer has zero length.
+*/
+   len = 1234;
+   KUNIT_EXPECT_EQ(test, 0, proc_dointvec(_maxlen_unset_table,
+  KUNIT_PROC_READ, buffer, ,
+  ));
+   KUNIT_EXPECT_EQ(test, (size_t)0, len);
+
+   /*
+* See previous comment.
+*/
+   len = 1234;
+   KUNIT_EXPECT_EQ(test, 0, proc_dointvec(_maxlen_unset_table,
+  KUNIT_PROC_WRITE, buffer, ,
+   

[PATCH v14 16/18] MAINTAINERS: add entry for KUnit the unit testing framework

2019-08-20 Thread Brendan Higgins
Add myself as maintainer of KUnit, the Linux kernel's unit testing
framework.

Signed-off-by: Brendan Higgins 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Logan Gunthorpe 
Reviewed-by: Stephen Boyd 
---
 MAINTAINERS | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index a2c343ee3b2ca..f0bd77e8a8a2f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8799,6 +8799,17 @@ S:   Maintained
 F: tools/testing/selftests/
 F: Documentation/dev-tools/kselftest*
 
+KERNEL UNIT TESTING FRAMEWORK (KUnit)
+M: Brendan Higgins 
+L: linux-kselft...@vger.kernel.org
+L: kunit-...@googlegroups.com
+W: https://google.github.io/kunit-docs/third_party/kernel/docs/
+S: Maintained
+F: Documentation/dev-tools/kunit/
+F: include/kunit/
+F: kunit/
+F: tools/testing/kunit/
+
 KERNEL USERMODE HELPER
 M: Luis Chamberlain 
 L: linux-ker...@vger.kernel.org
-- 
2.23.0.rc1.153.gdeed80330f-goog



[PATCH v14 18/18] MAINTAINERS: add proc sysctl KUnit test to PROC SYSCTL section

2019-08-20 Thread Brendan Higgins
Add entry for the new proc sysctl KUnit test to the PROC SYSCTL section,
and add Iurii as a maintainer.

Signed-off-by: Brendan Higgins 
Cc: Iurii Zaikin 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Logan Gunthorpe 
Acked-by: Luis Chamberlain 
---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index f0bd77e8a8a2f..0cac78807137b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12965,12 +12965,14 @@ F:Documentation/filesystems/proc.txt
 PROC SYSCTL
 M: Luis Chamberlain 
 M: Kees Cook 
+M: Iurii Zaikin 
 L: linux-ker...@vger.kernel.org
 L: linux-fsde...@vger.kernel.org
 S: Maintained
 F: fs/proc/proc_sysctl.c
 F: include/linux/sysctl.h
 F: kernel/sysctl.c
+F: kernel/sysctl-test.c
 F: tools/testing/selftests/sysctl/
 
 PS3 NETWORK SUPPORT
-- 
2.23.0.rc1.153.gdeed80330f-goog



[PATCH v14 13/18] kunit: tool: add Python wrappers for running KUnit tests

2019-08-20 Thread Brendan Higgins
From: Felix Guo 

The ultimate goal is to create minimal isolated test binaries; in the
meantime we are using UML to provide the infrastructure to run tests, so
define an abstract way to configure and run tests that allow us to
change the context in which tests are built without affecting the user.
This also makes pretty and dynamic error reporting, and a lot of other
nice features easier.

kunit_config.py:
  - parse .config and Kconfig files.

kunit_kernel.py: provides helper functions to:
  - configure the kernel using kunitconfig.
  - build the kernel with the appropriate configuration.
  - provide function to invoke the kernel and stream the output back.

kunit_parser.py: parses raw logs returned out by kunit_kernel and
displays them in a user friendly way.

test_data/*: samples of test data for testing kunit.py, kunit_config.py,
etc.

Signed-off-by: Felix Guo 
Signed-off-by: Brendan Higgins 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Logan Gunthorpe 
Reviewed-by: Stephen Boyd 
---
 tools/testing/kunit/.gitignore|   3 +
 tools/testing/kunit/kunit.py  | 116 +++
 tools/testing/kunit/kunit_config.py   |  66 
 tools/testing/kunit/kunit_kernel.py   | 148 +
 tools/testing/kunit/kunit_parser.py   | 310 ++
 tools/testing/kunit/kunit_tool_test.py| 206 
 .../test_is_test_passed-all_passed.log|  32 ++
 .../test_data/test_is_test_passed-crash.log   |  69 
 .../test_data/test_is_test_passed-failure.log |  36 ++
 .../test_is_test_passed-no_tests_run.log  |  75 +
 .../test_output_isolated_correctly.log| 106 ++
 .../test_data/test_read_from_file.kconfig |  17 +
 12 files changed, 1184 insertions(+)
 create mode 100644 tools/testing/kunit/.gitignore
 create mode 100755 tools/testing/kunit/kunit.py
 create mode 100644 tools/testing/kunit/kunit_config.py
 create mode 100644 tools/testing/kunit/kunit_kernel.py
 create mode 100644 tools/testing/kunit/kunit_parser.py
 create mode 100755 tools/testing/kunit/kunit_tool_test.py
 create mode 100644 
tools/testing/kunit/test_data/test_is_test_passed-all_passed.log
 create mode 100644 tools/testing/kunit/test_data/test_is_test_passed-crash.log
 create mode 100644 
tools/testing/kunit/test_data/test_is_test_passed-failure.log
 create mode 100644 
tools/testing/kunit/test_data/test_is_test_passed-no_tests_run.log
 create mode 100644 
tools/testing/kunit/test_data/test_output_isolated_correctly.log
 create mode 100644 tools/testing/kunit/test_data/test_read_from_file.kconfig

diff --git a/tools/testing/kunit/.gitignore b/tools/testing/kunit/.gitignore
new file mode 100644
index 0..c791ff59a37a9
--- /dev/null
+++ b/tools/testing/kunit/.gitignore
@@ -0,0 +1,3 @@
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
\ No newline at end of file
diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
new file mode 100755
index 0..da11bd62a4b82
--- /dev/null
+++ b/tools/testing/kunit/kunit.py
@@ -0,0 +1,116 @@
+#!/usr/bin/python3
+# SPDX-License-Identifier: GPL-2.0
+#
+# A thin wrapper on top of the KUnit Kernel
+#
+# Copyright (C) 2019, Google LLC.
+# Author: Felix Guo 
+# Author: Brendan Higgins 
+
+import argparse
+import sys
+import os
+import time
+
+from collections import namedtuple
+from enum import Enum, auto
+
+import kunit_config
+import kunit_kernel
+import kunit_parser
+
+KunitResult = namedtuple('KunitResult', ['status','result'])
+
+KunitRequest = namedtuple('KunitRequest', ['raw_output','timeout', 'jobs', 
'build_dir'])
+
+class KunitStatus(Enum):
+   SUCCESS = auto()
+   CONFIG_FAILURE = auto()
+   BUILD_FAILURE = auto()
+   TEST_FAILURE = auto()
+
+def run_tests(linux: kunit_kernel.LinuxSourceTree,
+ request: KunitRequest) -> KunitResult:
+   config_start = time.time()
+   success = linux.build_reconfig(request.build_dir)
+   config_end = time.time()
+   if not success:
+   return KunitResult(KunitStatus.CONFIG_FAILURE, 'could not 
configure kernel')
+
+   kunit_parser.print_with_timestamp('Building KUnit Kernel ...')
+
+   build_start = time.time()
+   success = linux.build_um_kernel(request.jobs, request.build_dir)
+   build_end = time.time()
+   if not success:
+   return KunitResult(KunitStatus.BUILD_FAILURE, 'could not build 
kernel')
+
+   kunit_parser.print_with_timestamp('Starting KUnit Kernel ...')
+   test_start = time.time()
+
+   test_result = kunit_parser.TestResult(kunit_parser.TestStatus.SUCCESS,
+ [],
+ 'Tests not Parsed.')
+   if request.raw_output:
+   kunit_parser.raw_output(
+   linux.run_kernel(timeout=request.timeout))
+   else:
+   kunit_output = linux.run_kernel(timeout=request.timeout)
+   test_result 

[PATCH v14 15/18] Documentation: kunit: add documentation for KUnit

2019-08-20 Thread Brendan Higgins
Add documentation for KUnit, the Linux kernel unit testing framework.
- Add intro and usage guide for KUnit
- Add API reference

Signed-off-by: Felix Guo 
Signed-off-by: Brendan Higgins 
Cc: Jonathan Corbet 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Logan Gunthorpe 
Reviewed-by: Stephen Boyd 
---
 Documentation/dev-tools/index.rst   |   1 +
 Documentation/dev-tools/kunit/api/index.rst |  16 +
 Documentation/dev-tools/kunit/api/test.rst  |  11 +
 Documentation/dev-tools/kunit/faq.rst   |  62 +++
 Documentation/dev-tools/kunit/index.rst |  79 +++
 Documentation/dev-tools/kunit/start.rst | 180 ++
 Documentation/dev-tools/kunit/usage.rst | 576 
 7 files changed, 925 insertions(+)
 create mode 100644 Documentation/dev-tools/kunit/api/index.rst
 create mode 100644 Documentation/dev-tools/kunit/api/test.rst
 create mode 100644 Documentation/dev-tools/kunit/faq.rst
 create mode 100644 Documentation/dev-tools/kunit/index.rst
 create mode 100644 Documentation/dev-tools/kunit/start.rst
 create mode 100644 Documentation/dev-tools/kunit/usage.rst

diff --git a/Documentation/dev-tools/index.rst 
b/Documentation/dev-tools/index.rst
index b0522a4dd1073..09dee10d25928 100644
--- a/Documentation/dev-tools/index.rst
+++ b/Documentation/dev-tools/index.rst
@@ -24,6 +24,7 @@ whole; patches welcome!
gdb-kernel-debugging
kgdb
kselftest
+   kunit/index
 
 
 .. only::  subproject and html
diff --git a/Documentation/dev-tools/kunit/api/index.rst 
b/Documentation/dev-tools/kunit/api/index.rst
new file mode 100644
index 0..9b9bffe5d41a0
--- /dev/null
+++ b/Documentation/dev-tools/kunit/api/index.rst
@@ -0,0 +1,16 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=
+API Reference
+=
+.. toctree::
+
+   test
+
+This section documents the KUnit kernel testing API. It is divided into the
+following sections:
+
+= 
==
+:doc:`test`   documents all of the standard testing API
+  excluding mocking or mocking related 
features.
+= 
==
diff --git a/Documentation/dev-tools/kunit/api/test.rst 
b/Documentation/dev-tools/kunit/api/test.rst
new file mode 100644
index 0..aaa97f17e5b32
--- /dev/null
+++ b/Documentation/dev-tools/kunit/api/test.rst
@@ -0,0 +1,11 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+
+Test API
+
+
+This file documents all of the standard testing API excluding mocking or 
mocking
+related features.
+
+.. kernel-doc:: include/kunit/test.h
+   :internal:
diff --git a/Documentation/dev-tools/kunit/faq.rst 
b/Documentation/dev-tools/kunit/faq.rst
new file mode 100644
index 0..bf2095112d899
--- /dev/null
+++ b/Documentation/dev-tools/kunit/faq.rst
@@ -0,0 +1,62 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+==
+Frequently Asked Questions
+==
+
+How is this different from Autotest, kselftest, etc?
+
+KUnit is a unit testing framework. Autotest, kselftest (and some others) are
+not.
+
+A `unit test `_ is supposed to
+test a single unit of code in isolation, hence the name. A unit test should be
+the finest granularity of testing and as such should allow all possible code
+paths to be tested in the code under test; this is only possible if the code
+under test is very small and does not have any external dependencies outside of
+the test's control like hardware.
+
+There are no testing frameworks currently available for the kernel that do not
+require installing the kernel on a test machine or in a VM and all require
+tests to be written in userspace and run on the kernel under test; this is true
+for Autotest, kselftest, and some others, disqualifying any of them from being
+considered unit testing frameworks.
+
+Does KUnit support running on architectures other than UML?
+===
+
+Yes, well, mostly.
+
+For the most part, the KUnit core framework (what you use to write the tests)
+can compile to any architecture; it compiles like just another part of the
+kernel and runs when the kernel boots. However, there is some infrastructure,
+like the KUnit Wrapper (``tools/testing/kunit/kunit.py``) that does not support
+other architectures.
+
+In short, this means that, yes, you can run KUnit on other architectures, but
+it might require more work than using KUnit on UML.
+
+For more information, see :ref:`kunit-on-non-uml`.
+
+What is the difference between a unit test and these other kinds of tests?
+==
+Most existing tests for the Linux kernel would be categorized as an integration
+test, or an end-to-end test.
+
+- A unit test is supposed to 

[PATCH v14 12/18] kunit: test: add tests for KUnit managed resources

2019-08-20 Thread Brendan Higgins
From: Avinash Kondareddy 

Add unit tests for KUnit managed resources. KUnit managed resources
(struct kunit_resource) are resources that are automatically cleaned up
at the end of a KUnit test, similar to the concept of devm_* managed
resources.

Signed-off-by: Avinash Kondareddy 
Signed-off-by: Brendan Higgins 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Logan Gunthorpe 
Reviewed-by: Stephen Boyd 
---
 kunit/test-test.c | 228 ++
 1 file changed, 228 insertions(+)

diff --git a/kunit/test-test.c b/kunit/test-test.c
index e0ab4bd546eac..5ebe059d16e25 100644
--- a/kunit/test-test.c
+++ b/kunit/test-test.c
@@ -101,3 +101,231 @@ static struct kunit_suite kunit_try_catch_test_suite = {
.test_cases = kunit_try_catch_test_cases,
 };
 kunit_test_suite(kunit_try_catch_test_suite);
+
+/*
+ * Context for testing test managed resources
+ * is_resource_initialized is used to test arbitrary resources
+ */
+struct kunit_test_resource_context {
+   struct kunit test;
+   bool is_resource_initialized;
+   int allocate_order[2];
+   int free_order[2];
+};
+
+static int fake_resource_init(struct kunit_resource *res, void *context)
+{
+   struct kunit_test_resource_context *ctx = context;
+
+   res->allocation = >is_resource_initialized;
+   ctx->is_resource_initialized = true;
+   return 0;
+}
+
+static void fake_resource_free(struct kunit_resource *res)
+{
+   bool *is_resource_initialized = res->allocation;
+
+   *is_resource_initialized = false;
+}
+
+static void kunit_resource_test_init_resources(struct kunit *test)
+{
+   struct kunit_test_resource_context *ctx = test->priv;
+
+   kunit_init_test(>test, "testing_test_init_test");
+
+   KUNIT_EXPECT_TRUE(test, list_empty(>test.resources));
+}
+
+static void kunit_resource_test_alloc_resource(struct kunit *test)
+{
+   struct kunit_test_resource_context *ctx = test->priv;
+   struct kunit_resource *res;
+   kunit_resource_free_t free = fake_resource_free;
+
+   res = kunit_alloc_and_get_resource(>test,
+  fake_resource_init,
+  fake_resource_free,
+  GFP_KERNEL,
+  ctx);
+
+   KUNIT_ASSERT_NOT_ERR_OR_NULL(test, res);
+   KUNIT_EXPECT_PTR_EQ(test,
+   >is_resource_initialized,
+   (bool *) res->allocation);
+   KUNIT_EXPECT_TRUE(test, list_is_last(>node, >test.resources));
+   KUNIT_EXPECT_PTR_EQ(test, free, res->free);
+}
+
+static void kunit_resource_test_destroy_resource(struct kunit *test)
+{
+   struct kunit_test_resource_context *ctx = test->priv;
+   struct kunit_resource *res = kunit_alloc_and_get_resource(
+   >test,
+   fake_resource_init,
+   fake_resource_free,
+   GFP_KERNEL,
+   ctx);
+
+   KUNIT_ASSERT_FALSE(test,
+  kunit_resource_destroy(>test,
+ kunit_resource_instance_match,
+ res->free,
+ res->allocation));
+
+   KUNIT_EXPECT_FALSE(test, ctx->is_resource_initialized);
+   KUNIT_EXPECT_TRUE(test, list_empty(>test.resources));
+}
+
+static void kunit_resource_test_cleanup_resources(struct kunit *test)
+{
+   int i;
+   struct kunit_test_resource_context *ctx = test->priv;
+   struct kunit_resource *resources[5];
+
+   for (i = 0; i < ARRAY_SIZE(resources); i++) {
+   resources[i] = kunit_alloc_and_get_resource(>test,
+   fake_resource_init,
+   fake_resource_free,
+   GFP_KERNEL,
+   ctx);
+   }
+
+   kunit_cleanup(>test);
+
+   KUNIT_EXPECT_TRUE(test, list_empty(>test.resources));
+}
+
+static void kunit_resource_test_mark_order(int order_array[],
+  size_t order_size,
+  int key)
+{
+   int i;
+
+   for (i = 0; i < order_size && order_array[i]; i++)
+   ;
+
+   order_array[i] = key;
+}
+
+#define KUNIT_RESOURCE_TEST_MARK_ORDER(ctx, order_field, key) \
+   kunit_resource_test_mark_order(ctx->order_field,   \
+  ARRAY_SIZE(ctx->order_field),   \
+  key)
+
+static int fake_resource_2_init(struct kunit_resource *res, void *context)
+{
+   struct kunit_test_resource_context *ctx = context;
+
+   KUNIT_RESOURCE_TEST_MARK_ORDER(ctx, 

[PATCH v14 09/18] kunit: test: add support for test abort

2019-08-20 Thread Brendan Higgins
Add support for aborting/bailing out of test cases, which is needed for
implementing assertions.

An assertion is like an expectation, but bails out of the test case
early if the assertion is not met. The idea with assertions is that you
use them to state all the preconditions for your test. Logically
speaking, these are the premises of the test case, so if a premise isn't
true, there is no point in continuing the test case because there are no
conclusions that can be drawn without the premises. Whereas, the
expectation is the thing you are trying to prove.

Signed-off-by: Brendan Higgins 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Logan Gunthorpe 
Reviewed-by: Stephen Boyd 
---
 include/kunit/test.h  |   2 +
 include/kunit/try-catch.h |  75 +
 kunit/Makefile|   3 +-
 kunit/test.c  | 137 +-
 kunit/try-catch.c | 118 
 5 files changed, 319 insertions(+), 16 deletions(-)
 create mode 100644 include/kunit/try-catch.h
 create mode 100644 kunit/try-catch.c

diff --git a/include/kunit/test.h b/include/kunit/test.h
index 6917b186b737a..390ce02f717b6 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -10,6 +10,7 @@
 #define _KUNIT_TEST_H
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -167,6 +168,7 @@ struct kunit {
 
/* private: internal use only. */
const char *name; /* Read only after initialization! */
+   struct kunit_try_catch try_catch;
/*
 * success starts as true, and may only be set to false during a test
 * case; thus, it is safe to update this across multiple threads using
diff --git a/include/kunit/try-catch.h b/include/kunit/try-catch.h
new file mode 100644
index 0..404f336cbdc85
--- /dev/null
+++ b/include/kunit/try-catch.h
@@ -0,0 +1,75 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * An API to allow a function, that may fail, to be executed, and recover in a
+ * controlled manner.
+ *
+ * Copyright (C) 2019, Google LLC.
+ * Author: Brendan Higgins 
+ */
+
+#ifndef _KUNIT_TRY_CATCH_H
+#define _KUNIT_TRY_CATCH_H
+
+#include 
+
+typedef void (*kunit_try_catch_func_t)(void *);
+
+struct completion;
+struct kunit;
+
+/**
+ * struct kunit_try_catch - provides a generic way to run code which might 
fail.
+ * @test: The test case that is currently being executed.
+ * @try_completion: Completion that the control thread waits on while test 
runs.
+ * @try_result: Contains any errno obtained while running test case.
+ * @try: The function, the test case, to attempt to run.
+ * @catch: The function called if @try bails out.
+ * @context: used to pass user data to the try and catch functions.
+ *
+ * kunit_try_catch provides a generic, architecture independent way to execute
+ * an arbitrary function of type kunit_try_catch_func_t which may bail out by
+ * calling kunit_try_catch_throw(). If kunit_try_catch_throw() is called, @try
+ * is stopped at the site of invocation and @catch is called.
+ *
+ * struct kunit_try_catch provides a generic interface for the functionality
+ * needed to implement kunit->abort() which in turn is needed for implementing
+ * assertions. Assertions allow stating a precondition for a test simplifying
+ * how test cases are written and presented.
+ *
+ * Assertions are like expectations, except they abort (call
+ * kunit_try_catch_throw()) when the specified condition is not met. This is
+ * useful when you look at a test case as a logical statement about some piece
+ * of code, where assertions are the premises for the test case, and the
+ * conclusion is a set of predicates, rather expectations, that must all be
+ * true. If your premises are violated, it does not makes sense to continue.
+ */
+struct kunit_try_catch {
+   /* private: internal use only. */
+   struct kunit *test;
+   struct completion *try_completion;
+   int try_result;
+   kunit_try_catch_func_t try;
+   kunit_try_catch_func_t catch;
+   void *context;
+};
+
+void kunit_try_catch_init(struct kunit_try_catch *try_catch,
+ struct kunit *test,
+ kunit_try_catch_func_t try,
+ kunit_try_catch_func_t catch);
+
+void kunit_try_catch_run(struct kunit_try_catch *try_catch, void *context);
+
+void __noreturn kunit_try_catch_throw(struct kunit_try_catch *try_catch);
+
+static inline int kunit_try_catch_get_result(struct kunit_try_catch *try_catch)
+{
+   return try_catch->try_result;
+}
+
+/*
+ * Exposed for testing only.
+ */
+void kunit_generic_try_catch_init(struct kunit_try_catch *try_catch);
+
+#endif /* _KUNIT_TRY_CATCH_H */
diff --git a/kunit/Makefile b/kunit/Makefile
index 4e46450bcb3a8..c9176c9c578c6 100644
--- a/kunit/Makefile
+++ b/kunit/Makefile
@@ -1,6 +1,7 @@
 obj-$(CONFIG_KUNIT) += test.o \
string-stream.o \
- 

[PATCH v14 06/18] kbuild: enable building KUnit

2019-08-20 Thread Brendan Higgins
KUnit is a new unit testing framework for the kernel and when used is
built into the kernel as a part of it. Add KUnit to the root Kconfig and
Makefile to allow it to be actually built.

Signed-off-by: Brendan Higgins 
Acked-by: Masahiro Yamada 
Cc: Michal Marek 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Logan Gunthorpe 
Reviewed-by: Stephen Boyd 
---
 Kconfig  | 2 ++
 Makefile | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/Kconfig b/Kconfig
index e10b3ee084d4d..47886dbd6c2a6 100644
--- a/Kconfig
+++ b/Kconfig
@@ -32,3 +32,5 @@ source "lib/Kconfig"
 source "lib/Kconfig.debug"
 
 source "Documentation/Kconfig"
+
+source "kunit/Kconfig"
diff --git a/Makefile b/Makefile
index 23cdf1f413646..3795d0a5d0376 100644
--- a/Makefile
+++ b/Makefile
@@ -1005,6 +1005,8 @@ PHONY += prepare0
 ifeq ($(KBUILD_EXTMOD),)
 core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/
 
+core-$(CONFIG_KUNIT) += kunit/
+
 vmlinux-dirs   := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
 $(net-y) $(net-m) $(libs-y) $(libs-m) $(virt-y)))
-- 
2.23.0.rc1.153.gdeed80330f-goog



[PATCH v14 08/18] objtool: add kunit_try_catch_throw to the noreturn list

2019-08-20 Thread Brendan Higgins
Fix the following warning seen on GCC 7.3:
  kunit/test-test.o: warning: objtool: kunit_test_unsuccessful_try() falls 
through to next function kunit_test_catch()

kunit_try_catch_throw is a function added in the following patch in this
series; it allows KUnit, a unit testing framework for the kernel, to
bail out of a broken test. As a consequence, it is a new __noreturn
function that objtool thinks is broken (as seen above). So fix this
warning by adding kunit_try_catch_throw to objtool's noreturn list.

Reported-by: kbuild test robot 
Signed-off-by: Brendan Higgins 
Acked-by: Josh Poimboeuf 
Link: https://www.spinics.net/lists/linux-kbuild/msg21708.html
Cc: Peter Zijlstra 
---
 tools/objtool/check.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 176f2f0840609..0c8e17f946cda 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -145,6 +145,7 @@ static bool __dead_end_function(struct objtool_file *file, 
struct symbol *func,
"usercopy_abort",
"machine_real_restart",
"rewind_stack_do_exit",
+   "kunit_try_catch_throw",
};
 
if (!func)
-- 
2.23.0.rc1.153.gdeed80330f-goog

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v14 03/18] kunit: test: add string_stream a std::stream like string builder

2019-08-20 Thread Brendan Higgins
A number of test features need to do pretty complicated string printing
where it may not be possible to rely on a single preallocated string
with parameters.

So provide a library for constructing the string as you go similar to
C++'s std::string. string_stream is really just a string builder,
nothing more.

Signed-off-by: Brendan Higgins 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Logan Gunthorpe 
Reviewed-by: Stephen Boyd 
---
 include/kunit/string-stream.h |  51 
 kunit/Makefile|   3 +-
 kunit/string-stream.c | 217 ++
 3 files changed, 270 insertions(+), 1 deletion(-)
 create mode 100644 include/kunit/string-stream.h
 create mode 100644 kunit/string-stream.c

diff --git a/include/kunit/string-stream.h b/include/kunit/string-stream.h
new file mode 100644
index 0..fe98a00b75a9c
--- /dev/null
+++ b/include/kunit/string-stream.h
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * C++ stream style string builder used in KUnit for building messages.
+ *
+ * Copyright (C) 2019, Google LLC.
+ * Author: Brendan Higgins 
+ */
+
+#ifndef _KUNIT_STRING_STREAM_H
+#define _KUNIT_STRING_STREAM_H
+
+#include 
+#include 
+#include 
+
+struct string_stream_fragment {
+   struct kunit *test;
+   struct list_head node;
+   char *fragment;
+};
+
+struct string_stream {
+   size_t length;
+   struct list_head fragments;
+   /* length and fragments are protected by this lock */
+   spinlock_t lock;
+   struct kunit *test;
+   gfp_t gfp;
+};
+
+struct kunit;
+
+struct string_stream *alloc_string_stream(struct kunit *test, gfp_t gfp);
+
+int __printf(2, 3) string_stream_add(struct string_stream *stream,
+const char *fmt, ...);
+
+int string_stream_vadd(struct string_stream *stream,
+  const char *fmt,
+  va_list args);
+
+char *string_stream_get_string(struct string_stream *stream);
+
+int string_stream_append(struct string_stream *stream,
+struct string_stream *other);
+
+bool string_stream_is_empty(struct string_stream *stream);
+
+int string_stream_destroy(struct string_stream *stream);
+
+#endif /* _KUNIT_STRING_STREAM_H */
diff --git a/kunit/Makefile b/kunit/Makefile
index 5efdc4dea2c08..275b565a0e81f 100644
--- a/kunit/Makefile
+++ b/kunit/Makefile
@@ -1 +1,2 @@
-obj-$(CONFIG_KUNIT) += test.o
+obj-$(CONFIG_KUNIT) += test.o \
+   string-stream.o
diff --git a/kunit/string-stream.c b/kunit/string-stream.c
new file mode 100644
index 0..e6d17aacca30d
--- /dev/null
+++ b/kunit/string-stream.c
@@ -0,0 +1,217 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * C++ stream style string builder used in KUnit for building messages.
+ *
+ * Copyright (C) 2019, Google LLC.
+ * Author: Brendan Higgins 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+struct string_stream_fragment_alloc_context {
+   struct kunit *test;
+   int len;
+   gfp_t gfp;
+};
+
+static int string_stream_fragment_init(struct kunit_resource *res,
+  void *context)
+{
+   struct string_stream_fragment_alloc_context *ctx = context;
+   struct string_stream_fragment *frag;
+
+   frag = kunit_kzalloc(ctx->test, sizeof(*frag), ctx->gfp);
+   if (!frag)
+   return -ENOMEM;
+
+   frag->test = ctx->test;
+   frag->fragment = kunit_kmalloc(ctx->test, ctx->len, ctx->gfp);
+   if (!frag->fragment)
+   return -ENOMEM;
+
+   res->allocation = frag;
+
+   return 0;
+}
+
+static void string_stream_fragment_free(struct kunit_resource *res)
+{
+   struct string_stream_fragment *frag = res->allocation;
+
+   list_del(>node);
+   kunit_kfree(frag->test, frag->fragment);
+   kunit_kfree(frag->test, frag);
+}
+
+static struct string_stream_fragment *alloc_string_stream_fragment(
+   struct kunit *test, int len, gfp_t gfp)
+{
+   struct string_stream_fragment_alloc_context context = {
+   .test = test,
+   .len = len,
+   .gfp = gfp
+   };
+
+   return kunit_alloc_resource(test,
+   string_stream_fragment_init,
+   string_stream_fragment_free,
+   gfp,
+   );
+}
+
+static int string_stream_fragment_destroy(struct string_stream_fragment *frag)
+{
+   return kunit_resource_destroy(frag->test,
+ kunit_resource_instance_match,
+ string_stream_fragment_free,
+ frag);
+}
+
+int string_stream_vadd(struct string_stream *stream,
+  const char *fmt,
+  va_list args)
+{
+   struct string_stream_fragment *frag_container;
+   int 

[PATCH v14 05/18] kunit: test: add the concept of expectations

2019-08-20 Thread Brendan Higgins
Add support for expectations, which allow properties to be specified and
then verified in tests.

Signed-off-by: Brendan Higgins 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Logan Gunthorpe 
Reviewed-by: Stephen Boyd 
---
 include/kunit/test.h | 842 ++-
 kunit/test.c |  62 
 2 files changed, 901 insertions(+), 3 deletions(-)

diff --git a/include/kunit/test.h b/include/kunit/test.h
index f264ffe58f008..6917b186b737a 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -9,6 +9,8 @@
 #ifndef _KUNIT_TEST_H
 #define _KUNIT_TEST_H
 
+#include 
+#include 
 #include 
 #include 
 
@@ -341,7 +343,7 @@ void __printf(3, 4) kunit_printk(const char *level,
  * a variable number of format parameters just like printk().
  */
 #define kunit_info(test, fmt, ...) \
-   kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__)
+   kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__)
 
 /**
  * kunit_warn() - Prints a WARN level message associated with the current test.
@@ -351,7 +353,7 @@ void __printf(3, 4) kunit_printk(const char *level,
  * Prints a warning level message.
  */
 #define kunit_warn(test, fmt, ...) \
-   kunit_printk(KERN_WARNING, test, fmt, ##__VA_ARGS__)
+   kunit_printk(KERN_WARNING, test, fmt, ##__VA_ARGS__)
 
 /**
  * kunit_err() - Prints an ERROR level message associated with the current 
test.
@@ -361,6 +363,840 @@ void __printf(3, 4) kunit_printk(const char *level,
  * Prints an error level message.
  */
 #define kunit_err(test, fmt, ...) \
-   kunit_printk(KERN_ERR, test, fmt, ##__VA_ARGS__)
+   kunit_printk(KERN_ERR, test, fmt, ##__VA_ARGS__)
+
+/**
+ * KUNIT_SUCCEED() - A no-op expectation. Only exists for code clarity.
+ * @test: The test context object.
+ *
+ * The opposite of KUNIT_FAIL(), it is an expectation that cannot fail. In 
other
+ * words, it does nothing and only exists for code clarity. See
+ * KUNIT_EXPECT_TRUE() for more information.
+ */
+#define KUNIT_SUCCEED(test) do {} while (0)
+
+void kunit_do_assertion(struct kunit *test,
+   struct kunit_assert *assert,
+   bool pass,
+   const char *fmt, ...);
+
+#define KUNIT_ASSERTION(test, pass, assert_class, INITIALIZER, fmt, ...) do {  
\
+   struct assert_class __assertion = INITIALIZER; \
+   kunit_do_assertion(test,   \
+  &__assertion.assert,\
+  pass,   \
+  fmt,\
+  ##__VA_ARGS__); \
+} while (0)
+
+
+#define KUNIT_FAIL_ASSERTION(test, assert_type, fmt, ...) \
+   KUNIT_ASSERTION(test,  \
+   false, \
+   kunit_fail_assert, \
+   KUNIT_INIT_FAIL_ASSERT_STRUCT(test, assert_type),  \
+   fmt,   \
+   ##__VA_ARGS__)
+
+/**
+ * KUNIT_FAIL() - Always causes a test to fail when evaluated.
+ * @test: The test context object.
+ * @fmt: an informational message to be printed when the assertion is made.
+ * @...: string format arguments.
+ *
+ * The opposite of KUNIT_SUCCEED(), it is an expectation that always fails. In
+ * other words, it always results in a failed expectation, and consequently
+ * always causes the test case to fail when evaluated. See KUNIT_EXPECT_TRUE()
+ * for more information.
+ */
+#define KUNIT_FAIL(test, fmt, ...)\
+   KUNIT_FAIL_ASSERTION(test, \
+KUNIT_EXPECTATION,\
+fmt,  \
+##__VA_ARGS__)
+
+#define KUNIT_UNARY_ASSERTION(test,   \
+ assert_type, \
+ condition,   \
+ expected_true,   \
+ fmt, \
+ ...) \
+   KUNIT_ASSERTION(test,  \
+   !!(condition) == !!expected_true,  \
+   kunit_unary_assert,\
+   KUNIT_INIT_UNARY_ASSERT_STRUCT(test,   

[PATCH v14 04/18] kunit: test: add assertion printing library

2019-08-20 Thread Brendan Higgins
Add `struct kunit_assert` and friends which provide a structured way to
capture data from an expectation or an assertion (introduced later in
the series) so that it may be printed out in the event of a failure.

Signed-off-by: Brendan Higgins 
Reviewed-by: Stephen Boyd 
---
 include/kunit/assert.h | 356 +
 kunit/Makefile |   3 +-
 kunit/assert.c | 141 
 3 files changed, 499 insertions(+), 1 deletion(-)
 create mode 100644 include/kunit/assert.h
 create mode 100644 kunit/assert.c

diff --git a/include/kunit/assert.h b/include/kunit/assert.h
new file mode 100644
index 0..db6a0fca09b49
--- /dev/null
+++ b/include/kunit/assert.h
@@ -0,0 +1,356 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Assertion and expectation serialization API.
+ *
+ * Copyright (C) 2019, Google LLC.
+ * Author: Brendan Higgins 
+ */
+
+#ifndef _KUNIT_ASSERT_H
+#define _KUNIT_ASSERT_H
+
+#include 
+#include 
+
+struct kunit;
+
+/**
+ * enum kunit_assert_type - Type of expectation/assertion.
+ * @KUNIT_ASSERTION: Used to denote that a kunit_assert represents an 
assertion.
+ * @KUNIT_EXPECTATION: Denotes that a kunit_assert represents an expectation.
+ *
+ * Used in conjunction with a  kunit_assert to denote whether it
+ * represents an expectation or an assertion.
+ */
+enum kunit_assert_type {
+   KUNIT_ASSERTION,
+   KUNIT_EXPECTATION,
+};
+
+/**
+ * struct kunit_assert - Data for printing a failed assertion or expectation.
+ * @test: the test case this expectation/assertion is associated with.
+ * @type: the type (either an expectation or an assertion) of this 
kunit_assert.
+ * @line: the source code line number that the expectation/assertion is at.
+ * @file: the file path of the source file that the expectation/assertion is 
in.
+ * @message: an optional message to provide additional context.
+ * @format: a function which formats the data in this kunit_assert to a string.
+ *
+ * Represents a failed expectation/assertion. Contains all the data necessary 
to
+ * format a string to a user reporting the failure.
+ */
+struct kunit_assert {
+   struct kunit *test;
+   enum kunit_assert_type type;
+   int line;
+   const char *file;
+   struct va_format message;
+   void (*format)(const struct kunit_assert *assert,
+  struct string_stream *stream);
+};
+
+/**
+ * KUNIT_INIT_VA_FMT_NULL - Default initializer for struct va_format.
+ *
+ * Used inside a struct initialization block to initialize struct va_format to
+ * default values where fmt and va are null.
+ */
+#define KUNIT_INIT_VA_FMT_NULL { .fmt = NULL, .va = NULL }
+
+/**
+ * KUNIT_INIT_ASSERT_STRUCT() - Initializer for a  kunit_assert.
+ * @kunit: The test case that this expectation/assertion is associated with.
+ * @assert_type: The type (assertion or expectation) of this kunit_assert.
+ * @fmt: The formatting function which builds a string out of this 
kunit_assert.
+ *
+ * The base initializer for a  kunit_assert.
+ */
+#define KUNIT_INIT_ASSERT_STRUCT(kunit, assert_type, fmt) {   \
+   .test = kunit, \
+   .type = assert_type,   \
+   .file = __FILE__,  \
+   .line = __LINE__,  \
+   .message = KUNIT_INIT_VA_FMT_NULL, \
+   .format = fmt  \
+}
+
+void kunit_base_assert_format(const struct kunit_assert *assert,
+ struct string_stream *stream);
+
+void kunit_assert_print_msg(const struct kunit_assert *assert,
+   struct string_stream *stream);
+
+/**
+ * struct kunit_fail_assert - Represents a plain fail expectation/assertion.
+ * @assert: The parent of this type.
+ *
+ * Represents a simple KUNIT_FAIL/KUNIT_ASSERT_FAILURE that always fails.
+ */
+struct kunit_fail_assert {
+   struct kunit_assert assert;
+};
+
+void kunit_fail_assert_format(const struct kunit_assert *assert,
+ struct string_stream *stream);
+
+/**
+ * KUNIT_INIT_FAIL_ASSERT_STRUCT() - Initializer for  kunit_fail_assert.
+ * @test: The test case that this expectation/assertion is associated with.
+ * @type: The type (assertion or expectation) of this kunit_assert.
+ *
+ * Initializes a  kunit_fail_assert. Intended to be used in
+ * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
+ */
+#define KUNIT_INIT_FAIL_ASSERT_STRUCT(test, type) {   \
+   .assert = KUNIT_INIT_ASSERT_STRUCT(test,   \
+  type,   \
+  kunit_fail_assert_format)   \
+}
+
+/**
+ * struct kunit_unary_assert - Represents a 

[PATCH v14 02/18] kunit: test: add test resource management API

2019-08-20 Thread Brendan Higgins
Create a common API for test managed resources like memory and test
objects. A lot of times a test will want to set up infrastructure to be
used in test cases; this could be anything from just wanting to allocate
some memory to setting up a driver stack; this defines facilities for
creating "test resources" which are managed by the test infrastructure
and are automatically cleaned up at the conclusion of the test.

Signed-off-by: Brendan Higgins 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Logan Gunthorpe 
Reviewed-by: Stephen Boyd 
---
 include/kunit/test.h | 187 +++
 kunit/test.c | 163 +
 2 files changed, 350 insertions(+)

diff --git a/include/kunit/test.h b/include/kunit/test.h
index e0b34acb9ee4e..f264ffe58f008 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -9,8 +9,72 @@
 #ifndef _KUNIT_TEST_H
 #define _KUNIT_TEST_H
 
+#include 
 #include 
 
+struct kunit_resource;
+
+typedef int (*kunit_resource_init_t)(struct kunit_resource *, void *);
+typedef void (*kunit_resource_free_t)(struct kunit_resource *);
+
+/**
+ * struct kunit_resource - represents a *test managed resource*
+ * @allocation: for the user to store arbitrary data.
+ * @free: a user supplied function to free the resource. Populated by
+ * kunit_alloc_resource().
+ *
+ * Represents a *test managed resource*, a resource which will automatically be
+ * cleaned up at the end of a test case.
+ *
+ * Example:
+ *
+ * .. code-block:: c
+ *
+ * struct kunit_kmalloc_params {
+ * size_t size;
+ * gfp_t gfp;
+ * };
+ *
+ * static int kunit_kmalloc_init(struct kunit_resource *res, void *context)
+ * {
+ * struct kunit_kmalloc_params *params = context;
+ * res->allocation = kmalloc(params->size, params->gfp);
+ *
+ * if (!res->allocation)
+ * return -ENOMEM;
+ *
+ * return 0;
+ * }
+ *
+ * static void kunit_kmalloc_free(struct kunit_resource *res)
+ * {
+ * kfree(res->allocation);
+ * }
+ *
+ * void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp)
+ * {
+ * struct kunit_kmalloc_params params;
+ * struct kunit_resource *res;
+ *
+ * params.size = size;
+ * params.gfp = gfp;
+ *
+ * res = kunit_alloc_resource(test, kunit_kmalloc_init,
+ * kunit_kmalloc_free, );
+ * if (res)
+ * return res->allocation;
+ *
+ * return NULL;
+ * }
+ */
+struct kunit_resource {
+   void *allocation;
+   kunit_resource_free_t free;
+
+   /* private: internal use only. */
+   struct list_head node;
+};
+
 struct kunit;
 
 /**
@@ -109,6 +173,13 @@ struct kunit {
 * have terminated.
 */
bool success; /* Read only after test_case finishes! */
+   spinlock_t lock; /* Guards all mutable test state. */
+   /*
+* Because resources is a list that may be updated multiple times (with
+* new resources) from any thread associated with a test case, we must
+* protect it with some type of lock.
+*/
+   struct list_head resources; /* Protected by lock. */
 };
 
 void kunit_init_test(struct kunit *test, const char *name);
@@ -141,6 +212,122 @@ int kunit_run_tests(struct kunit_suite *suite);
}  \
late_initcall(kunit_suite_init##suite)
 
+/*
+ * Like kunit_alloc_resource() below, but returns the struct kunit_resource
+ * object that contains the allocation. This is mostly for testing purposes.
+ */
+struct kunit_resource *kunit_alloc_and_get_resource(struct kunit *test,
+   kunit_resource_init_t init,
+   kunit_resource_free_t free,
+   gfp_t internal_gfp,
+   void *context);
+
+/**
+ * kunit_alloc_resource() - Allocates a *test managed resource*.
+ * @test: The test context object.
+ * @init: a user supplied function to initialize the resource.
+ * @free: a user supplied function to free the resource.
+ * @internal_gfp: gfp to use for internal allocations, if unsure, use 
GFP_KERNEL
+ * @context: for the user to pass in arbitrary data to the init function.
+ *
+ * Allocates a *test managed resource*, a resource which will automatically be
+ * cleaned up at the end of a test case. See  kunit_resource for an
+ * example.
+ *
+ * NOTE: KUnit needs to allocate memory for each kunit_resource object. You 
must
+ * specify an @internal_gfp that is compatible with the use context of your
+ * resource.
+ */
+static inline void *kunit_alloc_resource(struct kunit *test,
+kunit_resource_init_t init,
+

[PATCH v14 01/18] kunit: test: add KUnit test runner core

2019-08-20 Thread Brendan Higgins
Add core facilities for defining unit tests; this provides a common way
to define test cases, functions that execute code which is under test
and determine whether the code under test behaves as expected; this also
provides a way to group together related test cases in test suites (here
we call them test_modules).

Just define test cases and how to execute them for now; setting
expectations on code will be defined later.

Signed-off-by: Brendan Higgins 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Logan Gunthorpe 
Reviewed-by: Luis Chamberlain 
Reviewed-by: Stephen Boyd 
---
 include/kunit/test.h | 179 
 kunit/Kconfig|  17 
 kunit/Makefile   |   1 +
 kunit/test.c | 191 +++
 4 files changed, 388 insertions(+)
 create mode 100644 include/kunit/test.h
 create mode 100644 kunit/Kconfig
 create mode 100644 kunit/Makefile
 create mode 100644 kunit/test.c

diff --git a/include/kunit/test.h b/include/kunit/test.h
new file mode 100644
index 0..e0b34acb9ee4e
--- /dev/null
+++ b/include/kunit/test.h
@@ -0,0 +1,179 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Base unit test (KUnit) API.
+ *
+ * Copyright (C) 2019, Google LLC.
+ * Author: Brendan Higgins 
+ */
+
+#ifndef _KUNIT_TEST_H
+#define _KUNIT_TEST_H
+
+#include 
+
+struct kunit;
+
+/**
+ * struct kunit_case - represents an individual test case.
+ * @run_case: the function representing the actual test case.
+ * @name: the name of the test case.
+ *
+ * A test case is a function with the signature, ``void (*)(struct kunit *)``
+ * that makes expectations (see KUNIT_EXPECT_TRUE()) about code under test. 
Each
+ * test case is associated with a  kunit_suite and will be run after the
+ * suite's init function and followed by the suite's exit function.
+ *
+ * A test case should be static and should only be created with the 
KUNIT_CASE()
+ * macro; additionally, every array of test cases should be terminated with an
+ * empty test case.
+ *
+ * Example:
+ *
+ * .. code-block:: c
+ *
+ * void add_test_basic(struct kunit *test)
+ * {
+ * KUNIT_EXPECT_EQ(test, 1, add(1, 0));
+ * KUNIT_EXPECT_EQ(test, 2, add(1, 1));
+ * KUNIT_EXPECT_EQ(test, 0, add(-1, 1));
+ * KUNIT_EXPECT_EQ(test, INT_MAX, add(0, INT_MAX));
+ * KUNIT_EXPECT_EQ(test, -1, add(INT_MAX, INT_MIN));
+ * }
+ *
+ * static struct kunit_case example_test_cases[] = {
+ * KUNIT_CASE(add_test_basic),
+ * {}
+ * };
+ *
+ */
+struct kunit_case {
+   void (*run_case)(struct kunit *test);
+   const char *name;
+
+   /* private: internal use only. */
+   bool success;
+};
+
+/**
+ * KUNIT_CASE - A helper for creating a  kunit_case
+ * @test_name: a reference to a test case function.
+ *
+ * Takes a symbol for a function representing a test case and creates a
+ *  kunit_case object from it. See the documentation for
+ *  kunit_case for an example on how to use it.
+ */
+#define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name }
+
+/**
+ * struct kunit_suite - describes a related collection of  kunit_case s.
+ * @name: the name of the test. Purely informational.
+ * @init: called before every test case.
+ * @exit: called after every test case.
+ * @test_cases: a null terminated array of test cases.
+ *
+ * A kunit_suite is a collection of related  kunit_case s, such that
+ * @init is called before every test case and @exit is called after every test
+ * case, similar to the notion of a *test fixture* or a *test class* in other
+ * unit testing frameworks like JUnit or Googletest.
+ *
+ * Every  kunit_case must be associated with a kunit_suite for KUnit to
+ * run it.
+ */
+struct kunit_suite {
+   const char name[256];
+   int (*init)(struct kunit *test);
+   void (*exit)(struct kunit *test);
+   struct kunit_case *test_cases;
+};
+
+/**
+ * struct kunit - represents a running instance of a test.
+ * @priv: for user to store arbitrary data. Commonly used to pass data created
+ * in the init function (see  kunit_suite).
+ *
+ * Used to store information about the current context under which the test is
+ * running. Most of this data is private and should only be accessed indirectly
+ * via public functions; the one exception is @priv which can be used by the
+ * test writer to store arbitrary data.
+ */
+struct kunit {
+   void *priv;
+
+   /* private: internal use only. */
+   const char *name; /* Read only after initialization! */
+   /*
+* success starts as true, and may only be set to false during a test
+* case; thus, it is safe to update this across multiple threads using
+* WRITE_ONCE; however, as a consequence, it may only be read after the
+* test case finishes once all threads associated with the test case
+* have terminated.
+*/
+   bool success; /* Read only after 

[PATCH v14 00/18] kunit: introduce KUnit, the Linux kernel unit testing framework

2019-08-20 Thread Brendan Higgins
## TL;DR

This revision addresses comments from Shuah by removing two macros that
were causing checkpatch errors. No API or major structual changes have
been made since v13.

## Background

This patch set proposes KUnit, a lightweight unit testing and mocking
framework for the Linux kernel.

Unlike Autotest and kselftest, KUnit is a true unit testing framework;
it does not require installing the kernel on a test machine or in a VM
(however, KUnit still allows you to run tests on test machines or in VMs
if you want[1]) and does not require tests to be written in userspace
running on a host kernel. Additionally, KUnit is fast: From invocation
to completion KUnit can run several dozen tests in about a second.
Currently, the entire KUnit test suite for KUnit runs in under a second
from the initial invocation (build time excluded).

KUnit is heavily inspired by JUnit, Python's unittest.mock, and
Googletest/Googlemock for C++. KUnit provides facilities for defining
unit test cases, grouping related test cases into test suites, providing
common infrastructure for running tests, mocking, spying, and much more.

### What's so special about unit testing?

A unit test is supposed to test a single unit of code in isolation,
hence the name. There should be no dependencies outside the control of
the test; this means no external dependencies, which makes tests orders
of magnitudes faster. Likewise, since there are no external dependencies,
there are no hoops to jump through to run the tests. Additionally, this
makes unit tests deterministic: a failing unit test always indicates a
problem. Finally, because unit tests necessarily have finer granularity,
they are able to test all code paths easily solving the classic problem
of difficulty in exercising error handling code.

### Is KUnit trying to replace other testing frameworks for the kernel?

No. Most existing tests for the Linux kernel are end-to-end tests, which
have their place. A well tested system has lots of unit tests, a
reasonable number of integration tests, and some end-to-end tests. KUnit
is just trying to address the unit test space which is currently not
being addressed.

### More information on KUnit

There is a bunch of documentation near the end of this patch set that
describes how to use KUnit and best practices for writing unit tests.
For convenience I am hosting the compiled docs here[2].

Additionally for convenience, I have applied these patches to a
branch[3]. The repo may be cloned with:
git clone https://kunit.googlesource.com/linux
This patchset is on the kunit/rfc/v5.3/v14 branch.

## Changes Since Last Version

- Removed to macros which helped define expectation and assertion
  macros; these values are now just copied and pasted. Change was made
  to fix checkpatch error, as suggested by Shuah.

[1] 
https://google.github.io/kunit-docs/third_party/kernel/docs/usage.html#kunit-on-non-uml-architectures
[2] https://google.github.io/kunit-docs/third_party/kernel/docs/
[3] https://kunit.googlesource.com/linux/+/kunit/rfc/v5.3/v14

-- 
2.23.0.rc1.153.gdeed80330f-goog

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH] drm/msm/dpu: fix "frame done" timeouts

2019-08-20 Thread Rob Clark
From: Rob Clark 

Previously, dpu_crtc_frame_event_work() would try to aquire all the
modeset locks in order to check whether it can release bandwidth.  (If
we only have cmd-mode display, bandwidth can be released at frame-done
time.)

The problem with this is that it is also responsible for signalling
frame_done_comp, which dpu_crtc_commit_kickoff() waits on if there is
already a frame pending.  This is called in the msm_atomic_commit_tail()
path.. which means that for non-nonblock commits, at least some of the
modeset locks are already held.

Re-work this scheme to use a reference count to track our need to have
clocks enabled.  It is incremented for each atomic commit, and
decremented in the corresponding frame-done.  Additionally, any crtc
used in video mode hold an extra reference while they are enabled.  The
net effect is that we can determine in frame-done whether it is safe to
drop bandwidth without needing to aquire any modeset locks.

Signed-off-by: Rob Clark 
---
 drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c | 16 +--
 drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c  | 45 +++
 drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c   |  2 +
 drivers/gpu/drm/msm/disp/dpu1/dpu_kms.h   |  8 
 4 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c 
b/drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c
index 5cda96875e03..09a49b59bb5b 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c
@@ -214,7 +214,6 @@ static int _dpu_core_perf_crtc_update_bus(struct dpu_kms 
*kms,
  */
 void dpu_core_perf_crtc_release_bw(struct drm_crtc *crtc)
 {
-   struct drm_crtc *tmp_crtc;
struct dpu_crtc *dpu_crtc;
struct dpu_crtc_state *dpu_cstate;
struct dpu_kms *kms;
@@ -233,22 +232,9 @@ void dpu_core_perf_crtc_release_bw(struct drm_crtc *crtc)
dpu_crtc = to_dpu_crtc(crtc);
dpu_cstate = to_dpu_crtc_state(crtc->state);
 
-   /* only do this for command mode rt client */
-   if (dpu_crtc_get_intf_mode(crtc) != INTF_MODE_CMD)
+   if (atomic_dec_return(>bandwidth_ref) > 0)
return;
 
-   /*
-* If video interface present, cmd panel bandwidth cannot be
-* released.
-*/
-   if (dpu_crtc_get_intf_mode(crtc) == INTF_MODE_CMD)
-   drm_for_each_crtc(tmp_crtc, crtc->dev) {
-   if (tmp_crtc->enabled &&
-   dpu_crtc_get_intf_mode(tmp_crtc) ==
-   INTF_MODE_VIDEO)
-   return;
-   }
-
/* Release the bandwidth */
if (kms->perf.enable_bw_release) {
trace_dpu_cmd_release_bw(crtc->base.id);
diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c 
b/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
index b3417d56032d..4e54550c4a80 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
@@ -292,19 +292,6 @@ void dpu_crtc_vblank_callback(struct drm_crtc *crtc)
trace_dpu_crtc_vblank_cb(DRMID(crtc));
 }
 
-static void dpu_crtc_release_bw_unlocked(struct drm_crtc *crtc)
-{
-   int ret = 0;
-   struct drm_modeset_acquire_ctx ctx;
-
-   DRM_MODESET_LOCK_ALL_BEGIN(crtc->dev, ctx, 0, ret);
-   dpu_core_perf_crtc_release_bw(crtc);
-   DRM_MODESET_LOCK_ALL_END(ctx, ret);
-   if (ret)
-   DRM_ERROR("Failed to acquire modeset locks to release bw, %d\n",
- ret);
-}
-
 static void dpu_crtc_frame_event_work(struct kthread_work *work)
 {
struct dpu_crtc_frame_event *fevent = container_of(work,
@@ -334,7 +321,7 @@ static void dpu_crtc_frame_event_work(struct kthread_work 
*work)
/* release bandwidth and other resources */
trace_dpu_crtc_frame_event_done(DRMID(crtc),
fevent->event);
-   dpu_crtc_release_bw_unlocked(crtc);
+   dpu_core_perf_crtc_release_bw(crtc);
} else {
trace_dpu_crtc_frame_event_more_pending(DRMID(crtc),
fevent->event);
@@ -650,7 +637,7 @@ void dpu_crtc_commit_kickoff(struct drm_crtc *crtc, bool 
async)
dpu_encoder_prepare_for_kickoff(encoder, async);
 
if (!async) {
-   /* wait for frame_event_done completion */
+   /* wait for previous frame_event_done completion */
DPU_ATRACE_BEGIN("wait_for_frame_done_event");
ret = _dpu_crtc_wait_for_frame_done(crtc);
DPU_ATRACE_END("wait_for_frame_done_event");
@@ -729,6 +716,7 @@ static void dpu_crtc_disable(struct drm_crtc *crtc,
struct drm_encoder *encoder;
struct msm_drm_private *priv;
unsigned long flags;
+   bool release_bandwidth 

[PATCH v5 25/25] drm: kirin: Move ade drm init to kirin drm drv

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch renames ade_data to
kirin_drm_private, and moves crtc_init and plane_init to
kirin drm drv too. Now that they are generic the functions
can be shared between the kirin620 and (to be added later)
kirin960 specific support code.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: Reworded commit message]
Signed-off-by: John Stultz 
---
v5: checkpatch --strict whitespace fixups noticed by Sam
---
 .../gpu/drm/hisilicon/kirin/kirin_drm_ade.c   | 125 
 .../gpu/drm/hisilicon/kirin/kirin_drm_drv.c   | 141 --
 .../gpu/drm/hisilicon/kirin/kirin_drm_drv.h   |   5 -
 3 files changed, 129 insertions(+), 142 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index bbdfeac946a7..73cd28a6ea07 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -53,13 +53,6 @@ struct ade_hw_ctx {
struct drm_crtc *crtc;
 };
 
-struct ade_data {
-   struct kirin_crtc crtc;
-   struct kirin_plane planes[ADE_CH_NUM];
-   struct ade_hw_ctx *hw_ctx;
-};
-
-/* ade-format info: */
 static const struct kirin_format ade_formats[] = {
/* 16bpp RGB: */
{ DRM_FORMAT_RGB565, ADE_RGB_565 },
@@ -571,36 +564,6 @@ static const struct drm_crtc_funcs ade_crtc_funcs = {
.disable_vblank = ade_crtc_disable_vblank,
 };
 
-static int kirin_drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
-  struct drm_plane *plane,
-  const struct kirin_drm_data *driver_data)
-{
-   struct device_node *port;
-   int ret;
-
-   /* set crtc port so that
-* drm_of_find_possible_crtcs call works
-*/
-   port = of_get_child_by_name(dev->dev->of_node, "port");
-   if (!port) {
-   DRM_ERROR("no port node found in %pOF\n", dev->dev->of_node);
-   return -EINVAL;
-   }
-   of_node_put(port);
-   crtc->port = port;
-
-   ret = drm_crtc_init_with_planes(dev, crtc, plane, NULL,
-   driver_data->crtc_funcs, NULL);
-   if (ret) {
-   DRM_ERROR("failed to init crtc.\n");
-   return ret;
-   }
-
-   drm_crtc_helper_add(crtc, driver_data->crtc_helper_funcs);
-
-   return 0;
-}
-
 static void ade_rdma_set(void __iomem *base, struct drm_framebuffer *fb,
 u32 ch, u32 y, u32 in_h, u32 fmt)
 {
@@ -893,28 +856,6 @@ static struct drm_plane_funcs ade_plane_funcs = {
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
 };
 
-static int kirin_drm_plane_init(struct drm_device *dev,
-   struct kirin_plane *kplane,
-   enum drm_plane_type type,
-   const struct kirin_drm_data *driver_data)
-{
-   int ret = 0;
-
-   ret = drm_universal_plane_init(dev, >base, 1,
-  driver_data->plane_funcs,
-  driver_data->channel_formats,
-  driver_data->channel_formats_cnt,
-  NULL, type, NULL);
-   if (ret) {
-   DRM_ERROR("fail to init plane, ch=%d\n", kplane->ch);
-   return ret;
-   }
-
-   drm_plane_helper_add(>base, driver_data->plane_helper_funcs);
-
-   return 0;
-}
-
 static void *ade_hw_ctx_alloc(struct platform_device *pdev,
  struct drm_crtc *crtc)
 {
@@ -984,73 +925,10 @@ static void *ade_hw_ctx_alloc(struct platform_device 
*pdev,
return ctx;
 }
 
-static int ade_drm_init(struct platform_device *pdev)
-{
-   struct drm_device *dev = platform_get_drvdata(pdev);
-   struct ade_data *ade;
-   struct ade_hw_ctx *ctx;
-   struct kirin_crtc *kcrtc;
-   struct kirin_plane *kplane;
-   enum drm_plane_type type;
-   int prim_plane;
-   int ret;
-   u32 ch;
-
-   ade = devm_kzalloc(dev->dev, sizeof(*ade), GFP_KERNEL);
-   if (!ade) {
-   DRM_ERROR("failed to alloc ade_data\n");
-   return -ENOMEM;
-   }
-
-   ctx = ade_driver_data.alloc_hw_ctx(pdev, >crtc.base);
-   if (IS_ERR(ctx)) {
-   DRM_ERROR("failed to initialize kirin_priv hw ctx\n");
-   return -EINVAL;
-   }
-   ade->hw_ctx = ctx;
-
-   kcrtc = >crtc;
-   kcrtc->hw_ctx = ctx;
-
-   /*
-* plane init
-* TODO: Now only support primary plane, overlay planes
-* need to do.
-*/
-   for (ch = 0; ch < ade_driver_data.num_planes; ch++) {
-   kplane = >planes[ch];
-  

[PATCH v5 22/25] drm: kirin: Make driver_data variable non-global

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch changes the driver_data
value to not be a global variable. Instead the driver_data value
is accessed via the of_device_get_match_data() when needed.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: Reworded commit message]
Signed-off-by: John Stultz 
---
v5: checkpatch --strict whitespace fixups noticed by Sam
---
 .../gpu/drm/hisilicon/kirin/kirin_drm_drv.c   | 43 +++
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
index 7f8d4539b1a9..f5df88378591 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
@@ -29,18 +29,9 @@
 
 #include "kirin_drm_drv.h"
 
-static struct kirin_drm_data *driver_data;
 
-static int kirin_drm_kms_cleanup(struct drm_device *dev)
-{
-   drm_kms_helper_poll_fini(dev);
-   driver_data->cleanup(to_platform_device(dev->dev));
-   drm_mode_config_cleanup(dev);
-
-   return 0;
-}
-
-static int kirin_drm_kms_init(struct drm_device *dev)
+static int kirin_drm_kms_init(struct drm_device *dev,
+ const struct kirin_drm_data *driver_data)
 {
int ret;
 
@@ -96,6 +87,21 @@ static int compare_of(struct device *dev, void *data)
return dev->of_node == data;
 }
 
+static int kirin_drm_kms_cleanup(struct drm_device *dev)
+{
+   const struct kirin_drm_data *driver_data;
+
+   drm_kms_helper_poll_fini(dev);
+
+   driver_data = of_device_get_match_data(dev->dev);
+   if (driver_data->cleanup)
+   driver_data->cleanup(to_platform_device(dev->dev));
+
+   drm_mode_config_cleanup(dev);
+
+   return 0;
+}
+
 static int kirin_drm_connectors_register(struct drm_device *dev)
 {
struct drm_connector *connector;
@@ -132,15 +138,21 @@ static int kirin_drm_connectors_register(struct 
drm_device *dev)
 
 static int kirin_drm_bind(struct device *dev)
 {
+   struct kirin_drm_data *driver_data;
struct drm_device *drm_dev;
int ret;
 
+   driver_data = (struct kirin_drm_data *)of_device_get_match_data(dev);
+   if (!driver_data)
+   return -EINVAL;
+
drm_dev = drm_dev_alloc(driver_data->driver, dev);
if (IS_ERR(drm_dev))
return PTR_ERR(drm_dev);
dev_set_drvdata(dev, drm_dev);
 
-   ret = kirin_drm_kms_init(drm_dev);
+   /* display controller init */
+   ret = kirin_drm_kms_init(drm_dev, driver_data);
if (ret)
goto err_drm_dev_put;
 
@@ -190,12 +202,6 @@ static int kirin_drm_platform_probe(struct platform_device 
*pdev)
struct component_match *match = NULL;
struct device_node *remote;
 
-   driver_data = (struct kirin_drm_data *)of_device_get_match_data(dev);
-   if (!driver_data) {
-   DRM_ERROR("failed to get dt id data\n");
-   return -EINVAL;
-   }
-
remote = of_graph_get_remote_node(np, 0, 0);
if (!remote)
return -ENODEV;
@@ -209,7 +215,6 @@ static int kirin_drm_platform_probe(struct platform_device 
*pdev)
 static int kirin_drm_platform_remove(struct platform_device *pdev)
 {
component_master_del(>dev, _drm_ops);
-   driver_data = NULL;
return 0;
 }
 
-- 
2.17.1



[PATCH v5 19/25] drm: kirin: Add register connect helper functions in drm init

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch adds a flag to the
device specific driver data so that we can conditionally
register the connectors at init.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: reworded commit message]
Signed-off-by: John Stultz 
---
v5: checkpatch --strict whitespace fixups noticed by Sam
---
 .../gpu/drm/hisilicon/kirin/kirin_drm_ade.c   |  1 +
 .../gpu/drm/hisilicon/kirin/kirin_drm_drv.c   | 43 +++
 .../gpu/drm/hisilicon/kirin/kirin_drm_drv.h   |  1 +
 3 files changed, 45 insertions(+)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index 21c5d457a97d..89bdc0388138 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -1073,6 +1073,7 @@ static struct drm_driver ade_driver = {
 };
 
 struct kirin_drm_data ade_driver_data = {
+   .register_connects = false,
.num_planes = ADE_CH_NUM,
.prim_plane = ADE_CH1,
.channel_formats = channel_formats,
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
index c9faaa848cc6..68de8838da3c 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
@@ -98,6 +98,40 @@ static int compare_of(struct device *dev, void *data)
return dev->of_node == data;
 }
 
+static int kirin_drm_connectors_register(struct drm_device *dev)
+{
+   struct drm_connector *connector;
+   struct drm_connector *failed_connector;
+   struct drm_connector_list_iter conn_iter;
+   int ret;
+
+   mutex_lock(>mode_config.mutex);
+   drm_connector_list_iter_begin(dev, _iter);
+   drm_for_each_connector_iter(connector, _iter) {
+   ret = drm_connector_register(connector);
+   if (ret) {
+   failed_connector = connector;
+   goto err;
+   }
+   }
+   drm_connector_list_iter_end(_iter);
+   mutex_unlock(>mode_config.mutex);
+
+   return 0;
+
+err:
+   drm_connector_list_iter_begin(dev, _iter);
+   drm_for_each_connector_iter(connector, _iter) {
+   if (failed_connector == connector)
+   break;
+   drm_connector_unregister(connector);
+   }
+   drm_connector_list_iter_end(_iter);
+   mutex_unlock(>mode_config.mutex);
+
+   return ret;
+}
+
 static int kirin_drm_bind(struct device *dev)
 {
struct drm_device *drm_dev;
@@ -117,8 +151,17 @@ static int kirin_drm_bind(struct device *dev)
 
drm_fbdev_generic_setup(drm_dev, 32);
 
+   /* connectors should be registered after drm device register */
+   if (driver_data->register_connects) {
+   ret = kirin_drm_connectors_register(drm_dev);
+   if (ret)
+   goto err_drm_dev_unregister;
+   }
+
return 0;
 
+err_drm_dev_unregister:
+   drm_dev_unregister(drm_dev);
 err_kms_cleanup:
kirin_drm_kms_cleanup(drm_dev);
 err_drm_dev_put:
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
index fdbfc4a90f22..95f56c9960d5 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
@@ -39,6 +39,7 @@ struct kirin_drm_data {
u32 channel_formats_cnt;
int config_max_width;
int config_max_height;
+   bool register_connects;
u32 num_planes;
u32 prim_plane;
 
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v5 23/25] drm: kirin: Add alloc_hw_ctx/clean_hw_ctx ops in driver data

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch changes the
alloc/clean_hw_ctx functions to be called via driver_data
specific funciton pointers.

This will allow the ade_drm_init to later be made generic and
moved to kirin_drm_drv.c

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: Reworded commit message]
Signed-off-by: John Stultz 
---
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c | 9 -
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h | 5 +
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index d8e40fcff386..a2bb2b75be4b 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -1000,7 +1000,7 @@ static int ade_drm_init(struct platform_device *pdev)
return -ENOMEM;
}
 
-   ctx = ade_hw_ctx_alloc(pdev, >crtc.base);
+   ctx = ade_driver_data.alloc_hw_ctx(pdev, >crtc.base);
if (IS_ERR(ctx)) {
DRM_ERROR("failed to initialize kirin_priv hw ctx\n");
return -EINVAL;
@@ -1040,6 +1040,10 @@ static int ade_drm_init(struct platform_device *pdev)
return 0;
 }
 
+static void ade_hw_ctx_cleanup(void *hw_ctx)
+{
+}
+
 static void ade_drm_cleanup(struct platform_device *pdev)
 {
 }
@@ -1089,6 +1093,9 @@ struct kirin_drm_data ade_driver_data = {
.plane_funcs = _plane_funcs,
.mode_config_funcs = _mode_config_funcs,
 
+   .alloc_hw_ctx = ade_hw_ctx_alloc,
+   .cleanup_hw_ctx = ade_hw_ctx_cleanup,
+
.init = ade_drm_init,
.cleanup = ade_drm_cleanup
 };
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
index 95f56c9960d5..1663610d2cd8 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
@@ -49,6 +49,11 @@ struct kirin_drm_data {
const struct drm_plane_helper_funcs *plane_helper_funcs;
const struct drm_plane_funcs  *plane_funcs;
const struct drm_mode_config_funcs *mode_config_funcs;
+
+   void *(*alloc_hw_ctx)(struct platform_device *pdev,
+ struct drm_crtc *crtc);
+   void (*cleanup_hw_ctx)(void *hw_ctx);
+
int (*init)(struct platform_device *pdev);
void (*cleanup)(struct platform_device *pdev);
 };
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v5 15/25] drm: kirin: Move mode config function to driver_data

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch moves the mode config
initialization values into the kirin_drm_data structure.

This will make it easier to add support for new devices
via a new kirin_drm_data structure.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
Signed-off-by: John Stultz 
---
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c | 10 ++
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c |  8 +---
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h |  2 +-
 3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index 0489b6378e01..94d74c467a81 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "kirin_drm_drv.h"
 #include "kirin_ade_reg.h"
@@ -1038,6 +1039,13 @@ static void ade_drm_cleanup(struct platform_device *pdev)
 {
 }
 
+static const struct drm_mode_config_funcs ade_mode_config_funcs = {
+   .fb_create = drm_gem_fb_create,
+   .atomic_check = drm_atomic_helper_check,
+   .atomic_commit = drm_atomic_helper_commit,
+
+};
+
 struct kirin_drm_data ade_driver_data = {
.channel_formats = channel_formats,
.channel_formats_cnt = ARRAY_SIZE(channel_formats),
@@ -1045,6 +1053,8 @@ struct kirin_drm_data ade_driver_data = {
.crtc_funcs = _crtc_funcs,
.plane_helper_funcs = _plane_helper_funcs,
.plane_funcs = _plane_funcs,
+   .mode_config_funcs = _mode_config_funcs,
+
.init = ade_drm_init,
.cleanup = ade_drm_cleanup
 };
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
index 3d22f944a840..25191824b64e 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
@@ -40,12 +40,6 @@ static int kirin_drm_kms_cleanup(struct drm_device *dev)
return 0;
 }
 
-static const struct drm_mode_config_funcs kirin_drm_mode_config_funcs = {
-   .fb_create = drm_gem_fb_create,
-   .atomic_check = drm_atomic_helper_check,
-   .atomic_commit = drm_atomic_helper_commit,
-};
-
 static void kirin_drm_mode_config_init(struct drm_device *dev)
 {
dev->mode_config.min_width = 0;
@@ -54,7 +48,7 @@ static void kirin_drm_mode_config_init(struct drm_device *dev)
dev->mode_config.max_width = 2048;
dev->mode_config.max_height = 2048;
 
-   dev->mode_config.funcs = _drm_mode_config_funcs;
+   dev->mode_config.funcs = driver_data->mode_config_funcs;
 }
 
 static int kirin_drm_kms_init(struct drm_device *dev)
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
index 66916502a9e6..ce9ddccc67a8 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
@@ -42,7 +42,7 @@ struct kirin_drm_data {
const struct drm_crtc_funcs *crtc_funcs;
const struct drm_plane_helper_funcs *plane_helper_funcs;
const struct drm_plane_funcs  *plane_funcs;
-
+   const struct drm_mode_config_funcs *mode_config_funcs;
int (*init)(struct platform_device *pdev);
void (*cleanup)(struct platform_device *pdev);
 };
-- 
2.17.1



[PATCH v5 01/25] drm: kirin: Fix for hikey620 display offset problem

2019-08-20 Thread John Stultz
From: Da Lv 

The original HiKey (620) board has had a long running issue
where when using a 1080p montior, the display would occasionally
blink and come come back with a horizontal offset (usually also
shifting the colors, depending on the value of the offset%4).

After lots of analysis by HiSi developers, they found the issue
was due to when running at 1080p, it was possible to hit the
device memory bandwidth limits, which could cause the DSI signal
to get out of sync.

Unfortunately the DSI logic doesn't have the ability to
automatically recover from this situation, but we can get a an
LDI underflow interrupt when it happens.

To then correct the issue, when we get an LDI underflow irq, we
we can simply suspend and resume the display, which resets the
hardware.

Thus, this patch enables the ldi underflow interrupt, and
initializes a workqueue that is used to suspend/resume the
display to recover. Then when the irq occurs we clear it and
schedule the workqueue to reset display engine.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Da Lv 
Signed-off-by: Yidong Lin 
[jstultz: Reworded the commit message, checkpatch cleanups]
Signed-off-by: John Stultz 
---
v2: Minor cleanups

v3: Rename workqueue entry for clarity (suggested by Sam)
---
 .../gpu/drm/hisilicon/kirin/kirin_ade_reg.h   |  1 +
 .../gpu/drm/hisilicon/kirin/kirin_drm_ade.c   | 22 +++
 2 files changed, 23 insertions(+)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_ade_reg.h 
b/drivers/gpu/drm/hisilicon/kirin/kirin_ade_reg.h
index e2ac09894a6d..0da860200410 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_ade_reg.h
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_ade_reg.h
@@ -83,6 +83,7 @@
 #define VSIZE_OFST 20
 #define LDI_INT_EN 0x741C
 #define FRAME_END_INT_EN_OFST  1
+#define UNDERFLOW_INT_EN_OFST  2
 #define LDI_CTRL   0x7420
 #define BPP_OFST   3
 #define DATA_GATE_EN   BIT(2)
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index 0df1afdf319d..d972342527b8 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -58,6 +58,7 @@ struct ade_hw_ctx {
 struct ade_crtc {
struct drm_crtc base;
struct ade_hw_ctx *ctx;
+   struct work_struct display_reset_wq;
bool enable;
u32 out_format;
 };
@@ -176,6 +177,7 @@ static void ade_init(struct ade_hw_ctx *ctx)
 */
ade_update_bits(base + ADE_CTRL, FRM_END_START_OFST,
FRM_END_START_MASK, REG_EFFECTIVE_IN_ADEEN_FRMEND);
+   ade_update_bits(base + LDI_INT_EN, UNDERFLOW_INT_EN_OFST, MASK(1), 1);
 }
 
 static bool ade_crtc_mode_fixup(struct drm_crtc *crtc,
@@ -345,6 +347,17 @@ static void ade_crtc_disable_vblank(struct drm_crtc *crtc)
MASK(1), 0);
 }
 
+static void drm_underflow_wq(struct work_struct *work)
+{
+   struct ade_crtc *acrtc = container_of(work, struct ade_crtc,
+ display_reset_wq);
+   struct drm_device *drm_dev = (>base)->dev;
+   struct drm_atomic_state *state;
+
+   state = drm_atomic_helper_suspend(drm_dev);
+   drm_atomic_helper_resume(drm_dev, state);
+}
+
 static irqreturn_t ade_irq_handler(int irq, void *data)
 {
struct ade_crtc *acrtc = data;
@@ -362,6 +375,12 @@ static irqreturn_t ade_irq_handler(int irq, void *data)
MASK(1), 1);
drm_crtc_handle_vblank(crtc);
}
+   if (status & BIT(UNDERFLOW_INT_EN_OFST)) {
+   ade_update_bits(base + LDI_INT_CLR, UNDERFLOW_INT_EN_OFST,
+   MASK(1), 1);
+   DRM_ERROR("LDI underflow!");
+   schedule_work(>display_reset_wq);
+   }
 
return IRQ_HANDLED;
 }
@@ -1038,6 +1057,9 @@ static int ade_drm_init(struct platform_device *pdev)
/* vblank irq init */
ret = devm_request_irq(dev->dev, ctx->irq, ade_irq_handler,
   IRQF_SHARED, dev->driver->name, acrtc);
+
+   INIT_WORK(>display_reset_wq, drm_underflow_wq);
+
if (ret)
return ret;
 
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v5 08/25] drm: kirin: Dynamically allocate the hw_ctx

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch modifies the
initialization function to dynamically allocate the ade_hw_ctx
structure previously kept as part of struct ade_data.

This is done so that later we can have the hw_ctx point to
hardware revision specific ctx structures.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: reworded commit message]
Signed-off-by: John Stultz 
---
 .../gpu/drm/hisilicon/kirin/kirin_drm_ade.c   | 39 ---
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index fce374ec69e8..ecb507985fea 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -72,7 +72,7 @@ struct kirin_plane {
 struct ade_data {
struct kirin_crtc crtc;
struct kirin_plane planes[ADE_CH_NUM];
-   struct ade_hw_ctx ctx;
+   struct ade_hw_ctx *hw_ctx;
 };
 
 /* ade-format info: */
@@ -951,55 +951,62 @@ static int ade_plane_init(struct drm_device *dev, struct 
kirin_plane *kplane,
return 0;
 }
 
-static int ade_dts_parse(struct platform_device *pdev, struct ade_hw_ctx *ctx)
+static void *ade_hw_ctx_alloc(struct platform_device *pdev)
 {
struct resource *res;
struct device *dev = >dev;
struct device_node *np = pdev->dev.of_node;
+   struct ade_hw_ctx *ctx = NULL;
+
+   ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+   if (!ctx) {
+   DRM_ERROR("failed to alloc ade_hw_ctx\n");
+   return ERR_PTR(-ENOMEM);
+   }
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
ctx->base = devm_ioremap_resource(dev, res);
if (IS_ERR(ctx->base)) {
DRM_ERROR("failed to remap ade io base\n");
-   return  PTR_ERR(ctx->base);
+   return ERR_PTR(-EIO);
}
 
ctx->reset = devm_reset_control_get(dev, NULL);
if (IS_ERR(ctx->reset))
-   return PTR_ERR(ctx->reset);
+   return ERR_PTR(-ENODEV);
 
ctx->noc_regmap =
syscon_regmap_lookup_by_phandle(np, "hisilicon,noc-syscon");
if (IS_ERR(ctx->noc_regmap)) {
DRM_ERROR("failed to get noc regmap\n");
-   return PTR_ERR(ctx->noc_regmap);
+   return ERR_PTR(-ENODEV);
}
 
ctx->irq = platform_get_irq(pdev, 0);
if (ctx->irq < 0) {
DRM_ERROR("failed to get irq\n");
-   return -ENODEV;
+   return ERR_PTR(-ENODEV);
}
 
ctx->ade_core_clk = devm_clk_get(dev, "clk_ade_core");
if (IS_ERR(ctx->ade_core_clk)) {
DRM_ERROR("failed to parse clk ADE_CORE\n");
-   return PTR_ERR(ctx->ade_core_clk);
+   return ERR_PTR(-ENODEV);
}
 
ctx->media_noc_clk = devm_clk_get(dev, "clk_codec_jpeg");
if (IS_ERR(ctx->media_noc_clk)) {
DRM_ERROR("failed to parse clk CODEC_JPEG\n");
-   return PTR_ERR(ctx->media_noc_clk);
+   return ERR_PTR(-ENODEV);
}
 
ctx->ade_pix_clk = devm_clk_get(dev, "clk_ade_pix");
if (IS_ERR(ctx->ade_pix_clk)) {
DRM_ERROR("failed to parse clk ADE_PIX\n");
-   return PTR_ERR(ctx->ade_pix_clk);
+   return ERR_PTR(-ENODEV);
}
 
-   return 0;
+   return ctx;
 }
 
 static int ade_drm_init(struct platform_device *pdev)
@@ -1020,14 +1027,16 @@ static int ade_drm_init(struct platform_device *pdev)
}
platform_set_drvdata(pdev, ade);
 
-   ctx = >ctx;
+   ctx = ade_hw_ctx_alloc(pdev);
+   if (IS_ERR(ctx)) {
+   DRM_ERROR("failed to initialize kirin_priv hw ctx\n");
+   return -EINVAL;
+   }
+   ade->hw_ctx = ctx;
+
kcrtc = >crtc;
kcrtc->hw_ctx = ctx;
 
-   ret = ade_dts_parse(pdev, ctx);
-   if (ret)
-   return ret;
-
/*
 * plane init
 * TODO: Now only support primary plane, overlay planes
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v5 16/25] drm: kirin: Move plane number and primay plane in driver data

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch moves the number of
planes and the primary plane value to the kirin_drm_data
structure

This will make it easier to add support for new devices
via a new kirin_drm_data structure.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
Signed-off-by: John Stultz 
---
v5: checkpatch --strict whitespace fixups noticed by Sam
---
 .../gpu/drm/hisilicon/kirin/kirin_drm_ade.c   | 21 ---
 .../gpu/drm/hisilicon/kirin/kirin_drm_drv.h   |  2 ++
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index 94d74c467a81..a74b2623dbbb 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -35,7 +35,6 @@
 #include "kirin_drm_drv.h"
 #include "kirin_ade_reg.h"
 
-#define PRIMARY_CH ADE_CH1 /* primary plane */
 #define OUT_OVLY   ADE_OVLY2 /* output overlay compositor */
 #define ADE_DEBUG  1
 
@@ -991,7 +990,7 @@ static int ade_drm_init(struct platform_device *pdev)
struct kirin_plane *kplane;
enum drm_plane_type type;
int ret;
-   int i;
+   u32 ch;
 
ade = devm_kzalloc(dev->dev, sizeof(*ade), GFP_KERNEL);
if (!ade) {
@@ -1015,12 +1014,15 @@ static int ade_drm_init(struct platform_device *pdev)
 * TODO: Now only support primary plane, overlay planes
 * need to do.
 */
-   for (i = 0; i < ADE_CH_NUM; i++) {
-   kplane = >planes[i];
-   kplane->ch = i;
+   for (ch = 0; ch < ade_driver_data.num_planes; ch++) {
+   kplane = >planes[ch];
+   kplane->ch = ch;
kplane->hw_ctx = ctx;
-   type = i == PRIMARY_CH ? DRM_PLANE_TYPE_PRIMARY :
-   DRM_PLANE_TYPE_OVERLAY;
+
+   if (ch == ade_driver_data.prim_plane)
+   type = DRM_PLANE_TYPE_PRIMARY;
+   else
+   type = DRM_PLANE_TYPE_OVERLAY;
 
ret = ade_plane_init(dev, kplane, type);
if (ret)
@@ -1028,7 +1030,8 @@ static int ade_drm_init(struct platform_device *pdev)
}
 
/* crtc init */
-   ret = ade_crtc_init(dev, >base, >planes[PRIMARY_CH].base);
+   ret = ade_crtc_init(dev, >base,
+   >planes[ade_driver_data.prim_plane].base);
if (ret)
return ret;
 
@@ -1047,6 +1050,8 @@ static const struct drm_mode_config_funcs 
ade_mode_config_funcs = {
 };
 
 struct kirin_drm_data ade_driver_data = {
+   .num_planes = ADE_CH_NUM,
+   .prim_plane = ADE_CH1,
.channel_formats = channel_formats,
.channel_formats_cnt = ARRAY_SIZE(channel_formats),
.crtc_helper_funcs = _crtc_helper_funcs,
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
index ce9ddccc67a8..2b660df60293 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
@@ -37,6 +37,8 @@ struct kirin_plane {
 struct kirin_drm_data {
const u32 *channel_formats;
u32 channel_formats_cnt;
+   u32 num_planes;
+   u32 prim_plane;
 
const struct drm_crtc_helper_funcs *crtc_helper_funcs;
const struct drm_crtc_funcs *crtc_funcs;
-- 
2.17.1



[PATCH v5 04/25] drm: kirin: Remove uncessary parameter indirection

2019-08-20 Thread John Stultz
From: Xu YiPing 

In a few functions, we pass in a struct ade_crtc, which we only
use to get to the underlying struct ade_hw_ctx.

Thus this patch refactors the functions to just take the
struct ade_hw_ctx directly.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: reworded commit message]
Signed-off-by: John Stultz 
---
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index d972342527b8..45351934d919 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -210,11 +210,10 @@ static void ade_set_pix_clk(struct ade_hw_ctx *ctx,
adj_mode->clock = clk_get_rate(ctx->ade_pix_clk) / 1000;
 }
 
-static void ade_ldi_set_mode(struct ade_crtc *acrtc,
+static void ade_ldi_set_mode(struct ade_hw_ctx *ctx,
 struct drm_display_mode *mode,
 struct drm_display_mode *adj_mode)
 {
-   struct ade_hw_ctx *ctx = acrtc->ctx;
void __iomem *base = ctx->base;
u32 width = mode->hdisplay;
u32 height = mode->vdisplay;
@@ -301,9 +300,8 @@ static void ade_power_down(struct ade_hw_ctx *ctx)
ctx->power_on = false;
 }
 
-static void ade_set_medianoc_qos(struct ade_crtc *acrtc)
+static void ade_set_medianoc_qos(struct ade_hw_ctx *ctx)
 {
-   struct ade_hw_ctx *ctx = acrtc->ctx;
struct regmap *map = ctx->noc_regmap;
 
regmap_update_bits(map, ADE0_QOSGENERATOR_MODE,
@@ -515,7 +513,7 @@ static void ade_crtc_atomic_enable(struct drm_crtc *crtc,
return;
}
 
-   ade_set_medianoc_qos(acrtc);
+   ade_set_medianoc_qos(ctx);
ade_display_enable(acrtc);
ade_dump_regs(ctx->base);
drm_crtc_vblank_on(crtc);
@@ -545,7 +543,7 @@ static void ade_crtc_mode_set_nofb(struct drm_crtc *crtc)
 
if (!ctx->power_on)
(void)ade_power_up(ctx);
-   ade_ldi_set_mode(acrtc, mode, adj_mode);
+   ade_ldi_set_mode(ctx, mode, adj_mode);
 }
 
 static void ade_crtc_atomic_begin(struct drm_crtc *crtc,
@@ -558,7 +556,7 @@ static void ade_crtc_atomic_begin(struct drm_crtc *crtc,
 
if (!ctx->power_on)
(void)ade_power_up(ctx);
-   ade_ldi_set_mode(acrtc, mode, adj_mode);
+   ade_ldi_set_mode(ctx, mode, adj_mode);
 }
 
 static void ade_crtc_atomic_flush(struct drm_crtc *crtc,
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v5 17/25] drm: kirin: Move config max_width and max_height to driver data

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch moves the max_width
and max_height values used in kirin_drm_mode_config_inita to
hardware specific driver data.

This will make it easier to add support for new devices
via a new kirin_drm_data structure.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: reworded commit message]
Signed-off-by: John Stultz 
---
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c |  2 ++
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c | 17 +
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h |  2 ++
 3 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index a74b2623dbbb..a4cf122375ea 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -1054,6 +1054,8 @@ struct kirin_drm_data ade_driver_data = {
.prim_plane = ADE_CH1,
.channel_formats = channel_formats,
.channel_formats_cnt = ARRAY_SIZE(channel_formats),
+   .config_max_width = 2048,
+   .config_max_height = 2048,
.crtc_helper_funcs = _crtc_helper_funcs,
.crtc_funcs = _crtc_funcs,
.plane_helper_funcs = _plane_helper_funcs,
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
index 25191824b64e..2ab32c2e3f95 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
@@ -40,17 +40,6 @@ static int kirin_drm_kms_cleanup(struct drm_device *dev)
return 0;
 }
 
-static void kirin_drm_mode_config_init(struct drm_device *dev)
-{
-   dev->mode_config.min_width = 0;
-   dev->mode_config.min_height = 0;
-
-   dev->mode_config.max_width = 2048;
-   dev->mode_config.max_height = 2048;
-
-   dev->mode_config.funcs = driver_data->mode_config_funcs;
-}
-
 static int kirin_drm_kms_init(struct drm_device *dev)
 {
int ret;
@@ -59,7 +48,11 @@ static int kirin_drm_kms_init(struct drm_device *dev)
 
/* dev->mode_config initialization */
drm_mode_config_init(dev);
-   kirin_drm_mode_config_init(dev);
+   dev->mode_config.min_width = 0;
+   dev->mode_config.min_height = 0;
+   dev->mode_config.max_width = driver_data->config_max_width;
+   dev->mode_config.max_height = driver_data->config_max_width;
+   dev->mode_config.funcs = driver_data->mode_config_funcs;
 
/* display controller init */
ret = driver_data->init(to_platform_device(dev->dev));
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
index 2b660df60293..43be65f82a03 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
@@ -37,6 +37,8 @@ struct kirin_plane {
 struct kirin_drm_data {
const u32 *channel_formats;
u32 channel_formats_cnt;
+   int config_max_width;
+   int config_max_height;
u32 num_planes;
u32 prim_plane;
 
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v5 18/25] drm: kirin: Move drm driver to driver data

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch moves the drm_driver
structure to be under device specific driver data.

This will allow us to more easily add support for kirin960
hardware with later patches.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: Reworded commit message]
Signed-off-by: John Stultz 
---
 .../gpu/drm/hisilicon/kirin/kirin_drm_ade.c   | 24 +
 .../gpu/drm/hisilicon/kirin/kirin_drm_drv.c   | 35 +--
 .../gpu/drm/hisilicon/kirin/kirin_drm_drv.h   |  1 +
 3 files changed, 26 insertions(+), 34 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index a4cf122375ea..21c5d457a97d 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -1049,6 +1049,29 @@ static const struct drm_mode_config_funcs 
ade_mode_config_funcs = {
 
 };
 
+DEFINE_DRM_GEM_CMA_FOPS(ade_fops);
+
+static struct drm_driver ade_driver = {
+   .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
+   .fops = _fops,
+   .gem_free_object_unlocked = drm_gem_cma_free_object,
+   .gem_vm_ops = _gem_cma_vm_ops,
+   .dumb_create = drm_gem_cma_dumb_create_internal,
+   .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
+   .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
+   .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
+   .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table,
+   .gem_prime_vmap = drm_gem_cma_prime_vmap,
+   .gem_prime_vunmap = drm_gem_cma_prime_vunmap,
+   .gem_prime_mmap = drm_gem_cma_prime_mmap,
+
+   .name = "kirin",
+   .desc = "Hisilicon Kirin620 SoC DRM Driver",
+   .date = "20150718",
+   .major = 1,
+   .minor = 0,
+};
+
 struct kirin_drm_data ade_driver_data = {
.num_planes = ADE_CH_NUM,
.prim_plane = ADE_CH1,
@@ -1056,6 +1079,7 @@ struct kirin_drm_data ade_driver_data = {
.channel_formats_cnt = ARRAY_SIZE(channel_formats),
.config_max_width = 2048,
.config_max_height = 2048,
+   .driver = _driver,
.crtc_helper_funcs = _crtc_helper_funcs,
.crtc_funcs = _crtc_funcs,
.plane_helper_funcs = _plane_helper_funcs,
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
index 2ab32c2e3f95..c9faaa848cc6 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
@@ -93,38 +93,6 @@ static int kirin_drm_kms_init(struct drm_device *dev)
return ret;
 }
 
-DEFINE_DRM_GEM_CMA_FOPS(kirin_drm_fops);
-
-static int kirin_gem_cma_dumb_create(struct drm_file *file,
-struct drm_device *dev,
-struct drm_mode_create_dumb *args)
-{
-   return drm_gem_cma_dumb_create_internal(file, dev, args);
-}
-
-static struct drm_driver kirin_drm_driver = {
-   .driver_features= DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
-   .fops   = _drm_fops,
-
-   .gem_free_object_unlocked = drm_gem_cma_free_object,
-   .gem_vm_ops = _gem_cma_vm_ops,
-   .dumb_create= kirin_gem_cma_dumb_create,
-
-   .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
-   .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
-   .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
-   .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table,
-   .gem_prime_vmap = drm_gem_cma_prime_vmap,
-   .gem_prime_vunmap   = drm_gem_cma_prime_vunmap,
-   .gem_prime_mmap = drm_gem_cma_prime_mmap,
-
-   .name   = "kirin",
-   .desc   = "Hisilicon Kirin SoCs' DRM Driver",
-   .date   = "20150718",
-   .major  = 1,
-   .minor  = 0,
-};
-
 static int compare_of(struct device *dev, void *data)
 {
return dev->of_node == data;
@@ -132,11 +100,10 @@ static int compare_of(struct device *dev, void *data)
 
 static int kirin_drm_bind(struct device *dev)
 {
-   struct drm_driver *driver = _drm_driver;
struct drm_device *drm_dev;
int ret;
 
-   drm_dev = drm_dev_alloc(driver, dev);
+   drm_dev = drm_dev_alloc(driver_data->driver, dev);
if (IS_ERR(drm_dev))
return PTR_ERR(drm_dev);
 
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
index 43be65f82a03..fdbfc4a90f22 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
@@ -42,6 +42,7 @@ struct kirin_drm_data 

[PATCH v5 20/25] drm: kirin: Rename plane_init and crtc_init

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch renames
ade_crtc/plane_init kirin_plane/crtc_init, as they will later be
moved to kirin drm drv and shared with the kirin960 hardware
support.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: reworded commit message]
Signed-off-by: John Stultz 
---
v5: checkpatch --strict whitespace fixups noticed by Sam
---
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index 89bdc0388138..e390b1b657b8 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -571,8 +571,8 @@ static const struct drm_crtc_funcs ade_crtc_funcs = {
.disable_vblank = ade_crtc_disable_vblank,
 };
 
-static int ade_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
-struct drm_plane *plane)
+static int kirin_drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
+  struct drm_plane *plane)
 {
struct device_node *port;
int ret;
@@ -892,8 +892,9 @@ static struct drm_plane_funcs ade_plane_funcs = {
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
 };
 
-static int ade_plane_init(struct drm_device *dev, struct kirin_plane *kplane,
- enum drm_plane_type type)
+static int kirin_drm_plane_init(struct drm_device *dev,
+   struct kirin_plane *kplane,
+   enum drm_plane_type type)
 {
int ret = 0;
 
@@ -989,6 +990,7 @@ static int ade_drm_init(struct platform_device *pdev)
struct kirin_crtc *kcrtc;
struct kirin_plane *kplane;
enum drm_plane_type type;
+   int prim_plane;
int ret;
u32 ch;
 
@@ -1024,14 +1026,15 @@ static int ade_drm_init(struct platform_device *pdev)
else
type = DRM_PLANE_TYPE_OVERLAY;
 
-   ret = ade_plane_init(dev, kplane, type);
+   ret = kirin_drm_plane_init(dev, kplane, type);
if (ret)
return ret;
}
 
/* crtc init */
-   ret = ade_crtc_init(dev, >base,
-   >planes[ade_driver_data.prim_plane].base);
+   prim_plane = ade_driver_data.prim_plane;
+   ret = kirin_drm_crtc_init(dev, >base,
+ >planes[prim_plane].base);
if (ret)
return ret;
 
-- 
2.17.1



[PATCH v5 21/25] drm: kirin: Fix dev->driver_data setting

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch changes the
dev->driver_data to point to a drm_device, not ade_data.

Thus we set the driver data to drm device after alloc.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: Reworded commit message]
Signed-off-by: John Stultz 
---
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c | 1 -
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c | 3 +--
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index e390b1b657b8..d8e40fcff386 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -999,7 +999,6 @@ static int ade_drm_init(struct platform_device *pdev)
DRM_ERROR("failed to alloc ade_data\n");
return -ENOMEM;
}
-   platform_set_drvdata(pdev, ade);
 
ctx = ade_hw_ctx_alloc(pdev, >crtc.base);
if (IS_ERR(ctx)) {
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
index 68de8838da3c..7f8d4539b1a9 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
@@ -44,8 +44,6 @@ static int kirin_drm_kms_init(struct drm_device *dev)
 {
int ret;
 
-   dev_set_drvdata(dev->dev, dev);
-
/* dev->mode_config initialization */
drm_mode_config_init(dev);
dev->mode_config.min_width = 0;
@@ -140,6 +138,7 @@ static int kirin_drm_bind(struct device *dev)
drm_dev = drm_dev_alloc(driver_data->driver, dev);
if (IS_ERR(drm_dev))
return PTR_ERR(drm_dev);
+   dev_set_drvdata(dev, drm_dev);
 
ret = kirin_drm_kms_init(drm_dev);
if (ret)
-- 
2.17.1



[PATCH v5 24/25] drm: kirin: Pass driver data to crtc init and plane init

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch changes the code
via a passed in driver_data pointer, rather than hardcoding
them via ade_driver_data variable.

This will allow those funcitons to be later moved to the
generic kirin_drm_drv.c using alternative driver_data structures
that support other hardware.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: Reworded commit message]
Signed-off-by: John Stultz 
---
v2: Whitespace fixups, commit message tweaks suggested by Sam.
v5: checkpatch --strict whitespace fixups noticed by Sam
---
 .../gpu/drm/hisilicon/kirin/kirin_drm_ade.c   | 23 +++
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index a2bb2b75be4b..bbdfeac946a7 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -572,7 +572,8 @@ static const struct drm_crtc_funcs ade_crtc_funcs = {
 };
 
 static int kirin_drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
-  struct drm_plane *plane)
+  struct drm_plane *plane,
+  const struct kirin_drm_data *driver_data)
 {
struct device_node *port;
int ret;
@@ -589,13 +590,13 @@ static int kirin_drm_crtc_init(struct drm_device *dev, 
struct drm_crtc *crtc,
crtc->port = port;
 
ret = drm_crtc_init_with_planes(dev, crtc, plane, NULL,
-   ade_driver_data.crtc_funcs, NULL);
+   driver_data->crtc_funcs, NULL);
if (ret) {
DRM_ERROR("failed to init crtc.\n");
return ret;
}
 
-   drm_crtc_helper_add(crtc, ade_driver_data.crtc_helper_funcs);
+   drm_crtc_helper_add(crtc, driver_data->crtc_helper_funcs);
 
return 0;
 }
@@ -894,21 +895,22 @@ static struct drm_plane_funcs ade_plane_funcs = {
 
 static int kirin_drm_plane_init(struct drm_device *dev,
struct kirin_plane *kplane,
-   enum drm_plane_type type)
+   enum drm_plane_type type,
+   const struct kirin_drm_data *driver_data)
 {
int ret = 0;
 
ret = drm_universal_plane_init(dev, >base, 1,
-  ade_driver_data.plane_funcs,
-  ade_driver_data.channel_formats,
-  ade_driver_data.channel_formats_cnt,
+  driver_data->plane_funcs,
+  driver_data->channel_formats,
+  driver_data->channel_formats_cnt,
   NULL, type, NULL);
if (ret) {
DRM_ERROR("fail to init plane, ch=%d\n", kplane->ch);
return ret;
}
 
-   drm_plane_helper_add(>base, ade_driver_data.plane_helper_funcs);
+   drm_plane_helper_add(>base, driver_data->plane_helper_funcs);
 
return 0;
 }
@@ -1025,7 +1027,7 @@ static int ade_drm_init(struct platform_device *pdev)
else
type = DRM_PLANE_TYPE_OVERLAY;
 
-   ret = kirin_drm_plane_init(dev, kplane, type);
+   ret = kirin_drm_plane_init(dev, kplane, type, _driver_data);
if (ret)
return ret;
}
@@ -1033,7 +1035,8 @@ static int ade_drm_init(struct platform_device *pdev)
/* crtc init */
prim_plane = ade_driver_data.prim_plane;
ret = kirin_drm_crtc_init(dev, >base,
- >planes[prim_plane].base);
+ >planes[prim_plane].base,
+ _driver_data);
if (ret)
return ret;
 
-- 
2.17.1



[PATCH v5 09/25] drm: kirin: Move request irq handle in ade hw ctx alloc

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch modifies the
initialization routines so the devm_request_irq() function
is called as part of the allocation function.

This will be needed in the future when we will have different
allocation functions to allocate hardware specific hw_ctx
structures, which will setup the vblank irq differently.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: reworded commit message]
Signed-off-by: John Stultz 
---
v5: checkpatch --strict whitespace fixups noticed by Sam
---
 .../gpu/drm/hisilicon/kirin/kirin_drm_ade.c   | 29 +++
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index ecb507985fea..d0a7c1d0adbe 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -54,6 +54,8 @@ struct ade_hw_ctx {
struct reset_control *reset;
bool power_on;
int irq;
+
+   struct drm_crtc *crtc;
 };
 
 struct kirin_crtc {
@@ -358,9 +360,9 @@ static void drm_underflow_wq(struct work_struct *work)
 
 static irqreturn_t ade_irq_handler(int irq, void *data)
 {
-   struct kirin_crtc *kcrtc = data;
-   struct ade_hw_ctx *ctx = kcrtc->hw_ctx;
-   struct drm_crtc *crtc = >base;
+   struct ade_hw_ctx *ctx = data;
+   struct drm_crtc *crtc = ctx->crtc;
+   struct kirin_crtc *kcrtc = to_kirin_crtc(crtc);
void __iomem *base = ctx->base;
u32 status;
 
@@ -951,12 +953,14 @@ static int ade_plane_init(struct drm_device *dev, struct 
kirin_plane *kplane,
return 0;
 }
 
-static void *ade_hw_ctx_alloc(struct platform_device *pdev)
+static void *ade_hw_ctx_alloc(struct platform_device *pdev,
+ struct drm_crtc *crtc)
 {
struct resource *res;
struct device *dev = >dev;
struct device_node *np = pdev->dev.of_node;
struct ade_hw_ctx *ctx = NULL;
+   int ret;
 
ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
if (!ctx) {
@@ -1006,6 +1010,14 @@ static void *ade_hw_ctx_alloc(struct platform_device 
*pdev)
return ERR_PTR(-ENODEV);
}
 
+   /* vblank irq init */
+   ret = devm_request_irq(dev, ctx->irq, ade_irq_handler,
+  IRQF_SHARED, dev->driver->name, ctx);
+   if (ret)
+   return ERR_PTR(-EIO);
+
+   ctx->crtc = crtc;
+
return ctx;
 }
 
@@ -1027,7 +1039,7 @@ static int ade_drm_init(struct platform_device *pdev)
}
platform_set_drvdata(pdev, ade);
 
-   ctx = ade_hw_ctx_alloc(pdev);
+   ctx = ade_hw_ctx_alloc(pdev, >crtc.base);
if (IS_ERR(ctx)) {
DRM_ERROR("failed to initialize kirin_priv hw ctx\n");
return -EINVAL;
@@ -1059,15 +1071,8 @@ static int ade_drm_init(struct platform_device *pdev)
if (ret)
return ret;
 
-   /* vblank irq init */
-   ret = devm_request_irq(dev->dev, ctx->irq, ade_irq_handler,
-  IRQF_SHARED, dev->driver->name, kcrtc);
-
INIT_WORK(>display_reset_wq, drm_underflow_wq);
 
-   if (ret)
-   return ret;
-
return 0;
 }
 
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v5 12/25] drm: kirin: Reanme dc_ops to kirin_drm_data

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch renames the
struct kirin_dc_ops to struct kirin_drm_data and cleans
up the related variable names.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: reworded commit message]
Signed-off-by: John Stultz 
---
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c |  2 +-
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c | 16 
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h |  4 ++--
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index 3fbf099597c1..4c6646dfc465 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -1055,7 +1055,7 @@ static void ade_drm_cleanup(struct platform_device *pdev)
 {
 }
 
-const struct kirin_dc_ops ade_dc_ops = {
+struct kirin_drm_data ade_driver_data = {
.init = ade_drm_init,
.cleanup = ade_drm_cleanup
 };
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
index fcdd6b1e167d..3d22f944a840 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
@@ -29,12 +29,12 @@
 
 #include "kirin_drm_drv.h"
 
-static struct kirin_dc_ops *dc_ops;
+static struct kirin_drm_data *driver_data;
 
 static int kirin_drm_kms_cleanup(struct drm_device *dev)
 {
drm_kms_helper_poll_fini(dev);
-   dc_ops->cleanup(to_platform_device(dev->dev));
+   driver_data->cleanup(to_platform_device(dev->dev));
drm_mode_config_cleanup(dev);
 
return 0;
@@ -68,7 +68,7 @@ static int kirin_drm_kms_init(struct drm_device *dev)
kirin_drm_mode_config_init(dev);
 
/* display controller init */
-   ret = dc_ops->init(to_platform_device(dev->dev));
+   ret = driver_data->init(to_platform_device(dev->dev));
if (ret)
goto err_mode_config_cleanup;
 
@@ -99,7 +99,7 @@ static int kirin_drm_kms_init(struct drm_device *dev)
 err_unbind_all:
component_unbind_all(dev->dev, dev);
 err_dc_cleanup:
-   dc_ops->cleanup(to_platform_device(dev->dev));
+   driver_data->cleanup(to_platform_device(dev->dev));
 err_mode_config_cleanup:
drm_mode_config_cleanup(dev);
 
@@ -194,8 +194,8 @@ static int kirin_drm_platform_probe(struct platform_device 
*pdev)
struct component_match *match = NULL;
struct device_node *remote;
 
-   dc_ops = (struct kirin_dc_ops *)of_device_get_match_data(dev);
-   if (!dc_ops) {
+   driver_data = (struct kirin_drm_data *)of_device_get_match_data(dev);
+   if (!driver_data) {
DRM_ERROR("failed to get dt id data\n");
return -EINVAL;
}
@@ -213,13 +213,13 @@ static int kirin_drm_platform_probe(struct 
platform_device *pdev)
 static int kirin_drm_platform_remove(struct platform_device *pdev)
 {
component_master_del(>dev, _drm_ops);
-   dc_ops = NULL;
+   driver_data = NULL;
return 0;
 }
 
 static const struct of_device_id kirin_drm_dt_ids[] = {
{ .compatible = "hisilicon,hi6220-ade",
- .data = _dc_ops,
+ .data = _driver_data,
},
{ /* end node */ },
 };
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
index d47cbb427979..cd2eaa653db7 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
@@ -34,11 +34,11 @@ struct kirin_plane {
 };
 
 /* display controller init/cleanup ops */
-struct kirin_dc_ops {
+struct kirin_drm_data {
int (*init)(struct platform_device *pdev);
void (*cleanup)(struct platform_device *pdev);
 };
 
-extern const struct kirin_dc_ops ade_dc_ops;
+extern struct kirin_drm_data ade_driver_data;
 
 #endif /* __KIRIN_DRM_DRV_H__ */
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v5 10/25] drm: kirin: Move workqueue to ade_hw_ctx structure

2019-08-20 Thread John Stultz
The workqueue used to reset the display when we hit an LDI
underflow error is ADE specific, so since this patch series
works to make the kirin_crtc structure more generic, move the
workqueue to the ade_hw_ctx structure instead.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: John Stultz 
---
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index d0a7c1d0adbe..da9f477679a3 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -52,6 +52,7 @@ struct ade_hw_ctx {
struct clk *media_noc_clk;
struct clk *ade_pix_clk;
struct reset_control *reset;
+   struct work_struct display_reset_wq;
bool power_on;
int irq;
 
@@ -61,7 +62,6 @@ struct ade_hw_ctx {
 struct kirin_crtc {
struct drm_crtc base;
void *hw_ctx;
-   struct work_struct display_reset_wq;
bool enable;
 };
 
@@ -349,9 +349,9 @@ static void ade_crtc_disable_vblank(struct drm_crtc *crtc)
 
 static void drm_underflow_wq(struct work_struct *work)
 {
-   struct kirin_crtc *acrtc = container_of(work, struct kirin_crtc,
+   struct ade_hw_ctx *ctx = container_of(work, struct ade_hw_ctx,
  display_reset_wq);
-   struct drm_device *drm_dev = (>base)->dev;
+   struct drm_device *drm_dev = ctx->crtc->dev;
struct drm_atomic_state *state;
 
state = drm_atomic_helper_suspend(drm_dev);
@@ -362,7 +362,6 @@ static irqreturn_t ade_irq_handler(int irq, void *data)
 {
struct ade_hw_ctx *ctx = data;
struct drm_crtc *crtc = ctx->crtc;
-   struct kirin_crtc *kcrtc = to_kirin_crtc(crtc);
void __iomem *base = ctx->base;
u32 status;
 
@@ -379,7 +378,7 @@ static irqreturn_t ade_irq_handler(int irq, void *data)
ade_update_bits(base + LDI_INT_CLR, UNDERFLOW_INT_EN_OFST,
MASK(1), 1);
DRM_ERROR("LDI underflow!");
-   schedule_work(>display_reset_wq);
+   schedule_work(>display_reset_wq);
}
 
return IRQ_HANDLED;
@@ -1016,6 +1015,7 @@ static void *ade_hw_ctx_alloc(struct platform_device 
*pdev,
if (ret)
return ERR_PTR(-EIO);
 
+   INIT_WORK(>display_reset_wq, drm_underflow_wq);
ctx->crtc = crtc;
 
return ctx;
@@ -1071,8 +1071,6 @@ static int ade_drm_init(struct platform_device *pdev)
if (ret)
return ret;
 
-   INIT_WORK(>display_reset_wq, drm_underflow_wq);
-
return 0;
 }
 
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v5 14/25] drm: kirin: Move channel formats to driver data

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch moves the channel
format arrays into the kirin_drm_data structure.

This will make it easier to add support for new devices
via a new kirin_drm_data structure.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: reworded commit message]
Signed-off-by: John Stultz 
---
 .../gpu/drm/hisilicon/kirin/kirin_drm_ade.c   | 30 +--
 .../gpu/drm/hisilicon/kirin/kirin_drm_drv.h   |  3 ++
 2 files changed, 10 insertions(+), 23 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index a1a79f372bcd..0489b6378e01 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -76,7 +76,7 @@ static const struct kirin_format ade_formats[] = {
{ DRM_FORMAT_ABGR, ADE_ABGR_ },
 };
 
-static const u32 channel_formats1[] = {
+static const u32 channel_formats[] = {
/* channel 1,2,3,4 */
DRM_FORMAT_RGB565, DRM_FORMAT_BGR565, DRM_FORMAT_RGB888,
DRM_FORMAT_BGR888, DRM_FORMAT_XRGB, DRM_FORMAT_XBGR,
@@ -84,19 +84,6 @@ static const u32 channel_formats1[] = {
DRM_FORMAT_ABGR
 };
 
-u32 ade_get_channel_formats(u8 ch, const u32 **formats)
-{
-   switch (ch) {
-   case ADE_CH1:
-   *formats = channel_formats1;
-   return ARRAY_SIZE(channel_formats1);
-   default:
-   DRM_ERROR("no this channel %d\n", ch);
-   *formats = NULL;
-   return 0;
-   }
-}
-
 /* convert from fourcc format to ade format */
 static u32 ade_get_format(u32 pixel_format)
 {
@@ -908,18 +895,13 @@ static struct drm_plane_funcs ade_plane_funcs = {
 static int ade_plane_init(struct drm_device *dev, struct kirin_plane *kplane,
  enum drm_plane_type type)
 {
-   const u32 *fmts;
-   u32 fmts_cnt;
int ret = 0;
 
-   /* get  properties */
-   fmts_cnt = ade_get_channel_formats(kplane->ch, );
-   if (ret)
-   return ret;
-
ret = drm_universal_plane_init(dev, >base, 1,
-  ade_driver_data.plane_funcs, fmts,
-  fmts_cnt, NULL, type, NULL);
+  ade_driver_data.plane_funcs,
+  ade_driver_data.channel_formats,
+  ade_driver_data.channel_formats_cnt,
+  NULL, type, NULL);
if (ret) {
DRM_ERROR("fail to init plane, ch=%d\n", kplane->ch);
return ret;
@@ -1057,6 +1039,8 @@ static void ade_drm_cleanup(struct platform_device *pdev)
 }
 
 struct kirin_drm_data ade_driver_data = {
+   .channel_formats = channel_formats,
+   .channel_formats_cnt = ARRAY_SIZE(channel_formats),
.crtc_helper_funcs = _crtc_helper_funcs,
.crtc_funcs = _crtc_funcs,
.plane_helper_funcs = _plane_helper_funcs,
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
index 70b04e65789c..66916502a9e6 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
@@ -35,6 +35,9 @@ struct kirin_plane {
 
 /* display controller init/cleanup ops */
 struct kirin_drm_data {
+   const u32 *channel_formats;
+   u32 channel_formats_cnt;
+
const struct drm_crtc_helper_funcs *crtc_helper_funcs;
const struct drm_crtc_funcs *crtc_funcs;
const struct drm_plane_helper_funcs *plane_helper_funcs;
-- 
2.17.1



[PATCH v5 13/25] drm: kirin: Move ade crtc/plane help functions to driver_data

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch moves the crtc
and plane funcs/helper_funcs to the struct kirin_drm_data.

This will make it easier to add support for new devices
via a new kirin_drm_data structure.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: reworded commit message]
Signed-off-by: John Stultz 
---
v5: checkpatch --strict whitespace fixups noticed by Sam
---
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c | 15 ++-
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h |  5 +
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index 4c6646dfc465..a1a79f372bcd 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -602,13 +602,13 @@ static int ade_crtc_init(struct drm_device *dev, struct 
drm_crtc *crtc,
crtc->port = port;
 
ret = drm_crtc_init_with_planes(dev, crtc, plane, NULL,
-   _crtc_funcs, NULL);
+   ade_driver_data.crtc_funcs, NULL);
if (ret) {
DRM_ERROR("failed to init crtc.\n");
return ret;
}
 
-   drm_crtc_helper_add(crtc, _crtc_helper_funcs);
+   drm_crtc_helper_add(crtc, ade_driver_data.crtc_helper_funcs);
 
return 0;
 }
@@ -917,14 +917,15 @@ static int ade_plane_init(struct drm_device *dev, struct 
kirin_plane *kplane,
if (ret)
return ret;
 
-   ret = drm_universal_plane_init(dev, >base, 1, _plane_funcs,
-  fmts, fmts_cnt, NULL, type, NULL);
+   ret = drm_universal_plane_init(dev, >base, 1,
+  ade_driver_data.plane_funcs, fmts,
+  fmts_cnt, NULL, type, NULL);
if (ret) {
DRM_ERROR("fail to init plane, ch=%d\n", kplane->ch);
return ret;
}
 
-   drm_plane_helper_add(>base, _plane_helper_funcs);
+   drm_plane_helper_add(>base, ade_driver_data.plane_helper_funcs);
 
return 0;
 }
@@ -1056,6 +1057,10 @@ static void ade_drm_cleanup(struct platform_device *pdev)
 }
 
 struct kirin_drm_data ade_driver_data = {
+   .crtc_helper_funcs = _crtc_helper_funcs,
+   .crtc_funcs = _crtc_funcs,
+   .plane_helper_funcs = _plane_helper_funcs,
+   .plane_funcs = _plane_funcs,
.init = ade_drm_init,
.cleanup = ade_drm_cleanup
 };
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
index cd2eaa653db7..70b04e65789c 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
@@ -35,6 +35,11 @@ struct kirin_plane {
 
 /* display controller init/cleanup ops */
 struct kirin_drm_data {
+   const struct drm_crtc_helper_funcs *crtc_helper_funcs;
+   const struct drm_crtc_funcs *crtc_funcs;
+   const struct drm_plane_helper_funcs *plane_helper_funcs;
+   const struct drm_plane_funcs  *plane_funcs;
+
int (*init)(struct platform_device *pdev);
void (*cleanup)(struct platform_device *pdev);
 };
-- 
2.17.1



[PATCH v5 05/25] drm: kirin: Remove out_format from ade_crtc

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch removes the out_format
field in the struct ade_crtc, which was only ever set to
LDI_OUT_RGB_888.

Thus this patch removes the field and instead directly uses
LDI_OUT_RGB_888.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: reworded commit message]
Signed-off-by: John Stultz 
---
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index 45351934d919..65f1a57f7304 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -60,7 +60,6 @@ struct ade_crtc {
struct ade_hw_ctx *ctx;
struct work_struct display_reset_wq;
bool enable;
-   u32 out_format;
 };
 
 struct ade_plane {
@@ -383,11 +382,10 @@ static irqreturn_t ade_irq_handler(int irq, void *data)
return IRQ_HANDLED;
 }
 
-static void ade_display_enable(struct ade_crtc *acrtc)
+static void ade_display_enable(struct ade_hw_ctx *ctx)
 {
-   struct ade_hw_ctx *ctx = acrtc->ctx;
void __iomem *base = ctx->base;
-   u32 out_fmt = acrtc->out_format;
+   u32 out_fmt = LDI_OUT_RGB_888;
 
/* enable output overlay compositor */
writel(ADE_ENABLE, base + ADE_OVLYX_CTL(OUT_OVLY));
@@ -514,7 +512,7 @@ static void ade_crtc_atomic_enable(struct drm_crtc *crtc,
}
 
ade_set_medianoc_qos(ctx);
-   ade_display_enable(acrtc);
+   ade_display_enable(ctx);
ade_dump_regs(ctx->base);
drm_crtc_vblank_on(crtc);
acrtc->enable = true;
@@ -1024,7 +1022,6 @@ static int ade_drm_init(struct platform_device *pdev)
ctx = >ctx;
acrtc = >acrtc;
acrtc->ctx = ctx;
-   acrtc->out_format = LDI_OUT_RGB_888;
 
ret = ade_dts_parse(pdev, ctx);
if (ret)
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v5 11/25] drm: kirin: Move kirin_crtc, kirin_plane, kirin_format to kirin_drm_drv.h

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch moves some shared
structures and helpers to the common kirin_drm_drv.h

These structures will later used by both kirin620 and
future kirin960 driver

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: reworded commit message]
Signed-off-by: John Stultz 
---
 .../gpu/drm/hisilicon/kirin/kirin_drm_ade.c   | 27 ++-
 .../gpu/drm/hisilicon/kirin/kirin_drm_drv.h   | 24 +
 2 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index da9f477679a3..3fbf099597c1 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -38,12 +38,6 @@
 #define OUT_OVLY   ADE_OVLY2 /* output overlay compositor */
 #define ADE_DEBUG  1
 
-#define to_kirin_crtc(crtc) \
-   container_of(crtc, struct kirin_crtc, base)
-
-#define to_kirin_plane(plane) \
-   container_of(plane, struct kirin_plane, base)
-
 
 struct ade_hw_ctx {
void __iomem  *base;
@@ -59,18 +53,6 @@ struct ade_hw_ctx {
struct drm_crtc *crtc;
 };
 
-struct kirin_crtc {
-   struct drm_crtc base;
-   void *hw_ctx;
-   bool enable;
-};
-
-struct kirin_plane {
-   struct drm_plane base;
-   void *hw_ctx;
-   u32 ch;
-};
-
 struct ade_data {
struct kirin_crtc crtc;
struct kirin_plane planes[ADE_CH_NUM];
@@ -78,12 +60,7 @@ struct ade_data {
 };
 
 /* ade-format info: */
-struct ade_format {
-   u32 pixel_format;
-   enum ade_fb_format ade_format;
-};
-
-static const struct ade_format ade_formats[] = {
+static const struct kirin_format ade_formats[] = {
/* 16bpp RGB: */
{ DRM_FORMAT_RGB565, ADE_RGB_565 },
{ DRM_FORMAT_BGR565, ADE_BGR_565 },
@@ -127,7 +104,7 @@ static u32 ade_get_format(u32 pixel_format)
 
for (i = 0; i < ARRAY_SIZE(ade_formats); i++)
if (ade_formats[i].pixel_format == pixel_format)
-   return ade_formats[i].ade_format;
+   return ade_formats[i].hw_format;
 
/* not found */
DRM_ERROR("Not found pixel format!!fourcc_format= %d\n",
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
index 22d1291668cd..d47cbb427979 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.h
@@ -9,6 +9,30 @@
 
 #define MAX_CRTC   2
 
+#define to_kirin_crtc(crtc) \
+   container_of(crtc, struct kirin_crtc, base)
+
+#define to_kirin_plane(plane) \
+   container_of(plane, struct kirin_plane, base)
+
+/* kirin-format translate table */
+struct kirin_format {
+   u32 pixel_format;
+   u32 hw_format;
+};
+
+struct kirin_crtc {
+   struct drm_crtc base;
+   void *hw_ctx;
+   bool enable;
+};
+
+struct kirin_plane {
+   struct drm_plane base;
+   void *hw_ctx;
+   u32 ch;
+};
+
 /* display controller init/cleanup ops */
 struct kirin_dc_ops {
int (*init)(struct platform_device *pdev);
-- 
2.17.1



[PATCH v5 06/25] drm: kirin: Rename ade_plane to kirin_plane

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch renames the
struct ade_plane to kirin_plane.

The struct kirin_plane will later used by both kirin620 and
future kirin960 driver, and will be moved to a common
kirin_drm_drv.h in a future patch

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: reworded commit message]
Signed-off-by: John Stultz 
---
 .../gpu/drm/hisilicon/kirin/kirin_drm_ade.c   | 57 ++-
 1 file changed, 29 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index 65f1a57f7304..19d279167694 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -41,8 +41,9 @@
 #define to_ade_crtc(crtc) \
container_of(crtc, struct ade_crtc, base)
 
-#define to_ade_plane(plane) \
-   container_of(plane, struct ade_plane, base)
+#define to_kirin_plane(plane) \
+   container_of(plane, struct kirin_plane, base)
+
 
 struct ade_hw_ctx {
void __iomem  *base;
@@ -62,15 +63,15 @@ struct ade_crtc {
bool enable;
 };
 
-struct ade_plane {
+struct kirin_plane {
struct drm_plane base;
-   void *ctx;
-   u8 ch; /* channel */
+   void *hw_ctx;
+   u32 ch;
 };
 
 struct ade_data {
struct ade_crtc acrtc;
-   struct ade_plane aplane[ADE_CH_NUM];
+   struct kirin_plane planes[ADE_CH_NUM];
struct ade_hw_ctx ctx;
 };
 
@@ -795,16 +796,16 @@ static void ade_compositor_routing_disable(void __iomem 
*base, u32 ch)
 /*
  * Typicaly, a channel looks like: DMA-->clip-->scale-->ctrans-->compositor
  */
-static void ade_update_channel(struct ade_plane *aplane,
+static void ade_update_channel(struct kirin_plane *kplane,
   struct drm_framebuffer *fb, int crtc_x,
   int crtc_y, unsigned int crtc_w,
   unsigned int crtc_h, u32 src_x,
   u32 src_y, u32 src_w, u32 src_h)
 {
-   struct ade_hw_ctx *ctx = aplane->ctx;
+   struct ade_hw_ctx *ctx = kplane->hw_ctx;
void __iomem *base = ctx->base;
u32 fmt = ade_get_format(fb->format->format);
-   u32 ch = aplane->ch;
+   u32 ch = kplane->ch;
u32 in_w;
u32 in_h;
 
@@ -828,11 +829,11 @@ static void ade_update_channel(struct ade_plane *aplane,
ade_compositor_routing_set(base, ch, crtc_x, crtc_y, in_w, in_h, fmt);
 }
 
-static void ade_disable_channel(struct ade_plane *aplane)
+static void ade_disable_channel(struct kirin_plane *kplane)
 {
-   struct ade_hw_ctx *ctx = aplane->ctx;
+   struct ade_hw_ctx *ctx = kplane->hw_ctx;
void __iomem *base = ctx->base;
-   u32 ch = aplane->ch;
+   u32 ch = kplane->ch;
 
DRM_DEBUG_DRIVER("disable channel%d\n", ch + 1);
 
@@ -894,10 +895,10 @@ static int ade_plane_atomic_check(struct drm_plane *plane,
 static void ade_plane_atomic_update(struct drm_plane *plane,
struct drm_plane_state *old_state)
 {
-   struct drm_plane_state  *state  = plane->state;
-   struct ade_plane *aplane = to_ade_plane(plane);
+   struct drm_plane_state *state = plane->state;
+   struct kirin_plane *kplane = to_kirin_plane(plane);
 
-   ade_update_channel(aplane, state->fb, state->crtc_x, state->crtc_y,
+   ade_update_channel(kplane, state->fb, state->crtc_x, state->crtc_y,
   state->crtc_w, state->crtc_h,
   state->src_x >> 16, state->src_y >> 16,
   state->src_w >> 16, state->src_h >> 16);
@@ -906,9 +907,9 @@ static void ade_plane_atomic_update(struct drm_plane *plane,
 static void ade_plane_atomic_disable(struct drm_plane *plane,
 struct drm_plane_state *old_state)
 {
-   struct ade_plane *aplane = to_ade_plane(plane);
+   struct kirin_plane *kplane = to_kirin_plane(plane);
 
-   ade_disable_channel(aplane);
+   ade_disable_channel(kplane);
 }
 
 static const struct drm_plane_helper_funcs ade_plane_helper_funcs = {
@@ -926,7 +927,7 @@ static struct drm_plane_funcs ade_plane_funcs = {
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
 };
 
-static int ade_plane_init(struct drm_device *dev, struct ade_plane *aplane,
+static int ade_plane_init(struct drm_device *dev, struct kirin_plane *kplane,
  enum drm_plane_type type)
 {
const u32 *fmts;
@@ -934,18 +935,18 @@ static int ade_plane_init(struct drm_device *dev, struct 
ade_plane *aplane,
int ret = 0;
 
/* get  properties */
-   fmts_cnt = ade_get_channel_formats(aplane->ch, );
+   fmts_cnt = ade_get_channel_formats(kplane->ch, );
  

[PATCH v5 02/25] drm: kirin: Remove HISI_KIRIN_DW_DSI config option

2019-08-20 Thread John Stultz
The CONFIG_HISI_KIRIN_DW_DSI option is only used w/ kirin
driver, so cut out the middleman and condense the config
logic down.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: John Stultz 
---
v5: Build fixup for module config noticed by Sam
---
 drivers/gpu/drm/hisilicon/kirin/Kconfig  | 10 +-
 drivers/gpu/drm/hisilicon/kirin/Makefile |  3 +--
 2 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/Kconfig 
b/drivers/gpu/drm/hisilicon/kirin/Kconfig
index 0fa29af08ad0..290553e2f6b4 100644
--- a/drivers/gpu/drm/hisilicon/kirin/Kconfig
+++ b/drivers/gpu/drm/hisilicon/kirin/Kconfig
@@ -5,16 +5,8 @@ config DRM_HISI_KIRIN
select DRM_KMS_HELPER
select DRM_GEM_CMA_HELPER
select DRM_KMS_CMA_HELPER
-   select HISI_KIRIN_DW_DSI
+   select DRM_MIPI_DSI
help
  Choose this option if you have a hisilicon Kirin chipsets(hi6220).
  If M is selected the module will be called kirin-drm.
 
-config HISI_KIRIN_DW_DSI
-   tristate "HiSilicon Kirin specific extensions for Synopsys DW MIPI DSI"
-   depends on DRM_HISI_KIRIN
-   select DRM_MIPI_DSI
-   help
-This selects support for HiSilicon Kirin SoC specific extensions for
-the Synopsys DesignWare DSI driver. If you want to enable MIPI DSI on
-hi6220 based SoC, you should selet this option.
diff --git a/drivers/gpu/drm/hisilicon/kirin/Makefile 
b/drivers/gpu/drm/hisilicon/kirin/Makefile
index c0501fa3fe53..d9323f66a7d4 100644
--- a/drivers/gpu/drm/hisilicon/kirin/Makefile
+++ b/drivers/gpu/drm/hisilicon/kirin/Makefile
@@ -2,6 +2,5 @@
 kirin-drm-y := kirin_drm_drv.o \
   kirin_drm_ade.o
 
-obj-$(CONFIG_DRM_HISI_KIRIN) += kirin-drm.o
+obj-$(CONFIG_DRM_HISI_KIRIN) += kirin-drm.o dw_drm_dsi.o
 
-obj-$(CONFIG_HISI_KIRIN_DW_DSI) += dw_drm_dsi.o
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v5 00/25] drm: Kirin driver cleanups to prep for Kirin960 support

2019-08-20 Thread John Stultz
Sending this out again (apologies!), to address a few issues Sam
found.

This patchset contains one fix (in the front, so its easier to
eventually backport), and a series of changes from YiPing to
refactor the kirin drm driver so that it can be used on both
kirin620 based devices (like the original HiKey board) as well
as kirin960 based devices (like the HiKey960 board).

The full kirin960 drm support is still being refactored, but as
this base kirin rework was getting to be substantial, I wanted
to send out the first chunk, so that the review burden wasn't
overwhelming.

The full HiKey960 patch stack can be found here:
  
https://git.linaro.org/people/john.stultz/android-dev.git/log/?h=dev/hikey960-mainline-WIP

thanks
-john


New in v5:
* Whitespace changes and few logic simplifications to get
  checkpatch.pl --strict to pass, as noted by Sam
* Fix for one of my patches which broke building the kirin
  driver as a module. Again noted by Sam.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 

Da Lv (1):
  drm: kirin: Fix for hikey620 display offset problem

John Stultz (3):
  drm: kirin: Remove HISI_KIRIN_DW_DSI config option
  drm: kirin: Remove unreachable return
  drm: kirin: Move workqueue to ade_hw_ctx structure

Xu YiPing (21):
  drm: kirin: Remove uncessary parameter indirection
  drm: kirin: Remove out_format from ade_crtc
  drm: kirin: Rename ade_plane to kirin_plane
  drm: kirin: Rename ade_crtc to kirin_crtc
  drm: kirin: Dynamically allocate the hw_ctx
  drm: kirin: Move request irq handle in ade hw ctx alloc
  drm: kirin: Move kirin_crtc, kirin_plane, kirin_format to
kirin_drm_drv.h
  drm: kirin: Reanme dc_ops to kirin_drm_data
  drm: kirin: Move ade crtc/plane help functions to driver_data
  drm: kirin: Move channel formats to driver data
  drm: kirin: Move mode config function to driver_data
  drm: kirin: Move plane number and primay plane in driver data
  drm: kirin: Move config max_width and max_height to driver data
  drm: kirin: Move drm driver to driver data
  drm: kirin: Add register connect helper functions in drm init
  drm: kirin: Rename plane_init and crtc_init
  drm: kirin: Fix dev->driver_data setting
  drm: kirin: Make driver_data variable non-global
  drm: kirin: Add alloc_hw_ctx/clean_hw_ctx ops in driver data
  drm: kirin: Pass driver data to crtc init and plane init
  drm: kirin: Move ade drm init to kirin drm drv

 drivers/gpu/drm/hisilicon/kirin/Kconfig   |  10 +-
 drivers/gpu/drm/hisilicon/kirin/Makefile  |   3 +-
 .../gpu/drm/hisilicon/kirin/kirin_ade_reg.h   |   1 +
 .../gpu/drm/hisilicon/kirin/kirin_drm_ade.c   | 351 +++---
 .../gpu/drm/hisilicon/kirin/kirin_drm_drv.c   | 250 +
 .../gpu/drm/hisilicon/kirin/kirin_drm_drv.h   |  48 ++-
 6 files changed, 367 insertions(+), 296 deletions(-)

-- 
2.17.1



[PATCH v5 07/25] drm: kirin: Rename ade_crtc to kirin_crtc

2019-08-20 Thread John Stultz
From: Xu YiPing 

As part of refactoring the kirin driver to better support
different hardware revisions, this patch renames the
struct ade_crtc to kirin_crtc.

The struct kirin_crtc will later used by both kirin620 and
future kirin960 driver, and will be moved to a common
kirin_drm_drv.h in a future patch

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Signed-off-by: Xu YiPing 
[jstultz: reworded commit message]
Signed-off-by: John Stultz 
---
 .../gpu/drm/hisilicon/kirin/kirin_drm_ade.c   | 74 +--
 1 file changed, 37 insertions(+), 37 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
index 19d279167694..fce374ec69e8 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c
@@ -38,8 +38,8 @@
 #define OUT_OVLY   ADE_OVLY2 /* output overlay compositor */
 #define ADE_DEBUG  1
 
-#define to_ade_crtc(crtc) \
-   container_of(crtc, struct ade_crtc, base)
+#define to_kirin_crtc(crtc) \
+   container_of(crtc, struct kirin_crtc, base)
 
 #define to_kirin_plane(plane) \
container_of(plane, struct kirin_plane, base)
@@ -56,9 +56,9 @@ struct ade_hw_ctx {
int irq;
 };
 
-struct ade_crtc {
+struct kirin_crtc {
struct drm_crtc base;
-   struct ade_hw_ctx *ctx;
+   void *hw_ctx;
struct work_struct display_reset_wq;
bool enable;
 };
@@ -70,7 +70,7 @@ struct kirin_plane {
 };
 
 struct ade_data {
-   struct ade_crtc acrtc;
+   struct kirin_crtc crtc;
struct kirin_plane planes[ADE_CH_NUM];
struct ade_hw_ctx ctx;
 };
@@ -184,8 +184,8 @@ static bool ade_crtc_mode_fixup(struct drm_crtc *crtc,
const struct drm_display_mode *mode,
struct drm_display_mode *adjusted_mode)
 {
-   struct ade_crtc *acrtc = to_ade_crtc(crtc);
-   struct ade_hw_ctx *ctx = acrtc->ctx;
+   struct kirin_crtc *kcrtc = to_kirin_crtc(crtc);
+   struct ade_hw_ctx *ctx = kcrtc->hw_ctx;
 
adjusted_mode->clock =
clk_round_rate(ctx->ade_pix_clk, mode->clock * 1000) / 1000;
@@ -317,8 +317,8 @@ static void ade_set_medianoc_qos(struct ade_hw_ctx *ctx)
 
 static int ade_crtc_enable_vblank(struct drm_crtc *crtc)
 {
-   struct ade_crtc *acrtc = to_ade_crtc(crtc);
-   struct ade_hw_ctx *ctx = acrtc->ctx;
+   struct kirin_crtc *kcrtc = to_kirin_crtc(crtc);
+   struct ade_hw_ctx *ctx = kcrtc->hw_ctx;
void __iomem *base = ctx->base;
 
if (!ctx->power_on)
@@ -332,8 +332,8 @@ static int ade_crtc_enable_vblank(struct drm_crtc *crtc)
 
 static void ade_crtc_disable_vblank(struct drm_crtc *crtc)
 {
-   struct ade_crtc *acrtc = to_ade_crtc(crtc);
-   struct ade_hw_ctx *ctx = acrtc->ctx;
+   struct kirin_crtc *kcrtc = to_kirin_crtc(crtc);
+   struct ade_hw_ctx *ctx = kcrtc->hw_ctx;
void __iomem *base = ctx->base;
 
if (!ctx->power_on) {
@@ -347,7 +347,7 @@ static void ade_crtc_disable_vblank(struct drm_crtc *crtc)
 
 static void drm_underflow_wq(struct work_struct *work)
 {
-   struct ade_crtc *acrtc = container_of(work, struct ade_crtc,
+   struct kirin_crtc *acrtc = container_of(work, struct kirin_crtc,
  display_reset_wq);
struct drm_device *drm_dev = (>base)->dev;
struct drm_atomic_state *state;
@@ -358,9 +358,9 @@ static void drm_underflow_wq(struct work_struct *work)
 
 static irqreturn_t ade_irq_handler(int irq, void *data)
 {
-   struct ade_crtc *acrtc = data;
-   struct ade_hw_ctx *ctx = acrtc->ctx;
-   struct drm_crtc *crtc = >base;
+   struct kirin_crtc *kcrtc = data;
+   struct ade_hw_ctx *ctx = kcrtc->hw_ctx;
+   struct drm_crtc *crtc = >base;
void __iomem *base = ctx->base;
u32 status;
 
@@ -377,7 +377,7 @@ static irqreturn_t ade_irq_handler(int irq, void *data)
ade_update_bits(base + LDI_INT_CLR, UNDERFLOW_INT_EN_OFST,
MASK(1), 1);
DRM_ERROR("LDI underflow!");
-   schedule_work(>display_reset_wq);
+   schedule_work(>display_reset_wq);
}
 
return IRQ_HANDLED;
@@ -499,11 +499,11 @@ static void ade_dump_regs(void __iomem *base) { }
 static void ade_crtc_atomic_enable(struct drm_crtc *crtc,
   struct drm_crtc_state *old_state)
 {
-   struct ade_crtc *acrtc = to_ade_crtc(crtc);
-   struct ade_hw_ctx *ctx = acrtc->ctx;
+   struct kirin_crtc *kcrtc = to_kirin_crtc(crtc);
+   struct ade_hw_ctx *ctx = kcrtc->hw_ctx;
int ret;
 
-   if (acrtc->enable)
+   if (kcrtc->enable)
return;
 
if (!ctx->power_on) {
@@ -516,27 +516,27 @@ static void ade_crtc_atomic_enable(struct 

[PATCH v5 03/25] drm: kirin: Remove unreachable return

2019-08-20 Thread John Stultz
The 'return 0' in kirin_drm_platform_probe() is unreachable
code, so remove it.

Cc: Rongrong Zou 
Cc: Xinliang Liu 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-devel 
Cc: Sam Ravnborg 
Acked-by: Xinliang Liu 
Reviewed-by: Sam Ravnborg 
Suggested by: Xu YiPing 
Signed-off-by: John Stultz 
---
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c 
b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
index 204c94c01e3d..fcdd6b1e167d 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
@@ -208,8 +208,6 @@ static int kirin_drm_platform_probe(struct platform_device 
*pdev)
of_node_put(remote);
 
return component_master_add_with_match(dev, _drm_ops, match);
-
-   return 0;
 }
 
 static int kirin_drm_platform_remove(struct platform_device *pdev)
-- 
2.17.1



[Bug 111414] [REGRESSION] [BISECTED] Segmentation fault in si_bind_blend_state after removal of the blend state NULL check

2019-08-20 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=111414

--- Comment #5 from Dieter Nützel  ---
Hello Edmondo,

thank you for your comment.

Now, I get this:

mpv -hwdec /data/Filme/test.mkv
Playing: /data/Filme/test.mkv
 (+) Video --vid=1 (*) 'OceanWorld.2D.2009.BluRay.1080p.AC3.x264-CHD' (h264
1920x1080 24.000fps)
 (+) Audio --aid=1 --alang=eng (*) 'AC3 5.1 channels, 640kbps' (ac3 6ch
48000Hz)
File tags:
 Title: 深海探奇 2D
ATTENTION: default value of option mesa_glthread overridden by environment.
ATTENTION: option value of option mesa_glthread ignored.
ATTENTION: default value of option mesa_glthread overridden by environment.
ATTENTION: option value of option mesa_glthread ignored.
mesa: for the   --simplifycfg-sink-common option: may only occur zero or one
times!
mesa: for the   --global-isel-abort option: may only occur zero or one times!
mpv: ../src/gallium/state_trackers/vdpau/vdpau_private.h:138:
FormatYCBCRToPipe: Assertion `0' failed.
Abbruch (core dumped)

-- 
You are receiving this mail because:
You are the assignee for the bug.___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Re: [PATCH v2 09/14] drm/dp-mst: Export symbols for dpcd read/write

2019-08-20 Thread Li, Sun peng (Leo)



On 2019-08-20 5:02 p.m., Lyude Paul wrote:
> [Added Leo Li here, since they did the auxdev work that introduced these
> functions]
> 
> Since it seems we'll actually be doing remote DPCD read/writes in DRM drivers
> and not just from auxdev, maybe we should combine drm_dp_dpcd_read() with
> drm_dp_mst_dpcd_read() and do the same with the _write() variants? Based on
> previous discussions with Leo Li I remember that we can't just combine the
> dp_aux_dev->transfer() callbacks in struct drm_dp_aux_dev, but I don't see a
> reason we can't just teach drm_dp_dpcd_read/write() to work with MST aux so
> that we don't need two seperate functions. This should be pretty easy to do,
> just:
> 
> /* Add a check like this at the start of drm_dp_dpcd_read(): */
> ssize_t drm_dp_dpcd_read(...) {
>   if (aux->is_remote)
>   return drm_dp_mst_dpcd_read(...);
> 
>   /* ... */
> }
> 
> /* And in drm_dp_dpcd_write(): */
> ssize_t drm_dp_dpcd_write(...) {
>   if (aux->is_remote)
>   return drm_dp_mst_dpcd_write(...);
> 
>   /* ... */
> }
> 
> Then just replace the manual calls to drm_dp_mst_dpcd_write() in
> drivers/gpu/drm/drm_dp_aux_dev.c with normal
> drm_dp_dpcd_read()/drm_dp_dpcd_write() calls. Thoughts?

I think this would work well.

drm_dp_mst_dpcd_read/write will eventually call drm_dp_dpcd_write, so
doing so would cause a recursive call. That should be safe though. The
mst manager's aux will be used, and that should always be a real
(is_remote == false) aux, fwict.

Essentially, it's just moving that conditional from
auxdev_read/write_iter to drm_dp_dpcd_read/write.

Leo

> 
> On Tue, 2019-08-20 at 15:11 -0400, David Francis wrote:
>> To use these functions in drm driver directories, they must be
>> exported
>>
>> Signed-off-by: David Francis 
>> ---
>>  drivers/gpu/drm/drm_dp_mst_topology.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c
>> b/drivers/gpu/drm/drm_dp_mst_topology.c
>> index b40d975aec76..5d5bd42da17c 100644
>> --- a/drivers/gpu/drm/drm_dp_mst_topology.c
>> +++ b/drivers/gpu/drm/drm_dp_mst_topology.c
>> @@ -1512,6 +1512,7 @@ ssize_t drm_dp_mst_dpcd_read(struct drm_dp_aux *aux,
>>  return drm_dp_send_dpcd_read(port->mgr, port,
>>   offset, size, buffer);
>>  }
>> +EXPORT_SYMBOL(drm_dp_mst_dpcd_read);
>>  
>>  /**
>>   * drm_dp_mst_dpcd_write() - write a series of bytes to the DPCD via
>> sideband
>> @@ -1535,6 +1536,7 @@ ssize_t drm_dp_mst_dpcd_write(struct drm_dp_aux *aux,
>>  return drm_dp_send_dpcd_write(port->mgr, port,
>>offset, size, buffer);
>>  }
>> +EXPORT_SYMBOL(drm_dp_mst_dpcd_write);
>>  
>>  static void drm_dp_check_mstb_guid(struct drm_dp_mst_branch *mstb, u8
>> *guid)
>>  {
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Re: [PATCH v13 00/18] kunit: introduce KUnit, the Linux kernel unit testing framework

2019-08-20 Thread Brendan Higgins
On Tue, Aug 20, 2019 at 12:08 PM shuah  wrote:
>
> On 8/20/19 12:24 PM, Brendan Higgins wrote:
> > On Tue, Aug 20, 2019 at 11:24:45AM -0600, shuah wrote:
> >> On 8/13/19 11:50 PM, Brendan Higgins wrote:
> >>> ## TL;DR
> >>>
> >>> This revision addresses comments from Stephen and Bjorn Helgaas. Most
> >>> changes are pretty minor stuff that doesn't affect the API in anyway.
> >>> One significant change, however, is that I added support for freeing
> >>> kunit_resource managed resources before the test case is finished via
> >>> kunit_resource_destroy(). Additionally, Bjorn pointed out that I broke
> >>> KUnit on certain configurations (like the default one for x86, whoops).
> >>>
> >>> Based on Stephen's feedback on the previous change, I think we are
> >>> pretty close. I am not expecting any significant changes from here on
> >>> out.
> >>>
> >>
> >> Hi Brendan,
> >>
> >> I found checkpatch errors in one or two patches. Can you fix those and
> >> send v14.
> >
> > Hi Shuah,
> >
> > Are you refering to the following errors?
> >
> > ERROR: Macros with complex values should be enclosed in parentheses
> > #144: FILE: include/kunit/test.h:456:
> > +#define KUNIT_BINARY_CLASS \
> > +   kunit_binary_assert, KUNIT_INIT_BINARY_ASSERT_STRUCT
> >
> > ERROR: Macros with complex values should be enclosed in parentheses
> > #146: FILE: include/kunit/test.h:458:
> > +#define KUNIT_BINARY_PTR_CLASS \
> > +   kunit_binary_ptr_assert, KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT
> >
> > These values should *not* be in parentheses. I am guessing checkpatch is
> > getting confused and thinks that these are complex expressions, when
> > they are not.
> >
> > I ignored the errors since I figured checkpatch was complaining
> > erroneously.
> >
> > I could refactor the code to remove these macros entirely, but I think
> > the code is cleaner with them.
> >
>
> Please do. I am not veru sure what value these macros add.

Alright, I will have something for you later today.
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[Bug 111414] [REGRESSION] [BISECTED] Segmentation fault in si_bind_blend_state after removal of the blend state NULL check

2019-08-20 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=111414

--- Comment #4 from Edmondo Tommasina  ---
@Dieter: I cannot reproduce your issue with mpv and Marek's patch applied. It
looks good.

$ mpv -hwdec mytest.mkv 
Playing: mytest.mkv
 (+) Video --vid=1 (*) (h264 1280x720 23.976fps)
 (+) Audio --aid=1 --alang=eng (*) (aac 2ch 44100Hz)
 Subs  --sid=1 --slang=eng (subrip)
File tags:
 Title: mytest
Using hardware decoding (vdpau).
AO: [pulse] 44100Hz stereo 2ch float
VO: [gpu] 1280x720 vdpau[yuv420p]
AV: 00:00:32 / 00:42:26 (1%) A-V:  0.000

-- 
You are receiving this mail because:
You are the assignee for the bug.___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Re: [PATCH v2 14/14] drm/amd/display: Trigger modesets on MST DSC connectors

2019-08-20 Thread Lyude Paul
This should definitely be implemented as an atomic helper in
drm_dp_mst_topology.c as well.

On Tue, 2019-08-20 at 15:12 -0400, David Francis wrote:
> Whenever a connector on an MST network is attached, detached, or
> undergoes a modeset, the DSC configs for each stream on that
> topology will be recalculated. This can change their required
> bandwidth, requiring a full reprogramming, as though a modeset
> was performed, even if that stream did not change timing.
> 
> Therefore, whenever a crtc has drm_atomic_crtc_needs_modeset,
> for each crtc that shares a MST topology with that stream and
> supports DSC, add that crtc (and all affected connectors and
> planes) to the atomic state and set mode_changed on its state
> 
> v2: Do this check only on Navi and before adding connectors
> and planes on modesetting crtcs
> 
> Cc: Leo Li 
> Cc: Nicholas Kazlauskas 
> Signed-off-by: David Francis 
> ---
>  .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 74 +++
>  1 file changed, 74 insertions(+)
> 
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> index 145fd73025dc..e64f2a6eb71a 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> @@ -6475,7 +6475,70 @@ static int do_aquire_global_lock(struct drm_device
> *dev,
>  
>   return ret < 0 ? ret : 0;
>  }
> +#ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
> +static int add_affected_mst_dsc_crtcs(struct drm_atomic_state *state,
> struct drm_crtc *crtc)
> +{
> + struct drm_connector *connector;
> + struct drm_connector_state *conn_state;
> + struct drm_connector_list_iter conn_iter;
> + struct drm_crtc_state *new_crtc_state;
> + struct amdgpu_dm_connector *aconnector = NULL, *aconnector_to_add;
> + int i, j;
> + struct drm_crtc *crtcs_affected[AMDGPU_MAX_CRTCS] = { 0 };
> +
> + for_each_new_connector_in_state(state, connector, conn_state, i) {
> + if (conn_state->crtc != crtc)
> + continue;
> +
> + aconnector = to_amdgpu_dm_connector(connector);
> + if (!aconnector->port)
> + aconnector = NULL;
> + else
> + break;
> + }
> +
> + if (!aconnector)
> + return 0;
> +
> + i = 0;
> + drm_connector_list_iter_begin(state->dev, _iter);
> + drm_for_each_connector_iter(connector, _iter) {
> + if (!connector->state || !connector->state->crtc)
> + continue;
> +
> + aconnector_to_add = to_amdgpu_dm_connector(connector);
> + if (!aconnector_to_add->port)
> + continue;
> +
> + if (aconnector_to_add->port->mgr != aconnector->port->mgr)
> + continue;
>  
> + if (!aconnector_to_add->dc_sink)
> + continue;
> +
> + if (!aconnector_to_add->dc_sink-
> >sink_dsc_caps.dsc_dec_caps.is_dsc_supported)
> + continue;
> +
> + if (i >= AMDGPU_MAX_CRTCS)
> + continue;
> +
> + crtcs_affected[i] = connector->state->crtc;
> + i++;
> + }
> + drm_connector_list_iter_end(_iter);
> +
> + for (j = 0; j < i; j++) {
> + new_crtc_state = drm_atomic_get_crtc_state(state,
> crtcs_affected[j]);
> + if (IS_ERR(new_crtc_state))
> + return PTR_ERR(new_crtc_state);
> +
> + new_crtc_state->mode_changed = true;
> + }
> +
> + return 0;
> +
> +}
> +#endif
>  static void get_freesync_config_for_crtc(
>   struct dm_crtc_state *new_crtc_state,
>   struct dm_connector_state *new_con_state)
> @@ -7160,6 +7223,17 @@ static int amdgpu_dm_atomic_check(struct drm_device
> *dev,
>   if (ret)
>   goto fail;
>  
> +#ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
> + if (adev->asic_type >= CHIP_NAVI10) {
> + for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
> new_crtc_state, i) {
> + if (drm_atomic_crtc_needs_modeset(new_crtc_state)) {
> + ret = add_affected_mst_dsc_crtcs(state, crtc);
> + if (ret)
> + goto fail;
> + }
> + }
> + }
> +#endif
>   for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
> new_crtc_state, i) {
>   if (!drm_atomic_crtc_needs_modeset(new_crtc_state) &&
>   !new_crtc_state->color_mgmt_changed &&
-- 
Cheers,
Lyude Paul

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Re: [PATCH v2 10/14] drm/dp-mst: Fill branch->num_ports

2019-08-20 Thread Lyude Paul
On Tue, 2019-08-20 at 15:11 -0400, David Francis wrote:
> This field on drm_dp_mst_branch was never filled
> 
> Initialize it to zero when the list of ports is created.
> When a port is added to the list, increment num_ports
> 
> Signed-off-by: David Francis 
> ---
>  drivers/gpu/drm/drm_dp_mst_topology.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c
> b/drivers/gpu/drm/drm_dp_mst_topology.c
> index 5d5bd42da17c..0c580d5279c1 100644
> --- a/drivers/gpu/drm/drm_dp_mst_topology.c
> +++ b/drivers/gpu/drm/drm_dp_mst_topology.c
> @@ -918,6 +918,7 @@ static struct drm_dp_mst_branch
> *drm_dp_add_mst_branch_device(u8 lct, u8 *rad)
>   INIT_LIST_HEAD(>ports);
>   kref_init(>topology_kref);
>   kref_init(>malloc_kref);
> + mstb->num_ports = 0;
>   return mstb;
>  }
>  
> @@ -1672,6 +1673,7 @@ static void drm_dp_add_port(struct drm_dp_mst_branch
> *mstb,
>   mutex_lock(>mgr->lock);
>   drm_dp_mst_topology_get_port(port);
>   list_add(>next, >ports);
> + mstb->num_ports++;

You're forgot to add mstb->num_ports--; lower down in the function:

if (!port->connector) {
/* remove it from the port list */
mutex_lock(>mgr->lock);
list_del(>next);
/* Right here > */
mutex_unlock(>mgr->lock);
/* drop port list reference */
drm_dp_mst_topology_put_port(port);
goto out;
}

With that fixed:

Reviewed-by: Lyude Paul 

>   mutex_unlock(>mgr->lock);
>   }
>  
-- 
Cheers,
Lyude Paul

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Re: [PATCH v2 09/14] drm/dp-mst: Export symbols for dpcd read/write

2019-08-20 Thread Lyude Paul
[Added Leo Li here, since they did the auxdev work that introduced these
functions]

Since it seems we'll actually be doing remote DPCD read/writes in DRM drivers
and not just from auxdev, maybe we should combine drm_dp_dpcd_read() with
drm_dp_mst_dpcd_read() and do the same with the _write() variants? Based on
previous discussions with Leo Li I remember that we can't just combine the
dp_aux_dev->transfer() callbacks in struct drm_dp_aux_dev, but I don't see a
reason we can't just teach drm_dp_dpcd_read/write() to work with MST aux so
that we don't need two seperate functions. This should be pretty easy to do,
just:

/* Add a check like this at the start of drm_dp_dpcd_read(): */
ssize_t drm_dp_dpcd_read(...) {
if (aux->is_remote)
return drm_dp_mst_dpcd_read(...);

/* ... */
}

/* And in drm_dp_dpcd_write(): */
ssize_t drm_dp_dpcd_write(...) {
if (aux->is_remote)
return drm_dp_mst_dpcd_write(...);

/* ... */
}

Then just replace the manual calls to drm_dp_mst_dpcd_write() in
drivers/gpu/drm/drm_dp_aux_dev.c with normal
drm_dp_dpcd_read()/drm_dp_dpcd_write() calls. Thoughts?

On Tue, 2019-08-20 at 15:11 -0400, David Francis wrote:
> To use these functions in drm driver directories, they must be
> exported
> 
> Signed-off-by: David Francis 
> ---
>  drivers/gpu/drm/drm_dp_mst_topology.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c
> b/drivers/gpu/drm/drm_dp_mst_topology.c
> index b40d975aec76..5d5bd42da17c 100644
> --- a/drivers/gpu/drm/drm_dp_mst_topology.c
> +++ b/drivers/gpu/drm/drm_dp_mst_topology.c
> @@ -1512,6 +1512,7 @@ ssize_t drm_dp_mst_dpcd_read(struct drm_dp_aux *aux,
>   return drm_dp_send_dpcd_read(port->mgr, port,
>offset, size, buffer);
>  }
> +EXPORT_SYMBOL(drm_dp_mst_dpcd_read);
>  
>  /**
>   * drm_dp_mst_dpcd_write() - write a series of bytes to the DPCD via
> sideband
> @@ -1535,6 +1536,7 @@ ssize_t drm_dp_mst_dpcd_write(struct drm_dp_aux *aux,
>   return drm_dp_send_dpcd_write(port->mgr, port,
> offset, size, buffer);
>  }
> +EXPORT_SYMBOL(drm_dp_mst_dpcd_write);
>  
>  static void drm_dp_check_mstb_guid(struct drm_dp_mst_branch *mstb, u8
> *guid)
>  {
-- 
Cheers,
Lyude Paul

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Re: [PATCH v2 06/14] drm/dp-mst: Use dc and drm helpers to compute timeslots

2019-08-20 Thread Lyude Paul
Some nitpicks below

On Tue, 2019-08-20 at 15:11 -0400, David Francis wrote:
> We were using drm helpers to convert a timing into its
> bandwidth, its bandwidth into pbn, and its pbn into timeslots
> 
> These helpers
> -Did not take DSC timings into account
> -Used the link rate and lane count of the link's aux device,
>  which are not the same as the link's current cap
> -Did not take FEC into account (FEC reduces the PBN per timeslot)
> 
> For converting timing into PBN, add a new function
> drm_dp_calc_pbn_mode_dsc that handles the DSC case
> 
> For converting PBN into time slots, amdgpu doesn't use the
> 'correct' atomic method (drm_dp_atomic_find_vcpi_slots), so
> don't add a new helper to cover our approach. Use the same
> means of calculating pbn per time slot as the DSC code.
> 
> v2: Add drm helper for clock to pbn conversion
> 
> Cc: Jerry Zuo 
> Cc: Nicholas Kazlauskas 
> Signed-off-by: David Francis 
> ---
>  .../amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 18 +---
>  drivers/gpu/drm/drm_dp_mst_topology.c | 41 +++
>  include/drm/drm_dp_mst_helper.h   |  2 +-
>  3 files changed, 54 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
> b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
> index 5f2c315b18ba..dfa99e0d6e64 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
> @@ -189,8 +189,8 @@ bool dm_helpers_dp_mst_write_payload_allocation_table(
>   int slots = 0;
>   bool ret;
>   int clock;
> - int bpp = 0;
>   int pbn = 0;
> + int pbn_per_timeslot, bpp = 0;
>  
>   aconnector = (struct amdgpu_dm_connector *)stream->dm_stream_context;
>  
> @@ -208,7 +208,6 @@ bool dm_helpers_dp_mst_write_payload_allocation_table(
>   clock = stream->timing.pix_clk_100hz / 10;
>  
>   switch (stream->timing.display_color_depth) {
> -
>   case COLOR_DEPTH_666:
>   bpp = 6;
>   break;
> @@ -234,11 +233,18 @@ bool dm_helpers_dp_mst_write_payload_allocation_table(
>  
>   bpp = bpp * 3;
>  
> - /* TODO need to know link rate */
> -
> - pbn = drm_dp_calc_pbn_mode(clock, bpp);
> +#ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
> + if (stream->timing.flags.DSC)
> + pbn = drm_dp_calc_pbn_mode_dsc(clock,
> + stream-
> >timing.dsc_cfg.bits_per_pixel);
> + else
> +#endif
> + pbn = drm_dp_calc_pbn_mode(clock, bpp);
>  
> - slots = drm_dp_find_vcpi_slots(mst_mgr, pbn);
> + /* Convert kilobits per second / 64 (for 64 timeslots) to pbn
> (54/64 megabytes per second) */
> + pbn_per_timeslot = dc_link_bandwidth_kbps(
> + stream->link, dc_link_get_link_cap(stream-
> >link)) / (8 * 1000 * 54);
> + slots = DIV_ROUND_UP(pbn, pbn_per_timeslot);
>   ret = drm_dp_mst_allocate_vcpi(mst_mgr, mst_port, pbn, slots);
>  
>   if (!ret)
> diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c
> b/drivers/gpu/drm/drm_dp_mst_topology.c
> index 398e7314ea8b..d789b7af7dbf 100644
> --- a/drivers/gpu/drm/drm_dp_mst_topology.c
> +++ b/drivers/gpu/drm/drm_dp_mst_topology.c
> @@ -3588,6 +3588,47 @@ static int test_calc_pbn_mode(void)
>   return 0;
>  }
>  
> +/**
> + * drm_dp_calc_pbn_mode_dsc() - Calculate the PBN for a mode with DSC
> enabled.
> + * @clock: dot clock for the mode
> + * @dsc_bpp: dsc bits per pixel x16 (e.g. dsc_bpp = 136 is 8.5 bpp)
> + *
> + * This uses the formula in the spec to calculate the PBN value for a mode,
> + * given that the mode is using DSC

You should use the proper kdoc formatting for documenting return values (not
all of the DP MST code does this currently, but that's a bug I haven't taken
the time to fix :):

/*
 * foo_bar() - foo the bar
 *
 * foos the bar, guaranteed
 * Returns:
 * Some magic number
 */

> + */
> +int drm_dp_calc_pbn_mode_dsc(int clock, int dsc_bpp)
> +{
> + u64 kbps;
> + s64 peak_kbps;
> + u32 numerator;
> + u32 denominator;
> +
> + kbps = clock * dsc_bpp;
> +
> + /*
> +  * margin 5300ppm + 300ppm ~ 0.6% as per spec, factor is 1.006
> +  * The unit of 54/64Mbytes/sec is an arbitrary unit chosen based on
> +  * common multiplier to render an integer PBN for all link rate/lane
> +  * counts combinations
> +  * calculate
> +  * peak_kbps *= (1/16) bppx16 to bpp
> +  * peak_kbps *= (1006/1000)
> +  * peak_kbps *= (64/54)
> +  * peak_kbps *= 8convert to bytes
> +  *
> +  * Divide numerator and denominator by 16 to avoid overflow
> +  */
> +
> + numerator = 64 * 1006 / 16;
> + denominator = 54 * 8 * 1000 * 1000;
> +
> + kbps *= numerator;
> + peak_kbps = drm_fixp_from_fraction(kbps, denominator);
> +

Re: [PATCH v2 08/14] drm/dp-mst: Parse FEC capability on MST ports

2019-08-20 Thread Lyude Paul
Reviewed-by: Lyude Paul 

On Tue, 2019-08-20 at 15:11 -0400, David Francis wrote:
> As of DP1.4, ENUM_PATH_RESOURCES returns a bit indicating
> if FEC can be supported up to that point in the MST network.
> 
> The bit is the first byte of the ENUM_PATH_RESOURCES ack reply,
> bottom-most bit (refer to section 2.11.9.4 of DP standard,
> v1.4)
> 
> That value is needed for FEC and DSC support
> 
> Store it on drm_dp_mst_port
> 
> Signed-off-by: David Francis 
> ---
>  drivers/gpu/drm/drm_dp_mst_topology.c | 2 ++
>  include/drm/drm_dp_mst_helper.h   | 3 +++
>  2 files changed, 5 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c
> b/drivers/gpu/drm/drm_dp_mst_topology.c
> index d789b7af7dbf..b40d975aec76 100644
> --- a/drivers/gpu/drm/drm_dp_mst_topology.c
> +++ b/drivers/gpu/drm/drm_dp_mst_topology.c
> @@ -552,6 +552,7 @@ static bool
> drm_dp_sideband_parse_enum_path_resources_ack(struct drm_dp_sideband
>  {
>   int idx = 1;
>   repmsg->u.path_resources.port_number = (raw->msg[idx] >> 4) & 0xf;
> + repmsg->u.path_resources.fec_capable = raw->msg[idx] & 0x1;
>   idx++;
>   if (idx > raw->curlen)
>   goto fail_len;
> @@ -2180,6 +2181,7 @@ static int drm_dp_send_enum_path_resources(struct
> drm_dp_mst_topology_mgr *mgr,
>   DRM_DEBUG_KMS("enum path resources %d: %d %d\n",
> txmsg->reply.u.path_resources.port_number, txmsg-
> >reply.u.path_resources.full_payload_bw_number,
>  txmsg-
> >reply.u.path_resources.avail_payload_bw_number);
>   port->available_pbn = txmsg-
> >reply.u.path_resources.avail_payload_bw_number;
> + port->fec_capable = txmsg-
> >reply.u.path_resources.fec_capable;
>   }
>   }
>  
> diff --git a/include/drm/drm_dp_mst_helper.h
> b/include/drm/drm_dp_mst_helper.h
> index ddb518f2157a..fa973773a4a7 100644
> --- a/include/drm/drm_dp_mst_helper.h
> +++ b/include/drm/drm_dp_mst_helper.h
> @@ -108,6 +108,8 @@ struct drm_dp_mst_port {
>* audio-capable.
>*/
>   bool has_audio;
> +
> + bool fec_capable;
>  };
>  
>  /**
> @@ -312,6 +314,7 @@ struct drm_dp_port_number_req {
>  
>  struct drm_dp_enum_path_resources_ack_reply {
>   u8 port_number;
> + bool fec_capable;
>   u16 full_payload_bw_number;
>   u16 avail_payload_bw_number;
>  };
-- 
Cheers,
Lyude Paul

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Re: [PATCH v4 00/25] drm: Kirin driver cleanups to prep for Kirin960 support

2019-08-20 Thread John Stultz
On Tue, Aug 20, 2019 at 1:01 PM Sam Ravnborg  wrote:
>
> Hi John.
>
> On Mon, Aug 19, 2019 at 11:02:56PM +, John Stultz wrote:
> > Sending this out again, to get it based on drm-misc-next.
> >
> > This patchset contains one fix (in the front, so its easier to
> > eventually backport), and a series of changes from YiPing to
> > refactor the kirin drm driver so that it can be used on both
> > kirin620 based devices (like the original HiKey board) as well
> > as kirin960 based devices (like the HiKey960 board).
> >
> > The full kirin960 drm support is still being refactored, but as
> > this base kirin rework was getting to be substantial, I wanted
> > to send out the first chunk, so that the review burden wasn't
> > overwhelming.
> >
> > The full HiKey960 patch stack can be found here:
> >   
> > https://git.linaro.org/people/john.stultz/android-dev.git/log/?h=dev/hikey960-mainline-WIP
> >
> > thanks
> > -john
> >
> >
> > New in v4:
> > * Rebased to drm-misc-next, minor tweaks to merge changes
> > * Dropped "drm: kirin: Get rid of drmP.h includes" as similar change
> >   was already in drm-misc next
> > * Added acked-by tag from Xinliang
>
> There was some checkpatch noises in some of the patches - please verify
> with "--strict".

Ah. Apologies. I had not run with --strict.

> And then the build failed like this:
>  LD [M]  drivers/gpu/drm/hisilicon/kirin/kirin-drm.o
> aarch64-linux-gnu-ld: drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.o: in 
> function `init_module':
> dw_drm_dsi.c:(.init.text+0x0): multiple definition of `init_module'; 
> drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.o:kirin_drm_drv.c:(.init.text+0x0):
>  first defined here
> aarch64-linux-gnu-ld: drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.o: in 
> function `cleanup_module':
> dw_drm_dsi.c:(.exit.text+0x0): multiple definition of `cleanup_module'; 
> drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.o:kirin_drm_drv.c:(.exit.text+0x0):
>  first defined here
> make[3]: *** [/home/sam/drm/linux.git/scripts/Makefile.build:464: 
> drivers/gpu/drm/hisilicon/kirin/kirin-drm.o] Error 1
> make[2]: *** [/home/sam/drm/linux.git/scripts/Makefile.build:490: 
> drivers/gpu/drm/hisilicon/kirin] Error 2
> make[1]: *** [/home/sam/drm/linux.git/Makefile:1776: 
> drivers/gpu/drm/hisilicon/] Error 2
> make[1]: Leaving directory '/home/sam/drm/linux.git/.build/arm64-allmodconfig'
> make: *** [Makefile:179: sub-make] Error 2
>
> It was a simple allmodconfig build where I did:
>
> make drivers/gpu/drm/hisilicon/

Yes, I've not used modules much with the board. I'll fix this up.

> Please fix and resend. I did not look further.

Apologies again, thanks so much for finding these issues! I'll get a
new series to you shortly once the issues are resolved and I've
validated things.

thanks
-john
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Re: [PATCH v2 11/14] drm/amd/display: Validate DSC caps on MST endpoints

2019-08-20 Thread Lyude Paul
Hi, I was looking through patchwork and just noticed this series. I've been
working on trying to rework a lot of the drm MST helpers (currently on hold
for a short bit while I fix some other unrelated issues at work...), and one
of the things we're currently missing with our helpers are helpers for
handling checking the PBN of downstream sinks (which could be added to
drm_dp_mst_atomic_check()). As well, it looks like you could also add a DRM
helper for checking for DSC/FEC support on mstbs. Thoughts?

On Tue, 2019-08-20 at 15:12 -0400, David Francis wrote:
> The first step in MST DSC is checking MST endpoints
> to see how DSC can be enabled
> 
> Case 1: DP-to-DP peer device
> if the branch immediately upstream has
>  - PDT = DP_PEER_DEVICE_DP_MST_BRANCHING (2)
>  - DPCD rev. >= DP 1.4
>  - Exactly one input and one output
>  - The output has PDT = DP_PEER_DEVICE_SST_SINK (3)
> 
> In this case, DSC could be possible either on the endpoint
> or the peer device. Prefer the endpoint, which is possible if
>  - The endpoint has DP_DSC_DECOMPRESSION_IS_SUPPORTED bit set
>  - The endpoint has DP_FEC_CAPABLE bit set
>  - The peer device has DSC_PASSTHROUGH_CAPABILITY bit set (from DP v2.0)
> 
> Otherwise, use the peer device
> 
> Case 2: DP-to-HDMI peer device
> If the output port has
>  - PDT = DP_PEER_DEVICE_DP_LEGACY_CONV (4)
>  - DPCD rev. >= DP 1.4
>  - LDPS = true
>  - MCS = false
> 
> In this case, DSC can only be attempted on the peer device
> (the output port)
> 
> Case 3: Virtual DP Sink (Internal Display Panel)
> If the output port has
>  - DPCD rev. >= DP 1.4
>  - port_num >= 8
> 
> In this case, DSC can only be attempted on the peer device
> (the output port)
> 
> Case 4: Synaptix Workaround
> If the output has
>  - link DPCD rev. >= DP 1.4
>  - link branch_dev_id = 0x90CC24 (Synaptix)
>  - There is exactly one branch device between the link and output
> 
> In this case, DSC can be attempted, but only using the *link*
> aux device's caps. This is a quirk.
> 
> Test for these cases as modes are enumerated for an MST endpoint.
> We cannot do this during link attach because the dc_sink object
> will not have been created yet
> 
> If no DSC is attempted, zero the DSC caps
> 
> Cc: Wenjing Liu 
> Cc: Nikola Cornij 
> Signed-off-by: David Francis 
> ---
>  .../display/amdgpu_dm/amdgpu_dm_mst_types.c   | 123 +-
>  .../display/amdgpu_dm/amdgpu_dm_mst_types.h   |   3 +
>  2 files changed, 125 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
> b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
> index 16218a202b59..58571844f6d5 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
> @@ -25,6 +25,7 @@
>  
>  #include 
>  #include 
> +#include 
>  #include "dm_services.h"
>  #include "amdgpu.h"
>  #include "amdgpu_dm.h"
> @@ -189,6 +190,120 @@ static const struct drm_connector_funcs
> dm_dp_mst_connector_funcs = {
>   .early_unregister = amdgpu_dm_mst_connector_early_unregister,
>  };
>  
> +bool is_virtual_dpcd(struct drm_dp_mst_port *port)
> +{
> + struct drm_dp_mst_port *downstream_port;
> +
> + if (!port)
> + return false;
> +
> + if (port->port_num >= 8 &&
> + port->dpcd_rev >= DP_DPCD_REV_14) {
> + /* Virtual DP Sink (Internal Display Panel) */
> + return true;
> + } else if (port->pdt == DP_PEER_DEVICE_DP_LEGACY_CONV &&
> + !port->mcs &&
> + port->ldps &&
> + port->dpcd_rev >= DP_DPCD_REV_14) {
> + /* DP-to-HDMI Protocol Converter */
> + return true;
> + } else if (port->pdt == DP_PEER_DEVICE_MST_BRANCHING &&
> + port->mstb &&
> + port->dpcd_rev >= DP_DPCD_REV_14) {
> + /* DP-to-DP */
> + if (port->mstb->num_ports == 2) {
> + list_for_each_entry(downstream_port, >mstb-
> >ports, next) {
> + if (!downstream_port->input &&
> + downstream_port->pdt ==
> DP_PEER_DEVICE_SST_SINK)
> + return true;
> + }
> + }
> + }
> + return false;
> +}
> +
> +bool synaptix_workaround(struct amdgpu_dm_connector *aconnector)
> +{
> + struct drm_dp_mst_port *port = aconnector->port;
> + struct dc_link *link = aconnector->dc_sink->link;
> + u8 down_stream_port_data;
> +
> + if (port->mgr->mst_primary == port->parent &&
> + link->dpcd_caps.branch_dev_id == 0x90CC24 &&
> + link->dpcd_caps.dpcd_rev.raw >= DP_DPCD_REV_14) {
> + drm_dp_mst_dpcd_read(>aux, DP_DOWNSTREAMPORT_PRESENT,
> _stream_port_data, 1);
> + if ((down_stream_port_data & 7) != 3)
> + return true;
> + }
> + 

Re: [PATCH 3/4] kernel.h: Add non_block_start/end()

2019-08-20 Thread Daniel Vetter
On Tue, Aug 20, 2019 at 10:19:01AM +0200, Daniel Vetter wrote:
> In some special cases we must not block, but there's not a
> spinlock, preempt-off, irqs-off or similar critical section already
> that arms the might_sleep() debug checks. Add a non_block_start/end()
> pair to annotate these.
> 
> This will be used in the oom paths of mmu-notifiers, where blocking is
> not allowed to make sure there's forward progress. Quoting Michal:
> 
> "The notifier is called from quite a restricted context - oom_reaper -
> which shouldn't depend on any locks or sleepable conditionals. The code
> should be swift as well but we mostly do care about it to make a forward
> progress. Checking for sleepable context is the best thing we could come
> up with that would describe these demands at least partially."
> 
> Peter also asked whether we want to catch spinlocks on top, but Michal
> said those are less of a problem because spinlocks can't have an
> indirect dependency upon the page allocator and hence close the loop
> with the oom reaper.
> 
> Suggested by Michal Hocko.
> 
> v2:
> - Improve commit message (Michal)
> - Also check in schedule, not just might_sleep (Peter)
> 
> v3: It works better when I actually squash in the fixup I had lying
> around :-/
> 
> v4: Pick the suggestion from Andrew Morton to give non_block_start/end
> some good kerneldoc comments. I added that other blocking calls like
> wait_event pose similar issues, since that's the other example we
> discussed.
> 
> Cc: Jason Gunthorpe 
> Cc: Peter Zijlstra 
> Cc: Ingo Molnar 
> Cc: Andrew Morton 
> Cc: Michal Hocko 
> Cc: David Rientjes 
> Cc: "Christian König" 
> Cc: Daniel Vetter 
> Cc: "Jérôme Glisse" 
> Cc: linux...@kvack.org
> Cc: Masahiro Yamada 
> Cc: Wei Wang 
> Cc: Andy Shevchenko 
> Cc: Thomas Gleixner 
> Cc: Jann Horn 
> Cc: Feng Tang 
> Cc: Kees Cook 
> Cc: Randy Dunlap 
> Cc: linux-ker...@vger.kernel.org
> Acked-by: Christian König  (v1)
> Signed-off-by: Daniel Vetter 

Hi Peter,

Iirc you've been involved at least somewhat in discussing this. -mm folks
are a bit undecided whether these new non_block semantics are a good idea.
Michal Hocko still is in support, but Andrew Morton and Jason Gunthorpe
are less enthusiastic. Jason said he's ok with merging the hmm side of
this if scheduler folks ack. If not, then I'll respin with the
preempt_disable/enable instead like in v1.

So ack/nack for this from the scheduler side?

Thanks, Daniel

> ---
>  include/linux/kernel.h | 25 -
>  include/linux/sched.h  |  4 
>  kernel/sched/core.c| 19 ++-
>  3 files changed, 42 insertions(+), 6 deletions(-)
> 
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index 4fa360a13c1e..82f84cfe372f 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -217,7 +217,9 @@ extern void __cant_sleep(const char *file, int line, int 
> preempt_offset);
>   * might_sleep - annotation for functions that can sleep
>   *
>   * this macro will print a stack trace if it is executed in an atomic
> - * context (spinlock, irq-handler, ...).
> + * context (spinlock, irq-handler, ...). Additional sections where blocking 
> is
> + * not allowed can be annotated with non_block_start() and non_block_end()
> + * pairs.
>   *
>   * This is a useful debugging help to be able to catch problems early and not
>   * be bitten later when the calling function happens to sleep when it is not
> @@ -233,6 +235,25 @@ extern void __cant_sleep(const char *file, int line, int 
> preempt_offset);
>  # define cant_sleep() \
>   do { __cant_sleep(__FILE__, __LINE__, 0); } while (0)
>  # define sched_annotate_sleep()  (current->task_state_change = 0)
> +/**
> + * non_block_start - annotate the start of section where sleeping is 
> prohibited
> + *
> + * This is on behalf of the oom reaper, specifically when it is calling the 
> mmu
> + * notifiers. The problem is that if the notifier were to block on, for 
> example,
> + * mutex_lock() and if the process which holds that mutex were to perform a
> + * sleeping memory allocation, the oom reaper is now blocked on completion of
> + * that memory allocation. Other blocking calls like wait_event() pose 
> similar
> + * issues.
> + */
> +# define non_block_start() \
> + do { current->non_block_count++; } while (0)
> +/**
> + * non_block_end - annotate the end of section where sleeping is prohibited
> + *
> + * Closes a section opened by non_block_start().
> + */
> +# define non_block_end() \
> + do { WARN_ON(current->non_block_count-- == 0); } while (0)
>  #else
>static inline void ___might_sleep(const char *file, int line,
>  int preempt_offset) { }
> @@ -241,6 +262,8 @@ extern void __cant_sleep(const char *file, int line, int 
> preempt_offset);
>  # define might_sleep() do { might_resched(); } while (0)
>  # define cant_sleep() do { } while (0)
>  # define sched_annotate_sleep() do { } while (0)
> +# define non_block_start() do { } 

Re: [PATCH v4 00/25] drm: Kirin driver cleanups to prep for Kirin960 support

2019-08-20 Thread Sam Ravnborg
Hi John.

On Mon, Aug 19, 2019 at 11:02:56PM +, John Stultz wrote:
> Sending this out again, to get it based on drm-misc-next.
> 
> This patchset contains one fix (in the front, so its easier to
> eventually backport), and a series of changes from YiPing to
> refactor the kirin drm driver so that it can be used on both
> kirin620 based devices (like the original HiKey board) as well
> as kirin960 based devices (like the HiKey960 board).
> 
> The full kirin960 drm support is still being refactored, but as
> this base kirin rework was getting to be substantial, I wanted
> to send out the first chunk, so that the review burden wasn't
> overwhelming.
> 
> The full HiKey960 patch stack can be found here:
>   
> https://git.linaro.org/people/john.stultz/android-dev.git/log/?h=dev/hikey960-mainline-WIP
> 
> thanks
> -john
> 
> 
> New in v4:
> * Rebased to drm-misc-next, minor tweaks to merge changes
> * Dropped "drm: kirin: Get rid of drmP.h includes" as similar change
>   was already in drm-misc next
> * Added acked-by tag from Xinliang

There was some checkpatch noises in some of the patches - please verify
with "--strict".
Mostly alignment of parameters with open parantesis
Sample - but there was similar issues in other patches:

8788b59decc8 (HEAD -> drm-misc-next) drm: kirin: Move ade drm init to kirin drm 
drv
-:208: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#208: FILE: drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c:41:
+static int kirin_drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
+   struct drm_plane *plane,

-:244: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#244: FILE: drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c:77:
+   ret = drm_universal_plane_init(dev, plane, 1, data->plane_funcs,
+   data->channel_formats,

-:271: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#271: FILE: drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c:104:
+static int kirin_drm_private_init(struct drm_device *dev,
+   const struct kirin_drm_data *driver_data)




And then the build failed like this:
 LD [M]  drivers/gpu/drm/hisilicon/kirin/kirin-drm.o
aarch64-linux-gnu-ld: drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.o: in function 
`init_module':
dw_drm_dsi.c:(.init.text+0x0): multiple definition of `init_module'; 
drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.o:kirin_drm_drv.c:(.init.text+0x0):
 first defined here
aarch64-linux-gnu-ld: drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.o: in function 
`cleanup_module':
dw_drm_dsi.c:(.exit.text+0x0): multiple definition of `cleanup_module'; 
drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.o:kirin_drm_drv.c:(.exit.text+0x0):
 first defined here
make[3]: *** [/home/sam/drm/linux.git/scripts/Makefile.build:464: 
drivers/gpu/drm/hisilicon/kirin/kirin-drm.o] Error 1
make[2]: *** [/home/sam/drm/linux.git/scripts/Makefile.build:490: 
drivers/gpu/drm/hisilicon/kirin] Error 2
make[1]: *** [/home/sam/drm/linux.git/Makefile:1776: 
drivers/gpu/drm/hisilicon/] Error 2
make[1]: Leaving directory '/home/sam/drm/linux.git/.build/arm64-allmodconfig'
make: *** [Makefile:179: sub-make] Error 2

It was a simple allmodconfig build where I did:

make drivers/gpu/drm/hisilicon/

Please fix and resend. I did not look further.

Sam


[PATCH 1/3] dt-bindings: Convert Arm Mali Midgard GPU to DT schema

2019-08-20 Thread Rob Herring
Convert the Arm Midgard GPU binding to DT schema format.

Signed-off-by: Rob Herring 
---
 .../bindings/gpu/arm,mali-midgard.txt | 119 -
 .../bindings/gpu/arm,mali-midgard.yaml| 165 ++
 2 files changed, 165 insertions(+), 119 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/gpu/arm,mali-midgard.txt
 create mode 100644 Documentation/devicetree/bindings/gpu/arm,mali-midgard.yaml

diff --git a/Documentation/devicetree/bindings/gpu/arm,mali-midgard.txt 
b/Documentation/devicetree/bindings/gpu/arm,mali-midgard.txt
deleted file mode 100644
index 9b298edec5b2..
--- a/Documentation/devicetree/bindings/gpu/arm,mali-midgard.txt
+++ /dev/null
@@ -1,119 +0,0 @@
-ARM Mali Midgard GPU
-
-
-Required properties:
-
-- compatible :
-  * Must contain one of the following:
-+ "arm,mali-t604"
-+ "arm,mali-t624"
-+ "arm,mali-t628"
-+ "arm,mali-t720"
-+ "arm,mali-t760"
-+ "arm,mali-t820"
-+ "arm,mali-t830"
-+ "arm,mali-t860"
-+ "arm,mali-t880"
-  * which must be preceded by one of the following vendor specifics:
-+ "allwinner,sun50i-h6-mali"
-+ "amlogic,meson-gxm-mali"
-+ "samsung,exynos5433-mali"
-+ "rockchip,rk3288-mali"
-+ "rockchip,rk3399-mali"
-
-- reg : Physical base address of the device and length of the register area.
-
-- interrupts : Contains the three IRQ lines required by Mali Midgard devices.
-
-- interrupt-names : Contains the names of IRQ resources in the order they were
-  provided in the interrupts property. Must contain: "job", "mmu", "gpu".
-
-
-Optional properties:
-
-- clocks : Phandle to clock for the Mali Midgard device.
-
-- clock-names : Specify the names of the clocks specified in clocks
-  when multiple clocks are present.
-* core: clock driving the GPU itself (When only one clock is present,
-  assume it's this clock.)
-* bus: bus clock for the GPU
-
-- mali-supply : Phandle to regulator for the Mali device. Refer to
-  Documentation/devicetree/bindings/regulator/regulator.txt for details.
-
-- operating-points-v2 : Refer to Documentation/devicetree/bindings/opp/opp.txt
-  for details.
-
-- #cooling-cells: Refer to 
Documentation/devicetree/bindings/thermal/thermal.txt
-  for details.
-
-- resets : Phandle of the GPU reset line.
-
-Vendor-specific bindings
-
-
-The Mali GPU is integrated very differently from one SoC to
-another. In order to accommodate those differences, you have the option
-to specify one more vendor-specific compatible, among:
-
-- "allwinner,sun50i-h6-mali"
-  Required properties:
-  - clocks : phandles to core and bus clocks
-  - clock-names : must contain "core" and "bus"
-  - resets: phandle to GPU reset line
-
-- "amlogic,meson-gxm-mali"
-  Required properties:
-  - resets : Should contain phandles of :
-+ GPU reset line
-+ GPU APB glue reset line
-
-Example for a Mali-T760:
-
-gpu@ffa3 {
-   compatible = "rockchip,rk3288-mali", "arm,mali-t760";
-   reg = <0xffa3 0x1>;
-   interrupts = ,
-,
-;
-   interrupt-names = "job", "mmu", "gpu";
-   clocks = < ACLK_GPU>;
-   mali-supply = <_gpu>;
-   operating-points-v2 = <_opp_table>;
-   power-domains = < RK3288_PD_GPU>;
-   #cooling-cells = <2>;
-};
-
-gpu_opp_table: opp_table0 {
-   compatible = "operating-points-v2";
-
-   opp@53300 {
-   opp-hz = /bits/ 64 <53300>;
-   opp-microvolt = <125>;
-   };
-   opp@45000 {
-   opp-hz = /bits/ 64 <45000>;
-   opp-microvolt = <115>;
-   };
-   opp@4 {
-   opp-hz = /bits/ 64 <4>;
-   opp-microvolt = <1125000>;
-   };
-   opp@35000 {
-   opp-hz = /bits/ 64 <35000>;
-   opp-microvolt = <1075000>;
-   };
-   opp@26600 {
-   opp-hz = /bits/ 64 <26600>;
-   opp-microvolt = <1025000>;
-   };
-   opp@16000 {
-   opp-hz = /bits/ 64 <16000>;
-   opp-microvolt = <925000>;
-   };
-   opp@1 {
-   opp-hz = /bits/ 64 <1>;
-   opp-microvolt = <912500>;
-   };
-};
diff --git a/Documentation/devicetree/bindings/gpu/arm,mali-midgard.yaml 
b/Documentation/devicetree/bindings/gpu/arm,mali-midgard.yaml
new file mode 100644
index ..24c4af74fb8d
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpu/arm,mali-midgard.yaml
@@ -0,0 +1,165 @@
+# SPDX-License-Identifier: GPL-2.0-only
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/gpu/arm,mali-midgard.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ARM Mali Midgard GPU
+
+maintainers:
+  - Rob Herring 
+
+properties:
+  $nodename:
+pattern: '^gpu@[a-f0-9]+$'
+  compatible:
+oneOf:
+  - items:
+  - enum:
+ - 

[PATCH 2/3] dt-bindings: Convert Arm Mali Bifrost GPU to DT schema

2019-08-20 Thread Rob Herring
Convert the Arm Bifrost GPU binding to DT schema format.

Signed-off-by: Rob Herring 
---
 .../bindings/gpu/arm,mali-bifrost.txt |  92 --
 .../bindings/gpu/arm,mali-bifrost.yaml| 115 ++
 2 files changed, 115 insertions(+), 92 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/gpu/arm,mali-bifrost.txt
 create mode 100644 Documentation/devicetree/bindings/gpu/arm,mali-bifrost.yaml

diff --git a/Documentation/devicetree/bindings/gpu/arm,mali-bifrost.txt 
b/Documentation/devicetree/bindings/gpu/arm,mali-bifrost.txt
deleted file mode 100644
index b8be9dbc68b4..
--- a/Documentation/devicetree/bindings/gpu/arm,mali-bifrost.txt
+++ /dev/null
@@ -1,92 +0,0 @@
-ARM Mali Bifrost GPU
-
-
-Required properties:
-
-- compatible :
-  * Since Mali Bifrost GPU model/revision is fully discoverable by reading
-some determined registers, must contain the following:
-+ "arm,mali-bifrost"
-  * which must be preceded by one of the following vendor specifics:
-+ "amlogic,meson-g12a-mali"
-
-- reg : Physical base address of the device and length of the register area.
-
-- interrupts : Contains the three IRQ lines required by Mali Bifrost devices,
-  in the following defined order.
-
-- interrupt-names : Contains the names of IRQ resources in this exact defined
-  order: "job", "mmu", "gpu".
-
-Optional properties:
-
-- clocks : Phandle to clock for the Mali Bifrost device.
-
-- mali-supply : Phandle to regulator for the Mali device. Refer to
-  Documentation/devicetree/bindings/regulator/regulator.txt for details.
-
-- operating-points-v2 : Refer to Documentation/devicetree/bindings/opp/opp.txt
-  for details.
-
-- resets : Phandle of the GPU reset line.
-
-Vendor-specific bindings
-
-
-The Mali GPU is integrated very differently from one SoC to
-another. In order to accommodate those differences, you have the option
-to specify one more vendor-specific compatible, among:
-
-- "amlogic,meson-g12a-mali"
-  Required properties:
-  - resets : Should contain phandles of :
-+ GPU reset line
-+ GPU APB glue reset line
-
-Example for a Mali-G31:
-
-gpu@ffa3 {
-   compatible = "amlogic,meson-g12a-mali", "arm,mali-bifrost";
-   reg = <0xffe4 0x1>;
-   interrupts = ,
-,
-;
-   interrupt-names = "job", "mmu", "gpu";
-   clocks = < CLKID_MALI>;
-   mali-supply = <_gpu>;
-   operating-points-v2 = <_opp_table>;
-   resets = < RESET_DVALIN_CAPB3>, < RESET_DVALIN>;
-};
-
-gpu_opp_table: opp_table0 {
-   compatible = "operating-points-v2";
-
-   opp@53300 {
-   opp-hz = /bits/ 64 <53300>;
-   opp-microvolt = <125>;
-   };
-   opp@45000 {
-   opp-hz = /bits/ 64 <45000>;
-   opp-microvolt = <115>;
-   };
-   opp@4 {
-   opp-hz = /bits/ 64 <4>;
-   opp-microvolt = <1125000>;
-   };
-   opp@35000 {
-   opp-hz = /bits/ 64 <35000>;
-   opp-microvolt = <1075000>;
-   };
-   opp@26600 {
-   opp-hz = /bits/ 64 <26600>;
-   opp-microvolt = <1025000>;
-   };
-   opp@16000 {
-   opp-hz = /bits/ 64 <16000>;
-   opp-microvolt = <925000>;
-   };
-   opp@1 {
-   opp-hz = /bits/ 64 <1>;
-   opp-microvolt = <912500>;
-   };
-};
diff --git a/Documentation/devicetree/bindings/gpu/arm,mali-bifrost.yaml 
b/Documentation/devicetree/bindings/gpu/arm,mali-bifrost.yaml
new file mode 100644
index ..51f63c9dac46
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpu/arm,mali-bifrost.yaml
@@ -0,0 +1,115 @@
+# SPDX-License-Identifier: GPL-2.0-only
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/gpu/arm,mali-bifrost.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ARM Mali Bifrost GPU
+
+maintainers:
+  - Rob Herring 
+
+properties:
+  $nodename:
+pattern: '^gpu@[a-f0-9]+$'
+
+  compatible:
+items:
+  - enum:
+  - amlogic,meson-g12a-mali
+  - const: arm,mali-bifrost # Mali Bifrost GPU model/revision is fully 
discoverable
+
+  reg:
+maxItems: 1
+
+  interrupts:
+items:
+  - description: Job interrupt
+  - description: MMU interrupt
+  - description: GPU interrupt
+
+  interrupt-names:
+items:
+  - const: job
+  - const: mmu
+  - const: gpu
+
+  clocks:
+maxItems: 1
+
+  mali-supply:
+maxItems: 1
+
+  operating-points-v2: true
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-names
+
+allOf:
+  - if:
+  properties:
+compatible:
+  contains:
+const: amlogic,meson-g12a-mali
+then:
+  properties:
+resets:
+  minItems: 2
+  required:
+- resets
+
+examples:
+  - |
+

[PATCH 0/3] dt-bindings: Convert Arm Mali GPUs to DT schema

2019-08-20 Thread Rob Herring
This series converts the various Arm Mali GPU bindings to use the DT
schema format.

The Midgard and Bifrost bindings generate warnings on 'interrupt-names'
because there's all different ordering. The Utgard binding generates 
warnings on Rockchip platforms because 'clock-names' order is reversed.

Rob

Rob Herring (3):
  dt-bindings: Convert Arm Mali Midgard GPU to DT schema
  dt-bindings: Convert Arm Mali Bifrost GPU to DT schema
  dt-bindings: Convert Arm Mali Utgard GPU to DT schema

 .../bindings/gpu/arm,mali-bifrost.txt |  92 --
 .../bindings/gpu/arm,mali-bifrost.yaml| 115 
 .../bindings/gpu/arm,mali-midgard.txt | 119 -
 .../bindings/gpu/arm,mali-midgard.yaml| 165 +
 .../bindings/gpu/arm,mali-utgard.txt  | 129 --
 .../bindings/gpu/arm,mali-utgard.yaml | 166 ++
 6 files changed, 446 insertions(+), 340 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/gpu/arm,mali-bifrost.txt
 create mode 100644 Documentation/devicetree/bindings/gpu/arm,mali-bifrost.yaml
 delete mode 100644 Documentation/devicetree/bindings/gpu/arm,mali-midgard.txt
 create mode 100644 Documentation/devicetree/bindings/gpu/arm,mali-midgard.yaml
 delete mode 100644 Documentation/devicetree/bindings/gpu/arm,mali-utgard.txt
 create mode 100644 Documentation/devicetree/bindings/gpu/arm,mali-utgard.yaml

-- 
2.20.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH 3/3] dt-bindings: Convert Arm Mali Utgard GPU to DT schema

2019-08-20 Thread Rob Herring
Convert the Arm Utgard GPU binding to DT schema format.

'allwinner,sun8i-a23-mali' compatible was not documented, so add it.

Signed-off-by: Rob Herring 
---
 .../bindings/gpu/arm,mali-utgard.txt  | 129 --
 .../bindings/gpu/arm,mali-utgard.yaml | 166 ++
 2 files changed, 166 insertions(+), 129 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/gpu/arm,mali-utgard.txt
 create mode 100644 Documentation/devicetree/bindings/gpu/arm,mali-utgard.yaml

diff --git a/Documentation/devicetree/bindings/gpu/arm,mali-utgard.txt 
b/Documentation/devicetree/bindings/gpu/arm,mali-utgard.txt
deleted file mode 100644
index ba895efe3039..
--- a/Documentation/devicetree/bindings/gpu/arm,mali-utgard.txt
+++ /dev/null
@@ -1,129 +0,0 @@
-ARM Mali Utgard GPU
-===
-
-Required properties:
-  - compatible
-* Must be one of the following:
-  + "arm,mali-300"
-  + "arm,mali-400"
-  + "arm,mali-450"
-* And, optionally, one of the vendor specific compatible:
-  + allwinner,sun4i-a10-mali
-  + allwinner,sun7i-a20-mali
-  + allwinner,sun8i-h3-mali
-  + allwinner,sun50i-a64-mali
-  + allwinner,sun50i-h5-mali
-  + amlogic,meson8-mali
-  + amlogic,meson8b-mali
-  + amlogic,meson-gxbb-mali
-  + amlogic,meson-gxl-mali
-  + samsung,exynos4210-mali
-  + rockchip,rk3036-mali
-  + rockchip,rk3066-mali
-  + rockchip,rk3188-mali
-  + rockchip,rk3228-mali
-  + rockchip,rk3328-mali
-  + stericsson,db8500-mali
-  + hisilicon,hi6220-mali
-
-  - reg: Physical base address and length of the GPU registers
-
-  - interrupts: an entry for each entry in interrupt-names.
-See ../interrupt-controller/interrupts.txt for details.
-
-  - interrupt-names:
-* ppX: Pixel Processor X interrupt (X from 0 to 7)
-* ppmmuX: Pixel Processor X MMU interrupt (X from 0 to 7)
-* pp: Pixel Processor broadcast interrupt (mali-450 only)
-* gp: Geometry Processor interrupt
-* gpmmu: Geometry Processor MMU interrupt
-
-  - clocks: an entry for each entry in clock-names
-  - clock-names:
-* bus: bus clock for the GPU
-* core: clock driving the GPU itself
-
-Optional properties:
-  - interrupt-names and interrupts:
-* pmu: Power Management Unit interrupt, if implemented in hardware
-
-  - memory-region:
-Memory region to allocate from, as defined in
-Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt
-
-  - mali-supply:
-Phandle to regulator for the Mali device, as defined in
-Documentation/devicetree/bindings/regulator/regulator.txt for details.
-
-  - operating-points-v2:
-Operating Points for the GPU, as defined in
-Documentation/devicetree/bindings/opp/opp.txt
-
-  - power-domains:
-A power domain consumer specifier as defined in
-Documentation/devicetree/bindings/power/power_domain.txt
-
-Vendor-specific bindings
-
-
-The Mali GPU is integrated very differently from one SoC to
-another. In order to accomodate those differences, you have the option
-to specify one more vendor-specific compatible, among:
-
-  - allwinner,sun4i-a10-mali
-Required properties:
-  * resets: phandle to the reset line for the GPU
-
-  - allwinner,sun7i-a20-mali
-Required properties:
-  * resets: phandle to the reset line for the GPU
-
-  - allwinner,sun50i-a64-mali
-Required properties:
-  * resets: phandle to the reset line for the GPU
-
-  - allwinner,sun50i-h5-mali
-Required properties:
-  * resets: phandle to the reset line for the GPU
-
-  - amlogic,meson8-mali and amlogic,meson8b-mali
-Required properties:
-  * resets: phandle to the reset line for the GPU
-
-  - Rockchip variants:
-Required properties:
-  * resets: phandle to the reset line for the GPU
-
-  - stericsson,db8500-mali
-Required properties:
-  * interrupt-names and interrupts:
-+ combined: combined interrupt of all of the above lines
-
-  - hisilicon,hi6220-mali
-Required properties:
-  * resets: phandles to the reset lines for the GPU
-
-Example:
-
-mali: gpu@1c4 {
-   compatible = "allwinner,sun7i-a20-mali", "arm,mali-400";
-   reg = <0x01c4 0x1>;
-   interrupts = ,
-,
-,
-,
-,
-,
-;
-   interrupt-names = "gp",
- "gpmmu",
- "pp0",
- "ppmmu0",
- "pp1",
- "ppmmu1",
- "pmu";
-   clocks = < CLK_BUS_GPU>, < CLK_GPU>;
-   clock-names = "bus", "core";
-   resets = < RST_BUS_GPU>;
-};
-
diff --git a/Documentation/devicetree/bindings/gpu/arm,mali-utgard.yaml 
b/Documentation/devicetree/bindings/gpu/arm,mali-utgard.yaml
new file mode 100644
index ..d3883ba09174
--- /dev/null

[PATCH v2 07/14] drm/amd/display: Initialize DSC PPS variables to 0

2019-08-20 Thread David Francis
For DSC MST, sometimes monitors would break out
in full-screen static. The issue traced back to the
PPS generation code, where these variables were being used
uninitialized and were picking up garbage.

memset to 0 to avoid this

Signed-off-by: David Francis 
Reviewed-by: Nicholas Kazlauskas 
---
 drivers/gpu/drm/amd/display/dc/core/dc_link_hwss.c | 3 +++
 drivers/gpu/drm/amd/display/dc/dcn20/dcn20_dsc.c   | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_link_hwss.c 
b/drivers/gpu/drm/amd/display/dc/core/dc_link_hwss.c
index 35c5467e60e8..619ac48edd05 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc_link_hwss.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_link_hwss.c
@@ -491,6 +491,9 @@ bool dp_set_dsc_pps_sdp(struct pipe_ctx *pipe_ctx, bool 
enable)
struct dsc_config dsc_cfg;
uint8_t dsc_packed_pps[128];
 
+   memset(_cfg, 0, sizeof(dsc_cfg));
+   memset(dsc_packed_pps, 0, 128);
+
/* Enable DSC hw block */
dsc_cfg.pic_width = stream->timing.h_addressable + 
stream->timing.h_border_left + stream->timing.h_border_right;
dsc_cfg.pic_height = stream->timing.v_addressable + 
stream->timing.v_border_top + stream->timing.v_border_bottom;
diff --git a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_dsc.c 
b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_dsc.c
index 379c9e4ac63b..16debe6d89f2 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_dsc.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_dsc.c
@@ -207,6 +207,9 @@ static bool dsc2_get_packed_pps(struct 
display_stream_compressor *dsc, const str
struct dsc_reg_values dsc_reg_vals;
struct dsc_optc_config dsc_optc_cfg;
 
+   memset(_reg_vals, 0, sizeof(dsc_reg_vals));
+   memset(_optc_cfg, 0, sizeof(dsc_optc_cfg));
+
DC_LOG_DSC("Getting packed DSC PPS for DSC Config:");
dsc_config_log(dsc, dsc_cfg);
DC_LOG_DSC("DSC Picture Parameter Set (PPS):");
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v2 08/14] drm/dp-mst: Parse FEC capability on MST ports

2019-08-20 Thread David Francis
As of DP1.4, ENUM_PATH_RESOURCES returns a bit indicating
if FEC can be supported up to that point in the MST network.

The bit is the first byte of the ENUM_PATH_RESOURCES ack reply,
bottom-most bit (refer to section 2.11.9.4 of DP standard,
v1.4)

That value is needed for FEC and DSC support

Store it on drm_dp_mst_port

Signed-off-by: David Francis 
---
 drivers/gpu/drm/drm_dp_mst_topology.c | 2 ++
 include/drm/drm_dp_mst_helper.h   | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c 
b/drivers/gpu/drm/drm_dp_mst_topology.c
index d789b7af7dbf..b40d975aec76 100644
--- a/drivers/gpu/drm/drm_dp_mst_topology.c
+++ b/drivers/gpu/drm/drm_dp_mst_topology.c
@@ -552,6 +552,7 @@ static bool 
drm_dp_sideband_parse_enum_path_resources_ack(struct drm_dp_sideband
 {
int idx = 1;
repmsg->u.path_resources.port_number = (raw->msg[idx] >> 4) & 0xf;
+   repmsg->u.path_resources.fec_capable = raw->msg[idx] & 0x1;
idx++;
if (idx > raw->curlen)
goto fail_len;
@@ -2180,6 +2181,7 @@ static int drm_dp_send_enum_path_resources(struct 
drm_dp_mst_topology_mgr *mgr,
DRM_DEBUG_KMS("enum path resources %d: %d %d\n", 
txmsg->reply.u.path_resources.port_number, 
txmsg->reply.u.path_resources.full_payload_bw_number,
   
txmsg->reply.u.path_resources.avail_payload_bw_number);
port->available_pbn = 
txmsg->reply.u.path_resources.avail_payload_bw_number;
+   port->fec_capable = 
txmsg->reply.u.path_resources.fec_capable;
}
}
 
diff --git a/include/drm/drm_dp_mst_helper.h b/include/drm/drm_dp_mst_helper.h
index ddb518f2157a..fa973773a4a7 100644
--- a/include/drm/drm_dp_mst_helper.h
+++ b/include/drm/drm_dp_mst_helper.h
@@ -108,6 +108,8 @@ struct drm_dp_mst_port {
 * audio-capable.
 */
bool has_audio;
+
+   bool fec_capable;
 };
 
 /**
@@ -312,6 +314,7 @@ struct drm_dp_port_number_req {
 
 struct drm_dp_enum_path_resources_ack_reply {
u8 port_number;
+   bool fec_capable;
u16 full_payload_bw_number;
u16 avail_payload_bw_number;
 };
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v2 05/14] drm/amd/display: Enable SST DSC in DM

2019-08-20 Thread David Francis
In create_stream_for_sink, check for SST DP connectors

Parse DSC caps to DC format, then, if DSC is supported,
compute the config

DSC hardware will be programmed by dc_commit_state

Tested-by: Mikita Lipski 
Signed-off-by: David Francis 
Reviewed-by: Nicholas Kazlauskas 
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 32 ---
 .../amd/display/amdgpu_dm/amdgpu_dm_helpers.c |  4 ++-
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 911fe78b47c1..84249057e181 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -3576,6 +3576,10 @@ create_stream_for_sink(struct amdgpu_dm_connector 
*aconnector,
bool scale = dm_state ? (dm_state->scaling != RMX_OFF) : false;
int mode_refresh;
int preferred_refresh = 0;
+#ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
+   struct dsc_dec_dpcd_caps dsc_caps;
+   uint32_t link_bandwidth_kbps;
+#endif
 
struct dc_sink *sink = NULL;
if (aconnector == NULL) {
@@ -3648,17 +3652,23 @@ create_stream_for_sink(struct amdgpu_dm_connector 
*aconnector,
, >base, con_state, old_stream);
 
 #ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
-   /* stream->timing.flags.DSC = 0; */
-/*  */
-   /* if (aconnector->dc_link && */
-   /*  aconnector->dc_link->connector_signal == 
SIGNAL_TYPE_DISPLAY_PORT #<{(|&& */
-   /*  
aconnector->dc_link->dpcd_caps.dsc_caps.dsc_basic_caps.is_dsc_supported|)}>#) */
-   /*  if (dc_dsc_compute_config(aconnector->dc_link->ctx->dc, */
-   /*  >dc_link->dpcd_caps.dsc_caps, */
-   /*  dc_link_bandwidth_kbps(aconnector->dc_link, 
dc_link_get_link_cap(aconnector->dc_link)), */
-   /*  >timing, */
-   /*  >timing.dsc_cfg)) */
-   /*  stream->timing.flags.DSC = 1; */
+   stream->timing.flags.DSC = 0;
+
+   if (aconnector->dc_link && sink->sink_signal == 
SIGNAL_TYPE_DISPLAY_PORT) {
+   
dc_dsc_parse_dsc_dpcd(aconnector->dc_link->dpcd_caps.dsc_caps.dsc_basic_caps.raw,
+ 
aconnector->dc_link->dpcd_caps.dsc_caps.dsc_ext_caps.raw,
+ _caps);
+   link_bandwidth_kbps = 
dc_link_bandwidth_kbps(aconnector->dc_link,
+
dc_link_get_link_cap(aconnector->dc_link));
+
+   if (dsc_caps.is_dsc_supported)
+   if (dc_dsc_compute_config(aconnector->dc_link->ctx->dc,
+ _caps,
+ link_bandwidth_kbps,
+ >timing,
+ >timing.dsc_cfg))
+   stream->timing.flags.DSC = 1;
+   }
 #endif
 
update_stream_scaling_settings(, dm_state, stream);
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
index 7cf0573ab25f..5f2c315b18ba 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
@@ -549,7 +549,9 @@ bool dm_helpers_dp_write_dsc_enable(
bool enable
 )
 {
-   return false;
+   uint8_t enable_dsc = enable ? 1 : 0;
+
+   return dm_helpers_dp_write_dpcd(ctx, stream->sink->link, DP_DSC_ENABLE, 
_dsc, 1);
 }
 #endif
 
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v2 11/14] drm/amd/display: Validate DSC caps on MST endpoints

2019-08-20 Thread David Francis
The first step in MST DSC is checking MST endpoints
to see how DSC can be enabled

Case 1: DP-to-DP peer device
if the branch immediately upstream has
 - PDT = DP_PEER_DEVICE_DP_MST_BRANCHING (2)
 - DPCD rev. >= DP 1.4
 - Exactly one input and one output
 - The output has PDT = DP_PEER_DEVICE_SST_SINK (3)

In this case, DSC could be possible either on the endpoint
or the peer device. Prefer the endpoint, which is possible if
 - The endpoint has DP_DSC_DECOMPRESSION_IS_SUPPORTED bit set
 - The endpoint has DP_FEC_CAPABLE bit set
 - The peer device has DSC_PASSTHROUGH_CAPABILITY bit set (from DP v2.0)

Otherwise, use the peer device

Case 2: DP-to-HDMI peer device
If the output port has
 - PDT = DP_PEER_DEVICE_DP_LEGACY_CONV (4)
 - DPCD rev. >= DP 1.4
 - LDPS = true
 - MCS = false

In this case, DSC can only be attempted on the peer device
(the output port)

Case 3: Virtual DP Sink (Internal Display Panel)
If the output port has
 - DPCD rev. >= DP 1.4
 - port_num >= 8

In this case, DSC can only be attempted on the peer device
(the output port)

Case 4: Synaptix Workaround
If the output has
 - link DPCD rev. >= DP 1.4
 - link branch_dev_id = 0x90CC24 (Synaptix)
 - There is exactly one branch device between the link and output

In this case, DSC can be attempted, but only using the *link*
aux device's caps. This is a quirk.

Test for these cases as modes are enumerated for an MST endpoint.
We cannot do this during link attach because the dc_sink object
will not have been created yet

If no DSC is attempted, zero the DSC caps

Cc: Wenjing Liu 
Cc: Nikola Cornij 
Signed-off-by: David Francis 
---
 .../display/amdgpu_dm/amdgpu_dm_mst_types.c   | 123 +-
 .../display/amdgpu_dm/amdgpu_dm_mst_types.h   |   3 +
 2 files changed, 125 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
index 16218a202b59..58571844f6d5 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
@@ -25,6 +25,7 @@
 
 #include 
 #include 
+#include 
 #include "dm_services.h"
 #include "amdgpu.h"
 #include "amdgpu_dm.h"
@@ -189,6 +190,120 @@ static const struct drm_connector_funcs 
dm_dp_mst_connector_funcs = {
.early_unregister = amdgpu_dm_mst_connector_early_unregister,
 };
 
+bool is_virtual_dpcd(struct drm_dp_mst_port *port)
+{
+   struct drm_dp_mst_port *downstream_port;
+
+   if (!port)
+   return false;
+
+   if (port->port_num >= 8 &&
+   port->dpcd_rev >= DP_DPCD_REV_14) {
+   /* Virtual DP Sink (Internal Display Panel) */
+   return true;
+   } else if (port->pdt == DP_PEER_DEVICE_DP_LEGACY_CONV &&
+   !port->mcs &&
+   port->ldps &&
+   port->dpcd_rev >= DP_DPCD_REV_14) {
+   /* DP-to-HDMI Protocol Converter */
+   return true;
+   } else if (port->pdt == DP_PEER_DEVICE_MST_BRANCHING &&
+   port->mstb &&
+   port->dpcd_rev >= DP_DPCD_REV_14) {
+   /* DP-to-DP */
+   if (port->mstb->num_ports == 2) {
+   list_for_each_entry(downstream_port, 
>mstb->ports, next) {
+   if (!downstream_port->input &&
+   downstream_port->pdt == 
DP_PEER_DEVICE_SST_SINK)
+   return true;
+   }
+   }
+   }
+   return false;
+}
+
+bool synaptix_workaround(struct amdgpu_dm_connector *aconnector)
+{
+   struct drm_dp_mst_port *port = aconnector->port;
+   struct dc_link *link = aconnector->dc_sink->link;
+   u8 down_stream_port_data;
+
+   if (port->mgr->mst_primary == port->parent &&
+   link->dpcd_caps.branch_dev_id == 0x90CC24 &&
+   link->dpcd_caps.dpcd_rev.raw >= DP_DPCD_REV_14) {
+   drm_dp_mst_dpcd_read(>aux, DP_DOWNSTREAMPORT_PRESENT, 
_stream_port_data, 1);
+   if ((down_stream_port_data & 7) != 3)
+   return true;
+   }
+   return false;
+}
+
+#ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
+static bool validate_dsc_caps_on_connector(struct amdgpu_dm_connector 
*aconnector)
+{
+   u8 upstream_dsc_caps[16] = { 0 };
+   u8 endpoint_dsc_caps[16] = { 0 };
+   u8 endpoint_fec_caps = 0;
+   struct dc_sink *dc_sink = aconnector->dc_sink;
+   struct drm_dp_mst_port *output_port = aconnector->port;
+   struct drm_dp_mst_port *immediate_upstream_port;
+   struct drm_dp_mst_port *fec_port;
+
+   if (aconnector->port && aconnector->port->parent)
+   immediate_upstream_port = aconnector->port->parent->port_parent;
+   else
+   immediate_upstream_port = NULL;
+
+   fec_port = immediate_upstream_port;
+   

[PATCH v2 06/14] drm/dp-mst: Use dc and drm helpers to compute timeslots

2019-08-20 Thread David Francis
We were using drm helpers to convert a timing into its
bandwidth, its bandwidth into pbn, and its pbn into timeslots

These helpers
-Did not take DSC timings into account
-Used the link rate and lane count of the link's aux device,
 which are not the same as the link's current cap
-Did not take FEC into account (FEC reduces the PBN per timeslot)

For converting timing into PBN, add a new function
drm_dp_calc_pbn_mode_dsc that handles the DSC case

For converting PBN into time slots, amdgpu doesn't use the
'correct' atomic method (drm_dp_atomic_find_vcpi_slots), so
don't add a new helper to cover our approach. Use the same
means of calculating pbn per time slot as the DSC code.

v2: Add drm helper for clock to pbn conversion

Cc: Jerry Zuo 
Cc: Nicholas Kazlauskas 
Signed-off-by: David Francis 
---
 .../amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 18 +---
 drivers/gpu/drm/drm_dp_mst_topology.c | 41 +++
 include/drm/drm_dp_mst_helper.h   |  2 +-
 3 files changed, 54 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
index 5f2c315b18ba..dfa99e0d6e64 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
@@ -189,8 +189,8 @@ bool dm_helpers_dp_mst_write_payload_allocation_table(
int slots = 0;
bool ret;
int clock;
-   int bpp = 0;
int pbn = 0;
+   int pbn_per_timeslot, bpp = 0;
 
aconnector = (struct amdgpu_dm_connector *)stream->dm_stream_context;
 
@@ -208,7 +208,6 @@ bool dm_helpers_dp_mst_write_payload_allocation_table(
clock = stream->timing.pix_clk_100hz / 10;
 
switch (stream->timing.display_color_depth) {
-
case COLOR_DEPTH_666:
bpp = 6;
break;
@@ -234,11 +233,18 @@ bool dm_helpers_dp_mst_write_payload_allocation_table(
 
bpp = bpp * 3;
 
-   /* TODO need to know link rate */
-
-   pbn = drm_dp_calc_pbn_mode(clock, bpp);
+#ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
+   if (stream->timing.flags.DSC)
+   pbn = drm_dp_calc_pbn_mode_dsc(clock,
+   stream->timing.dsc_cfg.bits_per_pixel);
+   else
+#endif
+   pbn = drm_dp_calc_pbn_mode(clock, bpp);
 
-   slots = drm_dp_find_vcpi_slots(mst_mgr, pbn);
+   /* Convert kilobits per second / 64 (for 64 timeslots) to pbn 
(54/64 megabytes per second) */
+   pbn_per_timeslot = dc_link_bandwidth_kbps(
+   stream->link, 
dc_link_get_link_cap(stream->link)) / (8 * 1000 * 54);
+   slots = DIV_ROUND_UP(pbn, pbn_per_timeslot);
ret = drm_dp_mst_allocate_vcpi(mst_mgr, mst_port, pbn, slots);
 
if (!ret)
diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c 
b/drivers/gpu/drm/drm_dp_mst_topology.c
index 398e7314ea8b..d789b7af7dbf 100644
--- a/drivers/gpu/drm/drm_dp_mst_topology.c
+++ b/drivers/gpu/drm/drm_dp_mst_topology.c
@@ -3588,6 +3588,47 @@ static int test_calc_pbn_mode(void)
return 0;
 }
 
+/**
+ * drm_dp_calc_pbn_mode_dsc() - Calculate the PBN for a mode with DSC enabled.
+ * @clock: dot clock for the mode
+ * @dsc_bpp: dsc bits per pixel x16 (e.g. dsc_bpp = 136 is 8.5 bpp)
+ *
+ * This uses the formula in the spec to calculate the PBN value for a mode,
+ * given that the mode is using DSC
+ */
+int drm_dp_calc_pbn_mode_dsc(int clock, int dsc_bpp)
+{
+   u64 kbps;
+   s64 peak_kbps;
+   u32 numerator;
+   u32 denominator;
+
+   kbps = clock * dsc_bpp;
+
+   /*
+* margin 5300ppm + 300ppm ~ 0.6% as per spec, factor is 1.006
+* The unit of 54/64Mbytes/sec is an arbitrary unit chosen based on
+* common multiplier to render an integer PBN for all link rate/lane
+* counts combinations
+* calculate
+* peak_kbps *= (1/16) bppx16 to bpp
+* peak_kbps *= (1006/1000)
+* peak_kbps *= (64/54)
+* peak_kbps *= 8convert to bytes
+*
+* Divide numerator and denominator by 16 to avoid overflow
+*/
+
+   numerator = 64 * 1006 / 16;
+   denominator = 54 * 8 * 1000 * 1000;
+
+   kbps *= numerator;
+   peak_kbps = drm_fixp_from_fraction(kbps, denominator);
+
+   return drm_fixp2int_ceil(peak_kbps);
+}
+EXPORT_SYMBOL(drm_dp_calc_pbn_mode_dsc);
+
 /* we want to kick the TX after we've ack the up/down IRQs. */
 static void drm_dp_mst_kick_tx(struct drm_dp_mst_topology_mgr *mgr)
 {
diff --git a/include/drm/drm_dp_mst_helper.h b/include/drm/drm_dp_mst_helper.h
index 2ba6253ea6d3..ddb518f2157a 100644
--- a/include/drm/drm_dp_mst_helper.h
+++ b/include/drm/drm_dp_mst_helper.h
@@ -611,7 +611,7 @@ struct edid *drm_dp_mst_get_edid(struct drm_connector 

[PATCH v2 01/14] Revert "drm/amd/display: skip dsc config for navi10 bring up"

2019-08-20 Thread David Francis
This reverts commit 55ad81f3510ec1a1c19e6a4d8a6319812d07d256.

optc dsc config was causing warnings due to missing register
definitions. With the registers restored, the function can
be re-enabled

The reverted commit also disabled sanity checks and dsc
power gating. The sanity check warnings are not associated
with dsc, and power gating on dsc still has an issue on
non-dsc monitors where the dsc hardware block is never init
and so cannot respond to power gating requests. Therefore,
those are left as is

Signed-off-by: David Francis 
Reviewed-by: Roman Li 
Reviewed-by: Harry Wentland 
Reviewed-by: Nicholas Kazlauskas 
---
 drivers/gpu/drm/amd/display/dc/dcn20/dcn20_optc.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_optc.c 
b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_optc.c
index aedf9de1c947..99070e93020b 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_optc.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_optc.c
@@ -191,15 +191,6 @@ void optc2_set_dsc_config(struct timing_generator *optc,
uint32_t dsc_slice_width)
 {
struct optc *optc1 = DCN10TG_FROM_TG(optc);
-   uint32_t data_format = 0;
-   /* skip if dsc mode is not changed */
-   data_format = dm_read_reg(CTX, REG(OPTC_DATA_FORMAT_CONTROL));
-
-   data_format = data_format & 0x30; /* bit5:4 */
-   data_format = data_format >> 4;
-
-   if (data_format == dsc_mode)
-   return;
 
REG_UPDATE(OPTC_DATA_FORMAT_CONTROL,
OPTC_DSC_MODE, dsc_mode);
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v2 14/14] drm/amd/display: Trigger modesets on MST DSC connectors

2019-08-20 Thread David Francis
Whenever a connector on an MST network is attached, detached, or
undergoes a modeset, the DSC configs for each stream on that
topology will be recalculated. This can change their required
bandwidth, requiring a full reprogramming, as though a modeset
was performed, even if that stream did not change timing.

Therefore, whenever a crtc has drm_atomic_crtc_needs_modeset,
for each crtc that shares a MST topology with that stream and
supports DSC, add that crtc (and all affected connectors and
planes) to the atomic state and set mode_changed on its state

v2: Do this check only on Navi and before adding connectors
and planes on modesetting crtcs

Cc: Leo Li 
Cc: Nicholas Kazlauskas 
Signed-off-by: David Francis 
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 74 +++
 1 file changed, 74 insertions(+)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 145fd73025dc..e64f2a6eb71a 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -6475,7 +6475,70 @@ static int do_aquire_global_lock(struct drm_device *dev,
 
return ret < 0 ? ret : 0;
 }
+#ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
+static int add_affected_mst_dsc_crtcs(struct drm_atomic_state *state, struct 
drm_crtc *crtc)
+{
+   struct drm_connector *connector;
+   struct drm_connector_state *conn_state;
+   struct drm_connector_list_iter conn_iter;
+   struct drm_crtc_state *new_crtc_state;
+   struct amdgpu_dm_connector *aconnector = NULL, *aconnector_to_add;
+   int i, j;
+   struct drm_crtc *crtcs_affected[AMDGPU_MAX_CRTCS] = { 0 };
+
+   for_each_new_connector_in_state(state, connector, conn_state, i) {
+   if (conn_state->crtc != crtc)
+   continue;
+
+   aconnector = to_amdgpu_dm_connector(connector);
+   if (!aconnector->port)
+   aconnector = NULL;
+   else
+   break;
+   }
+
+   if (!aconnector)
+   return 0;
+
+   i = 0;
+   drm_connector_list_iter_begin(state->dev, _iter);
+   drm_for_each_connector_iter(connector, _iter) {
+   if (!connector->state || !connector->state->crtc)
+   continue;
+
+   aconnector_to_add = to_amdgpu_dm_connector(connector);
+   if (!aconnector_to_add->port)
+   continue;
+
+   if (aconnector_to_add->port->mgr != aconnector->port->mgr)
+   continue;
 
+   if (!aconnector_to_add->dc_sink)
+   continue;
+
+   if 
(!aconnector_to_add->dc_sink->sink_dsc_caps.dsc_dec_caps.is_dsc_supported)
+   continue;
+
+   if (i >= AMDGPU_MAX_CRTCS)
+   continue;
+
+   crtcs_affected[i] = connector->state->crtc;
+   i++;
+   }
+   drm_connector_list_iter_end(_iter);
+
+   for (j = 0; j < i; j++) {
+   new_crtc_state = drm_atomic_get_crtc_state(state, 
crtcs_affected[j]);
+   if (IS_ERR(new_crtc_state))
+   return PTR_ERR(new_crtc_state);
+
+   new_crtc_state->mode_changed = true;
+   }
+
+   return 0;
+
+}
+#endif
 static void get_freesync_config_for_crtc(
struct dm_crtc_state *new_crtc_state,
struct dm_connector_state *new_con_state)
@@ -7160,6 +7223,17 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev,
if (ret)
goto fail;
 
+#ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
+   if (adev->asic_type >= CHIP_NAVI10) {
+   for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, 
new_crtc_state, i) {
+   if (drm_atomic_crtc_needs_modeset(new_crtc_state)) {
+   ret = add_affected_mst_dsc_crtcs(state, crtc);
+   if (ret)
+   goto fail;
+   }
+   }
+   }
+#endif
for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, 
new_crtc_state, i) {
if (!drm_atomic_crtc_needs_modeset(new_crtc_state) &&
!new_crtc_state->color_mgmt_changed &&
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v2 03/14] Revert "drm/amd/display: add global master update lock for DCN2"

2019-08-20 Thread David Francis
This reverts commit 55a6f5bbcf00a49565946c0a9b8c716313dc6c05.

This commit was accidentally promoted twice

Signed-off-by: David Francis 
Reviewed-by: Roman Li 
Reviewed-by: Harry Wentland 
Reviewed-by: Nicholas Kazlauskas 
---
 .../drm/amd/display/dc/dcn20/dcn20_hwseq.c|  4 --
 .../gpu/drm/amd/display/dc/dcn20/dcn20_optc.c | 63 +--
 .../gpu/drm/amd/display/dc/dcn20/dcn20_optc.h |  3 -
 .../amd/display/dc/inc/hw/timing_generator.h  |  2 -
 4 files changed, 1 insertion(+), 71 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_hwseq.c 
b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_hwseq.c
index fa8a73f6c8e3..e146d1d8d45e 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_hwseq.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_hwseq.c
@@ -575,10 +575,6 @@ enum dc_status dcn20_enable_stream_timing(
pipe_ctx->stream->signal,
true);
 
-   if (pipe_ctx->stream_res.tg->funcs->setup_global_lock)
-   pipe_ctx->stream_res.tg->funcs->setup_global_lock(
-   pipe_ctx->stream_res.tg);
-
if (odm_pipe)
odm_pipe->stream_res.opp->funcs->opp_pipe_clock_control(
odm_pipe->stream_res.opp,
diff --git a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_optc.c 
b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_optc.c
index 99070e93020b..2137e2be2140 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_optc.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_optc.c
@@ -333,65 +333,6 @@ void optc2_triplebuffer_unlock(struct timing_generator 
*optc)
 
 }
 
-
-void optc2_setup_global_lock(struct timing_generator *optc)
-{
-   struct optc *optc1 = DCN10TG_FROM_TG(optc);
-   uint32_t v_blank_start = 0;
-   uint32_t h_blank_start = 0, h_total = 0;
-
-   REG_SET(OTG_GLOBAL_CONTROL1, 0, MASTER_UPDATE_LOCK_DB_EN, 1);
-
-   REG_SET(OTG_GLOBAL_CONTROL2, 0, DIG_UPDATE_LOCATION, 20);
-
-   REG_GET(OTG_V_BLANK_START_END, OTG_V_BLANK_START, _blank_start);
-
-   REG_GET(OTG_H_BLANK_START_END, OTG_H_BLANK_START, _blank_start);
-
-   REG_GET(OTG_H_TOTAL, OTG_H_TOTAL, _total);
-   REG_UPDATE_2(OTG_GLOBAL_CONTROL1,
-   MASTER_UPDATE_LOCK_DB_X,
-   h_blank_start - 200 - 1,
-   MASTER_UPDATE_LOCK_DB_Y,
-   v_blank_start - 1);
-}
-
-void optc2_lock_global(struct timing_generator *optc)
-{
-   struct optc *optc1 = DCN10TG_FROM_TG(optc);
-
-   REG_UPDATE(OTG_GLOBAL_CONTROL2, GLOBAL_UPDATE_LOCK_EN, 1);
-
-   REG_SET(OTG_GLOBAL_CONTROL0, 0,
-   OTG_MASTER_UPDATE_LOCK_SEL, optc->inst);
-   REG_SET(OTG_MASTER_UPDATE_LOCK, 0,
-   OTG_MASTER_UPDATE_LOCK, 1);
-
-   /* Should be fast, status does not update on maximus */
-   if (optc->ctx->dce_environment != DCE_ENV_FPGA_MAXIMUS)
-   REG_WAIT(OTG_MASTER_UPDATE_LOCK,
-   UPDATE_LOCK_STATUS, 1,
-   1, 10);
-}
-
-void optc2_lock(struct timing_generator *optc)
-{
-   struct optc *optc1 = DCN10TG_FROM_TG(optc);
-
-   REG_UPDATE(OTG_GLOBAL_CONTROL2, GLOBAL_UPDATE_LOCK_EN, 0);
-
-   REG_SET(OTG_GLOBAL_CONTROL0, 0,
-   OTG_MASTER_UPDATE_LOCK_SEL, optc->inst);
-   REG_SET(OTG_MASTER_UPDATE_LOCK, 0,
-   OTG_MASTER_UPDATE_LOCK, 1);
-
-   /* Should be fast, status does not update on maximus */
-   if (optc->ctx->dce_environment != DCE_ENV_FPGA_MAXIMUS)
-   REG_WAIT(OTG_MASTER_UPDATE_LOCK,
-   UPDATE_LOCK_STATUS, 1,
-   1, 10);
-}
-
 void optc2_lock_doublebuffer_enable(struct timing_generator *optc)
 {
struct optc *optc1 = DCN10TG_FROM_TG(optc);
@@ -486,10 +427,8 @@ static struct timing_generator_funcs dcn20_tg_funcs = {
.triplebuffer_lock = optc2_triplebuffer_lock,
.triplebuffer_unlock = optc2_triplebuffer_unlock,
.disable_reset_trigger = optc1_disable_reset_trigger,
-   .lock = optc2_lock,
+   .lock = optc1_lock,
.unlock = optc1_unlock,
-   .lock_global = optc2_lock_global,
-   .setup_global_lock = optc2_setup_global_lock,
.lock_doublebuffer_enable = optc2_lock_doublebuffer_enable,
.lock_doublebuffer_disable = optc2_lock_doublebuffer_disable,
.enable_optc_clock = optc1_enable_optc_clock,
diff --git a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_optc.h 
b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_optc.h
index 47cb4de1564c..32a58431fd09 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_optc.h
+++ b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_optc.h
@@ -106,9 +106,6 @@ void optc2_get_optc_source(struct timing_generator *optc,
 
 void optc2_triplebuffer_lock(struct timing_generator *optc);
 void 

[PATCH v2 13/14] drm/amd/display: MST DSC compute fair share

2019-08-20 Thread David Francis
If there is limited link bandwidth on a MST network,
it must be divided fairly between the streams on that network

Implement an algorithm to determine the correct DSC config
for each stream

The algorithm:
This
 [   ]  ( )
represents the range of bandwidths possible for a given stream.
The [] area represents the range of DSC configs, and the ()
represents no DSC. The bandwidth used increases from left to right.

First, try disabling DSC on all streams
 [  ]  (|)
 [ ](|)
Check this against the bandwidth limits of the link and each branch
(including each endpoint). If it passes, the job is done

Second, try maximum DSC compression on all streams
that support DSC
 [| ]( )
 [|] ( )
If this does not pass, then enabling this combination of streams
is impossible

Otherwise, divide the remaining bandwidth evenly amongst the streams
 [|  ] ( )
 [|  ]( )

If one or more of the streams reach minimum compression, evenly
divide the reamining bandwidth amongst the remaining streams
 [|] ( )
 [   |]   ( )
 [ |   ]   ( )
 [ |  ]  ( )

If all streams can reach minimum compression, disable compression
greedily
 [  |]  ( )
 [|]( )
 [ ](|)

Perform this algorithm on each full update, on each MST link
with at least one DSC stream on it

After the configs are computed, call
dcn20_add_dsc_to_stream_resource on each stream with DSC enabled.
It is only after all streams are created that we can know which
of them will need DSC.

Do all of this at the end of amdgpu atomic check.  If it fails,
fail check; This combination of timings cannot be supported.

Cc: Wenjing Liu 
Cc: Nikola Cornij 
Signed-off-by: David Francis 
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |   4 +
 .../display/amdgpu_dm/amdgpu_dm_mst_types.c   | 375 ++
 .../display/amdgpu_dm/amdgpu_dm_mst_types.h   |   4 +-
 .../drm/amd/display/dc/dcn20/dcn20_resource.c |   7 +-
 .../drm/amd/display/dc/dcn20/dcn20_resource.h |   1 +
 5 files changed, 388 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 84249057e181..145fd73025dc 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -7331,6 +7331,10 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev,
if (ret)
goto fail;
 
+#ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
+   if (!compute_mst_dsc_configs_for_state(dm_state->context))
+   goto fail;
+#endif
if (dc_validate_global_state(dc, dm_state->context, false) != 
DC_OK) {
ret = -EINVAL;
goto fail;
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
index 58571844f6d5..0b6bfa093e83 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
@@ -38,6 +38,8 @@
 
 #include "i2caux_interface.h"
 
+#include "dc/dcn20/dcn20_resource.h"
+
 /* #define TRACE_DPCD */
 
 #ifdef TRACE_DPCD
@@ -548,3 +550,376 @@ void amdgpu_dm_initialize_dp_connector(struct 
amdgpu_display_manager *dm,
aconnector->connector_id);
 }
 
+#ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
+struct dsc_mst_fairness_params {
+   struct dc_crtc_timing *timing;
+   struct dc_sink *sink;
+   struct dc_dsc_bw_range bw_range;
+   bool compression_possible;
+   struct drm_dp_mst_port *port;
+};
+
+struct dsc_mst_fairness_vars {
+   int pbn;
+   bool dsc_enabled;
+   int bpp_x16;
+};
+
+static bool port_downstream_of_branch(struct drm_dp_mst_port *port,
+   struct drm_dp_mst_branch *branch)
+{
+   while (port->parent) {
+   if (port->parent == branch)
+   return true;
+
+   if (port->parent->port_parent)
+   port = port->parent->port_parent;
+   else
+   break;
+   }
+   return false;
+}
+
+static bool check_pbn_limit_on_branch(struct drm_dp_mst_branch *branch,
+   struct dsc_mst_fairness_params *params,
+   struct dsc_mst_fairness_vars *vars, int count)
+{
+   struct drm_dp_mst_port *port;
+   int i;
+   int pbn_limit = 0;
+   int pbn_used = 0;
+
+   list_for_each_entry(port, >ports, next) {
+   if (port->mstb)
+   if (!check_pbn_limit_on_branch(port->mstb, params, 
vars, count))
+   return false;
+
+   if (port->available_pbn > 

[PATCH v2 04/14] Revert "drm/amd/display: Fix underscan not using proper scaling"

2019-08-20 Thread David Francis
This reverts commit 80e80ec817f161560b4159608fb41bd289abede3.

This commit fixed an issue with underscan commits not updating all
needed timing values, but through various refactors it is no longer
necessary. It causes corruption on odm combine by
overwriting the halved h_active in the stream timing

Signed-off-by: David Francis 
Reviewed-by: Roman Li 
Reviewed-by: Harry Wentland 
Reviewed-by: Nicholas Kazlauskas 
---
 drivers/gpu/drm/amd/display/dc/core/dc.c | 12 +---
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c 
b/drivers/gpu/drm/amd/display/dc/core/dc.c
index 77ac7f707ec5..1189e320062b 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc.c
@@ -2127,7 +2127,7 @@ void dc_commit_updates_for_stream(struct dc *dc,
enum surface_update_type update_type;
struct dc_state *context;
struct dc_context *dc_ctx = dc->ctx;
-   int i, j;
+   int i;
 
stream_status = dc_stream_get_status(stream);
context = dc->current_state;
@@ -2165,16 +2165,6 @@ void dc_commit_updates_for_stream(struct dc *dc,
 
copy_surface_update_to_plane(surface, _updates[i]);
 
-   if (update_type >= UPDATE_TYPE_MED) {
-   for (j = 0; j < dc->res_pool->pipe_count; j++) {
-   struct pipe_ctx *pipe_ctx = 
>res_ctx.pipe_ctx[j];
-
-   if (pipe_ctx->plane_state != surface)
-   continue;
-
-   resource_build_scaling_params(pipe_ctx);
-   }
-   }
}
 
copy_stream_update_to_stream(dc, context, stream, stream_update);
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v2 09/14] drm/dp-mst: Export symbols for dpcd read/write

2019-08-20 Thread David Francis
To use these functions in drm driver directories, they must be
exported

Signed-off-by: David Francis 
---
 drivers/gpu/drm/drm_dp_mst_topology.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c 
b/drivers/gpu/drm/drm_dp_mst_topology.c
index b40d975aec76..5d5bd42da17c 100644
--- a/drivers/gpu/drm/drm_dp_mst_topology.c
+++ b/drivers/gpu/drm/drm_dp_mst_topology.c
@@ -1512,6 +1512,7 @@ ssize_t drm_dp_mst_dpcd_read(struct drm_dp_aux *aux,
return drm_dp_send_dpcd_read(port->mgr, port,
 offset, size, buffer);
 }
+EXPORT_SYMBOL(drm_dp_mst_dpcd_read);
 
 /**
  * drm_dp_mst_dpcd_write() - write a series of bytes to the DPCD via sideband
@@ -1535,6 +1536,7 @@ ssize_t drm_dp_mst_dpcd_write(struct drm_dp_aux *aux,
return drm_dp_send_dpcd_write(port->mgr, port,
  offset, size, buffer);
 }
+EXPORT_SYMBOL(drm_dp_mst_dpcd_write);
 
 static void drm_dp_check_mstb_guid(struct drm_dp_mst_branch *mstb, u8 *guid)
 {
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v2 10/14] drm/dp-mst: Fill branch->num_ports

2019-08-20 Thread David Francis
This field on drm_dp_mst_branch was never filled

Initialize it to zero when the list of ports is created.
When a port is added to the list, increment num_ports

Signed-off-by: David Francis 
---
 drivers/gpu/drm/drm_dp_mst_topology.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c 
b/drivers/gpu/drm/drm_dp_mst_topology.c
index 5d5bd42da17c..0c580d5279c1 100644
--- a/drivers/gpu/drm/drm_dp_mst_topology.c
+++ b/drivers/gpu/drm/drm_dp_mst_topology.c
@@ -918,6 +918,7 @@ static struct drm_dp_mst_branch 
*drm_dp_add_mst_branch_device(u8 lct, u8 *rad)
INIT_LIST_HEAD(>ports);
kref_init(>topology_kref);
kref_init(>malloc_kref);
+   mstb->num_ports = 0;
return mstb;
 }
 
@@ -1672,6 +1673,7 @@ static void drm_dp_add_port(struct drm_dp_mst_branch 
*mstb,
mutex_lock(>mgr->lock);
drm_dp_mst_topology_get_port(port);
list_add(>next, >ports);
+   mstb->num_ports++;
mutex_unlock(>mgr->lock);
}
 
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v2 02/14] Revert "drm/amd/display: navi10 bring up skip dsc encoder config"

2019-08-20 Thread David Francis
This reverts commit 5f2fd347eeff7d4ce271920efd47baaa18fe968c.

Re-enable enc2_dp_set_dsc_config. This function caused warnings
due to missing register definitions. With the registers added,
this now works

Signed-off-by: David Francis 
Reviewed-by: Roman Li 
Reviewed-by: Harry Wentland 
Reviewed-by: Nicholas Kazlauskas 
---
 .../gpu/drm/amd/display/dc/dcn20/dcn20_stream_encoder.c   | 8 
 1 file changed, 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_stream_encoder.c 
b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_stream_encoder.c
index 6d54942ab98b..a4e67286cdad 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_stream_encoder.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_stream_encoder.c
@@ -277,14 +277,6 @@ static void enc2_dp_set_dsc_config(struct stream_encoder 
*enc,
uint32_t dsc_slice_width)
 {
struct dcn10_stream_encoder *enc1 = DCN10STRENC_FROM_STRENC(enc);
-   uint32_t dsc_value = 0;
-
-   dsc_value = REG_READ(DP_DSC_CNTL);
-
-   /* dsc disable skip */
-   if ((dsc_value & 0x3) == 0x0)
-   return;
-
 
REG_UPDATE_2(DP_DSC_CNTL,
DP_DSC_MODE, dsc_mode,
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v2 12/14] drm/amd/display: Write DSC enable to MST DPCD

2019-08-20 Thread David Francis
Rework the dm_helpers_write_dsc_enable callback to
handle the MST case

Depending on how DSC is done, the DP_DSC_ENABLE bit
needs to be set on a different point

For SST, use the link aux

For endpoint DSC over DP-to-DP peer devices,
use the output port

For peer device DSC over DP-to-DP peer devices,
use the upstream (peer) device

For DP-to-HDMI or virtual DP peer devices,
use the output port

For the Synaptix workaround, use the link aux

Cc: Wenjing Liu 
Cc: Nikola Cornij 
Signed-off-by: David Francis 
---
 .../amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 30 ++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
index dfa99e0d6e64..62731c2bf2bf 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
@@ -38,6 +38,7 @@
 #include "dc.h"
 #include "amdgpu_dm.h"
 #include "amdgpu_dm_irq.h"
+#include "amdgpu_dm_mst_types.h"
 
 #include "dm_helpers.h"
 
@@ -556,8 +557,35 @@ bool dm_helpers_dp_write_dsc_enable(
 )
 {
uint8_t enable_dsc = enable ? 1 : 0;
+   struct amdgpu_dm_connector *aconnector;
+
+   if (!stream)
+   return false;
+
+   if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
+   aconnector = (struct amdgpu_dm_connector 
*)stream->dm_stream_context;
+
+   if (!aconnector || !aconnector->dc_sink)
+   return false;
+
+   if (!aconnector->dc_sink->sink_dsc_caps.is_virtual_dpcd_dsc)
+   return drm_dp_mst_dpcd_write(>port->aux,
+   DP_DSC_ENABLE, _dsc, 
1) >= 0;
+   else if (is_virtual_dpcd(aconnector->port->parent->port_parent))
+   return 
drm_dp_mst_dpcd_write(>port->parent->port_parent->aux,
+   DP_DSC_ENABLE, _dsc, 
1) >= 0;
+   else if (is_virtual_dpcd(aconnector->port))
+   return drm_dp_mst_dpcd_write(>port->aux,
+   DP_DSC_ENABLE, _dsc, 
1) >= 0;
+   else if (synaptix_workaround(aconnector))
+   return dm_helpers_dp_write_dpcd(ctx, stream->link,
+   DP_DSC_ENABLE, _dsc, 1);
+   }
+
+   if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT)
+   return dm_helpers_dp_write_dpcd(ctx, stream->link, 
DP_DSC_ENABLE, _dsc, 1);
 
-   return dm_helpers_dp_write_dpcd(ctx, stream->sink->link, DP_DSC_ENABLE, 
_dsc, 1);
+   return false;
 }
 #endif
 
-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v2 00/14] Display Stream Compression (DSC) for AMD Navi

2019-08-20 Thread David Francis
This patchset enables Display Stream Compression (DSC) on DP
connectors on Navi ASICs, both SST and DSC.

8k60 and 4k144 support requires ODM combine, an AMD internal
feature that may be a bit buggy right now.

Patches 1 through 5 enable DSC for SST. Most of the work was
already done in the Navi promotion patches; this just hooks
it up to the atomic interface. The first two reverts are of temporary
changes to block off DSC. The third is of a commit that was
accidentally promoted twice. The fourth and last revert fixes a
potential issue with ODM combine.

Patches 6 and 7 are fixes for bugs that would be exposed by
MST DSC. One fix is with the MST code and the other in the DSC code.

Patches 8, 9, and 10 are small DRM changes required for DSC MST:
FEC, a new bit in the standard; some export definitions; and
a previously uninitialized variable.

Patches 11 through 14 are the DSC MST policy itself. This includes
the code for detecting and validating DSC capabilities, enabling
DSC over a link, computing the fair DSC configurations for
multiple DSC displays, and adding to atomic state crtcs that might
need reprogramming due to DSC.

v2: Updating patches 6 and 14 in respoinse to Nick's feedback

David Francis (14):
  Revert "drm/amd/display: skip dsc config for navi10 bring up"
  Revert "drm/amd/display: navi10 bring up skip dsc encoder config"
  Revert "drm/amd/display: add global master update lock for DCN2"
  Revert "drm/amd/display: Fix underscan not using proper scaling"
  drm/amd/display: Enable SST DSC in DM
  drm/dp-mst: Use dc and drm helpers to compute timeslots
  drm/amd/display: Initialize DSC PPS variables to 0
  drm/dp-mst: Parse FEC capability on MST ports
  drm/dp-mst: Export symbols for dpcd read/write
  drm/dp-mst: Fill branch->num_ports
  drm/amd/display: Validate DSC caps on MST endpoints
  drm/amd/display: Write DSC enable to MST DPCD
  drm/amd/display: MST DSC compute fair share
  drm/amd/display: Trigger modesets on MST DSC connectors

 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 110 +++-
 .../amd/display/amdgpu_dm/amdgpu_dm_helpers.c |  48 +-
 .../display/amdgpu_dm/amdgpu_dm_mst_types.c   | 498 +-
 .../display/amdgpu_dm/amdgpu_dm_mst_types.h   |   5 +
 drivers/gpu/drm/amd/display/dc/core/dc.c  |  12 +-
 .../drm/amd/display/dc/core/dc_link_hwss.c|   3 +
 .../gpu/drm/amd/display/dc/dcn20/dcn20_dsc.c  |   3 +
 .../drm/amd/display/dc/dcn20/dcn20_hwseq.c|   4 -
 .../gpu/drm/amd/display/dc/dcn20/dcn20_optc.c |  72 +--
 .../gpu/drm/amd/display/dc/dcn20/dcn20_optc.h |   3 -
 .../drm/amd/display/dc/dcn20/dcn20_resource.c |   7 +-
 .../drm/amd/display/dc/dcn20/dcn20_resource.h |   1 +
 .../display/dc/dcn20/dcn20_stream_encoder.c   |   8 -
 .../amd/display/dc/inc/hw/timing_generator.h  |   2 -
 drivers/gpu/drm/drm_dp_mst_topology.c |  47 ++
 include/drm/drm_dp_mst_helper.h   |   5 +-
 16 files changed, 708 insertions(+), 120 deletions(-)

-- 
2.17.1

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Re: [PATCH] backlight: add include guards to platform_lcd.h and ili9320.h

2019-08-20 Thread Daniel Thompson
On Sun, Jul 21, 2019 at 04:39:40PM +0900, Masahiro Yamada wrote:
> Add header include guards just in case.
> 
> Signed-off-by: Masahiro Yamada 

Reviewed-by: Daniel Thompson 

> ---
> 
>  include/video/ili9320.h  | 4 
>  include/video/platform_lcd.h | 4 
>  2 files changed, 8 insertions(+)
> 
> diff --git a/include/video/ili9320.h b/include/video/ili9320.h
> index 62f424f0bc52..b76a0b8f16fc 100644
> --- a/include/video/ili9320.h
> +++ b/include/video/ili9320.h
> @@ -9,6 +9,9 @@
>   * http://armlinux.simtec.co.uk/
>  */
>  
> +#ifndef _VIDEO_ILI9320_H
> +#define _VIDEO_ILI9320_H
> +
>  #define ILI9320_REG(x)   (x)
>  
>  #define ILI9320_INDEXILI9320_REG(0x00)
> @@ -196,3 +199,4 @@ struct ili9320_platdata {
>   unsigned short  interface6;
>  };
>  
> +#endif /* _VIDEO_ILI9320_H */
> diff --git a/include/video/platform_lcd.h b/include/video/platform_lcd.h
> index 6a95184a28c1..c68f3f45b5c1 100644
> --- a/include/video/platform_lcd.h
> +++ b/include/video/platform_lcd.h
> @@ -7,6 +7,9 @@
>   * Generic platform-device LCD power control interface.
>  */
>  
> +#ifndef _VIDEO_PLATFORM_LCD_H
> +#define _VIDEO_PLATFORM_LCD_H
> +
>  struct plat_lcd_data;
>  struct fb_info;
>  
> @@ -16,3 +19,4 @@ struct plat_lcd_data {
>   int (*match_fb)(struct plat_lcd_data *, struct fb_info *);
>  };
>  
> +#endif /* _VIDEO_PLATFORM_LCD_H */
> -- 
> 2.17.1


Re: [PATCH v13 00/18] kunit: introduce KUnit, the Linux kernel unit testing framework

2019-08-20 Thread shuah

On 8/20/19 12:24 PM, Brendan Higgins wrote:

On Tue, Aug 20, 2019 at 11:24:45AM -0600, shuah wrote:

On 8/13/19 11:50 PM, Brendan Higgins wrote:

## TL;DR

This revision addresses comments from Stephen and Bjorn Helgaas. Most
changes are pretty minor stuff that doesn't affect the API in anyway.
One significant change, however, is that I added support for freeing
kunit_resource managed resources before the test case is finished via
kunit_resource_destroy(). Additionally, Bjorn pointed out that I broke
KUnit on certain configurations (like the default one for x86, whoops).

Based on Stephen's feedback on the previous change, I think we are
pretty close. I am not expecting any significant changes from here on
out.



Hi Brendan,

I found checkpatch errors in one or two patches. Can you fix those and
send v14.


Hi Shuah,

Are you refering to the following errors?

ERROR: Macros with complex values should be enclosed in parentheses
#144: FILE: include/kunit/test.h:456:
+#define KUNIT_BINARY_CLASS \
+   kunit_binary_assert, KUNIT_INIT_BINARY_ASSERT_STRUCT

ERROR: Macros with complex values should be enclosed in parentheses
#146: FILE: include/kunit/test.h:458:
+#define KUNIT_BINARY_PTR_CLASS \
+   kunit_binary_ptr_assert, KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT

These values should *not* be in parentheses. I am guessing checkpatch is
getting confused and thinks that these are complex expressions, when
they are not.

I ignored the errors since I figured checkpatch was complaining
erroneously.

I could refactor the code to remove these macros entirely, but I think
the code is cleaner with them.



Please do. I am not veru sure what value these macros add.

thanks,
-- Shuah


[PATCH 7/7] drm/msm: Use per-target functions to set up address spaces

2019-08-20 Thread Jordan Crouse
Use a per-target function to set up the default address space for
each GPU. This allows a6xx targets to set up the correct address
range if split pagetables are enabled by the IOMMU device. This
also gets rid of a misplaced bit of a2xx code in msm_gpu
and returns it to where it belongs.

Signed-off-by: Jordan Crouse 
---

 drivers/gpu/drm/msm/adreno/a2xx_gpu.c   | 28 +
 drivers/gpu/drm/msm/adreno/a3xx_gpu.c   |  1 +
 drivers/gpu/drm/msm/adreno/a4xx_gpu.c   |  1 +
 drivers/gpu/drm/msm/adreno/a5xx_gpu.c   |  1 +
 drivers/gpu/drm/msm/adreno/a6xx_gpu.c   | 56 +
 drivers/gpu/drm/msm/adreno/adreno_gpu.c | 43 +
 drivers/gpu/drm/msm/adreno/adreno_gpu.h |  5 +++
 drivers/gpu/drm/msm/msm_gpu.c   | 56 ++---
 drivers/gpu/drm/msm/msm_gpu.h   |  4 +--
 9 files changed, 134 insertions(+), 61 deletions(-)

diff --git a/drivers/gpu/drm/msm/adreno/a2xx_gpu.c 
b/drivers/gpu/drm/msm/adreno/a2xx_gpu.c
index 1f83bc1..c9c032e 100644
--- a/drivers/gpu/drm/msm/adreno/a2xx_gpu.c
+++ b/drivers/gpu/drm/msm/adreno/a2xx_gpu.c
@@ -401,6 +401,33 @@ static struct msm_gpu_state *a2xx_gpu_state_get(struct 
msm_gpu *gpu)
return state;
 }
 
+static struct msm_gem_address_space *
+a2xx_create_address_space(struct msm_gpu *gpu, struct platform_device *pdev)
+{
+   struct msm_gem_address_space *aspace;
+   struct msm_mmu *mmu = msm_gpummu_new(>dev, gpu);
+   int ret;
+
+   if (IS_ERR(mmu))
+   return ERR_CAST(mmu);
+
+   ret = mmu->funcs->attach(mmu, NULL, 0);
+   if (ret) {
+   mmu->funcs->destroy(mmu);
+   return ERR_PTR(ret);
+   }
+
+   aspace = msm_gem_address_space_create(mmu, "gpu",
+   SZ_16M, SZ_16M + 0xfff * SZ_64K);
+
+   if (IS_ERR(aspace)) {
+   mmu->funcs->detach(mmu, NULL, 0);
+   mmu->funcs->destroy(mmu);
+   }
+
+   return aspace;
+}
+
 /* Register offset defines for A2XX - copy of A3XX */
 static const unsigned int a2xx_register_offsets[REG_ADRENO_REGISTER_MAX] = {
REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_BASE, REG_AXXX_CP_RB_BASE),
@@ -429,6 +456,7 @@ static const struct adreno_gpu_funcs funcs = {
 #endif
.gpu_state_get = a2xx_gpu_state_get,
.gpu_state_put = adreno_gpu_state_put,
+   .create_address_space = a2xx_create_address_space,
},
 };
 
diff --git a/drivers/gpu/drm/msm/adreno/a3xx_gpu.c 
b/drivers/gpu/drm/msm/adreno/a3xx_gpu.c
index 5f7e980..f24dc21 100644
--- a/drivers/gpu/drm/msm/adreno/a3xx_gpu.c
+++ b/drivers/gpu/drm/msm/adreno/a3xx_gpu.c
@@ -448,6 +448,7 @@ static const struct adreno_gpu_funcs funcs = {
 #endif
.gpu_state_get = a3xx_gpu_state_get,
.gpu_state_put = adreno_gpu_state_put,
+   .create_address_space = adreno_gpu_create_address_space,
},
 };
 
diff --git a/drivers/gpu/drm/msm/adreno/a4xx_gpu.c 
b/drivers/gpu/drm/msm/adreno/a4xx_gpu.c
index ab2b752..08f4292 100644
--- a/drivers/gpu/drm/msm/adreno/a4xx_gpu.c
+++ b/drivers/gpu/drm/msm/adreno/a4xx_gpu.c
@@ -538,6 +538,7 @@ static const struct adreno_gpu_funcs funcs = {
 #endif
.gpu_state_get = a4xx_gpu_state_get,
.gpu_state_put = adreno_gpu_state_put,
+   .create_address_space = adreno_gpu_create_address_space,
},
.get_timestamp = a4xx_get_timestamp,
 };
diff --git a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c 
b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c
index 1671db4..e29fea5 100644
--- a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c
+++ b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c
@@ -1385,6 +1385,7 @@ static const struct adreno_gpu_funcs funcs = {
.gpu_busy = a5xx_gpu_busy,
.gpu_state_get = a5xx_gpu_state_get,
.gpu_state_put = a5xx_gpu_state_put,
+   .create_address_space = adreno_gpu_create_address_space,
},
.get_timestamp = a5xx_get_timestamp,
 };
diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c 
b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c
index be39cf0..3092426 100644
--- a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c
+++ b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c
@@ -810,6 +810,61 @@ static unsigned long a6xx_gpu_busy(struct msm_gpu *gpu)
return (unsigned long)busy_time;
 }
 
+static struct msm_gem_address_space *
+a6xx_create_address_space(struct msm_gpu *gpu, struct platform_device *pdev)
+{
+   struct msm_gem_address_space *aspace;
+   struct iommu_domain *iommu;
+   struct msm_mmu *mmu;
+   int ret, val = 0;
+   u64 start, end;
+
+   iommu = iommu_domain_alloc(_bus_type);
+   if (!iommu)
+   return NULL;
+
+   mmu = msm_iommu_new(>dev, iommu);
+   if (IS_ERR(mmu)) {
+   iommu_domain_free(iommu);
+   return ERR_CAST(mmu);
+   }
+
+   ret = mmu->funcs->attach(mmu, NULL, 0);
+   if (ret) {
+   

  1   2   3   >