i915_drv.h 98 KB

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