i915_dma.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386
  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 "drmP.h"
  30. #include "drm.h"
  31. #include "drm_crtc_helper.h"
  32. #include "drm_fb_helper.h"
  33. #include "intel_drv.h"
  34. #include "i915_drm.h"
  35. #include "i915_drv.h"
  36. #include "i915_trace.h"
  37. #include "../../../platform/x86/intel_ips.h"
  38. #include <linux/pci.h>
  39. #include <linux/vgaarb.h>
  40. #include <linux/acpi.h>
  41. #include <linux/pnp.h>
  42. #include <linux/vga_switcheroo.h>
  43. #include <linux/slab.h>
  44. #include <linux/module.h>
  45. #include <acpi/video.h>
  46. #include <asm/pat.h>
  47. static void i915_write_hws_pga(struct drm_device *dev)
  48. {
  49. drm_i915_private_t *dev_priv = dev->dev_private;
  50. u32 addr;
  51. addr = dev_priv->status_page_dmah->busaddr;
  52. if (INTEL_INFO(dev)->gen >= 4)
  53. addr |= (dev_priv->status_page_dmah->busaddr >> 28) & 0xf0;
  54. I915_WRITE(HWS_PGA, addr);
  55. }
  56. /**
  57. * Sets up the hardware status page for devices that need a physical address
  58. * in the register.
  59. */
  60. static int i915_init_phys_hws(struct drm_device *dev)
  61. {
  62. drm_i915_private_t *dev_priv = dev->dev_private;
  63. /* Program Hardware Status Page */
  64. dev_priv->status_page_dmah =
  65. drm_pci_alloc(dev, PAGE_SIZE, PAGE_SIZE);
  66. if (!dev_priv->status_page_dmah) {
  67. DRM_ERROR("Can not allocate hardware status page\n");
  68. return -ENOMEM;
  69. }
  70. memset_io((void __force __iomem *)dev_priv->status_page_dmah->vaddr,
  71. 0, PAGE_SIZE);
  72. i915_write_hws_pga(dev);
  73. DRM_DEBUG_DRIVER("Enabled hardware status page\n");
  74. return 0;
  75. }
  76. /**
  77. * Frees the hardware status page, whether it's a physical address or a virtual
  78. * address set up by the X Server.
  79. */
  80. static void i915_free_hws(struct drm_device *dev)
  81. {
  82. drm_i915_private_t *dev_priv = dev->dev_private;
  83. struct intel_ring_buffer *ring = LP_RING(dev_priv);
  84. if (dev_priv->status_page_dmah) {
  85. drm_pci_free(dev, dev_priv->status_page_dmah);
  86. dev_priv->status_page_dmah = NULL;
  87. }
  88. if (ring->status_page.gfx_addr) {
  89. ring->status_page.gfx_addr = 0;
  90. drm_core_ioremapfree(&dev_priv->hws_map, dev);
  91. }
  92. /* Need to rewrite hardware status page */
  93. I915_WRITE(HWS_PGA, 0x1ffff000);
  94. }
  95. void i915_kernel_lost_context(struct drm_device * dev)
  96. {
  97. drm_i915_private_t *dev_priv = dev->dev_private;
  98. struct drm_i915_master_private *master_priv;
  99. struct intel_ring_buffer *ring = LP_RING(dev_priv);
  100. /*
  101. * We should never lose context on the ring with modesetting
  102. * as we don't expose it to userspace
  103. */
  104. if (drm_core_check_feature(dev, DRIVER_MODESET))
  105. return;
  106. ring->head = I915_READ_HEAD(ring) & HEAD_ADDR;
  107. ring->tail = I915_READ_TAIL(ring) & TAIL_ADDR;
  108. ring->space = ring->head - (ring->tail + 8);
  109. if (ring->space < 0)
  110. ring->space += ring->size;
  111. if (!dev->primary->master)
  112. return;
  113. master_priv = dev->primary->master->driver_priv;
  114. if (ring->head == ring->tail && master_priv->sarea_priv)
  115. master_priv->sarea_priv->perf_boxes |= I915_BOX_RING_EMPTY;
  116. }
  117. static int i915_dma_cleanup(struct drm_device * dev)
  118. {
  119. drm_i915_private_t *dev_priv = dev->dev_private;
  120. int i;
  121. /* Make sure interrupts are disabled here because the uninstall ioctl
  122. * may not have been called from userspace and after dev_private
  123. * is freed, it's too late.
  124. */
  125. if (dev->irq_enabled)
  126. drm_irq_uninstall(dev);
  127. mutex_lock(&dev->struct_mutex);
  128. for (i = 0; i < I915_NUM_RINGS; i++)
  129. intel_cleanup_ring_buffer(&dev_priv->ring[i]);
  130. mutex_unlock(&dev->struct_mutex);
  131. /* Clear the HWS virtual address at teardown */
  132. if (I915_NEED_GFX_HWS(dev))
  133. i915_free_hws(dev);
  134. return 0;
  135. }
  136. static int i915_initialize(struct drm_device * dev, drm_i915_init_t * init)
  137. {
  138. drm_i915_private_t *dev_priv = dev->dev_private;
  139. struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
  140. int ret;
  141. master_priv->sarea = drm_getsarea(dev);
  142. if (master_priv->sarea) {
  143. master_priv->sarea_priv = (drm_i915_sarea_t *)
  144. ((u8 *)master_priv->sarea->handle + init->sarea_priv_offset);
  145. } else {
  146. DRM_DEBUG_DRIVER("sarea not found assuming DRI2 userspace\n");
  147. }
  148. if (init->ring_size != 0) {
  149. if (LP_RING(dev_priv)->obj != NULL) {
  150. i915_dma_cleanup(dev);
  151. DRM_ERROR("Client tried to initialize ringbuffer in "
  152. "GEM mode\n");
  153. return -EINVAL;
  154. }
  155. ret = intel_render_ring_init_dri(dev,
  156. init->ring_start,
  157. init->ring_size);
  158. if (ret) {
  159. i915_dma_cleanup(dev);
  160. return ret;
  161. }
  162. }
  163. dev_priv->cpp = init->cpp;
  164. dev_priv->back_offset = init->back_offset;
  165. dev_priv->front_offset = init->front_offset;
  166. dev_priv->current_page = 0;
  167. if (master_priv->sarea_priv)
  168. master_priv->sarea_priv->pf_current_page = 0;
  169. /* Allow hardware batchbuffers unless told otherwise.
  170. */
  171. dev_priv->allow_batchbuffer = 1;
  172. return 0;
  173. }
  174. static int i915_dma_resume(struct drm_device * dev)
  175. {
  176. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  177. struct intel_ring_buffer *ring = LP_RING(dev_priv);
  178. DRM_DEBUG_DRIVER("%s\n", __func__);
  179. if (ring->map.handle == NULL) {
  180. DRM_ERROR("can not ioremap virtual address for"
  181. " ring buffer\n");
  182. return -ENOMEM;
  183. }
  184. /* Program Hardware Status Page */
  185. if (!ring->status_page.page_addr) {
  186. DRM_ERROR("Can not find hardware status page\n");
  187. return -EINVAL;
  188. }
  189. DRM_DEBUG_DRIVER("hw status page @ %p\n",
  190. ring->status_page.page_addr);
  191. if (ring->status_page.gfx_addr != 0)
  192. intel_ring_setup_status_page(ring);
  193. else
  194. i915_write_hws_pga(dev);
  195. DRM_DEBUG_DRIVER("Enabled hardware status page\n");
  196. return 0;
  197. }
  198. static int i915_dma_init(struct drm_device *dev, void *data,
  199. struct drm_file *file_priv)
  200. {
  201. drm_i915_init_t *init = data;
  202. int retcode = 0;
  203. switch (init->func) {
  204. case I915_INIT_DMA:
  205. retcode = i915_initialize(dev, init);
  206. break;
  207. case I915_CLEANUP_DMA:
  208. retcode = i915_dma_cleanup(dev);
  209. break;
  210. case I915_RESUME_DMA:
  211. retcode = i915_dma_resume(dev);
  212. break;
  213. default:
  214. retcode = -EINVAL;
  215. break;
  216. }
  217. return retcode;
  218. }
  219. /* Implement basically the same security restrictions as hardware does
  220. * for MI_BATCH_NON_SECURE. These can be made stricter at any time.
  221. *
  222. * Most of the calculations below involve calculating the size of a
  223. * particular instruction. It's important to get the size right as
  224. * that tells us where the next instruction to check is. Any illegal
  225. * instruction detected will be given a size of zero, which is a
  226. * signal to abort the rest of the buffer.
  227. */
  228. static int validate_cmd(int cmd)
  229. {
  230. switch (((cmd >> 29) & 0x7)) {
  231. case 0x0:
  232. switch ((cmd >> 23) & 0x3f) {
  233. case 0x0:
  234. return 1; /* MI_NOOP */
  235. case 0x4:
  236. return 1; /* MI_FLUSH */
  237. default:
  238. return 0; /* disallow everything else */
  239. }
  240. break;
  241. case 0x1:
  242. return 0; /* reserved */
  243. case 0x2:
  244. return (cmd & 0xff) + 2; /* 2d commands */
  245. case 0x3:
  246. if (((cmd >> 24) & 0x1f) <= 0x18)
  247. return 1;
  248. switch ((cmd >> 24) & 0x1f) {
  249. case 0x1c:
  250. return 1;
  251. case 0x1d:
  252. switch ((cmd >> 16) & 0xff) {
  253. case 0x3:
  254. return (cmd & 0x1f) + 2;
  255. case 0x4:
  256. return (cmd & 0xf) + 2;
  257. default:
  258. return (cmd & 0xffff) + 2;
  259. }
  260. case 0x1e:
  261. if (cmd & (1 << 23))
  262. return (cmd & 0xffff) + 1;
  263. else
  264. return 1;
  265. case 0x1f:
  266. if ((cmd & (1 << 23)) == 0) /* inline vertices */
  267. return (cmd & 0x1ffff) + 2;
  268. else if (cmd & (1 << 17)) /* indirect random */
  269. if ((cmd & 0xffff) == 0)
  270. return 0; /* unknown length, too hard */
  271. else
  272. return (((cmd & 0xffff) + 1) / 2) + 1;
  273. else
  274. return 2; /* indirect sequential */
  275. default:
  276. return 0;
  277. }
  278. default:
  279. return 0;
  280. }
  281. return 0;
  282. }
  283. static int i915_emit_cmds(struct drm_device * dev, int *buffer, int dwords)
  284. {
  285. drm_i915_private_t *dev_priv = dev->dev_private;
  286. int i, ret;
  287. if ((dwords+1) * sizeof(int) >= LP_RING(dev_priv)->size - 8)
  288. return -EINVAL;
  289. for (i = 0; i < dwords;) {
  290. int sz = validate_cmd(buffer[i]);
  291. if (sz == 0 || i + sz > dwords)
  292. return -EINVAL;
  293. i += sz;
  294. }
  295. ret = BEGIN_LP_RING((dwords+1)&~1);
  296. if (ret)
  297. return ret;
  298. for (i = 0; i < dwords; i++)
  299. OUT_RING(buffer[i]);
  300. if (dwords & 1)
  301. OUT_RING(0);
  302. ADVANCE_LP_RING();
  303. return 0;
  304. }
  305. int
  306. i915_emit_box(struct drm_device *dev,
  307. struct drm_clip_rect *box,
  308. int DR1, int DR4)
  309. {
  310. struct drm_i915_private *dev_priv = dev->dev_private;
  311. int ret;
  312. if (box->y2 <= box->y1 || box->x2 <= box->x1 ||
  313. box->y2 <= 0 || box->x2 <= 0) {
  314. DRM_ERROR("Bad box %d,%d..%d,%d\n",
  315. box->x1, box->y1, box->x2, box->y2);
  316. return -EINVAL;
  317. }
  318. if (INTEL_INFO(dev)->gen >= 4) {
  319. ret = BEGIN_LP_RING(4);
  320. if (ret)
  321. return ret;
  322. OUT_RING(GFX_OP_DRAWRECT_INFO_I965);
  323. OUT_RING((box->x1 & 0xffff) | (box->y1 << 16));
  324. OUT_RING(((box->x2 - 1) & 0xffff) | ((box->y2 - 1) << 16));
  325. OUT_RING(DR4);
  326. } else {
  327. ret = BEGIN_LP_RING(6);
  328. if (ret)
  329. return ret;
  330. OUT_RING(GFX_OP_DRAWRECT_INFO);
  331. OUT_RING(DR1);
  332. OUT_RING((box->x1 & 0xffff) | (box->y1 << 16));
  333. OUT_RING(((box->x2 - 1) & 0xffff) | ((box->y2 - 1) << 16));
  334. OUT_RING(DR4);
  335. OUT_RING(0);
  336. }
  337. ADVANCE_LP_RING();
  338. return 0;
  339. }
  340. /* XXX: Emitting the counter should really be moved to part of the IRQ
  341. * emit. For now, do it in both places:
  342. */
  343. static void i915_emit_breadcrumb(struct drm_device *dev)
  344. {
  345. drm_i915_private_t *dev_priv = dev->dev_private;
  346. struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
  347. dev_priv->counter++;
  348. if (dev_priv->counter > 0x7FFFFFFFUL)
  349. dev_priv->counter = 0;
  350. if (master_priv->sarea_priv)
  351. master_priv->sarea_priv->last_enqueue = dev_priv->counter;
  352. if (BEGIN_LP_RING(4) == 0) {
  353. OUT_RING(MI_STORE_DWORD_INDEX);
  354. OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT);
  355. OUT_RING(dev_priv->counter);
  356. OUT_RING(0);
  357. ADVANCE_LP_RING();
  358. }
  359. }
  360. static int i915_dispatch_cmdbuffer(struct drm_device * dev,
  361. drm_i915_cmdbuffer_t *cmd,
  362. struct drm_clip_rect *cliprects,
  363. void *cmdbuf)
  364. {
  365. int nbox = cmd->num_cliprects;
  366. int i = 0, count, ret;
  367. if (cmd->sz & 0x3) {
  368. DRM_ERROR("alignment");
  369. return -EINVAL;
  370. }
  371. i915_kernel_lost_context(dev);
  372. count = nbox ? nbox : 1;
  373. for (i = 0; i < count; i++) {
  374. if (i < nbox) {
  375. ret = i915_emit_box(dev, &cliprects[i],
  376. cmd->DR1, cmd->DR4);
  377. if (ret)
  378. return ret;
  379. }
  380. ret = i915_emit_cmds(dev, cmdbuf, cmd->sz / 4);
  381. if (ret)
  382. return ret;
  383. }
  384. i915_emit_breadcrumb(dev);
  385. return 0;
  386. }
  387. static int i915_dispatch_batchbuffer(struct drm_device * dev,
  388. drm_i915_batchbuffer_t * batch,
  389. struct drm_clip_rect *cliprects)
  390. {
  391. struct drm_i915_private *dev_priv = dev->dev_private;
  392. int nbox = batch->num_cliprects;
  393. int i, count, ret;
  394. if ((batch->start | batch->used) & 0x7) {
  395. DRM_ERROR("alignment");
  396. return -EINVAL;
  397. }
  398. i915_kernel_lost_context(dev);
  399. count = nbox ? nbox : 1;
  400. for (i = 0; i < count; i++) {
  401. if (i < nbox) {
  402. ret = i915_emit_box(dev, &cliprects[i],
  403. batch->DR1, batch->DR4);
  404. if (ret)
  405. return ret;
  406. }
  407. if (!IS_I830(dev) && !IS_845G(dev)) {
  408. ret = BEGIN_LP_RING(2);
  409. if (ret)
  410. return ret;
  411. if (INTEL_INFO(dev)->gen >= 4) {
  412. OUT_RING(MI_BATCH_BUFFER_START | (2 << 6) | MI_BATCH_NON_SECURE_I965);
  413. OUT_RING(batch->start);
  414. } else {
  415. OUT_RING(MI_BATCH_BUFFER_START | (2 << 6));
  416. OUT_RING(batch->start | MI_BATCH_NON_SECURE);
  417. }
  418. } else {
  419. ret = BEGIN_LP_RING(4);
  420. if (ret)
  421. return ret;
  422. OUT_RING(MI_BATCH_BUFFER);
  423. OUT_RING(batch->start | MI_BATCH_NON_SECURE);
  424. OUT_RING(batch->start + batch->used - 4);
  425. OUT_RING(0);
  426. }
  427. ADVANCE_LP_RING();
  428. }
  429. if (IS_G4X(dev) || IS_GEN5(dev)) {
  430. if (BEGIN_LP_RING(2) == 0) {
  431. OUT_RING(MI_FLUSH | MI_NO_WRITE_FLUSH | MI_INVALIDATE_ISP);
  432. OUT_RING(MI_NOOP);
  433. ADVANCE_LP_RING();
  434. }
  435. }
  436. i915_emit_breadcrumb(dev);
  437. return 0;
  438. }
  439. static int i915_dispatch_flip(struct drm_device * dev)
  440. {
  441. drm_i915_private_t *dev_priv = dev->dev_private;
  442. struct drm_i915_master_private *master_priv =
  443. dev->primary->master->driver_priv;
  444. int ret;
  445. if (!master_priv->sarea_priv)
  446. return -EINVAL;
  447. DRM_DEBUG_DRIVER("%s: page=%d pfCurrentPage=%d\n",
  448. __func__,
  449. dev_priv->current_page,
  450. master_priv->sarea_priv->pf_current_page);
  451. i915_kernel_lost_context(dev);
  452. ret = BEGIN_LP_RING(10);
  453. if (ret)
  454. return ret;
  455. OUT_RING(MI_FLUSH | MI_READ_FLUSH);
  456. OUT_RING(0);
  457. OUT_RING(CMD_OP_DISPLAYBUFFER_INFO | ASYNC_FLIP);
  458. OUT_RING(0);
  459. if (dev_priv->current_page == 0) {
  460. OUT_RING(dev_priv->back_offset);
  461. dev_priv->current_page = 1;
  462. } else {
  463. OUT_RING(dev_priv->front_offset);
  464. dev_priv->current_page = 0;
  465. }
  466. OUT_RING(0);
  467. OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_PLANE_A_FLIP);
  468. OUT_RING(0);
  469. ADVANCE_LP_RING();
  470. master_priv->sarea_priv->last_enqueue = dev_priv->counter++;
  471. if (BEGIN_LP_RING(4) == 0) {
  472. OUT_RING(MI_STORE_DWORD_INDEX);
  473. OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT);
  474. OUT_RING(dev_priv->counter);
  475. OUT_RING(0);
  476. ADVANCE_LP_RING();
  477. }
  478. master_priv->sarea_priv->pf_current_page = dev_priv->current_page;
  479. return 0;
  480. }
  481. static int i915_quiescent(struct drm_device *dev)
  482. {
  483. struct intel_ring_buffer *ring = LP_RING(dev->dev_private);
  484. i915_kernel_lost_context(dev);
  485. return intel_wait_ring_idle(ring);
  486. }
  487. static int i915_flush_ioctl(struct drm_device *dev, void *data,
  488. struct drm_file *file_priv)
  489. {
  490. int ret;
  491. RING_LOCK_TEST_WITH_RETURN(dev, file_priv);
  492. mutex_lock(&dev->struct_mutex);
  493. ret = i915_quiescent(dev);
  494. mutex_unlock(&dev->struct_mutex);
  495. return ret;
  496. }
  497. static int i915_batchbuffer(struct drm_device *dev, void *data,
  498. struct drm_file *file_priv)
  499. {
  500. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  501. struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
  502. drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *)
  503. master_priv->sarea_priv;
  504. drm_i915_batchbuffer_t *batch = data;
  505. int ret;
  506. struct drm_clip_rect *cliprects = NULL;
  507. if (!dev_priv->allow_batchbuffer) {
  508. DRM_ERROR("Batchbuffer ioctl disabled\n");
  509. return -EINVAL;
  510. }
  511. DRM_DEBUG_DRIVER("i915 batchbuffer, start %x used %d cliprects %d\n",
  512. batch->start, batch->used, batch->num_cliprects);
  513. RING_LOCK_TEST_WITH_RETURN(dev, file_priv);
  514. if (batch->num_cliprects < 0)
  515. return -EINVAL;
  516. if (batch->num_cliprects) {
  517. cliprects = kcalloc(batch->num_cliprects,
  518. sizeof(struct drm_clip_rect),
  519. GFP_KERNEL);
  520. if (cliprects == NULL)
  521. return -ENOMEM;
  522. ret = copy_from_user(cliprects, batch->cliprects,
  523. batch->num_cliprects *
  524. sizeof(struct drm_clip_rect));
  525. if (ret != 0) {
  526. ret = -EFAULT;
  527. goto fail_free;
  528. }
  529. }
  530. mutex_lock(&dev->struct_mutex);
  531. ret = i915_dispatch_batchbuffer(dev, batch, cliprects);
  532. mutex_unlock(&dev->struct_mutex);
  533. if (sarea_priv)
  534. sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
  535. fail_free:
  536. kfree(cliprects);
  537. return ret;
  538. }
  539. static int i915_cmdbuffer(struct drm_device *dev, void *data,
  540. struct drm_file *file_priv)
  541. {
  542. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  543. struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
  544. drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *)
  545. master_priv->sarea_priv;
  546. drm_i915_cmdbuffer_t *cmdbuf = data;
  547. struct drm_clip_rect *cliprects = NULL;
  548. void *batch_data;
  549. int ret;
  550. DRM_DEBUG_DRIVER("i915 cmdbuffer, buf %p sz %d cliprects %d\n",
  551. cmdbuf->buf, cmdbuf->sz, cmdbuf->num_cliprects);
  552. RING_LOCK_TEST_WITH_RETURN(dev, file_priv);
  553. if (cmdbuf->num_cliprects < 0)
  554. return -EINVAL;
  555. batch_data = kmalloc(cmdbuf->sz, GFP_KERNEL);
  556. if (batch_data == NULL)
  557. return -ENOMEM;
  558. ret = copy_from_user(batch_data, cmdbuf->buf, cmdbuf->sz);
  559. if (ret != 0) {
  560. ret = -EFAULT;
  561. goto fail_batch_free;
  562. }
  563. if (cmdbuf->num_cliprects) {
  564. cliprects = kcalloc(cmdbuf->num_cliprects,
  565. sizeof(struct drm_clip_rect), GFP_KERNEL);
  566. if (cliprects == NULL) {
  567. ret = -ENOMEM;
  568. goto fail_batch_free;
  569. }
  570. ret = copy_from_user(cliprects, cmdbuf->cliprects,
  571. cmdbuf->num_cliprects *
  572. sizeof(struct drm_clip_rect));
  573. if (ret != 0) {
  574. ret = -EFAULT;
  575. goto fail_clip_free;
  576. }
  577. }
  578. mutex_lock(&dev->struct_mutex);
  579. ret = i915_dispatch_cmdbuffer(dev, cmdbuf, cliprects, batch_data);
  580. mutex_unlock(&dev->struct_mutex);
  581. if (ret) {
  582. DRM_ERROR("i915_dispatch_cmdbuffer failed\n");
  583. goto fail_clip_free;
  584. }
  585. if (sarea_priv)
  586. sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
  587. fail_clip_free:
  588. kfree(cliprects);
  589. fail_batch_free:
  590. kfree(batch_data);
  591. return ret;
  592. }
  593. static int i915_flip_bufs(struct drm_device *dev, void *data,
  594. struct drm_file *file_priv)
  595. {
  596. int ret;
  597. DRM_DEBUG_DRIVER("%s\n", __func__);
  598. RING_LOCK_TEST_WITH_RETURN(dev, file_priv);
  599. mutex_lock(&dev->struct_mutex);
  600. ret = i915_dispatch_flip(dev);
  601. mutex_unlock(&dev->struct_mutex);
  602. return ret;
  603. }
  604. static int i915_getparam(struct drm_device *dev, void *data,
  605. struct drm_file *file_priv)
  606. {
  607. drm_i915_private_t *dev_priv = dev->dev_private;
  608. drm_i915_getparam_t *param = data;
  609. int value;
  610. if (!dev_priv) {
  611. DRM_ERROR("called with no initialization\n");
  612. return -EINVAL;
  613. }
  614. switch (param->param) {
  615. case I915_PARAM_IRQ_ACTIVE:
  616. value = dev->pdev->irq ? 1 : 0;
  617. break;
  618. case I915_PARAM_ALLOW_BATCHBUFFER:
  619. value = dev_priv->allow_batchbuffer ? 1 : 0;
  620. break;
  621. case I915_PARAM_LAST_DISPATCH:
  622. value = READ_BREADCRUMB(dev_priv);
  623. break;
  624. case I915_PARAM_CHIPSET_ID:
  625. value = dev->pci_device;
  626. break;
  627. case I915_PARAM_HAS_GEM:
  628. value = dev_priv->has_gem;
  629. break;
  630. case I915_PARAM_NUM_FENCES_AVAIL:
  631. value = dev_priv->num_fence_regs - dev_priv->fence_reg_start;
  632. break;
  633. case I915_PARAM_HAS_OVERLAY:
  634. value = dev_priv->overlay ? 1 : 0;
  635. break;
  636. case I915_PARAM_HAS_PAGEFLIPPING:
  637. value = 1;
  638. break;
  639. case I915_PARAM_HAS_EXECBUF2:
  640. /* depends on GEM */
  641. value = dev_priv->has_gem;
  642. break;
  643. case I915_PARAM_HAS_BSD:
  644. value = HAS_BSD(dev);
  645. break;
  646. case I915_PARAM_HAS_BLT:
  647. value = HAS_BLT(dev);
  648. break;
  649. case I915_PARAM_HAS_RELAXED_FENCING:
  650. value = 1;
  651. break;
  652. case I915_PARAM_HAS_COHERENT_RINGS:
  653. value = 1;
  654. break;
  655. case I915_PARAM_HAS_EXEC_CONSTANTS:
  656. value = INTEL_INFO(dev)->gen >= 4;
  657. break;
  658. case I915_PARAM_HAS_RELAXED_DELTA:
  659. value = 1;
  660. break;
  661. case I915_PARAM_HAS_GEN7_SOL_RESET:
  662. value = 1;
  663. break;
  664. case I915_PARAM_HAS_LLC:
  665. value = HAS_LLC(dev);
  666. break;
  667. case I915_PARAM_HAS_ALIASING_PPGTT:
  668. value = dev_priv->mm.aliasing_ppgtt ? 1 : 0;
  669. break;
  670. default:
  671. DRM_DEBUG_DRIVER("Unknown parameter %d\n",
  672. param->param);
  673. return -EINVAL;
  674. }
  675. if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) {
  676. DRM_ERROR("DRM_COPY_TO_USER failed\n");
  677. return -EFAULT;
  678. }
  679. return 0;
  680. }
  681. static int i915_setparam(struct drm_device *dev, void *data,
  682. struct drm_file *file_priv)
  683. {
  684. drm_i915_private_t *dev_priv = dev->dev_private;
  685. drm_i915_setparam_t *param = data;
  686. if (!dev_priv) {
  687. DRM_ERROR("called with no initialization\n");
  688. return -EINVAL;
  689. }
  690. switch (param->param) {
  691. case I915_SETPARAM_USE_MI_BATCHBUFFER_START:
  692. break;
  693. case I915_SETPARAM_TEX_LRU_LOG_GRANULARITY:
  694. dev_priv->tex_lru_log_granularity = param->value;
  695. break;
  696. case I915_SETPARAM_ALLOW_BATCHBUFFER:
  697. dev_priv->allow_batchbuffer = param->value;
  698. break;
  699. case I915_SETPARAM_NUM_USED_FENCES:
  700. if (param->value > dev_priv->num_fence_regs ||
  701. param->value < 0)
  702. return -EINVAL;
  703. /* Userspace can use first N regs */
  704. dev_priv->fence_reg_start = param->value;
  705. break;
  706. default:
  707. DRM_DEBUG_DRIVER("unknown parameter %d\n",
  708. param->param);
  709. return -EINVAL;
  710. }
  711. return 0;
  712. }
  713. static int i915_set_status_page(struct drm_device *dev, void *data,
  714. struct drm_file *file_priv)
  715. {
  716. drm_i915_private_t *dev_priv = dev->dev_private;
  717. drm_i915_hws_addr_t *hws = data;
  718. struct intel_ring_buffer *ring = LP_RING(dev_priv);
  719. if (!I915_NEED_GFX_HWS(dev))
  720. return -EINVAL;
  721. if (!dev_priv) {
  722. DRM_ERROR("called with no initialization\n");
  723. return -EINVAL;
  724. }
  725. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  726. WARN(1, "tried to set status page when mode setting active\n");
  727. return 0;
  728. }
  729. DRM_DEBUG_DRIVER("set status page addr 0x%08x\n", (u32)hws->addr);
  730. ring->status_page.gfx_addr = hws->addr & (0x1ffff<<12);
  731. dev_priv->hws_map.offset = dev->agp->base + hws->addr;
  732. dev_priv->hws_map.size = 4*1024;
  733. dev_priv->hws_map.type = 0;
  734. dev_priv->hws_map.flags = 0;
  735. dev_priv->hws_map.mtrr = 0;
  736. drm_core_ioremap_wc(&dev_priv->hws_map, dev);
  737. if (dev_priv->hws_map.handle == NULL) {
  738. i915_dma_cleanup(dev);
  739. ring->status_page.gfx_addr = 0;
  740. DRM_ERROR("can not ioremap virtual address for"
  741. " G33 hw status page\n");
  742. return -ENOMEM;
  743. }
  744. ring->status_page.page_addr =
  745. (void __force __iomem *)dev_priv->hws_map.handle;
  746. memset_io(ring->status_page.page_addr, 0, PAGE_SIZE);
  747. I915_WRITE(HWS_PGA, ring->status_page.gfx_addr);
  748. DRM_DEBUG_DRIVER("load hws HWS_PGA with gfx mem 0x%x\n",
  749. ring->status_page.gfx_addr);
  750. DRM_DEBUG_DRIVER("load hws at %p\n",
  751. ring->status_page.page_addr);
  752. return 0;
  753. }
  754. static int i915_get_bridge_dev(struct drm_device *dev)
  755. {
  756. struct drm_i915_private *dev_priv = dev->dev_private;
  757. dev_priv->bridge_dev = pci_get_bus_and_slot(0, PCI_DEVFN(0, 0));
  758. if (!dev_priv->bridge_dev) {
  759. DRM_ERROR("bridge device not found\n");
  760. return -1;
  761. }
  762. return 0;
  763. }
  764. #define MCHBAR_I915 0x44
  765. #define MCHBAR_I965 0x48
  766. #define MCHBAR_SIZE (4*4096)
  767. #define DEVEN_REG 0x54
  768. #define DEVEN_MCHBAR_EN (1 << 28)
  769. /* Allocate space for the MCH regs if needed, return nonzero on error */
  770. static int
  771. intel_alloc_mchbar_resource(struct drm_device *dev)
  772. {
  773. drm_i915_private_t *dev_priv = dev->dev_private;
  774. int reg = INTEL_INFO(dev)->gen >= 4 ? MCHBAR_I965 : MCHBAR_I915;
  775. u32 temp_lo, temp_hi = 0;
  776. u64 mchbar_addr;
  777. int ret;
  778. if (INTEL_INFO(dev)->gen >= 4)
  779. pci_read_config_dword(dev_priv->bridge_dev, reg + 4, &temp_hi);
  780. pci_read_config_dword(dev_priv->bridge_dev, reg, &temp_lo);
  781. mchbar_addr = ((u64)temp_hi << 32) | temp_lo;
  782. /* If ACPI doesn't have it, assume we need to allocate it ourselves */
  783. #ifdef CONFIG_PNP
  784. if (mchbar_addr &&
  785. pnp_range_reserved(mchbar_addr, mchbar_addr + MCHBAR_SIZE))
  786. return 0;
  787. #endif
  788. /* Get some space for it */
  789. dev_priv->mch_res.name = "i915 MCHBAR";
  790. dev_priv->mch_res.flags = IORESOURCE_MEM;
  791. ret = pci_bus_alloc_resource(dev_priv->bridge_dev->bus,
  792. &dev_priv->mch_res,
  793. MCHBAR_SIZE, MCHBAR_SIZE,
  794. PCIBIOS_MIN_MEM,
  795. 0, pcibios_align_resource,
  796. dev_priv->bridge_dev);
  797. if (ret) {
  798. DRM_DEBUG_DRIVER("failed bus alloc: %d\n", ret);
  799. dev_priv->mch_res.start = 0;
  800. return ret;
  801. }
  802. if (INTEL_INFO(dev)->gen >= 4)
  803. pci_write_config_dword(dev_priv->bridge_dev, reg + 4,
  804. upper_32_bits(dev_priv->mch_res.start));
  805. pci_write_config_dword(dev_priv->bridge_dev, reg,
  806. lower_32_bits(dev_priv->mch_res.start));
  807. return 0;
  808. }
  809. /* Setup MCHBAR if possible, return true if we should disable it again */
  810. static void
  811. intel_setup_mchbar(struct drm_device *dev)
  812. {
  813. drm_i915_private_t *dev_priv = dev->dev_private;
  814. int mchbar_reg = INTEL_INFO(dev)->gen >= 4 ? MCHBAR_I965 : MCHBAR_I915;
  815. u32 temp;
  816. bool enabled;
  817. dev_priv->mchbar_need_disable = false;
  818. if (IS_I915G(dev) || IS_I915GM(dev)) {
  819. pci_read_config_dword(dev_priv->bridge_dev, DEVEN_REG, &temp);
  820. enabled = !!(temp & DEVEN_MCHBAR_EN);
  821. } else {
  822. pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp);
  823. enabled = temp & 1;
  824. }
  825. /* If it's already enabled, don't have to do anything */
  826. if (enabled)
  827. return;
  828. if (intel_alloc_mchbar_resource(dev))
  829. return;
  830. dev_priv->mchbar_need_disable = true;
  831. /* Space is allocated or reserved, so enable it. */
  832. if (IS_I915G(dev) || IS_I915GM(dev)) {
  833. pci_write_config_dword(dev_priv->bridge_dev, DEVEN_REG,
  834. temp | DEVEN_MCHBAR_EN);
  835. } else {
  836. pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp);
  837. pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp | 1);
  838. }
  839. }
  840. static void
  841. intel_teardown_mchbar(struct drm_device *dev)
  842. {
  843. drm_i915_private_t *dev_priv = dev->dev_private;
  844. int mchbar_reg = INTEL_INFO(dev)->gen >= 4 ? MCHBAR_I965 : MCHBAR_I915;
  845. u32 temp;
  846. if (dev_priv->mchbar_need_disable) {
  847. if (IS_I915G(dev) || IS_I915GM(dev)) {
  848. pci_read_config_dword(dev_priv->bridge_dev, DEVEN_REG, &temp);
  849. temp &= ~DEVEN_MCHBAR_EN;
  850. pci_write_config_dword(dev_priv->bridge_dev, DEVEN_REG, temp);
  851. } else {
  852. pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp);
  853. temp &= ~1;
  854. pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp);
  855. }
  856. }
  857. if (dev_priv->mch_res.start)
  858. release_resource(&dev_priv->mch_res);
  859. }
  860. #define PTE_ADDRESS_MASK 0xfffff000
  861. #define PTE_ADDRESS_MASK_HIGH 0x000000f0 /* i915+ */
  862. #define PTE_MAPPING_TYPE_UNCACHED (0 << 1)
  863. #define PTE_MAPPING_TYPE_DCACHE (1 << 1) /* i830 only */
  864. #define PTE_MAPPING_TYPE_CACHED (3 << 1)
  865. #define PTE_MAPPING_TYPE_MASK (3 << 1)
  866. #define PTE_VALID (1 << 0)
  867. /**
  868. * i915_stolen_to_phys - take an offset into stolen memory and turn it into
  869. * a physical one
  870. * @dev: drm device
  871. * @offset: address to translate
  872. *
  873. * Some chip functions require allocations from stolen space and need the
  874. * physical address of the memory in question.
  875. */
  876. static unsigned long i915_stolen_to_phys(struct drm_device *dev, u32 offset)
  877. {
  878. struct drm_i915_private *dev_priv = dev->dev_private;
  879. struct pci_dev *pdev = dev_priv->bridge_dev;
  880. u32 base;
  881. #if 0
  882. /* On the machines I have tested the Graphics Base of Stolen Memory
  883. * is unreliable, so compute the base by subtracting the stolen memory
  884. * from the Top of Low Usable DRAM which is where the BIOS places
  885. * the graphics stolen memory.
  886. */
  887. if (INTEL_INFO(dev)->gen > 3 || IS_G33(dev)) {
  888. /* top 32bits are reserved = 0 */
  889. pci_read_config_dword(pdev, 0xA4, &base);
  890. } else {
  891. /* XXX presume 8xx is the same as i915 */
  892. pci_bus_read_config_dword(pdev->bus, 2, 0x5C, &base);
  893. }
  894. #else
  895. if (INTEL_INFO(dev)->gen > 3 || IS_G33(dev)) {
  896. u16 val;
  897. pci_read_config_word(pdev, 0xb0, &val);
  898. base = val >> 4 << 20;
  899. } else {
  900. u8 val;
  901. pci_read_config_byte(pdev, 0x9c, &val);
  902. base = val >> 3 << 27;
  903. }
  904. base -= dev_priv->mm.gtt->stolen_size;
  905. #endif
  906. return base + offset;
  907. }
  908. static void i915_warn_stolen(struct drm_device *dev)
  909. {
  910. DRM_ERROR("not enough stolen space for compressed buffer, disabling\n");
  911. DRM_ERROR("hint: you may be able to increase stolen memory size in the BIOS to avoid this\n");
  912. }
  913. static void i915_setup_compression(struct drm_device *dev, int size)
  914. {
  915. struct drm_i915_private *dev_priv = dev->dev_private;
  916. struct drm_mm_node *compressed_fb, *uninitialized_var(compressed_llb);
  917. unsigned long cfb_base;
  918. unsigned long ll_base = 0;
  919. /* Just in case the BIOS is doing something questionable. */
  920. intel_disable_fbc(dev);
  921. compressed_fb = drm_mm_search_free(&dev_priv->mm.stolen, size, 4096, 0);
  922. if (compressed_fb)
  923. compressed_fb = drm_mm_get_block(compressed_fb, size, 4096);
  924. if (!compressed_fb)
  925. goto err;
  926. cfb_base = i915_stolen_to_phys(dev, compressed_fb->start);
  927. if (!cfb_base)
  928. goto err_fb;
  929. if (!(IS_GM45(dev) || HAS_PCH_SPLIT(dev))) {
  930. compressed_llb = drm_mm_search_free(&dev_priv->mm.stolen,
  931. 4096, 4096, 0);
  932. if (compressed_llb)
  933. compressed_llb = drm_mm_get_block(compressed_llb,
  934. 4096, 4096);
  935. if (!compressed_llb)
  936. goto err_fb;
  937. ll_base = i915_stolen_to_phys(dev, compressed_llb->start);
  938. if (!ll_base)
  939. goto err_llb;
  940. }
  941. dev_priv->cfb_size = size;
  942. dev_priv->compressed_fb = compressed_fb;
  943. if (HAS_PCH_SPLIT(dev))
  944. I915_WRITE(ILK_DPFC_CB_BASE, compressed_fb->start);
  945. else if (IS_GM45(dev)) {
  946. I915_WRITE(DPFC_CB_BASE, compressed_fb->start);
  947. } else {
  948. I915_WRITE(FBC_CFB_BASE, cfb_base);
  949. I915_WRITE(FBC_LL_BASE, ll_base);
  950. dev_priv->compressed_llb = compressed_llb;
  951. }
  952. DRM_DEBUG_KMS("FBC base 0x%08lx, ll base 0x%08lx, size %dM\n",
  953. cfb_base, ll_base, size >> 20);
  954. return;
  955. err_llb:
  956. drm_mm_put_block(compressed_llb);
  957. err_fb:
  958. drm_mm_put_block(compressed_fb);
  959. err:
  960. dev_priv->no_fbc_reason = FBC_STOLEN_TOO_SMALL;
  961. i915_warn_stolen(dev);
  962. }
  963. static void i915_cleanup_compression(struct drm_device *dev)
  964. {
  965. struct drm_i915_private *dev_priv = dev->dev_private;
  966. drm_mm_put_block(dev_priv->compressed_fb);
  967. if (dev_priv->compressed_llb)
  968. drm_mm_put_block(dev_priv->compressed_llb);
  969. }
  970. /* true = enable decode, false = disable decoder */
  971. static unsigned int i915_vga_set_decode(void *cookie, bool state)
  972. {
  973. struct drm_device *dev = cookie;
  974. intel_modeset_vga_set_state(dev, state);
  975. if (state)
  976. return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
  977. VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
  978. else
  979. return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
  980. }
  981. static void i915_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state)
  982. {
  983. struct drm_device *dev = pci_get_drvdata(pdev);
  984. pm_message_t pmm = { .event = PM_EVENT_SUSPEND };
  985. if (state == VGA_SWITCHEROO_ON) {
  986. pr_info("switched on\n");
  987. dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  988. /* i915 resume handler doesn't set to D0 */
  989. pci_set_power_state(dev->pdev, PCI_D0);
  990. i915_resume(dev);
  991. dev->switch_power_state = DRM_SWITCH_POWER_ON;
  992. } else {
  993. pr_err("switched off\n");
  994. dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  995. i915_suspend(dev, pmm);
  996. dev->switch_power_state = DRM_SWITCH_POWER_OFF;
  997. }
  998. }
  999. static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
  1000. {
  1001. struct drm_device *dev = pci_get_drvdata(pdev);
  1002. bool can_switch;
  1003. spin_lock(&dev->count_lock);
  1004. can_switch = (dev->open_count == 0);
  1005. spin_unlock(&dev->count_lock);
  1006. return can_switch;
  1007. }
  1008. static bool
  1009. intel_enable_ppgtt(struct drm_device *dev)
  1010. {
  1011. if (i915_enable_ppgtt >= 0)
  1012. return i915_enable_ppgtt;
  1013. #ifdef CONFIG_INTEL_IOMMU
  1014. /* Disable ppgtt on SNB if VT-d is on. */
  1015. if (INTEL_INFO(dev)->gen == 6 && intel_iommu_gfx_mapped)
  1016. return false;
  1017. #endif
  1018. return true;
  1019. }
  1020. static int i915_load_gem_init(struct drm_device *dev)
  1021. {
  1022. struct drm_i915_private *dev_priv = dev->dev_private;
  1023. unsigned long prealloc_size, gtt_size, mappable_size;
  1024. int ret;
  1025. prealloc_size = dev_priv->mm.gtt->stolen_size;
  1026. gtt_size = dev_priv->mm.gtt->gtt_total_entries << PAGE_SHIFT;
  1027. mappable_size = dev_priv->mm.gtt->gtt_mappable_entries << PAGE_SHIFT;
  1028. /* Basic memrange allocator for stolen space */
  1029. drm_mm_init(&dev_priv->mm.stolen, 0, prealloc_size);
  1030. mutex_lock(&dev->struct_mutex);
  1031. if (intel_enable_ppgtt(dev) && HAS_ALIASING_PPGTT(dev)) {
  1032. /* PPGTT pdes are stolen from global gtt ptes, so shrink the
  1033. * aperture accordingly when using aliasing ppgtt. */
  1034. gtt_size -= I915_PPGTT_PD_ENTRIES*PAGE_SIZE;
  1035. i915_gem_init_global_gtt(dev, 0, mappable_size, gtt_size);
  1036. ret = i915_gem_init_aliasing_ppgtt(dev);
  1037. if (ret) {
  1038. mutex_unlock(&dev->struct_mutex);
  1039. return ret;
  1040. }
  1041. } else {
  1042. /* Let GEM Manage all of the aperture.
  1043. *
  1044. * However, leave one page at the end still bound to the scratch
  1045. * page. There are a number of places where the hardware
  1046. * apparently prefetches past the end of the object, and we've
  1047. * seen multiple hangs with the GPU head pointer stuck in a
  1048. * batchbuffer bound at the last page of the aperture. One page
  1049. * should be enough to keep any prefetching inside of the
  1050. * aperture.
  1051. */
  1052. i915_gem_init_global_gtt(dev, 0, mappable_size,
  1053. gtt_size);
  1054. }
  1055. ret = i915_gem_init_hw(dev);
  1056. mutex_unlock(&dev->struct_mutex);
  1057. if (ret) {
  1058. i915_gem_cleanup_aliasing_ppgtt(dev);
  1059. return ret;
  1060. }
  1061. /* Try to set up FBC with a reasonable compressed buffer size */
  1062. if (I915_HAS_FBC(dev) && i915_powersave) {
  1063. int cfb_size;
  1064. /* Leave 1M for line length buffer & misc. */
  1065. /* Try to get a 32M buffer... */
  1066. if (prealloc_size > (36*1024*1024))
  1067. cfb_size = 32*1024*1024;
  1068. else /* fall back to 7/8 of the stolen space */
  1069. cfb_size = prealloc_size * 7 / 8;
  1070. i915_setup_compression(dev, cfb_size);
  1071. }
  1072. /* Allow hardware batchbuffers unless told otherwise. */
  1073. dev_priv->allow_batchbuffer = 1;
  1074. return 0;
  1075. }
  1076. static int i915_load_modeset_init(struct drm_device *dev)
  1077. {
  1078. struct drm_i915_private *dev_priv = dev->dev_private;
  1079. int ret;
  1080. ret = intel_parse_bios(dev);
  1081. if (ret)
  1082. DRM_INFO("failed to find VBIOS tables\n");
  1083. /* If we have > 1 VGA cards, then we need to arbitrate access
  1084. * to the common VGA resources.
  1085. *
  1086. * If we are a secondary display controller (!PCI_DISPLAY_CLASS_VGA),
  1087. * then we do not take part in VGA arbitration and the
  1088. * vga_client_register() fails with -ENODEV.
  1089. */
  1090. ret = vga_client_register(dev->pdev, dev, NULL, i915_vga_set_decode);
  1091. if (ret && ret != -ENODEV)
  1092. goto out;
  1093. intel_register_dsm_handler();
  1094. ret = vga_switcheroo_register_client(dev->pdev,
  1095. i915_switcheroo_set_state,
  1096. NULL,
  1097. i915_switcheroo_can_switch);
  1098. if (ret)
  1099. goto cleanup_vga_client;
  1100. /* IIR "flip pending" bit means done if this bit is set */
  1101. if (IS_GEN3(dev) && (I915_READ(ECOSKPD) & ECO_FLIP_DONE))
  1102. dev_priv->flip_pending_is_done = true;
  1103. intel_modeset_init(dev);
  1104. ret = i915_load_gem_init(dev);
  1105. if (ret)
  1106. goto cleanup_vga_switcheroo;
  1107. intel_modeset_gem_init(dev);
  1108. ret = drm_irq_install(dev);
  1109. if (ret)
  1110. goto cleanup_gem;
  1111. /* Always safe in the mode setting case. */
  1112. /* FIXME: do pre/post-mode set stuff in core KMS code */
  1113. dev->vblank_disable_allowed = 1;
  1114. ret = intel_fbdev_init(dev);
  1115. if (ret)
  1116. goto cleanup_irq;
  1117. drm_kms_helper_poll_init(dev);
  1118. /* We're off and running w/KMS */
  1119. dev_priv->mm.suspended = 0;
  1120. return 0;
  1121. cleanup_irq:
  1122. drm_irq_uninstall(dev);
  1123. cleanup_gem:
  1124. mutex_lock(&dev->struct_mutex);
  1125. i915_gem_cleanup_ringbuffer(dev);
  1126. mutex_unlock(&dev->struct_mutex);
  1127. i915_gem_cleanup_aliasing_ppgtt(dev);
  1128. cleanup_vga_switcheroo:
  1129. vga_switcheroo_unregister_client(dev->pdev);
  1130. cleanup_vga_client:
  1131. vga_client_register(dev->pdev, NULL, NULL, NULL);
  1132. out:
  1133. return ret;
  1134. }
  1135. int i915_master_create(struct drm_device *dev, struct drm_master *master)
  1136. {
  1137. struct drm_i915_master_private *master_priv;
  1138. master_priv = kzalloc(sizeof(*master_priv), GFP_KERNEL);
  1139. if (!master_priv)
  1140. return -ENOMEM;
  1141. master->driver_priv = master_priv;
  1142. return 0;
  1143. }
  1144. void i915_master_destroy(struct drm_device *dev, struct drm_master *master)
  1145. {
  1146. struct drm_i915_master_private *master_priv = master->driver_priv;
  1147. if (!master_priv)
  1148. return;
  1149. kfree(master_priv);
  1150. master->driver_priv = NULL;
  1151. }
  1152. static void i915_pineview_get_mem_freq(struct drm_device *dev)
  1153. {
  1154. drm_i915_private_t *dev_priv = dev->dev_private;
  1155. u32 tmp;
  1156. tmp = I915_READ(CLKCFG);
  1157. switch (tmp & CLKCFG_FSB_MASK) {
  1158. case CLKCFG_FSB_533:
  1159. dev_priv->fsb_freq = 533; /* 133*4 */
  1160. break;
  1161. case CLKCFG_FSB_800:
  1162. dev_priv->fsb_freq = 800; /* 200*4 */
  1163. break;
  1164. case CLKCFG_FSB_667:
  1165. dev_priv->fsb_freq = 667; /* 167*4 */
  1166. break;
  1167. case CLKCFG_FSB_400:
  1168. dev_priv->fsb_freq = 400; /* 100*4 */
  1169. break;
  1170. }
  1171. switch (tmp & CLKCFG_MEM_MASK) {
  1172. case CLKCFG_MEM_533:
  1173. dev_priv->mem_freq = 533;
  1174. break;
  1175. case CLKCFG_MEM_667:
  1176. dev_priv->mem_freq = 667;
  1177. break;
  1178. case CLKCFG_MEM_800:
  1179. dev_priv->mem_freq = 800;
  1180. break;
  1181. }
  1182. /* detect pineview DDR3 setting */
  1183. tmp = I915_READ(CSHRDDR3CTL);
  1184. dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0;
  1185. }
  1186. static void i915_ironlake_get_mem_freq(struct drm_device *dev)
  1187. {
  1188. drm_i915_private_t *dev_priv = dev->dev_private;
  1189. u16 ddrpll, csipll;
  1190. ddrpll = I915_READ16(DDRMPLL1);
  1191. csipll = I915_READ16(CSIPLL0);
  1192. switch (ddrpll & 0xff) {
  1193. case 0xc:
  1194. dev_priv->mem_freq = 800;
  1195. break;
  1196. case 0x10:
  1197. dev_priv->mem_freq = 1066;
  1198. break;
  1199. case 0x14:
  1200. dev_priv->mem_freq = 1333;
  1201. break;
  1202. case 0x18:
  1203. dev_priv->mem_freq = 1600;
  1204. break;
  1205. default:
  1206. DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n",
  1207. ddrpll & 0xff);
  1208. dev_priv->mem_freq = 0;
  1209. break;
  1210. }
  1211. dev_priv->r_t = dev_priv->mem_freq;
  1212. switch (csipll & 0x3ff) {
  1213. case 0x00c:
  1214. dev_priv->fsb_freq = 3200;
  1215. break;
  1216. case 0x00e:
  1217. dev_priv->fsb_freq = 3733;
  1218. break;
  1219. case 0x010:
  1220. dev_priv->fsb_freq = 4266;
  1221. break;
  1222. case 0x012:
  1223. dev_priv->fsb_freq = 4800;
  1224. break;
  1225. case 0x014:
  1226. dev_priv->fsb_freq = 5333;
  1227. break;
  1228. case 0x016:
  1229. dev_priv->fsb_freq = 5866;
  1230. break;
  1231. case 0x018:
  1232. dev_priv->fsb_freq = 6400;
  1233. break;
  1234. default:
  1235. DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n",
  1236. csipll & 0x3ff);
  1237. dev_priv->fsb_freq = 0;
  1238. break;
  1239. }
  1240. if (dev_priv->fsb_freq == 3200) {
  1241. dev_priv->c_m = 0;
  1242. } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) {
  1243. dev_priv->c_m = 1;
  1244. } else {
  1245. dev_priv->c_m = 2;
  1246. }
  1247. }
  1248. static const struct cparams {
  1249. u16 i;
  1250. u16 t;
  1251. u16 m;
  1252. u16 c;
  1253. } cparams[] = {
  1254. { 1, 1333, 301, 28664 },
  1255. { 1, 1066, 294, 24460 },
  1256. { 1, 800, 294, 25192 },
  1257. { 0, 1333, 276, 27605 },
  1258. { 0, 1066, 276, 27605 },
  1259. { 0, 800, 231, 23784 },
  1260. };
  1261. unsigned long i915_chipset_val(struct drm_i915_private *dev_priv)
  1262. {
  1263. u64 total_count, diff, ret;
  1264. u32 count1, count2, count3, m = 0, c = 0;
  1265. unsigned long now = jiffies_to_msecs(jiffies), diff1;
  1266. int i;
  1267. diff1 = now - dev_priv->last_time1;
  1268. /* Prevent division-by-zero if we are asking too fast.
  1269. * Also, we don't get interesting results if we are polling
  1270. * faster than once in 10ms, so just return the saved value
  1271. * in such cases.
  1272. */
  1273. if (diff1 <= 10)
  1274. return dev_priv->chipset_power;
  1275. count1 = I915_READ(DMIEC);
  1276. count2 = I915_READ(DDREC);
  1277. count3 = I915_READ(CSIEC);
  1278. total_count = count1 + count2 + count3;
  1279. /* FIXME: handle per-counter overflow */
  1280. if (total_count < dev_priv->last_count1) {
  1281. diff = ~0UL - dev_priv->last_count1;
  1282. diff += total_count;
  1283. } else {
  1284. diff = total_count - dev_priv->last_count1;
  1285. }
  1286. for (i = 0; i < ARRAY_SIZE(cparams); i++) {
  1287. if (cparams[i].i == dev_priv->c_m &&
  1288. cparams[i].t == dev_priv->r_t) {
  1289. m = cparams[i].m;
  1290. c = cparams[i].c;
  1291. break;
  1292. }
  1293. }
  1294. diff = div_u64(diff, diff1);
  1295. ret = ((m * diff) + c);
  1296. ret = div_u64(ret, 10);
  1297. dev_priv->last_count1 = total_count;
  1298. dev_priv->last_time1 = now;
  1299. dev_priv->chipset_power = ret;
  1300. return ret;
  1301. }
  1302. unsigned long i915_mch_val(struct drm_i915_private *dev_priv)
  1303. {
  1304. unsigned long m, x, b;
  1305. u32 tsfs;
  1306. tsfs = I915_READ(TSFS);
  1307. m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT);
  1308. x = I915_READ8(TR1);
  1309. b = tsfs & TSFS_INTR_MASK;
  1310. return ((m * x) / 127) - b;
  1311. }
  1312. static u16 pvid_to_extvid(struct drm_i915_private *dev_priv, u8 pxvid)
  1313. {
  1314. static const struct v_table {
  1315. u16 vd; /* in .1 mil */
  1316. u16 vm; /* in .1 mil */
  1317. } v_table[] = {
  1318. { 0, 0, },
  1319. { 375, 0, },
  1320. { 500, 0, },
  1321. { 625, 0, },
  1322. { 750, 0, },
  1323. { 875, 0, },
  1324. { 1000, 0, },
  1325. { 1125, 0, },
  1326. { 4125, 3000, },
  1327. { 4125, 3000, },
  1328. { 4125, 3000, },
  1329. { 4125, 3000, },
  1330. { 4125, 3000, },
  1331. { 4125, 3000, },
  1332. { 4125, 3000, },
  1333. { 4125, 3000, },
  1334. { 4125, 3000, },
  1335. { 4125, 3000, },
  1336. { 4125, 3000, },
  1337. { 4125, 3000, },
  1338. { 4125, 3000, },
  1339. { 4125, 3000, },
  1340. { 4125, 3000, },
  1341. { 4125, 3000, },
  1342. { 4125, 3000, },
  1343. { 4125, 3000, },
  1344. { 4125, 3000, },
  1345. { 4125, 3000, },
  1346. { 4125, 3000, },
  1347. { 4125, 3000, },
  1348. { 4125, 3000, },
  1349. { 4125, 3000, },
  1350. { 4250, 3125, },
  1351. { 4375, 3250, },
  1352. { 4500, 3375, },
  1353. { 4625, 3500, },
  1354. { 4750, 3625, },
  1355. { 4875, 3750, },
  1356. { 5000, 3875, },
  1357. { 5125, 4000, },
  1358. { 5250, 4125, },
  1359. { 5375, 4250, },
  1360. { 5500, 4375, },
  1361. { 5625, 4500, },
  1362. { 5750, 4625, },
  1363. { 5875, 4750, },
  1364. { 6000, 4875, },
  1365. { 6125, 5000, },
  1366. { 6250, 5125, },
  1367. { 6375, 5250, },
  1368. { 6500, 5375, },
  1369. { 6625, 5500, },
  1370. { 6750, 5625, },
  1371. { 6875, 5750, },
  1372. { 7000, 5875, },
  1373. { 7125, 6000, },
  1374. { 7250, 6125, },
  1375. { 7375, 6250, },
  1376. { 7500, 6375, },
  1377. { 7625, 6500, },
  1378. { 7750, 6625, },
  1379. { 7875, 6750, },
  1380. { 8000, 6875, },
  1381. { 8125, 7000, },
  1382. { 8250, 7125, },
  1383. { 8375, 7250, },
  1384. { 8500, 7375, },
  1385. { 8625, 7500, },
  1386. { 8750, 7625, },
  1387. { 8875, 7750, },
  1388. { 9000, 7875, },
  1389. { 9125, 8000, },
  1390. { 9250, 8125, },
  1391. { 9375, 8250, },
  1392. { 9500, 8375, },
  1393. { 9625, 8500, },
  1394. { 9750, 8625, },
  1395. { 9875, 8750, },
  1396. { 10000, 8875, },
  1397. { 10125, 9000, },
  1398. { 10250, 9125, },
  1399. { 10375, 9250, },
  1400. { 10500, 9375, },
  1401. { 10625, 9500, },
  1402. { 10750, 9625, },
  1403. { 10875, 9750, },
  1404. { 11000, 9875, },
  1405. { 11125, 10000, },
  1406. { 11250, 10125, },
  1407. { 11375, 10250, },
  1408. { 11500, 10375, },
  1409. { 11625, 10500, },
  1410. { 11750, 10625, },
  1411. { 11875, 10750, },
  1412. { 12000, 10875, },
  1413. { 12125, 11000, },
  1414. { 12250, 11125, },
  1415. { 12375, 11250, },
  1416. { 12500, 11375, },
  1417. { 12625, 11500, },
  1418. { 12750, 11625, },
  1419. { 12875, 11750, },
  1420. { 13000, 11875, },
  1421. { 13125, 12000, },
  1422. { 13250, 12125, },
  1423. { 13375, 12250, },
  1424. { 13500, 12375, },
  1425. { 13625, 12500, },
  1426. { 13750, 12625, },
  1427. { 13875, 12750, },
  1428. { 14000, 12875, },
  1429. { 14125, 13000, },
  1430. { 14250, 13125, },
  1431. { 14375, 13250, },
  1432. { 14500, 13375, },
  1433. { 14625, 13500, },
  1434. { 14750, 13625, },
  1435. { 14875, 13750, },
  1436. { 15000, 13875, },
  1437. { 15125, 14000, },
  1438. { 15250, 14125, },
  1439. { 15375, 14250, },
  1440. { 15500, 14375, },
  1441. { 15625, 14500, },
  1442. { 15750, 14625, },
  1443. { 15875, 14750, },
  1444. { 16000, 14875, },
  1445. { 16125, 15000, },
  1446. };
  1447. if (dev_priv->info->is_mobile)
  1448. return v_table[pxvid].vm;
  1449. else
  1450. return v_table[pxvid].vd;
  1451. }
  1452. void i915_update_gfx_val(struct drm_i915_private *dev_priv)
  1453. {
  1454. struct timespec now, diff1;
  1455. u64 diff;
  1456. unsigned long diffms;
  1457. u32 count;
  1458. getrawmonotonic(&now);
  1459. diff1 = timespec_sub(now, dev_priv->last_time2);
  1460. /* Don't divide by 0 */
  1461. diffms = diff1.tv_sec * 1000 + diff1.tv_nsec / 1000000;
  1462. if (!diffms)
  1463. return;
  1464. count = I915_READ(GFXEC);
  1465. if (count < dev_priv->last_count2) {
  1466. diff = ~0UL - dev_priv->last_count2;
  1467. diff += count;
  1468. } else {
  1469. diff = count - dev_priv->last_count2;
  1470. }
  1471. dev_priv->last_count2 = count;
  1472. dev_priv->last_time2 = now;
  1473. /* More magic constants... */
  1474. diff = diff * 1181;
  1475. diff = div_u64(diff, diffms * 10);
  1476. dev_priv->gfx_power = diff;
  1477. }
  1478. unsigned long i915_gfx_val(struct drm_i915_private *dev_priv)
  1479. {
  1480. unsigned long t, corr, state1, corr2, state2;
  1481. u32 pxvid, ext_v;
  1482. pxvid = I915_READ(PXVFREQ_BASE + (dev_priv->cur_delay * 4));
  1483. pxvid = (pxvid >> 24) & 0x7f;
  1484. ext_v = pvid_to_extvid(dev_priv, pxvid);
  1485. state1 = ext_v;
  1486. t = i915_mch_val(dev_priv);
  1487. /* Revel in the empirically derived constants */
  1488. /* Correction factor in 1/100000 units */
  1489. if (t > 80)
  1490. corr = ((t * 2349) + 135940);
  1491. else if (t >= 50)
  1492. corr = ((t * 964) + 29317);
  1493. else /* < 50 */
  1494. corr = ((t * 301) + 1004);
  1495. corr = corr * ((150142 * state1) / 10000 - 78642);
  1496. corr /= 100000;
  1497. corr2 = (corr * dev_priv->corr);
  1498. state2 = (corr2 * state1) / 10000;
  1499. state2 /= 100; /* convert to mW */
  1500. i915_update_gfx_val(dev_priv);
  1501. return dev_priv->gfx_power + state2;
  1502. }
  1503. /* Global for IPS driver to get at the current i915 device */
  1504. static struct drm_i915_private *i915_mch_dev;
  1505. /*
  1506. * Lock protecting IPS related data structures
  1507. * - i915_mch_dev
  1508. * - dev_priv->max_delay
  1509. * - dev_priv->min_delay
  1510. * - dev_priv->fmax
  1511. * - dev_priv->gpu_busy
  1512. */
  1513. static DEFINE_SPINLOCK(mchdev_lock);
  1514. /**
  1515. * i915_read_mch_val - return value for IPS use
  1516. *
  1517. * Calculate and return a value for the IPS driver to use when deciding whether
  1518. * we have thermal and power headroom to increase CPU or GPU power budget.
  1519. */
  1520. unsigned long i915_read_mch_val(void)
  1521. {
  1522. struct drm_i915_private *dev_priv;
  1523. unsigned long chipset_val, graphics_val, ret = 0;
  1524. spin_lock(&mchdev_lock);
  1525. if (!i915_mch_dev)
  1526. goto out_unlock;
  1527. dev_priv = i915_mch_dev;
  1528. chipset_val = i915_chipset_val(dev_priv);
  1529. graphics_val = i915_gfx_val(dev_priv);
  1530. ret = chipset_val + graphics_val;
  1531. out_unlock:
  1532. spin_unlock(&mchdev_lock);
  1533. return ret;
  1534. }
  1535. EXPORT_SYMBOL_GPL(i915_read_mch_val);
  1536. /**
  1537. * i915_gpu_raise - raise GPU frequency limit
  1538. *
  1539. * Raise the limit; IPS indicates we have thermal headroom.
  1540. */
  1541. bool i915_gpu_raise(void)
  1542. {
  1543. struct drm_i915_private *dev_priv;
  1544. bool ret = true;
  1545. spin_lock(&mchdev_lock);
  1546. if (!i915_mch_dev) {
  1547. ret = false;
  1548. goto out_unlock;
  1549. }
  1550. dev_priv = i915_mch_dev;
  1551. if (dev_priv->max_delay > dev_priv->fmax)
  1552. dev_priv->max_delay--;
  1553. out_unlock:
  1554. spin_unlock(&mchdev_lock);
  1555. return ret;
  1556. }
  1557. EXPORT_SYMBOL_GPL(i915_gpu_raise);
  1558. /**
  1559. * i915_gpu_lower - lower GPU frequency limit
  1560. *
  1561. * IPS indicates we're close to a thermal limit, so throttle back the GPU
  1562. * frequency maximum.
  1563. */
  1564. bool i915_gpu_lower(void)
  1565. {
  1566. struct drm_i915_private *dev_priv;
  1567. bool ret = true;
  1568. spin_lock(&mchdev_lock);
  1569. if (!i915_mch_dev) {
  1570. ret = false;
  1571. goto out_unlock;
  1572. }
  1573. dev_priv = i915_mch_dev;
  1574. if (dev_priv->max_delay < dev_priv->min_delay)
  1575. dev_priv->max_delay++;
  1576. out_unlock:
  1577. spin_unlock(&mchdev_lock);
  1578. return ret;
  1579. }
  1580. EXPORT_SYMBOL_GPL(i915_gpu_lower);
  1581. /**
  1582. * i915_gpu_busy - indicate GPU business to IPS
  1583. *
  1584. * Tell the IPS driver whether or not the GPU is busy.
  1585. */
  1586. bool i915_gpu_busy(void)
  1587. {
  1588. struct drm_i915_private *dev_priv;
  1589. bool ret = false;
  1590. spin_lock(&mchdev_lock);
  1591. if (!i915_mch_dev)
  1592. goto out_unlock;
  1593. dev_priv = i915_mch_dev;
  1594. ret = dev_priv->busy;
  1595. out_unlock:
  1596. spin_unlock(&mchdev_lock);
  1597. return ret;
  1598. }
  1599. EXPORT_SYMBOL_GPL(i915_gpu_busy);
  1600. /**
  1601. * i915_gpu_turbo_disable - disable graphics turbo
  1602. *
  1603. * Disable graphics turbo by resetting the max frequency and setting the
  1604. * current frequency to the default.
  1605. */
  1606. bool i915_gpu_turbo_disable(void)
  1607. {
  1608. struct drm_i915_private *dev_priv;
  1609. bool ret = true;
  1610. spin_lock(&mchdev_lock);
  1611. if (!i915_mch_dev) {
  1612. ret = false;
  1613. goto out_unlock;
  1614. }
  1615. dev_priv = i915_mch_dev;
  1616. dev_priv->max_delay = dev_priv->fstart;
  1617. if (!ironlake_set_drps(dev_priv->dev, dev_priv->fstart))
  1618. ret = false;
  1619. out_unlock:
  1620. spin_unlock(&mchdev_lock);
  1621. return ret;
  1622. }
  1623. EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable);
  1624. /**
  1625. * Tells the intel_ips driver that the i915 driver is now loaded, if
  1626. * IPS got loaded first.
  1627. *
  1628. * This awkward dance is so that neither module has to depend on the
  1629. * other in order for IPS to do the appropriate communication of
  1630. * GPU turbo limits to i915.
  1631. */
  1632. static void
  1633. ips_ping_for_i915_load(void)
  1634. {
  1635. void (*link)(void);
  1636. link = symbol_get(ips_link_to_i915_driver);
  1637. if (link) {
  1638. link();
  1639. symbol_put(ips_link_to_i915_driver);
  1640. }
  1641. }
  1642. static void
  1643. i915_mtrr_setup(struct drm_i915_private *dev_priv, unsigned long base,
  1644. unsigned long size)
  1645. {
  1646. dev_priv->mm.gtt_mtrr = -1;
  1647. #if defined(CONFIG_X86_PAT)
  1648. if (cpu_has_pat)
  1649. return;
  1650. #endif
  1651. /* Set up a WC MTRR for non-PAT systems. This is more common than
  1652. * one would think, because the kernel disables PAT on first
  1653. * generation Core chips because WC PAT gets overridden by a UC
  1654. * MTRR if present. Even if a UC MTRR isn't present.
  1655. */
  1656. dev_priv->mm.gtt_mtrr = mtrr_add(base, size, MTRR_TYPE_WRCOMB, 1);
  1657. if (dev_priv->mm.gtt_mtrr < 0) {
  1658. DRM_INFO("MTRR allocation failed. Graphics "
  1659. "performance may suffer.\n");
  1660. }
  1661. }
  1662. /**
  1663. * i915_driver_load - setup chip and create an initial config
  1664. * @dev: DRM device
  1665. * @flags: startup flags
  1666. *
  1667. * The driver load routine has to do several things:
  1668. * - drive output discovery via intel_modeset_init()
  1669. * - initialize the memory manager
  1670. * - allocate initial config memory
  1671. * - setup the DRM framebuffer with the allocated memory
  1672. */
  1673. int i915_driver_load(struct drm_device *dev, unsigned long flags)
  1674. {
  1675. struct drm_i915_private *dev_priv;
  1676. struct intel_device_info *info;
  1677. int ret = 0, mmio_bar;
  1678. uint32_t aperture_size;
  1679. info = (struct intel_device_info *) flags;
  1680. /* Refuse to load on gen6+ without kms enabled. */
  1681. if (info->gen >= 6 && !drm_core_check_feature(dev, DRIVER_MODESET))
  1682. return -ENODEV;
  1683. /* i915 has 4 more counters */
  1684. dev->counters += 4;
  1685. dev->types[6] = _DRM_STAT_IRQ;
  1686. dev->types[7] = _DRM_STAT_PRIMARY;
  1687. dev->types[8] = _DRM_STAT_SECONDARY;
  1688. dev->types[9] = _DRM_STAT_DMA;
  1689. dev_priv = kzalloc(sizeof(drm_i915_private_t), GFP_KERNEL);
  1690. if (dev_priv == NULL)
  1691. return -ENOMEM;
  1692. dev->dev_private = (void *)dev_priv;
  1693. dev_priv->dev = dev;
  1694. dev_priv->info = info;
  1695. if (i915_get_bridge_dev(dev)) {
  1696. ret = -EIO;
  1697. goto free_priv;
  1698. }
  1699. pci_set_master(dev->pdev);
  1700. /* overlay on gen2 is broken and can't address above 1G */
  1701. if (IS_GEN2(dev))
  1702. dma_set_coherent_mask(&dev->pdev->dev, DMA_BIT_MASK(30));
  1703. /* 965GM sometimes incorrectly writes to hardware status page (HWS)
  1704. * using 32bit addressing, overwriting memory if HWS is located
  1705. * above 4GB.
  1706. *
  1707. * The documentation also mentions an issue with undefined
  1708. * behaviour if any general state is accessed within a page above 4GB,
  1709. * which also needs to be handled carefully.
  1710. */
  1711. if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  1712. dma_set_coherent_mask(&dev->pdev->dev, DMA_BIT_MASK(32));
  1713. mmio_bar = IS_GEN2(dev) ? 1 : 0;
  1714. dev_priv->regs = pci_iomap(dev->pdev, mmio_bar, 0);
  1715. if (!dev_priv->regs) {
  1716. DRM_ERROR("failed to map registers\n");
  1717. ret = -EIO;
  1718. goto put_bridge;
  1719. }
  1720. dev_priv->mm.gtt = intel_gtt_get();
  1721. if (!dev_priv->mm.gtt) {
  1722. DRM_ERROR("Failed to initialize GTT\n");
  1723. ret = -ENODEV;
  1724. goto out_rmmap;
  1725. }
  1726. aperture_size = dev_priv->mm.gtt->gtt_mappable_entries << PAGE_SHIFT;
  1727. dev_priv->mm.gtt_mapping =
  1728. io_mapping_create_wc(dev->agp->base, aperture_size);
  1729. if (dev_priv->mm.gtt_mapping == NULL) {
  1730. ret = -EIO;
  1731. goto out_rmmap;
  1732. }
  1733. i915_mtrr_setup(dev_priv, dev->agp->base, aperture_size);
  1734. /* The i915 workqueue is primarily used for batched retirement of
  1735. * requests (and thus managing bo) once the task has been completed
  1736. * by the GPU. i915_gem_retire_requests() is called directly when we
  1737. * need high-priority retirement, such as waiting for an explicit
  1738. * bo.
  1739. *
  1740. * It is also used for periodic low-priority events, such as
  1741. * idle-timers and recording error state.
  1742. *
  1743. * All tasks on the workqueue are expected to acquire the dev mutex
  1744. * so there is no point in running more than one instance of the
  1745. * workqueue at any time: max_active = 1 and NON_REENTRANT.
  1746. */
  1747. dev_priv->wq = alloc_workqueue("i915",
  1748. WQ_UNBOUND | WQ_NON_REENTRANT,
  1749. 1);
  1750. if (dev_priv->wq == NULL) {
  1751. DRM_ERROR("Failed to create our workqueue.\n");
  1752. ret = -ENOMEM;
  1753. goto out_mtrrfree;
  1754. }
  1755. /* enable GEM by default */
  1756. dev_priv->has_gem = 1;
  1757. intel_irq_init(dev);
  1758. /* Try to make sure MCHBAR is enabled before poking at it */
  1759. intel_setup_mchbar(dev);
  1760. intel_setup_gmbus(dev);
  1761. intel_opregion_setup(dev);
  1762. /* Make sure the bios did its job and set up vital registers */
  1763. intel_setup_bios(dev);
  1764. i915_gem_load(dev);
  1765. /* Init HWS */
  1766. if (!I915_NEED_GFX_HWS(dev)) {
  1767. ret = i915_init_phys_hws(dev);
  1768. if (ret)
  1769. goto out_gem_unload;
  1770. }
  1771. if (IS_PINEVIEW(dev))
  1772. i915_pineview_get_mem_freq(dev);
  1773. else if (IS_GEN5(dev))
  1774. i915_ironlake_get_mem_freq(dev);
  1775. /* On the 945G/GM, the chipset reports the MSI capability on the
  1776. * integrated graphics even though the support isn't actually there
  1777. * according to the published specs. It doesn't appear to function
  1778. * correctly in testing on 945G.
  1779. * This may be a side effect of MSI having been made available for PEG
  1780. * and the registers being closely associated.
  1781. *
  1782. * According to chipset errata, on the 965GM, MSI interrupts may
  1783. * be lost or delayed, but we use them anyways to avoid
  1784. * stuck interrupts on some machines.
  1785. */
  1786. if (!IS_I945G(dev) && !IS_I945GM(dev))
  1787. pci_enable_msi(dev->pdev);
  1788. spin_lock_init(&dev_priv->gt_lock);
  1789. spin_lock_init(&dev_priv->irq_lock);
  1790. spin_lock_init(&dev_priv->error_lock);
  1791. spin_lock_init(&dev_priv->rps_lock);
  1792. if (IS_IVYBRIDGE(dev))
  1793. dev_priv->num_pipe = 3;
  1794. else if (IS_MOBILE(dev) || !IS_GEN2(dev))
  1795. dev_priv->num_pipe = 2;
  1796. else
  1797. dev_priv->num_pipe = 1;
  1798. ret = drm_vblank_init(dev, dev_priv->num_pipe);
  1799. if (ret)
  1800. goto out_gem_unload;
  1801. /* Start out suspended */
  1802. dev_priv->mm.suspended = 1;
  1803. intel_detect_pch(dev);
  1804. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  1805. ret = i915_load_modeset_init(dev);
  1806. if (ret < 0) {
  1807. DRM_ERROR("failed to init modeset\n");
  1808. goto out_gem_unload;
  1809. }
  1810. }
  1811. /* Must be done after probing outputs */
  1812. intel_opregion_init(dev);
  1813. acpi_video_register();
  1814. setup_timer(&dev_priv->hangcheck_timer, i915_hangcheck_elapsed,
  1815. (unsigned long) dev);
  1816. spin_lock(&mchdev_lock);
  1817. i915_mch_dev = dev_priv;
  1818. dev_priv->mchdev_lock = &mchdev_lock;
  1819. spin_unlock(&mchdev_lock);
  1820. ips_ping_for_i915_load();
  1821. return 0;
  1822. out_gem_unload:
  1823. if (dev_priv->mm.inactive_shrinker.shrink)
  1824. unregister_shrinker(&dev_priv->mm.inactive_shrinker);
  1825. if (dev->pdev->msi_enabled)
  1826. pci_disable_msi(dev->pdev);
  1827. intel_teardown_gmbus(dev);
  1828. intel_teardown_mchbar(dev);
  1829. destroy_workqueue(dev_priv->wq);
  1830. out_mtrrfree:
  1831. if (dev_priv->mm.gtt_mtrr >= 0) {
  1832. mtrr_del(dev_priv->mm.gtt_mtrr, dev->agp->base,
  1833. dev->agp->agp_info.aper_size * 1024 * 1024);
  1834. dev_priv->mm.gtt_mtrr = -1;
  1835. }
  1836. io_mapping_free(dev_priv->mm.gtt_mapping);
  1837. out_rmmap:
  1838. pci_iounmap(dev->pdev, dev_priv->regs);
  1839. put_bridge:
  1840. pci_dev_put(dev_priv->bridge_dev);
  1841. free_priv:
  1842. kfree(dev_priv);
  1843. return ret;
  1844. }
  1845. int i915_driver_unload(struct drm_device *dev)
  1846. {
  1847. struct drm_i915_private *dev_priv = dev->dev_private;
  1848. int ret;
  1849. spin_lock(&mchdev_lock);
  1850. i915_mch_dev = NULL;
  1851. spin_unlock(&mchdev_lock);
  1852. if (dev_priv->mm.inactive_shrinker.shrink)
  1853. unregister_shrinker(&dev_priv->mm.inactive_shrinker);
  1854. mutex_lock(&dev->struct_mutex);
  1855. ret = i915_gpu_idle(dev, true);
  1856. if (ret)
  1857. DRM_ERROR("failed to idle hardware: %d\n", ret);
  1858. mutex_unlock(&dev->struct_mutex);
  1859. /* Cancel the retire work handler, which should be idle now. */
  1860. cancel_delayed_work_sync(&dev_priv->mm.retire_work);
  1861. io_mapping_free(dev_priv->mm.gtt_mapping);
  1862. if (dev_priv->mm.gtt_mtrr >= 0) {
  1863. mtrr_del(dev_priv->mm.gtt_mtrr, dev->agp->base,
  1864. dev->agp->agp_info.aper_size * 1024 * 1024);
  1865. dev_priv->mm.gtt_mtrr = -1;
  1866. }
  1867. acpi_video_unregister();
  1868. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  1869. intel_fbdev_fini(dev);
  1870. intel_modeset_cleanup(dev);
  1871. /*
  1872. * free the memory space allocated for the child device
  1873. * config parsed from VBT
  1874. */
  1875. if (dev_priv->child_dev && dev_priv->child_dev_num) {
  1876. kfree(dev_priv->child_dev);
  1877. dev_priv->child_dev = NULL;
  1878. dev_priv->child_dev_num = 0;
  1879. }
  1880. vga_switcheroo_unregister_client(dev->pdev);
  1881. vga_client_register(dev->pdev, NULL, NULL, NULL);
  1882. }
  1883. /* Free error state after interrupts are fully disabled. */
  1884. del_timer_sync(&dev_priv->hangcheck_timer);
  1885. cancel_work_sync(&dev_priv->error_work);
  1886. i915_destroy_error_state(dev);
  1887. if (dev->pdev->msi_enabled)
  1888. pci_disable_msi(dev->pdev);
  1889. intel_opregion_fini(dev);
  1890. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  1891. /* Flush any outstanding unpin_work. */
  1892. flush_workqueue(dev_priv->wq);
  1893. mutex_lock(&dev->struct_mutex);
  1894. i915_gem_free_all_phys_object(dev);
  1895. i915_gem_cleanup_ringbuffer(dev);
  1896. mutex_unlock(&dev->struct_mutex);
  1897. i915_gem_cleanup_aliasing_ppgtt(dev);
  1898. if (I915_HAS_FBC(dev) && i915_powersave)
  1899. i915_cleanup_compression(dev);
  1900. drm_mm_takedown(&dev_priv->mm.stolen);
  1901. intel_cleanup_overlay(dev);
  1902. if (!I915_NEED_GFX_HWS(dev))
  1903. i915_free_hws(dev);
  1904. }
  1905. if (dev_priv->regs != NULL)
  1906. pci_iounmap(dev->pdev, dev_priv->regs);
  1907. intel_teardown_gmbus(dev);
  1908. intel_teardown_mchbar(dev);
  1909. destroy_workqueue(dev_priv->wq);
  1910. pci_dev_put(dev_priv->bridge_dev);
  1911. kfree(dev->dev_private);
  1912. return 0;
  1913. }
  1914. int i915_driver_open(struct drm_device *dev, struct drm_file *file)
  1915. {
  1916. struct drm_i915_file_private *file_priv;
  1917. DRM_DEBUG_DRIVER("\n");
  1918. file_priv = kmalloc(sizeof(*file_priv), GFP_KERNEL);
  1919. if (!file_priv)
  1920. return -ENOMEM;
  1921. file->driver_priv = file_priv;
  1922. spin_lock_init(&file_priv->mm.lock);
  1923. INIT_LIST_HEAD(&file_priv->mm.request_list);
  1924. return 0;
  1925. }
  1926. /**
  1927. * i915_driver_lastclose - clean up after all DRM clients have exited
  1928. * @dev: DRM device
  1929. *
  1930. * Take care of cleaning up after all DRM clients have exited. In the
  1931. * mode setting case, we want to restore the kernel's initial mode (just
  1932. * in case the last client left us in a bad state).
  1933. *
  1934. * Additionally, in the non-mode setting case, we'll tear down the GTT
  1935. * and DMA structures, since the kernel won't be using them, and clea
  1936. * up any GEM state.
  1937. */
  1938. void i915_driver_lastclose(struct drm_device * dev)
  1939. {
  1940. drm_i915_private_t *dev_priv = dev->dev_private;
  1941. if (!dev_priv || drm_core_check_feature(dev, DRIVER_MODESET)) {
  1942. intel_fb_restore_mode(dev);
  1943. vga_switcheroo_process_delayed_switch();
  1944. return;
  1945. }
  1946. i915_gem_lastclose(dev);
  1947. i915_dma_cleanup(dev);
  1948. }
  1949. void i915_driver_preclose(struct drm_device * dev, struct drm_file *file_priv)
  1950. {
  1951. i915_gem_release(dev, file_priv);
  1952. }
  1953. void i915_driver_postclose(struct drm_device *dev, struct drm_file *file)
  1954. {
  1955. struct drm_i915_file_private *file_priv = file->driver_priv;
  1956. kfree(file_priv);
  1957. }
  1958. struct drm_ioctl_desc i915_ioctls[] = {
  1959. DRM_IOCTL_DEF_DRV(I915_INIT, i915_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  1960. DRM_IOCTL_DEF_DRV(I915_FLUSH, i915_flush_ioctl, DRM_AUTH),
  1961. DRM_IOCTL_DEF_DRV(I915_FLIP, i915_flip_bufs, DRM_AUTH),
  1962. DRM_IOCTL_DEF_DRV(I915_BATCHBUFFER, i915_batchbuffer, DRM_AUTH),
  1963. DRM_IOCTL_DEF_DRV(I915_IRQ_EMIT, i915_irq_emit, DRM_AUTH),
  1964. DRM_IOCTL_DEF_DRV(I915_IRQ_WAIT, i915_irq_wait, DRM_AUTH),
  1965. DRM_IOCTL_DEF_DRV(I915_GETPARAM, i915_getparam, DRM_AUTH),
  1966. DRM_IOCTL_DEF_DRV(I915_SETPARAM, i915_setparam, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  1967. DRM_IOCTL_DEF_DRV(I915_ALLOC, drm_noop, DRM_AUTH),
  1968. DRM_IOCTL_DEF_DRV(I915_FREE, drm_noop, DRM_AUTH),
  1969. DRM_IOCTL_DEF_DRV(I915_INIT_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  1970. DRM_IOCTL_DEF_DRV(I915_CMDBUFFER, i915_cmdbuffer, DRM_AUTH),
  1971. DRM_IOCTL_DEF_DRV(I915_DESTROY_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  1972. DRM_IOCTL_DEF_DRV(I915_SET_VBLANK_PIPE, i915_vblank_pipe_set, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  1973. DRM_IOCTL_DEF_DRV(I915_GET_VBLANK_PIPE, i915_vblank_pipe_get, DRM_AUTH),
  1974. DRM_IOCTL_DEF_DRV(I915_VBLANK_SWAP, i915_vblank_swap, DRM_AUTH),
  1975. DRM_IOCTL_DEF_DRV(I915_HWS_ADDR, i915_set_status_page, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  1976. DRM_IOCTL_DEF_DRV(I915_GEM_INIT, i915_gem_init_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED),
  1977. DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER, i915_gem_execbuffer, DRM_AUTH|DRM_UNLOCKED),
  1978. DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER2, i915_gem_execbuffer2, DRM_AUTH|DRM_UNLOCKED),
  1979. DRM_IOCTL_DEF_DRV(I915_GEM_PIN, i915_gem_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY|DRM_UNLOCKED),
  1980. DRM_IOCTL_DEF_DRV(I915_GEM_UNPIN, i915_gem_unpin_ioctl, DRM_AUTH|DRM_ROOT_ONLY|DRM_UNLOCKED),
  1981. DRM_IOCTL_DEF_DRV(I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_AUTH|DRM_UNLOCKED),
  1982. DRM_IOCTL_DEF_DRV(I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_AUTH|DRM_UNLOCKED),
  1983. DRM_IOCTL_DEF_DRV(I915_GEM_ENTERVT, i915_gem_entervt_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED),
  1984. DRM_IOCTL_DEF_DRV(I915_GEM_LEAVEVT, i915_gem_leavevt_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED),
  1985. DRM_IOCTL_DEF_DRV(I915_GEM_CREATE, i915_gem_create_ioctl, DRM_UNLOCKED),
  1986. DRM_IOCTL_DEF_DRV(I915_GEM_PREAD, i915_gem_pread_ioctl, DRM_UNLOCKED),
  1987. DRM_IOCTL_DEF_DRV(I915_GEM_PWRITE, i915_gem_pwrite_ioctl, DRM_UNLOCKED),
  1988. DRM_IOCTL_DEF_DRV(I915_GEM_MMAP, i915_gem_mmap_ioctl, DRM_UNLOCKED),
  1989. DRM_IOCTL_DEF_DRV(I915_GEM_MMAP_GTT, i915_gem_mmap_gtt_ioctl, DRM_UNLOCKED),
  1990. DRM_IOCTL_DEF_DRV(I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, DRM_UNLOCKED),
  1991. DRM_IOCTL_DEF_DRV(I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, DRM_UNLOCKED),
  1992. DRM_IOCTL_DEF_DRV(I915_GEM_SET_TILING, i915_gem_set_tiling, DRM_UNLOCKED),
  1993. DRM_IOCTL_DEF_DRV(I915_GEM_GET_TILING, i915_gem_get_tiling, DRM_UNLOCKED),
  1994. DRM_IOCTL_DEF_DRV(I915_GEM_GET_APERTURE, i915_gem_get_aperture_ioctl, DRM_UNLOCKED),
  1995. DRM_IOCTL_DEF_DRV(I915_GET_PIPE_FROM_CRTC_ID, intel_get_pipe_from_crtc_id, DRM_UNLOCKED),
  1996. DRM_IOCTL_DEF_DRV(I915_GEM_MADVISE, i915_gem_madvise_ioctl, DRM_UNLOCKED),
  1997. DRM_IOCTL_DEF_DRV(I915_OVERLAY_PUT_IMAGE, intel_overlay_put_image, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
  1998. DRM_IOCTL_DEF_DRV(I915_OVERLAY_ATTRS, intel_overlay_attrs, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
  1999. DRM_IOCTL_DEF_DRV(I915_SET_SPRITE_COLORKEY, intel_sprite_set_colorkey, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
  2000. DRM_IOCTL_DEF_DRV(I915_GET_SPRITE_COLORKEY, intel_sprite_get_colorkey, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
  2001. };
  2002. int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls);
  2003. /*
  2004. * This is really ugly: Because old userspace abused the linux agp interface to
  2005. * manage the gtt, we need to claim that all intel devices are agp. For
  2006. * otherwise the drm core refuses to initialize the agp support code.
  2007. */
  2008. int i915_driver_device_is_agp(struct drm_device * dev)
  2009. {
  2010. return 1;
  2011. }