i915_dma.c 36 KB

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