code:
From: Jan Kara <jack@suse.cz>
Subject: [PATCH] jbd2: Fix dbench4 performance regression for 'nobarrier' mounts
Date: Fri, 28 Apr 2017 11:59:34 +0200

Commit b685d3d65ac7 "block: treat REQ_FUA and REQ_PREFLUSH as
synchronous" removed REQ_SYNC flag from WRITE_FUA implementation. Since
JBD2 strips REQ_FUA and REQ_FLUSH flags from submitted IO when the
filesystem is mounted with nobarrier mount option, journal superblock
writes ended up being async writes after this patch and that caused
heavy performance regression for dbench4 benchmark with high number of
processes. In my test setup with HP RAID array with non-volatile write
cache and 32 GB ram, dbench4 runs with 8 processes regressed by ~25%.

Fix the problem by making sure journal superblock writes are always
treated as synchronous since they generally block progress of the
journalling machinery and thus the whole filesystem.

Fixes: b685d3d65ac791406e0dfd8779cc9b3707fea5a3
CC: stable@vger.kernel.org
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/jbd2/journal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 5adc2fb62b0f..e768126f6a72 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -1348,7 +1348,7 @@ static int jbd2_write_superblock(journal_t *journal, int write_flags)
 	jbd2_superblock_csum_set(journal, sb);
 	get_bh(bh);
 	bh->b_end_io = end_buffer_write_sync;
-	ret = submit_bh(REQ_OP_WRITE, write_flags, bh);
+	ret = submit_bh(REQ_OP_WRITE, write_flags | REQ_SYNC, bh);
 	wait_on_buffer(bh);
 	if (buffer_write_io_error(bh)) {
 		clear_buffer_write_io_error(bh);
--
2.12.0

repo_name: ayhanyalcinsoy/main


code:
From e522751d605d99a81508e58390a8f51ee96fb662 Mon Sep 17 00:00:00 2001
From: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
Date: Tue, 29 Nov 2016 15:18:20 +0100
Subject: [PATCH] seq_file: reset iterator to first record for zero offset

If kernfs file is empty on a first read, successive read operations
using the same file descriptor will return no data, even when data is
available. Default kernfs 'seq_next' implementation advances iterator
position even when next object is not there. Kernfs 'seq_start' for
following requests will not return iterator as position is already on
the second object.

This defect doesn't allow to monitor badblocks sysfs files from MD raid.
They are initially empty but if data appears at some stage, userspace is
not able to read it.

Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/seq_file.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/seq_file.c b/fs/seq_file.c
index 368bfb9..a11f271 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -190,6 +190,13 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
 	 */
 	m->version = file->f_version;

+	/*
+	 * if request is to read from zero offset, reset iterator to first
+	 * record as it might have been already advanced by previous requests
+	 */
+	if (*ppos == 0)
+		m->index = 0;
+
 	/* Don't assume *ppos is where we left it */
 	if (unlikely(*ppos != m->read_pos)) {
 		while ((err = traverse(m, *ppos)) == -EAGAIN)
--
2.10.2


code:
From cf8c73afb3abf0f8905efbaddd4ce11a0deec9da Mon Sep 17 00:00:00 2001
From: Evan Quan <evan.quan@amd.com>
Date: Fri, 17 Mar 2017 10:22:51 +0800
Subject: [PATCH] drm/amd/amdgpu: add POLARIS12 PCI ID

Signed-off-by: Evan Quan <evan.quan@amd.com>
Reviewed-by: Junwei Zhang <Jerry.Zhang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: stable@vger.kernel.org
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index f7adbac..b76cd69 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -421,6 +421,7 @@ static const struct pci_device_id pciidlist[] = {
 	{0x1002, 0x6985, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
 	{0x1002, 0x6986, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
 	{0x1002, 0x6987, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
+	{0x1002, 0x6995, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
 	{0x1002, 0x699F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},

 	{0, 0, 0}
--
2.10.2


code:
From fc8e9c54699e42754094ff475da46440778d8f19 Mon Sep 17 00:00:00 2001
From: Junwei Zhang <Jerry.Zhang@amd.com>
Date: Thu, 4 Aug 2016 12:54:22 +0800
Subject: [PATCH] drm/amd/amdgpu: add Polaris12 PCI ID
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Junwei Zhang <Jerry.Zhang@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Ken Wang  <Qingqing.Wang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 8cb937b..2534ada 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -418,6 +418,13 @@ static const struct pci_device_id pciidlist[] = {
 	{0x1002, 0x67CA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
 	{0x1002, 0x67CC, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
 	{0x1002, 0x67CF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
+	/* Polaris12 */
+	{0x1002, 0x6980, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
+	{0x1002, 0x6981, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
+	{0x1002, 0x6985, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
+	{0x1002, 0x6986, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
+	{0x1002, 0x6987, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
+	{0x1002, 0x699F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},

 	{0, 0, 0}
 };
--
2.10.2


code:
From c4642a479fac9f5c224ff7425d86c427b94011af Mon Sep 17 00:00:00 2001
From: Junwei Zhang <Jerry.Zhang@amd.com>
Date: Wed, 14 Dec 2016 15:32:28 -0500
Subject: [PATCH] drm/amd/amdgpu: add Polaris12 support (v3)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

v2: agd: squash in various fixes
v3: agd: squash in:
drm/amdgpu: remove unnecessary smc sk firmware for polaris12

Signed-off-by: Junwei Zhang <Jerry.Zhang@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Ken Wang  <Qingqing.Wang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
[ rebased for 4.9 / tmb ]
Signed-off-by: Thomas Backlund <tmb@mageia.org>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c    |  3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c    |  5 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c    |  5 +++++
 drivers/gpu/drm/amd/amdgpu/dce_v11_0.c     | 13 ++++++++++---
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c      | 31 +++++++++++++++++++++++++-----
 drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c      |  5 +++++
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c     |  6 ++++++
 drivers/gpu/drm/amd/amdgpu/vce_v3_0.c      |  5 +++--
 drivers/gpu/drm/amd/amdgpu/vi.c            | 10 ++++++++++
 drivers/gpu/drm/amd/include/amd_shared.h   |  1 +
 11 files changed, 76 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
index 9ada56c..4c851fde 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
@@ -840,6 +840,9 @@ static int amdgpu_cgs_get_firmware_info(struct cgs_device *cgs_device,
 				else if (type == CGS_UCODE_ID_SMU_SK)
 					strcpy(fw_name, "amdgpu/polaris10_smc_sk.bin");
 				break;
+			case CHIP_POLARIS12:
+				strcpy(fw_name, "amdgpu/polaris12_smc.bin");
+				break;
 			default:
 				DRM_ERROR("SMC firmware not supported\n");
 				return -EINVAL;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 60bd4af..fe3bb94 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -73,6 +73,7 @@ static const char *amdgpu_asic_name[] = {
 	"STONEY",
 	"POLARIS10",
 	"POLARIS11",
+	"POLARIS12",
 	"LAST",
 };

@@ -1277,6 +1278,7 @@ static int amdgpu_early_init(struct amdgpu_device *adev)
 	case CHIP_FIJI:
 	case CHIP_POLARIS11:
 	case CHIP_POLARIS10:
+	case CHIP_POLARIS12:
 	case CHIP_CARRIZO:
 	case CHIP_STONEY:
 		if (adev->asic_type == CHIP_CARRIZO || adev->asic_type == CHIP_STONEY)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
index a81dfae..1d564be 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
@@ -65,6 +65,7 @@
 #define FIRMWARE_STONEY		"amdgpu/stoney_uvd.bin"
 #define FIRMWARE_POLARIS10	"amdgpu/polaris10_uvd.bin"
 #define FIRMWARE_POLARIS11	"amdgpu/polaris11_uvd.bin"
+#define FIRMWARE_POLARIS12	"amdgpu/polaris12_uvd.bin"

 /**
  * amdgpu_uvd_cs_ctx - Command submission parser context
@@ -98,6 +99,7 @@ MODULE_FIRMWARE(FIRMWARE_FIJI);
 MODULE_FIRMWARE(FIRMWARE_STONEY);
 MODULE_FIRMWARE(FIRMWARE_POLARIS10);
 MODULE_FIRMWARE(FIRMWARE_POLARIS11);
+MODULE_FIRMWARE(FIRMWARE_POLARIS12);

 static void amdgpu_uvd_idle_work_handler(struct work_struct *work);

@@ -149,6 +151,9 @@ int amdgpu_uvd_sw_init(struct amdgpu_device *adev)
 	case CHIP_POLARIS11:
 		fw_name = FIRMWARE_POLARIS11;
 		break;
+	case CHIP_POLARIS12:
+		fw_name = FIRMWARE_POLARIS12;
+		break;
 	default:
 		return -EINVAL;
 	}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c
index 69b66b9..8fec802 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c
@@ -52,6 +52,7 @@
 #define FIRMWARE_STONEY		"amdgpu/stoney_vce.bin"
 #define FIRMWARE_POLARIS10	"amdgpu/polaris10_vce.bin"
 #define FIRMWARE_POLARIS11         "amdgpu/polaris11_vce.bin"
+#define FIRMWARE_POLARIS12         "amdgpu/polaris12_vce.bin"

 #ifdef CONFIG_DRM_AMDGPU_CIK
 MODULE_FIRMWARE(FIRMWARE_BONAIRE);
@@ -66,6 +67,7 @@ MODULE_FIRMWARE(FIRMWARE_FIJI);
 MODULE_FIRMWARE(FIRMWARE_STONEY);
 MODULE_FIRMWARE(FIRMWARE_POLARIS10);
 MODULE_FIRMWARE(FIRMWARE_POLARIS11);
+MODULE_FIRMWARE(FIRMWARE_POLARIS12);

 static void amdgpu_vce_idle_work_handler(struct work_struct *work);

@@ -121,6 +123,9 @@ int amdgpu_vce_sw_init(struct amdgpu_device *adev, unsigned long size)
 	case CHIP_POLARIS11:
 		fw_name = FIRMWARE_POLARIS11;
 		break;
+	case CHIP_POLARIS12:
+		fw_name = FIRMWARE_POLARIS12;
+		break;

 	default:
 		return -EINVAL;
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
index b3d62b9..2006abb 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
@@ -167,6 +167,7 @@ static void dce_v11_0_init_golden_registers(struct amdgpu_device *adev)
 						 (const u32)ARRAY_SIZE(stoney_golden_settings_a11));
 		break;
 	case CHIP_POLARIS11:
+	case CHIP_POLARIS12:
 		amdgpu_program_register_sequence(adev,
 						 polaris11_golden_settings_a11,
 						 (const u32)ARRAY_SIZE(polaris11_golden_settings_a11));
@@ -608,6 +609,7 @@ static int dce_v11_0_get_num_crtc (struct amdgpu_device *adev)
 		num_crtc = 6;
 		break;
 	case CHIP_POLARIS11:
+	case CHIP_POLARIS12:
 		num_crtc = 5;
 		break;
 	default:
@@ -1589,6 +1591,7 @@ static int dce_v11_0_audio_init(struct amdgpu_device *adev)
 		adev->mode_info.audio.num_pins = 8;
 		break;
 	case CHIP_POLARIS11:
+	case CHIP_POLARIS12:
 		adev->mode_info.audio.num_pins = 6;
 		break;
 	default:
@@ -2388,7 +2391,8 @@ static u32 dce_v11_0_pick_pll(struct drm_crtc *crtc)
 	int pll;

 	if ((adev->asic_type == CHIP_POLARIS10) ||
-	    (adev->asic_type == CHIP_POLARIS11)) {
+	    (adev->asic_type == CHIP_POLARIS11) ||
+	    (adev->asic_type == CHIP_POLARIS12)) {
 		struct amdgpu_encoder *amdgpu_encoder =
 			to_amdgpu_encoder(amdgpu_crtc->encoder);
 		struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
@@ -2822,7 +2826,8 @@ static int dce_v11_0_crtc_mode_set(struct drm_crtc *crtc,
 		return -EINVAL;

 	if ((adev->asic_type == CHIP_POLARIS10) ||
-	    (adev->asic_type == CHIP_POLARIS11)) {
+	    (adev->asic_type == CHIP_POLARIS11) ||
+	    (adev->asic_type == CHIP_POLARIS12)) {
 		struct amdgpu_encoder *amdgpu_encoder =
 			to_amdgpu_encoder(amdgpu_crtc->encoder);
 		int encoder_mode =
@@ -2992,6 +2997,7 @@ static int dce_v11_0_early_init(void *handle)
 		adev->mode_info.num_dig = 6;
 		break;
 	case CHIP_POLARIS11:
+	case CHIP_POLARIS12:
 		adev->mode_info.num_hpd = 5;
 		adev->mode_info.num_dig = 5;
 		break;
@@ -3101,7 +3107,8 @@ static int dce_v11_0_hw_init(void *handle)
 	amdgpu_atombios_crtc_powergate_init(adev);
 	amdgpu_atombios_encoder_init_dig(adev);
 	if ((adev->asic_type == CHIP_POLARIS10) ||
-	    (adev->asic_type == CHIP_POLARIS11)) {
+	    (adev->asic_type == CHIP_POLARIS11) ||
+	    (adev->asic_type == CHIP_POLARIS12)) {
 		amdgpu_atombios_crtc_set_dce_clock(adev, adev->clock.default_dispclk,
 						   DCE_CLOCK_TYPE_DISPCLK, ATOM_GCK_DFS);
 		amdgpu_atombios_crtc_set_dce_clock(adev, 0,
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
index d0ec009..3733741 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
@@ -138,6 +138,13 @@ MODULE_FIRMWARE("amdgpu/polaris10_mec.bi
 MODULE_FIRMWARE("amdgpu/polaris10_mec2.bin");
 MODULE_FIRMWARE("amdgpu/polaris10_rlc.bin");

+MODULE_FIRMWARE("amdgpu/polaris12_ce.bin");
+MODULE_FIRMWARE("amdgpu/polaris12_pfp.bin");
+MODULE_FIRMWARE("amdgpu/polaris12_me.bin");
+MODULE_FIRMWARE("amdgpu/polaris12_mec.bin");
+MODULE_FIRMWARE("amdgpu/polaris12_mec2.bin");
+MODULE_FIRMWARE("amdgpu/polaris12_rlc.bin");
+
 static const struct amdgpu_gds_reg_offset amdgpu_gds_reg_offset[] =
 {
 	{mmGDS_VMID0_BASE, mmGDS_VMID0_SIZE, mmGDS_GWS_VMID0, mmGDS_OA_VMID0},
@@ -687,6 +694,7 @@ static void gfx_v8_0_init_golden_registe
 						 (const u32)ARRAY_SIZE(tonga_golden_common_all));
 		break;
 	case CHIP_POLARIS11:
+	case CHIP_POLARIS12:
 		amdgpu_program_register_sequence(adev,
 						 golden_settings_polaris11_a11,
 						 (const u32)ARRAY_SIZE(golden_settings_polaris11_a11));
@@ -901,6 +909,9 @@ static int gfx_v8_0_init_microcode(struc
 	case CHIP_POLARIS10:
 		chip_name = "polaris10";
 		break;
+	case CHIP_POLARIS12:
+		chip_name = "polaris12";
+		break;
 	case CHIP_STONEY:
 		chip_name = "stoney";
 		break;
@@ -1777,6 +1788,7 @@ static int gfx_v8_0_gpu_early_init(struc
 		gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
 		break;
 	case CHIP_POLARIS11:
+	case CHIP_POLARIS12:
 		ret = amdgpu_atombios_get_gfx_info(adev);
 		if (ret)
 			return ret;
@@ -2695,6 +2707,7 @@ static void gfx_v8_0_tiling_mode_table_i

 		break;
 	case CHIP_POLARIS11:
+	case CHIP_POLARIS12:
 		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
@@ -3516,6 +3529,7 @@ gfx_v8_0_raster_config(struct amdgpu_dev
 		*rconf1 |= 0x0;
 		break;
 	case CHIP_POLARIS11:
+	case CHIP_POLARIS12:
 		*rconf |= RB_MAP_PKR0(2) | RB_XSEL2(1) | SE_MAP(2) |
 			  SE_XSEL(1) | SE_YSEL(1);
 		*rconf1 |= 0x0;
@@ -4029,7 +4043,8 @@ static void gfx_v8_0_init_pg(struct amdg
 				cz_enable_cp_power_gating(adev, true);
 			else
 				cz_enable_cp_power_gating(adev, false);
-		} else if (adev->asic_type == CHIP_POLARIS11) {
+		} else if ((adev->asic_type == CHIP_POLARIS11) ||
+			   (adev->asic_type == CHIP_POLARIS11)) {
 			gfx_v8_0_init_power_gating(adev);
 		}
 	}
@@ -4100,7 +4115,8 @@ static int gfx_v8_0_rlc_resume(struct am
 		 RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK);
 	WREG32(mmRLC_CGCG_CGLS_CTRL, tmp);
 	if (adev->asic_type == CHIP_POLARIS11 ||
-	    adev->asic_type == CHIP_POLARIS10) {
+	    adev->asic_type == CHIP_POLARIS10 ||
+	    adev->asic_type == CHIP_POLARIS12) {
 		tmp = RREG32(mmRLC_CGCG_CGLS_CTRL_3D);
 		tmp &= ~0x3;
 		WREG32(mmRLC_CGCG_CGLS_CTRL_3D, tmp);
@@ -4288,6 +4304,7 @@ static int gfx_v8_0_cp_gfx_start(struct
 		amdgpu_ring_write(ring, 0x0000002A);
 		break;
 	case CHIP_POLARIS11:
+	case CHIP_POLARIS12:
 		amdgpu_ring_write(ring, 0x16000012);
 		amdgpu_ring_write(ring, 0x00000000);
 		break;
@@ -4938,7 +4955,8 @@ static int gfx_v8_0_cp_compute_resume(st
 			    (adev->asic_type == CHIP_FIJI) ||
 			    (adev->asic_type == CHIP_STONEY) ||
 			    (adev->asic_type == CHIP_POLARIS11) ||
-			    (adev->asic_type == CHIP_POLARIS10)) {
+			    (adev->asic_type == CHIP_POLARIS10) ||
+			    (adev->asic_type == CHIP_POLARIS12)) {
 				WREG32(mmCP_MEC_DOORBELL_RANGE_LOWER,
 				       AMDGPU_DOORBELL_KIQ << 2);
 				WREG32(mmCP_MEC_DOORBELL_RANGE_UPPER,
@@ -4974,7 +4992,8 @@ static int gfx_v8_0_cp_compute_resume(st
 		mqd->cp_hqd_persistent_state = tmp;
 		if (adev->asic_type == CHIP_STONEY ||
 			adev->asic_type == CHIP_POLARIS11 ||
-			adev->asic_type == CHIP_POLARIS10) {
+			adev->asic_type == CHIP_POLARIS10 ||
+			adev->asic_type == CHIP_POLARIS12) {
 			tmp = RREG32(mmCP_ME1_PIPE3_INT_CNTL);
 			tmp = REG_SET_FIELD(tmp, CP_ME1_PIPE3_INT_CNTL, GENERIC2_INT_ENABLE, 1);
 			WREG32(mmCP_ME1_PIPE3_INT_CNTL, tmp);
@@ -5488,7 +5507,8 @@ static int gfx_v8_0_late_init(void *hand
 static void gfx_v8_0_enable_gfx_static_mg_power_gating(struct amdgpu_device *adev,
 						       bool enable)
 {
-	if (adev->asic_type == CHIP_POLARIS11)
+	if ((adev->asic_type == CHIP_POLARIS11) ||
+	    (adev->asic_type == CHIP_POLARIS12))
 		/* Send msg to SMU via Powerplay */
 		amdgpu_set_powergating_state(adev,
 					     AMD_IP_BLOCK_TYPE_SMC,
@@ -5565,6 +5585,7 @@ static int gfx_v8_0_set_powergating_stat
 			gfx_v8_0_enable_gfx_dynamic_mg_power_gating(adev, false);
 		break;
 	case CHIP_POLARIS11:
+	case CHIP_POLARIS12:
 		if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_SMG) && enable)
 			gfx_v8_0_enable_gfx_static_mg_power_gating(adev, true);
 		else
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
index 0daac3a..476bc9f 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
@@ -46,6 +46,7 @@ static int gmc_v8_0_wait_for_idle(void *handle);
 MODULE_FIRMWARE("amdgpu/tonga_mc.bin");
 MODULE_FIRMWARE("amdgpu/polaris11_mc.bin");
 MODULE_FIRMWARE("amdgpu/polaris10_mc.bin");
+MODULE_FIRMWARE("amdgpu/polaris12_mc.bin");

 static const u32 golden_settings_tonga_a11[] =
 {
@@ -130,6 +131,7 @@ static void gmc_v8_0_init_golden_registers(struct amdgpu_device *adev)
 						 (const u32)ARRAY_SIZE(golden_settings_tonga_a11));
 		break;
 	case CHIP_POLARIS11:
+	case CHIP_POLARIS12:
 		amdgpu_program_register_sequence(adev,
 						 golden_settings_polaris11_a11,
 						 (const u32)ARRAY_SIZE(golden_settings_polaris11_a11));
@@ -225,6 +227,9 @@ static int gmc_v8_0_init_microcode(struct amdgpu_device *adev)
 	case CHIP_POLARIS10:
 		chip_name = "polaris10";
 		break;
+	case CHIP_POLARIS12:
+		chip_name = "polaris12";
+		break;
 	case CHIP_FIJI:
 	case CHIP_CARRIZO:
 	case CHIP_STONEY:
diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
index 1170a64..034ace7 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
@@ -60,6 +60,8 @@ MODULE_FIRMWARE("amdgpu/polaris10_sdma.bin");
 MODULE_FIRMWARE("amdgpu/polaris10_sdma1.bin");
 MODULE_FIRMWARE("amdgpu/polaris11_sdma.bin");
 MODULE_FIRMWARE("amdgpu/polaris11_sdma1.bin");
+MODULE_FIRMWARE("amdgpu/polaris12_sdma.bin");
+MODULE_FIRMWARE("amdgpu/polaris12_sdma1.bin");

 static const u32 sdma_offsets[SDMA_MAX_INSTANCE] =
@@ -206,6 +208,7 @@ static void sdma_v3_0_init_golden_registers(struct amdgpu_device *adev)
 						 (const u32)ARRAY_SIZE(golden_settings_tonga_a11));
 		break;
 	case CHIP_POLARIS11:
+	case CHIP_POLARIS12:
 		amdgpu_program_register_sequence(adev,
 						 golden_settings_polaris11_a11,
 						 (const u32)ARRAY_SIZE(golden_settings_polaris11_a11));
@@ -278,6 +281,9 @@ static int sdma_v3_0_init_microcode(struct amdgpu_device *adev)
 	case CHIP_POLARIS10:
 		chip_name = "polaris10";
 		break;
+	case CHIP_POLARIS12:
+		chip_name = "polaris12";
+		break;
 	case CHIP_CARRIZO:
 		chip_name = "carrizo";
 		break;
diff --git a/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c b/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c
index 6b3293a..5fb0b7f 100644
--- a/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c
@@ -320,11 +320,12 @@ static unsigned vce_v3_0_get_harvest_config(struct amdgpu_device *adev)
 {
 	u32 tmp;

-	/* Fiji, Stoney, Polaris10, Polaris11 are single pipe */
+	/* Fiji, Stoney, Polaris10, Polaris11, Polaris12 are single pipe */
 	if ((adev->asic_type == CHIP_FIJI) ||
 	    (adev->asic_type == CHIP_STONEY) ||
 	    (adev->asic_type == CHIP_POLARIS10) ||
-	    (adev->asic_type == CHIP_POLARIS11))
+	    (adev->asic_type == CHIP_POLARIS11) ||
+	    (adev->asic_type == CHIP_POLARIS12))
 		return AMDGPU_VCE_HARVEST_VCE1;

 	/* Tonga and CZ are dual or single pipe */
diff --git a/drivers/gpu/drm/amd/amdgpu/vi.c b/drivers/gpu/drm/amd/amdgpu/vi.c
index bf088d6..c2ac54f 100644
--- a/drivers/gpu/drm/amd/amdgpu/vi.c
+++ b/drivers/gpu/drm/amd/amdgpu/vi.c
@@ -88,6 +88,7 @@ MODULE_FIRMWARE("amdgpu/polaris10_smc.bi
 MODULE_FIRMWARE("amdgpu/polaris10_smc_sk.bin");
 MODULE_FIRMWARE("amdgpu/polaris11_smc.bin");
 MODULE_FIRMWARE("amdgpu/polaris11_smc_sk.bin");
+MODULE_FIRMWARE("amdgpu/polaris12_smc.bin");

 /*
  * Indirect registers accessor
@@ -312,6 +313,7 @@ static void vi_init_golden_registers(str
 		break;
 	case CHIP_POLARIS11:
 	case CHIP_POLARIS10:
+	case CHIP_POLARIS12:
 	default:
 		break;
 	}
@@ -592,6 +594,7 @@ static int vi_read_register(struct amdgp
 	case CHIP_TONGA:
 	case CHIP_POLARIS11:
 	case CHIP_POLARIS10:
+	case CHIP_POLARIS12:
 	case CHIP_CARRIZO:
 	case CHIP_STONEY:
 		asic_register_table = cz_allowed_read_registers;
@@ -1465,6 +1468,7 @@ int vi_set_ip_blocks(struct amdgpu_devic
 			break;
 		case CHIP_POLARIS11:
 		case CHIP_POLARIS10:
+		case CHIP_POLARIS12:
 			adev->ip_blocks = polaris11_ip_blocks_vd;
 			adev->num_ip_blocks = ARRAY_SIZE(polaris11_ip_blocks_vd);
 			break;
@@ -1608,6 +1612,11 @@ static int vi_common_early_init(void *ha
 		adev->pg_flags = 0;
 		adev->external_rev_id = adev->rev_id + 0x50;
 		break;
+	case CHIP_POLARIS12:
+		adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG;
+		adev->pg_flags = 0;
+		adev->external_rev_id = adev->rev_id + 0x64;
+		break;
 	case CHIP_CARRIZO:
 		adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
 			AMD_CG_SUPPORT_GFX_MGCG |
@@ -1897,6 +1906,7 @@ static int vi_common_set_clockgating_sta
 	case CHIP_TONGA:
 	case CHIP_POLARIS10:
 	case CHIP_POLARIS11:
+	case CHIP_POLARIS12:
 		vi_common_set_clockgating_state_by_smu(adev, state);
 	default:
 		break;
diff --git a/drivers/gpu/drm/amd/include/amd_shared.h b/drivers/gpu/drm/amd/include/amd_shared.h
index c02469a..5f59117 100644
--- a/drivers/gpu/drm/amd/include/amd_shared.h
+++ b/drivers/gpu/drm/amd/include/amd_shared.h
@@ -46,6 +46,7 @@ enum amd_asic_type {
 	CHIP_STONEY,
 	CHIP_POLARIS10,
 	CHIP_POLARIS11,
+	CHIP_POLARIS12,
 	CHIP_LAST,
 };

--
2.10.2


code:
From 6e88491cf2a3b17199c78bd53348b39dc6a88275 Mon Sep 17 00:00:00 2001
From: Junshan Fang <Junshan.Fang@amd.com>
Date: Thu, 15 Jun 2017 14:02:20 +0800
Subject: [PATCH] drm/amdgpu: add Polaris12 DID

Signed-off-by: Junshan Fang <Junshan.Fang@amd.com>
Reviewed-by: Roger.He <Hongbo.He@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: stable@vger.kernel.org
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index f2d705e6a75a..ab6b0d0febab 100644
@@ -418,6 +418,7 @@ static const struct pci_device_id pciidl
 	{0x1002, 0x6986, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
 	{0x1002, 0x6987, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
 	{0x1002, 0x6995, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
+	{0x1002, 0x6997, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
 	{0x1002, 0x699F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},

 	{0, 0, 0}


code:
From c10c8f7c27103bd7ac02d041d9d6e97296d48fc1 Mon Sep 17 00:00:00 2001
From: Alex Deucher <alexander.deucher@amd.com>
Date: Fri, 10 Feb 2017 18:09:32 -0500
Subject: [PATCH] drm/amdgpu/pm: check for headless before calling
 compute_clocks

Don't update display bandwidth on headless asics.

bug:
https://bugs.freedesktop.org/show_bug.cgi?id=99387

Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: stable@vger.kernel.org
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 95e026a..346e80a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -1283,7 +1283,9 @@ void amdgpu_pm_compute_clocks(struct amd
 	if (adev->pp_enabled) {
 		int i = 0;

-		amdgpu_display_bandwidth_update(adev);
+		if (adev->mode_info.num_crtc)
+			amdgpu_display_bandwidth_update(adev);
+
 		for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
 			struct amdgpu_ring *ring = adev->rings[i];
 			if (ring && ring->ready)


code:
From f4309526576db325264b6dc9ee150ee70b330a42 Mon Sep 17 00:00:00 2001
From: Junwei Zhang <Jerry.Zhang@amd.com>
Date: Wed, 14 Dec 2016 15:40:48 -0500
Subject: [PATCH] drm/amdgpu/powerplay: add Polaris12 support
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Junwei Zhang <Jerry.Zhang@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Ken Wang  <Qingqing.Wang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c        | 1 +
 drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c          | 3 ++-
 drivers/gpu/drm/amd/powerplay/hwmgr/smu7_powertune.c | 2 +-
 drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c        | 1 +
 4 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c
index fc592c2..95a568d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c
@@ -98,6 +98,7 @@ static int amdgpu_pp_early_init(void *handle)
 	switch (adev->asic_type) {
 	case CHIP_POLARIS11:
 	case CHIP_POLARIS10:
+	case CHIP_POLARIS12:
 	case CHIP_TONGA:
 	case CHIP_FIJI:
 	case CHIP_TOPAZ:
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c
index dc6700a..b036064 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c
@@ -95,6 +95,7 @@ int hwmgr_init(struct amd_pp_init *pp_init, struct pp_instance *handle)
 			break;
 		case CHIP_POLARIS11:
 		case CHIP_POLARIS10:
+		case CHIP_POLARIS12:
 			polaris_set_asic_special_caps(hwmgr);
 			hwmgr->feature_mask &= ~(PP_UVD_HANDSHAKE_MASK);
 			break;
@@ -745,7 +746,7 @@ int polaris_set_asic_special_caps(struct pp_hwmgr *hwmgr)
 	phm_cap_set(hwmgr->platform_descriptor.platformCaps,
 				PHM_PlatformCaps_TablelessHardwareInterface);

-	if (hwmgr->chip_id == CHIP_POLARIS11)
+	if ((hwmgr->chip_id == CHIP_POLARIS11) || (hwmgr->chip_id == CHIP_POLARIS12))
 		phm_cap_set(hwmgr->platform_descriptor.platformCaps,
 					PHM_PlatformCaps_SPLLShutdownSupport);
 	return 0;
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_powertune.c b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_powertune.c
index 26477f0..6cd1287 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_powertune.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_powertune.c
@@ -521,7 +521,7 @@ int smu7_enable_didt_config(struct pp_hwmgr *hwmgr)
 				PP_ASSERT_WITH_CODE((result == 0), "DIDT Config failed.", return result);
 				result = smu7_program_pt_config_registers(hwmgr, DIDTConfig_Polaris10);
 				PP_ASSERT_WITH_CODE((result == 0), "DIDT Config failed.", return result);
-			} else if (hwmgr->chip_id == CHIP_POLARIS11) {
+			} else if ((hwmgr->chip_id == CHIP_POLARIS11) || (hwmgr->chip_id == CHIP_POLARIS12)) {
 				result = smu7_program_pt_config_registers(hwmgr, GCCACConfig_Polaris11);
 				PP_ASSERT_WITH_CODE((result == 0), "DIDT Config failed.", return result);
 				result = smu7_program_pt_config_registers(hwmgr, DIDTConfig_Polaris11);
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c b/drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c
index e5812aa..6e618aa 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c
@@ -65,6 +65,7 @@ int smum_init(struct amd_pp_init *pp_init, struct pp_instance *handle)
 			break;
 		case CHIP_POLARIS11:
 		case CHIP_POLARIS10:
+		case CHIP_POLARIS12:
 			polaris10_smum_init(smumgr);
 			break;
 		default:
--
2.10.2


code:
From 853277481178fdf14d1a4e9e6ac7174d6046176f Mon Sep 17 00:00:00 2001
From: Jani Nikula <jani.nikula@intel.com>
Date: Wed, 1 Feb 2017 15:46:09 +0200
Subject: [PATCH] drm/i915: don't warn about Skylake CPU - KabyPoint PCH combo

Apparently there are machines out there with Skylake CPU and KabyPoint
PCH. Judging from our driver code, there doesn't seem to be any code
paths that would do anything different between SunrisePoint and
KabyPoint PCHs, so it would seem okay to accept the combo without
warnings.

Fixes: 22dea0be50b2 ("drm/i915: Introduce Kabypoint PCH for Kabylake H/DT.")
References: https://lists.freedesktop.org/archives/intel-gfx/2017-February/118611.html
Reported-by: Rainer Koenig <Rainer.Koenig@ts.fujitsu.com>
Cc: Rainer Koenig <Rainer.Koenig@ts.fujitsu.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: <stable@vger.kernel.org> # v4.8+
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1485956769-26015-1-git-send-email-jani.nikula@intel.com
(cherry picked from commit 3aac4acb89710fe782c9e78e7b1febf76e112c6c)
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
[ rebased for 4.9 / tmb ]
Signed-off-by: Thomas Backlund <tmb@mageia.org>
---
 drivers/gpu/drm/i915/i915_drv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index b2c4a0b..8d63098 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -207,7 +207,8 @@ static void intel_detect_pch(struct drm_
 			} else if (id == INTEL_PCH_KBP_DEVICE_ID_TYPE) {
 				dev_priv->pch_type = PCH_KBP;
 				DRM_DEBUG_KMS("Found KabyPoint PCH\n");
-				WARN_ON(!IS_KABYLAKE(dev));
+				WARN_ON(!IS_SKYLAKE(dev) &&
+					!IS_KABYLAKE(dev));
 			} else if ((id == INTEL_PCH_P2X_DEVICE_ID_TYPE) ||
 				   (id == INTEL_PCH_P3X_DEVICE_ID_TYPE) ||
 				   ((id == INTEL_PCH_QEMU_DEVICE_ID_TYPE) &&


code:
Adapt mach64 to build with 2.6.31 series kernels

Signed-off-by: Thomas Backlund <tmb@mandriva.org>

diff -urp linux-2.6.31-rc3-git5-mnb1/drivers/gpu/drm/mach64/mach64_dma.c linux-2.6.31-rc3-git5-mnb1/drivers/gpu/drm/mach64.fixed/mach64_dma.c
--- linux-2.6.31-rc3-git5-mnb1/drivers/gpu/drm/mach64/mach64_dma.c	2009-07-23 00:24:12.000000000 +0300
+++ linux-2.6.31-rc3-git5-mnb1/drivers/gpu/drm/mach64.fixed/mach64_dma.c	2009-07-23 02:28:21.000000000 +0300
@@ -1006,7 +1006,7 @@ static int mach64_do_dma_init(struct drm

 	DRM_DEBUG("\n");

-	dev_priv = drm_alloc(sizeof(drm_mach64_private_t), DRM_MEM_DRIVER);
+	dev_priv = kmalloc(sizeof(drm_mach64_private_t), GFP_KERNEL);
 	if (dev_priv == NULL)
 		return -ENOMEM;

@@ -1386,8 +1386,7 @@ int mach64_do_cleanup_dma(struct drm_dev

 		mach64_destroy_freelist(dev);

-		drm_free(dev_priv, sizeof(drm_mach64_private_t),
-			 DRM_MEM_DRIVER);
+		kfree(dev_priv);
 		dev->dev_private = NULL;
 	}

@@ -1476,8 +1475,8 @@ int mach64_init_freelist(struct drm_devi
 	for (i = 0; i < dma->buf_count; i++) {
 		if ((entry =
 		     (drm_mach64_freelist_t *)
-		     drm_alloc(sizeof(drm_mach64_freelist_t),
-			       DRM_MEM_BUFLISTS)) == NULL)
+		     kmalloc(sizeof(drm_mach64_freelist_t),
+			       GFP_KERNEL)) == NULL)
 			return -ENOMEM;
 		memset(entry, 0, sizeof(drm_mach64_freelist_t));
 		entry->buf = dma->buflist[i];
@@ -1500,18 +1499,18 @@ void mach64_destroy_freelist(struct drm_
 	list_for_each_safe(ptr, tmp, &dev_priv->pending) {
 		list_del(ptr);
 		entry = list_entry(ptr, drm_mach64_freelist_t, list);
-		drm_free(entry, sizeof(*entry), DRM_MEM_BUFLISTS);
+		kfree(entry);
 	}
 	list_for_each_safe(ptr, tmp, &dev_priv->placeholders) {
 		list_del(ptr);
 		entry = list_entry(ptr, drm_mach64_freelist_t, list);
-		drm_free(entry, sizeof(*entry), DRM_MEM_BUFLISTS);
+		kfree(entry);
 	}

 	list_for_each_safe(ptr, tmp, &dev_priv->free_list) {
 		list_del(ptr);
 		entry = list_entry(ptr, drm_mach64_freelist_t, list);
-		drm_free(entry, sizeof(*entry), DRM_MEM_BUFLISTS);
+		kfree(entry);
 	}
 }

diff -urp linux-2.6.31-rc3-git5-mnb1/drivers/gpu/drm/mach64/mach64_state.c linux-2.6.31-rc3-git5-mnb1/drivers/gpu/drm/mach64.fixed/mach64_state.c
--- linux-2.6.31-rc3-git5-mnb1/drivers/gpu/drm/mach64/mach64_state.c	2009-07-23 00:24:12.000000000 +0300
+++ linux-2.6.31-rc3-git5-mnb1/drivers/gpu/drm/mach64.fixed/mach64_state.c	2009-07-23 02:29:24.000000000 +0300
@@ -490,12 +490,12 @@ static __inline__ int copy_from_user_ver
 	unsigned long n = bytes;	/* dwords remaining in buffer */
 	u32 *from, *orig_from;

-	from = drm_alloc(bytes, DRM_MEM_DRIVER);
+	from = kmalloc(bytes, GFP_KERNEL);
 	if (from == NULL)
 		return -ENOMEM;

 	if (DRM_COPY_FROM_USER(from, ufrom, bytes)) {
-		drm_free(from, bytes, DRM_MEM_DRIVER);
+		kfree(from);
 		return -EFAULT;
 	}
 	orig_from = from; /* we'll be modifying the "from" ptr, so save it */
@@ -526,19 +526,19 @@ static __inline__ int copy_from_user_ver
 				to += count;
 			} else {
 				DRM_ERROR("Got bad command: 0x%04x\n", reg);
-				drm_free(orig_from, bytes, DRM_MEM_DRIVER);
+				kfree(orig_from);
 				return -EACCES;
 			}
 		} else {
 			DRM_ERROR
 			    ("Got bad command count(=%u) dwords remaining=%lu\n",
 			     count, n);
-			drm_free(orig_from, bytes, DRM_MEM_DRIVER);
+			kfree(orig_from);
 			return -EINVAL;
 		}
 	}

-	drm_free(orig_from, bytes, DRM_MEM_DRIVER);
+	kfree(orig_from);
 	if (n == 0)
 		return 0;
 	else {


code:
--- linux-2.6.35/drivers/gpu/drm/mach64/mach64_state.c.orig	2010-10-03 13:29:10.000000000 +0300
+++ linux-2.6.35/drivers/gpu/drm/mach64/mach64_state.c	2010-10-03 14:04:45.991164007 +0300
@@ -41,15 +41,15 @@
  *
  */
 struct drm_ioctl_desc mach64_ioctls[] = {
-	DRM_IOCTL_DEF(DRM_MACH64_INIT, mach64_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-	DRM_IOCTL_DEF(DRM_MACH64_CLEAR, mach64_dma_clear, DRM_AUTH),
-	DRM_IOCTL_DEF(DRM_MACH64_SWAP, mach64_dma_swap, DRM_AUTH),
-	DRM_IOCTL_DEF(DRM_MACH64_IDLE, mach64_dma_idle, DRM_AUTH),
-	DRM_IOCTL_DEF(DRM_MACH64_RESET, mach64_engine_reset, DRM_AUTH),
-	DRM_IOCTL_DEF(DRM_MACH64_VERTEX, mach64_dma_vertex, DRM_AUTH),
-	DRM_IOCTL_DEF(DRM_MACH64_BLIT, mach64_dma_blit, DRM_AUTH),
-	DRM_IOCTL_DEF(DRM_MACH64_FLUSH, mach64_dma_flush, DRM_AUTH),
-	DRM_IOCTL_DEF(DRM_MACH64_GETPARAM, mach64_get_param, DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(MACH64_INIT, mach64_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+	DRM_IOCTL_DEF_DRV(MACH64_CLEAR, mach64_dma_clear, DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(MACH64_SWAP, mach64_dma_swap, DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(MACH64_IDLE, mach64_dma_idle, DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(MACH64_RESET, mach64_engine_reset, DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(MACH64_VERTEX, mach64_dma_vertex, DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(MACH64_BLIT, mach64_dma_blit, DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(MACH64_FLUSH, mach64_dma_flush, DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(MACH64_GETPARAM, mach64_get_param, DRM_AUTH),
 };

 int mach64_max_ioctl = DRM_ARRAY_SIZE(mach64_ioctls);


code:
Fix build for 2.6.37

Signed-off-by: Thomas Backlund <tmb@mandriva.org>

--- a/drivers/gpu/drm/mach64/mach64_drv.c.orig	2011-01-02 16:55:48.000000000 +0200
+++ a/drivers/gpu/drm/mach64/mach64_drv.c	2011-01-02 17:53:54.808775632 +0200
@@ -51,8 +51,6 @@ static struct drm_driver driver = {
 	.irq_uninstall = mach64_driver_irq_uninstall,
 	.irq_handler = mach64_driver_irq_handler,
 	.reclaim_buffers = drm_core_reclaim_buffers,
-	.get_map_ofs = drm_core_get_map_ofs,
-	.get_reg_ofs = drm_core_get_reg_ofs,
 	.ioctls = mach64_ioctls,
 	.dma_ioctl = mach64_dma_buffers,
 	.fops = {
@@ -63,6 +61,7 @@ static struct drm_driver driver = {
 		.mmap = drm_mmap,
 		.poll = drm_poll,
 		.fasync = drm_fasync,
+		.llseek = noop_llseek,
 		},
 	.pci_driver = {
 		.name = DRIVER_NAME,


code:
fix build with linux-3.0

Signed-off-by: Thomas Backlund <tmb@mageia.org>

 drivers/gpu/drm/mach64/mach64_drv.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

--- a/drivers/gpu/drm/mach64/mach64_drv.c.orig	2011-07-15 02:48:40.000000000 +0300
+++ a/drivers/gpu/drm/mach64/mach64_drv.c	2011-07-15 13:24:41.454753025 +0300
@@ -63,10 +63,6 @@ static struct drm_driver driver = {
 		.fasync = drm_fasync,
 		.llseek = noop_llseek,
 		},
-	.pci_driver = {
-		.name = DRIVER_NAME,
-		.id_table = pciidlist,
-	},

 	.name = DRIVER_NAME,
 	.desc = DRIVER_DESC,
@@ -76,15 +72,20 @@ static struct drm_driver driver = {
 	.patchlevel = DRIVER_PATCHLEVEL,
 };

+static struct pci_driver mach64_pci_driver = {
+	.name = DRIVER_NAME,
+	.id_table = pciidlist,
+};
+
 static int __init mach64_init(void)
 {
 	driver.num_ioctls = mach64_max_ioctl;
-	return drm_init(&driver);
+	return drm_pci_init(&driver, &mach64_pci_driver);
 }

 static void __exit mach64_exit(void)
 {
-	drm_exit(&driver);
+	drm_pci_exit(&driver, &mach64_pci_driver);
 }

 module_init(mach64_init);


code:
--- linux/drivers/gpu/drm/mach64/mach64_drv.c.orig	2013-10-13 12:19:41.000000000 +0300
+++ linux/drivers/gpu/drm/mach64/mach64_drv.c	2013-10-13 14:27:25.684247911 +0300
@@ -46,13 +46,12 @@ static const struct file_operations mach
 	.unlocked_ioctl = drm_ioctl,
 	.mmap = drm_mmap,
 	.poll = drm_poll,
-	.fasync = drm_fasync,
 	.llseek = noop_llseek,
 };

 static struct drm_driver driver = {
 	.driver_features =
-	    DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_HAVE_DMA
+	    DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_HAVE_DMA
 	    | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED,
 	.lastclose = mach64_driver_lastclose,
 	.get_vblank_counter = mach64_get_vblank_counter,


code:
Adapt for kernel-3.17

DRM_ARRAY_SIZE is a duplicate of ARRAY_SIZE and have been dropped.

drm_dev_to_irq has been dropped, so call dev->pdev->irq directly
for code simplicity.

Signed-off-by: Thomas Backlund <tmb@mageia.org>

diff -urp linux/drivers/gpu/drm/mach64/mach64_state.c.orig linux/drivers/gpu/drm/mach64/mach64_state.c
--- linux/drivers/gpu/drm/mach64/mach64_state.c.orig
+++ linux/drivers/gpu/drm/mach64/mach64_state.c
@@ -52,7 +52,7 @@ struct drm_ioctl_desc mach64_ioctls[] =
 	DRM_IOCTL_DEF_DRV(MACH64_GETPARAM, mach64_get_param, DRM_AUTH),
 };

-int mach64_max_ioctl = DRM_ARRAY_SIZE(mach64_ioctls);
+int mach64_max_ioctl = ARRAY_SIZE(mach64_ioctls);

 /* ================================================================
  * DMA hardware state programming functions
@@ -895,7 +895,7 @@ int mach64_get_param(struct drm_device *
 		value = mach64_do_get_frames_queued(dev_priv);
 		break;
 	case MACH64_PARAM_IRQ_NR:
-		value = drm_dev_to_irq(dev);
+		value = dev->pdev->irq;
 		break;
 	default:
 		return -EINVAL;


code:
Fix build with kernel 3.18

Signed-off-by: Thomas Backlund <tmb@mageia.org>

diff -urp linux/drivers/gpu/drm/mach64.orig/mach64_dma.c linux/drivers/gpu/drm/mach64/mach64_dma.c
--- linux/drivers/gpu/drm/mach64.orig/mach64_dma.c	2014-11-29 22:01:54.000000000 +0200
+++ linux/drivers/gpu/drm/mach64/mach64_dma.c	2014-11-30 00:02:06.906821818 +0200
@@ -1038,21 +1038,21 @@ static int mach64_do_dma_init(struct drm
 	INIT_LIST_HEAD(&dev_priv->placeholders);
 	INIT_LIST_HEAD(&dev_priv->pending);

-	dev_priv->sarea = drm_getsarea(dev);
+	dev_priv->sarea = drm_legacy_getsarea(dev);
 	if (!dev_priv->sarea) {
 		DRM_ERROR("can not find sarea!\n");
 		dev->dev_private = (void *)dev_priv;
 		mach64_do_cleanup_dma(dev);
 		return -EINVAL;
 	}
-	dev_priv->fb = drm_core_findmap(dev, init->fb_offset);
+	dev_priv->fb = drm_legacy_findmap(dev, init->fb_offset);
 	if (!dev_priv->fb) {
 		DRM_ERROR("can not find frame buffer map!\n");
 		dev->dev_private = (void *)dev_priv;
 		mach64_do_cleanup_dma(dev);
 		return -EINVAL;
 	}
-	dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset);
+	dev_priv->mmio = drm_legacy_findmap(dev, init->mmio_offset);
 	if (!dev_priv->mmio) {
 		DRM_ERROR("can not find mmio map!\n");
 		dev->dev_private = (void *)dev_priv;
@@ -1060,7 +1060,7 @@ static int mach64_do_dma_init(struct drm
 		return -EINVAL;
 	}

-	dev_priv->ring_map = drm_core_findmap(dev, init->ring_offset);
+	dev_priv->ring_map = drm_legacy_findmap(dev, init->ring_offset);
 	if (!dev_priv->ring_map) {
 		DRM_ERROR("can not find ring map!\n");
 		dev->dev_private = (void *)dev_priv;
@@ -1072,7 +1072,7 @@ static int mach64_do_dma_init(struct drm
 	    ((u8 *) dev_priv->sarea->handle + init->sarea_priv_offset);

 	if (!dev_priv->is_pci) {
-		drm_core_ioremap(dev_priv->ring_map, dev);
+		drm_legacy_ioremap(dev_priv->ring_map, dev);
 		if (!dev_priv->ring_map->handle) {
 			DRM_ERROR("can not ioremap virtual address for"
 				  " descriptor ring\n");
@@ -1082,7 +1082,7 @@ static int mach64_do_dma_init(struct drm
 		}
 		dev->agp_buffer_token = init->buffers_offset;
 		dev->agp_buffer_map =
-		    drm_core_findmap(dev, init->buffers_offset);
+		    drm_legacy_findmap(dev, init->buffers_offset);
 		if (!dev->agp_buffer_map) {
 			DRM_ERROR("can not find dma buffer map!\n");
 			dev->dev_private = (void *)dev_priv;
@@ -1093,7 +1093,7 @@ static int mach64_do_dma_init(struct drm
 		   dev isn't passed all the way though the mach64 - DA */
 		dev_priv->dev_buffers = dev->agp_buffer_map;

-		drm_core_ioremap(dev->agp_buffer_map, dev);
+		drm_legacy_ioremap(dev->agp_buffer_map, dev);
 		if (!dev->agp_buffer_map->handle) {
 			DRM_ERROR("can not ioremap virtual address for"
 				  " dma buffer\n");
@@ -1102,7 +1102,7 @@ static int mach64_do_dma_init(struct drm
 			return -ENOMEM;
 		}
 		dev_priv->agp_textures =
-		    drm_core_findmap(dev, init->agp_textures_offset);
+		    drm_legacy_findmap(dev, init->agp_textures_offset);
 		if (!dev_priv->agp_textures) {
 			DRM_ERROR("can not find agp texture region!\n");
 			dev->dev_private = (void *)dev_priv;
@@ -1376,10 +1376,10 @@ int mach64_do_cleanup_dma(struct drm_dev

 		if (!dev_priv->is_pci) {
 			if (dev_priv->ring_map)
-				drm_core_ioremapfree(dev_priv->ring_map, dev);
+				drm_legacy_ioremapfree(dev_priv->ring_map, dev);

 			if (dev->agp_buffer_map) {
-				drm_core_ioremapfree(dev->agp_buffer_map, dev);
+				drm_legacy_ioremapfree(dev->agp_buffer_map, dev);
 				dev->agp_buffer_map = NULL;
 			}
 		}
diff -urp linux/drivers/gpu/drm/mach64.orig/mach64_drv.c linux/drivers/gpu/drm/mach64/mach64_drv.c
--- linux/drivers/gpu/drm/mach64.orig/mach64_drv.c	2014-11-29 22:01:54.000000000 +0200
+++ linux/drivers/gpu/drm/mach64/mach64_drv.c	2014-11-29 23:14:21.918009653 +0200
@@ -34,6 +34,7 @@
 #include "mach64_drv.h"

 #include <drm/drm_pciids.h>
+#include <drm/drm_legacy.h>

 static struct pci_device_id pciidlist[] = {
 	mach64_PCI_IDS
@@ -44,7 +45,7 @@ static const struct file_operations mach
 	.open = drm_open,
 	.release = drm_release,
 	.unlocked_ioctl = drm_ioctl,
-	.mmap = drm_mmap,
+	.mmap = drm_legacy_mmap,
 	.poll = drm_poll,
 	.llseek = noop_llseek,
 };
diff -urp linux/drivers/gpu/drm/mach64.orig/mach64_drv.h linux/drivers/gpu/drm/mach64/mach64_drv.h
--- linux/drivers/gpu/drm/mach64.orig/mach64_drv.h	2014-11-29 22:01:54.000000000 +0200
+++ linux/drivers/gpu/drm/mach64/mach64_drv.h	2014-11-29 23:58:20.111491646 +0200
@@ -35,6 +35,8 @@
 #ifndef __MACH64_DRV_H__
 #define __MACH64_DRV_H__

+#include <drm/drm_legacy.h>
+
 /* General customization:
  */

@@ -102,12 +104,12 @@ typedef struct drm_mach64_private {
 	u32 back_offset_pitch;
 	u32 depth_offset_pitch;

-	drm_local_map_t *sarea;
-	drm_local_map_t *fb;
-	drm_local_map_t *mmio;
-	drm_local_map_t *ring_map;
-	drm_local_map_t *dev_buffers;	/* this is a pointer to a structure in dev */
-	drm_local_map_t *agp_textures;
+	struct drm_local_map *sarea;
+	struct drm_local_map *fb;
+	struct drm_local_map *mmio;
+	struct drm_local_map *ring_map;
+	struct drm_local_map *dev_buffers;	/* this is a pointer to a structure in dev */
+	struct drm_local_map *agp_textures;
 } drm_mach64_private_t;

 extern struct drm_ioctl_desc mach64_ioctls[];


code:
This moves the .fops to a separate struct as required by kernel-3.3

Signed-off-by: Thomas Backlund <tmb@mageia.org>

 b/drivers/gpu/drm/mach64/mach64_drv.c |   23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

--- a/drivers/gpu/drm/mach64/mach64_drv.c
+++ b/drivers/gpu/drm/mach64/mach64_drv.c
@@ -39,6 +39,17 @@ static struct pci_device_id pciidlist[]
 	mach64_PCI_IDS
 };

+static const struct file_operations mach64_driver_fops = {
+	.owner = THIS_MODULE,
+	.open = drm_open,
+	.release = drm_release,
+	.unlocked_ioctl = drm_ioctl,
+	.mmap = drm_mmap,
+	.poll = drm_poll,
+	.fasync = drm_fasync,
+	.llseek = noop_llseek,
+};
+
 static struct drm_driver driver = {
 	.driver_features =
 	    DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_HAVE_DMA
@@ -54,17 +65,7 @@ static struct drm_driver driver = {
 	.reclaim_buffers = drm_core_reclaim_buffers,
 	.ioctls = mach64_ioctls,
 	.dma_ioctl = mach64_dma_buffers,
-	.fops = {
-		.owner = THIS_MODULE,
-		.open = drm_open,
-		.release = drm_release,
-		.unlocked_ioctl = drm_ioctl,
-		.mmap = drm_mmap,
-		.poll = drm_poll,
-		.fasync = drm_fasync,
-		.llseek = noop_llseek,
-		},
-
+	.fops = &mach64_driver_fops,
 	.name = DRIVER_NAME,
 	.desc = DRIVER_DESC,
 	.date = DRIVER_DATE,


code:
reclaim_buffers is gone in 3.6

Signed-off-by: Thomas Backlund <tmb@mageia.org>

--- linux/drivers/gpu/drm/mach64/mach64_drv.c.orig	2012-10-17 22:26:58.000000000 +0300
+++ linux/drivers/gpu/drm/mach64/mach64_drv.c	2012-10-17 23:05:10.212566630 +0300
@@ -62,7 +62,6 @@ static struct drm_driver driver = {
 	.irq_postinstall = mach64_driver_irq_postinstall,
 	.irq_uninstall = mach64_driver_irq_uninstall,
 	.irq_handler = mach64_driver_irq_handler,
-	.reclaim_buffers = drm_core_reclaim_buffers,
 	.ioctls = mach64_ioctls,
 	.dma_ioctl = mach64_dma_buffers,
 	.fops = &mach64_driver_fops,


code:
diff -Nurp linux-3.7-rc8/drivers/gpu/drm/mach64.orig/mach64_dma.c linux-3.7-rc8/drivers/gpu/drm/mach64/mach64_dma.c
--- linux-3.7-rc8/drivers/gpu/drm/mach64.orig/mach64_dma.c	2012-12-06 19:50:10.000000000 +0200
+++ linux-3.7-rc8/drivers/gpu/drm/mach64/mach64_dma.c	2012-12-06 20:19:10.590681644 +0200
@@ -34,8 +34,8 @@
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */

-#include "drmP.h"
-#include "drm.h"
+#include <drm/drmP.h>
+#include <drm/drm.h>
 #include "mach64_drm.h"
 #include "mach64_drv.h"

diff -Nurp linux-3.7-rc8/drivers/gpu/drm/mach64.orig/mach64_drv.c linux-3.7-rc8/drivers/gpu/drm/mach64/mach64_drv.c
--- linux-3.7-rc8/drivers/gpu/drm/mach64.orig/mach64_drv.c	2012-12-06 19:50:10.000000000 +0200
+++ linux-3.7-rc8/drivers/gpu/drm/mach64/mach64_drv.c	2012-12-06 20:20:13.062073838 +0200
@@ -28,12 +28,12 @@
  */

 #include <linux/module.h>
-#include "drmP.h"
-#include "drm.h"
+#include <drm/drmP.h>
+#include <drm/drm.h>
 #include "mach64_drm.h"
 #include "mach64_drv.h"

-#include "drm_pciids.h"
+#include <drm/drm_pciids.h>

 static struct pci_device_id pciidlist[] = {
 	mach64_PCI_IDS
diff -Nurp linux-3.7-rc8/drivers/gpu/drm/mach64.orig/mach64_irq.c linux-3.7-rc8/drivers/gpu/drm/mach64/mach64_irq.c
--- linux-3.7-rc8/drivers/gpu/drm/mach64.orig/mach64_irq.c	2012-12-06 19:50:10.000000000 +0200
+++ linux-3.7-rc8/drivers/gpu/drm/mach64/mach64_irq.c	2012-12-06 20:20:40.192678476 +0200
@@ -35,8 +35,8 @@
  *    Leif Delgass <ldelgass@retinalburn.net>
  */

-#include "drmP.h"
-#include "drm.h"
+#include <drm/drmP.h>
+#include <drm/drm.h>
 #include "mach64_drm.h"
 #include "mach64_drv.h"

diff -Nurp linux-3.7-rc8/drivers/gpu/drm/mach64.orig/mach64_state.c linux-3.7-rc8/drivers/gpu/drm/mach64/mach64_state.c
--- linux-3.7-rc8/drivers/gpu/drm/mach64.orig/mach64_state.c	2012-12-06 19:50:10.000000000 +0200
+++ linux-3.7-rc8/drivers/gpu/drm/mach64/mach64_state.c	2012-12-06 20:21:00.783137370 +0200
@@ -30,8 +30,8 @@
  *    José Fonseca <j_r_fonseca@yahoo.co.uk>
  */

-#include "drmP.h"
-#include "drm.h"
+#include <drm/drmP.h>
+#include <drm/drm.h>
 #include "mach64_drm.h"
 #include "mach64_drv.h"


code:
Update mach64 for changes in drm_ioctl done in 2.6.33:
"drm: convert drm_ioctl to unlocked_ioctl" (commit ed8b670)

Signed-off-by: Herton Ronaldo Krzesinski <herton@mandriva.com.br>
---
 drivers/gpu/drm/mach64/mach64_drv.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff -p -up linux-2.6.33/drivers/gpu/drm/mach64/mach64_drv.c.orig linux-2.6.33/drivers/gpu/drm/mach64/mach64_drv.c
--- linux-2.6.33/drivers/gpu/drm/mach64/mach64_drv.c.orig	2010-03-16 19:27:22.517068880 -0300
+++ linux-2.6.33/drivers/gpu/drm/mach64/mach64_drv.c	2010-03-16 19:27:54.890318416 -0300
@@ -59,7 +59,7 @@ static struct drm_driver driver = {
 		.owner = THIS_MODULE,
 		.open = drm_open,
 		.release = drm_release,
-		.ioctl = drm_ioctl,
+		.unlocked_ioctl = drm_ioctl,
 		.mmap = drm_mmap,
 		.poll = drm_poll,
 		.fasync = drm_fasync,


code:
diff -p -up linux-2.6.32/drivers/gpu/drm/mach64/mach64_dma.c.orig linux-2.6.32/drivers/gpu/drm/mach64/mach64_dma.c
--- linux-2.6.32/drivers/gpu/drm/mach64/mach64_dma.c.orig	2010-01-06 11:35:13.784843304 -0200
+++ linux-2.6.32/drivers/gpu/drm/mach64/mach64_dma.c	2010-01-06 11:37:50.793843502 -0200
@@ -835,7 +835,7 @@ static int mach64_bm_dma_test(struct drm
 	/* FIXME: get a dma buffer from the freelist here */
 	DRM_DEBUG("Allocating data memory ...\n");
 	cpu_addr_dmah =
-	    drm_pci_alloc(dev, 0x1000, 0x1000, 0xfffffffful);
+	    drm_pci_alloc(dev, 0x1000, 0x1000);
 	if (!cpu_addr_dmah) {
 		DRM_INFO("data-memory allocation failed!\n");
 		return -ENOMEM;


code:
Fix/cleanup mach64 drm module for building with current kernel.

Signed-off-by: Herton Ronaldo Krzesinski <herton@mandriva.com.br>

---
 drivers/gpu/drm/mach64/mach64_dma.c   |    9 +--------
 drivers/gpu/drm/mach64/mach64_drv.c   |   11 +----------
 drivers/gpu/drm/mach64/mach64_state.c |    4 ++--
 3 files changed, 4 insertions(+), 20 deletions(-)

diff -p -up linux-2.6.28/drivers/gpu/drm/mach64/mach64_dma.c.orig linux-2.6.28/drivers/gpu/drm/mach64/mach64_dma.c
--- linux-2.6.28/drivers/gpu/drm/mach64/mach64_dma.c.orig	2008-12-10 12:19:14.000000000 -0500
+++ linux-2.6.28/drivers/gpu/drm/mach64/mach64_dma.c	2008-12-10 13:34:19.000000000 -0500
@@ -834,14 +834,8 @@ static int mach64_bm_dma_test(struct drm

 	/* FIXME: get a dma buffer from the freelist here */
 	DRM_DEBUG("Allocating data memory ...\n");
-#ifdef __FreeBSD__
-	DRM_UNLOCK();
-#endif
 	cpu_addr_dmah =
 	    drm_pci_alloc(dev, 0x1000, 0x1000, 0xfffffffful);
-#ifdef __FreeBSD__
-	DRM_LOCK();
-#endif
 	if (!cpu_addr_dmah) {
 		DRM_INFO("data-memory allocation failed!\n");
 		return -ENOMEM;
@@ -1375,8 +1369,7 @@ int mach64_do_cleanup_dma(struct drm_dev
 	 * may not have been called from userspace and after dev_private
 	 * is freed, it's too late.
 	 */
-	if (dev->irq)
-		drm_irq_uninstall(dev);
+	drm_irq_uninstall(dev);

 	if (dev->dev_private) {
 		drm_mach64_private_t *dev_priv = dev->dev_private;
diff -p -up linux-2.6.28/drivers/gpu/drm/mach64/mach64_drv.c.orig linux-2.6.28/drivers/gpu/drm/mach64/mach64_drv.c
--- linux-2.6.28/drivers/gpu/drm/mach64/mach64_drv.c.orig	2008-12-10 12:13:13.000000000 -0500
+++ linux-2.6.28/drivers/gpu/drm/mach64/mach64_drv.c	2008-12-10 12:16:54.000000000 -0500
@@ -38,7 +38,6 @@ static struct pci_device_id pciidlist[]
 	mach64_PCI_IDS
 };

-static int probe(struct pci_dev *pdev, const struct pci_device_id *ent);
 static struct drm_driver driver = {
 	.driver_features =
 	    DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_HAVE_DMA
@@ -68,8 +67,6 @@ static struct drm_driver driver = {
 	.pci_driver = {
 		.name = DRIVER_NAME,
 		.id_table = pciidlist,
-		.probe = probe,
-		.remove = __devexit_p(drm_cleanup_pci),
 	},

 	.name = DRIVER_NAME,
@@ -80,16 +77,10 @@ static struct drm_driver driver = {
 	.patchlevel = DRIVER_PATCHLEVEL,
 };

-static int probe(struct pci_dev *pdev, const struct pci_device_id *ent)
-{
-	return drm_get_dev(pdev, ent, &driver);
-}
-
-
 static int __init mach64_init(void)
 {
 	driver.num_ioctls = mach64_max_ioctl;
-	return drm_init(&driver, pciidlist);
+	return drm_init(&driver);
 }

 static void __exit mach64_exit(void)
diff -p -up linux-2.6.28/drivers/gpu/drm/mach64/mach64_state.c.orig linux-2.6.28/drivers/gpu/drm/mach64/mach64_state.c
--- linux-2.6.28/drivers/gpu/drm/mach64/mach64_state.c.orig	2008-12-10 12:13:13.000000000 -0500
+++ linux-2.6.28/drivers/gpu/drm/mach64/mach64_state.c	2008-12-10 13:38:54.000000000 -0500
@@ -455,7 +455,7 @@ static int mach64_do_get_frames_queued(d
 	head = ring->head;

 	start = (MACH64_MAX_QUEUED_FRAMES -
-		 DRM_MIN(MACH64_MAX_QUEUED_FRAMES, sarea_priv->frames_queued));
+		 min(MACH64_MAX_QUEUED_FRAMES, sarea_priv->frames_queued));

 	if (head == tail) {
 		sarea_priv->frames_queued = 0;
@@ -895,7 +895,7 @@ int mach64_get_param(struct drm_device *
 		value = mach64_do_get_frames_queued(dev_priv);
 		break;
 	case MACH64_PARAM_IRQ_NR:
-		value = dev->irq;
+		value = drm_dev_to_irq(dev);
 		break;
 	default:
 		return -EINVAL;


code:
--- linux/drivers/gpu/drm/mach64/mach64_drv.c.orig	2011-12-25 00:48:42.814932355 +0200
+++ linux/drivers/gpu/drm/mach64/mach64_drv.c	2011-12-25 00:47:43.393625260 +0200
@@ -27,6 +27,7 @@
  *    Leif Delgass <ldelgass@retinalburn.net>
  */

+#include <linux/module.h>
 #include "drmP.h"
 #include "drm.h"
 #include "mach64_drm.h"


code:
Fix build with kernel-3.14

Signed-off-by: Thomas Backlund <tmb@mageia.org>

 drivers/gpu/drm/mach64/mach64_dma.c   |   10 +++++-----
 drivers/gpu/drm/mach64/mach64_drv.h   |    2 +-
 drivers/gpu/drm/mach64/mach64_irq.c   |    2 +-
 drivers/gpu/drm/mach64/mach64_state.c |    6 +++---
 4 files changed, 10 insertions(+), 10 deletions(-)

diff -urp linux/drivers/gpu/drm/mach64.orig/mach64_dma.c linux/drivers/gpu/drm/mach64/mach64_dma.c
--- linux/drivers/gpu/drm/mach64.orig/mach64_dma.c	2014-04-26 19:10:55.000000000 +0300
+++ linux/drivers/gpu/drm/mach64/mach64_dma.c	2014-04-26 20:26:05.263501325 +0300
@@ -696,9 +696,9 @@ do {									\
 		DRM_INFO( "ADVANCE_RING() wr=0x%06x tail=0x%06x\n",	\
 			  _ring_write, _ring_tail );			\
 	}								\
-	DRM_MEMORYBARRIER();						\
+	mb();								\
 	mach64_clear_dma_eol( &_ring[(_ring_tail - 2) & _ring_mask] );	\
-	DRM_MEMORYBARRIER();						\
+	mb();								\
 	dev_priv->ring.tail = _ring_write;				\
 	mach64_ring_tick( dev_priv, &(dev_priv)->ring );		\
 } while (0)
@@ -912,7 +912,7 @@ static int mach64_bm_dma_test(struct drm
 		DRM_DEBUG(" data[%d] = 0x%08x\n", i, data[i]);
 	}

-	DRM_MEMORYBARRIER();
+	mb();

 	DRM_DEBUG("waiting for idle...\n");
 	if ((i = mach64_do_wait_for_idle(dev_priv))) {
@@ -1716,10 +1716,10 @@ static int mach64_dma_get_buffers(struct

 		buf->file_priv = file_priv;

-		if (DRM_COPY_TO_USER(&d->request_indices[i], &buf->idx,
+		if (copy_to_user(&d->request_indices[i], &buf->idx,
 				     sizeof(buf->idx)))
 			return -EFAULT;
-		if (DRM_COPY_TO_USER(&d->request_sizes[i], &buf->total,
+		if (copy_to_user(&d->request_sizes[i], &buf->total,
 				     sizeof(buf->total)))
 			return -EFAULT;

diff -urp linux/drivers/gpu/drm/mach64.orig/mach64_drv.h linux/drivers/gpu/drm/mach64/mach64_drv.h
--- linux/drivers/gpu/drm/mach64.orig/mach64_drv.h	2014-04-26 19:10:55.000000000 +0300
+++ linux/drivers/gpu/drm/mach64/mach64_drv.h	2014-04-26 20:28:43.693457652 +0300
@@ -166,7 +166,7 @@ extern int mach64_get_param(struct drm_d
 extern u32 mach64_get_vblank_counter(struct drm_device *dev, int crtc);
 extern int mach64_enable_vblank(struct drm_device *dev, int crtc);
 extern void mach64_disable_vblank(struct drm_device *dev, int crtc);
-extern irqreturn_t mach64_driver_irq_handler(DRM_IRQ_ARGS);
+extern irqreturn_t mach64_driver_irq_handler(int irq, void *arg);
 extern void mach64_driver_irq_preinstall(struct drm_device *dev);
 extern int mach64_driver_irq_postinstall(struct drm_device *dev);
 extern void mach64_driver_irq_uninstall(struct drm_device *dev);
diff -urp linux/drivers/gpu/drm/mach64.orig/mach64_irq.c linux/drivers/gpu/drm/mach64/mach64_irq.c
--- linux/drivers/gpu/drm/mach64.orig/mach64_irq.c	2014-04-26 19:10:55.000000000 +0300
+++ linux/drivers/gpu/drm/mach64/mach64_irq.c	2014-04-26 20:32:01.464898140 +0300
@@ -40,7 +40,7 @@
 #include "mach64_drm.h"
 #include "mach64_drv.h"

-irqreturn_t mach64_driver_irq_handler(DRM_IRQ_ARGS)
+irqreturn_t mach64_driver_irq_handler(int irq, void *arg)
 {
 	struct drm_device *dev = arg;
 	drm_mach64_private_t *dev_priv = dev->dev_private;
diff -urp linux/drivers/gpu/drm/mach64.orig/mach64_state.c linux/drivers/gpu/drm/mach64/mach64_state.c
--- linux/drivers/gpu/drm/mach64.orig/mach64_state.c	2014-04-26 19:10:55.000000000 +0300
+++ linux/drivers/gpu/drm/mach64/mach64_state.c	2014-04-26 20:07:16.701527488 +0300
@@ -494,7 +494,7 @@ static __inline__ int copy_from_user_ver
 	if (from == NULL)
 		return -ENOMEM;

-	if (DRM_COPY_FROM_USER(from, ufrom, bytes)) {
+	if (copy_from_user(from, ufrom, bytes)) {
 		kfree(from);
 		return -EFAULT;
 	}
@@ -640,7 +640,7 @@ static __inline__ int copy_from_user_bli
 {
 	to = (u32 *)((char *)to + MACH64_HOSTDATA_BLIT_OFFSET);

-	if (DRM_COPY_FROM_USER(to, ufrom, bytes)) {
+	if (copy_from_user(to, ufrom, bytes)) {
 		return -EFAULT;
 	}

@@ -901,7 +901,7 @@ int mach64_get_param(struct drm_device *
 		return -EINVAL;
 	}

-	if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) {
+	if (copy_to_user(param->value, &value, sizeof(int))) {
 		DRM_ERROR("copy_to_user\n");
 		return -EFAULT;
 	}