i915_irq.c 76 KB

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