i915_drv.h 123 KB

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