i915_drv.h 117 KB

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