i915_drv.h 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  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 "i915_reg.h"
  32. #include "intel_bios.h"
  33. #include "intel_ringbuffer.h"
  34. #include <linux/io-mapping.h>
  35. #include <linux/i2c.h>
  36. #include <drm/intel-gtt.h>
  37. /* General customization:
  38. */
  39. #define DRIVER_AUTHOR "Tungsten Graphics, Inc."
  40. #define DRIVER_NAME "i915"
  41. #define DRIVER_DESC "Intel Graphics"
  42. #define DRIVER_DATE "20080730"
  43. enum pipe {
  44. PIPE_A = 0,
  45. PIPE_B,
  46. };
  47. enum plane {
  48. PLANE_A = 0,
  49. PLANE_B,
  50. };
  51. #define I915_NUM_PIPE 2
  52. #define I915_GEM_GPU_DOMAINS (~(I915_GEM_DOMAIN_CPU | I915_GEM_DOMAIN_GTT))
  53. /* Interface history:
  54. *
  55. * 1.1: Original.
  56. * 1.2: Add Power Management
  57. * 1.3: Add vblank support
  58. * 1.4: Fix cmdbuffer path, add heap destroy
  59. * 1.5: Add vblank pipe configuration
  60. * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
  61. * - Support vertical blank on secondary display pipe
  62. */
  63. #define DRIVER_MAJOR 1
  64. #define DRIVER_MINOR 6
  65. #define DRIVER_PATCHLEVEL 0
  66. #define WATCH_COHERENCY 0
  67. #define WATCH_BUF 0
  68. #define WATCH_EXEC 0
  69. #define WATCH_LRU 0
  70. #define WATCH_RELOC 0
  71. #define WATCH_INACTIVE 0
  72. #define WATCH_PWRITE 0
  73. #define I915_GEM_PHYS_CURSOR_0 1
  74. #define I915_GEM_PHYS_CURSOR_1 2
  75. #define I915_GEM_PHYS_OVERLAY_REGS 3
  76. #define I915_MAX_PHYS_OBJECT (I915_GEM_PHYS_OVERLAY_REGS)
  77. struct drm_i915_gem_phys_object {
  78. int id;
  79. struct page **page_list;
  80. drm_dma_handle_t *handle;
  81. struct drm_gem_object *cur_obj;
  82. };
  83. struct mem_block {
  84. struct mem_block *next;
  85. struct mem_block *prev;
  86. int start;
  87. int size;
  88. struct drm_file *file_priv; /* NULL: free, -1: heap, other: real files */
  89. };
  90. struct opregion_header;
  91. struct opregion_acpi;
  92. struct opregion_swsci;
  93. struct opregion_asle;
  94. struct intel_opregion {
  95. struct opregion_header *header;
  96. struct opregion_acpi *acpi;
  97. struct opregion_swsci *swsci;
  98. struct opregion_asle *asle;
  99. void *vbt;
  100. };
  101. #define OPREGION_SIZE (8*1024)
  102. struct intel_overlay;
  103. struct intel_overlay_error_state;
  104. struct drm_i915_master_private {
  105. drm_local_map_t *sarea;
  106. struct _drm_i915_sarea *sarea_priv;
  107. };
  108. #define I915_FENCE_REG_NONE -1
  109. struct drm_i915_fence_reg {
  110. struct drm_gem_object *obj;
  111. struct list_head lru_list;
  112. bool gpu;
  113. };
  114. struct sdvo_device_mapping {
  115. u8 dvo_port;
  116. u8 slave_addr;
  117. u8 dvo_wiring;
  118. u8 initialized;
  119. u8 ddc_pin;
  120. };
  121. struct drm_i915_error_state {
  122. u32 eir;
  123. u32 pgtbl_er;
  124. u32 pipeastat;
  125. u32 pipebstat;
  126. u32 ipeir;
  127. u32 ipehr;
  128. u32 instdone;
  129. u32 acthd;
  130. u32 instpm;
  131. u32 instps;
  132. u32 instdone1;
  133. u32 seqno;
  134. u64 bbaddr;
  135. struct timeval time;
  136. struct drm_i915_error_object {
  137. int page_count;
  138. u32 gtt_offset;
  139. u32 *pages[0];
  140. } *ringbuffer, *batchbuffer[2];
  141. struct drm_i915_error_buffer {
  142. size_t size;
  143. u32 name;
  144. u32 seqno;
  145. u32 gtt_offset;
  146. u32 read_domains;
  147. u32 write_domain;
  148. u32 fence_reg;
  149. s32 pinned:2;
  150. u32 tiling:2;
  151. u32 dirty:1;
  152. u32 purgeable:1;
  153. } *active_bo;
  154. u32 active_bo_count;
  155. struct intel_overlay_error_state *overlay;
  156. };
  157. struct drm_i915_display_funcs {
  158. void (*dpms)(struct drm_crtc *crtc, int mode);
  159. bool (*fbc_enabled)(struct drm_device *dev);
  160. void (*enable_fbc)(struct drm_crtc *crtc, unsigned long interval);
  161. void (*disable_fbc)(struct drm_device *dev);
  162. int (*get_display_clock_speed)(struct drm_device *dev);
  163. int (*get_fifo_size)(struct drm_device *dev, int plane);
  164. void (*update_wm)(struct drm_device *dev, int planea_clock,
  165. int planeb_clock, int sr_hdisplay, int sr_htotal,
  166. int pixel_size);
  167. /* clock updates for mode set */
  168. /* cursor updates */
  169. /* render clock increase/decrease */
  170. /* display clock increase/decrease */
  171. /* pll clock increase/decrease */
  172. /* clock gating init */
  173. };
  174. struct intel_device_info {
  175. u8 gen;
  176. u8 is_mobile : 1;
  177. u8 is_i85x : 1;
  178. u8 is_i915g : 1;
  179. u8 is_i945gm : 1;
  180. u8 is_g33 : 1;
  181. u8 need_gfx_hws : 1;
  182. u8 is_g4x : 1;
  183. u8 is_pineview : 1;
  184. u8 is_broadwater : 1;
  185. u8 is_crestline : 1;
  186. u8 is_ironlake : 1;
  187. u8 has_fbc : 1;
  188. u8 has_rc6 : 1;
  189. u8 has_pipe_cxsr : 1;
  190. u8 has_hotplug : 1;
  191. u8 cursor_needs_physical : 1;
  192. u8 has_overlay : 1;
  193. u8 overlay_needs_physical : 1;
  194. u8 supports_tv : 1;
  195. u8 has_bsd_ring : 1;
  196. };
  197. enum no_fbc_reason {
  198. FBC_NO_OUTPUT, /* no outputs enabled to compress */
  199. FBC_STOLEN_TOO_SMALL, /* not enough space to hold compressed buffers */
  200. FBC_UNSUPPORTED_MODE, /* interlace or doublescanned mode */
  201. FBC_MODE_TOO_LARGE, /* mode too large for compression */
  202. FBC_BAD_PLANE, /* fbc not supported on plane */
  203. FBC_NOT_TILED, /* buffer not tiled */
  204. FBC_MULTIPLE_PIPES, /* more than one pipe active */
  205. };
  206. enum intel_pch {
  207. PCH_IBX, /* Ibexpeak PCH */
  208. PCH_CPT, /* Cougarpoint PCH */
  209. };
  210. #define QUIRK_PIPEA_FORCE (1<<0)
  211. struct intel_fbdev;
  212. typedef struct drm_i915_private {
  213. struct drm_device *dev;
  214. const struct intel_device_info *info;
  215. int has_gem;
  216. void __iomem *regs;
  217. struct intel_gmbus {
  218. struct i2c_adapter adapter;
  219. struct i2c_adapter *force_bitbanging;
  220. int pin;
  221. } *gmbus;
  222. struct pci_dev *bridge_dev;
  223. struct intel_ring_buffer render_ring;
  224. struct intel_ring_buffer bsd_ring;
  225. uint32_t next_seqno;
  226. drm_dma_handle_t *status_page_dmah;
  227. void *seqno_page;
  228. dma_addr_t dma_status_page;
  229. uint32_t counter;
  230. unsigned int seqno_gfx_addr;
  231. drm_local_map_t hws_map;
  232. struct drm_gem_object *seqno_obj;
  233. struct drm_gem_object *pwrctx;
  234. struct drm_gem_object *renderctx;
  235. struct resource mch_res;
  236. unsigned int cpp;
  237. int back_offset;
  238. int front_offset;
  239. int current_page;
  240. int page_flipping;
  241. #define I915_DEBUG_READ (1<<0)
  242. #define I915_DEBUG_WRITE (1<<1)
  243. unsigned long debug_flags;
  244. wait_queue_head_t irq_queue;
  245. atomic_t irq_received;
  246. /** Protects user_irq_refcount and irq_mask_reg */
  247. spinlock_t user_irq_lock;
  248. u32 trace_irq_seqno;
  249. /** Cached value of IMR to avoid reads in updating the bitfield */
  250. u32 irq_mask_reg;
  251. u32 pipestat[2];
  252. /** splitted irq regs for graphics and display engine on Ironlake,
  253. irq_mask_reg is still used for display irq. */
  254. u32 gt_irq_mask_reg;
  255. u32 gt_irq_enable_reg;
  256. u32 de_irq_enable_reg;
  257. u32 pch_irq_mask_reg;
  258. u32 pch_irq_enable_reg;
  259. u32 hotplug_supported_mask;
  260. struct work_struct hotplug_work;
  261. int tex_lru_log_granularity;
  262. int allow_batchbuffer;
  263. struct mem_block *agp_heap;
  264. unsigned int sr01, adpa, ppcr, dvob, dvoc, lvds;
  265. int vblank_pipe;
  266. int num_pipe;
  267. /* For hangcheck timer */
  268. #define DRM_I915_HANGCHECK_PERIOD 250 /* in ms */
  269. struct timer_list hangcheck_timer;
  270. int hangcheck_count;
  271. uint32_t last_acthd;
  272. uint32_t last_instdone;
  273. uint32_t last_instdone1;
  274. unsigned long cfb_size;
  275. unsigned long cfb_pitch;
  276. unsigned long cfb_offset;
  277. int cfb_fence;
  278. int cfb_plane;
  279. int cfb_y;
  280. int irq_enabled;
  281. struct intel_opregion opregion;
  282. /* overlay */
  283. struct intel_overlay *overlay;
  284. /* LVDS info */
  285. int backlight_level; /* restore backlight to this value */
  286. struct drm_display_mode *panel_fixed_mode;
  287. struct drm_display_mode *lfp_lvds_vbt_mode; /* if any */
  288. struct drm_display_mode *sdvo_lvds_vbt_mode; /* if any */
  289. /* Feature bits from the VBIOS */
  290. unsigned int int_tv_support:1;
  291. unsigned int lvds_dither:1;
  292. unsigned int lvds_vbt:1;
  293. unsigned int int_crt_support:1;
  294. unsigned int lvds_use_ssc:1;
  295. int lvds_ssc_freq;
  296. struct {
  297. u8 rate:4;
  298. u8 lanes:4;
  299. u8 preemphasis:4;
  300. u8 vswing:4;
  301. u8 initialized:1;
  302. u8 support:1;
  303. u8 bpp:6;
  304. } edp;
  305. struct notifier_block lid_notifier;
  306. int crt_ddc_pin;
  307. struct drm_i915_fence_reg fence_regs[16]; /* assume 965 */
  308. int fence_reg_start; /* 4 if userland hasn't ioctl'd us yet */
  309. int num_fence_regs; /* 8 on pre-965, 16 otherwise */
  310. unsigned int fsb_freq, mem_freq, is_ddr3;
  311. spinlock_t error_lock;
  312. struct drm_i915_error_state *first_error;
  313. struct work_struct error_work;
  314. struct workqueue_struct *wq;
  315. /* Display functions */
  316. struct drm_i915_display_funcs display;
  317. /* PCH chipset type */
  318. enum intel_pch pch_type;
  319. unsigned long quirks;
  320. /* Register state */
  321. bool modeset_on_lid;
  322. u8 saveLBB;
  323. u32 saveDSPACNTR;
  324. u32 saveDSPBCNTR;
  325. u32 saveDSPARB;
  326. u32 saveHWS;
  327. u32 savePIPEACONF;
  328. u32 savePIPEBCONF;
  329. u32 savePIPEASRC;
  330. u32 savePIPEBSRC;
  331. u32 saveFPA0;
  332. u32 saveFPA1;
  333. u32 saveDPLL_A;
  334. u32 saveDPLL_A_MD;
  335. u32 saveHTOTAL_A;
  336. u32 saveHBLANK_A;
  337. u32 saveHSYNC_A;
  338. u32 saveVTOTAL_A;
  339. u32 saveVBLANK_A;
  340. u32 saveVSYNC_A;
  341. u32 saveBCLRPAT_A;
  342. u32 saveTRANSACONF;
  343. u32 saveTRANS_HTOTAL_A;
  344. u32 saveTRANS_HBLANK_A;
  345. u32 saveTRANS_HSYNC_A;
  346. u32 saveTRANS_VTOTAL_A;
  347. u32 saveTRANS_VBLANK_A;
  348. u32 saveTRANS_VSYNC_A;
  349. u32 savePIPEASTAT;
  350. u32 saveDSPASTRIDE;
  351. u32 saveDSPASIZE;
  352. u32 saveDSPAPOS;
  353. u32 saveDSPAADDR;
  354. u32 saveDSPASURF;
  355. u32 saveDSPATILEOFF;
  356. u32 savePFIT_PGM_RATIOS;
  357. u32 saveBLC_HIST_CTL;
  358. u32 saveBLC_PWM_CTL;
  359. u32 saveBLC_PWM_CTL2;
  360. u32 saveBLC_CPU_PWM_CTL;
  361. u32 saveBLC_CPU_PWM_CTL2;
  362. u32 saveFPB0;
  363. u32 saveFPB1;
  364. u32 saveDPLL_B;
  365. u32 saveDPLL_B_MD;
  366. u32 saveHTOTAL_B;
  367. u32 saveHBLANK_B;
  368. u32 saveHSYNC_B;
  369. u32 saveVTOTAL_B;
  370. u32 saveVBLANK_B;
  371. u32 saveVSYNC_B;
  372. u32 saveBCLRPAT_B;
  373. u32 saveTRANSBCONF;
  374. u32 saveTRANS_HTOTAL_B;
  375. u32 saveTRANS_HBLANK_B;
  376. u32 saveTRANS_HSYNC_B;
  377. u32 saveTRANS_VTOTAL_B;
  378. u32 saveTRANS_VBLANK_B;
  379. u32 saveTRANS_VSYNC_B;
  380. u32 savePIPEBSTAT;
  381. u32 saveDSPBSTRIDE;
  382. u32 saveDSPBSIZE;
  383. u32 saveDSPBPOS;
  384. u32 saveDSPBADDR;
  385. u32 saveDSPBSURF;
  386. u32 saveDSPBTILEOFF;
  387. u32 saveVGA0;
  388. u32 saveVGA1;
  389. u32 saveVGA_PD;
  390. u32 saveVGACNTRL;
  391. u32 saveADPA;
  392. u32 saveLVDS;
  393. u32 savePP_ON_DELAYS;
  394. u32 savePP_OFF_DELAYS;
  395. u32 saveDVOA;
  396. u32 saveDVOB;
  397. u32 saveDVOC;
  398. u32 savePP_ON;
  399. u32 savePP_OFF;
  400. u32 savePP_CONTROL;
  401. u32 savePP_DIVISOR;
  402. u32 savePFIT_CONTROL;
  403. u32 save_palette_a[256];
  404. u32 save_palette_b[256];
  405. u32 saveDPFC_CB_BASE;
  406. u32 saveFBC_CFB_BASE;
  407. u32 saveFBC_LL_BASE;
  408. u32 saveFBC_CONTROL;
  409. u32 saveFBC_CONTROL2;
  410. u32 saveIER;
  411. u32 saveIIR;
  412. u32 saveIMR;
  413. u32 saveDEIER;
  414. u32 saveDEIMR;
  415. u32 saveGTIER;
  416. u32 saveGTIMR;
  417. u32 saveFDI_RXA_IMR;
  418. u32 saveFDI_RXB_IMR;
  419. u32 saveCACHE_MODE_0;
  420. u32 saveMI_ARB_STATE;
  421. u32 saveSWF0[16];
  422. u32 saveSWF1[16];
  423. u32 saveSWF2[3];
  424. u8 saveMSR;
  425. u8 saveSR[8];
  426. u8 saveGR[25];
  427. u8 saveAR_INDEX;
  428. u8 saveAR[21];
  429. u8 saveDACMASK;
  430. u8 saveCR[37];
  431. uint64_t saveFENCE[16];
  432. u32 saveCURACNTR;
  433. u32 saveCURAPOS;
  434. u32 saveCURABASE;
  435. u32 saveCURBCNTR;
  436. u32 saveCURBPOS;
  437. u32 saveCURBBASE;
  438. u32 saveCURSIZE;
  439. u32 saveDP_B;
  440. u32 saveDP_C;
  441. u32 saveDP_D;
  442. u32 savePIPEA_GMCH_DATA_M;
  443. u32 savePIPEB_GMCH_DATA_M;
  444. u32 savePIPEA_GMCH_DATA_N;
  445. u32 savePIPEB_GMCH_DATA_N;
  446. u32 savePIPEA_DP_LINK_M;
  447. u32 savePIPEB_DP_LINK_M;
  448. u32 savePIPEA_DP_LINK_N;
  449. u32 savePIPEB_DP_LINK_N;
  450. u32 saveFDI_RXA_CTL;
  451. u32 saveFDI_TXA_CTL;
  452. u32 saveFDI_RXB_CTL;
  453. u32 saveFDI_TXB_CTL;
  454. u32 savePFA_CTL_1;
  455. u32 savePFB_CTL_1;
  456. u32 savePFA_WIN_SZ;
  457. u32 savePFB_WIN_SZ;
  458. u32 savePFA_WIN_POS;
  459. u32 savePFB_WIN_POS;
  460. u32 savePCH_DREF_CONTROL;
  461. u32 saveDISP_ARB_CTL;
  462. u32 savePIPEA_DATA_M1;
  463. u32 savePIPEA_DATA_N1;
  464. u32 savePIPEA_LINK_M1;
  465. u32 savePIPEA_LINK_N1;
  466. u32 savePIPEB_DATA_M1;
  467. u32 savePIPEB_DATA_N1;
  468. u32 savePIPEB_LINK_M1;
  469. u32 savePIPEB_LINK_N1;
  470. u32 saveMCHBAR_RENDER_STANDBY;
  471. struct {
  472. /** Bridge to intel-gtt-ko */
  473. struct intel_gtt *gtt;
  474. /** Memory allocator for GTT stolen memory */
  475. struct drm_mm vram;
  476. /** Memory allocator for GTT */
  477. struct drm_mm gtt_space;
  478. struct io_mapping *gtt_mapping;
  479. int gtt_mtrr;
  480. /**
  481. * Membership on list of all loaded devices, used to evict
  482. * inactive buffers under memory pressure.
  483. *
  484. * Modifications should only be done whilst holding the
  485. * shrink_list_lock spinlock.
  486. */
  487. struct list_head shrink_list;
  488. /**
  489. * List of objects which are not in the ringbuffer but which
  490. * still have a write_domain which needs to be flushed before
  491. * unbinding.
  492. *
  493. * last_rendering_seqno is 0 while an object is in this list.
  494. *
  495. * A reference is held on the buffer while on this list.
  496. */
  497. struct list_head flushing_list;
  498. /**
  499. * List of objects currently pending a GPU write flush.
  500. *
  501. * All elements on this list will belong to either the
  502. * active_list or flushing_list, last_rendering_seqno can
  503. * be used to differentiate between the two elements.
  504. */
  505. struct list_head gpu_write_list;
  506. /**
  507. * LRU list of objects which are not in the ringbuffer and
  508. * are ready to unbind, but are still in the GTT.
  509. *
  510. * last_rendering_seqno is 0 while an object is in this list.
  511. *
  512. * A reference is not held on the buffer while on this list,
  513. * as merely being GTT-bound shouldn't prevent its being
  514. * freed, and we'll pull it off the list in the free path.
  515. */
  516. struct list_head inactive_list;
  517. /**
  518. * LRU list of objects which are not in the ringbuffer but
  519. * are still pinned in the GTT.
  520. */
  521. struct list_head pinned_list;
  522. /** LRU list of objects with fence regs on them. */
  523. struct list_head fence_list;
  524. /**
  525. * List of objects currently pending being freed.
  526. *
  527. * These objects are no longer in use, but due to a signal
  528. * we were prevented from freeing them at the appointed time.
  529. */
  530. struct list_head deferred_free_list;
  531. /**
  532. * We leave the user IRQ off as much as possible,
  533. * but this means that requests will finish and never
  534. * be retired once the system goes idle. Set a timer to
  535. * fire periodically while the ring is running. When it
  536. * fires, go retire requests.
  537. */
  538. struct delayed_work retire_work;
  539. /**
  540. * Waiting sequence number, if any
  541. */
  542. uint32_t waiting_gem_seqno;
  543. /**
  544. * Last seq seen at irq time
  545. */
  546. uint32_t irq_gem_seqno;
  547. /**
  548. * Flag if the X Server, and thus DRM, is not currently in
  549. * control of the device.
  550. *
  551. * This is set between LeaveVT and EnterVT. It needs to be
  552. * replaced with a semaphore. It also needs to be
  553. * transitioned away from for kernel modesetting.
  554. */
  555. int suspended;
  556. /**
  557. * Flag if the hardware appears to be wedged.
  558. *
  559. * This is set when attempts to idle the device timeout.
  560. * It prevents command submission from occuring and makes
  561. * every pending request fail
  562. */
  563. atomic_t wedged;
  564. /** Bit 6 swizzling required for X tiling */
  565. uint32_t bit_6_swizzle_x;
  566. /** Bit 6 swizzling required for Y tiling */
  567. uint32_t bit_6_swizzle_y;
  568. /* storage for physical objects */
  569. struct drm_i915_gem_phys_object *phys_objs[I915_MAX_PHYS_OBJECT];
  570. uint32_t flush_rings;
  571. } mm;
  572. struct sdvo_device_mapping sdvo_mappings[2];
  573. /* indicate whether the LVDS_BORDER should be enabled or not */
  574. unsigned int lvds_border_bits;
  575. /* Panel fitter placement and size for Ironlake+ */
  576. u32 pch_pf_pos, pch_pf_size;
  577. struct drm_crtc *plane_to_crtc_mapping[2];
  578. struct drm_crtc *pipe_to_crtc_mapping[2];
  579. wait_queue_head_t pending_flip_queue;
  580. bool flip_pending_is_done;
  581. /* Reclocking support */
  582. bool render_reclock_avail;
  583. bool lvds_downclock_avail;
  584. /* indicates the reduced downclock for LVDS*/
  585. int lvds_downclock;
  586. struct work_struct idle_work;
  587. struct timer_list idle_timer;
  588. bool busy;
  589. u16 orig_clock;
  590. int child_dev_num;
  591. struct child_device_config *child_dev;
  592. struct drm_connector *int_lvds_connector;
  593. bool mchbar_need_disable;
  594. u8 cur_delay;
  595. u8 min_delay;
  596. u8 max_delay;
  597. u8 fmax;
  598. u8 fstart;
  599. u64 last_count1;
  600. unsigned long last_time1;
  601. u64 last_count2;
  602. struct timespec last_time2;
  603. unsigned long gfx_power;
  604. int c_m;
  605. int r_t;
  606. u8 corr;
  607. spinlock_t *mchdev_lock;
  608. enum no_fbc_reason no_fbc_reason;
  609. struct drm_mm_node *compressed_fb;
  610. struct drm_mm_node *compressed_llb;
  611. /* list of fbdev register on this device */
  612. struct intel_fbdev *fbdev;
  613. } drm_i915_private_t;
  614. /** driver private structure attached to each drm_gem_object */
  615. struct drm_i915_gem_object {
  616. struct drm_gem_object base;
  617. /** Current space allocated to this object in the GTT, if any. */
  618. struct drm_mm_node *gtt_space;
  619. /** This object's place on the active/flushing/inactive lists */
  620. struct list_head list;
  621. /** This object's place on GPU write list */
  622. struct list_head gpu_write_list;
  623. /** This object's place on eviction list */
  624. struct list_head evict_list;
  625. /**
  626. * This is set if the object is on the active or flushing lists
  627. * (has pending rendering), and is not set if it's on inactive (ready
  628. * to be unbound).
  629. */
  630. unsigned int active : 1;
  631. /**
  632. * This is set if the object has been written to since last bound
  633. * to the GTT
  634. */
  635. unsigned int dirty : 1;
  636. /**
  637. * Fence register bits (if any) for this object. Will be set
  638. * as needed when mapped into the GTT.
  639. * Protected by dev->struct_mutex.
  640. *
  641. * Size: 4 bits for 16 fences + sign (for FENCE_REG_NONE)
  642. */
  643. signed int fence_reg : 5;
  644. /**
  645. * Used for checking the object doesn't appear more than once
  646. * in an execbuffer object list.
  647. */
  648. unsigned int in_execbuffer : 1;
  649. /**
  650. * Advice: are the backing pages purgeable?
  651. */
  652. unsigned int madv : 2;
  653. /**
  654. * Refcount for the pages array. With the current locking scheme, there
  655. * are at most two concurrent users: Binding a bo to the gtt and
  656. * pwrite/pread using physical addresses. So two bits for a maximum
  657. * of two users are enough.
  658. */
  659. unsigned int pages_refcount : 2;
  660. #define DRM_I915_GEM_OBJECT_MAX_PAGES_REFCOUNT 0x3
  661. /**
  662. * Current tiling mode for the object.
  663. */
  664. unsigned int tiling_mode : 2;
  665. /** How many users have pinned this object in GTT space. The following
  666. * users can each hold at most one reference: pwrite/pread, pin_ioctl
  667. * (via user_pin_count), execbuffer (objects are not allowed multiple
  668. * times for the same batchbuffer), and the framebuffer code. When
  669. * switching/pageflipping, the framebuffer code has at most two buffers
  670. * pinned per crtc.
  671. *
  672. * In the worst case this is 1 + 1 + 1 + 2*2 = 7. That would fit into 3
  673. * bits with absolutely no headroom. So use 4 bits. */
  674. unsigned int pin_count : 4;
  675. #define DRM_I915_GEM_OBJECT_MAX_PIN_COUNT 0xf
  676. /** AGP memory structure for our GTT binding. */
  677. DRM_AGP_MEM *agp_mem;
  678. struct page **pages;
  679. /**
  680. * Current offset of the object in GTT space.
  681. *
  682. * This is the same as gtt_space->start
  683. */
  684. uint32_t gtt_offset;
  685. /* Which ring is refering to is this object */
  686. struct intel_ring_buffer *ring;
  687. /**
  688. * Fake offset for use by mmap(2)
  689. */
  690. uint64_t mmap_offset;
  691. /** Breadcrumb of last rendering to the buffer. */
  692. uint32_t last_rendering_seqno;
  693. /** Current tiling stride for the object, if it's tiled. */
  694. uint32_t stride;
  695. /** Record of address bit 17 of each page at last unbind. */
  696. unsigned long *bit_17;
  697. /** AGP mapping type (AGP_USER_MEMORY or AGP_USER_CACHED_MEMORY */
  698. uint32_t agp_type;
  699. /**
  700. * If present, while GEM_DOMAIN_CPU is in the read domain this array
  701. * flags which individual pages are valid.
  702. */
  703. uint8_t *page_cpu_valid;
  704. /** User space pin count and filp owning the pin */
  705. uint32_t user_pin_count;
  706. struct drm_file *pin_filp;
  707. /** for phy allocated objects */
  708. struct drm_i915_gem_phys_object *phys_obj;
  709. /**
  710. * Number of crtcs where this object is currently the fb, but
  711. * will be page flipped away on the next vblank. When it
  712. * reaches 0, dev_priv->pending_flip_queue will be woken up.
  713. */
  714. atomic_t pending_flip;
  715. };
  716. #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
  717. /**
  718. * Request queue structure.
  719. *
  720. * The request queue allows us to note sequence numbers that have been emitted
  721. * and may be associated with active buffers to be retired.
  722. *
  723. * By keeping this list, we can avoid having to do questionable
  724. * sequence-number comparisons on buffer last_rendering_seqnos, and associate
  725. * an emission time with seqnos for tracking how far ahead of the GPU we are.
  726. */
  727. struct drm_i915_gem_request {
  728. /** On Which ring this request was generated */
  729. struct intel_ring_buffer *ring;
  730. /** GEM sequence number associated with this request. */
  731. uint32_t seqno;
  732. /** Time at which this request was emitted, in jiffies. */
  733. unsigned long emitted_jiffies;
  734. /** global list entry for this request */
  735. struct list_head list;
  736. struct drm_i915_file_private *file_priv;
  737. /** file_priv list entry for this request */
  738. struct list_head client_list;
  739. };
  740. struct drm_i915_file_private {
  741. struct mutex mutex;
  742. struct {
  743. struct list_head request_list;
  744. } mm;
  745. };
  746. enum intel_chip_family {
  747. CHIP_I8XX = 0x01,
  748. CHIP_I9XX = 0x02,
  749. CHIP_I915 = 0x04,
  750. CHIP_I965 = 0x08,
  751. };
  752. extern struct drm_ioctl_desc i915_ioctls[];
  753. extern int i915_max_ioctl;
  754. extern unsigned int i915_fbpercrtc;
  755. extern unsigned int i915_powersave;
  756. extern unsigned int i915_lvds_downclock;
  757. extern int i915_suspend(struct drm_device *dev, pm_message_t state);
  758. extern int i915_resume(struct drm_device *dev);
  759. extern void i915_save_display(struct drm_device *dev);
  760. extern void i915_restore_display(struct drm_device *dev);
  761. extern int i915_master_create(struct drm_device *dev, struct drm_master *master);
  762. extern void i915_master_destroy(struct drm_device *dev, struct drm_master *master);
  763. /* i915_dma.c */
  764. extern void i915_kernel_lost_context(struct drm_device * dev);
  765. extern int i915_driver_load(struct drm_device *, unsigned long flags);
  766. extern int i915_driver_unload(struct drm_device *);
  767. extern int i915_driver_open(struct drm_device *dev, struct drm_file *file_priv);
  768. extern void i915_driver_lastclose(struct drm_device * dev);
  769. extern void i915_driver_preclose(struct drm_device *dev,
  770. struct drm_file *file_priv);
  771. extern void i915_driver_postclose(struct drm_device *dev,
  772. struct drm_file *file_priv);
  773. extern int i915_driver_device_is_agp(struct drm_device * dev);
  774. extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
  775. unsigned long arg);
  776. extern int i915_emit_box(struct drm_device *dev,
  777. struct drm_clip_rect *boxes,
  778. int i, int DR1, int DR4);
  779. extern int i915_reset(struct drm_device *dev, u8 flags);
  780. extern unsigned long i915_chipset_val(struct drm_i915_private *dev_priv);
  781. extern unsigned long i915_mch_val(struct drm_i915_private *dev_priv);
  782. extern unsigned long i915_gfx_val(struct drm_i915_private *dev_priv);
  783. extern void i915_update_gfx_val(struct drm_i915_private *dev_priv);
  784. /* i915_irq.c */
  785. void i915_hangcheck_elapsed(unsigned long data);
  786. extern int i915_irq_emit(struct drm_device *dev, void *data,
  787. struct drm_file *file_priv);
  788. extern int i915_irq_wait(struct drm_device *dev, void *data,
  789. struct drm_file *file_priv);
  790. void i915_trace_irq_get(struct drm_device *dev, u32 seqno);
  791. extern void i915_enable_interrupt (struct drm_device *dev);
  792. extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS);
  793. extern void i915_driver_irq_preinstall(struct drm_device * dev);
  794. extern int i915_driver_irq_postinstall(struct drm_device *dev);
  795. extern void i915_driver_irq_uninstall(struct drm_device * dev);
  796. extern int i915_vblank_pipe_set(struct drm_device *dev, void *data,
  797. struct drm_file *file_priv);
  798. extern int i915_vblank_pipe_get(struct drm_device *dev, void *data,
  799. struct drm_file *file_priv);
  800. extern int i915_enable_vblank(struct drm_device *dev, int crtc);
  801. extern void i915_disable_vblank(struct drm_device *dev, int crtc);
  802. extern u32 i915_get_vblank_counter(struct drm_device *dev, int crtc);
  803. extern u32 gm45_get_vblank_counter(struct drm_device *dev, int crtc);
  804. extern int i915_vblank_swap(struct drm_device *dev, void *data,
  805. struct drm_file *file_priv);
  806. extern void i915_enable_irq(drm_i915_private_t *dev_priv, u32 mask);
  807. extern void i915_disable_irq(drm_i915_private_t *dev_priv, u32 mask);
  808. extern void ironlake_enable_graphics_irq(drm_i915_private_t *dev_priv,
  809. u32 mask);
  810. extern void ironlake_disable_graphics_irq(drm_i915_private_t *dev_priv,
  811. u32 mask);
  812. void
  813. i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask);
  814. void
  815. i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask);
  816. void intel_enable_asle (struct drm_device *dev);
  817. #ifdef CONFIG_DEBUG_FS
  818. extern void i915_destroy_error_state(struct drm_device *dev);
  819. #else
  820. #define i915_destroy_error_state(x)
  821. #endif
  822. /* i915_mem.c */
  823. extern int i915_mem_alloc(struct drm_device *dev, void *data,
  824. struct drm_file *file_priv);
  825. extern int i915_mem_free(struct drm_device *dev, void *data,
  826. struct drm_file *file_priv);
  827. extern int i915_mem_init_heap(struct drm_device *dev, void *data,
  828. struct drm_file *file_priv);
  829. extern int i915_mem_destroy_heap(struct drm_device *dev, void *data,
  830. struct drm_file *file_priv);
  831. extern void i915_mem_takedown(struct mem_block **heap);
  832. extern void i915_mem_release(struct drm_device * dev,
  833. struct drm_file *file_priv, struct mem_block *heap);
  834. /* i915_gem.c */
  835. int i915_gem_init_ioctl(struct drm_device *dev, void *data,
  836. struct drm_file *file_priv);
  837. int i915_gem_create_ioctl(struct drm_device *dev, void *data,
  838. struct drm_file *file_priv);
  839. int i915_gem_pread_ioctl(struct drm_device *dev, void *data,
  840. struct drm_file *file_priv);
  841. int i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  842. struct drm_file *file_priv);
  843. int i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
  844. struct drm_file *file_priv);
  845. int i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data,
  846. struct drm_file *file_priv);
  847. int i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  848. struct drm_file *file_priv);
  849. int i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
  850. struct drm_file *file_priv);
  851. int i915_gem_execbuffer(struct drm_device *dev, void *data,
  852. struct drm_file *file_priv);
  853. int i915_gem_execbuffer2(struct drm_device *dev, void *data,
  854. struct drm_file *file_priv);
  855. int i915_gem_pin_ioctl(struct drm_device *dev, void *data,
  856. struct drm_file *file_priv);
  857. int i915_gem_unpin_ioctl(struct drm_device *dev, void *data,
  858. struct drm_file *file_priv);
  859. int i915_gem_busy_ioctl(struct drm_device *dev, void *data,
  860. struct drm_file *file_priv);
  861. int i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
  862. struct drm_file *file_priv);
  863. int i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
  864. struct drm_file *file_priv);
  865. int i915_gem_entervt_ioctl(struct drm_device *dev, void *data,
  866. struct drm_file *file_priv);
  867. int i915_gem_leavevt_ioctl(struct drm_device *dev, void *data,
  868. struct drm_file *file_priv);
  869. int i915_gem_set_tiling(struct drm_device *dev, void *data,
  870. struct drm_file *file_priv);
  871. int i915_gem_get_tiling(struct drm_device *dev, void *data,
  872. struct drm_file *file_priv);
  873. int i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
  874. struct drm_file *file_priv);
  875. void i915_gem_load(struct drm_device *dev);
  876. int i915_gem_init_object(struct drm_gem_object *obj);
  877. struct drm_gem_object * i915_gem_alloc_object(struct drm_device *dev,
  878. size_t size);
  879. void i915_gem_free_object(struct drm_gem_object *obj);
  880. int i915_gem_object_pin(struct drm_gem_object *obj, uint32_t alignment);
  881. void i915_gem_object_unpin(struct drm_gem_object *obj);
  882. int i915_gem_object_unbind(struct drm_gem_object *obj);
  883. void i915_gem_release_mmap(struct drm_gem_object *obj);
  884. void i915_gem_lastclose(struct drm_device *dev);
  885. /**
  886. * Returns true if seq1 is later than seq2.
  887. */
  888. static inline bool
  889. i915_seqno_passed(uint32_t seq1, uint32_t seq2)
  890. {
  891. return (int32_t)(seq1 - seq2) >= 0;
  892. }
  893. int i915_gem_object_get_fence_reg(struct drm_gem_object *obj,
  894. bool interruptible);
  895. int i915_gem_object_put_fence_reg(struct drm_gem_object *obj,
  896. bool interruptible);
  897. void i915_gem_retire_requests(struct drm_device *dev);
  898. void i915_gem_reset_lists(struct drm_device *dev);
  899. void i915_gem_clflush_object(struct drm_gem_object *obj);
  900. int i915_gem_object_set_domain(struct drm_gem_object *obj,
  901. uint32_t read_domains,
  902. uint32_t write_domain);
  903. int i915_gem_init_ringbuffer(struct drm_device *dev);
  904. void i915_gem_cleanup_ringbuffer(struct drm_device *dev);
  905. int i915_gem_do_init(struct drm_device *dev, unsigned long start,
  906. unsigned long end);
  907. int i915_gpu_idle(struct drm_device *dev);
  908. int i915_gem_idle(struct drm_device *dev);
  909. uint32_t i915_add_request(struct drm_device *dev,
  910. struct drm_file *file_priv,
  911. struct drm_i915_gem_request *request,
  912. struct intel_ring_buffer *ring);
  913. int i915_do_wait_request(struct drm_device *dev,
  914. uint32_t seqno,
  915. bool interruptible,
  916. struct intel_ring_buffer *ring);
  917. int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
  918. int i915_gem_object_set_to_gtt_domain(struct drm_gem_object *obj,
  919. int write);
  920. int i915_gem_object_set_to_display_plane(struct drm_gem_object *obj,
  921. bool pipelined);
  922. int i915_gem_attach_phys_object(struct drm_device *dev,
  923. struct drm_gem_object *obj,
  924. int id,
  925. int align);
  926. void i915_gem_detach_phys_object(struct drm_device *dev,
  927. struct drm_gem_object *obj);
  928. void i915_gem_free_all_phys_object(struct drm_device *dev);
  929. int i915_gem_object_get_pages(struct drm_gem_object *obj, gfp_t gfpmask);
  930. void i915_gem_object_put_pages(struct drm_gem_object *obj);
  931. void i915_gem_release(struct drm_device * dev, struct drm_file *file_priv);
  932. void i915_gem_shrinker_init(void);
  933. void i915_gem_shrinker_exit(void);
  934. /* i915_gem_evict.c */
  935. int i915_gem_evict_something(struct drm_device *dev, int min_size, unsigned alignment);
  936. int i915_gem_evict_everything(struct drm_device *dev);
  937. int i915_gem_evict_inactive(struct drm_device *dev);
  938. /* i915_gem_tiling.c */
  939. void i915_gem_detect_bit_6_swizzle(struct drm_device *dev);
  940. void i915_gem_object_do_bit_17_swizzle(struct drm_gem_object *obj);
  941. void i915_gem_object_save_bit_17_swizzle(struct drm_gem_object *obj);
  942. bool i915_tiling_ok(struct drm_device *dev, int stride, int size,
  943. int tiling_mode);
  944. bool i915_gem_object_fence_offset_ok(struct drm_gem_object *obj,
  945. int tiling_mode);
  946. /* i915_gem_debug.c */
  947. void i915_gem_dump_object(struct drm_gem_object *obj, int len,
  948. const char *where, uint32_t mark);
  949. #if WATCH_INACTIVE
  950. void i915_verify_inactive(struct drm_device *dev, char *file, int line);
  951. #else
  952. #define i915_verify_inactive(dev, file, line)
  953. #endif
  954. void i915_gem_object_check_coherency(struct drm_gem_object *obj, int handle);
  955. void i915_gem_dump_object(struct drm_gem_object *obj, int len,
  956. const char *where, uint32_t mark);
  957. void i915_dump_lru(struct drm_device *dev, const char *where);
  958. /* i915_debugfs.c */
  959. int i915_debugfs_init(struct drm_minor *minor);
  960. void i915_debugfs_cleanup(struct drm_minor *minor);
  961. /* i915_suspend.c */
  962. extern int i915_save_state(struct drm_device *dev);
  963. extern int i915_restore_state(struct drm_device *dev);
  964. /* i915_suspend.c */
  965. extern int i915_save_state(struct drm_device *dev);
  966. extern int i915_restore_state(struct drm_device *dev);
  967. /* intel_i2c.c */
  968. extern int intel_setup_gmbus(struct drm_device *dev);
  969. extern void intel_teardown_gmbus(struct drm_device *dev);
  970. extern void intel_i2c_reset(struct drm_device *dev);
  971. /* intel_opregion.c */
  972. extern int intel_opregion_setup(struct drm_device *dev);
  973. #ifdef CONFIG_ACPI
  974. extern void intel_opregion_init(struct drm_device *dev);
  975. extern void intel_opregion_fini(struct drm_device *dev);
  976. extern void intel_opregion_asle_intr(struct drm_device *dev);
  977. extern void intel_opregion_gse_intr(struct drm_device *dev);
  978. extern void intel_opregion_enable_asle(struct drm_device *dev);
  979. #else
  980. static inline void intel_opregion_init(struct drm_device *dev) { return; }
  981. static inline void intel_opregion_fini(struct drm_device *dev) { return; }
  982. static inline void intel_opregion_asle_intr(struct drm_device *dev) { return; }
  983. static inline void intel_opregion_gse_intr(struct drm_device *dev) { return; }
  984. static inline void intel_opregion_enable_asle(struct drm_device *dev) { return; }
  985. #endif
  986. /* modesetting */
  987. extern void intel_modeset_init(struct drm_device *dev);
  988. extern void intel_modeset_cleanup(struct drm_device *dev);
  989. extern int intel_modeset_vga_set_state(struct drm_device *dev, bool state);
  990. extern void i8xx_disable_fbc(struct drm_device *dev);
  991. extern void g4x_disable_fbc(struct drm_device *dev);
  992. extern void ironlake_disable_fbc(struct drm_device *dev);
  993. extern void intel_disable_fbc(struct drm_device *dev);
  994. extern void intel_enable_fbc(struct drm_crtc *crtc, unsigned long interval);
  995. extern bool intel_fbc_enabled(struct drm_device *dev);
  996. extern bool ironlake_set_drps(struct drm_device *dev, u8 val);
  997. extern void intel_detect_pch (struct drm_device *dev);
  998. extern int intel_trans_dp_port_sel (struct drm_crtc *crtc);
  999. /* overlay */
  1000. #ifdef CONFIG_DEBUG_FS
  1001. extern struct intel_overlay_error_state *intel_overlay_capture_error_state(struct drm_device *dev);
  1002. extern void intel_overlay_print_error_state(struct seq_file *m, struct intel_overlay_error_state *error);
  1003. #endif
  1004. /**
  1005. * Lock test for when it's just for synchronization of ring access.
  1006. *
  1007. * In that case, we don't need to do it when GEM is initialized as nobody else
  1008. * has access to the ring.
  1009. */
  1010. #define RING_LOCK_TEST_WITH_RETURN(dev, file_priv) do { \
  1011. if (((drm_i915_private_t *)dev->dev_private)->render_ring.gem_object \
  1012. == NULL) \
  1013. LOCK_TEST_WITH_RETURN(dev, file_priv); \
  1014. } while (0)
  1015. static inline u32 i915_read(struct drm_i915_private *dev_priv, u32 reg)
  1016. {
  1017. u32 val;
  1018. val = readl(dev_priv->regs + reg);
  1019. if (dev_priv->debug_flags & I915_DEBUG_READ)
  1020. printk(KERN_ERR "read 0x%08x from 0x%08x\n", val, reg);
  1021. return val;
  1022. }
  1023. static inline void i915_write(struct drm_i915_private *dev_priv, u32 reg,
  1024. u32 val)
  1025. {
  1026. writel(val, dev_priv->regs + reg);
  1027. if (dev_priv->debug_flags & I915_DEBUG_WRITE)
  1028. printk(KERN_ERR "wrote 0x%08x to 0x%08x\n", val, reg);
  1029. }
  1030. #define I915_READ(reg) i915_read(dev_priv, (reg))
  1031. #define I915_WRITE(reg, val) i915_write(dev_priv, (reg), (val))
  1032. #define I915_READ16(reg) readw(dev_priv->regs + (reg))
  1033. #define I915_WRITE16(reg, val) writel(val, dev_priv->regs + (reg))
  1034. #define I915_READ8(reg) readb(dev_priv->regs + (reg))
  1035. #define I915_WRITE8(reg, val) writeb(val, dev_priv->regs + (reg))
  1036. #define I915_WRITE64(reg, val) writeq(val, dev_priv->regs + (reg))
  1037. #define I915_READ64(reg) readq(dev_priv->regs + (reg))
  1038. #define POSTING_READ(reg) (void)I915_READ(reg)
  1039. #define POSTING_READ16(reg) (void)I915_READ16(reg)
  1040. #define I915_DEBUG_ENABLE_IO() (dev_priv->debug_flags |= I915_DEBUG_READ | \
  1041. I915_DEBUG_WRITE)
  1042. #define I915_DEBUG_DISABLE_IO() (dev_priv->debug_flags &= ~(I915_DEBUG_READ | \
  1043. I915_DEBUG_WRITE))
  1044. #define I915_VERBOSE 0
  1045. #define BEGIN_LP_RING(n) do { \
  1046. drm_i915_private_t *dev_priv__ = dev->dev_private; \
  1047. if (I915_VERBOSE) \
  1048. DRM_DEBUG(" BEGIN_LP_RING %x\n", (int)(n)); \
  1049. intel_ring_begin(dev, &dev_priv__->render_ring, (n)); \
  1050. } while (0)
  1051. #define OUT_RING(x) do { \
  1052. drm_i915_private_t *dev_priv__ = dev->dev_private; \
  1053. if (I915_VERBOSE) \
  1054. DRM_DEBUG(" OUT_RING %x\n", (int)(x)); \
  1055. intel_ring_emit(dev, &dev_priv__->render_ring, x); \
  1056. } while (0)
  1057. #define ADVANCE_LP_RING() do { \
  1058. drm_i915_private_t *dev_priv__ = dev->dev_private; \
  1059. if (I915_VERBOSE) \
  1060. DRM_DEBUG("ADVANCE_LP_RING %x\n", \
  1061. dev_priv__->render_ring.tail); \
  1062. intel_ring_advance(dev, &dev_priv__->render_ring); \
  1063. } while(0)
  1064. /**
  1065. * Reads a dword out of the status page, which is written to from the command
  1066. * queue by automatic updates, MI_REPORT_HEAD, MI_STORE_DATA_INDEX, or
  1067. * MI_STORE_DATA_IMM.
  1068. *
  1069. * The following dwords have a reserved meaning:
  1070. * 0x00: ISR copy, updated when an ISR bit not set in the HWSTAM changes.
  1071. * 0x04: ring 0 head pointer
  1072. * 0x05: ring 1 head pointer (915-class)
  1073. * 0x06: ring 2 head pointer (915-class)
  1074. * 0x10-0x1b: Context status DWords (GM45)
  1075. * 0x1f: Last written status offset. (GM45)
  1076. *
  1077. * The area from dword 0x20 to 0x3ff is available for driver usage.
  1078. */
  1079. #define READ_HWSP(dev_priv, reg) (((volatile u32 *)\
  1080. (dev_priv->render_ring.status_page.page_addr))[reg])
  1081. #define READ_BREADCRUMB(dev_priv) READ_HWSP(dev_priv, I915_BREADCRUMB_INDEX)
  1082. #define I915_GEM_HWS_INDEX 0x20
  1083. #define I915_BREADCRUMB_INDEX 0x21
  1084. #define INTEL_INFO(dev) (((struct drm_i915_private *) (dev)->dev_private)->info)
  1085. #define IS_I830(dev) ((dev)->pci_device == 0x3577)
  1086. #define IS_845G(dev) ((dev)->pci_device == 0x2562)
  1087. #define IS_I85X(dev) (INTEL_INFO(dev)->is_i85x)
  1088. #define IS_I865G(dev) ((dev)->pci_device == 0x2572)
  1089. #define IS_I915G(dev) (INTEL_INFO(dev)->is_i915g)
  1090. #define IS_I915GM(dev) ((dev)->pci_device == 0x2592)
  1091. #define IS_I945G(dev) ((dev)->pci_device == 0x2772)
  1092. #define IS_I945GM(dev) (INTEL_INFO(dev)->is_i945gm)
  1093. #define IS_BROADWATER(dev) (INTEL_INFO(dev)->is_broadwater)
  1094. #define IS_CRESTLINE(dev) (INTEL_INFO(dev)->is_crestline)
  1095. #define IS_GM45(dev) ((dev)->pci_device == 0x2A42)
  1096. #define IS_G4X(dev) (INTEL_INFO(dev)->is_g4x)
  1097. #define IS_PINEVIEW_G(dev) ((dev)->pci_device == 0xa001)
  1098. #define IS_PINEVIEW_M(dev) ((dev)->pci_device == 0xa011)
  1099. #define IS_PINEVIEW(dev) (INTEL_INFO(dev)->is_pineview)
  1100. #define IS_G33(dev) (INTEL_INFO(dev)->is_g33)
  1101. #define IS_IRONLAKE_D(dev) ((dev)->pci_device == 0x0042)
  1102. #define IS_IRONLAKE_M(dev) ((dev)->pci_device == 0x0046)
  1103. #define IS_IRONLAKE(dev) (INTEL_INFO(dev)->is_ironlake)
  1104. #define IS_MOBILE(dev) (INTEL_INFO(dev)->is_mobile)
  1105. #define IS_GEN2(dev) (INTEL_INFO(dev)->gen == 2)
  1106. #define IS_GEN3(dev) (INTEL_INFO(dev)->gen == 3)
  1107. #define IS_GEN4(dev) (INTEL_INFO(dev)->gen == 4)
  1108. #define IS_GEN5(dev) (INTEL_INFO(dev)->gen == 5)
  1109. #define IS_GEN6(dev) (INTEL_INFO(dev)->gen == 6)
  1110. #define HAS_BSD(dev) (INTEL_INFO(dev)->has_bsd_ring)
  1111. #define I915_NEED_GFX_HWS(dev) (INTEL_INFO(dev)->need_gfx_hws)
  1112. #define HAS_OVERLAY(dev) (INTEL_INFO(dev)->has_overlay)
  1113. #define OVERLAY_NEEDS_PHYSICAL(dev) (INTEL_INFO(dev)->overlay_needs_physical)
  1114. /* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte
  1115. * rows, which changed the alignment requirements and fence programming.
  1116. */
  1117. #define HAS_128_BYTE_Y_TILING(dev) (!IS_GEN2(dev) && !(IS_I915G(dev) || \
  1118. IS_I915GM(dev)))
  1119. #define SUPPORTS_DIGITAL_OUTPUTS(dev) (!IS_GEN2(dev) && !IS_PINEVIEW(dev))
  1120. #define SUPPORTS_INTEGRATED_HDMI(dev) (IS_G4X(dev) || IS_IRONLAKE(dev))
  1121. #define SUPPORTS_INTEGRATED_DP(dev) (IS_G4X(dev) || IS_IRONLAKE(dev))
  1122. #define SUPPORTS_EDP(dev) (IS_IRONLAKE_M(dev))
  1123. #define SUPPORTS_TV(dev) (INTEL_INFO(dev)->supports_tv)
  1124. #define I915_HAS_HOTPLUG(dev) (INTEL_INFO(dev)->has_hotplug)
  1125. /* dsparb controlled by hw only */
  1126. #define DSPARB_HWCONTROL(dev) (IS_G4X(dev) || IS_IRONLAKE(dev))
  1127. #define HAS_FW_BLC(dev) (INTEL_INFO(dev)->gen > 2)
  1128. #define HAS_PIPE_CXSR(dev) (INTEL_INFO(dev)->has_pipe_cxsr)
  1129. #define I915_HAS_FBC(dev) (INTEL_INFO(dev)->has_fbc)
  1130. #define I915_HAS_RC6(dev) (INTEL_INFO(dev)->has_rc6)
  1131. #define HAS_PCH_SPLIT(dev) (IS_IRONLAKE(dev) || \
  1132. IS_GEN6(dev))
  1133. #define HAS_PIPE_CONTROL(dev) (IS_IRONLAKE(dev) || IS_GEN6(dev))
  1134. #define INTEL_PCH_TYPE(dev) (((struct drm_i915_private *)(dev)->dev_private)->pch_type)
  1135. #define HAS_PCH_CPT(dev) (INTEL_PCH_TYPE(dev) == PCH_CPT)
  1136. #define PRIMARY_RINGBUFFER_SIZE (128*1024)
  1137. #endif