blob: a61de1f9ff64ec347ae6394d127859e7462b2a20 [file] [log] [blame]
Rafał Miłecki74338742009-11-03 00:53:02 +01001/*
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 Deucher56278a82009-12-28 13:58:44 -050021 * Alex Deucher <alexdeucher@gmail.com>
Rafał Miłecki74338742009-11-03 00:53:02 +010022 */
23#include "drmP.h"
24#include "radeon.h"
Dave Airlief7352612010-02-18 15:58:36 +100025#include "avivod.h"
Rafał Miłecki74338742009-11-03 00:53:02 +010026
Rafał Miłeckic913e232009-12-22 23:02:16 +010027#define RADEON_IDLE_LOOP_MS 100
28#define RADEON_RECLOCK_DELAY_MS 200
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +010029#define RADEON_WAIT_VBLANK_TIMEOUT 200
Alex Deucher2031f772010-04-22 12:52:11 -040030#define RADEON_WAIT_IDLE_TIMEOUT 200
Rafał Miłeckic913e232009-12-22 23:02:16 +010031
Rafał Miłeckic913e232009-12-22 23:02:16 +010032static void radeon_pm_idle_work_handler(struct work_struct *work);
33static int radeon_debugfs_pm_init(struct radeon_device *rdev);
34
Matthew Garrett2aba6312010-04-26 15:45:23 -040035static void radeon_pm_set_clocks(struct radeon_device *rdev, int static_switch)
Alex Deuchera4248162010-04-24 14:50:23 -040036{
Matthew Garrett2aba6312010-04-26 15:45:23 -040037 int i;
38
Alex Deuchera4248162010-04-24 14:50:23 -040039 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
Matthew Garrett2aba6312010-04-26 15:45:23 -040051 if (!static_switch) {
52 for (i = 0; i < rdev->num_crtc; i++) {
53 if (rdev->pm.active_crtcs & (1 << i)) {
54 rdev->pm.req_vblank |= (1 << i);
55 drm_vblank_get(rdev->ddev, i);
56 }
57 }
58 }
59
60 radeon_set_power_state(rdev, static_switch);
Alex Deuchera4248162010-04-24 14:50:23 -040061
Matthew Garrett2aba6312010-04-26 15:45:23 -040062 if (!static_switch) {
63 for (i = 0; i < rdev->num_crtc; i++) {
64 if (rdev->pm.req_vblank & (1 << i)) {
65 rdev->pm.req_vblank &= ~(1 << i);
66 drm_vblank_put(rdev->ddev, i);
67 }
68 }
69 }
70
Alex Deuchera4248162010-04-24 14:50:23 -040071 /* update display watermarks based on new power state */
72 radeon_update_bandwidth_info(rdev);
73 if (rdev->pm.active_crtc_count)
74 radeon_bandwidth_update(rdev);
75
Matthew Garrett2aba6312010-04-26 15:45:23 -040076 rdev->pm.planned_action = PM_ACTION_NONE;
77
Alex Deuchera4248162010-04-24 14:50:23 -040078 mutex_unlock(&rdev->cp.mutex);
79}
80
81static ssize_t radeon_get_power_state_static(struct device *dev,
82 struct device_attribute *attr,
83 char *buf)
84{
85 struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev));
86 struct radeon_device *rdev = ddev->dev_private;
87
88 return snprintf(buf, PAGE_SIZE, "%d.%d\n", rdev->pm.current_power_state_index,
89 rdev->pm.current_clock_mode_index);
90}
91
92static ssize_t radeon_set_power_state_static(struct device *dev,
93 struct device_attribute *attr,
94 const char *buf,
95 size_t count)
96{
97 struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev));
98 struct radeon_device *rdev = ddev->dev_private;
99 int ps, cm;
100
101 if (sscanf(buf, "%u.%u", &ps, &cm) != 2) {
102 DRM_ERROR("Invalid power state!\n");
103 return count;
104 }
105
106 mutex_lock(&rdev->pm.mutex);
107 if ((ps >= 0) && (ps < rdev->pm.num_power_states) &&
108 (cm >= 0) && (cm < rdev->pm.power_state[ps].num_clock_modes)) {
109 if ((rdev->pm.active_crtc_count > 1) &&
110 (rdev->pm.power_state[ps].flags & RADEON_PM_SINGLE_DISPLAY_ONLY)) {
111 DRM_ERROR("Invalid power state for multi-head: %d.%d\n", ps, cm);
112 } else {
113 /* disable dynpm */
114 rdev->pm.state = PM_STATE_DISABLED;
115 rdev->pm.planned_action = PM_ACTION_NONE;
116 rdev->pm.requested_power_state_index = ps;
117 rdev->pm.requested_clock_mode_index = cm;
Matthew Garrett2aba6312010-04-26 15:45:23 -0400118 radeon_pm_set_clocks(rdev, true);
Alex Deuchera4248162010-04-24 14:50:23 -0400119 }
120 } else
121 DRM_ERROR("Invalid power state: %d.%d\n\n", ps, cm);
122 mutex_unlock(&rdev->pm.mutex);
123
124 return count;
125}
126
127static ssize_t radeon_get_dynpm(struct device *dev,
128 struct device_attribute *attr,
129 char *buf)
130{
131 struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev));
132 struct radeon_device *rdev = ddev->dev_private;
133
134 return snprintf(buf, PAGE_SIZE, "%s\n",
135 (rdev->pm.state == PM_STATE_DISABLED) ? "disabled" : "enabled");
136}
137
138static ssize_t radeon_set_dynpm(struct device *dev,
139 struct device_attribute *attr,
140 const char *buf,
141 size_t count)
142{
143 struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev));
144 struct radeon_device *rdev = ddev->dev_private;
145 int tmp = simple_strtoul(buf, NULL, 10);
146
147 if (tmp == 0) {
148 /* update power mode info */
149 radeon_pm_compute_clocks(rdev);
150 /* disable dynpm */
151 mutex_lock(&rdev->pm.mutex);
152 rdev->pm.state = PM_STATE_DISABLED;
153 rdev->pm.planned_action = PM_ACTION_NONE;
154 mutex_unlock(&rdev->pm.mutex);
155 DRM_INFO("radeon: dynamic power management disabled\n");
156 } else if (tmp == 1) {
157 if (rdev->pm.num_power_states > 1) {
158 /* enable dynpm */
159 mutex_lock(&rdev->pm.mutex);
160 rdev->pm.state = PM_STATE_PAUSED;
161 rdev->pm.planned_action = PM_ACTION_DEFAULT;
162 radeon_get_power_state(rdev, rdev->pm.planned_action);
163 mutex_unlock(&rdev->pm.mutex);
164 /* update power mode info */
165 radeon_pm_compute_clocks(rdev);
166 DRM_INFO("radeon: dynamic power management enabled\n");
167 } else
168 DRM_ERROR("dynpm not valid on this system\n");
169 } else
170 DRM_ERROR("Invalid setting: %d\n", tmp);
171
172 return count;
173}
174
175static DEVICE_ATTR(power_state, S_IRUGO | S_IWUSR, radeon_get_power_state_static, radeon_set_power_state_static);
176static DEVICE_ATTR(dynpm, S_IRUGO | S_IWUSR, radeon_get_dynpm, radeon_set_dynpm);
177
178
Rafał Miłeckic913e232009-12-22 23:02:16 +0100179static const char *pm_state_names[4] = {
180 "PM_STATE_DISABLED",
181 "PM_STATE_MINIMUM",
182 "PM_STATE_PAUSED",
183 "PM_STATE_ACTIVE"
184};
Rafał Miłecki74338742009-11-03 00:53:02 +0100185
Alex Deucher0ec0e742009-12-23 13:21:58 -0500186static const char *pm_state_types[5] = {
Alex Deucherd91eeb72010-04-05 15:26:43 -0400187 "",
Alex Deucher0ec0e742009-12-23 13:21:58 -0500188 "Powersave",
189 "Battery",
190 "Balanced",
191 "Performance",
192};
193
Alex Deucher56278a82009-12-28 13:58:44 -0500194static void radeon_print_power_mode_info(struct radeon_device *rdev)
195{
196 int i, j;
197 bool is_default;
198
199 DRM_INFO("%d Power State(s)\n", rdev->pm.num_power_states);
200 for (i = 0; i < rdev->pm.num_power_states; i++) {
Alex Deuchera48b9b42010-04-22 14:03:55 -0400201 if (rdev->pm.default_power_state_index == i)
Alex Deucher56278a82009-12-28 13:58:44 -0500202 is_default = true;
203 else
204 is_default = false;
Alex Deucher0ec0e742009-12-23 13:21:58 -0500205 DRM_INFO("State %d %s %s\n", i,
206 pm_state_types[rdev->pm.power_state[i].type],
207 is_default ? "(default)" : "");
Alex Deucher56278a82009-12-28 13:58:44 -0500208 if ((rdev->flags & RADEON_IS_PCIE) && !(rdev->flags & RADEON_IS_IGP))
Alex Deucher79daedc2010-04-22 14:25:19 -0400209 DRM_INFO("\t%d PCIE Lanes\n", rdev->pm.power_state[i].pcie_lanes);
Alex Deuchera48b9b42010-04-22 14:03:55 -0400210 if (rdev->pm.power_state[i].flags & RADEON_PM_SINGLE_DISPLAY_ONLY)
211 DRM_INFO("\tSingle display only\n");
Alex Deucher56278a82009-12-28 13:58:44 -0500212 DRM_INFO("\t%d Clock Mode(s)\n", rdev->pm.power_state[i].num_clock_modes);
213 for (j = 0; j < rdev->pm.power_state[i].num_clock_modes; j++) {
214 if (rdev->flags & RADEON_IS_IGP)
215 DRM_INFO("\t\t%d engine: %d\n",
216 j,
217 rdev->pm.power_state[i].clock_info[j].sclk * 10);
218 else
219 DRM_INFO("\t\t%d engine/memory: %d/%d\n",
220 j,
221 rdev->pm.power_state[i].clock_info[j].sclk * 10,
222 rdev->pm.power_state[i].clock_info[j].mclk * 10);
223 }
224 }
225}
226
Alex Deucherbae6b562010-04-22 13:38:05 -0400227void radeon_sync_with_vblank(struct radeon_device *rdev)
Rafał Miłeckid0d6cb82010-03-02 22:06:52 +0100228{
229 if (rdev->pm.active_crtcs) {
230 rdev->pm.vblank_sync = false;
231 wait_event_timeout(
232 rdev->irq.vblank_queue, rdev->pm.vblank_sync,
233 msecs_to_jiffies(RADEON_WAIT_VBLANK_TIMEOUT));
234 }
235}
236
Rafał Miłecki74338742009-11-03 00:53:02 +0100237int radeon_pm_init(struct radeon_device *rdev)
238{
Rafał Miłeckic913e232009-12-22 23:02:16 +0100239 rdev->pm.state = PM_STATE_DISABLED;
240 rdev->pm.planned_action = PM_ACTION_NONE;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400241 rdev->pm.can_upclock = true;
242 rdev->pm.can_downclock = true;
Rafał Miłeckic913e232009-12-22 23:02:16 +0100243
Alex Deucher56278a82009-12-28 13:58:44 -0500244 if (rdev->bios) {
245 if (rdev->is_atom_bios)
246 radeon_atombios_get_power_modes(rdev);
247 else
248 radeon_combios_get_power_modes(rdev);
249 radeon_print_power_mode_info(rdev);
250 }
251
Rafał Miłecki74338742009-11-03 00:53:02 +0100252 if (radeon_debugfs_pm_init(rdev)) {
Rafał Miłeckic142c3e2009-11-06 11:38:34 +0100253 DRM_ERROR("Failed to register debugfs file for PM!\n");
Rafał Miłecki74338742009-11-03 00:53:02 +0100254 }
255
Alex Deuchera4248162010-04-24 14:50:23 -0400256 /* where's the best place to put this? */
257 device_create_file(rdev->dev, &dev_attr_power_state);
258 device_create_file(rdev->dev, &dev_attr_dynpm);
259
Rafał Miłeckic913e232009-12-22 23:02:16 +0100260 INIT_DELAYED_WORK(&rdev->pm.idle_work, radeon_pm_idle_work_handler);
261
Alex Deucher90c39052010-03-24 11:32:29 -0400262 if ((radeon_dynpm != -1 && radeon_dynpm) && (rdev->pm.num_power_states > 1)) {
Rafał Miłeckic913e232009-12-22 23:02:16 +0100263 rdev->pm.state = PM_STATE_PAUSED;
264 DRM_INFO("radeon: dynamic power management enabled\n");
265 }
266
267 DRM_INFO("radeon: power management initialized\n");
268
Rafał Miłecki74338742009-11-03 00:53:02 +0100269 return 0;
270}
271
Alex Deucher29fb52c2010-03-11 10:01:17 -0500272void radeon_pm_fini(struct radeon_device *rdev)
273{
Alex Deucher58e21df2010-03-22 13:31:08 -0400274 if (rdev->pm.state != PM_STATE_DISABLED) {
275 /* cancel work */
276 cancel_delayed_work_sync(&rdev->pm.idle_work);
277 /* reset default clocks */
278 rdev->pm.state = PM_STATE_DISABLED;
279 rdev->pm.planned_action = PM_ACTION_DEFAULT;
Matthew Garrett2aba6312010-04-26 15:45:23 -0400280 radeon_pm_set_clocks(rdev, false);
Alex Deuchera4248162010-04-24 14:50:23 -0400281 } else if ((rdev->pm.current_power_state_index !=
282 rdev->pm.default_power_state_index) ||
283 (rdev->pm.current_clock_mode_index != 0)) {
284 rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
285 rdev->pm.requested_clock_mode_index = 0;
286 mutex_lock(&rdev->pm.mutex);
Matthew Garrett2aba6312010-04-26 15:45:23 -0400287 radeon_pm_set_clocks(rdev, true);
Alex Deuchera4248162010-04-24 14:50:23 -0400288 mutex_unlock(&rdev->pm.mutex);
Alex Deucher58e21df2010-03-22 13:31:08 -0400289 }
290
Alex Deuchera4248162010-04-24 14:50:23 -0400291 device_remove_file(rdev->dev, &dev_attr_power_state);
292 device_remove_file(rdev->dev, &dev_attr_dynpm);
293
Alex Deucher29fb52c2010-03-11 10:01:17 -0500294 if (rdev->pm.i2c_bus)
295 radeon_i2c_destroy(rdev->pm.i2c_bus);
296}
297
Rafał Miłeckic913e232009-12-22 23:02:16 +0100298void radeon_pm_compute_clocks(struct radeon_device *rdev)
299{
300 struct drm_device *ddev = rdev->ddev;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400301 struct drm_crtc *crtc;
Rafał Miłeckic913e232009-12-22 23:02:16 +0100302 struct radeon_crtc *radeon_crtc;
Rafał Miłeckic913e232009-12-22 23:02:16 +0100303
304 if (rdev->pm.state == PM_STATE_DISABLED)
305 return;
306
307 mutex_lock(&rdev->pm.mutex);
308
309 rdev->pm.active_crtcs = 0;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400310 rdev->pm.active_crtc_count = 0;
311 list_for_each_entry(crtc,
312 &ddev->mode_config.crtc_list, head) {
313 radeon_crtc = to_radeon_crtc(crtc);
314 if (radeon_crtc->enabled) {
Rafał Miłeckic913e232009-12-22 23:02:16 +0100315 rdev->pm.active_crtcs |= (1 << radeon_crtc->crtc_id);
Alex Deuchera48b9b42010-04-22 14:03:55 -0400316 rdev->pm.active_crtc_count++;
Rafał Miłeckic913e232009-12-22 23:02:16 +0100317 }
318 }
319
Alex Deuchera48b9b42010-04-22 14:03:55 -0400320 if (rdev->pm.active_crtc_count > 1) {
Rafał Miłeckic913e232009-12-22 23:02:16 +0100321 if (rdev->pm.state == PM_STATE_ACTIVE) {
Rafał Miłeckic913e232009-12-22 23:02:16 +0100322 cancel_delayed_work(&rdev->pm.idle_work);
323
324 rdev->pm.state = PM_STATE_PAUSED;
325 rdev->pm.planned_action = PM_ACTION_UPCLOCK;
Matthew Garrett2aba6312010-04-26 15:45:23 -0400326 radeon_pm_set_clocks(rdev, false);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100327
328 DRM_DEBUG("radeon: dynamic power management deactivated\n");
Rafał Miłeckic913e232009-12-22 23:02:16 +0100329 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400330 } else if (rdev->pm.active_crtc_count == 1) {
Rafał Miłeckic913e232009-12-22 23:02:16 +0100331 /* TODO: Increase clocks if needed for current mode */
332
333 if (rdev->pm.state == PM_STATE_MINIMUM) {
334 rdev->pm.state = PM_STATE_ACTIVE;
335 rdev->pm.planned_action = PM_ACTION_UPCLOCK;
Matthew Garrett2aba6312010-04-26 15:45:23 -0400336 radeon_pm_set_clocks(rdev, false);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100337
338 queue_delayed_work(rdev->wq, &rdev->pm.idle_work,
339 msecs_to_jiffies(RADEON_IDLE_LOOP_MS));
Alex Deuchera48b9b42010-04-22 14:03:55 -0400340 } else if (rdev->pm.state == PM_STATE_PAUSED) {
Rafał Miłeckic913e232009-12-22 23:02:16 +0100341 rdev->pm.state = PM_STATE_ACTIVE;
342 queue_delayed_work(rdev->wq, &rdev->pm.idle_work,
343 msecs_to_jiffies(RADEON_IDLE_LOOP_MS));
344 DRM_DEBUG("radeon: dynamic power management activated\n");
345 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400346 } else { /* count == 0 */
Rafał Miłeckic913e232009-12-22 23:02:16 +0100347 if (rdev->pm.state != PM_STATE_MINIMUM) {
348 cancel_delayed_work(&rdev->pm.idle_work);
349
350 rdev->pm.state = PM_STATE_MINIMUM;
351 rdev->pm.planned_action = PM_ACTION_MINIMUM;
Matthew Garrett2aba6312010-04-26 15:45:23 -0400352 radeon_pm_set_clocks(rdev, false);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100353 }
Rafał Miłeckic913e232009-12-22 23:02:16 +0100354 }
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100355
356 mutex_unlock(&rdev->pm.mutex);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100357}
358
Alex Deucherbae6b562010-04-22 13:38:05 -0400359bool radeon_pm_debug_check_in_vbl(struct radeon_device *rdev, bool finish)
Dave Airlief7352612010-02-18 15:58:36 +1000360{
Alex Deucherbae6b562010-04-22 13:38:05 -0400361 u32 stat_crtc = 0;
Dave Airlief7352612010-02-18 15:58:36 +1000362 bool in_vbl = true;
363
Alex Deucherbae6b562010-04-22 13:38:05 -0400364 if (ASIC_IS_DCE4(rdev)) {
Dave Airlief7352612010-02-18 15:58:36 +1000365 if (rdev->pm.active_crtcs & (1 << 0)) {
Alex Deucherbae6b562010-04-22 13:38:05 -0400366 stat_crtc = RREG32(EVERGREEN_CRTC_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
367 if (!(stat_crtc & 1))
Dave Airlief7352612010-02-18 15:58:36 +1000368 in_vbl = false;
369 }
370 if (rdev->pm.active_crtcs & (1 << 1)) {
Alex Deucherbae6b562010-04-22 13:38:05 -0400371 stat_crtc = RREG32(EVERGREEN_CRTC_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
372 if (!(stat_crtc & 1))
373 in_vbl = false;
374 }
375 if (rdev->pm.active_crtcs & (1 << 2)) {
376 stat_crtc = RREG32(EVERGREEN_CRTC_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
377 if (!(stat_crtc & 1))
378 in_vbl = false;
379 }
380 if (rdev->pm.active_crtcs & (1 << 3)) {
381 stat_crtc = RREG32(EVERGREEN_CRTC_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
382 if (!(stat_crtc & 1))
383 in_vbl = false;
384 }
385 if (rdev->pm.active_crtcs & (1 << 4)) {
386 stat_crtc = RREG32(EVERGREEN_CRTC_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
387 if (!(stat_crtc & 1))
388 in_vbl = false;
389 }
390 if (rdev->pm.active_crtcs & (1 << 5)) {
391 stat_crtc = RREG32(EVERGREEN_CRTC_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
392 if (!(stat_crtc & 1))
393 in_vbl = false;
394 }
395 } else if (ASIC_IS_AVIVO(rdev)) {
396 if (rdev->pm.active_crtcs & (1 << 0)) {
397 stat_crtc = RREG32(D1CRTC_STATUS);
398 if (!(stat_crtc & 1))
399 in_vbl = false;
400 }
401 if (rdev->pm.active_crtcs & (1 << 1)) {
402 stat_crtc = RREG32(D2CRTC_STATUS);
403 if (!(stat_crtc & 1))
404 in_vbl = false;
405 }
406 } else {
407 if (rdev->pm.active_crtcs & (1 << 0)) {
408 stat_crtc = RREG32(RADEON_CRTC_STATUS);
409 if (!(stat_crtc & 1))
410 in_vbl = false;
411 }
412 if (rdev->pm.active_crtcs & (1 << 1)) {
413 stat_crtc = RREG32(RADEON_CRTC2_STATUS);
414 if (!(stat_crtc & 1))
Dave Airlief7352612010-02-18 15:58:36 +1000415 in_vbl = false;
416 }
417 }
418 if (in_vbl == false)
Alex Deucherbae6b562010-04-22 13:38:05 -0400419 DRM_INFO("not in vbl for pm change %08x at %s\n", stat_crtc,
420 finish ? "exit" : "entry");
Dave Airlief7352612010-02-18 15:58:36 +1000421 return in_vbl;
422}
Rafał Miłeckic913e232009-12-22 23:02:16 +0100423
424static void radeon_pm_idle_work_handler(struct work_struct *work)
425{
426 struct radeon_device *rdev;
427 rdev = container_of(work, struct radeon_device,
428 pm.idle_work.work);
429
430 mutex_lock(&rdev->pm.mutex);
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100431 if (rdev->pm.state == PM_STATE_ACTIVE) {
Rafał Miłeckic913e232009-12-22 23:02:16 +0100432 unsigned long irq_flags;
433 int not_processed = 0;
434
435 read_lock_irqsave(&rdev->fence_drv.lock, irq_flags);
436 if (!list_empty(&rdev->fence_drv.emited)) {
437 struct list_head *ptr;
438 list_for_each(ptr, &rdev->fence_drv.emited) {
439 /* count up to 3, that's enought info */
440 if (++not_processed >= 3)
441 break;
442 }
443 }
444 read_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
445
446 if (not_processed >= 3) { /* should upclock */
447 if (rdev->pm.planned_action == PM_ACTION_DOWNCLOCK) {
448 rdev->pm.planned_action = PM_ACTION_NONE;
449 } else if (rdev->pm.planned_action == PM_ACTION_NONE &&
Alex Deuchera48b9b42010-04-22 14:03:55 -0400450 rdev->pm.can_upclock) {
Rafał Miłeckic913e232009-12-22 23:02:16 +0100451 rdev->pm.planned_action =
452 PM_ACTION_UPCLOCK;
453 rdev->pm.action_timeout = jiffies +
454 msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS);
455 }
456 } else if (not_processed == 0) { /* should downclock */
457 if (rdev->pm.planned_action == PM_ACTION_UPCLOCK) {
458 rdev->pm.planned_action = PM_ACTION_NONE;
459 } else if (rdev->pm.planned_action == PM_ACTION_NONE &&
Alex Deuchera48b9b42010-04-22 14:03:55 -0400460 rdev->pm.can_downclock) {
Rafał Miłeckic913e232009-12-22 23:02:16 +0100461 rdev->pm.planned_action =
462 PM_ACTION_DOWNCLOCK;
463 rdev->pm.action_timeout = jiffies +
464 msecs_to_jiffies(RADEON_RECLOCK_DELAY_MS);
465 }
466 }
467
468 if (rdev->pm.planned_action != PM_ACTION_NONE &&
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100469 jiffies > rdev->pm.action_timeout) {
Matthew Garrett2aba6312010-04-26 15:45:23 -0400470 radeon_pm_set_clocks(rdev, false);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100471 }
472 }
473 mutex_unlock(&rdev->pm.mutex);
474
475 queue_delayed_work(rdev->wq, &rdev->pm.idle_work,
476 msecs_to_jiffies(RADEON_IDLE_LOOP_MS));
477}
478
Rafał Miłecki74338742009-11-03 00:53:02 +0100479/*
480 * Debugfs info
481 */
482#if defined(CONFIG_DEBUG_FS)
483
484static int radeon_debugfs_pm_info(struct seq_file *m, void *data)
485{
486 struct drm_info_node *node = (struct drm_info_node *) m->private;
487 struct drm_device *dev = node->minor->dev;
488 struct radeon_device *rdev = dev->dev_private;
489
Rafał Miłeckic913e232009-12-22 23:02:16 +0100490 seq_printf(m, "state: %s\n", pm_state_names[rdev->pm.state]);
Rafał Miłecki62340772009-12-15 21:46:58 +0100491 seq_printf(m, "default engine clock: %u0 kHz\n", rdev->clock.default_sclk);
492 seq_printf(m, "current engine clock: %u0 kHz\n", radeon_get_engine_clock(rdev));
493 seq_printf(m, "default memory clock: %u0 kHz\n", rdev->clock.default_mclk);
494 if (rdev->asic->get_memory_clock)
495 seq_printf(m, "current memory clock: %u0 kHz\n", radeon_get_memory_clock(rdev));
Rafał Miłeckiaa5120d2010-02-18 20:24:28 +0000496 if (rdev->asic->get_pcie_lanes)
497 seq_printf(m, "PCIE lanes: %d\n", radeon_get_pcie_lanes(rdev));
Rafał Miłecki74338742009-11-03 00:53:02 +0100498
499 return 0;
500}
501
502static struct drm_info_list radeon_pm_info_list[] = {
503 {"radeon_pm_info", radeon_debugfs_pm_info, 0, NULL},
504};
505#endif
506
Rafał Miłeckic913e232009-12-22 23:02:16 +0100507static int radeon_debugfs_pm_init(struct radeon_device *rdev)
Rafał Miłecki74338742009-11-03 00:53:02 +0100508{
509#if defined(CONFIG_DEBUG_FS)
510 return radeon_debugfs_add_files(rdev, radeon_pm_info_list, ARRAY_SIZE(radeon_pm_info_list));
511#else
512 return 0;
513#endif
514}