i915_dma.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  1. /* i915_dma.c -- DMA support for the I915 -*- linux-c -*-
  2. */
  3. /*
  4. * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
  5. * All Rights Reserved.
  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. *
  27. */
  28. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  29. #include <linux/async.h>
  30. #include <drm/drmP.h>
  31. #include <drm/drm_crtc_helper.h>
  32. #include <drm/drm_fb_helper.h>
  33. #include <drm/drm_legacy.h>
  34. #include "intel_drv.h"
  35. #include <drm/i915_drm.h>
  36. #include "i915_drv.h"
  37. #include "i915_vgpu.h"
  38. #include "i915_trace.h"
  39. #include <linux/pci.h>
  40. #include <linux/console.h>
  41. #include <linux/vt.h>
  42. #include <linux/vgaarb.h>
  43. #include <linux/acpi.h>
  44. #include <linux/pnp.h>
  45. #include <linux/vga_switcheroo.h>
  46. #include <linux/slab.h>
  47. #include <acpi/video.h>
  48. #include <linux/pm.h>
  49. #include <linux/pm_runtime.h>
  50. #include <linux/oom.h>
  51. static int i915_getparam(struct drm_device *dev, void *data,
  52. struct drm_file *file_priv)
  53. {
  54. struct drm_i915_private *dev_priv = dev->dev_private;
  55. drm_i915_getparam_t *param = data;
  56. int value;
  57. switch (param->param) {
  58. case I915_PARAM_IRQ_ACTIVE:
  59. case I915_PARAM_ALLOW_BATCHBUFFER:
  60. case I915_PARAM_LAST_DISPATCH:
  61. /* Reject all old ums/dri params. */
  62. return -ENODEV;
  63. case I915_PARAM_CHIPSET_ID:
  64. value = dev->pdev->device;
  65. break;
  66. case I915_PARAM_REVISION:
  67. value = dev->pdev->revision;
  68. break;
  69. case I915_PARAM_HAS_GEM:
  70. value = 1;
  71. break;
  72. case I915_PARAM_NUM_FENCES_AVAIL:
  73. value = dev_priv->num_fence_regs - dev_priv->fence_reg_start;
  74. break;
  75. case I915_PARAM_HAS_OVERLAY:
  76. value = dev_priv->overlay ? 1 : 0;
  77. break;
  78. case I915_PARAM_HAS_PAGEFLIPPING:
  79. value = 1;
  80. break;
  81. case I915_PARAM_HAS_EXECBUF2:
  82. /* depends on GEM */
  83. value = 1;
  84. break;
  85. case I915_PARAM_HAS_BSD:
  86. value = intel_ring_initialized(&dev_priv->ring[VCS]);
  87. break;
  88. case I915_PARAM_HAS_BLT:
  89. value = intel_ring_initialized(&dev_priv->ring[BCS]);
  90. break;
  91. case I915_PARAM_HAS_VEBOX:
  92. value = intel_ring_initialized(&dev_priv->ring[VECS]);
  93. break;
  94. case I915_PARAM_HAS_BSD2:
  95. value = intel_ring_initialized(&dev_priv->ring[VCS2]);
  96. break;
  97. case I915_PARAM_HAS_RELAXED_FENCING:
  98. value = 1;
  99. break;
  100. case I915_PARAM_HAS_COHERENT_RINGS:
  101. value = 1;
  102. break;
  103. case I915_PARAM_HAS_EXEC_CONSTANTS:
  104. value = INTEL_INFO(dev)->gen >= 4;
  105. break;
  106. case I915_PARAM_HAS_RELAXED_DELTA:
  107. value = 1;
  108. break;
  109. case I915_PARAM_HAS_GEN7_SOL_RESET:
  110. value = 1;
  111. break;
  112. case I915_PARAM_HAS_LLC:
  113. value = HAS_LLC(dev);
  114. break;
  115. case I915_PARAM_HAS_WT:
  116. value = HAS_WT(dev);
  117. break;
  118. case I915_PARAM_HAS_ALIASING_PPGTT:
  119. value = USES_PPGTT(dev);
  120. break;
  121. case I915_PARAM_HAS_WAIT_TIMEOUT:
  122. value = 1;
  123. break;
  124. case I915_PARAM_HAS_SEMAPHORES:
  125. value = i915_semaphore_is_enabled(dev);
  126. break;
  127. case I915_PARAM_HAS_PRIME_VMAP_FLUSH:
  128. value = 1;
  129. break;
  130. case I915_PARAM_HAS_SECURE_BATCHES:
  131. value = capable(CAP_SYS_ADMIN);
  132. break;
  133. case I915_PARAM_HAS_PINNED_BATCHES:
  134. value = 1;
  135. break;
  136. case I915_PARAM_HAS_EXEC_NO_RELOC:
  137. value = 1;
  138. break;
  139. case I915_PARAM_HAS_EXEC_HANDLE_LUT:
  140. value = 1;
  141. break;
  142. case I915_PARAM_CMD_PARSER_VERSION:
  143. value = i915_cmd_parser_get_version();
  144. break;
  145. case I915_PARAM_HAS_COHERENT_PHYS_GTT:
  146. value = 1;
  147. break;
  148. case I915_PARAM_MMAP_VERSION:
  149. value = 1;
  150. break;
  151. case I915_PARAM_SUBSLICE_TOTAL:
  152. value = INTEL_INFO(dev)->subslice_total;
  153. if (!value)
  154. return -ENODEV;
  155. break;
  156. case I915_PARAM_EU_TOTAL:
  157. value = INTEL_INFO(dev)->eu_total;
  158. if (!value)
  159. return -ENODEV;
  160. break;
  161. case I915_PARAM_HAS_GPU_RESET:
  162. value = i915.enable_hangcheck &&
  163. intel_has_gpu_reset(dev);
  164. break;
  165. case I915_PARAM_HAS_RESOURCE_STREAMER:
  166. value = HAS_RESOURCE_STREAMER(dev);
  167. break;
  168. default:
  169. DRM_DEBUG("Unknown parameter %d\n", param->param);
  170. return -EINVAL;
  171. }
  172. if (copy_to_user(param->value, &value, sizeof(int))) {
  173. DRM_ERROR("copy_to_user failed\n");
  174. return -EFAULT;
  175. }
  176. return 0;
  177. }
  178. static int i915_setparam(struct drm_device *dev, void *data,
  179. struct drm_file *file_priv)
  180. {
  181. struct drm_i915_private *dev_priv = dev->dev_private;
  182. drm_i915_setparam_t *param = data;
  183. switch (param->param) {
  184. case I915_SETPARAM_USE_MI_BATCHBUFFER_START:
  185. case I915_SETPARAM_TEX_LRU_LOG_GRANULARITY:
  186. case I915_SETPARAM_ALLOW_BATCHBUFFER:
  187. /* Reject all old ums/dri params. */
  188. return -ENODEV;
  189. case I915_SETPARAM_NUM_USED_FENCES:
  190. if (param->value > dev_priv->num_fence_regs ||
  191. param->value < 0)
  192. return -EINVAL;
  193. /* Userspace can use first N regs */
  194. dev_priv->fence_reg_start = param->value;
  195. break;
  196. default:
  197. DRM_DEBUG_DRIVER("unknown parameter %d\n",
  198. param->param);
  199. return -EINVAL;
  200. }
  201. return 0;
  202. }
  203. static int i915_get_bridge_dev(struct drm_device *dev)
  204. {
  205. struct drm_i915_private *dev_priv = dev->dev_private;
  206. dev_priv->bridge_dev = pci_get_bus_and_slot(0, PCI_DEVFN(0, 0));
  207. if (!dev_priv->bridge_dev) {
  208. DRM_ERROR("bridge device not found\n");
  209. return -1;
  210. }
  211. return 0;
  212. }
  213. #define MCHBAR_I915 0x44
  214. #define MCHBAR_I965 0x48
  215. #define MCHBAR_SIZE (4*4096)
  216. #define DEVEN_REG 0x54
  217. #define DEVEN_MCHBAR_EN (1 << 28)
  218. /* Allocate space for the MCH regs if needed, return nonzero on error */
  219. static int
  220. intel_alloc_mchbar_resource(struct drm_device *dev)
  221. {
  222. struct drm_i915_private *dev_priv = dev->dev_private;
  223. int reg = INTEL_INFO(dev)->gen >= 4 ? MCHBAR_I965 : MCHBAR_I915;
  224. u32 temp_lo, temp_hi = 0;
  225. u64 mchbar_addr;
  226. int ret;
  227. if (INTEL_INFO(dev)->gen >= 4)
  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. /* If ACPI doesn't have it, assume we need to allocate it ourselves */
  232. #ifdef CONFIG_PNP
  233. if (mchbar_addr &&
  234. pnp_range_reserved(mchbar_addr, mchbar_addr + MCHBAR_SIZE))
  235. return 0;
  236. #endif
  237. /* Get some space for it */
  238. dev_priv->mch_res.name = "i915 MCHBAR";
  239. dev_priv->mch_res.flags = IORESOURCE_MEM;
  240. ret = pci_bus_alloc_resource(dev_priv->bridge_dev->bus,
  241. &dev_priv->mch_res,
  242. MCHBAR_SIZE, MCHBAR_SIZE,
  243. PCIBIOS_MIN_MEM,
  244. 0, pcibios_align_resource,
  245. dev_priv->bridge_dev);
  246. if (ret) {
  247. DRM_DEBUG_DRIVER("failed bus alloc: %d\n", ret);
  248. dev_priv->mch_res.start = 0;
  249. return ret;
  250. }
  251. if (INTEL_INFO(dev)->gen >= 4)
  252. pci_write_config_dword(dev_priv->bridge_dev, reg + 4,
  253. upper_32_bits(dev_priv->mch_res.start));
  254. pci_write_config_dword(dev_priv->bridge_dev, reg,
  255. lower_32_bits(dev_priv->mch_res.start));
  256. return 0;
  257. }
  258. /* Setup MCHBAR if possible, return true if we should disable it again */
  259. static void
  260. intel_setup_mchbar(struct drm_device *dev)
  261. {
  262. struct drm_i915_private *dev_priv = dev->dev_private;
  263. int mchbar_reg = INTEL_INFO(dev)->gen >= 4 ? MCHBAR_I965 : MCHBAR_I915;
  264. u32 temp;
  265. bool enabled;
  266. if (IS_VALLEYVIEW(dev))
  267. return;
  268. dev_priv->mchbar_need_disable = false;
  269. if (IS_I915G(dev) || IS_I915GM(dev)) {
  270. pci_read_config_dword(dev_priv->bridge_dev, DEVEN_REG, &temp);
  271. enabled = !!(temp & DEVEN_MCHBAR_EN);
  272. } else {
  273. pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp);
  274. enabled = temp & 1;
  275. }
  276. /* If it's already enabled, don't have to do anything */
  277. if (enabled)
  278. return;
  279. if (intel_alloc_mchbar_resource(dev))
  280. return;
  281. dev_priv->mchbar_need_disable = true;
  282. /* Space is allocated or reserved, so enable it. */
  283. if (IS_I915G(dev) || IS_I915GM(dev)) {
  284. pci_write_config_dword(dev_priv->bridge_dev, DEVEN_REG,
  285. temp | DEVEN_MCHBAR_EN);
  286. } else {
  287. pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp);
  288. pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp | 1);
  289. }
  290. }
  291. static void
  292. intel_teardown_mchbar(struct drm_device *dev)
  293. {
  294. struct drm_i915_private *dev_priv = dev->dev_private;
  295. int mchbar_reg = INTEL_INFO(dev)->gen >= 4 ? MCHBAR_I965 : MCHBAR_I915;
  296. u32 temp;
  297. if (dev_priv->mchbar_need_disable) {
  298. if (IS_I915G(dev) || IS_I915GM(dev)) {
  299. pci_read_config_dword(dev_priv->bridge_dev, DEVEN_REG, &temp);
  300. temp &= ~DEVEN_MCHBAR_EN;
  301. pci_write_config_dword(dev_priv->bridge_dev, DEVEN_REG, temp);
  302. } else {
  303. pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp);
  304. temp &= ~1;
  305. pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp);
  306. }
  307. }
  308. if (dev_priv->mch_res.start)
  309. release_resource(&dev_priv->mch_res);
  310. }
  311. /* true = enable decode, false = disable decoder */
  312. static unsigned int i915_vga_set_decode(void *cookie, bool state)
  313. {
  314. struct drm_device *dev = cookie;
  315. intel_modeset_vga_set_state(dev, state);
  316. if (state)
  317. return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
  318. VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
  319. else
  320. return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
  321. }
  322. static void i915_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state)
  323. {
  324. struct drm_device *dev = pci_get_drvdata(pdev);
  325. pm_message_t pmm = { .event = PM_EVENT_SUSPEND };
  326. if (state == VGA_SWITCHEROO_ON) {
  327. pr_info("switched on\n");
  328. dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  329. /* i915 resume handler doesn't set to D0 */
  330. pci_set_power_state(dev->pdev, PCI_D0);
  331. i915_resume_legacy(dev);
  332. dev->switch_power_state = DRM_SWITCH_POWER_ON;
  333. } else {
  334. pr_err("switched off\n");
  335. dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  336. i915_suspend_legacy(dev, pmm);
  337. dev->switch_power_state = DRM_SWITCH_POWER_OFF;
  338. }
  339. }
  340. static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
  341. {
  342. struct drm_device *dev = pci_get_drvdata(pdev);
  343. /*
  344. * FIXME: open_count is protected by drm_global_mutex but that would lead to
  345. * locking inversion with the driver load path. And the access here is
  346. * completely racy anyway. So don't bother with locking for now.
  347. */
  348. return dev->open_count == 0;
  349. }
  350. static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
  351. .set_gpu_state = i915_switcheroo_set_state,
  352. .reprobe = NULL,
  353. .can_switch = i915_switcheroo_can_switch,
  354. };
  355. static int i915_load_modeset_init(struct drm_device *dev)
  356. {
  357. struct drm_i915_private *dev_priv = dev->dev_private;
  358. int ret;
  359. ret = intel_parse_bios(dev);
  360. if (ret)
  361. DRM_INFO("failed to find VBIOS tables\n");
  362. /* If we have > 1 VGA cards, then we need to arbitrate access
  363. * to the common VGA resources.
  364. *
  365. * If we are a secondary display controller (!PCI_DISPLAY_CLASS_VGA),
  366. * then we do not take part in VGA arbitration and the
  367. * vga_client_register() fails with -ENODEV.
  368. */
  369. ret = vga_client_register(dev->pdev, dev, NULL, i915_vga_set_decode);
  370. if (ret && ret != -ENODEV)
  371. goto out;
  372. intel_register_dsm_handler();
  373. ret = vga_switcheroo_register_client(dev->pdev, &i915_switcheroo_ops, false);
  374. if (ret)
  375. goto cleanup_vga_client;
  376. /* Initialise stolen first so that we may reserve preallocated
  377. * objects for the BIOS to KMS transition.
  378. */
  379. ret = i915_gem_init_stolen(dev);
  380. if (ret)
  381. goto cleanup_vga_switcheroo;
  382. intel_power_domains_init_hw(dev_priv);
  383. ret = intel_irq_install(dev_priv);
  384. if (ret)
  385. goto cleanup_gem_stolen;
  386. /* Important: The output setup functions called by modeset_init need
  387. * working irqs for e.g. gmbus and dp aux transfers. */
  388. intel_modeset_init(dev);
  389. ret = i915_gem_init(dev);
  390. if (ret)
  391. goto cleanup_irq;
  392. intel_modeset_gem_init(dev);
  393. /* Always safe in the mode setting case. */
  394. /* FIXME: do pre/post-mode set stuff in core KMS code */
  395. dev->vblank_disable_allowed = true;
  396. if (INTEL_INFO(dev)->num_pipes == 0)
  397. return 0;
  398. ret = intel_fbdev_init(dev);
  399. if (ret)
  400. goto cleanup_gem;
  401. /* Only enable hotplug handling once the fbdev is fully set up. */
  402. intel_hpd_init(dev_priv);
  403. /*
  404. * Some ports require correctly set-up hpd registers for detection to
  405. * work properly (leading to ghost connected connector status), e.g. VGA
  406. * on gm45. Hence we can only set up the initial fbdev config after hpd
  407. * irqs are fully enabled. Now we should scan for the initial config
  408. * only once hotplug handling is enabled, but due to screwed-up locking
  409. * around kms/fbdev init we can't protect the fdbev initial config
  410. * scanning against hotplug events. Hence do this first and ignore the
  411. * tiny window where we will loose hotplug notifactions.
  412. */
  413. async_schedule(intel_fbdev_initial_config, dev_priv);
  414. drm_kms_helper_poll_init(dev);
  415. return 0;
  416. cleanup_gem:
  417. mutex_lock(&dev->struct_mutex);
  418. i915_gem_cleanup_ringbuffer(dev);
  419. i915_gem_context_fini(dev);
  420. mutex_unlock(&dev->struct_mutex);
  421. cleanup_irq:
  422. drm_irq_uninstall(dev);
  423. cleanup_gem_stolen:
  424. i915_gem_cleanup_stolen(dev);
  425. cleanup_vga_switcheroo:
  426. vga_switcheroo_unregister_client(dev->pdev);
  427. cleanup_vga_client:
  428. vga_client_register(dev->pdev, NULL, NULL, NULL);
  429. out:
  430. return ret;
  431. }
  432. #if IS_ENABLED(CONFIG_FB)
  433. static int i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv)
  434. {
  435. struct apertures_struct *ap;
  436. struct pci_dev *pdev = dev_priv->dev->pdev;
  437. bool primary;
  438. int ret;
  439. ap = alloc_apertures(1);
  440. if (!ap)
  441. return -ENOMEM;
  442. ap->ranges[0].base = dev_priv->gtt.mappable_base;
  443. ap->ranges[0].size = dev_priv->gtt.mappable_end;
  444. primary =
  445. pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
  446. ret = remove_conflicting_framebuffers(ap, "inteldrmfb", primary);
  447. kfree(ap);
  448. return ret;
  449. }
  450. #else
  451. static int i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv)
  452. {
  453. return 0;
  454. }
  455. #endif
  456. #if !defined(CONFIG_VGA_CONSOLE)
  457. static int i915_kick_out_vgacon(struct drm_i915_private *dev_priv)
  458. {
  459. return 0;
  460. }
  461. #elif !defined(CONFIG_DUMMY_CONSOLE)
  462. static int i915_kick_out_vgacon(struct drm_i915_private *dev_priv)
  463. {
  464. return -ENODEV;
  465. }
  466. #else
  467. static int i915_kick_out_vgacon(struct drm_i915_private *dev_priv)
  468. {
  469. int ret = 0;
  470. DRM_INFO("Replacing VGA console driver\n");
  471. console_lock();
  472. if (con_is_bound(&vga_con))
  473. ret = do_take_over_console(&dummy_con, 0, MAX_NR_CONSOLES - 1, 1);
  474. if (ret == 0) {
  475. ret = do_unregister_con_driver(&vga_con);
  476. /* Ignore "already unregistered". */
  477. if (ret == -ENODEV)
  478. ret = 0;
  479. }
  480. console_unlock();
  481. return ret;
  482. }
  483. #endif
  484. static void i915_dump_device_info(struct drm_i915_private *dev_priv)
  485. {
  486. const struct intel_device_info *info = &dev_priv->info;
  487. #define PRINT_S(name) "%s"
  488. #define SEP_EMPTY
  489. #define PRINT_FLAG(name) info->name ? #name "," : ""
  490. #define SEP_COMMA ,
  491. DRM_DEBUG_DRIVER("i915 device info: gen=%i, pciid=0x%04x rev=0x%02x flags="
  492. DEV_INFO_FOR_EACH_FLAG(PRINT_S, SEP_EMPTY),
  493. info->gen,
  494. dev_priv->dev->pdev->device,
  495. dev_priv->dev->pdev->revision,
  496. DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_COMMA));
  497. #undef PRINT_S
  498. #undef SEP_EMPTY
  499. #undef PRINT_FLAG
  500. #undef SEP_COMMA
  501. }
  502. static void cherryview_sseu_info_init(struct drm_device *dev)
  503. {
  504. struct drm_i915_private *dev_priv = dev->dev_private;
  505. struct intel_device_info *info;
  506. u32 fuse, eu_dis;
  507. info = (struct intel_device_info *)&dev_priv->info;
  508. fuse = I915_READ(CHV_FUSE_GT);
  509. info->slice_total = 1;
  510. if (!(fuse & CHV_FGT_DISABLE_SS0)) {
  511. info->subslice_per_slice++;
  512. eu_dis = fuse & (CHV_FGT_EU_DIS_SS0_R0_MASK |
  513. CHV_FGT_EU_DIS_SS0_R1_MASK);
  514. info->eu_total += 8 - hweight32(eu_dis);
  515. }
  516. if (!(fuse & CHV_FGT_DISABLE_SS1)) {
  517. info->subslice_per_slice++;
  518. eu_dis = fuse & (CHV_FGT_EU_DIS_SS1_R0_MASK |
  519. CHV_FGT_EU_DIS_SS1_R1_MASK);
  520. info->eu_total += 8 - hweight32(eu_dis);
  521. }
  522. info->subslice_total = info->subslice_per_slice;
  523. /*
  524. * CHV expected to always have a uniform distribution of EU
  525. * across subslices.
  526. */
  527. info->eu_per_subslice = info->subslice_total ?
  528. info->eu_total / info->subslice_total :
  529. 0;
  530. /*
  531. * CHV supports subslice power gating on devices with more than
  532. * one subslice, and supports EU power gating on devices with
  533. * more than one EU pair per subslice.
  534. */
  535. info->has_slice_pg = 0;
  536. info->has_subslice_pg = (info->subslice_total > 1);
  537. info->has_eu_pg = (info->eu_per_subslice > 2);
  538. }
  539. static void gen9_sseu_info_init(struct drm_device *dev)
  540. {
  541. struct drm_i915_private *dev_priv = dev->dev_private;
  542. struct intel_device_info *info;
  543. int s_max = 3, ss_max = 4, eu_max = 8;
  544. int s, ss;
  545. u32 fuse2, s_enable, ss_disable, eu_disable;
  546. u8 eu_mask = 0xff;
  547. /*
  548. * BXT has a single slice. BXT also has at most 6 EU per subslice,
  549. * and therefore only the lowest 6 bits of the 8-bit EU disable
  550. * fields are valid.
  551. */
  552. if (IS_BROXTON(dev)) {
  553. s_max = 1;
  554. eu_max = 6;
  555. eu_mask = 0x3f;
  556. }
  557. info = (struct intel_device_info *)&dev_priv->info;
  558. fuse2 = I915_READ(GEN8_FUSE2);
  559. s_enable = (fuse2 & GEN8_F2_S_ENA_MASK) >>
  560. GEN8_F2_S_ENA_SHIFT;
  561. ss_disable = (fuse2 & GEN9_F2_SS_DIS_MASK) >>
  562. GEN9_F2_SS_DIS_SHIFT;
  563. info->slice_total = hweight32(s_enable);
  564. /*
  565. * The subslice disable field is global, i.e. it applies
  566. * to each of the enabled slices.
  567. */
  568. info->subslice_per_slice = ss_max - hweight32(ss_disable);
  569. info->subslice_total = info->slice_total *
  570. info->subslice_per_slice;
  571. /*
  572. * Iterate through enabled slices and subslices to
  573. * count the total enabled EU.
  574. */
  575. for (s = 0; s < s_max; s++) {
  576. if (!(s_enable & (0x1 << s)))
  577. /* skip disabled slice */
  578. continue;
  579. eu_disable = I915_READ(GEN9_EU_DISABLE(s));
  580. for (ss = 0; ss < ss_max; ss++) {
  581. int eu_per_ss;
  582. if (ss_disable & (0x1 << ss))
  583. /* skip disabled subslice */
  584. continue;
  585. eu_per_ss = eu_max - hweight8((eu_disable >> (ss*8)) &
  586. eu_mask);
  587. /*
  588. * Record which subslice(s) has(have) 7 EUs. we
  589. * can tune the hash used to spread work among
  590. * subslices if they are unbalanced.
  591. */
  592. if (eu_per_ss == 7)
  593. info->subslice_7eu[s] |= 1 << ss;
  594. info->eu_total += eu_per_ss;
  595. }
  596. }
  597. /*
  598. * SKL is expected to always have a uniform distribution
  599. * of EU across subslices with the exception that any one
  600. * EU in any one subslice may be fused off for die
  601. * recovery. BXT is expected to be perfectly uniform in EU
  602. * distribution.
  603. */
  604. info->eu_per_subslice = info->subslice_total ?
  605. DIV_ROUND_UP(info->eu_total,
  606. info->subslice_total) : 0;
  607. /*
  608. * SKL supports slice power gating on devices with more than
  609. * one slice, and supports EU power gating on devices with
  610. * more than one EU pair per subslice. BXT supports subslice
  611. * power gating on devices with more than one subslice, and
  612. * supports EU power gating on devices with more than one EU
  613. * pair per subslice.
  614. */
  615. info->has_slice_pg = (IS_SKYLAKE(dev) && (info->slice_total > 1));
  616. info->has_subslice_pg = (IS_BROXTON(dev) && (info->subslice_total > 1));
  617. info->has_eu_pg = (info->eu_per_subslice > 2);
  618. }
  619. /*
  620. * Determine various intel_device_info fields at runtime.
  621. *
  622. * Use it when either:
  623. * - it's judged too laborious to fill n static structures with the limit
  624. * when a simple if statement does the job,
  625. * - run-time checks (eg read fuse/strap registers) are needed.
  626. *
  627. * This function needs to be called:
  628. * - after the MMIO has been setup as we are reading registers,
  629. * - after the PCH has been detected,
  630. * - before the first usage of the fields it can tweak.
  631. */
  632. static void intel_device_info_runtime_init(struct drm_device *dev)
  633. {
  634. struct drm_i915_private *dev_priv = dev->dev_private;
  635. struct intel_device_info *info;
  636. enum pipe pipe;
  637. info = (struct intel_device_info *)&dev_priv->info;
  638. /*
  639. * Skylake and Broxton currently don't expose the topmost plane as its
  640. * use is exclusive with the legacy cursor and we only want to expose
  641. * one of those, not both. Until we can safely expose the topmost plane
  642. * as a DRM_PLANE_TYPE_CURSOR with all the features exposed/supported,
  643. * we don't expose the topmost plane at all to prevent ABI breakage
  644. * down the line.
  645. */
  646. if (IS_BROXTON(dev)) {
  647. info->num_sprites[PIPE_A] = 2;
  648. info->num_sprites[PIPE_B] = 2;
  649. info->num_sprites[PIPE_C] = 1;
  650. } else if (IS_VALLEYVIEW(dev))
  651. for_each_pipe(dev_priv, pipe)
  652. info->num_sprites[pipe] = 2;
  653. else
  654. for_each_pipe(dev_priv, pipe)
  655. info->num_sprites[pipe] = 1;
  656. if (i915.disable_display) {
  657. DRM_INFO("Display disabled (module parameter)\n");
  658. info->num_pipes = 0;
  659. } else if (info->num_pipes > 0 &&
  660. (INTEL_INFO(dev)->gen == 7 || INTEL_INFO(dev)->gen == 8) &&
  661. !IS_VALLEYVIEW(dev)) {
  662. u32 fuse_strap = I915_READ(FUSE_STRAP);
  663. u32 sfuse_strap = I915_READ(SFUSE_STRAP);
  664. /*
  665. * SFUSE_STRAP is supposed to have a bit signalling the display
  666. * is fused off. Unfortunately it seems that, at least in
  667. * certain cases, fused off display means that PCH display
  668. * reads don't land anywhere. In that case, we read 0s.
  669. *
  670. * On CPT/PPT, we can detect this case as SFUSE_STRAP_FUSE_LOCK
  671. * should be set when taking over after the firmware.
  672. */
  673. if (fuse_strap & ILK_INTERNAL_DISPLAY_DISABLE ||
  674. sfuse_strap & SFUSE_STRAP_DISPLAY_DISABLED ||
  675. (dev_priv->pch_type == PCH_CPT &&
  676. !(sfuse_strap & SFUSE_STRAP_FUSE_LOCK))) {
  677. DRM_INFO("Display fused off, disabling\n");
  678. info->num_pipes = 0;
  679. }
  680. }
  681. /* Initialize slice/subslice/EU info */
  682. if (IS_CHERRYVIEW(dev))
  683. cherryview_sseu_info_init(dev);
  684. else if (INTEL_INFO(dev)->gen >= 9)
  685. gen9_sseu_info_init(dev);
  686. DRM_DEBUG_DRIVER("slice total: %u\n", info->slice_total);
  687. DRM_DEBUG_DRIVER("subslice total: %u\n", info->subslice_total);
  688. DRM_DEBUG_DRIVER("subslice per slice: %u\n", info->subslice_per_slice);
  689. DRM_DEBUG_DRIVER("EU total: %u\n", info->eu_total);
  690. DRM_DEBUG_DRIVER("EU per subslice: %u\n", info->eu_per_subslice);
  691. DRM_DEBUG_DRIVER("has slice power gating: %s\n",
  692. info->has_slice_pg ? "y" : "n");
  693. DRM_DEBUG_DRIVER("has subslice power gating: %s\n",
  694. info->has_subslice_pg ? "y" : "n");
  695. DRM_DEBUG_DRIVER("has EU power gating: %s\n",
  696. info->has_eu_pg ? "y" : "n");
  697. }
  698. /**
  699. * i915_driver_load - setup chip and create an initial config
  700. * @dev: DRM device
  701. * @flags: startup flags
  702. *
  703. * The driver load routine has to do several things:
  704. * - drive output discovery via intel_modeset_init()
  705. * - initialize the memory manager
  706. * - allocate initial config memory
  707. * - setup the DRM framebuffer with the allocated memory
  708. */
  709. int i915_driver_load(struct drm_device *dev, unsigned long flags)
  710. {
  711. struct drm_i915_private *dev_priv;
  712. struct intel_device_info *info, *device_info;
  713. int ret = 0, mmio_bar, mmio_size;
  714. uint32_t aperture_size;
  715. info = (struct intel_device_info *) flags;
  716. dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
  717. if (dev_priv == NULL)
  718. return -ENOMEM;
  719. dev->dev_private = dev_priv;
  720. dev_priv->dev = dev;
  721. /* Setup the write-once "constant" device info */
  722. device_info = (struct intel_device_info *)&dev_priv->info;
  723. memcpy(device_info, info, sizeof(dev_priv->info));
  724. device_info->device_id = dev->pdev->device;
  725. spin_lock_init(&dev_priv->irq_lock);
  726. spin_lock_init(&dev_priv->gpu_error.lock);
  727. mutex_init(&dev_priv->backlight_lock);
  728. spin_lock_init(&dev_priv->uncore.lock);
  729. spin_lock_init(&dev_priv->mm.object_stat_lock);
  730. spin_lock_init(&dev_priv->mmio_flip_lock);
  731. mutex_init(&dev_priv->sb_lock);
  732. mutex_init(&dev_priv->modeset_restore_lock);
  733. mutex_init(&dev_priv->csr_lock);
  734. intel_pm_setup(dev);
  735. intel_display_crc_init(dev);
  736. i915_dump_device_info(dev_priv);
  737. /* Not all pre-production machines fall into this category, only the
  738. * very first ones. Almost everything should work, except for maybe
  739. * suspend/resume. And we don't implement workarounds that affect only
  740. * pre-production machines. */
  741. if (IS_HSW_EARLY_SDV(dev))
  742. DRM_INFO("This is an early pre-production Haswell machine. "
  743. "It may not be fully functional.\n");
  744. if (i915_get_bridge_dev(dev)) {
  745. ret = -EIO;
  746. goto free_priv;
  747. }
  748. mmio_bar = IS_GEN2(dev) ? 1 : 0;
  749. /* Before gen4, the registers and the GTT are behind different BARs.
  750. * However, from gen4 onwards, the registers and the GTT are shared
  751. * in the same BAR, so we want to restrict this ioremap from
  752. * clobbering the GTT which we want ioremap_wc instead. Fortunately,
  753. * the register BAR remains the same size for all the earlier
  754. * generations up to Ironlake.
  755. */
  756. if (info->gen < 5)
  757. mmio_size = 512*1024;
  758. else
  759. mmio_size = 2*1024*1024;
  760. dev_priv->regs = pci_iomap(dev->pdev, mmio_bar, mmio_size);
  761. if (!dev_priv->regs) {
  762. DRM_ERROR("failed to map registers\n");
  763. ret = -EIO;
  764. goto put_bridge;
  765. }
  766. /* This must be called before any calls to HAS_PCH_* */
  767. intel_detect_pch(dev);
  768. intel_uncore_init(dev);
  769. /* Load CSR Firmware for SKL */
  770. intel_csr_ucode_init(dev);
  771. ret = i915_gem_gtt_init(dev);
  772. if (ret)
  773. goto out_freecsr;
  774. /* WARNING: Apparently we must kick fbdev drivers before vgacon,
  775. * otherwise the vga fbdev driver falls over. */
  776. ret = i915_kick_out_firmware_fb(dev_priv);
  777. if (ret) {
  778. DRM_ERROR("failed to remove conflicting framebuffer drivers\n");
  779. goto out_gtt;
  780. }
  781. ret = i915_kick_out_vgacon(dev_priv);
  782. if (ret) {
  783. DRM_ERROR("failed to remove conflicting VGA console\n");
  784. goto out_gtt;
  785. }
  786. pci_set_master(dev->pdev);
  787. /* overlay on gen2 is broken and can't address above 1G */
  788. if (IS_GEN2(dev))
  789. dma_set_coherent_mask(&dev->pdev->dev, DMA_BIT_MASK(30));
  790. /* 965GM sometimes incorrectly writes to hardware status page (HWS)
  791. * using 32bit addressing, overwriting memory if HWS is located
  792. * above 4GB.
  793. *
  794. * The documentation also mentions an issue with undefined
  795. * behaviour if any general state is accessed within a page above 4GB,
  796. * which also needs to be handled carefully.
  797. */
  798. if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  799. dma_set_coherent_mask(&dev->pdev->dev, DMA_BIT_MASK(32));
  800. aperture_size = dev_priv->gtt.mappable_end;
  801. dev_priv->gtt.mappable =
  802. io_mapping_create_wc(dev_priv->gtt.mappable_base,
  803. aperture_size);
  804. if (dev_priv->gtt.mappable == NULL) {
  805. ret = -EIO;
  806. goto out_gtt;
  807. }
  808. dev_priv->gtt.mtrr = arch_phys_wc_add(dev_priv->gtt.mappable_base,
  809. aperture_size);
  810. /* The i915 workqueue is primarily used for batched retirement of
  811. * requests (and thus managing bo) once the task has been completed
  812. * by the GPU. i915_gem_retire_requests() is called directly when we
  813. * need high-priority retirement, such as waiting for an explicit
  814. * bo.
  815. *
  816. * It is also used for periodic low-priority events, such as
  817. * idle-timers and recording error state.
  818. *
  819. * All tasks on the workqueue are expected to acquire the dev mutex
  820. * so there is no point in running more than one instance of the
  821. * workqueue at any time. Use an ordered one.
  822. */
  823. dev_priv->wq = alloc_ordered_workqueue("i915", 0);
  824. if (dev_priv->wq == NULL) {
  825. DRM_ERROR("Failed to create our workqueue.\n");
  826. ret = -ENOMEM;
  827. goto out_mtrrfree;
  828. }
  829. dev_priv->hotplug.dp_wq = alloc_ordered_workqueue("i915-dp", 0);
  830. if (dev_priv->hotplug.dp_wq == NULL) {
  831. DRM_ERROR("Failed to create our dp workqueue.\n");
  832. ret = -ENOMEM;
  833. goto out_freewq;
  834. }
  835. dev_priv->gpu_error.hangcheck_wq =
  836. alloc_ordered_workqueue("i915-hangcheck", 0);
  837. if (dev_priv->gpu_error.hangcheck_wq == NULL) {
  838. DRM_ERROR("Failed to create our hangcheck workqueue.\n");
  839. ret = -ENOMEM;
  840. goto out_freedpwq;
  841. }
  842. intel_irq_init(dev_priv);
  843. intel_uncore_sanitize(dev);
  844. /* Try to make sure MCHBAR is enabled before poking at it */
  845. intel_setup_mchbar(dev);
  846. intel_setup_gmbus(dev);
  847. intel_opregion_setup(dev);
  848. intel_setup_bios(dev);
  849. i915_gem_load(dev);
  850. /* On the 945G/GM, the chipset reports the MSI capability on the
  851. * integrated graphics even though the support isn't actually there
  852. * according to the published specs. It doesn't appear to function
  853. * correctly in testing on 945G.
  854. * This may be a side effect of MSI having been made available for PEG
  855. * and the registers being closely associated.
  856. *
  857. * According to chipset errata, on the 965GM, MSI interrupts may
  858. * be lost or delayed, but we use them anyways to avoid
  859. * stuck interrupts on some machines.
  860. */
  861. if (!IS_I945G(dev) && !IS_I945GM(dev))
  862. pci_enable_msi(dev->pdev);
  863. intel_device_info_runtime_init(dev);
  864. if (INTEL_INFO(dev)->num_pipes) {
  865. ret = drm_vblank_init(dev, INTEL_INFO(dev)->num_pipes);
  866. if (ret)
  867. goto out_gem_unload;
  868. }
  869. intel_power_domains_init(dev_priv);
  870. ret = i915_load_modeset_init(dev);
  871. if (ret < 0) {
  872. DRM_ERROR("failed to init modeset\n");
  873. goto out_power_well;
  874. }
  875. /*
  876. * Notify a valid surface after modesetting,
  877. * when running inside a VM.
  878. */
  879. if (intel_vgpu_active(dev))
  880. I915_WRITE(vgtif_reg(display_ready), VGT_DRV_DISPLAY_READY);
  881. i915_setup_sysfs(dev);
  882. if (INTEL_INFO(dev)->num_pipes) {
  883. /* Must be done after probing outputs */
  884. intel_opregion_init(dev);
  885. acpi_video_register();
  886. }
  887. if (IS_GEN5(dev))
  888. intel_gpu_ips_init(dev_priv);
  889. intel_runtime_pm_enable(dev_priv);
  890. i915_audio_component_init(dev_priv);
  891. return 0;
  892. out_power_well:
  893. intel_power_domains_fini(dev_priv);
  894. drm_vblank_cleanup(dev);
  895. out_gem_unload:
  896. WARN_ON(unregister_oom_notifier(&dev_priv->mm.oom_notifier));
  897. unregister_shrinker(&dev_priv->mm.shrinker);
  898. if (dev->pdev->msi_enabled)
  899. pci_disable_msi(dev->pdev);
  900. intel_teardown_gmbus(dev);
  901. intel_teardown_mchbar(dev);
  902. pm_qos_remove_request(&dev_priv->pm_qos);
  903. destroy_workqueue(dev_priv->gpu_error.hangcheck_wq);
  904. out_freedpwq:
  905. destroy_workqueue(dev_priv->hotplug.dp_wq);
  906. out_freewq:
  907. destroy_workqueue(dev_priv->wq);
  908. out_mtrrfree:
  909. arch_phys_wc_del(dev_priv->gtt.mtrr);
  910. io_mapping_free(dev_priv->gtt.mappable);
  911. out_gtt:
  912. i915_global_gtt_cleanup(dev);
  913. out_freecsr:
  914. intel_csr_ucode_fini(dev);
  915. intel_uncore_fini(dev);
  916. pci_iounmap(dev->pdev, dev_priv->regs);
  917. put_bridge:
  918. pci_dev_put(dev_priv->bridge_dev);
  919. free_priv:
  920. if (dev_priv->requests)
  921. kmem_cache_destroy(dev_priv->requests);
  922. if (dev_priv->vmas)
  923. kmem_cache_destroy(dev_priv->vmas);
  924. if (dev_priv->objects)
  925. kmem_cache_destroy(dev_priv->objects);
  926. kfree(dev_priv);
  927. return ret;
  928. }
  929. int i915_driver_unload(struct drm_device *dev)
  930. {
  931. struct drm_i915_private *dev_priv = dev->dev_private;
  932. int ret;
  933. i915_audio_component_cleanup(dev_priv);
  934. ret = i915_gem_suspend(dev);
  935. if (ret) {
  936. DRM_ERROR("failed to idle hardware: %d\n", ret);
  937. return ret;
  938. }
  939. intel_power_domains_fini(dev_priv);
  940. intel_gpu_ips_teardown();
  941. i915_teardown_sysfs(dev);
  942. WARN_ON(unregister_oom_notifier(&dev_priv->mm.oom_notifier));
  943. unregister_shrinker(&dev_priv->mm.shrinker);
  944. io_mapping_free(dev_priv->gtt.mappable);
  945. arch_phys_wc_del(dev_priv->gtt.mtrr);
  946. acpi_video_unregister();
  947. intel_fbdev_fini(dev);
  948. drm_vblank_cleanup(dev);
  949. intel_modeset_cleanup(dev);
  950. /*
  951. * free the memory space allocated for the child device
  952. * config parsed from VBT
  953. */
  954. if (dev_priv->vbt.child_dev && dev_priv->vbt.child_dev_num) {
  955. kfree(dev_priv->vbt.child_dev);
  956. dev_priv->vbt.child_dev = NULL;
  957. dev_priv->vbt.child_dev_num = 0;
  958. }
  959. vga_switcheroo_unregister_client(dev->pdev);
  960. vga_client_register(dev->pdev, NULL, NULL, NULL);
  961. /* Free error state after interrupts are fully disabled. */
  962. cancel_delayed_work_sync(&dev_priv->gpu_error.hangcheck_work);
  963. i915_destroy_error_state(dev);
  964. if (dev->pdev->msi_enabled)
  965. pci_disable_msi(dev->pdev);
  966. intel_opregion_fini(dev);
  967. /* Flush any outstanding unpin_work. */
  968. flush_workqueue(dev_priv->wq);
  969. mutex_lock(&dev->struct_mutex);
  970. i915_gem_cleanup_ringbuffer(dev);
  971. i915_gem_context_fini(dev);
  972. mutex_unlock(&dev->struct_mutex);
  973. intel_fbc_cleanup_cfb(dev_priv);
  974. i915_gem_cleanup_stolen(dev);
  975. intel_csr_ucode_fini(dev);
  976. intel_teardown_gmbus(dev);
  977. intel_teardown_mchbar(dev);
  978. destroy_workqueue(dev_priv->hotplug.dp_wq);
  979. destroy_workqueue(dev_priv->wq);
  980. destroy_workqueue(dev_priv->gpu_error.hangcheck_wq);
  981. pm_qos_remove_request(&dev_priv->pm_qos);
  982. i915_global_gtt_cleanup(dev);
  983. intel_uncore_fini(dev);
  984. if (dev_priv->regs != NULL)
  985. pci_iounmap(dev->pdev, dev_priv->regs);
  986. if (dev_priv->requests)
  987. kmem_cache_destroy(dev_priv->requests);
  988. if (dev_priv->vmas)
  989. kmem_cache_destroy(dev_priv->vmas);
  990. if (dev_priv->objects)
  991. kmem_cache_destroy(dev_priv->objects);
  992. pci_dev_put(dev_priv->bridge_dev);
  993. kfree(dev_priv);
  994. return 0;
  995. }
  996. int i915_driver_open(struct drm_device *dev, struct drm_file *file)
  997. {
  998. int ret;
  999. ret = i915_gem_open(dev, file);
  1000. if (ret)
  1001. return ret;
  1002. return 0;
  1003. }
  1004. /**
  1005. * i915_driver_lastclose - clean up after all DRM clients have exited
  1006. * @dev: DRM device
  1007. *
  1008. * Take care of cleaning up after all DRM clients have exited. In the
  1009. * mode setting case, we want to restore the kernel's initial mode (just
  1010. * in case the last client left us in a bad state).
  1011. *
  1012. * Additionally, in the non-mode setting case, we'll tear down the GTT
  1013. * and DMA structures, since the kernel won't be using them, and clea
  1014. * up any GEM state.
  1015. */
  1016. void i915_driver_lastclose(struct drm_device *dev)
  1017. {
  1018. intel_fbdev_restore_mode(dev);
  1019. vga_switcheroo_process_delayed_switch();
  1020. }
  1021. void i915_driver_preclose(struct drm_device *dev, struct drm_file *file)
  1022. {
  1023. mutex_lock(&dev->struct_mutex);
  1024. i915_gem_context_close(dev, file);
  1025. i915_gem_release(dev, file);
  1026. mutex_unlock(&dev->struct_mutex);
  1027. intel_modeset_preclose(dev, file);
  1028. }
  1029. void i915_driver_postclose(struct drm_device *dev, struct drm_file *file)
  1030. {
  1031. struct drm_i915_file_private *file_priv = file->driver_priv;
  1032. if (file_priv && file_priv->bsd_ring)
  1033. file_priv->bsd_ring = NULL;
  1034. kfree(file_priv);
  1035. }
  1036. static int
  1037. i915_gem_reject_pin_ioctl(struct drm_device *dev, void *data,
  1038. struct drm_file *file)
  1039. {
  1040. return -ENODEV;
  1041. }
  1042. const struct drm_ioctl_desc i915_ioctls[] = {
  1043. DRM_IOCTL_DEF_DRV(I915_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  1044. DRM_IOCTL_DEF_DRV(I915_FLUSH, drm_noop, DRM_AUTH),
  1045. DRM_IOCTL_DEF_DRV(I915_FLIP, drm_noop, DRM_AUTH),
  1046. DRM_IOCTL_DEF_DRV(I915_BATCHBUFFER, drm_noop, DRM_AUTH),
  1047. DRM_IOCTL_DEF_DRV(I915_IRQ_EMIT, drm_noop, DRM_AUTH),
  1048. DRM_IOCTL_DEF_DRV(I915_IRQ_WAIT, drm_noop, DRM_AUTH),
  1049. DRM_IOCTL_DEF_DRV(I915_GETPARAM, i915_getparam, DRM_AUTH|DRM_RENDER_ALLOW),
  1050. DRM_IOCTL_DEF_DRV(I915_SETPARAM, i915_setparam, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  1051. DRM_IOCTL_DEF_DRV(I915_ALLOC, drm_noop, DRM_AUTH),
  1052. DRM_IOCTL_DEF_DRV(I915_FREE, drm_noop, DRM_AUTH),
  1053. DRM_IOCTL_DEF_DRV(I915_INIT_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  1054. DRM_IOCTL_DEF_DRV(I915_CMDBUFFER, drm_noop, DRM_AUTH),
  1055. DRM_IOCTL_DEF_DRV(I915_DESTROY_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  1056. DRM_IOCTL_DEF_DRV(I915_SET_VBLANK_PIPE, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  1057. DRM_IOCTL_DEF_DRV(I915_GET_VBLANK_PIPE, drm_noop, DRM_AUTH),
  1058. DRM_IOCTL_DEF_DRV(I915_VBLANK_SWAP, drm_noop, DRM_AUTH),
  1059. DRM_IOCTL_DEF_DRV(I915_HWS_ADDR, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  1060. DRM_IOCTL_DEF_DRV(I915_GEM_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED),
  1061. DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER, i915_gem_execbuffer, DRM_AUTH|DRM_UNLOCKED),
  1062. DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER2, i915_gem_execbuffer2, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1063. DRM_IOCTL_DEF_DRV(I915_GEM_PIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY|DRM_UNLOCKED),
  1064. DRM_IOCTL_DEF_DRV(I915_GEM_UNPIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY|DRM_UNLOCKED),
  1065. DRM_IOCTL_DEF_DRV(I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1066. DRM_IOCTL_DEF_DRV(I915_GEM_SET_CACHING, i915_gem_set_caching_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1067. DRM_IOCTL_DEF_DRV(I915_GEM_GET_CACHING, i915_gem_get_caching_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1068. DRM_IOCTL_DEF_DRV(I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1069. DRM_IOCTL_DEF_DRV(I915_GEM_ENTERVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED),
  1070. DRM_IOCTL_DEF_DRV(I915_GEM_LEAVEVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED),
  1071. DRM_IOCTL_DEF_DRV(I915_GEM_CREATE, i915_gem_create_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1072. DRM_IOCTL_DEF_DRV(I915_GEM_PREAD, i915_gem_pread_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1073. DRM_IOCTL_DEF_DRV(I915_GEM_PWRITE, i915_gem_pwrite_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1074. DRM_IOCTL_DEF_DRV(I915_GEM_MMAP, i915_gem_mmap_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1075. DRM_IOCTL_DEF_DRV(I915_GEM_MMAP_GTT, i915_gem_mmap_gtt_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1076. DRM_IOCTL_DEF_DRV(I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1077. DRM_IOCTL_DEF_DRV(I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1078. DRM_IOCTL_DEF_DRV(I915_GEM_SET_TILING, i915_gem_set_tiling, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1079. DRM_IOCTL_DEF_DRV(I915_GEM_GET_TILING, i915_gem_get_tiling, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1080. DRM_IOCTL_DEF_DRV(I915_GEM_GET_APERTURE, i915_gem_get_aperture_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1081. DRM_IOCTL_DEF_DRV(I915_GET_PIPE_FROM_CRTC_ID, intel_get_pipe_from_crtc_id, DRM_UNLOCKED),
  1082. DRM_IOCTL_DEF_DRV(I915_GEM_MADVISE, i915_gem_madvise_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1083. DRM_IOCTL_DEF_DRV(I915_OVERLAY_PUT_IMAGE, intel_overlay_put_image, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
  1084. DRM_IOCTL_DEF_DRV(I915_OVERLAY_ATTRS, intel_overlay_attrs, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
  1085. DRM_IOCTL_DEF_DRV(I915_SET_SPRITE_COLORKEY, intel_sprite_set_colorkey, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
  1086. DRM_IOCTL_DEF_DRV(I915_GET_SPRITE_COLORKEY, drm_noop, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
  1087. DRM_IOCTL_DEF_DRV(I915_GEM_WAIT, i915_gem_wait_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1088. DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_CREATE, i915_gem_context_create_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1089. DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_DESTROY, i915_gem_context_destroy_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1090. DRM_IOCTL_DEF_DRV(I915_REG_READ, i915_reg_read_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1091. DRM_IOCTL_DEF_DRV(I915_GET_RESET_STATS, i915_get_reset_stats_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1092. DRM_IOCTL_DEF_DRV(I915_GEM_USERPTR, i915_gem_userptr_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1093. DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_GETPARAM, i915_gem_context_getparam_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1094. DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_SETPARAM, i915_gem_context_setparam_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  1095. };
  1096. int i915_max_ioctl = ARRAY_SIZE(i915_ioctls);