i915_irq.c 76 KB

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