[drm-intel:drm-intel-next-queued 1/1] drivers/gpu/drm/i915/gvt/handlers.c:137:3: note: in expansion of macro 'if'

2016-10-18 Thread kbuild test robot
ine[i].mmio_base == reg)
28c4c6ca Zhi Wang 2016-05-01  138   return i;
28c4c6ca Zhi Wang 2016-05-01  139   }
28c4c6ca Zhi Wang 2016-05-01  140   return -1;

:: The code at line 137 was first introduced by commit
:: 28c4c6ca7f794b2d5ac8773d43311e95f6518415 drm/i915/gvt: vGPU workload 
submission

:: TO: Zhi Wang 
:: CC: Zhenyu Wang 

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation
-- next part --
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/gzip
Size: 24421 bytes
Desc: not available
URL: 
<https://lists.freedesktop.org/archives/dri-devel/attachments/20161018/baea959d/attachment-0001.gz>


mm: fix cache mode tracking in vm_insert_mixed() breaks AMDGPU [was: Re: Latest testing with drm-next-4.9-wip and latest LLVM/mesa stack - Regression in PowerPlay/DPM on CIK?]

2016-10-18 Thread Dave Airlie
On 18 October 2016 at 07:25, Dan Williams  wrote:
> On Sun, Oct 16, 2016 at 1:53 PM, Dave Airlie  wrote:
>> On 17 October 2016 at 04:41, Marek Olšák  wrote:
>>> On Fri, Oct 14, 2016 at 3:33 AM, Michel Dänzer  
>>> wrote:

 [ Adding Dan Williams and dri-devel ]

 On 14/10/16 03:28 AM, Shawn Starr wrote:
> Hello AMD folks,
>
> I have discovered a problem in Linus master that affects AMDGPU, nobody 
> would
> notice this in drm-next-4.9-wip since its not in this repo.

 [...]

> 87744ab3832b83ba71b931f86f9cfdb000d07da5 is the first bad commit
> commit 87744ab3832b83ba71b931f86f9cfdb000d07da5
> Author: Dan Williams 
> Date:   Fri Oct 7 17:00:18 2016 -0700
>
> mm: fix cache mode tracking in vm_insert_mixed()
>
> vm_insert_mixed() unlike vm_insert_pfn_prot() and 
> vmf_insert_pfn_pmd(),
> fails to check the pgprot_t it uses for the mapping against the one
> recorded in the memtype tracking tree.  Add the missing call to
> track_pfn_insert() to preclude cases where incompatible aliased 
> mappings
> are established for a given physical address range.
>
> Link: http://lkml.kernel.org/r/
> 147328717909.35069.14256589123570653697.stgit at dwillia2-
> desk3.amr.corp.intel.com
> Signed-off-by: Dan Williams 
> Cc: David Airlie 
> Cc: Matthew Wilcox 
> Cc: Ross Zwisler 
> Signed-off-by: Andrew Morton 
> Signed-off-by: Linus Torvalds 
>
> :04 04 7517c0019fe49c1830b5a1d81f1dc099c5aab98a
> fd497a604a2af5995db2b8ed1e9c640bede6adf3 M  mm
>
>
> Removal of this patch stops graphics stalls.

 Thanks for bisecting this Shawn.


> A friend of mine mentions,
>
> "looks like a graphics thingy you depend on is requesting a mapping with a
> not-allowed cache mode, and now you are (rightfully) getting errors?"

 It would be nice to get some more specific pointers what amdgpu (or
 maybe ttm, since that calls vm_insert_mixed in ttm_bo_vm_fault) might be
 doing wrong.
>>
>>/*
>>  * We'd like to use VM_PFNMAP on shared mappings, where
>>  * (vma->vm_flags & VM_SHARED) != 0, for performance reasons,
>>  * but for some reason VM_PFNMAP + x86 PAT + write-combine is very
>>  * bad for performance. Until that has been sorted out, use
>>  * VM_MIXEDMAP on all mappings. See freedesktop.org bug #75719
>>  */
>> vma->vm_flags |= VM_MIXEDMAP;
>>
>> We have that comment in the ttm code, which to me implies that mixed is
>> doing the right thing now, but that is slow, as the interface we
>> should be using.
>>
>
> Aren't there only 2 possibilities for this regression?
>
> 1/ a memtype entry was never made so track_pfn_insert() returns an
> uncached mapping
>
> 2/ a conflicting memtype entry exists and undefined behavior due to
> mixed mapping types is avoided with the change.

3/ The CPU usage through this path goes up, and slows things down,
though I suspect you it's more an uncached mapping showing up
when we don't expect it.

Dave.


[PATCH 00/28] Reenable maybe-uninitialized warnings

2016-10-18 Thread Arnd Bergmann
This is a set of patches that I hope to get into v4.9 in some form
in order to turn on the -Wmaybe-uninitialized warnings again.

After talking to Linus in person at Linaro Connect about this, I
spent some time on finding all the remaining warnings, and this
is the resulting patch series. More details are in the description
of the last patch that actually enables the warning.

Let me know if there are other warnings that I missed, and whether
you think these are still appropriate for v4.9 or not.
A couple of patches are non-obvious, and could use some more
detailed review.

Arnd

Arnd Bergmann (28):
  [v2] netfilter: nf_tables: avoid uninitialized variable warning
  [v2] mtd: mtk: avoid warning in mtk_ecc_encode
  [v2] infiniband: shut up a maybe-uninitialized warning
  f2fs: replace a build-time warning with runtime WARN_ON
  ext2: avoid bogus -Wmaybe-uninitialized warning
  NFSv4.1: work around -Wmaybe-uninitialized warning
  ceph: avoid false positive maybe-uninitialized warning
  staging: lustre: restore initialization of return code
  staging: lustre: remove broken dead code in
cfs_cpt_table_create_pattern
  UBI: fix uninitialized access of vid_hdr pointer
  block: rdb: false-postive gcc-4.9 -Wmaybe-uninitialized
  [media] rc: print correct variable for z8f0811
  [media] dib0700: fix uninitialized data on 'repeat' event
  iio: accel: sca3000_core: avoid potentially uninitialized variable
  crypto: aesni: avoid -Wmaybe-uninitialized warning
  pcmcia: fix return value of soc_pcmcia_regulator_set
  spi: fsl-espi: avoid processing uninitalized data on error
  drm: avoid uninitialized timestamp use in wait_vblank
  brcmfmac: avoid maybe-uninitialized warning in brcmf_cfg80211_start_ap
  net: bcm63xx: avoid referencing uninitialized variable
  net/hyperv: avoid uninitialized variable
  x86: apm: avoid uninitialized data
  x86: mark target address as output in 'insb' asm
  x86: math-emu: possible uninitialized variable use
  s390: pci: don't print uninitialized data for debugging
  nios2: fix timer initcall return value
  rocker: fix maybe-uninitialized warning
  Kbuild: bring back -Wmaybe-uninitialized warning

 Makefile   |  10 +-
 arch/arc/Makefile  |   4 +-
 arch/nios2/kernel/time.c   |   1 +
 arch/s390/pci/pci_dma.c|   2 +-
 arch/x86/crypto/aesni-intel_glue.c | 121 +
 arch/x86/include/asm/io.h  |   4 +-
 arch/x86/kernel/apm_32.c   |   5 +-
 arch/x86/math-emu/Makefile |   4 +-
 arch/x86/math-emu/reg_compare.c|  16 +--
 drivers/block/rbd.c|   1 +
 drivers/gpu/drm/drm_irq.c  |   4 +-
 drivers/infiniband/core/cma.c  |  56 +-
 drivers/media/i2c/ir-kbd-i2c.c |   2 +-
 drivers/media/usb/dvb-usb/dib0700_core.c   |  10 +-
 drivers/mtd/nand/mtk_ecc.c |  19 ++--
 drivers/mtd/ubi/eba.c  |   2 +-
 drivers/net/ethernet/broadcom/bcm63xx_enet.c   |   3 +-
 drivers/net/ethernet/rocker/rocker_ofdpa.c |   4 +-
 drivers/net/hyperv/netvsc_drv.c|   2 +-
 .../broadcom/brcm80211/brcmfmac/cfg80211.c |   2 +-
 drivers/pcmcia/soc_common.c|   2 +-
 drivers/spi/spi-fsl-espi.c |   2 +-
 drivers/staging/iio/accel/sca3000_core.c   |   2 +
 .../staging/lustre/lnet/libcfs/linux/linux-cpu.c   |   7 --
 drivers/staging/lustre/lustre/lov/lov_pack.c   |   2 +
 fs/ceph/super.c|   3 +-
 fs/ext2/inode.c|   7 +-
 fs/f2fs/data.c |   7 ++
 fs/nfs/nfs4session.c   |  10 +-
 net/netfilter/nft_range.c  |  10 +-
 scripts/Makefile.ubsan |   4 +
 31 files changed, 187 insertions(+), 141 deletions(-)

-- 
Cc: x86 at kernel.org
Cc: linux-media at vger.kernel.org
Cc: Mauro Carvalho Chehab 
Cc: Martin Schwidefsky 
Cc: linux-s390 at vger.kernel.org
Cc: Ilya Dryomov 
Cc: dri-devel at lists.freedesktop.org
Cc: linux-mtd at lists.infradead.org
Cc: Herbert Xu 
Cc: linux-crypto at vger.kernel.org
Cc: "David S. Miller" 
Cc: netdev at vger.kernel.org
Cc: Greg Kroah-Hartman 
Cc: ceph-devel at vger.kernel.org
Cc: linux-f2fs-devel at lists.sourceforge.net
Cc: linux-ext4 at vger.kernel.org
Cc: netfilter-devel at vger.kernel.org
2.9.0



[PATCH 18/28] drm: avoid uninitialized timestamp use in wait_vblank

2016-10-18 Thread Arnd Bergmann
gcc warns about the timestamp in drm_wait_vblank being possibly
used without an initialization:

drivers/gpu/drm/drm_irq.c: In function 'drm_crtc_send_vblank_event':
drivers/gpu/drm/drm_irq.c:992:24: error: 'now.tv_usec' may be used 
uninitialized in this function [-Werror=maybe-uninitialized]
drivers/gpu/drm/drm_irq.c:1069:17: note: 'now.tv_usec' was declared here
drivers/gpu/drm/drm_irq.c:991:23: error: 'now.tv_sec' may be used uninitialized 
in this function [-Werror=maybe-uninitialized]

This can happen if drm_vblank_count_and_time() returns 0 in its
error path. To sanitize the error case, I'm changing that function
to return a zero timestamp when it fails.

Fixes: e6ae8687a87b ("drm: idiot-proof vblank")
Reviewed-by: David Herrmann 
Cc: Rob Clark 
Cc: Daniel Vetter 
Signed-off-by: Arnd Bergmann 
---
First submitted in January 2016, second submission in February,
the patch is still required.

 drivers/gpu/drm/drm_irq.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index b969a64..48a6167 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -952,8 +952,10 @@ static u32 drm_vblank_count_and_time(struct drm_device 
*dev, unsigned int pipe,
u32 vblank_count;
unsigned int seq;

-   if (WARN_ON(pipe >= dev->num_crtcs))
+   if (WARN_ON(pipe >= dev->num_crtcs)) {
+   *vblanktime = (struct timeval) { 0 };
return 0;
+   }

do {
seq = read_seqbegin(&vblank->seqlock);
-- 
2.9.0



[PATCH 12/15] drm: RIP mode_config->rotation_property

2016-10-18 Thread Laurent Pinchart
Hi Ville,

On Friday 22 Jul 2016 16:43:13 ville.syrjala at linux.intel.com wrote:
> From: Ville Syrjälä 
> 
> Now that all drivers have been converted over to the per-plane rotation
> property, we can just nuke the global rotation property.
> 
> Signed-off-by: Ville Syrjälä 

Stupid question, but how does this work when the hardware supports global 
rotation only, not per-plane rotation ?

> ---
>  drivers/gpu/drm/drm_atomic.c|  6 ++
>  drivers/gpu/drm/drm_crtc.c  | 18 --
>  drivers/gpu/drm/drm_fb_helper.c |  7 +--
>  include/drm/drm_crtc.h  |  7 ---
>  4 files changed, 3 insertions(+), 35 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index 116f940a9267..81061fcdb984 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -709,8 +709,7 @@ int drm_atomic_plane_set_property(struct drm_plane
> *plane, state->src_w = val;
>   } else if (property == config->prop_src_h) {
>   state->src_h = val;
> - } else if (property == config->rotation_property ||
> -property == plane->rotation_property) {
> + } else if (property == plane->rotation_property) {
>   if (!is_power_of_2(val & DRM_ROTATE_MASK))
>   return -EINVAL;
>   state->rotation = val;
> @@ -768,8 +767,7 @@ drm_atomic_plane_get_property(struct drm_plane *plane,
>   *val = state->src_w;
>   } else if (property == config->prop_src_h) {
>   *val = state->src_h;
> - } else if (property == config->rotation_property ||
> -property == plane->rotation_property) {
> + } else if (property == plane->rotation_property) {
>   *val = state->rotation;
>   } else if (plane->funcs->atomic_get_property) {
>   return plane->funcs->atomic_get_property(plane, state, 
property, val);
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index 9e20a52ece7c..c1df75caf72f 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -5783,24 +5783,6 @@ void drm_mode_config_cleanup(struct drm_device *dev)
>  }
>  EXPORT_SYMBOL(drm_mode_config_cleanup);
> 
> -struct drm_property *drm_mode_create_rotation_property(struct drm_device
> *dev, -  unsigned int 
supported_rotations)
> -{
> - static const struct drm_prop_enum_list props[] = {
> - { DRM_ROTATE_0,   "rotate-0" },
> - { DRM_ROTATE_90,  "rotate-90" },
> - { DRM_ROTATE_180, "rotate-180" },
> - { DRM_ROTATE_270, "rotate-270" },
> - { DRM_REFLECT_X,  "reflect-x" },
> - { DRM_REFLECT_Y,  "reflect-y" },
> - };
> -
> - return drm_property_create_bitmask(dev, 0, "rotation",
> -props, ARRAY_SIZE(props),
> -supported_rotations);
> -}
> -EXPORT_SYMBOL(drm_mode_create_rotation_property);
> -
>  int drm_plane_create_rotation_property(struct drm_plane *plane,
>  unsigned int rotation,
>  unsigned int supported_rotations)
> diff --git a/drivers/gpu/drm/drm_fb_helper.c
> b/drivers/gpu/drm/drm_fb_helper.c index ce536c0553e5..cf5f071ffae1 100644
> --- a/drivers/gpu/drm/drm_fb_helper.c
> +++ b/drivers/gpu/drm/drm_fb_helper.c
> @@ -392,15 +392,10 @@ static int restore_fbdev_mode(struct drm_fb_helper
> *fb_helper) if (plane->type != DRM_PLANE_TYPE_PRIMARY)
>   drm_plane_force_disable(plane);
> 
> - if (plane->rotation_property) {
> + if (plane->rotation_property)
>   drm_mode_plane_set_obj_prop(plane,
>   plane->rotation_property,
>   BIT(DRM_ROTATE_0));
> - } else if (dev->mode_config.rotation_property) {
> - drm_mode_plane_set_obj_prop(plane,
> - dev-
>mode_config.rotation_property,
> - BIT(DRM_ROTATE_0));
> - }
>   }
> 
>   for (i = 0; i < fb_helper->crtc_count; i++) {
> diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
> index 01cf0673f6c8..00a93e44f854 100644
> --- a/include/drm/drm_crtc.h
> +++ b/include/drm/drm_crtc.h
> @@ -2480,11 +2480,6 @@ struct drm_mode_config {
>*/
>   struct drm_property *plane_type_property;
>   /**
> -  * @rotation_property: Optional property for planes or CRTCs to 
specify
> -  * rotation.
> -  */
> - struct drm_property *rotation_property;
> - /**
>* @prop_src_x: Default atomic plane property for the plane source
>* position in the connected &drm_framebuffer.
>*/
> @@ -2960,8 +2955,6 @@ extern int drm_mode_plane_set_obj_prop(struct
> drm_pl

[PATCH v5 00/13] Centralize format information

2016-10-18 Thread Laurent Pinchart
Hello,

Various pieces of information about DRM formats (number of planes, color
depth, chroma subsampling, ...) are scattered across different helper
functions in the DRM core. Callers of those functions often need to access
more than a single parameter of the format, leading to inefficiencies due to
multiple lookups.

This patch series addresses this issue by centralizing all format information
in a single data structure (01/13). It reimplements the existing format helper
functions based on that structure (02/13) and converts the DRM core code to
use the new structure (03/13). The DRM core now WARNs when a driver tries to
query information about an unsupported format (04/13).

The second part of the patch series removes the drm_fb_get_bpp_depth() legacy
function that shouldn't be used directly by drivers. It modifies all its users
to use the appropriate API instead (05/13 to 12/13) and finally merges the
function into its only caller in the DRM core (13/13).

The new API is also useful for drivers as shown by the "[PATCH v2 00/20] OMAP
DRM fixes and improvements" patch series previously posted.

All patches have been acked, the series is ready to be merged for v4.10.

Changes since v4:

- Rebased on top of latest drm/master branch
- Collected acks
- Fixed depth value of DRM_FORMAT_[AXRGB]{4} formats to match current code
- Added support for DRM_FORMAT_BGR565, DRM_FORMAT_XBGR and
  DRM_FORMAT_BGR888 to tilcdc
- Documented the depth field as legacy

Changes since v3:

- Rebased on top of latest drm/master branch
- Collected acks
- Dropped "drm: Move format-related helpers to drm_fourcc.c" and
  "drm/msm: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()" that
  have been merged already
- Added new "drm/arm: mali-dp: Replace drm_fb_get_bpp_depth() with
  drm_format_plane_cpp()" patch
- Coding style fixes and variable renames

Changes since v2:

- Remove bpp field from drm_format_info structure
- Replace all users of drm_fb_get_bpp_depth() with the appropriate API
- Merge drm_fb_get_bpp_depth() into its only caller

Changes since v1:

- Move format-related helpers to drm_fourcc.c
- Use named initializers for the formats array
- WARN when calling drm_format_info() for an unsupported format
- Don't drop the drm_format_plane_width() and drm_format_plane_height()
  helpers

Laurent Pinchart (13):
  drm: Centralize format information
  drm: Implement the drm_format_*() helpers as drm_format_info()
wrappers
  drm: Use drm_format_info() in DRM core code
  drm: WARN when calling drm_format_info() for an unsupported format
  drm: hdlcd: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  drm: tilcdc: Replace drm_fb_get_bpp_depth() with
drm_format_plane_cpp()
  drm: cirrus: Replace drm_fb_get_bpp_depth() with
drm_format_plane_cpp()
  drm: gma500: Replace drm_fb_get_bpp_depth() with drm_format_info()
  drm: amdgpu: Replace drm_fb_get_bpp_depth() with
drm_format_plane_cpp()
  drm: radeon: Replace drm_fb_get_bpp_depth() with
drm_format_plane_cpp()
  drm: vmwgfx: Replace drm_fb_get_bpp_depth() with drm_format_info()
  drm/arm: mali-dp: Replace drm_fb_get_bpp_depth() with
drm_format_plane_cpp()
  drm: Don't export the drm_fb_get_bpp_depth() function

 Documentation/gpu/drm-kms.rst   |   3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c  |  14 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c |   3 +-
 drivers/gpu/drm/arm/hdlcd_crtc.c|   5 +-
 drivers/gpu/drm/arm/malidp_hw.c |   7 +-
 drivers/gpu/drm/cirrus/cirrus_fbdev.c   |   6 +-
 drivers/gpu/drm/cirrus/cirrus_main.c|   4 +-
 drivers/gpu/drm/drm_fb_cma_helper.c |  23 +--
 drivers/gpu/drm/drm_fourcc.c| 281 ++--
 drivers/gpu/drm/drm_framebuffer.c   | 102 ++--
 drivers/gpu/drm/drm_modeset_helper.c|  17 +-
 drivers/gpu/drm/gma500/framebuffer.c|  20 +--
 drivers/gpu/drm/radeon/radeon_fb.c  |  20 +--
 drivers/gpu/drm/radeon/radeon_gem.c |   3 +-
 drivers/gpu/drm/tilcdc/tilcdc_crtc.c|  18 +-
 drivers/gpu/drm/tilcdc/tilcdc_plane.c   |   7 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c |  12 +-
 include/drm/drm_fourcc.h|  23 ++-
 18 files changed, 244 insertions(+), 324 deletions(-)

-- 
Regards,

Laurent Pinchart



[PATCH v5 05/13] drm: hdlcd: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()

2016-10-18 Thread Laurent Pinchart
The driver needs the number of bytes per pixel, not the bpp and depth
info meant for fbdev compatibility. Use the right API.

Signed-off-by: Laurent Pinchart 
Acked-by: Liviu Dudau 
---
 drivers/gpu/drm/arm/hdlcd_crtc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/arm/hdlcd_crtc.c b/drivers/gpu/drm/arm/hdlcd_crtc.c
index 48019ae22ddb..bbaa55add2d2 100644
--- a/drivers/gpu/drm/arm/hdlcd_crtc.c
+++ b/drivers/gpu/drm/arm/hdlcd_crtc.c
@@ -223,14 +223,12 @@ static void hdlcd_plane_atomic_update(struct drm_plane 
*plane,
 {
struct hdlcd_drm_private *hdlcd;
struct drm_gem_cma_object *gem;
-   unsigned int depth, bpp;
u32 src_w, src_h, dest_w, dest_h;
dma_addr_t scanout_start;

if (!plane->state->fb)
return;

-   drm_fb_get_bpp_depth(plane->state->fb->pixel_format, &depth, &bpp);
src_w = plane->state->src_w >> 16;
src_h = plane->state->src_h >> 16;
dest_w = plane->state->crtc_w;
@@ -238,7 +236,8 @@ static void hdlcd_plane_atomic_update(struct drm_plane 
*plane,
gem = drm_fb_cma_get_gem_obj(plane->state->fb, 0);
scanout_start = gem->paddr + plane->state->fb->offsets[0] +
plane->state->crtc_y * plane->state->fb->pitches[0] +
-   plane->state->crtc_x * bpp / 8;
+   plane->state->crtc_x *
+   drm_format_plane_cpp(plane->state->fb->pixel_format, 0);

hdlcd = plane->dev->dev_private;
hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_LENGTH, 
plane->state->fb->pitches[0]);
-- 
Regards,

Laurent Pinchart



[PATCH v5 08/13] drm: gma500: Replace drm_fb_get_bpp_depth() with drm_format_info()

2016-10-18 Thread Laurent Pinchart
The driver uses drm_fb_get_bpp_depth() to check whether it can support
the format requested by userspace when creating a framebuffer. This
isn't the right API, as it doesn't differentiate between RGB formats
other than on a depth and bpp basis.

Fixing this requires non trivial changes to the drivers internals. As a
first step, replace usage of the drm_fb_get_bpp_depth() function with an
equivalent check based on drm_format_info(). This is part of a wider
effort to remove usage of the drm_fb_get_bpp_depth() function in
drivers.

Signed-off-by: Laurent Pinchart 
Reviewed-by: Daniel Vetter 
---
 drivers/gpu/drm/gma500/framebuffer.c | 20 +---
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/gma500/framebuffer.c 
b/drivers/gpu/drm/gma500/framebuffer.c
index 3a44e705db53..6cb92cc0bef8 100644
--- a/drivers/gpu/drm/gma500/framebuffer.c
+++ b/drivers/gpu/drm/gma500/framebuffer.c
@@ -236,22 +236,20 @@ static int psb_framebuffer_init(struct drm_device *dev,
const struct drm_mode_fb_cmd2 *mode_cmd,
struct gtt_range *gt)
 {
-   u32 bpp, depth;
+   const struct drm_format_info *info;
int ret;

-   drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp);
+   /*
+* Reject unknown formats, YUV formats, and formats with more than
+* 4 bytes per pixel.
+*/
+   info = drm_format_info(mode_cmd->pixel_format);
+   if (!info || !info->depth || info->cpp[0] > 4)
+   return -EINVAL;

if (mode_cmd->pitches[0] & 63)
return -EINVAL;
-   switch (bpp) {
-   case 8:
-   case 16:
-   case 24:
-   case 32:
-   break;
-   default:
-   return -EINVAL;
-   }
+
drm_helper_mode_fill_fb_struct(&fb->base, mode_cmd);
fb->gtt = gt;
ret = drm_framebuffer_init(dev, &fb->base, &psb_fb_funcs);
-- 
Regards,

Laurent Pinchart



[PATCH v5 01/13] drm: Centralize format information

2016-10-18 Thread Laurent Pinchart
Various pieces of information about DRM formats (number of planes, color
depth, chroma subsampling, ...) are scattered across different helper
functions in the DRM core. Callers of those functions often need to
access more than a single parameter of the format, leading to
inefficiencies due to multiple lookups.

Centralize all format information in a data structure and create a
function to look up information based on the format 4CC.

Signed-off-by: Laurent Pinchart 
Reviewed-by: Daniel Vetter 
Reviewed-by: Eric Engestrom 
---
Changes since v4:

- Fixed depth value of DRM_FORMAT_[AXRGB]{4} formats to match
  current code
- Documented the depth field as legacy
---
 Documentation/gpu/drm-kms.rst |  3 ++
 drivers/gpu/drm/drm_fourcc.c  | 84 +++
 include/drm/drm_fourcc.h  | 21 +++
 3 files changed, 108 insertions(+)

diff --git a/Documentation/gpu/drm-kms.rst b/Documentation/gpu/drm-kms.rst
index 53b872c105d2..cb0d3537b705 100644
--- a/Documentation/gpu/drm-kms.rst
+++ b/Documentation/gpu/drm-kms.rst
@@ -63,6 +63,9 @@ Frame Buffer Functions Reference
 DRM Format Handling
 ===

+.. kernel-doc:: include/drm/drm_fourcc.h
+   :internal:
+
 .. kernel-doc:: drivers/gpu/drm/drm_fourcc.c
:export:

diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index 29c56b4331e0..39f09c564111 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -103,6 +103,90 @@ char *drm_get_format_name(uint32_t format)
 EXPORT_SYMBOL(drm_get_format_name);

 /**
+ * drm_format_info - query information for a given format
+ * @format: pixel format (DRM_FORMAT_*)
+ *
+ * Returns:
+ * The instance of struct drm_format_info that describes the pixel format, or
+ * NULL if the format is unsupported.
+ */
+const struct drm_format_info *drm_format_info(u32 format)
+{
+   static const struct drm_format_info formats[] = {
+   { .format = DRM_FORMAT_C8,  .depth = 8,  
.num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_RGB332,  .depth = 8,  
.num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_BGR233,  .depth = 8,  
.num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_XRGB,.depth = 0,  
.num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_XBGR,.depth = 0,  
.num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_RGBX,.depth = 0,  
.num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_BGRX,.depth = 0,  
.num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_ARGB,.depth = 0,  
.num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_ABGR,.depth = 0,  
.num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_RGBA,.depth = 0,  
.num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_BGRA,.depth = 0,  
.num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_XRGB1555,.depth = 15, 
.num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_XBGR1555,.depth = 15, 
.num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_RGBX5551,.depth = 15, 
.num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_BGRX5551,.depth = 15, 
.num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_ARGB1555,.depth = 15, 
.num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_ABGR1555,.depth = 15, 
.num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_RGBA5551,.depth = 15, 
.num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_BGRA5551,.depth = 15, 
.num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_RGB565,  .depth = 16, 
.num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_BGR565,  .depth = 16, 
.num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_RGB888,  .depth = 24, 
.num_planes = 1, .cpp = { 3, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_BGR888,  .depth = 24, 
.num_planes = 1, .cpp = { 3, 0, 0 }, .hsub = 1, .vsub = 1 },
+   { .format = DRM_FORMAT_XRGB,

[PATCH v5 02/13] drm: Implement the drm_format_*() helpers as drm_format_info() wrappers

2016-10-18 Thread Laurent Pinchart
Turn the drm_format_*() helpers into wrappers around the drm_format_info
lookup function to centralize all format information in a single place.

Signed-off-by: Laurent Pinchart 
Reviewed-by: Tomi Valkeinen 
Reviewed-by: Daniel Vetter 
Reviewed-by: Eric Engestrom 
---
 drivers/gpu/drm/drm_fourcc.c | 186 +--
 1 file changed, 37 insertions(+), 149 deletions(-)

diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index 39f09c564111..23d4b82ec17c 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -198,69 +198,22 @@ EXPORT_SYMBOL(drm_format_info);
 void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
  int *bpp)
 {
-   char *format_name;
-
-   switch (format) {
-   case DRM_FORMAT_C8:
-   case DRM_FORMAT_RGB332:
-   case DRM_FORMAT_BGR233:
-   *depth = 8;
-   *bpp = 8;
-   break;
-   case DRM_FORMAT_XRGB1555:
-   case DRM_FORMAT_XBGR1555:
-   case DRM_FORMAT_RGBX5551:
-   case DRM_FORMAT_BGRX5551:
-   case DRM_FORMAT_ARGB1555:
-   case DRM_FORMAT_ABGR1555:
-   case DRM_FORMAT_RGBA5551:
-   case DRM_FORMAT_BGRA5551:
-   *depth = 15;
-   *bpp = 16;
-   break;
-   case DRM_FORMAT_RGB565:
-   case DRM_FORMAT_BGR565:
-   *depth = 16;
-   *bpp = 16;
-   break;
-   case DRM_FORMAT_RGB888:
-   case DRM_FORMAT_BGR888:
-   *depth = 24;
-   *bpp = 24;
-   break;
-   case DRM_FORMAT_XRGB:
-   case DRM_FORMAT_XBGR:
-   case DRM_FORMAT_RGBX:
-   case DRM_FORMAT_BGRX:
-   *depth = 24;
-   *bpp = 32;
-   break;
-   case DRM_FORMAT_XRGB2101010:
-   case DRM_FORMAT_XBGR2101010:
-   case DRM_FORMAT_RGBX1010102:
-   case DRM_FORMAT_BGRX1010102:
-   case DRM_FORMAT_ARGB2101010:
-   case DRM_FORMAT_ABGR2101010:
-   case DRM_FORMAT_RGBA1010102:
-   case DRM_FORMAT_BGRA1010102:
-   *depth = 30;
-   *bpp = 32;
-   break;
-   case DRM_FORMAT_ARGB:
-   case DRM_FORMAT_ABGR:
-   case DRM_FORMAT_RGBA:
-   case DRM_FORMAT_BGRA:
-   *depth = 32;
-   *bpp = 32;
-   break;
-   default:
-   format_name = drm_get_format_name(format);
+   const struct drm_format_info *info;
+
+   info = drm_format_info(format);
+   if (!info || !info->depth) {
+   char *format_name = drm_get_format_name(format);
+
DRM_DEBUG_KMS("unsupported pixel format %s\n", format_name);
kfree(format_name);
+
*depth = 0;
*bpp = 0;
-   break;
+   return;
}
+
+   *depth = info->depth;
+   *bpp = info->cpp[0] * 8;
 }
 EXPORT_SYMBOL(drm_fb_get_bpp_depth);

@@ -273,28 +226,10 @@ EXPORT_SYMBOL(drm_fb_get_bpp_depth);
  */
 int drm_format_num_planes(uint32_t format)
 {
-   switch (format) {
-   case DRM_FORMAT_YUV410:
-   case DRM_FORMAT_YVU410:
-   case DRM_FORMAT_YUV411:
-   case DRM_FORMAT_YVU411:
-   case DRM_FORMAT_YUV420:
-   case DRM_FORMAT_YVU420:
-   case DRM_FORMAT_YUV422:
-   case DRM_FORMAT_YVU422:
-   case DRM_FORMAT_YUV444:
-   case DRM_FORMAT_YVU444:
-   return 3;
-   case DRM_FORMAT_NV12:
-   case DRM_FORMAT_NV21:
-   case DRM_FORMAT_NV16:
-   case DRM_FORMAT_NV61:
-   case DRM_FORMAT_NV24:
-   case DRM_FORMAT_NV42:
-   return 2;
-   default:
-   return 1;
-   }
+   const struct drm_format_info *info;
+
+   info = drm_format_info(format);
+   return info ? info->num_planes : 1;
 }
 EXPORT_SYMBOL(drm_format_num_planes);

@@ -308,40 +243,13 @@ EXPORT_SYMBOL(drm_format_num_planes);
  */
 int drm_format_plane_cpp(uint32_t format, int plane)
 {
-   unsigned int depth;
-   int bpp;
+   const struct drm_format_info *info;

-   if (plane >= drm_format_num_planes(format))
+   info = drm_format_info(format);
+   if (!info || plane >= info->num_planes)
return 0;

-   switch (format) {
-   case DRM_FORMAT_YUYV:
-   case DRM_FORMAT_YVYU:
-   case DRM_FORMAT_UYVY:
-   case DRM_FORMAT_VYUY:
-   return 2;
-   case DRM_FORMAT_NV12:
-   case DRM_FORMAT_NV21:
-   case DRM_FORMAT_NV16:
-   case DRM_FORMAT_NV61:
-   case DRM_FORMAT_NV24:
-   case DRM_FORMAT_NV42:
-   return plane ? 2 : 1;
-   case DRM_FORMAT_YUV410:
-   case DRM_FORMAT_YVU410:
-   case DRM_FORMAT_YUV411:
-   case DRM_FORMAT_YVU411:
-   case DRM_FORMAT_YUV420:
-   case DRM_FORMAT_YVU420:
-   case DRM_FORMAT_YUV422:
-   case DRM_FORMAT_YVU422:
-   case DRM_FORMAT_YUV444:
-   case DRM_FO

[PATCH v5 09/13] drm: amdgpu: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()

2016-10-18 Thread Laurent Pinchart
The driver needs the number of bytes per pixel, not the bpp and depth
info meant for fbdev compatibility. Use the right API.

Signed-off-by: Laurent Pinchart 
Reviewed-by: Daniel Vetter 
---
Changes since v4:

- Added Daniel Vetter's Reviewed-by received off-line

Changes since v3:

- Renamed bpp to cpp
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c  | 14 +++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c |  3 ++-
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
index 9fb8aa4d6bae..8d01aa24d68a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
@@ -90,12 +90,12 @@ static struct fb_ops amdgpufb_ops = {
 };


-int amdgpu_align_pitch(struct amdgpu_device *adev, int width, int bpp, bool 
tiled)
+int amdgpu_align_pitch(struct amdgpu_device *adev, int width, int cpp, bool 
tiled)
 {
int aligned = width;
int pitch_mask = 0;

-   switch (bpp / 8) {
+   switch (cpp) {
case 1:
pitch_mask = 255;
break;
@@ -110,7 +110,7 @@ int amdgpu_align_pitch(struct amdgpu_device *adev, int 
width, int bpp, bool tile

aligned += pitch_mask;
aligned &= ~pitch_mask;
-   return aligned;
+   return aligned * cpp;
 }

 static void amdgpufb_destroy_pinned_object(struct drm_gem_object *gobj)
@@ -139,13 +139,13 @@ static int amdgpufb_create_pinned_object(struct 
amdgpu_fbdev *rfbdev,
int ret;
int aligned_size, size;
int height = mode_cmd->height;
-   u32 bpp, depth;
+   u32 cpp;

-   drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp);
+   cpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0);

/* need to align pitch with crtc limits */
-   mode_cmd->pitches[0] = amdgpu_align_pitch(adev, mode_cmd->width, bpp,
- fb_tiled) * ((bpp + 1) / 8);
+   mode_cmd->pitches[0] = amdgpu_align_pitch(adev, mode_cmd->width, cpp,
+ fb_tiled);

height = ALIGN(mode_cmd->height, 8);
size = mode_cmd->pitches[0] * height;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index a7ea9a3b454e..63d89f38d680 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -704,7 +704,8 @@ int amdgpu_mode_dumb_create(struct drm_file *file_priv,
uint32_t handle;
int r;

-   args->pitch = amdgpu_align_pitch(adev, args->width, args->bpp, 0) * 
((args->bpp + 1) / 8);
+   args->pitch = amdgpu_align_pitch(adev, args->width,
+DIV_ROUND_UP(args->bpp, 8), 0);
args->size = (u64)args->pitch * args->height;
args->size = ALIGN(args->size, PAGE_SIZE);

-- 
Regards,

Laurent Pinchart



[PATCH v5 10/13] drm: radeon: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()

2016-10-18 Thread Laurent Pinchart
The driver needs the number of bytes per pixel, not the bpp and depth
info meant for fbdev compatibility. Use the right API.

Signed-off-by: Laurent Pinchart 
Reviewed-by: Daniel Vetter 
---
Changes since v4:

- Added Daniel Vetter's Reviewed-by received off-line

Changes since v3:

- Renamed bpp to cpp
---
 drivers/gpu/drm/radeon/radeon_fb.c  | 20 ++--
 drivers/gpu/drm/radeon/radeon_gem.c |  3 ++-
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_fb.c 
b/drivers/gpu/drm/radeon/radeon_fb.c
index 0daad446d2c7..f65f29911dca 100644
--- a/drivers/gpu/drm/radeon/radeon_fb.c
+++ b/drivers/gpu/drm/radeon/radeon_fb.c
@@ -89,13 +89,13 @@ static struct fb_ops radeonfb_ops = {
 };


-int radeon_align_pitch(struct radeon_device *rdev, int width, int bpp, bool 
tiled)
+int radeon_align_pitch(struct radeon_device *rdev, int width, int cpp, bool 
tiled)
 {
int aligned = width;
int align_large = (ASIC_IS_AVIVO(rdev)) || tiled;
int pitch_mask = 0;

-   switch (bpp / 8) {
+   switch (cpp) {
case 1:
pitch_mask = align_large ? 255 : 127;
break;
@@ -110,7 +110,7 @@ int radeon_align_pitch(struct radeon_device *rdev, int 
width, int bpp, bool tile

aligned += pitch_mask;
aligned &= ~pitch_mask;
-   return aligned;
+   return aligned * cpp;
 }

 static void radeonfb_destroy_pinned_object(struct drm_gem_object *gobj)
@@ -139,13 +139,13 @@ static int radeonfb_create_pinned_object(struct 
radeon_fbdev *rfbdev,
int ret;
int aligned_size, size;
int height = mode_cmd->height;
-   u32 bpp, depth;
+   u32 cpp;

-   drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp);
+   cpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0);

/* need to align pitch with crtc limits */
-   mode_cmd->pitches[0] = radeon_align_pitch(rdev, mode_cmd->width, bpp,
- fb_tiled) * ((bpp + 1) / 8);
+   mode_cmd->pitches[0] = radeon_align_pitch(rdev, mode_cmd->width, cpp,
+ fb_tiled);

if (rdev->family >= CHIP_R600)
height = ALIGN(mode_cmd->height, 8);
@@ -165,11 +165,11 @@ static int radeonfb_create_pinned_object(struct 
radeon_fbdev *rfbdev,
tiling_flags = RADEON_TILING_MACRO;

 #ifdef __BIG_ENDIAN
-   switch (bpp) {
-   case 32:
+   switch (cpp) {
+   case 4:
tiling_flags |= RADEON_TILING_SWAP_32BIT;
break;
-   case 16:
+   case 2:
tiling_flags |= RADEON_TILING_SWAP_16BIT;
default:
break;
diff --git a/drivers/gpu/drm/radeon/radeon_gem.c 
b/drivers/gpu/drm/radeon/radeon_gem.c
index deb9511725c9..0bcffd8a7bd3 100644
--- a/drivers/gpu/drm/radeon/radeon_gem.c
+++ b/drivers/gpu/drm/radeon/radeon_gem.c
@@ -745,7 +745,8 @@ int radeon_mode_dumb_create(struct drm_file *file_priv,
uint32_t handle;
int r;

-   args->pitch = radeon_align_pitch(rdev, args->width, args->bpp, 0) * 
((args->bpp + 1) / 8);
+   args->pitch = radeon_align_pitch(rdev, args->width,
+DIV_ROUND_UP(args->bpp, 8), 0);
args->size = args->pitch * args->height;
args->size = ALIGN(args->size, PAGE_SIZE);

-- 
Regards,

Laurent Pinchart



[PATCH v5 11/13] drm: vmwgfx: Replace drm_fb_get_bpp_depth() with drm_format_info()

2016-10-18 Thread Laurent Pinchart
The driver is the last users of the drm_fb_get_bpp_depth() function. It
should ideally be converted to use struct drm_mode_fb_cmd2 instead of
the legacy struct drm_mode_fb_cmd internally, but that will require
broad changes across the code base. As a first step, replace
drm_fb_get_bpp_depth() with drm_format_info() in order to stop exporting
the function to drivers.

The new DRM_ERROR() message comes from the vmw_create_dmabuf_proxy(),
vmw_kms_new_framebuffer_surface() and vmw_kms_new_framebuffer_dmabuf()
functions that currently print an error if the pixel format is
unsupported.

Signed-off-by: Laurent Pinchart 
Reviewed-by: Sinclair Yeh 
Reviewed-by: Daniel Vetter 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index bf28ccc150df..c965514b82be 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -980,14 +980,22 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct 
drm_device *dev,
struct vmw_dma_buffer *bo = NULL;
struct ttm_base_object *user_obj;
struct drm_mode_fb_cmd mode_cmd;
+   const struct drm_format_info *info;
int ret;

+   info = drm_format_info(mode_cmd2->pixel_format);
+   if (!info || !info->depth) {
+   DRM_ERROR("Unsupported framebuffer format %s\n",
+ drm_get_format_name(mode_cmd2->pixel_format));
+   return ERR_PTR(-EINVAL);
+   }
+
mode_cmd.width = mode_cmd2->width;
mode_cmd.height = mode_cmd2->height;
mode_cmd.pitch = mode_cmd2->pitches[0];
mode_cmd.handle = mode_cmd2->handles[0];
-   drm_fb_get_bpp_depth(mode_cmd2->pixel_format, &mode_cmd.depth,
-   &mode_cmd.bpp);
+   mode_cmd.depth = info->depth;
+   mode_cmd.bpp = info->cpp[0] * 8;

/**
 * This code should be conditioned on Screen Objects not being used.
-- 
Regards,

Laurent Pinchart



[PATCH v5 06/13] drm: tilcdc: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()

2016-10-18 Thread Laurent Pinchart
The driver needs the number of bytes per pixel, not the bpp and depth
info meant for fbdev compatibility. Use the right API.

In the tilcdc_crtc_mode_set() function compute the hardware register
value directly from the pixel format instead of computing the number of
bits per pixels first.

Signed-off-by: Laurent Pinchart 
Reviewed-by: Tomi Valkeinen 
---
Changes since v4:

- Added support for DRM_FORMAT_BGR565, DRM_FORMAT_XBGR and
  DRM_FORMAT_BGR888

Changes since v3:

- Removed DRM_FORMAT_ARGB support
- Fixed coding style
- Renamed min_pitch to pitch
---
 drivers/gpu/drm/tilcdc/tilcdc_crtc.c  | 18 --
 drivers/gpu/drm/tilcdc/tilcdc_plane.c |  7 ---
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c 
b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
index 52ebe8fc1784..822531ebd4b0 100644
--- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
+++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
@@ -72,16 +72,14 @@ static void set_scanout(struct drm_crtc *crtc, struct 
drm_framebuffer *fb)
struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc);
struct drm_device *dev = crtc->dev;
struct drm_gem_cma_object *gem;
-   unsigned int depth, bpp;
dma_addr_t start, end;
u64 dma_base_and_ceiling;

-   drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
gem = drm_fb_cma_get_gem_obj(fb, 0);

start = gem->paddr + fb->offsets[0] +
crtc->y * fb->pitches[0] +
-   crtc->x * bpp / 8;
+   crtc->x * drm_format_plane_cpp(fb->pixel_format, 0);

end = start + (crtc->mode.vdisplay * fb->pitches[0]);

@@ -461,16 +459,16 @@ static void tilcdc_crtc_mode_set_nofb(struct drm_crtc 
*crtc)
if (info->tft_alt_mode)
reg |= LCDC_TFT_ALT_ENABLE;
if (priv->rev == 2) {
-   unsigned int depth, bpp;
-
-   drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
-   switch (bpp) {
-   case 16:
+   switch (fb->pixel_format) {
+   case DRM_FORMAT_BGR565:
+   case DRM_FORMAT_RGB565:
break;
-   case 32:
+   case DRM_FORMAT_XBGR:
+   case DRM_FORMAT_XRGB:
reg |= LCDC_V2_TFT_24BPP_UNPACK;
/* fallthrough */
-   case 24:
+   case DRM_FORMAT_BGR888:
+   case DRM_FORMAT_RGB888:
reg |= LCDC_V2_TFT_24BPP_MODE;
break;
default:
diff --git a/drivers/gpu/drm/tilcdc/tilcdc_plane.c 
b/drivers/gpu/drm/tilcdc/tilcdc_plane.c
index 74c65fa859b2..8a6a50d74aff 100644
--- a/drivers/gpu/drm/tilcdc/tilcdc_plane.c
+++ b/drivers/gpu/drm/tilcdc/tilcdc_plane.c
@@ -39,7 +39,7 @@ static int tilcdc_plane_atomic_check(struct drm_plane *plane,
 {
struct drm_crtc_state *crtc_state;
struct drm_plane_state *old_state = plane->state;
-   unsigned int depth, bpp;
+   unsigned int pitch;

if (!state->crtc)
return 0;
@@ -68,8 +68,9 @@ static int tilcdc_plane_atomic_check(struct drm_plane *plane,
return -EINVAL;
}

-   drm_fb_get_bpp_depth(state->fb->pixel_format, &depth, &bpp);
-   if (state->fb->pitches[0] != crtc_state->mode.hdisplay * bpp / 8) {
+   pitch = crtc_state->mode.hdisplay *
+   drm_format_plane_cpp(state->fb->pixel_format, 0);
+   if (state->fb->pitches[0] != pitch) {
dev_err(plane->dev->dev,
"Invalid pitch: fb and crtc widths must be the same");
return -EINVAL;
-- 
Regards,

Laurent Pinchart



[PATCH v5 04/13] drm: WARN when calling drm_format_info() for an unsupported format

2016-10-18 Thread Laurent Pinchart
The format helpers have historically treated unsupported formats as part
of the default case, returning values that are likely wrong. We can't
change this behaviour now without risking breaking drivers in difficult
to detect ways, but we can WARN on unsupported formats to catch faulty
callers.

The only exception is the framebuffer_check() function that calls
drm_format_info() to validate the format passed from userspace. This is
a valid use case that shouldn't generate a warning.

Signed-off-by: Laurent Pinchart 
Reviewed-by: Tomi Valkeinen 
---
 drivers/gpu/drm/drm_fourcc.c  | 32 
 drivers/gpu/drm/drm_framebuffer.c |  2 +-
 include/drm/drm_fourcc.h  |  1 +
 3 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index 23d4b82ec17c..523ed916a1c0 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -102,15 +102,11 @@ char *drm_get_format_name(uint32_t format)
 }
 EXPORT_SYMBOL(drm_get_format_name);

-/**
- * drm_format_info - query information for a given format
- * @format: pixel format (DRM_FORMAT_*)
- *
- * Returns:
- * The instance of struct drm_format_info that describes the pixel format, or
- * NULL if the format is unsupported.
+/*
+ * Internal function to query information for a given format. See
+ * drm_format_info() for the public API.
  */
-const struct drm_format_info *drm_format_info(u32 format)
+const struct drm_format_info *__drm_format_info(u32 format)
 {
static const struct drm_format_info formats[] = {
{ .format = DRM_FORMAT_C8,  .depth = 8,  
.num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 },
@@ -184,6 +180,26 @@ const struct drm_format_info *drm_format_info(u32 format)

return NULL;
 }
+
+/**
+ * drm_format_info - query information for a given format
+ * @format: pixel format (DRM_FORMAT_*)
+ *
+ * The caller should only pass a supported pixel format to this function.
+ * Unsupported pixel formats will generate a warning in the kernel log.
+ *
+ * Returns:
+ * The instance of struct drm_format_info that describes the pixel format, or
+ * NULL if the format is unsupported.
+ */
+const struct drm_format_info *drm_format_info(u32 format)
+{
+   const struct drm_format_info *info;
+
+   info = __drm_format_info(format);
+   WARN_ON(!info);
+   return info;
+}
 EXPORT_SYMBOL(drm_format_info);

 /**
diff --git a/drivers/gpu/drm/drm_framebuffer.c 
b/drivers/gpu/drm/drm_framebuffer.c
index 386977df72ce..49fd7db758e0 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -131,7 +131,7 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 
*r)
const struct drm_format_info *info;
int i;

-   info = drm_format_info(r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN);
+   info = __drm_format_info(r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN);
if (!info) {
char *format_name = drm_get_format_name(r->pixel_format);
DRM_DEBUG_KMS("bad framebuffer format %s\n", format_name);
diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
index 135fef050ee6..f73f97afd1e2 100644
--- a/include/drm/drm_fourcc.h
+++ b/include/drm/drm_fourcc.h
@@ -45,6 +45,7 @@ struct drm_format_info {
u8 vsub;
 };

+const struct drm_format_info *__drm_format_info(u32 format);
 const struct drm_format_info *drm_format_info(u32 format);
 uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
 void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, int *bpp);
-- 
Regards,

Laurent Pinchart



[PATCH v5 03/13] drm: Use drm_format_info() in DRM core code

2016-10-18 Thread Laurent Pinchart
Replace calls to the drm_format_*() helper functions with direct use of
the drm_format_info structure. This improves efficiency by removing
duplicate lookups.

Signed-off-by: Laurent Pinchart 
Reviewed-by: Daniel Vetter 
Reviewed-by: Eric Engestrom 
---
 drivers/gpu/drm/drm_fb_cma_helper.c |  23 
 drivers/gpu/drm/drm_framebuffer.c   | 102 +---
 2 files changed, 25 insertions(+), 100 deletions(-)

diff --git a/drivers/gpu/drm/drm_fb_cma_helper.c 
b/drivers/gpu/drm/drm_fb_cma_helper.c
index 1fd6eac1400c..fac4f06f8485 100644
--- a/drivers/gpu/drm/drm_fb_cma_helper.c
+++ b/drivers/gpu/drm/drm_fb_cma_helper.c
@@ -176,20 +176,20 @@ struct drm_framebuffer 
*drm_fb_cma_create_with_funcs(struct drm_device *dev,
struct drm_file *file_priv, const struct drm_mode_fb_cmd2 *mode_cmd,
const struct drm_framebuffer_funcs *funcs)
 {
+   const struct drm_format_info *info;
struct drm_fb_cma *fb_cma;
struct drm_gem_cma_object *objs[4];
struct drm_gem_object *obj;
-   unsigned int hsub;
-   unsigned int vsub;
int ret;
int i;

-   hsub = drm_format_horz_chroma_subsampling(mode_cmd->pixel_format);
-   vsub = drm_format_vert_chroma_subsampling(mode_cmd->pixel_format);
+   info = drm_format_info(mode_cmd->pixel_format);
+   if (!info)
+   return ERR_PTR(-EINVAL);

-   for (i = 0; i < drm_format_num_planes(mode_cmd->pixel_format); i++) {
-   unsigned int width = mode_cmd->width / (i ? hsub : 1);
-   unsigned int height = mode_cmd->height / (i ? vsub : 1);
+   for (i = 0; i < info->num_planes; i++) {
+   unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
+   unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
unsigned int min_size;

obj = drm_gem_object_lookup(file_priv, mode_cmd->handles[i]);
@@ -200,7 +200,7 @@ struct drm_framebuffer *drm_fb_cma_create_with_funcs(struct 
drm_device *dev,
}

min_size = (height - 1) * mode_cmd->pitches[i]
-+ width * drm_format_plane_cpp(mode_cmd->pixel_format, 
i)
++ width * info->cpp[i]
 + mode_cmd->offsets[i];

if (obj->size < min_size) {
@@ -269,12 +269,15 @@ EXPORT_SYMBOL_GPL(drm_fb_cma_get_gem_obj);
 static void drm_fb_cma_describe(struct drm_framebuffer *fb, struct seq_file *m)
 {
struct drm_fb_cma *fb_cma = to_fb_cma(fb);
-   int i, n = drm_format_num_planes(fb->pixel_format);
+   const struct drm_format_info *info;
+   int i;

seq_printf(m, "fb: %dx%d@%4.4s\n", fb->width, fb->height,
(char *)&fb->pixel_format);

-   for (i = 0; i < n; i++) {
+   info = drm_format_info(fb->pixel_format);
+
+   for (i = 0; i < info->num_planes; i++) {
seq_printf(m, "   %d: offset=%d pitch=%d, obj: ",
i, fb->offsets[i], fb->pitches[i]);
drm_gem_cma_describe(fb_cma->obj[i], m);
diff --git a/drivers/gpu/drm/drm_framebuffer.c 
b/drivers/gpu/drm/drm_framebuffer.c
index 398efd67cb93..386977df72ce 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -126,111 +126,33 @@ int drm_mode_addfb(struct drm_device *dev,
return 0;
 }

-static int format_check(const struct drm_mode_fb_cmd2 *r)
-{
-   uint32_t format = r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN;
-   char *format_name;
-
-   switch (format) {
-   case DRM_FORMAT_C8:
-   case DRM_FORMAT_RGB332:
-   case DRM_FORMAT_BGR233:
-   case DRM_FORMAT_XRGB:
-   case DRM_FORMAT_XBGR:
-   case DRM_FORMAT_RGBX:
-   case DRM_FORMAT_BGRX:
-   case DRM_FORMAT_ARGB:
-   case DRM_FORMAT_ABGR:
-   case DRM_FORMAT_RGBA:
-   case DRM_FORMAT_BGRA:
-   case DRM_FORMAT_XRGB1555:
-   case DRM_FORMAT_XBGR1555:
-   case DRM_FORMAT_RGBX5551:
-   case DRM_FORMAT_BGRX5551:
-   case DRM_FORMAT_ARGB1555:
-   case DRM_FORMAT_ABGR1555:
-   case DRM_FORMAT_RGBA5551:
-   case DRM_FORMAT_BGRA5551:
-   case DRM_FORMAT_RGB565:
-   case DRM_FORMAT_BGR565:
-   case DRM_FORMAT_RGB888:
-   case DRM_FORMAT_BGR888:
-   case DRM_FORMAT_XRGB:
-   case DRM_FORMAT_XBGR:
-   case DRM_FORMAT_RGBX:
-   case DRM_FORMAT_BGRX:
-   case DRM_FORMAT_ARGB:
-   case DRM_FORMAT_ABGR:
-   case DRM_FORMAT_RGBA:
-   case DRM_FORMAT_BGRA:
-   case DRM_FORMAT_XRGB2101010:
-   case DRM_FORMAT_XBGR2101010:
-   case DRM_FORMAT_RGBX1010102:
-   case DRM_FORMAT_BGRX1010102:
-   case DRM_FORMAT_ARGB2101010:
-   case DRM_FORMAT_ABGR2101010:
-   case DRM_FORMAT_RGBA1010102:
-   case DRM_FORMAT_BGRA1010102:
-   case DRM_FORMAT_YUYV:
-   case DRM_FORMAT_YVYU:
-   case DRM_F

[PATCH v5 12/13] drm/arm: mali-dp: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()

2016-10-18 Thread Laurent Pinchart
The driver doesn't need the color depth, only the number of bits per
pixel. Use the right API.

Signed-off-by: Laurent Pinchart 
Reviewed-by: Daniel Vetter 
---
 drivers/gpu/drm/arm/malidp_hw.c | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/arm/malidp_hw.c b/drivers/gpu/drm/arm/malidp_hw.c
index a6132f1d58c1..be815d0cc772 100644
--- a/drivers/gpu/drm/arm/malidp_hw.c
+++ b/drivers/gpu/drm/arm/malidp_hw.c
@@ -198,9 +198,6 @@ static void malidp500_modeset(struct malidp_hw_device 
*hwdev, struct videomode *

 static int malidp500_rotmem_required(struct malidp_hw_device *hwdev, u16 w, 
u16 h, u32 fmt)
 {
-   unsigned int depth;
-   int bpp;
-
/* RGB888 or BGR888 can't be rotated */
if ((fmt == DRM_FORMAT_RGB888) || (fmt == DRM_FORMAT_BGR888))
return -EINVAL;
@@ -210,9 +207,7 @@ static int malidp500_rotmem_required(struct 
malidp_hw_device *hwdev, u16 w, u16
 * worth of pixel data. Required size is then:
 *size = rotated_width * (bpp / 8) * 8;
 */
-   drm_fb_get_bpp_depth(fmt, &depth, &bpp);
-
-   return w * bpp;
+   return w * drm_format_plane_cpp(fmt, 0) * 8;
 }

 static int malidp550_query_hw(struct malidp_hw_device *hwdev)
-- 
Regards,

Laurent Pinchart



[PATCH v5 13/13] drm: Don't export the drm_fb_get_bpp_depth() function

2016-10-18 Thread Laurent Pinchart
The function is only used by the drm_helper_mode_fill_fb_struct() core
function to fill the drm_framebuffer bpp and depth fields, used by
drivers that haven't been converted to use pixel formats directly yet.
It should not be used by new drivers, so inline it in its only caller.

Signed-off-by: Laurent Pinchart 
Reviewed-by: Tomi Valkeinen 
---
 drivers/gpu/drm/drm_fourcc.c | 31 ---
 drivers/gpu/drm/drm_modeset_helper.c | 17 +++--
 include/drm/drm_fourcc.h |  1 -
 3 files changed, 15 insertions(+), 34 deletions(-)

diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index 523ed916a1c0..cbb8b77c363c 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -203,37 +203,6 @@ const struct drm_format_info *drm_format_info(u32 format)
 EXPORT_SYMBOL(drm_format_info);

 /**
- * drm_fb_get_bpp_depth - get the bpp/depth values for format
- * @format: pixel format (DRM_FORMAT_*)
- * @depth: storage for the depth value
- * @bpp: storage for the bpp value
- *
- * This only supports RGB formats here for compat with code that doesn't use
- * pixel formats directly yet.
- */
-void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
- int *bpp)
-{
-   const struct drm_format_info *info;
-
-   info = drm_format_info(format);
-   if (!info || !info->depth) {
-   char *format_name = drm_get_format_name(format);
-
-   DRM_DEBUG_KMS("unsupported pixel format %s\n", format_name);
-   kfree(format_name);
-
-   *depth = 0;
-   *bpp = 0;
-   return;
-   }
-
-   *depth = info->depth;
-   *bpp = info->cpp[0] * 8;
-}
-EXPORT_SYMBOL(drm_fb_get_bpp_depth);
-
-/**
  * drm_format_num_planes - get the number of planes for format
  * @format: pixel format (DRM_FORMAT_*)
  *
diff --git a/drivers/gpu/drm/drm_modeset_helper.c 
b/drivers/gpu/drm/drm_modeset_helper.c
index 1d45738f8f98..2544dfe7354c 100644
--- a/drivers/gpu/drm/drm_modeset_helper.c
+++ b/drivers/gpu/drm/drm_modeset_helper.c
@@ -70,8 +70,23 @@ EXPORT_SYMBOL(drm_helper_move_panel_connectors_to_head);
 void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
const struct drm_mode_fb_cmd2 *mode_cmd)
 {
+   const struct drm_format_info *info;
int i;

+   info = drm_format_info(mode_cmd->pixel_format);
+   if (!info || !info->depth) {
+   char *format_name = drm_get_format_name(mode_cmd->pixel_format);
+
+   DRM_DEBUG_KMS("non-RGB pixel format %s\n", format_name);
+   kfree(format_name);
+
+   fb->depth = 0;
+   fb->bits_per_pixel = 0;
+   } else {
+   fb->depth = info->depth;
+   fb->bits_per_pixel = info->cpp[0] * 8;
+   }
+
fb->width = mode_cmd->width;
fb->height = mode_cmd->height;
for (i = 0; i < 4; i++) {
@@ -79,8 +94,6 @@ void drm_helper_mode_fill_fb_struct(struct drm_framebuffer 
*fb,
fb->offsets[i] = mode_cmd->offsets[i];
fb->modifier[i] = mode_cmd->modifier[i];
}
-   drm_fb_get_bpp_depth(mode_cmd->pixel_format, &fb->depth,
-   &fb->bits_per_pixel);
fb->pixel_format = mode_cmd->pixel_format;
fb->flags = mode_cmd->flags;
 }
diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
index f73f97afd1e2..dc0aafab9ffd 100644
--- a/include/drm/drm_fourcc.h
+++ b/include/drm/drm_fourcc.h
@@ -48,7 +48,6 @@ struct drm_format_info {
 const struct drm_format_info *__drm_format_info(u32 format);
 const struct drm_format_info *drm_format_info(u32 format);
 uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
-void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, int *bpp);
 int drm_format_num_planes(uint32_t format);
 int drm_format_plane_cpp(uint32_t format, int plane);
 int drm_format_horz_chroma_subsampling(uint32_t format);
-- 
Regards,

Laurent Pinchart



[PATCH v5 07/13] drm: cirrus: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()

2016-10-18 Thread Laurent Pinchart
The driver doesn't need the color depth, only the number of bits per
pixel. Use the right API.

Signed-off-by: Laurent Pinchart 
Reviewed-by: Daniel Vetter 
---
 drivers/gpu/drm/cirrus/cirrus_fbdev.c | 6 +++---
 drivers/gpu/drm/cirrus/cirrus_main.c  | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/cirrus/cirrus_fbdev.c 
b/drivers/gpu/drm/cirrus/cirrus_fbdev.c
index daecf1ad76a4..3a6309d7d8e4 100644
--- a/drivers/gpu/drm/cirrus/cirrus_fbdev.c
+++ b/drivers/gpu/drm/cirrus/cirrus_fbdev.c
@@ -138,12 +138,12 @@ static int cirrusfb_create_object(struct cirrus_fbdev 
*afbdev,
 {
struct drm_device *dev = afbdev->helper.dev;
struct cirrus_device *cdev = dev->dev_private;
-   u32 bpp, depth;
+   u32 bpp;
u32 size;
struct drm_gem_object *gobj;
-
int ret = 0;
-   drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp);
+
+   bpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0) * 8;

if (!cirrus_check_framebuffer(cdev, mode_cmd->width, mode_cmd->height,
  bpp, mode_cmd->pitches[0]))
diff --git a/drivers/gpu/drm/cirrus/cirrus_main.c 
b/drivers/gpu/drm/cirrus/cirrus_main.c
index 76bcb43e7c06..2c3c0d4072ce 100644
--- a/drivers/gpu/drm/cirrus/cirrus_main.c
+++ b/drivers/gpu/drm/cirrus/cirrus_main.c
@@ -52,10 +52,10 @@ cirrus_user_framebuffer_create(struct drm_device *dev,
struct cirrus_device *cdev = dev->dev_private;
struct drm_gem_object *obj;
struct cirrus_framebuffer *cirrus_fb;
+   u32 bpp;
int ret;
-   u32 bpp, depth;

-   drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp);
+   bpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0) * 8;

if (!cirrus_check_framebuffer(cdev, mode_cmd->width, mode_cmd->height,
  bpp, mode_cmd->pitches[0]))
-- 
Regards,

Laurent Pinchart



[drm-intel:for-linux-next 0/3] drivers/gpu/drm/i915/gvt/handlers.c:137: error: request for member 'mmio_base' in something not a structure or union

2016-10-18 Thread kbuild test robot
tree:   git://anongit.freedesktop.org/drm-intel for-linux-next
head:   bfd02b3c557caa083be0d55a3164ede706a446e1
commit: 06a75ace46e2fdd1d93b06228df0e2dfe526cc27 [0/3] Merge tag 
'gvt-next-2016-10-14' of https://github.com/01org/gvt-linux into 
drm-intel-next-queued
config: x86_64-randconfig-s0-10180350 (attached as .config)
compiler: gcc-4.4 (Debian 4.4.7-8) 4.4.7
reproduce:
git checkout 06a75ace46e2fdd1d93b06228df0e2dfe526cc27
# save the attached .config to linux build tree
make ARCH=x86_64 

All error/warnings (new ones prefixed by >>):

   drivers/gpu/drm/i915/gvt/handlers.c: In function 'render_mmio_to_ring_id':
>> drivers/gpu/drm/i915/gvt/handlers.c:137: error: request for member 
>> 'mmio_base' in something not a structure or union
--
   drivers/gpu/drm/i915/gvt/execlist.c: In function 'emulate_execlist_status':
>> drivers/gpu/drm/i915/gvt/execlist.c:97: error: request for member 
>> 'mmio_base' in something not a structure or union
   drivers/gpu/drm/i915/gvt/execlist.c: In function 'emulate_csb_update':
   drivers/gpu/drm/i915/gvt/execlist.c:136: error: request for member 
'mmio_base' in something not a structure or union
   drivers/gpu/drm/i915/gvt/execlist.c:138: error: request for member 
'mmio_base' in something not a structure or union
   drivers/gpu/drm/i915/gvt/execlist.c: In function 'get_next_execlist_slot':
   drivers/gpu/drm/i915/gvt/execlist.c:248: error: request for member 
'mmio_base' in something not a structure or union
   drivers/gpu/drm/i915/gvt/execlist.c: In function 'init_vgpu_execlist':
   drivers/gpu/drm/i915/gvt/execlist.c:798: error: request for member 
'mmio_base' in something not a structure or union
--
   drivers/gpu/drm/i915/gvt/scheduler.c: In function 'populate_shadow_context':
>> drivers/gpu/drm/i915/gvt/scheduler.c:71: warning: passing argument 1 of 
>> 'intel_lr_context_size' from incompatible pointer type
   drivers/gpu/drm/i915/intel_lrc.h:84: note: expected 'struct intel_engine_cs 
*' but argument is of type 'struct intel_engine_cs **'
   drivers/gpu/drm/i915/gvt/scheduler.c: In function 'dispatch_workload':
>> drivers/gpu/drm/i915/gvt/scheduler.c:175: warning: passing argument 1 of 
>> 'i915_gem_request_alloc' from incompatible pointer type
   drivers/gpu/drm/i915/i915_gem_request.h:156: note: expected 'struct 
intel_engine_cs *' but argument is of type 'struct intel_engine_cs **'
   drivers/gpu/drm/i915/gvt/scheduler.c: In function 'update_guest_context':
   drivers/gpu/drm/i915/gvt/scheduler.c:301: warning: passing argument 1 of 
'intel_lr_context_size' from incompatible pointer type
   drivers/gpu/drm/i915/intel_lrc.h:84: note: expected 'struct intel_engine_cs 
*' but argument is of type 'struct intel_engine_cs **'
   drivers/gpu/drm/i915/gvt/scheduler.o: warning: objtool: 
complete_current_workload()+0x771: function has unreachable instruction

vim +/mmio_base +137 drivers/gpu/drm/i915/gvt/handlers.c

28c4c6ca Zhi Wang 2016-05-01  131  static int render_mmio_to_ring_id(struct 
intel_gvt *gvt, unsigned int reg)
28c4c6ca Zhi Wang 2016-05-01  132  {
28c4c6ca Zhi Wang 2016-05-01  133   int i;
28c4c6ca Zhi Wang 2016-05-01  134  
28c4c6ca Zhi Wang 2016-05-01  135   reg &= ~GENMASK(11, 0);
28c4c6ca Zhi Wang 2016-05-01  136   for (i = 0; i < I915_NUM_ENGINES; i++) {
28c4c6ca Zhi Wang 2016-05-01 @137   if 
(gvt->dev_priv->engine[i].mmio_base == reg)
28c4c6ca Zhi Wang 2016-05-01  138   return i;
28c4c6ca Zhi Wang 2016-05-01  139   }
28c4c6ca Zhi Wang 2016-05-01  140   return -1;

:: The code at line 137 was first introduced by commit
:: 28c4c6ca7f794b2d5ac8773d43311e95f6518415 drm/i915/gvt: vGPU workload 
submission

:: TO: Zhi Wang 
:: CC: Zhenyu Wang 

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation
-- next part --
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/gzip
Size: 25778 bytes
Desc: not available
URL: 
<https://lists.freedesktop.org/archives/dri-devel/attachments/20161018/a74d876e/attachment-0001.gz>


[PATCH 18/28] drm: avoid uninitialized timestamp use in wait_vblank

2016-10-18 Thread Mario Kleiner
On 10/18/2016 12:13 AM, Arnd Bergmann wrote:
> gcc warns about the timestamp in drm_wait_vblank being possibly
> used without an initialization:
>
> drivers/gpu/drm/drm_irq.c: In function 'drm_crtc_send_vblank_event':
> drivers/gpu/drm/drm_irq.c:992:24: error: 'now.tv_usec' may be used 
> uninitialized in this function [-Werror=maybe-uninitialized]
> drivers/gpu/drm/drm_irq.c:1069:17: note: 'now.tv_usec' was declared here
> drivers/gpu/drm/drm_irq.c:991:23: error: 'now.tv_sec' may be used 
> uninitialized in this function [-Werror=maybe-uninitialized]
>
> This can happen if drm_vblank_count_and_time() returns 0 in its
> error path. To sanitize the error case, I'm changing that function
> to return a zero timestamp when it fails.
>
> Fixes: e6ae8687a87b ("drm: idiot-proof vblank")
> Reviewed-by: David Herrmann 
> Cc: Rob Clark 
> Cc: Daniel Vetter 
> Signed-off-by: Arnd Bergmann 
> ---
> First submitted in January 2016, second submission in February,
> the patch is still required.
>
>  drivers/gpu/drm/drm_irq.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> index b969a64..48a6167 100644
> --- a/drivers/gpu/drm/drm_irq.c
> +++ b/drivers/gpu/drm/drm_irq.c
> @@ -952,8 +952,10 @@ static u32 drm_vblank_count_and_time(struct drm_device 
> *dev, unsigned int pipe,
>   u32 vblank_count;
>   unsigned int seq;
>
> - if (WARN_ON(pipe >= dev->num_crtcs))
> + if (WARN_ON(pipe >= dev->num_crtcs)) {
> + *vblanktime = (struct timeval) { 0 };
>   return 0;
> + }
>
>   do {
>   seq = read_seqbegin(&vblank->seqlock);
>

Looks good to me.

Reviewed-by: Mario Kleiner 

-mario


linux-next: build failure after merge of the drm-intel tree

2016-10-18 Thread Stephen Rothwell
Hi all,

After merging the drm-intel tree, today's linux-next build (x86_64
allmodconfig) failed like this:

drivers/gpu/drm/i915/gvt/handlers.c: In function 'render_mmio_to_ring_id':
drivers/gpu/drm/i915/gvt/handlers.c:137:31: error: request for member 
'mmio_base' in something not a structure or union
   if (gvt->dev_priv->engine[i].mmio_base == reg)
   ^
drivers/gpu/drm/i915/gvt/scheduler.c: In function 'populate_shadow_context':
drivers/gpu/drm/i915/gvt/scheduler.c:71:4: error: passing argument 1 of 
'intel_lr_context_size' from incompatible pointer type 
[-Werror=incompatible-pointer-types]
&gvt->dev_priv->engine[ring_id]);
^
In file included from drivers/gpu/drm/i915/i915_drv.h:58:0,
 from drivers/gpu/drm/i915/gvt/scheduler.c:36:
drivers/gpu/drm/i915/intel_lrc.h:84:10: note: expected 'struct intel_engine_cs 
*' but argument is of type 'struct intel_engine_cs **'
 uint32_t intel_lr_context_size(struct intel_engine_cs *engine);
  ^
drivers/gpu/drm/i915/gvt/scheduler.c: In function 'dispatch_workload':
drivers/gpu/drm/i915/gvt/scheduler.c:174:41: error: passing argument 1 of 
'i915_gem_request_alloc' from incompatible pointer type 
[-Werror=incompatible-pointer-types]
  workload->req = i915_gem_request_alloc(&dev_priv->engine[ring_id],
 ^
In file included from drivers/gpu/drm/i915/intel_ringbuffer.h:6:0,
 from drivers/gpu/drm/i915/intel_guc.h:29,
 from drivers/gpu/drm/i915/i915_drv.h:57,
 from drivers/gpu/drm/i915/gvt/scheduler.c:36:
drivers/gpu/drm/i915/i915_gem_request.h:156:1: note: expected 'struct 
intel_engine_cs *' but argument is of type 'struct intel_engine_cs **'
 i915_gem_request_alloc(struct intel_engine_cs *engine,
 ^
drivers/gpu/drm/i915/gvt/scheduler.c: In function 'update_guest_context':
drivers/gpu/drm/i915/gvt/scheduler.c:301:4: error: passing argument 1 of 
'intel_lr_context_size' from incompatible pointer type 
[-Werror=incompatible-pointer-types]
&gvt->dev_priv->engine[ring_id]);
^
In file included from drivers/gpu/drm/i915/i915_drv.h:58:0,
 from drivers/gpu/drm/i915/gvt/scheduler.c:36:
drivers/gpu/drm/i915/intel_lrc.h:84:10: note: expected 'struct intel_engine_cs 
*' but argument is of type 'struct intel_engine_cs **'
 uint32_t intel_lr_context_size(struct intel_engine_cs *engine);
  ^
drivers/gpu/drm/i915/gvt/execlist.c: In function 'emulate_execlist_status':
drivers/gpu/drm/i915/gvt/execlist.c:42:33: error: request for member 
'mmio_base' in something not a structure or union
  (gvt->dev_priv->engine[ring_id].mmio_base + (offset))
 ^  
drivers/gpu/drm/i915/gvt/execlist.c:97:19: note: in expansion of macro 
'execlist_ring_mmio'
  u32 status_reg = execlist_ring_mmio(vgpu->gvt,
   ^
drivers/gpu/drm/i915/gvt/execlist.c: In function 'emulate_csb_update':
drivers/gpu/drm/i915/gvt/execlist.c:42:33: error: request for member 
'mmio_base' in something not a structure or union
  (gvt->dev_priv->engine[ring_id].mmio_base + (offset))
 ^  
drivers/gpu/drm/i915/gvt/execlist.c:136:23: note: in expansion of macro 
'execlist_ring_mmio'
  ctx_status_ptr_reg = execlist_ring_mmio(vgpu->gvt, ring_id,
   ^
drivers/gpu/drm/i915/gvt/execlist.c:42:33: error: request for member 
'mmio_base' in something not a structure or union
  (gvt->dev_priv->engine[ring_id].mmio_base + (offset))
 ^  
drivers/gpu/drm/i915/gvt/execlist.c:138:23: note: in expansion of macro 
'execlist_ring_mmio'
  ctx_status_buf_reg = execlist_ring_mmio(vgpu->gvt, ring_id,
   ^
drivers/gpu/drm/i915/gvt/execlist.c: In function 'get_next_execlist_slot':
drivers/gpu/drm/i915/gvt/execlist.c:42:33: error: request for member 
'mmio_base' in something not a structure or union
  (gvt->dev_priv->engine[ring_id].mmio_base + (offset))
 ^  
drivers/gpu/drm/i915/gvt/execlist.c:248:19: note: in expansion of macro 
'execlist_ring_mmio'
  u32 status_reg = execlist_ring_mmio(vgpu->gvt, ring_id,
   ^
drivers/gpu/drm/i915/gvt/execlist.c: In function 'release_shadow_batch_buffer':
drivers/gpu/drm/i915/gvt/execlist.c:501:4: warning: 
'drm_gem_object_unreference' is deprecated [-Wdeprecated-declarations]
drm_gem_object_unreference(&(entry_obj->obj->base));
^
In file included from drivers/gpu/drm/i915/gvt/execlist.c:35:0:
drivers/gpu/drm/i915/i915_drv.h:2344:13: note: declared here
 extern void drm_gem_object_unreference(struct drm_gem_object *);
 ^
drivers/gpu/drm/i915/gvt/execlist.c: In function 'release_shadow_wa_ctx':
drivers/gpu/drm/i915/gvt/execlist.c:514:2: warning: 
'drm_gem_object_unreference' is deprecated [-Wdeprecated-declarations]
  drm_gem_object_unreference(&(wa_ctx->indirect_ctx.obj->base));
  ^
In file included from drivers/gpu/drm/i915/gvt/execlist.c

[PATCH v5 0/3] drm/nouveau: set DMA mask before mapping scratch page

2016-10-18 Thread Alexandre Courbot
On Mon, Oct 17, 2016 at 5:12 AM, Ard Biesheuvel
 wrote:
> On 7 October 2016 at 09:12, Alexandre Courbot  wrote:
>> On Fri, Oct 7, 2016 at 12:49 AM, Ard Biesheuvel
>>  wrote:
>>> This v4 is now a 3 piece series (since v4), after Alexandre pointed out that
>>> both GF 100 and NV50 are affected by the same issue, and that a related 
>>> issue
>>> has been solved already for Tegra in commit 9d0394c6bed5
>>> ("drm/nouveau/instmem/gk20a: set DMA mask early").
>>>
>>> The issue that this series addresses is the fact that the Nouveau driver
>>> invokes the DMA API before setting the DMA mask. In both cases addressed
>>> here, these are simply static bidirectional mappings of scratch pages whose
>>> purpose is not well understood, and in most cases, it does not matter that
>>> these pages are always allocated below 4 GB even if the hardware can access
>>> memory much higher up.
>>>
>>> However, on platforms without any RAM below 4 GB, the preliminary DMA mask
>>> of 32 is preventing the nouveau driver from loading on GF100 and NV50
>>> hardware with an error like the following one:
>>>
>>>nouveau :02:00.0: enabling device ( -> 0003)
>>>nouveau :02:00.0: NVIDIA GT218 (0a8280b1)
>>>nouveau :02:00.0: bios: version 70.18.a6.00.00
>>>nouveau :02:00.0: fb ctor failed, -14
>>>nouveau: probe of :02:00.0 failed with error -14
>>>
>>> So fix this by setting a preliminary DMA mask based on the MMU device 
>>> 'dma_bits'
>>> property (patch #1), and postpone mapping the scratch pages to the 
>>> respective
>>> FB .init() hooks. (#2 and #3)
>>>
>>> v5: move setting of preliminary DMA mask to nvkm_device_pci_new() (#1)
>>> move allocation and DMA mapping of scratch pages to .oneinit hooks (#2, 
>>> #3)
>>> v4: split and move dma_set_mask to probe hook (Alexander)
>>> v3: rework code to get rid of DMA_ERROR_CODE references, which is not
>>> defined on all architectures
>>> v2: replace incorrect comparison of dma_addr_t type var against NULL
>>>
>>> Ard Biesheuvel (3):
>>>   drm/nouveau: set streaming DMA mask early
>>>   drm/nouveau/fb/gf100: defer DMA mapping of scratch page to oneinit()
>>> hook
>>>   drm/nouveau/fb/nv50: defer DMA mapping of scratch page to oneinit()
>>> hook
>>
>> The series,
>>
>> Reviewed-by: Alexandre Courbot 
>>
>
> Thank you Alexandre.
>
> So is there a nouveau subtree this should go into? Or is it up to Dave
> to pull it into drm?

Ben already merged your patches into
https://github.com/skeggsb/nouveau/commits/master (and forgot to add
my Reviewed-by ;)). This repository will be merged into the next
kernel release.


[Bug 96381] Texture artifacts with immutable texture storage and mipmaps

2016-10-18 Thread bugzilla-dae...@freedesktop.org
https://bugs.freedesktop.org/show_bug.cgi?id=96381

--- Comment #4 from Fabian Maurer  ---
Can confirm that the issue isn't present anymore with a recent version of mesa.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-- next part --
An HTML attachment was scrubbed...
URL: 
<https://lists.freedesktop.org/archives/dri-devel/attachments/20161018/552aab57/attachment-0001.html>


[PATCH 28/28] Kbuild: bring back -Wmaybe-uninitialized warning

2016-10-18 Thread Arnd Bergmann
Traditionally, we have always had warnings about uninitialized variables
enabled, as this is part of -Wall, and generally a good idea [1], but it
also always produced false positives, mainly because this is a variation
of the halting problem and provably impossible to get right in all cases
[2].

Various people have identified cases that are particularly bad for false
positives, and in commit e74fc973b6e5 ("Turn off -Wmaybe-uninitialized
when building with -Os"), I turned off the warning for any build that
was done with CC_OPTIMIZE_FOR_SIZE.  This drastically reduced the number
of false positive warnings in the default build but unfortunately had
the side effect of turning the warning off completely in 'allmodconfig'
builds, which in turn led to a lot of warnings (both actual bugs, and
remaining false positives) to go in unnoticed.

With commit 877417e6ffb9 ("Kbuild: change CC_OPTIMIZE_FOR_SIZE
definition") enabled the warning again for allmodconfig builds in v4.7
and in v4.8-rc1, I had finally managed to address all warnings I get in
an ARM allmodconfig build and most other maybe-uninitialized warnings
for ARM randconfig builds.

However, commit 6e8d666e9253 ("Disable "maybe-uninitialized" warning
globally") was merged at the same time and disabled it completely for
all configurations, because of false-positive warnings on x86 that
I had not addressed until then. This caused a lot of actual bugs to
get merged into mainline, and I sent several dozen patches for these
during the v4.9 development cycle. Most of these are actual bugs,
some are for correct code that is safe because it is only called
under external constraints that make it impossible to run into
the case that gcc sees, and in a few cases gcc is just stupid and
finds something that can obviously never happen.

I have now done a few thousand randconfig builds on x86 and collected
all patches that I needed to address every single warning I got
(I can provide the combined patch for the other warnings if anyone
is interested), so I hope we can get the warning back and let people
catch the actual bugs earlier.

Note that the majority of the patches I created are for the third kind
of problem (stupid false-positives), for one of two reasons:
- some of them only get triggered in certain combinations of config
  options, so we don't always run into them, and
- the actual bugs tend to get addressed much quicker as they also
  lead to incorrect runtime behavior.

These 27 patches address the warnings that either occur in one of the more
common configurations (defconfig, allmodconfig, or something built by the
kbuild robot or kernelci.org), or they are about a real bug. It would be
good to get these all into v4.9 if we want to turn on the warning again.
I have tested these extensively with gcc-4.9 and gcc-6 and done a bit
of testing with gcc-5, and all of these should now be fine. gcc-4.8
is much worse about the false-positive warnings and is also fairly old
now, so I'm leaving the warning disabled with that version. gcc-4.7 and
older don't understand the -Wno-maybe-uninitialized option and are not
affected by this patch either way.

I have another (smaller) series of patches for warnings that are both
harmless and not as easy to trigger, and I will send them for inclusion
in v4.10.

Link: https://rusty.ozlabs.org/?p=232 [1]
Link: https://gcc.gnu.org/wiki/Better_Uninitialized_Warnings [2]
Signed-off-by: Arnd Bergmann 
---
 Makefile   | 10 ++
 arch/arc/Makefile  |  4 +++-
 scripts/Makefile.ubsan |  4 
 3 files changed, 13 insertions(+), 5 deletions(-)

Cc: x86 at kernel.org
Cc: linux-media at vger.kernel.org
Cc: Mauro Carvalho Chehab 
Cc: Martin Schwidefsky 
Cc: linux-s390 at vger.kernel.org
Cc: Ilya Dryomov 
Cc: dri-devel at lists.freedesktop.org
Cc: linux-mtd at lists.infradead.org
Cc: Herbert Xu 
Cc: linux-crypto at vger.kernel.org
Cc: "David S. Miller" 
Cc: netdev at vger.kernel.org
Cc: Greg Kroah-Hartman 
Cc: ceph-devel at vger.kernel.org
Cc: linux-f2fs-devel at lists.sourceforge.net
Cc: linux-ext4 at vger.kernel.org
Cc: netfilter-devel at vger.kernel.org

diff --git a/Makefile b/Makefile
index 512e47a..43cd3d9 100644
--- a/Makefile
+++ b/Makefile
@@ -370,7 +370,7 @@ LDFLAGS_MODULE  =
 CFLAGS_KERNEL  =
 AFLAGS_KERNEL  =
 LDFLAGS_vmlinux =
-CFLAGS_GCOV= -fprofile-arcs -ftest-coverage -fno-tree-loop-im
+CFLAGS_GCOV= -fprofile-arcs -ftest-coverage -fno-tree-loop-im  
-Wno-maybe-uninitialized
 CFLAGS_KCOV:= $(call cc-option,-fsanitize-coverage=trace-pc,)


@@ -620,7 +620,6 @@ ARCH_CFLAGS :=
 include arch/$(SRCARCH)/Makefile

 KBUILD_CFLAGS  += $(call cc-option,-fno-delete-null-pointer-checks,)
-KBUILD_CFLAGS  += $(call cc-disable-warning,maybe-uninitialized,)
 KBUILD_CFLAGS  += $(call cc-disable-warning,frame-address,)

 ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
@@ -629,15 +628,18 @@ KBUILD_CFLAGS += $(call cc-option,-fdata-sections,)
 endif

 ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
-KBUILD_CFLAGS  += -Os
+KBUILD_CFLA

[PATCH v5 0/3] MT8173 HDMI 4K support

2016-10-18 Thread CK Hu
On Thu, 2016-09-29 at 11:02 +0800, Bibby Hsieh wrote:
> This is MT8173 HDMI 4K support PATCH v5, based on 4.8-rc1.
> 
> In order to support HDMI 4K on MT8173,
> we have to make some modifications.
> 1) Make sure that mtk_hdmi_send_infoframe is sent successfully.
> 2) Enhance the HDMI driving current to improve performance.
> 3) Make sure that pixel clock is 297MHz when resolution is 4K.
> 

For this series,
Acked-by: CK Hu 

> Changes since v4:
>  - Update commit message and patch title.
> 
> Changes since v3:
>  - Rebase to 4.8-rc1.
>  - The valid range of tvdpll is 1G to 2G Hz, so, we Change the
>if statement of mode->clock to fit that and add a comment.
> 
> Changes since v2:
>  - Remove the change about preparation for MT2701 support.
> 
> Changes since v1:
>  - According to the suggestion from philipp, We use the new
>dpi0_sel rate set method.
>  - calls clk_set_rate to set the dpi0_sel according to the
>pixel clock.
>  - Remove the direct access to all the intermediate clock part.
>  - Remove the intermediate tvdpll_d* clocks in dts.
>  - According to suggestion from CK, we rename the clock parse
>function and remove it from mtk_dpi_conf struct.
>  - Merges the hdmi Pll set rate for pixel clock greater than
>165MHz and smaller parts.
> 
> The PATCH depends on the following patch:
> https://patchwork.kernel.org/patch/9262575/
> (arm64: dts: mt8173: add mmsel clocks for 4K support)
> 
> Junzhi Zhao (3):
>   drm/mediatek: do mtk_hdmi_send_infoframe after HDMI clock enable
>   drm/mediatek: enhance the HDMI driving current
>   drm/mediatek: modify the factor to make the pll_rate set in the 1G-2G
> range
> 
>  drivers/gpu/drm/mediatek/mtk_dpi.c |9 +++--
>  drivers/gpu/drm/mediatek/mtk_hdmi.c|   17 ++
>  drivers/gpu/drm/mediatek/mtk_mt8173_hdmi_phy.c |   42 
> +---
>  3 files changed, 48 insertions(+), 20 deletions(-)
> 




[PATCH 1/3] dma-buf/fence: make timeout handling in fence_default_wait consistent

2016-10-18 Thread zhoucm1


On 2016年10月17日 21:55, Christian König wrote:
> From: Christian König 
>
> Kernel functions taking a timeout usually return 1 on success even
> when they get a zero timeout.
>
> Signen-off-by: Christian König 

The series is Reviewed-by: Chunming Zhou 

> ---
>   drivers/dma-buf/fence.c | 8 +---
>   1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
> index 4d51f9e..fb915ab 100644
> --- a/drivers/dma-buf/fence.c
> +++ b/drivers/dma-buf/fence.c
> @@ -335,18 +335,20 @@ fence_default_wait_cb(struct fence *fence, struct 
> fence_cb *cb)
>* @timeout:[in]timeout value in jiffies, or 
> MAX_SCHEDULE_TIMEOUT
>*
>* Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or the
> - * remaining timeout in jiffies on success.
> + * remaining timeout in jiffies on success. If timeout is zero the value one 
> is
> + * returned if the fence is already signaled for consistency with other
> + * functions taking a jiffies timeout.
>*/
>   signed long
>   fence_default_wait(struct fence *fence, bool intr, signed long timeout)
>   {
>   struct default_wait_cb cb;
>   unsigned long flags;
> - signed long ret = timeout;
> + signed long ret = timeout ? timeout : 1;
>   bool was_set;
>   
>   if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags))
> - return timeout;
> + return ret;
>   
>   spin_lock_irqsave(fence->lock, flags);
>   



[Bug 178221] radeon performance drop from 4.8 to 4.9-rc1 in Shadow of Mordor

2016-10-18 Thread bugzilla-dae...@bugzilla.kernel.org
https://bugzilla.kernel.org/show_bug.cgi?id=178221

Alex Deucher  changed:

   What|Removed |Added

 CC||alexdeucher at gmail.com

--- Comment #1 from Alex Deucher  ---
This was bisected to"

87744ab3832b83ba71b931f86f9cfdb000d07da5 is the first bad commit
commit 87744ab3832b83ba71b931f86f9cfdb000d07da5
Author: Dan Williams 
Date:   Fri Oct 7 17:00:18 2016 -0700

mm: fix cache mode tracking in vm_insert_mixed()

vm_insert_mixed() unlike vm_insert_pfn_prot() and vmf_insert_pfn_pmd(),
fails to check the pgprot_t it uses for the mapping against the one
recorded in the memtype tracking tree.  Add the missing call to
track_pfn_insert() to preclude cases where incompatible aliased mappings
are established for a given physical address range.

Link: http://lkml.kernel.org/r/
147328717909.35069.14256589123570653697.stgit at dwillia2-
desk3.amr.corp.intel.com
Signed-off-by: Dan Williams 
Cc: David Airlie 
Cc: Matthew Wilcox 
Cc: Ross Zwisler 
Signed-off-by: Andrew Morton 
Signed-off-by: Linus Torvalds 

Does reverting that commit fix your issue?

See:
https://lists.freedesktop.org/archives/dri-devel/2016-October/120693.html

-- 
You are receiving this mail because:
You are watching the assignee of the bug.


[PATCH 3/3] drm/imx: ipuv3-plane: Access old u/vbo properly in ->atomic_check for YU12/YV12

2016-10-18 Thread Liu Ying
Hi Philipp,

2016-10-18 0:10 GMT+08:00 Philipp Zabel :
> Hi Liu,
>
> Am Montag, den 10.10.2016, 14:50 +0800 schrieb Liu Ying:
>> Before accessing the u/v offset(aka, u/vbo for IPUv3) of the old plane 
>> state's
>> relevant fb, we should make sure the fb is in YU12 or YV12 pixel format(which
>> are the two YUV pixel formats we support only), otherwise, we are likely to
>> trigger BUG_ON() in drm_plane_state_to_u/vbo() since the fb's pixel format is
>> probably not YU12 or YV12.
>>
>> Link: https://bugs.freedesktop.org/show_bug.cgi?id=98150
>> Fixes: c6c1f9bc798b ("drm/imx: Add active plane reconfiguration support")
>> Cc: stable at vger.kernel.org # 4.8
>> Signed-off-by: Liu Ying 
>> ---
>>  drivers/gpu/drm/imx/ipuv3-plane.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/imx/ipuv3-plane.c 
>> b/drivers/gpu/drm/imx/ipuv3-plane.c
>> index e33110e..a691892 100644
>> --- a/drivers/gpu/drm/imx/ipuv3-plane.c
>> +++ b/drivers/gpu/drm/imx/ipuv3-plane.c
>> @@ -359,7 +359,7 @@ static int ipu_plane_atomic_check(struct drm_plane 
>> *plane,
>>   if ((ubo > 0xf8) || (vbo > 0xf8))
>>   return -EINVAL;
>>
>> - if (old_fb) {
>> + if (old_fb && old_fb->pixel_format == fb->pixel_format) {
>>   old_ubo = drm_plane_state_to_ubo(old_state);
>>   old_vbo = drm_plane_state_to_vbo(old_state);
>>   if (ubo != old_ubo || vbo != old_vbo)
>
> thank you for the patches. I have applied patches 1 and 2, but with this
> change UBO/VBO changes are ignored when switching from YU12 to YV12.

Good catch.  Does this change look okay, then?

-   if (old_fb) {
+   if (old_fb &&
+   (old_fb->pixel_format == DRM_FORMAT_YUV420 ||
+old_fb->pixel_format == DRM_FORMAT_YVU420)) {

>
> Shouldn't we rather set crtc_state->mode_changed = true if either
> (fb->pixel_format != old_fb->pixel_format) for any pixel format or
> (ubo != old_ubo || vbo != old_vbo) for YUV formats, instead of returning
> -EINVAL?

I thought about this and determined that this could be done
in an additional patch later.
It would be good if we change as little as we can in a patch
with stable Cced.

Regards,
Liu Ying

>
> regards
> Philipp
>
> ___
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel



-- 
Best Regards,
Liu Ying


mm: fix cache mode tracking in vm_insert_mixed() breaks AMDGPU [was: Re: Latest testing with drm-next-4.9-wip and latest LLVM/mesa stack - Regression in PowerPlay/DPM on CIK?]

2016-10-18 Thread Dave Airlie
On 18 October 2016 at 08:01, Dave Airlie  wrote:
> On 18 October 2016 at 07:25, Dan Williams  wrote:
>> On Sun, Oct 16, 2016 at 1:53 PM, Dave Airlie  wrote:
>>> On 17 October 2016 at 04:41, Marek Olšák  wrote:
 On Fri, Oct 14, 2016 at 3:33 AM, Michel Dänzer  
 wrote:
>
> [ Adding Dan Williams and dri-devel ]
>
> On 14/10/16 03:28 AM, Shawn Starr wrote:
>> Hello AMD folks,
>>
>> I have discovered a problem in Linus master that affects AMDGPU, nobody 
>> would
>> notice this in drm-next-4.9-wip since its not in this repo.
>
> [...]
>
>> 87744ab3832b83ba71b931f86f9cfdb000d07da5 is the first bad commit
>> commit 87744ab3832b83ba71b931f86f9cfdb000d07da5
>> Author: Dan Williams 
>> Date:   Fri Oct 7 17:00:18 2016 -0700
>>
>> mm: fix cache mode tracking in vm_insert_mixed()
>>
>> vm_insert_mixed() unlike vm_insert_pfn_prot() and 
>> vmf_insert_pfn_pmd(),
>> fails to check the pgprot_t it uses for the mapping against the one
>> recorded in the memtype tracking tree.  Add the missing call to
>> track_pfn_insert() to preclude cases where incompatible aliased 
>> mappings
>> are established for a given physical address range.
>>
>> Link: http://lkml.kernel.org/r/
>> 147328717909.35069.14256589123570653697.stgit at dwillia2-
>> desk3.amr.corp.intel.com
>> Signed-off-by: Dan Williams 
>> Cc: David Airlie 
>> Cc: Matthew Wilcox 
>> Cc: Ross Zwisler 
>> Signed-off-by: Andrew Morton 
>> Signed-off-by: Linus Torvalds 
>>
>> :04 04 7517c0019fe49c1830b5a1d81f1dc099c5aab98a
>> fd497a604a2af5995db2b8ed1e9c640bede6adf3 M  mm
>>
>>
>> Removal of this patch stops graphics stalls.
>
> Thanks for bisecting this Shawn.
>
>
>> A friend of mine mentions,
>>
>> "looks like a graphics thingy you depend on is requesting a mapping with 
>> a
>> not-allowed cache mode, and now you are (rightfully) getting errors?"
>
> It would be nice to get some more specific pointers what amdgpu (or
> maybe ttm, since that calls vm_insert_mixed in ttm_bo_vm_fault) might be
> doing wrong.
>>>
>>>/*
>>>  * We'd like to use VM_PFNMAP on shared mappings, where
>>>  * (vma->vm_flags & VM_SHARED) != 0, for performance reasons,
>>>  * but for some reason VM_PFNMAP + x86 PAT + write-combine is very
>>>  * bad for performance. Until that has been sorted out, use
>>>  * VM_MIXEDMAP on all mappings. See freedesktop.org bug #75719
>>>  */
>>> vma->vm_flags |= VM_MIXEDMAP;
>>>
>>> We have that comment in the ttm code, which to me implies that mixed is
>>> doing the right thing now, but that is slow, as the interface we
>>> should be using.
>>>
>>
>> Aren't there only 2 possibilities for this regression?
>>
>> 1/ a memtype entry was never made so track_pfn_insert() returns an
>> uncached mapping
>>
>> 2/ a conflicting memtype entry exists and undefined behavior due to
>> mixed mapping types is avoided with the change.
>
> 3/ The CPU usage through this path goes up, and slows things down,
> though I suspect you it's more an uncached mapping showing up
> when we don't expect it.

It's looking line number 1, there is no mapping, now we get uncached
where we used to get write through.

difference in page prot 7f7bbc0e, pfn 200e71e4,
8037, 802f

0x2f is the vma pg prot which has PWT set in it, 0x37 is the returned
pgprot which lacks that bit.

not sure where to go from here, suggestions?
Dave.


[rfc] fix for regression in pat memory tracking in 4.9-rc1

2016-10-18 Thread Dave Airlie
Okay I spent some time looking into it, and this is the result.

We have to manually insert the VRAM BAR into the pat memory tracking
table as WC. The only other way things get inserted are via ioremap,
which we never do for the whole VRAM BAR. We could in theory map
the VRAM BAR using the iomap stuff that i915 uses, but we don't
and this seems easier for now.

We have to fix up at least nouveau and radeon I think as well.

Dave.



[PATCH 1/3] x86/pat: export io memory reserve/free api.

2016-10-18 Thread Dave Airlie
From: Dave Airlie 

These functions are needed for gpu/ttm drivers to reserve the
VRAM area as write combined. In a lot of places we don't ioremap
but still need to insert pfn from it into a VMA using vm_insert_mixed,
but a recent change in mixed insertion means we need to reserve
VRAM as WC upfront, so we need these APIs exported.

Signed-off-by: Dave Airlie 
---
 arch/x86/mm/pat.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
index 170cc4f..5ce2fbb 100644
--- a/arch/x86/mm/pat.c
+++ b/arch/x86/mm/pat.c
@@ -719,6 +719,7 @@ out_free:
 out_err:
return ret;
 }
+EXPORT_SYMBOL(io_reserve_memtype);

 /**
  * io_free_memtype - Release a memory type mapping for a region of memory
@@ -729,6 +730,7 @@ void io_free_memtype(resource_size_t start, resource_size_t 
end)
 {
free_memtype(start, end);
 }
+EXPORT_SYMBOL(io_free_memtype);

 pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
unsigned long size, pgprot_t vma_prot)
-- 
2.5.5



[PATCH 3/3] amdgpu: reserve VRAM ranges in PAT memtype tables.

2016-10-18 Thread Dave Airlie
From: Dave Airlie 

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 887483b..3142d70 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -,6 +,8 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
DRM_ERROR("Failed initializing VRAM heap.\n");
return r;
}
+
+   ttm_io_reserve_memtype_wc(adev->mc.aper_base, adev->mc.aper_base + 
adev->mc.aper_size);
/* Change the size here instead of the init above so only lpfn is 
affected */
amdgpu_ttm_set_active_vram_size(adev, adev->mc.visible_vram_size);

@@ -1203,6 +1205,7 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
ttm_bo_clean_mm(&adev->mman.bdev, AMDGPU_PL_GWS);
ttm_bo_clean_mm(&adev->mman.bdev, AMDGPU_PL_OA);
ttm_bo_device_release(&adev->mman.bdev);
+   ttm_io_free_memtype(adev->mc.aper_base, adev->mc.aper_base + 
adev->mc.aper_size);
amdgpu_gart_fini(adev);
amdgpu_ttm_global_fini(adev);
adev->mman.initialized = false;
-- 
2.5.5



[PATCH 2/3] drm/ttm: add API to reserve/free WC memory.

2016-10-18 Thread Dave Airlie
From: Dave Airlie 

These will be used by drivers to reserve/free WC memory in the
PAT tracking tables, for VRAM BARs.

Signed-off-by: Dave Airlie 
---
 drivers/gpu/drm/ttm/ttm_bo_util.c | 24 
 include/drm/ttm/ttm_bo_driver.h   |  2 ++
 2 files changed, 26 insertions(+)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c 
b/drivers/gpu/drm/ttm/ttm_bo_util.c
index bf6e216..192c003 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -39,6 +39,13 @@
 #include 
 #include 

+#ifdef CONFIG_X86
+#include 
+#else
+#define io_reserve_memtype(start, end, pcm) (0)
+#define io_free_memtype(start, end)
+#endif
+
 void ttm_bo_free_old_node(struct ttm_buffer_object *bo)
 {
ttm_bo_mem_put(bo, &bo->mem);
@@ -796,3 +803,20 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
return 0;
 }
 EXPORT_SYMBOL(ttm_bo_pipeline_move);
+
+int ttm_io_reserve_memtype_wc(resource_size_t start, resource_size_t end)
+{
+   enum page_cache_mode pcm = _PAGE_CACHE_MODE_WC;
+   int ret;
+   ret = io_reserve_memtype(start, end, &pcm);
+   if (ret)
+   return ret;
+   return 0;
+}
+EXPORT_SYMBOL(ttm_io_reserve_memtype_wc);
+
+void ttm_io_free_memtype(resource_size_t start, resource_size_t end)
+{
+   io_free_memtype(start, end);
+}
+EXPORT_SYMBOL(ttm_io_free_memtype);
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 4f0a921..6b2d24e 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -1054,6 +1054,8 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
  */
 extern pgprot_t ttm_io_prot(uint32_t caching_flags, pgprot_t tmp);

+int ttm_io_reserve_memtype_wc(resource_size_t start, resource_size_t end);
+void ttm_io_free_memtype(resource_size_t start, resource_size_t end);
 extern const struct ttm_mem_type_manager_func ttm_bo_manager_func;

 #if IS_ENABLED(CONFIG_AGP)
-- 
2.5.5



linux-next: build failure after merge of the drm-intel tree

2016-10-18 Thread Daniel Vetter
On Tue, Oct 18, 2016 at 10:59:20AM +1100, Stephen Rothwell wrote:
> Hi all,
> 
> After merging the drm-intel tree, today's linux-next build (x86_64
> allmodconfig) failed like this:
> 
> drivers/gpu/drm/i915/gvt/handlers.c: In function 'render_mmio_to_ring_id':
> drivers/gpu/drm/i915/gvt/handlers.c:137:31: error: request for member 
> 'mmio_base' in something not a structure or union
>if (gvt->dev_priv->engine[i].mmio_base == reg)
>^
> drivers/gpu/drm/i915/gvt/scheduler.c: In function 'populate_shadow_context':
> drivers/gpu/drm/i915/gvt/scheduler.c:71:4: error: passing argument 1 of 
> 'intel_lr_context_size' from incompatible pointer type 
> [-Werror=incompatible-pointer-types]
> &gvt->dev_priv->engine[ring_id]);
> ^
> In file included from drivers/gpu/drm/i915/i915_drv.h:58:0,
>  from drivers/gpu/drm/i915/gvt/scheduler.c:36:
> drivers/gpu/drm/i915/intel_lrc.h:84:10: note: expected 'struct 
> intel_engine_cs *' but argument is of type 'struct intel_engine_cs **'
>  uint32_t intel_lr_context_size(struct intel_engine_cs *engine);
>   ^
> drivers/gpu/drm/i915/gvt/scheduler.c: In function 'dispatch_workload':
> drivers/gpu/drm/i915/gvt/scheduler.c:174:41: error: passing argument 1 of 
> 'i915_gem_request_alloc' from incompatible pointer type 
> [-Werror=incompatible-pointer-types]
>   workload->req = i915_gem_request_alloc(&dev_priv->engine[ring_id],
>  ^
> In file included from drivers/gpu/drm/i915/intel_ringbuffer.h:6:0,
>  from drivers/gpu/drm/i915/intel_guc.h:29,
>  from drivers/gpu/drm/i915/i915_drv.h:57,
>  from drivers/gpu/drm/i915/gvt/scheduler.c:36:
> drivers/gpu/drm/i915/i915_gem_request.h:156:1: note: expected 'struct 
> intel_engine_cs *' but argument is of type 'struct intel_engine_cs **'
>  i915_gem_request_alloc(struct intel_engine_cs *engine,
>  ^
> drivers/gpu/drm/i915/gvt/scheduler.c: In function 'update_guest_context':
> drivers/gpu/drm/i915/gvt/scheduler.c:301:4: error: passing argument 1 of 
> 'intel_lr_context_size' from incompatible pointer type 
> [-Werror=incompatible-pointer-types]
> &gvt->dev_priv->engine[ring_id]);
> ^
> In file included from drivers/gpu/drm/i915/i915_drv.h:58:0,
>  from drivers/gpu/drm/i915/gvt/scheduler.c:36:
> drivers/gpu/drm/i915/intel_lrc.h:84:10: note: expected 'struct 
> intel_engine_cs *' but argument is of type 'struct intel_engine_cs **'
>  uint32_t intel_lr_context_size(struct intel_engine_cs *engine);
>   ^
> drivers/gpu/drm/i915/gvt/execlist.c: In function 'emulate_execlist_status':
> drivers/gpu/drm/i915/gvt/execlist.c:42:33: error: request for member 
> 'mmio_base' in something not a structure or union
>   (gvt->dev_priv->engine[ring_id].mmio_base + (offset))
>  ^  
> drivers/gpu/drm/i915/gvt/execlist.c:97:19: note: in expansion of macro 
> 'execlist_ring_mmio'
>   u32 status_reg = execlist_ring_mmio(vgpu->gvt,
>^
> drivers/gpu/drm/i915/gvt/execlist.c: In function 'emulate_csb_update':
> drivers/gpu/drm/i915/gvt/execlist.c:42:33: error: request for member 
> 'mmio_base' in something not a structure or union
>   (gvt->dev_priv->engine[ring_id].mmio_base + (offset))
>  ^  
> drivers/gpu/drm/i915/gvt/execlist.c:136:23: note: in expansion of macro 
> 'execlist_ring_mmio'
>   ctx_status_ptr_reg = execlist_ring_mmio(vgpu->gvt, ring_id,
>^
> drivers/gpu/drm/i915/gvt/execlist.c:42:33: error: request for member 
> 'mmio_base' in something not a structure or union
>   (gvt->dev_priv->engine[ring_id].mmio_base + (offset))
>  ^  
> drivers/gpu/drm/i915/gvt/execlist.c:138:23: note: in expansion of macro 
> 'execlist_ring_mmio'
>   ctx_status_buf_reg = execlist_ring_mmio(vgpu->gvt, ring_id,
>^
> drivers/gpu/drm/i915/gvt/execlist.c: In function 'get_next_execlist_slot':
> drivers/gpu/drm/i915/gvt/execlist.c:42:33: error: request for member 
> 'mmio_base' in something not a structure or union
>   (gvt->dev_priv->engine[ring_id].mmio_base + (offset))
>  ^  
> drivers/gpu/drm/i915/gvt/execlist.c:248:19: note: in expansion of macro 
> 'execlist_ring_mmio'
>   u32 status_reg = execlist_ring_mmio(vgpu->gvt, ring_id,
>^
> drivers/gpu/drm/i915/gvt/execlist.c: In function 
> 'release_shadow_batch_buffer':
> drivers/gpu/drm/i915/gvt/execlist.c:501:4: warning: 
> 'drm_gem_object_unreference' is deprecated [-Wdeprecated-declarations]
> drm_gem_object_unreference(&(entry_obj->obj->base));
> ^
> In file included from drivers/gpu/drm/i915/gvt/execlist.c:35:0:
> drivers/gpu/drm/i915/i915_drv.h:2344:13: note: declared here
>  extern void drm_gem_object_unreference(struct drm_gem_object *);
>  ^
> drivers/gpu/drm/i915/gvt/execlist.c: In function 'release_shadow_wa_c

[PATCH v6] drm: Helper for lspcon in drm_dp_dual_mode

2016-10-18 Thread Jani Nikula
On Mon, 17 Oct 2016, Shashank Sharma  wrote:
> Readme: {
>   This patch-series got approved in drm-intel mailing list already.
>   Sending this one patch to dri-devel too, as this patch touches the
>   drm layer dp_dual_mode_helper implementation. Plese provide an ack
>   so that we can merge this in intel-gfx tree.
>   The full patch series and review history at:
>   https://patchwork.freedesktop.org/patch/115769/
> }

For future reference, you can add such notes after the Signed-off-by
etc. tags under a "---" line, before the "---" line for the
diffstat. It'll be automagically removed at git am.

BR,
Jani.

>
> This patch adds lspcon support in dp_dual_mode helper.
> lspcon is essentially a dp->hdmi dongle with dual personality.
>
> LS mode: It works as a passive dongle, by level shifting DP++
> signals to HDMI signals, in LS mode.
> PCON mode: It works as a protocol converter active dongle
> in pcon mode, by converting DP++ outputs to HDMI 2.0 outputs.
>
> This patch adds support for lspcon detection and mode set
> switch operations, as a dp dual mode dongle.
>
> v2: Addressed review comments from Ville
> - add adaptor id for lspcon devices (0x08), use it to identify lspcon
> - change function names
>   old: drm_lspcon_get_current_mode/drm_lspcon_change_mode
>   new: drm_lspcon_get_mode/drm_lspcon_set_mode
> - change drm_lspcon_get_mode type to int, to match
>   drm_dp_dual_mode_get_tmds_output
> - change 'err' to 'ret' to match the rest of the functions
> - remove pointless typecasting during call to dual_mode_read
> - fix the but while setting value of data, while writing lspcon mode
> - fix indentation
> - change mdelay(10) -> msleep(10)
> - return ETIMEDOUT instead of EFAULT, when lspcon mode change times out
> - Add an empty line to separate std regs macros and lspcon regs macros
>   Indent bit definition
>
> v3: Addressed review comments from Rodrigo
> - change macro name from DP_DUAL_MODE_TYPE_LSPCON to
>   DP_DUAL_MODE_TYPE_HAS_DPCD for better readability
> - change macro name from DP_DUAL_MODE_LSPCON_MODE_PCON to
>   DP_DUAL_MODE_LSPCON_MODE_PCON for better readability
> - add comment for MCA specific offsets like 0x40 and 0x41
> - remove DP_DUAL_MODE_REV_TYPE2 check while checking lspcon adapter id
>
> v4: Addressed review comments from Ville
> - Fixed indentation at few places
> - s/current_mode/mode
> - s/reqd_mode/mode
> - remove unnecessary void* cast
> - remove drm_edid.h from includes
> - Add a comment for _HAS_DPCD
> - Fix enum description, for lspcon_mode.
>
> v5: Rebase
> v6: Rebase
>
> Signed-off-by: Shashank Sharma 
> Reviewed-by: Rodrigo Vivi 
> ---
>  drivers/gpu/drm/drm_dp_dual_mode_helper.c | 103 
> ++
>  include/drm/drm_dp_dual_mode_helper.h |  26 
>  2 files changed, 129 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c 
> b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> index a7b2a75..a7aeb1e 100644
> --- a/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> +++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> @@ -148,6 +148,14 @@ static bool is_type2_adaptor(uint8_t adaptor_id)
> DP_DUAL_MODE_REV_TYPE2);
>  }
>  
> +bool is_lspcon_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN],
> + const uint8_t adaptor_id)
> +{
> + return is_hdmi_adaptor(hdmi_id) &&
> + (adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
> +  DP_DUAL_MODE_TYPE_HAS_DPCD));
> +}
> +
>  /**
>   * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor
>   * @adapter: I2C adapter for the DDC bus
> @@ -203,6 +211,8 @@ enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct 
> i2c_adapter *adapter)
>   ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_ADAPTOR_ID,
>   &adaptor_id, sizeof(adaptor_id));
>   if (ret == 0) {
> + if (is_lspcon_adaptor(hdmi_id, adaptor_id))
> + return DRM_DP_DUAL_MODE_LSPCON;
>   if (is_type2_adaptor(adaptor_id)) {
>   if (is_hdmi_adaptor(hdmi_id))
>   return DRM_DP_DUAL_MODE_TYPE2_HDMI;
> @@ -364,3 +374,96 @@ const char *drm_dp_get_dual_mode_type_name(enum 
> drm_dp_dual_mode_type type)
>   }
>  }
>  EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name);
> +
> +/**
> + * drm_lspcon_get_mode: Get LSPCON's current mode of operation by
> + * by reading offset (0x80, 0x41)
> + * @i2c_adapter: I2C-over-aux adapter
> + * @current_mode: out vaiable, current lspcon mode of operation
> + *
> + * Returns:
> + * 0 on success, sets the current_mode value to appropriate mode
> + * -error on failure
> + */
> +int drm_lspcon_get_mode(struct i2c_adapter *adapter,
> + enum drm_lspcon_mode *mode)
> +{
> + u8 data;
> + int ret = 0;
> +
> + if (!mode) {
> + DRM_ERROR("NULL input\n");
> + return -EINVAL;
> + }
> +
> + /* Read Status: i2c over aux */
> + ret = drm_dp_dual_mode_read(

[PATCH 12/15] drm: RIP mode_config->rotation_property

2016-10-18 Thread Daniel Vetter
On Tue, Oct 18, 2016 at 01:38:05AM +0300, Laurent Pinchart wrote:
> Hi Ville,
> 
> On Friday 22 Jul 2016 16:43:13 ville.syrjala at linux.intel.com wrote:
> > From: Ville Syrjälä 
> > 
> > Now that all drivers have been converted over to the per-plane rotation
> > property, we can just nuke the global rotation property.
> > 
> > Signed-off-by: Ville Syrjälä 
> 
> Stupid question, but how does this work when the hardware supports global 
> rotation only, not per-plane rotation ?

Does that exist? If so I guess we get to add a rotation property to CRTCS
(and update docs and all that).
-Daniel

> 
> > ---
> >  drivers/gpu/drm/drm_atomic.c|  6 ++
> >  drivers/gpu/drm/drm_crtc.c  | 18 --
> >  drivers/gpu/drm/drm_fb_helper.c |  7 +--
> >  include/drm/drm_crtc.h  |  7 ---
> >  4 files changed, 3 insertions(+), 35 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> > index 116f940a9267..81061fcdb984 100644
> > --- a/drivers/gpu/drm/drm_atomic.c
> > +++ b/drivers/gpu/drm/drm_atomic.c
> > @@ -709,8 +709,7 @@ int drm_atomic_plane_set_property(struct drm_plane
> > *plane, state->src_w = val;
> > } else if (property == config->prop_src_h) {
> > state->src_h = val;
> > -   } else if (property == config->rotation_property ||
> > -  property == plane->rotation_property) {
> > +   } else if (property == plane->rotation_property) {
> > if (!is_power_of_2(val & DRM_ROTATE_MASK))
> > return -EINVAL;
> > state->rotation = val;
> > @@ -768,8 +767,7 @@ drm_atomic_plane_get_property(struct drm_plane *plane,
> > *val = state->src_w;
> > } else if (property == config->prop_src_h) {
> > *val = state->src_h;
> > -   } else if (property == config->rotation_property ||
> > -  property == plane->rotation_property) {
> > +   } else if (property == plane->rotation_property) {
> > *val = state->rotation;
> > } else if (plane->funcs->atomic_get_property) {
> > return plane->funcs->atomic_get_property(plane, state, 
> property, val);
> > diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> > index 9e20a52ece7c..c1df75caf72f 100644
> > --- a/drivers/gpu/drm/drm_crtc.c
> > +++ b/drivers/gpu/drm/drm_crtc.c
> > @@ -5783,24 +5783,6 @@ void drm_mode_config_cleanup(struct drm_device *dev)
> >  }
> >  EXPORT_SYMBOL(drm_mode_config_cleanup);
> > 
> > -struct drm_property *drm_mode_create_rotation_property(struct drm_device
> > *dev, -unsigned int 
> supported_rotations)
> > -{
> > -   static const struct drm_prop_enum_list props[] = {
> > -   { DRM_ROTATE_0,   "rotate-0" },
> > -   { DRM_ROTATE_90,  "rotate-90" },
> > -   { DRM_ROTATE_180, "rotate-180" },
> > -   { DRM_ROTATE_270, "rotate-270" },
> > -   { DRM_REFLECT_X,  "reflect-x" },
> > -   { DRM_REFLECT_Y,  "reflect-y" },
> > -   };
> > -
> > -   return drm_property_create_bitmask(dev, 0, "rotation",
> > -  props, ARRAY_SIZE(props),
> > -  supported_rotations);
> > -}
> > -EXPORT_SYMBOL(drm_mode_create_rotation_property);
> > -
> >  int drm_plane_create_rotation_property(struct drm_plane *plane,
> >unsigned int rotation,
> >unsigned int supported_rotations)
> > diff --git a/drivers/gpu/drm/drm_fb_helper.c
> > b/drivers/gpu/drm/drm_fb_helper.c index ce536c0553e5..cf5f071ffae1 100644
> > --- a/drivers/gpu/drm/drm_fb_helper.c
> > +++ b/drivers/gpu/drm/drm_fb_helper.c
> > @@ -392,15 +392,10 @@ static int restore_fbdev_mode(struct drm_fb_helper
> > *fb_helper) if (plane->type != DRM_PLANE_TYPE_PRIMARY)
> > drm_plane_force_disable(plane);
> > 
> > -   if (plane->rotation_property) {
> > +   if (plane->rotation_property)
> > drm_mode_plane_set_obj_prop(plane,
> > plane->rotation_property,
> > BIT(DRM_ROTATE_0));
> > -   } else if (dev->mode_config.rotation_property) {
> > -   drm_mode_plane_set_obj_prop(plane,
> > -   dev-
> >mode_config.rotation_property,
> > -   BIT(DRM_ROTATE_0));
> > -   }
> > }
> > 
> > for (i = 0; i < fb_helper->crtc_count; i++) {
> > diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
> > index 01cf0673f6c8..00a93e44f854 100644
> > --- a/include/drm/drm_crtc.h
> > +++ b/include/drm/drm_crtc.h
> > @@ -2480,11 +2480,6 @@ struct drm_mode_config {
> >  */
> > struct drm_property *plane_type_property;
> > /**
> > -* @rotation_property: Optional property for planes or CRTCs to 
> specify
> > -* ro

mm: fix cache mode tracking in vm_insert_mixed() breaks AMDGPU [was: Re: Latest testing with drm-next-4.9-wip and latest LLVM/mesa stack - Regression in PowerPlay/DPM on CIK?]

2016-10-18 Thread Daniel Vetter
On Tue, Oct 18, 2016 at 08:01:01AM +1000, Dave Airlie wrote:
> On 18 October 2016 at 07:25, Dan Williams  wrote:
> > On Sun, Oct 16, 2016 at 1:53 PM, Dave Airlie  wrote:
> >> On 17 October 2016 at 04:41, Marek Olšák  wrote:
> >>> On Fri, Oct 14, 2016 at 3:33 AM, Michel Dänzer  
> >>> wrote:
> 
>  [ Adding Dan Williams and dri-devel ]
> 
>  On 14/10/16 03:28 AM, Shawn Starr wrote:
> > Hello AMD folks,
> >
> > I have discovered a problem in Linus master that affects AMDGPU, nobody 
> > would
> > notice this in drm-next-4.9-wip since its not in this repo.
> 
>  [...]
> 
> > 87744ab3832b83ba71b931f86f9cfdb000d07da5 is the first bad commit
> > commit 87744ab3832b83ba71b931f86f9cfdb000d07da5
> > Author: Dan Williams 
> > Date:   Fri Oct 7 17:00:18 2016 -0700
> >
> > mm: fix cache mode tracking in vm_insert_mixed()
> >
> > vm_insert_mixed() unlike vm_insert_pfn_prot() and 
> > vmf_insert_pfn_pmd(),
> > fails to check the pgprot_t it uses for the mapping against the one
> > recorded in the memtype tracking tree.  Add the missing call to
> > track_pfn_insert() to preclude cases where incompatible aliased 
> > mappings
> > are established for a given physical address range.
> >
> > Link: http://lkml.kernel.org/r/
> > 147328717909.35069.14256589123570653697.stgit at dwillia2-
> > desk3.amr.corp.intel.com
> > Signed-off-by: Dan Williams 
> > Cc: David Airlie 
> > Cc: Matthew Wilcox 
> > Cc: Ross Zwisler 
> > Signed-off-by: Andrew Morton 
> > Signed-off-by: Linus Torvalds 
> >
> > :04 04 7517c0019fe49c1830b5a1d81f1dc099c5aab98a
> > fd497a604a2af5995db2b8ed1e9c640bede6adf3 M  mm
> >
> >
> > Removal of this patch stops graphics stalls.
> 
>  Thanks for bisecting this Shawn.
> 
> 
> > A friend of mine mentions,
> >
> > "looks like a graphics thingy you depend on is requesting a mapping 
> > with a
> > not-allowed cache mode, and now you are (rightfully) getting errors?"
> 
>  It would be nice to get some more specific pointers what amdgpu (or
>  maybe ttm, since that calls vm_insert_mixed in ttm_bo_vm_fault) might be
>  doing wrong.
> >>
> >>/*
> >>  * We'd like to use VM_PFNMAP on shared mappings, where
> >>  * (vma->vm_flags & VM_SHARED) != 0, for performance reasons,
> >>  * but for some reason VM_PFNMAP + x86 PAT + write-combine is very
> >>  * bad for performance. Until that has been sorted out, use
> >>  * VM_MIXEDMAP on all mappings. See freedesktop.org bug #75719
> >>  */
> >> vma->vm_flags |= VM_MIXEDMAP;
> >>
> >> We have that comment in the ttm code, which to me implies that mixed is
> >> doing the right thing now, but that is slow, as the interface we
> >> should be using.
> >>
> >
> > Aren't there only 2 possibilities for this regression?
> >
> > 1/ a memtype entry was never made so track_pfn_insert() returns an
> > uncached mapping
> >
> > 2/ a conflicting memtype entry exists and undefined behavior due to
> > mixed mapping types is avoided with the change.
> 
> 3/ The CPU usage through this path goes up, and slows things down,
> though I suspect you it's more an uncached mapping showing up
> when we don't expect it.

Sounds reasonable, at least we (=i915 folks) known pte caching type
tracking is ridiculously expensive. In 4.9 we have our own pte walker and
upfront (at driver load) caching type checking to avoid all that. It's in
i915_mm.c, but probably should be moved into core kernel code (next to the
io_mapping stuff, which we reused as the tracking structure).
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


[PATCH] dma-buf/fence-array: fix deadlock in fence-array

2016-10-18 Thread Daniel Vetter
On Mon, Oct 17, 2016 at 05:44:48PM -0200, Gustavo Padovan wrote:
> 2016-10-17 Chris Wilson :
> 
> > On Mon, Oct 17, 2016 at 02:59:52PM -0400, Rob Clark wrote:
> > > On Mon, Oct 17, 2016 at 2:52 PM, Gustavo Padovan  
> > > wrote:
> > > > 2016-10-17 Rob Clark :
> > > >
> > > >> Currently with fence-array, we have a potential deadlock situation.  
> > > >> If we
> > > >> fence_add_callback() on an array-fence, the array-fence's lock is 
> > > >> acquired
> > > >> first, and in it's ->enable_signaling() callback, it will install cb's 
> > > >> on
> > > >> it's array-member fences, so the array-member's lock is acquired 
> > > >> second.
> > > >>
> > > >> But in the signal path, the array-member's lock is acquired first, and 
> > > >> the
> > > >> array-fence's lock acquired second.
> > > >>
> > > >> To solve that, always enabling signaling up-front (in the fence_array
> > > >> constructor) without the fence_array's lock held.
> > > >
> > > > Do we always want to enable signaling for arrays? One of the things we
> > > > removed from the Sync Framework was the need to enable signalling at
> > > > creation time.
> > > >
> > > > Just merging fencing doesn't mean you want signaling, that is supposed
> > > > to happen only when poll() is called on the sync file.
> > > 
> > > It was something Maarten suggested, as an alternative to introducing a
> > > wq into the mix or worse hacks..
> > > https://lists.freedesktop.org/archives/dri-devel/2016-October/120868.html
> > > 
> > > I think I agree with him that it is an optimization that is unlikely
> > > to be useful in the case of fence-arrays.  If you need to wait on
> > > multiple fences from different timelines, you probably aren't doing
> > > that in hw.
> > 
> > For 2 i915 fences, I definitely do not want signaling enabled at
> > creation time.
> 
> Should we add arg flags for fence_array_create()? We already have
> signal_on_any flag there. We can convert that arg to a bitfield.

The thing creating the array might not be aware of the fences contained
therein, e.g. SYNC_FILE_MERGE. Imo we really need to keep the lazy
signalling enabling properties of fences.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


[PATCH v3 5/5] drm/fsl-dcu: only init fbdev if required

2016-10-18 Thread Daniel Vetter
On Mon, Oct 17, 2016 at 02:33:21PM -0700, Stefan Agner wrote:
> There is no need to request a CMA backed framebuffer if fbdev
> emulation is not enabled.
> 
> Signed-off-by: Stefan Agner 
> ---
>  drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c 
> b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
> index e04efbe..3a5880c 100644
> --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
> +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
> @@ -87,7 +87,8 @@ static int fsl_dcu_load(struct drm_device *dev, unsigned 
> long flags)
>   goto done;
>   dev->irq_enabled = true;
>  
> - fsl_dcu_fbdev_init(dev);
> + if (IS_ENABLED(CONFIG_DRM_FBDEV_EMULATION))
> + fsl_dcu_fbdev_init(dev);

Totally not required, since this will all no-op out. Also, please nuke
that fsl_dcu_fbdv_init wrapper seems like pointless indirection.

And if there really is an issue with the cma helpers allocating an fb when
they should, then the correct fix is to fix that in the helpers, not in
the drivers.

Nack.
-Daniel
>  
>   return 0;
>  done:
> -- 
> 2.10.0
> 
> ___
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


[PATCH 18/28] drm: avoid uninitialized timestamp use in wait_vblank

2016-10-18 Thread Daniel Vetter
On Tue, Oct 18, 2016 at 01:47:24AM +0200, Mario Kleiner wrote:
> On 10/18/2016 12:13 AM, Arnd Bergmann wrote:
> > gcc warns about the timestamp in drm_wait_vblank being possibly
> > used without an initialization:
> > 
> > drivers/gpu/drm/drm_irq.c: In function 'drm_crtc_send_vblank_event':
> > drivers/gpu/drm/drm_irq.c:992:24: error: 'now.tv_usec' may be used 
> > uninitialized in this function [-Werror=maybe-uninitialized]
> > drivers/gpu/drm/drm_irq.c:1069:17: note: 'now.tv_usec' was declared here
> > drivers/gpu/drm/drm_irq.c:991:23: error: 'now.tv_sec' may be used 
> > uninitialized in this function [-Werror=maybe-uninitialized]
> > 
> > This can happen if drm_vblank_count_and_time() returns 0 in its
> > error path. To sanitize the error case, I'm changing that function
> > to return a zero timestamp when it fails.
> > 
> > Fixes: e6ae8687a87b ("drm: idiot-proof vblank")
> > Reviewed-by: David Herrmann 
> > Cc: Rob Clark 
> > Cc: Daniel Vetter 
> > Signed-off-by: Arnd Bergmann 
> > ---
> > First submitted in January 2016, second submission in February,
> > the patch is still required.

Hm, sorry I missed that.

> >  drivers/gpu/drm/drm_irq.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> > index b969a64..48a6167 100644
> > --- a/drivers/gpu/drm/drm_irq.c
> > +++ b/drivers/gpu/drm/drm_irq.c
> > @@ -952,8 +952,10 @@ static u32 drm_vblank_count_and_time(struct drm_device 
> > *dev, unsigned int pipe,
> > u32 vblank_count;
> > unsigned int seq;
> > 
> > -   if (WARN_ON(pipe >= dev->num_crtcs))
> > +   if (WARN_ON(pipe >= dev->num_crtcs)) {
> > +   *vblanktime = (struct timeval) { 0 };
> > return 0;
> > +   }
> > 
> > do {
> > seq = read_seqbegin(&vblank->seqlock);
> > 
> 
> Looks good to me.
> 
> Reviewed-by: Mario Kleiner 

Applied to drm-misc, thanks.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


[PATCH v4 3/9] drm/hisilicon/hibmc: Add support for frame buffer

2016-10-18 Thread Daniel Vetter
On Tue, Oct 18, 2016 at 12:01:18PM +0800, Rongrong Zou wrote:
> Add support for fbdev and framebuffer.
> 
> Signed-off-by: Rongrong Zou 
> ---
>  drivers/gpu/drm/hisilicon/hibmc/Makefile  |   2 +-
>  drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c   |  25 +++
>  drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h   |  25 +++
>  drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_fbdev.c | 257 
> ++
>  drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c   |  67 ++
>  5 files changed, 375 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_fbdev.c
> 
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/Makefile 
> b/drivers/gpu/drm/hisilicon/hibmc/Makefile
> index d5c40b8..810a37e 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/Makefile
> +++ b/drivers/gpu/drm/hisilicon/hibmc/Makefile
> @@ -1,5 +1,5 @@
>  ccflags-y := -Iinclude/drm
> -hibmc-drm-y := hibmc_drm_drv.o hibmc_drm_power.o hibmc_ttm.o
> +hibmc-drm-y := hibmc_drm_drv.o hibmc_drm_fbdev.o hibmc_drm_power.o 
> hibmc_ttm.o
>  
>  obj-$(CONFIG_DRM_HISI_HIBMC) +=hibmc-drm.o
>  #obj-y   += hibmc-drm.o
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c 
> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> index e118f3b..8ddb763 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> @@ -66,11 +66,31 @@ static void hibmc_disable_vblank(struct drm_device *dev, 
> unsigned int pipe)
>  
>  static int hibmc_pm_suspend(struct device *dev)
>  {
> + struct pci_dev *pdev = to_pci_dev(dev);
> + struct drm_device *drm_dev = pci_get_drvdata(pdev);
> + struct hibmc_drm_device *hidev = drm_dev->dev_private;
> +
> + if (hidev->fbdev.initialized) {

What do you need these checks for? This looks a bit fishy tbh ...

> + console_lock();
> + drm_fb_helper_set_suspend(&hidev->fbdev.helper, 1);
> + console_unlock();

drm_fb_helper_set_suspend_unlocked is the new fancy one. Please use that
one instead. Also, that has the check you might need already included,
which means you can nuke this entire function here and just call it
directly.
-Daniel

> + }
> +
>   return 0;
>  }
>  
>  static int hibmc_pm_resume(struct device *dev)
>  {
> + struct pci_dev *pdev = to_pci_dev(dev);
> + struct drm_device *drm_dev = pci_get_drvdata(pdev);
> + struct hibmc_drm_device *hidev = drm_dev->dev_private;
> +
> + if (hidev->fbdev.initialized) {
> + console_lock();
> + drm_fb_helper_set_suspend(&hidev->fbdev.helper, 0);
> + console_unlock();
> + }
> +
>   return 0;
>  }
>  
> @@ -170,6 +190,7 @@ static int hibmc_unload(struct drm_device *dev)
>  {
>   struct hibmc_drm_device *hidev = dev->dev_private;
>  
> + hibmc_fbdev_fini(hidev);
>   hibmc_hw_fini(hidev);
>   dev->dev_private = NULL;
>   return 0;
> @@ -194,6 +215,10 @@ static int hibmc_load(struct drm_device *dev, unsigned 
> long flags)
>   if (ret)
>   goto err;
>  
> + ret = hibmc_fbdev_init(hidev);
> + if (ret)
> + goto err;
> +
>   return 0;
>  
>  err:
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h 
> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
> index 00bb153..4f5887f 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
> @@ -20,9 +20,23 @@
>  #define HIBMC_DRM_DRV_H
>  
>  #include 
> +#include 
>  #include 
>  #include 
>  
> +struct hibmc_framebuffer {
> + struct drm_framebuffer fb;
> + struct drm_gem_object *obj;
> + bool is_fbdev_fb;
> +};
> +
> +struct hibmc_fbdev {
> + struct drm_fb_helper helper;
> + struct hibmc_framebuffer fb;
> + int size;
> + bool initialized;
> +};
> +
>  struct hibmc_drm_device {
>   /* hw */
>   void __iomem   *mmio;
> @@ -41,9 +55,13 @@ struct hibmc_drm_device {
>   bool initialized;
>   } ttm;
>  
> + /* fbdev */
> + struct hibmc_fbdev fbdev;
>   bool mm_inited;
>  };
>  
> +#define to_hibmc_framebuffer(x) container_of(x, struct hibmc_framebuffer, fb)
> +
>  struct hibmc_bo {
>   struct ttm_buffer_object bo;
>   struct ttm_placement placement;
> @@ -65,8 +83,15 @@ static inline struct hibmc_bo *gem_to_hibmc_bo(struct 
> drm_gem_object *gem)
>  
>  #define DRM_FILE_PAGE_OFFSET (0x1ULL >> PAGE_SHIFT)
>  
> +int hibmc_fbdev_init(struct hibmc_drm_device *hidev);
> +void hibmc_fbdev_fini(struct hibmc_drm_device *hidev);
> +
>  int hibmc_gem_create(struct drm_device *dev, u32 size, bool iskernel,
>struct drm_gem_object **obj);
> +int hibmc_framebuffer_init(struct drm_device *dev,
> +struct hibmc_framebuffer *gfb,
> +const struct drm_mode_fb_cmd2 *mode_cmd,
> +struct drm_gem_object *obj);
>  
>  int hibmc_mm_init(struct hibmc_drm_device *hibmc);
>  i

[rfc] fix for regression in pat memory tracking in 4.9-rc1

2016-10-18 Thread Daniel Vetter
On Tue, Oct 18, 2016 at 04:13:10PM +1000, Dave Airlie wrote:
> Okay I spent some time looking into it, and this is the result.
> 
> We have to manually insert the VRAM BAR into the pat memory tracking
> table as WC. The only other way things get inserted are via ioremap,
> which we never do for the whole VRAM BAR. We could in theory map
> the VRAM BAR using the iomap stuff that i915 uses, but we don't
> and this seems easier for now.
> 
> We have to fix up at least nouveau and radeon I think as well.

We have something pretty close to this in i915 already, in i915/i915_mm.c.
Our idea was to reuse struct io_mapping, since that one already tracks the
cache type for us (so that it could do the on-demand kmap stuff properly).
Extending that to writing userspace ptes was pretty straightforward. And
it has the upshot that it keeps the memtype tracking encapsulated (at
least if we'd move the helper from i915_mm.c into core).
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


[PATCH v3 1/9] drm/hisilicon/hibmc: Add hisilicon hibmc drm master driver

2016-10-18 Thread Xinliang Liu
On 14 October 2016 at 22:33, Benjamin Gaignard
 wrote:
> Just by curiosity, why using "old" TTM instead of GEM ? any particular 
> reasons ?

>From the linux kernel DRM mm doc[1] it says:
"GEM has simpler initialization and execution requirements than
 25 TTM, but has no video RAM management capabilities and is thus
limited to
 26 UMA devices."

So, I think we can't use GEM to managing video RAM.
But in fact, in this driver fb buffer is also created as an GEM object
though it use TTM to manage video RAM.
So GEM ,like its name, say mostly use for execution management ???

[1] Documentation/gpu/drm-mm.rst

-xinliang

>
> 2016-10-14 16:44 GMT+02:00 Rongrong Zou :
>> Hi Benjamin,
>>
>> Thanks for reviewing!
>>
>> Benjamin Gaignard 於 2016/10/14 16:29 寫道:
>>>
>>> [snip]
>>>
 --- /dev/null
 +++ b/drivers/gpu/drm/hisilicon/hibmc/Kconfig
 @@ -0,0 +1,15 @@
 +config DRM_HISI_HIBMC
 +   tristate "DRM Support for Hisilicon Hibmc"
 +   depends on DRM && PCI
 +   select DRM_KMS_HELPER
 +   select DRM_KMS_FB_HELPER
 +   select DRM_GEM_CMA_HELPER
 +   select DRM_KMS_CMA_HELPER
>>>
>>>
>>> since you use TTM I don't think that selecting DRM_GEM_CMA_HELPER and
>>> DRM_KMS_CMA_HELPER
>>> help you lot here.
>>> You could add configuration flags step by step in following patches
>>> that will make you needs more clear (that also true for #include)
>>
>>
>> will delete them, thanks.
>>
>>
>>>
 +   select FB_SYS_FILLRECT
 +   select FB_SYS_COPYAREA
 +   select FB_SYS_IMAGEBLIT
 +   select DRM_TTM
 +
 +   help
 + Choose this option if you have a Hisilicon Hibmc soc chipset.
 + If M is selected the module will be called hibmc-drm.
 diff --git a/drivers/gpu/drm/hisilicon/hibmc/Makefile
 b/drivers/gpu/drm/hisilicon/hibmc/Makefile
 new file mode 100644
 index 000..97cf4a0
 --- /dev/null
 +++ b/drivers/gpu/drm/hisilicon/hibmc/Makefile
 @@ -0,0 +1,5 @@
 +ccflags-y := -Iinclude/drm
 +hibmc-drm-y := hibmc_drm_drv.o hibmc_drm_power.o
 +
 +obj-$(CONFIG_DRM_HISI_HIBMC)   +=hibmc-drm.o
 +#obj-y += hibmc-drm.o
 diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
 b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
 new file mode 100644
 index 000..52c9353
 --- /dev/null
 +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
 @@ -0,0 +1,288 @@
 +/* Hisilicon Hibmc SoC drm driver
 + *
 + * Based on the bochs drm driver.
 + *
 + * Copyright (c) 2016 Huawei Limited.
 + *
 + * Author:
 + * Rongrong Zou 
>>>
>>>
>>> ".com" is missing in you email address (same typo in all other files)
>>
>>
>> will fix it in next version, thanks. :)
>>
>>>
 + * Rongrong Zou 
 + * Jianhua Li 
 + *
 + * This program is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
 + * the Free Software Foundation; either version 2 of the License, or
 + * (at your option) any later version.
 + *
 + */
 +
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
>>>
>>>
>>> cma_helpers look useless since you use TTM, no ?
>>
>>
>> I add TTM just in this version, and forgot to clean these
>> cma relevant code, will fix in next version. Thanks.
>>
>>>
 +#include 
 +
 +#include "hibmc_drm_drv.h"
 +#include "hibmc_drm_regs.h"
 +#include "hibmc_drm_power.h"
 +
>>
>>
>> Regards,
>> Rongrong
>
>
>
> --
> Benjamin Gaignard
>
> Graphic Study Group
>
> Linaro.org │ Open source software for ARM SoCs
>
> Follow Linaro: Facebook | Twitter | Blog


[PATCH v6] drm: Helper for lspcon in drm_dp_dual_mode

2016-10-18 Thread Sharma, Shashank
Ok, Sure. 
Thanks for this information, Jani. 

Regards
Shashank

-Original Message-
From: Nikula, Jani 
Sent: Tuesday, October 18, 2016 12:28 PM
To: Sharma, Shashank ; dri-devel at 
lists.freedesktop.org; airlied at redhat.com
Cc: Vetter, Daniel ; Deak, Imre ; ville.syrjala at linux.intel.com; Sharma, Shashank 
Subject: Re: [PATCH v6] drm: Helper for lspcon in drm_dp_dual_mode

On Mon, 17 Oct 2016, Shashank Sharma  wrote:
> Readme: {
>   This patch-series got approved in drm-intel mailing list already.
>   Sending this one patch to dri-devel too, as this patch touches the
>   drm layer dp_dual_mode_helper implementation. Plese provide an ack
>   so that we can merge this in intel-gfx tree.
>   The full patch series and review history at:
>   https://patchwork.freedesktop.org/patch/115769/
> }

For future reference, you can add such notes after the Signed-off-by etc. tags 
under a "---" line, before the "---" line for the diffstat. It'll be 
automagically removed at git am.

BR,
Jani.

>
> This patch adds lspcon support in dp_dual_mode helper.
> lspcon is essentially a dp->hdmi dongle with dual personality.
>
> LS mode: It works as a passive dongle, by level shifting DP++ signals 
> to HDMI signals, in LS mode.
> PCON mode: It works as a protocol converter active dongle in pcon 
> mode, by converting DP++ outputs to HDMI 2.0 outputs.
>
> This patch adds support for lspcon detection and mode set switch 
> operations, as a dp dual mode dongle.
>
> v2: Addressed review comments from Ville
> - add adaptor id for lspcon devices (0x08), use it to identify lspcon
> - change function names
>   old: drm_lspcon_get_current_mode/drm_lspcon_change_mode
>   new: drm_lspcon_get_mode/drm_lspcon_set_mode
> - change drm_lspcon_get_mode type to int, to match
>   drm_dp_dual_mode_get_tmds_output
> - change 'err' to 'ret' to match the rest of the functions
> - remove pointless typecasting during call to dual_mode_read
> - fix the but while setting value of data, while writing lspcon mode
> - fix indentation
> - change mdelay(10) -> msleep(10)
> - return ETIMEDOUT instead of EFAULT, when lspcon mode change times 
> out
> - Add an empty line to separate std regs macros and lspcon regs macros
>   Indent bit definition
>
> v3: Addressed review comments from Rodrigo
> - change macro name from DP_DUAL_MODE_TYPE_LSPCON to
>   DP_DUAL_MODE_TYPE_HAS_DPCD for better readability
> - change macro name from DP_DUAL_MODE_LSPCON_MODE_PCON to
>   DP_DUAL_MODE_LSPCON_MODE_PCON for better readability
> - add comment for MCA specific offsets like 0x40 and 0x41
> - remove DP_DUAL_MODE_REV_TYPE2 check while checking lspcon adapter id
>
> v4: Addressed review comments from Ville
> - Fixed indentation at few places
> - s/current_mode/mode
> - s/reqd_mode/mode
> - remove unnecessary void* cast
> - remove drm_edid.h from includes
> - Add a comment for _HAS_DPCD
> - Fix enum description, for lspcon_mode.
>
> v5: Rebase
> v6: Rebase
>
> Signed-off-by: Shashank Sharma 
> Reviewed-by: Rodrigo Vivi 
> ---
>  drivers/gpu/drm/drm_dp_dual_mode_helper.c | 103 
> ++
>  include/drm/drm_dp_dual_mode_helper.h |  26 
>  2 files changed, 129 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c 
> b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> index a7b2a75..a7aeb1e 100644
> --- a/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> +++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> @@ -148,6 +148,14 @@ static bool is_type2_adaptor(uint8_t adaptor_id)
> DP_DUAL_MODE_REV_TYPE2);
>  }
>  
> +bool is_lspcon_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN],
> + const uint8_t adaptor_id)
> +{
> + return is_hdmi_adaptor(hdmi_id) &&
> + (adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
> +  DP_DUAL_MODE_TYPE_HAS_DPCD));
> +}
> +
>  /**
>   * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor
>   * @adapter: I2C adapter for the DDC bus @@ -203,6 +211,8 @@ enum 
> drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter)
>   ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_ADAPTOR_ID,
>   &adaptor_id, sizeof(adaptor_id));
>   if (ret == 0) {
> + if (is_lspcon_adaptor(hdmi_id, adaptor_id))
> + return DRM_DP_DUAL_MODE_LSPCON;
>   if (is_type2_adaptor(adaptor_id)) {
>   if (is_hdmi_adaptor(hdmi_id))
>   return DRM_DP_DUAL_MODE_TYPE2_HDMI; @@ -364,3 
> +374,96 @@ const 
> char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type)
>   }
>  }
>  EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name);
> +
> +/**
> + * drm_lspcon_get_mode: Get LSPCON's current mode of operation by
> + * by reading offset (0x80, 0x41)
> + * @i2c_adapter: I2C-over-aux adapter
> + * @current_mode: out vaiable, current lspcon mode of operation
> + *
> + * Returns:
> + * 0 on success, sets the current_mode v

[PATCH v4 7/9] drm/hisilicon/hibmc: Add connector for VDAC

2016-10-18 Thread Rongrong Zou
Add connector funcs and helper funcs for VDAC.

Signed-off-by: Rongrong Zou 
---
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c  |  8 +++
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h  |  2 +
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c | 76 
 3 files changed, 86 insertions(+)

diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c 
b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
index f51e5a209..2ade5a8 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
@@ -142,6 +142,14 @@ static int hibmc_kms_init(struct hibmc_drm_device *hidev)
return ret;
}

+   ret = hibmc_connector_init(hidev);
+   if (ret) {
+   DRM_ERROR("failed to init connector\n");
+   return ret;
+   }
+
+   drm_mode_connector_attach_encoder(&hidev->connector,
+ &hidev->encoder);
return 0;
 }

diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h 
b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
index c45449b..e328fb3 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
@@ -49,6 +49,7 @@ struct hibmc_drm_device {
struct drm_plane plane;
struct drm_crtc crtc;
struct drm_encoder encoder;
+   struct drm_connector connector;
bool mode_config_initialized;

/* ttm */
@@ -90,6 +91,7 @@ static inline struct hibmc_bo *gem_to_hibmc_bo(struct 
drm_gem_object *gem)
 int hibmc_plane_init(struct hibmc_drm_device *hidev);
 int hibmc_crtc_init(struct hibmc_drm_device *hidev);
 int hibmc_encoder_init(struct hibmc_drm_device *hidev);
+int hibmc_connector_init(struct hibmc_drm_device *hidev);
 int hibmc_fbdev_init(struct hibmc_drm_device *hidev);
 void hibmc_fbdev_fini(struct hibmc_drm_device *hidev);

diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c 
b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
index 3cdd634..ca6448b 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
@@ -88,3 +88,79 @@ int hibmc_encoder_init(struct hibmc_drm_device *hidev)
return 0;
 }

+static int hibmc_connector_get_modes(struct drm_connector *connector)
+{
+   int count;
+
+   count = drm_add_modes_noedid(connector, 800, 600);
+   drm_set_preferred_mode(connector, defx, defy);
+   return count;
+}
+
+static int hibmc_connector_mode_valid(struct drm_connector *connector,
+ struct drm_display_mode *mode)
+{
+   struct hibmc_drm_device *hiprivate =
+container_of(connector, struct hibmc_drm_device, connector);
+   unsigned long size = mode->hdisplay * mode->vdisplay * 4;
+
+   if (size * 2 > hiprivate->fb_size)
+   return MODE_BAD;
+
+   return MODE_OK;
+}
+
+static struct drm_encoder *
+hibmc_connector_best_encoder(struct drm_connector *connector)
+{
+   int enc_id = connector->encoder_ids[0];
+
+   /* pick the encoder ids */
+   if (enc_id)
+   return drm_encoder_find(connector->dev, enc_id);
+
+   return NULL;
+}
+
+static enum drm_connector_status hibmc_connector_detect(struct drm_connector
+*connector, bool force)
+{
+   return connector_status_connected;
+}
+
+static const struct drm_connector_helper_funcs
+   hibmc_connector_connector_helper_funcs = {
+   .get_modes = hibmc_connector_get_modes,
+   .mode_valid = hibmc_connector_mode_valid,
+   .best_encoder = hibmc_connector_best_encoder,
+};
+
+static const struct drm_connector_funcs hibmc_connector_connector_funcs = {
+   .dpms = drm_atomic_helper_connector_dpms,
+   .detect = hibmc_connector_detect,
+   .fill_modes = drm_helper_probe_single_connector_modes,
+   .destroy = drm_connector_cleanup,
+   .reset = drm_atomic_helper_connector_reset,
+   .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
+   .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
+};
+
+int hibmc_connector_init(struct hibmc_drm_device *hidev)
+{
+   struct drm_device *dev = hidev->dev;
+   struct drm_connector *connector = &hidev->connector;
+   int ret;
+
+   ret = drm_connector_init(dev, connector,
+&hibmc_connector_connector_funcs,
+DRM_MODE_CONNECTOR_VGA);
+   if (ret) {
+   DRM_ERROR("failed to init connector\n");
+   return ret;
+   }
+   drm_connector_helper_add(connector,
+&hibmc_connector_connector_helper_funcs);
+
+   return 0;
+}
+
-- 
1.9.1



[PATCH v3 3/6] drm/bridge: analogix_dp: detect Sink PSR state after configuring the PSR

2016-10-18 Thread Zain Wang
From: Yakir Yang 

Make sure the request PSR state takes effect in analogix_dp_send_psr_spd()
function, or print the sink PSR error state if we failed to apply the
requested PSR setting.

Signed-off-by: zain wang 
Signed-off-by: Yakir Yang 
---

Changes in v3: None
Changes in v2: None

 drivers/gpu/drm/bridge/analogix/analogix_dp_core.c |  6 ++
 drivers/gpu/drm/bridge/analogix/analogix_dp_core.h |  6 --
 drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c  | 25 --
 drivers/gpu/drm/rockchip/analogix_dp-rockchip.c|  6 --
 4 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c 
b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
index bcae4dd..7faad93 100644
--- a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
+++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
@@ -124,8 +124,7 @@ int analogix_dp_enable_psr(struct device *dev)
psr_vsc.DB0 = 0;
psr_vsc.DB1 = EDP_VSC_PSR_STATE_ACTIVE | EDP_VSC_PSR_CRC_VALUES_VALID;

-   analogix_dp_send_psr_spd(dp, &psr_vsc);
-   return 0;
+   return analogix_dp_send_psr_spd(dp, &psr_vsc);
 }
 EXPORT_SYMBOL_GPL(analogix_dp_enable_psr);

@@ -147,8 +146,7 @@ int analogix_dp_disable_psr(struct device *dev)
psr_vsc.DB0 = 0;
psr_vsc.DB1 = 0;

-   analogix_dp_send_psr_spd(dp, &psr_vsc);
-   return 0;
+   return analogix_dp_send_psr_spd(dp, &psr_vsc);
 }
 EXPORT_SYMBOL_GPL(analogix_dp_disable_psr);

diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.h 
b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.h
index 5c6a288..cdc0535 100644
--- a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.h
+++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.h
@@ -20,6 +20,8 @@
 #define MAX_CR_LOOP 5
 #define MAX_EQ_LOOP 5

+#define DP_TIMEOUT_PSR_LOOP_MS msecs_to_jiffies(300)
+
 /* DP_MAX_LANE_COUNT */
 #define DPCD_ENHANCED_FRAME_CAP(x) (((x) >> 7) & 0x1)
 #define DPCD_MAX_LANE_COUNT(x) ((x) & 0x1f)
@@ -247,8 +249,8 @@ void analogix_dp_config_video_slave_mode(struct 
analogix_dp_device *dp);
 void analogix_dp_enable_scrambling(struct analogix_dp_device *dp);
 void analogix_dp_disable_scrambling(struct analogix_dp_device *dp);
 void analogix_dp_enable_psr_crc(struct analogix_dp_device *dp);
-void analogix_dp_send_psr_spd(struct analogix_dp_device *dp,
- struct edp_vsc_psr *vsc);
+int analogix_dp_send_psr_spd(struct analogix_dp_device *dp,
+struct edp_vsc_psr *vsc);
 ssize_t analogix_dp_transfer(struct analogix_dp_device *dp,
 struct drm_dp_aux_msg *msg);

diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c 
b/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c
index cd37ac0..9e1177c 100644
--- a/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c
+++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c
@@ -992,10 +992,12 @@ void analogix_dp_enable_psr_crc(struct analogix_dp_device 
*dp)
writel(PSR_VID_CRC_ENABLE, dp->reg_base + ANALOGIX_DP_CRC_CON);
 }

-void analogix_dp_send_psr_spd(struct analogix_dp_device *dp,
- struct edp_vsc_psr *vsc)
+int analogix_dp_send_psr_spd(struct analogix_dp_device *dp,
+struct edp_vsc_psr *vsc)
 {
+   unsigned long timeout;
unsigned int val;
+   u8 sink;

/* don't send info frame */
val = readl(dp->reg_base + ANALOGIX_DP_PKT_SEND_CTL);
@@ -1036,6 +1038,25 @@ void analogix_dp_send_psr_spd(struct analogix_dp_device 
*dp,
val = readl(dp->reg_base + ANALOGIX_DP_PKT_SEND_CTL);
val |= IF_EN;
writel(val, dp->reg_base + ANALOGIX_DP_PKT_SEND_CTL);
+
+   timeout = jiffies + DP_TIMEOUT_PSR_LOOP_MS;
+   while (time_before(jiffies, timeout)) {
+   val = drm_dp_dpcd_readb(&dp->aux, DP_PSR_STATUS, &sink);
+   if (val != 1) {
+   dev_err(dp->dev, "PSR_STATUS read failed ret=%d", val);
+   return -EBUSY;
+   }
+
+   if ((vsc->DB1 && sink == DP_PSR_SINK_ACTIVE_RFB) ||
+   (!vsc->DB1 && sink == DP_PSR_SINK_INACTIVE))
+   return 0;
+
+   usleep_range(1000, 1500);
+   }
+
+   dev_warn(dp->dev, "Failed to apply PSR, sink state was [%x]", sink);
+
+   return -ETIMEDOUT;
 }

 ssize_t analogix_dp_transfer(struct analogix_dp_device *dp,
diff --git a/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c 
b/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c
index e5471e7..1c2d756 100644
--- a/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c
+++ b/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c
@@ -105,7 +105,7 @@ static void analogix_dp_psr_work(struct work_struct *work)
struct rockchip_dp_device *dp =
container_of(work, typeof(*dp), psr_work);
struct drm_crtc *crtc = dp->encoder.crtc;

[PATCH v4 4/9] drm/hisilicon/hibmc: Add plane for DE

2016-10-18 Thread Rongrong Zou
Add plane funcs and helper funcs for DE.

Signed-off-by: Rongrong Zou 
---
 drivers/gpu/drm/hisilicon/hibmc/Kconfig |   1 +
 drivers/gpu/drm/hisilicon/hibmc/Makefile|   2 +-
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c  | 171 
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.h  |  29 
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c |  54 +++-
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h |   5 +
 drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c |   6 +
 7 files changed, 265 insertions(+), 3 deletions(-)
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.h

diff --git a/drivers/gpu/drm/hisilicon/hibmc/Kconfig 
b/drivers/gpu/drm/hisilicon/hibmc/Kconfig
index bcb8c18..380622a 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/Kconfig
+++ b/drivers/gpu/drm/hisilicon/hibmc/Kconfig
@@ -1,6 +1,7 @@
 config DRM_HISI_HIBMC
tristate "DRM Support for Hisilicon Hibmc"
depends on DRM && PCI
+   select DRM_KMS_HELPER
select DRM_TTM

help
diff --git a/drivers/gpu/drm/hisilicon/hibmc/Makefile 
b/drivers/gpu/drm/hisilicon/hibmc/Makefile
index 810a37e..72e107e 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/Makefile
+++ b/drivers/gpu/drm/hisilicon/hibmc/Makefile
@@ -1,5 +1,5 @@
 ccflags-y := -Iinclude/drm
-hibmc-drm-y := hibmc_drm_drv.o hibmc_drm_fbdev.o hibmc_drm_power.o hibmc_ttm.o
+hibmc-drm-y := hibmc_drm_drv.o hibmc_drm_de.o hibmc_drm_fbdev.o 
hibmc_drm_power.o hibmc_ttm.o

 obj-$(CONFIG_DRM_HISI_HIBMC)   +=hibmc-drm.o
 #obj-y += hibmc-drm.o
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c 
b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
new file mode 100644
index 000..36c4d24
--- /dev/null
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
@@ -0,0 +1,171 @@
+/* Hisilicon Hibmc SoC drm driver
+ *
+ * Based on the bochs drm driver.
+ *
+ * Copyright (c) 2016 Huawei Limited.
+ *
+ * Author:
+ * Rongrong Zou 
+ * Rongrong Zou 
+ * Jianhua Li 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "hibmc_drm_drv.h"
+#include "hibmc_drm_regs.h"
+#include "hibmc_drm_power.h"
+
+/* -- */
+
+static int hibmc_plane_atomic_check(struct drm_plane *plane,
+   struct drm_plane_state *state)
+{
+   struct drm_framebuffer *fb = state->fb;
+   struct drm_crtc *crtc = state->crtc;
+   struct drm_crtc_state *crtc_state;
+   u32 src_x = state->src_x >> 16;
+   u32 src_y = state->src_y >> 16;
+   u32 src_w = state->src_w >> 16;
+   u32 src_h = state->src_h >> 16;
+   int crtc_x = state->crtc_x;
+   int crtc_y = state->crtc_y;
+   u32 crtc_w = state->crtc_w;
+   u32 crtc_h = state->crtc_h;
+
+   if (!crtc || !fb)
+   return 0;
+
+   crtc_state = drm_atomic_get_crtc_state(state->state, crtc);
+   if (IS_ERR(crtc_state))
+   return PTR_ERR(crtc_state);
+
+   if (src_w != crtc_w || src_h != crtc_h) {
+   DRM_ERROR("Scale not support!!!\n");
+   return -EINVAL;
+   }
+
+   if (src_x + src_w > fb->width ||
+   src_y + src_h > fb->height)
+   return -EINVAL;
+
+   if (crtc_x < 0 || crtc_y < 0)
+   return -EINVAL;
+
+   if (crtc_x + crtc_w > crtc_state->adjusted_mode.hdisplay ||
+   crtc_y + crtc_h > crtc_state->adjusted_mode.vdisplay)
+   return -EINVAL;
+
+   return 0;
+}
+
+static void hibmc_plane_atomic_update(struct drm_plane *plane,
+ struct drm_plane_state *old_state)
+{
+   struct drm_plane_state  *state  = plane->state;
+   u32 reg;
+   int ret;
+   u64 gpu_addr = 0;
+   unsigned int line_l;
+   struct hibmc_drm_device *hidev =
+   (struct hibmc_drm_device *)plane->dev->dev_private;
+
+   struct hibmc_framebuffer *hibmc_fb;
+   struct hibmc_bo *bo;
+
+   hibmc_fb = to_hibmc_framebuffer(state->fb);
+   bo = gem_to_hibmc_bo(hibmc_fb->obj);
+   ret = ttm_bo_reserve(&bo->bo, true, false, NULL);
+   if (ret)
+   return;
+
+   hibmc_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr);
+   if (ret) {
+   ttm_bo_unreserve(&bo->bo);
+   return;
+   }
+
+   ttm_bo_unreserve(&bo->bo);
+
+   writel(gpu_addr, hidev->mmio + HIBMC_CRT_FB_ADDRESS);
+
+   reg = state->fb->width * (state->fb->bits_per_pixel >> 3);
+   /* now line_pad is 16 */
+   reg = PADDING(16, reg);
+
+   line_l = state->fb->width * state->fb->bits_per_pixel / 8;
+   line_l = PADDING(16, line_l);
+   

[PATCH v4 5/9] drm/hisilicon/hibmc: Add crtc for DE

2016-10-18 Thread Rongrong Zou
Add crtc funcs and helper funcs for DE.

Signed-off-by: Rongrong Zou 
---
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c  | 318 
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c |   6 +
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h |   2 +
 3 files changed, 326 insertions(+)

diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c 
b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
index 36c4d24..2c9aef0 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
@@ -23,6 +23,7 @@

 #include "hibmc_drm_drv.h"
 #include "hibmc_drm_regs.h"
+#include "hibmc_drm_de.h"
 #include "hibmc_drm_power.h"

 /* -- */
@@ -169,3 +170,320 @@ int hibmc_plane_init(struct hibmc_drm_device *hidev)
return 0;
 }

+static void hibmc_crtc_enable(struct drm_crtc *crtc)
+{
+   unsigned int reg;
+   /* power mode 0 is default. */
+   struct hibmc_drm_device *hidev = crtc->dev->dev_private;
+
+   hibmc_set_power_mode(hidev, HIBMC_PW_MODE_CTL_MODE_MODE0);
+
+   /* Enable display power gate & LOCALMEM power gate*/
+   reg = readl(hidev->mmio + HIBMC_CURRENT_GATE);
+   reg &= ~HIBMC_CURR_GATE_LOCALMEM_MASK;
+   reg &= ~HIBMC_CURR_GATE_DISPLAY_MASK;
+   reg |= HIBMC_CURR_GATE_LOCALMEM(ON);
+   reg |= HIBMC_CURR_GATE_DISPLAY(ON);
+   hibmc_set_current_gate(hidev, reg);
+   drm_crtc_vblank_on(crtc);
+}
+
+static void hibmc_crtc_disable(struct drm_crtc *crtc)
+{
+   unsigned int reg;
+   struct hibmc_drm_device *hidev = crtc->dev->dev_private;
+
+   drm_crtc_vblank_off(crtc);
+
+   hibmc_set_power_mode(hidev, HIBMC_PW_MODE_CTL_MODE_SLEEP);
+
+   /* Enable display power gate & LOCALMEM power gate*/
+   reg = readl(hidev->mmio + HIBMC_CURRENT_GATE);
+   reg &= ~HIBMC_CURR_GATE_LOCALMEM_MASK;
+   reg &= ~HIBMC_CURR_GATE_DISPLAY_MASK;
+   reg |= HIBMC_CURR_GATE_LOCALMEM(OFF);
+   reg |= HIBMC_CURR_GATE_DISPLAY(OFF);
+   hibmc_set_current_gate(hidev, reg);
+}
+
+static int hibmc_crtc_atomic_check(struct drm_crtc *crtc,
+  struct drm_crtc_state *state)
+{
+   return 0;
+}
+
+static unsigned int format_pll_reg(void)
+{
+   unsigned int pllreg = 0;
+   struct panel_pll pll = {0};
+
+   /* Note that all PLL's have the same format. Here,
+* we just use Panel PLL parameter to work out the bit
+* fields in the register.On returning a 32 bit number, the value can
+* be applied to any PLL in the calling function.
+*/
+   pllreg |= HIBMC_PLL_CTRL_BYPASS(OFF) & HIBMC_PLL_CTRL_BYPASS_MASK;
+   pllreg |= HIBMC_PLL_CTRL_POWER(ON) & HIBMC_PLL_CTRL_POWER_MASK;
+   pllreg |= HIBMC_PLL_CTRL_INPUT(OSC) & HIBMC_PLL_CTRL_INPUT_MASK;
+   pllreg |= HIBMC_PLL_CTRL_POD(pll.POD) & HIBMC_PLL_CTRL_POD_MASK;
+   pllreg |= HIBMC_PLL_CTRL_OD(pll.OD) & HIBMC_PLL_CTRL_OD_MASK;
+   pllreg |= HIBMC_PLL_CTRL_N(pll.N) & HIBMC_PLL_CTRL_N_MASK;
+   pllreg |= HIBMC_PLL_CTRL_M(pll.M) & HIBMC_PLL_CTRL_M_MASK;
+
+   return pllreg;
+}
+
+static void set_vclock_hisilicon(struct drm_device *dev, unsigned long pll)
+{
+   unsigned long tmp0, tmp1;
+   struct hibmc_drm_device *hidev = dev->dev_private;
+
+   /* 1. outer_bypass_n=0 */
+   tmp0 = readl(hidev->mmio + CRT_PLL1_HS);
+   tmp0 &= 0xBFFF;
+   writel(tmp0, hidev->mmio + CRT_PLL1_HS);
+
+   /* 2. pll_pd=1?inter_bypass=1 */
+   writel(0x2100, hidev->mmio + CRT_PLL1_HS);
+
+   /* 3. config pll */
+   writel(pll, hidev->mmio + CRT_PLL1_HS);
+
+   /* 4. delay  */
+   mdelay(1);
+
+   /* 5. pll_pd =0 */
+   tmp1 = pll & ~0x0100;
+   writel(tmp1, hidev->mmio + CRT_PLL1_HS);
+
+   /* 6. delay  */
+   mdelay(1);
+
+   /* 7. inter_bypass=0 */
+   tmp1 &= ~0x2000;
+   writel(tmp1, hidev->mmio + CRT_PLL1_HS);
+
+   /* 8. delay  */
+   mdelay(1);
+
+   /* 9. outer_bypass_n=1 */
+   tmp1 |= 0x4000;
+   writel(tmp1, hidev->mmio + CRT_PLL1_HS);
+}
+
+/* This function takes care the extra registers and bit fields required to
+ *setup a mode in board.
+ *Explanation about Display Control register:
+ *FPGA only supports 7 predefined pixel clocks, and clock select is
+ *in bit 4:0 of new register 0x802a8.
+ */
+static unsigned int display_ctrl_adjust(struct drm_device *dev,
+   struct drm_display_mode *mode,
+   unsigned int ctrl)
+{
+   unsigned long x, y;
+   unsigned long pll1; /* bit[31:0] of PLL */
+   unsigned long pll2; /* bit[63:32] of PLL */
+   struct hibmc_drm_device *hidev = dev->dev_private;
+
+   x = mode->hdisplay;
+   y = mode->vdisplay;
+
+   /* Hisilicon has to set up a new register for PLL control
+*(CRT_PLL1_HS & CRT_PLL2_HS).
+*/
+   if (x ==

[PATCH 6/6] drm: bridge/analogix: enable vop standby when entry PSR

2016-10-18 Thread Zain Wang
From: zain wang 

make VOP standby when entry PSR to save some power.

Signed-off-by: zain wang 
---
 drivers/gpu/drm/rockchip/analogix_dp-rockchip.c | 29 ++---
 drivers/gpu/drm/rockchip/rockchip_drm_drv.h |  1 +
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 19 
 3 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c 
b/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c
index 1c2d756..e0f3ed3 100644
--- a/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c
+++ b/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c
@@ -113,6 +113,13 @@ static void analogix_dp_psr_work(struct work_struct *work)
if (!crtc)
return;

+   spin_lock_irqsave(&dp->psr_lock, flags);
+   psr_state = dp->psr_state;
+   spin_unlock_irqrestore(&dp->psr_lock, flags);
+
+   if (psr_state != EDP_VSC_PSR_STATE_ACTIVE)
+   rockchip_drm_vop_set_standby(crtc, false);
+
vact_end = crtc->mode.vtotal - crtc->mode.vsync_start + 
crtc->mode.vdisplay;

ret = rockchip_drm_wait_line_flag(dp->encoder.crtc, vact_end,
@@ -122,14 +129,20 @@ static void analogix_dp_psr_work(struct work_struct *work)
return;
}

-   spin_lock_irqsave(&dp->psr_lock, flags);
-   psr_state = dp->psr_state;
-   spin_unlock_irqrestore(&dp->psr_lock, flags);
-
-   if (psr_state == EDP_VSC_PSR_STATE_ACTIVE)
-   analogix_dp_enable_psr(dp->dev);
-   else
-   analogix_dp_disable_psr(dp->dev);
+   if (psr_state == EDP_VSC_PSR_STATE_ACTIVE) {
+   ret = analogix_dp_enable_psr(dp->dev);
+   if (ret) {
+   dev_err(dp->dev, "failed to enable psr\n");
+   return;
+   }
+   rockchip_drm_vop_set_standby(crtc, true);
+   } else {
+   ret = analogix_dp_disable_psr(dp->dev);
+   if (ret) {
+   dev_err(dp->dev, "failed to disable psr\n");
+   return;
+   }
+   }
 }

 static int rockchip_dp_pre_init(struct rockchip_dp_device *dp)
diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h 
b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h
index fb6226c..7149c69 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h
@@ -74,5 +74,6 @@ void rockchip_drm_dma_detach_device(struct drm_device 
*drm_dev,
struct device *dev);
 int rockchip_drm_wait_line_flag(struct drm_crtc *crtc, unsigned int line_num,
unsigned int mstimeout);
+void rockchip_drm_vop_set_standby(struct drm_crtc *crtc, bool enabled);

 #endif /* _ROCKCHIP_DRM_DRV_H_ */
diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c 
b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
index 1740a0b..13eabda 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
@@ -1478,6 +1478,25 @@ int rockchip_drm_wait_line_flag(struct drm_crtc *crtc, 
unsigned int line_num,
 }
 EXPORT_SYMBOL(rockchip_drm_wait_line_flag);

+void rockchip_drm_vop_set_standby(struct drm_crtc *crtc, bool enabled)
+{
+   struct vop *vop = to_vop(crtc);
+
+   if (!crtc || !vop->is_enabled)
+   return;
+
+   spin_lock(&vop->reg_lock);
+
+   if (enabled)
+   VOP_CTRL_SET(vop, standby, 1);
+   else
+   VOP_CTRL_SET(vop, standby, 0);
+
+   spin_unlock(&vop->reg_lock);
+
+}
+EXPORT_SYMBOL(rockchip_drm_vop_set_standby);
+
 static int vop_bind(struct device *dev, struct device *master, void *data)
 {
struct platform_device *pdev = to_platform_device(dev);
-- 
1.9.1




[PATCH v4 1/9] drm/hisilicon/hibmc: Add hisilicon hibmc drm master driver

2016-10-18 Thread Rongrong Zou
Add DRM master driver for Hisilicon Hibmc SoC which used for
Out-of-band management. Blow is the general hardware connection,
both the Hibmc and the host CPU are on the same mother board.

+--+   +--+
|  | PCIe  |  Hibmc   |
|host CPU( |<->| display  |
|arm64,x86)|   |subsystem |
+--+   +--+

Signed-off-by: Rongrong Zou 
---
 drivers/gpu/drm/hisilicon/Kconfig |   1 +
 drivers/gpu/drm/hisilicon/Makefile|   1 +
 drivers/gpu/drm/hisilicon/hibmc/Kconfig   |   7 +
 drivers/gpu/drm/hisilicon/hibmc/Makefile  |   5 +
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c   | 270 ++
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h   |  35 +++
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_power.c |  85 +++
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_power.h |  28 +++
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h  | 212 +
 9 files changed, 644 insertions(+)
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/Kconfig
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/Makefile
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_power.c
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_power.h
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h

diff --git a/drivers/gpu/drm/hisilicon/Kconfig 
b/drivers/gpu/drm/hisilicon/Kconfig
index 558c61b..2fd2724 100644
--- a/drivers/gpu/drm/hisilicon/Kconfig
+++ b/drivers/gpu/drm/hisilicon/Kconfig
@@ -2,4 +2,5 @@
 # hisilicon drm device configuration.
 # Please keep this list sorted alphabetically

+source "drivers/gpu/drm/hisilicon/hibmc/Kconfig"
 source "drivers/gpu/drm/hisilicon/kirin/Kconfig"
diff --git a/drivers/gpu/drm/hisilicon/Makefile 
b/drivers/gpu/drm/hisilicon/Makefile
index e3f6d49..c8155bf 100644
--- a/drivers/gpu/drm/hisilicon/Makefile
+++ b/drivers/gpu/drm/hisilicon/Makefile
@@ -2,4 +2,5 @@
 # Makefile for hisilicon drm drivers.
 # Please keep this list sorted alphabetically

+obj-$(CONFIG_DRM_HISI_HIBMC) += hibmc/
 obj-$(CONFIG_DRM_HISI_KIRIN) += kirin/
diff --git a/drivers/gpu/drm/hisilicon/hibmc/Kconfig 
b/drivers/gpu/drm/hisilicon/hibmc/Kconfig
new file mode 100644
index 000..a9af90d
--- /dev/null
+++ b/drivers/gpu/drm/hisilicon/hibmc/Kconfig
@@ -0,0 +1,7 @@
+config DRM_HISI_HIBMC
+   tristate "DRM Support for Hisilicon Hibmc"
+   depends on DRM && PCI
+
+   help
+ Choose this option if you have a Hisilicon Hibmc soc chipset.
+ If M is selected the module will be called hibmc-drm.
diff --git a/drivers/gpu/drm/hisilicon/hibmc/Makefile 
b/drivers/gpu/drm/hisilicon/hibmc/Makefile
new file mode 100644
index 000..97cf4a0
--- /dev/null
+++ b/drivers/gpu/drm/hisilicon/hibmc/Makefile
@@ -0,0 +1,5 @@
+ccflags-y := -Iinclude/drm
+hibmc-drm-y := hibmc_drm_drv.o hibmc_drm_power.o
+
+obj-$(CONFIG_DRM_HISI_HIBMC)   +=hibmc-drm.o
+#obj-y += hibmc-drm.o
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c 
b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
new file mode 100644
index 000..733c0dd
--- /dev/null
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
@@ -0,0 +1,270 @@
+/* Hisilicon Hibmc SoC drm driver
+ *
+ * Based on the bochs drm driver.
+ *
+ * Copyright (c) 2016 Huawei Limited.
+ *
+ * Author:
+ * Rongrong Zou 
+ * Rongrong Zou 
+ * Jianhua Li 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ */
+
+#include 
+#include 
+
+#include "hibmc_drm_drv.h"
+#include "hibmc_drm_regs.h"
+#include "hibmc_drm_power.h"
+
+static const struct file_operations hibmc_fops = {
+   .owner  = THIS_MODULE,
+   .open   = drm_open,
+   .release= drm_release,
+   .unlocked_ioctl = drm_ioctl,
+#ifdef CONFIG_COMPAT
+   .compat_ioctl   = drm_compat_ioctl,
+#endif
+   .poll   = drm_poll,
+   .read   = drm_read,
+   .llseek = no_llseek,
+};
+
+static int hibmc_enable_vblank(struct drm_device *dev, unsigned int pipe)
+{
+   return 0;
+}
+
+static void hibmc_disable_vblank(struct drm_device *dev, unsigned int pipe)
+{
+}
+
+static struct drm_driver hibmc_driver = {
+   .fops   = &hibmc_fops,
+   .name   = "hibmc",
+   .date   = "20160828",
+   .desc   = "hibmc drm driver",
+   .major  = 1,
+   .minor  = 0,
+   .get_vblank_counter = drm_vblank_no_hw_counter,
+   .enable_vblank  = hibmc_enable_vblank,
+   .disable_vblank = hibmc_disable_vblank,
+};
+
+static int hibmc_pm_suspend(stru

[PATCH v4 0/9] Add DRM driver for Hisilicon Hibmc

2016-10-18 Thread Rongrong Zou
This patch set adds a new drm driver for Hisilicon Hibmc. Hibmc is a
BMC SoC with a display controller intergrated, usually it is used on
server for Out-of-band management purpose. In this patch set, we just
support basic function for Hibmc display subsystem. Hibmc display
subsystem is connected to host CPU by PCIe as blow:

+--+   +--+
|  | PCIe  |  Hibmc   |
|host CPU( |<->| display  |
|arm64,x86)|   |subsystem |
+--+   +--+

Hardware Detail for Hibmc display subsystem
---

  The display subsystem of Hibmc is show as bellow:
  ++  ++  ++ ++
  ||  ||  || ||
  | FB |->| DE |->|VDAC|>|external|
  ||  ||  || | VGA|
  ++  ++  ++ ++

  -DE(Display Engine) is the display controller.
  -VDAC(Video Digital-to-Analog converter) converts the RGB diaital data
  stream from DE to VGA analog signals.

Change History


Changes in v4:
  -remove unused include files, and include header file when it is needed.
  -remove unused FLAG in Kconfig: DRM_GEM_CMA_HELPER/DRM_KMS_CMA_HELPER.
  -remove drm_helper_disable_unused_functions, since we use DRIVER_ATOMIC.

Changes in v3:
  -enable KMS, in v2, only fbdev is enabled.
  -management video memory with ttm.
  -add vblank interrupt.
  -remove drm_connector_register_all() and drm_connector_unregister_all().
  -I have a basic test with igt.

Changes in v2:
  -Remove self-defined macros for bit operations.
  -Remove unused register.
  -Replace those deprecated functions with new version of them.
  -use drm_connector_register_all() to register connector after
   drm_dev_register().

The patch v2 is at
https://lists.freedesktop.org/archives/dri-devel/2016-May/108661.html

Rongrong Zou (9):
  drm/hisilicon/hibmc: Add hisilicon hibmc drm master driver
  drm/hisilicon/hibmc: Add video memory management
  drm/hisilicon/hibmc: Add support for frame buffer
  drm/hisilicon/hibmc: Add plane for DE
  drm/hisilicon/hibmc: Add crtc for DE
  drm/hisilicon/hibmc: Add encoder for VDAC
  drm/hisilicon/hibmc: Add connector for VDAC
  drm/hisilicon/hibmc: Add vblank interruput
  MAINTAINERS: Update HISILICON DRM entries

 MAINTAINERS   |   1 +
 drivers/gpu/drm/hisilicon/Kconfig |   1 +
 drivers/gpu/drm/hisilicon/Makefile|   1 +
 drivers/gpu/drm/hisilicon/hibmc/Kconfig   |   9 +
 drivers/gpu/drm/hisilicon/hibmc/Makefile  |   5 +
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c| 489 +++
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.h|  29 ++
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c   | 421 
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h   | 116 +
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_fbdev.c | 257 ++
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_power.c |  85 
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_power.h |  28 ++
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h  | 212 
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c  | 166 +++
 drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c   | 564 ++
 15 files changed, 2384 insertions(+)
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/Kconfig
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/Makefile
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.h
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_fbdev.c
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_power.c
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_power.h
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c

-- 
1.9.1



[PATCH v3 1/6] drm/bridge: analogix_dp: set psr activate/deactivate when enable/disable bridge

2016-10-18 Thread Zain Wang
From: zain wang 

There's a race between when bridge_disable and when vop_crtc_disable are called.
If the flush timer triggers a new psr work between these, we will operate eDP
without power shutdowned by bridge_disable.
In this case, moving activate/deactivate to enable/disable bridge to avoid it.

Signed-off-by: zain wang 
---

Changes in v3:
- remove changes before.
- move psr activat/deactivate to enable/disable bridge.

Changes in v2:
- add spin_lock to protect dpms_mode


 drivers/gpu/drm/rockchip/analogix_dp-rockchip.c |  4 ++--
 drivers/gpu/drm/rockchip/rockchip_drm_psr.c | 30 -
 drivers/gpu/drm/rockchip/rockchip_drm_psr.h |  4 ++--
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c |  4 
 4 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c 
b/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c
index 8548e82..e5471e7 100644
--- a/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c
+++ b/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c
@@ -159,7 +159,7 @@ static int rockchip_dp_poweron(struct analogix_dp_plat_data 
*plat_data)
return ret;
}

-   return 0;
+   return rockchip_drm_psr_activate(&dp->encoder);
 }

 static int rockchip_dp_powerdown(struct analogix_dp_plat_data *plat_data)
@@ -168,7 +168,7 @@ static int rockchip_dp_powerdown(struct 
analogix_dp_plat_data *plat_data)

clk_disable_unprepare(dp->pclk);

-   return 0;
+   return rockchip_drm_psr_deactivate(&dp->encoder);
 }

 static int rockchip_dp_get_modes(struct analogix_dp_plat_data *plat_data,
diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_psr.c 
b/drivers/gpu/drm/rockchip/rockchip_drm_psr.c
index a553e18..4c379e9 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_psr.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_psr.c
@@ -57,6 +57,24 @@ out:
return psr;
 }

+static struct psr_drv *find_psr_by_encoder(struct drm_encoder *encoder)
+{
+   struct rockchip_drm_private *drm_drv = encoder->dev->dev_private;
+   struct psr_drv *psr;
+   unsigned long flags;
+
+   spin_lock_irqsave(&drm_drv->psr_list_lock, flags);
+   list_for_each_entry(psr, &drm_drv->psr_list, list) {
+   if (psr->encoder == encoder)
+   goto out;
+   }
+   psr = ERR_PTR(-ENODEV);
+
+out:
+   spin_unlock_irqrestore(&drm_drv->psr_list_lock, flags);
+   return psr;
+}
+
 static void psr_set_state_locked(struct psr_drv *psr, enum psr_state state)
 {
/*
@@ -115,14 +133,14 @@ static void psr_flush_handler(unsigned long data)

 /**
  * rockchip_drm_psr_activate - activate PSR on the given pipe
- * @crtc: CRTC to obtain the PSR encoder
+ * @encoder: encoder to obtain the PSR encoder
  *
  * Returns:
  * Zero on success, negative errno on failure.
  */
-int rockchip_drm_psr_activate(struct drm_crtc *crtc)
+int rockchip_drm_psr_activate(struct drm_encoder *encoder)
 {
-   struct psr_drv *psr = find_psr_by_crtc(crtc);
+   struct psr_drv *psr = find_psr_by_encoder(encoder);
unsigned long flags;

if (IS_ERR(psr))
@@ -138,14 +156,14 @@ EXPORT_SYMBOL(rockchip_drm_psr_activate);

 /**
  * rockchip_drm_psr_deactivate - deactivate PSR on the given pipe
- * @crtc: CRTC to obtain the PSR encoder
+ * @encoder: encoder to obtain the PSR encoder
  *
  * Returns:
  * Zero on success, negative errno on failure.
  */
-int rockchip_drm_psr_deactivate(struct drm_crtc *crtc)
+int rockchip_drm_psr_deactivate(struct drm_encoder *encoder)
 {
-   struct psr_drv *psr = find_psr_by_crtc(crtc);
+   struct psr_drv *psr = find_psr_by_encoder(encoder);
unsigned long flags;

if (IS_ERR(psr))
diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_psr.h 
b/drivers/gpu/drm/rockchip/rockchip_drm_psr.h
index b420cf1..b1ea015 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_psr.h
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_psr.h
@@ -18,8 +18,8 @@
 void rockchip_drm_psr_flush_all(struct drm_device *dev);
 int rockchip_drm_psr_flush(struct drm_crtc *crtc);

-int rockchip_drm_psr_activate(struct drm_crtc *crtc);
-int rockchip_drm_psr_deactivate(struct drm_crtc *crtc);
+int rockchip_drm_psr_activate(struct drm_encoder *encoder);
+int rockchip_drm_psr_deactivate(struct drm_encoder *encoder);

 int rockchip_drm_psr_register(struct drm_encoder *encoder,
void (*psr_set)(struct drm_encoder *, bool enable));
diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c 
b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
index c7eba30..1740a0b 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
@@ -566,8 +566,6 @@ static void vop_crtc_disable(struct drm_crtc *crtc)

WARN_ON(vop->event);

-   rockchip_drm_psr_deactivate(&vop->crtc);
-
/*
 * We need to make sure that all windows are disabled before we
 * disable that crtc. Otherwise we might try to scan from a destroy

[PATCH v4 9/9] MAINTAINERS: Update HISILICON DRM entries

2016-10-18 Thread Rongrong Zou
Signed-off-by: Rongrong Zou 
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 1cd38a7..c063c9b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4117,6 +4117,7 @@ F:drivers/gpu/drm/gma500/

 DRM DRIVERS FOR HISILICON
 M: Xinliang Liu 
+M: Rongrong Zou 
 R: Xinwei Kong 
 R: Chen Feng 
 L: dri-devel at lists.freedesktop.org
-- 
1.9.1



[PATCH v3 2/6] drm/bridge: remove dp init from analogix_dp_bind

2016-10-18 Thread Zain Wang
From: zain wang 

phy_power_on() and analogix_dp_init_dp would be called in bridge_eanble,
so remove them from analogix_dp_bind to be clear.

Signed-off-by: zain wang 
---

Changes in v3:
- remove changes before
- remove phy_power_on() and analogix_dp_init_dp from analogix_dp_bind().

Changes in v2: None

 drivers/gpu/drm/bridge/analogix/analogix_dp_core.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c 
b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
index 001b075..bcae4dd 100644
--- a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
+++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
@@ -1389,10 +1389,6 @@ int analogix_dp_bind(struct device *dev, struct 
drm_device *drm_dev,

pm_runtime_enable(dev);

-   phy_power_on(dp->phy);
-
-   analogix_dp_init_dp(dp);
-
ret = devm_request_threaded_irq(&pdev->dev, dp->irq,
analogix_dp_hardirq,
analogix_dp_irq_thread,
-- 
1.9.1




[PATCH v4 3/9] drm/hisilicon/hibmc: Add support for frame buffer

2016-10-18 Thread Rongrong Zou
Add support for fbdev and framebuffer.

Signed-off-by: Rongrong Zou 
---
 drivers/gpu/drm/hisilicon/hibmc/Makefile  |   2 +-
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c   |  25 +++
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h   |  25 +++
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_fbdev.c | 257 ++
 drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c   |  67 ++
 5 files changed, 375 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_fbdev.c

diff --git a/drivers/gpu/drm/hisilicon/hibmc/Makefile 
b/drivers/gpu/drm/hisilicon/hibmc/Makefile
index d5c40b8..810a37e 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/Makefile
+++ b/drivers/gpu/drm/hisilicon/hibmc/Makefile
@@ -1,5 +1,5 @@
 ccflags-y := -Iinclude/drm
-hibmc-drm-y := hibmc_drm_drv.o hibmc_drm_power.o hibmc_ttm.o
+hibmc-drm-y := hibmc_drm_drv.o hibmc_drm_fbdev.o hibmc_drm_power.o hibmc_ttm.o

 obj-$(CONFIG_DRM_HISI_HIBMC)   +=hibmc-drm.o
 #obj-y += hibmc-drm.o
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c 
b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
index e118f3b..8ddb763 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
@@ -66,11 +66,31 @@ static void hibmc_disable_vblank(struct drm_device *dev, 
unsigned int pipe)

 static int hibmc_pm_suspend(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
+   struct drm_device *drm_dev = pci_get_drvdata(pdev);
+   struct hibmc_drm_device *hidev = drm_dev->dev_private;
+
+   if (hidev->fbdev.initialized) {
+   console_lock();
+   drm_fb_helper_set_suspend(&hidev->fbdev.helper, 1);
+   console_unlock();
+   }
+
return 0;
 }

 static int hibmc_pm_resume(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
+   struct drm_device *drm_dev = pci_get_drvdata(pdev);
+   struct hibmc_drm_device *hidev = drm_dev->dev_private;
+
+   if (hidev->fbdev.initialized) {
+   console_lock();
+   drm_fb_helper_set_suspend(&hidev->fbdev.helper, 0);
+   console_unlock();
+   }
+
return 0;
 }

@@ -170,6 +190,7 @@ static int hibmc_unload(struct drm_device *dev)
 {
struct hibmc_drm_device *hidev = dev->dev_private;

+   hibmc_fbdev_fini(hidev);
hibmc_hw_fini(hidev);
dev->dev_private = NULL;
return 0;
@@ -194,6 +215,10 @@ static int hibmc_load(struct drm_device *dev, unsigned 
long flags)
if (ret)
goto err;

+   ret = hibmc_fbdev_init(hidev);
+   if (ret)
+   goto err;
+
return 0;

 err:
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h 
b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
index 00bb153..4f5887f 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
@@ -20,9 +20,23 @@
 #define HIBMC_DRM_DRV_H

 #include 
+#include 
 #include 
 #include 

+struct hibmc_framebuffer {
+   struct drm_framebuffer fb;
+   struct drm_gem_object *obj;
+   bool is_fbdev_fb;
+};
+
+struct hibmc_fbdev {
+   struct drm_fb_helper helper;
+   struct hibmc_framebuffer fb;
+   int size;
+   bool initialized;
+};
+
 struct hibmc_drm_device {
/* hw */
void __iomem   *mmio;
@@ -41,9 +55,13 @@ struct hibmc_drm_device {
bool initialized;
} ttm;

+   /* fbdev */
+   struct hibmc_fbdev fbdev;
bool mm_inited;
 };

+#define to_hibmc_framebuffer(x) container_of(x, struct hibmc_framebuffer, fb)
+
 struct hibmc_bo {
struct ttm_buffer_object bo;
struct ttm_placement placement;
@@ -65,8 +83,15 @@ static inline struct hibmc_bo *gem_to_hibmc_bo(struct 
drm_gem_object *gem)

 #define DRM_FILE_PAGE_OFFSET (0x1ULL >> PAGE_SHIFT)

+int hibmc_fbdev_init(struct hibmc_drm_device *hidev);
+void hibmc_fbdev_fini(struct hibmc_drm_device *hidev);
+
 int hibmc_gem_create(struct drm_device *dev, u32 size, bool iskernel,
 struct drm_gem_object **obj);
+int hibmc_framebuffer_init(struct drm_device *dev,
+  struct hibmc_framebuffer *gfb,
+  const struct drm_mode_fb_cmd2 *mode_cmd,
+  struct drm_gem_object *obj);

 int hibmc_mm_init(struct hibmc_drm_device *hibmc);
 int hibmc_bo_pin(struct hibmc_bo *bo, u32 pl_flag, u64 *gpu_addr);
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_fbdev.c 
b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_fbdev.c
new file mode 100644
index 000..ea2d86a
--- /dev/null
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_fbdev.c
@@ -0,0 +1,257 @@
+/* Hisilicon Hibmc SoC drm driver
+ *
+ * Based on the bochs drm driver.
+ *
+ * Copyright (c) 2016 Huawei Limited.
+ *
+ * Author:
+ * Rongrong Zou 
+ * Rongrong Zou 
+ * Jianhua Li 
+ *
+ * This program is free software; you can redistribute i

[PATCH 1/3] x86/pat: export io memory reserve/free api.

2016-10-18 Thread Edward O'Callaghan
NACK,

I think you want to use 'iomap_create_wc()' instead to avoid aliasing.

Kind Regards,
Edward.

On 10/18/2016 05:13 PM, Dave Airlie wrote:
> From: Dave Airlie 
> 
> These functions are needed for gpu/ttm drivers to reserve the
> VRAM area as write combined. In a lot of places we don't ioremap
> but still need to insert pfn from it into a VMA using vm_insert_mixed,
> but a recent change in mixed insertion means we need to reserve
> VRAM as WC upfront, so we need these APIs exported.
> 
> Signed-off-by: Dave Airlie 
> ---
>  arch/x86/mm/pat.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
> index 170cc4f..5ce2fbb 100644
> --- a/arch/x86/mm/pat.c
> +++ b/arch/x86/mm/pat.c
> @@ -719,6 +719,7 @@ out_free:
>  out_err:
>   return ret;
>  }
> +EXPORT_SYMBOL(io_reserve_memtype);
>  
>  /**
>   * io_free_memtype - Release a memory type mapping for a region of memory
> @@ -729,6 +730,7 @@ void io_free_memtype(resource_size_t start, 
> resource_size_t end)
>  {
>   free_memtype(start, end);
>  }
> +EXPORT_SYMBOL(io_free_memtype);
>  
>  pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
>   unsigned long size, pgprot_t vma_prot)
> 

-- next part --
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: 
<https://lists.freedesktop.org/archives/dri-devel/attachments/20161018/ffe079b3/attachment-0001.sig>


[PATCH v3 0/6] Misc changes to Rockchip PSR drivers

2016-10-18 Thread Zain Wang
This serise of patches works for saving power on eDP PHY and VOP during PSR.

BR,
- Zain

Changes in v3:
- add new patch to support fast link training.
- add new patch to make VOP standby when entry PSR.
- Misc changes.

Changes in v2:
- add spin_lock to protect dpms_mode
- misc changes.

Yakir Yang (1):
  drm/bridge: analogix_dp: detect Sink PSR state after configuring the
PSR

zain wang (5):
  drm/bridge: analogix_dp: set psr activate/deactivate when
enable/disable bridge
  drm/bridge: remove dp init from analogix_dp_bind
  drm: bridge/analogix: switch Main-link and eDP PHY when enable/disable
psr
  drm: bridge/analogix: add fast link train for eDP
  drm: bridge/analogix: enable vop standby when entry PSR

 drivers/gpu/drm/bridge/analogix/analogix_dp_core.c | 218 +++--
 drivers/gpu/drm/bridge/analogix/analogix_dp_core.h |   7 +-
 drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c  |  25 ++-
 drivers/gpu/drm/rockchip/analogix_dp-rockchip.c|  33 +++-
 drivers/gpu/drm/rockchip/rockchip_drm_drv.h|   1 +
 drivers/gpu/drm/rockchip/rockchip_drm_psr.c|  30 ++-
 drivers/gpu/drm/rockchip/rockchip_drm_psr.h|   4 +-
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c|  23 ++-
 8 files changed, 259 insertions(+), 82 deletions(-)

-- 
1.9.1




[PATCH v3 5/6] drm: bridge/analogix: add fast link train for eDP

2016-10-18 Thread Zain Wang
From: zain wang 

we would meet a short black screen when exit PSR with the full link
training, In this case, we should use fast link train instead of full
link training.

Signed-off-by: zain wang 
---
 drivers/gpu/drm/bridge/analogix/analogix_dp_core.c | 89 +-
 drivers/gpu/drm/bridge/analogix/analogix_dp_core.h |  1 +
 2 files changed, 86 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c 
b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
index 561b644..0516621 100644
--- a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
+++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 

 #include 
 #include 
@@ -35,6 +36,8 @@

 #define to_dp(nm)  container_of(nm, struct analogix_dp_device, nm)

+static const int FAST_LINK_VERIFICATION = false;
+
 struct bridge_init {
struct i2c_client *client;
struct device_node *node;
@@ -244,6 +247,7 @@ static int analogix_dp_link_start(struct analogix_dp_device 
*dp)
usleep_range(90, 120);
}

+
/* Set training pattern 1 */
analogix_dp_set_training_pattern(dp, TRAINING_PTN1);

@@ -481,7 +485,7 @@ static int analogix_dp_process_equalizer_training(struct 
analogix_dp_device *dp)
 {
int lane, lane_count, retval;
u32 reg;
-   u8 link_align, link_status[2], adjust_request[2];
+   u8 link_align, link_status[2], adjust_request[2], spread;

usleep_range(400, 401);

@@ -524,6 +528,12 @@ static int analogix_dp_process_equalizer_training(struct 
analogix_dp_device *dp)
dev_dbg(dp->dev, "final lane count = %.2x\n",
dp->link_train.lane_count);

+   drm_dp_dpcd_readb(&dp->aux, DP_MAX_DOWNSPREAD, &spread);
+   dp->fast_train_support = (spread &
+   DP_NO_AUX_HANDSHAKE_LINK_TRAINING) ? true : false;
+   dev_dbg(dp->dev, "fast link training %s\n",
+   dp->fast_train_support ? "supported" : "unsupported");
+
/* set enhanced mode if available */
analogix_dp_set_enhanced_mode(dp);
dp->link_train.lt_state = FINISHED;
@@ -655,6 +665,75 @@ static int analogix_dp_sw_link_training(struct 
analogix_dp_device *dp)
return retval;
 }

+static int analogix_dp_full_link_train(struct analogix_dp_device *dp,
+   u32 count, u32 bwtype)
+{
+   analogix_dp_init_training(dp, count, bwtype);
+   return analogix_dp_sw_link_training(dp);
+}
+
+static int analogix_dp_fast_link_train(struct analogix_dp_device *dp)
+{
+   int lane;
+   int retval;
+   u8 link_align, link_status[2];
+   enum pll_status status;
+
+   analogix_dp_reset_macro(dp);
+
+   analogix_dp_set_link_bandwidth(dp, dp->link_train.link_rate);
+   analogix_dp_set_lane_count(dp, dp->link_train.lane_count);
+
+   for (lane = 0; lane < dp->link_train.lane_count; lane++) {
+   analogix_dp_set_lane_link_training(dp,
+   dp->link_train.training_lane[lane], lane);
+   }
+
+   retval = readx_poll_timeout(analogix_dp_get_pll_lock_status, dp, status,
+   status != PLL_UNLOCKED,
+   120, 120 * DP_TIMEOUT_LOOP_COUNT);
+
+   if (retval)
+   return retval;
+
+   /* source Set training pattern 1 */
+   analogix_dp_set_training_pattern(dp, TRAINING_PTN1);
+   usleep_range(500, 600);
+
+   analogix_dp_set_training_pattern(dp, TRAINING_PTN2);
+   usleep_range(500, 600);
+
+   /* TODO: enhanced_mode?*/
+   analogix_dp_set_training_pattern(dp, DP_NONE);
+
+   if (FAST_LINK_VERIFICATION) {
+   retval = drm_dp_dpcd_readb(&dp->aux,
+  DP_LANE_ALIGN_STATUS_UPDATED,
+  &link_align);
+   if (retval < 0)
+   return retval;
+
+   retval = drm_dp_dpcd_read(&dp->aux, DP_LANE0_1_STATUS,
+ link_status, 2);
+   if (retval < 0)
+   return retval;
+
+   if (analogix_dp_clock_recovery_ok(link_status,
+ dp->link_train.lane_count)) {
+   analogix_dp_reduce_link_rate(dp);
+   return -EIO;
+   }
+
+   if (analogix_dp_channel_eq_ok(link_status, link_align,
+ dp->link_train.lane_count)) {
+   analogix_dp_reduce_link_rate(dp);
+   return -EIO;
+   }
+   }
+
+   return 0;
+}
+
 static int analogix_dp_set_link_train(struct analogix_dp_device *dp,
  u32 count, u32 bwtype)
 {
@@ -662,11 +741,13 @@ static int analogix_dp_s

[PATCH v4 8/9] drm/hisilicon/hibmc: Add vblank interruput

2016-10-18 Thread Rongrong Zou
Add vblank interrupt.

Signed-off-by: Rongrong Zou 
---
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 47 -
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c 
b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
index 2ade5a8..5ae0e1d 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
@@ -40,16 +40,46 @@

 static int hibmc_enable_vblank(struct drm_device *dev, unsigned int pipe)
 {
+   struct hibmc_drm_device *hidev =
+   (struct hibmc_drm_device *)dev->dev_private;
+
+   writel(HIBMC_RAW_INTERRUPT_EN_VBLANK(1),
+  hidev->mmio + HIBMC_RAW_INTERRUPT_EN);
+
return 0;
 }

 static void hibmc_disable_vblank(struct drm_device *dev, unsigned int pipe)
 {
+   struct hibmc_drm_device *hidev =
+   (struct hibmc_drm_device *)dev->dev_private;
+
+   writel(HIBMC_RAW_INTERRUPT_EN_VBLANK(0),
+  hidev->mmio + HIBMC_RAW_INTERRUPT_EN);
+}
+
+irqreturn_t hibmc_drm_interrupt(int irq, void *arg)
+{
+   struct drm_device *dev = (struct drm_device *)arg;
+   struct hibmc_drm_device *hidev =
+   (struct hibmc_drm_device *)dev->dev_private;
+   struct drm_crtc *crtc = &hidev->crtc;
+   u32 status;
+
+   status = readl(hidev->mmio + HIBMC_RAW_INTERRUPT);
+
+   if (status & HIBMC_RAW_INTERRUPT_VBLANK(1)) {
+   writel(HIBMC_RAW_INTERRUPT_VBLANK(1),
+  hidev->mmio + HIBMC_RAW_INTERRUPT);
+   drm_crtc_handle_vblank(crtc);
+   }
+
+   return IRQ_HANDLED;
 }

 static struct drm_driver hibmc_driver = {
.driver_features= DRIVER_GEM | DRIVER_MODESET |
- DRIVER_ATOMIC,
+ DRIVER_ATOMIC | DRIVER_HAVE_IRQ,
.fops   = &hibmc_fops,
.name   = "hibmc",
.date   = "20160828",
@@ -63,6 +93,7 @@ static void hibmc_disable_vblank(struct drm_device *dev, 
unsigned int pipe)
.dumb_create= hibmc_dumb_create,
.dumb_map_offset= hibmc_dumb_mmap_offset,
.dumb_destroy   = drm_gem_dumb_destroy,
+   .irq_handler= hibmc_drm_interrupt,
 };

 static int hibmc_pm_suspend(struct device *dev)
@@ -282,6 +313,20 @@ static int hibmc_load(struct drm_device *dev, unsigned 
long flags)
if (ret)
goto err;

+   ret = drm_vblank_init(dev, dev->mode_config.num_crtc);
+   if (ret) {
+   DRM_ERROR("failed to initialize vblank.\n");
+   return ret;
+   }
+
+   if (pci_enable_msi(dev->pdev)) {
+   DRM_ERROR("Enabling MSI failed!\n");
+   } else {
+   ret = drm_irq_install(dev, dev->pdev->irq);
+   if (ret)
+   DRM_ERROR("install irq failed , ret = %d\n", ret);
+   }
+
/* reset all the states of crtc/plane/encoder/connector */
drm_mode_config_reset(dev);

-- 
1.9.1



[PATCH v4 2/9] drm/hisilicon/hibmc: Add video memory management

2016-10-18 Thread Rongrong Zou
Hibmc have 32m video memory which can be accessed through PCIe by host,
we use ttm to manage these memory.

Signed-off-by: Rongrong Zou 
---
 drivers/gpu/drm/hisilicon/hibmc/Kconfig |   1 +
 drivers/gpu/drm/hisilicon/hibmc/Makefile|   2 +-
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c |  11 +
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h |  45 +++
 drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 491 
 5 files changed, 549 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c

diff --git a/drivers/gpu/drm/hisilicon/hibmc/Kconfig 
b/drivers/gpu/drm/hisilicon/hibmc/Kconfig
index a9af90d..bcb8c18 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/Kconfig
+++ b/drivers/gpu/drm/hisilicon/hibmc/Kconfig
@@ -1,6 +1,7 @@
 config DRM_HISI_HIBMC
tristate "DRM Support for Hisilicon Hibmc"
depends on DRM && PCI
+   select DRM_TTM

help
  Choose this option if you have a Hisilicon Hibmc soc chipset.
diff --git a/drivers/gpu/drm/hisilicon/hibmc/Makefile 
b/drivers/gpu/drm/hisilicon/hibmc/Makefile
index 97cf4a0..d5c40b8 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/Makefile
+++ b/drivers/gpu/drm/hisilicon/hibmc/Makefile
@@ -1,5 +1,5 @@
 ccflags-y := -Iinclude/drm
-hibmc-drm-y := hibmc_drm_drv.o hibmc_drm_power.o
+hibmc-drm-y := hibmc_drm_drv.o hibmc_drm_power.o hibmc_ttm.o

 obj-$(CONFIG_DRM_HISI_HIBMC)   +=hibmc-drm.o
 #obj-y += hibmc-drm.o
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c 
b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
index 733c0dd..e118f3b 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
@@ -31,6 +31,7 @@
 #ifdef CONFIG_COMPAT
.compat_ioctl   = drm_compat_ioctl,
 #endif
+   .mmap   = hibmc_mmap,
.poll   = drm_poll,
.read   = drm_read,
.llseek = no_llseek,
@@ -46,6 +47,8 @@ static void hibmc_disable_vblank(struct drm_device *dev, 
unsigned int pipe)
 }

 static struct drm_driver hibmc_driver = {
+   .driver_features= DRIVER_GEM,
+
.fops   = &hibmc_fops,
.name   = "hibmc",
.date   = "20160828",
@@ -55,6 +58,10 @@ static void hibmc_disable_vblank(struct drm_device *dev, 
unsigned int pipe)
.get_vblank_counter = drm_vblank_no_hw_counter,
.enable_vblank  = hibmc_enable_vblank,
.disable_vblank = hibmc_disable_vblank,
+   .gem_free_object_unlocked = hibmc_gem_free_object,
+   .dumb_create= hibmc_dumb_create,
+   .dumb_map_offset= hibmc_dumb_mmap_offset,
+   .dumb_destroy   = drm_gem_dumb_destroy,
 };

 static int hibmc_pm_suspend(struct device *dev)
@@ -183,6 +190,10 @@ static int hibmc_load(struct drm_device *dev, unsigned 
long flags)
if (ret)
goto err;

+   ret = hibmc_mm_init(hidev);
+   if (ret)
+   goto err;
+
return 0;

 err:
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h 
b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
index 0037341..00bb153 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
@@ -20,6 +20,8 @@
 #define HIBMC_DRM_DRV_H

 #include 
+#include 
+#include 

 struct hibmc_drm_device {
/* hw */
@@ -30,6 +32,49 @@ struct hibmc_drm_device {

/* drm */
struct drm_device  *dev;
+
+   /* ttm */
+   struct {
+   struct drm_global_reference mem_global_ref;
+   struct ttm_bo_global_ref bo_global_ref;
+   struct ttm_bo_device bdev;
+   bool initialized;
+   } ttm;
+
+   bool mm_inited;
 };

+struct hibmc_bo {
+   struct ttm_buffer_object bo;
+   struct ttm_placement placement;
+   struct ttm_bo_kmap_obj kmap;
+   struct drm_gem_object gem;
+   struct ttm_place placements[3];
+   int pin_count;
+};
+
+static inline struct hibmc_bo *hibmc_bo(struct ttm_buffer_object *bo)
+{
+   return container_of(bo, struct hibmc_bo, bo);
+}
+
+static inline struct hibmc_bo *gem_to_hibmc_bo(struct drm_gem_object *gem)
+{
+   return container_of(gem, struct hibmc_bo, gem);
+}
+
+#define DRM_FILE_PAGE_OFFSET (0x1ULL >> PAGE_SHIFT)
+
+int hibmc_gem_create(struct drm_device *dev, u32 size, bool iskernel,
+struct drm_gem_object **obj);
+
+int hibmc_mm_init(struct hibmc_drm_device *hibmc);
+int hibmc_bo_pin(struct hibmc_bo *bo, u32 pl_flag, u64 *gpu_addr);
+void hibmc_gem_free_object(struct drm_gem_object *obj);
+int hibmc_dumb_create(struct drm_file *file, struct drm_device *dev,
+ struct drm_mode_create_dumb *args);
+int hibmc_dumb_mmap_offset(struct drm_file *file, struct drm_device *dev,
+  u32 handle, u64 *offset);
+int hibmc_mmap(struct file *filp, struct vm_area_struct *vm

[PATCH v3 4/6] drm: bridge/analogix: switch Main-link and eDP PHY when enable/disable psr

2016-10-18 Thread Zain Wang
From: zain wang 

turn off Main-link and power down eDP PHY when enable psr,
turn on Main-link and power up eDP PHY when disable psr.

Signed-off-by: zain wang 
---

Changes in v3:
- detecting PSR state at enable/disable_psr() avoid to make link training
  when sink in not PSR State.

Changes in v2:
- misc changes

 drivers/gpu/drm/bridge/analogix/analogix_dp_core.c | 123 +
 1 file changed, 76 insertions(+), 47 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c 
b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
index c4f139a..c662e5d 100644
--- a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
+++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
@@ -98,50 +98,6 @@ static int analogix_dp_detect_hpd(struct analogix_dp_device 
*dp)
return 0;
 }

-int analogix_dp_enable_psr(struct device *dev)
-{
-   struct analogix_dp_device *dp = dev_get_drvdata(dev);
-   struct edp_vsc_psr psr_vsc;
-
-   if (!dp->psr_support)
-   return -EINVAL;
-
-   /* Prepare VSC packet as per EDP 1.4 spec, Table 6.9 */
-   memset(&psr_vsc, 0, sizeof(psr_vsc));
-   psr_vsc.sdp_header.HB0 = 0;
-   psr_vsc.sdp_header.HB1 = 0x7;
-   psr_vsc.sdp_header.HB2 = 0x2;
-   psr_vsc.sdp_header.HB3 = 0x8;
-
-   psr_vsc.DB0 = 0;
-   psr_vsc.DB1 = EDP_VSC_PSR_STATE_ACTIVE | EDP_VSC_PSR_CRC_VALUES_VALID;
-
-   return analogix_dp_send_psr_spd(dp, &psr_vsc);
-}
-EXPORT_SYMBOL_GPL(analogix_dp_enable_psr);
-
-int analogix_dp_disable_psr(struct device *dev)
-{
-   struct analogix_dp_device *dp = dev_get_drvdata(dev);
-   struct edp_vsc_psr psr_vsc;
-
-   if (!dp->psr_support)
-   return -EINVAL;
-
-   /* Prepare VSC packet as per EDP 1.4 spec, Table 6.9 */
-   memset(&psr_vsc, 0, sizeof(psr_vsc));
-   psr_vsc.sdp_header.HB0 = 0;
-   psr_vsc.sdp_header.HB1 = 0x7;
-   psr_vsc.sdp_header.HB2 = 0x2;
-   psr_vsc.sdp_header.HB3 = 0x8;
-
-   psr_vsc.DB0 = 0;
-   psr_vsc.DB1 = 0;
-
-   return analogix_dp_send_psr_spd(dp, &psr_vsc);
-}
-EXPORT_SYMBOL_GPL(analogix_dp_disable_psr);
-
 static bool analogix_dp_detect_sink_psr(struct analogix_dp_device *dp)
 {
unsigned char psr_version;
@@ -162,12 +118,11 @@ static void analogix_dp_enable_sink_psr(struct 
analogix_dp_device *dp)
drm_dp_dpcd_writeb(&dp->aux, DP_PSR_EN_CFG, psr_en);

/* Main-Link transmitter remains active during PSR active states */
-   psr_en = DP_PSR_MAIN_LINK_ACTIVE | DP_PSR_CRC_VERIFICATION;
+   psr_en = DP_PSR_CRC_VERIFICATION;
drm_dp_dpcd_writeb(&dp->aux, DP_PSR_EN_CFG, psr_en);

/* Enable psr function */
-   psr_en = DP_PSR_ENABLE | DP_PSR_MAIN_LINK_ACTIVE |
-DP_PSR_CRC_VERIFICATION;
+   psr_en = DP_PSR_ENABLE | DP_PSR_CRC_VERIFICATION;
drm_dp_dpcd_writeb(&dp->aux, DP_PSR_EN_CFG, psr_en);

analogix_dp_enable_psr_crc(dp);
@@ -870,6 +825,80 @@ static void analogix_dp_commit(struct analogix_dp_device 
*dp)
analogix_dp_enable_sink_psr(dp);
 }

+int analogix_dp_enable_psr(struct device *dev)
+{
+   struct analogix_dp_device *dp = dev_get_drvdata(dev);
+   struct edp_vsc_psr psr_vsc;
+   int retval;
+   u8 sink;
+
+   if (!dp->psr_support)
+   return -EINVAL;
+
+   drm_dp_dpcd_readb(&dp->aux, DP_PSR_STATUS, &sink);
+   if (sink == DP_PSR_SINK_ACTIVE_RFB)
+   return 0;
+
+   /* Prepare VSC packet as per EDP 1.4 spec, Table 6.9 */
+   memset(&psr_vsc, 0, sizeof(psr_vsc));
+   psr_vsc.sdp_header.HB0 = 0;
+   psr_vsc.sdp_header.HB1 = 0x7;
+   psr_vsc.sdp_header.HB2 = 0x2;
+   psr_vsc.sdp_header.HB3 = 0x8;
+
+   psr_vsc.DB0 = 0;
+   psr_vsc.DB1 = EDP_VSC_PSR_STATE_ACTIVE | EDP_VSC_PSR_CRC_VALUES_VALID;
+
+   retval = analogix_dp_send_psr_spd(dp, &psr_vsc);
+
+   if (!retval) {
+   /* Power down the eDP PHY */
+   analogix_dp_set_analog_power_down(dp, POWER_ALL, true);
+   }
+
+   return retval;
+}
+EXPORT_SYMBOL_GPL(analogix_dp_enable_psr);
+
+int analogix_dp_disable_psr(struct device *dev)
+{
+   struct analogix_dp_device *dp = dev_get_drvdata(dev);
+   struct edp_vsc_psr psr_vsc;
+   int ret;
+   u8 sink;
+
+   if (!dp->psr_support)
+   return -EINVAL;
+
+   /* Power up the eDP PHY */
+   analogix_dp_set_analog_power_down(dp, POWER_ALL, false);
+
+   drm_dp_dpcd_readb(&dp->aux, DP_PSR_STATUS, &sink);
+   if (sink == DP_PSR_SINK_INACTIVE)
+   return 0;
+
+   ret = drm_dp_dpcd_writeb(&dp->aux, DP_SET_POWER, DP_SET_POWER_D0);
+   if (ret < 0) {
+   dev_err(dp->dev, "Failed to set DP Power0\n");
+   }
+
+   analogix_dp_set_link_train(dp, dp->video_info.max_lane_count,
+  dp->video_info.max_link_rate);
+
+   /* Prepare VSC packet as per EDP 1.4 spec, Table 6.9 */
+   memset(&psr_vsc

[PATCH v4 6/9] drm/hisilicon/hibmc: Add encoder for VDAC

2016-10-18 Thread Rongrong Zou
Add encoder funcs and helpers for VDAC.

Signed-off-by: Rongrong Zou 
---
 drivers/gpu/drm/hisilicon/hibmc/Makefile |  2 +-
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c  |  6 ++
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h  |  2 +
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c | 90 
 4 files changed, 99 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c

diff --git a/drivers/gpu/drm/hisilicon/hibmc/Makefile 
b/drivers/gpu/drm/hisilicon/hibmc/Makefile
index 72e107e..e04f114 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/Makefile
+++ b/drivers/gpu/drm/hisilicon/hibmc/Makefile
@@ -1,5 +1,5 @@
 ccflags-y := -Iinclude/drm
-hibmc-drm-y := hibmc_drm_drv.o hibmc_drm_de.o hibmc_drm_fbdev.o 
hibmc_drm_power.o hibmc_ttm.o
+hibmc-drm-y := hibmc_drm_drv.o hibmc_drm_de.o hibmc_drm_vdac.o 
hibmc_drm_fbdev.o hibmc_drm_power.o hibmc_ttm.o

 obj-$(CONFIG_DRM_HISI_HIBMC)   +=hibmc-drm.o
 #obj-y += hibmc-drm.o
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c 
b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
index 748f6b1..f51e5a209 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
@@ -136,6 +136,12 @@ static int hibmc_kms_init(struct hibmc_drm_device *hidev)
return ret;
}

+   ret = hibmc_encoder_init(hidev);
+   if (ret) {
+   DRM_ERROR("failed to init encoder\n");
+   return ret;
+   }
+
return 0;
 }

diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h 
b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
index 9b83201..c45449b 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
@@ -48,6 +48,7 @@ struct hibmc_drm_device {
struct drm_device  *dev;
struct drm_plane plane;
struct drm_crtc crtc;
+   struct drm_encoder encoder;
bool mode_config_initialized;

/* ttm */
@@ -88,6 +89,7 @@ static inline struct hibmc_bo *gem_to_hibmc_bo(struct 
drm_gem_object *gem)

 int hibmc_plane_init(struct hibmc_drm_device *hidev);
 int hibmc_crtc_init(struct hibmc_drm_device *hidev);
+int hibmc_encoder_init(struct hibmc_drm_device *hidev);
 int hibmc_fbdev_init(struct hibmc_drm_device *hidev);
 void hibmc_fbdev_fini(struct hibmc_drm_device *hidev);

diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c 
b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
new file mode 100644
index 000..3cdd634
--- /dev/null
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
@@ -0,0 +1,90 @@
+/* Hisilicon Hibmc SoC drm driver
+ *
+ * Based on the bochs drm driver.
+ *
+ * Copyright (c) 2016 Huawei Limited.
+ *
+ * Author:
+ * Rongrong Zou 
+ * Rongrong Zou 
+ * Jianhua Li 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ */
+
+#include 
+#include 
+
+#include "hibmc_drm_drv.h"
+#include "hibmc_drm_regs.h"
+
+static int defx = 800;
+static int defy = 600;
+
+module_param(defx, int, 0444);
+module_param(defy, int, 0444);
+MODULE_PARM_DESC(defx, "default x resolution");
+MODULE_PARM_DESC(defy, "default y resolution");
+
+static void hibmc_encoder_disable(struct drm_encoder *encoder)
+{
+}
+
+static void hibmc_encoder_enable(struct drm_encoder *encoder)
+{
+}
+
+static void hibmc_encoder_mode_set(struct drm_encoder *encoder,
+  struct drm_display_mode *mode,
+  struct drm_display_mode *adj_mode)
+{
+   u32 reg;
+   struct drm_device *dev = encoder->dev;
+   struct hibmc_drm_device *hidev = dev->dev_private;
+
+   /* just open DISPLAY_CONTROL_HISILE register bit 3:0*/
+   reg = readl(hidev->mmio + DISPLAY_CONTROL_HISILE);
+   reg |= 0xf;
+   writel(reg, hidev->mmio + DISPLAY_CONTROL_HISILE);
+}
+
+static int hibmc_encoder_atomic_check(struct drm_encoder *encoder,
+ struct drm_crtc_state *crtc_state,
+ struct drm_connector_state *conn_state)
+{
+   return 0;
+}
+
+static const struct drm_encoder_helper_funcs hibmc_encoder_helper_funcs = {
+   .mode_set = hibmc_encoder_mode_set,
+   .disable = hibmc_encoder_disable,
+   .enable = hibmc_encoder_enable,
+   .atomic_check = hibmc_encoder_atomic_check,
+};
+
+static const struct drm_encoder_funcs hibmc_encoder_encoder_funcs = {
+   .destroy = drm_encoder_cleanup,
+};
+
+int hibmc_encoder_init(struct hibmc_drm_device *hidev)
+{
+   struct drm_device *dev = hidev->dev;
+   struct drm_encoder *encoder = &hidev->encoder;
+   int ret;
+
+   encoder->possible_crtcs = 0x1;
+   ret = drm_encoder_init(dev, encoder, &hibmc_encoder_encoder_funcs,
+  

[PATCH 12/15] drm: RIP mode_config->rotation_property

2016-10-18 Thread Laurent Pinchart
Hi Daniel,

On Tuesday 18 Oct 2016 09:36:23 Daniel Vetter wrote:
> On Tue, Oct 18, 2016 at 01:38:05AM +0300, Laurent Pinchart wrote:
> > On Friday 22 Jul 2016 16:43:13 ville.syrjala at linux.intel.com wrote:
> >> From: Ville Syrjälä 
> >> 
> >> Now that all drivers have been converted over to the per-plane rotation
> >> property, we can just nuke the global rotation property.
> >> 
> >> Signed-off-by: Ville Syrjälä 
> > 
> > Stupid question, but how does this work when the hardware supports global
> > rotation only, not per-plane rotation ?
> 
> Does that exist? If so I guess we get to add a rotation property to CRTCS
> (and update docs and all that).

I have a hardware composer that performs rotation on the output side. At the 
moment it doesn't support rotation when used with the display, but I wouldn't 
rule that out in future SoC versions. So I'm not aware of any use case for a 
rotation property on the CRTC at the moment, I just wanted to make sure we 
have a path forward.

-- 
Regards,

Laurent Pinchart



[PATCH v2] drm/mediatek: fix a typo

2016-10-18 Thread Bibby Hsieh
If we want to set the hardware OD to relay mode,
we have to set OD_CFG register rather than
OD_RELAYMODE; otherwise, the system will access
the wrong address.

Fixes: 7216436420414144646f5d8343d061355fd23483 ("drm/mediatek: set mt8173 
dithering function")
Cc: stable at vger.kernel.org # v4.9+
Signed-off-by: Bibby Hsieh 
---
 drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c 
b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
index df33b3c..aa5f20f 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
@@ -123,7 +123,7 @@ static void mtk_od_config(struct mtk_ddp_comp *comp, 
unsigned int w,
  unsigned int bpc)
 {
writel(w << 16 | h, comp->regs + DISP_OD_SIZE);
-   writel(OD_RELAYMODE, comp->regs + OD_RELAYMODE);
+   writel(OD_RELAYMODE, comp->regs + OD_CFG);
mtk_dither_set(comp, bpc, DISP_OD_CFG);
 }

-- 
1.7.9.5



[PATCH 1/3] x86/pat: export io memory reserve/free api.

2016-10-18 Thread Dave Airlie
On 18 Oct. 2016 17:23, "Edward O'Callaghan" 
wrote:
>
> NACK,
>
> I think you want to use 'iomap_create_wc()' instead to avoid aliasing.

Please explain what can alias here?

Dave.

>
> Kind Regards,
> Edward.
>
> On 10/18/2016 05:13 PM, Dave Airlie wrote:
> > From: Dave Airlie 
> >
> > These functions are needed for gpu/ttm drivers to reserve the
> > VRAM area as write combined. In a lot of places we don't ioremap
> > but still need to insert pfn from it into a VMA using vm_insert_mixed,
> > but a recent change in mixed insertion means we need to reserve
> > VRAM as WC upfront, so we need these APIs exported.
> >
> > Signed-off-by: Dave Airlie 
> > ---
> >  arch/x86/mm/pat.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
> > index 170cc4f..5ce2fbb 100644
> > --- a/arch/x86/mm/pat.c
> > +++ b/arch/x86/mm/pat.c
> > @@ -719,6 +719,7 @@ out_free:
> >  out_err:
> >   return ret;
> >  }
> > +EXPORT_SYMBOL(io_reserve_memtype);
> >
> >  /**
> >   * io_free_memtype - Release a memory type mapping for a region of
memory
> > @@ -729,6 +730,7 @@ void io_free_memtype(resource_size_t start,
resource_size_t end)
> >  {
> >   free_memtype(start, end);
> >  }
> > +EXPORT_SYMBOL(io_free_memtype);
> >
> >  pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
> >   unsigned long size, pgprot_t vma_prot)
> >
>
-- next part --
An HTML attachment was scrubbed...
URL: 
<https://lists.freedesktop.org/archives/dri-devel/attachments/20161018/434ffdbf/attachment.html>


[PATCH 3/3] drm/imx: ipuv3-plane: Access old u/vbo properly in ->atomic_check for YU12/YV12

2016-10-18 Thread Philipp Zabel
Am Dienstag, den 18.10.2016, 11:39 +0800 schrieb Liu Ying:
[...]
> >> @@ -359,7 +359,7 @@ static int ipu_plane_atomic_check(struct drm_plane 
> >> *plane,
> >>   if ((ubo > 0xf8) || (vbo > 0xf8))
> >>   return -EINVAL;
> >>
> >> - if (old_fb) {
> >> + if (old_fb && old_fb->pixel_format == fb->pixel_format) {
> >>   old_ubo = drm_plane_state_to_ubo(old_state);
> >>   old_vbo = drm_plane_state_to_vbo(old_state);
> >>   if (ubo != old_ubo || vbo != old_vbo)
> >
> > thank you for the patches. I have applied patches 1 and 2, but with this
> > change UBO/VBO changes are ignored when switching from YU12 to YV12.
> 
> Good catch.  Does this change look okay, then?
> 
> -   if (old_fb) {
> +   if (old_fb &&
> +   (old_fb->pixel_format == DRM_FORMAT_YUV420 ||
> +old_fb->pixel_format == DRM_FORMAT_YVU420)) {
> 
> >
> > Shouldn't we rather set crtc_state->mode_changed = true if either
> > (fb->pixel_format != old_fb->pixel_format) for any pixel format or
> > (ubo != old_ubo || vbo != old_vbo) for YUV formats, instead of returning
> > -EINVAL?
> 
> I thought about this and determined that this could be done
> in an additional patch later.
> It would be good if we change as little as we can in a patch
> with stable Cced.

Alright, the change you suggest above should work then.

regards
Philipp



[PATCH 4/5] drm/sun4i: Compute TCON1 mode from tv mode

2016-10-18 Thread Maxime Ripard
Since the mode passed in mode_set is probably going to be a scaled down
version of the TV mode, we cannot just use it.

Instead, try to retrieve the actual mode we want to set, and generate a drm
mode from that.

Signed-off-by: Maxime Ripard 
---
 drivers/gpu/drm/sun4i/sun4i_tv.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/sun4i/sun4i_tv.c b/drivers/gpu/drm/sun4i/sun4i_tv.c
index 6f8077013be3..f99886462cb8 100644
--- a/drivers/gpu/drm/sun4i/sun4i_tv.c
+++ b/drivers/gpu/drm/sun4i/sun4i_tv.c
@@ -401,8 +401,13 @@ static void sun4i_tv_mode_set(struct drm_encoder *encoder,
struct sun4i_drv *drv = tv->drv;
struct sun4i_tcon *tcon = drv->tcon;
const struct tv_mode *tv_mode = sun4i_tv_find_tv_by_mode(mode);
+   struct drm_display_mode tv_drm_mode = { 0 };

-   sun4i_tcon1_mode_set(tcon, mode);
+   strcpy(tv_drm_mode.name, "TV");
+   sun4i_tv_mode_to_drm_mode(tv_mode, &tv_drm_mode);
+   drm_mode_set_crtcinfo(&tv_drm_mode, CRTC_INTERLACE_HALVE_V);
+
+   sun4i_tcon1_mode_set(tcon, &tv_drm_mode);

/* Enable and map the DAC to the output */
regmap_update_bits(tv->regs, SUN4I_TVE_EN_REG,
-- 
git-series 0.8.10


[PATCH 1/5] drm/modes: Rewrite the command line parser

2016-10-18 Thread Maxime Ripard
Rewrite the command line parser in order to get away from the state machine
parsing the video mode lines.

Hopefully, this will allow to extend it more easily to support named modes
and / or properties set directly on the command line.

Signed-off-by: Maxime Ripard 
---
 drivers/gpu/drm/drm_modes.c | 305 +++--
 1 file changed, 190 insertions(+), 115 deletions(-)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 53f07ac7c174..7d5bdca276f2 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -30,6 +30,7 @@
  * authorization from the copyright holder(s) and author(s).
  */

+#include 
 #include 
 #include 
 #include 
@@ -1261,6 +1262,131 @@ void drm_mode_connector_list_update(struct 
drm_connector *connector)
 }
 EXPORT_SYMBOL(drm_mode_connector_list_update);

+static int drm_mode_parse_cmdline_bpp(const char *str, char **end_ptr,
+ struct drm_cmdline_mode *mode)
+{
+   if (str[0] != '-')
+   return -EINVAL;
+
+   mode->bpp = simple_strtol(str + 1, end_ptr, 10);
+   mode->bpp_specified = true;
+
+   return 0;
+}
+
+static int drm_mode_parse_cmdline_refresh(const char *str, char **end_ptr,
+ struct drm_cmdline_mode *mode)
+{
+   if (str[0] != '@')
+   return -EINVAL;
+
+   mode->refresh = simple_strtol(str + 1, end_ptr, 10);
+   mode->refresh_specified = true;
+
+   return 0;
+}
+
+static int drm_mode_parse_cmdline_extra(const char *str, int length,
+   struct drm_connector *connector,
+   struct drm_cmdline_mode *mode)
+{
+   int i;
+
+   for (i = 0; i < length; i++) {
+   switch (str[i]) {
+   case 'i':
+   mode->interlace = true;
+   break;
+   case 'm':
+   mode->margins = true;
+   break;
+   case 'D':
+   if (mode->force != DRM_FORCE_UNSPECIFIED)
+   return -EINVAL;
+
+   if ((connector->connector_type != 
DRM_MODE_CONNECTOR_DVII) &&
+   (connector->connector_type != 
DRM_MODE_CONNECTOR_HDMIB))
+   mode->force = DRM_FORCE_ON;
+   else
+   mode->force = DRM_FORCE_ON_DIGITAL;
+   break;
+   case 'd':
+   if (mode->force != DRM_FORCE_UNSPECIFIED)
+   return -EINVAL;
+
+   mode->force = DRM_FORCE_OFF;
+   break;
+   case 'e':
+   if (mode->force != DRM_FORCE_UNSPECIFIED)
+   return -EINVAL;
+
+   mode->force = DRM_FORCE_ON;
+   break;
+   default:
+   return -EINVAL;
+   }
+   }
+
+   return 0;
+}
+
+static int drm_mode_parse_cmdline_res_mode(const char *str, unsigned int 
length,
+  bool extras,
+  struct drm_connector *connector,
+  struct drm_cmdline_mode *mode)
+{
+   bool rb = false, cvt = false;
+   int xres = 0, yres = 0;
+   int remaining, i;
+   char *end_ptr;
+
+   xres = simple_strtol(str, &end_ptr, 10);
+
+   if (end_ptr[0] != 'x')
+   return -EINVAL;
+   end_ptr++;
+
+   yres = simple_strtol(end_ptr, &end_ptr, 10);
+
+   remaining = length - (end_ptr - str);
+   if (remaining < 0)
+   return -EINVAL;
+
+   for (i = 0; i < remaining; i++) {
+   switch (end_ptr[i]) {
+   case 'M':
+   cvt = true;
+   break;
+   case 'R':
+   rb = true;
+   break;
+   default:
+   /*
+* Try to pass that to our extras parsing
+* function to handle the case where the
+* extras are directly after the resolution
+*/
+   if (extras) {
+   int ret = drm_mode_parse_cmdline_extra(end_ptr 
+ i,
+  1,
+  
connector,
+  mode);
+   if (ret)
+   return ret;
+   } else {
+   return -EINVAL;
+   }
+   }
+   }
+
+   mode->xres = xres;
+   mode->yres = yres;
+

[PATCH 0/5] drm/sun4i: Handle TV overscan

2016-10-18 Thread Maxime Ripard
Hi,

The Allwinner display engine doesn't have any kind of hardware help to deal
with TV overscan.

This means that if we use the only mode the hardware provides (either PAL
or NTSC, or something else), most of the screens will crop the borders of
the image, which is bad.

We can however use somekind of a hack, to instead reduce the mode exposed
to the userspace, and center it in the final image. We would expose
different overscan ratio to be able to deal with most of the screens, each
reducing more the displayable area.

The first patches are rework for the command line parser in order to be
able to use named modes. This is going to be helpful for us, since
different modes might have the same timings but only differ on a few
settings not exposed in the modes, but it might eventually be used for the
*VGA modes for example.

The last patches extend the current driver to deal with the changes used
to introduce the overscan.

Let me know what you think,
Maxime

Maxime Ripard (5):
  drm/modes: Rewrite the command line parser
  drm/modes: Support modes names on the command line
  drm/sun4i: Add custom crtc state
  drm/sun4i: Compute TCON1 mode from tv mode
  drm/sun4i: Add support for the overscan profiles

 drivers/gpu/drm/drm_connector.c   |   3 +-
 drivers/gpu/drm/drm_fb_helper.c   |   4 +-
 drivers/gpu/drm/drm_modes.c   | 324 +--
 drivers/gpu/drm/sun4i/sun4i_backend.c |  18 +-
 drivers/gpu/drm/sun4i/sun4i_crtc.c|  37 ++-
 drivers/gpu/drm/sun4i/sun4i_crtc.h|  16 +-
 drivers/gpu/drm/sun4i/sun4i_rgb.c |  10 +-
 drivers/gpu/drm/sun4i/sun4i_tv.c  |  75 --
 include/drm/drm_connector.h   |   1 +-
 9 files changed, 342 insertions(+), 146 deletions(-)

-- 
git-series 0.8.10


[PATCH 3/5] drm/sun4i: Add custom crtc state

2016-10-18 Thread Maxime Ripard
We'll need a custom CRTC state to deal with the overscan setup.

We'll store in it the actual display size that can be used by the
applications, and the size to use on the plane.

Signed-off-by: Maxime Ripard 
---
 drivers/gpu/drm/sun4i/sun4i_backend.c | 18 +-
 drivers/gpu/drm/sun4i/sun4i_crtc.c| 37 ++--
 drivers/gpu/drm/sun4i/sun4i_crtc.h| 16 -
 drivers/gpu/drm/sun4i/sun4i_rgb.c | 10 -
 drivers/gpu/drm/sun4i/sun4i_tv.c  | 14 +++-
 5 files changed, 87 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.c 
b/drivers/gpu/drm/sun4i/sun4i_backend.c
index 32c0584e3c35..9b36b7104c15 100644
--- a/drivers/gpu/drm/sun4i/sun4i_backend.c
+++ b/drivers/gpu/drm/sun4i/sun4i_backend.c
@@ -22,6 +22,7 @@
 #include 

 #include "sun4i_backend.h"
+#include "sun4i_crtc.h"
 #include "sun4i_drv.h"

 static u32 sunxi_rgb2yuv_coef[12] = {
@@ -115,15 +116,19 @@ int sun4i_backend_update_layer_coord(struct sun4i_backend 
*backend,
 {
struct drm_plane_state *state = plane->state;
struct drm_framebuffer *fb = state->fb;
+   struct sun4i_crtc_state *s_state = 
drm_crtc_state_to_sun4i_crtc_state(state->crtc->state);
+   u16 x, y;
+

DRM_DEBUG_DRIVER("Updating layer %d\n", layer);

if (plane->type == DRM_PLANE_TYPE_PRIMARY) {
DRM_DEBUG_DRIVER("Primary layer, updating global size W: %u H: 
%u\n",
-state->crtc_w, state->crtc_h);
+s_state->display_x_size,
+s_state->display_y_size);
regmap_write(backend->regs, SUN4I_BACKEND_DISSIZE_REG,
-SUN4I_BACKEND_DISSIZE(state->crtc_w,
-  state->crtc_h));
+SUN4I_BACKEND_DISSIZE(s_state->display_x_size,
+  s_state->display_y_size));
}

/* Set the line width */
@@ -139,11 +144,12 @@ int sun4i_backend_update_layer_coord(struct sun4i_backend 
*backend,
   state->crtc_h));

/* Set base coordinates */
+   x = s_state->plane_x_offset + state->crtc_x;
+   y = s_state->plane_y_offset + state->crtc_y;
DRM_DEBUG_DRIVER("Layer coordinates X: %d Y: %d\n",
-state->crtc_x, state->crtc_y);
+x, y);
regmap_write(backend->regs, SUN4I_BACKEND_LAYCOOR_REG(layer),
-SUN4I_BACKEND_LAYCOOR(state->crtc_x,
-  state->crtc_y));
+SUN4I_BACKEND_LAYCOOR(x, y));

return 0;
 }
diff --git a/drivers/gpu/drm/sun4i/sun4i_crtc.c 
b/drivers/gpu/drm/sun4i/sun4i_crtc.c
index 4a192210574f..772e0ecd72db 100644
--- a/drivers/gpu/drm/sun4i/sun4i_crtc.c
+++ b/drivers/gpu/drm/sun4i/sun4i_crtc.c
@@ -104,9 +104,42 @@ static const struct drm_crtc_helper_funcs 
sun4i_crtc_helper_funcs = {
.enable = sun4i_crtc_enable,
 };

+struct drm_crtc_state *sun4i_crtc_duplicate_state(struct drm_crtc *crtc)
+{
+   struct sun4i_crtc_state *state = 
drm_crtc_state_to_sun4i_crtc_state(crtc->state);
+   struct sun4i_crtc_state *copy;
+
+   copy = kmalloc(sizeof(*copy), GFP_KERNEL);
+   if (!copy)
+   return NULL;
+
+   DRM_DEBUG_DRIVER("Copying state %p to %p", state, copy);
+
+   __drm_atomic_helper_crtc_duplicate_state(crtc, ©->base);
+
+   copy->display_x_size = state->display_x_size;
+   copy->display_y_size = state->display_y_size;
+
+   copy->plane_x_offset = state->plane_x_offset;
+   copy->plane_y_offset = state->plane_y_offset;
+
+   return ©->base;
+}
+
+void sun4i_crtc_destroy_state(struct drm_crtc *crtc,
+ struct drm_crtc_state *c_state)
+{
+   struct sun4i_crtc_state *s_state = 
drm_crtc_state_to_sun4i_crtc_state(c_state);
+
+   DRM_DEBUG_DRIVER("Freeing state %p", s_state);
+
+   __drm_atomic_helper_crtc_destroy_state(c_state);
+   kfree(s_state);
+}
+
 static const struct drm_crtc_funcs sun4i_crtc_funcs = {
-   .atomic_destroy_state   = drm_atomic_helper_crtc_destroy_state,
-   .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
+   .atomic_destroy_state   = sun4i_crtc_destroy_state,
+   .atomic_duplicate_state = sun4i_crtc_duplicate_state,
.destroy= drm_crtc_cleanup,
.page_flip  = drm_atomic_helper_page_flip,
.reset  = drm_atomic_helper_crtc_reset,
diff --git a/drivers/gpu/drm/sun4i/sun4i_crtc.h 
b/drivers/gpu/drm/sun4i/sun4i_crtc.h
index dec8ce4d9b25..625c9ac41434 100644
--- a/drivers/gpu/drm/sun4i/sun4i_crtc.h
+++ b/drivers/gpu/drm/sun4i/sun4i_crtc.h
@@ -20,11 +20,27 @@ struct sun4i_crtc {
struct sun4i_drv*drv;
 };

+struct sun4i_crtc_state {
+   struct drm_crtc_state   base;
+

[PATCH 2/5] drm/modes: Support modes names on the command line

2016-10-18 Thread Maxime Ripard
The drm subsystem also uses the video= kernel parameter, and in the
documentation refers to the fbdev documentation for that parameter.

However, that documentation also says that instead of giving the mode using
its resolution we can also give a name. However, DRM doesn't handle that
case at the moment. Even though in most case it shouldn't make any
difference, it might be useful for analog modes, where different standards
might have the same resolution, but still have a few different parameters
that are not encoded in the modes (NTSC vs NTSC-J vs PAL-M for example).

Signed-off-by: Maxime Ripard 
---
 drivers/gpu/drm/drm_connector.c |  3 +-
 drivers/gpu/drm/drm_fb_helper.c |  4 +++-
 drivers/gpu/drm/drm_modes.c | 49 +++---
 include/drm/drm_connector.h |  1 +-
 4 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index 2db7fb510b6c..27a8a511257c 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -147,8 +147,9 @@ static void drm_connector_get_cmdline_mode(struct 
drm_connector *connector)
connector->force = mode->force;
}

-   DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
+   DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n",
  connector->name,
+ mode->name ? mode->name : "",
  mode->xres, mode->yres,
  mode->refresh_specified ? mode->refresh : 60,
  mode->rb ? " reduced blanking" : "",
diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index 03414bde1f15..20a68305fb45 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -1748,6 +1748,10 @@ struct drm_display_mode *drm_pick_cmdline_mode(struct 
drm_fb_helper_connector *f
prefer_non_interlace = !cmdline_mode->interlace;
 again:
list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
+   /* Check (optional) mode name first */
+   if (!strcmp(mode->name, cmdline_mode->name))
+   return mode;
+
/* check width/height */
if (mode->hdisplay != cmdline_mode->xres ||
mode->vdisplay != cmdline_mode->yres)
diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 7d5bdca276f2..fdbf541a5978 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -1413,7 +1413,7 @@ bool drm_mode_parse_command_line_for_connector(const char 
*mode_option,
   struct drm_cmdline_mode *mode)
 {
const char *name;
-   bool parse_extras = false;
+   bool named_mode = false, parse_extras = false;
unsigned int bpp_off = 0, refresh_off = 0;
unsigned int mode_end = 0;
char *bpp_ptr = NULL, *refresh_ptr = NULL, *extra_ptr = NULL;
@@ -1432,8 +1432,14 @@ bool drm_mode_parse_command_line_for_connector(const 
char *mode_option,

name = mode_option;

+   /*
+* If the first character is not a digit, then it means that
+* we have a named mode.
+*/
if (!isdigit(name[0]))
-   return false;
+   named_mode = true;
+   else
+   named_mode = false;

/* Try to locate the bpp and refresh specifiers, if any */
bpp_ptr = strchr(name, '-');
@@ -1460,12 +1466,16 @@ bool drm_mode_parse_command_line_for_connector(const 
char *mode_option,
parse_extras = true;
}

-   ret = drm_mode_parse_cmdline_res_mode(name, mode_end,
- parse_extras,
- connector,
- mode);
-   if (ret)
-   return false;
+   if (named_mode) {
+   strncpy(mode->name, name, mode_end);
+   } else {
+   ret = drm_mode_parse_cmdline_res_mode(name, mode_end,
+ parse_extras,
+ connector,
+ mode);
+   if (ret)
+   return false;
+   }
mode->specified = true;

if (bpp_ptr) {
@@ -1493,14 +1503,23 @@ bool drm_mode_parse_command_line_for_connector(const 
char *mode_option,
extra_ptr = refresh_end_ptr;

if (extra_ptr) {
-   int remaining = strlen(name) - (extra_ptr - name);
+   if (!named_mode) {
+   int len = strlen(name) - (extra_ptr - name);

-   /*
-* We still have characters to process, while
-* we shouldn't have any
-*/
-   if (remaining > 0)
-   return false;
+   

[PATCH 5/5] drm/sun4i: Add support for the overscan profiles

2016-10-18 Thread Maxime Ripard
Create overscan profiles reducing the displayed zone.

For each TV standard (PAL and NTSC so far), we create 4 more reduced modes
by steps of 5% that the user will be able to select.

Signed-off-by: Maxime Ripard 
---
 drivers/gpu/drm/sun4i/sun4i_tv.c | 60 +++--
 1 file changed, 36 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/sun4i/sun4i_tv.c b/drivers/gpu/drm/sun4i/sun4i_tv.c
index f99886462cb8..9ee03ba086b6 100644
--- a/drivers/gpu/drm/sun4i/sun4i_tv.c
+++ b/drivers/gpu/drm/sun4i/sun4i_tv.c
@@ -301,27 +301,33 @@ static const struct tv_mode 
*sun4i_tv_find_tv_by_mode(const struct drm_display_m
DRM_DEBUG_DRIVER("Comparing mode %s vs %s",
 mode->name, tv_mode->name);

-   if (!strcmp(mode->name, tv_mode->name))
+   if (!strncmp(mode->name, tv_mode->name, strlen(tv_mode->name)))
return tv_mode;
}

/* Then by number of lines */
for (i = 0; i < ARRAY_SIZE(tv_modes); i++) {
const struct tv_mode *tv_mode = &tv_modes[i];
+   int j;

-   DRM_DEBUG_DRIVER("Comparing mode %s vs %s (X: %d vs %d)",
-mode->name, tv_mode->name,
-mode->vdisplay, tv_mode->vdisplay);
+   for (j = 0; j < 20; j += 5) {
+   u32 vdisplay = tv_mode->vdisplay * (100 - j) / 100;

-   if (mode->vdisplay == tv_mode->vdisplay)
-   return tv_mode;
+   DRM_DEBUG_DRIVER("Comparing mode with %s (%d) (X: %d vs 
%d)",
+tv_mode->name, j,
+vdisplay, tv_mode->vdisplay);
+
+   if (vdisplay == tv_mode->vdisplay)
+   return tv_mode;
+   }
}

return NULL;
 }

 static void sun4i_tv_mode_to_drm_mode(const struct tv_mode *tv_mode,
- struct drm_display_mode *mode)
+ struct drm_display_mode *mode,
+ int overscan)
 {
DRM_DEBUG_DRIVER("Creating mode %s\n", mode->name);

@@ -329,12 +335,12 @@ static void sun4i_tv_mode_to_drm_mode(const struct 
tv_mode *tv_mode,
mode->clock = 13500;
mode->flags = DRM_MODE_FLAG_INTERLACE;

-   mode->hdisplay = tv_mode->hdisplay;
+   mode->hdisplay = tv_mode->hdisplay * (100 - overscan) / 100;
mode->hsync_start = mode->hdisplay + tv_mode->hfront_porch;
mode->hsync_end = mode->hsync_start + tv_mode->hsync_len;
mode->htotal = mode->hsync_end  + tv_mode->hback_porch;

-   mode->vdisplay = tv_mode->vdisplay;
+   mode->vdisplay = tv_mode->vdisplay * (100 - overscan) / 100;
mode->vsync_start = mode->vdisplay + tv_mode->vfront_porch;
mode->vsync_end = mode->vsync_start + tv_mode->vsync_len;
mode->vtotal = mode->vsync_end  + tv_mode->vback_porch;
@@ -352,10 +358,10 @@ static int sun4i_tv_atomic_check(struct drm_encoder 
*encoder,
return -EINVAL;

state->display_x_size = tv_mode->hdisplay;
-   state->plane_x_offset = 0;
+   state->plane_x_offset = (tv_mode->hdisplay - mode->hdisplay) / 2;

state->display_y_size = tv_mode->vdisplay;
-   state->plane_y_offset = 0;
+   state->plane_y_offset = (tv_mode->vdisplay - mode->vdisplay) / 2;

return 0;
 }
@@ -404,7 +410,7 @@ static void sun4i_tv_mode_set(struct drm_encoder *encoder,
struct drm_display_mode tv_drm_mode = { 0 };

strcpy(tv_drm_mode.name, "TV");
-   sun4i_tv_mode_to_drm_mode(tv_mode, &tv_drm_mode);
+   sun4i_tv_mode_to_drm_mode(tv_mode, &tv_drm_mode, 0);
drm_mode_set_crtcinfo(&tv_drm_mode, CRTC_INTERLACE_HALVE_V);

sun4i_tcon1_mode_set(tcon, &tv_drm_mode);
@@ -526,22 +532,28 @@ static int sun4i_tv_comp_get_modes(struct drm_connector 
*connector)
int i;

for (i = 0; i < ARRAY_SIZE(tv_modes); i++) {
-   struct drm_display_mode *mode;
const struct tv_mode *tv_mode = &tv_modes[i];
-
-   mode = drm_mode_create(connector->dev);
-   if (!mode) {
-   DRM_ERROR("Failed to create a new display mode\n");
-   return 0;
+   int j;
+
+   for (j = 0; j < 20; j += 5) {
+   struct drm_display_mode *mode = 
drm_mode_create(connector->dev);
+   if (!mode) {
+   DRM_ERROR("Failed to create a new display 
mode\n");
+   return 0;
+   }
+
+   if (j)
+   sprintf(mode->name, "%s%d", tv_mode->name,
+   j);
+   else
+   strcpy(mode->name, tv_mode->name);
+
+   

[PATCH v2] drm/imx: ipuv3-plane: Access old u/vbo properly in ->atomic_check for YU12/YV12

2016-10-18 Thread Liu Ying
Before accessing the u/v offset(aka, u/vbo for IPUv3) of the old plane state's
relevant fb, we should make sure the fb is in YU12 or YV12 pixel format(which
are the two YUV pixel formats we support only), otherwise, we are likely to
trigger BUG_ON() in drm_plane_state_to_u/vbo() since the fb's pixel format is
probably not YU12 or YV12.

Link: https://bugs.freedesktop.org/show_bug.cgi?id=98150
Fixes: c6c1f9bc798b ("drm/imx: Add active plane reconfiguration support")
Cc: stable at vger.kernel.org # 4.8
Signed-off-by: Liu Ying 
---
v1->v2:
* Correct the condition under which we may access old u/vbo - old->pixel_format
  is not necessarily the same to fb->pixel_format, instead, it could be YU12
  or YV12.  This may cover the case in which we switch fb pixel format
  bewteen YU12 and YV12.

 drivers/gpu/drm/imx/ipuv3-plane.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/imx/ipuv3-plane.c 
b/drivers/gpu/drm/imx/ipuv3-plane.c
index e33110e..08d0fd5 100644
--- a/drivers/gpu/drm/imx/ipuv3-plane.c
+++ b/drivers/gpu/drm/imx/ipuv3-plane.c
@@ -359,7 +359,9 @@ static int ipu_plane_atomic_check(struct drm_plane *plane,
if ((ubo > 0xf8) || (vbo > 0xf8))
return -EINVAL;

-   if (old_fb) {
+   if (old_fb &&
+   (old_fb->pixel_format == DRM_FORMAT_YUV420 ||
+old_fb->pixel_format == DRM_FORMAT_YVU420)) {
old_ubo = drm_plane_state_to_ubo(old_state);
old_vbo = drm_plane_state_to_vbo(old_state);
if (ubo != old_ubo || vbo != old_vbo)
-- 
2.7.4



[PATCH] drm/sun4i: Add a few formats

2016-10-18 Thread Maxime Ripard
The planes can do more than what was previously exposed. Add support for
them.

Signed-off-by: Maxime Ripard 
---
 drivers/gpu/drm/sun4i/sun4i_backend.c | 20 
 drivers/gpu/drm/sun4i/sun4i_layer.c   |  6 ++
 2 files changed, 26 insertions(+)

diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.c 
b/drivers/gpu/drm/sun4i/sun4i_backend.c
index afb7ddf660ef..b184a476a480 100644
--- a/drivers/gpu/drm/sun4i/sun4i_backend.c
+++ b/drivers/gpu/drm/sun4i/sun4i_backend.c
@@ -96,6 +96,22 @@ static int sun4i_backend_drm_format_to_layer(struct 
drm_plane *plane,
*mode = SUN4I_BACKEND_LAY_FBFMT_ARGB;
break;

+   case DRM_FORMAT_ARGB:
+   *mode = SUN4I_BACKEND_LAY_FBFMT_ARGB;
+   break;
+
+   case DRM_FORMAT_ARGB1555:
+   *mode = SUN4I_BACKEND_LAY_FBFMT_ARGB1555;
+   break;
+
+   case DRM_FORMAT_RGBA5551:
+   *mode = SUN4I_BACKEND_LAY_FBFMT_RGBA5551;
+   break;
+
+   case DRM_FORMAT_RGBA:
+   *mode = SUN4I_BACKEND_LAY_FBFMT_RGBA;
+   break;
+
case DRM_FORMAT_XRGB:
*mode = SUN4I_BACKEND_LAY_FBFMT_XRGB;
break;
@@ -104,6 +120,10 @@ static int sun4i_backend_drm_format_to_layer(struct 
drm_plane *plane,
*mode = SUN4I_BACKEND_LAY_FBFMT_RGB888;
break;

+   case DRM_FORMAT_RGB565:
+   *mode = SUN4I_BACKEND_LAY_FBFMT_RGB565;
+   break;
+
default:
return -EINVAL;
}
diff --git a/drivers/gpu/drm/sun4i/sun4i_layer.c 
b/drivers/gpu/drm/sun4i/sun4i_layer.c
index f0035bf5efea..5d53c977bca5 100644
--- a/drivers/gpu/drm/sun4i/sun4i_layer.c
+++ b/drivers/gpu/drm/sun4i/sun4i_layer.c
@@ -73,12 +73,18 @@ static const struct drm_plane_funcs 
sun4i_backend_layer_funcs = {
 static const uint32_t sun4i_backend_layer_formats_primary[] = {
DRM_FORMAT_ARGB,
DRM_FORMAT_RGB888,
+   DRM_FORMAT_RGB565,
DRM_FORMAT_XRGB,
 };

 static const uint32_t sun4i_backend_layer_formats_overlay[] = {
DRM_FORMAT_ARGB,
+   DRM_FORMAT_ARGB,
+   DRM_FORMAT_ARGB1555,
+   DRM_FORMAT_RGBA5551,
+   DRM_FORMAT_RGBA,
DRM_FORMAT_RGB888,
+   DRM_FORMAT_RGB565,
DRM_FORMAT_XRGB,
 };

-- 
2.9.3



[PATCH v2] drm/imx: ipuv3-plane: Access old u/vbo properly in ->atomic_check for YU12/YV12

2016-10-18 Thread Philipp Zabel
Am Dienstag, den 18.10.2016, 16:44 +0800 schrieb Liu Ying:
> Before accessing the u/v offset(aka, u/vbo for IPUv3) of the old plane state's
> relevant fb, we should make sure the fb is in YU12 or YV12 pixel format(which
> are the two YUV pixel formats we support only), otherwise, we are likely to
> trigger BUG_ON() in drm_plane_state_to_u/vbo() since the fb's pixel format is
> probably not YU12 or YV12.
> 
> Link: https://bugs.freedesktop.org/show_bug.cgi?id=98150
> Fixes: c6c1f9bc798b ("drm/imx: Add active plane reconfiguration support")
> Cc: stable at vger.kernel.org # 4.8
> Signed-off-by: Liu Ying 
> ---
> v1->v2:
> * Correct the condition under which we may access old u/vbo - 
> old->pixel_format
>   is not necessarily the same to fb->pixel_format, instead, it could be YU12
>   or YV12.  This may cover the case in which we switch fb pixel format
>   bewteen YU12 and YV12.

Applied, thank you.

regards
Philipp

>  drivers/gpu/drm/imx/ipuv3-plane.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/imx/ipuv3-plane.c 
> b/drivers/gpu/drm/imx/ipuv3-plane.c
> index e33110e..08d0fd5 100644
> --- a/drivers/gpu/drm/imx/ipuv3-plane.c
> +++ b/drivers/gpu/drm/imx/ipuv3-plane.c
> @@ -359,7 +359,9 @@ static int ipu_plane_atomic_check(struct drm_plane *plane,
>   if ((ubo > 0xf8) || (vbo > 0xf8))
>   return -EINVAL;
>  
> - if (old_fb) {
> + if (old_fb &&
> + (old_fb->pixel_format == DRM_FORMAT_YUV420 ||
> +  old_fb->pixel_format == DRM_FORMAT_YVU420)) {
>   old_ubo = drm_plane_state_to_ubo(old_state);
>   old_vbo = drm_plane_state_to_vbo(old_state);
>   if (ubo != old_ubo || vbo != old_vbo)



[Intel-gfx] [PATCH 12/15] drm: RIP mode_config->rotation_property

2016-10-18 Thread Ville Syrjälä
On Tue, Oct 18, 2016 at 11:13:53AM +0300, Laurent Pinchart wrote:
> Hi Daniel,
> 
> On Tuesday 18 Oct 2016 09:36:23 Daniel Vetter wrote:
> > On Tue, Oct 18, 2016 at 01:38:05AM +0300, Laurent Pinchart wrote:
> > > On Friday 22 Jul 2016 16:43:13 ville.syrjala at linux.intel.com wrote:
> > >> From: Ville Syrjälä 
> > >> 
> > >> Now that all drivers have been converted over to the per-plane rotation
> > >> property, we can just nuke the global rotation property.
> > >> 
> > >> Signed-off-by: Ville Syrjälä 
> > > 
> > > Stupid question, but how does this work when the hardware supports global
> > > rotation only, not per-plane rotation ?
> > 
> > Does that exist? If so I guess we get to add a rotation property to CRTCS
> > (and update docs and all that).
> 
> I have a hardware composer that performs rotation on the output side. At the 
> moment it doesn't support rotation when used with the display, but I wouldn't 
> rule that out in future SoC versions. So I'm not aware of any use case for a 
> rotation property on the CRTC at the moment, I just wanted to make sure we 
> have a path forward.

I even implemented that for i915 long ago by having it rotate all the
planes (+ adjust their coordinates appropriately). But people weren't
too keen on putting that in, so I dropped it.

https://lists.freedesktop.org/archives/intel-gfx/2014-February/040053.html

The only bigger snafu here is omap, which already has a rotation property
on the crtc, except it actually only rotates the primary plane. So
when/if someone adds a real crtc rotation property it has to be called
something else that "rotation". I think I settled on "crtc-rotation"
judging what I have in my last branch on that topic.

-- 
Ville Syrjälä
Intel OTC


[PATCH v2] drm/mediatek: fix a typo

2016-10-18 Thread CK Hu
Acked-by: CK Hu 

On Tue, 2016-10-18 at 16:23 +0800, Bibby Hsieh wrote:
> If we want to set the hardware OD to relay mode,
> we have to set OD_CFG register rather than
> OD_RELAYMODE; otherwise, the system will access
> the wrong address.
> 
> Fixes: 7216436420414144646f5d8343d061355fd23483 ("drm/mediatek: set mt8173 
> dithering function")
> Cc: stable at vger.kernel.org # v4.9+
> Signed-off-by: Bibby Hsieh 
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c |2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c 
> b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> index df33b3c..aa5f20f 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> @@ -123,7 +123,7 @@ static void mtk_od_config(struct mtk_ddp_comp *comp, 
> unsigned int w,
> unsigned int bpc)
>  {
>   writel(w << 16 | h, comp->regs + DISP_OD_SIZE);
> - writel(OD_RELAYMODE, comp->regs + OD_RELAYMODE);
> + writel(OD_RELAYMODE, comp->regs + OD_CFG);
>   mtk_dither_set(comp, bpc, DISP_OD_CFG);
>  }
>  




[PATCH 0/5] drm/sun4i: Handle TV overscan

2016-10-18 Thread Maxime Ripard
Hi Russell,

On Tue, Oct 18, 2016 at 10:24:22AM +0100, Russell King - ARM Linux wrote:
> On Tue, Oct 18, 2016 at 10:29:33AM +0200, Maxime Ripard wrote:
> > The Allwinner display engine doesn't have any kind of hardware help to deal
> > with TV overscan.
> 
> I'm not sure I follow.  My understanding (from reading the CEA specs)
> is that TVs are expected to overscan the image, so the upper left, and
> bottom right pixels are not visible.

Yes, this is why we have to work around it somehow.

> I assume we are talking about TVs connected via HDMI.  In the HDMI AVI
> infoframe, there are bits which specify whether the image should be
> overscanned or underscanned - however, whether a TV implements those
> bits is rather sketchy.  I assume when you say "any kind of hardware
> help" you mean you can't control these bits?
> 
> However, some (most?) TVs now implement a menu option which allows the
> (over)scan mode to be selected.  Others assume that if it's a TV mode,
> it's supposed to be overscanned, if it's a "PC" mode, it should be
> underscanned and provide no option to change the behaviour.

We're talking about plain dumb composite output, so no infoframes,
setup or anything here :)

> > This means that if we use the only mode the hardware provides (either PAL
> > or NTSC, or something else), most of the screens will crop the borders of
> > the image, which is bad.
> 
> I think you're trying to apply monitor-type behaviour to TVs...

Yes, kind of. Our users are usually running a desktop distro, and the
default output on those boards are just plain composite, which means
running any DE onto a TV.

Note that it's not only about the interface itself, but you'll lose
content for all pictures displayed. And no one cares about the TV safe
area anymore these days (starting with the framebuffer console).

> > We can however use somekind of a hack, to instead reduce the mode
> > exposed to the userspace, and center it in the final image. We
> > would expose different overscan ratio to be able to deal with most
> > of the screens, each reducing more the displayable area.
> 
> I'm not sure we need "a hack".  What if we treated the primary plane just
> like any other (eg, overlay) plane?  We could then specify (eg) a 1920x1080
> display mode, but with the primary plane reduced in size, positioned in
> the centre of the display mode?
> 
> I know that there's hardware out there which can do exactly that - Marvell
> Dove implements this: you set the display size separately from two planes,
> one graphics plane and one video plane.  Both planes can be positioned
> anywhere in the displayed size.

This might have been poorly worded on my side, but it's exactly what
I'm doing in those patches.

> We could then specify at DRM level that a connected device overscans by
> N%, and have the primary plane adjusted by DRM itself.

I'd agree with you, however, there's a few issues with that I
think.

The first one is that this overscanning should be reported by the
connector I guess? but this is really TV specific, so we need one way
to let the user tell how the image is displayed on its side, and we
cannot really autodetect it, and this needs to be done at runtime so
that we can present some shiny interface to let it select which
overscan ratio works for him/her.

The second one is that we still need to expose the reduced modes to
userspace, and not only the displayed size, so that the applications
know what they must draw on. But I guess this could be adjusted by the
core too.

In order to work consistently, I think all planes should be adjusted
that way, so that relative coordinates are from the primary plane
origin, and not the display origin. But that could be adjusted too by
the core I guess.

The fourth one being the major one. Every time I raised the issue on
IRC, the answer basically was "we don't care about analog", so I'm a
bit pessimistic about whether dealing with this in the core would be
accepted, hence why I chose to deal with this at the driver level.

Thanks,
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
-- next part --
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: 
<https://lists.freedesktop.org/archives/dri-devel/attachments/20161018/64e682e0/attachment.sig>


[RFC] dma-buf/fence: avoid holding lock while calling cb

2016-10-18 Thread Christian König
Am 17.10.2016 um 20:02 schrieb Rob Clark:
> On Mon, Oct 17, 2016 at 4:25 AM, Maarten Lankhorst
>  wrote:
>> Op 16-10-16 om 18:03 schreef Rob Clark:
>>> Currently with fence-array, we have a potential deadlock situation.  If we
>>> fence_add_callback() on an array-fence, the array-fence's lock is aquired
>>> first, and in it's ->enable_signaling() callback, it will install cb's on
>>> it's array-member fences, so the array-member's lock is acquired second.
>>>
>>> But in the signal path, the array-member's lock is acquired first, and the
>>> array-fence's lock acquired second.
>>>
>>> One approach to deal with this is avoid holding the fence's lock when
>>> calling the cb.  It is a bit intrusive and I haven't fixed up all the
>>> other drivers that call directly or indirectly fence_signal_locked().
>>>
>>> I guess the other option would be introduce a work-queue for array-fence?
>>> Or??
>> Enable signaling when creating the fence array is an option. As an 
>> optimization we don't enable
>> signaling when creating a single fence, but when you merge fences you're 
>> probably interested
>> in the result anyway.
> I think what you mean is to fence_add_callback() on all the member
> fences up-front, rather from ops->enable_signaling()?  I guess that
> should work.

Yeah, but we should try to avoid that. Enabling signaling all the time 
is really expensive for some use cases.

I would certainly prefer the approach using a work item.

Regards,
Christian.

>
> BR,
> -R
> ___
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel




[RFC] dma-buf/fence: avoid holding lock while calling cb

2016-10-18 Thread Christian König
Am 16.10.2016 um 18:03 schrieb Rob Clark:
> Currently with fence-array, we have a potential deadlock situation.  If we
> fence_add_callback() on an array-fence, the array-fence's lock is aquired
> first, and in it's ->enable_signaling() callback, it will install cb's on
> it's array-member fences, so the array-member's lock is acquired second.
>
> But in the signal path, the array-member's lock is acquired first, and the
> array-fence's lock acquired second.
>
> One approach to deal with this is avoid holding the fence's lock when
> calling the cb.  It is a bit intrusive and I haven't fixed up all the
> other drivers that call directly or indirectly fence_signal_locked().

In general: Oh! Yes! Please! We have the same issue in the AMD scheduler 
when we want to register a new callback on the next fence in the list.

> I guess the other option would be introduce a work-queue for array-fence?

That's what we do in the GPU scheduler and it adds quite a bunch of 
extra overhead.

So my preferences are clearly to fix calling the cb with any locks held 
before using another work item for the array fences. But I'm not sure if 
that is possible with all drivers.

Regards,
Christian.

> Or??
>
> lockdep splat:
>
>   ==
> [ INFO: possible circular locking dependency detected ]
> 4.7.0-rc7+ #489 Not tainted
> ---
> surfaceflinger/2034 is trying to acquire lock:
>   (&(&array->lock)->rlock){..}, at: [] 
> fence_signal+0x5c/0xf8
>
> but task is already holding lock:
>   (&(&obj->child_list_lock)->rlock){..}, at: [] 
> sw_sync_ioctl+0x228/0x3b0
>
> which lock already depends on the new lock.
>
> the existing dependency chain (in reverse order) is:
>
> -> #1 (&(&obj->child_list_lock)->rlock){..}:
> [] __lock_acquire+0x173c/0x18d8
> [] lock_acquire+0x4c/0x68
> [] _raw_spin_lock_irqsave+0x54/0x70
> [] fence_add_callback+0x3c/0x100
> [] fence_array_enable_signaling+0x80/0x170
> [] fence_add_callback+0xb8/0x100
> [] sync_file_poll+0xd4/0xf0
> [] do_sys_poll+0x220/0x438
> [] SyS_ppoll+0x1b0/0x1d8
> [] el0_svc_naked+0x24/0x28
>
> -> #0 (&(&array->lock)->rlock){..}:
> [] print_circular_bug+0x80/0x2e0
> [] __lock_acquire+0x17c4/0x18d8
> [] lock_acquire+0x4c/0x68
> [] _raw_spin_lock_irqsave+0x54/0x70
> [] fence_signal+0x5c/0xf8
> [] fence_array_cb_func+0x78/0x88
> [] fence_signal_locked+0x80/0xe0
> [] sw_sync_ioctl+0x2f8/0x3b0
> [] do_vfs_ioctl+0xa4/0x790
> [] SyS_ioctl+0x8c/0xa0
> [] el0_svc_naked+0x24/0x28
>
> other info that might help us debug this:
>
>   Possible unsafe locking scenario:
>
> CPU0CPU1
> 
>lock(&(&obj->child_list_lock)->rlock);
> lock(&(&array->lock)->rlock);
> lock(&(&obj->child_list_lock)->rlock);
>lock(&(&array->lock)->rlock);
>
>   *** DEADLOCK ***
>
> 1 lock held by surfaceflinger/2034:
>   #0:  (&(&obj->child_list_lock)->rlock){..}, at: [] 
> sw_sync_ioctl+0x228/0x3b0
> ---
>   drivers/dma-buf/fence.c  | 22 ++
>   drivers/dma-buf/sw_sync.c|  2 +-
>   drivers/dma-buf/sync_debug.c | 16 +---
>   include/linux/fence.h|  6 +++---
>   4 files changed, 27 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
> index cc05ddd..917f905 100644
> --- a/drivers/dma-buf/fence.c
> +++ b/drivers/dma-buf/fence.c
> @@ -63,9 +63,9 @@ EXPORT_SYMBOL(fence_context_alloc);
>*
>* Unlike fence_signal, this function must be called with fence->lock held.
>*/
> -int fence_signal_locked(struct fence *fence)
> +int fence_signal_locked(struct fence *fence, unsigned long flags)
>   {
> - struct fence_cb *cur, *tmp;
> + struct fence_cb *cur;
>   int ret = 0;
>   
>   lockdep_assert_held(fence->lock);
> @@ -88,9 +88,12 @@ int fence_signal_locked(struct fence *fence)
>   } else
>   trace_fence_signaled(fence);
>   
> - list_for_each_entry_safe(cur, tmp, &fence->cb_list, node) {
> + while (!list_empty(&fence->cb_list)) {
> + cur = list_first_entry(&fence->cb_list, struct fence_cb, node);
>   list_del_init(&cur->node);
> + spin_unlock_irqrestore(fence->lock, flags);
>   cur->func(fence, cur);
> + spin_lock_irqsave(fence->lock, flags);
>   }
>   return ret;
>   }
> @@ -124,12 +127,15 @@ int fence_signal(struct fence *fence)
>   trace_fence_signaled(fence);
>   
>   if (test_bit(FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags)) {
> - struct fence_cb *cur, *tmp;
> + struct fence_cb *cur;
>   
>   spin_lock_irqsave(fence->lock, flags);
> - list_for_each_entry_safe(c

[PATCH] drm/bridge: adv7511: Remove unused code blocks

2016-10-18 Thread Jitendra Sharma
Remove unused id_table entries
Currently this driver supports only device tree based configuration.
So, no need in keeping the id_table entries

Remove redundant condition check
Remove not necessary if-else block for checking DT entry because else
part will never be picked as in absence of device node, probe will
fail in initial stage only.

Signed-off-by: Jitendra Sharma 
---
 drivers/gpu/drm/bridge/adv7511/adv7511_drv.c | 17 +
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c 
b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
index 8ed3906..44eea5c 100644
--- a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
+++ b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
@@ -942,10 +942,7 @@ static int adv7511_probe(struct i2c_client *i2c, const 
struct i2c_device_id *id)
adv7511->powered = false;
adv7511->status = connector_status_disconnected;

-   if (dev->of_node)
-   adv7511->type = (enum 
adv7511_type)of_device_get_match_data(dev);
-   else
-   adv7511->type = id->driver_data;
+   adv7511->type = (enum adv7511_type)of_device_get_match_data(dev);

memset(&link_config, 0, sizeof(link_config));

@@ -1065,17 +1062,6 @@ static int adv7511_remove(struct i2c_client *i2c)
return 0;
 }

-static const struct i2c_device_id adv7511_i2c_ids[] = {
-   { "adv7511", ADV7511 },
-   { "adv7511w", ADV7511 },
-   { "adv7513", ADV7511 },
-#ifdef CONFIG_DRM_I2C_ADV7533
-   { "adv7533", ADV7533 },
-#endif
-   { }
-};
-MODULE_DEVICE_TABLE(i2c, adv7511_i2c_ids);
-
 static const struct of_device_id adv7511_of_ids[] = {
{ .compatible = "adi,adv7511", .data = (void *)ADV7511 },
{ .compatible = "adi,adv7511w", .data = (void *)ADV7511 },
@@ -1096,7 +1082,6 @@ static int adv7511_remove(struct i2c_client *i2c)
.name = "adv7511",
.of_match_table = adv7511_of_ids,
},
-   .id_table = adv7511_i2c_ids,
.probe = adv7511_probe,
.remove = adv7511_remove,
 };
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v5 00/13] Centralize format information

2016-10-18 Thread Archit Taneja
Hi,

On 10/18/2016 04:11 AM, Laurent Pinchart wrote:
> Hello,
>
> Various pieces of information about DRM formats (number of planes, color
> depth, chroma subsampling, ...) are scattered across different helper
> functions in the DRM core. Callers of those functions often need to access
> more than a single parameter of the format, leading to inefficiencies due to
> multiple lookups.
>
> This patch series addresses this issue by centralizing all format information
> in a single data structure (01/13). It reimplements the existing format helper
> functions based on that structure (02/13) and converts the DRM core code to
> use the new structure (03/13). The DRM core now WARNs when a driver tries to
> query information about an unsupported format (04/13).
>
> The second part of the patch series removes the drm_fb_get_bpp_depth() legacy
> function that shouldn't be used directly by drivers. It modifies all its users
> to use the appropriate API instead (05/13 to 12/13) and finally merges the
> function into its only caller in the DRM core (13/13).
>
> The new API is also useful for drivers as shown by the "[PATCH v2 00/20] OMAP
> DRM fixes and improvements" patch series previously posted.
>
> All patches have been acked, the series is ready to be merged for v4.10.

Queued all patches to drm-misc.

Thanks,
Archit

>
> Changes since v4:
>
> - Rebased on top of latest drm/master branch
> - Collected acks
> - Fixed depth value of DRM_FORMAT_[AXRGB]{4} formats to match current code
> - Added support for DRM_FORMAT_BGR565, DRM_FORMAT_XBGR and
>   DRM_FORMAT_BGR888 to tilcdc
> - Documented the depth field as legacy
>
> Changes since v3:
>
> - Rebased on top of latest drm/master branch
> - Collected acks
> - Dropped "drm: Move format-related helpers to drm_fourcc.c" and
>   "drm/msm: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()" that
>   have been merged already
> - Added new "drm/arm: mali-dp: Replace drm_fb_get_bpp_depth() with
>   drm_format_plane_cpp()" patch
> - Coding style fixes and variable renames
>
> Changes since v2:
>
> - Remove bpp field from drm_format_info structure
> - Replace all users of drm_fb_get_bpp_depth() with the appropriate API
> - Merge drm_fb_get_bpp_depth() into its only caller
>
> Changes since v1:
>
> - Move format-related helpers to drm_fourcc.c
> - Use named initializers for the formats array
> - WARN when calling drm_format_info() for an unsupported format
> - Don't drop the drm_format_plane_width() and drm_format_plane_height()
>   helpers
>
> Laurent Pinchart (13):
>   drm: Centralize format information
>   drm: Implement the drm_format_*() helpers as drm_format_info()
> wrappers
>   drm: Use drm_format_info() in DRM core code
>   drm: WARN when calling drm_format_info() for an unsupported format
>   drm: hdlcd: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
>   drm: tilcdc: Replace drm_fb_get_bpp_depth() with
> drm_format_plane_cpp()
>   drm: cirrus: Replace drm_fb_get_bpp_depth() with
> drm_format_plane_cpp()
>   drm: gma500: Replace drm_fb_get_bpp_depth() with drm_format_info()
>   drm: amdgpu: Replace drm_fb_get_bpp_depth() with
> drm_format_plane_cpp()
>   drm: radeon: Replace drm_fb_get_bpp_depth() with
> drm_format_plane_cpp()
>   drm: vmwgfx: Replace drm_fb_get_bpp_depth() with drm_format_info()
>   drm/arm: mali-dp: Replace drm_fb_get_bpp_depth() with
> drm_format_plane_cpp()
>   drm: Don't export the drm_fb_get_bpp_depth() function
>
>  Documentation/gpu/drm-kms.rst   |   3 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c  |  14 +-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c |   3 +-
>  drivers/gpu/drm/arm/hdlcd_crtc.c|   5 +-
>  drivers/gpu/drm/arm/malidp_hw.c |   7 +-
>  drivers/gpu/drm/cirrus/cirrus_fbdev.c   |   6 +-
>  drivers/gpu/drm/cirrus/cirrus_main.c|   4 +-
>  drivers/gpu/drm/drm_fb_cma_helper.c |  23 +--
>  drivers/gpu/drm/drm_fourcc.c| 281 
> ++--
>  drivers/gpu/drm/drm_framebuffer.c   | 102 ++--
>  drivers/gpu/drm/drm_modeset_helper.c|  17 +-
>  drivers/gpu/drm/gma500/framebuffer.c|  20 +--
>  drivers/gpu/drm/radeon/radeon_fb.c  |  20 +--
>  drivers/gpu/drm/radeon/radeon_gem.c |   3 +-
>  drivers/gpu/drm/tilcdc/tilcdc_crtc.c|  18 +-
>  drivers/gpu/drm/tilcdc/tilcdc_plane.c   |   7 +-
>  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c |  12 +-
>  include/drm/drm_fourcc.h|  23 ++-
>  18 files changed, 244 insertions(+), 324 deletions(-)
>

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project


[Bug 178281] New: wine-staging apps freezes the machine with RX460

2016-10-18 Thread bugzilla-dae...@bugzilla.kernel.org
https://bugzilla.kernel.org/show_bug.cgi?id=178281

Bug ID: 178281
   Summary: wine-staging apps freezes the machine with RX460
   Product: Drivers
   Version: 2.5
Kernel Version: 4.9-rc1, 4.8.2, amd-staging-4.7
  Hardware: x86-64
OS: Linux
  Tree: Mainline
Status: NEW
  Severity: blocking
  Priority: P1
 Component: Video(DRI - non Intel)
  Assignee: drivers_video-dri at kernel-bugs.osdl.org
  Reporter: fin4478 at hotmail.com
Regression: No

When running Unigine Heaven windows version benchmark my computer always
freezes at scene 8. Freezing happens when using Tomb Raider 2013 windows
version benchmark too. Ssh connection works but I can not kill the hanging app
and virtual terminal and keyboard does not work. Rebooting via shh does not
work either. No dmesg or other log events can be seen when this happens.
Running native Linux Heaven benchmark or other native games runs ok.

glxinfo | grep OpenGL
OpenGL vendor string: X.Org
OpenGL renderer string: Gallium 0.4 on AMD POLARIS11 (DRM 3.3.0 /
4.7.0-g1ed6b7d-dirty, LLVM 4.0.0)
OpenGL core profile version string: 4.3 (Core Profile) Mesa 12.1.0-devel -
padoka PPA
OpenGL core profile shading language version string: 4.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 12.1.0-devel - padoka PPA
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.1 Mesa 12.1.0-devel - padoka PPA
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10

I will not use amdgpu-pro driver, because wine-staging csmt feature does not
work with it and amdgpu-pro does not support latest kernels.

-- 
You are receiving this mail because:
You are watching the assignee of the bug.


[PATCH 1/2] drm: make is_lspcon_adaptor static

2016-10-18 Thread Jani Nikula
Fixes sparse warning:

drivers/gpu/drm/drm_dp_dual_mode_helper.c:151:6: warning: symbol
'is_lspcon_adaptor' was not declared. Should it be static?

Fixes: 056996b95686 ("drm: Helper for lspcon in drm_dp_dual_mode")
Cc: Rodrigo Vivi 
Cc: Shashank Sharma 
Cc: 
Signed-off-by: Jani Nikula 

---

n.b. 056996b95686 ("drm: Helper for lspcon in drm_dp_dual_mode") has
been merged via drm-intel tree
---
 drivers/gpu/drm/drm_dp_dual_mode_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c 
b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
index a7aeb1ec852c..2624e266abbd 100644
--- a/drivers/gpu/drm/drm_dp_dual_mode_helper.c
+++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
@@ -148,8 +148,8 @@ static bool is_type2_adaptor(uint8_t adaptor_id)
  DP_DUAL_MODE_REV_TYPE2);
 }

-bool is_lspcon_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN],
-   const uint8_t adaptor_id)
+static bool is_lspcon_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN],
+ const uint8_t adaptor_id)
 {
return is_hdmi_adaptor(hdmi_id) &&
(adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
-- 
2.1.4



[PATCH] drm: fix sparse warnings on undeclared symbols in crc debugfs

2016-10-18 Thread Jani Nikula
Fixes sparse warnings:

drivers/gpu/drm/drm_debugfs_crc.c:118:30: warning: symbol
'drm_crtc_crc_control_fops' was not declared. Should it be static?

drivers/gpu/drm/drm_debugfs_crc.c:264:30: warning: symbol
'drm_crtc_crc_data_fops' was not declared. Should it be static?

drivers/gpu/drm/drm_debugfs_crc.c:281:5: warning: symbol
'drm_debugfs_crtc_crc_add' was not declared. Should it be static?

Fixes: 9edbf1fa600a ("drm: Add API for capturing frame CRCs")
Cc: Benjamin Gaignard 
Cc: Daniel Vetter 
Cc: Emil Velikov 
Cc: Tomeu Vizoso 
Signed-off-by: Jani Nikula 
---
 drivers/gpu/drm/drm_debugfs_crc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_debugfs_crc.c 
b/drivers/gpu/drm/drm_debugfs_crc.c
index 4129405d17c0..00e771fb7df2 100644
--- a/drivers/gpu/drm/drm_debugfs_crc.c
+++ b/drivers/gpu/drm/drm_debugfs_crc.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include "drm_internal.h"

 /**
  * DOC: CRC ABI
@@ -115,7 +116,7 @@ static ssize_t crc_control_write(struct file *file, const 
char __user *ubuf,
return len;
 }

-const struct file_operations drm_crtc_crc_control_fops = {
+static const struct file_operations drm_crtc_crc_control_fops = {
.owner = THIS_MODULE,
.open = crc_control_open,
.read = seq_read,
@@ -261,7 +262,7 @@ static ssize_t crtc_crc_read(struct file *filep, char 
__user *user_buf,
return LINE_LEN(crc->values_cnt);
 }

-const struct file_operations drm_crtc_crc_data_fops = {
+static const struct file_operations drm_crtc_crc_data_fops = {
.owner = THIS_MODULE,
.open = crtc_crc_open,
.read = crtc_crc_read,
-- 
2.1.4



[PATCH] drm: fix sparse warnings on undeclared symbols in crc debugfs

2016-10-18 Thread Chris Wilson
On Tue, Oct 18, 2016 at 02:28:35PM +0300, Jani Nikula wrote:
> Fixes sparse warnings:
> 
> drivers/gpu/drm/drm_debugfs_crc.c:118:30: warning: symbol
> 'drm_crtc_crc_control_fops' was not declared. Should it be static?
> 
> drivers/gpu/drm/drm_debugfs_crc.c:264:30: warning: symbol
> 'drm_crtc_crc_data_fops' was not declared. Should it be static?
> 
> drivers/gpu/drm/drm_debugfs_crc.c:281:5: warning: symbol
> 'drm_debugfs_crtc_crc_add' was not declared. Should it be static?
> 
> Fixes: 9edbf1fa600a ("drm: Add API for capturing frame CRCs")
> Cc: Benjamin Gaignard 
> Cc: Daniel Vetter 
> Cc: Emil Velikov 
> Cc: Tomeu Vizoso 
> Signed-off-by: Jani Nikula 
Reviewed-by: Chris Wilson 
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


[PATCH v5 00/13] Centralize format information

2016-10-18 Thread Ville Syrjälä
On Tue, Oct 18, 2016 at 01:41:08AM +0300, Laurent Pinchart wrote:
> Hello,
> 
> Various pieces of information about DRM formats (number of planes, color
> depth, chroma subsampling, ...) are scattered across different helper
> functions in the DRM core. Callers of those functions often need to access
> more than a single parameter of the format, leading to inefficiencies due to
> multiple lookups.
> 
> This patch series addresses this issue by centralizing all format information
> in a single data structure (01/13). It reimplements the existing format helper
> functions based on that structure (02/13) and converts the DRM core code to
> use the new structure (03/13). The DRM core now WARNs when a driver tries to
> query information about an unsupported format (04/13).
> 
> The second part of the patch series removes the drm_fb_get_bpp_depth() legacy
> function that shouldn't be used directly by drivers. It modifies all its users
> to use the appropriate API instead (05/13 to 12/13) and finally merges the
> function into its only caller in the DRM core (13/13).
> 
> The new API is also useful for drivers as shown by the "[PATCH v2 00/20] OMAP
> DRM fixes and improvements" patch series previously posted.
> 
> All patches have been acked, the series is ready to be merged for v4.10.

BTW and idea I had recently is that we could store the pointer to the
format info into drm_framebuffer, and then a lot of the
drm_format_...() calls could just vanish, or if the information we
need isn't directly stored in the info structure we'd just need a small
function that takes the entire drm_framebuffer or just the format info
struct and computes what we need. Would avoid having to sprinkle
drm_format_info() calls into the drivers.

-- 
Ville Syrjälä
Intel OTC


[PATCH 1/2] drm: make is_lspcon_adaptor static

2016-10-18 Thread Sharma, Shashank
Reviewed-by: Shashank Sharma

Regards
Shashank
-Original Message-
From: Nikula, Jani 
Sent: Tuesday, October 18, 2016 4:52 PM
To: intel-gfx at lists.freedesktop.org
Cc: Nikula, Jani ; Vivi, Rodrigo ; Sharma, Shashank ; dri-devel at 
lists.freedesktop.org
Subject: [PATCH 1/2] drm: make is_lspcon_adaptor static

Fixes sparse warning:

drivers/gpu/drm/drm_dp_dual_mode_helper.c:151:6: warning: symbol 
'is_lspcon_adaptor' was not declared. Should it be static?

Fixes: 056996b95686 ("drm: Helper for lspcon in drm_dp_dual_mode")
Cc: Rodrigo Vivi 
Cc: Shashank Sharma 
Cc: 
Signed-off-by: Jani Nikula 

---

n.b. 056996b95686 ("drm: Helper for lspcon in drm_dp_dual_mode") has been 
merged via drm-intel tree
---
 drivers/gpu/drm/drm_dp_dual_mode_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c 
b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
index a7aeb1ec852c..2624e266abbd 100644
--- a/drivers/gpu/drm/drm_dp_dual_mode_helper.c
+++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
@@ -148,8 +148,8 @@ static bool is_type2_adaptor(uint8_t adaptor_id)
  DP_DUAL_MODE_REV_TYPE2);
 }

-bool is_lspcon_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN],
-   const uint8_t adaptor_id)
+static bool is_lspcon_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN],
+ const uint8_t adaptor_id)
 {
return is_hdmi_adaptor(hdmi_id) &&
(adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
--
2.1.4



[PATCH] dma-buf/fence-array: fix deadlock in fence-array

2016-10-18 Thread Rob Clark
On Tue, Oct 18, 2016 at 3:41 AM, Daniel Vetter  wrote:
> On Mon, Oct 17, 2016 at 05:44:48PM -0200, Gustavo Padovan wrote:
>> 2016-10-17 Chris Wilson :
>>
>> > On Mon, Oct 17, 2016 at 02:59:52PM -0400, Rob Clark wrote:
>> > > On Mon, Oct 17, 2016 at 2:52 PM, Gustavo Padovan > > > padovan.org> wrote:
>> > > > 2016-10-17 Rob Clark :
>> > > >
>> > > >> Currently with fence-array, we have a potential deadlock situation.  
>> > > >> If we
>> > > >> fence_add_callback() on an array-fence, the array-fence's lock is 
>> > > >> acquired
>> > > >> first, and in it's ->enable_signaling() callback, it will install 
>> > > >> cb's on
>> > > >> it's array-member fences, so the array-member's lock is acquired 
>> > > >> second.
>> > > >>
>> > > >> But in the signal path, the array-member's lock is acquired first, 
>> > > >> and the
>> > > >> array-fence's lock acquired second.
>> > > >>
>> > > >> To solve that, always enabling signaling up-front (in the fence_array
>> > > >> constructor) without the fence_array's lock held.
>> > > >
>> > > > Do we always want to enable signaling for arrays? One of the things we
>> > > > removed from the Sync Framework was the need to enable signalling at
>> > > > creation time.
>> > > >
>> > > > Just merging fencing doesn't mean you want signaling, that is supposed
>> > > > to happen only when poll() is called on the sync file.
>> > >
>> > > It was something Maarten suggested, as an alternative to introducing a
>> > > wq into the mix or worse hacks..
>> > > https://lists.freedesktop.org/archives/dri-devel/2016-October/120868.html
>> > >
>> > > I think I agree with him that it is an optimization that is unlikely
>> > > to be useful in the case of fence-arrays.  If you need to wait on
>> > > multiple fences from different timelines, you probably aren't doing
>> > > that in hw.
>> >
>> > For 2 i915 fences, I definitely do not want signaling enabled at
>> > creation time.
>>
>> Should we add arg flags for fence_array_create()? We already have
>> signal_on_any flag there. We can convert that arg to a bitfield.
>
> The thing creating the array might not be aware of the fences contained
> therein, e.g. SYNC_FILE_MERGE. Imo we really need to keep the lazy
> signalling enabling properties of fences.

Well, in all my cases, if you end up with a fence-array, it means you
are waiting on cpu, so enabling signalling now vs later doesn't
matter.

But Chris mentioned on IRC that he does actually have a case where he
can wait in hw on fences from multiple contexts (ie. meaning MERGE
would create a fence-array).. so in that case it does still make sense
to defer enable-signalling.  So I guess back to the wq approach..

BR,
-R

> -Daniel
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch


[PATCH 02/10] dim: Autocheck for up-to-dateness

2016-10-18 Thread Daniel Vetter
Exits script to annoy people roughly every 100th time ...

Also switch to the magic @{upstream} reference, in case the remote is
not called origin (which is pretty normal in case of using git
worktree).

Signed-off-by: Daniel Vetter 
---
 dim | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/dim b/dim
index 57ad4fcf9767..192d6ee10838 100755
--- a/dim
+++ b/dim
@@ -176,13 +176,17 @@ function dim_uptodate
exit 1
fi

-   if ! git --git-dir=$DIM_PREFIX/maintainer-tools/.git show 
origin/maintainer-tools:dim |\
+   if ! git --git-dir=$DIM_PREFIX/maintainer-tools/.git show 
@{upstream}:dim |\
diff "$using" - >& /dev/null; then
echo "$dim: not running upstream version of the script." >&2
exit 1
fi
 }

+if [[ "$((`date +%s` % 100))" -eq "0" ]] ; then
+dim_uptodate
+fi
+
 # get message id from file
 # $1 = file
 message_get_id ()
-- 
2.9.3



[PATCH 01/10] dim: Extract TODO

2016-10-18 Thread Daniel Vetter
Just maybe a bit more visibility, the scripts are growing.

Signed-off-by: Daniel Vetter 
---
 TODO | 27 +++
 dim  | 17 -
 qf   | 11 ---
 3 files changed, 27 insertions(+), 28 deletions(-)
 create mode 100644 TODO

diff --git a/TODO b/TODO
new file mode 100644
index ..ac0f27763dfa
--- /dev/null
+++ b/TODO
@@ -0,0 +1,27 @@
+dim:
+- extract the integration tree logic and make it generally useful, maybe for a
+  drm-integration tree ...
+- Improve nightly-forget to forget a specific merge instead of just the first
+  dinq/dif merge.
+- add option to check-patch to check stdin
+- integrate ninja-check? Or too much checkers considered harmful?
+  
https://lists.linuxfoundation.org/pipermail/ksummit-discuss/2014-May/000554.html
+- add patchwork Link: also after manually resolving conflicts in drm
+  apply-resolved
+- pull in dim extract-tags tool from Ville
+- allow dim rebuild-nightly to pull branches from local trees in dry-run mode.
+  This is useful to confirm a backmerge is indeed correct, by comparing the
+  resulting -nightly with the old one. Current the branch must be pushed out
+  first for rebuild-nightly to pick it up, which means the merge can't be
+  fixed any more.
+
+qf:
+- get better at preventing and cleaning up a mess when switching branches
+  while there's still applied quilt patches around ...
+- combine quilt annotate and git blame into one tool
+- use the index a bit more to e.g. stage all applied quilt patches, then use
+  the output of git diff to refresh a quilt patch
+- use git commit-tree and git write-tree in the setup code instead of the
+  current high-level hacks
+- track/restore the topmost patch maybe?
+- synchronize quilt notes in qf push and qf fetch
diff --git a/dim b/dim
index 5fb3a0fee7ff..57ad4fcf9767 100755
--- a/dim
+++ b/dim
@@ -27,23 +27,6 @@

 # drm-intel-next maintainer script

-# TODO
-# - extract the integration tree logic and make it generally useful, maybe for 
a
-#   drm-integration tree ...
-# - Improve nightly-forget to forget a specific merge instead of just the first
-#   dinq/dif merge.
-# - add option to check-patch to check stdin
-# - integrate ninja-check? Or too much checkers considered harmful?
-#   
https://lists.linuxfoundation.org/pipermail/ksummit-discuss/2014-May/000554.html
-# - add patchwork Link: also after manually resolving conflicts in drm
-#   apply-resolved
-# - pull in dim extract-tags tool from Ville
-# - allow dim rebuild-nightly to pull branches from local trees in dry-run 
mode.
-#   This is useful to confirm a backmerge is indeed correct, by comparing the
-#   resulting -nightly with the old one. Current the branch must be pushed out
-#   first for rebuild-nightly to pick it up, which means the merge can't be
-#   fixed any more.
-
 # fail on any goof-up
 set -e

diff --git a/qf b/qf
index 4e9cb03f31fe..31b9f3bae0a2 100755
--- a/qf
+++ b/qf
@@ -26,17 +26,6 @@

 # quilt git flow script

-# TODO
-# - get better at preventing and cleaning up a mess when switching branches
-# while there's still applied quilt patches around ...
-# - combine quilt annotate and git blame into one tool
-# - use the index a bit more to e.g. stage all applied quilt patches, then use
-# the output of git diff to refresh a quilt patch
-# - use git commit-tree and git write-tree in the setup code instead of the
-# current high-level hacks
-# - track/restore the topmost patch maybe?
-# - synchronize quilt notes in qf push and qf fetch
-
 # config
 QUILT_PREFIX=quilt/

-- 
2.9.3



[PATCH 10/10] dim: s/drm-nightly/drm-tip

2016-10-18 Thread Daniel Vetter
tip = testing and integration pile

Also rename drm-intel-rerere directory to drm-rerere.

Signed-off-by: Daniel Vetter 
---
 dim| 48 
 dim.rst| 16 +++-
 dimrc.sample   |  2 +-
 drm-intel-flow.dot | 18 +-
 drm-intel.rst  | 20 +++-
 5 files changed, 52 insertions(+), 52 deletions(-)

diff --git a/dim b/dim
index de01f0addeaf..fd3800e8c078 100755
--- a/dim
+++ b/dim
@@ -78,7 +78,7 @@ dim=$(basename $0)
 today=`date +%Y-%m-%d`

 drm_intel_ssh=ssh://git.freedesktop.org/git/drm-intel
-drm_nightly_ssh=ssh://git.freedesktop.org/git/drm-nightly
+drm_tip_ssh=ssh://git.freedesktop.org/git/drm-tip
 drm_intel_git=git://anongit.freedesktop.org/drm-intel
 drm_upstream_git=git://people.freedesktop.org/~airlied/linux
 
linux_upstream_git=git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
@@ -151,7 +151,7 @@ fi
 #

 if [ "$subcommand" != "setup" -a "$subcommand" != "help" -a "$subcommand" != 
"usage" ]; then
-   for d in $DIM_PREFIX $DIM_PREFIX/$DIM_DRM_INTEL 
$DIM_PREFIX/drm-intel-rerere $DIM_PREFIX/drm-intel-nightly; do
+   for d in $DIM_PREFIX $DIM_PREFIX/$DIM_DRM_INTEL $DIM_PREFIX/drm-rerere 
$DIM_PREFIX/drm-tip; do
if [ ! -d $d ]; then
echo "$d is missing, please check your configuration 
and/or run dim setup"
exit 1
@@ -162,7 +162,7 @@ if [ "$subcommand" != "setup" -a "$subcommand" != "help" -a 
"$subcommand" != "us
# Internal configuration that depends on a sane setup.
#

-   dim_branches=`(source $DIM_PREFIX/drm-intel-rerere/nightly.conf ; echo 
$nightly_branches) | \
+   dim_branches=`(source $DIM_PREFIX/drm-rerere/nightly.conf ; echo 
$nightly_branches) | \
xargs -n 1 echo | grep '^origin' | sed -e 's/^origin\///'`
 fi

@@ -244,7 +244,7 @@ function map_nightly_remote

 function update_linux_next
 {
-   cd $DIM_PREFIX/drm-intel-nightly
+   cd $DIM_PREFIX/drm-tip

local nightly_origin=`map_nightly_remote origin`

@@ -283,8 +283,8 @@ function check_conflicts

 function rr_cache_dir
 {
-   if [ -d $DIM_PREFIX/drm-intel-nightly/.git/rr-cache/ ] ; then
-   echo $DIM_PREFIX/drm-intel-nightly/.git/rr-cache/
+   if [ -d $DIM_PREFIX/drm-tip/.git/rr-cache/ ] ; then
+   echo $DIM_PREFIX/drm-tip/.git/rr-cache/
else
echo $DIM_PREFIX/$DIM_DRM_INTEL/.git/rr-cache/
fi
@@ -292,7 +292,7 @@ function rr_cache_dir

 function update_rerere_cache
 {
-   cd $DIM_PREFIX/drm-intel-rerere/
+   cd $DIM_PREFIX/drm-rerere/
git pull
cp rr-cache/* `rr_cache-dir` -r
cd -
@@ -300,12 +300,12 @@ function update_rerere_cache

 function dim_rebuild_nightly
 {
-   local integration_branch=drm-intel-nightly
+   local integration_branch=drm-tip
local specfile=`mktemp`
local time="`date --utc +%Yy-%mm-%dd-%Hh-%Mm-%Ss` UTC"
local first=1

-   local rerere=$DIM_PREFIX/drm-intel-rerere
+   local rerere=$DIM_PREFIX/drm-rerere

cd $rerere
if [[ `git status --porcelain | grep -v "^[ ?][ ?]" | wc -l` -gt 0 ]]; 
then
@@ -512,7 +512,7 @@ function dim_apply_next_fixes

 function dim_cherry_pick
 {
-   local nightly_remote=`get_remote_name $drm_nightly_ssh`
+   local nightly_remote=`get_remote_name $drm_tip_ssh`

if [[ "x$1" = "x" ]]; then
echo "usage: $dim $subcommand commit-ish"
@@ -524,7 +524,7 @@ function dim_cherry_pick
# need latest -nightly
git fetch $nightly_remote
echo Possible fixup patches for your cherry-pick:
-   git log --grep=$sha_short --pretty=oneline 
$sha..$nightly_remote/drm-intel-nightly
+   git log --grep=$sha_short --pretty=oneline $sha..$nightly_remote/drm-tip
$DRY git cherry-pick -s -x -e $1
 }

@@ -649,7 +649,7 @@ function dim_create_branch

$DRY git branch $branch $start
git push $DRY_RUN $DIM_DRM_INTEL_REMOTE +$branch --set-upstream
-   cd $DIM_PREFIX/drm-intel-rerere
+   cd $DIM_PREFIX/drm-rerere
$DRY echo "nightly_branches=\"\$nightly_branches origin/$branch\"" \
 >> nightly.conf
$DRY git add nightly.conf
@@ -674,10 +674,10 @@ function dim_remove_branch
rm -R $DIM_PREFIX/$branch
fi

-   cd $DIM_PREFIX/drm-intel-nightly
+   cd $DIM_PREFIX/drm-tip
git push $DRY_RUN origin --delete $branch
$DRY git fetch origin --prune
-   cd $DIM_PREFIX/drm-intel-rerere
+   cd $DIM_PREFIX/drm-rerere
full_branch="origin/$branch"
$DRY sed -e "/${full_branch//\//\\\/}/d" -i nightly.conf
$DRY git add nightly.conf
@@ -893,17 +893,17 @@ function dim_for_each_workdirs

 function dim_update_next
 {
-   local nightly_remote=`get_remote_name $drm_nightly_ssh`
+   local nightly_remote=`get_remote_name $drm_tip_ssh`

assert_branch drm-in

[PATCH 03/10] dim: echoerr helper for printing to stderr

2016-10-18 Thread Daniel Vetter
Signed-off-by: Daniel Vetter 
---
 dim | 19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/dim b/dim
index 192d6ee10838..2601bb7dbbad 100755
--- a/dim
+++ b/dim
@@ -102,12 +102,17 @@ DRY=
 FORCE=
 HELP=

+function echoerr
+{
+   echo "$@" >&2
+}
+
 function warn_or_fail
 {
if [[ $FORCE ]] ; then
-   echo WARNING: $1, but continuing
+   echoerr WARNING: $1, but continuing
else
-   echo ERROR: $1, aborting
+   echoerr ERROR: $1, aborting
exit 1
fi
 }
@@ -128,7 +133,7 @@ while getopts hdfi opt; do
HELP=1
;;
*)
-   echo "See '$dim help' for more information." >&2
+   echoerr "See '$dim help' for more information."
exit
esac
 done
@@ -167,18 +172,18 @@ function dim_uptodate
local using="${BASH_SOURCE[0]}"

if [[ ! -e "$using" ]]; then
-   echo "$dim: could not figure out the version being used 
($using)." >&2
+   echoerr "$dim: could not figure out the version being used 
($using)."
exit 1
fi

if [[ ! -e "$DIM_PREFIX/maintainer-tools/.git" ]]; then
-   echo "$dim: could not find the upstream repo for $dim." >&2
+   echoerr "$dim: could not find the upstream repo for $dim."
exit 1
fi

if ! git --git-dir=$DIM_PREFIX/maintainer-tools/.git show 
@{upstream}:dim |\
diff "$using" - >& /dev/null; then
-   echo "$dim: not running upstream version of the script." >&2
+   echoerr "$dim: not running upstream version of the script."
exit 1
fi
 }
@@ -1280,6 +1285,6 @@ subcmd_func=dim_${subcmd//-/_}
 if declare -f $subcmd_func >/dev/null; then
$subcmd_func "$@"
 else
-   echo "$dim: '$subcommand' is not a dim command." >&2
+   echoerr "$dim: '$subcommand' is not a dim command."
dim_usage
 fi
-- 
2.9.3



[PATCH 05/10] dim: support git worktree for aux checkouts

2016-10-18 Thread Daniel Vetter
If available by default. This saves quite a pile of disk-space that
imo making it the default is justified.

Note that this will break the rebuild-nightly script for now,
follow-up patches will fix that.

Signed-off-by: Daniel Vetter 
---
 dim | 23 ---
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/dim b/dim
index 90eb553c6575..80baf24e4ad7 100755
--- a/dim
+++ b/dim
@@ -1072,15 +1072,24 @@ function setup_aux_checkout # name remote
echo "Setting up $dir ..."

if [ ! -d $dir ]; then
-   git clone --reference=$DIM_PREFIX/$DIM_DRM_INTEL/.git 
$remote_url $dir
-   cd $dir
-   git config remote.origin.url $remote_url
-   echo "$DIM_PREFIX/$DIM_DRM_INTEL/.git/objects" > 
.git/objects/info/alternates
-   git repack -a -d -l
-   remote=origin
+   if git help worktree &> /dev/null ; then
+   cd $DIM_PREFIX/$DIM_DRM_INTEL
+   remote=`get_remote_name $remote_url`
+   if ! git branch | grep $name > /dev/null ; then
+   git branch --track $name $remote/$name
+   fi
+   git worktree add ../$dir $name
+   else
+   git clone --reference=$DIM_PREFIX/$DIM_DRM_INTEL/.git 
$remote_url $dir
+   cd $dir
+   git config remote.origin.url $remote_url
+   echo "$DIM_PREFIX/$DIM_DRM_INTEL/.git/objects" > 
.git/objects/info/alternates
+   git repack -a -d -l
+   remote=origin
+   fi
else
cd $dir
-   remote=`get_remote_name $drm_intel_ssh`
+   remote=`get_remote_name $remote_url`
fi
if ! git branch | grep $name > /dev/null ; then
git checkout -t $remote/$name
-- 
2.9.3



[PATCH 04/10] dim: autodetect remotes, first part for dim_setup

2016-10-18 Thread Daniel Vetter
The goals here are multiple:
- simpler configuration through autodetection
- allows seamless upgrading to git worktree for the aux checkouts
- eventually I want to split up drm-misc into a separate remote ...

And yes this is just a start.

v2: Print errors to stderr, otherwise they can't be seen when directly
assigning the result of get_remote_name to a variable.

Signed-off-by: Daniel Vetter 
---
 dim | 112 +++-
 1 file changed, 58 insertions(+), 54 deletions(-)

diff --git a/dim b/dim
index 2601bb7dbbad..90eb553c6575 100755
--- a/dim
+++ b/dim
@@ -192,6 +192,24 @@ if [[ "$((`date +%s` % 100))" -eq "0" ]] ; then
 dim_uptodate
 fi

+function get_remote_name
+{
+   local remote_url=$1
+
+   local remote=`git remote -v | grep $remote_url | \
+   head -n1 | sed -e 's/^\(.*\)\t.*/\1/'`
+
+   if [[ $remote == "" ]] ; then
+   echoerr No git remote for $remote_url found in `pwd`.
+   echoerr Please set it up using
+   echoerr $ git remote add '' $remote_url
+   echoerr with a name of your choice.
+   exit 1
+   fi
+
+   echo $remote
+}
+
 # get message id from file
 # $1 = file
 message_get_id ()
@@ -1044,8 +1062,36 @@ function dim_update_branches
update_rerere_cache
 }

+function setup_aux_checkout # name remote
+{
+   local name=$1
+   local remote_url=$2
+   local dir=$3
+   local remote
+
+   echo "Setting up $dir ..."
+
+   if [ ! -d $dir ]; then
+   git clone --reference=$DIM_PREFIX/$DIM_DRM_INTEL/.git 
$remote_url $dir
+   cd $dir
+   git config remote.origin.url $remote_url
+   echo "$DIM_PREFIX/$DIM_DRM_INTEL/.git/objects" > 
.git/objects/info/alternates
+   git repack -a -d -l
+   remote=origin
+   else
+   cd $dir
+   remote=`get_remote_name $drm_intel_ssh`
+   fi
+   if ! git branch | grep $name > /dev/null ; then
+   git checkout -t $remote/$name
+   fi
+   cd ..
+}
+
 function dim_setup
 {
+   local remote
+
if [ ! -d $DIM_PREFIX ]; then
echo "please set up your repository directory with:"
echo "mkdir -p $DIM_PREFIX"
@@ -1062,76 +1108,34 @@ function dim_setup
exit 1
fi
cd $DIM_DRM_INTEL
-   if ! git remote -v | grep "^origin[[:space:]]" | grep 
$linux_upstream_git > /dev/null; then
-   echo "please set up remote origin for $linux_upstream_git"
-   exit 1
-   fi
-   if ! git remote -v | grep "^$DIM_DRM_INTEL_REMOTE[[:space:]]" | grep 
$drm_intel_ssh > /dev/null; then
-   echo "please set up remote $DIM_DRM_INTEL_REMOTE for 
$drm_intel_ssh with:"
-   echo "git remote add $DIM_DRM_INTEL_REMOTE $drm_intel_ssh"
-   echo "or update your configuration."
-   exit 1
-   fi
-   if ! git remote -v | grep "^$DIM_DRM_UPSTREAM_REMOTE[[:space:]]" | grep 
$drm_upstream_git > /dev/null; then
-   echo "please set up remote $DIM_DRM_UPSTREAM_REMOTE for 
$drm_upstream_git with:"
-   echo "git remote add $DIM_DRM_UPSTREAM_REMOTE 
$drm_upstream_git"
-   echo "or update your configuration."
-   exit 1
-   fi
-   cd ..

-   echo "Setting up maintainer-tools ..."
-   if [ ! -d maintainer-tools ]; then
-   git clone --reference=$DIM_PREFIX/$DIM_DRM_INTEL/.git 
$drm_intel_ssh maintainer-tools
-   fi
-   cd maintainer-tools
-   git config remote.origin.url $drm_intel_ssh
-   echo "$DIM_PREFIX/$DIM_DRM_INTEL/.git/objects" > 
.git/objects/info/alternates
-   git repack -a -d -l
-   if ! git branch | grep maintainer-tools > /dev/null ; then
-   git checkout -t origin/maintainer-tools
-   fi
-   cd ..
+   # check remote configuration
+   remote=`get_remote_name $linux_upstream_git`
+   remote=`get_remote_name $drm_intel_ssh`
+   remote=`get_remote_name $drm_upstream_git`

-   echo "Setting up drm-intel-rerere ..."
-   if [ ! -d drm-intel-rerere ]; then
-   git clone --reference=$DIM_PREFIX/$DIM_DRM_INTEL/.git 
$drm_intel_ssh drm-intel-rerere
-   fi
-   cd drm-intel-rerere
-   git config remote.origin.url $drm_intel_ssh
-   echo "$DIM_PREFIX/$DIM_DRM_INTEL/.git/objects" > 
.git/objects/info/alternates
-   git repack -a -d -l
-   if ! git branch | grep rerere-cache > /dev/null ; then
-   git checkout -t origin/rerere-cache
-   fi
cd ..

-   echo "Setting up drm-intel-nightly ..."
-   if [ ! -d drm-intel-nightly ]; then
-   git clone --reference=$DIM_PREFIX/$DIM_DRM_INTEL/.git 
$drm_intel_ssh drm-intel-nightly
-   fi
+   setup_aux_checkout maintainer-tools $drm_intel_ssh maintainer-tools
+
+   setup_au

[PATCH 06/10] dim: Nuke nightly-forget

2016-10-18 Thread Daniel Vetter
With our proliferation of branches it's become long useless. Nowadays
my MO is to revert the offending commit in the rerere-cache branch
explicitly, remove drm-intel-nightly/.git/rr-cache and then re-run
rebuild-nightly. That works much better, hence nuke this helper.

Signed-off-by: Daniel Vetter 
---
 TODO | 2 --
 dim  | 9 -
 2 files changed, 11 deletions(-)

diff --git a/TODO b/TODO
index ac0f27763dfa..c1c6e20eb0e3 100644
--- a/TODO
+++ b/TODO
@@ -1,8 +1,6 @@
 dim:
 - extract the integration tree logic and make it generally useful, maybe for a
   drm-integration tree ...
-- Improve nightly-forget to forget a specific merge instead of just the first
-  dinq/dif merge.
 - add option to check-patch to check stdin
 - integrate ninja-check? Or too much checkers considered harmful?
   
https://lists.linuxfoundation.org/pipermail/ksummit-discuss/2014-May/000554.html
diff --git a/dim b/dim
index 80baf24e4ad7..48d5e7b6477a 100755
--- a/dim
+++ b/dim
@@ -395,15 +395,6 @@ function dim_rebuild_nightly
update_linux_next
 }

-function dim_nightly_forget
-{
-   cd $DIM_PREFIX/drm-intel-nightly
-   git fetch origin >& /dev/null
-   git reset --hard origin/drm-intel-next-queued >& /dev/null
-   git merge origin/drm-intel-fixes
-   git rerere forget
-}
-
 # push branch $1, rebuild nightly. the rest of the arguments are passed to git
 # push.
 function dim_push_branch
-- 
2.9.3



[PATCH 08/10] dim: remove integration-tree remotes

2016-10-18 Thread Daniel Vetter
With the remotes stored in nightly.conf and git worktrees we can avoid
hard-coding them in even more places.

Signed-off-by: Daniel Vetter 
---
 dim | 12 
 1 file changed, 12 deletions(-)

diff --git a/dim b/dim
index f9b28d5fd241..20a3143a5c1e 100755
--- a/dim
+++ b/dim
@@ -80,8 +80,6 @@ today=`date +%Y-%m-%d`
 drm_intel_ssh=ssh://git.freedesktop.org/git/drm-intel
 drm_intel_git=git://anongit.freedesktop.org/drm-intel
 drm_upstream_git=git://people.freedesktop.org/~airlied/linux
-sound_upstream_git=git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
-driver_core_upstream_git=git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
 
linux_upstream_git=git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

 # email aliases
@@ -1151,16 +1149,6 @@ function dim_setup
else
remote=`get_remote_name $drm_upstream_git`
fi
-   if git remote | grep sound-upstream > /dev/null ; then
-   git config remote.sound-upstream.url $sound_upstream_git
-   else
-   remote=`get_remote_name $sound_upstream_git`
-   fi
-   if git remote | grep driver-core-upstream > /dev/null ; then
-   git config remote.driver-core-upstream.url 
$driver_core_upstream_git
-   else
-   remote=`get_remote_name $driver_core_upstream_git`
-   fi

echo "dim setup successfully completed!"
 }
-- 
2.9.3



[PATCH 09/10] dim: Split out drm-nightly.git

2016-10-18 Thread Daniel Vetter
This is a prep step to eventually split out the drm-misc branches all
into their own repo. To get there we first need to split out the
integration tree mangling.

Since dim doesn't auto-update and since the transition is a good
reason to switch over to worktrees and it's tricky it's not scripted.
The following needs to be done when dim rebuild-nightly fails:

- Make sure you have the latest dim version.

- Good to also check you have a recent-ish git. Latest dim supports
  git worktree to save on disk space needed for .git metadata. It's
  much more robust than the git alternates storage trick we've used
  thus far. Note that git worktree is still optional (but that's not a
  recommended setup).

- Delete $DIM_PREFIX/{drm-intel-rerere,drm-intel-nightly,maintainer-tools}
  It's not strictly needed to kill the maintainer-tools checkout too,
  but might as well switch it over to git worktree too.

- Make sure you don't have any branches left over for drm-intel-rerere
  and drm-intel-nightly anywhere (since they need to switch their
  remotes).

- run dim setup and enjoy the new awesomeness.

If it breaks, I'm guilty ;-)

Signed-off-by: Daniel Vetter 
---
 dim | 22 +++---
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/dim b/dim
index 20a3143a5c1e..de01f0addeaf 100755
--- a/dim
+++ b/dim
@@ -78,6 +78,7 @@ dim=$(basename $0)
 today=`date +%Y-%m-%d`

 drm_intel_ssh=ssh://git.freedesktop.org/git/drm-intel
+drm_nightly_ssh=ssh://git.freedesktop.org/git/drm-nightly
 drm_intel_git=git://anongit.freedesktop.org/drm-intel
 drm_upstream_git=git://people.freedesktop.org/~airlied/linux
 
linux_upstream_git=git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
@@ -511,6 +512,8 @@ function dim_apply_next_fixes

 function dim_cherry_pick
 {
+   local nightly_remote=`get_remote_name $drm_nightly_ssh`
+
if [[ "x$1" = "x" ]]; then
echo "usage: $dim $subcommand commit-ish"
exit 1
@@ -519,9 +522,9 @@ function dim_cherry_pick
sha_short=${sha:0:8}

# need latest -nightly
-   git fetch $DIM_DRM_INTEL_REMOTE
+   git fetch $nightly_remote
echo Possible fixup patches for your cherry-pick:
-   git log --grep=$sha_short --pretty=oneline 
$sha..$DIM_DRM_INTEL_REMOTE/drm-intel-nightly
+   git log --grep=$sha_short --pretty=oneline 
$sha..$nightly_remote/drm-intel-nightly
$DRY git cherry-pick -s -x -e $1
 }

@@ -890,15 +893,17 @@ function dim_for_each_workdirs

 function dim_update_next
 {
+   local nightly_remote=`get_remote_name $drm_nightly_ssh`
+
assert_branch drm-intel-next-queued

git pull --ff-only

-   if ! git branch --merged $DIM_DRM_INTEL_REMOTE/drm-intel-nightly | grep 
drm-intel-fixes &> /dev/null ; then
+   if ! git branch --merged $nightly_remote/drm-intel-nightly | grep 
drm-intel-fixes &> /dev/null ; then
echo "drm-intel-fixes not merged into -nigthly, please update!"
exit 2
fi
-   if ! git branch --merged $DIM_DRM_INTEL_REMOTE/drm-intel-nightly | grep 
drm-intel-next-queued &> /dev/null ; then
+   if ! git branch --merged $nightly_remote/drm-intel-nightly | grep 
drm-intel-next-queued &> /dev/null ; then
echo "drm-intel-next-queued not merged into -nigthly, please 
update!"
exit 2
fi
@@ -920,6 +925,8 @@ function dim_update_next

 function dim_update_next_continue
 {
+   local nightly_remote=`get_remote_name $drm_nightly_ssh`
+
assert_branch drm-intel-next-queued

git push $DRY_RUN -f $DIM_DRM_INTEL_REMOTE 
drm-intel-next-queued:drm-intel-next
@@ -928,7 +935,7 @@ function dim_update_next_continue
git push $DRY_RUN -f $DIM_DRM_INTEL_REMOTE $tag

echo "Updating -testing to latest -nightly"
-   git push $DRY_RUN $DIM_DRM_INTEL_REMOTE 
+$DIM_DRM_INTEL_REMOTE/drm-intel-nightly:drm-intel-testing
+   git push $DRY_RUN $DIM_DRM_INTEL_REMOTE 
+$nightly_remote/drm-intel-nightly:drm-intel-testing
$DRY git tag -f drm-intel-testing-$today 
$DIM_DRM_INTEL_REMOTE/drm-intel-testing
$DRY git push -f $DIM_DRM_INTEL_REMOTE drm-intel-testing-$today

@@ -1134,15 +1141,16 @@ function dim_setup
# check remote configuration
remote=`get_remote_name $linux_upstream_git`
remote=`get_remote_name $drm_intel_ssh`
+   remote=`get_remote_name $drm_nightly_ssh`
remote=`get_remote_name $drm_upstream_git`

cd ..

setup_aux_checkout maintainer-tools $drm_intel_ssh maintainer-tools

-   setup_aux_checkout rerere-cache $drm_intel_ssh drm-intel-rerere
+   setup_aux_checkout rerere-cache $drm_nightly_ssh drm-intel-rerere

-   setup_aux_checkout drm-intel-nightly $drm_intel_ssh drm-intel-nightly
+   setup_aux_checkout drm-intel-nightly $drm_nightly_ssh drm-intel-nightly
cd drm-intel-nightly
if git remote | grep drm-upstream > /dev/null ; then
git config remote

[PATCH 07/10] dim: autodetect branches in rebuild-nightly

2016-10-18 Thread Daniel Vetter
Needs new url-mapping information in nightly.conf to work properly.

Signed-off-by: Daniel Vetter 
---
 dim | 48 
 1 file changed, 36 insertions(+), 12 deletions(-)

diff --git a/dim b/dim
index 48d5e7b6477a..f9b28d5fd241 100755
--- a/dim
+++ b/dim
@@ -235,20 +235,30 @@ function dim_commit_add_tag
done
 }

+function map_nightly_remote
+{
+   local nightly_remote=$1
+   local remote_url=`eval echo 
"\\\$nightly_remote_url_${nightly_remote/-/_}"`
+
+   get_remote_name $remote_url
+}
+
 function update_linux_next
 {
cd $DIM_PREFIX/drm-intel-nightly

+   local nightly_origin=`map_nightly_remote origin`
+
# always update drm-intel-fixes
echo -n "Pushing drm-intel-fixes to for-linux-next-fixes... "
-   git push $DRY_RUN origin +origin/drm-intel-fixes:for-linux-next-fixes 
>& /dev/null
+   git push $DRY_RUN $nightly_origin 
+$nightly_origin/drm-intel-fixes:for-linux-next-fixes >& /dev/null
echo "Done."

-   if git merge-base --is-ancestor origin/drm-intel-next-fixes 
origin/drm-intel-fixes ; then
+   if git merge-base --is-ancestor $nightly_origin/drm-intel-next-fixes 
$nightly_origin/drm-intel-fixes ; then
# -fixes has caught up to dinf, i.e. we're out of the merge
# window. Push the next queue.
echo -n "Out of merge window. Pushing drm-intel-next-queued to 
for-linux-next... "
-   git push $DRY_RUN origin 
+origin/drm-intel-next-queued:for-linux-next >& /dev/null
+   git push $DRY_RUN $nightly_origin 
+$nightly_origin/drm-intel-next-queued:for-linux-next >& /dev/null
echo "Done."
else
# dinf is ahead of -fixes, i.e. drm-next has already closed for
@@ -256,7 +266,7 @@ function update_linux_next
# for the current -next cycle. Push dinf

echo -n "Pushing drm-intel-next-fixes to for-linux-next... "
-   git push $DRY_RUN origin 
+origin/drm-intel-next-fixes:for-linux-next >& /dev/null
+   git push $DRY_RUN $nightly_origin 
+$nightly_origin/drm-intel-next-fixes:for-linux-next >& /dev/null
echo "Done."
fi
 }
@@ -272,11 +282,20 @@ function check_conflicts
true
 }

+function rr_cache_dir
+{
+   if [ -d $DIM_PREFIX/drm-intel-nightly/.git/rr-cache/ ] ; then
+   echo $DIM_PREFIX/drm-intel-nightly/.git/rr-cache/
+   else
+   echo $DIM_PREFIX/$DIM_DRM_INTEL/.git/rr-cache/
+   fi
+}
+
 function update_rerere_cache
 {
cd $DIM_PREFIX/drm-intel-rerere/
git pull
-   cp rr-cache/* $DIM_PREFIX/drm-intel-nightly/.git/rr-cache/ -r
+   cp rr-cache/* `rr_cache-dir` -r
cd -
 }

@@ -307,9 +326,10 @@ function dim_rebuild_nightly
fi

for remote in $(echo $nightly_branches | tr " " "\n" | sed 's|/.*$||g' 
| sort -u); do
-   echo -n "Fetching $remote... "
+   local nightly_remote=`map_nightly_remote $remote`
+   echo -n "Fetching $remote (as $nightly_remote) ... "
# git fetch returns 128 if there's nothing to be fetched
-   git fetch $remote >& /dev/null || true
+   git fetch $nightly_remote >& /dev/null || true
echo "Done."
done

@@ -329,12 +349,14 @@ function dim_rebuild_nightly
if [[ -n $sha1 ]] ; then
echo -n "Using override sha1: $sha1... "
else
-   sha1=$branch
+   local remote=${branch%%/*}
+   local nightly_remote=`map_nightly_remote $remote`
+   sha1=`echo $branch | sed -e s/^$remote/$nightly_remote/`
fi

if [ $first == 1 ] ; then
+   git reset --hard $sha1 &> /dev/null
echo "Reset. Done."
-   git reset --hard $sha1 >& /dev/null
first=0
elif git merge --rerere-autoupdate --ff-only $sha1 >& /dev/null 
; then
# nothing to do if just fast-forward
@@ -370,14 +392,16 @@ function dim_rebuild_nightly
git commit --quiet -m "$integration_branch: $time integration manifest"
echo "Done."

+   local nightly_origin=`map_nightly_remote origin`
+
echo -n "Pushing $integration_branch... "
-   git push $DRY_RUN origin +HEAD >& /dev/null && echo "Done."
+   git push $DRY_RUN $nightly_origin +HEAD >& /dev/null && echo "Done."

echo -n "Updating rerere cache... "
cd $rerere
if git branch | grep rerere-cache | grep '\*' >& /dev/null ; then
git pull >& /dev/null
-   cp $DIM_PREFIX/$integration_branch/.git/rr-cache/* rr-cache -r
+   cp `rr_cache_dir` rr-cache -r
git add *.patch >& /dev/null || true
git add rr-cache/* > /dev/null

  1   2   >