i915_drv.h 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961
  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 <linux/io-mapping.h>
  36. #include <linux/i2c.h>
  37. #include <linux/i2c-algo-bit.h>
  38. #include <drm/intel-gtt.h>
  39. #include <linux/backlight.h>
  40. #include <linux/intel-iommu.h>
  41. #include <linux/kref.h>
  42. #include <linux/pm_qos.h>
  43. /* General customization:
  44. */
  45. #define DRIVER_AUTHOR "Tungsten Graphics, Inc."
  46. #define DRIVER_NAME "i915"
  47. #define DRIVER_DESC "Intel Graphics"
  48. #define DRIVER_DATE "20080730"
  49. enum pipe {
  50. PIPE_A = 0,
  51. PIPE_B,
  52. PIPE_C,
  53. I915_MAX_PIPES
  54. };
  55. #define pipe_name(p) ((p) + 'A')
  56. enum transcoder {
  57. TRANSCODER_A = 0,
  58. TRANSCODER_B,
  59. TRANSCODER_C,
  60. TRANSCODER_EDP = 0xF,
  61. };
  62. #define transcoder_name(t) ((t) + 'A')
  63. enum plane {
  64. PLANE_A = 0,
  65. PLANE_B,
  66. PLANE_C,
  67. };
  68. #define plane_name(p) ((p) + 'A')
  69. enum port {
  70. PORT_A = 0,
  71. PORT_B,
  72. PORT_C,
  73. PORT_D,
  74. PORT_E,
  75. I915_MAX_PORTS
  76. };
  77. #define port_name(p) ((p) + 'A')
  78. enum hpd_pin {
  79. HPD_NONE = 0,
  80. HPD_PORT_A = HPD_NONE, /* PORT_A is internal */
  81. HPD_TV = HPD_NONE, /* TV is known to be unreliable */
  82. HPD_CRT,
  83. HPD_SDVO_B,
  84. HPD_SDVO_C,
  85. HPD_PORT_B,
  86. HPD_PORT_C,
  87. HPD_PORT_D,
  88. HPD_NUM_PINS
  89. };
  90. #define I915_GEM_GPU_DOMAINS \
  91. (I915_GEM_DOMAIN_RENDER | \
  92. I915_GEM_DOMAIN_SAMPLER | \
  93. I915_GEM_DOMAIN_COMMAND | \
  94. I915_GEM_DOMAIN_INSTRUCTION | \
  95. I915_GEM_DOMAIN_VERTEX)
  96. #define for_each_pipe(p) for ((p) = 0; (p) < INTEL_INFO(dev)->num_pipes; (p)++)
  97. #define for_each_encoder_on_crtc(dev, __crtc, intel_encoder) \
  98. list_for_each_entry((intel_encoder), &(dev)->mode_config.encoder_list, base.head) \
  99. if ((intel_encoder)->base.crtc == (__crtc))
  100. struct intel_pch_pll {
  101. int refcount; /* count of number of CRTCs sharing this PLL */
  102. int active; /* count of number of active CRTCs (i.e. DPMS on) */
  103. bool on; /* is the PLL actually active? Disabled during modeset */
  104. int pll_reg;
  105. int fp0_reg;
  106. int fp1_reg;
  107. };
  108. #define I915_NUM_PLLS 2
  109. /* Used by dp and fdi links */
  110. struct intel_link_m_n {
  111. uint32_t tu;
  112. uint32_t gmch_m;
  113. uint32_t gmch_n;
  114. uint32_t link_m;
  115. uint32_t link_n;
  116. };
  117. void intel_link_compute_m_n(int bpp, int nlanes,
  118. int pixel_clock, int link_clock,
  119. struct intel_link_m_n *m_n);
  120. struct intel_ddi_plls {
  121. int spll_refcount;
  122. int wrpll1_refcount;
  123. int wrpll2_refcount;
  124. };
  125. /* Interface history:
  126. *
  127. * 1.1: Original.
  128. * 1.2: Add Power Management
  129. * 1.3: Add vblank support
  130. * 1.4: Fix cmdbuffer path, add heap destroy
  131. * 1.5: Add vblank pipe configuration
  132. * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
  133. * - Support vertical blank on secondary display pipe
  134. */
  135. #define DRIVER_MAJOR 1
  136. #define DRIVER_MINOR 6
  137. #define DRIVER_PATCHLEVEL 0
  138. #define WATCH_COHERENCY 0
  139. #define WATCH_LISTS 0
  140. #define WATCH_GTT 0
  141. #define I915_GEM_PHYS_CURSOR_0 1
  142. #define I915_GEM_PHYS_CURSOR_1 2
  143. #define I915_GEM_PHYS_OVERLAY_REGS 3
  144. #define I915_MAX_PHYS_OBJECT (I915_GEM_PHYS_OVERLAY_REGS)
  145. struct drm_i915_gem_phys_object {
  146. int id;
  147. struct page **page_list;
  148. drm_dma_handle_t *handle;
  149. struct drm_i915_gem_object *cur_obj;
  150. };
  151. struct opregion_header;
  152. struct opregion_acpi;
  153. struct opregion_swsci;
  154. struct opregion_asle;
  155. struct drm_i915_private;
  156. struct intel_opregion {
  157. struct opregion_header __iomem *header;
  158. struct opregion_acpi __iomem *acpi;
  159. struct opregion_swsci __iomem *swsci;
  160. struct opregion_asle __iomem *asle;
  161. void __iomem *vbt;
  162. u32 __iomem *lid_state;
  163. };
  164. #define OPREGION_SIZE (8*1024)
  165. struct intel_overlay;
  166. struct intel_overlay_error_state;
  167. struct drm_i915_master_private {
  168. drm_local_map_t *sarea;
  169. struct _drm_i915_sarea *sarea_priv;
  170. };
  171. #define I915_FENCE_REG_NONE -1
  172. #define I915_MAX_NUM_FENCES 32
  173. /* 32 fences + sign bit for FENCE_REG_NONE */
  174. #define I915_MAX_NUM_FENCE_BITS 6
  175. struct drm_i915_fence_reg {
  176. struct list_head lru_list;
  177. struct drm_i915_gem_object *obj;
  178. int pin_count;
  179. };
  180. struct sdvo_device_mapping {
  181. u8 initialized;
  182. u8 dvo_port;
  183. u8 slave_addr;
  184. u8 dvo_wiring;
  185. u8 i2c_pin;
  186. u8 ddc_pin;
  187. };
  188. struct intel_display_error_state;
  189. struct drm_i915_error_state {
  190. struct kref ref;
  191. u32 eir;
  192. u32 pgtbl_er;
  193. u32 ier;
  194. u32 ccid;
  195. u32 derrmr;
  196. u32 forcewake;
  197. bool waiting[I915_NUM_RINGS];
  198. u32 pipestat[I915_MAX_PIPES];
  199. u32 tail[I915_NUM_RINGS];
  200. u32 head[I915_NUM_RINGS];
  201. u32 ctl[I915_NUM_RINGS];
  202. u32 ipeir[I915_NUM_RINGS];
  203. u32 ipehr[I915_NUM_RINGS];
  204. u32 instdone[I915_NUM_RINGS];
  205. u32 acthd[I915_NUM_RINGS];
  206. u32 semaphore_mboxes[I915_NUM_RINGS][I915_NUM_RINGS - 1];
  207. u32 semaphore_seqno[I915_NUM_RINGS][I915_NUM_RINGS - 1];
  208. u32 rc_psmi[I915_NUM_RINGS]; /* sleep state */
  209. /* our own tracking of ring head and tail */
  210. u32 cpu_ring_head[I915_NUM_RINGS];
  211. u32 cpu_ring_tail[I915_NUM_RINGS];
  212. u32 error; /* gen6+ */
  213. u32 err_int; /* gen7 */
  214. u32 instpm[I915_NUM_RINGS];
  215. u32 instps[I915_NUM_RINGS];
  216. u32 extra_instdone[I915_NUM_INSTDONE_REG];
  217. u32 seqno[I915_NUM_RINGS];
  218. u64 bbaddr;
  219. u32 fault_reg[I915_NUM_RINGS];
  220. u32 done_reg;
  221. u32 faddr[I915_NUM_RINGS];
  222. u64 fence[I915_MAX_NUM_FENCES];
  223. struct timeval time;
  224. struct drm_i915_error_ring {
  225. struct drm_i915_error_object {
  226. int page_count;
  227. u32 gtt_offset;
  228. u32 *pages[0];
  229. } *ringbuffer, *batchbuffer, *ctx;
  230. struct drm_i915_error_request {
  231. long jiffies;
  232. u32 seqno;
  233. u32 tail;
  234. } *requests;
  235. int num_requests;
  236. } ring[I915_NUM_RINGS];
  237. struct drm_i915_error_buffer {
  238. u32 size;
  239. u32 name;
  240. u32 rseqno, wseqno;
  241. u32 gtt_offset;
  242. u32 read_domains;
  243. u32 write_domain;
  244. s32 fence_reg:I915_MAX_NUM_FENCE_BITS;
  245. s32 pinned:2;
  246. u32 tiling:2;
  247. u32 dirty:1;
  248. u32 purgeable:1;
  249. s32 ring:4;
  250. u32 cache_level:2;
  251. } *active_bo, *pinned_bo;
  252. u32 active_bo_count, pinned_bo_count;
  253. struct intel_overlay_error_state *overlay;
  254. struct intel_display_error_state *display;
  255. };
  256. struct intel_crtc_config;
  257. struct intel_crtc;
  258. struct drm_i915_display_funcs {
  259. bool (*fbc_enabled)(struct drm_device *dev);
  260. void (*enable_fbc)(struct drm_crtc *crtc, unsigned long interval);
  261. void (*disable_fbc)(struct drm_device *dev);
  262. int (*get_display_clock_speed)(struct drm_device *dev);
  263. int (*get_fifo_size)(struct drm_device *dev, int plane);
  264. void (*update_wm)(struct drm_device *dev);
  265. void (*update_sprite_wm)(struct drm_device *dev, int pipe,
  266. uint32_t sprite_width, int pixel_size);
  267. void (*update_linetime_wm)(struct drm_device *dev, int pipe,
  268. struct drm_display_mode *mode);
  269. void (*modeset_global_resources)(struct drm_device *dev);
  270. /* Returns the active state of the crtc, and if the crtc is active,
  271. * fills out the pipe-config with the hw state. */
  272. bool (*get_pipe_config)(struct intel_crtc *,
  273. struct intel_crtc_config *);
  274. int (*crtc_mode_set)(struct drm_crtc *crtc,
  275. int x, int y,
  276. struct drm_framebuffer *old_fb);
  277. void (*crtc_enable)(struct drm_crtc *crtc);
  278. void (*crtc_disable)(struct drm_crtc *crtc);
  279. void (*off)(struct drm_crtc *crtc);
  280. void (*write_eld)(struct drm_connector *connector,
  281. struct drm_crtc *crtc);
  282. void (*fdi_link_train)(struct drm_crtc *crtc);
  283. void (*init_clock_gating)(struct drm_device *dev);
  284. int (*queue_flip)(struct drm_device *dev, struct drm_crtc *crtc,
  285. struct drm_framebuffer *fb,
  286. struct drm_i915_gem_object *obj);
  287. int (*update_plane)(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  288. int x, int y);
  289. void (*hpd_irq_setup)(struct drm_device *dev);
  290. /* clock updates for mode set */
  291. /* cursor updates */
  292. /* render clock increase/decrease */
  293. /* display clock increase/decrease */
  294. /* pll clock increase/decrease */
  295. };
  296. struct drm_i915_gt_funcs {
  297. void (*force_wake_get)(struct drm_i915_private *dev_priv);
  298. void (*force_wake_put)(struct drm_i915_private *dev_priv);
  299. };
  300. #define DEV_INFO_FLAGS \
  301. DEV_INFO_FLAG(is_mobile) DEV_INFO_SEP \
  302. DEV_INFO_FLAG(is_i85x) DEV_INFO_SEP \
  303. DEV_INFO_FLAG(is_i915g) DEV_INFO_SEP \
  304. DEV_INFO_FLAG(is_i945gm) DEV_INFO_SEP \
  305. DEV_INFO_FLAG(is_g33) DEV_INFO_SEP \
  306. DEV_INFO_FLAG(need_gfx_hws) DEV_INFO_SEP \
  307. DEV_INFO_FLAG(is_g4x) DEV_INFO_SEP \
  308. DEV_INFO_FLAG(is_pineview) DEV_INFO_SEP \
  309. DEV_INFO_FLAG(is_broadwater) DEV_INFO_SEP \
  310. DEV_INFO_FLAG(is_crestline) DEV_INFO_SEP \
  311. DEV_INFO_FLAG(is_ivybridge) DEV_INFO_SEP \
  312. DEV_INFO_FLAG(is_valleyview) DEV_INFO_SEP \
  313. DEV_INFO_FLAG(is_haswell) DEV_INFO_SEP \
  314. DEV_INFO_FLAG(has_force_wake) DEV_INFO_SEP \
  315. DEV_INFO_FLAG(has_fbc) DEV_INFO_SEP \
  316. DEV_INFO_FLAG(has_pipe_cxsr) DEV_INFO_SEP \
  317. DEV_INFO_FLAG(has_hotplug) DEV_INFO_SEP \
  318. DEV_INFO_FLAG(cursor_needs_physical) DEV_INFO_SEP \
  319. DEV_INFO_FLAG(has_overlay) DEV_INFO_SEP \
  320. DEV_INFO_FLAG(overlay_needs_physical) DEV_INFO_SEP \
  321. DEV_INFO_FLAG(supports_tv) DEV_INFO_SEP \
  322. DEV_INFO_FLAG(has_bsd_ring) DEV_INFO_SEP \
  323. DEV_INFO_FLAG(has_blt_ring) DEV_INFO_SEP \
  324. DEV_INFO_FLAG(has_llc)
  325. struct intel_device_info {
  326. u32 display_mmio_offset;
  327. u8 num_pipes:3;
  328. u8 gen;
  329. u8 is_mobile:1;
  330. u8 is_i85x:1;
  331. u8 is_i915g:1;
  332. u8 is_i945gm:1;
  333. u8 is_g33:1;
  334. u8 need_gfx_hws:1;
  335. u8 is_g4x:1;
  336. u8 is_pineview:1;
  337. u8 is_broadwater:1;
  338. u8 is_crestline:1;
  339. u8 is_ivybridge:1;
  340. u8 is_valleyview:1;
  341. u8 has_force_wake:1;
  342. u8 is_haswell:1;
  343. u8 has_fbc:1;
  344. u8 has_pipe_cxsr:1;
  345. u8 has_hotplug:1;
  346. u8 cursor_needs_physical:1;
  347. u8 has_overlay:1;
  348. u8 overlay_needs_physical:1;
  349. u8 supports_tv:1;
  350. u8 has_bsd_ring:1;
  351. u8 has_blt_ring:1;
  352. u8 has_llc:1;
  353. };
  354. enum i915_cache_level {
  355. I915_CACHE_NONE = 0,
  356. I915_CACHE_LLC,
  357. I915_CACHE_LLC_MLC, /* gen6+, in docs at least! */
  358. };
  359. /* The Graphics Translation Table is the way in which GEN hardware translates a
  360. * Graphics Virtual Address into a Physical Address. In addition to the normal
  361. * collateral associated with any va->pa translations GEN hardware also has a
  362. * portion of the GTT which can be mapped by the CPU and remain both coherent
  363. * and correct (in cases like swizzling). That region is referred to as GMADR in
  364. * the spec.
  365. */
  366. struct i915_gtt {
  367. unsigned long start; /* Start offset of used GTT */
  368. size_t total; /* Total size GTT can map */
  369. size_t stolen_size; /* Total size of stolen memory */
  370. unsigned long mappable_end; /* End offset that we can CPU map */
  371. struct io_mapping *mappable; /* Mapping to our CPU mappable region */
  372. phys_addr_t mappable_base; /* PA of our GMADR */
  373. /** "Graphics Stolen Memory" holds the global PTEs */
  374. void __iomem *gsm;
  375. bool do_idle_maps;
  376. dma_addr_t scratch_page_dma;
  377. struct page *scratch_page;
  378. /* global gtt ops */
  379. int (*gtt_probe)(struct drm_device *dev, size_t *gtt_total,
  380. size_t *stolen, phys_addr_t *mappable_base,
  381. unsigned long *mappable_end);
  382. void (*gtt_remove)(struct drm_device *dev);
  383. void (*gtt_clear_range)(struct drm_device *dev,
  384. unsigned int first_entry,
  385. unsigned int num_entries);
  386. void (*gtt_insert_entries)(struct drm_device *dev,
  387. struct sg_table *st,
  388. unsigned int pg_start,
  389. enum i915_cache_level cache_level);
  390. };
  391. #define gtt_total_entries(gtt) ((gtt).total >> PAGE_SHIFT)
  392. #define I915_PPGTT_PD_ENTRIES 512
  393. #define I915_PPGTT_PT_ENTRIES 1024
  394. struct i915_hw_ppgtt {
  395. struct drm_device *dev;
  396. unsigned num_pd_entries;
  397. struct page **pt_pages;
  398. uint32_t pd_offset;
  399. dma_addr_t *pt_dma_addr;
  400. dma_addr_t scratch_page_dma_addr;
  401. /* pte functions, mirroring the interface of the global gtt. */
  402. void (*clear_range)(struct i915_hw_ppgtt *ppgtt,
  403. unsigned int first_entry,
  404. unsigned int num_entries);
  405. void (*insert_entries)(struct i915_hw_ppgtt *ppgtt,
  406. struct sg_table *st,
  407. unsigned int pg_start,
  408. enum i915_cache_level cache_level);
  409. int (*enable)(struct drm_device *dev);
  410. void (*cleanup)(struct i915_hw_ppgtt *ppgtt);
  411. };
  412. /* This must match up with the value previously used for execbuf2.rsvd1. */
  413. #define DEFAULT_CONTEXT_ID 0
  414. struct i915_hw_context {
  415. int id;
  416. bool is_initialized;
  417. struct drm_i915_file_private *file_priv;
  418. struct intel_ring_buffer *ring;
  419. struct drm_i915_gem_object *obj;
  420. };
  421. enum no_fbc_reason {
  422. FBC_NO_OUTPUT, /* no outputs enabled to compress */
  423. FBC_STOLEN_TOO_SMALL, /* not enough space to hold compressed buffers */
  424. FBC_UNSUPPORTED_MODE, /* interlace or doublescanned mode */
  425. FBC_MODE_TOO_LARGE, /* mode too large for compression */
  426. FBC_BAD_PLANE, /* fbc not supported on plane */
  427. FBC_NOT_TILED, /* buffer not tiled */
  428. FBC_MULTIPLE_PIPES, /* more than one pipe active */
  429. FBC_MODULE_PARAM,
  430. };
  431. enum intel_pch {
  432. PCH_NONE = 0, /* No PCH present */
  433. PCH_IBX, /* Ibexpeak PCH */
  434. PCH_CPT, /* Cougarpoint PCH */
  435. PCH_LPT, /* Lynxpoint PCH */
  436. PCH_NOP,
  437. };
  438. enum intel_sbi_destination {
  439. SBI_ICLK,
  440. SBI_MPHY,
  441. };
  442. #define QUIRK_PIPEA_FORCE (1<<0)
  443. #define QUIRK_LVDS_SSC_DISABLE (1<<1)
  444. #define QUIRK_INVERT_BRIGHTNESS (1<<2)
  445. struct intel_fbdev;
  446. struct intel_fbc_work;
  447. struct intel_gmbus {
  448. struct i2c_adapter adapter;
  449. u32 force_bit;
  450. u32 reg0;
  451. u32 gpio_reg;
  452. struct i2c_algo_bit_data bit_algo;
  453. struct drm_i915_private *dev_priv;
  454. };
  455. struct i915_suspend_saved_registers {
  456. u8 saveLBB;
  457. u32 saveDSPACNTR;
  458. u32 saveDSPBCNTR;
  459. u32 saveDSPARB;
  460. u32 savePIPEACONF;
  461. u32 savePIPEBCONF;
  462. u32 savePIPEASRC;
  463. u32 savePIPEBSRC;
  464. u32 saveFPA0;
  465. u32 saveFPA1;
  466. u32 saveDPLL_A;
  467. u32 saveDPLL_A_MD;
  468. u32 saveHTOTAL_A;
  469. u32 saveHBLANK_A;
  470. u32 saveHSYNC_A;
  471. u32 saveVTOTAL_A;
  472. u32 saveVBLANK_A;
  473. u32 saveVSYNC_A;
  474. u32 saveBCLRPAT_A;
  475. u32 saveTRANSACONF;
  476. u32 saveTRANS_HTOTAL_A;
  477. u32 saveTRANS_HBLANK_A;
  478. u32 saveTRANS_HSYNC_A;
  479. u32 saveTRANS_VTOTAL_A;
  480. u32 saveTRANS_VBLANK_A;
  481. u32 saveTRANS_VSYNC_A;
  482. u32 savePIPEASTAT;
  483. u32 saveDSPASTRIDE;
  484. u32 saveDSPASIZE;
  485. u32 saveDSPAPOS;
  486. u32 saveDSPAADDR;
  487. u32 saveDSPASURF;
  488. u32 saveDSPATILEOFF;
  489. u32 savePFIT_PGM_RATIOS;
  490. u32 saveBLC_HIST_CTL;
  491. u32 saveBLC_PWM_CTL;
  492. u32 saveBLC_PWM_CTL2;
  493. u32 saveBLC_CPU_PWM_CTL;
  494. u32 saveBLC_CPU_PWM_CTL2;
  495. u32 saveFPB0;
  496. u32 saveFPB1;
  497. u32 saveDPLL_B;
  498. u32 saveDPLL_B_MD;
  499. u32 saveHTOTAL_B;
  500. u32 saveHBLANK_B;
  501. u32 saveHSYNC_B;
  502. u32 saveVTOTAL_B;
  503. u32 saveVBLANK_B;
  504. u32 saveVSYNC_B;
  505. u32 saveBCLRPAT_B;
  506. u32 saveTRANSBCONF;
  507. u32 saveTRANS_HTOTAL_B;
  508. u32 saveTRANS_HBLANK_B;
  509. u32 saveTRANS_HSYNC_B;
  510. u32 saveTRANS_VTOTAL_B;
  511. u32 saveTRANS_VBLANK_B;
  512. u32 saveTRANS_VSYNC_B;
  513. u32 savePIPEBSTAT;
  514. u32 saveDSPBSTRIDE;
  515. u32 saveDSPBSIZE;
  516. u32 saveDSPBPOS;
  517. u32 saveDSPBADDR;
  518. u32 saveDSPBSURF;
  519. u32 saveDSPBTILEOFF;
  520. u32 saveVGA0;
  521. u32 saveVGA1;
  522. u32 saveVGA_PD;
  523. u32 saveVGACNTRL;
  524. u32 saveADPA;
  525. u32 saveLVDS;
  526. u32 savePP_ON_DELAYS;
  527. u32 savePP_OFF_DELAYS;
  528. u32 saveDVOA;
  529. u32 saveDVOB;
  530. u32 saveDVOC;
  531. u32 savePP_ON;
  532. u32 savePP_OFF;
  533. u32 savePP_CONTROL;
  534. u32 savePP_DIVISOR;
  535. u32 savePFIT_CONTROL;
  536. u32 save_palette_a[256];
  537. u32 save_palette_b[256];
  538. u32 saveDPFC_CB_BASE;
  539. u32 saveFBC_CFB_BASE;
  540. u32 saveFBC_LL_BASE;
  541. u32 saveFBC_CONTROL;
  542. u32 saveFBC_CONTROL2;
  543. u32 saveIER;
  544. u32 saveIIR;
  545. u32 saveIMR;
  546. u32 saveDEIER;
  547. u32 saveDEIMR;
  548. u32 saveGTIER;
  549. u32 saveGTIMR;
  550. u32 saveFDI_RXA_IMR;
  551. u32 saveFDI_RXB_IMR;
  552. u32 saveCACHE_MODE_0;
  553. u32 saveMI_ARB_STATE;
  554. u32 saveSWF0[16];
  555. u32 saveSWF1[16];
  556. u32 saveSWF2[3];
  557. u8 saveMSR;
  558. u8 saveSR[8];
  559. u8 saveGR[25];
  560. u8 saveAR_INDEX;
  561. u8 saveAR[21];
  562. u8 saveDACMASK;
  563. u8 saveCR[37];
  564. uint64_t saveFENCE[I915_MAX_NUM_FENCES];
  565. u32 saveCURACNTR;
  566. u32 saveCURAPOS;
  567. u32 saveCURABASE;
  568. u32 saveCURBCNTR;
  569. u32 saveCURBPOS;
  570. u32 saveCURBBASE;
  571. u32 saveCURSIZE;
  572. u32 saveDP_B;
  573. u32 saveDP_C;
  574. u32 saveDP_D;
  575. u32 savePIPEA_GMCH_DATA_M;
  576. u32 savePIPEB_GMCH_DATA_M;
  577. u32 savePIPEA_GMCH_DATA_N;
  578. u32 savePIPEB_GMCH_DATA_N;
  579. u32 savePIPEA_DP_LINK_M;
  580. u32 savePIPEB_DP_LINK_M;
  581. u32 savePIPEA_DP_LINK_N;
  582. u32 savePIPEB_DP_LINK_N;
  583. u32 saveFDI_RXA_CTL;
  584. u32 saveFDI_TXA_CTL;
  585. u32 saveFDI_RXB_CTL;
  586. u32 saveFDI_TXB_CTL;
  587. u32 savePFA_CTL_1;
  588. u32 savePFB_CTL_1;
  589. u32 savePFA_WIN_SZ;
  590. u32 savePFB_WIN_SZ;
  591. u32 savePFA_WIN_POS;
  592. u32 savePFB_WIN_POS;
  593. u32 savePCH_DREF_CONTROL;
  594. u32 saveDISP_ARB_CTL;
  595. u32 savePIPEA_DATA_M1;
  596. u32 savePIPEA_DATA_N1;
  597. u32 savePIPEA_LINK_M1;
  598. u32 savePIPEA_LINK_N1;
  599. u32 savePIPEB_DATA_M1;
  600. u32 savePIPEB_DATA_N1;
  601. u32 savePIPEB_LINK_M1;
  602. u32 savePIPEB_LINK_N1;
  603. u32 saveMCHBAR_RENDER_STANDBY;
  604. u32 savePCH_PORT_HOTPLUG;
  605. };
  606. struct intel_gen6_power_mgmt {
  607. struct work_struct work;
  608. u32 pm_iir;
  609. /* lock - irqsave spinlock that protectects the work_struct and
  610. * pm_iir. */
  611. spinlock_t lock;
  612. /* The below variables an all the rps hw state are protected by
  613. * dev->struct mutext. */
  614. u8 cur_delay;
  615. u8 min_delay;
  616. u8 max_delay;
  617. u8 hw_max;
  618. struct delayed_work delayed_resume_work;
  619. /*
  620. * Protects RPS/RC6 register access and PCU communication.
  621. * Must be taken after struct_mutex if nested.
  622. */
  623. struct mutex hw_lock;
  624. };
  625. /* defined intel_pm.c */
  626. extern spinlock_t mchdev_lock;
  627. struct intel_ilk_power_mgmt {
  628. u8 cur_delay;
  629. u8 min_delay;
  630. u8 max_delay;
  631. u8 fmax;
  632. u8 fstart;
  633. u64 last_count1;
  634. unsigned long last_time1;
  635. unsigned long chipset_power;
  636. u64 last_count2;
  637. struct timespec last_time2;
  638. unsigned long gfx_power;
  639. u8 corr;
  640. int c_m;
  641. int r_t;
  642. struct drm_i915_gem_object *pwrctx;
  643. struct drm_i915_gem_object *renderctx;
  644. };
  645. struct i915_dri1_state {
  646. unsigned allow_batchbuffer : 1;
  647. u32 __iomem *gfx_hws_cpu_addr;
  648. unsigned int cpp;
  649. int back_offset;
  650. int front_offset;
  651. int current_page;
  652. int page_flipping;
  653. uint32_t counter;
  654. };
  655. struct intel_l3_parity {
  656. u32 *remap_info;
  657. struct work_struct error_work;
  658. };
  659. struct i915_gem_mm {
  660. /** Memory allocator for GTT stolen memory */
  661. struct drm_mm stolen;
  662. /** Memory allocator for GTT */
  663. struct drm_mm gtt_space;
  664. /** List of all objects in gtt_space. Used to restore gtt
  665. * mappings on resume */
  666. struct list_head bound_list;
  667. /**
  668. * List of objects which are not bound to the GTT (thus
  669. * are idle and not used by the GPU) but still have
  670. * (presumably uncached) pages still attached.
  671. */
  672. struct list_head unbound_list;
  673. /** Usable portion of the GTT for GEM */
  674. unsigned long stolen_base; /* limited to low memory (32-bit) */
  675. int gtt_mtrr;
  676. /** PPGTT used for aliasing the PPGTT with the GTT */
  677. struct i915_hw_ppgtt *aliasing_ppgtt;
  678. struct shrinker inactive_shrinker;
  679. bool shrinker_no_lock_stealing;
  680. /**
  681. * List of objects currently involved in rendering.
  682. *
  683. * Includes buffers having the contents of their GPU caches
  684. * flushed, not necessarily primitives. last_rendering_seqno
  685. * represents when the rendering involved will be completed.
  686. *
  687. * A reference is held on the buffer while on this list.
  688. */
  689. struct list_head active_list;
  690. /**
  691. * LRU list of objects which are not in the ringbuffer and
  692. * are ready to unbind, but are still in the GTT.
  693. *
  694. * last_rendering_seqno is 0 while an object is in this list.
  695. *
  696. * A reference is not held on the buffer while on this list,
  697. * as merely being GTT-bound shouldn't prevent its being
  698. * freed, and we'll pull it off the list in the free path.
  699. */
  700. struct list_head inactive_list;
  701. /** LRU list of objects with fence regs on them. */
  702. struct list_head fence_list;
  703. /**
  704. * We leave the user IRQ off as much as possible,
  705. * but this means that requests will finish and never
  706. * be retired once the system goes idle. Set a timer to
  707. * fire periodically while the ring is running. When it
  708. * fires, go retire requests.
  709. */
  710. struct delayed_work retire_work;
  711. /**
  712. * Are we in a non-interruptible section of code like
  713. * modesetting?
  714. */
  715. bool interruptible;
  716. /**
  717. * Flag if the X Server, and thus DRM, is not currently in
  718. * control of the device.
  719. *
  720. * This is set between LeaveVT and EnterVT. It needs to be
  721. * replaced with a semaphore. It also needs to be
  722. * transitioned away from for kernel modesetting.
  723. */
  724. int suspended;
  725. /** Bit 6 swizzling required for X tiling */
  726. uint32_t bit_6_swizzle_x;
  727. /** Bit 6 swizzling required for Y tiling */
  728. uint32_t bit_6_swizzle_y;
  729. /* storage for physical objects */
  730. struct drm_i915_gem_phys_object *phys_objs[I915_MAX_PHYS_OBJECT];
  731. /* accounting, useful for userland debugging */
  732. size_t object_memory;
  733. u32 object_count;
  734. };
  735. struct i915_gpu_error {
  736. /* For hangcheck timer */
  737. #define DRM_I915_HANGCHECK_PERIOD 1500 /* in ms */
  738. #define DRM_I915_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD)
  739. struct timer_list hangcheck_timer;
  740. int hangcheck_count;
  741. uint32_t last_acthd[I915_NUM_RINGS];
  742. uint32_t prev_instdone[I915_NUM_INSTDONE_REG];
  743. /* For reset and error_state handling. */
  744. spinlock_t lock;
  745. /* Protected by the above dev->gpu_error.lock. */
  746. struct drm_i915_error_state *first_error;
  747. struct work_struct work;
  748. unsigned long last_reset;
  749. /**
  750. * State variable and reset counter controlling the reset flow
  751. *
  752. * Upper bits are for the reset counter. This counter is used by the
  753. * wait_seqno code to race-free noticed that a reset event happened and
  754. * that it needs to restart the entire ioctl (since most likely the
  755. * seqno it waited for won't ever signal anytime soon).
  756. *
  757. * This is important for lock-free wait paths, where no contended lock
  758. * naturally enforces the correct ordering between the bail-out of the
  759. * waiter and the gpu reset work code.
  760. *
  761. * Lowest bit controls the reset state machine: Set means a reset is in
  762. * progress. This state will (presuming we don't have any bugs) decay
  763. * into either unset (successful reset) or the special WEDGED value (hw
  764. * terminally sour). All waiters on the reset_queue will be woken when
  765. * that happens.
  766. */
  767. atomic_t reset_counter;
  768. /**
  769. * Special values/flags for reset_counter
  770. *
  771. * Note that the code relies on
  772. * I915_WEDGED & I915_RESET_IN_PROGRESS_FLAG
  773. * being true.
  774. */
  775. #define I915_RESET_IN_PROGRESS_FLAG 1
  776. #define I915_WEDGED 0xffffffff
  777. /**
  778. * Waitqueue to signal when the reset has completed. Used by clients
  779. * that wait for dev_priv->mm.wedged to settle.
  780. */
  781. wait_queue_head_t reset_queue;
  782. /* For gpu hang simulation. */
  783. unsigned int stop_rings;
  784. };
  785. enum modeset_restore {
  786. MODESET_ON_LID_OPEN,
  787. MODESET_DONE,
  788. MODESET_SUSPENDED,
  789. };
  790. typedef struct drm_i915_private {
  791. struct drm_device *dev;
  792. struct kmem_cache *slab;
  793. const struct intel_device_info *info;
  794. int relative_constants_mode;
  795. void __iomem *regs;
  796. struct drm_i915_gt_funcs gt;
  797. /** gt_fifo_count and the subsequent register write are synchronized
  798. * with dev->struct_mutex. */
  799. unsigned gt_fifo_count;
  800. /** forcewake_count is protected by gt_lock */
  801. unsigned forcewake_count;
  802. /** gt_lock is also taken in irq contexts. */
  803. spinlock_t gt_lock;
  804. struct intel_gmbus gmbus[GMBUS_NUM_PORTS];
  805. /** gmbus_mutex protects against concurrent usage of the single hw gmbus
  806. * controller on different i2c buses. */
  807. struct mutex gmbus_mutex;
  808. /**
  809. * Base address of the gmbus and gpio block.
  810. */
  811. uint32_t gpio_mmio_base;
  812. wait_queue_head_t gmbus_wait_queue;
  813. struct pci_dev *bridge_dev;
  814. struct intel_ring_buffer ring[I915_NUM_RINGS];
  815. uint32_t last_seqno, next_seqno;
  816. drm_dma_handle_t *status_page_dmah;
  817. struct resource mch_res;
  818. atomic_t irq_received;
  819. /* protects the irq masks */
  820. spinlock_t irq_lock;
  821. /* To control wakeup latency, e.g. for irq-driven dp aux transfers. */
  822. struct pm_qos_request pm_qos;
  823. /* DPIO indirect register protection */
  824. struct mutex dpio_lock;
  825. /** Cached value of IMR to avoid reads in updating the bitfield */
  826. u32 irq_mask;
  827. u32 gt_irq_mask;
  828. struct work_struct hotplug_work;
  829. bool enable_hotplug_processing;
  830. struct {
  831. unsigned long hpd_last_jiffies;
  832. int hpd_cnt;
  833. enum {
  834. HPD_ENABLED = 0,
  835. HPD_DISABLED = 1,
  836. HPD_MARK_DISABLED = 2
  837. } hpd_mark;
  838. } hpd_stats[HPD_NUM_PINS];
  839. struct timer_list hotplug_reenable_timer;
  840. int num_pch_pll;
  841. int num_plane;
  842. unsigned long cfb_size;
  843. unsigned int cfb_fb;
  844. enum plane cfb_plane;
  845. int cfb_y;
  846. struct intel_fbc_work *fbc_work;
  847. struct intel_opregion opregion;
  848. /* overlay */
  849. struct intel_overlay *overlay;
  850. unsigned int sprite_scaling_enabled;
  851. /* backlight */
  852. struct {
  853. int level;
  854. bool enabled;
  855. struct backlight_device *device;
  856. } backlight;
  857. /* LVDS info */
  858. struct drm_display_mode *lfp_lvds_vbt_mode; /* if any */
  859. struct drm_display_mode *sdvo_lvds_vbt_mode; /* if any */
  860. /* Feature bits from the VBIOS */
  861. unsigned int int_tv_support:1;
  862. unsigned int lvds_dither:1;
  863. unsigned int lvds_vbt:1;
  864. unsigned int int_crt_support:1;
  865. unsigned int lvds_use_ssc:1;
  866. unsigned int display_clock_mode:1;
  867. unsigned int fdi_rx_polarity_inverted:1;
  868. int lvds_ssc_freq;
  869. unsigned int bios_lvds_val; /* initial [PCH_]LVDS reg val in VBIOS */
  870. struct {
  871. int rate;
  872. int lanes;
  873. int preemphasis;
  874. int vswing;
  875. bool initialized;
  876. bool support;
  877. int bpp;
  878. struct edp_power_seq pps;
  879. } edp;
  880. bool no_aux_handshake;
  881. int crt_ddc_pin;
  882. struct drm_i915_fence_reg fence_regs[I915_MAX_NUM_FENCES]; /* assume 965 */
  883. int fence_reg_start; /* 4 if userland hasn't ioctl'd us yet */
  884. int num_fence_regs; /* 8 on pre-965, 16 otherwise */
  885. unsigned int fsb_freq, mem_freq, is_ddr3;
  886. struct workqueue_struct *wq;
  887. /* Display functions */
  888. struct drm_i915_display_funcs display;
  889. /* PCH chipset type */
  890. enum intel_pch pch_type;
  891. unsigned short pch_id;
  892. unsigned long quirks;
  893. enum modeset_restore modeset_restore;
  894. struct mutex modeset_restore_lock;
  895. struct i915_gtt gtt;
  896. struct i915_gem_mm mm;
  897. /* Kernel Modesetting */
  898. struct sdvo_device_mapping sdvo_mappings[2];
  899. /* indicate whether the LVDS_BORDER should be enabled or not */
  900. unsigned int lvds_border_bits;
  901. /* Panel fitter placement and size for Ironlake+ */
  902. u32 pch_pf_pos, pch_pf_size;
  903. struct drm_crtc *plane_to_crtc_mapping[3];
  904. struct drm_crtc *pipe_to_crtc_mapping[3];
  905. wait_queue_head_t pending_flip_queue;
  906. struct intel_pch_pll pch_plls[I915_NUM_PLLS];
  907. struct intel_ddi_plls ddi_plls;
  908. /* Reclocking support */
  909. bool render_reclock_avail;
  910. bool lvds_downclock_avail;
  911. /* indicates the reduced downclock for LVDS*/
  912. int lvds_downclock;
  913. u16 orig_clock;
  914. int child_dev_num;
  915. struct child_device_config *child_dev;
  916. bool mchbar_need_disable;
  917. struct intel_l3_parity l3_parity;
  918. /* gen6+ rps state */
  919. struct intel_gen6_power_mgmt rps;
  920. /* ilk-only ips/rps state. Everything in here is protected by the global
  921. * mchdev_lock in intel_pm.c */
  922. struct intel_ilk_power_mgmt ips;
  923. enum no_fbc_reason no_fbc_reason;
  924. struct drm_mm_node *compressed_fb;
  925. struct drm_mm_node *compressed_llb;
  926. struct i915_gpu_error gpu_error;
  927. /* list of fbdev register on this device */
  928. struct intel_fbdev *fbdev;
  929. /*
  930. * The console may be contended at resume, but we don't
  931. * want it to block on it.
  932. */
  933. struct work_struct console_resume_work;
  934. struct drm_property *broadcast_rgb_property;
  935. struct drm_property *force_audio_property;
  936. bool hw_contexts_disabled;
  937. uint32_t hw_context_size;
  938. u32 fdi_rx_config;
  939. struct i915_suspend_saved_registers regfile;
  940. /* Old dri1 support infrastructure, beware the dragons ya fools entering
  941. * here! */
  942. struct i915_dri1_state dri1;
  943. } drm_i915_private_t;
  944. /* Iterate over initialised rings */
  945. #define for_each_ring(ring__, dev_priv__, i__) \
  946. for ((i__) = 0; (i__) < I915_NUM_RINGS; (i__)++) \
  947. if (((ring__) = &(dev_priv__)->ring[(i__)]), intel_ring_initialized((ring__)))
  948. enum hdmi_force_audio {
  949. HDMI_AUDIO_OFF_DVI = -2, /* no aux data for HDMI-DVI converter */
  950. HDMI_AUDIO_OFF, /* force turn off HDMI audio */
  951. HDMI_AUDIO_AUTO, /* trust EDID */
  952. HDMI_AUDIO_ON, /* force turn on HDMI audio */
  953. };
  954. #define I915_GTT_RESERVED ((struct drm_mm_node *)0x1)
  955. struct drm_i915_gem_object_ops {
  956. /* Interface between the GEM object and its backing storage.
  957. * get_pages() is called once prior to the use of the associated set
  958. * of pages before to binding them into the GTT, and put_pages() is
  959. * called after we no longer need them. As we expect there to be
  960. * associated cost with migrating pages between the backing storage
  961. * and making them available for the GPU (e.g. clflush), we may hold
  962. * onto the pages after they are no longer referenced by the GPU
  963. * in case they may be used again shortly (for example migrating the
  964. * pages to a different memory domain within the GTT). put_pages()
  965. * will therefore most likely be called when the object itself is
  966. * being released or under memory pressure (where we attempt to
  967. * reap pages for the shrinker).
  968. */
  969. int (*get_pages)(struct drm_i915_gem_object *);
  970. void (*put_pages)(struct drm_i915_gem_object *);
  971. };
  972. struct drm_i915_gem_object {
  973. struct drm_gem_object base;
  974. const struct drm_i915_gem_object_ops *ops;
  975. /** Current space allocated to this object in the GTT, if any. */
  976. struct drm_mm_node *gtt_space;
  977. /** Stolen memory for this object, instead of being backed by shmem. */
  978. struct drm_mm_node *stolen;
  979. struct list_head gtt_list;
  980. /** This object's place on the active/inactive lists */
  981. struct list_head ring_list;
  982. struct list_head mm_list;
  983. /** This object's place in the batchbuffer or on the eviction list */
  984. struct list_head exec_list;
  985. /**
  986. * This is set if the object is on the active lists (has pending
  987. * rendering and so a non-zero seqno), and is not set if it i s on
  988. * inactive (ready to be unbound) list.
  989. */
  990. unsigned int active:1;
  991. /**
  992. * This is set if the object has been written to since last bound
  993. * to the GTT
  994. */
  995. unsigned int dirty:1;
  996. /**
  997. * Fence register bits (if any) for this object. Will be set
  998. * as needed when mapped into the GTT.
  999. * Protected by dev->struct_mutex.
  1000. */
  1001. signed int fence_reg:I915_MAX_NUM_FENCE_BITS;
  1002. /**
  1003. * Advice: are the backing pages purgeable?
  1004. */
  1005. unsigned int madv:2;
  1006. /**
  1007. * Current tiling mode for the object.
  1008. */
  1009. unsigned int tiling_mode:2;
  1010. /**
  1011. * Whether the tiling parameters for the currently associated fence
  1012. * register have changed. Note that for the purposes of tracking
  1013. * tiling changes we also treat the unfenced register, the register
  1014. * slot that the object occupies whilst it executes a fenced
  1015. * command (such as BLT on gen2/3), as a "fence".
  1016. */
  1017. unsigned int fence_dirty:1;
  1018. /** How many users have pinned this object in GTT space. The following
  1019. * users can each hold at most one reference: pwrite/pread, pin_ioctl
  1020. * (via user_pin_count), execbuffer (objects are not allowed multiple
  1021. * times for the same batchbuffer), and the framebuffer code. When
  1022. * switching/pageflipping, the framebuffer code has at most two buffers
  1023. * pinned per crtc.
  1024. *
  1025. * In the worst case this is 1 + 1 + 1 + 2*2 = 7. That would fit into 3
  1026. * bits with absolutely no headroom. So use 4 bits. */
  1027. unsigned int pin_count:4;
  1028. #define DRM_I915_GEM_OBJECT_MAX_PIN_COUNT 0xf
  1029. /**
  1030. * Is the object at the current location in the gtt mappable and
  1031. * fenceable? Used to avoid costly recalculations.
  1032. */
  1033. unsigned int map_and_fenceable:1;
  1034. /**
  1035. * Whether the current gtt mapping needs to be mappable (and isn't just
  1036. * mappable by accident). Track pin and fault separate for a more
  1037. * accurate mappable working set.
  1038. */
  1039. unsigned int fault_mappable:1;
  1040. unsigned int pin_mappable:1;
  1041. /*
  1042. * Is the GPU currently using a fence to access this buffer,
  1043. */
  1044. unsigned int pending_fenced_gpu_access:1;
  1045. unsigned int fenced_gpu_access:1;
  1046. unsigned int cache_level:2;
  1047. unsigned int has_aliasing_ppgtt_mapping:1;
  1048. unsigned int has_global_gtt_mapping:1;
  1049. unsigned int has_dma_mapping:1;
  1050. struct sg_table *pages;
  1051. int pages_pin_count;
  1052. /* prime dma-buf support */
  1053. void *dma_buf_vmapping;
  1054. int vmapping_count;
  1055. /**
  1056. * Used for performing relocations during execbuffer insertion.
  1057. */
  1058. struct hlist_node exec_node;
  1059. unsigned long exec_handle;
  1060. struct drm_i915_gem_exec_object2 *exec_entry;
  1061. /**
  1062. * Current offset of the object in GTT space.
  1063. *
  1064. * This is the same as gtt_space->start
  1065. */
  1066. uint32_t gtt_offset;
  1067. struct intel_ring_buffer *ring;
  1068. /** Breadcrumb of last rendering to the buffer. */
  1069. uint32_t last_read_seqno;
  1070. uint32_t last_write_seqno;
  1071. /** Breadcrumb of last fenced GPU access to the buffer. */
  1072. uint32_t last_fenced_seqno;
  1073. /** Current tiling stride for the object, if it's tiled. */
  1074. uint32_t stride;
  1075. /** Record of address bit 17 of each page at last unbind. */
  1076. unsigned long *bit_17;
  1077. /** User space pin count and filp owning the pin */
  1078. uint32_t user_pin_count;
  1079. struct drm_file *pin_filp;
  1080. /** for phy allocated objects */
  1081. struct drm_i915_gem_phys_object *phys_obj;
  1082. };
  1083. #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
  1084. #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
  1085. /**
  1086. * Request queue structure.
  1087. *
  1088. * The request queue allows us to note sequence numbers that have been emitted
  1089. * and may be associated with active buffers to be retired.
  1090. *
  1091. * By keeping this list, we can avoid having to do questionable
  1092. * sequence-number comparisons on buffer last_rendering_seqnos, and associate
  1093. * an emission time with seqnos for tracking how far ahead of the GPU we are.
  1094. */
  1095. struct drm_i915_gem_request {
  1096. /** On Which ring this request was generated */
  1097. struct intel_ring_buffer *ring;
  1098. /** GEM sequence number associated with this request. */
  1099. uint32_t seqno;
  1100. /** Postion in the ringbuffer of the end of the request */
  1101. u32 tail;
  1102. /** Time at which this request was emitted, in jiffies. */
  1103. unsigned long emitted_jiffies;
  1104. /** global list entry for this request */
  1105. struct list_head list;
  1106. struct drm_i915_file_private *file_priv;
  1107. /** file_priv list entry for this request */
  1108. struct list_head client_list;
  1109. };
  1110. struct drm_i915_file_private {
  1111. struct {
  1112. spinlock_t lock;
  1113. struct list_head request_list;
  1114. } mm;
  1115. struct idr context_idr;
  1116. };
  1117. #define INTEL_INFO(dev) (((struct drm_i915_private *) (dev)->dev_private)->info)
  1118. #define IS_I830(dev) ((dev)->pci_device == 0x3577)
  1119. #define IS_845G(dev) ((dev)->pci_device == 0x2562)
  1120. #define IS_I85X(dev) (INTEL_INFO(dev)->is_i85x)
  1121. #define IS_I865G(dev) ((dev)->pci_device == 0x2572)
  1122. #define IS_I915G(dev) (INTEL_INFO(dev)->is_i915g)
  1123. #define IS_I915GM(dev) ((dev)->pci_device == 0x2592)
  1124. #define IS_I945G(dev) ((dev)->pci_device == 0x2772)
  1125. #define IS_I945GM(dev) (INTEL_INFO(dev)->is_i945gm)
  1126. #define IS_BROADWATER(dev) (INTEL_INFO(dev)->is_broadwater)
  1127. #define IS_CRESTLINE(dev) (INTEL_INFO(dev)->is_crestline)
  1128. #define IS_GM45(dev) ((dev)->pci_device == 0x2A42)
  1129. #define IS_G4X(dev) (INTEL_INFO(dev)->is_g4x)
  1130. #define IS_PINEVIEW_G(dev) ((dev)->pci_device == 0xa001)
  1131. #define IS_PINEVIEW_M(dev) ((dev)->pci_device == 0xa011)
  1132. #define IS_PINEVIEW(dev) (INTEL_INFO(dev)->is_pineview)
  1133. #define IS_G33(dev) (INTEL_INFO(dev)->is_g33)
  1134. #define IS_IRONLAKE_D(dev) ((dev)->pci_device == 0x0042)
  1135. #define IS_IRONLAKE_M(dev) ((dev)->pci_device == 0x0046)
  1136. #define IS_IVYBRIDGE(dev) (INTEL_INFO(dev)->is_ivybridge)
  1137. #define IS_IVB_GT1(dev) ((dev)->pci_device == 0x0156 || \
  1138. (dev)->pci_device == 0x0152 || \
  1139. (dev)->pci_device == 0x015a)
  1140. #define IS_SNB_GT1(dev) ((dev)->pci_device == 0x0102 || \
  1141. (dev)->pci_device == 0x0106 || \
  1142. (dev)->pci_device == 0x010A)
  1143. #define IS_VALLEYVIEW(dev) (INTEL_INFO(dev)->is_valleyview)
  1144. #define IS_HASWELL(dev) (INTEL_INFO(dev)->is_haswell)
  1145. #define IS_MOBILE(dev) (INTEL_INFO(dev)->is_mobile)
  1146. #define IS_ULT(dev) (IS_HASWELL(dev) && \
  1147. ((dev)->pci_device & 0xFF00) == 0x0A00)
  1148. /*
  1149. * The genX designation typically refers to the render engine, so render
  1150. * capability related checks should use IS_GEN, while display and other checks
  1151. * have their own (e.g. HAS_PCH_SPLIT for ILK+ display, IS_foo for particular
  1152. * chips, etc.).
  1153. */
  1154. #define IS_GEN2(dev) (INTEL_INFO(dev)->gen == 2)
  1155. #define IS_GEN3(dev) (INTEL_INFO(dev)->gen == 3)
  1156. #define IS_GEN4(dev) (INTEL_INFO(dev)->gen == 4)
  1157. #define IS_GEN5(dev) (INTEL_INFO(dev)->gen == 5)
  1158. #define IS_GEN6(dev) (INTEL_INFO(dev)->gen == 6)
  1159. #define IS_GEN7(dev) (INTEL_INFO(dev)->gen == 7)
  1160. #define HAS_BSD(dev) (INTEL_INFO(dev)->has_bsd_ring)
  1161. #define HAS_BLT(dev) (INTEL_INFO(dev)->has_blt_ring)
  1162. #define HAS_LLC(dev) (INTEL_INFO(dev)->has_llc)
  1163. #define I915_NEED_GFX_HWS(dev) (INTEL_INFO(dev)->need_gfx_hws)
  1164. #define HAS_HW_CONTEXTS(dev) (INTEL_INFO(dev)->gen >= 6)
  1165. #define HAS_ALIASING_PPGTT(dev) (INTEL_INFO(dev)->gen >=6 && !IS_VALLEYVIEW(dev))
  1166. #define HAS_OVERLAY(dev) (INTEL_INFO(dev)->has_overlay)
  1167. #define OVERLAY_NEEDS_PHYSICAL(dev) (INTEL_INFO(dev)->overlay_needs_physical)
  1168. /* Early gen2 have a totally busted CS tlb and require pinned batches. */
  1169. #define HAS_BROKEN_CS_TLB(dev) (IS_I830(dev) || IS_845G(dev))
  1170. /* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte
  1171. * rows, which changed the alignment requirements and fence programming.
  1172. */
  1173. #define HAS_128_BYTE_Y_TILING(dev) (!IS_GEN2(dev) && !(IS_I915G(dev) || \
  1174. IS_I915GM(dev)))
  1175. #define SUPPORTS_DIGITAL_OUTPUTS(dev) (!IS_GEN2(dev) && !IS_PINEVIEW(dev))
  1176. #define SUPPORTS_INTEGRATED_HDMI(dev) (IS_G4X(dev) || IS_GEN5(dev))
  1177. #define SUPPORTS_INTEGRATED_DP(dev) (IS_G4X(dev) || IS_GEN5(dev))
  1178. #define SUPPORTS_EDP(dev) (IS_IRONLAKE_M(dev))
  1179. #define SUPPORTS_TV(dev) (INTEL_INFO(dev)->supports_tv)
  1180. #define I915_HAS_HOTPLUG(dev) (INTEL_INFO(dev)->has_hotplug)
  1181. /* dsparb controlled by hw only */
  1182. #define DSPARB_HWCONTROL(dev) (IS_G4X(dev) || IS_IRONLAKE(dev))
  1183. #define HAS_FW_BLC(dev) (INTEL_INFO(dev)->gen > 2)
  1184. #define HAS_PIPE_CXSR(dev) (INTEL_INFO(dev)->has_pipe_cxsr)
  1185. #define I915_HAS_FBC(dev) (INTEL_INFO(dev)->has_fbc)
  1186. #define HAS_PIPE_CONTROL(dev) (INTEL_INFO(dev)->gen >= 5)
  1187. #define HAS_DDI(dev) (IS_HASWELL(dev))
  1188. #define HAS_POWER_WELL(dev) (IS_HASWELL(dev))
  1189. #define INTEL_PCH_DEVICE_ID_MASK 0xff00
  1190. #define INTEL_PCH_IBX_DEVICE_ID_TYPE 0x3b00
  1191. #define INTEL_PCH_CPT_DEVICE_ID_TYPE 0x1c00
  1192. #define INTEL_PCH_PPT_DEVICE_ID_TYPE 0x1e00
  1193. #define INTEL_PCH_LPT_DEVICE_ID_TYPE 0x8c00
  1194. #define INTEL_PCH_LPT_LP_DEVICE_ID_TYPE 0x9c00
  1195. #define INTEL_PCH_TYPE(dev) (((struct drm_i915_private *)(dev)->dev_private)->pch_type)
  1196. #define HAS_PCH_LPT(dev) (INTEL_PCH_TYPE(dev) == PCH_LPT)
  1197. #define HAS_PCH_CPT(dev) (INTEL_PCH_TYPE(dev) == PCH_CPT)
  1198. #define HAS_PCH_IBX(dev) (INTEL_PCH_TYPE(dev) == PCH_IBX)
  1199. #define HAS_PCH_NOP(dev) (INTEL_PCH_TYPE(dev) == PCH_NOP)
  1200. #define HAS_PCH_SPLIT(dev) (INTEL_PCH_TYPE(dev) != PCH_NONE)
  1201. #define HAS_FORCE_WAKE(dev) (INTEL_INFO(dev)->has_force_wake)
  1202. #define HAS_L3_GPU_CACHE(dev) (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
  1203. #define GT_FREQUENCY_MULTIPLIER 50
  1204. #include "i915_trace.h"
  1205. /**
  1206. * RC6 is a special power stage which allows the GPU to enter an very
  1207. * low-voltage mode when idle, using down to 0V while at this stage. This
  1208. * stage is entered automatically when the GPU is idle when RC6 support is
  1209. * enabled, and as soon as new workload arises GPU wakes up automatically as well.
  1210. *
  1211. * There are different RC6 modes available in Intel GPU, which differentiate
  1212. * among each other with the latency required to enter and leave RC6 and
  1213. * voltage consumed by the GPU in different states.
  1214. *
  1215. * The combination of the following flags define which states GPU is allowed
  1216. * to enter, while RC6 is the normal RC6 state, RC6p is the deep RC6, and
  1217. * RC6pp is deepest RC6. Their support by hardware varies according to the
  1218. * GPU, BIOS, chipset and platform. RC6 is usually the safest one and the one
  1219. * which brings the most power savings; deeper states save more power, but
  1220. * require higher latency to switch to and wake up.
  1221. */
  1222. #define INTEL_RC6_ENABLE (1<<0)
  1223. #define INTEL_RC6p_ENABLE (1<<1)
  1224. #define INTEL_RC6pp_ENABLE (1<<2)
  1225. extern struct drm_ioctl_desc i915_ioctls[];
  1226. extern int i915_max_ioctl;
  1227. extern unsigned int i915_fbpercrtc __always_unused;
  1228. extern int i915_panel_ignore_lid __read_mostly;
  1229. extern unsigned int i915_powersave __read_mostly;
  1230. extern int i915_semaphores __read_mostly;
  1231. extern unsigned int i915_lvds_downclock __read_mostly;
  1232. extern int i915_lvds_channel_mode __read_mostly;
  1233. extern int i915_panel_use_ssc __read_mostly;
  1234. extern int i915_vbt_sdvo_panel_type __read_mostly;
  1235. extern int i915_enable_rc6 __read_mostly;
  1236. extern int i915_enable_fbc __read_mostly;
  1237. extern bool i915_enable_hangcheck __read_mostly;
  1238. extern int i915_enable_ppgtt __read_mostly;
  1239. extern unsigned int i915_preliminary_hw_support __read_mostly;
  1240. extern int i915_disable_power_well __read_mostly;
  1241. extern int i915_suspend(struct drm_device *dev, pm_message_t state);
  1242. extern int i915_resume(struct drm_device *dev);
  1243. extern int i915_master_create(struct drm_device *dev, struct drm_master *master);
  1244. extern void i915_master_destroy(struct drm_device *dev, struct drm_master *master);
  1245. /* i915_dma.c */
  1246. void i915_update_dri1_breadcrumb(struct drm_device *dev);
  1247. extern void i915_kernel_lost_context(struct drm_device * dev);
  1248. extern int i915_driver_load(struct drm_device *, unsigned long flags);
  1249. extern int i915_driver_unload(struct drm_device *);
  1250. extern int i915_driver_open(struct drm_device *dev, struct drm_file *file_priv);
  1251. extern void i915_driver_lastclose(struct drm_device * dev);
  1252. extern void i915_driver_preclose(struct drm_device *dev,
  1253. struct drm_file *file_priv);
  1254. extern void i915_driver_postclose(struct drm_device *dev,
  1255. struct drm_file *file_priv);
  1256. extern int i915_driver_device_is_agp(struct drm_device * dev);
  1257. #ifdef CONFIG_COMPAT
  1258. extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
  1259. unsigned long arg);
  1260. #endif
  1261. extern int i915_emit_box(struct drm_device *dev,
  1262. struct drm_clip_rect *box,
  1263. int DR1, int DR4);
  1264. extern int intel_gpu_reset(struct drm_device *dev);
  1265. extern int i915_reset(struct drm_device *dev);
  1266. extern unsigned long i915_chipset_val(struct drm_i915_private *dev_priv);
  1267. extern unsigned long i915_mch_val(struct drm_i915_private *dev_priv);
  1268. extern unsigned long i915_gfx_val(struct drm_i915_private *dev_priv);
  1269. extern void i915_update_gfx_val(struct drm_i915_private *dev_priv);
  1270. extern void intel_console_resume(struct work_struct *work);
  1271. /* i915_irq.c */
  1272. void i915_hangcheck_elapsed(unsigned long data);
  1273. void i915_handle_error(struct drm_device *dev, bool wedged);
  1274. extern void intel_irq_init(struct drm_device *dev);
  1275. extern void intel_hpd_init(struct drm_device *dev);
  1276. extern void intel_gt_init(struct drm_device *dev);
  1277. extern void intel_gt_reset(struct drm_device *dev);
  1278. void i915_error_state_free(struct kref *error_ref);
  1279. void
  1280. i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask);
  1281. void
  1282. i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask);
  1283. void intel_enable_asle(struct drm_device *dev);
  1284. #ifdef CONFIG_DEBUG_FS
  1285. extern void i915_destroy_error_state(struct drm_device *dev);
  1286. #else
  1287. #define i915_destroy_error_state(x)
  1288. #endif
  1289. /* i915_gem.c */
  1290. int i915_gem_init_ioctl(struct drm_device *dev, void *data,
  1291. struct drm_file *file_priv);
  1292. int i915_gem_create_ioctl(struct drm_device *dev, void *data,
  1293. struct drm_file *file_priv);
  1294. int i915_gem_pread_ioctl(struct drm_device *dev, void *data,
  1295. struct drm_file *file_priv);
  1296. int i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  1297. struct drm_file *file_priv);
  1298. int i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
  1299. struct drm_file *file_priv);
  1300. int i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data,
  1301. struct drm_file *file_priv);
  1302. int i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  1303. struct drm_file *file_priv);
  1304. int i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
  1305. struct drm_file *file_priv);
  1306. int i915_gem_execbuffer(struct drm_device *dev, void *data,
  1307. struct drm_file *file_priv);
  1308. int i915_gem_execbuffer2(struct drm_device *dev, void *data,
  1309. struct drm_file *file_priv);
  1310. int i915_gem_pin_ioctl(struct drm_device *dev, void *data,
  1311. struct drm_file *file_priv);
  1312. int i915_gem_unpin_ioctl(struct drm_device *dev, void *data,
  1313. struct drm_file *file_priv);
  1314. int i915_gem_busy_ioctl(struct drm_device *dev, void *data,
  1315. struct drm_file *file_priv);
  1316. int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data,
  1317. struct drm_file *file);
  1318. int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
  1319. struct drm_file *file);
  1320. int i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
  1321. struct drm_file *file_priv);
  1322. int i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
  1323. struct drm_file *file_priv);
  1324. int i915_gem_entervt_ioctl(struct drm_device *dev, void *data,
  1325. struct drm_file *file_priv);
  1326. int i915_gem_leavevt_ioctl(struct drm_device *dev, void *data,
  1327. struct drm_file *file_priv);
  1328. int i915_gem_set_tiling(struct drm_device *dev, void *data,
  1329. struct drm_file *file_priv);
  1330. int i915_gem_get_tiling(struct drm_device *dev, void *data,
  1331. struct drm_file *file_priv);
  1332. int i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
  1333. struct drm_file *file_priv);
  1334. int i915_gem_wait_ioctl(struct drm_device *dev, void *data,
  1335. struct drm_file *file_priv);
  1336. void i915_gem_load(struct drm_device *dev);
  1337. void *i915_gem_object_alloc(struct drm_device *dev);
  1338. void i915_gem_object_free(struct drm_i915_gem_object *obj);
  1339. int i915_gem_init_object(struct drm_gem_object *obj);
  1340. void i915_gem_object_init(struct drm_i915_gem_object *obj,
  1341. const struct drm_i915_gem_object_ops *ops);
  1342. struct drm_i915_gem_object *i915_gem_alloc_object(struct drm_device *dev,
  1343. size_t size);
  1344. void i915_gem_free_object(struct drm_gem_object *obj);
  1345. int __must_check i915_gem_object_pin(struct drm_i915_gem_object *obj,
  1346. uint32_t alignment,
  1347. bool map_and_fenceable,
  1348. bool nonblocking);
  1349. void i915_gem_object_unpin(struct drm_i915_gem_object *obj);
  1350. int __must_check i915_gem_object_unbind(struct drm_i915_gem_object *obj);
  1351. int i915_gem_object_put_pages(struct drm_i915_gem_object *obj);
  1352. void i915_gem_release_mmap(struct drm_i915_gem_object *obj);
  1353. void i915_gem_lastclose(struct drm_device *dev);
  1354. int __must_check i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
  1355. static inline struct page *i915_gem_object_get_page(struct drm_i915_gem_object *obj, int n)
  1356. {
  1357. struct sg_page_iter sg_iter;
  1358. for_each_sg_page(obj->pages->sgl, &sg_iter, obj->pages->nents, n)
  1359. return sg_page_iter_page(&sg_iter);
  1360. return NULL;
  1361. }
  1362. static inline void i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
  1363. {
  1364. BUG_ON(obj->pages == NULL);
  1365. obj->pages_pin_count++;
  1366. }
  1367. static inline void i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj)
  1368. {
  1369. BUG_ON(obj->pages_pin_count == 0);
  1370. obj->pages_pin_count--;
  1371. }
  1372. int __must_check i915_mutex_lock_interruptible(struct drm_device *dev);
  1373. int i915_gem_object_sync(struct drm_i915_gem_object *obj,
  1374. struct intel_ring_buffer *to);
  1375. void i915_gem_object_move_to_active(struct drm_i915_gem_object *obj,
  1376. struct intel_ring_buffer *ring);
  1377. int i915_gem_dumb_create(struct drm_file *file_priv,
  1378. struct drm_device *dev,
  1379. struct drm_mode_create_dumb *args);
  1380. int i915_gem_mmap_gtt(struct drm_file *file_priv, struct drm_device *dev,
  1381. uint32_t handle, uint64_t *offset);
  1382. int i915_gem_dumb_destroy(struct drm_file *file_priv, struct drm_device *dev,
  1383. uint32_t handle);
  1384. /**
  1385. * Returns true if seq1 is later than seq2.
  1386. */
  1387. static inline bool
  1388. i915_seqno_passed(uint32_t seq1, uint32_t seq2)
  1389. {
  1390. return (int32_t)(seq1 - seq2) >= 0;
  1391. }
  1392. int __must_check i915_gem_get_seqno(struct drm_device *dev, u32 *seqno);
  1393. int __must_check i915_gem_set_seqno(struct drm_device *dev, u32 seqno);
  1394. int __must_check i915_gem_object_get_fence(struct drm_i915_gem_object *obj);
  1395. int __must_check i915_gem_object_put_fence(struct drm_i915_gem_object *obj);
  1396. static inline bool
  1397. i915_gem_object_pin_fence(struct drm_i915_gem_object *obj)
  1398. {
  1399. if (obj->fence_reg != I915_FENCE_REG_NONE) {
  1400. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  1401. dev_priv->fence_regs[obj->fence_reg].pin_count++;
  1402. return true;
  1403. } else
  1404. return false;
  1405. }
  1406. static inline void
  1407. i915_gem_object_unpin_fence(struct drm_i915_gem_object *obj)
  1408. {
  1409. if (obj->fence_reg != I915_FENCE_REG_NONE) {
  1410. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  1411. dev_priv->fence_regs[obj->fence_reg].pin_count--;
  1412. }
  1413. }
  1414. void i915_gem_retire_requests(struct drm_device *dev);
  1415. void i915_gem_retire_requests_ring(struct intel_ring_buffer *ring);
  1416. int __must_check i915_gem_check_wedge(struct i915_gpu_error *error,
  1417. bool interruptible);
  1418. static inline bool i915_reset_in_progress(struct i915_gpu_error *error)
  1419. {
  1420. return unlikely(atomic_read(&error->reset_counter)
  1421. & I915_RESET_IN_PROGRESS_FLAG);
  1422. }
  1423. static inline bool i915_terminally_wedged(struct i915_gpu_error *error)
  1424. {
  1425. return atomic_read(&error->reset_counter) == I915_WEDGED;
  1426. }
  1427. void i915_gem_reset(struct drm_device *dev);
  1428. void i915_gem_clflush_object(struct drm_i915_gem_object *obj);
  1429. int __must_check i915_gem_object_set_domain(struct drm_i915_gem_object *obj,
  1430. uint32_t read_domains,
  1431. uint32_t write_domain);
  1432. int __must_check i915_gem_object_finish_gpu(struct drm_i915_gem_object *obj);
  1433. int __must_check i915_gem_init(struct drm_device *dev);
  1434. int __must_check i915_gem_init_hw(struct drm_device *dev);
  1435. void i915_gem_l3_remap(struct drm_device *dev);
  1436. void i915_gem_init_swizzling(struct drm_device *dev);
  1437. void i915_gem_cleanup_ringbuffer(struct drm_device *dev);
  1438. int __must_check i915_gpu_idle(struct drm_device *dev);
  1439. int __must_check i915_gem_idle(struct drm_device *dev);
  1440. int i915_add_request(struct intel_ring_buffer *ring,
  1441. struct drm_file *file,
  1442. u32 *seqno);
  1443. int __must_check i915_wait_seqno(struct intel_ring_buffer *ring,
  1444. uint32_t seqno);
  1445. int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
  1446. int __must_check
  1447. i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj,
  1448. bool write);
  1449. int __must_check
  1450. i915_gem_object_set_to_cpu_domain(struct drm_i915_gem_object *obj, bool write);
  1451. int __must_check
  1452. i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
  1453. u32 alignment,
  1454. struct intel_ring_buffer *pipelined);
  1455. int i915_gem_attach_phys_object(struct drm_device *dev,
  1456. struct drm_i915_gem_object *obj,
  1457. int id,
  1458. int align);
  1459. void i915_gem_detach_phys_object(struct drm_device *dev,
  1460. struct drm_i915_gem_object *obj);
  1461. void i915_gem_free_all_phys_object(struct drm_device *dev);
  1462. void i915_gem_release(struct drm_device *dev, struct drm_file *file);
  1463. uint32_t
  1464. i915_gem_get_gtt_size(struct drm_device *dev, uint32_t size, int tiling_mode);
  1465. uint32_t
  1466. i915_gem_get_gtt_alignment(struct drm_device *dev, uint32_t size,
  1467. int tiling_mode, bool fenced);
  1468. int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
  1469. enum i915_cache_level cache_level);
  1470. struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
  1471. struct dma_buf *dma_buf);
  1472. struct dma_buf *i915_gem_prime_export(struct drm_device *dev,
  1473. struct drm_gem_object *gem_obj, int flags);
  1474. /* i915_gem_context.c */
  1475. void i915_gem_context_init(struct drm_device *dev);
  1476. void i915_gem_context_fini(struct drm_device *dev);
  1477. void i915_gem_context_close(struct drm_device *dev, struct drm_file *file);
  1478. int i915_switch_context(struct intel_ring_buffer *ring,
  1479. struct drm_file *file, int to_id);
  1480. int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
  1481. struct drm_file *file);
  1482. int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
  1483. struct drm_file *file);
  1484. /* i915_gem_gtt.c */
  1485. void i915_gem_cleanup_aliasing_ppgtt(struct drm_device *dev);
  1486. void i915_ppgtt_bind_object(struct i915_hw_ppgtt *ppgtt,
  1487. struct drm_i915_gem_object *obj,
  1488. enum i915_cache_level cache_level);
  1489. void i915_ppgtt_unbind_object(struct i915_hw_ppgtt *ppgtt,
  1490. struct drm_i915_gem_object *obj);
  1491. void i915_gem_restore_gtt_mappings(struct drm_device *dev);
  1492. int __must_check i915_gem_gtt_prepare_object(struct drm_i915_gem_object *obj);
  1493. void i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj,
  1494. enum i915_cache_level cache_level);
  1495. void i915_gem_gtt_unbind_object(struct drm_i915_gem_object *obj);
  1496. void i915_gem_gtt_finish_object(struct drm_i915_gem_object *obj);
  1497. void i915_gem_init_global_gtt(struct drm_device *dev);
  1498. void i915_gem_setup_global_gtt(struct drm_device *dev, unsigned long start,
  1499. unsigned long mappable_end, unsigned long end);
  1500. int i915_gem_gtt_init(struct drm_device *dev);
  1501. static inline void i915_gem_chipset_flush(struct drm_device *dev)
  1502. {
  1503. if (INTEL_INFO(dev)->gen < 6)
  1504. intel_gtt_chipset_flush();
  1505. }
  1506. /* i915_gem_evict.c */
  1507. int __must_check i915_gem_evict_something(struct drm_device *dev, int min_size,
  1508. unsigned alignment,
  1509. unsigned cache_level,
  1510. bool mappable,
  1511. bool nonblock);
  1512. int i915_gem_evict_everything(struct drm_device *dev);
  1513. /* i915_gem_stolen.c */
  1514. int i915_gem_init_stolen(struct drm_device *dev);
  1515. int i915_gem_stolen_setup_compression(struct drm_device *dev, int size);
  1516. void i915_gem_stolen_cleanup_compression(struct drm_device *dev);
  1517. void i915_gem_cleanup_stolen(struct drm_device *dev);
  1518. struct drm_i915_gem_object *
  1519. i915_gem_object_create_stolen(struct drm_device *dev, u32 size);
  1520. struct drm_i915_gem_object *
  1521. i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
  1522. u32 stolen_offset,
  1523. u32 gtt_offset,
  1524. u32 size);
  1525. void i915_gem_object_release_stolen(struct drm_i915_gem_object *obj);
  1526. /* i915_gem_tiling.c */
  1527. inline static bool i915_gem_object_needs_bit17_swizzle(struct drm_i915_gem_object *obj)
  1528. {
  1529. drm_i915_private_t *dev_priv = obj->base.dev->dev_private;
  1530. return dev_priv->mm.bit_6_swizzle_x == I915_BIT_6_SWIZZLE_9_10_17 &&
  1531. obj->tiling_mode != I915_TILING_NONE;
  1532. }
  1533. void i915_gem_detect_bit_6_swizzle(struct drm_device *dev);
  1534. void i915_gem_object_do_bit_17_swizzle(struct drm_i915_gem_object *obj);
  1535. void i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj);
  1536. /* i915_gem_debug.c */
  1537. void i915_gem_dump_object(struct drm_i915_gem_object *obj, int len,
  1538. const char *where, uint32_t mark);
  1539. #if WATCH_LISTS
  1540. int i915_verify_lists(struct drm_device *dev);
  1541. #else
  1542. #define i915_verify_lists(dev) 0
  1543. #endif
  1544. void i915_gem_object_check_coherency(struct drm_i915_gem_object *obj,
  1545. int handle);
  1546. void i915_gem_dump_object(struct drm_i915_gem_object *obj, int len,
  1547. const char *where, uint32_t mark);
  1548. /* i915_debugfs.c */
  1549. int i915_debugfs_init(struct drm_minor *minor);
  1550. void i915_debugfs_cleanup(struct drm_minor *minor);
  1551. /* i915_suspend.c */
  1552. extern int i915_save_state(struct drm_device *dev);
  1553. extern int i915_restore_state(struct drm_device *dev);
  1554. /* i915_ums.c */
  1555. void i915_save_display_reg(struct drm_device *dev);
  1556. void i915_restore_display_reg(struct drm_device *dev);
  1557. /* i915_sysfs.c */
  1558. void i915_setup_sysfs(struct drm_device *dev_priv);
  1559. void i915_teardown_sysfs(struct drm_device *dev_priv);
  1560. /* intel_i2c.c */
  1561. extern int intel_setup_gmbus(struct drm_device *dev);
  1562. extern void intel_teardown_gmbus(struct drm_device *dev);
  1563. extern inline bool intel_gmbus_is_port_valid(unsigned port)
  1564. {
  1565. return (port >= GMBUS_PORT_SSC && port <= GMBUS_PORT_DPD);
  1566. }
  1567. extern struct i2c_adapter *intel_gmbus_get_adapter(
  1568. struct drm_i915_private *dev_priv, unsigned port);
  1569. extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
  1570. extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
  1571. extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
  1572. {
  1573. return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
  1574. }
  1575. extern void intel_i2c_reset(struct drm_device *dev);
  1576. /* intel_opregion.c */
  1577. extern int intel_opregion_setup(struct drm_device *dev);
  1578. #ifdef CONFIG_ACPI
  1579. extern void intel_opregion_init(struct drm_device *dev);
  1580. extern void intel_opregion_fini(struct drm_device *dev);
  1581. extern void intel_opregion_asle_intr(struct drm_device *dev);
  1582. extern void intel_opregion_gse_intr(struct drm_device *dev);
  1583. extern void intel_opregion_enable_asle(struct drm_device *dev);
  1584. #else
  1585. static inline void intel_opregion_init(struct drm_device *dev) { return; }
  1586. static inline void intel_opregion_fini(struct drm_device *dev) { return; }
  1587. static inline void intel_opregion_asle_intr(struct drm_device *dev) { return; }
  1588. static inline void intel_opregion_gse_intr(struct drm_device *dev) { return; }
  1589. static inline void intel_opregion_enable_asle(struct drm_device *dev) { return; }
  1590. #endif
  1591. /* intel_acpi.c */
  1592. #ifdef CONFIG_ACPI
  1593. extern void intel_register_dsm_handler(void);
  1594. extern void intel_unregister_dsm_handler(void);
  1595. #else
  1596. static inline void intel_register_dsm_handler(void) { return; }
  1597. static inline void intel_unregister_dsm_handler(void) { return; }
  1598. #endif /* CONFIG_ACPI */
  1599. /* modesetting */
  1600. extern void intel_modeset_init_hw(struct drm_device *dev);
  1601. extern void intel_modeset_init(struct drm_device *dev);
  1602. extern void intel_modeset_gem_init(struct drm_device *dev);
  1603. extern void intel_modeset_cleanup(struct drm_device *dev);
  1604. extern int intel_modeset_vga_set_state(struct drm_device *dev, bool state);
  1605. extern void intel_modeset_setup_hw_state(struct drm_device *dev,
  1606. bool force_restore);
  1607. extern void i915_redisable_vga(struct drm_device *dev);
  1608. extern bool intel_fbc_enabled(struct drm_device *dev);
  1609. extern void intel_disable_fbc(struct drm_device *dev);
  1610. extern bool ironlake_set_drps(struct drm_device *dev, u8 val);
  1611. extern void intel_init_pch_refclk(struct drm_device *dev);
  1612. extern void gen6_set_rps(struct drm_device *dev, u8 val);
  1613. extern void intel_detect_pch(struct drm_device *dev);
  1614. extern int intel_trans_dp_port_sel(struct drm_crtc *crtc);
  1615. extern int intel_enable_rc6(const struct drm_device *dev);
  1616. extern bool i915_semaphore_is_enabled(struct drm_device *dev);
  1617. int i915_reg_read_ioctl(struct drm_device *dev, void *data,
  1618. struct drm_file *file);
  1619. /* overlay */
  1620. #ifdef CONFIG_DEBUG_FS
  1621. extern struct intel_overlay_error_state *intel_overlay_capture_error_state(struct drm_device *dev);
  1622. extern void intel_overlay_print_error_state(struct seq_file *m, struct intel_overlay_error_state *error);
  1623. extern struct intel_display_error_state *intel_display_capture_error_state(struct drm_device *dev);
  1624. extern void intel_display_print_error_state(struct seq_file *m,
  1625. struct drm_device *dev,
  1626. struct intel_display_error_state *error);
  1627. #endif
  1628. /* On SNB platform, before reading ring registers forcewake bit
  1629. * must be set to prevent GT core from power down and stale values being
  1630. * returned.
  1631. */
  1632. void gen6_gt_force_wake_get(struct drm_i915_private *dev_priv);
  1633. void gen6_gt_force_wake_put(struct drm_i915_private *dev_priv);
  1634. int __gen6_gt_wait_for_fifo(struct drm_i915_private *dev_priv);
  1635. int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u8 mbox, u32 *val);
  1636. int sandybridge_pcode_write(struct drm_i915_private *dev_priv, u8 mbox, u32 val);
  1637. int valleyview_punit_read(struct drm_i915_private *dev_priv, u8 addr, u32 *val);
  1638. int valleyview_punit_write(struct drm_i915_private *dev_priv, u8 addr, u32 val);
  1639. #define __i915_read(x, y) \
  1640. u##x i915_read##x(struct drm_i915_private *dev_priv, u32 reg);
  1641. __i915_read(8, b)
  1642. __i915_read(16, w)
  1643. __i915_read(32, l)
  1644. __i915_read(64, q)
  1645. #undef __i915_read
  1646. #define __i915_write(x, y) \
  1647. void i915_write##x(struct drm_i915_private *dev_priv, u32 reg, u##x val);
  1648. __i915_write(8, b)
  1649. __i915_write(16, w)
  1650. __i915_write(32, l)
  1651. __i915_write(64, q)
  1652. #undef __i915_write
  1653. #define I915_READ8(reg) i915_read8(dev_priv, (reg))
  1654. #define I915_WRITE8(reg, val) i915_write8(dev_priv, (reg), (val))
  1655. #define I915_READ16(reg) i915_read16(dev_priv, (reg))
  1656. #define I915_WRITE16(reg, val) i915_write16(dev_priv, (reg), (val))
  1657. #define I915_READ16_NOTRACE(reg) readw(dev_priv->regs + (reg))
  1658. #define I915_WRITE16_NOTRACE(reg, val) writew(val, dev_priv->regs + (reg))
  1659. #define I915_READ(reg) i915_read32(dev_priv, (reg))
  1660. #define I915_WRITE(reg, val) i915_write32(dev_priv, (reg), (val))
  1661. #define I915_READ_NOTRACE(reg) readl(dev_priv->regs + (reg))
  1662. #define I915_WRITE_NOTRACE(reg, val) writel(val, dev_priv->regs + (reg))
  1663. #define I915_WRITE64(reg, val) i915_write64(dev_priv, (reg), (val))
  1664. #define I915_READ64(reg) i915_read64(dev_priv, (reg))
  1665. #define POSTING_READ(reg) (void)I915_READ_NOTRACE(reg)
  1666. #define POSTING_READ16(reg) (void)I915_READ16_NOTRACE(reg)
  1667. /* "Broadcast RGB" property */
  1668. #define INTEL_BROADCAST_RGB_AUTO 0
  1669. #define INTEL_BROADCAST_RGB_FULL 1
  1670. #define INTEL_BROADCAST_RGB_LIMITED 2
  1671. static inline uint32_t i915_vgacntrl_reg(struct drm_device *dev)
  1672. {
  1673. if (HAS_PCH_SPLIT(dev))
  1674. return CPU_VGACNTRL;
  1675. else if (IS_VALLEYVIEW(dev))
  1676. return VLV_VGACNTRL;
  1677. else
  1678. return VGACNTRL;
  1679. }
  1680. static inline void __user *to_user_ptr(u64 address)
  1681. {
  1682. return (void __user *)(uintptr_t)address;
  1683. }
  1684. static inline unsigned long msecs_to_jiffies_timeout(const unsigned int m)
  1685. {
  1686. unsigned long j = msecs_to_jiffies(m);
  1687. return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
  1688. }
  1689. static inline unsigned long
  1690. timespec_to_jiffies_timeout(const struct timespec *value)
  1691. {
  1692. unsigned long j = timespec_to_jiffies(value);
  1693. return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
  1694. }
  1695. #endif