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 |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 30 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 31 | static void radeon_pm_set_clocks_locked(struct radeon_device *rdev); |
| 32 | static void radeon_pm_set_clocks(struct radeon_device *rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 33 | static void radeon_pm_idle_work_handler(struct work_struct *work); |
| 34 | static int radeon_debugfs_pm_init(struct radeon_device *rdev); |
| 35 | |
| 36 | static const char *pm_state_names[4] = { |
| 37 | "PM_STATE_DISABLED", |
| 38 | "PM_STATE_MINIMUM", |
| 39 | "PM_STATE_PAUSED", |
| 40 | "PM_STATE_ACTIVE" |
| 41 | }; |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 42 | |
Alex Deucher | 0ec0e74 | 2009-12-23 13:21:58 -0500 | [diff] [blame] | 43 | static const char *pm_state_types[5] = { |
| 44 | "Default", |
| 45 | "Powersave", |
| 46 | "Battery", |
| 47 | "Balanced", |
| 48 | "Performance", |
| 49 | }; |
| 50 | |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 51 | static void radeon_print_power_mode_info(struct radeon_device *rdev) |
| 52 | { |
| 53 | int i, j; |
| 54 | bool is_default; |
| 55 | |
| 56 | DRM_INFO("%d Power State(s)\n", rdev->pm.num_power_states); |
| 57 | for (i = 0; i < rdev->pm.num_power_states; i++) { |
| 58 | if (rdev->pm.default_power_state == &rdev->pm.power_state[i]) |
| 59 | is_default = true; |
| 60 | else |
| 61 | is_default = false; |
Alex Deucher | 0ec0e74 | 2009-12-23 13:21:58 -0500 | [diff] [blame] | 62 | DRM_INFO("State %d %s %s\n", i, |
| 63 | pm_state_types[rdev->pm.power_state[i].type], |
| 64 | is_default ? "(default)" : ""); |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 65 | if ((rdev->flags & RADEON_IS_PCIE) && !(rdev->flags & RADEON_IS_IGP)) |
| 66 | DRM_INFO("\t%d PCIE Lanes\n", rdev->pm.power_state[i].non_clock_info.pcie_lanes); |
| 67 | DRM_INFO("\t%d Clock Mode(s)\n", rdev->pm.power_state[i].num_clock_modes); |
| 68 | for (j = 0; j < rdev->pm.power_state[i].num_clock_modes; j++) { |
| 69 | if (rdev->flags & RADEON_IS_IGP) |
| 70 | DRM_INFO("\t\t%d engine: %d\n", |
| 71 | j, |
| 72 | rdev->pm.power_state[i].clock_info[j].sclk * 10); |
| 73 | else |
| 74 | DRM_INFO("\t\t%d engine/memory: %d/%d\n", |
| 75 | j, |
| 76 | rdev->pm.power_state[i].clock_info[j].sclk * 10, |
| 77 | rdev->pm.power_state[i].clock_info[j].mclk * 10); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
Alex Deucher | 516d0e4 | 2009-12-23 14:28:05 -0500 | [diff] [blame] | 82 | static struct radeon_power_state * radeon_pick_power_state(struct radeon_device *rdev, |
| 83 | enum radeon_pm_state_type type) |
| 84 | { |
Rafał Miłecki | bc4624c | 2010-02-11 21:50:06 +0000 | [diff] [blame] | 85 | int i, j; |
| 86 | enum radeon_pm_state_type wanted_types[2]; |
| 87 | int wanted_count; |
Alex Deucher | 516d0e4 | 2009-12-23 14:28:05 -0500 | [diff] [blame] | 88 | |
| 89 | switch (type) { |
| 90 | case POWER_STATE_TYPE_DEFAULT: |
| 91 | default: |
| 92 | return rdev->pm.default_power_state; |
| 93 | case POWER_STATE_TYPE_POWERSAVE: |
Rafał Miłecki | 08ff2a7 | 2010-02-21 22:46:30 +0000 | [diff] [blame] | 94 | if (rdev->flags & RADEON_IS_MOBILITY) { |
| 95 | wanted_types[0] = POWER_STATE_TYPE_POWERSAVE; |
| 96 | wanted_types[1] = POWER_STATE_TYPE_BATTERY; |
| 97 | wanted_count = 2; |
| 98 | } else { |
| 99 | wanted_types[0] = POWER_STATE_TYPE_PERFORMANCE; |
| 100 | wanted_count = 1; |
| 101 | } |
Alex Deucher | 516d0e4 | 2009-12-23 14:28:05 -0500 | [diff] [blame] | 102 | break; |
| 103 | case POWER_STATE_TYPE_BATTERY: |
Rafał Miłecki | 08ff2a7 | 2010-02-21 22:46:30 +0000 | [diff] [blame] | 104 | if (rdev->flags & RADEON_IS_MOBILITY) { |
| 105 | wanted_types[0] = POWER_STATE_TYPE_BATTERY; |
| 106 | wanted_types[1] = POWER_STATE_TYPE_POWERSAVE; |
| 107 | wanted_count = 2; |
| 108 | } else { |
| 109 | wanted_types[0] = POWER_STATE_TYPE_PERFORMANCE; |
| 110 | wanted_count = 1; |
| 111 | } |
Alex Deucher | 516d0e4 | 2009-12-23 14:28:05 -0500 | [diff] [blame] | 112 | break; |
| 113 | case POWER_STATE_TYPE_BALANCED: |
| 114 | case POWER_STATE_TYPE_PERFORMANCE: |
Rafał Miłecki | bc4624c | 2010-02-11 21:50:06 +0000 | [diff] [blame] | 115 | wanted_types[0] = type; |
| 116 | wanted_count = 1; |
Alex Deucher | 516d0e4 | 2009-12-23 14:28:05 -0500 | [diff] [blame] | 117 | break; |
| 118 | } |
| 119 | |
Rafał Miłecki | bc4624c | 2010-02-11 21:50:06 +0000 | [diff] [blame] | 120 | for (i = 0; i < wanted_count; i++) { |
| 121 | for (j = 0; j < rdev->pm.num_power_states; j++) { |
| 122 | if (rdev->pm.power_state[j].type == wanted_types[i]) |
| 123 | return &rdev->pm.power_state[j]; |
| 124 | } |
| 125 | } |
Alex Deucher | 516d0e4 | 2009-12-23 14:28:05 -0500 | [diff] [blame] | 126 | |
Rafał Miłecki | bc4624c | 2010-02-11 21:50:06 +0000 | [diff] [blame] | 127 | return rdev->pm.default_power_state; |
Alex Deucher | 516d0e4 | 2009-12-23 14:28:05 -0500 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static struct radeon_pm_clock_info * radeon_pick_clock_mode(struct radeon_device *rdev, |
| 131 | struct radeon_power_state *power_state, |
| 132 | enum radeon_pm_clock_mode_type type) |
| 133 | { |
| 134 | switch (type) { |
| 135 | case POWER_MODE_TYPE_DEFAULT: |
| 136 | default: |
| 137 | return power_state->default_clock_mode; |
| 138 | case POWER_MODE_TYPE_LOW: |
| 139 | return &power_state->clock_info[0]; |
| 140 | case POWER_MODE_TYPE_MID: |
| 141 | if (power_state->num_clock_modes > 2) |
| 142 | return &power_state->clock_info[1]; |
| 143 | else |
| 144 | return &power_state->clock_info[0]; |
| 145 | break; |
| 146 | case POWER_MODE_TYPE_HIGH: |
| 147 | return &power_state->clock_info[power_state->num_clock_modes - 1]; |
| 148 | } |
| 149 | |
| 150 | } |
| 151 | |
| 152 | static void radeon_get_power_state(struct radeon_device *rdev, |
| 153 | enum radeon_pm_action action) |
| 154 | { |
| 155 | switch (action) { |
Alex Deucher | 516d0e4 | 2009-12-23 14:28:05 -0500 | [diff] [blame] | 156 | case PM_ACTION_MINIMUM: |
| 157 | rdev->pm.requested_power_state = radeon_pick_power_state(rdev, POWER_STATE_TYPE_BATTERY); |
Rafał Miłecki | 9038dfd | 2010-02-20 23:15:04 +0000 | [diff] [blame] | 158 | rdev->pm.requested_clock_mode = |
Alex Deucher | 516d0e4 | 2009-12-23 14:28:05 -0500 | [diff] [blame] | 159 | radeon_pick_clock_mode(rdev, rdev->pm.requested_power_state, POWER_MODE_TYPE_LOW); |
| 160 | break; |
| 161 | case PM_ACTION_DOWNCLOCK: |
| 162 | rdev->pm.requested_power_state = radeon_pick_power_state(rdev, POWER_STATE_TYPE_POWERSAVE); |
Rafał Miłecki | 9038dfd | 2010-02-20 23:15:04 +0000 | [diff] [blame] | 163 | rdev->pm.requested_clock_mode = |
Alex Deucher | 516d0e4 | 2009-12-23 14:28:05 -0500 | [diff] [blame] | 164 | radeon_pick_clock_mode(rdev, rdev->pm.requested_power_state, POWER_MODE_TYPE_MID); |
| 165 | break; |
| 166 | case PM_ACTION_UPCLOCK: |
| 167 | rdev->pm.requested_power_state = radeon_pick_power_state(rdev, POWER_STATE_TYPE_DEFAULT); |
Rafał Miłecki | 9038dfd | 2010-02-20 23:15:04 +0000 | [diff] [blame] | 168 | rdev->pm.requested_clock_mode = |
Alex Deucher | 516d0e4 | 2009-12-23 14:28:05 -0500 | [diff] [blame] | 169 | radeon_pick_clock_mode(rdev, rdev->pm.requested_power_state, POWER_MODE_TYPE_HIGH); |
| 170 | break; |
Rafał Miłecki | 9038dfd | 2010-02-20 23:15:04 +0000 | [diff] [blame] | 171 | case PM_ACTION_NONE: |
| 172 | default: |
| 173 | DRM_ERROR("Requested mode for not defined action\n"); |
| 174 | return; |
Alex Deucher | 516d0e4 | 2009-12-23 14:28:05 -0500 | [diff] [blame] | 175 | } |
Alex Deucher | 530079a | 2009-12-23 14:39:36 -0500 | [diff] [blame] | 176 | DRM_INFO("Requested: e: %d m: %d p: %d\n", |
Rafał Miłecki | 9038dfd | 2010-02-20 23:15:04 +0000 | [diff] [blame] | 177 | rdev->pm.requested_clock_mode->sclk, |
| 178 | rdev->pm.requested_clock_mode->mclk, |
Alex Deucher | 530079a | 2009-12-23 14:39:36 -0500 | [diff] [blame] | 179 | rdev->pm.requested_power_state->non_clock_info.pcie_lanes); |
Alex Deucher | 516d0e4 | 2009-12-23 14:28:05 -0500 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | static void radeon_set_power_state(struct radeon_device *rdev) |
| 183 | { |
Rafał Miłecki | 9038dfd | 2010-02-20 23:15:04 +0000 | [diff] [blame] | 184 | /* if *_clock_mode are the same, *_power_state are as well */ |
| 185 | if (rdev->pm.requested_clock_mode == rdev->pm.current_clock_mode) |
Alex Deucher | 516d0e4 | 2009-12-23 14:28:05 -0500 | [diff] [blame] | 186 | return; |
Alex Deucher | 530079a | 2009-12-23 14:39:36 -0500 | [diff] [blame] | 187 | |
| 188 | DRM_INFO("Setting: e: %d m: %d p: %d\n", |
Rafał Miłecki | 9038dfd | 2010-02-20 23:15:04 +0000 | [diff] [blame] | 189 | rdev->pm.requested_clock_mode->sclk, |
| 190 | rdev->pm.requested_clock_mode->mclk, |
Alex Deucher | 530079a | 2009-12-23 14:39:36 -0500 | [diff] [blame] | 191 | rdev->pm.requested_power_state->non_clock_info.pcie_lanes); |
Alex Deucher | 516d0e4 | 2009-12-23 14:28:05 -0500 | [diff] [blame] | 192 | /* set pcie lanes */ |
| 193 | /* set voltage */ |
| 194 | /* set engine clock */ |
Rafał Miłecki | 9038dfd | 2010-02-20 23:15:04 +0000 | [diff] [blame] | 195 | radeon_set_engine_clock(rdev, rdev->pm.requested_clock_mode->sclk); |
Alex Deucher | 516d0e4 | 2009-12-23 14:28:05 -0500 | [diff] [blame] | 196 | /* set memory clock */ |
| 197 | |
| 198 | rdev->pm.current_power_state = rdev->pm.requested_power_state; |
Rafał Miłecki | 9038dfd | 2010-02-20 23:15:04 +0000 | [diff] [blame] | 199 | rdev->pm.current_clock_mode = rdev->pm.requested_clock_mode; |
Alex Deucher | 516d0e4 | 2009-12-23 14:28:05 -0500 | [diff] [blame] | 200 | } |
| 201 | |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 202 | int radeon_pm_init(struct radeon_device *rdev) |
| 203 | { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 204 | rdev->pm.state = PM_STATE_DISABLED; |
| 205 | rdev->pm.planned_action = PM_ACTION_NONE; |
| 206 | rdev->pm.downclocked = false; |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 207 | |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 208 | if (rdev->bios) { |
| 209 | if (rdev->is_atom_bios) |
| 210 | radeon_atombios_get_power_modes(rdev); |
| 211 | else |
| 212 | radeon_combios_get_power_modes(rdev); |
| 213 | radeon_print_power_mode_info(rdev); |
| 214 | } |
| 215 | |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 216 | if (radeon_debugfs_pm_init(rdev)) { |
Rafał Miłecki | c142c3e | 2009-11-06 11:38:34 +0100 | [diff] [blame] | 217 | DRM_ERROR("Failed to register debugfs file for PM!\n"); |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 218 | } |
| 219 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 220 | INIT_DELAYED_WORK(&rdev->pm.idle_work, radeon_pm_idle_work_handler); |
| 221 | |
| 222 | if (radeon_dynpm != -1 && radeon_dynpm) { |
| 223 | rdev->pm.state = PM_STATE_PAUSED; |
| 224 | DRM_INFO("radeon: dynamic power management enabled\n"); |
| 225 | } |
| 226 | |
| 227 | DRM_INFO("radeon: power management initialized\n"); |
| 228 | |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 229 | return 0; |
| 230 | } |
| 231 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 232 | void radeon_pm_compute_clocks(struct radeon_device *rdev) |
| 233 | { |
| 234 | struct drm_device *ddev = rdev->ddev; |
| 235 | struct drm_connector *connector; |
| 236 | struct radeon_crtc *radeon_crtc; |
| 237 | int count = 0; |
| 238 | |
| 239 | if (rdev->pm.state == PM_STATE_DISABLED) |
| 240 | return; |
| 241 | |
| 242 | mutex_lock(&rdev->pm.mutex); |
| 243 | |
| 244 | rdev->pm.active_crtcs = 0; |
| 245 | list_for_each_entry(connector, |
| 246 | &ddev->mode_config.connector_list, head) { |
| 247 | if (connector->encoder && |
| 248 | connector->dpms != DRM_MODE_DPMS_OFF) { |
| 249 | radeon_crtc = to_radeon_crtc(connector->encoder->crtc); |
| 250 | rdev->pm.active_crtcs |= (1 << radeon_crtc->crtc_id); |
| 251 | ++count; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | if (count > 1) { |
| 256 | if (rdev->pm.state == PM_STATE_ACTIVE) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 257 | cancel_delayed_work(&rdev->pm.idle_work); |
| 258 | |
| 259 | rdev->pm.state = PM_STATE_PAUSED; |
| 260 | rdev->pm.planned_action = PM_ACTION_UPCLOCK; |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 261 | if (rdev->pm.downclocked) |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 262 | radeon_pm_set_clocks(rdev); |
| 263 | |
| 264 | DRM_DEBUG("radeon: dynamic power management deactivated\n"); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 265 | } |
| 266 | } else if (count == 1) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 267 | /* TODO: Increase clocks if needed for current mode */ |
| 268 | |
| 269 | if (rdev->pm.state == PM_STATE_MINIMUM) { |
| 270 | rdev->pm.state = PM_STATE_ACTIVE; |
| 271 | rdev->pm.planned_action = PM_ACTION_UPCLOCK; |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 272 | radeon_pm_set_clocks(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 273 | |
| 274 | queue_delayed_work(rdev->wq, &rdev->pm.idle_work, |
| 275 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
| 276 | } |
| 277 | else if (rdev->pm.state == PM_STATE_PAUSED) { |
| 278 | rdev->pm.state = PM_STATE_ACTIVE; |
| 279 | queue_delayed_work(rdev->wq, &rdev->pm.idle_work, |
| 280 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
| 281 | DRM_DEBUG("radeon: dynamic power management activated\n"); |
| 282 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 283 | } |
| 284 | else { /* count == 0 */ |
| 285 | if (rdev->pm.state != PM_STATE_MINIMUM) { |
| 286 | cancel_delayed_work(&rdev->pm.idle_work); |
| 287 | |
| 288 | rdev->pm.state = PM_STATE_MINIMUM; |
| 289 | rdev->pm.planned_action = PM_ACTION_MINIMUM; |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 290 | radeon_pm_set_clocks(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 291 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 292 | } |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 293 | |
| 294 | mutex_unlock(&rdev->pm.mutex); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 295 | } |
| 296 | |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 297 | static bool radeon_pm_debug_check_in_vbl(struct radeon_device *rdev, bool finish) |
| 298 | { |
| 299 | u32 stat_crtc1 = 0, stat_crtc2 = 0; |
| 300 | bool in_vbl = true; |
| 301 | |
| 302 | if (ASIC_IS_AVIVO(rdev)) { |
| 303 | if (rdev->pm.active_crtcs & (1 << 0)) { |
| 304 | stat_crtc1 = RREG32(D1CRTC_STATUS); |
| 305 | if (!(stat_crtc1 & 1)) |
| 306 | in_vbl = false; |
| 307 | } |
| 308 | if (rdev->pm.active_crtcs & (1 << 1)) { |
| 309 | stat_crtc2 = RREG32(D2CRTC_STATUS); |
| 310 | if (!(stat_crtc2 & 1)) |
| 311 | in_vbl = false; |
| 312 | } |
| 313 | } |
| 314 | if (in_vbl == false) |
| 315 | DRM_INFO("not in vbl for pm change %08x %08x at %s\n", stat_crtc1, |
| 316 | stat_crtc2, finish ? "exit" : "entry"); |
| 317 | return in_vbl; |
| 318 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 319 | static void radeon_pm_set_clocks_locked(struct radeon_device *rdev) |
| 320 | { |
| 321 | /*radeon_fence_wait_last(rdev);*/ |
| 322 | switch (rdev->pm.planned_action) { |
| 323 | case PM_ACTION_UPCLOCK: |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 324 | rdev->pm.downclocked = false; |
| 325 | break; |
| 326 | case PM_ACTION_DOWNCLOCK: |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 327 | rdev->pm.downclocked = true; |
| 328 | break; |
| 329 | case PM_ACTION_MINIMUM: |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 330 | break; |
| 331 | case PM_ACTION_NONE: |
| 332 | DRM_ERROR("%s: PM_ACTION_NONE\n", __func__); |
| 333 | break; |
| 334 | } |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 335 | |
| 336 | /* check if we are in vblank */ |
| 337 | radeon_pm_debug_check_in_vbl(rdev, false); |
Alex Deucher | 530079a | 2009-12-23 14:39:36 -0500 | [diff] [blame] | 338 | radeon_set_power_state(rdev); |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 339 | radeon_pm_debug_check_in_vbl(rdev, true); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 340 | rdev->pm.planned_action = PM_ACTION_NONE; |
| 341 | } |
| 342 | |
| 343 | static void radeon_pm_set_clocks(struct radeon_device *rdev) |
| 344 | { |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 345 | radeon_get_power_state(rdev, rdev->pm.planned_action); |
| 346 | mutex_lock(&rdev->cp.mutex); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 347 | |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 348 | if (rdev->pm.active_crtcs & (1 << 0)) { |
| 349 | rdev->pm.req_vblank |= (1 << 0); |
| 350 | drm_vblank_get(rdev->ddev, 0); |
| 351 | } |
| 352 | if (rdev->pm.active_crtcs & (1 << 1)) { |
| 353 | rdev->pm.req_vblank |= (1 << 1); |
| 354 | drm_vblank_get(rdev->ddev, 1); |
| 355 | } |
| 356 | if (rdev->pm.active_crtcs) |
| 357 | wait_event_interruptible_timeout( |
| 358 | rdev->irq.vblank_queue, 0, |
| 359 | msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT)); |
| 360 | if (rdev->pm.req_vblank & (1 << 0)) { |
| 361 | rdev->pm.req_vblank &= ~(1 << 0); |
| 362 | drm_vblank_put(rdev->ddev, 0); |
| 363 | } |
| 364 | if (rdev->pm.req_vblank & (1 << 1)) { |
| 365 | rdev->pm.req_vblank &= ~(1 << 1); |
| 366 | drm_vblank_put(rdev->ddev, 1); |
| 367 | } |
| 368 | |
| 369 | radeon_pm_set_clocks_locked(rdev); |
| 370 | mutex_unlock(&rdev->cp.mutex); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | static void radeon_pm_idle_work_handler(struct work_struct *work) |
| 374 | { |
| 375 | struct radeon_device *rdev; |
| 376 | rdev = container_of(work, struct radeon_device, |
| 377 | pm.idle_work.work); |
| 378 | |
| 379 | mutex_lock(&rdev->pm.mutex); |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 380 | if (rdev->pm.state == PM_STATE_ACTIVE) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 381 | unsigned long irq_flags; |
| 382 | int not_processed = 0; |
| 383 | |
| 384 | read_lock_irqsave(&rdev->fence_drv.lock, irq_flags); |
| 385 | if (!list_empty(&rdev->fence_drv.emited)) { |
| 386 | struct list_head *ptr; |
| 387 | list_for_each(ptr, &rdev->fence_drv.emited) { |
| 388 | /* count up to 3, that's enought info */ |
| 389 | if (++not_processed >= 3) |
| 390 | break; |
| 391 | } |
| 392 | } |
| 393 | read_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags); |
| 394 | |
| 395 | if (not_processed >= 3) { /* should upclock */ |
| 396 | if (rdev->pm.planned_action == PM_ACTION_DOWNCLOCK) { |
| 397 | rdev->pm.planned_action = PM_ACTION_NONE; |
| 398 | } else if (rdev->pm.planned_action == PM_ACTION_NONE && |
| 399 | rdev->pm.downclocked) { |
| 400 | rdev->pm.planned_action = |
| 401 | PM_ACTION_UPCLOCK; |
| 402 | rdev->pm.action_timeout = jiffies + |
| 403 | msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS); |
| 404 | } |
| 405 | } else if (not_processed == 0) { /* should downclock */ |
| 406 | if (rdev->pm.planned_action == PM_ACTION_UPCLOCK) { |
| 407 | rdev->pm.planned_action = PM_ACTION_NONE; |
| 408 | } else if (rdev->pm.planned_action == PM_ACTION_NONE && |
| 409 | !rdev->pm.downclocked) { |
| 410 | rdev->pm.planned_action = |
| 411 | PM_ACTION_DOWNCLOCK; |
| 412 | rdev->pm.action_timeout = jiffies + |
| 413 | msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS); |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | if (rdev->pm.planned_action != PM_ACTION_NONE && |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 418 | jiffies > rdev->pm.action_timeout) { |
| 419 | radeon_pm_set_clocks(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 420 | } |
| 421 | } |
| 422 | mutex_unlock(&rdev->pm.mutex); |
| 423 | |
| 424 | queue_delayed_work(rdev->wq, &rdev->pm.idle_work, |
| 425 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
| 426 | } |
| 427 | |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 428 | /* |
| 429 | * Debugfs info |
| 430 | */ |
| 431 | #if defined(CONFIG_DEBUG_FS) |
| 432 | |
| 433 | static int radeon_debugfs_pm_info(struct seq_file *m, void *data) |
| 434 | { |
| 435 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 436 | struct drm_device *dev = node->minor->dev; |
| 437 | struct radeon_device *rdev = dev->dev_private; |
| 438 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 439 | 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] | 440 | seq_printf(m, "default engine clock: %u0 kHz\n", rdev->clock.default_sclk); |
| 441 | seq_printf(m, "current engine clock: %u0 kHz\n", radeon_get_engine_clock(rdev)); |
| 442 | seq_printf(m, "default memory clock: %u0 kHz\n", rdev->clock.default_mclk); |
| 443 | if (rdev->asic->get_memory_clock) |
| 444 | 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^] | 445 | if (rdev->asic->get_pcie_lanes) |
| 446 | 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] | 447 | |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | static struct drm_info_list radeon_pm_info_list[] = { |
| 452 | {"radeon_pm_info", radeon_debugfs_pm_info, 0, NULL}, |
| 453 | }; |
| 454 | #endif |
| 455 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 456 | static int radeon_debugfs_pm_init(struct radeon_device *rdev) |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 457 | { |
| 458 | #if defined(CONFIG_DEBUG_FS) |
| 459 | return radeon_debugfs_add_files(rdev, radeon_pm_info_list, ARRAY_SIZE(radeon_pm_info_list)); |
| 460 | #else |
| 461 | return 0; |
| 462 | #endif |
| 463 | } |