i915_drv.h 60 KB

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