i915_drv.h 119 KB

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