[PATCH] drm/dp: Allow signals to interrupt drm_aux-dev reads/writes

2016-04-27 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

Let's be nice and interrupt the dpcd aux-dev reads/writes when there's
a signal pending. Much nicer if the user can hit ^C instead of having to
sit around waiting for the read/write to finish.

time dd if=/dev/drm_dp_aux0 bs=$((1024*1024))
^C

before:
 real   0m34.681s
 user   0m0.003s
 sys0m6.880s

after:
 real   0m0.222s
 user   0m0.006s
 sys0m0.057s

Cc: Rafael Antognolli 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_dp_aux_dev.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/gpu/drm/drm_dp_aux_dev.c b/drivers/gpu/drm/drm_dp_aux_dev.c
index f73b38b33a8e..3334baacf43d 100644
--- a/drivers/gpu/drm/drm_dp_aux_dev.c
+++ b/drivers/gpu/drm/drm_dp_aux_dev.c
@@ -159,6 +159,12 @@ static ssize_t auxdev_read(struct file *file, char __user 
*buf, size_t count,
uint8_t localbuf[DP_AUX_MAX_PAYLOAD_BYTES];
ssize_t todo = min_t(size_t, bytes_pending, sizeof(localbuf));

+   if (signal_pending(current)) {
+   res = num_bytes_processed ?
+   num_bytes_processed : -ERESTARTSYS;
+   goto out;
+   }
+
res = drm_dp_dpcd_read(aux_dev->aux, *offset, localbuf, todo);
if (res <= 0) {
res = num_bytes_processed ? num_bytes_processed : res;
@@ -202,6 +208,12 @@ static ssize_t auxdev_write(struct file *file, const char 
__user *buf,
uint8_t localbuf[DP_AUX_MAX_PAYLOAD_BYTES];
ssize_t todo = min_t(size_t, bytes_pending, sizeof(localbuf));

+   if (signal_pending(current)) {
+   res = num_bytes_processed ?
+   num_bytes_processed : -ERESTARTSYS;
+   goto out;
+   }
+
if (__copy_from_user(localbuf,
 buf + num_bytes_processed, todo)) {
res = num_bytes_processed ?
-- 
2.7.4



[PATCH 00/10] drm/edid: Clean up display_info stuff

2016-08-03 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

This series aims to clean up the way we fill out the display_info 
structure a bit. Mainly doing a clean separation of the audio and
video related bits.

My aim is getting i915 to respect the HDMI sink TMDS clock limit
(currently we respect only the DP++ dongle limit, and the source
limit). But while doing that, I noticed that the display_info stuff
was a bit of mess, hence it resulted in this bigger series.

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

Ville Syrjälä (10):
  drm/edid: Clear old audio latency values before parsing the new EDID
  drm/edid: Clear old dvi_dual/max_tmds_clock before parsing the new
EDID
  drm/edid: Make max_tmds_clock kHz instead of MHz
  drm/edid: Move dvi_dual/max_tmds_clock to drm_display_info
  drm/edid: Don't pass around drm_display_info needlessly
  drm/edid: Reduce the number of times we parse the CEA extension block
  drm/edid: Clear the old cea_rev when there's no CEA extension in the
new EDID
  drm/edid: Move dvi_dual/max_tmds_clock parsing out from
drm_edid_to_eld()
  drm/i915: Replace a bunch of connector->base.display_info with a local
variable
  drm/i915: Account for sink max TMDS clock when checking the port clock

 drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c |   4 +-
 drivers/gpu/drm/drm_edid.c | 258 +
 drivers/gpu/drm/i915/intel_display.c   |  14 +-
 drivers/gpu/drm/i915/intel_hdmi.c  |   9 +-
 drivers/gpu/drm/radeon/radeon_connectors.c |   4 +-
 include/drm/drm_crtc.h |   7 +-
 6 files changed, 152 insertions(+), 144 deletions(-)

-- 
2.7.4



[PATCH 01/10] drm/edid: Clear old audio latency values before parsing the new EDID

2016-08-03 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

Clear out stale audio latency information (potentially from a previous
EDID) before constructing the ELD from the EDID.

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

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 7df26d4b7ad8..05ef93c8fa44 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -3353,6 +3353,13 @@ void drm_edid_to_eld(struct drm_connector *connector, 
struct edid *edid)

memset(eld, 0, sizeof(connector->eld));

+   connector->latency_present[0] = false;
+   connector->latency_present[1] = false;
+   connector->video_latency[0] = 0;
+   connector->audio_latency[0] = 0;
+   connector->video_latency[1] = 0;
+   connector->audio_latency[1] = 0;
+
cea = drm_find_cea_extension(edid);
if (!cea) {
DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
-- 
2.7.4



[PATCH 02/10] drm/edid: Clear old dvi_dual/max_tmds_clock before parsing the new EDID

2016-08-03 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

Clear out old max_tmds_clock and dvi_dual information (possibly from a
previous EDID) before parsing the current EDID. Tne current EDID might
not even have these in its HDMI VSDB, which would mean that we'd leave
the old stale values in place.

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_edid.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 05ef93c8fa44..40e7f1a863a6 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -3360,6 +3360,9 @@ void drm_edid_to_eld(struct drm_connector *connector, 
struct edid *edid)
connector->video_latency[1] = 0;
connector->audio_latency[1] = 0;

+   connector->max_tmds_clock = 0;
+   connector->dvi_dual = false;
+
cea = drm_find_cea_extension(edid);
if (!cea) {
DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
-- 
2.7.4



[PATCH 03/10] drm/edid: Make max_tmds_clock kHz instead of MHz

2016-08-03 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

We generally store clocks in kHz, so let's do that for the
HDMI max TMDS clock value as well. Less surpising.

Cc: Alex Deucher 
Cc: "Christian König" 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c | 2 +-
 drivers/gpu/drm/drm_edid.c | 2 +-
 drivers/gpu/drm/radeon/radeon_connectors.c | 2 +-
 include/drm/drm_crtc.h | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
index ff0b55a65ca3..a56eeaa213f4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
@@ -173,7 +173,7 @@ int amdgpu_connector_get_monitor_bpc(struct drm_connector 
*connector)
mode_clock = amdgpu_connector->pixelclock_for_modeset;

/* Maximum allowable input clock in kHz */
-   max_tmds_clock = connector->max_tmds_clock * 1000;
+   max_tmds_clock = connector->max_tmds_clock;

DRM_DEBUG("%s: hdmi mode dotclock %d kHz, max tmds 
input clock %d kHz.\n",
  connector->name, mode_clock, max_tmds_clock);
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 40e7f1a863a6..f0f08f56ea97 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -3257,7 +3257,7 @@ parse_hdmi_vsdb(struct drm_connector *connector, const u8 
*db)
connector->dvi_dual = db[6] & 1;
}
if (len >= 7)
-   connector->max_tmds_clock = db[7] * 5;
+   connector->max_tmds_clock = db[7] * 5000;
if (len >= 8) {
connector->latency_present[0] = db[8] >> 7;
connector->latency_present[1] = (db[8] >> 6) & 1;
diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c 
b/drivers/gpu/drm/radeon/radeon_connectors.c
index b79f3b002471..db5488732e31 100644
--- a/drivers/gpu/drm/radeon/radeon_connectors.c
+++ b/drivers/gpu/drm/radeon/radeon_connectors.c
@@ -203,7 +203,7 @@ int radeon_get_monitor_bpc(struct drm_connector *connector)
mode_clock = radeon_connector->pixelclock_for_modeset;

/* Maximum allowable input clock in kHz */
-   max_tmds_clock = connector->max_tmds_clock * 1000;
+   max_tmds_clock = connector->max_tmds_clock;

DRM_DEBUG("%s: hdmi mode dotclock %d kHz, max tmds 
input clock %d kHz.\n",
  connector->name, mode_clock, 
max_tmds_clock);
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 3edeaf88ebc0..e7cf08d9df10 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -1366,7 +1366,7 @@ struct drm_connector {
/* EDID bits */
uint8_t eld[MAX_ELD_BYTES];
bool dvi_dual;
-   int max_tmds_clock; /* in MHz */
+   int max_tmds_clock; /* in kHz */
bool latency_present[2];
int video_latency[2];   /* [0]: progressive, [1]: interlaced */
int audio_latency[2];
-- 
2.7.4



[PATCH 06/10] drm/edid: Reduce the number of times we parse the CEA extension block

2016-08-03 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

Instead of parsing parts of the CEA extension block in two places
to determine supported color formats and whatnot, let's just
consolidate it to one function. This also makes it possible to neatly
flatten drm_assign_hdmi_deep_color_info().

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_edid.c | 192 +
 1 file changed, 89 insertions(+), 103 deletions(-)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index d8c7da56ab75..82ab57c4d6c9 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -3728,119 +3728,119 @@ bool drm_rgb_quant_range_selectable(struct edid *edid)
 }
 EXPORT_SYMBOL(drm_rgb_quant_range_selectable);

-/**
- * drm_assign_hdmi_deep_color_info - detect whether monitor supports
- * hdmi deep color modes and update drm_display_info if so.
- * @edid: monitor EDID information
- * @connector: DRM connector, used only for debug output
- *
- * Parse the CEA extension according to CEA-861-B.
- * Return true if HDMI deep color supported, false if not or unknown.
- */
-static bool drm_assign_hdmi_deep_color_info(struct edid *edid,
-struct drm_connector *connector)
+static void drm_parse_hdmi_deep_color_info(struct drm_connector *connector,
+  const u8 *hdmi)
 {
struct drm_display_info *info = &connector->display_info;
-   u8 *edid_ext, *hdmi;
-   int i;
-   int start_offset, end_offset;
unsigned int dc_bpc = 0;

-   edid_ext = drm_find_cea_extension(edid);
-   if (!edid_ext)
-   return false;
+   /* HDMI supports at least 8 bpc */
+   info->bpc = 8;

-   if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
-   return false;
+   if (cea_db_payload_len(hdmi) < 6)
+   return;
+
+   if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
+   dc_bpc = 10;
+   info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_30;
+   DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
+ connector->name);
+   }
+
+   if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
+   dc_bpc = 12;
+   info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_36;
+   DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
+ connector->name);
+   }
+
+   if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
+   dc_bpc = 16;
+   info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_48;
+   DRM_DEBUG("%s: HDMI sink does deep color 48.\n",
+ connector->name);
+   }
+
+   if (dc_bpc == 0) {
+   DRM_DEBUG("%s: No deep color support on this HDMI sink.\n",
+ connector->name);
+   return;
+   }
+
+   DRM_DEBUG("%s: Assigning HDMI sink color depth as %d bpc.\n",
+ connector->name, dc_bpc);
+   info->bpc = dc_bpc;

/*
-* Because HDMI identifier is in Vendor Specific Block,
-* search it from all data blocks of CEA extension.
+* Deep color support mandates RGB444 support for all video
+* modes and forbids YCRCB422 support for all video modes per
+* HDMI 1.3 spec.
 */
-   for_each_cea_db(edid_ext, i, start_offset, end_offset) {
-   if (cea_db_is_hdmi_vsdb(&edid_ext[i])) {
-   /* HDMI supports at least 8 bpc */
-   info->bpc = 8;
-
-   hdmi = &edid_ext[i];
-   if (cea_db_payload_len(hdmi) < 6)
-   return false;
-
-   if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
-   dc_bpc = 10;
-   info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_30;
-   DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
- connector->name);
-   }
+   info->color_formats = DRM_COLOR_FORMAT_RGB444;

-   if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
-   dc_bpc = 12;
-   info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_36;
-   DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
- connector->name);
-   }
+   /* YCRCB444 is optional according to spec. */
+   if (hdmi[6] & DRM_EDID_HDMI_DC_Y444) {
+   info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
+   DRM_DEBUG("%s: HDMI sink does YCRCB444 in deep color.\n",
+ connector->name);
+   }

-   if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
-   dc_bpc = 16;
-   info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_48;
-   DRM_DEBUG("%s:

[PATCH 04/10] drm/edid: Move dvi_dual/max_tmds_clock to drm_display_info

2016-08-03 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

We have the drm_display_info for storing information about the sink, so
let's move dvi_dual and max_tmds_clock in there.

Cc: Alex Deucher 
Cc: "Christian König" 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c |  4 ++--
 drivers/gpu/drm/drm_edid.c | 14 --
 drivers/gpu/drm/radeon/radeon_connectors.c |  4 ++--
 include/drm/drm_crtc.h |  7 +++
 4 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
index a56eeaa213f4..3df2f6a56b46 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
@@ -168,12 +168,12 @@ int amdgpu_connector_get_monitor_bpc(struct drm_connector 
*connector)
}

/* Any defined maximum tmds clock limit we must not exceed? */
-   if (connector->max_tmds_clock > 0) {
+   if (connector->display_info.max_tmds_clock > 0) {
/* mode_clock is clock in kHz for mode to be modeset on 
this connector */
mode_clock = amdgpu_connector->pixelclock_for_modeset;

/* Maximum allowable input clock in kHz */
-   max_tmds_clock = connector->max_tmds_clock;
+   max_tmds_clock = connector->display_info.max_tmds_clock;

DRM_DEBUG("%s: hdmi mode dotclock %d kHz, max tmds 
input clock %d kHz.\n",
  connector->name, mode_clock, max_tmds_clock);
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index f0f08f56ea97..abd6d3c77ef2 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -3250,14 +3250,15 @@ static void fixup_detailed_cea_mode_clock(struct 
drm_display_mode *mode)
 static void
 parse_hdmi_vsdb(struct drm_connector *connector, const u8 *db)
 {
+   struct drm_display_info *info = &connector->display_info;
u8 len = cea_db_payload_len(db);

if (len >= 6) {
connector->eld[5] |= (db[6] >> 7) << 1;  /* Supports_AI */
-   connector->dvi_dual = db[6] & 1;
+   info->dvi_dual = db[6] & 1;
}
if (len >= 7)
-   connector->max_tmds_clock = db[7] * 5000;
+   info->max_tmds_clock = db[7] * 5000;
if (len >= 8) {
connector->latency_present[0] = db[8] >> 7;
connector->latency_present[1] = (db[8] >> 6) & 1;
@@ -3276,8 +3277,8 @@ parse_hdmi_vsdb(struct drm_connector *connector, const u8 
*db)
"latency present %d %d, "
"video latency %d %d, "
"audio latency %d %d\n",
-   connector->dvi_dual,
-   connector->max_tmds_clock,
+   info->dvi_dual,
+   info->max_tmds_clock,
  (int) connector->latency_present[0],
  (int) connector->latency_present[1],
connector->video_latency[0],
@@ -3344,6 +3345,7 @@ EXPORT_SYMBOL(drm_edid_get_monitor_name);
  */
 void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
 {
+   struct drm_display_info *info = &connector->display_info;
uint8_t *eld = connector->eld;
u8 *cea;
u8 *db;
@@ -3360,8 +3362,8 @@ void drm_edid_to_eld(struct drm_connector *connector, 
struct edid *edid)
connector->video_latency[1] = 0;
connector->audio_latency[1] = 0;

-   connector->max_tmds_clock = 0;
-   connector->dvi_dual = false;
+   info->max_tmds_clock = 0;
+   info->dvi_dual = false;

cea = drm_find_cea_extension(edid);
if (!cea) {
diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c 
b/drivers/gpu/drm/radeon/radeon_connectors.c
index db5488732e31..50e96d2c593d 100644
--- a/drivers/gpu/drm/radeon/radeon_connectors.c
+++ b/drivers/gpu/drm/radeon/radeon_connectors.c
@@ -198,12 +198,12 @@ int radeon_get_monitor_bpc(struct drm_connector 
*connector)
}

/* Any defined maximum tmds clock limit we must not exceed? */
-   if (connector->max_tmds_clock > 0) {
+   if (connector->display_info.max_tmds_clock > 0) {
/* mode_clock is clock in kHz for mode to be modeset on 
this connector */
mode_clock = radeon_connector->pixelclock_for_modeset;

/* Maximum allowable input clock in kHz */
-   max_tmds_clock = connector->max_tmds_clock;
+   max_tmds_clock = connector->display_info.max_tmds_clock;

DRM_DEBUG("%s: hdmi mode dotclock %d kHz, max tmds 
input clock %d kHz.\n",
  connector->name, mode_clock, 
max_tmds_clock);
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_cr

[PATCH 07/10] drm/edid: Clear the old cea_rev when there's no CEA extension in the new EDID

2016-08-03 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

It's not a good idea to leave stale cea_rev in the drm_display_info. The
current EDID might not even have a CEA ext block in which case we'd end
up leaving the stale value in place.

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

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 82ab57c4d6c9..452e8c51a729 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -3848,6 +3848,7 @@ static void drm_add_display_info(struct drm_connector 
*connector,
/* driver figures it out in this case */
info->bpc = 0;
info->color_formats = 0;
+   info->cea_rev = 0;

if (edid->revision < 3)
return;
-- 
2.7.4



[PATCH 08/10] drm/edid: Move dvi_dual/max_tmds_clock parsing out from drm_edid_to_eld()

2016-08-03 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

drm_edid_to_eld() is just mean to cook up the ELD for the audio driver,
so having it parse non-audio related stuff seems just wrong, and
potentially could lead to that information not being even filled out
if the function doesn't even get called. Let's move that stuff to the
place where we parse the color formats and whatnot from the CEA ext
block.

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_edid.c | 64 +-
 1 file changed, 35 insertions(+), 29 deletions(-)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 452e8c51a729..3cf8e44e040d 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -3248,17 +3248,12 @@ static void fixup_detailed_cea_mode_clock(struct 
drm_display_mode *mode)
 }

 static void
-parse_hdmi_vsdb(struct drm_connector *connector, const u8 *db)
+drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db)
 {
-   struct drm_display_info *info = &connector->display_info;
u8 len = cea_db_payload_len(db);

-   if (len >= 6) {
+   if (len >= 6)
connector->eld[5] |= (db[6] >> 7) << 1;  /* Supports_AI */
-   info->dvi_dual = db[6] & 1;
-   }
-   if (len >= 7)
-   info->max_tmds_clock = db[7] * 5000;
if (len >= 8) {
connector->latency_present[0] = db[8] >> 7;
connector->latency_present[1] = (db[8] >> 6) & 1;
@@ -3272,19 +3267,15 @@ parse_hdmi_vsdb(struct drm_connector *connector, const 
u8 *db)
if (len >= 12)
connector->audio_latency[1] = db[12];

-   DRM_DEBUG_KMS("HDMI: DVI dual %d, "
-   "max TMDS clock %d, "
-   "latency present %d %d, "
-   "video latency %d %d, "
-   "audio latency %d %d\n",
-   info->dvi_dual,
-   info->max_tmds_clock,
- (int) connector->latency_present[0],
- (int) connector->latency_present[1],
-   connector->video_latency[0],
-   connector->video_latency[1],
-   connector->audio_latency[0],
-   connector->audio_latency[1]);
+   DRM_DEBUG_KMS("HDMI: latency present %d %d, "
+ "video latency %d %d, "
+ "audio latency %d %d\n",
+ connector->latency_present[0],
+ connector->latency_present[1],
+ connector->video_latency[0],
+ connector->video_latency[1],
+ connector->audio_latency[0],
+ connector->audio_latency[1]);
 }

 static void
@@ -3345,7 +3336,6 @@ EXPORT_SYMBOL(drm_edid_get_monitor_name);
  */
 void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
 {
-   struct drm_display_info *info = &connector->display_info;
uint8_t *eld = connector->eld;
u8 *cea;
u8 *db;
@@ -3362,9 +3352,6 @@ void drm_edid_to_eld(struct drm_connector *connector, 
struct edid *edid)
connector->video_latency[1] = 0;
connector->audio_latency[1] = 0;

-   info->max_tmds_clock = 0;
-   info->dvi_dual = false;
-
cea = drm_find_cea_extension(edid);
if (!cea) {
DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
@@ -3414,7 +3401,7 @@ void drm_edid_to_eld(struct drm_connector *connector, 
struct edid *edid)
case VENDOR_BLOCK:
/* HDMI Vendor-Specific Data Block */
if (cea_db_is_hdmi_vsdb(db))
-   parse_hdmi_vsdb(connector, db);
+   drm_parse_hdmi_vsdb_audio(connector, 
db);
break;
default:
break;
@@ -3795,6 +3782,25 @@ static void drm_parse_hdmi_deep_color_info(struct 
drm_connector *connector,
}
 }

+static void
+drm_parse_hdmi_vsdb_video(struct drm_connector *connector, const u8 *db)
+{
+   struct drm_display_info *info = &connector->display_info;
+   u8 len = cea_db_payload_len(db);
+
+   if (len >= 6)
+   info->dvi_dual = db[6] & 1;
+   if (len >= 7)
+   info->max_tmds_clock = db[7] * 5000;
+
+   DRM_DEBUG_KMS("HDMI: DVI dual %d, "
+ "max TMDS clock %d kHz\n",
+ info->dvi_dual,
+ info->max_tmds_clock);
+
+   drm_parse_hdmi_deep_color_info(connector, db);
+}
+
 static void drm_parse_cea_ext(struct drm_connector *connector,
  struct edid *edid)
 {
@@ -3821,10 +3827,8 @@ static void drm_parse_cea_ext(struct drm_connector 
*connector,
for_each_cea_db(edid_ext, i, start, end) {
const u8 *db = &edid_ext[i];

-   if (!cea_db_is_hdmi_vsdb(db))
-   continue;
-
- 

[PATCH 05/10] drm/edid: Don't pass around drm_display_info needlessly

2016-08-03 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

We already pass the connector to drm_add_display_info() and
drm_assign_hdmi_deep_color_info(), so passing the
connector->display_info also is pointless.

Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_edid.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index abd6d3c77ef2..d8c7da56ab75 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -3732,17 +3732,15 @@ EXPORT_SYMBOL(drm_rgb_quant_range_selectable);
  * drm_assign_hdmi_deep_color_info - detect whether monitor supports
  * hdmi deep color modes and update drm_display_info if so.
  * @edid: monitor EDID information
- * @info: Updated with maximum supported deep color bpc and color format
- *if deep color supported.
  * @connector: DRM connector, used only for debug output
  *
  * Parse the CEA extension according to CEA-861-B.
  * Return true if HDMI deep color supported, false if not or unknown.
  */
 static bool drm_assign_hdmi_deep_color_info(struct edid *edid,
-struct drm_display_info *info,
 struct drm_connector *connector)
 {
+   struct drm_display_info *info = &connector->display_info;
u8 *edid_ext, *hdmi;
int i;
int start_offset, end_offset;
@@ -3832,7 +3830,6 @@ static bool drm_assign_hdmi_deep_color_info(struct edid 
*edid,
 /**
  * drm_add_display_info - pull display info out if present
  * @edid: EDID data
- * @info: display info (attached to connector)
  * @connector: connector whose edid is used to build display info
  *
  * Grab any available display info and stuff it into the drm_display_info
@@ -3840,9 +3837,9 @@ static bool drm_assign_hdmi_deep_color_info(struct edid 
*edid,
  * color spaces.
  */
 static void drm_add_display_info(struct edid *edid,
- struct drm_display_info *info,
  struct drm_connector *connector)
 {
+   struct drm_display_info *info = &connector->display_info;
u8 *edid_ext;

info->width_mm = edid->width_cm * 10;
@@ -3872,7 +3869,7 @@ static void drm_add_display_info(struct edid *edid,
}

/* HDMI deep color modes supported? Assign to info, if so */
-   drm_assign_hdmi_deep_color_info(edid, info, connector);
+   drm_assign_hdmi_deep_color_info(edid, connector);

/* Only defined for 1.4 with digital displays */
if (edid->revision < 4)
@@ -4092,7 +4089,7 @@ int drm_add_edid_modes(struct drm_connector *connector, 
struct edid *edid)
if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
edid_fixup_preferred(connector, quirks);

-   drm_add_display_info(edid, &connector->display_info, connector);
+   drm_add_display_info(edid, connector);

if (quirks & EDID_QUIRK_FORCE_8BPC)
connector->display_info.bpc = 8;
-- 
2.7.4



[PATCH 09/10] drm/i915: Replace a bunch of connector->base.display_info with a local variable

2016-08-03 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

Reduce the eyesore with a local variable.

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

diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index a8e8cc8dfae9..b9cdf9060da6 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -12090,22 +12090,22 @@ static void
 connected_sink_compute_bpp(struct intel_connector *connector,
   struct intel_crtc_state *pipe_config)
 {
+   const struct drm_display_info *info = &connector->base.display_info;
int bpp = pipe_config->pipe_bpp;

DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
-   connector->base.base.id,
-   connector->base.name);
+ connector->base.base.id,
+ connector->base.name);

/* Don't use an invalid EDID bpc value */
-   if (connector->base.display_info.bpc &&
-   connector->base.display_info.bpc * 3 < bpp) {
+   if (info->bpc != 0 && info->bpc * 3 < bpp) {
DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported 
max of %d\n",
- bpp, connector->base.display_info.bpc*3);
-   pipe_config->pipe_bpp = connector->base.display_info.bpc*3;
+ bpp, info->bpc * 3);
+   pipe_config->pipe_bpp = info->bpc * 3;
}

/* Clamp bpp to default limit on screens without EDID 1.4 */
-   if (connector->base.display_info.bpc == 0) {
+   if (info->bpc == 0) {
int type = connector->base.connector_type;
int clamp_bpp = 24;

-- 
2.7.4



[PATCH 10/10] drm/i915: Account for sink max TMDS clock when checking the port clock

2016-08-03 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

It's perfectly legal for the sink to support 12bpc only for
some lower resolution modes, while the higher resolution modes
can only be used with 8bpc. So let's take the sink's max TMDS clock
into account before we go and decide that a particular mode can
be used with 12bpc.

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

diff --git a/drivers/gpu/drm/i915/intel_hdmi.c 
b/drivers/gpu/drm/i915/intel_hdmi.c
index 4df9f384910c..8b013301cf11 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -1204,10 +1204,17 @@ static int hdmi_port_clock_limit(struct intel_hdmi 
*hdmi,
int max_tmds_clock = intel_hdmi_source_max_tmds_clock(to_i915(dev));

if (respect_downstream_limits) {
+   struct intel_connector *connector = hdmi->attached_connector;
+   const struct drm_display_info *info = 
&connector->base.display_info;
+
if (hdmi->dp_dual_mode.max_tmds_clock)
max_tmds_clock = min(max_tmds_clock,
 hdmi->dp_dual_mode.max_tmds_clock);
-   if (!hdmi->has_hdmi_sink)
+
+   if (info->max_tmds_clock)
+   max_tmds_clock = min(max_tmds_clock,
+info->max_tmds_clock);
+   else if (!hdmi->has_hdmi_sink)
max_tmds_clock = min(max_tmds_clock, 165000);
}

-- 
2.7.4



[PATCH v3 3/9] drm/plane-helper: Add drm_plane_helper_check_state()

2016-08-08 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

Add a version of drm_plane_helper_check_update() which takes a plane
state instead of having the caller pass in everything.

And to reduce code duplication, let's reimplement
drm_plane_helper_check_update() in terms of the new function, by
having a tempororary plane state on the stack.

v2: Add a note that the functions modifies the state (Chris)
v3: Fix drm_plane_helper_check_update() y coordinates (Daniel Kurtz)

Cc: Daniel Kurtz 
Cc: Chris Wilson 
Signed-off-by: Ville Syrjälä 
Reviewed-by: Sean Paul  (v2)
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_plane_helper.c | 139 -
 include/drm/drm_plane_helper.h |   5 ++
 2 files changed, 112 insertions(+), 32 deletions(-)

diff --git a/drivers/gpu/drm/drm_plane_helper.c 
b/drivers/gpu/drm/drm_plane_helper.c
index 16c4a7bd7465..0251aeec2bf3 100644
--- a/drivers/gpu/drm/drm_plane_helper.c
+++ b/drivers/gpu/drm/drm_plane_helper.c
@@ -108,14 +108,9 @@ static int get_connectors_for_crtc(struct drm_crtc *crtc,
 }

 /**
- * drm_plane_helper_check_update() - Check plane update for validity
- * @plane: plane object to update
- * @crtc: owning CRTC of owning plane
- * @fb: framebuffer to flip onto plane
- * @src: source coordinates in 16.16 fixed point
- * @dest: integer destination coordinates
+ * drm_plane_helper_check_state() - Check plane state for validity
+ * @state: plane state to check
  * @clip: integer clipping coordinates
- * @rotation: plane rotation
  * @min_scale: minimum @src:@dest scaling factor in 16.16 fixed point
  * @max_scale: maximum @src:@dest scaling factor in 16.16 fixed point
  * @can_position: is it legal to position the plane such that it
@@ -123,10 +118,9 @@ static int get_connectors_for_crtc(struct drm_crtc *crtc,
  *only be false for primary planes.
  * @can_update_disabled: can the plane be updated while the crtc
  *   is disabled?
- * @visible: output parameter indicating whether plane is still visible after
- *   clipping
  *
- * Checks that a desired plane update is valid.  Drivers that provide
+ * Checks that a desired plane update is valid, and updates various
+ * bits of derived state (clipped coordinates etc.). Drivers that provide
  * their own plane handling rather than helper-provided implementations may
  * still wish to call this function to avoid duplication of error checking
  * code.
@@ -134,29 +128,38 @@ static int get_connectors_for_crtc(struct drm_crtc *crtc,
  * RETURNS:
  * Zero if update appears valid, error code on failure
  */
-int drm_plane_helper_check_update(struct drm_plane *plane,
- struct drm_crtc *crtc,
- struct drm_framebuffer *fb,
- struct drm_rect *src,
- struct drm_rect *dest,
- const struct drm_rect *clip,
- unsigned int rotation,
- int min_scale,
- int max_scale,
- bool can_position,
- bool can_update_disabled,
- bool *visible)
+int drm_plane_helper_check_state(struct drm_plane_state *state,
+const struct drm_rect *clip,
+int min_scale,
+int max_scale,
+bool can_position,
+bool can_update_disabled)
 {
+   struct drm_crtc *crtc = state->crtc;
+   struct drm_framebuffer *fb = state->fb;
+   struct drm_rect *src = &state->src;
+   struct drm_rect *dst = &state->dst;
+   unsigned int rotation = state->rotation;
int hscale, vscale;

+   src->x1 = state->src_x;
+   src->y1 = state->src_y;
+   src->x2 = state->src_x + state->src_w;
+   src->y2 = state->src_y + state->src_h;
+
+   dst->x1 = state->crtc_x;
+   dst->y1 = state->crtc_y;
+   dst->x2 = state->crtc_x + state->crtc_w;
+   dst->y2 = state->crtc_y + state->crtc_h;
+
if (!fb) {
-   *visible = false;
+   state->visible = false;
return 0;
}

/* crtc should only be NULL when disabling (i.e., !fb) */
if (WARN_ON(!crtc)) {
-   *visible = false;
+   state->visible = false;
return 0;
}

@@ -168,20 +171,20 @@ int drm_plane_helper_check_update(struct drm_plane *plane,
drm_rect_rotate(src, fb->width << 16, fb->height << 16, rotation);

/* Check scaling */
-   hscale = drm_rect_calc_hscale(src, dest, min_scale, max_scale);
-   vscale = drm_rect_calc_vscale(src, dest, min_scale, max_scale);
+   hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
+   vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
if (hsc

[PATCH] drm: Don't force all planes to be added to the state due to zpos

2016-10-10 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

We don't want all planes to be added to the state whenever a
plane with fixed zpos gets enabled/disabled. This is true
especially for eg. cursor planes on i915, as we want cursor
updates to go through w/o throttling. Same holds for drivers
that don't support zpos at all (i915 actually falls into this
category right now since we've not yet added zpos support).

Allow drivers more freedom by letting them deal with zpos
themselves instead of doing it in drm_atomic_helper_check_planes()
unconditionally. Easiest solution seems to be to move the call
up to drm_atomic_helper_check(). But as some drivers might want
to use that function without the zpos handling, let's provide
two variants: the normal one, and one that deals with zpos.

Cc: Marek Szyprowski 
Cc: Benjamin Gaignard 
Cc: Vincent Abriou 
Cc: Laurent Pinchart 
Cc: Inki Dae 
Cc: Joonyoung Shim 
Cc: Seung-Woo Kim 
Cc: Kyungmin Park 
Cc: Lyude 
Cc: Maarten Lankhorst 
Cc: stable at vger.kernel.org
Fixes: 44d1240d006c ("drm: add generic zpos property")
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_atomic_helper.c| 46 +++---
 drivers/gpu/drm/exynos/exynos_drm_fb.c |  2 +-
 drivers/gpu/drm/rcar-du/rcar_du_kms.c  |  2 +-
 drivers/gpu/drm/sti/sti_drv.c  |  2 +-
 include/drm/drm_atomic_helper.h|  2 ++
 5 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index c3f83476f996..cd19281cdefb 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -594,10 +594,6 @@ drm_atomic_helper_check_planes(struct drm_device *dev,
struct drm_plane_state *plane_state;
int i, ret = 0;

-   ret = drm_atomic_normalize_zpos(dev, state);
-   if (ret)
-   return ret;
-
for_each_plane_in_state(state, plane, plane_state, i) {
const struct drm_plane_helper_funcs *funcs;

@@ -673,6 +669,48 @@ int drm_atomic_helper_check(struct drm_device *dev,
 }
 EXPORT_SYMBOL(drm_atomic_helper_check);

+/**
+ * drm_atomic_helper_check_with_zpos - validate state object, dealing with zpos
+ * @dev: DRM device
+ * @state: the driver state object
+ *
+ * Check the state object to see if the requested state is physically possible.
+ * Only crtcs and planes have check callbacks, so for any additional (global)
+ * checking that a driver needs it can simply wrap that around this function.
+ * Drivers without such needs can directly use this as their ->atomic_check()
+ * callback.
+ *
+ * This just wraps the two parts of the state checking for planes and modeset
+ * state in the default order: First it calls 
drm_atomic_helper_check_modeset(),
+ * followed by drm_atomic_normalize_zpos(), and finally
+ * drm_atomic_helper_check_planes(). The assumption is that the
+ * ->atomic_check functions depend upon an updated adjusted_mode.clock to
+ * e.g. properly compute watermarks.
+ *
+ * RETURNS:
+ * Zero for success or -errno
+ */
+int drm_atomic_helper_check_with_zpos(struct drm_device *dev,
+ struct drm_atomic_state *state)
+{
+   int ret;
+
+   ret = drm_atomic_helper_check_modeset(dev, state);
+   if (ret)
+   return ret;
+
+   ret = drm_atomic_normalize_zpos(dev, state);
+   if (ret)
+   return ret;
+
+   ret = drm_atomic_helper_check_planes(dev, state);
+   if (ret)
+   return ret;
+
+   return ret;
+}
+EXPORT_SYMBOL(drm_atomic_helper_check_with_zpos);
+
 static void
 disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state)
 {
diff --git a/drivers/gpu/drm/exynos/exynos_drm_fb.c 
b/drivers/gpu/drm/exynos/exynos_drm_fb.c
index 40ce841eb952..5c0930af01fa 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_fb.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_fb.c
@@ -190,7 +190,7 @@ dma_addr_t exynos_drm_fb_dma_addr(struct drm_framebuffer 
*fb, int index)
 static const struct drm_mode_config_funcs exynos_drm_mode_config_funcs = {
.fb_create = exynos_user_fb_create,
.output_poll_changed = exynos_drm_output_poll_changed,
-   .atomic_check = drm_atomic_helper_check,
+   .atomic_check = drm_atomic_helper_check_with_zpos,
.atomic_commit = exynos_atomic_commit,
 };

diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.c 
b/drivers/gpu/drm/rcar-du/rcar_du_kms.c
index bd9c3bb9252c..2cfd35f3f2f6 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_kms.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.c
@@ -231,7 +231,7 @@ static int rcar_du_atomic_check(struct drm_device *dev,
struct rcar_du_device *rcdu = dev->dev_private;
int ret;

-   ret = drm_atomic_helper_check(dev, state);
+   ret = drm_atomic_helper_check_with_zpos(dev, state);
if (ret < 0)
return ret;

diff --git a/drivers/gpu/drm/sti/sti_drv.c b/drivers/gpu/drm/sti/sti_drv.c
index 2784919a7366..df5f150021d0 100644
--- a/drivers/gpu/drm/

[PATCH v2] drm: Don't force all planes to be added to the state due to zpos

2016-10-10 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

We don't want all planes to be added to the state whenever a
plane with fixed zpos gets enabled/disabled. This is true
especially for eg. cursor planes on i915, as we want cursor
updates to go through w/o throttling. Same holds for drivers
that don't support zpos at all (i915 actually falls into this
category right now since we've not yet added zpos support).

Allow drivers more freedom by letting them deal with zpos
themselves instead of doing it in drm_atomic_helper_check_planes()
unconditionally. Let's just inline the required calls into all
the driver that currently depend on this.

v2: Inline the stuff into the drivers instead of adding another
helper, document things better (Daniel)

Cc: Daniel Vetter 
Cc: Marek Szyprowski 
Cc: Benjamin Gaignard 
Cc: Vincent Abriou 
Cc: Laurent Pinchart 
Cc: Inki Dae 
Cc: Joonyoung Shim 
Cc: Seung-Woo Kim 
Cc: Kyungmin Park 
Cc: Lyude 
Cc: Maarten Lankhorst 
Cc: stable at vger.kernel.org
Fixes: 44d1240d006c ("drm: add generic zpos property")
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_atomic_helper.c |  4 
 drivers/gpu/drm/exynos/exynos_drm_drv.c | 20 
 drivers/gpu/drm/exynos/exynos_drm_drv.h |  1 +
 drivers/gpu/drm/exynos/exynos_drm_fb.c  |  2 +-
 drivers/gpu/drm/rcar-du/rcar_du_kms.c   | 12 ++--
 drivers/gpu/drm/sti/sti_drv.c   | 22 +-
 include/drm/drm_plane.h |  8 +++-
 7 files changed, 60 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index c3f83476f996..21f992605541 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -594,10 +594,6 @@ drm_atomic_helper_check_planes(struct drm_device *dev,
struct drm_plane_state *plane_state;
int i, ret = 0;

-   ret = drm_atomic_normalize_zpos(dev, state);
-   if (ret)
-   return ret;
-
for_each_plane_in_state(state, plane, plane_state, i) {
const struct drm_plane_helper_funcs *funcs;

diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c 
b/drivers/gpu/drm/exynos/exynos_drm_drv.c
index def78c8c1780..f86e7c846678 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
@@ -262,6 +262,26 @@ int exynos_atomic_commit(struct drm_device *dev, struct 
drm_atomic_state *state,
return 0;
 }

+int exynos_atomic_check(struct drm_device *dev,
+   struct drm_atomic_state *state)
+{
+   int ret;
+
+   ret = drm_atomic_helper_check_modeset(dev, state);
+   if (ret)
+   return ret;
+
+   ret = drm_atomic_normalize_zpos(dev, state);
+   if (ret)
+   return ret;
+
+   ret = drm_atomic_helper_check_planes(dev, state);
+   if (ret)
+   return ret;
+
+   return ret;
+}
+
 static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
 {
struct drm_exynos_file_private *file_priv;
diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.h 
b/drivers/gpu/drm/exynos/exynos_drm_drv.h
index d215149e737b..80c4d5b81689 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.h
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.h
@@ -301,6 +301,7 @@ static inline int exynos_dpi_bind(struct drm_device *dev,

 int exynos_atomic_commit(struct drm_device *dev, struct drm_atomic_state 
*state,
 bool nonblock);
+int exynos_atomic_check(struct drm_device *dev, struct drm_atomic_state 
*state);


 extern struct platform_driver fimd_driver;
diff --git a/drivers/gpu/drm/exynos/exynos_drm_fb.c 
b/drivers/gpu/drm/exynos/exynos_drm_fb.c
index 40ce841eb952..23cce0a3f5fc 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_fb.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_fb.c
@@ -190,7 +190,7 @@ dma_addr_t exynos_drm_fb_dma_addr(struct drm_framebuffer 
*fb, int index)
 static const struct drm_mode_config_funcs exynos_drm_mode_config_funcs = {
.fb_create = exynos_user_fb_create,
.output_poll_changed = exynos_drm_output_poll_changed,
-   .atomic_check = drm_atomic_helper_check,
+   .atomic_check = exynos_atomic_check,
.atomic_commit = exynos_atomic_commit,
 };

diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.c 
b/drivers/gpu/drm/rcar-du/rcar_du_kms.c
index bd9c3bb9252c..392c7e6de042 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_kms.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.c
@@ -231,8 +231,16 @@ static int rcar_du_atomic_check(struct drm_device *dev,
struct rcar_du_device *rcdu = dev->dev_private;
int ret;

-   ret = drm_atomic_helper_check(dev, state);
-   if (ret < 0)
+   ret = drm_atomic_helper_check_modeset(dev, state);
+   if (ret)
+   return ret;
+
+   ret = drm_atomic_normalize_zpos(dev, state);
+   if (ret)
+   return ret;
+
+   ret = drm_atomic_helper_check_planes(dev, state);
+   if (ret)
return ret;

 

[PATCH 0/6] drm/i915: Remaining PSR fixes

2016-05-31 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

Here's a repost of my PSR fixes, and one straggler from Daniel.

One interesting thing I noticed is that my SKL actually hits the PSR setup
time vs. vblank length check, so after these patches that machine won't
actually use PSR. The panel does support a lower refresh rate timing as well
though which doesn't suffer from this limitation, so I hacked the code to
use that mode instead, and PSR did seem to work without problems. With the
original mode I had some screen stalls while running xonotic, which I'm
going to assume were due to the setup time exceeding the safe limit.

I also hooked up the PSR interrupts for BDW+ and pushed the patches to [1],
but I'm not including those patches here since the PSR interrupts don't
seem to gain us anything useful in practice.

[1] git://github.com/vsyrjala/linux.git psr_interrupts

Daniel Vetter (1):
  drm/i915/psr: Skip aux handeshake if the vbt tells us to

Ville Syrjälä (5):
  drm/dp: Add drm_dp_psr_setup_time()
  drm/dp: Add drm_dp_psr_need_train_on_exit()
  drm/i915: Check PSR setup time vs. vblank length
  drm/i915: Ask the sink whether training is required when exiting PSR
main-link off mode
  drm/i915: Move psr.link_standby setup to intel_psr_match_conditions()

 drivers/gpu/drm/drm_dp_helper.c | 46 ++
 drivers/gpu/drm/i915/intel_drv.h|  2 ++
 drivers/gpu/drm/i915/intel_psr.c| 64 +
 drivers/gpu/drm/i915/intel_sprite.c |  6 ++--
 include/drm/drm_dp_helper.h |  3 ++
 5 files changed, 97 insertions(+), 24 deletions(-)

-- 
2.7.4



[PATCH v2 1/6] drm/dp: Add drm_dp_psr_setup_time()

2016-05-31 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

Add a small helper to parse the PSR setup time from the DPCD PSR
capabilities and return the value in microseconds.

v2: Don't waste so many bytes on the psr_setup_time_us[] table

Cc: Daniel Vetter 
Reviewed-by: Daniel Vetter 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_dp_helper.c | 32 
 include/drm/drm_dp_helper.h |  2 ++
 2 files changed, 34 insertions(+)

diff --git a/drivers/gpu/drm/drm_dp_helper.c b/drivers/gpu/drm/drm_dp_helper.c
index eeaf5a7c3aa7..1f914629031e 100644
--- a/drivers/gpu/drm/drm_dp_helper.c
+++ b/drivers/gpu/drm/drm_dp_helper.c
@@ -822,3 +822,35 @@ void drm_dp_aux_unregister(struct drm_dp_aux *aux)
i2c_del_adapter(&aux->ddc);
 }
 EXPORT_SYMBOL(drm_dp_aux_unregister);
+
+#define PSR_SETUP_TIME(x) [DP_PSR_SETUP_TIME_ ## x >> DP_PSR_SETUP_TIME_SHIFT] 
= (x)
+
+/**
+ * drm_dp_psr_setup_time() - PSR setup in time usec
+ * @psr_cap: PSR capabilities from DPCD
+ *
+ * Returns:
+ * PSR setup time for the panel in microseconds,  negative
+ * error code on failure.
+ */
+int drm_dp_psr_setup_time(const u8 psr_cap[EDP_PSR_RECEIVER_CAP_SIZE])
+{
+   static const u16 psr_setup_time_us[] = {
+   PSR_SETUP_TIME(330),
+   PSR_SETUP_TIME(275),
+   PSR_SETUP_TIME(165),
+   PSR_SETUP_TIME(110),
+   PSR_SETUP_TIME(55),
+   PSR_SETUP_TIME(0),
+   };
+   int i;
+
+   i = (psr_cap[1] & DP_PSR_SETUP_TIME_MASK) >> DP_PSR_SETUP_TIME_SHIFT;
+   if (i >= ARRAY_SIZE(psr_setup_time_us))
+   return -EINVAL;
+
+   return psr_setup_time_us[i];
+}
+EXPORT_SYMBOL(drm_dp_psr_setup_time);
+
+#undef PSR_SETUP_TIME
diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h
index 5a848e734422..6aa74f7d45b4 100644
--- a/include/drm/drm_dp_helper.h
+++ b/include/drm/drm_dp_helper.h
@@ -657,6 +657,8 @@ struct edp_vsc_psr {
 #define EDP_VSC_PSR_UPDATE_RFB (1<<1)
 #define EDP_VSC_PSR_CRC_VALUES_VALID   (1<<2)

+int drm_dp_psr_setup_time(const u8 psr_cap[EDP_PSR_RECEIVER_CAP_SIZE]);
+
 static inline int
 drm_dp_max_link_rate(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
 {
-- 
2.7.4



[PATCH v2 2/6] drm/dp: Add drm_dp_psr_need_train_on_exit()

2016-05-31 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

Add a small helper to parse from the DPCD whether link training
is required when exiting PSR main-link off mode.

v2: Rebased

Cc: Daniel Vetter 
Reviewed-by: Daniel Vetter 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/drm_dp_helper.c | 14 ++
 include/drm/drm_dp_helper.h |  1 +
 2 files changed, 15 insertions(+)

diff --git a/drivers/gpu/drm/drm_dp_helper.c b/drivers/gpu/drm/drm_dp_helper.c
index 1f914629031e..cc7b55a695b5 100644
--- a/drivers/gpu/drm/drm_dp_helper.c
+++ b/drivers/gpu/drm/drm_dp_helper.c
@@ -854,3 +854,17 @@ int drm_dp_psr_setup_time(const u8 
psr_cap[EDP_PSR_RECEIVER_CAP_SIZE])
 EXPORT_SYMBOL(drm_dp_psr_setup_time);

 #undef PSR_SETUP_TIME
+
+/**
+ * drm_dp_psr_need_train_on_exit() - Indicate whether link training is needed 
on PSR exit
+ * @psr_cap: PSR capabilities from DPCD
+ *
+ * Returns:
+ * Whether link training is required when exiting PSR main-link off mode.
+ */
+bool drm_dp_psr_need_train_on_exit(const u8 psr_cap[EDP_PSR_RECEIVER_CAP_SIZE])
+{
+   /* DP_PSR_NO_TRAIN_ON_EXIT is "don't care" for PSR2 capable devices */
+   return psr_cap[0] < 0x2 && (psr_cap[1] & DP_PSR_NO_TRAIN_ON_EXIT) == 0;
+}
+EXPORT_SYMBOL(drm_dp_psr_need_train_on_exit);
diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h
index 6aa74f7d45b4..2437f1b6e776 100644
--- a/include/drm/drm_dp_helper.h
+++ b/include/drm/drm_dp_helper.h
@@ -658,6 +658,7 @@ struct edp_vsc_psr {
 #define EDP_VSC_PSR_CRC_VALUES_VALID   (1<<2)

 int drm_dp_psr_setup_time(const u8 psr_cap[EDP_PSR_RECEIVER_CAP_SIZE]);
+bool drm_dp_psr_need_train_on_exit(const u8 
psr_cap[EDP_PSR_RECEIVER_CAP_SIZE]);

 static inline int
 drm_dp_max_link_rate(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
-- 
2.7.4



[PATCH 3/6] drm/i915: Check PSR setup time vs. vblank length

2016-05-31 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

Bspec says:
"Restriction : SRD must not be enabled when the PSR Setup time from DPCD
00071h is greater than the time for vertical blank minus one line."

Let's check for that and disallow PSR if we exceed the limit.

Cc: Daniel Vetter 
Reviewed-by: Daniel Vetter 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_drv.h|  2 ++
 drivers/gpu/drm/i915/intel_psr.c| 19 ++-
 drivers/gpu/drm/i915/intel_sprite.c |  6 +++---
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index 9b5f6634c558..56ae3b78e25e 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -1672,6 +1672,8 @@ bool intel_sdvo_init(struct drm_device *dev,


 /* intel_sprite.c */
+int intel_usecs_to_scanlines(const struct drm_display_mode *adjusted_mode,
+int usecs);
 int intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane);
 int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
  struct drm_file *file_priv);
diff --git a/drivers/gpu/drm/i915/intel_psr.c b/drivers/gpu/drm/i915/intel_psr.c
index 29a09bf6bd18..aacd8d1767f2 100644
--- a/drivers/gpu/drm/i915/intel_psr.c
+++ b/drivers/gpu/drm/i915/intel_psr.c
@@ -327,6 +327,9 @@ static bool intel_psr_match_conditions(struct intel_dp 
*intel_dp)
struct drm_i915_private *dev_priv = dev->dev_private;
struct drm_crtc *crtc = dig_port->base.base.crtc;
struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
+   const struct drm_display_mode *adjusted_mode =
+   &intel_crtc->config->base.adjusted_mode;
+   int psr_setup_time;

lockdep_assert_held(&dev_priv->psr.lock);
WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
@@ -365,11 +368,25 @@ static bool intel_psr_match_conditions(struct intel_dp 
*intel_dp)
}

if (IS_HASWELL(dev) &&
-   intel_crtc->config->base.adjusted_mode.flags & 
DRM_MODE_FLAG_INTERLACE) {
+   adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
DRM_DEBUG_KMS("PSR condition failed: Interlaced is Enabled\n");
return false;
}

+   psr_setup_time = drm_dp_psr_setup_time(intel_dp->psr_dpcd);
+   if (psr_setup_time < 0) {
+   DRM_DEBUG_KMS("PSR condition failed: Invalid PSR setup time 
(0x%02x)\n",
+ intel_dp->psr_dpcd[1]);
+   return false;
+   }
+
+   if (intel_usecs_to_scanlines(adjusted_mode, psr_setup_time) >
+   adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vdisplay - 1) {
+   DRM_DEBUG_KMS("PSR condition failed: PSR setup time (%d us) too 
long\n",
+ psr_setup_time);
+   return false;
+   }
+
dev_priv->psr.source_ok = true;
return true;
 }
diff --git a/drivers/gpu/drm/i915/intel_sprite.c 
b/drivers/gpu/drm/i915/intel_sprite.c
index 324ccb06397d..293b48007006 100644
--- a/drivers/gpu/drm/i915/intel_sprite.c
+++ b/drivers/gpu/drm/i915/intel_sprite.c
@@ -53,8 +53,8 @@ format_is_yuv(uint32_t format)
}
 }

-static int usecs_to_scanlines(const struct drm_display_mode *adjusted_mode,
- int usecs)
+int intel_usecs_to_scanlines(const struct drm_display_mode *adjusted_mode,
+int usecs)
 {
/* paranoia */
if (!adjusted_mode->crtc_htotal)
@@ -91,7 +91,7 @@ void intel_pipe_update_start(struct intel_crtc *crtc)
vblank_start = DIV_ROUND_UP(vblank_start, 2);

/* FIXME needs to be calibrated sensibly */
-   min = vblank_start - usecs_to_scanlines(adjusted_mode, 100);
+   min = vblank_start - intel_usecs_to_scanlines(adjusted_mode, 100);
max = vblank_start - 1;

local_irq_disable();
-- 
2.7.4



[PATCH 4/6] drm/i915/psr: Skip aux handeshake if the vbt tells us to

2016-05-31 Thread ville.syrj...@linux.intel.com
From: Daniel Vetter 

Not sure we can trust VBT on this one, but let's try.

Cc: Rodrigo Vivi 
Cc: Sonika Jindal 
Cc: Durgadoss R 
Signed-off-by: Daniel Vetter 
Reviewed-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_psr.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/i915/intel_psr.c b/drivers/gpu/drm/i915/intel_psr.c
index aacd8d1767f2..c073cbbf1b91 100644
--- a/drivers/gpu/drm/i915/intel_psr.c
+++ b/drivers/gpu/drm/i915/intel_psr.c
@@ -298,6 +298,9 @@ static void hsw_psr_enable_source(struct intel_dp *intel_dp)
else
val |= EDP_PSR_TP1_TP2_SEL;

+   if (!dev_priv->vbt.psr.require_aux_wakeup)
+   val |= EDP_PSR_SKIP_AUX_EXIT;
+
I915_WRITE(EDP_PSR_CTL, val);

if (!dev_priv->psr.psr2_support)
-- 
2.7.4



[PATCH 5/6] drm/i915: Ask the sink whether training is required when exiting PSR main-link off mode

2016-05-31 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

The sink can tell us if link training needs to be performed when
exiting PSR main-link off mode. Currently we get that information
from the VBT, but at least on my HSW the VBT says one thing, the sink
another. And in practice the sink doesn't seem to notice any screen
updates unless we do the training.

Reviewed-by: Daniel Vetter 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_psr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/intel_psr.c b/drivers/gpu/drm/i915/intel_psr.c
index c073cbbf1b91..4db9c26fb970 100644
--- a/drivers/gpu/drm/i915/intel_psr.c
+++ b/drivers/gpu/drm/i915/intel_psr.c
@@ -298,7 +298,8 @@ static void hsw_psr_enable_source(struct intel_dp *intel_dp)
else
val |= EDP_PSR_TP1_TP2_SEL;

-   if (!dev_priv->vbt.psr.require_aux_wakeup)
+   if (!dev_priv->vbt.psr.require_aux_wakeup &&
+   !drm_dp_psr_need_train_on_exit(intel_dp->psr_dpcd))
val |= EDP_PSR_SKIP_AUX_EXIT;

I915_WRITE(EDP_PSR_CTL, val);
-- 
2.7.4



[PATCH 6/6] drm/i915: Move psr.link_standby setup to intel_psr_match_conditions()

2016-05-31 Thread ville.syrj...@linux.intel.com
From: Ville Syrjälä 

Determine the value of psr.link_standby at runtime rather than at init
time. This helps in testing since you can change between link-off and
link-standby at runtime.

Reviewed-by: Daniel Vetter 
Signed-off-by: Ville Syrjälä 
---
 drivers/gpu/drm/i915/intel_psr.c | 41 
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_psr.c b/drivers/gpu/drm/i915/intel_psr.c
index 4db9c26fb970..8c70420cc6db 100644
--- a/drivers/gpu/drm/i915/intel_psr.c
+++ b/drivers/gpu/drm/i915/intel_psr.c
@@ -339,6 +339,27 @@ static bool intel_psr_match_conditions(struct intel_dp 
*intel_dp)
WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
WARN_ON(!drm_modeset_is_locked(&crtc->mutex));

+   /* Set link_standby x link_off defaults */
+   if (IS_HASWELL(dev) || IS_BROADWELL(dev))
+   /* HSW and BDW require workarounds that we don't implement. */
+   dev_priv->psr.link_standby = false;
+   else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
+   /* On VLV and CHV only standby mode is supported. */
+   dev_priv->psr.link_standby = true;
+   else
+   /* For new platforms let's respect VBT back again */
+   dev_priv->psr.link_standby = dev_priv->vbt.psr.full_link;
+
+   /* Override link_standby x link_off defaults */
+   if (i915.enable_psr == 2 && !dev_priv->psr.link_standby) {
+   DRM_DEBUG_KMS("PSR: Forcing link standby\n");
+   dev_priv->psr.link_standby = true;
+   }
+   if (i915.enable_psr == 3 && dev_priv->psr.link_standby) {
+   DRM_DEBUG_KMS("PSR: Forcing main link off\n");
+   dev_priv->psr.link_standby = false;
+   }
+
dev_priv->psr.source_ok = false;

/*
@@ -830,26 +851,6 @@ void intel_psr_init(struct drm_device *dev)
i915.enable_psr = 0;
}

-   /* Set link_standby x link_off defaults */
-   if (IS_HASWELL(dev) || IS_BROADWELL(dev))
-   /* HSW and BDW require workarounds that we don't implement. */
-   dev_priv->psr.link_standby = false;
-   else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
-   /* On VLV and CHV only standby mode is supported. */
-   dev_priv->psr.link_standby = true;
-   else
-   /* For new platforms let's respect VBT back again */
-   dev_priv->psr.link_standby = dev_priv->vbt.psr.full_link;
-
-   /* Override link_standby x link_off defaults */
-   if (i915.enable_psr == 2 && !dev_priv->psr.link_standby) {
-   DRM_DEBUG_KMS("PSR: Forcing link standby\n");
-   dev_priv->psr.link_standby = true;
-   }
-   if (i915.enable_psr == 3 && dev_priv->psr.link_standby) {
-   DRM_DEBUG_KMS("PSR: Forcing main link off\n");
-   dev_priv->psr.link_standby = false;
-   }

INIT_DELAYED_WORK(&dev_priv->psr.work, intel_psr_work);
mutex_init(&dev_priv->psr.lock);
-- 
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ä 

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



[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ä 

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] drm/edid: Add the missing "Hz" to VIC 58,59 comment

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

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] drm/edid: Consider alternate cea timings to be the same VIC

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

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 = &edid_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(&cea_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, 
&cea_mode))
+   return vic;
+   } while (cea_mode_alternate_timings(vic, &cea_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 = &edid_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(&cea_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, 
&cea_mode))
+   return vic;
+   } while (cea_mode_alternate_timings(vic, &cea_mode));
}
+
return 0;
 }
 EXPORT_SYMBOL(drm_match_cea_mode);
-- 

[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ä 

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



[RFC][PATCH] drm: Nuke modifier[1-3]

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

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, 
&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(&dest));
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],
+  fbdev_fb->base.modifier,
   drm_framebuffer_read_refcount(&fbdev_fb->base));
describe_obj(m, fbdev_fb->obj);
seq_putc(m, '\n');
@@ -1915,7 +1915,7 @@ static int i915_ge

[PATCH 00/32] drm: Deduplicate fb format information

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

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_fimd.c|  4 +-
 drivers/gpu/drm/exynos/exynos_mixer.c   | 12 ++--
 drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_p

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

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

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 03/32] drm/radeon: Use DIV_ROUND_UP()

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

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ä 

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 = &rdev->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 = &rdev->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 05/32] drm/ast: Add local 'fb' variables

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

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 = &vbios_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 07/32] drm/cirrus: Add some local 'fb' variables

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

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ä 

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 = &dev_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 = &dev_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 --git a/drivers/gpu/drm/gma500/oaktrail_crtc.c 
b/drivers/gpu/drm/gma500/oaktrail_crtc.c
index da9fd34b9550..a51896544d91 100644
--- a/drivers/gpu/drm/gma500/oaktrail_crtc.c
+++ b/drivers/gpu/drm/gma500/oaktrail_crtc.c
@@ -599,7 +599,8 @@ static int oaktrail_pipe_set_base(struct drm_crtc *crtc,
struct

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

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

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 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ä 

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 11/32] drm/nouveau: Add local 'fb' variables

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

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 = 
&nv04_display(dev)->mode_reg.crtc_reg[nv_crtc->index];
struct nv04_crtc_reg *savep = 
&nv04_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 = &nv_encoder->mode;
struct drm_connector *connector = &nv_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 09/32] drm/arm: Add local 'fb' variables

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

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 12/32] drm/vmwgfx: Populate fb->dev before drm_framebuffer_init()

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

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 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ä 

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(&rfb->base, mode_cmd);
+   drm_helper_mode_fill_fb_struct(dev, &rfb->base, mode_cmd);
ret = drm_framebuffer_init(dev, &rfb->base, &amdgpu_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(&dfb->fb, mode);
+   drm_helper_mode_fill_fb_struct(dev, &dfb->fb, mode);

ret = drm_framebuffer_init(dev, &dfb->fb, &armada_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(&ast_fb->base, mode_cmd);
+   drm_helper_mode_fill_fb_struct(dev, &ast_fb->base, mode_cmd);
ast_fb->obj = obj;
ret = drm_framebuffer_init(dev, &ast_fb->base, &ast_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(&gfb->base, mode_cmd);
+   drm_helper_mode_fill_fb_struct(dev, &gfb->base, mode_cmd);
gfb->obj = obj;
ret = drm_framebuffer_init(dev, &gfb->base, &bochs_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(&gfb->base, mode_c

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

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

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 08/32] drm/arcpgu: Add local 'fb' variables

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

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 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ä 

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, &qfb->base, mode_cmd);
ret = drm_framebuffer_init(dev, &qfb->base, funcs);
if (ret) {
qfb->obj = NULL;
return ret;
}
-   drm_helper_mode_fill_fb_struct(dev, &qfb->base, mode_cmd);
return 0;
 }

-- 
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ä 

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, &vgfb->base, mode_cmd);
+
ret = drm_framebuffer_init(dev, &vgfb->base, &virtio_gpu_fb_funcs);
if (ret) {
vgfb->obj = NULL;
return ret;
}
-   drm_helper_mode_fill_fb_struct(dev, &vgfb->base, mode_cmd);

spin_lock_init(&vgfb->dirty_lock);
vgfb->x1 = vgfb->y1 = INT_MAX;
-- 
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ä 

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(&fb->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, &fb->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 20/32] drm/vmwgfx: Populate fb->format correctly

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

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 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ä 

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 = &intel_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 = &intel_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 = &intel_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 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ä 

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(&fb->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, &fb->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 21/32] drm/i915: Populate fb->format early for inherited fbs

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

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 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ä 

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 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ä 

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(&fbc->compressed_fb));

size = intel_fbc_calculate_cfb_size(dev_priv, &fbc->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, &fbc->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 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ä 

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 *)&fb->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 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ä 

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(&asyw->state, &asyw->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 28/32] drm: Add drm_framebuffer_plane_{width,height}()

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

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);
\
 &fb->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 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ä 

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
@@ -652,7 +652,7 @@ static void pineview_update_wm(struct intel_crtc 
*unused_crtc)
&crtc->config->base.adjusted_mode;
const struct drm_framebuffer *fb =
crt

[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ä 

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 31/32] drm: Nuke fb->bits_per_pixel

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

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 +++---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c   |  2 --
 drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c   |  4 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c  |  2 +-
 drivers/gpu/drm/vmwgfx/vmwg

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

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

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 = &amdgpufb_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 = &dfb->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_DEBUG_KMS("allocated %dx%d %dbpp fb: 0x%08llx\n",
diff --git a/drivers/gpu/drm/ast/ast_fb.c b/drivers/gpu/drm/ast/ast_fb.c
index d6f5ec64c667..f751792a3c7c 100644
--- a/drivers/gpu/drm/ast/ast_fb.c
+++ b/drivers/gpu/drm/ast/ast_fb.c
@@ 

[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ä 

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 = &intel_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(&x, &y, fb, i);

-- 
2.7.4



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

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

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.c|  4 +--
 drivers/gpu/drm/tilcdc/tilcdc_plane.c   |  4 +--
 drivers/gpu/drm/vc4/vc4_plane.c |  6 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c

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

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

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/udl_fb.c  |  2 +-
 drivers/gpu/drm/virtio/virtgpu_fb.c   |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_fb.c|  6 +++---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c   |  2

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

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

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   |   3 +-
 drivers/gpu/drm/drm_fb_cma_helper.c |  13 ++-
 drivers/gpu/drm/drm_fb_helper.c | 

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

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

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 02/37] drm/radeon: Add local 'fb' variables

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

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 = &rdev->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 = &rdev->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 03/37] drm/radeon: Use DIV_ROUND_UP()

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

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 04/37] drm/mgag200: Add local 'fb' variable

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

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 05/37] drm/ast: Add local 'fb' variables

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

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 = &vbios_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 08/37] drm/arcpgu: Add local 'fb' variables

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

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 09/37] drm/arm: Add local 'fb' variables

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

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 07/37] drm/cirrus: Add some local 'fb' variables

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

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 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ä 

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 12/37] drm/vmwgfx: Populate fb->dev before drm_framebuffer_init()

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

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 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ä 

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(&rfb->base, mode_cmd);
+   drm_helper_mode_fill_fb_struct(dev, &rfb->base, mode_cmd);
ret = drm_framebuffer_init(dev, &rfb->base, &amdgpu_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(&dfb->fb, mode);
+   drm_helper_mode_fill_fb_struct(dev, &dfb->fb, mode);

ret = drm_framebuffer_init(dev, &dfb->fb, &armada_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(&ast_fb->base, mode_cmd);
+   drm_helper_mode_fill_fb_struct(dev, &ast_fb->base, mode_cmd);
ast_fb->obj = obj;
ret = drm_framebuffer_init(dev, &ast_fb->base, &ast_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(&gfb->base, mode_cmd);
+   drm_helper_mode_fill_fb_struct(dev, &gfb->base, mode_cmd);
gfb->obj = obj;
ret = drm_framebuffer_init(dev, &gfb->base, &bochs_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;

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

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

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 = &dev_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 = &dev_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 --git a/drivers/gpu/drm/gma500/oaktrail_crtc.c 
b/drivers/gpu/drm/gma500/oaktrail_crtc.c
index da9fd34b9550..a51896544d91 100644
--- a/drivers/gpu/drm/gma500/oaktrail_crtc.c
+++ b/drivers/gpu/drm/gma500/oaktrail_crtc.c
@@ -599,7 +599,8 @@ static int oaktrail_pipe_set_base(struct drm_crtc *crtc,
struct

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

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

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 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ä 

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, &qfb->base, mode_cmd);
ret = drm_framebuffer_init(dev, &qfb->base, funcs);
if (ret) {
qfb->obj = NULL;
return ret;
}
-   drm_helper_mode_fill_fb_struct(dev, &qfb->base, mode_cmd);
return 0;
 }

-- 
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ä 

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 = &intel_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 = &intel_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 = &intel_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 11/37] drm/nouveau: Add local 'fb' variables

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

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 = 
&nv04_display(dev)->mode_reg.crtc_reg[nv_crtc->index];
struct nv04_crtc_reg *savep = 
&nv04_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 = &nv_encoder->mode;
struct drm_connector *connector = &nv_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 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ä 

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, &vgfb->base, mode_cmd);
+
ret = drm_framebuffer_init(dev, &vgfb->base, &virtio_gpu_fb_funcs);
if (ret) {
vgfb->obj = NULL;
return ret;
}
-   drm_helper_mode_fill_fb_struct(dev, &vgfb->base, mode_cmd);

spin_lock_init(&vgfb->dirty_lock);
vgfb->x1 = vgfb->y1 = INT_MAX;
-- 
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ä 

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 21/37] drm/i915: Populate fb->format early for inherited fbs

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

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 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ä 

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(&fb->filp_head);
-   fb->dev = dev;
+
fb->funcs = funcs;

ret = drm_mode_object_get_reg(dev, &fb->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 20/37] drm/vmwgfx: Populate fb->format correctly

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

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 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ä 

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(&fb->filp_head);
-- 
2.7.4



[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ä 

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(&pstate->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 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ä 

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 *)&fb->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 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ä 

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_name;

drm_printf(p, "\t\tformat=%s\n",
diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index c45da6766fff..c19d8bdf46d8 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i

[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ä 

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(&fbc->compressed_fb));

size = intel_fbc_calculate_cfb_size(dev_priv, &fbc->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, &fbc->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 29/37] drm: Add drm_framebuffer_plane_{width,height}()

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

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);
\
 &fb->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/37] drm/nouveau: Use fb->format rather than drm_format_info()

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

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(&asyw->state, &asyw->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 v2 32/37] drm: Nuke fb->bits_per_pixel

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

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/udl/udl_fb.c  |  2 +-
 drivers/gpu/drm/virtio/virtgpu_fb.c   |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_fb.c|  6 +++---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c  

[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ä 

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_atomic_check(struct drm_plane *plane,
 */
if (old_fb && (state->src_w != old_state->src_w ||
  state->src_h != old_state->src_h ||
- fb->format->format != old_fb->format->format))
+ fb->format != old_fb->format))
crtc_state->mode_changed = true;

eba = drm_plane_state_to_eba(state)

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

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

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 = &amdgpufb_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 = &dfb->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_DEBUG_KMS("allocated %dx%d %dbpp fb: 0x%08llx\n",
diff --git a/drivers/gpu/drm/ast/ast_fb.c b/drivers/gpu/drm/ast/ast_fb.c
index d6f5ec64c667..f751792a3c7c 100644
--- a/drivers/gpu/drm/ast/ast_fb.c
+++ b/dr

[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ä 

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 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(co

[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ä 

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 &formats[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 v2 33/37] drm: Nuke fb->pixel_format

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

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|  2 +-
 drivers/gpu/drm/tilcdc/tilcdc_plane.c   |  2 +-
 drivers/gpu/drm/vc4/vc4_plane.c |  4 +--
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c |  2 --
 driv

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

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

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_format_info(struct drm_device *dev,
+   const struct drm_mode_fb_cmd2 *mode_cmd);
 uint32_t drm_mode_legacy_f

[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ä 

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 = &intel_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(&x, &y, fb, i);

-- 
2.7.4



[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ä 

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,
- &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



  1   2   3   4   5   6   7   8   9   10   >