i915_drv.h 112 KB

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