[PATCH v2 9/9] drm/i915: Add render decompression support

2017-01-05 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

SKL+ display engine can scan out certain kinds of compressed surfaces
produced by the render engine. This involved telling the display engine
the location of the color control surfae (CCS) which describes
which parts of the main surface are compressed and which are not. The
location of CCS is provided by userspace as just another plane with its
own offset.

Add the required stuff to validate the user provided AUX plane metadata
and convert the user provided linear offset into something the hardware
can consume.

Due to hardware limitations we require that the main surface and
the AUX surface (CCS) be part of the same bo. The hardware also
makes life hard by not allowing you to provide separate x/y offsets
for the main and AUX surfaces (excpet with NV12), so finding suitable
offsets for both requires a bit of work. Assuming we still want keep
playing tricks with the offsets. I've just gone with a dumb "search
backward for suitable offsets" approach, which is far from optimal,
but it works.

Also not all planes will be capable of scanning out compressed surfaces,
and eg. 90/270 degree rotation is not supported in combination with
decompression either.

This patch may contain work from at least the following people:
* Vandana Kannan 
* Daniel Vetter 
* Ben Widawsky 

v2: Deal with display workarounds 0390, 0531, 1125 (Paulo)

Cc: Paulo Zanoni 
Cc: Vandana Kannan 
Cc: Daniel Vetter 
Cc: Ben Widawsky 
Cc: Jason Ekstrand 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/i915_reg.h  |  23 
 drivers/gpu/drm/i915/intel_display.c | 234 ---
 drivers/gpu/drm/i915/intel_pm.c  |  29 -
 drivers/gpu/drm/i915/intel_sprite.c  |   5 +
 4 files changed, 274 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index 00970aa77afa..6849ba93f1d9 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -6209,6 +6209,28 @@ enum {
_ID(id, _PS_ECC_STAT_1A, _PS_ECC_STAT_2A),   \
_ID(id, _PS_ECC_STAT_1B, _PS_ECC_STAT_2B))

+#define PLANE_AUX_DIST_1_A 0x701c0
+#define PLANE_AUX_DIST_2_A 0x702c0
+#define PLANE_AUX_DIST_1_B 0x711c0
+#define PLANE_AUX_DIST_2_B 0x712c0
+#define _PLANE_AUX_DIST_1(pipe) \
+   _PIPE(pipe, PLANE_AUX_DIST_1_A, PLANE_AUX_DIST_1_B)
+#define _PLANE_AUX_DIST_2(pipe) \
+   _PIPE(pipe, PLANE_AUX_DIST_2_A, PLANE_AUX_DIST_2_B)
+#define PLANE_AUX_DIST(pipe, plane) \
+   _MMIO_PLANE(plane, _PLANE_AUX_DIST_1(pipe), _PLANE_AUX_DIST_2(pipe))
+
+#define PLANE_AUX_OFFSET_1_A   0x701c4
+#define PLANE_AUX_OFFSET_2_A   0x702c4
+#define PLANE_AUX_OFFSET_1_B   0x711c4
+#define PLANE_AUX_OFFSET_2_B   0x712c4
+#define _PLANE_AUX_OFFSET_1(pipe)   \
+   _PIPE(pipe, PLANE_AUX_OFFSET_1_A, PLANE_AUX_OFFSET_1_B)
+#define _PLANE_AUX_OFFSET_2(pipe)   \
+   _PIPE(pipe, PLANE_AUX_OFFSET_2_A, PLANE_AUX_OFFSET_2_B)
+#define PLANE_AUX_OFFSET(pipe, plane)   \
+   _MMIO_PLANE(plane, _PLANE_AUX_OFFSET_1(pipe), _PLANE_AUX_OFFSET_2(pipe))
+
 /* legacy palette */
 #define _LGC_PALETTE_A   0x4a000
 #define _LGC_PALETTE_B   0x4a800
@@ -6433,6 +6455,7 @@ enum {
 # define CHICKEN3_DGMG_DONE_FIX_DISABLE(1 << 2)

 #define CHICKEN_PAR1_1 _MMIO(0x42080)
+#define  SKL_RC_HASH_OUTSIDE   (1 << 15)
 #define  DPA_MASK_VBLANK_SRD   (1 << 15)
 #define  FORCE_ARB_IDLE_PLANES (1 << 14)
 #define  SKL_EDP_PSR_FIX_RDWRAP(1 << 3)
diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 38de9df0ec60..2236abebd8bc 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2064,11 +2064,19 @@ intel_tile_width_bytes(const struct drm_framebuffer 
*fb, int plane)
return 128;
else
return 512;
+   case I915_FORMAT_MOD_Y_TILED_CCS:
+   if (plane == 1)
+   return 64;
+   /* fall through */
case I915_FORMAT_MOD_Y_TILED:
if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv))
return 128;
else
return 512;
+   case I915_FORMAT_MOD_Yf_TILED_CCS:
+   if (plane == 1)
+   return 64;
+   /* fall through */
case I915_FORMAT_MOD_Yf_TILED:
/*
 * Bspec seems to suggest that the Yf tile width would
@@ -2156,7 +2164,7 @@ static unsigned int intel_surf_alignment(const struct 
drm_framebuffer *fb,
struct drm_i915_private *dev_priv = to_i915(fb->dev);

/* AUX_DIST needs only 4K alignment */
-   if (fb->format->for

[PATCH 9/9] drm/i915: Add render decompression support

2017-01-04 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

SKL+ display engine can scan out certain kinds of compressed surfaces
produced by the render engine. This involved telling the display engine
the location of the color control surfae (CCS) which describes
which parts of the main surface are compressed and which are not. The
location of CCS is provided by userspace as just another plane with its
own offset.

Add the required stuff to validate the user provided AUX plane metadata
and convert the user provided linear offset into something the hardware
can consume.

Due to hardware limitations we require that the main surface and
the AUX surface (CCS) be part of the same bo. The hardware also
makes life hard by not allowing you to provide separate x/y offsets
for the main and AUX surfaces (excpet with NV12), so finding suitable
offsets for both requires a bit of work. Assuming we still want keep
playing tricks with the offsets. I've just gone with a dumb "search
backward for suitable offsets" approach, which is far from optimal,
but it works.

Also not all planes will be capable of scanning out compressed surfaces,
and eg. 90/270 degree rotation is not supported in combination with
decompression either.

This patch may contain work from at least the following people:
* Vandana Kannan 
* Daniel Vetter 
* Ben Widawsky 

Cc: Vandana Kannan 
Cc: Daniel Vetter 
Cc: Ben Widawsky 
Cc: Jason Ekstrand 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/i915_reg.h  |  22 
 drivers/gpu/drm/i915/intel_display.c | 219 +--
 drivers/gpu/drm/i915/intel_pm.c  |   8 +-
 drivers/gpu/drm/i915/intel_sprite.c  |   5 +
 4 files changed, 240 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index 00970aa77afa..05e18e742776 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -6209,6 +6209,28 @@ enum {
_ID(id, _PS_ECC_STAT_1A, _PS_ECC_STAT_2A),   \
_ID(id, _PS_ECC_STAT_1B, _PS_ECC_STAT_2B))

+#define PLANE_AUX_DIST_1_A 0x701c0
+#define PLANE_AUX_DIST_2_A 0x702c0
+#define PLANE_AUX_DIST_1_B 0x711c0
+#define PLANE_AUX_DIST_2_B 0x712c0
+#define _PLANE_AUX_DIST_1(pipe) \
+   _PIPE(pipe, PLANE_AUX_DIST_1_A, PLANE_AUX_DIST_1_B)
+#define _PLANE_AUX_DIST_2(pipe) \
+   _PIPE(pipe, PLANE_AUX_DIST_2_A, PLANE_AUX_DIST_2_B)
+#define PLANE_AUX_DIST(pipe, plane) \
+   _MMIO_PLANE(plane, _PLANE_AUX_DIST_1(pipe), _PLANE_AUX_DIST_2(pipe))
+
+#define PLANE_AUX_OFFSET_1_A   0x701c4
+#define PLANE_AUX_OFFSET_2_A   0x702c4
+#define PLANE_AUX_OFFSET_1_B   0x711c4
+#define PLANE_AUX_OFFSET_2_B   0x712c4
+#define _PLANE_AUX_OFFSET_1(pipe)   \
+   _PIPE(pipe, PLANE_AUX_OFFSET_1_A, PLANE_AUX_OFFSET_1_B)
+#define _PLANE_AUX_OFFSET_2(pipe)   \
+   _PIPE(pipe, PLANE_AUX_OFFSET_2_A, PLANE_AUX_OFFSET_2_B)
+#define PLANE_AUX_OFFSET(pipe, plane)   \
+   _MMIO_PLANE(plane, _PLANE_AUX_OFFSET_1(pipe), _PLANE_AUX_OFFSET_2(pipe))
+
 /* legacy palette */
 #define _LGC_PALETTE_A   0x4a000
 #define _LGC_PALETTE_B   0x4a800
diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 38de9df0ec60..b547332eeda1 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2064,11 +2064,19 @@ intel_tile_width_bytes(const struct drm_framebuffer 
*fb, int plane)
return 128;
else
return 512;
+   case I915_FORMAT_MOD_Y_TILED_CCS:
+   if (plane == 1)
+   return 64;
+   /* fall through */
case I915_FORMAT_MOD_Y_TILED:
if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv))
return 128;
else
return 512;
+   case I915_FORMAT_MOD_Yf_TILED_CCS:
+   if (plane == 1)
+   return 64;
+   /* fall through */
case I915_FORMAT_MOD_Yf_TILED:
/*
 * Bspec seems to suggest that the Yf tile width would
@@ -2156,7 +2164,7 @@ static unsigned int intel_surf_alignment(const struct 
drm_framebuffer *fb,
struct drm_i915_private *dev_priv = to_i915(fb->dev);

/* AUX_DIST needs only 4K alignment */
-   if (fb->format->format == DRM_FORMAT_NV12 && plane == 1)
+   if (plane == 1)
return 4096;

switch (fb->modifier) {
@@ -2166,6 +2174,8 @@ static unsigned int intel_surf_alignment(const struct 
drm_framebuffer *fb,
if (INTEL_GEN(dev_priv) >= 9)
return 256 * 1024;
return 0;
+   case I915_FORMAT_MOD_Y_TILED_CCS:
+   case I91

[PATCH 8/9] drm/i915: Implement .get_format_info() hook for CCS

2017-01-04 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

SKL+ display engine can scan out certain kinds of compressed surfaces
produced by the render engine. This involved telling the display engine
the location of the color control surfae (CCS) which describes which
parts of the main surface are compressed and which are not. The location
of CCS is provided by userspace as just another plane with its own offset.

By providing our own format information for the CCS formats, we should
be able to make framebuffer_check() do the right thing for the CCS
surface as well.

Note that we'll return the same format info for both Y and Yf tiled
format as that's what happens with the non-CCS Y vs. Yf as well. If
desired, we could potentially return a unique pointer for each
pixel_format+tiling+ccs combination, in which case we immediately be
able to tell if any of that stuff changed by just comparing the
pointers. But that does sound a bit wasteful space wise.

v2: Drop the 'dev' argument from the hook
v3: Include the description of the CCS surface layout

Cc: Vandana Kannan 
Cc: Daniel Vetter 
Cc: Ben Widawsky 
Cc: Jason Ekstrand 
Reviewed-by: Ben Widawsky 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_display.c | 36 ++
 include/uapi/drm/drm_fourcc.h| 49 
 2 files changed, 85 insertions(+)

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index c4662b2e9613..38de9df0ec60 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2478,6 +2478,41 @@ static unsigned int intel_fb_modifier_to_tiling(uint64_t 
fb_modifier)
}
 }

+static const struct drm_format_info ccs_formats[] = {
+   { .format = DRM_FORMAT_XRGB, .depth = 24, .num_planes = 2, .cpp = { 
4, 1, }, .hsub = 16, .vsub = 8, },
+   { .format = DRM_FORMAT_XBGR, .depth = 24, .num_planes = 2, .cpp = { 
4, 1, }, .hsub = 16, .vsub = 8, },
+   { .format = DRM_FORMAT_ARGB, .depth = 32, .num_planes = 2, .cpp = { 
4, 1, }, .hsub = 16, .vsub = 8, },
+   { .format = DRM_FORMAT_ABGR, .depth = 32, .num_planes = 2, .cpp = { 
4, 1, }, .hsub = 16, .vsub = 8, },
+};
+
+static const struct drm_format_info *
+lookup_format_info(const struct drm_format_info formats[],
+  int num_formats, u32 format)
+{
+   int i;
+
+   for (i = 0; i < num_formats; i++) {
+   if (formats[i].format == format)
+   return [i];
+   }
+
+   return NULL;
+}
+
+static const struct drm_format_info *
+intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
+{
+   switch (cmd->modifier[0]) {
+   case I915_FORMAT_MOD_Y_TILED_CCS:
+   case I915_FORMAT_MOD_Yf_TILED_CCS:
+   return lookup_format_info(ccs_formats,
+ ARRAY_SIZE(ccs_formats),
+ cmd->pixel_format);
+   default:
+   return NULL;
+   }
+}
+
 static int
 intel_fill_fb_info(struct drm_i915_private *dev_priv,
   struct drm_framebuffer *fb)
@@ -16083,6 +16118,7 @@ static void intel_atomic_state_free(struct 
drm_atomic_state *state)

 static const struct drm_mode_config_funcs intel_mode_funcs = {
.fb_create = intel_user_framebuffer_create,
+   .get_format_info = intel_get_format_info,
.output_poll_changed = intel_fbdev_output_poll_changed,
.atomic_check = intel_atomic_check,
.atomic_commit = intel_atomic_commit,
diff --git a/include/uapi/drm/drm_fourcc.h b/include/uapi/drm/drm_fourcc.h
index 9e1bb7fabcde..4581e3d41e5c 100644
--- a/include/uapi/drm/drm_fourcc.h
+++ b/include/uapi/drm/drm_fourcc.h
@@ -230,6 +230,55 @@ extern "C" {
 #define I915_FORMAT_MOD_Yf_TILED fourcc_mod_code(INTEL, 3)

 /*
+ * Intel color control surface (CCS) for render compression
+ *
+ * The framebuffer format must be one of the 8:8:8:8 RGB formats,
+ * the main surface will be plane index 0 and will be Y/Yf-tiled,
+ * the CCS will be plane index 1.
+ *
+ * Each byte of CCS contains 4 pairs of bits, with each pair of bits
+ * matching an area of 8x4 pixels of the main surface. Which would seem
+ * to match 2 cachelines containing 4x4 pixels each. The pairs bits within
+ * the byte form a 2x2 grid, which thus matches a 16x8 pixel area of the
+ * main surface. This is the 2x2 pattern the bits form (0=lsb, 7=msb):
+ * ---
+ * | 01 | 23 |
+ *  --
+ * | 45 | 67 |
+ * ---
+ *
+ * Actually only the lower bit of the pair seems to have any effect.
+ * No idea why. 0 in the lower bit would seem to mean not compressed,
+ * and 1 is compressed.  The interpreation of the main surface data
+ * when the block is marked compressed is unknown as of now.
+ *
+ * CCS tile is laid out in 8 byte horizontal strips each strip thus corresponds
+ * to a 128x8 pixel are of the main surface. So each 8x8 bytes of the CCS
+ *

[PATCH 7/9] drm/i915: Use DRM_DEBUG_KMS() for framebuffer failure debug messages

2017-01-04 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

DRM_UT_CORE generates way too much noise usually, so having the
framebuffer init failures use DRM_UT_CORE is a pain when trying to
find out the reason why you failed in creating a framebuffer.
Let's use DRM_UT_KMS for these debug messages instead.

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_display.c | 66 ++--
 1 file changed, 33 insertions(+), 33 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 5fee5a7ac9a4..c4662b2e9613 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2512,8 +2512,8 @@ intel_fill_fb_info(struct drm_i915_private *dev_priv,
 */
if (i915_gem_object_is_tiled(intel_fb->obj) &&
(x + width) * cpp > fb->pitches[i]) {
-   DRM_DEBUG("bad fb plane %d offset: 0x%x\n",
- i, fb->offsets[i]);
+   DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
+ i, fb->offsets[i]);
return -EINVAL;
}

@@ -2594,9 +2594,9 @@ intel_fill_fb_info(struct drm_i915_private *dev_priv,
max_size = max(max_size, offset + size);
}

-   if (max_size * tile_size > to_intel_framebuffer(fb)->obj->base.size) {
-   DRM_DEBUG("fb too big for bo (need %u bytes, have %zu bytes)\n",
- max_size * tile_size, 
to_intel_framebuffer(fb)->obj->base.size);
+   if (max_size * tile_size > intel_fb->obj->base.size) {
+   DRM_DEBUG_KMS("fb too big for bo (need %u bytes, have %zu 
bytes)\n",
+ max_size * tile_size, intel_fb->obj->base.size);
return -EINVAL;
}

@@ -15904,14 +15904,14 @@ static int intel_framebuffer_init(struct drm_device 
*dev,
 */
if (tiling != I915_TILING_NONE &&
tiling != 
intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
-   DRM_DEBUG("tiling_mode doesn't match fb modifier\n");
+   DRM_DEBUG_KMS("tiling_mode doesn't match fb 
modifier\n");
return -EINVAL;
}
} else {
if (tiling == I915_TILING_X) {
mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
} else if (tiling == I915_TILING_Y) {
-   DRM_DEBUG("No Y tiling for legacy addfb\n");
+   DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
return -EINVAL;
}
}
@@ -15921,16 +15921,16 @@ static int intel_framebuffer_init(struct drm_device 
*dev,
case I915_FORMAT_MOD_Y_TILED:
case I915_FORMAT_MOD_Yf_TILED:
if (INTEL_GEN(dev_priv) < 9) {
-   DRM_DEBUG("Unsupported tiling 0x%llx!\n",
- mode_cmd->modifier[0]);
+   DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n",
+ mode_cmd->modifier[0]);
return -EINVAL;
}
case DRM_FORMAT_MOD_NONE:
case I915_FORMAT_MOD_X_TILED:
break;
default:
-   DRM_DEBUG("Unsupported fb modifier 0x%llx!\n",
- mode_cmd->modifier[0]);
+   DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n",
+ mode_cmd->modifier[0]);
return -EINVAL;
}

@@ -15940,17 +15940,17 @@ static int intel_framebuffer_init(struct drm_device 
*dev,
 */
if (INTEL_INFO(dev_priv)->gen < 4 &&
tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
-   DRM_DEBUG("tiling_mode must match fb modifier exactly on 
gen2/3\n");
+   DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on 
gen2/3\n");
return -EINVAL;
}

pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->modifier[0],
   mode_cmd->pixel_format);
if (mode_cmd->pitches[0] > pitch_limit) {
-   DRM_DEBUG("%s pitch (%u) must be at less than %d\n",
- mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ?
- "tiled" : "linear",
- mode_cmd->pitches[0], pitch_limit);
+   DRM_DEBUG_KMS("%s pitch (%u) must be at less than %d\n",
+ mode_cmd->modifier[0] != DRM_FORM

[PATCH 6/9] drm/i915: Pass the correct plane index to _intel_compute_tile_offset()

2017-01-04 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

intel_fill_fb_info() should pass the correct plane index to
_intel_compute_tile_offset() once we start to care about the AUX
surface.

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 0ca0dbccc005..5fee5a7ac9a4 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2525,7 +2525,7 @@ intel_fill_fb_info(struct drm_i915_private *dev_priv,
intel_fb->normal[i].y = y;

offset = _intel_compute_tile_offset(dev_priv, , ,
-   fb, 0, fb->pitches[i],
+   fb, i, fb->pitches[i],
DRM_ROTATE_0, tile_size);
offset /= tile_size;

-- 
2.10.2



[PATCH 5/9] drm/i915: Fix Yf tile width

2017-01-04 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Based on empirical evidence the display engine (at least) always
treats Yf tiles as 128Bx32. Currently we're assuming the tile dimensions
change based on the pixel format. Let's adjust our code to match the
hardware.

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_display.c | 20 ++--
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index bc398743e941..0ca0dbccc005 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2070,20 +2070,12 @@ intel_tile_width_bytes(const struct drm_framebuffer 
*fb, int plane)
else
return 512;
case I915_FORMAT_MOD_Yf_TILED:
-   switch (cpp) {
-   case 1:
-   return 64;
-   case 2:
-   case 4:
-   return 128;
-   case 8:
-   case 16:
-   return 256;
-   default:
-   MISSING_CASE(cpp);
-   return cpp;
-   }
-   break;
+   /*
+* Bspec seems to suggest that the Yf tile width would
+* depend on the cpp. In reality it doesn't, at least
+* as far as the display engine is concerned.
+*/
+   return 128;
default:
MISSING_CASE(fb->modifier);
return cpp;
-- 
2.10.2



[PATCH 4/9] drm/i915: Avoid div-by-zero when computing aux_stride w/o an aux plane

2017-01-04 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

To make life easier let's allow skl_plane_stride() to be called for the
AUX surface even when there is no AUX surface. Avoids special cases in
the callers.

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_display.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 4d514ca1da88..bc398743e941 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -3261,7 +3261,12 @@ static void skl_detach_scalers(struct intel_crtc 
*intel_crtc)
 u32 skl_plane_stride(const struct drm_framebuffer *fb, int plane,
 unsigned int rotation)
 {
-   u32 stride = intel_fb_pitch(fb, plane, rotation);
+   u32 stride;
+
+   if (plane >= fb->format->num_planes)
+   return 0;
+
+   stride = intel_fb_pitch(fb, plane, rotation);

/*
 * The stride is either expressed as a multiple of 64 bytes chunks for
-- 
2.10.2



[PATCH 3/9] drm/i915: Move nv12 chroma plane handling into intel_surf_alignment()

2017-01-04 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Let's try to keep the alignment requirements in one place, and so
towards that end let's move the AUX_DIST alignment handling into
intel_surf_alignment() alongside the main surface alignment stuff.

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_display.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index f0cb80aba89a..4d514ca1da88 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2163,6 +2163,10 @@ static unsigned int intel_surf_alignment(const struct 
drm_framebuffer *fb,
 {
struct drm_i915_private *dev_priv = to_i915(fb->dev);

+   /* AUX_DIST needs only 4K alignment */
+   if (fb->format->format == DRM_FORMAT_NV12 && plane == 1)
+   return 4096;
+
switch (fb->modifier) {
case DRM_FORMAT_MOD_NONE:
return intel_linear_alignment(dev_priv);
@@ -2452,13 +2456,7 @@ u32 intel_compute_tile_offset(int *x, int *y,
const struct drm_framebuffer *fb = state->base.fb;
unsigned int rotation = state->base.rotation;
int pitch = intel_fb_pitch(fb, plane, rotation);
-   u32 alignment;
-
-   /* AUX_DIST needs only 4K alignment */
-   if (fb->format->format == DRM_FORMAT_NV12 && plane == 1)
-   alignment = 4096;
-   else
-   alignment = intel_surf_alignment(fb, plane);
+   u32 alignment = intel_surf_alignment(fb, plane);

return _intel_compute_tile_offset(dev_priv, x, y, fb, plane, pitch,
  rotation, alignment);
-- 
2.10.2



[PATCH 2/9] drm/i915: Plumb drm_framebuffer into more places

2017-01-04 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Now that framebuffers can be used even before calling
drm_framebuffer_init() we can start to plumb them into more places,
instead of passing individual pieces for fb metadata.

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_display.c | 127 +++
 drivers/gpu/drm/i915/intel_drv.h |  11 +--
 drivers/gpu/drm/i915/intel_fbdev.c   |   4 +-
 3 files changed, 57 insertions(+), 85 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index e2150a64860c..f0cb80aba89a 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2050,10 +2050,13 @@ static unsigned int intel_tile_size(const struct 
drm_i915_private *dev_priv)
return IS_GEN2(dev_priv) ? 2048 : 4096;
 }

-static unsigned int intel_tile_width_bytes(const struct drm_i915_private 
*dev_priv,
-  uint64_t fb_modifier, unsigned int 
cpp)
+static unsigned int
+intel_tile_width_bytes(const struct drm_framebuffer *fb, int plane)
 {
-   switch (fb_modifier) {
+   struct drm_i915_private *dev_priv = to_i915(fb->dev);
+   unsigned int cpp = fb->format->cpp[plane];
+
+   switch (fb->modifier) {
case DRM_FORMAT_MOD_NONE:
return cpp;
case I915_FORMAT_MOD_X_TILED:
@@ -2082,41 +2085,38 @@ static unsigned int intel_tile_width_bytes(const struct 
drm_i915_private *dev_pr
}
break;
default:
-   MISSING_CASE(fb_modifier);
+   MISSING_CASE(fb->modifier);
return cpp;
}
 }

-unsigned int intel_tile_height(const struct drm_i915_private *dev_priv,
-  uint64_t fb_modifier, unsigned int cpp)
+static unsigned int
+intel_tile_height(const struct drm_framebuffer *fb, int plane)
 {
-   if (fb_modifier == DRM_FORMAT_MOD_NONE)
+   if (fb->modifier == DRM_FORMAT_MOD_NONE)
return 1;
else
-   return intel_tile_size(dev_priv) /
-   intel_tile_width_bytes(dev_priv, fb_modifier, cpp);
+   return intel_tile_size(to_i915(fb->dev)) /
+   intel_tile_width_bytes(fb, plane);
 }

 /* Return the tile dimensions in pixel units */
-static void intel_tile_dims(const struct drm_i915_private *dev_priv,
+static void intel_tile_dims(const struct drm_framebuffer *fb, int plane,
unsigned int *tile_width,
-   unsigned int *tile_height,
-   uint64_t fb_modifier,
-   unsigned int cpp)
+   unsigned int *tile_height)
 {
-   unsigned int tile_width_bytes =
-   intel_tile_width_bytes(dev_priv, fb_modifier, cpp);
+   unsigned int tile_width_bytes = intel_tile_width_bytes(fb, plane);
+   unsigned int cpp = fb->format->cpp[plane];

*tile_width = tile_width_bytes / cpp;
-   *tile_height = intel_tile_size(dev_priv) / tile_width_bytes;
+   *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
 }

 unsigned int
-intel_fb_align_height(struct drm_device *dev, unsigned int height,
- uint32_t pixel_format, uint64_t fb_modifier)
+intel_fb_align_height(const struct drm_framebuffer *fb,
+ int plane, unsigned int height)
 {
-   unsigned int cpp = drm_format_plane_cpp(pixel_format, 0);
-   unsigned int tile_height = intel_tile_height(to_i915(dev), fb_modifier, 
cpp);
+   unsigned int tile_height = intel_tile_height(fb, plane);

return ALIGN(height, tile_height);
 }
@@ -2158,21 +2158,23 @@ static unsigned int intel_linear_alignment(const struct 
drm_i915_private *dev_pr
return 0;
 }

-static unsigned int intel_surf_alignment(const struct drm_i915_private 
*dev_priv,
-uint64_t fb_modifier)
+static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
+int plane)
 {
-   switch (fb_modifier) {
+   struct drm_i915_private *dev_priv = to_i915(fb->dev);
+
+   switch (fb->modifier) {
case DRM_FORMAT_MOD_NONE:
return intel_linear_alignment(dev_priv);
case I915_FORMAT_MOD_X_TILED:
-   if (INTEL_INFO(dev_priv)->gen >= 9)
+   if (INTEL_GEN(dev_priv) >= 9)
return 256 * 1024;
return 0;
case I915_FORMAT_MOD_Y_TILED:
case I915_FORMAT_MOD_Yf_TILED:
return 1 * 1024 * 1024;
default:
-   MISSING_CASE(fb_modifier);
+   MISSING_CASE(fb->modifier);
return 0;
}
 }
@@ -2189,7 +2191,7 @@ intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, 
unsigned int rot

[PATCH 1/9] drm: Add mode_config .get_format_info() hook

2017-01-04 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Allow drivers to return a custom drm_format_info structure for special
fb layouts. We'll use this for the compression control surface in i915.

v2: Fix drm_get_format_info() kernel doc (Laurent)
Don't pass 'dev' to the new hook (Laurent)

Cc: Laurent Pinchart 
Cc: Ben Widawsky 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_fb_cma_helper.c  |  2 +-
 drivers/gpu/drm/drm_fourcc.c | 25 +
 drivers/gpu/drm/drm_framebuffer.c|  9 +++--
 drivers/gpu/drm/drm_modeset_helper.c |  2 +-
 include/drm/drm_fourcc.h |  6 ++
 include/drm/drm_mode_config.h| 14 ++
 6 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_fb_cma_helper.c 
b/drivers/gpu/drm/drm_fb_cma_helper.c
index 20a4011f790d..de3c9fe116fc 100644
--- a/drivers/gpu/drm/drm_fb_cma_helper.c
+++ b/drivers/gpu/drm/drm_fb_cma_helper.c
@@ -177,7 +177,7 @@ struct drm_framebuffer *drm_fb_cma_create_with_funcs(struct 
drm_device *dev,
int ret;
int i;

-   info = drm_format_info(mode_cmd->pixel_format);
+   info = drm_get_format_info(dev, mode_cmd);
if (!info)
return ERR_PTR(-EINVAL);

diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index 90d2cc8da8eb..f9b6445e846a 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -199,6 +199,31 @@ const struct drm_format_info *drm_format_info(u32 format)
 EXPORT_SYMBOL(drm_format_info);

 /**
+ * drm_get_format_info - query information for a given framebuffer 
configuration
+ * @dev: DRM device
+ * @mode_cmd: metadata from the userspace fb creation request
+ *
+ * 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_get_format_info(struct drm_device *dev,
+   const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+   const struct drm_format_info *info = NULL;
+
+   if (dev->mode_config.funcs->get_format_info)
+   info = dev->mode_config.funcs->get_format_info(mode_cmd);
+
+   if (!info)
+   info = drm_format_info(mode_cmd->pixel_format);
+
+   return info;
+}
+EXPORT_SYMBOL(drm_get_format_info);
+
+/**
  * drm_format_num_planes - get the number of planes for format
  * @format: pixel format (DRM_FORMAT_*)
  *
diff --git a/drivers/gpu/drm/drm_framebuffer.c 
b/drivers/gpu/drm/drm_framebuffer.c
index 588ccc3a2218..e276fcdc3a62 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -126,11 +126,13 @@ int drm_mode_addfb(struct drm_device *dev,
return 0;
 }

-static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
+static int framebuffer_check(struct drm_device *dev,
+const struct drm_mode_fb_cmd2 *r)
 {
const struct drm_format_info *info;
int i;

+   /* check if the format is supported at all */
info = __drm_format_info(r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN);
if (!info) {
struct drm_format_name_buf format_name;
@@ -140,6 +142,9 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 
*r)
return -EINVAL;
}

+   /* now let the driver pick its own format info */
+   info = drm_get_format_info(dev, r);
+
if (r->width == 0 || r->width % info->hsub) {
DRM_DEBUG_KMS("bad framebuffer width %u\n", r->width);
return -EINVAL;
@@ -263,7 +268,7 @@ drm_internal_framebuffer_create(struct drm_device *dev,
return ERR_PTR(-EINVAL);
}

-   ret = framebuffer_check(r);
+   ret = framebuffer_check(dev, r);
if (ret)
return ERR_PTR(ret);

diff --git a/drivers/gpu/drm/drm_modeset_helper.c 
b/drivers/gpu/drm/drm_modeset_helper.c
index cc44a9a4b004..2b33825f2f93 100644
--- a/drivers/gpu/drm/drm_modeset_helper.c
+++ b/drivers/gpu/drm/drm_modeset_helper.c
@@ -78,7 +78,7 @@ void drm_helper_mode_fill_fb_struct(struct drm_device *dev,
int i;

fb->dev = dev;
-   fb->format = drm_format_info(mode_cmd->pixel_format);
+   fb->format = drm_get_format_info(dev, mode_cmd);
fb->width = mode_cmd->width;
fb->height = mode_cmd->height;
for (i = 0; i < 4; i++) {
diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
index fcc08da850c8..6942e84b6edd 100644
--- a/include/drm/drm_fourcc.h
+++ b/include/drm/drm_fourcc.h
@@ -25,6 +25,9 @@
 #include 
 #include 

+struct drm_device;
+struct drm_mode_fb_cmd2;
+
 /**
  * struct drm_format_info - information about a DRM format
  * @format: 4CC format identifier (DRM_FORMAT_*)
@@ -55,6 +58,9 @@ struct drm_format_name_buf {

 const struct drm_format_info *__drm_format_info(u32 format);
 const struct drm_format_info *d

[PATCH 0/9] drm/i915: SKL+ render decompression support

2017-01-04 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

This series enables the SKL+ display engine render decompression
support. Some bits and pieces of the i915 code are based on work
from various people, but I just put my name on it since it
would be hard to figure out which parts came from where.

Entire series available here:
git://github.com/vsyrjala/linux.git fb_format_dedup_4_ccs

Cc: Vandana Kannan 
Cc: Daniel Vetter 
Cc: Ben Widawsky 
Cc: Jason Ekstrand 
Cc: Laurent Pinchart 

Ville Syrjälä (9):
  drm: Add mode_config .get_format_info() hook
  drm/i915: Plumb drm_framebuffer into more places
  drm/i915: Move nv12 chroma plane handling into intel_surf_alignment()
  drm/i915: Avoid div-by-zero when computing aux_stride w/o an aux plane
  drm/i915: Fix Yf tile width
  drm/i915: Pass the correct plane index to _intel_compute_tile_offset()
  drm/i915: Use DRM_DEBUG_KMS() for framebuffer failure debug messages
  drm/i915: Implement .get_format_info() hook for CCS
  drm/i915: Add render decompression support

 drivers/gpu/drm/drm_fb_cma_helper.c  |   2 +-
 drivers/gpu/drm/drm_fourcc.c |  25 ++
 drivers/gpu/drm/drm_framebuffer.c|   9 +-
 drivers/gpu/drm/drm_modeset_helper.c |   2 +-
 drivers/gpu/drm/i915/i915_reg.h  |  22 ++
 drivers/gpu/drm/i915/intel_display.c | 474 +--
 drivers/gpu/drm/i915/intel_drv.h |  11 +-
 drivers/gpu/drm/i915/intel_fbdev.c   |   4 +-
 drivers/gpu/drm/i915/intel_pm.c  |   8 +-
 drivers/gpu/drm/i915/intel_sprite.c  |   5 +
 include/drm/drm_fourcc.h |   6 +
 include/drm/drm_mode_config.h|  14 ++
 include/uapi/drm/drm_fourcc.h|  49 
 13 files changed, 478 insertions(+), 153 deletions(-)

-- 
2.10.2



[PATCH] drm: Fix kernel docs for drm_helper_mode_fill_fb_struct()

2016-12-15 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

drm_modeset_helper.c:74: warning: No description found for parameter 'dev'

Cc: Laurent Pinchart 
Cc: Alex Deucher 
Fixes: a3f913ca9892 ("drm: Pass 'dev' to drm_helper_mode_fill_fb_struct()")
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_modeset_helper.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/drm_modeset_helper.c 
b/drivers/gpu/drm/drm_modeset_helper.c
index f78df06a940d..4b31f5f70177 100644
--- a/drivers/gpu/drm/drm_modeset_helper.c
+++ b/drivers/gpu/drm/drm_modeset_helper.c
@@ -62,6 +62,7 @@ EXPORT_SYMBOL(drm_helper_move_panel_connectors_to_head);

 /**
  * drm_helper_mode_fill_fb_struct - fill out framebuffer metadata
+ * @dev: DRM device
  * @fb: drm_framebuffer object to fill out
  * @mode_cmd: metadata from the userspace fb creation request
  *
-- 
2.10.2



[PATCH] drm/cma: Fix compile fail due to fomat->format typo

2016-12-15 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Apparently my arm .config had reverted to CMA=n at some point, so I
failed to notice that I typoed the code. Fix it up so that the
cma helper will compile again.

Reported-by: kbuild test robot 
Cc: Laurent Pinchart 
Fixes: ca984a998ad3 ("drm/fb_cma_helper: Replace drm_format_info() with 
fb->format")
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_fb_cma_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_fb_cma_helper.c 
b/drivers/gpu/drm/drm_fb_cma_helper.c
index aab4465307ed..591f30ebc42a 100644
--- a/drivers/gpu/drm/drm_fb_cma_helper.c
+++ b/drivers/gpu/drm/drm_fb_cma_helper.c
@@ -309,7 +309,7 @@ static void drm_fb_cma_describe(struct drm_framebuffer *fb, 
struct seq_file *m)
seq_printf(m, "fb: %dx%d@%4.4s\n", fb->width, fb->height,
(char *)>format->format);

-   for (i = 0; i < fb->fomat->num_planes; i++) {
+   for (i = 0; i < fb->format->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);
-- 
2.10.2



[PATCH v3 33/37] drm: Nuke fb->pixel_format

2016-12-14 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Replace uses of fb->pixel_format with fb->format->format.
Less duplicated information is a good thing.

Note that coccinelle failed to eliminate the
"/* fourcc format */" comment from drm_framebuffer.h, so I had
to do that part manually.

@@
struct drm_framebuffer *FB;
expression E;
@@
 drm_helper_mode_fill_fb_struct(...) {
...
-   FB->pixel_format = E;
...
 }

@@
struct drm_framebuffer *FB;
expression E;
@@
 i9xx_get_initial_plane_config(...) {
...
-   FB->pixel_format = E;
...
 }

@@
struct drm_framebuffer *FB;
expression E;
@@
 ironlake_get_initial_plane_config(...) {
...
-   FB->pixel_format = E;
...
 }

@@
struct drm_framebuffer *FB;
expression E;
@@
 skylake_get_initial_plane_config(...) {
...
-   FB->pixel_format = E;
...
 }

@@
struct drm_framebuffer *a;
struct drm_framebuffer b;
@@
(
- a->pixel_format
+ a->format->format
|
- b.pixel_format
+ b.format->format
)

@@
struct drm_plane_state *a;
struct drm_plane_state b;
@@
(
- a->fb->pixel_format
+ a->fb->format->format
|
- b.fb->pixel_format
+ b.fb->format->format
)

@@
struct drm_crtc *CRTC;
@@
(
- CRTC->primary->fb->pixel_format
+ CRTC->primary->fb->format->format
|
- CRTC->primary->state->fb->pixel_format
+ CRTC->primary->state->fb->format->format
)

@@
struct drm_mode_set *set;
@@
(
- set->fb->pixel_format
+ set->fb->format->format
|
- set->crtc->primary->fb->pixel_format
+ set->crtc->primary->fb->format->format
)

@@
@@
 struct drm_framebuffer {
 ...
-uint32_t pixel_format;
 ...
 };

v2: Fix commit message (Laurent)
Rebase due to earlier removal of many fb->pixel_format uses,
including the 'fb->format = drm_format_info(fb->format->format);'
snafu
v3: Adjusted the semantic patch a bit and regenerated due to code
changes

Cc: Laurent Pinchart 
Signed-off-by: Ville Syrjälä 
Reviewed-by: Alex Deucher  (v1)
Reviewed-by: Laurent Pinchart 
---
 drivers/gpu/drm/amd/amdgpu/dce_v10_0.c  |  4 +--
 drivers/gpu/drm/amd/amdgpu/dce_v11_0.c  |  4 +--
 drivers/gpu/drm/amd/amdgpu/dce_v6_0.c   |  4 +--
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c   |  4 +--
 drivers/gpu/drm/arc/arcpgu_crtc.c   |  2 +-
 drivers/gpu/drm/arm/hdlcd_crtc.c|  2 +-
 drivers/gpu/drm/arm/malidp_planes.c |  8 +++---
 drivers/gpu/drm/armada/armada_crtc.c|  2 +-
 drivers/gpu/drm/armada/armada_overlay.c |  2 +-
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c | 18 ++---
 drivers/gpu/drm/drm_atomic.c|  6 ++---
 drivers/gpu/drm/drm_crtc.c  |  4 +--
 drivers/gpu/drm/drm_crtc_helper.c   |  4 +--
 drivers/gpu/drm/drm_fb_cma_helper.c |  2 +-
 drivers/gpu/drm/drm_modeset_helper.c|  1 -
 drivers/gpu/drm/drm_plane.c |  6 ++---
 drivers/gpu/drm/exynos/exynos5433_drm_decon.c   |  2 +-
 drivers/gpu/drm/exynos/exynos7_drm_decon.c  |  2 +-
 drivers/gpu/drm/exynos/exynos_drm_fimd.c|  2 +-
 drivers/gpu/drm/exynos/exynos_mixer.c   |  8 +++---
 drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c |  4 +--
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c |  6 ++---
 drivers/gpu/drm/i915/i915_debugfs.c |  3 ++-
 drivers/gpu/drm/i915/intel_atomic_plane.c   |  4 +--
 drivers/gpu/drm/i915/intel_display.c| 33 +++-
 drivers/gpu/drm/i915/intel_fbdev.c  |  2 +-
 drivers/gpu/drm/i915/intel_overlay.c|  2 +-
 drivers/gpu/drm/i915/intel_pm.c | 10 
 drivers/gpu/drm/i915/intel_sprite.c | 12 -
 drivers/gpu/drm/imx/ipuv3-plane.c   | 34 -
 drivers/gpu/drm/mediatek/mtk_drm_plane.c|  2 +-
 drivers/gpu/drm/meson/meson_plane.c |  2 +-
 drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c   |  2 +-
 drivers/gpu/drm/msm/msm_fb.c|  2 +-
 drivers/gpu/drm/mxsfb/mxsfb_crtc.c  |  2 +-
 drivers/gpu/drm/nouveau/dispnv04/overlay.c  |  8 +++---
 drivers/gpu/drm/nouveau/nv50_display.c  |  4 +--
 drivers/gpu/drm/omapdrm/omap_fb.c   |  2 +-
 drivers/gpu/drm/radeon/atombios_crtc.c  |  8 +++---
 drivers/gpu/drm/rcar-du/rcar_du_plane.c |  4 +--
 drivers/gpu/drm/rcar-du/rcar_du_vsp.c   |  4 +--
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 18 ++---
 drivers/gpu/drm/shmobile/shmob_drm_crtc.c   |  6 ++---
 drivers/gpu/drm/shmobile/shmob_drm_plane.c  |  4 +--
 drivers/gpu/drm/sti/sti_gdp.c   |  8 +++---
 drivers/gpu/drm/sti/sti_hqvdp.c |  2 +-
 drivers/gpu/drm/sun4i/sun4i_backend.c   |  3 ++-
 drivers/gpu

[PATCH v3 32/37] drm: Nuke fb->bits_per_pixel

2016-12-14 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Replace uses of fb->bits_per_pixel with fb->format->cpp[0]*8.
Less duplicated information is a good thing.

Note that I didn't put parens around the cpp*8 in the below cocci script,
on account of not wanting spurious parens all over the place. Instead I
did the unsafe way, and tried to look over the entire diff to spot if
any dangerous expressions were produced. I didn't see any.

There are some cases where previously the code did X*bpp/8, so the
division happened after the multiplication. Those are now just X*cpp
so the division effectively happens before the multiplication,
but that is perfectly fine since bpp is always a multiple of 8.

@@
struct drm_framebuffer *FB;
expression E;
@@
 drm_helper_mode_fill_fb_struct(...) {
...
-   FB->bits_per_pixel = E;
...
 }

@@
struct drm_framebuffer *FB;
expression E;
@@
 i9xx_get_initial_plane_config(...) {
...
-   FB->bits_per_pixel = E;
...
 }

@@
struct drm_framebuffer *FB;
expression E;
@@
 ironlake_get_initial_plane_config(...) {
...
-   FB->bits_per_pixel = E;
...
 }

@@
struct drm_framebuffer *FB;
expression E;
@@
 skylake_get_initial_plane_config(...) {
...
-   FB->bits_per_pixel = E;
...
 }

@@
struct drm_framebuffer FB;
expression E;
@@
(
- E * FB.bits_per_pixel / 8
+ E * FB.format->cpp[0]
|
- FB.bits_per_pixel / 8
+ FB.format->cpp[0]
|
- E * FB.bits_per_pixel >> 3
+ E * FB.format->cpp[0]
|
- FB.bits_per_pixel >> 3
+ FB.format->cpp[0]
|
- (FB.bits_per_pixel + 7) / 8
+ FB.format->cpp[0]
|
- FB.bits_per_pixel
+ FB.format->cpp[0] * 8
|
- FB.format->cpp[0] * 8 != 8
+ FB.format->cpp[0] != 1
)

@@
struct drm_framebuffer *FB;
expression E;
@@
(
- E * FB->bits_per_pixel / 8
+ E * FB->format->cpp[0]
|
- FB->bits_per_pixel / 8
+ FB->format->cpp[0]
|
- E * FB->bits_per_pixel >> 3
+ E * FB->format->cpp[0]
|
- FB->bits_per_pixel >> 3
+ FB->format->cpp[0]
|
- (FB->bits_per_pixel + 7) / 8
+ FB->format->cpp[0]
|
- FB->bits_per_pixel
+ FB->format->cpp[0] * 8
|
- FB->format->cpp[0] * 8 != 8
+ FB->format->cpp[0] != 1
)

@@
struct drm_plane_state *state;
expression E;
@@
(
- E * state->fb->bits_per_pixel / 8
+ E * state->fb->format->cpp[0]
|
- state->fb->bits_per_pixel / 8
+ state->fb->format->cpp[0]
|
- E * state->fb->bits_per_pixel >> 3
+ E * state->fb->format->cpp[0]
|
- state->fb->bits_per_pixel >> 3
+ state->fb->format->cpp[0]
|
- (state->fb->bits_per_pixel + 7) / 8
+ state->fb->format->cpp[0]
|
- state->fb->bits_per_pixel
+ state->fb->format->cpp[0] * 8
|
- state->fb->format->cpp[0] * 8 != 8
+ state->fb->format->cpp[0] != 1
)

@@
@@
- (8 * 8)
+ 8 * 8

@@
struct drm_framebuffer FB;
@@
- (FB.format->cpp[0])
+ FB.format->cpp[0]

@@
struct drm_framebuffer *FB;
@@
- (FB->format->cpp[0])
+ FB->format->cpp[0]

@@
@@
 struct drm_framebuffer {
 ...
-int bits_per_pixel;
 ...
 };

v2: Clean up the 'cpp*8 != 8' and '(8 * 8)' cases (Laurent)
v3: Adjusted the semantic patch a bit and regenerated due to code
changes

Signed-off-by: Ville Syrjälä 
Reviewed-by: Laurent Pinchart 
Reviewed-by: Alex Deucher  (v1)
---
 drivers/gpu/drm/amd/amdgpu/dce_v10_0.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/dce_v11_0.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/dce_v6_0.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c  |  2 +-
 drivers/gpu/drm/armada/armada_crtc.c   |  2 +-
 drivers/gpu/drm/armada/armada_fbdev.c  |  2 +-
 drivers/gpu/drm/ast/ast_fb.c   |  2 +-
 drivers/gpu/drm/ast/ast_mode.c |  9 +
 drivers/gpu/drm/cirrus/cirrus_fbdev.c  |  2 +-
 drivers/gpu/drm/cirrus/cirrus_mode.c   |  2 +-
 drivers/gpu/drm/drm_fb_helper.c|  8 
 drivers/gpu/drm/drm_framebuffer.c  |  2 +-
 drivers/gpu/drm/drm_modeset_helper.c   |  3 ---
 drivers/gpu/drm/exynos/exynos5433_drm_decon.c  |  4 ++--
 drivers/gpu/drm/exynos/exynos7_drm_decon.c |  6 +++---
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c  |  4 ++--
 drivers/gpu/drm/exynos/exynos_drm_fimd.c   |  2 +-
 drivers/gpu/drm/exynos/exynos_mixer.c  |  4 ++--
 drivers/gpu/drm/gma500/framebuffer.c   |  2 +-
 drivers/gpu/drm/gma500/gma_display.c   |  4 ++--
 drivers/gpu/drm/gma500/mdfld_intel_display.c   |  6 +++---
 drivers/gpu/drm/gma500/oaktrail_crtc.c |  4 ++--
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c |  6 +++---
 drivers/gpu/drm/i915/i915_debugfs.c|  4 ++--
 drivers/gpu/drm/i915/intel_display.c   | 11 ---
 drivers/gpu/drm/i915/intel_fbdev.c |  6 +++---
 drivers/gpu/drm/mgag200/mgag200_fb.c   |  2 +-

[PATCH v2 31/37] drm: Nuke fb->depth

2016-12-14 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Replace uses of fb->depth with fb->format->depth. Less duplicate
information is a good thing.

@@
struct drm_framebuffer *fb;
expression E;
@@
 drm_helper_mode_fill_fb_struct(...) {
...
-   fb->depth = E;
...
 }

@@
struct nouveau_framebuffer *fb;
@@
- fb->base.depth
+ fb->base.format->depth

@@
struct drm_framebuffer fb;
@@
- fb.depth
+ fb.format->depth

@@
struct drm_framebuffer *fb;
@@
- fb->depth
+ fb->format->depth

@@
struct drm_framebuffer fb;
@@
- (fb.format->depth)
+ fb.format->depth

@@
struct drm_framebuffer *fb;
@@
- (fb->format->depth)
+ fb->format->depth

@@
@@
 struct drm_framebuffer {
 ...
-unsigned int depth;
 ...
 };

v2: Drop the vmw stuff (Daniel)
Rerun spatch due to code changes

Signed-off-by: Ville Syrjälä 
Reviewed-by: Laurent Pinchart 
Reviewed-by: Alex Deucher 
Reviewed-by: Daniel Vetter 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c|  4 ++--
 drivers/gpu/drm/armada/armada_fbdev.c |  3 ++-
 drivers/gpu/drm/ast/ast_fb.c  |  2 +-
 drivers/gpu/drm/bochs/bochs_fbdev.c   |  2 +-
 drivers/gpu/drm/cirrus/cirrus_fbdev.c |  4 ++--
 drivers/gpu/drm/drm_fb_cma_helper.c   |  2 +-
 drivers/gpu/drm/drm_fb_helper.c   |  2 +-
 drivers/gpu/drm/drm_framebuffer.c |  2 +-
 drivers/gpu/drm/drm_modeset_helper.c  |  2 --
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c |  2 +-
 drivers/gpu/drm/gma500/accel_2d.c |  2 +-
 drivers/gpu/drm/gma500/framebuffer.c  |  2 +-
 drivers/gpu/drm/gma500/gma_display.c  |  2 +-
 drivers/gpu/drm/gma500/mdfld_intel_display.c  |  2 +-
 drivers/gpu/drm/gma500/oaktrail_crtc.c|  2 +-
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_fbdev.c |  2 +-
 drivers/gpu/drm/i915/i915_debugfs.c   |  4 ++--
 drivers/gpu/drm/i915/intel_fbdev.c|  2 +-
 drivers/gpu/drm/mgag200/mgag200_fb.c  |  2 +-
 drivers/gpu/drm/mgag200/mgag200_mode.c|  6 +++---
 drivers/gpu/drm/msm/msm_fbdev.c   |  2 +-
 drivers/gpu/drm/nouveau/dispnv04/crtc.c   | 12 ++--
 drivers/gpu/drm/nouveau/dispnv04/dfp.c|  2 +-
 drivers/gpu/drm/nouveau/nouveau_fbcon.c   |  3 ++-
 drivers/gpu/drm/omapdrm/omap_fbdev.c  |  2 +-
 drivers/gpu/drm/qxl/qxl_fb.c  |  5 +++--
 drivers/gpu/drm/radeon/radeon_fb.c|  4 ++--
 drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c |  5 +++--
 drivers/gpu/drm/tegra/drm.c   |  3 ++-
 drivers/gpu/drm/tegra/fb.c|  2 +-
 drivers/gpu/drm/udl/udl_fb.c  |  2 +-
 drivers/gpu/drm/virtio/virtgpu_fb.c   |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_fb.c|  5 +++--
 drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c   |  5 +++--
 drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c  |  2 +-
 include/drm/drm_framebuffer.h |  6 --
 36 files changed, 56 insertions(+), 57 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
index 24629bec181a..838943d0962e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
@@ -245,7 +245,7 @@ static int amdgpufb_create(struct drm_fb_helper *helper,

strcpy(info->fix.id, "amdgpudrmfb");

-   drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth);
+   drm_fb_helper_fill_fix(info, fb->pitches[0], fb->format->depth);

info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT;
info->fbops = _ops;
@@ -272,7 +272,7 @@ static int amdgpufb_create(struct drm_fb_helper *helper,
DRM_INFO("fb mappable at 0x%lX\n",  info->fix.smem_start);
DRM_INFO("vram apper at 0x%lX\n",  (unsigned long)adev->mc.aper_base);
DRM_INFO("size %lu\n", (unsigned long)amdgpu_bo_size(abo));
-   DRM_INFO("fb depth is %d\n", fb->depth);
+   DRM_INFO("fb depth is %d\n", fb->format->depth);
DRM_INFO("   pitch is %d\n", fb->pitches[0]);

vga_switcheroo_client_fb_set(adev->ddev->pdev, info);
diff --git a/drivers/gpu/drm/armada/armada_fbdev.c 
b/drivers/gpu/drm/armada/armada_fbdev.c
index c5dc06a55883..3a58fb600b05 100644
--- a/drivers/gpu/drm/armada/armada_fbdev.c
+++ b/drivers/gpu/drm/armada/armada_fbdev.c
@@ -89,7 +89,8 @@ static int armada_fb_create(struct drm_fb_helper *fbh,
info->screen_base = ptr;
fbh->fb = >fb;

-   drm_fb_helper_fill_fix(info, dfb->fb.pitches[0], dfb->fb.depth);
+   drm_fb_helper_fill_fix(info, dfb->fb.pitches[0],
+  dfb->fb.format->depth);
drm_fb

[PATCH v2 25/37] drm: Replace drm_format_plane_cpp() with fb->format->cpp[]

2016-12-14 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Replace drm_format_plane_cpp(fb->pixel_format) with just
fb->format->cpp[]. Avoids the expensive format info lookup.

@@
struct drm_framebuffer *a;
struct drm_framebuffer b;
expression E;
@@
(
- drm_format_plane_cpp(a->pixel_format, E)
+ a->format->cpp[E]
|
- drm_format_plane_cpp(b.pixel_format, E)
+ b.format->cpp[E]
)

@@
struct drm_plane_state *a;
struct drm_plane_state b;
expression E;
@@
(
- drm_format_plane_cpp(a->fb->pixel_format, E)
+ a->fb->format->cpp[E]
|
- drm_format_plane_cpp(b.fb->pixel_format, E)
+ b.fb->format->cpp[E]
)

@@
struct drm_framebuffer *a;
identifier T;
expression E;
@@
  T = a->pixel_format
<+...
- drm_format_plane_cpp(T, E)
+ a->format->cpp[E]
...+>

@@
struct drm_framebuffer b;
identifier T;
expression E;
@@
  T = b.pixel_format
<+...
- drm_format_plane_cpp(T, E)
+ b.format->cpp[E]
...+>

v2: Rerun spatch due to code changes

Cc: Laurent Pinchart 
Suggested-by: Laurent Pinchart 
Signed-off-by: Ville Syrjälä 
Reviewed-by: Laurent Pinchart 
---
 drivers/gpu/drm/arm/hdlcd_crtc.c|  2 +-
 drivers/gpu/drm/armada/armada_crtc.c|  3 +-
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c |  2 +-
 drivers/gpu/drm/i915/intel_display.c| 16 +-
 drivers/gpu/drm/i915/intel_pm.c | 42 -
 drivers/gpu/drm/i915/intel_sprite.c |  2 +-
 drivers/gpu/drm/imx/ipuv3-plane.c   |  6 ++--
 drivers/gpu/drm/mediatek/mtk_drm_plane.c|  2 +-
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c |  4 +--
 drivers/gpu/drm/sti/sti_gdp.c   |  2 +-
 drivers/gpu/drm/sun4i/sun4i_backend.c   |  2 +-
 drivers/gpu/drm/tilcdc/tilcdc_crtc.c|  2 +-
 drivers/gpu/drm/tilcdc/tilcdc_plane.c   |  2 +-
 drivers/gpu/drm/vc4/vc4_plane.c |  2 +-
 drivers/gpu/drm/zte/zx_plane.c  |  2 +-
 15 files changed, 45 insertions(+), 46 deletions(-)

diff --git a/drivers/gpu/drm/arm/hdlcd_crtc.c b/drivers/gpu/drm/arm/hdlcd_crtc.c
index 35705a4173f3..ecdcd99c92cc 100644
--- a/drivers/gpu/drm/arm/hdlcd_crtc.c
+++ b/drivers/gpu/drm/arm/hdlcd_crtc.c
@@ -238,7 +238,7 @@ static void hdlcd_plane_atomic_update(struct drm_plane 
*plane,
scanout_start = gem->paddr + fb->offsets[0] +
plane->state->crtc_y * fb->pitches[0] +
plane->state->crtc_x *
-   drm_format_plane_cpp(fb->pixel_format, 0);
+   fb->format->cpp[0];

hdlcd = plane->dev->dev_private;
hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_LENGTH, fb->pitches[0]);
diff --git a/drivers/gpu/drm/armada/armada_crtc.c 
b/drivers/gpu/drm/armada/armada_crtc.c
index 2e1c63569c72..99283f30edc5 100644
--- a/drivers/gpu/drm/armada/armada_crtc.c
+++ b/drivers/gpu/drm/armada/armada_crtc.c
@@ -169,7 +169,6 @@ void armada_drm_plane_calc_addrs(u32 *addrs, struct 
drm_framebuffer *fb,
int x, int y)
 {
u32 addr = drm_fb_obj(fb)->dev_addr;
-   u32 pixel_format = fb->pixel_format;
int num_planes = fb->format->num_planes;
int i;

@@ -178,7 +177,7 @@ void armada_drm_plane_calc_addrs(u32 *addrs, struct 
drm_framebuffer *fb,

for (i = 0; i < num_planes; i++)
addrs[i] = addr + fb->offsets[i] + y * fb->pitches[i] +
-x * drm_format_plane_cpp(pixel_format, i);
+x * fb->format->cpp[i];
for (; i < 3; i++)
addrs[i] = 0;
 }
diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c 
b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
index f97ae75f9e63..3e00512ef187 100644
--- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
+++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
@@ -672,7 +672,7 @@ static int atmel_hlcdc_plane_atomic_check(struct drm_plane 
*p,
int xdiv = i ? hsub : 1;
int ydiv = i ? vsub : 1;

-   state->bpp[i] = drm_format_plane_cpp(fb->pixel_format, i);
+   state->bpp[i] = fb->format->cpp[i];
if (!state->bpp[i])
return -EINVAL;

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 41f9b3d5ce85..1f9e5adc0d69 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2276,7 +2276,7 @@ u32 intel_fb_xy_to_linear(int x, int y,
  int plane)
 {
const struct drm_framebuffer *fb = state->base.fb;
-   unsigned int cpp = drm_format_plane_cpp(fb->pixel_format, plane);
+   unsigned int cpp = fb->format->cpp[plane];
unsigned int pitch = fb->pitches[plane];

return y * pitch + x * cpp;
@@ -2345,7 +2345,7 @@ static u32 intel_adjust_tile_offset(int *x, int *y,
 {
const st

[PATCH v2 23/37] drm: Replace drm_format_num_planes() with fb->format->num_planes

2016-12-14 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Replace drm_format_num_planes(fb->pixel_format) with just
fb->format->num_planes. Avoids the expensive format info lookup.

@@
struct drm_framebuffer *a;
struct drm_framebuffer b;
@@
(
- drm_format_num_planes(a->pixel_format)
+ a->format->num_planes
|
- drm_format_num_planes(b.pixel_format)
+ b.format->num_planes
)

@@
struct drm_plane_state *a;
struct drm_plane_state b;
@@
(
- drm_format_num_planes(a->fb->pixel_format)
+ a->fb->format->num_planes
|
- drm_format_num_planes(b.fb->pixel_format)
+ b.fb->format->num_planes
)

@@
struct drm_framebuffer *a;
identifier T;
@@
  T = a->pixel_format
<+...
- drm_format_num_planes(T)
+ a->format->num_planes
...+>

@@
struct drm_framebuffer b;
identifier T;
@@
  T = b.pixel_format
<+...
- drm_format_num_planes(T)
+ b.format->num_planes
...+>

v2: Rerun spatch due to code changes

Cc: Laurent Pinchart 
Suggested-by: Laurent Pinchart 
Signed-off-by: Ville Syrjälä 
Reviewed-by: Laurent Pinchart 
---
 drivers/gpu/drm/arm/malidp_planes.c | 2 +-
 drivers/gpu/drm/armada/armada_crtc.c| 2 +-
 drivers/gpu/drm/armada/armada_overlay.c | 2 +-
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_layer.c | 2 +-
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c | 2 +-
 drivers/gpu/drm/drm_atomic.c| 2 +-
 drivers/gpu/drm/i915/intel_display.c| 2 +-
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c   | 2 +-
 drivers/gpu/drm/msm/msm_fb.c| 8 
 drivers/gpu/drm/omapdrm/omap_fb.c   | 8 
 drivers/gpu/drm/tegra/dc.c  | 4 ++--
 drivers/gpu/drm/tegra/fb.c  | 2 +-
 drivers/gpu/drm/vc4/vc4_plane.c | 2 +-
 13 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/arm/malidp_planes.c 
b/drivers/gpu/drm/arm/malidp_planes.c
index ee7f7663a307..533ee2fa64be 100644
--- a/drivers/gpu/drm/arm/malidp_planes.c
+++ b/drivers/gpu/drm/arm/malidp_planes.c
@@ -116,7 +116,7 @@ static int malidp_de_plane_check(struct drm_plane *plane,
if (ms->format == MALIDP_INVALID_FORMAT_ID)
return -EINVAL;

-   ms->n_planes = drm_format_num_planes(fb->pixel_format);
+   ms->n_planes = fb->format->num_planes;
for (i = 0; i < ms->n_planes; i++) {
if (!malidp_hw_pitch_valid(mp->hwdev, fb->pitches[i])) {
DRM_DEBUG_KMS("Invalid pitch %u for plane %d\n",
diff --git a/drivers/gpu/drm/armada/armada_crtc.c 
b/drivers/gpu/drm/armada/armada_crtc.c
index 95cb3966b2ca..2e1c63569c72 100644
--- a/drivers/gpu/drm/armada/armada_crtc.c
+++ b/drivers/gpu/drm/armada/armada_crtc.c
@@ -170,7 +170,7 @@ void armada_drm_plane_calc_addrs(u32 *addrs, struct 
drm_framebuffer *fb,
 {
u32 addr = drm_fb_obj(fb)->dev_addr;
u32 pixel_format = fb->pixel_format;
-   int num_planes = drm_format_num_planes(pixel_format);
+   int num_planes = fb->format->num_planes;
int i;

if (num_planes > 3)
diff --git a/drivers/gpu/drm/armada/armada_overlay.c 
b/drivers/gpu/drm/armada/armada_overlay.c
index 6743615232f5..a0883a1b3387 100644
--- a/drivers/gpu/drm/armada/armada_overlay.c
+++ b/drivers/gpu/drm/armada/armada_overlay.c
@@ -188,7 +188,7 @@ armada_ovl_plane_update(struct drm_plane *plane, struct 
drm_crtc *crtc,

pixel_format = fb->pixel_format;
hsub = drm_format_horz_chroma_subsampling(pixel_format);
-   num_planes = drm_format_num_planes(pixel_format);
+   num_planes = fb->format->num_planes;

/*
 * Annoyingly, shifting a YUYV-format image by one pixel
diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_layer.c 
b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_layer.c
index 377e43cea9dd..63dfdbf34f80 100644
--- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_layer.c
+++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_layer.c
@@ -446,7 +446,7 @@ void atmel_hlcdc_layer_update_set_fb(struct 
atmel_hlcdc_layer *layer,
return;

if (fb)
-   nplanes = drm_format_num_planes(fb->pixel_format);
+   nplanes = fb->format->num_planes;

if (nplanes > layer->max_planes)
return;
diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c 
b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
index 246ed1e33d8a..f97ae75f9e63 100644
--- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
+++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
@@ -621,7 +621,7 @@ static int atmel_hlcdc_plane_atomic_check(struct drm_plane 
*p,
state->src_w >>= 16;
state->src_h >>= 16;

-   state->nplanes = drm_format_num_planes(fb->pixel_format);
+   state->nplanes = fb->format->num_planes;
if (state->npl

[PATCH v2 13/37] drm: Pass 'dev' to drm_helper_mode_fill_fb_struct()

2016-12-14 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Pass the drm_device to drm_helper_mode_fill_fb_struct() so that we can
populate fb->dev early. Will make it easier to use the fb before we
register it.

@@
identifier fb, mode_cmd;
@@
 void drm_helper_mode_fill_fb_struct(
+struct drm_device *dev,
 struct drm_framebuffer *fb,
 const struct drm_mode_fb_cmd2 *mode_cmd
 );

@@
identifier fb, mode_cmd;
@@
 void drm_helper_mode_fill_fb_struct(
+struct drm_device *dev,
 struct drm_framebuffer *fb,
 const struct drm_mode_fb_cmd2 *mode_cmd
 )
{ ... }

@@
function func;
identifier dev;
expression E1, E2;
@@
func(struct drm_device *dev, ...)
{
 ...
 drm_helper_mode_fill_fb_struct(
+   dev,
E1, E2);
 ...
}

@@
expression E1, E2;
@@
 drm_helper_mode_fill_fb_struct(
+   dev,
E1, E2);

v2: Rerun spatch due to code changes

Signed-off-by: Ville Syrjälä 
Reviewed-by: Laurent Pinchart 
Reviewed-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 2 +-
 drivers/gpu/drm/armada/armada_fb.c  | 2 +-
 drivers/gpu/drm/ast/ast_main.c  | 2 +-
 drivers/gpu/drm/bochs/bochs_mm.c| 2 +-
 drivers/gpu/drm/cirrus/cirrus_main.c| 2 +-
 drivers/gpu/drm/drm_fb_cma_helper.c | 2 +-
 drivers/gpu/drm/drm_modeset_helper.c| 3 ++-
 drivers/gpu/drm/exynos/exynos_drm_fb.c  | 2 +-
 drivers/gpu/drm/gma500/framebuffer.c| 2 +-
 drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 2 +-
 drivers/gpu/drm/i915/intel_display.c| 2 +-
 drivers/gpu/drm/mediatek/mtk_drm_fb.c   | 2 +-
 drivers/gpu/drm/mgag200/mgag200_main.c  | 2 +-
 drivers/gpu/drm/msm/msm_fb.c| 2 +-
 drivers/gpu/drm/nouveau/nouveau_display.c   | 2 +-
 drivers/gpu/drm/omapdrm/omap_fb.c   | 2 +-
 drivers/gpu/drm/qxl/qxl_display.c   | 2 +-
 drivers/gpu/drm/radeon/radeon_display.c | 2 +-
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c  | 2 +-
 drivers/gpu/drm/tegra/fb.c  | 2 +-
 drivers/gpu/drm/udl/udl_fb.c| 2 +-
 drivers/gpu/drm/virtio/virtgpu_display.c| 2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 4 ++--
 include/drm/drm_modeset_helper.h| 3 ++-
 24 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
index 581601ca6b89..d2036df145b3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
@@ -508,7 +508,7 @@ amdgpu_framebuffer_init(struct drm_device *dev,
 {
int ret;
rfb->obj = obj;
-   drm_helper_mode_fill_fb_struct(>base, mode_cmd);
+   drm_helper_mode_fill_fb_struct(dev, >base, mode_cmd);
ret = drm_framebuffer_init(dev, >base, _fb_funcs);
if (ret) {
rfb->obj = NULL;
diff --git a/drivers/gpu/drm/armada/armada_fb.c 
b/drivers/gpu/drm/armada/armada_fb.c
index f03c212b754d..2a7eb6817c36 100644
--- a/drivers/gpu/drm/armada/armada_fb.c
+++ b/drivers/gpu/drm/armada/armada_fb.c
@@ -81,7 +81,7 @@ struct armada_framebuffer *armada_framebuffer_create(struct 
drm_device *dev,
dfb->mod = config;
dfb->obj = obj;

-   drm_helper_mode_fill_fb_struct(>fb, mode);
+   drm_helper_mode_fill_fb_struct(dev, >fb, mode);

ret = drm_framebuffer_init(dev, >fb, _fb_funcs);
if (ret) {
diff --git a/drivers/gpu/drm/ast/ast_main.c b/drivers/gpu/drm/ast/ast_main.c
index 904beaa932d0..d85af0ff2653 100644
--- a/drivers/gpu/drm/ast/ast_main.c
+++ b/drivers/gpu/drm/ast/ast_main.c
@@ -313,7 +313,7 @@ int ast_framebuffer_init(struct drm_device *dev,
 {
int ret;

-   drm_helper_mode_fill_fb_struct(_fb->base, mode_cmd);
+   drm_helper_mode_fill_fb_struct(dev, _fb->base, mode_cmd);
ast_fb->obj = obj;
ret = drm_framebuffer_init(dev, _fb->base, _fb_funcs);
if (ret) {
diff --git a/drivers/gpu/drm/bochs/bochs_mm.c b/drivers/gpu/drm/bochs/bochs_mm.c
index 099a3c688c26..ceb1fecf02dd 100644
--- a/drivers/gpu/drm/bochs/bochs_mm.c
+++ b/drivers/gpu/drm/bochs/bochs_mm.c
@@ -484,7 +484,7 @@ int bochs_framebuffer_init(struct drm_device *dev,
 {
int ret;

-   drm_helper_mode_fill_fb_struct(>base, mode_cmd);
+   drm_helper_mode_fill_fb_struct(dev, >base, mode_cmd);
gfb->obj = obj;
ret = drm_framebuffer_init(dev, >base, _fb_funcs);
if (ret) {
diff --git a/drivers/gpu/drm/cirrus/cirrus_main.c 
b/drivers/gpu/drm/cirrus/cirrus_main.c
index 2c3c0d4072ce..52d901fa8687 100644
--- a/dr

[PATCH] drm/atomic: Constify drm_atomic_crtc_needs_modeset()

2016-11-24 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

drm_atomic_crtc_needs_modeset() doesn't change the passed in
crtc state, so pass it as const.

Signed-off-by: Ville Syrjälä 
---
 include/drm/drm_atomic.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
index 5d5f85db43f0..d6d241f63b9f 100644
--- a/include/drm/drm_atomic.h
+++ b/include/drm/drm_atomic.h
@@ -418,7 +418,7 @@ int drm_atomic_debugfs_cleanup(struct drm_minor *minor);
  * should clear mode_changed during its ->atomic_check.
  */
 static inline bool
-drm_atomic_crtc_needs_modeset(struct drm_crtc_state *state)
+drm_atomic_crtc_needs_modeset(const struct drm_crtc_state *state)
 {
return state->mode_changed || state->active_changed ||
   state->connectors_changed;
-- 
2.7.4



[PATCH v2 12/37] drm/vmwgfx: Populate fb->dev before drm_framebuffer_init()

2016-11-22 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

drm_framebuffer_init() will start to check that fb->dev is already
populated, so let's do that manually since vmwgfx isn't using
drm_helper_mode_fill_fb_struct().

v2: s/to/do/ (Sinclair)

Cc: linux-graphics-maintainer at vmware.com
Cc: Sinclair Yeh 
Cc: Thomas Hellstrom 
Signed-off-by: Ville Syrjälä 
Reviewed-by: Sinclair Yeh 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index e3f68cc9bb4b..7d92ab56961b 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -581,6 +581,7 @@ static int vmw_kms_new_framebuffer_surface(struct 
vmw_private *dev_priv,
goto out_err1;
}

+   vfbs->base.base.dev = dev;
/* XXX get the first 3 from the surface info */
vfbs->base.base.bits_per_pixel = mode_cmd->bpp;
vfbs->base.base.pitches[0] = mode_cmd->pitch;
@@ -875,6 +876,7 @@ static int vmw_kms_new_framebuffer_dmabuf(struct 
vmw_private *dev_priv,
goto out_err1;
}

+   vfbd->base.base.dev = dev;
vfbd->base.base.bits_per_pixel = mode_cmd->bpp;
vfbd->base.base.pitches[0] = mode_cmd->pitch;
vfbd->base.base.depth = mode_cmd->depth;
-- 
2.7.4



[PATCH v2 36/37] drm: Add mode_config .get_format_info() hook

2016-11-22 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Allow drivers to return a custom drm_format_info structure for special
fb layouts. We'll use this for the compression control surface in i915.

v2: Fix drm_get_format_info() kernel doc (Laurent)
Don't pass 'dev' to the new hook (Laurent)

Cc: Laurent Pinchart 
Cc: Ben Widawsky 
Cc: intel-gfx at lists.freedesktop.org
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_fb_cma_helper.c  |  2 +-
 drivers/gpu/drm/drm_fourcc.c | 25 +
 drivers/gpu/drm/drm_framebuffer.c|  9 +++--
 drivers/gpu/drm/drm_modeset_helper.c |  2 +-
 include/drm/drm_fourcc.h |  6 ++
 include/drm/drm_mode_config.h| 14 ++
 6 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_fb_cma_helper.c 
b/drivers/gpu/drm/drm_fb_cma_helper.c
index aab4465307ed..d7f8876cf5e9 100644
--- a/drivers/gpu/drm/drm_fb_cma_helper.c
+++ b/drivers/gpu/drm/drm_fb_cma_helper.c
@@ -186,7 +186,7 @@ struct drm_framebuffer *drm_fb_cma_create_with_funcs(struct 
drm_device *dev,
int ret;
int i;

-   info = drm_format_info(mode_cmd->pixel_format);
+   info = drm_get_format_info(dev, mode_cmd);
if (!info)
return ERR_PTR(-EINVAL);

diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index 90d2cc8da8eb..f9b6445e846a 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -199,6 +199,31 @@ const struct drm_format_info *drm_format_info(u32 format)
 EXPORT_SYMBOL(drm_format_info);

 /**
+ * drm_get_format_info - query information for a given framebuffer 
configuration
+ * @dev: DRM device
+ * @mode_cmd: metadata from the userspace fb creation request
+ *
+ * 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_get_format_info(struct drm_device *dev,
+   const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+   const struct drm_format_info *info = NULL;
+
+   if (dev->mode_config.funcs->get_format_info)
+   info = dev->mode_config.funcs->get_format_info(mode_cmd);
+
+   if (!info)
+   info = drm_format_info(mode_cmd->pixel_format);
+
+   return info;
+}
+EXPORT_SYMBOL(drm_get_format_info);
+
+/**
  * drm_format_num_planes - get the number of planes for format
  * @format: pixel format (DRM_FORMAT_*)
  *
diff --git a/drivers/gpu/drm/drm_framebuffer.c 
b/drivers/gpu/drm/drm_framebuffer.c
index 94ddab41f24f..292930a5dcc2 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -126,11 +126,13 @@ int drm_mode_addfb(struct drm_device *dev,
return 0;
 }

-static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
+static int framebuffer_check(struct drm_device *dev,
+const struct drm_mode_fb_cmd2 *r)
 {
const struct drm_format_info *info;
int i;

+   /* check if the format is supported at all */
info = __drm_format_info(r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN);
if (!info) {
struct drm_format_name_buf format_name;
@@ -140,6 +142,9 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 
*r)
return -EINVAL;
}

+   /* now let the driver pick its own format info */
+   info = drm_get_format_info(dev, r);
+
if (r->width == 0 || r->width % info->hsub) {
DRM_DEBUG_KMS("bad framebuffer width %u\n", r->width);
return -EINVAL;
@@ -263,7 +268,7 @@ drm_internal_framebuffer_create(struct drm_device *dev,
return ERR_PTR(-EINVAL);
}

-   ret = framebuffer_check(r);
+   ret = framebuffer_check(dev, r);
if (ret)
return ERR_PTR(ret);

diff --git a/drivers/gpu/drm/drm_modeset_helper.c 
b/drivers/gpu/drm/drm_modeset_helper.c
index 5b051859b8d3..f78df06a940d 100644
--- a/drivers/gpu/drm/drm_modeset_helper.c
+++ b/drivers/gpu/drm/drm_modeset_helper.c
@@ -75,7 +75,7 @@ void drm_helper_mode_fill_fb_struct(struct drm_device *dev,
int i;

fb->dev = dev;
-   fb->format = drm_format_info(mode_cmd->pixel_format);
+   fb->format = drm_get_format_info(dev, mode_cmd);
fb->width = mode_cmd->width;
fb->height = mode_cmd->height;
for (i = 0; i < 4; i++) {
diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
index fcc08da850c8..6942e84b6edd 100644
--- a/include/drm/drm_fourcc.h
+++ b/include/drm/drm_fourcc.h
@@ -25,6 +25,9 @@
 #include 
 #include 

+struct drm_device;
+struct drm_mode_fb_cmd2;
+
 /**
  * struct drm_format_info - information about a DRM format
  * @format: 4CC format identifier (DRM_FORMAT_*)
@@ -55,6 +58,9 @@ struct drm_format_name_buf {

 const struct drm_format_info *__drm_format_info(u32 fo

[PATCH 37/37] drm/i915: Implement .get_format_info() hook for CCS

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

By providing our own format information for the CCS formats, we should
be able to make framebuffer_check() do the right thing for the CCS
surface as well.

Note that we'll return the same format info for both Y and Yf tiled
format as that's what happens with the non-CCS Y vs. Yf as well. If
desired, we could potentially return a unique pointer for each
pixel_format+tiling+ccs combination, in which case we immediately be
able to tell if any of that stuff changed by just comparing the
pointers. But that does sound a bit wasteful space wise.

Cc: Ben Widawsky 
Cc: intel-gfx at lists.freedesktop.org
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_display.c | 37 
 include/uapi/drm/drm_fourcc.h|  3 +++
 2 files changed, 40 insertions(+)

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 7b7135be3b9e..de6909770c68 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2488,6 +2488,42 @@ static unsigned int intel_fb_modifier_to_tiling(uint64_t 
fb_modifier)
}
 }

+static const struct drm_format_info ccs_formats[] = {
+   { .format = DRM_FORMAT_XRGB, .depth = 24, .num_planes = 2, .cpp = { 
4, 1, }, .hsub = 16, .vsub = 8, },
+   { .format = DRM_FORMAT_XBGR, .depth = 24, .num_planes = 2, .cpp = { 
4, 1, }, .hsub = 16, .vsub = 8, },
+   { .format = DRM_FORMAT_ARGB, .depth = 32, .num_planes = 2, .cpp = { 
4, 1, }, .hsub = 16, .vsub = 8, },
+   { .format = DRM_FORMAT_ABGR, .depth = 32, .num_planes = 2, .cpp = { 
4, 1, }, .hsub = 16, .vsub = 8, },
+};
+
+static const struct drm_format_info *
+lookup_format_info(const struct drm_format_info formats[],
+  int num_formats, u32 format)
+{
+   int i;
+
+   for (i = 0; i < num_formats; i++) {
+   if (formats[i].format == format)
+   return [i];
+   }
+
+   return NULL;
+}
+
+static const struct drm_format_info *
+intel_get_format_info(struct drm_device *dev,
+ const struct drm_mode_fb_cmd2 *cmd)
+{
+   switch (cmd->modifier[0]) {
+   case I915_FORMAT_MOD_Y_TILED_CCS:
+   case I915_FORMAT_MOD_Yf_TILED_CCS:
+   return lookup_format_info(ccs_formats,
+ ARRAY_SIZE(ccs_formats),
+ cmd->pixel_format);
+   default:
+   return NULL;
+   }
+}
+
 static int
 intel_fill_fb_info(struct drm_i915_private *dev_priv,
   struct drm_framebuffer *fb)
@@ -15922,6 +15958,7 @@ intel_user_framebuffer_create(struct drm_device *dev,

 static const struct drm_mode_config_funcs intel_mode_funcs = {
.fb_create = intel_user_framebuffer_create,
+   .get_format_info = intel_get_format_info,
.output_poll_changed = intel_fbdev_output_poll_changed,
.atomic_check = intel_atomic_check,
.atomic_commit = intel_atomic_commit,
diff --git a/include/uapi/drm/drm_fourcc.h b/include/uapi/drm/drm_fourcc.h
index a5890bf44c0a..2926d916f199 100644
--- a/include/uapi/drm/drm_fourcc.h
+++ b/include/uapi/drm/drm_fourcc.h
@@ -218,6 +218,9 @@ extern "C" {
  */
 #define I915_FORMAT_MOD_Yf_TILED fourcc_mod_code(INTEL, 3)

+#define I915_FORMAT_MOD_Y_TILED_CCSfourcc_mod_code(INTEL, 4)
+#define I915_FORMAT_MOD_Yf_TILED_CCS   fourcc_mod_code(INTEL, 5)
+
 /*
  * Tiled, NV12MT, grouped in 64 (pixels) x 32 (lines) -sized macroblocks
  *
-- 
2.7.4



[PATCH 36/37] drm: Add mode_config .get_format_info() hook

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Allow drivers to return a custom drm_format_info structure for special
fb layouts. We'll use this for the compression control surface in i915.

Cc: Ben Widawsky 
Cc: intel-gfx at lists.freedesktop.org
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_fb_cma_helper.c  |  2 +-
 drivers/gpu/drm/drm_fourcc.c | 25 +
 drivers/gpu/drm/drm_framebuffer.c|  9 +++--
 drivers/gpu/drm/drm_modeset_helper.c |  2 +-
 include/drm/drm_fourcc.h |  6 ++
 include/drm/drm_mode_config.h| 15 +++
 6 files changed, 55 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_fb_cma_helper.c 
b/drivers/gpu/drm/drm_fb_cma_helper.c
index aab4465307ed..d7f8876cf5e9 100644
--- a/drivers/gpu/drm/drm_fb_cma_helper.c
+++ b/drivers/gpu/drm/drm_fb_cma_helper.c
@@ -186,7 +186,7 @@ struct drm_framebuffer *drm_fb_cma_create_with_funcs(struct 
drm_device *dev,
int ret;
int i;

-   info = drm_format_info(mode_cmd->pixel_format);
+   info = drm_get_format_info(dev, mode_cmd);
if (!info)
return ERR_PTR(-EINVAL);

diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index 90d2cc8da8eb..7cfaee689f0c 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -199,6 +199,31 @@ const struct drm_format_info *drm_format_info(u32 format)
 EXPORT_SYMBOL(drm_format_info);

 /**
+ * drm_format_info - query information for a given framebuffer configuration
+ * @dev: DRM device
+ * @mode_cmd: metadata from the userspace fb creation request
+ *
+ * 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_get_format_info(struct drm_device *dev,
+   const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+   const struct drm_format_info *info = NULL;
+
+   if (dev->mode_config.funcs->get_format_info)
+   info = dev->mode_config.funcs->get_format_info(dev, mode_cmd);
+
+   if (!info)
+   info = drm_format_info(mode_cmd->pixel_format);
+
+   return info;
+}
+EXPORT_SYMBOL(drm_get_format_info);
+
+/**
  * drm_format_num_planes - get the number of planes for format
  * @format: pixel format (DRM_FORMAT_*)
  *
diff --git a/drivers/gpu/drm/drm_framebuffer.c 
b/drivers/gpu/drm/drm_framebuffer.c
index 94ddab41f24f..292930a5dcc2 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -126,11 +126,13 @@ int drm_mode_addfb(struct drm_device *dev,
return 0;
 }

-static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
+static int framebuffer_check(struct drm_device *dev,
+const struct drm_mode_fb_cmd2 *r)
 {
const struct drm_format_info *info;
int i;

+   /* check if the format is supported at all */
info = __drm_format_info(r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN);
if (!info) {
struct drm_format_name_buf format_name;
@@ -140,6 +142,9 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 
*r)
return -EINVAL;
}

+   /* now let the driver pick its own format info */
+   info = drm_get_format_info(dev, r);
+
if (r->width == 0 || r->width % info->hsub) {
DRM_DEBUG_KMS("bad framebuffer width %u\n", r->width);
return -EINVAL;
@@ -263,7 +268,7 @@ drm_internal_framebuffer_create(struct drm_device *dev,
return ERR_PTR(-EINVAL);
}

-   ret = framebuffer_check(r);
+   ret = framebuffer_check(dev, r);
if (ret)
return ERR_PTR(ret);

diff --git a/drivers/gpu/drm/drm_modeset_helper.c 
b/drivers/gpu/drm/drm_modeset_helper.c
index 5b051859b8d3..f78df06a940d 100644
--- a/drivers/gpu/drm/drm_modeset_helper.c
+++ b/drivers/gpu/drm/drm_modeset_helper.c
@@ -75,7 +75,7 @@ void drm_helper_mode_fill_fb_struct(struct drm_device *dev,
int i;

fb->dev = dev;
-   fb->format = drm_format_info(mode_cmd->pixel_format);
+   fb->format = drm_get_format_info(dev, mode_cmd);
fb->width = mode_cmd->width;
fb->height = mode_cmd->height;
for (i = 0; i < 4; i++) {
diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
index fcc08da850c8..6942e84b6edd 100644
--- a/include/drm/drm_fourcc.h
+++ b/include/drm/drm_fourcc.h
@@ -25,6 +25,9 @@
 #include 
 #include 

+struct drm_device;
+struct drm_mode_fb_cmd2;
+
 /**
  * struct drm_format_info - information about a DRM format
  * @format: 4CC format identifier (DRM_FORMAT_*)
@@ -55,6 +58,9 @@ struct drm_format_name_buf {

 const struct drm_format_info *__drm_format_info(u32 format);
 const struct drm_format_info *drm_format_info(u32 format);
+const struct drm_format_info *
+drm_get_forma

[PATCH 35/37] drm: Eliminate the useless "non-RGB fb" debug message

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

No point in spamming the log whenever a non-RGB fb is being
constructed. And since there's nothing to do anymore that
fb->bits_per_pixel and fb->depth are gone, we can just kill
off this entire piece of code.

Cc: Laurent Pinchart 
Suggested-by: Laurent Pinchart 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_modeset_helper.c | 13 +
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/drm_modeset_helper.c 
b/drivers/gpu/drm/drm_modeset_helper.c
index 639e474e7d43..5b051859b8d3 100644
--- a/drivers/gpu/drm/drm_modeset_helper.c
+++ b/drivers/gpu/drm/drm_modeset_helper.c
@@ -72,21 +72,10 @@ void drm_helper_mode_fill_fb_struct(struct drm_device *dev,
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) {
-   struct drm_format_name_buf format_name;
-
-   DRM_DEBUG_KMS("non-RGB pixel format %s\n",
- drm_get_format_name(mode_cmd->pixel_format,
- _name));
-   } else {
-   }
-
fb->dev = dev;
-   fb->format = info;
+   fb->format = drm_format_info(mode_cmd->pixel_format);
fb->width = mode_cmd->width;
fb->height = mode_cmd->height;
for (i = 0; i < 4; i++) {
-- 
2.7.4



[PATCH 34/37] drm: Replace 'format->format' comparisons to just 'format' comparisons

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Rather than compare the format u32s of two format infos, we can direclty
compare the format info pointers themselves. Noramlly all the ->format
pointers all point to somwehere in the big array, so this is a valid
way to test for equality.

Also drivers may want to point ->format at a private format info struct
instead (eg. for special compressed formats with extra planes), so
just comparing the pixel format values wouldn't necessaritly even work.
But comparing the pointers will also take care of that case.

@@
struct drm_framebuffer *a;
struct drm_framebuffer *b;
@@
(
- a->format->format != b->format->format
+ a->format != b->format
|
- a->format->format == b->format->format
+ a->format == b->format
)

@@
struct drm_plane_state *a;
struct drm_plane_state *b;
@@
(
- a->fb->format->format != b->fb->format->format
+ a->fb->format != b->fb->format
|
- a->fb->format->format == b->fb->format->format
+ a->fb->format == b->fb->format
)

@@
struct drm_crtc *crtc;
struct drm_framebuffer *x;
@@
(
- crtc->primary->fb->format->format != x->format->format
+ crtc->primary->fb->format != x->format
|
- x->format->format != crtc->primary->fb->format->format
+ x->format != crtc->primary->fb->format
)

@@
struct drm_mode_set *set;
@@
- set->fb->format->format != set->crtc->primary->fb->format->format
+ set->fb->format != set->crtc->primary->fb->format

Cc: Laurent Pinchart 
Suggested-by: Laurent Pinchart 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/armada/armada_crtc.c  | 2 +-
 drivers/gpu/drm/drm_crtc_helper.c | 3 +--
 drivers/gpu/drm/drm_plane.c   | 2 +-
 drivers/gpu/drm/i915/intel_display.c  | 2 +-
 drivers/gpu/drm/imx/ipuv3-plane.c | 6 +++---
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c | 2 +-
 drivers/gpu/drm/tilcdc/tilcdc_plane.c | 2 +-
 7 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/armada/armada_crtc.c 
b/drivers/gpu/drm/armada/armada_crtc.c
index 52e139dc9e38..baebf3775f60 100644
--- a/drivers/gpu/drm/armada/armada_crtc.c
+++ b/drivers/gpu/drm/armada/armada_crtc.c
@@ -996,7 +996,7 @@ static int armada_drm_crtc_page_flip(struct drm_crtc *crtc,
int ret;

/* We don't support changing the pixel format */
-   if (fb->format->format != crtc->primary->fb->format->format)
+   if (fb->format != crtc->primary->fb->format)
return -EINVAL;

work = kmalloc(sizeof(*work), GFP_KERNEL);
diff --git a/drivers/gpu/drm/drm_crtc_helper.c 
b/drivers/gpu/drm/drm_crtc_helper.c
index 94bce0b462aa..9d007f5f9732 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -588,8 +588,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
if (set->crtc->primary->fb == NULL) {
DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
mode_changed = true;
-   } else if (set->fb->format->format !=
-  set->crtc->primary->fb->format->format) {
+   } else if (set->fb->format != set->crtc->primary->fb->format) {
mode_changed = true;
} else
fb_changed = true;
diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
index ac1e06df7280..1d90520457d7 100644
--- a/drivers/gpu/drm/drm_plane.c
+++ b/drivers/gpu/drm/drm_plane.c
@@ -854,7 +854,7 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
if (ret)
goto out;

-   if (crtc->primary->fb->format->format != fb->format->format) {
+   if (crtc->primary->fb->format != fb->format) {
DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer 
format.\n");
ret = -EINVAL;
goto out;
diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index f5f9f1422d69..7b7135be3b9e 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -12148,7 +12148,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
return -EBUSY;

/* Can't change pixel format via MI display flips. */
-   if (fb->format->format != crtc->primary->fb->format->format)
+   if (fb->format != crtc->primary->fb->format)
return -EINVAL;

/*
diff --git a/drivers/gpu/drm/imx/ipuv3-plane.c 
b/drivers/gpu/drm/imx/ipuv3-plane.c
index 0b945f077344..8b5294d47cee 100644
--- a/drivers/gpu/drm/imx/ipuv3-plane.c
+++ b/drivers/gpu/drm/imx/ipuv3-plane.c
@@ -281,7 +281,7 @@ static int ipu_plane_ato

[PATCH v2 33/37] drm: Nuke fb->pixel_format

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Replace uses of fb->pixel_format with fb->format->format.
Less duplicated information is a good thing.

Note that coccinelle failed to eliminate the
"/* fourcc format */" comment from drm_framebuffer.h, so I had
to do that part manually.

@@
struct drm_framebuffer *fb;
expression E;
@@
 drm_helper_mode_fill_fb_struct(...) {
...
-   fb->pixel_format = E;
...
 }

@@
struct vmw_framebuffer_surface *vfb;
expression E;
@@
- vfb->base.base.pixel_format = E;

@@
struct vmw_framebuffer_dmabuf *vfb;
expression E;
@@
- vfb->base.base.pixel_format = E;

@@
struct drm_framebuffer *fb;
expression E;
@@
 i9xx_get_initial_plane_config(...) {
...
-   fb->pixel_format = E;
...
 }

@@
struct drm_framebuffer *fb;
expression E;
@@
 ironlake_get_initial_plane_config(...) {
...
-   fb->pixel_format = E;
...
 }

@@
struct drm_framebuffer *fb;
expression E;
@@
 skylake_get_initial_plane_config(...) {
...
-   fb->pixel_format = E;
...
 }

@@
struct drm_framebuffer *a;
struct drm_framebuffer b;
@@
(
- a->pixel_format
+ a->format->format
|
- b.pixel_format
+ b.format->format
)

@@
struct drm_plane_state *a;
struct drm_plane_state b;
@@
(
- a->fb->pixel_format
+ a->fb->format->format
|
- b.fb->pixel_format
+ b.fb->format->format
)

@@
struct drm_crtc *crtc;
@@
- crtc->primary->fb->pixel_format
+ crtc->primary->fb->format->format

@@
struct drm_mode_set *set;
@@
(
- set->fb->pixel_format
+ set->fb->format->format
|
- set->crtc->primary->fb->pixel_format
+ set->crtc->primary->fb->format->format
)

@@
@@
 struct drm_framebuffer {
 ...
-uint32_t pixel_format;
 ...
 };

v2: Fix commit message (Laurent)
Rebase due to earlier removal of many fb->pixel_format uses,
including the 'fb->format = drm_format_info(fb->format->format);'
snafu

Cc: Laurent Pinchart 
Signed-off-by: Ville Syrjälä 
Reviewed-by: Alex Deucher  (v1)
---
 drivers/gpu/drm/amd/amdgpu/dce_v10_0.c  |  4 +--
 drivers/gpu/drm/amd/amdgpu/dce_v11_0.c  |  4 +--
 drivers/gpu/drm/amd/amdgpu/dce_v6_0.c   |  4 +--
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c   |  4 +--
 drivers/gpu/drm/arc/arcpgu_crtc.c   |  2 +-
 drivers/gpu/drm/arm/hdlcd_crtc.c|  2 +-
 drivers/gpu/drm/arm/malidp_planes.c |  8 +++---
 drivers/gpu/drm/armada/armada_crtc.c|  2 +-
 drivers/gpu/drm/armada/armada_overlay.c |  2 +-
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c | 18 ++---
 drivers/gpu/drm/drm_atomic.c|  6 ++---
 drivers/gpu/drm/drm_crtc.c  |  4 +--
 drivers/gpu/drm/drm_crtc_helper.c   |  4 +--
 drivers/gpu/drm/drm_fb_cma_helper.c |  2 +-
 drivers/gpu/drm/drm_modeset_helper.c|  1 -
 drivers/gpu/drm/drm_plane.c |  6 ++---
 drivers/gpu/drm/exynos/exynos5433_drm_decon.c   |  2 +-
 drivers/gpu/drm/exynos/exynos7_drm_decon.c  |  2 +-
 drivers/gpu/drm/exynos/exynos_drm_fimd.c|  2 +-
 drivers/gpu/drm/exynos/exynos_mixer.c   |  8 +++---
 drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c |  4 +--
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c |  6 ++---
 drivers/gpu/drm/i915/i915_debugfs.c |  3 ++-
 drivers/gpu/drm/i915/intel_atomic_plane.c   |  4 +--
 drivers/gpu/drm/i915/intel_display.c| 33 +++-
 drivers/gpu/drm/i915/intel_fbdev.c  |  2 +-
 drivers/gpu/drm/i915/intel_overlay.c|  2 +-
 drivers/gpu/drm/i915/intel_pm.c | 10 
 drivers/gpu/drm/i915/intel_sprite.c | 12 -
 drivers/gpu/drm/imx/ipuv3-plane.c   | 34 -
 drivers/gpu/drm/mediatek/mtk_drm_plane.c|  2 +-
 drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c   |  2 +-
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c   |  2 +-
 drivers/gpu/drm/msm/msm_fb.c|  2 +-
 drivers/gpu/drm/nouveau/dispnv04/overlay.c  |  8 +++---
 drivers/gpu/drm/nouveau/nv50_display.c  |  4 +--
 drivers/gpu/drm/omapdrm/omap_fb.c   |  2 +-
 drivers/gpu/drm/radeon/atombios_crtc.c  |  8 +++---
 drivers/gpu/drm/rcar-du/rcar_du_plane.c |  4 +--
 drivers/gpu/drm/rcar-du/rcar_du_vsp.c   |  4 +--
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 18 ++---
 drivers/gpu/drm/shmobile/shmob_drm_crtc.c   |  6 ++---
 drivers/gpu/drm/shmobile/shmob_drm_plane.c  |  4 +--
 drivers/gpu/drm/sti/sti_gdp.c   |  8 +++---
 drivers/gpu/drm/sti/sti_hqvdp.c |  2 +-
 drivers/gpu/drm/sun4i/sun4i_backend.c   |  3 ++-
 drivers/gpu/drm/tegra/dc.c  |  2 +-
 drivers/gpu/drm/tilcdc/tilcdc_crtc.c

[PATCH v2 32/37] drm: Nuke fb->bits_per_pixel

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Replace uses of fb->bits_per_pixel with fb->format->cpp[0]*8.
Less duplicated information is a good thing.

Note that I didn't put parens around the cpp*8 in the below cocci script,
on account of not wanting spurious parens all over the place. Instead I
did the unsafe way, and tried to look over the entire diff to spot if
any dangerous expressions were produced. I didn't see any.

There are some cases where previously the code did X*bpp/8, so the
division happened after the multiplication. Those are now just X*cpp
so the division effectively happens before the multiplication,
but that is perfectly fine since bpp is always a multiple of 8.

@@
struct drm_framebuffer *fb;
expression E;
@@
 drm_helper_mode_fill_fb_struct(...) {
...
-   fb->bits_per_pixel = E;
...
 }

@@
struct vmw_framebuffer_surface *vfb;
expression E;
@@
- vfb->base.base.bits_per_pixel = E;

@@
struct vmw_framebuffer_dmabuf *vfb;
expression E;
@@
- vfb->base.base.bits_per_pixel = E;

@@
struct drm_framebuffer *fb;
expression E;
@@
 i9xx_get_initial_plane_config(...) {
...
-   fb->bits_per_pixel = E;
...
 }

@@
struct drm_framebuffer *fb;
expression E;
@@
 ironlake_get_initial_plane_config(...) {
...
-   fb->bits_per_pixel = E;
...
 }

@@
struct drm_framebuffer *fb;
expression E;
@@
 skylake_get_initial_plane_config(...) {
...
-   fb->bits_per_pixel = E;
...
 }

@@
struct drm_framebuffer fb;
expression E;
@@
(
- E * fb.bits_per_pixel / 8
+ E * fb.format->cpp[0]
|
- fb.bits_per_pixel / 8
+ fb.format->cpp[0]
|
- E * fb.bits_per_pixel >> 3
+ E * fb.format->cpp[0]
|
- fb.bits_per_pixel >> 3
+ fb.format->cpp[0]
|
- (fb.bits_per_pixel + 7) / 8
+ fb.format->cpp[0]
|
- fb.bits_per_pixel
+ fb.format->cpp[0] * 8
|
- fb.format->cpp[0] * 8 != 8
+ fb.format->cpp[0] != 1
)

@@
struct drm_framebuffer *fb;
expression E;
@@
(
- E * fb->bits_per_pixel / 8
+ E * fb->format->cpp[0]
|
- fb->bits_per_pixel / 8
+ fb->format->cpp[0]
|
- E * fb->bits_per_pixel >> 3
+ E * fb->format->cpp[0]
|
- fb->bits_per_pixel >> 3
+ fb->format->cpp[0]
|
- (fb->bits_per_pixel + 7) / 8
+ fb->format->cpp[0]
|
- fb->bits_per_pixel
+ fb->format->cpp[0] * 8
|
- fb->format->cpp[0] * 8 != 8
+ fb->format->cpp[0] != 1
)

@@
@@
- (8 * 8)
+ 8 * 8

@@
struct drm_framebuffer fb;
@@
- (fb.format->cpp[0])
+ fb.format->cpp[0]

@@
struct drm_framebuffer *fb;
@@
- (fb->format->cpp[0])
+ fb->format->cpp[0]

@@
@@
 struct drm_framebuffer {
 ...
-int bits_per_pixel;
 ...
 };

v2: Clean up the 'cpp*8 != 8' and '(8 * 8)' cases (Laurent)

Signed-off-by: Ville Syrjälä 
Reviewed-by: Laurent Pinchart 
Reviewed-by: Alex Deucher  (v1)
---
 drivers/gpu/drm/amd/amdgpu/dce_v10_0.c|  2 +-
 drivers/gpu/drm/amd/amdgpu/dce_v11_0.c|  2 +-
 drivers/gpu/drm/amd/amdgpu/dce_v6_0.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c |  2 +-
 drivers/gpu/drm/armada/armada_crtc.c  |  4 ++--
 drivers/gpu/drm/armada/armada_fbdev.c |  2 +-
 drivers/gpu/drm/ast/ast_fb.c  |  2 +-
 drivers/gpu/drm/ast/ast_mode.c|  9 +
 drivers/gpu/drm/cirrus/cirrus_fbdev.c |  2 +-
 drivers/gpu/drm/cirrus/cirrus_mode.c  |  2 +-
 drivers/gpu/drm/drm_fb_helper.c   |  8 
 drivers/gpu/drm/drm_framebuffer.c |  2 +-
 drivers/gpu/drm/drm_modeset_helper.c  |  3 ---
 drivers/gpu/drm/exynos/exynos5433_drm_decon.c |  4 ++--
 drivers/gpu/drm/exynos/exynos7_drm_decon.c|  6 +++---
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c |  4 ++--
 drivers/gpu/drm/exynos/exynos_drm_fimd.c  |  2 +-
 drivers/gpu/drm/exynos/exynos_mixer.c |  4 ++--
 drivers/gpu/drm/gma500/framebuffer.c  |  2 +-
 drivers/gpu/drm/gma500/gma_display.c  |  4 ++--
 drivers/gpu/drm/gma500/mdfld_intel_display.c  |  6 +++---
 drivers/gpu/drm/gma500/oaktrail_crtc.c|  4 ++--
 drivers/gpu/drm/i915/i915_debugfs.c   |  4 ++--
 drivers/gpu/drm/i915/intel_display.c  | 11 ---
 drivers/gpu/drm/i915/intel_fbdev.c|  6 +++---
 drivers/gpu/drm/mgag200/mgag200_fb.c  |  2 +-
 drivers/gpu/drm/mgag200/mgag200_mode.c| 16 
 drivers/gpu/drm/nouveau/dispnv04/crtc.c   |  4 ++--
 drivers/gpu/drm/nouveau/nouveau_display.c |  2 +-
 drivers/gpu/drm/qxl/qxl_draw.c|  2 +-
 drivers/gpu/drm/radeon/atombios_crtc.c| 11 ++-
 drivers/gpu/drm/radeon/r100.c |  4 ++--
 drivers/gpu/drm/radeon/radeon_display.c   |  6 +++---
 drivers/gpu/drm/radeon/radeon_legacy_crtc.c   | 14 +++---
 drivers/gpu/drm/tegra/dc.c|  2 +-
 drivers/gpu/drm/tegra/drm.c   |  2 +-
 drivers/gpu/drm

[PATCH 31/37] drm: Nuke fb->depth

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Replace uses of fb->depth with fb->format->depth. Less duplicate
information is a good thing.

@@
struct drm_framebuffer *fb;
expression E1, E2;
@@
 drm_helper_mode_fill_fb_struct(...) {
...
-   fb->depth = E1;
...
 }

@@
struct vmw_framebuffer_surface *vfb;
expression E;
@@
- vfb->base.base.depth = E;

@@
struct vmw_framebuffer_dmabuf *vfb;
expression E;
@@
- vfb->base.base.depth = E;

@@
struct nouveau_framebuffer *fb;
@@
- fb->base.depth
+ fb->base.format->depth

@@
struct drm_framebuffer fb;
@@
- fb.depth
+ fb.format->depth

@@
struct drm_framebuffer *fb;
@@
- fb->depth
+ fb->format->depth

@@
struct drm_framebuffer fb;
@@
- (fb.format->depth)
+ fb.format->depth

@@
struct drm_framebuffer *fb;
@@
- (fb->format->depth)
+ fb->format->depth

@@
@@
 struct drm_framebuffer {
 ...
-unsigned int depth;
 ...
 };

Signed-off-by: Ville Syrjälä 
Reviewed-by: Laurent Pinchart 
Reviewed-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c|  4 ++--
 drivers/gpu/drm/armada/armada_fbdev.c |  3 ++-
 drivers/gpu/drm/ast/ast_fb.c  |  2 +-
 drivers/gpu/drm/bochs/bochs_fbdev.c   |  2 +-
 drivers/gpu/drm/cirrus/cirrus_fbdev.c |  4 ++--
 drivers/gpu/drm/drm_fb_cma_helper.c   |  2 +-
 drivers/gpu/drm/drm_fb_helper.c   |  2 +-
 drivers/gpu/drm/drm_framebuffer.c |  2 +-
 drivers/gpu/drm/drm_modeset_helper.c  |  2 --
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c |  2 +-
 drivers/gpu/drm/gma500/accel_2d.c |  2 +-
 drivers/gpu/drm/gma500/framebuffer.c  |  2 +-
 drivers/gpu/drm/gma500/gma_display.c  |  2 +-
 drivers/gpu/drm/gma500/mdfld_intel_display.c  |  2 +-
 drivers/gpu/drm/gma500/oaktrail_crtc.c|  2 +-
 drivers/gpu/drm/i915/i915_debugfs.c   |  4 ++--
 drivers/gpu/drm/i915/intel_fbdev.c|  2 +-
 drivers/gpu/drm/mgag200/mgag200_fb.c  |  2 +-
 drivers/gpu/drm/mgag200/mgag200_mode.c|  6 +++---
 drivers/gpu/drm/msm/msm_fbdev.c   |  2 +-
 drivers/gpu/drm/nouveau/dispnv04/crtc.c   | 12 ++--
 drivers/gpu/drm/nouveau/dispnv04/dfp.c|  2 +-
 drivers/gpu/drm/nouveau/nouveau_fbcon.c   |  3 ++-
 drivers/gpu/drm/omapdrm/omap_fbdev.c  |  2 +-
 drivers/gpu/drm/qxl/qxl_fb.c  |  5 +++--
 drivers/gpu/drm/radeon/radeon_fb.c|  4 ++--
 drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c |  5 +++--
 drivers/gpu/drm/tegra/drm.c   |  3 ++-
 drivers/gpu/drm/tegra/fb.c|  2 +-
 drivers/gpu/drm/udl/udl_fb.c  |  2 +-
 drivers/gpu/drm/virtio/virtgpu_fb.c   |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_fb.c|  7 ---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c   |  2 --
 drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c   |  5 +++--
 drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c  |  2 +-
 include/drm/drm_framebuffer.h |  6 --
 36 files changed, 56 insertions(+), 59 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
index f1c9e59a7c87..f24c91b699a9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
@@ -245,7 +245,7 @@ static int amdgpufb_create(struct drm_fb_helper *helper,

strcpy(info->fix.id, "amdgpudrmfb");

-   drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth);
+   drm_fb_helper_fill_fix(info, fb->pitches[0], fb->format->depth);

info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT;
info->fbops = _ops;
@@ -272,7 +272,7 @@ static int amdgpufb_create(struct drm_fb_helper *helper,
DRM_INFO("fb mappable at 0x%lX\n",  info->fix.smem_start);
DRM_INFO("vram apper at 0x%lX\n",  (unsigned long)adev->mc.aper_base);
DRM_INFO("size %lu\n", (unsigned long)amdgpu_bo_size(abo));
-   DRM_INFO("fb depth is %d\n", fb->depth);
+   DRM_INFO("fb depth is %d\n", fb->format->depth);
DRM_INFO("   pitch is %d\n", fb->pitches[0]);

vga_switcheroo_client_fb_set(adev->ddev->pdev, info);
diff --git a/drivers/gpu/drm/armada/armada_fbdev.c 
b/drivers/gpu/drm/armada/armada_fbdev.c
index c5dc06a55883..3a58fb600b05 100644
--- a/drivers/gpu/drm/armada/armada_fbdev.c
+++ b/drivers/gpu/drm/armada/armada_fbdev.c
@@ -89,7 +89,8 @@ static int armada_fb_create(struct drm_fb_helper *fbh,
info->screen_base = ptr;
fbh->fb = >fb;

-   drm_fb_helper_fill_fix(info, dfb->fb.pitches[0], dfb->fb.depth);
+   drm_fb_helper_fill_fix(info, dfb->fb.pitches[0],
+  dfb->fb.format->depth);
drm_fb_helper_fill_var(info, fbh, sizes->fb_width, sizes->fb

[PATCH 30/37] drm/i915: Use drm_framebuffer_plane_{width, height}() where possible

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Replace drm_format_plane_{width,height}() usage with
drm_framebuffer_plane_{width,height}() to avoid the lookup of the format
info.

Cc: intel-gfx at lists.freedesktop.org
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_display.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 8f63fd38deee..5d8db436c557 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2496,7 +2496,6 @@ intel_fill_fb_info(struct drm_i915_private *dev_priv,
struct intel_rotation_info *rot_info = _fb->rot_info;
u32 gtt_offset_rotated = 0;
unsigned int max_size = 0;
-   uint32_t format = fb->pixel_format;
int i, num_planes = fb->format->num_planes;
unsigned int tile_size = intel_tile_size(dev_priv);

@@ -2507,8 +2506,8 @@ intel_fill_fb_info(struct drm_i915_private *dev_priv,
int x, y;

cpp = fb->format->cpp[i];
-   width = drm_format_plane_width(fb->width, format, i);
-   height = drm_format_plane_height(fb->height, format, i);
+   width = drm_framebuffer_plane_width(fb->width, fb, i);
+   height = drm_framebuffer_plane_height(fb->height, fb, i);

intel_fb_offset_to_xy(, , fb, i);

-- 
2.7.4



[PATCH 29/37] drm: Add drm_framebuffer_plane_{width,height}()

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add variants of drm_format_plane_{width,height}() that take an entire fb
object instead of just the format. These should be more efficent as they
can just look up the format info from the fb->format pointer rather than
having to look it up (using a linear search based on the format).

Signed-off-by: Ville Syrjälä 
Reviewed-by: Alex Deucher 
---
 drivers/gpu/drm/drm_framebuffer.c | 44 +++
 include/drm/drm_framebuffer.h |  6 ++
 2 files changed, 50 insertions(+)

diff --git a/drivers/gpu/drm/drm_framebuffer.c 
b/drivers/gpu/drm/drm_framebuffer.c
index 892976d974e5..22071d7e3420 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -793,3 +793,47 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb)
drm_framebuffer_unreference(fb);
 }
 EXPORT_SYMBOL(drm_framebuffer_remove);
+
+/**
+ * drm_framebuffer_plane_width - width of the plane given the first plane
+ * @width: width of the first plane
+ * @fb: the framebuffer
+ * @plane: plane index
+ *
+ * Returns:
+ * The width of @plane, given that the width of the first plane is @width.
+ */
+int drm_framebuffer_plane_width(int width,
+   const struct drm_framebuffer *fb, int plane)
+{
+   if (plane >= fb->format->num_planes)
+   return 0;
+
+   if (plane == 0)
+   return width;
+
+   return width / fb->format->hsub;
+}
+EXPORT_SYMBOL(drm_framebuffer_plane_width);
+
+/**
+ * drm_framebuffer_plane_height - height of the plane given the first plane
+ * @height: height of the first plane
+ * @fb: the framebuffer
+ * @plane: plane index
+ *
+ * Returns:
+ * The height of @plane, given that the height of the first plane is @height.
+ */
+int drm_framebuffer_plane_height(int height,
+const struct drm_framebuffer *fb, int plane)
+{
+   if (plane >= fb->format->num_planes)
+   return 0;
+
+   if (plane == 0)
+   return height;
+
+   return height / fb->format->vsub;
+}
+EXPORT_SYMBOL(drm_framebuffer_plane_height);
diff --git a/include/drm/drm_framebuffer.h b/include/drm/drm_framebuffer.h
index 741b3a994d1f..cdcfb86b3f74 100644
--- a/include/drm/drm_framebuffer.h
+++ b/include/drm/drm_framebuffer.h
@@ -268,4 +268,10 @@ static inline uint32_t 
drm_framebuffer_read_refcount(struct drm_framebuffer *fb)
  struct drm_framebuffer, head);
\
 >head != (&(dev)->mode_config.fb_list);
\
 fb = list_next_entry(fb, head))
+
+int drm_framebuffer_plane_width(int width,
+   const struct drm_framebuffer *fb, int plane);
+int drm_framebuffer_plane_height(int height,
+const struct drm_framebuffer *fb, int plane);
+
 #endif
-- 
2.7.4



[PATCH 28/37] drm/i915: Store a pointer to the pixel format info for fbc

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Rather than store the pixel format and look up the format info as
needed,  let's just store a pointer to the format info directly
and speed up our lookups.

Cc: Paulo Zanoni 
Cc: intel-gfx at lists.freedesktop.org
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/i915_drv.h  |  4 ++--
 drivers/gpu/drm/i915/intel_fbc.c | 14 +++---
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index be67aeece749..692b79e056be 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1026,7 +1026,7 @@ struct intel_fbc {

struct {
u64 ilk_ggtt_offset;
-   uint32_t pixel_format;
+   const struct drm_format_info *format;
unsigned int stride;
int fence_reg;
unsigned int tiling_mode;
@@ -1042,7 +1042,7 @@ struct intel_fbc {

struct {
u64 ggtt_offset;
-   uint32_t pixel_format;
+   const struct drm_format_info *format;
unsigned int stride;
int fence_reg;
} fb;
diff --git a/drivers/gpu/drm/i915/intel_fbc.c b/drivers/gpu/drm/i915/intel_fbc.c
index 62f215b12eb5..659cebc3bfd2 100644
--- a/drivers/gpu/drm/i915/intel_fbc.c
+++ b/drivers/gpu/drm/i915/intel_fbc.c
@@ -188,7 +188,7 @@ static void g4x_fbc_activate(struct drm_i915_private 
*dev_priv)
u32 dpfc_ctl;

dpfc_ctl = DPFC_CTL_PLANE(params->crtc.plane) | DPFC_SR_EN;
-   if (drm_format_plane_cpp(params->fb.pixel_format, 0) == 2)
+   if (params->fb.format->cpp[0] == 2)
dpfc_ctl |= DPFC_CTL_LIMIT_2X;
else
dpfc_ctl |= DPFC_CTL_LIMIT_1X;
@@ -235,7 +235,7 @@ static void ilk_fbc_activate(struct drm_i915_private 
*dev_priv)
int threshold = dev_priv->fbc.threshold;

dpfc_ctl = DPFC_CTL_PLANE(params->crtc.plane);
-   if (drm_format_plane_cpp(params->fb.pixel_format, 0) == 2)
+   if (params->fb.format->cpp[0] == 2)
threshold++;

switch (threshold) {
@@ -303,7 +303,7 @@ static void gen7_fbc_activate(struct drm_i915_private 
*dev_priv)
if (IS_IVYBRIDGE(dev_priv))
dpfc_ctl |= IVB_DPFC_CTL_PLANE(params->crtc.plane);

-   if (drm_format_plane_cpp(params->fb.pixel_format, 0) == 2)
+   if (params->fb.format->cpp[0] == 2)
threshold++;

switch (threshold) {
@@ -581,7 +581,7 @@ static int intel_fbc_alloc_cfb(struct intel_crtc *crtc)
WARN_ON(drm_mm_node_allocated(>compressed_fb));

size = intel_fbc_calculate_cfb_size(dev_priv, >state_cache);
-   fb_cpp = drm_format_plane_cpp(fbc->state_cache.fb.pixel_format, 0);
+   fb_cpp = fbc->state_cache.fb.format->cpp[0];

ret = find_compression_threshold(dev_priv, >compressed_fb,
 size, fb_cpp);
@@ -764,7 +764,7 @@ static void intel_fbc_update_state_cache(struct intel_crtc 
*crtc,
 * platforms that need. */
if (IS_GEN(dev_priv, 5, 6))
cache->fb.ilk_ggtt_offset = i915_gem_object_ggtt_offset(obj, 
NULL);
-   cache->fb.pixel_format = fb->pixel_format;
+   cache->fb.format = fb->format;
cache->fb.stride = fb->pitches[0];
cache->fb.fence_reg = get_fence_id(fb);
cache->fb.tiling_mode = i915_gem_object_get_tiling(obj);
@@ -823,7 +823,7 @@ static bool intel_fbc_can_activate(struct intel_crtc *crtc)
return false;
}

-   if (!pixel_format_is_valid(dev_priv, cache->fb.pixel_format)) {
+   if (!pixel_format_is_valid(dev_priv, cache->fb.format->format)) {
fbc->no_fbc_reason = "pixel format is invalid";
return false;
}
@@ -892,7 +892,7 @@ static void intel_fbc_get_reg_params(struct intel_crtc 
*crtc,
params->crtc.plane = crtc->plane;
params->crtc.fence_y_offset = get_crtc_fence_y_offset(crtc);

-   params->fb.pixel_format = cache->fb.pixel_format;
+   params->fb.format = cache->fb.format;
params->fb.stride = cache->fb.stride;
params->fb.fence_reg = cache->fb.fence_reg;

-- 
2.7.4



[PATCH 27/37] drm/nouveau: Use fb->format rather than drm_format_info()

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Let's use the pointer to the format information cached under
drm_framebuffer rather than look it up manually.

Cc: Ben Skeggs 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/nouveau/nv50_display.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nv50_display.c 
b/drivers/gpu/drm/nouveau/nv50_display.c
index a9855a4ec532..d3bd428023ea 100644
--- a/drivers/gpu/drm/nouveau/nv50_display.c
+++ b/drivers/gpu/drm/nouveau/nv50_display.c
@@ -1418,12 +1418,10 @@ static int
 nv50_base_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
  struct nv50_head_atom *asyh)
 {
-   const u32 format = asyw->state.fb->pixel_format;
-   const struct drm_format_info *info;
+   const struct drm_framebuffer *fb = asyw->state.fb;
int ret;

-   info = drm_format_info(format);
-   if (!info || !info->depth)
+   if (!fb->format->depth)
return -EINVAL;

ret = drm_plane_helper_check_state(>state, >clip,
@@ -1433,14 +1431,14 @@ nv50_base_acquire(struct nv50_wndw *wndw, struct 
nv50_wndw_atom *asyw,
if (ret)
return ret;

-   asyh->base.depth = info->depth;
-   asyh->base.cpp = info->cpp[0];
+   asyh->base.depth = fb->format->depth;
+   asyh->base.cpp = fb->format->cpp[0];
asyh->base.x = asyw->state.src.x1 >> 16;
asyh->base.y = asyw->state.src.y1 >> 16;
asyh->base.w = asyw->state.fb->width;
asyh->base.h = asyw->state.fb->height;

-   switch (format) {
+   switch (fb->pixel_format) {
case DRM_FORMAT_C8 : asyw->image.format = 0x1e; break;
case DRM_FORMAT_RGB565 : asyw->image.format = 0xe8; break;
case DRM_FORMAT_XRGB1555   :
-- 
2.7.4



[PATCH 26/37] drm/fb_cma_helper: Replace drm_format_info() with fb->format

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Get the format information via the neat fb->format pointer rather than
doing a linear search over all the format info structures.

Signed-off-by: Ville Syrjälä 
Reviewed-by: Laurent Pinchart 
---
 drivers/gpu/drm/drm_fb_cma_helper.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_fb_cma_helper.c 
b/drivers/gpu/drm/drm_fb_cma_helper.c
index 570f5c6063f3..0dc3f5bcbf48 100644
--- a/drivers/gpu/drm/drm_fb_cma_helper.c
+++ b/drivers/gpu/drm/drm_fb_cma_helper.c
@@ -304,15 +304,12 @@ EXPORT_SYMBOL_GPL(drm_fb_cma_prepare_fb);
 static void drm_fb_cma_describe(struct drm_framebuffer *fb, struct seq_file *m)
 {
struct drm_fb_cma *fb_cma = to_fb_cma(fb);
-   const struct drm_format_info *info;
int i;

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

-   info = drm_format_info(fb->pixel_format);
-
-   for (i = 0; i < info->num_planes; i++) {
+   for (i = 0; i < fb->fomat->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);
-- 
2.7.4



[PATCH 25/37] drm: Replace drm_format_plane_cpp() with fb->format->cpp[]

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Replace drm_format_plane_cpp(fb->pixel_format) with just
fb->format->cpp[]. Avoids the expensive format info lookup.

@@
struct drm_framebuffer *a;
struct drm_framebuffer b;
expression E;
@@
(
- drm_format_plane_cpp(a->pixel_format, E)
+ a->format->cpp[E]
|
- drm_format_plane_cpp(b.pixel_format, E)
+ b.format->cpp[E]
)

@@
struct drm_plane_state *a;
struct drm_plane_state b;
expression E;
@@
(
- drm_format_plane_cpp(a->fb->pixel_format, E)
+ a->fb->format->cpp[E]
|
- drm_format_plane_cpp(b.fb->pixel_format, E)
+ b.fb->format->cpp[E]
)

@@
struct drm_framebuffer *a;
identifier T;
expression E;
@@
  T = a->pixel_format
<+...
- drm_format_plane_cpp(T, E)
+ a->format->cpp[E]
...+>

@@
struct drm_framebuffer b;
identifier T;
expression E;
@@
  T = b.pixel_format
<+...
- drm_format_plane_cpp(T, E)
+ b.format->cpp[E]
...+>

Cc: Laurent Pinchart 
Suggested-by: Laurent Pinchart 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/arm/hdlcd_crtc.c|  2 +-
 drivers/gpu/drm/armada/armada_overlay.c |  2 +-
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c |  2 +-
 drivers/gpu/drm/i915/intel_display.c| 16 +-
 drivers/gpu/drm/i915/intel_pm.c | 42 -
 drivers/gpu/drm/i915/intel_sprite.c |  2 +-
 drivers/gpu/drm/imx/ipuv3-plane.c   |  6 ++--
 drivers/gpu/drm/mediatek/mtk_drm_plane.c|  2 +-
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c |  4 +--
 drivers/gpu/drm/sti/sti_gdp.c   |  2 +-
 drivers/gpu/drm/sun4i/sun4i_backend.c   |  2 +-
 drivers/gpu/drm/tilcdc/tilcdc_crtc.c|  2 +-
 drivers/gpu/drm/tilcdc/tilcdc_plane.c   |  2 +-
 drivers/gpu/drm/vc4/vc4_plane.c |  2 +-
 drivers/gpu/drm/zte/zx_plane.c  |  2 +-
 15 files changed, 45 insertions(+), 45 deletions(-)

diff --git a/drivers/gpu/drm/arm/hdlcd_crtc.c b/drivers/gpu/drm/arm/hdlcd_crtc.c
index 8a0fee03aa39..5c19c25729cb 100644
--- a/drivers/gpu/drm/arm/hdlcd_crtc.c
+++ b/drivers/gpu/drm/arm/hdlcd_crtc.c
@@ -239,7 +239,7 @@ static void hdlcd_plane_atomic_update(struct drm_plane 
*plane,
scanout_start = gem->paddr + fb->offsets[0] +
plane->state->crtc_y * fb->pitches[0] +
plane->state->crtc_x *
-   drm_format_plane_cpp(fb->pixel_format, 0);
+   fb->format->cpp[0];

hdlcd = plane->dev->dev_private;
hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_LENGTH, fb->pitches[0]);
diff --git a/drivers/gpu/drm/armada/armada_overlay.c 
b/drivers/gpu/drm/armada/armada_overlay.c
index 903fff422e92..e2ad408c2f24 100644
--- a/drivers/gpu/drm/armada/armada_overlay.c
+++ b/drivers/gpu/drm/armada/armada_overlay.c
@@ -197,7 +197,7 @@ armada_ovl_plane_update(struct drm_plane *plane, struct 
drm_crtc *crtc,
for (i = 0; i < num_planes; i++)
addr[i] = obj->dev_addr + fb->offsets[i] +
  src_y * fb->pitches[i] +
- src_x * drm_format_plane_cpp(pixel_format, i);
+ src_x * fb->format->cpp[i];
for (; i < ARRAY_SIZE(addr); i++)
addr[i] = 0;

diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c 
b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
index f97ae75f9e63..3e00512ef187 100644
--- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
+++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
@@ -672,7 +672,7 @@ static int atmel_hlcdc_plane_atomic_check(struct drm_plane 
*p,
int xdiv = i ? hsub : 1;
int ydiv = i ? vsub : 1;

-   state->bpp[i] = drm_format_plane_cpp(fb->pixel_format, i);
+   state->bpp[i] = fb->format->cpp[i];
if (!state->bpp[i])
return -EINVAL;

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index c19d8bdf46d8..8f63fd38deee 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2275,7 +2275,7 @@ u32 intel_fb_xy_to_linear(int x, int y,
  int plane)
 {
const struct drm_framebuffer *fb = state->base.fb;
-   unsigned int cpp = drm_format_plane_cpp(fb->pixel_format, plane);
+   unsigned int cpp = fb->format->cpp[plane];
unsigned int pitch = fb->pitches[plane];

return y * pitch + x * cpp;
@@ -2344,7 +2344,7 @@ static u32 intel_adjust_tile_offset(int *x, int *y,
 {
const struct drm_i915_private *dev_priv = 
to_i915(state->base.plane->dev);
const struct drm_framebuffer *fb = state->base.fb;
-   unsigned int cpp = drm_format_plane_cpp(fb->pixel_format, plane);
+   unsigned int

[PATCH 24/37] drm/i915: Eliminate the ugly 'fb?:' constructs from the ilk/skl wm code

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Don't access plane_state->fb until we know the plane to be visible.
It it's visible, it will have an fb, and thus we don't have to
consider the NULL fb case. Makes the code look nicer.

Cc: intel-gfx at lists.freedesktop.org
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_pm.c | 23 +++
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index bbb1eaf1e6db..8ba7413872dd 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -1781,13 +1781,14 @@ static uint32_t ilk_compute_pri_wm(const struct 
intel_crtc_state *cstate,
   uint32_t mem_value,
   bool is_lp)
 {
-   int cpp = pstate->base.fb ?
-   drm_format_plane_cpp(pstate->base.fb->pixel_format, 0) : 0;
uint32_t method1, method2;
+   int cpp;

if (!cstate->base.active || !pstate->base.visible)
return 0;

+   cpp = drm_format_plane_cpp(pstate->base.fb->pixel_format, 0);
+
method1 = ilk_wm_method1(ilk_pipe_pixel_rate(cstate), cpp, mem_value);

if (!is_lp)
@@ -1809,13 +1810,14 @@ static uint32_t ilk_compute_spr_wm(const struct 
intel_crtc_state *cstate,
   const struct intel_plane_state *pstate,
   uint32_t mem_value)
 {
-   int cpp = pstate->base.fb ?
-   drm_format_plane_cpp(pstate->base.fb->pixel_format, 0) : 0;
uint32_t method1, method2;
+   int cpp;

if (!cstate->base.active || !pstate->base.visible)
return 0;

+   cpp = drm_format_plane_cpp(pstate->base.fb->pixel_format, 0);
+
method1 = ilk_wm_method1(ilk_pipe_pixel_rate(cstate), cpp, mem_value);
method2 = ilk_wm_method2(ilk_pipe_pixel_rate(cstate),
 cstate->base.adjusted_mode.crtc_htotal,
@@ -1853,12 +1855,13 @@ static uint32_t ilk_compute_fbc_wm(const struct 
intel_crtc_state *cstate,
   const struct intel_plane_state *pstate,
   uint32_t pri_val)
 {
-   int cpp = pstate->base.fb ?
-   drm_format_plane_cpp(pstate->base.fb->pixel_format, 0) : 0;
+   int cpp;

if (!cstate->base.active || !pstate->base.visible)
return 0;

+   cpp = drm_format_plane_cpp(pstate->base.fb->pixel_format, 0);
+
return ilk_wm_fbc(pri_val, drm_rect_width(>base.dst), cpp);
 }

@@ -3229,13 +3232,17 @@ skl_plane_relative_data_rate(const struct 
intel_crtc_state *cstate,
 int y)
 {
struct intel_plane_state *intel_pstate = to_intel_plane_state(pstate);
-   struct drm_framebuffer *fb = pstate->fb;
uint32_t down_scale_amount, data_rate;
uint32_t width = 0, height = 0;
-   unsigned format = fb ? fb->pixel_format : DRM_FORMAT_XRGB;
+   struct drm_framebuffer *fb;
+   u32 format;

if (!intel_pstate->base.visible)
return 0;
+
+   fb = pstate->fb;
+   format = fb->pixel_format;
+
if (pstate->plane->type == DRM_PLANE_TYPE_CURSOR)
return 0;
if (y && format != DRM_FORMAT_NV12)
-- 
2.7.4



[PATCH 23/37] drm: Replace drm_format_num_planes() with fb->format->num_planes

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Replace drm_format_num_planes(fb->pixel_format) with just
fb->format->num_planes. Avoids the expensive format info lookup.

@@
struct drm_framebuffer *a;
struct drm_framebuffer b;
@@
(
- drm_format_num_planes(a->pixel_format)
+ a->format->num_planes
|
- drm_format_num_planes(b.pixel_format)
+ b.format->num_planes
)

@@
struct drm_plane_state *a;
struct drm_plane_state b;
@@
(
- drm_format_num_planes(a->fb->pixel_format)
+ a->fb->format->num_planes
|
- drm_format_num_planes(b.fb->pixel_format)
+ b.fb->format->num_planes
)

@@
struct drm_framebuffer *a;
identifier T;
@@
  T = a->pixel_format
<+...
- drm_format_num_planes(T)
+ a->format->num_planes
...+>

@@
struct drm_framebuffer b;
identifier T;
@@
  T = b.pixel_format
<+...
- drm_format_num_planes(T)
+ b.format->num_planes
...+>

Cc: Laurent Pinchart 
Suggested-by: Laurent Pinchart 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/arm/malidp_planes.c | 2 +-
 drivers/gpu/drm/armada/armada_overlay.c | 2 +-
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_layer.c | 2 +-
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c | 2 +-
 drivers/gpu/drm/drm_atomic.c| 2 +-
 drivers/gpu/drm/i915/intel_display.c| 2 +-
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c   | 2 +-
 drivers/gpu/drm/msm/msm_fb.c| 8 
 drivers/gpu/drm/omapdrm/omap_fb.c   | 8 
 drivers/gpu/drm/tegra/dc.c  | 4 ++--
 drivers/gpu/drm/tegra/fb.c  | 2 +-
 drivers/gpu/drm/vc4/vc4_plane.c | 2 +-
 12 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/arm/malidp_planes.c 
b/drivers/gpu/drm/arm/malidp_planes.c
index ee7f7663a307..533ee2fa64be 100644
--- a/drivers/gpu/drm/arm/malidp_planes.c
+++ b/drivers/gpu/drm/arm/malidp_planes.c
@@ -116,7 +116,7 @@ static int malidp_de_plane_check(struct drm_plane *plane,
if (ms->format == MALIDP_INVALID_FORMAT_ID)
return -EINVAL;

-   ms->n_planes = drm_format_num_planes(fb->pixel_format);
+   ms->n_planes = fb->format->num_planes;
for (i = 0; i < ms->n_planes; i++) {
if (!malidp_hw_pitch_valid(mp->hwdev, fb->pitches[i])) {
DRM_DEBUG_KMS("Invalid pitch %u for plane %d\n",
diff --git a/drivers/gpu/drm/armada/armada_overlay.c 
b/drivers/gpu/drm/armada/armada_overlay.c
index 152b4e716269..903fff422e92 100644
--- a/drivers/gpu/drm/armada/armada_overlay.c
+++ b/drivers/gpu/drm/armada/armada_overlay.c
@@ -184,7 +184,7 @@ armada_ovl_plane_update(struct drm_plane *plane, struct 
drm_crtc *crtc,

pixel_format = fb->pixel_format;
hsub = drm_format_horz_chroma_subsampling(pixel_format);
-   num_planes = drm_format_num_planes(pixel_format);
+   num_planes = fb->format->num_planes;

/*
 * Annoyingly, shifting a YUYV-format image by one pixel
diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_layer.c 
b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_layer.c
index 377e43cea9dd..63dfdbf34f80 100644
--- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_layer.c
+++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_layer.c
@@ -446,7 +446,7 @@ void atmel_hlcdc_layer_update_set_fb(struct 
atmel_hlcdc_layer *layer,
return;

if (fb)
-   nplanes = drm_format_num_planes(fb->pixel_format);
+   nplanes = fb->format->num_planes;

if (nplanes > layer->max_planes)
return;
diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c 
b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
index 246ed1e33d8a..f97ae75f9e63 100644
--- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
+++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
@@ -621,7 +621,7 @@ static int atmel_hlcdc_plane_atomic_check(struct drm_plane 
*p,
state->src_w >>= 16;
state->src_h >>= 16;

-   state->nplanes = drm_format_num_planes(fb->pixel_format);
+   state->nplanes = fb->format->num_planes;
if (state->nplanes > ATMEL_HLCDC_MAX_PLANES)
return -EINVAL;

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 85466cc67819..cb6ab0106b0b 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -960,7 +960,7 @@ static void drm_atomic_plane_print_state(struct drm_printer 
*p,
drm_printf(p, "\tfb=%u\n", state->fb ? state->fb->base.id : 0);
if (state->fb) {
struct drm_framebuffer *fb = state->fb;
-   int i, n = drm_format_num_planes(fb->pixel_format);
+   int i, n = fb->format->num_planes;
struct drm_format_name_buf format_

[PATCH 22/37] drm: Reject fbs w/o format info in drm_framebuffer_init()

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Any framebuffer that doesn't have proper format information when
drm_framebuffer_init() is called is a bug. Let's warn and return
an error to avoid oopsing the kernel later due to dereferencing the
NULL fb->format pointer.

Cc: Laurent Pinchart 
Suggested-by: Laurent Pinchart 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_framebuffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_framebuffer.c 
b/drivers/gpu/drm/drm_framebuffer.c
index f397565d3c20..892976d974e5 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -631,7 +631,7 @@ int drm_framebuffer_init(struct drm_device *dev, struct 
drm_framebuffer *fb,
 {
int ret;

-   if (WARN_ON_ONCE(fb->dev != dev))
+   if (WARN_ON_ONCE(fb->dev != dev || !fb->format))
return -EINVAL;

INIT_LIST_HEAD(>filp_head);
-- 
2.7.4



[PATCH 21/37] drm/i915: Populate fb->format early for inherited fbs

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Make sure the framebuffer format info is available as early as possible
for fbs we inherit from the BIOS. This will allow us to use the fb as
if it was fully formed before we register it.

Cc: intel-gfx at lists.freedesktop.org
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_display.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 74a638c8de61..c45da6766fff 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -8717,6 +8717,7 @@ i9xx_get_initial_plane_config(struct intel_crtc *crtc,
fourcc = i9xx_format_to_fourcc(pixel_format);
fb->pixel_format = fourcc;
fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8;
+   fb->format = drm_format_info(fourcc);

if (INTEL_GEN(dev_priv) >= 4) {
if (plane_config->tiling)
@@ -9748,6 +9749,7 @@ skylake_get_initial_plane_config(struct intel_crtc *crtc,
  val & PLANE_CTL_ALPHA_MASK);
fb->pixel_format = fourcc;
fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8;
+   fb->format = drm_format_info(fourcc);

tiling = val & PLANE_CTL_TILED_MASK;
switch (tiling) {
@@ -9863,6 +9865,7 @@ ironlake_get_initial_plane_config(struct intel_crtc *crtc,
fourcc = i9xx_format_to_fourcc(pixel_format);
fb->pixel_format = fourcc;
fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8;
+   fb->format = drm_format_info(fourcc);

base = I915_READ(DSPSURF(pipe)) & 0xf000;
if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
-- 
2.7.4



[PATCH 20/37] drm/vmwgfx: Populate fb->format correctly

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Populate the fb->format to point at the correct format information
structure.

Cc: linux-graphics-maintainer at vmware.com
Cc: Sinclair Yeh 
Cc: Thomas Hellstrom 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index 5788913ca8f9..77f936e3056e 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -589,6 +589,7 @@ static int vmw_kms_new_framebuffer_surface(struct 
vmw_private *dev_priv,

vfbs->base.base.dev = dev;
/* XXX get the first 4 from the surface info */
+   vfbs->base.base.format = drm_format_info(pixel_format);
vfbs->base.base.pixel_format = pixel_format;
vfbs->base.base.bits_per_pixel = mode_cmd->bpp;
vfbs->base.base.pitches[0] = mode_cmd->pitch;
@@ -897,6 +898,7 @@ static int vmw_kms_new_framebuffer_dmabuf(struct 
vmw_private *dev_priv,
}

vfbd->base.base.dev = dev;
+   vfbd->base.base.format = drm_format_info(pixel_format);
vfbd->base.base.pixel_format = pixel_format;
vfbd->base.base.bits_per_pixel = mode_cmd->bpp;
vfbd->base.base.pitches[0] = mode_cmd->pitch;
-- 
2.7.4



[PATCH v2 19/37] drm: Store a pointer to drm_format_info under drm_framebuffer

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

To avoid having to look up the format information struct every time,
let's just store a pointer to it under drm_framebuffer.

v2: Don't populate the fb->format pointer in drm_framebuffer_init().
instead we'll treat a NULL format as an error later

Cc: Laurent Pinchart 
Signed-off-by: Ville Syrjälä 
Reviewed-by: Alex Deucher  (v1)
---
 drivers/gpu/drm/drm_modeset_helper.c | 1 +
 include/drm/drm_framebuffer.h| 4 
 2 files changed, 5 insertions(+)

diff --git a/drivers/gpu/drm/drm_modeset_helper.c 
b/drivers/gpu/drm/drm_modeset_helper.c
index 57a319e3f780..1aa5e3bcc8a1 100644
--- a/drivers/gpu/drm/drm_modeset_helper.c
+++ b/drivers/gpu/drm/drm_modeset_helper.c
@@ -91,6 +91,7 @@ void drm_helper_mode_fill_fb_struct(struct drm_device *dev,
}

fb->dev = dev;
+   fb->format = info;
fb->width = mode_cmd->width;
fb->height = mode_cmd->height;
for (i = 0; i < 4; i++) {
diff --git a/include/drm/drm_framebuffer.h b/include/drm/drm_framebuffer.h
index b3141a0e609b..741b3a994d1f 100644
--- a/include/drm/drm_framebuffer.h
+++ b/include/drm/drm_framebuffer.h
@@ -122,6 +122,10 @@ struct drm_framebuffer {
 */
struct drm_mode_object base;
/**
+* @format: framebuffer format information
+*/
+   const struct drm_format_info *format;
+   /**
 * @funcs: framebuffer vfunc table
 */
const struct drm_framebuffer_funcs *funcs;
-- 
2.7.4



[PATCH v2 18/37] drm: Populate fb->dev from drm_helper_mode_fill_fb_struct()

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Populating fb->dev before drm_framebuffer_init() allows us to use
fb->dev already while validating the framebuffer. Let's have
drm_helper_mode_fill_fb_struct() do that for us.

Also make drm_framebuffer_init() warn us if a different device
pointer is passed to it than was passed to
drm_helper_mode_fill_fb_struct().

v2: Reject fbs with invalid fb->dev (Laurent)

Cc: Laurent Pinchart 
Signed-off-by: Ville Syrjälä 
Reviewed-by: Laurent Pinchart 
Reviewed-by: Alex Deucher  (v1)
---
 drivers/gpu/drm/drm_framebuffer.c| 5 -
 drivers/gpu/drm/drm_modeset_helper.c | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_framebuffer.c 
b/drivers/gpu/drm/drm_framebuffer.c
index cbf0c893f426..f397565d3c20 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -631,8 +631,11 @@ int drm_framebuffer_init(struct drm_device *dev, struct 
drm_framebuffer *fb,
 {
int ret;

+   if (WARN_ON_ONCE(fb->dev != dev))
+   return -EINVAL;
+
INIT_LIST_HEAD(>filp_head);
-   fb->dev = dev;
+
fb->funcs = funcs;

ret = drm_mode_object_get_reg(dev, >base, DRM_MODE_OBJECT_FB,
diff --git a/drivers/gpu/drm/drm_modeset_helper.c 
b/drivers/gpu/drm/drm_modeset_helper.c
index 285ffcba0fe8..57a319e3f780 100644
--- a/drivers/gpu/drm/drm_modeset_helper.c
+++ b/drivers/gpu/drm/drm_modeset_helper.c
@@ -90,6 +90,7 @@ void drm_helper_mode_fill_fb_struct(struct drm_device *dev,
fb->bits_per_pixel = info->cpp[0] * 8;
}

+   fb->dev = dev;
fb->width = mode_cmd->width;
fb->height = mode_cmd->height;
for (i = 0; i < 4; i++) {
-- 
2.7.4



[PATCH 17/37] drm/i915: Set fb->dev early on for inherited fbs

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

We want the fbs inherited from the BIOS to be more or less fully working
prior to actually registering them. This will allow us to just pass the
fb to various helper function instead of having to pass all the
different parameters separately.

Cc: intel-gfx at lists.freedesktop.org
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_display.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 12af936a402d..74a638c8de61 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -8704,6 +8704,8 @@ i9xx_get_initial_plane_config(struct intel_crtc *crtc,

fb = _fb->base;

+   fb->dev = dev;
+
if (INTEL_GEN(dev_priv) >= 4) {
if (val & DISPPLANE_TILED) {
plane_config->tiling = I915_TILING_X;
@@ -9734,6 +9736,8 @@ skylake_get_initial_plane_config(struct intel_crtc *crtc,

fb = _fb->base;

+   fb->dev = dev;
+
val = I915_READ(PLANE_CTL(pipe, 0));
if (!(val & PLANE_CTL_ENABLE))
goto error;
@@ -9846,6 +9850,8 @@ ironlake_get_initial_plane_config(struct intel_crtc *crtc,

fb = _fb->base;

+   fb->dev = dev;
+
if (INTEL_GEN(dev_priv) >= 4) {
if (val & DISPPLANE_TILED) {
plane_config->tiling = I915_TILING_X;
-- 
2.7.4



[PATCH 16/37] drm/virtio: Call drm_helper_mode_fill_fb_struct() before drm_framebuffer_init()

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

We want framebuffers to be mostly useable already before
drm_framebuffer_init() get called, and so we will start demanding that
all the interesting format/size/etc. information be filled in before
drm_framebuffer_init(). drm_helper_mode_fill_fb_struct() will do that
for us, so let's make sure it gets called before drm_framebuffer_init().

Cc: Dave Airlie 
Cc: Gerd Hoffmann 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/virtio/virtgpu_display.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_display.c 
b/drivers/gpu/drm/virtio/virtgpu_display.c
index 8b80fdd0e0a8..fad5a1cc5903 100644
--- a/drivers/gpu/drm/virtio/virtgpu_display.c
+++ b/drivers/gpu/drm/virtio/virtgpu_display.c
@@ -88,12 +88,13 @@ virtio_gpu_framebuffer_init(struct drm_device *dev,

bo = gem_to_virtio_gpu_obj(obj);

+   drm_helper_mode_fill_fb_struct(dev, >base, mode_cmd);
+
ret = drm_framebuffer_init(dev, >base, _gpu_fb_funcs);
if (ret) {
vgfb->obj = NULL;
return ret;
}
-   drm_helper_mode_fill_fb_struct(dev, >base, mode_cmd);

spin_lock_init(>dirty_lock);
vgfb->x1 = vgfb->y1 = INT_MAX;
-- 
2.7.4



[PATCH 15/37] drm/qxl: Call drm_helper_mode_fill_fb_struct() before drm_framebuffer_init()

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

We want framebuffers to be mostly useable already before
drm_framebuffer_init() is called, and so we will start demanding that
all the interesting format/size/etc. information be filled in before
drm_framebuffer_init(). drm_helper_mode_fill_fb_struct() will do that
for us, so let's make sure it gets called before drm_framebuffer_init().

Cc: Dave Airlie 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/qxl/qxl_display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/qxl/qxl_display.c 
b/drivers/gpu/drm/qxl/qxl_display.c
index bcbad877ce4f..9e2c92b9d12e 100644
--- a/drivers/gpu/drm/qxl/qxl_display.c
+++ b/drivers/gpu/drm/qxl/qxl_display.c
@@ -579,12 +579,12 @@ qxl_framebuffer_init(struct drm_device *dev,
int ret;

qfb->obj = obj;
+   drm_helper_mode_fill_fb_struct(dev, >base, mode_cmd);
ret = drm_framebuffer_init(dev, >base, funcs);
if (ret) {
qfb->obj = NULL;
return ret;
}
-   drm_helper_mode_fill_fb_struct(dev, >base, mode_cmd);
return 0;
 }

-- 
2.7.4



[PATCH 14/37] drm/vmwgfx: Populate fb->pixel_format

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Stuff something semi-reasonable into fb->pixel_format. I had to guess
as to which formats we should pick. Did I guess correctly?

We can't quite use drm_mode_legacy_fb_format() due to the ARGB1555
vs. XRGB155 mess. However use of 'A' formats should imply per-pixel
alpha blending as far as KMS is concerned so I'm not at all sure we
want to have any 'A' formats exposed as opposed to just 'X' formats.
OTOH vmvgfx doesn't do planes, and so the core won't enforce that
these formats match any list of supported formats, so the choice
shouldn't be super important at this point.

Cc: linux-graphics-maintainer at vmware.com
Cc: Sinclair Yeh 
Cc: Thomas Hellstrom 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index 7d92ab56961b..5788913ca8f9 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -524,6 +524,7 @@ static int vmw_kms_new_framebuffer_surface(struct 
vmw_private *dev_priv,
struct drm_device *dev = dev_priv->dev;
struct vmw_framebuffer_surface *vfbs;
enum SVGA3dSurfaceFormat format;
+   u32 pixel_format;
int ret;

/* 3D is only supported on HWv8 and newer hosts */
@@ -548,17 +549,22 @@ static int vmw_kms_new_framebuffer_surface(struct 
vmw_private *dev_priv,
return -EINVAL;
}

+   /* FIXME 'A' format implies per-pixel alpha blending for KMS */
switch (mode_cmd->depth) {
case 32:
+   pixel_format = DRM_FORMAT_ARGB;
format = SVGA3D_A8R8G8B8;
break;
case 24:
+   pixel_format = DRM_FORMAT_XRGB;
format = SVGA3D_X8R8G8B8;
break;
case 16:
+   pixel_format = DRM_FORMAT_RGB565;
format = SVGA3D_R5G6B5;
break;
case 15:
+   pixel_format = DRM_FORMAT_ARGB1555;
format = SVGA3D_A1R5G5B5;
break;
default:
@@ -582,7 +588,8 @@ static int vmw_kms_new_framebuffer_surface(struct 
vmw_private *dev_priv,
}

vfbs->base.base.dev = dev;
-   /* XXX get the first 3 from the surface info */
+   /* XXX get the first 4 from the surface info */
+   vfbs->base.base.pixel_format = pixel_format;
vfbs->base.base.bits_per_pixel = mode_cmd->bpp;
vfbs->base.base.pitches[0] = mode_cmd->pitch;
vfbs->base.base.depth = mode_cmd->depth;
@@ -834,6 +841,7 @@ static int vmw_kms_new_framebuffer_dmabuf(struct 
vmw_private *dev_priv,
struct drm_device *dev = dev_priv->dev;
struct vmw_framebuffer_dmabuf *vfbd;
unsigned int requested_size;
+   u32 pixel_format;
int ret;

requested_size = mode_cmd->height * mode_cmd->pitch;
@@ -852,6 +860,12 @@ static int vmw_kms_new_framebuffer_dmabuf(struct 
vmw_private *dev_priv,
if (mode_cmd->bpp == 32)
break;

+   /* FIXME 'A' format implies per-pixel alpha blending 
for KMS */
+   if (mode_cmd->depth == 32)
+   pixel_format = DRM_FORMAT_ARGB;
+   else
+   pixel_format = DRM_FORMAT_XRGB;
+
DRM_ERROR("Invalid color depth/bbp: %d %d\n",
  mode_cmd->depth, mode_cmd->bpp);
return -EINVAL;
@@ -861,6 +875,12 @@ static int vmw_kms_new_framebuffer_dmabuf(struct 
vmw_private *dev_priv,
if (mode_cmd->bpp == 16)
break;

+   /* FIXME 'A' format implies per-pixel alpha blending 
for KMS */
+   if (mode_cmd->depth == 16)
+   pixel_format = DRM_FORMAT_RGB565;
+   else
+   pixel_format = DRM_FORMAT_ARGB1555;
+
DRM_ERROR("Invalid color depth/bbp: %d %d\n",
  mode_cmd->depth, mode_cmd->bpp);
return -EINVAL;
@@ -877,6 +897,7 @@ static int vmw_kms_new_framebuffer_dmabuf(struct 
vmw_private *dev_priv,
}

vfbd->base.base.dev = dev;
+   vfbd->base.base.pixel_format = pixel_format;
vfbd->base.base.bits_per_pixel = mode_cmd->bpp;
vfbd->base.base.pitches[0] = mode_cmd->pitch;
vfbd->base.base.depth = mode_cmd->depth;
-- 
2.7.4



[PATCH 13/37] drm: Pass 'dev' to drm_helper_mode_fill_fb_struct()

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Pass the drm_device to drm_helper_mode_fill_fb_struct() so that we can
populate fb->dev early. Will make it easier to use the fb before we
register it.

@@
identifier fb, mode_cmd;
@@
 void drm_helper_mode_fill_fb_struct(
+struct drm_device *dev,
 struct drm_framebuffer *fb,
 const struct drm_mode_fb_cmd2 *mode_cmd
 );

@@
identifier fb, mode_cmd;
@@
 void drm_helper_mode_fill_fb_struct(
+struct drm_device *dev,
 struct drm_framebuffer *fb,
 const struct drm_mode_fb_cmd2 *mode_cmd
 )
{ ... }

@@
function func;
identifier dev;
expression E1, E2;
@@
func(struct drm_device *dev, ...)
{
 ...
 drm_helper_mode_fill_fb_struct(
+   dev,
E1, E2);
 ...
}

@@
expression E1, E2;
@@
 drm_helper_mode_fill_fb_struct(
+   dev,
E1, E2);

Signed-off-by: Ville Syrjälä 
Reviewed-by: Laurent Pinchart 
Reviewed-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 2 +-
 drivers/gpu/drm/armada/armada_fb.c  | 2 +-
 drivers/gpu/drm/ast/ast_main.c  | 2 +-
 drivers/gpu/drm/bochs/bochs_mm.c| 2 +-
 drivers/gpu/drm/cirrus/cirrus_main.c| 2 +-
 drivers/gpu/drm/drm_fb_cma_helper.c | 2 +-
 drivers/gpu/drm/drm_modeset_helper.c| 3 ++-
 drivers/gpu/drm/exynos/exynos_drm_fb.c  | 2 +-
 drivers/gpu/drm/gma500/framebuffer.c| 2 +-
 drivers/gpu/drm/i915/intel_display.c| 2 +-
 drivers/gpu/drm/mediatek/mtk_drm_fb.c   | 2 +-
 drivers/gpu/drm/mgag200/mgag200_main.c  | 2 +-
 drivers/gpu/drm/msm/msm_fb.c| 2 +-
 drivers/gpu/drm/nouveau/nouveau_display.c   | 2 +-
 drivers/gpu/drm/omapdrm/omap_fb.c   | 2 +-
 drivers/gpu/drm/qxl/qxl_display.c   | 2 +-
 drivers/gpu/drm/radeon/radeon_display.c | 2 +-
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c  | 2 +-
 drivers/gpu/drm/tegra/fb.c  | 2 +-
 drivers/gpu/drm/udl/udl_fb.c| 2 +-
 drivers/gpu/drm/virtio/virtgpu_display.c| 2 +-
 include/drm/drm_modeset_helper.h| 3 ++-
 22 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
index 741144fcc7bc..d492cf84ddc1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
@@ -508,7 +508,7 @@ amdgpu_framebuffer_init(struct drm_device *dev,
 {
int ret;
rfb->obj = obj;
-   drm_helper_mode_fill_fb_struct(>base, mode_cmd);
+   drm_helper_mode_fill_fb_struct(dev, >base, mode_cmd);
ret = drm_framebuffer_init(dev, >base, _fb_funcs);
if (ret) {
rfb->obj = NULL;
diff --git a/drivers/gpu/drm/armada/armada_fb.c 
b/drivers/gpu/drm/armada/armada_fb.c
index f03c212b754d..2a7eb6817c36 100644
--- a/drivers/gpu/drm/armada/armada_fb.c
+++ b/drivers/gpu/drm/armada/armada_fb.c
@@ -81,7 +81,7 @@ struct armada_framebuffer *armada_framebuffer_create(struct 
drm_device *dev,
dfb->mod = config;
dfb->obj = obj;

-   drm_helper_mode_fill_fb_struct(>fb, mode);
+   drm_helper_mode_fill_fb_struct(dev, >fb, mode);

ret = drm_framebuffer_init(dev, >fb, _fb_funcs);
if (ret) {
diff --git a/drivers/gpu/drm/ast/ast_main.c b/drivers/gpu/drm/ast/ast_main.c
index 904beaa932d0..d85af0ff2653 100644
--- a/drivers/gpu/drm/ast/ast_main.c
+++ b/drivers/gpu/drm/ast/ast_main.c
@@ -313,7 +313,7 @@ int ast_framebuffer_init(struct drm_device *dev,
 {
int ret;

-   drm_helper_mode_fill_fb_struct(_fb->base, mode_cmd);
+   drm_helper_mode_fill_fb_struct(dev, _fb->base, mode_cmd);
ast_fb->obj = obj;
ret = drm_framebuffer_init(dev, _fb->base, _fb_funcs);
if (ret) {
diff --git a/drivers/gpu/drm/bochs/bochs_mm.c b/drivers/gpu/drm/bochs/bochs_mm.c
index 099a3c688c26..ceb1fecf02dd 100644
--- a/drivers/gpu/drm/bochs/bochs_mm.c
+++ b/drivers/gpu/drm/bochs/bochs_mm.c
@@ -484,7 +484,7 @@ int bochs_framebuffer_init(struct drm_device *dev,
 {
int ret;

-   drm_helper_mode_fill_fb_struct(>base, mode_cmd);
+   drm_helper_mode_fill_fb_struct(dev, >base, mode_cmd);
gfb->obj = obj;
ret = drm_framebuffer_init(dev, >base, _fb_funcs);
if (ret) {
diff --git a/drivers/gpu/drm/cirrus/cirrus_main.c 
b/drivers/gpu/drm/cirrus/cirrus_main.c
index 2c3c0d4072ce..52d901fa8687 100644
--- a/drivers/gpu/drm/cirrus/cirrus_main.c
+++ b/drivers/gpu/drm/cirrus/cirrus_main.c
@@ -34,7 +34,7 @@ int cirrus_framebuffer_init(struct drm_device *dev,
 {

[PATCH 12/37] drm/vmwgfx: Populate fb->dev before drm_framebuffer_init()

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

drm_framebuffer_init() will start to check that fb->dev is already
populated, so let's to that manually since vmwgfx isn't using
drm_helper_mode_fill_fb_struct().

Cc: linux-graphics-maintainer at vmware.com
Cc: Sinclair Yeh 
Cc: Thomas Hellstrom 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index e3f68cc9bb4b..7d92ab56961b 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -581,6 +581,7 @@ static int vmw_kms_new_framebuffer_surface(struct 
vmw_private *dev_priv,
goto out_err1;
}

+   vfbs->base.base.dev = dev;
/* XXX get the first 3 from the surface info */
vfbs->base.base.bits_per_pixel = mode_cmd->bpp;
vfbs->base.base.pitches[0] = mode_cmd->pitch;
@@ -875,6 +876,7 @@ static int vmw_kms_new_framebuffer_dmabuf(struct 
vmw_private *dev_priv,
goto out_err1;
}

+   vfbd->base.base.dev = dev;
vfbd->base.base.bits_per_pixel = mode_cmd->bpp;
vfbd->base.base.pitches[0] = mode_cmd->pitch;
vfbd->base.base.depth = mode_cmd->depth;
-- 
2.7.4



[PATCH 11/37] drm/nouveau: Add local 'fb' variables

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add a local 'fb' variable to a few places to get rid of the
'crtc->primary->fb' stuff. Looks neater and helps me with my poor
coccinelle skills later.

Cc: Ben Skeggs 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/nouveau/dispnv04/crtc.c | 5 +++--
 drivers/gpu/drm/nouveau/dispnv04/dfp.c  | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/dispnv04/crtc.c 
b/drivers/gpu/drm/nouveau/dispnv04/crtc.c
index 7c6c66f177df..8286b8ffe109 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/crtc.c
+++ b/drivers/gpu/drm/nouveau/dispnv04/crtc.c
@@ -460,6 +460,7 @@ nv_crtc_mode_set_regs(struct drm_crtc *crtc, struct 
drm_display_mode * mode)
struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
struct nv04_crtc_reg *regp = 
_display(dev)->mode_reg.crtc_reg[nv_crtc->index];
struct nv04_crtc_reg *savep = 
_display(dev)->saved_reg.crtc_reg[nv_crtc->index];
+   const struct drm_framebuffer *fb = crtc->primary->fb;
struct drm_encoder *encoder;
bool lvds_output = false, tmds_output = false, tv_output = false,
off_chip_digital = false;
@@ -569,7 +570,7 @@ nv_crtc_mode_set_regs(struct drm_crtc *crtc, struct 
drm_display_mode * mode)
regp->CRTC[NV_CIO_CRE_86] = 0x1;
}

-   regp->CRTC[NV_CIO_CRE_PIXEL_INDEX] = (crtc->primary->fb->depth + 1) / 8;
+   regp->CRTC[NV_CIO_CRE_PIXEL_INDEX] = (fb->depth + 1) / 8;
/* Enable slaved mode (called MODE_TV in nv4ref.h) */
if (lvds_output || tmds_output || tv_output)
regp->CRTC[NV_CIO_CRE_PIXEL_INDEX] |= (1 << 7);
@@ -583,7 +584,7 @@ nv_crtc_mode_set_regs(struct drm_crtc *crtc, struct 
drm_display_mode * mode)
regp->ramdac_gen_ctrl = NV_PRAMDAC_GENERAL_CONTROL_BPC_8BITS |
NV_PRAMDAC_GENERAL_CONTROL_VGA_STATE_SEL |
NV_PRAMDAC_GENERAL_CONTROL_PIXMIX_ON;
-   if (crtc->primary->fb->depth == 16)
+   if (fb->depth == 16)
regp->ramdac_gen_ctrl |= 
NV_PRAMDAC_GENERAL_CONTROL_ALT_MODE_SEL;
if (drm->device.info.chipset >= 0x11)
regp->ramdac_gen_ctrl |= NV_PRAMDAC_GENERAL_CONTROL_PIPE_LONG;
diff --git a/drivers/gpu/drm/nouveau/dispnv04/dfp.c 
b/drivers/gpu/drm/nouveau/dispnv04/dfp.c
index c2947ef7d4fc..945607b3cd41 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/dfp.c
+++ b/drivers/gpu/drm/nouveau/dispnv04/dfp.c
@@ -290,6 +290,7 @@ static void nv04_dfp_mode_set(struct drm_encoder *encoder,
struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
struct drm_display_mode *output_mode = _encoder->mode;
struct drm_connector *connector = _connector->base;
+   const struct drm_framebuffer *fb = encoder->crtc->primary->fb;
uint32_t mode_ratio, panel_ratio;

NV_DEBUG(drm, "Output mode on CRTC %d:\n", nv_crtc->index);
@@ -415,7 +416,7 @@ static void nv04_dfp_mode_set(struct drm_encoder *encoder,
/* Output property. */
if ((nv_connector->dithering_mode == DITHERING_MODE_ON) ||
(nv_connector->dithering_mode == DITHERING_MODE_AUTO &&
-encoder->crtc->primary->fb->depth > connector->display_info.bpc * 
3)) {
+fb->depth > connector->display_info.bpc * 3)) {
if (drm->device.info.chipset == 0x11)
regp->dither = savep->dither | 0x0001;
else {
-- 
2.7.4



[PATCH 10/37] drm/nouveau: Fix crtc->primary->fb vs. drm_fb fail

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

So it looks like the code is trying to pick between the passed in fb and
crtc->primary->fb based on that funky 'bool atomic'. But later it will
mix uses of both drm_fb (which was picked by the aforementioned logic)
and crtc->primary->fb. So looks like a bug to me. Let's make it use
drm_fb only.

Cc: Ben Skeggs 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/nouveau/dispnv04/crtc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/dispnv04/crtc.c 
b/drivers/gpu/drm/nouveau/dispnv04/crtc.c
index 59d1d1c5de5f..7c6c66f177df 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/crtc.c
+++ b/drivers/gpu/drm/nouveau/dispnv04/crtc.c
@@ -854,9 +854,9 @@ nv04_crtc_do_mode_set_base(struct drm_crtc *crtc,

/* Update the framebuffer format. */
regp->CRTC[NV_CIO_CRE_PIXEL_INDEX] &= ~3;
-   regp->CRTC[NV_CIO_CRE_PIXEL_INDEX] |= (crtc->primary->fb->depth + 1) / 
8;
+   regp->CRTC[NV_CIO_CRE_PIXEL_INDEX] |= (drm_fb->depth + 1) / 8;
regp->ramdac_gen_ctrl &= ~NV_PRAMDAC_GENERAL_CONTROL_ALT_MODE_SEL;
-   if (crtc->primary->fb->depth == 16)
+   if (drm_fb->depth == 16)
regp->ramdac_gen_ctrl |= 
NV_PRAMDAC_GENERAL_CONTROL_ALT_MODE_SEL;
crtc_wr_cio_state(crtc, regp, NV_CIO_CRE_PIXEL_INDEX);
NVWriteRAMDAC(dev, nv_crtc->index, NV_PRAMDAC_GENERAL_CONTROL,
-- 
2.7.4



[PATCH 09/37] drm/arm: Add local 'fb' variables

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add a local 'fb' variable to a few places to get rid of the
'crtc->primary->fb' stuff. Looks neater and helps me with my ppor
coccinelle skills later.

In some places the local variable was already there, just not used
consistently.

Cc: Liviu Dudau 
Cc: Brian Starkey 
Cc: Mali DP Maintainers 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/arm/hdlcd_crtc.c| 18 ++
 drivers/gpu/drm/arm/malidp_planes.c |  6 +++---
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/arm/hdlcd_crtc.c b/drivers/gpu/drm/arm/hdlcd_crtc.c
index bbaa55add2d2..8a0fee03aa39 100644
--- a/drivers/gpu/drm/arm/hdlcd_crtc.c
+++ b/drivers/gpu/drm/arm/hdlcd_crtc.c
@@ -60,11 +60,12 @@ static int hdlcd_set_pxl_fmt(struct drm_crtc *crtc)
 {
unsigned int btpp;
struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc);
+   const struct drm_framebuffer *fb = crtc->primary->state->fb;
uint32_t pixel_format;
struct simplefb_format *format = NULL;
int i;

-   pixel_format = crtc->primary->state->fb->pixel_format;
+   pixel_format = fb->pixel_format;

for (i = 0; i < ARRAY_SIZE(supported_formats); i++) {
if (supported_formats[i].fourcc == pixel_format)
@@ -221,27 +222,28 @@ static int hdlcd_plane_atomic_check(struct drm_plane 
*plane,
 static void hdlcd_plane_atomic_update(struct drm_plane *plane,
  struct drm_plane_state *state)
 {
+   struct drm_framebuffer *fb = plane->state->fb;
struct hdlcd_drm_private *hdlcd;
struct drm_gem_cma_object *gem;
u32 src_w, src_h, dest_w, dest_h;
dma_addr_t scanout_start;

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

src_w = plane->state->src_w >> 16;
src_h = plane->state->src_h >> 16;
dest_w = plane->state->crtc_w;
dest_h = plane->state->crtc_h;
-   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] +
+   gem = drm_fb_cma_get_gem_obj(fb, 0);
+   scanout_start = gem->paddr + fb->offsets[0] +
+   plane->state->crtc_y * fb->pitches[0] +
plane->state->crtc_x *
-   drm_format_plane_cpp(plane->state->fb->pixel_format, 0);
+   drm_format_plane_cpp(fb->pixel_format, 0);

hdlcd = plane->dev->dev_private;
-   hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_LENGTH, 
plane->state->fb->pitches[0]);
-   hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_PITCH, 
plane->state->fb->pitches[0]);
+   hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_LENGTH, fb->pitches[0]);
+   hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_PITCH, fb->pitches[0]);
hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_COUNT, dest_h - 1);
hdlcd_write(hdlcd, HDLCD_REG_FB_BASE, scanout_start);
 }
diff --git a/drivers/gpu/drm/arm/malidp_planes.c 
b/drivers/gpu/drm/arm/malidp_planes.c
index 63eec8f37cfc..ee7f7663a307 100644
--- a/drivers/gpu/drm/arm/malidp_planes.c
+++ b/drivers/gpu/drm/arm/malidp_planes.c
@@ -137,8 +137,8 @@ static int malidp_de_plane_check(struct drm_plane *plane,

/* packed RGB888 / BGR888 can't be rotated or flipped */
if (state->rotation != DRM_ROTATE_0 &&
-   (state->fb->pixel_format == DRM_FORMAT_RGB888 ||
-state->fb->pixel_format == DRM_FORMAT_BGR888))
+   (fb->pixel_format == DRM_FORMAT_RGB888 ||
+fb->pixel_format == DRM_FORMAT_BGR888))
return -EINVAL;

ms->rotmem_size = 0;
@@ -147,7 +147,7 @@ static int malidp_de_plane_check(struct drm_plane *plane,

val = mp->hwdev->rotmem_required(mp->hwdev, state->crtc_h,
 state->crtc_w,
-state->fb->pixel_format);
+fb->pixel_format);
if (val < 0)
return val;

-- 
2.7.4



[PATCH 08/37] drm/arcpgu: Add local 'fb' variables

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add a local 'fb' variable to a few places to get rid of the
'crtc->primary->fb' stuff. Looks neater and helps me with my ppor
coccinelle skills later.

Cc: Alexey Brodkin 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/arc/arcpgu_crtc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/arc/arcpgu_crtc.c 
b/drivers/gpu/drm/arc/arcpgu_crtc.c
index 7130b044b004..5c26c5f126a3 100644
--- a/drivers/gpu/drm/arc/arcpgu_crtc.c
+++ b/drivers/gpu/drm/arc/arcpgu_crtc.c
@@ -35,7 +35,8 @@ static struct simplefb_format supported_formats[] = {
 static void arc_pgu_set_pxl_fmt(struct drm_crtc *crtc)
 {
struct arcpgu_drm_private *arcpgu = crtc_to_arcpgu_priv(crtc);
-   uint32_t pixel_format = crtc->primary->state->fb->pixel_format;
+   const struct drm_framebuffer *fb = crtc->primary->state->fb;
+   uint32_t pixel_format = fb->pixel_format;
struct simplefb_format *format = NULL;
int i;

-- 
2.7.4



[PATCH 07/37] drm/cirrus: Add some local 'fb' variables

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add a local 'fb' variable to a few places to get rid of the
'crtc->primary->fb' stuff. Looks neater and helps me with my poor
coccinelle skills later.

Cc: Dave Airlie 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/cirrus/cirrus_mode.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/cirrus/cirrus_mode.c 
b/drivers/gpu/drm/cirrus/cirrus_mode.c
index 17c915d9a03e..f2297acae235 100644
--- a/drivers/gpu/drm/cirrus/cirrus_mode.c
+++ b/drivers/gpu/drm/cirrus/cirrus_mode.c
@@ -185,6 +185,7 @@ static int cirrus_crtc_mode_set(struct drm_crtc *crtc,
 {
struct drm_device *dev = crtc->dev;
struct cirrus_device *cdev = dev->dev_private;
+   const struct drm_framebuffer *fb = crtc->primary->fb;
int hsyncstart, hsyncend, htotal, hdispend;
int vtotal, vdispend;
int tmp;
@@ -257,7 +258,7 @@ static int cirrus_crtc_mode_set(struct drm_crtc *crtc,
sr07 = RREG8(SEQ_DATA);
sr07 &= 0xe0;
hdr = 0;
-   switch (crtc->primary->fb->bits_per_pixel) {
+   switch (fb->bits_per_pixel) {
case 8:
sr07 |= 0x11;
break;
@@ -280,13 +281,13 @@ static int cirrus_crtc_mode_set(struct drm_crtc *crtc,
WREG_SEQ(0x7, sr07);

/* Program the pitch */
-   tmp = crtc->primary->fb->pitches[0] / 8;
+   tmp = fb->pitches[0] / 8;
WREG_CRT(VGA_CRTC_OFFSET, tmp);

/* Enable extended blanking and pitch bits, and enable full memory */
tmp = 0x22;
-   tmp |= (crtc->primary->fb->pitches[0] >> 7) & 0x10;
-   tmp |= (crtc->primary->fb->pitches[0] >> 6) & 0x40;
+   tmp |= (fb->pitches[0] >> 7) & 0x10;
+   tmp |= (fb->pitches[0] >> 6) & 0x40;
WREG_CRT(0x1b, tmp);

/* Enable high-colour modes */
-- 
2.7.4



[PATCH 06/37] drm/gma500: Add some local 'fb' variables

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add a local 'fb' variable to a few places to get rid of the
'crtc->primary->fb' stuff. Looks neater and helps me with my poor
coccinelle skills later.

Cc: Patrik Jakobsson 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/gma500/gma_display.c | 13 +++--
 drivers/gpu/drm/gma500/mdfld_intel_display.c | 15 ---
 drivers/gpu/drm/gma500/oaktrail_crtc.c   | 13 +++--
 3 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/gma500/gma_display.c 
b/drivers/gpu/drm/gma500/gma_display.c
index 1a1cf7a3b5ef..05b9a4ceb58d 100644
--- a/drivers/gpu/drm/gma500/gma_display.c
+++ b/drivers/gpu/drm/gma500/gma_display.c
@@ -59,7 +59,8 @@ int gma_pipe_set_base(struct drm_crtc *crtc, int x, int y,
struct drm_device *dev = crtc->dev;
struct drm_psb_private *dev_priv = dev->dev_private;
struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
-   struct psb_framebuffer *psbfb = to_psb_fb(crtc->primary->fb);
+   struct drm_framebuffer *fb = crtc->primary->fb;
+   struct psb_framebuffer *psbfb = to_psb_fb(fb);
int pipe = gma_crtc->pipe;
const struct psb_offset *map = _priv->regmap[pipe];
unsigned long start, offset;
@@ -70,7 +71,7 @@ int gma_pipe_set_base(struct drm_crtc *crtc, int x, int y,
return 0;

/* no fb bound */
-   if (!crtc->primary->fb) {
+   if (!fb) {
dev_err(dev->dev, "No FB bound\n");
goto gma_pipe_cleaner;
}
@@ -81,19 +82,19 @@ int gma_pipe_set_base(struct drm_crtc *crtc, int x, int y,
if (ret < 0)
goto gma_pipe_set_base_exit;
start = psbfb->gtt->offset;
-   offset = y * crtc->primary->fb->pitches[0] + x * 
(crtc->primary->fb->bits_per_pixel / 8);
+   offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);

-   REG_WRITE(map->stride, crtc->primary->fb->pitches[0]);
+   REG_WRITE(map->stride, fb->pitches[0]);

dspcntr = REG_READ(map->cntr);
dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;

-   switch (crtc->primary->fb->bits_per_pixel) {
+   switch (fb->bits_per_pixel) {
case 8:
dspcntr |= DISPPLANE_8BPP;
break;
case 16:
-   if (crtc->primary->fb->depth == 15)
+   if (fb->depth == 15)
dspcntr |= DISPPLANE_15_16BPP;
else
dspcntr |= DISPPLANE_16BPP;
diff --git a/drivers/gpu/drm/gma500/mdfld_intel_display.c 
b/drivers/gpu/drm/gma500/mdfld_intel_display.c
index 92e3f93ee682..e80895285e94 100644
--- a/drivers/gpu/drm/gma500/mdfld_intel_display.c
+++ b/drivers/gpu/drm/gma500/mdfld_intel_display.c
@@ -165,8 +165,9 @@ static int mdfld__intel_pipe_set_base(struct drm_crtc 
*crtc, int x, int y,
 {
struct drm_device *dev = crtc->dev;
struct drm_psb_private *dev_priv = dev->dev_private;
+   struct drm_framebuffer *fb = crtc->primary->fb;
struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
-   struct psb_framebuffer *psbfb = to_psb_fb(crtc->primary->fb);
+   struct psb_framebuffer *psbfb = to_psb_fb(fb);
int pipe = gma_crtc->pipe;
const struct psb_offset *map = _priv->regmap[pipe];
unsigned long start, offset;
@@ -178,12 +179,12 @@ static int mdfld__intel_pipe_set_base(struct drm_crtc 
*crtc, int x, int y,
dev_dbg(dev->dev, "pipe = 0x%x.\n", pipe);

/* no fb bound */
-   if (!crtc->primary->fb) {
+   if (!fb) {
dev_dbg(dev->dev, "No FB bound\n");
return 0;
}

-   ret = check_fb(crtc->primary->fb);
+   ret = check_fb(fb);
if (ret)
return ret;

@@ -196,18 +197,18 @@ static int mdfld__intel_pipe_set_base(struct drm_crtc 
*crtc, int x, int y,
return 0;

start = psbfb->gtt->offset;
-   offset = y * crtc->primary->fb->pitches[0] + x * 
(crtc->primary->fb->bits_per_pixel / 8);
+   offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);

-   REG_WRITE(map->stride, crtc->primary->fb->pitches[0]);
+   REG_WRITE(map->stride, fb->pitches[0]);
dspcntr = REG_READ(map->cntr);
dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;

-   switch (crtc->primary->fb->bits_per_pixel) {
+   switch (fb->bits_per_pixel) {
case 8:
dspcntr |= DISPPLANE_8BPP;
break;
case 16:
-   if (crtc->primary->fb->depth == 15)
+   if (fb->depth == 15)
dspcntr |= DISPPLANE_15_16BPP;
else
dspcntr |= DISPPLANE_16BPP;
diff -

[PATCH 05/37] drm/ast: Add local 'fb' variables

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add a local 'fb' variable to a few places to get rid of the
'crtc->primary->fb' stuff. Looks neater and helps me with my poor
coccinelle skills later.

Cc: Dave Airlie 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/ast/ast_mode.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
index 5957c3e659fe..deb3684ccaf8 100644
--- a/drivers/gpu/drm/ast/ast_mode.c
+++ b/drivers/gpu/drm/ast/ast_mode.c
@@ -79,12 +79,13 @@ static bool ast_get_vbios_mode_info(struct drm_crtc *crtc, 
struct drm_display_mo
struct ast_vbios_mode_info *vbios_mode)
 {
struct ast_private *ast = crtc->dev->dev_private;
+   const struct drm_framebuffer *fb = crtc->primary->fb;
u32 refresh_rate_index = 0, mode_id, color_index, refresh_rate;
u32 hborder, vborder;
bool check_sync;
struct ast_vbios_enhtable *best = NULL;

-   switch (crtc->primary->fb->bits_per_pixel) {
+   switch (fb->bits_per_pixel) {
case 8:
vbios_mode->std_table = _stdtable[VGAModeIndex];
color_index = VGAModeIndex - 1;
@@ -207,7 +208,7 @@ static bool ast_get_vbios_mode_info(struct drm_crtc *crtc, 
struct drm_display_mo
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x91, 0x00);
if (vbios_mode->enh_table->flags & NewModeInfo) {
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x91, 0xa8);
-   ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x92, 
crtc->primary->fb->bits_per_pixel);
+   ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x92, 
fb->bits_per_pixel);
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x93, 
adjusted_mode->clock / 1000);
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x94, 
adjusted_mode->crtc_hdisplay);
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x95, 
adjusted_mode->crtc_hdisplay >> 8);
@@ -369,10 +370,11 @@ static void ast_set_crtc_reg(struct drm_crtc *crtc, 
struct drm_display_mode *mod
 static void ast_set_offset_reg(struct drm_crtc *crtc)
 {
struct ast_private *ast = crtc->dev->dev_private;
+   const struct drm_framebuffer *fb = crtc->primary->fb;

u16 offset;

-   offset = crtc->primary->fb->pitches[0] >> 3;
+   offset = fb->pitches[0] >> 3;
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x13, (offset & 0xff));
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xb0, (offset >> 8) & 0x3f);
 }
@@ -395,9 +397,10 @@ static void ast_set_ext_reg(struct drm_crtc *crtc, struct 
drm_display_mode *mode
 struct ast_vbios_mode_info *vbios_mode)
 {
struct ast_private *ast = crtc->dev->dev_private;
+   const struct drm_framebuffer *fb = crtc->primary->fb;
u8 jregA0 = 0, jregA3 = 0, jregA8 = 0;

-   switch (crtc->primary->fb->bits_per_pixel) {
+   switch (fb->bits_per_pixel) {
case 8:
jregA0 = 0x70;
jregA3 = 0x01;
@@ -452,7 +455,9 @@ static void ast_set_sync_reg(struct drm_device *dev, struct 
drm_display_mode *mo
 static bool ast_set_dac_reg(struct drm_crtc *crtc, struct drm_display_mode 
*mode,
 struct ast_vbios_mode_info *vbios_mode)
 {
-   switch (crtc->primary->fb->bits_per_pixel) {
+   const struct drm_framebuffer *fb = crtc->primary->fb;
+
+   switch (fb->bits_per_pixel) {
case 8:
break;
default:
-- 
2.7.4



[PATCH 04/37] drm/mgag200: Add local 'fb' variable

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add a local 'fb' variable to a few places to get rid of the
'crtc->primary->fb' stuff. Looks neater and helps me with my poor
coccinelle skills later.

Cc: Dave Airlie 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/mgag200/mgag200_mode.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c 
b/drivers/gpu/drm/mgag200/mgag200_mode.c
index 6b21cb27e1cc..bdac288ab16d 100644
--- a/drivers/gpu/drm/mgag200/mgag200_mode.c
+++ b/drivers/gpu/drm/mgag200/mgag200_mode.c
@@ -880,6 +880,7 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc,
 {
struct drm_device *dev = crtc->dev;
struct mga_device *mdev = dev->dev_private;
+   const struct drm_framebuffer *fb = crtc->primary->fb;
int hdisplay, hsyncstart, hsyncend, htotal;
int vdisplay, vsyncstart, vsyncend, vtotal;
int pitch;
@@ -902,7 +903,7 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc,
/* 0x48: */0,0,0,0,0,0,0,0
};

-   bppshift = mdev->bpp_shifts[(crtc->primary->fb->bits_per_pixel >> 3) - 
1];
+   bppshift = mdev->bpp_shifts[(fb->bits_per_pixel >> 3) - 1];

switch (mdev->type) {
case G200_SE_A:
@@ -941,12 +942,12 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc,
break;
}

-   switch (crtc->primary->fb->bits_per_pixel) {
+   switch (fb->bits_per_pixel) {
case 8:
dacvalue[MGA1064_MUL_CTL] = MGA1064_MUL_CTL_8bits;
break;
case 16:
-   if (crtc->primary->fb->depth == 15)
+   if (fb->depth == 15)
dacvalue[MGA1064_MUL_CTL] = MGA1064_MUL_CTL_15bits;
else
dacvalue[MGA1064_MUL_CTL] = MGA1064_MUL_CTL_16bits;
@@ -997,8 +998,8 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc,
WREG_SEQ(3, 0);
WREG_SEQ(4, 0xe);

-   pitch = crtc->primary->fb->pitches[0] / 
(crtc->primary->fb->bits_per_pixel / 8);
-   if (crtc->primary->fb->bits_per_pixel == 24)
+   pitch = fb->pitches[0] / (fb->bits_per_pixel / 8);
+   if (fb->bits_per_pixel == 24)
pitch = (pitch * 3) >> (4 - bppshift);
else
pitch = pitch >> (4 - bppshift);
@@ -1075,7 +1076,7 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc,
((vdisplay & 0xc00) >> 7) |
((vsyncstart & 0xc00) >> 5) |
((vdisplay & 0x400) >> 3);
-   if (crtc->primary->fb->bits_per_pixel == 24)
+   if (fb->bits_per_pixel == 24)
ext_vga[3] = (((1 << bppshift) * 3) - 1) | 0x80;
else
ext_vga[3] = ((1 << bppshift) - 1) | 0x80;
@@ -1138,9 +1139,9 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc,
u32 bpp;
u32 mb;

-   if (crtc->primary->fb->bits_per_pixel > 16)
+   if (fb->bits_per_pixel > 16)
bpp = 32;
-   else if (crtc->primary->fb->bits_per_pixel > 8)
+   else if (fb->bits_per_pixel > 8)
bpp = 16;
else
bpp = 8;
-- 
2.7.4



[PATCH 03/37] drm/radeon: Use DIV_ROUND_UP()

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Use DIV_ROUND_UP() instead of hand rolling it. Just a drive-by change.

Cc: Alex Deucher 
Cc: "Christian König" 
Signed-off-by: Ville Syrjälä 
Reviewed-by: Alex Deucher 
---
 drivers/gpu/drm/radeon/radeon_legacy_crtc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_legacy_crtc.c 
b/drivers/gpu/drm/radeon/radeon_legacy_crtc.c
index bb5346812de4..31c03e32a6b5 100644
--- a/drivers/gpu/drm/radeon/radeon_legacy_crtc.c
+++ b/drivers/gpu/drm/radeon/radeon_legacy_crtc.c
@@ -477,9 +477,8 @@ int radeon_crtc_do_set_base(struct drm_crtc *crtc,
crtc_offset_cntl = 0;

pitch_pixels = target_fb->pitches[0] / (target_fb->bits_per_pixel / 8);
-   crtc_pitch  = (((pitch_pixels * target_fb->bits_per_pixel) +
-   ((target_fb->bits_per_pixel * 8) - 1)) /
-  (target_fb->bits_per_pixel * 8));
+   crtc_pitch = DIV_ROUND_UP(pitch_pixels * target_fb->bits_per_pixel,
+ target_fb->bits_per_pixel * 8);
crtc_pitch |= crtc_pitch << 16;

crtc_offset_cntl |= RADEON_CRTC_GUI_TRIG_OFFSET_LEFT_EN;
-- 
2.7.4



[PATCH 02/37] drm/radeon: Add local 'fb' variables

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add a local 'fb' variable to a few places to get rid of the
'crtc->primary->fb' stuff. Looks neater and helps me with my poor
coccinelle skills later.

Cc: Alex Deucher 
Cc: "Christian König" 
Signed-off-by: Ville Syrjälä 
Reviewed-by: Alex Deucher 
---
 drivers/gpu/drm/radeon/r100.c   | 10 --
 drivers/gpu/drm/radeon/radeon_legacy_crtc.c |  3 ++-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c
index f5e84f4b58e6..984b35f43554 100644
--- a/drivers/gpu/drm/radeon/r100.c
+++ b/drivers/gpu/drm/radeon/r100.c
@@ -3225,13 +3225,19 @@ void r100_bandwidth_update(struct radeon_device *rdev)
radeon_update_display_priority(rdev);

if (rdev->mode_info.crtcs[0]->base.enabled) {
+   const struct drm_framebuffer *fb =
+   rdev->mode_info.crtcs[0]->base.primary->fb;
+
mode1 = >mode_info.crtcs[0]->base.mode;
-   pixel_bytes1 = 
rdev->mode_info.crtcs[0]->base.primary->fb->bits_per_pixel / 8;
+   pixel_bytes1 = fb->bits_per_pixel / 8;
}
if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
if (rdev->mode_info.crtcs[1]->base.enabled) {
+   const struct drm_framebuffer *fb =
+   rdev->mode_info.crtcs[1]->base.primary->fb;
+
mode2 = >mode_info.crtcs[1]->base.mode;
-   pixel_bytes2 = 
rdev->mode_info.crtcs[1]->base.primary->fb->bits_per_pixel / 8;
+   pixel_bytes2 = fb->bits_per_pixel / 8;
}
}

diff --git a/drivers/gpu/drm/radeon/radeon_legacy_crtc.c 
b/drivers/gpu/drm/radeon/radeon_legacy_crtc.c
index d0de4022fff9..bb5346812de4 100644
--- a/drivers/gpu/drm/radeon/radeon_legacy_crtc.c
+++ b/drivers/gpu/drm/radeon/radeon_legacy_crtc.c
@@ -579,6 +579,7 @@ static bool radeon_set_crtc_timing(struct drm_crtc *crtc, 
struct drm_display_mod
struct drm_device *dev = crtc->dev;
struct radeon_device *rdev = dev->dev_private;
struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
+   const struct drm_framebuffer *fb = crtc->primary->fb;
struct drm_encoder *encoder;
int format;
int hsync_start;
@@ -602,7 +603,7 @@ static bool radeon_set_crtc_timing(struct drm_crtc *crtc, 
struct drm_display_mod
}
}

-   switch (crtc->primary->fb->bits_per_pixel) {
+   switch (fb->bits_per_pixel) {
case 8:
format = 2;
break;
-- 
2.7.4



[PATCH 01/37] drm/i915: Add local 'fb' variables

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add a local 'fb' variable to a few places to get rid of the
'crtc->primary->fb' stuff. Looks neater and helps me with my poor
coccinelle skills later.

While at it switch over to using the pixel format rather than
depth+bpp.

Cc: intel-gfx at lists.freedesktop.org
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_overlay.c | 26 --
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_overlay.c 
b/drivers/gpu/drm/i915/intel_overlay.c
index fd0e4dac7cc1..ce3667c18e18 100644
--- a/drivers/gpu/drm/i915/intel_overlay.c
+++ b/drivers/gpu/drm/i915/intel_overlay.c
@@ -658,6 +658,8 @@ static bool update_scaling_factors(struct intel_overlay 
*overlay,
 static void update_colorkey(struct intel_overlay *overlay,
struct overlay_registers __iomem *regs)
 {
+   const struct drm_framebuffer *fb =
+   overlay->crtc->base.primary->fb;
u32 key = overlay->color_key;
u32 flags;

@@ -665,24 +667,20 @@ static void update_colorkey(struct intel_overlay *overlay,
if (overlay->color_key_enabled)
flags |= DST_KEY_ENABLE;

-   switch (overlay->crtc->base.primary->fb->bits_per_pixel) {
-   case 8:
+   switch (fb->pixel_format) {
+   case DRM_FORMAT_C8:
key = 0;
flags |= CLK_RGB8I_MASK;
break;
-
-   case 16:
-   if (overlay->crtc->base.primary->fb->depth == 15) {
-   key = RGB15_TO_COLORKEY(key);
-   flags |= CLK_RGB15_MASK;
-   } else {
-   key = RGB16_TO_COLORKEY(key);
-   flags |= CLK_RGB16_MASK;
-   }
+   case DRM_FORMAT_XRGB1555:
+   key = RGB15_TO_COLORKEY(key);
+   flags |= CLK_RGB15_MASK;
break;
-
-   case 24:
-   case 32:
+   case DRM_FORMAT_RGB565:
+   key = RGB16_TO_COLORKEY(key);
+   flags |= CLK_RGB16_MASK;
+   break;
+   default:
flags |= CLK_RGB24_MASK;
break;
}
-- 
2.7.4



[PATCH v2 00/37] drm: Deduplicate fb format information (v2)

2016-11-18 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Second installment of my effort to remove the duplicated
depth/bpp/pixel_format from drm_framebuffer and just use
struct drm_format_info instead.

I tried to address all of the review feedback, and collect
up all the r-bs I already got. Thanks for the review, guys.

Changes since the last version are roughly:
* drm_framebuffer_init() now fails if the fb isn't properly prepared
* Applied mode cocciry all over to use fb->format more extensively
* Dropped a few i915 specific patches that were taken care of the
  previous item
* Took up Laurent's idea that we can just compare the fb->format
  pointers instead of comparing the fb->format->format values
* Added a new .get_format_info() hooks for drivers to provide custom
  format information + an quick example patch how we'd hook it up
  for i915 render compression support

Link to the previous version:
https://lists.freedesktop.org/archives/dri-devel/2016-November/124135.html

Entire series is available here:
git://github.com/vsyrjala/linux.git fb_format_dedup_2

Cc: Alex Deucher 
Cc: Alexey Brodkin 
Cc: Ben Skeggs 
Cc: Ben Widawsky 
Cc: Brian Starkey 
Cc: "Christian König" 
Cc: Dave Airlie 
Cc: Gerd Hoffmann 
Cc: intel-gfx at lists.freedesktop.org
Cc: Laurent Pinchart 
Cc: linux-graphics-maintainer at vmware.com
Cc: Liviu Dudau 
Cc: Mali DP Maintainers 
Cc: Patrik Jakobsson 
Cc: Paulo Zanoni 
Cc: Sinclair Yeh 
Cc: Thomas Hellstrom 

Ville Syrjälä (37):
  drm/i915: Add local 'fb' variables
  drm/radeon: Add local 'fb' variables
  drm/radeon: Use DIV_ROUND_UP()
  drm/mgag200: Add local 'fb' variable
  drm/ast: Add local 'fb' variables
  drm/gma500: Add some local 'fb' variables
  drm/cirrus: Add some local 'fb' variables
  drm/arcpgu: Add local 'fb' variables
  drm/arm: Add local 'fb' variables
  drm/nouveau: Fix crtc->primary->fb vs. drm_fb fail
  drm/nouveau: Add local 'fb' variables
  drm/vmwgfx: Populate fb->dev before drm_framebuffer_init()
  drm: Pass 'dev' to drm_helper_mode_fill_fb_struct()
  drm/vmwgfx: Populate fb->pixel_format
  drm/qxl: Call drm_helper_mode_fill_fb_struct() before
drm_framebuffer_init()
  drm/virtio: Call drm_helper_mode_fill_fb_struct() before
drm_framebuffer_init()
  drm/i915: Set fb->dev early on for inherited fbs
  drm: Populate fb->dev from drm_helper_mode_fill_fb_struct()
  drm: Store a pointer to drm_format_info under drm_framebuffer
  drm/vmwgfx: Populate fb->format correctly
  drm/i915: Populate fb->format early for inherited fbs
  drm: Reject fbs w/o format info in drm_framebuffer_init()
  drm: Replace drm_format_num_planes() with fb->format->num_planes
  drm/i915: Eliminate the ugly 'fb?:' constructs from the ilk/skl wm
code
  drm: Replace drm_format_plane_cpp() with fb->format->cpp[]
  drm/fb_cma_helper: Replace drm_format_info() with fb->format
  drm/nouveau: Use fb->format rather than drm_format_info()
  drm/i915: Store a pointer to the pixel format info for fbc
  drm: Add drm_framebuffer_plane_{width,height}()
  drm/i915: Use drm_framebuffer_plane_{width,height}() where possible
  drm: Nuke fb->depth
  drm: Nuke fb->bits_per_pixel
  drm: Nuke fb->pixel_format
  drm: Replace 'format->format' comparisons to just 'format' comparisons
  drm: Eliminate the useless "non-RGB fb" debug message
  drm: Add mode_config .get_format_info() hook
  drm/i915: Implement .get_format_info() hook for CCS

 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c  |   4 +-
 drivers/gpu/drm/amd/amdgpu/dce_v10_0.c  |   6 +-
 drivers/gpu/drm/amd/amdgpu/dce_v11_0.c  |   6 +-
 drivers/gpu/drm/amd/amdgpu/dce_v6_0.c   |   6 +-
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c   |   6 +-
 drivers/gpu/drm/arc/arcpgu_crtc.c   |   3 +-
 drivers/gpu/drm/arm/hdlcd_crtc.c|  18 ++--
 drivers/gpu/drm/arm/malidp_planes.c |  10 +--
 drivers/gpu/drm/armada/armada_crtc.c|   6 +-
 drivers/gpu/drm/armada/armada_fb.c  |   2 +-
 drivers/gpu/drm/armada/armada_fbdev.c   |   5 +-
 drivers/gpu/drm/armada/armada_overlay.c |   6 +-
 drivers/gpu/drm/ast/ast_fb.c|   4 +-
 drivers/gpu/drm/ast/ast_main.c  |   2 +-
 drivers/gpu/drm/ast/ast_mode.c  |  16 ++--
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_layer.c |   2 +-
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c |  22 ++---
 drivers/gpu/drm/bochs/bochs_fbdev.c |   2 +-
 drivers/gpu/drm/bochs/bochs_mm.c|   2 +-
 drivers/gpu/drm/cirrus/cirrus_fbdev.c   |   6 +-
 drivers/gpu/drm/cirrus/cirrus_main.c|   2 +-
 drivers/gpu/drm/cirrus/cirrus_mode.c|   9 +-
 drivers/gpu/drm/drm_atomic.c|   8 +-
 drivers/gpu/drm/drm_crtc.c  |   4 +-
 drivers/gpu/drm/drm_crtc_helper.c   

[PATCH v2 31/32] drm: Nuke fb->bits_per_pixel

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Replace uses of fb->bits_per_pixel with fb->format->cpp[0]*8.
Less duplicated information is a good thing.

Note that I didn't put parens around the cpp*8 in the below cocci script,
on account of not wanting spurious parens all over the place. Instead I
did the unsafe way, and tried to look over the entire diff to spot if
any dangerous expressions were produced. I didn't see any.

There are some cases where previously the code did X*bpp/8, so the
division happened after the multiplication. Those are now just X*cpp
so the division effectively happens before the multiplication,
but that is perfectly fine since bpp is always a multiple of 8.

@@
struct drm_framebuffer *fb;
expression E;
@@
 drm_helper_mode_fill_fb_struct(...) {
...
-   fb->bits_per_pixel = E;
...
 }

@@
struct vmw_framebuffer_surface *vfb;
expression E;
@@
- vfb->base.base.bits_per_pixel = E;

@@
struct vmw_framebuffer_dmabuf *vfb;
expression E;
@@
- vfb->base.base.bits_per_pixel = E;

@@
struct drm_framebuffer *fb;
expression E;
@@
 i9xx_get_initial_plane_config(...) {
...
-   fb->bits_per_pixel = E;
...
 }

@@
struct drm_framebuffer *fb;
expression E;
@@
 ironlake_get_initial_plane_config(...) {
...
-   fb->bits_per_pixel = E;
...
 }

@@
struct drm_framebuffer *fb;
expression E;
@@
 skylake_get_initial_plane_config(...) {
...
-   fb->bits_per_pixel = E;
...
 }

@@
struct drm_framebuffer fb;
expression E;
@@
(
- E * fb.bits_per_pixel / 8
+ E * fb.format->cpp[0]
|
- fb.bits_per_pixel / 8
+ fb.format->cpp[0]
|
- E * fb.bits_per_pixel >> 3
+ E * fb.format->cpp[0]
|
- fb.bits_per_pixel >> 3
+ fb.format->cpp[0]
|
- (fb.bits_per_pixel + 7) / 8
+ fb.format->cpp[0]
|
- fb.bits_per_pixel
+ fb.format->cpp[0] * 8
|
- fb.format->cpp[0] * 8 != 8
+ fb.format->cpp[0] != 1
)

@@
struct drm_framebuffer *fb;
expression E;
@@
(
- E * fb->bits_per_pixel / 8
+ E * fb->format->cpp[0]
|
- fb->bits_per_pixel / 8
+ fb->format->cpp[0]
|
- E * fb->bits_per_pixel >> 3
+ E * fb->format->cpp[0]
|
- fb->bits_per_pixel >> 3
+ fb->format->cpp[0]
|
- (fb->bits_per_pixel + 7) / 8
+ fb->format->cpp[0]
|
- fb->bits_per_pixel
+ fb->format->cpp[0] * 8
|
- fb->format->cpp[0] * 8 != 8
+ fb->format->cpp[0] != 1
)

@@
@@
- (8 * 8)
+ 8 * 8

@@
struct drm_framebuffer fb;
@@
- (fb.format->cpp[0])
+ fb.format->cpp[0]

@@
struct drm_framebuffer *fb;
@@
- (fb->format->cpp[0])
+ fb->format->cpp[0]

@@
@@
 struct drm_framebuffer {
 ...
-int bits_per_pixel;
 ...
 };

v2: Clean up the 'cpp*8 != 8' and '(8 * 8)' cases (Laurent)

Signed-off-by: Ville Syrjälä 
Reviewed-by: Laurent Pinchart 
Reviewed-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/dce_v10_0.c|  2 +-
 drivers/gpu/drm/amd/amdgpu/dce_v11_0.c|  2 +-
 drivers/gpu/drm/amd/amdgpu/dce_v6_0.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c |  2 +-
 drivers/gpu/drm/armada/armada_crtc.c  |  4 ++--
 drivers/gpu/drm/armada/armada_fbdev.c |  2 +-
 drivers/gpu/drm/ast/ast_fb.c  |  2 +-
 drivers/gpu/drm/ast/ast_mode.c|  9 +
 drivers/gpu/drm/cirrus/cirrus_fbdev.c |  2 +-
 drivers/gpu/drm/cirrus/cirrus_mode.c  |  2 +-
 drivers/gpu/drm/drm_fb_helper.c   |  8 
 drivers/gpu/drm/drm_framebuffer.c |  2 +-
 drivers/gpu/drm/drm_modeset_helper.c  |  3 ---
 drivers/gpu/drm/exynos/exynos5433_drm_decon.c |  4 ++--
 drivers/gpu/drm/exynos/exynos7_drm_decon.c|  6 +++---
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c |  4 ++--
 drivers/gpu/drm/exynos/exynos_drm_fimd.c  |  2 +-
 drivers/gpu/drm/exynos/exynos_mixer.c |  4 ++--
 drivers/gpu/drm/gma500/framebuffer.c  |  2 +-
 drivers/gpu/drm/gma500/gma_display.c  |  4 ++--
 drivers/gpu/drm/gma500/mdfld_intel_display.c  |  6 +++---
 drivers/gpu/drm/gma500/oaktrail_crtc.c|  4 ++--
 drivers/gpu/drm/i915/i915_debugfs.c   |  4 ++--
 drivers/gpu/drm/i915/intel_display.c  | 11 ---
 drivers/gpu/drm/i915/intel_fbdev.c|  6 +++---
 drivers/gpu/drm/mgag200/mgag200_fb.c  |  2 +-
 drivers/gpu/drm/mgag200/mgag200_mode.c| 16 
 drivers/gpu/drm/nouveau/dispnv04/crtc.c   |  4 ++--
 drivers/gpu/drm/nouveau/nouveau_display.c |  2 +-
 drivers/gpu/drm/qxl/qxl_draw.c|  2 +-
 drivers/gpu/drm/radeon/atombios_crtc.c| 11 ++-
 drivers/gpu/drm/radeon/r100.c |  4 ++--
 drivers/gpu/drm/radeon/radeon_display.c   |  6 +++---
 drivers/gpu/drm/radeon/radeon_legacy_crtc.c   | 14 +++---
 drivers/gpu/drm/tegra/dc.c|  2 +-
 drivers/gpu/drm/tegra/drm.c   |  2 +-
 drivers/gpu/drm/udl

[PATCH 32/32] drm: Nuke fb->pixel_format

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Replace uses of fb->bits_per_pixel with fb->format->format.
Less duplicated information is a good thing.

Note that coccinelle failed to eliminate the
"/* fourcc format */" comment from drm_framebuffer.h, so I had
to do that part manually.

@@
struct drm_framebuffer *fb;
expression E;
@@
 drm_helper_mode_fill_fb_struct(...) {
...
-   fb->pixel_format = E;
...
 }

@@
struct vmw_framebuffer_surface *vfb;
expression E;
@@
- vfb->base.base.pixel_format = E;

@@
struct vmw_framebuffer_dmabuf *vfb;
expression E;
@@
- vfb->base.base.pixel_format = E;

@@
struct drm_framebuffer *fb;
expression E;
@@
 i9xx_get_initial_plane_config(...) {
...
-   fb->pixel_format = E;
...
 }

@@
struct drm_framebuffer *fb;
expression E;
@@
 ironlake_get_initial_plane_config(...) {
...
-   fb->pixel_format = E;
...
 }

@@
struct drm_framebuffer *fb;
expression E;
@@
 skylake_get_initial_plane_config(...) {
...
-   fb->pixel_format = E;
...
 }

@@
struct drm_framebuffer *fb;
@@
- fb->pixel_format
+ fb->format->format

@@
struct intel_framebuffer *fb;
@@
- fb->base.pixel_format
+ fb->base.format->format

@@
struct drm_plane_state *state;
@@
- state->fb->pixel_format
+ state->fb->format->format

@@
struct drm_plane_state state;
@@
- state.fb->pixel_format
+ state.fb->format->format

@@
struct drm_crtc *crtc;
@@
- crtc->primary->fb->pixel_format
+ crtc->primary->fb->format->format

@@
struct drm_mode_set *set;
@@
- set->fb->pixel_format
+ set->fb->format->format

@@
struct drm_mode_set *set;
@@
- set->crtc->primary->fb->pixel_format
+ set->crtc->primary->fb->format->format

@@
@@
 struct drm_framebuffer {
 ...
-uint32_t pixel_format;
 ...
 };

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/amd/amdgpu/dce_v10_0.c  |  4 +--
 drivers/gpu/drm/amd/amdgpu/dce_v11_0.c  |  4 +--
 drivers/gpu/drm/amd/amdgpu/dce_v6_0.c   |  4 +--
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c   |  4 +--
 drivers/gpu/drm/arc/arcpgu_crtc.c   |  2 +-
 drivers/gpu/drm/arm/hdlcd_crtc.c|  4 +--
 drivers/gpu/drm/arm/malidp_planes.c | 10 +++
 drivers/gpu/drm/armada/armada_crtc.c|  2 +-
 drivers/gpu/drm/armada/armada_overlay.c |  2 +-
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_layer.c |  2 +-
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c | 22 +++---
 drivers/gpu/drm/drm_atomic.c|  6 ++--
 drivers/gpu/drm/drm_crtc.c  |  4 +--
 drivers/gpu/drm/drm_crtc_helper.c   |  4 +--
 drivers/gpu/drm/drm_fb_cma_helper.c |  2 +-
 drivers/gpu/drm/drm_framebuffer.c   |  2 +-
 drivers/gpu/drm/drm_modeset_helper.c|  1 -
 drivers/gpu/drm/drm_plane.c |  6 ++--
 drivers/gpu/drm/exynos/exynos5433_drm_decon.c   |  2 +-
 drivers/gpu/drm/exynos/exynos7_drm_decon.c  |  2 +-
 drivers/gpu/drm/exynos/exynos_drm_fimd.c|  2 +-
 drivers/gpu/drm/exynos/exynos_mixer.c   |  8 ++---
 drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c |  4 +--
 drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c |  6 ++--
 drivers/gpu/drm/i915/i915_debugfs.c |  3 +-
 drivers/gpu/drm/i915/intel_atomic_plane.c   |  4 +--
 drivers/gpu/drm/i915/intel_display.c| 33 ++--
 drivers/gpu/drm/i915/intel_fbdev.c  |  2 +-
 drivers/gpu/drm/i915/intel_overlay.c|  2 +-
 drivers/gpu/drm/i915/intel_pm.c | 10 +++
 drivers/gpu/drm/i915/intel_sprite.c | 12 
 drivers/gpu/drm/imx/ipuv3-plane.c   | 40 -
 drivers/gpu/drm/mediatek/mtk_drm_plane.c|  2 +-
 drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c   |  2 +-
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c   |  4 +--
 drivers/gpu/drm/msm/msm_fb.c| 10 +++
 drivers/gpu/drm/nouveau/dispnv04/overlay.c  |  8 ++---
 drivers/gpu/drm/nouveau/nv50_display.c  |  4 +--
 drivers/gpu/drm/omapdrm/omap_fb.c   | 10 +++
 drivers/gpu/drm/radeon/atombios_crtc.c  |  8 ++---
 drivers/gpu/drm/rcar-du/rcar_du_plane.c |  4 +--
 drivers/gpu/drm/rcar-du/rcar_du_vsp.c   |  4 +--
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 22 +++---
 drivers/gpu/drm/shmobile/shmob_drm_crtc.c   |  6 ++--
 drivers/gpu/drm/shmobile/shmob_drm_plane.c  |  4 +--
 drivers/gpu/drm/sti/sti_gdp.c   | 10 +++
 drivers/gpu/drm/sti/sti_hqvdp.c |  2 +-
 drivers/gpu/drm/sun4i/sun4i_backend.c   |  5 ++--
 drivers/gpu/drm/tegra/dc.c  |  6 ++--
 drivers/gpu/drm/tegra/fb.c  |  2 +-
 drivers/gpu/drm/tilcdc/tilcdc_crtc

[PATCH 31/32] drm: Nuke fb->bits_per_pixel

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Replace uses of fb->bits_per_pixel with fb->format->cpp[0]*8.
Less duplicated information is a good thing.

Note that I didn't put parens around the cpp*8 in the below cocci script,
on account of not wanting spurious parens all over the place. Instead I
did the unsafe way, and tried to look over the entire diff to spot if
any dangerous expressions were produced. I didn't see any.

There are some cases where previously the code did X*bpp/8, so the
division happened after the multiplication. Those are now just X*cpp
so the division effectively happens before the multiplication,
but that is perfectly fine since bpp is always a multiple of 8.

@@
struct drm_framebuffer *fb;
expression E;
@@
 drm_helper_mode_fill_fb_struct(...) {
...
-   fb->bits_per_pixel = E;
...
 }

@@
struct vmw_framebuffer_surface *vfb;
expression E;
@@
- vfb->base.base.bits_per_pixel = E;

@@
struct vmw_framebuffer_dmabuf *vfb;
expression E;
@@
- vfb->base.base.bits_per_pixel = E;

@@
struct drm_framebuffer *fb;
expression E;
@@
 i9xx_get_initial_plane_config(...) {
...
-   fb->bits_per_pixel = E;
...
 }

@@
struct drm_framebuffer *fb;
expression E;
@@
 ironlake_get_initial_plane_config(...) {
...
-   fb->bits_per_pixel = E;
...
 }

@@
struct drm_framebuffer *fb;
expression E;
@@
 skylake_get_initial_plane_config(...) {
...
-   fb->bits_per_pixel = E;
...
 }

@@
struct drm_framebuffer fb;
expression E;
@@
(
- E * fb.bits_per_pixel / 8
+ E * fb.format->cpp[0]
|
- fb.bits_per_pixel / 8
+ fb.format->cpp[0]
|
- E * fb.bits_per_pixel >> 3
+ E * fb.format->cpp[0]
|
- fb.bits_per_pixel >> 3
+ fb.format->cpp[0]
|
- (fb.bits_per_pixel + 7) / 8
+ fb.format->cpp[0]
|
- fb.bits_per_pixel
+ fb.format->cpp[0] * 8
|
- fb.format->cpp[0] * 8 != 8
+ fb.format->cpp[0] != 1
)

@@
struct drm_framebuffer *fb;
expression E;
@@
(
- E * fb->bits_per_pixel / 8
+ E * fb->format->cpp[0]
|
- fb->bits_per_pixel / 8
+ fb->format->cpp[0]
|
- E * fb->bits_per_pixel >> 3
+ E * fb->format->cpp[0]
|
- fb->bits_per_pixel >> 3
+ fb->format->cpp[0]
|
- (fb->bits_per_pixel + 7) / 8
+ fb->format->cpp[0]
|
- fb->bits_per_pixel
+ fb->format->cpp[0] * 8
|
- fb->format->cpp[0] * 8 != 8
+ fb->format->cpp[0] != 1
)

@@
struct drm_framebuffer fb;
@@
- (fb.format->cpp[0])
+ fb.format->cpp[0]

@@
struct drm_framebuffer *fb;
@@
- (fb->format->cpp[0])
+ fb->format->cpp[0]

@@
@@
 struct drm_framebuffer {
 ...
-int bits_per_pixel;
 ...
 };

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/amd/amdgpu/dce_v10_0.c|  2 +-
 drivers/gpu/drm/amd/amdgpu/dce_v11_0.c|  2 +-
 drivers/gpu/drm/amd/amdgpu/dce_v6_0.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c |  2 +-
 drivers/gpu/drm/armada/armada_crtc.c  |  4 ++--
 drivers/gpu/drm/armada/armada_fbdev.c |  2 +-
 drivers/gpu/drm/ast/ast_fb.c  |  2 +-
 drivers/gpu/drm/ast/ast_mode.c|  9 +
 drivers/gpu/drm/cirrus/cirrus_fbdev.c |  2 +-
 drivers/gpu/drm/cirrus/cirrus_mode.c  |  2 +-
 drivers/gpu/drm/drm_fb_helper.c   |  8 
 drivers/gpu/drm/drm_framebuffer.c |  2 +-
 drivers/gpu/drm/drm_modeset_helper.c  |  3 ---
 drivers/gpu/drm/exynos/exynos5433_drm_decon.c |  4 ++--
 drivers/gpu/drm/exynos/exynos7_drm_decon.c|  6 +++---
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c |  4 ++--
 drivers/gpu/drm/exynos/exynos_drm_fimd.c  |  2 +-
 drivers/gpu/drm/exynos/exynos_mixer.c |  4 ++--
 drivers/gpu/drm/gma500/framebuffer.c  |  2 +-
 drivers/gpu/drm/gma500/gma_display.c  |  4 ++--
 drivers/gpu/drm/gma500/mdfld_intel_display.c  |  6 +++---
 drivers/gpu/drm/gma500/oaktrail_crtc.c|  4 ++--
 drivers/gpu/drm/i915/i915_debugfs.c   |  4 ++--
 drivers/gpu/drm/i915/intel_display.c  | 11 ---
 drivers/gpu/drm/i915/intel_fbdev.c|  6 +++---
 drivers/gpu/drm/mgag200/mgag200_fb.c  |  2 +-
 drivers/gpu/drm/mgag200/mgag200_mode.c| 16 
 drivers/gpu/drm/nouveau/dispnv04/crtc.c   |  4 ++--
 drivers/gpu/drm/nouveau/nouveau_display.c |  2 +-
 drivers/gpu/drm/qxl/qxl_draw.c|  2 +-
 drivers/gpu/drm/radeon/atombios_crtc.c| 11 ++-
 drivers/gpu/drm/radeon/r100.c |  4 ++--
 drivers/gpu/drm/radeon/radeon_display.c   |  6 +++---
 drivers/gpu/drm/radeon/radeon_legacy_crtc.c   | 14 +++---
 drivers/gpu/drm/tegra/dc.c|  2 +-
 drivers/gpu/drm/tegra/drm.c   |  2 +-
 drivers/gpu/drm/udl/udl_fb.c  |  2 +-
 drivers/gpu/drm/virtio/virtgpu_fb.c   |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_fb.c|  6 +++--

[PATCH 30/32] drm: Nuke fb->depth

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Replace uses of fb->depth with fb->format->depth. Less duplicate
information is a good thing.

@@
struct drm_framebuffer *fb;
expression E1, E2;
@@
 drm_helper_mode_fill_fb_struct(...) {
...
-   fb->depth = E1;
...
 }

@@
struct vmw_framebuffer_surface *vfb;
expression E;
@@
- vfb->base.base.depth = E;

@@
struct vmw_framebuffer_dmabuf *vfb;
expression E;
@@
- vfb->base.base.depth = E;

@@
struct nouveau_framebuffer *fb;
@@
- fb->base.depth
+ fb->base.format->depth

@@
struct drm_framebuffer fb;
expression E;
@@
- fb.depth
+ fb.format->depth

@@
struct drm_framebuffer *fb;
expression E;
@@
- fb->depth
+ fb->format->depth

@@
struct drm_framebuffer fb;
@@
- (fb.format->depth)
+ fb.format->depth

@@
struct drm_framebuffer *fb;
@@
- (fb->format->depth)
+ fb->format->depth

@@
@@
 struct drm_framebuffer {
 ...
-unsigned int depth;
 ...
 };

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c|  4 ++--
 drivers/gpu/drm/armada/armada_fbdev.c |  3 ++-
 drivers/gpu/drm/ast/ast_fb.c  |  2 +-
 drivers/gpu/drm/bochs/bochs_fbdev.c   |  2 +-
 drivers/gpu/drm/cirrus/cirrus_fbdev.c |  4 ++--
 drivers/gpu/drm/drm_fb_cma_helper.c   |  2 +-
 drivers/gpu/drm/drm_fb_helper.c   |  2 +-
 drivers/gpu/drm/drm_framebuffer.c |  2 +-
 drivers/gpu/drm/drm_modeset_helper.c  |  2 --
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c |  2 +-
 drivers/gpu/drm/gma500/accel_2d.c |  2 +-
 drivers/gpu/drm/gma500/framebuffer.c  |  2 +-
 drivers/gpu/drm/gma500/gma_display.c  |  2 +-
 drivers/gpu/drm/gma500/mdfld_intel_display.c  |  2 +-
 drivers/gpu/drm/gma500/oaktrail_crtc.c|  2 +-
 drivers/gpu/drm/i915/i915_debugfs.c   |  4 ++--
 drivers/gpu/drm/i915/intel_fbdev.c|  2 +-
 drivers/gpu/drm/mgag200/mgag200_fb.c  |  2 +-
 drivers/gpu/drm/mgag200/mgag200_mode.c|  6 +++---
 drivers/gpu/drm/msm/msm_fbdev.c   |  2 +-
 drivers/gpu/drm/nouveau/dispnv04/crtc.c   | 12 ++--
 drivers/gpu/drm/nouveau/dispnv04/dfp.c|  2 +-
 drivers/gpu/drm/nouveau/nouveau_fbcon.c   |  3 ++-
 drivers/gpu/drm/omapdrm/omap_fbdev.c  |  2 +-
 drivers/gpu/drm/qxl/qxl_fb.c  |  5 +++--
 drivers/gpu/drm/radeon/radeon_fb.c|  4 ++--
 drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c |  5 +++--
 drivers/gpu/drm/tegra/drm.c   |  3 ++-
 drivers/gpu/drm/tegra/fb.c|  2 +-
 drivers/gpu/drm/udl/udl_fb.c  |  2 +-
 drivers/gpu/drm/virtio/virtgpu_fb.c   |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_fb.c|  7 ---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c   |  2 --
 drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c   |  5 +++--
 drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c  |  2 +-
 include/drm/drm_framebuffer.h |  6 --
 36 files changed, 56 insertions(+), 59 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
index f1c9e59a7c87..f24c91b699a9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
@@ -245,7 +245,7 @@ static int amdgpufb_create(struct drm_fb_helper *helper,

strcpy(info->fix.id, "amdgpudrmfb");

-   drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth);
+   drm_fb_helper_fill_fix(info, fb->pitches[0], fb->format->depth);

info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT;
info->fbops = _ops;
@@ -272,7 +272,7 @@ static int amdgpufb_create(struct drm_fb_helper *helper,
DRM_INFO("fb mappable at 0x%lX\n",  info->fix.smem_start);
DRM_INFO("vram apper at 0x%lX\n",  (unsigned long)adev->mc.aper_base);
DRM_INFO("size %lu\n", (unsigned long)amdgpu_bo_size(abo));
-   DRM_INFO("fb depth is %d\n", fb->depth);
+   DRM_INFO("fb depth is %d\n", fb->format->depth);
DRM_INFO("   pitch is %d\n", fb->pitches[0]);

vga_switcheroo_client_fb_set(adev->ddev->pdev, info);
diff --git a/drivers/gpu/drm/armada/armada_fbdev.c 
b/drivers/gpu/drm/armada/armada_fbdev.c
index c5dc06a55883..3a58fb600b05 100644
--- a/drivers/gpu/drm/armada/armada_fbdev.c
+++ b/drivers/gpu/drm/armada/armada_fbdev.c
@@ -89,7 +89,8 @@ static int armada_fb_create(struct drm_fb_helper *fbh,
info->screen_base = ptr;
fbh->fb = >fb;

-   drm_fb_helper_fill_fix(info, dfb->fb.pitches[0], dfb->fb.depth);
+   drm_fb_helper_fill_fix(info, dfb->fb.pitches[0],
+  dfb->fb.format->depth);
drm_fb_helper_fill_var(info, fbh, sizes->fb_width, sizes->fb_height);

DRM_DEBU

[PATCH 29/32] drm/i915: Use drm_framebuffer_plane_{width, height}() where possible

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Replace drm_format_plane_{width,height}() usage with
drm_framebuffer_plane_{width,height}() to avoid the lookup of the format
info.

Cc: intel-gfx at lists.freedesktop.org
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_display.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 8f63fd38deee..5d8db436c557 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2496,7 +2496,6 @@ intel_fill_fb_info(struct drm_i915_private *dev_priv,
struct intel_rotation_info *rot_info = _fb->rot_info;
u32 gtt_offset_rotated = 0;
unsigned int max_size = 0;
-   uint32_t format = fb->pixel_format;
int i, num_planes = fb->format->num_planes;
unsigned int tile_size = intel_tile_size(dev_priv);

@@ -2507,8 +2506,8 @@ intel_fill_fb_info(struct drm_i915_private *dev_priv,
int x, y;

cpp = fb->format->cpp[i];
-   width = drm_format_plane_width(fb->width, format, i);
-   height = drm_format_plane_height(fb->height, format, i);
+   width = drm_framebuffer_plane_width(fb->width, fb, i);
+   height = drm_framebuffer_plane_height(fb->height, fb, i);

intel_fb_offset_to_xy(, , fb, i);

-- 
2.7.4



[PATCH 28/32] drm: Add drm_framebuffer_plane_{width,height}()

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add variants of drm_format_plane_{width,height}() that take an entire fb
object instead of just the format. These should be more efficent as they
can just look up the format info from the fb->format pointer rather than
having to look it up (using a linear search based on the format).

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_framebuffer.c | 44 +++
 include/drm/drm_framebuffer.h |  6 ++
 2 files changed, 50 insertions(+)

diff --git a/drivers/gpu/drm/drm_framebuffer.c 
b/drivers/gpu/drm/drm_framebuffer.c
index 47478678d609..28d697ae1faf 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -793,3 +793,47 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb)
drm_framebuffer_unreference(fb);
 }
 EXPORT_SYMBOL(drm_framebuffer_remove);
+
+/**
+ * drm_framebuffer_plane_width - width of the plane given the first plane
+ * @width: width of the first plane
+ * @fb: the framebuffer
+ * @plane: plane index
+ *
+ * Returns:
+ * The width of @plane, given that the width of the first plane is @width.
+ */
+int drm_framebuffer_plane_width(int width,
+   const struct drm_framebuffer *fb, int plane)
+{
+   if (plane >= fb->format->num_planes)
+   return 0;
+
+   if (plane == 0)
+   return width;
+
+   return width / fb->format->hsub;
+}
+EXPORT_SYMBOL(drm_framebuffer_plane_width);
+
+/**
+ * drm_framebuffer_plane_height - height of the plane given the first plane
+ * @height: height of the first plane
+ * @fb: the framebuffer
+ * @plane: plane index
+ *
+ * Returns:
+ * The height of @plane, given that the height of the first plane is @height.
+ */
+int drm_framebuffer_plane_height(int height,
+const struct drm_framebuffer *fb, int plane)
+{
+   if (plane >= fb->format->num_planes)
+   return 0;
+
+   if (plane == 0)
+   return height;
+
+   return height / fb->format->vsub;
+}
+EXPORT_SYMBOL(drm_framebuffer_plane_height);
diff --git a/include/drm/drm_framebuffer.h b/include/drm/drm_framebuffer.h
index 741b3a994d1f..cdcfb86b3f74 100644
--- a/include/drm/drm_framebuffer.h
+++ b/include/drm/drm_framebuffer.h
@@ -268,4 +268,10 @@ static inline uint32_t 
drm_framebuffer_read_refcount(struct drm_framebuffer *fb)
  struct drm_framebuffer, head);
\
 >head != (&(dev)->mode_config.fb_list);
\
 fb = list_next_entry(fb, head))
+
+int drm_framebuffer_plane_width(int width,
+   const struct drm_framebuffer *fb, int plane);
+int drm_framebuffer_plane_height(int height,
+const struct drm_framebuffer *fb, int plane);
+
 #endif
-- 
2.7.4



[PATCH 27/32] drm/i915: Replace drm_format_num_planes() with fb->format->num_planes

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

No need to look up the format info to get the number of planes, just
use fb->format->num_planes directly.

Cc: intel-gfx at lists.freedesktop.org
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 6565e5cd0ada..8f63fd38deee 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2497,7 +2497,7 @@ intel_fill_fb_info(struct drm_i915_private *dev_priv,
u32 gtt_offset_rotated = 0;
unsigned int max_size = 0;
uint32_t format = fb->pixel_format;
-   int i, num_planes = drm_format_num_planes(format);
+   int i, num_planes = fb->format->num_planes;
unsigned int tile_size = intel_tile_size(dev_priv);

for (i = 0; i < num_planes; i++) {
-- 
2.7.4



[PATCH 26/32] drm/i915: Replace drm_format_plane_cpp() with fb->format->cpp[]

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Avoid the fb format information lookups when we already have the
fb->format pointer at hand.

@@
struct drm_framebuffer *fb;
expression E;
@@
- drm_format_plane_cpp(fb->pixel_format, E)
+ fb->format->cpp[E]

@@
struct drm_framebuffer fb;
expression E;
@@
- drm_format_plane_cpp(fb.pixel_format, E)
+ fb.format->cpp[E]

@@
struct intel_plane_state *state;
expression E;
@@
- drm_format_plane_cpp(state->base.fb->pixel_format, E)
+ state->base.fb->format->cpp[E]

@@
struct drm_framebuffer *fb;
expression E1, E2;
@@
  unsigned format = fb ? fb->pixel_format : E1;
<+...
- drm_format_plane_cpp(format, E2)
+ fb->format->cpp[E2]
...+>

@@
struct drm_framebuffer *fb;
expression E;
@@
  uint32_t format = fb->pixel_format;
<+...
- drm_format_plane_cpp(format, E)
+ fb->format->cpp[E]
...+>

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_display.c | 16 +++---
 drivers/gpu/drm/i915/intel_pm.c  | 42 ++--
 drivers/gpu/drm/i915/intel_sprite.c  |  2 +-
 3 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index c45da6766fff..6565e5cd0ada 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2275,7 +2275,7 @@ u32 intel_fb_xy_to_linear(int x, int y,
  int plane)
 {
const struct drm_framebuffer *fb = state->base.fb;
-   unsigned int cpp = drm_format_plane_cpp(fb->pixel_format, plane);
+   unsigned int cpp = fb->format->cpp[plane];
unsigned int pitch = fb->pitches[plane];

return y * pitch + x * cpp;
@@ -2344,7 +2344,7 @@ static u32 intel_adjust_tile_offset(int *x, int *y,
 {
const struct drm_i915_private *dev_priv = 
to_i915(state->base.plane->dev);
const struct drm_framebuffer *fb = state->base.fb;
-   unsigned int cpp = drm_format_plane_cpp(fb->pixel_format, plane);
+   unsigned int cpp = fb->format->cpp[plane];
unsigned int rotation = state->base.rotation;
unsigned int pitch = intel_fb_pitch(fb, plane, rotation);

@@ -2400,7 +2400,7 @@ static u32 _intel_compute_tile_offset(const struct 
drm_i915_private *dev_priv,
  u32 alignment)
 {
uint64_t fb_modifier = fb->modifier;
-   unsigned int cpp = drm_format_plane_cpp(fb->pixel_format, plane);
+   unsigned int cpp = fb->format->cpp[plane];
u32 offset, offset_aligned;

if (alignment)
@@ -2468,7 +2468,7 @@ u32 intel_compute_tile_offset(int *x, int *y,
 static void intel_fb_offset_to_xy(int *x, int *y,
  const struct drm_framebuffer *fb, int plane)
 {
-   unsigned int cpp = drm_format_plane_cpp(fb->pixel_format, plane);
+   unsigned int cpp = fb->format->cpp[plane];
unsigned int pitch = fb->pitches[plane];
u32 linear_offset = fb->offsets[plane];

@@ -2506,7 +2506,7 @@ intel_fill_fb_info(struct drm_i915_private *dev_priv,
u32 offset;
int x, y;

-   cpp = drm_format_plane_cpp(format, i);
+   cpp = fb->format->cpp[i];
width = drm_format_plane_width(fb->width, format, i);
height = drm_format_plane_height(fb->height, format, i);

@@ -2833,7 +2833,7 @@ intel_find_initial_plane_obj(struct intel_crtc 
*intel_crtc,
 static int skl_max_plane_width(const struct drm_framebuffer *fb, int plane,
   unsigned int rotation)
 {
-   int cpp = drm_format_plane_cpp(fb->pixel_format, plane);
+   int cpp = fb->format->cpp[plane];

switch (fb->modifier) {
case DRM_FORMAT_MOD_NONE:
@@ -2912,7 +2912,7 @@ static int skl_check_main_surface(struct 
intel_plane_state *plane_state)
 * TODO: linear and Y-tiled seem fine, Yf untested,
 */
if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
-   int cpp = drm_format_plane_cpp(fb->pixel_format, 0);
+   int cpp = fb->format->cpp[0];

while ((x + w) * cpp > fb->pitches[0]) {
if (offset == 0) {
@@ -3278,7 +3278,7 @@ u32 skl_plane_stride(const struct drm_framebuffer *fb, 
int plane,
 * linear buffers or in number of tiles for tiled buffers.
 */
if (drm_rotation_90_or_270(rotation)) {
-   int cpp = drm_format_plane_cpp(fb->pixel_format, plane);
+   int cpp = fb->format->cpp[plane];

stride /= intel_tile_height(dev_priv, fb->modifier, cpp);
} else {
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index bbb1eaf1e6db..318cd7bdd785 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@

[PATCH 25/32] drm/i915: Store a pointer to the pixel format info for fbc

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Rather than store the pixel format and look up the format info as
needed,  let's just store a pointer to the format info directly
and speed up our lookups.

Cc: Paulo Zanoni 
Cc: intel-gfx at lists.freedesktop.org
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/i915_drv.h  |  4 ++--
 drivers/gpu/drm/i915/intel_fbc.c | 14 +++---
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index be67aeece749..692b79e056be 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1026,7 +1026,7 @@ struct intel_fbc {

struct {
u64 ilk_ggtt_offset;
-   uint32_t pixel_format;
+   const struct drm_format_info *format;
unsigned int stride;
int fence_reg;
unsigned int tiling_mode;
@@ -1042,7 +1042,7 @@ struct intel_fbc {

struct {
u64 ggtt_offset;
-   uint32_t pixel_format;
+   const struct drm_format_info *format;
unsigned int stride;
int fence_reg;
} fb;
diff --git a/drivers/gpu/drm/i915/intel_fbc.c b/drivers/gpu/drm/i915/intel_fbc.c
index 62f215b12eb5..659cebc3bfd2 100644
--- a/drivers/gpu/drm/i915/intel_fbc.c
+++ b/drivers/gpu/drm/i915/intel_fbc.c
@@ -188,7 +188,7 @@ static void g4x_fbc_activate(struct drm_i915_private 
*dev_priv)
u32 dpfc_ctl;

dpfc_ctl = DPFC_CTL_PLANE(params->crtc.plane) | DPFC_SR_EN;
-   if (drm_format_plane_cpp(params->fb.pixel_format, 0) == 2)
+   if (params->fb.format->cpp[0] == 2)
dpfc_ctl |= DPFC_CTL_LIMIT_2X;
else
dpfc_ctl |= DPFC_CTL_LIMIT_1X;
@@ -235,7 +235,7 @@ static void ilk_fbc_activate(struct drm_i915_private 
*dev_priv)
int threshold = dev_priv->fbc.threshold;

dpfc_ctl = DPFC_CTL_PLANE(params->crtc.plane);
-   if (drm_format_plane_cpp(params->fb.pixel_format, 0) == 2)
+   if (params->fb.format->cpp[0] == 2)
threshold++;

switch (threshold) {
@@ -303,7 +303,7 @@ static void gen7_fbc_activate(struct drm_i915_private 
*dev_priv)
if (IS_IVYBRIDGE(dev_priv))
dpfc_ctl |= IVB_DPFC_CTL_PLANE(params->crtc.plane);

-   if (drm_format_plane_cpp(params->fb.pixel_format, 0) == 2)
+   if (params->fb.format->cpp[0] == 2)
threshold++;

switch (threshold) {
@@ -581,7 +581,7 @@ static int intel_fbc_alloc_cfb(struct intel_crtc *crtc)
WARN_ON(drm_mm_node_allocated(>compressed_fb));

size = intel_fbc_calculate_cfb_size(dev_priv, >state_cache);
-   fb_cpp = drm_format_plane_cpp(fbc->state_cache.fb.pixel_format, 0);
+   fb_cpp = fbc->state_cache.fb.format->cpp[0];

ret = find_compression_threshold(dev_priv, >compressed_fb,
 size, fb_cpp);
@@ -764,7 +764,7 @@ static void intel_fbc_update_state_cache(struct intel_crtc 
*crtc,
 * platforms that need. */
if (IS_GEN(dev_priv, 5, 6))
cache->fb.ilk_ggtt_offset = i915_gem_object_ggtt_offset(obj, 
NULL);
-   cache->fb.pixel_format = fb->pixel_format;
+   cache->fb.format = fb->format;
cache->fb.stride = fb->pitches[0];
cache->fb.fence_reg = get_fence_id(fb);
cache->fb.tiling_mode = i915_gem_object_get_tiling(obj);
@@ -823,7 +823,7 @@ static bool intel_fbc_can_activate(struct intel_crtc *crtc)
return false;
}

-   if (!pixel_format_is_valid(dev_priv, cache->fb.pixel_format)) {
+   if (!pixel_format_is_valid(dev_priv, cache->fb.format->format)) {
fbc->no_fbc_reason = "pixel format is invalid";
return false;
}
@@ -892,7 +892,7 @@ static void intel_fbc_get_reg_params(struct intel_crtc 
*crtc,
params->crtc.plane = crtc->plane;
params->crtc.fence_y_offset = get_crtc_fence_y_offset(crtc);

-   params->fb.pixel_format = cache->fb.pixel_format;
+   params->fb.format = cache->fb.format;
params->fb.stride = cache->fb.stride;
params->fb.fence_reg = cache->fb.fence_reg;

-- 
2.7.4



[PATCH 24/32] drm/nouveau: Use fb->format rather than drm_format_info()

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Let's use the pointer to the format information cached under
drm_framebuffer rather than look it up manually.

Cc: Ben Skeggs 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/nouveau/nv50_display.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nv50_display.c 
b/drivers/gpu/drm/nouveau/nv50_display.c
index a9855a4ec532..d3bd428023ea 100644
--- a/drivers/gpu/drm/nouveau/nv50_display.c
+++ b/drivers/gpu/drm/nouveau/nv50_display.c
@@ -1418,12 +1418,10 @@ static int
 nv50_base_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
  struct nv50_head_atom *asyh)
 {
-   const u32 format = asyw->state.fb->pixel_format;
-   const struct drm_format_info *info;
+   const struct drm_framebuffer *fb = asyw->state.fb;
int ret;

-   info = drm_format_info(format);
-   if (!info || !info->depth)
+   if (!fb->format->depth)
return -EINVAL;

ret = drm_plane_helper_check_state(>state, >clip,
@@ -1433,14 +1431,14 @@ nv50_base_acquire(struct nv50_wndw *wndw, struct 
nv50_wndw_atom *asyw,
if (ret)
return ret;

-   asyh->base.depth = info->depth;
-   asyh->base.cpp = info->cpp[0];
+   asyh->base.depth = fb->format->depth;
+   asyh->base.cpp = fb->format->cpp[0];
asyh->base.x = asyw->state.src.x1 >> 16;
asyh->base.y = asyw->state.src.y1 >> 16;
asyh->base.w = asyw->state.fb->width;
asyh->base.h = asyw->state.fb->height;

-   switch (format) {
+   switch (fb->pixel_format) {
case DRM_FORMAT_C8 : asyw->image.format = 0x1e; break;
case DRM_FORMAT_RGB565 : asyw->image.format = 0xe8; break;
case DRM_FORMAT_XRGB1555   :
-- 
2.7.4



[PATCH 23/32] drm/fb_cma_helper: Replace drm_format_info() with fb->format

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Get the format information via the neat fb->format pointer rather than
doing a linear search over all the format info structures.

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_fb_cma_helper.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_fb_cma_helper.c 
b/drivers/gpu/drm/drm_fb_cma_helper.c
index 570f5c6063f3..0dc3f5bcbf48 100644
--- a/drivers/gpu/drm/drm_fb_cma_helper.c
+++ b/drivers/gpu/drm/drm_fb_cma_helper.c
@@ -304,15 +304,12 @@ EXPORT_SYMBOL_GPL(drm_fb_cma_prepare_fb);
 static void drm_fb_cma_describe(struct drm_framebuffer *fb, struct seq_file *m)
 {
struct drm_fb_cma *fb_cma = to_fb_cma(fb);
-   const struct drm_format_info *info;
int i;

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

-   info = drm_format_info(fb->pixel_format);
-
-   for (i = 0; i < info->num_planes; i++) {
+   for (i = 0; i < fb->fomat->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);
-- 
2.7.4



[PATCH 22/32] drm/atomic: Replace drm_format_num_planes() with fb->format->num_planes

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Avoid the format info lookup and just use the pointer stored under
drm_framebuffer.

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_atomic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 85466cc67819..cb6ab0106b0b 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -960,7 +960,7 @@ static void drm_atomic_plane_print_state(struct drm_printer 
*p,
drm_printf(p, "\tfb=%u\n", state->fb ? state->fb->base.id : 0);
if (state->fb) {
struct drm_framebuffer *fb = state->fb;
-   int i, n = drm_format_num_planes(fb->pixel_format);
+   int i, n = fb->format->num_planes;
struct drm_format_name_buf format_name;

drm_printf(p, "\t\tformat=%s\n",
-- 
2.7.4



[PATCH 21/32] drm/i915: Populate fb->format early for inherited fbs

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

MAke sure the framebuffer format info is available as early as possible
for fbs we inherit from the BIOS. This will allow us to use the fb as
if it was fully formed before we register it.

Cc: intel-gfx at lists.freedesktop.org
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_display.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 74a638c8de61..c45da6766fff 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -8717,6 +8717,7 @@ i9xx_get_initial_plane_config(struct intel_crtc *crtc,
fourcc = i9xx_format_to_fourcc(pixel_format);
fb->pixel_format = fourcc;
fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8;
+   fb->format = drm_format_info(fourcc);

if (INTEL_GEN(dev_priv) >= 4) {
if (plane_config->tiling)
@@ -9748,6 +9749,7 @@ skylake_get_initial_plane_config(struct intel_crtc *crtc,
  val & PLANE_CTL_ALPHA_MASK);
fb->pixel_format = fourcc;
fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8;
+   fb->format = drm_format_info(fourcc);

tiling = val & PLANE_CTL_TILED_MASK;
switch (tiling) {
@@ -9863,6 +9865,7 @@ ironlake_get_initial_plane_config(struct intel_crtc *crtc,
fourcc = i9xx_format_to_fourcc(pixel_format);
fb->pixel_format = fourcc;
fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8;
+   fb->format = drm_format_info(fourcc);

base = I915_READ(DSPSURF(pipe)) & 0xf000;
if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
-- 
2.7.4



[PATCH 20/32] drm/vmwgfx: Populate fb->format correctly

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Populate the fb->format to point at the correct format information
structure.

Cc: linux-graphics-maintainer at vmware.com
Cc: Sinclair Yeh 
Cc: Thomas Hellstrom 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index 5788913ca8f9..77f936e3056e 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -589,6 +589,7 @@ static int vmw_kms_new_framebuffer_surface(struct 
vmw_private *dev_priv,

vfbs->base.base.dev = dev;
/* XXX get the first 4 from the surface info */
+   vfbs->base.base.format = drm_format_info(pixel_format);
vfbs->base.base.pixel_format = pixel_format;
vfbs->base.base.bits_per_pixel = mode_cmd->bpp;
vfbs->base.base.pitches[0] = mode_cmd->pitch;
@@ -897,6 +898,7 @@ static int vmw_kms_new_framebuffer_dmabuf(struct 
vmw_private *dev_priv,
}

vfbd->base.base.dev = dev;
+   vfbd->base.base.format = drm_format_info(pixel_format);
vfbd->base.base.pixel_format = pixel_format;
vfbd->base.base.bits_per_pixel = mode_cmd->bpp;
vfbd->base.base.pitches[0] = mode_cmd->pitch;
-- 
2.7.4



[PATCH 19/32] drm: Store a pointer to drm_format_info under drm_framebuffer

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

To avoid having to look up the format information struct every time,
let's just store a pointer to it under drm_framebuffer.

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_framebuffer.c| 4 +++-
 drivers/gpu/drm/drm_modeset_helper.c | 1 +
 include/drm/drm_framebuffer.h| 4 
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_framebuffer.c 
b/drivers/gpu/drm/drm_framebuffer.c
index 527220c08f9b..47478678d609 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -632,8 +632,10 @@ int drm_framebuffer_init(struct drm_device *dev, struct 
drm_framebuffer *fb,
int ret;

INIT_LIST_HEAD(>filp_head);
-   if (WARN_ON_ONCE(fb->dev != dev))
+   if (WARN_ON_ONCE(fb->dev != dev)) {
fb->dev = dev;
+   fb->format = drm_format_info(fb->pixel_format);
+   }
fb->funcs = funcs;

ret = drm_mode_object_get_reg(dev, >base, DRM_MODE_OBJECT_FB,
diff --git a/drivers/gpu/drm/drm_modeset_helper.c 
b/drivers/gpu/drm/drm_modeset_helper.c
index 57a319e3f780..1aa5e3bcc8a1 100644
--- a/drivers/gpu/drm/drm_modeset_helper.c
+++ b/drivers/gpu/drm/drm_modeset_helper.c
@@ -91,6 +91,7 @@ void drm_helper_mode_fill_fb_struct(struct drm_device *dev,
}

fb->dev = dev;
+   fb->format = info;
fb->width = mode_cmd->width;
fb->height = mode_cmd->height;
for (i = 0; i < 4; i++) {
diff --git a/include/drm/drm_framebuffer.h b/include/drm/drm_framebuffer.h
index b3141a0e609b..741b3a994d1f 100644
--- a/include/drm/drm_framebuffer.h
+++ b/include/drm/drm_framebuffer.h
@@ -122,6 +122,10 @@ struct drm_framebuffer {
 */
struct drm_mode_object base;
/**
+* @format: framebuffer format information
+*/
+   const struct drm_format_info *format;
+   /**
 * @funcs: framebuffer vfunc table
 */
const struct drm_framebuffer_funcs *funcs;
-- 
2.7.4



[PATCH 18/32] drm: Populate fb->dev from drm_helper_mode_fill_fb_struct()

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Populating fb->dev before drm_framebuffer_init() allows us to use
fb->dev already while validating the framebuffer. Let's have
drm_helper_mode_fill_fb_struct() do that for us.

Also make drm_framebuffer_init() warn us if a different device
pointer is passed to it than was passed to
drm_helper_mode_fill_fb_struct().

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_framebuffer.c| 3 ++-
 drivers/gpu/drm/drm_modeset_helper.c | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_framebuffer.c 
b/drivers/gpu/drm/drm_framebuffer.c
index cbf0c893f426..527220c08f9b 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -632,7 +632,8 @@ int drm_framebuffer_init(struct drm_device *dev, struct 
drm_framebuffer *fb,
int ret;

INIT_LIST_HEAD(>filp_head);
-   fb->dev = dev;
+   if (WARN_ON_ONCE(fb->dev != dev))
+   fb->dev = dev;
fb->funcs = funcs;

ret = drm_mode_object_get_reg(dev, >base, DRM_MODE_OBJECT_FB,
diff --git a/drivers/gpu/drm/drm_modeset_helper.c 
b/drivers/gpu/drm/drm_modeset_helper.c
index 285ffcba0fe8..57a319e3f780 100644
--- a/drivers/gpu/drm/drm_modeset_helper.c
+++ b/drivers/gpu/drm/drm_modeset_helper.c
@@ -90,6 +90,7 @@ void drm_helper_mode_fill_fb_struct(struct drm_device *dev,
fb->bits_per_pixel = info->cpp[0] * 8;
}

+   fb->dev = dev;
fb->width = mode_cmd->width;
fb->height = mode_cmd->height;
for (i = 0; i < 4; i++) {
-- 
2.7.4



[PATCH 17/32] drm/i915: Set fb->dev early on for inherited fbs

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

We want the fbs inherited from the BIOS to be more or less fully working
prior to actually registering them. This will allow us to just pass the
fb to various helper function instead of having to pass all the
different parameters separately.

Cc: intel-gfx at lists.freedesktop.org
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_display.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 12af936a402d..74a638c8de61 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -8704,6 +8704,8 @@ i9xx_get_initial_plane_config(struct intel_crtc *crtc,

fb = _fb->base;

+   fb->dev = dev;
+
if (INTEL_GEN(dev_priv) >= 4) {
if (val & DISPPLANE_TILED) {
plane_config->tiling = I915_TILING_X;
@@ -9734,6 +9736,8 @@ skylake_get_initial_plane_config(struct intel_crtc *crtc,

fb = _fb->base;

+   fb->dev = dev;
+
val = I915_READ(PLANE_CTL(pipe, 0));
if (!(val & PLANE_CTL_ENABLE))
goto error;
@@ -9846,6 +9850,8 @@ ironlake_get_initial_plane_config(struct intel_crtc *crtc,

fb = _fb->base;

+   fb->dev = dev;
+
if (INTEL_GEN(dev_priv) >= 4) {
if (val & DISPPLANE_TILED) {
plane_config->tiling = I915_TILING_X;
-- 
2.7.4



[PATCH 16/32] drm/virtio: Call drm_helper_mode_fill_fb_struct() before drm_framebuffer_init()

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

We want framebuffers to be mostly useable already before
drm_framebuffer_init() get called, and so we will start demanding that
all the interesting format/size/etc. information be filled in before
drm_framebuffer_init(). drm_helper_mode_fill_fb_struct() will do that
for us, so let's make sure it gets called before drm_framebuffer_init().

Cc: Dave Airlie 
Cc: Gerd Hoffmann 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/virtio/virtgpu_display.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_display.c 
b/drivers/gpu/drm/virtio/virtgpu_display.c
index 8b80fdd0e0a8..fad5a1cc5903 100644
--- a/drivers/gpu/drm/virtio/virtgpu_display.c
+++ b/drivers/gpu/drm/virtio/virtgpu_display.c
@@ -88,12 +88,13 @@ virtio_gpu_framebuffer_init(struct drm_device *dev,

bo = gem_to_virtio_gpu_obj(obj);

+   drm_helper_mode_fill_fb_struct(dev, >base, mode_cmd);
+
ret = drm_framebuffer_init(dev, >base, _gpu_fb_funcs);
if (ret) {
vgfb->obj = NULL;
return ret;
}
-   drm_helper_mode_fill_fb_struct(dev, >base, mode_cmd);

spin_lock_init(>dirty_lock);
vgfb->x1 = vgfb->y1 = INT_MAX;
-- 
2.7.4



[PATCH 15/32] drm/qxl: Call drm_helper_mode_fill_fb_struct() before drm_framebuffer_init()

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

We want framebuffers to be mostly useable already before
drm_framebuffer_init() is called, and so we will start demanding that
all the interesting format/size/etc. information be filled in before
drm_framebuffer_init(). drm_helper_mode_fill_fb_struct() will do that
for us, so let's make sure it gets called before drm_framebuffer_init().

Cc: Dave Airlie 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/qxl/qxl_display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/qxl/qxl_display.c 
b/drivers/gpu/drm/qxl/qxl_display.c
index bcbad877ce4f..9e2c92b9d12e 100644
--- a/drivers/gpu/drm/qxl/qxl_display.c
+++ b/drivers/gpu/drm/qxl/qxl_display.c
@@ -579,12 +579,12 @@ qxl_framebuffer_init(struct drm_device *dev,
int ret;

qfb->obj = obj;
+   drm_helper_mode_fill_fb_struct(dev, >base, mode_cmd);
ret = drm_framebuffer_init(dev, >base, funcs);
if (ret) {
qfb->obj = NULL;
return ret;
}
-   drm_helper_mode_fill_fb_struct(dev, >base, mode_cmd);
return 0;
 }

-- 
2.7.4



[PATCH 14/32] drm/vmwgfx: Populate fb->pixel_format

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Stuff something semi-reasonable into fb->pixel_format. I had to guess
as to which formats we should pick. Did I guess correctly?

We can't quite use drm_mode_legacy_fb_format() due to the ARGB1555
vs. XRGB155 mess. However use of 'A' formats should imply per-pixel
alpha blending as far as KMS is concerned so I'm not at all sure we
want to have any 'A' formats exposed as opposed to just 'X' formats.
OTOH vmvgfx doesn't do planes, and so the core won't enforce that
these formats match any list of supported formats, so the choice
shouldn't be super important at this point.

Cc: linux-graphics-maintainer at vmware.com
Cc: Sinclair Yeh 
Cc: Thomas Hellstrom 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index 7d92ab56961b..5788913ca8f9 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -524,6 +524,7 @@ static int vmw_kms_new_framebuffer_surface(struct 
vmw_private *dev_priv,
struct drm_device *dev = dev_priv->dev;
struct vmw_framebuffer_surface *vfbs;
enum SVGA3dSurfaceFormat format;
+   u32 pixel_format;
int ret;

/* 3D is only supported on HWv8 and newer hosts */
@@ -548,17 +549,22 @@ static int vmw_kms_new_framebuffer_surface(struct 
vmw_private *dev_priv,
return -EINVAL;
}

+   /* FIXME 'A' format implies per-pixel alpha blending for KMS */
switch (mode_cmd->depth) {
case 32:
+   pixel_format = DRM_FORMAT_ARGB;
format = SVGA3D_A8R8G8B8;
break;
case 24:
+   pixel_format = DRM_FORMAT_XRGB;
format = SVGA3D_X8R8G8B8;
break;
case 16:
+   pixel_format = DRM_FORMAT_RGB565;
format = SVGA3D_R5G6B5;
break;
case 15:
+   pixel_format = DRM_FORMAT_ARGB1555;
format = SVGA3D_A1R5G5B5;
break;
default:
@@ -582,7 +588,8 @@ static int vmw_kms_new_framebuffer_surface(struct 
vmw_private *dev_priv,
}

vfbs->base.base.dev = dev;
-   /* XXX get the first 3 from the surface info */
+   /* XXX get the first 4 from the surface info */
+   vfbs->base.base.pixel_format = pixel_format;
vfbs->base.base.bits_per_pixel = mode_cmd->bpp;
vfbs->base.base.pitches[0] = mode_cmd->pitch;
vfbs->base.base.depth = mode_cmd->depth;
@@ -834,6 +841,7 @@ static int vmw_kms_new_framebuffer_dmabuf(struct 
vmw_private *dev_priv,
struct drm_device *dev = dev_priv->dev;
struct vmw_framebuffer_dmabuf *vfbd;
unsigned int requested_size;
+   u32 pixel_format;
int ret;

requested_size = mode_cmd->height * mode_cmd->pitch;
@@ -852,6 +860,12 @@ static int vmw_kms_new_framebuffer_dmabuf(struct 
vmw_private *dev_priv,
if (mode_cmd->bpp == 32)
break;

+   /* FIXME 'A' format implies per-pixel alpha blending 
for KMS */
+   if (mode_cmd->depth == 32)
+   pixel_format = DRM_FORMAT_ARGB;
+   else
+   pixel_format = DRM_FORMAT_XRGB;
+
DRM_ERROR("Invalid color depth/bbp: %d %d\n",
  mode_cmd->depth, mode_cmd->bpp);
return -EINVAL;
@@ -861,6 +875,12 @@ static int vmw_kms_new_framebuffer_dmabuf(struct 
vmw_private *dev_priv,
if (mode_cmd->bpp == 16)
break;

+   /* FIXME 'A' format implies per-pixel alpha blending 
for KMS */
+   if (mode_cmd->depth == 16)
+   pixel_format = DRM_FORMAT_RGB565;
+   else
+   pixel_format = DRM_FORMAT_ARGB1555;
+
DRM_ERROR("Invalid color depth/bbp: %d %d\n",
  mode_cmd->depth, mode_cmd->bpp);
return -EINVAL;
@@ -877,6 +897,7 @@ static int vmw_kms_new_framebuffer_dmabuf(struct 
vmw_private *dev_priv,
}

vfbd->base.base.dev = dev;
+   vfbd->base.base.pixel_format = pixel_format;
vfbd->base.base.bits_per_pixel = mode_cmd->bpp;
vfbd->base.base.pitches[0] = mode_cmd->pitch;
vfbd->base.base.depth = mode_cmd->depth;
-- 
2.7.4



[PATCH 13/32] drm: Pass 'dev' to drm_helper_mode_fill_fb_struct()

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Pass the drm_device to drm_helper_mode_fill_fb_struct() so that we can
populate fb->dev early. Will make it easier to use the fb before we
register it.

@@
identifier fb, mode_cmd;
@@
 void drm_helper_mode_fill_fb_struct(
+struct drm_device *dev,
 struct drm_framebuffer *fb,
 const struct drm_mode_fb_cmd2 *mode_cmd
 );

@@
identifier fb, mode_cmd;
@@
 void drm_helper_mode_fill_fb_struct(
+struct drm_device *dev,
 struct drm_framebuffer *fb,
 const struct drm_mode_fb_cmd2 *mode_cmd
 )
{ ... }

@@
function func;
identifier dev;
expression E1, E2;
@@
func(struct drm_device *dev, ...)
{
 ...
 drm_helper_mode_fill_fb_struct(
+   dev,
E1, E2);
 ...
}

@@
expression E1, E2;
@@
 drm_helper_mode_fill_fb_struct(
+   dev,
E1, E2);

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 2 +-
 drivers/gpu/drm/armada/armada_fb.c  | 2 +-
 drivers/gpu/drm/ast/ast_main.c  | 2 +-
 drivers/gpu/drm/bochs/bochs_mm.c| 2 +-
 drivers/gpu/drm/cirrus/cirrus_main.c| 2 +-
 drivers/gpu/drm/drm_fb_cma_helper.c | 2 +-
 drivers/gpu/drm/drm_modeset_helper.c| 3 ++-
 drivers/gpu/drm/exynos/exynos_drm_fb.c  | 2 +-
 drivers/gpu/drm/gma500/framebuffer.c| 2 +-
 drivers/gpu/drm/i915/intel_display.c| 2 +-
 drivers/gpu/drm/mediatek/mtk_drm_fb.c   | 2 +-
 drivers/gpu/drm/mgag200/mgag200_main.c  | 2 +-
 drivers/gpu/drm/msm/msm_fb.c| 2 +-
 drivers/gpu/drm/nouveau/nouveau_display.c   | 2 +-
 drivers/gpu/drm/omapdrm/omap_fb.c   | 2 +-
 drivers/gpu/drm/qxl/qxl_display.c   | 2 +-
 drivers/gpu/drm/radeon/radeon_display.c | 2 +-
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c  | 2 +-
 drivers/gpu/drm/tegra/fb.c  | 2 +-
 drivers/gpu/drm/udl/udl_fb.c| 2 +-
 drivers/gpu/drm/virtio/virtgpu_display.c| 2 +-
 include/drm/drm_modeset_helper.h| 3 ++-
 22 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
index 741144fcc7bc..d492cf84ddc1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
@@ -508,7 +508,7 @@ amdgpu_framebuffer_init(struct drm_device *dev,
 {
int ret;
rfb->obj = obj;
-   drm_helper_mode_fill_fb_struct(>base, mode_cmd);
+   drm_helper_mode_fill_fb_struct(dev, >base, mode_cmd);
ret = drm_framebuffer_init(dev, >base, _fb_funcs);
if (ret) {
rfb->obj = NULL;
diff --git a/drivers/gpu/drm/armada/armada_fb.c 
b/drivers/gpu/drm/armada/armada_fb.c
index f03c212b754d..2a7eb6817c36 100644
--- a/drivers/gpu/drm/armada/armada_fb.c
+++ b/drivers/gpu/drm/armada/armada_fb.c
@@ -81,7 +81,7 @@ struct armada_framebuffer *armada_framebuffer_create(struct 
drm_device *dev,
dfb->mod = config;
dfb->obj = obj;

-   drm_helper_mode_fill_fb_struct(>fb, mode);
+   drm_helper_mode_fill_fb_struct(dev, >fb, mode);

ret = drm_framebuffer_init(dev, >fb, _fb_funcs);
if (ret) {
diff --git a/drivers/gpu/drm/ast/ast_main.c b/drivers/gpu/drm/ast/ast_main.c
index 904beaa932d0..d85af0ff2653 100644
--- a/drivers/gpu/drm/ast/ast_main.c
+++ b/drivers/gpu/drm/ast/ast_main.c
@@ -313,7 +313,7 @@ int ast_framebuffer_init(struct drm_device *dev,
 {
int ret;

-   drm_helper_mode_fill_fb_struct(_fb->base, mode_cmd);
+   drm_helper_mode_fill_fb_struct(dev, _fb->base, mode_cmd);
ast_fb->obj = obj;
ret = drm_framebuffer_init(dev, _fb->base, _fb_funcs);
if (ret) {
diff --git a/drivers/gpu/drm/bochs/bochs_mm.c b/drivers/gpu/drm/bochs/bochs_mm.c
index 099a3c688c26..ceb1fecf02dd 100644
--- a/drivers/gpu/drm/bochs/bochs_mm.c
+++ b/drivers/gpu/drm/bochs/bochs_mm.c
@@ -484,7 +484,7 @@ int bochs_framebuffer_init(struct drm_device *dev,
 {
int ret;

-   drm_helper_mode_fill_fb_struct(>base, mode_cmd);
+   drm_helper_mode_fill_fb_struct(dev, >base, mode_cmd);
gfb->obj = obj;
ret = drm_framebuffer_init(dev, >base, _fb_funcs);
if (ret) {
diff --git a/drivers/gpu/drm/cirrus/cirrus_main.c 
b/drivers/gpu/drm/cirrus/cirrus_main.c
index 2c3c0d4072ce..52d901fa8687 100644
--- a/drivers/gpu/drm/cirrus/cirrus_main.c
+++ b/drivers/gpu/drm/cirrus/cirrus_main.c
@@ -34,7 +34,7 @@ int cirrus_framebuffer_init(struct drm_device *dev,
 {
int ret;

-   drm_helper_mode_fill_fb_struct(>

[PATCH 12/32] drm/vmwgfx: Populate fb->dev before drm_framebuffer_init()

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

drm_framebuffer_init() will start to check that fb->dev is already
populated, so let's to that manually since vmwgfx isn't using
drm_helper_mode_fill_fb_struct().

Cc: linux-graphics-maintainer at vmware.com
Cc: Sinclair Yeh 
Cc: Thomas Hellstrom 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index e3f68cc9bb4b..7d92ab56961b 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -581,6 +581,7 @@ static int vmw_kms_new_framebuffer_surface(struct 
vmw_private *dev_priv,
goto out_err1;
}

+   vfbs->base.base.dev = dev;
/* XXX get the first 3 from the surface info */
vfbs->base.base.bits_per_pixel = mode_cmd->bpp;
vfbs->base.base.pitches[0] = mode_cmd->pitch;
@@ -875,6 +876,7 @@ static int vmw_kms_new_framebuffer_dmabuf(struct 
vmw_private *dev_priv,
goto out_err1;
}

+   vfbd->base.base.dev = dev;
vfbd->base.base.bits_per_pixel = mode_cmd->bpp;
vfbd->base.base.pitches[0] = mode_cmd->pitch;
vfbd->base.base.depth = mode_cmd->depth;
-- 
2.7.4



[PATCH 11/32] drm/nouveau: Add local 'fb' variables

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add a local 'fb' variable to a few places to get rid of the
'crtc->primary->fb' stuff. Looks neater and helps me with my poor
coccinelle skills later.

Cc: Ben Skeggs 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/nouveau/dispnv04/crtc.c | 5 +++--
 drivers/gpu/drm/nouveau/dispnv04/dfp.c  | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/dispnv04/crtc.c 
b/drivers/gpu/drm/nouveau/dispnv04/crtc.c
index 7c6c66f177df..8286b8ffe109 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/crtc.c
+++ b/drivers/gpu/drm/nouveau/dispnv04/crtc.c
@@ -460,6 +460,7 @@ nv_crtc_mode_set_regs(struct drm_crtc *crtc, struct 
drm_display_mode * mode)
struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
struct nv04_crtc_reg *regp = 
_display(dev)->mode_reg.crtc_reg[nv_crtc->index];
struct nv04_crtc_reg *savep = 
_display(dev)->saved_reg.crtc_reg[nv_crtc->index];
+   const struct drm_framebuffer *fb = crtc->primary->fb;
struct drm_encoder *encoder;
bool lvds_output = false, tmds_output = false, tv_output = false,
off_chip_digital = false;
@@ -569,7 +570,7 @@ nv_crtc_mode_set_regs(struct drm_crtc *crtc, struct 
drm_display_mode * mode)
regp->CRTC[NV_CIO_CRE_86] = 0x1;
}

-   regp->CRTC[NV_CIO_CRE_PIXEL_INDEX] = (crtc->primary->fb->depth + 1) / 8;
+   regp->CRTC[NV_CIO_CRE_PIXEL_INDEX] = (fb->depth + 1) / 8;
/* Enable slaved mode (called MODE_TV in nv4ref.h) */
if (lvds_output || tmds_output || tv_output)
regp->CRTC[NV_CIO_CRE_PIXEL_INDEX] |= (1 << 7);
@@ -583,7 +584,7 @@ nv_crtc_mode_set_regs(struct drm_crtc *crtc, struct 
drm_display_mode * mode)
regp->ramdac_gen_ctrl = NV_PRAMDAC_GENERAL_CONTROL_BPC_8BITS |
NV_PRAMDAC_GENERAL_CONTROL_VGA_STATE_SEL |
NV_PRAMDAC_GENERAL_CONTROL_PIXMIX_ON;
-   if (crtc->primary->fb->depth == 16)
+   if (fb->depth == 16)
regp->ramdac_gen_ctrl |= 
NV_PRAMDAC_GENERAL_CONTROL_ALT_MODE_SEL;
if (drm->device.info.chipset >= 0x11)
regp->ramdac_gen_ctrl |= NV_PRAMDAC_GENERAL_CONTROL_PIPE_LONG;
diff --git a/drivers/gpu/drm/nouveau/dispnv04/dfp.c 
b/drivers/gpu/drm/nouveau/dispnv04/dfp.c
index c2947ef7d4fc..945607b3cd41 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/dfp.c
+++ b/drivers/gpu/drm/nouveau/dispnv04/dfp.c
@@ -290,6 +290,7 @@ static void nv04_dfp_mode_set(struct drm_encoder *encoder,
struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
struct drm_display_mode *output_mode = _encoder->mode;
struct drm_connector *connector = _connector->base;
+   const struct drm_framebuffer *fb = encoder->crtc->primary->fb;
uint32_t mode_ratio, panel_ratio;

NV_DEBUG(drm, "Output mode on CRTC %d:\n", nv_crtc->index);
@@ -415,7 +416,7 @@ static void nv04_dfp_mode_set(struct drm_encoder *encoder,
/* Output property. */
if ((nv_connector->dithering_mode == DITHERING_MODE_ON) ||
(nv_connector->dithering_mode == DITHERING_MODE_AUTO &&
-encoder->crtc->primary->fb->depth > connector->display_info.bpc * 
3)) {
+fb->depth > connector->display_info.bpc * 3)) {
if (drm->device.info.chipset == 0x11)
regp->dither = savep->dither | 0x0001;
else {
-- 
2.7.4



[PATCH 10/32] drm/nouveau: Fix crtc->primary->fb vs. drm_fb fail

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

So it looks like the code is trying to pick between the passed in fb and
crtc->primary->fb based on that funky 'bool atomic'. But later it will
mix uses of both drm_fb (which was picked by the aforementioned logic)
and crtc->primary->fb. So looks like a bug to me. Let's make it use
drm_fb only.

Cc: Ben Skeggs 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/nouveau/dispnv04/crtc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/dispnv04/crtc.c 
b/drivers/gpu/drm/nouveau/dispnv04/crtc.c
index 59d1d1c5de5f..7c6c66f177df 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/crtc.c
+++ b/drivers/gpu/drm/nouveau/dispnv04/crtc.c
@@ -854,9 +854,9 @@ nv04_crtc_do_mode_set_base(struct drm_crtc *crtc,

/* Update the framebuffer format. */
regp->CRTC[NV_CIO_CRE_PIXEL_INDEX] &= ~3;
-   regp->CRTC[NV_CIO_CRE_PIXEL_INDEX] |= (crtc->primary->fb->depth + 1) / 
8;
+   regp->CRTC[NV_CIO_CRE_PIXEL_INDEX] |= (drm_fb->depth + 1) / 8;
regp->ramdac_gen_ctrl &= ~NV_PRAMDAC_GENERAL_CONTROL_ALT_MODE_SEL;
-   if (crtc->primary->fb->depth == 16)
+   if (drm_fb->depth == 16)
regp->ramdac_gen_ctrl |= 
NV_PRAMDAC_GENERAL_CONTROL_ALT_MODE_SEL;
crtc_wr_cio_state(crtc, regp, NV_CIO_CRE_PIXEL_INDEX);
NVWriteRAMDAC(dev, nv_crtc->index, NV_PRAMDAC_GENERAL_CONTROL,
-- 
2.7.4



[PATCH 09/32] drm/arm: Add local 'fb' variables

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add a local 'fb' variable to a few places to get rid of the
'crtc->primary->fb' stuff. Looks neater and helps me with my ppor
coccinelle skills later.

In some places the local variable was already there, just not used
consistently.

Cc: Liviu Dudau 
Cc: Brian Starkey 
Cc: Mali DP Maintainers 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/arm/hdlcd_crtc.c| 18 ++
 drivers/gpu/drm/arm/malidp_planes.c |  6 +++---
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/arm/hdlcd_crtc.c b/drivers/gpu/drm/arm/hdlcd_crtc.c
index bbaa55add2d2..8a0fee03aa39 100644
--- a/drivers/gpu/drm/arm/hdlcd_crtc.c
+++ b/drivers/gpu/drm/arm/hdlcd_crtc.c
@@ -60,11 +60,12 @@ static int hdlcd_set_pxl_fmt(struct drm_crtc *crtc)
 {
unsigned int btpp;
struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc);
+   const struct drm_framebuffer *fb = crtc->primary->state->fb;
uint32_t pixel_format;
struct simplefb_format *format = NULL;
int i;

-   pixel_format = crtc->primary->state->fb->pixel_format;
+   pixel_format = fb->pixel_format;

for (i = 0; i < ARRAY_SIZE(supported_formats); i++) {
if (supported_formats[i].fourcc == pixel_format)
@@ -221,27 +222,28 @@ static int hdlcd_plane_atomic_check(struct drm_plane 
*plane,
 static void hdlcd_plane_atomic_update(struct drm_plane *plane,
  struct drm_plane_state *state)
 {
+   struct drm_framebuffer *fb = plane->state->fb;
struct hdlcd_drm_private *hdlcd;
struct drm_gem_cma_object *gem;
u32 src_w, src_h, dest_w, dest_h;
dma_addr_t scanout_start;

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

src_w = plane->state->src_w >> 16;
src_h = plane->state->src_h >> 16;
dest_w = plane->state->crtc_w;
dest_h = plane->state->crtc_h;
-   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] +
+   gem = drm_fb_cma_get_gem_obj(fb, 0);
+   scanout_start = gem->paddr + fb->offsets[0] +
+   plane->state->crtc_y * fb->pitches[0] +
plane->state->crtc_x *
-   drm_format_plane_cpp(plane->state->fb->pixel_format, 0);
+   drm_format_plane_cpp(fb->pixel_format, 0);

hdlcd = plane->dev->dev_private;
-   hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_LENGTH, 
plane->state->fb->pitches[0]);
-   hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_PITCH, 
plane->state->fb->pitches[0]);
+   hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_LENGTH, fb->pitches[0]);
+   hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_PITCH, fb->pitches[0]);
hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_COUNT, dest_h - 1);
hdlcd_write(hdlcd, HDLCD_REG_FB_BASE, scanout_start);
 }
diff --git a/drivers/gpu/drm/arm/malidp_planes.c 
b/drivers/gpu/drm/arm/malidp_planes.c
index 63eec8f37cfc..ee7f7663a307 100644
--- a/drivers/gpu/drm/arm/malidp_planes.c
+++ b/drivers/gpu/drm/arm/malidp_planes.c
@@ -137,8 +137,8 @@ static int malidp_de_plane_check(struct drm_plane *plane,

/* packed RGB888 / BGR888 can't be rotated or flipped */
if (state->rotation != DRM_ROTATE_0 &&
-   (state->fb->pixel_format == DRM_FORMAT_RGB888 ||
-state->fb->pixel_format == DRM_FORMAT_BGR888))
+   (fb->pixel_format == DRM_FORMAT_RGB888 ||
+fb->pixel_format == DRM_FORMAT_BGR888))
return -EINVAL;

ms->rotmem_size = 0;
@@ -147,7 +147,7 @@ static int malidp_de_plane_check(struct drm_plane *plane,

val = mp->hwdev->rotmem_required(mp->hwdev, state->crtc_h,
 state->crtc_w,
-state->fb->pixel_format);
+fb->pixel_format);
if (val < 0)
return val;

-- 
2.7.4



[PATCH 08/32] drm/arcpgu: Add local 'fb' variables

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add a local 'fb' variable to a few places to get rid of the
'crtc->primary->fb' stuff. Looks neater and helps me with my ppor
coccinelle skills later.

Cc: Alexey Brodkin 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/arc/arcpgu_crtc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/arc/arcpgu_crtc.c 
b/drivers/gpu/drm/arc/arcpgu_crtc.c
index 7130b044b004..5c26c5f126a3 100644
--- a/drivers/gpu/drm/arc/arcpgu_crtc.c
+++ b/drivers/gpu/drm/arc/arcpgu_crtc.c
@@ -35,7 +35,8 @@ static struct simplefb_format supported_formats[] = {
 static void arc_pgu_set_pxl_fmt(struct drm_crtc *crtc)
 {
struct arcpgu_drm_private *arcpgu = crtc_to_arcpgu_priv(crtc);
-   uint32_t pixel_format = crtc->primary->state->fb->pixel_format;
+   const struct drm_framebuffer *fb = crtc->primary->state->fb;
+   uint32_t pixel_format = fb->pixel_format;
struct simplefb_format *format = NULL;
int i;

-- 
2.7.4



[PATCH 07/32] drm/cirrus: Add some local 'fb' variables

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add a local 'fb' variable to a few places to get rid of the
'crtc->primary->fb' stuff. Looks neater and helps me with my poor
coccinelle skills later.

Cc: Dave Airlie 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/cirrus/cirrus_mode.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/cirrus/cirrus_mode.c 
b/drivers/gpu/drm/cirrus/cirrus_mode.c
index 17c915d9a03e..f2297acae235 100644
--- a/drivers/gpu/drm/cirrus/cirrus_mode.c
+++ b/drivers/gpu/drm/cirrus/cirrus_mode.c
@@ -185,6 +185,7 @@ static int cirrus_crtc_mode_set(struct drm_crtc *crtc,
 {
struct drm_device *dev = crtc->dev;
struct cirrus_device *cdev = dev->dev_private;
+   const struct drm_framebuffer *fb = crtc->primary->fb;
int hsyncstart, hsyncend, htotal, hdispend;
int vtotal, vdispend;
int tmp;
@@ -257,7 +258,7 @@ static int cirrus_crtc_mode_set(struct drm_crtc *crtc,
sr07 = RREG8(SEQ_DATA);
sr07 &= 0xe0;
hdr = 0;
-   switch (crtc->primary->fb->bits_per_pixel) {
+   switch (fb->bits_per_pixel) {
case 8:
sr07 |= 0x11;
break;
@@ -280,13 +281,13 @@ static int cirrus_crtc_mode_set(struct drm_crtc *crtc,
WREG_SEQ(0x7, sr07);

/* Program the pitch */
-   tmp = crtc->primary->fb->pitches[0] / 8;
+   tmp = fb->pitches[0] / 8;
WREG_CRT(VGA_CRTC_OFFSET, tmp);

/* Enable extended blanking and pitch bits, and enable full memory */
tmp = 0x22;
-   tmp |= (crtc->primary->fb->pitches[0] >> 7) & 0x10;
-   tmp |= (crtc->primary->fb->pitches[0] >> 6) & 0x40;
+   tmp |= (fb->pitches[0] >> 7) & 0x10;
+   tmp |= (fb->pitches[0] >> 6) & 0x40;
WREG_CRT(0x1b, tmp);

/* Enable high-colour modes */
-- 
2.7.4



[PATCH 06/32] drm/gma500: Add some local 'fb' variables

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add a local 'fb' variable to a few places to get rid of the
'crtc->primary->fb' stuff. Looks neater and helps me with my poor
coccinelle skills later.

Cc: Patrik Jakobsson 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/gma500/gma_display.c | 13 +++--
 drivers/gpu/drm/gma500/mdfld_intel_display.c | 15 ---
 drivers/gpu/drm/gma500/oaktrail_crtc.c   | 13 +++--
 3 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/gma500/gma_display.c 
b/drivers/gpu/drm/gma500/gma_display.c
index 1a1cf7a3b5ef..05b9a4ceb58d 100644
--- a/drivers/gpu/drm/gma500/gma_display.c
+++ b/drivers/gpu/drm/gma500/gma_display.c
@@ -59,7 +59,8 @@ int gma_pipe_set_base(struct drm_crtc *crtc, int x, int y,
struct drm_device *dev = crtc->dev;
struct drm_psb_private *dev_priv = dev->dev_private;
struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
-   struct psb_framebuffer *psbfb = to_psb_fb(crtc->primary->fb);
+   struct drm_framebuffer *fb = crtc->primary->fb;
+   struct psb_framebuffer *psbfb = to_psb_fb(fb);
int pipe = gma_crtc->pipe;
const struct psb_offset *map = _priv->regmap[pipe];
unsigned long start, offset;
@@ -70,7 +71,7 @@ int gma_pipe_set_base(struct drm_crtc *crtc, int x, int y,
return 0;

/* no fb bound */
-   if (!crtc->primary->fb) {
+   if (!fb) {
dev_err(dev->dev, "No FB bound\n");
goto gma_pipe_cleaner;
}
@@ -81,19 +82,19 @@ int gma_pipe_set_base(struct drm_crtc *crtc, int x, int y,
if (ret < 0)
goto gma_pipe_set_base_exit;
start = psbfb->gtt->offset;
-   offset = y * crtc->primary->fb->pitches[0] + x * 
(crtc->primary->fb->bits_per_pixel / 8);
+   offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);

-   REG_WRITE(map->stride, crtc->primary->fb->pitches[0]);
+   REG_WRITE(map->stride, fb->pitches[0]);

dspcntr = REG_READ(map->cntr);
dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;

-   switch (crtc->primary->fb->bits_per_pixel) {
+   switch (fb->bits_per_pixel) {
case 8:
dspcntr |= DISPPLANE_8BPP;
break;
case 16:
-   if (crtc->primary->fb->depth == 15)
+   if (fb->depth == 15)
dspcntr |= DISPPLANE_15_16BPP;
else
dspcntr |= DISPPLANE_16BPP;
diff --git a/drivers/gpu/drm/gma500/mdfld_intel_display.c 
b/drivers/gpu/drm/gma500/mdfld_intel_display.c
index 92e3f93ee682..e80895285e94 100644
--- a/drivers/gpu/drm/gma500/mdfld_intel_display.c
+++ b/drivers/gpu/drm/gma500/mdfld_intel_display.c
@@ -165,8 +165,9 @@ static int mdfld__intel_pipe_set_base(struct drm_crtc 
*crtc, int x, int y,
 {
struct drm_device *dev = crtc->dev;
struct drm_psb_private *dev_priv = dev->dev_private;
+   struct drm_framebuffer *fb = crtc->primary->fb;
struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
-   struct psb_framebuffer *psbfb = to_psb_fb(crtc->primary->fb);
+   struct psb_framebuffer *psbfb = to_psb_fb(fb);
int pipe = gma_crtc->pipe;
const struct psb_offset *map = _priv->regmap[pipe];
unsigned long start, offset;
@@ -178,12 +179,12 @@ static int mdfld__intel_pipe_set_base(struct drm_crtc 
*crtc, int x, int y,
dev_dbg(dev->dev, "pipe = 0x%x.\n", pipe);

/* no fb bound */
-   if (!crtc->primary->fb) {
+   if (!fb) {
dev_dbg(dev->dev, "No FB bound\n");
return 0;
}

-   ret = check_fb(crtc->primary->fb);
+   ret = check_fb(fb);
if (ret)
return ret;

@@ -196,18 +197,18 @@ static int mdfld__intel_pipe_set_base(struct drm_crtc 
*crtc, int x, int y,
return 0;

start = psbfb->gtt->offset;
-   offset = y * crtc->primary->fb->pitches[0] + x * 
(crtc->primary->fb->bits_per_pixel / 8);
+   offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);

-   REG_WRITE(map->stride, crtc->primary->fb->pitches[0]);
+   REG_WRITE(map->stride, fb->pitches[0]);
dspcntr = REG_READ(map->cntr);
dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;

-   switch (crtc->primary->fb->bits_per_pixel) {
+   switch (fb->bits_per_pixel) {
case 8:
dspcntr |= DISPPLANE_8BPP;
break;
case 16:
-   if (crtc->primary->fb->depth == 15)
+   if (fb->depth == 15)
dspcntr |= DISPPLANE_15_16BPP;
else
dspcntr |= DISPPLANE_16BPP;
diff -

[PATCH 05/32] drm/ast: Add local 'fb' variables

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add a local 'fb' variable to a few places to get rid of the
'crtc->primary->fb' stuff. Looks neater and helps me with my poor
coccinelle skills later.

Cc: Dave Airlie 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/ast/ast_mode.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
index 5957c3e659fe..deb3684ccaf8 100644
--- a/drivers/gpu/drm/ast/ast_mode.c
+++ b/drivers/gpu/drm/ast/ast_mode.c
@@ -79,12 +79,13 @@ static bool ast_get_vbios_mode_info(struct drm_crtc *crtc, 
struct drm_display_mo
struct ast_vbios_mode_info *vbios_mode)
 {
struct ast_private *ast = crtc->dev->dev_private;
+   const struct drm_framebuffer *fb = crtc->primary->fb;
u32 refresh_rate_index = 0, mode_id, color_index, refresh_rate;
u32 hborder, vborder;
bool check_sync;
struct ast_vbios_enhtable *best = NULL;

-   switch (crtc->primary->fb->bits_per_pixel) {
+   switch (fb->bits_per_pixel) {
case 8:
vbios_mode->std_table = _stdtable[VGAModeIndex];
color_index = VGAModeIndex - 1;
@@ -207,7 +208,7 @@ static bool ast_get_vbios_mode_info(struct drm_crtc *crtc, 
struct drm_display_mo
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x91, 0x00);
if (vbios_mode->enh_table->flags & NewModeInfo) {
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x91, 0xa8);
-   ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x92, 
crtc->primary->fb->bits_per_pixel);
+   ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x92, 
fb->bits_per_pixel);
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x93, 
adjusted_mode->clock / 1000);
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x94, 
adjusted_mode->crtc_hdisplay);
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x95, 
adjusted_mode->crtc_hdisplay >> 8);
@@ -369,10 +370,11 @@ static void ast_set_crtc_reg(struct drm_crtc *crtc, 
struct drm_display_mode *mod
 static void ast_set_offset_reg(struct drm_crtc *crtc)
 {
struct ast_private *ast = crtc->dev->dev_private;
+   const struct drm_framebuffer *fb = crtc->primary->fb;

u16 offset;

-   offset = crtc->primary->fb->pitches[0] >> 3;
+   offset = fb->pitches[0] >> 3;
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x13, (offset & 0xff));
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xb0, (offset >> 8) & 0x3f);
 }
@@ -395,9 +397,10 @@ static void ast_set_ext_reg(struct drm_crtc *crtc, struct 
drm_display_mode *mode
 struct ast_vbios_mode_info *vbios_mode)
 {
struct ast_private *ast = crtc->dev->dev_private;
+   const struct drm_framebuffer *fb = crtc->primary->fb;
u8 jregA0 = 0, jregA3 = 0, jregA8 = 0;

-   switch (crtc->primary->fb->bits_per_pixel) {
+   switch (fb->bits_per_pixel) {
case 8:
jregA0 = 0x70;
jregA3 = 0x01;
@@ -452,7 +455,9 @@ static void ast_set_sync_reg(struct drm_device *dev, struct 
drm_display_mode *mo
 static bool ast_set_dac_reg(struct drm_crtc *crtc, struct drm_display_mode 
*mode,
 struct ast_vbios_mode_info *vbios_mode)
 {
-   switch (crtc->primary->fb->bits_per_pixel) {
+   const struct drm_framebuffer *fb = crtc->primary->fb;
+
+   switch (fb->bits_per_pixel) {
case 8:
break;
default:
-- 
2.7.4



[PATCH 04/32] drm/mgag200: Add local 'fb' variable

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add a local 'fb' variable to a few places to get rid of the
'crtc->primary->fb' stuff. Looks neater and helps me with my poor
coccinelle skills later.

Cc: Dave Airlie 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/mgag200/mgag200_mode.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c 
b/drivers/gpu/drm/mgag200/mgag200_mode.c
index 6b21cb27e1cc..bdac288ab16d 100644
--- a/drivers/gpu/drm/mgag200/mgag200_mode.c
+++ b/drivers/gpu/drm/mgag200/mgag200_mode.c
@@ -880,6 +880,7 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc,
 {
struct drm_device *dev = crtc->dev;
struct mga_device *mdev = dev->dev_private;
+   const struct drm_framebuffer *fb = crtc->primary->fb;
int hdisplay, hsyncstart, hsyncend, htotal;
int vdisplay, vsyncstart, vsyncend, vtotal;
int pitch;
@@ -902,7 +903,7 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc,
/* 0x48: */0,0,0,0,0,0,0,0
};

-   bppshift = mdev->bpp_shifts[(crtc->primary->fb->bits_per_pixel >> 3) - 
1];
+   bppshift = mdev->bpp_shifts[(fb->bits_per_pixel >> 3) - 1];

switch (mdev->type) {
case G200_SE_A:
@@ -941,12 +942,12 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc,
break;
}

-   switch (crtc->primary->fb->bits_per_pixel) {
+   switch (fb->bits_per_pixel) {
case 8:
dacvalue[MGA1064_MUL_CTL] = MGA1064_MUL_CTL_8bits;
break;
case 16:
-   if (crtc->primary->fb->depth == 15)
+   if (fb->depth == 15)
dacvalue[MGA1064_MUL_CTL] = MGA1064_MUL_CTL_15bits;
else
dacvalue[MGA1064_MUL_CTL] = MGA1064_MUL_CTL_16bits;
@@ -997,8 +998,8 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc,
WREG_SEQ(3, 0);
WREG_SEQ(4, 0xe);

-   pitch = crtc->primary->fb->pitches[0] / 
(crtc->primary->fb->bits_per_pixel / 8);
-   if (crtc->primary->fb->bits_per_pixel == 24)
+   pitch = fb->pitches[0] / (fb->bits_per_pixel / 8);
+   if (fb->bits_per_pixel == 24)
pitch = (pitch * 3) >> (4 - bppshift);
else
pitch = pitch >> (4 - bppshift);
@@ -1075,7 +1076,7 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc,
((vdisplay & 0xc00) >> 7) |
((vsyncstart & 0xc00) >> 5) |
((vdisplay & 0x400) >> 3);
-   if (crtc->primary->fb->bits_per_pixel == 24)
+   if (fb->bits_per_pixel == 24)
ext_vga[3] = (((1 << bppshift) * 3) - 1) | 0x80;
else
ext_vga[3] = ((1 << bppshift) - 1) | 0x80;
@@ -1138,9 +1139,9 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc,
u32 bpp;
u32 mb;

-   if (crtc->primary->fb->bits_per_pixel > 16)
+   if (fb->bits_per_pixel > 16)
bpp = 32;
-   else if (crtc->primary->fb->bits_per_pixel > 8)
+   else if (fb->bits_per_pixel > 8)
bpp = 16;
else
bpp = 8;
-- 
2.7.4



[PATCH 03/32] drm/radeon: Use DIV_ROUND_UP()

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Use DIV_ROUND_UP() instead of hand rolling it. Just a drive-by change.

Cc: Alex Deucher 
Cc: "Christian König" 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/radeon/radeon_legacy_crtc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_legacy_crtc.c 
b/drivers/gpu/drm/radeon/radeon_legacy_crtc.c
index bb5346812de4..31c03e32a6b5 100644
--- a/drivers/gpu/drm/radeon/radeon_legacy_crtc.c
+++ b/drivers/gpu/drm/radeon/radeon_legacy_crtc.c
@@ -477,9 +477,8 @@ int radeon_crtc_do_set_base(struct drm_crtc *crtc,
crtc_offset_cntl = 0;

pitch_pixels = target_fb->pitches[0] / (target_fb->bits_per_pixel / 8);
-   crtc_pitch  = (((pitch_pixels * target_fb->bits_per_pixel) +
-   ((target_fb->bits_per_pixel * 8) - 1)) /
-  (target_fb->bits_per_pixel * 8));
+   crtc_pitch = DIV_ROUND_UP(pitch_pixels * target_fb->bits_per_pixel,
+ target_fb->bits_per_pixel * 8);
crtc_pitch |= crtc_pitch << 16;

crtc_offset_cntl |= RADEON_CRTC_GUI_TRIG_OFFSET_LEFT_EN;
-- 
2.7.4



[PATCH 02/32] drm/radeon: Add local 'fb' variables

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add a local 'fb' variable to a few places to get rid of the
'crtc->primary->fb' stuff. Looks neater and helps me with my poor
coccinelle skills later.

Cc: Alex Deucher 
Cc: "Christian König" 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/radeon/r100.c   | 10 --
 drivers/gpu/drm/radeon/radeon_legacy_crtc.c |  3 ++-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c
index f5e84f4b58e6..984b35f43554 100644
--- a/drivers/gpu/drm/radeon/r100.c
+++ b/drivers/gpu/drm/radeon/r100.c
@@ -3225,13 +3225,19 @@ void r100_bandwidth_update(struct radeon_device *rdev)
radeon_update_display_priority(rdev);

if (rdev->mode_info.crtcs[0]->base.enabled) {
+   const struct drm_framebuffer *fb =
+   rdev->mode_info.crtcs[0]->base.primary->fb;
+
mode1 = >mode_info.crtcs[0]->base.mode;
-   pixel_bytes1 = 
rdev->mode_info.crtcs[0]->base.primary->fb->bits_per_pixel / 8;
+   pixel_bytes1 = fb->bits_per_pixel / 8;
}
if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
if (rdev->mode_info.crtcs[1]->base.enabled) {
+   const struct drm_framebuffer *fb =
+   rdev->mode_info.crtcs[1]->base.primary->fb;
+
mode2 = >mode_info.crtcs[1]->base.mode;
-   pixel_bytes2 = 
rdev->mode_info.crtcs[1]->base.primary->fb->bits_per_pixel / 8;
+   pixel_bytes2 = fb->bits_per_pixel / 8;
}
}

diff --git a/drivers/gpu/drm/radeon/radeon_legacy_crtc.c 
b/drivers/gpu/drm/radeon/radeon_legacy_crtc.c
index d0de4022fff9..bb5346812de4 100644
--- a/drivers/gpu/drm/radeon/radeon_legacy_crtc.c
+++ b/drivers/gpu/drm/radeon/radeon_legacy_crtc.c
@@ -579,6 +579,7 @@ static bool radeon_set_crtc_timing(struct drm_crtc *crtc, 
struct drm_display_mod
struct drm_device *dev = crtc->dev;
struct radeon_device *rdev = dev->dev_private;
struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
+   const struct drm_framebuffer *fb = crtc->primary->fb;
struct drm_encoder *encoder;
int format;
int hsync_start;
@@ -602,7 +603,7 @@ static bool radeon_set_crtc_timing(struct drm_crtc *crtc, 
struct drm_display_mod
}
}

-   switch (crtc->primary->fb->bits_per_pixel) {
+   switch (fb->bits_per_pixel) {
case 8:
format = 2;
break;
-- 
2.7.4



[PATCH 01/32] drm/i915: Add local 'fb' variables

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Add a local 'fb' variable to a few places to get rid of the
'crtc->primary->fb' stuff. Looks neater and helps me with my poor
coccinelle skills later.

While at it switch over to using the pixel format rather than
depth+bpp.

Cc: intel-gfx at lists.freedesktop.org
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_overlay.c | 26 --
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_overlay.c 
b/drivers/gpu/drm/i915/intel_overlay.c
index fd0e4dac7cc1..ce3667c18e18 100644
--- a/drivers/gpu/drm/i915/intel_overlay.c
+++ b/drivers/gpu/drm/i915/intel_overlay.c
@@ -658,6 +658,8 @@ static bool update_scaling_factors(struct intel_overlay 
*overlay,
 static void update_colorkey(struct intel_overlay *overlay,
struct overlay_registers __iomem *regs)
 {
+   const struct drm_framebuffer *fb =
+   overlay->crtc->base.primary->fb;
u32 key = overlay->color_key;
u32 flags;

@@ -665,24 +667,20 @@ static void update_colorkey(struct intel_overlay *overlay,
if (overlay->color_key_enabled)
flags |= DST_KEY_ENABLE;

-   switch (overlay->crtc->base.primary->fb->bits_per_pixel) {
-   case 8:
+   switch (fb->pixel_format) {
+   case DRM_FORMAT_C8:
key = 0;
flags |= CLK_RGB8I_MASK;
break;
-
-   case 16:
-   if (overlay->crtc->base.primary->fb->depth == 15) {
-   key = RGB15_TO_COLORKEY(key);
-   flags |= CLK_RGB15_MASK;
-   } else {
-   key = RGB16_TO_COLORKEY(key);
-   flags |= CLK_RGB16_MASK;
-   }
+   case DRM_FORMAT_XRGB1555:
+   key = RGB15_TO_COLORKEY(key);
+   flags |= CLK_RGB15_MASK;
break;
-
-   case 24:
-   case 32:
+   case DRM_FORMAT_RGB565:
+   key = RGB16_TO_COLORKEY(key);
+   flags |= CLK_RGB16_MASK;
+   break;
+   default:
flags |= CLK_RGB24_MASK;
break;
}
-- 
2.7.4



[PATCH 00/32] drm: Deduplicate fb format information

2016-11-17 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

This series aims to remove the duplicated format information stored under
drm_framebuffer (depth,bits_per_pixel,pixel_format), and instead we just
use the drm_format_info structure. And we store a pointer to the approriate
drm_format_info under drm_framebuffer so that we don't have to do expensive
linear searches through the big array.

Quite of bit of this was cocci magic, and I've tried to keep the cocci
patches pure of manual tinkering in case someone needs to rerun them.
I had some issues with cocci behaving like an idiot, so I've included
a bunch of hand rolled patches up front to make life easier for it.

I've smoke tested this on i915, and compile tested on everything else
(I hope).

Entire series available here:
git://github.com/vsyrjala/linux.git fb_format_dedup

Cc: Alex Deucher 
Cc: Alexey Brodkin 
Cc: Ben Skeggs 
Cc: Brian Starkey 
Cc: "Christian König" 
Cc: Dave Airlie 
Cc: Gerd Hoffmann 
Cc: intel-gfx at lists.freedesktop.org
Cc: linux-graphics-maintainer at vmware.com
Cc: Liviu Dudau 
Cc: Mali DP Maintainers 
Cc: Patrik Jakobsson 
Cc: Paulo Zanoni 
Cc: Sinclair Yeh 
Cc: Thomas Hellstrom 

Ville Syrjälä (32):
  drm/i915: Add local 'fb' variables
  drm/radeon: Add local 'fb' variables
  drm/radeon: Use DIV_ROUND_UP()
  drm/mgag200: Add local 'fb' variable
  drm/ast: Add local 'fb' variables
  drm/gma500: Add some local 'fb' variables
  drm/cirrus: Add some local 'fb' variables
  drm/arcpgu: Add local 'fb' variables
  drm/arm: Add local 'fb' variables
  drm/nouveau: Fix crtc->primary->fb vs. drm_fb fail
  drm/nouveau: Add local 'fb' variables
  drm/vmwgfx: Populate fb->dev before drm_framebuffer_init()
  drm: Pass 'dev' to drm_helper_mode_fill_fb_struct()
  drm/vmwgfx: Populate fb->pixel_format
  drm/qxl: Call drm_helper_mode_fill_fb_struct() before
drm_framebuffer_init()
  drm/virtio: Call drm_helper_mode_fill_fb_struct() before
drm_framebuffer_init()
  drm/i915: Set fb->dev early on for inherited fbs
  drm: Populate fb->dev from drm_helper_mode_fill_fb_struct()
  drm: Store a pointer to drm_format_info under drm_framebuffer
  drm/vmwgfx: Populate fb->format correctly
  drm/i915: Populate fb->format early for inherited fbs
  drm/atomic: Replace drm_format_num_planes() with
fb->format->num_planes
  drm/fb_cma_helper: Replace drm_format_info() with fb->format
  drm/nouveau: Use fb->format rather than drm_format_info()
  drm/i915: Store a pointer to the pixel format info for fbc
  drm/i915: Replace drm_format_plane_cpp() with fb->format->cpp[]
  drm/i915: Replace drm_format_num_planes() with fb->format->num_planes
  drm: Add drm_framebuffer_plane_{width,height}()
  drm/i915: Use drm_framebuffer_plane_{width,height}() where possible
  drm: Nuke fb->depth
  drm: Nuke fb->bits_per_pixel
  drm: Nuke fb->pixel_format

 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c  |  4 +-
 drivers/gpu/drm/amd/amdgpu/dce_v10_0.c  |  6 +-
 drivers/gpu/drm/amd/amdgpu/dce_v11_0.c  |  6 +-
 drivers/gpu/drm/amd/amdgpu/dce_v6_0.c   |  6 +-
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c   |  6 +-
 drivers/gpu/drm/arc/arcpgu_crtc.c   |  3 +-
 drivers/gpu/drm/arm/hdlcd_crtc.c| 18 +++---
 drivers/gpu/drm/arm/malidp_planes.c | 10 ++--
 drivers/gpu/drm/armada/armada_crtc.c|  6 +-
 drivers/gpu/drm/armada/armada_fb.c  |  2 +-
 drivers/gpu/drm/armada/armada_fbdev.c   |  5 +-
 drivers/gpu/drm/armada/armada_overlay.c |  2 +-
 drivers/gpu/drm/ast/ast_fb.c|  4 +-
 drivers/gpu/drm/ast/ast_main.c  |  2 +-
 drivers/gpu/drm/ast/ast_mode.c  | 16 +++--
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_layer.c |  2 +-
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c | 22 +++
 drivers/gpu/drm/bochs/bochs_fbdev.c |  2 +-
 drivers/gpu/drm/bochs/bochs_mm.c|  2 +-
 drivers/gpu/drm/cirrus/cirrus_fbdev.c   |  6 +-
 drivers/gpu/drm/cirrus/cirrus_main.c|  2 +-
 drivers/gpu/drm/cirrus/cirrus_mode.c|  9 +--
 drivers/gpu/drm/drm_atomic.c|  8 +--
 drivers/gpu/drm/drm_crtc.c  |  4 +-
 drivers/gpu/drm/drm_crtc_helper.c   |  4 +-
 drivers/gpu/drm/drm_fb_cma_helper.c | 11 ++--
 drivers/gpu/drm/drm_fb_helper.c | 10 ++--
 drivers/gpu/drm/drm_framebuffer.c   | 53 -
 drivers/gpu/drm/drm_modeset_helper.c| 11 ++--
 drivers/gpu/drm/drm_plane.c |  6 +-
 drivers/gpu/drm/exynos/exynos5433_drm_decon.c   |  6 +-
 drivers/gpu/drm/exynos/exynos7_drm_decon.c  |  8 +--
 drivers/gpu/drm/exynos/exynos_drm_fb.c  |  2 +-
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c   |  6 +-
 drivers/gpu/drm/exynos/exynos_drm_fi

[RFC][PATCH] drm: Nuke modifier[1-3]

2016-11-16 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

It has been suggested that having per-plane modifiers is making life
more difficult for userspace, so let's just retire modifier[1-3] and
use modifier[0] to apply to the entire framebuffer.

Obviosuly this means that if individual planes need different tiling
layouts and whatnot we will need a new modifier for each combination
of planes with different tiling layouts.

For a bit of extra backwards compatilbilty the kernel will allow
non-zero modifier[1+] but it require that they will match modifier[0].
This in case there's existing userspace out there that sets
modifier[1+] to something non-zero with planar formats.

Mostly a cocci job, with a bit of manual stuff mixed in.

@@
struct drm_framebuffer *fb;
expression E;
@@
- fb->modifier[E]
+ fb->modifier

@@
struct drm_framebuffer fb;
expression E;
@@
- fb.modifier[E]
+ fb.modifier

Cc: Kristian Høgsberg 
Cc: Ben Widawsky 
Cc: Rob Clark 
Cc: Daniel Vetter 
Cc: Tomeu Vizoso 
Cc: dczaplejewicz at collabora.co.uk
Suggested-by: Kristian Høgsberg 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_atomic.c  |  2 +-
 drivers/gpu/drm/drm_framebuffer.c |  7 +++
 drivers/gpu/drm/drm_modeset_helper.c  |  2 +-
 drivers/gpu/drm/i915/i915_debugfs.c   |  4 +-
 drivers/gpu/drm/i915/intel_atomic_plane.c |  4 +-
 drivers/gpu/drm/i915/intel_display.c  | 72 +++
 drivers/gpu/drm/i915/intel_fbdev.c|  2 +-
 drivers/gpu/drm/i915/intel_pm.c   | 22 +-
 drivers/gpu/drm/i915/intel_sprite.c   | 14 +++---
 drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c |  2 +-
 include/drm/drm_framebuffer.h |  4 +-
 include/uapi/drm/drm_mode.h   | 13 +++---
 12 files changed, 79 insertions(+), 69 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 57e0a6e96f6d..bfaa6e4a9989 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -922,12 +922,12 @@ static void drm_atomic_plane_print_state(struct 
drm_printer *p,

drm_printf(p, "\t\tformat=%s\n",
  drm_get_format_name(fb->pixel_format, 
_name));
+   drm_printf(p, "\t\t\tmodifier=0x%llx\n", fb->modifier);
drm_printf(p, "\t\tsize=%dx%d\n", fb->width, fb->height);
drm_printf(p, "\t\tlayers:\n");
for (i = 0; i < n; i++) {
drm_printf(p, "\t\t\tpitch[%d]=%u\n", i, 
fb->pitches[i]);
drm_printf(p, "\t\t\toffset[%d]=%u\n", i, 
fb->offsets[i]);
-   drm_printf(p, "\t\t\tmodifier[%d]=0x%llx\n", i, 
fb->modifier[i]);
}
}
drm_printf(p, "\tcrtc-pos=" DRM_RECT_FMT "\n", DRM_RECT_ARG());
diff --git a/drivers/gpu/drm/drm_framebuffer.c 
b/drivers/gpu/drm/drm_framebuffer.c
index 06ad3d1350c4..cbf0c893f426 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -177,6 +177,13 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 
*r)
return -EINVAL;
}

+   if (r->flags & DRM_MODE_FB_MODIFIERS &&
+   r->modifier[i] != r->modifier[0]) {
+   DRM_DEBUG_KMS("bad fb modifier %llu for plane %d\n",
+ r->modifier[i], i);
+   return -EINVAL;
+   }
+
/* modifier specific checks: */
switch (r->modifier[i]) {
case DRM_FORMAT_MOD_SAMSUNG_64_32_TILE:
diff --git a/drivers/gpu/drm/drm_modeset_helper.c 
b/drivers/gpu/drm/drm_modeset_helper.c
index 2f452b3dd40e..633355e02398 100644
--- a/drivers/gpu/drm/drm_modeset_helper.c
+++ b/drivers/gpu/drm/drm_modeset_helper.c
@@ -93,8 +93,8 @@ void drm_helper_mode_fill_fb_struct(struct drm_framebuffer 
*fb,
for (i = 0; i < 4; i++) {
fb->pitches[i] = mode_cmd->pitches[i];
fb->offsets[i] = mode_cmd->offsets[i];
-   fb->modifier[i] = mode_cmd->modifier[i];
}
+   fb->modifier = mode_cmd->modifier[0];
fb->pixel_format = mode_cmd->pixel_format;
fb->flags = mode_cmd->flags;
 }
diff --git a/drivers/gpu/drm/i915/i915_debugfs.c 
b/drivers/gpu/drm/i915/i915_debugfs.c
index 1cc971cb6cb1..ae136af4aa37 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -1897,7 +1897,7 @@ static int i915_gem_framebuffer_info(struct seq_file *m, 
void *data)
   fbdev_fb->base.height,
   fbdev_fb->base.depth,
   fbdev_fb->base.bits_per_pixel,
-  fbdev_fb->base.modifier[0],
+

[PATCH] drm/uapi: Add a warning that mode flags must match the xrandr definitions

2016-11-03 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Existing userspace expected the mode flags to match the xrandr
definitions 1:1, and even adding new flags in he previously unused
bits is likely to break existing userspace. Add a comment warning
people about this potential trap.

Cc: Shashank Sharma 
Cc: "Lin, Jia" 
Cc: Akashdeep Sharma 
Cc: Jim Bride 
Cc: Jose Abreu 
Cc: Daniel Vetter 
Cc: Emil Velikov 
Signed-off-by: Ville Syrjälä 
---
 include/uapi/drm/drm_mode.h | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h
index 084b50a02dc5..01000c9f7c2c 100644
--- a/include/uapi/drm/drm_mode.h
+++ b/include/uapi/drm/drm_mode.h
@@ -47,7 +47,15 @@ extern "C" {
 #define DRM_MODE_TYPE_DRIVER   (1<<6)

 /* Video mode flags */
-/* bit compatible with the xorg definitions. */
+/* bit compatible with the xrandr RR_ definitions (bits 0-13)
+ *
+ * ABI warning: Existing userspace really expects
+ * the mode flags to match the xrandr definitions. Any
+ * changes that don't match the xrandr definitions will
+ * likely need a new client cap or some other mechanism
+ * to avoid breaking existing userspace. This includes
+ * allocating new flags in the previously unused bits!
+ */
 #define DRM_MODE_FLAG_PHSYNC   (1<<0)
 #define DRM_MODE_FLAG_NHSYNC   (1<<1)
 #define DRM_MODE_FLAG_PVSYNC   (1<<2)
-- 
2.7.4



[PATCH 2/2] drm/edid: Consider alternate cea timings to be the same VIC

2016-11-03 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

CEA-861 specifies that the vertical front porch may vary by one or two
lines for specific VICs. Up to now we've only considered a mode to match
the VIC if it matched the shortest possible vertical front porch length
(as that is the variant we store in cea_modes[]). Let's allow our VIC
matching to work with the other timings variants as well so that that
we'll send out the correct VIC if the variant actually used isn't the
one with the shortest vertical front porch.

Cc: Shashank Sharma 
Cc: Andrzej Hajda 
Cc: Adam Jackson 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_edid.c | 66 +-
 1 file changed, 54 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 7eec18925b70..728990fee4ef 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -2613,6 +2613,41 @@ cea_mode_alternate_clock(const struct drm_display_mode 
*cea_mode)
return clock;
 }

+static bool
+cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
+{
+   /*
+* For certain VICs the spec allows the vertical
+* front porch to vary by one or two lines.
+*
+* cea_modes[] stores the variant with the shortest
+* vertical front porch. We can adjust the mode to
+* get the other variants by simply increasing the
+* vertical front porch length.
+*/
+   BUILD_BUG_ON(edid_cea_modes[8].vtotal != 262 ||
+edid_cea_modes[9].vtotal != 262 ||
+edid_cea_modes[12].vtotal != 262 ||
+edid_cea_modes[13].vtotal != 262 ||
+edid_cea_modes[23].vtotal != 312 ||
+edid_cea_modes[24].vtotal != 312 ||
+edid_cea_modes[27].vtotal != 312 ||
+edid_cea_modes[28].vtotal != 312);
+
+   if (((vic == 8 || vic == 9 ||
+ vic == 12 || vic == 13) && mode->vtotal < 263) ||
+   ((vic == 23 || vic == 24 ||
+ vic == 27 || vic == 28) && mode->vtotal < 314)) {
+   mode->vsync_start++;
+   mode->vsync_end++;
+   mode->vtotal++;
+
+   return true;
+   }
+
+   return false;
+}
+
 static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode 
*to_match,
 unsigned int clock_tolerance)
 {
@@ -2622,19 +2657,21 @@ static u8 drm_match_cea_mode_clock_tolerance(const 
struct drm_display_mode *to_m
return 0;

for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
-   const struct drm_display_mode *cea_mode = _cea_modes[vic];
+   struct drm_display_mode cea_mode = edid_cea_modes[vic];
unsigned int clock1, clock2;

/* Check both 60Hz and 59.94Hz */
-   clock1 = cea_mode->clock;
-   clock2 = cea_mode_alternate_clock(cea_mode);
+   clock1 = cea_mode.clock;
+   clock2 = cea_mode_alternate_clock(_mode);

if (abs(to_match->clock - clock1) > clock_tolerance &&
abs(to_match->clock - clock2) > clock_tolerance)
continue;

-   if (drm_mode_equal_no_clocks(to_match, cea_mode))
-   return vic;
+   do {
+   if (drm_mode_equal_no_clocks_no_stereo(to_match, 
_mode))
+   return vic;
+   } while (cea_mode_alternate_timings(vic, _mode));
}

return 0;
@@ -2655,18 +2692,23 @@ u8 drm_match_cea_mode(const struct drm_display_mode 
*to_match)
return 0;

for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
-   const struct drm_display_mode *cea_mode = _cea_modes[vic];
+   struct drm_display_mode cea_mode = edid_cea_modes[vic];
unsigned int clock1, clock2;

/* Check both 60Hz and 59.94Hz */
-   clock1 = cea_mode->clock;
-   clock2 = cea_mode_alternate_clock(cea_mode);
+   clock1 = cea_mode.clock;
+   clock2 = cea_mode_alternate_clock(_mode);

-   if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
-KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
-   drm_mode_equal_no_clocks_no_stereo(to_match, cea_mode))
-   return vic;
+   if (KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock1) &&
+   KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock2))
+   continue;
+
+   do {
+   if (drm_mode_equal_no_clocks_no_stereo(to_match, 
_mode))
+   return vic;
+   } while (cea_

[PATCH 1/2] drm/edid: Add the missing "Hz" to VIC 58,59 comment

2016-11-03 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

All the VICs apart from 58 and 59 have the word "Hz" included in the
comment. Include it for 59 and 59 as well.

Cc: Shashank Sharma 
Cc: Andrzej Hajda 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_edid.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 9506933b41cd..7eec18925b70 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -957,13 +957,13 @@ static const struct drm_display_mode edid_cea_modes[] = {
   798, 858, 0, 480, 489, 495, 525, 0,
   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
-   /* 58 - 720(1440)x480i at 240 */
+   /* 58 - 720(1440)x480i at 240Hz */
{ DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
   801, 858, 0, 480, 488, 494, 525, 0,
   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
-   /* 59 - 720(1440)x480i at 240 */
+   /* 59 - 720(1440)x480i at 240Hz */
{ DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
   801, 858, 0, 480, 488, 494, 525, 0,
   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-- 
2.7.4



[PATCH 2/2] Revert "drm: Add aspect ratio parsing in DRM layer"

2016-11-03 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

This reverts commit 6dffd431e2296cda08e7e4f0242e02df1d1698cd.

Adding new mode flags willy nilly breaks existing userspace. We need to
coordinate this better, potentially with a new client cap that only
exposes the aspect ratio flags when userspace is prepared for them
(similar to what we do with stereo 3D modes).

This also broke things so that we would always send out VIC==0 in
the AVI infoframe unless the user specified an aspect ratio via
the mode flags. And the automagic RGB full vs. limited range
handling was similartly broken as the user mode would never match
any CEA mode.

Cc: Shashank Sharma 
Cc: Lin, Jia 
Cc: Akashdeep Sharma 
Cc: Jim Bride 
Cc: Jose Abreu 
Cc: Daniel Vetter 
Cc: Emil Velikov 
Cc: Daniel Vetter 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_modes.c | 31 ---
 1 file changed, 31 deletions(-)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 725faa6409aa..18442b5bb34c 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -1001,7 +1001,6 @@ bool drm_mode_equal_no_clocks_no_stereo(const struct 
drm_display_mode *mode1,
mode1->vsync_end == mode2->vsync_end &&
mode1->vtotal == mode2->vtotal &&
mode1->vscan == mode2->vscan &&
-   mode1->picture_aspect_ratio == mode2->picture_aspect_ratio &&
(mode1->flags & ~DRM_MODE_FLAG_3D_MASK) ==
 (mode2->flags & ~DRM_MODE_FLAG_3D_MASK))
return true;
@@ -1504,21 +1503,6 @@ void drm_mode_convert_to_umode(struct drm_mode_modeinfo 
*out,
out->vrefresh = in->vrefresh;
out->flags = in->flags;
out->type = in->type;
-   out->flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
-
-   switch (in->picture_aspect_ratio) {
-   case HDMI_PICTURE_ASPECT_4_3:
-   out->flags |= DRM_MODE_FLAG_PIC_AR_4_3;
-   break;
-   case HDMI_PICTURE_ASPECT_16_9:
-   out->flags |= DRM_MODE_FLAG_PIC_AR_16_9;
-   break;
-   case HDMI_PICTURE_ASPECT_RESERVED:
-   default:
-   out->flags |= DRM_MODE_FLAG_PIC_AR_NONE;
-   break;
-   }
-
strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
 }
@@ -1564,21 +1548,6 @@ int drm_mode_convert_umode(struct drm_display_mode *out,
strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
out->name[DRM_DISPLAY_MODE_LEN-1] = 0;

-   /* Clearing picture aspect ratio bits from out flags */
-   out->flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
-
-   switch (in->flags & DRM_MODE_FLAG_PIC_AR_MASK) {
-   case DRM_MODE_FLAG_PIC_AR_4_3:
-   out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_4_3;
-   break;
-   case DRM_MODE_FLAG_PIC_AR_16_9:
-   out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_16_9;
-   break;
-   default:
-   out->picture_aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
-   break;
-   }
-
out->status = drm_mode_validate_basic(out);
if (out->status != MODE_OK)
goto out;
-- 
2.7.4



[PATCH 1/2] Revert "drm: Add and handle new aspect ratios in DRM layer"

2016-11-03 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä <ville.syrj...@linux.intel.com>

This reverts commit a68362fe3e84fcbedd49939aa200519aa5410135.

Adding new mode flags willy nilly breaks existing userspace. We need to
coordinate this better, potentially with a new client cap that only
exposes the aspect ratio flags when userspace is prepared for them
(similar to what we do with stereo 3D modes).

Cc: Shashank Sharma 
Cc: Lin, Jia 
Cc: Akashdeep Sharma 
Cc: Jim Bride 
Cc: Jose Abreu 
Cc: Daniel Vetter 
Cc: Emil Velikov 
Cc: Daniel Vetter 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_modes.c | 12 
 include/uapi/drm/drm_mode.h |  6 --
 2 files changed, 18 deletions(-)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index f64ac86deb84..725faa6409aa 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -1513,12 +1513,6 @@ void drm_mode_convert_to_umode(struct drm_mode_modeinfo 
*out,
case HDMI_PICTURE_ASPECT_16_9:
out->flags |= DRM_MODE_FLAG_PIC_AR_16_9;
break;
-   case HDMI_PICTURE_ASPECT_64_27:
-   out->flags |= DRM_MODE_FLAG_PIC_AR_64_27;
-   break;
-   case DRM_MODE_PICTURE_ASPECT_256_135:
-   out->flags |= DRM_MODE_FLAG_PIC_AR_256_135;
-   break;
case HDMI_PICTURE_ASPECT_RESERVED:
default:
out->flags |= DRM_MODE_FLAG_PIC_AR_NONE;
@@ -1580,12 +1574,6 @@ int drm_mode_convert_umode(struct drm_display_mode *out,
case DRM_MODE_FLAG_PIC_AR_16_9:
out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_16_9;
break;
-   case DRM_MODE_FLAG_PIC_AR_64_27:
-   out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_64_27;
-   break;
-   case DRM_MODE_FLAG_PIC_AR_256_135:
-   out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_256_135;
-   break;
default:
out->picture_aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
break;
diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h
index 084b50a02dc5..5c142b1387ac 100644
--- a/include/uapi/drm/drm_mode.h
+++ b/include/uapi/drm/drm_mode.h
@@ -81,8 +81,6 @@ extern "C" {
 #define DRM_MODE_PICTURE_ASPECT_NONE   0
 #define DRM_MODE_PICTURE_ASPECT_4_31
 #define DRM_MODE_PICTURE_ASPECT_16_9   2
-#define DRM_MODE_PICTURE_ASPECT_64_27  3
-#define DRM_MODE_PICTURE_ASPECT_256_1354

 /* Aspect ratio flag bitmask (4 bits 22:19) */
 #define DRM_MODE_FLAG_PIC_AR_MASK  (0x0F<<19)
@@ -92,10 +90,6 @@ extern "C" {
(DRM_MODE_PICTURE_ASPECT_4_3<<19)
 #define  DRM_MODE_FLAG_PIC_AR_16_9 \
(DRM_MODE_PICTURE_ASPECT_16_9<<19)
-#define  DRM_MODE_FLAG_PIC_AR_64_27 \
-   (DRM_MODE_PICTURE_ASPECT_64_27<<19)
-#define  DRM_MODE_FLAG_PIC_AR_256_135 \
-   (DRM_MODE_PICTURE_ASPECT_256_135<<19)

 /* DPMS flags */
 /* bit compatible with the xorg definitions. */
-- 
2.7.4



  1   2   3   4   5   6   7   8   9   10   >