i915_irq.c 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  29. #include <linux/sysrq.h>
  30. #include <linux/slab.h>
  31. #include <drm/drmP.h>
  32. #include <drm/i915_drm.h>
  33. #include "i915_drv.h"
  34. #include "i915_trace.h"
  35. #include "intel_drv.h"
  36. /* For display hotplug interrupt */
  37. static void
  38. ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
  39. {
  40. if ((dev_priv->irq_mask & mask) != 0) {
  41. dev_priv->irq_mask &= ~mask;
  42. I915_WRITE(DEIMR, dev_priv->irq_mask);
  43. POSTING_READ(DEIMR);
  44. }
  45. }
  46. static inline void
  47. ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
  48. {
  49. if ((dev_priv->irq_mask & mask) != mask) {
  50. dev_priv->irq_mask |= mask;
  51. I915_WRITE(DEIMR, dev_priv->irq_mask);
  52. POSTING_READ(DEIMR);
  53. }
  54. }
  55. void
  56. i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
  57. {
  58. if ((dev_priv->pipestat[pipe] & mask) != mask) {
  59. u32 reg = PIPESTAT(pipe);
  60. dev_priv->pipestat[pipe] |= mask;
  61. /* Enable the interrupt, clear any pending status */
  62. I915_WRITE(reg, dev_priv->pipestat[pipe] | (mask >> 16));
  63. POSTING_READ(reg);
  64. }
  65. }
  66. void
  67. i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
  68. {
  69. if ((dev_priv->pipestat[pipe] & mask) != 0) {
  70. u32 reg = PIPESTAT(pipe);
  71. dev_priv->pipestat[pipe] &= ~mask;
  72. I915_WRITE(reg, dev_priv->pipestat[pipe]);
  73. POSTING_READ(reg);
  74. }
  75. }
  76. /**
  77. * intel_enable_asle - enable ASLE interrupt for OpRegion
  78. */
  79. void intel_enable_asle(struct drm_device *dev)
  80. {
  81. drm_i915_private_t *dev_priv = dev->dev_private;
  82. unsigned long irqflags;
  83. /* FIXME: opregion/asle for VLV */
  84. if (IS_VALLEYVIEW(dev))
  85. return;
  86. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  87. if (HAS_PCH_SPLIT(dev))
  88. ironlake_enable_display_irq(dev_priv, DE_GSE);
  89. else {
  90. i915_enable_pipestat(dev_priv, 1,
  91. PIPE_LEGACY_BLC_EVENT_ENABLE);
  92. if (INTEL_INFO(dev)->gen >= 4)
  93. i915_enable_pipestat(dev_priv, 0,
  94. PIPE_LEGACY_BLC_EVENT_ENABLE);
  95. }
  96. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  97. }
  98. /**
  99. * i915_pipe_enabled - check if a pipe is enabled
  100. * @dev: DRM device
  101. * @pipe: pipe to check
  102. *
  103. * Reading certain registers when the pipe is disabled can hang the chip.
  104. * Use this routine to make sure the PLL is running and the pipe is active
  105. * before reading such registers if unsure.
  106. */
  107. static int
  108. i915_pipe_enabled(struct drm_device *dev, int pipe)
  109. {
  110. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  111. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  112. pipe);
  113. return I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_ENABLE;
  114. }
  115. /* Called from drm generic code, passed a 'crtc', which
  116. * we use as a pipe index
  117. */
  118. static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
  119. {
  120. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  121. unsigned long high_frame;
  122. unsigned long low_frame;
  123. u32 high1, high2, low;
  124. if (!i915_pipe_enabled(dev, pipe)) {
  125. DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
  126. "pipe %c\n", pipe_name(pipe));
  127. return 0;
  128. }
  129. high_frame = PIPEFRAME(pipe);
  130. low_frame = PIPEFRAMEPIXEL(pipe);
  131. /*
  132. * High & low register fields aren't synchronized, so make sure
  133. * we get a low value that's stable across two reads of the high
  134. * register.
  135. */
  136. do {
  137. high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
  138. low = I915_READ(low_frame) & PIPE_FRAME_LOW_MASK;
  139. high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
  140. } while (high1 != high2);
  141. high1 >>= PIPE_FRAME_HIGH_SHIFT;
  142. low >>= PIPE_FRAME_LOW_SHIFT;
  143. return (high1 << 8) | low;
  144. }
  145. static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
  146. {
  147. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  148. int reg = PIPE_FRMCOUNT_GM45(pipe);
  149. if (!i915_pipe_enabled(dev, pipe)) {
  150. DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
  151. "pipe %c\n", pipe_name(pipe));
  152. return 0;
  153. }
  154. return I915_READ(reg);
  155. }
  156. static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
  157. int *vpos, int *hpos)
  158. {
  159. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  160. u32 vbl = 0, position = 0;
  161. int vbl_start, vbl_end, htotal, vtotal;
  162. bool in_vbl = true;
  163. int ret = 0;
  164. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  165. pipe);
  166. if (!i915_pipe_enabled(dev, pipe)) {
  167. DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
  168. "pipe %c\n", pipe_name(pipe));
  169. return 0;
  170. }
  171. /* Get vtotal. */
  172. vtotal = 1 + ((I915_READ(VTOTAL(cpu_transcoder)) >> 16) & 0x1fff);
  173. if (INTEL_INFO(dev)->gen >= 4) {
  174. /* No obvious pixelcount register. Only query vertical
  175. * scanout position from Display scan line register.
  176. */
  177. position = I915_READ(PIPEDSL(pipe));
  178. /* Decode into vertical scanout position. Don't have
  179. * horizontal scanout position.
  180. */
  181. *vpos = position & 0x1fff;
  182. *hpos = 0;
  183. } else {
  184. /* Have access to pixelcount since start of frame.
  185. * We can split this into vertical and horizontal
  186. * scanout position.
  187. */
  188. position = (I915_READ(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
  189. htotal = 1 + ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff);
  190. *vpos = position / htotal;
  191. *hpos = position - (*vpos * htotal);
  192. }
  193. /* Query vblank area. */
  194. vbl = I915_READ(VBLANK(cpu_transcoder));
  195. /* Test position against vblank region. */
  196. vbl_start = vbl & 0x1fff;
  197. vbl_end = (vbl >> 16) & 0x1fff;
  198. if ((*vpos < vbl_start) || (*vpos > vbl_end))
  199. in_vbl = false;
  200. /* Inside "upper part" of vblank area? Apply corrective offset: */
  201. if (in_vbl && (*vpos >= vbl_start))
  202. *vpos = *vpos - vtotal;
  203. /* Readouts valid? */
  204. if (vbl > 0)
  205. ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
  206. /* In vblank? */
  207. if (in_vbl)
  208. ret |= DRM_SCANOUTPOS_INVBL;
  209. return ret;
  210. }
  211. static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
  212. int *max_error,
  213. struct timeval *vblank_time,
  214. unsigned flags)
  215. {
  216. struct drm_i915_private *dev_priv = dev->dev_private;
  217. struct drm_crtc *crtc;
  218. if (pipe < 0 || pipe >= dev_priv->num_pipe) {
  219. DRM_ERROR("Invalid crtc %d\n", pipe);
  220. return -EINVAL;
  221. }
  222. /* Get drm_crtc to timestamp: */
  223. crtc = intel_get_crtc_for_pipe(dev, pipe);
  224. if (crtc == NULL) {
  225. DRM_ERROR("Invalid crtc %d\n", pipe);
  226. return -EINVAL;
  227. }
  228. if (!crtc->enabled) {
  229. DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
  230. return -EBUSY;
  231. }
  232. /* Helper routine in DRM core does all the work: */
  233. return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
  234. vblank_time, flags,
  235. crtc);
  236. }
  237. /*
  238. * Handle hotplug events outside the interrupt handler proper.
  239. */
  240. static void i915_hotplug_work_func(struct work_struct *work)
  241. {
  242. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  243. hotplug_work);
  244. struct drm_device *dev = dev_priv->dev;
  245. struct drm_mode_config *mode_config = &dev->mode_config;
  246. struct intel_encoder *encoder;
  247. mutex_lock(&mode_config->mutex);
  248. DRM_DEBUG_KMS("running encoder hotplug functions\n");
  249. list_for_each_entry(encoder, &mode_config->encoder_list, base.head)
  250. if (encoder->hot_plug)
  251. encoder->hot_plug(encoder);
  252. mutex_unlock(&mode_config->mutex);
  253. /* Just fire off a uevent and let userspace tell us what to do */
  254. drm_helper_hpd_irq_event(dev);
  255. }
  256. /* defined intel_pm.c */
  257. extern spinlock_t mchdev_lock;
  258. static void ironlake_handle_rps_change(struct drm_device *dev)
  259. {
  260. drm_i915_private_t *dev_priv = dev->dev_private;
  261. u32 busy_up, busy_down, max_avg, min_avg;
  262. u8 new_delay;
  263. unsigned long flags;
  264. spin_lock_irqsave(&mchdev_lock, flags);
  265. I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
  266. new_delay = dev_priv->ips.cur_delay;
  267. I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
  268. busy_up = I915_READ(RCPREVBSYTUPAVG);
  269. busy_down = I915_READ(RCPREVBSYTDNAVG);
  270. max_avg = I915_READ(RCBMAXAVG);
  271. min_avg = I915_READ(RCBMINAVG);
  272. /* Handle RCS change request from hw */
  273. if (busy_up > max_avg) {
  274. if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
  275. new_delay = dev_priv->ips.cur_delay - 1;
  276. if (new_delay < dev_priv->ips.max_delay)
  277. new_delay = dev_priv->ips.max_delay;
  278. } else if (busy_down < min_avg) {
  279. if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
  280. new_delay = dev_priv->ips.cur_delay + 1;
  281. if (new_delay > dev_priv->ips.min_delay)
  282. new_delay = dev_priv->ips.min_delay;
  283. }
  284. if (ironlake_set_drps(dev, new_delay))
  285. dev_priv->ips.cur_delay = new_delay;
  286. spin_unlock_irqrestore(&mchdev_lock, flags);
  287. return;
  288. }
  289. static void notify_ring(struct drm_device *dev,
  290. struct intel_ring_buffer *ring)
  291. {
  292. struct drm_i915_private *dev_priv = dev->dev_private;
  293. if (ring->obj == NULL)
  294. return;
  295. trace_i915_gem_request_complete(ring, ring->get_seqno(ring, false));
  296. wake_up_all(&ring->irq_queue);
  297. if (i915_enable_hangcheck) {
  298. dev_priv->hangcheck_count = 0;
  299. mod_timer(&dev_priv->hangcheck_timer,
  300. round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
  301. }
  302. }
  303. static void gen6_pm_rps_work(struct work_struct *work)
  304. {
  305. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  306. rps.work);
  307. u32 pm_iir, pm_imr;
  308. u8 new_delay;
  309. spin_lock_irq(&dev_priv->rps.lock);
  310. pm_iir = dev_priv->rps.pm_iir;
  311. dev_priv->rps.pm_iir = 0;
  312. pm_imr = I915_READ(GEN6_PMIMR);
  313. I915_WRITE(GEN6_PMIMR, 0);
  314. spin_unlock_irq(&dev_priv->rps.lock);
  315. if ((pm_iir & GEN6_PM_DEFERRED_EVENTS) == 0)
  316. return;
  317. mutex_lock(&dev_priv->dev->struct_mutex);
  318. if (pm_iir & GEN6_PM_RP_UP_THRESHOLD)
  319. new_delay = dev_priv->rps.cur_delay + 1;
  320. else
  321. new_delay = dev_priv->rps.cur_delay - 1;
  322. /* sysfs frequency interfaces may have snuck in while servicing the
  323. * interrupt
  324. */
  325. if (!(new_delay > dev_priv->rps.max_delay ||
  326. new_delay < dev_priv->rps.min_delay)) {
  327. gen6_set_rps(dev_priv->dev, new_delay);
  328. }
  329. mutex_unlock(&dev_priv->dev->struct_mutex);
  330. }
  331. /**
  332. * ivybridge_parity_work - Workqueue called when a parity error interrupt
  333. * occurred.
  334. * @work: workqueue struct
  335. *
  336. * Doesn't actually do anything except notify userspace. As a consequence of
  337. * this event, userspace should try to remap the bad rows since statistically
  338. * it is likely the same row is more likely to go bad again.
  339. */
  340. static void ivybridge_parity_work(struct work_struct *work)
  341. {
  342. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  343. l3_parity.error_work);
  344. u32 error_status, row, bank, subbank;
  345. char *parity_event[5];
  346. uint32_t misccpctl;
  347. unsigned long flags;
  348. /* We must turn off DOP level clock gating to access the L3 registers.
  349. * In order to prevent a get/put style interface, acquire struct mutex
  350. * any time we access those registers.
  351. */
  352. mutex_lock(&dev_priv->dev->struct_mutex);
  353. misccpctl = I915_READ(GEN7_MISCCPCTL);
  354. I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
  355. POSTING_READ(GEN7_MISCCPCTL);
  356. error_status = I915_READ(GEN7_L3CDERRST1);
  357. row = GEN7_PARITY_ERROR_ROW(error_status);
  358. bank = GEN7_PARITY_ERROR_BANK(error_status);
  359. subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
  360. I915_WRITE(GEN7_L3CDERRST1, GEN7_PARITY_ERROR_VALID |
  361. GEN7_L3CDERRST1_ENABLE);
  362. POSTING_READ(GEN7_L3CDERRST1);
  363. I915_WRITE(GEN7_MISCCPCTL, misccpctl);
  364. spin_lock_irqsave(&dev_priv->irq_lock, flags);
  365. dev_priv->gt_irq_mask &= ~GT_GEN7_L3_PARITY_ERROR_INTERRUPT;
  366. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  367. spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
  368. mutex_unlock(&dev_priv->dev->struct_mutex);
  369. parity_event[0] = "L3_PARITY_ERROR=1";
  370. parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
  371. parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
  372. parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
  373. parity_event[4] = NULL;
  374. kobject_uevent_env(&dev_priv->dev->primary->kdev.kobj,
  375. KOBJ_CHANGE, parity_event);
  376. DRM_DEBUG("Parity error: Row = %d, Bank = %d, Sub bank = %d.\n",
  377. row, bank, subbank);
  378. kfree(parity_event[3]);
  379. kfree(parity_event[2]);
  380. kfree(parity_event[1]);
  381. }
  382. static void ivybridge_handle_parity_error(struct drm_device *dev)
  383. {
  384. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  385. unsigned long flags;
  386. if (!HAS_L3_GPU_CACHE(dev))
  387. return;
  388. spin_lock_irqsave(&dev_priv->irq_lock, flags);
  389. dev_priv->gt_irq_mask |= GT_GEN7_L3_PARITY_ERROR_INTERRUPT;
  390. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  391. spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
  392. queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
  393. }
  394. static void snb_gt_irq_handler(struct drm_device *dev,
  395. struct drm_i915_private *dev_priv,
  396. u32 gt_iir)
  397. {
  398. if (gt_iir & (GEN6_RENDER_USER_INTERRUPT |
  399. GEN6_RENDER_PIPE_CONTROL_NOTIFY_INTERRUPT))
  400. notify_ring(dev, &dev_priv->ring[RCS]);
  401. if (gt_iir & GEN6_BSD_USER_INTERRUPT)
  402. notify_ring(dev, &dev_priv->ring[VCS]);
  403. if (gt_iir & GEN6_BLITTER_USER_INTERRUPT)
  404. notify_ring(dev, &dev_priv->ring[BCS]);
  405. if (gt_iir & (GT_GEN6_BLT_CS_ERROR_INTERRUPT |
  406. GT_GEN6_BSD_CS_ERROR_INTERRUPT |
  407. GT_RENDER_CS_ERROR_INTERRUPT)) {
  408. DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir);
  409. i915_handle_error(dev, false);
  410. }
  411. if (gt_iir & GT_GEN7_L3_PARITY_ERROR_INTERRUPT)
  412. ivybridge_handle_parity_error(dev);
  413. }
  414. static void gen6_queue_rps_work(struct drm_i915_private *dev_priv,
  415. u32 pm_iir)
  416. {
  417. unsigned long flags;
  418. /*
  419. * IIR bits should never already be set because IMR should
  420. * prevent an interrupt from being shown in IIR. The warning
  421. * displays a case where we've unsafely cleared
  422. * dev_priv->rps.pm_iir. Although missing an interrupt of the same
  423. * type is not a problem, it displays a problem in the logic.
  424. *
  425. * The mask bit in IMR is cleared by dev_priv->rps.work.
  426. */
  427. spin_lock_irqsave(&dev_priv->rps.lock, flags);
  428. dev_priv->rps.pm_iir |= pm_iir;
  429. I915_WRITE(GEN6_PMIMR, dev_priv->rps.pm_iir);
  430. POSTING_READ(GEN6_PMIMR);
  431. spin_unlock_irqrestore(&dev_priv->rps.lock, flags);
  432. queue_work(dev_priv->wq, &dev_priv->rps.work);
  433. }
  434. static irqreturn_t valleyview_irq_handler(int irq, void *arg)
  435. {
  436. struct drm_device *dev = (struct drm_device *) arg;
  437. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  438. u32 iir, gt_iir, pm_iir;
  439. irqreturn_t ret = IRQ_NONE;
  440. unsigned long irqflags;
  441. int pipe;
  442. u32 pipe_stats[I915_MAX_PIPES];
  443. bool blc_event;
  444. atomic_inc(&dev_priv->irq_received);
  445. while (true) {
  446. iir = I915_READ(VLV_IIR);
  447. gt_iir = I915_READ(GTIIR);
  448. pm_iir = I915_READ(GEN6_PMIIR);
  449. if (gt_iir == 0 && pm_iir == 0 && iir == 0)
  450. goto out;
  451. ret = IRQ_HANDLED;
  452. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  453. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  454. for_each_pipe(pipe) {
  455. int reg = PIPESTAT(pipe);
  456. pipe_stats[pipe] = I915_READ(reg);
  457. /*
  458. * Clear the PIPE*STAT regs before the IIR
  459. */
  460. if (pipe_stats[pipe] & 0x8000ffff) {
  461. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  462. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  463. pipe_name(pipe));
  464. I915_WRITE(reg, pipe_stats[pipe]);
  465. }
  466. }
  467. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  468. for_each_pipe(pipe) {
  469. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
  470. drm_handle_vblank(dev, pipe);
  471. if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) {
  472. intel_prepare_page_flip(dev, pipe);
  473. intel_finish_page_flip(dev, pipe);
  474. }
  475. }
  476. /* Consume port. Then clear IIR or we'll miss events */
  477. if (iir & I915_DISPLAY_PORT_INTERRUPT) {
  478. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  479. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  480. hotplug_status);
  481. if (hotplug_status & dev_priv->hotplug_supported_mask)
  482. queue_work(dev_priv->wq,
  483. &dev_priv->hotplug_work);
  484. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  485. I915_READ(PORT_HOTPLUG_STAT);
  486. }
  487. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  488. blc_event = true;
  489. if (pm_iir & GEN6_PM_DEFERRED_EVENTS)
  490. gen6_queue_rps_work(dev_priv, pm_iir);
  491. I915_WRITE(GTIIR, gt_iir);
  492. I915_WRITE(GEN6_PMIIR, pm_iir);
  493. I915_WRITE(VLV_IIR, iir);
  494. }
  495. out:
  496. return ret;
  497. }
  498. static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
  499. {
  500. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  501. int pipe;
  502. if (pch_iir & SDE_HOTPLUG_MASK)
  503. queue_work(dev_priv->wq, &dev_priv->hotplug_work);
  504. if (pch_iir & SDE_AUDIO_POWER_MASK)
  505. DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
  506. (pch_iir & SDE_AUDIO_POWER_MASK) >>
  507. SDE_AUDIO_POWER_SHIFT);
  508. if (pch_iir & SDE_GMBUS)
  509. DRM_DEBUG_DRIVER("PCH GMBUS interrupt\n");
  510. if (pch_iir & SDE_AUDIO_HDCP_MASK)
  511. DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
  512. if (pch_iir & SDE_AUDIO_TRANS_MASK)
  513. DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
  514. if (pch_iir & SDE_POISON)
  515. DRM_ERROR("PCH poison interrupt\n");
  516. if (pch_iir & SDE_FDI_MASK)
  517. for_each_pipe(pipe)
  518. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  519. pipe_name(pipe),
  520. I915_READ(FDI_RX_IIR(pipe)));
  521. if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
  522. DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
  523. if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
  524. DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
  525. if (pch_iir & SDE_TRANSB_FIFO_UNDER)
  526. DRM_DEBUG_DRIVER("PCH transcoder B underrun interrupt\n");
  527. if (pch_iir & SDE_TRANSA_FIFO_UNDER)
  528. DRM_DEBUG_DRIVER("PCH transcoder A underrun interrupt\n");
  529. }
  530. static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
  531. {
  532. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  533. int pipe;
  534. if (pch_iir & SDE_HOTPLUG_MASK_CPT)
  535. queue_work(dev_priv->wq, &dev_priv->hotplug_work);
  536. if (pch_iir & SDE_AUDIO_POWER_MASK_CPT)
  537. DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
  538. (pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
  539. SDE_AUDIO_POWER_SHIFT_CPT);
  540. if (pch_iir & SDE_AUX_MASK_CPT)
  541. DRM_DEBUG_DRIVER("AUX channel interrupt\n");
  542. if (pch_iir & SDE_GMBUS_CPT)
  543. DRM_DEBUG_DRIVER("PCH GMBUS interrupt\n");
  544. if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
  545. DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
  546. if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
  547. DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
  548. if (pch_iir & SDE_FDI_MASK_CPT)
  549. for_each_pipe(pipe)
  550. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  551. pipe_name(pipe),
  552. I915_READ(FDI_RX_IIR(pipe)));
  553. }
  554. static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
  555. {
  556. struct drm_device *dev = (struct drm_device *) arg;
  557. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  558. u32 de_iir, gt_iir, de_ier, pm_iir;
  559. irqreturn_t ret = IRQ_NONE;
  560. int i;
  561. atomic_inc(&dev_priv->irq_received);
  562. /* disable master interrupt before clearing iir */
  563. de_ier = I915_READ(DEIER);
  564. I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  565. gt_iir = I915_READ(GTIIR);
  566. if (gt_iir) {
  567. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  568. I915_WRITE(GTIIR, gt_iir);
  569. ret = IRQ_HANDLED;
  570. }
  571. de_iir = I915_READ(DEIIR);
  572. if (de_iir) {
  573. if (de_iir & DE_GSE_IVB)
  574. intel_opregion_gse_intr(dev);
  575. for (i = 0; i < 3; i++) {
  576. if (de_iir & (DE_PIPEA_VBLANK_IVB << (5 * i)))
  577. drm_handle_vblank(dev, i);
  578. if (de_iir & (DE_PLANEA_FLIP_DONE_IVB << (5 * i))) {
  579. intel_prepare_page_flip(dev, i);
  580. intel_finish_page_flip_plane(dev, i);
  581. }
  582. }
  583. /* check event from PCH */
  584. if (de_iir & DE_PCH_EVENT_IVB) {
  585. u32 pch_iir = I915_READ(SDEIIR);
  586. cpt_irq_handler(dev, pch_iir);
  587. /* clear PCH hotplug event before clear CPU irq */
  588. I915_WRITE(SDEIIR, pch_iir);
  589. }
  590. I915_WRITE(DEIIR, de_iir);
  591. ret = IRQ_HANDLED;
  592. }
  593. pm_iir = I915_READ(GEN6_PMIIR);
  594. if (pm_iir) {
  595. if (pm_iir & GEN6_PM_DEFERRED_EVENTS)
  596. gen6_queue_rps_work(dev_priv, pm_iir);
  597. I915_WRITE(GEN6_PMIIR, pm_iir);
  598. ret = IRQ_HANDLED;
  599. }
  600. I915_WRITE(DEIER, de_ier);
  601. POSTING_READ(DEIER);
  602. return ret;
  603. }
  604. static void ilk_gt_irq_handler(struct drm_device *dev,
  605. struct drm_i915_private *dev_priv,
  606. u32 gt_iir)
  607. {
  608. if (gt_iir & (GT_USER_INTERRUPT | GT_PIPE_NOTIFY))
  609. notify_ring(dev, &dev_priv->ring[RCS]);
  610. if (gt_iir & GT_BSD_USER_INTERRUPT)
  611. notify_ring(dev, &dev_priv->ring[VCS]);
  612. }
  613. static irqreturn_t ironlake_irq_handler(int irq, void *arg)
  614. {
  615. struct drm_device *dev = (struct drm_device *) arg;
  616. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  617. int ret = IRQ_NONE;
  618. u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
  619. atomic_inc(&dev_priv->irq_received);
  620. /* disable master interrupt before clearing iir */
  621. de_ier = I915_READ(DEIER);
  622. I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  623. POSTING_READ(DEIER);
  624. de_iir = I915_READ(DEIIR);
  625. gt_iir = I915_READ(GTIIR);
  626. pch_iir = I915_READ(SDEIIR);
  627. pm_iir = I915_READ(GEN6_PMIIR);
  628. if (de_iir == 0 && gt_iir == 0 && pch_iir == 0 &&
  629. (!IS_GEN6(dev) || pm_iir == 0))
  630. goto done;
  631. ret = IRQ_HANDLED;
  632. if (IS_GEN5(dev))
  633. ilk_gt_irq_handler(dev, dev_priv, gt_iir);
  634. else
  635. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  636. if (de_iir & DE_GSE)
  637. intel_opregion_gse_intr(dev);
  638. if (de_iir & DE_PIPEA_VBLANK)
  639. drm_handle_vblank(dev, 0);
  640. if (de_iir & DE_PIPEB_VBLANK)
  641. drm_handle_vblank(dev, 1);
  642. if (de_iir & DE_PLANEA_FLIP_DONE) {
  643. intel_prepare_page_flip(dev, 0);
  644. intel_finish_page_flip_plane(dev, 0);
  645. }
  646. if (de_iir & DE_PLANEB_FLIP_DONE) {
  647. intel_prepare_page_flip(dev, 1);
  648. intel_finish_page_flip_plane(dev, 1);
  649. }
  650. /* check event from PCH */
  651. if (de_iir & DE_PCH_EVENT) {
  652. if (HAS_PCH_CPT(dev))
  653. cpt_irq_handler(dev, pch_iir);
  654. else
  655. ibx_irq_handler(dev, pch_iir);
  656. }
  657. if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
  658. ironlake_handle_rps_change(dev);
  659. if (IS_GEN6(dev) && pm_iir & GEN6_PM_DEFERRED_EVENTS)
  660. gen6_queue_rps_work(dev_priv, pm_iir);
  661. /* should clear PCH hotplug event before clear CPU irq */
  662. I915_WRITE(SDEIIR, pch_iir);
  663. I915_WRITE(GTIIR, gt_iir);
  664. I915_WRITE(DEIIR, de_iir);
  665. I915_WRITE(GEN6_PMIIR, pm_iir);
  666. done:
  667. I915_WRITE(DEIER, de_ier);
  668. POSTING_READ(DEIER);
  669. return ret;
  670. }
  671. /**
  672. * i915_error_work_func - do process context error handling work
  673. * @work: work struct
  674. *
  675. * Fire an error uevent so userspace can see that a hang or error
  676. * was detected.
  677. */
  678. static void i915_error_work_func(struct work_struct *work)
  679. {
  680. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  681. error_work);
  682. struct drm_device *dev = dev_priv->dev;
  683. char *error_event[] = { "ERROR=1", NULL };
  684. char *reset_event[] = { "RESET=1", NULL };
  685. char *reset_done_event[] = { "ERROR=0", NULL };
  686. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
  687. if (atomic_read(&dev_priv->mm.wedged)) {
  688. DRM_DEBUG_DRIVER("resetting chip\n");
  689. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_event);
  690. if (!i915_reset(dev)) {
  691. atomic_set(&dev_priv->mm.wedged, 0);
  692. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_done_event);
  693. }
  694. complete_all(&dev_priv->error_completion);
  695. }
  696. }
  697. /* NB: please notice the memset */
  698. static void i915_get_extra_instdone(struct drm_device *dev,
  699. uint32_t *instdone)
  700. {
  701. struct drm_i915_private *dev_priv = dev->dev_private;
  702. memset(instdone, 0, sizeof(*instdone) * I915_NUM_INSTDONE_REG);
  703. switch(INTEL_INFO(dev)->gen) {
  704. case 2:
  705. case 3:
  706. instdone[0] = I915_READ(INSTDONE);
  707. break;
  708. case 4:
  709. case 5:
  710. case 6:
  711. instdone[0] = I915_READ(INSTDONE_I965);
  712. instdone[1] = I915_READ(INSTDONE1);
  713. break;
  714. default:
  715. WARN_ONCE(1, "Unsupported platform\n");
  716. case 7:
  717. instdone[0] = I915_READ(GEN7_INSTDONE_1);
  718. instdone[1] = I915_READ(GEN7_SC_INSTDONE);
  719. instdone[2] = I915_READ(GEN7_SAMPLER_INSTDONE);
  720. instdone[3] = I915_READ(GEN7_ROW_INSTDONE);
  721. break;
  722. }
  723. }
  724. #ifdef CONFIG_DEBUG_FS
  725. static struct drm_i915_error_object *
  726. i915_error_object_create(struct drm_i915_private *dev_priv,
  727. struct drm_i915_gem_object *src)
  728. {
  729. struct drm_i915_error_object *dst;
  730. int i, count;
  731. u32 reloc_offset;
  732. if (src == NULL || src->pages == NULL)
  733. return NULL;
  734. count = src->base.size / PAGE_SIZE;
  735. dst = kmalloc(sizeof(*dst) + count * sizeof(u32 *), GFP_ATOMIC);
  736. if (dst == NULL)
  737. return NULL;
  738. reloc_offset = src->gtt_offset;
  739. for (i = 0; i < count; i++) {
  740. unsigned long flags;
  741. void *d;
  742. d = kmalloc(PAGE_SIZE, GFP_ATOMIC);
  743. if (d == NULL)
  744. goto unwind;
  745. local_irq_save(flags);
  746. if (reloc_offset < dev_priv->mm.gtt_mappable_end &&
  747. src->has_global_gtt_mapping) {
  748. void __iomem *s;
  749. /* Simply ignore tiling or any overlapping fence.
  750. * It's part of the error state, and this hopefully
  751. * captures what the GPU read.
  752. */
  753. s = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping,
  754. reloc_offset);
  755. memcpy_fromio(d, s, PAGE_SIZE);
  756. io_mapping_unmap_atomic(s);
  757. } else {
  758. struct page *page;
  759. void *s;
  760. page = i915_gem_object_get_page(src, i);
  761. drm_clflush_pages(&page, 1);
  762. s = kmap_atomic(page);
  763. memcpy(d, s, PAGE_SIZE);
  764. kunmap_atomic(s);
  765. drm_clflush_pages(&page, 1);
  766. }
  767. local_irq_restore(flags);
  768. dst->pages[i] = d;
  769. reloc_offset += PAGE_SIZE;
  770. }
  771. dst->page_count = count;
  772. dst->gtt_offset = src->gtt_offset;
  773. return dst;
  774. unwind:
  775. while (i--)
  776. kfree(dst->pages[i]);
  777. kfree(dst);
  778. return NULL;
  779. }
  780. static void
  781. i915_error_object_free(struct drm_i915_error_object *obj)
  782. {
  783. int page;
  784. if (obj == NULL)
  785. return;
  786. for (page = 0; page < obj->page_count; page++)
  787. kfree(obj->pages[page]);
  788. kfree(obj);
  789. }
  790. void
  791. i915_error_state_free(struct kref *error_ref)
  792. {
  793. struct drm_i915_error_state *error = container_of(error_ref,
  794. typeof(*error), ref);
  795. int i;
  796. for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
  797. i915_error_object_free(error->ring[i].batchbuffer);
  798. i915_error_object_free(error->ring[i].ringbuffer);
  799. kfree(error->ring[i].requests);
  800. }
  801. kfree(error->active_bo);
  802. kfree(error->overlay);
  803. kfree(error);
  804. }
  805. static void capture_bo(struct drm_i915_error_buffer *err,
  806. struct drm_i915_gem_object *obj)
  807. {
  808. err->size = obj->base.size;
  809. err->name = obj->base.name;
  810. err->rseqno = obj->last_read_seqno;
  811. err->wseqno = obj->last_write_seqno;
  812. err->gtt_offset = obj->gtt_offset;
  813. err->read_domains = obj->base.read_domains;
  814. err->write_domain = obj->base.write_domain;
  815. err->fence_reg = obj->fence_reg;
  816. err->pinned = 0;
  817. if (obj->pin_count > 0)
  818. err->pinned = 1;
  819. if (obj->user_pin_count > 0)
  820. err->pinned = -1;
  821. err->tiling = obj->tiling_mode;
  822. err->dirty = obj->dirty;
  823. err->purgeable = obj->madv != I915_MADV_WILLNEED;
  824. err->ring = obj->ring ? obj->ring->id : -1;
  825. err->cache_level = obj->cache_level;
  826. }
  827. static u32 capture_active_bo(struct drm_i915_error_buffer *err,
  828. int count, struct list_head *head)
  829. {
  830. struct drm_i915_gem_object *obj;
  831. int i = 0;
  832. list_for_each_entry(obj, head, mm_list) {
  833. capture_bo(err++, obj);
  834. if (++i == count)
  835. break;
  836. }
  837. return i;
  838. }
  839. static u32 capture_pinned_bo(struct drm_i915_error_buffer *err,
  840. int count, struct list_head *head)
  841. {
  842. struct drm_i915_gem_object *obj;
  843. int i = 0;
  844. list_for_each_entry(obj, head, gtt_list) {
  845. if (obj->pin_count == 0)
  846. continue;
  847. capture_bo(err++, obj);
  848. if (++i == count)
  849. break;
  850. }
  851. return i;
  852. }
  853. static void i915_gem_record_fences(struct drm_device *dev,
  854. struct drm_i915_error_state *error)
  855. {
  856. struct drm_i915_private *dev_priv = dev->dev_private;
  857. int i;
  858. /* Fences */
  859. switch (INTEL_INFO(dev)->gen) {
  860. case 7:
  861. case 6:
  862. for (i = 0; i < 16; i++)
  863. error->fence[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8));
  864. break;
  865. case 5:
  866. case 4:
  867. for (i = 0; i < 16; i++)
  868. error->fence[i] = I915_READ64(FENCE_REG_965_0 + (i * 8));
  869. break;
  870. case 3:
  871. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
  872. for (i = 0; i < 8; i++)
  873. error->fence[i+8] = I915_READ(FENCE_REG_945_8 + (i * 4));
  874. case 2:
  875. for (i = 0; i < 8; i++)
  876. error->fence[i] = I915_READ(FENCE_REG_830_0 + (i * 4));
  877. break;
  878. }
  879. }
  880. static struct drm_i915_error_object *
  881. i915_error_first_batchbuffer(struct drm_i915_private *dev_priv,
  882. struct intel_ring_buffer *ring)
  883. {
  884. struct drm_i915_gem_object *obj;
  885. u32 seqno;
  886. if (!ring->get_seqno)
  887. return NULL;
  888. seqno = ring->get_seqno(ring, false);
  889. list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list) {
  890. if (obj->ring != ring)
  891. continue;
  892. if (i915_seqno_passed(seqno, obj->last_read_seqno))
  893. continue;
  894. if ((obj->base.read_domains & I915_GEM_DOMAIN_COMMAND) == 0)
  895. continue;
  896. /* We need to copy these to an anonymous buffer as the simplest
  897. * method to avoid being overwritten by userspace.
  898. */
  899. return i915_error_object_create(dev_priv, obj);
  900. }
  901. return NULL;
  902. }
  903. static void i915_record_ring_state(struct drm_device *dev,
  904. struct drm_i915_error_state *error,
  905. struct intel_ring_buffer *ring)
  906. {
  907. struct drm_i915_private *dev_priv = dev->dev_private;
  908. if (INTEL_INFO(dev)->gen >= 6) {
  909. error->rc_psmi[ring->id] = I915_READ(ring->mmio_base + 0x50);
  910. error->fault_reg[ring->id] = I915_READ(RING_FAULT_REG(ring));
  911. error->semaphore_mboxes[ring->id][0]
  912. = I915_READ(RING_SYNC_0(ring->mmio_base));
  913. error->semaphore_mboxes[ring->id][1]
  914. = I915_READ(RING_SYNC_1(ring->mmio_base));
  915. }
  916. if (INTEL_INFO(dev)->gen >= 4) {
  917. error->faddr[ring->id] = I915_READ(RING_DMA_FADD(ring->mmio_base));
  918. error->ipeir[ring->id] = I915_READ(RING_IPEIR(ring->mmio_base));
  919. error->ipehr[ring->id] = I915_READ(RING_IPEHR(ring->mmio_base));
  920. error->instdone[ring->id] = I915_READ(RING_INSTDONE(ring->mmio_base));
  921. error->instps[ring->id] = I915_READ(RING_INSTPS(ring->mmio_base));
  922. if (ring->id == RCS)
  923. error->bbaddr = I915_READ64(BB_ADDR);
  924. } else {
  925. error->faddr[ring->id] = I915_READ(DMA_FADD_I8XX);
  926. error->ipeir[ring->id] = I915_READ(IPEIR);
  927. error->ipehr[ring->id] = I915_READ(IPEHR);
  928. error->instdone[ring->id] = I915_READ(INSTDONE);
  929. }
  930. error->waiting[ring->id] = waitqueue_active(&ring->irq_queue);
  931. error->instpm[ring->id] = I915_READ(RING_INSTPM(ring->mmio_base));
  932. error->seqno[ring->id] = ring->get_seqno(ring, false);
  933. error->acthd[ring->id] = intel_ring_get_active_head(ring);
  934. error->head[ring->id] = I915_READ_HEAD(ring);
  935. error->tail[ring->id] = I915_READ_TAIL(ring);
  936. error->cpu_ring_head[ring->id] = ring->head;
  937. error->cpu_ring_tail[ring->id] = ring->tail;
  938. }
  939. static void i915_gem_record_rings(struct drm_device *dev,
  940. struct drm_i915_error_state *error)
  941. {
  942. struct drm_i915_private *dev_priv = dev->dev_private;
  943. struct intel_ring_buffer *ring;
  944. struct drm_i915_gem_request *request;
  945. int i, count;
  946. for_each_ring(ring, dev_priv, i) {
  947. i915_record_ring_state(dev, error, ring);
  948. error->ring[i].batchbuffer =
  949. i915_error_first_batchbuffer(dev_priv, ring);
  950. error->ring[i].ringbuffer =
  951. i915_error_object_create(dev_priv, ring->obj);
  952. count = 0;
  953. list_for_each_entry(request, &ring->request_list, list)
  954. count++;
  955. error->ring[i].num_requests = count;
  956. error->ring[i].requests =
  957. kmalloc(count*sizeof(struct drm_i915_error_request),
  958. GFP_ATOMIC);
  959. if (error->ring[i].requests == NULL) {
  960. error->ring[i].num_requests = 0;
  961. continue;
  962. }
  963. count = 0;
  964. list_for_each_entry(request, &ring->request_list, list) {
  965. struct drm_i915_error_request *erq;
  966. erq = &error->ring[i].requests[count++];
  967. erq->seqno = request->seqno;
  968. erq->jiffies = request->emitted_jiffies;
  969. erq->tail = request->tail;
  970. }
  971. }
  972. }
  973. /**
  974. * i915_capture_error_state - capture an error record for later analysis
  975. * @dev: drm device
  976. *
  977. * Should be called when an error is detected (either a hang or an error
  978. * interrupt) to capture error state from the time of the error. Fills
  979. * out a structure which becomes available in debugfs for user level tools
  980. * to pick up.
  981. */
  982. static void i915_capture_error_state(struct drm_device *dev)
  983. {
  984. struct drm_i915_private *dev_priv = dev->dev_private;
  985. struct drm_i915_gem_object *obj;
  986. struct drm_i915_error_state *error;
  987. unsigned long flags;
  988. int i, pipe;
  989. spin_lock_irqsave(&dev_priv->error_lock, flags);
  990. error = dev_priv->first_error;
  991. spin_unlock_irqrestore(&dev_priv->error_lock, flags);
  992. if (error)
  993. return;
  994. /* Account for pipe specific data like PIPE*STAT */
  995. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  996. if (!error) {
  997. DRM_DEBUG_DRIVER("out of memory, not capturing error state\n");
  998. return;
  999. }
  1000. DRM_INFO("capturing error event; look for more information in /debug/dri/%d/i915_error_state\n",
  1001. dev->primary->index);
  1002. kref_init(&error->ref);
  1003. error->eir = I915_READ(EIR);
  1004. error->pgtbl_er = I915_READ(PGTBL_ER);
  1005. error->ccid = I915_READ(CCID);
  1006. if (HAS_PCH_SPLIT(dev))
  1007. error->ier = I915_READ(DEIER) | I915_READ(GTIER);
  1008. else if (IS_VALLEYVIEW(dev))
  1009. error->ier = I915_READ(GTIER) | I915_READ(VLV_IER);
  1010. else if (IS_GEN2(dev))
  1011. error->ier = I915_READ16(IER);
  1012. else
  1013. error->ier = I915_READ(IER);
  1014. for_each_pipe(pipe)
  1015. error->pipestat[pipe] = I915_READ(PIPESTAT(pipe));
  1016. if (INTEL_INFO(dev)->gen >= 6) {
  1017. error->error = I915_READ(ERROR_GEN6);
  1018. error->done_reg = I915_READ(DONE_REG);
  1019. }
  1020. if (INTEL_INFO(dev)->gen == 7)
  1021. error->err_int = I915_READ(GEN7_ERR_INT);
  1022. i915_get_extra_instdone(dev, error->extra_instdone);
  1023. i915_gem_record_fences(dev, error);
  1024. i915_gem_record_rings(dev, error);
  1025. /* Record buffers on the active and pinned lists. */
  1026. error->active_bo = NULL;
  1027. error->pinned_bo = NULL;
  1028. i = 0;
  1029. list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list)
  1030. i++;
  1031. error->active_bo_count = i;
  1032. list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list)
  1033. if (obj->pin_count)
  1034. i++;
  1035. error->pinned_bo_count = i - error->active_bo_count;
  1036. error->active_bo = NULL;
  1037. error->pinned_bo = NULL;
  1038. if (i) {
  1039. error->active_bo = kmalloc(sizeof(*error->active_bo)*i,
  1040. GFP_ATOMIC);
  1041. if (error->active_bo)
  1042. error->pinned_bo =
  1043. error->active_bo + error->active_bo_count;
  1044. }
  1045. if (error->active_bo)
  1046. error->active_bo_count =
  1047. capture_active_bo(error->active_bo,
  1048. error->active_bo_count,
  1049. &dev_priv->mm.active_list);
  1050. if (error->pinned_bo)
  1051. error->pinned_bo_count =
  1052. capture_pinned_bo(error->pinned_bo,
  1053. error->pinned_bo_count,
  1054. &dev_priv->mm.bound_list);
  1055. do_gettimeofday(&error->time);
  1056. error->overlay = intel_overlay_capture_error_state(dev);
  1057. error->display = intel_display_capture_error_state(dev);
  1058. spin_lock_irqsave(&dev_priv->error_lock, flags);
  1059. if (dev_priv->first_error == NULL) {
  1060. dev_priv->first_error = error;
  1061. error = NULL;
  1062. }
  1063. spin_unlock_irqrestore(&dev_priv->error_lock, flags);
  1064. if (error)
  1065. i915_error_state_free(&error->ref);
  1066. }
  1067. void i915_destroy_error_state(struct drm_device *dev)
  1068. {
  1069. struct drm_i915_private *dev_priv = dev->dev_private;
  1070. struct drm_i915_error_state *error;
  1071. unsigned long flags;
  1072. spin_lock_irqsave(&dev_priv->error_lock, flags);
  1073. error = dev_priv->first_error;
  1074. dev_priv->first_error = NULL;
  1075. spin_unlock_irqrestore(&dev_priv->error_lock, flags);
  1076. if (error)
  1077. kref_put(&error->ref, i915_error_state_free);
  1078. }
  1079. #else
  1080. #define i915_capture_error_state(x)
  1081. #endif
  1082. static void i915_report_and_clear_eir(struct drm_device *dev)
  1083. {
  1084. struct drm_i915_private *dev_priv = dev->dev_private;
  1085. uint32_t instdone[I915_NUM_INSTDONE_REG];
  1086. u32 eir = I915_READ(EIR);
  1087. int pipe, i;
  1088. if (!eir)
  1089. return;
  1090. pr_err("render error detected, EIR: 0x%08x\n", eir);
  1091. i915_get_extra_instdone(dev, instdone);
  1092. if (IS_G4X(dev)) {
  1093. if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
  1094. u32 ipeir = I915_READ(IPEIR_I965);
  1095. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1096. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1097. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1098. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1099. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1100. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1101. I915_WRITE(IPEIR_I965, ipeir);
  1102. POSTING_READ(IPEIR_I965);
  1103. }
  1104. if (eir & GM45_ERROR_PAGE_TABLE) {
  1105. u32 pgtbl_err = I915_READ(PGTBL_ER);
  1106. pr_err("page table error\n");
  1107. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  1108. I915_WRITE(PGTBL_ER, pgtbl_err);
  1109. POSTING_READ(PGTBL_ER);
  1110. }
  1111. }
  1112. if (!IS_GEN2(dev)) {
  1113. if (eir & I915_ERROR_PAGE_TABLE) {
  1114. u32 pgtbl_err = I915_READ(PGTBL_ER);
  1115. pr_err("page table error\n");
  1116. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  1117. I915_WRITE(PGTBL_ER, pgtbl_err);
  1118. POSTING_READ(PGTBL_ER);
  1119. }
  1120. }
  1121. if (eir & I915_ERROR_MEMORY_REFRESH) {
  1122. pr_err("memory refresh error:\n");
  1123. for_each_pipe(pipe)
  1124. pr_err("pipe %c stat: 0x%08x\n",
  1125. pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
  1126. /* pipestat has already been acked */
  1127. }
  1128. if (eir & I915_ERROR_INSTRUCTION) {
  1129. pr_err("instruction error\n");
  1130. pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
  1131. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1132. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1133. if (INTEL_INFO(dev)->gen < 4) {
  1134. u32 ipeir = I915_READ(IPEIR);
  1135. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
  1136. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
  1137. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
  1138. I915_WRITE(IPEIR, ipeir);
  1139. POSTING_READ(IPEIR);
  1140. } else {
  1141. u32 ipeir = I915_READ(IPEIR_I965);
  1142. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1143. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1144. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1145. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1146. I915_WRITE(IPEIR_I965, ipeir);
  1147. POSTING_READ(IPEIR_I965);
  1148. }
  1149. }
  1150. I915_WRITE(EIR, eir);
  1151. POSTING_READ(EIR);
  1152. eir = I915_READ(EIR);
  1153. if (eir) {
  1154. /*
  1155. * some errors might have become stuck,
  1156. * mask them.
  1157. */
  1158. DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
  1159. I915_WRITE(EMR, I915_READ(EMR) | eir);
  1160. I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  1161. }
  1162. }
  1163. /**
  1164. * i915_handle_error - handle an error interrupt
  1165. * @dev: drm device
  1166. *
  1167. * Do some basic checking of regsiter state at error interrupt time and
  1168. * dump it to the syslog. Also call i915_capture_error_state() to make
  1169. * sure we get a record and make it available in debugfs. Fire a uevent
  1170. * so userspace knows something bad happened (should trigger collection
  1171. * of a ring dump etc.).
  1172. */
  1173. void i915_handle_error(struct drm_device *dev, bool wedged)
  1174. {
  1175. struct drm_i915_private *dev_priv = dev->dev_private;
  1176. struct intel_ring_buffer *ring;
  1177. int i;
  1178. i915_capture_error_state(dev);
  1179. i915_report_and_clear_eir(dev);
  1180. if (wedged) {
  1181. INIT_COMPLETION(dev_priv->error_completion);
  1182. atomic_set(&dev_priv->mm.wedged, 1);
  1183. /*
  1184. * Wakeup waiting processes so they don't hang
  1185. */
  1186. for_each_ring(ring, dev_priv, i)
  1187. wake_up_all(&ring->irq_queue);
  1188. }
  1189. queue_work(dev_priv->wq, &dev_priv->error_work);
  1190. }
  1191. static void i915_pageflip_stall_check(struct drm_device *dev, int pipe)
  1192. {
  1193. drm_i915_private_t *dev_priv = dev->dev_private;
  1194. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1195. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1196. struct drm_i915_gem_object *obj;
  1197. struct intel_unpin_work *work;
  1198. unsigned long flags;
  1199. bool stall_detected;
  1200. /* Ignore early vblank irqs */
  1201. if (intel_crtc == NULL)
  1202. return;
  1203. spin_lock_irqsave(&dev->event_lock, flags);
  1204. work = intel_crtc->unpin_work;
  1205. if (work == NULL || work->pending || !work->enable_stall_check) {
  1206. /* Either the pending flip IRQ arrived, or we're too early. Don't check */
  1207. spin_unlock_irqrestore(&dev->event_lock, flags);
  1208. return;
  1209. }
  1210. /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
  1211. obj = work->pending_flip_obj;
  1212. if (INTEL_INFO(dev)->gen >= 4) {
  1213. int dspsurf = DSPSURF(intel_crtc->plane);
  1214. stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
  1215. obj->gtt_offset;
  1216. } else {
  1217. int dspaddr = DSPADDR(intel_crtc->plane);
  1218. stall_detected = I915_READ(dspaddr) == (obj->gtt_offset +
  1219. crtc->y * crtc->fb->pitches[0] +
  1220. crtc->x * crtc->fb->bits_per_pixel/8);
  1221. }
  1222. spin_unlock_irqrestore(&dev->event_lock, flags);
  1223. if (stall_detected) {
  1224. DRM_DEBUG_DRIVER("Pageflip stall detected\n");
  1225. intel_prepare_page_flip(dev, intel_crtc->plane);
  1226. }
  1227. }
  1228. /* Called from drm generic code, passed 'crtc' which
  1229. * we use as a pipe index
  1230. */
  1231. static int i915_enable_vblank(struct drm_device *dev, int pipe)
  1232. {
  1233. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1234. unsigned long irqflags;
  1235. if (!i915_pipe_enabled(dev, pipe))
  1236. return -EINVAL;
  1237. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1238. if (INTEL_INFO(dev)->gen >= 4)
  1239. i915_enable_pipestat(dev_priv, pipe,
  1240. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1241. else
  1242. i915_enable_pipestat(dev_priv, pipe,
  1243. PIPE_VBLANK_INTERRUPT_ENABLE);
  1244. /* maintain vblank delivery even in deep C-states */
  1245. if (dev_priv->info->gen == 3)
  1246. I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
  1247. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1248. return 0;
  1249. }
  1250. static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
  1251. {
  1252. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1253. unsigned long irqflags;
  1254. if (!i915_pipe_enabled(dev, pipe))
  1255. return -EINVAL;
  1256. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1257. ironlake_enable_display_irq(dev_priv, (pipe == 0) ?
  1258. DE_PIPEA_VBLANK : DE_PIPEB_VBLANK);
  1259. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1260. return 0;
  1261. }
  1262. static int ivybridge_enable_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. if (!i915_pipe_enabled(dev, pipe))
  1267. return -EINVAL;
  1268. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1269. ironlake_enable_display_irq(dev_priv,
  1270. DE_PIPEA_VBLANK_IVB << (5 * pipe));
  1271. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1272. return 0;
  1273. }
  1274. static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
  1275. {
  1276. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1277. unsigned long irqflags;
  1278. u32 imr;
  1279. if (!i915_pipe_enabled(dev, pipe))
  1280. return -EINVAL;
  1281. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1282. imr = I915_READ(VLV_IMR);
  1283. if (pipe == 0)
  1284. imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
  1285. else
  1286. imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1287. I915_WRITE(VLV_IMR, imr);
  1288. i915_enable_pipestat(dev_priv, pipe,
  1289. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1290. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1291. return 0;
  1292. }
  1293. /* Called from drm generic code, passed 'crtc' which
  1294. * we use as a pipe index
  1295. */
  1296. static void i915_disable_vblank(struct drm_device *dev, int pipe)
  1297. {
  1298. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1299. unsigned long irqflags;
  1300. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1301. if (dev_priv->info->gen == 3)
  1302. I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
  1303. i915_disable_pipestat(dev_priv, pipe,
  1304. PIPE_VBLANK_INTERRUPT_ENABLE |
  1305. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1306. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1307. }
  1308. static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
  1309. {
  1310. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1311. unsigned long irqflags;
  1312. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1313. ironlake_disable_display_irq(dev_priv, (pipe == 0) ?
  1314. DE_PIPEA_VBLANK : DE_PIPEB_VBLANK);
  1315. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1316. }
  1317. static void ivybridge_disable_vblank(struct drm_device *dev, int pipe)
  1318. {
  1319. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1320. unsigned long irqflags;
  1321. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1322. ironlake_disable_display_irq(dev_priv,
  1323. DE_PIPEA_VBLANK_IVB << (pipe * 5));
  1324. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1325. }
  1326. static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
  1327. {
  1328. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1329. unsigned long irqflags;
  1330. u32 imr;
  1331. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1332. i915_disable_pipestat(dev_priv, pipe,
  1333. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1334. imr = I915_READ(VLV_IMR);
  1335. if (pipe == 0)
  1336. imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
  1337. else
  1338. imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1339. I915_WRITE(VLV_IMR, imr);
  1340. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1341. }
  1342. static u32
  1343. ring_last_seqno(struct intel_ring_buffer *ring)
  1344. {
  1345. return list_entry(ring->request_list.prev,
  1346. struct drm_i915_gem_request, list)->seqno;
  1347. }
  1348. static bool i915_hangcheck_ring_idle(struct intel_ring_buffer *ring, bool *err)
  1349. {
  1350. if (list_empty(&ring->request_list) ||
  1351. i915_seqno_passed(ring->get_seqno(ring, false),
  1352. ring_last_seqno(ring))) {
  1353. /* Issue a wake-up to catch stuck h/w. */
  1354. if (waitqueue_active(&ring->irq_queue)) {
  1355. DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
  1356. ring->name);
  1357. wake_up_all(&ring->irq_queue);
  1358. *err = true;
  1359. }
  1360. return true;
  1361. }
  1362. return false;
  1363. }
  1364. static bool kick_ring(struct intel_ring_buffer *ring)
  1365. {
  1366. struct drm_device *dev = ring->dev;
  1367. struct drm_i915_private *dev_priv = dev->dev_private;
  1368. u32 tmp = I915_READ_CTL(ring);
  1369. if (tmp & RING_WAIT) {
  1370. DRM_ERROR("Kicking stuck wait on %s\n",
  1371. ring->name);
  1372. I915_WRITE_CTL(ring, tmp);
  1373. return true;
  1374. }
  1375. return false;
  1376. }
  1377. static bool i915_hangcheck_hung(struct drm_device *dev)
  1378. {
  1379. drm_i915_private_t *dev_priv = dev->dev_private;
  1380. if (dev_priv->hangcheck_count++ > 1) {
  1381. bool hung = true;
  1382. DRM_ERROR("Hangcheck timer elapsed... GPU hung\n");
  1383. i915_handle_error(dev, true);
  1384. if (!IS_GEN2(dev)) {
  1385. struct intel_ring_buffer *ring;
  1386. int i;
  1387. /* Is the chip hanging on a WAIT_FOR_EVENT?
  1388. * If so we can simply poke the RB_WAIT bit
  1389. * and break the hang. This should work on
  1390. * all but the second generation chipsets.
  1391. */
  1392. for_each_ring(ring, dev_priv, i)
  1393. hung &= !kick_ring(ring);
  1394. }
  1395. return hung;
  1396. }
  1397. return false;
  1398. }
  1399. /**
  1400. * This is called when the chip hasn't reported back with completed
  1401. * batchbuffers in a long time. The first time this is called we simply record
  1402. * ACTHD. If ACTHD hasn't changed by the time the hangcheck timer elapses
  1403. * again, we assume the chip is wedged and try to fix it.
  1404. */
  1405. void i915_hangcheck_elapsed(unsigned long data)
  1406. {
  1407. struct drm_device *dev = (struct drm_device *)data;
  1408. drm_i915_private_t *dev_priv = dev->dev_private;
  1409. uint32_t acthd[I915_NUM_RINGS], instdone[I915_NUM_INSTDONE_REG];
  1410. struct intel_ring_buffer *ring;
  1411. bool err = false, idle;
  1412. int i;
  1413. if (!i915_enable_hangcheck)
  1414. return;
  1415. memset(acthd, 0, sizeof(acthd));
  1416. idle = true;
  1417. for_each_ring(ring, dev_priv, i) {
  1418. idle &= i915_hangcheck_ring_idle(ring, &err);
  1419. acthd[i] = intel_ring_get_active_head(ring);
  1420. }
  1421. /* If all work is done then ACTHD clearly hasn't advanced. */
  1422. if (idle) {
  1423. if (err) {
  1424. if (i915_hangcheck_hung(dev))
  1425. return;
  1426. goto repeat;
  1427. }
  1428. dev_priv->hangcheck_count = 0;
  1429. return;
  1430. }
  1431. i915_get_extra_instdone(dev, instdone);
  1432. if (memcmp(dev_priv->last_acthd, acthd, sizeof(acthd)) == 0 &&
  1433. memcmp(dev_priv->prev_instdone, instdone, sizeof(instdone)) == 0) {
  1434. if (i915_hangcheck_hung(dev))
  1435. return;
  1436. } else {
  1437. dev_priv->hangcheck_count = 0;
  1438. memcpy(dev_priv->last_acthd, acthd, sizeof(acthd));
  1439. memcpy(dev_priv->prev_instdone, instdone, sizeof(instdone));
  1440. }
  1441. repeat:
  1442. /* Reset timer case chip hangs without another request being added */
  1443. mod_timer(&dev_priv->hangcheck_timer,
  1444. round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
  1445. }
  1446. /* drm_dma.h hooks
  1447. */
  1448. static 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. I915_WRITE(HWSTAM, 0xeffe);
  1453. /* XXX hotplug from PCH */
  1454. I915_WRITE(DEIMR, 0xffffffff);
  1455. I915_WRITE(DEIER, 0x0);
  1456. POSTING_READ(DEIER);
  1457. /* and GT */
  1458. I915_WRITE(GTIMR, 0xffffffff);
  1459. I915_WRITE(GTIER, 0x0);
  1460. POSTING_READ(GTIER);
  1461. /* south display irq */
  1462. I915_WRITE(SDEIMR, 0xffffffff);
  1463. I915_WRITE(SDEIER, 0x0);
  1464. POSTING_READ(SDEIER);
  1465. }
  1466. static void valleyview_irq_preinstall(struct drm_device *dev)
  1467. {
  1468. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1469. int pipe;
  1470. atomic_set(&dev_priv->irq_received, 0);
  1471. /* VLV magic */
  1472. I915_WRITE(VLV_IMR, 0);
  1473. I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
  1474. I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
  1475. I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
  1476. /* and GT */
  1477. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1478. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1479. I915_WRITE(GTIMR, 0xffffffff);
  1480. I915_WRITE(GTIER, 0x0);
  1481. POSTING_READ(GTIER);
  1482. I915_WRITE(DPINVGTT, 0xff);
  1483. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1484. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  1485. for_each_pipe(pipe)
  1486. I915_WRITE(PIPESTAT(pipe), 0xffff);
  1487. I915_WRITE(VLV_IIR, 0xffffffff);
  1488. I915_WRITE(VLV_IMR, 0xffffffff);
  1489. I915_WRITE(VLV_IER, 0x0);
  1490. POSTING_READ(VLV_IER);
  1491. }
  1492. /*
  1493. * Enable digital hotplug on the PCH, and configure the DP short pulse
  1494. * duration to 2ms (which is the minimum in the Display Port spec)
  1495. *
  1496. * This register is the same on all known PCH chips.
  1497. */
  1498. static void ironlake_enable_pch_hotplug(struct drm_device *dev)
  1499. {
  1500. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1501. u32 hotplug;
  1502. hotplug = I915_READ(PCH_PORT_HOTPLUG);
  1503. hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
  1504. hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
  1505. hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
  1506. hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
  1507. I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
  1508. }
  1509. static int ironlake_irq_postinstall(struct drm_device *dev)
  1510. {
  1511. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1512. /* enable kind of interrupts always enabled */
  1513. u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
  1514. DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE;
  1515. u32 render_irqs;
  1516. u32 hotplug_mask;
  1517. dev_priv->irq_mask = ~display_mask;
  1518. /* should always can generate irq */
  1519. I915_WRITE(DEIIR, I915_READ(DEIIR));
  1520. I915_WRITE(DEIMR, dev_priv->irq_mask);
  1521. I915_WRITE(DEIER, display_mask | DE_PIPEA_VBLANK | DE_PIPEB_VBLANK);
  1522. POSTING_READ(DEIER);
  1523. dev_priv->gt_irq_mask = ~0;
  1524. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1525. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  1526. if (IS_GEN6(dev))
  1527. render_irqs =
  1528. GT_USER_INTERRUPT |
  1529. GEN6_BSD_USER_INTERRUPT |
  1530. GEN6_BLITTER_USER_INTERRUPT;
  1531. else
  1532. render_irqs =
  1533. GT_USER_INTERRUPT |
  1534. GT_PIPE_NOTIFY |
  1535. GT_BSD_USER_INTERRUPT;
  1536. I915_WRITE(GTIER, render_irqs);
  1537. POSTING_READ(GTIER);
  1538. if (HAS_PCH_CPT(dev)) {
  1539. hotplug_mask = (SDE_CRT_HOTPLUG_CPT |
  1540. SDE_PORTB_HOTPLUG_CPT |
  1541. SDE_PORTC_HOTPLUG_CPT |
  1542. SDE_PORTD_HOTPLUG_CPT);
  1543. } else {
  1544. hotplug_mask = (SDE_CRT_HOTPLUG |
  1545. SDE_PORTB_HOTPLUG |
  1546. SDE_PORTC_HOTPLUG |
  1547. SDE_PORTD_HOTPLUG |
  1548. SDE_AUX_MASK);
  1549. }
  1550. dev_priv->pch_irq_mask = ~hotplug_mask;
  1551. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  1552. I915_WRITE(SDEIMR, dev_priv->pch_irq_mask);
  1553. I915_WRITE(SDEIER, hotplug_mask);
  1554. POSTING_READ(SDEIER);
  1555. ironlake_enable_pch_hotplug(dev);
  1556. if (IS_IRONLAKE_M(dev)) {
  1557. /* Clear & enable PCU event interrupts */
  1558. I915_WRITE(DEIIR, DE_PCU_EVENT);
  1559. I915_WRITE(DEIER, I915_READ(DEIER) | DE_PCU_EVENT);
  1560. ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
  1561. }
  1562. return 0;
  1563. }
  1564. static int ivybridge_irq_postinstall(struct drm_device *dev)
  1565. {
  1566. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1567. /* enable kind of interrupts always enabled */
  1568. u32 display_mask =
  1569. DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | DE_PCH_EVENT_IVB |
  1570. DE_PLANEC_FLIP_DONE_IVB |
  1571. DE_PLANEB_FLIP_DONE_IVB |
  1572. DE_PLANEA_FLIP_DONE_IVB;
  1573. u32 render_irqs;
  1574. u32 hotplug_mask;
  1575. dev_priv->irq_mask = ~display_mask;
  1576. /* should always can generate irq */
  1577. I915_WRITE(DEIIR, I915_READ(DEIIR));
  1578. I915_WRITE(DEIMR, dev_priv->irq_mask);
  1579. I915_WRITE(DEIER,
  1580. display_mask |
  1581. DE_PIPEC_VBLANK_IVB |
  1582. DE_PIPEB_VBLANK_IVB |
  1583. DE_PIPEA_VBLANK_IVB);
  1584. POSTING_READ(DEIER);
  1585. dev_priv->gt_irq_mask = ~GT_GEN7_L3_PARITY_ERROR_INTERRUPT;
  1586. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1587. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  1588. render_irqs = GT_USER_INTERRUPT | GEN6_BSD_USER_INTERRUPT |
  1589. GEN6_BLITTER_USER_INTERRUPT | GT_GEN7_L3_PARITY_ERROR_INTERRUPT;
  1590. I915_WRITE(GTIER, render_irqs);
  1591. POSTING_READ(GTIER);
  1592. hotplug_mask = (SDE_CRT_HOTPLUG_CPT |
  1593. SDE_PORTB_HOTPLUG_CPT |
  1594. SDE_PORTC_HOTPLUG_CPT |
  1595. SDE_PORTD_HOTPLUG_CPT);
  1596. dev_priv->pch_irq_mask = ~hotplug_mask;
  1597. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  1598. I915_WRITE(SDEIMR, dev_priv->pch_irq_mask);
  1599. I915_WRITE(SDEIER, hotplug_mask);
  1600. POSTING_READ(SDEIER);
  1601. ironlake_enable_pch_hotplug(dev);
  1602. return 0;
  1603. }
  1604. static int valleyview_irq_postinstall(struct drm_device *dev)
  1605. {
  1606. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1607. u32 enable_mask;
  1608. u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
  1609. u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV;
  1610. u32 render_irqs;
  1611. u16 msid;
  1612. enable_mask = I915_DISPLAY_PORT_INTERRUPT;
  1613. enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1614. I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
  1615. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  1616. I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1617. /*
  1618. *Leave vblank interrupts masked initially. enable/disable will
  1619. * toggle them based on usage.
  1620. */
  1621. dev_priv->irq_mask = (~enable_mask) |
  1622. I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
  1623. I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1624. dev_priv->pipestat[0] = 0;
  1625. dev_priv->pipestat[1] = 0;
  1626. /* Hack for broken MSIs on VLV */
  1627. pci_write_config_dword(dev_priv->dev->pdev, 0x94, 0xfee00000);
  1628. pci_read_config_word(dev->pdev, 0x98, &msid);
  1629. msid &= 0xff; /* mask out delivery bits */
  1630. msid |= (1<<14);
  1631. pci_write_config_word(dev_priv->dev->pdev, 0x98, msid);
  1632. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  1633. I915_WRITE(VLV_IER, enable_mask);
  1634. I915_WRITE(VLV_IIR, 0xffffffff);
  1635. I915_WRITE(PIPESTAT(0), 0xffff);
  1636. I915_WRITE(PIPESTAT(1), 0xffff);
  1637. POSTING_READ(VLV_IER);
  1638. i915_enable_pipestat(dev_priv, 0, pipestat_enable);
  1639. i915_enable_pipestat(dev_priv, 1, pipestat_enable);
  1640. I915_WRITE(VLV_IIR, 0xffffffff);
  1641. I915_WRITE(VLV_IIR, 0xffffffff);
  1642. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1643. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  1644. render_irqs = GT_USER_INTERRUPT | GEN6_BSD_USER_INTERRUPT |
  1645. GEN6_BLITTER_USER_INTERRUPT;
  1646. I915_WRITE(GTIER, render_irqs);
  1647. POSTING_READ(GTIER);
  1648. /* ack & enable invalid PTE error interrupts */
  1649. #if 0 /* FIXME: add support to irq handler for checking these bits */
  1650. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
  1651. I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
  1652. #endif
  1653. I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
  1654. /* Note HDMI and DP share bits */
  1655. if (dev_priv->hotplug_supported_mask & HDMIB_HOTPLUG_INT_STATUS)
  1656. hotplug_en |= HDMIB_HOTPLUG_INT_EN;
  1657. if (dev_priv->hotplug_supported_mask & HDMIC_HOTPLUG_INT_STATUS)
  1658. hotplug_en |= HDMIC_HOTPLUG_INT_EN;
  1659. if (dev_priv->hotplug_supported_mask & HDMID_HOTPLUG_INT_STATUS)
  1660. hotplug_en |= HDMID_HOTPLUG_INT_EN;
  1661. if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS_I915)
  1662. hotplug_en |= SDVOC_HOTPLUG_INT_EN;
  1663. if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS_I915)
  1664. hotplug_en |= SDVOB_HOTPLUG_INT_EN;
  1665. if (dev_priv->hotplug_supported_mask & CRT_HOTPLUG_INT_STATUS) {
  1666. hotplug_en |= CRT_HOTPLUG_INT_EN;
  1667. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  1668. }
  1669. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  1670. return 0;
  1671. }
  1672. static void valleyview_irq_uninstall(struct drm_device *dev)
  1673. {
  1674. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1675. int pipe;
  1676. if (!dev_priv)
  1677. return;
  1678. for_each_pipe(pipe)
  1679. I915_WRITE(PIPESTAT(pipe), 0xffff);
  1680. I915_WRITE(HWSTAM, 0xffffffff);
  1681. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1682. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  1683. for_each_pipe(pipe)
  1684. I915_WRITE(PIPESTAT(pipe), 0xffff);
  1685. I915_WRITE(VLV_IIR, 0xffffffff);
  1686. I915_WRITE(VLV_IMR, 0xffffffff);
  1687. I915_WRITE(VLV_IER, 0x0);
  1688. POSTING_READ(VLV_IER);
  1689. }
  1690. static void ironlake_irq_uninstall(struct drm_device *dev)
  1691. {
  1692. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1693. if (!dev_priv)
  1694. return;
  1695. I915_WRITE(HWSTAM, 0xffffffff);
  1696. I915_WRITE(DEIMR, 0xffffffff);
  1697. I915_WRITE(DEIER, 0x0);
  1698. I915_WRITE(DEIIR, I915_READ(DEIIR));
  1699. I915_WRITE(GTIMR, 0xffffffff);
  1700. I915_WRITE(GTIER, 0x0);
  1701. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1702. I915_WRITE(SDEIMR, 0xffffffff);
  1703. I915_WRITE(SDEIER, 0x0);
  1704. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  1705. }
  1706. static void i8xx_irq_preinstall(struct drm_device * dev)
  1707. {
  1708. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1709. int pipe;
  1710. atomic_set(&dev_priv->irq_received, 0);
  1711. for_each_pipe(pipe)
  1712. I915_WRITE(PIPESTAT(pipe), 0);
  1713. I915_WRITE16(IMR, 0xffff);
  1714. I915_WRITE16(IER, 0x0);
  1715. POSTING_READ16(IER);
  1716. }
  1717. static int i8xx_irq_postinstall(struct drm_device *dev)
  1718. {
  1719. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1720. dev_priv->pipestat[0] = 0;
  1721. dev_priv->pipestat[1] = 0;
  1722. I915_WRITE16(EMR,
  1723. ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  1724. /* Unmask the interrupts that we always want on. */
  1725. dev_priv->irq_mask =
  1726. ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1727. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  1728. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  1729. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  1730. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  1731. I915_WRITE16(IMR, dev_priv->irq_mask);
  1732. I915_WRITE16(IER,
  1733. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1734. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  1735. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
  1736. I915_USER_INTERRUPT);
  1737. POSTING_READ16(IER);
  1738. return 0;
  1739. }
  1740. static irqreturn_t i8xx_irq_handler(int irq, void *arg)
  1741. {
  1742. struct drm_device *dev = (struct drm_device *) arg;
  1743. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1744. u16 iir, new_iir;
  1745. u32 pipe_stats[2];
  1746. unsigned long irqflags;
  1747. int irq_received;
  1748. int pipe;
  1749. u16 flip_mask =
  1750. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  1751. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  1752. atomic_inc(&dev_priv->irq_received);
  1753. iir = I915_READ16(IIR);
  1754. if (iir == 0)
  1755. return IRQ_NONE;
  1756. while (iir & ~flip_mask) {
  1757. /* Can't rely on pipestat interrupt bit in iir as it might
  1758. * have been cleared after the pipestat interrupt was received.
  1759. * It doesn't set the bit in iir again, but it still produces
  1760. * interrupts (for non-MSI).
  1761. */
  1762. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1763. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  1764. i915_handle_error(dev, false);
  1765. for_each_pipe(pipe) {
  1766. int reg = PIPESTAT(pipe);
  1767. pipe_stats[pipe] = I915_READ(reg);
  1768. /*
  1769. * Clear the PIPE*STAT regs before the IIR
  1770. */
  1771. if (pipe_stats[pipe] & 0x8000ffff) {
  1772. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  1773. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  1774. pipe_name(pipe));
  1775. I915_WRITE(reg, pipe_stats[pipe]);
  1776. irq_received = 1;
  1777. }
  1778. }
  1779. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1780. I915_WRITE16(IIR, iir & ~flip_mask);
  1781. new_iir = I915_READ16(IIR); /* Flush posted writes */
  1782. i915_update_dri1_breadcrumb(dev);
  1783. if (iir & I915_USER_INTERRUPT)
  1784. notify_ring(dev, &dev_priv->ring[RCS]);
  1785. if (pipe_stats[0] & PIPE_VBLANK_INTERRUPT_STATUS &&
  1786. drm_handle_vblank(dev, 0)) {
  1787. if (iir & I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT) {
  1788. intel_prepare_page_flip(dev, 0);
  1789. intel_finish_page_flip(dev, 0);
  1790. flip_mask &= ~I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT;
  1791. }
  1792. }
  1793. if (pipe_stats[1] & PIPE_VBLANK_INTERRUPT_STATUS &&
  1794. drm_handle_vblank(dev, 1)) {
  1795. if (iir & I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT) {
  1796. intel_prepare_page_flip(dev, 1);
  1797. intel_finish_page_flip(dev, 1);
  1798. flip_mask &= ~I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  1799. }
  1800. }
  1801. iir = new_iir;
  1802. }
  1803. return IRQ_HANDLED;
  1804. }
  1805. static void i8xx_irq_uninstall(struct drm_device * dev)
  1806. {
  1807. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1808. int pipe;
  1809. for_each_pipe(pipe) {
  1810. /* Clear enable bits; then clear status bits */
  1811. I915_WRITE(PIPESTAT(pipe), 0);
  1812. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  1813. }
  1814. I915_WRITE16(IMR, 0xffff);
  1815. I915_WRITE16(IER, 0x0);
  1816. I915_WRITE16(IIR, I915_READ16(IIR));
  1817. }
  1818. static void i915_irq_preinstall(struct drm_device * dev)
  1819. {
  1820. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1821. int pipe;
  1822. atomic_set(&dev_priv->irq_received, 0);
  1823. if (I915_HAS_HOTPLUG(dev)) {
  1824. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1825. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  1826. }
  1827. I915_WRITE16(HWSTAM, 0xeffe);
  1828. for_each_pipe(pipe)
  1829. I915_WRITE(PIPESTAT(pipe), 0);
  1830. I915_WRITE(IMR, 0xffffffff);
  1831. I915_WRITE(IER, 0x0);
  1832. POSTING_READ(IER);
  1833. }
  1834. static int i915_irq_postinstall(struct drm_device *dev)
  1835. {
  1836. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1837. u32 enable_mask;
  1838. dev_priv->pipestat[0] = 0;
  1839. dev_priv->pipestat[1] = 0;
  1840. I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  1841. /* Unmask the interrupts that we always want on. */
  1842. dev_priv->irq_mask =
  1843. ~(I915_ASLE_INTERRUPT |
  1844. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1845. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  1846. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  1847. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  1848. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  1849. enable_mask =
  1850. I915_ASLE_INTERRUPT |
  1851. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1852. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  1853. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
  1854. I915_USER_INTERRUPT;
  1855. if (I915_HAS_HOTPLUG(dev)) {
  1856. /* Enable in IER... */
  1857. enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
  1858. /* and unmask in IMR */
  1859. dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
  1860. }
  1861. I915_WRITE(IMR, dev_priv->irq_mask);
  1862. I915_WRITE(IER, enable_mask);
  1863. POSTING_READ(IER);
  1864. if (I915_HAS_HOTPLUG(dev)) {
  1865. u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
  1866. if (dev_priv->hotplug_supported_mask & HDMIB_HOTPLUG_INT_STATUS)
  1867. hotplug_en |= HDMIB_HOTPLUG_INT_EN;
  1868. if (dev_priv->hotplug_supported_mask & HDMIC_HOTPLUG_INT_STATUS)
  1869. hotplug_en |= HDMIC_HOTPLUG_INT_EN;
  1870. if (dev_priv->hotplug_supported_mask & HDMID_HOTPLUG_INT_STATUS)
  1871. hotplug_en |= HDMID_HOTPLUG_INT_EN;
  1872. if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS_I915)
  1873. hotplug_en |= SDVOC_HOTPLUG_INT_EN;
  1874. if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS_I915)
  1875. hotplug_en |= SDVOB_HOTPLUG_INT_EN;
  1876. if (dev_priv->hotplug_supported_mask & CRT_HOTPLUG_INT_STATUS) {
  1877. hotplug_en |= CRT_HOTPLUG_INT_EN;
  1878. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  1879. }
  1880. /* Ignore TV since it's buggy */
  1881. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  1882. }
  1883. intel_opregion_enable_asle(dev);
  1884. return 0;
  1885. }
  1886. static irqreturn_t i915_irq_handler(int irq, void *arg)
  1887. {
  1888. struct drm_device *dev = (struct drm_device *) arg;
  1889. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1890. u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
  1891. unsigned long irqflags;
  1892. u32 flip_mask =
  1893. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  1894. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  1895. u32 flip[2] = {
  1896. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT,
  1897. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT
  1898. };
  1899. int pipe, ret = IRQ_NONE;
  1900. atomic_inc(&dev_priv->irq_received);
  1901. iir = I915_READ(IIR);
  1902. do {
  1903. bool irq_received = (iir & ~flip_mask) != 0;
  1904. bool blc_event = false;
  1905. /* Can't rely on pipestat interrupt bit in iir as it might
  1906. * have been cleared after the pipestat interrupt was received.
  1907. * It doesn't set the bit in iir again, but it still produces
  1908. * interrupts (for non-MSI).
  1909. */
  1910. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1911. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  1912. i915_handle_error(dev, false);
  1913. for_each_pipe(pipe) {
  1914. int reg = PIPESTAT(pipe);
  1915. pipe_stats[pipe] = I915_READ(reg);
  1916. /* Clear the PIPE*STAT regs before the IIR */
  1917. if (pipe_stats[pipe] & 0x8000ffff) {
  1918. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  1919. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  1920. pipe_name(pipe));
  1921. I915_WRITE(reg, pipe_stats[pipe]);
  1922. irq_received = true;
  1923. }
  1924. }
  1925. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1926. if (!irq_received)
  1927. break;
  1928. /* Consume port. Then clear IIR or we'll miss events */
  1929. if ((I915_HAS_HOTPLUG(dev)) &&
  1930. (iir & I915_DISPLAY_PORT_INTERRUPT)) {
  1931. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  1932. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  1933. hotplug_status);
  1934. if (hotplug_status & dev_priv->hotplug_supported_mask)
  1935. queue_work(dev_priv->wq,
  1936. &dev_priv->hotplug_work);
  1937. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  1938. POSTING_READ(PORT_HOTPLUG_STAT);
  1939. }
  1940. I915_WRITE(IIR, iir & ~flip_mask);
  1941. new_iir = I915_READ(IIR); /* Flush posted writes */
  1942. if (iir & I915_USER_INTERRUPT)
  1943. notify_ring(dev, &dev_priv->ring[RCS]);
  1944. for_each_pipe(pipe) {
  1945. int plane = pipe;
  1946. if (IS_MOBILE(dev))
  1947. plane = !plane;
  1948. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  1949. drm_handle_vblank(dev, pipe)) {
  1950. if (iir & flip[plane]) {
  1951. intel_prepare_page_flip(dev, plane);
  1952. intel_finish_page_flip(dev, pipe);
  1953. flip_mask &= ~flip[plane];
  1954. }
  1955. }
  1956. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  1957. blc_event = true;
  1958. }
  1959. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  1960. intel_opregion_asle_intr(dev);
  1961. /* With MSI, interrupts are only generated when iir
  1962. * transitions from zero to nonzero. If another bit got
  1963. * set while we were handling the existing iir bits, then
  1964. * we would never get another interrupt.
  1965. *
  1966. * This is fine on non-MSI as well, as if we hit this path
  1967. * we avoid exiting the interrupt handler only to generate
  1968. * another one.
  1969. *
  1970. * Note that for MSI this could cause a stray interrupt report
  1971. * if an interrupt landed in the time between writing IIR and
  1972. * the posting read. This should be rare enough to never
  1973. * trigger the 99% of 100,000 interrupts test for disabling
  1974. * stray interrupts.
  1975. */
  1976. ret = IRQ_HANDLED;
  1977. iir = new_iir;
  1978. } while (iir & ~flip_mask);
  1979. i915_update_dri1_breadcrumb(dev);
  1980. return ret;
  1981. }
  1982. static void i915_irq_uninstall(struct drm_device * dev)
  1983. {
  1984. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1985. int pipe;
  1986. if (I915_HAS_HOTPLUG(dev)) {
  1987. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1988. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  1989. }
  1990. I915_WRITE16(HWSTAM, 0xffff);
  1991. for_each_pipe(pipe) {
  1992. /* Clear enable bits; then clear status bits */
  1993. I915_WRITE(PIPESTAT(pipe), 0);
  1994. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  1995. }
  1996. I915_WRITE(IMR, 0xffffffff);
  1997. I915_WRITE(IER, 0x0);
  1998. I915_WRITE(IIR, I915_READ(IIR));
  1999. }
  2000. static void i965_irq_preinstall(struct drm_device * dev)
  2001. {
  2002. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2003. int pipe;
  2004. atomic_set(&dev_priv->irq_received, 0);
  2005. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2006. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2007. I915_WRITE(HWSTAM, 0xeffe);
  2008. for_each_pipe(pipe)
  2009. I915_WRITE(PIPESTAT(pipe), 0);
  2010. I915_WRITE(IMR, 0xffffffff);
  2011. I915_WRITE(IER, 0x0);
  2012. POSTING_READ(IER);
  2013. }
  2014. static int i965_irq_postinstall(struct drm_device *dev)
  2015. {
  2016. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2017. u32 hotplug_en;
  2018. u32 enable_mask;
  2019. u32 error_mask;
  2020. /* Unmask the interrupts that we always want on. */
  2021. dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
  2022. I915_DISPLAY_PORT_INTERRUPT |
  2023. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2024. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2025. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2026. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  2027. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2028. enable_mask = ~dev_priv->irq_mask;
  2029. enable_mask |= I915_USER_INTERRUPT;
  2030. if (IS_G4X(dev))
  2031. enable_mask |= I915_BSD_USER_INTERRUPT;
  2032. dev_priv->pipestat[0] = 0;
  2033. dev_priv->pipestat[1] = 0;
  2034. /*
  2035. * Enable some error detection, note the instruction error mask
  2036. * bit is reserved, so we leave it masked.
  2037. */
  2038. if (IS_G4X(dev)) {
  2039. error_mask = ~(GM45_ERROR_PAGE_TABLE |
  2040. GM45_ERROR_MEM_PRIV |
  2041. GM45_ERROR_CP_PRIV |
  2042. I915_ERROR_MEMORY_REFRESH);
  2043. } else {
  2044. error_mask = ~(I915_ERROR_PAGE_TABLE |
  2045. I915_ERROR_MEMORY_REFRESH);
  2046. }
  2047. I915_WRITE(EMR, error_mask);
  2048. I915_WRITE(IMR, dev_priv->irq_mask);
  2049. I915_WRITE(IER, enable_mask);
  2050. POSTING_READ(IER);
  2051. /* Note HDMI and DP share hotplug bits */
  2052. hotplug_en = 0;
  2053. if (dev_priv->hotplug_supported_mask & HDMIB_HOTPLUG_INT_STATUS)
  2054. hotplug_en |= HDMIB_HOTPLUG_INT_EN;
  2055. if (dev_priv->hotplug_supported_mask & HDMIC_HOTPLUG_INT_STATUS)
  2056. hotplug_en |= HDMIC_HOTPLUG_INT_EN;
  2057. if (dev_priv->hotplug_supported_mask & HDMID_HOTPLUG_INT_STATUS)
  2058. hotplug_en |= HDMID_HOTPLUG_INT_EN;
  2059. if (IS_G4X(dev)) {
  2060. if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS_G4X)
  2061. hotplug_en |= SDVOC_HOTPLUG_INT_EN;
  2062. if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS_G4X)
  2063. hotplug_en |= SDVOB_HOTPLUG_INT_EN;
  2064. } else {
  2065. if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS_I965)
  2066. hotplug_en |= SDVOC_HOTPLUG_INT_EN;
  2067. if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS_I965)
  2068. hotplug_en |= SDVOB_HOTPLUG_INT_EN;
  2069. }
  2070. if (dev_priv->hotplug_supported_mask & CRT_HOTPLUG_INT_STATUS) {
  2071. hotplug_en |= CRT_HOTPLUG_INT_EN;
  2072. /* Programming the CRT detection parameters tends
  2073. to generate a spurious hotplug event about three
  2074. seconds later. So just do it once.
  2075. */
  2076. if (IS_G4X(dev))
  2077. hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
  2078. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  2079. }
  2080. /* Ignore TV since it's buggy */
  2081. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  2082. intel_opregion_enable_asle(dev);
  2083. return 0;
  2084. }
  2085. static irqreturn_t i965_irq_handler(int irq, void *arg)
  2086. {
  2087. struct drm_device *dev = (struct drm_device *) arg;
  2088. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2089. u32 iir, new_iir;
  2090. u32 pipe_stats[I915_MAX_PIPES];
  2091. unsigned long irqflags;
  2092. int irq_received;
  2093. int ret = IRQ_NONE, pipe;
  2094. atomic_inc(&dev_priv->irq_received);
  2095. iir = I915_READ(IIR);
  2096. for (;;) {
  2097. bool blc_event = false;
  2098. irq_received = iir != 0;
  2099. /* Can't rely on pipestat interrupt bit in iir as it might
  2100. * have been cleared after the pipestat interrupt was received.
  2101. * It doesn't set the bit in iir again, but it still produces
  2102. * interrupts (for non-MSI).
  2103. */
  2104. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2105. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  2106. i915_handle_error(dev, false);
  2107. for_each_pipe(pipe) {
  2108. int reg = PIPESTAT(pipe);
  2109. pipe_stats[pipe] = I915_READ(reg);
  2110. /*
  2111. * Clear the PIPE*STAT regs before the IIR
  2112. */
  2113. if (pipe_stats[pipe] & 0x8000ffff) {
  2114. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  2115. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  2116. pipe_name(pipe));
  2117. I915_WRITE(reg, pipe_stats[pipe]);
  2118. irq_received = 1;
  2119. }
  2120. }
  2121. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2122. if (!irq_received)
  2123. break;
  2124. ret = IRQ_HANDLED;
  2125. /* Consume port. Then clear IIR or we'll miss events */
  2126. if (iir & I915_DISPLAY_PORT_INTERRUPT) {
  2127. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  2128. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  2129. hotplug_status);
  2130. if (hotplug_status & dev_priv->hotplug_supported_mask)
  2131. queue_work(dev_priv->wq,
  2132. &dev_priv->hotplug_work);
  2133. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  2134. I915_READ(PORT_HOTPLUG_STAT);
  2135. }
  2136. I915_WRITE(IIR, iir);
  2137. new_iir = I915_READ(IIR); /* Flush posted writes */
  2138. if (iir & I915_USER_INTERRUPT)
  2139. notify_ring(dev, &dev_priv->ring[RCS]);
  2140. if (iir & I915_BSD_USER_INTERRUPT)
  2141. notify_ring(dev, &dev_priv->ring[VCS]);
  2142. if (iir & I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT)
  2143. intel_prepare_page_flip(dev, 0);
  2144. if (iir & I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT)
  2145. intel_prepare_page_flip(dev, 1);
  2146. for_each_pipe(pipe) {
  2147. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
  2148. drm_handle_vblank(dev, pipe)) {
  2149. i915_pageflip_stall_check(dev, pipe);
  2150. intel_finish_page_flip(dev, pipe);
  2151. }
  2152. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  2153. blc_event = true;
  2154. }
  2155. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  2156. intel_opregion_asle_intr(dev);
  2157. /* With MSI, interrupts are only generated when iir
  2158. * transitions from zero to nonzero. If another bit got
  2159. * set while we were handling the existing iir bits, then
  2160. * we would never get another interrupt.
  2161. *
  2162. * This is fine on non-MSI as well, as if we hit this path
  2163. * we avoid exiting the interrupt handler only to generate
  2164. * another one.
  2165. *
  2166. * Note that for MSI this could cause a stray interrupt report
  2167. * if an interrupt landed in the time between writing IIR and
  2168. * the posting read. This should be rare enough to never
  2169. * trigger the 99% of 100,000 interrupts test for disabling
  2170. * stray interrupts.
  2171. */
  2172. iir = new_iir;
  2173. }
  2174. i915_update_dri1_breadcrumb(dev);
  2175. return ret;
  2176. }
  2177. static void i965_irq_uninstall(struct drm_device * dev)
  2178. {
  2179. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2180. int pipe;
  2181. if (!dev_priv)
  2182. return;
  2183. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2184. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2185. I915_WRITE(HWSTAM, 0xffffffff);
  2186. for_each_pipe(pipe)
  2187. I915_WRITE(PIPESTAT(pipe), 0);
  2188. I915_WRITE(IMR, 0xffffffff);
  2189. I915_WRITE(IER, 0x0);
  2190. for_each_pipe(pipe)
  2191. I915_WRITE(PIPESTAT(pipe),
  2192. I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
  2193. I915_WRITE(IIR, I915_READ(IIR));
  2194. }
  2195. void intel_irq_init(struct drm_device *dev)
  2196. {
  2197. struct drm_i915_private *dev_priv = dev->dev_private;
  2198. INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
  2199. INIT_WORK(&dev_priv->error_work, i915_error_work_func);
  2200. INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
  2201. INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
  2202. dev->driver->get_vblank_counter = i915_get_vblank_counter;
  2203. dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
  2204. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  2205. dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
  2206. dev->driver->get_vblank_counter = gm45_get_vblank_counter;
  2207. }
  2208. if (drm_core_check_feature(dev, DRIVER_MODESET))
  2209. dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
  2210. else
  2211. dev->driver->get_vblank_timestamp = NULL;
  2212. dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
  2213. if (IS_VALLEYVIEW(dev)) {
  2214. dev->driver->irq_handler = valleyview_irq_handler;
  2215. dev->driver->irq_preinstall = valleyview_irq_preinstall;
  2216. dev->driver->irq_postinstall = valleyview_irq_postinstall;
  2217. dev->driver->irq_uninstall = valleyview_irq_uninstall;
  2218. dev->driver->enable_vblank = valleyview_enable_vblank;
  2219. dev->driver->disable_vblank = valleyview_disable_vblank;
  2220. } else if (IS_IVYBRIDGE(dev)) {
  2221. /* Share pre & uninstall handlers with ILK/SNB */
  2222. dev->driver->irq_handler = ivybridge_irq_handler;
  2223. dev->driver->irq_preinstall = ironlake_irq_preinstall;
  2224. dev->driver->irq_postinstall = ivybridge_irq_postinstall;
  2225. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  2226. dev->driver->enable_vblank = ivybridge_enable_vblank;
  2227. dev->driver->disable_vblank = ivybridge_disable_vblank;
  2228. } else if (IS_HASWELL(dev)) {
  2229. /* Share interrupts handling with IVB */
  2230. dev->driver->irq_handler = ivybridge_irq_handler;
  2231. dev->driver->irq_preinstall = ironlake_irq_preinstall;
  2232. dev->driver->irq_postinstall = ivybridge_irq_postinstall;
  2233. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  2234. dev->driver->enable_vblank = ivybridge_enable_vblank;
  2235. dev->driver->disable_vblank = ivybridge_disable_vblank;
  2236. } else if (HAS_PCH_SPLIT(dev)) {
  2237. dev->driver->irq_handler = ironlake_irq_handler;
  2238. dev->driver->irq_preinstall = ironlake_irq_preinstall;
  2239. dev->driver->irq_postinstall = ironlake_irq_postinstall;
  2240. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  2241. dev->driver->enable_vblank = ironlake_enable_vblank;
  2242. dev->driver->disable_vblank = ironlake_disable_vblank;
  2243. } else {
  2244. if (INTEL_INFO(dev)->gen == 2) {
  2245. dev->driver->irq_preinstall = i8xx_irq_preinstall;
  2246. dev->driver->irq_postinstall = i8xx_irq_postinstall;
  2247. dev->driver->irq_handler = i8xx_irq_handler;
  2248. dev->driver->irq_uninstall = i8xx_irq_uninstall;
  2249. } else if (INTEL_INFO(dev)->gen == 3) {
  2250. dev->driver->irq_preinstall = i915_irq_preinstall;
  2251. dev->driver->irq_postinstall = i915_irq_postinstall;
  2252. dev->driver->irq_uninstall = i915_irq_uninstall;
  2253. dev->driver->irq_handler = i915_irq_handler;
  2254. } else {
  2255. dev->driver->irq_preinstall = i965_irq_preinstall;
  2256. dev->driver->irq_postinstall = i965_irq_postinstall;
  2257. dev->driver->irq_uninstall = i965_irq_uninstall;
  2258. dev->driver->irq_handler = i965_irq_handler;
  2259. }
  2260. dev->driver->enable_vblank = i915_enable_vblank;
  2261. dev->driver->disable_vblank = i915_disable_vblank;
  2262. }
  2263. }