i915_irq.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173
  1. /* i915_irq.c -- IRQ 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. #include <linux/sysrq.h>
  29. #include <linux/slab.h>
  30. #include "drmP.h"
  31. #include "drm.h"
  32. #include "i915_drm.h"
  33. #include "i915_drv.h"
  34. #include "i915_trace.h"
  35. #include "intel_drv.h"
  36. #define MAX_NOPID ((u32)~0)
  37. /**
  38. * Interrupts that are always left unmasked.
  39. *
  40. * Since pipe events are edge-triggered from the PIPESTAT register to IIR,
  41. * we leave them always unmasked in IMR and then control enabling them through
  42. * PIPESTAT alone.
  43. */
  44. #define I915_INTERRUPT_ENABLE_FIX \
  45. (I915_ASLE_INTERRUPT | \
  46. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | \
  47. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | \
  48. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | \
  49. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | \
  50. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  51. /** Interrupts that we mask and unmask at runtime. */
  52. #define I915_INTERRUPT_ENABLE_VAR (I915_USER_INTERRUPT | I915_BSD_USER_INTERRUPT)
  53. #define I915_PIPE_VBLANK_STATUS (PIPE_START_VBLANK_INTERRUPT_STATUS |\
  54. PIPE_VBLANK_INTERRUPT_STATUS)
  55. #define I915_PIPE_VBLANK_ENABLE (PIPE_START_VBLANK_INTERRUPT_ENABLE |\
  56. PIPE_VBLANK_INTERRUPT_ENABLE)
  57. #define DRM_I915_VBLANK_PIPE_ALL (DRM_I915_VBLANK_PIPE_A | \
  58. DRM_I915_VBLANK_PIPE_B)
  59. /* For display hotplug interrupt */
  60. static void
  61. ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
  62. {
  63. if ((dev_priv->irq_mask & mask) != 0) {
  64. dev_priv->irq_mask &= ~mask;
  65. I915_WRITE(DEIMR, dev_priv->irq_mask);
  66. POSTING_READ(DEIMR);
  67. }
  68. }
  69. static inline void
  70. ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
  71. {
  72. if ((dev_priv->irq_mask & mask) != mask) {
  73. dev_priv->irq_mask |= mask;
  74. I915_WRITE(DEIMR, dev_priv->irq_mask);
  75. POSTING_READ(DEIMR);
  76. }
  77. }
  78. void
  79. i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
  80. {
  81. if ((dev_priv->pipestat[pipe] & mask) != mask) {
  82. u32 reg = PIPESTAT(pipe);
  83. dev_priv->pipestat[pipe] |= mask;
  84. /* Enable the interrupt, clear any pending status */
  85. I915_WRITE(reg, dev_priv->pipestat[pipe] | (mask >> 16));
  86. POSTING_READ(reg);
  87. }
  88. }
  89. void
  90. i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
  91. {
  92. if ((dev_priv->pipestat[pipe] & mask) != 0) {
  93. u32 reg = PIPESTAT(pipe);
  94. dev_priv->pipestat[pipe] &= ~mask;
  95. I915_WRITE(reg, dev_priv->pipestat[pipe]);
  96. POSTING_READ(reg);
  97. }
  98. }
  99. /**
  100. * intel_enable_asle - enable ASLE interrupt for OpRegion
  101. */
  102. void intel_enable_asle(struct drm_device *dev)
  103. {
  104. drm_i915_private_t *dev_priv = dev->dev_private;
  105. unsigned long irqflags;
  106. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  107. if (HAS_PCH_SPLIT(dev))
  108. ironlake_enable_display_irq(dev_priv, DE_GSE);
  109. else {
  110. i915_enable_pipestat(dev_priv, 1,
  111. PIPE_LEGACY_BLC_EVENT_ENABLE);
  112. if (INTEL_INFO(dev)->gen >= 4)
  113. i915_enable_pipestat(dev_priv, 0,
  114. PIPE_LEGACY_BLC_EVENT_ENABLE);
  115. }
  116. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  117. }
  118. /**
  119. * i915_pipe_enabled - check if a pipe is enabled
  120. * @dev: DRM device
  121. * @pipe: pipe to check
  122. *
  123. * Reading certain registers when the pipe is disabled can hang the chip.
  124. * Use this routine to make sure the PLL is running and the pipe is active
  125. * before reading such registers if unsure.
  126. */
  127. static int
  128. i915_pipe_enabled(struct drm_device *dev, int pipe)
  129. {
  130. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  131. return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
  132. }
  133. /* Called from drm generic code, passed a 'crtc', which
  134. * we use as a pipe index
  135. */
  136. static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
  137. {
  138. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  139. unsigned long high_frame;
  140. unsigned long low_frame;
  141. u32 high1, high2, low;
  142. if (!i915_pipe_enabled(dev, pipe)) {
  143. DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
  144. "pipe %c\n", pipe_name(pipe));
  145. return 0;
  146. }
  147. high_frame = PIPEFRAME(pipe);
  148. low_frame = PIPEFRAMEPIXEL(pipe);
  149. /*
  150. * High & low register fields aren't synchronized, so make sure
  151. * we get a low value that's stable across two reads of the high
  152. * register.
  153. */
  154. do {
  155. high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
  156. low = I915_READ(low_frame) & PIPE_FRAME_LOW_MASK;
  157. high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
  158. } while (high1 != high2);
  159. high1 >>= PIPE_FRAME_HIGH_SHIFT;
  160. low >>= PIPE_FRAME_LOW_SHIFT;
  161. return (high1 << 8) | low;
  162. }
  163. static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
  164. {
  165. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  166. int reg = PIPE_FRMCOUNT_GM45(pipe);
  167. if (!i915_pipe_enabled(dev, pipe)) {
  168. DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
  169. "pipe %c\n", pipe_name(pipe));
  170. return 0;
  171. }
  172. return I915_READ(reg);
  173. }
  174. static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
  175. int *vpos, int *hpos)
  176. {
  177. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  178. u32 vbl = 0, position = 0;
  179. int vbl_start, vbl_end, htotal, vtotal;
  180. bool in_vbl = true;
  181. int ret = 0;
  182. if (!i915_pipe_enabled(dev, pipe)) {
  183. DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
  184. "pipe %c\n", pipe_name(pipe));
  185. return 0;
  186. }
  187. /* Get vtotal. */
  188. vtotal = 1 + ((I915_READ(VTOTAL(pipe)) >> 16) & 0x1fff);
  189. if (INTEL_INFO(dev)->gen >= 4) {
  190. /* No obvious pixelcount register. Only query vertical
  191. * scanout position from Display scan line register.
  192. */
  193. position = I915_READ(PIPEDSL(pipe));
  194. /* Decode into vertical scanout position. Don't have
  195. * horizontal scanout position.
  196. */
  197. *vpos = position & 0x1fff;
  198. *hpos = 0;
  199. } else {
  200. /* Have access to pixelcount since start of frame.
  201. * We can split this into vertical and horizontal
  202. * scanout position.
  203. */
  204. position = (I915_READ(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
  205. htotal = 1 + ((I915_READ(HTOTAL(pipe)) >> 16) & 0x1fff);
  206. *vpos = position / htotal;
  207. *hpos = position - (*vpos * htotal);
  208. }
  209. /* Query vblank area. */
  210. vbl = I915_READ(VBLANK(pipe));
  211. /* Test position against vblank region. */
  212. vbl_start = vbl & 0x1fff;
  213. vbl_end = (vbl >> 16) & 0x1fff;
  214. if ((*vpos < vbl_start) || (*vpos > vbl_end))
  215. in_vbl = false;
  216. /* Inside "upper part" of vblank area? Apply corrective offset: */
  217. if (in_vbl && (*vpos >= vbl_start))
  218. *vpos = *vpos - vtotal;
  219. /* Readouts valid? */
  220. if (vbl > 0)
  221. ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
  222. /* In vblank? */
  223. if (in_vbl)
  224. ret |= DRM_SCANOUTPOS_INVBL;
  225. return ret;
  226. }
  227. static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
  228. int *max_error,
  229. struct timeval *vblank_time,
  230. unsigned flags)
  231. {
  232. struct drm_i915_private *dev_priv = dev->dev_private;
  233. struct drm_crtc *crtc;
  234. if (pipe < 0 || pipe >= dev_priv->num_pipe) {
  235. DRM_ERROR("Invalid crtc %d\n", pipe);
  236. return -EINVAL;
  237. }
  238. /* Get drm_crtc to timestamp: */
  239. crtc = intel_get_crtc_for_pipe(dev, pipe);
  240. if (crtc == NULL) {
  241. DRM_ERROR("Invalid crtc %d\n", pipe);
  242. return -EINVAL;
  243. }
  244. if (!crtc->enabled) {
  245. DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
  246. return -EBUSY;
  247. }
  248. /* Helper routine in DRM core does all the work: */
  249. return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
  250. vblank_time, flags,
  251. crtc);
  252. }
  253. /*
  254. * Handle hotplug events outside the interrupt handler proper.
  255. */
  256. static void i915_hotplug_work_func(struct work_struct *work)
  257. {
  258. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  259. hotplug_work);
  260. struct drm_device *dev = dev_priv->dev;
  261. struct drm_mode_config *mode_config = &dev->mode_config;
  262. struct intel_encoder *encoder;
  263. mutex_lock(&mode_config->mutex);
  264. DRM_DEBUG_KMS("running encoder hotplug functions\n");
  265. list_for_each_entry(encoder, &mode_config->encoder_list, base.head)
  266. if (encoder->hot_plug)
  267. encoder->hot_plug(encoder);
  268. mutex_unlock(&mode_config->mutex);
  269. /* Just fire off a uevent and let userspace tell us what to do */
  270. drm_helper_hpd_irq_event(dev);
  271. }
  272. static void i915_handle_rps_change(struct drm_device *dev)
  273. {
  274. drm_i915_private_t *dev_priv = dev->dev_private;
  275. u32 busy_up, busy_down, max_avg, min_avg;
  276. u8 new_delay = dev_priv->cur_delay;
  277. I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
  278. busy_up = I915_READ(RCPREVBSYTUPAVG);
  279. busy_down = I915_READ(RCPREVBSYTDNAVG);
  280. max_avg = I915_READ(RCBMAXAVG);
  281. min_avg = I915_READ(RCBMINAVG);
  282. /* Handle RCS change request from hw */
  283. if (busy_up > max_avg) {
  284. if (dev_priv->cur_delay != dev_priv->max_delay)
  285. new_delay = dev_priv->cur_delay - 1;
  286. if (new_delay < dev_priv->max_delay)
  287. new_delay = dev_priv->max_delay;
  288. } else if (busy_down < min_avg) {
  289. if (dev_priv->cur_delay != dev_priv->min_delay)
  290. new_delay = dev_priv->cur_delay + 1;
  291. if (new_delay > dev_priv->min_delay)
  292. new_delay = dev_priv->min_delay;
  293. }
  294. if (ironlake_set_drps(dev, new_delay))
  295. dev_priv->cur_delay = new_delay;
  296. return;
  297. }
  298. static void notify_ring(struct drm_device *dev,
  299. struct intel_ring_buffer *ring)
  300. {
  301. struct drm_i915_private *dev_priv = dev->dev_private;
  302. u32 seqno;
  303. if (ring->obj == NULL)
  304. return;
  305. seqno = ring->get_seqno(ring);
  306. trace_i915_gem_request_complete(ring, seqno);
  307. ring->irq_seqno = seqno;
  308. wake_up_all(&ring->irq_queue);
  309. if (i915_enable_hangcheck) {
  310. dev_priv->hangcheck_count = 0;
  311. mod_timer(&dev_priv->hangcheck_timer,
  312. jiffies +
  313. msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD));
  314. }
  315. }
  316. static void gen6_pm_rps_work(struct work_struct *work)
  317. {
  318. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  319. rps_work);
  320. u8 new_delay = dev_priv->cur_delay;
  321. u32 pm_iir, pm_imr;
  322. spin_lock_irq(&dev_priv->rps_lock);
  323. pm_iir = dev_priv->pm_iir;
  324. dev_priv->pm_iir = 0;
  325. pm_imr = I915_READ(GEN6_PMIMR);
  326. I915_WRITE(GEN6_PMIMR, 0);
  327. spin_unlock_irq(&dev_priv->rps_lock);
  328. if (!pm_iir)
  329. return;
  330. mutex_lock(&dev_priv->dev->struct_mutex);
  331. if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
  332. if (dev_priv->cur_delay != dev_priv->max_delay)
  333. new_delay = dev_priv->cur_delay + 1;
  334. if (new_delay > dev_priv->max_delay)
  335. new_delay = dev_priv->max_delay;
  336. } else if (pm_iir & (GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT)) {
  337. gen6_gt_force_wake_get(dev_priv);
  338. if (dev_priv->cur_delay != dev_priv->min_delay)
  339. new_delay = dev_priv->cur_delay - 1;
  340. if (new_delay < dev_priv->min_delay) {
  341. new_delay = dev_priv->min_delay;
  342. I915_WRITE(GEN6_RP_INTERRUPT_LIMITS,
  343. I915_READ(GEN6_RP_INTERRUPT_LIMITS) |
  344. ((new_delay << 16) & 0x3f0000));
  345. } else {
  346. /* Make sure we continue to get down interrupts
  347. * until we hit the minimum frequency */
  348. I915_WRITE(GEN6_RP_INTERRUPT_LIMITS,
  349. I915_READ(GEN6_RP_INTERRUPT_LIMITS) & ~0x3f0000);
  350. }
  351. gen6_gt_force_wake_put(dev_priv);
  352. }
  353. gen6_set_rps(dev_priv->dev, new_delay);
  354. dev_priv->cur_delay = new_delay;
  355. /*
  356. * rps_lock not held here because clearing is non-destructive. There is
  357. * an *extremely* unlikely race with gen6_rps_enable() that is prevented
  358. * by holding struct_mutex for the duration of the write.
  359. */
  360. mutex_unlock(&dev_priv->dev->struct_mutex);
  361. }
  362. static void pch_irq_handler(struct drm_device *dev)
  363. {
  364. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  365. u32 pch_iir;
  366. int pipe;
  367. pch_iir = I915_READ(SDEIIR);
  368. if (pch_iir & SDE_AUDIO_POWER_MASK)
  369. DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
  370. (pch_iir & SDE_AUDIO_POWER_MASK) >>
  371. SDE_AUDIO_POWER_SHIFT);
  372. if (pch_iir & SDE_GMBUS)
  373. DRM_DEBUG_DRIVER("PCH GMBUS interrupt\n");
  374. if (pch_iir & SDE_AUDIO_HDCP_MASK)
  375. DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
  376. if (pch_iir & SDE_AUDIO_TRANS_MASK)
  377. DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
  378. if (pch_iir & SDE_POISON)
  379. DRM_ERROR("PCH poison interrupt\n");
  380. if (pch_iir & SDE_FDI_MASK)
  381. for_each_pipe(pipe)
  382. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  383. pipe_name(pipe),
  384. I915_READ(FDI_RX_IIR(pipe)));
  385. if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
  386. DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
  387. if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
  388. DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
  389. if (pch_iir & SDE_TRANSB_FIFO_UNDER)
  390. DRM_DEBUG_DRIVER("PCH transcoder B underrun interrupt\n");
  391. if (pch_iir & SDE_TRANSA_FIFO_UNDER)
  392. DRM_DEBUG_DRIVER("PCH transcoder A underrun interrupt\n");
  393. }
  394. static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
  395. {
  396. struct drm_device *dev = (struct drm_device *) arg;
  397. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  398. int ret = IRQ_NONE;
  399. u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
  400. struct drm_i915_master_private *master_priv;
  401. atomic_inc(&dev_priv->irq_received);
  402. /* disable master interrupt before clearing iir */
  403. de_ier = I915_READ(DEIER);
  404. I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  405. POSTING_READ(DEIER);
  406. de_iir = I915_READ(DEIIR);
  407. gt_iir = I915_READ(GTIIR);
  408. pch_iir = I915_READ(SDEIIR);
  409. pm_iir = I915_READ(GEN6_PMIIR);
  410. if (de_iir == 0 && gt_iir == 0 && pch_iir == 0 && pm_iir == 0)
  411. goto done;
  412. ret = IRQ_HANDLED;
  413. if (dev->primary->master) {
  414. master_priv = dev->primary->master->driver_priv;
  415. if (master_priv->sarea_priv)
  416. master_priv->sarea_priv->last_dispatch =
  417. READ_BREADCRUMB(dev_priv);
  418. }
  419. if (gt_iir & (GT_USER_INTERRUPT | GT_PIPE_NOTIFY))
  420. notify_ring(dev, &dev_priv->ring[RCS]);
  421. if (gt_iir & GT_GEN6_BSD_USER_INTERRUPT)
  422. notify_ring(dev, &dev_priv->ring[VCS]);
  423. if (gt_iir & GT_BLT_USER_INTERRUPT)
  424. notify_ring(dev, &dev_priv->ring[BCS]);
  425. if (de_iir & DE_GSE_IVB)
  426. intel_opregion_gse_intr(dev);
  427. if (de_iir & DE_PLANEA_FLIP_DONE_IVB) {
  428. intel_prepare_page_flip(dev, 0);
  429. intel_finish_page_flip_plane(dev, 0);
  430. }
  431. if (de_iir & DE_PLANEB_FLIP_DONE_IVB) {
  432. intel_prepare_page_flip(dev, 1);
  433. intel_finish_page_flip_plane(dev, 1);
  434. }
  435. if (de_iir & DE_PIPEA_VBLANK_IVB)
  436. drm_handle_vblank(dev, 0);
  437. if (de_iir & DE_PIPEB_VBLANK_IVB)
  438. drm_handle_vblank(dev, 1);
  439. /* check event from PCH */
  440. if (de_iir & DE_PCH_EVENT_IVB) {
  441. if (pch_iir & SDE_HOTPLUG_MASK_CPT)
  442. queue_work(dev_priv->wq, &dev_priv->hotplug_work);
  443. pch_irq_handler(dev);
  444. }
  445. if (pm_iir & GEN6_PM_DEFERRED_EVENTS) {
  446. unsigned long flags;
  447. spin_lock_irqsave(&dev_priv->rps_lock, flags);
  448. WARN(dev_priv->pm_iir & pm_iir, "Missed a PM interrupt\n");
  449. dev_priv->pm_iir |= pm_iir;
  450. I915_WRITE(GEN6_PMIMR, dev_priv->pm_iir);
  451. POSTING_READ(GEN6_PMIMR);
  452. spin_unlock_irqrestore(&dev_priv->rps_lock, flags);
  453. queue_work(dev_priv->wq, &dev_priv->rps_work);
  454. }
  455. /* should clear PCH hotplug event before clear CPU irq */
  456. I915_WRITE(SDEIIR, pch_iir);
  457. I915_WRITE(GTIIR, gt_iir);
  458. I915_WRITE(DEIIR, de_iir);
  459. I915_WRITE(GEN6_PMIIR, pm_iir);
  460. done:
  461. I915_WRITE(DEIER, de_ier);
  462. POSTING_READ(DEIER);
  463. return ret;
  464. }
  465. static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
  466. {
  467. struct drm_device *dev = (struct drm_device *) arg;
  468. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  469. int ret = IRQ_NONE;
  470. u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
  471. u32 hotplug_mask;
  472. struct drm_i915_master_private *master_priv;
  473. u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
  474. atomic_inc(&dev_priv->irq_received);
  475. if (IS_GEN6(dev))
  476. bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
  477. /* disable master interrupt before clearing iir */
  478. de_ier = I915_READ(DEIER);
  479. I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  480. POSTING_READ(DEIER);
  481. de_iir = I915_READ(DEIIR);
  482. gt_iir = I915_READ(GTIIR);
  483. pch_iir = I915_READ(SDEIIR);
  484. pm_iir = I915_READ(GEN6_PMIIR);
  485. if (de_iir == 0 && gt_iir == 0 && pch_iir == 0 &&
  486. (!IS_GEN6(dev) || pm_iir == 0))
  487. goto done;
  488. if (HAS_PCH_CPT(dev))
  489. hotplug_mask = SDE_HOTPLUG_MASK_CPT;
  490. else
  491. hotplug_mask = SDE_HOTPLUG_MASK;
  492. ret = IRQ_HANDLED;
  493. if (dev->primary->master) {
  494. master_priv = dev->primary->master->driver_priv;
  495. if (master_priv->sarea_priv)
  496. master_priv->sarea_priv->last_dispatch =
  497. READ_BREADCRUMB(dev_priv);
  498. }
  499. if (gt_iir & (GT_USER_INTERRUPT | GT_PIPE_NOTIFY))
  500. notify_ring(dev, &dev_priv->ring[RCS]);
  501. if (gt_iir & bsd_usr_interrupt)
  502. notify_ring(dev, &dev_priv->ring[VCS]);
  503. if (gt_iir & GT_BLT_USER_INTERRUPT)
  504. notify_ring(dev, &dev_priv->ring[BCS]);
  505. if (de_iir & DE_GSE)
  506. intel_opregion_gse_intr(dev);
  507. if (de_iir & DE_PLANEA_FLIP_DONE) {
  508. intel_prepare_page_flip(dev, 0);
  509. intel_finish_page_flip_plane(dev, 0);
  510. }
  511. if (de_iir & DE_PLANEB_FLIP_DONE) {
  512. intel_prepare_page_flip(dev, 1);
  513. intel_finish_page_flip_plane(dev, 1);
  514. }
  515. if (de_iir & DE_PIPEA_VBLANK)
  516. drm_handle_vblank(dev, 0);
  517. if (de_iir & DE_PIPEB_VBLANK)
  518. drm_handle_vblank(dev, 1);
  519. /* check event from PCH */
  520. if (de_iir & DE_PCH_EVENT) {
  521. if (pch_iir & hotplug_mask)
  522. queue_work(dev_priv->wq, &dev_priv->hotplug_work);
  523. pch_irq_handler(dev);
  524. }
  525. if (de_iir & DE_PCU_EVENT) {
  526. I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
  527. i915_handle_rps_change(dev);
  528. }
  529. if (IS_GEN6(dev) && pm_iir & GEN6_PM_DEFERRED_EVENTS) {
  530. /*
  531. * IIR bits should never already be set because IMR should
  532. * prevent an interrupt from being shown in IIR. The warning
  533. * displays a case where we've unsafely cleared
  534. * dev_priv->pm_iir. Although missing an interrupt of the same
  535. * type is not a problem, it displays a problem in the logic.
  536. *
  537. * The mask bit in IMR is cleared by rps_work.
  538. */
  539. unsigned long flags;
  540. spin_lock_irqsave(&dev_priv->rps_lock, flags);
  541. WARN(dev_priv->pm_iir & pm_iir, "Missed a PM interrupt\n");
  542. dev_priv->pm_iir |= pm_iir;
  543. I915_WRITE(GEN6_PMIMR, dev_priv->pm_iir);
  544. POSTING_READ(GEN6_PMIMR);
  545. spin_unlock_irqrestore(&dev_priv->rps_lock, flags);
  546. queue_work(dev_priv->wq, &dev_priv->rps_work);
  547. }
  548. /* should clear PCH hotplug event before clear CPU irq */
  549. I915_WRITE(SDEIIR, pch_iir);
  550. I915_WRITE(GTIIR, gt_iir);
  551. I915_WRITE(DEIIR, de_iir);
  552. I915_WRITE(GEN6_PMIIR, pm_iir);
  553. done:
  554. I915_WRITE(DEIER, de_ier);
  555. POSTING_READ(DEIER);
  556. return ret;
  557. }
  558. /**
  559. * i915_error_work_func - do process context error handling work
  560. * @work: work struct
  561. *
  562. * Fire an error uevent so userspace can see that a hang or error
  563. * was detected.
  564. */
  565. static void i915_error_work_func(struct work_struct *work)
  566. {
  567. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  568. error_work);
  569. struct drm_device *dev = dev_priv->dev;
  570. char *error_event[] = { "ERROR=1", NULL };
  571. char *reset_event[] = { "RESET=1", NULL };
  572. char *reset_done_event[] = { "ERROR=0", NULL };
  573. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
  574. if (atomic_read(&dev_priv->mm.wedged)) {
  575. DRM_DEBUG_DRIVER("resetting chip\n");
  576. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_event);
  577. if (!i915_reset(dev, GRDOM_RENDER)) {
  578. atomic_set(&dev_priv->mm.wedged, 0);
  579. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_done_event);
  580. }
  581. complete_all(&dev_priv->error_completion);
  582. }
  583. }
  584. #ifdef CONFIG_DEBUG_FS
  585. static struct drm_i915_error_object *
  586. i915_error_object_create(struct drm_i915_private *dev_priv,
  587. struct drm_i915_gem_object *src)
  588. {
  589. struct drm_i915_error_object *dst;
  590. int page, page_count;
  591. u32 reloc_offset;
  592. if (src == NULL || src->pages == NULL)
  593. return NULL;
  594. page_count = src->base.size / PAGE_SIZE;
  595. dst = kmalloc(sizeof(*dst) + page_count * sizeof(u32 *), GFP_ATOMIC);
  596. if (dst == NULL)
  597. return NULL;
  598. reloc_offset = src->gtt_offset;
  599. for (page = 0; page < page_count; page++) {
  600. unsigned long flags;
  601. void *d;
  602. d = kmalloc(PAGE_SIZE, GFP_ATOMIC);
  603. if (d == NULL)
  604. goto unwind;
  605. local_irq_save(flags);
  606. if (reloc_offset < dev_priv->mm.gtt_mappable_end) {
  607. void __iomem *s;
  608. /* Simply ignore tiling or any overlapping fence.
  609. * It's part of the error state, and this hopefully
  610. * captures what the GPU read.
  611. */
  612. s = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping,
  613. reloc_offset);
  614. memcpy_fromio(d, s, PAGE_SIZE);
  615. io_mapping_unmap_atomic(s);
  616. } else {
  617. void *s;
  618. drm_clflush_pages(&src->pages[page], 1);
  619. s = kmap_atomic(src->pages[page]);
  620. memcpy(d, s, PAGE_SIZE);
  621. kunmap_atomic(s);
  622. drm_clflush_pages(&src->pages[page], 1);
  623. }
  624. local_irq_restore(flags);
  625. dst->pages[page] = d;
  626. reloc_offset += PAGE_SIZE;
  627. }
  628. dst->page_count = page_count;
  629. dst->gtt_offset = src->gtt_offset;
  630. return dst;
  631. unwind:
  632. while (page--)
  633. kfree(dst->pages[page]);
  634. kfree(dst);
  635. return NULL;
  636. }
  637. static void
  638. i915_error_object_free(struct drm_i915_error_object *obj)
  639. {
  640. int page;
  641. if (obj == NULL)
  642. return;
  643. for (page = 0; page < obj->page_count; page++)
  644. kfree(obj->pages[page]);
  645. kfree(obj);
  646. }
  647. static void
  648. i915_error_state_free(struct drm_device *dev,
  649. struct drm_i915_error_state *error)
  650. {
  651. int i;
  652. for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
  653. i915_error_object_free(error->ring[i].batchbuffer);
  654. i915_error_object_free(error->ring[i].ringbuffer);
  655. kfree(error->ring[i].requests);
  656. }
  657. kfree(error->active_bo);
  658. kfree(error->overlay);
  659. kfree(error);
  660. }
  661. static u32 capture_bo_list(struct drm_i915_error_buffer *err,
  662. int count,
  663. struct list_head *head)
  664. {
  665. struct drm_i915_gem_object *obj;
  666. int i = 0;
  667. list_for_each_entry(obj, head, mm_list) {
  668. err->size = obj->base.size;
  669. err->name = obj->base.name;
  670. err->seqno = obj->last_rendering_seqno;
  671. err->gtt_offset = obj->gtt_offset;
  672. err->read_domains = obj->base.read_domains;
  673. err->write_domain = obj->base.write_domain;
  674. err->fence_reg = obj->fence_reg;
  675. err->pinned = 0;
  676. if (obj->pin_count > 0)
  677. err->pinned = 1;
  678. if (obj->user_pin_count > 0)
  679. err->pinned = -1;
  680. err->tiling = obj->tiling_mode;
  681. err->dirty = obj->dirty;
  682. err->purgeable = obj->madv != I915_MADV_WILLNEED;
  683. err->ring = obj->ring ? obj->ring->id : -1;
  684. err->cache_level = obj->cache_level;
  685. if (++i == count)
  686. break;
  687. err++;
  688. }
  689. return i;
  690. }
  691. static void i915_gem_record_fences(struct drm_device *dev,
  692. struct drm_i915_error_state *error)
  693. {
  694. struct drm_i915_private *dev_priv = dev->dev_private;
  695. int i;
  696. /* Fences */
  697. switch (INTEL_INFO(dev)->gen) {
  698. case 7:
  699. case 6:
  700. for (i = 0; i < 16; i++)
  701. error->fence[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8));
  702. break;
  703. case 5:
  704. case 4:
  705. for (i = 0; i < 16; i++)
  706. error->fence[i] = I915_READ64(FENCE_REG_965_0 + (i * 8));
  707. break;
  708. case 3:
  709. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
  710. for (i = 0; i < 8; i++)
  711. error->fence[i+8] = I915_READ(FENCE_REG_945_8 + (i * 4));
  712. case 2:
  713. for (i = 0; i < 8; i++)
  714. error->fence[i] = I915_READ(FENCE_REG_830_0 + (i * 4));
  715. break;
  716. }
  717. }
  718. static struct drm_i915_error_object *
  719. i915_error_first_batchbuffer(struct drm_i915_private *dev_priv,
  720. struct intel_ring_buffer *ring)
  721. {
  722. struct drm_i915_gem_object *obj;
  723. u32 seqno;
  724. if (!ring->get_seqno)
  725. return NULL;
  726. seqno = ring->get_seqno(ring);
  727. list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list) {
  728. if (obj->ring != ring)
  729. continue;
  730. if (i915_seqno_passed(seqno, obj->last_rendering_seqno))
  731. continue;
  732. if ((obj->base.read_domains & I915_GEM_DOMAIN_COMMAND) == 0)
  733. continue;
  734. /* We need to copy these to an anonymous buffer as the simplest
  735. * method to avoid being overwritten by userspace.
  736. */
  737. return i915_error_object_create(dev_priv, obj);
  738. }
  739. return NULL;
  740. }
  741. static void i915_record_ring_state(struct drm_device *dev,
  742. struct drm_i915_error_state *error,
  743. struct intel_ring_buffer *ring)
  744. {
  745. struct drm_i915_private *dev_priv = dev->dev_private;
  746. if (INTEL_INFO(dev)->gen >= 6) {
  747. error->faddr[ring->id] = I915_READ(RING_DMA_FADD(ring->mmio_base));
  748. error->fault_reg[ring->id] = I915_READ(RING_FAULT_REG(ring));
  749. error->semaphore_mboxes[ring->id][0]
  750. = I915_READ(RING_SYNC_0(ring->mmio_base));
  751. error->semaphore_mboxes[ring->id][1]
  752. = I915_READ(RING_SYNC_1(ring->mmio_base));
  753. }
  754. if (INTEL_INFO(dev)->gen >= 4) {
  755. error->ipeir[ring->id] = I915_READ(RING_IPEIR(ring->mmio_base));
  756. error->ipehr[ring->id] = I915_READ(RING_IPEHR(ring->mmio_base));
  757. error->instdone[ring->id] = I915_READ(RING_INSTDONE(ring->mmio_base));
  758. error->instps[ring->id] = I915_READ(RING_INSTPS(ring->mmio_base));
  759. if (ring->id == RCS) {
  760. error->instdone1 = I915_READ(INSTDONE1);
  761. error->bbaddr = I915_READ64(BB_ADDR);
  762. }
  763. } else {
  764. error->ipeir[ring->id] = I915_READ(IPEIR);
  765. error->ipehr[ring->id] = I915_READ(IPEHR);
  766. error->instdone[ring->id] = I915_READ(INSTDONE);
  767. }
  768. error->instpm[ring->id] = I915_READ(RING_INSTPM(ring->mmio_base));
  769. error->seqno[ring->id] = ring->get_seqno(ring);
  770. error->acthd[ring->id] = intel_ring_get_active_head(ring);
  771. error->head[ring->id] = I915_READ_HEAD(ring);
  772. error->tail[ring->id] = I915_READ_TAIL(ring);
  773. error->cpu_ring_head[ring->id] = ring->head;
  774. error->cpu_ring_tail[ring->id] = ring->tail;
  775. }
  776. static void i915_gem_record_rings(struct drm_device *dev,
  777. struct drm_i915_error_state *error)
  778. {
  779. struct drm_i915_private *dev_priv = dev->dev_private;
  780. struct drm_i915_gem_request *request;
  781. int i, count;
  782. for (i = 0; i < I915_NUM_RINGS; i++) {
  783. struct intel_ring_buffer *ring = &dev_priv->ring[i];
  784. if (ring->obj == NULL)
  785. continue;
  786. i915_record_ring_state(dev, error, ring);
  787. error->ring[i].batchbuffer =
  788. i915_error_first_batchbuffer(dev_priv, ring);
  789. error->ring[i].ringbuffer =
  790. i915_error_object_create(dev_priv, ring->obj);
  791. count = 0;
  792. list_for_each_entry(request, &ring->request_list, list)
  793. count++;
  794. error->ring[i].num_requests = count;
  795. error->ring[i].requests =
  796. kmalloc(count*sizeof(struct drm_i915_error_request),
  797. GFP_ATOMIC);
  798. if (error->ring[i].requests == NULL) {
  799. error->ring[i].num_requests = 0;
  800. continue;
  801. }
  802. count = 0;
  803. list_for_each_entry(request, &ring->request_list, list) {
  804. struct drm_i915_error_request *erq;
  805. erq = &error->ring[i].requests[count++];
  806. erq->seqno = request->seqno;
  807. erq->jiffies = request->emitted_jiffies;
  808. erq->tail = request->tail;
  809. }
  810. }
  811. }
  812. /**
  813. * i915_capture_error_state - capture an error record for later analysis
  814. * @dev: drm device
  815. *
  816. * Should be called when an error is detected (either a hang or an error
  817. * interrupt) to capture error state from the time of the error. Fills
  818. * out a structure which becomes available in debugfs for user level tools
  819. * to pick up.
  820. */
  821. static void i915_capture_error_state(struct drm_device *dev)
  822. {
  823. struct drm_i915_private *dev_priv = dev->dev_private;
  824. struct drm_i915_gem_object *obj;
  825. struct drm_i915_error_state *error;
  826. unsigned long flags;
  827. int i, pipe;
  828. spin_lock_irqsave(&dev_priv->error_lock, flags);
  829. error = dev_priv->first_error;
  830. spin_unlock_irqrestore(&dev_priv->error_lock, flags);
  831. if (error)
  832. return;
  833. /* Account for pipe specific data like PIPE*STAT */
  834. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  835. if (!error) {
  836. DRM_DEBUG_DRIVER("out of memory, not capturing error state\n");
  837. return;
  838. }
  839. DRM_INFO("capturing error event; look for more information in /debug/dri/%d/i915_error_state\n",
  840. dev->primary->index);
  841. error->eir = I915_READ(EIR);
  842. error->pgtbl_er = I915_READ(PGTBL_ER);
  843. for_each_pipe(pipe)
  844. error->pipestat[pipe] = I915_READ(PIPESTAT(pipe));
  845. if (INTEL_INFO(dev)->gen >= 6) {
  846. error->error = I915_READ(ERROR_GEN6);
  847. error->done_reg = I915_READ(DONE_REG);
  848. }
  849. i915_gem_record_fences(dev, error);
  850. i915_gem_record_rings(dev, error);
  851. /* Record buffers on the active and pinned lists. */
  852. error->active_bo = NULL;
  853. error->pinned_bo = NULL;
  854. i = 0;
  855. list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list)
  856. i++;
  857. error->active_bo_count = i;
  858. list_for_each_entry(obj, &dev_priv->mm.pinned_list, mm_list)
  859. i++;
  860. error->pinned_bo_count = i - error->active_bo_count;
  861. error->active_bo = NULL;
  862. error->pinned_bo = NULL;
  863. if (i) {
  864. error->active_bo = kmalloc(sizeof(*error->active_bo)*i,
  865. GFP_ATOMIC);
  866. if (error->active_bo)
  867. error->pinned_bo =
  868. error->active_bo + error->active_bo_count;
  869. }
  870. if (error->active_bo)
  871. error->active_bo_count =
  872. capture_bo_list(error->active_bo,
  873. error->active_bo_count,
  874. &dev_priv->mm.active_list);
  875. if (error->pinned_bo)
  876. error->pinned_bo_count =
  877. capture_bo_list(error->pinned_bo,
  878. error->pinned_bo_count,
  879. &dev_priv->mm.pinned_list);
  880. do_gettimeofday(&error->time);
  881. error->overlay = intel_overlay_capture_error_state(dev);
  882. error->display = intel_display_capture_error_state(dev);
  883. spin_lock_irqsave(&dev_priv->error_lock, flags);
  884. if (dev_priv->first_error == NULL) {
  885. dev_priv->first_error = error;
  886. error = NULL;
  887. }
  888. spin_unlock_irqrestore(&dev_priv->error_lock, flags);
  889. if (error)
  890. i915_error_state_free(dev, error);
  891. }
  892. void i915_destroy_error_state(struct drm_device *dev)
  893. {
  894. struct drm_i915_private *dev_priv = dev->dev_private;
  895. struct drm_i915_error_state *error;
  896. unsigned long flags;
  897. spin_lock_irqsave(&dev_priv->error_lock, flags);
  898. error = dev_priv->first_error;
  899. dev_priv->first_error = NULL;
  900. spin_unlock_irqrestore(&dev_priv->error_lock, flags);
  901. if (error)
  902. i915_error_state_free(dev, error);
  903. }
  904. #else
  905. #define i915_capture_error_state(x)
  906. #endif
  907. static void i915_report_and_clear_eir(struct drm_device *dev)
  908. {
  909. struct drm_i915_private *dev_priv = dev->dev_private;
  910. u32 eir = I915_READ(EIR);
  911. int pipe;
  912. if (!eir)
  913. return;
  914. printk(KERN_ERR "render error detected, EIR: 0x%08x\n",
  915. eir);
  916. if (IS_G4X(dev)) {
  917. if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
  918. u32 ipeir = I915_READ(IPEIR_I965);
  919. printk(KERN_ERR " IPEIR: 0x%08x\n",
  920. I915_READ(IPEIR_I965));
  921. printk(KERN_ERR " IPEHR: 0x%08x\n",
  922. I915_READ(IPEHR_I965));
  923. printk(KERN_ERR " INSTDONE: 0x%08x\n",
  924. I915_READ(INSTDONE_I965));
  925. printk(KERN_ERR " INSTPS: 0x%08x\n",
  926. I915_READ(INSTPS));
  927. printk(KERN_ERR " INSTDONE1: 0x%08x\n",
  928. I915_READ(INSTDONE1));
  929. printk(KERN_ERR " ACTHD: 0x%08x\n",
  930. I915_READ(ACTHD_I965));
  931. I915_WRITE(IPEIR_I965, ipeir);
  932. POSTING_READ(IPEIR_I965);
  933. }
  934. if (eir & GM45_ERROR_PAGE_TABLE) {
  935. u32 pgtbl_err = I915_READ(PGTBL_ER);
  936. printk(KERN_ERR "page table error\n");
  937. printk(KERN_ERR " PGTBL_ER: 0x%08x\n",
  938. pgtbl_err);
  939. I915_WRITE(PGTBL_ER, pgtbl_err);
  940. POSTING_READ(PGTBL_ER);
  941. }
  942. }
  943. if (!IS_GEN2(dev)) {
  944. if (eir & I915_ERROR_PAGE_TABLE) {
  945. u32 pgtbl_err = I915_READ(PGTBL_ER);
  946. printk(KERN_ERR "page table error\n");
  947. printk(KERN_ERR " PGTBL_ER: 0x%08x\n",
  948. pgtbl_err);
  949. I915_WRITE(PGTBL_ER, pgtbl_err);
  950. POSTING_READ(PGTBL_ER);
  951. }
  952. }
  953. if (eir & I915_ERROR_MEMORY_REFRESH) {
  954. printk(KERN_ERR "memory refresh error:\n");
  955. for_each_pipe(pipe)
  956. printk(KERN_ERR "pipe %c stat: 0x%08x\n",
  957. pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
  958. /* pipestat has already been acked */
  959. }
  960. if (eir & I915_ERROR_INSTRUCTION) {
  961. printk(KERN_ERR "instruction error\n");
  962. printk(KERN_ERR " INSTPM: 0x%08x\n",
  963. I915_READ(INSTPM));
  964. if (INTEL_INFO(dev)->gen < 4) {
  965. u32 ipeir = I915_READ(IPEIR);
  966. printk(KERN_ERR " IPEIR: 0x%08x\n",
  967. I915_READ(IPEIR));
  968. printk(KERN_ERR " IPEHR: 0x%08x\n",
  969. I915_READ(IPEHR));
  970. printk(KERN_ERR " INSTDONE: 0x%08x\n",
  971. I915_READ(INSTDONE));
  972. printk(KERN_ERR " ACTHD: 0x%08x\n",
  973. I915_READ(ACTHD));
  974. I915_WRITE(IPEIR, ipeir);
  975. POSTING_READ(IPEIR);
  976. } else {
  977. u32 ipeir = I915_READ(IPEIR_I965);
  978. printk(KERN_ERR " IPEIR: 0x%08x\n",
  979. I915_READ(IPEIR_I965));
  980. printk(KERN_ERR " IPEHR: 0x%08x\n",
  981. I915_READ(IPEHR_I965));
  982. printk(KERN_ERR " INSTDONE: 0x%08x\n",
  983. I915_READ(INSTDONE_I965));
  984. printk(KERN_ERR " INSTPS: 0x%08x\n",
  985. I915_READ(INSTPS));
  986. printk(KERN_ERR " INSTDONE1: 0x%08x\n",
  987. I915_READ(INSTDONE1));
  988. printk(KERN_ERR " ACTHD: 0x%08x\n",
  989. I915_READ(ACTHD_I965));
  990. I915_WRITE(IPEIR_I965, ipeir);
  991. POSTING_READ(IPEIR_I965);
  992. }
  993. }
  994. I915_WRITE(EIR, eir);
  995. POSTING_READ(EIR);
  996. eir = I915_READ(EIR);
  997. if (eir) {
  998. /*
  999. * some errors might have become stuck,
  1000. * mask them.
  1001. */
  1002. DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
  1003. I915_WRITE(EMR, I915_READ(EMR) | eir);
  1004. I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  1005. }
  1006. }
  1007. /**
  1008. * i915_handle_error - handle an error interrupt
  1009. * @dev: drm device
  1010. *
  1011. * Do some basic checking of regsiter state at error interrupt time and
  1012. * dump it to the syslog. Also call i915_capture_error_state() to make
  1013. * sure we get a record and make it available in debugfs. Fire a uevent
  1014. * so userspace knows something bad happened (should trigger collection
  1015. * of a ring dump etc.).
  1016. */
  1017. void i915_handle_error(struct drm_device *dev, bool wedged)
  1018. {
  1019. struct drm_i915_private *dev_priv = dev->dev_private;
  1020. i915_capture_error_state(dev);
  1021. i915_report_and_clear_eir(dev);
  1022. if (wedged) {
  1023. INIT_COMPLETION(dev_priv->error_completion);
  1024. atomic_set(&dev_priv->mm.wedged, 1);
  1025. /*
  1026. * Wakeup waiting processes so they don't hang
  1027. */
  1028. wake_up_all(&dev_priv->ring[RCS].irq_queue);
  1029. if (HAS_BSD(dev))
  1030. wake_up_all(&dev_priv->ring[VCS].irq_queue);
  1031. if (HAS_BLT(dev))
  1032. wake_up_all(&dev_priv->ring[BCS].irq_queue);
  1033. }
  1034. queue_work(dev_priv->wq, &dev_priv->error_work);
  1035. }
  1036. static void i915_pageflip_stall_check(struct drm_device *dev, int pipe)
  1037. {
  1038. drm_i915_private_t *dev_priv = dev->dev_private;
  1039. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1040. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1041. struct drm_i915_gem_object *obj;
  1042. struct intel_unpin_work *work;
  1043. unsigned long flags;
  1044. bool stall_detected;
  1045. /* Ignore early vblank irqs */
  1046. if (intel_crtc == NULL)
  1047. return;
  1048. spin_lock_irqsave(&dev->event_lock, flags);
  1049. work = intel_crtc->unpin_work;
  1050. if (work == NULL || work->pending || !work->enable_stall_check) {
  1051. /* Either the pending flip IRQ arrived, or we're too early. Don't check */
  1052. spin_unlock_irqrestore(&dev->event_lock, flags);
  1053. return;
  1054. }
  1055. /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
  1056. obj = work->pending_flip_obj;
  1057. if (INTEL_INFO(dev)->gen >= 4) {
  1058. int dspsurf = DSPSURF(intel_crtc->plane);
  1059. stall_detected = I915_READ(dspsurf) == obj->gtt_offset;
  1060. } else {
  1061. int dspaddr = DSPADDR(intel_crtc->plane);
  1062. stall_detected = I915_READ(dspaddr) == (obj->gtt_offset +
  1063. crtc->y * crtc->fb->pitches[0] +
  1064. crtc->x * crtc->fb->bits_per_pixel/8);
  1065. }
  1066. spin_unlock_irqrestore(&dev->event_lock, flags);
  1067. if (stall_detected) {
  1068. DRM_DEBUG_DRIVER("Pageflip stall detected\n");
  1069. intel_prepare_page_flip(dev, intel_crtc->plane);
  1070. }
  1071. }
  1072. static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
  1073. {
  1074. struct drm_device *dev = (struct drm_device *) arg;
  1075. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1076. struct drm_i915_master_private *master_priv;
  1077. u32 iir, new_iir;
  1078. u32 pipe_stats[I915_MAX_PIPES];
  1079. u32 vblank_status;
  1080. int vblank = 0;
  1081. unsigned long irqflags;
  1082. int irq_received;
  1083. int ret = IRQ_NONE, pipe;
  1084. bool blc_event = false;
  1085. atomic_inc(&dev_priv->irq_received);
  1086. iir = I915_READ(IIR);
  1087. if (INTEL_INFO(dev)->gen >= 4)
  1088. vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS;
  1089. else
  1090. vblank_status = PIPE_VBLANK_INTERRUPT_STATUS;
  1091. for (;;) {
  1092. irq_received = iir != 0;
  1093. /* Can't rely on pipestat interrupt bit in iir as it might
  1094. * have been cleared after the pipestat interrupt was received.
  1095. * It doesn't set the bit in iir again, but it still produces
  1096. * interrupts (for non-MSI).
  1097. */
  1098. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1099. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  1100. i915_handle_error(dev, false);
  1101. for_each_pipe(pipe) {
  1102. int reg = PIPESTAT(pipe);
  1103. pipe_stats[pipe] = I915_READ(reg);
  1104. /*
  1105. * Clear the PIPE*STAT regs before the IIR
  1106. */
  1107. if (pipe_stats[pipe] & 0x8000ffff) {
  1108. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  1109. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  1110. pipe_name(pipe));
  1111. I915_WRITE(reg, pipe_stats[pipe]);
  1112. irq_received = 1;
  1113. }
  1114. }
  1115. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1116. if (!irq_received)
  1117. break;
  1118. ret = IRQ_HANDLED;
  1119. /* Consume port. Then clear IIR or we'll miss events */
  1120. if ((I915_HAS_HOTPLUG(dev)) &&
  1121. (iir & I915_DISPLAY_PORT_INTERRUPT)) {
  1122. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  1123. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  1124. hotplug_status);
  1125. if (hotplug_status & dev_priv->hotplug_supported_mask)
  1126. queue_work(dev_priv->wq,
  1127. &dev_priv->hotplug_work);
  1128. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  1129. I915_READ(PORT_HOTPLUG_STAT);
  1130. }
  1131. I915_WRITE(IIR, iir);
  1132. new_iir = I915_READ(IIR); /* Flush posted writes */
  1133. if (dev->primary->master) {
  1134. master_priv = dev->primary->master->driver_priv;
  1135. if (master_priv->sarea_priv)
  1136. master_priv->sarea_priv->last_dispatch =
  1137. READ_BREADCRUMB(dev_priv);
  1138. }
  1139. if (iir & I915_USER_INTERRUPT)
  1140. notify_ring(dev, &dev_priv->ring[RCS]);
  1141. if (iir & I915_BSD_USER_INTERRUPT)
  1142. notify_ring(dev, &dev_priv->ring[VCS]);
  1143. if (iir & I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT) {
  1144. intel_prepare_page_flip(dev, 0);
  1145. if (dev_priv->flip_pending_is_done)
  1146. intel_finish_page_flip_plane(dev, 0);
  1147. }
  1148. if (iir & I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT) {
  1149. intel_prepare_page_flip(dev, 1);
  1150. if (dev_priv->flip_pending_is_done)
  1151. intel_finish_page_flip_plane(dev, 1);
  1152. }
  1153. for_each_pipe(pipe) {
  1154. if (pipe_stats[pipe] & vblank_status &&
  1155. drm_handle_vblank(dev, pipe)) {
  1156. vblank++;
  1157. if (!dev_priv->flip_pending_is_done) {
  1158. i915_pageflip_stall_check(dev, pipe);
  1159. intel_finish_page_flip(dev, pipe);
  1160. }
  1161. }
  1162. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  1163. blc_event = true;
  1164. }
  1165. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  1166. intel_opregion_asle_intr(dev);
  1167. /* With MSI, interrupts are only generated when iir
  1168. * transitions from zero to nonzero. If another bit got
  1169. * set while we were handling the existing iir bits, then
  1170. * we would never get another interrupt.
  1171. *
  1172. * This is fine on non-MSI as well, as if we hit this path
  1173. * we avoid exiting the interrupt handler only to generate
  1174. * another one.
  1175. *
  1176. * Note that for MSI this could cause a stray interrupt report
  1177. * if an interrupt landed in the time between writing IIR and
  1178. * the posting read. This should be rare enough to never
  1179. * trigger the 99% of 100,000 interrupts test for disabling
  1180. * stray interrupts.
  1181. */
  1182. iir = new_iir;
  1183. }
  1184. return ret;
  1185. }
  1186. static int i915_emit_irq(struct drm_device * dev)
  1187. {
  1188. drm_i915_private_t *dev_priv = dev->dev_private;
  1189. struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
  1190. i915_kernel_lost_context(dev);
  1191. DRM_DEBUG_DRIVER("\n");
  1192. dev_priv->counter++;
  1193. if (dev_priv->counter > 0x7FFFFFFFUL)
  1194. dev_priv->counter = 1;
  1195. if (master_priv->sarea_priv)
  1196. master_priv->sarea_priv->last_enqueue = dev_priv->counter;
  1197. if (BEGIN_LP_RING(4) == 0) {
  1198. OUT_RING(MI_STORE_DWORD_INDEX);
  1199. OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT);
  1200. OUT_RING(dev_priv->counter);
  1201. OUT_RING(MI_USER_INTERRUPT);
  1202. ADVANCE_LP_RING();
  1203. }
  1204. return dev_priv->counter;
  1205. }
  1206. static int i915_wait_irq(struct drm_device * dev, int irq_nr)
  1207. {
  1208. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1209. struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
  1210. int ret = 0;
  1211. struct intel_ring_buffer *ring = LP_RING(dev_priv);
  1212. DRM_DEBUG_DRIVER("irq_nr=%d breadcrumb=%d\n", irq_nr,
  1213. READ_BREADCRUMB(dev_priv));
  1214. if (READ_BREADCRUMB(dev_priv) >= irq_nr) {
  1215. if (master_priv->sarea_priv)
  1216. master_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
  1217. return 0;
  1218. }
  1219. if (master_priv->sarea_priv)
  1220. master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
  1221. if (ring->irq_get(ring)) {
  1222. DRM_WAIT_ON(ret, ring->irq_queue, 3 * DRM_HZ,
  1223. READ_BREADCRUMB(dev_priv) >= irq_nr);
  1224. ring->irq_put(ring);
  1225. } else if (wait_for(READ_BREADCRUMB(dev_priv) >= irq_nr, 3000))
  1226. ret = -EBUSY;
  1227. if (ret == -EBUSY) {
  1228. DRM_ERROR("EBUSY -- rec: %d emitted: %d\n",
  1229. READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
  1230. }
  1231. return ret;
  1232. }
  1233. /* Needs the lock as it touches the ring.
  1234. */
  1235. int i915_irq_emit(struct drm_device *dev, void *data,
  1236. struct drm_file *file_priv)
  1237. {
  1238. drm_i915_private_t *dev_priv = dev->dev_private;
  1239. drm_i915_irq_emit_t *emit = data;
  1240. int result;
  1241. if (!dev_priv || !LP_RING(dev_priv)->virtual_start) {
  1242. DRM_ERROR("called with no initialization\n");
  1243. return -EINVAL;
  1244. }
  1245. RING_LOCK_TEST_WITH_RETURN(dev, file_priv);
  1246. mutex_lock(&dev->struct_mutex);
  1247. result = i915_emit_irq(dev);
  1248. mutex_unlock(&dev->struct_mutex);
  1249. if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) {
  1250. DRM_ERROR("copy_to_user\n");
  1251. return -EFAULT;
  1252. }
  1253. return 0;
  1254. }
  1255. /* Doesn't need the hardware lock.
  1256. */
  1257. int i915_irq_wait(struct drm_device *dev, void *data,
  1258. struct drm_file *file_priv)
  1259. {
  1260. drm_i915_private_t *dev_priv = dev->dev_private;
  1261. drm_i915_irq_wait_t *irqwait = data;
  1262. if (!dev_priv) {
  1263. DRM_ERROR("called with no initialization\n");
  1264. return -EINVAL;
  1265. }
  1266. return i915_wait_irq(dev, irqwait->irq_seq);
  1267. }
  1268. /* Called from drm generic code, passed 'crtc' which
  1269. * we use as a pipe index
  1270. */
  1271. static int i915_enable_vblank(struct drm_device *dev, int pipe)
  1272. {
  1273. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1274. unsigned long irqflags;
  1275. if (!i915_pipe_enabled(dev, pipe))
  1276. return -EINVAL;
  1277. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1278. if (INTEL_INFO(dev)->gen >= 4)
  1279. i915_enable_pipestat(dev_priv, pipe,
  1280. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1281. else
  1282. i915_enable_pipestat(dev_priv, pipe,
  1283. PIPE_VBLANK_INTERRUPT_ENABLE);
  1284. /* maintain vblank delivery even in deep C-states */
  1285. if (dev_priv->info->gen == 3)
  1286. I915_WRITE(INSTPM, INSTPM_AGPBUSY_DIS << 16);
  1287. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1288. return 0;
  1289. }
  1290. static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
  1291. {
  1292. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1293. unsigned long irqflags;
  1294. if (!i915_pipe_enabled(dev, pipe))
  1295. return -EINVAL;
  1296. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1297. ironlake_enable_display_irq(dev_priv, (pipe == 0) ?
  1298. DE_PIPEA_VBLANK : DE_PIPEB_VBLANK);
  1299. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1300. return 0;
  1301. }
  1302. static int ivybridge_enable_vblank(struct drm_device *dev, int pipe)
  1303. {
  1304. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1305. unsigned long irqflags;
  1306. if (!i915_pipe_enabled(dev, pipe))
  1307. return -EINVAL;
  1308. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1309. ironlake_enable_display_irq(dev_priv, (pipe == 0) ?
  1310. DE_PIPEA_VBLANK_IVB : DE_PIPEB_VBLANK_IVB);
  1311. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1312. return 0;
  1313. }
  1314. /* Called from drm generic code, passed 'crtc' which
  1315. * we use as a pipe index
  1316. */
  1317. static void i915_disable_vblank(struct drm_device *dev, int pipe)
  1318. {
  1319. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1320. unsigned long irqflags;
  1321. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1322. if (dev_priv->info->gen == 3)
  1323. I915_WRITE(INSTPM,
  1324. INSTPM_AGPBUSY_DIS << 16 | INSTPM_AGPBUSY_DIS);
  1325. i915_disable_pipestat(dev_priv, pipe,
  1326. PIPE_VBLANK_INTERRUPT_ENABLE |
  1327. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1328. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1329. }
  1330. static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
  1331. {
  1332. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1333. unsigned long irqflags;
  1334. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1335. ironlake_disable_display_irq(dev_priv, (pipe == 0) ?
  1336. DE_PIPEA_VBLANK : DE_PIPEB_VBLANK);
  1337. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1338. }
  1339. static void ivybridge_disable_vblank(struct drm_device *dev, int pipe)
  1340. {
  1341. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1342. unsigned long irqflags;
  1343. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1344. ironlake_disable_display_irq(dev_priv, (pipe == 0) ?
  1345. DE_PIPEA_VBLANK_IVB : DE_PIPEB_VBLANK_IVB);
  1346. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1347. }
  1348. /* Set the vblank monitor pipe
  1349. */
  1350. int i915_vblank_pipe_set(struct drm_device *dev, void *data,
  1351. struct drm_file *file_priv)
  1352. {
  1353. drm_i915_private_t *dev_priv = dev->dev_private;
  1354. if (!dev_priv) {
  1355. DRM_ERROR("called with no initialization\n");
  1356. return -EINVAL;
  1357. }
  1358. return 0;
  1359. }
  1360. int i915_vblank_pipe_get(struct drm_device *dev, void *data,
  1361. struct drm_file *file_priv)
  1362. {
  1363. drm_i915_private_t *dev_priv = dev->dev_private;
  1364. drm_i915_vblank_pipe_t *pipe = data;
  1365. if (!dev_priv) {
  1366. DRM_ERROR("called with no initialization\n");
  1367. return -EINVAL;
  1368. }
  1369. pipe->pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B;
  1370. return 0;
  1371. }
  1372. /**
  1373. * Schedule buffer swap at given vertical blank.
  1374. */
  1375. int i915_vblank_swap(struct drm_device *dev, void *data,
  1376. struct drm_file *file_priv)
  1377. {
  1378. /* The delayed swap mechanism was fundamentally racy, and has been
  1379. * removed. The model was that the client requested a delayed flip/swap
  1380. * from the kernel, then waited for vblank before continuing to perform
  1381. * rendering. The problem was that the kernel might wake the client
  1382. * up before it dispatched the vblank swap (since the lock has to be
  1383. * held while touching the ringbuffer), in which case the client would
  1384. * clear and start the next frame before the swap occurred, and
  1385. * flicker would occur in addition to likely missing the vblank.
  1386. *
  1387. * In the absence of this ioctl, userland falls back to a correct path
  1388. * of waiting for a vblank, then dispatching the swap on its own.
  1389. * Context switching to userland and back is plenty fast enough for
  1390. * meeting the requirements of vblank swapping.
  1391. */
  1392. return -EINVAL;
  1393. }
  1394. static u32
  1395. ring_last_seqno(struct intel_ring_buffer *ring)
  1396. {
  1397. return list_entry(ring->request_list.prev,
  1398. struct drm_i915_gem_request, list)->seqno;
  1399. }
  1400. static bool i915_hangcheck_ring_idle(struct intel_ring_buffer *ring, bool *err)
  1401. {
  1402. if (list_empty(&ring->request_list) ||
  1403. i915_seqno_passed(ring->get_seqno(ring), ring_last_seqno(ring))) {
  1404. /* Issue a wake-up to catch stuck h/w. */
  1405. if (ring->waiting_seqno && waitqueue_active(&ring->irq_queue)) {
  1406. DRM_ERROR("Hangcheck timer elapsed... %s idle [waiting on %d, at %d], missed IRQ?\n",
  1407. ring->name,
  1408. ring->waiting_seqno,
  1409. ring->get_seqno(ring));
  1410. wake_up_all(&ring->irq_queue);
  1411. *err = true;
  1412. }
  1413. return true;
  1414. }
  1415. return false;
  1416. }
  1417. static bool kick_ring(struct intel_ring_buffer *ring)
  1418. {
  1419. struct drm_device *dev = ring->dev;
  1420. struct drm_i915_private *dev_priv = dev->dev_private;
  1421. u32 tmp = I915_READ_CTL(ring);
  1422. if (tmp & RING_WAIT) {
  1423. DRM_ERROR("Kicking stuck wait on %s\n",
  1424. ring->name);
  1425. I915_WRITE_CTL(ring, tmp);
  1426. return true;
  1427. }
  1428. return false;
  1429. }
  1430. /**
  1431. * This is called when the chip hasn't reported back with completed
  1432. * batchbuffers in a long time. The first time this is called we simply record
  1433. * ACTHD. If ACTHD hasn't changed by the time the hangcheck timer elapses
  1434. * again, we assume the chip is wedged and try to fix it.
  1435. */
  1436. void i915_hangcheck_elapsed(unsigned long data)
  1437. {
  1438. struct drm_device *dev = (struct drm_device *)data;
  1439. drm_i915_private_t *dev_priv = dev->dev_private;
  1440. uint32_t acthd, instdone, instdone1, acthd_bsd, acthd_blt;
  1441. bool err = false;
  1442. if (!i915_enable_hangcheck)
  1443. return;
  1444. /* If all work is done then ACTHD clearly hasn't advanced. */
  1445. if (i915_hangcheck_ring_idle(&dev_priv->ring[RCS], &err) &&
  1446. i915_hangcheck_ring_idle(&dev_priv->ring[VCS], &err) &&
  1447. i915_hangcheck_ring_idle(&dev_priv->ring[BCS], &err)) {
  1448. dev_priv->hangcheck_count = 0;
  1449. if (err)
  1450. goto repeat;
  1451. return;
  1452. }
  1453. if (INTEL_INFO(dev)->gen < 4) {
  1454. instdone = I915_READ(INSTDONE);
  1455. instdone1 = 0;
  1456. } else {
  1457. instdone = I915_READ(INSTDONE_I965);
  1458. instdone1 = I915_READ(INSTDONE1);
  1459. }
  1460. acthd = intel_ring_get_active_head(&dev_priv->ring[RCS]);
  1461. acthd_bsd = HAS_BSD(dev) ?
  1462. intel_ring_get_active_head(&dev_priv->ring[VCS]) : 0;
  1463. acthd_blt = HAS_BLT(dev) ?
  1464. intel_ring_get_active_head(&dev_priv->ring[BCS]) : 0;
  1465. if (dev_priv->last_acthd == acthd &&
  1466. dev_priv->last_acthd_bsd == acthd_bsd &&
  1467. dev_priv->last_acthd_blt == acthd_blt &&
  1468. dev_priv->last_instdone == instdone &&
  1469. dev_priv->last_instdone1 == instdone1) {
  1470. if (dev_priv->hangcheck_count++ > 1) {
  1471. DRM_ERROR("Hangcheck timer elapsed... GPU hung\n");
  1472. i915_handle_error(dev, true);
  1473. if (!IS_GEN2(dev)) {
  1474. /* Is the chip hanging on a WAIT_FOR_EVENT?
  1475. * If so we can simply poke the RB_WAIT bit
  1476. * and break the hang. This should work on
  1477. * all but the second generation chipsets.
  1478. */
  1479. if (kick_ring(&dev_priv->ring[RCS]))
  1480. goto repeat;
  1481. if (HAS_BSD(dev) &&
  1482. kick_ring(&dev_priv->ring[VCS]))
  1483. goto repeat;
  1484. if (HAS_BLT(dev) &&
  1485. kick_ring(&dev_priv->ring[BCS]))
  1486. goto repeat;
  1487. }
  1488. return;
  1489. }
  1490. } else {
  1491. dev_priv->hangcheck_count = 0;
  1492. dev_priv->last_acthd = acthd;
  1493. dev_priv->last_acthd_bsd = acthd_bsd;
  1494. dev_priv->last_acthd_blt = acthd_blt;
  1495. dev_priv->last_instdone = instdone;
  1496. dev_priv->last_instdone1 = instdone1;
  1497. }
  1498. repeat:
  1499. /* Reset timer case chip hangs without another request being added */
  1500. mod_timer(&dev_priv->hangcheck_timer,
  1501. jiffies + msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD));
  1502. }
  1503. /* drm_dma.h hooks
  1504. */
  1505. static void ironlake_irq_preinstall(struct drm_device *dev)
  1506. {
  1507. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1508. atomic_set(&dev_priv->irq_received, 0);
  1509. INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
  1510. INIT_WORK(&dev_priv->error_work, i915_error_work_func);
  1511. if (IS_GEN6(dev) || IS_IVYBRIDGE(dev))
  1512. INIT_WORK(&dev_priv->rps_work, gen6_pm_rps_work);
  1513. I915_WRITE(HWSTAM, 0xeffe);
  1514. /* XXX hotplug from PCH */
  1515. I915_WRITE(DEIMR, 0xffffffff);
  1516. I915_WRITE(DEIER, 0x0);
  1517. POSTING_READ(DEIER);
  1518. /* and GT */
  1519. I915_WRITE(GTIMR, 0xffffffff);
  1520. I915_WRITE(GTIER, 0x0);
  1521. POSTING_READ(GTIER);
  1522. /* south display irq */
  1523. I915_WRITE(SDEIMR, 0xffffffff);
  1524. I915_WRITE(SDEIER, 0x0);
  1525. POSTING_READ(SDEIER);
  1526. }
  1527. /*
  1528. * Enable digital hotplug on the PCH, and configure the DP short pulse
  1529. * duration to 2ms (which is the minimum in the Display Port spec)
  1530. *
  1531. * This register is the same on all known PCH chips.
  1532. */
  1533. static void ironlake_enable_pch_hotplug(struct drm_device *dev)
  1534. {
  1535. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1536. u32 hotplug;
  1537. hotplug = I915_READ(PCH_PORT_HOTPLUG);
  1538. hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
  1539. hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
  1540. hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
  1541. hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
  1542. I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
  1543. }
  1544. static int ironlake_irq_postinstall(struct drm_device *dev)
  1545. {
  1546. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1547. /* enable kind of interrupts always enabled */
  1548. u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
  1549. DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE;
  1550. u32 render_irqs;
  1551. u32 hotplug_mask;
  1552. DRM_INIT_WAITQUEUE(&dev_priv->ring[RCS].irq_queue);
  1553. if (HAS_BSD(dev))
  1554. DRM_INIT_WAITQUEUE(&dev_priv->ring[VCS].irq_queue);
  1555. if (HAS_BLT(dev))
  1556. DRM_INIT_WAITQUEUE(&dev_priv->ring[BCS].irq_queue);
  1557. dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B;
  1558. dev_priv->irq_mask = ~display_mask;
  1559. /* should always can generate irq */
  1560. I915_WRITE(DEIIR, I915_READ(DEIIR));
  1561. I915_WRITE(DEIMR, dev_priv->irq_mask);
  1562. I915_WRITE(DEIER, display_mask | DE_PIPEA_VBLANK | DE_PIPEB_VBLANK);
  1563. POSTING_READ(DEIER);
  1564. dev_priv->gt_irq_mask = ~0;
  1565. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1566. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  1567. if (IS_GEN6(dev))
  1568. render_irqs =
  1569. GT_USER_INTERRUPT |
  1570. GT_GEN6_BSD_USER_INTERRUPT |
  1571. GT_BLT_USER_INTERRUPT;
  1572. else
  1573. render_irqs =
  1574. GT_USER_INTERRUPT |
  1575. GT_PIPE_NOTIFY |
  1576. GT_BSD_USER_INTERRUPT;
  1577. I915_WRITE(GTIER, render_irqs);
  1578. POSTING_READ(GTIER);
  1579. if (HAS_PCH_CPT(dev)) {
  1580. hotplug_mask = (SDE_CRT_HOTPLUG_CPT |
  1581. SDE_PORTB_HOTPLUG_CPT |
  1582. SDE_PORTC_HOTPLUG_CPT |
  1583. SDE_PORTD_HOTPLUG_CPT);
  1584. } else {
  1585. hotplug_mask = (SDE_CRT_HOTPLUG |
  1586. SDE_PORTB_HOTPLUG |
  1587. SDE_PORTC_HOTPLUG |
  1588. SDE_PORTD_HOTPLUG |
  1589. SDE_AUX_MASK);
  1590. }
  1591. dev_priv->pch_irq_mask = ~hotplug_mask;
  1592. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  1593. I915_WRITE(SDEIMR, dev_priv->pch_irq_mask);
  1594. I915_WRITE(SDEIER, hotplug_mask);
  1595. POSTING_READ(SDEIER);
  1596. ironlake_enable_pch_hotplug(dev);
  1597. if (IS_IRONLAKE_M(dev)) {
  1598. /* Clear & enable PCU event interrupts */
  1599. I915_WRITE(DEIIR, DE_PCU_EVENT);
  1600. I915_WRITE(DEIER, I915_READ(DEIER) | DE_PCU_EVENT);
  1601. ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
  1602. }
  1603. return 0;
  1604. }
  1605. static int ivybridge_irq_postinstall(struct drm_device *dev)
  1606. {
  1607. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1608. /* enable kind of interrupts always enabled */
  1609. u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
  1610. DE_PCH_EVENT_IVB | DE_PLANEA_FLIP_DONE_IVB |
  1611. DE_PLANEB_FLIP_DONE_IVB;
  1612. u32 render_irqs;
  1613. u32 hotplug_mask;
  1614. DRM_INIT_WAITQUEUE(&dev_priv->ring[RCS].irq_queue);
  1615. if (HAS_BSD(dev))
  1616. DRM_INIT_WAITQUEUE(&dev_priv->ring[VCS].irq_queue);
  1617. if (HAS_BLT(dev))
  1618. DRM_INIT_WAITQUEUE(&dev_priv->ring[BCS].irq_queue);
  1619. dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B;
  1620. dev_priv->irq_mask = ~display_mask;
  1621. /* should always can generate irq */
  1622. I915_WRITE(DEIIR, I915_READ(DEIIR));
  1623. I915_WRITE(DEIMR, dev_priv->irq_mask);
  1624. I915_WRITE(DEIER, display_mask | DE_PIPEA_VBLANK_IVB |
  1625. DE_PIPEB_VBLANK_IVB);
  1626. POSTING_READ(DEIER);
  1627. dev_priv->gt_irq_mask = ~0;
  1628. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1629. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  1630. render_irqs = GT_USER_INTERRUPT | GT_GEN6_BSD_USER_INTERRUPT |
  1631. GT_BLT_USER_INTERRUPT;
  1632. I915_WRITE(GTIER, render_irqs);
  1633. POSTING_READ(GTIER);
  1634. hotplug_mask = (SDE_CRT_HOTPLUG_CPT |
  1635. SDE_PORTB_HOTPLUG_CPT |
  1636. SDE_PORTC_HOTPLUG_CPT |
  1637. SDE_PORTD_HOTPLUG_CPT);
  1638. dev_priv->pch_irq_mask = ~hotplug_mask;
  1639. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  1640. I915_WRITE(SDEIMR, dev_priv->pch_irq_mask);
  1641. I915_WRITE(SDEIER, hotplug_mask);
  1642. POSTING_READ(SDEIER);
  1643. ironlake_enable_pch_hotplug(dev);
  1644. return 0;
  1645. }
  1646. static void i915_driver_irq_preinstall(struct drm_device * dev)
  1647. {
  1648. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1649. int pipe;
  1650. atomic_set(&dev_priv->irq_received, 0);
  1651. INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
  1652. INIT_WORK(&dev_priv->error_work, i915_error_work_func);
  1653. if (I915_HAS_HOTPLUG(dev)) {
  1654. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1655. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  1656. }
  1657. I915_WRITE(HWSTAM, 0xeffe);
  1658. for_each_pipe(pipe)
  1659. I915_WRITE(PIPESTAT(pipe), 0);
  1660. I915_WRITE(IMR, 0xffffffff);
  1661. I915_WRITE(IER, 0x0);
  1662. POSTING_READ(IER);
  1663. }
  1664. /*
  1665. * Must be called after intel_modeset_init or hotplug interrupts won't be
  1666. * enabled correctly.
  1667. */
  1668. static int i915_driver_irq_postinstall(struct drm_device *dev)
  1669. {
  1670. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1671. u32 enable_mask = I915_INTERRUPT_ENABLE_FIX | I915_INTERRUPT_ENABLE_VAR;
  1672. u32 error_mask;
  1673. dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B;
  1674. /* Unmask the interrupts that we always want on. */
  1675. dev_priv->irq_mask = ~I915_INTERRUPT_ENABLE_FIX;
  1676. dev_priv->pipestat[0] = 0;
  1677. dev_priv->pipestat[1] = 0;
  1678. if (I915_HAS_HOTPLUG(dev)) {
  1679. /* Enable in IER... */
  1680. enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
  1681. /* and unmask in IMR */
  1682. dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
  1683. }
  1684. /*
  1685. * Enable some error detection, note the instruction error mask
  1686. * bit is reserved, so we leave it masked.
  1687. */
  1688. if (IS_G4X(dev)) {
  1689. error_mask = ~(GM45_ERROR_PAGE_TABLE |
  1690. GM45_ERROR_MEM_PRIV |
  1691. GM45_ERROR_CP_PRIV |
  1692. I915_ERROR_MEMORY_REFRESH);
  1693. } else {
  1694. error_mask = ~(I915_ERROR_PAGE_TABLE |
  1695. I915_ERROR_MEMORY_REFRESH);
  1696. }
  1697. I915_WRITE(EMR, error_mask);
  1698. I915_WRITE(IMR, dev_priv->irq_mask);
  1699. I915_WRITE(IER, enable_mask);
  1700. POSTING_READ(IER);
  1701. if (I915_HAS_HOTPLUG(dev)) {
  1702. u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
  1703. /* Note HDMI and DP share bits */
  1704. if (dev_priv->hotplug_supported_mask & HDMIB_HOTPLUG_INT_STATUS)
  1705. hotplug_en |= HDMIB_HOTPLUG_INT_EN;
  1706. if (dev_priv->hotplug_supported_mask & HDMIC_HOTPLUG_INT_STATUS)
  1707. hotplug_en |= HDMIC_HOTPLUG_INT_EN;
  1708. if (dev_priv->hotplug_supported_mask & HDMID_HOTPLUG_INT_STATUS)
  1709. hotplug_en |= HDMID_HOTPLUG_INT_EN;
  1710. if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS)
  1711. hotplug_en |= SDVOC_HOTPLUG_INT_EN;
  1712. if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS)
  1713. hotplug_en |= SDVOB_HOTPLUG_INT_EN;
  1714. if (dev_priv->hotplug_supported_mask & CRT_HOTPLUG_INT_STATUS) {
  1715. hotplug_en |= CRT_HOTPLUG_INT_EN;
  1716. /* Programming the CRT detection parameters tends
  1717. to generate a spurious hotplug event about three
  1718. seconds later. So just do it once.
  1719. */
  1720. if (IS_G4X(dev))
  1721. hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
  1722. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  1723. }
  1724. /* Ignore TV since it's buggy */
  1725. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  1726. }
  1727. intel_opregion_enable_asle(dev);
  1728. return 0;
  1729. }
  1730. static void ironlake_irq_uninstall(struct drm_device *dev)
  1731. {
  1732. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1733. if (!dev_priv)
  1734. return;
  1735. dev_priv->vblank_pipe = 0;
  1736. I915_WRITE(HWSTAM, 0xffffffff);
  1737. I915_WRITE(DEIMR, 0xffffffff);
  1738. I915_WRITE(DEIER, 0x0);
  1739. I915_WRITE(DEIIR, I915_READ(DEIIR));
  1740. I915_WRITE(GTIMR, 0xffffffff);
  1741. I915_WRITE(GTIER, 0x0);
  1742. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1743. I915_WRITE(SDEIMR, 0xffffffff);
  1744. I915_WRITE(SDEIER, 0x0);
  1745. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  1746. }
  1747. static void i915_driver_irq_uninstall(struct drm_device * dev)
  1748. {
  1749. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1750. int pipe;
  1751. if (!dev_priv)
  1752. return;
  1753. dev_priv->vblank_pipe = 0;
  1754. if (I915_HAS_HOTPLUG(dev)) {
  1755. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1756. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  1757. }
  1758. I915_WRITE(HWSTAM, 0xffffffff);
  1759. for_each_pipe(pipe)
  1760. I915_WRITE(PIPESTAT(pipe), 0);
  1761. I915_WRITE(IMR, 0xffffffff);
  1762. I915_WRITE(IER, 0x0);
  1763. for_each_pipe(pipe)
  1764. I915_WRITE(PIPESTAT(pipe),
  1765. I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
  1766. I915_WRITE(IIR, I915_READ(IIR));
  1767. }
  1768. void intel_irq_init(struct drm_device *dev)
  1769. {
  1770. dev->driver->get_vblank_counter = i915_get_vblank_counter;
  1771. dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
  1772. if (IS_G4X(dev) || IS_GEN5(dev) || IS_GEN6(dev) || IS_IVYBRIDGE(dev)) {
  1773. dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
  1774. dev->driver->get_vblank_counter = gm45_get_vblank_counter;
  1775. }
  1776. if (drm_core_check_feature(dev, DRIVER_MODESET))
  1777. dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
  1778. else
  1779. dev->driver->get_vblank_timestamp = NULL;
  1780. dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
  1781. if (IS_IVYBRIDGE(dev)) {
  1782. /* Share pre & uninstall handlers with ILK/SNB */
  1783. dev->driver->irq_handler = ivybridge_irq_handler;
  1784. dev->driver->irq_preinstall = ironlake_irq_preinstall;
  1785. dev->driver->irq_postinstall = ivybridge_irq_postinstall;
  1786. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  1787. dev->driver->enable_vblank = ivybridge_enable_vblank;
  1788. dev->driver->disable_vblank = ivybridge_disable_vblank;
  1789. } else if (HAS_PCH_SPLIT(dev)) {
  1790. dev->driver->irq_handler = ironlake_irq_handler;
  1791. dev->driver->irq_preinstall = ironlake_irq_preinstall;
  1792. dev->driver->irq_postinstall = ironlake_irq_postinstall;
  1793. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  1794. dev->driver->enable_vblank = ironlake_enable_vblank;
  1795. dev->driver->disable_vblank = ironlake_disable_vblank;
  1796. } else {
  1797. dev->driver->irq_preinstall = i915_driver_irq_preinstall;
  1798. dev->driver->irq_postinstall = i915_driver_irq_postinstall;
  1799. dev->driver->irq_uninstall = i915_driver_irq_uninstall;
  1800. dev->driver->irq_handler = i915_driver_irq_handler;
  1801. dev->driver->enable_vblank = i915_enable_vblank;
  1802. dev->driver->disable_vblank = i915_disable_vblank;
  1803. }
  1804. }