i915_drv.h 60 KB

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