blob: 50d1a71aeddca5cec6ab19a66f6bf118313ef5a6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* i915_drv.c -- i830,i845,i855,i865,i915 driver -*- linux-c -*-
2 */
Dave Airlie0d6aa602006-01-02 20:14:23 +11003/*
Dave Airliebc54fd12005-06-23 22:46:46 +10004 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * All Rights Reserved.
Dave Airliebc54fd12005-06-23 22:46:46 +10007 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
24 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
Dave Airlie0d6aa602006-01-02 20:14:23 +110028 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Jesse Barnese5747e32014-06-12 08:35:47 -070030#include <linux/acpi.h>
Chris Wilson0673ad42016-06-24 14:00:22 +010031#include <linux/console.h>
32#include <linux/device.h>
33#include <linux/oom.h>
34#include <linux/module.h>
35#include <linux/pci.h>
36#include <linux/pm.h>
37#include <linux/pm_runtime.h>
38#include <linux/pnp.h>
39#include <linux/slab.h>
40#include <linux/vgaarb.h>
41#include <linux/vga_switcheroo.h>
42#include <linux/vt.h>
43#include <acpi/video.h>
44
David Howells760285e2012-10-02 18:01:07 +010045#include <drm/drmP.h>
Chris Wilson0673ad42016-06-24 14:00:22 +010046#include <drm/drm_crtc_helper.h>
David Howells760285e2012-10-02 18:01:07 +010047#include <drm/i915_drm.h>
Chris Wilson0673ad42016-06-24 14:00:22 +010048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include "i915_drv.h"
Chris Wilson990bbda2012-07-02 11:51:02 -030050#include "i915_trace.h"
Chris Wilson0673ad42016-06-24 14:00:22 +010051#include "i915_vgpu.h"
Kenneth Graunkef49f0582010-09-11 01:19:14 -070052#include "intel_drv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Kristian Høgsberg112b7152009-01-04 16:55:33 -050054static struct drm_driver driver;
55
Antti Koskipaaa57c7742014-02-04 14:22:24 +020056#define GEN_DEFAULT_PIPEOFFSETS \
57 .pipe_offsets = { PIPE_A_OFFSET, PIPE_B_OFFSET, \
58 PIPE_C_OFFSET, PIPE_EDP_OFFSET }, \
59 .trans_offsets = { TRANSCODER_A_OFFSET, TRANSCODER_B_OFFSET, \
60 TRANSCODER_C_OFFSET, TRANSCODER_EDP_OFFSET }, \
Antti Koskipaaa57c7742014-02-04 14:22:24 +020061 .palette_offsets = { PALETTE_A_OFFSET, PALETTE_B_OFFSET }
62
Rafael Barbalho84fd4f42014-04-28 14:00:42 +030063#define GEN_CHV_PIPEOFFSETS \
64 .pipe_offsets = { PIPE_A_OFFSET, PIPE_B_OFFSET, \
65 CHV_PIPE_C_OFFSET }, \
66 .trans_offsets = { TRANSCODER_A_OFFSET, TRANSCODER_B_OFFSET, \
67 CHV_TRANSCODER_C_OFFSET, }, \
Rafael Barbalho84fd4f42014-04-28 14:00:42 +030068 .palette_offsets = { PALETTE_A_OFFSET, PALETTE_B_OFFSET, \
69 CHV_PALETTE_C_OFFSET }
Antti Koskipaaa57c7742014-02-04 14:22:24 +020070
Ville Syrjälä5efb3e22014-04-09 13:28:53 +030071#define CURSOR_OFFSETS \
72 .cursor_offsets = { CURSOR_A_OFFSET, CURSOR_B_OFFSET, CHV_CURSOR_C_OFFSET }
73
74#define IVB_CURSOR_OFFSETS \
75 .cursor_offsets = { CURSOR_A_OFFSET, IVB_CURSOR_B_OFFSET, IVB_CURSOR_C_OFFSET }
76
Lionel Landwerlin82cf4352016-03-16 10:57:16 +000077#define BDW_COLORS \
78 .color = { .degamma_lut_size = 512, .gamma_lut_size = 512 }
Lionel Landwerlin29dc3732016-03-16 10:57:17 +000079#define CHV_COLORS \
80 .color = { .degamma_lut_size = 65, .gamma_lut_size = 257 }
Lionel Landwerlin82cf4352016-03-16 10:57:16 +000081
Tobias Klauser9a7e8492010-05-20 10:33:46 +020082static const struct intel_device_info intel_i830_info = {
Ben Widawsky7eb552a2013-03-13 14:05:41 -070083 .gen = 2, .is_mobile = 1, .cursor_needs_physical = 1, .num_pipes = 2,
Chris Wilson315781482010-08-12 09:42:51 +010084 .has_overlay = 1, .overlay_needs_physical = 1,
Ben Widawsky73ae4782013-10-15 10:02:57 -070085 .ring_mask = RENDER_RING,
Antti Koskipaaa57c7742014-02-04 14:22:24 +020086 GEN_DEFAULT_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +030087 CURSOR_OFFSETS,
Kristian Høgsbergcfdf1fa2009-12-16 15:16:16 -050088};
89
Tobias Klauser9a7e8492010-05-20 10:33:46 +020090static const struct intel_device_info intel_845g_info = {
Ben Widawsky7eb552a2013-03-13 14:05:41 -070091 .gen = 2, .num_pipes = 1,
Chris Wilson315781482010-08-12 09:42:51 +010092 .has_overlay = 1, .overlay_needs_physical = 1,
Ben Widawsky73ae4782013-10-15 10:02:57 -070093 .ring_mask = RENDER_RING,
Antti Koskipaaa57c7742014-02-04 14:22:24 +020094 GEN_DEFAULT_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +030095 CURSOR_OFFSETS,
Kristian Høgsbergcfdf1fa2009-12-16 15:16:16 -050096};
97
Tobias Klauser9a7e8492010-05-20 10:33:46 +020098static const struct intel_device_info intel_i85x_info = {
Ben Widawsky7eb552a2013-03-13 14:05:41 -070099 .gen = 2, .is_i85x = 1, .is_mobile = 1, .num_pipes = 2,
Adam Jackson5ce8ba72010-04-15 14:03:30 -0400100 .cursor_needs_physical = 1,
Chris Wilson315781482010-08-12 09:42:51 +0100101 .has_overlay = 1, .overlay_needs_physical = 1,
Ville Syrjäläfd70d522013-11-28 17:30:02 +0200102 .has_fbc = 1,
Ben Widawsky73ae4782013-10-15 10:02:57 -0700103 .ring_mask = RENDER_RING,
Antti Koskipaaa57c7742014-02-04 14:22:24 +0200104 GEN_DEFAULT_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +0300105 CURSOR_OFFSETS,
Kristian Høgsbergcfdf1fa2009-12-16 15:16:16 -0500106};
107
Tobias Klauser9a7e8492010-05-20 10:33:46 +0200108static const struct intel_device_info intel_i865g_info = {
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700109 .gen = 2, .num_pipes = 1,
Chris Wilson315781482010-08-12 09:42:51 +0100110 .has_overlay = 1, .overlay_needs_physical = 1,
Ben Widawsky73ae4782013-10-15 10:02:57 -0700111 .ring_mask = RENDER_RING,
Antti Koskipaaa57c7742014-02-04 14:22:24 +0200112 GEN_DEFAULT_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +0300113 CURSOR_OFFSETS,
Kristian Høgsbergcfdf1fa2009-12-16 15:16:16 -0500114};
115
Tobias Klauser9a7e8492010-05-20 10:33:46 +0200116static const struct intel_device_info intel_i915g_info = {
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700117 .gen = 3, .is_i915g = 1, .cursor_needs_physical = 1, .num_pipes = 2,
Chris Wilson315781482010-08-12 09:42:51 +0100118 .has_overlay = 1, .overlay_needs_physical = 1,
Ben Widawsky73ae4782013-10-15 10:02:57 -0700119 .ring_mask = RENDER_RING,
Antti Koskipaaa57c7742014-02-04 14:22:24 +0200120 GEN_DEFAULT_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +0300121 CURSOR_OFFSETS,
Kristian Høgsbergcfdf1fa2009-12-16 15:16:16 -0500122};
Tobias Klauser9a7e8492010-05-20 10:33:46 +0200123static const struct intel_device_info intel_i915gm_info = {
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700124 .gen = 3, .is_mobile = 1, .num_pipes = 2,
Kristian Høgsbergb295d1b2009-12-16 15:16:17 -0500125 .cursor_needs_physical = 1,
Chris Wilson315781482010-08-12 09:42:51 +0100126 .has_overlay = 1, .overlay_needs_physical = 1,
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100127 .supports_tv = 1,
Ville Syrjäläfd70d522013-11-28 17:30:02 +0200128 .has_fbc = 1,
Ben Widawsky73ae4782013-10-15 10:02:57 -0700129 .ring_mask = RENDER_RING,
Antti Koskipaaa57c7742014-02-04 14:22:24 +0200130 GEN_DEFAULT_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +0300131 CURSOR_OFFSETS,
Kristian Høgsbergcfdf1fa2009-12-16 15:16:16 -0500132};
Tobias Klauser9a7e8492010-05-20 10:33:46 +0200133static const struct intel_device_info intel_i945g_info = {
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700134 .gen = 3, .has_hotplug = 1, .cursor_needs_physical = 1, .num_pipes = 2,
Chris Wilson315781482010-08-12 09:42:51 +0100135 .has_overlay = 1, .overlay_needs_physical = 1,
Ben Widawsky73ae4782013-10-15 10:02:57 -0700136 .ring_mask = RENDER_RING,
Antti Koskipaaa57c7742014-02-04 14:22:24 +0200137 GEN_DEFAULT_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +0300138 CURSOR_OFFSETS,
Kristian Høgsbergcfdf1fa2009-12-16 15:16:16 -0500139};
Tobias Klauser9a7e8492010-05-20 10:33:46 +0200140static const struct intel_device_info intel_i945gm_info = {
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700141 .gen = 3, .is_i945gm = 1, .is_mobile = 1, .num_pipes = 2,
Kristian Høgsbergb295d1b2009-12-16 15:16:17 -0500142 .has_hotplug = 1, .cursor_needs_physical = 1,
Chris Wilson315781482010-08-12 09:42:51 +0100143 .has_overlay = 1, .overlay_needs_physical = 1,
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100144 .supports_tv = 1,
Ville Syrjäläfd70d522013-11-28 17:30:02 +0200145 .has_fbc = 1,
Ben Widawsky73ae4782013-10-15 10:02:57 -0700146 .ring_mask = RENDER_RING,
Antti Koskipaaa57c7742014-02-04 14:22:24 +0200147 GEN_DEFAULT_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +0300148 CURSOR_OFFSETS,
Kristian Høgsbergcfdf1fa2009-12-16 15:16:16 -0500149};
150
Tobias Klauser9a7e8492010-05-20 10:33:46 +0200151static const struct intel_device_info intel_i965g_info = {
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700152 .gen = 4, .is_broadwater = 1, .num_pipes = 2,
Chris Wilsonc96c3a8c2010-08-11 09:59:24 +0100153 .has_hotplug = 1,
Chris Wilson315781482010-08-12 09:42:51 +0100154 .has_overlay = 1,
Ben Widawsky73ae4782013-10-15 10:02:57 -0700155 .ring_mask = RENDER_RING,
Antti Koskipaaa57c7742014-02-04 14:22:24 +0200156 GEN_DEFAULT_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +0300157 CURSOR_OFFSETS,
Kristian Høgsbergcfdf1fa2009-12-16 15:16:16 -0500158};
159
Tobias Klauser9a7e8492010-05-20 10:33:46 +0200160static const struct intel_device_info intel_i965gm_info = {
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700161 .gen = 4, .is_crestline = 1, .num_pipes = 2,
Chris Wilsone3c4e5d2010-12-05 16:49:51 +0000162 .is_mobile = 1, .has_fbc = 1, .has_hotplug = 1,
Chris Wilson315781482010-08-12 09:42:51 +0100163 .has_overlay = 1,
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100164 .supports_tv = 1,
Ben Widawsky73ae4782013-10-15 10:02:57 -0700165 .ring_mask = RENDER_RING,
Antti Koskipaaa57c7742014-02-04 14:22:24 +0200166 GEN_DEFAULT_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +0300167 CURSOR_OFFSETS,
Kristian Høgsbergcfdf1fa2009-12-16 15:16:16 -0500168};
169
Tobias Klauser9a7e8492010-05-20 10:33:46 +0200170static const struct intel_device_info intel_g33_info = {
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700171 .gen = 3, .is_g33 = 1, .num_pipes = 2,
Chris Wilsonc96c3a8c2010-08-11 09:59:24 +0100172 .need_gfx_hws = 1, .has_hotplug = 1,
Chris Wilson315781482010-08-12 09:42:51 +0100173 .has_overlay = 1,
Ben Widawsky73ae4782013-10-15 10:02:57 -0700174 .ring_mask = RENDER_RING,
Antti Koskipaaa57c7742014-02-04 14:22:24 +0200175 GEN_DEFAULT_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +0300176 CURSOR_OFFSETS,
Kristian Høgsbergcfdf1fa2009-12-16 15:16:16 -0500177};
178
Tobias Klauser9a7e8492010-05-20 10:33:46 +0200179static const struct intel_device_info intel_g45_info = {
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700180 .gen = 4, .is_g4x = 1, .need_gfx_hws = 1, .num_pipes = 2,
Chris Wilsonc96c3a8c2010-08-11 09:59:24 +0100181 .has_pipe_cxsr = 1, .has_hotplug = 1,
Ben Widawsky73ae4782013-10-15 10:02:57 -0700182 .ring_mask = RENDER_RING | BSD_RING,
Antti Koskipaaa57c7742014-02-04 14:22:24 +0200183 GEN_DEFAULT_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +0300184 CURSOR_OFFSETS,
Kristian Høgsbergcfdf1fa2009-12-16 15:16:16 -0500185};
186
Tobias Klauser9a7e8492010-05-20 10:33:46 +0200187static const struct intel_device_info intel_gm45_info = {
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700188 .gen = 4, .is_g4x = 1, .num_pipes = 2,
Chris Wilsone3c4e5d2010-12-05 16:49:51 +0000189 .is_mobile = 1, .need_gfx_hws = 1, .has_fbc = 1,
Chris Wilsonc96c3a8c2010-08-11 09:59:24 +0100190 .has_pipe_cxsr = 1, .has_hotplug = 1,
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100191 .supports_tv = 1,
Ben Widawsky73ae4782013-10-15 10:02:57 -0700192 .ring_mask = RENDER_RING | BSD_RING,
Antti Koskipaaa57c7742014-02-04 14:22:24 +0200193 GEN_DEFAULT_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +0300194 CURSOR_OFFSETS,
Kristian Høgsbergcfdf1fa2009-12-16 15:16:16 -0500195};
196
Tobias Klauser9a7e8492010-05-20 10:33:46 +0200197static const struct intel_device_info intel_pineview_info = {
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700198 .gen = 3, .is_g33 = 1, .is_pineview = 1, .is_mobile = 1, .num_pipes = 2,
Chris Wilsonc96c3a8c2010-08-11 09:59:24 +0100199 .need_gfx_hws = 1, .has_hotplug = 1,
Chris Wilson315781482010-08-12 09:42:51 +0100200 .has_overlay = 1,
Antti Koskipaaa57c7742014-02-04 14:22:24 +0200201 GEN_DEFAULT_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +0300202 CURSOR_OFFSETS,
Kristian Høgsbergcfdf1fa2009-12-16 15:16:16 -0500203};
204
Tobias Klauser9a7e8492010-05-20 10:33:46 +0200205static const struct intel_device_info intel_ironlake_d_info = {
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700206 .gen = 5, .num_pipes = 2,
Eugeni Dodonov5a117db2012-01-05 09:34:29 -0200207 .need_gfx_hws = 1, .has_hotplug = 1,
Ben Widawsky73ae4782013-10-15 10:02:57 -0700208 .ring_mask = RENDER_RING | BSD_RING,
Antti Koskipaaa57c7742014-02-04 14:22:24 +0200209 GEN_DEFAULT_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +0300210 CURSOR_OFFSETS,
Kristian Høgsbergcfdf1fa2009-12-16 15:16:16 -0500211};
212
Tobias Klauser9a7e8492010-05-20 10:33:46 +0200213static const struct intel_device_info intel_ironlake_m_info = {
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700214 .gen = 5, .is_mobile = 1, .num_pipes = 2,
Chris Wilsone3c4e5d2010-12-05 16:49:51 +0000215 .need_gfx_hws = 1, .has_hotplug = 1,
Jesse Barnesc1a9f042011-05-05 15:24:21 -0700216 .has_fbc = 1,
Ben Widawsky73ae4782013-10-15 10:02:57 -0700217 .ring_mask = RENDER_RING | BSD_RING,
Antti Koskipaaa57c7742014-02-04 14:22:24 +0200218 GEN_DEFAULT_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +0300219 CURSOR_OFFSETS,
Kristian Høgsbergcfdf1fa2009-12-16 15:16:16 -0500220};
221
Tobias Klauser9a7e8492010-05-20 10:33:46 +0200222static const struct intel_device_info intel_sandybridge_d_info = {
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700223 .gen = 6, .num_pipes = 2,
Chris Wilsonc96c3a8c2010-08-11 09:59:24 +0100224 .need_gfx_hws = 1, .has_hotplug = 1,
Ville Syrjäläcbaef0f2013-11-06 23:02:24 +0200225 .has_fbc = 1,
Ben Widawsky73ae4782013-10-15 10:02:57 -0700226 .ring_mask = RENDER_RING | BSD_RING | BLT_RING,
Eugeni Dodonov3d29b842012-01-17 14:43:53 -0200227 .has_llc = 1,
Antti Koskipaaa57c7742014-02-04 14:22:24 +0200228 GEN_DEFAULT_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +0300229 CURSOR_OFFSETS,
Eric Anholtf6e450a2009-11-02 12:08:22 -0800230};
231
Tobias Klauser9a7e8492010-05-20 10:33:46 +0200232static const struct intel_device_info intel_sandybridge_m_info = {
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700233 .gen = 6, .is_mobile = 1, .num_pipes = 2,
Chris Wilsonc96c3a8c2010-08-11 09:59:24 +0100234 .need_gfx_hws = 1, .has_hotplug = 1,
Yuanhan Liu9c04f012010-12-15 15:42:32 +0800235 .has_fbc = 1,
Ben Widawsky73ae4782013-10-15 10:02:57 -0700236 .ring_mask = RENDER_RING | BSD_RING | BLT_RING,
Eugeni Dodonov3d29b842012-01-17 14:43:53 -0200237 .has_llc = 1,
Antti Koskipaaa57c7742014-02-04 14:22:24 +0200238 GEN_DEFAULT_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +0300239 CURSOR_OFFSETS,
Eric Anholta13e4092010-01-07 15:08:18 -0800240};
241
Ben Widawsky219f4fd2013-03-15 11:17:54 -0700242#define GEN7_FEATURES \
243 .gen = 7, .num_pipes = 3, \
244 .need_gfx_hws = 1, .has_hotplug = 1, \
Ville Syrjäläcbaef0f2013-11-06 23:02:24 +0200245 .has_fbc = 1, \
Ben Widawsky73ae4782013-10-15 10:02:57 -0700246 .ring_mask = RENDER_RING | BSD_RING | BLT_RING, \
Wayne Boyer6a8beef2015-12-02 13:28:14 -0800247 .has_llc = 1, \
248 GEN_DEFAULT_PIPEOFFSETS, \
249 IVB_CURSOR_OFFSETS
Ben Widawsky219f4fd2013-03-15 11:17:54 -0700250
Jesse Barnesc76b6152011-04-28 14:32:07 -0700251static const struct intel_device_info intel_ivybridge_d_info = {
Ben Widawsky219f4fd2013-03-15 11:17:54 -0700252 GEN7_FEATURES,
253 .is_ivybridge = 1,
Jesse Barnesc76b6152011-04-28 14:32:07 -0700254};
255
256static const struct intel_device_info intel_ivybridge_m_info = {
Ben Widawsky219f4fd2013-03-15 11:17:54 -0700257 GEN7_FEATURES,
258 .is_ivybridge = 1,
259 .is_mobile = 1,
Jesse Barnesc76b6152011-04-28 14:32:07 -0700260};
261
Ben Widawsky999bcde2013-04-05 13:12:45 -0700262static const struct intel_device_info intel_ivybridge_q_info = {
263 GEN7_FEATURES,
264 .is_ivybridge = 1,
265 .num_pipes = 0, /* legal, last one wins */
266};
267
Wayne Boyer6a8beef2015-12-02 13:28:14 -0800268#define VLV_FEATURES \
269 .gen = 7, .num_pipes = 2, \
270 .need_gfx_hws = 1, .has_hotplug = 1, \
271 .ring_mask = RENDER_RING | BSD_RING | BLT_RING, \
272 .display_mmio_offset = VLV_DISPLAY_BASE, \
273 GEN_DEFAULT_PIPEOFFSETS, \
274 CURSOR_OFFSETS
275
Jesse Barnes70a3eb72012-03-28 13:39:21 -0700276static const struct intel_device_info intel_valleyview_m_info = {
Wayne Boyer6a8beef2015-12-02 13:28:14 -0800277 VLV_FEATURES,
Jesse Barnes70a3eb72012-03-28 13:39:21 -0700278 .is_valleyview = 1,
Wayne Boyer6a8beef2015-12-02 13:28:14 -0800279 .is_mobile = 1,
Jesse Barnes70a3eb72012-03-28 13:39:21 -0700280};
281
282static const struct intel_device_info intel_valleyview_d_info = {
Wayne Boyer6a8beef2015-12-02 13:28:14 -0800283 VLV_FEATURES,
Jesse Barnes70a3eb72012-03-28 13:39:21 -0700284 .is_valleyview = 1,
285};
286
Wayne Boyer6a8beef2015-12-02 13:28:14 -0800287#define HSW_FEATURES \
288 GEN7_FEATURES, \
289 .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING, \
290 .has_ddi = 1, \
291 .has_fpga_dbg = 1
292
Eugeni Dodonov4cae9ae2012-03-29 12:32:18 -0300293static const struct intel_device_info intel_haswell_d_info = {
Wayne Boyer6a8beef2015-12-02 13:28:14 -0800294 HSW_FEATURES,
Ben Widawsky219f4fd2013-03-15 11:17:54 -0700295 .is_haswell = 1,
Eugeni Dodonov4cae9ae2012-03-29 12:32:18 -0300296};
297
298static const struct intel_device_info intel_haswell_m_info = {
Wayne Boyer6a8beef2015-12-02 13:28:14 -0800299 HSW_FEATURES,
Ben Widawsky219f4fd2013-03-15 11:17:54 -0700300 .is_haswell = 1,
301 .is_mobile = 1,
Kristian Høgsbergcfdf1fa2009-12-16 15:16:16 -0500302};
303
Lionel Landwerlin82cf4352016-03-16 10:57:16 +0000304#define BDW_FEATURES \
305 HSW_FEATURES, \
306 BDW_COLORS
307
Ben Widawsky4d4dead2013-11-03 16:47:33 -0800308static const struct intel_device_info intel_broadwell_d_info = {
Lionel Landwerlin82cf4352016-03-16 10:57:16 +0000309 BDW_FEATURES,
Wayne Boyer6a8beef2015-12-02 13:28:14 -0800310 .gen = 8,
Tvrtko Ursulinab0d24a2016-05-10 10:57:05 +0100311 .is_broadwell = 1,
Ben Widawsky4d4dead2013-11-03 16:47:33 -0800312};
313
314static const struct intel_device_info intel_broadwell_m_info = {
Lionel Landwerlin82cf4352016-03-16 10:57:16 +0000315 BDW_FEATURES,
Wayne Boyer6a8beef2015-12-02 13:28:14 -0800316 .gen = 8, .is_mobile = 1,
Tvrtko Ursulinab0d24a2016-05-10 10:57:05 +0100317 .is_broadwell = 1,
Ben Widawsky4d4dead2013-11-03 16:47:33 -0800318};
319
Zhao Yakuifd3c2692014-04-17 10:37:35 +0800320static const struct intel_device_info intel_broadwell_gt3d_info = {
Lionel Landwerlin82cf4352016-03-16 10:57:16 +0000321 BDW_FEATURES,
Wayne Boyer6a8beef2015-12-02 13:28:14 -0800322 .gen = 8,
Tvrtko Ursulinab0d24a2016-05-10 10:57:05 +0100323 .is_broadwell = 1,
Zhao Yakui845f74a2014-04-17 10:37:37 +0800324 .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING,
Zhao Yakuifd3c2692014-04-17 10:37:35 +0800325};
326
327static const struct intel_device_info intel_broadwell_gt3m_info = {
Lionel Landwerlin82cf4352016-03-16 10:57:16 +0000328 BDW_FEATURES,
Wayne Boyer6a8beef2015-12-02 13:28:14 -0800329 .gen = 8, .is_mobile = 1,
Tvrtko Ursulinab0d24a2016-05-10 10:57:05 +0100330 .is_broadwell = 1,
Zhao Yakui845f74a2014-04-17 10:37:37 +0800331 .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING,
Zhao Yakuifd3c2692014-04-17 10:37:35 +0800332};
333
Ville Syrjälä7d87a7f2014-04-09 18:19:04 +0300334static const struct intel_device_info intel_cherryview_info = {
Ville Syrjälä07fddb12014-04-09 13:28:54 +0300335 .gen = 8, .num_pipes = 3,
Ville Syrjälä7d87a7f2014-04-09 18:19:04 +0300336 .need_gfx_hws = 1, .has_hotplug = 1,
337 .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
Wayne Boyer666a4532015-12-09 12:29:35 -0800338 .is_cherryview = 1,
Ville Syrjälä7d87a7f2014-04-09 18:19:04 +0300339 .display_mmio_offset = VLV_DISPLAY_BASE,
Rafael Barbalho84fd4f42014-04-28 14:00:42 +0300340 GEN_CHV_PIPEOFFSETS,
Ville Syrjälä5efb3e22014-04-09 13:28:53 +0300341 CURSOR_OFFSETS,
Lionel Landwerlin29dc3732016-03-16 10:57:17 +0000342 CHV_COLORS,
Ville Syrjälä7d87a7f2014-04-09 18:19:04 +0300343};
344
Damien Lespiau72bbf0a2013-02-13 15:27:37 +0000345static const struct intel_device_info intel_skylake_info = {
Lionel Landwerlin82cf4352016-03-16 10:57:16 +0000346 BDW_FEATURES,
Satheeshakrishna M7201c0b2014-04-02 11:24:50 +0530347 .is_skylake = 1,
Wayne Boyer6a8beef2015-12-02 13:28:14 -0800348 .gen = 9,
Damien Lespiau72bbf0a2013-02-13 15:27:37 +0000349};
350
Damien Lespiau719388e2015-02-04 13:22:27 +0000351static const struct intel_device_info intel_skylake_gt3_info = {
Lionel Landwerlin82cf4352016-03-16 10:57:16 +0000352 BDW_FEATURES,
Damien Lespiau719388e2015-02-04 13:22:27 +0000353 .is_skylake = 1,
Wayne Boyer6a8beef2015-12-02 13:28:14 -0800354 .gen = 9,
Damien Lespiau719388e2015-02-04 13:22:27 +0000355 .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING,
Damien Lespiau719388e2015-02-04 13:22:27 +0000356};
357
Damien Lespiau1347f5b2015-03-17 11:39:27 +0200358static const struct intel_device_info intel_broxton_info = {
359 .is_preliminary = 1,
Rodrigo Vivi7526ac12015-10-27 10:14:54 -0700360 .is_broxton = 1,
Damien Lespiau1347f5b2015-03-17 11:39:27 +0200361 .gen = 9,
362 .need_gfx_hws = 1, .has_hotplug = 1,
363 .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
364 .num_pipes = 3,
365 .has_ddi = 1,
Paulo Zanoni6c908bf2015-08-25 19:03:41 -0300366 .has_fpga_dbg = 1,
Daisy Sunce89db22015-03-17 11:39:28 +0200367 .has_fbc = 1,
arun.siluvery@linux.intel.come015dd62016-06-03 11:14:51 +0100368 .has_pooled_eu = 0,
Damien Lespiau1347f5b2015-03-17 11:39:27 +0200369 GEN_DEFAULT_PIPEOFFSETS,
370 IVB_CURSOR_OFFSETS,
Lionel Landwerlin82cf4352016-03-16 10:57:16 +0000371 BDW_COLORS,
Damien Lespiau1347f5b2015-03-17 11:39:27 +0200372};
373
Rodrigo Vivief11bdb2015-10-28 04:16:45 -0700374static const struct intel_device_info intel_kabylake_info = {
Lionel Landwerlin82cf4352016-03-16 10:57:16 +0000375 BDW_FEATURES,
Rodrigo Vivief11bdb2015-10-28 04:16:45 -0700376 .is_kabylake = 1,
377 .gen = 9,
Rodrigo Vivief11bdb2015-10-28 04:16:45 -0700378};
379
380static const struct intel_device_info intel_kabylake_gt3_info = {
Lionel Landwerlin82cf4352016-03-16 10:57:16 +0000381 BDW_FEATURES,
Rodrigo Vivief11bdb2015-10-28 04:16:45 -0700382 .is_kabylake = 1,
383 .gen = 9,
Rodrigo Vivief11bdb2015-10-28 04:16:45 -0700384 .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING,
Rodrigo Vivief11bdb2015-10-28 04:16:45 -0700385};
386
Jesse Barnesa0a18072013-07-26 13:32:51 -0700387/*
388 * Make sure any device matches here are from most specific to most
389 * general. For example, since the Quanta match is based on the subsystem
390 * and subvendor IDs, we need it to come before the more general IVB
391 * PCI ID matches, otherwise we'll use the wrong info struct above.
392 */
Jani Nikula3cb27f32015-10-28 19:33:09 +0200393static const struct pci_device_id pciidlist[] = {
394 INTEL_I830_IDS(&intel_i830_info),
395 INTEL_I845G_IDS(&intel_845g_info),
396 INTEL_I85X_IDS(&intel_i85x_info),
397 INTEL_I865G_IDS(&intel_i865g_info),
398 INTEL_I915G_IDS(&intel_i915g_info),
399 INTEL_I915GM_IDS(&intel_i915gm_info),
400 INTEL_I945G_IDS(&intel_i945g_info),
401 INTEL_I945GM_IDS(&intel_i945gm_info),
402 INTEL_I965G_IDS(&intel_i965g_info),
403 INTEL_G33_IDS(&intel_g33_info),
404 INTEL_I965GM_IDS(&intel_i965gm_info),
405 INTEL_GM45_IDS(&intel_gm45_info),
406 INTEL_G45_IDS(&intel_g45_info),
407 INTEL_PINEVIEW_IDS(&intel_pineview_info),
408 INTEL_IRONLAKE_D_IDS(&intel_ironlake_d_info),
409 INTEL_IRONLAKE_M_IDS(&intel_ironlake_m_info),
410 INTEL_SNB_D_IDS(&intel_sandybridge_d_info),
411 INTEL_SNB_M_IDS(&intel_sandybridge_m_info),
412 INTEL_IVB_Q_IDS(&intel_ivybridge_q_info), /* must be first IVB */
413 INTEL_IVB_M_IDS(&intel_ivybridge_m_info),
414 INTEL_IVB_D_IDS(&intel_ivybridge_d_info),
415 INTEL_HSW_D_IDS(&intel_haswell_d_info),
416 INTEL_HSW_M_IDS(&intel_haswell_m_info),
417 INTEL_VLV_M_IDS(&intel_valleyview_m_info),
418 INTEL_VLV_D_IDS(&intel_valleyview_d_info),
419 INTEL_BDW_GT12M_IDS(&intel_broadwell_m_info),
420 INTEL_BDW_GT12D_IDS(&intel_broadwell_d_info),
421 INTEL_BDW_GT3M_IDS(&intel_broadwell_gt3m_info),
422 INTEL_BDW_GT3D_IDS(&intel_broadwell_gt3d_info),
423 INTEL_CHV_IDS(&intel_cherryview_info),
424 INTEL_SKL_GT1_IDS(&intel_skylake_info),
425 INTEL_SKL_GT2_IDS(&intel_skylake_info),
426 INTEL_SKL_GT3_IDS(&intel_skylake_gt3_info),
Mika Kuoppala15620202015-11-06 14:11:16 +0200427 INTEL_SKL_GT4_IDS(&intel_skylake_gt3_info),
Jani Nikula3cb27f32015-10-28 19:33:09 +0200428 INTEL_BXT_IDS(&intel_broxton_info),
Deepak Sd97044b2015-10-28 12:19:51 -0700429 INTEL_KBL_GT1_IDS(&intel_kabylake_info),
430 INTEL_KBL_GT2_IDS(&intel_kabylake_info),
431 INTEL_KBL_GT3_IDS(&intel_kabylake_gt3_info),
Deepak S8b10c0c2015-10-28 12:21:12 -0700432 INTEL_KBL_GT4_IDS(&intel_kabylake_gt3_info),
Kristian Høgsberg49ae35f2009-12-16 15:16:15 -0500433 {0, 0, 0}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434};
Jesse Barnes79e53942008-11-07 14:24:08 -0800435MODULE_DEVICE_TABLE(pci, pciidlist);
Jesse Barnes79e53942008-11-07 14:24:08 -0800436
Chris Wilson0673ad42016-06-24 14:00:22 +0100437static unsigned int i915_load_fail_count;
438
439bool __i915_inject_load_failure(const char *func, int line)
440{
441 if (i915_load_fail_count >= i915.inject_load_failure)
442 return false;
443
444 if (++i915_load_fail_count == i915.inject_load_failure) {
445 DRM_INFO("Injecting failure at checkpoint %u [%s:%d]\n",
446 i915.inject_load_failure, func, line);
447 return true;
448 }
449
450 return false;
451}
452
453#define FDO_BUG_URL "https://bugs.freedesktop.org/enter_bug.cgi?product=DRI"
454#define FDO_BUG_MSG "Please file a bug at " FDO_BUG_URL " against DRM/Intel " \
455 "providing the dmesg log by booting with drm.debug=0xf"
456
457void
458__i915_printk(struct drm_i915_private *dev_priv, const char *level,
459 const char *fmt, ...)
460{
461 static bool shown_bug_once;
462 struct device *dev = dev_priv->dev->dev;
463 bool is_error = level[1] <= KERN_ERR[1];
464 bool is_debug = level[1] == KERN_DEBUG[1];
465 struct va_format vaf;
466 va_list args;
467
468 if (is_debug && !(drm_debug & DRM_UT_DRIVER))
469 return;
470
471 va_start(args, fmt);
472
473 vaf.fmt = fmt;
474 vaf.va = &args;
475
476 dev_printk(level, dev, "[" DRM_NAME ":%ps] %pV",
477 __builtin_return_address(0), &vaf);
478
479 if (is_error && !shown_bug_once) {
480 dev_notice(dev, "%s", FDO_BUG_MSG);
481 shown_bug_once = true;
482 }
483
484 va_end(args);
485}
486
487static bool i915_error_injected(struct drm_i915_private *dev_priv)
488{
489 return i915.inject_load_failure &&
490 i915_load_fail_count == i915.inject_load_failure;
491}
492
493#define i915_load_error(dev_priv, fmt, ...) \
494 __i915_printk(dev_priv, \
495 i915_error_injected(dev_priv) ? KERN_DEBUG : KERN_ERR, \
496 fmt, ##__VA_ARGS__)
497
498
Robert Beckett30c964a2015-08-28 13:10:22 +0100499static enum intel_pch intel_virt_detect_pch(struct drm_device *dev)
500{
501 enum intel_pch ret = PCH_NOP;
502
503 /*
504 * In a virtualized passthrough environment we can be in a
505 * setup where the ISA bridge is not able to be passed through.
506 * In this case, a south bridge can be emulated and we have to
507 * make an educated guess as to which PCH is really there.
508 */
509
510 if (IS_GEN5(dev)) {
511 ret = PCH_IBX;
512 DRM_DEBUG_KMS("Assuming Ibex Peak PCH\n");
513 } else if (IS_GEN6(dev) || IS_IVYBRIDGE(dev)) {
514 ret = PCH_CPT;
515 DRM_DEBUG_KMS("Assuming CouarPoint PCH\n");
516 } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
517 ret = PCH_LPT;
518 DRM_DEBUG_KMS("Assuming LynxPoint PCH\n");
Rodrigo Vivief11bdb2015-10-28 04:16:45 -0700519 } else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
Robert Beckett30c964a2015-08-28 13:10:22 +0100520 ret = PCH_SPT;
521 DRM_DEBUG_KMS("Assuming SunrisePoint PCH\n");
522 }
523
524 return ret;
525}
526
Chris Wilson0673ad42016-06-24 14:00:22 +0100527static void intel_detect_pch(struct drm_device *dev)
Zhenyu Wang3bad0782010-04-07 16:15:53 +0800528{
529 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deakbcdb72a2014-02-14 20:23:54 +0200530 struct pci_dev *pch = NULL;
Zhenyu Wang3bad0782010-04-07 16:15:53 +0800531
Ben Widawskyce1bb322013-04-05 13:12:44 -0700532 /* In all current cases, num_pipes is equivalent to the PCH_NOP setting
533 * (which really amounts to a PCH but no South Display).
534 */
535 if (INTEL_INFO(dev)->num_pipes == 0) {
536 dev_priv->pch_type = PCH_NOP;
Ben Widawskyce1bb322013-04-05 13:12:44 -0700537 return;
538 }
539
Zhenyu Wang3bad0782010-04-07 16:15:53 +0800540 /*
541 * The reason to probe ISA bridge instead of Dev31:Fun0 is to
542 * make graphics device passthrough work easy for VMM, that only
543 * need to expose ISA bridge to let driver know the real hardware
544 * underneath. This is a requirement from virtualization team.
Rui Guo6a9c4b32013-06-19 21:10:23 +0800545 *
546 * In some virtualized environments (e.g. XEN), there is irrelevant
547 * ISA bridge in the system. To work reliably, we should scan trhough
548 * all the ISA bridge devices and check for the first match, instead
549 * of only checking the first one.
Zhenyu Wang3bad0782010-04-07 16:15:53 +0800550 */
Imre Deakbcdb72a2014-02-14 20:23:54 +0200551 while ((pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, pch))) {
Zhenyu Wang3bad0782010-04-07 16:15:53 +0800552 if (pch->vendor == PCI_VENDOR_ID_INTEL) {
Imre Deakbcdb72a2014-02-14 20:23:54 +0200553 unsigned short id = pch->device & INTEL_PCH_DEVICE_ID_MASK;
Paulo Zanoni17a303e2012-11-20 15:12:07 -0200554 dev_priv->pch_id = id;
Zhenyu Wang3bad0782010-04-07 16:15:53 +0800555
Jesse Barnes90711d52011-04-28 14:48:02 -0700556 if (id == INTEL_PCH_IBX_DEVICE_ID_TYPE) {
557 dev_priv->pch_type = PCH_IBX;
558 DRM_DEBUG_KMS("Found Ibex Peak PCH\n");
Daniel Vetter7fcb83c2012-10-31 22:52:27 +0100559 WARN_ON(!IS_GEN5(dev));
Jesse Barnes90711d52011-04-28 14:48:02 -0700560 } else if (id == INTEL_PCH_CPT_DEVICE_ID_TYPE) {
Zhenyu Wang3bad0782010-04-07 16:15:53 +0800561 dev_priv->pch_type = PCH_CPT;
562 DRM_DEBUG_KMS("Found CougarPoint PCH\n");
Daniel Vetter7fcb83c2012-10-31 22:52:27 +0100563 WARN_ON(!(IS_GEN6(dev) || IS_IVYBRIDGE(dev)));
Jesse Barnesc7925132011-04-07 12:33:56 -0700564 } else if (id == INTEL_PCH_PPT_DEVICE_ID_TYPE) {
565 /* PantherPoint is CPT compatible */
566 dev_priv->pch_type = PCH_CPT;
Jani Nikula492ab662013-10-01 12:12:33 +0300567 DRM_DEBUG_KMS("Found PantherPoint PCH\n");
Daniel Vetter7fcb83c2012-10-31 22:52:27 +0100568 WARN_ON(!(IS_GEN6(dev) || IS_IVYBRIDGE(dev)));
Eugeni Dodonoveb877eb2012-03-29 12:32:20 -0300569 } else if (id == INTEL_PCH_LPT_DEVICE_ID_TYPE) {
570 dev_priv->pch_type = PCH_LPT;
571 DRM_DEBUG_KMS("Found LynxPoint PCH\n");
Rodrigo Vivia35cc9d02015-01-21 10:33:53 -0800572 WARN_ON(!IS_HASWELL(dev) && !IS_BROADWELL(dev));
573 WARN_ON(IS_HSW_ULT(dev) || IS_BDW_ULT(dev));
Ben Widawskye76e0632013-11-07 21:40:41 -0800574 } else if (id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
575 dev_priv->pch_type = PCH_LPT;
576 DRM_DEBUG_KMS("Found LynxPoint LP PCH\n");
Rodrigo Vivia35cc9d02015-01-21 10:33:53 -0800577 WARN_ON(!IS_HASWELL(dev) && !IS_BROADWELL(dev));
578 WARN_ON(!IS_HSW_ULT(dev) && !IS_BDW_ULT(dev));
Satheeshakrishna Me7e7ea22014-04-09 11:08:57 +0530579 } else if (id == INTEL_PCH_SPT_DEVICE_ID_TYPE) {
580 dev_priv->pch_type = PCH_SPT;
581 DRM_DEBUG_KMS("Found SunrisePoint PCH\n");
Rodrigo Vivief11bdb2015-10-28 04:16:45 -0700582 WARN_ON(!IS_SKYLAKE(dev) &&
583 !IS_KABYLAKE(dev));
Satheeshakrishna Me7e7ea22014-04-09 11:08:57 +0530584 } else if (id == INTEL_PCH_SPT_LP_DEVICE_ID_TYPE) {
585 dev_priv->pch_type = PCH_SPT;
586 DRM_DEBUG_KMS("Found SunrisePoint LP PCH\n");
Rodrigo Vivief11bdb2015-10-28 04:16:45 -0700587 WARN_ON(!IS_SKYLAKE(dev) &&
588 !IS_KABYLAKE(dev));
Gerd Hoffmann39bfcd522015-11-26 12:03:51 +0100589 } else if ((id == INTEL_PCH_P2X_DEVICE_ID_TYPE) ||
Jesse Barnes1844a662016-03-16 13:31:30 -0700590 (id == INTEL_PCH_P3X_DEVICE_ID_TYPE) ||
Gerd Hoffmannf2e30512016-01-25 12:02:28 +0100591 ((id == INTEL_PCH_QEMU_DEVICE_ID_TYPE) &&
Gerd Hoffmann94bb4892016-06-13 14:38:56 +0200592 pch->subsystem_vendor ==
593 PCI_SUBVENDOR_ID_REDHAT_QUMRANET &&
594 pch->subsystem_device ==
595 PCI_SUBDEVICE_ID_QEMU)) {
Robert Beckett30c964a2015-08-28 13:10:22 +0100596 dev_priv->pch_type = intel_virt_detect_pch(dev);
Imre Deakbcdb72a2014-02-14 20:23:54 +0200597 } else
598 continue;
599
Rui Guo6a9c4b32013-06-19 21:10:23 +0800600 break;
Zhenyu Wang3bad0782010-04-07 16:15:53 +0800601 }
Zhenyu Wang3bad0782010-04-07 16:15:53 +0800602 }
Rui Guo6a9c4b32013-06-19 21:10:23 +0800603 if (!pch)
Imre Deakbcdb72a2014-02-14 20:23:54 +0200604 DRM_DEBUG_KMS("No PCH found.\n");
605
606 pci_dev_put(pch);
Zhenyu Wang3bad0782010-04-07 16:15:53 +0800607}
608
Chris Wilsonc0336662016-05-06 15:40:21 +0100609bool i915_semaphore_is_enabled(struct drm_i915_private *dev_priv)
Ben Widawsky2911a352012-04-05 14:47:36 -0700610{
Chris Wilsonc0336662016-05-06 15:40:21 +0100611 if (INTEL_GEN(dev_priv) < 6)
Daniel Vettera08acaf2013-12-17 09:56:53 +0100612 return false;
Ben Widawsky2911a352012-04-05 14:47:36 -0700613
Jani Nikulad330a952014-01-21 11:24:25 +0200614 if (i915.semaphores >= 0)
615 return i915.semaphores;
Ben Widawsky2911a352012-04-05 14:47:36 -0700616
Oscar Mateo71386ef2014-07-24 17:04:44 +0100617 /* TODO: make semaphores and Execlists play nicely together */
618 if (i915.enable_execlists)
619 return false;
620
Daniel Vetter59de3292012-04-02 20:48:43 +0200621#ifdef CONFIG_INTEL_IOMMU
Ben Widawsky2911a352012-04-05 14:47:36 -0700622 /* Enable semaphores on SNB when IO remapping is off */
Chris Wilsonc0336662016-05-06 15:40:21 +0100623 if (IS_GEN6(dev_priv) && intel_iommu_gfx_mapped)
Daniel Vetter59de3292012-04-02 20:48:43 +0200624 return false;
625#endif
Ben Widawsky2911a352012-04-05 14:47:36 -0700626
Daniel Vettera08acaf2013-12-17 09:56:53 +0100627 return true;
Ben Widawsky2911a352012-04-05 14:47:36 -0700628}
629
Chris Wilson0673ad42016-06-24 14:00:22 +0100630static int i915_getparam(struct drm_device *dev, void *data,
631 struct drm_file *file_priv)
632{
633 struct drm_i915_private *dev_priv = dev->dev_private;
634 drm_i915_getparam_t *param = data;
635 int value;
636
637 switch (param->param) {
638 case I915_PARAM_IRQ_ACTIVE:
639 case I915_PARAM_ALLOW_BATCHBUFFER:
640 case I915_PARAM_LAST_DISPATCH:
641 /* Reject all old ums/dri params. */
642 return -ENODEV;
643 case I915_PARAM_CHIPSET_ID:
644 value = dev->pdev->device;
645 break;
646 case I915_PARAM_REVISION:
647 value = dev->pdev->revision;
648 break;
649 case I915_PARAM_HAS_GEM:
650 value = 1;
651 break;
652 case I915_PARAM_NUM_FENCES_AVAIL:
653 value = dev_priv->num_fence_regs;
654 break;
655 case I915_PARAM_HAS_OVERLAY:
656 value = dev_priv->overlay ? 1 : 0;
657 break;
658 case I915_PARAM_HAS_PAGEFLIPPING:
659 value = 1;
660 break;
661 case I915_PARAM_HAS_EXECBUF2:
662 /* depends on GEM */
663 value = 1;
664 break;
665 case I915_PARAM_HAS_BSD:
666 value = intel_engine_initialized(&dev_priv->engine[VCS]);
667 break;
668 case I915_PARAM_HAS_BLT:
669 value = intel_engine_initialized(&dev_priv->engine[BCS]);
670 break;
671 case I915_PARAM_HAS_VEBOX:
672 value = intel_engine_initialized(&dev_priv->engine[VECS]);
673 break;
674 case I915_PARAM_HAS_BSD2:
675 value = intel_engine_initialized(&dev_priv->engine[VCS2]);
676 break;
677 case I915_PARAM_HAS_RELAXED_FENCING:
678 value = 1;
679 break;
680 case I915_PARAM_HAS_COHERENT_RINGS:
681 value = 1;
682 break;
683 case I915_PARAM_HAS_EXEC_CONSTANTS:
684 value = INTEL_INFO(dev)->gen >= 4;
685 break;
686 case I915_PARAM_HAS_RELAXED_DELTA:
687 value = 1;
688 break;
689 case I915_PARAM_HAS_GEN7_SOL_RESET:
690 value = 1;
691 break;
692 case I915_PARAM_HAS_LLC:
693 value = HAS_LLC(dev);
694 break;
695 case I915_PARAM_HAS_WT:
696 value = HAS_WT(dev);
697 break;
698 case I915_PARAM_HAS_ALIASING_PPGTT:
699 value = USES_PPGTT(dev);
700 break;
701 case I915_PARAM_HAS_WAIT_TIMEOUT:
702 value = 1;
703 break;
704 case I915_PARAM_HAS_SEMAPHORES:
705 value = i915_semaphore_is_enabled(dev_priv);
706 break;
707 case I915_PARAM_HAS_PRIME_VMAP_FLUSH:
708 value = 1;
709 break;
710 case I915_PARAM_HAS_SECURE_BATCHES:
711 value = capable(CAP_SYS_ADMIN);
712 break;
713 case I915_PARAM_HAS_PINNED_BATCHES:
714 value = 1;
715 break;
716 case I915_PARAM_HAS_EXEC_NO_RELOC:
717 value = 1;
718 break;
719 case I915_PARAM_HAS_EXEC_HANDLE_LUT:
720 value = 1;
721 break;
722 case I915_PARAM_CMD_PARSER_VERSION:
723 value = i915_cmd_parser_get_version(dev_priv);
724 break;
725 case I915_PARAM_HAS_COHERENT_PHYS_GTT:
726 value = 1;
727 break;
728 case I915_PARAM_MMAP_VERSION:
729 value = 1;
730 break;
731 case I915_PARAM_SUBSLICE_TOTAL:
732 value = INTEL_INFO(dev)->subslice_total;
733 if (!value)
734 return -ENODEV;
735 break;
736 case I915_PARAM_EU_TOTAL:
737 value = INTEL_INFO(dev)->eu_total;
738 if (!value)
739 return -ENODEV;
740 break;
741 case I915_PARAM_HAS_GPU_RESET:
742 value = i915.enable_hangcheck && intel_has_gpu_reset(dev_priv);
743 break;
744 case I915_PARAM_HAS_RESOURCE_STREAMER:
745 value = HAS_RESOURCE_STREAMER(dev);
746 break;
747 case I915_PARAM_HAS_EXEC_SOFTPIN:
748 value = 1;
749 break;
750 default:
751 DRM_DEBUG("Unknown parameter %d\n", param->param);
752 return -EINVAL;
753 }
754
Chris Wilsondda33002016-06-24 14:00:23 +0100755 if (put_user(value, param->value))
Chris Wilson0673ad42016-06-24 14:00:22 +0100756 return -EFAULT;
Chris Wilson0673ad42016-06-24 14:00:22 +0100757
758 return 0;
759}
760
761static int i915_get_bridge_dev(struct drm_device *dev)
762{
763 struct drm_i915_private *dev_priv = dev->dev_private;
764
765 dev_priv->bridge_dev = pci_get_bus_and_slot(0, PCI_DEVFN(0, 0));
766 if (!dev_priv->bridge_dev) {
767 DRM_ERROR("bridge device not found\n");
768 return -1;
769 }
770 return 0;
771}
772
773/* Allocate space for the MCH regs if needed, return nonzero on error */
774static int
775intel_alloc_mchbar_resource(struct drm_device *dev)
776{
777 struct drm_i915_private *dev_priv = dev->dev_private;
778 int reg = INTEL_INFO(dev)->gen >= 4 ? MCHBAR_I965 : MCHBAR_I915;
779 u32 temp_lo, temp_hi = 0;
780 u64 mchbar_addr;
781 int ret;
782
783 if (INTEL_INFO(dev)->gen >= 4)
784 pci_read_config_dword(dev_priv->bridge_dev, reg + 4, &temp_hi);
785 pci_read_config_dword(dev_priv->bridge_dev, reg, &temp_lo);
786 mchbar_addr = ((u64)temp_hi << 32) | temp_lo;
787
788 /* If ACPI doesn't have it, assume we need to allocate it ourselves */
789#ifdef CONFIG_PNP
790 if (mchbar_addr &&
791 pnp_range_reserved(mchbar_addr, mchbar_addr + MCHBAR_SIZE))
792 return 0;
793#endif
794
795 /* Get some space for it */
796 dev_priv->mch_res.name = "i915 MCHBAR";
797 dev_priv->mch_res.flags = IORESOURCE_MEM;
798 ret = pci_bus_alloc_resource(dev_priv->bridge_dev->bus,
799 &dev_priv->mch_res,
800 MCHBAR_SIZE, MCHBAR_SIZE,
801 PCIBIOS_MIN_MEM,
802 0, pcibios_align_resource,
803 dev_priv->bridge_dev);
804 if (ret) {
805 DRM_DEBUG_DRIVER("failed bus alloc: %d\n", ret);
806 dev_priv->mch_res.start = 0;
807 return ret;
808 }
809
810 if (INTEL_INFO(dev)->gen >= 4)
811 pci_write_config_dword(dev_priv->bridge_dev, reg + 4,
812 upper_32_bits(dev_priv->mch_res.start));
813
814 pci_write_config_dword(dev_priv->bridge_dev, reg,
815 lower_32_bits(dev_priv->mch_res.start));
816 return 0;
817}
818
819/* Setup MCHBAR if possible, return true if we should disable it again */
820static void
821intel_setup_mchbar(struct drm_device *dev)
822{
823 struct drm_i915_private *dev_priv = dev->dev_private;
824 int mchbar_reg = INTEL_INFO(dev)->gen >= 4 ? MCHBAR_I965 : MCHBAR_I915;
825 u32 temp;
826 bool enabled;
827
828 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
829 return;
830
831 dev_priv->mchbar_need_disable = false;
832
833 if (IS_I915G(dev) || IS_I915GM(dev)) {
834 pci_read_config_dword(dev_priv->bridge_dev, DEVEN, &temp);
835 enabled = !!(temp & DEVEN_MCHBAR_EN);
836 } else {
837 pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp);
838 enabled = temp & 1;
839 }
840
841 /* If it's already enabled, don't have to do anything */
842 if (enabled)
843 return;
844
845 if (intel_alloc_mchbar_resource(dev))
846 return;
847
848 dev_priv->mchbar_need_disable = true;
849
850 /* Space is allocated or reserved, so enable it. */
851 if (IS_I915G(dev) || IS_I915GM(dev)) {
852 pci_write_config_dword(dev_priv->bridge_dev, DEVEN,
853 temp | DEVEN_MCHBAR_EN);
854 } else {
855 pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp);
856 pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp | 1);
857 }
858}
859
860static void
861intel_teardown_mchbar(struct drm_device *dev)
862{
863 struct drm_i915_private *dev_priv = dev->dev_private;
864 int mchbar_reg = INTEL_INFO(dev)->gen >= 4 ? MCHBAR_I965 : MCHBAR_I915;
865
866 if (dev_priv->mchbar_need_disable) {
867 if (IS_I915G(dev) || IS_I915GM(dev)) {
868 u32 deven_val;
869
870 pci_read_config_dword(dev_priv->bridge_dev, DEVEN,
871 &deven_val);
872 deven_val &= ~DEVEN_MCHBAR_EN;
873 pci_write_config_dword(dev_priv->bridge_dev, DEVEN,
874 deven_val);
875 } else {
876 u32 mchbar_val;
877
878 pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg,
879 &mchbar_val);
880 mchbar_val &= ~1;
881 pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg,
882 mchbar_val);
883 }
884 }
885
886 if (dev_priv->mch_res.start)
887 release_resource(&dev_priv->mch_res);
888}
889
890/* true = enable decode, false = disable decoder */
891static unsigned int i915_vga_set_decode(void *cookie, bool state)
892{
893 struct drm_device *dev = cookie;
894
895 intel_modeset_vga_set_state(dev, state);
896 if (state)
897 return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
898 VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
899 else
900 return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
901}
902
903static void i915_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state)
904{
905 struct drm_device *dev = pci_get_drvdata(pdev);
906 pm_message_t pmm = { .event = PM_EVENT_SUSPEND };
907
908 if (state == VGA_SWITCHEROO_ON) {
909 pr_info("switched on\n");
910 dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
911 /* i915 resume handler doesn't set to D0 */
912 pci_set_power_state(dev->pdev, PCI_D0);
913 i915_resume_switcheroo(dev);
914 dev->switch_power_state = DRM_SWITCH_POWER_ON;
915 } else {
916 pr_info("switched off\n");
917 dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
918 i915_suspend_switcheroo(dev, pmm);
919 dev->switch_power_state = DRM_SWITCH_POWER_OFF;
920 }
921}
922
923static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
924{
925 struct drm_device *dev = pci_get_drvdata(pdev);
926
927 /*
928 * FIXME: open_count is protected by drm_global_mutex but that would lead to
929 * locking inversion with the driver load path. And the access here is
930 * completely racy anyway. So don't bother with locking for now.
931 */
932 return dev->open_count == 0;
933}
934
935static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
936 .set_gpu_state = i915_switcheroo_set_state,
937 .reprobe = NULL,
938 .can_switch = i915_switcheroo_can_switch,
939};
940
941static void i915_gem_fini(struct drm_device *dev)
942{
943 struct drm_i915_private *dev_priv = to_i915(dev);
944
945 /*
946 * Neither the BIOS, ourselves or any other kernel
947 * expects the system to be in execlists mode on startup,
948 * so we need to reset the GPU back to legacy mode. And the only
949 * known way to disable logical contexts is through a GPU reset.
950 *
951 * So in order to leave the system in a known default configuration,
952 * always reset the GPU upon unload. Afterwards we then clean up the
953 * GEM state tracking, flushing off the requests and leaving the
954 * system in a known idle state.
955 *
956 * Note that is of the upmost importance that the GPU is idle and
957 * all stray writes are flushed *before* we dismantle the backing
958 * storage for the pinned objects.
959 *
960 * However, since we are uncertain that reseting the GPU on older
961 * machines is a good idea, we don't - just in case it leaves the
962 * machine in an unusable condition.
963 */
964 if (HAS_HW_CONTEXTS(dev)) {
965 int reset = intel_gpu_reset(dev_priv, ALL_ENGINES);
966 WARN_ON(reset && reset != -ENODEV);
967 }
968
969 mutex_lock(&dev->struct_mutex);
970 i915_gem_reset(dev);
971 i915_gem_cleanup_engines(dev);
972 i915_gem_context_fini(dev);
973 mutex_unlock(&dev->struct_mutex);
974
975 WARN_ON(!list_empty(&to_i915(dev)->context_list));
976}
977
978static int i915_load_modeset_init(struct drm_device *dev)
979{
980 struct drm_i915_private *dev_priv = dev->dev_private;
981 int ret;
982
983 if (i915_inject_load_failure())
984 return -ENODEV;
985
986 ret = intel_bios_init(dev_priv);
987 if (ret)
988 DRM_INFO("failed to find VBIOS tables\n");
989
990 /* If we have > 1 VGA cards, then we need to arbitrate access
991 * to the common VGA resources.
992 *
993 * If we are a secondary display controller (!PCI_DISPLAY_CLASS_VGA),
994 * then we do not take part in VGA arbitration and the
995 * vga_client_register() fails with -ENODEV.
996 */
997 ret = vga_client_register(dev->pdev, dev, NULL, i915_vga_set_decode);
998 if (ret && ret != -ENODEV)
999 goto out;
1000
1001 intel_register_dsm_handler();
1002
1003 ret = vga_switcheroo_register_client(dev->pdev, &i915_switcheroo_ops, false);
1004 if (ret)
1005 goto cleanup_vga_client;
1006
1007 /* must happen before intel_power_domains_init_hw() on VLV/CHV */
1008 intel_update_rawclk(dev_priv);
1009
1010 intel_power_domains_init_hw(dev_priv, false);
1011
1012 intel_csr_ucode_init(dev_priv);
1013
1014 ret = intel_irq_install(dev_priv);
1015 if (ret)
1016 goto cleanup_csr;
1017
1018 intel_setup_gmbus(dev);
1019
1020 /* Important: The output setup functions called by modeset_init need
1021 * working irqs for e.g. gmbus and dp aux transfers. */
1022 intel_modeset_init(dev);
1023
1024 intel_guc_init(dev);
1025
1026 ret = i915_gem_init(dev);
1027 if (ret)
1028 goto cleanup_irq;
1029
1030 intel_modeset_gem_init(dev);
1031
1032 if (INTEL_INFO(dev)->num_pipes == 0)
1033 return 0;
1034
1035 ret = intel_fbdev_init(dev);
1036 if (ret)
1037 goto cleanup_gem;
1038
1039 /* Only enable hotplug handling once the fbdev is fully set up. */
1040 intel_hpd_init(dev_priv);
1041
1042 drm_kms_helper_poll_init(dev);
1043
1044 return 0;
1045
1046cleanup_gem:
1047 i915_gem_fini(dev);
1048cleanup_irq:
1049 intel_guc_fini(dev);
1050 drm_irq_uninstall(dev);
1051 intel_teardown_gmbus(dev);
1052cleanup_csr:
1053 intel_csr_ucode_fini(dev_priv);
1054 intel_power_domains_fini(dev_priv);
1055 vga_switcheroo_unregister_client(dev->pdev);
1056cleanup_vga_client:
1057 vga_client_register(dev->pdev, NULL, NULL, NULL);
1058out:
1059 return ret;
1060}
1061
1062#if IS_ENABLED(CONFIG_FB)
1063static int i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv)
1064{
1065 struct apertures_struct *ap;
1066 struct pci_dev *pdev = dev_priv->dev->pdev;
1067 struct i915_ggtt *ggtt = &dev_priv->ggtt;
1068 bool primary;
1069 int ret;
1070
1071 ap = alloc_apertures(1);
1072 if (!ap)
1073 return -ENOMEM;
1074
1075 ap->ranges[0].base = ggtt->mappable_base;
1076 ap->ranges[0].size = ggtt->mappable_end;
1077
1078 primary =
1079 pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
1080
1081 ret = remove_conflicting_framebuffers(ap, "inteldrmfb", primary);
1082
1083 kfree(ap);
1084
1085 return ret;
1086}
1087#else
1088static int i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv)
1089{
1090 return 0;
1091}
1092#endif
1093
1094#if !defined(CONFIG_VGA_CONSOLE)
1095static int i915_kick_out_vgacon(struct drm_i915_private *dev_priv)
1096{
1097 return 0;
1098}
1099#elif !defined(CONFIG_DUMMY_CONSOLE)
1100static int i915_kick_out_vgacon(struct drm_i915_private *dev_priv)
1101{
1102 return -ENODEV;
1103}
1104#else
1105static int i915_kick_out_vgacon(struct drm_i915_private *dev_priv)
1106{
1107 int ret = 0;
1108
1109 DRM_INFO("Replacing VGA console driver\n");
1110
1111 console_lock();
1112 if (con_is_bound(&vga_con))
1113 ret = do_take_over_console(&dummy_con, 0, MAX_NR_CONSOLES - 1, 1);
1114 if (ret == 0) {
1115 ret = do_unregister_con_driver(&vga_con);
1116
1117 /* Ignore "already unregistered". */
1118 if (ret == -ENODEV)
1119 ret = 0;
1120 }
1121 console_unlock();
1122
1123 return ret;
1124}
1125#endif
1126
1127static void i915_dump_device_info(struct drm_i915_private *dev_priv)
1128{
1129 const struct intel_device_info *info = &dev_priv->info;
1130
1131#define PRINT_S(name) "%s"
1132#define SEP_EMPTY
1133#define PRINT_FLAG(name) info->name ? #name "," : ""
1134#define SEP_COMMA ,
1135 DRM_DEBUG_DRIVER("i915 device info: gen=%i, pciid=0x%04x rev=0x%02x flags="
1136 DEV_INFO_FOR_EACH_FLAG(PRINT_S, SEP_EMPTY),
1137 info->gen,
1138 dev_priv->dev->pdev->device,
1139 dev_priv->dev->pdev->revision,
1140 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_COMMA));
1141#undef PRINT_S
1142#undef SEP_EMPTY
1143#undef PRINT_FLAG
1144#undef SEP_COMMA
1145}
1146
1147static void cherryview_sseu_info_init(struct drm_device *dev)
1148{
1149 struct drm_i915_private *dev_priv = dev->dev_private;
1150 struct intel_device_info *info;
1151 u32 fuse, eu_dis;
1152
1153 info = (struct intel_device_info *)&dev_priv->info;
1154 fuse = I915_READ(CHV_FUSE_GT);
1155
1156 info->slice_total = 1;
1157
1158 if (!(fuse & CHV_FGT_DISABLE_SS0)) {
1159 info->subslice_per_slice++;
1160 eu_dis = fuse & (CHV_FGT_EU_DIS_SS0_R0_MASK |
1161 CHV_FGT_EU_DIS_SS0_R1_MASK);
1162 info->eu_total += 8 - hweight32(eu_dis);
1163 }
1164
1165 if (!(fuse & CHV_FGT_DISABLE_SS1)) {
1166 info->subslice_per_slice++;
1167 eu_dis = fuse & (CHV_FGT_EU_DIS_SS1_R0_MASK |
1168 CHV_FGT_EU_DIS_SS1_R1_MASK);
1169 info->eu_total += 8 - hweight32(eu_dis);
1170 }
1171
1172 info->subslice_total = info->subslice_per_slice;
1173 /*
1174 * CHV expected to always have a uniform distribution of EU
1175 * across subslices.
1176 */
1177 info->eu_per_subslice = info->subslice_total ?
1178 info->eu_total / info->subslice_total :
1179 0;
1180 /*
1181 * CHV supports subslice power gating on devices with more than
1182 * one subslice, and supports EU power gating on devices with
1183 * more than one EU pair per subslice.
1184 */
1185 info->has_slice_pg = 0;
1186 info->has_subslice_pg = (info->subslice_total > 1);
1187 info->has_eu_pg = (info->eu_per_subslice > 2);
1188}
1189
1190static void gen9_sseu_info_init(struct drm_device *dev)
1191{
1192 struct drm_i915_private *dev_priv = dev->dev_private;
1193 struct intel_device_info *info;
1194 int s_max = 3, ss_max = 4, eu_max = 8;
1195 int s, ss;
1196 u32 fuse2, s_enable, ss_disable, eu_disable;
1197 u8 eu_mask = 0xff;
1198
1199 info = (struct intel_device_info *)&dev_priv->info;
1200 fuse2 = I915_READ(GEN8_FUSE2);
1201 s_enable = (fuse2 & GEN8_F2_S_ENA_MASK) >>
1202 GEN8_F2_S_ENA_SHIFT;
1203 ss_disable = (fuse2 & GEN9_F2_SS_DIS_MASK) >>
1204 GEN9_F2_SS_DIS_SHIFT;
1205
1206 info->slice_total = hweight32(s_enable);
1207 /*
1208 * The subslice disable field is global, i.e. it applies
1209 * to each of the enabled slices.
1210 */
1211 info->subslice_per_slice = ss_max - hweight32(ss_disable);
1212 info->subslice_total = info->slice_total *
1213 info->subslice_per_slice;
1214
1215 /*
1216 * Iterate through enabled slices and subslices to
1217 * count the total enabled EU.
1218 */
1219 for (s = 0; s < s_max; s++) {
1220 if (!(s_enable & (0x1 << s)))
1221 /* skip disabled slice */
1222 continue;
1223
1224 eu_disable = I915_READ(GEN9_EU_DISABLE(s));
1225 for (ss = 0; ss < ss_max; ss++) {
1226 int eu_per_ss;
1227
1228 if (ss_disable & (0x1 << ss))
1229 /* skip disabled subslice */
1230 continue;
1231
1232 eu_per_ss = eu_max - hweight8((eu_disable >> (ss*8)) &
1233 eu_mask);
1234
1235 /*
1236 * Record which subslice(s) has(have) 7 EUs. we
1237 * can tune the hash used to spread work among
1238 * subslices if they are unbalanced.
1239 */
1240 if (eu_per_ss == 7)
1241 info->subslice_7eu[s] |= 1 << ss;
1242
1243 info->eu_total += eu_per_ss;
1244 }
1245 }
1246
1247 /*
1248 * SKL is expected to always have a uniform distribution
1249 * of EU across subslices with the exception that any one
1250 * EU in any one subslice may be fused off for die
1251 * recovery. BXT is expected to be perfectly uniform in EU
1252 * distribution.
1253 */
1254 info->eu_per_subslice = info->subslice_total ?
1255 DIV_ROUND_UP(info->eu_total,
1256 info->subslice_total) : 0;
1257 /*
1258 * SKL supports slice power gating on devices with more than
1259 * one slice, and supports EU power gating on devices with
1260 * more than one EU pair per subslice. BXT supports subslice
1261 * power gating on devices with more than one subslice, and
1262 * supports EU power gating on devices with more than one EU
1263 * pair per subslice.
1264 */
1265 info->has_slice_pg = ((IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) &&
1266 (info->slice_total > 1));
1267 info->has_subslice_pg = (IS_BROXTON(dev) && (info->subslice_total > 1));
1268 info->has_eu_pg = (info->eu_per_subslice > 2);
1269
1270 if (IS_BROXTON(dev)) {
1271#define IS_SS_DISABLED(_ss_disable, ss) (_ss_disable & (0x1 << ss))
1272 /*
1273 * There is a HW issue in 2x6 fused down parts that requires
1274 * Pooled EU to be enabled as a WA. The pool configuration
1275 * changes depending upon which subslice is fused down. This
1276 * doesn't affect if the device has all 3 subslices enabled.
1277 */
1278 /* WaEnablePooledEuFor2x6:bxt */
1279 info->has_pooled_eu = ((info->subslice_per_slice == 3) ||
1280 (info->subslice_per_slice == 2 &&
1281 INTEL_REVID(dev) < BXT_REVID_C0));
1282
1283 info->min_eu_in_pool = 0;
1284 if (info->has_pooled_eu) {
1285 if (IS_SS_DISABLED(ss_disable, 0) ||
1286 IS_SS_DISABLED(ss_disable, 2))
1287 info->min_eu_in_pool = 3;
1288 else if (IS_SS_DISABLED(ss_disable, 1))
1289 info->min_eu_in_pool = 6;
1290 else
1291 info->min_eu_in_pool = 9;
1292 }
1293#undef IS_SS_DISABLED
1294 }
1295}
1296
1297static void broadwell_sseu_info_init(struct drm_device *dev)
1298{
1299 struct drm_i915_private *dev_priv = dev->dev_private;
1300 struct intel_device_info *info;
1301 const int s_max = 3, ss_max = 3, eu_max = 8;
1302 int s, ss;
1303 u32 fuse2, eu_disable[s_max], s_enable, ss_disable;
1304
1305 fuse2 = I915_READ(GEN8_FUSE2);
1306 s_enable = (fuse2 & GEN8_F2_S_ENA_MASK) >> GEN8_F2_S_ENA_SHIFT;
1307 ss_disable = (fuse2 & GEN8_F2_SS_DIS_MASK) >> GEN8_F2_SS_DIS_SHIFT;
1308
1309 eu_disable[0] = I915_READ(GEN8_EU_DISABLE0) & GEN8_EU_DIS0_S0_MASK;
1310 eu_disable[1] = (I915_READ(GEN8_EU_DISABLE0) >> GEN8_EU_DIS0_S1_SHIFT) |
1311 ((I915_READ(GEN8_EU_DISABLE1) & GEN8_EU_DIS1_S1_MASK) <<
1312 (32 - GEN8_EU_DIS0_S1_SHIFT));
1313 eu_disable[2] = (I915_READ(GEN8_EU_DISABLE1) >> GEN8_EU_DIS1_S2_SHIFT) |
1314 ((I915_READ(GEN8_EU_DISABLE2) & GEN8_EU_DIS2_S2_MASK) <<
1315 (32 - GEN8_EU_DIS1_S2_SHIFT));
1316
1317
1318 info = (struct intel_device_info *)&dev_priv->info;
1319 info->slice_total = hweight32(s_enable);
1320
1321 /*
1322 * The subslice disable field is global, i.e. it applies
1323 * to each of the enabled slices.
1324 */
1325 info->subslice_per_slice = ss_max - hweight32(ss_disable);
1326 info->subslice_total = info->slice_total * info->subslice_per_slice;
1327
1328 /*
1329 * Iterate through enabled slices and subslices to
1330 * count the total enabled EU.
1331 */
1332 for (s = 0; s < s_max; s++) {
1333 if (!(s_enable & (0x1 << s)))
1334 /* skip disabled slice */
1335 continue;
1336
1337 for (ss = 0; ss < ss_max; ss++) {
1338 u32 n_disabled;
1339
1340 if (ss_disable & (0x1 << ss))
1341 /* skip disabled subslice */
1342 continue;
1343
1344 n_disabled = hweight8(eu_disable[s] >> (ss * eu_max));
1345
1346 /*
1347 * Record which subslices have 7 EUs.
1348 */
1349 if (eu_max - n_disabled == 7)
1350 info->subslice_7eu[s] |= 1 << ss;
1351
1352 info->eu_total += eu_max - n_disabled;
1353 }
1354 }
1355
1356 /*
1357 * BDW is expected to always have a uniform distribution of EU across
1358 * subslices with the exception that any one EU in any one subslice may
1359 * be fused off for die recovery.
1360 */
1361 info->eu_per_subslice = info->subslice_total ?
1362 DIV_ROUND_UP(info->eu_total, info->subslice_total) : 0;
1363
1364 /*
1365 * BDW supports slice power gating on devices with more than
1366 * one slice.
1367 */
1368 info->has_slice_pg = (info->slice_total > 1);
1369 info->has_subslice_pg = 0;
1370 info->has_eu_pg = 0;
1371}
1372
1373/*
1374 * Determine various intel_device_info fields at runtime.
1375 *
1376 * Use it when either:
1377 * - it's judged too laborious to fill n static structures with the limit
1378 * when a simple if statement does the job,
1379 * - run-time checks (eg read fuse/strap registers) are needed.
1380 *
1381 * This function needs to be called:
1382 * - after the MMIO has been setup as we are reading registers,
1383 * - after the PCH has been detected,
1384 * - before the first usage of the fields it can tweak.
1385 */
1386static void intel_device_info_runtime_init(struct drm_device *dev)
1387{
1388 struct drm_i915_private *dev_priv = dev->dev_private;
1389 struct intel_device_info *info;
1390 enum pipe pipe;
1391
1392 info = (struct intel_device_info *)&dev_priv->info;
1393
1394 /*
1395 * Skylake and Broxton currently don't expose the topmost plane as its
1396 * use is exclusive with the legacy cursor and we only want to expose
1397 * one of those, not both. Until we can safely expose the topmost plane
1398 * as a DRM_PLANE_TYPE_CURSOR with all the features exposed/supported,
1399 * we don't expose the topmost plane at all to prevent ABI breakage
1400 * down the line.
1401 */
1402 if (IS_BROXTON(dev)) {
1403 info->num_sprites[PIPE_A] = 2;
1404 info->num_sprites[PIPE_B] = 2;
1405 info->num_sprites[PIPE_C] = 1;
1406 } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
1407 for_each_pipe(dev_priv, pipe)
1408 info->num_sprites[pipe] = 2;
1409 else
1410 for_each_pipe(dev_priv, pipe)
1411 info->num_sprites[pipe] = 1;
1412
1413 if (i915.disable_display) {
1414 DRM_INFO("Display disabled (module parameter)\n");
1415 info->num_pipes = 0;
1416 } else if (info->num_pipes > 0 &&
1417 (IS_GEN7(dev_priv) || IS_GEN8(dev_priv)) &&
1418 HAS_PCH_SPLIT(dev)) {
1419 u32 fuse_strap = I915_READ(FUSE_STRAP);
1420 u32 sfuse_strap = I915_READ(SFUSE_STRAP);
1421
1422 /*
1423 * SFUSE_STRAP is supposed to have a bit signalling the display
1424 * is fused off. Unfortunately it seems that, at least in
1425 * certain cases, fused off display means that PCH display
1426 * reads don't land anywhere. In that case, we read 0s.
1427 *
1428 * On CPT/PPT, we can detect this case as SFUSE_STRAP_FUSE_LOCK
1429 * should be set when taking over after the firmware.
1430 */
1431 if (fuse_strap & ILK_INTERNAL_DISPLAY_DISABLE ||
1432 sfuse_strap & SFUSE_STRAP_DISPLAY_DISABLED ||
1433 (dev_priv->pch_type == PCH_CPT &&
1434 !(sfuse_strap & SFUSE_STRAP_FUSE_LOCK))) {
1435 DRM_INFO("Display fused off, disabling\n");
1436 info->num_pipes = 0;
1437 } else if (fuse_strap & IVB_PIPE_C_DISABLE) {
1438 DRM_INFO("PipeC fused off\n");
1439 info->num_pipes -= 1;
1440 }
1441 } else if (info->num_pipes > 0 && IS_GEN9(dev_priv)) {
1442 u32 dfsm = I915_READ(SKL_DFSM);
1443 u8 disabled_mask = 0;
1444 bool invalid;
1445 int num_bits;
1446
1447 if (dfsm & SKL_DFSM_PIPE_A_DISABLE)
1448 disabled_mask |= BIT(PIPE_A);
1449 if (dfsm & SKL_DFSM_PIPE_B_DISABLE)
1450 disabled_mask |= BIT(PIPE_B);
1451 if (dfsm & SKL_DFSM_PIPE_C_DISABLE)
1452 disabled_mask |= BIT(PIPE_C);
1453
1454 num_bits = hweight8(disabled_mask);
1455
1456 switch (disabled_mask) {
1457 case BIT(PIPE_A):
1458 case BIT(PIPE_B):
1459 case BIT(PIPE_A) | BIT(PIPE_B):
1460 case BIT(PIPE_A) | BIT(PIPE_C):
1461 invalid = true;
1462 break;
1463 default:
1464 invalid = false;
1465 }
1466
1467 if (num_bits > info->num_pipes || invalid)
1468 DRM_ERROR("invalid pipe fuse configuration: 0x%x\n",
1469 disabled_mask);
1470 else
1471 info->num_pipes -= num_bits;
1472 }
1473
1474 /* Initialize slice/subslice/EU info */
1475 if (IS_CHERRYVIEW(dev))
1476 cherryview_sseu_info_init(dev);
1477 else if (IS_BROADWELL(dev))
1478 broadwell_sseu_info_init(dev);
1479 else if (INTEL_INFO(dev)->gen >= 9)
1480 gen9_sseu_info_init(dev);
1481
1482 info->has_snoop = !info->has_llc;
1483
1484 /* Snooping is broken on BXT A stepping. */
1485 if (IS_BXT_REVID(dev, 0, BXT_REVID_A1))
1486 info->has_snoop = false;
1487
1488 DRM_DEBUG_DRIVER("slice total: %u\n", info->slice_total);
1489 DRM_DEBUG_DRIVER("subslice total: %u\n", info->subslice_total);
1490 DRM_DEBUG_DRIVER("subslice per slice: %u\n", info->subslice_per_slice);
1491 DRM_DEBUG_DRIVER("EU total: %u\n", info->eu_total);
1492 DRM_DEBUG_DRIVER("EU per subslice: %u\n", info->eu_per_subslice);
1493 DRM_DEBUG_DRIVER("has slice power gating: %s\n",
1494 info->has_slice_pg ? "y" : "n");
1495 DRM_DEBUG_DRIVER("has subslice power gating: %s\n",
1496 info->has_subslice_pg ? "y" : "n");
1497 DRM_DEBUG_DRIVER("has EU power gating: %s\n",
1498 info->has_eu_pg ? "y" : "n");
1499
1500 i915.enable_execlists =
1501 intel_sanitize_enable_execlists(dev_priv,
1502 i915.enable_execlists);
1503
1504 /*
1505 * i915.enable_ppgtt is read-only, so do an early pass to validate the
1506 * user's requested state against the hardware/driver capabilities. We
1507 * do this now so that we can print out any log messages once rather
1508 * than every time we check intel_enable_ppgtt().
1509 */
1510 i915.enable_ppgtt =
1511 intel_sanitize_enable_ppgtt(dev_priv, i915.enable_ppgtt);
1512 DRM_DEBUG_DRIVER("ppgtt mode: %i\n", i915.enable_ppgtt);
1513}
1514
1515static void intel_init_dpio(struct drm_i915_private *dev_priv)
1516{
1517 /*
1518 * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
1519 * CHV x1 PHY (DP/HDMI D)
1520 * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
1521 */
1522 if (IS_CHERRYVIEW(dev_priv)) {
1523 DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2;
1524 DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO;
1525 } else if (IS_VALLEYVIEW(dev_priv)) {
1526 DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO;
1527 }
1528}
1529
1530static int i915_workqueues_init(struct drm_i915_private *dev_priv)
1531{
1532 /*
1533 * The i915 workqueue is primarily used for batched retirement of
1534 * requests (and thus managing bo) once the task has been completed
1535 * by the GPU. i915_gem_retire_requests() is called directly when we
1536 * need high-priority retirement, such as waiting for an explicit
1537 * bo.
1538 *
1539 * It is also used for periodic low-priority events, such as
1540 * idle-timers and recording error state.
1541 *
1542 * All tasks on the workqueue are expected to acquire the dev mutex
1543 * so there is no point in running more than one instance of the
1544 * workqueue at any time. Use an ordered one.
1545 */
1546 dev_priv->wq = alloc_ordered_workqueue("i915", 0);
1547 if (dev_priv->wq == NULL)
1548 goto out_err;
1549
1550 dev_priv->hotplug.dp_wq = alloc_ordered_workqueue("i915-dp", 0);
1551 if (dev_priv->hotplug.dp_wq == NULL)
1552 goto out_free_wq;
1553
1554 dev_priv->gpu_error.hangcheck_wq =
1555 alloc_ordered_workqueue("i915-hangcheck", 0);
1556 if (dev_priv->gpu_error.hangcheck_wq == NULL)
1557 goto out_free_dp_wq;
1558
1559 return 0;
1560
1561out_free_dp_wq:
1562 destroy_workqueue(dev_priv->hotplug.dp_wq);
1563out_free_wq:
1564 destroy_workqueue(dev_priv->wq);
1565out_err:
1566 DRM_ERROR("Failed to allocate workqueues.\n");
1567
1568 return -ENOMEM;
1569}
1570
1571static void i915_workqueues_cleanup(struct drm_i915_private *dev_priv)
1572{
1573 destroy_workqueue(dev_priv->gpu_error.hangcheck_wq);
1574 destroy_workqueue(dev_priv->hotplug.dp_wq);
1575 destroy_workqueue(dev_priv->wq);
1576}
1577
1578/**
1579 * i915_driver_init_early - setup state not requiring device access
1580 * @dev_priv: device private
1581 *
1582 * Initialize everything that is a "SW-only" state, that is state not
1583 * requiring accessing the device or exposing the driver via kernel internal
1584 * or userspace interfaces. Example steps belonging here: lock initialization,
1585 * system memory allocation, setting up device specific attributes and
1586 * function hooks not requiring accessing the device.
1587 */
1588static int i915_driver_init_early(struct drm_i915_private *dev_priv,
1589 const struct pci_device_id *ent)
1590{
1591 const struct intel_device_info *match_info =
1592 (struct intel_device_info *)ent->driver_data;
1593 struct intel_device_info *device_info;
1594 int ret = 0;
1595
1596 if (i915_inject_load_failure())
1597 return -ENODEV;
1598
1599 /* Setup the write-once "constant" device info */
1600 device_info = (struct intel_device_info *)&dev_priv->info;
1601 memcpy(device_info, match_info, sizeof(*device_info));
1602 device_info->device_id = dev_priv->drm.pdev->device;
1603
1604 BUG_ON(device_info->gen > sizeof(device_info->gen_mask) * BITS_PER_BYTE);
1605 device_info->gen_mask = BIT(device_info->gen - 1);
1606
1607 spin_lock_init(&dev_priv->irq_lock);
1608 spin_lock_init(&dev_priv->gpu_error.lock);
1609 mutex_init(&dev_priv->backlight_lock);
1610 spin_lock_init(&dev_priv->uncore.lock);
1611 spin_lock_init(&dev_priv->mm.object_stat_lock);
1612 spin_lock_init(&dev_priv->mmio_flip_lock);
1613 mutex_init(&dev_priv->sb_lock);
1614 mutex_init(&dev_priv->modeset_restore_lock);
1615 mutex_init(&dev_priv->av_mutex);
1616 mutex_init(&dev_priv->wm.wm_mutex);
1617 mutex_init(&dev_priv->pps_mutex);
1618
1619 ret = i915_workqueues_init(dev_priv);
1620 if (ret < 0)
1621 return ret;
1622
1623 ret = intel_gvt_init(dev_priv);
1624 if (ret < 0)
1625 goto err_workqueues;
1626
1627 /* This must be called before any calls to HAS_PCH_* */
1628 intel_detect_pch(&dev_priv->drm);
1629
1630 intel_pm_setup(&dev_priv->drm);
1631 intel_init_dpio(dev_priv);
1632 intel_power_domains_init(dev_priv);
1633 intel_irq_init(dev_priv);
1634 intel_init_display_hooks(dev_priv);
1635 intel_init_clock_gating_hooks(dev_priv);
1636 intel_init_audio_hooks(dev_priv);
1637 i915_gem_load_init(&dev_priv->drm);
1638
1639 intel_display_crc_init(&dev_priv->drm);
1640
1641 i915_dump_device_info(dev_priv);
1642
1643 /* Not all pre-production machines fall into this category, only the
1644 * very first ones. Almost everything should work, except for maybe
1645 * suspend/resume. And we don't implement workarounds that affect only
1646 * pre-production machines. */
1647 if (IS_HSW_EARLY_SDV(dev_priv))
1648 DRM_INFO("This is an early pre-production Haswell machine. "
1649 "It may not be fully functional.\n");
1650
1651 return 0;
1652
1653err_workqueues:
1654 i915_workqueues_cleanup(dev_priv);
1655 return ret;
1656}
1657
1658/**
1659 * i915_driver_cleanup_early - cleanup the setup done in i915_driver_init_early()
1660 * @dev_priv: device private
1661 */
1662static void i915_driver_cleanup_early(struct drm_i915_private *dev_priv)
1663{
1664 i915_gem_load_cleanup(dev_priv->dev);
1665 i915_workqueues_cleanup(dev_priv);
1666}
1667
1668static int i915_mmio_setup(struct drm_device *dev)
1669{
1670 struct drm_i915_private *dev_priv = to_i915(dev);
1671 int mmio_bar;
1672 int mmio_size;
1673
1674 mmio_bar = IS_GEN2(dev) ? 1 : 0;
1675 /*
1676 * Before gen4, the registers and the GTT are behind different BARs.
1677 * However, from gen4 onwards, the registers and the GTT are shared
1678 * in the same BAR, so we want to restrict this ioremap from
1679 * clobbering the GTT which we want ioremap_wc instead. Fortunately,
1680 * the register BAR remains the same size for all the earlier
1681 * generations up to Ironlake.
1682 */
1683 if (INTEL_INFO(dev)->gen < 5)
1684 mmio_size = 512 * 1024;
1685 else
1686 mmio_size = 2 * 1024 * 1024;
1687 dev_priv->regs = pci_iomap(dev->pdev, mmio_bar, mmio_size);
1688 if (dev_priv->regs == NULL) {
1689 DRM_ERROR("failed to map registers\n");
1690
1691 return -EIO;
1692 }
1693
1694 /* Try to make sure MCHBAR is enabled before poking at it */
1695 intel_setup_mchbar(dev);
1696
1697 return 0;
1698}
1699
1700static void i915_mmio_cleanup(struct drm_device *dev)
1701{
1702 struct drm_i915_private *dev_priv = to_i915(dev);
1703
1704 intel_teardown_mchbar(dev);
1705 pci_iounmap(dev->pdev, dev_priv->regs);
1706}
1707
1708/**
1709 * i915_driver_init_mmio - setup device MMIO
1710 * @dev_priv: device private
1711 *
1712 * Setup minimal device state necessary for MMIO accesses later in the
1713 * initialization sequence. The setup here should avoid any other device-wide
1714 * side effects or exposing the driver via kernel internal or user space
1715 * interfaces.
1716 */
1717static int i915_driver_init_mmio(struct drm_i915_private *dev_priv)
1718{
1719 struct drm_device *dev = dev_priv->dev;
1720 int ret;
1721
1722 if (i915_inject_load_failure())
1723 return -ENODEV;
1724
1725 if (i915_get_bridge_dev(dev))
1726 return -EIO;
1727
1728 ret = i915_mmio_setup(dev);
1729 if (ret < 0)
1730 goto put_bridge;
1731
1732 intel_uncore_init(dev_priv);
1733
1734 return 0;
1735
1736put_bridge:
1737 pci_dev_put(dev_priv->bridge_dev);
1738
1739 return ret;
1740}
1741
1742/**
1743 * i915_driver_cleanup_mmio - cleanup the setup done in i915_driver_init_mmio()
1744 * @dev_priv: device private
1745 */
1746static void i915_driver_cleanup_mmio(struct drm_i915_private *dev_priv)
1747{
1748 struct drm_device *dev = dev_priv->dev;
1749
1750 intel_uncore_fini(dev_priv);
1751 i915_mmio_cleanup(dev);
1752 pci_dev_put(dev_priv->bridge_dev);
1753}
1754
1755/**
1756 * i915_driver_init_hw - setup state requiring device access
1757 * @dev_priv: device private
1758 *
1759 * Setup state that requires accessing the device, but doesn't require
1760 * exposing the driver via kernel internal or userspace interfaces.
1761 */
1762static int i915_driver_init_hw(struct drm_i915_private *dev_priv)
1763{
1764 struct drm_device *dev = dev_priv->dev;
1765 struct i915_ggtt *ggtt = &dev_priv->ggtt;
1766 uint32_t aperture_size;
1767 int ret;
1768
1769 if (i915_inject_load_failure())
1770 return -ENODEV;
1771
1772 intel_device_info_runtime_init(dev);
1773
1774 ret = i915_ggtt_init_hw(dev);
1775 if (ret)
1776 return ret;
1777
1778 ret = i915_ggtt_enable_hw(dev);
1779 if (ret) {
1780 DRM_ERROR("failed to enable GGTT\n");
1781 goto out_ggtt;
1782 }
1783
1784 /* WARNING: Apparently we must kick fbdev drivers before vgacon,
1785 * otherwise the vga fbdev driver falls over. */
1786 ret = i915_kick_out_firmware_fb(dev_priv);
1787 if (ret) {
1788 DRM_ERROR("failed to remove conflicting framebuffer drivers\n");
1789 goto out_ggtt;
1790 }
1791
1792 ret = i915_kick_out_vgacon(dev_priv);
1793 if (ret) {
1794 DRM_ERROR("failed to remove conflicting VGA console\n");
1795 goto out_ggtt;
1796 }
1797
1798 pci_set_master(dev->pdev);
1799
1800 /* overlay on gen2 is broken and can't address above 1G */
1801 if (IS_GEN2(dev)) {
1802 ret = dma_set_coherent_mask(&dev->pdev->dev, DMA_BIT_MASK(30));
1803 if (ret) {
1804 DRM_ERROR("failed to set DMA mask\n");
1805
1806 goto out_ggtt;
1807 }
1808 }
1809
1810
1811 /* 965GM sometimes incorrectly writes to hardware status page (HWS)
1812 * using 32bit addressing, overwriting memory if HWS is located
1813 * above 4GB.
1814 *
1815 * The documentation also mentions an issue with undefined
1816 * behaviour if any general state is accessed within a page above 4GB,
1817 * which also needs to be handled carefully.
1818 */
1819 if (IS_BROADWATER(dev) || IS_CRESTLINE(dev)) {
1820 ret = dma_set_coherent_mask(&dev->pdev->dev, DMA_BIT_MASK(32));
1821
1822 if (ret) {
1823 DRM_ERROR("failed to set DMA mask\n");
1824
1825 goto out_ggtt;
1826 }
1827 }
1828
1829 aperture_size = ggtt->mappable_end;
1830
1831 ggtt->mappable =
1832 io_mapping_create_wc(ggtt->mappable_base,
1833 aperture_size);
1834 if (!ggtt->mappable) {
1835 ret = -EIO;
1836 goto out_ggtt;
1837 }
1838
1839 ggtt->mtrr = arch_phys_wc_add(ggtt->mappable_base,
1840 aperture_size);
1841
1842 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY,
1843 PM_QOS_DEFAULT_VALUE);
1844
1845 intel_uncore_sanitize(dev_priv);
1846
1847 intel_opregion_setup(dev_priv);
1848
1849 i915_gem_load_init_fences(dev_priv);
1850
1851 /* On the 945G/GM, the chipset reports the MSI capability on the
1852 * integrated graphics even though the support isn't actually there
1853 * according to the published specs. It doesn't appear to function
1854 * correctly in testing on 945G.
1855 * This may be a side effect of MSI having been made available for PEG
1856 * and the registers being closely associated.
1857 *
1858 * According to chipset errata, on the 965GM, MSI interrupts may
1859 * be lost or delayed, but we use them anyways to avoid
1860 * stuck interrupts on some machines.
1861 */
1862 if (!IS_I945G(dev) && !IS_I945GM(dev)) {
1863 if (pci_enable_msi(dev->pdev) < 0)
1864 DRM_DEBUG_DRIVER("can't enable MSI");
1865 }
1866
1867 return 0;
1868
1869out_ggtt:
1870 i915_ggtt_cleanup_hw(dev);
1871
1872 return ret;
1873}
1874
1875/**
1876 * i915_driver_cleanup_hw - cleanup the setup done in i915_driver_init_hw()
1877 * @dev_priv: device private
1878 */
1879static void i915_driver_cleanup_hw(struct drm_i915_private *dev_priv)
1880{
1881 struct drm_device *dev = dev_priv->dev;
1882 struct i915_ggtt *ggtt = &dev_priv->ggtt;
1883
1884 if (dev->pdev->msi_enabled)
1885 pci_disable_msi(dev->pdev);
1886
1887 pm_qos_remove_request(&dev_priv->pm_qos);
1888 arch_phys_wc_del(ggtt->mtrr);
1889 io_mapping_free(ggtt->mappable);
1890 i915_ggtt_cleanup_hw(dev);
1891}
1892
1893/**
1894 * i915_driver_register - register the driver with the rest of the system
1895 * @dev_priv: device private
1896 *
1897 * Perform any steps necessary to make the driver available via kernel
1898 * internal or userspace interfaces.
1899 */
1900static void i915_driver_register(struct drm_i915_private *dev_priv)
1901{
1902 struct drm_device *dev = dev_priv->dev;
1903
1904 i915_gem_shrinker_init(dev_priv);
1905
1906 /*
1907 * Notify a valid surface after modesetting,
1908 * when running inside a VM.
1909 */
1910 if (intel_vgpu_active(dev_priv))
1911 I915_WRITE(vgtif_reg(display_ready), VGT_DRV_DISPLAY_READY);
1912
1913 /* Reveal our presence to userspace */
1914 if (drm_dev_register(dev, 0) == 0) {
1915 i915_debugfs_register(dev_priv);
1916 i915_setup_sysfs(dev);
1917 } else
1918 DRM_ERROR("Failed to register driver for userspace access!\n");
1919
1920 if (INTEL_INFO(dev_priv)->num_pipes) {
1921 /* Must be done after probing outputs */
1922 intel_opregion_register(dev_priv);
1923 acpi_video_register();
1924 }
1925
1926 if (IS_GEN5(dev_priv))
1927 intel_gpu_ips_init(dev_priv);
1928
1929 i915_audio_component_init(dev_priv);
1930
1931 /*
1932 * Some ports require correctly set-up hpd registers for detection to
1933 * work properly (leading to ghost connected connector status), e.g. VGA
1934 * on gm45. Hence we can only set up the initial fbdev config after hpd
1935 * irqs are fully enabled. We do it last so that the async config
1936 * cannot run before the connectors are registered.
1937 */
1938 intel_fbdev_initial_config_async(dev);
1939}
1940
1941/**
1942 * i915_driver_unregister - cleanup the registration done in i915_driver_regiser()
1943 * @dev_priv: device private
1944 */
1945static void i915_driver_unregister(struct drm_i915_private *dev_priv)
1946{
1947 i915_audio_component_cleanup(dev_priv);
1948
1949 intel_gpu_ips_teardown();
1950 acpi_video_unregister();
1951 intel_opregion_unregister(dev_priv);
1952
1953 i915_teardown_sysfs(dev_priv->dev);
1954 i915_debugfs_unregister(dev_priv);
1955 drm_dev_unregister(dev_priv->dev);
1956
1957 i915_gem_shrinker_cleanup(dev_priv);
1958}
1959
1960/**
1961 * i915_driver_load - setup chip and create an initial config
1962 * @dev: DRM device
1963 * @flags: startup flags
1964 *
1965 * The driver load routine has to do several things:
1966 * - drive output discovery via intel_modeset_init()
1967 * - initialize the memory manager
1968 * - allocate initial config memory
1969 * - setup the DRM framebuffer with the allocated memory
1970 */
1971static int i915_driver_load(struct pci_dev *pdev,
1972 const struct pci_device_id *ent)
1973{
1974 struct drm_i915_private *dev_priv;
1975 int ret;
1976
1977 ret = -ENOMEM;
1978 dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
1979 if (dev_priv)
1980 ret = drm_dev_init(&dev_priv->drm, &driver, &pdev->dev);
1981 if (ret) {
1982 dev_printk(KERN_ERR, &pdev->dev,
1983 "[" DRM_NAME ":%s] allocation failed\n", __func__);
1984 kfree(dev_priv);
1985 return ret;
1986 }
1987
1988 /* Must be set before calling __i915_printk */
1989 dev_priv->drm.pdev = pdev;
1990 dev_priv->drm.dev_private = dev_priv;
1991 dev_priv->dev = &dev_priv->drm;
1992
1993 ret = pci_enable_device(pdev);
1994 if (ret)
1995 goto out_free_priv;
1996
1997 pci_set_drvdata(pdev, &dev_priv->drm);
1998
1999 ret = i915_driver_init_early(dev_priv, ent);
2000 if (ret < 0)
2001 goto out_pci_disable;
2002
2003 intel_runtime_pm_get(dev_priv);
2004
2005 ret = i915_driver_init_mmio(dev_priv);
2006 if (ret < 0)
2007 goto out_runtime_pm_put;
2008
2009 ret = i915_driver_init_hw(dev_priv);
2010 if (ret < 0)
2011 goto out_cleanup_mmio;
2012
2013 /*
2014 * TODO: move the vblank init and parts of modeset init steps into one
2015 * of the i915_driver_init_/i915_driver_register functions according
2016 * to the role/effect of the given init step.
2017 */
2018 if (INTEL_INFO(dev_priv)->num_pipes) {
2019 ret = drm_vblank_init(dev_priv->dev,
2020 INTEL_INFO(dev_priv)->num_pipes);
2021 if (ret)
2022 goto out_cleanup_hw;
2023 }
2024
2025 ret = i915_load_modeset_init(dev_priv->dev);
2026 if (ret < 0)
2027 goto out_cleanup_vblank;
2028
2029 i915_driver_register(dev_priv);
2030
2031 intel_runtime_pm_enable(dev_priv);
2032
2033 intel_runtime_pm_put(dev_priv);
2034
2035 return 0;
2036
2037out_cleanup_vblank:
2038 drm_vblank_cleanup(dev_priv->dev);
2039out_cleanup_hw:
2040 i915_driver_cleanup_hw(dev_priv);
2041out_cleanup_mmio:
2042 i915_driver_cleanup_mmio(dev_priv);
2043out_runtime_pm_put:
2044 intel_runtime_pm_put(dev_priv);
2045 i915_driver_cleanup_early(dev_priv);
2046out_pci_disable:
2047 pci_disable_device(pdev);
2048out_free_priv:
2049 i915_load_error(dev_priv, "Device initialization failed (%d)\n", ret);
2050 drm_dev_unref(&dev_priv->drm);
2051 return ret;
2052}
2053
2054static int i915_driver_unload(struct drm_device *dev)
2055{
2056 struct drm_i915_private *dev_priv = dev->dev_private;
2057 int ret;
2058
2059 intel_fbdev_fini(dev);
2060
2061 ret = i915_gem_suspend(dev);
2062 if (ret) {
2063 DRM_ERROR("failed to idle hardware: %d\n", ret);
2064 return ret;
2065 }
2066
2067 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
2068
2069 i915_driver_unregister(dev_priv);
2070
2071 drm_vblank_cleanup(dev);
2072
2073 intel_modeset_cleanup(dev);
2074
2075 /*
2076 * free the memory space allocated for the child device
2077 * config parsed from VBT
2078 */
2079 if (dev_priv->vbt.child_dev && dev_priv->vbt.child_dev_num) {
2080 kfree(dev_priv->vbt.child_dev);
2081 dev_priv->vbt.child_dev = NULL;
2082 dev_priv->vbt.child_dev_num = 0;
2083 }
2084 kfree(dev_priv->vbt.sdvo_lvds_vbt_mode);
2085 dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
2086 kfree(dev_priv->vbt.lfp_lvds_vbt_mode);
2087 dev_priv->vbt.lfp_lvds_vbt_mode = NULL;
2088
2089 vga_switcheroo_unregister_client(dev->pdev);
2090 vga_client_register(dev->pdev, NULL, NULL, NULL);
2091
2092 intel_csr_ucode_fini(dev_priv);
2093
2094 /* Free error state after interrupts are fully disabled. */
2095 cancel_delayed_work_sync(&dev_priv->gpu_error.hangcheck_work);
2096 i915_destroy_error_state(dev);
2097
2098 /* Flush any outstanding unpin_work. */
2099 flush_workqueue(dev_priv->wq);
2100
2101 intel_guc_fini(dev);
2102 i915_gem_fini(dev);
2103 intel_fbc_cleanup_cfb(dev_priv);
2104
2105 intel_power_domains_fini(dev_priv);
2106
2107 i915_driver_cleanup_hw(dev_priv);
2108 i915_driver_cleanup_mmio(dev_priv);
2109
2110 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
2111
2112 i915_driver_cleanup_early(dev_priv);
2113
2114 return 0;
2115}
2116
2117static int i915_driver_open(struct drm_device *dev, struct drm_file *file)
2118{
2119 int ret;
2120
2121 ret = i915_gem_open(dev, file);
2122 if (ret)
2123 return ret;
2124
2125 return 0;
2126}
2127
2128/**
2129 * i915_driver_lastclose - clean up after all DRM clients have exited
2130 * @dev: DRM device
2131 *
2132 * Take care of cleaning up after all DRM clients have exited. In the
2133 * mode setting case, we want to restore the kernel's initial mode (just
2134 * in case the last client left us in a bad state).
2135 *
2136 * Additionally, in the non-mode setting case, we'll tear down the GTT
2137 * and DMA structures, since the kernel won't be using them, and clea
2138 * up any GEM state.
2139 */
2140static void i915_driver_lastclose(struct drm_device *dev)
2141{
2142 intel_fbdev_restore_mode(dev);
2143 vga_switcheroo_process_delayed_switch();
2144}
2145
2146static void i915_driver_preclose(struct drm_device *dev, struct drm_file *file)
2147{
2148 mutex_lock(&dev->struct_mutex);
2149 i915_gem_context_close(dev, file);
2150 i915_gem_release(dev, file);
2151 mutex_unlock(&dev->struct_mutex);
2152}
2153
2154static void i915_driver_postclose(struct drm_device *dev, struct drm_file *file)
2155{
2156 struct drm_i915_file_private *file_priv = file->driver_priv;
2157
2158 kfree(file_priv);
2159}
2160
Imre Deak07f9cd02014-08-18 14:42:45 +03002161static void intel_suspend_encoders(struct drm_i915_private *dev_priv)
2162{
2163 struct drm_device *dev = dev_priv->dev;
Jani Nikula19c80542015-12-16 12:48:16 +02002164 struct intel_encoder *encoder;
Imre Deak07f9cd02014-08-18 14:42:45 +03002165
2166 drm_modeset_lock_all(dev);
Jani Nikula19c80542015-12-16 12:48:16 +02002167 for_each_intel_encoder(dev, encoder)
2168 if (encoder->suspend)
2169 encoder->suspend(encoder);
Imre Deak07f9cd02014-08-18 14:42:45 +03002170 drm_modeset_unlock_all(dev);
2171}
2172
Paulo Zanoni1a5df182014-10-27 17:54:32 -02002173static int vlv_resume_prepare(struct drm_i915_private *dev_priv,
2174 bool rpm_resume);
Imre Deak507e1262016-04-20 20:27:54 +03002175static int vlv_suspend_complete(struct drm_i915_private *dev_priv);
Suketu Shahf75a1982015-04-16 14:22:11 +05302176
Imre Deakbc872292015-11-18 17:32:30 +02002177static bool suspend_to_idle(struct drm_i915_private *dev_priv)
2178{
2179#if IS_ENABLED(CONFIG_ACPI_SLEEP)
2180 if (acpi_target_system_state() < ACPI_STATE_S3)
2181 return true;
2182#endif
2183 return false;
2184}
Sagar Kambleebc32822014-08-13 23:07:05 +05302185
Imre Deak5e365c32014-10-23 19:23:25 +03002186static int i915_drm_suspend(struct drm_device *dev)
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01002187{
Rafael J. Wysocki61caf872010-02-18 23:06:27 +01002188 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnese5747e32014-06-12 08:35:47 -07002189 pci_power_t opregion_target_state;
Daniel Vetterd5818932015-02-23 12:03:26 +01002190 int error;
Rafael J. Wysocki61caf872010-02-18 23:06:27 +01002191
Zhang Ruib8efb172013-02-05 15:41:53 +08002192 /* ignore lid events during suspend */
2193 mutex_lock(&dev_priv->modeset_restore_lock);
2194 dev_priv->modeset_restore = MODESET_SUSPENDED;
2195 mutex_unlock(&dev_priv->modeset_restore_lock);
2196
Imre Deak1f814da2015-12-16 02:52:19 +02002197 disable_rpm_wakeref_asserts(dev_priv);
2198
Paulo Zanonic67a4702013-08-19 13:18:09 -03002199 /* We do a lot of poking in a lot of registers, make sure they work
2200 * properly. */
Imre Deakda7e29b2014-02-18 00:02:02 +02002201 intel_display_set_init_power(dev_priv, true);
Paulo Zanonicb107992013-01-25 16:59:15 -02002202
Dave Airlie5bcf7192010-12-07 09:20:40 +10002203 drm_kms_helper_poll_disable(dev);
2204
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01002205 pci_save_state(dev->pdev);
2206
Daniel Vetterd5818932015-02-23 12:03:26 +01002207 error = i915_gem_suspend(dev);
2208 if (error) {
2209 dev_err(&dev->pdev->dev,
2210 "GEM idle failed, resume might fail\n");
Imre Deak1f814da2015-12-16 02:52:19 +02002211 goto out;
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01002212 }
2213
Alex Daia1c41992015-09-30 09:46:37 -07002214 intel_guc_suspend(dev);
2215
Chris Wilsondc979972016-05-10 14:10:04 +01002216 intel_suspend_gt_powersave(dev_priv);
Daniel Vetterd5818932015-02-23 12:03:26 +01002217
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02002218 intel_display_suspend(dev);
Daniel Vetterd5818932015-02-23 12:03:26 +01002219
2220 intel_dp_mst_suspend(dev);
2221
2222 intel_runtime_pm_disable_interrupts(dev_priv);
2223 intel_hpd_cancel_work(dev_priv);
2224
2225 intel_suspend_encoders(dev_priv);
2226
2227 intel_suspend_hw(dev);
2228
Ben Widawsky828c7902013-10-16 09:21:30 -07002229 i915_gem_suspend_gtt_mappings(dev);
2230
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01002231 i915_save_state(dev);
2232
Imre Deakbc872292015-11-18 17:32:30 +02002233 opregion_target_state = suspend_to_idle(dev_priv) ? PCI_D1 : PCI_D3cold;
Chris Wilson6f9f4b72016-05-23 15:08:09 +01002234 intel_opregion_notify_adapter(dev_priv, opregion_target_state);
Jesse Barnese5747e32014-06-12 08:35:47 -07002235
Chris Wilsondc979972016-05-10 14:10:04 +01002236 intel_uncore_forcewake_reset(dev_priv, false);
Chris Wilson03d92e42016-05-23 15:08:10 +01002237 intel_opregion_unregister(dev_priv);
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01002238
Chris Wilson82e3b8c2014-08-13 13:09:46 +01002239 intel_fbdev_set_suspend(dev, FBINFO_STATE_SUSPENDED, true);
Dave Airlie3fa016a2012-03-28 10:48:49 +01002240
Mika Kuoppala62d5d692014-02-25 17:11:28 +02002241 dev_priv->suspend_count++;
2242
Kristen Carlson Accardi85e90672014-06-12 08:35:44 -07002243 intel_display_set_init_power(dev_priv, false);
2244
Imre Deakf74ed082016-04-18 14:48:21 +03002245 intel_csr_ucode_suspend(dev_priv);
Imre Deakf514c2d2015-10-28 23:59:06 +02002246
Imre Deak1f814da2015-12-16 02:52:19 +02002247out:
2248 enable_rpm_wakeref_asserts(dev_priv);
2249
2250 return error;
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01002251}
2252
Imre Deakab3be732015-03-02 13:04:41 +02002253static int i915_drm_suspend_late(struct drm_device *drm_dev, bool hibernation)
Imre Deakc3c09c92014-10-23 19:23:15 +03002254{
2255 struct drm_i915_private *dev_priv = drm_dev->dev_private;
Imre Deakbc872292015-11-18 17:32:30 +02002256 bool fw_csr;
Imre Deakc3c09c92014-10-23 19:23:15 +03002257 int ret;
2258
Imre Deak1f814da2015-12-16 02:52:19 +02002259 disable_rpm_wakeref_asserts(dev_priv);
2260
Imre Deaka7c81252016-04-01 16:02:38 +03002261 fw_csr = !IS_BROXTON(dev_priv) &&
2262 suspend_to_idle(dev_priv) && dev_priv->csr.dmc_payload;
Imre Deakbc872292015-11-18 17:32:30 +02002263 /*
2264 * In case of firmware assisted context save/restore don't manually
2265 * deinit the power domains. This also means the CSR/DMC firmware will
2266 * stay active, it will power down any HW resources as required and
2267 * also enable deeper system power states that would be blocked if the
2268 * firmware was inactive.
2269 */
2270 if (!fw_csr)
2271 intel_power_domains_suspend(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002272
Imre Deak507e1262016-04-20 20:27:54 +03002273 ret = 0;
Imre Deakb8aea3d12016-04-20 20:27:55 +03002274 if (IS_BROXTON(dev_priv))
Imre Deak507e1262016-04-20 20:27:54 +03002275 bxt_enable_dc9(dev_priv);
Imre Deakb8aea3d12016-04-20 20:27:55 +03002276 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Imre Deak507e1262016-04-20 20:27:54 +03002277 hsw_enable_pc8(dev_priv);
2278 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2279 ret = vlv_suspend_complete(dev_priv);
Imre Deakc3c09c92014-10-23 19:23:15 +03002280
2281 if (ret) {
2282 DRM_ERROR("Suspend complete failed: %d\n", ret);
Imre Deakbc872292015-11-18 17:32:30 +02002283 if (!fw_csr)
2284 intel_power_domains_init_hw(dev_priv, true);
Imre Deakc3c09c92014-10-23 19:23:15 +03002285
Imre Deak1f814da2015-12-16 02:52:19 +02002286 goto out;
Imre Deakc3c09c92014-10-23 19:23:15 +03002287 }
2288
2289 pci_disable_device(drm_dev->pdev);
Imre Deakab3be732015-03-02 13:04:41 +02002290 /*
Imre Deak54875572015-06-30 17:06:47 +03002291 * During hibernation on some platforms the BIOS may try to access
Imre Deakab3be732015-03-02 13:04:41 +02002292 * the device even though it's already in D3 and hang the machine. So
2293 * leave the device in D0 on those platforms and hope the BIOS will
Imre Deak54875572015-06-30 17:06:47 +03002294 * power down the device properly. The issue was seen on multiple old
2295 * GENs with different BIOS vendors, so having an explicit blacklist
2296 * is inpractical; apply the workaround on everything pre GEN6. The
2297 * platforms where the issue was seen:
2298 * Lenovo Thinkpad X301, X61s, X60, T60, X41
2299 * Fujitsu FSC S7110
2300 * Acer Aspire 1830T
Imre Deakab3be732015-03-02 13:04:41 +02002301 */
Imre Deak54875572015-06-30 17:06:47 +03002302 if (!(hibernation && INTEL_INFO(dev_priv)->gen < 6))
Imre Deakab3be732015-03-02 13:04:41 +02002303 pci_set_power_state(drm_dev->pdev, PCI_D3hot);
Imre Deakc3c09c92014-10-23 19:23:15 +03002304
Imre Deakbc872292015-11-18 17:32:30 +02002305 dev_priv->suspended_to_idle = suspend_to_idle(dev_priv);
2306
Imre Deak1f814da2015-12-16 02:52:19 +02002307out:
2308 enable_rpm_wakeref_asserts(dev_priv);
2309
2310 return ret;
Imre Deakc3c09c92014-10-23 19:23:15 +03002311}
2312
Maarten Lankhorst1751fcf2015-08-27 15:15:15 +02002313int i915_suspend_switcheroo(struct drm_device *dev, pm_message_t state)
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01002314{
2315 int error;
2316
2317 if (!dev || !dev->dev_private) {
2318 DRM_ERROR("dev: %p\n", dev);
Keith Packard1ae8c0a2009-06-28 15:42:17 -07002319 DRM_ERROR("DRM not initialized, aborting suspend.\n");
Jesse Barnesba8bbcf2007-11-22 14:14:14 +10002320 return -ENODEV;
2321 }
2322
Imre Deak0b14cbd2014-09-10 18:16:55 +03002323 if (WARN_ON_ONCE(state.event != PM_EVENT_SUSPEND &&
2324 state.event != PM_EVENT_FREEZE))
2325 return -EINVAL;
Dave Airlie5bcf7192010-12-07 09:20:40 +10002326
2327 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
2328 return 0;
Chris Wilson6eecba32010-09-08 09:45:11 +01002329
Imre Deak5e365c32014-10-23 19:23:25 +03002330 error = i915_drm_suspend(dev);
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01002331 if (error)
2332 return error;
Jesse Barnesba8bbcf2007-11-22 14:14:14 +10002333
Imre Deakab3be732015-03-02 13:04:41 +02002334 return i915_drm_suspend_late(dev, false);
Jesse Barnesba8bbcf2007-11-22 14:14:14 +10002335}
2336
Imre Deak5e365c32014-10-23 19:23:25 +03002337static int i915_drm_resume(struct drm_device *dev)
Jesse Barnesba8bbcf2007-11-22 14:14:14 +10002338{
Jesse Barnes5669fca2009-02-17 15:13:31 -08002339 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläac840ae2016-05-06 21:35:55 +03002340 int ret;
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +01002341
Imre Deak1f814da2015-12-16 02:52:19 +02002342 disable_rpm_wakeref_asserts(dev_priv);
2343
Ville Syrjäläac840ae2016-05-06 21:35:55 +03002344 ret = i915_ggtt_enable_hw(dev);
2345 if (ret)
2346 DRM_ERROR("failed to re-enable GGTT\n");
2347
Imre Deakf74ed082016-04-18 14:48:21 +03002348 intel_csr_ucode_resume(dev_priv);
2349
Daniel Vetterd5818932015-02-23 12:03:26 +01002350 mutex_lock(&dev->struct_mutex);
2351 i915_gem_restore_gtt_mappings(dev);
2352 mutex_unlock(&dev->struct_mutex);
Paulo Zanoni9d49c0e2013-09-12 18:06:43 -03002353
Rafael J. Wysocki61caf872010-02-18 23:06:27 +01002354 i915_restore_state(dev);
Chris Wilson6f9f4b72016-05-23 15:08:09 +01002355 intel_opregion_setup(dev_priv);
Rafael J. Wysocki61caf872010-02-18 23:06:27 +01002356
Daniel Vetterd5818932015-02-23 12:03:26 +01002357 intel_init_pch_refclk(dev);
2358 drm_mode_config_reset(dev);
Chris Wilson1833b132012-05-09 11:56:28 +01002359
Peter Antoine364aece2015-05-11 08:50:45 +01002360 /*
2361 * Interrupts have to be enabled before any batches are run. If not the
2362 * GPU will hang. i915_gem_init_hw() will initiate batches to
2363 * update/restore the context.
2364 *
2365 * Modeset enabling in intel_modeset_init_hw() also needs working
2366 * interrupts.
2367 */
2368 intel_runtime_pm_enable_interrupts(dev_priv);
2369
Daniel Vetterd5818932015-02-23 12:03:26 +01002370 mutex_lock(&dev->struct_mutex);
2371 if (i915_gem_init_hw(dev)) {
2372 DRM_ERROR("failed to re-initialize GPU, declaring wedged!\n");
Peter Zijlstra805de8f42015-04-24 01:12:32 +02002373 atomic_or(I915_WEDGED, &dev_priv->gpu_error.reset_counter);
Jesse Barnesd5bb0812011-01-05 12:01:26 -08002374 }
Daniel Vetterd5818932015-02-23 12:03:26 +01002375 mutex_unlock(&dev->struct_mutex);
2376
Alex Daia1c41992015-09-30 09:46:37 -07002377 intel_guc_resume(dev);
2378
Daniel Vetterd5818932015-02-23 12:03:26 +01002379 intel_modeset_init_hw(dev);
2380
2381 spin_lock_irq(&dev_priv->irq_lock);
2382 if (dev_priv->display.hpd_irq_setup)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002383 dev_priv->display.hpd_irq_setup(dev_priv);
Daniel Vetterd5818932015-02-23 12:03:26 +01002384 spin_unlock_irq(&dev_priv->irq_lock);
2385
Daniel Vetterd5818932015-02-23 12:03:26 +01002386 intel_dp_mst_resume(dev);
2387
Lyudea16b7652016-03-11 10:57:01 -05002388 intel_display_resume(dev);
2389
Daniel Vetterd5818932015-02-23 12:03:26 +01002390 /*
2391 * ... but also need to make sure that hotplug processing
2392 * doesn't cause havoc. Like in the driver load code we don't
2393 * bother with the tiny race here where we might loose hotplug
2394 * notifications.
2395 * */
2396 intel_hpd_init(dev_priv);
2397 /* Config may have changed between suspend and resume */
2398 drm_helper_hpd_irq_event(dev);
Jesse Barnes1daed3f2011-01-05 12:01:25 -08002399
Chris Wilson03d92e42016-05-23 15:08:10 +01002400 intel_opregion_register(dev_priv);
Chris Wilson44834a62010-08-19 16:09:23 +01002401
Chris Wilson82e3b8c2014-08-13 13:09:46 +01002402 intel_fbdev_set_suspend(dev, FBINFO_STATE_RUNNING, false);
Jesse Barnes073f34d2012-11-02 11:13:59 -07002403
Zhang Ruib8efb172013-02-05 15:41:53 +08002404 mutex_lock(&dev_priv->modeset_restore_lock);
2405 dev_priv->modeset_restore = MODESET_DONE;
2406 mutex_unlock(&dev_priv->modeset_restore_lock);
Paulo Zanoni8a187452013-12-06 20:32:13 -02002407
Chris Wilson6f9f4b72016-05-23 15:08:09 +01002408 intel_opregion_notify_adapter(dev_priv, PCI_D0);
Jesse Barnese5747e32014-06-12 08:35:47 -07002409
Imre Deakee6f2802014-10-23 19:23:22 +03002410 drm_kms_helper_poll_enable(dev);
2411
Imre Deak1f814da2015-12-16 02:52:19 +02002412 enable_rpm_wakeref_asserts(dev_priv);
2413
Chris Wilson074c6ad2014-04-09 09:19:43 +01002414 return 0;
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01002415}
2416
Imre Deak5e365c32014-10-23 19:23:25 +03002417static int i915_drm_resume_early(struct drm_device *dev)
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01002418{
Imre Deak36d61e62014-10-23 19:23:24 +03002419 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak44410cd2016-04-18 14:45:54 +03002420 int ret;
Imre Deak36d61e62014-10-23 19:23:24 +03002421
Imre Deak76c4b252014-04-01 19:55:22 +03002422 /*
2423 * We have a resume ordering issue with the snd-hda driver also
2424 * requiring our device to be power up. Due to the lack of a
2425 * parent/child relationship we currently solve this with an early
2426 * resume hook.
2427 *
2428 * FIXME: This should be solved with a special hdmi sink device or
2429 * similar so that power domains can be employed.
2430 */
Imre Deak44410cd2016-04-18 14:45:54 +03002431
2432 /*
2433 * Note that we need to set the power state explicitly, since we
2434 * powered off the device during freeze and the PCI core won't power
2435 * it back up for us during thaw. Powering off the device during
2436 * freeze is not a hard requirement though, and during the
2437 * suspend/resume phases the PCI core makes sure we get here with the
2438 * device powered on. So in case we change our freeze logic and keep
2439 * the device powered we can also remove the following set power state
2440 * call.
2441 */
2442 ret = pci_set_power_state(dev->pdev, PCI_D0);
2443 if (ret) {
2444 DRM_ERROR("failed to set PCI D0 power state (%d)\n", ret);
2445 goto out;
2446 }
2447
2448 /*
2449 * Note that pci_enable_device() first enables any parent bridge
2450 * device and only then sets the power state for this device. The
2451 * bridge enabling is a nop though, since bridge devices are resumed
2452 * first. The order of enabling power and enabling the device is
2453 * imposed by the PCI core as described above, so here we preserve the
2454 * same order for the freeze/thaw phases.
2455 *
2456 * TODO: eventually we should remove pci_disable_device() /
2457 * pci_enable_enable_device() from suspend/resume. Due to how they
2458 * depend on the device enable refcount we can't anyway depend on them
2459 * disabling/enabling the device.
2460 */
Imre Deakbc872292015-11-18 17:32:30 +02002461 if (pci_enable_device(dev->pdev)) {
2462 ret = -EIO;
2463 goto out;
2464 }
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01002465
2466 pci_set_master(dev->pdev);
2467
Imre Deak1f814da2015-12-16 02:52:19 +02002468 disable_rpm_wakeref_asserts(dev_priv);
2469
Wayne Boyer666a4532015-12-09 12:29:35 -08002470 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Paulo Zanoni1a5df182014-10-27 17:54:32 -02002471 ret = vlv_resume_prepare(dev_priv, false);
Imre Deak36d61e62014-10-23 19:23:24 +03002472 if (ret)
Damien Lespiauff0b1872015-05-20 14:45:15 +01002473 DRM_ERROR("Resume prepare failed: %d, continuing anyway\n",
2474 ret);
Imre Deak36d61e62014-10-23 19:23:24 +03002475
Chris Wilsondc979972016-05-10 14:10:04 +01002476 intel_uncore_early_sanitize(dev_priv, true);
Paulo Zanoniefee8332014-10-27 17:54:33 -02002477
Chris Wilsondc979972016-05-10 14:10:04 +01002478 if (IS_BROXTON(dev_priv)) {
Imre Deakda2f41d2016-04-20 20:27:56 +03002479 if (!dev_priv->suspended_to_idle)
2480 gen9_sanitize_dc_state(dev_priv);
Imre Deak507e1262016-04-20 20:27:54 +03002481 bxt_disable_dc9(dev_priv);
Imre Deakda2f41d2016-04-20 20:27:56 +03002482 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Damien Lespiaua9a6b732015-05-20 14:45:14 +01002483 hsw_disable_pc8(dev_priv);
Imre Deakda2f41d2016-04-20 20:27:56 +03002484 }
Paulo Zanoniefee8332014-10-27 17:54:33 -02002485
Chris Wilsondc979972016-05-10 14:10:04 +01002486 intel_uncore_sanitize(dev_priv);
Imre Deakbc872292015-11-18 17:32:30 +02002487
Imre Deaka7c81252016-04-01 16:02:38 +03002488 if (IS_BROXTON(dev_priv) ||
2489 !(dev_priv->suspended_to_idle && dev_priv->csr.dmc_payload))
Imre Deakbc872292015-11-18 17:32:30 +02002490 intel_power_domains_init_hw(dev_priv, true);
2491
Imre Deak6e35e8a2016-04-18 10:04:19 +03002492 enable_rpm_wakeref_asserts(dev_priv);
2493
Imre Deakbc872292015-11-18 17:32:30 +02002494out:
2495 dev_priv->suspended_to_idle = false;
Imre Deak36d61e62014-10-23 19:23:24 +03002496
2497 return ret;
Imre Deak76c4b252014-04-01 19:55:22 +03002498}
2499
Maarten Lankhorst1751fcf2015-08-27 15:15:15 +02002500int i915_resume_switcheroo(struct drm_device *dev)
Imre Deak76c4b252014-04-01 19:55:22 +03002501{
Imre Deak50a00722014-10-23 19:23:17 +03002502 int ret;
Imre Deak76c4b252014-04-01 19:55:22 +03002503
Imre Deak097dd832014-10-23 19:23:19 +03002504 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
2505 return 0;
2506
Imre Deak5e365c32014-10-23 19:23:25 +03002507 ret = i915_drm_resume_early(dev);
Imre Deak50a00722014-10-23 19:23:17 +03002508 if (ret)
2509 return ret;
2510
Imre Deak5a175142014-10-23 19:23:18 +03002511 return i915_drm_resume(dev);
2512}
2513
Ben Gamari11ed50e2009-09-14 17:48:45 -04002514/**
Eugeni Dodonovf3953dc2011-11-28 16:15:17 -02002515 * i915_reset - reset chip after a hang
Ben Gamari11ed50e2009-09-14 17:48:45 -04002516 * @dev: drm device to reset
Ben Gamari11ed50e2009-09-14 17:48:45 -04002517 *
2518 * Reset the chip. Useful if a hang is detected. Returns zero on successful
2519 * reset or otherwise an error code.
2520 *
2521 * Procedure is fairly simple:
2522 * - reset the chip using the reset reg
2523 * - re-init context state
2524 * - re-init hardware status page
2525 * - re-init ring buffer
2526 * - re-init interrupt state
2527 * - re-init display
2528 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002529int i915_reset(struct drm_i915_private *dev_priv)
Ben Gamari11ed50e2009-09-14 17:48:45 -04002530{
Chris Wilsonc0336662016-05-06 15:40:21 +01002531 struct drm_device *dev = dev_priv->dev;
Chris Wilsond98c52c2016-04-13 17:35:05 +01002532 struct i915_gpu_error *error = &dev_priv->gpu_error;
2533 unsigned reset_counter;
Kenneth Graunke0573ed42010-09-11 03:17:19 -07002534 int ret;
Ben Gamari11ed50e2009-09-14 17:48:45 -04002535
Chris Wilsondc979972016-05-10 14:10:04 +01002536 intel_reset_gt_powersave(dev_priv);
Imre Deakdbea3ce2014-12-15 18:59:28 +02002537
Daniel Vetterd54a02c2012-07-04 22:18:39 +02002538 mutex_lock(&dev->struct_mutex);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002539
Chris Wilsond98c52c2016-04-13 17:35:05 +01002540 /* Clear any previous failed attempts at recovery. Time to try again. */
2541 atomic_andnot(I915_WEDGED, &error->reset_counter);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002542
Chris Wilsond98c52c2016-04-13 17:35:05 +01002543 /* Clear the reset-in-progress flag and increment the reset epoch. */
2544 reset_counter = atomic_inc_return(&error->reset_counter);
2545 if (WARN_ON(__i915_reset_in_progress(reset_counter))) {
2546 ret = -EIO;
2547 goto error;
2548 }
2549
2550 i915_gem_reset(dev);
Chris Wilson2e7c8ee2013-05-28 10:38:44 +01002551
Chris Wilsondc979972016-05-10 14:10:04 +01002552 ret = intel_gpu_reset(dev_priv, ALL_ENGINES);
Daniel Vetter350d2702012-04-27 15:17:42 +02002553
Mika Kuoppalabe62acb2013-08-30 16:19:28 +03002554 /* Also reset the gpu hangman. */
Chris Wilsond98c52c2016-04-13 17:35:05 +01002555 if (error->stop_rings != 0) {
Mika Kuoppalabe62acb2013-08-30 16:19:28 +03002556 DRM_INFO("Simulated gpu hang, resetting stop_rings\n");
Chris Wilsond98c52c2016-04-13 17:35:05 +01002557 error->stop_rings = 0;
Mika Kuoppalabe62acb2013-08-30 16:19:28 +03002558 if (ret == -ENODEV) {
Daniel Vetterf2d91a22013-11-07 09:48:57 +01002559 DRM_INFO("Reset not implemented, but ignoring "
2560 "error for simulated gpu hangs\n");
Mika Kuoppalabe62acb2013-08-30 16:19:28 +03002561 ret = 0;
2562 }
Chris Wilson2e7c8ee2013-05-28 10:38:44 +01002563 }
Mika Kuoppalabe62acb2013-08-30 16:19:28 +03002564
Daniel Vetterd8f27162014-10-01 01:02:04 +02002565 if (i915_stop_ring_allow_warn(dev_priv))
2566 pr_notice("drm/i915: Resetting chip after gpu hang\n");
2567
Kenneth Graunke0573ed42010-09-11 03:17:19 -07002568 if (ret) {
Chris Wilson804e59a2016-04-13 17:35:09 +01002569 if (ret != -ENODEV)
2570 DRM_ERROR("Failed to reset chip: %i\n", ret);
2571 else
2572 DRM_DEBUG_DRIVER("GPU reset disabled\n");
Chris Wilsond98c52c2016-04-13 17:35:05 +01002573 goto error;
Ben Gamari11ed50e2009-09-14 17:48:45 -04002574 }
2575
Ville Syrjälä1362b772014-11-26 17:07:29 +02002576 intel_overlay_reset(dev_priv);
2577
Ben Gamari11ed50e2009-09-14 17:48:45 -04002578 /* Ok, now get things going again... */
2579
2580 /*
2581 * Everything depends on having the GTT running, so we need to start
2582 * there. Fortunately we don't need to do this unless we reset the
2583 * chip at a PCI level.
2584 *
2585 * Next we need to restore the context, but we don't use those
2586 * yet either...
2587 *
2588 * Ring buffer needs to be re-initialized in the KMS case, or if X
2589 * was running at the time of the reset (i.e. we weren't VT
2590 * switched away).
2591 */
Daniel Vetter33d30a92015-02-23 12:03:27 +01002592 ret = i915_gem_init_hw(dev);
Daniel Vetter33d30a92015-02-23 12:03:27 +01002593 if (ret) {
2594 DRM_ERROR("Failed hw init on reset %d\n", ret);
Chris Wilsond98c52c2016-04-13 17:35:05 +01002595 goto error;
Ben Gamari11ed50e2009-09-14 17:48:45 -04002596 }
2597
Chris Wilsond98c52c2016-04-13 17:35:05 +01002598 mutex_unlock(&dev->struct_mutex);
2599
Daniel Vetter33d30a92015-02-23 12:03:27 +01002600 /*
Daniel Vetter33d30a92015-02-23 12:03:27 +01002601 * rps/rc6 re-init is necessary to restore state lost after the
2602 * reset and the re-install of gt irqs. Skip for ironlake per
2603 * previous concerns that it doesn't respond well to some forms
2604 * of re-init after reset.
2605 */
2606 if (INTEL_INFO(dev)->gen > 5)
Chris Wilsondc979972016-05-10 14:10:04 +01002607 intel_enable_gt_powersave(dev_priv);
Daniel Vetter33d30a92015-02-23 12:03:27 +01002608
Ben Gamari11ed50e2009-09-14 17:48:45 -04002609 return 0;
Chris Wilsond98c52c2016-04-13 17:35:05 +01002610
2611error:
2612 atomic_or(I915_WEDGED, &error->reset_counter);
2613 mutex_unlock(&dev->struct_mutex);
2614 return ret;
Ben Gamari11ed50e2009-09-14 17:48:45 -04002615}
2616
Greg Kroah-Hartman56550d92012-12-21 15:09:25 -08002617static int i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Kristian Høgsberg112b7152009-01-04 16:55:33 -05002618{
Daniel Vetter01a06852012-06-25 15:58:49 +02002619 struct intel_device_info *intel_info =
2620 (struct intel_device_info *) ent->driver_data;
2621
Jani Nikulad330a952014-01-21 11:24:25 +02002622 if (IS_PRELIMINARY_HW(intel_info) && !i915.preliminary_hw_support) {
Ben Widawskyb833d682013-08-23 16:00:07 -07002623 DRM_INFO("This hardware requires preliminary hardware support.\n"
2624 "See CONFIG_DRM_I915_PRELIMINARY_HW_SUPPORT, and/or modparam preliminary_hw_support\n");
2625 return -ENODEV;
2626 }
2627
Chris Wilson5fe49d82011-02-01 19:43:02 +00002628 /* Only bind to function 0 of the device. Early generations
2629 * used function 1 as a placeholder for multi-head. This causes
2630 * us confusion instead, especially on the systems where both
2631 * functions have the same PCI-ID!
2632 */
2633 if (PCI_FUNC(pdev->devfn))
2634 return -ENODEV;
2635
Lukas Wunnerb00e5332016-05-31 11:13:27 +02002636 if (vga_switcheroo_client_probe_defer(pdev))
Lukas Wunner704ab612016-01-11 20:09:20 +01002637 return -EPROBE_DEFER;
2638
Chris Wilson0673ad42016-06-24 14:00:22 +01002639 return i915_driver_load(pdev, ent);
Kristian Høgsberg112b7152009-01-04 16:55:33 -05002640}
2641
2642static void
2643i915_pci_remove(struct pci_dev *pdev)
2644{
2645 struct drm_device *dev = pci_get_drvdata(pdev);
2646
Chris Wilson3e783ba2016-06-24 14:00:19 +01002647 i915_driver_unload(dev);
2648 drm_dev_unref(dev);
Kristian Høgsberg112b7152009-01-04 16:55:33 -05002649}
2650
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01002651static int i915_pm_suspend(struct device *dev)
Kristian Høgsberg112b7152009-01-04 16:55:33 -05002652{
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01002653 struct pci_dev *pdev = to_pci_dev(dev);
2654 struct drm_device *drm_dev = pci_get_drvdata(pdev);
Kristian Høgsberg112b7152009-01-04 16:55:33 -05002655
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01002656 if (!drm_dev || !drm_dev->dev_private) {
2657 dev_err(dev, "DRM not initialized, aborting suspend.\n");
2658 return -ENODEV;
2659 }
Kristian Høgsberg112b7152009-01-04 16:55:33 -05002660
Dave Airlie5bcf7192010-12-07 09:20:40 +10002661 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
2662 return 0;
2663
Imre Deak5e365c32014-10-23 19:23:25 +03002664 return i915_drm_suspend(drm_dev);
Imre Deak76c4b252014-04-01 19:55:22 +03002665}
2666
2667static int i915_pm_suspend_late(struct device *dev)
2668{
Imre Deak888d0d42015-01-08 17:54:13 +02002669 struct drm_device *drm_dev = dev_to_i915(dev)->dev;
Imre Deak76c4b252014-04-01 19:55:22 +03002670
2671 /*
Damien Lespiauc965d9952015-05-18 19:53:48 +01002672 * We have a suspend ordering issue with the snd-hda driver also
Imre Deak76c4b252014-04-01 19:55:22 +03002673 * requiring our device to be power up. Due to the lack of a
2674 * parent/child relationship we currently solve this with an late
2675 * suspend hook.
2676 *
2677 * FIXME: This should be solved with a special hdmi sink device or
2678 * similar so that power domains can be employed.
2679 */
2680 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
2681 return 0;
Kristian Høgsberg112b7152009-01-04 16:55:33 -05002682
Imre Deakab3be732015-03-02 13:04:41 +02002683 return i915_drm_suspend_late(drm_dev, false);
2684}
2685
2686static int i915_pm_poweroff_late(struct device *dev)
2687{
2688 struct drm_device *drm_dev = dev_to_i915(dev)->dev;
2689
2690 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
2691 return 0;
2692
2693 return i915_drm_suspend_late(drm_dev, true);
Zhenyu Wangcbda12d2009-12-16 13:36:10 +08002694}
2695
Imre Deak76c4b252014-04-01 19:55:22 +03002696static int i915_pm_resume_early(struct device *dev)
2697{
Imre Deak888d0d42015-01-08 17:54:13 +02002698 struct drm_device *drm_dev = dev_to_i915(dev)->dev;
Imre Deak76c4b252014-04-01 19:55:22 +03002699
Imre Deak097dd832014-10-23 19:23:19 +03002700 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
2701 return 0;
2702
Imre Deak5e365c32014-10-23 19:23:25 +03002703 return i915_drm_resume_early(drm_dev);
Imre Deak76c4b252014-04-01 19:55:22 +03002704}
2705
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01002706static int i915_pm_resume(struct device *dev)
Zhenyu Wangcbda12d2009-12-16 13:36:10 +08002707{
Imre Deak888d0d42015-01-08 17:54:13 +02002708 struct drm_device *drm_dev = dev_to_i915(dev)->dev;
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01002709
Imre Deak097dd832014-10-23 19:23:19 +03002710 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
2711 return 0;
2712
Imre Deak5a175142014-10-23 19:23:18 +03002713 return i915_drm_resume(drm_dev);
Zhenyu Wangcbda12d2009-12-16 13:36:10 +08002714}
2715
Chris Wilson1f19ac22016-05-14 07:26:32 +01002716/* freeze: before creating the hibernation_image */
2717static int i915_pm_freeze(struct device *dev)
2718{
2719 return i915_pm_suspend(dev);
2720}
2721
2722static int i915_pm_freeze_late(struct device *dev)
2723{
Chris Wilson461fb992016-05-14 07:26:33 +01002724 int ret;
2725
2726 ret = i915_pm_suspend_late(dev);
2727 if (ret)
2728 return ret;
2729
2730 ret = i915_gem_freeze_late(dev_to_i915(dev));
2731 if (ret)
2732 return ret;
2733
2734 return 0;
Chris Wilson1f19ac22016-05-14 07:26:32 +01002735}
2736
2737/* thaw: called after creating the hibernation image, but before turning off. */
2738static int i915_pm_thaw_early(struct device *dev)
2739{
2740 return i915_pm_resume_early(dev);
2741}
2742
2743static int i915_pm_thaw(struct device *dev)
2744{
2745 return i915_pm_resume(dev);
2746}
2747
2748/* restore: called after loading the hibernation image. */
2749static int i915_pm_restore_early(struct device *dev)
2750{
2751 return i915_pm_resume_early(dev);
2752}
2753
2754static int i915_pm_restore(struct device *dev)
2755{
2756 return i915_pm_resume(dev);
2757}
2758
Imre Deakddeea5b2014-05-05 15:19:56 +03002759/*
2760 * Save all Gunit registers that may be lost after a D3 and a subsequent
2761 * S0i[R123] transition. The list of registers needing a save/restore is
2762 * defined in the VLV2_S0IXRegs document. This documents marks all Gunit
2763 * registers in the following way:
2764 * - Driver: saved/restored by the driver
2765 * - Punit : saved/restored by the Punit firmware
2766 * - No, w/o marking: no need to save/restore, since the register is R/O or
2767 * used internally by the HW in a way that doesn't depend
2768 * keeping the content across a suspend/resume.
2769 * - Debug : used for debugging
2770 *
2771 * We save/restore all registers marked with 'Driver', with the following
2772 * exceptions:
2773 * - Registers out of use, including also registers marked with 'Debug'.
2774 * These have no effect on the driver's operation, so we don't save/restore
2775 * them to reduce the overhead.
2776 * - Registers that are fully setup by an initialization function called from
2777 * the resume path. For example many clock gating and RPS/RC6 registers.
2778 * - Registers that provide the right functionality with their reset defaults.
2779 *
2780 * TODO: Except for registers that based on the above 3 criteria can be safely
2781 * ignored, we save/restore all others, practically treating the HW context as
2782 * a black-box for the driver. Further investigation is needed to reduce the
2783 * saved/restored registers even further, by following the same 3 criteria.
2784 */
2785static void vlv_save_gunit_s0ix_state(struct drm_i915_private *dev_priv)
2786{
2787 struct vlv_s0ix_state *s = &dev_priv->vlv_s0ix_state;
2788 int i;
2789
2790 /* GAM 0x4000-0x4770 */
2791 s->wr_watermark = I915_READ(GEN7_WR_WATERMARK);
2792 s->gfx_prio_ctrl = I915_READ(GEN7_GFX_PRIO_CTRL);
2793 s->arb_mode = I915_READ(ARB_MODE);
2794 s->gfx_pend_tlb0 = I915_READ(GEN7_GFX_PEND_TLB0);
2795 s->gfx_pend_tlb1 = I915_READ(GEN7_GFX_PEND_TLB1);
2796
2797 for (i = 0; i < ARRAY_SIZE(s->lra_limits); i++)
Ville Syrjälä22dfe792015-09-18 20:03:16 +03002798 s->lra_limits[i] = I915_READ(GEN7_LRA_LIMITS(i));
Imre Deakddeea5b2014-05-05 15:19:56 +03002799
2800 s->media_max_req_count = I915_READ(GEN7_MEDIA_MAX_REQ_COUNT);
Imre Deakb5f1c972015-04-15 16:52:30 -07002801 s->gfx_max_req_count = I915_READ(GEN7_GFX_MAX_REQ_COUNT);
Imre Deakddeea5b2014-05-05 15:19:56 +03002802
2803 s->render_hwsp = I915_READ(RENDER_HWS_PGA_GEN7);
2804 s->ecochk = I915_READ(GAM_ECOCHK);
2805 s->bsd_hwsp = I915_READ(BSD_HWS_PGA_GEN7);
2806 s->blt_hwsp = I915_READ(BLT_HWS_PGA_GEN7);
2807
2808 s->tlb_rd_addr = I915_READ(GEN7_TLB_RD_ADDR);
2809
2810 /* MBC 0x9024-0x91D0, 0x8500 */
2811 s->g3dctl = I915_READ(VLV_G3DCTL);
2812 s->gsckgctl = I915_READ(VLV_GSCKGCTL);
2813 s->mbctl = I915_READ(GEN6_MBCTL);
2814
2815 /* GCP 0x9400-0x9424, 0x8100-0x810C */
2816 s->ucgctl1 = I915_READ(GEN6_UCGCTL1);
2817 s->ucgctl3 = I915_READ(GEN6_UCGCTL3);
2818 s->rcgctl1 = I915_READ(GEN6_RCGCTL1);
2819 s->rcgctl2 = I915_READ(GEN6_RCGCTL2);
2820 s->rstctl = I915_READ(GEN6_RSTCTL);
2821 s->misccpctl = I915_READ(GEN7_MISCCPCTL);
2822
2823 /* GPM 0xA000-0xAA84, 0x8000-0x80FC */
2824 s->gfxpause = I915_READ(GEN6_GFXPAUSE);
2825 s->rpdeuhwtc = I915_READ(GEN6_RPDEUHWTC);
2826 s->rpdeuc = I915_READ(GEN6_RPDEUC);
2827 s->ecobus = I915_READ(ECOBUS);
2828 s->pwrdwnupctl = I915_READ(VLV_PWRDWNUPCTL);
2829 s->rp_down_timeout = I915_READ(GEN6_RP_DOWN_TIMEOUT);
2830 s->rp_deucsw = I915_READ(GEN6_RPDEUCSW);
2831 s->rcubmabdtmr = I915_READ(GEN6_RCUBMABDTMR);
2832 s->rcedata = I915_READ(VLV_RCEDATA);
2833 s->spare2gh = I915_READ(VLV_SPAREG2H);
2834
2835 /* Display CZ domain, 0x4400C-0x4402C, 0x4F000-0x4F11F */
2836 s->gt_imr = I915_READ(GTIMR);
2837 s->gt_ier = I915_READ(GTIER);
2838 s->pm_imr = I915_READ(GEN6_PMIMR);
2839 s->pm_ier = I915_READ(GEN6_PMIER);
2840
2841 for (i = 0; i < ARRAY_SIZE(s->gt_scratch); i++)
Ville Syrjälä22dfe792015-09-18 20:03:16 +03002842 s->gt_scratch[i] = I915_READ(GEN7_GT_SCRATCH(i));
Imre Deakddeea5b2014-05-05 15:19:56 +03002843
2844 /* GT SA CZ domain, 0x100000-0x138124 */
2845 s->tilectl = I915_READ(TILECTL);
2846 s->gt_fifoctl = I915_READ(GTFIFOCTL);
2847 s->gtlc_wake_ctrl = I915_READ(VLV_GTLC_WAKE_CTRL);
2848 s->gtlc_survive = I915_READ(VLV_GTLC_SURVIVABILITY_REG);
2849 s->pmwgicz = I915_READ(VLV_PMWGICZ);
2850
2851 /* Gunit-Display CZ domain, 0x182028-0x1821CF */
2852 s->gu_ctl0 = I915_READ(VLV_GU_CTL0);
2853 s->gu_ctl1 = I915_READ(VLV_GU_CTL1);
Jesse Barnes9c252102015-04-01 14:22:57 -07002854 s->pcbr = I915_READ(VLV_PCBR);
Imre Deakddeea5b2014-05-05 15:19:56 +03002855 s->clock_gate_dis2 = I915_READ(VLV_GUNIT_CLOCK_GATE2);
2856
2857 /*
2858 * Not saving any of:
2859 * DFT, 0x9800-0x9EC0
2860 * SARB, 0xB000-0xB1FC
2861 * GAC, 0x5208-0x524C, 0x14000-0x14C000
2862 * PCI CFG
2863 */
2864}
2865
2866static void vlv_restore_gunit_s0ix_state(struct drm_i915_private *dev_priv)
2867{
2868 struct vlv_s0ix_state *s = &dev_priv->vlv_s0ix_state;
2869 u32 val;
2870 int i;
2871
2872 /* GAM 0x4000-0x4770 */
2873 I915_WRITE(GEN7_WR_WATERMARK, s->wr_watermark);
2874 I915_WRITE(GEN7_GFX_PRIO_CTRL, s->gfx_prio_ctrl);
2875 I915_WRITE(ARB_MODE, s->arb_mode | (0xffff << 16));
2876 I915_WRITE(GEN7_GFX_PEND_TLB0, s->gfx_pend_tlb0);
2877 I915_WRITE(GEN7_GFX_PEND_TLB1, s->gfx_pend_tlb1);
2878
2879 for (i = 0; i < ARRAY_SIZE(s->lra_limits); i++)
Ville Syrjälä22dfe792015-09-18 20:03:16 +03002880 I915_WRITE(GEN7_LRA_LIMITS(i), s->lra_limits[i]);
Imre Deakddeea5b2014-05-05 15:19:56 +03002881
2882 I915_WRITE(GEN7_MEDIA_MAX_REQ_COUNT, s->media_max_req_count);
Imre Deakb5f1c972015-04-15 16:52:30 -07002883 I915_WRITE(GEN7_GFX_MAX_REQ_COUNT, s->gfx_max_req_count);
Imre Deakddeea5b2014-05-05 15:19:56 +03002884
2885 I915_WRITE(RENDER_HWS_PGA_GEN7, s->render_hwsp);
2886 I915_WRITE(GAM_ECOCHK, s->ecochk);
2887 I915_WRITE(BSD_HWS_PGA_GEN7, s->bsd_hwsp);
2888 I915_WRITE(BLT_HWS_PGA_GEN7, s->blt_hwsp);
2889
2890 I915_WRITE(GEN7_TLB_RD_ADDR, s->tlb_rd_addr);
2891
2892 /* MBC 0x9024-0x91D0, 0x8500 */
2893 I915_WRITE(VLV_G3DCTL, s->g3dctl);
2894 I915_WRITE(VLV_GSCKGCTL, s->gsckgctl);
2895 I915_WRITE(GEN6_MBCTL, s->mbctl);
2896
2897 /* GCP 0x9400-0x9424, 0x8100-0x810C */
2898 I915_WRITE(GEN6_UCGCTL1, s->ucgctl1);
2899 I915_WRITE(GEN6_UCGCTL3, s->ucgctl3);
2900 I915_WRITE(GEN6_RCGCTL1, s->rcgctl1);
2901 I915_WRITE(GEN6_RCGCTL2, s->rcgctl2);
2902 I915_WRITE(GEN6_RSTCTL, s->rstctl);
2903 I915_WRITE(GEN7_MISCCPCTL, s->misccpctl);
2904
2905 /* GPM 0xA000-0xAA84, 0x8000-0x80FC */
2906 I915_WRITE(GEN6_GFXPAUSE, s->gfxpause);
2907 I915_WRITE(GEN6_RPDEUHWTC, s->rpdeuhwtc);
2908 I915_WRITE(GEN6_RPDEUC, s->rpdeuc);
2909 I915_WRITE(ECOBUS, s->ecobus);
2910 I915_WRITE(VLV_PWRDWNUPCTL, s->pwrdwnupctl);
2911 I915_WRITE(GEN6_RP_DOWN_TIMEOUT,s->rp_down_timeout);
2912 I915_WRITE(GEN6_RPDEUCSW, s->rp_deucsw);
2913 I915_WRITE(GEN6_RCUBMABDTMR, s->rcubmabdtmr);
2914 I915_WRITE(VLV_RCEDATA, s->rcedata);
2915 I915_WRITE(VLV_SPAREG2H, s->spare2gh);
2916
2917 /* Display CZ domain, 0x4400C-0x4402C, 0x4F000-0x4F11F */
2918 I915_WRITE(GTIMR, s->gt_imr);
2919 I915_WRITE(GTIER, s->gt_ier);
2920 I915_WRITE(GEN6_PMIMR, s->pm_imr);
2921 I915_WRITE(GEN6_PMIER, s->pm_ier);
2922
2923 for (i = 0; i < ARRAY_SIZE(s->gt_scratch); i++)
Ville Syrjälä22dfe792015-09-18 20:03:16 +03002924 I915_WRITE(GEN7_GT_SCRATCH(i), s->gt_scratch[i]);
Imre Deakddeea5b2014-05-05 15:19:56 +03002925
2926 /* GT SA CZ domain, 0x100000-0x138124 */
2927 I915_WRITE(TILECTL, s->tilectl);
2928 I915_WRITE(GTFIFOCTL, s->gt_fifoctl);
2929 /*
2930 * Preserve the GT allow wake and GFX force clock bit, they are not
2931 * be restored, as they are used to control the s0ix suspend/resume
2932 * sequence by the caller.
2933 */
2934 val = I915_READ(VLV_GTLC_WAKE_CTRL);
2935 val &= VLV_GTLC_ALLOWWAKEREQ;
2936 val |= s->gtlc_wake_ctrl & ~VLV_GTLC_ALLOWWAKEREQ;
2937 I915_WRITE(VLV_GTLC_WAKE_CTRL, val);
2938
2939 val = I915_READ(VLV_GTLC_SURVIVABILITY_REG);
2940 val &= VLV_GFX_CLK_FORCE_ON_BIT;
2941 val |= s->gtlc_survive & ~VLV_GFX_CLK_FORCE_ON_BIT;
2942 I915_WRITE(VLV_GTLC_SURVIVABILITY_REG, val);
2943
2944 I915_WRITE(VLV_PMWGICZ, s->pmwgicz);
2945
2946 /* Gunit-Display CZ domain, 0x182028-0x1821CF */
2947 I915_WRITE(VLV_GU_CTL0, s->gu_ctl0);
2948 I915_WRITE(VLV_GU_CTL1, s->gu_ctl1);
Jesse Barnes9c252102015-04-01 14:22:57 -07002949 I915_WRITE(VLV_PCBR, s->pcbr);
Imre Deakddeea5b2014-05-05 15:19:56 +03002950 I915_WRITE(VLV_GUNIT_CLOCK_GATE2, s->clock_gate_dis2);
2951}
2952
Imre Deak650ad972014-04-18 16:35:02 +03002953int vlv_force_gfx_clock(struct drm_i915_private *dev_priv, bool force_on)
2954{
2955 u32 val;
2956 int err;
2957
Imre Deak650ad972014-04-18 16:35:02 +03002958#define COND (I915_READ(VLV_GTLC_SURVIVABILITY_REG) & VLV_GFX_CLK_STATUS_BIT)
Imre Deak650ad972014-04-18 16:35:02 +03002959
2960 val = I915_READ(VLV_GTLC_SURVIVABILITY_REG);
2961 val &= ~VLV_GFX_CLK_FORCE_ON_BIT;
2962 if (force_on)
2963 val |= VLV_GFX_CLK_FORCE_ON_BIT;
2964 I915_WRITE(VLV_GTLC_SURVIVABILITY_REG, val);
2965
2966 if (!force_on)
2967 return 0;
2968
Imre Deak8d4eee92014-04-14 20:24:43 +03002969 err = wait_for(COND, 20);
Imre Deak650ad972014-04-18 16:35:02 +03002970 if (err)
2971 DRM_ERROR("timeout waiting for GFX clock force-on (%08x)\n",
2972 I915_READ(VLV_GTLC_SURVIVABILITY_REG));
2973
2974 return err;
2975#undef COND
2976}
2977
Imre Deakddeea5b2014-05-05 15:19:56 +03002978static int vlv_allow_gt_wake(struct drm_i915_private *dev_priv, bool allow)
2979{
2980 u32 val;
2981 int err = 0;
2982
2983 val = I915_READ(VLV_GTLC_WAKE_CTRL);
2984 val &= ~VLV_GTLC_ALLOWWAKEREQ;
2985 if (allow)
2986 val |= VLV_GTLC_ALLOWWAKEREQ;
2987 I915_WRITE(VLV_GTLC_WAKE_CTRL, val);
2988 POSTING_READ(VLV_GTLC_WAKE_CTRL);
2989
2990#define COND (!!(I915_READ(VLV_GTLC_PW_STATUS) & VLV_GTLC_ALLOWWAKEACK) == \
2991 allow)
2992 err = wait_for(COND, 1);
2993 if (err)
2994 DRM_ERROR("timeout disabling GT waking\n");
2995 return err;
2996#undef COND
2997}
2998
2999static int vlv_wait_for_gt_wells(struct drm_i915_private *dev_priv,
3000 bool wait_for_on)
3001{
3002 u32 mask;
3003 u32 val;
3004 int err;
3005
3006 mask = VLV_GTLC_PW_MEDIA_STATUS_MASK | VLV_GTLC_PW_RENDER_STATUS_MASK;
3007 val = wait_for_on ? mask : 0;
3008#define COND ((I915_READ(VLV_GTLC_PW_STATUS) & mask) == val)
3009 if (COND)
3010 return 0;
3011
3012 DRM_DEBUG_KMS("waiting for GT wells to go %s (%08x)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02003013 onoff(wait_for_on),
3014 I915_READ(VLV_GTLC_PW_STATUS));
Imre Deakddeea5b2014-05-05 15:19:56 +03003015
3016 /*
3017 * RC6 transitioning can be delayed up to 2 msec (see
3018 * valleyview_enable_rps), use 3 msec for safety.
3019 */
3020 err = wait_for(COND, 3);
3021 if (err)
3022 DRM_ERROR("timeout waiting for GT wells to go %s\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02003023 onoff(wait_for_on));
Imre Deakddeea5b2014-05-05 15:19:56 +03003024
3025 return err;
3026#undef COND
3027}
3028
3029static void vlv_check_no_gt_access(struct drm_i915_private *dev_priv)
3030{
3031 if (!(I915_READ(VLV_GTLC_PW_STATUS) & VLV_GTLC_ALLOWWAKEERR))
3032 return;
3033
Daniel Vetter6fa283b2016-01-19 21:00:56 +01003034 DRM_DEBUG_DRIVER("GT register access while GT waking disabled\n");
Imre Deakddeea5b2014-05-05 15:19:56 +03003035 I915_WRITE(VLV_GTLC_PW_STATUS, VLV_GTLC_ALLOWWAKEERR);
3036}
3037
Sagar Kambleebc32822014-08-13 23:07:05 +05303038static int vlv_suspend_complete(struct drm_i915_private *dev_priv)
Imre Deakddeea5b2014-05-05 15:19:56 +03003039{
3040 u32 mask;
3041 int err;
3042
3043 /*
3044 * Bspec defines the following GT well on flags as debug only, so
3045 * don't treat them as hard failures.
3046 */
3047 (void)vlv_wait_for_gt_wells(dev_priv, false);
3048
3049 mask = VLV_GTLC_RENDER_CTX_EXISTS | VLV_GTLC_MEDIA_CTX_EXISTS;
3050 WARN_ON((I915_READ(VLV_GTLC_WAKE_CTRL) & mask) != mask);
3051
3052 vlv_check_no_gt_access(dev_priv);
3053
3054 err = vlv_force_gfx_clock(dev_priv, true);
3055 if (err)
3056 goto err1;
3057
3058 err = vlv_allow_gt_wake(dev_priv, false);
3059 if (err)
3060 goto err2;
Deepak S98711162014-12-12 14:18:16 +05303061
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03003062 if (!IS_CHERRYVIEW(dev_priv))
Deepak S98711162014-12-12 14:18:16 +05303063 vlv_save_gunit_s0ix_state(dev_priv);
Imre Deakddeea5b2014-05-05 15:19:56 +03003064
3065 err = vlv_force_gfx_clock(dev_priv, false);
3066 if (err)
3067 goto err2;
3068
3069 return 0;
3070
3071err2:
3072 /* For safety always re-enable waking and disable gfx clock forcing */
3073 vlv_allow_gt_wake(dev_priv, true);
3074err1:
3075 vlv_force_gfx_clock(dev_priv, false);
3076
3077 return err;
3078}
3079
Sagar Kamble016970b2014-08-13 23:07:06 +05303080static int vlv_resume_prepare(struct drm_i915_private *dev_priv,
3081 bool rpm_resume)
Imre Deakddeea5b2014-05-05 15:19:56 +03003082{
3083 struct drm_device *dev = dev_priv->dev;
3084 int err;
3085 int ret;
3086
3087 /*
3088 * If any of the steps fail just try to continue, that's the best we
3089 * can do at this point. Return the first error code (which will also
3090 * leave RPM permanently disabled).
3091 */
3092 ret = vlv_force_gfx_clock(dev_priv, true);
3093
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03003094 if (!IS_CHERRYVIEW(dev_priv))
Deepak S98711162014-12-12 14:18:16 +05303095 vlv_restore_gunit_s0ix_state(dev_priv);
Imre Deakddeea5b2014-05-05 15:19:56 +03003096
3097 err = vlv_allow_gt_wake(dev_priv, true);
3098 if (!ret)
3099 ret = err;
3100
3101 err = vlv_force_gfx_clock(dev_priv, false);
3102 if (!ret)
3103 ret = err;
3104
3105 vlv_check_no_gt_access(dev_priv);
3106
Sagar Kamble016970b2014-08-13 23:07:06 +05303107 if (rpm_resume) {
3108 intel_init_clock_gating(dev);
3109 i915_gem_restore_fences(dev);
3110 }
Imre Deakddeea5b2014-05-05 15:19:56 +03003111
3112 return ret;
3113}
3114
Paulo Zanoni97bea202014-03-07 20:12:33 -03003115static int intel_runtime_suspend(struct device *device)
Paulo Zanoni8a187452013-12-06 20:32:13 -02003116{
3117 struct pci_dev *pdev = to_pci_dev(device);
3118 struct drm_device *dev = pci_get_drvdata(pdev);
3119 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak0ab9cfe2014-04-15 16:39:45 +03003120 int ret;
Paulo Zanoni8a187452013-12-06 20:32:13 -02003121
Chris Wilsondc979972016-05-10 14:10:04 +01003122 if (WARN_ON_ONCE(!(dev_priv->rps.enabled && intel_enable_rc6())))
Imre Deakc6df39b2014-04-14 20:24:29 +03003123 return -ENODEV;
3124
Imre Deak604effb2014-08-26 13:26:56 +03003125 if (WARN_ON_ONCE(!HAS_RUNTIME_PM(dev)))
3126 return -ENODEV;
3127
Paulo Zanoni8a187452013-12-06 20:32:13 -02003128 DRM_DEBUG_KMS("Suspending device\n");
3129
Imre Deak9486db62014-04-22 20:21:07 +03003130 /*
Imre Deakd6102972014-05-07 19:57:49 +03003131 * We could deadlock here in case another thread holding struct_mutex
3132 * calls RPM suspend concurrently, since the RPM suspend will wait
3133 * first for this RPM suspend to finish. In this case the concurrent
3134 * RPM resume will be followed by its RPM suspend counterpart. Still
3135 * for consistency return -EAGAIN, which will reschedule this suspend.
3136 */
3137 if (!mutex_trylock(&dev->struct_mutex)) {
3138 DRM_DEBUG_KMS("device lock contention, deffering suspend\n");
3139 /*
3140 * Bump the expiration timestamp, otherwise the suspend won't
3141 * be rescheduled.
3142 */
3143 pm_runtime_mark_last_busy(device);
3144
3145 return -EAGAIN;
3146 }
Imre Deak1f814da2015-12-16 02:52:19 +02003147
3148 disable_rpm_wakeref_asserts(dev_priv);
3149
Imre Deakd6102972014-05-07 19:57:49 +03003150 /*
3151 * We are safe here against re-faults, since the fault handler takes
3152 * an RPM reference.
3153 */
3154 i915_gem_release_all_mmaps(dev_priv);
3155 mutex_unlock(&dev->struct_mutex);
3156
Joonas Lahtinen825f2722015-12-09 15:56:13 +02003157 cancel_delayed_work_sync(&dev_priv->gpu_error.hangcheck_work);
3158
Alex Daia1c41992015-09-30 09:46:37 -07003159 intel_guc_suspend(dev);
3160
Chris Wilsondc979972016-05-10 14:10:04 +01003161 intel_suspend_gt_powersave(dev_priv);
Imre Deak2eb52522014-11-19 15:30:05 +02003162 intel_runtime_pm_disable_interrupts(dev_priv);
Imre Deakb5478bc2014-04-14 20:24:37 +03003163
Imre Deak507e1262016-04-20 20:27:54 +03003164 ret = 0;
3165 if (IS_BROXTON(dev_priv)) {
3166 bxt_display_core_uninit(dev_priv);
3167 bxt_enable_dc9(dev_priv);
3168 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3169 hsw_enable_pc8(dev_priv);
3170 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3171 ret = vlv_suspend_complete(dev_priv);
3172 }
3173
Imre Deak0ab9cfe2014-04-15 16:39:45 +03003174 if (ret) {
3175 DRM_ERROR("Runtime suspend failed, disabling it (%d)\n", ret);
Daniel Vetterb9632912014-09-30 10:56:44 +02003176 intel_runtime_pm_enable_interrupts(dev_priv);
Imre Deak0ab9cfe2014-04-15 16:39:45 +03003177
Imre Deak1f814da2015-12-16 02:52:19 +02003178 enable_rpm_wakeref_asserts(dev_priv);
3179
Imre Deak0ab9cfe2014-04-15 16:39:45 +03003180 return ret;
3181 }
Paulo Zanonia8a8bd52014-03-07 20:08:05 -03003182
Chris Wilsondc979972016-05-10 14:10:04 +01003183 intel_uncore_forcewake_reset(dev_priv, false);
Imre Deak1f814da2015-12-16 02:52:19 +02003184
3185 enable_rpm_wakeref_asserts(dev_priv);
3186 WARN_ON_ONCE(atomic_read(&dev_priv->pm.wakeref_count));
Mika Kuoppala55ec45c2015-12-15 16:25:08 +02003187
Mika Kuoppalabc3b9342016-01-08 15:51:20 +02003188 if (intel_uncore_arm_unclaimed_mmio_detection(dev_priv))
Mika Kuoppala55ec45c2015-12-15 16:25:08 +02003189 DRM_ERROR("Unclaimed access detected prior to suspending\n");
3190
Paulo Zanoni8a187452013-12-06 20:32:13 -02003191 dev_priv->pm.suspended = true;
Kristen Carlson Accardi1fb23622014-01-14 15:36:15 -08003192
3193 /*
Paulo Zanonic8a0bd42014-08-21 17:09:38 -03003194 * FIXME: We really should find a document that references the arguments
3195 * used below!
Kristen Carlson Accardi1fb23622014-01-14 15:36:15 -08003196 */
Chris Wilson6f9f4b72016-05-23 15:08:09 +01003197 if (IS_BROADWELL(dev_priv)) {
Paulo Zanonid37ae192015-07-30 18:20:29 -03003198 /*
3199 * On Broadwell, if we use PCI_D1 the PCH DDI ports will stop
3200 * being detected, and the call we do at intel_runtime_resume()
3201 * won't be able to restore them. Since PCI_D3hot matches the
3202 * actual specification and appears to be working, use it.
3203 */
Chris Wilson6f9f4b72016-05-23 15:08:09 +01003204 intel_opregion_notify_adapter(dev_priv, PCI_D3hot);
Paulo Zanonid37ae192015-07-30 18:20:29 -03003205 } else {
Paulo Zanonic8a0bd42014-08-21 17:09:38 -03003206 /*
3207 * current versions of firmware which depend on this opregion
3208 * notification have repurposed the D1 definition to mean
3209 * "runtime suspended" vs. what you would normally expect (D3)
3210 * to distinguish it from notifications that might be sent via
3211 * the suspend path.
3212 */
Chris Wilson6f9f4b72016-05-23 15:08:09 +01003213 intel_opregion_notify_adapter(dev_priv, PCI_D1);
Paulo Zanonic8a0bd42014-08-21 17:09:38 -03003214 }
Paulo Zanoni8a187452013-12-06 20:32:13 -02003215
Mika Kuoppala59bad942015-01-16 11:34:40 +02003216 assert_forcewakes_inactive(dev_priv);
Chris Wilsondc9fb092015-01-16 11:34:34 +02003217
Paulo Zanonia8a8bd52014-03-07 20:08:05 -03003218 DRM_DEBUG_KMS("Device suspended\n");
Paulo Zanoni8a187452013-12-06 20:32:13 -02003219 return 0;
3220}
3221
Paulo Zanoni97bea202014-03-07 20:12:33 -03003222static int intel_runtime_resume(struct device *device)
Paulo Zanoni8a187452013-12-06 20:32:13 -02003223{
3224 struct pci_dev *pdev = to_pci_dev(device);
3225 struct drm_device *dev = pci_get_drvdata(pdev);
3226 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni1a5df182014-10-27 17:54:32 -02003227 int ret = 0;
Paulo Zanoni8a187452013-12-06 20:32:13 -02003228
Imre Deak604effb2014-08-26 13:26:56 +03003229 if (WARN_ON_ONCE(!HAS_RUNTIME_PM(dev)))
3230 return -ENODEV;
Paulo Zanoni8a187452013-12-06 20:32:13 -02003231
3232 DRM_DEBUG_KMS("Resuming device\n");
3233
Imre Deak1f814da2015-12-16 02:52:19 +02003234 WARN_ON_ONCE(atomic_read(&dev_priv->pm.wakeref_count));
3235 disable_rpm_wakeref_asserts(dev_priv);
3236
Chris Wilson6f9f4b72016-05-23 15:08:09 +01003237 intel_opregion_notify_adapter(dev_priv, PCI_D0);
Paulo Zanoni8a187452013-12-06 20:32:13 -02003238 dev_priv->pm.suspended = false;
Mika Kuoppala55ec45c2015-12-15 16:25:08 +02003239 if (intel_uncore_unclaimed_mmio(dev_priv))
3240 DRM_DEBUG_DRIVER("Unclaimed access during suspend, bios?\n");
Paulo Zanoni8a187452013-12-06 20:32:13 -02003241
Alex Daia1c41992015-09-30 09:46:37 -07003242 intel_guc_resume(dev);
3243
Paulo Zanoni1a5df182014-10-27 17:54:32 -02003244 if (IS_GEN6(dev_priv))
3245 intel_init_pch_refclk(dev);
Suketu Shah31335ce2014-11-24 13:37:45 +05303246
Imre Deak507e1262016-04-20 20:27:54 +03003247 if (IS_BROXTON(dev)) {
3248 bxt_disable_dc9(dev_priv);
3249 bxt_display_core_init(dev_priv, true);
Imre Deakf62c79b2016-04-20 20:27:57 +03003250 if (dev_priv->csr.dmc_payload &&
3251 (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5))
3252 gen9_enable_dc5(dev_priv);
Imre Deak507e1262016-04-20 20:27:54 +03003253 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Paulo Zanoni1a5df182014-10-27 17:54:32 -02003254 hsw_disable_pc8(dev_priv);
Imre Deak507e1262016-04-20 20:27:54 +03003255 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Paulo Zanoni1a5df182014-10-27 17:54:32 -02003256 ret = vlv_resume_prepare(dev_priv, true);
Imre Deak507e1262016-04-20 20:27:54 +03003257 }
Paulo Zanoni1a5df182014-10-27 17:54:32 -02003258
Imre Deak0ab9cfe2014-04-15 16:39:45 +03003259 /*
3260 * No point of rolling back things in case of an error, as the best
3261 * we can do is to hope that things will still work (and disable RPM).
3262 */
Imre Deak92b806d2014-04-14 20:24:39 +03003263 i915_gem_init_swizzling(dev);
Chris Wilsondc979972016-05-10 14:10:04 +01003264 gen6_update_ring_freq(dev_priv);
Imre Deak92b806d2014-04-14 20:24:39 +03003265
Daniel Vetterb9632912014-09-30 10:56:44 +02003266 intel_runtime_pm_enable_interrupts(dev_priv);
Ville Syrjälä08d8a232015-08-27 23:56:08 +03003267
3268 /*
3269 * On VLV/CHV display interrupts are part of the display
3270 * power well, so hpd is reinitialized from there. For
3271 * everyone else do it here.
3272 */
Wayne Boyer666a4532015-12-09 12:29:35 -08003273 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
Ville Syrjälä08d8a232015-08-27 23:56:08 +03003274 intel_hpd_init(dev_priv);
3275
Chris Wilsondc979972016-05-10 14:10:04 +01003276 intel_enable_gt_powersave(dev_priv);
Imre Deakb5478bc2014-04-14 20:24:37 +03003277
Imre Deak1f814da2015-12-16 02:52:19 +02003278 enable_rpm_wakeref_asserts(dev_priv);
3279
Imre Deak0ab9cfe2014-04-15 16:39:45 +03003280 if (ret)
3281 DRM_ERROR("Runtime resume failed, disabling it (%d)\n", ret);
3282 else
3283 DRM_DEBUG_KMS("Device resumed\n");
3284
3285 return ret;
Paulo Zanoni8a187452013-12-06 20:32:13 -02003286}
3287
Chris Wilsonb4b78d12010-06-06 15:40:20 +01003288static const struct dev_pm_ops i915_pm_ops = {
Imre Deak5545dbb2014-10-23 19:23:28 +03003289 /*
3290 * S0ix (via system suspend) and S3 event handlers [PMSG_SUSPEND,
3291 * PMSG_RESUME]
3292 */
Akshay Joshi0206e352011-08-16 15:34:10 -04003293 .suspend = i915_pm_suspend,
Imre Deak76c4b252014-04-01 19:55:22 +03003294 .suspend_late = i915_pm_suspend_late,
3295 .resume_early = i915_pm_resume_early,
Akshay Joshi0206e352011-08-16 15:34:10 -04003296 .resume = i915_pm_resume,
Imre Deak5545dbb2014-10-23 19:23:28 +03003297
3298 /*
3299 * S4 event handlers
3300 * @freeze, @freeze_late : called (1) before creating the
3301 * hibernation image [PMSG_FREEZE] and
3302 * (2) after rebooting, before restoring
3303 * the image [PMSG_QUIESCE]
3304 * @thaw, @thaw_early : called (1) after creating the hibernation
3305 * image, before writing it [PMSG_THAW]
3306 * and (2) after failing to create or
3307 * restore the image [PMSG_RECOVER]
3308 * @poweroff, @poweroff_late: called after writing the hibernation
3309 * image, before rebooting [PMSG_HIBERNATE]
3310 * @restore, @restore_early : called after rebooting and restoring the
3311 * hibernation image [PMSG_RESTORE]
3312 */
Chris Wilson1f19ac22016-05-14 07:26:32 +01003313 .freeze = i915_pm_freeze,
3314 .freeze_late = i915_pm_freeze_late,
3315 .thaw_early = i915_pm_thaw_early,
3316 .thaw = i915_pm_thaw,
Imre Deak36d61e62014-10-23 19:23:24 +03003317 .poweroff = i915_pm_suspend,
Imre Deakab3be732015-03-02 13:04:41 +02003318 .poweroff_late = i915_pm_poweroff_late,
Chris Wilson1f19ac22016-05-14 07:26:32 +01003319 .restore_early = i915_pm_restore_early,
3320 .restore = i915_pm_restore,
Imre Deak5545dbb2014-10-23 19:23:28 +03003321
3322 /* S0ix (via runtime suspend) event handlers */
Paulo Zanoni97bea202014-03-07 20:12:33 -03003323 .runtime_suspend = intel_runtime_suspend,
3324 .runtime_resume = intel_runtime_resume,
Zhenyu Wangcbda12d2009-12-16 13:36:10 +08003325};
3326
Laurent Pinchart78b68552012-05-17 13:27:22 +02003327static const struct vm_operations_struct i915_gem_vm_ops = {
Jesse Barnesde151cf2008-11-12 10:03:55 -08003328 .fault = i915_gem_fault,
Jesse Barnesab00b3e2009-02-11 14:01:46 -08003329 .open = drm_gem_vm_open,
3330 .close = drm_gem_vm_close,
Jesse Barnesde151cf2008-11-12 10:03:55 -08003331};
3332
Arjan van de Vene08e96d2011-10-31 07:28:57 -07003333static const struct file_operations i915_driver_fops = {
3334 .owner = THIS_MODULE,
3335 .open = drm_open,
3336 .release = drm_release,
3337 .unlocked_ioctl = drm_ioctl,
3338 .mmap = drm_gem_mmap,
3339 .poll = drm_poll,
Arjan van de Vene08e96d2011-10-31 07:28:57 -07003340 .read = drm_read,
3341#ifdef CONFIG_COMPAT
3342 .compat_ioctl = i915_compat_ioctl,
3343#endif
3344 .llseek = noop_llseek,
3345};
3346
Chris Wilson0673ad42016-06-24 14:00:22 +01003347static int
3348i915_gem_reject_pin_ioctl(struct drm_device *dev, void *data,
3349 struct drm_file *file)
3350{
3351 return -ENODEV;
3352}
3353
3354static const struct drm_ioctl_desc i915_ioctls[] = {
3355 DRM_IOCTL_DEF_DRV(I915_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
3356 DRM_IOCTL_DEF_DRV(I915_FLUSH, drm_noop, DRM_AUTH),
3357 DRM_IOCTL_DEF_DRV(I915_FLIP, drm_noop, DRM_AUTH),
3358 DRM_IOCTL_DEF_DRV(I915_BATCHBUFFER, drm_noop, DRM_AUTH),
3359 DRM_IOCTL_DEF_DRV(I915_IRQ_EMIT, drm_noop, DRM_AUTH),
3360 DRM_IOCTL_DEF_DRV(I915_IRQ_WAIT, drm_noop, DRM_AUTH),
3361 DRM_IOCTL_DEF_DRV(I915_GETPARAM, i915_getparam, DRM_AUTH|DRM_RENDER_ALLOW),
3362 DRM_IOCTL_DEF_DRV(I915_SETPARAM, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
3363 DRM_IOCTL_DEF_DRV(I915_ALLOC, drm_noop, DRM_AUTH),
3364 DRM_IOCTL_DEF_DRV(I915_FREE, drm_noop, DRM_AUTH),
3365 DRM_IOCTL_DEF_DRV(I915_INIT_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
3366 DRM_IOCTL_DEF_DRV(I915_CMDBUFFER, drm_noop, DRM_AUTH),
3367 DRM_IOCTL_DEF_DRV(I915_DESTROY_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
3368 DRM_IOCTL_DEF_DRV(I915_SET_VBLANK_PIPE, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
3369 DRM_IOCTL_DEF_DRV(I915_GET_VBLANK_PIPE, drm_noop, DRM_AUTH),
3370 DRM_IOCTL_DEF_DRV(I915_VBLANK_SWAP, drm_noop, DRM_AUTH),
3371 DRM_IOCTL_DEF_DRV(I915_HWS_ADDR, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
3372 DRM_IOCTL_DEF_DRV(I915_GEM_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
3373 DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER, i915_gem_execbuffer, DRM_AUTH),
3374 DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER2, i915_gem_execbuffer2, DRM_AUTH|DRM_RENDER_ALLOW),
3375 DRM_IOCTL_DEF_DRV(I915_GEM_PIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY),
3376 DRM_IOCTL_DEF_DRV(I915_GEM_UNPIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY),
3377 DRM_IOCTL_DEF_DRV(I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
3378 DRM_IOCTL_DEF_DRV(I915_GEM_SET_CACHING, i915_gem_set_caching_ioctl, DRM_RENDER_ALLOW),
3379 DRM_IOCTL_DEF_DRV(I915_GEM_GET_CACHING, i915_gem_get_caching_ioctl, DRM_RENDER_ALLOW),
3380 DRM_IOCTL_DEF_DRV(I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
3381 DRM_IOCTL_DEF_DRV(I915_GEM_ENTERVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
3382 DRM_IOCTL_DEF_DRV(I915_GEM_LEAVEVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
3383 DRM_IOCTL_DEF_DRV(I915_GEM_CREATE, i915_gem_create_ioctl, DRM_RENDER_ALLOW),
3384 DRM_IOCTL_DEF_DRV(I915_GEM_PREAD, i915_gem_pread_ioctl, DRM_RENDER_ALLOW),
3385 DRM_IOCTL_DEF_DRV(I915_GEM_PWRITE, i915_gem_pwrite_ioctl, DRM_RENDER_ALLOW),
3386 DRM_IOCTL_DEF_DRV(I915_GEM_MMAP, i915_gem_mmap_ioctl, DRM_RENDER_ALLOW),
3387 DRM_IOCTL_DEF_DRV(I915_GEM_MMAP_GTT, i915_gem_mmap_gtt_ioctl, DRM_RENDER_ALLOW),
3388 DRM_IOCTL_DEF_DRV(I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, DRM_RENDER_ALLOW),
3389 DRM_IOCTL_DEF_DRV(I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, DRM_RENDER_ALLOW),
3390 DRM_IOCTL_DEF_DRV(I915_GEM_SET_TILING, i915_gem_set_tiling, DRM_RENDER_ALLOW),
3391 DRM_IOCTL_DEF_DRV(I915_GEM_GET_TILING, i915_gem_get_tiling, DRM_RENDER_ALLOW),
3392 DRM_IOCTL_DEF_DRV(I915_GEM_GET_APERTURE, i915_gem_get_aperture_ioctl, DRM_RENDER_ALLOW),
3393 DRM_IOCTL_DEF_DRV(I915_GET_PIPE_FROM_CRTC_ID, intel_get_pipe_from_crtc_id, 0),
3394 DRM_IOCTL_DEF_DRV(I915_GEM_MADVISE, i915_gem_madvise_ioctl, DRM_RENDER_ALLOW),
3395 DRM_IOCTL_DEF_DRV(I915_OVERLAY_PUT_IMAGE, intel_overlay_put_image_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW),
3396 DRM_IOCTL_DEF_DRV(I915_OVERLAY_ATTRS, intel_overlay_attrs_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW),
3397 DRM_IOCTL_DEF_DRV(I915_SET_SPRITE_COLORKEY, intel_sprite_set_colorkey, DRM_MASTER|DRM_CONTROL_ALLOW),
3398 DRM_IOCTL_DEF_DRV(I915_GET_SPRITE_COLORKEY, drm_noop, DRM_MASTER|DRM_CONTROL_ALLOW),
3399 DRM_IOCTL_DEF_DRV(I915_GEM_WAIT, i915_gem_wait_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
3400 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_CREATE, i915_gem_context_create_ioctl, DRM_RENDER_ALLOW),
3401 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_DESTROY, i915_gem_context_destroy_ioctl, DRM_RENDER_ALLOW),
3402 DRM_IOCTL_DEF_DRV(I915_REG_READ, i915_reg_read_ioctl, DRM_RENDER_ALLOW),
3403 DRM_IOCTL_DEF_DRV(I915_GET_RESET_STATS, i915_gem_context_reset_stats_ioctl, DRM_RENDER_ALLOW),
3404 DRM_IOCTL_DEF_DRV(I915_GEM_USERPTR, i915_gem_userptr_ioctl, DRM_RENDER_ALLOW),
3405 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_GETPARAM, i915_gem_context_getparam_ioctl, DRM_RENDER_ALLOW),
3406 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_SETPARAM, i915_gem_context_setparam_ioctl, DRM_RENDER_ALLOW),
3407};
3408
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409static struct drm_driver driver = {
Michael Witten0c547812011-08-25 17:55:54 +00003410 /* Don't use MTRRs here; the Xserver or userspace app should
3411 * deal with them for Intel hardware.
Dave Airlie792d2b92005-11-11 23:30:27 +11003412 */
Eric Anholt673a3942008-07-30 12:06:12 -07003413 .driver_features =
Kristian Høgsberg10ba5012013-08-25 18:29:01 +02003414 DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | DRIVER_PRIME |
Maarten Lankhorst1751fcf2015-08-27 15:15:15 +02003415 DRIVER_RENDER | DRIVER_MODESET,
Eric Anholt673a3942008-07-30 12:06:12 -07003416 .open = i915_driver_open,
Dave Airlie22eae942005-11-10 22:16:34 +11003417 .lastclose = i915_driver_lastclose,
3418 .preclose = i915_driver_preclose,
Eric Anholt673a3942008-07-30 12:06:12 -07003419 .postclose = i915_driver_postclose,
David Herrmann915b4d12014-08-29 12:12:43 +02003420 .set_busid = drm_pci_set_busid,
Rafael J. Wysockid8e29202010-01-09 00:45:33 +01003421
Eric Anholt673a3942008-07-30 12:06:12 -07003422 .gem_free_object = i915_gem_free_object,
Jesse Barnesde151cf2008-11-12 10:03:55 -08003423 .gem_vm_ops = &i915_gem_vm_ops,
Daniel Vetter1286ff72012-05-10 15:25:09 +02003424
3425 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
3426 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
3427 .gem_prime_export = i915_gem_prime_export,
3428 .gem_prime_import = i915_gem_prime_import,
3429
Dave Airlieff72145b2011-02-07 12:16:14 +10003430 .dumb_create = i915_gem_dumb_create,
Dave Airlieda6b51d2014-12-24 13:11:17 +10003431 .dumb_map_offset = i915_gem_mmap_gtt,
Daniel Vetter43387b32013-07-16 09:12:04 +02003432 .dumb_destroy = drm_gem_dumb_destroy,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 .ioctls = i915_ioctls,
Chris Wilson0673ad42016-06-24 14:00:22 +01003434 .num_ioctls = ARRAY_SIZE(i915_ioctls),
Arjan van de Vene08e96d2011-10-31 07:28:57 -07003435 .fops = &i915_driver_fops,
Dave Airlie22eae942005-11-10 22:16:34 +11003436 .name = DRIVER_NAME,
3437 .desc = DRIVER_DESC,
3438 .date = DRIVER_DATE,
3439 .major = DRIVER_MAJOR,
3440 .minor = DRIVER_MINOR,
3441 .patchlevel = DRIVER_PATCHLEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442};
3443
Dave Airlie8410ea32010-12-15 03:16:38 +10003444static struct pci_driver i915_pci_driver = {
3445 .name = DRIVER_NAME,
3446 .id_table = pciidlist,
3447 .probe = i915_pci_probe,
3448 .remove = i915_pci_remove,
3449 .driver.pm = &i915_pm_ops,
3450};
3451
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452static int __init i915_init(void)
3453{
Jesse Barnes79e53942008-11-07 14:24:08 -08003454 /*
Chris Wilsonfd930472015-06-19 20:27:27 +01003455 * Enable KMS by default, unless explicitly overriden by
3456 * either the i915.modeset prarameter or by the
3457 * vga_text_mode_force boot option.
Jesse Barnes79e53942008-11-07 14:24:08 -08003458 */
Chris Wilsonfd930472015-06-19 20:27:27 +01003459
3460 if (i915.modeset == 0)
3461 driver.driver_features &= ~DRIVER_MODESET;
Jesse Barnes79e53942008-11-07 14:24:08 -08003462
Jani Nikulad330a952014-01-21 11:24:25 +02003463 if (vgacon_text_force() && i915.modeset == -1)
Jesse Barnes79e53942008-11-07 14:24:08 -08003464 driver.driver_features &= ~DRIVER_MODESET;
Jesse Barnes79e53942008-11-07 14:24:08 -08003465
Daniel Vetterb30324a2013-11-13 22:11:25 +01003466 if (!(driver.driver_features & DRIVER_MODESET)) {
Daniel Vetterb30324a2013-11-13 22:11:25 +01003467 /* Silently fail loading to not upset userspace. */
Frank Binnsc2dac862016-06-24 14:00:25 +01003468 DRM_DEBUG_DRIVER("KMS disabled.\n");
Daniel Vetterb30324a2013-11-13 22:11:25 +01003469 return 0;
Daniel Vetterb30324a2013-11-13 22:11:25 +01003470 }
Chris Wilson3885c6b2011-01-23 10:45:14 +00003471
Maarten Lankhorstc5b852f2015-08-26 09:29:56 +02003472 if (i915.nuclear_pageflip)
Matt Roperb2e77232015-01-22 16:53:12 -08003473 driver.driver_features |= DRIVER_ATOMIC;
3474
Dave Airlie8410ea32010-12-15 03:16:38 +10003475 return drm_pci_init(&driver, &i915_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476}
3477
3478static void __exit i915_exit(void)
3479{
Daniel Vetterb33ecdd2013-11-15 17:16:33 +01003480 if (!(driver.driver_features & DRIVER_MODESET))
3481 return; /* Never loaded a driver. */
Daniel Vetterb33ecdd2013-11-15 17:16:33 +01003482
Dave Airlie8410ea32010-12-15 03:16:38 +10003483 drm_pci_exit(&driver, &i915_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484}
3485
3486module_init(i915_init);
3487module_exit(i915_exit);
3488
Damien Lespiau0a6d1632014-08-27 11:30:20 +01003489MODULE_AUTHOR("Tungsten Graphics, Inc.");
Damien Lespiau1eab9232014-08-27 11:30:21 +01003490MODULE_AUTHOR("Intel Corporation");
Damien Lespiau0a6d1632014-08-27 11:30:20 +01003491
Dave Airlieb5e89ed2005-09-25 14:28:13 +10003492MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493MODULE_LICENSE("GPL and additional rights");