i915_drv.h 127 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270
  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/hash.h>
  38. #include <linux/intel-iommu.h>
  39. #include <linux/kref.h>
  40. #include <linux/perf_event.h>
  41. #include <linux/pm_qos.h>
  42. #include <linux/reservation.h>
  43. #include <linux/shmem_fs.h>
  44. #include <drm/drmP.h>
  45. #include <drm/intel-gtt.h>
  46. #include <drm/drm_legacy.h> /* for struct drm_dma_handle */
  47. #include <drm/drm_gem.h>
  48. #include <drm/drm_auth.h>
  49. #include <drm/drm_cache.h>
  50. #include "i915_params.h"
  51. #include "i915_reg.h"
  52. #include "i915_utils.h"
  53. #include "intel_uncore.h"
  54. #include "intel_bios.h"
  55. #include "intel_dpll_mgr.h"
  56. #include "intel_uc.h"
  57. #include "intel_lrc.h"
  58. #include "intel_ringbuffer.h"
  59. #include "intel_display.h"
  60. #include "i915_gem.h"
  61. #include "i915_gem_context.h"
  62. #include "i915_gem_fence_reg.h"
  63. #include "i915_gem_object.h"
  64. #include "i915_gem_gtt.h"
  65. #include "i915_gem_request.h"
  66. #include "i915_gem_timeline.h"
  67. #include "i915_vma.h"
  68. #include "intel_gvt.h"
  69. /* General customization:
  70. */
  71. #define DRIVER_NAME "i915"
  72. #define DRIVER_DESC "Intel Graphics"
  73. #define DRIVER_DATE "20171214"
  74. #define DRIVER_TIMESTAMP 1513282202
  75. /* Use I915_STATE_WARN(x) and I915_STATE_WARN_ON() (rather than WARN() and
  76. * WARN_ON()) for hw state sanity checks to check for unexpected conditions
  77. * which may not necessarily be a user visible problem. This will either
  78. * WARN() or DRM_ERROR() depending on the verbose_checks moduleparam, to
  79. * enable distros and users to tailor their preferred amount of i915 abrt
  80. * spam.
  81. */
  82. #define I915_STATE_WARN(condition, format...) ({ \
  83. int __ret_warn_on = !!(condition); \
  84. if (unlikely(__ret_warn_on)) \
  85. if (!WARN(i915_modparams.verbose_state_checks, format)) \
  86. DRM_ERROR(format); \
  87. unlikely(__ret_warn_on); \
  88. })
  89. #define I915_STATE_WARN_ON(x) \
  90. I915_STATE_WARN((x), "%s", "WARN_ON(" __stringify(x) ")")
  91. bool __i915_inject_load_failure(const char *func, int line);
  92. #define i915_inject_load_failure() \
  93. __i915_inject_load_failure(__func__, __LINE__)
  94. typedef struct {
  95. uint32_t val;
  96. } uint_fixed_16_16_t;
  97. #define FP_16_16_MAX ({ \
  98. uint_fixed_16_16_t fp; \
  99. fp.val = UINT_MAX; \
  100. fp; \
  101. })
  102. static inline bool is_fixed16_zero(uint_fixed_16_16_t val)
  103. {
  104. if (val.val == 0)
  105. return true;
  106. return false;
  107. }
  108. static inline uint_fixed_16_16_t u32_to_fixed16(uint32_t val)
  109. {
  110. uint_fixed_16_16_t fp;
  111. WARN_ON(val > U16_MAX);
  112. fp.val = val << 16;
  113. return fp;
  114. }
  115. static inline uint32_t fixed16_to_u32_round_up(uint_fixed_16_16_t fp)
  116. {
  117. return DIV_ROUND_UP(fp.val, 1 << 16);
  118. }
  119. static inline uint32_t fixed16_to_u32(uint_fixed_16_16_t fp)
  120. {
  121. return fp.val >> 16;
  122. }
  123. static inline uint_fixed_16_16_t min_fixed16(uint_fixed_16_16_t min1,
  124. uint_fixed_16_16_t min2)
  125. {
  126. uint_fixed_16_16_t min;
  127. min.val = min(min1.val, min2.val);
  128. return min;
  129. }
  130. static inline uint_fixed_16_16_t max_fixed16(uint_fixed_16_16_t max1,
  131. uint_fixed_16_16_t max2)
  132. {
  133. uint_fixed_16_16_t max;
  134. max.val = max(max1.val, max2.val);
  135. return max;
  136. }
  137. static inline uint_fixed_16_16_t clamp_u64_to_fixed16(uint64_t val)
  138. {
  139. uint_fixed_16_16_t fp;
  140. WARN_ON(val > U32_MAX);
  141. fp.val = (uint32_t) val;
  142. return fp;
  143. }
  144. static inline uint32_t div_round_up_fixed16(uint_fixed_16_16_t val,
  145. uint_fixed_16_16_t d)
  146. {
  147. return DIV_ROUND_UP(val.val, d.val);
  148. }
  149. static inline uint32_t mul_round_up_u32_fixed16(uint32_t val,
  150. uint_fixed_16_16_t mul)
  151. {
  152. uint64_t intermediate_val;
  153. intermediate_val = (uint64_t) val * mul.val;
  154. intermediate_val = DIV_ROUND_UP_ULL(intermediate_val, 1 << 16);
  155. WARN_ON(intermediate_val > U32_MAX);
  156. return (uint32_t) intermediate_val;
  157. }
  158. static inline uint_fixed_16_16_t mul_fixed16(uint_fixed_16_16_t val,
  159. uint_fixed_16_16_t mul)
  160. {
  161. uint64_t intermediate_val;
  162. intermediate_val = (uint64_t) val.val * mul.val;
  163. intermediate_val = intermediate_val >> 16;
  164. return clamp_u64_to_fixed16(intermediate_val);
  165. }
  166. static inline uint_fixed_16_16_t div_fixed16(uint32_t val, uint32_t d)
  167. {
  168. uint64_t interm_val;
  169. interm_val = (uint64_t)val << 16;
  170. interm_val = DIV_ROUND_UP_ULL(interm_val, d);
  171. return clamp_u64_to_fixed16(interm_val);
  172. }
  173. static inline uint32_t div_round_up_u32_fixed16(uint32_t val,
  174. uint_fixed_16_16_t d)
  175. {
  176. uint64_t interm_val;
  177. interm_val = (uint64_t)val << 16;
  178. interm_val = DIV_ROUND_UP_ULL(interm_val, d.val);
  179. WARN_ON(interm_val > U32_MAX);
  180. return (uint32_t) interm_val;
  181. }
  182. static inline uint_fixed_16_16_t mul_u32_fixed16(uint32_t val,
  183. uint_fixed_16_16_t mul)
  184. {
  185. uint64_t intermediate_val;
  186. intermediate_val = (uint64_t) val * mul.val;
  187. return clamp_u64_to_fixed16(intermediate_val);
  188. }
  189. static inline uint_fixed_16_16_t add_fixed16(uint_fixed_16_16_t add1,
  190. uint_fixed_16_16_t add2)
  191. {
  192. uint64_t interm_sum;
  193. interm_sum = (uint64_t) add1.val + add2.val;
  194. return clamp_u64_to_fixed16(interm_sum);
  195. }
  196. static inline uint_fixed_16_16_t add_fixed16_u32(uint_fixed_16_16_t add1,
  197. uint32_t add2)
  198. {
  199. uint64_t interm_sum;
  200. uint_fixed_16_16_t interm_add2 = u32_to_fixed16(add2);
  201. interm_sum = (uint64_t) add1.val + interm_add2.val;
  202. return clamp_u64_to_fixed16(interm_sum);
  203. }
  204. enum hpd_pin {
  205. HPD_NONE = 0,
  206. HPD_TV = HPD_NONE, /* TV is known to be unreliable */
  207. HPD_CRT,
  208. HPD_SDVO_B,
  209. HPD_SDVO_C,
  210. HPD_PORT_A,
  211. HPD_PORT_B,
  212. HPD_PORT_C,
  213. HPD_PORT_D,
  214. HPD_PORT_E,
  215. HPD_NUM_PINS
  216. };
  217. #define for_each_hpd_pin(__pin) \
  218. for ((__pin) = (HPD_NONE + 1); (__pin) < HPD_NUM_PINS; (__pin)++)
  219. #define HPD_STORM_DEFAULT_THRESHOLD 5
  220. struct i915_hotplug {
  221. struct work_struct hotplug_work;
  222. struct {
  223. unsigned long last_jiffies;
  224. int count;
  225. enum {
  226. HPD_ENABLED = 0,
  227. HPD_DISABLED = 1,
  228. HPD_MARK_DISABLED = 2
  229. } state;
  230. } stats[HPD_NUM_PINS];
  231. u32 event_bits;
  232. struct delayed_work reenable_work;
  233. struct intel_digital_port *irq_port[I915_MAX_PORTS];
  234. u32 long_port_mask;
  235. u32 short_port_mask;
  236. struct work_struct dig_port_work;
  237. struct work_struct poll_init_work;
  238. bool poll_enabled;
  239. unsigned int hpd_storm_threshold;
  240. /*
  241. * if we get a HPD irq from DP and a HPD irq from non-DP
  242. * the non-DP HPD could block the workqueue on a mode config
  243. * mutex getting, that userspace may have taken. However
  244. * userspace is waiting on the DP workqueue to run which is
  245. * blocked behind the non-DP one.
  246. */
  247. struct workqueue_struct *dp_wq;
  248. };
  249. #define I915_GEM_GPU_DOMAINS \
  250. (I915_GEM_DOMAIN_RENDER | \
  251. I915_GEM_DOMAIN_SAMPLER | \
  252. I915_GEM_DOMAIN_COMMAND | \
  253. I915_GEM_DOMAIN_INSTRUCTION | \
  254. I915_GEM_DOMAIN_VERTEX)
  255. struct drm_i915_private;
  256. struct i915_mm_struct;
  257. struct i915_mmu_object;
  258. struct drm_i915_file_private {
  259. struct drm_i915_private *dev_priv;
  260. struct drm_file *file;
  261. struct {
  262. spinlock_t lock;
  263. struct list_head request_list;
  264. /* 20ms is a fairly arbitrary limit (greater than the average frame time)
  265. * chosen to prevent the CPU getting more than a frame ahead of the GPU
  266. * (when using lax throttling for the frontbuffer). We also use it to
  267. * offer free GPU waitboosts for severely congested workloads.
  268. */
  269. #define DRM_I915_THROTTLE_JIFFIES msecs_to_jiffies(20)
  270. } mm;
  271. struct idr context_idr;
  272. struct intel_rps_client {
  273. atomic_t boosts;
  274. } rps_client;
  275. unsigned int bsd_engine;
  276. /* Client can have a maximum of 3 contexts banned before
  277. * it is denied of creating new contexts. As one context
  278. * ban needs 4 consecutive hangs, and more if there is
  279. * progress in between, this is a last resort stop gap measure
  280. * to limit the badly behaving clients access to gpu.
  281. */
  282. #define I915_MAX_CLIENT_CONTEXT_BANS 3
  283. atomic_t context_bans;
  284. };
  285. /* Interface history:
  286. *
  287. * 1.1: Original.
  288. * 1.2: Add Power Management
  289. * 1.3: Add vblank support
  290. * 1.4: Fix cmdbuffer path, add heap destroy
  291. * 1.5: Add vblank pipe configuration
  292. * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
  293. * - Support vertical blank on secondary display pipe
  294. */
  295. #define DRIVER_MAJOR 1
  296. #define DRIVER_MINOR 6
  297. #define DRIVER_PATCHLEVEL 0
  298. struct opregion_header;
  299. struct opregion_acpi;
  300. struct opregion_swsci;
  301. struct opregion_asle;
  302. struct intel_opregion {
  303. struct opregion_header *header;
  304. struct opregion_acpi *acpi;
  305. struct opregion_swsci *swsci;
  306. u32 swsci_gbda_sub_functions;
  307. u32 swsci_sbcb_sub_functions;
  308. struct opregion_asle *asle;
  309. void *rvda;
  310. void *vbt_firmware;
  311. const void *vbt;
  312. u32 vbt_size;
  313. u32 *lid_state;
  314. struct work_struct asle_work;
  315. };
  316. #define OPREGION_SIZE (8*1024)
  317. struct intel_overlay;
  318. struct intel_overlay_error_state;
  319. struct sdvo_device_mapping {
  320. u8 initialized;
  321. u8 dvo_port;
  322. u8 slave_addr;
  323. u8 dvo_wiring;
  324. u8 i2c_pin;
  325. u8 ddc_pin;
  326. };
  327. struct intel_connector;
  328. struct intel_encoder;
  329. struct intel_atomic_state;
  330. struct intel_crtc_state;
  331. struct intel_initial_plane_config;
  332. struct intel_crtc;
  333. struct intel_limit;
  334. struct dpll;
  335. struct intel_cdclk_state;
  336. struct drm_i915_display_funcs {
  337. void (*get_cdclk)(struct drm_i915_private *dev_priv,
  338. struct intel_cdclk_state *cdclk_state);
  339. void (*set_cdclk)(struct drm_i915_private *dev_priv,
  340. const struct intel_cdclk_state *cdclk_state);
  341. int (*get_fifo_size)(struct drm_i915_private *dev_priv,
  342. enum i9xx_plane_id i9xx_plane);
  343. int (*compute_pipe_wm)(struct intel_crtc_state *cstate);
  344. int (*compute_intermediate_wm)(struct drm_device *dev,
  345. struct intel_crtc *intel_crtc,
  346. struct intel_crtc_state *newstate);
  347. void (*initial_watermarks)(struct intel_atomic_state *state,
  348. struct intel_crtc_state *cstate);
  349. void (*atomic_update_watermarks)(struct intel_atomic_state *state,
  350. struct intel_crtc_state *cstate);
  351. void (*optimize_watermarks)(struct intel_atomic_state *state,
  352. struct intel_crtc_state *cstate);
  353. int (*compute_global_watermarks)(struct drm_atomic_state *state);
  354. void (*update_wm)(struct intel_crtc *crtc);
  355. int (*modeset_calc_cdclk)(struct drm_atomic_state *state);
  356. /* Returns the active state of the crtc, and if the crtc is active,
  357. * fills out the pipe-config with the hw state. */
  358. bool (*get_pipe_config)(struct intel_crtc *,
  359. struct intel_crtc_state *);
  360. void (*get_initial_plane_config)(struct intel_crtc *,
  361. struct intel_initial_plane_config *);
  362. int (*crtc_compute_clock)(struct intel_crtc *crtc,
  363. struct intel_crtc_state *crtc_state);
  364. void (*crtc_enable)(struct intel_crtc_state *pipe_config,
  365. struct drm_atomic_state *old_state);
  366. void (*crtc_disable)(struct intel_crtc_state *old_crtc_state,
  367. struct drm_atomic_state *old_state);
  368. void (*update_crtcs)(struct drm_atomic_state *state);
  369. void (*audio_codec_enable)(struct intel_encoder *encoder,
  370. const struct intel_crtc_state *crtc_state,
  371. const struct drm_connector_state *conn_state);
  372. void (*audio_codec_disable)(struct intel_encoder *encoder,
  373. const struct intel_crtc_state *old_crtc_state,
  374. const struct drm_connector_state *old_conn_state);
  375. void (*fdi_link_train)(struct intel_crtc *crtc,
  376. const struct intel_crtc_state *crtc_state);
  377. void (*init_clock_gating)(struct drm_i915_private *dev_priv);
  378. void (*hpd_irq_setup)(struct drm_i915_private *dev_priv);
  379. /* clock updates for mode set */
  380. /* cursor updates */
  381. /* render clock increase/decrease */
  382. /* display clock increase/decrease */
  383. /* pll clock increase/decrease */
  384. void (*load_csc_matrix)(struct drm_crtc_state *crtc_state);
  385. void (*load_luts)(struct drm_crtc_state *crtc_state);
  386. };
  387. #define CSR_VERSION(major, minor) ((major) << 16 | (minor))
  388. #define CSR_VERSION_MAJOR(version) ((version) >> 16)
  389. #define CSR_VERSION_MINOR(version) ((version) & 0xffff)
  390. struct intel_csr {
  391. struct work_struct work;
  392. const char *fw_path;
  393. uint32_t *dmc_payload;
  394. uint32_t dmc_fw_size;
  395. uint32_t version;
  396. uint32_t mmio_count;
  397. i915_reg_t mmioaddr[8];
  398. uint32_t mmiodata[8];
  399. uint32_t dc_state;
  400. uint32_t allowed_dc_mask;
  401. };
  402. #define DEV_INFO_FOR_EACH_FLAG(func) \
  403. func(is_mobile); \
  404. func(is_lp); \
  405. func(is_alpha_support); \
  406. /* Keep has_* in alphabetical order */ \
  407. func(has_64bit_reloc); \
  408. func(has_aliasing_ppgtt); \
  409. func(has_csr); \
  410. func(has_ddi); \
  411. func(has_dp_mst); \
  412. func(has_reset_engine); \
  413. func(has_fbc); \
  414. func(has_fpga_dbg); \
  415. func(has_full_ppgtt); \
  416. func(has_full_48bit_ppgtt); \
  417. func(has_gmch_display); \
  418. func(has_guc); \
  419. func(has_guc_ct); \
  420. func(has_hotplug); \
  421. func(has_l3_dpf); \
  422. func(has_llc); \
  423. func(has_logical_ring_contexts); \
  424. func(has_logical_ring_preemption); \
  425. func(has_overlay); \
  426. func(has_pooled_eu); \
  427. func(has_psr); \
  428. func(has_rc6); \
  429. func(has_rc6p); \
  430. func(has_resource_streamer); \
  431. func(has_runtime_pm); \
  432. func(has_snoop); \
  433. func(unfenced_needs_alignment); \
  434. func(cursor_needs_physical); \
  435. func(hws_needs_physical); \
  436. func(overlay_needs_physical); \
  437. func(supports_tv); \
  438. func(has_ipc);
  439. struct sseu_dev_info {
  440. u8 slice_mask;
  441. u8 subslice_mask;
  442. u8 eu_total;
  443. u8 eu_per_subslice;
  444. u8 min_eu_in_pool;
  445. /* For each slice, which subslice(s) has(have) 7 EUs (bitfield)? */
  446. u8 subslice_7eu[3];
  447. u8 has_slice_pg:1;
  448. u8 has_subslice_pg:1;
  449. u8 has_eu_pg:1;
  450. };
  451. static inline unsigned int sseu_subslice_total(const struct sseu_dev_info *sseu)
  452. {
  453. return hweight8(sseu->slice_mask) * hweight8(sseu->subslice_mask);
  454. }
  455. /* Keep in gen based order, and chronological order within a gen */
  456. enum intel_platform {
  457. INTEL_PLATFORM_UNINITIALIZED = 0,
  458. INTEL_I830,
  459. INTEL_I845G,
  460. INTEL_I85X,
  461. INTEL_I865G,
  462. INTEL_I915G,
  463. INTEL_I915GM,
  464. INTEL_I945G,
  465. INTEL_I945GM,
  466. INTEL_G33,
  467. INTEL_PINEVIEW,
  468. INTEL_I965G,
  469. INTEL_I965GM,
  470. INTEL_G45,
  471. INTEL_GM45,
  472. INTEL_IRONLAKE,
  473. INTEL_SANDYBRIDGE,
  474. INTEL_IVYBRIDGE,
  475. INTEL_VALLEYVIEW,
  476. INTEL_HASWELL,
  477. INTEL_BROADWELL,
  478. INTEL_CHERRYVIEW,
  479. INTEL_SKYLAKE,
  480. INTEL_BROXTON,
  481. INTEL_KABYLAKE,
  482. INTEL_GEMINILAKE,
  483. INTEL_COFFEELAKE,
  484. INTEL_CANNONLAKE,
  485. INTEL_MAX_PLATFORMS
  486. };
  487. struct intel_device_info {
  488. u16 device_id;
  489. u16 gen_mask;
  490. u8 gen;
  491. u8 gt; /* GT number, 0 if undefined */
  492. u8 num_rings;
  493. u8 ring_mask; /* Rings supported by the HW */
  494. enum intel_platform platform;
  495. u32 platform_mask;
  496. u32 display_mmio_offset;
  497. u8 num_pipes;
  498. u8 num_sprites[I915_MAX_PIPES];
  499. u8 num_scalers[I915_MAX_PIPES];
  500. unsigned int page_sizes; /* page sizes supported by the HW */
  501. #define DEFINE_FLAG(name) u8 name:1
  502. DEV_INFO_FOR_EACH_FLAG(DEFINE_FLAG);
  503. #undef DEFINE_FLAG
  504. u16 ddb_size; /* in blocks */
  505. /* Register offsets for the various display pipes and transcoders */
  506. int pipe_offsets[I915_MAX_TRANSCODERS];
  507. int trans_offsets[I915_MAX_TRANSCODERS];
  508. int palette_offsets[I915_MAX_PIPES];
  509. int cursor_offsets[I915_MAX_PIPES];
  510. /* Slice/subslice/EU info */
  511. struct sseu_dev_info sseu;
  512. u32 cs_timestamp_frequency_khz;
  513. struct color_luts {
  514. u16 degamma_lut_size;
  515. u16 gamma_lut_size;
  516. } color;
  517. };
  518. struct intel_display_error_state;
  519. struct i915_gpu_state {
  520. struct kref ref;
  521. struct timeval time;
  522. struct timeval boottime;
  523. struct timeval uptime;
  524. struct drm_i915_private *i915;
  525. char error_msg[128];
  526. bool simulated;
  527. bool awake;
  528. bool wakelock;
  529. bool suspended;
  530. int iommu;
  531. u32 reset_count;
  532. u32 suspend_count;
  533. struct intel_device_info device_info;
  534. struct i915_params params;
  535. struct i915_error_uc {
  536. struct intel_uc_fw guc_fw;
  537. struct intel_uc_fw huc_fw;
  538. struct drm_i915_error_object *guc_log;
  539. } uc;
  540. /* Generic register state */
  541. u32 eir;
  542. u32 pgtbl_er;
  543. u32 ier;
  544. u32 gtier[4], ngtier;
  545. u32 ccid;
  546. u32 derrmr;
  547. u32 forcewake;
  548. u32 error; /* gen6+ */
  549. u32 err_int; /* gen7 */
  550. u32 fault_data0; /* gen8, gen9 */
  551. u32 fault_data1; /* gen8, gen9 */
  552. u32 done_reg;
  553. u32 gac_eco;
  554. u32 gam_ecochk;
  555. u32 gab_ctl;
  556. u32 gfx_mode;
  557. u32 nfence;
  558. u64 fence[I915_MAX_NUM_FENCES];
  559. struct intel_overlay_error_state *overlay;
  560. struct intel_display_error_state *display;
  561. struct drm_i915_error_engine {
  562. int engine_id;
  563. /* Software tracked state */
  564. bool idle;
  565. bool waiting;
  566. int num_waiters;
  567. unsigned long hangcheck_timestamp;
  568. bool hangcheck_stalled;
  569. enum intel_engine_hangcheck_action hangcheck_action;
  570. struct i915_address_space *vm;
  571. int num_requests;
  572. u32 reset_count;
  573. /* position of active request inside the ring */
  574. u32 rq_head, rq_post, rq_tail;
  575. /* our own tracking of ring head and tail */
  576. u32 cpu_ring_head;
  577. u32 cpu_ring_tail;
  578. u32 last_seqno;
  579. /* Register state */
  580. u32 start;
  581. u32 tail;
  582. u32 head;
  583. u32 ctl;
  584. u32 mode;
  585. u32 hws;
  586. u32 ipeir;
  587. u32 ipehr;
  588. u32 bbstate;
  589. u32 instpm;
  590. u32 instps;
  591. u32 seqno;
  592. u64 bbaddr;
  593. u64 acthd;
  594. u32 fault_reg;
  595. u64 faddr;
  596. u32 rc_psmi; /* sleep state */
  597. u32 semaphore_mboxes[I915_NUM_ENGINES - 1];
  598. struct intel_instdone instdone;
  599. struct drm_i915_error_context {
  600. char comm[TASK_COMM_LEN];
  601. pid_t pid;
  602. u32 handle;
  603. u32 hw_id;
  604. int priority;
  605. int ban_score;
  606. int active;
  607. int guilty;
  608. } context;
  609. struct drm_i915_error_object {
  610. u64 gtt_offset;
  611. u64 gtt_size;
  612. int page_count;
  613. int unused;
  614. u32 *pages[0];
  615. } *ringbuffer, *batchbuffer, *wa_batchbuffer, *ctx, *hws_page;
  616. struct drm_i915_error_object **user_bo;
  617. long user_bo_count;
  618. struct drm_i915_error_object *wa_ctx;
  619. struct drm_i915_error_object *default_state;
  620. struct drm_i915_error_request {
  621. long jiffies;
  622. pid_t pid;
  623. u32 context;
  624. int priority;
  625. int ban_score;
  626. u32 seqno;
  627. u32 head;
  628. u32 tail;
  629. } *requests, execlist[EXECLIST_MAX_PORTS];
  630. unsigned int num_ports;
  631. struct drm_i915_error_waiter {
  632. char comm[TASK_COMM_LEN];
  633. pid_t pid;
  634. u32 seqno;
  635. } *waiters;
  636. struct {
  637. u32 gfx_mode;
  638. union {
  639. u64 pdp[4];
  640. u32 pp_dir_base;
  641. };
  642. } vm_info;
  643. } engine[I915_NUM_ENGINES];
  644. struct drm_i915_error_buffer {
  645. u32 size;
  646. u32 name;
  647. u32 rseqno[I915_NUM_ENGINES], wseqno;
  648. u64 gtt_offset;
  649. u32 read_domains;
  650. u32 write_domain;
  651. s32 fence_reg:I915_MAX_NUM_FENCE_BITS;
  652. u32 tiling:2;
  653. u32 dirty:1;
  654. u32 purgeable:1;
  655. u32 userptr:1;
  656. s32 engine:4;
  657. u32 cache_level:3;
  658. } *active_bo[I915_NUM_ENGINES], *pinned_bo;
  659. u32 active_bo_count[I915_NUM_ENGINES], pinned_bo_count;
  660. struct i915_address_space *active_vm[I915_NUM_ENGINES];
  661. };
  662. enum i915_cache_level {
  663. I915_CACHE_NONE = 0,
  664. I915_CACHE_LLC, /* also used for snoopable memory on non-LLC */
  665. I915_CACHE_L3_LLC, /* gen7+, L3 sits between the domain specifc
  666. caches, eg sampler/render caches, and the
  667. large Last-Level-Cache. LLC is coherent with
  668. the CPU, but L3 is only visible to the GPU. */
  669. I915_CACHE_WT, /* hsw:gt3e WriteThrough for scanouts */
  670. };
  671. #define I915_COLOR_UNEVICTABLE (-1) /* a non-vma sharing the address space */
  672. enum fb_op_origin {
  673. ORIGIN_GTT,
  674. ORIGIN_CPU,
  675. ORIGIN_CS,
  676. ORIGIN_FLIP,
  677. ORIGIN_DIRTYFB,
  678. };
  679. struct intel_fbc {
  680. /* This is always the inner lock when overlapping with struct_mutex and
  681. * it's the outer lock when overlapping with stolen_lock. */
  682. struct mutex lock;
  683. unsigned threshold;
  684. unsigned int possible_framebuffer_bits;
  685. unsigned int busy_bits;
  686. unsigned int visible_pipes_mask;
  687. struct intel_crtc *crtc;
  688. struct drm_mm_node compressed_fb;
  689. struct drm_mm_node *compressed_llb;
  690. bool false_color;
  691. bool enabled;
  692. bool active;
  693. bool underrun_detected;
  694. struct work_struct underrun_work;
  695. /*
  696. * Due to the atomic rules we can't access some structures without the
  697. * appropriate locking, so we cache information here in order to avoid
  698. * these problems.
  699. */
  700. struct intel_fbc_state_cache {
  701. struct i915_vma *vma;
  702. struct {
  703. unsigned int mode_flags;
  704. uint32_t hsw_bdw_pixel_rate;
  705. } crtc;
  706. struct {
  707. unsigned int rotation;
  708. int src_w;
  709. int src_h;
  710. bool visible;
  711. /*
  712. * Display surface base address adjustement for
  713. * pageflips. Note that on gen4+ this only adjusts up
  714. * to a tile, offsets within a tile are handled in
  715. * the hw itself (with the TILEOFF register).
  716. */
  717. int adjusted_x;
  718. int adjusted_y;
  719. int y;
  720. } plane;
  721. struct {
  722. const struct drm_format_info *format;
  723. unsigned int stride;
  724. } fb;
  725. } state_cache;
  726. /*
  727. * This structure contains everything that's relevant to program the
  728. * hardware registers. When we want to figure out if we need to disable
  729. * and re-enable FBC for a new configuration we just check if there's
  730. * something different in the struct. The genx_fbc_activate functions
  731. * are supposed to read from it in order to program the registers.
  732. */
  733. struct intel_fbc_reg_params {
  734. struct i915_vma *vma;
  735. struct {
  736. enum pipe pipe;
  737. enum i9xx_plane_id i9xx_plane;
  738. unsigned int fence_y_offset;
  739. } crtc;
  740. struct {
  741. const struct drm_format_info *format;
  742. unsigned int stride;
  743. } fb;
  744. int cfb_size;
  745. unsigned int gen9_wa_cfb_stride;
  746. } params;
  747. struct intel_fbc_work {
  748. bool scheduled;
  749. u32 scheduled_vblank;
  750. struct work_struct work;
  751. } work;
  752. const char *no_fbc_reason;
  753. };
  754. /*
  755. * HIGH_RR is the highest eDP panel refresh rate read from EDID
  756. * LOW_RR is the lowest eDP panel refresh rate found from EDID
  757. * parsing for same resolution.
  758. */
  759. enum drrs_refresh_rate_type {
  760. DRRS_HIGH_RR,
  761. DRRS_LOW_RR,
  762. DRRS_MAX_RR, /* RR count */
  763. };
  764. enum drrs_support_type {
  765. DRRS_NOT_SUPPORTED = 0,
  766. STATIC_DRRS_SUPPORT = 1,
  767. SEAMLESS_DRRS_SUPPORT = 2
  768. };
  769. struct intel_dp;
  770. struct i915_drrs {
  771. struct mutex mutex;
  772. struct delayed_work work;
  773. struct intel_dp *dp;
  774. unsigned busy_frontbuffer_bits;
  775. enum drrs_refresh_rate_type refresh_rate_type;
  776. enum drrs_support_type type;
  777. };
  778. struct i915_psr {
  779. struct mutex lock;
  780. bool sink_support;
  781. bool source_ok;
  782. struct intel_dp *enabled;
  783. bool active;
  784. struct delayed_work work;
  785. unsigned busy_frontbuffer_bits;
  786. bool psr2_support;
  787. bool aux_frame_sync;
  788. bool link_standby;
  789. bool y_cord_support;
  790. bool colorimetry_support;
  791. bool alpm;
  792. void (*enable_source)(struct intel_dp *,
  793. const struct intel_crtc_state *);
  794. void (*disable_source)(struct intel_dp *,
  795. const struct intel_crtc_state *);
  796. void (*enable_sink)(struct intel_dp *);
  797. void (*activate)(struct intel_dp *);
  798. void (*setup_vsc)(struct intel_dp *, const struct intel_crtc_state *);
  799. };
  800. enum intel_pch {
  801. PCH_NONE = 0, /* No PCH present */
  802. PCH_IBX, /* Ibexpeak PCH */
  803. PCH_CPT, /* Cougarpoint/Pantherpoint PCH */
  804. PCH_LPT, /* Lynxpoint/Wildcatpoint PCH */
  805. PCH_SPT, /* Sunrisepoint PCH */
  806. PCH_KBP, /* Kaby Lake PCH */
  807. PCH_CNP, /* Cannon Lake PCH */
  808. PCH_NOP,
  809. };
  810. enum intel_sbi_destination {
  811. SBI_ICLK,
  812. SBI_MPHY,
  813. };
  814. #define QUIRK_LVDS_SSC_DISABLE (1<<1)
  815. #define QUIRK_INVERT_BRIGHTNESS (1<<2)
  816. #define QUIRK_BACKLIGHT_PRESENT (1<<3)
  817. #define QUIRK_PIN_SWIZZLED_PAGES (1<<5)
  818. #define QUIRK_INCREASE_T12_DELAY (1<<6)
  819. struct intel_fbdev;
  820. struct intel_fbc_work;
  821. struct intel_gmbus {
  822. struct i2c_adapter adapter;
  823. #define GMBUS_FORCE_BIT_RETRY (1U << 31)
  824. u32 force_bit;
  825. u32 reg0;
  826. i915_reg_t gpio_reg;
  827. struct i2c_algo_bit_data bit_algo;
  828. struct drm_i915_private *dev_priv;
  829. };
  830. struct i915_suspend_saved_registers {
  831. u32 saveDSPARB;
  832. u32 saveFBC_CONTROL;
  833. u32 saveCACHE_MODE_0;
  834. u32 saveMI_ARB_STATE;
  835. u32 saveSWF0[16];
  836. u32 saveSWF1[16];
  837. u32 saveSWF3[3];
  838. uint64_t saveFENCE[I915_MAX_NUM_FENCES];
  839. u32 savePCH_PORT_HOTPLUG;
  840. u16 saveGCDGMBUS;
  841. };
  842. struct vlv_s0ix_state {
  843. /* GAM */
  844. u32 wr_watermark;
  845. u32 gfx_prio_ctrl;
  846. u32 arb_mode;
  847. u32 gfx_pend_tlb0;
  848. u32 gfx_pend_tlb1;
  849. u32 lra_limits[GEN7_LRA_LIMITS_REG_NUM];
  850. u32 media_max_req_count;
  851. u32 gfx_max_req_count;
  852. u32 render_hwsp;
  853. u32 ecochk;
  854. u32 bsd_hwsp;
  855. u32 blt_hwsp;
  856. u32 tlb_rd_addr;
  857. /* MBC */
  858. u32 g3dctl;
  859. u32 gsckgctl;
  860. u32 mbctl;
  861. /* GCP */
  862. u32 ucgctl1;
  863. u32 ucgctl3;
  864. u32 rcgctl1;
  865. u32 rcgctl2;
  866. u32 rstctl;
  867. u32 misccpctl;
  868. /* GPM */
  869. u32 gfxpause;
  870. u32 rpdeuhwtc;
  871. u32 rpdeuc;
  872. u32 ecobus;
  873. u32 pwrdwnupctl;
  874. u32 rp_down_timeout;
  875. u32 rp_deucsw;
  876. u32 rcubmabdtmr;
  877. u32 rcedata;
  878. u32 spare2gh;
  879. /* Display 1 CZ domain */
  880. u32 gt_imr;
  881. u32 gt_ier;
  882. u32 pm_imr;
  883. u32 pm_ier;
  884. u32 gt_scratch[GEN7_GT_SCRATCH_REG_NUM];
  885. /* GT SA CZ domain */
  886. u32 tilectl;
  887. u32 gt_fifoctl;
  888. u32 gtlc_wake_ctrl;
  889. u32 gtlc_survive;
  890. u32 pmwgicz;
  891. /* Display 2 CZ domain */
  892. u32 gu_ctl0;
  893. u32 gu_ctl1;
  894. u32 pcbr;
  895. u32 clock_gate_dis2;
  896. };
  897. struct intel_rps_ei {
  898. ktime_t ktime;
  899. u32 render_c0;
  900. u32 media_c0;
  901. };
  902. struct intel_rps {
  903. /*
  904. * work, interrupts_enabled and pm_iir are protected by
  905. * dev_priv->irq_lock
  906. */
  907. struct work_struct work;
  908. bool interrupts_enabled;
  909. u32 pm_iir;
  910. /* PM interrupt bits that should never be masked */
  911. u32 pm_intrmsk_mbz;
  912. /* Frequencies are stored in potentially platform dependent multiples.
  913. * In other words, *_freq needs to be multiplied by X to be interesting.
  914. * Soft limits are those which are used for the dynamic reclocking done
  915. * by the driver (raise frequencies under heavy loads, and lower for
  916. * lighter loads). Hard limits are those imposed by the hardware.
  917. *
  918. * A distinction is made for overclocking, which is never enabled by
  919. * default, and is considered to be above the hard limit if it's
  920. * possible at all.
  921. */
  922. u8 cur_freq; /* Current frequency (cached, may not == HW) */
  923. u8 min_freq_softlimit; /* Minimum frequency permitted by the driver */
  924. u8 max_freq_softlimit; /* Max frequency permitted by the driver */
  925. u8 max_freq; /* Maximum frequency, RP0 if not overclocking */
  926. u8 min_freq; /* AKA RPn. Minimum frequency */
  927. u8 boost_freq; /* Frequency to request when wait boosting */
  928. u8 idle_freq; /* Frequency to request when we are idle */
  929. u8 efficient_freq; /* AKA RPe. Pre-determined balanced frequency */
  930. u8 rp1_freq; /* "less than" RP0 power/freqency */
  931. u8 rp0_freq; /* Non-overclocked max frequency. */
  932. u16 gpll_ref_freq; /* vlv/chv GPLL reference frequency */
  933. u8 up_threshold; /* Current %busy required to uplock */
  934. u8 down_threshold; /* Current %busy required to downclock */
  935. int last_adj;
  936. enum { LOW_POWER, BETWEEN, HIGH_POWER } power;
  937. bool enabled;
  938. atomic_t num_waiters;
  939. atomic_t boosts;
  940. /* manual wa residency calculations */
  941. struct intel_rps_ei ei;
  942. };
  943. struct intel_rc6 {
  944. bool enabled;
  945. };
  946. struct intel_llc_pstate {
  947. bool enabled;
  948. };
  949. struct intel_gen6_power_mgmt {
  950. struct intel_rps rps;
  951. struct intel_rc6 rc6;
  952. struct intel_llc_pstate llc_pstate;
  953. };
  954. /* defined intel_pm.c */
  955. extern spinlock_t mchdev_lock;
  956. struct intel_ilk_power_mgmt {
  957. u8 cur_delay;
  958. u8 min_delay;
  959. u8 max_delay;
  960. u8 fmax;
  961. u8 fstart;
  962. u64 last_count1;
  963. unsigned long last_time1;
  964. unsigned long chipset_power;
  965. u64 last_count2;
  966. u64 last_time2;
  967. unsigned long gfx_power;
  968. u8 corr;
  969. int c_m;
  970. int r_t;
  971. };
  972. struct drm_i915_private;
  973. struct i915_power_well;
  974. struct i915_power_well_ops {
  975. /*
  976. * Synchronize the well's hw state to match the current sw state, for
  977. * example enable/disable it based on the current refcount. Called
  978. * during driver init and resume time, possibly after first calling
  979. * the enable/disable handlers.
  980. */
  981. void (*sync_hw)(struct drm_i915_private *dev_priv,
  982. struct i915_power_well *power_well);
  983. /*
  984. * Enable the well and resources that depend on it (for example
  985. * interrupts located on the well). Called after the 0->1 refcount
  986. * transition.
  987. */
  988. void (*enable)(struct drm_i915_private *dev_priv,
  989. struct i915_power_well *power_well);
  990. /*
  991. * Disable the well and resources that depend on it. Called after
  992. * the 1->0 refcount transition.
  993. */
  994. void (*disable)(struct drm_i915_private *dev_priv,
  995. struct i915_power_well *power_well);
  996. /* Returns the hw enabled state. */
  997. bool (*is_enabled)(struct drm_i915_private *dev_priv,
  998. struct i915_power_well *power_well);
  999. };
  1000. /* Power well structure for haswell */
  1001. struct i915_power_well {
  1002. const char *name;
  1003. bool always_on;
  1004. /* power well enable/disable usage count */
  1005. int count;
  1006. /* cached hw enabled state */
  1007. bool hw_enabled;
  1008. u64 domains;
  1009. /* unique identifier for this power well */
  1010. enum i915_power_well_id id;
  1011. /*
  1012. * Arbitraty data associated with this power well. Platform and power
  1013. * well specific.
  1014. */
  1015. union {
  1016. struct {
  1017. enum dpio_phy phy;
  1018. } bxt;
  1019. struct {
  1020. /* Mask of pipes whose IRQ logic is backed by the pw */
  1021. u8 irq_pipe_mask;
  1022. /* The pw is backing the VGA functionality */
  1023. bool has_vga:1;
  1024. bool has_fuses:1;
  1025. } hsw;
  1026. };
  1027. const struct i915_power_well_ops *ops;
  1028. };
  1029. struct i915_power_domains {
  1030. /*
  1031. * Power wells needed for initialization at driver init and suspend
  1032. * time are on. They are kept on until after the first modeset.
  1033. */
  1034. bool init_power_on;
  1035. bool initializing;
  1036. int power_well_count;
  1037. struct mutex lock;
  1038. int domain_use_count[POWER_DOMAIN_NUM];
  1039. struct i915_power_well *power_wells;
  1040. };
  1041. #define MAX_L3_SLICES 2
  1042. struct intel_l3_parity {
  1043. u32 *remap_info[MAX_L3_SLICES];
  1044. struct work_struct error_work;
  1045. int which_slice;
  1046. };
  1047. struct i915_gem_mm {
  1048. /** Memory allocator for GTT stolen memory */
  1049. struct drm_mm stolen;
  1050. /** Protects the usage of the GTT stolen memory allocator. This is
  1051. * always the inner lock when overlapping with struct_mutex. */
  1052. struct mutex stolen_lock;
  1053. /* Protects bound_list/unbound_list and #drm_i915_gem_object.mm.link */
  1054. spinlock_t obj_lock;
  1055. /** List of all objects in gtt_space. Used to restore gtt
  1056. * mappings on resume */
  1057. struct list_head bound_list;
  1058. /**
  1059. * List of objects which are not bound to the GTT (thus
  1060. * are idle and not used by the GPU). These objects may or may
  1061. * not actually have any pages attached.
  1062. */
  1063. struct list_head unbound_list;
  1064. /** List of all objects in gtt_space, currently mmaped by userspace.
  1065. * All objects within this list must also be on bound_list.
  1066. */
  1067. struct list_head userfault_list;
  1068. /**
  1069. * List of objects which are pending destruction.
  1070. */
  1071. struct llist_head free_list;
  1072. struct work_struct free_work;
  1073. spinlock_t free_lock;
  1074. /**
  1075. * Small stash of WC pages
  1076. */
  1077. struct pagevec wc_stash;
  1078. /**
  1079. * tmpfs instance used for shmem backed objects
  1080. */
  1081. struct vfsmount *gemfs;
  1082. /** PPGTT used for aliasing the PPGTT with the GTT */
  1083. struct i915_hw_ppgtt *aliasing_ppgtt;
  1084. struct notifier_block oom_notifier;
  1085. struct notifier_block vmap_notifier;
  1086. struct shrinker shrinker;
  1087. /** LRU list of objects with fence regs on them. */
  1088. struct list_head fence_list;
  1089. /**
  1090. * Workqueue to fault in userptr pages, flushed by the execbuf
  1091. * when required but otherwise left to userspace to try again
  1092. * on EAGAIN.
  1093. */
  1094. struct workqueue_struct *userptr_wq;
  1095. u64 unordered_timeline;
  1096. /* the indicator for dispatch video commands on two BSD rings */
  1097. atomic_t bsd_engine_dispatch_index;
  1098. /** Bit 6 swizzling required for X tiling */
  1099. uint32_t bit_6_swizzle_x;
  1100. /** Bit 6 swizzling required for Y tiling */
  1101. uint32_t bit_6_swizzle_y;
  1102. /* accounting, useful for userland debugging */
  1103. spinlock_t object_stat_lock;
  1104. u64 object_memory;
  1105. u32 object_count;
  1106. };
  1107. struct drm_i915_error_state_buf {
  1108. struct drm_i915_private *i915;
  1109. unsigned bytes;
  1110. unsigned size;
  1111. int err;
  1112. u8 *buf;
  1113. loff_t start;
  1114. loff_t pos;
  1115. };
  1116. #define I915_IDLE_ENGINES_TIMEOUT (200) /* in ms */
  1117. #define I915_RESET_TIMEOUT (10 * HZ) /* 10s */
  1118. #define I915_FENCE_TIMEOUT (10 * HZ) /* 10s */
  1119. #define I915_ENGINE_DEAD_TIMEOUT (4 * HZ) /* Seqno, head and subunits dead */
  1120. #define I915_SEQNO_DEAD_TIMEOUT (12 * HZ) /* Seqno dead with active head */
  1121. struct i915_gpu_error {
  1122. /* For hangcheck timer */
  1123. #define DRM_I915_HANGCHECK_PERIOD 1500 /* in ms */
  1124. #define DRM_I915_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD)
  1125. struct delayed_work hangcheck_work;
  1126. /* For reset and error_state handling. */
  1127. spinlock_t lock;
  1128. /* Protected by the above dev->gpu_error.lock. */
  1129. struct i915_gpu_state *first_error;
  1130. atomic_t pending_fb_pin;
  1131. unsigned long missed_irq_rings;
  1132. /**
  1133. * State variable controlling the reset flow and count
  1134. *
  1135. * This is a counter which gets incremented when reset is triggered,
  1136. *
  1137. * Before the reset commences, the I915_RESET_BACKOFF bit is set
  1138. * meaning that any waiters holding onto the struct_mutex should
  1139. * relinquish the lock immediately in order for the reset to start.
  1140. *
  1141. * If reset is not completed succesfully, the I915_WEDGE bit is
  1142. * set meaning that hardware is terminally sour and there is no
  1143. * recovery. All waiters on the reset_queue will be woken when
  1144. * that happens.
  1145. *
  1146. * This counter is used by the wait_seqno code to notice that reset
  1147. * event happened and it needs to restart the entire ioctl (since most
  1148. * likely the seqno it waited for won't ever signal anytime soon).
  1149. *
  1150. * This is important for lock-free wait paths, where no contended lock
  1151. * naturally enforces the correct ordering between the bail-out of the
  1152. * waiter and the gpu reset work code.
  1153. */
  1154. unsigned long reset_count;
  1155. /**
  1156. * flags: Control various stages of the GPU reset
  1157. *
  1158. * #I915_RESET_BACKOFF - When we start a reset, we want to stop any
  1159. * other users acquiring the struct_mutex. To do this we set the
  1160. * #I915_RESET_BACKOFF bit in the error flags when we detect a reset
  1161. * and then check for that bit before acquiring the struct_mutex (in
  1162. * i915_mutex_lock_interruptible()?). I915_RESET_BACKOFF serves a
  1163. * secondary role in preventing two concurrent global reset attempts.
  1164. *
  1165. * #I915_RESET_HANDOFF - To perform the actual GPU reset, we need the
  1166. * struct_mutex. We try to acquire the struct_mutex in the reset worker,
  1167. * but it may be held by some long running waiter (that we cannot
  1168. * interrupt without causing trouble). Once we are ready to do the GPU
  1169. * reset, we set the I915_RESET_HANDOFF bit and wakeup any waiters. If
  1170. * they already hold the struct_mutex and want to participate they can
  1171. * inspect the bit and do the reset directly, otherwise the worker
  1172. * waits for the struct_mutex.
  1173. *
  1174. * #I915_RESET_ENGINE[num_engines] - Since the driver doesn't need to
  1175. * acquire the struct_mutex to reset an engine, we need an explicit
  1176. * flag to prevent two concurrent reset attempts in the same engine.
  1177. * As the number of engines continues to grow, allocate the flags from
  1178. * the most significant bits.
  1179. *
  1180. * #I915_WEDGED - If reset fails and we can no longer use the GPU,
  1181. * we set the #I915_WEDGED bit. Prior to command submission, e.g.
  1182. * i915_gem_request_alloc(), this bit is checked and the sequence
  1183. * aborted (with -EIO reported to userspace) if set.
  1184. */
  1185. unsigned long flags;
  1186. #define I915_RESET_BACKOFF 0
  1187. #define I915_RESET_HANDOFF 1
  1188. #define I915_RESET_MODESET 2
  1189. #define I915_WEDGED (BITS_PER_LONG - 1)
  1190. #define I915_RESET_ENGINE (I915_WEDGED - I915_NUM_ENGINES)
  1191. /** Number of times an engine has been reset */
  1192. u32 reset_engine_count[I915_NUM_ENGINES];
  1193. /**
  1194. * Waitqueue to signal when a hang is detected. Used to for waiters
  1195. * to release the struct_mutex for the reset to procede.
  1196. */
  1197. wait_queue_head_t wait_queue;
  1198. /**
  1199. * Waitqueue to signal when the reset has completed. Used by clients
  1200. * that wait for dev_priv->mm.wedged to settle.
  1201. */
  1202. wait_queue_head_t reset_queue;
  1203. /* For missed irq/seqno simulation. */
  1204. unsigned long test_irq_rings;
  1205. };
  1206. enum modeset_restore {
  1207. MODESET_ON_LID_OPEN,
  1208. MODESET_DONE,
  1209. MODESET_SUSPENDED,
  1210. };
  1211. #define DP_AUX_A 0x40
  1212. #define DP_AUX_B 0x10
  1213. #define DP_AUX_C 0x20
  1214. #define DP_AUX_D 0x30
  1215. #define DDC_PIN_B 0x05
  1216. #define DDC_PIN_C 0x04
  1217. #define DDC_PIN_D 0x06
  1218. struct ddi_vbt_port_info {
  1219. int max_tmds_clock;
  1220. /*
  1221. * This is an index in the HDMI/DVI DDI buffer translation table.
  1222. * The special value HDMI_LEVEL_SHIFT_UNKNOWN means the VBT didn't
  1223. * populate this field.
  1224. */
  1225. #define HDMI_LEVEL_SHIFT_UNKNOWN 0xff
  1226. uint8_t hdmi_level_shift;
  1227. uint8_t supports_dvi:1;
  1228. uint8_t supports_hdmi:1;
  1229. uint8_t supports_dp:1;
  1230. uint8_t supports_edp:1;
  1231. uint8_t alternate_aux_channel;
  1232. uint8_t alternate_ddc_pin;
  1233. uint8_t dp_boost_level;
  1234. uint8_t hdmi_boost_level;
  1235. };
  1236. enum psr_lines_to_wait {
  1237. PSR_0_LINES_TO_WAIT = 0,
  1238. PSR_1_LINE_TO_WAIT,
  1239. PSR_4_LINES_TO_WAIT,
  1240. PSR_8_LINES_TO_WAIT
  1241. };
  1242. struct intel_vbt_data {
  1243. struct drm_display_mode *lfp_lvds_vbt_mode; /* if any */
  1244. struct drm_display_mode *sdvo_lvds_vbt_mode; /* if any */
  1245. /* Feature bits */
  1246. unsigned int int_tv_support:1;
  1247. unsigned int lvds_dither:1;
  1248. unsigned int lvds_vbt:1;
  1249. unsigned int int_crt_support:1;
  1250. unsigned int lvds_use_ssc:1;
  1251. unsigned int display_clock_mode:1;
  1252. unsigned int fdi_rx_polarity_inverted:1;
  1253. unsigned int panel_type:4;
  1254. int lvds_ssc_freq;
  1255. unsigned int bios_lvds_val; /* initial [PCH_]LVDS reg val in VBIOS */
  1256. enum drrs_support_type drrs_type;
  1257. struct {
  1258. int rate;
  1259. int lanes;
  1260. int preemphasis;
  1261. int vswing;
  1262. bool low_vswing;
  1263. bool initialized;
  1264. bool support;
  1265. int bpp;
  1266. struct edp_power_seq pps;
  1267. } edp;
  1268. struct {
  1269. bool full_link;
  1270. bool require_aux_wakeup;
  1271. int idle_frames;
  1272. enum psr_lines_to_wait lines_to_wait;
  1273. int tp1_wakeup_time;
  1274. int tp2_tp3_wakeup_time;
  1275. } psr;
  1276. struct {
  1277. u16 pwm_freq_hz;
  1278. bool present;
  1279. bool active_low_pwm;
  1280. u8 min_brightness; /* min_brightness/255 of max */
  1281. u8 controller; /* brightness controller number */
  1282. enum intel_backlight_type type;
  1283. } backlight;
  1284. /* MIPI DSI */
  1285. struct {
  1286. u16 panel_id;
  1287. struct mipi_config *config;
  1288. struct mipi_pps_data *pps;
  1289. u16 bl_ports;
  1290. u16 cabc_ports;
  1291. u8 seq_version;
  1292. u32 size;
  1293. u8 *data;
  1294. const u8 *sequence[MIPI_SEQ_MAX];
  1295. } dsi;
  1296. int crt_ddc_pin;
  1297. int child_dev_num;
  1298. struct child_device_config *child_dev;
  1299. struct ddi_vbt_port_info ddi_port_info[I915_MAX_PORTS];
  1300. struct sdvo_device_mapping sdvo_mappings[2];
  1301. };
  1302. enum intel_ddb_partitioning {
  1303. INTEL_DDB_PART_1_2,
  1304. INTEL_DDB_PART_5_6, /* IVB+ */
  1305. };
  1306. struct intel_wm_level {
  1307. bool enable;
  1308. uint32_t pri_val;
  1309. uint32_t spr_val;
  1310. uint32_t cur_val;
  1311. uint32_t fbc_val;
  1312. };
  1313. struct ilk_wm_values {
  1314. uint32_t wm_pipe[3];
  1315. uint32_t wm_lp[3];
  1316. uint32_t wm_lp_spr[3];
  1317. uint32_t wm_linetime[3];
  1318. bool enable_fbc_wm;
  1319. enum intel_ddb_partitioning partitioning;
  1320. };
  1321. struct g4x_pipe_wm {
  1322. uint16_t plane[I915_MAX_PLANES];
  1323. uint16_t fbc;
  1324. };
  1325. struct g4x_sr_wm {
  1326. uint16_t plane;
  1327. uint16_t cursor;
  1328. uint16_t fbc;
  1329. };
  1330. struct vlv_wm_ddl_values {
  1331. uint8_t plane[I915_MAX_PLANES];
  1332. };
  1333. struct vlv_wm_values {
  1334. struct g4x_pipe_wm pipe[3];
  1335. struct g4x_sr_wm sr;
  1336. struct vlv_wm_ddl_values ddl[3];
  1337. uint8_t level;
  1338. bool cxsr;
  1339. };
  1340. struct g4x_wm_values {
  1341. struct g4x_pipe_wm pipe[2];
  1342. struct g4x_sr_wm sr;
  1343. struct g4x_sr_wm hpll;
  1344. bool cxsr;
  1345. bool hpll_en;
  1346. bool fbc_en;
  1347. };
  1348. struct skl_ddb_entry {
  1349. uint16_t start, end; /* in number of blocks, 'end' is exclusive */
  1350. };
  1351. static inline uint16_t skl_ddb_entry_size(const struct skl_ddb_entry *entry)
  1352. {
  1353. return entry->end - entry->start;
  1354. }
  1355. static inline bool skl_ddb_entry_equal(const struct skl_ddb_entry *e1,
  1356. const struct skl_ddb_entry *e2)
  1357. {
  1358. if (e1->start == e2->start && e1->end == e2->end)
  1359. return true;
  1360. return false;
  1361. }
  1362. struct skl_ddb_allocation {
  1363. struct skl_ddb_entry plane[I915_MAX_PIPES][I915_MAX_PLANES]; /* packed/uv */
  1364. struct skl_ddb_entry y_plane[I915_MAX_PIPES][I915_MAX_PLANES];
  1365. };
  1366. struct skl_wm_values {
  1367. unsigned dirty_pipes;
  1368. struct skl_ddb_allocation ddb;
  1369. };
  1370. struct skl_wm_level {
  1371. bool plane_en;
  1372. uint16_t plane_res_b;
  1373. uint8_t plane_res_l;
  1374. };
  1375. /* Stores plane specific WM parameters */
  1376. struct skl_wm_params {
  1377. bool x_tiled, y_tiled;
  1378. bool rc_surface;
  1379. uint32_t width;
  1380. uint8_t cpp;
  1381. uint32_t plane_pixel_rate;
  1382. uint32_t y_min_scanlines;
  1383. uint32_t plane_bytes_per_line;
  1384. uint_fixed_16_16_t plane_blocks_per_line;
  1385. uint_fixed_16_16_t y_tile_minimum;
  1386. uint32_t linetime_us;
  1387. };
  1388. /*
  1389. * This struct helps tracking the state needed for runtime PM, which puts the
  1390. * device in PCI D3 state. Notice that when this happens, nothing on the
  1391. * graphics device works, even register access, so we don't get interrupts nor
  1392. * anything else.
  1393. *
  1394. * Every piece of our code that needs to actually touch the hardware needs to
  1395. * either call intel_runtime_pm_get or call intel_display_power_get with the
  1396. * appropriate power domain.
  1397. *
  1398. * Our driver uses the autosuspend delay feature, which means we'll only really
  1399. * suspend if we stay with zero refcount for a certain amount of time. The
  1400. * default value is currently very conservative (see intel_runtime_pm_enable), but
  1401. * it can be changed with the standard runtime PM files from sysfs.
  1402. *
  1403. * The irqs_disabled variable becomes true exactly after we disable the IRQs and
  1404. * goes back to false exactly before we reenable the IRQs. We use this variable
  1405. * to check if someone is trying to enable/disable IRQs while they're supposed
  1406. * to be disabled. This shouldn't happen and we'll print some error messages in
  1407. * case it happens.
  1408. *
  1409. * For more, read the Documentation/power/runtime_pm.txt.
  1410. */
  1411. struct i915_runtime_pm {
  1412. atomic_t wakeref_count;
  1413. bool suspended;
  1414. bool irqs_enabled;
  1415. };
  1416. enum intel_pipe_crc_source {
  1417. INTEL_PIPE_CRC_SOURCE_NONE,
  1418. INTEL_PIPE_CRC_SOURCE_PLANE1,
  1419. INTEL_PIPE_CRC_SOURCE_PLANE2,
  1420. INTEL_PIPE_CRC_SOURCE_PF,
  1421. INTEL_PIPE_CRC_SOURCE_PIPE,
  1422. /* TV/DP on pre-gen5/vlv can't use the pipe source. */
  1423. INTEL_PIPE_CRC_SOURCE_TV,
  1424. INTEL_PIPE_CRC_SOURCE_DP_B,
  1425. INTEL_PIPE_CRC_SOURCE_DP_C,
  1426. INTEL_PIPE_CRC_SOURCE_DP_D,
  1427. INTEL_PIPE_CRC_SOURCE_AUTO,
  1428. INTEL_PIPE_CRC_SOURCE_MAX,
  1429. };
  1430. struct intel_pipe_crc_entry {
  1431. uint32_t frame;
  1432. uint32_t crc[5];
  1433. };
  1434. #define INTEL_PIPE_CRC_ENTRIES_NR 128
  1435. struct intel_pipe_crc {
  1436. spinlock_t lock;
  1437. bool opened; /* exclusive access to the result file */
  1438. struct intel_pipe_crc_entry *entries;
  1439. enum intel_pipe_crc_source source;
  1440. int head, tail;
  1441. wait_queue_head_t wq;
  1442. int skipped;
  1443. };
  1444. struct i915_frontbuffer_tracking {
  1445. spinlock_t lock;
  1446. /*
  1447. * Tracking bits for delayed frontbuffer flushing du to gpu activity or
  1448. * scheduled flips.
  1449. */
  1450. unsigned busy_bits;
  1451. unsigned flip_bits;
  1452. };
  1453. struct i915_wa_reg {
  1454. i915_reg_t addr;
  1455. u32 value;
  1456. /* bitmask representing WA bits */
  1457. u32 mask;
  1458. };
  1459. #define I915_MAX_WA_REGS 16
  1460. struct i915_workarounds {
  1461. struct i915_wa_reg reg[I915_MAX_WA_REGS];
  1462. u32 count;
  1463. u32 hw_whitelist_count[I915_NUM_ENGINES];
  1464. };
  1465. struct i915_virtual_gpu {
  1466. bool active;
  1467. u32 caps;
  1468. };
  1469. /* used in computing the new watermarks state */
  1470. struct intel_wm_config {
  1471. unsigned int num_pipes_active;
  1472. bool sprites_enabled;
  1473. bool sprites_scaled;
  1474. };
  1475. struct i915_oa_format {
  1476. u32 format;
  1477. int size;
  1478. };
  1479. struct i915_oa_reg {
  1480. i915_reg_t addr;
  1481. u32 value;
  1482. };
  1483. struct i915_oa_config {
  1484. char uuid[UUID_STRING_LEN + 1];
  1485. int id;
  1486. const struct i915_oa_reg *mux_regs;
  1487. u32 mux_regs_len;
  1488. const struct i915_oa_reg *b_counter_regs;
  1489. u32 b_counter_regs_len;
  1490. const struct i915_oa_reg *flex_regs;
  1491. u32 flex_regs_len;
  1492. struct attribute_group sysfs_metric;
  1493. struct attribute *attrs[2];
  1494. struct device_attribute sysfs_metric_id;
  1495. atomic_t ref_count;
  1496. };
  1497. struct i915_perf_stream;
  1498. /**
  1499. * struct i915_perf_stream_ops - the OPs to support a specific stream type
  1500. */
  1501. struct i915_perf_stream_ops {
  1502. /**
  1503. * @enable: Enables the collection of HW samples, either in response to
  1504. * `I915_PERF_IOCTL_ENABLE` or implicitly called when stream is opened
  1505. * without `I915_PERF_FLAG_DISABLED`.
  1506. */
  1507. void (*enable)(struct i915_perf_stream *stream);
  1508. /**
  1509. * @disable: Disables the collection of HW samples, either in response
  1510. * to `I915_PERF_IOCTL_DISABLE` or implicitly called before destroying
  1511. * the stream.
  1512. */
  1513. void (*disable)(struct i915_perf_stream *stream);
  1514. /**
  1515. * @poll_wait: Call poll_wait, passing a wait queue that will be woken
  1516. * once there is something ready to read() for the stream
  1517. */
  1518. void (*poll_wait)(struct i915_perf_stream *stream,
  1519. struct file *file,
  1520. poll_table *wait);
  1521. /**
  1522. * @wait_unlocked: For handling a blocking read, wait until there is
  1523. * something to ready to read() for the stream. E.g. wait on the same
  1524. * wait queue that would be passed to poll_wait().
  1525. */
  1526. int (*wait_unlocked)(struct i915_perf_stream *stream);
  1527. /**
  1528. * @read: Copy buffered metrics as records to userspace
  1529. * **buf**: the userspace, destination buffer
  1530. * **count**: the number of bytes to copy, requested by userspace
  1531. * **offset**: zero at the start of the read, updated as the read
  1532. * proceeds, it represents how many bytes have been copied so far and
  1533. * the buffer offset for copying the next record.
  1534. *
  1535. * Copy as many buffered i915 perf samples and records for this stream
  1536. * to userspace as will fit in the given buffer.
  1537. *
  1538. * Only write complete records; returning -%ENOSPC if there isn't room
  1539. * for a complete record.
  1540. *
  1541. * Return any error condition that results in a short read such as
  1542. * -%ENOSPC or -%EFAULT, even though these may be squashed before
  1543. * returning to userspace.
  1544. */
  1545. int (*read)(struct i915_perf_stream *stream,
  1546. char __user *buf,
  1547. size_t count,
  1548. size_t *offset);
  1549. /**
  1550. * @destroy: Cleanup any stream specific resources.
  1551. *
  1552. * The stream will always be disabled before this is called.
  1553. */
  1554. void (*destroy)(struct i915_perf_stream *stream);
  1555. };
  1556. /**
  1557. * struct i915_perf_stream - state for a single open stream FD
  1558. */
  1559. struct i915_perf_stream {
  1560. /**
  1561. * @dev_priv: i915 drm device
  1562. */
  1563. struct drm_i915_private *dev_priv;
  1564. /**
  1565. * @link: Links the stream into ``&drm_i915_private->streams``
  1566. */
  1567. struct list_head link;
  1568. /**
  1569. * @sample_flags: Flags representing the `DRM_I915_PERF_PROP_SAMPLE_*`
  1570. * properties given when opening a stream, representing the contents
  1571. * of a single sample as read() by userspace.
  1572. */
  1573. u32 sample_flags;
  1574. /**
  1575. * @sample_size: Considering the configured contents of a sample
  1576. * combined with the required header size, this is the total size
  1577. * of a single sample record.
  1578. */
  1579. int sample_size;
  1580. /**
  1581. * @ctx: %NULL if measuring system-wide across all contexts or a
  1582. * specific context that is being monitored.
  1583. */
  1584. struct i915_gem_context *ctx;
  1585. /**
  1586. * @enabled: Whether the stream is currently enabled, considering
  1587. * whether the stream was opened in a disabled state and based
  1588. * on `I915_PERF_IOCTL_ENABLE` and `I915_PERF_IOCTL_DISABLE` calls.
  1589. */
  1590. bool enabled;
  1591. /**
  1592. * @ops: The callbacks providing the implementation of this specific
  1593. * type of configured stream.
  1594. */
  1595. const struct i915_perf_stream_ops *ops;
  1596. /**
  1597. * @oa_config: The OA configuration used by the stream.
  1598. */
  1599. struct i915_oa_config *oa_config;
  1600. };
  1601. /**
  1602. * struct i915_oa_ops - Gen specific implementation of an OA unit stream
  1603. */
  1604. struct i915_oa_ops {
  1605. /**
  1606. * @is_valid_b_counter_reg: Validates register's address for
  1607. * programming boolean counters for a particular platform.
  1608. */
  1609. bool (*is_valid_b_counter_reg)(struct drm_i915_private *dev_priv,
  1610. u32 addr);
  1611. /**
  1612. * @is_valid_mux_reg: Validates register's address for programming mux
  1613. * for a particular platform.
  1614. */
  1615. bool (*is_valid_mux_reg)(struct drm_i915_private *dev_priv, u32 addr);
  1616. /**
  1617. * @is_valid_flex_reg: Validates register's address for programming
  1618. * flex EU filtering for a particular platform.
  1619. */
  1620. bool (*is_valid_flex_reg)(struct drm_i915_private *dev_priv, u32 addr);
  1621. /**
  1622. * @init_oa_buffer: Resets the head and tail pointers of the
  1623. * circular buffer for periodic OA reports.
  1624. *
  1625. * Called when first opening a stream for OA metrics, but also may be
  1626. * called in response to an OA buffer overflow or other error
  1627. * condition.
  1628. *
  1629. * Note it may be necessary to clear the full OA buffer here as part of
  1630. * maintaining the invariable that new reports must be written to
  1631. * zeroed memory for us to be able to reliable detect if an expected
  1632. * report has not yet landed in memory. (At least on Haswell the OA
  1633. * buffer tail pointer is not synchronized with reports being visible
  1634. * to the CPU)
  1635. */
  1636. void (*init_oa_buffer)(struct drm_i915_private *dev_priv);
  1637. /**
  1638. * @enable_metric_set: Selects and applies any MUX configuration to set
  1639. * up the Boolean and Custom (B/C) counters that are part of the
  1640. * counter reports being sampled. May apply system constraints such as
  1641. * disabling EU clock gating as required.
  1642. */
  1643. int (*enable_metric_set)(struct drm_i915_private *dev_priv,
  1644. const struct i915_oa_config *oa_config);
  1645. /**
  1646. * @disable_metric_set: Remove system constraints associated with using
  1647. * the OA unit.
  1648. */
  1649. void (*disable_metric_set)(struct drm_i915_private *dev_priv);
  1650. /**
  1651. * @oa_enable: Enable periodic sampling
  1652. */
  1653. void (*oa_enable)(struct drm_i915_private *dev_priv);
  1654. /**
  1655. * @oa_disable: Disable periodic sampling
  1656. */
  1657. void (*oa_disable)(struct drm_i915_private *dev_priv);
  1658. /**
  1659. * @read: Copy data from the circular OA buffer into a given userspace
  1660. * buffer.
  1661. */
  1662. int (*read)(struct i915_perf_stream *stream,
  1663. char __user *buf,
  1664. size_t count,
  1665. size_t *offset);
  1666. /**
  1667. * @oa_hw_tail_read: read the OA tail pointer register
  1668. *
  1669. * In particular this enables us to share all the fiddly code for
  1670. * handling the OA unit tail pointer race that affects multiple
  1671. * generations.
  1672. */
  1673. u32 (*oa_hw_tail_read)(struct drm_i915_private *dev_priv);
  1674. };
  1675. struct intel_cdclk_state {
  1676. unsigned int cdclk, vco, ref;
  1677. u8 voltage_level;
  1678. };
  1679. struct drm_i915_private {
  1680. struct drm_device drm;
  1681. struct kmem_cache *objects;
  1682. struct kmem_cache *vmas;
  1683. struct kmem_cache *luts;
  1684. struct kmem_cache *requests;
  1685. struct kmem_cache *dependencies;
  1686. struct kmem_cache *priorities;
  1687. const struct intel_device_info info;
  1688. /**
  1689. * Data Stolen Memory - aka "i915 stolen memory" gives us the start and
  1690. * end of stolen which we can optionally use to create GEM objects
  1691. * backed by stolen memory. Note that stolen_usable_size tells us
  1692. * exactly how much of this we are actually allowed to use, given that
  1693. * some portion of it is in fact reserved for use by hardware functions.
  1694. */
  1695. struct resource dsm;
  1696. /**
  1697. * Reseved portion of Data Stolen Memory
  1698. */
  1699. struct resource dsm_reserved;
  1700. /*
  1701. * Stolen memory is segmented in hardware with different portions
  1702. * offlimits to certain functions.
  1703. *
  1704. * The drm_mm is initialised to the total accessible range, as found
  1705. * from the PCI config. On Broadwell+, this is further restricted to
  1706. * avoid the first page! The upper end of stolen memory is reserved for
  1707. * hardware functions and similarly removed from the accessible range.
  1708. */
  1709. resource_size_t stolen_usable_size; /* Total size minus reserved ranges */
  1710. void __iomem *regs;
  1711. struct intel_uncore uncore;
  1712. struct i915_virtual_gpu vgpu;
  1713. struct intel_gvt *gvt;
  1714. struct intel_huc huc;
  1715. struct intel_guc guc;
  1716. struct intel_csr csr;
  1717. struct intel_gmbus gmbus[GMBUS_NUM_PINS];
  1718. /** gmbus_mutex protects against concurrent usage of the single hw gmbus
  1719. * controller on different i2c buses. */
  1720. struct mutex gmbus_mutex;
  1721. /**
  1722. * Base address of the gmbus and gpio block.
  1723. */
  1724. uint32_t gpio_mmio_base;
  1725. /* MMIO base address for MIPI regs */
  1726. uint32_t mipi_mmio_base;
  1727. uint32_t psr_mmio_base;
  1728. uint32_t pps_mmio_base;
  1729. wait_queue_head_t gmbus_wait_queue;
  1730. struct pci_dev *bridge_dev;
  1731. struct intel_engine_cs *engine[I915_NUM_ENGINES];
  1732. /* Context used internally to idle the GPU and setup initial state */
  1733. struct i915_gem_context *kernel_context;
  1734. /* Context only to be used for injecting preemption commands */
  1735. struct i915_gem_context *preempt_context;
  1736. struct intel_engine_cs *engine_class[MAX_ENGINE_CLASS + 1]
  1737. [MAX_ENGINE_INSTANCE + 1];
  1738. struct drm_dma_handle *status_page_dmah;
  1739. struct resource mch_res;
  1740. /* protects the irq masks */
  1741. spinlock_t irq_lock;
  1742. bool display_irqs_enabled;
  1743. /* To control wakeup latency, e.g. for irq-driven dp aux transfers. */
  1744. struct pm_qos_request pm_qos;
  1745. /* Sideband mailbox protection */
  1746. struct mutex sb_lock;
  1747. /** Cached value of IMR to avoid reads in updating the bitfield */
  1748. union {
  1749. u32 irq_mask;
  1750. u32 de_irq_mask[I915_MAX_PIPES];
  1751. };
  1752. u32 gt_irq_mask;
  1753. u32 pm_imr;
  1754. u32 pm_ier;
  1755. u32 pm_rps_events;
  1756. u32 pm_guc_events;
  1757. u32 pipestat_irq_mask[I915_MAX_PIPES];
  1758. struct i915_hotplug hotplug;
  1759. struct intel_fbc fbc;
  1760. struct i915_drrs drrs;
  1761. struct intel_opregion opregion;
  1762. struct intel_vbt_data vbt;
  1763. bool preserve_bios_swizzle;
  1764. /* overlay */
  1765. struct intel_overlay *overlay;
  1766. /* backlight registers and fields in struct intel_panel */
  1767. struct mutex backlight_lock;
  1768. /* LVDS info */
  1769. bool no_aux_handshake;
  1770. /* protects panel power sequencer state */
  1771. struct mutex pps_mutex;
  1772. struct drm_i915_fence_reg fence_regs[I915_MAX_NUM_FENCES]; /* assume 965 */
  1773. int num_fence_regs; /* 8 on pre-965, 16 otherwise */
  1774. unsigned int fsb_freq, mem_freq, is_ddr3;
  1775. unsigned int skl_preferred_vco_freq;
  1776. unsigned int max_cdclk_freq;
  1777. unsigned int max_dotclk_freq;
  1778. unsigned int rawclk_freq;
  1779. unsigned int hpll_freq;
  1780. unsigned int fdi_pll_freq;
  1781. unsigned int czclk_freq;
  1782. struct {
  1783. /*
  1784. * The current logical cdclk state.
  1785. * See intel_atomic_state.cdclk.logical
  1786. *
  1787. * For reading holding any crtc lock is sufficient,
  1788. * for writing must hold all of them.
  1789. */
  1790. struct intel_cdclk_state logical;
  1791. /*
  1792. * The current actual cdclk state.
  1793. * See intel_atomic_state.cdclk.actual
  1794. */
  1795. struct intel_cdclk_state actual;
  1796. /* The current hardware cdclk state */
  1797. struct intel_cdclk_state hw;
  1798. } cdclk;
  1799. /**
  1800. * wq - Driver workqueue for GEM.
  1801. *
  1802. * NOTE: Work items scheduled here are not allowed to grab any modeset
  1803. * locks, for otherwise the flushing done in the pageflip code will
  1804. * result in deadlocks.
  1805. */
  1806. struct workqueue_struct *wq;
  1807. /* Display functions */
  1808. struct drm_i915_display_funcs display;
  1809. /* PCH chipset type */
  1810. enum intel_pch pch_type;
  1811. unsigned short pch_id;
  1812. unsigned long quirks;
  1813. enum modeset_restore modeset_restore;
  1814. struct mutex modeset_restore_lock;
  1815. struct drm_atomic_state *modeset_restore_state;
  1816. struct drm_modeset_acquire_ctx reset_ctx;
  1817. struct list_head vm_list; /* Global list of all address spaces */
  1818. struct i915_ggtt ggtt; /* VM representing the global address space */
  1819. struct i915_gem_mm mm;
  1820. DECLARE_HASHTABLE(mm_structs, 7);
  1821. struct mutex mm_lock;
  1822. struct intel_ppat ppat;
  1823. /* Kernel Modesetting */
  1824. struct intel_crtc *plane_to_crtc_mapping[I915_MAX_PIPES];
  1825. struct intel_crtc *pipe_to_crtc_mapping[I915_MAX_PIPES];
  1826. #ifdef CONFIG_DEBUG_FS
  1827. struct intel_pipe_crc pipe_crc[I915_MAX_PIPES];
  1828. #endif
  1829. /* dpll and cdclk state is protected by connection_mutex */
  1830. int num_shared_dpll;
  1831. struct intel_shared_dpll shared_dplls[I915_NUM_PLLS];
  1832. const struct intel_dpll_mgr *dpll_mgr;
  1833. /*
  1834. * dpll_lock serializes intel_{prepare,enable,disable}_shared_dpll.
  1835. * Must be global rather than per dpll, because on some platforms
  1836. * plls share registers.
  1837. */
  1838. struct mutex dpll_lock;
  1839. unsigned int active_crtcs;
  1840. /* minimum acceptable cdclk for each pipe */
  1841. int min_cdclk[I915_MAX_PIPES];
  1842. /* minimum acceptable voltage level for each pipe */
  1843. u8 min_voltage_level[I915_MAX_PIPES];
  1844. int dpio_phy_iosf_port[I915_NUM_PHYS_VLV];
  1845. struct i915_workarounds workarounds;
  1846. struct i915_frontbuffer_tracking fb_tracking;
  1847. struct intel_atomic_helper {
  1848. struct llist_head free_list;
  1849. struct work_struct free_work;
  1850. } atomic_helper;
  1851. u16 orig_clock;
  1852. bool mchbar_need_disable;
  1853. struct intel_l3_parity l3_parity;
  1854. /* Cannot be determined by PCIID. You must always read a register. */
  1855. u32 edram_cap;
  1856. /*
  1857. * Protects RPS/RC6 register access and PCU communication.
  1858. * Must be taken after struct_mutex if nested. Note that
  1859. * this lock may be held for long periods of time when
  1860. * talking to hw - so only take it when talking to hw!
  1861. */
  1862. struct mutex pcu_lock;
  1863. /* gen6+ GT PM state */
  1864. struct intel_gen6_power_mgmt gt_pm;
  1865. /* ilk-only ips/rps state. Everything in here is protected by the global
  1866. * mchdev_lock in intel_pm.c */
  1867. struct intel_ilk_power_mgmt ips;
  1868. struct i915_power_domains power_domains;
  1869. struct i915_psr psr;
  1870. struct i915_gpu_error gpu_error;
  1871. struct drm_i915_gem_object *vlv_pctx;
  1872. /* list of fbdev register on this device */
  1873. struct intel_fbdev *fbdev;
  1874. struct work_struct fbdev_suspend_work;
  1875. struct drm_property *broadcast_rgb_property;
  1876. struct drm_property *force_audio_property;
  1877. /* hda/i915 audio component */
  1878. struct i915_audio_component *audio_component;
  1879. bool audio_component_registered;
  1880. /**
  1881. * av_mutex - mutex for audio/video sync
  1882. *
  1883. */
  1884. struct mutex av_mutex;
  1885. struct {
  1886. struct list_head list;
  1887. struct llist_head free_list;
  1888. struct work_struct free_work;
  1889. /* The hw wants to have a stable context identifier for the
  1890. * lifetime of the context (for OA, PASID, faults, etc).
  1891. * This is limited in execlists to 21 bits.
  1892. */
  1893. struct ida hw_ida;
  1894. #define MAX_CONTEXT_HW_ID (1<<21) /* exclusive */
  1895. } contexts;
  1896. u32 fdi_rx_config;
  1897. /* Shadow for DISPLAY_PHY_CONTROL which can't be safely read */
  1898. u32 chv_phy_control;
  1899. /*
  1900. * Shadows for CHV DPLL_MD regs to keep the state
  1901. * checker somewhat working in the presence hardware
  1902. * crappiness (can't read out DPLL_MD for pipes B & C).
  1903. */
  1904. u32 chv_dpll_md[I915_MAX_PIPES];
  1905. u32 bxt_phy_grc;
  1906. u32 suspend_count;
  1907. bool suspended_to_idle;
  1908. struct i915_suspend_saved_registers regfile;
  1909. struct vlv_s0ix_state vlv_s0ix_state;
  1910. enum {
  1911. I915_SAGV_UNKNOWN = 0,
  1912. I915_SAGV_DISABLED,
  1913. I915_SAGV_ENABLED,
  1914. I915_SAGV_NOT_CONTROLLED
  1915. } sagv_status;
  1916. struct {
  1917. /*
  1918. * Raw watermark latency values:
  1919. * in 0.1us units for WM0,
  1920. * in 0.5us units for WM1+.
  1921. */
  1922. /* primary */
  1923. uint16_t pri_latency[5];
  1924. /* sprite */
  1925. uint16_t spr_latency[5];
  1926. /* cursor */
  1927. uint16_t cur_latency[5];
  1928. /*
  1929. * Raw watermark memory latency values
  1930. * for SKL for all 8 levels
  1931. * in 1us units.
  1932. */
  1933. uint16_t skl_latency[8];
  1934. /* current hardware state */
  1935. union {
  1936. struct ilk_wm_values hw;
  1937. struct skl_wm_values skl_hw;
  1938. struct vlv_wm_values vlv;
  1939. struct g4x_wm_values g4x;
  1940. };
  1941. uint8_t max_level;
  1942. /*
  1943. * Should be held around atomic WM register writing; also
  1944. * protects * intel_crtc->wm.active and
  1945. * cstate->wm.need_postvbl_update.
  1946. */
  1947. struct mutex wm_mutex;
  1948. /*
  1949. * Set during HW readout of watermarks/DDB. Some platforms
  1950. * need to know when we're still using BIOS-provided values
  1951. * (which we don't fully trust).
  1952. */
  1953. bool distrust_bios_wm;
  1954. } wm;
  1955. struct i915_runtime_pm runtime_pm;
  1956. struct {
  1957. bool initialized;
  1958. struct kobject *metrics_kobj;
  1959. struct ctl_table_header *sysctl_header;
  1960. /*
  1961. * Lock associated with adding/modifying/removing OA configs
  1962. * in dev_priv->perf.metrics_idr.
  1963. */
  1964. struct mutex metrics_lock;
  1965. /*
  1966. * List of dynamic configurations, you need to hold
  1967. * dev_priv->perf.metrics_lock to access it.
  1968. */
  1969. struct idr metrics_idr;
  1970. /*
  1971. * Lock associated with anything below within this structure
  1972. * except exclusive_stream.
  1973. */
  1974. struct mutex lock;
  1975. struct list_head streams;
  1976. struct {
  1977. /*
  1978. * The stream currently using the OA unit. If accessed
  1979. * outside a syscall associated to its file
  1980. * descriptor, you need to hold
  1981. * dev_priv->drm.struct_mutex.
  1982. */
  1983. struct i915_perf_stream *exclusive_stream;
  1984. u32 specific_ctx_id;
  1985. struct hrtimer poll_check_timer;
  1986. wait_queue_head_t poll_wq;
  1987. bool pollin;
  1988. /**
  1989. * For rate limiting any notifications of spurious
  1990. * invalid OA reports
  1991. */
  1992. struct ratelimit_state spurious_report_rs;
  1993. bool periodic;
  1994. int period_exponent;
  1995. struct i915_oa_config test_config;
  1996. struct {
  1997. struct i915_vma *vma;
  1998. u8 *vaddr;
  1999. u32 last_ctx_id;
  2000. int format;
  2001. int format_size;
  2002. /**
  2003. * Locks reads and writes to all head/tail state
  2004. *
  2005. * Consider: the head and tail pointer state
  2006. * needs to be read consistently from a hrtimer
  2007. * callback (atomic context) and read() fop
  2008. * (user context) with tail pointer updates
  2009. * happening in atomic context and head updates
  2010. * in user context and the (unlikely)
  2011. * possibility of read() errors needing to
  2012. * reset all head/tail state.
  2013. *
  2014. * Note: Contention or performance aren't
  2015. * currently a significant concern here
  2016. * considering the relatively low frequency of
  2017. * hrtimer callbacks (5ms period) and that
  2018. * reads typically only happen in response to a
  2019. * hrtimer event and likely complete before the
  2020. * next callback.
  2021. *
  2022. * Note: This lock is not held *while* reading
  2023. * and copying data to userspace so the value
  2024. * of head observed in htrimer callbacks won't
  2025. * represent any partial consumption of data.
  2026. */
  2027. spinlock_t ptr_lock;
  2028. /**
  2029. * One 'aging' tail pointer and one 'aged'
  2030. * tail pointer ready to used for reading.
  2031. *
  2032. * Initial values of 0xffffffff are invalid
  2033. * and imply that an update is required
  2034. * (and should be ignored by an attempted
  2035. * read)
  2036. */
  2037. struct {
  2038. u32 offset;
  2039. } tails[2];
  2040. /**
  2041. * Index for the aged tail ready to read()
  2042. * data up to.
  2043. */
  2044. unsigned int aged_tail_idx;
  2045. /**
  2046. * A monotonic timestamp for when the current
  2047. * aging tail pointer was read; used to
  2048. * determine when it is old enough to trust.
  2049. */
  2050. u64 aging_timestamp;
  2051. /**
  2052. * Although we can always read back the head
  2053. * pointer register, we prefer to avoid
  2054. * trusting the HW state, just to avoid any
  2055. * risk that some hardware condition could
  2056. * somehow bump the head pointer unpredictably
  2057. * and cause us to forward the wrong OA buffer
  2058. * data to userspace.
  2059. */
  2060. u32 head;
  2061. } oa_buffer;
  2062. u32 gen7_latched_oastatus1;
  2063. u32 ctx_oactxctrl_offset;
  2064. u32 ctx_flexeu0_offset;
  2065. /**
  2066. * The RPT_ID/reason field for Gen8+ includes a bit
  2067. * to determine if the CTX ID in the report is valid
  2068. * but the specific bit differs between Gen 8 and 9
  2069. */
  2070. u32 gen8_valid_ctx_bit;
  2071. struct i915_oa_ops ops;
  2072. const struct i915_oa_format *oa_formats;
  2073. } oa;
  2074. } perf;
  2075. /* Abstract the submission mechanism (legacy ringbuffer or execlists) away */
  2076. struct {
  2077. void (*resume)(struct drm_i915_private *);
  2078. void (*cleanup_engine)(struct intel_engine_cs *engine);
  2079. struct list_head timelines;
  2080. struct i915_gem_timeline global_timeline;
  2081. u32 active_requests;
  2082. /**
  2083. * Is the GPU currently considered idle, or busy executing
  2084. * userspace requests? Whilst idle, we allow runtime power
  2085. * management to power down the hardware and display clocks.
  2086. * In order to reduce the effect on performance, there
  2087. * is a slight delay before we do so.
  2088. */
  2089. bool awake;
  2090. /**
  2091. * We leave the user IRQ off as much as possible,
  2092. * but this means that requests will finish and never
  2093. * be retired once the system goes idle. Set a timer to
  2094. * fire periodically while the ring is running. When it
  2095. * fires, go retire requests.
  2096. */
  2097. struct delayed_work retire_work;
  2098. /**
  2099. * When we detect an idle GPU, we want to turn on
  2100. * powersaving features. So once we see that there
  2101. * are no more requests outstanding and no more
  2102. * arrive within a small period of time, we fire
  2103. * off the idle_work.
  2104. */
  2105. struct delayed_work idle_work;
  2106. ktime_t last_init_time;
  2107. } gt;
  2108. /* perform PHY state sanity checks? */
  2109. bool chv_phy_assert[2];
  2110. bool ipc_enabled;
  2111. /* Used to save the pipe-to-encoder mapping for audio */
  2112. struct intel_encoder *av_enc_map[I915_MAX_PIPES];
  2113. /* necessary resource sharing with HDMI LPE audio driver. */
  2114. struct {
  2115. struct platform_device *platdev;
  2116. int irq;
  2117. } lpe_audio;
  2118. struct i915_pmu pmu;
  2119. /*
  2120. * NOTE: This is the dri1/ums dungeon, don't add stuff here. Your patch
  2121. * will be rejected. Instead look for a better place.
  2122. */
  2123. };
  2124. static inline struct drm_i915_private *to_i915(const struct drm_device *dev)
  2125. {
  2126. return container_of(dev, struct drm_i915_private, drm);
  2127. }
  2128. static inline struct drm_i915_private *kdev_to_i915(struct device *kdev)
  2129. {
  2130. return to_i915(dev_get_drvdata(kdev));
  2131. }
  2132. static inline struct drm_i915_private *guc_to_i915(struct intel_guc *guc)
  2133. {
  2134. return container_of(guc, struct drm_i915_private, guc);
  2135. }
  2136. static inline struct drm_i915_private *huc_to_i915(struct intel_huc *huc)
  2137. {
  2138. return container_of(huc, struct drm_i915_private, huc);
  2139. }
  2140. /* Simple iterator over all initialised engines */
  2141. #define for_each_engine(engine__, dev_priv__, id__) \
  2142. for ((id__) = 0; \
  2143. (id__) < I915_NUM_ENGINES; \
  2144. (id__)++) \
  2145. for_each_if ((engine__) = (dev_priv__)->engine[(id__)])
  2146. /* Iterator over subset of engines selected by mask */
  2147. #define for_each_engine_masked(engine__, dev_priv__, mask__, tmp__) \
  2148. for (tmp__ = mask__ & INTEL_INFO(dev_priv__)->ring_mask; \
  2149. tmp__ ? (engine__ = (dev_priv__)->engine[__mask_next_bit(tmp__)]), 1 : 0; )
  2150. enum hdmi_force_audio {
  2151. HDMI_AUDIO_OFF_DVI = -2, /* no aux data for HDMI-DVI converter */
  2152. HDMI_AUDIO_OFF, /* force turn off HDMI audio */
  2153. HDMI_AUDIO_AUTO, /* trust EDID */
  2154. HDMI_AUDIO_ON, /* force turn on HDMI audio */
  2155. };
  2156. #define I915_GTT_OFFSET_NONE ((u32)-1)
  2157. /*
  2158. * Frontbuffer tracking bits. Set in obj->frontbuffer_bits while a gem bo is
  2159. * considered to be the frontbuffer for the given plane interface-wise. This
  2160. * doesn't mean that the hw necessarily already scans it out, but that any
  2161. * rendering (by the cpu or gpu) will land in the frontbuffer eventually.
  2162. *
  2163. * We have one bit per pipe and per scanout plane type.
  2164. */
  2165. #define INTEL_MAX_SPRITE_BITS_PER_PIPE 5
  2166. #define INTEL_FRONTBUFFER_BITS_PER_PIPE 8
  2167. #define INTEL_FRONTBUFFER_PRIMARY(pipe) \
  2168. (1 << (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe)))
  2169. #define INTEL_FRONTBUFFER_CURSOR(pipe) \
  2170. (1 << (1 + (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))))
  2171. #define INTEL_FRONTBUFFER_SPRITE(pipe, plane) \
  2172. (1 << (2 + plane + (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))))
  2173. #define INTEL_FRONTBUFFER_OVERLAY(pipe) \
  2174. (1 << (2 + INTEL_MAX_SPRITE_BITS_PER_PIPE + (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))))
  2175. #define INTEL_FRONTBUFFER_ALL_MASK(pipe) \
  2176. (0xff << (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe)))
  2177. /*
  2178. * Optimised SGL iterator for GEM objects
  2179. */
  2180. static __always_inline struct sgt_iter {
  2181. struct scatterlist *sgp;
  2182. union {
  2183. unsigned long pfn;
  2184. dma_addr_t dma;
  2185. };
  2186. unsigned int curr;
  2187. unsigned int max;
  2188. } __sgt_iter(struct scatterlist *sgl, bool dma) {
  2189. struct sgt_iter s = { .sgp = sgl };
  2190. if (s.sgp) {
  2191. s.max = s.curr = s.sgp->offset;
  2192. s.max += s.sgp->length;
  2193. if (dma)
  2194. s.dma = sg_dma_address(s.sgp);
  2195. else
  2196. s.pfn = page_to_pfn(sg_page(s.sgp));
  2197. }
  2198. return s;
  2199. }
  2200. static inline struct scatterlist *____sg_next(struct scatterlist *sg)
  2201. {
  2202. ++sg;
  2203. if (unlikely(sg_is_chain(sg)))
  2204. sg = sg_chain_ptr(sg);
  2205. return sg;
  2206. }
  2207. /**
  2208. * __sg_next - return the next scatterlist entry in a list
  2209. * @sg: The current sg entry
  2210. *
  2211. * Description:
  2212. * If the entry is the last, return NULL; otherwise, step to the next
  2213. * element in the array (@sg@+1). If that's a chain pointer, follow it;
  2214. * otherwise just return the pointer to the current element.
  2215. **/
  2216. static inline struct scatterlist *__sg_next(struct scatterlist *sg)
  2217. {
  2218. #ifdef CONFIG_DEBUG_SG
  2219. BUG_ON(sg->sg_magic != SG_MAGIC);
  2220. #endif
  2221. return sg_is_last(sg) ? NULL : ____sg_next(sg);
  2222. }
  2223. /**
  2224. * for_each_sgt_dma - iterate over the DMA addresses of the given sg_table
  2225. * @__dmap: DMA address (output)
  2226. * @__iter: 'struct sgt_iter' (iterator state, internal)
  2227. * @__sgt: sg_table to iterate over (input)
  2228. */
  2229. #define for_each_sgt_dma(__dmap, __iter, __sgt) \
  2230. for ((__iter) = __sgt_iter((__sgt)->sgl, true); \
  2231. ((__dmap) = (__iter).dma + (__iter).curr); \
  2232. (((__iter).curr += PAGE_SIZE) >= (__iter).max) ? \
  2233. (__iter) = __sgt_iter(__sg_next((__iter).sgp), true), 0 : 0)
  2234. /**
  2235. * for_each_sgt_page - iterate over the pages of the given sg_table
  2236. * @__pp: page pointer (output)
  2237. * @__iter: 'struct sgt_iter' (iterator state, internal)
  2238. * @__sgt: sg_table to iterate over (input)
  2239. */
  2240. #define for_each_sgt_page(__pp, __iter, __sgt) \
  2241. for ((__iter) = __sgt_iter((__sgt)->sgl, false); \
  2242. ((__pp) = (__iter).pfn == 0 ? NULL : \
  2243. pfn_to_page((__iter).pfn + ((__iter).curr >> PAGE_SHIFT))); \
  2244. (((__iter).curr += PAGE_SIZE) >= (__iter).max) ? \
  2245. (__iter) = __sgt_iter(__sg_next((__iter).sgp), false), 0 : 0)
  2246. static inline unsigned int i915_sg_page_sizes(struct scatterlist *sg)
  2247. {
  2248. unsigned int page_sizes;
  2249. page_sizes = 0;
  2250. while (sg) {
  2251. GEM_BUG_ON(sg->offset);
  2252. GEM_BUG_ON(!IS_ALIGNED(sg->length, PAGE_SIZE));
  2253. page_sizes |= sg->length;
  2254. sg = __sg_next(sg);
  2255. }
  2256. return page_sizes;
  2257. }
  2258. static inline unsigned int i915_sg_segment_size(void)
  2259. {
  2260. unsigned int size = swiotlb_max_segment();
  2261. if (size == 0)
  2262. return SCATTERLIST_MAX_SEGMENT;
  2263. size = rounddown(size, PAGE_SIZE);
  2264. /* swiotlb_max_segment_size can return 1 byte when it means one page. */
  2265. if (size < PAGE_SIZE)
  2266. size = PAGE_SIZE;
  2267. return size;
  2268. }
  2269. static inline const struct intel_device_info *
  2270. intel_info(const struct drm_i915_private *dev_priv)
  2271. {
  2272. return &dev_priv->info;
  2273. }
  2274. #define INTEL_INFO(dev_priv) intel_info((dev_priv))
  2275. #define INTEL_GEN(dev_priv) ((dev_priv)->info.gen)
  2276. #define INTEL_DEVID(dev_priv) ((dev_priv)->info.device_id)
  2277. #define REVID_FOREVER 0xff
  2278. #define INTEL_REVID(dev_priv) ((dev_priv)->drm.pdev->revision)
  2279. #define GEN_FOREVER (0)
  2280. #define INTEL_GEN_MASK(s, e) ( \
  2281. BUILD_BUG_ON_ZERO(!__builtin_constant_p(s)) + \
  2282. BUILD_BUG_ON_ZERO(!__builtin_constant_p(e)) + \
  2283. GENMASK((e) != GEN_FOREVER ? (e) - 1 : BITS_PER_LONG - 1, \
  2284. (s) != GEN_FOREVER ? (s) - 1 : 0) \
  2285. )
  2286. /*
  2287. * Returns true if Gen is in inclusive range [Start, End].
  2288. *
  2289. * Use GEN_FOREVER for unbound start and or end.
  2290. */
  2291. #define IS_GEN(dev_priv, s, e) \
  2292. (!!((dev_priv)->info.gen_mask & INTEL_GEN_MASK((s), (e))))
  2293. /*
  2294. * Return true if revision is in range [since,until] inclusive.
  2295. *
  2296. * Use 0 for open-ended since, and REVID_FOREVER for open-ended until.
  2297. */
  2298. #define IS_REVID(p, since, until) \
  2299. (INTEL_REVID(p) >= (since) && INTEL_REVID(p) <= (until))
  2300. #define IS_PLATFORM(dev_priv, p) ((dev_priv)->info.platform_mask & BIT(p))
  2301. #define IS_I830(dev_priv) IS_PLATFORM(dev_priv, INTEL_I830)
  2302. #define IS_I845G(dev_priv) IS_PLATFORM(dev_priv, INTEL_I845G)
  2303. #define IS_I85X(dev_priv) IS_PLATFORM(dev_priv, INTEL_I85X)
  2304. #define IS_I865G(dev_priv) IS_PLATFORM(dev_priv, INTEL_I865G)
  2305. #define IS_I915G(dev_priv) IS_PLATFORM(dev_priv, INTEL_I915G)
  2306. #define IS_I915GM(dev_priv) IS_PLATFORM(dev_priv, INTEL_I915GM)
  2307. #define IS_I945G(dev_priv) IS_PLATFORM(dev_priv, INTEL_I945G)
  2308. #define IS_I945GM(dev_priv) IS_PLATFORM(dev_priv, INTEL_I945GM)
  2309. #define IS_I965G(dev_priv) IS_PLATFORM(dev_priv, INTEL_I965G)
  2310. #define IS_I965GM(dev_priv) IS_PLATFORM(dev_priv, INTEL_I965GM)
  2311. #define IS_G45(dev_priv) IS_PLATFORM(dev_priv, INTEL_G45)
  2312. #define IS_GM45(dev_priv) IS_PLATFORM(dev_priv, INTEL_GM45)
  2313. #define IS_G4X(dev_priv) (IS_G45(dev_priv) || IS_GM45(dev_priv))
  2314. #define IS_PINEVIEW_G(dev_priv) (INTEL_DEVID(dev_priv) == 0xa001)
  2315. #define IS_PINEVIEW_M(dev_priv) (INTEL_DEVID(dev_priv) == 0xa011)
  2316. #define IS_PINEVIEW(dev_priv) IS_PLATFORM(dev_priv, INTEL_PINEVIEW)
  2317. #define IS_G33(dev_priv) IS_PLATFORM(dev_priv, INTEL_G33)
  2318. #define IS_IRONLAKE_M(dev_priv) (INTEL_DEVID(dev_priv) == 0x0046)
  2319. #define IS_IVYBRIDGE(dev_priv) IS_PLATFORM(dev_priv, INTEL_IVYBRIDGE)
  2320. #define IS_IVB_GT1(dev_priv) (IS_IVYBRIDGE(dev_priv) && \
  2321. (dev_priv)->info.gt == 1)
  2322. #define IS_VALLEYVIEW(dev_priv) IS_PLATFORM(dev_priv, INTEL_VALLEYVIEW)
  2323. #define IS_CHERRYVIEW(dev_priv) IS_PLATFORM(dev_priv, INTEL_CHERRYVIEW)
  2324. #define IS_HASWELL(dev_priv) IS_PLATFORM(dev_priv, INTEL_HASWELL)
  2325. #define IS_BROADWELL(dev_priv) IS_PLATFORM(dev_priv, INTEL_BROADWELL)
  2326. #define IS_SKYLAKE(dev_priv) IS_PLATFORM(dev_priv, INTEL_SKYLAKE)
  2327. #define IS_BROXTON(dev_priv) IS_PLATFORM(dev_priv, INTEL_BROXTON)
  2328. #define IS_KABYLAKE(dev_priv) IS_PLATFORM(dev_priv, INTEL_KABYLAKE)
  2329. #define IS_GEMINILAKE(dev_priv) IS_PLATFORM(dev_priv, INTEL_GEMINILAKE)
  2330. #define IS_COFFEELAKE(dev_priv) IS_PLATFORM(dev_priv, INTEL_COFFEELAKE)
  2331. #define IS_CANNONLAKE(dev_priv) IS_PLATFORM(dev_priv, INTEL_CANNONLAKE)
  2332. #define IS_MOBILE(dev_priv) ((dev_priv)->info.is_mobile)
  2333. #define IS_HSW_EARLY_SDV(dev_priv) (IS_HASWELL(dev_priv) && \
  2334. (INTEL_DEVID(dev_priv) & 0xFF00) == 0x0C00)
  2335. #define IS_BDW_ULT(dev_priv) (IS_BROADWELL(dev_priv) && \
  2336. ((INTEL_DEVID(dev_priv) & 0xf) == 0x6 || \
  2337. (INTEL_DEVID(dev_priv) & 0xf) == 0xb || \
  2338. (INTEL_DEVID(dev_priv) & 0xf) == 0xe))
  2339. /* ULX machines are also considered ULT. */
  2340. #define IS_BDW_ULX(dev_priv) (IS_BROADWELL(dev_priv) && \
  2341. (INTEL_DEVID(dev_priv) & 0xf) == 0xe)
  2342. #define IS_BDW_GT3(dev_priv) (IS_BROADWELL(dev_priv) && \
  2343. (dev_priv)->info.gt == 3)
  2344. #define IS_HSW_ULT(dev_priv) (IS_HASWELL(dev_priv) && \
  2345. (INTEL_DEVID(dev_priv) & 0xFF00) == 0x0A00)
  2346. #define IS_HSW_GT3(dev_priv) (IS_HASWELL(dev_priv) && \
  2347. (dev_priv)->info.gt == 3)
  2348. /* ULX machines are also considered ULT. */
  2349. #define IS_HSW_ULX(dev_priv) (INTEL_DEVID(dev_priv) == 0x0A0E || \
  2350. INTEL_DEVID(dev_priv) == 0x0A1E)
  2351. #define IS_SKL_ULT(dev_priv) (INTEL_DEVID(dev_priv) == 0x1906 || \
  2352. INTEL_DEVID(dev_priv) == 0x1913 || \
  2353. INTEL_DEVID(dev_priv) == 0x1916 || \
  2354. INTEL_DEVID(dev_priv) == 0x1921 || \
  2355. INTEL_DEVID(dev_priv) == 0x1926)
  2356. #define IS_SKL_ULX(dev_priv) (INTEL_DEVID(dev_priv) == 0x190E || \
  2357. INTEL_DEVID(dev_priv) == 0x1915 || \
  2358. INTEL_DEVID(dev_priv) == 0x191E)
  2359. #define IS_KBL_ULT(dev_priv) (INTEL_DEVID(dev_priv) == 0x5906 || \
  2360. INTEL_DEVID(dev_priv) == 0x5913 || \
  2361. INTEL_DEVID(dev_priv) == 0x5916 || \
  2362. INTEL_DEVID(dev_priv) == 0x5921 || \
  2363. INTEL_DEVID(dev_priv) == 0x5926)
  2364. #define IS_KBL_ULX(dev_priv) (INTEL_DEVID(dev_priv) == 0x590E || \
  2365. INTEL_DEVID(dev_priv) == 0x5915 || \
  2366. INTEL_DEVID(dev_priv) == 0x591E)
  2367. #define IS_SKL_GT2(dev_priv) (IS_SKYLAKE(dev_priv) && \
  2368. (dev_priv)->info.gt == 2)
  2369. #define IS_SKL_GT3(dev_priv) (IS_SKYLAKE(dev_priv) && \
  2370. (dev_priv)->info.gt == 3)
  2371. #define IS_SKL_GT4(dev_priv) (IS_SKYLAKE(dev_priv) && \
  2372. (dev_priv)->info.gt == 4)
  2373. #define IS_KBL_GT2(dev_priv) (IS_KABYLAKE(dev_priv) && \
  2374. (dev_priv)->info.gt == 2)
  2375. #define IS_KBL_GT3(dev_priv) (IS_KABYLAKE(dev_priv) && \
  2376. (dev_priv)->info.gt == 3)
  2377. #define IS_CFL_ULT(dev_priv) (IS_COFFEELAKE(dev_priv) && \
  2378. (INTEL_DEVID(dev_priv) & 0x00F0) == 0x00A0)
  2379. #define IS_CFL_GT2(dev_priv) (IS_COFFEELAKE(dev_priv) && \
  2380. (dev_priv)->info.gt == 2)
  2381. #define IS_CFL_GT3(dev_priv) (IS_COFFEELAKE(dev_priv) && \
  2382. (dev_priv)->info.gt == 3)
  2383. #define IS_ALPHA_SUPPORT(intel_info) ((intel_info)->is_alpha_support)
  2384. #define SKL_REVID_A0 0x0
  2385. #define SKL_REVID_B0 0x1
  2386. #define SKL_REVID_C0 0x2
  2387. #define SKL_REVID_D0 0x3
  2388. #define SKL_REVID_E0 0x4
  2389. #define SKL_REVID_F0 0x5
  2390. #define SKL_REVID_G0 0x6
  2391. #define SKL_REVID_H0 0x7
  2392. #define IS_SKL_REVID(p, since, until) (IS_SKYLAKE(p) && IS_REVID(p, since, until))
  2393. #define BXT_REVID_A0 0x0
  2394. #define BXT_REVID_A1 0x1
  2395. #define BXT_REVID_B0 0x3
  2396. #define BXT_REVID_B_LAST 0x8
  2397. #define BXT_REVID_C0 0x9
  2398. #define IS_BXT_REVID(dev_priv, since, until) \
  2399. (IS_BROXTON(dev_priv) && IS_REVID(dev_priv, since, until))
  2400. #define KBL_REVID_A0 0x0
  2401. #define KBL_REVID_B0 0x1
  2402. #define KBL_REVID_C0 0x2
  2403. #define KBL_REVID_D0 0x3
  2404. #define KBL_REVID_E0 0x4
  2405. #define IS_KBL_REVID(dev_priv, since, until) \
  2406. (IS_KABYLAKE(dev_priv) && IS_REVID(dev_priv, since, until))
  2407. #define GLK_REVID_A0 0x0
  2408. #define GLK_REVID_A1 0x1
  2409. #define IS_GLK_REVID(dev_priv, since, until) \
  2410. (IS_GEMINILAKE(dev_priv) && IS_REVID(dev_priv, since, until))
  2411. #define CNL_REVID_A0 0x0
  2412. #define CNL_REVID_B0 0x1
  2413. #define CNL_REVID_C0 0x2
  2414. #define IS_CNL_REVID(p, since, until) \
  2415. (IS_CANNONLAKE(p) && IS_REVID(p, since, until))
  2416. /*
  2417. * The genX designation typically refers to the render engine, so render
  2418. * capability related checks should use IS_GEN, while display and other checks
  2419. * have their own (e.g. HAS_PCH_SPLIT for ILK+ display, IS_foo for particular
  2420. * chips, etc.).
  2421. */
  2422. #define IS_GEN2(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(1)))
  2423. #define IS_GEN3(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(2)))
  2424. #define IS_GEN4(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(3)))
  2425. #define IS_GEN5(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(4)))
  2426. #define IS_GEN6(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(5)))
  2427. #define IS_GEN7(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(6)))
  2428. #define IS_GEN8(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(7)))
  2429. #define IS_GEN9(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(8)))
  2430. #define IS_GEN10(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(9)))
  2431. #define IS_LP(dev_priv) (INTEL_INFO(dev_priv)->is_lp)
  2432. #define IS_GEN9_LP(dev_priv) (IS_GEN9(dev_priv) && IS_LP(dev_priv))
  2433. #define IS_GEN9_BC(dev_priv) (IS_GEN9(dev_priv) && !IS_LP(dev_priv))
  2434. #define ENGINE_MASK(id) BIT(id)
  2435. #define RENDER_RING ENGINE_MASK(RCS)
  2436. #define BSD_RING ENGINE_MASK(VCS)
  2437. #define BLT_RING ENGINE_MASK(BCS)
  2438. #define VEBOX_RING ENGINE_MASK(VECS)
  2439. #define BSD2_RING ENGINE_MASK(VCS2)
  2440. #define ALL_ENGINES (~0)
  2441. #define HAS_ENGINE(dev_priv, id) \
  2442. (!!((dev_priv)->info.ring_mask & ENGINE_MASK(id)))
  2443. #define HAS_BSD(dev_priv) HAS_ENGINE(dev_priv, VCS)
  2444. #define HAS_BSD2(dev_priv) HAS_ENGINE(dev_priv, VCS2)
  2445. #define HAS_BLT(dev_priv) HAS_ENGINE(dev_priv, BCS)
  2446. #define HAS_VEBOX(dev_priv) HAS_ENGINE(dev_priv, VECS)
  2447. #define HAS_LEGACY_SEMAPHORES(dev_priv) IS_GEN7(dev_priv)
  2448. #define HAS_LLC(dev_priv) ((dev_priv)->info.has_llc)
  2449. #define HAS_SNOOP(dev_priv) ((dev_priv)->info.has_snoop)
  2450. #define HAS_EDRAM(dev_priv) (!!((dev_priv)->edram_cap & EDRAM_ENABLED))
  2451. #define HAS_WT(dev_priv) ((IS_HASWELL(dev_priv) || \
  2452. IS_BROADWELL(dev_priv)) && HAS_EDRAM(dev_priv))
  2453. #define HWS_NEEDS_PHYSICAL(dev_priv) ((dev_priv)->info.hws_needs_physical)
  2454. #define HAS_LOGICAL_RING_CONTEXTS(dev_priv) \
  2455. ((dev_priv)->info.has_logical_ring_contexts)
  2456. #define HAS_LOGICAL_RING_PREEMPTION(dev_priv) \
  2457. ((dev_priv)->info.has_logical_ring_preemption)
  2458. #define HAS_EXECLISTS(dev_priv) HAS_LOGICAL_RING_CONTEXTS(dev_priv)
  2459. #define USES_PPGTT(dev_priv) (i915_modparams.enable_ppgtt)
  2460. #define USES_FULL_PPGTT(dev_priv) (i915_modparams.enable_ppgtt >= 2)
  2461. #define USES_FULL_48BIT_PPGTT(dev_priv) (i915_modparams.enable_ppgtt == 3)
  2462. #define HAS_PAGE_SIZES(dev_priv, sizes) ({ \
  2463. GEM_BUG_ON((sizes) == 0); \
  2464. ((sizes) & ~(dev_priv)->info.page_sizes) == 0; \
  2465. })
  2466. #define HAS_OVERLAY(dev_priv) ((dev_priv)->info.has_overlay)
  2467. #define OVERLAY_NEEDS_PHYSICAL(dev_priv) \
  2468. ((dev_priv)->info.overlay_needs_physical)
  2469. /* Early gen2 have a totally busted CS tlb and require pinned batches. */
  2470. #define HAS_BROKEN_CS_TLB(dev_priv) (IS_I830(dev_priv) || IS_I845G(dev_priv))
  2471. /* WaRsDisableCoarsePowerGating:skl,bxt */
  2472. #define NEEDS_WaRsDisableCoarsePowerGating(dev_priv) \
  2473. (IS_SKL_GT3(dev_priv) || IS_SKL_GT4(dev_priv))
  2474. /*
  2475. * dp aux and gmbus irq on gen4 seems to be able to generate legacy interrupts
  2476. * even when in MSI mode. This results in spurious interrupt warnings if the
  2477. * legacy irq no. is shared with another device. The kernel then disables that
  2478. * interrupt source and so prevents the other device from working properly.
  2479. *
  2480. * Since we don't enable MSI anymore on gen4, we can always use GMBUS/AUX
  2481. * interrupts.
  2482. */
  2483. #define HAS_AUX_IRQ(dev_priv) true
  2484. #define HAS_GMBUS_IRQ(dev_priv) (INTEL_GEN(dev_priv) >= 4)
  2485. /* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte
  2486. * rows, which changed the alignment requirements and fence programming.
  2487. */
  2488. #define HAS_128_BYTE_Y_TILING(dev_priv) (!IS_GEN2(dev_priv) && \
  2489. !(IS_I915G(dev_priv) || \
  2490. IS_I915GM(dev_priv)))
  2491. #define SUPPORTS_TV(dev_priv) ((dev_priv)->info.supports_tv)
  2492. #define I915_HAS_HOTPLUG(dev_priv) ((dev_priv)->info.has_hotplug)
  2493. #define HAS_FW_BLC(dev_priv) (INTEL_GEN(dev_priv) > 2)
  2494. #define HAS_FBC(dev_priv) ((dev_priv)->info.has_fbc)
  2495. #define HAS_CUR_FBC(dev_priv) (!HAS_GMCH_DISPLAY(dev_priv) && INTEL_INFO(dev_priv)->gen >= 7)
  2496. #define HAS_IPS(dev_priv) (IS_HSW_ULT(dev_priv) || IS_BROADWELL(dev_priv))
  2497. #define HAS_DP_MST(dev_priv) ((dev_priv)->info.has_dp_mst)
  2498. #define HAS_DDI(dev_priv) ((dev_priv)->info.has_ddi)
  2499. #define HAS_FPGA_DBG_UNCLAIMED(dev_priv) ((dev_priv)->info.has_fpga_dbg)
  2500. #define HAS_PSR(dev_priv) ((dev_priv)->info.has_psr)
  2501. #define HAS_RC6(dev_priv) ((dev_priv)->info.has_rc6)
  2502. #define HAS_RC6p(dev_priv) ((dev_priv)->info.has_rc6p)
  2503. #define HAS_RC6pp(dev_priv) (false) /* HW was never validated */
  2504. #define HAS_CSR(dev_priv) ((dev_priv)->info.has_csr)
  2505. #define HAS_RUNTIME_PM(dev_priv) ((dev_priv)->info.has_runtime_pm)
  2506. #define HAS_64BIT_RELOC(dev_priv) ((dev_priv)->info.has_64bit_reloc)
  2507. #define HAS_IPC(dev_priv) ((dev_priv)->info.has_ipc)
  2508. /*
  2509. * For now, anything with a GuC requires uCode loading, and then supports
  2510. * command submission once loaded. But these are logically independent
  2511. * properties, so we have separate macros to test them.
  2512. */
  2513. #define HAS_GUC(dev_priv) ((dev_priv)->info.has_guc)
  2514. #define HAS_GUC_CT(dev_priv) ((dev_priv)->info.has_guc_ct)
  2515. #define HAS_GUC_UCODE(dev_priv) (HAS_GUC(dev_priv))
  2516. #define HAS_GUC_SCHED(dev_priv) (HAS_GUC(dev_priv))
  2517. /* For now, anything with a GuC has also HuC */
  2518. #define HAS_HUC(dev_priv) (HAS_GUC(dev_priv))
  2519. #define HAS_HUC_UCODE(dev_priv) (HAS_GUC(dev_priv))
  2520. /* Having a GuC is not the same as using a GuC */
  2521. #define USES_GUC(dev_priv) intel_uc_is_using_guc()
  2522. #define USES_GUC_SUBMISSION(dev_priv) intel_uc_is_using_guc_submission()
  2523. #define USES_HUC(dev_priv) intel_uc_is_using_huc()
  2524. #define HAS_RESOURCE_STREAMER(dev_priv) ((dev_priv)->info.has_resource_streamer)
  2525. #define HAS_POOLED_EU(dev_priv) ((dev_priv)->info.has_pooled_eu)
  2526. #define INTEL_PCH_DEVICE_ID_MASK 0xff80
  2527. #define INTEL_PCH_IBX_DEVICE_ID_TYPE 0x3b00
  2528. #define INTEL_PCH_CPT_DEVICE_ID_TYPE 0x1c00
  2529. #define INTEL_PCH_PPT_DEVICE_ID_TYPE 0x1e00
  2530. #define INTEL_PCH_LPT_DEVICE_ID_TYPE 0x8c00
  2531. #define INTEL_PCH_LPT_LP_DEVICE_ID_TYPE 0x9c00
  2532. #define INTEL_PCH_WPT_DEVICE_ID_TYPE 0x8c80
  2533. #define INTEL_PCH_WPT_LP_DEVICE_ID_TYPE 0x9c80
  2534. #define INTEL_PCH_SPT_DEVICE_ID_TYPE 0xA100
  2535. #define INTEL_PCH_SPT_LP_DEVICE_ID_TYPE 0x9D00
  2536. #define INTEL_PCH_KBP_DEVICE_ID_TYPE 0xA280
  2537. #define INTEL_PCH_CNP_DEVICE_ID_TYPE 0xA300
  2538. #define INTEL_PCH_CNP_LP_DEVICE_ID_TYPE 0x9D80
  2539. #define INTEL_PCH_P2X_DEVICE_ID_TYPE 0x7100
  2540. #define INTEL_PCH_P3X_DEVICE_ID_TYPE 0x7000
  2541. #define INTEL_PCH_QEMU_DEVICE_ID_TYPE 0x2900 /* qemu q35 has 2918 */
  2542. #define INTEL_PCH_TYPE(dev_priv) ((dev_priv)->pch_type)
  2543. #define HAS_PCH_CNP(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_CNP)
  2544. #define HAS_PCH_CNP_LP(dev_priv) \
  2545. ((dev_priv)->pch_id == INTEL_PCH_CNP_LP_DEVICE_ID_TYPE)
  2546. #define HAS_PCH_KBP(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_KBP)
  2547. #define HAS_PCH_SPT(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_SPT)
  2548. #define HAS_PCH_LPT(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_LPT)
  2549. #define HAS_PCH_LPT_LP(dev_priv) \
  2550. ((dev_priv)->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE || \
  2551. (dev_priv)->pch_id == INTEL_PCH_WPT_LP_DEVICE_ID_TYPE)
  2552. #define HAS_PCH_LPT_H(dev_priv) \
  2553. ((dev_priv)->pch_id == INTEL_PCH_LPT_DEVICE_ID_TYPE || \
  2554. (dev_priv)->pch_id == INTEL_PCH_WPT_DEVICE_ID_TYPE)
  2555. #define HAS_PCH_CPT(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_CPT)
  2556. #define HAS_PCH_IBX(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_IBX)
  2557. #define HAS_PCH_NOP(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_NOP)
  2558. #define HAS_PCH_SPLIT(dev_priv) (INTEL_PCH_TYPE(dev_priv) != PCH_NONE)
  2559. #define HAS_GMCH_DISPLAY(dev_priv) ((dev_priv)->info.has_gmch_display)
  2560. #define HAS_LSPCON(dev_priv) (INTEL_GEN(dev_priv) >= 9)
  2561. /* DPF == dynamic parity feature */
  2562. #define HAS_L3_DPF(dev_priv) ((dev_priv)->info.has_l3_dpf)
  2563. #define NUM_L3_SLICES(dev_priv) (IS_HSW_GT3(dev_priv) ? \
  2564. 2 : HAS_L3_DPF(dev_priv))
  2565. #define GT_FREQUENCY_MULTIPLIER 50
  2566. #define GEN9_FREQ_SCALER 3
  2567. #include "i915_trace.h"
  2568. static inline bool intel_vtd_active(void)
  2569. {
  2570. #ifdef CONFIG_INTEL_IOMMU
  2571. if (intel_iommu_gfx_mapped)
  2572. return true;
  2573. #endif
  2574. return false;
  2575. }
  2576. static inline bool intel_scanout_needs_vtd_wa(struct drm_i915_private *dev_priv)
  2577. {
  2578. return INTEL_GEN(dev_priv) >= 6 && intel_vtd_active();
  2579. }
  2580. static inline bool
  2581. intel_ggtt_update_needs_vtd_wa(struct drm_i915_private *dev_priv)
  2582. {
  2583. return IS_BROXTON(dev_priv) && intel_vtd_active();
  2584. }
  2585. int intel_sanitize_enable_ppgtt(struct drm_i915_private *dev_priv,
  2586. int enable_ppgtt);
  2587. /* i915_drv.c */
  2588. void __printf(3, 4)
  2589. __i915_printk(struct drm_i915_private *dev_priv, const char *level,
  2590. const char *fmt, ...);
  2591. #define i915_report_error(dev_priv, fmt, ...) \
  2592. __i915_printk(dev_priv, KERN_ERR, fmt, ##__VA_ARGS__)
  2593. #ifdef CONFIG_COMPAT
  2594. extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
  2595. unsigned long arg);
  2596. #else
  2597. #define i915_compat_ioctl NULL
  2598. #endif
  2599. extern const struct dev_pm_ops i915_pm_ops;
  2600. extern int i915_driver_load(struct pci_dev *pdev,
  2601. const struct pci_device_id *ent);
  2602. extern void i915_driver_unload(struct drm_device *dev);
  2603. extern int intel_gpu_reset(struct drm_i915_private *dev_priv, u32 engine_mask);
  2604. extern bool intel_has_gpu_reset(struct drm_i915_private *dev_priv);
  2605. #define I915_RESET_QUIET BIT(0)
  2606. extern void i915_reset(struct drm_i915_private *i915, unsigned int flags);
  2607. extern int i915_reset_engine(struct intel_engine_cs *engine,
  2608. unsigned int flags);
  2609. extern bool intel_has_reset_engine(struct drm_i915_private *dev_priv);
  2610. extern int intel_reset_guc(struct drm_i915_private *dev_priv);
  2611. extern int intel_guc_reset_engine(struct intel_guc *guc,
  2612. struct intel_engine_cs *engine);
  2613. extern void intel_engine_init_hangcheck(struct intel_engine_cs *engine);
  2614. extern void intel_hangcheck_init(struct drm_i915_private *dev_priv);
  2615. extern unsigned long i915_chipset_val(struct drm_i915_private *dev_priv);
  2616. extern unsigned long i915_mch_val(struct drm_i915_private *dev_priv);
  2617. extern unsigned long i915_gfx_val(struct drm_i915_private *dev_priv);
  2618. extern void i915_update_gfx_val(struct drm_i915_private *dev_priv);
  2619. int vlv_force_gfx_clock(struct drm_i915_private *dev_priv, bool on);
  2620. int intel_engines_init_mmio(struct drm_i915_private *dev_priv);
  2621. int intel_engines_init(struct drm_i915_private *dev_priv);
  2622. /* intel_hotplug.c */
  2623. void intel_hpd_irq_handler(struct drm_i915_private *dev_priv,
  2624. u32 pin_mask, u32 long_mask);
  2625. void intel_hpd_init(struct drm_i915_private *dev_priv);
  2626. void intel_hpd_init_work(struct drm_i915_private *dev_priv);
  2627. void intel_hpd_cancel_work(struct drm_i915_private *dev_priv);
  2628. enum port intel_hpd_pin_to_port(enum hpd_pin pin);
  2629. enum hpd_pin intel_hpd_pin(enum port port);
  2630. bool intel_hpd_disable(struct drm_i915_private *dev_priv, enum hpd_pin pin);
  2631. void intel_hpd_enable(struct drm_i915_private *dev_priv, enum hpd_pin pin);
  2632. /* i915_irq.c */
  2633. static inline void i915_queue_hangcheck(struct drm_i915_private *dev_priv)
  2634. {
  2635. unsigned long delay;
  2636. if (unlikely(!i915_modparams.enable_hangcheck))
  2637. return;
  2638. /* Don't continually defer the hangcheck so that it is always run at
  2639. * least once after work has been scheduled on any ring. Otherwise,
  2640. * we will ignore a hung ring if a second ring is kept busy.
  2641. */
  2642. delay = round_jiffies_up_relative(DRM_I915_HANGCHECK_JIFFIES);
  2643. queue_delayed_work(system_long_wq,
  2644. &dev_priv->gpu_error.hangcheck_work, delay);
  2645. }
  2646. __printf(3, 4)
  2647. void i915_handle_error(struct drm_i915_private *dev_priv,
  2648. u32 engine_mask,
  2649. const char *fmt, ...);
  2650. extern void intel_irq_init(struct drm_i915_private *dev_priv);
  2651. extern void intel_irq_fini(struct drm_i915_private *dev_priv);
  2652. int intel_irq_install(struct drm_i915_private *dev_priv);
  2653. void intel_irq_uninstall(struct drm_i915_private *dev_priv);
  2654. static inline bool intel_gvt_active(struct drm_i915_private *dev_priv)
  2655. {
  2656. return dev_priv->gvt;
  2657. }
  2658. static inline bool intel_vgpu_active(struct drm_i915_private *dev_priv)
  2659. {
  2660. return dev_priv->vgpu.active;
  2661. }
  2662. u32 i915_pipestat_enable_mask(struct drm_i915_private *dev_priv,
  2663. enum pipe pipe);
  2664. void
  2665. i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  2666. u32 status_mask);
  2667. void
  2668. i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  2669. u32 status_mask);
  2670. void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv);
  2671. void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv);
  2672. void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
  2673. uint32_t mask,
  2674. uint32_t bits);
  2675. void ilk_update_display_irq(struct drm_i915_private *dev_priv,
  2676. uint32_t interrupt_mask,
  2677. uint32_t enabled_irq_mask);
  2678. static inline void
  2679. ilk_enable_display_irq(struct drm_i915_private *dev_priv, uint32_t bits)
  2680. {
  2681. ilk_update_display_irq(dev_priv, bits, bits);
  2682. }
  2683. static inline void
  2684. ilk_disable_display_irq(struct drm_i915_private *dev_priv, uint32_t bits)
  2685. {
  2686. ilk_update_display_irq(dev_priv, bits, 0);
  2687. }
  2688. void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
  2689. enum pipe pipe,
  2690. uint32_t interrupt_mask,
  2691. uint32_t enabled_irq_mask);
  2692. static inline void bdw_enable_pipe_irq(struct drm_i915_private *dev_priv,
  2693. enum pipe pipe, uint32_t bits)
  2694. {
  2695. bdw_update_pipe_irq(dev_priv, pipe, bits, bits);
  2696. }
  2697. static inline void bdw_disable_pipe_irq(struct drm_i915_private *dev_priv,
  2698. enum pipe pipe, uint32_t bits)
  2699. {
  2700. bdw_update_pipe_irq(dev_priv, pipe, bits, 0);
  2701. }
  2702. void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
  2703. uint32_t interrupt_mask,
  2704. uint32_t enabled_irq_mask);
  2705. static inline void
  2706. ibx_enable_display_interrupt(struct drm_i915_private *dev_priv, uint32_t bits)
  2707. {
  2708. ibx_display_interrupt_update(dev_priv, bits, bits);
  2709. }
  2710. static inline void
  2711. ibx_disable_display_interrupt(struct drm_i915_private *dev_priv, uint32_t bits)
  2712. {
  2713. ibx_display_interrupt_update(dev_priv, bits, 0);
  2714. }
  2715. /* i915_gem.c */
  2716. int i915_gem_create_ioctl(struct drm_device *dev, void *data,
  2717. struct drm_file *file_priv);
  2718. int i915_gem_pread_ioctl(struct drm_device *dev, void *data,
  2719. struct drm_file *file_priv);
  2720. int i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  2721. struct drm_file *file_priv);
  2722. int i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
  2723. struct drm_file *file_priv);
  2724. int i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data,
  2725. struct drm_file *file_priv);
  2726. int i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  2727. struct drm_file *file_priv);
  2728. int i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
  2729. struct drm_file *file_priv);
  2730. int i915_gem_execbuffer(struct drm_device *dev, void *data,
  2731. struct drm_file *file_priv);
  2732. int i915_gem_execbuffer2(struct drm_device *dev, void *data,
  2733. struct drm_file *file_priv);
  2734. int i915_gem_busy_ioctl(struct drm_device *dev, void *data,
  2735. struct drm_file *file_priv);
  2736. int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data,
  2737. struct drm_file *file);
  2738. int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
  2739. struct drm_file *file);
  2740. int i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
  2741. struct drm_file *file_priv);
  2742. int i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
  2743. struct drm_file *file_priv);
  2744. int i915_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
  2745. struct drm_file *file_priv);
  2746. int i915_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
  2747. struct drm_file *file_priv);
  2748. int i915_gem_init_userptr(struct drm_i915_private *dev_priv);
  2749. void i915_gem_cleanup_userptr(struct drm_i915_private *dev_priv);
  2750. int i915_gem_userptr_ioctl(struct drm_device *dev, void *data,
  2751. struct drm_file *file);
  2752. int i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
  2753. struct drm_file *file_priv);
  2754. int i915_gem_wait_ioctl(struct drm_device *dev, void *data,
  2755. struct drm_file *file_priv);
  2756. void i915_gem_sanitize(struct drm_i915_private *i915);
  2757. int i915_gem_load_init(struct drm_i915_private *dev_priv);
  2758. void i915_gem_load_cleanup(struct drm_i915_private *dev_priv);
  2759. void i915_gem_load_init_fences(struct drm_i915_private *dev_priv);
  2760. int i915_gem_freeze(struct drm_i915_private *dev_priv);
  2761. int i915_gem_freeze_late(struct drm_i915_private *dev_priv);
  2762. void *i915_gem_object_alloc(struct drm_i915_private *dev_priv);
  2763. void i915_gem_object_free(struct drm_i915_gem_object *obj);
  2764. void i915_gem_object_init(struct drm_i915_gem_object *obj,
  2765. const struct drm_i915_gem_object_ops *ops);
  2766. struct drm_i915_gem_object *
  2767. i915_gem_object_create(struct drm_i915_private *dev_priv, u64 size);
  2768. struct drm_i915_gem_object *
  2769. i915_gem_object_create_from_data(struct drm_i915_private *dev_priv,
  2770. const void *data, size_t size);
  2771. void i915_gem_close_object(struct drm_gem_object *gem, struct drm_file *file);
  2772. void i915_gem_free_object(struct drm_gem_object *obj);
  2773. static inline void i915_gem_drain_freed_objects(struct drm_i915_private *i915)
  2774. {
  2775. /* A single pass should suffice to release all the freed objects (along
  2776. * most call paths) , but be a little more paranoid in that freeing
  2777. * the objects does take a little amount of time, during which the rcu
  2778. * callbacks could have added new objects into the freed list, and
  2779. * armed the work again.
  2780. */
  2781. do {
  2782. rcu_barrier();
  2783. } while (flush_work(&i915->mm.free_work));
  2784. }
  2785. static inline void i915_gem_drain_workqueue(struct drm_i915_private *i915)
  2786. {
  2787. /*
  2788. * Similar to objects above (see i915_gem_drain_freed-objects), in
  2789. * general we have workers that are armed by RCU and then rearm
  2790. * themselves in their callbacks. To be paranoid, we need to
  2791. * drain the workqueue a second time after waiting for the RCU
  2792. * grace period so that we catch work queued via RCU from the first
  2793. * pass. As neither drain_workqueue() nor flush_workqueue() report
  2794. * a result, we make an assumption that we only don't require more
  2795. * than 2 passes to catch all recursive RCU delayed work.
  2796. *
  2797. */
  2798. int pass = 2;
  2799. do {
  2800. rcu_barrier();
  2801. drain_workqueue(i915->wq);
  2802. } while (--pass);
  2803. }
  2804. struct i915_vma * __must_check
  2805. i915_gem_object_ggtt_pin(struct drm_i915_gem_object *obj,
  2806. const struct i915_ggtt_view *view,
  2807. u64 size,
  2808. u64 alignment,
  2809. u64 flags);
  2810. int i915_gem_object_unbind(struct drm_i915_gem_object *obj);
  2811. void i915_gem_release_mmap(struct drm_i915_gem_object *obj);
  2812. void i915_gem_runtime_suspend(struct drm_i915_private *dev_priv);
  2813. static inline int __sg_page_count(const struct scatterlist *sg)
  2814. {
  2815. return sg->length >> PAGE_SHIFT;
  2816. }
  2817. struct scatterlist *
  2818. i915_gem_object_get_sg(struct drm_i915_gem_object *obj,
  2819. unsigned int n, unsigned int *offset);
  2820. struct page *
  2821. i915_gem_object_get_page(struct drm_i915_gem_object *obj,
  2822. unsigned int n);
  2823. struct page *
  2824. i915_gem_object_get_dirty_page(struct drm_i915_gem_object *obj,
  2825. unsigned int n);
  2826. dma_addr_t
  2827. i915_gem_object_get_dma_address(struct drm_i915_gem_object *obj,
  2828. unsigned long n);
  2829. void __i915_gem_object_set_pages(struct drm_i915_gem_object *obj,
  2830. struct sg_table *pages,
  2831. unsigned int sg_page_sizes);
  2832. int __i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
  2833. static inline int __must_check
  2834. i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
  2835. {
  2836. might_lock(&obj->mm.lock);
  2837. if (atomic_inc_not_zero(&obj->mm.pages_pin_count))
  2838. return 0;
  2839. return __i915_gem_object_get_pages(obj);
  2840. }
  2841. static inline bool
  2842. i915_gem_object_has_pages(struct drm_i915_gem_object *obj)
  2843. {
  2844. return !IS_ERR_OR_NULL(READ_ONCE(obj->mm.pages));
  2845. }
  2846. static inline void
  2847. __i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
  2848. {
  2849. GEM_BUG_ON(!i915_gem_object_has_pages(obj));
  2850. atomic_inc(&obj->mm.pages_pin_count);
  2851. }
  2852. static inline bool
  2853. i915_gem_object_has_pinned_pages(struct drm_i915_gem_object *obj)
  2854. {
  2855. return atomic_read(&obj->mm.pages_pin_count);
  2856. }
  2857. static inline void
  2858. __i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj)
  2859. {
  2860. GEM_BUG_ON(!i915_gem_object_has_pages(obj));
  2861. GEM_BUG_ON(!i915_gem_object_has_pinned_pages(obj));
  2862. atomic_dec(&obj->mm.pages_pin_count);
  2863. }
  2864. static inline void
  2865. i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj)
  2866. {
  2867. __i915_gem_object_unpin_pages(obj);
  2868. }
  2869. enum i915_mm_subclass { /* lockdep subclass for obj->mm.lock */
  2870. I915_MM_NORMAL = 0,
  2871. I915_MM_SHRINKER
  2872. };
  2873. void __i915_gem_object_put_pages(struct drm_i915_gem_object *obj,
  2874. enum i915_mm_subclass subclass);
  2875. void __i915_gem_object_invalidate(struct drm_i915_gem_object *obj);
  2876. enum i915_map_type {
  2877. I915_MAP_WB = 0,
  2878. I915_MAP_WC,
  2879. #define I915_MAP_OVERRIDE BIT(31)
  2880. I915_MAP_FORCE_WB = I915_MAP_WB | I915_MAP_OVERRIDE,
  2881. I915_MAP_FORCE_WC = I915_MAP_WC | I915_MAP_OVERRIDE,
  2882. };
  2883. /**
  2884. * i915_gem_object_pin_map - return a contiguous mapping of the entire object
  2885. * @obj: the object to map into kernel address space
  2886. * @type: the type of mapping, used to select pgprot_t
  2887. *
  2888. * Calls i915_gem_object_pin_pages() to prevent reaping of the object's
  2889. * pages and then returns a contiguous mapping of the backing storage into
  2890. * the kernel address space. Based on the @type of mapping, the PTE will be
  2891. * set to either WriteBack or WriteCombine (via pgprot_t).
  2892. *
  2893. * The caller is responsible for calling i915_gem_object_unpin_map() when the
  2894. * mapping is no longer required.
  2895. *
  2896. * Returns the pointer through which to access the mapped object, or an
  2897. * ERR_PTR() on error.
  2898. */
  2899. void *__must_check i915_gem_object_pin_map(struct drm_i915_gem_object *obj,
  2900. enum i915_map_type type);
  2901. /**
  2902. * i915_gem_object_unpin_map - releases an earlier mapping
  2903. * @obj: the object to unmap
  2904. *
  2905. * After pinning the object and mapping its pages, once you are finished
  2906. * with your access, call i915_gem_object_unpin_map() to release the pin
  2907. * upon the mapping. Once the pin count reaches zero, that mapping may be
  2908. * removed.
  2909. */
  2910. static inline void i915_gem_object_unpin_map(struct drm_i915_gem_object *obj)
  2911. {
  2912. i915_gem_object_unpin_pages(obj);
  2913. }
  2914. int i915_gem_obj_prepare_shmem_read(struct drm_i915_gem_object *obj,
  2915. unsigned int *needs_clflush);
  2916. int i915_gem_obj_prepare_shmem_write(struct drm_i915_gem_object *obj,
  2917. unsigned int *needs_clflush);
  2918. #define CLFLUSH_BEFORE BIT(0)
  2919. #define CLFLUSH_AFTER BIT(1)
  2920. #define CLFLUSH_FLAGS (CLFLUSH_BEFORE | CLFLUSH_AFTER)
  2921. static inline void
  2922. i915_gem_obj_finish_shmem_access(struct drm_i915_gem_object *obj)
  2923. {
  2924. i915_gem_object_unpin_pages(obj);
  2925. }
  2926. int __must_check i915_mutex_lock_interruptible(struct drm_device *dev);
  2927. void i915_vma_move_to_active(struct i915_vma *vma,
  2928. struct drm_i915_gem_request *req,
  2929. unsigned int flags);
  2930. int i915_gem_dumb_create(struct drm_file *file_priv,
  2931. struct drm_device *dev,
  2932. struct drm_mode_create_dumb *args);
  2933. int i915_gem_mmap_gtt(struct drm_file *file_priv, struct drm_device *dev,
  2934. uint32_t handle, uint64_t *offset);
  2935. int i915_gem_mmap_gtt_version(void);
  2936. void i915_gem_track_fb(struct drm_i915_gem_object *old,
  2937. struct drm_i915_gem_object *new,
  2938. unsigned frontbuffer_bits);
  2939. int __must_check i915_gem_set_global_seqno(struct drm_device *dev, u32 seqno);
  2940. struct drm_i915_gem_request *
  2941. i915_gem_find_active_request(struct intel_engine_cs *engine);
  2942. void i915_gem_retire_requests(struct drm_i915_private *dev_priv);
  2943. static inline bool i915_reset_backoff(struct i915_gpu_error *error)
  2944. {
  2945. return unlikely(test_bit(I915_RESET_BACKOFF, &error->flags));
  2946. }
  2947. static inline bool i915_reset_handoff(struct i915_gpu_error *error)
  2948. {
  2949. return unlikely(test_bit(I915_RESET_HANDOFF, &error->flags));
  2950. }
  2951. static inline bool i915_terminally_wedged(struct i915_gpu_error *error)
  2952. {
  2953. return unlikely(test_bit(I915_WEDGED, &error->flags));
  2954. }
  2955. static inline bool i915_reset_backoff_or_wedged(struct i915_gpu_error *error)
  2956. {
  2957. return i915_reset_backoff(error) | i915_terminally_wedged(error);
  2958. }
  2959. static inline u32 i915_reset_count(struct i915_gpu_error *error)
  2960. {
  2961. return READ_ONCE(error->reset_count);
  2962. }
  2963. static inline u32 i915_reset_engine_count(struct i915_gpu_error *error,
  2964. struct intel_engine_cs *engine)
  2965. {
  2966. return READ_ONCE(error->reset_engine_count[engine->id]);
  2967. }
  2968. struct drm_i915_gem_request *
  2969. i915_gem_reset_prepare_engine(struct intel_engine_cs *engine);
  2970. int i915_gem_reset_prepare(struct drm_i915_private *dev_priv);
  2971. void i915_gem_reset(struct drm_i915_private *dev_priv);
  2972. void i915_gem_reset_finish_engine(struct intel_engine_cs *engine);
  2973. void i915_gem_reset_finish(struct drm_i915_private *dev_priv);
  2974. void i915_gem_set_wedged(struct drm_i915_private *dev_priv);
  2975. bool i915_gem_unset_wedged(struct drm_i915_private *dev_priv);
  2976. void i915_gem_reset_engine(struct intel_engine_cs *engine,
  2977. struct drm_i915_gem_request *request);
  2978. void i915_gem_init_mmio(struct drm_i915_private *i915);
  2979. int __must_check i915_gem_init(struct drm_i915_private *dev_priv);
  2980. int __must_check i915_gem_init_hw(struct drm_i915_private *dev_priv);
  2981. void i915_gem_init_swizzling(struct drm_i915_private *dev_priv);
  2982. void i915_gem_cleanup_engines(struct drm_i915_private *dev_priv);
  2983. int i915_gem_wait_for_idle(struct drm_i915_private *dev_priv,
  2984. unsigned int flags);
  2985. int __must_check i915_gem_suspend(struct drm_i915_private *dev_priv);
  2986. void i915_gem_resume(struct drm_i915_private *dev_priv);
  2987. int i915_gem_fault(struct vm_fault *vmf);
  2988. int i915_gem_object_wait(struct drm_i915_gem_object *obj,
  2989. unsigned int flags,
  2990. long timeout,
  2991. struct intel_rps_client *rps);
  2992. int i915_gem_object_wait_priority(struct drm_i915_gem_object *obj,
  2993. unsigned int flags,
  2994. int priority);
  2995. #define I915_PRIORITY_DISPLAY I915_PRIORITY_MAX
  2996. int __must_check
  2997. i915_gem_object_set_to_wc_domain(struct drm_i915_gem_object *obj, bool write);
  2998. int __must_check
  2999. i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write);
  3000. int __must_check
  3001. i915_gem_object_set_to_cpu_domain(struct drm_i915_gem_object *obj, bool write);
  3002. struct i915_vma * __must_check
  3003. i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
  3004. u32 alignment,
  3005. const struct i915_ggtt_view *view);
  3006. void i915_gem_object_unpin_from_display_plane(struct i915_vma *vma);
  3007. int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj,
  3008. int align);
  3009. int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file);
  3010. void i915_gem_release(struct drm_device *dev, struct drm_file *file);
  3011. int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
  3012. enum i915_cache_level cache_level);
  3013. struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
  3014. struct dma_buf *dma_buf);
  3015. struct dma_buf *i915_gem_prime_export(struct drm_device *dev,
  3016. struct drm_gem_object *gem_obj, int flags);
  3017. static inline struct i915_hw_ppgtt *
  3018. i915_vm_to_ppgtt(struct i915_address_space *vm)
  3019. {
  3020. return container_of(vm, struct i915_hw_ppgtt, base);
  3021. }
  3022. /* i915_gem_fence_reg.c */
  3023. struct drm_i915_fence_reg *
  3024. i915_reserve_fence(struct drm_i915_private *dev_priv);
  3025. void i915_unreserve_fence(struct drm_i915_fence_reg *fence);
  3026. void i915_gem_revoke_fences(struct drm_i915_private *dev_priv);
  3027. void i915_gem_restore_fences(struct drm_i915_private *dev_priv);
  3028. void i915_gem_detect_bit_6_swizzle(struct drm_i915_private *dev_priv);
  3029. void i915_gem_object_do_bit_17_swizzle(struct drm_i915_gem_object *obj,
  3030. struct sg_table *pages);
  3031. void i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj,
  3032. struct sg_table *pages);
  3033. static inline struct i915_gem_context *
  3034. __i915_gem_context_lookup_rcu(struct drm_i915_file_private *file_priv, u32 id)
  3035. {
  3036. return idr_find(&file_priv->context_idr, id);
  3037. }
  3038. static inline struct i915_gem_context *
  3039. i915_gem_context_lookup(struct drm_i915_file_private *file_priv, u32 id)
  3040. {
  3041. struct i915_gem_context *ctx;
  3042. rcu_read_lock();
  3043. ctx = __i915_gem_context_lookup_rcu(file_priv, id);
  3044. if (ctx && !kref_get_unless_zero(&ctx->ref))
  3045. ctx = NULL;
  3046. rcu_read_unlock();
  3047. return ctx;
  3048. }
  3049. static inline struct intel_timeline *
  3050. i915_gem_context_lookup_timeline(struct i915_gem_context *ctx,
  3051. struct intel_engine_cs *engine)
  3052. {
  3053. struct i915_address_space *vm;
  3054. vm = ctx->ppgtt ? &ctx->ppgtt->base : &ctx->i915->ggtt.base;
  3055. return &vm->timeline.engine[engine->id];
  3056. }
  3057. int i915_perf_open_ioctl(struct drm_device *dev, void *data,
  3058. struct drm_file *file);
  3059. int i915_perf_add_config_ioctl(struct drm_device *dev, void *data,
  3060. struct drm_file *file);
  3061. int i915_perf_remove_config_ioctl(struct drm_device *dev, void *data,
  3062. struct drm_file *file);
  3063. void i915_oa_init_reg_state(struct intel_engine_cs *engine,
  3064. struct i915_gem_context *ctx,
  3065. uint32_t *reg_state);
  3066. /* i915_gem_evict.c */
  3067. int __must_check i915_gem_evict_something(struct i915_address_space *vm,
  3068. u64 min_size, u64 alignment,
  3069. unsigned cache_level,
  3070. u64 start, u64 end,
  3071. unsigned flags);
  3072. int __must_check i915_gem_evict_for_node(struct i915_address_space *vm,
  3073. struct drm_mm_node *node,
  3074. unsigned int flags);
  3075. int i915_gem_evict_vm(struct i915_address_space *vm);
  3076. void i915_gem_flush_ggtt_writes(struct drm_i915_private *dev_priv);
  3077. /* belongs in i915_gem_gtt.h */
  3078. static inline void i915_gem_chipset_flush(struct drm_i915_private *dev_priv)
  3079. {
  3080. wmb();
  3081. if (INTEL_GEN(dev_priv) < 6)
  3082. intel_gtt_chipset_flush();
  3083. }
  3084. /* i915_gem_stolen.c */
  3085. int i915_gem_stolen_insert_node(struct drm_i915_private *dev_priv,
  3086. struct drm_mm_node *node, u64 size,
  3087. unsigned alignment);
  3088. int i915_gem_stolen_insert_node_in_range(struct drm_i915_private *dev_priv,
  3089. struct drm_mm_node *node, u64 size,
  3090. unsigned alignment, u64 start,
  3091. u64 end);
  3092. void i915_gem_stolen_remove_node(struct drm_i915_private *dev_priv,
  3093. struct drm_mm_node *node);
  3094. int i915_gem_init_stolen(struct drm_i915_private *dev_priv);
  3095. void i915_gem_cleanup_stolen(struct drm_device *dev);
  3096. struct drm_i915_gem_object *
  3097. i915_gem_object_create_stolen(struct drm_i915_private *dev_priv,
  3098. resource_size_t size);
  3099. struct drm_i915_gem_object *
  3100. i915_gem_object_create_stolen_for_preallocated(struct drm_i915_private *dev_priv,
  3101. resource_size_t stolen_offset,
  3102. resource_size_t gtt_offset,
  3103. resource_size_t size);
  3104. /* i915_gem_internal.c */
  3105. struct drm_i915_gem_object *
  3106. i915_gem_object_create_internal(struct drm_i915_private *dev_priv,
  3107. phys_addr_t size);
  3108. /* i915_gem_shrinker.c */
  3109. unsigned long i915_gem_shrink(struct drm_i915_private *i915,
  3110. unsigned long target,
  3111. unsigned long *nr_scanned,
  3112. unsigned flags);
  3113. #define I915_SHRINK_PURGEABLE 0x1
  3114. #define I915_SHRINK_UNBOUND 0x2
  3115. #define I915_SHRINK_BOUND 0x4
  3116. #define I915_SHRINK_ACTIVE 0x8
  3117. #define I915_SHRINK_VMAPS 0x10
  3118. unsigned long i915_gem_shrink_all(struct drm_i915_private *i915);
  3119. void i915_gem_shrinker_register(struct drm_i915_private *i915);
  3120. void i915_gem_shrinker_unregister(struct drm_i915_private *i915);
  3121. /* i915_gem_tiling.c */
  3122. static inline bool i915_gem_object_needs_bit17_swizzle(struct drm_i915_gem_object *obj)
  3123. {
  3124. struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
  3125. return dev_priv->mm.bit_6_swizzle_x == I915_BIT_6_SWIZZLE_9_10_17 &&
  3126. i915_gem_object_is_tiled(obj);
  3127. }
  3128. u32 i915_gem_fence_size(struct drm_i915_private *dev_priv, u32 size,
  3129. unsigned int tiling, unsigned int stride);
  3130. u32 i915_gem_fence_alignment(struct drm_i915_private *dev_priv, u32 size,
  3131. unsigned int tiling, unsigned int stride);
  3132. /* i915_debugfs.c */
  3133. #ifdef CONFIG_DEBUG_FS
  3134. int i915_debugfs_register(struct drm_i915_private *dev_priv);
  3135. int i915_debugfs_connector_add(struct drm_connector *connector);
  3136. void intel_display_crc_init(struct drm_i915_private *dev_priv);
  3137. #else
  3138. static inline int i915_debugfs_register(struct drm_i915_private *dev_priv) {return 0;}
  3139. static inline int i915_debugfs_connector_add(struct drm_connector *connector)
  3140. { return 0; }
  3141. static inline void intel_display_crc_init(struct drm_i915_private *dev_priv) {}
  3142. #endif
  3143. /* i915_gpu_error.c */
  3144. #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
  3145. __printf(2, 3)
  3146. void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...);
  3147. int i915_error_state_to_str(struct drm_i915_error_state_buf *estr,
  3148. const struct i915_gpu_state *gpu);
  3149. int i915_error_state_buf_init(struct drm_i915_error_state_buf *eb,
  3150. struct drm_i915_private *i915,
  3151. size_t count, loff_t pos);
  3152. static inline void i915_error_state_buf_release(
  3153. struct drm_i915_error_state_buf *eb)
  3154. {
  3155. kfree(eb->buf);
  3156. }
  3157. struct i915_gpu_state *i915_capture_gpu_state(struct drm_i915_private *i915);
  3158. void i915_capture_error_state(struct drm_i915_private *dev_priv,
  3159. u32 engine_mask,
  3160. const char *error_msg);
  3161. static inline struct i915_gpu_state *
  3162. i915_gpu_state_get(struct i915_gpu_state *gpu)
  3163. {
  3164. kref_get(&gpu->ref);
  3165. return gpu;
  3166. }
  3167. void __i915_gpu_state_free(struct kref *kref);
  3168. static inline void i915_gpu_state_put(struct i915_gpu_state *gpu)
  3169. {
  3170. if (gpu)
  3171. kref_put(&gpu->ref, __i915_gpu_state_free);
  3172. }
  3173. struct i915_gpu_state *i915_first_error_state(struct drm_i915_private *i915);
  3174. void i915_reset_error_state(struct drm_i915_private *i915);
  3175. #else
  3176. static inline void i915_capture_error_state(struct drm_i915_private *dev_priv,
  3177. u32 engine_mask,
  3178. const char *error_msg)
  3179. {
  3180. }
  3181. static inline struct i915_gpu_state *
  3182. i915_first_error_state(struct drm_i915_private *i915)
  3183. {
  3184. return NULL;
  3185. }
  3186. static inline void i915_reset_error_state(struct drm_i915_private *i915)
  3187. {
  3188. }
  3189. #endif
  3190. const char *i915_cache_level_str(struct drm_i915_private *i915, int type);
  3191. /* i915_cmd_parser.c */
  3192. int i915_cmd_parser_get_version(struct drm_i915_private *dev_priv);
  3193. void intel_engine_init_cmd_parser(struct intel_engine_cs *engine);
  3194. void intel_engine_cleanup_cmd_parser(struct intel_engine_cs *engine);
  3195. int intel_engine_cmd_parser(struct intel_engine_cs *engine,
  3196. struct drm_i915_gem_object *batch_obj,
  3197. struct drm_i915_gem_object *shadow_batch_obj,
  3198. u32 batch_start_offset,
  3199. u32 batch_len,
  3200. bool is_master);
  3201. /* i915_perf.c */
  3202. extern void i915_perf_init(struct drm_i915_private *dev_priv);
  3203. extern void i915_perf_fini(struct drm_i915_private *dev_priv);
  3204. extern void i915_perf_register(struct drm_i915_private *dev_priv);
  3205. extern void i915_perf_unregister(struct drm_i915_private *dev_priv);
  3206. /* i915_suspend.c */
  3207. extern int i915_save_state(struct drm_i915_private *dev_priv);
  3208. extern int i915_restore_state(struct drm_i915_private *dev_priv);
  3209. /* i915_sysfs.c */
  3210. void i915_setup_sysfs(struct drm_i915_private *dev_priv);
  3211. void i915_teardown_sysfs(struct drm_i915_private *dev_priv);
  3212. /* intel_lpe_audio.c */
  3213. int intel_lpe_audio_init(struct drm_i915_private *dev_priv);
  3214. void intel_lpe_audio_teardown(struct drm_i915_private *dev_priv);
  3215. void intel_lpe_audio_irq_handler(struct drm_i915_private *dev_priv);
  3216. void intel_lpe_audio_notify(struct drm_i915_private *dev_priv,
  3217. enum pipe pipe, enum port port,
  3218. const void *eld, int ls_clock, bool dp_output);
  3219. /* intel_i2c.c */
  3220. extern int intel_setup_gmbus(struct drm_i915_private *dev_priv);
  3221. extern void intel_teardown_gmbus(struct drm_i915_private *dev_priv);
  3222. extern bool intel_gmbus_is_valid_pin(struct drm_i915_private *dev_priv,
  3223. unsigned int pin);
  3224. extern struct i2c_adapter *
  3225. intel_gmbus_get_adapter(struct drm_i915_private *dev_priv, unsigned int pin);
  3226. extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
  3227. extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
  3228. static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
  3229. {
  3230. return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
  3231. }
  3232. extern void intel_i2c_reset(struct drm_i915_private *dev_priv);
  3233. /* intel_bios.c */
  3234. void intel_bios_init(struct drm_i915_private *dev_priv);
  3235. bool intel_bios_is_valid_vbt(const void *buf, size_t size);
  3236. bool intel_bios_is_tv_present(struct drm_i915_private *dev_priv);
  3237. bool intel_bios_is_lvds_present(struct drm_i915_private *dev_priv, u8 *i2c_pin);
  3238. bool intel_bios_is_port_present(struct drm_i915_private *dev_priv, enum port port);
  3239. bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port);
  3240. bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port);
  3241. bool intel_bios_is_dsi_present(struct drm_i915_private *dev_priv, enum port *port);
  3242. bool intel_bios_is_port_hpd_inverted(struct drm_i915_private *dev_priv,
  3243. enum port port);
  3244. bool intel_bios_is_lspcon_present(struct drm_i915_private *dev_priv,
  3245. enum port port);
  3246. /* intel_opregion.c */
  3247. #ifdef CONFIG_ACPI
  3248. extern int intel_opregion_setup(struct drm_i915_private *dev_priv);
  3249. extern void intel_opregion_register(struct drm_i915_private *dev_priv);
  3250. extern void intel_opregion_unregister(struct drm_i915_private *dev_priv);
  3251. extern void intel_opregion_asle_intr(struct drm_i915_private *dev_priv);
  3252. extern int intel_opregion_notify_encoder(struct intel_encoder *intel_encoder,
  3253. bool enable);
  3254. extern int intel_opregion_notify_adapter(struct drm_i915_private *dev_priv,
  3255. pci_power_t state);
  3256. extern int intel_opregion_get_panel_type(struct drm_i915_private *dev_priv);
  3257. #else
  3258. static inline int intel_opregion_setup(struct drm_i915_private *dev) { return 0; }
  3259. static inline void intel_opregion_register(struct drm_i915_private *dev_priv) { }
  3260. static inline void intel_opregion_unregister(struct drm_i915_private *dev_priv) { }
  3261. static inline void intel_opregion_asle_intr(struct drm_i915_private *dev_priv)
  3262. {
  3263. }
  3264. static inline int
  3265. intel_opregion_notify_encoder(struct intel_encoder *intel_encoder, bool enable)
  3266. {
  3267. return 0;
  3268. }
  3269. static inline int
  3270. intel_opregion_notify_adapter(struct drm_i915_private *dev, pci_power_t state)
  3271. {
  3272. return 0;
  3273. }
  3274. static inline int intel_opregion_get_panel_type(struct drm_i915_private *dev)
  3275. {
  3276. return -ENODEV;
  3277. }
  3278. #endif
  3279. /* intel_acpi.c */
  3280. #ifdef CONFIG_ACPI
  3281. extern void intel_register_dsm_handler(void);
  3282. extern void intel_unregister_dsm_handler(void);
  3283. #else
  3284. static inline void intel_register_dsm_handler(void) { return; }
  3285. static inline void intel_unregister_dsm_handler(void) { return; }
  3286. #endif /* CONFIG_ACPI */
  3287. /* intel_device_info.c */
  3288. static inline struct intel_device_info *
  3289. mkwrite_device_info(struct drm_i915_private *dev_priv)
  3290. {
  3291. return (struct intel_device_info *)&dev_priv->info;
  3292. }
  3293. const char *intel_platform_name(enum intel_platform platform);
  3294. void intel_device_info_runtime_init(struct drm_i915_private *dev_priv);
  3295. void intel_device_info_dump(const struct intel_device_info *info,
  3296. struct drm_printer *p);
  3297. void intel_device_info_dump_flags(const struct intel_device_info *info,
  3298. struct drm_printer *p);
  3299. /* modesetting */
  3300. extern void intel_modeset_init_hw(struct drm_device *dev);
  3301. extern int intel_modeset_init(struct drm_device *dev);
  3302. extern void intel_modeset_cleanup(struct drm_device *dev);
  3303. extern int intel_connector_register(struct drm_connector *);
  3304. extern void intel_connector_unregister(struct drm_connector *);
  3305. extern int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv,
  3306. bool state);
  3307. extern void intel_display_resume(struct drm_device *dev);
  3308. extern void i915_redisable_vga(struct drm_i915_private *dev_priv);
  3309. extern void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv);
  3310. extern bool ironlake_set_drps(struct drm_i915_private *dev_priv, u8 val);
  3311. extern void intel_init_pch_refclk(struct drm_i915_private *dev_priv);
  3312. extern int intel_set_rps(struct drm_i915_private *dev_priv, u8 val);
  3313. extern bool intel_set_memory_cxsr(struct drm_i915_private *dev_priv,
  3314. bool enable);
  3315. int i915_reg_read_ioctl(struct drm_device *dev, void *data,
  3316. struct drm_file *file);
  3317. /* overlay */
  3318. extern struct intel_overlay_error_state *
  3319. intel_overlay_capture_error_state(struct drm_i915_private *dev_priv);
  3320. extern void intel_overlay_print_error_state(struct drm_i915_error_state_buf *e,
  3321. struct intel_overlay_error_state *error);
  3322. extern struct intel_display_error_state *
  3323. intel_display_capture_error_state(struct drm_i915_private *dev_priv);
  3324. extern void intel_display_print_error_state(struct drm_i915_error_state_buf *e,
  3325. struct intel_display_error_state *error);
  3326. int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u32 mbox, u32 *val);
  3327. int sandybridge_pcode_write(struct drm_i915_private *dev_priv, u32 mbox, u32 val);
  3328. int skl_pcode_request(struct drm_i915_private *dev_priv, u32 mbox, u32 request,
  3329. u32 reply_mask, u32 reply, int timeout_base_ms);
  3330. /* intel_sideband.c */
  3331. u32 vlv_punit_read(struct drm_i915_private *dev_priv, u32 addr);
  3332. int vlv_punit_write(struct drm_i915_private *dev_priv, u32 addr, u32 val);
  3333. u32 vlv_nc_read(struct drm_i915_private *dev_priv, u8 addr);
  3334. u32 vlv_iosf_sb_read(struct drm_i915_private *dev_priv, u8 port, u32 reg);
  3335. void vlv_iosf_sb_write(struct drm_i915_private *dev_priv, u8 port, u32 reg, u32 val);
  3336. u32 vlv_cck_read(struct drm_i915_private *dev_priv, u32 reg);
  3337. void vlv_cck_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  3338. u32 vlv_ccu_read(struct drm_i915_private *dev_priv, u32 reg);
  3339. void vlv_ccu_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  3340. u32 vlv_bunit_read(struct drm_i915_private *dev_priv, u32 reg);
  3341. void vlv_bunit_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  3342. u32 vlv_dpio_read(struct drm_i915_private *dev_priv, enum pipe pipe, int reg);
  3343. void vlv_dpio_write(struct drm_i915_private *dev_priv, enum pipe pipe, int reg, u32 val);
  3344. u32 intel_sbi_read(struct drm_i915_private *dev_priv, u16 reg,
  3345. enum intel_sbi_destination destination);
  3346. void intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
  3347. enum intel_sbi_destination destination);
  3348. u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
  3349. void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  3350. /* intel_dpio_phy.c */
  3351. void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum port port,
  3352. enum dpio_phy *phy, enum dpio_channel *ch);
  3353. void bxt_ddi_phy_set_signal_level(struct drm_i915_private *dev_priv,
  3354. enum port port, u32 margin, u32 scale,
  3355. u32 enable, u32 deemphasis);
  3356. void bxt_ddi_phy_init(struct drm_i915_private *dev_priv, enum dpio_phy phy);
  3357. void bxt_ddi_phy_uninit(struct drm_i915_private *dev_priv, enum dpio_phy phy);
  3358. bool bxt_ddi_phy_is_enabled(struct drm_i915_private *dev_priv,
  3359. enum dpio_phy phy);
  3360. bool bxt_ddi_phy_verify_state(struct drm_i915_private *dev_priv,
  3361. enum dpio_phy phy);
  3362. uint8_t bxt_ddi_phy_calc_lane_lat_optim_mask(uint8_t lane_count);
  3363. void bxt_ddi_phy_set_lane_optim_mask(struct intel_encoder *encoder,
  3364. uint8_t lane_lat_optim_mask);
  3365. uint8_t bxt_ddi_phy_get_lane_lat_optim_mask(struct intel_encoder *encoder);
  3366. void chv_set_phy_signal_level(struct intel_encoder *encoder,
  3367. u32 deemph_reg_value, u32 margin_reg_value,
  3368. bool uniq_trans_scale);
  3369. void chv_data_lane_soft_reset(struct intel_encoder *encoder,
  3370. const struct intel_crtc_state *crtc_state,
  3371. bool reset);
  3372. void chv_phy_pre_pll_enable(struct intel_encoder *encoder,
  3373. const struct intel_crtc_state *crtc_state);
  3374. void chv_phy_pre_encoder_enable(struct intel_encoder *encoder,
  3375. const struct intel_crtc_state *crtc_state);
  3376. void chv_phy_release_cl2_override(struct intel_encoder *encoder);
  3377. void chv_phy_post_pll_disable(struct intel_encoder *encoder,
  3378. const struct intel_crtc_state *old_crtc_state);
  3379. void vlv_set_phy_signal_level(struct intel_encoder *encoder,
  3380. u32 demph_reg_value, u32 preemph_reg_value,
  3381. u32 uniqtranscale_reg_value, u32 tx3_demph);
  3382. void vlv_phy_pre_pll_enable(struct intel_encoder *encoder,
  3383. const struct intel_crtc_state *crtc_state);
  3384. void vlv_phy_pre_encoder_enable(struct intel_encoder *encoder,
  3385. const struct intel_crtc_state *crtc_state);
  3386. void vlv_phy_reset_lanes(struct intel_encoder *encoder,
  3387. const struct intel_crtc_state *old_crtc_state);
  3388. int intel_gpu_freq(struct drm_i915_private *dev_priv, int val);
  3389. int intel_freq_opcode(struct drm_i915_private *dev_priv, int val);
  3390. u64 intel_rc6_residency_ns(struct drm_i915_private *dev_priv,
  3391. const i915_reg_t reg);
  3392. u32 intel_get_cagf(struct drm_i915_private *dev_priv, u32 rpstat1);
  3393. static inline u64 intel_rc6_residency_us(struct drm_i915_private *dev_priv,
  3394. const i915_reg_t reg)
  3395. {
  3396. return DIV_ROUND_UP_ULL(intel_rc6_residency_ns(dev_priv, reg), 1000);
  3397. }
  3398. #define I915_READ8(reg) dev_priv->uncore.funcs.mmio_readb(dev_priv, (reg), true)
  3399. #define I915_WRITE8(reg, val) dev_priv->uncore.funcs.mmio_writeb(dev_priv, (reg), (val), true)
  3400. #define I915_READ16(reg) dev_priv->uncore.funcs.mmio_readw(dev_priv, (reg), true)
  3401. #define I915_WRITE16(reg, val) dev_priv->uncore.funcs.mmio_writew(dev_priv, (reg), (val), true)
  3402. #define I915_READ16_NOTRACE(reg) dev_priv->uncore.funcs.mmio_readw(dev_priv, (reg), false)
  3403. #define I915_WRITE16_NOTRACE(reg, val) dev_priv->uncore.funcs.mmio_writew(dev_priv, (reg), (val), false)
  3404. #define I915_READ(reg) dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), true)
  3405. #define I915_WRITE(reg, val) dev_priv->uncore.funcs.mmio_writel(dev_priv, (reg), (val), true)
  3406. #define I915_READ_NOTRACE(reg) dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), false)
  3407. #define I915_WRITE_NOTRACE(reg, val) dev_priv->uncore.funcs.mmio_writel(dev_priv, (reg), (val), false)
  3408. /* Be very careful with read/write 64-bit values. On 32-bit machines, they
  3409. * will be implemented using 2 32-bit writes in an arbitrary order with
  3410. * an arbitrary delay between them. This can cause the hardware to
  3411. * act upon the intermediate value, possibly leading to corruption and
  3412. * machine death. For this reason we do not support I915_WRITE64, or
  3413. * dev_priv->uncore.funcs.mmio_writeq.
  3414. *
  3415. * When reading a 64-bit value as two 32-bit values, the delay may cause
  3416. * the two reads to mismatch, e.g. a timestamp overflowing. Also note that
  3417. * occasionally a 64-bit register does not actualy support a full readq
  3418. * and must be read using two 32-bit reads.
  3419. *
  3420. * You have been warned.
  3421. */
  3422. #define I915_READ64(reg) dev_priv->uncore.funcs.mmio_readq(dev_priv, (reg), true)
  3423. #define I915_READ64_2x32(lower_reg, upper_reg) ({ \
  3424. u32 upper, lower, old_upper, loop = 0; \
  3425. upper = I915_READ(upper_reg); \
  3426. do { \
  3427. old_upper = upper; \
  3428. lower = I915_READ(lower_reg); \
  3429. upper = I915_READ(upper_reg); \
  3430. } while (upper != old_upper && loop++ < 2); \
  3431. (u64)upper << 32 | lower; })
  3432. #define POSTING_READ(reg) (void)I915_READ_NOTRACE(reg)
  3433. #define POSTING_READ16(reg) (void)I915_READ16_NOTRACE(reg)
  3434. #define __raw_read(x, s) \
  3435. static inline uint##x##_t __raw_i915_read##x(const struct drm_i915_private *dev_priv, \
  3436. i915_reg_t reg) \
  3437. { \
  3438. return read##s(dev_priv->regs + i915_mmio_reg_offset(reg)); \
  3439. }
  3440. #define __raw_write(x, s) \
  3441. static inline void __raw_i915_write##x(const struct drm_i915_private *dev_priv, \
  3442. i915_reg_t reg, uint##x##_t val) \
  3443. { \
  3444. write##s(val, dev_priv->regs + i915_mmio_reg_offset(reg)); \
  3445. }
  3446. __raw_read(8, b)
  3447. __raw_read(16, w)
  3448. __raw_read(32, l)
  3449. __raw_read(64, q)
  3450. __raw_write(8, b)
  3451. __raw_write(16, w)
  3452. __raw_write(32, l)
  3453. __raw_write(64, q)
  3454. #undef __raw_read
  3455. #undef __raw_write
  3456. /* These are untraced mmio-accessors that are only valid to be used inside
  3457. * critical sections, such as inside IRQ handlers, where forcewake is explicitly
  3458. * controlled.
  3459. *
  3460. * Think twice, and think again, before using these.
  3461. *
  3462. * As an example, these accessors can possibly be used between:
  3463. *
  3464. * spin_lock_irq(&dev_priv->uncore.lock);
  3465. * intel_uncore_forcewake_get__locked();
  3466. *
  3467. * and
  3468. *
  3469. * intel_uncore_forcewake_put__locked();
  3470. * spin_unlock_irq(&dev_priv->uncore.lock);
  3471. *
  3472. *
  3473. * Note: some registers may not need forcewake held, so
  3474. * intel_uncore_forcewake_{get,put} can be omitted, see
  3475. * intel_uncore_forcewake_for_reg().
  3476. *
  3477. * Certain architectures will die if the same cacheline is concurrently accessed
  3478. * by different clients (e.g. on Ivybridge). Access to registers should
  3479. * therefore generally be serialised, by either the dev_priv->uncore.lock or
  3480. * a more localised lock guarding all access to that bank of registers.
  3481. */
  3482. #define I915_READ_FW(reg__) __raw_i915_read32(dev_priv, (reg__))
  3483. #define I915_WRITE_FW(reg__, val__) __raw_i915_write32(dev_priv, (reg__), (val__))
  3484. #define I915_WRITE64_FW(reg__, val__) __raw_i915_write64(dev_priv, (reg__), (val__))
  3485. #define POSTING_READ_FW(reg__) (void)I915_READ_FW(reg__)
  3486. /* "Broadcast RGB" property */
  3487. #define INTEL_BROADCAST_RGB_AUTO 0
  3488. #define INTEL_BROADCAST_RGB_FULL 1
  3489. #define INTEL_BROADCAST_RGB_LIMITED 2
  3490. static inline i915_reg_t i915_vgacntrl_reg(struct drm_i915_private *dev_priv)
  3491. {
  3492. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  3493. return VLV_VGACNTRL;
  3494. else if (INTEL_GEN(dev_priv) >= 5)
  3495. return CPU_VGACNTRL;
  3496. else
  3497. return VGACNTRL;
  3498. }
  3499. static inline unsigned long msecs_to_jiffies_timeout(const unsigned int m)
  3500. {
  3501. unsigned long j = msecs_to_jiffies(m);
  3502. return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
  3503. }
  3504. static inline unsigned long nsecs_to_jiffies_timeout(const u64 n)
  3505. {
  3506. /* nsecs_to_jiffies64() does not guard against overflow */
  3507. if (NSEC_PER_SEC % HZ &&
  3508. div_u64(n, NSEC_PER_SEC) >= MAX_JIFFY_OFFSET / HZ)
  3509. return MAX_JIFFY_OFFSET;
  3510. return min_t(u64, MAX_JIFFY_OFFSET, nsecs_to_jiffies64(n) + 1);
  3511. }
  3512. static inline unsigned long
  3513. timespec_to_jiffies_timeout(const struct timespec *value)
  3514. {
  3515. unsigned long j = timespec_to_jiffies(value);
  3516. return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
  3517. }
  3518. /*
  3519. * If you need to wait X milliseconds between events A and B, but event B
  3520. * doesn't happen exactly after event A, you record the timestamp (jiffies) of
  3521. * when event A happened, then just before event B you call this function and
  3522. * pass the timestamp as the first argument, and X as the second argument.
  3523. */
  3524. static inline void
  3525. wait_remaining_ms_from_jiffies(unsigned long timestamp_jiffies, int to_wait_ms)
  3526. {
  3527. unsigned long target_jiffies, tmp_jiffies, remaining_jiffies;
  3528. /*
  3529. * Don't re-read the value of "jiffies" every time since it may change
  3530. * behind our back and break the math.
  3531. */
  3532. tmp_jiffies = jiffies;
  3533. target_jiffies = timestamp_jiffies +
  3534. msecs_to_jiffies_timeout(to_wait_ms);
  3535. if (time_after(target_jiffies, tmp_jiffies)) {
  3536. remaining_jiffies = target_jiffies - tmp_jiffies;
  3537. while (remaining_jiffies)
  3538. remaining_jiffies =
  3539. schedule_timeout_uninterruptible(remaining_jiffies);
  3540. }
  3541. }
  3542. static inline bool
  3543. __i915_request_irq_complete(const struct drm_i915_gem_request *req)
  3544. {
  3545. struct intel_engine_cs *engine = req->engine;
  3546. u32 seqno;
  3547. /* Note that the engine may have wrapped around the seqno, and
  3548. * so our request->global_seqno will be ahead of the hardware,
  3549. * even though it completed the request before wrapping. We catch
  3550. * this by kicking all the waiters before resetting the seqno
  3551. * in hardware, and also signal the fence.
  3552. */
  3553. if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &req->fence.flags))
  3554. return true;
  3555. /* The request was dequeued before we were awoken. We check after
  3556. * inspecting the hw to confirm that this was the same request
  3557. * that generated the HWS update. The memory barriers within
  3558. * the request execution are sufficient to ensure that a check
  3559. * after reading the value from hw matches this request.
  3560. */
  3561. seqno = i915_gem_request_global_seqno(req);
  3562. if (!seqno)
  3563. return false;
  3564. /* Before we do the heavier coherent read of the seqno,
  3565. * check the value (hopefully) in the CPU cacheline.
  3566. */
  3567. if (__i915_gem_request_completed(req, seqno))
  3568. return true;
  3569. /* Ensure our read of the seqno is coherent so that we
  3570. * do not "miss an interrupt" (i.e. if this is the last
  3571. * request and the seqno write from the GPU is not visible
  3572. * by the time the interrupt fires, we will see that the
  3573. * request is incomplete and go back to sleep awaiting
  3574. * another interrupt that will never come.)
  3575. *
  3576. * Strictly, we only need to do this once after an interrupt,
  3577. * but it is easier and safer to do it every time the waiter
  3578. * is woken.
  3579. */
  3580. if (engine->irq_seqno_barrier &&
  3581. test_and_clear_bit(ENGINE_IRQ_BREADCRUMB, &engine->irq_posted)) {
  3582. struct intel_breadcrumbs *b = &engine->breadcrumbs;
  3583. /* The ordering of irq_posted versus applying the barrier
  3584. * is crucial. The clearing of the current irq_posted must
  3585. * be visible before we perform the barrier operation,
  3586. * such that if a subsequent interrupt arrives, irq_posted
  3587. * is reasserted and our task rewoken (which causes us to
  3588. * do another __i915_request_irq_complete() immediately
  3589. * and reapply the barrier). Conversely, if the clear
  3590. * occurs after the barrier, then an interrupt that arrived
  3591. * whilst we waited on the barrier would not trigger a
  3592. * barrier on the next pass, and the read may not see the
  3593. * seqno update.
  3594. */
  3595. engine->irq_seqno_barrier(engine);
  3596. /* If we consume the irq, but we are no longer the bottom-half,
  3597. * the real bottom-half may not have serialised their own
  3598. * seqno check with the irq-barrier (i.e. may have inspected
  3599. * the seqno before we believe it coherent since they see
  3600. * irq_posted == false but we are still running).
  3601. */
  3602. spin_lock_irq(&b->irq_lock);
  3603. if (b->irq_wait && b->irq_wait->tsk != current)
  3604. /* Note that if the bottom-half is changed as we
  3605. * are sending the wake-up, the new bottom-half will
  3606. * be woken by whomever made the change. We only have
  3607. * to worry about when we steal the irq-posted for
  3608. * ourself.
  3609. */
  3610. wake_up_process(b->irq_wait->tsk);
  3611. spin_unlock_irq(&b->irq_lock);
  3612. if (__i915_gem_request_completed(req, seqno))
  3613. return true;
  3614. }
  3615. return false;
  3616. }
  3617. void i915_memcpy_init_early(struct drm_i915_private *dev_priv);
  3618. bool i915_memcpy_from_wc(void *dst, const void *src, unsigned long len);
  3619. /* The movntdqa instructions used for memcpy-from-wc require 16-byte alignment,
  3620. * as well as SSE4.1 support. i915_memcpy_from_wc() will report if it cannot
  3621. * perform the operation. To check beforehand, pass in the parameters to
  3622. * to i915_can_memcpy_from_wc() - since we only care about the low 4 bits,
  3623. * you only need to pass in the minor offsets, page-aligned pointers are
  3624. * always valid.
  3625. *
  3626. * For just checking for SSE4.1, in the foreknowledge that the future use
  3627. * will be correctly aligned, just use i915_has_memcpy_from_wc().
  3628. */
  3629. #define i915_can_memcpy_from_wc(dst, src, len) \
  3630. i915_memcpy_from_wc((void *)((unsigned long)(dst) | (unsigned long)(src) | (len)), NULL, 0)
  3631. #define i915_has_memcpy_from_wc() \
  3632. i915_memcpy_from_wc(NULL, NULL, 0)
  3633. /* i915_mm.c */
  3634. int remap_io_mapping(struct vm_area_struct *vma,
  3635. unsigned long addr, unsigned long pfn, unsigned long size,
  3636. struct io_mapping *iomap);
  3637. static inline int intel_hws_csb_write_index(struct drm_i915_private *i915)
  3638. {
  3639. if (INTEL_GEN(i915) >= 10)
  3640. return CNL_HWS_CSB_WRITE_INDEX;
  3641. else
  3642. return I915_HWS_CSB_WRITE_INDEX;
  3643. }
  3644. #endif