Loading...
Note: File does not exist in v3.1.
1/*
2 * Copyright © 2012 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Ben Widawsky <ben@bwidawsk.net>
25 *
26 */
27
28#include <linux/device.h>
29#include <linux/module.h>
30#include <linux/stat.h>
31#include <linux/sysfs.h>
32#include "i915_drv.h"
33
34#ifdef CONFIG_PM
35static u32 calc_residency(struct drm_device *dev, const u32 reg)
36{
37 struct drm_i915_private *dev_priv = dev->dev_private;
38 u64 raw_time; /* 32b value may overflow during fixed point math */
39
40 if (!intel_enable_rc6(dev))
41 return 0;
42
43 raw_time = I915_READ(reg) * 128ULL;
44 return DIV_ROUND_UP_ULL(raw_time, 100000);
45}
46
47static ssize_t
48show_rc6_mask(struct device *dev, struct device_attribute *attr, char *buf)
49{
50 struct drm_minor *dminor = container_of(dev, struct drm_minor, kdev);
51 return snprintf(buf, PAGE_SIZE, "%x", intel_enable_rc6(dminor->dev));
52}
53
54static ssize_t
55show_rc6_ms(struct device *dev, struct device_attribute *attr, char *buf)
56{
57 struct drm_minor *dminor = container_of(dev, struct drm_minor, kdev);
58 u32 rc6_residency = calc_residency(dminor->dev, GEN6_GT_GFX_RC6);
59 return snprintf(buf, PAGE_SIZE, "%u", rc6_residency);
60}
61
62static ssize_t
63show_rc6p_ms(struct device *dev, struct device_attribute *attr, char *buf)
64{
65 struct drm_minor *dminor = container_of(dev, struct drm_minor, kdev);
66 u32 rc6p_residency = calc_residency(dminor->dev, GEN6_GT_GFX_RC6p);
67 return snprintf(buf, PAGE_SIZE, "%u", rc6p_residency);
68}
69
70static ssize_t
71show_rc6pp_ms(struct device *dev, struct device_attribute *attr, char *buf)
72{
73 struct drm_minor *dminor = container_of(dev, struct drm_minor, kdev);
74 u32 rc6pp_residency = calc_residency(dminor->dev, GEN6_GT_GFX_RC6pp);
75 return snprintf(buf, PAGE_SIZE, "%u", rc6pp_residency);
76}
77
78static DEVICE_ATTR(rc6_enable, S_IRUGO, show_rc6_mask, NULL);
79static DEVICE_ATTR(rc6_residency_ms, S_IRUGO, show_rc6_ms, NULL);
80static DEVICE_ATTR(rc6p_residency_ms, S_IRUGO, show_rc6p_ms, NULL);
81static DEVICE_ATTR(rc6pp_residency_ms, S_IRUGO, show_rc6pp_ms, NULL);
82
83static struct attribute *rc6_attrs[] = {
84 &dev_attr_rc6_enable.attr,
85 &dev_attr_rc6_residency_ms.attr,
86 &dev_attr_rc6p_residency_ms.attr,
87 &dev_attr_rc6pp_residency_ms.attr,
88 NULL
89};
90
91static struct attribute_group rc6_attr_group = {
92 .name = power_group_name,
93 .attrs = rc6_attrs
94};
95
96void i915_setup_sysfs(struct drm_device *dev)
97{
98 int ret;
99
100 /* ILK doesn't have any residency information */
101 if (INTEL_INFO(dev)->gen < 6)
102 return;
103
104 ret = sysfs_merge_group(&dev->primary->kdev.kobj, &rc6_attr_group);
105 if (ret)
106 DRM_ERROR("sysfs setup failed\n");
107}
108
109void i915_teardown_sysfs(struct drm_device *dev)
110{
111 sysfs_unmerge_group(&dev->primary->kdev.kobj, &rc6_attr_group);
112}
113#else
114void i915_setup_sysfs(struct drm_device *dev)
115{
116 return;
117}
118
119void i915_teardown_sysfs(struct drm_device *dev)
120{
121 return;
122}
123#endif /* CONFIG_PM */