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