i915_drv.h 113 KB

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