i915_irq.c 55 KB

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