i915_drv.h 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579
  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 "i915_reg.h"
  34. #include "intel_bios.h"
  35. #include "intel_ringbuffer.h"
  36. #include "intel_lrc.h"
  37. #include "i915_gem_gtt.h"
  38. #include "i915_gem_render_state.h"
  39. #include <linux/io-mapping.h>
  40. #include <linux/i2c.h>
  41. #include <linux/i2c-algo-bit.h>
  42. #include <drm/intel-gtt.h>
  43. #include <drm/drm_legacy.h> /* for struct drm_dma_handle */
  44. #include <drm/drm_gem.h>
  45. #include <linux/backlight.h>
  46. #include <linux/hashtable.h>
  47. #include <linux/intel-iommu.h>
  48. #include <linux/kref.h>
  49. #include <linux/pm_qos.h>
  50. #include "intel_guc.h"
  51. /* General customization:
  52. */
  53. #define DRIVER_NAME "i915"
  54. #define DRIVER_DESC "Intel Graphics"
  55. #define DRIVER_DATE "20151120"
  56. #undef WARN_ON
  57. /* Many gcc seem to no see through this and fall over :( */
  58. #if 0
  59. #define WARN_ON(x) ({ \
  60. bool __i915_warn_cond = (x); \
  61. if (__builtin_constant_p(__i915_warn_cond)) \
  62. BUILD_BUG_ON(__i915_warn_cond); \
  63. WARN(__i915_warn_cond, "WARN_ON(" #x ")"); })
  64. #else
  65. #define WARN_ON(x) WARN((x), "WARN_ON(%s)", #x )
  66. #endif
  67. #undef WARN_ON_ONCE
  68. #define WARN_ON_ONCE(x) WARN_ONCE((x), "WARN_ON_ONCE(%s)", #x )
  69. #define MISSING_CASE(x) WARN(1, "Missing switch case (%lu) in %s\n", \
  70. (long) (x), __func__);
  71. /* Use I915_STATE_WARN(x) and I915_STATE_WARN_ON() (rather than WARN() and
  72. * WARN_ON()) for hw state sanity checks to check for unexpected conditions
  73. * which may not necessarily be a user visible problem. This will either
  74. * WARN() or DRM_ERROR() depending on the verbose_checks moduleparam, to
  75. * enable distros and users to tailor their preferred amount of i915 abrt
  76. * spam.
  77. */
  78. #define I915_STATE_WARN(condition, format...) ({ \
  79. int __ret_warn_on = !!(condition); \
  80. if (unlikely(__ret_warn_on)) { \
  81. if (i915.verbose_state_checks) \
  82. WARN(1, format); \
  83. else \
  84. DRM_ERROR(format); \
  85. } \
  86. unlikely(__ret_warn_on); \
  87. })
  88. #define I915_STATE_WARN_ON(condition) ({ \
  89. int __ret_warn_on = !!(condition); \
  90. if (unlikely(__ret_warn_on)) { \
  91. if (i915.verbose_state_checks) \
  92. WARN(1, "WARN_ON(" #condition ")\n"); \
  93. else \
  94. DRM_ERROR("WARN_ON(" #condition ")\n"); \
  95. } \
  96. unlikely(__ret_warn_on); \
  97. })
  98. static inline const char *yesno(bool v)
  99. {
  100. return v ? "yes" : "no";
  101. }
  102. enum pipe {
  103. INVALID_PIPE = -1,
  104. PIPE_A = 0,
  105. PIPE_B,
  106. PIPE_C,
  107. _PIPE_EDP,
  108. I915_MAX_PIPES = _PIPE_EDP
  109. };
  110. #define pipe_name(p) ((p) + 'A')
  111. enum transcoder {
  112. TRANSCODER_A = 0,
  113. TRANSCODER_B,
  114. TRANSCODER_C,
  115. TRANSCODER_EDP,
  116. I915_MAX_TRANSCODERS
  117. };
  118. #define transcoder_name(t) ((t) + 'A')
  119. /*
  120. * I915_MAX_PLANES in the enum below is the maximum (across all platforms)
  121. * number of planes per CRTC. Not all platforms really have this many planes,
  122. * which means some arrays of size I915_MAX_PLANES may have unused entries
  123. * between the topmost sprite plane and the cursor plane.
  124. */
  125. enum plane {
  126. PLANE_A = 0,
  127. PLANE_B,
  128. PLANE_C,
  129. PLANE_CURSOR,
  130. I915_MAX_PLANES,
  131. };
  132. #define plane_name(p) ((p) + 'A')
  133. #define sprite_name(p, s) ((p) * INTEL_INFO(dev)->num_sprites[(p)] + (s) + 'A')
  134. enum port {
  135. PORT_A = 0,
  136. PORT_B,
  137. PORT_C,
  138. PORT_D,
  139. PORT_E,
  140. I915_MAX_PORTS
  141. };
  142. #define port_name(p) ((p) + 'A')
  143. #define I915_NUM_PHYS_VLV 2
  144. enum dpio_channel {
  145. DPIO_CH0,
  146. DPIO_CH1
  147. };
  148. enum dpio_phy {
  149. DPIO_PHY0,
  150. DPIO_PHY1
  151. };
  152. enum intel_display_power_domain {
  153. POWER_DOMAIN_PIPE_A,
  154. POWER_DOMAIN_PIPE_B,
  155. POWER_DOMAIN_PIPE_C,
  156. POWER_DOMAIN_PIPE_A_PANEL_FITTER,
  157. POWER_DOMAIN_PIPE_B_PANEL_FITTER,
  158. POWER_DOMAIN_PIPE_C_PANEL_FITTER,
  159. POWER_DOMAIN_TRANSCODER_A,
  160. POWER_DOMAIN_TRANSCODER_B,
  161. POWER_DOMAIN_TRANSCODER_C,
  162. POWER_DOMAIN_TRANSCODER_EDP,
  163. POWER_DOMAIN_PORT_DDI_A_LANES,
  164. POWER_DOMAIN_PORT_DDI_B_LANES,
  165. POWER_DOMAIN_PORT_DDI_C_LANES,
  166. POWER_DOMAIN_PORT_DDI_D_LANES,
  167. POWER_DOMAIN_PORT_DDI_E_LANES,
  168. POWER_DOMAIN_PORT_DSI,
  169. POWER_DOMAIN_PORT_CRT,
  170. POWER_DOMAIN_PORT_OTHER,
  171. POWER_DOMAIN_VGA,
  172. POWER_DOMAIN_AUDIO,
  173. POWER_DOMAIN_PLLS,
  174. POWER_DOMAIN_AUX_A,
  175. POWER_DOMAIN_AUX_B,
  176. POWER_DOMAIN_AUX_C,
  177. POWER_DOMAIN_AUX_D,
  178. POWER_DOMAIN_GMBUS,
  179. POWER_DOMAIN_MODESET,
  180. POWER_DOMAIN_INIT,
  181. POWER_DOMAIN_NUM,
  182. };
  183. #define POWER_DOMAIN_PIPE(pipe) ((pipe) + POWER_DOMAIN_PIPE_A)
  184. #define POWER_DOMAIN_PIPE_PANEL_FITTER(pipe) \
  185. ((pipe) + POWER_DOMAIN_PIPE_A_PANEL_FITTER)
  186. #define POWER_DOMAIN_TRANSCODER(tran) \
  187. ((tran) == TRANSCODER_EDP ? POWER_DOMAIN_TRANSCODER_EDP : \
  188. (tran) + POWER_DOMAIN_TRANSCODER_A)
  189. enum hpd_pin {
  190. HPD_NONE = 0,
  191. HPD_TV = HPD_NONE, /* TV is known to be unreliable */
  192. HPD_CRT,
  193. HPD_SDVO_B,
  194. HPD_SDVO_C,
  195. HPD_PORT_A,
  196. HPD_PORT_B,
  197. HPD_PORT_C,
  198. HPD_PORT_D,
  199. HPD_PORT_E,
  200. HPD_NUM_PINS
  201. };
  202. #define for_each_hpd_pin(__pin) \
  203. for ((__pin) = (HPD_NONE + 1); (__pin) < HPD_NUM_PINS; (__pin)++)
  204. struct i915_hotplug {
  205. struct work_struct hotplug_work;
  206. struct {
  207. unsigned long last_jiffies;
  208. int count;
  209. enum {
  210. HPD_ENABLED = 0,
  211. HPD_DISABLED = 1,
  212. HPD_MARK_DISABLED = 2
  213. } state;
  214. } stats[HPD_NUM_PINS];
  215. u32 event_bits;
  216. struct delayed_work reenable_work;
  217. struct intel_digital_port *irq_port[I915_MAX_PORTS];
  218. u32 long_port_mask;
  219. u32 short_port_mask;
  220. struct work_struct dig_port_work;
  221. /*
  222. * if we get a HPD irq from DP and a HPD irq from non-DP
  223. * the non-DP HPD could block the workqueue on a mode config
  224. * mutex getting, that userspace may have taken. However
  225. * userspace is waiting on the DP workqueue to run which is
  226. * blocked behind the non-DP one.
  227. */
  228. struct workqueue_struct *dp_wq;
  229. };
  230. #define I915_GEM_GPU_DOMAINS \
  231. (I915_GEM_DOMAIN_RENDER | \
  232. I915_GEM_DOMAIN_SAMPLER | \
  233. I915_GEM_DOMAIN_COMMAND | \
  234. I915_GEM_DOMAIN_INSTRUCTION | \
  235. I915_GEM_DOMAIN_VERTEX)
  236. #define for_each_pipe(__dev_priv, __p) \
  237. for ((__p) = 0; (__p) < INTEL_INFO(__dev_priv)->num_pipes; (__p)++)
  238. #define for_each_plane(__dev_priv, __pipe, __p) \
  239. for ((__p) = 0; \
  240. (__p) < INTEL_INFO(__dev_priv)->num_sprites[(__pipe)] + 1; \
  241. (__p)++)
  242. #define for_each_sprite(__dev_priv, __p, __s) \
  243. for ((__s) = 0; \
  244. (__s) < INTEL_INFO(__dev_priv)->num_sprites[(__p)]; \
  245. (__s)++)
  246. #define for_each_crtc(dev, crtc) \
  247. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  248. #define for_each_intel_plane(dev, intel_plane) \
  249. list_for_each_entry(intel_plane, \
  250. &dev->mode_config.plane_list, \
  251. base.head)
  252. #define for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) \
  253. list_for_each_entry(intel_plane, \
  254. &(dev)->mode_config.plane_list, \
  255. base.head) \
  256. if ((intel_plane)->pipe == (intel_crtc)->pipe)
  257. #define for_each_intel_crtc(dev, intel_crtc) \
  258. list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, base.head)
  259. #define for_each_intel_encoder(dev, intel_encoder) \
  260. list_for_each_entry(intel_encoder, \
  261. &(dev)->mode_config.encoder_list, \
  262. base.head)
  263. #define for_each_intel_connector(dev, intel_connector) \
  264. list_for_each_entry(intel_connector, \
  265. &dev->mode_config.connector_list, \
  266. base.head)
  267. #define for_each_encoder_on_crtc(dev, __crtc, intel_encoder) \
  268. list_for_each_entry((intel_encoder), &(dev)->mode_config.encoder_list, base.head) \
  269. if ((intel_encoder)->base.crtc == (__crtc))
  270. #define for_each_connector_on_encoder(dev, __encoder, intel_connector) \
  271. list_for_each_entry((intel_connector), &(dev)->mode_config.connector_list, base.head) \
  272. if ((intel_connector)->base.encoder == (__encoder))
  273. #define for_each_power_domain(domain, mask) \
  274. for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
  275. if ((1 << (domain)) & (mask))
  276. struct drm_i915_private;
  277. struct i915_mm_struct;
  278. struct i915_mmu_object;
  279. struct drm_i915_file_private {
  280. struct drm_i915_private *dev_priv;
  281. struct drm_file *file;
  282. struct {
  283. spinlock_t lock;
  284. struct list_head request_list;
  285. /* 20ms is a fairly arbitrary limit (greater than the average frame time)
  286. * chosen to prevent the CPU getting more than a frame ahead of the GPU
  287. * (when using lax throttling for the frontbuffer). We also use it to
  288. * offer free GPU waitboosts for severely congested workloads.
  289. */
  290. #define DRM_I915_THROTTLE_JIFFIES msecs_to_jiffies(20)
  291. } mm;
  292. struct idr context_idr;
  293. struct intel_rps_client {
  294. struct list_head link;
  295. unsigned boosts;
  296. } rps;
  297. struct intel_engine_cs *bsd_ring;
  298. };
  299. enum intel_dpll_id {
  300. DPLL_ID_PRIVATE = -1, /* non-shared dpll in use */
  301. /* real shared dpll ids must be >= 0 */
  302. DPLL_ID_PCH_PLL_A = 0,
  303. DPLL_ID_PCH_PLL_B = 1,
  304. /* hsw/bdw */
  305. DPLL_ID_WRPLL1 = 0,
  306. DPLL_ID_WRPLL2 = 1,
  307. DPLL_ID_SPLL = 2,
  308. /* skl */
  309. DPLL_ID_SKL_DPLL1 = 0,
  310. DPLL_ID_SKL_DPLL2 = 1,
  311. DPLL_ID_SKL_DPLL3 = 2,
  312. };
  313. #define I915_NUM_PLLS 3
  314. struct intel_dpll_hw_state {
  315. /* i9xx, pch plls */
  316. uint32_t dpll;
  317. uint32_t dpll_md;
  318. uint32_t fp0;
  319. uint32_t fp1;
  320. /* hsw, bdw */
  321. uint32_t wrpll;
  322. uint32_t spll;
  323. /* skl */
  324. /*
  325. * DPLL_CTRL1 has 6 bits for each each this DPLL. We store those in
  326. * lower part of ctrl1 and they get shifted into position when writing
  327. * the register. This allows us to easily compare the state to share
  328. * the DPLL.
  329. */
  330. uint32_t ctrl1;
  331. /* HDMI only, 0 when used for DP */
  332. uint32_t cfgcr1, cfgcr2;
  333. /* bxt */
  334. uint32_t ebb0, ebb4, pll0, pll1, pll2, pll3, pll6, pll8, pll9, pll10,
  335. pcsdw12;
  336. };
  337. struct intel_shared_dpll_config {
  338. unsigned crtc_mask; /* mask of CRTCs sharing this PLL */
  339. struct intel_dpll_hw_state hw_state;
  340. };
  341. struct intel_shared_dpll {
  342. struct intel_shared_dpll_config config;
  343. int active; /* count of number of active CRTCs (i.e. DPMS on) */
  344. bool on; /* is the PLL actually active? Disabled during modeset */
  345. const char *name;
  346. /* should match the index in the dev_priv->shared_dplls array */
  347. enum intel_dpll_id id;
  348. /* The mode_set hook is optional and should be used together with the
  349. * intel_prepare_shared_dpll function. */
  350. void (*mode_set)(struct drm_i915_private *dev_priv,
  351. struct intel_shared_dpll *pll);
  352. void (*enable)(struct drm_i915_private *dev_priv,
  353. struct intel_shared_dpll *pll);
  354. void (*disable)(struct drm_i915_private *dev_priv,
  355. struct intel_shared_dpll *pll);
  356. bool (*get_hw_state)(struct drm_i915_private *dev_priv,
  357. struct intel_shared_dpll *pll,
  358. struct intel_dpll_hw_state *hw_state);
  359. };
  360. #define SKL_DPLL0 0
  361. #define SKL_DPLL1 1
  362. #define SKL_DPLL2 2
  363. #define SKL_DPLL3 3
  364. /* Used by dp and fdi links */
  365. struct intel_link_m_n {
  366. uint32_t tu;
  367. uint32_t gmch_m;
  368. uint32_t gmch_n;
  369. uint32_t link_m;
  370. uint32_t link_n;
  371. };
  372. void intel_link_compute_m_n(int bpp, int nlanes,
  373. int pixel_clock, int link_clock,
  374. struct intel_link_m_n *m_n);
  375. /* Interface history:
  376. *
  377. * 1.1: Original.
  378. * 1.2: Add Power Management
  379. * 1.3: Add vblank support
  380. * 1.4: Fix cmdbuffer path, add heap destroy
  381. * 1.5: Add vblank pipe configuration
  382. * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
  383. * - Support vertical blank on secondary display pipe
  384. */
  385. #define DRIVER_MAJOR 1
  386. #define DRIVER_MINOR 6
  387. #define DRIVER_PATCHLEVEL 0
  388. #define WATCH_LISTS 0
  389. struct opregion_header;
  390. struct opregion_acpi;
  391. struct opregion_swsci;
  392. struct opregion_asle;
  393. struct intel_opregion {
  394. struct opregion_header *header;
  395. struct opregion_acpi *acpi;
  396. struct opregion_swsci *swsci;
  397. u32 swsci_gbda_sub_functions;
  398. u32 swsci_sbcb_sub_functions;
  399. struct opregion_asle *asle;
  400. void *vbt;
  401. u32 *lid_state;
  402. struct work_struct asle_work;
  403. };
  404. #define OPREGION_SIZE (8*1024)
  405. struct intel_overlay;
  406. struct intel_overlay_error_state;
  407. #define I915_FENCE_REG_NONE -1
  408. #define I915_MAX_NUM_FENCES 32
  409. /* 32 fences + sign bit for FENCE_REG_NONE */
  410. #define I915_MAX_NUM_FENCE_BITS 6
  411. struct drm_i915_fence_reg {
  412. struct list_head lru_list;
  413. struct drm_i915_gem_object *obj;
  414. int pin_count;
  415. };
  416. struct sdvo_device_mapping {
  417. u8 initialized;
  418. u8 dvo_port;
  419. u8 slave_addr;
  420. u8 dvo_wiring;
  421. u8 i2c_pin;
  422. u8 ddc_pin;
  423. };
  424. struct intel_display_error_state;
  425. struct drm_i915_error_state {
  426. struct kref ref;
  427. struct timeval time;
  428. char error_msg[128];
  429. int iommu;
  430. u32 reset_count;
  431. u32 suspend_count;
  432. /* Generic register state */
  433. u32 eir;
  434. u32 pgtbl_er;
  435. u32 ier;
  436. u32 gtier[4];
  437. u32 ccid;
  438. u32 derrmr;
  439. u32 forcewake;
  440. u32 error; /* gen6+ */
  441. u32 err_int; /* gen7 */
  442. u32 fault_data0; /* gen8, gen9 */
  443. u32 fault_data1; /* gen8, gen9 */
  444. u32 done_reg;
  445. u32 gac_eco;
  446. u32 gam_ecochk;
  447. u32 gab_ctl;
  448. u32 gfx_mode;
  449. u32 extra_instdone[I915_NUM_INSTDONE_REG];
  450. u64 fence[I915_MAX_NUM_FENCES];
  451. struct intel_overlay_error_state *overlay;
  452. struct intel_display_error_state *display;
  453. struct drm_i915_error_object *semaphore_obj;
  454. struct drm_i915_error_ring {
  455. bool valid;
  456. /* Software tracked state */
  457. bool waiting;
  458. int hangcheck_score;
  459. enum intel_ring_hangcheck_action hangcheck_action;
  460. int num_requests;
  461. /* our own tracking of ring head and tail */
  462. u32 cpu_ring_head;
  463. u32 cpu_ring_tail;
  464. u32 semaphore_seqno[I915_NUM_RINGS - 1];
  465. /* Register state */
  466. u32 start;
  467. u32 tail;
  468. u32 head;
  469. u32 ctl;
  470. u32 hws;
  471. u32 ipeir;
  472. u32 ipehr;
  473. u32 instdone;
  474. u32 bbstate;
  475. u32 instpm;
  476. u32 instps;
  477. u32 seqno;
  478. u64 bbaddr;
  479. u64 acthd;
  480. u32 fault_reg;
  481. u64 faddr;
  482. u32 rc_psmi; /* sleep state */
  483. u32 semaphore_mboxes[I915_NUM_RINGS - 1];
  484. struct drm_i915_error_object {
  485. int page_count;
  486. u64 gtt_offset;
  487. u32 *pages[0];
  488. } *ringbuffer, *batchbuffer, *wa_batchbuffer, *ctx, *hws_page;
  489. struct drm_i915_error_request {
  490. long jiffies;
  491. u32 seqno;
  492. u32 tail;
  493. } *requests;
  494. struct {
  495. u32 gfx_mode;
  496. union {
  497. u64 pdp[4];
  498. u32 pp_dir_base;
  499. };
  500. } vm_info;
  501. pid_t pid;
  502. char comm[TASK_COMM_LEN];
  503. } ring[I915_NUM_RINGS];
  504. struct drm_i915_error_buffer {
  505. u32 size;
  506. u32 name;
  507. u32 rseqno[I915_NUM_RINGS], wseqno;
  508. u64 gtt_offset;
  509. u32 read_domains;
  510. u32 write_domain;
  511. s32 fence_reg:I915_MAX_NUM_FENCE_BITS;
  512. s32 pinned:2;
  513. u32 tiling:2;
  514. u32 dirty:1;
  515. u32 purgeable:1;
  516. u32 userptr:1;
  517. s32 ring:4;
  518. u32 cache_level:3;
  519. } **active_bo, **pinned_bo;
  520. u32 *active_bo_count, *pinned_bo_count;
  521. u32 vm_count;
  522. };
  523. struct intel_connector;
  524. struct intel_encoder;
  525. struct intel_crtc_state;
  526. struct intel_initial_plane_config;
  527. struct intel_crtc;
  528. struct intel_limit;
  529. struct dpll;
  530. struct drm_i915_display_funcs {
  531. int (*get_display_clock_speed)(struct drm_device *dev);
  532. int (*get_fifo_size)(struct drm_device *dev, int plane);
  533. /**
  534. * find_dpll() - Find the best values for the PLL
  535. * @limit: limits for the PLL
  536. * @crtc: current CRTC
  537. * @target: target frequency in kHz
  538. * @refclk: reference clock frequency in kHz
  539. * @match_clock: if provided, @best_clock P divider must
  540. * match the P divider from @match_clock
  541. * used for LVDS downclocking
  542. * @best_clock: best PLL values found
  543. *
  544. * Returns true on success, false on failure.
  545. */
  546. bool (*find_dpll)(const struct intel_limit *limit,
  547. struct intel_crtc_state *crtc_state,
  548. int target, int refclk,
  549. struct dpll *match_clock,
  550. struct dpll *best_clock);
  551. int (*compute_pipe_wm)(struct intel_crtc *crtc,
  552. struct drm_atomic_state *state);
  553. void (*update_wm)(struct drm_crtc *crtc);
  554. int (*modeset_calc_cdclk)(struct drm_atomic_state *state);
  555. void (*modeset_commit_cdclk)(struct drm_atomic_state *state);
  556. /* Returns the active state of the crtc, and if the crtc is active,
  557. * fills out the pipe-config with the hw state. */
  558. bool (*get_pipe_config)(struct intel_crtc *,
  559. struct intel_crtc_state *);
  560. void (*get_initial_plane_config)(struct intel_crtc *,
  561. struct intel_initial_plane_config *);
  562. int (*crtc_compute_clock)(struct intel_crtc *crtc,
  563. struct intel_crtc_state *crtc_state);
  564. void (*crtc_enable)(struct drm_crtc *crtc);
  565. void (*crtc_disable)(struct drm_crtc *crtc);
  566. void (*audio_codec_enable)(struct drm_connector *connector,
  567. struct intel_encoder *encoder,
  568. const struct drm_display_mode *adjusted_mode);
  569. void (*audio_codec_disable)(struct intel_encoder *encoder);
  570. void (*fdi_link_train)(struct drm_crtc *crtc);
  571. void (*init_clock_gating)(struct drm_device *dev);
  572. int (*queue_flip)(struct drm_device *dev, struct drm_crtc *crtc,
  573. struct drm_framebuffer *fb,
  574. struct drm_i915_gem_object *obj,
  575. struct drm_i915_gem_request *req,
  576. uint32_t flags);
  577. void (*update_primary_plane)(struct drm_crtc *crtc,
  578. struct drm_framebuffer *fb,
  579. int x, int y);
  580. void (*hpd_irq_setup)(struct drm_device *dev);
  581. /* clock updates for mode set */
  582. /* cursor updates */
  583. /* render clock increase/decrease */
  584. /* display clock increase/decrease */
  585. /* pll clock increase/decrease */
  586. };
  587. enum forcewake_domain_id {
  588. FW_DOMAIN_ID_RENDER = 0,
  589. FW_DOMAIN_ID_BLITTER,
  590. FW_DOMAIN_ID_MEDIA,
  591. FW_DOMAIN_ID_COUNT
  592. };
  593. enum forcewake_domains {
  594. FORCEWAKE_RENDER = (1 << FW_DOMAIN_ID_RENDER),
  595. FORCEWAKE_BLITTER = (1 << FW_DOMAIN_ID_BLITTER),
  596. FORCEWAKE_MEDIA = (1 << FW_DOMAIN_ID_MEDIA),
  597. FORCEWAKE_ALL = (FORCEWAKE_RENDER |
  598. FORCEWAKE_BLITTER |
  599. FORCEWAKE_MEDIA)
  600. };
  601. struct intel_uncore_funcs {
  602. void (*force_wake_get)(struct drm_i915_private *dev_priv,
  603. enum forcewake_domains domains);
  604. void (*force_wake_put)(struct drm_i915_private *dev_priv,
  605. enum forcewake_domains domains);
  606. uint8_t (*mmio_readb)(struct drm_i915_private *dev_priv, i915_reg_t r, bool trace);
  607. uint16_t (*mmio_readw)(struct drm_i915_private *dev_priv, i915_reg_t r, bool trace);
  608. uint32_t (*mmio_readl)(struct drm_i915_private *dev_priv, i915_reg_t r, bool trace);
  609. uint64_t (*mmio_readq)(struct drm_i915_private *dev_priv, i915_reg_t r, bool trace);
  610. void (*mmio_writeb)(struct drm_i915_private *dev_priv, i915_reg_t r,
  611. uint8_t val, bool trace);
  612. void (*mmio_writew)(struct drm_i915_private *dev_priv, i915_reg_t r,
  613. uint16_t val, bool trace);
  614. void (*mmio_writel)(struct drm_i915_private *dev_priv, i915_reg_t r,
  615. uint32_t val, bool trace);
  616. void (*mmio_writeq)(struct drm_i915_private *dev_priv, i915_reg_t r,
  617. uint64_t val, bool trace);
  618. };
  619. struct intel_uncore {
  620. spinlock_t lock; /** lock is also taken in irq contexts. */
  621. struct intel_uncore_funcs funcs;
  622. unsigned fifo_count;
  623. enum forcewake_domains fw_domains;
  624. struct intel_uncore_forcewake_domain {
  625. struct drm_i915_private *i915;
  626. enum forcewake_domain_id id;
  627. unsigned wake_count;
  628. struct timer_list timer;
  629. i915_reg_t reg_set;
  630. u32 val_set;
  631. u32 val_clear;
  632. i915_reg_t reg_ack;
  633. i915_reg_t reg_post;
  634. u32 val_reset;
  635. } fw_domain[FW_DOMAIN_ID_COUNT];
  636. };
  637. /* Iterate over initialised fw domains */
  638. #define for_each_fw_domain_mask(domain__, mask__, dev_priv__, i__) \
  639. for ((i__) = 0, (domain__) = &(dev_priv__)->uncore.fw_domain[0]; \
  640. (i__) < FW_DOMAIN_ID_COUNT; \
  641. (i__)++, (domain__) = &(dev_priv__)->uncore.fw_domain[i__]) \
  642. if (((mask__) & (dev_priv__)->uncore.fw_domains) & (1 << (i__)))
  643. #define for_each_fw_domain(domain__, dev_priv__, i__) \
  644. for_each_fw_domain_mask(domain__, FORCEWAKE_ALL, dev_priv__, i__)
  645. #define CSR_VERSION(major, minor) ((major) << 16 | (minor))
  646. #define CSR_VERSION_MAJOR(version) ((version) >> 16)
  647. #define CSR_VERSION_MINOR(version) ((version) & 0xffff)
  648. struct intel_csr {
  649. struct work_struct work;
  650. const char *fw_path;
  651. uint32_t *dmc_payload;
  652. uint32_t dmc_fw_size;
  653. uint32_t version;
  654. uint32_t mmio_count;
  655. i915_reg_t mmioaddr[8];
  656. uint32_t mmiodata[8];
  657. };
  658. #define DEV_INFO_FOR_EACH_FLAG(func, sep) \
  659. func(is_mobile) sep \
  660. func(is_i85x) sep \
  661. func(is_i915g) sep \
  662. func(is_i945gm) sep \
  663. func(is_g33) sep \
  664. func(need_gfx_hws) sep \
  665. func(is_g4x) sep \
  666. func(is_pineview) sep \
  667. func(is_broadwater) sep \
  668. func(is_crestline) sep \
  669. func(is_ivybridge) sep \
  670. func(is_valleyview) sep \
  671. func(is_haswell) sep \
  672. func(is_skylake) sep \
  673. func(is_broxton) sep \
  674. func(is_kabylake) sep \
  675. func(is_preliminary) sep \
  676. func(has_fbc) sep \
  677. func(has_pipe_cxsr) sep \
  678. func(has_hotplug) sep \
  679. func(cursor_needs_physical) sep \
  680. func(has_overlay) sep \
  681. func(overlay_needs_physical) sep \
  682. func(supports_tv) sep \
  683. func(has_llc) sep \
  684. func(has_ddi) sep \
  685. func(has_fpga_dbg)
  686. #define DEFINE_FLAG(name) u8 name:1
  687. #define SEP_SEMICOLON ;
  688. struct intel_device_info {
  689. u32 display_mmio_offset;
  690. u16 device_id;
  691. u8 num_pipes:3;
  692. u8 num_sprites[I915_MAX_PIPES];
  693. u8 gen;
  694. u8 ring_mask; /* Rings supported by the HW */
  695. DEV_INFO_FOR_EACH_FLAG(DEFINE_FLAG, SEP_SEMICOLON);
  696. /* Register offsets for the various display pipes and transcoders */
  697. int pipe_offsets[I915_MAX_TRANSCODERS];
  698. int trans_offsets[I915_MAX_TRANSCODERS];
  699. int palette_offsets[I915_MAX_PIPES];
  700. int cursor_offsets[I915_MAX_PIPES];
  701. /* Slice/subslice/EU info */
  702. u8 slice_total;
  703. u8 subslice_total;
  704. u8 subslice_per_slice;
  705. u8 eu_total;
  706. u8 eu_per_subslice;
  707. /* For each slice, which subslice(s) has(have) 7 EUs (bitfield)? */
  708. u8 subslice_7eu[3];
  709. u8 has_slice_pg:1;
  710. u8 has_subslice_pg:1;
  711. u8 has_eu_pg:1;
  712. };
  713. #undef DEFINE_FLAG
  714. #undef SEP_SEMICOLON
  715. enum i915_cache_level {
  716. I915_CACHE_NONE = 0,
  717. I915_CACHE_LLC, /* also used for snoopable memory on non-LLC */
  718. I915_CACHE_L3_LLC, /* gen7+, L3 sits between the domain specifc
  719. caches, eg sampler/render caches, and the
  720. large Last-Level-Cache. LLC is coherent with
  721. the CPU, but L3 is only visible to the GPU. */
  722. I915_CACHE_WT, /* hsw:gt3e WriteThrough for scanouts */
  723. };
  724. struct i915_ctx_hang_stats {
  725. /* This context had batch pending when hang was declared */
  726. unsigned batch_pending;
  727. /* This context had batch active when hang was declared */
  728. unsigned batch_active;
  729. /* Time when this context was last blamed for a GPU reset */
  730. unsigned long guilty_ts;
  731. /* If the contexts causes a second GPU hang within this time,
  732. * it is permanently banned from submitting any more work.
  733. */
  734. unsigned long ban_period_seconds;
  735. /* This context is banned to submit more work */
  736. bool banned;
  737. };
  738. /* This must match up with the value previously used for execbuf2.rsvd1. */
  739. #define DEFAULT_CONTEXT_HANDLE 0
  740. #define CONTEXT_NO_ZEROMAP (1<<0)
  741. /**
  742. * struct intel_context - as the name implies, represents a context.
  743. * @ref: reference count.
  744. * @user_handle: userspace tracking identity for this context.
  745. * @remap_slice: l3 row remapping information.
  746. * @flags: context specific flags:
  747. * CONTEXT_NO_ZEROMAP: do not allow mapping things to page 0.
  748. * @file_priv: filp associated with this context (NULL for global default
  749. * context).
  750. * @hang_stats: information about the role of this context in possible GPU
  751. * hangs.
  752. * @ppgtt: virtual memory space used by this context.
  753. * @legacy_hw_ctx: render context backing object and whether it is correctly
  754. * initialized (legacy ring submission mechanism only).
  755. * @link: link in the global list of contexts.
  756. *
  757. * Contexts are memory images used by the hardware to store copies of their
  758. * internal state.
  759. */
  760. struct intel_context {
  761. struct kref ref;
  762. int user_handle;
  763. uint8_t remap_slice;
  764. struct drm_i915_private *i915;
  765. int flags;
  766. struct drm_i915_file_private *file_priv;
  767. struct i915_ctx_hang_stats hang_stats;
  768. struct i915_hw_ppgtt *ppgtt;
  769. /* Legacy ring buffer submission */
  770. struct {
  771. struct drm_i915_gem_object *rcs_state;
  772. bool initialized;
  773. } legacy_hw_ctx;
  774. /* Execlists */
  775. struct {
  776. struct drm_i915_gem_object *state;
  777. struct intel_ringbuffer *ringbuf;
  778. int pin_count;
  779. } engine[I915_NUM_RINGS];
  780. struct list_head link;
  781. };
  782. enum fb_op_origin {
  783. ORIGIN_GTT,
  784. ORIGIN_CPU,
  785. ORIGIN_CS,
  786. ORIGIN_FLIP,
  787. ORIGIN_DIRTYFB,
  788. };
  789. struct i915_fbc {
  790. /* This is always the inner lock when overlapping with struct_mutex and
  791. * it's the outer lock when overlapping with stolen_lock. */
  792. struct mutex lock;
  793. unsigned long uncompressed_size;
  794. unsigned threshold;
  795. unsigned int fb_id;
  796. unsigned int possible_framebuffer_bits;
  797. unsigned int busy_bits;
  798. struct intel_crtc *crtc;
  799. int y;
  800. struct drm_mm_node compressed_fb;
  801. struct drm_mm_node *compressed_llb;
  802. bool false_color;
  803. bool active;
  804. struct intel_fbc_work {
  805. struct delayed_work work;
  806. struct drm_framebuffer *fb;
  807. } *fbc_work;
  808. const char *no_fbc_reason;
  809. bool (*is_active)(struct drm_i915_private *dev_priv);
  810. void (*activate)(struct intel_crtc *crtc);
  811. void (*deactivate)(struct drm_i915_private *dev_priv);
  812. };
  813. /**
  814. * HIGH_RR is the highest eDP panel refresh rate read from EDID
  815. * LOW_RR is the lowest eDP panel refresh rate found from EDID
  816. * parsing for same resolution.
  817. */
  818. enum drrs_refresh_rate_type {
  819. DRRS_HIGH_RR,
  820. DRRS_LOW_RR,
  821. DRRS_MAX_RR, /* RR count */
  822. };
  823. enum drrs_support_type {
  824. DRRS_NOT_SUPPORTED = 0,
  825. STATIC_DRRS_SUPPORT = 1,
  826. SEAMLESS_DRRS_SUPPORT = 2
  827. };
  828. struct intel_dp;
  829. struct i915_drrs {
  830. struct mutex mutex;
  831. struct delayed_work work;
  832. struct intel_dp *dp;
  833. unsigned busy_frontbuffer_bits;
  834. enum drrs_refresh_rate_type refresh_rate_type;
  835. enum drrs_support_type type;
  836. };
  837. struct i915_psr {
  838. struct mutex lock;
  839. bool sink_support;
  840. bool source_ok;
  841. struct intel_dp *enabled;
  842. bool active;
  843. struct delayed_work work;
  844. unsigned busy_frontbuffer_bits;
  845. bool psr2_support;
  846. bool aux_frame_sync;
  847. };
  848. enum intel_pch {
  849. PCH_NONE = 0, /* No PCH present */
  850. PCH_IBX, /* Ibexpeak PCH */
  851. PCH_CPT, /* Cougarpoint PCH */
  852. PCH_LPT, /* Lynxpoint PCH */
  853. PCH_SPT, /* Sunrisepoint PCH */
  854. PCH_NOP,
  855. };
  856. enum intel_sbi_destination {
  857. SBI_ICLK,
  858. SBI_MPHY,
  859. };
  860. #define QUIRK_PIPEA_FORCE (1<<0)
  861. #define QUIRK_LVDS_SSC_DISABLE (1<<1)
  862. #define QUIRK_INVERT_BRIGHTNESS (1<<2)
  863. #define QUIRK_BACKLIGHT_PRESENT (1<<3)
  864. #define QUIRK_PIPEB_FORCE (1<<4)
  865. #define QUIRK_PIN_SWIZZLED_PAGES (1<<5)
  866. struct intel_fbdev;
  867. struct intel_fbc_work;
  868. struct intel_gmbus {
  869. struct i2c_adapter adapter;
  870. u32 force_bit;
  871. u32 reg0;
  872. i915_reg_t gpio_reg;
  873. struct i2c_algo_bit_data bit_algo;
  874. struct drm_i915_private *dev_priv;
  875. };
  876. struct i915_suspend_saved_registers {
  877. u32 saveDSPARB;
  878. u32 saveLVDS;
  879. u32 savePP_ON_DELAYS;
  880. u32 savePP_OFF_DELAYS;
  881. u32 savePP_ON;
  882. u32 savePP_OFF;
  883. u32 savePP_CONTROL;
  884. u32 savePP_DIVISOR;
  885. u32 saveFBC_CONTROL;
  886. u32 saveCACHE_MODE_0;
  887. u32 saveMI_ARB_STATE;
  888. u32 saveSWF0[16];
  889. u32 saveSWF1[16];
  890. u32 saveSWF3[3];
  891. uint64_t saveFENCE[I915_MAX_NUM_FENCES];
  892. u32 savePCH_PORT_HOTPLUG;
  893. u16 saveGCDGMBUS;
  894. };
  895. struct vlv_s0ix_state {
  896. /* GAM */
  897. u32 wr_watermark;
  898. u32 gfx_prio_ctrl;
  899. u32 arb_mode;
  900. u32 gfx_pend_tlb0;
  901. u32 gfx_pend_tlb1;
  902. u32 lra_limits[GEN7_LRA_LIMITS_REG_NUM];
  903. u32 media_max_req_count;
  904. u32 gfx_max_req_count;
  905. u32 render_hwsp;
  906. u32 ecochk;
  907. u32 bsd_hwsp;
  908. u32 blt_hwsp;
  909. u32 tlb_rd_addr;
  910. /* MBC */
  911. u32 g3dctl;
  912. u32 gsckgctl;
  913. u32 mbctl;
  914. /* GCP */
  915. u32 ucgctl1;
  916. u32 ucgctl3;
  917. u32 rcgctl1;
  918. u32 rcgctl2;
  919. u32 rstctl;
  920. u32 misccpctl;
  921. /* GPM */
  922. u32 gfxpause;
  923. u32 rpdeuhwtc;
  924. u32 rpdeuc;
  925. u32 ecobus;
  926. u32 pwrdwnupctl;
  927. u32 rp_down_timeout;
  928. u32 rp_deucsw;
  929. u32 rcubmabdtmr;
  930. u32 rcedata;
  931. u32 spare2gh;
  932. /* Display 1 CZ domain */
  933. u32 gt_imr;
  934. u32 gt_ier;
  935. u32 pm_imr;
  936. u32 pm_ier;
  937. u32 gt_scratch[GEN7_GT_SCRATCH_REG_NUM];
  938. /* GT SA CZ domain */
  939. u32 tilectl;
  940. u32 gt_fifoctl;
  941. u32 gtlc_wake_ctrl;
  942. u32 gtlc_survive;
  943. u32 pmwgicz;
  944. /* Display 2 CZ domain */
  945. u32 gu_ctl0;
  946. u32 gu_ctl1;
  947. u32 pcbr;
  948. u32 clock_gate_dis2;
  949. };
  950. struct intel_rps_ei {
  951. u32 cz_clock;
  952. u32 render_c0;
  953. u32 media_c0;
  954. };
  955. struct intel_gen6_power_mgmt {
  956. /*
  957. * work, interrupts_enabled and pm_iir are protected by
  958. * dev_priv->irq_lock
  959. */
  960. struct work_struct work;
  961. bool interrupts_enabled;
  962. u32 pm_iir;
  963. /* Frequencies are stored in potentially platform dependent multiples.
  964. * In other words, *_freq needs to be multiplied by X to be interesting.
  965. * Soft limits are those which are used for the dynamic reclocking done
  966. * by the driver (raise frequencies under heavy loads, and lower for
  967. * lighter loads). Hard limits are those imposed by the hardware.
  968. *
  969. * A distinction is made for overclocking, which is never enabled by
  970. * default, and is considered to be above the hard limit if it's
  971. * possible at all.
  972. */
  973. u8 cur_freq; /* Current frequency (cached, may not == HW) */
  974. u8 min_freq_softlimit; /* Minimum frequency permitted by the driver */
  975. u8 max_freq_softlimit; /* Max frequency permitted by the driver */
  976. u8 max_freq; /* Maximum frequency, RP0 if not overclocking */
  977. u8 min_freq; /* AKA RPn. Minimum frequency */
  978. u8 idle_freq; /* Frequency to request when we are idle */
  979. u8 efficient_freq; /* AKA RPe. Pre-determined balanced frequency */
  980. u8 rp1_freq; /* "less than" RP0 power/freqency */
  981. u8 rp0_freq; /* Non-overclocked max frequency. */
  982. u8 up_threshold; /* Current %busy required to uplock */
  983. u8 down_threshold; /* Current %busy required to downclock */
  984. int last_adj;
  985. enum { LOW_POWER, BETWEEN, HIGH_POWER } power;
  986. spinlock_t client_lock;
  987. struct list_head clients;
  988. bool client_boost;
  989. bool enabled;
  990. struct delayed_work delayed_resume_work;
  991. unsigned boosts;
  992. struct intel_rps_client semaphores, mmioflips;
  993. /* manual wa residency calculations */
  994. struct intel_rps_ei up_ei, down_ei;
  995. /*
  996. * Protects RPS/RC6 register access and PCU communication.
  997. * Must be taken after struct_mutex if nested. Note that
  998. * this lock may be held for long periods of time when
  999. * talking to hw - so only take it when talking to hw!
  1000. */
  1001. struct mutex hw_lock;
  1002. };
  1003. /* defined intel_pm.c */
  1004. extern spinlock_t mchdev_lock;
  1005. struct intel_ilk_power_mgmt {
  1006. u8 cur_delay;
  1007. u8 min_delay;
  1008. u8 max_delay;
  1009. u8 fmax;
  1010. u8 fstart;
  1011. u64 last_count1;
  1012. unsigned long last_time1;
  1013. unsigned long chipset_power;
  1014. u64 last_count2;
  1015. u64 last_time2;
  1016. unsigned long gfx_power;
  1017. u8 corr;
  1018. int c_m;
  1019. int r_t;
  1020. };
  1021. struct drm_i915_private;
  1022. struct i915_power_well;
  1023. struct i915_power_well_ops {
  1024. /*
  1025. * Synchronize the well's hw state to match the current sw state, for
  1026. * example enable/disable it based on the current refcount. Called
  1027. * during driver init and resume time, possibly after first calling
  1028. * the enable/disable handlers.
  1029. */
  1030. void (*sync_hw)(struct drm_i915_private *dev_priv,
  1031. struct i915_power_well *power_well);
  1032. /*
  1033. * Enable the well and resources that depend on it (for example
  1034. * interrupts located on the well). Called after the 0->1 refcount
  1035. * transition.
  1036. */
  1037. void (*enable)(struct drm_i915_private *dev_priv,
  1038. struct i915_power_well *power_well);
  1039. /*
  1040. * Disable the well and resources that depend on it. Called after
  1041. * the 1->0 refcount transition.
  1042. */
  1043. void (*disable)(struct drm_i915_private *dev_priv,
  1044. struct i915_power_well *power_well);
  1045. /* Returns the hw enabled state. */
  1046. bool (*is_enabled)(struct drm_i915_private *dev_priv,
  1047. struct i915_power_well *power_well);
  1048. };
  1049. /* Power well structure for haswell */
  1050. struct i915_power_well {
  1051. const char *name;
  1052. bool always_on;
  1053. /* power well enable/disable usage count */
  1054. int count;
  1055. /* cached hw enabled state */
  1056. bool hw_enabled;
  1057. unsigned long domains;
  1058. unsigned long data;
  1059. const struct i915_power_well_ops *ops;
  1060. };
  1061. struct i915_power_domains {
  1062. /*
  1063. * Power wells needed for initialization at driver init and suspend
  1064. * time are on. They are kept on until after the first modeset.
  1065. */
  1066. bool init_power_on;
  1067. bool initializing;
  1068. int power_well_count;
  1069. struct mutex lock;
  1070. int domain_use_count[POWER_DOMAIN_NUM];
  1071. struct i915_power_well *power_wells;
  1072. };
  1073. #define MAX_L3_SLICES 2
  1074. struct intel_l3_parity {
  1075. u32 *remap_info[MAX_L3_SLICES];
  1076. struct work_struct error_work;
  1077. int which_slice;
  1078. };
  1079. struct i915_gem_mm {
  1080. /** Memory allocator for GTT stolen memory */
  1081. struct drm_mm stolen;
  1082. /** Protects the usage of the GTT stolen memory allocator. This is
  1083. * always the inner lock when overlapping with struct_mutex. */
  1084. struct mutex stolen_lock;
  1085. /** List of all objects in gtt_space. Used to restore gtt
  1086. * mappings on resume */
  1087. struct list_head bound_list;
  1088. /**
  1089. * List of objects which are not bound to the GTT (thus
  1090. * are idle and not used by the GPU) but still have
  1091. * (presumably uncached) pages still attached.
  1092. */
  1093. struct list_head unbound_list;
  1094. /** Usable portion of the GTT for GEM */
  1095. unsigned long stolen_base; /* limited to low memory (32-bit) */
  1096. /** PPGTT used for aliasing the PPGTT with the GTT */
  1097. struct i915_hw_ppgtt *aliasing_ppgtt;
  1098. struct notifier_block oom_notifier;
  1099. struct shrinker shrinker;
  1100. bool shrinker_no_lock_stealing;
  1101. /** LRU list of objects with fence regs on them. */
  1102. struct list_head fence_list;
  1103. /**
  1104. * We leave the user IRQ off as much as possible,
  1105. * but this means that requests will finish and never
  1106. * be retired once the system goes idle. Set a timer to
  1107. * fire periodically while the ring is running. When it
  1108. * fires, go retire requests.
  1109. */
  1110. struct delayed_work retire_work;
  1111. /**
  1112. * When we detect an idle GPU, we want to turn on
  1113. * powersaving features. So once we see that there
  1114. * are no more requests outstanding and no more
  1115. * arrive within a small period of time, we fire
  1116. * off the idle_work.
  1117. */
  1118. struct delayed_work idle_work;
  1119. /**
  1120. * Are we in a non-interruptible section of code like
  1121. * modesetting?
  1122. */
  1123. bool interruptible;
  1124. /**
  1125. * Is the GPU currently considered idle, or busy executing userspace
  1126. * requests? Whilst idle, we attempt to power down the hardware and
  1127. * display clocks. In order to reduce the effect on performance, there
  1128. * is a slight delay before we do so.
  1129. */
  1130. bool busy;
  1131. /* the indicator for dispatch video commands on two BSD rings */
  1132. int bsd_ring_dispatch_index;
  1133. /** Bit 6 swizzling required for X tiling */
  1134. uint32_t bit_6_swizzle_x;
  1135. /** Bit 6 swizzling required for Y tiling */
  1136. uint32_t bit_6_swizzle_y;
  1137. /* accounting, useful for userland debugging */
  1138. spinlock_t object_stat_lock;
  1139. size_t object_memory;
  1140. u32 object_count;
  1141. };
  1142. struct drm_i915_error_state_buf {
  1143. struct drm_i915_private *i915;
  1144. unsigned bytes;
  1145. unsigned size;
  1146. int err;
  1147. u8 *buf;
  1148. loff_t start;
  1149. loff_t pos;
  1150. };
  1151. struct i915_error_state_file_priv {
  1152. struct drm_device *dev;
  1153. struct drm_i915_error_state *error;
  1154. };
  1155. struct i915_gpu_error {
  1156. /* For hangcheck timer */
  1157. #define DRM_I915_HANGCHECK_PERIOD 1500 /* in ms */
  1158. #define DRM_I915_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD)
  1159. /* Hang gpu twice in this window and your context gets banned */
  1160. #define DRM_I915_CTX_BAN_PERIOD DIV_ROUND_UP(8*DRM_I915_HANGCHECK_PERIOD, 1000)
  1161. struct workqueue_struct *hangcheck_wq;
  1162. struct delayed_work hangcheck_work;
  1163. /* For reset and error_state handling. */
  1164. spinlock_t lock;
  1165. /* Protected by the above dev->gpu_error.lock. */
  1166. struct drm_i915_error_state *first_error;
  1167. unsigned long missed_irq_rings;
  1168. /**
  1169. * State variable controlling the reset flow and count
  1170. *
  1171. * This is a counter which gets incremented when reset is triggered,
  1172. * and again when reset has been handled. So odd values (lowest bit set)
  1173. * means that reset is in progress and even values that
  1174. * (reset_counter >> 1):th reset was successfully completed.
  1175. *
  1176. * If reset is not completed succesfully, the I915_WEDGE bit is
  1177. * set meaning that hardware is terminally sour and there is no
  1178. * recovery. All waiters on the reset_queue will be woken when
  1179. * that happens.
  1180. *
  1181. * This counter is used by the wait_seqno code to notice that reset
  1182. * event happened and it needs to restart the entire ioctl (since most
  1183. * likely the seqno it waited for won't ever signal anytime soon).
  1184. *
  1185. * This is important for lock-free wait paths, where no contended lock
  1186. * naturally enforces the correct ordering between the bail-out of the
  1187. * waiter and the gpu reset work code.
  1188. */
  1189. atomic_t reset_counter;
  1190. #define I915_RESET_IN_PROGRESS_FLAG 1
  1191. #define I915_WEDGED (1 << 31)
  1192. /**
  1193. * Waitqueue to signal when the reset has completed. Used by clients
  1194. * that wait for dev_priv->mm.wedged to settle.
  1195. */
  1196. wait_queue_head_t reset_queue;
  1197. /* Userspace knobs for gpu hang simulation;
  1198. * combines both a ring mask, and extra flags
  1199. */
  1200. u32 stop_rings;
  1201. #define I915_STOP_RING_ALLOW_BAN (1 << 31)
  1202. #define I915_STOP_RING_ALLOW_WARN (1 << 30)
  1203. /* For missed irq/seqno simulation. */
  1204. unsigned int test_irq_rings;
  1205. /* Used to prevent gem_check_wedged returning -EAGAIN during gpu reset */
  1206. bool reload_in_reset;
  1207. };
  1208. enum modeset_restore {
  1209. MODESET_ON_LID_OPEN,
  1210. MODESET_DONE,
  1211. MODESET_SUSPENDED,
  1212. };
  1213. #define DP_AUX_A 0x40
  1214. #define DP_AUX_B 0x10
  1215. #define DP_AUX_C 0x20
  1216. #define DP_AUX_D 0x30
  1217. #define DDC_PIN_B 0x05
  1218. #define DDC_PIN_C 0x04
  1219. #define DDC_PIN_D 0x06
  1220. struct ddi_vbt_port_info {
  1221. /*
  1222. * This is an index in the HDMI/DVI DDI buffer translation table.
  1223. * The special value HDMI_LEVEL_SHIFT_UNKNOWN means the VBT didn't
  1224. * populate this field.
  1225. */
  1226. #define HDMI_LEVEL_SHIFT_UNKNOWN 0xff
  1227. uint8_t hdmi_level_shift;
  1228. uint8_t supports_dvi:1;
  1229. uint8_t supports_hdmi:1;
  1230. uint8_t supports_dp:1;
  1231. uint8_t alternate_aux_channel;
  1232. uint8_t alternate_ddc_pin;
  1233. uint8_t dp_boost_level;
  1234. uint8_t hdmi_boost_level;
  1235. };
  1236. enum psr_lines_to_wait {
  1237. PSR_0_LINES_TO_WAIT = 0,
  1238. PSR_1_LINE_TO_WAIT,
  1239. PSR_4_LINES_TO_WAIT,
  1240. PSR_8_LINES_TO_WAIT
  1241. };
  1242. struct intel_vbt_data {
  1243. struct drm_display_mode *lfp_lvds_vbt_mode; /* if any */
  1244. struct drm_display_mode *sdvo_lvds_vbt_mode; /* if any */
  1245. /* Feature bits */
  1246. unsigned int int_tv_support:1;
  1247. unsigned int lvds_dither:1;
  1248. unsigned int lvds_vbt:1;
  1249. unsigned int int_crt_support:1;
  1250. unsigned int lvds_use_ssc:1;
  1251. unsigned int display_clock_mode:1;
  1252. unsigned int fdi_rx_polarity_inverted:1;
  1253. unsigned int has_mipi:1;
  1254. int lvds_ssc_freq;
  1255. unsigned int bios_lvds_val; /* initial [PCH_]LVDS reg val in VBIOS */
  1256. enum drrs_support_type drrs_type;
  1257. /* eDP */
  1258. int edp_rate;
  1259. int edp_lanes;
  1260. int edp_preemphasis;
  1261. int edp_vswing;
  1262. bool edp_initialized;
  1263. bool edp_support;
  1264. int edp_bpp;
  1265. struct edp_power_seq edp_pps;
  1266. struct {
  1267. bool full_link;
  1268. bool require_aux_wakeup;
  1269. int idle_frames;
  1270. enum psr_lines_to_wait lines_to_wait;
  1271. int tp1_wakeup_time;
  1272. int tp2_tp3_wakeup_time;
  1273. } psr;
  1274. struct {
  1275. u16 pwm_freq_hz;
  1276. bool present;
  1277. bool active_low_pwm;
  1278. u8 min_brightness; /* min_brightness/255 of max */
  1279. } backlight;
  1280. /* MIPI DSI */
  1281. struct {
  1282. u16 port;
  1283. u16 panel_id;
  1284. struct mipi_config *config;
  1285. struct mipi_pps_data *pps;
  1286. u8 seq_version;
  1287. u32 size;
  1288. u8 *data;
  1289. u8 *sequence[MIPI_SEQ_MAX];
  1290. } dsi;
  1291. int crt_ddc_pin;
  1292. int child_dev_num;
  1293. union child_device_config *child_dev;
  1294. struct ddi_vbt_port_info ddi_port_info[I915_MAX_PORTS];
  1295. };
  1296. enum intel_ddb_partitioning {
  1297. INTEL_DDB_PART_1_2,
  1298. INTEL_DDB_PART_5_6, /* IVB+ */
  1299. };
  1300. struct intel_wm_level {
  1301. bool enable;
  1302. uint32_t pri_val;
  1303. uint32_t spr_val;
  1304. uint32_t cur_val;
  1305. uint32_t fbc_val;
  1306. };
  1307. struct ilk_wm_values {
  1308. uint32_t wm_pipe[3];
  1309. uint32_t wm_lp[3];
  1310. uint32_t wm_lp_spr[3];
  1311. uint32_t wm_linetime[3];
  1312. bool enable_fbc_wm;
  1313. enum intel_ddb_partitioning partitioning;
  1314. };
  1315. struct vlv_pipe_wm {
  1316. uint16_t primary;
  1317. uint16_t sprite[2];
  1318. uint8_t cursor;
  1319. };
  1320. struct vlv_sr_wm {
  1321. uint16_t plane;
  1322. uint8_t cursor;
  1323. };
  1324. struct vlv_wm_values {
  1325. struct vlv_pipe_wm pipe[3];
  1326. struct vlv_sr_wm sr;
  1327. struct {
  1328. uint8_t cursor;
  1329. uint8_t sprite[2];
  1330. uint8_t primary;
  1331. } ddl[3];
  1332. uint8_t level;
  1333. bool cxsr;
  1334. };
  1335. struct skl_ddb_entry {
  1336. uint16_t start, end; /* in number of blocks, 'end' is exclusive */
  1337. };
  1338. static inline uint16_t skl_ddb_entry_size(const struct skl_ddb_entry *entry)
  1339. {
  1340. return entry->end - entry->start;
  1341. }
  1342. static inline bool skl_ddb_entry_equal(const struct skl_ddb_entry *e1,
  1343. const struct skl_ddb_entry *e2)
  1344. {
  1345. if (e1->start == e2->start && e1->end == e2->end)
  1346. return true;
  1347. return false;
  1348. }
  1349. struct skl_ddb_allocation {
  1350. struct skl_ddb_entry pipe[I915_MAX_PIPES];
  1351. struct skl_ddb_entry plane[I915_MAX_PIPES][I915_MAX_PLANES]; /* packed/uv */
  1352. struct skl_ddb_entry y_plane[I915_MAX_PIPES][I915_MAX_PLANES];
  1353. };
  1354. struct skl_wm_values {
  1355. bool dirty[I915_MAX_PIPES];
  1356. struct skl_ddb_allocation ddb;
  1357. uint32_t wm_linetime[I915_MAX_PIPES];
  1358. uint32_t plane[I915_MAX_PIPES][I915_MAX_PLANES][8];
  1359. uint32_t plane_trans[I915_MAX_PIPES][I915_MAX_PLANES];
  1360. };
  1361. struct skl_wm_level {
  1362. bool plane_en[I915_MAX_PLANES];
  1363. uint16_t plane_res_b[I915_MAX_PLANES];
  1364. uint8_t plane_res_l[I915_MAX_PLANES];
  1365. };
  1366. /*
  1367. * This struct helps tracking the state needed for runtime PM, which puts the
  1368. * device in PCI D3 state. Notice that when this happens, nothing on the
  1369. * graphics device works, even register access, so we don't get interrupts nor
  1370. * anything else.
  1371. *
  1372. * Every piece of our code that needs to actually touch the hardware needs to
  1373. * either call intel_runtime_pm_get or call intel_display_power_get with the
  1374. * appropriate power domain.
  1375. *
  1376. * Our driver uses the autosuspend delay feature, which means we'll only really
  1377. * suspend if we stay with zero refcount for a certain amount of time. The
  1378. * default value is currently very conservative (see intel_runtime_pm_enable), but
  1379. * it can be changed with the standard runtime PM files from sysfs.
  1380. *
  1381. * The irqs_disabled variable becomes true exactly after we disable the IRQs and
  1382. * goes back to false exactly before we reenable the IRQs. We use this variable
  1383. * to check if someone is trying to enable/disable IRQs while they're supposed
  1384. * to be disabled. This shouldn't happen and we'll print some error messages in
  1385. * case it happens.
  1386. *
  1387. * For more, read the Documentation/power/runtime_pm.txt.
  1388. */
  1389. struct i915_runtime_pm {
  1390. bool suspended;
  1391. bool irqs_enabled;
  1392. };
  1393. enum intel_pipe_crc_source {
  1394. INTEL_PIPE_CRC_SOURCE_NONE,
  1395. INTEL_PIPE_CRC_SOURCE_PLANE1,
  1396. INTEL_PIPE_CRC_SOURCE_PLANE2,
  1397. INTEL_PIPE_CRC_SOURCE_PF,
  1398. INTEL_PIPE_CRC_SOURCE_PIPE,
  1399. /* TV/DP on pre-gen5/vlv can't use the pipe source. */
  1400. INTEL_PIPE_CRC_SOURCE_TV,
  1401. INTEL_PIPE_CRC_SOURCE_DP_B,
  1402. INTEL_PIPE_CRC_SOURCE_DP_C,
  1403. INTEL_PIPE_CRC_SOURCE_DP_D,
  1404. INTEL_PIPE_CRC_SOURCE_AUTO,
  1405. INTEL_PIPE_CRC_SOURCE_MAX,
  1406. };
  1407. struct intel_pipe_crc_entry {
  1408. uint32_t frame;
  1409. uint32_t crc[5];
  1410. };
  1411. #define INTEL_PIPE_CRC_ENTRIES_NR 128
  1412. struct intel_pipe_crc {
  1413. spinlock_t lock;
  1414. bool opened; /* exclusive access to the result file */
  1415. struct intel_pipe_crc_entry *entries;
  1416. enum intel_pipe_crc_source source;
  1417. int head, tail;
  1418. wait_queue_head_t wq;
  1419. };
  1420. struct i915_frontbuffer_tracking {
  1421. struct mutex lock;
  1422. /*
  1423. * Tracking bits for delayed frontbuffer flushing du to gpu activity or
  1424. * scheduled flips.
  1425. */
  1426. unsigned busy_bits;
  1427. unsigned flip_bits;
  1428. };
  1429. struct i915_wa_reg {
  1430. i915_reg_t addr;
  1431. u32 value;
  1432. /* bitmask representing WA bits */
  1433. u32 mask;
  1434. };
  1435. #define I915_MAX_WA_REGS 16
  1436. struct i915_workarounds {
  1437. struct i915_wa_reg reg[I915_MAX_WA_REGS];
  1438. u32 count;
  1439. };
  1440. struct i915_virtual_gpu {
  1441. bool active;
  1442. };
  1443. struct i915_execbuffer_params {
  1444. struct drm_device *dev;
  1445. struct drm_file *file;
  1446. uint32_t dispatch_flags;
  1447. uint32_t args_batch_start_offset;
  1448. uint64_t batch_obj_vm_offset;
  1449. struct intel_engine_cs *ring;
  1450. struct drm_i915_gem_object *batch_obj;
  1451. struct intel_context *ctx;
  1452. struct drm_i915_gem_request *request;
  1453. };
  1454. /* used in computing the new watermarks state */
  1455. struct intel_wm_config {
  1456. unsigned int num_pipes_active;
  1457. bool sprites_enabled;
  1458. bool sprites_scaled;
  1459. };
  1460. struct drm_i915_private {
  1461. struct drm_device *dev;
  1462. struct kmem_cache *objects;
  1463. struct kmem_cache *vmas;
  1464. struct kmem_cache *requests;
  1465. const struct intel_device_info info;
  1466. int relative_constants_mode;
  1467. void __iomem *regs;
  1468. struct intel_uncore uncore;
  1469. struct i915_virtual_gpu vgpu;
  1470. struct intel_guc guc;
  1471. struct intel_csr csr;
  1472. struct intel_gmbus gmbus[GMBUS_NUM_PINS];
  1473. /** gmbus_mutex protects against concurrent usage of the single hw gmbus
  1474. * controller on different i2c buses. */
  1475. struct mutex gmbus_mutex;
  1476. /**
  1477. * Base address of the gmbus and gpio block.
  1478. */
  1479. uint32_t gpio_mmio_base;
  1480. /* MMIO base address for MIPI regs */
  1481. uint32_t mipi_mmio_base;
  1482. uint32_t psr_mmio_base;
  1483. wait_queue_head_t gmbus_wait_queue;
  1484. struct pci_dev *bridge_dev;
  1485. struct intel_engine_cs ring[I915_NUM_RINGS];
  1486. struct drm_i915_gem_object *semaphore_obj;
  1487. uint32_t last_seqno, next_seqno;
  1488. struct drm_dma_handle *status_page_dmah;
  1489. struct resource mch_res;
  1490. /* protects the irq masks */
  1491. spinlock_t irq_lock;
  1492. /* protects the mmio flip data */
  1493. spinlock_t mmio_flip_lock;
  1494. bool display_irqs_enabled;
  1495. /* To control wakeup latency, e.g. for irq-driven dp aux transfers. */
  1496. struct pm_qos_request pm_qos;
  1497. /* Sideband mailbox protection */
  1498. struct mutex sb_lock;
  1499. /** Cached value of IMR to avoid reads in updating the bitfield */
  1500. union {
  1501. u32 irq_mask;
  1502. u32 de_irq_mask[I915_MAX_PIPES];
  1503. };
  1504. u32 gt_irq_mask;
  1505. u32 pm_irq_mask;
  1506. u32 pm_rps_events;
  1507. u32 pipestat_irq_mask[I915_MAX_PIPES];
  1508. struct i915_hotplug hotplug;
  1509. struct i915_fbc fbc;
  1510. struct i915_drrs drrs;
  1511. struct intel_opregion opregion;
  1512. struct intel_vbt_data vbt;
  1513. bool preserve_bios_swizzle;
  1514. /* overlay */
  1515. struct intel_overlay *overlay;
  1516. /* backlight registers and fields in struct intel_panel */
  1517. struct mutex backlight_lock;
  1518. /* LVDS info */
  1519. bool no_aux_handshake;
  1520. /* protects panel power sequencer state */
  1521. struct mutex pps_mutex;
  1522. struct drm_i915_fence_reg fence_regs[I915_MAX_NUM_FENCES]; /* assume 965 */
  1523. int num_fence_regs; /* 8 on pre-965, 16 otherwise */
  1524. unsigned int fsb_freq, mem_freq, is_ddr3;
  1525. unsigned int skl_boot_cdclk;
  1526. unsigned int cdclk_freq, max_cdclk_freq;
  1527. unsigned int max_dotclk_freq;
  1528. unsigned int hpll_freq;
  1529. unsigned int czclk_freq;
  1530. /**
  1531. * wq - Driver workqueue for GEM.
  1532. *
  1533. * NOTE: Work items scheduled here are not allowed to grab any modeset
  1534. * locks, for otherwise the flushing done in the pageflip code will
  1535. * result in deadlocks.
  1536. */
  1537. struct workqueue_struct *wq;
  1538. /* Display functions */
  1539. struct drm_i915_display_funcs display;
  1540. /* PCH chipset type */
  1541. enum intel_pch pch_type;
  1542. unsigned short pch_id;
  1543. unsigned long quirks;
  1544. enum modeset_restore modeset_restore;
  1545. struct mutex modeset_restore_lock;
  1546. struct list_head vm_list; /* Global list of all address spaces */
  1547. struct i915_gtt gtt; /* VM representing the global address space */
  1548. struct i915_gem_mm mm;
  1549. DECLARE_HASHTABLE(mm_structs, 7);
  1550. struct mutex mm_lock;
  1551. /* Kernel Modesetting */
  1552. struct sdvo_device_mapping sdvo_mappings[2];
  1553. struct drm_crtc *plane_to_crtc_mapping[I915_MAX_PIPES];
  1554. struct drm_crtc *pipe_to_crtc_mapping[I915_MAX_PIPES];
  1555. wait_queue_head_t pending_flip_queue;
  1556. #ifdef CONFIG_DEBUG_FS
  1557. struct intel_pipe_crc pipe_crc[I915_MAX_PIPES];
  1558. #endif
  1559. int num_shared_dpll;
  1560. struct intel_shared_dpll shared_dplls[I915_NUM_PLLS];
  1561. int dpio_phy_iosf_port[I915_NUM_PHYS_VLV];
  1562. struct i915_workarounds workarounds;
  1563. /* Reclocking support */
  1564. bool render_reclock_avail;
  1565. struct i915_frontbuffer_tracking fb_tracking;
  1566. u16 orig_clock;
  1567. bool mchbar_need_disable;
  1568. struct intel_l3_parity l3_parity;
  1569. /* Cannot be determined by PCIID. You must always read a register. */
  1570. size_t ellc_size;
  1571. /* gen6+ rps state */
  1572. struct intel_gen6_power_mgmt rps;
  1573. /* ilk-only ips/rps state. Everything in here is protected by the global
  1574. * mchdev_lock in intel_pm.c */
  1575. struct intel_ilk_power_mgmt ips;
  1576. struct i915_power_domains power_domains;
  1577. struct i915_psr psr;
  1578. struct i915_gpu_error gpu_error;
  1579. struct drm_i915_gem_object *vlv_pctx;
  1580. #ifdef CONFIG_DRM_FBDEV_EMULATION
  1581. /* list of fbdev register on this device */
  1582. struct intel_fbdev *fbdev;
  1583. struct work_struct fbdev_suspend_work;
  1584. #endif
  1585. struct drm_property *broadcast_rgb_property;
  1586. struct drm_property *force_audio_property;
  1587. /* hda/i915 audio component */
  1588. struct i915_audio_component *audio_component;
  1589. bool audio_component_registered;
  1590. /**
  1591. * av_mutex - mutex for audio/video sync
  1592. *
  1593. */
  1594. struct mutex av_mutex;
  1595. uint32_t hw_context_size;
  1596. struct list_head context_list;
  1597. u32 fdi_rx_config;
  1598. u32 chv_phy_control;
  1599. u32 suspend_count;
  1600. bool suspended_to_idle;
  1601. struct i915_suspend_saved_registers regfile;
  1602. struct vlv_s0ix_state vlv_s0ix_state;
  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. /* Committed wm config */
  1622. struct intel_wm_config config;
  1623. /*
  1624. * The skl_wm_values structure is a bit too big for stack
  1625. * allocation, so we keep the staging struct where we store
  1626. * intermediate results here instead.
  1627. */
  1628. struct skl_wm_values skl_results;
  1629. /* current hardware state */
  1630. union {
  1631. struct ilk_wm_values hw;
  1632. struct skl_wm_values skl_hw;
  1633. struct vlv_wm_values vlv;
  1634. };
  1635. uint8_t max_level;
  1636. } wm;
  1637. struct i915_runtime_pm pm;
  1638. /* Abstract the submission mechanism (legacy ringbuffer or execlists) away */
  1639. struct {
  1640. int (*execbuf_submit)(struct i915_execbuffer_params *params,
  1641. struct drm_i915_gem_execbuffer2 *args,
  1642. struct list_head *vmas);
  1643. int (*init_rings)(struct drm_device *dev);
  1644. void (*cleanup_ring)(struct intel_engine_cs *ring);
  1645. void (*stop_ring)(struct intel_engine_cs *ring);
  1646. } gt;
  1647. bool edp_low_vswing;
  1648. /* perform PHY state sanity checks? */
  1649. bool chv_phy_assert[2];
  1650. /*
  1651. * NOTE: This is the dri1/ums dungeon, don't add stuff here. Your patch
  1652. * will be rejected. Instead look for a better place.
  1653. */
  1654. };
  1655. static inline struct drm_i915_private *to_i915(const struct drm_device *dev)
  1656. {
  1657. return dev->dev_private;
  1658. }
  1659. static inline struct drm_i915_private *dev_to_i915(struct device *dev)
  1660. {
  1661. return to_i915(dev_get_drvdata(dev));
  1662. }
  1663. static inline struct drm_i915_private *guc_to_i915(struct intel_guc *guc)
  1664. {
  1665. return container_of(guc, struct drm_i915_private, guc);
  1666. }
  1667. /* Iterate over initialised rings */
  1668. #define for_each_ring(ring__, dev_priv__, i__) \
  1669. for ((i__) = 0; (i__) < I915_NUM_RINGS; (i__)++) \
  1670. if (((ring__) = &(dev_priv__)->ring[(i__)]), intel_ring_initialized((ring__)))
  1671. enum hdmi_force_audio {
  1672. HDMI_AUDIO_OFF_DVI = -2, /* no aux data for HDMI-DVI converter */
  1673. HDMI_AUDIO_OFF, /* force turn off HDMI audio */
  1674. HDMI_AUDIO_AUTO, /* trust EDID */
  1675. HDMI_AUDIO_ON, /* force turn on HDMI audio */
  1676. };
  1677. #define I915_GTT_OFFSET_NONE ((u32)-1)
  1678. struct drm_i915_gem_object_ops {
  1679. /* Interface between the GEM object and its backing storage.
  1680. * get_pages() is called once prior to the use of the associated set
  1681. * of pages before to binding them into the GTT, and put_pages() is
  1682. * called after we no longer need them. As we expect there to be
  1683. * associated cost with migrating pages between the backing storage
  1684. * and making them available for the GPU (e.g. clflush), we may hold
  1685. * onto the pages after they are no longer referenced by the GPU
  1686. * in case they may be used again shortly (for example migrating the
  1687. * pages to a different memory domain within the GTT). put_pages()
  1688. * will therefore most likely be called when the object itself is
  1689. * being released or under memory pressure (where we attempt to
  1690. * reap pages for the shrinker).
  1691. */
  1692. int (*get_pages)(struct drm_i915_gem_object *);
  1693. void (*put_pages)(struct drm_i915_gem_object *);
  1694. int (*dmabuf_export)(struct drm_i915_gem_object *);
  1695. void (*release)(struct drm_i915_gem_object *);
  1696. };
  1697. /*
  1698. * Frontbuffer tracking bits. Set in obj->frontbuffer_bits while a gem bo is
  1699. * considered to be the frontbuffer for the given plane interface-wise. This
  1700. * doesn't mean that the hw necessarily already scans it out, but that any
  1701. * rendering (by the cpu or gpu) will land in the frontbuffer eventually.
  1702. *
  1703. * We have one bit per pipe and per scanout plane type.
  1704. */
  1705. #define INTEL_MAX_SPRITE_BITS_PER_PIPE 5
  1706. #define INTEL_FRONTBUFFER_BITS_PER_PIPE 8
  1707. #define INTEL_FRONTBUFFER_BITS \
  1708. (INTEL_FRONTBUFFER_BITS_PER_PIPE * I915_MAX_PIPES)
  1709. #define INTEL_FRONTBUFFER_PRIMARY(pipe) \
  1710. (1 << (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe)))
  1711. #define INTEL_FRONTBUFFER_CURSOR(pipe) \
  1712. (1 << (1 + (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))))
  1713. #define INTEL_FRONTBUFFER_SPRITE(pipe, plane) \
  1714. (1 << (2 + plane + (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))))
  1715. #define INTEL_FRONTBUFFER_OVERLAY(pipe) \
  1716. (1 << (2 + INTEL_MAX_SPRITE_BITS_PER_PIPE + (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))))
  1717. #define INTEL_FRONTBUFFER_ALL_MASK(pipe) \
  1718. (0xff << (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe)))
  1719. struct drm_i915_gem_object {
  1720. struct drm_gem_object base;
  1721. const struct drm_i915_gem_object_ops *ops;
  1722. /** List of VMAs backed by this object */
  1723. struct list_head vma_list;
  1724. /** Stolen memory for this object, instead of being backed by shmem. */
  1725. struct drm_mm_node *stolen;
  1726. struct list_head global_list;
  1727. struct list_head ring_list[I915_NUM_RINGS];
  1728. /** Used in execbuf to temporarily hold a ref */
  1729. struct list_head obj_exec_link;
  1730. struct list_head batch_pool_link;
  1731. /**
  1732. * This is set if the object is on the active lists (has pending
  1733. * rendering and so a non-zero seqno), and is not set if it i s on
  1734. * inactive (ready to be unbound) list.
  1735. */
  1736. unsigned int active:I915_NUM_RINGS;
  1737. /**
  1738. * This is set if the object has been written to since last bound
  1739. * to the GTT
  1740. */
  1741. unsigned int dirty:1;
  1742. /**
  1743. * Fence register bits (if any) for this object. Will be set
  1744. * as needed when mapped into the GTT.
  1745. * Protected by dev->struct_mutex.
  1746. */
  1747. signed int fence_reg:I915_MAX_NUM_FENCE_BITS;
  1748. /**
  1749. * Advice: are the backing pages purgeable?
  1750. */
  1751. unsigned int madv:2;
  1752. /**
  1753. * Current tiling mode for the object.
  1754. */
  1755. unsigned int tiling_mode:2;
  1756. /**
  1757. * Whether the tiling parameters for the currently associated fence
  1758. * register have changed. Note that for the purposes of tracking
  1759. * tiling changes we also treat the unfenced register, the register
  1760. * slot that the object occupies whilst it executes a fenced
  1761. * command (such as BLT on gen2/3), as a "fence".
  1762. */
  1763. unsigned int fence_dirty:1;
  1764. /**
  1765. * Is the object at the current location in the gtt mappable and
  1766. * fenceable? Used to avoid costly recalculations.
  1767. */
  1768. unsigned int map_and_fenceable:1;
  1769. /**
  1770. * Whether the current gtt mapping needs to be mappable (and isn't just
  1771. * mappable by accident). Track pin and fault separate for a more
  1772. * accurate mappable working set.
  1773. */
  1774. unsigned int fault_mappable:1;
  1775. /*
  1776. * Is the object to be mapped as read-only to the GPU
  1777. * Only honoured if hardware has relevant pte bit
  1778. */
  1779. unsigned long gt_ro:1;
  1780. unsigned int cache_level:3;
  1781. unsigned int cache_dirty:1;
  1782. unsigned int frontbuffer_bits:INTEL_FRONTBUFFER_BITS;
  1783. unsigned int pin_display;
  1784. struct sg_table *pages;
  1785. int pages_pin_count;
  1786. struct get_page {
  1787. struct scatterlist *sg;
  1788. int last;
  1789. } get_page;
  1790. /* prime dma-buf support */
  1791. void *dma_buf_vmapping;
  1792. int vmapping_count;
  1793. /** Breadcrumb of last rendering to the buffer.
  1794. * There can only be one writer, but we allow for multiple readers.
  1795. * If there is a writer that necessarily implies that all other
  1796. * read requests are complete - but we may only be lazily clearing
  1797. * the read requests. A read request is naturally the most recent
  1798. * request on a ring, so we may have two different write and read
  1799. * requests on one ring where the write request is older than the
  1800. * read request. This allows for the CPU to read from an active
  1801. * buffer by only waiting for the write to complete.
  1802. * */
  1803. struct drm_i915_gem_request *last_read_req[I915_NUM_RINGS];
  1804. struct drm_i915_gem_request *last_write_req;
  1805. /** Breadcrumb of last fenced GPU access to the buffer. */
  1806. struct drm_i915_gem_request *last_fenced_req;
  1807. /** Current tiling stride for the object, if it's tiled. */
  1808. uint32_t stride;
  1809. /** References from framebuffers, locks out tiling changes. */
  1810. unsigned long framebuffer_references;
  1811. /** Record of address bit 17 of each page at last unbind. */
  1812. unsigned long *bit_17;
  1813. union {
  1814. /** for phy allocated objects */
  1815. struct drm_dma_handle *phys_handle;
  1816. struct i915_gem_userptr {
  1817. uintptr_t ptr;
  1818. unsigned read_only :1;
  1819. unsigned workers :4;
  1820. #define I915_GEM_USERPTR_MAX_WORKERS 15
  1821. struct i915_mm_struct *mm;
  1822. struct i915_mmu_object *mmu_object;
  1823. struct work_struct *work;
  1824. } userptr;
  1825. };
  1826. };
  1827. #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
  1828. void i915_gem_track_fb(struct drm_i915_gem_object *old,
  1829. struct drm_i915_gem_object *new,
  1830. unsigned frontbuffer_bits);
  1831. /**
  1832. * Request queue structure.
  1833. *
  1834. * The request queue allows us to note sequence numbers that have been emitted
  1835. * and may be associated with active buffers to be retired.
  1836. *
  1837. * By keeping this list, we can avoid having to do questionable sequence
  1838. * number comparisons on buffer last_read|write_seqno. It also allows an
  1839. * emission time to be associated with the request for tracking how far ahead
  1840. * of the GPU the submission is.
  1841. *
  1842. * The requests are reference counted, so upon creation they should have an
  1843. * initial reference taken using kref_init
  1844. */
  1845. struct drm_i915_gem_request {
  1846. struct kref ref;
  1847. /** On Which ring this request was generated */
  1848. struct drm_i915_private *i915;
  1849. struct intel_engine_cs *ring;
  1850. /** GEM sequence number associated with this request. */
  1851. uint32_t seqno;
  1852. /** Position in the ringbuffer of the start of the request */
  1853. u32 head;
  1854. /**
  1855. * Position in the ringbuffer of the start of the postfix.
  1856. * This is required to calculate the maximum available ringbuffer
  1857. * space without overwriting the postfix.
  1858. */
  1859. u32 postfix;
  1860. /** Position in the ringbuffer of the end of the whole request */
  1861. u32 tail;
  1862. /**
  1863. * Context and ring buffer related to this request
  1864. * Contexts are refcounted, so when this request is associated with a
  1865. * context, we must increment the context's refcount, to guarantee that
  1866. * it persists while any request is linked to it. Requests themselves
  1867. * are also refcounted, so the request will only be freed when the last
  1868. * reference to it is dismissed, and the code in
  1869. * i915_gem_request_free() will then decrement the refcount on the
  1870. * context.
  1871. */
  1872. struct intel_context *ctx;
  1873. struct intel_ringbuffer *ringbuf;
  1874. /** Batch buffer related to this request if any (used for
  1875. error state dump only) */
  1876. struct drm_i915_gem_object *batch_obj;
  1877. /** Time at which this request was emitted, in jiffies. */
  1878. unsigned long emitted_jiffies;
  1879. /** global list entry for this request */
  1880. struct list_head list;
  1881. struct drm_i915_file_private *file_priv;
  1882. /** file_priv list entry for this request */
  1883. struct list_head client_list;
  1884. /** process identifier submitting this request */
  1885. struct pid *pid;
  1886. /**
  1887. * The ELSP only accepts two elements at a time, so we queue
  1888. * context/tail pairs on a given queue (ring->execlist_queue) until the
  1889. * hardware is available. The queue serves a double purpose: we also use
  1890. * it to keep track of the up to 2 contexts currently in the hardware
  1891. * (usually one in execution and the other queued up by the GPU): We
  1892. * only remove elements from the head of the queue when the hardware
  1893. * informs us that an element has been completed.
  1894. *
  1895. * All accesses to the queue are mediated by a spinlock
  1896. * (ring->execlist_lock).
  1897. */
  1898. /** Execlist link in the submission queue.*/
  1899. struct list_head execlist_link;
  1900. /** Execlists no. of times this request has been sent to the ELSP */
  1901. int elsp_submitted;
  1902. };
  1903. int i915_gem_request_alloc(struct intel_engine_cs *ring,
  1904. struct intel_context *ctx,
  1905. struct drm_i915_gem_request **req_out);
  1906. void i915_gem_request_cancel(struct drm_i915_gem_request *req);
  1907. void i915_gem_request_free(struct kref *req_ref);
  1908. int i915_gem_request_add_to_client(struct drm_i915_gem_request *req,
  1909. struct drm_file *file);
  1910. static inline uint32_t
  1911. i915_gem_request_get_seqno(struct drm_i915_gem_request *req)
  1912. {
  1913. return req ? req->seqno : 0;
  1914. }
  1915. static inline struct intel_engine_cs *
  1916. i915_gem_request_get_ring(struct drm_i915_gem_request *req)
  1917. {
  1918. return req ? req->ring : NULL;
  1919. }
  1920. static inline struct drm_i915_gem_request *
  1921. i915_gem_request_reference(struct drm_i915_gem_request *req)
  1922. {
  1923. if (req)
  1924. kref_get(&req->ref);
  1925. return req;
  1926. }
  1927. static inline void
  1928. i915_gem_request_unreference(struct drm_i915_gem_request *req)
  1929. {
  1930. WARN_ON(!mutex_is_locked(&req->ring->dev->struct_mutex));
  1931. kref_put(&req->ref, i915_gem_request_free);
  1932. }
  1933. static inline void
  1934. i915_gem_request_unreference__unlocked(struct drm_i915_gem_request *req)
  1935. {
  1936. struct drm_device *dev;
  1937. if (!req)
  1938. return;
  1939. dev = req->ring->dev;
  1940. if (kref_put_mutex(&req->ref, i915_gem_request_free, &dev->struct_mutex))
  1941. mutex_unlock(&dev->struct_mutex);
  1942. }
  1943. static inline void i915_gem_request_assign(struct drm_i915_gem_request **pdst,
  1944. struct drm_i915_gem_request *src)
  1945. {
  1946. if (src)
  1947. i915_gem_request_reference(src);
  1948. if (*pdst)
  1949. i915_gem_request_unreference(*pdst);
  1950. *pdst = src;
  1951. }
  1952. /*
  1953. * XXX: i915_gem_request_completed should be here but currently needs the
  1954. * definition of i915_seqno_passed() which is below. It will be moved in
  1955. * a later patch when the call to i915_seqno_passed() is obsoleted...
  1956. */
  1957. /*
  1958. * A command that requires special handling by the command parser.
  1959. */
  1960. struct drm_i915_cmd_descriptor {
  1961. /*
  1962. * Flags describing how the command parser processes the command.
  1963. *
  1964. * CMD_DESC_FIXED: The command has a fixed length if this is set,
  1965. * a length mask if not set
  1966. * CMD_DESC_SKIP: The command is allowed but does not follow the
  1967. * standard length encoding for the opcode range in
  1968. * which it falls
  1969. * CMD_DESC_REJECT: The command is never allowed
  1970. * CMD_DESC_REGISTER: The command should be checked against the
  1971. * register whitelist for the appropriate ring
  1972. * CMD_DESC_MASTER: The command is allowed if the submitting process
  1973. * is the DRM master
  1974. */
  1975. u32 flags;
  1976. #define CMD_DESC_FIXED (1<<0)
  1977. #define CMD_DESC_SKIP (1<<1)
  1978. #define CMD_DESC_REJECT (1<<2)
  1979. #define CMD_DESC_REGISTER (1<<3)
  1980. #define CMD_DESC_BITMASK (1<<4)
  1981. #define CMD_DESC_MASTER (1<<5)
  1982. /*
  1983. * The command's unique identification bits and the bitmask to get them.
  1984. * This isn't strictly the opcode field as defined in the spec and may
  1985. * also include type, subtype, and/or subop fields.
  1986. */
  1987. struct {
  1988. u32 value;
  1989. u32 mask;
  1990. } cmd;
  1991. /*
  1992. * The command's length. The command is either fixed length (i.e. does
  1993. * not include a length field) or has a length field mask. The flag
  1994. * CMD_DESC_FIXED indicates a fixed length. Otherwise, the command has
  1995. * a length mask. All command entries in a command table must include
  1996. * length information.
  1997. */
  1998. union {
  1999. u32 fixed;
  2000. u32 mask;
  2001. } length;
  2002. /*
  2003. * Describes where to find a register address in the command to check
  2004. * against the ring's register whitelist. Only valid if flags has the
  2005. * CMD_DESC_REGISTER bit set.
  2006. *
  2007. * A non-zero step value implies that the command may access multiple
  2008. * registers in sequence (e.g. LRI), in that case step gives the
  2009. * distance in dwords between individual offset fields.
  2010. */
  2011. struct {
  2012. u32 offset;
  2013. u32 mask;
  2014. u32 step;
  2015. } reg;
  2016. #define MAX_CMD_DESC_BITMASKS 3
  2017. /*
  2018. * Describes command checks where a particular dword is masked and
  2019. * compared against an expected value. If the command does not match
  2020. * the expected value, the parser rejects it. Only valid if flags has
  2021. * the CMD_DESC_BITMASK bit set. Only entries where mask is non-zero
  2022. * are valid.
  2023. *
  2024. * If the check specifies a non-zero condition_mask then the parser
  2025. * only performs the check when the bits specified by condition_mask
  2026. * are non-zero.
  2027. */
  2028. struct {
  2029. u32 offset;
  2030. u32 mask;
  2031. u32 expected;
  2032. u32 condition_offset;
  2033. u32 condition_mask;
  2034. } bits[MAX_CMD_DESC_BITMASKS];
  2035. };
  2036. /*
  2037. * A table of commands requiring special handling by the command parser.
  2038. *
  2039. * Each ring has an array of tables. Each table consists of an array of command
  2040. * descriptors, which must be sorted with command opcodes in ascending order.
  2041. */
  2042. struct drm_i915_cmd_table {
  2043. const struct drm_i915_cmd_descriptor *table;
  2044. int count;
  2045. };
  2046. /* Note that the (struct drm_i915_private *) cast is just to shut up gcc. */
  2047. #define __I915__(p) ({ \
  2048. struct drm_i915_private *__p; \
  2049. if (__builtin_types_compatible_p(typeof(*p), struct drm_i915_private)) \
  2050. __p = (struct drm_i915_private *)p; \
  2051. else if (__builtin_types_compatible_p(typeof(*p), struct drm_device)) \
  2052. __p = to_i915((struct drm_device *)p); \
  2053. else \
  2054. BUILD_BUG(); \
  2055. __p; \
  2056. })
  2057. #define INTEL_INFO(p) (&__I915__(p)->info)
  2058. #define INTEL_DEVID(p) (INTEL_INFO(p)->device_id)
  2059. #define INTEL_REVID(p) (__I915__(p)->dev->pdev->revision)
  2060. #define REVID_FOREVER 0xff
  2061. /*
  2062. * Return true if revision is in range [since,until] inclusive.
  2063. *
  2064. * Use 0 for open-ended since, and REVID_FOREVER for open-ended until.
  2065. */
  2066. #define IS_REVID(p, since, until) \
  2067. (INTEL_REVID(p) >= (since) && INTEL_REVID(p) <= (until))
  2068. #define IS_I830(dev) (INTEL_DEVID(dev) == 0x3577)
  2069. #define IS_845G(dev) (INTEL_DEVID(dev) == 0x2562)
  2070. #define IS_I85X(dev) (INTEL_INFO(dev)->is_i85x)
  2071. #define IS_I865G(dev) (INTEL_DEVID(dev) == 0x2572)
  2072. #define IS_I915G(dev) (INTEL_INFO(dev)->is_i915g)
  2073. #define IS_I915GM(dev) (INTEL_DEVID(dev) == 0x2592)
  2074. #define IS_I945G(dev) (INTEL_DEVID(dev) == 0x2772)
  2075. #define IS_I945GM(dev) (INTEL_INFO(dev)->is_i945gm)
  2076. #define IS_BROADWATER(dev) (INTEL_INFO(dev)->is_broadwater)
  2077. #define IS_CRESTLINE(dev) (INTEL_INFO(dev)->is_crestline)
  2078. #define IS_GM45(dev) (INTEL_DEVID(dev) == 0x2A42)
  2079. #define IS_G4X(dev) (INTEL_INFO(dev)->is_g4x)
  2080. #define IS_PINEVIEW_G(dev) (INTEL_DEVID(dev) == 0xa001)
  2081. #define IS_PINEVIEW_M(dev) (INTEL_DEVID(dev) == 0xa011)
  2082. #define IS_PINEVIEW(dev) (INTEL_INFO(dev)->is_pineview)
  2083. #define IS_G33(dev) (INTEL_INFO(dev)->is_g33)
  2084. #define IS_IRONLAKE_M(dev) (INTEL_DEVID(dev) == 0x0046)
  2085. #define IS_IVYBRIDGE(dev) (INTEL_INFO(dev)->is_ivybridge)
  2086. #define IS_IVB_GT1(dev) (INTEL_DEVID(dev) == 0x0156 || \
  2087. INTEL_DEVID(dev) == 0x0152 || \
  2088. INTEL_DEVID(dev) == 0x015a)
  2089. #define IS_VALLEYVIEW(dev) (INTEL_INFO(dev)->is_valleyview)
  2090. #define IS_CHERRYVIEW(dev) (INTEL_INFO(dev)->is_valleyview && IS_GEN8(dev))
  2091. #define IS_HASWELL(dev) (INTEL_INFO(dev)->is_haswell)
  2092. #define IS_BROADWELL(dev) (!INTEL_INFO(dev)->is_valleyview && IS_GEN8(dev))
  2093. #define IS_SKYLAKE(dev) (INTEL_INFO(dev)->is_skylake)
  2094. #define IS_BROXTON(dev) (INTEL_INFO(dev)->is_broxton)
  2095. #define IS_KABYLAKE(dev) (INTEL_INFO(dev)->is_kabylake)
  2096. #define IS_MOBILE(dev) (INTEL_INFO(dev)->is_mobile)
  2097. #define IS_HSW_EARLY_SDV(dev) (IS_HASWELL(dev) && \
  2098. (INTEL_DEVID(dev) & 0xFF00) == 0x0C00)
  2099. #define IS_BDW_ULT(dev) (IS_BROADWELL(dev) && \
  2100. ((INTEL_DEVID(dev) & 0xf) == 0x6 || \
  2101. (INTEL_DEVID(dev) & 0xf) == 0xb || \
  2102. (INTEL_DEVID(dev) & 0xf) == 0xe))
  2103. /* ULX machines are also considered ULT. */
  2104. #define IS_BDW_ULX(dev) (IS_BROADWELL(dev) && \
  2105. (INTEL_DEVID(dev) & 0xf) == 0xe)
  2106. #define IS_BDW_GT3(dev) (IS_BROADWELL(dev) && \
  2107. (INTEL_DEVID(dev) & 0x00F0) == 0x0020)
  2108. #define IS_HSW_ULT(dev) (IS_HASWELL(dev) && \
  2109. (INTEL_DEVID(dev) & 0xFF00) == 0x0A00)
  2110. #define IS_HSW_GT3(dev) (IS_HASWELL(dev) && \
  2111. (INTEL_DEVID(dev) & 0x00F0) == 0x0020)
  2112. /* ULX machines are also considered ULT. */
  2113. #define IS_HSW_ULX(dev) (INTEL_DEVID(dev) == 0x0A0E || \
  2114. INTEL_DEVID(dev) == 0x0A1E)
  2115. #define IS_SKL_ULT(dev) (INTEL_DEVID(dev) == 0x1906 || \
  2116. INTEL_DEVID(dev) == 0x1913 || \
  2117. INTEL_DEVID(dev) == 0x1916 || \
  2118. INTEL_DEVID(dev) == 0x1921 || \
  2119. INTEL_DEVID(dev) == 0x1926)
  2120. #define IS_SKL_ULX(dev) (INTEL_DEVID(dev) == 0x190E || \
  2121. INTEL_DEVID(dev) == 0x1915 || \
  2122. INTEL_DEVID(dev) == 0x191E)
  2123. #define IS_SKL_GT3(dev) (IS_SKYLAKE(dev) && \
  2124. (INTEL_DEVID(dev) & 0x00F0) == 0x0020)
  2125. #define IS_SKL_GT4(dev) (IS_SKYLAKE(dev) && \
  2126. (INTEL_DEVID(dev) & 0x00F0) == 0x0030)
  2127. #define IS_PRELIMINARY_HW(intel_info) ((intel_info)->is_preliminary)
  2128. #define SKL_REVID_A0 0x0
  2129. #define SKL_REVID_B0 0x1
  2130. #define SKL_REVID_C0 0x2
  2131. #define SKL_REVID_D0 0x3
  2132. #define SKL_REVID_E0 0x4
  2133. #define SKL_REVID_F0 0x5
  2134. #define IS_SKL_REVID(p, since, until) (IS_SKYLAKE(p) && IS_REVID(p, since, until))
  2135. #define BXT_REVID_A0 0x0
  2136. #define BXT_REVID_A1 0x1
  2137. #define BXT_REVID_B0 0x3
  2138. #define BXT_REVID_C0 0x9
  2139. #define IS_BXT_REVID(p, since, until) (IS_BROXTON(p) && IS_REVID(p, since, until))
  2140. /*
  2141. * The genX designation typically refers to the render engine, so render
  2142. * capability related checks should use IS_GEN, while display and other checks
  2143. * have their own (e.g. HAS_PCH_SPLIT for ILK+ display, IS_foo for particular
  2144. * chips, etc.).
  2145. */
  2146. #define IS_GEN2(dev) (INTEL_INFO(dev)->gen == 2)
  2147. #define IS_GEN3(dev) (INTEL_INFO(dev)->gen == 3)
  2148. #define IS_GEN4(dev) (INTEL_INFO(dev)->gen == 4)
  2149. #define IS_GEN5(dev) (INTEL_INFO(dev)->gen == 5)
  2150. #define IS_GEN6(dev) (INTEL_INFO(dev)->gen == 6)
  2151. #define IS_GEN7(dev) (INTEL_INFO(dev)->gen == 7)
  2152. #define IS_GEN8(dev) (INTEL_INFO(dev)->gen == 8)
  2153. #define IS_GEN9(dev) (INTEL_INFO(dev)->gen == 9)
  2154. #define RENDER_RING (1<<RCS)
  2155. #define BSD_RING (1<<VCS)
  2156. #define BLT_RING (1<<BCS)
  2157. #define VEBOX_RING (1<<VECS)
  2158. #define BSD2_RING (1<<VCS2)
  2159. #define HAS_BSD(dev) (INTEL_INFO(dev)->ring_mask & BSD_RING)
  2160. #define HAS_BSD2(dev) (INTEL_INFO(dev)->ring_mask & BSD2_RING)
  2161. #define HAS_BLT(dev) (INTEL_INFO(dev)->ring_mask & BLT_RING)
  2162. #define HAS_VEBOX(dev) (INTEL_INFO(dev)->ring_mask & VEBOX_RING)
  2163. #define HAS_LLC(dev) (INTEL_INFO(dev)->has_llc)
  2164. #define HAS_WT(dev) ((IS_HASWELL(dev) || IS_BROADWELL(dev)) && \
  2165. __I915__(dev)->ellc_size)
  2166. #define I915_NEED_GFX_HWS(dev) (INTEL_INFO(dev)->need_gfx_hws)
  2167. #define HAS_HW_CONTEXTS(dev) (INTEL_INFO(dev)->gen >= 6)
  2168. #define HAS_LOGICAL_RING_CONTEXTS(dev) (INTEL_INFO(dev)->gen >= 8)
  2169. #define USES_PPGTT(dev) (i915.enable_ppgtt)
  2170. #define USES_FULL_PPGTT(dev) (i915.enable_ppgtt >= 2)
  2171. #define USES_FULL_48BIT_PPGTT(dev) (i915.enable_ppgtt == 3)
  2172. #define HAS_OVERLAY(dev) (INTEL_INFO(dev)->has_overlay)
  2173. #define OVERLAY_NEEDS_PHYSICAL(dev) (INTEL_INFO(dev)->overlay_needs_physical)
  2174. /* Early gen2 have a totally busted CS tlb and require pinned batches. */
  2175. #define HAS_BROKEN_CS_TLB(dev) (IS_I830(dev) || IS_845G(dev))
  2176. /*
  2177. * dp aux and gmbus irq on gen4 seems to be able to generate legacy interrupts
  2178. * even when in MSI mode. This results in spurious interrupt warnings if the
  2179. * legacy irq no. is shared with another device. The kernel then disables that
  2180. * interrupt source and so prevents the other device from working properly.
  2181. */
  2182. #define HAS_AUX_IRQ(dev) (INTEL_INFO(dev)->gen >= 5)
  2183. #define HAS_GMBUS_IRQ(dev) (INTEL_INFO(dev)->gen >= 5)
  2184. /* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte
  2185. * rows, which changed the alignment requirements and fence programming.
  2186. */
  2187. #define HAS_128_BYTE_Y_TILING(dev) (!IS_GEN2(dev) && !(IS_I915G(dev) || \
  2188. IS_I915GM(dev)))
  2189. #define SUPPORTS_TV(dev) (INTEL_INFO(dev)->supports_tv)
  2190. #define I915_HAS_HOTPLUG(dev) (INTEL_INFO(dev)->has_hotplug)
  2191. #define HAS_FW_BLC(dev) (INTEL_INFO(dev)->gen > 2)
  2192. #define HAS_PIPE_CXSR(dev) (INTEL_INFO(dev)->has_pipe_cxsr)
  2193. #define HAS_FBC(dev) (INTEL_INFO(dev)->has_fbc)
  2194. #define HAS_IPS(dev) (IS_HSW_ULT(dev) || IS_BROADWELL(dev))
  2195. #define HAS_DP_MST(dev) (IS_HASWELL(dev) || IS_BROADWELL(dev) || \
  2196. INTEL_INFO(dev)->gen >= 9)
  2197. #define HAS_DDI(dev) (INTEL_INFO(dev)->has_ddi)
  2198. #define HAS_FPGA_DBG_UNCLAIMED(dev) (INTEL_INFO(dev)->has_fpga_dbg)
  2199. #define HAS_PSR(dev) (IS_HASWELL(dev) || IS_BROADWELL(dev) || \
  2200. IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev) || \
  2201. IS_SKYLAKE(dev) || IS_KABYLAKE(dev))
  2202. #define HAS_RUNTIME_PM(dev) (IS_GEN6(dev) || IS_HASWELL(dev) || \
  2203. IS_BROADWELL(dev) || IS_VALLEYVIEW(dev) || \
  2204. IS_SKYLAKE(dev) || IS_KABYLAKE(dev))
  2205. #define HAS_RC6(dev) (INTEL_INFO(dev)->gen >= 6)
  2206. #define HAS_RC6p(dev) (INTEL_INFO(dev)->gen == 6 || IS_IVYBRIDGE(dev))
  2207. #define HAS_CSR(dev) (IS_GEN9(dev))
  2208. #define HAS_GUC_UCODE(dev) (IS_GEN9(dev))
  2209. #define HAS_GUC_SCHED(dev) (IS_GEN9(dev))
  2210. #define HAS_RESOURCE_STREAMER(dev) (IS_HASWELL(dev) || \
  2211. INTEL_INFO(dev)->gen >= 8)
  2212. #define HAS_CORE_RING_FREQ(dev) (INTEL_INFO(dev)->gen >= 6 && \
  2213. !IS_VALLEYVIEW(dev) && !IS_BROXTON(dev))
  2214. #define INTEL_PCH_DEVICE_ID_MASK 0xff00
  2215. #define INTEL_PCH_IBX_DEVICE_ID_TYPE 0x3b00
  2216. #define INTEL_PCH_CPT_DEVICE_ID_TYPE 0x1c00
  2217. #define INTEL_PCH_PPT_DEVICE_ID_TYPE 0x1e00
  2218. #define INTEL_PCH_LPT_DEVICE_ID_TYPE 0x8c00
  2219. #define INTEL_PCH_LPT_LP_DEVICE_ID_TYPE 0x9c00
  2220. #define INTEL_PCH_SPT_DEVICE_ID_TYPE 0xA100
  2221. #define INTEL_PCH_SPT_LP_DEVICE_ID_TYPE 0x9D00
  2222. #define INTEL_PCH_P2X_DEVICE_ID_TYPE 0x7100
  2223. #define INTEL_PCH_QEMU_DEVICE_ID_TYPE 0x2900 /* qemu q35 has 2918 */
  2224. #define INTEL_PCH_TYPE(dev) (__I915__(dev)->pch_type)
  2225. #define HAS_PCH_SPT(dev) (INTEL_PCH_TYPE(dev) == PCH_SPT)
  2226. #define HAS_PCH_LPT(dev) (INTEL_PCH_TYPE(dev) == PCH_LPT)
  2227. #define HAS_PCH_LPT_LP(dev) (__I915__(dev)->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE)
  2228. #define HAS_PCH_LPT_H(dev) (__I915__(dev)->pch_id == INTEL_PCH_LPT_DEVICE_ID_TYPE)
  2229. #define HAS_PCH_CPT(dev) (INTEL_PCH_TYPE(dev) == PCH_CPT)
  2230. #define HAS_PCH_IBX(dev) (INTEL_PCH_TYPE(dev) == PCH_IBX)
  2231. #define HAS_PCH_NOP(dev) (INTEL_PCH_TYPE(dev) == PCH_NOP)
  2232. #define HAS_PCH_SPLIT(dev) (INTEL_PCH_TYPE(dev) != PCH_NONE)
  2233. #define HAS_GMCH_DISPLAY(dev) (INTEL_INFO(dev)->gen < 5 || IS_VALLEYVIEW(dev))
  2234. /* DPF == dynamic parity feature */
  2235. #define HAS_L3_DPF(dev) (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
  2236. #define NUM_L3_SLICES(dev) (IS_HSW_GT3(dev) ? 2 : HAS_L3_DPF(dev))
  2237. #define GT_FREQUENCY_MULTIPLIER 50
  2238. #define GEN9_FREQ_SCALER 3
  2239. #include "i915_trace.h"
  2240. extern const struct drm_ioctl_desc i915_ioctls[];
  2241. extern int i915_max_ioctl;
  2242. extern int i915_suspend_switcheroo(struct drm_device *dev, pm_message_t state);
  2243. extern int i915_resume_switcheroo(struct drm_device *dev);
  2244. /* i915_params.c */
  2245. struct i915_params {
  2246. int modeset;
  2247. int panel_ignore_lid;
  2248. int semaphores;
  2249. int lvds_channel_mode;
  2250. int panel_use_ssc;
  2251. int vbt_sdvo_panel_type;
  2252. int enable_rc6;
  2253. int enable_dc;
  2254. int enable_fbc;
  2255. int enable_ppgtt;
  2256. int enable_execlists;
  2257. int enable_psr;
  2258. unsigned int preliminary_hw_support;
  2259. int disable_power_well;
  2260. int enable_ips;
  2261. int invert_brightness;
  2262. int enable_cmd_parser;
  2263. /* leave bools at the end to not create holes */
  2264. bool enable_hangcheck;
  2265. bool fastboot;
  2266. bool prefault_disable;
  2267. bool load_detect_test;
  2268. bool reset;
  2269. bool disable_display;
  2270. bool disable_vtd_wa;
  2271. bool enable_guc_submission;
  2272. int guc_log_level;
  2273. int use_mmio_flip;
  2274. int mmio_debug;
  2275. bool verbose_state_checks;
  2276. bool nuclear_pageflip;
  2277. int edp_vswing;
  2278. };
  2279. extern struct i915_params i915 __read_mostly;
  2280. /* i915_dma.c */
  2281. extern int i915_driver_load(struct drm_device *, unsigned long flags);
  2282. extern int i915_driver_unload(struct drm_device *);
  2283. extern int i915_driver_open(struct drm_device *dev, struct drm_file *file);
  2284. extern void i915_driver_lastclose(struct drm_device * dev);
  2285. extern void i915_driver_preclose(struct drm_device *dev,
  2286. struct drm_file *file);
  2287. extern void i915_driver_postclose(struct drm_device *dev,
  2288. struct drm_file *file);
  2289. #ifdef CONFIG_COMPAT
  2290. extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
  2291. unsigned long arg);
  2292. #endif
  2293. extern int intel_gpu_reset(struct drm_device *dev);
  2294. extern bool intel_has_gpu_reset(struct drm_device *dev);
  2295. extern int i915_reset(struct drm_device *dev);
  2296. extern unsigned long i915_chipset_val(struct drm_i915_private *dev_priv);
  2297. extern unsigned long i915_mch_val(struct drm_i915_private *dev_priv);
  2298. extern unsigned long i915_gfx_val(struct drm_i915_private *dev_priv);
  2299. extern void i915_update_gfx_val(struct drm_i915_private *dev_priv);
  2300. int vlv_force_gfx_clock(struct drm_i915_private *dev_priv, bool on);
  2301. /* intel_hotplug.c */
  2302. void intel_hpd_irq_handler(struct drm_device *dev, u32 pin_mask, u32 long_mask);
  2303. void intel_hpd_init(struct drm_i915_private *dev_priv);
  2304. void intel_hpd_init_work(struct drm_i915_private *dev_priv);
  2305. void intel_hpd_cancel_work(struct drm_i915_private *dev_priv);
  2306. bool intel_hpd_pin_to_port(enum hpd_pin pin, enum port *port);
  2307. /* i915_irq.c */
  2308. void i915_queue_hangcheck(struct drm_device *dev);
  2309. __printf(3, 4)
  2310. void i915_handle_error(struct drm_device *dev, bool wedged,
  2311. const char *fmt, ...);
  2312. extern void intel_irq_init(struct drm_i915_private *dev_priv);
  2313. int intel_irq_install(struct drm_i915_private *dev_priv);
  2314. void intel_irq_uninstall(struct drm_i915_private *dev_priv);
  2315. extern void intel_uncore_sanitize(struct drm_device *dev);
  2316. extern void intel_uncore_early_sanitize(struct drm_device *dev,
  2317. bool restore_forcewake);
  2318. extern void intel_uncore_init(struct drm_device *dev);
  2319. extern void intel_uncore_check_errors(struct drm_device *dev);
  2320. extern void intel_uncore_fini(struct drm_device *dev);
  2321. extern void intel_uncore_forcewake_reset(struct drm_device *dev, bool restore);
  2322. const char *intel_uncore_forcewake_domain_to_str(const enum forcewake_domain_id id);
  2323. void intel_uncore_forcewake_get(struct drm_i915_private *dev_priv,
  2324. enum forcewake_domains domains);
  2325. void intel_uncore_forcewake_put(struct drm_i915_private *dev_priv,
  2326. enum forcewake_domains domains);
  2327. /* Like above but the caller must manage the uncore.lock itself.
  2328. * Must be used with I915_READ_FW and friends.
  2329. */
  2330. void intel_uncore_forcewake_get__locked(struct drm_i915_private *dev_priv,
  2331. enum forcewake_domains domains);
  2332. void intel_uncore_forcewake_put__locked(struct drm_i915_private *dev_priv,
  2333. enum forcewake_domains domains);
  2334. void assert_forcewakes_inactive(struct drm_i915_private *dev_priv);
  2335. static inline bool intel_vgpu_active(struct drm_device *dev)
  2336. {
  2337. return to_i915(dev)->vgpu.active;
  2338. }
  2339. void
  2340. i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  2341. u32 status_mask);
  2342. void
  2343. i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  2344. u32 status_mask);
  2345. void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv);
  2346. void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv);
  2347. void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
  2348. uint32_t mask,
  2349. uint32_t bits);
  2350. void ilk_update_display_irq(struct drm_i915_private *dev_priv,
  2351. uint32_t interrupt_mask,
  2352. uint32_t enabled_irq_mask);
  2353. static inline void
  2354. ilk_enable_display_irq(struct drm_i915_private *dev_priv, uint32_t bits)
  2355. {
  2356. ilk_update_display_irq(dev_priv, bits, bits);
  2357. }
  2358. static inline void
  2359. ilk_disable_display_irq(struct drm_i915_private *dev_priv, uint32_t bits)
  2360. {
  2361. ilk_update_display_irq(dev_priv, bits, 0);
  2362. }
  2363. void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
  2364. enum pipe pipe,
  2365. uint32_t interrupt_mask,
  2366. uint32_t enabled_irq_mask);
  2367. static inline void bdw_enable_pipe_irq(struct drm_i915_private *dev_priv,
  2368. enum pipe pipe, uint32_t bits)
  2369. {
  2370. bdw_update_pipe_irq(dev_priv, pipe, bits, bits);
  2371. }
  2372. static inline void bdw_disable_pipe_irq(struct drm_i915_private *dev_priv,
  2373. enum pipe pipe, uint32_t bits)
  2374. {
  2375. bdw_update_pipe_irq(dev_priv, pipe, bits, 0);
  2376. }
  2377. void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
  2378. uint32_t interrupt_mask,
  2379. uint32_t enabled_irq_mask);
  2380. static inline void
  2381. ibx_enable_display_interrupt(struct drm_i915_private *dev_priv, uint32_t bits)
  2382. {
  2383. ibx_display_interrupt_update(dev_priv, bits, bits);
  2384. }
  2385. static inline void
  2386. ibx_disable_display_interrupt(struct drm_i915_private *dev_priv, uint32_t bits)
  2387. {
  2388. ibx_display_interrupt_update(dev_priv, bits, 0);
  2389. }
  2390. /* i915_gem.c */
  2391. int i915_gem_create_ioctl(struct drm_device *dev, void *data,
  2392. struct drm_file *file_priv);
  2393. int i915_gem_pread_ioctl(struct drm_device *dev, void *data,
  2394. struct drm_file *file_priv);
  2395. int i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  2396. struct drm_file *file_priv);
  2397. int i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
  2398. struct drm_file *file_priv);
  2399. int i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data,
  2400. struct drm_file *file_priv);
  2401. int i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  2402. struct drm_file *file_priv);
  2403. int i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
  2404. struct drm_file *file_priv);
  2405. void i915_gem_execbuffer_move_to_active(struct list_head *vmas,
  2406. struct drm_i915_gem_request *req);
  2407. void i915_gem_execbuffer_retire_commands(struct i915_execbuffer_params *params);
  2408. int i915_gem_ringbuffer_submission(struct i915_execbuffer_params *params,
  2409. struct drm_i915_gem_execbuffer2 *args,
  2410. struct list_head *vmas);
  2411. int i915_gem_execbuffer(struct drm_device *dev, void *data,
  2412. struct drm_file *file_priv);
  2413. int i915_gem_execbuffer2(struct drm_device *dev, void *data,
  2414. struct drm_file *file_priv);
  2415. int i915_gem_busy_ioctl(struct drm_device *dev, void *data,
  2416. struct drm_file *file_priv);
  2417. int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data,
  2418. struct drm_file *file);
  2419. int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
  2420. struct drm_file *file);
  2421. int i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
  2422. struct drm_file *file_priv);
  2423. int i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
  2424. struct drm_file *file_priv);
  2425. int i915_gem_set_tiling(struct drm_device *dev, void *data,
  2426. struct drm_file *file_priv);
  2427. int i915_gem_get_tiling(struct drm_device *dev, void *data,
  2428. struct drm_file *file_priv);
  2429. int i915_gem_init_userptr(struct drm_device *dev);
  2430. int i915_gem_userptr_ioctl(struct drm_device *dev, void *data,
  2431. struct drm_file *file);
  2432. int i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
  2433. struct drm_file *file_priv);
  2434. int i915_gem_wait_ioctl(struct drm_device *dev, void *data,
  2435. struct drm_file *file_priv);
  2436. void i915_gem_load(struct drm_device *dev);
  2437. void *i915_gem_object_alloc(struct drm_device *dev);
  2438. void i915_gem_object_free(struct drm_i915_gem_object *obj);
  2439. void i915_gem_object_init(struct drm_i915_gem_object *obj,
  2440. const struct drm_i915_gem_object_ops *ops);
  2441. struct drm_i915_gem_object *i915_gem_alloc_object(struct drm_device *dev,
  2442. size_t size);
  2443. struct drm_i915_gem_object *i915_gem_object_create_from_data(
  2444. struct drm_device *dev, const void *data, size_t size);
  2445. void i915_gem_free_object(struct drm_gem_object *obj);
  2446. void i915_gem_vma_destroy(struct i915_vma *vma);
  2447. /* Flags used by pin/bind&friends. */
  2448. #define PIN_MAPPABLE (1<<0)
  2449. #define PIN_NONBLOCK (1<<1)
  2450. #define PIN_GLOBAL (1<<2)
  2451. #define PIN_OFFSET_BIAS (1<<3)
  2452. #define PIN_USER (1<<4)
  2453. #define PIN_UPDATE (1<<5)
  2454. #define PIN_ZONE_4G (1<<6)
  2455. #define PIN_HIGH (1<<7)
  2456. #define PIN_OFFSET_MASK (~4095)
  2457. int __must_check
  2458. i915_gem_object_pin(struct drm_i915_gem_object *obj,
  2459. struct i915_address_space *vm,
  2460. uint32_t alignment,
  2461. uint64_t flags);
  2462. int __must_check
  2463. i915_gem_object_ggtt_pin(struct drm_i915_gem_object *obj,
  2464. const struct i915_ggtt_view *view,
  2465. uint32_t alignment,
  2466. uint64_t flags);
  2467. int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level,
  2468. u32 flags);
  2469. int __must_check i915_vma_unbind(struct i915_vma *vma);
  2470. /*
  2471. * BEWARE: Do not use the function below unless you can _absolutely_
  2472. * _guarantee_ VMA in question is _not in use_ anywhere.
  2473. */
  2474. int __must_check __i915_vma_unbind_no_wait(struct i915_vma *vma);
  2475. int i915_gem_object_put_pages(struct drm_i915_gem_object *obj);
  2476. void i915_gem_release_all_mmaps(struct drm_i915_private *dev_priv);
  2477. void i915_gem_release_mmap(struct drm_i915_gem_object *obj);
  2478. int i915_gem_obj_prepare_shmem_read(struct drm_i915_gem_object *obj,
  2479. int *needs_clflush);
  2480. int __must_check i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
  2481. static inline int __sg_page_count(struct scatterlist *sg)
  2482. {
  2483. return sg->length >> PAGE_SHIFT;
  2484. }
  2485. static inline struct page *
  2486. i915_gem_object_get_page(struct drm_i915_gem_object *obj, int n)
  2487. {
  2488. if (WARN_ON(n >= obj->base.size >> PAGE_SHIFT))
  2489. return NULL;
  2490. if (n < obj->get_page.last) {
  2491. obj->get_page.sg = obj->pages->sgl;
  2492. obj->get_page.last = 0;
  2493. }
  2494. while (obj->get_page.last + __sg_page_count(obj->get_page.sg) <= n) {
  2495. obj->get_page.last += __sg_page_count(obj->get_page.sg++);
  2496. if (unlikely(sg_is_chain(obj->get_page.sg)))
  2497. obj->get_page.sg = sg_chain_ptr(obj->get_page.sg);
  2498. }
  2499. return nth_page(sg_page(obj->get_page.sg), n - obj->get_page.last);
  2500. }
  2501. static inline void i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
  2502. {
  2503. BUG_ON(obj->pages == NULL);
  2504. obj->pages_pin_count++;
  2505. }
  2506. static inline void i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj)
  2507. {
  2508. BUG_ON(obj->pages_pin_count == 0);
  2509. obj->pages_pin_count--;
  2510. }
  2511. int __must_check i915_mutex_lock_interruptible(struct drm_device *dev);
  2512. int i915_gem_object_sync(struct drm_i915_gem_object *obj,
  2513. struct intel_engine_cs *to,
  2514. struct drm_i915_gem_request **to_req);
  2515. void i915_vma_move_to_active(struct i915_vma *vma,
  2516. struct drm_i915_gem_request *req);
  2517. int i915_gem_dumb_create(struct drm_file *file_priv,
  2518. struct drm_device *dev,
  2519. struct drm_mode_create_dumb *args);
  2520. int i915_gem_mmap_gtt(struct drm_file *file_priv, struct drm_device *dev,
  2521. uint32_t handle, uint64_t *offset);
  2522. /**
  2523. * Returns true if seq1 is later than seq2.
  2524. */
  2525. static inline bool
  2526. i915_seqno_passed(uint32_t seq1, uint32_t seq2)
  2527. {
  2528. return (int32_t)(seq1 - seq2) >= 0;
  2529. }
  2530. static inline bool i915_gem_request_completed(struct drm_i915_gem_request *req,
  2531. bool lazy_coherency)
  2532. {
  2533. u32 seqno;
  2534. BUG_ON(req == NULL);
  2535. seqno = req->ring->get_seqno(req->ring, lazy_coherency);
  2536. return i915_seqno_passed(seqno, req->seqno);
  2537. }
  2538. int __must_check i915_gem_get_seqno(struct drm_device *dev, u32 *seqno);
  2539. int __must_check i915_gem_set_seqno(struct drm_device *dev, u32 seqno);
  2540. struct drm_i915_gem_request *
  2541. i915_gem_find_active_request(struct intel_engine_cs *ring);
  2542. bool i915_gem_retire_requests(struct drm_device *dev);
  2543. void i915_gem_retire_requests_ring(struct intel_engine_cs *ring);
  2544. int __must_check i915_gem_check_wedge(struct i915_gpu_error *error,
  2545. bool interruptible);
  2546. static inline bool i915_reset_in_progress(struct i915_gpu_error *error)
  2547. {
  2548. return unlikely(atomic_read(&error->reset_counter)
  2549. & (I915_RESET_IN_PROGRESS_FLAG | I915_WEDGED));
  2550. }
  2551. static inline bool i915_terminally_wedged(struct i915_gpu_error *error)
  2552. {
  2553. return atomic_read(&error->reset_counter) & I915_WEDGED;
  2554. }
  2555. static inline u32 i915_reset_count(struct i915_gpu_error *error)
  2556. {
  2557. return ((atomic_read(&error->reset_counter) & ~I915_WEDGED) + 1) / 2;
  2558. }
  2559. static inline bool i915_stop_ring_allow_ban(struct drm_i915_private *dev_priv)
  2560. {
  2561. return dev_priv->gpu_error.stop_rings == 0 ||
  2562. dev_priv->gpu_error.stop_rings & I915_STOP_RING_ALLOW_BAN;
  2563. }
  2564. static inline bool i915_stop_ring_allow_warn(struct drm_i915_private *dev_priv)
  2565. {
  2566. return dev_priv->gpu_error.stop_rings == 0 ||
  2567. dev_priv->gpu_error.stop_rings & I915_STOP_RING_ALLOW_WARN;
  2568. }
  2569. void i915_gem_reset(struct drm_device *dev);
  2570. bool i915_gem_clflush_object(struct drm_i915_gem_object *obj, bool force);
  2571. int __must_check i915_gem_init(struct drm_device *dev);
  2572. int i915_gem_init_rings(struct drm_device *dev);
  2573. int __must_check i915_gem_init_hw(struct drm_device *dev);
  2574. int i915_gem_l3_remap(struct drm_i915_gem_request *req, int slice);
  2575. void i915_gem_init_swizzling(struct drm_device *dev);
  2576. void i915_gem_cleanup_ringbuffer(struct drm_device *dev);
  2577. int __must_check i915_gpu_idle(struct drm_device *dev);
  2578. int __must_check i915_gem_suspend(struct drm_device *dev);
  2579. void __i915_add_request(struct drm_i915_gem_request *req,
  2580. struct drm_i915_gem_object *batch_obj,
  2581. bool flush_caches);
  2582. #define i915_add_request(req) \
  2583. __i915_add_request(req, NULL, true)
  2584. #define i915_add_request_no_flush(req) \
  2585. __i915_add_request(req, NULL, false)
  2586. int __i915_wait_request(struct drm_i915_gem_request *req,
  2587. unsigned reset_counter,
  2588. bool interruptible,
  2589. s64 *timeout,
  2590. struct intel_rps_client *rps);
  2591. int __must_check i915_wait_request(struct drm_i915_gem_request *req);
  2592. int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
  2593. int __must_check
  2594. i915_gem_object_wait_rendering(struct drm_i915_gem_object *obj,
  2595. bool readonly);
  2596. int __must_check
  2597. i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj,
  2598. bool write);
  2599. int __must_check
  2600. i915_gem_object_set_to_cpu_domain(struct drm_i915_gem_object *obj, bool write);
  2601. int __must_check
  2602. i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
  2603. u32 alignment,
  2604. const struct i915_ggtt_view *view);
  2605. void i915_gem_object_unpin_from_display_plane(struct drm_i915_gem_object *obj,
  2606. const struct i915_ggtt_view *view);
  2607. int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj,
  2608. int align);
  2609. int i915_gem_open(struct drm_device *dev, struct drm_file *file);
  2610. void i915_gem_release(struct drm_device *dev, struct drm_file *file);
  2611. uint32_t
  2612. i915_gem_get_gtt_size(struct drm_device *dev, uint32_t size, int tiling_mode);
  2613. uint32_t
  2614. i915_gem_get_gtt_alignment(struct drm_device *dev, uint32_t size,
  2615. int tiling_mode, bool fenced);
  2616. int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
  2617. enum i915_cache_level cache_level);
  2618. struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
  2619. struct dma_buf *dma_buf);
  2620. struct dma_buf *i915_gem_prime_export(struct drm_device *dev,
  2621. struct drm_gem_object *gem_obj, int flags);
  2622. u64 i915_gem_obj_ggtt_offset_view(struct drm_i915_gem_object *o,
  2623. const struct i915_ggtt_view *view);
  2624. u64 i915_gem_obj_offset(struct drm_i915_gem_object *o,
  2625. struct i915_address_space *vm);
  2626. static inline u64
  2627. i915_gem_obj_ggtt_offset(struct drm_i915_gem_object *o)
  2628. {
  2629. return i915_gem_obj_ggtt_offset_view(o, &i915_ggtt_view_normal);
  2630. }
  2631. bool i915_gem_obj_bound_any(struct drm_i915_gem_object *o);
  2632. bool i915_gem_obj_ggtt_bound_view(struct drm_i915_gem_object *o,
  2633. const struct i915_ggtt_view *view);
  2634. bool i915_gem_obj_bound(struct drm_i915_gem_object *o,
  2635. struct i915_address_space *vm);
  2636. unsigned long i915_gem_obj_size(struct drm_i915_gem_object *o,
  2637. struct i915_address_space *vm);
  2638. struct i915_vma *
  2639. i915_gem_obj_to_vma(struct drm_i915_gem_object *obj,
  2640. struct i915_address_space *vm);
  2641. struct i915_vma *
  2642. i915_gem_obj_to_ggtt_view(struct drm_i915_gem_object *obj,
  2643. const struct i915_ggtt_view *view);
  2644. struct i915_vma *
  2645. i915_gem_obj_lookup_or_create_vma(struct drm_i915_gem_object *obj,
  2646. struct i915_address_space *vm);
  2647. struct i915_vma *
  2648. i915_gem_obj_lookup_or_create_ggtt_vma(struct drm_i915_gem_object *obj,
  2649. const struct i915_ggtt_view *view);
  2650. static inline struct i915_vma *
  2651. i915_gem_obj_to_ggtt(struct drm_i915_gem_object *obj)
  2652. {
  2653. return i915_gem_obj_to_ggtt_view(obj, &i915_ggtt_view_normal);
  2654. }
  2655. bool i915_gem_obj_is_pinned(struct drm_i915_gem_object *obj);
  2656. /* Some GGTT VM helpers */
  2657. #define i915_obj_to_ggtt(obj) \
  2658. (&((struct drm_i915_private *)(obj)->base.dev->dev_private)->gtt.base)
  2659. static inline bool i915_is_ggtt(struct i915_address_space *vm)
  2660. {
  2661. struct i915_address_space *ggtt =
  2662. &((struct drm_i915_private *)(vm)->dev->dev_private)->gtt.base;
  2663. return vm == ggtt;
  2664. }
  2665. static inline struct i915_hw_ppgtt *
  2666. i915_vm_to_ppgtt(struct i915_address_space *vm)
  2667. {
  2668. WARN_ON(i915_is_ggtt(vm));
  2669. return container_of(vm, struct i915_hw_ppgtt, base);
  2670. }
  2671. static inline bool i915_gem_obj_ggtt_bound(struct drm_i915_gem_object *obj)
  2672. {
  2673. return i915_gem_obj_ggtt_bound_view(obj, &i915_ggtt_view_normal);
  2674. }
  2675. static inline unsigned long
  2676. i915_gem_obj_ggtt_size(struct drm_i915_gem_object *obj)
  2677. {
  2678. return i915_gem_obj_size(obj, i915_obj_to_ggtt(obj));
  2679. }
  2680. static inline int __must_check
  2681. i915_gem_obj_ggtt_pin(struct drm_i915_gem_object *obj,
  2682. uint32_t alignment,
  2683. unsigned flags)
  2684. {
  2685. return i915_gem_object_pin(obj, i915_obj_to_ggtt(obj),
  2686. alignment, flags | PIN_GLOBAL);
  2687. }
  2688. static inline int
  2689. i915_gem_object_ggtt_unbind(struct drm_i915_gem_object *obj)
  2690. {
  2691. return i915_vma_unbind(i915_gem_obj_to_ggtt(obj));
  2692. }
  2693. void i915_gem_object_ggtt_unpin_view(struct drm_i915_gem_object *obj,
  2694. const struct i915_ggtt_view *view);
  2695. static inline void
  2696. i915_gem_object_ggtt_unpin(struct drm_i915_gem_object *obj)
  2697. {
  2698. i915_gem_object_ggtt_unpin_view(obj, &i915_ggtt_view_normal);
  2699. }
  2700. /* i915_gem_fence.c */
  2701. int __must_check i915_gem_object_get_fence(struct drm_i915_gem_object *obj);
  2702. int __must_check i915_gem_object_put_fence(struct drm_i915_gem_object *obj);
  2703. bool i915_gem_object_pin_fence(struct drm_i915_gem_object *obj);
  2704. void i915_gem_object_unpin_fence(struct drm_i915_gem_object *obj);
  2705. void i915_gem_restore_fences(struct drm_device *dev);
  2706. void i915_gem_detect_bit_6_swizzle(struct drm_device *dev);
  2707. void i915_gem_object_do_bit_17_swizzle(struct drm_i915_gem_object *obj);
  2708. void i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj);
  2709. /* i915_gem_context.c */
  2710. int __must_check i915_gem_context_init(struct drm_device *dev);
  2711. void i915_gem_context_fini(struct drm_device *dev);
  2712. void i915_gem_context_reset(struct drm_device *dev);
  2713. int i915_gem_context_open(struct drm_device *dev, struct drm_file *file);
  2714. int i915_gem_context_enable(struct drm_i915_gem_request *req);
  2715. void i915_gem_context_close(struct drm_device *dev, struct drm_file *file);
  2716. int i915_switch_context(struct drm_i915_gem_request *req);
  2717. struct intel_context *
  2718. i915_gem_context_get(struct drm_i915_file_private *file_priv, u32 id);
  2719. void i915_gem_context_free(struct kref *ctx_ref);
  2720. struct drm_i915_gem_object *
  2721. i915_gem_alloc_context_obj(struct drm_device *dev, size_t size);
  2722. static inline void i915_gem_context_reference(struct intel_context *ctx)
  2723. {
  2724. kref_get(&ctx->ref);
  2725. }
  2726. static inline void i915_gem_context_unreference(struct intel_context *ctx)
  2727. {
  2728. kref_put(&ctx->ref, i915_gem_context_free);
  2729. }
  2730. static inline bool i915_gem_context_is_default(const struct intel_context *c)
  2731. {
  2732. return c->user_handle == DEFAULT_CONTEXT_HANDLE;
  2733. }
  2734. int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
  2735. struct drm_file *file);
  2736. int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
  2737. struct drm_file *file);
  2738. int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,
  2739. struct drm_file *file_priv);
  2740. int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data,
  2741. struct drm_file *file_priv);
  2742. /* i915_gem_evict.c */
  2743. int __must_check i915_gem_evict_something(struct drm_device *dev,
  2744. struct i915_address_space *vm,
  2745. int min_size,
  2746. unsigned alignment,
  2747. unsigned cache_level,
  2748. unsigned long start,
  2749. unsigned long end,
  2750. unsigned flags);
  2751. int i915_gem_evict_vm(struct i915_address_space *vm, bool do_idle);
  2752. /* belongs in i915_gem_gtt.h */
  2753. static inline void i915_gem_chipset_flush(struct drm_device *dev)
  2754. {
  2755. if (INTEL_INFO(dev)->gen < 6)
  2756. intel_gtt_chipset_flush();
  2757. }
  2758. /* i915_gem_stolen.c */
  2759. int i915_gem_stolen_insert_node(struct drm_i915_private *dev_priv,
  2760. struct drm_mm_node *node, u64 size,
  2761. unsigned alignment);
  2762. int i915_gem_stolen_insert_node_in_range(struct drm_i915_private *dev_priv,
  2763. struct drm_mm_node *node, u64 size,
  2764. unsigned alignment, u64 start,
  2765. u64 end);
  2766. void i915_gem_stolen_remove_node(struct drm_i915_private *dev_priv,
  2767. struct drm_mm_node *node);
  2768. int i915_gem_init_stolen(struct drm_device *dev);
  2769. void i915_gem_cleanup_stolen(struct drm_device *dev);
  2770. struct drm_i915_gem_object *
  2771. i915_gem_object_create_stolen(struct drm_device *dev, u32 size);
  2772. struct drm_i915_gem_object *
  2773. i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
  2774. u32 stolen_offset,
  2775. u32 gtt_offset,
  2776. u32 size);
  2777. /* i915_gem_shrinker.c */
  2778. unsigned long i915_gem_shrink(struct drm_i915_private *dev_priv,
  2779. unsigned long target,
  2780. unsigned flags);
  2781. #define I915_SHRINK_PURGEABLE 0x1
  2782. #define I915_SHRINK_UNBOUND 0x2
  2783. #define I915_SHRINK_BOUND 0x4
  2784. #define I915_SHRINK_ACTIVE 0x8
  2785. unsigned long i915_gem_shrink_all(struct drm_i915_private *dev_priv);
  2786. void i915_gem_shrinker_init(struct drm_i915_private *dev_priv);
  2787. /* i915_gem_tiling.c */
  2788. static inline bool i915_gem_object_needs_bit17_swizzle(struct drm_i915_gem_object *obj)
  2789. {
  2790. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  2791. return dev_priv->mm.bit_6_swizzle_x == I915_BIT_6_SWIZZLE_9_10_17 &&
  2792. obj->tiling_mode != I915_TILING_NONE;
  2793. }
  2794. /* i915_gem_debug.c */
  2795. #if WATCH_LISTS
  2796. int i915_verify_lists(struct drm_device *dev);
  2797. #else
  2798. #define i915_verify_lists(dev) 0
  2799. #endif
  2800. /* i915_debugfs.c */
  2801. int i915_debugfs_init(struct drm_minor *minor);
  2802. void i915_debugfs_cleanup(struct drm_minor *minor);
  2803. #ifdef CONFIG_DEBUG_FS
  2804. int i915_debugfs_connector_add(struct drm_connector *connector);
  2805. void intel_display_crc_init(struct drm_device *dev);
  2806. #else
  2807. static inline int i915_debugfs_connector_add(struct drm_connector *connector)
  2808. { return 0; }
  2809. static inline void intel_display_crc_init(struct drm_device *dev) {}
  2810. #endif
  2811. /* i915_gpu_error.c */
  2812. __printf(2, 3)
  2813. void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...);
  2814. int i915_error_state_to_str(struct drm_i915_error_state_buf *estr,
  2815. const struct i915_error_state_file_priv *error);
  2816. int i915_error_state_buf_init(struct drm_i915_error_state_buf *eb,
  2817. struct drm_i915_private *i915,
  2818. size_t count, loff_t pos);
  2819. static inline void i915_error_state_buf_release(
  2820. struct drm_i915_error_state_buf *eb)
  2821. {
  2822. kfree(eb->buf);
  2823. }
  2824. void i915_capture_error_state(struct drm_device *dev, bool wedge,
  2825. const char *error_msg);
  2826. void i915_error_state_get(struct drm_device *dev,
  2827. struct i915_error_state_file_priv *error_priv);
  2828. void i915_error_state_put(struct i915_error_state_file_priv *error_priv);
  2829. void i915_destroy_error_state(struct drm_device *dev);
  2830. void i915_get_extra_instdone(struct drm_device *dev, uint32_t *instdone);
  2831. const char *i915_cache_level_str(struct drm_i915_private *i915, int type);
  2832. /* i915_cmd_parser.c */
  2833. int i915_cmd_parser_get_version(void);
  2834. int i915_cmd_parser_init_ring(struct intel_engine_cs *ring);
  2835. void i915_cmd_parser_fini_ring(struct intel_engine_cs *ring);
  2836. bool i915_needs_cmd_parser(struct intel_engine_cs *ring);
  2837. int i915_parse_cmds(struct intel_engine_cs *ring,
  2838. struct drm_i915_gem_object *batch_obj,
  2839. struct drm_i915_gem_object *shadow_batch_obj,
  2840. u32 batch_start_offset,
  2841. u32 batch_len,
  2842. bool is_master);
  2843. /* i915_suspend.c */
  2844. extern int i915_save_state(struct drm_device *dev);
  2845. extern int i915_restore_state(struct drm_device *dev);
  2846. /* i915_sysfs.c */
  2847. void i915_setup_sysfs(struct drm_device *dev_priv);
  2848. void i915_teardown_sysfs(struct drm_device *dev_priv);
  2849. /* intel_i2c.c */
  2850. extern int intel_setup_gmbus(struct drm_device *dev);
  2851. extern void intel_teardown_gmbus(struct drm_device *dev);
  2852. extern bool intel_gmbus_is_valid_pin(struct drm_i915_private *dev_priv,
  2853. unsigned int pin);
  2854. extern struct i2c_adapter *
  2855. intel_gmbus_get_adapter(struct drm_i915_private *dev_priv, unsigned int pin);
  2856. extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
  2857. extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
  2858. static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
  2859. {
  2860. return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
  2861. }
  2862. extern void intel_i2c_reset(struct drm_device *dev);
  2863. /* intel_opregion.c */
  2864. #ifdef CONFIG_ACPI
  2865. extern int intel_opregion_setup(struct drm_device *dev);
  2866. extern void intel_opregion_init(struct drm_device *dev);
  2867. extern void intel_opregion_fini(struct drm_device *dev);
  2868. extern void intel_opregion_asle_intr(struct drm_device *dev);
  2869. extern int intel_opregion_notify_encoder(struct intel_encoder *intel_encoder,
  2870. bool enable);
  2871. extern int intel_opregion_notify_adapter(struct drm_device *dev,
  2872. pci_power_t state);
  2873. #else
  2874. static inline int intel_opregion_setup(struct drm_device *dev) { return 0; }
  2875. static inline void intel_opregion_init(struct drm_device *dev) { return; }
  2876. static inline void intel_opregion_fini(struct drm_device *dev) { return; }
  2877. static inline void intel_opregion_asle_intr(struct drm_device *dev) { return; }
  2878. static inline int
  2879. intel_opregion_notify_encoder(struct intel_encoder *intel_encoder, bool enable)
  2880. {
  2881. return 0;
  2882. }
  2883. static inline int
  2884. intel_opregion_notify_adapter(struct drm_device *dev, pci_power_t state)
  2885. {
  2886. return 0;
  2887. }
  2888. #endif
  2889. /* intel_acpi.c */
  2890. #ifdef CONFIG_ACPI
  2891. extern void intel_register_dsm_handler(void);
  2892. extern void intel_unregister_dsm_handler(void);
  2893. #else
  2894. static inline void intel_register_dsm_handler(void) { return; }
  2895. static inline void intel_unregister_dsm_handler(void) { return; }
  2896. #endif /* CONFIG_ACPI */
  2897. /* modesetting */
  2898. extern void intel_modeset_init_hw(struct drm_device *dev);
  2899. extern void intel_modeset_init(struct drm_device *dev);
  2900. extern void intel_modeset_gem_init(struct drm_device *dev);
  2901. extern void intel_modeset_cleanup(struct drm_device *dev);
  2902. extern void intel_connector_unregister(struct intel_connector *);
  2903. extern int intel_modeset_vga_set_state(struct drm_device *dev, bool state);
  2904. extern void intel_display_resume(struct drm_device *dev);
  2905. extern void i915_redisable_vga(struct drm_device *dev);
  2906. extern void i915_redisable_vga_power_on(struct drm_device *dev);
  2907. extern bool ironlake_set_drps(struct drm_device *dev, u8 val);
  2908. extern void intel_init_pch_refclk(struct drm_device *dev);
  2909. extern void intel_set_rps(struct drm_device *dev, u8 val);
  2910. extern void intel_set_memory_cxsr(struct drm_i915_private *dev_priv,
  2911. bool enable);
  2912. extern void intel_detect_pch(struct drm_device *dev);
  2913. extern int intel_enable_rc6(const struct drm_device *dev);
  2914. extern bool i915_semaphore_is_enabled(struct drm_device *dev);
  2915. int i915_reg_read_ioctl(struct drm_device *dev, void *data,
  2916. struct drm_file *file);
  2917. int i915_get_reset_stats_ioctl(struct drm_device *dev, void *data,
  2918. struct drm_file *file);
  2919. /* overlay */
  2920. extern struct intel_overlay_error_state *intel_overlay_capture_error_state(struct drm_device *dev);
  2921. extern void intel_overlay_print_error_state(struct drm_i915_error_state_buf *e,
  2922. struct intel_overlay_error_state *error);
  2923. extern struct intel_display_error_state *intel_display_capture_error_state(struct drm_device *dev);
  2924. extern void intel_display_print_error_state(struct drm_i915_error_state_buf *e,
  2925. struct drm_device *dev,
  2926. struct intel_display_error_state *error);
  2927. int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u32 mbox, u32 *val);
  2928. int sandybridge_pcode_write(struct drm_i915_private *dev_priv, u32 mbox, u32 val);
  2929. /* intel_sideband.c */
  2930. u32 vlv_punit_read(struct drm_i915_private *dev_priv, u32 addr);
  2931. void vlv_punit_write(struct drm_i915_private *dev_priv, u32 addr, u32 val);
  2932. u32 vlv_nc_read(struct drm_i915_private *dev_priv, u8 addr);
  2933. u32 vlv_gpio_nc_read(struct drm_i915_private *dev_priv, u32 reg);
  2934. void vlv_gpio_nc_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2935. u32 vlv_cck_read(struct drm_i915_private *dev_priv, u32 reg);
  2936. void vlv_cck_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2937. u32 vlv_ccu_read(struct drm_i915_private *dev_priv, u32 reg);
  2938. void vlv_ccu_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2939. u32 vlv_bunit_read(struct drm_i915_private *dev_priv, u32 reg);
  2940. void vlv_bunit_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2941. u32 vlv_gps_core_read(struct drm_i915_private *dev_priv, u32 reg);
  2942. void vlv_gps_core_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2943. u32 vlv_dpio_read(struct drm_i915_private *dev_priv, enum pipe pipe, int reg);
  2944. void vlv_dpio_write(struct drm_i915_private *dev_priv, enum pipe pipe, int reg, u32 val);
  2945. u32 intel_sbi_read(struct drm_i915_private *dev_priv, u16 reg,
  2946. enum intel_sbi_destination destination);
  2947. void intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
  2948. enum intel_sbi_destination destination);
  2949. u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
  2950. void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2951. int intel_gpu_freq(struct drm_i915_private *dev_priv, int val);
  2952. int intel_freq_opcode(struct drm_i915_private *dev_priv, int val);
  2953. #define I915_READ8(reg) dev_priv->uncore.funcs.mmio_readb(dev_priv, (reg), true)
  2954. #define I915_WRITE8(reg, val) dev_priv->uncore.funcs.mmio_writeb(dev_priv, (reg), (val), true)
  2955. #define I915_READ16(reg) dev_priv->uncore.funcs.mmio_readw(dev_priv, (reg), true)
  2956. #define I915_WRITE16(reg, val) dev_priv->uncore.funcs.mmio_writew(dev_priv, (reg), (val), true)
  2957. #define I915_READ16_NOTRACE(reg) dev_priv->uncore.funcs.mmio_readw(dev_priv, (reg), false)
  2958. #define I915_WRITE16_NOTRACE(reg, val) dev_priv->uncore.funcs.mmio_writew(dev_priv, (reg), (val), false)
  2959. #define I915_READ(reg) dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), true)
  2960. #define I915_WRITE(reg, val) dev_priv->uncore.funcs.mmio_writel(dev_priv, (reg), (val), true)
  2961. #define I915_READ_NOTRACE(reg) dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), false)
  2962. #define I915_WRITE_NOTRACE(reg, val) dev_priv->uncore.funcs.mmio_writel(dev_priv, (reg), (val), false)
  2963. /* Be very careful with read/write 64-bit values. On 32-bit machines, they
  2964. * will be implemented using 2 32-bit writes in an arbitrary order with
  2965. * an arbitrary delay between them. This can cause the hardware to
  2966. * act upon the intermediate value, possibly leading to corruption and
  2967. * machine death. You have been warned.
  2968. */
  2969. #define I915_WRITE64(reg, val) dev_priv->uncore.funcs.mmio_writeq(dev_priv, (reg), (val), true)
  2970. #define I915_READ64(reg) dev_priv->uncore.funcs.mmio_readq(dev_priv, (reg), true)
  2971. #define I915_READ64_2x32(lower_reg, upper_reg) ({ \
  2972. u32 upper, lower, old_upper, loop = 0; \
  2973. upper = I915_READ(upper_reg); \
  2974. do { \
  2975. old_upper = upper; \
  2976. lower = I915_READ(lower_reg); \
  2977. upper = I915_READ(upper_reg); \
  2978. } while (upper != old_upper && loop++ < 2); \
  2979. (u64)upper << 32 | lower; })
  2980. #define POSTING_READ(reg) (void)I915_READ_NOTRACE(reg)
  2981. #define POSTING_READ16(reg) (void)I915_READ16_NOTRACE(reg)
  2982. #define __raw_read(x, s) \
  2983. static inline uint##x##_t __raw_i915_read##x(struct drm_i915_private *dev_priv, \
  2984. i915_reg_t reg) \
  2985. { \
  2986. return read##s(dev_priv->regs + i915_mmio_reg_offset(reg)); \
  2987. }
  2988. #define __raw_write(x, s) \
  2989. static inline void __raw_i915_write##x(struct drm_i915_private *dev_priv, \
  2990. i915_reg_t reg, uint##x##_t val) \
  2991. { \
  2992. write##s(val, dev_priv->regs + i915_mmio_reg_offset(reg)); \
  2993. }
  2994. __raw_read(8, b)
  2995. __raw_read(16, w)
  2996. __raw_read(32, l)
  2997. __raw_read(64, q)
  2998. __raw_write(8, b)
  2999. __raw_write(16, w)
  3000. __raw_write(32, l)
  3001. __raw_write(64, q)
  3002. #undef __raw_read
  3003. #undef __raw_write
  3004. /* These are untraced mmio-accessors that are only valid to be used inside
  3005. * criticial sections inside IRQ handlers where forcewake is explicitly
  3006. * controlled.
  3007. * Think twice, and think again, before using these.
  3008. * Note: Should only be used between intel_uncore_forcewake_irqlock() and
  3009. * intel_uncore_forcewake_irqunlock().
  3010. */
  3011. #define I915_READ_FW(reg__) __raw_i915_read32(dev_priv, (reg__))
  3012. #define I915_WRITE_FW(reg__, val__) __raw_i915_write32(dev_priv, (reg__), (val__))
  3013. #define POSTING_READ_FW(reg__) (void)I915_READ_FW(reg__)
  3014. /* "Broadcast RGB" property */
  3015. #define INTEL_BROADCAST_RGB_AUTO 0
  3016. #define INTEL_BROADCAST_RGB_FULL 1
  3017. #define INTEL_BROADCAST_RGB_LIMITED 2
  3018. static inline i915_reg_t i915_vgacntrl_reg(struct drm_device *dev)
  3019. {
  3020. if (IS_VALLEYVIEW(dev))
  3021. return VLV_VGACNTRL;
  3022. else if (INTEL_INFO(dev)->gen >= 5)
  3023. return CPU_VGACNTRL;
  3024. else
  3025. return VGACNTRL;
  3026. }
  3027. static inline void __user *to_user_ptr(u64 address)
  3028. {
  3029. return (void __user *)(uintptr_t)address;
  3030. }
  3031. static inline unsigned long msecs_to_jiffies_timeout(const unsigned int m)
  3032. {
  3033. unsigned long j = msecs_to_jiffies(m);
  3034. return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
  3035. }
  3036. static inline unsigned long nsecs_to_jiffies_timeout(const u64 n)
  3037. {
  3038. return min_t(u64, MAX_JIFFY_OFFSET, nsecs_to_jiffies64(n) + 1);
  3039. }
  3040. static inline unsigned long
  3041. timespec_to_jiffies_timeout(const struct timespec *value)
  3042. {
  3043. unsigned long j = timespec_to_jiffies(value);
  3044. return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
  3045. }
  3046. /*
  3047. * If you need to wait X milliseconds between events A and B, but event B
  3048. * doesn't happen exactly after event A, you record the timestamp (jiffies) of
  3049. * when event A happened, then just before event B you call this function and
  3050. * pass the timestamp as the first argument, and X as the second argument.
  3051. */
  3052. static inline void
  3053. wait_remaining_ms_from_jiffies(unsigned long timestamp_jiffies, int to_wait_ms)
  3054. {
  3055. unsigned long target_jiffies, tmp_jiffies, remaining_jiffies;
  3056. /*
  3057. * Don't re-read the value of "jiffies" every time since it may change
  3058. * behind our back and break the math.
  3059. */
  3060. tmp_jiffies = jiffies;
  3061. target_jiffies = timestamp_jiffies +
  3062. msecs_to_jiffies_timeout(to_wait_ms);
  3063. if (time_after(target_jiffies, tmp_jiffies)) {
  3064. remaining_jiffies = target_jiffies - tmp_jiffies;
  3065. while (remaining_jiffies)
  3066. remaining_jiffies =
  3067. schedule_timeout_uninterruptible(remaining_jiffies);
  3068. }
  3069. }
  3070. static inline void i915_trace_irq_get(struct intel_engine_cs *ring,
  3071. struct drm_i915_gem_request *req)
  3072. {
  3073. if (ring->trace_irq_req == NULL && ring->irq_get(ring))
  3074. i915_gem_request_assign(&ring->trace_irq_req, req);
  3075. }
  3076. #endif