i915_drv.h 124 KB

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