i915_drv.h 125 KB

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