i915_drv.h 130 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343
  1. /* i915_drv.h -- Private header for the I915 driver -*- linux-c -*-
  2. */
  3. /*
  4. *
  5. * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
  6. * All Rights Reserved.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the
  10. * "Software"), to deal in the Software without restriction, including
  11. * without limitation the rights to use, copy, modify, merge, publish,
  12. * distribute, sub license, and/or sell copies of the Software, and to
  13. * permit persons to whom the Software is furnished to do so, subject to
  14. * the following conditions:
  15. *
  16. * The above copyright notice and this permission notice (including the
  17. * next paragraph) shall be included in all copies or substantial portions
  18. * of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  23. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  24. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  25. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  26. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. *
  28. */
  29. #ifndef _I915_DRV_H_
  30. #define _I915_DRV_H_
  31. #include <uapi/drm/i915_drm.h>
  32. #include <uapi/drm/drm_fourcc.h>
  33. #include <linux/io-mapping.h>
  34. #include <linux/i2c.h>
  35. #include <linux/i2c-algo-bit.h>
  36. #include <linux/backlight.h>
  37. #include <linux/hash.h>
  38. #include <linux/intel-iommu.h>
  39. #include <linux/kref.h>
  40. #include <linux/pm_qos.h>
  41. #include <linux/reservation.h>
  42. #include <linux/shmem_fs.h>
  43. #include <drm/drmP.h>
  44. #include <drm/intel-gtt.h>
  45. #include <drm/drm_legacy.h> /* for struct drm_dma_handle */
  46. #include <drm/drm_gem.h>
  47. #include <drm/drm_auth.h>
  48. #include <drm/drm_cache.h>
  49. #include "i915_params.h"
  50. #include "i915_reg.h"
  51. #include "i915_utils.h"
  52. #include "intel_uncore.h"
  53. #include "intel_bios.h"
  54. #include "intel_dpll_mgr.h"
  55. #include "intel_uc.h"
  56. #include "intel_lrc.h"
  57. #include "intel_ringbuffer.h"
  58. #include "i915_gem.h"
  59. #include "i915_gem_context.h"
  60. #include "i915_gem_fence_reg.h"
  61. #include "i915_gem_object.h"
  62. #include "i915_gem_gtt.h"
  63. #include "i915_gem_render_state.h"
  64. #include "i915_gem_request.h"
  65. #include "i915_gem_timeline.h"
  66. #include "i915_vma.h"
  67. #include "intel_gvt.h"
  68. /* General customization:
  69. */
  70. #define DRIVER_NAME "i915"
  71. #define DRIVER_DESC "Intel Graphics"
  72. #define DRIVER_DATE "20170818"
  73. #define DRIVER_TIMESTAMP 1503088845
  74. /* Use I915_STATE_WARN(x) and I915_STATE_WARN_ON() (rather than WARN() and
  75. * WARN_ON()) for hw state sanity checks to check for unexpected conditions
  76. * which may not necessarily be a user visible problem. This will either
  77. * WARN() or DRM_ERROR() depending on the verbose_checks moduleparam, to
  78. * enable distros and users to tailor their preferred amount of i915 abrt
  79. * spam.
  80. */
  81. #define I915_STATE_WARN(condition, format...) ({ \
  82. int __ret_warn_on = !!(condition); \
  83. if (unlikely(__ret_warn_on)) \
  84. if (!WARN(i915.verbose_state_checks, format)) \
  85. DRM_ERROR(format); \
  86. unlikely(__ret_warn_on); \
  87. })
  88. #define I915_STATE_WARN_ON(x) \
  89. I915_STATE_WARN((x), "%s", "WARN_ON(" __stringify(x) ")")
  90. bool __i915_inject_load_failure(const char *func, int line);
  91. #define i915_inject_load_failure() \
  92. __i915_inject_load_failure(__func__, __LINE__)
  93. typedef struct {
  94. uint32_t val;
  95. } uint_fixed_16_16_t;
  96. #define FP_16_16_MAX ({ \
  97. uint_fixed_16_16_t fp; \
  98. fp.val = UINT_MAX; \
  99. fp; \
  100. })
  101. static inline bool is_fixed16_zero(uint_fixed_16_16_t val)
  102. {
  103. if (val.val == 0)
  104. return true;
  105. return false;
  106. }
  107. static inline uint_fixed_16_16_t u32_to_fixed16(uint32_t val)
  108. {
  109. uint_fixed_16_16_t fp;
  110. WARN_ON(val >> 16);
  111. fp.val = val << 16;
  112. return fp;
  113. }
  114. static inline uint32_t fixed16_to_u32_round_up(uint_fixed_16_16_t fp)
  115. {
  116. return DIV_ROUND_UP(fp.val, 1 << 16);
  117. }
  118. static inline uint32_t fixed16_to_u32(uint_fixed_16_16_t fp)
  119. {
  120. return fp.val >> 16;
  121. }
  122. static inline uint_fixed_16_16_t min_fixed16(uint_fixed_16_16_t min1,
  123. uint_fixed_16_16_t min2)
  124. {
  125. uint_fixed_16_16_t min;
  126. min.val = min(min1.val, min2.val);
  127. return min;
  128. }
  129. static inline uint_fixed_16_16_t max_fixed16(uint_fixed_16_16_t max1,
  130. uint_fixed_16_16_t max2)
  131. {
  132. uint_fixed_16_16_t max;
  133. max.val = max(max1.val, max2.val);
  134. return max;
  135. }
  136. static inline uint_fixed_16_16_t clamp_u64_to_fixed16(uint64_t val)
  137. {
  138. uint_fixed_16_16_t fp;
  139. WARN_ON(val >> 32);
  140. fp.val = clamp_t(uint32_t, val, 0, ~0);
  141. return fp;
  142. }
  143. static inline uint32_t div_round_up_fixed16(uint_fixed_16_16_t val,
  144. uint_fixed_16_16_t d)
  145. {
  146. return DIV_ROUND_UP(val.val, d.val);
  147. }
  148. static inline uint32_t mul_round_up_u32_fixed16(uint32_t val,
  149. uint_fixed_16_16_t mul)
  150. {
  151. uint64_t intermediate_val;
  152. intermediate_val = (uint64_t) val * mul.val;
  153. intermediate_val = DIV_ROUND_UP_ULL(intermediate_val, 1 << 16);
  154. WARN_ON(intermediate_val >> 32);
  155. return clamp_t(uint32_t, intermediate_val, 0, ~0);
  156. }
  157. static inline uint_fixed_16_16_t mul_fixed16(uint_fixed_16_16_t val,
  158. uint_fixed_16_16_t mul)
  159. {
  160. uint64_t intermediate_val;
  161. intermediate_val = (uint64_t) val.val * mul.val;
  162. intermediate_val = intermediate_val >> 16;
  163. return clamp_u64_to_fixed16(intermediate_val);
  164. }
  165. static inline uint_fixed_16_16_t div_fixed16(uint32_t val, uint32_t d)
  166. {
  167. uint64_t interm_val;
  168. interm_val = (uint64_t)val << 16;
  169. interm_val = DIV_ROUND_UP_ULL(interm_val, d);
  170. return clamp_u64_to_fixed16(interm_val);
  171. }
  172. static inline uint32_t div_round_up_u32_fixed16(uint32_t val,
  173. uint_fixed_16_16_t d)
  174. {
  175. uint64_t interm_val;
  176. interm_val = (uint64_t)val << 16;
  177. interm_val = DIV_ROUND_UP_ULL(interm_val, d.val);
  178. WARN_ON(interm_val >> 32);
  179. return clamp_t(uint32_t, interm_val, 0, ~0);
  180. }
  181. static inline uint_fixed_16_16_t mul_u32_fixed16(uint32_t val,
  182. uint_fixed_16_16_t mul)
  183. {
  184. uint64_t intermediate_val;
  185. intermediate_val = (uint64_t) val * mul.val;
  186. return clamp_u64_to_fixed16(intermediate_val);
  187. }
  188. static inline uint_fixed_16_16_t add_fixed16(uint_fixed_16_16_t add1,
  189. uint_fixed_16_16_t add2)
  190. {
  191. uint64_t interm_sum;
  192. interm_sum = (uint64_t) add1.val + add2.val;
  193. return clamp_u64_to_fixed16(interm_sum);
  194. }
  195. static inline uint_fixed_16_16_t add_fixed16_u32(uint_fixed_16_16_t add1,
  196. uint32_t add2)
  197. {
  198. uint64_t interm_sum;
  199. uint_fixed_16_16_t interm_add2 = u32_to_fixed16(add2);
  200. interm_sum = (uint64_t) add1.val + interm_add2.val;
  201. return clamp_u64_to_fixed16(interm_sum);
  202. }
  203. static inline const char *yesno(bool v)
  204. {
  205. return v ? "yes" : "no";
  206. }
  207. static inline const char *onoff(bool v)
  208. {
  209. return v ? "on" : "off";
  210. }
  211. static inline const char *enableddisabled(bool v)
  212. {
  213. return v ? "enabled" : "disabled";
  214. }
  215. enum pipe {
  216. INVALID_PIPE = -1,
  217. PIPE_A = 0,
  218. PIPE_B,
  219. PIPE_C,
  220. _PIPE_EDP,
  221. I915_MAX_PIPES = _PIPE_EDP
  222. };
  223. #define pipe_name(p) ((p) + 'A')
  224. enum transcoder {
  225. TRANSCODER_A = 0,
  226. TRANSCODER_B,
  227. TRANSCODER_C,
  228. TRANSCODER_EDP,
  229. TRANSCODER_DSI_A,
  230. TRANSCODER_DSI_C,
  231. I915_MAX_TRANSCODERS
  232. };
  233. static inline const char *transcoder_name(enum transcoder transcoder)
  234. {
  235. switch (transcoder) {
  236. case TRANSCODER_A:
  237. return "A";
  238. case TRANSCODER_B:
  239. return "B";
  240. case TRANSCODER_C:
  241. return "C";
  242. case TRANSCODER_EDP:
  243. return "EDP";
  244. case TRANSCODER_DSI_A:
  245. return "DSI A";
  246. case TRANSCODER_DSI_C:
  247. return "DSI C";
  248. default:
  249. return "<invalid>";
  250. }
  251. }
  252. static inline bool transcoder_is_dsi(enum transcoder transcoder)
  253. {
  254. return transcoder == TRANSCODER_DSI_A || transcoder == TRANSCODER_DSI_C;
  255. }
  256. /*
  257. * Global legacy plane identifier. Valid only for primary/sprite
  258. * planes on pre-g4x, and only for primary planes on g4x+.
  259. */
  260. enum plane {
  261. PLANE_A,
  262. PLANE_B,
  263. PLANE_C,
  264. };
  265. #define plane_name(p) ((p) + 'A')
  266. #define sprite_name(p, s) ((p) * INTEL_INFO(dev_priv)->num_sprites[(p)] + (s) + 'A')
  267. /*
  268. * Per-pipe plane identifier.
  269. * I915_MAX_PLANES in the enum below is the maximum (across all platforms)
  270. * number of planes per CRTC. Not all platforms really have this many planes,
  271. * which means some arrays of size I915_MAX_PLANES may have unused entries
  272. * between the topmost sprite plane and the cursor plane.
  273. *
  274. * This is expected to be passed to various register macros
  275. * (eg. PLANE_CTL(), PS_PLANE_SEL(), etc.) so adjust with care.
  276. */
  277. enum plane_id {
  278. PLANE_PRIMARY,
  279. PLANE_SPRITE0,
  280. PLANE_SPRITE1,
  281. PLANE_SPRITE2,
  282. PLANE_CURSOR,
  283. I915_MAX_PLANES,
  284. };
  285. #define for_each_plane_id_on_crtc(__crtc, __p) \
  286. for ((__p) = PLANE_PRIMARY; (__p) < I915_MAX_PLANES; (__p)++) \
  287. for_each_if ((__crtc)->plane_ids_mask & BIT(__p))
  288. enum port {
  289. PORT_NONE = -1,
  290. PORT_A = 0,
  291. PORT_B,
  292. PORT_C,
  293. PORT_D,
  294. PORT_E,
  295. I915_MAX_PORTS
  296. };
  297. #define port_name(p) ((p) + 'A')
  298. #define I915_NUM_PHYS_VLV 2
  299. enum dpio_channel {
  300. DPIO_CH0,
  301. DPIO_CH1
  302. };
  303. enum dpio_phy {
  304. DPIO_PHY0,
  305. DPIO_PHY1,
  306. DPIO_PHY2,
  307. };
  308. enum intel_display_power_domain {
  309. POWER_DOMAIN_PIPE_A,
  310. POWER_DOMAIN_PIPE_B,
  311. POWER_DOMAIN_PIPE_C,
  312. POWER_DOMAIN_PIPE_A_PANEL_FITTER,
  313. POWER_DOMAIN_PIPE_B_PANEL_FITTER,
  314. POWER_DOMAIN_PIPE_C_PANEL_FITTER,
  315. POWER_DOMAIN_TRANSCODER_A,
  316. POWER_DOMAIN_TRANSCODER_B,
  317. POWER_DOMAIN_TRANSCODER_C,
  318. POWER_DOMAIN_TRANSCODER_EDP,
  319. POWER_DOMAIN_TRANSCODER_DSI_A,
  320. POWER_DOMAIN_TRANSCODER_DSI_C,
  321. POWER_DOMAIN_PORT_DDI_A_LANES,
  322. POWER_DOMAIN_PORT_DDI_B_LANES,
  323. POWER_DOMAIN_PORT_DDI_C_LANES,
  324. POWER_DOMAIN_PORT_DDI_D_LANES,
  325. POWER_DOMAIN_PORT_DDI_E_LANES,
  326. POWER_DOMAIN_PORT_DDI_A_IO,
  327. POWER_DOMAIN_PORT_DDI_B_IO,
  328. POWER_DOMAIN_PORT_DDI_C_IO,
  329. POWER_DOMAIN_PORT_DDI_D_IO,
  330. POWER_DOMAIN_PORT_DDI_E_IO,
  331. POWER_DOMAIN_PORT_DSI,
  332. POWER_DOMAIN_PORT_CRT,
  333. POWER_DOMAIN_PORT_OTHER,
  334. POWER_DOMAIN_VGA,
  335. POWER_DOMAIN_AUDIO,
  336. POWER_DOMAIN_PLLS,
  337. POWER_DOMAIN_AUX_A,
  338. POWER_DOMAIN_AUX_B,
  339. POWER_DOMAIN_AUX_C,
  340. POWER_DOMAIN_AUX_D,
  341. POWER_DOMAIN_GMBUS,
  342. POWER_DOMAIN_MODESET,
  343. POWER_DOMAIN_INIT,
  344. POWER_DOMAIN_NUM,
  345. };
  346. #define POWER_DOMAIN_PIPE(pipe) ((pipe) + POWER_DOMAIN_PIPE_A)
  347. #define POWER_DOMAIN_PIPE_PANEL_FITTER(pipe) \
  348. ((pipe) + POWER_DOMAIN_PIPE_A_PANEL_FITTER)
  349. #define POWER_DOMAIN_TRANSCODER(tran) \
  350. ((tran) == TRANSCODER_EDP ? POWER_DOMAIN_TRANSCODER_EDP : \
  351. (tran) + POWER_DOMAIN_TRANSCODER_A)
  352. enum hpd_pin {
  353. HPD_NONE = 0,
  354. HPD_TV = HPD_NONE, /* TV is known to be unreliable */
  355. HPD_CRT,
  356. HPD_SDVO_B,
  357. HPD_SDVO_C,
  358. HPD_PORT_A,
  359. HPD_PORT_B,
  360. HPD_PORT_C,
  361. HPD_PORT_D,
  362. HPD_PORT_E,
  363. HPD_NUM_PINS
  364. };
  365. #define for_each_hpd_pin(__pin) \
  366. for ((__pin) = (HPD_NONE + 1); (__pin) < HPD_NUM_PINS; (__pin)++)
  367. #define HPD_STORM_DEFAULT_THRESHOLD 5
  368. struct i915_hotplug {
  369. struct work_struct hotplug_work;
  370. struct {
  371. unsigned long last_jiffies;
  372. int count;
  373. enum {
  374. HPD_ENABLED = 0,
  375. HPD_DISABLED = 1,
  376. HPD_MARK_DISABLED = 2
  377. } state;
  378. } stats[HPD_NUM_PINS];
  379. u32 event_bits;
  380. struct delayed_work reenable_work;
  381. struct intel_digital_port *irq_port[I915_MAX_PORTS];
  382. u32 long_port_mask;
  383. u32 short_port_mask;
  384. struct work_struct dig_port_work;
  385. struct work_struct poll_init_work;
  386. bool poll_enabled;
  387. unsigned int hpd_storm_threshold;
  388. /*
  389. * if we get a HPD irq from DP and a HPD irq from non-DP
  390. * the non-DP HPD could block the workqueue on a mode config
  391. * mutex getting, that userspace may have taken. However
  392. * userspace is waiting on the DP workqueue to run which is
  393. * blocked behind the non-DP one.
  394. */
  395. struct workqueue_struct *dp_wq;
  396. };
  397. #define I915_GEM_GPU_DOMAINS \
  398. (I915_GEM_DOMAIN_RENDER | \
  399. I915_GEM_DOMAIN_SAMPLER | \
  400. I915_GEM_DOMAIN_COMMAND | \
  401. I915_GEM_DOMAIN_INSTRUCTION | \
  402. I915_GEM_DOMAIN_VERTEX)
  403. #define for_each_pipe(__dev_priv, __p) \
  404. for ((__p) = 0; (__p) < INTEL_INFO(__dev_priv)->num_pipes; (__p)++)
  405. #define for_each_pipe_masked(__dev_priv, __p, __mask) \
  406. for ((__p) = 0; (__p) < INTEL_INFO(__dev_priv)->num_pipes; (__p)++) \
  407. for_each_if ((__mask) & (1 << (__p)))
  408. #define for_each_universal_plane(__dev_priv, __pipe, __p) \
  409. for ((__p) = 0; \
  410. (__p) < INTEL_INFO(__dev_priv)->num_sprites[(__pipe)] + 1; \
  411. (__p)++)
  412. #define for_each_sprite(__dev_priv, __p, __s) \
  413. for ((__s) = 0; \
  414. (__s) < INTEL_INFO(__dev_priv)->num_sprites[(__p)]; \
  415. (__s)++)
  416. #define for_each_port_masked(__port, __ports_mask) \
  417. for ((__port) = PORT_A; (__port) < I915_MAX_PORTS; (__port)++) \
  418. for_each_if ((__ports_mask) & (1 << (__port)))
  419. #define for_each_crtc(dev, crtc) \
  420. list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
  421. #define for_each_intel_plane(dev, intel_plane) \
  422. list_for_each_entry(intel_plane, \
  423. &(dev)->mode_config.plane_list, \
  424. base.head)
  425. #define for_each_intel_plane_mask(dev, intel_plane, plane_mask) \
  426. list_for_each_entry(intel_plane, \
  427. &(dev)->mode_config.plane_list, \
  428. base.head) \
  429. for_each_if ((plane_mask) & \
  430. (1 << drm_plane_index(&intel_plane->base)))
  431. #define for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) \
  432. list_for_each_entry(intel_plane, \
  433. &(dev)->mode_config.plane_list, \
  434. base.head) \
  435. for_each_if ((intel_plane)->pipe == (intel_crtc)->pipe)
  436. #define for_each_intel_crtc(dev, intel_crtc) \
  437. list_for_each_entry(intel_crtc, \
  438. &(dev)->mode_config.crtc_list, \
  439. base.head)
  440. #define for_each_intel_crtc_mask(dev, intel_crtc, crtc_mask) \
  441. list_for_each_entry(intel_crtc, \
  442. &(dev)->mode_config.crtc_list, \
  443. base.head) \
  444. for_each_if ((crtc_mask) & (1 << drm_crtc_index(&intel_crtc->base)))
  445. #define for_each_intel_encoder(dev, intel_encoder) \
  446. list_for_each_entry(intel_encoder, \
  447. &(dev)->mode_config.encoder_list, \
  448. base.head)
  449. #define for_each_intel_connector_iter(intel_connector, iter) \
  450. while ((intel_connector = to_intel_connector(drm_connector_list_iter_next(iter))))
  451. #define for_each_encoder_on_crtc(dev, __crtc, intel_encoder) \
  452. list_for_each_entry((intel_encoder), &(dev)->mode_config.encoder_list, base.head) \
  453. for_each_if ((intel_encoder)->base.crtc == (__crtc))
  454. #define for_each_connector_on_encoder(dev, __encoder, intel_connector) \
  455. list_for_each_entry((intel_connector), &(dev)->mode_config.connector_list, base.head) \
  456. for_each_if ((intel_connector)->base.encoder == (__encoder))
  457. #define for_each_power_domain(domain, mask) \
  458. for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
  459. for_each_if (BIT_ULL(domain) & (mask))
  460. #define for_each_power_well(__dev_priv, __power_well) \
  461. for ((__power_well) = (__dev_priv)->power_domains.power_wells; \
  462. (__power_well) - (__dev_priv)->power_domains.power_wells < \
  463. (__dev_priv)->power_domains.power_well_count; \
  464. (__power_well)++)
  465. #define for_each_power_well_rev(__dev_priv, __power_well) \
  466. for ((__power_well) = (__dev_priv)->power_domains.power_wells + \
  467. (__dev_priv)->power_domains.power_well_count - 1; \
  468. (__power_well) - (__dev_priv)->power_domains.power_wells >= 0; \
  469. (__power_well)--)
  470. #define for_each_power_domain_well(__dev_priv, __power_well, __domain_mask) \
  471. for_each_power_well(__dev_priv, __power_well) \
  472. for_each_if ((__power_well)->domains & (__domain_mask))
  473. #define for_each_power_domain_well_rev(__dev_priv, __power_well, __domain_mask) \
  474. for_each_power_well_rev(__dev_priv, __power_well) \
  475. for_each_if ((__power_well)->domains & (__domain_mask))
  476. #define for_each_intel_plane_in_state(__state, plane, plane_state, __i) \
  477. for ((__i) = 0; \
  478. (__i) < (__state)->base.dev->mode_config.num_total_plane && \
  479. ((plane) = to_intel_plane((__state)->base.planes[__i].ptr), \
  480. (plane_state) = to_intel_plane_state((__state)->base.planes[__i].state), 1); \
  481. (__i)++) \
  482. for_each_if (plane_state)
  483. struct drm_i915_private;
  484. struct i915_mm_struct;
  485. struct i915_mmu_object;
  486. struct drm_i915_file_private {
  487. struct drm_i915_private *dev_priv;
  488. struct drm_file *file;
  489. struct {
  490. spinlock_t lock;
  491. struct list_head request_list;
  492. /* 20ms is a fairly arbitrary limit (greater than the average frame time)
  493. * chosen to prevent the CPU getting more than a frame ahead of the GPU
  494. * (when using lax throttling for the frontbuffer). We also use it to
  495. * offer free GPU waitboosts for severely congested workloads.
  496. */
  497. #define DRM_I915_THROTTLE_JIFFIES msecs_to_jiffies(20)
  498. } mm;
  499. struct idr context_idr;
  500. struct intel_rps_client {
  501. atomic_t boosts;
  502. } rps;
  503. unsigned int bsd_engine;
  504. /* Client can have a maximum of 3 contexts banned before
  505. * it is denied of creating new contexts. As one context
  506. * ban needs 4 consecutive hangs, and more if there is
  507. * progress in between, this is a last resort stop gap measure
  508. * to limit the badly behaving clients access to gpu.
  509. */
  510. #define I915_MAX_CLIENT_CONTEXT_BANS 3
  511. atomic_t context_bans;
  512. };
  513. /* Used by dp and fdi links */
  514. struct intel_link_m_n {
  515. uint32_t tu;
  516. uint32_t gmch_m;
  517. uint32_t gmch_n;
  518. uint32_t link_m;
  519. uint32_t link_n;
  520. };
  521. void intel_link_compute_m_n(int bpp, int nlanes,
  522. int pixel_clock, int link_clock,
  523. struct intel_link_m_n *m_n,
  524. bool reduce_m_n);
  525. /* Interface history:
  526. *
  527. * 1.1: Original.
  528. * 1.2: Add Power Management
  529. * 1.3: Add vblank support
  530. * 1.4: Fix cmdbuffer path, add heap destroy
  531. * 1.5: Add vblank pipe configuration
  532. * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
  533. * - Support vertical blank on secondary display pipe
  534. */
  535. #define DRIVER_MAJOR 1
  536. #define DRIVER_MINOR 6
  537. #define DRIVER_PATCHLEVEL 0
  538. struct opregion_header;
  539. struct opregion_acpi;
  540. struct opregion_swsci;
  541. struct opregion_asle;
  542. struct intel_opregion {
  543. struct opregion_header *header;
  544. struct opregion_acpi *acpi;
  545. struct opregion_swsci *swsci;
  546. u32 swsci_gbda_sub_functions;
  547. u32 swsci_sbcb_sub_functions;
  548. struct opregion_asle *asle;
  549. void *rvda;
  550. void *vbt_firmware;
  551. const void *vbt;
  552. u32 vbt_size;
  553. u32 *lid_state;
  554. struct work_struct asle_work;
  555. };
  556. #define OPREGION_SIZE (8*1024)
  557. struct intel_overlay;
  558. struct intel_overlay_error_state;
  559. struct sdvo_device_mapping {
  560. u8 initialized;
  561. u8 dvo_port;
  562. u8 slave_addr;
  563. u8 dvo_wiring;
  564. u8 i2c_pin;
  565. u8 ddc_pin;
  566. };
  567. struct intel_connector;
  568. struct intel_encoder;
  569. struct intel_atomic_state;
  570. struct intel_crtc_state;
  571. struct intel_initial_plane_config;
  572. struct intel_crtc;
  573. struct intel_limit;
  574. struct dpll;
  575. struct intel_cdclk_state;
  576. struct drm_i915_display_funcs {
  577. void (*get_cdclk)(struct drm_i915_private *dev_priv,
  578. struct intel_cdclk_state *cdclk_state);
  579. void (*set_cdclk)(struct drm_i915_private *dev_priv,
  580. const struct intel_cdclk_state *cdclk_state);
  581. int (*get_fifo_size)(struct drm_i915_private *dev_priv, int plane);
  582. int (*compute_pipe_wm)(struct intel_crtc_state *cstate);
  583. int (*compute_intermediate_wm)(struct drm_device *dev,
  584. struct intel_crtc *intel_crtc,
  585. struct intel_crtc_state *newstate);
  586. void (*initial_watermarks)(struct intel_atomic_state *state,
  587. struct intel_crtc_state *cstate);
  588. void (*atomic_update_watermarks)(struct intel_atomic_state *state,
  589. struct intel_crtc_state *cstate);
  590. void (*optimize_watermarks)(struct intel_atomic_state *state,
  591. struct intel_crtc_state *cstate);
  592. int (*compute_global_watermarks)(struct drm_atomic_state *state);
  593. void (*update_wm)(struct intel_crtc *crtc);
  594. int (*modeset_calc_cdclk)(struct drm_atomic_state *state);
  595. /* Returns the active state of the crtc, and if the crtc is active,
  596. * fills out the pipe-config with the hw state. */
  597. bool (*get_pipe_config)(struct intel_crtc *,
  598. struct intel_crtc_state *);
  599. void (*get_initial_plane_config)(struct intel_crtc *,
  600. struct intel_initial_plane_config *);
  601. int (*crtc_compute_clock)(struct intel_crtc *crtc,
  602. struct intel_crtc_state *crtc_state);
  603. void (*crtc_enable)(struct intel_crtc_state *pipe_config,
  604. struct drm_atomic_state *old_state);
  605. void (*crtc_disable)(struct intel_crtc_state *old_crtc_state,
  606. struct drm_atomic_state *old_state);
  607. void (*update_crtcs)(struct drm_atomic_state *state,
  608. unsigned int *crtc_vblank_mask);
  609. void (*audio_codec_enable)(struct drm_connector *connector,
  610. struct intel_encoder *encoder,
  611. const struct drm_display_mode *adjusted_mode);
  612. void (*audio_codec_disable)(struct intel_encoder *encoder);
  613. void (*fdi_link_train)(struct intel_crtc *crtc,
  614. const struct intel_crtc_state *crtc_state);
  615. void (*init_clock_gating)(struct drm_i915_private *dev_priv);
  616. void (*hpd_irq_setup)(struct drm_i915_private *dev_priv);
  617. /* clock updates for mode set */
  618. /* cursor updates */
  619. /* render clock increase/decrease */
  620. /* display clock increase/decrease */
  621. /* pll clock increase/decrease */
  622. void (*load_csc_matrix)(struct drm_crtc_state *crtc_state);
  623. void (*load_luts)(struct drm_crtc_state *crtc_state);
  624. };
  625. #define CSR_VERSION(major, minor) ((major) << 16 | (minor))
  626. #define CSR_VERSION_MAJOR(version) ((version) >> 16)
  627. #define CSR_VERSION_MINOR(version) ((version) & 0xffff)
  628. struct intel_csr {
  629. struct work_struct work;
  630. const char *fw_path;
  631. uint32_t *dmc_payload;
  632. uint32_t dmc_fw_size;
  633. uint32_t version;
  634. uint32_t mmio_count;
  635. i915_reg_t mmioaddr[8];
  636. uint32_t mmiodata[8];
  637. uint32_t dc_state;
  638. uint32_t allowed_dc_mask;
  639. };
  640. #define DEV_INFO_FOR_EACH_FLAG(func) \
  641. func(is_mobile); \
  642. func(is_lp); \
  643. func(is_alpha_support); \
  644. /* Keep has_* in alphabetical order */ \
  645. func(has_64bit_reloc); \
  646. func(has_aliasing_ppgtt); \
  647. func(has_csr); \
  648. func(has_ddi); \
  649. func(has_dp_mst); \
  650. func(has_reset_engine); \
  651. func(has_fbc); \
  652. func(has_fpga_dbg); \
  653. func(has_full_ppgtt); \
  654. func(has_full_48bit_ppgtt); \
  655. func(has_gmbus_irq); \
  656. func(has_gmch_display); \
  657. func(has_guc); \
  658. func(has_guc_ct); \
  659. func(has_hotplug); \
  660. func(has_l3_dpf); \
  661. func(has_llc); \
  662. func(has_logical_ring_contexts); \
  663. func(has_overlay); \
  664. func(has_pipe_cxsr); \
  665. func(has_pooled_eu); \
  666. func(has_psr); \
  667. func(has_rc6); \
  668. func(has_rc6p); \
  669. func(has_resource_streamer); \
  670. func(has_runtime_pm); \
  671. func(has_snoop); \
  672. func(unfenced_needs_alignment); \
  673. func(cursor_needs_physical); \
  674. func(hws_needs_physical); \
  675. func(overlay_needs_physical); \
  676. func(supports_tv);
  677. struct sseu_dev_info {
  678. u8 slice_mask;
  679. u8 subslice_mask;
  680. u8 eu_total;
  681. u8 eu_per_subslice;
  682. u8 min_eu_in_pool;
  683. /* For each slice, which subslice(s) has(have) 7 EUs (bitfield)? */
  684. u8 subslice_7eu[3];
  685. u8 has_slice_pg:1;
  686. u8 has_subslice_pg:1;
  687. u8 has_eu_pg:1;
  688. };
  689. static inline unsigned int sseu_subslice_total(const struct sseu_dev_info *sseu)
  690. {
  691. return hweight8(sseu->slice_mask) * hweight8(sseu->subslice_mask);
  692. }
  693. /* Keep in gen based order, and chronological order within a gen */
  694. enum intel_platform {
  695. INTEL_PLATFORM_UNINITIALIZED = 0,
  696. INTEL_I830,
  697. INTEL_I845G,
  698. INTEL_I85X,
  699. INTEL_I865G,
  700. INTEL_I915G,
  701. INTEL_I915GM,
  702. INTEL_I945G,
  703. INTEL_I945GM,
  704. INTEL_G33,
  705. INTEL_PINEVIEW,
  706. INTEL_I965G,
  707. INTEL_I965GM,
  708. INTEL_G45,
  709. INTEL_GM45,
  710. INTEL_IRONLAKE,
  711. INTEL_SANDYBRIDGE,
  712. INTEL_IVYBRIDGE,
  713. INTEL_VALLEYVIEW,
  714. INTEL_HASWELL,
  715. INTEL_BROADWELL,
  716. INTEL_CHERRYVIEW,
  717. INTEL_SKYLAKE,
  718. INTEL_BROXTON,
  719. INTEL_KABYLAKE,
  720. INTEL_GEMINILAKE,
  721. INTEL_COFFEELAKE,
  722. INTEL_CANNONLAKE,
  723. INTEL_MAX_PLATFORMS
  724. };
  725. struct intel_device_info {
  726. u32 display_mmio_offset;
  727. u16 device_id;
  728. u8 num_pipes;
  729. u8 num_sprites[I915_MAX_PIPES];
  730. u8 num_scalers[I915_MAX_PIPES];
  731. u8 gen;
  732. u16 gen_mask;
  733. enum intel_platform platform;
  734. u8 ring_mask; /* Rings supported by the HW */
  735. u8 num_rings;
  736. #define DEFINE_FLAG(name) u8 name:1
  737. DEV_INFO_FOR_EACH_FLAG(DEFINE_FLAG);
  738. #undef DEFINE_FLAG
  739. u16 ddb_size; /* in blocks */
  740. /* Register offsets for the various display pipes and transcoders */
  741. int pipe_offsets[I915_MAX_TRANSCODERS];
  742. int trans_offsets[I915_MAX_TRANSCODERS];
  743. int palette_offsets[I915_MAX_PIPES];
  744. int cursor_offsets[I915_MAX_PIPES];
  745. /* Slice/subslice/EU info */
  746. struct sseu_dev_info sseu;
  747. struct color_luts {
  748. u16 degamma_lut_size;
  749. u16 gamma_lut_size;
  750. } color;
  751. };
  752. struct intel_display_error_state;
  753. struct i915_gpu_state {
  754. struct kref ref;
  755. struct timeval time;
  756. struct timeval boottime;
  757. struct timeval uptime;
  758. struct drm_i915_private *i915;
  759. char error_msg[128];
  760. bool simulated;
  761. bool awake;
  762. bool wakelock;
  763. bool suspended;
  764. int iommu;
  765. u32 reset_count;
  766. u32 suspend_count;
  767. struct intel_device_info device_info;
  768. struct i915_params params;
  769. /* Generic register state */
  770. u32 eir;
  771. u32 pgtbl_er;
  772. u32 ier;
  773. u32 gtier[4], ngtier;
  774. u32 ccid;
  775. u32 derrmr;
  776. u32 forcewake;
  777. u32 error; /* gen6+ */
  778. u32 err_int; /* gen7 */
  779. u32 fault_data0; /* gen8, gen9 */
  780. u32 fault_data1; /* gen8, gen9 */
  781. u32 done_reg;
  782. u32 gac_eco;
  783. u32 gam_ecochk;
  784. u32 gab_ctl;
  785. u32 gfx_mode;
  786. u32 nfence;
  787. u64 fence[I915_MAX_NUM_FENCES];
  788. struct intel_overlay_error_state *overlay;
  789. struct intel_display_error_state *display;
  790. struct drm_i915_error_object *semaphore;
  791. struct drm_i915_error_object *guc_log;
  792. struct drm_i915_error_engine {
  793. int engine_id;
  794. /* Software tracked state */
  795. bool waiting;
  796. int num_waiters;
  797. unsigned long hangcheck_timestamp;
  798. bool hangcheck_stalled;
  799. enum intel_engine_hangcheck_action hangcheck_action;
  800. struct i915_address_space *vm;
  801. int num_requests;
  802. u32 reset_count;
  803. /* position of active request inside the ring */
  804. u32 rq_head, rq_post, rq_tail;
  805. /* our own tracking of ring head and tail */
  806. u32 cpu_ring_head;
  807. u32 cpu_ring_tail;
  808. u32 last_seqno;
  809. /* Register state */
  810. u32 start;
  811. u32 tail;
  812. u32 head;
  813. u32 ctl;
  814. u32 mode;
  815. u32 hws;
  816. u32 ipeir;
  817. u32 ipehr;
  818. u32 bbstate;
  819. u32 instpm;
  820. u32 instps;
  821. u32 seqno;
  822. u64 bbaddr;
  823. u64 acthd;
  824. u32 fault_reg;
  825. u64 faddr;
  826. u32 rc_psmi; /* sleep state */
  827. u32 semaphore_mboxes[I915_NUM_ENGINES - 1];
  828. struct intel_instdone instdone;
  829. struct drm_i915_error_context {
  830. char comm[TASK_COMM_LEN];
  831. pid_t pid;
  832. u32 handle;
  833. u32 hw_id;
  834. int ban_score;
  835. int active;
  836. int guilty;
  837. } context;
  838. struct drm_i915_error_object {
  839. u64 gtt_offset;
  840. u64 gtt_size;
  841. int page_count;
  842. int unused;
  843. u32 *pages[0];
  844. } *ringbuffer, *batchbuffer, *wa_batchbuffer, *ctx, *hws_page;
  845. struct drm_i915_error_object **user_bo;
  846. long user_bo_count;
  847. struct drm_i915_error_object *wa_ctx;
  848. struct drm_i915_error_request {
  849. long jiffies;
  850. pid_t pid;
  851. u32 context;
  852. int ban_score;
  853. u32 seqno;
  854. u32 head;
  855. u32 tail;
  856. } *requests, execlist[2];
  857. struct drm_i915_error_waiter {
  858. char comm[TASK_COMM_LEN];
  859. pid_t pid;
  860. u32 seqno;
  861. } *waiters;
  862. struct {
  863. u32 gfx_mode;
  864. union {
  865. u64 pdp[4];
  866. u32 pp_dir_base;
  867. };
  868. } vm_info;
  869. } engine[I915_NUM_ENGINES];
  870. struct drm_i915_error_buffer {
  871. u32 size;
  872. u32 name;
  873. u32 rseqno[I915_NUM_ENGINES], wseqno;
  874. u64 gtt_offset;
  875. u32 read_domains;
  876. u32 write_domain;
  877. s32 fence_reg:I915_MAX_NUM_FENCE_BITS;
  878. u32 tiling:2;
  879. u32 dirty:1;
  880. u32 purgeable:1;
  881. u32 userptr:1;
  882. s32 engine:4;
  883. u32 cache_level:3;
  884. } *active_bo[I915_NUM_ENGINES], *pinned_bo;
  885. u32 active_bo_count[I915_NUM_ENGINES], pinned_bo_count;
  886. struct i915_address_space *active_vm[I915_NUM_ENGINES];
  887. };
  888. enum i915_cache_level {
  889. I915_CACHE_NONE = 0,
  890. I915_CACHE_LLC, /* also used for snoopable memory on non-LLC */
  891. I915_CACHE_L3_LLC, /* gen7+, L3 sits between the domain specifc
  892. caches, eg sampler/render caches, and the
  893. large Last-Level-Cache. LLC is coherent with
  894. the CPU, but L3 is only visible to the GPU. */
  895. I915_CACHE_WT, /* hsw:gt3e WriteThrough for scanouts */
  896. };
  897. #define I915_COLOR_UNEVICTABLE (-1) /* a non-vma sharing the address space */
  898. enum fb_op_origin {
  899. ORIGIN_GTT,
  900. ORIGIN_CPU,
  901. ORIGIN_CS,
  902. ORIGIN_FLIP,
  903. ORIGIN_DIRTYFB,
  904. };
  905. struct intel_fbc {
  906. /* This is always the inner lock when overlapping with struct_mutex and
  907. * it's the outer lock when overlapping with stolen_lock. */
  908. struct mutex lock;
  909. unsigned threshold;
  910. unsigned int possible_framebuffer_bits;
  911. unsigned int busy_bits;
  912. unsigned int visible_pipes_mask;
  913. struct intel_crtc *crtc;
  914. struct drm_mm_node compressed_fb;
  915. struct drm_mm_node *compressed_llb;
  916. bool false_color;
  917. bool enabled;
  918. bool active;
  919. bool underrun_detected;
  920. struct work_struct underrun_work;
  921. /*
  922. * Due to the atomic rules we can't access some structures without the
  923. * appropriate locking, so we cache information here in order to avoid
  924. * these problems.
  925. */
  926. struct intel_fbc_state_cache {
  927. struct i915_vma *vma;
  928. struct {
  929. unsigned int mode_flags;
  930. uint32_t hsw_bdw_pixel_rate;
  931. } crtc;
  932. struct {
  933. unsigned int rotation;
  934. int src_w;
  935. int src_h;
  936. bool visible;
  937. } plane;
  938. struct {
  939. const struct drm_format_info *format;
  940. unsigned int stride;
  941. } fb;
  942. } state_cache;
  943. /*
  944. * This structure contains everything that's relevant to program the
  945. * hardware registers. When we want to figure out if we need to disable
  946. * and re-enable FBC for a new configuration we just check if there's
  947. * something different in the struct. The genx_fbc_activate functions
  948. * are supposed to read from it in order to program the registers.
  949. */
  950. struct intel_fbc_reg_params {
  951. struct i915_vma *vma;
  952. struct {
  953. enum pipe pipe;
  954. enum plane plane;
  955. unsigned int fence_y_offset;
  956. } crtc;
  957. struct {
  958. const struct drm_format_info *format;
  959. unsigned int stride;
  960. } fb;
  961. int cfb_size;
  962. } params;
  963. struct intel_fbc_work {
  964. bool scheduled;
  965. u32 scheduled_vblank;
  966. struct work_struct work;
  967. } work;
  968. const char *no_fbc_reason;
  969. };
  970. /*
  971. * HIGH_RR is the highest eDP panel refresh rate read from EDID
  972. * LOW_RR is the lowest eDP panel refresh rate found from EDID
  973. * parsing for same resolution.
  974. */
  975. enum drrs_refresh_rate_type {
  976. DRRS_HIGH_RR,
  977. DRRS_LOW_RR,
  978. DRRS_MAX_RR, /* RR count */
  979. };
  980. enum drrs_support_type {
  981. DRRS_NOT_SUPPORTED = 0,
  982. STATIC_DRRS_SUPPORT = 1,
  983. SEAMLESS_DRRS_SUPPORT = 2
  984. };
  985. struct intel_dp;
  986. struct i915_drrs {
  987. struct mutex mutex;
  988. struct delayed_work work;
  989. struct intel_dp *dp;
  990. unsigned busy_frontbuffer_bits;
  991. enum drrs_refresh_rate_type refresh_rate_type;
  992. enum drrs_support_type type;
  993. };
  994. struct i915_psr {
  995. struct mutex lock;
  996. bool sink_support;
  997. bool source_ok;
  998. struct intel_dp *enabled;
  999. bool active;
  1000. struct delayed_work work;
  1001. unsigned busy_frontbuffer_bits;
  1002. bool psr2_support;
  1003. bool aux_frame_sync;
  1004. bool link_standby;
  1005. bool y_cord_support;
  1006. bool colorimetry_support;
  1007. bool alpm;
  1008. };
  1009. enum intel_pch {
  1010. PCH_NONE = 0, /* No PCH present */
  1011. PCH_IBX, /* Ibexpeak PCH */
  1012. PCH_CPT, /* Cougarpoint/Pantherpoint PCH */
  1013. PCH_LPT, /* Lynxpoint/Wildcatpoint PCH */
  1014. PCH_SPT, /* Sunrisepoint PCH */
  1015. PCH_KBP, /* Kaby Lake PCH */
  1016. PCH_CNP, /* Cannon Lake PCH */
  1017. PCH_NOP,
  1018. };
  1019. enum intel_sbi_destination {
  1020. SBI_ICLK,
  1021. SBI_MPHY,
  1022. };
  1023. #define QUIRK_LVDS_SSC_DISABLE (1<<1)
  1024. #define QUIRK_INVERT_BRIGHTNESS (1<<2)
  1025. #define QUIRK_BACKLIGHT_PRESENT (1<<3)
  1026. #define QUIRK_PIN_SWIZZLED_PAGES (1<<5)
  1027. #define QUIRK_INCREASE_T12_DELAY (1<<6)
  1028. struct intel_fbdev;
  1029. struct intel_fbc_work;
  1030. struct intel_gmbus {
  1031. struct i2c_adapter adapter;
  1032. #define GMBUS_FORCE_BIT_RETRY (1U << 31)
  1033. u32 force_bit;
  1034. u32 reg0;
  1035. i915_reg_t gpio_reg;
  1036. struct i2c_algo_bit_data bit_algo;
  1037. struct drm_i915_private *dev_priv;
  1038. };
  1039. struct i915_suspend_saved_registers {
  1040. u32 saveDSPARB;
  1041. u32 saveFBC_CONTROL;
  1042. u32 saveCACHE_MODE_0;
  1043. u32 saveMI_ARB_STATE;
  1044. u32 saveSWF0[16];
  1045. u32 saveSWF1[16];
  1046. u32 saveSWF3[3];
  1047. uint64_t saveFENCE[I915_MAX_NUM_FENCES];
  1048. u32 savePCH_PORT_HOTPLUG;
  1049. u16 saveGCDGMBUS;
  1050. };
  1051. struct vlv_s0ix_state {
  1052. /* GAM */
  1053. u32 wr_watermark;
  1054. u32 gfx_prio_ctrl;
  1055. u32 arb_mode;
  1056. u32 gfx_pend_tlb0;
  1057. u32 gfx_pend_tlb1;
  1058. u32 lra_limits[GEN7_LRA_LIMITS_REG_NUM];
  1059. u32 media_max_req_count;
  1060. u32 gfx_max_req_count;
  1061. u32 render_hwsp;
  1062. u32 ecochk;
  1063. u32 bsd_hwsp;
  1064. u32 blt_hwsp;
  1065. u32 tlb_rd_addr;
  1066. /* MBC */
  1067. u32 g3dctl;
  1068. u32 gsckgctl;
  1069. u32 mbctl;
  1070. /* GCP */
  1071. u32 ucgctl1;
  1072. u32 ucgctl3;
  1073. u32 rcgctl1;
  1074. u32 rcgctl2;
  1075. u32 rstctl;
  1076. u32 misccpctl;
  1077. /* GPM */
  1078. u32 gfxpause;
  1079. u32 rpdeuhwtc;
  1080. u32 rpdeuc;
  1081. u32 ecobus;
  1082. u32 pwrdwnupctl;
  1083. u32 rp_down_timeout;
  1084. u32 rp_deucsw;
  1085. u32 rcubmabdtmr;
  1086. u32 rcedata;
  1087. u32 spare2gh;
  1088. /* Display 1 CZ domain */
  1089. u32 gt_imr;
  1090. u32 gt_ier;
  1091. u32 pm_imr;
  1092. u32 pm_ier;
  1093. u32 gt_scratch[GEN7_GT_SCRATCH_REG_NUM];
  1094. /* GT SA CZ domain */
  1095. u32 tilectl;
  1096. u32 gt_fifoctl;
  1097. u32 gtlc_wake_ctrl;
  1098. u32 gtlc_survive;
  1099. u32 pmwgicz;
  1100. /* Display 2 CZ domain */
  1101. u32 gu_ctl0;
  1102. u32 gu_ctl1;
  1103. u32 pcbr;
  1104. u32 clock_gate_dis2;
  1105. };
  1106. struct intel_rps_ei {
  1107. ktime_t ktime;
  1108. u32 render_c0;
  1109. u32 media_c0;
  1110. };
  1111. struct intel_gen6_power_mgmt {
  1112. /*
  1113. * work, interrupts_enabled and pm_iir are protected by
  1114. * dev_priv->irq_lock
  1115. */
  1116. struct work_struct work;
  1117. bool interrupts_enabled;
  1118. u32 pm_iir;
  1119. /* PM interrupt bits that should never be masked */
  1120. u32 pm_intrmsk_mbz;
  1121. /* Frequencies are stored in potentially platform dependent multiples.
  1122. * In other words, *_freq needs to be multiplied by X to be interesting.
  1123. * Soft limits are those which are used for the dynamic reclocking done
  1124. * by the driver (raise frequencies under heavy loads, and lower for
  1125. * lighter loads). Hard limits are those imposed by the hardware.
  1126. *
  1127. * A distinction is made for overclocking, which is never enabled by
  1128. * default, and is considered to be above the hard limit if it's
  1129. * possible at all.
  1130. */
  1131. u8 cur_freq; /* Current frequency (cached, may not == HW) */
  1132. u8 min_freq_softlimit; /* Minimum frequency permitted by the driver */
  1133. u8 max_freq_softlimit; /* Max frequency permitted by the driver */
  1134. u8 max_freq; /* Maximum frequency, RP0 if not overclocking */
  1135. u8 min_freq; /* AKA RPn. Minimum frequency */
  1136. u8 boost_freq; /* Frequency to request when wait boosting */
  1137. u8 idle_freq; /* Frequency to request when we are idle */
  1138. u8 efficient_freq; /* AKA RPe. Pre-determined balanced frequency */
  1139. u8 rp1_freq; /* "less than" RP0 power/freqency */
  1140. u8 rp0_freq; /* Non-overclocked max frequency. */
  1141. u16 gpll_ref_freq; /* vlv/chv GPLL reference frequency */
  1142. u8 up_threshold; /* Current %busy required to uplock */
  1143. u8 down_threshold; /* Current %busy required to downclock */
  1144. int last_adj;
  1145. enum { LOW_POWER, BETWEEN, HIGH_POWER } power;
  1146. bool enabled;
  1147. struct delayed_work autoenable_work;
  1148. atomic_t num_waiters;
  1149. atomic_t boosts;
  1150. /* manual wa residency calculations */
  1151. struct intel_rps_ei ei;
  1152. /*
  1153. * Protects RPS/RC6 register access and PCU communication.
  1154. * Must be taken after struct_mutex if nested. Note that
  1155. * this lock may be held for long periods of time when
  1156. * talking to hw - so only take it when talking to hw!
  1157. */
  1158. struct mutex hw_lock;
  1159. };
  1160. /* defined intel_pm.c */
  1161. extern spinlock_t mchdev_lock;
  1162. struct intel_ilk_power_mgmt {
  1163. u8 cur_delay;
  1164. u8 min_delay;
  1165. u8 max_delay;
  1166. u8 fmax;
  1167. u8 fstart;
  1168. u64 last_count1;
  1169. unsigned long last_time1;
  1170. unsigned long chipset_power;
  1171. u64 last_count2;
  1172. u64 last_time2;
  1173. unsigned long gfx_power;
  1174. u8 corr;
  1175. int c_m;
  1176. int r_t;
  1177. };
  1178. struct drm_i915_private;
  1179. struct i915_power_well;
  1180. struct i915_power_well_ops {
  1181. /*
  1182. * Synchronize the well's hw state to match the current sw state, for
  1183. * example enable/disable it based on the current refcount. Called
  1184. * during driver init and resume time, possibly after first calling
  1185. * the enable/disable handlers.
  1186. */
  1187. void (*sync_hw)(struct drm_i915_private *dev_priv,
  1188. struct i915_power_well *power_well);
  1189. /*
  1190. * Enable the well and resources that depend on it (for example
  1191. * interrupts located on the well). Called after the 0->1 refcount
  1192. * transition.
  1193. */
  1194. void (*enable)(struct drm_i915_private *dev_priv,
  1195. struct i915_power_well *power_well);
  1196. /*
  1197. * Disable the well and resources that depend on it. Called after
  1198. * the 1->0 refcount transition.
  1199. */
  1200. void (*disable)(struct drm_i915_private *dev_priv,
  1201. struct i915_power_well *power_well);
  1202. /* Returns the hw enabled state. */
  1203. bool (*is_enabled)(struct drm_i915_private *dev_priv,
  1204. struct i915_power_well *power_well);
  1205. };
  1206. /* Power well structure for haswell */
  1207. struct i915_power_well {
  1208. const char *name;
  1209. bool always_on;
  1210. /* power well enable/disable usage count */
  1211. int count;
  1212. /* cached hw enabled state */
  1213. bool hw_enabled;
  1214. u64 domains;
  1215. /* unique identifier for this power well */
  1216. enum i915_power_well_id id;
  1217. /*
  1218. * Arbitraty data associated with this power well. Platform and power
  1219. * well specific.
  1220. */
  1221. union {
  1222. struct {
  1223. enum dpio_phy phy;
  1224. } bxt;
  1225. struct {
  1226. /* Mask of pipes whose IRQ logic is backed by the pw */
  1227. u8 irq_pipe_mask;
  1228. /* The pw is backing the VGA functionality */
  1229. bool has_vga:1;
  1230. bool has_fuses:1;
  1231. } hsw;
  1232. };
  1233. const struct i915_power_well_ops *ops;
  1234. };
  1235. struct i915_power_domains {
  1236. /*
  1237. * Power wells needed for initialization at driver init and suspend
  1238. * time are on. They are kept on until after the first modeset.
  1239. */
  1240. bool init_power_on;
  1241. bool initializing;
  1242. int power_well_count;
  1243. struct mutex lock;
  1244. int domain_use_count[POWER_DOMAIN_NUM];
  1245. struct i915_power_well *power_wells;
  1246. };
  1247. #define MAX_L3_SLICES 2
  1248. struct intel_l3_parity {
  1249. u32 *remap_info[MAX_L3_SLICES];
  1250. struct work_struct error_work;
  1251. int which_slice;
  1252. };
  1253. struct i915_gem_mm {
  1254. /** Memory allocator for GTT stolen memory */
  1255. struct drm_mm stolen;
  1256. /** Protects the usage of the GTT stolen memory allocator. This is
  1257. * always the inner lock when overlapping with struct_mutex. */
  1258. struct mutex stolen_lock;
  1259. /** List of all objects in gtt_space. Used to restore gtt
  1260. * mappings on resume */
  1261. struct list_head bound_list;
  1262. /**
  1263. * List of objects which are not bound to the GTT (thus
  1264. * are idle and not used by the GPU). These objects may or may
  1265. * not actually have any pages attached.
  1266. */
  1267. struct list_head unbound_list;
  1268. /** List of all objects in gtt_space, currently mmaped by userspace.
  1269. * All objects within this list must also be on bound_list.
  1270. */
  1271. struct list_head userfault_list;
  1272. /**
  1273. * List of objects which are pending destruction.
  1274. */
  1275. struct llist_head free_list;
  1276. struct work_struct free_work;
  1277. /** Usable portion of the GTT for GEM */
  1278. dma_addr_t stolen_base; /* limited to low memory (32-bit) */
  1279. /** PPGTT used for aliasing the PPGTT with the GTT */
  1280. struct i915_hw_ppgtt *aliasing_ppgtt;
  1281. struct notifier_block oom_notifier;
  1282. struct notifier_block vmap_notifier;
  1283. struct shrinker shrinker;
  1284. /** LRU list of objects with fence regs on them. */
  1285. struct list_head fence_list;
  1286. /**
  1287. * Workqueue to fault in userptr pages, flushed by the execbuf
  1288. * when required but otherwise left to userspace to try again
  1289. * on EAGAIN.
  1290. */
  1291. struct workqueue_struct *userptr_wq;
  1292. u64 unordered_timeline;
  1293. /* the indicator for dispatch video commands on two BSD rings */
  1294. atomic_t bsd_engine_dispatch_index;
  1295. /** Bit 6 swizzling required for X tiling */
  1296. uint32_t bit_6_swizzle_x;
  1297. /** Bit 6 swizzling required for Y tiling */
  1298. uint32_t bit_6_swizzle_y;
  1299. /* accounting, useful for userland debugging */
  1300. spinlock_t object_stat_lock;
  1301. u64 object_memory;
  1302. u32 object_count;
  1303. };
  1304. struct drm_i915_error_state_buf {
  1305. struct drm_i915_private *i915;
  1306. unsigned bytes;
  1307. unsigned size;
  1308. int err;
  1309. u8 *buf;
  1310. loff_t start;
  1311. loff_t pos;
  1312. };
  1313. #define I915_RESET_TIMEOUT (10 * HZ) /* 10s */
  1314. #define I915_FENCE_TIMEOUT (10 * HZ) /* 10s */
  1315. #define I915_ENGINE_DEAD_TIMEOUT (4 * HZ) /* Seqno, head and subunits dead */
  1316. #define I915_SEQNO_DEAD_TIMEOUT (12 * HZ) /* Seqno dead with active head */
  1317. struct i915_gpu_error {
  1318. /* For hangcheck timer */
  1319. #define DRM_I915_HANGCHECK_PERIOD 1500 /* in ms */
  1320. #define DRM_I915_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD)
  1321. struct delayed_work hangcheck_work;
  1322. /* For reset and error_state handling. */
  1323. spinlock_t lock;
  1324. /* Protected by the above dev->gpu_error.lock. */
  1325. struct i915_gpu_state *first_error;
  1326. atomic_t pending_fb_pin;
  1327. unsigned long missed_irq_rings;
  1328. /**
  1329. * State variable controlling the reset flow and count
  1330. *
  1331. * This is a counter which gets incremented when reset is triggered,
  1332. *
  1333. * Before the reset commences, the I915_RESET_BACKOFF bit is set
  1334. * meaning that any waiters holding onto the struct_mutex should
  1335. * relinquish the lock immediately in order for the reset to start.
  1336. *
  1337. * If reset is not completed succesfully, the I915_WEDGE bit is
  1338. * set meaning that hardware is terminally sour and there is no
  1339. * recovery. All waiters on the reset_queue will be woken when
  1340. * that happens.
  1341. *
  1342. * This counter is used by the wait_seqno code to notice that reset
  1343. * event happened and it needs to restart the entire ioctl (since most
  1344. * likely the seqno it waited for won't ever signal anytime soon).
  1345. *
  1346. * This is important for lock-free wait paths, where no contended lock
  1347. * naturally enforces the correct ordering between the bail-out of the
  1348. * waiter and the gpu reset work code.
  1349. */
  1350. unsigned long reset_count;
  1351. /**
  1352. * flags: Control various stages of the GPU reset
  1353. *
  1354. * #I915_RESET_BACKOFF - When we start a reset, we want to stop any
  1355. * other users acquiring the struct_mutex. To do this we set the
  1356. * #I915_RESET_BACKOFF bit in the error flags when we detect a reset
  1357. * and then check for that bit before acquiring the struct_mutex (in
  1358. * i915_mutex_lock_interruptible()?). I915_RESET_BACKOFF serves a
  1359. * secondary role in preventing two concurrent global reset attempts.
  1360. *
  1361. * #I915_RESET_HANDOFF - To perform the actual GPU reset, we need the
  1362. * struct_mutex. We try to acquire the struct_mutex in the reset worker,
  1363. * but it may be held by some long running waiter (that we cannot
  1364. * interrupt without causing trouble). Once we are ready to do the GPU
  1365. * reset, we set the I915_RESET_HANDOFF bit and wakeup any waiters. If
  1366. * they already hold the struct_mutex and want to participate they can
  1367. * inspect the bit and do the reset directly, otherwise the worker
  1368. * waits for the struct_mutex.
  1369. *
  1370. * #I915_RESET_ENGINE[num_engines] - Since the driver doesn't need to
  1371. * acquire the struct_mutex to reset an engine, we need an explicit
  1372. * flag to prevent two concurrent reset attempts in the same engine.
  1373. * As the number of engines continues to grow, allocate the flags from
  1374. * the most significant bits.
  1375. *
  1376. * #I915_WEDGED - If reset fails and we can no longer use the GPU,
  1377. * we set the #I915_WEDGED bit. Prior to command submission, e.g.
  1378. * i915_gem_request_alloc(), this bit is checked and the sequence
  1379. * aborted (with -EIO reported to userspace) if set.
  1380. */
  1381. unsigned long flags;
  1382. #define I915_RESET_BACKOFF 0
  1383. #define I915_RESET_HANDOFF 1
  1384. #define I915_RESET_MODESET 2
  1385. #define I915_WEDGED (BITS_PER_LONG - 1)
  1386. #define I915_RESET_ENGINE (I915_WEDGED - I915_NUM_ENGINES)
  1387. /** Number of times an engine has been reset */
  1388. u32 reset_engine_count[I915_NUM_ENGINES];
  1389. /**
  1390. * Waitqueue to signal when a hang is detected. Used to for waiters
  1391. * to release the struct_mutex for the reset to procede.
  1392. */
  1393. wait_queue_head_t wait_queue;
  1394. /**
  1395. * Waitqueue to signal when the reset has completed. Used by clients
  1396. * that wait for dev_priv->mm.wedged to settle.
  1397. */
  1398. wait_queue_head_t reset_queue;
  1399. /* For missed irq/seqno simulation. */
  1400. unsigned long test_irq_rings;
  1401. };
  1402. enum modeset_restore {
  1403. MODESET_ON_LID_OPEN,
  1404. MODESET_DONE,
  1405. MODESET_SUSPENDED,
  1406. };
  1407. #define DP_AUX_A 0x40
  1408. #define DP_AUX_B 0x10
  1409. #define DP_AUX_C 0x20
  1410. #define DP_AUX_D 0x30
  1411. #define DDC_PIN_B 0x05
  1412. #define DDC_PIN_C 0x04
  1413. #define DDC_PIN_D 0x06
  1414. struct ddi_vbt_port_info {
  1415. /*
  1416. * This is an index in the HDMI/DVI DDI buffer translation table.
  1417. * The special value HDMI_LEVEL_SHIFT_UNKNOWN means the VBT didn't
  1418. * populate this field.
  1419. */
  1420. #define HDMI_LEVEL_SHIFT_UNKNOWN 0xff
  1421. uint8_t hdmi_level_shift;
  1422. uint8_t supports_dvi:1;
  1423. uint8_t supports_hdmi:1;
  1424. uint8_t supports_dp:1;
  1425. uint8_t supports_edp:1;
  1426. uint8_t alternate_aux_channel;
  1427. uint8_t alternate_ddc_pin;
  1428. uint8_t dp_boost_level;
  1429. uint8_t hdmi_boost_level;
  1430. };
  1431. enum psr_lines_to_wait {
  1432. PSR_0_LINES_TO_WAIT = 0,
  1433. PSR_1_LINE_TO_WAIT,
  1434. PSR_4_LINES_TO_WAIT,
  1435. PSR_8_LINES_TO_WAIT
  1436. };
  1437. struct intel_vbt_data {
  1438. struct drm_display_mode *lfp_lvds_vbt_mode; /* if any */
  1439. struct drm_display_mode *sdvo_lvds_vbt_mode; /* if any */
  1440. /* Feature bits */
  1441. unsigned int int_tv_support:1;
  1442. unsigned int lvds_dither:1;
  1443. unsigned int lvds_vbt:1;
  1444. unsigned int int_crt_support:1;
  1445. unsigned int lvds_use_ssc:1;
  1446. unsigned int display_clock_mode:1;
  1447. unsigned int fdi_rx_polarity_inverted:1;
  1448. unsigned int panel_type:4;
  1449. int lvds_ssc_freq;
  1450. unsigned int bios_lvds_val; /* initial [PCH_]LVDS reg val in VBIOS */
  1451. enum drrs_support_type drrs_type;
  1452. struct {
  1453. int rate;
  1454. int lanes;
  1455. int preemphasis;
  1456. int vswing;
  1457. bool low_vswing;
  1458. bool initialized;
  1459. bool support;
  1460. int bpp;
  1461. struct edp_power_seq pps;
  1462. } edp;
  1463. struct {
  1464. bool full_link;
  1465. bool require_aux_wakeup;
  1466. int idle_frames;
  1467. enum psr_lines_to_wait lines_to_wait;
  1468. int tp1_wakeup_time;
  1469. int tp2_tp3_wakeup_time;
  1470. } psr;
  1471. struct {
  1472. u16 pwm_freq_hz;
  1473. bool present;
  1474. bool active_low_pwm;
  1475. u8 min_brightness; /* min_brightness/255 of max */
  1476. u8 controller; /* brightness controller number */
  1477. enum intel_backlight_type type;
  1478. } backlight;
  1479. /* MIPI DSI */
  1480. struct {
  1481. u16 panel_id;
  1482. struct mipi_config *config;
  1483. struct mipi_pps_data *pps;
  1484. u8 seq_version;
  1485. u32 size;
  1486. u8 *data;
  1487. const u8 *sequence[MIPI_SEQ_MAX];
  1488. } dsi;
  1489. int crt_ddc_pin;
  1490. int child_dev_num;
  1491. union child_device_config *child_dev;
  1492. struct ddi_vbt_port_info ddi_port_info[I915_MAX_PORTS];
  1493. struct sdvo_device_mapping sdvo_mappings[2];
  1494. };
  1495. enum intel_ddb_partitioning {
  1496. INTEL_DDB_PART_1_2,
  1497. INTEL_DDB_PART_5_6, /* IVB+ */
  1498. };
  1499. struct intel_wm_level {
  1500. bool enable;
  1501. uint32_t pri_val;
  1502. uint32_t spr_val;
  1503. uint32_t cur_val;
  1504. uint32_t fbc_val;
  1505. };
  1506. struct ilk_wm_values {
  1507. uint32_t wm_pipe[3];
  1508. uint32_t wm_lp[3];
  1509. uint32_t wm_lp_spr[3];
  1510. uint32_t wm_linetime[3];
  1511. bool enable_fbc_wm;
  1512. enum intel_ddb_partitioning partitioning;
  1513. };
  1514. struct g4x_pipe_wm {
  1515. uint16_t plane[I915_MAX_PLANES];
  1516. uint16_t fbc;
  1517. };
  1518. struct g4x_sr_wm {
  1519. uint16_t plane;
  1520. uint16_t cursor;
  1521. uint16_t fbc;
  1522. };
  1523. struct vlv_wm_ddl_values {
  1524. uint8_t plane[I915_MAX_PLANES];
  1525. };
  1526. struct vlv_wm_values {
  1527. struct g4x_pipe_wm pipe[3];
  1528. struct g4x_sr_wm sr;
  1529. struct vlv_wm_ddl_values ddl[3];
  1530. uint8_t level;
  1531. bool cxsr;
  1532. };
  1533. struct g4x_wm_values {
  1534. struct g4x_pipe_wm pipe[2];
  1535. struct g4x_sr_wm sr;
  1536. struct g4x_sr_wm hpll;
  1537. bool cxsr;
  1538. bool hpll_en;
  1539. bool fbc_en;
  1540. };
  1541. struct skl_ddb_entry {
  1542. uint16_t start, end; /* in number of blocks, 'end' is exclusive */
  1543. };
  1544. static inline uint16_t skl_ddb_entry_size(const struct skl_ddb_entry *entry)
  1545. {
  1546. return entry->end - entry->start;
  1547. }
  1548. static inline bool skl_ddb_entry_equal(const struct skl_ddb_entry *e1,
  1549. const struct skl_ddb_entry *e2)
  1550. {
  1551. if (e1->start == e2->start && e1->end == e2->end)
  1552. return true;
  1553. return false;
  1554. }
  1555. struct skl_ddb_allocation {
  1556. struct skl_ddb_entry plane[I915_MAX_PIPES][I915_MAX_PLANES]; /* packed/uv */
  1557. struct skl_ddb_entry y_plane[I915_MAX_PIPES][I915_MAX_PLANES];
  1558. };
  1559. struct skl_wm_values {
  1560. unsigned dirty_pipes;
  1561. struct skl_ddb_allocation ddb;
  1562. };
  1563. struct skl_wm_level {
  1564. bool plane_en;
  1565. uint16_t plane_res_b;
  1566. uint8_t plane_res_l;
  1567. };
  1568. /*
  1569. * This struct helps tracking the state needed for runtime PM, which puts the
  1570. * device in PCI D3 state. Notice that when this happens, nothing on the
  1571. * graphics device works, even register access, so we don't get interrupts nor
  1572. * anything else.
  1573. *
  1574. * Every piece of our code that needs to actually touch the hardware needs to
  1575. * either call intel_runtime_pm_get or call intel_display_power_get with the
  1576. * appropriate power domain.
  1577. *
  1578. * Our driver uses the autosuspend delay feature, which means we'll only really
  1579. * suspend if we stay with zero refcount for a certain amount of time. The
  1580. * default value is currently very conservative (see intel_runtime_pm_enable), but
  1581. * it can be changed with the standard runtime PM files from sysfs.
  1582. *
  1583. * The irqs_disabled variable becomes true exactly after we disable the IRQs and
  1584. * goes back to false exactly before we reenable the IRQs. We use this variable
  1585. * to check if someone is trying to enable/disable IRQs while they're supposed
  1586. * to be disabled. This shouldn't happen and we'll print some error messages in
  1587. * case it happens.
  1588. *
  1589. * For more, read the Documentation/power/runtime_pm.txt.
  1590. */
  1591. struct i915_runtime_pm {
  1592. atomic_t wakeref_count;
  1593. bool suspended;
  1594. bool irqs_enabled;
  1595. };
  1596. enum intel_pipe_crc_source {
  1597. INTEL_PIPE_CRC_SOURCE_NONE,
  1598. INTEL_PIPE_CRC_SOURCE_PLANE1,
  1599. INTEL_PIPE_CRC_SOURCE_PLANE2,
  1600. INTEL_PIPE_CRC_SOURCE_PF,
  1601. INTEL_PIPE_CRC_SOURCE_PIPE,
  1602. /* TV/DP on pre-gen5/vlv can't use the pipe source. */
  1603. INTEL_PIPE_CRC_SOURCE_TV,
  1604. INTEL_PIPE_CRC_SOURCE_DP_B,
  1605. INTEL_PIPE_CRC_SOURCE_DP_C,
  1606. INTEL_PIPE_CRC_SOURCE_DP_D,
  1607. INTEL_PIPE_CRC_SOURCE_AUTO,
  1608. INTEL_PIPE_CRC_SOURCE_MAX,
  1609. };
  1610. struct intel_pipe_crc_entry {
  1611. uint32_t frame;
  1612. uint32_t crc[5];
  1613. };
  1614. #define INTEL_PIPE_CRC_ENTRIES_NR 128
  1615. struct intel_pipe_crc {
  1616. spinlock_t lock;
  1617. bool opened; /* exclusive access to the result file */
  1618. struct intel_pipe_crc_entry *entries;
  1619. enum intel_pipe_crc_source source;
  1620. int head, tail;
  1621. wait_queue_head_t wq;
  1622. int skipped;
  1623. };
  1624. struct i915_frontbuffer_tracking {
  1625. spinlock_t lock;
  1626. /*
  1627. * Tracking bits for delayed frontbuffer flushing du to gpu activity or
  1628. * scheduled flips.
  1629. */
  1630. unsigned busy_bits;
  1631. unsigned flip_bits;
  1632. };
  1633. struct i915_wa_reg {
  1634. i915_reg_t addr;
  1635. u32 value;
  1636. /* bitmask representing WA bits */
  1637. u32 mask;
  1638. };
  1639. /*
  1640. * RING_MAX_NONPRIV_SLOTS is per-engine but at this point we are only
  1641. * allowing it for RCS as we don't foresee any requirement of having
  1642. * a whitelist for other engines. When it is really required for
  1643. * other engines then the limit need to be increased.
  1644. */
  1645. #define I915_MAX_WA_REGS (16 + RING_MAX_NONPRIV_SLOTS)
  1646. struct i915_workarounds {
  1647. struct i915_wa_reg reg[I915_MAX_WA_REGS];
  1648. u32 count;
  1649. u32 hw_whitelist_count[I915_NUM_ENGINES];
  1650. };
  1651. struct i915_virtual_gpu {
  1652. bool active;
  1653. u32 caps;
  1654. };
  1655. /* used in computing the new watermarks state */
  1656. struct intel_wm_config {
  1657. unsigned int num_pipes_active;
  1658. bool sprites_enabled;
  1659. bool sprites_scaled;
  1660. };
  1661. struct i915_oa_format {
  1662. u32 format;
  1663. int size;
  1664. };
  1665. struct i915_oa_reg {
  1666. i915_reg_t addr;
  1667. u32 value;
  1668. };
  1669. struct i915_oa_config {
  1670. char uuid[UUID_STRING_LEN + 1];
  1671. int id;
  1672. const struct i915_oa_reg *mux_regs;
  1673. u32 mux_regs_len;
  1674. const struct i915_oa_reg *b_counter_regs;
  1675. u32 b_counter_regs_len;
  1676. const struct i915_oa_reg *flex_regs;
  1677. u32 flex_regs_len;
  1678. struct attribute_group sysfs_metric;
  1679. struct attribute *attrs[2];
  1680. struct device_attribute sysfs_metric_id;
  1681. atomic_t ref_count;
  1682. };
  1683. struct i915_perf_stream;
  1684. /**
  1685. * struct i915_perf_stream_ops - the OPs to support a specific stream type
  1686. */
  1687. struct i915_perf_stream_ops {
  1688. /**
  1689. * @enable: Enables the collection of HW samples, either in response to
  1690. * `I915_PERF_IOCTL_ENABLE` or implicitly called when stream is opened
  1691. * without `I915_PERF_FLAG_DISABLED`.
  1692. */
  1693. void (*enable)(struct i915_perf_stream *stream);
  1694. /**
  1695. * @disable: Disables the collection of HW samples, either in response
  1696. * to `I915_PERF_IOCTL_DISABLE` or implicitly called before destroying
  1697. * the stream.
  1698. */
  1699. void (*disable)(struct i915_perf_stream *stream);
  1700. /**
  1701. * @poll_wait: Call poll_wait, passing a wait queue that will be woken
  1702. * once there is something ready to read() for the stream
  1703. */
  1704. void (*poll_wait)(struct i915_perf_stream *stream,
  1705. struct file *file,
  1706. poll_table *wait);
  1707. /**
  1708. * @wait_unlocked: For handling a blocking read, wait until there is
  1709. * something to ready to read() for the stream. E.g. wait on the same
  1710. * wait queue that would be passed to poll_wait().
  1711. */
  1712. int (*wait_unlocked)(struct i915_perf_stream *stream);
  1713. /**
  1714. * @read: Copy buffered metrics as records to userspace
  1715. * **buf**: the userspace, destination buffer
  1716. * **count**: the number of bytes to copy, requested by userspace
  1717. * **offset**: zero at the start of the read, updated as the read
  1718. * proceeds, it represents how many bytes have been copied so far and
  1719. * the buffer offset for copying the next record.
  1720. *
  1721. * Copy as many buffered i915 perf samples and records for this stream
  1722. * to userspace as will fit in the given buffer.
  1723. *
  1724. * Only write complete records; returning -%ENOSPC if there isn't room
  1725. * for a complete record.
  1726. *
  1727. * Return any error condition that results in a short read such as
  1728. * -%ENOSPC or -%EFAULT, even though these may be squashed before
  1729. * returning to userspace.
  1730. */
  1731. int (*read)(struct i915_perf_stream *stream,
  1732. char __user *buf,
  1733. size_t count,
  1734. size_t *offset);
  1735. /**
  1736. * @destroy: Cleanup any stream specific resources.
  1737. *
  1738. * The stream will always be disabled before this is called.
  1739. */
  1740. void (*destroy)(struct i915_perf_stream *stream);
  1741. };
  1742. /**
  1743. * struct i915_perf_stream - state for a single open stream FD
  1744. */
  1745. struct i915_perf_stream {
  1746. /**
  1747. * @dev_priv: i915 drm device
  1748. */
  1749. struct drm_i915_private *dev_priv;
  1750. /**
  1751. * @link: Links the stream into ``&drm_i915_private->streams``
  1752. */
  1753. struct list_head link;
  1754. /**
  1755. * @sample_flags: Flags representing the `DRM_I915_PERF_PROP_SAMPLE_*`
  1756. * properties given when opening a stream, representing the contents
  1757. * of a single sample as read() by userspace.
  1758. */
  1759. u32 sample_flags;
  1760. /**
  1761. * @sample_size: Considering the configured contents of a sample
  1762. * combined with the required header size, this is the total size
  1763. * of a single sample record.
  1764. */
  1765. int sample_size;
  1766. /**
  1767. * @ctx: %NULL if measuring system-wide across all contexts or a
  1768. * specific context that is being monitored.
  1769. */
  1770. struct i915_gem_context *ctx;
  1771. /**
  1772. * @enabled: Whether the stream is currently enabled, considering
  1773. * whether the stream was opened in a disabled state and based
  1774. * on `I915_PERF_IOCTL_ENABLE` and `I915_PERF_IOCTL_DISABLE` calls.
  1775. */
  1776. bool enabled;
  1777. /**
  1778. * @ops: The callbacks providing the implementation of this specific
  1779. * type of configured stream.
  1780. */
  1781. const struct i915_perf_stream_ops *ops;
  1782. /**
  1783. * @oa_config: The OA configuration used by the stream.
  1784. */
  1785. struct i915_oa_config *oa_config;
  1786. };
  1787. /**
  1788. * struct i915_oa_ops - Gen specific implementation of an OA unit stream
  1789. */
  1790. struct i915_oa_ops {
  1791. /**
  1792. * @is_valid_b_counter_reg: Validates register's address for
  1793. * programming boolean counters for a particular platform.
  1794. */
  1795. bool (*is_valid_b_counter_reg)(struct drm_i915_private *dev_priv,
  1796. u32 addr);
  1797. /**
  1798. * @is_valid_mux_reg: Validates register's address for programming mux
  1799. * for a particular platform.
  1800. */
  1801. bool (*is_valid_mux_reg)(struct drm_i915_private *dev_priv, u32 addr);
  1802. /**
  1803. * @is_valid_flex_reg: Validates register's address for programming
  1804. * flex EU filtering for a particular platform.
  1805. */
  1806. bool (*is_valid_flex_reg)(struct drm_i915_private *dev_priv, u32 addr);
  1807. /**
  1808. * @init_oa_buffer: Resets the head and tail pointers of the
  1809. * circular buffer for periodic OA reports.
  1810. *
  1811. * Called when first opening a stream for OA metrics, but also may be
  1812. * called in response to an OA buffer overflow or other error
  1813. * condition.
  1814. *
  1815. * Note it may be necessary to clear the full OA buffer here as part of
  1816. * maintaining the invariable that new reports must be written to
  1817. * zeroed memory for us to be able to reliable detect if an expected
  1818. * report has not yet landed in memory. (At least on Haswell the OA
  1819. * buffer tail pointer is not synchronized with reports being visible
  1820. * to the CPU)
  1821. */
  1822. void (*init_oa_buffer)(struct drm_i915_private *dev_priv);
  1823. /**
  1824. * @enable_metric_set: Selects and applies any MUX configuration to set
  1825. * up the Boolean and Custom (B/C) counters that are part of the
  1826. * counter reports being sampled. May apply system constraints such as
  1827. * disabling EU clock gating as required.
  1828. */
  1829. int (*enable_metric_set)(struct drm_i915_private *dev_priv,
  1830. const struct i915_oa_config *oa_config);
  1831. /**
  1832. * @disable_metric_set: Remove system constraints associated with using
  1833. * the OA unit.
  1834. */
  1835. void (*disable_metric_set)(struct drm_i915_private *dev_priv);
  1836. /**
  1837. * @oa_enable: Enable periodic sampling
  1838. */
  1839. void (*oa_enable)(struct drm_i915_private *dev_priv);
  1840. /**
  1841. * @oa_disable: Disable periodic sampling
  1842. */
  1843. void (*oa_disable)(struct drm_i915_private *dev_priv);
  1844. /**
  1845. * @read: Copy data from the circular OA buffer into a given userspace
  1846. * buffer.
  1847. */
  1848. int (*read)(struct i915_perf_stream *stream,
  1849. char __user *buf,
  1850. size_t count,
  1851. size_t *offset);
  1852. /**
  1853. * @oa_hw_tail_read: read the OA tail pointer register
  1854. *
  1855. * In particular this enables us to share all the fiddly code for
  1856. * handling the OA unit tail pointer race that affects multiple
  1857. * generations.
  1858. */
  1859. u32 (*oa_hw_tail_read)(struct drm_i915_private *dev_priv);
  1860. };
  1861. struct intel_cdclk_state {
  1862. unsigned int cdclk, vco, ref;
  1863. };
  1864. struct drm_i915_private {
  1865. struct drm_device drm;
  1866. struct kmem_cache *objects;
  1867. struct kmem_cache *vmas;
  1868. struct kmem_cache *luts;
  1869. struct kmem_cache *requests;
  1870. struct kmem_cache *dependencies;
  1871. struct kmem_cache *priorities;
  1872. const struct intel_device_info info;
  1873. void __iomem *regs;
  1874. struct intel_uncore uncore;
  1875. struct i915_virtual_gpu vgpu;
  1876. struct intel_gvt *gvt;
  1877. struct intel_huc huc;
  1878. struct intel_guc guc;
  1879. struct intel_csr csr;
  1880. struct intel_gmbus gmbus[GMBUS_NUM_PINS];
  1881. /** gmbus_mutex protects against concurrent usage of the single hw gmbus
  1882. * controller on different i2c buses. */
  1883. struct mutex gmbus_mutex;
  1884. /**
  1885. * Base address of the gmbus and gpio block.
  1886. */
  1887. uint32_t gpio_mmio_base;
  1888. /* MMIO base address for MIPI regs */
  1889. uint32_t mipi_mmio_base;
  1890. uint32_t psr_mmio_base;
  1891. uint32_t pps_mmio_base;
  1892. wait_queue_head_t gmbus_wait_queue;
  1893. struct pci_dev *bridge_dev;
  1894. struct i915_gem_context *kernel_context;
  1895. struct intel_engine_cs *engine[I915_NUM_ENGINES];
  1896. struct i915_vma *semaphore;
  1897. struct drm_dma_handle *status_page_dmah;
  1898. struct resource mch_res;
  1899. /* protects the irq masks */
  1900. spinlock_t irq_lock;
  1901. bool display_irqs_enabled;
  1902. /* To control wakeup latency, e.g. for irq-driven dp aux transfers. */
  1903. struct pm_qos_request pm_qos;
  1904. /* Sideband mailbox protection */
  1905. struct mutex sb_lock;
  1906. /** Cached value of IMR to avoid reads in updating the bitfield */
  1907. union {
  1908. u32 irq_mask;
  1909. u32 de_irq_mask[I915_MAX_PIPES];
  1910. };
  1911. u32 gt_irq_mask;
  1912. u32 pm_imr;
  1913. u32 pm_ier;
  1914. u32 pm_rps_events;
  1915. u32 pm_guc_events;
  1916. u32 pipestat_irq_mask[I915_MAX_PIPES];
  1917. struct i915_hotplug hotplug;
  1918. struct intel_fbc fbc;
  1919. struct i915_drrs drrs;
  1920. struct intel_opregion opregion;
  1921. struct intel_vbt_data vbt;
  1922. bool preserve_bios_swizzle;
  1923. /* overlay */
  1924. struct intel_overlay *overlay;
  1925. /* backlight registers and fields in struct intel_panel */
  1926. struct mutex backlight_lock;
  1927. /* LVDS info */
  1928. bool no_aux_handshake;
  1929. /* protects panel power sequencer state */
  1930. struct mutex pps_mutex;
  1931. struct drm_i915_fence_reg fence_regs[I915_MAX_NUM_FENCES]; /* assume 965 */
  1932. int num_fence_regs; /* 8 on pre-965, 16 otherwise */
  1933. unsigned int fsb_freq, mem_freq, is_ddr3;
  1934. unsigned int skl_preferred_vco_freq;
  1935. unsigned int max_cdclk_freq;
  1936. unsigned int max_dotclk_freq;
  1937. unsigned int rawclk_freq;
  1938. unsigned int hpll_freq;
  1939. unsigned int czclk_freq;
  1940. struct {
  1941. /*
  1942. * The current logical cdclk state.
  1943. * See intel_atomic_state.cdclk.logical
  1944. *
  1945. * For reading holding any crtc lock is sufficient,
  1946. * for writing must hold all of them.
  1947. */
  1948. struct intel_cdclk_state logical;
  1949. /*
  1950. * The current actual cdclk state.
  1951. * See intel_atomic_state.cdclk.actual
  1952. */
  1953. struct intel_cdclk_state actual;
  1954. /* The current hardware cdclk state */
  1955. struct intel_cdclk_state hw;
  1956. } cdclk;
  1957. /**
  1958. * wq - Driver workqueue for GEM.
  1959. *
  1960. * NOTE: Work items scheduled here are not allowed to grab any modeset
  1961. * locks, for otherwise the flushing done in the pageflip code will
  1962. * result in deadlocks.
  1963. */
  1964. struct workqueue_struct *wq;
  1965. /* Display functions */
  1966. struct drm_i915_display_funcs display;
  1967. /* PCH chipset type */
  1968. enum intel_pch pch_type;
  1969. unsigned short pch_id;
  1970. unsigned long quirks;
  1971. enum modeset_restore modeset_restore;
  1972. struct mutex modeset_restore_lock;
  1973. struct drm_atomic_state *modeset_restore_state;
  1974. struct drm_modeset_acquire_ctx reset_ctx;
  1975. struct list_head vm_list; /* Global list of all address spaces */
  1976. struct i915_ggtt ggtt; /* VM representing the global address space */
  1977. struct i915_gem_mm mm;
  1978. DECLARE_HASHTABLE(mm_structs, 7);
  1979. struct mutex mm_lock;
  1980. /* Kernel Modesetting */
  1981. struct intel_crtc *plane_to_crtc_mapping[I915_MAX_PIPES];
  1982. struct intel_crtc *pipe_to_crtc_mapping[I915_MAX_PIPES];
  1983. #ifdef CONFIG_DEBUG_FS
  1984. struct intel_pipe_crc pipe_crc[I915_MAX_PIPES];
  1985. #endif
  1986. /* dpll and cdclk state is protected by connection_mutex */
  1987. int num_shared_dpll;
  1988. struct intel_shared_dpll shared_dplls[I915_NUM_PLLS];
  1989. const struct intel_dpll_mgr *dpll_mgr;
  1990. /*
  1991. * dpll_lock serializes intel_{prepare,enable,disable}_shared_dpll.
  1992. * Must be global rather than per dpll, because on some platforms
  1993. * plls share registers.
  1994. */
  1995. struct mutex dpll_lock;
  1996. unsigned int active_crtcs;
  1997. unsigned int min_pixclk[I915_MAX_PIPES];
  1998. int dpio_phy_iosf_port[I915_NUM_PHYS_VLV];
  1999. struct i915_workarounds workarounds;
  2000. struct i915_frontbuffer_tracking fb_tracking;
  2001. struct intel_atomic_helper {
  2002. struct llist_head free_list;
  2003. struct work_struct free_work;
  2004. } atomic_helper;
  2005. u16 orig_clock;
  2006. bool mchbar_need_disable;
  2007. struct intel_l3_parity l3_parity;
  2008. /* Cannot be determined by PCIID. You must always read a register. */
  2009. u32 edram_cap;
  2010. /* gen6+ rps state */
  2011. struct intel_gen6_power_mgmt rps;
  2012. /* ilk-only ips/rps state. Everything in here is protected by the global
  2013. * mchdev_lock in intel_pm.c */
  2014. struct intel_ilk_power_mgmt ips;
  2015. struct i915_power_domains power_domains;
  2016. struct i915_psr psr;
  2017. struct i915_gpu_error gpu_error;
  2018. struct drm_i915_gem_object *vlv_pctx;
  2019. /* list of fbdev register on this device */
  2020. struct intel_fbdev *fbdev;
  2021. struct work_struct fbdev_suspend_work;
  2022. struct drm_property *broadcast_rgb_property;
  2023. struct drm_property *force_audio_property;
  2024. /* hda/i915 audio component */
  2025. struct i915_audio_component *audio_component;
  2026. bool audio_component_registered;
  2027. /**
  2028. * av_mutex - mutex for audio/video sync
  2029. *
  2030. */
  2031. struct mutex av_mutex;
  2032. struct {
  2033. struct list_head list;
  2034. struct llist_head free_list;
  2035. struct work_struct free_work;
  2036. /* The hw wants to have a stable context identifier for the
  2037. * lifetime of the context (for OA, PASID, faults, etc).
  2038. * This is limited in execlists to 21 bits.
  2039. */
  2040. struct ida hw_ida;
  2041. #define MAX_CONTEXT_HW_ID (1<<21) /* exclusive */
  2042. } contexts;
  2043. u32 fdi_rx_config;
  2044. /* Shadow for DISPLAY_PHY_CONTROL which can't be safely read */
  2045. u32 chv_phy_control;
  2046. /*
  2047. * Shadows for CHV DPLL_MD regs to keep the state
  2048. * checker somewhat working in the presence hardware
  2049. * crappiness (can't read out DPLL_MD for pipes B & C).
  2050. */
  2051. u32 chv_dpll_md[I915_MAX_PIPES];
  2052. u32 bxt_phy_grc;
  2053. u32 suspend_count;
  2054. bool suspended_to_idle;
  2055. struct i915_suspend_saved_registers regfile;
  2056. struct vlv_s0ix_state vlv_s0ix_state;
  2057. enum {
  2058. I915_SAGV_UNKNOWN = 0,
  2059. I915_SAGV_DISABLED,
  2060. I915_SAGV_ENABLED,
  2061. I915_SAGV_NOT_CONTROLLED
  2062. } sagv_status;
  2063. struct {
  2064. /*
  2065. * Raw watermark latency values:
  2066. * in 0.1us units for WM0,
  2067. * in 0.5us units for WM1+.
  2068. */
  2069. /* primary */
  2070. uint16_t pri_latency[5];
  2071. /* sprite */
  2072. uint16_t spr_latency[5];
  2073. /* cursor */
  2074. uint16_t cur_latency[5];
  2075. /*
  2076. * Raw watermark memory latency values
  2077. * for SKL for all 8 levels
  2078. * in 1us units.
  2079. */
  2080. uint16_t skl_latency[8];
  2081. /* current hardware state */
  2082. union {
  2083. struct ilk_wm_values hw;
  2084. struct skl_wm_values skl_hw;
  2085. struct vlv_wm_values vlv;
  2086. struct g4x_wm_values g4x;
  2087. };
  2088. uint8_t max_level;
  2089. /*
  2090. * Should be held around atomic WM register writing; also
  2091. * protects * intel_crtc->wm.active and
  2092. * cstate->wm.need_postvbl_update.
  2093. */
  2094. struct mutex wm_mutex;
  2095. /*
  2096. * Set during HW readout of watermarks/DDB. Some platforms
  2097. * need to know when we're still using BIOS-provided values
  2098. * (which we don't fully trust).
  2099. */
  2100. bool distrust_bios_wm;
  2101. } wm;
  2102. struct i915_runtime_pm pm;
  2103. struct {
  2104. bool initialized;
  2105. struct kobject *metrics_kobj;
  2106. struct ctl_table_header *sysctl_header;
  2107. /*
  2108. * Lock associated with adding/modifying/removing OA configs
  2109. * in dev_priv->perf.metrics_idr.
  2110. */
  2111. struct mutex metrics_lock;
  2112. /*
  2113. * List of dynamic configurations, you need to hold
  2114. * dev_priv->perf.metrics_lock to access it.
  2115. */
  2116. struct idr metrics_idr;
  2117. /*
  2118. * Lock associated with anything below within this structure
  2119. * except exclusive_stream.
  2120. */
  2121. struct mutex lock;
  2122. struct list_head streams;
  2123. struct {
  2124. /*
  2125. * The stream currently using the OA unit. If accessed
  2126. * outside a syscall associated to its file
  2127. * descriptor, you need to hold
  2128. * dev_priv->drm.struct_mutex.
  2129. */
  2130. struct i915_perf_stream *exclusive_stream;
  2131. u32 specific_ctx_id;
  2132. struct hrtimer poll_check_timer;
  2133. wait_queue_head_t poll_wq;
  2134. bool pollin;
  2135. /**
  2136. * For rate limiting any notifications of spurious
  2137. * invalid OA reports
  2138. */
  2139. struct ratelimit_state spurious_report_rs;
  2140. bool periodic;
  2141. int period_exponent;
  2142. int timestamp_frequency;
  2143. struct i915_oa_config test_config;
  2144. struct {
  2145. struct i915_vma *vma;
  2146. u8 *vaddr;
  2147. u32 last_ctx_id;
  2148. int format;
  2149. int format_size;
  2150. /**
  2151. * Locks reads and writes to all head/tail state
  2152. *
  2153. * Consider: the head and tail pointer state
  2154. * needs to be read consistently from a hrtimer
  2155. * callback (atomic context) and read() fop
  2156. * (user context) with tail pointer updates
  2157. * happening in atomic context and head updates
  2158. * in user context and the (unlikely)
  2159. * possibility of read() errors needing to
  2160. * reset all head/tail state.
  2161. *
  2162. * Note: Contention or performance aren't
  2163. * currently a significant concern here
  2164. * considering the relatively low frequency of
  2165. * hrtimer callbacks (5ms period) and that
  2166. * reads typically only happen in response to a
  2167. * hrtimer event and likely complete before the
  2168. * next callback.
  2169. *
  2170. * Note: This lock is not held *while* reading
  2171. * and copying data to userspace so the value
  2172. * of head observed in htrimer callbacks won't
  2173. * represent any partial consumption of data.
  2174. */
  2175. spinlock_t ptr_lock;
  2176. /**
  2177. * One 'aging' tail pointer and one 'aged'
  2178. * tail pointer ready to used for reading.
  2179. *
  2180. * Initial values of 0xffffffff are invalid
  2181. * and imply that an update is required
  2182. * (and should be ignored by an attempted
  2183. * read)
  2184. */
  2185. struct {
  2186. u32 offset;
  2187. } tails[2];
  2188. /**
  2189. * Index for the aged tail ready to read()
  2190. * data up to.
  2191. */
  2192. unsigned int aged_tail_idx;
  2193. /**
  2194. * A monotonic timestamp for when the current
  2195. * aging tail pointer was read; used to
  2196. * determine when it is old enough to trust.
  2197. */
  2198. u64 aging_timestamp;
  2199. /**
  2200. * Although we can always read back the head
  2201. * pointer register, we prefer to avoid
  2202. * trusting the HW state, just to avoid any
  2203. * risk that some hardware condition could
  2204. * somehow bump the head pointer unpredictably
  2205. * and cause us to forward the wrong OA buffer
  2206. * data to userspace.
  2207. */
  2208. u32 head;
  2209. } oa_buffer;
  2210. u32 gen7_latched_oastatus1;
  2211. u32 ctx_oactxctrl_offset;
  2212. u32 ctx_flexeu0_offset;
  2213. /**
  2214. * The RPT_ID/reason field for Gen8+ includes a bit
  2215. * to determine if the CTX ID in the report is valid
  2216. * but the specific bit differs between Gen 8 and 9
  2217. */
  2218. u32 gen8_valid_ctx_bit;
  2219. struct i915_oa_ops ops;
  2220. const struct i915_oa_format *oa_formats;
  2221. } oa;
  2222. } perf;
  2223. /* Abstract the submission mechanism (legacy ringbuffer or execlists) away */
  2224. struct {
  2225. void (*resume)(struct drm_i915_private *);
  2226. void (*cleanup_engine)(struct intel_engine_cs *engine);
  2227. struct list_head timelines;
  2228. struct i915_gem_timeline global_timeline;
  2229. u32 active_requests;
  2230. /**
  2231. * Is the GPU currently considered idle, or busy executing
  2232. * userspace requests? Whilst idle, we allow runtime power
  2233. * management to power down the hardware and display clocks.
  2234. * In order to reduce the effect on performance, there
  2235. * is a slight delay before we do so.
  2236. */
  2237. bool awake;
  2238. /**
  2239. * We leave the user IRQ off as much as possible,
  2240. * but this means that requests will finish and never
  2241. * be retired once the system goes idle. Set a timer to
  2242. * fire periodically while the ring is running. When it
  2243. * fires, go retire requests.
  2244. */
  2245. struct delayed_work retire_work;
  2246. /**
  2247. * When we detect an idle GPU, we want to turn on
  2248. * powersaving features. So once we see that there
  2249. * are no more requests outstanding and no more
  2250. * arrive within a small period of time, we fire
  2251. * off the idle_work.
  2252. */
  2253. struct delayed_work idle_work;
  2254. ktime_t last_init_time;
  2255. } gt;
  2256. /* perform PHY state sanity checks? */
  2257. bool chv_phy_assert[2];
  2258. bool ipc_enabled;
  2259. /* Used to save the pipe-to-encoder mapping for audio */
  2260. struct intel_encoder *av_enc_map[I915_MAX_PIPES];
  2261. /* necessary resource sharing with HDMI LPE audio driver. */
  2262. struct {
  2263. struct platform_device *platdev;
  2264. int irq;
  2265. } lpe_audio;
  2266. /*
  2267. * NOTE: This is the dri1/ums dungeon, don't add stuff here. Your patch
  2268. * will be rejected. Instead look for a better place.
  2269. */
  2270. };
  2271. static inline struct drm_i915_private *to_i915(const struct drm_device *dev)
  2272. {
  2273. return container_of(dev, struct drm_i915_private, drm);
  2274. }
  2275. static inline struct drm_i915_private *kdev_to_i915(struct device *kdev)
  2276. {
  2277. return to_i915(dev_get_drvdata(kdev));
  2278. }
  2279. static inline struct drm_i915_private *guc_to_i915(struct intel_guc *guc)
  2280. {
  2281. return container_of(guc, struct drm_i915_private, guc);
  2282. }
  2283. static inline struct drm_i915_private *huc_to_i915(struct intel_huc *huc)
  2284. {
  2285. return container_of(huc, struct drm_i915_private, huc);
  2286. }
  2287. /* Simple iterator over all initialised engines */
  2288. #define for_each_engine(engine__, dev_priv__, id__) \
  2289. for ((id__) = 0; \
  2290. (id__) < I915_NUM_ENGINES; \
  2291. (id__)++) \
  2292. for_each_if ((engine__) = (dev_priv__)->engine[(id__)])
  2293. /* Iterator over subset of engines selected by mask */
  2294. #define for_each_engine_masked(engine__, dev_priv__, mask__, tmp__) \
  2295. for (tmp__ = mask__ & INTEL_INFO(dev_priv__)->ring_mask; \
  2296. tmp__ ? (engine__ = (dev_priv__)->engine[__mask_next_bit(tmp__)]), 1 : 0; )
  2297. enum hdmi_force_audio {
  2298. HDMI_AUDIO_OFF_DVI = -2, /* no aux data for HDMI-DVI converter */
  2299. HDMI_AUDIO_OFF, /* force turn off HDMI audio */
  2300. HDMI_AUDIO_AUTO, /* trust EDID */
  2301. HDMI_AUDIO_ON, /* force turn on HDMI audio */
  2302. };
  2303. #define I915_GTT_OFFSET_NONE ((u32)-1)
  2304. /*
  2305. * Frontbuffer tracking bits. Set in obj->frontbuffer_bits while a gem bo is
  2306. * considered to be the frontbuffer for the given plane interface-wise. This
  2307. * doesn't mean that the hw necessarily already scans it out, but that any
  2308. * rendering (by the cpu or gpu) will land in the frontbuffer eventually.
  2309. *
  2310. * We have one bit per pipe and per scanout plane type.
  2311. */
  2312. #define INTEL_MAX_SPRITE_BITS_PER_PIPE 5
  2313. #define INTEL_FRONTBUFFER_BITS_PER_PIPE 8
  2314. #define INTEL_FRONTBUFFER_PRIMARY(pipe) \
  2315. (1 << (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe)))
  2316. #define INTEL_FRONTBUFFER_CURSOR(pipe) \
  2317. (1 << (1 + (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))))
  2318. #define INTEL_FRONTBUFFER_SPRITE(pipe, plane) \
  2319. (1 << (2 + plane + (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))))
  2320. #define INTEL_FRONTBUFFER_OVERLAY(pipe) \
  2321. (1 << (2 + INTEL_MAX_SPRITE_BITS_PER_PIPE + (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))))
  2322. #define INTEL_FRONTBUFFER_ALL_MASK(pipe) \
  2323. (0xff << (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe)))
  2324. /*
  2325. * Optimised SGL iterator for GEM objects
  2326. */
  2327. static __always_inline struct sgt_iter {
  2328. struct scatterlist *sgp;
  2329. union {
  2330. unsigned long pfn;
  2331. dma_addr_t dma;
  2332. };
  2333. unsigned int curr;
  2334. unsigned int max;
  2335. } __sgt_iter(struct scatterlist *sgl, bool dma) {
  2336. struct sgt_iter s = { .sgp = sgl };
  2337. if (s.sgp) {
  2338. s.max = s.curr = s.sgp->offset;
  2339. s.max += s.sgp->length;
  2340. if (dma)
  2341. s.dma = sg_dma_address(s.sgp);
  2342. else
  2343. s.pfn = page_to_pfn(sg_page(s.sgp));
  2344. }
  2345. return s;
  2346. }
  2347. static inline struct scatterlist *____sg_next(struct scatterlist *sg)
  2348. {
  2349. ++sg;
  2350. if (unlikely(sg_is_chain(sg)))
  2351. sg = sg_chain_ptr(sg);
  2352. return sg;
  2353. }
  2354. /**
  2355. * __sg_next - return the next scatterlist entry in a list
  2356. * @sg: The current sg entry
  2357. *
  2358. * Description:
  2359. * If the entry is the last, return NULL; otherwise, step to the next
  2360. * element in the array (@sg@+1). If that's a chain pointer, follow it;
  2361. * otherwise just return the pointer to the current element.
  2362. **/
  2363. static inline struct scatterlist *__sg_next(struct scatterlist *sg)
  2364. {
  2365. #ifdef CONFIG_DEBUG_SG
  2366. BUG_ON(sg->sg_magic != SG_MAGIC);
  2367. #endif
  2368. return sg_is_last(sg) ? NULL : ____sg_next(sg);
  2369. }
  2370. /**
  2371. * for_each_sgt_dma - iterate over the DMA addresses of the given sg_table
  2372. * @__dmap: DMA address (output)
  2373. * @__iter: 'struct sgt_iter' (iterator state, internal)
  2374. * @__sgt: sg_table to iterate over (input)
  2375. */
  2376. #define for_each_sgt_dma(__dmap, __iter, __sgt) \
  2377. for ((__iter) = __sgt_iter((__sgt)->sgl, true); \
  2378. ((__dmap) = (__iter).dma + (__iter).curr); \
  2379. (((__iter).curr += PAGE_SIZE) < (__iter).max) || \
  2380. ((__iter) = __sgt_iter(__sg_next((__iter).sgp), true), 0))
  2381. /**
  2382. * for_each_sgt_page - iterate over the pages of the given sg_table
  2383. * @__pp: page pointer (output)
  2384. * @__iter: 'struct sgt_iter' (iterator state, internal)
  2385. * @__sgt: sg_table to iterate over (input)
  2386. */
  2387. #define for_each_sgt_page(__pp, __iter, __sgt) \
  2388. for ((__iter) = __sgt_iter((__sgt)->sgl, false); \
  2389. ((__pp) = (__iter).pfn == 0 ? NULL : \
  2390. pfn_to_page((__iter).pfn + ((__iter).curr >> PAGE_SHIFT))); \
  2391. (((__iter).curr += PAGE_SIZE) < (__iter).max) || \
  2392. ((__iter) = __sgt_iter(__sg_next((__iter).sgp), false), 0))
  2393. static inline const struct intel_device_info *
  2394. intel_info(const struct drm_i915_private *dev_priv)
  2395. {
  2396. return &dev_priv->info;
  2397. }
  2398. #define INTEL_INFO(dev_priv) intel_info((dev_priv))
  2399. #define INTEL_GEN(dev_priv) ((dev_priv)->info.gen)
  2400. #define INTEL_DEVID(dev_priv) ((dev_priv)->info.device_id)
  2401. #define REVID_FOREVER 0xff
  2402. #define INTEL_REVID(dev_priv) ((dev_priv)->drm.pdev->revision)
  2403. #define GEN_FOREVER (0)
  2404. /*
  2405. * Returns true if Gen is in inclusive range [Start, End].
  2406. *
  2407. * Use GEN_FOREVER for unbound start and or end.
  2408. */
  2409. #define IS_GEN(dev_priv, s, e) ({ \
  2410. unsigned int __s = (s), __e = (e); \
  2411. BUILD_BUG_ON(!__builtin_constant_p(s)); \
  2412. BUILD_BUG_ON(!__builtin_constant_p(e)); \
  2413. if ((__s) != GEN_FOREVER) \
  2414. __s = (s) - 1; \
  2415. if ((__e) == GEN_FOREVER) \
  2416. __e = BITS_PER_LONG - 1; \
  2417. else \
  2418. __e = (e) - 1; \
  2419. !!((dev_priv)->info.gen_mask & GENMASK((__e), (__s))); \
  2420. })
  2421. /*
  2422. * Return true if revision is in range [since,until] inclusive.
  2423. *
  2424. * Use 0 for open-ended since, and REVID_FOREVER for open-ended until.
  2425. */
  2426. #define IS_REVID(p, since, until) \
  2427. (INTEL_REVID(p) >= (since) && INTEL_REVID(p) <= (until))
  2428. #define IS_I830(dev_priv) ((dev_priv)->info.platform == INTEL_I830)
  2429. #define IS_I845G(dev_priv) ((dev_priv)->info.platform == INTEL_I845G)
  2430. #define IS_I85X(dev_priv) ((dev_priv)->info.platform == INTEL_I85X)
  2431. #define IS_I865G(dev_priv) ((dev_priv)->info.platform == INTEL_I865G)
  2432. #define IS_I915G(dev_priv) ((dev_priv)->info.platform == INTEL_I915G)
  2433. #define IS_I915GM(dev_priv) ((dev_priv)->info.platform == INTEL_I915GM)
  2434. #define IS_I945G(dev_priv) ((dev_priv)->info.platform == INTEL_I945G)
  2435. #define IS_I945GM(dev_priv) ((dev_priv)->info.platform == INTEL_I945GM)
  2436. #define IS_I965G(dev_priv) ((dev_priv)->info.platform == INTEL_I965G)
  2437. #define IS_I965GM(dev_priv) ((dev_priv)->info.platform == INTEL_I965GM)
  2438. #define IS_G45(dev_priv) ((dev_priv)->info.platform == INTEL_G45)
  2439. #define IS_GM45(dev_priv) ((dev_priv)->info.platform == INTEL_GM45)
  2440. #define IS_G4X(dev_priv) (IS_G45(dev_priv) || IS_GM45(dev_priv))
  2441. #define IS_PINEVIEW_G(dev_priv) (INTEL_DEVID(dev_priv) == 0xa001)
  2442. #define IS_PINEVIEW_M(dev_priv) (INTEL_DEVID(dev_priv) == 0xa011)
  2443. #define IS_PINEVIEW(dev_priv) ((dev_priv)->info.platform == INTEL_PINEVIEW)
  2444. #define IS_G33(dev_priv) ((dev_priv)->info.platform == INTEL_G33)
  2445. #define IS_IRONLAKE_M(dev_priv) (INTEL_DEVID(dev_priv) == 0x0046)
  2446. #define IS_IVYBRIDGE(dev_priv) ((dev_priv)->info.platform == INTEL_IVYBRIDGE)
  2447. #define IS_IVB_GT1(dev_priv) (INTEL_DEVID(dev_priv) == 0x0156 || \
  2448. INTEL_DEVID(dev_priv) == 0x0152 || \
  2449. INTEL_DEVID(dev_priv) == 0x015a)
  2450. #define IS_VALLEYVIEW(dev_priv) ((dev_priv)->info.platform == INTEL_VALLEYVIEW)
  2451. #define IS_CHERRYVIEW(dev_priv) ((dev_priv)->info.platform == INTEL_CHERRYVIEW)
  2452. #define IS_HASWELL(dev_priv) ((dev_priv)->info.platform == INTEL_HASWELL)
  2453. #define IS_BROADWELL(dev_priv) ((dev_priv)->info.platform == INTEL_BROADWELL)
  2454. #define IS_SKYLAKE(dev_priv) ((dev_priv)->info.platform == INTEL_SKYLAKE)
  2455. #define IS_BROXTON(dev_priv) ((dev_priv)->info.platform == INTEL_BROXTON)
  2456. #define IS_KABYLAKE(dev_priv) ((dev_priv)->info.platform == INTEL_KABYLAKE)
  2457. #define IS_GEMINILAKE(dev_priv) ((dev_priv)->info.platform == INTEL_GEMINILAKE)
  2458. #define IS_COFFEELAKE(dev_priv) ((dev_priv)->info.platform == INTEL_COFFEELAKE)
  2459. #define IS_CANNONLAKE(dev_priv) ((dev_priv)->info.platform == INTEL_CANNONLAKE)
  2460. #define IS_MOBILE(dev_priv) ((dev_priv)->info.is_mobile)
  2461. #define IS_HSW_EARLY_SDV(dev_priv) (IS_HASWELL(dev_priv) && \
  2462. (INTEL_DEVID(dev_priv) & 0xFF00) == 0x0C00)
  2463. #define IS_BDW_ULT(dev_priv) (IS_BROADWELL(dev_priv) && \
  2464. ((INTEL_DEVID(dev_priv) & 0xf) == 0x6 || \
  2465. (INTEL_DEVID(dev_priv) & 0xf) == 0xb || \
  2466. (INTEL_DEVID(dev_priv) & 0xf) == 0xe))
  2467. /* ULX machines are also considered ULT. */
  2468. #define IS_BDW_ULX(dev_priv) (IS_BROADWELL(dev_priv) && \
  2469. (INTEL_DEVID(dev_priv) & 0xf) == 0xe)
  2470. #define IS_BDW_GT3(dev_priv) (IS_BROADWELL(dev_priv) && \
  2471. (INTEL_DEVID(dev_priv) & 0x00F0) == 0x0020)
  2472. #define IS_HSW_ULT(dev_priv) (IS_HASWELL(dev_priv) && \
  2473. (INTEL_DEVID(dev_priv) & 0xFF00) == 0x0A00)
  2474. #define IS_HSW_GT3(dev_priv) (IS_HASWELL(dev_priv) && \
  2475. (INTEL_DEVID(dev_priv) & 0x00F0) == 0x0020)
  2476. /* ULX machines are also considered ULT. */
  2477. #define IS_HSW_ULX(dev_priv) (INTEL_DEVID(dev_priv) == 0x0A0E || \
  2478. INTEL_DEVID(dev_priv) == 0x0A1E)
  2479. #define IS_SKL_ULT(dev_priv) (INTEL_DEVID(dev_priv) == 0x1906 || \
  2480. INTEL_DEVID(dev_priv) == 0x1913 || \
  2481. INTEL_DEVID(dev_priv) == 0x1916 || \
  2482. INTEL_DEVID(dev_priv) == 0x1921 || \
  2483. INTEL_DEVID(dev_priv) == 0x1926)
  2484. #define IS_SKL_ULX(dev_priv) (INTEL_DEVID(dev_priv) == 0x190E || \
  2485. INTEL_DEVID(dev_priv) == 0x1915 || \
  2486. INTEL_DEVID(dev_priv) == 0x191E)
  2487. #define IS_KBL_ULT(dev_priv) (INTEL_DEVID(dev_priv) == 0x5906 || \
  2488. INTEL_DEVID(dev_priv) == 0x5913 || \
  2489. INTEL_DEVID(dev_priv) == 0x5916 || \
  2490. INTEL_DEVID(dev_priv) == 0x5921 || \
  2491. INTEL_DEVID(dev_priv) == 0x5926)
  2492. #define IS_KBL_ULX(dev_priv) (INTEL_DEVID(dev_priv) == 0x590E || \
  2493. INTEL_DEVID(dev_priv) == 0x5915 || \
  2494. INTEL_DEVID(dev_priv) == 0x591E)
  2495. #define IS_SKL_GT2(dev_priv) (IS_SKYLAKE(dev_priv) && \
  2496. (INTEL_DEVID(dev_priv) & 0x00F0) == 0x0010)
  2497. #define IS_SKL_GT3(dev_priv) (IS_SKYLAKE(dev_priv) && \
  2498. (INTEL_DEVID(dev_priv) & 0x00F0) == 0x0020)
  2499. #define IS_SKL_GT4(dev_priv) (IS_SKYLAKE(dev_priv) && \
  2500. (INTEL_DEVID(dev_priv) & 0x00F0) == 0x0030)
  2501. #define IS_KBL_GT2(dev_priv) (IS_KABYLAKE(dev_priv) && \
  2502. (INTEL_DEVID(dev_priv) & 0x00F0) == 0x0010)
  2503. #define IS_KBL_GT3(dev_priv) (IS_KABYLAKE(dev_priv) && \
  2504. (INTEL_DEVID(dev_priv) & 0x00F0) == 0x0020)
  2505. #define IS_CFL_ULT(dev_priv) (IS_COFFEELAKE(dev_priv) && \
  2506. (INTEL_DEVID(dev_priv) & 0x00F0) == 0x00A0)
  2507. #define IS_ALPHA_SUPPORT(intel_info) ((intel_info)->is_alpha_support)
  2508. #define SKL_REVID_A0 0x0
  2509. #define SKL_REVID_B0 0x1
  2510. #define SKL_REVID_C0 0x2
  2511. #define SKL_REVID_D0 0x3
  2512. #define SKL_REVID_E0 0x4
  2513. #define SKL_REVID_F0 0x5
  2514. #define SKL_REVID_G0 0x6
  2515. #define SKL_REVID_H0 0x7
  2516. #define IS_SKL_REVID(p, since, until) (IS_SKYLAKE(p) && IS_REVID(p, since, until))
  2517. #define BXT_REVID_A0 0x0
  2518. #define BXT_REVID_A1 0x1
  2519. #define BXT_REVID_B0 0x3
  2520. #define BXT_REVID_B_LAST 0x8
  2521. #define BXT_REVID_C0 0x9
  2522. #define IS_BXT_REVID(dev_priv, since, until) \
  2523. (IS_BROXTON(dev_priv) && IS_REVID(dev_priv, since, until))
  2524. #define KBL_REVID_A0 0x0
  2525. #define KBL_REVID_B0 0x1
  2526. #define KBL_REVID_C0 0x2
  2527. #define KBL_REVID_D0 0x3
  2528. #define KBL_REVID_E0 0x4
  2529. #define IS_KBL_REVID(dev_priv, since, until) \
  2530. (IS_KABYLAKE(dev_priv) && IS_REVID(dev_priv, since, until))
  2531. #define GLK_REVID_A0 0x0
  2532. #define GLK_REVID_A1 0x1
  2533. #define IS_GLK_REVID(dev_priv, since, until) \
  2534. (IS_GEMINILAKE(dev_priv) && IS_REVID(dev_priv, since, until))
  2535. #define CNL_REVID_A0 0x0
  2536. #define CNL_REVID_B0 0x1
  2537. #define IS_CNL_REVID(p, since, until) \
  2538. (IS_CANNONLAKE(p) && IS_REVID(p, since, until))
  2539. /*
  2540. * The genX designation typically refers to the render engine, so render
  2541. * capability related checks should use IS_GEN, while display and other checks
  2542. * have their own (e.g. HAS_PCH_SPLIT for ILK+ display, IS_foo for particular
  2543. * chips, etc.).
  2544. */
  2545. #define IS_GEN2(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(1)))
  2546. #define IS_GEN3(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(2)))
  2547. #define IS_GEN4(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(3)))
  2548. #define IS_GEN5(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(4)))
  2549. #define IS_GEN6(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(5)))
  2550. #define IS_GEN7(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(6)))
  2551. #define IS_GEN8(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(7)))
  2552. #define IS_GEN9(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(8)))
  2553. #define IS_GEN10(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(9)))
  2554. #define IS_LP(dev_priv) (INTEL_INFO(dev_priv)->is_lp)
  2555. #define IS_GEN9_LP(dev_priv) (IS_GEN9(dev_priv) && IS_LP(dev_priv))
  2556. #define IS_GEN9_BC(dev_priv) (IS_GEN9(dev_priv) && !IS_LP(dev_priv))
  2557. #define ENGINE_MASK(id) BIT(id)
  2558. #define RENDER_RING ENGINE_MASK(RCS)
  2559. #define BSD_RING ENGINE_MASK(VCS)
  2560. #define BLT_RING ENGINE_MASK(BCS)
  2561. #define VEBOX_RING ENGINE_MASK(VECS)
  2562. #define BSD2_RING ENGINE_MASK(VCS2)
  2563. #define ALL_ENGINES (~0)
  2564. #define HAS_ENGINE(dev_priv, id) \
  2565. (!!((dev_priv)->info.ring_mask & ENGINE_MASK(id)))
  2566. #define HAS_BSD(dev_priv) HAS_ENGINE(dev_priv, VCS)
  2567. #define HAS_BSD2(dev_priv) HAS_ENGINE(dev_priv, VCS2)
  2568. #define HAS_BLT(dev_priv) HAS_ENGINE(dev_priv, BCS)
  2569. #define HAS_VEBOX(dev_priv) HAS_ENGINE(dev_priv, VECS)
  2570. #define HAS_LLC(dev_priv) ((dev_priv)->info.has_llc)
  2571. #define HAS_SNOOP(dev_priv) ((dev_priv)->info.has_snoop)
  2572. #define HAS_EDRAM(dev_priv) (!!((dev_priv)->edram_cap & EDRAM_ENABLED))
  2573. #define HAS_WT(dev_priv) ((IS_HASWELL(dev_priv) || \
  2574. IS_BROADWELL(dev_priv)) && HAS_EDRAM(dev_priv))
  2575. #define HWS_NEEDS_PHYSICAL(dev_priv) ((dev_priv)->info.hws_needs_physical)
  2576. #define HAS_LOGICAL_RING_CONTEXTS(dev_priv) \
  2577. ((dev_priv)->info.has_logical_ring_contexts)
  2578. #define USES_PPGTT(dev_priv) (i915.enable_ppgtt)
  2579. #define USES_FULL_PPGTT(dev_priv) (i915.enable_ppgtt >= 2)
  2580. #define USES_FULL_48BIT_PPGTT(dev_priv) (i915.enable_ppgtt == 3)
  2581. #define HAS_OVERLAY(dev_priv) ((dev_priv)->info.has_overlay)
  2582. #define OVERLAY_NEEDS_PHYSICAL(dev_priv) \
  2583. ((dev_priv)->info.overlay_needs_physical)
  2584. /* Early gen2 have a totally busted CS tlb and require pinned batches. */
  2585. #define HAS_BROKEN_CS_TLB(dev_priv) (IS_I830(dev_priv) || IS_I845G(dev_priv))
  2586. /* WaRsDisableCoarsePowerGating:skl,bxt */
  2587. #define NEEDS_WaRsDisableCoarsePowerGating(dev_priv) \
  2588. (IS_SKL_GT3(dev_priv) || IS_SKL_GT4(dev_priv))
  2589. /*
  2590. * dp aux and gmbus irq on gen4 seems to be able to generate legacy interrupts
  2591. * even when in MSI mode. This results in spurious interrupt warnings if the
  2592. * legacy irq no. is shared with another device. The kernel then disables that
  2593. * interrupt source and so prevents the other device from working properly.
  2594. */
  2595. #define HAS_AUX_IRQ(dev_priv) ((dev_priv)->info.gen >= 5)
  2596. #define HAS_GMBUS_IRQ(dev_priv) ((dev_priv)->info.has_gmbus_irq)
  2597. /* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte
  2598. * rows, which changed the alignment requirements and fence programming.
  2599. */
  2600. #define HAS_128_BYTE_Y_TILING(dev_priv) (!IS_GEN2(dev_priv) && \
  2601. !(IS_I915G(dev_priv) || \
  2602. IS_I915GM(dev_priv)))
  2603. #define SUPPORTS_TV(dev_priv) ((dev_priv)->info.supports_tv)
  2604. #define I915_HAS_HOTPLUG(dev_priv) ((dev_priv)->info.has_hotplug)
  2605. #define HAS_FW_BLC(dev_priv) (INTEL_GEN(dev_priv) > 2)
  2606. #define HAS_PIPE_CXSR(dev_priv) ((dev_priv)->info.has_pipe_cxsr)
  2607. #define HAS_FBC(dev_priv) ((dev_priv)->info.has_fbc)
  2608. #define HAS_CUR_FBC(dev_priv) (!HAS_GMCH_DISPLAY(dev_priv) && INTEL_INFO(dev_priv)->gen >= 7)
  2609. #define HAS_IPS(dev_priv) (IS_HSW_ULT(dev_priv) || IS_BROADWELL(dev_priv))
  2610. #define HAS_DP_MST(dev_priv) ((dev_priv)->info.has_dp_mst)
  2611. #define HAS_DDI(dev_priv) ((dev_priv)->info.has_ddi)
  2612. #define HAS_FPGA_DBG_UNCLAIMED(dev_priv) ((dev_priv)->info.has_fpga_dbg)
  2613. #define HAS_PSR(dev_priv) ((dev_priv)->info.has_psr)
  2614. #define HAS_RC6(dev_priv) ((dev_priv)->info.has_rc6)
  2615. #define HAS_RC6p(dev_priv) ((dev_priv)->info.has_rc6p)
  2616. #define HAS_CSR(dev_priv) ((dev_priv)->info.has_csr)
  2617. #define HAS_RUNTIME_PM(dev_priv) ((dev_priv)->info.has_runtime_pm)
  2618. #define HAS_64BIT_RELOC(dev_priv) ((dev_priv)->info.has_64bit_reloc)
  2619. /*
  2620. * For now, anything with a GuC requires uCode loading, and then supports
  2621. * command submission once loaded. But these are logically independent
  2622. * properties, so we have separate macros to test them.
  2623. */
  2624. #define HAS_GUC(dev_priv) ((dev_priv)->info.has_guc)
  2625. #define HAS_GUC_CT(dev_priv) ((dev_priv)->info.has_guc_ct)
  2626. #define HAS_GUC_UCODE(dev_priv) (HAS_GUC(dev_priv))
  2627. #define HAS_GUC_SCHED(dev_priv) (HAS_GUC(dev_priv))
  2628. #define HAS_HUC_UCODE(dev_priv) (HAS_GUC(dev_priv))
  2629. #define HAS_RESOURCE_STREAMER(dev_priv) ((dev_priv)->info.has_resource_streamer)
  2630. #define HAS_POOLED_EU(dev_priv) ((dev_priv)->info.has_pooled_eu)
  2631. #define INTEL_PCH_DEVICE_ID_MASK 0xff80
  2632. #define INTEL_PCH_IBX_DEVICE_ID_TYPE 0x3b00
  2633. #define INTEL_PCH_CPT_DEVICE_ID_TYPE 0x1c00
  2634. #define INTEL_PCH_PPT_DEVICE_ID_TYPE 0x1e00
  2635. #define INTEL_PCH_LPT_DEVICE_ID_TYPE 0x8c00
  2636. #define INTEL_PCH_LPT_LP_DEVICE_ID_TYPE 0x9c00
  2637. #define INTEL_PCH_WPT_DEVICE_ID_TYPE 0x8c80
  2638. #define INTEL_PCH_WPT_LP_DEVICE_ID_TYPE 0x9c80
  2639. #define INTEL_PCH_SPT_DEVICE_ID_TYPE 0xA100
  2640. #define INTEL_PCH_SPT_LP_DEVICE_ID_TYPE 0x9D00
  2641. #define INTEL_PCH_KBP_DEVICE_ID_TYPE 0xA280
  2642. #define INTEL_PCH_CNP_DEVICE_ID_TYPE 0xA300
  2643. #define INTEL_PCH_CNP_LP_DEVICE_ID_TYPE 0x9D80
  2644. #define INTEL_PCH_P2X_DEVICE_ID_TYPE 0x7100
  2645. #define INTEL_PCH_P3X_DEVICE_ID_TYPE 0x7000
  2646. #define INTEL_PCH_QEMU_DEVICE_ID_TYPE 0x2900 /* qemu q35 has 2918 */
  2647. #define INTEL_PCH_TYPE(dev_priv) ((dev_priv)->pch_type)
  2648. #define HAS_PCH_CNP(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_CNP)
  2649. #define HAS_PCH_CNP_LP(dev_priv) \
  2650. ((dev_priv)->pch_id == INTEL_PCH_CNP_LP_DEVICE_ID_TYPE)
  2651. #define HAS_PCH_KBP(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_KBP)
  2652. #define HAS_PCH_SPT(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_SPT)
  2653. #define HAS_PCH_LPT(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_LPT)
  2654. #define HAS_PCH_LPT_LP(dev_priv) \
  2655. ((dev_priv)->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE || \
  2656. (dev_priv)->pch_id == INTEL_PCH_WPT_LP_DEVICE_ID_TYPE)
  2657. #define HAS_PCH_LPT_H(dev_priv) \
  2658. ((dev_priv)->pch_id == INTEL_PCH_LPT_DEVICE_ID_TYPE || \
  2659. (dev_priv)->pch_id == INTEL_PCH_WPT_DEVICE_ID_TYPE)
  2660. #define HAS_PCH_CPT(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_CPT)
  2661. #define HAS_PCH_IBX(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_IBX)
  2662. #define HAS_PCH_NOP(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_NOP)
  2663. #define HAS_PCH_SPLIT(dev_priv) (INTEL_PCH_TYPE(dev_priv) != PCH_NONE)
  2664. #define HAS_GMCH_DISPLAY(dev_priv) ((dev_priv)->info.has_gmch_display)
  2665. #define HAS_LSPCON(dev_priv) (INTEL_GEN(dev_priv) >= 9)
  2666. /* DPF == dynamic parity feature */
  2667. #define HAS_L3_DPF(dev_priv) ((dev_priv)->info.has_l3_dpf)
  2668. #define NUM_L3_SLICES(dev_priv) (IS_HSW_GT3(dev_priv) ? \
  2669. 2 : HAS_L3_DPF(dev_priv))
  2670. #define GT_FREQUENCY_MULTIPLIER 50
  2671. #define GEN9_FREQ_SCALER 3
  2672. #include "i915_trace.h"
  2673. static inline bool intel_vtd_active(void)
  2674. {
  2675. #ifdef CONFIG_INTEL_IOMMU
  2676. if (intel_iommu_gfx_mapped)
  2677. return true;
  2678. #endif
  2679. return false;
  2680. }
  2681. static inline bool intel_scanout_needs_vtd_wa(struct drm_i915_private *dev_priv)
  2682. {
  2683. return INTEL_GEN(dev_priv) >= 6 && intel_vtd_active();
  2684. }
  2685. static inline bool
  2686. intel_ggtt_update_needs_vtd_wa(struct drm_i915_private *dev_priv)
  2687. {
  2688. return IS_BROXTON(dev_priv) && intel_vtd_active();
  2689. }
  2690. int intel_sanitize_enable_ppgtt(struct drm_i915_private *dev_priv,
  2691. int enable_ppgtt);
  2692. bool intel_sanitize_semaphores(struct drm_i915_private *dev_priv, int value);
  2693. /* i915_drv.c */
  2694. void __printf(3, 4)
  2695. __i915_printk(struct drm_i915_private *dev_priv, const char *level,
  2696. const char *fmt, ...);
  2697. #define i915_report_error(dev_priv, fmt, ...) \
  2698. __i915_printk(dev_priv, KERN_ERR, fmt, ##__VA_ARGS__)
  2699. #ifdef CONFIG_COMPAT
  2700. extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
  2701. unsigned long arg);
  2702. #else
  2703. #define i915_compat_ioctl NULL
  2704. #endif
  2705. extern const struct dev_pm_ops i915_pm_ops;
  2706. extern int i915_driver_load(struct pci_dev *pdev,
  2707. const struct pci_device_id *ent);
  2708. extern void i915_driver_unload(struct drm_device *dev);
  2709. extern int intel_gpu_reset(struct drm_i915_private *dev_priv, u32 engine_mask);
  2710. extern bool intel_has_gpu_reset(struct drm_i915_private *dev_priv);
  2711. #define I915_RESET_QUIET BIT(0)
  2712. extern void i915_reset(struct drm_i915_private *i915, unsigned int flags);
  2713. extern int i915_reset_engine(struct intel_engine_cs *engine,
  2714. unsigned int flags);
  2715. extern bool intel_has_reset_engine(struct drm_i915_private *dev_priv);
  2716. extern int intel_guc_reset(struct drm_i915_private *dev_priv);
  2717. extern void intel_engine_init_hangcheck(struct intel_engine_cs *engine);
  2718. extern void intel_hangcheck_init(struct drm_i915_private *dev_priv);
  2719. extern unsigned long i915_chipset_val(struct drm_i915_private *dev_priv);
  2720. extern unsigned long i915_mch_val(struct drm_i915_private *dev_priv);
  2721. extern unsigned long i915_gfx_val(struct drm_i915_private *dev_priv);
  2722. extern void i915_update_gfx_val(struct drm_i915_private *dev_priv);
  2723. int vlv_force_gfx_clock(struct drm_i915_private *dev_priv, bool on);
  2724. int intel_engines_init_mmio(struct drm_i915_private *dev_priv);
  2725. int intel_engines_init(struct drm_i915_private *dev_priv);
  2726. /* intel_hotplug.c */
  2727. void intel_hpd_irq_handler(struct drm_i915_private *dev_priv,
  2728. u32 pin_mask, u32 long_mask);
  2729. void intel_hpd_init(struct drm_i915_private *dev_priv);
  2730. void intel_hpd_init_work(struct drm_i915_private *dev_priv);
  2731. void intel_hpd_cancel_work(struct drm_i915_private *dev_priv);
  2732. enum port intel_hpd_pin_to_port(enum hpd_pin pin);
  2733. enum hpd_pin intel_hpd_pin(enum port port);
  2734. bool intel_hpd_disable(struct drm_i915_private *dev_priv, enum hpd_pin pin);
  2735. void intel_hpd_enable(struct drm_i915_private *dev_priv, enum hpd_pin pin);
  2736. /* i915_irq.c */
  2737. static inline void i915_queue_hangcheck(struct drm_i915_private *dev_priv)
  2738. {
  2739. unsigned long delay;
  2740. if (unlikely(!i915.enable_hangcheck))
  2741. return;
  2742. /* Don't continually defer the hangcheck so that it is always run at
  2743. * least once after work has been scheduled on any ring. Otherwise,
  2744. * we will ignore a hung ring if a second ring is kept busy.
  2745. */
  2746. delay = round_jiffies_up_relative(DRM_I915_HANGCHECK_JIFFIES);
  2747. queue_delayed_work(system_long_wq,
  2748. &dev_priv->gpu_error.hangcheck_work, delay);
  2749. }
  2750. __printf(3, 4)
  2751. void i915_handle_error(struct drm_i915_private *dev_priv,
  2752. u32 engine_mask,
  2753. const char *fmt, ...);
  2754. extern void intel_irq_init(struct drm_i915_private *dev_priv);
  2755. extern void intel_irq_fini(struct drm_i915_private *dev_priv);
  2756. int intel_irq_install(struct drm_i915_private *dev_priv);
  2757. void intel_irq_uninstall(struct drm_i915_private *dev_priv);
  2758. static inline bool intel_gvt_active(struct drm_i915_private *dev_priv)
  2759. {
  2760. return dev_priv->gvt;
  2761. }
  2762. static inline bool intel_vgpu_active(struct drm_i915_private *dev_priv)
  2763. {
  2764. return dev_priv->vgpu.active;
  2765. }
  2766. void
  2767. i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  2768. u32 status_mask);
  2769. void
  2770. i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  2771. u32 status_mask);
  2772. void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv);
  2773. void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv);
  2774. void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
  2775. uint32_t mask,
  2776. uint32_t bits);
  2777. void ilk_update_display_irq(struct drm_i915_private *dev_priv,
  2778. uint32_t interrupt_mask,
  2779. uint32_t enabled_irq_mask);
  2780. static inline void
  2781. ilk_enable_display_irq(struct drm_i915_private *dev_priv, uint32_t bits)
  2782. {
  2783. ilk_update_display_irq(dev_priv, bits, bits);
  2784. }
  2785. static inline void
  2786. ilk_disable_display_irq(struct drm_i915_private *dev_priv, uint32_t bits)
  2787. {
  2788. ilk_update_display_irq(dev_priv, bits, 0);
  2789. }
  2790. void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
  2791. enum pipe pipe,
  2792. uint32_t interrupt_mask,
  2793. uint32_t enabled_irq_mask);
  2794. static inline void bdw_enable_pipe_irq(struct drm_i915_private *dev_priv,
  2795. enum pipe pipe, uint32_t bits)
  2796. {
  2797. bdw_update_pipe_irq(dev_priv, pipe, bits, bits);
  2798. }
  2799. static inline void bdw_disable_pipe_irq(struct drm_i915_private *dev_priv,
  2800. enum pipe pipe, uint32_t bits)
  2801. {
  2802. bdw_update_pipe_irq(dev_priv, pipe, bits, 0);
  2803. }
  2804. void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
  2805. uint32_t interrupt_mask,
  2806. uint32_t enabled_irq_mask);
  2807. static inline void
  2808. ibx_enable_display_interrupt(struct drm_i915_private *dev_priv, uint32_t bits)
  2809. {
  2810. ibx_display_interrupt_update(dev_priv, bits, bits);
  2811. }
  2812. static inline void
  2813. ibx_disable_display_interrupt(struct drm_i915_private *dev_priv, uint32_t bits)
  2814. {
  2815. ibx_display_interrupt_update(dev_priv, bits, 0);
  2816. }
  2817. /* i915_gem.c */
  2818. int i915_gem_create_ioctl(struct drm_device *dev, void *data,
  2819. struct drm_file *file_priv);
  2820. int i915_gem_pread_ioctl(struct drm_device *dev, void *data,
  2821. struct drm_file *file_priv);
  2822. int i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  2823. struct drm_file *file_priv);
  2824. int i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
  2825. struct drm_file *file_priv);
  2826. int i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data,
  2827. struct drm_file *file_priv);
  2828. int i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  2829. struct drm_file *file_priv);
  2830. int i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
  2831. struct drm_file *file_priv);
  2832. int i915_gem_execbuffer(struct drm_device *dev, void *data,
  2833. struct drm_file *file_priv);
  2834. int i915_gem_execbuffer2(struct drm_device *dev, void *data,
  2835. struct drm_file *file_priv);
  2836. int i915_gem_busy_ioctl(struct drm_device *dev, void *data,
  2837. struct drm_file *file_priv);
  2838. int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data,
  2839. struct drm_file *file);
  2840. int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
  2841. struct drm_file *file);
  2842. int i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
  2843. struct drm_file *file_priv);
  2844. int i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
  2845. struct drm_file *file_priv);
  2846. int i915_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
  2847. struct drm_file *file_priv);
  2848. int i915_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
  2849. struct drm_file *file_priv);
  2850. int i915_gem_init_userptr(struct drm_i915_private *dev_priv);
  2851. void i915_gem_cleanup_userptr(struct drm_i915_private *dev_priv);
  2852. int i915_gem_userptr_ioctl(struct drm_device *dev, void *data,
  2853. struct drm_file *file);
  2854. int i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
  2855. struct drm_file *file_priv);
  2856. int i915_gem_wait_ioctl(struct drm_device *dev, void *data,
  2857. struct drm_file *file_priv);
  2858. void i915_gem_sanitize(struct drm_i915_private *i915);
  2859. int i915_gem_load_init(struct drm_i915_private *dev_priv);
  2860. void i915_gem_load_cleanup(struct drm_i915_private *dev_priv);
  2861. void i915_gem_load_init_fences(struct drm_i915_private *dev_priv);
  2862. int i915_gem_freeze(struct drm_i915_private *dev_priv);
  2863. int i915_gem_freeze_late(struct drm_i915_private *dev_priv);
  2864. void *i915_gem_object_alloc(struct drm_i915_private *dev_priv);
  2865. void i915_gem_object_free(struct drm_i915_gem_object *obj);
  2866. void i915_gem_object_init(struct drm_i915_gem_object *obj,
  2867. const struct drm_i915_gem_object_ops *ops);
  2868. struct drm_i915_gem_object *
  2869. i915_gem_object_create(struct drm_i915_private *dev_priv, u64 size);
  2870. struct drm_i915_gem_object *
  2871. i915_gem_object_create_from_data(struct drm_i915_private *dev_priv,
  2872. const void *data, size_t size);
  2873. void i915_gem_close_object(struct drm_gem_object *gem, struct drm_file *file);
  2874. void i915_gem_free_object(struct drm_gem_object *obj);
  2875. static inline void i915_gem_drain_freed_objects(struct drm_i915_private *i915)
  2876. {
  2877. /* A single pass should suffice to release all the freed objects (along
  2878. * most call paths) , but be a little more paranoid in that freeing
  2879. * the objects does take a little amount of time, during which the rcu
  2880. * callbacks could have added new objects into the freed list, and
  2881. * armed the work again.
  2882. */
  2883. do {
  2884. rcu_barrier();
  2885. } while (flush_work(&i915->mm.free_work));
  2886. }
  2887. static inline void i915_gem_drain_workqueue(struct drm_i915_private *i915)
  2888. {
  2889. /*
  2890. * Similar to objects above (see i915_gem_drain_freed-objects), in
  2891. * general we have workers that are armed by RCU and then rearm
  2892. * themselves in their callbacks. To be paranoid, we need to
  2893. * drain the workqueue a second time after waiting for the RCU
  2894. * grace period so that we catch work queued via RCU from the first
  2895. * pass. As neither drain_workqueue() nor flush_workqueue() report
  2896. * a result, we make an assumption that we only don't require more
  2897. * than 2 passes to catch all recursive RCU delayed work.
  2898. *
  2899. */
  2900. int pass = 2;
  2901. do {
  2902. rcu_barrier();
  2903. drain_workqueue(i915->wq);
  2904. } while (--pass);
  2905. }
  2906. struct i915_vma * __must_check
  2907. i915_gem_object_ggtt_pin(struct drm_i915_gem_object *obj,
  2908. const struct i915_ggtt_view *view,
  2909. u64 size,
  2910. u64 alignment,
  2911. u64 flags);
  2912. int i915_gem_object_unbind(struct drm_i915_gem_object *obj);
  2913. void i915_gem_release_mmap(struct drm_i915_gem_object *obj);
  2914. void i915_gem_runtime_suspend(struct drm_i915_private *dev_priv);
  2915. static inline int __sg_page_count(const struct scatterlist *sg)
  2916. {
  2917. return sg->length >> PAGE_SHIFT;
  2918. }
  2919. struct scatterlist *
  2920. i915_gem_object_get_sg(struct drm_i915_gem_object *obj,
  2921. unsigned int n, unsigned int *offset);
  2922. struct page *
  2923. i915_gem_object_get_page(struct drm_i915_gem_object *obj,
  2924. unsigned int n);
  2925. struct page *
  2926. i915_gem_object_get_dirty_page(struct drm_i915_gem_object *obj,
  2927. unsigned int n);
  2928. dma_addr_t
  2929. i915_gem_object_get_dma_address(struct drm_i915_gem_object *obj,
  2930. unsigned long n);
  2931. void __i915_gem_object_set_pages(struct drm_i915_gem_object *obj,
  2932. struct sg_table *pages);
  2933. int __i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
  2934. static inline int __must_check
  2935. i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
  2936. {
  2937. might_lock(&obj->mm.lock);
  2938. if (atomic_inc_not_zero(&obj->mm.pages_pin_count))
  2939. return 0;
  2940. return __i915_gem_object_get_pages(obj);
  2941. }
  2942. static inline void
  2943. __i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
  2944. {
  2945. GEM_BUG_ON(!obj->mm.pages);
  2946. atomic_inc(&obj->mm.pages_pin_count);
  2947. }
  2948. static inline bool
  2949. i915_gem_object_has_pinned_pages(struct drm_i915_gem_object *obj)
  2950. {
  2951. return atomic_read(&obj->mm.pages_pin_count);
  2952. }
  2953. static inline void
  2954. __i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj)
  2955. {
  2956. GEM_BUG_ON(!i915_gem_object_has_pinned_pages(obj));
  2957. GEM_BUG_ON(!obj->mm.pages);
  2958. atomic_dec(&obj->mm.pages_pin_count);
  2959. }
  2960. static inline void
  2961. i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj)
  2962. {
  2963. __i915_gem_object_unpin_pages(obj);
  2964. }
  2965. enum i915_mm_subclass { /* lockdep subclass for obj->mm.lock */
  2966. I915_MM_NORMAL = 0,
  2967. I915_MM_SHRINKER
  2968. };
  2969. void __i915_gem_object_put_pages(struct drm_i915_gem_object *obj,
  2970. enum i915_mm_subclass subclass);
  2971. void __i915_gem_object_invalidate(struct drm_i915_gem_object *obj);
  2972. enum i915_map_type {
  2973. I915_MAP_WB = 0,
  2974. I915_MAP_WC,
  2975. #define I915_MAP_OVERRIDE BIT(31)
  2976. I915_MAP_FORCE_WB = I915_MAP_WB | I915_MAP_OVERRIDE,
  2977. I915_MAP_FORCE_WC = I915_MAP_WC | I915_MAP_OVERRIDE,
  2978. };
  2979. /**
  2980. * i915_gem_object_pin_map - return a contiguous mapping of the entire object
  2981. * @obj: the object to map into kernel address space
  2982. * @type: the type of mapping, used to select pgprot_t
  2983. *
  2984. * Calls i915_gem_object_pin_pages() to prevent reaping of the object's
  2985. * pages and then returns a contiguous mapping of the backing storage into
  2986. * the kernel address space. Based on the @type of mapping, the PTE will be
  2987. * set to either WriteBack or WriteCombine (via pgprot_t).
  2988. *
  2989. * The caller is responsible for calling i915_gem_object_unpin_map() when the
  2990. * mapping is no longer required.
  2991. *
  2992. * Returns the pointer through which to access the mapped object, or an
  2993. * ERR_PTR() on error.
  2994. */
  2995. void *__must_check i915_gem_object_pin_map(struct drm_i915_gem_object *obj,
  2996. enum i915_map_type type);
  2997. /**
  2998. * i915_gem_object_unpin_map - releases an earlier mapping
  2999. * @obj: the object to unmap
  3000. *
  3001. * After pinning the object and mapping its pages, once you are finished
  3002. * with your access, call i915_gem_object_unpin_map() to release the pin
  3003. * upon the mapping. Once the pin count reaches zero, that mapping may be
  3004. * removed.
  3005. */
  3006. static inline void i915_gem_object_unpin_map(struct drm_i915_gem_object *obj)
  3007. {
  3008. i915_gem_object_unpin_pages(obj);
  3009. }
  3010. int i915_gem_obj_prepare_shmem_read(struct drm_i915_gem_object *obj,
  3011. unsigned int *needs_clflush);
  3012. int i915_gem_obj_prepare_shmem_write(struct drm_i915_gem_object *obj,
  3013. unsigned int *needs_clflush);
  3014. #define CLFLUSH_BEFORE BIT(0)
  3015. #define CLFLUSH_AFTER BIT(1)
  3016. #define CLFLUSH_FLAGS (CLFLUSH_BEFORE | CLFLUSH_AFTER)
  3017. static inline void
  3018. i915_gem_obj_finish_shmem_access(struct drm_i915_gem_object *obj)
  3019. {
  3020. i915_gem_object_unpin_pages(obj);
  3021. }
  3022. int __must_check i915_mutex_lock_interruptible(struct drm_device *dev);
  3023. void i915_vma_move_to_active(struct i915_vma *vma,
  3024. struct drm_i915_gem_request *req,
  3025. unsigned int flags);
  3026. int i915_gem_dumb_create(struct drm_file *file_priv,
  3027. struct drm_device *dev,
  3028. struct drm_mode_create_dumb *args);
  3029. int i915_gem_mmap_gtt(struct drm_file *file_priv, struct drm_device *dev,
  3030. uint32_t handle, uint64_t *offset);
  3031. int i915_gem_mmap_gtt_version(void);
  3032. void i915_gem_track_fb(struct drm_i915_gem_object *old,
  3033. struct drm_i915_gem_object *new,
  3034. unsigned frontbuffer_bits);
  3035. int __must_check i915_gem_set_global_seqno(struct drm_device *dev, u32 seqno);
  3036. struct drm_i915_gem_request *
  3037. i915_gem_find_active_request(struct intel_engine_cs *engine);
  3038. void i915_gem_retire_requests(struct drm_i915_private *dev_priv);
  3039. static inline bool i915_reset_backoff(struct i915_gpu_error *error)
  3040. {
  3041. return unlikely(test_bit(I915_RESET_BACKOFF, &error->flags));
  3042. }
  3043. static inline bool i915_reset_handoff(struct i915_gpu_error *error)
  3044. {
  3045. return unlikely(test_bit(I915_RESET_HANDOFF, &error->flags));
  3046. }
  3047. static inline bool i915_terminally_wedged(struct i915_gpu_error *error)
  3048. {
  3049. return unlikely(test_bit(I915_WEDGED, &error->flags));
  3050. }
  3051. static inline bool i915_reset_backoff_or_wedged(struct i915_gpu_error *error)
  3052. {
  3053. return i915_reset_backoff(error) | i915_terminally_wedged(error);
  3054. }
  3055. static inline u32 i915_reset_count(struct i915_gpu_error *error)
  3056. {
  3057. return READ_ONCE(error->reset_count);
  3058. }
  3059. static inline u32 i915_reset_engine_count(struct i915_gpu_error *error,
  3060. struct intel_engine_cs *engine)
  3061. {
  3062. return READ_ONCE(error->reset_engine_count[engine->id]);
  3063. }
  3064. struct drm_i915_gem_request *
  3065. i915_gem_reset_prepare_engine(struct intel_engine_cs *engine);
  3066. int i915_gem_reset_prepare(struct drm_i915_private *dev_priv);
  3067. void i915_gem_reset(struct drm_i915_private *dev_priv);
  3068. void i915_gem_reset_finish_engine(struct intel_engine_cs *engine);
  3069. void i915_gem_reset_finish(struct drm_i915_private *dev_priv);
  3070. void i915_gem_set_wedged(struct drm_i915_private *dev_priv);
  3071. bool i915_gem_unset_wedged(struct drm_i915_private *dev_priv);
  3072. void i915_gem_reset_engine(struct intel_engine_cs *engine,
  3073. struct drm_i915_gem_request *request);
  3074. void i915_gem_init_mmio(struct drm_i915_private *i915);
  3075. int __must_check i915_gem_init(struct drm_i915_private *dev_priv);
  3076. int __must_check i915_gem_init_hw(struct drm_i915_private *dev_priv);
  3077. void i915_gem_init_swizzling(struct drm_i915_private *dev_priv);
  3078. void i915_gem_cleanup_engines(struct drm_i915_private *dev_priv);
  3079. int i915_gem_wait_for_idle(struct drm_i915_private *dev_priv,
  3080. unsigned int flags);
  3081. int __must_check i915_gem_suspend(struct drm_i915_private *dev_priv);
  3082. void i915_gem_resume(struct drm_i915_private *dev_priv);
  3083. int i915_gem_fault(struct vm_fault *vmf);
  3084. int i915_gem_object_wait(struct drm_i915_gem_object *obj,
  3085. unsigned int flags,
  3086. long timeout,
  3087. struct intel_rps_client *rps);
  3088. int i915_gem_object_wait_priority(struct drm_i915_gem_object *obj,
  3089. unsigned int flags,
  3090. int priority);
  3091. #define I915_PRIORITY_DISPLAY I915_PRIORITY_MAX
  3092. int __must_check
  3093. i915_gem_object_set_to_wc_domain(struct drm_i915_gem_object *obj, bool write);
  3094. int __must_check
  3095. i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write);
  3096. int __must_check
  3097. i915_gem_object_set_to_cpu_domain(struct drm_i915_gem_object *obj, bool write);
  3098. struct i915_vma * __must_check
  3099. i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
  3100. u32 alignment,
  3101. const struct i915_ggtt_view *view);
  3102. void i915_gem_object_unpin_from_display_plane(struct i915_vma *vma);
  3103. int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj,
  3104. int align);
  3105. int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file);
  3106. void i915_gem_release(struct drm_device *dev, struct drm_file *file);
  3107. int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
  3108. enum i915_cache_level cache_level);
  3109. struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
  3110. struct dma_buf *dma_buf);
  3111. struct dma_buf *i915_gem_prime_export(struct drm_device *dev,
  3112. struct drm_gem_object *gem_obj, int flags);
  3113. static inline struct i915_hw_ppgtt *
  3114. i915_vm_to_ppgtt(struct i915_address_space *vm)
  3115. {
  3116. return container_of(vm, struct i915_hw_ppgtt, base);
  3117. }
  3118. /* i915_gem_fence_reg.c */
  3119. int __must_check i915_vma_get_fence(struct i915_vma *vma);
  3120. int __must_check i915_vma_put_fence(struct i915_vma *vma);
  3121. void i915_gem_revoke_fences(struct drm_i915_private *dev_priv);
  3122. void i915_gem_restore_fences(struct drm_i915_private *dev_priv);
  3123. void i915_gem_detect_bit_6_swizzle(struct drm_i915_private *dev_priv);
  3124. void i915_gem_object_do_bit_17_swizzle(struct drm_i915_gem_object *obj,
  3125. struct sg_table *pages);
  3126. void i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj,
  3127. struct sg_table *pages);
  3128. static inline struct i915_gem_context *
  3129. __i915_gem_context_lookup_rcu(struct drm_i915_file_private *file_priv, u32 id)
  3130. {
  3131. return idr_find(&file_priv->context_idr, id);
  3132. }
  3133. static inline struct i915_gem_context *
  3134. i915_gem_context_lookup(struct drm_i915_file_private *file_priv, u32 id)
  3135. {
  3136. struct i915_gem_context *ctx;
  3137. rcu_read_lock();
  3138. ctx = __i915_gem_context_lookup_rcu(file_priv, id);
  3139. if (ctx && !kref_get_unless_zero(&ctx->ref))
  3140. ctx = NULL;
  3141. rcu_read_unlock();
  3142. return ctx;
  3143. }
  3144. static inline struct intel_timeline *
  3145. i915_gem_context_lookup_timeline(struct i915_gem_context *ctx,
  3146. struct intel_engine_cs *engine)
  3147. {
  3148. struct i915_address_space *vm;
  3149. vm = ctx->ppgtt ? &ctx->ppgtt->base : &ctx->i915->ggtt.base;
  3150. return &vm->timeline.engine[engine->id];
  3151. }
  3152. int i915_perf_open_ioctl(struct drm_device *dev, void *data,
  3153. struct drm_file *file);
  3154. int i915_perf_add_config_ioctl(struct drm_device *dev, void *data,
  3155. struct drm_file *file);
  3156. int i915_perf_remove_config_ioctl(struct drm_device *dev, void *data,
  3157. struct drm_file *file);
  3158. void i915_oa_init_reg_state(struct intel_engine_cs *engine,
  3159. struct i915_gem_context *ctx,
  3160. uint32_t *reg_state);
  3161. /* i915_gem_evict.c */
  3162. int __must_check i915_gem_evict_something(struct i915_address_space *vm,
  3163. u64 min_size, u64 alignment,
  3164. unsigned cache_level,
  3165. u64 start, u64 end,
  3166. unsigned flags);
  3167. int __must_check i915_gem_evict_for_node(struct i915_address_space *vm,
  3168. struct drm_mm_node *node,
  3169. unsigned int flags);
  3170. int i915_gem_evict_vm(struct i915_address_space *vm);
  3171. /* belongs in i915_gem_gtt.h */
  3172. static inline void i915_gem_chipset_flush(struct drm_i915_private *dev_priv)
  3173. {
  3174. wmb();
  3175. if (INTEL_GEN(dev_priv) < 6)
  3176. intel_gtt_chipset_flush();
  3177. }
  3178. /* i915_gem_stolen.c */
  3179. int i915_gem_stolen_insert_node(struct drm_i915_private *dev_priv,
  3180. struct drm_mm_node *node, u64 size,
  3181. unsigned alignment);
  3182. int i915_gem_stolen_insert_node_in_range(struct drm_i915_private *dev_priv,
  3183. struct drm_mm_node *node, u64 size,
  3184. unsigned alignment, u64 start,
  3185. u64 end);
  3186. void i915_gem_stolen_remove_node(struct drm_i915_private *dev_priv,
  3187. struct drm_mm_node *node);
  3188. int i915_gem_init_stolen(struct drm_i915_private *dev_priv);
  3189. void i915_gem_cleanup_stolen(struct drm_device *dev);
  3190. struct drm_i915_gem_object *
  3191. i915_gem_object_create_stolen(struct drm_i915_private *dev_priv, u32 size);
  3192. struct drm_i915_gem_object *
  3193. i915_gem_object_create_stolen_for_preallocated(struct drm_i915_private *dev_priv,
  3194. u32 stolen_offset,
  3195. u32 gtt_offset,
  3196. u32 size);
  3197. /* i915_gem_internal.c */
  3198. struct drm_i915_gem_object *
  3199. i915_gem_object_create_internal(struct drm_i915_private *dev_priv,
  3200. phys_addr_t size);
  3201. /* i915_gem_shrinker.c */
  3202. unsigned long i915_gem_shrink(struct drm_i915_private *dev_priv,
  3203. unsigned long target,
  3204. unsigned long *nr_scanned,
  3205. unsigned flags);
  3206. #define I915_SHRINK_PURGEABLE 0x1
  3207. #define I915_SHRINK_UNBOUND 0x2
  3208. #define I915_SHRINK_BOUND 0x4
  3209. #define I915_SHRINK_ACTIVE 0x8
  3210. #define I915_SHRINK_VMAPS 0x10
  3211. unsigned long i915_gem_shrink_all(struct drm_i915_private *dev_priv);
  3212. void i915_gem_shrinker_init(struct drm_i915_private *dev_priv);
  3213. void i915_gem_shrinker_cleanup(struct drm_i915_private *dev_priv);
  3214. /* i915_gem_tiling.c */
  3215. static inline bool i915_gem_object_needs_bit17_swizzle(struct drm_i915_gem_object *obj)
  3216. {
  3217. struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
  3218. return dev_priv->mm.bit_6_swizzle_x == I915_BIT_6_SWIZZLE_9_10_17 &&
  3219. i915_gem_object_is_tiled(obj);
  3220. }
  3221. u32 i915_gem_fence_size(struct drm_i915_private *dev_priv, u32 size,
  3222. unsigned int tiling, unsigned int stride);
  3223. u32 i915_gem_fence_alignment(struct drm_i915_private *dev_priv, u32 size,
  3224. unsigned int tiling, unsigned int stride);
  3225. /* i915_debugfs.c */
  3226. #ifdef CONFIG_DEBUG_FS
  3227. int i915_debugfs_register(struct drm_i915_private *dev_priv);
  3228. int i915_debugfs_connector_add(struct drm_connector *connector);
  3229. void intel_display_crc_init(struct drm_i915_private *dev_priv);
  3230. #else
  3231. static inline int i915_debugfs_register(struct drm_i915_private *dev_priv) {return 0;}
  3232. static inline int i915_debugfs_connector_add(struct drm_connector *connector)
  3233. { return 0; }
  3234. static inline void intel_display_crc_init(struct drm_i915_private *dev_priv) {}
  3235. #endif
  3236. /* i915_gpu_error.c */
  3237. #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
  3238. __printf(2, 3)
  3239. void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...);
  3240. int i915_error_state_to_str(struct drm_i915_error_state_buf *estr,
  3241. const struct i915_gpu_state *gpu);
  3242. int i915_error_state_buf_init(struct drm_i915_error_state_buf *eb,
  3243. struct drm_i915_private *i915,
  3244. size_t count, loff_t pos);
  3245. static inline void i915_error_state_buf_release(
  3246. struct drm_i915_error_state_buf *eb)
  3247. {
  3248. kfree(eb->buf);
  3249. }
  3250. struct i915_gpu_state *i915_capture_gpu_state(struct drm_i915_private *i915);
  3251. void i915_capture_error_state(struct drm_i915_private *dev_priv,
  3252. u32 engine_mask,
  3253. const char *error_msg);
  3254. static inline struct i915_gpu_state *
  3255. i915_gpu_state_get(struct i915_gpu_state *gpu)
  3256. {
  3257. kref_get(&gpu->ref);
  3258. return gpu;
  3259. }
  3260. void __i915_gpu_state_free(struct kref *kref);
  3261. static inline void i915_gpu_state_put(struct i915_gpu_state *gpu)
  3262. {
  3263. if (gpu)
  3264. kref_put(&gpu->ref, __i915_gpu_state_free);
  3265. }
  3266. struct i915_gpu_state *i915_first_error_state(struct drm_i915_private *i915);
  3267. void i915_reset_error_state(struct drm_i915_private *i915);
  3268. #else
  3269. static inline void i915_capture_error_state(struct drm_i915_private *dev_priv,
  3270. u32 engine_mask,
  3271. const char *error_msg)
  3272. {
  3273. }
  3274. static inline struct i915_gpu_state *
  3275. i915_first_error_state(struct drm_i915_private *i915)
  3276. {
  3277. return NULL;
  3278. }
  3279. static inline void i915_reset_error_state(struct drm_i915_private *i915)
  3280. {
  3281. }
  3282. #endif
  3283. const char *i915_cache_level_str(struct drm_i915_private *i915, int type);
  3284. /* i915_cmd_parser.c */
  3285. int i915_cmd_parser_get_version(struct drm_i915_private *dev_priv);
  3286. void intel_engine_init_cmd_parser(struct intel_engine_cs *engine);
  3287. void intel_engine_cleanup_cmd_parser(struct intel_engine_cs *engine);
  3288. int intel_engine_cmd_parser(struct intel_engine_cs *engine,
  3289. struct drm_i915_gem_object *batch_obj,
  3290. struct drm_i915_gem_object *shadow_batch_obj,
  3291. u32 batch_start_offset,
  3292. u32 batch_len,
  3293. bool is_master);
  3294. /* i915_perf.c */
  3295. extern void i915_perf_init(struct drm_i915_private *dev_priv);
  3296. extern void i915_perf_fini(struct drm_i915_private *dev_priv);
  3297. extern void i915_perf_register(struct drm_i915_private *dev_priv);
  3298. extern void i915_perf_unregister(struct drm_i915_private *dev_priv);
  3299. /* i915_suspend.c */
  3300. extern int i915_save_state(struct drm_i915_private *dev_priv);
  3301. extern int i915_restore_state(struct drm_i915_private *dev_priv);
  3302. /* i915_sysfs.c */
  3303. void i915_setup_sysfs(struct drm_i915_private *dev_priv);
  3304. void i915_teardown_sysfs(struct drm_i915_private *dev_priv);
  3305. /* intel_lpe_audio.c */
  3306. int intel_lpe_audio_init(struct drm_i915_private *dev_priv);
  3307. void intel_lpe_audio_teardown(struct drm_i915_private *dev_priv);
  3308. void intel_lpe_audio_irq_handler(struct drm_i915_private *dev_priv);
  3309. void intel_lpe_audio_notify(struct drm_i915_private *dev_priv,
  3310. enum pipe pipe, enum port port,
  3311. const void *eld, int ls_clock, bool dp_output);
  3312. /* intel_i2c.c */
  3313. extern int intel_setup_gmbus(struct drm_i915_private *dev_priv);
  3314. extern void intel_teardown_gmbus(struct drm_i915_private *dev_priv);
  3315. extern bool intel_gmbus_is_valid_pin(struct drm_i915_private *dev_priv,
  3316. unsigned int pin);
  3317. extern struct i2c_adapter *
  3318. intel_gmbus_get_adapter(struct drm_i915_private *dev_priv, unsigned int pin);
  3319. extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
  3320. extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
  3321. static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
  3322. {
  3323. return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
  3324. }
  3325. extern void intel_i2c_reset(struct drm_i915_private *dev_priv);
  3326. /* intel_bios.c */
  3327. void intel_bios_init(struct drm_i915_private *dev_priv);
  3328. bool intel_bios_is_valid_vbt(const void *buf, size_t size);
  3329. bool intel_bios_is_tv_present(struct drm_i915_private *dev_priv);
  3330. bool intel_bios_is_lvds_present(struct drm_i915_private *dev_priv, u8 *i2c_pin);
  3331. bool intel_bios_is_port_present(struct drm_i915_private *dev_priv, enum port port);
  3332. bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port);
  3333. bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port);
  3334. bool intel_bios_is_dsi_present(struct drm_i915_private *dev_priv, enum port *port);
  3335. bool intel_bios_is_port_hpd_inverted(struct drm_i915_private *dev_priv,
  3336. enum port port);
  3337. bool intel_bios_is_lspcon_present(struct drm_i915_private *dev_priv,
  3338. enum port port);
  3339. /* intel_opregion.c */
  3340. #ifdef CONFIG_ACPI
  3341. extern int intel_opregion_setup(struct drm_i915_private *dev_priv);
  3342. extern void intel_opregion_register(struct drm_i915_private *dev_priv);
  3343. extern void intel_opregion_unregister(struct drm_i915_private *dev_priv);
  3344. extern void intel_opregion_asle_intr(struct drm_i915_private *dev_priv);
  3345. extern int intel_opregion_notify_encoder(struct intel_encoder *intel_encoder,
  3346. bool enable);
  3347. extern int intel_opregion_notify_adapter(struct drm_i915_private *dev_priv,
  3348. pci_power_t state);
  3349. extern int intel_opregion_get_panel_type(struct drm_i915_private *dev_priv);
  3350. #else
  3351. static inline int intel_opregion_setup(struct drm_i915_private *dev) { return 0; }
  3352. static inline void intel_opregion_register(struct drm_i915_private *dev_priv) { }
  3353. static inline void intel_opregion_unregister(struct drm_i915_private *dev_priv) { }
  3354. static inline void intel_opregion_asle_intr(struct drm_i915_private *dev_priv)
  3355. {
  3356. }
  3357. static inline int
  3358. intel_opregion_notify_encoder(struct intel_encoder *intel_encoder, bool enable)
  3359. {
  3360. return 0;
  3361. }
  3362. static inline int
  3363. intel_opregion_notify_adapter(struct drm_i915_private *dev, pci_power_t state)
  3364. {
  3365. return 0;
  3366. }
  3367. static inline int intel_opregion_get_panel_type(struct drm_i915_private *dev)
  3368. {
  3369. return -ENODEV;
  3370. }
  3371. #endif
  3372. /* intel_acpi.c */
  3373. #ifdef CONFIG_ACPI
  3374. extern void intel_register_dsm_handler(void);
  3375. extern void intel_unregister_dsm_handler(void);
  3376. #else
  3377. static inline void intel_register_dsm_handler(void) { return; }
  3378. static inline void intel_unregister_dsm_handler(void) { return; }
  3379. #endif /* CONFIG_ACPI */
  3380. /* intel_device_info.c */
  3381. static inline struct intel_device_info *
  3382. mkwrite_device_info(struct drm_i915_private *dev_priv)
  3383. {
  3384. return (struct intel_device_info *)&dev_priv->info;
  3385. }
  3386. const char *intel_platform_name(enum intel_platform platform);
  3387. void intel_device_info_runtime_init(struct drm_i915_private *dev_priv);
  3388. void intel_device_info_dump(struct drm_i915_private *dev_priv);
  3389. /* modesetting */
  3390. extern void intel_modeset_init_hw(struct drm_device *dev);
  3391. extern int intel_modeset_init(struct drm_device *dev);
  3392. extern void intel_modeset_gem_init(struct drm_device *dev);
  3393. extern void intel_modeset_cleanup(struct drm_device *dev);
  3394. extern int intel_connector_register(struct drm_connector *);
  3395. extern void intel_connector_unregister(struct drm_connector *);
  3396. extern int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv,
  3397. bool state);
  3398. extern void intel_display_resume(struct drm_device *dev);
  3399. extern void i915_redisable_vga(struct drm_i915_private *dev_priv);
  3400. extern void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv);
  3401. extern bool ironlake_set_drps(struct drm_i915_private *dev_priv, u8 val);
  3402. extern void intel_init_pch_refclk(struct drm_i915_private *dev_priv);
  3403. extern int intel_set_rps(struct drm_i915_private *dev_priv, u8 val);
  3404. extern bool intel_set_memory_cxsr(struct drm_i915_private *dev_priv,
  3405. bool enable);
  3406. int i915_reg_read_ioctl(struct drm_device *dev, void *data,
  3407. struct drm_file *file);
  3408. /* overlay */
  3409. extern struct intel_overlay_error_state *
  3410. intel_overlay_capture_error_state(struct drm_i915_private *dev_priv);
  3411. extern void intel_overlay_print_error_state(struct drm_i915_error_state_buf *e,
  3412. struct intel_overlay_error_state *error);
  3413. extern struct intel_display_error_state *
  3414. intel_display_capture_error_state(struct drm_i915_private *dev_priv);
  3415. extern void intel_display_print_error_state(struct drm_i915_error_state_buf *e,
  3416. struct intel_display_error_state *error);
  3417. int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u32 mbox, u32 *val);
  3418. int sandybridge_pcode_write(struct drm_i915_private *dev_priv, u32 mbox, u32 val);
  3419. int skl_pcode_request(struct drm_i915_private *dev_priv, u32 mbox, u32 request,
  3420. u32 reply_mask, u32 reply, int timeout_base_ms);
  3421. /* intel_sideband.c */
  3422. u32 vlv_punit_read(struct drm_i915_private *dev_priv, u32 addr);
  3423. int vlv_punit_write(struct drm_i915_private *dev_priv, u32 addr, u32 val);
  3424. u32 vlv_nc_read(struct drm_i915_private *dev_priv, u8 addr);
  3425. u32 vlv_iosf_sb_read(struct drm_i915_private *dev_priv, u8 port, u32 reg);
  3426. void vlv_iosf_sb_write(struct drm_i915_private *dev_priv, u8 port, u32 reg, u32 val);
  3427. u32 vlv_cck_read(struct drm_i915_private *dev_priv, u32 reg);
  3428. void vlv_cck_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  3429. u32 vlv_ccu_read(struct drm_i915_private *dev_priv, u32 reg);
  3430. void vlv_ccu_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  3431. u32 vlv_bunit_read(struct drm_i915_private *dev_priv, u32 reg);
  3432. void vlv_bunit_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  3433. u32 vlv_dpio_read(struct drm_i915_private *dev_priv, enum pipe pipe, int reg);
  3434. void vlv_dpio_write(struct drm_i915_private *dev_priv, enum pipe pipe, int reg, u32 val);
  3435. u32 intel_sbi_read(struct drm_i915_private *dev_priv, u16 reg,
  3436. enum intel_sbi_destination destination);
  3437. void intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
  3438. enum intel_sbi_destination destination);
  3439. u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
  3440. void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  3441. /* intel_dpio_phy.c */
  3442. void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum port port,
  3443. enum dpio_phy *phy, enum dpio_channel *ch);
  3444. void bxt_ddi_phy_set_signal_level(struct drm_i915_private *dev_priv,
  3445. enum port port, u32 margin, u32 scale,
  3446. u32 enable, u32 deemphasis);
  3447. void bxt_ddi_phy_init(struct drm_i915_private *dev_priv, enum dpio_phy phy);
  3448. void bxt_ddi_phy_uninit(struct drm_i915_private *dev_priv, enum dpio_phy phy);
  3449. bool bxt_ddi_phy_is_enabled(struct drm_i915_private *dev_priv,
  3450. enum dpio_phy phy);
  3451. bool bxt_ddi_phy_verify_state(struct drm_i915_private *dev_priv,
  3452. enum dpio_phy phy);
  3453. uint8_t bxt_ddi_phy_calc_lane_lat_optim_mask(struct intel_encoder *encoder,
  3454. uint8_t lane_count);
  3455. void bxt_ddi_phy_set_lane_optim_mask(struct intel_encoder *encoder,
  3456. uint8_t lane_lat_optim_mask);
  3457. uint8_t bxt_ddi_phy_get_lane_lat_optim_mask(struct intel_encoder *encoder);
  3458. void chv_set_phy_signal_level(struct intel_encoder *encoder,
  3459. u32 deemph_reg_value, u32 margin_reg_value,
  3460. bool uniq_trans_scale);
  3461. void chv_data_lane_soft_reset(struct intel_encoder *encoder,
  3462. bool reset);
  3463. void chv_phy_pre_pll_enable(struct intel_encoder *encoder);
  3464. void chv_phy_pre_encoder_enable(struct intel_encoder *encoder);
  3465. void chv_phy_release_cl2_override(struct intel_encoder *encoder);
  3466. void chv_phy_post_pll_disable(struct intel_encoder *encoder);
  3467. void vlv_set_phy_signal_level(struct intel_encoder *encoder,
  3468. u32 demph_reg_value, u32 preemph_reg_value,
  3469. u32 uniqtranscale_reg_value, u32 tx3_demph);
  3470. void vlv_phy_pre_pll_enable(struct intel_encoder *encoder);
  3471. void vlv_phy_pre_encoder_enable(struct intel_encoder *encoder);
  3472. void vlv_phy_reset_lanes(struct intel_encoder *encoder);
  3473. int intel_gpu_freq(struct drm_i915_private *dev_priv, int val);
  3474. int intel_freq_opcode(struct drm_i915_private *dev_priv, int val);
  3475. u64 intel_rc6_residency_us(struct drm_i915_private *dev_priv,
  3476. const i915_reg_t reg);
  3477. #define I915_READ8(reg) dev_priv->uncore.funcs.mmio_readb(dev_priv, (reg), true)
  3478. #define I915_WRITE8(reg, val) dev_priv->uncore.funcs.mmio_writeb(dev_priv, (reg), (val), true)
  3479. #define I915_READ16(reg) dev_priv->uncore.funcs.mmio_readw(dev_priv, (reg), true)
  3480. #define I915_WRITE16(reg, val) dev_priv->uncore.funcs.mmio_writew(dev_priv, (reg), (val), true)
  3481. #define I915_READ16_NOTRACE(reg) dev_priv->uncore.funcs.mmio_readw(dev_priv, (reg), false)
  3482. #define I915_WRITE16_NOTRACE(reg, val) dev_priv->uncore.funcs.mmio_writew(dev_priv, (reg), (val), false)
  3483. #define I915_READ(reg) dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), true)
  3484. #define I915_WRITE(reg, val) dev_priv->uncore.funcs.mmio_writel(dev_priv, (reg), (val), true)
  3485. #define I915_READ_NOTRACE(reg) dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), false)
  3486. #define I915_WRITE_NOTRACE(reg, val) dev_priv->uncore.funcs.mmio_writel(dev_priv, (reg), (val), false)
  3487. /* Be very careful with read/write 64-bit values. On 32-bit machines, they
  3488. * will be implemented using 2 32-bit writes in an arbitrary order with
  3489. * an arbitrary delay between them. This can cause the hardware to
  3490. * act upon the intermediate value, possibly leading to corruption and
  3491. * machine death. For this reason we do not support I915_WRITE64, or
  3492. * dev_priv->uncore.funcs.mmio_writeq.
  3493. *
  3494. * When reading a 64-bit value as two 32-bit values, the delay may cause
  3495. * the two reads to mismatch, e.g. a timestamp overflowing. Also note that
  3496. * occasionally a 64-bit register does not actualy support a full readq
  3497. * and must be read using two 32-bit reads.
  3498. *
  3499. * You have been warned.
  3500. */
  3501. #define I915_READ64(reg) dev_priv->uncore.funcs.mmio_readq(dev_priv, (reg), true)
  3502. #define I915_READ64_2x32(lower_reg, upper_reg) ({ \
  3503. u32 upper, lower, old_upper, loop = 0; \
  3504. upper = I915_READ(upper_reg); \
  3505. do { \
  3506. old_upper = upper; \
  3507. lower = I915_READ(lower_reg); \
  3508. upper = I915_READ(upper_reg); \
  3509. } while (upper != old_upper && loop++ < 2); \
  3510. (u64)upper << 32 | lower; })
  3511. #define POSTING_READ(reg) (void)I915_READ_NOTRACE(reg)
  3512. #define POSTING_READ16(reg) (void)I915_READ16_NOTRACE(reg)
  3513. #define __raw_read(x, s) \
  3514. static inline uint##x##_t __raw_i915_read##x(const struct drm_i915_private *dev_priv, \
  3515. i915_reg_t reg) \
  3516. { \
  3517. return read##s(dev_priv->regs + i915_mmio_reg_offset(reg)); \
  3518. }
  3519. #define __raw_write(x, s) \
  3520. static inline void __raw_i915_write##x(const struct drm_i915_private *dev_priv, \
  3521. i915_reg_t reg, uint##x##_t val) \
  3522. { \
  3523. write##s(val, dev_priv->regs + i915_mmio_reg_offset(reg)); \
  3524. }
  3525. __raw_read(8, b)
  3526. __raw_read(16, w)
  3527. __raw_read(32, l)
  3528. __raw_read(64, q)
  3529. __raw_write(8, b)
  3530. __raw_write(16, w)
  3531. __raw_write(32, l)
  3532. __raw_write(64, q)
  3533. #undef __raw_read
  3534. #undef __raw_write
  3535. /* These are untraced mmio-accessors that are only valid to be used inside
  3536. * critical sections, such as inside IRQ handlers, where forcewake is explicitly
  3537. * controlled.
  3538. *
  3539. * Think twice, and think again, before using these.
  3540. *
  3541. * As an example, these accessors can possibly be used between:
  3542. *
  3543. * spin_lock_irq(&dev_priv->uncore.lock);
  3544. * intel_uncore_forcewake_get__locked();
  3545. *
  3546. * and
  3547. *
  3548. * intel_uncore_forcewake_put__locked();
  3549. * spin_unlock_irq(&dev_priv->uncore.lock);
  3550. *
  3551. *
  3552. * Note: some registers may not need forcewake held, so
  3553. * intel_uncore_forcewake_{get,put} can be omitted, see
  3554. * intel_uncore_forcewake_for_reg().
  3555. *
  3556. * Certain architectures will die if the same cacheline is concurrently accessed
  3557. * by different clients (e.g. on Ivybridge). Access to registers should
  3558. * therefore generally be serialised, by either the dev_priv->uncore.lock or
  3559. * a more localised lock guarding all access to that bank of registers.
  3560. */
  3561. #define I915_READ_FW(reg__) __raw_i915_read32(dev_priv, (reg__))
  3562. #define I915_WRITE_FW(reg__, val__) __raw_i915_write32(dev_priv, (reg__), (val__))
  3563. #define I915_WRITE64_FW(reg__, val__) __raw_i915_write64(dev_priv, (reg__), (val__))
  3564. #define POSTING_READ_FW(reg__) (void)I915_READ_FW(reg__)
  3565. /* "Broadcast RGB" property */
  3566. #define INTEL_BROADCAST_RGB_AUTO 0
  3567. #define INTEL_BROADCAST_RGB_FULL 1
  3568. #define INTEL_BROADCAST_RGB_LIMITED 2
  3569. static inline i915_reg_t i915_vgacntrl_reg(struct drm_i915_private *dev_priv)
  3570. {
  3571. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  3572. return VLV_VGACNTRL;
  3573. else if (INTEL_GEN(dev_priv) >= 5)
  3574. return CPU_VGACNTRL;
  3575. else
  3576. return VGACNTRL;
  3577. }
  3578. static inline unsigned long msecs_to_jiffies_timeout(const unsigned int m)
  3579. {
  3580. unsigned long j = msecs_to_jiffies(m);
  3581. return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
  3582. }
  3583. static inline unsigned long nsecs_to_jiffies_timeout(const u64 n)
  3584. {
  3585. /* nsecs_to_jiffies64() does not guard against overflow */
  3586. if (NSEC_PER_SEC % HZ &&
  3587. div_u64(n, NSEC_PER_SEC) >= MAX_JIFFY_OFFSET / HZ)
  3588. return MAX_JIFFY_OFFSET;
  3589. return min_t(u64, MAX_JIFFY_OFFSET, nsecs_to_jiffies64(n) + 1);
  3590. }
  3591. static inline unsigned long
  3592. timespec_to_jiffies_timeout(const struct timespec *value)
  3593. {
  3594. unsigned long j = timespec_to_jiffies(value);
  3595. return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
  3596. }
  3597. /*
  3598. * If you need to wait X milliseconds between events A and B, but event B
  3599. * doesn't happen exactly after event A, you record the timestamp (jiffies) of
  3600. * when event A happened, then just before event B you call this function and
  3601. * pass the timestamp as the first argument, and X as the second argument.
  3602. */
  3603. static inline void
  3604. wait_remaining_ms_from_jiffies(unsigned long timestamp_jiffies, int to_wait_ms)
  3605. {
  3606. unsigned long target_jiffies, tmp_jiffies, remaining_jiffies;
  3607. /*
  3608. * Don't re-read the value of "jiffies" every time since it may change
  3609. * behind our back and break the math.
  3610. */
  3611. tmp_jiffies = jiffies;
  3612. target_jiffies = timestamp_jiffies +
  3613. msecs_to_jiffies_timeout(to_wait_ms);
  3614. if (time_after(target_jiffies, tmp_jiffies)) {
  3615. remaining_jiffies = target_jiffies - tmp_jiffies;
  3616. while (remaining_jiffies)
  3617. remaining_jiffies =
  3618. schedule_timeout_uninterruptible(remaining_jiffies);
  3619. }
  3620. }
  3621. static inline bool
  3622. __i915_request_irq_complete(const struct drm_i915_gem_request *req)
  3623. {
  3624. struct intel_engine_cs *engine = req->engine;
  3625. u32 seqno;
  3626. /* Note that the engine may have wrapped around the seqno, and
  3627. * so our request->global_seqno will be ahead of the hardware,
  3628. * even though it completed the request before wrapping. We catch
  3629. * this by kicking all the waiters before resetting the seqno
  3630. * in hardware, and also signal the fence.
  3631. */
  3632. if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &req->fence.flags))
  3633. return true;
  3634. /* The request was dequeued before we were awoken. We check after
  3635. * inspecting the hw to confirm that this was the same request
  3636. * that generated the HWS update. The memory barriers within
  3637. * the request execution are sufficient to ensure that a check
  3638. * after reading the value from hw matches this request.
  3639. */
  3640. seqno = i915_gem_request_global_seqno(req);
  3641. if (!seqno)
  3642. return false;
  3643. /* Before we do the heavier coherent read of the seqno,
  3644. * check the value (hopefully) in the CPU cacheline.
  3645. */
  3646. if (__i915_gem_request_completed(req, seqno))
  3647. return true;
  3648. /* Ensure our read of the seqno is coherent so that we
  3649. * do not "miss an interrupt" (i.e. if this is the last
  3650. * request and the seqno write from the GPU is not visible
  3651. * by the time the interrupt fires, we will see that the
  3652. * request is incomplete and go back to sleep awaiting
  3653. * another interrupt that will never come.)
  3654. *
  3655. * Strictly, we only need to do this once after an interrupt,
  3656. * but it is easier and safer to do it every time the waiter
  3657. * is woken.
  3658. */
  3659. if (engine->irq_seqno_barrier &&
  3660. test_and_clear_bit(ENGINE_IRQ_BREADCRUMB, &engine->irq_posted)) {
  3661. struct intel_breadcrumbs *b = &engine->breadcrumbs;
  3662. /* The ordering of irq_posted versus applying the barrier
  3663. * is crucial. The clearing of the current irq_posted must
  3664. * be visible before we perform the barrier operation,
  3665. * such that if a subsequent interrupt arrives, irq_posted
  3666. * is reasserted and our task rewoken (which causes us to
  3667. * do another __i915_request_irq_complete() immediately
  3668. * and reapply the barrier). Conversely, if the clear
  3669. * occurs after the barrier, then an interrupt that arrived
  3670. * whilst we waited on the barrier would not trigger a
  3671. * barrier on the next pass, and the read may not see the
  3672. * seqno update.
  3673. */
  3674. engine->irq_seqno_barrier(engine);
  3675. /* If we consume the irq, but we are no longer the bottom-half,
  3676. * the real bottom-half may not have serialised their own
  3677. * seqno check with the irq-barrier (i.e. may have inspected
  3678. * the seqno before we believe it coherent since they see
  3679. * irq_posted == false but we are still running).
  3680. */
  3681. spin_lock_irq(&b->irq_lock);
  3682. if (b->irq_wait && b->irq_wait->tsk != current)
  3683. /* Note that if the bottom-half is changed as we
  3684. * are sending the wake-up, the new bottom-half will
  3685. * be woken by whomever made the change. We only have
  3686. * to worry about when we steal the irq-posted for
  3687. * ourself.
  3688. */
  3689. wake_up_process(b->irq_wait->tsk);
  3690. spin_unlock_irq(&b->irq_lock);
  3691. if (__i915_gem_request_completed(req, seqno))
  3692. return true;
  3693. }
  3694. return false;
  3695. }
  3696. void i915_memcpy_init_early(struct drm_i915_private *dev_priv);
  3697. bool i915_memcpy_from_wc(void *dst, const void *src, unsigned long len);
  3698. /* The movntdqa instructions used for memcpy-from-wc require 16-byte alignment,
  3699. * as well as SSE4.1 support. i915_memcpy_from_wc() will report if it cannot
  3700. * perform the operation. To check beforehand, pass in the parameters to
  3701. * to i915_can_memcpy_from_wc() - since we only care about the low 4 bits,
  3702. * you only need to pass in the minor offsets, page-aligned pointers are
  3703. * always valid.
  3704. *
  3705. * For just checking for SSE4.1, in the foreknowledge that the future use
  3706. * will be correctly aligned, just use i915_has_memcpy_from_wc().
  3707. */
  3708. #define i915_can_memcpy_from_wc(dst, src, len) \
  3709. i915_memcpy_from_wc((void *)((unsigned long)(dst) | (unsigned long)(src) | (len)), NULL, 0)
  3710. #define i915_has_memcpy_from_wc() \
  3711. i915_memcpy_from_wc(NULL, NULL, 0)
  3712. /* i915_mm.c */
  3713. int remap_io_mapping(struct vm_area_struct *vma,
  3714. unsigned long addr, unsigned long pfn, unsigned long size,
  3715. struct io_mapping *iomap);
  3716. static inline bool
  3717. intel_engine_can_store_dword(struct intel_engine_cs *engine)
  3718. {
  3719. return __intel_engine_can_store_dword(INTEL_GEN(engine->i915),
  3720. engine->class);
  3721. }
  3722. #endif