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