drm/msm: fix compilation issues for "msm" on 4.9

The "msm/sde" driver is porting from "4.4" kernel
to "4.9". The "msm/sde" compilation is failing on
on this kernel branch due to upstream changes. This
patch fixes all compilation issues due to upstream
API changes, mdp4/5 driver changes, driver probe
changes, etc.

Change-Id: Id76a31ea9fa7c06c63a5eaa78e69642b938cb4bf
Signed-off-by: Dhaval Patel <pdhaval@codeaurora.org>
diff --git a/drivers/gpu/drm/msm/Makefile b/drivers/gpu/drm/msm/Makefile
index 62c6579..9770155 100644
--- a/drivers/gpu/drm/msm/Makefile
+++ b/drivers/gpu/drm/msm/Makefile
@@ -62,6 +62,7 @@
 	mdp/mdp4/mdp4_lvds_connector.o \
 	mdp/mdp4/mdp4_irq.o \
 	mdp/mdp4/mdp4_kms.o \
+	mdp/mdp4/mdp4_dsi_encoder.o \
 	mdp/mdp4/mdp4_plane.o
 
 msm_drm-$(CONFIG_DRM_FBDEV_EMULATION) += msm_fbdev.o
@@ -133,12 +134,15 @@
 	msm_gem.o \
 	msm_gem_prime.o \
 	msm_gem_submit.o \
+	msm_gem_shrinker.o \
 	msm_gpu.o \
 	msm_iommu.o \
 	msm_smmu.o \
 	msm_perf.o \
 	msm_rd.o \
 	msm_ringbuffer.o \
-	msm_prop.o
+	msm_prop.o \
+	msm_fence.o \
+	msm_debugfs.o
 
 obj-$(CONFIG_DRM_MSM)	+= msm_drm.o
diff --git a/drivers/gpu/drm/msm/hdmi/hdmi_hdcp.c b/drivers/gpu/drm/msm/hdmi/hdmi_hdcp.c
index d3b7615..8f3059b 100644
--- a/drivers/gpu/drm/msm/hdmi/hdmi_hdcp.c
+++ b/drivers/gpu/drm/msm/hdmi/hdmi_hdcp.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2016, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2010-2017, The Linux Foundation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 and
@@ -1438,24 +1438,24 @@
 }
 
 #else
-struct hdmi_hdcp_ctrl *hdmi_hdcp_ctrl_init(struct hdmi *hdmi)
+struct hdmi_hdcp_ctrl *msm_hdmi_hdcp_init(struct hdmi *hdmi)
 {
 	return NULL;
 }
 
-void hdmi_hdcp_ctrl_destroy(struct hdmi *hdmi)
+void msm_hdmi_hdcp_destroy(struct hdmi *hdmi)
 {
 }
 
-void hdmi_hdcp_ctrl_on(struct hdmi_hdcp_ctrl *hdcp_ctrl)
+void msm_hdmi_hdcp_on(struct hdmi_hdcp_ctrl *hdcp_ctrl)
 {
 }
 
-void hdmi_hdcp_ctrl_off(struct hdmi_hdcp_ctrl *hdcp_ctrl)
+void msm_hdmi_hdcp_off(struct hdmi_hdcp_ctrl *hdcp_ctrl)
 {
 }
 
-void hdmi_hdcp_ctrl_irq(struct hdmi_hdcp_ctrl *hdcp_ctrl)
+void msm_hdmi_hdcp_irq(struct hdmi_hdcp_ctrl *hdcp_ctrl)
 {
 }
 #endif
diff --git a/drivers/gpu/drm/msm/mdp/mdp4/mdp4_kms.h b/drivers/gpu/drm/msm/mdp/mdp4/mdp4_kms.h
index 25fb839..ddfabde 100644
--- a/drivers/gpu/drm/msm/mdp/mdp4/mdp4_kms.h
+++ b/drivers/gpu/drm/msm/mdp/mdp4/mdp4_kms.h
@@ -200,8 +200,19 @@
 		enum mdp4_pipe pipe_id, bool private_plane);
 
 uint32_t mdp4_crtc_vblank(struct drm_crtc *crtc);
+#ifdef CONFIG_DRM_MSM_MDP4
 void mdp4_crtc_set_config(struct drm_crtc *crtc, uint32_t config);
 void mdp4_crtc_set_intf(struct drm_crtc *crtc, enum mdp4_intf intf, int mixer);
+#else
+static inline void mdp4_crtc_set_config(struct drm_crtc *crtc, uint32_t config)
+{
+}
+
+static inline void mdp4_crtc_set_intf(struct drm_crtc *crtc,
+						enum mdp4_intf intf, int mixer)
+{
+}
+#endif
 void mdp4_crtc_wait_for_commit_done(struct drm_crtc *crtc);
 struct drm_crtc *mdp4_crtc_init(struct drm_device *dev,
 		struct drm_plane *plane, int id, int ovlp_id,
diff --git a/drivers/gpu/drm/msm/msm_atomic.c b/drivers/gpu/drm/msm/msm_atomic.c
index f651e72..b0679b0 100644
--- a/drivers/gpu/drm/msm/msm_atomic.c
+++ b/drivers/gpu/drm/msm/msm_atomic.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
  * Copyright (C) 2014 Red Hat
  * Author: Rob Clark <robdclark@gmail.com>
  *
@@ -93,6 +93,8 @@
 	int i;
 
 	for_each_crtc_in_state(old_state, crtc, crtc_state, i) {
+		int private_flags;
+
 		if (!crtc->state->enable)
 			continue;
 
@@ -133,7 +135,8 @@
 			continue;
 
 		crtc_idx = drm_crtc_index(old_conn_state->crtc);
-		old_crtc_state = old_state->crtc_states[crtc_idx];
+		old_crtc_state = drm_atomic_get_existing_crtc_state(old_state,
+						    old_conn_state->crtc);
 
 		if (!old_crtc_state->active ||
 		    !drm_atomic_crtc_needs_modeset(old_conn_state->crtc->state))
diff --git a/drivers/gpu/drm/msm/msm_kms.h b/drivers/gpu/drm/msm/msm_kms.h
index 5f97483..228e678 100644
--- a/drivers/gpu/drm/msm/msm_kms.h
+++ b/drivers/gpu/drm/msm/msm_kms.h
@@ -106,6 +106,8 @@
 struct msm_kms *mdp4_kms_init(struct drm_device *dev) { return NULL; };
 #endif
 struct msm_kms *mdp5_kms_init(struct drm_device *dev);
+int msm_mdss_init(struct drm_device *dev);
+void msm_mdss_destroy(struct drm_device *dev);
 struct msm_kms *sde_kms_init(struct drm_device *dev);
 
 /**
diff --git a/drivers/gpu/drm/msm/msm_smmu.c b/drivers/gpu/drm/msm/msm_smmu.c
index 0b23f5c..4203803 100644
--- a/drivers/gpu/drm/msm/msm_smmu.c
+++ b/drivers/gpu/drm/msm/msm_smmu.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 and
@@ -50,7 +50,8 @@
 static int _msm_smmu_create_mapping(struct msm_smmu_client *client,
 	const struct msm_smmu_domain *domain);
 
-static int msm_smmu_attach(struct msm_mmu *mmu, const char **names, int cnt)
+static int msm_smmu_attach(struct msm_mmu *mmu, const char * const *names,
+									int cnt)
 {
 	struct msm_smmu *smmu = to_msm_smmu(mmu);
 	struct msm_smmu_client *client = msm_smmu_to_client(smmu);
@@ -80,7 +81,8 @@
 	return 0;
 }
 
-static void msm_smmu_detach(struct msm_mmu *mmu, const char **names, int cnt)
+static void msm_smmu_detach(struct msm_mmu *mmu, const char * const *names,
+									int cnt)
 {
 	struct msm_smmu *smmu = to_msm_smmu(mmu);
 	struct msm_smmu_client *client = msm_smmu_to_client(smmu);
@@ -376,7 +378,6 @@
 static int _msm_smmu_create_mapping(struct msm_smmu_client *client,
 	const struct msm_smmu_domain *domain)
 {
-	int disable_htw = 1;
 	int rc;
 
 	client->mmu_mapping = arm_iommu_create_mapping(&platform_bus_type,
@@ -388,13 +389,6 @@
 		return PTR_ERR(client->mmu_mapping);
 	}
 
-	rc = iommu_domain_set_attr(client->mmu_mapping->domain,
-			DOMAIN_ATTR_COHERENT_HTW_DISABLE, &disable_htw);
-	if (rc) {
-		dev_err(client->dev, "couldn't disable coherent HTW\n");
-		goto error;
-	}
-
 	if (domain->secure) {
 		int secure_vmid = VMID_CP_PIXEL;
 
diff --git a/drivers/gpu/drm/msm/sde/sde_crtc.c b/drivers/gpu/drm/msm/sde/sde_crtc.c
index 27374ec..35ba699 100644
--- a/drivers/gpu/drm/msm/sde/sde_crtc.c
+++ b/drivers/gpu/drm/msm/sde/sde_crtc.c
@@ -682,7 +682,7 @@
 
 	SDE_DEBUG("crtc%d\n", crtc->base.id);
 
-	__drm_atomic_helper_crtc_destroy_state(crtc, state);
+	__drm_atomic_helper_crtc_destroy_state(state);
 
 	/* destroy value helper */
 	msm_property_destroy_state(&sde_crtc->property_info, cstate,
@@ -855,7 +855,7 @@
 
 struct plane_state {
 	struct sde_plane_state *sde_pstate;
-	struct drm_plane_state *drm_pstate;
+	const struct drm_plane_state *drm_pstate;
 
 	int stage;
 };
@@ -884,7 +884,7 @@
 	struct sde_crtc *sde_crtc;
 	struct plane_state pstates[SDE_STAGE_MAX * 2];
 
-	struct drm_plane_state *pstate;
+	const struct drm_plane_state *pstate;
 	struct drm_plane *plane;
 	struct drm_display_mode *mode;
 
@@ -910,8 +910,7 @@
 	mixer_width = sde_crtc_mixer_width(sde_crtc, mode);
 
 	 /* get plane state for all drm planes associated with crtc state */
-	drm_atomic_crtc_state_for_each_plane(plane, state) {
-		pstate = drm_atomic_get_plane_state(state->state, plane);
+	drm_atomic_crtc_state_for_each_plane_state(plane, pstate, state) {
 		if (IS_ERR_OR_NULL(pstate)) {
 			rc = PTR_ERR(pstate);
 			SDE_ERROR("%s: failed to get plane%d state, %d\n",
@@ -1312,16 +1311,6 @@
 	return single_open(file, _sde_debugfs_status_show, inode->i_private);
 }
 
-static void sde_crtc_suspend(struct drm_crtc *crtc)
-{
-	sde_cp_crtc_suspend(crtc);
-}
-
-static void sde_crtc_resume(struct drm_crtc *crtc)
-{
-	sde_cp_crtc_resume(crtc);
-}
-
 static const struct drm_crtc_funcs sde_crtc_funcs = {
 	.set_config = drm_atomic_helper_set_config,
 	.destroy = sde_crtc_destroy,
@@ -1332,8 +1321,6 @@
 	.reset = sde_crtc_reset,
 	.atomic_duplicate_state = sde_crtc_duplicate_state,
 	.atomic_destroy_state = sde_crtc_destroy_state,
-	.save = sde_crtc_suspend,
-	.restore = sde_crtc_resume,
 };
 
 static const struct drm_crtc_helper_funcs sde_crtc_helper_funcs = {
@@ -1385,7 +1372,8 @@
 	crtc->dev = dev;
 	atomic_set(&sde_crtc->vblank_refcount, 0);
 
-	drm_crtc_init_with_planes(dev, crtc, plane, NULL, &sde_crtc_funcs);
+	drm_crtc_init_with_planes(dev, crtc, plane, NULL, &sde_crtc_funcs,
+				NULL);
 
 	drm_crtc_helper_add(crtc, &sde_crtc_helper_funcs);
 	plane->crtc = crtc;
diff --git a/drivers/gpu/drm/msm/sde/sde_encoder.c b/drivers/gpu/drm/msm/sde/sde_encoder.c
index af5f81d..6ece91d 100644
--- a/drivers/gpu/drm/msm/sde/sde_encoder.c
+++ b/drivers/gpu/drm/msm/sde/sde_encoder.c
@@ -1215,7 +1215,7 @@
 	sde_enc->cur_master = NULL;
 	spin_lock_init(&sde_enc->enc_spinlock);
 	drm_enc = &sde_enc->base;
-	drm_encoder_init(dev, drm_enc, &sde_encoder_funcs, drm_enc_mode);
+	drm_encoder_init(dev, drm_enc, &sde_encoder_funcs, drm_enc_mode, NULL);
 	drm_encoder_helper_add(drm_enc, &sde_encoder_helper_funcs);
 	bs_init(sde_enc);
 
diff --git a/drivers/gpu/drm/msm/sde/sde_kms.c b/drivers/gpu/drm/msm/sde/sde_kms.c
index 716759c..32d55d1 100644
--- a/drivers/gpu/drm/msm/sde/sde_kms.c
+++ b/drivers/gpu/drm/msm/sde/sde_kms.c
@@ -14,6 +14,7 @@
 
 #include <drm/drm_crtc.h>
 #include <linux/debugfs.h>
+#include <linux/of_irq.h>
 
 #include "msm_drv.h"
 #include "msm_mmu.h"
@@ -793,11 +794,6 @@
 
 	dev = sde_kms->dev;
 
-	/*
-	 * Allow vblank interrupt to be disabled by drm vblank timer.
-	 */
-	dev->vblank_disable_allowed = true;
-
 	return 0;
 }
 
diff --git a/drivers/gpu/drm/msm/sde/sde_kms.h b/drivers/gpu/drm/msm/sde/sde_kms.h
index cd9d103..6990d16 100644
--- a/drivers/gpu/drm/msm/sde/sde_kms.h
+++ b/drivers/gpu/drm/msm/sde/sde_kms.h
@@ -36,7 +36,7 @@
 #define SDE_DEBUG(fmt, ...)                                                \
 	do {                                                               \
 		if (unlikely(drm_debug & DRM_UT_KMS))                      \
-			drm_ut_debug_printk(__func__, fmt, ##__VA_ARGS__); \
+			DRM_DEBUG(fmt, ##__VA_ARGS__); \
 		else                                                       \
 			pr_debug(fmt, ##__VA_ARGS__);                      \
 	} while (0)
@@ -48,7 +48,7 @@
 #define SDE_DEBUG_DRIVER(fmt, ...)                                         \
 	do {                                                               \
 		if (unlikely(drm_debug & DRM_UT_DRIVER))                   \
-			drm_ut_debug_printk(__func__, fmt, ##__VA_ARGS__); \
+			DRM_ERROR(fmt, ##__VA_ARGS__); \
 		else                                                       \
 			pr_debug(fmt, ##__VA_ARGS__);                      \
 	} while (0)
diff --git a/drivers/gpu/drm/msm/sde/sde_plane.c b/drivers/gpu/drm/msm/sde/sde_plane.c
index 8cf15c5..d2884f0 100644
--- a/drivers/gpu/drm/msm/sde/sde_plane.c
+++ b/drivers/gpu/drm/msm/sde/sde_plane.c
@@ -1199,7 +1199,7 @@
 }
 
 static int sde_plane_prepare_fb(struct drm_plane *plane,
-		const struct drm_plane_state *new_state)
+		struct drm_plane_state *new_state)
 {
 	struct drm_framebuffer *fb = new_state->fb;
 	struct sde_plane *psde = to_sde_plane(plane);
@@ -1212,7 +1212,7 @@
 }
 
 static void sde_plane_cleanup_fb(struct drm_plane *plane,
-		const struct drm_plane_state *old_state)
+		struct drm_plane_state *old_state)
 {
 	struct drm_framebuffer *fb = old_state ? old_state->fb : NULL;
 	struct sde_plane *psde = plane ? to_sde_plane(plane) : NULL;
@@ -1616,7 +1616,8 @@
 
 	/* standard properties */
 	msm_property_install_rotation(&psde->property_info,
-		BIT(DRM_REFLECT_X) | BIT(DRM_REFLECT_Y), PLANE_PROP_ROTATION);
+		(unsigned int) (BIT(DRM_REFLECT_X) | BIT(DRM_REFLECT_Y)),
+		PLANE_PROP_ROTATION);
 
 	msm_property_install_enum(&psde->property_info, "blend_op", 0x0, 0,
 		e_blend_op, ARRAY_SIZE(e_blend_op), PLANE_PROP_BLEND_OP);
@@ -2356,8 +2357,9 @@
 		type = DRM_PLANE_TYPE_PRIMARY;
 	else
 		type = DRM_PLANE_TYPE_OVERLAY;
-	ret = drm_universal_plane_init(dev, plane, possible_crtcs,
-			&sde_plane_funcs, psde->formats, psde->nformats, type);
+	ret = drm_universal_plane_init(dev, plane, 0xff, &sde_plane_funcs,
+				psde->formats, psde->nformats,
+				type, NULL);
 	if (ret)
 		goto clean_sspp;
 
diff --git a/drivers/gpu/drm/msm/sde/sde_wb.c b/drivers/gpu/drm/msm/sde/sde_wb.c
index 647cb58..ab4497b 100644
--- a/drivers/gpu/drm/msm/sde/sde_wb.c
+++ b/drivers/gpu/drm/msm/sde/sde_wb.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 and
@@ -453,7 +453,7 @@
 
 	priv = drm_dev->dev_private;
 
-	connector = drm_connector_find(drm_dev, connector_id);
+	connector = drm_connector_lookup(drm_dev, connector_id);
 	if (!connector) {
 		SDE_ERROR("failed to find connector\n");
 		rc = -ENOENT;