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 && |
| 282 | connector->dpms != DRM_MODE_DPMS_OFF) { |
| 283 | radeon_crtc = to_radeon_crtc(connector->encoder->crtc); |
| 284 | rdev->pm.active_crtcs |= (1 << radeon_crtc->crtc_id); |
| 285 | ++count; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | if (count > 1) { |
| 290 | if (rdev->pm.state == PM_STATE_ACTIVE) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 291 | cancel_delayed_work(&rdev->pm.idle_work); |
| 292 | |
| 293 | rdev->pm.state = PM_STATE_PAUSED; |
| 294 | rdev->pm.planned_action = PM_ACTION_UPCLOCK; |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 295 | if (rdev->pm.downclocked) |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 296 | radeon_pm_set_clocks(rdev); |
| 297 | |
| 298 | DRM_DEBUG("radeon: dynamic power management deactivated\n"); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 299 | } |
| 300 | } else if (count == 1) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 301 | /* TODO: Increase clocks if needed for current mode */ |
| 302 | |
| 303 | if (rdev->pm.state == PM_STATE_MINIMUM) { |
| 304 | rdev->pm.state = PM_STATE_ACTIVE; |
| 305 | rdev->pm.planned_action = PM_ACTION_UPCLOCK; |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 306 | radeon_pm_set_clocks(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 307 | |
| 308 | queue_delayed_work(rdev->wq, &rdev->pm.idle_work, |
| 309 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
| 310 | } |
| 311 | else if (rdev->pm.state == PM_STATE_PAUSED) { |
| 312 | rdev->pm.state = PM_STATE_ACTIVE; |
| 313 | queue_delayed_work(rdev->wq, &rdev->pm.idle_work, |
| 314 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
| 315 | DRM_DEBUG("radeon: dynamic power management activated\n"); |
| 316 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 317 | } |
| 318 | else { /* count == 0 */ |
| 319 | if (rdev->pm.state != PM_STATE_MINIMUM) { |
| 320 | cancel_delayed_work(&rdev->pm.idle_work); |
| 321 | |
| 322 | rdev->pm.state = PM_STATE_MINIMUM; |
| 323 | rdev->pm.planned_action = PM_ACTION_MINIMUM; |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 324 | radeon_pm_set_clocks(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 325 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 326 | } |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 327 | |
| 328 | mutex_unlock(&rdev->pm.mutex); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 329 | } |
| 330 | |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 331 | static bool radeon_pm_debug_check_in_vbl(struct radeon_device *rdev, bool finish) |
| 332 | { |
| 333 | u32 stat_crtc1 = 0, stat_crtc2 = 0; |
| 334 | bool in_vbl = true; |
| 335 | |
| 336 | if (ASIC_IS_AVIVO(rdev)) { |
| 337 | if (rdev->pm.active_crtcs & (1 << 0)) { |
| 338 | stat_crtc1 = RREG32(D1CRTC_STATUS); |
| 339 | if (!(stat_crtc1 & 1)) |
| 340 | in_vbl = false; |
| 341 | } |
| 342 | if (rdev->pm.active_crtcs & (1 << 1)) { |
| 343 | stat_crtc2 = RREG32(D2CRTC_STATUS); |
| 344 | if (!(stat_crtc2 & 1)) |
| 345 | in_vbl = false; |
| 346 | } |
| 347 | } |
| 348 | if (in_vbl == false) |
| 349 | DRM_INFO("not in vbl for pm change %08x %08x at %s\n", stat_crtc1, |
| 350 | stat_crtc2, finish ? "exit" : "entry"); |
| 351 | return in_vbl; |
| 352 | } |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 353 | static void radeon_pm_set_clocks_locked(struct radeon_device *rdev) |
| 354 | { |
| 355 | /*radeon_fence_wait_last(rdev);*/ |
| 356 | switch (rdev->pm.planned_action) { |
| 357 | case PM_ACTION_UPCLOCK: |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 358 | rdev->pm.downclocked = false; |
| 359 | break; |
| 360 | case PM_ACTION_DOWNCLOCK: |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 361 | rdev->pm.downclocked = true; |
| 362 | break; |
| 363 | case PM_ACTION_MINIMUM: |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 364 | break; |
| 365 | case PM_ACTION_NONE: |
| 366 | DRM_ERROR("%s: PM_ACTION_NONE\n", __func__); |
| 367 | break; |
| 368 | } |
Dave Airlie | f735261 | 2010-02-18 15:58:36 +1000 | [diff] [blame] | 369 | |
Alex Deucher | 530079a | 2009-12-23 14:39:36 -0500 | [diff] [blame] | 370 | radeon_set_power_state(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 371 | rdev->pm.planned_action = PM_ACTION_NONE; |
| 372 | } |
| 373 | |
| 374 | static void radeon_pm_set_clocks(struct radeon_device *rdev) |
| 375 | { |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 376 | radeon_get_power_state(rdev, rdev->pm.planned_action); |
| 377 | mutex_lock(&rdev->cp.mutex); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 378 | |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 379 | if (rdev->pm.active_crtcs & (1 << 0)) { |
| 380 | rdev->pm.req_vblank |= (1 << 0); |
| 381 | drm_vblank_get(rdev->ddev, 0); |
| 382 | } |
| 383 | if (rdev->pm.active_crtcs & (1 << 1)) { |
| 384 | rdev->pm.req_vblank |= (1 << 1); |
| 385 | drm_vblank_get(rdev->ddev, 1); |
| 386 | } |
Rafał Miłecki | d0d6cb8 | 2010-03-02 22:06:52 +0100 | [diff] [blame] | 387 | radeon_pm_set_clocks_locked(rdev); |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 388 | if (rdev->pm.req_vblank & (1 << 0)) { |
| 389 | rdev->pm.req_vblank &= ~(1 << 0); |
| 390 | drm_vblank_put(rdev->ddev, 0); |
| 391 | } |
| 392 | if (rdev->pm.req_vblank & (1 << 1)) { |
| 393 | rdev->pm.req_vblank &= ~(1 << 1); |
| 394 | drm_vblank_put(rdev->ddev, 1); |
| 395 | } |
| 396 | |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 397 | mutex_unlock(&rdev->cp.mutex); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | static void radeon_pm_idle_work_handler(struct work_struct *work) |
| 401 | { |
| 402 | struct radeon_device *rdev; |
| 403 | rdev = container_of(work, struct radeon_device, |
| 404 | pm.idle_work.work); |
| 405 | |
| 406 | mutex_lock(&rdev->pm.mutex); |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 407 | if (rdev->pm.state == PM_STATE_ACTIVE) { |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 408 | unsigned long irq_flags; |
| 409 | int not_processed = 0; |
| 410 | |
| 411 | read_lock_irqsave(&rdev->fence_drv.lock, irq_flags); |
| 412 | if (!list_empty(&rdev->fence_drv.emited)) { |
| 413 | struct list_head *ptr; |
| 414 | list_for_each(ptr, &rdev->fence_drv.emited) { |
| 415 | /* count up to 3, that's enought info */ |
| 416 | if (++not_processed >= 3) |
| 417 | break; |
| 418 | } |
| 419 | } |
| 420 | read_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags); |
| 421 | |
| 422 | if (not_processed >= 3) { /* should upclock */ |
| 423 | if (rdev->pm.planned_action == PM_ACTION_DOWNCLOCK) { |
| 424 | rdev->pm.planned_action = PM_ACTION_NONE; |
| 425 | } else if (rdev->pm.planned_action == PM_ACTION_NONE && |
| 426 | rdev->pm.downclocked) { |
| 427 | rdev->pm.planned_action = |
| 428 | PM_ACTION_UPCLOCK; |
| 429 | rdev->pm.action_timeout = jiffies + |
| 430 | msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS); |
| 431 | } |
| 432 | } else if (not_processed == 0) { /* should downclock */ |
| 433 | if (rdev->pm.planned_action == PM_ACTION_UPCLOCK) { |
| 434 | rdev->pm.planned_action = PM_ACTION_NONE; |
| 435 | } else if (rdev->pm.planned_action == PM_ACTION_NONE && |
| 436 | !rdev->pm.downclocked) { |
| 437 | rdev->pm.planned_action = |
| 438 | PM_ACTION_DOWNCLOCK; |
| 439 | rdev->pm.action_timeout = jiffies + |
| 440 | msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS); |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | if (rdev->pm.planned_action != PM_ACTION_NONE && |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 445 | jiffies > rdev->pm.action_timeout) { |
| 446 | radeon_pm_set_clocks(rdev); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | mutex_unlock(&rdev->pm.mutex); |
| 450 | |
| 451 | queue_delayed_work(rdev->wq, &rdev->pm.idle_work, |
| 452 | msecs_to_jiffies(RADEON_IDLE_LOOP_MS)); |
| 453 | } |
| 454 | |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 455 | /* |
| 456 | * Debugfs info |
| 457 | */ |
| 458 | #if defined(CONFIG_DEBUG_FS) |
| 459 | |
| 460 | static int radeon_debugfs_pm_info(struct seq_file *m, void *data) |
| 461 | { |
| 462 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 463 | struct drm_device *dev = node->minor->dev; |
| 464 | struct radeon_device *rdev = dev->dev_private; |
| 465 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 466 | 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] | 467 | seq_printf(m, "default engine clock: %u0 kHz\n", rdev->clock.default_sclk); |
| 468 | seq_printf(m, "current engine clock: %u0 kHz\n", radeon_get_engine_clock(rdev)); |
| 469 | seq_printf(m, "default memory clock: %u0 kHz\n", rdev->clock.default_mclk); |
| 470 | if (rdev->asic->get_memory_clock) |
| 471 | 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] | 472 | if (rdev->asic->get_pcie_lanes) |
| 473 | 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] | 474 | |
| 475 | return 0; |
| 476 | } |
| 477 | |
| 478 | static struct drm_info_list radeon_pm_info_list[] = { |
| 479 | {"radeon_pm_info", radeon_debugfs_pm_info, 0, NULL}, |
| 480 | }; |
| 481 | #endif |
| 482 | |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 483 | static int radeon_debugfs_pm_init(struct radeon_device *rdev) |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 484 | { |
| 485 | #if defined(CONFIG_DEBUG_FS) |
| 486 | return radeon_debugfs_add_files(rdev, radeon_pm_info_list, ARRAY_SIZE(radeon_pm_info_list)); |
| 487 | #else |
| 488 | return 0; |
| 489 | #endif |
| 490 | } |