i915_drv.h 125 KB

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