i915_drv.h 118 KB

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