i915_drv.h 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943
  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) sep \
  327. func(has_fpga_dbg)
  328. #define DEFINE_FLAG(name) u8 name:1
  329. #define SEP_SEMICOLON ;
  330. struct intel_device_info {
  331. u32 display_mmio_offset;
  332. u8 num_pipes:3;
  333. u8 gen;
  334. DEV_INFO_FOR_EACH_FLAG(DEFINE_FLAG, SEP_SEMICOLON);
  335. };
  336. #undef DEFINE_FLAG
  337. #undef SEP_SEMICOLON
  338. enum i915_cache_level {
  339. I915_CACHE_NONE = 0,
  340. I915_CACHE_LLC,
  341. I915_CACHE_LLC_MLC, /* gen6+, in docs at least! */
  342. };
  343. typedef uint32_t gen6_gtt_pte_t;
  344. /* The Graphics Translation Table is the way in which GEN hardware translates a
  345. * Graphics Virtual Address into a Physical Address. In addition to the normal
  346. * collateral associated with any va->pa translations GEN hardware also has a
  347. * portion of the GTT which can be mapped by the CPU and remain both coherent
  348. * and correct (in cases like swizzling). That region is referred to as GMADR in
  349. * the spec.
  350. */
  351. struct i915_gtt {
  352. unsigned long start; /* Start offset of used GTT */
  353. size_t total; /* Total size GTT can map */
  354. size_t stolen_size; /* Total size of stolen memory */
  355. unsigned long mappable_end; /* End offset that we can CPU map */
  356. struct io_mapping *mappable; /* Mapping to our CPU mappable region */
  357. phys_addr_t mappable_base; /* PA of our GMADR */
  358. /** "Graphics Stolen Memory" holds the global PTEs */
  359. void __iomem *gsm;
  360. bool do_idle_maps;
  361. dma_addr_t scratch_page_dma;
  362. struct page *scratch_page;
  363. /* global gtt ops */
  364. int (*gtt_probe)(struct drm_device *dev, size_t *gtt_total,
  365. size_t *stolen, phys_addr_t *mappable_base,
  366. unsigned long *mappable_end);
  367. void (*gtt_remove)(struct drm_device *dev);
  368. void (*gtt_clear_range)(struct drm_device *dev,
  369. unsigned int first_entry,
  370. unsigned int num_entries);
  371. void (*gtt_insert_entries)(struct drm_device *dev,
  372. struct sg_table *st,
  373. unsigned int pg_start,
  374. enum i915_cache_level cache_level);
  375. gen6_gtt_pte_t (*pte_encode)(struct drm_device *dev,
  376. dma_addr_t addr,
  377. enum i915_cache_level level);
  378. };
  379. #define gtt_total_entries(gtt) ((gtt).total >> PAGE_SHIFT)
  380. #define I915_PPGTT_PD_ENTRIES 512
  381. #define I915_PPGTT_PT_ENTRIES 1024
  382. struct i915_hw_ppgtt {
  383. struct drm_device *dev;
  384. unsigned num_pd_entries;
  385. struct page **pt_pages;
  386. uint32_t pd_offset;
  387. dma_addr_t *pt_dma_addr;
  388. dma_addr_t scratch_page_dma_addr;
  389. /* pte functions, mirroring the interface of the global gtt. */
  390. void (*clear_range)(struct i915_hw_ppgtt *ppgtt,
  391. unsigned int first_entry,
  392. unsigned int num_entries);
  393. void (*insert_entries)(struct i915_hw_ppgtt *ppgtt,
  394. struct sg_table *st,
  395. unsigned int pg_start,
  396. enum i915_cache_level cache_level);
  397. gen6_gtt_pte_t (*pte_encode)(struct drm_device *dev,
  398. dma_addr_t addr,
  399. enum i915_cache_level level);
  400. int (*enable)(struct drm_device *dev);
  401. void (*cleanup)(struct i915_hw_ppgtt *ppgtt);
  402. };
  403. /* This must match up with the value previously used for execbuf2.rsvd1. */
  404. #define DEFAULT_CONTEXT_ID 0
  405. struct i915_hw_context {
  406. int id;
  407. bool is_initialized;
  408. struct drm_i915_file_private *file_priv;
  409. struct intel_ring_buffer *ring;
  410. struct drm_i915_gem_object *obj;
  411. };
  412. enum no_fbc_reason {
  413. FBC_NO_OUTPUT, /* no outputs enabled to compress */
  414. FBC_STOLEN_TOO_SMALL, /* not enough space to hold compressed buffers */
  415. FBC_UNSUPPORTED_MODE, /* interlace or doublescanned mode */
  416. FBC_MODE_TOO_LARGE, /* mode too large for compression */
  417. FBC_BAD_PLANE, /* fbc not supported on plane */
  418. FBC_NOT_TILED, /* buffer not tiled */
  419. FBC_MULTIPLE_PIPES, /* more than one pipe active */
  420. FBC_MODULE_PARAM,
  421. };
  422. enum intel_pch {
  423. PCH_NONE = 0, /* No PCH present */
  424. PCH_IBX, /* Ibexpeak PCH */
  425. PCH_CPT, /* Cougarpoint PCH */
  426. PCH_LPT, /* Lynxpoint PCH */
  427. PCH_NOP,
  428. };
  429. enum intel_sbi_destination {
  430. SBI_ICLK,
  431. SBI_MPHY,
  432. };
  433. #define QUIRK_PIPEA_FORCE (1<<0)
  434. #define QUIRK_LVDS_SSC_DISABLE (1<<1)
  435. #define QUIRK_INVERT_BRIGHTNESS (1<<2)
  436. struct intel_fbdev;
  437. struct intel_fbc_work;
  438. struct intel_gmbus {
  439. struct i2c_adapter adapter;
  440. u32 force_bit;
  441. u32 reg0;
  442. u32 gpio_reg;
  443. struct i2c_algo_bit_data bit_algo;
  444. struct drm_i915_private *dev_priv;
  445. };
  446. struct i915_suspend_saved_registers {
  447. u8 saveLBB;
  448. u32 saveDSPACNTR;
  449. u32 saveDSPBCNTR;
  450. u32 saveDSPARB;
  451. u32 savePIPEACONF;
  452. u32 savePIPEBCONF;
  453. u32 savePIPEASRC;
  454. u32 savePIPEBSRC;
  455. u32 saveFPA0;
  456. u32 saveFPA1;
  457. u32 saveDPLL_A;
  458. u32 saveDPLL_A_MD;
  459. u32 saveHTOTAL_A;
  460. u32 saveHBLANK_A;
  461. u32 saveHSYNC_A;
  462. u32 saveVTOTAL_A;
  463. u32 saveVBLANK_A;
  464. u32 saveVSYNC_A;
  465. u32 saveBCLRPAT_A;
  466. u32 saveTRANSACONF;
  467. u32 saveTRANS_HTOTAL_A;
  468. u32 saveTRANS_HBLANK_A;
  469. u32 saveTRANS_HSYNC_A;
  470. u32 saveTRANS_VTOTAL_A;
  471. u32 saveTRANS_VBLANK_A;
  472. u32 saveTRANS_VSYNC_A;
  473. u32 savePIPEASTAT;
  474. u32 saveDSPASTRIDE;
  475. u32 saveDSPASIZE;
  476. u32 saveDSPAPOS;
  477. u32 saveDSPAADDR;
  478. u32 saveDSPASURF;
  479. u32 saveDSPATILEOFF;
  480. u32 savePFIT_PGM_RATIOS;
  481. u32 saveBLC_HIST_CTL;
  482. u32 saveBLC_PWM_CTL;
  483. u32 saveBLC_PWM_CTL2;
  484. u32 saveBLC_CPU_PWM_CTL;
  485. u32 saveBLC_CPU_PWM_CTL2;
  486. u32 saveFPB0;
  487. u32 saveFPB1;
  488. u32 saveDPLL_B;
  489. u32 saveDPLL_B_MD;
  490. u32 saveHTOTAL_B;
  491. u32 saveHBLANK_B;
  492. u32 saveHSYNC_B;
  493. u32 saveVTOTAL_B;
  494. u32 saveVBLANK_B;
  495. u32 saveVSYNC_B;
  496. u32 saveBCLRPAT_B;
  497. u32 saveTRANSBCONF;
  498. u32 saveTRANS_HTOTAL_B;
  499. u32 saveTRANS_HBLANK_B;
  500. u32 saveTRANS_HSYNC_B;
  501. u32 saveTRANS_VTOTAL_B;
  502. u32 saveTRANS_VBLANK_B;
  503. u32 saveTRANS_VSYNC_B;
  504. u32 savePIPEBSTAT;
  505. u32 saveDSPBSTRIDE;
  506. u32 saveDSPBSIZE;
  507. u32 saveDSPBPOS;
  508. u32 saveDSPBADDR;
  509. u32 saveDSPBSURF;
  510. u32 saveDSPBTILEOFF;
  511. u32 saveVGA0;
  512. u32 saveVGA1;
  513. u32 saveVGA_PD;
  514. u32 saveVGACNTRL;
  515. u32 saveADPA;
  516. u32 saveLVDS;
  517. u32 savePP_ON_DELAYS;
  518. u32 savePP_OFF_DELAYS;
  519. u32 saveDVOA;
  520. u32 saveDVOB;
  521. u32 saveDVOC;
  522. u32 savePP_ON;
  523. u32 savePP_OFF;
  524. u32 savePP_CONTROL;
  525. u32 savePP_DIVISOR;
  526. u32 savePFIT_CONTROL;
  527. u32 save_palette_a[256];
  528. u32 save_palette_b[256];
  529. u32 saveDPFC_CB_BASE;
  530. u32 saveFBC_CFB_BASE;
  531. u32 saveFBC_LL_BASE;
  532. u32 saveFBC_CONTROL;
  533. u32 saveFBC_CONTROL2;
  534. u32 saveIER;
  535. u32 saveIIR;
  536. u32 saveIMR;
  537. u32 saveDEIER;
  538. u32 saveDEIMR;
  539. u32 saveGTIER;
  540. u32 saveGTIMR;
  541. u32 saveFDI_RXA_IMR;
  542. u32 saveFDI_RXB_IMR;
  543. u32 saveCACHE_MODE_0;
  544. u32 saveMI_ARB_STATE;
  545. u32 saveSWF0[16];
  546. u32 saveSWF1[16];
  547. u32 saveSWF2[3];
  548. u8 saveMSR;
  549. u8 saveSR[8];
  550. u8 saveGR[25];
  551. u8 saveAR_INDEX;
  552. u8 saveAR[21];
  553. u8 saveDACMASK;
  554. u8 saveCR[37];
  555. uint64_t saveFENCE[I915_MAX_NUM_FENCES];
  556. u32 saveCURACNTR;
  557. u32 saveCURAPOS;
  558. u32 saveCURABASE;
  559. u32 saveCURBCNTR;
  560. u32 saveCURBPOS;
  561. u32 saveCURBBASE;
  562. u32 saveCURSIZE;
  563. u32 saveDP_B;
  564. u32 saveDP_C;
  565. u32 saveDP_D;
  566. u32 savePIPEA_GMCH_DATA_M;
  567. u32 savePIPEB_GMCH_DATA_M;
  568. u32 savePIPEA_GMCH_DATA_N;
  569. u32 savePIPEB_GMCH_DATA_N;
  570. u32 savePIPEA_DP_LINK_M;
  571. u32 savePIPEB_DP_LINK_M;
  572. u32 savePIPEA_DP_LINK_N;
  573. u32 savePIPEB_DP_LINK_N;
  574. u32 saveFDI_RXA_CTL;
  575. u32 saveFDI_TXA_CTL;
  576. u32 saveFDI_RXB_CTL;
  577. u32 saveFDI_TXB_CTL;
  578. u32 savePFA_CTL_1;
  579. u32 savePFB_CTL_1;
  580. u32 savePFA_WIN_SZ;
  581. u32 savePFB_WIN_SZ;
  582. u32 savePFA_WIN_POS;
  583. u32 savePFB_WIN_POS;
  584. u32 savePCH_DREF_CONTROL;
  585. u32 saveDISP_ARB_CTL;
  586. u32 savePIPEA_DATA_M1;
  587. u32 savePIPEA_DATA_N1;
  588. u32 savePIPEA_LINK_M1;
  589. u32 savePIPEA_LINK_N1;
  590. u32 savePIPEB_DATA_M1;
  591. u32 savePIPEB_DATA_N1;
  592. u32 savePIPEB_LINK_M1;
  593. u32 savePIPEB_LINK_N1;
  594. u32 saveMCHBAR_RENDER_STANDBY;
  595. u32 savePCH_PORT_HOTPLUG;
  596. };
  597. struct intel_gen6_power_mgmt {
  598. struct work_struct work;
  599. struct delayed_work vlv_work;
  600. u32 pm_iir;
  601. /* lock - irqsave spinlock that protectects the work_struct and
  602. * pm_iir. */
  603. spinlock_t lock;
  604. /* The below variables an all the rps hw state are protected by
  605. * dev->struct mutext. */
  606. u8 cur_delay;
  607. u8 min_delay;
  608. u8 max_delay;
  609. u8 rpe_delay;
  610. u8 hw_max;
  611. struct delayed_work delayed_resume_work;
  612. /*
  613. * Protects RPS/RC6 register access and PCU communication.
  614. * Must be taken after struct_mutex if nested.
  615. */
  616. struct mutex hw_lock;
  617. };
  618. /* defined intel_pm.c */
  619. extern spinlock_t mchdev_lock;
  620. struct intel_ilk_power_mgmt {
  621. u8 cur_delay;
  622. u8 min_delay;
  623. u8 max_delay;
  624. u8 fmax;
  625. u8 fstart;
  626. u64 last_count1;
  627. unsigned long last_time1;
  628. unsigned long chipset_power;
  629. u64 last_count2;
  630. struct timespec last_time2;
  631. unsigned long gfx_power;
  632. u8 corr;
  633. int c_m;
  634. int r_t;
  635. struct drm_i915_gem_object *pwrctx;
  636. struct drm_i915_gem_object *renderctx;
  637. };
  638. struct i915_dri1_state {
  639. unsigned allow_batchbuffer : 1;
  640. u32 __iomem *gfx_hws_cpu_addr;
  641. unsigned int cpp;
  642. int back_offset;
  643. int front_offset;
  644. int current_page;
  645. int page_flipping;
  646. uint32_t counter;
  647. };
  648. struct intel_l3_parity {
  649. u32 *remap_info;
  650. struct work_struct error_work;
  651. };
  652. struct i915_gem_mm {
  653. /** Memory allocator for GTT stolen memory */
  654. struct drm_mm stolen;
  655. /** Memory allocator for GTT */
  656. struct drm_mm gtt_space;
  657. /** List of all objects in gtt_space. Used to restore gtt
  658. * mappings on resume */
  659. struct list_head bound_list;
  660. /**
  661. * List of objects which are not bound to the GTT (thus
  662. * are idle and not used by the GPU) but still have
  663. * (presumably uncached) pages still attached.
  664. */
  665. struct list_head unbound_list;
  666. /** Usable portion of the GTT for GEM */
  667. unsigned long stolen_base; /* limited to low memory (32-bit) */
  668. int gtt_mtrr;
  669. /** PPGTT used for aliasing the PPGTT with the GTT */
  670. struct i915_hw_ppgtt *aliasing_ppgtt;
  671. struct shrinker inactive_shrinker;
  672. bool shrinker_no_lock_stealing;
  673. /**
  674. * List of objects currently involved in rendering.
  675. *
  676. * Includes buffers having the contents of their GPU caches
  677. * flushed, not necessarily primitives. last_rendering_seqno
  678. * represents when the rendering involved will be completed.
  679. *
  680. * A reference is held on the buffer while on this list.
  681. */
  682. struct list_head active_list;
  683. /**
  684. * LRU list of objects which are not in the ringbuffer and
  685. * are ready to unbind, but are still in the GTT.
  686. *
  687. * last_rendering_seqno is 0 while an object is in this list.
  688. *
  689. * A reference is not held on the buffer while on this list,
  690. * as merely being GTT-bound shouldn't prevent its being
  691. * freed, and we'll pull it off the list in the free path.
  692. */
  693. struct list_head inactive_list;
  694. /** LRU list of objects with fence regs on them. */
  695. struct list_head fence_list;
  696. /**
  697. * We leave the user IRQ off as much as possible,
  698. * but this means that requests will finish and never
  699. * be retired once the system goes idle. Set a timer to
  700. * fire periodically while the ring is running. When it
  701. * fires, go retire requests.
  702. */
  703. struct delayed_work retire_work;
  704. /**
  705. * Are we in a non-interruptible section of code like
  706. * modesetting?
  707. */
  708. bool interruptible;
  709. /**
  710. * Flag if the X Server, and thus DRM, is not currently in
  711. * control of the device.
  712. *
  713. * This is set between LeaveVT and EnterVT. It needs to be
  714. * replaced with a semaphore. It also needs to be
  715. * transitioned away from for kernel modesetting.
  716. */
  717. int suspended;
  718. /** Bit 6 swizzling required for X tiling */
  719. uint32_t bit_6_swizzle_x;
  720. /** Bit 6 swizzling required for Y tiling */
  721. uint32_t bit_6_swizzle_y;
  722. /* storage for physical objects */
  723. struct drm_i915_gem_phys_object *phys_objs[I915_MAX_PHYS_OBJECT];
  724. /* accounting, useful for userland debugging */
  725. size_t object_memory;
  726. u32 object_count;
  727. };
  728. struct i915_gpu_error {
  729. /* For hangcheck timer */
  730. #define DRM_I915_HANGCHECK_PERIOD 1500 /* in ms */
  731. #define DRM_I915_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD)
  732. struct timer_list hangcheck_timer;
  733. int hangcheck_count;
  734. uint32_t last_acthd[I915_NUM_RINGS];
  735. uint32_t prev_instdone[I915_NUM_INSTDONE_REG];
  736. /* For reset and error_state handling. */
  737. spinlock_t lock;
  738. /* Protected by the above dev->gpu_error.lock. */
  739. struct drm_i915_error_state *first_error;
  740. struct work_struct work;
  741. unsigned long last_reset;
  742. /**
  743. * State variable and reset counter controlling the reset flow
  744. *
  745. * Upper bits are for the reset counter. This counter is used by the
  746. * wait_seqno code to race-free noticed that a reset event happened and
  747. * that it needs to restart the entire ioctl (since most likely the
  748. * seqno it waited for won't ever signal anytime soon).
  749. *
  750. * This is important for lock-free wait paths, where no contended lock
  751. * naturally enforces the correct ordering between the bail-out of the
  752. * waiter and the gpu reset work code.
  753. *
  754. * Lowest bit controls the reset state machine: Set means a reset is in
  755. * progress. This state will (presuming we don't have any bugs) decay
  756. * into either unset (successful reset) or the special WEDGED value (hw
  757. * terminally sour). All waiters on the reset_queue will be woken when
  758. * that happens.
  759. */
  760. atomic_t reset_counter;
  761. /**
  762. * Special values/flags for reset_counter
  763. *
  764. * Note that the code relies on
  765. * I915_WEDGED & I915_RESET_IN_PROGRESS_FLAG
  766. * being true.
  767. */
  768. #define I915_RESET_IN_PROGRESS_FLAG 1
  769. #define I915_WEDGED 0xffffffff
  770. /**
  771. * Waitqueue to signal when the reset has completed. Used by clients
  772. * that wait for dev_priv->mm.wedged to settle.
  773. */
  774. wait_queue_head_t reset_queue;
  775. /* For gpu hang simulation. */
  776. unsigned int stop_rings;
  777. };
  778. enum modeset_restore {
  779. MODESET_ON_LID_OPEN,
  780. MODESET_DONE,
  781. MODESET_SUSPENDED,
  782. };
  783. typedef struct drm_i915_private {
  784. struct drm_device *dev;
  785. struct kmem_cache *slab;
  786. const struct intel_device_info *info;
  787. int relative_constants_mode;
  788. void __iomem *regs;
  789. struct drm_i915_gt_funcs gt;
  790. /** gt_fifo_count and the subsequent register write are synchronized
  791. * with dev->struct_mutex. */
  792. unsigned gt_fifo_count;
  793. /** forcewake_count is protected by gt_lock */
  794. unsigned forcewake_count;
  795. /** gt_lock is also taken in irq contexts. */
  796. spinlock_t gt_lock;
  797. struct intel_gmbus gmbus[GMBUS_NUM_PORTS];
  798. /** gmbus_mutex protects against concurrent usage of the single hw gmbus
  799. * controller on different i2c buses. */
  800. struct mutex gmbus_mutex;
  801. /**
  802. * Base address of the gmbus and gpio block.
  803. */
  804. uint32_t gpio_mmio_base;
  805. wait_queue_head_t gmbus_wait_queue;
  806. struct pci_dev *bridge_dev;
  807. struct intel_ring_buffer ring[I915_NUM_RINGS];
  808. uint32_t last_seqno, next_seqno;
  809. drm_dma_handle_t *status_page_dmah;
  810. struct resource mch_res;
  811. atomic_t irq_received;
  812. /* protects the irq masks */
  813. spinlock_t irq_lock;
  814. /* To control wakeup latency, e.g. for irq-driven dp aux transfers. */
  815. struct pm_qos_request pm_qos;
  816. /* DPIO indirect register protection */
  817. struct mutex dpio_lock;
  818. /** Cached value of IMR to avoid reads in updating the bitfield */
  819. u32 irq_mask;
  820. u32 gt_irq_mask;
  821. struct work_struct hotplug_work;
  822. bool enable_hotplug_processing;
  823. struct {
  824. unsigned long hpd_last_jiffies;
  825. int hpd_cnt;
  826. enum {
  827. HPD_ENABLED = 0,
  828. HPD_DISABLED = 1,
  829. HPD_MARK_DISABLED = 2
  830. } hpd_mark;
  831. } hpd_stats[HPD_NUM_PINS];
  832. u32 hpd_event_bits;
  833. struct timer_list hotplug_reenable_timer;
  834. int num_pch_pll;
  835. int num_plane;
  836. unsigned long cfb_size;
  837. unsigned int cfb_fb;
  838. enum plane cfb_plane;
  839. int cfb_y;
  840. struct intel_fbc_work *fbc_work;
  841. struct intel_opregion opregion;
  842. /* overlay */
  843. struct intel_overlay *overlay;
  844. unsigned int sprite_scaling_enabled;
  845. /* backlight */
  846. struct {
  847. int level;
  848. bool enabled;
  849. spinlock_t lock; /* bl registers and the above bl fields */
  850. struct backlight_device *device;
  851. } backlight;
  852. /* LVDS info */
  853. struct drm_display_mode *lfp_lvds_vbt_mode; /* if any */
  854. struct drm_display_mode *sdvo_lvds_vbt_mode; /* if any */
  855. /* Feature bits from the VBIOS */
  856. unsigned int int_tv_support:1;
  857. unsigned int lvds_dither:1;
  858. unsigned int lvds_vbt:1;
  859. unsigned int int_crt_support:1;
  860. unsigned int lvds_use_ssc:1;
  861. unsigned int display_clock_mode:1;
  862. unsigned int fdi_rx_polarity_inverted:1;
  863. int lvds_ssc_freq;
  864. unsigned int bios_lvds_val; /* initial [PCH_]LVDS reg val in VBIOS */
  865. struct {
  866. int rate;
  867. int lanes;
  868. int preemphasis;
  869. int vswing;
  870. bool initialized;
  871. bool support;
  872. int bpp;
  873. struct edp_power_seq pps;
  874. } edp;
  875. bool no_aux_handshake;
  876. int crt_ddc_pin;
  877. struct drm_i915_fence_reg fence_regs[I915_MAX_NUM_FENCES]; /* assume 965 */
  878. int fence_reg_start; /* 4 if userland hasn't ioctl'd us yet */
  879. int num_fence_regs; /* 8 on pre-965, 16 otherwise */
  880. unsigned int fsb_freq, mem_freq, is_ddr3;
  881. struct workqueue_struct *wq;
  882. /* Display functions */
  883. struct drm_i915_display_funcs display;
  884. /* PCH chipset type */
  885. enum intel_pch pch_type;
  886. unsigned short pch_id;
  887. unsigned long quirks;
  888. enum modeset_restore modeset_restore;
  889. struct mutex modeset_restore_lock;
  890. struct i915_gtt gtt;
  891. struct i915_gem_mm mm;
  892. /* Kernel Modesetting */
  893. struct sdvo_device_mapping sdvo_mappings[2];
  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) (INTEL_INFO(dev)->has_fpga_dbg)
  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. #ifdef CONFIG_DEBUG_FS
  1276. extern void i915_destroy_error_state(struct drm_device *dev);
  1277. #else
  1278. #define i915_destroy_error_state(x)
  1279. #endif
  1280. /* i915_gem.c */
  1281. int i915_gem_init_ioctl(struct drm_device *dev, void *data,
  1282. struct drm_file *file_priv);
  1283. int i915_gem_create_ioctl(struct drm_device *dev, void *data,
  1284. struct drm_file *file_priv);
  1285. int i915_gem_pread_ioctl(struct drm_device *dev, void *data,
  1286. struct drm_file *file_priv);
  1287. int i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  1288. struct drm_file *file_priv);
  1289. int i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
  1290. struct drm_file *file_priv);
  1291. int i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data,
  1292. struct drm_file *file_priv);
  1293. int i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  1294. struct drm_file *file_priv);
  1295. int i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
  1296. struct drm_file *file_priv);
  1297. int i915_gem_execbuffer(struct drm_device *dev, void *data,
  1298. struct drm_file *file_priv);
  1299. int i915_gem_execbuffer2(struct drm_device *dev, void *data,
  1300. struct drm_file *file_priv);
  1301. int i915_gem_pin_ioctl(struct drm_device *dev, void *data,
  1302. struct drm_file *file_priv);
  1303. int i915_gem_unpin_ioctl(struct drm_device *dev, void *data,
  1304. struct drm_file *file_priv);
  1305. int i915_gem_busy_ioctl(struct drm_device *dev, void *data,
  1306. struct drm_file *file_priv);
  1307. int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data,
  1308. struct drm_file *file);
  1309. int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
  1310. struct drm_file *file);
  1311. int i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
  1312. struct drm_file *file_priv);
  1313. int i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
  1314. struct drm_file *file_priv);
  1315. int i915_gem_entervt_ioctl(struct drm_device *dev, void *data,
  1316. struct drm_file *file_priv);
  1317. int i915_gem_leavevt_ioctl(struct drm_device *dev, void *data,
  1318. struct drm_file *file_priv);
  1319. int i915_gem_set_tiling(struct drm_device *dev, void *data,
  1320. struct drm_file *file_priv);
  1321. int i915_gem_get_tiling(struct drm_device *dev, void *data,
  1322. struct drm_file *file_priv);
  1323. int i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
  1324. struct drm_file *file_priv);
  1325. int i915_gem_wait_ioctl(struct drm_device *dev, void *data,
  1326. struct drm_file *file_priv);
  1327. void i915_gem_load(struct drm_device *dev);
  1328. void *i915_gem_object_alloc(struct drm_device *dev);
  1329. void i915_gem_object_free(struct drm_i915_gem_object *obj);
  1330. int i915_gem_init_object(struct drm_gem_object *obj);
  1331. void i915_gem_object_init(struct drm_i915_gem_object *obj,
  1332. const struct drm_i915_gem_object_ops *ops);
  1333. struct drm_i915_gem_object *i915_gem_alloc_object(struct drm_device *dev,
  1334. size_t size);
  1335. void i915_gem_free_object(struct drm_gem_object *obj);
  1336. int __must_check i915_gem_object_pin(struct drm_i915_gem_object *obj,
  1337. uint32_t alignment,
  1338. bool map_and_fenceable,
  1339. bool nonblocking);
  1340. void i915_gem_object_unpin(struct drm_i915_gem_object *obj);
  1341. int __must_check i915_gem_object_unbind(struct drm_i915_gem_object *obj);
  1342. int i915_gem_object_put_pages(struct drm_i915_gem_object *obj);
  1343. void i915_gem_release_mmap(struct drm_i915_gem_object *obj);
  1344. void i915_gem_lastclose(struct drm_device *dev);
  1345. int __must_check i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
  1346. static inline struct page *i915_gem_object_get_page(struct drm_i915_gem_object *obj, int n)
  1347. {
  1348. struct sg_page_iter sg_iter;
  1349. for_each_sg_page(obj->pages->sgl, &sg_iter, obj->pages->nents, n)
  1350. return sg_page_iter_page(&sg_iter);
  1351. return NULL;
  1352. }
  1353. static inline void i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
  1354. {
  1355. BUG_ON(obj->pages == NULL);
  1356. obj->pages_pin_count++;
  1357. }
  1358. static inline void i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj)
  1359. {
  1360. BUG_ON(obj->pages_pin_count == 0);
  1361. obj->pages_pin_count--;
  1362. }
  1363. int __must_check i915_mutex_lock_interruptible(struct drm_device *dev);
  1364. int i915_gem_object_sync(struct drm_i915_gem_object *obj,
  1365. struct intel_ring_buffer *to);
  1366. void i915_gem_object_move_to_active(struct drm_i915_gem_object *obj,
  1367. struct intel_ring_buffer *ring);
  1368. int i915_gem_dumb_create(struct drm_file *file_priv,
  1369. struct drm_device *dev,
  1370. struct drm_mode_create_dumb *args);
  1371. int i915_gem_mmap_gtt(struct drm_file *file_priv, struct drm_device *dev,
  1372. uint32_t handle, uint64_t *offset);
  1373. int i915_gem_dumb_destroy(struct drm_file *file_priv, struct drm_device *dev,
  1374. uint32_t handle);
  1375. /**
  1376. * Returns true if seq1 is later than seq2.
  1377. */
  1378. static inline bool
  1379. i915_seqno_passed(uint32_t seq1, uint32_t seq2)
  1380. {
  1381. return (int32_t)(seq1 - seq2) >= 0;
  1382. }
  1383. int __must_check i915_gem_get_seqno(struct drm_device *dev, u32 *seqno);
  1384. int __must_check i915_gem_set_seqno(struct drm_device *dev, u32 seqno);
  1385. int __must_check i915_gem_object_get_fence(struct drm_i915_gem_object *obj);
  1386. int __must_check i915_gem_object_put_fence(struct drm_i915_gem_object *obj);
  1387. static inline bool
  1388. i915_gem_object_pin_fence(struct drm_i915_gem_object *obj)
  1389. {
  1390. if (obj->fence_reg != I915_FENCE_REG_NONE) {
  1391. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  1392. dev_priv->fence_regs[obj->fence_reg].pin_count++;
  1393. return true;
  1394. } else
  1395. return false;
  1396. }
  1397. static inline void
  1398. i915_gem_object_unpin_fence(struct drm_i915_gem_object *obj)
  1399. {
  1400. if (obj->fence_reg != I915_FENCE_REG_NONE) {
  1401. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  1402. dev_priv->fence_regs[obj->fence_reg].pin_count--;
  1403. }
  1404. }
  1405. void i915_gem_retire_requests(struct drm_device *dev);
  1406. void i915_gem_retire_requests_ring(struct intel_ring_buffer *ring);
  1407. int __must_check i915_gem_check_wedge(struct i915_gpu_error *error,
  1408. bool interruptible);
  1409. static inline bool i915_reset_in_progress(struct i915_gpu_error *error)
  1410. {
  1411. return unlikely(atomic_read(&error->reset_counter)
  1412. & I915_RESET_IN_PROGRESS_FLAG);
  1413. }
  1414. static inline bool i915_terminally_wedged(struct i915_gpu_error *error)
  1415. {
  1416. return atomic_read(&error->reset_counter) == I915_WEDGED;
  1417. }
  1418. void i915_gem_reset(struct drm_device *dev);
  1419. void i915_gem_clflush_object(struct drm_i915_gem_object *obj);
  1420. int __must_check i915_gem_object_set_domain(struct drm_i915_gem_object *obj,
  1421. uint32_t read_domains,
  1422. uint32_t write_domain);
  1423. int __must_check i915_gem_object_finish_gpu(struct drm_i915_gem_object *obj);
  1424. int __must_check i915_gem_init(struct drm_device *dev);
  1425. int __must_check i915_gem_init_hw(struct drm_device *dev);
  1426. void i915_gem_l3_remap(struct drm_device *dev);
  1427. void i915_gem_init_swizzling(struct drm_device *dev);
  1428. void i915_gem_cleanup_ringbuffer(struct drm_device *dev);
  1429. int __must_check i915_gpu_idle(struct drm_device *dev);
  1430. int __must_check i915_gem_idle(struct drm_device *dev);
  1431. int i915_add_request(struct intel_ring_buffer *ring,
  1432. struct drm_file *file,
  1433. u32 *seqno);
  1434. int __must_check i915_wait_seqno(struct intel_ring_buffer *ring,
  1435. uint32_t seqno);
  1436. int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
  1437. int __must_check
  1438. i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj,
  1439. bool write);
  1440. int __must_check
  1441. i915_gem_object_set_to_cpu_domain(struct drm_i915_gem_object *obj, bool write);
  1442. int __must_check
  1443. i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
  1444. u32 alignment,
  1445. struct intel_ring_buffer *pipelined);
  1446. int i915_gem_attach_phys_object(struct drm_device *dev,
  1447. struct drm_i915_gem_object *obj,
  1448. int id,
  1449. int align);
  1450. void i915_gem_detach_phys_object(struct drm_device *dev,
  1451. struct drm_i915_gem_object *obj);
  1452. void i915_gem_free_all_phys_object(struct drm_device *dev);
  1453. void i915_gem_release(struct drm_device *dev, struct drm_file *file);
  1454. uint32_t
  1455. i915_gem_get_gtt_size(struct drm_device *dev, uint32_t size, int tiling_mode);
  1456. uint32_t
  1457. i915_gem_get_gtt_alignment(struct drm_device *dev, uint32_t size,
  1458. int tiling_mode, bool fenced);
  1459. int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
  1460. enum i915_cache_level cache_level);
  1461. struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
  1462. struct dma_buf *dma_buf);
  1463. struct dma_buf *i915_gem_prime_export(struct drm_device *dev,
  1464. struct drm_gem_object *gem_obj, int flags);
  1465. /* i915_gem_context.c */
  1466. void i915_gem_context_init(struct drm_device *dev);
  1467. void i915_gem_context_fini(struct drm_device *dev);
  1468. void i915_gem_context_close(struct drm_device *dev, struct drm_file *file);
  1469. int i915_switch_context(struct intel_ring_buffer *ring,
  1470. struct drm_file *file, int to_id);
  1471. int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
  1472. struct drm_file *file);
  1473. int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
  1474. struct drm_file *file);
  1475. /* i915_gem_gtt.c */
  1476. void i915_gem_cleanup_aliasing_ppgtt(struct drm_device *dev);
  1477. void i915_ppgtt_bind_object(struct i915_hw_ppgtt *ppgtt,
  1478. struct drm_i915_gem_object *obj,
  1479. enum i915_cache_level cache_level);
  1480. void i915_ppgtt_unbind_object(struct i915_hw_ppgtt *ppgtt,
  1481. struct drm_i915_gem_object *obj);
  1482. void i915_gem_restore_gtt_mappings(struct drm_device *dev);
  1483. int __must_check i915_gem_gtt_prepare_object(struct drm_i915_gem_object *obj);
  1484. void i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj,
  1485. enum i915_cache_level cache_level);
  1486. void i915_gem_gtt_unbind_object(struct drm_i915_gem_object *obj);
  1487. void i915_gem_gtt_finish_object(struct drm_i915_gem_object *obj);
  1488. void i915_gem_init_global_gtt(struct drm_device *dev);
  1489. void i915_gem_setup_global_gtt(struct drm_device *dev, unsigned long start,
  1490. unsigned long mappable_end, unsigned long end);
  1491. int i915_gem_gtt_init(struct drm_device *dev);
  1492. static inline void i915_gem_chipset_flush(struct drm_device *dev)
  1493. {
  1494. if (INTEL_INFO(dev)->gen < 6)
  1495. intel_gtt_chipset_flush();
  1496. }
  1497. /* i915_gem_evict.c */
  1498. int __must_check i915_gem_evict_something(struct drm_device *dev, int min_size,
  1499. unsigned alignment,
  1500. unsigned cache_level,
  1501. bool mappable,
  1502. bool nonblock);
  1503. int i915_gem_evict_everything(struct drm_device *dev);
  1504. /* i915_gem_stolen.c */
  1505. int i915_gem_init_stolen(struct drm_device *dev);
  1506. int i915_gem_stolen_setup_compression(struct drm_device *dev, int size);
  1507. void i915_gem_stolen_cleanup_compression(struct drm_device *dev);
  1508. void i915_gem_cleanup_stolen(struct drm_device *dev);
  1509. struct drm_i915_gem_object *
  1510. i915_gem_object_create_stolen(struct drm_device *dev, u32 size);
  1511. struct drm_i915_gem_object *
  1512. i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
  1513. u32 stolen_offset,
  1514. u32 gtt_offset,
  1515. u32 size);
  1516. void i915_gem_object_release_stolen(struct drm_i915_gem_object *obj);
  1517. /* i915_gem_tiling.c */
  1518. inline static bool i915_gem_object_needs_bit17_swizzle(struct drm_i915_gem_object *obj)
  1519. {
  1520. drm_i915_private_t *dev_priv = obj->base.dev->dev_private;
  1521. return dev_priv->mm.bit_6_swizzle_x == I915_BIT_6_SWIZZLE_9_10_17 &&
  1522. obj->tiling_mode != I915_TILING_NONE;
  1523. }
  1524. void i915_gem_detect_bit_6_swizzle(struct drm_device *dev);
  1525. void i915_gem_object_do_bit_17_swizzle(struct drm_i915_gem_object *obj);
  1526. void i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj);
  1527. /* i915_gem_debug.c */
  1528. void i915_gem_dump_object(struct drm_i915_gem_object *obj, int len,
  1529. const char *where, uint32_t mark);
  1530. #if WATCH_LISTS
  1531. int i915_verify_lists(struct drm_device *dev);
  1532. #else
  1533. #define i915_verify_lists(dev) 0
  1534. #endif
  1535. void i915_gem_object_check_coherency(struct drm_i915_gem_object *obj,
  1536. int handle);
  1537. void i915_gem_dump_object(struct drm_i915_gem_object *obj, int len,
  1538. const char *where, uint32_t mark);
  1539. /* i915_debugfs.c */
  1540. int i915_debugfs_init(struct drm_minor *minor);
  1541. void i915_debugfs_cleanup(struct drm_minor *minor);
  1542. /* i915_suspend.c */
  1543. extern int i915_save_state(struct drm_device *dev);
  1544. extern int i915_restore_state(struct drm_device *dev);
  1545. /* i915_ums.c */
  1546. void i915_save_display_reg(struct drm_device *dev);
  1547. void i915_restore_display_reg(struct drm_device *dev);
  1548. /* i915_sysfs.c */
  1549. void i915_setup_sysfs(struct drm_device *dev_priv);
  1550. void i915_teardown_sysfs(struct drm_device *dev_priv);
  1551. /* intel_i2c.c */
  1552. extern int intel_setup_gmbus(struct drm_device *dev);
  1553. extern void intel_teardown_gmbus(struct drm_device *dev);
  1554. extern inline bool intel_gmbus_is_port_valid(unsigned port)
  1555. {
  1556. return (port >= GMBUS_PORT_SSC && port <= GMBUS_PORT_DPD);
  1557. }
  1558. extern struct i2c_adapter *intel_gmbus_get_adapter(
  1559. struct drm_i915_private *dev_priv, unsigned port);
  1560. extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
  1561. extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
  1562. extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
  1563. {
  1564. return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
  1565. }
  1566. extern void intel_i2c_reset(struct drm_device *dev);
  1567. /* intel_opregion.c */
  1568. extern int intel_opregion_setup(struct drm_device *dev);
  1569. #ifdef CONFIG_ACPI
  1570. extern void intel_opregion_init(struct drm_device *dev);
  1571. extern void intel_opregion_fini(struct drm_device *dev);
  1572. extern void intel_opregion_asle_intr(struct drm_device *dev);
  1573. #else
  1574. static inline void intel_opregion_init(struct drm_device *dev) { return; }
  1575. static inline void intel_opregion_fini(struct drm_device *dev) { return; }
  1576. static inline void intel_opregion_asle_intr(struct drm_device *dev) { return; }
  1577. #endif
  1578. /* intel_acpi.c */
  1579. #ifdef CONFIG_ACPI
  1580. extern void intel_register_dsm_handler(void);
  1581. extern void intel_unregister_dsm_handler(void);
  1582. #else
  1583. static inline void intel_register_dsm_handler(void) { return; }
  1584. static inline void intel_unregister_dsm_handler(void) { return; }
  1585. #endif /* CONFIG_ACPI */
  1586. /* modesetting */
  1587. extern void intel_modeset_init_hw(struct drm_device *dev);
  1588. extern void intel_modeset_init(struct drm_device *dev);
  1589. extern void intel_modeset_gem_init(struct drm_device *dev);
  1590. extern void intel_modeset_cleanup(struct drm_device *dev);
  1591. extern int intel_modeset_vga_set_state(struct drm_device *dev, bool state);
  1592. extern void intel_modeset_setup_hw_state(struct drm_device *dev,
  1593. bool force_restore);
  1594. extern void i915_redisable_vga(struct drm_device *dev);
  1595. extern bool intel_fbc_enabled(struct drm_device *dev);
  1596. extern void intel_disable_fbc(struct drm_device *dev);
  1597. extern bool ironlake_set_drps(struct drm_device *dev, u8 val);
  1598. extern void intel_init_pch_refclk(struct drm_device *dev);
  1599. extern void gen6_set_rps(struct drm_device *dev, u8 val);
  1600. extern void valleyview_set_rps(struct drm_device *dev, u8 val);
  1601. extern int valleyview_rps_max_freq(struct drm_i915_private *dev_priv);
  1602. extern int valleyview_rps_min_freq(struct drm_i915_private *dev_priv);
  1603. extern void intel_detect_pch(struct drm_device *dev);
  1604. extern int intel_trans_dp_port_sel(struct drm_crtc *crtc);
  1605. extern int intel_enable_rc6(const struct drm_device *dev);
  1606. extern bool i915_semaphore_is_enabled(struct drm_device *dev);
  1607. int i915_reg_read_ioctl(struct drm_device *dev, void *data,
  1608. struct drm_file *file);
  1609. /* overlay */
  1610. #ifdef CONFIG_DEBUG_FS
  1611. extern struct intel_overlay_error_state *intel_overlay_capture_error_state(struct drm_device *dev);
  1612. extern void intel_overlay_print_error_state(struct seq_file *m, struct intel_overlay_error_state *error);
  1613. extern struct intel_display_error_state *intel_display_capture_error_state(struct drm_device *dev);
  1614. extern void intel_display_print_error_state(struct seq_file *m,
  1615. struct drm_device *dev,
  1616. struct intel_display_error_state *error);
  1617. #endif
  1618. /* On SNB platform, before reading ring registers forcewake bit
  1619. * must be set to prevent GT core from power down and stale values being
  1620. * returned.
  1621. */
  1622. void gen6_gt_force_wake_get(struct drm_i915_private *dev_priv);
  1623. void gen6_gt_force_wake_put(struct drm_i915_private *dev_priv);
  1624. int __gen6_gt_wait_for_fifo(struct drm_i915_private *dev_priv);
  1625. int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u8 mbox, u32 *val);
  1626. int sandybridge_pcode_write(struct drm_i915_private *dev_priv, u8 mbox, u32 val);
  1627. int valleyview_punit_read(struct drm_i915_private *dev_priv, u8 addr, u32 *val);
  1628. int valleyview_punit_write(struct drm_i915_private *dev_priv, u8 addr, u32 val);
  1629. int valleyview_nc_read(struct drm_i915_private *dev_priv, u8 addr, u32 *val);
  1630. int vlv_gpu_freq(int ddr_freq, int val);
  1631. int vlv_freq_opcode(int ddr_freq, int val);
  1632. #define __i915_read(x, y) \
  1633. u##x i915_read##x(struct drm_i915_private *dev_priv, u32 reg);
  1634. __i915_read(8, b)
  1635. __i915_read(16, w)
  1636. __i915_read(32, l)
  1637. __i915_read(64, q)
  1638. #undef __i915_read
  1639. #define __i915_write(x, y) \
  1640. void i915_write##x(struct drm_i915_private *dev_priv, u32 reg, u##x val);
  1641. __i915_write(8, b)
  1642. __i915_write(16, w)
  1643. __i915_write(32, l)
  1644. __i915_write(64, q)
  1645. #undef __i915_write
  1646. #define I915_READ8(reg) i915_read8(dev_priv, (reg))
  1647. #define I915_WRITE8(reg, val) i915_write8(dev_priv, (reg), (val))
  1648. #define I915_READ16(reg) i915_read16(dev_priv, (reg))
  1649. #define I915_WRITE16(reg, val) i915_write16(dev_priv, (reg), (val))
  1650. #define I915_READ16_NOTRACE(reg) readw(dev_priv->regs + (reg))
  1651. #define I915_WRITE16_NOTRACE(reg, val) writew(val, dev_priv->regs + (reg))
  1652. #define I915_READ(reg) i915_read32(dev_priv, (reg))
  1653. #define I915_WRITE(reg, val) i915_write32(dev_priv, (reg), (val))
  1654. #define I915_READ_NOTRACE(reg) readl(dev_priv->regs + (reg))
  1655. #define I915_WRITE_NOTRACE(reg, val) writel(val, dev_priv->regs + (reg))
  1656. #define I915_WRITE64(reg, val) i915_write64(dev_priv, (reg), (val))
  1657. #define I915_READ64(reg) i915_read64(dev_priv, (reg))
  1658. #define POSTING_READ(reg) (void)I915_READ_NOTRACE(reg)
  1659. #define POSTING_READ16(reg) (void)I915_READ16_NOTRACE(reg)
  1660. /* "Broadcast RGB" property */
  1661. #define INTEL_BROADCAST_RGB_AUTO 0
  1662. #define INTEL_BROADCAST_RGB_FULL 1
  1663. #define INTEL_BROADCAST_RGB_LIMITED 2
  1664. static inline uint32_t i915_vgacntrl_reg(struct drm_device *dev)
  1665. {
  1666. if (HAS_PCH_SPLIT(dev))
  1667. return CPU_VGACNTRL;
  1668. else if (IS_VALLEYVIEW(dev))
  1669. return VLV_VGACNTRL;
  1670. else
  1671. return VGACNTRL;
  1672. }
  1673. static inline void __user *to_user_ptr(u64 address)
  1674. {
  1675. return (void __user *)(uintptr_t)address;
  1676. }
  1677. #endif