i915_drv.h 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873
  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 "i915_reg.h"
  33. #include "intel_bios.h"
  34. #include "intel_ringbuffer.h"
  35. #include "i915_gem_gtt.h"
  36. #include <linux/io-mapping.h>
  37. #include <linux/i2c.h>
  38. #include <linux/i2c-algo-bit.h>
  39. #include <drm/intel-gtt.h>
  40. #include <linux/backlight.h>
  41. #include <linux/hashtable.h>
  42. #include <linux/intel-iommu.h>
  43. #include <linux/kref.h>
  44. #include <linux/pm_qos.h>
  45. /* General customization:
  46. */
  47. #define DRIVER_AUTHOR "Tungsten Graphics, Inc."
  48. #define DRIVER_NAME "i915"
  49. #define DRIVER_DESC "Intel Graphics"
  50. #define DRIVER_DATE "20140725"
  51. enum pipe {
  52. INVALID_PIPE = -1,
  53. PIPE_A = 0,
  54. PIPE_B,
  55. PIPE_C,
  56. _PIPE_EDP,
  57. I915_MAX_PIPES = _PIPE_EDP
  58. };
  59. #define pipe_name(p) ((p) + 'A')
  60. enum transcoder {
  61. TRANSCODER_A = 0,
  62. TRANSCODER_B,
  63. TRANSCODER_C,
  64. TRANSCODER_EDP,
  65. I915_MAX_TRANSCODERS
  66. };
  67. #define transcoder_name(t) ((t) + 'A')
  68. enum plane {
  69. PLANE_A = 0,
  70. PLANE_B,
  71. PLANE_C,
  72. };
  73. #define plane_name(p) ((p) + 'A')
  74. #define sprite_name(p, s) ((p) * INTEL_INFO(dev)->num_sprites[(p)] + (s) + 'A')
  75. enum port {
  76. PORT_A = 0,
  77. PORT_B,
  78. PORT_C,
  79. PORT_D,
  80. PORT_E,
  81. I915_MAX_PORTS
  82. };
  83. #define port_name(p) ((p) + 'A')
  84. #define I915_NUM_PHYS_VLV 2
  85. enum dpio_channel {
  86. DPIO_CH0,
  87. DPIO_CH1
  88. };
  89. enum dpio_phy {
  90. DPIO_PHY0,
  91. DPIO_PHY1
  92. };
  93. enum intel_display_power_domain {
  94. POWER_DOMAIN_PIPE_A,
  95. POWER_DOMAIN_PIPE_B,
  96. POWER_DOMAIN_PIPE_C,
  97. POWER_DOMAIN_PIPE_A_PANEL_FITTER,
  98. POWER_DOMAIN_PIPE_B_PANEL_FITTER,
  99. POWER_DOMAIN_PIPE_C_PANEL_FITTER,
  100. POWER_DOMAIN_TRANSCODER_A,
  101. POWER_DOMAIN_TRANSCODER_B,
  102. POWER_DOMAIN_TRANSCODER_C,
  103. POWER_DOMAIN_TRANSCODER_EDP,
  104. POWER_DOMAIN_PORT_DDI_A_2_LANES,
  105. POWER_DOMAIN_PORT_DDI_A_4_LANES,
  106. POWER_DOMAIN_PORT_DDI_B_2_LANES,
  107. POWER_DOMAIN_PORT_DDI_B_4_LANES,
  108. POWER_DOMAIN_PORT_DDI_C_2_LANES,
  109. POWER_DOMAIN_PORT_DDI_C_4_LANES,
  110. POWER_DOMAIN_PORT_DDI_D_2_LANES,
  111. POWER_DOMAIN_PORT_DDI_D_4_LANES,
  112. POWER_DOMAIN_PORT_DSI,
  113. POWER_DOMAIN_PORT_CRT,
  114. POWER_DOMAIN_PORT_OTHER,
  115. POWER_DOMAIN_VGA,
  116. POWER_DOMAIN_AUDIO,
  117. POWER_DOMAIN_PLLS,
  118. POWER_DOMAIN_INIT,
  119. POWER_DOMAIN_NUM,
  120. };
  121. #define POWER_DOMAIN_PIPE(pipe) ((pipe) + POWER_DOMAIN_PIPE_A)
  122. #define POWER_DOMAIN_PIPE_PANEL_FITTER(pipe) \
  123. ((pipe) + POWER_DOMAIN_PIPE_A_PANEL_FITTER)
  124. #define POWER_DOMAIN_TRANSCODER(tran) \
  125. ((tran) == TRANSCODER_EDP ? POWER_DOMAIN_TRANSCODER_EDP : \
  126. (tran) + POWER_DOMAIN_TRANSCODER_A)
  127. enum hpd_pin {
  128. HPD_NONE = 0,
  129. HPD_PORT_A = HPD_NONE, /* PORT_A is internal */
  130. HPD_TV = HPD_NONE, /* TV is known to be unreliable */
  131. HPD_CRT,
  132. HPD_SDVO_B,
  133. HPD_SDVO_C,
  134. HPD_PORT_B,
  135. HPD_PORT_C,
  136. HPD_PORT_D,
  137. HPD_NUM_PINS
  138. };
  139. #define I915_GEM_GPU_DOMAINS \
  140. (I915_GEM_DOMAIN_RENDER | \
  141. I915_GEM_DOMAIN_SAMPLER | \
  142. I915_GEM_DOMAIN_COMMAND | \
  143. I915_GEM_DOMAIN_INSTRUCTION | \
  144. I915_GEM_DOMAIN_VERTEX)
  145. #define for_each_pipe(p) for ((p) = 0; (p) < INTEL_INFO(dev)->num_pipes; (p)++)
  146. #define for_each_sprite(p, s) for ((s) = 0; (s) < INTEL_INFO(dev)->num_sprites[(p)]; (s)++)
  147. #define for_each_crtc(dev, crtc) \
  148. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  149. #define for_each_intel_crtc(dev, intel_crtc) \
  150. list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, base.head)
  151. #define for_each_encoder_on_crtc(dev, __crtc, intel_encoder) \
  152. list_for_each_entry((intel_encoder), &(dev)->mode_config.encoder_list, base.head) \
  153. if ((intel_encoder)->base.crtc == (__crtc))
  154. #define for_each_connector_on_encoder(dev, __encoder, intel_connector) \
  155. list_for_each_entry((intel_connector), &(dev)->mode_config.connector_list, base.head) \
  156. if ((intel_connector)->base.encoder == (__encoder))
  157. #define for_each_power_domain(domain, mask) \
  158. for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
  159. if ((1 << (domain)) & (mask))
  160. struct drm_i915_private;
  161. struct i915_mm_struct;
  162. struct i915_mmu_object;
  163. enum intel_dpll_id {
  164. DPLL_ID_PRIVATE = -1, /* non-shared dpll in use */
  165. /* real shared dpll ids must be >= 0 */
  166. DPLL_ID_PCH_PLL_A = 0,
  167. DPLL_ID_PCH_PLL_B = 1,
  168. DPLL_ID_WRPLL1 = 0,
  169. DPLL_ID_WRPLL2 = 1,
  170. };
  171. #define I915_NUM_PLLS 2
  172. struct intel_dpll_hw_state {
  173. uint32_t dpll;
  174. uint32_t dpll_md;
  175. uint32_t fp0;
  176. uint32_t fp1;
  177. uint32_t wrpll;
  178. };
  179. struct intel_shared_dpll {
  180. int refcount; /* count of number of CRTCs sharing this PLL */
  181. int active; /* count of number of active CRTCs (i.e. DPMS on) */
  182. bool on; /* is the PLL actually active? Disabled during modeset */
  183. const char *name;
  184. /* should match the index in the dev_priv->shared_dplls array */
  185. enum intel_dpll_id id;
  186. struct intel_dpll_hw_state hw_state;
  187. /* The mode_set hook is optional and should be used together with the
  188. * intel_prepare_shared_dpll function. */
  189. void (*mode_set)(struct drm_i915_private *dev_priv,
  190. struct intel_shared_dpll *pll);
  191. void (*enable)(struct drm_i915_private *dev_priv,
  192. struct intel_shared_dpll *pll);
  193. void (*disable)(struct drm_i915_private *dev_priv,
  194. struct intel_shared_dpll *pll);
  195. bool (*get_hw_state)(struct drm_i915_private *dev_priv,
  196. struct intel_shared_dpll *pll,
  197. struct intel_dpll_hw_state *hw_state);
  198. };
  199. /* Used by dp and fdi links */
  200. struct intel_link_m_n {
  201. uint32_t tu;
  202. uint32_t gmch_m;
  203. uint32_t gmch_n;
  204. uint32_t link_m;
  205. uint32_t link_n;
  206. };
  207. void intel_link_compute_m_n(int bpp, int nlanes,
  208. int pixel_clock, int link_clock,
  209. struct intel_link_m_n *m_n);
  210. /* Interface history:
  211. *
  212. * 1.1: Original.
  213. * 1.2: Add Power Management
  214. * 1.3: Add vblank support
  215. * 1.4: Fix cmdbuffer path, add heap destroy
  216. * 1.5: Add vblank pipe configuration
  217. * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
  218. * - Support vertical blank on secondary display pipe
  219. */
  220. #define DRIVER_MAJOR 1
  221. #define DRIVER_MINOR 6
  222. #define DRIVER_PATCHLEVEL 0
  223. #define WATCH_LISTS 0
  224. #define WATCH_GTT 0
  225. struct opregion_header;
  226. struct opregion_acpi;
  227. struct opregion_swsci;
  228. struct opregion_asle;
  229. struct intel_opregion {
  230. struct opregion_header __iomem *header;
  231. struct opregion_acpi __iomem *acpi;
  232. struct opregion_swsci __iomem *swsci;
  233. u32 swsci_gbda_sub_functions;
  234. u32 swsci_sbcb_sub_functions;
  235. struct opregion_asle __iomem *asle;
  236. void __iomem *vbt;
  237. u32 __iomem *lid_state;
  238. struct work_struct asle_work;
  239. };
  240. #define OPREGION_SIZE (8*1024)
  241. struct intel_overlay;
  242. struct intel_overlay_error_state;
  243. struct drm_i915_master_private {
  244. drm_local_map_t *sarea;
  245. struct _drm_i915_sarea *sarea_priv;
  246. };
  247. #define I915_FENCE_REG_NONE -1
  248. #define I915_MAX_NUM_FENCES 32
  249. /* 32 fences + sign bit for FENCE_REG_NONE */
  250. #define I915_MAX_NUM_FENCE_BITS 6
  251. struct drm_i915_fence_reg {
  252. struct list_head lru_list;
  253. struct drm_i915_gem_object *obj;
  254. int pin_count;
  255. };
  256. struct sdvo_device_mapping {
  257. u8 initialized;
  258. u8 dvo_port;
  259. u8 slave_addr;
  260. u8 dvo_wiring;
  261. u8 i2c_pin;
  262. u8 ddc_pin;
  263. };
  264. struct intel_display_error_state;
  265. struct drm_i915_error_state {
  266. struct kref ref;
  267. struct timeval time;
  268. char error_msg[128];
  269. u32 reset_count;
  270. u32 suspend_count;
  271. /* Generic register state */
  272. u32 eir;
  273. u32 pgtbl_er;
  274. u32 ier;
  275. u32 gtier[4];
  276. u32 ccid;
  277. u32 derrmr;
  278. u32 forcewake;
  279. u32 error; /* gen6+ */
  280. u32 err_int; /* gen7 */
  281. u32 done_reg;
  282. u32 gac_eco;
  283. u32 gam_ecochk;
  284. u32 gab_ctl;
  285. u32 gfx_mode;
  286. u32 extra_instdone[I915_NUM_INSTDONE_REG];
  287. u64 fence[I915_MAX_NUM_FENCES];
  288. struct intel_overlay_error_state *overlay;
  289. struct intel_display_error_state *display;
  290. struct drm_i915_error_object *semaphore_obj;
  291. struct drm_i915_error_ring {
  292. bool valid;
  293. /* Software tracked state */
  294. bool waiting;
  295. int hangcheck_score;
  296. enum intel_ring_hangcheck_action hangcheck_action;
  297. int num_requests;
  298. /* our own tracking of ring head and tail */
  299. u32 cpu_ring_head;
  300. u32 cpu_ring_tail;
  301. u32 semaphore_seqno[I915_NUM_RINGS - 1];
  302. /* Register state */
  303. u32 tail;
  304. u32 head;
  305. u32 ctl;
  306. u32 hws;
  307. u32 ipeir;
  308. u32 ipehr;
  309. u32 instdone;
  310. u32 bbstate;
  311. u32 instpm;
  312. u32 instps;
  313. u32 seqno;
  314. u64 bbaddr;
  315. u64 acthd;
  316. u32 fault_reg;
  317. u64 faddr;
  318. u32 rc_psmi; /* sleep state */
  319. u32 semaphore_mboxes[I915_NUM_RINGS - 1];
  320. struct drm_i915_error_object {
  321. int page_count;
  322. u32 gtt_offset;
  323. u32 *pages[0];
  324. } *ringbuffer, *batchbuffer, *wa_batchbuffer, *ctx, *hws_page;
  325. struct drm_i915_error_request {
  326. long jiffies;
  327. u32 seqno;
  328. u32 tail;
  329. } *requests;
  330. struct {
  331. u32 gfx_mode;
  332. union {
  333. u64 pdp[4];
  334. u32 pp_dir_base;
  335. };
  336. } vm_info;
  337. pid_t pid;
  338. char comm[TASK_COMM_LEN];
  339. } ring[I915_NUM_RINGS];
  340. struct drm_i915_error_buffer {
  341. u32 size;
  342. u32 name;
  343. u32 rseqno, wseqno;
  344. u32 gtt_offset;
  345. u32 read_domains;
  346. u32 write_domain;
  347. s32 fence_reg:I915_MAX_NUM_FENCE_BITS;
  348. s32 pinned:2;
  349. u32 tiling:2;
  350. u32 dirty:1;
  351. u32 purgeable:1;
  352. u32 userptr:1;
  353. s32 ring:4;
  354. u32 cache_level:3;
  355. } **active_bo, **pinned_bo;
  356. u32 *active_bo_count, *pinned_bo_count;
  357. };
  358. struct intel_connector;
  359. struct intel_crtc_config;
  360. struct intel_plane_config;
  361. struct intel_crtc;
  362. struct intel_limit;
  363. struct dpll;
  364. struct drm_i915_display_funcs {
  365. bool (*fbc_enabled)(struct drm_device *dev);
  366. void (*enable_fbc)(struct drm_crtc *crtc);
  367. void (*disable_fbc)(struct drm_device *dev);
  368. int (*get_display_clock_speed)(struct drm_device *dev);
  369. int (*get_fifo_size)(struct drm_device *dev, int plane);
  370. /**
  371. * find_dpll() - Find the best values for the PLL
  372. * @limit: limits for the PLL
  373. * @crtc: current CRTC
  374. * @target: target frequency in kHz
  375. * @refclk: reference clock frequency in kHz
  376. * @match_clock: if provided, @best_clock P divider must
  377. * match the P divider from @match_clock
  378. * used for LVDS downclocking
  379. * @best_clock: best PLL values found
  380. *
  381. * Returns true on success, false on failure.
  382. */
  383. bool (*find_dpll)(const struct intel_limit *limit,
  384. struct drm_crtc *crtc,
  385. int target, int refclk,
  386. struct dpll *match_clock,
  387. struct dpll *best_clock);
  388. void (*update_wm)(struct drm_crtc *crtc);
  389. void (*update_sprite_wm)(struct drm_plane *plane,
  390. struct drm_crtc *crtc,
  391. uint32_t sprite_width, uint32_t sprite_height,
  392. int pixel_size, bool enable, bool scaled);
  393. void (*modeset_global_resources)(struct drm_device *dev);
  394. /* Returns the active state of the crtc, and if the crtc is active,
  395. * fills out the pipe-config with the hw state. */
  396. bool (*get_pipe_config)(struct intel_crtc *,
  397. struct intel_crtc_config *);
  398. void (*get_plane_config)(struct intel_crtc *,
  399. struct intel_plane_config *);
  400. int (*crtc_mode_set)(struct drm_crtc *crtc,
  401. int x, int y,
  402. struct drm_framebuffer *old_fb);
  403. void (*crtc_enable)(struct drm_crtc *crtc);
  404. void (*crtc_disable)(struct drm_crtc *crtc);
  405. void (*off)(struct drm_crtc *crtc);
  406. void (*write_eld)(struct drm_connector *connector,
  407. struct drm_crtc *crtc,
  408. struct drm_display_mode *mode);
  409. void (*fdi_link_train)(struct drm_crtc *crtc);
  410. void (*init_clock_gating)(struct drm_device *dev);
  411. int (*queue_flip)(struct drm_device *dev, struct drm_crtc *crtc,
  412. struct drm_framebuffer *fb,
  413. struct drm_i915_gem_object *obj,
  414. struct intel_engine_cs *ring,
  415. uint32_t flags);
  416. void (*update_primary_plane)(struct drm_crtc *crtc,
  417. struct drm_framebuffer *fb,
  418. int x, int y);
  419. void (*hpd_irq_setup)(struct drm_device *dev);
  420. /* clock updates for mode set */
  421. /* cursor updates */
  422. /* render clock increase/decrease */
  423. /* display clock increase/decrease */
  424. /* pll clock increase/decrease */
  425. int (*setup_backlight)(struct intel_connector *connector);
  426. uint32_t (*get_backlight)(struct intel_connector *connector);
  427. void (*set_backlight)(struct intel_connector *connector,
  428. uint32_t level);
  429. void (*disable_backlight)(struct intel_connector *connector);
  430. void (*enable_backlight)(struct intel_connector *connector);
  431. };
  432. struct intel_uncore_funcs {
  433. void (*force_wake_get)(struct drm_i915_private *dev_priv,
  434. int fw_engine);
  435. void (*force_wake_put)(struct drm_i915_private *dev_priv,
  436. int fw_engine);
  437. uint8_t (*mmio_readb)(struct drm_i915_private *dev_priv, off_t offset, bool trace);
  438. uint16_t (*mmio_readw)(struct drm_i915_private *dev_priv, off_t offset, bool trace);
  439. uint32_t (*mmio_readl)(struct drm_i915_private *dev_priv, off_t offset, bool trace);
  440. uint64_t (*mmio_readq)(struct drm_i915_private *dev_priv, off_t offset, bool trace);
  441. void (*mmio_writeb)(struct drm_i915_private *dev_priv, off_t offset,
  442. uint8_t val, bool trace);
  443. void (*mmio_writew)(struct drm_i915_private *dev_priv, off_t offset,
  444. uint16_t val, bool trace);
  445. void (*mmio_writel)(struct drm_i915_private *dev_priv, off_t offset,
  446. uint32_t val, bool trace);
  447. void (*mmio_writeq)(struct drm_i915_private *dev_priv, off_t offset,
  448. uint64_t val, bool trace);
  449. };
  450. struct intel_uncore {
  451. spinlock_t lock; /** lock is also taken in irq contexts. */
  452. struct intel_uncore_funcs funcs;
  453. unsigned fifo_count;
  454. unsigned forcewake_count;
  455. unsigned fw_rendercount;
  456. unsigned fw_mediacount;
  457. struct timer_list force_wake_timer;
  458. };
  459. #define DEV_INFO_FOR_EACH_FLAG(func, sep) \
  460. func(is_mobile) sep \
  461. func(is_i85x) sep \
  462. func(is_i915g) sep \
  463. func(is_i945gm) sep \
  464. func(is_g33) sep \
  465. func(need_gfx_hws) sep \
  466. func(is_g4x) sep \
  467. func(is_pineview) sep \
  468. func(is_broadwater) sep \
  469. func(is_crestline) sep \
  470. func(is_ivybridge) sep \
  471. func(is_valleyview) sep \
  472. func(is_haswell) sep \
  473. func(is_preliminary) sep \
  474. func(has_fbc) sep \
  475. func(has_pipe_cxsr) sep \
  476. func(has_hotplug) sep \
  477. func(cursor_needs_physical) sep \
  478. func(has_overlay) sep \
  479. func(overlay_needs_physical) sep \
  480. func(supports_tv) sep \
  481. func(has_llc) sep \
  482. func(has_ddi) sep \
  483. func(has_fpga_dbg)
  484. #define DEFINE_FLAG(name) u8 name:1
  485. #define SEP_SEMICOLON ;
  486. struct intel_device_info {
  487. u32 display_mmio_offset;
  488. u8 num_pipes:3;
  489. u8 num_sprites[I915_MAX_PIPES];
  490. u8 gen;
  491. u8 ring_mask; /* Rings supported by the HW */
  492. DEV_INFO_FOR_EACH_FLAG(DEFINE_FLAG, SEP_SEMICOLON);
  493. /* Register offsets for the various display pipes and transcoders */
  494. int pipe_offsets[I915_MAX_TRANSCODERS];
  495. int trans_offsets[I915_MAX_TRANSCODERS];
  496. int palette_offsets[I915_MAX_PIPES];
  497. int cursor_offsets[I915_MAX_PIPES];
  498. };
  499. #undef DEFINE_FLAG
  500. #undef SEP_SEMICOLON
  501. enum i915_cache_level {
  502. I915_CACHE_NONE = 0,
  503. I915_CACHE_LLC, /* also used for snoopable memory on non-LLC */
  504. I915_CACHE_L3_LLC, /* gen7+, L3 sits between the domain specifc
  505. caches, eg sampler/render caches, and the
  506. large Last-Level-Cache. LLC is coherent with
  507. the CPU, but L3 is only visible to the GPU. */
  508. I915_CACHE_WT, /* hsw:gt3e WriteThrough for scanouts */
  509. };
  510. struct i915_ctx_hang_stats {
  511. /* This context had batch pending when hang was declared */
  512. unsigned batch_pending;
  513. /* This context had batch active when hang was declared */
  514. unsigned batch_active;
  515. /* Time when this context was last blamed for a GPU reset */
  516. unsigned long guilty_ts;
  517. /* This context is banned to submit more work */
  518. bool banned;
  519. };
  520. /* This must match up with the value previously used for execbuf2.rsvd1. */
  521. #define DEFAULT_CONTEXT_HANDLE 0
  522. /**
  523. * struct intel_context - as the name implies, represents a context.
  524. * @ref: reference count.
  525. * @user_handle: userspace tracking identity for this context.
  526. * @remap_slice: l3 row remapping information.
  527. * @file_priv: filp associated with this context (NULL for global default
  528. * context).
  529. * @hang_stats: information about the role of this context in possible GPU
  530. * hangs.
  531. * @vm: virtual memory space used by this context.
  532. * @legacy_hw_ctx: render context backing object and whether it is correctly
  533. * initialized (legacy ring submission mechanism only).
  534. * @link: link in the global list of contexts.
  535. *
  536. * Contexts are memory images used by the hardware to store copies of their
  537. * internal state.
  538. */
  539. struct intel_context {
  540. struct kref ref;
  541. int user_handle;
  542. uint8_t remap_slice;
  543. struct drm_i915_file_private *file_priv;
  544. struct i915_ctx_hang_stats hang_stats;
  545. struct i915_address_space *vm;
  546. struct {
  547. struct drm_i915_gem_object *rcs_state;
  548. bool initialized;
  549. } legacy_hw_ctx;
  550. struct list_head link;
  551. };
  552. struct i915_fbc {
  553. unsigned long size;
  554. unsigned threshold;
  555. unsigned int fb_id;
  556. enum plane plane;
  557. int y;
  558. struct drm_mm_node compressed_fb;
  559. struct drm_mm_node *compressed_llb;
  560. struct intel_fbc_work {
  561. struct delayed_work work;
  562. struct drm_crtc *crtc;
  563. struct drm_framebuffer *fb;
  564. } *fbc_work;
  565. enum no_fbc_reason {
  566. FBC_OK, /* FBC is enabled */
  567. FBC_UNSUPPORTED, /* FBC is not supported by this chipset */
  568. FBC_NO_OUTPUT, /* no outputs enabled to compress */
  569. FBC_STOLEN_TOO_SMALL, /* not enough space for buffers */
  570. FBC_UNSUPPORTED_MODE, /* interlace or doublescanned mode */
  571. FBC_MODE_TOO_LARGE, /* mode too large for compression */
  572. FBC_BAD_PLANE, /* fbc not supported on plane */
  573. FBC_NOT_TILED, /* buffer not tiled */
  574. FBC_MULTIPLE_PIPES, /* more than one pipe active */
  575. FBC_MODULE_PARAM,
  576. FBC_CHIP_DEFAULT, /* disabled by default on this chip */
  577. } no_fbc_reason;
  578. };
  579. struct i915_drrs {
  580. struct intel_connector *connector;
  581. };
  582. struct intel_dp;
  583. struct i915_psr {
  584. struct mutex lock;
  585. bool sink_support;
  586. bool source_ok;
  587. struct intel_dp *enabled;
  588. bool active;
  589. struct delayed_work work;
  590. unsigned busy_frontbuffer_bits;
  591. };
  592. enum intel_pch {
  593. PCH_NONE = 0, /* No PCH present */
  594. PCH_IBX, /* Ibexpeak PCH */
  595. PCH_CPT, /* Cougarpoint PCH */
  596. PCH_LPT, /* Lynxpoint PCH */
  597. PCH_NOP,
  598. };
  599. enum intel_sbi_destination {
  600. SBI_ICLK,
  601. SBI_MPHY,
  602. };
  603. #define QUIRK_PIPEA_FORCE (1<<0)
  604. #define QUIRK_LVDS_SSC_DISABLE (1<<1)
  605. #define QUIRK_INVERT_BRIGHTNESS (1<<2)
  606. #define QUIRK_BACKLIGHT_PRESENT (1<<3)
  607. struct intel_fbdev;
  608. struct intel_fbc_work;
  609. struct intel_gmbus {
  610. struct i2c_adapter adapter;
  611. u32 force_bit;
  612. u32 reg0;
  613. u32 gpio_reg;
  614. struct i2c_algo_bit_data bit_algo;
  615. struct drm_i915_private *dev_priv;
  616. };
  617. struct i915_suspend_saved_registers {
  618. u8 saveLBB;
  619. u32 saveDSPACNTR;
  620. u32 saveDSPBCNTR;
  621. u32 saveDSPARB;
  622. u32 savePIPEACONF;
  623. u32 savePIPEBCONF;
  624. u32 savePIPEASRC;
  625. u32 savePIPEBSRC;
  626. u32 saveFPA0;
  627. u32 saveFPA1;
  628. u32 saveDPLL_A;
  629. u32 saveDPLL_A_MD;
  630. u32 saveHTOTAL_A;
  631. u32 saveHBLANK_A;
  632. u32 saveHSYNC_A;
  633. u32 saveVTOTAL_A;
  634. u32 saveVBLANK_A;
  635. u32 saveVSYNC_A;
  636. u32 saveBCLRPAT_A;
  637. u32 saveTRANSACONF;
  638. u32 saveTRANS_HTOTAL_A;
  639. u32 saveTRANS_HBLANK_A;
  640. u32 saveTRANS_HSYNC_A;
  641. u32 saveTRANS_VTOTAL_A;
  642. u32 saveTRANS_VBLANK_A;
  643. u32 saveTRANS_VSYNC_A;
  644. u32 savePIPEASTAT;
  645. u32 saveDSPASTRIDE;
  646. u32 saveDSPASIZE;
  647. u32 saveDSPAPOS;
  648. u32 saveDSPAADDR;
  649. u32 saveDSPASURF;
  650. u32 saveDSPATILEOFF;
  651. u32 savePFIT_PGM_RATIOS;
  652. u32 saveBLC_HIST_CTL;
  653. u32 saveBLC_PWM_CTL;
  654. u32 saveBLC_PWM_CTL2;
  655. u32 saveBLC_HIST_CTL_B;
  656. u32 saveBLC_CPU_PWM_CTL;
  657. u32 saveBLC_CPU_PWM_CTL2;
  658. u32 saveFPB0;
  659. u32 saveFPB1;
  660. u32 saveDPLL_B;
  661. u32 saveDPLL_B_MD;
  662. u32 saveHTOTAL_B;
  663. u32 saveHBLANK_B;
  664. u32 saveHSYNC_B;
  665. u32 saveVTOTAL_B;
  666. u32 saveVBLANK_B;
  667. u32 saveVSYNC_B;
  668. u32 saveBCLRPAT_B;
  669. u32 saveTRANSBCONF;
  670. u32 saveTRANS_HTOTAL_B;
  671. u32 saveTRANS_HBLANK_B;
  672. u32 saveTRANS_HSYNC_B;
  673. u32 saveTRANS_VTOTAL_B;
  674. u32 saveTRANS_VBLANK_B;
  675. u32 saveTRANS_VSYNC_B;
  676. u32 savePIPEBSTAT;
  677. u32 saveDSPBSTRIDE;
  678. u32 saveDSPBSIZE;
  679. u32 saveDSPBPOS;
  680. u32 saveDSPBADDR;
  681. u32 saveDSPBSURF;
  682. u32 saveDSPBTILEOFF;
  683. u32 saveVGA0;
  684. u32 saveVGA1;
  685. u32 saveVGA_PD;
  686. u32 saveVGACNTRL;
  687. u32 saveADPA;
  688. u32 saveLVDS;
  689. u32 savePP_ON_DELAYS;
  690. u32 savePP_OFF_DELAYS;
  691. u32 saveDVOA;
  692. u32 saveDVOB;
  693. u32 saveDVOC;
  694. u32 savePP_ON;
  695. u32 savePP_OFF;
  696. u32 savePP_CONTROL;
  697. u32 savePP_DIVISOR;
  698. u32 savePFIT_CONTROL;
  699. u32 save_palette_a[256];
  700. u32 save_palette_b[256];
  701. u32 saveFBC_CONTROL;
  702. u32 saveIER;
  703. u32 saveIIR;
  704. u32 saveIMR;
  705. u32 saveDEIER;
  706. u32 saveDEIMR;
  707. u32 saveGTIER;
  708. u32 saveGTIMR;
  709. u32 saveFDI_RXA_IMR;
  710. u32 saveFDI_RXB_IMR;
  711. u32 saveCACHE_MODE_0;
  712. u32 saveMI_ARB_STATE;
  713. u32 saveSWF0[16];
  714. u32 saveSWF1[16];
  715. u32 saveSWF2[3];
  716. u8 saveMSR;
  717. u8 saveSR[8];
  718. u8 saveGR[25];
  719. u8 saveAR_INDEX;
  720. u8 saveAR[21];
  721. u8 saveDACMASK;
  722. u8 saveCR[37];
  723. uint64_t saveFENCE[I915_MAX_NUM_FENCES];
  724. u32 saveCURACNTR;
  725. u32 saveCURAPOS;
  726. u32 saveCURABASE;
  727. u32 saveCURBCNTR;
  728. u32 saveCURBPOS;
  729. u32 saveCURBBASE;
  730. u32 saveCURSIZE;
  731. u32 saveDP_B;
  732. u32 saveDP_C;
  733. u32 saveDP_D;
  734. u32 savePIPEA_GMCH_DATA_M;
  735. u32 savePIPEB_GMCH_DATA_M;
  736. u32 savePIPEA_GMCH_DATA_N;
  737. u32 savePIPEB_GMCH_DATA_N;
  738. u32 savePIPEA_DP_LINK_M;
  739. u32 savePIPEB_DP_LINK_M;
  740. u32 savePIPEA_DP_LINK_N;
  741. u32 savePIPEB_DP_LINK_N;
  742. u32 saveFDI_RXA_CTL;
  743. u32 saveFDI_TXA_CTL;
  744. u32 saveFDI_RXB_CTL;
  745. u32 saveFDI_TXB_CTL;
  746. u32 savePFA_CTL_1;
  747. u32 savePFB_CTL_1;
  748. u32 savePFA_WIN_SZ;
  749. u32 savePFB_WIN_SZ;
  750. u32 savePFA_WIN_POS;
  751. u32 savePFB_WIN_POS;
  752. u32 savePCH_DREF_CONTROL;
  753. u32 saveDISP_ARB_CTL;
  754. u32 savePIPEA_DATA_M1;
  755. u32 savePIPEA_DATA_N1;
  756. u32 savePIPEA_LINK_M1;
  757. u32 savePIPEA_LINK_N1;
  758. u32 savePIPEB_DATA_M1;
  759. u32 savePIPEB_DATA_N1;
  760. u32 savePIPEB_LINK_M1;
  761. u32 savePIPEB_LINK_N1;
  762. u32 saveMCHBAR_RENDER_STANDBY;
  763. u32 savePCH_PORT_HOTPLUG;
  764. };
  765. struct vlv_s0ix_state {
  766. /* GAM */
  767. u32 wr_watermark;
  768. u32 gfx_prio_ctrl;
  769. u32 arb_mode;
  770. u32 gfx_pend_tlb0;
  771. u32 gfx_pend_tlb1;
  772. u32 lra_limits[GEN7_LRA_LIMITS_REG_NUM];
  773. u32 media_max_req_count;
  774. u32 gfx_max_req_count;
  775. u32 render_hwsp;
  776. u32 ecochk;
  777. u32 bsd_hwsp;
  778. u32 blt_hwsp;
  779. u32 tlb_rd_addr;
  780. /* MBC */
  781. u32 g3dctl;
  782. u32 gsckgctl;
  783. u32 mbctl;
  784. /* GCP */
  785. u32 ucgctl1;
  786. u32 ucgctl3;
  787. u32 rcgctl1;
  788. u32 rcgctl2;
  789. u32 rstctl;
  790. u32 misccpctl;
  791. /* GPM */
  792. u32 gfxpause;
  793. u32 rpdeuhwtc;
  794. u32 rpdeuc;
  795. u32 ecobus;
  796. u32 pwrdwnupctl;
  797. u32 rp_down_timeout;
  798. u32 rp_deucsw;
  799. u32 rcubmabdtmr;
  800. u32 rcedata;
  801. u32 spare2gh;
  802. /* Display 1 CZ domain */
  803. u32 gt_imr;
  804. u32 gt_ier;
  805. u32 pm_imr;
  806. u32 pm_ier;
  807. u32 gt_scratch[GEN7_GT_SCRATCH_REG_NUM];
  808. /* GT SA CZ domain */
  809. u32 tilectl;
  810. u32 gt_fifoctl;
  811. u32 gtlc_wake_ctrl;
  812. u32 gtlc_survive;
  813. u32 pmwgicz;
  814. /* Display 2 CZ domain */
  815. u32 gu_ctl0;
  816. u32 gu_ctl1;
  817. u32 clock_gate_dis2;
  818. };
  819. struct intel_rps_ei {
  820. u32 cz_clock;
  821. u32 render_c0;
  822. u32 media_c0;
  823. };
  824. struct intel_gen6_power_mgmt {
  825. /* work and pm_iir are protected by dev_priv->irq_lock */
  826. struct work_struct work;
  827. u32 pm_iir;
  828. /* Frequencies are stored in potentially platform dependent multiples.
  829. * In other words, *_freq needs to be multiplied by X to be interesting.
  830. * Soft limits are those which are used for the dynamic reclocking done
  831. * by the driver (raise frequencies under heavy loads, and lower for
  832. * lighter loads). Hard limits are those imposed by the hardware.
  833. *
  834. * A distinction is made for overclocking, which is never enabled by
  835. * default, and is considered to be above the hard limit if it's
  836. * possible at all.
  837. */
  838. u8 cur_freq; /* Current frequency (cached, may not == HW) */
  839. u8 min_freq_softlimit; /* Minimum frequency permitted by the driver */
  840. u8 max_freq_softlimit; /* Max frequency permitted by the driver */
  841. u8 max_freq; /* Maximum frequency, RP0 if not overclocking */
  842. u8 min_freq; /* AKA RPn. Minimum frequency */
  843. u8 efficient_freq; /* AKA RPe. Pre-determined balanced frequency */
  844. u8 rp1_freq; /* "less than" RP0 power/freqency */
  845. u8 rp0_freq; /* Non-overclocked max frequency. */
  846. u32 cz_freq;
  847. u32 ei_interrupt_count;
  848. int last_adj;
  849. enum { LOW_POWER, BETWEEN, HIGH_POWER } power;
  850. bool enabled;
  851. struct delayed_work delayed_resume_work;
  852. /* manual wa residency calculations */
  853. struct intel_rps_ei up_ei, down_ei;
  854. /*
  855. * Protects RPS/RC6 register access and PCU communication.
  856. * Must be taken after struct_mutex if nested.
  857. */
  858. struct mutex hw_lock;
  859. };
  860. /* defined intel_pm.c */
  861. extern spinlock_t mchdev_lock;
  862. struct intel_ilk_power_mgmt {
  863. u8 cur_delay;
  864. u8 min_delay;
  865. u8 max_delay;
  866. u8 fmax;
  867. u8 fstart;
  868. u64 last_count1;
  869. unsigned long last_time1;
  870. unsigned long chipset_power;
  871. u64 last_count2;
  872. u64 last_time2;
  873. unsigned long gfx_power;
  874. u8 corr;
  875. int c_m;
  876. int r_t;
  877. struct drm_i915_gem_object *pwrctx;
  878. struct drm_i915_gem_object *renderctx;
  879. };
  880. struct drm_i915_private;
  881. struct i915_power_well;
  882. struct i915_power_well_ops {
  883. /*
  884. * Synchronize the well's hw state to match the current sw state, for
  885. * example enable/disable it based on the current refcount. Called
  886. * during driver init and resume time, possibly after first calling
  887. * the enable/disable handlers.
  888. */
  889. void (*sync_hw)(struct drm_i915_private *dev_priv,
  890. struct i915_power_well *power_well);
  891. /*
  892. * Enable the well and resources that depend on it (for example
  893. * interrupts located on the well). Called after the 0->1 refcount
  894. * transition.
  895. */
  896. void (*enable)(struct drm_i915_private *dev_priv,
  897. struct i915_power_well *power_well);
  898. /*
  899. * Disable the well and resources that depend on it. Called after
  900. * the 1->0 refcount transition.
  901. */
  902. void (*disable)(struct drm_i915_private *dev_priv,
  903. struct i915_power_well *power_well);
  904. /* Returns the hw enabled state. */
  905. bool (*is_enabled)(struct drm_i915_private *dev_priv,
  906. struct i915_power_well *power_well);
  907. };
  908. /* Power well structure for haswell */
  909. struct i915_power_well {
  910. const char *name;
  911. bool always_on;
  912. /* power well enable/disable usage count */
  913. int count;
  914. /* cached hw enabled state */
  915. bool hw_enabled;
  916. unsigned long domains;
  917. unsigned long data;
  918. const struct i915_power_well_ops *ops;
  919. };
  920. struct i915_power_domains {
  921. /*
  922. * Power wells needed for initialization at driver init and suspend
  923. * time are on. They are kept on until after the first modeset.
  924. */
  925. bool init_power_on;
  926. bool initializing;
  927. int power_well_count;
  928. struct mutex lock;
  929. int domain_use_count[POWER_DOMAIN_NUM];
  930. struct i915_power_well *power_wells;
  931. };
  932. struct i915_dri1_state {
  933. unsigned allow_batchbuffer : 1;
  934. u32 __iomem *gfx_hws_cpu_addr;
  935. unsigned int cpp;
  936. int back_offset;
  937. int front_offset;
  938. int current_page;
  939. int page_flipping;
  940. uint32_t counter;
  941. };
  942. struct i915_ums_state {
  943. /**
  944. * Flag if the X Server, and thus DRM, is not currently in
  945. * control of the device.
  946. *
  947. * This is set between LeaveVT and EnterVT. It needs to be
  948. * replaced with a semaphore. It also needs to be
  949. * transitioned away from for kernel modesetting.
  950. */
  951. int mm_suspended;
  952. };
  953. #define MAX_L3_SLICES 2
  954. struct intel_l3_parity {
  955. u32 *remap_info[MAX_L3_SLICES];
  956. struct work_struct error_work;
  957. int which_slice;
  958. };
  959. struct i915_gem_mm {
  960. /** Memory allocator for GTT stolen memory */
  961. struct drm_mm stolen;
  962. /** List of all objects in gtt_space. Used to restore gtt
  963. * mappings on resume */
  964. struct list_head bound_list;
  965. /**
  966. * List of objects which are not bound to the GTT (thus
  967. * are idle and not used by the GPU) but still have
  968. * (presumably uncached) pages still attached.
  969. */
  970. struct list_head unbound_list;
  971. /** Usable portion of the GTT for GEM */
  972. unsigned long stolen_base; /* limited to low memory (32-bit) */
  973. /** PPGTT used for aliasing the PPGTT with the GTT */
  974. struct i915_hw_ppgtt *aliasing_ppgtt;
  975. struct notifier_block oom_notifier;
  976. struct shrinker shrinker;
  977. bool shrinker_no_lock_stealing;
  978. /** LRU list of objects with fence regs on them. */
  979. struct list_head fence_list;
  980. /**
  981. * We leave the user IRQ off as much as possible,
  982. * but this means that requests will finish and never
  983. * be retired once the system goes idle. Set a timer to
  984. * fire periodically while the ring is running. When it
  985. * fires, go retire requests.
  986. */
  987. struct delayed_work retire_work;
  988. /**
  989. * When we detect an idle GPU, we want to turn on
  990. * powersaving features. So once we see that there
  991. * are no more requests outstanding and no more
  992. * arrive within a small period of time, we fire
  993. * off the idle_work.
  994. */
  995. struct delayed_work idle_work;
  996. /**
  997. * Are we in a non-interruptible section of code like
  998. * modesetting?
  999. */
  1000. bool interruptible;
  1001. /**
  1002. * Is the GPU currently considered idle, or busy executing userspace
  1003. * requests? Whilst idle, we attempt to power down the hardware and
  1004. * display clocks. In order to reduce the effect on performance, there
  1005. * is a slight delay before we do so.
  1006. */
  1007. bool busy;
  1008. /* the indicator for dispatch video commands on two BSD rings */
  1009. int bsd_ring_dispatch_index;
  1010. /** Bit 6 swizzling required for X tiling */
  1011. uint32_t bit_6_swizzle_x;
  1012. /** Bit 6 swizzling required for Y tiling */
  1013. uint32_t bit_6_swizzle_y;
  1014. /* accounting, useful for userland debugging */
  1015. spinlock_t object_stat_lock;
  1016. size_t object_memory;
  1017. u32 object_count;
  1018. };
  1019. struct drm_i915_error_state_buf {
  1020. unsigned bytes;
  1021. unsigned size;
  1022. int err;
  1023. u8 *buf;
  1024. loff_t start;
  1025. loff_t pos;
  1026. };
  1027. struct i915_error_state_file_priv {
  1028. struct drm_device *dev;
  1029. struct drm_i915_error_state *error;
  1030. };
  1031. struct i915_gpu_error {
  1032. /* For hangcheck timer */
  1033. #define DRM_I915_HANGCHECK_PERIOD 1500 /* in ms */
  1034. #define DRM_I915_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD)
  1035. /* Hang gpu twice in this window and your context gets banned */
  1036. #define DRM_I915_CTX_BAN_PERIOD DIV_ROUND_UP(8*DRM_I915_HANGCHECK_PERIOD, 1000)
  1037. struct timer_list hangcheck_timer;
  1038. /* For reset and error_state handling. */
  1039. spinlock_t lock;
  1040. /* Protected by the above dev->gpu_error.lock. */
  1041. struct drm_i915_error_state *first_error;
  1042. struct work_struct work;
  1043. unsigned long missed_irq_rings;
  1044. /**
  1045. * State variable controlling the reset flow and count
  1046. *
  1047. * This is a counter which gets incremented when reset is triggered,
  1048. * and again when reset has been handled. So odd values (lowest bit set)
  1049. * means that reset is in progress and even values that
  1050. * (reset_counter >> 1):th reset was successfully completed.
  1051. *
  1052. * If reset is not completed succesfully, the I915_WEDGE bit is
  1053. * set meaning that hardware is terminally sour and there is no
  1054. * recovery. All waiters on the reset_queue will be woken when
  1055. * that happens.
  1056. *
  1057. * This counter is used by the wait_seqno code to notice that reset
  1058. * event happened and it needs to restart the entire ioctl (since most
  1059. * likely the seqno it waited for won't ever signal anytime soon).
  1060. *
  1061. * This is important for lock-free wait paths, where no contended lock
  1062. * naturally enforces the correct ordering between the bail-out of the
  1063. * waiter and the gpu reset work code.
  1064. */
  1065. atomic_t reset_counter;
  1066. #define I915_RESET_IN_PROGRESS_FLAG 1
  1067. #define I915_WEDGED (1 << 31)
  1068. /**
  1069. * Waitqueue to signal when the reset has completed. Used by clients
  1070. * that wait for dev_priv->mm.wedged to settle.
  1071. */
  1072. wait_queue_head_t reset_queue;
  1073. /* Userspace knobs for gpu hang simulation;
  1074. * combines both a ring mask, and extra flags
  1075. */
  1076. u32 stop_rings;
  1077. #define I915_STOP_RING_ALLOW_BAN (1 << 31)
  1078. #define I915_STOP_RING_ALLOW_WARN (1 << 30)
  1079. /* For missed irq/seqno simulation. */
  1080. unsigned int test_irq_rings;
  1081. };
  1082. enum modeset_restore {
  1083. MODESET_ON_LID_OPEN,
  1084. MODESET_DONE,
  1085. MODESET_SUSPENDED,
  1086. };
  1087. struct ddi_vbt_port_info {
  1088. uint8_t hdmi_level_shift;
  1089. uint8_t supports_dvi:1;
  1090. uint8_t supports_hdmi:1;
  1091. uint8_t supports_dp:1;
  1092. };
  1093. enum drrs_support_type {
  1094. DRRS_NOT_SUPPORTED = 0,
  1095. STATIC_DRRS_SUPPORT = 1,
  1096. SEAMLESS_DRRS_SUPPORT = 2
  1097. };
  1098. struct intel_vbt_data {
  1099. struct drm_display_mode *lfp_lvds_vbt_mode; /* if any */
  1100. struct drm_display_mode *sdvo_lvds_vbt_mode; /* if any */
  1101. /* Feature bits */
  1102. unsigned int int_tv_support:1;
  1103. unsigned int lvds_dither:1;
  1104. unsigned int lvds_vbt:1;
  1105. unsigned int int_crt_support:1;
  1106. unsigned int lvds_use_ssc:1;
  1107. unsigned int display_clock_mode:1;
  1108. unsigned int fdi_rx_polarity_inverted:1;
  1109. unsigned int has_mipi:1;
  1110. int lvds_ssc_freq;
  1111. unsigned int bios_lvds_val; /* initial [PCH_]LVDS reg val in VBIOS */
  1112. enum drrs_support_type drrs_type;
  1113. /* eDP */
  1114. int edp_rate;
  1115. int edp_lanes;
  1116. int edp_preemphasis;
  1117. int edp_vswing;
  1118. bool edp_initialized;
  1119. bool edp_support;
  1120. int edp_bpp;
  1121. struct edp_power_seq edp_pps;
  1122. struct {
  1123. u16 pwm_freq_hz;
  1124. bool present;
  1125. bool active_low_pwm;
  1126. u8 min_brightness; /* min_brightness/255 of max */
  1127. } backlight;
  1128. /* MIPI DSI */
  1129. struct {
  1130. u16 port;
  1131. u16 panel_id;
  1132. struct mipi_config *config;
  1133. struct mipi_pps_data *pps;
  1134. u8 seq_version;
  1135. u32 size;
  1136. u8 *data;
  1137. u8 *sequence[MIPI_SEQ_MAX];
  1138. } dsi;
  1139. int crt_ddc_pin;
  1140. int child_dev_num;
  1141. union child_device_config *child_dev;
  1142. struct ddi_vbt_port_info ddi_port_info[I915_MAX_PORTS];
  1143. };
  1144. enum intel_ddb_partitioning {
  1145. INTEL_DDB_PART_1_2,
  1146. INTEL_DDB_PART_5_6, /* IVB+ */
  1147. };
  1148. struct intel_wm_level {
  1149. bool enable;
  1150. uint32_t pri_val;
  1151. uint32_t spr_val;
  1152. uint32_t cur_val;
  1153. uint32_t fbc_val;
  1154. };
  1155. struct ilk_wm_values {
  1156. uint32_t wm_pipe[3];
  1157. uint32_t wm_lp[3];
  1158. uint32_t wm_lp_spr[3];
  1159. uint32_t wm_linetime[3];
  1160. bool enable_fbc_wm;
  1161. enum intel_ddb_partitioning partitioning;
  1162. };
  1163. /*
  1164. * This struct helps tracking the state needed for runtime PM, which puts the
  1165. * device in PCI D3 state. Notice that when this happens, nothing on the
  1166. * graphics device works, even register access, so we don't get interrupts nor
  1167. * anything else.
  1168. *
  1169. * Every piece of our code that needs to actually touch the hardware needs to
  1170. * either call intel_runtime_pm_get or call intel_display_power_get with the
  1171. * appropriate power domain.
  1172. *
  1173. * Our driver uses the autosuspend delay feature, which means we'll only really
  1174. * suspend if we stay with zero refcount for a certain amount of time. The
  1175. * default value is currently very conservative (see intel_init_runtime_pm), but
  1176. * it can be changed with the standard runtime PM files from sysfs.
  1177. *
  1178. * The irqs_disabled variable becomes true exactly after we disable the IRQs and
  1179. * goes back to false exactly before we reenable the IRQs. We use this variable
  1180. * to check if someone is trying to enable/disable IRQs while they're supposed
  1181. * to be disabled. This shouldn't happen and we'll print some error messages in
  1182. * case it happens.
  1183. *
  1184. * For more, read the Documentation/power/runtime_pm.txt.
  1185. */
  1186. struct i915_runtime_pm {
  1187. bool suspended;
  1188. bool _irqs_disabled;
  1189. };
  1190. enum intel_pipe_crc_source {
  1191. INTEL_PIPE_CRC_SOURCE_NONE,
  1192. INTEL_PIPE_CRC_SOURCE_PLANE1,
  1193. INTEL_PIPE_CRC_SOURCE_PLANE2,
  1194. INTEL_PIPE_CRC_SOURCE_PF,
  1195. INTEL_PIPE_CRC_SOURCE_PIPE,
  1196. /* TV/DP on pre-gen5/vlv can't use the pipe source. */
  1197. INTEL_PIPE_CRC_SOURCE_TV,
  1198. INTEL_PIPE_CRC_SOURCE_DP_B,
  1199. INTEL_PIPE_CRC_SOURCE_DP_C,
  1200. INTEL_PIPE_CRC_SOURCE_DP_D,
  1201. INTEL_PIPE_CRC_SOURCE_AUTO,
  1202. INTEL_PIPE_CRC_SOURCE_MAX,
  1203. };
  1204. struct intel_pipe_crc_entry {
  1205. uint32_t frame;
  1206. uint32_t crc[5];
  1207. };
  1208. #define INTEL_PIPE_CRC_ENTRIES_NR 128
  1209. struct intel_pipe_crc {
  1210. spinlock_t lock;
  1211. bool opened; /* exclusive access to the result file */
  1212. struct intel_pipe_crc_entry *entries;
  1213. enum intel_pipe_crc_source source;
  1214. int head, tail;
  1215. wait_queue_head_t wq;
  1216. };
  1217. struct i915_frontbuffer_tracking {
  1218. struct mutex lock;
  1219. /*
  1220. * Tracking bits for delayed frontbuffer flushing du to gpu activity or
  1221. * scheduled flips.
  1222. */
  1223. unsigned busy_bits;
  1224. unsigned flip_bits;
  1225. };
  1226. struct drm_i915_private {
  1227. struct drm_device *dev;
  1228. struct kmem_cache *slab;
  1229. const struct intel_device_info info;
  1230. int relative_constants_mode;
  1231. void __iomem *regs;
  1232. struct intel_uncore uncore;
  1233. struct intel_gmbus gmbus[GMBUS_NUM_PORTS];
  1234. /** gmbus_mutex protects against concurrent usage of the single hw gmbus
  1235. * controller on different i2c buses. */
  1236. struct mutex gmbus_mutex;
  1237. /**
  1238. * Base address of the gmbus and gpio block.
  1239. */
  1240. uint32_t gpio_mmio_base;
  1241. /* MMIO base address for MIPI regs */
  1242. uint32_t mipi_mmio_base;
  1243. wait_queue_head_t gmbus_wait_queue;
  1244. struct pci_dev *bridge_dev;
  1245. struct intel_engine_cs ring[I915_NUM_RINGS];
  1246. struct drm_i915_gem_object *semaphore_obj;
  1247. uint32_t last_seqno, next_seqno;
  1248. drm_dma_handle_t *status_page_dmah;
  1249. struct resource mch_res;
  1250. /* protects the irq masks */
  1251. spinlock_t irq_lock;
  1252. /* protects the mmio flip data */
  1253. spinlock_t mmio_flip_lock;
  1254. bool display_irqs_enabled;
  1255. /* To control wakeup latency, e.g. for irq-driven dp aux transfers. */
  1256. struct pm_qos_request pm_qos;
  1257. /* DPIO indirect register protection */
  1258. struct mutex dpio_lock;
  1259. /** Cached value of IMR to avoid reads in updating the bitfield */
  1260. union {
  1261. u32 irq_mask;
  1262. u32 de_irq_mask[I915_MAX_PIPES];
  1263. };
  1264. u32 gt_irq_mask;
  1265. u32 pm_irq_mask;
  1266. u32 pm_rps_events;
  1267. u32 pipestat_irq_mask[I915_MAX_PIPES];
  1268. struct work_struct hotplug_work;
  1269. struct {
  1270. unsigned long hpd_last_jiffies;
  1271. int hpd_cnt;
  1272. enum {
  1273. HPD_ENABLED = 0,
  1274. HPD_DISABLED = 1,
  1275. HPD_MARK_DISABLED = 2
  1276. } hpd_mark;
  1277. } hpd_stats[HPD_NUM_PINS];
  1278. u32 hpd_event_bits;
  1279. struct delayed_work hotplug_reenable_work;
  1280. struct i915_fbc fbc;
  1281. struct i915_drrs drrs;
  1282. struct intel_opregion opregion;
  1283. struct intel_vbt_data vbt;
  1284. /* overlay */
  1285. struct intel_overlay *overlay;
  1286. /* backlight registers and fields in struct intel_panel */
  1287. spinlock_t backlight_lock;
  1288. /* LVDS info */
  1289. bool no_aux_handshake;
  1290. struct drm_i915_fence_reg fence_regs[I915_MAX_NUM_FENCES]; /* assume 965 */
  1291. int fence_reg_start; /* 4 if userland hasn't ioctl'd us yet */
  1292. int num_fence_regs; /* 8 on pre-965, 16 otherwise */
  1293. unsigned int fsb_freq, mem_freq, is_ddr3;
  1294. unsigned int vlv_cdclk_freq;
  1295. /**
  1296. * wq - Driver workqueue for GEM.
  1297. *
  1298. * NOTE: Work items scheduled here are not allowed to grab any modeset
  1299. * locks, for otherwise the flushing done in the pageflip code will
  1300. * result in deadlocks.
  1301. */
  1302. struct workqueue_struct *wq;
  1303. /* Display functions */
  1304. struct drm_i915_display_funcs display;
  1305. /* PCH chipset type */
  1306. enum intel_pch pch_type;
  1307. unsigned short pch_id;
  1308. unsigned long quirks;
  1309. enum modeset_restore modeset_restore;
  1310. struct mutex modeset_restore_lock;
  1311. struct list_head vm_list; /* Global list of all address spaces */
  1312. struct i915_gtt gtt; /* VM representing the global address space */
  1313. struct i915_gem_mm mm;
  1314. DECLARE_HASHTABLE(mm_structs, 7);
  1315. struct mutex mm_lock;
  1316. /* Kernel Modesetting */
  1317. struct sdvo_device_mapping sdvo_mappings[2];
  1318. struct drm_crtc *plane_to_crtc_mapping[I915_MAX_PIPES];
  1319. struct drm_crtc *pipe_to_crtc_mapping[I915_MAX_PIPES];
  1320. wait_queue_head_t pending_flip_queue;
  1321. #ifdef CONFIG_DEBUG_FS
  1322. struct intel_pipe_crc pipe_crc[I915_MAX_PIPES];
  1323. #endif
  1324. int num_shared_dpll;
  1325. struct intel_shared_dpll shared_dplls[I915_NUM_PLLS];
  1326. int dpio_phy_iosf_port[I915_NUM_PHYS_VLV];
  1327. /* Reclocking support */
  1328. bool render_reclock_avail;
  1329. bool lvds_downclock_avail;
  1330. /* indicates the reduced downclock for LVDS*/
  1331. int lvds_downclock;
  1332. struct i915_frontbuffer_tracking fb_tracking;
  1333. u16 orig_clock;
  1334. bool mchbar_need_disable;
  1335. struct intel_l3_parity l3_parity;
  1336. /* Cannot be determined by PCIID. You must always read a register. */
  1337. size_t ellc_size;
  1338. /* gen6+ rps state */
  1339. struct intel_gen6_power_mgmt rps;
  1340. /* ilk-only ips/rps state. Everything in here is protected by the global
  1341. * mchdev_lock in intel_pm.c */
  1342. struct intel_ilk_power_mgmt ips;
  1343. struct i915_power_domains power_domains;
  1344. struct i915_psr psr;
  1345. struct i915_gpu_error gpu_error;
  1346. struct drm_i915_gem_object *vlv_pctx;
  1347. #ifdef CONFIG_DRM_I915_FBDEV
  1348. /* list of fbdev register on this device */
  1349. struct intel_fbdev *fbdev;
  1350. #endif
  1351. /*
  1352. * The console may be contended at resume, but we don't
  1353. * want it to block on it.
  1354. */
  1355. struct work_struct console_resume_work;
  1356. struct drm_property *broadcast_rgb_property;
  1357. struct drm_property *force_audio_property;
  1358. uint32_t hw_context_size;
  1359. struct list_head context_list;
  1360. u32 fdi_rx_config;
  1361. u32 suspend_count;
  1362. struct i915_suspend_saved_registers regfile;
  1363. struct vlv_s0ix_state vlv_s0ix_state;
  1364. struct {
  1365. /*
  1366. * Raw watermark latency values:
  1367. * in 0.1us units for WM0,
  1368. * in 0.5us units for WM1+.
  1369. */
  1370. /* primary */
  1371. uint16_t pri_latency[5];
  1372. /* sprite */
  1373. uint16_t spr_latency[5];
  1374. /* cursor */
  1375. uint16_t cur_latency[5];
  1376. /* current hardware state */
  1377. struct ilk_wm_values hw;
  1378. } wm;
  1379. struct i915_runtime_pm pm;
  1380. struct intel_digital_port *hpd_irq_port[I915_MAX_PORTS];
  1381. u32 long_hpd_port_mask;
  1382. u32 short_hpd_port_mask;
  1383. struct work_struct dig_port_work;
  1384. /*
  1385. * if we get a HPD irq from DP and a HPD irq from non-DP
  1386. * the non-DP HPD could block the workqueue on a mode config
  1387. * mutex getting, that userspace may have taken. However
  1388. * userspace is waiting on the DP workqueue to run which is
  1389. * blocked behind the non-DP one.
  1390. */
  1391. struct workqueue_struct *dp_wq;
  1392. /* Old dri1 support infrastructure, beware the dragons ya fools entering
  1393. * here! */
  1394. struct i915_dri1_state dri1;
  1395. /* Old ums support infrastructure, same warning applies. */
  1396. struct i915_ums_state ums;
  1397. /*
  1398. * NOTE: This is the dri1/ums dungeon, don't add stuff here. Your patch
  1399. * will be rejected. Instead look for a better place.
  1400. */
  1401. };
  1402. static inline struct drm_i915_private *to_i915(const struct drm_device *dev)
  1403. {
  1404. return dev->dev_private;
  1405. }
  1406. /* Iterate over initialised rings */
  1407. #define for_each_ring(ring__, dev_priv__, i__) \
  1408. for ((i__) = 0; (i__) < I915_NUM_RINGS; (i__)++) \
  1409. if (((ring__) = &(dev_priv__)->ring[(i__)]), intel_ring_initialized((ring__)))
  1410. enum hdmi_force_audio {
  1411. HDMI_AUDIO_OFF_DVI = -2, /* no aux data for HDMI-DVI converter */
  1412. HDMI_AUDIO_OFF, /* force turn off HDMI audio */
  1413. HDMI_AUDIO_AUTO, /* trust EDID */
  1414. HDMI_AUDIO_ON, /* force turn on HDMI audio */
  1415. };
  1416. #define I915_GTT_OFFSET_NONE ((u32)-1)
  1417. struct drm_i915_gem_object_ops {
  1418. /* Interface between the GEM object and its backing storage.
  1419. * get_pages() is called once prior to the use of the associated set
  1420. * of pages before to binding them into the GTT, and put_pages() is
  1421. * called after we no longer need them. As we expect there to be
  1422. * associated cost with migrating pages between the backing storage
  1423. * and making them available for the GPU (e.g. clflush), we may hold
  1424. * onto the pages after they are no longer referenced by the GPU
  1425. * in case they may be used again shortly (for example migrating the
  1426. * pages to a different memory domain within the GTT). put_pages()
  1427. * will therefore most likely be called when the object itself is
  1428. * being released or under memory pressure (where we attempt to
  1429. * reap pages for the shrinker).
  1430. */
  1431. int (*get_pages)(struct drm_i915_gem_object *);
  1432. void (*put_pages)(struct drm_i915_gem_object *);
  1433. int (*dmabuf_export)(struct drm_i915_gem_object *);
  1434. void (*release)(struct drm_i915_gem_object *);
  1435. };
  1436. /*
  1437. * Frontbuffer tracking bits. Set in obj->frontbuffer_bits while a gem bo is
  1438. * considered to be the frontbuffer for the given plane interface-vise. This
  1439. * doesn't mean that the hw necessarily already scans it out, but that any
  1440. * rendering (by the cpu or gpu) will land in the frontbuffer eventually.
  1441. *
  1442. * We have one bit per pipe and per scanout plane type.
  1443. */
  1444. #define INTEL_FRONTBUFFER_BITS_PER_PIPE 4
  1445. #define INTEL_FRONTBUFFER_BITS \
  1446. (INTEL_FRONTBUFFER_BITS_PER_PIPE * I915_MAX_PIPES)
  1447. #define INTEL_FRONTBUFFER_PRIMARY(pipe) \
  1448. (1 << (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe)))
  1449. #define INTEL_FRONTBUFFER_CURSOR(pipe) \
  1450. (1 << (1 +(INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))))
  1451. #define INTEL_FRONTBUFFER_SPRITE(pipe) \
  1452. (1 << (2 +(INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))))
  1453. #define INTEL_FRONTBUFFER_OVERLAY(pipe) \
  1454. (1 << (3 +(INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))))
  1455. #define INTEL_FRONTBUFFER_ALL_MASK(pipe) \
  1456. (0xf << (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe)))
  1457. struct drm_i915_gem_object {
  1458. struct drm_gem_object base;
  1459. const struct drm_i915_gem_object_ops *ops;
  1460. /** List of VMAs backed by this object */
  1461. struct list_head vma_list;
  1462. /** Stolen memory for this object, instead of being backed by shmem. */
  1463. struct drm_mm_node *stolen;
  1464. struct list_head global_list;
  1465. struct list_head ring_list;
  1466. /** Used in execbuf to temporarily hold a ref */
  1467. struct list_head obj_exec_link;
  1468. /**
  1469. * This is set if the object is on the active lists (has pending
  1470. * rendering and so a non-zero seqno), and is not set if it i s on
  1471. * inactive (ready to be unbound) list.
  1472. */
  1473. unsigned int active:1;
  1474. /**
  1475. * This is set if the object has been written to since last bound
  1476. * to the GTT
  1477. */
  1478. unsigned int dirty:1;
  1479. /**
  1480. * Fence register bits (if any) for this object. Will be set
  1481. * as needed when mapped into the GTT.
  1482. * Protected by dev->struct_mutex.
  1483. */
  1484. signed int fence_reg:I915_MAX_NUM_FENCE_BITS;
  1485. /**
  1486. * Advice: are the backing pages purgeable?
  1487. */
  1488. unsigned int madv:2;
  1489. /**
  1490. * Current tiling mode for the object.
  1491. */
  1492. unsigned int tiling_mode:2;
  1493. /**
  1494. * Whether the tiling parameters for the currently associated fence
  1495. * register have changed. Note that for the purposes of tracking
  1496. * tiling changes we also treat the unfenced register, the register
  1497. * slot that the object occupies whilst it executes a fenced
  1498. * command (such as BLT on gen2/3), as a "fence".
  1499. */
  1500. unsigned int fence_dirty:1;
  1501. /**
  1502. * Is the object at the current location in the gtt mappable and
  1503. * fenceable? Used to avoid costly recalculations.
  1504. */
  1505. unsigned int map_and_fenceable:1;
  1506. /**
  1507. * Whether the current gtt mapping needs to be mappable (and isn't just
  1508. * mappable by accident). Track pin and fault separate for a more
  1509. * accurate mappable working set.
  1510. */
  1511. unsigned int fault_mappable:1;
  1512. unsigned int pin_mappable:1;
  1513. unsigned int pin_display:1;
  1514. /*
  1515. * Is the object to be mapped as read-only to the GPU
  1516. * Only honoured if hardware has relevant pte bit
  1517. */
  1518. unsigned long gt_ro:1;
  1519. /*
  1520. * Is the GPU currently using a fence to access this buffer,
  1521. */
  1522. unsigned int pending_fenced_gpu_access:1;
  1523. unsigned int fenced_gpu_access:1;
  1524. unsigned int cache_level:3;
  1525. unsigned int has_aliasing_ppgtt_mapping:1;
  1526. unsigned int has_global_gtt_mapping:1;
  1527. unsigned int has_dma_mapping:1;
  1528. unsigned int frontbuffer_bits:INTEL_FRONTBUFFER_BITS;
  1529. struct sg_table *pages;
  1530. int pages_pin_count;
  1531. /* prime dma-buf support */
  1532. void *dma_buf_vmapping;
  1533. int vmapping_count;
  1534. struct intel_engine_cs *ring;
  1535. /** Breadcrumb of last rendering to the buffer. */
  1536. uint32_t last_read_seqno;
  1537. uint32_t last_write_seqno;
  1538. /** Breadcrumb of last fenced GPU access to the buffer. */
  1539. uint32_t last_fenced_seqno;
  1540. /** Current tiling stride for the object, if it's tiled. */
  1541. uint32_t stride;
  1542. /** References from framebuffers, locks out tiling changes. */
  1543. unsigned long framebuffer_references;
  1544. /** Record of address bit 17 of each page at last unbind. */
  1545. unsigned long *bit_17;
  1546. /** User space pin count and filp owning the pin */
  1547. unsigned long user_pin_count;
  1548. struct drm_file *pin_filp;
  1549. /** for phy allocated objects */
  1550. drm_dma_handle_t *phys_handle;
  1551. union {
  1552. struct i915_gem_userptr {
  1553. uintptr_t ptr;
  1554. unsigned read_only :1;
  1555. unsigned workers :4;
  1556. #define I915_GEM_USERPTR_MAX_WORKERS 15
  1557. struct i915_mm_struct *mm;
  1558. struct i915_mmu_object *mmu_object;
  1559. struct work_struct *work;
  1560. } userptr;
  1561. };
  1562. };
  1563. #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
  1564. void i915_gem_track_fb(struct drm_i915_gem_object *old,
  1565. struct drm_i915_gem_object *new,
  1566. unsigned frontbuffer_bits);
  1567. /**
  1568. * Request queue structure.
  1569. *
  1570. * The request queue allows us to note sequence numbers that have been emitted
  1571. * and may be associated with active buffers to be retired.
  1572. *
  1573. * By keeping this list, we can avoid having to do questionable
  1574. * sequence-number comparisons on buffer last_rendering_seqnos, and associate
  1575. * an emission time with seqnos for tracking how far ahead of the GPU we are.
  1576. */
  1577. struct drm_i915_gem_request {
  1578. /** On Which ring this request was generated */
  1579. struct intel_engine_cs *ring;
  1580. /** GEM sequence number associated with this request. */
  1581. uint32_t seqno;
  1582. /** Position in the ringbuffer of the start of the request */
  1583. u32 head;
  1584. /** Position in the ringbuffer of the end of the request */
  1585. u32 tail;
  1586. /** Context related to this request */
  1587. struct intel_context *ctx;
  1588. /** Batch buffer related to this request if any */
  1589. struct drm_i915_gem_object *batch_obj;
  1590. /** Time at which this request was emitted, in jiffies. */
  1591. unsigned long emitted_jiffies;
  1592. /** global list entry for this request */
  1593. struct list_head list;
  1594. struct drm_i915_file_private *file_priv;
  1595. /** file_priv list entry for this request */
  1596. struct list_head client_list;
  1597. };
  1598. struct drm_i915_file_private {
  1599. struct drm_i915_private *dev_priv;
  1600. struct drm_file *file;
  1601. struct {
  1602. spinlock_t lock;
  1603. struct list_head request_list;
  1604. struct delayed_work idle_work;
  1605. } mm;
  1606. struct idr context_idr;
  1607. atomic_t rps_wait_boost;
  1608. struct intel_engine_cs *bsd_ring;
  1609. };
  1610. /*
  1611. * A command that requires special handling by the command parser.
  1612. */
  1613. struct drm_i915_cmd_descriptor {
  1614. /*
  1615. * Flags describing how the command parser processes the command.
  1616. *
  1617. * CMD_DESC_FIXED: The command has a fixed length if this is set,
  1618. * a length mask if not set
  1619. * CMD_DESC_SKIP: The command is allowed but does not follow the
  1620. * standard length encoding for the opcode range in
  1621. * which it falls
  1622. * CMD_DESC_REJECT: The command is never allowed
  1623. * CMD_DESC_REGISTER: The command should be checked against the
  1624. * register whitelist for the appropriate ring
  1625. * CMD_DESC_MASTER: The command is allowed if the submitting process
  1626. * is the DRM master
  1627. */
  1628. u32 flags;
  1629. #define CMD_DESC_FIXED (1<<0)
  1630. #define CMD_DESC_SKIP (1<<1)
  1631. #define CMD_DESC_REJECT (1<<2)
  1632. #define CMD_DESC_REGISTER (1<<3)
  1633. #define CMD_DESC_BITMASK (1<<4)
  1634. #define CMD_DESC_MASTER (1<<5)
  1635. /*
  1636. * The command's unique identification bits and the bitmask to get them.
  1637. * This isn't strictly the opcode field as defined in the spec and may
  1638. * also include type, subtype, and/or subop fields.
  1639. */
  1640. struct {
  1641. u32 value;
  1642. u32 mask;
  1643. } cmd;
  1644. /*
  1645. * The command's length. The command is either fixed length (i.e. does
  1646. * not include a length field) or has a length field mask. The flag
  1647. * CMD_DESC_FIXED indicates a fixed length. Otherwise, the command has
  1648. * a length mask. All command entries in a command table must include
  1649. * length information.
  1650. */
  1651. union {
  1652. u32 fixed;
  1653. u32 mask;
  1654. } length;
  1655. /*
  1656. * Describes where to find a register address in the command to check
  1657. * against the ring's register whitelist. Only valid if flags has the
  1658. * CMD_DESC_REGISTER bit set.
  1659. */
  1660. struct {
  1661. u32 offset;
  1662. u32 mask;
  1663. } reg;
  1664. #define MAX_CMD_DESC_BITMASKS 3
  1665. /*
  1666. * Describes command checks where a particular dword is masked and
  1667. * compared against an expected value. If the command does not match
  1668. * the expected value, the parser rejects it. Only valid if flags has
  1669. * the CMD_DESC_BITMASK bit set. Only entries where mask is non-zero
  1670. * are valid.
  1671. *
  1672. * If the check specifies a non-zero condition_mask then the parser
  1673. * only performs the check when the bits specified by condition_mask
  1674. * are non-zero.
  1675. */
  1676. struct {
  1677. u32 offset;
  1678. u32 mask;
  1679. u32 expected;
  1680. u32 condition_offset;
  1681. u32 condition_mask;
  1682. } bits[MAX_CMD_DESC_BITMASKS];
  1683. };
  1684. /*
  1685. * A table of commands requiring special handling by the command parser.
  1686. *
  1687. * Each ring has an array of tables. Each table consists of an array of command
  1688. * descriptors, which must be sorted with command opcodes in ascending order.
  1689. */
  1690. struct drm_i915_cmd_table {
  1691. const struct drm_i915_cmd_descriptor *table;
  1692. int count;
  1693. };
  1694. #define INTEL_INFO(dev) (&to_i915(dev)->info)
  1695. #define IS_I830(dev) ((dev)->pdev->device == 0x3577)
  1696. #define IS_845G(dev) ((dev)->pdev->device == 0x2562)
  1697. #define IS_I85X(dev) (INTEL_INFO(dev)->is_i85x)
  1698. #define IS_I865G(dev) ((dev)->pdev->device == 0x2572)
  1699. #define IS_I915G(dev) (INTEL_INFO(dev)->is_i915g)
  1700. #define IS_I915GM(dev) ((dev)->pdev->device == 0x2592)
  1701. #define IS_I945G(dev) ((dev)->pdev->device == 0x2772)
  1702. #define IS_I945GM(dev) (INTEL_INFO(dev)->is_i945gm)
  1703. #define IS_BROADWATER(dev) (INTEL_INFO(dev)->is_broadwater)
  1704. #define IS_CRESTLINE(dev) (INTEL_INFO(dev)->is_crestline)
  1705. #define IS_GM45(dev) ((dev)->pdev->device == 0x2A42)
  1706. #define IS_G4X(dev) (INTEL_INFO(dev)->is_g4x)
  1707. #define IS_PINEVIEW_G(dev) ((dev)->pdev->device == 0xa001)
  1708. #define IS_PINEVIEW_M(dev) ((dev)->pdev->device == 0xa011)
  1709. #define IS_PINEVIEW(dev) (INTEL_INFO(dev)->is_pineview)
  1710. #define IS_G33(dev) (INTEL_INFO(dev)->is_g33)
  1711. #define IS_IRONLAKE_M(dev) ((dev)->pdev->device == 0x0046)
  1712. #define IS_IVYBRIDGE(dev) (INTEL_INFO(dev)->is_ivybridge)
  1713. #define IS_IVB_GT1(dev) ((dev)->pdev->device == 0x0156 || \
  1714. (dev)->pdev->device == 0x0152 || \
  1715. (dev)->pdev->device == 0x015a)
  1716. #define IS_SNB_GT1(dev) ((dev)->pdev->device == 0x0102 || \
  1717. (dev)->pdev->device == 0x0106 || \
  1718. (dev)->pdev->device == 0x010A)
  1719. #define IS_VALLEYVIEW(dev) (INTEL_INFO(dev)->is_valleyview)
  1720. #define IS_CHERRYVIEW(dev) (INTEL_INFO(dev)->is_valleyview && IS_GEN8(dev))
  1721. #define IS_HASWELL(dev) (INTEL_INFO(dev)->is_haswell)
  1722. #define IS_BROADWELL(dev) (!INTEL_INFO(dev)->is_valleyview && IS_GEN8(dev))
  1723. #define IS_MOBILE(dev) (INTEL_INFO(dev)->is_mobile)
  1724. #define IS_HSW_EARLY_SDV(dev) (IS_HASWELL(dev) && \
  1725. ((dev)->pdev->device & 0xFF00) == 0x0C00)
  1726. #define IS_BDW_ULT(dev) (IS_BROADWELL(dev) && \
  1727. (((dev)->pdev->device & 0xf) == 0x2 || \
  1728. ((dev)->pdev->device & 0xf) == 0x6 || \
  1729. ((dev)->pdev->device & 0xf) == 0xe))
  1730. #define IS_HSW_ULT(dev) (IS_HASWELL(dev) && \
  1731. ((dev)->pdev->device & 0xFF00) == 0x0A00)
  1732. #define IS_ULT(dev) (IS_HSW_ULT(dev) || IS_BDW_ULT(dev))
  1733. #define IS_HSW_GT3(dev) (IS_HASWELL(dev) && \
  1734. ((dev)->pdev->device & 0x00F0) == 0x0020)
  1735. /* ULX machines are also considered ULT. */
  1736. #define IS_HSW_ULX(dev) ((dev)->pdev->device == 0x0A0E || \
  1737. (dev)->pdev->device == 0x0A1E)
  1738. #define IS_PRELIMINARY_HW(intel_info) ((intel_info)->is_preliminary)
  1739. /*
  1740. * The genX designation typically refers to the render engine, so render
  1741. * capability related checks should use IS_GEN, while display and other checks
  1742. * have their own (e.g. HAS_PCH_SPLIT for ILK+ display, IS_foo for particular
  1743. * chips, etc.).
  1744. */
  1745. #define IS_GEN2(dev) (INTEL_INFO(dev)->gen == 2)
  1746. #define IS_GEN3(dev) (INTEL_INFO(dev)->gen == 3)
  1747. #define IS_GEN4(dev) (INTEL_INFO(dev)->gen == 4)
  1748. #define IS_GEN5(dev) (INTEL_INFO(dev)->gen == 5)
  1749. #define IS_GEN6(dev) (INTEL_INFO(dev)->gen == 6)
  1750. #define IS_GEN7(dev) (INTEL_INFO(dev)->gen == 7)
  1751. #define IS_GEN8(dev) (INTEL_INFO(dev)->gen == 8)
  1752. #define RENDER_RING (1<<RCS)
  1753. #define BSD_RING (1<<VCS)
  1754. #define BLT_RING (1<<BCS)
  1755. #define VEBOX_RING (1<<VECS)
  1756. #define BSD2_RING (1<<VCS2)
  1757. #define HAS_BSD(dev) (INTEL_INFO(dev)->ring_mask & BSD_RING)
  1758. #define HAS_BSD2(dev) (INTEL_INFO(dev)->ring_mask & BSD2_RING)
  1759. #define HAS_BLT(dev) (INTEL_INFO(dev)->ring_mask & BLT_RING)
  1760. #define HAS_VEBOX(dev) (INTEL_INFO(dev)->ring_mask & VEBOX_RING)
  1761. #define HAS_LLC(dev) (INTEL_INFO(dev)->has_llc)
  1762. #define HAS_WT(dev) ((IS_HASWELL(dev) || IS_BROADWELL(dev)) && \
  1763. to_i915(dev)->ellc_size)
  1764. #define I915_NEED_GFX_HWS(dev) (INTEL_INFO(dev)->need_gfx_hws)
  1765. #define HAS_HW_CONTEXTS(dev) (INTEL_INFO(dev)->gen >= 6)
  1766. #define HAS_ALIASING_PPGTT(dev) (INTEL_INFO(dev)->gen >= 6)
  1767. #define HAS_PPGTT(dev) (INTEL_INFO(dev)->gen >= 7 && !IS_GEN8(dev))
  1768. #define USES_PPGTT(dev) intel_enable_ppgtt(dev, false)
  1769. #define USES_FULL_PPGTT(dev) intel_enable_ppgtt(dev, true)
  1770. #define HAS_OVERLAY(dev) (INTEL_INFO(dev)->has_overlay)
  1771. #define OVERLAY_NEEDS_PHYSICAL(dev) (INTEL_INFO(dev)->overlay_needs_physical)
  1772. /* Early gen2 have a totally busted CS tlb and require pinned batches. */
  1773. #define HAS_BROKEN_CS_TLB(dev) (IS_I830(dev) || IS_845G(dev))
  1774. /*
  1775. * dp aux and gmbus irq on gen4 seems to be able to generate legacy interrupts
  1776. * even when in MSI mode. This results in spurious interrupt warnings if the
  1777. * legacy irq no. is shared with another device. The kernel then disables that
  1778. * interrupt source and so prevents the other device from working properly.
  1779. */
  1780. #define HAS_AUX_IRQ(dev) (INTEL_INFO(dev)->gen >= 5)
  1781. #define HAS_GMBUS_IRQ(dev) (INTEL_INFO(dev)->gen >= 5)
  1782. /* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte
  1783. * rows, which changed the alignment requirements and fence programming.
  1784. */
  1785. #define HAS_128_BYTE_Y_TILING(dev) (!IS_GEN2(dev) && !(IS_I915G(dev) || \
  1786. IS_I915GM(dev)))
  1787. #define SUPPORTS_DIGITAL_OUTPUTS(dev) (!IS_GEN2(dev) && !IS_PINEVIEW(dev))
  1788. #define SUPPORTS_INTEGRATED_HDMI(dev) (IS_G4X(dev) || IS_GEN5(dev))
  1789. #define SUPPORTS_INTEGRATED_DP(dev) (IS_G4X(dev) || IS_GEN5(dev))
  1790. #define SUPPORTS_TV(dev) (INTEL_INFO(dev)->supports_tv)
  1791. #define I915_HAS_HOTPLUG(dev) (INTEL_INFO(dev)->has_hotplug)
  1792. #define HAS_FW_BLC(dev) (INTEL_INFO(dev)->gen > 2)
  1793. #define HAS_PIPE_CXSR(dev) (INTEL_INFO(dev)->has_pipe_cxsr)
  1794. #define HAS_FBC(dev) (INTEL_INFO(dev)->has_fbc)
  1795. #define HAS_IPS(dev) (IS_ULT(dev) || IS_BROADWELL(dev))
  1796. #define HAS_DDI(dev) (INTEL_INFO(dev)->has_ddi)
  1797. #define HAS_FPGA_DBG_UNCLAIMED(dev) (INTEL_INFO(dev)->has_fpga_dbg)
  1798. #define HAS_PSR(dev) (IS_HASWELL(dev) || IS_BROADWELL(dev))
  1799. #define HAS_RUNTIME_PM(dev) (IS_GEN6(dev) || IS_HASWELL(dev) || \
  1800. IS_BROADWELL(dev) || IS_VALLEYVIEW(dev))
  1801. #define INTEL_PCH_DEVICE_ID_MASK 0xff00
  1802. #define INTEL_PCH_IBX_DEVICE_ID_TYPE 0x3b00
  1803. #define INTEL_PCH_CPT_DEVICE_ID_TYPE 0x1c00
  1804. #define INTEL_PCH_PPT_DEVICE_ID_TYPE 0x1e00
  1805. #define INTEL_PCH_LPT_DEVICE_ID_TYPE 0x8c00
  1806. #define INTEL_PCH_LPT_LP_DEVICE_ID_TYPE 0x9c00
  1807. #define INTEL_PCH_TYPE(dev) (to_i915(dev)->pch_type)
  1808. #define HAS_PCH_LPT(dev) (INTEL_PCH_TYPE(dev) == PCH_LPT)
  1809. #define HAS_PCH_CPT(dev) (INTEL_PCH_TYPE(dev) == PCH_CPT)
  1810. #define HAS_PCH_IBX(dev) (INTEL_PCH_TYPE(dev) == PCH_IBX)
  1811. #define HAS_PCH_NOP(dev) (INTEL_PCH_TYPE(dev) == PCH_NOP)
  1812. #define HAS_PCH_SPLIT(dev) (INTEL_PCH_TYPE(dev) != PCH_NONE)
  1813. #define HAS_GMCH_DISPLAY(dev) (INTEL_INFO(dev)->gen < 5 || IS_VALLEYVIEW(dev))
  1814. /* DPF == dynamic parity feature */
  1815. #define HAS_L3_DPF(dev) (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
  1816. #define NUM_L3_SLICES(dev) (IS_HSW_GT3(dev) ? 2 : HAS_L3_DPF(dev))
  1817. #define GT_FREQUENCY_MULTIPLIER 50
  1818. #include "i915_trace.h"
  1819. extern const struct drm_ioctl_desc i915_ioctls[];
  1820. extern int i915_max_ioctl;
  1821. extern int i915_suspend(struct drm_device *dev, pm_message_t state);
  1822. extern int i915_resume(struct drm_device *dev);
  1823. extern int i915_master_create(struct drm_device *dev, struct drm_master *master);
  1824. extern void i915_master_destroy(struct drm_device *dev, struct drm_master *master);
  1825. /* i915_params.c */
  1826. struct i915_params {
  1827. int modeset;
  1828. int panel_ignore_lid;
  1829. unsigned int powersave;
  1830. int semaphores;
  1831. unsigned int lvds_downclock;
  1832. int lvds_channel_mode;
  1833. int panel_use_ssc;
  1834. int vbt_sdvo_panel_type;
  1835. int enable_rc6;
  1836. int enable_fbc;
  1837. int enable_ppgtt;
  1838. int enable_psr;
  1839. unsigned int preliminary_hw_support;
  1840. int disable_power_well;
  1841. int enable_ips;
  1842. int invert_brightness;
  1843. int enable_cmd_parser;
  1844. /* leave bools at the end to not create holes */
  1845. bool enable_hangcheck;
  1846. bool fastboot;
  1847. bool prefault_disable;
  1848. bool reset;
  1849. bool disable_display;
  1850. bool disable_vtd_wa;
  1851. int use_mmio_flip;
  1852. bool mmio_debug;
  1853. };
  1854. extern struct i915_params i915 __read_mostly;
  1855. /* i915_dma.c */
  1856. void i915_update_dri1_breadcrumb(struct drm_device *dev);
  1857. extern void i915_kernel_lost_context(struct drm_device * dev);
  1858. extern int i915_driver_load(struct drm_device *, unsigned long flags);
  1859. extern int i915_driver_unload(struct drm_device *);
  1860. extern int i915_driver_open(struct drm_device *dev, struct drm_file *file);
  1861. extern void i915_driver_lastclose(struct drm_device * dev);
  1862. extern void i915_driver_preclose(struct drm_device *dev,
  1863. struct drm_file *file);
  1864. extern void i915_driver_postclose(struct drm_device *dev,
  1865. struct drm_file *file);
  1866. extern int i915_driver_device_is_agp(struct drm_device * dev);
  1867. #ifdef CONFIG_COMPAT
  1868. extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
  1869. unsigned long arg);
  1870. #endif
  1871. extern int i915_emit_box(struct drm_device *dev,
  1872. struct drm_clip_rect *box,
  1873. int DR1, int DR4);
  1874. extern int intel_gpu_reset(struct drm_device *dev);
  1875. extern int i915_reset(struct drm_device *dev);
  1876. extern unsigned long i915_chipset_val(struct drm_i915_private *dev_priv);
  1877. extern unsigned long i915_mch_val(struct drm_i915_private *dev_priv);
  1878. extern unsigned long i915_gfx_val(struct drm_i915_private *dev_priv);
  1879. extern void i915_update_gfx_val(struct drm_i915_private *dev_priv);
  1880. int vlv_force_gfx_clock(struct drm_i915_private *dev_priv, bool on);
  1881. void intel_hpd_cancel_work(struct drm_i915_private *dev_priv);
  1882. extern void intel_console_resume(struct work_struct *work);
  1883. /* i915_irq.c */
  1884. void i915_queue_hangcheck(struct drm_device *dev);
  1885. __printf(3, 4)
  1886. void i915_handle_error(struct drm_device *dev, bool wedged,
  1887. const char *fmt, ...);
  1888. void gen6_set_pm_mask(struct drm_i915_private *dev_priv, u32 pm_iir,
  1889. int new_delay);
  1890. extern void intel_irq_init(struct drm_device *dev);
  1891. extern void intel_hpd_init(struct drm_device *dev);
  1892. extern void intel_uncore_sanitize(struct drm_device *dev);
  1893. extern void intel_uncore_early_sanitize(struct drm_device *dev,
  1894. bool restore_forcewake);
  1895. extern void intel_uncore_init(struct drm_device *dev);
  1896. extern void intel_uncore_check_errors(struct drm_device *dev);
  1897. extern void intel_uncore_fini(struct drm_device *dev);
  1898. extern void intel_uncore_forcewake_reset(struct drm_device *dev, bool restore);
  1899. void
  1900. i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  1901. u32 status_mask);
  1902. void
  1903. i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  1904. u32 status_mask);
  1905. void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv);
  1906. void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv);
  1907. /* i915_gem.c */
  1908. int i915_gem_init_ioctl(struct drm_device *dev, void *data,
  1909. struct drm_file *file_priv);
  1910. int i915_gem_create_ioctl(struct drm_device *dev, void *data,
  1911. struct drm_file *file_priv);
  1912. int i915_gem_pread_ioctl(struct drm_device *dev, void *data,
  1913. struct drm_file *file_priv);
  1914. int i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  1915. struct drm_file *file_priv);
  1916. int i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
  1917. struct drm_file *file_priv);
  1918. int i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data,
  1919. struct drm_file *file_priv);
  1920. int i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  1921. struct drm_file *file_priv);
  1922. int i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
  1923. struct drm_file *file_priv);
  1924. int i915_gem_execbuffer(struct drm_device *dev, void *data,
  1925. struct drm_file *file_priv);
  1926. int i915_gem_execbuffer2(struct drm_device *dev, void *data,
  1927. struct drm_file *file_priv);
  1928. int i915_gem_pin_ioctl(struct drm_device *dev, void *data,
  1929. struct drm_file *file_priv);
  1930. int i915_gem_unpin_ioctl(struct drm_device *dev, void *data,
  1931. struct drm_file *file_priv);
  1932. int i915_gem_busy_ioctl(struct drm_device *dev, void *data,
  1933. struct drm_file *file_priv);
  1934. int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data,
  1935. struct drm_file *file);
  1936. int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
  1937. struct drm_file *file);
  1938. int i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
  1939. struct drm_file *file_priv);
  1940. int i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
  1941. struct drm_file *file_priv);
  1942. int i915_gem_entervt_ioctl(struct drm_device *dev, void *data,
  1943. struct drm_file *file_priv);
  1944. int i915_gem_leavevt_ioctl(struct drm_device *dev, void *data,
  1945. struct drm_file *file_priv);
  1946. int i915_gem_set_tiling(struct drm_device *dev, void *data,
  1947. struct drm_file *file_priv);
  1948. int i915_gem_get_tiling(struct drm_device *dev, void *data,
  1949. struct drm_file *file_priv);
  1950. int i915_gem_init_userptr(struct drm_device *dev);
  1951. int i915_gem_userptr_ioctl(struct drm_device *dev, void *data,
  1952. struct drm_file *file);
  1953. int i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
  1954. struct drm_file *file_priv);
  1955. int i915_gem_wait_ioctl(struct drm_device *dev, void *data,
  1956. struct drm_file *file_priv);
  1957. void i915_gem_load(struct drm_device *dev);
  1958. void *i915_gem_object_alloc(struct drm_device *dev);
  1959. void i915_gem_object_free(struct drm_i915_gem_object *obj);
  1960. void i915_gem_object_init(struct drm_i915_gem_object *obj,
  1961. const struct drm_i915_gem_object_ops *ops);
  1962. struct drm_i915_gem_object *i915_gem_alloc_object(struct drm_device *dev,
  1963. size_t size);
  1964. void i915_init_vm(struct drm_i915_private *dev_priv,
  1965. struct i915_address_space *vm);
  1966. void i915_gem_free_object(struct drm_gem_object *obj);
  1967. void i915_gem_vma_destroy(struct i915_vma *vma);
  1968. #define PIN_MAPPABLE 0x1
  1969. #define PIN_NONBLOCK 0x2
  1970. #define PIN_GLOBAL 0x4
  1971. #define PIN_OFFSET_BIAS 0x8
  1972. #define PIN_OFFSET_MASK (~4095)
  1973. int __must_check i915_gem_object_pin(struct drm_i915_gem_object *obj,
  1974. struct i915_address_space *vm,
  1975. uint32_t alignment,
  1976. uint64_t flags);
  1977. int __must_check i915_vma_unbind(struct i915_vma *vma);
  1978. int i915_gem_object_put_pages(struct drm_i915_gem_object *obj);
  1979. void i915_gem_release_all_mmaps(struct drm_i915_private *dev_priv);
  1980. void i915_gem_release_mmap(struct drm_i915_gem_object *obj);
  1981. void i915_gem_lastclose(struct drm_device *dev);
  1982. int i915_gem_obj_prepare_shmem_read(struct drm_i915_gem_object *obj,
  1983. int *needs_clflush);
  1984. int __must_check i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
  1985. static inline struct page *i915_gem_object_get_page(struct drm_i915_gem_object *obj, int n)
  1986. {
  1987. struct sg_page_iter sg_iter;
  1988. for_each_sg_page(obj->pages->sgl, &sg_iter, obj->pages->nents, n)
  1989. return sg_page_iter_page(&sg_iter);
  1990. return NULL;
  1991. }
  1992. static inline void i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
  1993. {
  1994. BUG_ON(obj->pages == NULL);
  1995. obj->pages_pin_count++;
  1996. }
  1997. static inline void i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj)
  1998. {
  1999. BUG_ON(obj->pages_pin_count == 0);
  2000. obj->pages_pin_count--;
  2001. }
  2002. int __must_check i915_mutex_lock_interruptible(struct drm_device *dev);
  2003. int i915_gem_object_sync(struct drm_i915_gem_object *obj,
  2004. struct intel_engine_cs *to);
  2005. void i915_vma_move_to_active(struct i915_vma *vma,
  2006. struct intel_engine_cs *ring);
  2007. int i915_gem_dumb_create(struct drm_file *file_priv,
  2008. struct drm_device *dev,
  2009. struct drm_mode_create_dumb *args);
  2010. int i915_gem_mmap_gtt(struct drm_file *file_priv, struct drm_device *dev,
  2011. uint32_t handle, uint64_t *offset);
  2012. /**
  2013. * Returns true if seq1 is later than seq2.
  2014. */
  2015. static inline bool
  2016. i915_seqno_passed(uint32_t seq1, uint32_t seq2)
  2017. {
  2018. return (int32_t)(seq1 - seq2) >= 0;
  2019. }
  2020. int __must_check i915_gem_get_seqno(struct drm_device *dev, u32 *seqno);
  2021. int __must_check i915_gem_set_seqno(struct drm_device *dev, u32 seqno);
  2022. int __must_check i915_gem_object_get_fence(struct drm_i915_gem_object *obj);
  2023. int __must_check i915_gem_object_put_fence(struct drm_i915_gem_object *obj);
  2024. bool i915_gem_object_pin_fence(struct drm_i915_gem_object *obj);
  2025. void i915_gem_object_unpin_fence(struct drm_i915_gem_object *obj);
  2026. struct drm_i915_gem_request *
  2027. i915_gem_find_active_request(struct intel_engine_cs *ring);
  2028. bool i915_gem_retire_requests(struct drm_device *dev);
  2029. void i915_gem_retire_requests_ring(struct intel_engine_cs *ring);
  2030. int __must_check i915_gem_check_wedge(struct i915_gpu_error *error,
  2031. bool interruptible);
  2032. int __must_check i915_gem_check_olr(struct intel_engine_cs *ring, u32 seqno);
  2033. static inline bool i915_reset_in_progress(struct i915_gpu_error *error)
  2034. {
  2035. return unlikely(atomic_read(&error->reset_counter)
  2036. & (I915_RESET_IN_PROGRESS_FLAG | I915_WEDGED));
  2037. }
  2038. static inline bool i915_terminally_wedged(struct i915_gpu_error *error)
  2039. {
  2040. return atomic_read(&error->reset_counter) & I915_WEDGED;
  2041. }
  2042. static inline u32 i915_reset_count(struct i915_gpu_error *error)
  2043. {
  2044. return ((atomic_read(&error->reset_counter) & ~I915_WEDGED) + 1) / 2;
  2045. }
  2046. static inline bool i915_stop_ring_allow_ban(struct drm_i915_private *dev_priv)
  2047. {
  2048. return dev_priv->gpu_error.stop_rings == 0 ||
  2049. dev_priv->gpu_error.stop_rings & I915_STOP_RING_ALLOW_BAN;
  2050. }
  2051. static inline bool i915_stop_ring_allow_warn(struct drm_i915_private *dev_priv)
  2052. {
  2053. return dev_priv->gpu_error.stop_rings == 0 ||
  2054. dev_priv->gpu_error.stop_rings & I915_STOP_RING_ALLOW_WARN;
  2055. }
  2056. void i915_gem_reset(struct drm_device *dev);
  2057. bool i915_gem_clflush_object(struct drm_i915_gem_object *obj, bool force);
  2058. int __must_check i915_gem_object_finish_gpu(struct drm_i915_gem_object *obj);
  2059. int __must_check i915_gem_init(struct drm_device *dev);
  2060. int __must_check i915_gem_init_hw(struct drm_device *dev);
  2061. int i915_gem_l3_remap(struct intel_engine_cs *ring, int slice);
  2062. void i915_gem_init_swizzling(struct drm_device *dev);
  2063. void i915_gem_cleanup_ringbuffer(struct drm_device *dev);
  2064. int __must_check i915_gpu_idle(struct drm_device *dev);
  2065. int __must_check i915_gem_suspend(struct drm_device *dev);
  2066. int __i915_add_request(struct intel_engine_cs *ring,
  2067. struct drm_file *file,
  2068. struct drm_i915_gem_object *batch_obj,
  2069. u32 *seqno);
  2070. #define i915_add_request(ring, seqno) \
  2071. __i915_add_request(ring, NULL, NULL, seqno)
  2072. int __must_check i915_wait_seqno(struct intel_engine_cs *ring,
  2073. uint32_t seqno);
  2074. int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
  2075. int __must_check
  2076. i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj,
  2077. bool write);
  2078. int __must_check
  2079. i915_gem_object_set_to_cpu_domain(struct drm_i915_gem_object *obj, bool write);
  2080. int __must_check
  2081. i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
  2082. u32 alignment,
  2083. struct intel_engine_cs *pipelined);
  2084. void i915_gem_object_unpin_from_display_plane(struct drm_i915_gem_object *obj);
  2085. int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj,
  2086. int align);
  2087. int i915_gem_open(struct drm_device *dev, struct drm_file *file);
  2088. void i915_gem_release(struct drm_device *dev, struct drm_file *file);
  2089. uint32_t
  2090. i915_gem_get_gtt_size(struct drm_device *dev, uint32_t size, int tiling_mode);
  2091. uint32_t
  2092. i915_gem_get_gtt_alignment(struct drm_device *dev, uint32_t size,
  2093. int tiling_mode, bool fenced);
  2094. int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
  2095. enum i915_cache_level cache_level);
  2096. struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
  2097. struct dma_buf *dma_buf);
  2098. struct dma_buf *i915_gem_prime_export(struct drm_device *dev,
  2099. struct drm_gem_object *gem_obj, int flags);
  2100. void i915_gem_restore_fences(struct drm_device *dev);
  2101. unsigned long i915_gem_obj_offset(struct drm_i915_gem_object *o,
  2102. struct i915_address_space *vm);
  2103. bool i915_gem_obj_bound_any(struct drm_i915_gem_object *o);
  2104. bool i915_gem_obj_bound(struct drm_i915_gem_object *o,
  2105. struct i915_address_space *vm);
  2106. unsigned long i915_gem_obj_size(struct drm_i915_gem_object *o,
  2107. struct i915_address_space *vm);
  2108. struct i915_vma *i915_gem_obj_to_vma(struct drm_i915_gem_object *obj,
  2109. struct i915_address_space *vm);
  2110. struct i915_vma *
  2111. i915_gem_obj_lookup_or_create_vma(struct drm_i915_gem_object *obj,
  2112. struct i915_address_space *vm);
  2113. struct i915_vma *i915_gem_obj_to_ggtt(struct drm_i915_gem_object *obj);
  2114. static inline bool i915_gem_obj_is_pinned(struct drm_i915_gem_object *obj) {
  2115. struct i915_vma *vma;
  2116. list_for_each_entry(vma, &obj->vma_list, vma_link)
  2117. if (vma->pin_count > 0)
  2118. return true;
  2119. return false;
  2120. }
  2121. /* Some GGTT VM helpers */
  2122. #define obj_to_ggtt(obj) \
  2123. (&((struct drm_i915_private *)(obj)->base.dev->dev_private)->gtt.base)
  2124. static inline bool i915_is_ggtt(struct i915_address_space *vm)
  2125. {
  2126. struct i915_address_space *ggtt =
  2127. &((struct drm_i915_private *)(vm)->dev->dev_private)->gtt.base;
  2128. return vm == ggtt;
  2129. }
  2130. static inline bool i915_gem_obj_ggtt_bound(struct drm_i915_gem_object *obj)
  2131. {
  2132. return i915_gem_obj_bound(obj, obj_to_ggtt(obj));
  2133. }
  2134. static inline unsigned long
  2135. i915_gem_obj_ggtt_offset(struct drm_i915_gem_object *obj)
  2136. {
  2137. return i915_gem_obj_offset(obj, obj_to_ggtt(obj));
  2138. }
  2139. static inline unsigned long
  2140. i915_gem_obj_ggtt_size(struct drm_i915_gem_object *obj)
  2141. {
  2142. return i915_gem_obj_size(obj, obj_to_ggtt(obj));
  2143. }
  2144. static inline int __must_check
  2145. i915_gem_obj_ggtt_pin(struct drm_i915_gem_object *obj,
  2146. uint32_t alignment,
  2147. unsigned flags)
  2148. {
  2149. return i915_gem_object_pin(obj, obj_to_ggtt(obj), alignment, flags | PIN_GLOBAL);
  2150. }
  2151. static inline int
  2152. i915_gem_object_ggtt_unbind(struct drm_i915_gem_object *obj)
  2153. {
  2154. return i915_vma_unbind(i915_gem_obj_to_ggtt(obj));
  2155. }
  2156. void i915_gem_object_ggtt_unpin(struct drm_i915_gem_object *obj);
  2157. /* i915_gem_context.c */
  2158. #define ctx_to_ppgtt(ctx) container_of((ctx)->vm, struct i915_hw_ppgtt, base)
  2159. int __must_check i915_gem_context_init(struct drm_device *dev);
  2160. void i915_gem_context_fini(struct drm_device *dev);
  2161. void i915_gem_context_reset(struct drm_device *dev);
  2162. int i915_gem_context_open(struct drm_device *dev, struct drm_file *file);
  2163. int i915_gem_context_enable(struct drm_i915_private *dev_priv);
  2164. void i915_gem_context_close(struct drm_device *dev, struct drm_file *file);
  2165. int i915_switch_context(struct intel_engine_cs *ring,
  2166. struct intel_context *to);
  2167. struct intel_context *
  2168. i915_gem_context_get(struct drm_i915_file_private *file_priv, u32 id);
  2169. void i915_gem_context_free(struct kref *ctx_ref);
  2170. static inline void i915_gem_context_reference(struct intel_context *ctx)
  2171. {
  2172. kref_get(&ctx->ref);
  2173. }
  2174. static inline void i915_gem_context_unreference(struct intel_context *ctx)
  2175. {
  2176. kref_put(&ctx->ref, i915_gem_context_free);
  2177. }
  2178. static inline bool i915_gem_context_is_default(const struct intel_context *c)
  2179. {
  2180. return c->user_handle == DEFAULT_CONTEXT_HANDLE;
  2181. }
  2182. int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
  2183. struct drm_file *file);
  2184. int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
  2185. struct drm_file *file);
  2186. /* i915_gem_render_state.c */
  2187. int i915_gem_render_state_init(struct intel_engine_cs *ring);
  2188. /* i915_gem_evict.c */
  2189. int __must_check i915_gem_evict_something(struct drm_device *dev,
  2190. struct i915_address_space *vm,
  2191. int min_size,
  2192. unsigned alignment,
  2193. unsigned cache_level,
  2194. unsigned long start,
  2195. unsigned long end,
  2196. unsigned flags);
  2197. int i915_gem_evict_vm(struct i915_address_space *vm, bool do_idle);
  2198. int i915_gem_evict_everything(struct drm_device *dev);
  2199. /* belongs in i915_gem_gtt.h */
  2200. static inline void i915_gem_chipset_flush(struct drm_device *dev)
  2201. {
  2202. if (INTEL_INFO(dev)->gen < 6)
  2203. intel_gtt_chipset_flush();
  2204. }
  2205. /* i915_gem_stolen.c */
  2206. int i915_gem_init_stolen(struct drm_device *dev);
  2207. int i915_gem_stolen_setup_compression(struct drm_device *dev, int size, int fb_cpp);
  2208. void i915_gem_stolen_cleanup_compression(struct drm_device *dev);
  2209. void i915_gem_cleanup_stolen(struct drm_device *dev);
  2210. struct drm_i915_gem_object *
  2211. i915_gem_object_create_stolen(struct drm_device *dev, u32 size);
  2212. struct drm_i915_gem_object *
  2213. i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
  2214. u32 stolen_offset,
  2215. u32 gtt_offset,
  2216. u32 size);
  2217. /* i915_gem_tiling.c */
  2218. static inline bool i915_gem_object_needs_bit17_swizzle(struct drm_i915_gem_object *obj)
  2219. {
  2220. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  2221. return dev_priv->mm.bit_6_swizzle_x == I915_BIT_6_SWIZZLE_9_10_17 &&
  2222. obj->tiling_mode != I915_TILING_NONE;
  2223. }
  2224. void i915_gem_detect_bit_6_swizzle(struct drm_device *dev);
  2225. void i915_gem_object_do_bit_17_swizzle(struct drm_i915_gem_object *obj);
  2226. void i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj);
  2227. /* i915_gem_debug.c */
  2228. #if WATCH_LISTS
  2229. int i915_verify_lists(struct drm_device *dev);
  2230. #else
  2231. #define i915_verify_lists(dev) 0
  2232. #endif
  2233. /* i915_debugfs.c */
  2234. int i915_debugfs_init(struct drm_minor *minor);
  2235. void i915_debugfs_cleanup(struct drm_minor *minor);
  2236. #ifdef CONFIG_DEBUG_FS
  2237. void intel_display_crc_init(struct drm_device *dev);
  2238. #else
  2239. static inline void intel_display_crc_init(struct drm_device *dev) {}
  2240. #endif
  2241. /* i915_gpu_error.c */
  2242. __printf(2, 3)
  2243. void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...);
  2244. int i915_error_state_to_str(struct drm_i915_error_state_buf *estr,
  2245. const struct i915_error_state_file_priv *error);
  2246. int i915_error_state_buf_init(struct drm_i915_error_state_buf *eb,
  2247. size_t count, loff_t pos);
  2248. static inline void i915_error_state_buf_release(
  2249. struct drm_i915_error_state_buf *eb)
  2250. {
  2251. kfree(eb->buf);
  2252. }
  2253. void i915_capture_error_state(struct drm_device *dev, bool wedge,
  2254. const char *error_msg);
  2255. void i915_error_state_get(struct drm_device *dev,
  2256. struct i915_error_state_file_priv *error_priv);
  2257. void i915_error_state_put(struct i915_error_state_file_priv *error_priv);
  2258. void i915_destroy_error_state(struct drm_device *dev);
  2259. void i915_get_extra_instdone(struct drm_device *dev, uint32_t *instdone);
  2260. const char *i915_cache_level_str(int type);
  2261. /* i915_cmd_parser.c */
  2262. int i915_cmd_parser_get_version(void);
  2263. int i915_cmd_parser_init_ring(struct intel_engine_cs *ring);
  2264. void i915_cmd_parser_fini_ring(struct intel_engine_cs *ring);
  2265. bool i915_needs_cmd_parser(struct intel_engine_cs *ring);
  2266. int i915_parse_cmds(struct intel_engine_cs *ring,
  2267. struct drm_i915_gem_object *batch_obj,
  2268. u32 batch_start_offset,
  2269. bool is_master);
  2270. /* i915_suspend.c */
  2271. extern int i915_save_state(struct drm_device *dev);
  2272. extern int i915_restore_state(struct drm_device *dev);
  2273. /* i915_ums.c */
  2274. void i915_save_display_reg(struct drm_device *dev);
  2275. void i915_restore_display_reg(struct drm_device *dev);
  2276. /* i915_sysfs.c */
  2277. void i915_setup_sysfs(struct drm_device *dev_priv);
  2278. void i915_teardown_sysfs(struct drm_device *dev_priv);
  2279. /* intel_i2c.c */
  2280. extern int intel_setup_gmbus(struct drm_device *dev);
  2281. extern void intel_teardown_gmbus(struct drm_device *dev);
  2282. static inline bool intel_gmbus_is_port_valid(unsigned port)
  2283. {
  2284. return (port >= GMBUS_PORT_SSC && port <= GMBUS_PORT_DPD);
  2285. }
  2286. extern struct i2c_adapter *intel_gmbus_get_adapter(
  2287. struct drm_i915_private *dev_priv, unsigned port);
  2288. extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
  2289. extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
  2290. static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
  2291. {
  2292. return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
  2293. }
  2294. extern void intel_i2c_reset(struct drm_device *dev);
  2295. /* intel_opregion.c */
  2296. struct intel_encoder;
  2297. #ifdef CONFIG_ACPI
  2298. extern int intel_opregion_setup(struct drm_device *dev);
  2299. extern void intel_opregion_init(struct drm_device *dev);
  2300. extern void intel_opregion_fini(struct drm_device *dev);
  2301. extern void intel_opregion_asle_intr(struct drm_device *dev);
  2302. extern int intel_opregion_notify_encoder(struct intel_encoder *intel_encoder,
  2303. bool enable);
  2304. extern int intel_opregion_notify_adapter(struct drm_device *dev,
  2305. pci_power_t state);
  2306. #else
  2307. static inline int intel_opregion_setup(struct drm_device *dev) { return 0; }
  2308. static inline void intel_opregion_init(struct drm_device *dev) { return; }
  2309. static inline void intel_opregion_fini(struct drm_device *dev) { return; }
  2310. static inline void intel_opregion_asle_intr(struct drm_device *dev) { return; }
  2311. static inline int
  2312. intel_opregion_notify_encoder(struct intel_encoder *intel_encoder, bool enable)
  2313. {
  2314. return 0;
  2315. }
  2316. static inline int
  2317. intel_opregion_notify_adapter(struct drm_device *dev, pci_power_t state)
  2318. {
  2319. return 0;
  2320. }
  2321. #endif
  2322. /* intel_acpi.c */
  2323. #ifdef CONFIG_ACPI
  2324. extern void intel_register_dsm_handler(void);
  2325. extern void intel_unregister_dsm_handler(void);
  2326. #else
  2327. static inline void intel_register_dsm_handler(void) { return; }
  2328. static inline void intel_unregister_dsm_handler(void) { return; }
  2329. #endif /* CONFIG_ACPI */
  2330. /* modesetting */
  2331. extern void intel_modeset_init_hw(struct drm_device *dev);
  2332. extern void intel_modeset_suspend_hw(struct drm_device *dev);
  2333. extern void intel_modeset_init(struct drm_device *dev);
  2334. extern void intel_modeset_gem_init(struct drm_device *dev);
  2335. extern void intel_modeset_cleanup(struct drm_device *dev);
  2336. extern void intel_connector_unregister(struct intel_connector *);
  2337. extern int intel_modeset_vga_set_state(struct drm_device *dev, bool state);
  2338. extern void intel_modeset_setup_hw_state(struct drm_device *dev,
  2339. bool force_restore);
  2340. extern void i915_redisable_vga(struct drm_device *dev);
  2341. extern void i915_redisable_vga_power_on(struct drm_device *dev);
  2342. extern bool intel_fbc_enabled(struct drm_device *dev);
  2343. extern void intel_disable_fbc(struct drm_device *dev);
  2344. extern bool ironlake_set_drps(struct drm_device *dev, u8 val);
  2345. extern void intel_init_pch_refclk(struct drm_device *dev);
  2346. extern void gen6_set_rps(struct drm_device *dev, u8 val);
  2347. extern void valleyview_set_rps(struct drm_device *dev, u8 val);
  2348. extern void intel_set_memory_cxsr(struct drm_i915_private *dev_priv,
  2349. bool enable);
  2350. extern void intel_detect_pch(struct drm_device *dev);
  2351. extern int intel_trans_dp_port_sel(struct drm_crtc *crtc);
  2352. extern int intel_enable_rc6(const struct drm_device *dev);
  2353. extern bool i915_semaphore_is_enabled(struct drm_device *dev);
  2354. int i915_reg_read_ioctl(struct drm_device *dev, void *data,
  2355. struct drm_file *file);
  2356. int i915_get_reset_stats_ioctl(struct drm_device *dev, void *data,
  2357. struct drm_file *file);
  2358. void intel_notify_mmio_flip(struct intel_engine_cs *ring);
  2359. /* overlay */
  2360. extern struct intel_overlay_error_state *intel_overlay_capture_error_state(struct drm_device *dev);
  2361. extern void intel_overlay_print_error_state(struct drm_i915_error_state_buf *e,
  2362. struct intel_overlay_error_state *error);
  2363. extern struct intel_display_error_state *intel_display_capture_error_state(struct drm_device *dev);
  2364. extern void intel_display_print_error_state(struct drm_i915_error_state_buf *e,
  2365. struct drm_device *dev,
  2366. struct intel_display_error_state *error);
  2367. /* On SNB platform, before reading ring registers forcewake bit
  2368. * must be set to prevent GT core from power down and stale values being
  2369. * returned.
  2370. */
  2371. void gen6_gt_force_wake_get(struct drm_i915_private *dev_priv, int fw_engine);
  2372. void gen6_gt_force_wake_put(struct drm_i915_private *dev_priv, int fw_engine);
  2373. void assert_force_wake_inactive(struct drm_i915_private *dev_priv);
  2374. int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u8 mbox, u32 *val);
  2375. int sandybridge_pcode_write(struct drm_i915_private *dev_priv, u8 mbox, u32 val);
  2376. /* intel_sideband.c */
  2377. u32 vlv_punit_read(struct drm_i915_private *dev_priv, u8 addr);
  2378. void vlv_punit_write(struct drm_i915_private *dev_priv, u8 addr, u32 val);
  2379. u32 vlv_nc_read(struct drm_i915_private *dev_priv, u8 addr);
  2380. u32 vlv_gpio_nc_read(struct drm_i915_private *dev_priv, u32 reg);
  2381. void vlv_gpio_nc_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2382. u32 vlv_cck_read(struct drm_i915_private *dev_priv, u32 reg);
  2383. void vlv_cck_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2384. u32 vlv_ccu_read(struct drm_i915_private *dev_priv, u32 reg);
  2385. void vlv_ccu_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2386. u32 vlv_bunit_read(struct drm_i915_private *dev_priv, u32 reg);
  2387. void vlv_bunit_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2388. u32 vlv_gps_core_read(struct drm_i915_private *dev_priv, u32 reg);
  2389. void vlv_gps_core_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2390. u32 vlv_dpio_read(struct drm_i915_private *dev_priv, enum pipe pipe, int reg);
  2391. void vlv_dpio_write(struct drm_i915_private *dev_priv, enum pipe pipe, int reg, u32 val);
  2392. u32 intel_sbi_read(struct drm_i915_private *dev_priv, u16 reg,
  2393. enum intel_sbi_destination destination);
  2394. void intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
  2395. enum intel_sbi_destination destination);
  2396. u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
  2397. void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
  2398. int vlv_gpu_freq(struct drm_i915_private *dev_priv, int val);
  2399. int vlv_freq_opcode(struct drm_i915_private *dev_priv, int val);
  2400. #define FORCEWAKE_RENDER (1 << 0)
  2401. #define FORCEWAKE_MEDIA (1 << 1)
  2402. #define FORCEWAKE_ALL (FORCEWAKE_RENDER | FORCEWAKE_MEDIA)
  2403. #define I915_READ8(reg) dev_priv->uncore.funcs.mmio_readb(dev_priv, (reg), true)
  2404. #define I915_WRITE8(reg, val) dev_priv->uncore.funcs.mmio_writeb(dev_priv, (reg), (val), true)
  2405. #define I915_READ16(reg) dev_priv->uncore.funcs.mmio_readw(dev_priv, (reg), true)
  2406. #define I915_WRITE16(reg, val) dev_priv->uncore.funcs.mmio_writew(dev_priv, (reg), (val), true)
  2407. #define I915_READ16_NOTRACE(reg) dev_priv->uncore.funcs.mmio_readw(dev_priv, (reg), false)
  2408. #define I915_WRITE16_NOTRACE(reg, val) dev_priv->uncore.funcs.mmio_writew(dev_priv, (reg), (val), false)
  2409. #define I915_READ(reg) dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), true)
  2410. #define I915_WRITE(reg, val) dev_priv->uncore.funcs.mmio_writel(dev_priv, (reg), (val), true)
  2411. #define I915_READ_NOTRACE(reg) dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), false)
  2412. #define I915_WRITE_NOTRACE(reg, val) dev_priv->uncore.funcs.mmio_writel(dev_priv, (reg), (val), false)
  2413. /* Be very careful with read/write 64-bit values. On 32-bit machines, they
  2414. * will be implemented using 2 32-bit writes in an arbitrary order with
  2415. * an arbitrary delay between them. This can cause the hardware to
  2416. * act upon the intermediate value, possibly leading to corruption and
  2417. * machine death. You have been warned.
  2418. */
  2419. #define I915_WRITE64(reg, val) dev_priv->uncore.funcs.mmio_writeq(dev_priv, (reg), (val), true)
  2420. #define I915_READ64(reg) dev_priv->uncore.funcs.mmio_readq(dev_priv, (reg), true)
  2421. #define I915_READ64_2x32(lower_reg, upper_reg) ({ \
  2422. u32 upper = I915_READ(upper_reg); \
  2423. u32 lower = I915_READ(lower_reg); \
  2424. u32 tmp = I915_READ(upper_reg); \
  2425. if (upper != tmp) { \
  2426. upper = tmp; \
  2427. lower = I915_READ(lower_reg); \
  2428. WARN_ON(I915_READ(upper_reg) != upper); \
  2429. } \
  2430. (u64)upper << 32 | lower; })
  2431. #define POSTING_READ(reg) (void)I915_READ_NOTRACE(reg)
  2432. #define POSTING_READ16(reg) (void)I915_READ16_NOTRACE(reg)
  2433. /* "Broadcast RGB" property */
  2434. #define INTEL_BROADCAST_RGB_AUTO 0
  2435. #define INTEL_BROADCAST_RGB_FULL 1
  2436. #define INTEL_BROADCAST_RGB_LIMITED 2
  2437. static inline uint32_t i915_vgacntrl_reg(struct drm_device *dev)
  2438. {
  2439. if (IS_VALLEYVIEW(dev))
  2440. return VLV_VGACNTRL;
  2441. else if (INTEL_INFO(dev)->gen >= 5)
  2442. return CPU_VGACNTRL;
  2443. else
  2444. return VGACNTRL;
  2445. }
  2446. static inline void __user *to_user_ptr(u64 address)
  2447. {
  2448. return (void __user *)(uintptr_t)address;
  2449. }
  2450. static inline unsigned long msecs_to_jiffies_timeout(const unsigned int m)
  2451. {
  2452. unsigned long j = msecs_to_jiffies(m);
  2453. return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
  2454. }
  2455. static inline unsigned long
  2456. timespec_to_jiffies_timeout(const struct timespec *value)
  2457. {
  2458. unsigned long j = timespec_to_jiffies(value);
  2459. return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
  2460. }
  2461. /*
  2462. * If you need to wait X milliseconds between events A and B, but event B
  2463. * doesn't happen exactly after event A, you record the timestamp (jiffies) of
  2464. * when event A happened, then just before event B you call this function and
  2465. * pass the timestamp as the first argument, and X as the second argument.
  2466. */
  2467. static inline void
  2468. wait_remaining_ms_from_jiffies(unsigned long timestamp_jiffies, int to_wait_ms)
  2469. {
  2470. unsigned long target_jiffies, tmp_jiffies, remaining_jiffies;
  2471. /*
  2472. * Don't re-read the value of "jiffies" every time since it may change
  2473. * behind our back and break the math.
  2474. */
  2475. tmp_jiffies = jiffies;
  2476. target_jiffies = timestamp_jiffies +
  2477. msecs_to_jiffies_timeout(to_wait_ms);
  2478. if (time_after(target_jiffies, tmp_jiffies)) {
  2479. remaining_jiffies = target_jiffies - tmp_jiffies;
  2480. while (remaining_jiffies)
  2481. remaining_jiffies =
  2482. schedule_timeout_uninterruptible(remaining_jiffies);
  2483. }
  2484. }
  2485. #endif