[PATCH 1/1] drm/i915/gvt: verify functions types in new_mmio_info()

2016-12-26 Thread Nicolas Iooss
The current prototype of new_mmio_info() uses void* for parameters read
and write, which are functions with precise calling conventions
(argument types and return type). Write down these conventions in
new_mmio_info() definition.

This has been reported by the following warnings when clang is used to
build the kernel:

drivers/gpu/drm/i915/gvt/handlers.c:124:21: error: pointer type
mismatch ('void *' and 'int (*)(struct intel_vgpu *, unsigned int,
void *, unsigned int)') [-Werror,-Wpointer-type-mismatch]
info->read = read ? read : intel_vgpu_default_mmio_read;
  ^    
drivers/gpu/drm/i915/gvt/handlers.c:125:23: error: pointer type
mismatch ('void *' and 'int (*)(struct intel_vgpu *, unsigned int,
void *, unsigned int)') [-Werror,-Wpointer-type-mismatch]
info->write = write ? write : intel_vgpu_default_mmio_write;
^ ~   ~

This allows the compiler to detect that sbi_ctl_mmio_write() returns a
"bool" value instead of an expected "int" one. Fix this.

Signed-off-by: Nicolas Iooss 
---
 drivers/gpu/drm/i915/gvt/handlers.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/gvt/handlers.c 
b/drivers/gpu/drm/i915/gvt/handlers.c
index 522809710312..052e57124c0a 100644
--- a/drivers/gpu/drm/i915/gvt/handlers.c
+++ b/drivers/gpu/drm/i915/gvt/handlers.c
@@ -93,7 +93,8 @@ static void write_vreg(struct intel_vgpu *vgpu, unsigned int 
offset,
 static int new_mmio_info(struct intel_gvt *gvt,
u32 offset, u32 flags, u32 size,
u32 addr_mask, u32 ro_mask, u32 device,
-   void *read, void *write)
+   int (*read)(struct intel_vgpu *, unsigned int, void *, unsigned 
int),
+   int (*write)(struct intel_vgpu *, unsigned int, void *, 
unsigned int))
 {
struct intel_gvt_mmio_info *info, *p;
u32 start, end, i;
@@ -974,7 +975,7 @@ static int sbi_data_mmio_read(struct intel_vgpu *vgpu, 
unsigned int offset,
return 0;
 }

-static bool sbi_ctl_mmio_write(struct intel_vgpu *vgpu, unsigned int offset,
+static int sbi_ctl_mmio_write(struct intel_vgpu *vgpu, unsigned int offset,
void *p_data, unsigned int bytes)
 {
u32 data;
-- 
2.11.0



[PATCH 1/2] Add DRM_IOCTL_MODE_GETPLANE2 ioctl wrapper

2016-12-26 Thread Ben Widawsky
On 16-12-20 16:13:32, Kristian H. Kristensen wrote:
>From: "Kristian H. Kristensen" 
>
>This adds support for the new DRM_IOCTL_MODE_GETPLANE2 ioctl. For older
>kernels drmModeGetPlane2() falls back to DRM_IOCTL_MODE_GETPLANE and
>return the new, bigger drmModePlaneRec, reporting 0 modifiers.
>
>BUG=chrome-os-partner:56407
>TEST=modetest with next commit reports modifiers
>
>Change-Id: I9cf9979c0b72933bad661fd03b9beebb36120dfd
>---
> include/drm/drm.h  |  1 +
> include/drm/drm_mode.h | 27 +++
> xf86drmMode.c  | 49 -
> xf86drmMode.h  |  4 
> 4 files changed, 76 insertions(+), 5 deletions(-)
>
>diff --git a/include/drm/drm.h b/include/drm/drm.h
>index f6fd5c2..09d4262 100644
>--- a/include/drm/drm.h
>+++ b/include/drm/drm.h
>@@ -799,6 +799,7 @@ extern "C" {
> #define DRM_IOCTL_MODE_DESTROY_DUMBDRM_IOWR(0xB4, struct 
> drm_mode_destroy_dumb)
> #define DRM_IOCTL_MODE_GETPLANERESOURCES DRM_IOWR(0xB5, struct 
> drm_mode_get_plane_res)
> #define DRM_IOCTL_MODE_GETPLANE   DRM_IOWR(0xB6, struct 
> drm_mode_get_plane)
>+#define DRM_IOCTL_MODE_GETPLANE2  DRM_IOWR(0xB6, struct 
>drm_mode_get_plane2)
> #define DRM_IOCTL_MODE_SETPLANE   DRM_IOWR(0xB7, struct 
> drm_mode_set_plane)
> #define DRM_IOCTL_MODE_ADDFB2 DRM_IOWR(0xB8, struct drm_mode_fb_cmd2)
> #define DRM_IOCTL_MODE_OBJ_GETPROPERTIES  DRM_IOWR(0xB9, struct 
> drm_mode_obj_get_properties)
>diff --git a/include/drm/drm_mode.h b/include/drm/drm_mode.h
>index df0e350..ce773fa 100644
>--- a/include/drm/drm_mode.h
>+++ b/include/drm/drm_mode.h
>@@ -193,6 +193,33 @@ struct drm_mode_get_plane {
>   __u64 format_type_ptr;
> };
>
>+struct drm_format_modifier {
>+  /* Bitmask of formats in get_plane format list this info
>+   * applies to. */
>+  __u64 formats;
>+
>+  /* This modifier can be used with the format for this plane. */
>+  __u64 modifier;
>+};
>+
>+struct drm_mode_get_plane2 {
>+  __u32 plane_id;
>+
>+  __u32 crtc_id;
>+  __u32 fb_id;
>+
>+  __u32 possible_crtcs;
>+  __u32 gamma_size;
>+
>+  __u32 count_format_types;
>+  __u64 format_type_ptr;
>+
>+  /* New in v2 */
>+  __u32 count_format_modifiers;
>+  __u32 flags;
>+  __u64 format_modifier_ptr;
>+};
>+
> struct drm_mode_get_plane_res {
>   __u64 plane_id_ptr;
>   __u32 count_planes;
>diff --git a/xf86drmMode.c b/xf86drmMode.c
>index fb22f68..298d502 100644
>--- a/xf86drmMode.c
>+++ b/xf86drmMode.c
>@@ -990,15 +990,15 @@ int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t 
>crtc_id,
>   return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETPLANE, &s);
> }
>
>-drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id)
>+static drmModePlanePtr get_plane(unsigned long cmd, int fd, uint32_t plane_id)
> {
>-  struct drm_mode_get_plane ovr, counts;
>+  struct drm_mode_get_plane2 ovr, counts;
>   drmModePlanePtr r = 0;
>
> retry:
>   memclear(ovr);
>   ovr.plane_id = plane_id;
>-  if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANE, &ovr))
>+  if (drmIoctl(fd, cmd, &ovr))
>   return 0;
>
>   counts = ovr;
>@@ -1010,11 +1010,21 @@ retry:
>   goto err_allocs;
>   }
>
>-  if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANE, &ovr))
>+  if (ovr.count_format_modifiers) {
>+  ovr.format_modifier_ptr =
>+  VOID2U64(drmMalloc(ovr.count_format_modifiers *
>+ sizeof(struct drm_format_modifier)));
>+  if (!ovr.format_modifier_ptr)
>+  goto err_allocs;
>+  }
>+
>+  if (drmIoctl(fd, cmd, &ovr))
>   goto err_allocs;
>
>-  if (counts.count_format_types < ovr.count_format_types) {
>+  if (counts.count_format_types < ovr.count_format_types ||
>+  counts.count_format_modifiers < ovr.count_format_modifiers) {
>   drmFree(U642VOID(ovr.format_type_ptr));
>+  drmFree(U642VOID(ovr.format_modifier_ptr));
>   goto retry;
>   }
>
>@@ -1022,6 +1032,7 @@ retry:
>   goto err_allocs;
>
>   r->count_formats = ovr.count_format_types;
>+  r->count_format_modifiers = ovr.count_format_modifiers;
>   r->plane_id = ovr.plane_id;
>   r->crtc_id = ovr.crtc_id;
>   r->fb_id = ovr.fb_id;
>@@ -1033,20 +1044,48 @@ retry:
>   drmFree(r->formats);
>   drmFree(r);
>   r = 0;
>+  goto err_allocs;
>+  }
>+
>+  r->format_modifiers =
>+  drmAllocCpy(U642VOID(ovr.format_modifier_ptr),
>+  ovr.count_format_modifiers,
>+  sizeof(struct drm_format_modifier));
>+  if (ovr.count_format_modifiers && !r->format_modifiers) {
>+  drmFree(r->formats);
>+  drmFree(r);
>+  r = 0;
>   }
>
> err_allocs:
>   drmFree(U642VOID(ovr.format_type_ptr));
>+  drmFree(U642VO

[PATCH 2/2] modetest: Teach modetest about format info

2016-12-26 Thread Ben Widawsky
On 16-12-20 16:13:33, Kristian H. Kristensen wrote:
>From: "Kristian H. Kristensen" 
>
>BUG=chrome-os-partner:56407
>TEST=modetest on a KMS driver that exposes modifiers should print those
>
>Change-Id: I91b2a408b1c8f112d7ba5d0998119b3c800b199c
>---
> tests/modetest/modetest.c | 40 
> 1 file changed, 36 insertions(+), 4 deletions(-)
>
>diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
>index dedd286..091bcba 100644
>--- a/tests/modetest/modetest.c
>+++ b/tests/modetest/modetest.c
>@@ -417,9 +417,30 @@ static void dump_framebuffers(struct device *dev)
>   printf("\n");
> }
>
>+static const char *
>+mod_to_string(uint64_t mod, char *buf, int len)
>+{
>+  switch (mod) {
>+  case DRM_FORMAT_MOD_NONE:
>+  return "LINEAR";

Just being pedantic here but a lack of modifier doesn't only mean that it's
linear, it means that there is no compression, and whatever else the future
holds. I'd just maybe return something like "unmodified".

>+  case I915_FORMAT_MOD_X_TILED:
>+  return "X_TILED";
>+  case I915_FORMAT_MOD_Y_TILED:
>+  return "Y_TILED";
>+  case I915_FORMAT_MOD_Yf_TILED:
>+  return "Yf_TILED";
>+  case DRM_FORMAT_MOD_SAMSUNG_64_32_TILE:
>+  return "SAMSUNG_64_32_TILE";
>+  default:
>+  snprintf(buf, len, "%016x", mod);
>+  return buf;
>+  }
>+}
>+
> static void dump_planes(struct device *dev)
> {
>-  unsigned int i, j;
>+  unsigned int i, j, k;
>+  char buf[17];
>
>   printf("Planes:\n");
>   printf("id\tcrtc\tfb\tCRTC x,y\tx,y\tgamma size\tpossible crtcs\n");
>@@ -442,8 +463,19 @@ static void dump_planes(struct device *dev)
>   continue;
>
>   printf("  formats:");
>-  for (j = 0; j < ovr->count_formats; j++)
>-  printf(" %4.4s", (char *)&ovr->formats[j]);
>+  for (j = 0; j < ovr->count_formats; j++) {
>+  if (ovr->count_format_modifiers == 0) {
>+  printf(" %4.4s", (char *)&ovr->formats[j]);
>+  continue;
>+  }
>+  struct drm_format_modifier *fm;
>+  for (k = 0; k < ovr->count_format_modifiers; k++) {
>+  fm = &ovr->format_modifiers[k];
>+  if (fm->formats & (1 << j))
>+  printf(" %4.4s:%s", (char 
>*)&ovr->formats[j],
>+ mod_to_string(fm->modifier, buf, 
>sizeof(buf)));
>+  }
>+  }

Wasn't the plan to have only 1 modifier per plane? Did that change? The GBM
interface only allows 1 modifier per plane.

>   printf("\n");
>
>   if (plane->props) {
>@@ -609,7 +641,7 @@ static struct resources *get_resources(struct device *dev)
>   if (!res->planes)
>   goto error;
>
>-  get_resource(res, plane_res, plane, Plane);
>+  get_resource(res, plane_res, plane, Plane2);
>   get_properties(res, plane_res, plane, PLANE);
>
>   return res;
>-- 
>2.9.3
>


[PATCH] omap drm: fix compile errors where the conversion from omap_timing to videomode was not perfect

2016-12-26 Thread H. Nikolaus Schaller
Signed-off-by: H. Nikolaus Schaller 
---
 drivers/gpu/drm/omapdrm/dss/dsi.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/dss/dsi.c 
b/drivers/gpu/drm/omapdrm/dss/dsi.c
index f060bda..f74615d 100644
--- a/drivers/gpu/drm/omapdrm/dss/dsi.c
+++ b/drivers/gpu/drm/omapdrm/dss/dsi.c
@@ -4336,7 +4336,7 @@ static void print_dsi_vm(const char *str,

wc = DIV_ROUND_UP(t->hact * t->bitspp, 8);
pps = DIV_ROUND_UP(wc + 6, t->ndl); /* pixel packet size */
-   bl = t->hss + t->hsa + t->hse + t->hbp + t->hfront_porch;
+   bl = t->hss + t->hsa + t->hse + t->hbp + t->hfp;
tot = bl + pps;

 #define TO_DSI_T(x) ((u32)div64_u64((u64)x * 10llu, byteclk))
@@ -4345,14 +4345,14 @@ static void print_dsi_vm(const char *str,
"%u/%u/%u/%u/%u/%u = %u + %u = %u\n",
str,
byteclk,
-   t->hss, t->hsa, t->hse, t->hbp, pps, t->hfront_porch,
+   t->hss, t->hsa, t->hse, t->hbp, pps, t->hfp,
bl, pps, tot,
TO_DSI_T(t->hss),
TO_DSI_T(t->hsa),
TO_DSI_T(t->hse),
TO_DSI_T(t->hbp),
TO_DSI_T(pps),
-   TO_DSI_T(t->hfront_porch),
+   TO_DSI_T(t->hfp),

TO_DSI_T(bl),
TO_DSI_T(pps),
@@ -4367,7 +4367,7 @@ static void print_dispc_vm(const char *str, const struct 
videomode *vm)
int hact, bl, tot;

hact = vm->hactive;
-   bl = vm->hsync_len + vm->hbp + vm->hfront_porch;
+   bl = vm->hsync_len + vm->hback_porch + vm->hfront_porch;
tot = hact + bl;

 #define TO_DISPC_T(x) ((u32)div64_u64((u64)x * 10llu, pck))
@@ -4376,10 +4376,10 @@ static void print_dispc_vm(const char *str, const 
struct videomode *vm)
"%u/%u/%u/%u = %u + %u = %u\n",
str,
pck,
-   vm->hsync_len, vm->hbp, hact, vm->hfront_porch,
+   vm->hsync_len, vm->hback_porch, hact, vm->hfront_porch,
bl, hact, tot,
TO_DISPC_T(vm->hsync_len),
-   TO_DISPC_T(vm->hbp),
+   TO_DISPC_T(vm->hback_porch),
TO_DISPC_T(hact),
TO_DISPC_T(vm->hfront_porch),
TO_DISPC_T(bl),
@@ -4401,12 +4401,12 @@ static void print_dsi_dispc_vm(const char *str,
dsi_tput = (u64)byteclk * t->ndl * 8;
pck = (u32)div64_u64(dsi_tput, t->bitspp);
dsi_hact = DIV_ROUND_UP(DIV_ROUND_UP(t->hact * t->bitspp, 8) + 6, 
t->ndl);
-   dsi_htot = t->hss + t->hsa + t->hse + t->hbp + dsi_hact + 
t->hfront_porch;
+   dsi_htot = t->hss + t->hsa + t->hse + t->hbp + dsi_hact + t->hfp;

vm.pixelclock = pck;
vm.hsync_len = div64_u64((u64)(t->hsa + t->hse) * pck, byteclk);
-   vm.hbp = div64_u64((u64)t->hbp * pck, byteclk);
-   vm.hfront_porch = div64_u64((u64)t->hfront_porch * pck, byteclk);
+   vm.hback_porch = div64_u64((u64)t->hbp * pck, byteclk);
+   vm.hfront_porch = div64_u64((u64)t->hfp * pck, byteclk);
vm.hactive = t->hact;

print_dispc_vm(str, &vm);
-- 
2.7.3



[Intel-gfx] [PATCH] drm/i915: check if execlist_port is empty before using its content

2016-12-26 Thread Du, Changbin
> On Fri, Dec 23, 2016 at 01:46:36PM +0800, changbin.du at intel.com wrote:
> > From: "Du, Changbin" 
> >
> > This patch fix a crash in function reset_common_ring. In this case,
> > the port[0].request is null when reset the render ring, so a null
> > dereference exception is raised. We need to check execlist_port status
> > first.
> 
> No. The root cause is whatever got you into the illegal condition in the
> first place.
> -Chris
> 
Thanks, I will restudy the code after process my current job. Since this happen
on gvt guest, so this may related to gvt emulation.

> --
> Chris Wilson, Intel Open Source Technology Centre


[RFC, v2, 10/11] vb2: dma-contig: Let drivers decide DMA attrs of MMAP and USERPTR bufs

2016-12-26 Thread Ricky Liang
Hi Laurent,

On Fri, Dec 16, 2016 at 9:24 AM, Laurent Pinchart
 wrote:
> From: Sakari Ailus 
>
> The desirable DMA attributes are not generic for all devices using
> Videobuf2 contiguous DMA ops. Let the drivers decide.
>
> This change also results in MMAP buffers always having an sg_table
> (dma_sgt field).
>
> Also arrange the header files alphabetically.
>
> As a result, also the DMA-BUF exporter must provide ops for synchronising
> the cache. This adds begin_cpu_access and end_cpu_access ops to
> vb2_dc_dmabuf_ops.
>
> Signed-off-by: Sakari Ailus 
> ---
>  drivers/media/v4l2-core/videobuf2-dma-contig.c | 66 
> ++
>  1 file changed, 56 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c 
> b/drivers/media/v4l2-core/videobuf2-dma-contig.c
> index d503647ea522..a0e88ad93f07 100644
> --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
> +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
> @@ -11,11 +11,11 @@
>   */
>
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
>  #include 
> -#include 
>
>  #include 
>  #include 
> @@ -115,8 +115,11 @@ static void vb2_dc_prepare(void *buf_priv)
> struct vb2_dc_buf *buf = buf_priv;
> struct sg_table *sgt = buf->dma_sgt;
>
> -   /* DMABUF exporter will flush the cache for us */
> -   if (!buf->vec)
> +   /*
> +* DMABUF exporter will flush the cache for us; only USERPTR
> +* and MMAP buffers with non-coherent memory will be flushed.
> +*/
> +   if (!(buf->attrs & DMA_ATTR_NON_CONSISTENT))

Should here be "if (!buf->vec || !(buf->attrs & DMA_ATTR_NON_CONSISTENT))" ?

> return;
>
> dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->orig_nents,
> @@ -128,8 +131,11 @@ static void vb2_dc_finish(void *buf_priv)
> struct vb2_dc_buf *buf = buf_priv;
> struct sg_table *sgt = buf->dma_sgt;
>
> -   /* DMABUF exporter will flush the cache for us */
> -   if (!buf->vec)
> +   /*
> +* DMABUF exporter will flush the cache for us; only USERPTR
> +* and MMAP buffers with non-coherent memory will be flushed.
> +*/
> +   if (!(buf->attrs & DMA_ATTR_NON_CONSISTENT))
> return;
>
> dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->orig_nents, 
> buf->dma_dir);
> @@ -172,13 +178,22 @@ static void *vb2_dc_alloc(struct device *dev, unsigned 
> long attrs,
> if (attrs)
> buf->attrs = attrs;
> buf->cookie = dma_alloc_attrs(dev, size, &buf->dma_addr,
> -   GFP_KERNEL | gfp_flags, buf->attrs);
> +GFP_KERNEL | gfp_flags, buf->attrs);
> if (!buf->cookie) {
> -   dev_err(dev, "dma_alloc_coherent of size %ld failed\n", size);
> +   dev_err(dev, "dma_alloc_attrs of size %ld failed\n", size);
> kfree(buf);
> return ERR_PTR(-ENOMEM);
> }
>
> +   if (buf->attrs & DMA_ATTR_NON_CONSISTENT) {
> +   buf->dma_sgt = vb2_dc_get_base_sgt(buf);
> +   if (!buf->dma_sgt) {
> +   dma_free_attrs(dev, size, buf->cookie, buf->dma_addr,
> +  buf->attrs);
> +   return ERR_PTR(-ENOMEM);
> +   }
> +   }
> +
> if ((buf->attrs & DMA_ATTR_NO_KERNEL_MAPPING) == 0)
> buf->vaddr = buf->cookie;
>
> @@ -359,6 +374,34 @@ static void *vb2_dc_dmabuf_ops_kmap(struct dma_buf 
> *dbuf, unsigned long pgnum)
> return buf->vaddr ? buf->vaddr + pgnum * PAGE_SIZE : NULL;
>  }
>
> +static int vb2_dc_dmabuf_ops_begin_cpu_access(struct dma_buf *dbuf,
> + enum dma_data_direction 
> direction)
> +{
> +   struct vb2_dc_buf *buf = dbuf->priv;
> +   struct sg_table *sgt = buf->dma_sgt;
> +
> +   if (!(buf->attrs & DMA_ATTR_NON_CONSISTENT))
> +   return 0;
> +
> +   dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir);
> +
> +   return 0;
> +}
> +
> +static int vb2_dc_dmabuf_ops_end_cpu_access(struct dma_buf *dbuf,
> +   enum dma_data_direction direction)
> +{
> +   struct vb2_dc_buf *buf = dbuf->priv;
> +   struct sg_table *sgt = buf->dma_sgt;
> +
> +   if (!(buf->attrs & DMA_ATTR_NON_CONSISTENT))
> +   return 0;
> +
> +   dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir);
> +
> +   return 0;
> +}
> +
>  static void *vb2_dc_dmabuf_ops_vmap(struct dma_buf *dbuf)
>  {
> struct vb2_dc_buf *buf = dbuf->priv;
> @@ -379,6 +422,8 @@ static struct dma_buf_ops vb2_dc_dmabuf_ops = {
> .unmap_dma_buf = vb2_dc_dmabuf_ops_unmap,
> .kmap = vb2_dc_dmabuf_ops_kmap,
> .kmap_atomic = vb2_dc_dmabuf_ops_kmap,
> +   .begin_cpu_access = vb2_dc_dmabuf_ops_begin_cpu_access,
> +   .end_cpu_access = vb2_dc_

[PATCH] drm: rcar-du: enable VSPDs on R8A7791

2016-12-26 Thread Sergei Shtylyov
On 12/19/2016 11:24 PM, Laurent Pinchart wrote:

 We're going to use R8A7791 VSPDs to control DU, so set the corresponding
 flag.

 Signed-off-by: Sergei Shtylyov 
>>>
>>> For the same reason I nacked the corresponding patch to the VSP1 driver, I
>>> have to nack this one as well. The Gen2 DU has native planes, this patch
>>> would prevent using them. I don't see a good reason to do so.
>>
>> One of the reasons is that these patches kill the horizontal noise when
>> playing video in Weston...
>
> What horizontal noise ? :-)

Occurs with V4L2 renderer... :-)

MBR, Sergei