drm/i915/chv: Determine CHV slice/subslice/EU info
[deliverable/linux.git] / drivers / gpu / drm / i915 / i915_dma.c
CommitLineData
1da177e4
LT
1/* i915_dma.c -- DMA support for the I915 -*- linux-c -*-
2 */
0d6aa60b 3/*
1da177e4
LT
4 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * All Rights Reserved.
bc54fd1a
DA
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
0d6aa60b 27 */
1da177e4 28
a70491cc
JP
29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
d1d70677 31#include <linux/async.h>
760285e7
DH
32#include <drm/drmP.h>
33#include <drm/drm_crtc_helper.h>
34#include <drm/drm_fb_helper.h>
4f03b1fc 35#include <drm/drm_legacy.h>
79e53945 36#include "intel_drv.h"
760285e7 37#include <drm/i915_drm.h>
1da177e4 38#include "i915_drv.h"
e21fd552 39#include "i915_vgpu.h"
1c5d22f7 40#include "i915_trace.h"
dcdb1674 41#include <linux/pci.h>
a4de0526
DV
42#include <linux/console.h>
43#include <linux/vt.h>
28d52043 44#include <linux/vgaarb.h>
c4804411
ZW
45#include <linux/acpi.h>
46#include <linux/pnp.h>
6a9ee8af 47#include <linux/vga_switcheroo.h>
5a0e3ad6 48#include <linux/slab.h>
44834a67 49#include <acpi/video.h>
8a187455
PZ
50#include <linux/pm.h>
51#include <linux/pm_runtime.h>
4bdc7293 52#include <linux/oom.h>
1da177e4 53
1da177e4 54
c153f45f
EA
55static int i915_getparam(struct drm_device *dev, void *data,
56 struct drm_file *file_priv)
1da177e4 57{
4c8a4be9 58 struct drm_i915_private *dev_priv = dev->dev_private;
c153f45f 59 drm_i915_getparam_t *param = data;
1da177e4
LT
60 int value;
61
c153f45f 62 switch (param->param) {
1da177e4 63 case I915_PARAM_IRQ_ACTIVE:
1da177e4 64 case I915_PARAM_ALLOW_BATCHBUFFER:
0d6aa60b 65 case I915_PARAM_LAST_DISPATCH:
ac883c84 66 /* Reject all old ums/dri params. */
5c6c6003 67 return -ENODEV;
ed4c9c4a 68 case I915_PARAM_CHIPSET_ID:
ffbab09b 69 value = dev->pdev->device;
ed4c9c4a 70 break;
27cd4461
NR
71 case I915_PARAM_REVISION:
72 value = dev->pdev->revision;
73 break;
673a394b 74 case I915_PARAM_HAS_GEM:
2e895b17 75 value = 1;
673a394b 76 break;
0f973f27
JB
77 case I915_PARAM_NUM_FENCES_AVAIL:
78 value = dev_priv->num_fence_regs - dev_priv->fence_reg_start;
79 break;
02e792fb
DV
80 case I915_PARAM_HAS_OVERLAY:
81 value = dev_priv->overlay ? 1 : 0;
82 break;
e9560f7c
JB
83 case I915_PARAM_HAS_PAGEFLIPPING:
84 value = 1;
85 break;
76446cac
JB
86 case I915_PARAM_HAS_EXECBUF2:
87 /* depends on GEM */
2e895b17 88 value = 1;
76446cac 89 break;
e3a815fc 90 case I915_PARAM_HAS_BSD:
edc912f5 91 value = intel_ring_initialized(&dev_priv->ring[VCS]);
e3a815fc 92 break;
549f7365 93 case I915_PARAM_HAS_BLT:
edc912f5 94 value = intel_ring_initialized(&dev_priv->ring[BCS]);
549f7365 95 break;
a1f2cc73
XH
96 case I915_PARAM_HAS_VEBOX:
97 value = intel_ring_initialized(&dev_priv->ring[VECS]);
98 break;
08e16dc8
ZG
99 case I915_PARAM_HAS_BSD2:
100 value = intel_ring_initialized(&dev_priv->ring[VCS2]);
101 break;
a00b10c3
CW
102 case I915_PARAM_HAS_RELAXED_FENCING:
103 value = 1;
104 break;
bbf0c6b3
DV
105 case I915_PARAM_HAS_COHERENT_RINGS:
106 value = 1;
107 break;
72bfa19c
CW
108 case I915_PARAM_HAS_EXEC_CONSTANTS:
109 value = INTEL_INFO(dev)->gen >= 4;
110 break;
271d81b8
CW
111 case I915_PARAM_HAS_RELAXED_DELTA:
112 value = 1;
113 break;
ae662d31
EA
114 case I915_PARAM_HAS_GEN7_SOL_RESET:
115 value = 1;
116 break;
3d29b842
ED
117 case I915_PARAM_HAS_LLC:
118 value = HAS_LLC(dev);
119 break;
651d794f
CW
120 case I915_PARAM_HAS_WT:
121 value = HAS_WT(dev);
122 break;
777ee96f 123 case I915_PARAM_HAS_ALIASING_PPGTT:
896ab1a5 124 value = USES_PPGTT(dev);
777ee96f 125 break;
172cf15d
BW
126 case I915_PARAM_HAS_WAIT_TIMEOUT:
127 value = 1;
128 break;
2fedbff9
CW
129 case I915_PARAM_HAS_SEMAPHORES:
130 value = i915_semaphore_is_enabled(dev);
131 break;
ec6f1bb9
DA
132 case I915_PARAM_HAS_PRIME_VMAP_FLUSH:
133 value = 1;
134 break;
d7d4eedd
CW
135 case I915_PARAM_HAS_SECURE_BATCHES:
136 value = capable(CAP_SYS_ADMIN);
137 break;
b45305fc
DV
138 case I915_PARAM_HAS_PINNED_BATCHES:
139 value = 1;
140 break;
ed5982e6
DV
141 case I915_PARAM_HAS_EXEC_NO_RELOC:
142 value = 1;
143 break;
eef90ccb
CW
144 case I915_PARAM_HAS_EXEC_HANDLE_LUT:
145 value = 1;
146 break;
d728c8ef
BV
147 case I915_PARAM_CMD_PARSER_VERSION:
148 value = i915_cmd_parser_get_version();
149 break;
6a2c4232
CW
150 case I915_PARAM_HAS_COHERENT_PHYS_GTT:
151 value = 1;
1816f923
AG
152 break;
153 case I915_PARAM_MMAP_VERSION:
154 value = 1;
6a2c4232 155 break;
1da177e4 156 default:
e29c32da 157 DRM_DEBUG("Unknown parameter %d\n", param->param);
20caafa6 158 return -EINVAL;
1da177e4
LT
159 }
160
1d6ac185
DV
161 if (copy_to_user(param->value, &value, sizeof(int))) {
162 DRM_ERROR("copy_to_user failed\n");
20caafa6 163 return -EFAULT;
1da177e4
LT
164 }
165
166 return 0;
167}
168
c153f45f
EA
169static int i915_setparam(struct drm_device *dev, void *data,
170 struct drm_file *file_priv)
1da177e4 171{
4c8a4be9 172 struct drm_i915_private *dev_priv = dev->dev_private;
c153f45f 173 drm_i915_setparam_t *param = data;
1da177e4 174
c153f45f 175 switch (param->param) {
1da177e4 176 case I915_SETPARAM_USE_MI_BATCHBUFFER_START:
1da177e4 177 case I915_SETPARAM_TEX_LRU_LOG_GRANULARITY:
1da177e4 178 case I915_SETPARAM_ALLOW_BATCHBUFFER:
ac883c84 179 /* Reject all old ums/dri params. */
5c6c6003
CW
180 return -ENODEV;
181
0f973f27
JB
182 case I915_SETPARAM_NUM_USED_FENCES:
183 if (param->value > dev_priv->num_fence_regs ||
184 param->value < 0)
185 return -EINVAL;
186 /* Userspace can use first N regs */
187 dev_priv->fence_reg_start = param->value;
188 break;
1da177e4 189 default:
8a4c47f3 190 DRM_DEBUG_DRIVER("unknown parameter %d\n",
be25ed9c 191 param->param);
20caafa6 192 return -EINVAL;
1da177e4
LT
193 }
194
195 return 0;
196}
197
ec2a4c3f
DA
198static int i915_get_bridge_dev(struct drm_device *dev)
199{
200 struct drm_i915_private *dev_priv = dev->dev_private;
201
0206e353 202 dev_priv->bridge_dev = pci_get_bus_and_slot(0, PCI_DEVFN(0, 0));
ec2a4c3f
DA
203 if (!dev_priv->bridge_dev) {
204 DRM_ERROR("bridge device not found\n");
205 return -1;
206 }
207 return 0;
208}
209
c4804411
ZW
210#define MCHBAR_I915 0x44
211#define MCHBAR_I965 0x48
212#define MCHBAR_SIZE (4*4096)
213
214#define DEVEN_REG 0x54
215#define DEVEN_MCHBAR_EN (1 << 28)
216
217/* Allocate space for the MCH regs if needed, return nonzero on error */
218static int
219intel_alloc_mchbar_resource(struct drm_device *dev)
220{
4c8a4be9 221 struct drm_i915_private *dev_priv = dev->dev_private;
a6c45cf0 222 int reg = INTEL_INFO(dev)->gen >= 4 ? MCHBAR_I965 : MCHBAR_I915;
c4804411
ZW
223 u32 temp_lo, temp_hi = 0;
224 u64 mchbar_addr;
a25c25c2 225 int ret;
c4804411 226
a6c45cf0 227 if (INTEL_INFO(dev)->gen >= 4)
c4804411
ZW
228 pci_read_config_dword(dev_priv->bridge_dev, reg + 4, &temp_hi);
229 pci_read_config_dword(dev_priv->bridge_dev, reg, &temp_lo);
230 mchbar_addr = ((u64)temp_hi << 32) | temp_lo;
231
232 /* If ACPI doesn't have it, assume we need to allocate it ourselves */
233#ifdef CONFIG_PNP
234 if (mchbar_addr &&
a25c25c2
CW
235 pnp_range_reserved(mchbar_addr, mchbar_addr + MCHBAR_SIZE))
236 return 0;
c4804411
ZW
237#endif
238
239 /* Get some space for it */
a25c25c2
CW
240 dev_priv->mch_res.name = "i915 MCHBAR";
241 dev_priv->mch_res.flags = IORESOURCE_MEM;
242 ret = pci_bus_alloc_resource(dev_priv->bridge_dev->bus,
243 &dev_priv->mch_res,
c4804411
ZW
244 MCHBAR_SIZE, MCHBAR_SIZE,
245 PCIBIOS_MIN_MEM,
a25c25c2 246 0, pcibios_align_resource,
c4804411
ZW
247 dev_priv->bridge_dev);
248 if (ret) {
249 DRM_DEBUG_DRIVER("failed bus alloc: %d\n", ret);
250 dev_priv->mch_res.start = 0;
a25c25c2 251 return ret;
c4804411
ZW
252 }
253
a6c45cf0 254 if (INTEL_INFO(dev)->gen >= 4)
c4804411
ZW
255 pci_write_config_dword(dev_priv->bridge_dev, reg + 4,
256 upper_32_bits(dev_priv->mch_res.start));
257
258 pci_write_config_dword(dev_priv->bridge_dev, reg,
259 lower_32_bits(dev_priv->mch_res.start));
a25c25c2 260 return 0;
c4804411
ZW
261}
262
263/* Setup MCHBAR if possible, return true if we should disable it again */
264static void
265intel_setup_mchbar(struct drm_device *dev)
266{
4c8a4be9 267 struct drm_i915_private *dev_priv = dev->dev_private;
a6c45cf0 268 int mchbar_reg = INTEL_INFO(dev)->gen >= 4 ? MCHBAR_I965 : MCHBAR_I915;
c4804411
ZW
269 u32 temp;
270 bool enabled;
271
11ea8b7d
JB
272 if (IS_VALLEYVIEW(dev))
273 return;
274
c4804411
ZW
275 dev_priv->mchbar_need_disable = false;
276
277 if (IS_I915G(dev) || IS_I915GM(dev)) {
278 pci_read_config_dword(dev_priv->bridge_dev, DEVEN_REG, &temp);
279 enabled = !!(temp & DEVEN_MCHBAR_EN);
280 } else {
281 pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp);
282 enabled = temp & 1;
283 }
284
285 /* If it's already enabled, don't have to do anything */
286 if (enabled)
287 return;
288
289 if (intel_alloc_mchbar_resource(dev))
290 return;
291
292 dev_priv->mchbar_need_disable = true;
293
294 /* Space is allocated or reserved, so enable it. */
295 if (IS_I915G(dev) || IS_I915GM(dev)) {
296 pci_write_config_dword(dev_priv->bridge_dev, DEVEN_REG,
297 temp | DEVEN_MCHBAR_EN);
298 } else {
299 pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp);
300 pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp | 1);
301 }
302}
303
304static void
305intel_teardown_mchbar(struct drm_device *dev)
306{
4c8a4be9 307 struct drm_i915_private *dev_priv = dev->dev_private;
a6c45cf0 308 int mchbar_reg = INTEL_INFO(dev)->gen >= 4 ? MCHBAR_I965 : MCHBAR_I915;
c4804411
ZW
309 u32 temp;
310
311 if (dev_priv->mchbar_need_disable) {
312 if (IS_I915G(dev) || IS_I915GM(dev)) {
313 pci_read_config_dword(dev_priv->bridge_dev, DEVEN_REG, &temp);
314 temp &= ~DEVEN_MCHBAR_EN;
315 pci_write_config_dword(dev_priv->bridge_dev, DEVEN_REG, temp);
316 } else {
317 pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp);
318 temp &= ~1;
319 pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp);
320 }
321 }
322
323 if (dev_priv->mch_res.start)
324 release_resource(&dev_priv->mch_res);
325}
326
28d52043
DA
327/* true = enable decode, false = disable decoder */
328static unsigned int i915_vga_set_decode(void *cookie, bool state)
329{
330 struct drm_device *dev = cookie;
331
332 intel_modeset_vga_set_state(dev, state);
333 if (state)
334 return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
335 VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
336 else
337 return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
338}
339
6a9ee8af
DA
340static void i915_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state)
341{
342 struct drm_device *dev = pci_get_drvdata(pdev);
343 pm_message_t pmm = { .event = PM_EVENT_SUSPEND };
1a5036bf 344
6a9ee8af 345 if (state == VGA_SWITCHEROO_ON) {
a70491cc 346 pr_info("switched on\n");
5bcf719b 347 dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
6a9ee8af
DA
348 /* i915 resume handler doesn't set to D0 */
349 pci_set_power_state(dev->pdev, PCI_D0);
fc49b3da 350 i915_resume_legacy(dev);
5bcf719b 351 dev->switch_power_state = DRM_SWITCH_POWER_ON;
6a9ee8af 352 } else {
a70491cc 353 pr_err("switched off\n");
5bcf719b 354 dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
fc49b3da 355 i915_suspend_legacy(dev, pmm);
5bcf719b 356 dev->switch_power_state = DRM_SWITCH_POWER_OFF;
6a9ee8af
DA
357 }
358}
359
360static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
361{
362 struct drm_device *dev = pci_get_drvdata(pdev);
6a9ee8af 363
fc8fd40e
DV
364 /*
365 * FIXME: open_count is protected by drm_global_mutex but that would lead to
366 * locking inversion with the driver load path. And the access here is
367 * completely racy anyway. So don't bother with locking for now.
368 */
369 return dev->open_count == 0;
6a9ee8af
DA
370}
371
26ec685f
TI
372static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
373 .set_gpu_state = i915_switcheroo_set_state,
374 .reprobe = NULL,
375 .can_switch = i915_switcheroo_can_switch,
376};
377
2c7111db
CW
378static int i915_load_modeset_init(struct drm_device *dev)
379{
380 struct drm_i915_private *dev_priv = dev->dev_private;
381 int ret;
79e53945 382
6d139a87 383 ret = intel_parse_bios(dev);
79e53945
JB
384 if (ret)
385 DRM_INFO("failed to find VBIOS tables\n");
386
934f992c
CW
387 /* If we have > 1 VGA cards, then we need to arbitrate access
388 * to the common VGA resources.
389 *
390 * If we are a secondary display controller (!PCI_DISPLAY_CLASS_VGA),
391 * then we do not take part in VGA arbitration and the
392 * vga_client_register() fails with -ENODEV.
393 */
ebff5fa9
DA
394 ret = vga_client_register(dev->pdev, dev, NULL, i915_vga_set_decode);
395 if (ret && ret != -ENODEV)
396 goto out;
28d52043 397
723bfd70
JB
398 intel_register_dsm_handler();
399
0d69704a 400 ret = vga_switcheroo_register_client(dev->pdev, &i915_switcheroo_ops, false);
6a9ee8af 401 if (ret)
5a79395b 402 goto cleanup_vga_client;
6a9ee8af 403
9797fbfb
CW
404 /* Initialise stolen first so that we may reserve preallocated
405 * objects for the BIOS to KMS transition.
406 */
407 ret = i915_gem_init_stolen(dev);
408 if (ret)
409 goto cleanup_vga_switcheroo;
410
e13192f6
ID
411 intel_power_domains_init_hw(dev_priv);
412
2aeb7d3a 413 ret = intel_irq_install(dev_priv);
52d7eced
DV
414 if (ret)
415 goto cleanup_gem_stolen;
416
417 /* Important: The output setup functions called by modeset_init need
418 * working irqs for e.g. gmbus and dp aux transfers. */
b01f2c3a
JB
419 intel_modeset_init(dev);
420
1070a42b 421 ret = i915_gem_init(dev);
79e53945 422 if (ret)
713028b3 423 goto cleanup_irq;
2c7111db 424
52d7eced 425 intel_modeset_gem_init(dev);
2c7111db 426
79e53945
JB
427 /* Always safe in the mode setting case. */
428 /* FIXME: do pre/post-mode set stuff in core KMS code */
ba0bf120 429 dev->vblank_disable_allowed = true;
713028b3 430 if (INTEL_INFO(dev)->num_pipes == 0)
e3c74757 431 return 0;
79e53945 432
5a79395b
CW
433 ret = intel_fbdev_init(dev);
434 if (ret)
52d7eced
DV
435 goto cleanup_gem;
436
20afbda2 437 /* Only enable hotplug handling once the fbdev is fully set up. */
b963291c 438 intel_hpd_init(dev_priv);
20afbda2
DV
439
440 /*
441 * Some ports require correctly set-up hpd registers for detection to
442 * work properly (leading to ghost connected connector status), e.g. VGA
443 * on gm45. Hence we can only set up the initial fbdev config after hpd
444 * irqs are fully enabled. Now we should scan for the initial config
445 * only once hotplug handling is enabled, but due to screwed-up locking
446 * around kms/fbdev init we can't protect the fdbev initial config
447 * scanning against hotplug events. Hence do this first and ignore the
448 * tiny window where we will loose hotplug notifactions.
449 */
d1d70677 450 async_schedule(intel_fbdev_initial_config, dev_priv);
20afbda2 451
eb1f8e4f 452 drm_kms_helper_poll_init(dev);
87acb0a5 453
79e53945
JB
454 return 0;
455
2c7111db
CW
456cleanup_gem:
457 mutex_lock(&dev->struct_mutex);
458 i915_gem_cleanup_ringbuffer(dev);
55d23285 459 i915_gem_context_fini(dev);
2c7111db 460 mutex_unlock(&dev->struct_mutex);
713028b3 461cleanup_irq:
52d7eced 462 drm_irq_uninstall(dev);
9797fbfb
CW
463cleanup_gem_stolen:
464 i915_gem_cleanup_stolen(dev);
5a79395b
CW
465cleanup_vga_switcheroo:
466 vga_switcheroo_unregister_client(dev->pdev);
467cleanup_vga_client:
468 vga_client_register(dev->pdev, NULL, NULL, NULL);
79e53945
JB
469out:
470 return ret;
471}
472
243eaf38 473#if IS_ENABLED(CONFIG_FB)
f96de58f 474static int i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv)
e188719a
DV
475{
476 struct apertures_struct *ap;
477 struct pci_dev *pdev = dev_priv->dev->pdev;
478 bool primary;
f96de58f 479 int ret;
e188719a
DV
480
481 ap = alloc_apertures(1);
482 if (!ap)
f96de58f 483 return -ENOMEM;
e188719a 484
dabb7a91 485 ap->ranges[0].base = dev_priv->gtt.mappable_base;
f64e2922 486 ap->ranges[0].size = dev_priv->gtt.mappable_end;
93d18799 487
e188719a
DV
488 primary =
489 pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
490
f96de58f 491 ret = remove_conflicting_framebuffers(ap, "inteldrmfb", primary);
e188719a
DV
492
493 kfree(ap);
f96de58f
CW
494
495 return ret;
e188719a 496}
4520f53a 497#else
f96de58f 498static int i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv)
4520f53a 499{
f96de58f 500 return 0;
4520f53a
DV
501}
502#endif
e188719a 503
a4de0526
DV
504#if !defined(CONFIG_VGA_CONSOLE)
505static int i915_kick_out_vgacon(struct drm_i915_private *dev_priv)
506{
507 return 0;
508}
509#elif !defined(CONFIG_DUMMY_CONSOLE)
510static int i915_kick_out_vgacon(struct drm_i915_private *dev_priv)
511{
512 return -ENODEV;
513}
514#else
515static int i915_kick_out_vgacon(struct drm_i915_private *dev_priv)
516{
1bb9e632 517 int ret = 0;
a4de0526
DV
518
519 DRM_INFO("Replacing VGA console driver\n");
520
521 console_lock();
1bb9e632
DV
522 if (con_is_bound(&vga_con))
523 ret = do_take_over_console(&dummy_con, 0, MAX_NR_CONSOLES - 1, 1);
a4de0526
DV
524 if (ret == 0) {
525 ret = do_unregister_con_driver(&vga_con);
526
527 /* Ignore "already unregistered". */
528 if (ret == -ENODEV)
529 ret = 0;
530 }
531 console_unlock();
532
533 return ret;
534}
535#endif
536
c96ea64e
DV
537static void i915_dump_device_info(struct drm_i915_private *dev_priv)
538{
5c969aa7 539 const struct intel_device_info *info = &dev_priv->info;
c96ea64e 540
e2a5800a
DL
541#define PRINT_S(name) "%s"
542#define SEP_EMPTY
79fc46df
DL
543#define PRINT_FLAG(name) info->name ? #name "," : ""
544#define SEP_COMMA ,
19c656a1 545 DRM_DEBUG_DRIVER("i915 device info: gen=%i, pciid=0x%04x rev=0x%02x flags="
e2a5800a 546 DEV_INFO_FOR_EACH_FLAG(PRINT_S, SEP_EMPTY),
c96ea64e
DV
547 info->gen,
548 dev_priv->dev->pdev->device,
19c656a1 549 dev_priv->dev->pdev->revision,
79fc46df 550 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_COMMA));
e2a5800a
DL
551#undef PRINT_S
552#undef SEP_EMPTY
79fc46df
DL
553#undef PRINT_FLAG
554#undef SEP_COMMA
c96ea64e
DV
555}
556
22d3fd46
DL
557/*
558 * Determine various intel_device_info fields at runtime.
559 *
560 * Use it when either:
561 * - it's judged too laborious to fill n static structures with the limit
562 * when a simple if statement does the job,
563 * - run-time checks (eg read fuse/strap registers) are needed.
658ac4c6
DL
564 *
565 * This function needs to be called:
566 * - after the MMIO has been setup as we are reading registers,
567 * - after the PCH has been detected,
568 * - before the first usage of the fields it can tweak.
22d3fd46
DL
569 */
570static void intel_device_info_runtime_init(struct drm_device *dev)
571{
658ac4c6 572 struct drm_i915_private *dev_priv = dev->dev_private;
22d3fd46 573 struct intel_device_info *info;
d615a166 574 enum pipe pipe;
22d3fd46 575
658ac4c6 576 info = (struct intel_device_info *)&dev_priv->info;
22d3fd46 577
1fc8ac3e 578 if (IS_VALLEYVIEW(dev) || INTEL_INFO(dev)->gen == 9)
055e393f 579 for_each_pipe(dev_priv, pipe)
d615a166
DL
580 info->num_sprites[pipe] = 2;
581 else
055e393f 582 for_each_pipe(dev_priv, pipe)
d615a166 583 info->num_sprites[pipe] = 1;
658ac4c6 584
a0bae57f
DL
585 if (i915.disable_display) {
586 DRM_INFO("Display disabled (module parameter)\n");
587 info->num_pipes = 0;
588 } else if (info->num_pipes > 0 &&
589 (INTEL_INFO(dev)->gen == 7 || INTEL_INFO(dev)->gen == 8) &&
590 !IS_VALLEYVIEW(dev)) {
658ac4c6
DL
591 u32 fuse_strap = I915_READ(FUSE_STRAP);
592 u32 sfuse_strap = I915_READ(SFUSE_STRAP);
593
594 /*
595 * SFUSE_STRAP is supposed to have a bit signalling the display
596 * is fused off. Unfortunately it seems that, at least in
597 * certain cases, fused off display means that PCH display
598 * reads don't land anywhere. In that case, we read 0s.
599 *
600 * On CPT/PPT, we can detect this case as SFUSE_STRAP_FUSE_LOCK
601 * should be set when taking over after the firmware.
602 */
603 if (fuse_strap & ILK_INTERNAL_DISPLAY_DISABLE ||
604 sfuse_strap & SFUSE_STRAP_DISPLAY_DISABLED ||
605 (dev_priv->pch_type == PCH_CPT &&
606 !(sfuse_strap & SFUSE_STRAP_FUSE_LOCK))) {
607 DRM_INFO("Display fused off, disabling\n");
608 info->num_pipes = 0;
609 }
610 }
693d11c3 611
3873218f 612 /* Initialize slice/subslice/EU info */
693d11c3 613 if (IS_CHERRYVIEW(dev)) {
c93043ae 614 u32 fuse, eu_dis;
693d11c3
D
615
616 fuse = I915_READ(CHV_FUSE_GT);
c93043ae
JM
617
618 info->slice_total = 1;
619
620 if (!(fuse & CHV_FGT_DISABLE_SS0)) {
621 info->subslice_per_slice++;
622 eu_dis = fuse & (CHV_FGT_EU_DIS_SS0_R0_MASK |
623 CHV_FGT_EU_DIS_SS0_R1_MASK);
624 info->eu_total += 8 - hweight32(eu_dis);
625 }
626
627 if (!(fuse & CHV_FGT_DISABLE_SS1)) {
628 info->subslice_per_slice++;
629 eu_dis = fuse & (CHV_FGT_EU_DIS_SS1_R0_MASK |
630 CHV_FGT_EU_DIS_SS1_R1_MASK);
631 info->eu_total += 8 - hweight32(eu_dis);
632 }
633
634 info->subslice_total = info->subslice_per_slice;
635 /*
636 * CHV expected to always have a uniform distribution of EU
637 * across subslices.
638 */
639 info->eu_per_subslice = info->subslice_total ?
640 info->eu_total / info->subslice_total :
641 0;
642 /*
643 * CHV supports subslice power gating on devices with more than
644 * one subslice, and supports EU power gating on devices with
645 * more than one EU pair per subslice.
646 */
647 info->has_slice_pg = 0;
648 info->has_subslice_pg = (info->subslice_total > 1);
649 info->has_eu_pg = (info->eu_per_subslice > 2);
3873218f
JM
650 } else if (IS_SKYLAKE(dev)) {
651 const int s_max = 3, ss_max = 4, eu_max = 8;
652 int s, ss;
653 u32 fuse2, eu_disable[s_max], s_enable, ss_disable;
654
655 fuse2 = I915_READ(GEN8_FUSE2);
656 s_enable = (fuse2 & GEN8_F2_S_ENA_MASK) >>
657 GEN8_F2_S_ENA_SHIFT;
658 ss_disable = (fuse2 & GEN9_F2_SS_DIS_MASK) >>
659 GEN9_F2_SS_DIS_SHIFT;
660
661 eu_disable[0] = I915_READ(GEN8_EU_DISABLE0);
662 eu_disable[1] = I915_READ(GEN8_EU_DISABLE1);
663 eu_disable[2] = I915_READ(GEN8_EU_DISABLE2);
664
665 info->slice_total = hweight32(s_enable);
666 /*
667 * The subslice disable field is global, i.e. it applies
668 * to each of the enabled slices.
669 */
670 info->subslice_per_slice = ss_max - hweight32(ss_disable);
671 info->subslice_total = info->slice_total *
672 info->subslice_per_slice;
673
674 /*
675 * Iterate through enabled slices and subslices to
676 * count the total enabled EU.
677 */
678 for (s = 0; s < s_max; s++) {
679 if (!(s_enable & (0x1 << s)))
680 /* skip disabled slice */
681 continue;
682
683 for (ss = 0; ss < ss_max; ss++) {
b7668791
DL
684 u32 n_disabled;
685
3873218f
JM
686 if (ss_disable & (0x1 << ss))
687 /* skip disabled subslice */
688 continue;
689
b7668791
DL
690 n_disabled = hweight8(eu_disable[s] >>
691 (ss * eu_max));
692
693 /*
694 * Record which subslice(s) has(have) 7 EUs. we
695 * can tune the hash used to spread work among
696 * subslices if they are unbalanced.
697 */
698 if (eu_max - n_disabled == 7)
699 info->subslice_7eu[s] |= 1 << ss;
700
701 info->eu_total += eu_max - n_disabled;
3873218f
JM
702 }
703 }
704
705 /*
706 * SKL is expected to always have a uniform distribution
707 * of EU across subslices with the exception that any one
708 * EU in any one subslice may be fused off for die
709 * recovery.
710 */
711 info->eu_per_subslice = info->subslice_total ?
712 DIV_ROUND_UP(info->eu_total,
713 info->subslice_total) : 0;
714 /*
715 * SKL supports slice power gating on devices with more than
716 * one slice, and supports EU power gating on devices with
717 * more than one EU pair per subslice.
718 */
719 info->has_slice_pg = (info->slice_total > 1) ? 1 : 0;
720 info->has_subslice_pg = 0;
721 info->has_eu_pg = (info->eu_per_subslice > 2) ? 1 : 0;
693d11c3 722 }
3873218f
JM
723 DRM_DEBUG_DRIVER("slice total: %u\n", info->slice_total);
724 DRM_DEBUG_DRIVER("subslice total: %u\n", info->subslice_total);
725 DRM_DEBUG_DRIVER("subslice per slice: %u\n", info->subslice_per_slice);
726 DRM_DEBUG_DRIVER("EU total: %u\n", info->eu_total);
727 DRM_DEBUG_DRIVER("EU per subslice: %u\n", info->eu_per_subslice);
728 DRM_DEBUG_DRIVER("has slice power gating: %s\n",
729 info->has_slice_pg ? "y" : "n");
730 DRM_DEBUG_DRIVER("has subslice power gating: %s\n",
731 info->has_subslice_pg ? "y" : "n");
732 DRM_DEBUG_DRIVER("has EU power gating: %s\n",
733 info->has_eu_pg ? "y" : "n");
22d3fd46
DL
734}
735
79e53945
JB
736/**
737 * i915_driver_load - setup chip and create an initial config
738 * @dev: DRM device
739 * @flags: startup flags
740 *
741 * The driver load routine has to do several things:
742 * - drive output discovery via intel_modeset_init()
743 * - initialize the memory manager
744 * - allocate initial config memory
745 * - setup the DRM framebuffer with the allocated memory
746 */
84b1fd10 747int i915_driver_load(struct drm_device *dev, unsigned long flags)
22eae947 748{
ea059a1e 749 struct drm_i915_private *dev_priv;
5c969aa7 750 struct intel_device_info *info, *device_info;
934d6086 751 int ret = 0, mmio_bar, mmio_size;
9021f284 752 uint32_t aperture_size;
fe669bf8 753
26394d92
DV
754 info = (struct intel_device_info *) flags;
755
b14c5679 756 dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
ba8bbcf6
JB
757 if (dev_priv == NULL)
758 return -ENOMEM;
759
755f68f4 760 dev->dev_private = dev_priv;
673a394b 761 dev_priv->dev = dev;
5c969aa7 762
87f1f465 763 /* Setup the write-once "constant" device info */
5c969aa7 764 device_info = (struct intel_device_info *)&dev_priv->info;
87f1f465
CW
765 memcpy(device_info, info, sizeof(dev_priv->info));
766 device_info->device_id = dev->pdev->device;
ba8bbcf6 767
7dcd2677
KK
768 spin_lock_init(&dev_priv->irq_lock);
769 spin_lock_init(&dev_priv->gpu_error.lock);
07f11d49 770 mutex_init(&dev_priv->backlight_lock);
907b28c5 771 spin_lock_init(&dev_priv->uncore.lock);
c20e8355 772 spin_lock_init(&dev_priv->mm.object_stat_lock);
84c33a64 773 spin_lock_init(&dev_priv->mmio_flip_lock);
7dcd2677 774 mutex_init(&dev_priv->dpio_lock);
7dcd2677
KK
775 mutex_init(&dev_priv->modeset_restore_lock);
776
f742a552 777 intel_pm_setup(dev);
c67a470b 778
07144428
DL
779 intel_display_crc_init(dev);
780
c96ea64e
DV
781 i915_dump_device_info(dev_priv);
782
ed1c9e2c
PZ
783 /* Not all pre-production machines fall into this category, only the
784 * very first ones. Almost everything should work, except for maybe
785 * suspend/resume. And we don't implement workarounds that affect only
786 * pre-production machines. */
787 if (IS_HSW_EARLY_SDV(dev))
788 DRM_INFO("This is an early pre-production Haswell machine. "
789 "It may not be fully functional.\n");
790
ec2a4c3f
DA
791 if (i915_get_bridge_dev(dev)) {
792 ret = -EIO;
793 goto free_priv;
794 }
795
1e1bd0fd
BW
796 mmio_bar = IS_GEN2(dev) ? 1 : 0;
797 /* Before gen4, the registers and the GTT are behind different BARs.
798 * However, from gen4 onwards, the registers and the GTT are shared
799 * in the same BAR, so we want to restrict this ioremap from
800 * clobbering the GTT which we want ioremap_wc instead. Fortunately,
801 * the register BAR remains the same size for all the earlier
802 * generations up to Ironlake.
803 */
804 if (info->gen < 5)
805 mmio_size = 512*1024;
806 else
807 mmio_size = 2*1024*1024;
808
809 dev_priv->regs = pci_iomap(dev->pdev, mmio_bar, mmio_size);
810 if (!dev_priv->regs) {
811 DRM_ERROR("failed to map registers\n");
812 ret = -EIO;
813 goto put_bridge;
814 }
815
c3d685a7
BW
816 /* This must be called before any calls to HAS_PCH_* */
817 intel_detect_pch(dev);
818
819 intel_uncore_init(dev);
820
e76e9aeb
BW
821 ret = i915_gem_gtt_init(dev);
822 if (ret)
cbb47d17 823 goto out_regs;
e188719a 824
17fa6463
DV
825 /* WARNING: Apparently we must kick fbdev drivers before vgacon,
826 * otherwise the vga fbdev driver falls over. */
827 ret = i915_kick_out_firmware_fb(dev_priv);
828 if (ret) {
829 DRM_ERROR("failed to remove conflicting framebuffer drivers\n");
830 goto out_gtt;
831 }
a4de0526 832
17fa6463
DV
833 ret = i915_kick_out_vgacon(dev_priv);
834 if (ret) {
835 DRM_ERROR("failed to remove conflicting VGA console\n");
836 goto out_gtt;
a4de0526 837 }
e188719a 838
466e69b8
DA
839 pci_set_master(dev->pdev);
840
9f82d238
DV
841 /* overlay on gen2 is broken and can't address above 1G */
842 if (IS_GEN2(dev))
843 dma_set_coherent_mask(&dev->pdev->dev, DMA_BIT_MASK(30));
844
6927faf3
JN
845 /* 965GM sometimes incorrectly writes to hardware status page (HWS)
846 * using 32bit addressing, overwriting memory if HWS is located
847 * above 4GB.
848 *
849 * The documentation also mentions an issue with undefined
850 * behaviour if any general state is accessed within a page above 4GB,
851 * which also needs to be handled carefully.
852 */
853 if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
854 dma_set_coherent_mask(&dev->pdev->dev, DMA_BIT_MASK(32));
855
93d18799 856 aperture_size = dev_priv->gtt.mappable_end;
71e9339c 857
5d4545ae
BW
858 dev_priv->gtt.mappable =
859 io_mapping_create_wc(dev_priv->gtt.mappable_base,
dd2757f8 860 aperture_size);
5d4545ae 861 if (dev_priv->gtt.mappable == NULL) {
6644107d 862 ret = -EIO;
cbb47d17 863 goto out_gtt;
6644107d
VP
864 }
865
911bdf0a
BW
866 dev_priv->gtt.mtrr = arch_phys_wc_add(dev_priv->gtt.mappable_base,
867 aperture_size);
19966754 868
e642abbf
CW
869 /* The i915 workqueue is primarily used for batched retirement of
870 * requests (and thus managing bo) once the task has been completed
871 * by the GPU. i915_gem_retire_requests() is called directly when we
872 * need high-priority retirement, such as waiting for an explicit
873 * bo.
874 *
875 * It is also used for periodic low-priority events, such as
df9c2042 876 * idle-timers and recording error state.
e642abbf
CW
877 *
878 * All tasks on the workqueue are expected to acquire the dev mutex
879 * so there is no point in running more than one instance of the
53621860 880 * workqueue at any time. Use an ordered one.
e642abbf 881 */
53621860 882 dev_priv->wq = alloc_ordered_workqueue("i915", 0);
9c9fe1f8
EA
883 if (dev_priv->wq == NULL) {
884 DRM_ERROR("Failed to create our workqueue.\n");
885 ret = -ENOMEM;
a7b85d2a 886 goto out_mtrrfree;
9c9fe1f8
EA
887 }
888
0e32b39c
DA
889 dev_priv->dp_wq = alloc_ordered_workqueue("i915-dp", 0);
890 if (dev_priv->dp_wq == NULL) {
891 DRM_ERROR("Failed to create our dp workqueue.\n");
892 ret = -ENOMEM;
893 goto out_freewq;
894 }
895
737b1506
CW
896 dev_priv->gpu_error.hangcheck_wq =
897 alloc_ordered_workqueue("i915-hangcheck", 0);
898 if (dev_priv->gpu_error.hangcheck_wq == NULL) {
899 DRM_ERROR("Failed to create our hangcheck workqueue.\n");
900 ret = -ENOMEM;
901 goto out_freedpwq;
902 }
903
b963291c 904 intel_irq_init(dev_priv);
78511f2a 905 intel_uncore_sanitize(dev);
9880b7a5 906
c4804411
ZW
907 /* Try to make sure MCHBAR is enabled before poking at it */
908 intel_setup_mchbar(dev);
f899fc64 909 intel_setup_gmbus(dev);
44834a67 910 intel_opregion_setup(dev);
c4804411 911
6d139a87
BF
912 intel_setup_bios(dev);
913
673a394b
EA
914 i915_gem_load(dev);
915
ed4cb414
EA
916 /* On the 945G/GM, the chipset reports the MSI capability on the
917 * integrated graphics even though the support isn't actually there
918 * according to the published specs. It doesn't appear to function
919 * correctly in testing on 945G.
920 * This may be a side effect of MSI having been made available for PEG
921 * and the registers being closely associated.
d1ed629f
KP
922 *
923 * According to chipset errata, on the 965GM, MSI interrupts may
b60678a7
KP
924 * be lost or delayed, but we use them anyways to avoid
925 * stuck interrupts on some machines.
ed4cb414 926 */
b60678a7 927 if (!IS_I945G(dev) && !IS_I945GM(dev))
d3e74d02 928 pci_enable_msi(dev->pdev);
ed4cb414 929
22d3fd46 930 intel_device_info_runtime_init(dev);
7f1f3851 931
e3c74757
BW
932 if (INTEL_INFO(dev)->num_pipes) {
933 ret = drm_vblank_init(dev, INTEL_INFO(dev)->num_pipes);
934 if (ret)
935 goto out_gem_unload;
936 }
52440211 937
da7e29bd 938 intel_power_domains_init(dev_priv);
a38911a3 939
17fa6463
DV
940 ret = i915_load_modeset_init(dev);
941 if (ret < 0) {
942 DRM_ERROR("failed to init modeset\n");
943 goto out_power_well;
79e53945
JB
944 }
945
e21fd552
YZ
946 /*
947 * Notify a valid surface after modesetting,
948 * when running inside a VM.
949 */
950 if (intel_vgpu_active(dev))
951 I915_WRITE(vgtif_reg(display_ready), VGT_DRV_DISPLAY_READY);
952
0136db58
BW
953 i915_setup_sysfs(dev);
954
e3c74757
BW
955 if (INTEL_INFO(dev)->num_pipes) {
956 /* Must be done after probing outputs */
957 intel_opregion_init(dev);
8e5c2b77 958 acpi_video_register();
e3c74757 959 }
74a365b3 960
eb48eb00
DV
961 if (IS_GEN5(dev))
962 intel_gpu_ips_init(dev_priv);
63ee41d7 963
f458ebbc 964 intel_runtime_pm_enable(dev_priv);
8a187455 965
58fddc28
ID
966 i915_audio_component_init(dev_priv);
967
79e53945
JB
968 return 0;
969
cbb47d17 970out_power_well:
f458ebbc 971 intel_power_domains_fini(dev_priv);
cbb47d17 972 drm_vblank_cleanup(dev);
56e2ea34 973out_gem_unload:
4bdc7293
ID
974 WARN_ON(unregister_oom_notifier(&dev_priv->mm.oom_notifier));
975 unregister_shrinker(&dev_priv->mm.shrinker);
a7b85d2a 976
56e2ea34
CW
977 if (dev->pdev->msi_enabled)
978 pci_disable_msi(dev->pdev);
979
980 intel_teardown_gmbus(dev);
981 intel_teardown_mchbar(dev);
22accca0 982 pm_qos_remove_request(&dev_priv->pm_qos);
737b1506
CW
983 destroy_workqueue(dev_priv->gpu_error.hangcheck_wq);
984out_freedpwq:
0e32b39c
DA
985 destroy_workqueue(dev_priv->dp_wq);
986out_freewq:
9c9fe1f8 987 destroy_workqueue(dev_priv->wq);
a7b85d2a 988out_mtrrfree:
911bdf0a 989 arch_phys_wc_del(dev_priv->gtt.mtrr);
5d4545ae 990 io_mapping_free(dev_priv->gtt.mappable);
cbb47d17 991out_gtt:
90d0a0e8 992 i915_global_gtt_cleanup(dev);
cbb47d17 993out_regs:
c3d685a7 994 intel_uncore_fini(dev);
6dda569f 995 pci_iounmap(dev->pdev, dev_priv->regs);
ec2a4c3f
DA
996put_bridge:
997 pci_dev_put(dev_priv->bridge_dev);
79e53945 998free_priv:
cbb47d17
CW
999 if (dev_priv->slab)
1000 kmem_cache_destroy(dev_priv->slab);
9a298b2a 1001 kfree(dev_priv);
ba8bbcf6
JB
1002 return ret;
1003}
1004
1005int i915_driver_unload(struct drm_device *dev)
1006{
1007 struct drm_i915_private *dev_priv = dev->dev_private;
c911fc1c 1008 int ret;
ba8bbcf6 1009
58fddc28
ID
1010 i915_audio_component_cleanup(dev_priv);
1011
ce58c32b
CW
1012 ret = i915_gem_suspend(dev);
1013 if (ret) {
1014 DRM_ERROR("failed to idle hardware: %d\n", ret);
1015 return ret;
1016 }
1017
41373cd5 1018 intel_power_domains_fini(dev_priv);
8a187455 1019
eb48eb00 1020 intel_gpu_ips_teardown();
7648fa99 1021
0136db58
BW
1022 i915_teardown_sysfs(dev);
1023
4bdc7293
ID
1024 WARN_ON(unregister_oom_notifier(&dev_priv->mm.oom_notifier));
1025 unregister_shrinker(&dev_priv->mm.shrinker);
17250b71 1026
5d4545ae 1027 io_mapping_free(dev_priv->gtt.mappable);
911bdf0a 1028 arch_phys_wc_del(dev_priv->gtt.mtrr);
ab657db1 1029
44834a67
CW
1030 acpi_video_unregister();
1031
17fa6463 1032 intel_fbdev_fini(dev);
2ebfaf5f
PZ
1033
1034 drm_vblank_cleanup(dev);
1035
17fa6463 1036 intel_modeset_cleanup(dev);
6c0d9350 1037
17fa6463
DV
1038 /*
1039 * free the memory space allocated for the child device
1040 * config parsed from VBT
1041 */
1042 if (dev_priv->vbt.child_dev && dev_priv->vbt.child_dev_num) {
1043 kfree(dev_priv->vbt.child_dev);
1044 dev_priv->vbt.child_dev = NULL;
1045 dev_priv->vbt.child_dev_num = 0;
79e53945
JB
1046 }
1047
17fa6463
DV
1048 vga_switcheroo_unregister_client(dev->pdev);
1049 vga_client_register(dev->pdev, NULL, NULL, NULL);
1050
a8b4899e 1051 /* Free error state after interrupts are fully disabled. */
737b1506 1052 cancel_delayed_work_sync(&dev_priv->gpu_error.hangcheck_work);
a8b4899e 1053 i915_destroy_error_state(dev);
bc0c7f14 1054
ed4cb414
EA
1055 if (dev->pdev->msi_enabled)
1056 pci_disable_msi(dev->pdev);
1057
44834a67 1058 intel_opregion_fini(dev);
8ee1c3db 1059
17fa6463
DV
1060 /* Flush any outstanding unpin_work. */
1061 flush_workqueue(dev_priv->wq);
67e77c5a 1062
17fa6463
DV
1063 mutex_lock(&dev->struct_mutex);
1064 i915_gem_cleanup_ringbuffer(dev);
1065 i915_gem_batch_pool_fini(&dev_priv->mm.batch_pool);
1066 i915_gem_context_fini(dev);
1067 mutex_unlock(&dev->struct_mutex);
1068 i915_gem_cleanup_stolen(dev);
79e53945 1069
f899fc64 1070 intel_teardown_gmbus(dev);
c4804411
ZW
1071 intel_teardown_mchbar(dev);
1072
0e32b39c 1073 destroy_workqueue(dev_priv->dp_wq);
bc0c7f14 1074 destroy_workqueue(dev_priv->wq);
737b1506 1075 destroy_workqueue(dev_priv->gpu_error.hangcheck_wq);
9ee32fea 1076 pm_qos_remove_request(&dev_priv->pm_qos);
bc0c7f14 1077
90d0a0e8 1078 i915_global_gtt_cleanup(dev);
6640aab6 1079
aec347ab
CW
1080 intel_uncore_fini(dev);
1081 if (dev_priv->regs != NULL)
1082 pci_iounmap(dev->pdev, dev_priv->regs);
1083
42dcedd4
CW
1084 if (dev_priv->slab)
1085 kmem_cache_destroy(dev_priv->slab);
bc0c7f14 1086
ec2a4c3f 1087 pci_dev_put(dev_priv->bridge_dev);
2206e6a1 1088 kfree(dev_priv);
ba8bbcf6 1089
22eae947
DA
1090 return 0;
1091}
1092
f787a5f5 1093int i915_driver_open(struct drm_device *dev, struct drm_file *file)
673a394b 1094{
b29c19b6 1095 int ret;
673a394b 1096
b29c19b6
CW
1097 ret = i915_gem_open(dev, file);
1098 if (ret)
1099 return ret;
254f965c 1100
673a394b
EA
1101 return 0;
1102}
1103
79e53945
JB
1104/**
1105 * i915_driver_lastclose - clean up after all DRM clients have exited
1106 * @dev: DRM device
1107 *
1108 * Take care of cleaning up after all DRM clients have exited. In the
1109 * mode setting case, we want to restore the kernel's initial mode (just
1110 * in case the last client left us in a bad state).
1111 *
9021f284 1112 * Additionally, in the non-mode setting case, we'll tear down the GTT
79e53945
JB
1113 * and DMA structures, since the kernel won't be using them, and clea
1114 * up any GEM state.
1115 */
1a5036bf 1116void i915_driver_lastclose(struct drm_device *dev)
1da177e4 1117{
377e91b2
DV
1118 intel_fbdev_restore_mode(dev);
1119 vga_switcheroo_process_delayed_switch();
1da177e4
LT
1120}
1121
2885f6ac 1122void i915_driver_preclose(struct drm_device *dev, struct drm_file *file)
1da177e4 1123{
0d1430a3 1124 mutex_lock(&dev->struct_mutex);
2885f6ac
JH
1125 i915_gem_context_close(dev, file);
1126 i915_gem_release(dev, file);
0d1430a3 1127 mutex_unlock(&dev->struct_mutex);
e2fcdaa9 1128
17fa6463 1129 intel_modeset_preclose(dev, file);
1da177e4
LT
1130}
1131
f787a5f5 1132void i915_driver_postclose(struct drm_device *dev, struct drm_file *file)
673a394b 1133{
f787a5f5 1134 struct drm_i915_file_private *file_priv = file->driver_priv;
673a394b 1135
a8ebba75
ZY
1136 if (file_priv && file_priv->bsd_ring)
1137 file_priv->bsd_ring = NULL;
f787a5f5 1138 kfree(file_priv);
673a394b
EA
1139}
1140
4feb7659
DV
1141static int
1142i915_gem_reject_pin_ioctl(struct drm_device *dev, void *data,
1143 struct drm_file *file)
1144{
1145 return -ENODEV;
1146}
1147
baa70943 1148const struct drm_ioctl_desc i915_ioctls[] = {
77f31815
DV
1149 DRM_IOCTL_DEF_DRV(I915_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1150 DRM_IOCTL_DEF_DRV(I915_FLUSH, drm_noop, DRM_AUTH),
1151 DRM_IOCTL_DEF_DRV(I915_FLIP, drm_noop, DRM_AUTH),
1152 DRM_IOCTL_DEF_DRV(I915_BATCHBUFFER, drm_noop, DRM_AUTH),
1153 DRM_IOCTL_DEF_DRV(I915_IRQ_EMIT, drm_noop, DRM_AUTH),
1154 DRM_IOCTL_DEF_DRV(I915_IRQ_WAIT, drm_noop, DRM_AUTH),
10ba5012 1155 DRM_IOCTL_DEF_DRV(I915_GETPARAM, i915_getparam, DRM_AUTH|DRM_RENDER_ALLOW),
1b2f1489 1156 DRM_IOCTL_DEF_DRV(I915_SETPARAM, i915_setparam, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
b2c606fe
DV
1157 DRM_IOCTL_DEF_DRV(I915_ALLOC, drm_noop, DRM_AUTH),
1158 DRM_IOCTL_DEF_DRV(I915_FREE, drm_noop, DRM_AUTH),
1159 DRM_IOCTL_DEF_DRV(I915_INIT_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
77f31815 1160 DRM_IOCTL_DEF_DRV(I915_CMDBUFFER, drm_noop, DRM_AUTH),
b2c606fe 1161 DRM_IOCTL_DEF_DRV(I915_DESTROY_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
d1c1edbc 1162 DRM_IOCTL_DEF_DRV(I915_SET_VBLANK_PIPE, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
77f31815
DV
1163 DRM_IOCTL_DEF_DRV(I915_GET_VBLANK_PIPE, drm_noop, DRM_AUTH),
1164 DRM_IOCTL_DEF_DRV(I915_VBLANK_SWAP, drm_noop, DRM_AUTH),
1165 DRM_IOCTL_DEF_DRV(I915_HWS_ADDR, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
f548c0e9 1166 DRM_IOCTL_DEF_DRV(I915_GEM_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED),
1b2f1489 1167 DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER, i915_gem_execbuffer, DRM_AUTH|DRM_UNLOCKED),
10ba5012 1168 DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER2, i915_gem_execbuffer2, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
4feb7659
DV
1169 DRM_IOCTL_DEF_DRV(I915_GEM_PIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY|DRM_UNLOCKED),
1170 DRM_IOCTL_DEF_DRV(I915_GEM_UNPIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY|DRM_UNLOCKED),
10ba5012
KH
1171 DRM_IOCTL_DEF_DRV(I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
1172 DRM_IOCTL_DEF_DRV(I915_GEM_SET_CACHING, i915_gem_set_caching_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1173 DRM_IOCTL_DEF_DRV(I915_GEM_GET_CACHING, i915_gem_get_caching_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1174 DRM_IOCTL_DEF_DRV(I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
71b14ab6
DV
1175 DRM_IOCTL_DEF_DRV(I915_GEM_ENTERVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED),
1176 DRM_IOCTL_DEF_DRV(I915_GEM_LEAVEVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED),
10ba5012
KH
1177 DRM_IOCTL_DEF_DRV(I915_GEM_CREATE, i915_gem_create_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1178 DRM_IOCTL_DEF_DRV(I915_GEM_PREAD, i915_gem_pread_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1179 DRM_IOCTL_DEF_DRV(I915_GEM_PWRITE, i915_gem_pwrite_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1180 DRM_IOCTL_DEF_DRV(I915_GEM_MMAP, i915_gem_mmap_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1181 DRM_IOCTL_DEF_DRV(I915_GEM_MMAP_GTT, i915_gem_mmap_gtt_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1182 DRM_IOCTL_DEF_DRV(I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1183 DRM_IOCTL_DEF_DRV(I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1184 DRM_IOCTL_DEF_DRV(I915_GEM_SET_TILING, i915_gem_set_tiling, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1185 DRM_IOCTL_DEF_DRV(I915_GEM_GET_TILING, i915_gem_get_tiling, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1186 DRM_IOCTL_DEF_DRV(I915_GEM_GET_APERTURE, i915_gem_get_aperture_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1b2f1489 1187 DRM_IOCTL_DEF_DRV(I915_GET_PIPE_FROM_CRTC_ID, intel_get_pipe_from_crtc_id, DRM_UNLOCKED),
10ba5012 1188 DRM_IOCTL_DEF_DRV(I915_GEM_MADVISE, i915_gem_madvise_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1b2f1489
DA
1189 DRM_IOCTL_DEF_DRV(I915_OVERLAY_PUT_IMAGE, intel_overlay_put_image, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
1190 DRM_IOCTL_DEF_DRV(I915_OVERLAY_ATTRS, intel_overlay_attrs, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
8ea30864
JB
1191 DRM_IOCTL_DEF_DRV(I915_SET_SPRITE_COLORKEY, intel_sprite_set_colorkey, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
1192 DRM_IOCTL_DEF_DRV(I915_GET_SPRITE_COLORKEY, intel_sprite_get_colorkey, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
10ba5012
KH
1193 DRM_IOCTL_DEF_DRV(I915_GEM_WAIT, i915_gem_wait_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
1194 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_CREATE, i915_gem_context_create_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1195 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_DESTROY, i915_gem_context_destroy_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1196 DRM_IOCTL_DEF_DRV(I915_REG_READ, i915_reg_read_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
b6359918 1197 DRM_IOCTL_DEF_DRV(I915_GET_RESET_STATS, i915_get_reset_stats_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
5cc9ed4b 1198 DRM_IOCTL_DEF_DRV(I915_GEM_USERPTR, i915_gem_userptr_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
c9dc0f35
CW
1199 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_GETPARAM, i915_gem_context_getparam_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1200 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_SETPARAM, i915_gem_context_setparam_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
c94f7029
DA
1201};
1202
f95aeb17 1203int i915_max_ioctl = ARRAY_SIZE(i915_ioctls);
cda17380 1204
9021f284
DV
1205/*
1206 * This is really ugly: Because old userspace abused the linux agp interface to
1207 * manage the gtt, we need to claim that all intel devices are agp. For
1208 * otherwise the drm core refuses to initialize the agp support code.
cda17380 1209 */
1a5036bf 1210int i915_driver_device_is_agp(struct drm_device *dev)
cda17380
DA
1211{
1212 return 1;
1213}
This page took 0.807422 seconds and 5 git commands to generate.