i915_drv.h 109 KB

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