i915_irq.c 60 KB

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