i915_drv.h 120 KB

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