i915_drv.h 134 KB

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