Skip to contentSkip to conversation

radeon: Allow execution of scripts in atomic context

PATCH New Matthew Garrett 1 participant 4 messages Mar 22, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 radeon: Allow execution of scripts in atomic context

We want to perform radeon memory reclocking in interrupt context, so need to ensure that we don't do anything that may sleep. Add an alternate entry point to the atom interpreter that flags things appropriately and make behaviour conditional on that.

---
 drivers/gpu/drm/radeon/atom.c          |   26 ++++++++++++++++++++++++--
 drivers/gpu/drm/radeon/atom.h          |    4 +++-
 drivers/gpu/drm/radeon/radeon_device.c |    2 +-
 3 files changed, 28 insertions(+), 4 deletions(-)
drivers/gpu/drm/radeon/atom.c +24 -2
index 247f8ee..bd5c5b5 100644
@@ -651,6 +651,8 @@ static void atom_op_delay(atom_exec_context *ctx, int *ptr, int arg)
 	SDEBUG("   count: %d\n", count);
 	if (arg == ATOM_UNIT_MICROSEC)
 		udelay(count);
+	else if (ctx->ctx->atomic)
+		mdelay(count);
 	else
 		schedule_timeout_uninterruptible(msecs_to_jiffies(count));
 }
@@ -1191,8 +1193,9 @@ static int atom_execute_table_locked(struct atom_context *ctx, int index, uint32
 int atom_execute_table(struct atom_context *ctx, int index, uint32_t * params)
 {
 	int r;
+	unsigned long flags;
 
-	mutex_lock(&ctx->mutex);
+	spin_lock_irqsave(&ctx->spinlock, flags);
 	/* reset reg block */
 	ctx->reg_block = 0;
 	/* reset fb window */
@@ -1200,7 +1203,26 @@ int atom_execute_table(struct atom_context *ctx, int index, uint32_t * params)
 	/* reset io mode */
 	ctx->io_mode = ATOM_IO_MM;
 	r = atom_execute_table_locked(ctx, index, params);
-	mutex_unlock(&ctx->mutex);
+	spin_unlock_irqrestore(&ctx->spinlock, flags);
+	return r;
+}
+
+int atom_execute_table_atomic(struct atom_context *ctx, int index, uint32_t * params)
+{
+	int r;
+	unsigned long flags;
+	spin_lock_irqsave(&ctx->spinlock, flags);
+	/* reset reg block */
+	ctx->reg_block = 0;
+	/* reset fb window */
+	ctx->fb_base = 0;
+	/* reset io mode */
+	ctx->io_mode = ATOM_IO_MM;
+	/* be atomic */
+	ctx->atomic = true;
+	r = atom_execute_table_locked(ctx, index, params);
+	ctx->atomic = false;
+	spin_unlock_irqrestore(&ctx->spinlock, flags);
 	return r;
 }
 
drivers/gpu/drm/radeon/atom.h +3 -1
index cd1b64a..c26f5e1 100644
@@ -121,7 +121,7 @@ struct card_info {
 
 struct atom_context {
 	struct card_info *card;
-	struct mutex mutex;
+	spinlock_t spinlock;
 	void *bios;
 	uint32_t cmd_table, data_table;
 	uint16_t *iio;
@@ -135,12 +135,14 @@ struct atom_context {
 	int cs_equal, cs_above;
 	int io_mode;
 	uint32_t *scratch;
+	bool atomic;
 };
 
 extern int atom_debug;
 
 struct atom_context *atom_parse(struct card_info *, void *);
 int atom_execute_table(struct atom_context *, int, uint32_t *);
+int atom_execute_table_atomic(struct atom_context *, int, uint32_t *);
 int atom_asic_init(struct atom_context *);
 void atom_destroy(struct atom_context *);
 bool atom_parse_data_header(struct atom_context *ctx, int index, uint16_t *size,
drivers/gpu/drm/radeon/radeon_device.c +1 -1
index 75f7b1e..3a711a9 100644
@@ -384,7 +384,7 @@ int radeon_atombios_init(struct radeon_device *rdev)
 	atom_card_info->pll_write = cail_pll_write;
 
 	rdev->mode_info.atom_context = atom_parse(atom_card_info, rdev->bios);
-	mutex_init(&rdev->mode_info.atom_context->mutex);
+	spin_lock_init(&rdev->mode_info.atom_context->spinlock);
 	radeon_atom_initialize_bios_scratch_regs(rdev->ddev);
 	atom_allocate_fb_scratch(rdev->mode_info.atom_context);
 	return 0;
Signature · 10 lines
1.6.5.2


------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
--
#1 lore raw

PATCH 2/4 radeon: perform memory reclocking in atomic context

This is fast enough and rare enough that it's worth making sure that it happens in the vblank, which means doing it in irq context. The alternative is visual corruption and potential machine crashes.

---
 drivers/gpu/drm/radeon/r100.c            |   26 +++++++++++++++++++++-----
 drivers/gpu/drm/radeon/r600.c            |   24 ++++++++++++++++++++----
 drivers/gpu/drm/radeon/radeon.h          |    1 +
 drivers/gpu/drm/radeon/radeon_atombios.c |    2 +-
 drivers/gpu/drm/radeon/rs600.c           |   14 ++++++++++++++
 5 files changed, 57 insertions(+), 10 deletions(-)
drivers/gpu/drm/radeon/r100.c +21 -5
index 9a7d16b..08e22fe 100644
@@ -197,11 +197,13 @@ void r100_set_power_state(struct radeon_device *rdev)
 
 		/* set memory clock */
 		if (rdev->asic->set_memory_clock && (mclk != rdev->pm.current_mclk)) {
-			radeon_sync_with_vblank(rdev);
-			radeon_pm_debug_check_in_vbl(rdev, false);
-			radeon_set_memory_clock(rdev, mclk);
-			radeon_pm_debug_check_in_vbl(rdev, true);
-			rdev->pm.current_mclk = mclk;
+                        if (!rdev->pm.active_crtcs) {
+                                radeon_set_memory_clock(rdev, mclk);
+                                rdev->pm.current_mclk = mclk;
+                        } else {
+                                rdev->pm.new_mclk = mclk;
+                        }
+                        radeon_sync_with_vblank(rdev);
 			DRM_INFO("Setting: m: %d\n", mclk);
 		}
 
@@ -485,11 +487,25 @@ int r100_irq_process(struct radeon_device *rdev)
 		if (status & RADEON_CRTC_VBLANK_STAT) {
 			drm_handle_vblank(rdev->ddev, 0);
 			rdev->pm.vblank_sync = true;
+			if (rdev->pm.new_mclk) {
+				radeon_pm_debug_check_in_vbl(rdev, false);
+				radeon_set_memory_clock(rdev, rdev->pm.new_mclk);
+				radeon_pm_debug_check_in_vbl(rdev, true);
+				rdev->pm.current_mclk = rdev->pm.new_mclk;
+				rdev->pm.new_mclk = 0;
+			}
 			wake_up(&rdev->irq.vblank_queue);
 		}
 		if (status & RADEON_CRTC2_VBLANK_STAT) {
 			drm_handle_vblank(rdev->ddev, 1);
 			rdev->pm.vblank_sync = true;
+			if (rdev->pm.new_mclk) {
+				radeon_pm_debug_check_in_vbl(rdev, false);
+				radeon_set_memory_clock(rdev, rdev->pm.new_mclk);
+				radeon_pm_debug_check_in_vbl(rdev, true);
+				rdev->pm.current_mclk = rdev->pm.new_mclk;
+				rdev->pm.new_mclk = 0;
+			}
 			wake_up(&rdev->irq.vblank_queue);
 		}
 		if (status & RADEON_FP_DETECT_STAT) {
drivers/gpu/drm/radeon/r600.c +20 -4
index adc558b..a89821b 100644
@@ -299,11 +299,13 @@ void r600_set_power_state(struct radeon_device *rdev)
 
 		/* set memory clock */
 		if (rdev->asic->set_memory_clock && (mclk != rdev->pm.current_mclk)) {
+			if (!rdev->pm.active_crtcs) {
+				radeon_set_memory_clock(rdev, mclk);
+				rdev->pm.current_mclk = mclk;
+			} else {
+				rdev->pm.new_mclk = mclk;
+			}
 			radeon_sync_with_vblank(rdev);
-			radeon_pm_debug_check_in_vbl(rdev, false);
-			radeon_set_memory_clock(rdev, mclk);
-			radeon_pm_debug_check_in_vbl(rdev, true);
-			rdev->pm.current_mclk = mclk;
 			DRM_INFO("Setting: m: %d\n", mclk);
 		}
 
@@ -3020,6 +3022,13 @@ restart_ih:
 				if (disp_int & LB_D1_VBLANK_INTERRUPT) {
 					drm_handle_vblank(rdev->ddev, 0);
 					rdev->pm.vblank_sync = true;
+					if (rdev->pm.new_mclk) {
+						radeon_pm_debug_check_in_vbl(rdev, false);
+						radeon_set_memory_clock(rdev, rdev->pm.new_mclk);
+						radeon_pm_debug_check_in_vbl(rdev, true);
+						rdev->pm.current_mclk = rdev->pm.new_mclk;
+						rdev->pm.new_mclk = 0;
+					}
 					wake_up(&rdev->irq.vblank_queue);
 					disp_int &= ~LB_D1_VBLANK_INTERRUPT;
 					DRM_DEBUG("IH: D1 vblank\n");
@@ -3042,6 +3051,13 @@ restart_ih:
 				if (disp_int & LB_D2_VBLANK_INTERRUPT) {
 					drm_handle_vblank(rdev->ddev, 1);
 					rdev->pm.vblank_sync = true;
+					if (rdev->pm.new_mclk) {
+						radeon_pm_debug_check_in_vbl(rdev, false);
+						radeon_set_memory_clock(rdev, rdev->pm.new_mclk);
+						radeon_pm_debug_check_in_vbl(rdev, true);
+						rdev->pm.current_mclk = rdev->pm.new_mclk;
+						rdev->pm.new_mclk = 0;
+					}
 					wake_up(&rdev->irq.vblank_queue);
 					disp_int &= ~LB_D2_VBLANK_INTERRUPT;
 					DRM_DEBUG("IH: D2 vblank\n");
drivers/gpu/drm/radeon/radeon.h +1 -0
index e8e2fe3..ac403e4 100644
@@ -727,6 +727,7 @@ struct radeon_pm {
 	int                     default_power_state_index;
 	u32                     current_sclk;
 	u32                     current_mclk;
+	u32			new_mclk;
 	struct radeon_i2c_chan *i2c_bus;
 	/* r6xx+ only */
 	u32 low_simd_mask;
drivers/gpu/drm/radeon/radeon_atombios.c +1 -1
index 00bae31..0af81b7 100644
@@ -1941,7 +1941,7 @@ void radeon_atom_set_memory_clock(struct radeon_device *rdev,
 
 	args.ulTargetMemoryClock = mem_clock;	/* 10 khz */
 
-	atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
+	atom_execute_table_atomic(rdev->mode_info.atom_context, index, (uint32_t *)&args);
 }
 
 void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
drivers/gpu/drm/radeon/rs600.c +14 -0
index 55f00a7..83eda0e 100644
@@ -484,11 +484,25 @@ int rs600_irq_process(struct radeon_device *rdev)
 		if (G_007EDC_LB_D1_VBLANK_INTERRUPT(r500_disp_int)) {
 			drm_handle_vblank(rdev->ddev, 0);
 			rdev->pm.vblank_sync = true;
+                        if (rdev->pm.new_mclk) {
+                                radeon_pm_debug_check_in_vbl(rdev, false);
+                                radeon_set_memory_clock(rdev, rdev->pm.new_mclk);
+                                radeon_pm_debug_check_in_vbl(rdev, true);
+                                rdev->pm.current_mclk = rdev->pm.new_mclk;
+                                rdev->pm.new_mclk = 0;
+                        }
 			wake_up(&rdev->irq.vblank_queue);
 		}
 		if (G_007EDC_LB_D2_VBLANK_INTERRUPT(r500_disp_int)) {
 			drm_handle_vblank(rdev->ddev, 1);
 			rdev->pm.vblank_sync = true;
+                        if (rdev->pm.new_mclk) {
+                                radeon_pm_debug_check_in_vbl(rdev, false);
+                                radeon_set_memory_clock(rdev, rdev->pm.new_mclk);
+                                radeon_pm_debug_check_in_vbl(rdev, true);
+                                rdev->pm.current_mclk = rdev->pm.new_mclk;
+                                rdev->pm.new_mclk = 0;
+                        }
 			wake_up(&rdev->irq.vblank_queue);
 		}
 		if (G_007EDC_DC_HOT_PLUG_DETECT1_INTERRUPT(r500_disp_int)) {
Signature · 10 lines
1.6.5.2


------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
--
#2 lore raw

PATCH 3/4 radeon: Reclock r520 memory by hand

The r520 atom tables sleep for long enough that it's impossible to reclock memory during an interrupt. Implement this by hand instead in order to avoid the delay.

---
 drivers/gpu/drm/radeon/r500_reg.h        |    4 ++-
 drivers/gpu/drm/radeon/r520.c            |   39 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/radeon/radeon.h          |    2 +
 drivers/gpu/drm/radeon/radeon_asic.c     |    2 +-
 drivers/gpu/drm/radeon/radeon_asic.h     |    3 ++
 drivers/gpu/drm/radeon/radeon_atombios.c |   21 ++++++++++++++++
 drivers/gpu/drm/radeon/radeon_cp.c       |    2 +-
 drivers/gpu/drm/radeon/radeon_drv.h      |    1 +
 drivers/gpu/drm/radeon/radeon_pm.c       |    8 ++++-
 9 files changed, 77 insertions(+), 5 deletions(-)
drivers/gpu/drm/radeon/r500_reg.h +3 -1
index 0cf2ad2..b3e798f 100644
@@ -258,7 +258,7 @@
 #define		R520_MC_AGP_TOP_SHIFT		16
 #define R520_MC_AGP_BASE		0x06
 #define R520_MC_AGP_BASE_2		0x07
-
+#define R520_MC_ARB_RATIO_CLK_SEQ	0x16
 
 #define AVIVO_MC_INDEX						0x0070
 #define R520_MC_STATUS 0x00
@@ -279,6 +279,8 @@
 #	define R520_MEM_NUM_CHANNELS_SHIFT  24
 #	define R520_MC_CHANNEL_SIZE  (1 << 23)
 
+#define AVIVO_SPLL_FUNC_CNTL			       0x0000 /* PLL */
+#define AVIVO_MPLL_FUNC_CNTL			       0x0004 /* PLL */
 #define AVIVO_CP_DYN_CNTL                              0x000f /* PLL */
 #       define AVIVO_CP_FORCEON                        (1 << 0)
 #define AVIVO_E2_DYN_CNTL                              0x0011 /* PLL */
drivers/gpu/drm/radeon/r520.c +39 -0
index 870111e..fda7c11 100644
@@ -26,6 +26,8 @@
  *          Jerome Glisse
  */
 #include "drmP.h"
+#include "radeon_drm.h"
+#include "radeon_drv.h"
 #include "radeon.h"
 #include "radeon_asic.h"
 #include "atom.h"
@@ -127,6 +129,8 @@ void r520_mc_init(struct radeon_device *rdev)
 	radeon_vram_location(rdev, &rdev->mc, 0);
 	if (!(rdev->flags & RADEON_IS_AGP))
 		radeon_gtt_location(rdev, &rdev->mc);
+	rdev->clock.fbdiv =
+		(RADEON_READ_PLL(rdev->ddev, AVIVO_MPLL_FUNC_CNTL) & 0x1fe0) >> 5;
 	radeon_update_bandwidth_info(rdev);
 }
 
@@ -303,3 +307,38 @@ int r520_init(struct radeon_device *rdev)
 	}
 	return 0;
 }
+
+void r520_set_memory_clock(struct radeon_device *rdev, uint32_t mem_clock)
+{
+	int mpll, spll, hclk, sclk, fbdiv, index, factor;
+	struct drm_radeon_private *dev_priv = rdev->ddev->dev_private;
+
+	mpll = RADEON_READ_PLL(rdev->ddev, AVIVO_MPLL_FUNC_CNTL);
+	fbdiv = (mpll & 0x1fe0) >> 5;
+
+	/* Set new fbdiv */
+	factor = rdev->clock.default_mclk / mem_clock;
+	fbdiv = rdev->clock.fbdiv / factor;
+
+	mpll &= ~0x1fe0;
+	mpll |= ((fbdiv << 5) | (1 << 24));
+	mpll &= ~(1 << 25);
+
+	spll = RADEON_READ_PLL(rdev->ddev, AVIVO_SPLL_FUNC_CNTL);
+
+	hclk = fbdiv << 5;
+	hclk += 0x20;
+	hclk *= 8;
+
+	sclk = spll * 0x1fe0;
+	sclk += 0x20;
+	sclk *= 6;
+	sclk = sclk >> 5;
+
+	index = hclk/sclk;
+
+	R500_WRITE_MCIND(R520_MC_ARB_RATIO_CLK_SEQ,
+			 rdev->pm.mc_arb_init_values[index]);
+	RADEON_WRITE_PLL(AVIVO_MPLL_FUNC_CNTL, mpll);
+	radeon_atom_initialize_memory_controller(rdev);
+}
drivers/gpu/drm/radeon/radeon.h +2 -0
index ac403e4..d706974 100644
@@ -163,6 +163,7 @@ struct radeon_clock {
 	uint32_t default_sclk;
 	uint32_t default_dispclk;
 	uint32_t dp_extclk;
+	uint32_t fbdiv;
 };
 
 /*
@@ -728,6 +729,7 @@ struct radeon_pm {
 	u32                     current_sclk;
 	u32                     current_mclk;
 	u32			new_mclk;
+	u32			*mc_arb_init_values;
 	struct radeon_i2c_chan *i2c_bus;
 	/* r6xx+ only */
 	u32 low_simd_mask;
drivers/gpu/drm/radeon/radeon_asic.c +1 -1
index 1df1e89..80487e0 100644
@@ -529,7 +529,7 @@ static struct radeon_asic r520_asic = {
 	.get_engine_clock = &radeon_atom_get_engine_clock,
 	.set_engine_clock = &radeon_atom_set_engine_clock,
 	.get_memory_clock = &radeon_atom_get_memory_clock,
-	.set_memory_clock = &radeon_atom_set_memory_clock,
+	.set_memory_clock = &r520_set_memory_clock,
 	.get_pcie_lanes = &rv370_get_pcie_lanes,
 	.set_pcie_lanes = &rv370_set_pcie_lanes,
 	.set_clock_gating = &radeon_atom_set_clock_gating,
drivers/gpu/drm/radeon/radeon_asic.h +3 -0
index 7de4947..51ddb60 100644
@@ -36,10 +36,12 @@ void radeon_legacy_set_engine_clock(struct radeon_device *rdev, uint32_t eng_clo
 uint32_t radeon_legacy_get_memory_clock(struct radeon_device *rdev);
 void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
 
+void radeon_atom_get_mc_arb_info(struct radeon_device *rdev);
 uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev);
 void radeon_atom_set_engine_clock(struct radeon_device *rdev, uint32_t eng_clock);
 uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev);
 void radeon_atom_set_memory_clock(struct radeon_device *rdev, uint32_t mem_clock);
+void radeon_atom_initialize_memory_controller(struct radeon_device *rdev);
 void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
 
 /*
@@ -232,6 +234,7 @@ int rv515_suspend(struct radeon_device *rdev);
  */
 int r520_init(struct radeon_device *rdev);
 int r520_resume(struct radeon_device *rdev);
+void r520_set_memory_clock(struct radeon_device *rdev, uint32_t mem_clock);
 
 /*
  * r600,rv610,rv630,rv620,rv635,rv670,rs780,rs880
drivers/gpu/drm/radeon/radeon_atombios.c +21 -0
index 0af81b7..5b964e2 100644
@@ -1901,6 +1901,19 @@ void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
 	atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
 }
 
+void radeon_atom_get_mc_arb_info(struct radeon_device *rdev)
+{
+	int index = GetIndexIntoMasterTable(DATA, MC_InitParameter);
+	u16 size, data_offset;
+	struct atom_context *ctx = rdev->mode_info.atom_context;
+
+	if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
+		rdev->pm.mc_arb_init_values = kmalloc(size*sizeof(u32), GFP_KERNEL);
+		memcpy(rdev->pm.mc_arb_init_values, ctx->bios + data_offset,
+		       size * sizeof(u32));
+	}
+}
+
 uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
 {
 	GET_ENGINE_CLOCK_PS_ALLOCATION args;
@@ -1944,6 +1957,14 @@ void radeon_atom_set_memory_clock(struct radeon_device *rdev,
 	atom_execute_table_atomic(rdev->mode_info.atom_context, index, (uint32_t *)&args);
 }
 
+void radeon_atom_initialize_memory_controller(struct radeon_device *rdev)
+{
+	int index = GetIndexIntoMasterTable(COMMAND, MemoryDeviceInit);
+	MEMORY_PLLINIT_PS_ALLOCATION args;
+
+	atom_execute_table_atomic(rdev->mode_info.atom_context, index, (uint32_t *)&args);
+}
+
 void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
 {
 	struct radeon_device *rdev = dev->dev_private;
drivers/gpu/drm/radeon/radeon_cp.c +1 -1
index dc6eba6..d22e832 100644
@@ -292,7 +292,7 @@ void radeon_enable_bm(struct drm_radeon_private *dev_priv)
 	} /* PCIE cards appears to not need this */
 }
 
-static int RADEON_READ_PLL(struct drm_device * dev, int addr)
+int RADEON_READ_PLL(struct drm_device *dev, int addr)
 {
 	drm_radeon_private_t *dev_priv = dev->dev_private;
 
drivers/gpu/drm/radeon/radeon_drv.h +1 -0
index ec55f2b..43fd3b9 100644
@@ -1859,6 +1859,7 @@ do {									\
 #define RADEON_READ8(reg)	DRM_READ8(  dev_priv->mmio, (reg) )
 #define RADEON_WRITE8(reg,val)	DRM_WRITE8( dev_priv->mmio, (reg), (val) )
 
+int RADEON_READ_PLL(struct drm_device *dev, int addr);
 #define RADEON_WRITE_PLL(addr, val)					\
 do {									\
 	RADEON_WRITE8(RADEON_CLOCK_CNTL_INDEX,				\
drivers/gpu/drm/radeon/radeon_pm.c +6 -2
index 3f4beef..745475f 100644
@@ -23,6 +23,7 @@
 #include "drmP.h"
 #include "radeon.h"
 #include "avivod.h"
+#include "radeon_asic.h"
 
 #define RADEON_IDLE_LOOP_MS 100
 #define RADEON_RECLOCK_DELAY_MS 200
@@ -100,10 +101,12 @@ int radeon_pm_init(struct radeon_device *rdev)
 	rdev->pm.can_downclock = true;
 
 	if (rdev->bios) {
-		if (rdev->is_atom_bios)
+		if (rdev->is_atom_bios) {
 			radeon_atombios_get_power_modes(rdev);
-		else
+			radeon_atom_get_mc_arb_info(rdev);
+		} else {
 			radeon_combios_get_power_modes(rdev);
+		}
 		radeon_print_power_mode_info(rdev);
 	}
 
@@ -131,6 +134,7 @@ void radeon_pm_fini(struct radeon_device *rdev)
 		/* reset default clocks */
 		rdev->pm.state = PM_STATE_DISABLED;
 		rdev->pm.planned_action = PM_ACTION_DEFAULT;
+		kfree(rdev->pm.mc_arb_init_values);
 		radeon_pm_set_clocks(rdev);
 	}
 
Signature · 10 lines
1.6.5.2


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
--
#3 lore raw

PATCH 4/4 radeon: Run engine reclocking during vblank

Reclocking the engine during screen refresh can cause corruption on some hardware. Do it during vblank instead, and make sure that we're really in vblank.

---
 drivers/gpu/drm/radeon/r100.c            |   54 +++++++++++++++++++++--------
 drivers/gpu/drm/radeon/r600.c            |   54 ++++++++++++++++++++++--------
 drivers/gpu/drm/radeon/radeon.h          |    1 +
 drivers/gpu/drm/radeon/radeon_atombios.c |    2 +-
 4 files changed, 81 insertions(+), 30 deletions(-)
drivers/gpu/drm/radeon/r100.c +39 -15
index 08e22fe..cdd55b2 100644
@@ -189,11 +189,14 @@ void r100_set_power_state(struct radeon_device *rdev)
 		/* reclocking the engine appears to be ok as long as the engine is idle
 		 * no need for vblank waiting
 		 */
-		if (sclk != rdev->pm.current_sclk) {
-			radeon_set_engine_clock(rdev, sclk);
-			rdev->pm.current_sclk = sclk;
-			DRM_INFO("Setting: e: %d\n", sclk);
-		}
+                if (sclk != rdev->pm.current_sclk) {
+                        if (!rdev->pm.active_crtcs) {
+                                radeon_set_engine_clock(rdev, sclk);
+                                rdev->pm.current_sclk = sclk;
+                        } else {
+                                rdev->pm.new_mclk = sclk;
+                        }
+                }
 
 		/* set memory clock */
 		if (rdev->asic->set_memory_clock && (mclk != rdev->pm.current_mclk)) {
@@ -461,6 +464,7 @@ int r100_irq_process(struct radeon_device *rdev)
 {
 	uint32_t status, msi_rearm;
 	bool queue_hotplug = false;
+	int i = 0;
 
 	/* reset gui idle ack.  the status bit is broken */
 	rdev->irq.gui_idle_acked = false;
@@ -487,24 +491,44 @@ int r100_irq_process(struct radeon_device *rdev)
 		if (status & RADEON_CRTC_VBLANK_STAT) {
 			drm_handle_vblank(rdev->ddev, 0);
 			rdev->pm.vblank_sync = true;
-			if (rdev->pm.new_mclk) {
-				radeon_pm_debug_check_in_vbl(rdev, false);
-				radeon_set_memory_clock(rdev, rdev->pm.new_mclk);
+			if (rdev->pm.new_mclk || rdev->pm.new_sclk) {
+				while (!radeon_pm_debug_check_in_vbl(rdev, false) && i <100) {
+					udelay(1);
+					i++;
+				}
+				if (i==100) {
+					dev_err(rdev->dev, "Failed to sync with vblank\n");
+				} else if (rdev->pm.new_mclk) {
+					radeon_set_memory_clock(rdev, rdev->pm.new_mclk);
+					rdev->pm.current_mclk = rdev->pm.new_mclk;
+				} else if (rdev->pm.new_sclk) {
+					radeon_set_engine_clock(rdev, rdev->pm.new_sclk);
+					rdev->pm.current_sclk = rdev->pm.new_sclk;
+				}
 				radeon_pm_debug_check_in_vbl(rdev, true);
-				rdev->pm.current_mclk = rdev->pm.new_mclk;
-				rdev->pm.new_mclk = 0;
+				rdev->pm.new_mclk = rdev->pm.new_sclk = 0;
 			}
 			wake_up(&rdev->irq.vblank_queue);
 		}
 		if (status & RADEON_CRTC2_VBLANK_STAT) {
 			drm_handle_vblank(rdev->ddev, 1);
 			rdev->pm.vblank_sync = true;
-			if (rdev->pm.new_mclk) {
-				radeon_pm_debug_check_in_vbl(rdev, false);
-				radeon_set_memory_clock(rdev, rdev->pm.new_mclk);
+			if (rdev->pm.new_mclk || rdev->pm.new_sclk) {
+				while (!radeon_pm_debug_check_in_vbl(rdev, false) && i <100) {
+					udelay(1);
+					i++;
+				}
+				if (i==100) {
+					dev_err(rdev->dev, "Failed to sync with vblank\n");
+				} else if (rdev->pm.new_mclk) {
+					radeon_set_memory_clock(rdev, rdev->pm.new_mclk);
+					rdev->pm.current_mclk = rdev->pm.new_mclk;
+				} else if (rdev->pm.new_sclk) {
+					radeon_set_engine_clock(rdev, rdev->pm.new_sclk);
+					rdev->pm.current_sclk = rdev->pm.new_sclk;
+				}
 				radeon_pm_debug_check_in_vbl(rdev, true);
-				rdev->pm.current_mclk = rdev->pm.new_mclk;
-				rdev->pm.new_mclk = 0;
+				rdev->pm.new_mclk = rdev->pm.new_sclk = 0;
 			}
 			wake_up(&rdev->irq.vblank_queue);
 		}
drivers/gpu/drm/radeon/r600.c +40 -14

89 lines not on this page · raw message

drivers/gpu/drm/radeon/radeon.h +1 -0
index d706974..e3e4afc 100644
@@ -729,6 +729,7 @@ struct radeon_pm {
 	u32                     current_sclk;
 	u32                     current_mclk;
 	u32			new_mclk;
+	u32			new_sclk;
 	u32			*mc_arb_init_values;
 	struct radeon_i2c_chan *i2c_bus;
 	/* r6xx+ only */
drivers/gpu/drm/radeon/radeon_atombios.c +1 -1
index 5b964e2..e68c320 100644
@@ -1940,7 +1940,7 @@ void radeon_atom_set_engine_clock(struct radeon_device *rdev,
 
 	args.ulTargetEngineClock = eng_clock;	/* 10 khz */
 
-	atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
+	atom_execute_table_atomic(rdev->mode_info.atom_context, index, (uint32_t *)&args);
 }
 
 void radeon_atom_set_memory_clock(struct radeon_device *rdev,
Signature · 10 lines
1.6.5.2


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
--