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" |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 26 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 27 | #define RADEON_IDLE_LOOP_MS 100 |
| 28 | #define RADEON_RECLOCK_DELAY_MS 200 |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 29 | #define RADEON_WAIT_VBLANK_TIMEOUT 200 |
Alex Deucher | 2031f77 | 2010-04-22 12:52:11 -0400 | [diff] [blame] | 30 | #define RADEON_WAIT_IDLE_TIMEOUT 200 |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 31 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 32 | static void radeon_pm_idle_work_handler(struct work_struct *work); |
| 33 | static int radeon_debugfs_pm_init(struct radeon_device *rdev); |
| 34 | |
Matthew Garrett | 5876dd2 | 2010-04-26 15:52:20 -0400 | [diff] [blame] | 35 | static void radeon_unmap_vram_bos(struct radeon_device *rdev) |
| 36 | { |
| 37 | struct radeon_bo *bo, *n; |
| 38 | |
| 39 | if (list_empty(&rdev->gem.objects)) |
| 40 | return; |
| 41 | |
| 42 | list_for_each_entry_safe(bo, n, &rdev->gem.objects, list) { |
| 43 | if (bo->tbo.mem.mem_type == TTM_PL_VRAM) |
| 44 | ttm_bo_unmap_virtual(&bo->tbo); |
| 45 | } |
| 46 | |
| 47 | if (rdev->gart.table.vram.robj) |
| 48 | ttm_bo_unmap_virtual(&rdev->gart.table.vram.robj->tbo); |
| 49 | |
| 50 | if (rdev->stollen_vga_memory) |
| 51 | ttm_bo_unmap_virtual(&rdev->stollen_vga_memory->tbo); |
| 52 | |
| 53 | if (rdev->r600_blit.shader_obj) |
| 54 | ttm_bo_unmap_virtual(&rdev->r600_blit.shader_obj->tbo); |
| 55 | } |
| 56 | |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 57 | static void radeon_pm_set_clocks(struct radeon_device *rdev, int static_switch) |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 58 | { |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 59 | int i; |
| 60 | |
Matthew Garrett | c37d230 | 2010-04-27 13:58:46 -0400 | [diff] [blame] | 61 | if (!static_switch) |
| 62 | radeon_get_power_state(rdev, rdev->pm.planned_action); |
| 63 | |
Matthew Garrett | 612e06c | 2010-04-27 17:16:58 -0400 | [diff] [blame] | 64 | mutex_lock(&rdev->ddev->struct_mutex); |
| 65 | mutex_lock(&rdev->vram_mutex); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 66 | mutex_lock(&rdev->cp.mutex); |
| 67 | |
| 68 | /* wait for GPU idle */ |
| 69 | rdev->pm.gui_idle = false; |
| 70 | rdev->irq.gui_idle = true; |
| 71 | radeon_irq_set(rdev); |
| 72 | wait_event_interruptible_timeout( |
| 73 | rdev->irq.idle_queue, rdev->pm.gui_idle, |
| 74 | msecs_to_jiffies(RADEON_WAIT_IDLE_TIMEOUT)); |
| 75 | rdev->irq.gui_idle = false; |
| 76 | radeon_irq_set(rdev); |
| 77 | |
Matthew Garrett | 5876dd2 | 2010-04-26 15:52:20 -0400 | [diff] [blame] | 78 | radeon_unmap_vram_bos(rdev); |
| 79 | |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 80 | if (!static_switch) { |
| 81 | for (i = 0; i < rdev->num_crtc; i++) { |
| 82 | if (rdev->pm.active_crtcs & (1 << i)) { |
| 83 | rdev->pm.req_vblank |= (1 << i); |
| 84 | drm_vblank_get(rdev->ddev, i); |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | radeon_set_power_state(rdev, static_switch); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 90 | |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 91 | if (!static_switch) { |
| 92 | for (i = 0; i < rdev->num_crtc; i++) { |
| 93 | if (rdev->pm.req_vblank & (1 << i)) { |
| 94 | rdev->pm.req_vblank &= ~(1 << i); |
| 95 | drm_vblank_put(rdev->ddev, i); |
| 96 | } |
| 97 | } |
| 98 | } |
Matthew Garrett | 5876dd2 | 2010-04-26 15:52:20 -0400 | [diff] [blame] | 99 | |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 100 | /* update display watermarks based on new power state */ |
| 101 | radeon_update_bandwidth_info(rdev); |
| 102 | if (rdev->pm.active_crtc_count) |
| 103 | radeon_bandwidth_update(rdev); |
| 104 | |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 105 | rdev->pm.planned_action = PM_ACTION_NONE; |
| 106 | |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 107 | mutex_unlock(&rdev->cp.mutex); |
Matthew Garrett | 612e06c | 2010-04-27 17:16:58 -0400 | [diff] [blame] | 108 | mutex_unlock(&rdev->vram_mutex); |
| 109 | mutex_unlock(&rdev->ddev->struct_mutex); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static ssize_t radeon_get_power_state_static(struct device *dev, |
| 113 | struct device_attribute *attr, |
| 114 | char *buf) |
| 115 | { |
| 116 | struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); |
| 117 | struct radeon_device *rdev = ddev->dev_private; |
| 118 | |
| 119 | return snprintf(buf, PAGE_SIZE, "%d.%d\n", rdev->pm.current_power_state_index, |
| 120 | rdev->pm.current_clock_mode_index); |
| 121 | } |
| 122 | |
| 123 | static ssize_t radeon_set_power_state_static(struct device *dev, |
| 124 | struct device_attribute *attr, |
| 125 | const char *buf, |
| 126 | size_t count) |
| 127 | { |
| 128 | struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); |
| 129 | struct radeon_device *rdev = ddev->dev_private; |
| 130 | int ps, cm; |
| 131 | |
| 132 | if (sscanf(buf, "%u.%u", &ps, &cm) != 2) { |
| 133 | DRM_ERROR("Invalid power state!\n"); |
| 134 | return count; |
| 135 | } |
| 136 | |
| 137 | mutex_lock(&rdev->pm.mutex); |
| 138 | if ((ps >= 0) && (ps < rdev->pm.num_power_states) && |
| 139 | (cm >= 0) && (cm < rdev->pm.power_state[ps].num_clock_modes)) { |
| 140 | if ((rdev->pm.active_crtc_count > 1) && |
| 141 | (rdev->pm.power_state[ps].flags & RADEON_PM_SINGLE_DISPLAY_ONLY)) { |
| 142 | DRM_ERROR("Invalid power state for multi-head: %d.%d\n", ps, cm); |
| 143 | } else { |
| 144 | /* disable dynpm */ |
| 145 | rdev->pm.state = PM_STATE_DISABLED; |
| 146 | rdev->pm.planned_action = PM_ACTION_NONE; |
| 147 | rdev->pm.requested_power_state_index = ps; |
| 148 | rdev->pm.requested_clock_mode_index = cm; |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 149 | radeon_pm_set_clocks(rdev, true); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 150 | } |
| 151 | } else |
| 152 | DRM_ERROR("Invalid power state: %d.%d\n\n", ps, cm); |
| 153 | mutex_unlock(&rdev->pm.mutex); |
| 154 | |
| 155 | return count; |
| 156 | } |
| 157 | |
| 158 | static ssize_t radeon_get_dynpm(struct device *dev, |
| 159 | struct device_attribute *attr, |
| 160 | char *buf) |
| 161 | { |
| 162 | struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); |
| 163 | struct radeon_device *rdev = ddev->dev_private; |
| 164 | |
| 165 | return snprintf(buf, PAGE_SIZE, "%s\n", |
| 166 | (rdev->pm.state == PM_STATE_DISABLED) ? "disabled" : "enabled"); |
| 167 | } |
| 168 | |
| 169 | static ssize_t radeon_set_dynpm(struct device *dev, |
| 170 | struct device_attribute *attr, |
| 171 | const char *buf, |
| 172 | size_t count) |
| 173 | { |
| 174 | struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); |
| 175 | struct radeon_device *rdev = ddev->dev_private; |
| 176 | int tmp = simple_strtoul(buf, NULL, 10); |
| 177 | |
| 178 | if (tmp == 0) { |
| 179 | /* update power mode info */ |
| 180 | radeon_pm_compute_clocks(rdev); |
| 181 | /* disable dynpm */ |
| 182 | mutex_lock(&rdev->pm.mutex); |
| 183 | rdev->pm.state = PM_STATE_DISABLED; |
| 184 | rdev->pm.planned_action = PM_ACTION_NONE; |
| 185 | mutex_unlock(&rdev->pm.mutex); |
| 186 | DRM_INFO("radeon: dynamic power management disabled\n"); |
| 187 | } else if (tmp == 1) { |
| 188 | if (rdev->pm.num_power_states > 1) { |
| 189 | /* enable dynpm */ |
| 190 | mutex_lock(&rdev->pm.mutex); |
| 191 | rdev->pm.state = PM_STATE_PAUSED; |
| 192 | rdev->pm.planned_action = PM_ACTION_DEFAULT; |
| 193 | radeon_get_power_state(rdev, rdev->pm.planned_action); |
| 194 | mutex_unlock(&rdev->pm.mutex); |
| 195 | /* update power mode info */ |
| 196 | radeon_pm_compute_clocks(rdev); |
| 197 | DRM_INFO("radeon: dynamic power management enabled\n"); |
| 198 | } else |
| 199 | DRM_ERROR("dynpm not valid on this system\n"); |
| 200 | } else |
| 201 | DRM_ERROR("Invalid setting: %d\n", tmp); |
| 202 | |
| 203 | return count; |
| 204 | } |
| 205 | |
| 206 | static DEVICE_ATTR(power_state, S_IRUGO | S_IWUSR, radeon_get_power_state_static, radeon_set_power_state_static); |
| 207 | static DEVICE_ATTR(dynpm, S_IRUGO | S_IWUSR, radeon_get_dynpm, radeon_set_dynpm); |
| 208 | |
| 209 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 210 | static const char *pm_state_names[4] = { |
| 211 | "PM_STATE_DISABLED", |
| 212 | "PM_STATE_MINIMUM", |
| 213 | "PM_STATE_PAUSED", |
| 214 | "PM_STATE_ACTIVE" |
| 215 | }; |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 216 | |
Alex Deucher | 0ec0e74 | 2009-12-23 13:21:58 -0500 | [diff] [blame] | 217 | static const char *pm_state_types[5] = { |
Alex Deucher | d91eeb7 | 2010-04-05 15:26:43 -0400 | [diff] [blame] | 218 | "", |
Alex Deucher | 0ec0e74 | 2009-12-23 13:21:58 -0500 | [diff] [blame] | 219 | "Powersave", |
| 220 | "Battery", |
| 221 | "Balanced", |
| 222 | "Performance", |
| 223 | }; |
| 224 | |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 225 | static void radeon_print_power_mode_info(struct radeon_device *rdev) |
| 226 | { |
| 227 | int i, j; |
| 228 | bool is_default; |
| 229 | |
| 230 | DRM_INFO("%d Power State(s)\n", rdev->pm.num_power_states); |
| 231 | for (i = 0; i < rdev->pm.num_power_states; i++) { |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 232 | if (rdev->pm.default_power_state_index == i) |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 233 | is_default = true; |
| 234 | else |
| 235 | is_default = false; |
Alex Deucher | 0ec0e74 | 2009-12-23 13:21:58 -0500 | [diff] [blame] | 236 | DRM_INFO("State %d %s %s\n", i, |
| 237 | pm_state_types[rdev->pm.power_state[i].type], |
| 238 | is_default ? "(default)" : ""); |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 239 | if ((rdev->flags & RADEON_IS_PCIE) && !(rdev->flags & RADEON_IS_IGP)) |
Alex Deucher | 79daedc | 2010-04-22 14:25:19 -0400 | [diff] [blame] | 240 | DRM_INFO("\t%d PCIE Lanes\n", rdev->pm.power_state[i].pcie_lanes); |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 241 | if (rdev->pm.power_state[i].flags & RADEON_PM_SINGLE_DISPLAY_ONLY) |
| 242 | DRM_INFO("\tSingle display only\n"); |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 243 | DRM_INFO("\t%d Clock Mode(s)\n", rdev->pm.power_state[i].num_clock_modes); |
| 244 | for (j = 0; j < rdev->pm.power_state[i].num_clock_modes; j++) { |
| 245 | if (rdev->flags & RADEON_IS_IGP) |
| 246 | DRM_INFO("\t\t%d engine: %d\n", |
| 247 | j, |
| 248 | rdev->pm.power_state[i].clock_info[j].sclk * 10); |
| 249 | else |
| 250 | DRM_INFO("\t\t%d engine/memory: %d/%d\n", |
| 251 | j, |
| 252 | rdev->pm.power_state[i].clock_info[j].sclk * 10, |
| 253 | rdev->pm.power_state[i].clock_info[j].mclk * 10); |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
Alex Deucher | bae6b562 | 2010-04-22 13:38:05 -0400 | [diff] [blame] | 258 | void radeon_sync_with_vblank(struct radeon_device *rdev) |
Rafał Miłecki | d0d6cb8 | 2010-03-02 22:06:52 +0100 | [diff] [blame] | 259 | { |
| 260 | if (rdev->pm.active_crtcs) { |
| 261 | rdev->pm.vblank_sync = false; |
| 262 | wait_event_timeout( |
| 263 | rdev->irq.vblank_queue, rdev->pm.vblank_sync, |
| 264 | msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT)); |
| 265 | } |
| 266 | } |
| 267 | |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 268 | int radeon_pm_init(struct radeon_device *rdev) |
| 269 | { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 270 | rdev->pm.state = PM_STATE_DISABLED; |
| 271 | rdev->pm.planned_action = PM_ACTION_NONE; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 272 | rdev->pm.can_upclock = true; |
| 273 | rdev->pm.can_downclock = true; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 274 | |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 275 | if (rdev->bios) { |
| 276 | if (rdev->is_atom_bios) |
| 277 | radeon_atombios_get_power_modes(rdev); |
| 278 | else |
| 279 | radeon_combios_get_power_modes(rdev); |
| 280 | radeon_print_power_mode_info(rdev); |
| 281 | } |
| 282 | |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 283 | if (radeon_debugfs_pm_init(rdev)) { |
Rafał Miłecki | c142c3e | 2009-11-06 11:38:34 +0100 | [diff] [blame] | 284 | DRM_ERROR("Failed to register debugfs file for PM!\n"); |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 285 | } |
| 286 | |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 287 | /* where's the best place to put this? */ |
| 288 | device_create_file(rdev->dev, &dev_attr_power_state); |
| 289 | device_create_file(rdev->dev, &dev_attr_dynpm); |
| 290 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 291 | INIT_DELAYED_WORK(&rdev->pm.idle_work, radeon_pm_idle_work_handler); |
| 292 | |
Alex Deucher | 90c3905 | 2010-03-24 11:32:29 -0400 | [diff] [blame] | 293 | if ((radeon_dynpm != -1 && radeon_dynpm) && (rdev->pm.num_power_states > 1)) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 294 | rdev->pm.state = PM_STATE_PAUSED; |
| 295 | DRM_INFO("radeon: dynamic power management enabled\n"); |
| 296 | } |
| 297 | |
| 298 | DRM_INFO("radeon: power management initialized\n"); |
| 299 | |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 300 | return 0; |
| 301 | } |
| 302 | |
Alex Deucher | 29fb52c | 2010-03-11 10:01:17 -0500 | [diff] [blame] | 303 | void radeon_pm_fini(struct radeon_device *rdev) |
| 304 | { |
Alex Deucher | 58e21df | 2010-03-22 13:31:08 -0400 | [diff] [blame] | 305 | if (rdev->pm.state != PM_STATE_DISABLED) { |
| 306 | /* cancel work */ |
| 307 | cancel_delayed_work_sync(&rdev->pm.idle_work); |
| 308 | /* reset default clocks */ |
| 309 | rdev->pm.state = PM_STATE_DISABLED; |
| 310 | rdev->pm.planned_action = PM_ACTION_DEFAULT; |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 311 | radeon_pm_set_clocks(rdev, false); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 312 | } else if ((rdev->pm.current_power_state_index != |
| 313 | rdev->pm.default_power_state_index) || |
| 314 | (rdev->pm.current_clock_mode_index != 0)) { |
| 315 | rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index; |
| 316 | rdev->pm.requested_clock_mode_index = 0; |
| 317 | mutex_lock(&rdev->pm.mutex); |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 318 | radeon_pm_set_clocks(rdev, true); |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 319 | mutex_unlock(&rdev->pm.mutex); |
Alex Deucher | 58e21df | 2010-03-22 13:31:08 -0400 | [diff] [blame] | 320 | } |
| 321 | |
Alex Deucher | a424816 | 2010-04-24 14:50:23 -0400 | [diff] [blame] | 322 | device_remove_file(rdev->dev, &dev_attr_power_state); |
| 323 | device_remove_file(rdev->dev, &dev_attr_dynpm); |
| 324 | |
Alex Deucher | 29fb52c | 2010-03-11 10:01:17 -0500 | [diff] [blame] | 325 | if (rdev->pm.i2c_bus) |
| 326 | radeon_i2c_destroy(rdev->pm.i2c_bus); |
| 327 | } |
| 328 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 329 | void radeon_pm_compute_clocks(struct radeon_device *rdev) |
| 330 | { |
| 331 | struct drm_device *ddev = rdev->ddev; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 332 | struct drm_crtc *crtc; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 333 | struct radeon_crtc *radeon_crtc; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 334 | |
| 335 | if (rdev->pm.state == PM_STATE_DISABLED) |
| 336 | return; |
| 337 | |
| 338 | mutex_lock(&rdev->pm.mutex); |
| 339 | |
| 340 | rdev->pm.active_crtcs = 0; |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 341 | rdev->pm.active_crtc_count = 0; |
| 342 | list_for_each_entry(crtc, |
| 343 | &ddev->mode_config.crtc_list, head) { |
| 344 | radeon_crtc = to_radeon_crtc(crtc); |
| 345 | if (radeon_crtc->enabled) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 346 | rdev->pm.active_crtcs |= (1 << radeon_crtc->crtc_id); |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 347 | rdev->pm.active_crtc_count++; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 351 | if (rdev->pm.active_crtc_count > 1) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 352 | if (rdev->pm.state == PM_STATE_ACTIVE) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 353 | cancel_delayed_work(&rdev->pm.idle_work); |
| 354 | |
| 355 | rdev->pm.state = PM_STATE_PAUSED; |
| 356 | rdev->pm.planned_action = PM_ACTION_UPCLOCK; |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 357 | radeon_pm_set_clocks(rdev, false); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 358 | |
| 359 | DRM_DEBUG("radeon: dynamic power management deactivated\n"); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 360 | } |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 361 | } else if (rdev->pm.active_crtc_count == 1) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 362 | /* TODO: Increase clocks if needed for current mode */ |
| 363 | |
| 364 | if (rdev->pm.state == PM_STATE_MINIMUM) { |
| 365 | rdev->pm.state = PM_STATE_ACTIVE; |
| 366 | rdev->pm.planned_action = PM_ACTION_UPCLOCK; |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 367 | radeon_pm_set_clocks(rdev, false); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 368 | |
| 369 | queue_delayed_work(rdev->wq, &rdev->pm.idle_work, |
| 370 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 371 | } else if (rdev->pm.state == PM_STATE_PAUSED) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 372 | rdev->pm.state = PM_STATE_ACTIVE; |
| 373 | queue_delayed_work(rdev->wq, &rdev->pm.idle_work, |
| 374 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
| 375 | DRM_DEBUG("radeon: dynamic power management activated\n"); |
| 376 | } |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 377 | } else { /* count == 0 */ |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 378 | if (rdev->pm.state != PM_STATE_MINIMUM) { |
| 379 | cancel_delayed_work(&rdev->pm.idle_work); |
| 380 | |
| 381 | rdev->pm.state = PM_STATE_MINIMUM; |
| 382 | rdev->pm.planned_action = PM_ACTION_MINIMUM; |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 383 | radeon_pm_set_clocks(rdev, false); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 384 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 385 | } |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 386 | |
| 387 | mutex_unlock(&rdev->pm.mutex); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 388 | } |
| 389 | |
Matthew Garrett | f81f202 | 2010-04-28 12:13:06 -0400 | [diff] [blame^] | 390 | bool radeon_pm_in_vbl(struct radeon_device *rdev) |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 391 | { |
Alex Deucher | bae6b562 | 2010-04-22 13:38:05 -0400 | [diff] [blame] | 392 | u32 stat_crtc = 0; |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 393 | bool in_vbl = true; |
| 394 | |
Alex Deucher | bae6b562 | 2010-04-22 13:38:05 -0400 | [diff] [blame] | 395 | if (ASIC_IS_DCE4(rdev)) { |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 396 | if (rdev->pm.active_crtcs & (1 << 0)) { |
Alex Deucher | bae6b562 | 2010-04-22 13:38:05 -0400 | [diff] [blame] | 397 | stat_crtc = RREG32(EVERGREEN_CRTC_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET); |
| 398 | if (!(stat_crtc & 1)) |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 399 | in_vbl = false; |
| 400 | } |
| 401 | if (rdev->pm.active_crtcs & (1 << 1)) { |
Alex Deucher | bae6b562 | 2010-04-22 13:38:05 -0400 | [diff] [blame] | 402 | stat_crtc = RREG32(EVERGREEN_CRTC_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET); |
| 403 | if (!(stat_crtc & 1)) |
| 404 | in_vbl = false; |
| 405 | } |
| 406 | if (rdev->pm.active_crtcs & (1 << 2)) { |
| 407 | stat_crtc = RREG32(EVERGREEN_CRTC_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET); |
| 408 | if (!(stat_crtc & 1)) |
| 409 | in_vbl = false; |
| 410 | } |
| 411 | if (rdev->pm.active_crtcs & (1 << 3)) { |
| 412 | stat_crtc = RREG32(EVERGREEN_CRTC_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET); |
| 413 | if (!(stat_crtc & 1)) |
| 414 | in_vbl = false; |
| 415 | } |
| 416 | if (rdev->pm.active_crtcs & (1 << 4)) { |
| 417 | stat_crtc = RREG32(EVERGREEN_CRTC_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET); |
| 418 | if (!(stat_crtc & 1)) |
| 419 | in_vbl = false; |
| 420 | } |
| 421 | if (rdev->pm.active_crtcs & (1 << 5)) { |
| 422 | stat_crtc = RREG32(EVERGREEN_CRTC_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET); |
| 423 | if (!(stat_crtc & 1)) |
| 424 | in_vbl = false; |
| 425 | } |
| 426 | } else if (ASIC_IS_AVIVO(rdev)) { |
| 427 | if (rdev->pm.active_crtcs & (1 << 0)) { |
| 428 | stat_crtc = RREG32(D1CRTC_STATUS); |
| 429 | if (!(stat_crtc & 1)) |
| 430 | in_vbl = false; |
| 431 | } |
| 432 | if (rdev->pm.active_crtcs & (1 << 1)) { |
| 433 | stat_crtc = RREG32(D2CRTC_STATUS); |
| 434 | if (!(stat_crtc & 1)) |
| 435 | in_vbl = false; |
| 436 | } |
| 437 | } else { |
| 438 | if (rdev->pm.active_crtcs & (1 << 0)) { |
| 439 | stat_crtc = RREG32(RADEON_CRTC_STATUS); |
| 440 | if (!(stat_crtc & 1)) |
| 441 | in_vbl = false; |
| 442 | } |
| 443 | if (rdev->pm.active_crtcs & (1 << 1)) { |
| 444 | stat_crtc = RREG32(RADEON_CRTC2_STATUS); |
| 445 | if (!(stat_crtc & 1)) |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 446 | in_vbl = false; |
| 447 | } |
| 448 | } |
Matthew Garrett | f81f202 | 2010-04-28 12:13:06 -0400 | [diff] [blame^] | 449 | |
| 450 | return in_vbl; |
| 451 | } |
| 452 | |
| 453 | bool radeon_pm_debug_check_in_vbl(struct radeon_device *rdev, bool finish) |
| 454 | { |
| 455 | u32 stat_crtc = 0; |
| 456 | bool in_vbl = radeon_pm_in_vbl(rdev); |
| 457 | |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 458 | if (in_vbl == false) |
Alex Deucher | bae6b562 | 2010-04-22 13:38:05 -0400 | [diff] [blame] | 459 | DRM_INFO("not in vbl for pm change %08x at %s\n", stat_crtc, |
| 460 | finish ? "exit" : "entry"); |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 461 | return in_vbl; |
| 462 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 463 | |
| 464 | static void radeon_pm_idle_work_handler(struct work_struct *work) |
| 465 | { |
| 466 | struct radeon_device *rdev; |
Matthew Garrett | d9932a3 | 2010-04-26 16:02:26 -0400 | [diff] [blame] | 467 | int resched; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 468 | rdev = container_of(work, struct radeon_device, |
| 469 | pm.idle_work.work); |
| 470 | |
Matthew Garrett | d9932a3 | 2010-04-26 16:02:26 -0400 | [diff] [blame] | 471 | resched = ttm_bo_lock_delayed_workqueue(&rdev->mman.bdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 472 | mutex_lock(&rdev->pm.mutex); |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 473 | if (rdev->pm.state == PM_STATE_ACTIVE) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 474 | unsigned long irq_flags; |
| 475 | int not_processed = 0; |
| 476 | |
| 477 | read_lock_irqsave(&rdev->fence_drv.lock, irq_flags); |
| 478 | if (!list_empty(&rdev->fence_drv.emited)) { |
| 479 | struct list_head *ptr; |
| 480 | list_for_each(ptr, &rdev->fence_drv.emited) { |
| 481 | /* count up to 3, that's enought info */ |
| 482 | if (++not_processed >= 3) |
| 483 | break; |
| 484 | } |
| 485 | } |
| 486 | read_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags); |
| 487 | |
| 488 | if (not_processed >= 3) { /* should upclock */ |
| 489 | if (rdev->pm.planned_action == PM_ACTION_DOWNCLOCK) { |
| 490 | rdev->pm.planned_action = PM_ACTION_NONE; |
| 491 | } else if (rdev->pm.planned_action == PM_ACTION_NONE && |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 492 | rdev->pm.can_upclock) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 493 | rdev->pm.planned_action = |
| 494 | PM_ACTION_UPCLOCK; |
| 495 | rdev->pm.action_timeout = jiffies + |
| 496 | msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS); |
| 497 | } |
| 498 | } else if (not_processed == 0) { /* should downclock */ |
| 499 | if (rdev->pm.planned_action == PM_ACTION_UPCLOCK) { |
| 500 | rdev->pm.planned_action = PM_ACTION_NONE; |
| 501 | } else if (rdev->pm.planned_action == PM_ACTION_NONE && |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 502 | rdev->pm.can_downclock) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 503 | rdev->pm.planned_action = |
| 504 | PM_ACTION_DOWNCLOCK; |
| 505 | rdev->pm.action_timeout = jiffies + |
| 506 | msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS); |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | if (rdev->pm.planned_action != PM_ACTION_NONE && |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 511 | jiffies > rdev->pm.action_timeout) { |
Matthew Garrett | 2aba631 | 2010-04-26 15:45:23 -0400 | [diff] [blame] | 512 | radeon_pm_set_clocks(rdev, false); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | mutex_unlock(&rdev->pm.mutex); |
Matthew Garrett | d9932a3 | 2010-04-26 16:02:26 -0400 | [diff] [blame] | 516 | ttm_bo_unlock_delayed_workqueue(&rdev->mman.bdev, resched); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 517 | |
| 518 | queue_delayed_work(rdev->wq, &rdev->pm.idle_work, |
| 519 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
| 520 | } |
| 521 | |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 522 | /* |
| 523 | * Debugfs info |
| 524 | */ |
| 525 | #if defined(CONFIG_DEBUG_FS) |
| 526 | |
| 527 | static int radeon_debugfs_pm_info(struct seq_file *m, void *data) |
| 528 | { |
| 529 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 530 | struct drm_device *dev = node->minor->dev; |
| 531 | struct radeon_device *rdev = dev->dev_private; |
| 532 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 533 | seq_printf(m, "state: %s\n", pm_state_names[rdev->pm.state]); |
Rafał Miłecki | 6234077 | 2009-12-15 21:46:58 +0100 | [diff] [blame] | 534 | seq_printf(m, "default engine clock: %u0 kHz\n", rdev->clock.default_sclk); |
| 535 | seq_printf(m, "current engine clock: %u0 kHz\n", radeon_get_engine_clock(rdev)); |
| 536 | seq_printf(m, "default memory clock: %u0 kHz\n", rdev->clock.default_mclk); |
| 537 | if (rdev->asic->get_memory_clock) |
| 538 | 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] | 539 | if (rdev->asic->get_pcie_lanes) |
| 540 | 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] | 541 | |
| 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | static struct drm_info_list radeon_pm_info_list[] = { |
| 546 | {"radeon_pm_info", radeon_debugfs_pm_info, 0, NULL}, |
| 547 | }; |
| 548 | #endif |
| 549 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 550 | static int radeon_debugfs_pm_init(struct radeon_device *rdev) |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 551 | { |
| 552 | #if defined(CONFIG_DEBUG_FS) |
| 553 | return radeon_debugfs_add_files(rdev, radeon_pm_info_list, ARRAY_SIZE(radeon_pm_info_list)); |
| 554 | #else |
| 555 | return 0; |
| 556 | #endif |
| 557 | } |