i915_drv.h 119 KB

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