i915_drv.h 123 KB

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