1 From 63ee41d794d9c555f84205517a68509848988760 Mon Sep 17 00:00:00 2001
2 From: Eric Anholt <eric@anholt.net>
3 Date: Mon, 20 Dec 2010 18:40:06 -0800
4 Subject: [PATCH 08/66] drm/i915, intel_ips: When i915 loads after IPS, make IPS relink to i915.
6 The IPS driver is designed to be able to run detached from i915 and
7 just not enable GPU turbo in that case, in order to avoid module
8 dependencies between the two drivers. This means that we don't know
9 what the load order between the two is going to be, and we had
10 previously only supported IPS after (optionally) i915, but not i915
11 after IPS. If the wrong order was chosen, you'd get no GPU turbo, and
12 something like half the possible graphics performance.
14 Signed-off-by: Eric Anholt <eric@anholt.net>
15 Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
18 drivers/gpu/drm/i915/i915_dma.c | 23 +++++++++++++++++++++++
19 drivers/platform/x86/intel_ips.c | 36 +++++++++++++++++++++++++++++++++---
20 drivers/platform/x86/intel_ips.h | 21 +++++++++++++++++++++
21 3 files changed, 77 insertions(+), 3 deletions(-)
22 create mode 100644 drivers/platform/x86/intel_ips.h
24 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
25 index e680081..cb900dc 100644
26 --- a/drivers/gpu/drm/i915/i915_dma.c
27 +++ b/drivers/gpu/drm/i915/i915_dma.c
31 #include "i915_trace.h"
32 +#include "../../../platform/x86/intel_ips.h"
33 #include <linux/pci.h>
34 #include <linux/vgaarb.h>
35 #include <linux/acpi.h>
36 @@ -1871,6 +1872,26 @@ out_unlock:
37 EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable);
40 + * Tells the intel_ips driver that the i915 driver is now loaded, if
41 + * IPS got loaded first.
43 + * This awkward dance is so that neither module has to depend on the
44 + * other in order for IPS to do the appropriate communication of
45 + * GPU turbo limits to i915.
48 +ips_ping_for_i915_load(void)
52 + link = symbol_get(ips_link_to_i915_driver);
55 + symbol_put(ips_link_to_i915_driver);
60 * i915_driver_load - setup chip and create an initial config
62 * @flags: startup flags
63 @@ -2075,6 +2096,8 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
64 dev_priv->mchdev_lock = &mchdev_lock;
65 spin_unlock(&mchdev_lock);
67 + ips_ping_for_i915_load();
72 diff --git a/drivers/platform/x86/intel_ips.c b/drivers/platform/x86/intel_ips.c
73 index c44a5e8..f0b3ad1 100644
74 --- a/drivers/platform/x86/intel_ips.c
75 +++ b/drivers/platform/x86/intel_ips.c
77 #include <drm/i915_drm.h>
79 #include <asm/processor.h>
80 +#include "intel_ips.h"
82 #define PCI_DEVICE_ID_INTEL_THERMAL_SENSOR 0x3b32
85 #define thm_writel(off, val) writel((val), ips->regmap + (off))
87 static const int IPS_ADJUST_PERIOD = 5000; /* ms */
88 +static bool late_i915_load = false;
90 /* For initial average collection */
91 static const int IPS_SAMPLE_PERIOD = 200; /* ms */
92 @@ -339,6 +341,9 @@ struct ips_driver {
93 u64 orig_turbo_ratios;
97 +ips_gpu_turbo_enabled(struct ips_driver *ips);
100 * ips_cpu_busy - is CPU busy?
101 * @ips: IPS driver struct
102 @@ -517,7 +522,7 @@ static void ips_disable_cpu_turbo(struct ips_driver *ips)
104 static bool ips_gpu_busy(struct ips_driver *ips)
106 - if (!ips->gpu_turbo_enabled)
107 + if (!ips_gpu_turbo_enabled(ips))
110 return ips->gpu_busy();
111 @@ -532,7 +537,7 @@ static bool ips_gpu_busy(struct ips_driver *ips)
113 static void ips_gpu_raise(struct ips_driver *ips)
115 - if (!ips->gpu_turbo_enabled)
116 + if (!ips_gpu_turbo_enabled(ips))
119 if (!ips->gpu_raise())
120 @@ -549,7 +554,7 @@ static void ips_gpu_raise(struct ips_driver *ips)
122 static void ips_gpu_lower(struct ips_driver *ips)
124 - if (!ips->gpu_turbo_enabled)
125 + if (!ips_gpu_turbo_enabled(ips))
128 if (!ips->gpu_lower())
129 @@ -1454,6 +1459,31 @@ out_err:
134 +ips_gpu_turbo_enabled(struct ips_driver *ips)
136 + if (!ips->gpu_busy && late_i915_load) {
137 + if (ips_get_i915_syms(ips)) {
138 + dev_info(&ips->dev->dev,
139 + "i915 driver attached, reenabling gpu turbo\n");
140 + ips->gpu_turbo_enabled = !(thm_readl(THM_HTS) & HTS_GTD_DIS);
144 + return ips->gpu_turbo_enabled;
148 +ips_link_to_i915_driver()
150 + /* We can't cleanly get at the various ips_driver structs from
151 + * this caller (the i915 driver), so just set a flag saying
152 + * that it's time to try getting the symbols again.
154 + late_i915_load = true;
156 +EXPORT_SYMBOL_GPL(ips_link_to_i915_driver);
158 static DEFINE_PCI_DEVICE_TABLE(ips_id_table) = {
159 { PCI_DEVICE(PCI_VENDOR_ID_INTEL,
160 PCI_DEVICE_ID_INTEL_THERMAL_SENSOR), },
161 diff --git a/drivers/platform/x86/intel_ips.h b/drivers/platform/x86/intel_ips.h
163 index 0000000..73299be
165 +++ b/drivers/platform/x86/intel_ips.h
168 + * Copyright (c) 2010 Intel Corporation
170 + * This program is free software; you can redistribute it and/or modify it
171 + * under the terms and conditions of the GNU General Public License,
172 + * version 2, as published by the Free Software Foundation.
174 + * This program is distributed in the hope it will be useful, but WITHOUT
175 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
176 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
179 + * You should have received a copy of the GNU General Public License along with
180 + * this program; if not, write to the Free Software Foundation, Inc.,
181 + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
183 + * The full GNU General Public License is included in this distribution in
184 + * the file called "COPYING".
187 +void ips_link_to_i915_driver(void);