i915_drv.h 124 KB

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