i915_drv.h 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075
  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 "i915_reg.h"
  33. #include "intel_bios.h"
  34. #include "intel_ringbuffer.h"
  35. #include "intel_lrc.h"
  36. #include "i915_gem_gtt.h"
  37. #include "i915_gem_render_state.h"
  38. #include <linux/io-mapping.h>
  39. #include <linux/i2c.h>
  40. #include <linux/i2c-algo-bit.h>
  41. #include <drm/intel-gtt.h>
  42. #include <drm/drm_legacy.h> /* for struct drm_dma_handle */
  43. #include <drm/drm_gem.h>
  44. #include <linux/backlight.h>
  45. #include <linux/hashtable.h>
  46. #include <linux/intel-iommu.h>
  47. #include <linux/kref.h>
  48. #include <linux/pm_qos.h>
  49. /* General customization:
  50. */
  51. #define DRIVER_NAME "i915"
  52. #define DRIVER_DESC "Intel Graphics"
  53. #define DRIVER_DATE "20141121"
  54. #undef WARN_ON
  55. #define WARN_ON(x) WARN(x, "WARN_ON(" #x ")")
  56. enum pipe {
  57. INVALID_PIPE = -1,
  58. PIPE_A = 0,
  59. PIPE_B,
  60. PIPE_C,
  61. _PIPE_EDP,
  62. I915_MAX_PIPES = _PIPE_EDP
  63. };
  64. #define pipe_name(p) ((p) + 'A')
  65. enum transcoder {
  66. TRANSCODER_A = 0,
  67. TRANSCODER_B,
  68. TRANSCODER_C,
  69. TRANSCODER_EDP,
  70. I915_MAX_TRANSCODERS
  71. };
  72. #define transcoder_name(t) ((t) + 'A')
  73. /*
  74. * This is the maximum (across all platforms) number of planes (primary +
  75. * sprites) that can be active at the same time on one pipe.
  76. *
  77. * This value doesn't count the cursor plane.
  78. */
  79. #define I915_MAX_PLANES 3
  80. enum plane {
  81. PLANE_A = 0,
  82. PLANE_B,
  83. PLANE_C,
  84. };
  85. #define plane_name(p) ((p) + 'A')
  86. #define sprite_name(p, s) ((p) * INTEL_INFO(dev)->num_sprites[(p)] + (s) + 'A')
  87. enum port {
  88. PORT_A = 0,
  89. PORT_B,
  90. PORT_C,
  91. PORT_D,
  92. PORT_E,
  93. I915_MAX_PORTS
  94. };
  95. #define port_name(p) ((p) + 'A')
  96. #define I915_NUM_PHYS_VLV 2
  97. enum dpio_channel {
  98. DPIO_CH0,
  99. DPIO_CH1
  100. };
  101. enum dpio_phy {
  102. DPIO_PHY0,
  103. DPIO_PHY1
  104. };
  105. enum intel_display_power_domain {
  106. POWER_DOMAIN_PIPE_A,
  107. POWER_DOMAIN_PIPE_B,
  108. POWER_DOMAIN_PIPE_C,
  109. POWER_DOMAIN_PIPE_A_PANEL_FITTER,
  110. POWER_DOMAIN_PIPE_B_PANEL_FITTER,
  111. POWER_DOMAIN_PIPE_C_PANEL_FITTER,
  112. POWER_DOMAIN_TRANSCODER_A,
  113. POWER_DOMAIN_TRANSCODER_B,
  114. POWER_DOMAIN_TRANSCODER_C,
  115. POWER_DOMAIN_TRANSCODER_EDP,
  116. POWER_DOMAIN_PORT_DDI_A_2_LANES,
  117. POWER_DOMAIN_PORT_DDI_A_4_LANES,
  118. POWER_DOMAIN_PORT_DDI_B_2_LANES,
  119. POWER_DOMAIN_PORT_DDI_B_4_LANES,
  120. POWER_DOMAIN_PORT_DDI_C_2_LANES,
  121. POWER_DOMAIN_PORT_DDI_C_4_LANES,
  122. POWER_DOMAIN_PORT_DDI_D_2_LANES,
  123. POWER_DOMAIN_PORT_DDI_D_4_LANES,
  124. POWER_DOMAIN_PORT_DSI,
  125. POWER_DOMAIN_PORT_CRT,
  126. POWER_DOMAIN_PORT_OTHER,
  127. POWER_DOMAIN_VGA,
  128. POWER_DOMAIN_AUDIO,
  129. POWER_DOMAIN_PLLS,
  130. POWER_DOMAIN_INIT,
  131. POWER_DOMAIN_NUM,
  132. };
  133. #define POWER_DOMAIN_PIPE(pipe) ((pipe) + POWER_DOMAIN_PIPE_A)
  134. #define POWER_DOMAIN_PIPE_PANEL_FITTER(pipe) \
  135. ((pipe) + POWER_DOMAIN_PIPE_A_PANEL_FITTER)
  136. #define POWER_DOMAIN_TRANSCODER(tran) \
  137. ((tran) == TRANSCODER_EDP ? POWER_DOMAIN_TRANSCODER_EDP : \
  138. (tran) + POWER_DOMAIN_TRANSCODER_A)
  139. enum hpd_pin {
  140. HPD_NONE = 0,
  141. HPD_PORT_A = HPD_NONE, /* PORT_A is internal */
  142. HPD_TV = HPD_NONE, /* TV is known to be unreliable */
  143. HPD_CRT,
  144. HPD_SDVO_B,
  145. HPD_SDVO_C,
  146. HPD_PORT_B,
  147. HPD_PORT_C,
  148. HPD_PORT_D,
  149. HPD_NUM_PINS
  150. };
  151. #define I915_GEM_GPU_DOMAINS \
  152. (I915_GEM_DOMAIN_RENDER | \
  153. I915_GEM_DOMAIN_SAMPLER | \
  154. I915_GEM_DOMAIN_COMMAND | \
  155. I915_GEM_DOMAIN_INSTRUCTION | \
  156. I915_GEM_DOMAIN_VERTEX)
  157. #define for_each_pipe(__dev_priv, __p) \
  158. for ((__p) = 0; (__p) < INTEL_INFO(__dev_priv)->num_pipes; (__p)++)
  159. #define for_each_plane(pipe, p) \
  160. for ((p) = 0; (p) < INTEL_INFO(dev)->num_sprites[(pipe)] + 1; (p)++)
  161. #define for_each_sprite(p, s) for ((s) = 0; (s) < INTEL_INFO(dev)->num_sprites[(p)]; (s)++)
  162. #define for_each_crtc(dev, crtc) \
  163. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  164. #define for_each_intel_crtc(dev, intel_crtc) \
  165. list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, base.head)
  166. #define for_each_intel_encoder(dev, intel_encoder) \
  167. list_for_each_entry(intel_encoder, \
  168. &(dev)->mode_config.encoder_list, \
  169. base.head)
  170. #define for_each_encoder_on_crtc(dev, __crtc, intel_encoder) \
  171. list_for_each_entry((intel_encoder), &(dev)->mode_config.encoder_list, base.head) \
  172. if ((intel_encoder)->base.crtc == (__crtc))
  173. #define for_each_connector_on_encoder(dev, __encoder, intel_connector) \
  174. list_for_each_entry((intel_connector), &(dev)->mode_config.connector_list, base.head) \
  175. if ((intel_connector)->base.encoder == (__encoder))
  176. #define for_each_power_domain(domain, mask) \
  177. for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
  178. if ((1 << (domain)) & (mask))
  179. struct drm_i915_private;
  180. struct i915_mm_struct;
  181. struct i915_mmu_object;
  182. enum intel_dpll_id {
  183. DPLL_ID_PRIVATE = -1, /* non-shared dpll in use */
  184. /* real shared dpll ids must be >= 0 */
  185. DPLL_ID_PCH_PLL_A = 0,
  186. DPLL_ID_PCH_PLL_B = 1,
  187. /* hsw/bdw */
  188. DPLL_ID_WRPLL1 = 0,
  189. DPLL_ID_WRPLL2 = 1,
  190. /* skl */
  191. DPLL_ID_SKL_DPLL1 = 0,
  192. DPLL_ID_SKL_DPLL2 = 1,
  193. DPLL_ID_SKL_DPLL3 = 2,
  194. };
  195. #define I915_NUM_PLLS 3
  196. struct intel_dpll_hw_state {
  197. /* i9xx, pch plls */
  198. uint32_t dpll;
  199. uint32_t dpll_md;
  200. uint32_t fp0;
  201. uint32_t fp1;
  202. /* hsw, bdw */
  203. uint32_t wrpll;
  204. /* skl */
  205. /*
  206. * DPLL_CTRL1 has 6 bits for each each this DPLL. We store those in
  207. * lower part of crtl1 and they get shifted into position when writing
  208. * the register. This allows us to easily compare the state to share
  209. * the DPLL.
  210. */
  211. uint32_t ctrl1;
  212. /* HDMI only, 0 when used for DP */
  213. uint32_t cfgcr1, cfgcr2;
  214. };
  215. struct intel_shared_dpll_config {
  216. unsigned crtc_mask; /* mask of CRTCs sharing this PLL */
  217. struct intel_dpll_hw_state hw_state;
  218. };
  219. struct intel_shared_dpll {
  220. struct intel_shared_dpll_config config;
  221. struct intel_shared_dpll_config *new_config;
  222. int active; /* count of number of active CRTCs (i.e. DPMS on) */
  223. bool on; /* is the PLL actually active? Disabled during modeset */
  224. const char *name;
  225. /* should match the index in the dev_priv->shared_dplls array */
  226. enum intel_dpll_id id;
  227. /* The mode_set hook is optional and should be used together with the
  228. * intel_prepare_shared_dpll function. */
  229. void (*mode_set)(struct drm_i915_private *dev_priv,
  230. struct intel_shared_dpll *pll);
  231. void (*enable)(struct drm_i915_private *dev_priv,
  232. struct intel_shared_dpll *pll);
  233. void (*disable)(struct drm_i915_private *dev_priv,
  234. struct intel_shared_dpll *pll);
  235. bool (*get_hw_state)(struct drm_i915_private *dev_priv,
  236. struct intel_shared_dpll *pll,
  237. struct intel_dpll_hw_state *hw_state);
  238. };
  239. #define SKL_DPLL0 0
  240. #define SKL_DPLL1 1
  241. #define SKL_DPLL2 2
  242. #define SKL_DPLL3 3
  243. /* Used by dp and fdi links */
  244. struct intel_link_m_n {
  245. uint32_t tu;
  246. uint32_t gmch_m;
  247. uint32_t gmch_n;
  248. uint32_t link_m;
  249. uint32_t link_n;
  250. };
  251. void intel_link_compute_m_n(int bpp, int nlanes,
  252. int pixel_clock, int link_clock,
  253. struct intel_link_m_n *m_n);
  254. /* Interface history:
  255. *
  256. * 1.1: Original.
  257. * 1.2: Add Power Management
  258. * 1.3: Add vblank support
  259. * 1.4: Fix cmdbuffer path, add heap destroy
  260. * 1.5: Add vblank pipe configuration
  261. * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
  262. * - Support vertical blank on secondary display pipe
  263. */
  264. #define DRIVER_MAJOR 1
  265. #define DRIVER_MINOR 6
  266. #define DRIVER_PATCHLEVEL 0
  267. #define WATCH_LISTS 0
  268. struct opregion_header;
  269. struct opregion_acpi;
  270. struct opregion_swsci;
  271. struct opregion_asle;
  272. struct intel_opregion {
  273. struct opregion_header __iomem *header;
  274. struct opregion_acpi __iomem *acpi;
  275. struct opregion_swsci __iomem *swsci;
  276. u32 swsci_gbda_sub_functions;
  277. u32 swsci_sbcb_sub_functions;
  278. struct opregion_asle __iomem *asle;
  279. void __iomem *vbt;
  280. u32 __iomem *lid_state;
  281. struct work_struct asle_work;
  282. };
  283. #define OPREGION_SIZE (8*1024)
  284. struct intel_overlay;
  285. struct intel_overlay_error_state;
  286. #define I915_FENCE_REG_NONE -1
  287. #define I915_MAX_NUM_FENCES 32
  288. /* 32 fences + sign bit for FENCE_REG_NONE */
  289. #define I915_MAX_NUM_FENCE_BITS 6
  290. struct drm_i915_fence_reg {
  291. struct list_head lru_list;
  292. struct drm_i915_gem_object *obj;
  293. int pin_count;
  294. };
  295. struct sdvo_device_mapping {
  296. u8 initialized;
  297. u8 dvo_port;
  298. u8 slave_addr;
  299. u8 dvo_wiring;
  300. u8 i2c_pin;
  301. u8 ddc_pin;
  302. };
  303. struct intel_display_error_state;
  304. struct drm_i915_error_state {
  305. struct kref ref;
  306. struct timeval time;
  307. char error_msg[128];
  308. u32 reset_count;
  309. u32 suspend_count;
  310. /* Generic register state */
  311. u32 eir;
  312. u32 pgtbl_er;
  313. u32 ier;
  314. u32 gtier[4];
  315. u32 ccid;
  316. u32 derrmr;
  317. u32 forcewake;
  318. u32 error; /* gen6+ */
  319. u32 err_int; /* gen7 */
  320. u32 done_reg;
  321. u32 gac_eco;
  322. u32 gam_ecochk;
  323. u32 gab_ctl;
  324. u32 gfx_mode;
  325. u32 extra_instdone[I915_NUM_INSTDONE_REG];
  326. u64 fence[I915_MAX_NUM_FENCES];
  327. struct intel_overlay_error_state *overlay;
  328. struct intel_display_error_state *display;
  329. struct drm_i915_error_object *semaphore_obj;
  330. struct drm_i915_error_ring {
  331. bool valid;
  332. /* Software tracked state */
  333. bool waiting;
  334. int hangcheck_score;
  335. enum intel_ring_hangcheck_action hangcheck_action;
  336. int num_requests;
  337. /* our own tracking of ring head and tail */
  338. u32 cpu_ring_head;
  339. u32 cpu_ring_tail;
  340. u32 semaphore_seqno[I915_NUM_RINGS - 1];
  341. /* Register state */
  342. u32 tail;
  343. u32 head;
  344. u32 ctl;
  345. u32 hws;
  346. u32 ipeir;
  347. u32 ipehr;
  348. u32 instdone;
  349. u32 bbstate;
  350. u32 instpm;
  351. u32 instps;
  352. u32 seqno;
  353. u64 bbaddr;
  354. u64 acthd;
  355. u32 fault_reg;
  356. u64 faddr;
  357. u32 rc_psmi; /* sleep state */
  358. u32 semaphore_mboxes[I915_NUM_RINGS - 1];
  359. struct drm_i915_error_object {
  360. int page_count;
  361. u32 gtt_offset;
  362. u32 *pages[0];
  363. } *ringbuffer, *batchbuffer, *wa_batchbuffer, *ctx, *hws_page;
  364. struct drm_i915_error_request {
  365. long jiffies;
  366. u32 seqno;
  367. u32 tail;
  368. } *requests;
  369. struct {
  370. u32 gfx_mode;
  371. union {
  372. u64 pdp[4];
  373. u32 pp_dir_base;
  374. };
  375. } vm_info;
  376. pid_t pid;
  377. char comm[TASK_COMM_LEN];
  378. } ring[I915_NUM_RINGS];
  379. struct drm_i915_error_buffer {
  380. u32 size;
  381. u32 name;
  382. u32 rseqno, wseqno;
  383. u32 gtt_offset;
  384. u32 read_domains;
  385. u32 write_domain;
  386. s32 fence_reg:I915_MAX_NUM_FENCE_BITS;
  387. s32 pinned:2;
  388. u32 tiling:2;
  389. u32 dirty:1;
  390. u32 purgeable:1;
  391. u32 userptr:1;
  392. s32 ring:4;
  393. u32 cache_level:3;
  394. } **active_bo, **pinned_bo;
  395. u32 *active_bo_count, *pinned_bo_count;
  396. u32 vm_count;
  397. };
  398. struct intel_connector;
  399. struct intel_encoder;
  400. struct intel_crtc_config;
  401. struct intel_plane_config;
  402. struct intel_crtc;
  403. struct intel_limit;
  404. struct dpll;
  405. struct drm_i915_display_funcs {
  406. bool (*fbc_enabled)(struct drm_device *dev);
  407. void (*enable_fbc)(struct drm_crtc *crtc);
  408. void (*disable_fbc)(struct drm_device *dev);
  409. int (*get_display_clock_speed)(struct drm_device *dev);
  410. int (*get_fifo_size)(struct drm_device *dev, int plane);
  411. /**
  412. * find_dpll() - Find the best values for the PLL
  413. * @limit: limits for the PLL
  414. * @crtc: current CRTC
  415. * @target: target frequency in kHz
  416. * @refclk: reference clock frequency in kHz
  417. * @match_clock: if provided, @best_clock P divider must
  418. * match the P divider from @match_clock
  419. * used for LVDS downclocking
  420. * @best_clock: best PLL values found
  421. *
  422. * Returns true on success, false on failure.
  423. */
  424. bool (*find_dpll)(const struct intel_limit *limit,
  425. struct intel_crtc *crtc,
  426. int target, int refclk,
  427. struct dpll *match_clock,
  428. struct dpll *best_clock);
  429. void (*update_wm)(struct drm_crtc *crtc);
  430. void (*update_sprite_wm)(struct drm_plane *plane,
  431. struct drm_crtc *crtc,
  432. uint32_t sprite_width, uint32_t sprite_height,
  433. int pixel_size, bool enable, bool scaled);
  434. void (*modeset_global_resources)(struct drm_device *dev);
  435. /* Returns the active state of the crtc, and if the crtc is active,
  436. * fills out the pipe-config with the hw state. */
  437. bool (*get_pipe_config)(struct intel_crtc *,
  438. struct intel_crtc_config *);
  439. void (*get_plane_config)(struct intel_crtc *,
  440. struct intel_plane_config *);
  441. int (*crtc_compute_clock)(struct intel_crtc *crtc);
  442. void (*crtc_enable)(struct drm_crtc *crtc);
  443. void (*crtc_disable)(struct drm_crtc *crtc);
  444. void (*off)(struct drm_crtc *crtc);
  445. void (*audio_codec_enable)(struct drm_connector *connector,
  446. struct intel_encoder *encoder,
  447. struct drm_display_mode *mode);
  448. void (*audio_codec_disable)(struct intel_encoder *encoder);
  449. void (*fdi_link_train)(struct drm_crtc *crtc);
  450. void (*init_clock_gating)(struct drm_device *dev);
  451. int (*queue_flip)(struct drm_device *dev, struct drm_crtc *crtc,
  452. struct drm_framebuffer *fb,
  453. struct drm_i915_gem_object *obj,
  454. struct intel_engine_cs *ring,
  455. uint32_t flags);
  456. void (*update_primary_plane)(struct drm_crtc *crtc,
  457. struct drm_framebuffer *fb,
  458. int x, int y);
  459. void (*hpd_irq_setup)(struct drm_device *dev);
  460. /* clock updates for mode set */
  461. /* cursor updates */
  462. /* render clock increase/decrease */
  463. /* display clock increase/decrease */
  464. /* pll clock increase/decrease */
  465. int (*setup_backlight)(struct intel_connector *connector, enum pipe pipe);
  466. uint32_t (*get_backlight)(struct intel_connector *connector);
  467. void (*set_backlight)(struct intel_connector *connector,
  468. uint32_t level);
  469. void (*disable_backlight)(struct intel_connector *connector);
  470. void (*enable_backlight)(struct intel_connector *connector);
  471. };
  472. struct intel_uncore_funcs {
  473. void (*force_wake_get)(struct drm_i915_private *dev_priv,
  474. int fw_engine);
  475. void (*force_wake_put)(struct drm_i915_private *dev_priv,
  476. int fw_engine);
  477. uint8_t (*mmio_readb)(struct drm_i915_private *dev_priv, off_t offset, bool trace);
  478. uint16_t (*mmio_readw)(struct drm_i915_private *dev_priv, off_t offset, bool trace);
  479. uint32_t (*mmio_readl)(struct drm_i915_private *dev_priv, off_t offset, bool trace);
  480. uint64_t (*mmio_readq)(struct drm_i915_private *dev_priv, off_t offset, bool trace);
  481. void (*mmio_writeb)(struct drm_i915_private *dev_priv, off_t offset,
  482. uint8_t val, bool trace);
  483. void (*mmio_writew)(struct drm_i915_private *dev_priv, off_t offset,
  484. uint16_t val, bool trace);
  485. void (*mmio_writel)(struct drm_i915_private *dev_priv, off_t offset,
  486. uint32_t val, bool trace);
  487. void (*mmio_writeq)(struct drm_i915_private *dev_priv, off_t offset,
  488. uint64_t val, bool trace);
  489. };
  490. struct intel_uncore {
  491. spinlock_t lock; /** lock is also taken in irq contexts. */
  492. struct intel_uncore_funcs funcs;
  493. unsigned fifo_count;
  494. unsigned forcewake_count;
  495. unsigned fw_rendercount;
  496. unsigned fw_mediacount;
  497. unsigned fw_blittercount;
  498. struct timer_list force_wake_timer;
  499. };
  500. #define DEV_INFO_FOR_EACH_FLAG(func, sep) \
  501. func(is_mobile) sep \
  502. func(is_i85x) sep \
  503. func(is_i915g) sep \
  504. func(is_i945gm) sep \
  505. func(is_g33) sep \
  506. func(need_gfx_hws) sep \
  507. func(is_g4x) sep \
  508. func(is_pineview) sep \
  509. func(is_broadwater) sep \
  510. func(is_crestline) sep \
  511. func(is_ivybridge) sep \
  512. func(is_valleyview) sep \
  513. func(is_haswell) sep \
  514. func(is_skylake) sep \
  515. func(is_preliminary) sep \
  516. func(has_fbc) sep \
  517. func(has_pipe_cxsr) sep \
  518. func(has_hotplug) sep \
  519. func(cursor_needs_physical) sep \
  520. func(has_overlay) sep \
  521. func(overlay_needs_physical) sep \
  522. func(supports_tv) sep \
  523. func(has_llc) sep \
  524. func(has_ddi) sep \
  525. func(has_fpga_dbg)
  526. #define DEFINE_FLAG(name) u8 name:1
  527. #define SEP_SEMICOLON ;
  528. struct intel_device_info {
  529. u32 display_mmio_offset;
  530. u16 device_id;
  531. u8 num_pipes:3;
  532. u8 num_sprites[I915_MAX_PIPES];
  533. u8 gen;
  534. u8 ring_mask; /* Rings supported by the HW */
  535. DEV_INFO_FOR_EACH_FLAG(DEFINE_FLAG, SEP_SEMICOLON);
  536. /* Register offsets for the various display pipes and transcoders */
  537. int pipe_offsets[I915_MAX_TRANSCODERS];
  538. int trans_offsets[I915_MAX_TRANSCODERS];
  539. int palette_offsets[I915_MAX_PIPES];
  540. int cursor_offsets[I915_MAX_PIPES];
  541. };
  542. #undef DEFINE_FLAG
  543. #undef SEP_SEMICOLON
  544. enum i915_cache_level {
  545. I915_CACHE_NONE = 0,
  546. I915_CACHE_LLC, /* also used for snoopable memory on non-LLC */
  547. I915_CACHE_L3_LLC, /* gen7+, L3 sits between the domain specifc
  548. caches, eg sampler/render caches, and the
  549. large Last-Level-Cache. LLC is coherent with
  550. the CPU, but L3 is only visible to the GPU. */
  551. I915_CACHE_WT, /* hsw:gt3e WriteThrough for scanouts */
  552. };
  553. struct i915_ctx_hang_stats {
  554. /* This context had batch pending when hang was declared */
  555. unsigned batch_pending;
  556. /* This context had batch active when hang was declared */
  557. unsigned batch_active;
  558. /* Time when this context was last blamed for a GPU reset */
  559. unsigned long guilty_ts;
  560. /* This context is banned to submit more work */
  561. bool banned;
  562. };
  563. /* This must match up with the value previously used for execbuf2.rsvd1. */
  564. #define DEFAULT_CONTEXT_HANDLE 0
  565. /**
  566. * struct intel_context - as the name implies, represents a context.
  567. * @ref: reference count.
  568. * @user_handle: userspace tracking identity for this context.
  569. * @remap_slice: l3 row remapping information.
  570. * @file_priv: filp associated with this context (NULL for global default
  571. * context).
  572. * @hang_stats: information about the role of this context in possible GPU
  573. * hangs.
  574. * @vm: virtual memory space used by this context.
  575. * @legacy_hw_ctx: render context backing object and whether it is correctly
  576. * initialized (legacy ring submission mechanism only).
  577. * @link: link in the global list of contexts.
  578. *
  579. * Contexts are memory images used by the hardware to store copies of their
  580. * internal state.
  581. */
  582. struct intel_context {
  583. struct kref ref;
  584. int user_handle;
  585. uint8_t remap_slice;
  586. struct drm_i915_file_private *file_priv;
  587. struct i915_ctx_hang_stats hang_stats;
  588. struct i915_hw_ppgtt *ppgtt;
  589. /* Legacy ring buffer submission */
  590. struct {
  591. struct drm_i915_gem_object *rcs_state;
  592. bool initialized;
  593. } legacy_hw_ctx;
  594. /* Execlists */
  595. bool rcs_initialized;
  596. struct {
  597. struct drm_i915_gem_object *state;
  598. struct intel_ringbuffer *ringbuf;
  599. int unpin_count;
  600. } engine[I915_NUM_RINGS];
  601. struct list_head link;
  602. };
  603. struct i915_fbc {
  604. unsigned long size;
  605. unsigned threshold;
  606. unsigned int fb_id;
  607. enum plane plane;
  608. int y;
  609. struct drm_mm_node compressed_fb;
  610. struct drm_mm_node *compressed_llb;
  611. bool false_color;
  612. /* Tracks whether the HW is actually enabled, not whether the feature is
  613. * possible. */
  614. bool enabled;
  615. /* On gen8 some rings cannont perform fbc clean operation so for now
  616. * we are doing this on SW with mmio.
  617. * This variable works in the opposite information direction
  618. * of ring->fbc_dirty telling software on frontbuffer tracking
  619. * to perform the cache clean on sw side.
  620. */
  621. bool need_sw_cache_clean;
  622. struct intel_fbc_work {
  623. struct delayed_work work;
  624. struct drm_crtc *crtc;
  625. struct drm_framebuffer *fb;
  626. } *fbc_work;
  627. enum no_fbc_reason {
  628. FBC_OK, /* FBC is enabled */
  629. FBC_UNSUPPORTED, /* FBC is not supported by this chipset */
  630. FBC_NO_OUTPUT, /* no outputs enabled to compress */
  631. FBC_STOLEN_TOO_SMALL, /* not enough space for buffers */
  632. FBC_UNSUPPORTED_MODE, /* interlace or doublescanned mode */
  633. FBC_MODE_TOO_LARGE, /* mode too large for compression */
  634. FBC_BAD_PLANE, /* fbc not supported on plane */
  635. FBC_NOT_TILED, /* buffer not tiled */
  636. FBC_MULTIPLE_PIPES, /* more than one pipe active */
  637. FBC_MODULE_PARAM,
  638. FBC_CHIP_DEFAULT, /* disabled by default on this chip */
  639. } no_fbc_reason;
  640. };
  641. struct i915_drrs {
  642. struct intel_connector *connector;
  643. };
  644. struct intel_dp;
  645. struct i915_psr {
  646. struct mutex lock;
  647. bool sink_support;
  648. bool source_ok;
  649. struct intel_dp *enabled;
  650. bool active;
  651. struct delayed_work work;
  652. unsigned busy_frontbuffer_bits;
  653. };
  654. enum intel_pch {
  655. PCH_NONE = 0, /* No PCH present */
  656. PCH_IBX, /* Ibexpeak PCH */
  657. PCH_CPT, /* Cougarpoint PCH */
  658. PCH_LPT, /* Lynxpoint PCH */
  659. PCH_SPT, /* Sunrisepoint PCH */
  660. PCH_NOP,
  661. };
  662. enum intel_sbi_destination {
  663. SBI_ICLK,
  664. SBI_MPHY,
  665. };
  666. #define QUIRK_PIPEA_FORCE (1<<0)
  667. #define QUIRK_LVDS_SSC_DISABLE (1<<1)
  668. #define QUIRK_INVERT_BRIGHTNESS (1<<2)
  669. #define QUIRK_BACKLIGHT_PRESENT (1<<3)
  670. #define QUIRK_PIPEB_FORCE (1<<4)
  671. #define QUIRK_PIN_SWIZZLED_PAGES (1<<5)
  672. struct intel_fbdev;
  673. struct intel_fbc_work;
  674. struct intel_gmbus {
  675. struct i2c_adapter adapter;
  676. u32 force_bit;
  677. u32 reg0;
  678. u32 gpio_reg;
  679. struct i2c_algo_bit_data bit_algo;
  680. struct drm_i915_private *dev_priv;
  681. };
  682. struct i915_suspend_saved_registers {
  683. u8 saveLBB;
  684. u32 saveDSPACNTR;
  685. u32 saveDSPBCNTR;
  686. u32 saveDSPARB;
  687. u32 savePIPEACONF;
  688. u32 savePIPEBCONF;
  689. u32 savePIPEASRC;
  690. u32 savePIPEBSRC;
  691. u32 saveFPA0;
  692. u32 saveFPA1;
  693. u32 saveDPLL_A;
  694. u32 saveDPLL_A_MD;
  695. u32 saveHTOTAL_A;
  696. u32 saveHBLANK_A;
  697. u32 saveHSYNC_A;
  698. u32 saveVTOTAL_A;
  699. u32 saveVBLANK_A;
  700. u32 saveVSYNC_A;
  701. u32 saveBCLRPAT_A;
  702. u32 saveTRANSACONF;
  703. u32 saveTRANS_HTOTAL_A;
  704. u32 saveTRANS_HBLANK_A;
  705. u32 saveTRANS_HSYNC_A;
  706. u32 saveTRANS_VTOTAL_A;
  707. u32 saveTRANS_VBLANK_A;
  708. u32 saveTRANS_VSYNC_A;
  709. u32 savePIPEASTAT;
  710. u32 saveDSPASTRIDE;
  711. u32 saveDSPASIZE;
  712. u32 saveDSPAPOS;
  713. u32 saveDSPAADDR;
  714. u32 saveDSPASURF;
  715. u32 saveDSPATILEOFF;
  716. u32 savePFIT_PGM_RATIOS;
  717. u32 saveBLC_HIST_CTL;
  718. u32 saveBLC_PWM_CTL;
  719. u32 saveBLC_PWM_CTL2;
  720. u32 saveBLC_CPU_PWM_CTL;
  721. u32 saveBLC_CPU_PWM_CTL2;
  722. u32 saveFPB0;
  723. u32 saveFPB1;
  724. u32 saveDPLL_B;
  725. u32 saveDPLL_B_MD;
  726. u32 saveHTOTAL_B;
  727. u32 saveHBLANK_B;
  728. u32 saveHSYNC_B;
  729. u32 saveVTOTAL_B;
  730. u32 saveVBLANK_B;
  731. u32 saveVSYNC_B;
  732. u32 saveBCLRPAT_B;
  733. u32 saveTRANSBCONF;
  734. u32 saveTRANS_HTOTAL_B;
  735. u32 saveTRANS_HBLANK_B;
  736. u32 saveTRANS_HSYNC_B;
  737. u32 saveTRANS_VTOTAL_B;
  738. u32 saveTRANS_VBLANK_B;
  739. u32 saveTRANS_VSYNC_B;
  740. u32 savePIPEBSTAT;
  741. u32 saveDSPBSTRIDE;
  742. u32 saveDSPBSIZE;
  743. u32 saveDSPBPOS;
  744. u32 saveDSPBADDR;
  745. u32 saveDSPBSURF;
  746. u32 saveDSPBTILEOFF;
  747. u32 saveVGA0;
  748. u32 saveVGA1;
  749. u32 saveVGA_PD;
  750. u32 saveVGACNTRL;
  751. u32 saveADPA;
  752. u32 saveLVDS;
  753. u32 savePP_ON_DELAYS;
  754. u32 savePP_OFF_DELAYS;
  755. u32 saveDVOA;
  756. u32 saveDVOB;
  757. u32 saveDVOC;
  758. u32 savePP_ON;
  759. u32 savePP_OFF;
  760. u32 savePP_CONTROL;
  761. u32 savePP_DIVISOR;
  762. u32 savePFIT_CONTROL;
  763. u32 save_palette_a[256];
  764. u32 save_palette_b[256];
  765. u32 saveFBC_CONTROL;
  766. u32 saveIER;
  767. u32 saveIIR;
  768. u32 saveIMR;
  769. u32 saveDEIER;
  770. u32 saveDEIMR;
  771. u32 saveGTIER;
  772. u32 saveGTIMR;
  773. u32 saveFDI_RXA_IMR;
  774. u32 saveFDI_RXB_IMR;
  775. u32 saveCACHE_MODE_0;
  776. u32 saveMI_ARB_STATE;
  777. u32 saveSWF0[16];
  778. u32 saveSWF1[16];
  779. u32 saveSWF2[3];
  780. u8 saveMSR;
  781. u8 saveSR[8];
  782. u8 saveGR[25];
  783. u8 saveAR_INDEX;
  784. u8 saveAR[21];
  785. u8 saveDACMASK;
  786. u8 saveCR[37];
  787. uint64_t saveFENCE[I915_MAX_NUM_FENCES];
  788. u32 saveCURACNTR;
  789. u32 saveCURAPOS;
  790. u32 saveCURABASE;
  791. u32 saveCURBCNTR;
  792. u32 saveCURBPOS;
  793. u32 saveCURBBASE;
  794. u32 saveCURSIZE;
  795. u32 saveDP_B;
  796. u32 saveDP_C;
  797. u32 saveDP_D;
  798. u32 savePIPEA_GMCH_DATA_M;
  799. u32 savePIPEB_GMCH_DATA_M;
  800. u32 savePIPEA_GMCH_DATA_N;
  801. u32 savePIPEB_GMCH_DATA_N;
  802. u32 savePIPEA_DP_LINK_M;
  803. u32 savePIPEB_DP_LINK_M;
  804. u32 savePIPEA_DP_LINK_N;
  805. u32 savePIPEB_DP_LINK_N;
  806. u32 saveFDI_RXA_CTL;
  807. u32 saveFDI_TXA_CTL;
  808. u32 saveFDI_RXB_CTL;
  809. u32 saveFDI_TXB_CTL;
  810. u32 savePFA_CTL_1;
  811. u32 savePFB_CTL_1;
  812. u32 savePFA_WIN_SZ;
  813. u32 savePFB_WIN_SZ;
  814. u32 savePFA_WIN_POS;
  815. u32 savePFB_WIN_POS;
  816. u32 savePCH_DREF_CONTROL;
  817. u32 saveDISP_ARB_CTL;
  818. u32 savePIPEA_DATA_M1;
  819. u32 savePIPEA_DATA_N1;
  820. u32 savePIPEA_LINK_M1;
  821. u32 savePIPEA_LINK_N1;
  822. u32 savePIPEB_DATA_M1;
  823. u32 savePIPEB_DATA_N1;
  824. u32 savePIPEB_LINK_M1;
  825. u32 savePIPEB_LINK_N1;
  826. u32 saveMCHBAR_RENDER_STANDBY;
  827. u32 savePCH_PORT_HOTPLUG;
  828. u16 saveGCDGMBUS;
  829. };
  830. struct vlv_s0ix_state {
  831. /* GAM */
  832. u32 wr_watermark;
  833. u32 gfx_prio_ctrl;
  834. u32 arb_mode;
  835. u32 gfx_pend_tlb0;
  836. u32 gfx_pend_tlb1;
  837. u32 lra_limits[GEN7_LRA_LIMITS_REG_NUM];
  838. u32 media_max_req_count;
  839. u32 gfx_max_req_count;
  840. u32 render_hwsp;
  841. u32 ecochk;
  842. u32 bsd_hwsp;
  843. u32 blt_hwsp;
  844. u32 tlb_rd_addr;
  845. /* MBC */
  846. u32 g3dctl;
  847. u32 gsckgctl;
  848. u32 mbctl;
  849. /* GCP */
  850. u32 ucgctl1;
  851. u32 ucgctl3;
  852. u32 rcgctl1;
  853. u32 rcgctl2;
  854. u32 rstctl;
  855. u32 misccpctl;
  856. /* GPM */
  857. u32 gfxpause;
  858. u32 rpdeuhwtc;
  859. u32 rpdeuc;
  860. u32 ecobus;
  861. u32 pwrdwnupctl;
  862. u32 rp_down_timeout;
  863. u32 rp_deucsw;
  864. u32 rcubmabdtmr;
  865. u32 rcedata;
  866. u32 spare2gh;
  867. /* Display 1 CZ domain */
  868. u32 gt_imr;
  869. u32 gt_ier;
  870. u32 pm_imr;
  871. u32 pm_ier;
  872. u32 gt_scratch[GEN7_GT_SCRATCH_REG_NUM];
  873. /* GT SA CZ domain */
  874. u32 tilectl;
  875. u32 gt_fifoctl;
  876. u32 gtlc_wake_ctrl;
  877. u32 gtlc_survive;
  878. u32 pmwgicz;
  879. /* Display 2 CZ domain */
  880. u32 gu_ctl0;
  881. u32 gu_ctl1;
  882. u32 clock_gate_dis2;
  883. };
  884. struct intel_rps_ei {
  885. u32 cz_clock;
  886. u32 render_c0;
  887. u32 media_c0;
  888. };
  889. struct intel_gen6_power_mgmt {
  890. /*
  891. * work, interrupts_enabled and pm_iir are protected by
  892. * dev_priv->irq_lock
  893. */
  894. struct work_struct work;
  895. bool interrupts_enabled;
  896. u32 pm_iir;
  897. /* Frequencies are stored in potentially platform dependent multiples.
  898. * In other words, *_freq needs to be multiplied by X to be interesting.
  899. * Soft limits are those which are used for the dynamic reclocking done
  900. * by the driver (raise frequencies under heavy loads, and lower for
  901. * lighter loads). Hard limits are those imposed by the hardware.
  902. *
  903. * A distinction is made for overclocking, which is never enabled by
  904. * default, and is considered to be above the hard limit if it's
  905. * possible at all.
  906. */
  907. u8 cur_freq; /* Current frequency (cached, may not == HW) */
  908. u8 min_freq_softlimit; /* Minimum frequency permitted by the driver */
  909. u8 max_freq_softlimit; /* Max frequency permitted by the driver */
  910. u8 max_freq; /* Maximum frequency, RP0 if not overclocking */
  911. u8 min_freq; /* AKA RPn. Minimum frequency */
  912. u8 efficient_freq; /* AKA RPe. Pre-determined balanced frequency */
  913. u8 rp1_freq; /* "less than" RP0 power/freqency */
  914. u8 rp0_freq; /* Non-overclocked max frequency. */
  915. u32 cz_freq;
  916. u32 ei_interrupt_count;
  917. int last_adj;
  918. enum { LOW_POWER, BETWEEN, HIGH_POWER } power;
  919. bool enabled;
  920. struct delayed_work delayed_resume_work;
  921. /* manual wa residency calculations */
  922. struct intel_rps_ei up_ei, down_ei;
  923. /*
  924. * Protects RPS/RC6 register access and PCU communication.
  925. * Must be taken after struct_mutex if nested.
  926. */
  927. struct mutex hw_lock;
  928. };
  929. /* defined intel_pm.c */
  930. extern spinlock_t mchdev_lock;
  931. struct intel_ilk_power_mgmt {
  932. u8 cur_delay;
  933. u8 min_delay;
  934. u8 max_delay;
  935. u8 fmax;
  936. u8 fstart;
  937. u64 last_count1;
  938. unsigned long last_time1;
  939. unsigned long chipset_power;
  940. u64 last_count2;
  941. u64 last_time2;
  942. unsigned long gfx_power;
  943. u8 corr;
  944. int c_m;
  945. int r_t;
  946. struct drm_i915_gem_object *pwrctx;
  947. struct drm_i915_gem_object *renderctx;
  948. };
  949. struct drm_i915_private;
  950. struct i915_power_well;
  951. struct i915_power_well_ops {
  952. /*
  953. * Synchronize the well's hw state to match the current sw state, for
  954. * example enable/disable it based on the current refcount. Called
  955. * during driver init and resume time, possibly after first calling
  956. * the enable/disable handlers.
  957. */
  958. void (*sync_hw)(struct drm_i915_private *dev_priv,
  959. struct i915_power_well *power_well);
  960. /*
  961. * Enable the well and resources that depend on it (for example
  962. * interrupts located on the well). Called after the 0->1 refcount
  963. * transition.
  964. */
  965. void (*enable)(struct drm_i915_private *dev_priv,
  966. struct i915_power_well *power_well);
  967. /*
  968. * Disable the well and resources that depend on it. Called after
  969. * the 1->0 refcount transition.
  970. */
  971. void (*disable)(struct drm_i915_private *dev_priv,
  972. struct i915_power_well *power_well);
  973. /* Returns the hw enabled state. */
  974. bool (*is_enabled)(struct drm_i915_private *dev_priv,
  975. struct i915_power_well *power_well);
  976. };
  977. /* Power well structure for haswell */
  978. struct i915_power_well {
  979. const char *name;
  980. bool always_on;
  981. /* power well enable/disable usage count */
  982. int count;
  983. /* cached hw enabled state */
  984. bool hw_enabled;
  985. unsigned long domains;
  986. unsigned long data;
  987. const struct i915_power_well_ops *ops;
  988. };
  989. struct i915_power_domains {
  990. /*
  991. * Power wells needed for initialization at driver init and suspend
  992. * time are on. They are kept on until after the first modeset.
  993. */
  994. bool init_power_on;
  995. bool initializing;
  996. int power_well_count;
  997. struct mutex lock;
  998. int domain_use_count[POWER_DOMAIN_NUM];
  999. struct i915_power_well *power_wells;
  1000. };
  1001. #define MAX_L3_SLICES 2
  1002. struct intel_l3_parity {
  1003. u32 *remap_info[MAX_L3_SLICES];
  1004. struct work_struct error_work;
  1005. int which_slice;
  1006. };
  1007. struct i915_gem_mm {
  1008. /** Memory allocator for GTT stolen memory */
  1009. struct drm_mm stolen;
  1010. /** List of all objects in gtt_space. Used to restore gtt
  1011. * mappings on resume */
  1012. struct list_head bound_list;
  1013. /**
  1014. * List of objects which are not bound to the GTT (thus
  1015. * are idle and not used by the GPU) but still have
  1016. * (presumably uncached) pages still attached.
  1017. */
  1018. struct list_head unbound_list;
  1019. /** Usable portion of the GTT for GEM */
  1020. unsigned long stolen_base; /* limited to low memory (32-bit) */
  1021. /** PPGTT used for aliasing the PPGTT with the GTT */
  1022. struct i915_hw_ppgtt *aliasing_ppgtt;
  1023. struct notifier_block oom_notifier;
  1024. struct shrinker shrinker;
  1025. bool shrinker_no_lock_stealing;
  1026. /** LRU list of objects with fence regs on them. */
  1027. struct list_head fence_list;
  1028. /**
  1029. * We leave the user IRQ off as much as possible,
  1030. * but this means that requests will finish and never
  1031. * be retired once the system goes idle. Set a timer to
  1032. * fire periodically while the ring is running. When it
  1033. * fires, go retire requests.
  1034. */
  1035. struct delayed_work retire_work;
  1036. /**
  1037. * When we detect an idle GPU, we want to turn on
  1038. * powersaving features. So once we see that there
  1039. * are no more requests outstanding and no more
  1040. * arrive within a small period of time, we fire
  1041. * off the idle_work.
  1042. */
  1043. struct delayed_work idle_work;
  1044. /**
  1045. * Are we in a non-interruptible section of code like
  1046. * modesetting?
  1047. */
  1048. bool interruptible;
  1049. /**
  1050. * Is the GPU currently considered idle, or busy executing userspace
  1051. * requests? Whilst idle, we attempt to power down the hardware and
  1052. * display clocks. In order to reduce the effect on performance, there
  1053. * is a slight delay before we do so.
  1054. */
  1055. bool busy;
  1056. /* the indicator for dispatch video commands on two BSD rings */
  1057. int bsd_ring_dispatch_index;
  1058. /** Bit 6 swizzling required for X tiling */
  1059. uint32_t bit_6_swizzle_x;
  1060. /** Bit 6 swizzling required for Y tiling */
  1061. uint32_t bit_6_swizzle_y;
  1062. /* accounting, useful for userland debugging */
  1063. spinlock_t object_stat_lock;
  1064. size_t object_memory;
  1065. u32 object_count;
  1066. };
  1067. struct drm_i915_error_state_buf {
  1068. struct drm_i915_private *i915;
  1069. unsigned bytes;
  1070. unsigned size;
  1071. int err;
  1072. u8 *buf;
  1073. loff_t start;
  1074. loff_t pos;
  1075. };
  1076. struct i915_error_state_file_priv {
  1077. struct drm_device *dev;
  1078. struct drm_i915_error_state *error;
  1079. };
  1080. struct i915_gpu_error {
  1081. /* For hangcheck timer */
  1082. #define DRM_I915_HANGCHECK_PERIOD 1500 /* in ms */
  1083. #define DRM_I915_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD)
  1084. /* Hang gpu twice in this window and your context gets banned */
  1085. #define DRM_I915_CTX_BAN_PERIOD DIV_ROUND_UP(8*DRM_I915_HANGCHECK_PERIOD, 1000)
  1086. struct timer_list hangcheck_timer;
  1087. /* For reset and error_state handling. */
  1088. spinlock_t lock;
  1089. /* Protected by the above dev->gpu_error.lock. */
  1090. struct drm_i915_error_state *first_error;
  1091. struct work_struct work;
  1092. unsigned long missed_irq_rings;
  1093. /**
  1094. * State variable controlling the reset flow and count
  1095. *
  1096. * This is a counter which gets incremented when reset is triggered,
  1097. * and again when reset has been handled. So odd values (lowest bit set)
  1098. * means that reset is in progress and even values that
  1099. * (reset_counter >> 1):th reset was successfully completed.
  1100. *
  1101. * If reset is not completed succesfully, the I915_WEDGE bit is
  1102. * set meaning that hardware is terminally sour and there is no
  1103. * recovery. All waiters on the reset_queue will be woken when
  1104. * that happens.
  1105. *
  1106. * This counter is used by the wait_seqno code to notice that reset
  1107. * event happened and it needs to restart the entire ioctl (since most
  1108. * likely the seqno it waited for won't ever signal anytime soon).
  1109. *
  1110. * This is important for lock-free wait paths, where no contended lock
  1111. * naturally enforces the correct ordering between the bail-out of the
  1112. * waiter and the gpu reset work code.
  1113. */
  1114. atomic_t reset_counter;
  1115. #define I915_RESET_IN_PROGRESS_FLAG 1
  1116. #define I915_WEDGED (1 << 31)
  1117. /**
  1118. * Waitqueue to signal when the reset has completed. Used by clients
  1119. * that wait for dev_priv->mm.wedged to settle.
  1120. */
  1121. wait_queue_head_t reset_queue;
  1122. /* Userspace knobs for gpu hang simulation;
  1123. * combines both a ring mask, and extra flags
  1124. */
  1125. u32 stop_rings;
  1126. #define I915_STOP_RING_ALLOW_BAN (1 << 31)
  1127. #define I915_STOP_RING_ALLOW_WARN (1 << 30)
  1128. /* For missed irq/seqno simulation. */
  1129. unsigned int test_irq_rings;
  1130. /* Used to prevent gem_check_wedged returning -EAGAIN during gpu reset */
  1131. bool reload_in_reset;
  1132. };
  1133. enum modeset_restore {
  1134. MODESET_ON_LID_OPEN,
  1135. MODESET_DONE,
  1136. MODESET_SUSPENDED,
  1137. };
  1138. struct ddi_vbt_port_info {
  1139. /*
  1140. * This is an index in the HDMI/DVI DDI buffer translation table.
  1141. * The special value HDMI_LEVEL_SHIFT_UNKNOWN means the VBT didn't
  1142. * populate this field.
  1143. */
  1144. #define HDMI_LEVEL_SHIFT_UNKNOWN 0xff
  1145. uint8_t hdmi_level_shift;
  1146. uint8_t supports_dvi:1;
  1147. uint8_t supports_hdmi:1;
  1148. uint8_t supports_dp:1;
  1149. };
  1150. enum drrs_support_type {
  1151. DRRS_NOT_SUPPORTED = 0,
  1152. STATIC_DRRS_SUPPORT = 1,
  1153. SEAMLESS_DRRS_SUPPORT = 2
  1154. };
  1155. struct intel_vbt_data {
  1156. struct drm_display_mode *lfp_lvds_vbt_mode; /* if any */
  1157. struct drm_display_mode *sdvo_lvds_vbt_mode; /* if any */
  1158. /* Feature bits */
  1159. unsigned int int_tv_support:1;
  1160. unsigned int lvds_dither:1;
  1161. unsigned int lvds_vbt:1;
  1162. unsigned int int_crt_support:1;
  1163. unsigned int lvds_use_ssc:1;
  1164. unsigned int display_clock_mode:1;
  1165. unsigned int fdi_rx_polarity_inverted:1;
  1166. unsigned int has_mipi:1;
  1167. int lvds_ssc_freq;
  1168. unsigned int bios_lvds_val; /* initial [PCH_]LVDS reg val in VBIOS */
  1169. enum drrs_support_type drrs_type;
  1170. /* eDP */
  1171. int edp_rate;
  1172. int edp_lanes;
  1173. int edp_preemphasis;
  1174. int edp_vswing;
  1175. bool edp_initialized;
  1176. bool edp_support;
  1177. int edp_bpp;
  1178. struct edp_power_seq edp_pps;
  1179. struct {
  1180. u16 pwm_freq_hz;
  1181. bool present;
  1182. bool active_low_pwm;
  1183. u8 min_brightness; /* min_brightness/255 of max */
  1184. } backlight;
  1185. /* MIPI DSI */
  1186. struct {
  1187. u16 port;
  1188. u16 panel_id;
  1189. struct mipi_config *config;
  1190. struct mipi_pps_data *pps;
  1191. u8 seq_version;
  1192. u32 size;
  1193. u8 *data;
  1194. u8 *sequence[MIPI_SEQ_MAX];
  1195. } dsi;
  1196. int crt_ddc_pin;
  1197. int child_dev_num;
  1198. union child_device_config *child_dev;
  1199. struct ddi_vbt_port_info ddi_port_info[I915_MAX_PORTS];
  1200. };
  1201. enum intel_ddb_partitioning {
  1202. INTEL_DDB_PART_1_2,
  1203. INTEL_DDB_PART_5_6, /* IVB+ */
  1204. };
  1205. struct intel_wm_level {
  1206. bool enable;
  1207. uint32_t pri_val;
  1208. uint32_t spr_val;
  1209. uint32_t cur_val;
  1210. uint32_t fbc_val;
  1211. };
  1212. struct ilk_wm_values {
  1213. uint32_t wm_pipe[3];
  1214. uint32_t wm_lp[3];
  1215. uint32_t wm_lp_spr[3];
  1216. uint32_t wm_linetime[3];
  1217. bool enable_fbc_wm;
  1218. enum intel_ddb_partitioning partitioning;
  1219. };
  1220. struct skl_ddb_entry {
  1221. uint16_t start, end; /* in number of blocks, 'end' is exclusive */
  1222. };
  1223. static inline uint16_t skl_ddb_entry_size(const struct skl_ddb_entry *entry)
  1224. {
  1225. return entry->end - entry->start;
  1226. }
  1227. static inline bool skl_ddb_entry_equal(const struct skl_ddb_entry *e1,
  1228. const struct skl_ddb_entry *e2)
  1229. {
  1230. if (e1->start == e2->start && e1->end == e2->end)
  1231. return true;
  1232. return false;
  1233. }
  1234. struct skl_ddb_allocation {
  1235. struct skl_ddb_entry pipe[I915_MAX_PIPES];
  1236. struct skl_ddb_entry plane[I915_MAX_PIPES][I915_MAX_PLANES];
  1237. struct skl_ddb_entry cursor[I915_MAX_PIPES];
  1238. };
  1239. struct skl_wm_values {
  1240. bool dirty[I915_MAX_PIPES];
  1241. struct skl_ddb_allocation ddb;
  1242. uint32_t wm_linetime[I915_MAX_PIPES];
  1243. uint32_t plane[I915_MAX_PIPES][I915_MAX_PLANES][8];
  1244. uint32_t cursor[I915_MAX_PIPES][8];
  1245. uint32_t plane_trans[I915_MAX_PIPES][I915_MAX_PLANES];
  1246. uint32_t cursor_trans[I915_MAX_PIPES];
  1247. };
  1248. struct skl_wm_level {
  1249. bool plane_en[I915_MAX_PLANES];
  1250. bool cursor_en;
  1251. uint16_t plane_res_b[I915_MAX_PLANES];
  1252. uint8_t plane_res_l[I915_MAX_PLANES];
  1253. uint16_t cursor_res_b;
  1254. uint8_t cursor_res_l;
  1255. };
  1256. /*
  1257. * This struct helps tracking the state needed for runtime PM, which puts the
  1258. * device in PCI D3 state. Notice that when this happens, nothing on the
  1259. * graphics device works, even register access, so we don't get interrupts nor
  1260. * anything else.
  1261. *
  1262. * Every piece of our code that needs to actually touch the hardware needs to
  1263. * either call intel_runtime_pm_get or call intel_display_power_get with the
  1264. * appropriate power domain.
  1265. *
  1266. * Our driver uses the autosuspend delay feature, which means we'll only really
  1267. * suspend if we stay with zero refcount for a certain amount of time. The
  1268. * default value is currently very conservative (see intel_runtime_pm_enable), but
  1269. * it can be changed with the standard runtime PM files from sysfs.
  1270. *
  1271. * The irqs_disabled variable becomes true exactly after we disable the IRQs and
  1272. * goes back to false exactly before we reenable the IRQs. We use this variable
  1273. * to check if someone is trying to enable/disable IRQs while they're supposed
  1274. * to be disabled. This shouldn't happen and we'll print some error messages in
  1275. * case it happens.
  1276. *
  1277. * For more, read the Documentation/power/runtime_pm.txt.
  1278. */
  1279. struct i915_runtime_pm {
  1280. bool suspended;
  1281. bool irqs_enabled;
  1282. };
  1283. enum intel_pipe_crc_source {
  1284. INTEL_PIPE_CRC_SOURCE_NONE,
  1285. INTEL_PIPE_CRC_SOURCE_PLANE1,
  1286. INTEL_PIPE_CRC_SOURCE_PLANE2,
  1287. INTEL_PIPE_CRC_SOURCE_PF,
  1288. INTEL_PIPE_CRC_SOURCE_PIPE,
  1289. /* TV/DP on pre-gen5/vlv can't use the pipe source. */
  1290. INTEL_PIPE_CRC_SOURCE_TV,
  1291. INTEL_PIPE_CRC_SOURCE_DP_B,
  1292. INTEL_PIPE_CRC_SOURCE_DP_C,
  1293. INTEL_PIPE_CRC_SOURCE_DP_D,
  1294. INTEL_PIPE_CRC_SOURCE_AUTO,
  1295. INTEL_PIPE_CRC_SOURCE_MAX,
  1296. };
  1297. struct intel_pipe_crc_entry {
  1298. uint32_t frame;
  1299. uint32_t crc[5];
  1300. };
  1301. #define INTEL_PIPE_CRC_ENTRIES_NR 128
  1302. struct intel_pipe_crc {
  1303. spinlock_t lock;
  1304. bool opened; /* exclusive access to the result file */
  1305. struct intel_pipe_crc_entry *entries;
  1306. enum intel_pipe_crc_source source;
  1307. int head, tail;
  1308. wait_queue_head_t wq;
  1309. };
  1310. struct i915_frontbuffer_tracking {
  1311. struct mutex lock;
  1312. /*
  1313. * Tracking bits for delayed frontbuffer flushing du to gpu activity or
  1314. * scheduled flips.
  1315. */
  1316. unsigned busy_bits;
  1317. unsigned flip_bits;
  1318. };
  1319. struct i915_wa_reg {
  1320. u32 addr;
  1321. u32 value;
  1322. /* bitmask representing WA bits */
  1323. u32 mask;
  1324. };
  1325. #define I915_MAX_WA_REGS 16
  1326. struct i915_workarounds {
  1327. struct i915_wa_reg reg[I915_MAX_WA_REGS];
  1328. u32 count;
  1329. };
  1330. struct drm_i915_private {
  1331. struct drm_device *dev;
  1332. struct kmem_cache *slab;
  1333. const struct intel_device_info info;
  1334. int relative_constants_mode;
  1335. void __iomem *regs;
  1336. struct intel_uncore uncore;
  1337. struct intel_gmbus gmbus[GMBUS_NUM_PORTS];
  1338. /** gmbus_mutex protects against concurrent usage of the single hw gmbus
  1339. * controller on different i2c buses. */
  1340. struct mutex gmbus_mutex;
  1341. /**
  1342. * Base address of the gmbus and gpio block.
  1343. */
  1344. uint32_t gpio_mmio_base;
  1345. /* MMIO base address for MIPI regs */
  1346. uint32_t mipi_mmio_base;
  1347. wait_queue_head_t gmbus_wait_queue;
  1348. struct pci_dev *bridge_dev;
  1349. struct intel_engine_cs ring[I915_NUM_RINGS];
  1350. struct drm_i915_gem_object *semaphore_obj;
  1351. uint32_t last_seqno, next_seqno;
  1352. struct drm_dma_handle *status_page_dmah;
  1353. struct resource mch_res;
  1354. /* protects the irq masks */
  1355. spinlock_t irq_lock;
  1356. /* protects the mmio flip data */
  1357. spinlock_t mmio_flip_lock;
  1358. bool display_irqs_enabled;
  1359. /* To control wakeup latency, e.g. for irq-driven dp aux transfers. */
  1360. struct pm_qos_request pm_qos;
  1361. /* DPIO indirect register protection */
  1362. struct mutex dpio_lock;
  1363. /** Cached value of IMR to avoid reads in updating the bitfield */
  1364. union {
  1365. u32 irq_mask;
  1366. u32 de_irq_mask[I915_MAX_PIPES];
  1367. };
  1368. u32 gt_irq_mask;
  1369. u32 pm_irq_mask;
  1370. u32 pm_rps_events;
  1371. u32 pipestat_irq_mask[I915_MAX_PIPES];
  1372. struct work_struct hotplug_work;
  1373. struct {
  1374. unsigned long hpd_last_jiffies;
  1375. int hpd_cnt;
  1376. enum {
  1377. HPD_ENABLED = 0,
  1378. HPD_DISABLED = 1,
  1379. HPD_MARK_DISABLED = 2
  1380. } hpd_mark;
  1381. } hpd_stats[HPD_NUM_PINS];
  1382. u32 hpd_event_bits;
  1383. struct delayed_work hotplug_reenable_work;
  1384. struct i915_fbc fbc;
  1385. struct i915_drrs drrs;
  1386. struct intel_opregion opregion;
  1387. struct intel_vbt_data vbt;
  1388. bool preserve_bios_swizzle;
  1389. /* overlay */
  1390. struct intel_overlay *overlay;
  1391. /* backlight registers and fields in struct intel_panel */
  1392. struct mutex backlight_lock;
  1393. /* LVDS info */
  1394. bool no_aux_handshake;
  1395. /* protects panel power sequencer state */
  1396. struct mutex pps_mutex;
  1397. struct drm_i915_fence_reg fence_regs[I915_MAX_NUM_FENCES]; /* assume 965 */
  1398. int fence_reg_start; /* 4 if userland hasn't ioctl'd us yet */
  1399. int num_fence_regs; /* 8 on pre-965, 16 otherwise */
  1400. unsigned int fsb_freq, mem_freq, is_ddr3;
  1401. unsigned int vlv_cdclk_freq;
  1402. unsigned int hpll_freq;
  1403. /**
  1404. * wq - Driver workqueue for GEM.
  1405. *
  1406. * NOTE: Work items scheduled here are not allowed to grab any modeset
  1407. * locks, for otherwise the flushing done in the pageflip code will
  1408. * result in deadlocks.
  1409. */
  1410. struct workqueue_struct *wq;
  1411. /* Display functions */
  1412. struct drm_i915_display_funcs display;
  1413. /* PCH chipset type */
  1414. enum intel_pch pch_type;
  1415. unsigned short pch_id;
  1416. unsigned long quirks;
  1417. enum modeset_restore modeset_restore;
  1418. struct mutex modeset_restore_lock;
  1419. struct list_head vm_list; /* Global list of all address spaces */
  1420. struct i915_gtt gtt; /* VM representing the global address space */
  1421. struct i915_gem_mm mm;
  1422. DECLARE_HASHTABLE(mm_structs, 7);
  1423. struct mutex mm_lock;
  1424. /* Kernel Modesetting */
  1425. struct sdvo_device_mapping sdvo_mappings[2];
  1426. struct drm_crtc *plane_to_crtc_mapping[I915_MAX_PIPES];
  1427. struct drm_crtc *pipe_to_crtc_mapping[I915_MAX_PIPES];
  1428. wait_queue_head_t pending_flip_queue;
  1429. #ifdef CONFIG_DEBUG_FS
  1430. struct intel_pipe_crc pipe_crc[I915_MAX_PIPES];
  1431. #endif
  1432. int num_shared_dpll;
  1433. struct intel_shared_dpll shared_dplls[I915_NUM_PLLS];
  1434. int dpio_phy_iosf_port[I915_NUM_PHYS_VLV];
  1435. struct i915_workarounds workarounds;
  1436. /* Reclocking support */
  1437. bool render_reclock_avail;
  1438. bool lvds_downclock_avail;
  1439. /* indicates the reduced downclock for LVDS*/
  1440. int lvds_downclock;
  1441. struct i915_frontbuffer_tracking fb_tracking;
  1442. u16 orig_clock;
  1443. bool mchbar_need_disable;
  1444. struct intel_l3_parity l3_parity;
  1445. /* Cannot be determined by PCIID. You must always read a register. */
  1446. size_t ellc_size;
  1447. /* gen6+ rps state */
  1448. struct intel_gen6_power_mgmt rps;
  1449. /* ilk-only ips/rps state. Everything in here is protected by the global
  1450. * mchdev_lock in intel_pm.c */
  1451. struct intel_ilk_power_mgmt ips;
  1452. struct i915_power_domains power_domains;
  1453. struct i915_psr psr;
  1454. struct i915_gpu_error gpu_error;
  1455. struct drm_i915_gem_object *vlv_pctx;
  1456. #ifdef CONFIG_DRM_I915_FBDEV
  1457. /* list of fbdev register on this device */
  1458. struct intel_fbdev *fbdev;
  1459. struct work_struct fbdev_suspend_work;
  1460. #endif
  1461. struct drm_property *broadcast_rgb_property;
  1462. struct drm_property *force_audio_property;
  1463. uint32_t hw_context_size;
  1464. struct list_head context_list;
  1465. u32 fdi_rx_config;
  1466. u32 suspend_count;
  1467. struct i915_suspend_saved_registers regfile;
  1468. struct vlv_s0ix_state vlv_s0ix_state;
  1469. struct {
  1470. /*
  1471. * Raw watermark latency values:
  1472. * in 0.1us units for WM0,
  1473. * in 0.5us units for WM1+.
  1474. */
  1475. /* primary */
  1476. uint16_t pri_latency[5];
  1477. /* sprite */
  1478. uint16_t spr_latency[5];
  1479. /* cursor */
  1480. uint16_t cur_latency[5];
  1481. /*
  1482. * Raw watermark memory latency values
  1483. * for SKL for all 8 levels
  1484. * in 1us units.
  1485. */
  1486. uint16_t skl_latency[8];
  1487. /*
  1488. * The skl_wm_values structure is a bit too big for stack
  1489. * allocation, so we keep the staging struct where we store
  1490. * intermediate results here instead.
  1491. */
  1492. struct skl_wm_values skl_results;
  1493. /* current hardware state */
  1494. union {
  1495. struct ilk_wm_values hw;
  1496. struct skl_wm_values skl_hw;
  1497. };
  1498. } wm;
  1499. struct i915_runtime_pm pm;
  1500. struct intel_digital_port *hpd_irq_port[I915_MAX_PORTS];
  1501. u32 long_hpd_port_mask;
  1502. u32 short_hpd_port_mask;
  1503. struct work_struct dig_port_work;
  1504. /*
  1505. * if we get a HPD irq from DP and a HPD irq from non-DP
  1506. * the non-DP HPD could block the workqueue on a mode config
  1507. * mutex getting, that userspace may have taken. However
  1508. * userspace is waiting on the DP workqueue to run which is
  1509. * blocked behind the non-DP one.
  1510. */
  1511. struct workqueue_struct *dp_wq;
  1512. uint32_t bios_vgacntr;
  1513. /* Abstract the submission mechanism (legacy ringbuffer or execlists) away */
  1514. struct {
  1515. int (*do_execbuf)(struct drm_device *dev, struct drm_file *file,
  1516. struct intel_engine_cs *ring,
  1517. struct intel_context *ctx,
  1518. struct drm_i915_gem_execbuffer2 *args,
  1519. struct list_head *vmas,
  1520. struct drm_i915_gem_object *batch_obj,
  1521. u64 exec_start, u32 flags);
  1522. int (*init_rings)(struct drm_device *dev);
  1523. void (*cleanup_ring)(struct intel_engine_cs *ring);
  1524. void (*stop_ring)(struct intel_engine_cs *ring);
  1525. } gt;
  1526. /*
  1527. * NOTE: This is the dri1/ums dungeon, don't add stuff here. Your patch
  1528. * will be rejected. Instead look for a better place.
  1529. */
  1530. };
  1531. static inline struct drm_i915_private *to_i915(const struct drm_device *dev)
  1532. {
  1533. return dev->dev_private;
  1534. }
  1535. /* Iterate over initialised rings */
  1536. #define for_each_ring(ring__, dev_priv__, i__) \
  1537. for ((i__) = 0; (i__) < I915_NUM_RINGS; (i__)++) \
  1538. if (((ring__) = &(dev_priv__)->ring[(i__)]), intel_ring_initialized((ring__)))
  1539. enum hdmi_force_audio {
  1540. HDMI_AUDIO_OFF_DVI = -2, /* no aux data for HDMI-DVI converter */
  1541. HDMI_AUDIO_OFF, /* force turn off HDMI audio */
  1542. HDMI_AUDIO_AUTO, /* trust EDID */
  1543. HDMI_AUDIO_ON, /* force turn on HDMI audio */
  1544. };
  1545. #define I915_GTT_OFFSET_NONE ((u32)-1)
  1546. struct drm_i915_gem_object_ops {
  1547. /* Interface between the GEM object and its backing storage.
  1548. * get_pages() is called once prior to the use of the associated set
  1549. * of pages before to binding them into the GTT, and put_pages() is
  1550. * called after we no longer need them. As we expect there to be
  1551. * associated cost with migrating pages between the backing storage
  1552. * and making them available for the GPU (e.g. clflush), we may hold
  1553. * onto the pages after they are no longer referenced by the GPU
  1554. * in case they may be used again shortly (for example migrating the
  1555. * pages to a different memory domain within the GTT). put_pages()
  1556. * will therefore most likely be called when the object itself is
  1557. * being released or under memory pressure (where we attempt to
  1558. * reap pages for the shrinker).
  1559. */
  1560. int (*get_pages)(struct drm_i915_gem_object *);
  1561. void (*put_pages)(struct drm_i915_gem_object *);
  1562. int (*dmabuf_export)(struct drm_i915_gem_object *);
  1563. void (*release)(struct drm_i915_gem_object *);
  1564. };
  1565. /*
  1566. * Frontbuffer tracking bits. Set in obj->frontbuffer_bits while a gem bo is
  1567. * considered to be the frontbuffer for the given plane interface-vise. This
  1568. * doesn't mean that the hw necessarily already scans it out, but that any
  1569. * rendering (by the cpu or gpu) will land in the frontbuffer eventually.
  1570. *
  1571. * We have one bit per pipe and per scanout plane type.
  1572. */
  1573. #define INTEL_FRONTBUFFER_BITS_PER_PIPE 4
  1574. #define INTEL_FRONTBUFFER_BITS \
  1575. (INTEL_FRONTBUFFER_BITS_PER_PIPE * I915_MAX_PIPES)
  1576. #define INTEL_FRONTBUFFER_PRIMARY(pipe) \
  1577. (1 << (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe)))
  1578. #define INTEL_FRONTBUFFER_CURSOR(pipe) \
  1579. (1 << (1 +(INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))))
  1580. #define INTEL_FRONTBUFFER_SPRITE(pipe) \
  1581. (1 << (2 +(INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))))
  1582. #define INTEL_FRONTBUFFER_OVERLAY(pipe) \
  1583. (1 << (3 +(INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))))
  1584. #define INTEL_FRONTBUFFER_ALL_MASK(pipe) \
  1585. (0xf << (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe)))
  1586. struct drm_i915_gem_object {
  1587. struct drm_gem_object base;
  1588. const struct drm_i915_gem_object_ops *ops;
  1589. /** List of VMAs backed by this object */
  1590. struct list_head vma_list;
  1591. /** Stolen memory for this object, instead of being backed by shmem. */
  1592. struct drm_mm_node *stolen;
  1593. struct list_head global_list;
  1594. struct list_head ring_list;
  1595. /** Used in execbuf to temporarily hold a ref */
  1596. struct list_head obj_exec_link;
  1597. /**
  1598. * This is set if the object is on the active lists (has pending
  1599. * rendering and so a non-zero seqno), and is not set if it i s on
  1600. * inactive (ready to be unbound) list.
  1601. */
  1602. unsigned int active:1;
  1603. /**
  1604. * This is set if the object has been written to since last bound
  1605. * to the GTT
  1606. */
  1607. unsigned int dirty:1;
  1608. /**
  1609. * Fence register bits (if any) for this object. Will be set
  1610. * as needed when mapped into the GTT.
  1611. * Protected by dev->struct_mutex.
  1612. */
  1613. signed int fence_reg:I915_MAX_NUM_FENCE_BITS;
  1614. /**
  1615. * Advice: are the backing pages purgeable?
  1616. */
  1617. unsigned int madv:2;
  1618. /**
  1619. * Current tiling mode for the object.
  1620. */
  1621. unsigned int tiling_mode:2;
  1622. /**
  1623. * Whether the tiling parameters for the currently associated fence
  1624. * register have changed. Note that for the purposes of tracking
  1625. * tiling changes we also treat the unfenced register, the register
  1626. * slot that the object occupies whilst it executes a fenced
  1627. * command (such as BLT on gen2/3), as a "fence".
  1628. */
  1629. unsigned int fence_dirty:1;
  1630. /**
  1631. * Is the object at the current location in the gtt mappable and
  1632. * fenceable? Used to avoid costly recalculations.
  1633. */
  1634. unsigned int map_and_fenceable:1;
  1635. /**
  1636. * Whether the current gtt mapping needs to be mappable (and isn't just
  1637. * mappable by accident). Track pin and fault separate for a more
  1638. * accurate mappable working set.
  1639. */
  1640. unsigned int fault_mappable:1;
  1641. unsigned int pin_mappable:1;
  1642. unsigned int pin_display:1;
  1643. /*
  1644. * Is the object to be mapped as read-only to the GPU
  1645. * Only honoured if hardware has relevant pte bit
  1646. */
  1647. unsigned long gt_ro:1;
  1648. unsigned int cache_level:3;
  1649. unsigned int has_dma_mapping:1;
  1650. unsigned int frontbuffer_bits:INTEL_FRONTBUFFER_BITS;
  1651. struct sg_table *pages;
  1652. int pages_pin_count;
  1653. /* prime dma-buf support */
  1654. void *dma_buf_vmapping;
  1655. int vmapping_count;
  1656. struct intel_engine_cs *ring;
  1657. /** Breadcrumb of last rendering to the buffer. */
  1658. uint32_t last_read_seqno;
  1659. uint32_t last_write_seqno;
  1660. /** Breadcrumb of last fenced GPU access to the buffer. */
  1661. uint32_t last_fenced_seqno;
  1662. /** Current tiling stride for the object, if it's tiled. */
  1663. uint32_t stride;
  1664. /** References from framebuffers, locks out tiling changes. */
  1665. unsigned long framebuffer_references;
  1666. /** Record of address bit 17 of each page at last unbind. */
  1667. unsigned long *bit_17;
  1668. /** User space pin count and filp owning the pin */
  1669. unsigned long user_pin_count;
  1670. struct drm_file *pin_filp;
  1671. union {
  1672. /** for phy allocated objects */
  1673. struct drm_dma_handle *phys_handle;
  1674. struct i915_gem_userptr {
  1675. uintptr_t ptr;
  1676. unsigned read_only :1;
  1677. unsigned workers :4;
  1678. #define I915_GEM_USERPTR_MAX_WORKERS 15
  1679. struct i915_mm_struct *mm;
  1680. struct i915_mmu_object *mmu_object;
  1681. struct work_struct *work;
  1682. } userptr;
  1683. };
  1684. };
  1685. #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
  1686. void i915_gem_track_fb(struct drm_i915_gem_object *old,
  1687. struct drm_i915_gem_object *new,
  1688. unsigned frontbuffer_bits);
  1689. /**
  1690. * Request queue structure.
  1691. *
  1692. * The request queue allows us to note sequence numbers that have been emitted
  1693. * and may be associated with active buffers to be retired.
  1694. *
  1695. * By keeping this list, we can avoid having to do questionable
  1696. * sequence-number comparisons on buffer last_rendering_seqnos, and associate
  1697. * an emission time with seqnos for tracking how far ahead of the GPU we are.
  1698. */
  1699. struct drm_i915_gem_request {
  1700. /** On Which ring this request was generated */
  1701. struct intel_engine_cs *ring;
  1702. /** GEM sequence number associated with this request. */
  1703. uint32_t seqno;
  1704. /** Position in the ringbuffer of the start of the request */
  1705. u32 head;
  1706. /** Position in the ringbuffer of the end of the request */
  1707. u32 tail;
  1708. /** Context related to this request */
  1709. struct intel_context *ctx;
  1710. /** Batch buffer related to this request if any */
  1711. struct drm_i915_gem_object *batch_obj;
  1712. /** Time at which this request was emitted, in jiffies. */
  1713. unsigned long emitted_jiffies;
  1714. /** global list entry for this request */
  1715. struct list_head list;
  1716. struct drm_i915_file_private *file_priv;
  1717. /** file_priv list entry for this request */
  1718. struct list_head client_list;
  1719. };
  1720. struct drm_i915_file_private {
  1721. struct drm_i915_private *dev_priv;
  1722. struct drm_file *file;
  1723. struct {
  1724. spinlock_t lock;
  1725. struct list_head request_list;
  1726. struct delayed_work idle_work;
  1727. } mm;
  1728. struct idr context_idr;
  1729. atomic_t rps_wait_boost;
  1730. struct intel_engine_cs *bsd_ring;
  1731. };
  1732. /*
  1733. * A command that requires special handling by the command parser.
  1734. */
  1735. struct drm_i915_cmd_descriptor {
  1736. /*
  1737. * Flags describing how the command parser processes the command.
  1738. *
  1739. * CMD_DESC_FIXED: The command has a fixed length if this is set,
  1740. * a length mask if not set
  1741. * CMD_DESC_SKIP: The command is allowed but does not follow the
  1742. * standard length encoding for the opcode range in
  1743. * which it falls
  1744. * CMD_DESC_REJECT: The command is never allowed
  1745. * CMD_DESC_REGISTER: The command should be checked against the
  1746. * register whitelist for the appropriate ring
  1747. * CMD_DESC_MASTER: The command is allowed if the submitting process
  1748. * is the DRM master
  1749. */
  1750. u32 flags;
  1751. #define CMD_DESC_FIXED (1<<0)
  1752. #define CMD_DESC_SKIP (1<<1)
  1753. #define CMD_DESC_REJECT (1<<2)
  1754. #define CMD_DESC_REGISTER (1<<3)
  1755. #define CMD_DESC_BITMASK (1<<4)
  1756. #define CMD_DESC_MASTER (1<<5)
  1757. /*
  1758. * The command's unique identification bits and the bitmask to get them.
  1759. * This isn't strictly the opcode field as defined in the spec and may
  1760. * also include type, subtype, and/or subop fields.
  1761. */
  1762. struct {
  1763. u32 value;
  1764. u32 mask;
  1765. } cmd;
  1766. /*
  1767. * The command's length. The command is either fixed length (i.e. does
  1768. * not include a length field) or has a length field mask. The flag
  1769. * CMD_DESC_FIXED indicates a fixed length. Otherwise, the command has
  1770. * a length mask. All command entries in a command table must include
  1771. * length information.
  1772. */
  1773. union {
  1774. u32 fixed;
  1775. u32 mask;
  1776. } length;
  1777. /*
  1778. * Describes where to find a register address in the command to check
  1779. * against the ring's register whitelist. Only valid if flags has the
  1780. * CMD_DESC_REGISTER bit set.
  1781. */
  1782. struct {
  1783. u32 offset;
  1784. u32 mask;
  1785. } reg;
  1786. #define MAX_CMD_DESC_BITMASKS 3
  1787. /*
  1788. * Describes command checks where a particular dword is masked and
  1789. * compared against an expected value. If the command does not match
  1790. * the expected value, the parser rejects it. Only valid if flags has
  1791. * the CMD_DESC_BITMASK bit set. Only entries where mask is non-zero
  1792. * are valid.
  1793. *
  1794. * If the check specifies a non-zero condition_mask then the parser
  1795. * only performs the check when the bits specified by condition_mask
  1796. * are non-zero.
  1797. */
  1798. struct {
  1799. u32 offset;
  1800. u32 mask;
  1801. u32 expected;
  1802. u32 condition_offset;
  1803. u32 condition_mask;
  1804. } bits[MAX_CMD_DESC_BITMASKS];
  1805. };
  1806. /*
  1807. * A table of commands requiring special handling by the command parser.
  1808. *
  1809. * Each ring has an array of tables. Each table consists of an array of command
  1810. * descriptors, which must be sorted with command opcodes in ascending order.
  1811. */
  1812. struct drm_i915_cmd_table {
  1813. const struct drm_i915_cmd_descriptor *table;
  1814. int count;
  1815. };
  1816. /* Note that the (struct drm_i915_private *) cast is just to shut up gcc. */
  1817. #define __I915__(p) ({ \
  1818. struct drm_i915_private *__p; \
  1819. if (__builtin_types_compatible_p(typeof(*p), struct drm_i915_private)) \
  1820. __p = (struct drm_i915_private *)p; \
  1821. else if (__builtin_types_compatible_p(typeof(*p), struct drm_device)) \
  1822. __p = to_i915((struct drm_device *)p); \
  1823. else \
  1824. BUILD_BUG(); \
  1825. __p; \
  1826. })
  1827. #define INTEL_INFO(p) (&__I915__(p)->info)
  1828. #define INTEL_DEVID(p) (INTEL_INFO(p)->device_id)
  1829. #define IS_I830(dev) (INTEL_DEVID(dev) == 0x3577)
  1830. #define IS_845G(dev) (INTEL_DEVID(dev) == 0x2562)
  1831. #define IS_I85X(dev) (INTEL_INFO(dev)->is_i85x)
  1832. #define IS_I865G(dev) (INTEL_DEVID(dev) == 0x2572)
  1833. #define IS_I915G(dev) (INTEL_INFO(dev)->is_i915g)
  1834. #define IS_I915GM(dev) (INTEL_DEVID(dev) == 0x2592)
  1835. #define IS_I945G(dev) (INTEL_DEVID(dev) == 0x2772)
  1836. #define IS_I945GM(dev) (INTEL_INFO(dev)->is_i945gm)
  1837. #define IS_BROADWATER(dev) (INTEL_INFO(dev)->is_broadwater)
  1838. #define IS_CRESTLINE(dev) (INTEL_INFO(dev)->is_crestline)
  1839. #define IS_GM45(dev) (INTEL_DEVID(dev) == 0x2A42)
  1840. #define IS_G4X(dev) (INTEL_INFO(dev)->is_g4x)
  1841. #define IS_PINEVIEW_G(dev) (INTEL_DEVID(dev) == 0xa001)
  1842. #define IS_PINEVIEW_M(dev) (INTEL_DEVID(dev) == 0xa011)
  1843. #define IS_PINEVIEW(dev) (INTEL_INFO(dev)->is_pineview)
  1844. #define IS_G33(dev) (INTEL_INFO(dev)->is_g33)
  1845. #define IS_IRONLAKE_M(dev) (INTEL_DEVID(dev) == 0x0046)
  1846. #define IS_IVYBRIDGE(dev) (INTEL_INFO(dev)->is_ivybridge)
  1847. #define IS_IVB_GT1(dev) (INTEL_DEVID(dev) == 0x0156 || \
  1848. INTEL_DEVID(dev) == 0x0152 || \
  1849. INTEL_DEVID(dev) == 0x015a)
  1850. #define IS_SNB_GT1(dev) (INTEL_DEVID(dev) == 0x0102 || \
  1851. INTEL_DEVID(dev) == 0x0106 || \
  1852. INTEL_DEVID(dev) == 0x010A)
  1853. #define IS_VALLEYVIEW(dev) (INTEL_INFO(dev)->is_valleyview)
  1854. #define IS_CHERRYVIEW(dev) (INTEL_INFO(dev)->is_valleyview && IS_GEN8(dev))
  1855. #define IS_HASWELL(dev) (INTEL_INFO(dev)->is_haswell)
  1856. #define IS_BROADWELL(dev) (!INTEL_INFO(dev)->is_valleyview && IS_GEN8(dev))
  1857. #define IS_SKYLAKE(dev) (INTEL_INFO(dev)->is_skylake)
  1858. #define IS_MOBILE(dev) (INTEL_INFO(dev)->is_mobile)
  1859. #define IS_HSW_EARLY_SDV(dev) (IS_HASWELL(dev) && \
  1860. (INTEL_DEVID(dev) & 0xFF00) == 0x0C00)
  1861. #define IS_BDW_ULT(dev) (IS_BROADWELL(dev) && \
  1862. ((INTEL_DEVID(dev) & 0xf) == 0x2 || \
  1863. (INTEL_DEVID(dev) & 0xf) == 0x6 || \
  1864. (INTEL_DEVID(dev) & 0xf) == 0xe))
  1865. #define IS_BDW_GT3(dev) (IS_BROADWELL(dev) && \
  1866. (INTEL_DEVID(dev) & 0x00F0) == 0x0020)
  1867. #define IS_HSW_ULT(dev) (IS_HASWELL(dev) && \
  1868. (INTEL_DEVID(dev) & 0xFF00) == 0x0A00)
  1869. #define IS_HSW_GT3(dev) (IS_HASWELL(dev) && \
  1870. (INTEL_DEVID(dev) & 0x00F0) == 0x0020)
  1871. /* ULX machines are also considered ULT. */
  1872. #define IS_HSW_ULX(dev) (INTEL_DEVID(dev) == 0x0A0E || \
  1873. INTEL_DEVID(dev) == 0x0A1E)
  1874. #define IS_PRELIMINARY_HW(intel_info) ((intel_info)->is_preliminary)
  1875. /*
  1876. * The genX designation typically refers to the render engine, so render
  1877. * capability related checks should use IS_GEN, while display and other checks
  1878. * have their own (e.g. HAS_PCH_SPLIT for ILK+ display, IS_foo for particular
  1879. * chips, etc.).
  1880. */
  1881. #define IS_GEN2(dev) (INTEL_INFO(dev)->gen == 2)
  1882. #define IS_GEN3(dev) (INTEL_INFO(dev)->gen == 3)
  1883. #define IS_GEN4(dev) (INTEL_INFO(dev)->gen == 4)
  1884. #define IS_GEN5(dev) (INTEL_INFO(dev)->gen == 5)
  1885. #define IS_GEN6(dev) (INTEL_INFO(dev)->gen == 6)
  1886. #define IS_GEN7(dev) (INTEL_INFO(dev)->gen == 7)
  1887. #define IS_GEN8(dev) (INTEL_INFO(dev)->gen == 8)
  1888. #define IS_GEN9(dev) (INTEL_INFO(dev)->gen == 9)
  1889. #define RENDER_RING (1<<RCS)
  1890. #define BSD_RING (1<<VCS)
  1891. #define BLT_RING (1<<BCS)
  1892. #define VEBOX_RING (1<<VECS)
  1893. #define BSD2_RING (1<<VCS2)
  1894. #define HAS_BSD(dev) (INTEL_INFO(dev)->ring_mask & BSD_RING)
  1895. #define HAS_BSD2(dev) (INTEL_INFO(dev)->ring_mask & BSD2_RING)
  1896. #define HAS_BLT(dev) (INTEL_INFO(dev)->ring_mask & BLT_RING)
  1897. #define HAS_VEBOX(dev) (INTEL_INFO(dev)->ring_mask & VEBOX_RING)
  1898. #define HAS_LLC(dev) (INTEL_INFO(dev)->has_llc)
  1899. #define HAS_WT(dev) ((IS_HASWELL(dev) || IS_BROADWELL(dev)) && \
  1900. __I915__(dev)->ellc_size)
  1901. #define I915_NEED_GFX_HWS(dev) (INTEL_INFO(dev)->need_gfx_hws)
  1902. #define HAS_HW_CONTEXTS(dev) (INTEL_INFO(dev)->gen >= 6)
  1903. #define HAS_LOGICAL_RING_CONTEXTS(dev) (INTEL_INFO(dev)->gen >= 8)
  1904. #define USES_PPGTT(dev) (i915.enable_ppgtt)
  1905. #define USES_FULL_PPGTT(dev) (i915.enable_ppgtt == 2)
  1906. #define HAS_OVERLAY(dev) (INTEL_INFO(dev)->has_overlay)
  1907. #define OVERLAY_NEEDS_PHYSICAL(dev) (INTEL_INFO(dev)->overlay_needs_physical)
  1908. /* Early gen2 have a totally busted CS tlb and require pinned batches. */
  1909. #define HAS_BROKEN_CS_TLB(dev) (IS_I830(dev) || IS_845G(dev))
  1910. /*
  1911. * dp aux and gmbus irq on gen4 seems to be able to generate legacy interrupts
  1912. * even when in MSI mode. This results in spurious interrupt warnings if the
  1913. * legacy irq no. is shared with another device. The kernel then disables that
  1914. * interrupt source and so prevents the other device from working properly.
  1915. */
  1916. #define HAS_AUX_IRQ(dev) (INTEL_INFO(dev)->gen >= 5)
  1917. #define HAS_GMBUS_IRQ(dev) (INTEL_INFO(dev)->gen >= 5)
  1918. /* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte
  1919. * rows, which changed the alignment requirements and fence programming.
  1920. */
  1921. #define HAS_128_BYTE_Y_TILING(dev) (!IS_GEN2(dev) && !(IS_I915G(dev) || \
  1922. IS_I915GM(dev)))
  1923. #define SUPPORTS_DIGITAL_OUTPUTS(dev) (!IS_GEN2(dev) && !IS_PINEVIEW(dev))
  1924. #define SUPPORTS_INTEGRATED_HDMI(dev) (IS_G4X(dev) || IS_GEN5(dev))
  1925. #define SUPPORTS_INTEGRATED_DP(dev) (IS_G4X(dev) || IS_GEN5(dev))
  1926. #define SUPPORTS_TV(dev) (INTEL_INFO(dev)->supports_tv)
  1927. #define I915_HAS_HOTPLUG(dev) (INTEL_INFO(dev)->has_hotplug)
  1928. #define HAS_FW_BLC(dev) (INTEL_INFO(dev)->gen > 2)
  1929. #define HAS_PIPE_CXSR(dev) (INTEL_INFO(dev)->has_pipe_cxsr)
  1930. #define HAS_FBC(dev) (INTEL_INFO(dev)->has_fbc)
  1931. #define HAS_IPS(dev) (IS_HSW_ULT(dev) || IS_BROADWELL(dev))
  1932. #define HAS_DDI(dev) (INTEL_INFO(dev)->has_ddi)
  1933. #define HAS_FPGA_DBG_UNCLAIMED(dev) (INTEL_INFO(dev)->has_fpga_dbg)
  1934. #define HAS_PSR(dev) (IS_HASWELL(dev) || IS_BROADWELL(dev))
  1935. #define HAS_RUNTIME_PM(dev) (IS_GEN6(dev) || IS_HASWELL(dev) || \
  1936. IS_BROADWELL(dev) || IS_VALLEYVIEW(dev))
  1937. #define HAS_RC6(dev) (INTEL_INFO(dev)->gen >= 6)
  1938. #define HAS_RC6p(dev) (INTEL_INFO(dev)->gen == 6 || IS_IVYBRIDGE(dev))
  1939. #define INTEL_PCH_DEVICE_ID_MASK 0xff00
  1940. #define INTEL_PCH_IBX_DEVICE_ID_TYPE 0x3b00
  1941. #define INTEL_PCH_CPT_DEVICE_ID_TYPE 0x1c00
  1942. #define INTEL_PCH_PPT_DEVICE_ID_TYPE 0x1e00
  1943. #define INTEL_PCH_LPT_DEVICE_ID_TYPE 0x8c00
  1944. #define INTEL_PCH_LPT_LP_DEVICE_ID_TYPE 0x9c00
  1945. #define INTEL_PCH_SPT_DEVICE_ID_TYPE 0xA100
  1946. #define INTEL_PCH_SPT_LP_DEVICE_ID_TYPE 0x9D00
  1947. #define INTEL_PCH_TYPE(dev) (__I915__(dev)->pch_type)
  1948. #define HAS_PCH_SPT(dev) (INTEL_PCH_TYPE(dev) == PCH_SPT)
  1949. #define HAS_PCH_LPT(dev) (INTEL_PCH_TYPE(dev) == PCH_LPT)
  1950. #define HAS_PCH_CPT(dev) (INTEL_PCH_TYPE(dev) == PCH_CPT)
  1951. #define HAS_PCH_IBX(dev) (INTEL_PCH_TYPE(dev) == PCH_IBX)
  1952. #define HAS_PCH_NOP(dev) (INTEL_PCH_TYPE(dev) == PCH_NOP)
  1953. #define HAS_PCH_SPLIT(dev) (INTEL_PCH_TYPE(dev) != PCH_NONE)
  1954. #define HAS_GMCH_DISPLAY(dev) (INTEL_INFO(dev)->gen < 5 || IS_VALLEYVIEW(dev))
  1955. /* DPF == dynamic parity feature */
  1956. #define HAS_L3_DPF(dev) (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
  1957. #define NUM_L3_SLICES(dev) (IS_HSW_GT3(dev) ? 2 : HAS_L3_DPF(dev))
  1958. #define GT_FREQUENCY_MULTIPLIER 50
  1959. #include "i915_trace.h"
  1960. extern const struct drm_ioctl_desc i915_ioctls[];
  1961. extern int i915_max_ioctl;
  1962. extern int i915_suspend_legacy(struct drm_device *dev, pm_message_t state);
  1963. extern int i915_resume_legacy(struct drm_device *dev);
  1964. extern int i915_master_create(struct drm_device *dev, struct drm_master *master);
  1965. extern void i915_master_destroy(struct drm_device *dev, struct drm_master *master);
  1966. /* i915_params.c */
  1967. struct i915_params {
  1968. int modeset;
  1969. int panel_ignore_lid;
  1970. unsigned int powersave;
  1971. int semaphores;
  1972. unsigned int lvds_downclock;
  1973. int lvds_channel_mode;
  1974. int panel_use_ssc;
  1975. int vbt_sdvo_panel_type;
  1976. int enable_rc6;
  1977. int enable_fbc;
  1978. int enable_ppgtt;
  1979. int enable_execlists;
  1980. int enable_psr;
  1981. unsigned int preliminary_hw_support;
  1982. int disable_power_well;
  1983. int enable_ips;
  1984. int invert_brightness;
  1985. int enable_cmd_parser;
  1986. /* leave bools at the end to not create holes */
  1987. bool enable_hangcheck;
  1988. bool fastboot;
  1989. bool prefault_disable;
  1990. bool reset;
  1991. bool disable_display;
  1992. bool disable_vtd_wa;
  1993. int use_mmio_flip;
  1994. bool mmio_debug;
  1995. };
  1996. extern struct i915_params i915 __read_mostly;
  1997. /* i915_dma.c */
  1998. extern int i915_driver_load(struct drm_device *, unsigned long flags);
  1999. extern int i915_driver_unload(struct drm_device *);
  2000. extern int i915_driver_open(struct drm_device *dev, struct drm_file *file);
  2001. extern void i915_driver_lastclose(struct drm_device * dev);
  2002. extern void i915_driver_preclose(struct drm_device *dev,
  2003. struct drm_file *file);
  2004. extern void i915_driver_postclose(struct drm_device *dev,
  2005. struct drm_file *file);
  2006. extern int i915_driver_device_is_agp(struct drm_device * dev);
  2007. #ifdef CONFIG_COMPAT
  2008. extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
  2009. unsigned long arg);
  2010. #endif
  2011. extern int intel_gpu_reset(struct drm_device *dev);
  2012. extern int i915_reset(struct drm_device *dev);
  2013. extern unsigned long i915_chipset_val(struct drm_i915_private *dev_priv);
  2014. extern unsigned long i915_mch_val(struct drm_i915_private *dev_priv);
  2015. extern unsigned long i915_gfx_val(struct drm_i915_private *dev_priv);
  2016. extern void i915_update_gfx_val(struct drm_i915_private *dev_priv);
  2017. int vlv_force_gfx_clock(struct drm_i915_private *dev_priv, bool on);
  2018. void intel_hpd_cancel_work(struct drm_i915_private *dev_priv);
  2019. /* i915_irq.c */
  2020. void i915_queue_hangcheck(struct drm_device *dev);
  2021. __printf(3, 4)
  2022. void i915_handle_error(struct drm_device *dev, bool wedged,
  2023. const char *fmt, ...);
  2024. extern void intel_irq_init(struct drm_i915_private *dev_priv);
  2025. extern void intel_hpd_init(struct drm_i915_private *dev_priv);
  2026. int intel_irq_install(struct drm_i915_private *dev_priv);
  2027. void intel_irq_uninstall(struct drm_i915_private *dev_priv);
  2028. extern void intel_uncore_sanitize(struct drm_device *dev);
  2029. extern void intel_uncore_early_sanitize(struct drm_device *dev,
  2030. bool restore_forcewake);
  2031. extern void intel_uncore_init(struct drm_device *dev);
  2032. extern void intel_uncore_check_errors(struct drm_device *dev);
  2033. extern void intel_uncore_fini(struct drm_device *dev);
  2034. extern void intel_uncore_forcewake_reset(struct drm_device *dev, bool restore);
  2035. void
  2036. i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  2037. u32 status_mask);
  2038. void
  2039. i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  2040. u32 status_mask);
  2041. void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv);
  2042. void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv);
  2043. void
  2044. ironlake_enable_display_irq(struct drm_i915_private *dev_priv, u32 mask);
  2045. void
  2046. ironlake_disable_display_irq(struct drm_i915_private *dev_priv, u32 mask);
  2047. void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
  2048. uint32_t interrupt_mask,
  2049. uint32_t enabled_irq_mask);
  2050. #define ibx_enable_display_interrupt(dev_priv, bits) \
  2051. ibx_display_interrupt_update((dev_priv), (bits), (bits))
  2052. #define ibx_disable_display_interrupt(dev_priv, bits) \
  2053. ibx_display_interrupt_update((dev_priv), (bits), 0)
  2054. /* i915_gem.c */
  2055. int i915_gem_create_ioctl(struct drm_device *dev, void *data,
  2056. struct drm_file *file_priv);
  2057. int i915_gem_pread_ioctl(struct drm_device *dev, void *data,
  2058. struct drm_file *file_priv);
  2059. int i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  2060. struct drm_file *file_priv);
  2061. int i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
  2062. struct drm_file *file_priv);
  2063. int i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data,
  2064. struct drm_file *file_priv);
  2065. int i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  2066. struct drm_file *file_priv);
  2067. int i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
  2068. struct drm_file *file_priv);
  2069. void i915_gem_execbuffer_move_to_active(struct list_head *vmas,
  2070. struct intel_engine_cs *ring);
  2071. void i915_gem_execbuffer_retire_commands(struct drm_device *dev,
  2072. struct drm_file *file,
  2073. struct intel_engine_cs *ring,
  2074. struct drm_i915_gem_object *obj);
  2075. int i915_gem_ringbuffer_submission(struct drm_device *dev,
  2076. struct drm_file *file,
  2077. struct intel_engine_cs *ring,
  2078. struct intel_context *ctx,
  2079. struct drm_i915_gem_execbuffer2 *args,
  2080. struct list_head *vmas,
  2081. struct drm_i915_gem_object *batch_obj,
  2082. u64 exec_start, u32 flags);
  2083. int i915_gem_execbuffer(struct drm_device *dev, void *data,
  2084. struct drm_file *file_priv);
  2085. int i915_gem_execbuffer2(struct drm_device *dev, void *data,
  2086. struct drm_file *file_priv);
  2087. int i915_gem_pin_ioctl(struct drm_device *dev, void *data,
  2088. struct drm_file *file_priv);
  2089. int i915_gem_unpin_ioctl(struct drm_device *dev, void *data,
  2090. struct drm_file *file_priv);
  2091. int i915_gem_busy_ioctl(struct drm_device *dev, void *data,
  2092. struct drm_file *file_priv);
  2093. int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data,
  2094. struct drm_file *file);
  2095. int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
  2096. struct drm_file *file);
  2097. int i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
  2098. struct drm_file *file_priv);
  2099. int i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
  2100. struct drm_file *file_priv);
  2101. int i915_gem_set_tiling(struct drm_device *dev, void *data,
  2102. struct drm_file *file_priv);
  2103. int i915_gem_get_tiling(struct drm_device *dev, void *data,
  2104. struct drm_file *file_priv);
  2105. int i915_gem_init_userptr(struct drm_device *dev);
  2106. int i915_gem_userptr_ioctl(struct drm_device *dev, void *data,
  2107. struct drm_file *file);
  2108. int i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
  2109. struct drm_file *file_priv);
  2110. int i915_gem_wait_ioctl(struct drm_device *dev, void *data,
  2111. struct drm_file *file_priv);
  2112. void i915_gem_load(struct drm_device *dev);
  2113. unsigned long i915_gem_shrink(struct drm_i915_private *dev_priv,
  2114. long target,
  2115. unsigned flags);
  2116. #define I915_SHRINK_PURGEABLE 0x1
  2117. #define I915_SHRINK_UNBOUND 0x2
  2118. #define I915_SHRINK_BOUND 0x4
  2119. void *i915_gem_object_alloc(struct drm_device *dev);
  2120. void i915_gem_object_free(struct drm_i915_gem_object *obj);
  2121. void i915_gem_object_init(struct drm_i915_gem_object *obj,
  2122. const struct drm_i915_gem_object_ops *ops);
  2123. struct drm_i915_gem_object *i915_gem_alloc_object(struct drm_device *dev,
  2124. size_t size);
  2125. void i915_init_vm(struct drm_i915_private *dev_priv,
  2126. struct i915_address_space *vm);
  2127. void i915_gem_free_object(struct drm_gem_object *obj);
  2128. void i915_gem_vma_destroy(struct i915_vma *vma);
  2129. #define PIN_MAPPABLE 0x1
  2130. #define PIN_NONBLOCK 0x2
  2131. #define PIN_GLOBAL 0x4
  2132. #define PIN_OFFSET_BIAS 0x8
  2133. #define PIN_OFFSET_MASK (~4095)
  2134. int __must_check i915_gem_object_pin(struct drm_i915_gem_object *obj,
  2135. struct i915_address_space *vm,
  2136. uint32_t alignment,
  2137. uint64_t flags);
  2138. int __must_check i915_vma_unbind(struct i915_vma *vma);
  2139. int i915_gem_object_put_pages(struct drm_i915_gem_object *obj);
  2140. void i915_gem_release_all_mmaps(struct drm_i915_private *dev_priv);
  2141. void i915_gem_release_mmap(struct drm_i915_gem_object *obj);
  2142. int i915_gem_obj_prepare_shmem_read(struct drm_i915_gem_object *obj,
  2143. int *needs_clflush);
  2144. int __must_check i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
  2145. static inline struct page *i915_gem_object_get_page(struct drm_i915_gem_object *obj, int n)
  2146. {
  2147. struct sg_page_iter sg_iter;
  2148. for_each_sg_page(obj->pages->sgl, &sg_iter, obj->pages->nents, n)
  2149. return sg_page_iter_page(&sg_iter);
  2150. return NULL;
  2151. }
  2152. static inline void i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
  2153. {
  2154. BUG_ON(obj->pages == NULL);
  2155. obj->pages_pin_count++;
  2156. }
  2157. static inline void i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj)
  2158. {
  2159. BUG_ON(obj->pages_pin_count == 0);
  2160. obj->pages_pin_count--;
  2161. }
  2162. int __must_check i915_mutex_lock_interruptible(struct drm_device *dev);
  2163. int i915_gem_object_sync(struct drm_i915_gem_object *obj,
  2164. struct intel_engine_cs *to);
  2165. void i915_vma_move_to_active(struct i915_vma *vma,
  2166. struct intel_engine_cs *ring);
  2167. int i915_gem_dumb_create(struct drm_file *file_priv,
  2168. struct drm_device *dev,
  2169. struct drm_mode_create_dumb *args);
  2170. int i915_gem_mmap_gtt(struct drm_file *file_priv, struct drm_device *dev,
  2171. uint32_t handle, uint64_t *offset);
  2172. /**
  2173. * Returns true if seq1 is later than seq2.
  2174. */
  2175. static inline bool
  2176. i915_seqno_passed(uint32_t seq1, uint32_t seq2)
  2177. {
  2178. return (int32_t)(seq1 - seq2) >= 0;
  2179. }
  2180. int __must_check i915_gem_get_seqno(struct drm_device *dev, u32 *seqno);
  2181. int __must_check i915_gem_set_seqno(struct drm_device *dev, u32 seqno);
  2182. int __must_check i915_gem_object_get_fence(struct drm_i915_gem_object *obj);
  2183. int __must_check i915_gem_object_put_fence(struct drm_i915_gem_object *obj);
  2184. bool i915_gem_object_pin_fence(struct drm_i915_gem_object *obj);
  2185. void i915_gem_object_unpin_fence(struct drm_i915_gem_object *obj);
  2186. struct drm_i915_gem_request *
  2187. i915_gem_find_active_request(struct intel_engine_cs *ring);
  2188. bool i915_gem_retire_requests(struct drm_device *dev);
  2189. void i915_gem_retire_requests_ring(struct intel_engine_cs *ring);
  2190. int __must_check i915_gem_check_wedge(struct i915_gpu_error *error,
  2191. bool interruptible);
  2192. int __must_check i915_gem_check_olr(struct intel_engine_cs *ring, u32 seqno);
  2193. static inline bool i915_reset_in_progress(struct i915_gpu_error *error)
  2194. {
  2195. return unlikely(atomic_read(&error->reset_counter)
  2196. & (I915_RESET_IN_PROGRESS_FLAG | I915_WEDGED));
  2197. }
  2198. static inline bool i915_terminally_wedged(struct i915_gpu_error *error)
  2199. {
  2200. return atomic_read(&error->reset_counter) & I915_WEDGED;
  2201. }
  2202. static inline u32 i915_reset_count(struct i915_gpu_error *error)
  2203. {
  2204. return ((atomic_read(&error->reset_counter) & ~I915_WEDGED) + 1) / 2;
  2205. }
  2206. static inline bool i915_stop_ring_allow_ban(struct drm_i915_private *dev_priv)
  2207. {
  2208. return dev_priv->gpu_error.stop_rings == 0 ||
  2209. dev_priv->gpu_error.stop_rings & I915_STOP_RING_ALLOW_BAN;
  2210. }
  2211. static inline bool i915_stop_ring_allow_warn(struct drm_i915_private *dev_priv)
  2212. {
  2213. return dev_priv->gpu_error.stop_rings == 0 ||
  2214. dev_priv->gpu_error.stop_rings & I915_STOP_RING_ALLOW_WARN;
  2215. }
  2216. void i915_gem_reset(struct drm_device *dev);
  2217. bool i915_gem_clflush_object(struct drm_i915_gem_object *obj, bool force);
  2218. int __must_check i915_gem_object_finish_gpu(struct drm_i915_gem_object *obj);
  2219. int __must_check i915_gem_init(struct drm_device *dev);
  2220. int i915_gem_init_rings(struct drm_device *dev);
  2221. int __must_check i915_gem_init_hw(struct drm_device *dev);
  2222. int i915_gem_l3_remap(struct intel_engine_cs *ring, int slice);
  2223. void i915_gem_init_swizzling(struct drm_device *dev);
  2224. void i915_gem_cleanup_ringbuffer(struct drm_device *dev);
  2225. int __must_check i915_gpu_idle(struct drm_device *dev);
  2226. int __must_check i915_gem_suspend(struct drm_device *dev);
  2227. int __i915_add_request(struct intel_engine_cs *ring,
  2228. struct drm_file *file,
  2229. struct drm_i915_gem_object *batch_obj,
  2230. u32 *seqno);
  2231. #define i915_add_request(ring, seqno) \
  2232. __i915_add_request(ring, NULL, NULL, seqno)
  2233. int __i915_wait_seqno(struct intel_engine_cs *ring, u32 seqno,
  2234. unsigned reset_counter,
  2235. bool interruptible,
  2236. s64 *timeout,
  2237. struct drm_i915_file_private *file_priv);
  2238. int __must_check i915_wait_seqno(struct intel_engine_cs *ring,
  2239. uint32_t seqno);
  2240. int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
  2241. int __must_check
  2242. i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj,
  2243. bool write);
  2244. int __must_check
  2245. i915_gem_object_set_to_cpu_domain(struct drm_i915_gem_object *obj, bool write);
  2246. int __must_check
  2247. i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
  2248. u32 alignment,
  2249. struct intel_engine_cs *pipelined);
  2250. void i915_gem_object_unpin_from_display_plane(struct drm_i915_gem_object *obj);
  2251. int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj,
  2252. int align);
  2253. int i915_gem_open(struct drm_device *dev, struct drm_file *file);
  2254. void i915_gem_release(struct drm_device *dev, struct drm_file *file);
  2255. uint32_t
  2256. i915_gem_get_gtt_size(struct drm_device *dev, uint32_t size, int tiling_mode);
  2257. uint32_t
  2258. i915_gem_get_gtt_alignment(struct drm_device *dev, uint32_t size,
  2259. int tiling_mode, bool fenced);
  2260. int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
  2261. enum i915_cache_level cache_level);
  2262. struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
  2263. struct dma_buf *dma_buf);
  2264. struct dma_buf *i915_gem_prime_export(struct drm_device *dev,
  2265. struct drm_gem_object *gem_obj, int flags);
  2266. void i915_gem_restore_fences(struct drm_device *dev);
  2267. unsigned long i915_gem_obj_offset(struct drm_i915_gem_object *o,
  2268. struct i915_address_space *vm);
  2269. bool i915_gem_obj_bound_any(struct drm_i915_gem_object *o);
  2270. bool i915_gem_obj_bound(struct drm_i915_gem_object *o,
  2271. struct i915_address_space *vm);
  2272. unsigned long i915_gem_obj_size(struct drm_i915_gem_object *o,
  2273. struct i915_address_space *vm);
  2274. struct i915_vma *i915_gem_obj_to_vma(struct drm_i915_gem_object *obj,
  2275. struct i915_address_space *vm);
  2276. struct i915_vma *
  2277. i915_gem_obj_lookup_or_create_vma(struct drm_i915_gem_object *obj,
  2278. struct i915_address_space *vm);
  2279. struct i915_vma *i915_gem_obj_to_ggtt(struct drm_i915_gem_object *obj);
  2280. static inline bool i915_gem_obj_is_pinned(struct drm_i915_gem_object *obj) {
  2281. struct i915_vma *vma;
  2282. list_for_each_entry(vma, &obj->vma_list, vma_link)
  2283. if (vma->pin_count > 0)
  2284. return true;
  2285. return false;
  2286. }
  2287. /* Some GGTT VM helpers */
  2288. #define i915_obj_to_ggtt(obj) \
  2289. (&((struct drm_i915_private *)(obj)->base.dev->dev_private)->gtt.base)
  2290. static inline bool i915_is_ggtt(struct i915_address_space *vm)
  2291. {
  2292. struct i915_address_space *ggtt =
  2293. &((struct drm_i915_private *)(vm)->dev->dev_private)->gtt.base;
  2294. return vm == ggtt;
  2295. }
  2296. static inline struct i915_hw_ppgtt *
  2297. i915_vm_to_ppgtt(struct i915_address_space *vm)
  2298. {
  2299. WARN_ON(i915_is_ggtt(vm));
  2300. return container_of(vm, struct i915_hw_ppgtt, base);
  2301. }
  2302. static inline bool i915_gem_obj_ggtt_bound(struct drm_i915_gem_object *obj)
  2303. {
  2304. return i915_gem_obj_bound(obj, i915_obj_to_ggtt(obj));
  2305. }
  2306. static inline unsigned long
  2307. i915_gem_obj_ggtt_offset(struct drm_i915_gem_object *obj)
  2308. {
  2309. return i915_gem_obj_offset(obj, i915_obj_to_ggtt(obj));
  2310. }
  2311. static inline unsigned long
  2312. i915_gem_obj_ggtt_size(struct drm_i915_gem_object *obj)
  2313. {
  2314. return i915_gem_obj_size(obj, i915_obj_to_ggtt(obj));
  2315. }
  2316. static inline int __must_check
  2317. i915_gem_obj_ggtt_pin(struct drm_i915_gem_object *obj,
  2318. uint32_t alignment,
  2319. unsigned flags)
  2320. {
  2321. return i915_gem_object_pin(obj, i915_obj_to_ggtt(obj),
  2322. alignment, flags | PIN_GLOBAL);
  2323. }
  2324. static inline int
  2325. i915_gem_object_ggtt_unbind(struct drm_i915_gem_object *obj)
  2326. {
  2327. return i915_vma_unbind(i915_gem_obj_to_ggtt(obj));
  2328. }
  2329. void i915_gem_object_ggtt_unpin(struct drm_i915_gem_object *obj);
  2330. /* i915_gem_context.c */
  2331. int __must_check i915_gem_context_init(struct drm_device *dev);
  2332. void i915_gem_context_fini(struct drm_device *dev);
  2333. void i915_gem_context_reset(struct drm_device *dev);
  2334. int i915_gem_context_open(struct drm_device *dev, struct drm_file *file);
  2335. int i915_gem_context_enable(struct drm_i915_private *dev_priv);
  2336. void i915_gem_context_close(struct drm_device *dev, struct drm_file *file);
  2337. int i915_switch_context(struct intel_engine_cs *ring,
  2338. struct intel_context *to);
  2339. struct intel_context *
  2340. i915_gem_context_get(struct drm_i915_file_private *file_priv, u32 id);
  2341. void i915_gem_context_free(struct kref *ctx_ref);
  2342. struct drm_i915_gem_object *
  2343. i915_gem_alloc_context_obj(struct drm_device *dev, size_t size);
  2344. static inline void i915_gem_context_reference(struct intel_context *ctx)
  2345. {
  2346. kref_get(&ctx->ref);
  2347. }
  2348. static inline void i915_gem_context_unreference(struct intel_context *ctx)
  2349. {
  2350. kref_put(&ctx->ref, i915_gem_context_free);
  2351. }
  2352. static inline bool i915_gem_context_is_default(const struct intel_context *c)
  2353. {
  2354. return c->user_handle == DEFAULT_CONTEXT_HANDLE;
  2355. }
  2356. int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
  2357. struct drm_file *file);
  2358. int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
  2359. struct drm_file *file);
  2360. /* i915_gem_evict.c */
  2361. int __must_check i915_gem_evict_something(struct drm_device *dev,
  2362. struct i915_address_space *vm,
  2363. int min_size,
  2364. unsigned alignment,
  2365. unsigned cache_level,
  2366. unsigned long start,
  2367. unsigned long end,
  2368. unsigned flags);
  2369. int i915_gem_evict_vm(struct i915_address_space *vm, bool do_idle);
  2370. int i915_gem_evict_everything(struct drm_device *dev);
  2371. /* belongs in i915_gem_gtt.h */
  2372. static inline void i915_gem_chipset_flush(struct drm_device *dev)
  2373. {
  2374. if (INTEL_INFO(dev)->gen < 6)
  2375. intel_gtt_chipset_flush();
  2376. }
  2377. /* i915_gem_stolen.c */
  2378. int i915_gem_init_stolen(struct drm_device *dev);
  2379. int i915_gem_stolen_setup_compression(struct drm_device *dev, int size, int fb_cpp);
  2380. void i915_gem_stolen_cleanup_compression(struct drm_device *dev);
  2381. void i915_gem_cleanup_stolen(struct drm_device *dev);
  2382. struct drm_i915_gem_object *
  2383. i915_gem_object_create_stolen(struct drm_device *dev, u32 size);
  2384. struct drm_i915_gem_object *
  2385. i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
  2386. u32 stolen_offset,
  2387. u32 gtt_offset,
  2388. u32 size);
  2389. /* i915_gem_tiling.c */
  2390. static inline bool i915_gem_object_needs_bit17_swizzle(struct drm_i915_gem_object *obj)
  2391. {
  2392. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  2393. return dev_priv->mm.bit_6_swizzle_x == I915_BIT_6_SWIZZLE_9_10_17 &&
  2394. obj->tiling_mode != I915_TILING_NONE;
  2395. }
  2396. void i915_gem_detect_bit_6_swizzle(struct drm_device *dev);
  2397. void i915_gem_object_do_bit_17_swizzle(struct drm_i915_gem_object *obj);
  2398. void i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj);
  2399. /* i915_gem_debug.c */
  2400. #if WATCH_LISTS
  2401. int i915_verify_lists(struct drm_device *dev);
  2402. #else
  2403. #define i915_verify_lists(dev) 0
  2404. #endif
  2405. /* i915_debugfs.c */
  2406. int i915_debugfs_init(struct drm_minor *minor);
  2407. void i915_debugfs_cleanup(struct drm_minor *minor);
  2408. #ifdef CONFIG_DEBUG_FS
  2409. void intel_display_crc_init(struct drm_device *dev);
  2410. #else
  2411. static inline void intel_display_crc_init(struct drm_device *dev) {}
  2412. #endif
  2413. /* i915_gpu_error.c */
  2414. __printf(2, 3)
  2415. void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...);
  2416. int i915_error_state_to_str(struct drm_i915_error_state_buf *estr,
  2417. const struct i915_error_state_file_priv *error);
  2418. int i915_error_state_buf_init(struct drm_i915_error_state_buf *eb,
  2419. struct drm_i915_private *i915,
  2420. size_t count, loff_t pos);
  2421. static inline void i915_error_state_buf_release(
  2422. struct drm_i915_error_state_buf *eb)
  2423. {
  2424. kfree(eb->buf);
  2425. }
  2426. void i915_capture_error_state(struct drm_device *dev, bool wedge,
  2427. const char *error_msg);
  2428. void i915_error_state_get(struct drm_device *dev,
  2429. struct i915_error_state_file_priv *error_priv);
  2430. void i915_error_state_put(struct i915_error_state_file_priv *error_priv);
  2431. void i915_destroy_error_state(struct drm_device *dev);
  2432. void i915_get_extra_instdone(struct drm_device *dev, uint32_t *instdone);
  2433. const char *i915_cache_level_str(struct drm_i915_private *i915, int type);
  2434. /* i915_cmd_parser.c */
  2435. int i915_cmd_parser_get_version(void);
  2436. int i915_cmd_parser_init_ring(struct intel_engine_cs *ring);
  2437. void i915_cmd_parser_fini_ring(struct intel_engine_cs *ring);
  2438. bool i915_needs_cmd_parser(struct intel_engine_cs *ring);
  2439. int i915_parse_cmds(struct intel_engine_cs *ring,
  2440. struct drm_i915_gem_object *batch_obj,
  2441. u32 batch_start_offset,
  2442. bool is_master);
  2443. /* i915_suspend.c */
  2444. extern int i915_save_state(struct drm_device *dev);
  2445. extern int i915_restore_state(struct drm_device *dev);
  2446. /* i915_ums.c */
  2447. void i915_save_display_reg(struct drm_device *dev);
  2448. void i915_restore_display_reg(struct drm_device *dev);
  2449. /* i915_sysfs.c */
  2450. void i915_setup_sysfs(struct drm_device *dev_priv);
  2451. void i915_teardown_sysfs(struct drm_device *dev_priv);
  2452. /* intel_i2c.c */
  2453. extern int intel_setup_gmbus(struct drm_device *dev);
  2454. extern void intel_teardown_gmbus(struct drm_device *dev);
  2455. static inline bool intel_gmbus_is_port_valid(unsigned port)
  2456. {
  2457. return (port >= GMBUS_PORT_SSC && port <= GMBUS_PORT_DPD);
  2458. }
  2459. extern struct i2c_adapter *intel_gmbus_get_adapter(
  2460. struct drm_i915_private *dev_priv, unsigned port);
  2461. extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
  2462. extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
  2463. static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
  2464. {
  2465. return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
  2466. }
  2467. extern void intel_i2c_reset(struct drm_device *dev);
  2468. /* intel_opregion.c */
  2469. #ifdef CONFIG_ACPI
  2470. extern int intel_opregion_setup(struct drm_device *dev);
  2471. extern void intel_opregion_init(struct drm_device *dev);
  2472. extern void intel_opregion_fini(struct drm_device *dev);
  2473. extern void intel_opregion_asle_intr(struct drm_device *dev);
  2474. extern int intel_opregion_notify_encoder(struct intel_encoder *intel_encoder,
  2475. bool enable);
  2476. extern int intel_opregion_notify_adapter(struct drm_device *dev,
  2477. pci_power_t state);
  2478. #else
  2479. static inline int intel_opregion_setup(struct drm_device *dev) { return 0; }
  2480. static inline void intel_opregion_init(struct drm_device *dev) { return; }
  2481. static inline void intel_opregion_fini(struct drm_device *dev) { return; }
  2482. static inline void intel_opregion_asle_intr(struct drm_device *dev) { return; }
  2483. static inline int
  2484. intel_opregion_notify_encoder(struct intel_encoder *intel_encoder, bool enable)
  2485. {
  2486. return 0;
  2487. }
  2488. static inline int
  2489. intel_opregion_notify_adapter(struct drm_device *dev, pci_power_t state)
  2490. {
  2491. return 0;
  2492. }
  2493. #endif
  2494. /* intel_acpi.c */
  2495. #ifdef CONFIG_ACPI
  2496. extern void intel_register_dsm_handler(void);
  2497. extern void intel_unregister_dsm_handler(void);
  2498. #else
  2499. static inline void intel_register_dsm_handler(void) { return; }
  2500. static inline void intel_unregister_dsm_handler(void) { return; }
  2501. #endif /* CONFIG_ACPI */
  2502. /* modesetting */
  2503. extern void intel_modeset_init_hw(struct drm_device *dev);
  2504. extern void intel_modeset_init(struct drm_device *dev);
  2505. extern void intel_modeset_gem_init(struct drm_device *dev);
  2506. extern void intel_modeset_cleanup(struct drm_device *dev);
  2507. extern void intel_connector_unregister(struct intel_connector *);
  2508. extern int intel_modeset_vga_set_state(struct drm_device *dev, bool state);
  2509. extern void intel_modeset_setup_hw_state(struct drm_device *dev,
  2510. bool force_restore);
  2511. extern void i915_redisable_vga(struct drm_device *dev);
  2512. extern void i915_redisable_vga_power_on(struct drm_device *dev);
  2513. extern bool intel_fbc_enabled(struct drm_device *dev);
  2514. extern void bdw_fbc_sw_flush(struct drm_device *dev, u32 value);
  2515. extern void intel_disable_fbc(struct drm_device *dev);
  2516. extern bool ironlake_set_drps(struct drm_device *dev, u8 val);
  2517. extern void intel_init_pch_refclk(struct drm_device *dev);
  2518. extern void gen6_set_rps(struct drm_device *dev, u8 val);
  2519. extern void valleyview_set_rps(struct drm_device *dev, u8 val);
  2520. extern void intel_set_memory_cxsr(struct drm_i915_private *dev_priv,
  2521. bool enable);
  2522. extern void intel_detect_pch(struct drm_device *dev);
  2523. extern int intel_trans_dp_port_sel(struct drm_crtc *crtc);
  2524. extern int intel_enable_rc6(const struct drm_device *dev);
  2525. extern bool i915_semaphore_is_enabled(struct drm_device *dev);
  2526. int i915_reg_read_ioctl(struct drm_device *dev, void *data,
  2527. struct drm_file *file);
  2528. int i915_get_reset_stats_ioctl(struct drm_device *dev, void *data,
  2529. struct drm_file *file);
  2530. void intel_notify_mmio_flip(struct intel_engine_cs *ring);
  2531. /* overlay */
  2532. extern struct intel_overlay_error_state *intel_overlay_capture_error_state(struct drm_device *dev);
  2533. extern void intel_overlay_print_error_state(struct drm_i915_error_state_buf *e,
  2534. struct intel_overlay_error_state *error);
  2535. extern struct intel_display_error_state *intel_display_capture_error_state(struct drm_device *dev);
  2536. extern void intel_display_print_error_state(struct drm_i915_error_state_buf *e,
  2537. struct drm_device *dev,
  2538. struct intel_display_error_state *error);
  2539. /* On SNB platform, before reading ring registers forcewake bit
  2540. * must be set to prevent GT core from power down and stale values being
  2541. * returned.
  2542. */
  2543. void gen6_gt_force_wake_get(struct drm_i915_private *dev_priv, int fw_engine);
  2544. void gen6_gt_force_wake_put(struct drm_i915_private *dev_priv, int fw_engine);
  2545. void assert_force_wake_inactive(struct drm_i915_private *dev_priv);
  2546. int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u32 mbox, u32 *val);
  2547. int sandybridge_pcode_write(struct drm_i915_private *dev_priv, u32 mbox, u32 val);
  2548. /* intel_sideband.c */
  2549. u32 vlv_punit_read(struct drm_i915_private *dev_priv, u8 addr);
  2550. void vlv_punit_write(struct drm_i915_private *dev_priv, u8 addr, u32 val);
  2551. u32 vlv_nc_read(struct drm_i915_private *dev_priv, u8 addr);
  2552. u32 vlv_gpio_nc_read(struct drm_i915_private *dev_priv, u32 reg);
  2553. void vlv_gpio_nc_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2554. u32 vlv_cck_read(struct drm_i915_private *dev_priv, u32 reg);
  2555. void vlv_cck_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2556. u32 vlv_ccu_read(struct drm_i915_private *dev_priv, u32 reg);
  2557. void vlv_ccu_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2558. u32 vlv_bunit_read(struct drm_i915_private *dev_priv, u32 reg);
  2559. void vlv_bunit_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2560. u32 vlv_gps_core_read(struct drm_i915_private *dev_priv, u32 reg);
  2561. void vlv_gps_core_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2562. u32 vlv_dpio_read(struct drm_i915_private *dev_priv, enum pipe pipe, int reg);
  2563. void vlv_dpio_write(struct drm_i915_private *dev_priv, enum pipe pipe, int reg, u32 val);
  2564. u32 intel_sbi_read(struct drm_i915_private *dev_priv, u16 reg,
  2565. enum intel_sbi_destination destination);
  2566. void intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
  2567. enum intel_sbi_destination destination);
  2568. u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
  2569. void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2570. int vlv_gpu_freq(struct drm_i915_private *dev_priv, int val);
  2571. int vlv_freq_opcode(struct drm_i915_private *dev_priv, int val);
  2572. #define FORCEWAKE_RENDER (1 << 0)
  2573. #define FORCEWAKE_MEDIA (1 << 1)
  2574. #define FORCEWAKE_BLITTER (1 << 2)
  2575. #define FORCEWAKE_ALL (FORCEWAKE_RENDER | FORCEWAKE_MEDIA | \
  2576. FORCEWAKE_BLITTER)
  2577. #define I915_READ8(reg) dev_priv->uncore.funcs.mmio_readb(dev_priv, (reg), true)
  2578. #define I915_WRITE8(reg, val) dev_priv->uncore.funcs.mmio_writeb(dev_priv, (reg), (val), true)
  2579. #define I915_READ16(reg) dev_priv->uncore.funcs.mmio_readw(dev_priv, (reg), true)
  2580. #define I915_WRITE16(reg, val) dev_priv->uncore.funcs.mmio_writew(dev_priv, (reg), (val), true)
  2581. #define I915_READ16_NOTRACE(reg) dev_priv->uncore.funcs.mmio_readw(dev_priv, (reg), false)
  2582. #define I915_WRITE16_NOTRACE(reg, val) dev_priv->uncore.funcs.mmio_writew(dev_priv, (reg), (val), false)
  2583. #define I915_READ(reg) dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), true)
  2584. #define I915_WRITE(reg, val) dev_priv->uncore.funcs.mmio_writel(dev_priv, (reg), (val), true)
  2585. #define I915_READ_NOTRACE(reg) dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), false)
  2586. #define I915_WRITE_NOTRACE(reg, val) dev_priv->uncore.funcs.mmio_writel(dev_priv, (reg), (val), false)
  2587. /* Be very careful with read/write 64-bit values. On 32-bit machines, they
  2588. * will be implemented using 2 32-bit writes in an arbitrary order with
  2589. * an arbitrary delay between them. This can cause the hardware to
  2590. * act upon the intermediate value, possibly leading to corruption and
  2591. * machine death. You have been warned.
  2592. */
  2593. #define I915_WRITE64(reg, val) dev_priv->uncore.funcs.mmio_writeq(dev_priv, (reg), (val), true)
  2594. #define I915_READ64(reg) dev_priv->uncore.funcs.mmio_readq(dev_priv, (reg), true)
  2595. #define I915_READ64_2x32(lower_reg, upper_reg) ({ \
  2596. u32 upper = I915_READ(upper_reg); \
  2597. u32 lower = I915_READ(lower_reg); \
  2598. u32 tmp = I915_READ(upper_reg); \
  2599. if (upper != tmp) { \
  2600. upper = tmp; \
  2601. lower = I915_READ(lower_reg); \
  2602. WARN_ON(I915_READ(upper_reg) != upper); \
  2603. } \
  2604. (u64)upper << 32 | lower; })
  2605. #define POSTING_READ(reg) (void)I915_READ_NOTRACE(reg)
  2606. #define POSTING_READ16(reg) (void)I915_READ16_NOTRACE(reg)
  2607. /* "Broadcast RGB" property */
  2608. #define INTEL_BROADCAST_RGB_AUTO 0
  2609. #define INTEL_BROADCAST_RGB_FULL 1
  2610. #define INTEL_BROADCAST_RGB_LIMITED 2
  2611. static inline uint32_t i915_vgacntrl_reg(struct drm_device *dev)
  2612. {
  2613. if (IS_VALLEYVIEW(dev))
  2614. return VLV_VGACNTRL;
  2615. else if (INTEL_INFO(dev)->gen >= 5)
  2616. return CPU_VGACNTRL;
  2617. else
  2618. return VGACNTRL;
  2619. }
  2620. static inline void __user *to_user_ptr(u64 address)
  2621. {
  2622. return (void __user *)(uintptr_t)address;
  2623. }
  2624. static inline unsigned long msecs_to_jiffies_timeout(const unsigned int m)
  2625. {
  2626. unsigned long j = msecs_to_jiffies(m);
  2627. return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
  2628. }
  2629. static inline unsigned long nsecs_to_jiffies_timeout(const u64 n)
  2630. {
  2631. return min_t(u64, MAX_JIFFY_OFFSET, nsecs_to_jiffies64(n) + 1);
  2632. }
  2633. static inline unsigned long
  2634. timespec_to_jiffies_timeout(const struct timespec *value)
  2635. {
  2636. unsigned long j = timespec_to_jiffies(value);
  2637. return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
  2638. }
  2639. /*
  2640. * If you need to wait X milliseconds between events A and B, but event B
  2641. * doesn't happen exactly after event A, you record the timestamp (jiffies) of
  2642. * when event A happened, then just before event B you call this function and
  2643. * pass the timestamp as the first argument, and X as the second argument.
  2644. */
  2645. static inline void
  2646. wait_remaining_ms_from_jiffies(unsigned long timestamp_jiffies, int to_wait_ms)
  2647. {
  2648. unsigned long target_jiffies, tmp_jiffies, remaining_jiffies;
  2649. /*
  2650. * Don't re-read the value of "jiffies" every time since it may change
  2651. * behind our back and break the math.
  2652. */
  2653. tmp_jiffies = jiffies;
  2654. target_jiffies = timestamp_jiffies +
  2655. msecs_to_jiffies_timeout(to_wait_ms);
  2656. if (time_after(target_jiffies, tmp_jiffies)) {
  2657. remaining_jiffies = target_jiffies - tmp_jiffies;
  2658. while (remaining_jiffies)
  2659. remaining_jiffies =
  2660. schedule_timeout_uninterruptible(remaining_jiffies);
  2661. }
  2662. }
  2663. #endif