i915_irq.c 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752
  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->rps.hw_lock);
  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->rps.hw_lock);
  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, 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. pm_iir = I915_READ(GEN6_PMIIR);
  627. if (de_iir == 0 && gt_iir == 0 && (!IS_GEN6(dev) || pm_iir == 0))
  628. goto done;
  629. ret = IRQ_HANDLED;
  630. if (IS_GEN5(dev))
  631. ilk_gt_irq_handler(dev, dev_priv, gt_iir);
  632. else
  633. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  634. if (de_iir & DE_GSE)
  635. intel_opregion_gse_intr(dev);
  636. if (de_iir & DE_PIPEA_VBLANK)
  637. drm_handle_vblank(dev, 0);
  638. if (de_iir & DE_PIPEB_VBLANK)
  639. drm_handle_vblank(dev, 1);
  640. if (de_iir & DE_PLANEA_FLIP_DONE) {
  641. intel_prepare_page_flip(dev, 0);
  642. intel_finish_page_flip_plane(dev, 0);
  643. }
  644. if (de_iir & DE_PLANEB_FLIP_DONE) {
  645. intel_prepare_page_flip(dev, 1);
  646. intel_finish_page_flip_plane(dev, 1);
  647. }
  648. /* check event from PCH */
  649. if (de_iir & DE_PCH_EVENT) {
  650. u32 pch_iir = I915_READ(SDEIIR);
  651. if (HAS_PCH_CPT(dev))
  652. cpt_irq_handler(dev, pch_iir);
  653. else
  654. ibx_irq_handler(dev, pch_iir);
  655. /* should clear PCH hotplug event before clear CPU irq */
  656. I915_WRITE(SDEIIR, pch_iir);
  657. }
  658. if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
  659. ironlake_handle_rps_change(dev);
  660. if (IS_GEN6(dev) && pm_iir & GEN6_PM_DEFERRED_EVENTS)
  661. gen6_queue_rps_work(dev_priv, pm_iir);
  662. I915_WRITE(GTIIR, gt_iir);
  663. I915_WRITE(DEIIR, de_iir);
  664. I915_WRITE(GEN6_PMIIR, pm_iir);
  665. done:
  666. I915_WRITE(DEIER, de_ier);
  667. POSTING_READ(DEIER);
  668. return ret;
  669. }
  670. /**
  671. * i915_error_work_func - do process context error handling work
  672. * @work: work struct
  673. *
  674. * Fire an error uevent so userspace can see that a hang or error
  675. * was detected.
  676. */
  677. static void i915_error_work_func(struct work_struct *work)
  678. {
  679. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  680. error_work);
  681. struct drm_device *dev = dev_priv->dev;
  682. char *error_event[] = { "ERROR=1", NULL };
  683. char *reset_event[] = { "RESET=1", NULL };
  684. char *reset_done_event[] = { "ERROR=0", NULL };
  685. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
  686. if (atomic_read(&dev_priv->mm.wedged)) {
  687. DRM_DEBUG_DRIVER("resetting chip\n");
  688. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_event);
  689. if (!i915_reset(dev)) {
  690. atomic_set(&dev_priv->mm.wedged, 0);
  691. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_done_event);
  692. }
  693. complete_all(&dev_priv->error_completion);
  694. }
  695. }
  696. /* NB: please notice the memset */
  697. static void i915_get_extra_instdone(struct drm_device *dev,
  698. uint32_t *instdone)
  699. {
  700. struct drm_i915_private *dev_priv = dev->dev_private;
  701. memset(instdone, 0, sizeof(*instdone) * I915_NUM_INSTDONE_REG);
  702. switch(INTEL_INFO(dev)->gen) {
  703. case 2:
  704. case 3:
  705. instdone[0] = I915_READ(INSTDONE);
  706. break;
  707. case 4:
  708. case 5:
  709. case 6:
  710. instdone[0] = I915_READ(INSTDONE_I965);
  711. instdone[1] = I915_READ(INSTDONE1);
  712. break;
  713. default:
  714. WARN_ONCE(1, "Unsupported platform\n");
  715. case 7:
  716. instdone[0] = I915_READ(GEN7_INSTDONE_1);
  717. instdone[1] = I915_READ(GEN7_SC_INSTDONE);
  718. instdone[2] = I915_READ(GEN7_SAMPLER_INSTDONE);
  719. instdone[3] = I915_READ(GEN7_ROW_INSTDONE);
  720. break;
  721. }
  722. }
  723. #ifdef CONFIG_DEBUG_FS
  724. static struct drm_i915_error_object *
  725. i915_error_object_create(struct drm_i915_private *dev_priv,
  726. struct drm_i915_gem_object *src)
  727. {
  728. struct drm_i915_error_object *dst;
  729. int i, count;
  730. u32 reloc_offset;
  731. if (src == NULL || src->pages == NULL)
  732. return NULL;
  733. count = src->base.size / PAGE_SIZE;
  734. dst = kmalloc(sizeof(*dst) + count * sizeof(u32 *), GFP_ATOMIC);
  735. if (dst == NULL)
  736. return NULL;
  737. reloc_offset = src->gtt_offset;
  738. for (i = 0; i < count; i++) {
  739. unsigned long flags;
  740. void *d;
  741. d = kmalloc(PAGE_SIZE, GFP_ATOMIC);
  742. if (d == NULL)
  743. goto unwind;
  744. local_irq_save(flags);
  745. if (reloc_offset < dev_priv->mm.gtt_mappable_end &&
  746. src->has_global_gtt_mapping) {
  747. void __iomem *s;
  748. /* Simply ignore tiling or any overlapping fence.
  749. * It's part of the error state, and this hopefully
  750. * captures what the GPU read.
  751. */
  752. s = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping,
  753. reloc_offset);
  754. memcpy_fromio(d, s, PAGE_SIZE);
  755. io_mapping_unmap_atomic(s);
  756. } else {
  757. struct page *page;
  758. void *s;
  759. page = i915_gem_object_get_page(src, i);
  760. drm_clflush_pages(&page, 1);
  761. s = kmap_atomic(page);
  762. memcpy(d, s, PAGE_SIZE);
  763. kunmap_atomic(s);
  764. drm_clflush_pages(&page, 1);
  765. }
  766. local_irq_restore(flags);
  767. dst->pages[i] = d;
  768. reloc_offset += PAGE_SIZE;
  769. }
  770. dst->page_count = count;
  771. dst->gtt_offset = src->gtt_offset;
  772. return dst;
  773. unwind:
  774. while (i--)
  775. kfree(dst->pages[i]);
  776. kfree(dst);
  777. return NULL;
  778. }
  779. static void
  780. i915_error_object_free(struct drm_i915_error_object *obj)
  781. {
  782. int page;
  783. if (obj == NULL)
  784. return;
  785. for (page = 0; page < obj->page_count; page++)
  786. kfree(obj->pages[page]);
  787. kfree(obj);
  788. }
  789. void
  790. i915_error_state_free(struct kref *error_ref)
  791. {
  792. struct drm_i915_error_state *error = container_of(error_ref,
  793. typeof(*error), ref);
  794. int i;
  795. for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
  796. i915_error_object_free(error->ring[i].batchbuffer);
  797. i915_error_object_free(error->ring[i].ringbuffer);
  798. kfree(error->ring[i].requests);
  799. }
  800. kfree(error->active_bo);
  801. kfree(error->overlay);
  802. kfree(error);
  803. }
  804. static void capture_bo(struct drm_i915_error_buffer *err,
  805. struct drm_i915_gem_object *obj)
  806. {
  807. err->size = obj->base.size;
  808. err->name = obj->base.name;
  809. err->rseqno = obj->last_read_seqno;
  810. err->wseqno = obj->last_write_seqno;
  811. err->gtt_offset = obj->gtt_offset;
  812. err->read_domains = obj->base.read_domains;
  813. err->write_domain = obj->base.write_domain;
  814. err->fence_reg = obj->fence_reg;
  815. err->pinned = 0;
  816. if (obj->pin_count > 0)
  817. err->pinned = 1;
  818. if (obj->user_pin_count > 0)
  819. err->pinned = -1;
  820. err->tiling = obj->tiling_mode;
  821. err->dirty = obj->dirty;
  822. err->purgeable = obj->madv != I915_MADV_WILLNEED;
  823. err->ring = obj->ring ? obj->ring->id : -1;
  824. err->cache_level = obj->cache_level;
  825. }
  826. static u32 capture_active_bo(struct drm_i915_error_buffer *err,
  827. int count, struct list_head *head)
  828. {
  829. struct drm_i915_gem_object *obj;
  830. int i = 0;
  831. list_for_each_entry(obj, head, mm_list) {
  832. capture_bo(err++, obj);
  833. if (++i == count)
  834. break;
  835. }
  836. return i;
  837. }
  838. static u32 capture_pinned_bo(struct drm_i915_error_buffer *err,
  839. int count, struct list_head *head)
  840. {
  841. struct drm_i915_gem_object *obj;
  842. int i = 0;
  843. list_for_each_entry(obj, head, gtt_list) {
  844. if (obj->pin_count == 0)
  845. continue;
  846. capture_bo(err++, obj);
  847. if (++i == count)
  848. break;
  849. }
  850. return i;
  851. }
  852. static void i915_gem_record_fences(struct drm_device *dev,
  853. struct drm_i915_error_state *error)
  854. {
  855. struct drm_i915_private *dev_priv = dev->dev_private;
  856. int i;
  857. /* Fences */
  858. switch (INTEL_INFO(dev)->gen) {
  859. case 7:
  860. case 6:
  861. for (i = 0; i < 16; i++)
  862. error->fence[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8));
  863. break;
  864. case 5:
  865. case 4:
  866. for (i = 0; i < 16; i++)
  867. error->fence[i] = I915_READ64(FENCE_REG_965_0 + (i * 8));
  868. break;
  869. case 3:
  870. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
  871. for (i = 0; i < 8; i++)
  872. error->fence[i+8] = I915_READ(FENCE_REG_945_8 + (i * 4));
  873. case 2:
  874. for (i = 0; i < 8; i++)
  875. error->fence[i] = I915_READ(FENCE_REG_830_0 + (i * 4));
  876. break;
  877. }
  878. }
  879. static struct drm_i915_error_object *
  880. i915_error_first_batchbuffer(struct drm_i915_private *dev_priv,
  881. struct intel_ring_buffer *ring)
  882. {
  883. struct drm_i915_gem_object *obj;
  884. u32 seqno;
  885. if (!ring->get_seqno)
  886. return NULL;
  887. seqno = ring->get_seqno(ring, false);
  888. list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list) {
  889. if (obj->ring != ring)
  890. continue;
  891. if (i915_seqno_passed(seqno, obj->last_read_seqno))
  892. continue;
  893. if ((obj->base.read_domains & I915_GEM_DOMAIN_COMMAND) == 0)
  894. continue;
  895. /* We need to copy these to an anonymous buffer as the simplest
  896. * method to avoid being overwritten by userspace.
  897. */
  898. return i915_error_object_create(dev_priv, obj);
  899. }
  900. return NULL;
  901. }
  902. static void i915_record_ring_state(struct drm_device *dev,
  903. struct drm_i915_error_state *error,
  904. struct intel_ring_buffer *ring)
  905. {
  906. struct drm_i915_private *dev_priv = dev->dev_private;
  907. if (INTEL_INFO(dev)->gen >= 6) {
  908. error->rc_psmi[ring->id] = I915_READ(ring->mmio_base + 0x50);
  909. error->fault_reg[ring->id] = I915_READ(RING_FAULT_REG(ring));
  910. error->semaphore_mboxes[ring->id][0]
  911. = I915_READ(RING_SYNC_0(ring->mmio_base));
  912. error->semaphore_mboxes[ring->id][1]
  913. = I915_READ(RING_SYNC_1(ring->mmio_base));
  914. error->semaphore_seqno[ring->id][0] = ring->sync_seqno[0];
  915. error->semaphore_seqno[ring->id][1] = ring->sync_seqno[1];
  916. }
  917. if (INTEL_INFO(dev)->gen >= 4) {
  918. error->faddr[ring->id] = I915_READ(RING_DMA_FADD(ring->mmio_base));
  919. error->ipeir[ring->id] = I915_READ(RING_IPEIR(ring->mmio_base));
  920. error->ipehr[ring->id] = I915_READ(RING_IPEHR(ring->mmio_base));
  921. error->instdone[ring->id] = I915_READ(RING_INSTDONE(ring->mmio_base));
  922. error->instps[ring->id] = I915_READ(RING_INSTPS(ring->mmio_base));
  923. if (ring->id == RCS)
  924. error->bbaddr = I915_READ64(BB_ADDR);
  925. } else {
  926. error->faddr[ring->id] = I915_READ(DMA_FADD_I8XX);
  927. error->ipeir[ring->id] = I915_READ(IPEIR);
  928. error->ipehr[ring->id] = I915_READ(IPEHR);
  929. error->instdone[ring->id] = I915_READ(INSTDONE);
  930. }
  931. error->waiting[ring->id] = waitqueue_active(&ring->irq_queue);
  932. error->instpm[ring->id] = I915_READ(RING_INSTPM(ring->mmio_base));
  933. error->seqno[ring->id] = ring->get_seqno(ring, false);
  934. error->acthd[ring->id] = intel_ring_get_active_head(ring);
  935. error->head[ring->id] = I915_READ_HEAD(ring);
  936. error->tail[ring->id] = I915_READ_TAIL(ring);
  937. error->cpu_ring_head[ring->id] = ring->head;
  938. error->cpu_ring_tail[ring->id] = ring->tail;
  939. }
  940. static void i915_gem_record_rings(struct drm_device *dev,
  941. struct drm_i915_error_state *error)
  942. {
  943. struct drm_i915_private *dev_priv = dev->dev_private;
  944. struct intel_ring_buffer *ring;
  945. struct drm_i915_gem_request *request;
  946. int i, count;
  947. for_each_ring(ring, dev_priv, i) {
  948. i915_record_ring_state(dev, error, ring);
  949. error->ring[i].batchbuffer =
  950. i915_error_first_batchbuffer(dev_priv, ring);
  951. error->ring[i].ringbuffer =
  952. i915_error_object_create(dev_priv, ring->obj);
  953. count = 0;
  954. list_for_each_entry(request, &ring->request_list, list)
  955. count++;
  956. error->ring[i].num_requests = count;
  957. error->ring[i].requests =
  958. kmalloc(count*sizeof(struct drm_i915_error_request),
  959. GFP_ATOMIC);
  960. if (error->ring[i].requests == NULL) {
  961. error->ring[i].num_requests = 0;
  962. continue;
  963. }
  964. count = 0;
  965. list_for_each_entry(request, &ring->request_list, list) {
  966. struct drm_i915_error_request *erq;
  967. erq = &error->ring[i].requests[count++];
  968. erq->seqno = request->seqno;
  969. erq->jiffies = request->emitted_jiffies;
  970. erq->tail = request->tail;
  971. }
  972. }
  973. }
  974. /**
  975. * i915_capture_error_state - capture an error record for later analysis
  976. * @dev: drm device
  977. *
  978. * Should be called when an error is detected (either a hang or an error
  979. * interrupt) to capture error state from the time of the error. Fills
  980. * out a structure which becomes available in debugfs for user level tools
  981. * to pick up.
  982. */
  983. static void i915_capture_error_state(struct drm_device *dev)
  984. {
  985. struct drm_i915_private *dev_priv = dev->dev_private;
  986. struct drm_i915_gem_object *obj;
  987. struct drm_i915_error_state *error;
  988. unsigned long flags;
  989. int i, pipe;
  990. spin_lock_irqsave(&dev_priv->error_lock, flags);
  991. error = dev_priv->first_error;
  992. spin_unlock_irqrestore(&dev_priv->error_lock, flags);
  993. if (error)
  994. return;
  995. /* Account for pipe specific data like PIPE*STAT */
  996. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  997. if (!error) {
  998. DRM_DEBUG_DRIVER("out of memory, not capturing error state\n");
  999. return;
  1000. }
  1001. DRM_INFO("capturing error event; look for more information in /debug/dri/%d/i915_error_state\n",
  1002. dev->primary->index);
  1003. kref_init(&error->ref);
  1004. error->eir = I915_READ(EIR);
  1005. error->pgtbl_er = I915_READ(PGTBL_ER);
  1006. error->ccid = I915_READ(CCID);
  1007. if (HAS_PCH_SPLIT(dev))
  1008. error->ier = I915_READ(DEIER) | I915_READ(GTIER);
  1009. else if (IS_VALLEYVIEW(dev))
  1010. error->ier = I915_READ(GTIER) | I915_READ(VLV_IER);
  1011. else if (IS_GEN2(dev))
  1012. error->ier = I915_READ16(IER);
  1013. else
  1014. error->ier = I915_READ(IER);
  1015. for_each_pipe(pipe)
  1016. error->pipestat[pipe] = I915_READ(PIPESTAT(pipe));
  1017. if (INTEL_INFO(dev)->gen >= 6) {
  1018. error->error = I915_READ(ERROR_GEN6);
  1019. error->done_reg = I915_READ(DONE_REG);
  1020. }
  1021. if (INTEL_INFO(dev)->gen == 7)
  1022. error->err_int = I915_READ(GEN7_ERR_INT);
  1023. i915_get_extra_instdone(dev, error->extra_instdone);
  1024. i915_gem_record_fences(dev, error);
  1025. i915_gem_record_rings(dev, error);
  1026. /* Record buffers on the active and pinned lists. */
  1027. error->active_bo = NULL;
  1028. error->pinned_bo = NULL;
  1029. i = 0;
  1030. list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list)
  1031. i++;
  1032. error->active_bo_count = i;
  1033. list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list)
  1034. if (obj->pin_count)
  1035. i++;
  1036. error->pinned_bo_count = i - error->active_bo_count;
  1037. error->active_bo = NULL;
  1038. error->pinned_bo = NULL;
  1039. if (i) {
  1040. error->active_bo = kmalloc(sizeof(*error->active_bo)*i,
  1041. GFP_ATOMIC);
  1042. if (error->active_bo)
  1043. error->pinned_bo =
  1044. error->active_bo + error->active_bo_count;
  1045. }
  1046. if (error->active_bo)
  1047. error->active_bo_count =
  1048. capture_active_bo(error->active_bo,
  1049. error->active_bo_count,
  1050. &dev_priv->mm.active_list);
  1051. if (error->pinned_bo)
  1052. error->pinned_bo_count =
  1053. capture_pinned_bo(error->pinned_bo,
  1054. error->pinned_bo_count,
  1055. &dev_priv->mm.bound_list);
  1056. do_gettimeofday(&error->time);
  1057. error->overlay = intel_overlay_capture_error_state(dev);
  1058. error->display = intel_display_capture_error_state(dev);
  1059. spin_lock_irqsave(&dev_priv->error_lock, flags);
  1060. if (dev_priv->first_error == NULL) {
  1061. dev_priv->first_error = error;
  1062. error = NULL;
  1063. }
  1064. spin_unlock_irqrestore(&dev_priv->error_lock, flags);
  1065. if (error)
  1066. i915_error_state_free(&error->ref);
  1067. }
  1068. void i915_destroy_error_state(struct drm_device *dev)
  1069. {
  1070. struct drm_i915_private *dev_priv = dev->dev_private;
  1071. struct drm_i915_error_state *error;
  1072. unsigned long flags;
  1073. spin_lock_irqsave(&dev_priv->error_lock, flags);
  1074. error = dev_priv->first_error;
  1075. dev_priv->first_error = NULL;
  1076. spin_unlock_irqrestore(&dev_priv->error_lock, flags);
  1077. if (error)
  1078. kref_put(&error->ref, i915_error_state_free);
  1079. }
  1080. #else
  1081. #define i915_capture_error_state(x)
  1082. #endif
  1083. static void i915_report_and_clear_eir(struct drm_device *dev)
  1084. {
  1085. struct drm_i915_private *dev_priv = dev->dev_private;
  1086. uint32_t instdone[I915_NUM_INSTDONE_REG];
  1087. u32 eir = I915_READ(EIR);
  1088. int pipe, i;
  1089. if (!eir)
  1090. return;
  1091. pr_err("render error detected, EIR: 0x%08x\n", eir);
  1092. i915_get_extra_instdone(dev, instdone);
  1093. if (IS_G4X(dev)) {
  1094. if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
  1095. u32 ipeir = I915_READ(IPEIR_I965);
  1096. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1097. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1098. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1099. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1100. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1101. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1102. I915_WRITE(IPEIR_I965, ipeir);
  1103. POSTING_READ(IPEIR_I965);
  1104. }
  1105. if (eir & GM45_ERROR_PAGE_TABLE) {
  1106. u32 pgtbl_err = I915_READ(PGTBL_ER);
  1107. pr_err("page table error\n");
  1108. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  1109. I915_WRITE(PGTBL_ER, pgtbl_err);
  1110. POSTING_READ(PGTBL_ER);
  1111. }
  1112. }
  1113. if (!IS_GEN2(dev)) {
  1114. if (eir & I915_ERROR_PAGE_TABLE) {
  1115. u32 pgtbl_err = I915_READ(PGTBL_ER);
  1116. pr_err("page table error\n");
  1117. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  1118. I915_WRITE(PGTBL_ER, pgtbl_err);
  1119. POSTING_READ(PGTBL_ER);
  1120. }
  1121. }
  1122. if (eir & I915_ERROR_MEMORY_REFRESH) {
  1123. pr_err("memory refresh error:\n");
  1124. for_each_pipe(pipe)
  1125. pr_err("pipe %c stat: 0x%08x\n",
  1126. pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
  1127. /* pipestat has already been acked */
  1128. }
  1129. if (eir & I915_ERROR_INSTRUCTION) {
  1130. pr_err("instruction error\n");
  1131. pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
  1132. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1133. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1134. if (INTEL_INFO(dev)->gen < 4) {
  1135. u32 ipeir = I915_READ(IPEIR);
  1136. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
  1137. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
  1138. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
  1139. I915_WRITE(IPEIR, ipeir);
  1140. POSTING_READ(IPEIR);
  1141. } else {
  1142. u32 ipeir = I915_READ(IPEIR_I965);
  1143. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1144. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1145. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1146. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1147. I915_WRITE(IPEIR_I965, ipeir);
  1148. POSTING_READ(IPEIR_I965);
  1149. }
  1150. }
  1151. I915_WRITE(EIR, eir);
  1152. POSTING_READ(EIR);
  1153. eir = I915_READ(EIR);
  1154. if (eir) {
  1155. /*
  1156. * some errors might have become stuck,
  1157. * mask them.
  1158. */
  1159. DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
  1160. I915_WRITE(EMR, I915_READ(EMR) | eir);
  1161. I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  1162. }
  1163. }
  1164. /**
  1165. * i915_handle_error - handle an error interrupt
  1166. * @dev: drm device
  1167. *
  1168. * Do some basic checking of regsiter state at error interrupt time and
  1169. * dump it to the syslog. Also call i915_capture_error_state() to make
  1170. * sure we get a record and make it available in debugfs. Fire a uevent
  1171. * so userspace knows something bad happened (should trigger collection
  1172. * of a ring dump etc.).
  1173. */
  1174. void i915_handle_error(struct drm_device *dev, bool wedged)
  1175. {
  1176. struct drm_i915_private *dev_priv = dev->dev_private;
  1177. struct intel_ring_buffer *ring;
  1178. int i;
  1179. i915_capture_error_state(dev);
  1180. i915_report_and_clear_eir(dev);
  1181. if (wedged) {
  1182. INIT_COMPLETION(dev_priv->error_completion);
  1183. atomic_set(&dev_priv->mm.wedged, 1);
  1184. /*
  1185. * Wakeup waiting processes so they don't hang
  1186. */
  1187. for_each_ring(ring, dev_priv, i)
  1188. wake_up_all(&ring->irq_queue);
  1189. }
  1190. queue_work(dev_priv->wq, &dev_priv->error_work);
  1191. }
  1192. static void i915_pageflip_stall_check(struct drm_device *dev, int pipe)
  1193. {
  1194. drm_i915_private_t *dev_priv = dev->dev_private;
  1195. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1196. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1197. struct drm_i915_gem_object *obj;
  1198. struct intel_unpin_work *work;
  1199. unsigned long flags;
  1200. bool stall_detected;
  1201. /* Ignore early vblank irqs */
  1202. if (intel_crtc == NULL)
  1203. return;
  1204. spin_lock_irqsave(&dev->event_lock, flags);
  1205. work = intel_crtc->unpin_work;
  1206. if (work == NULL || work->pending || !work->enable_stall_check) {
  1207. /* Either the pending flip IRQ arrived, or we're too early. Don't check */
  1208. spin_unlock_irqrestore(&dev->event_lock, flags);
  1209. return;
  1210. }
  1211. /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
  1212. obj = work->pending_flip_obj;
  1213. if (INTEL_INFO(dev)->gen >= 4) {
  1214. int dspsurf = DSPSURF(intel_crtc->plane);
  1215. stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
  1216. obj->gtt_offset;
  1217. } else {
  1218. int dspaddr = DSPADDR(intel_crtc->plane);
  1219. stall_detected = I915_READ(dspaddr) == (obj->gtt_offset +
  1220. crtc->y * crtc->fb->pitches[0] +
  1221. crtc->x * crtc->fb->bits_per_pixel/8);
  1222. }
  1223. spin_unlock_irqrestore(&dev->event_lock, flags);
  1224. if (stall_detected) {
  1225. DRM_DEBUG_DRIVER("Pageflip stall detected\n");
  1226. intel_prepare_page_flip(dev, intel_crtc->plane);
  1227. }
  1228. }
  1229. /* Called from drm generic code, passed 'crtc' which
  1230. * we use as a pipe index
  1231. */
  1232. static int i915_enable_vblank(struct drm_device *dev, int pipe)
  1233. {
  1234. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1235. unsigned long irqflags;
  1236. if (!i915_pipe_enabled(dev, pipe))
  1237. return -EINVAL;
  1238. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1239. if (INTEL_INFO(dev)->gen >= 4)
  1240. i915_enable_pipestat(dev_priv, pipe,
  1241. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1242. else
  1243. i915_enable_pipestat(dev_priv, pipe,
  1244. PIPE_VBLANK_INTERRUPT_ENABLE);
  1245. /* maintain vblank delivery even in deep C-states */
  1246. if (dev_priv->info->gen == 3)
  1247. I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
  1248. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1249. return 0;
  1250. }
  1251. static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
  1252. {
  1253. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1254. unsigned long irqflags;
  1255. if (!i915_pipe_enabled(dev, pipe))
  1256. return -EINVAL;
  1257. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1258. ironlake_enable_display_irq(dev_priv, (pipe == 0) ?
  1259. DE_PIPEA_VBLANK : DE_PIPEB_VBLANK);
  1260. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1261. return 0;
  1262. }
  1263. static int ivybridge_enable_vblank(struct drm_device *dev, int pipe)
  1264. {
  1265. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1266. unsigned long irqflags;
  1267. if (!i915_pipe_enabled(dev, pipe))
  1268. return -EINVAL;
  1269. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1270. ironlake_enable_display_irq(dev_priv,
  1271. DE_PIPEA_VBLANK_IVB << (5 * pipe));
  1272. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1273. return 0;
  1274. }
  1275. static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
  1276. {
  1277. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1278. unsigned long irqflags;
  1279. u32 imr;
  1280. if (!i915_pipe_enabled(dev, pipe))
  1281. return -EINVAL;
  1282. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1283. imr = I915_READ(VLV_IMR);
  1284. if (pipe == 0)
  1285. imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
  1286. else
  1287. imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1288. I915_WRITE(VLV_IMR, imr);
  1289. i915_enable_pipestat(dev_priv, pipe,
  1290. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1291. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1292. return 0;
  1293. }
  1294. /* Called from drm generic code, passed 'crtc' which
  1295. * we use as a pipe index
  1296. */
  1297. static void i915_disable_vblank(struct drm_device *dev, int pipe)
  1298. {
  1299. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1300. unsigned long irqflags;
  1301. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1302. if (dev_priv->info->gen == 3)
  1303. I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
  1304. i915_disable_pipestat(dev_priv, pipe,
  1305. PIPE_VBLANK_INTERRUPT_ENABLE |
  1306. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1307. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1308. }
  1309. static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
  1310. {
  1311. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1312. unsigned long irqflags;
  1313. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1314. ironlake_disable_display_irq(dev_priv, (pipe == 0) ?
  1315. DE_PIPEA_VBLANK : DE_PIPEB_VBLANK);
  1316. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1317. }
  1318. static void ivybridge_disable_vblank(struct drm_device *dev, int pipe)
  1319. {
  1320. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1321. unsigned long irqflags;
  1322. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1323. ironlake_disable_display_irq(dev_priv,
  1324. DE_PIPEA_VBLANK_IVB << (pipe * 5));
  1325. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1326. }
  1327. static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
  1328. {
  1329. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1330. unsigned long irqflags;
  1331. u32 imr;
  1332. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1333. i915_disable_pipestat(dev_priv, pipe,
  1334. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1335. imr = I915_READ(VLV_IMR);
  1336. if (pipe == 0)
  1337. imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
  1338. else
  1339. imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1340. I915_WRITE(VLV_IMR, imr);
  1341. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1342. }
  1343. static u32
  1344. ring_last_seqno(struct intel_ring_buffer *ring)
  1345. {
  1346. return list_entry(ring->request_list.prev,
  1347. struct drm_i915_gem_request, list)->seqno;
  1348. }
  1349. static bool i915_hangcheck_ring_idle(struct intel_ring_buffer *ring, bool *err)
  1350. {
  1351. if (list_empty(&ring->request_list) ||
  1352. i915_seqno_passed(ring->get_seqno(ring, false),
  1353. ring_last_seqno(ring))) {
  1354. /* Issue a wake-up to catch stuck h/w. */
  1355. if (waitqueue_active(&ring->irq_queue)) {
  1356. DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
  1357. ring->name);
  1358. wake_up_all(&ring->irq_queue);
  1359. *err = true;
  1360. }
  1361. return true;
  1362. }
  1363. return false;
  1364. }
  1365. static bool kick_ring(struct intel_ring_buffer *ring)
  1366. {
  1367. struct drm_device *dev = ring->dev;
  1368. struct drm_i915_private *dev_priv = dev->dev_private;
  1369. u32 tmp = I915_READ_CTL(ring);
  1370. if (tmp & RING_WAIT) {
  1371. DRM_ERROR("Kicking stuck wait on %s\n",
  1372. ring->name);
  1373. I915_WRITE_CTL(ring, tmp);
  1374. return true;
  1375. }
  1376. return false;
  1377. }
  1378. static bool i915_hangcheck_hung(struct drm_device *dev)
  1379. {
  1380. drm_i915_private_t *dev_priv = dev->dev_private;
  1381. if (dev_priv->hangcheck_count++ > 1) {
  1382. bool hung = true;
  1383. DRM_ERROR("Hangcheck timer elapsed... GPU hung\n");
  1384. i915_handle_error(dev, true);
  1385. if (!IS_GEN2(dev)) {
  1386. struct intel_ring_buffer *ring;
  1387. int i;
  1388. /* Is the chip hanging on a WAIT_FOR_EVENT?
  1389. * If so we can simply poke the RB_WAIT bit
  1390. * and break the hang. This should work on
  1391. * all but the second generation chipsets.
  1392. */
  1393. for_each_ring(ring, dev_priv, i)
  1394. hung &= !kick_ring(ring);
  1395. }
  1396. return hung;
  1397. }
  1398. return false;
  1399. }
  1400. /**
  1401. * This is called when the chip hasn't reported back with completed
  1402. * batchbuffers in a long time. The first time this is called we simply record
  1403. * ACTHD. If ACTHD hasn't changed by the time the hangcheck timer elapses
  1404. * again, we assume the chip is wedged and try to fix it.
  1405. */
  1406. void i915_hangcheck_elapsed(unsigned long data)
  1407. {
  1408. struct drm_device *dev = (struct drm_device *)data;
  1409. drm_i915_private_t *dev_priv = dev->dev_private;
  1410. uint32_t acthd[I915_NUM_RINGS], instdone[I915_NUM_INSTDONE_REG];
  1411. struct intel_ring_buffer *ring;
  1412. bool err = false, idle;
  1413. int i;
  1414. if (!i915_enable_hangcheck)
  1415. return;
  1416. memset(acthd, 0, sizeof(acthd));
  1417. idle = true;
  1418. for_each_ring(ring, dev_priv, i) {
  1419. idle &= i915_hangcheck_ring_idle(ring, &err);
  1420. acthd[i] = intel_ring_get_active_head(ring);
  1421. }
  1422. /* If all work is done then ACTHD clearly hasn't advanced. */
  1423. if (idle) {
  1424. if (err) {
  1425. if (i915_hangcheck_hung(dev))
  1426. return;
  1427. goto repeat;
  1428. }
  1429. dev_priv->hangcheck_count = 0;
  1430. return;
  1431. }
  1432. i915_get_extra_instdone(dev, instdone);
  1433. if (memcmp(dev_priv->last_acthd, acthd, sizeof(acthd)) == 0 &&
  1434. memcmp(dev_priv->prev_instdone, instdone, sizeof(instdone)) == 0) {
  1435. if (i915_hangcheck_hung(dev))
  1436. return;
  1437. } else {
  1438. dev_priv->hangcheck_count = 0;
  1439. memcpy(dev_priv->last_acthd, acthd, sizeof(acthd));
  1440. memcpy(dev_priv->prev_instdone, instdone, sizeof(instdone));
  1441. }
  1442. repeat:
  1443. /* Reset timer case chip hangs without another request being added */
  1444. mod_timer(&dev_priv->hangcheck_timer,
  1445. round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
  1446. }
  1447. /* drm_dma.h hooks
  1448. */
  1449. static void ironlake_irq_preinstall(struct drm_device *dev)
  1450. {
  1451. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1452. atomic_set(&dev_priv->irq_received, 0);
  1453. I915_WRITE(HWSTAM, 0xeffe);
  1454. /* XXX hotplug from PCH */
  1455. I915_WRITE(DEIMR, 0xffffffff);
  1456. I915_WRITE(DEIER, 0x0);
  1457. POSTING_READ(DEIER);
  1458. /* and GT */
  1459. I915_WRITE(GTIMR, 0xffffffff);
  1460. I915_WRITE(GTIER, 0x0);
  1461. POSTING_READ(GTIER);
  1462. /* south display irq */
  1463. I915_WRITE(SDEIMR, 0xffffffff);
  1464. I915_WRITE(SDEIER, 0x0);
  1465. POSTING_READ(SDEIER);
  1466. }
  1467. static void valleyview_irq_preinstall(struct drm_device *dev)
  1468. {
  1469. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1470. int pipe;
  1471. atomic_set(&dev_priv->irq_received, 0);
  1472. /* VLV magic */
  1473. I915_WRITE(VLV_IMR, 0);
  1474. I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
  1475. I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
  1476. I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
  1477. /* and GT */
  1478. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1479. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1480. I915_WRITE(GTIMR, 0xffffffff);
  1481. I915_WRITE(GTIER, 0x0);
  1482. POSTING_READ(GTIER);
  1483. I915_WRITE(DPINVGTT, 0xff);
  1484. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1485. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  1486. for_each_pipe(pipe)
  1487. I915_WRITE(PIPESTAT(pipe), 0xffff);
  1488. I915_WRITE(VLV_IIR, 0xffffffff);
  1489. I915_WRITE(VLV_IMR, 0xffffffff);
  1490. I915_WRITE(VLV_IER, 0x0);
  1491. POSTING_READ(VLV_IER);
  1492. }
  1493. /*
  1494. * Enable digital hotplug on the PCH, and configure the DP short pulse
  1495. * duration to 2ms (which is the minimum in the Display Port spec)
  1496. *
  1497. * This register is the same on all known PCH chips.
  1498. */
  1499. static void ironlake_enable_pch_hotplug(struct drm_device *dev)
  1500. {
  1501. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1502. u32 hotplug;
  1503. hotplug = I915_READ(PCH_PORT_HOTPLUG);
  1504. hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
  1505. hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
  1506. hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
  1507. hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
  1508. I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
  1509. }
  1510. static int ironlake_irq_postinstall(struct drm_device *dev)
  1511. {
  1512. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1513. /* enable kind of interrupts always enabled */
  1514. u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
  1515. DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE;
  1516. u32 render_irqs;
  1517. u32 hotplug_mask;
  1518. dev_priv->irq_mask = ~display_mask;
  1519. /* should always can generate irq */
  1520. I915_WRITE(DEIIR, I915_READ(DEIIR));
  1521. I915_WRITE(DEIMR, dev_priv->irq_mask);
  1522. I915_WRITE(DEIER, display_mask | DE_PIPEA_VBLANK | DE_PIPEB_VBLANK);
  1523. POSTING_READ(DEIER);
  1524. dev_priv->gt_irq_mask = ~0;
  1525. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1526. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  1527. if (IS_GEN6(dev))
  1528. render_irqs =
  1529. GT_USER_INTERRUPT |
  1530. GEN6_BSD_USER_INTERRUPT |
  1531. GEN6_BLITTER_USER_INTERRUPT;
  1532. else
  1533. render_irqs =
  1534. GT_USER_INTERRUPT |
  1535. GT_PIPE_NOTIFY |
  1536. GT_BSD_USER_INTERRUPT;
  1537. I915_WRITE(GTIER, render_irqs);
  1538. POSTING_READ(GTIER);
  1539. if (HAS_PCH_CPT(dev)) {
  1540. hotplug_mask = (SDE_CRT_HOTPLUG_CPT |
  1541. SDE_PORTB_HOTPLUG_CPT |
  1542. SDE_PORTC_HOTPLUG_CPT |
  1543. SDE_PORTD_HOTPLUG_CPT);
  1544. } else {
  1545. hotplug_mask = (SDE_CRT_HOTPLUG |
  1546. SDE_PORTB_HOTPLUG |
  1547. SDE_PORTC_HOTPLUG |
  1548. SDE_PORTD_HOTPLUG |
  1549. SDE_AUX_MASK);
  1550. }
  1551. dev_priv->pch_irq_mask = ~hotplug_mask;
  1552. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  1553. I915_WRITE(SDEIMR, dev_priv->pch_irq_mask);
  1554. I915_WRITE(SDEIER, hotplug_mask);
  1555. POSTING_READ(SDEIER);
  1556. ironlake_enable_pch_hotplug(dev);
  1557. if (IS_IRONLAKE_M(dev)) {
  1558. /* Clear & enable PCU event interrupts */
  1559. I915_WRITE(DEIIR, DE_PCU_EVENT);
  1560. I915_WRITE(DEIER, I915_READ(DEIER) | DE_PCU_EVENT);
  1561. ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
  1562. }
  1563. return 0;
  1564. }
  1565. static int ivybridge_irq_postinstall(struct drm_device *dev)
  1566. {
  1567. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1568. /* enable kind of interrupts always enabled */
  1569. u32 display_mask =
  1570. DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | DE_PCH_EVENT_IVB |
  1571. DE_PLANEC_FLIP_DONE_IVB |
  1572. DE_PLANEB_FLIP_DONE_IVB |
  1573. DE_PLANEA_FLIP_DONE_IVB;
  1574. u32 render_irqs;
  1575. u32 hotplug_mask;
  1576. dev_priv->irq_mask = ~display_mask;
  1577. /* should always can generate irq */
  1578. I915_WRITE(DEIIR, I915_READ(DEIIR));
  1579. I915_WRITE(DEIMR, dev_priv->irq_mask);
  1580. I915_WRITE(DEIER,
  1581. display_mask |
  1582. DE_PIPEC_VBLANK_IVB |
  1583. DE_PIPEB_VBLANK_IVB |
  1584. DE_PIPEA_VBLANK_IVB);
  1585. POSTING_READ(DEIER);
  1586. dev_priv->gt_irq_mask = ~GT_GEN7_L3_PARITY_ERROR_INTERRUPT;
  1587. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1588. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  1589. render_irqs = GT_USER_INTERRUPT | GEN6_BSD_USER_INTERRUPT |
  1590. GEN6_BLITTER_USER_INTERRUPT | GT_GEN7_L3_PARITY_ERROR_INTERRUPT;
  1591. I915_WRITE(GTIER, render_irqs);
  1592. POSTING_READ(GTIER);
  1593. hotplug_mask = (SDE_CRT_HOTPLUG_CPT |
  1594. SDE_PORTB_HOTPLUG_CPT |
  1595. SDE_PORTC_HOTPLUG_CPT |
  1596. SDE_PORTD_HOTPLUG_CPT);
  1597. dev_priv->pch_irq_mask = ~hotplug_mask;
  1598. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  1599. I915_WRITE(SDEIMR, dev_priv->pch_irq_mask);
  1600. I915_WRITE(SDEIER, hotplug_mask);
  1601. POSTING_READ(SDEIER);
  1602. ironlake_enable_pch_hotplug(dev);
  1603. return 0;
  1604. }
  1605. static int valleyview_irq_postinstall(struct drm_device *dev)
  1606. {
  1607. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1608. u32 enable_mask;
  1609. u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
  1610. u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV;
  1611. u32 render_irqs;
  1612. u16 msid;
  1613. enable_mask = I915_DISPLAY_PORT_INTERRUPT;
  1614. enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1615. I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
  1616. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  1617. I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1618. /*
  1619. *Leave vblank interrupts masked initially. enable/disable will
  1620. * toggle them based on usage.
  1621. */
  1622. dev_priv->irq_mask = (~enable_mask) |
  1623. I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
  1624. I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1625. dev_priv->pipestat[0] = 0;
  1626. dev_priv->pipestat[1] = 0;
  1627. /* Hack for broken MSIs on VLV */
  1628. pci_write_config_dword(dev_priv->dev->pdev, 0x94, 0xfee00000);
  1629. pci_read_config_word(dev->pdev, 0x98, &msid);
  1630. msid &= 0xff; /* mask out delivery bits */
  1631. msid |= (1<<14);
  1632. pci_write_config_word(dev_priv->dev->pdev, 0x98, msid);
  1633. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  1634. I915_WRITE(VLV_IER, enable_mask);
  1635. I915_WRITE(VLV_IIR, 0xffffffff);
  1636. I915_WRITE(PIPESTAT(0), 0xffff);
  1637. I915_WRITE(PIPESTAT(1), 0xffff);
  1638. POSTING_READ(VLV_IER);
  1639. i915_enable_pipestat(dev_priv, 0, pipestat_enable);
  1640. i915_enable_pipestat(dev_priv, 1, pipestat_enable);
  1641. I915_WRITE(VLV_IIR, 0xffffffff);
  1642. I915_WRITE(VLV_IIR, 0xffffffff);
  1643. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1644. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  1645. render_irqs = GT_USER_INTERRUPT | GEN6_BSD_USER_INTERRUPT |
  1646. GEN6_BLITTER_USER_INTERRUPT;
  1647. I915_WRITE(GTIER, render_irqs);
  1648. POSTING_READ(GTIER);
  1649. /* ack & enable invalid PTE error interrupts */
  1650. #if 0 /* FIXME: add support to irq handler for checking these bits */
  1651. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
  1652. I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
  1653. #endif
  1654. I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
  1655. /* Note HDMI and DP share bits */
  1656. if (dev_priv->hotplug_supported_mask & HDMIB_HOTPLUG_INT_STATUS)
  1657. hotplug_en |= HDMIB_HOTPLUG_INT_EN;
  1658. if (dev_priv->hotplug_supported_mask & HDMIC_HOTPLUG_INT_STATUS)
  1659. hotplug_en |= HDMIC_HOTPLUG_INT_EN;
  1660. if (dev_priv->hotplug_supported_mask & HDMID_HOTPLUG_INT_STATUS)
  1661. hotplug_en |= HDMID_HOTPLUG_INT_EN;
  1662. if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS_I915)
  1663. hotplug_en |= SDVOC_HOTPLUG_INT_EN;
  1664. if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS_I915)
  1665. hotplug_en |= SDVOB_HOTPLUG_INT_EN;
  1666. if (dev_priv->hotplug_supported_mask & CRT_HOTPLUG_INT_STATUS) {
  1667. hotplug_en |= CRT_HOTPLUG_INT_EN;
  1668. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  1669. }
  1670. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  1671. return 0;
  1672. }
  1673. static void valleyview_irq_uninstall(struct drm_device *dev)
  1674. {
  1675. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1676. int pipe;
  1677. if (!dev_priv)
  1678. return;
  1679. for_each_pipe(pipe)
  1680. I915_WRITE(PIPESTAT(pipe), 0xffff);
  1681. I915_WRITE(HWSTAM, 0xffffffff);
  1682. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1683. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  1684. for_each_pipe(pipe)
  1685. I915_WRITE(PIPESTAT(pipe), 0xffff);
  1686. I915_WRITE(VLV_IIR, 0xffffffff);
  1687. I915_WRITE(VLV_IMR, 0xffffffff);
  1688. I915_WRITE(VLV_IER, 0x0);
  1689. POSTING_READ(VLV_IER);
  1690. }
  1691. static void ironlake_irq_uninstall(struct drm_device *dev)
  1692. {
  1693. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1694. if (!dev_priv)
  1695. return;
  1696. I915_WRITE(HWSTAM, 0xffffffff);
  1697. I915_WRITE(DEIMR, 0xffffffff);
  1698. I915_WRITE(DEIER, 0x0);
  1699. I915_WRITE(DEIIR, I915_READ(DEIIR));
  1700. I915_WRITE(GTIMR, 0xffffffff);
  1701. I915_WRITE(GTIER, 0x0);
  1702. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1703. I915_WRITE(SDEIMR, 0xffffffff);
  1704. I915_WRITE(SDEIER, 0x0);
  1705. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  1706. }
  1707. static void i8xx_irq_preinstall(struct drm_device * dev)
  1708. {
  1709. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1710. int pipe;
  1711. atomic_set(&dev_priv->irq_received, 0);
  1712. for_each_pipe(pipe)
  1713. I915_WRITE(PIPESTAT(pipe), 0);
  1714. I915_WRITE16(IMR, 0xffff);
  1715. I915_WRITE16(IER, 0x0);
  1716. POSTING_READ16(IER);
  1717. }
  1718. static int i8xx_irq_postinstall(struct drm_device *dev)
  1719. {
  1720. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1721. dev_priv->pipestat[0] = 0;
  1722. dev_priv->pipestat[1] = 0;
  1723. I915_WRITE16(EMR,
  1724. ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  1725. /* Unmask the interrupts that we always want on. */
  1726. dev_priv->irq_mask =
  1727. ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1728. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  1729. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  1730. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  1731. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  1732. I915_WRITE16(IMR, dev_priv->irq_mask);
  1733. I915_WRITE16(IER,
  1734. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1735. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  1736. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
  1737. I915_USER_INTERRUPT);
  1738. POSTING_READ16(IER);
  1739. return 0;
  1740. }
  1741. static irqreturn_t i8xx_irq_handler(int irq, void *arg)
  1742. {
  1743. struct drm_device *dev = (struct drm_device *) arg;
  1744. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1745. u16 iir, new_iir;
  1746. u32 pipe_stats[2];
  1747. unsigned long irqflags;
  1748. int irq_received;
  1749. int pipe;
  1750. u16 flip_mask =
  1751. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  1752. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  1753. atomic_inc(&dev_priv->irq_received);
  1754. iir = I915_READ16(IIR);
  1755. if (iir == 0)
  1756. return IRQ_NONE;
  1757. while (iir & ~flip_mask) {
  1758. /* Can't rely on pipestat interrupt bit in iir as it might
  1759. * have been cleared after the pipestat interrupt was received.
  1760. * It doesn't set the bit in iir again, but it still produces
  1761. * interrupts (for non-MSI).
  1762. */
  1763. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1764. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  1765. i915_handle_error(dev, false);
  1766. for_each_pipe(pipe) {
  1767. int reg = PIPESTAT(pipe);
  1768. pipe_stats[pipe] = I915_READ(reg);
  1769. /*
  1770. * Clear the PIPE*STAT regs before the IIR
  1771. */
  1772. if (pipe_stats[pipe] & 0x8000ffff) {
  1773. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  1774. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  1775. pipe_name(pipe));
  1776. I915_WRITE(reg, pipe_stats[pipe]);
  1777. irq_received = 1;
  1778. }
  1779. }
  1780. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1781. I915_WRITE16(IIR, iir & ~flip_mask);
  1782. new_iir = I915_READ16(IIR); /* Flush posted writes */
  1783. i915_update_dri1_breadcrumb(dev);
  1784. if (iir & I915_USER_INTERRUPT)
  1785. notify_ring(dev, &dev_priv->ring[RCS]);
  1786. if (pipe_stats[0] & PIPE_VBLANK_INTERRUPT_STATUS &&
  1787. drm_handle_vblank(dev, 0)) {
  1788. if (iir & I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT) {
  1789. intel_prepare_page_flip(dev, 0);
  1790. intel_finish_page_flip(dev, 0);
  1791. flip_mask &= ~I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT;
  1792. }
  1793. }
  1794. if (pipe_stats[1] & PIPE_VBLANK_INTERRUPT_STATUS &&
  1795. drm_handle_vblank(dev, 1)) {
  1796. if (iir & I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT) {
  1797. intel_prepare_page_flip(dev, 1);
  1798. intel_finish_page_flip(dev, 1);
  1799. flip_mask &= ~I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  1800. }
  1801. }
  1802. iir = new_iir;
  1803. }
  1804. return IRQ_HANDLED;
  1805. }
  1806. static void i8xx_irq_uninstall(struct drm_device * dev)
  1807. {
  1808. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1809. int pipe;
  1810. for_each_pipe(pipe) {
  1811. /* Clear enable bits; then clear status bits */
  1812. I915_WRITE(PIPESTAT(pipe), 0);
  1813. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  1814. }
  1815. I915_WRITE16(IMR, 0xffff);
  1816. I915_WRITE16(IER, 0x0);
  1817. I915_WRITE16(IIR, I915_READ16(IIR));
  1818. }
  1819. static void i915_irq_preinstall(struct drm_device * dev)
  1820. {
  1821. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1822. int pipe;
  1823. atomic_set(&dev_priv->irq_received, 0);
  1824. if (I915_HAS_HOTPLUG(dev)) {
  1825. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1826. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  1827. }
  1828. I915_WRITE16(HWSTAM, 0xeffe);
  1829. for_each_pipe(pipe)
  1830. I915_WRITE(PIPESTAT(pipe), 0);
  1831. I915_WRITE(IMR, 0xffffffff);
  1832. I915_WRITE(IER, 0x0);
  1833. POSTING_READ(IER);
  1834. }
  1835. static int i915_irq_postinstall(struct drm_device *dev)
  1836. {
  1837. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1838. u32 enable_mask;
  1839. dev_priv->pipestat[0] = 0;
  1840. dev_priv->pipestat[1] = 0;
  1841. I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  1842. /* Unmask the interrupts that we always want on. */
  1843. dev_priv->irq_mask =
  1844. ~(I915_ASLE_INTERRUPT |
  1845. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1846. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  1847. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  1848. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  1849. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  1850. enable_mask =
  1851. I915_ASLE_INTERRUPT |
  1852. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1853. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  1854. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
  1855. I915_USER_INTERRUPT;
  1856. if (I915_HAS_HOTPLUG(dev)) {
  1857. /* Enable in IER... */
  1858. enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
  1859. /* and unmask in IMR */
  1860. dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
  1861. }
  1862. I915_WRITE(IMR, dev_priv->irq_mask);
  1863. I915_WRITE(IER, enable_mask);
  1864. POSTING_READ(IER);
  1865. if (I915_HAS_HOTPLUG(dev)) {
  1866. u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
  1867. if (dev_priv->hotplug_supported_mask & HDMIB_HOTPLUG_INT_STATUS)
  1868. hotplug_en |= HDMIB_HOTPLUG_INT_EN;
  1869. if (dev_priv->hotplug_supported_mask & HDMIC_HOTPLUG_INT_STATUS)
  1870. hotplug_en |= HDMIC_HOTPLUG_INT_EN;
  1871. if (dev_priv->hotplug_supported_mask & HDMID_HOTPLUG_INT_STATUS)
  1872. hotplug_en |= HDMID_HOTPLUG_INT_EN;
  1873. if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS_I915)
  1874. hotplug_en |= SDVOC_HOTPLUG_INT_EN;
  1875. if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS_I915)
  1876. hotplug_en |= SDVOB_HOTPLUG_INT_EN;
  1877. if (dev_priv->hotplug_supported_mask & CRT_HOTPLUG_INT_STATUS) {
  1878. hotplug_en |= CRT_HOTPLUG_INT_EN;
  1879. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  1880. }
  1881. /* Ignore TV since it's buggy */
  1882. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  1883. }
  1884. intel_opregion_enable_asle(dev);
  1885. return 0;
  1886. }
  1887. static irqreturn_t i915_irq_handler(int irq, void *arg)
  1888. {
  1889. struct drm_device *dev = (struct drm_device *) arg;
  1890. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1891. u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
  1892. unsigned long irqflags;
  1893. u32 flip_mask =
  1894. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  1895. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  1896. u32 flip[2] = {
  1897. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT,
  1898. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT
  1899. };
  1900. int pipe, ret = IRQ_NONE;
  1901. atomic_inc(&dev_priv->irq_received);
  1902. iir = I915_READ(IIR);
  1903. do {
  1904. bool irq_received = (iir & ~flip_mask) != 0;
  1905. bool blc_event = false;
  1906. /* Can't rely on pipestat interrupt bit in iir as it might
  1907. * have been cleared after the pipestat interrupt was received.
  1908. * It doesn't set the bit in iir again, but it still produces
  1909. * interrupts (for non-MSI).
  1910. */
  1911. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1912. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  1913. i915_handle_error(dev, false);
  1914. for_each_pipe(pipe) {
  1915. int reg = PIPESTAT(pipe);
  1916. pipe_stats[pipe] = I915_READ(reg);
  1917. /* Clear the PIPE*STAT regs before the IIR */
  1918. if (pipe_stats[pipe] & 0x8000ffff) {
  1919. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  1920. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  1921. pipe_name(pipe));
  1922. I915_WRITE(reg, pipe_stats[pipe]);
  1923. irq_received = true;
  1924. }
  1925. }
  1926. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1927. if (!irq_received)
  1928. break;
  1929. /* Consume port. Then clear IIR or we'll miss events */
  1930. if ((I915_HAS_HOTPLUG(dev)) &&
  1931. (iir & I915_DISPLAY_PORT_INTERRUPT)) {
  1932. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  1933. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  1934. hotplug_status);
  1935. if (hotplug_status & dev_priv->hotplug_supported_mask)
  1936. queue_work(dev_priv->wq,
  1937. &dev_priv->hotplug_work);
  1938. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  1939. POSTING_READ(PORT_HOTPLUG_STAT);
  1940. }
  1941. I915_WRITE(IIR, iir & ~flip_mask);
  1942. new_iir = I915_READ(IIR); /* Flush posted writes */
  1943. if (iir & I915_USER_INTERRUPT)
  1944. notify_ring(dev, &dev_priv->ring[RCS]);
  1945. for_each_pipe(pipe) {
  1946. int plane = pipe;
  1947. if (IS_MOBILE(dev))
  1948. plane = !plane;
  1949. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  1950. drm_handle_vblank(dev, pipe)) {
  1951. if (iir & flip[plane]) {
  1952. intel_prepare_page_flip(dev, plane);
  1953. intel_finish_page_flip(dev, pipe);
  1954. flip_mask &= ~flip[plane];
  1955. }
  1956. }
  1957. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  1958. blc_event = true;
  1959. }
  1960. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  1961. intel_opregion_asle_intr(dev);
  1962. /* With MSI, interrupts are only generated when iir
  1963. * transitions from zero to nonzero. If another bit got
  1964. * set while we were handling the existing iir bits, then
  1965. * we would never get another interrupt.
  1966. *
  1967. * This is fine on non-MSI as well, as if we hit this path
  1968. * we avoid exiting the interrupt handler only to generate
  1969. * another one.
  1970. *
  1971. * Note that for MSI this could cause a stray interrupt report
  1972. * if an interrupt landed in the time between writing IIR and
  1973. * the posting read. This should be rare enough to never
  1974. * trigger the 99% of 100,000 interrupts test for disabling
  1975. * stray interrupts.
  1976. */
  1977. ret = IRQ_HANDLED;
  1978. iir = new_iir;
  1979. } while (iir & ~flip_mask);
  1980. i915_update_dri1_breadcrumb(dev);
  1981. return ret;
  1982. }
  1983. static void i915_irq_uninstall(struct drm_device * dev)
  1984. {
  1985. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1986. int pipe;
  1987. if (I915_HAS_HOTPLUG(dev)) {
  1988. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1989. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  1990. }
  1991. I915_WRITE16(HWSTAM, 0xffff);
  1992. for_each_pipe(pipe) {
  1993. /* Clear enable bits; then clear status bits */
  1994. I915_WRITE(PIPESTAT(pipe), 0);
  1995. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  1996. }
  1997. I915_WRITE(IMR, 0xffffffff);
  1998. I915_WRITE(IER, 0x0);
  1999. I915_WRITE(IIR, I915_READ(IIR));
  2000. }
  2001. static void i965_irq_preinstall(struct drm_device * dev)
  2002. {
  2003. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2004. int pipe;
  2005. atomic_set(&dev_priv->irq_received, 0);
  2006. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2007. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2008. I915_WRITE(HWSTAM, 0xeffe);
  2009. for_each_pipe(pipe)
  2010. I915_WRITE(PIPESTAT(pipe), 0);
  2011. I915_WRITE(IMR, 0xffffffff);
  2012. I915_WRITE(IER, 0x0);
  2013. POSTING_READ(IER);
  2014. }
  2015. static int i965_irq_postinstall(struct drm_device *dev)
  2016. {
  2017. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2018. u32 hotplug_en;
  2019. u32 enable_mask;
  2020. u32 error_mask;
  2021. /* Unmask the interrupts that we always want on. */
  2022. dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
  2023. I915_DISPLAY_PORT_INTERRUPT |
  2024. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2025. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2026. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2027. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  2028. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2029. enable_mask = ~dev_priv->irq_mask;
  2030. enable_mask |= I915_USER_INTERRUPT;
  2031. if (IS_G4X(dev))
  2032. enable_mask |= I915_BSD_USER_INTERRUPT;
  2033. dev_priv->pipestat[0] = 0;
  2034. dev_priv->pipestat[1] = 0;
  2035. /*
  2036. * Enable some error detection, note the instruction error mask
  2037. * bit is reserved, so we leave it masked.
  2038. */
  2039. if (IS_G4X(dev)) {
  2040. error_mask = ~(GM45_ERROR_PAGE_TABLE |
  2041. GM45_ERROR_MEM_PRIV |
  2042. GM45_ERROR_CP_PRIV |
  2043. I915_ERROR_MEMORY_REFRESH);
  2044. } else {
  2045. error_mask = ~(I915_ERROR_PAGE_TABLE |
  2046. I915_ERROR_MEMORY_REFRESH);
  2047. }
  2048. I915_WRITE(EMR, error_mask);
  2049. I915_WRITE(IMR, dev_priv->irq_mask);
  2050. I915_WRITE(IER, enable_mask);
  2051. POSTING_READ(IER);
  2052. /* Note HDMI and DP share hotplug bits */
  2053. hotplug_en = 0;
  2054. if (dev_priv->hotplug_supported_mask & HDMIB_HOTPLUG_INT_STATUS)
  2055. hotplug_en |= HDMIB_HOTPLUG_INT_EN;
  2056. if (dev_priv->hotplug_supported_mask & HDMIC_HOTPLUG_INT_STATUS)
  2057. hotplug_en |= HDMIC_HOTPLUG_INT_EN;
  2058. if (dev_priv->hotplug_supported_mask & HDMID_HOTPLUG_INT_STATUS)
  2059. hotplug_en |= HDMID_HOTPLUG_INT_EN;
  2060. if (IS_G4X(dev)) {
  2061. if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS_G4X)
  2062. hotplug_en |= SDVOC_HOTPLUG_INT_EN;
  2063. if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS_G4X)
  2064. hotplug_en |= SDVOB_HOTPLUG_INT_EN;
  2065. } else {
  2066. if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS_I965)
  2067. hotplug_en |= SDVOC_HOTPLUG_INT_EN;
  2068. if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS_I965)
  2069. hotplug_en |= SDVOB_HOTPLUG_INT_EN;
  2070. }
  2071. if (dev_priv->hotplug_supported_mask & CRT_HOTPLUG_INT_STATUS) {
  2072. hotplug_en |= CRT_HOTPLUG_INT_EN;
  2073. /* Programming the CRT detection parameters tends
  2074. to generate a spurious hotplug event about three
  2075. seconds later. So just do it once.
  2076. */
  2077. if (IS_G4X(dev))
  2078. hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
  2079. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  2080. }
  2081. /* Ignore TV since it's buggy */
  2082. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  2083. intel_opregion_enable_asle(dev);
  2084. return 0;
  2085. }
  2086. static irqreturn_t i965_irq_handler(int irq, void *arg)
  2087. {
  2088. struct drm_device *dev = (struct drm_device *) arg;
  2089. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2090. u32 iir, new_iir;
  2091. u32 pipe_stats[I915_MAX_PIPES];
  2092. unsigned long irqflags;
  2093. int irq_received;
  2094. int ret = IRQ_NONE, pipe;
  2095. atomic_inc(&dev_priv->irq_received);
  2096. iir = I915_READ(IIR);
  2097. for (;;) {
  2098. bool blc_event = false;
  2099. irq_received = iir != 0;
  2100. /* Can't rely on pipestat interrupt bit in iir as it might
  2101. * have been cleared after the pipestat interrupt was received.
  2102. * It doesn't set the bit in iir again, but it still produces
  2103. * interrupts (for non-MSI).
  2104. */
  2105. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2106. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  2107. i915_handle_error(dev, false);
  2108. for_each_pipe(pipe) {
  2109. int reg = PIPESTAT(pipe);
  2110. pipe_stats[pipe] = I915_READ(reg);
  2111. /*
  2112. * Clear the PIPE*STAT regs before the IIR
  2113. */
  2114. if (pipe_stats[pipe] & 0x8000ffff) {
  2115. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  2116. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  2117. pipe_name(pipe));
  2118. I915_WRITE(reg, pipe_stats[pipe]);
  2119. irq_received = 1;
  2120. }
  2121. }
  2122. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2123. if (!irq_received)
  2124. break;
  2125. ret = IRQ_HANDLED;
  2126. /* Consume port. Then clear IIR or we'll miss events */
  2127. if (iir & I915_DISPLAY_PORT_INTERRUPT) {
  2128. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  2129. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  2130. hotplug_status);
  2131. if (hotplug_status & dev_priv->hotplug_supported_mask)
  2132. queue_work(dev_priv->wq,
  2133. &dev_priv->hotplug_work);
  2134. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  2135. I915_READ(PORT_HOTPLUG_STAT);
  2136. }
  2137. I915_WRITE(IIR, iir);
  2138. new_iir = I915_READ(IIR); /* Flush posted writes */
  2139. if (iir & I915_USER_INTERRUPT)
  2140. notify_ring(dev, &dev_priv->ring[RCS]);
  2141. if (iir & I915_BSD_USER_INTERRUPT)
  2142. notify_ring(dev, &dev_priv->ring[VCS]);
  2143. if (iir & I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT)
  2144. intel_prepare_page_flip(dev, 0);
  2145. if (iir & I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT)
  2146. intel_prepare_page_flip(dev, 1);
  2147. for_each_pipe(pipe) {
  2148. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
  2149. drm_handle_vblank(dev, pipe)) {
  2150. i915_pageflip_stall_check(dev, pipe);
  2151. intel_finish_page_flip(dev, pipe);
  2152. }
  2153. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  2154. blc_event = true;
  2155. }
  2156. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  2157. intel_opregion_asle_intr(dev);
  2158. /* With MSI, interrupts are only generated when iir
  2159. * transitions from zero to nonzero. If another bit got
  2160. * set while we were handling the existing iir bits, then
  2161. * we would never get another interrupt.
  2162. *
  2163. * This is fine on non-MSI as well, as if we hit this path
  2164. * we avoid exiting the interrupt handler only to generate
  2165. * another one.
  2166. *
  2167. * Note that for MSI this could cause a stray interrupt report
  2168. * if an interrupt landed in the time between writing IIR and
  2169. * the posting read. This should be rare enough to never
  2170. * trigger the 99% of 100,000 interrupts test for disabling
  2171. * stray interrupts.
  2172. */
  2173. iir = new_iir;
  2174. }
  2175. i915_update_dri1_breadcrumb(dev);
  2176. return ret;
  2177. }
  2178. static void i965_irq_uninstall(struct drm_device * dev)
  2179. {
  2180. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2181. int pipe;
  2182. if (!dev_priv)
  2183. return;
  2184. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2185. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2186. I915_WRITE(HWSTAM, 0xffffffff);
  2187. for_each_pipe(pipe)
  2188. I915_WRITE(PIPESTAT(pipe), 0);
  2189. I915_WRITE(IMR, 0xffffffff);
  2190. I915_WRITE(IER, 0x0);
  2191. for_each_pipe(pipe)
  2192. I915_WRITE(PIPESTAT(pipe),
  2193. I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
  2194. I915_WRITE(IIR, I915_READ(IIR));
  2195. }
  2196. void intel_irq_init(struct drm_device *dev)
  2197. {
  2198. struct drm_i915_private *dev_priv = dev->dev_private;
  2199. INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
  2200. INIT_WORK(&dev_priv->error_work, i915_error_work_func);
  2201. INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
  2202. INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
  2203. dev->driver->get_vblank_counter = i915_get_vblank_counter;
  2204. dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
  2205. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  2206. dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
  2207. dev->driver->get_vblank_counter = gm45_get_vblank_counter;
  2208. }
  2209. if (drm_core_check_feature(dev, DRIVER_MODESET))
  2210. dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
  2211. else
  2212. dev->driver->get_vblank_timestamp = NULL;
  2213. dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
  2214. if (IS_VALLEYVIEW(dev)) {
  2215. dev->driver->irq_handler = valleyview_irq_handler;
  2216. dev->driver->irq_preinstall = valleyview_irq_preinstall;
  2217. dev->driver->irq_postinstall = valleyview_irq_postinstall;
  2218. dev->driver->irq_uninstall = valleyview_irq_uninstall;
  2219. dev->driver->enable_vblank = valleyview_enable_vblank;
  2220. dev->driver->disable_vblank = valleyview_disable_vblank;
  2221. } else if (IS_IVYBRIDGE(dev)) {
  2222. /* Share pre & uninstall handlers with ILK/SNB */
  2223. dev->driver->irq_handler = ivybridge_irq_handler;
  2224. dev->driver->irq_preinstall = ironlake_irq_preinstall;
  2225. dev->driver->irq_postinstall = ivybridge_irq_postinstall;
  2226. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  2227. dev->driver->enable_vblank = ivybridge_enable_vblank;
  2228. dev->driver->disable_vblank = ivybridge_disable_vblank;
  2229. } else if (IS_HASWELL(dev)) {
  2230. /* Share interrupts handling with IVB */
  2231. dev->driver->irq_handler = ivybridge_irq_handler;
  2232. dev->driver->irq_preinstall = ironlake_irq_preinstall;
  2233. dev->driver->irq_postinstall = ivybridge_irq_postinstall;
  2234. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  2235. dev->driver->enable_vblank = ivybridge_enable_vblank;
  2236. dev->driver->disable_vblank = ivybridge_disable_vblank;
  2237. } else if (HAS_PCH_SPLIT(dev)) {
  2238. dev->driver->irq_handler = ironlake_irq_handler;
  2239. dev->driver->irq_preinstall = ironlake_irq_preinstall;
  2240. dev->driver->irq_postinstall = ironlake_irq_postinstall;
  2241. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  2242. dev->driver->enable_vblank = ironlake_enable_vblank;
  2243. dev->driver->disable_vblank = ironlake_disable_vblank;
  2244. } else {
  2245. if (INTEL_INFO(dev)->gen == 2) {
  2246. dev->driver->irq_preinstall = i8xx_irq_preinstall;
  2247. dev->driver->irq_postinstall = i8xx_irq_postinstall;
  2248. dev->driver->irq_handler = i8xx_irq_handler;
  2249. dev->driver->irq_uninstall = i8xx_irq_uninstall;
  2250. } else if (INTEL_INFO(dev)->gen == 3) {
  2251. dev->driver->irq_preinstall = i915_irq_preinstall;
  2252. dev->driver->irq_postinstall = i915_irq_postinstall;
  2253. dev->driver->irq_uninstall = i915_irq_uninstall;
  2254. dev->driver->irq_handler = i915_irq_handler;
  2255. } else {
  2256. dev->driver->irq_preinstall = i965_irq_preinstall;
  2257. dev->driver->irq_postinstall = i965_irq_postinstall;
  2258. dev->driver->irq_uninstall = i965_irq_uninstall;
  2259. dev->driver->irq_handler = i965_irq_handler;
  2260. }
  2261. dev->driver->enable_vblank = i915_enable_vblank;
  2262. dev->driver->disable_vblank = i915_disable_vblank;
  2263. }
  2264. }