Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 3 | * copy of this software and associated documentation files (the "Software"), |
| 4 | * to deal in the Software without restriction, including without limitation |
| 5 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 6 | * and/or sell copies of the Software, and to permit persons to whom the |
| 7 | * Software is furnished to do so, subject to the following conditions: |
| 8 | * |
| 9 | * The above copyright notice and this permission notice shall be included in |
| 10 | * all copies or substantial portions of the Software. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 15 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 16 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 17 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 18 | * OTHER DEALINGS IN THE SOFTWARE. |
| 19 | * |
| 20 | * Authors: Rafał Miłecki <zajec5@gmail.com> |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 21 | * Alex Deucher <alexdeucher@gmail.com> |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 22 | */ |
| 23 | #include "drmP.h" |
| 24 | #include "radeon.h" |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 25 | #include "avivod.h" |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 26 | #ifdef CONFIG_ACPI |
| 27 | #include <linux/acpi.h> |
| 28 | #endif |
| 29 | #include <linux/power_supply.h> |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 30 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 31 | #define RADEON_IDLE_LOOP_MS 100 |
| 32 | #define RADEON_RECLOCK_DELAY_MS 200 |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 33 | #define RADEON_WAIT_VBLANK_TIMEOUT 200 |
Alex Deucher | 2031f77 | 2010-04-22 12:52:11 -0400 | [diff] [blame] | 34 | #define RADEON_WAIT_IDLE_TIMEOUT 200 |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 35 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 36 | static void radeon_dynpm_idle_work_handler(struct work_struct *work); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 37 | static int radeon_debugfs_pm_init(struct radeon_device *rdev); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 38 | static bool radeon_pm_in_vbl(struct radeon_device *rdev); |
| 39 | static bool radeon_pm_debug_check_in_vbl(struct radeon_device *rdev, bool finish); |
| 40 | static void radeon_pm_update_profile(struct radeon_device *rdev); |
| 41 | static void radeon_pm_set_clocks(struct radeon_device *rdev); |
| 42 | |
| 43 | #define ACPI_AC_CLASS "ac_adapter" |
| 44 | |
| 45 | #ifdef CONFIG_ACPI |
| 46 | static int radeon_acpi_event(struct notifier_block *nb, |
| 47 | unsigned long val, |
| 48 | void *data) |
| 49 | { |
| 50 | struct radeon_device *rdev = container_of(nb, struct radeon_device, acpi_nb); |
| 51 | struct acpi_bus_event *entry = (struct acpi_bus_event *)data; |
| 52 | |
| 53 | if (strcmp(entry->device_class, ACPI_AC_CLASS) == 0) { |
| 54 | if (power_supply_is_system_supplied() > 0) |
Alex Deucher | ce8a3eb | 2010-05-07 16:58:27 -0400 | [diff] [blame] | 55 | DRM_DEBUG("pm: AC\n"); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 56 | else |
Alex Deucher | ce8a3eb | 2010-05-07 16:58:27 -0400 | [diff] [blame] | 57 | DRM_DEBUG("pm: DC\n"); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 58 | |
| 59 | if (rdev->pm.pm_method == PM_METHOD_PROFILE) { |
| 60 | if (rdev->pm.profile == PM_PROFILE_AUTO) { |
| 61 | mutex_lock(&rdev->pm.mutex); |
| 62 | radeon_pm_update_profile(rdev); |
| 63 | radeon_pm_set_clocks(rdev); |
| 64 | mutex_unlock(&rdev->pm.mutex); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | return NOTIFY_OK; |
| 70 | } |
| 71 | #endif |
| 72 | |
| 73 | static void radeon_pm_update_profile(struct radeon_device *rdev) |
| 74 | { |
| 75 | switch (rdev->pm.profile) { |
| 76 | case PM_PROFILE_DEFAULT: |
| 77 | rdev->pm.profile_index = PM_PROFILE_DEFAULT_IDX; |
| 78 | break; |
| 79 | case PM_PROFILE_AUTO: |
| 80 | if (power_supply_is_system_supplied() > 0) { |
| 81 | if (rdev->pm.active_crtc_count > 1) |
| 82 | rdev->pm.profile_index = PM_PROFILE_HIGH_MH_IDX; |
| 83 | else |
| 84 | rdev->pm.profile_index = PM_PROFILE_HIGH_SH_IDX; |
| 85 | } else { |
| 86 | if (rdev->pm.active_crtc_count > 1) |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame^] | 87 | rdev->pm.profile_index = PM_PROFILE_MID_MH_IDX; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 88 | else |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame^] | 89 | rdev->pm.profile_index = PM_PROFILE_MID_SH_IDX; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 90 | } |
| 91 | break; |
| 92 | case PM_PROFILE_LOW: |
| 93 | if (rdev->pm.active_crtc_count > 1) |
| 94 | rdev->pm.profile_index = PM_PROFILE_LOW_MH_IDX; |
| 95 | else |
| 96 | rdev->pm.profile_index = PM_PROFILE_LOW_SH_IDX; |
| 97 | break; |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame^] | 98 | case PM_PROFILE_MID: |
| 99 | if (rdev->pm.active_crtc_count > 1) |
| 100 | rdev->pm.profile_index = PM_PROFILE_MID_MH_IDX; |
| 101 | else |
| 102 | rdev->pm.profile_index = PM_PROFILE_MID_SH_IDX; |
| 103 | break; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 104 | case PM_PROFILE_HIGH: |
| 105 | if (rdev->pm.active_crtc_count > 1) |
| 106 | rdev->pm.profile_index = PM_PROFILE_HIGH_MH_IDX; |
| 107 | else |
| 108 | rdev->pm.profile_index = PM_PROFILE_HIGH_SH_IDX; |
| 109 | break; |
| 110 | } |
| 111 | |
| 112 | if (rdev->pm.active_crtc_count == 0) { |
| 113 | rdev->pm.requested_power_state_index = |
| 114 | rdev->pm.profiles[rdev->pm.profile_index].dpms_off_ps_idx; |
| 115 | rdev->pm.requested_clock_mode_index = |
| 116 | rdev->pm.profiles[rdev->pm.profile_index].dpms_off_cm_idx; |
| 117 | } else { |
| 118 | rdev->pm.requested_power_state_index = |
| 119 | rdev->pm.profiles[rdev->pm.profile_index].dpms_on_ps_idx; |
| 120 | rdev->pm.requested_clock_mode_index = |
| 121 | rdev->pm.profiles[rdev->pm.profile_index].dpms_on_cm_idx; |
| 122 | } |
| 123 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 124 | |
Matthew Garrett | 5876dd2 | 2010-04-26 15:52:20 -0400 | [diff] [blame] | 125 | static void radeon_unmap_vram_bos(struct radeon_device *rdev) |
| 126 | { |
| 127 | struct radeon_bo *bo, *n; |
| 128 | |
| 129 | if (list_empty(&rdev->gem.objects)) |
| 130 | return; |
| 131 | |
| 132 | list_for_each_entry_safe(bo, n, &rdev->gem.objects, list) { |
| 133 | if (bo->tbo.mem.mem_type == TTM_PL_VRAM) |
| 134 | ttm_bo_unmap_virtual(&bo->tbo); |
| 135 | } |
Matthew Garrett | 5876dd2 | 2010-04-26 15:52:20 -0400 | [diff] [blame] | 136 | } |
| 137 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 138 | static void radeon_sync_with_vblank(struct radeon_device *rdev) |
| 139 | { |
| 140 | if (rdev->pm.active_crtcs) { |
| 141 | rdev->pm.vblank_sync = false; |
| 142 | wait_event_timeout( |
| 143 | rdev->irq.vblank_queue, rdev->pm.vblank_sync, |
| 144 | msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT)); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | static void radeon_set_power_state(struct radeon_device *rdev) |
| 149 | { |
| 150 | u32 sclk, mclk; |
Alex Deucher | 9264587 | 2010-05-27 17:01:41 -0400 | [diff] [blame] | 151 | bool misc_after = false; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 152 | |
| 153 | if ((rdev->pm.requested_clock_mode_index == rdev->pm.current_clock_mode_index) && |
| 154 | (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index)) |
| 155 | return; |
| 156 | |
| 157 | if (radeon_gui_idle(rdev)) { |
| 158 | sclk = rdev->pm.power_state[rdev->pm.requested_power_state_index]. |
| 159 | clock_info[rdev->pm.requested_clock_mode_index].sclk; |
| 160 | if (sclk > rdev->clock.default_sclk) |
| 161 | sclk = rdev->clock.default_sclk; |
| 162 | |
| 163 | mclk = rdev->pm.power_state[rdev->pm.requested_power_state_index]. |
| 164 | clock_info[rdev->pm.requested_clock_mode_index].mclk; |
| 165 | if (mclk > rdev->clock.default_mclk) |
| 166 | mclk = rdev->clock.default_mclk; |
| 167 | |
Alex Deucher | 9264587 | 2010-05-27 17:01:41 -0400 | [diff] [blame] | 168 | /* upvolt before raising clocks, downvolt after lowering clocks */ |
| 169 | if (sclk < rdev->pm.current_sclk) |
| 170 | misc_after = true; |
| 171 | |
| 172 | radeon_sync_with_vblank(rdev); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 173 | |
| 174 | if (rdev->pm.pm_method == PM_METHOD_DYNPM) { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 175 | if (!radeon_pm_in_vbl(rdev)) |
| 176 | return; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 177 | } |
| 178 | |
Alex Deucher | 9264587 | 2010-05-27 17:01:41 -0400 | [diff] [blame] | 179 | radeon_pm_prepare(rdev); |
| 180 | |
| 181 | if (!misc_after) |
| 182 | /* voltage, pcie lanes, etc.*/ |
| 183 | radeon_pm_misc(rdev); |
| 184 | |
| 185 | /* set engine clock */ |
| 186 | if (sclk != rdev->pm.current_sclk) { |
| 187 | radeon_pm_debug_check_in_vbl(rdev, false); |
| 188 | radeon_set_engine_clock(rdev, sclk); |
| 189 | radeon_pm_debug_check_in_vbl(rdev, true); |
| 190 | rdev->pm.current_sclk = sclk; |
| 191 | DRM_DEBUG("Setting: e: %d\n", sclk); |
| 192 | } |
| 193 | |
| 194 | /* set memory clock */ |
| 195 | if (rdev->asic->set_memory_clock && (mclk != rdev->pm.current_mclk)) { |
| 196 | radeon_pm_debug_check_in_vbl(rdev, false); |
| 197 | radeon_set_memory_clock(rdev, mclk); |
| 198 | radeon_pm_debug_check_in_vbl(rdev, true); |
| 199 | rdev->pm.current_mclk = mclk; |
| 200 | DRM_DEBUG("Setting: m: %d\n", mclk); |
| 201 | } |
| 202 | |
| 203 | if (misc_after) |
| 204 | /* voltage, pcie lanes, etc.*/ |
| 205 | radeon_pm_misc(rdev); |
| 206 | |
| 207 | radeon_pm_finish(rdev); |
| 208 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 209 | rdev->pm.current_power_state_index = rdev->pm.requested_power_state_index; |
| 210 | rdev->pm.current_clock_mode_index = rdev->pm.requested_clock_mode_index; |
| 211 | } else |
Alex Deucher | ce8a3eb | 2010-05-07 16:58:27 -0400 | [diff] [blame] | 212 | DRM_DEBUG("pm: GUI not idle!!!\n"); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static void radeon_pm_set_clocks(struct radeon_device *rdev) |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 216 | { |
Matthew Garrett | 2aba631c0 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 217 | int i; |
| 218 | |
Matthew Garrett | 612e06c | 2010-04-27 17:16:58 -0400 | [diff] [blame] | 219 | mutex_lock(&rdev->ddev->struct_mutex); |
| 220 | mutex_lock(&rdev->vram_mutex); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 221 | mutex_lock(&rdev->cp.mutex); |
Alex Deucher | 4f3218c | 2010-04-29 16:14:02 -0400 | [diff] [blame] | 222 | |
| 223 | /* gui idle int has issues on older chips it seems */ |
| 224 | if (rdev->family >= CHIP_R600) { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 225 | if (rdev->irq.installed) { |
| 226 | /* wait for GPU idle */ |
| 227 | rdev->pm.gui_idle = false; |
| 228 | rdev->irq.gui_idle = true; |
| 229 | radeon_irq_set(rdev); |
| 230 | wait_event_interruptible_timeout( |
| 231 | rdev->irq.idle_queue, rdev->pm.gui_idle, |
| 232 | msecs_to_jiffies(RADEON_WAIT_IDLE_TIMEOUT)); |
| 233 | rdev->irq.gui_idle = false; |
| 234 | radeon_irq_set(rdev); |
| 235 | } |
Matthew Garrett | 01434b4 | 2010-04-30 15:48:23 -0400 | [diff] [blame] | 236 | } else { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 237 | if (rdev->cp.ready) { |
| 238 | struct radeon_fence *fence; |
| 239 | radeon_ring_alloc(rdev, 64); |
| 240 | radeon_fence_create(rdev, &fence); |
| 241 | radeon_fence_emit(rdev, fence); |
| 242 | radeon_ring_commit(rdev); |
| 243 | radeon_fence_wait(fence, false); |
| 244 | radeon_fence_unref(&fence); |
| 245 | } |
Alex Deucher | 4f3218c | 2010-04-29 16:14:02 -0400 | [diff] [blame] | 246 | } |
Matthew Garrett | 5876dd2 | 2010-04-26 15:52:20 -0400 | [diff] [blame] | 247 | radeon_unmap_vram_bos(rdev); |
| 248 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 249 | if (rdev->irq.installed) { |
Matthew Garrett | 2aba631c0 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 250 | for (i = 0; i < rdev->num_crtc; i++) { |
| 251 | if (rdev->pm.active_crtcs & (1 << i)) { |
| 252 | rdev->pm.req_vblank |= (1 << i); |
| 253 | drm_vblank_get(rdev->ddev, i); |
| 254 | } |
| 255 | } |
| 256 | } |
Alex Deucher | 539d241 | 2010-04-29 00:22:43 -0400 | [diff] [blame] | 257 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 258 | radeon_set_power_state(rdev); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 259 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 260 | if (rdev->irq.installed) { |
Matthew Garrett | 2aba631c0 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 261 | for (i = 0; i < rdev->num_crtc; i++) { |
| 262 | if (rdev->pm.req_vblank & (1 << i)) { |
| 263 | rdev->pm.req_vblank &= ~(1 << i); |
| 264 | drm_vblank_put(rdev->ddev, i); |
| 265 | } |
| 266 | } |
| 267 | } |
Matthew Garrett | 5876dd2 | 2010-04-26 15:52:20 -0400 | [diff] [blame] | 268 | |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 269 | /* update display watermarks based on new power state */ |
| 270 | radeon_update_bandwidth_info(rdev); |
| 271 | if (rdev->pm.active_crtc_count) |
| 272 | radeon_bandwidth_update(rdev); |
| 273 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 274 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
Matthew Garrett | 2aba631c0 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 275 | |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 276 | mutex_unlock(&rdev->cp.mutex); |
Matthew Garrett | 612e06c | 2010-04-27 17:16:58 -0400 | [diff] [blame] | 277 | mutex_unlock(&rdev->vram_mutex); |
| 278 | mutex_unlock(&rdev->ddev->struct_mutex); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 279 | } |
| 280 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 281 | static ssize_t radeon_get_pm_profile(struct device *dev, |
| 282 | struct device_attribute *attr, |
| 283 | char *buf) |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 284 | { |
| 285 | struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); |
| 286 | struct radeon_device *rdev = ddev->dev_private; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 287 | int cp = rdev->pm.profile; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 288 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 289 | return snprintf(buf, PAGE_SIZE, "%s\n", |
| 290 | (cp == PM_PROFILE_AUTO) ? "auto" : |
| 291 | (cp == PM_PROFILE_LOW) ? "low" : |
| 292 | (cp == PM_PROFILE_HIGH) ? "high" : "default"); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 293 | } |
| 294 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 295 | static ssize_t radeon_set_pm_profile(struct device *dev, |
| 296 | struct device_attribute *attr, |
| 297 | const char *buf, |
| 298 | size_t count) |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 299 | { |
| 300 | struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); |
| 301 | struct radeon_device *rdev = ddev->dev_private; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 302 | |
| 303 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 304 | if (rdev->pm.pm_method == PM_METHOD_PROFILE) { |
| 305 | if (strncmp("default", buf, strlen("default")) == 0) |
| 306 | rdev->pm.profile = PM_PROFILE_DEFAULT; |
| 307 | else if (strncmp("auto", buf, strlen("auto")) == 0) |
| 308 | rdev->pm.profile = PM_PROFILE_AUTO; |
| 309 | else if (strncmp("low", buf, strlen("low")) == 0) |
| 310 | rdev->pm.profile = PM_PROFILE_LOW; |
Alex Deucher | c9e75b2 | 2010-06-02 17:56:01 -0400 | [diff] [blame^] | 311 | else if (strncmp("mid", buf, strlen("mid")) == 0) |
| 312 | rdev->pm.profile = PM_PROFILE_MID; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 313 | else if (strncmp("high", buf, strlen("high")) == 0) |
| 314 | rdev->pm.profile = PM_PROFILE_HIGH; |
| 315 | else { |
| 316 | DRM_ERROR("invalid power profile!\n"); |
| 317 | goto fail; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 318 | } |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 319 | radeon_pm_update_profile(rdev); |
| 320 | radeon_pm_set_clocks(rdev); |
| 321 | } |
| 322 | fail: |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 323 | mutex_unlock(&rdev->pm.mutex); |
| 324 | |
| 325 | return count; |
| 326 | } |
| 327 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 328 | static ssize_t radeon_get_pm_method(struct device *dev, |
| 329 | struct device_attribute *attr, |
| 330 | char *buf) |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 331 | { |
| 332 | struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); |
| 333 | struct radeon_device *rdev = ddev->dev_private; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 334 | int pm = rdev->pm.pm_method; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 335 | |
| 336 | return snprintf(buf, PAGE_SIZE, "%s\n", |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 337 | (pm == PM_METHOD_DYNPM) ? "dynpm" : "profile"); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 338 | } |
| 339 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 340 | static ssize_t radeon_set_pm_method(struct device *dev, |
| 341 | struct device_attribute *attr, |
| 342 | const char *buf, |
| 343 | size_t count) |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 344 | { |
| 345 | struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); |
| 346 | struct radeon_device *rdev = ddev->dev_private; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 347 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 348 | |
| 349 | if (strncmp("dynpm", buf, strlen("dynpm")) == 0) { |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 350 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 351 | rdev->pm.pm_method = PM_METHOD_DYNPM; |
| 352 | rdev->pm.dynpm_state = DYNPM_STATE_PAUSED; |
| 353 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_DEFAULT; |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 354 | mutex_unlock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 355 | } else if (strncmp("profile", buf, strlen("profile")) == 0) { |
| 356 | mutex_lock(&rdev->pm.mutex); |
| 357 | rdev->pm.pm_method = PM_METHOD_PROFILE; |
| 358 | /* disable dynpm */ |
| 359 | rdev->pm.dynpm_state = DYNPM_STATE_DISABLED; |
| 360 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
| 361 | cancel_delayed_work(&rdev->pm.dynpm_idle_work); |
| 362 | mutex_unlock(&rdev->pm.mutex); |
| 363 | } else { |
| 364 | DRM_ERROR("invalid power method!\n"); |
| 365 | goto fail; |
| 366 | } |
| 367 | radeon_pm_compute_clocks(rdev); |
| 368 | fail: |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 369 | return count; |
| 370 | } |
| 371 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 372 | static DEVICE_ATTR(power_profile, S_IRUGO | S_IWUSR, radeon_get_pm_profile, radeon_set_pm_profile); |
| 373 | static DEVICE_ATTR(power_method, S_IRUGO | S_IWUSR, radeon_get_pm_method, radeon_set_pm_method); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 374 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 375 | void radeon_pm_suspend(struct radeon_device *rdev) |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 376 | { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 377 | mutex_lock(&rdev->pm.mutex); |
| 378 | cancel_delayed_work(&rdev->pm.dynpm_idle_work); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 379 | mutex_unlock(&rdev->pm.mutex); |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 380 | } |
| 381 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 382 | void radeon_pm_resume(struct radeon_device *rdev) |
Rafał Miłecki | d0d6cb8 | 2010-03-02 22:06:52 +0100 | [diff] [blame] | 383 | { |
Alex Deucher | f8ed8b4 | 2010-06-07 17:49:51 -0400 | [diff] [blame] | 384 | /* asic init will reset the default power state */ |
| 385 | mutex_lock(&rdev->pm.mutex); |
| 386 | rdev->pm.current_power_state_index = rdev->pm.default_power_state_index; |
| 387 | rdev->pm.current_clock_mode_index = 0; |
| 388 | rdev->pm.current_sclk = rdev->clock.default_sclk; |
| 389 | rdev->pm.current_mclk = rdev->clock.default_mclk; |
| 390 | mutex_unlock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 391 | radeon_pm_compute_clocks(rdev); |
Rafał Miłecki | d0d6cb8 | 2010-03-02 22:06:52 +0100 | [diff] [blame] | 392 | } |
| 393 | |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 394 | int radeon_pm_init(struct radeon_device *rdev) |
| 395 | { |
Dave Airlie | 26481fb | 2010-05-18 19:00:14 +1000 | [diff] [blame] | 396 | int ret; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 397 | /* default to profile method */ |
| 398 | rdev->pm.pm_method = PM_METHOD_PROFILE; |
Alex Deucher | f8ed8b4 | 2010-06-07 17:49:51 -0400 | [diff] [blame] | 399 | rdev->pm.profile = PM_PROFILE_DEFAULT; |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 400 | rdev->pm.dynpm_state = DYNPM_STATE_DISABLED; |
| 401 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
| 402 | rdev->pm.dynpm_can_upclock = true; |
| 403 | rdev->pm.dynpm_can_downclock = true; |
Alex Deucher | f8ed8b4 | 2010-06-07 17:49:51 -0400 | [diff] [blame] | 404 | rdev->pm.current_sclk = rdev->clock.default_sclk; |
| 405 | rdev->pm.current_mclk = rdev->clock.default_mclk; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 406 | |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 407 | if (rdev->bios) { |
| 408 | if (rdev->is_atom_bios) |
| 409 | radeon_atombios_get_power_modes(rdev); |
| 410 | else |
| 411 | radeon_combios_get_power_modes(rdev); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 412 | radeon_pm_init_profile(rdev); |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 413 | } |
| 414 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 415 | if (rdev->pm.num_power_states > 1) { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 416 | /* where's the best place to put these? */ |
Dave Airlie | 26481fb | 2010-05-18 19:00:14 +1000 | [diff] [blame] | 417 | ret = device_create_file(rdev->dev, &dev_attr_power_profile); |
| 418 | if (ret) |
| 419 | DRM_ERROR("failed to create device file for power profile\n"); |
| 420 | ret = device_create_file(rdev->dev, &dev_attr_power_method); |
| 421 | if (ret) |
| 422 | DRM_ERROR("failed to create device file for power method\n"); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 423 | |
| 424 | #ifdef CONFIG_ACPI |
| 425 | rdev->acpi_nb.notifier_call = radeon_acpi_event; |
| 426 | register_acpi_notifier(&rdev->acpi_nb); |
| 427 | #endif |
| 428 | INIT_DELAYED_WORK(&rdev->pm.dynpm_idle_work, radeon_dynpm_idle_work_handler); |
| 429 | |
| 430 | if (radeon_debugfs_pm_init(rdev)) { |
| 431 | DRM_ERROR("Failed to register debugfs file for PM!\n"); |
| 432 | } |
| 433 | |
| 434 | DRM_INFO("radeon: power management initialized\n"); |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | return 0; |
| 438 | } |
| 439 | |
Alex Deucher | 29fb52c | 2010-03-11 10:01:17 -0500 | [diff] [blame] | 440 | void radeon_pm_fini(struct radeon_device *rdev) |
| 441 | { |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 442 | if (rdev->pm.num_power_states > 1) { |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 443 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 444 | if (rdev->pm.pm_method == PM_METHOD_PROFILE) { |
| 445 | rdev->pm.profile = PM_PROFILE_DEFAULT; |
| 446 | radeon_pm_update_profile(rdev); |
| 447 | radeon_pm_set_clocks(rdev); |
| 448 | } else if (rdev->pm.pm_method == PM_METHOD_DYNPM) { |
| 449 | /* cancel work */ |
| 450 | cancel_delayed_work_sync(&rdev->pm.dynpm_idle_work); |
| 451 | /* reset default clocks */ |
| 452 | rdev->pm.dynpm_state = DYNPM_STATE_DISABLED; |
| 453 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_DEFAULT; |
| 454 | radeon_pm_set_clocks(rdev); |
| 455 | } |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 456 | mutex_unlock(&rdev->pm.mutex); |
Alex Deucher | 58e21df | 2010-03-22 13:31:08 -0400 | [diff] [blame] | 457 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 458 | device_remove_file(rdev->dev, &dev_attr_power_profile); |
| 459 | device_remove_file(rdev->dev, &dev_attr_power_method); |
| 460 | #ifdef CONFIG_ACPI |
| 461 | unregister_acpi_notifier(&rdev->acpi_nb); |
| 462 | #endif |
| 463 | } |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 464 | |
Alex Deucher | 29fb52c | 2010-03-11 10:01:17 -0500 | [diff] [blame] | 465 | if (rdev->pm.i2c_bus) |
| 466 | radeon_i2c_destroy(rdev->pm.i2c_bus); |
| 467 | } |
| 468 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 469 | void radeon_pm_compute_clocks(struct radeon_device *rdev) |
| 470 | { |
| 471 | struct drm_device *ddev = rdev->ddev; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 472 | struct drm_crtc *crtc; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 473 | struct radeon_crtc *radeon_crtc; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 474 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 475 | if (rdev->pm.num_power_states < 2) |
| 476 | return; |
| 477 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 478 | mutex_lock(&rdev->pm.mutex); |
| 479 | |
| 480 | rdev->pm.active_crtcs = 0; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 481 | rdev->pm.active_crtc_count = 0; |
| 482 | list_for_each_entry(crtc, |
| 483 | &ddev->mode_config.crtc_list, head) { |
| 484 | radeon_crtc = to_radeon_crtc(crtc); |
| 485 | if (radeon_crtc->enabled) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 486 | rdev->pm.active_crtcs |= (1 << radeon_crtc->crtc_id); |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 487 | rdev->pm.active_crtc_count++; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 488 | } |
| 489 | } |
| 490 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 491 | if (rdev->pm.pm_method == PM_METHOD_PROFILE) { |
| 492 | radeon_pm_update_profile(rdev); |
| 493 | radeon_pm_set_clocks(rdev); |
| 494 | } else if (rdev->pm.pm_method == PM_METHOD_DYNPM) { |
| 495 | if (rdev->pm.dynpm_state != DYNPM_STATE_DISABLED) { |
| 496 | if (rdev->pm.active_crtc_count > 1) { |
| 497 | if (rdev->pm.dynpm_state == DYNPM_STATE_ACTIVE) { |
| 498 | cancel_delayed_work(&rdev->pm.dynpm_idle_work); |
Alex Deucher | d731117 | 2010-05-03 01:13:14 -0400 | [diff] [blame] | 499 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 500 | rdev->pm.dynpm_state = DYNPM_STATE_PAUSED; |
| 501 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_DEFAULT; |
| 502 | radeon_pm_get_dynpm_state(rdev); |
| 503 | radeon_pm_set_clocks(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 504 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 505 | DRM_DEBUG("radeon: dynamic power management deactivated\n"); |
| 506 | } |
| 507 | } else if (rdev->pm.active_crtc_count == 1) { |
| 508 | /* TODO: Increase clocks if needed for current mode */ |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 509 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 510 | if (rdev->pm.dynpm_state == DYNPM_STATE_MINIMUM) { |
| 511 | rdev->pm.dynpm_state = DYNPM_STATE_ACTIVE; |
| 512 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_UPCLOCK; |
| 513 | radeon_pm_get_dynpm_state(rdev); |
| 514 | radeon_pm_set_clocks(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 515 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 516 | queue_delayed_work(rdev->wq, &rdev->pm.dynpm_idle_work, |
| 517 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
| 518 | } else if (rdev->pm.dynpm_state == DYNPM_STATE_PAUSED) { |
| 519 | rdev->pm.dynpm_state = DYNPM_STATE_ACTIVE; |
| 520 | queue_delayed_work(rdev->wq, &rdev->pm.dynpm_idle_work, |
| 521 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
| 522 | DRM_DEBUG("radeon: dynamic power management activated\n"); |
| 523 | } |
| 524 | } else { /* count == 0 */ |
| 525 | if (rdev->pm.dynpm_state != DYNPM_STATE_MINIMUM) { |
| 526 | cancel_delayed_work(&rdev->pm.dynpm_idle_work); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 527 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 528 | rdev->pm.dynpm_state = DYNPM_STATE_MINIMUM; |
| 529 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_MINIMUM; |
| 530 | radeon_pm_get_dynpm_state(rdev); |
| 531 | radeon_pm_set_clocks(rdev); |
| 532 | } |
| 533 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 534 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 535 | } |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 536 | |
| 537 | mutex_unlock(&rdev->pm.mutex); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 538 | } |
| 539 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 540 | static bool radeon_pm_in_vbl(struct radeon_device *rdev) |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 541 | { |
Alex Deucher | 539d241 | 2010-04-29 00:22:43 -0400 | [diff] [blame] | 542 | u32 stat_crtc = 0, vbl = 0, position = 0; |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 543 | bool in_vbl = true; |
| 544 | |
Alex Deucher | bae6b562 | 2010-04-22 13:38:05 -0400 | [diff] [blame] | 545 | if (ASIC_IS_DCE4(rdev)) { |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 546 | if (rdev->pm.active_crtcs & (1 << 0)) { |
Alex Deucher | 539d241 | 2010-04-29 00:22:43 -0400 | [diff] [blame] | 547 | vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END + |
| 548 | EVERGREEN_CRTC0_REGISTER_OFFSET) & 0xfff; |
| 549 | position = RREG32(EVERGREEN_CRTC_STATUS_POSITION + |
| 550 | EVERGREEN_CRTC0_REGISTER_OFFSET) & 0xfff; |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 551 | } |
| 552 | if (rdev->pm.active_crtcs & (1 << 1)) { |
Alex Deucher | 539d241 | 2010-04-29 00:22:43 -0400 | [diff] [blame] | 553 | vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END + |
| 554 | EVERGREEN_CRTC1_REGISTER_OFFSET) & 0xfff; |
| 555 | position = RREG32(EVERGREEN_CRTC_STATUS_POSITION + |
| 556 | EVERGREEN_CRTC1_REGISTER_OFFSET) & 0xfff; |
Alex Deucher | bae6b562 | 2010-04-22 13:38:05 -0400 | [diff] [blame] | 557 | } |
| 558 | if (rdev->pm.active_crtcs & (1 << 2)) { |
Alex Deucher | 539d241 | 2010-04-29 00:22:43 -0400 | [diff] [blame] | 559 | vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END + |
| 560 | EVERGREEN_CRTC2_REGISTER_OFFSET) & 0xfff; |
| 561 | position = RREG32(EVERGREEN_CRTC_STATUS_POSITION + |
| 562 | EVERGREEN_CRTC2_REGISTER_OFFSET) & 0xfff; |
Alex Deucher | bae6b562 | 2010-04-22 13:38:05 -0400 | [diff] [blame] | 563 | } |
| 564 | if (rdev->pm.active_crtcs & (1 << 3)) { |
Alex Deucher | 539d241 | 2010-04-29 00:22:43 -0400 | [diff] [blame] | 565 | vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END + |
| 566 | EVERGREEN_CRTC3_REGISTER_OFFSET) & 0xfff; |
| 567 | position = RREG32(EVERGREEN_CRTC_STATUS_POSITION + |
| 568 | EVERGREEN_CRTC3_REGISTER_OFFSET) & 0xfff; |
Alex Deucher | bae6b562 | 2010-04-22 13:38:05 -0400 | [diff] [blame] | 569 | } |
| 570 | if (rdev->pm.active_crtcs & (1 << 4)) { |
Alex Deucher | 539d241 | 2010-04-29 00:22:43 -0400 | [diff] [blame] | 571 | vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END + |
| 572 | EVERGREEN_CRTC4_REGISTER_OFFSET) & 0xfff; |
| 573 | position = RREG32(EVERGREEN_CRTC_STATUS_POSITION + |
| 574 | EVERGREEN_CRTC4_REGISTER_OFFSET) & 0xfff; |
Alex Deucher | bae6b562 | 2010-04-22 13:38:05 -0400 | [diff] [blame] | 575 | } |
| 576 | if (rdev->pm.active_crtcs & (1 << 5)) { |
Alex Deucher | 539d241 | 2010-04-29 00:22:43 -0400 | [diff] [blame] | 577 | vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END + |
| 578 | EVERGREEN_CRTC5_REGISTER_OFFSET) & 0xfff; |
| 579 | position = RREG32(EVERGREEN_CRTC_STATUS_POSITION + |
| 580 | EVERGREEN_CRTC5_REGISTER_OFFSET) & 0xfff; |
Alex Deucher | bae6b562 | 2010-04-22 13:38:05 -0400 | [diff] [blame] | 581 | } |
| 582 | } else if (ASIC_IS_AVIVO(rdev)) { |
| 583 | if (rdev->pm.active_crtcs & (1 << 0)) { |
Alex Deucher | 539d241 | 2010-04-29 00:22:43 -0400 | [diff] [blame] | 584 | vbl = RREG32(AVIVO_D1CRTC_V_BLANK_START_END) & 0xfff; |
| 585 | position = RREG32(AVIVO_D1CRTC_STATUS_POSITION) & 0xfff; |
Alex Deucher | bae6b562 | 2010-04-22 13:38:05 -0400 | [diff] [blame] | 586 | } |
| 587 | if (rdev->pm.active_crtcs & (1 << 1)) { |
Alex Deucher | 539d241 | 2010-04-29 00:22:43 -0400 | [diff] [blame] | 588 | vbl = RREG32(AVIVO_D2CRTC_V_BLANK_START_END) & 0xfff; |
| 589 | position = RREG32(AVIVO_D2CRTC_STATUS_POSITION) & 0xfff; |
Alex Deucher | bae6b562 | 2010-04-22 13:38:05 -0400 | [diff] [blame] | 590 | } |
Alex Deucher | 539d241 | 2010-04-29 00:22:43 -0400 | [diff] [blame] | 591 | if (position < vbl && position > 1) |
| 592 | in_vbl = false; |
Alex Deucher | bae6b562 | 2010-04-22 13:38:05 -0400 | [diff] [blame] | 593 | } else { |
| 594 | if (rdev->pm.active_crtcs & (1 << 0)) { |
| 595 | stat_crtc = RREG32(RADEON_CRTC_STATUS); |
| 596 | if (!(stat_crtc & 1)) |
| 597 | in_vbl = false; |
| 598 | } |
| 599 | if (rdev->pm.active_crtcs & (1 << 1)) { |
| 600 | stat_crtc = RREG32(RADEON_CRTC2_STATUS); |
| 601 | if (!(stat_crtc & 1)) |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 602 | in_vbl = false; |
| 603 | } |
| 604 | } |
Matthew Garrett | f81f202 | 2010-04-28 12:13:06 -0400 | [diff] [blame] | 605 | |
Alex Deucher | 539d241 | 2010-04-29 00:22:43 -0400 | [diff] [blame] | 606 | if (position < vbl && position > 1) |
| 607 | in_vbl = false; |
| 608 | |
Matthew Garrett | f81f202 | 2010-04-28 12:13:06 -0400 | [diff] [blame] | 609 | return in_vbl; |
| 610 | } |
| 611 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 612 | static bool radeon_pm_debug_check_in_vbl(struct radeon_device *rdev, bool finish) |
Matthew Garrett | f81f202 | 2010-04-28 12:13:06 -0400 | [diff] [blame] | 613 | { |
| 614 | u32 stat_crtc = 0; |
| 615 | bool in_vbl = radeon_pm_in_vbl(rdev); |
| 616 | |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 617 | if (in_vbl == false) |
Alex Deucher | ce8a3eb | 2010-05-07 16:58:27 -0400 | [diff] [blame] | 618 | DRM_DEBUG("not in vbl for pm change %08x at %s\n", stat_crtc, |
Alex Deucher | bae6b562 | 2010-04-22 13:38:05 -0400 | [diff] [blame] | 619 | finish ? "exit" : "entry"); |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 620 | return in_vbl; |
| 621 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 622 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 623 | static void radeon_dynpm_idle_work_handler(struct work_struct *work) |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 624 | { |
| 625 | struct radeon_device *rdev; |
Matthew Garrett | d9932a3 | 2010-04-26 16:02:26 -0400 | [diff] [blame] | 626 | int resched; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 627 | rdev = container_of(work, struct radeon_device, |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 628 | pm.dynpm_idle_work.work); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 629 | |
Matthew Garrett | d9932a3 | 2010-04-26 16:02:26 -0400 | [diff] [blame] | 630 | resched = ttm_bo_lock_delayed_workqueue(&rdev->mman.bdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 631 | mutex_lock(&rdev->pm.mutex); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 632 | if (rdev->pm.dynpm_state == DYNPM_STATE_ACTIVE) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 633 | unsigned long irq_flags; |
| 634 | int not_processed = 0; |
| 635 | |
| 636 | read_lock_irqsave(&rdev->fence_drv.lock, irq_flags); |
| 637 | if (!list_empty(&rdev->fence_drv.emited)) { |
| 638 | struct list_head *ptr; |
| 639 | list_for_each(ptr, &rdev->fence_drv.emited) { |
| 640 | /* count up to 3, that's enought info */ |
| 641 | if (++not_processed >= 3) |
| 642 | break; |
| 643 | } |
| 644 | } |
| 645 | read_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags); |
| 646 | |
| 647 | if (not_processed >= 3) { /* should upclock */ |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 648 | if (rdev->pm.dynpm_planned_action == DYNPM_ACTION_DOWNCLOCK) { |
| 649 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
| 650 | } else if (rdev->pm.dynpm_planned_action == DYNPM_ACTION_NONE && |
| 651 | rdev->pm.dynpm_can_upclock) { |
| 652 | rdev->pm.dynpm_planned_action = |
| 653 | DYNPM_ACTION_UPCLOCK; |
| 654 | rdev->pm.dynpm_action_timeout = jiffies + |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 655 | msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS); |
| 656 | } |
| 657 | } else if (not_processed == 0) { /* should downclock */ |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 658 | if (rdev->pm.dynpm_planned_action == DYNPM_ACTION_UPCLOCK) { |
| 659 | rdev->pm.dynpm_planned_action = DYNPM_ACTION_NONE; |
| 660 | } else if (rdev->pm.dynpm_planned_action == DYNPM_ACTION_NONE && |
| 661 | rdev->pm.dynpm_can_downclock) { |
| 662 | rdev->pm.dynpm_planned_action = |
| 663 | DYNPM_ACTION_DOWNCLOCK; |
| 664 | rdev->pm.dynpm_action_timeout = jiffies + |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 665 | msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS); |
| 666 | } |
| 667 | } |
| 668 | |
Alex Deucher | d731117 | 2010-05-03 01:13:14 -0400 | [diff] [blame] | 669 | /* Note, radeon_pm_set_clocks is called with static_switch set |
| 670 | * to false since we want to wait for vbl to avoid flicker. |
| 671 | */ |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 672 | if (rdev->pm.dynpm_planned_action != DYNPM_ACTION_NONE && |
| 673 | jiffies > rdev->pm.dynpm_action_timeout) { |
| 674 | radeon_pm_get_dynpm_state(rdev); |
| 675 | radeon_pm_set_clocks(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 676 | } |
| 677 | } |
| 678 | mutex_unlock(&rdev->pm.mutex); |
Matthew Garrett | d9932a3 | 2010-04-26 16:02:26 -0400 | [diff] [blame] | 679 | ttm_bo_unlock_delayed_workqueue(&rdev->mman.bdev, resched); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 680 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 681 | queue_delayed_work(rdev->wq, &rdev->pm.dynpm_idle_work, |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 682 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
| 683 | } |
| 684 | |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 685 | /* |
| 686 | * Debugfs info |
| 687 | */ |
| 688 | #if defined(CONFIG_DEBUG_FS) |
| 689 | |
| 690 | static int radeon_debugfs_pm_info(struct seq_file *m, void *data) |
| 691 | { |
| 692 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 693 | struct drm_device *dev = node->minor->dev; |
| 694 | struct radeon_device *rdev = dev->dev_private; |
| 695 | |
Rafał Miłecki | 6234077 | 2009-12-15 21:46:58 +0100 | [diff] [blame] | 696 | seq_printf(m, "default engine clock: %u0 kHz\n", rdev->clock.default_sclk); |
| 697 | seq_printf(m, "current engine clock: %u0 kHz\n", radeon_get_engine_clock(rdev)); |
| 698 | seq_printf(m, "default memory clock: %u0 kHz\n", rdev->clock.default_mclk); |
| 699 | if (rdev->asic->get_memory_clock) |
| 700 | seq_printf(m, "current memory clock: %u0 kHz\n", radeon_get_memory_clock(rdev)); |
Rafał Miłecki | aa5120d | 2010-02-18 20:24:28 +0000 | [diff] [blame] | 701 | if (rdev->asic->get_pcie_lanes) |
| 702 | seq_printf(m, "PCIE lanes: %d\n", radeon_get_pcie_lanes(rdev)); |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 703 | |
| 704 | return 0; |
| 705 | } |
| 706 | |
| 707 | static struct drm_info_list radeon_pm_info_list[] = { |
| 708 | {"radeon_pm_info", radeon_debugfs_pm_info, 0, NULL}, |
| 709 | }; |
| 710 | #endif |
| 711 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 712 | static int radeon_debugfs_pm_init(struct radeon_device *rdev) |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 713 | { |
| 714 | #if defined(CONFIG_DEBUG_FS) |
| 715 | return radeon_debugfs_add_files(rdev, radeon_pm_info_list, ARRAY_SIZE(radeon_pm_info_list)); |
| 716 | #else |
| 717 | return 0; |
| 718 | #endif |
| 719 | } |