i915_drv.h 117 KB

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