i915_drv.h 117 KB

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