i915_irq.c 79 KB

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