i915_drv.h 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  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. unsigned int edp_support:1;
  296. int lvds_ssc_freq;
  297. int edp_bpp;
  298. struct notifier_block lid_notifier;
  299. int crt_ddc_pin;
  300. struct drm_i915_fence_reg fence_regs[16]; /* assume 965 */
  301. int fence_reg_start; /* 4 if userland hasn't ioctl'd us yet */
  302. int num_fence_regs; /* 8 on pre-965, 16 otherwise */
  303. unsigned int fsb_freq, mem_freq, is_ddr3;
  304. spinlock_t error_lock;
  305. struct drm_i915_error_state *first_error;
  306. struct work_struct error_work;
  307. struct workqueue_struct *wq;
  308. /* Display functions */
  309. struct drm_i915_display_funcs display;
  310. /* PCH chipset type */
  311. enum intel_pch pch_type;
  312. unsigned long quirks;
  313. /* Register state */
  314. bool modeset_on_lid;
  315. u8 saveLBB;
  316. u32 saveDSPACNTR;
  317. u32 saveDSPBCNTR;
  318. u32 saveDSPARB;
  319. u32 saveHWS;
  320. u32 savePIPEACONF;
  321. u32 savePIPEBCONF;
  322. u32 savePIPEASRC;
  323. u32 savePIPEBSRC;
  324. u32 saveFPA0;
  325. u32 saveFPA1;
  326. u32 saveDPLL_A;
  327. u32 saveDPLL_A_MD;
  328. u32 saveHTOTAL_A;
  329. u32 saveHBLANK_A;
  330. u32 saveHSYNC_A;
  331. u32 saveVTOTAL_A;
  332. u32 saveVBLANK_A;
  333. u32 saveVSYNC_A;
  334. u32 saveBCLRPAT_A;
  335. u32 saveTRANSACONF;
  336. u32 saveTRANS_HTOTAL_A;
  337. u32 saveTRANS_HBLANK_A;
  338. u32 saveTRANS_HSYNC_A;
  339. u32 saveTRANS_VTOTAL_A;
  340. u32 saveTRANS_VBLANK_A;
  341. u32 saveTRANS_VSYNC_A;
  342. u32 savePIPEASTAT;
  343. u32 saveDSPASTRIDE;
  344. u32 saveDSPASIZE;
  345. u32 saveDSPAPOS;
  346. u32 saveDSPAADDR;
  347. u32 saveDSPASURF;
  348. u32 saveDSPATILEOFF;
  349. u32 savePFIT_PGM_RATIOS;
  350. u32 saveBLC_HIST_CTL;
  351. u32 saveBLC_PWM_CTL;
  352. u32 saveBLC_PWM_CTL2;
  353. u32 saveBLC_CPU_PWM_CTL;
  354. u32 saveBLC_CPU_PWM_CTL2;
  355. u32 saveFPB0;
  356. u32 saveFPB1;
  357. u32 saveDPLL_B;
  358. u32 saveDPLL_B_MD;
  359. u32 saveHTOTAL_B;
  360. u32 saveHBLANK_B;
  361. u32 saveHSYNC_B;
  362. u32 saveVTOTAL_B;
  363. u32 saveVBLANK_B;
  364. u32 saveVSYNC_B;
  365. u32 saveBCLRPAT_B;
  366. u32 saveTRANSBCONF;
  367. u32 saveTRANS_HTOTAL_B;
  368. u32 saveTRANS_HBLANK_B;
  369. u32 saveTRANS_HSYNC_B;
  370. u32 saveTRANS_VTOTAL_B;
  371. u32 saveTRANS_VBLANK_B;
  372. u32 saveTRANS_VSYNC_B;
  373. u32 savePIPEBSTAT;
  374. u32 saveDSPBSTRIDE;
  375. u32 saveDSPBSIZE;
  376. u32 saveDSPBPOS;
  377. u32 saveDSPBADDR;
  378. u32 saveDSPBSURF;
  379. u32 saveDSPBTILEOFF;
  380. u32 saveVGA0;
  381. u32 saveVGA1;
  382. u32 saveVGA_PD;
  383. u32 saveVGACNTRL;
  384. u32 saveADPA;
  385. u32 saveLVDS;
  386. u32 savePP_ON_DELAYS;
  387. u32 savePP_OFF_DELAYS;
  388. u32 saveDVOA;
  389. u32 saveDVOB;
  390. u32 saveDVOC;
  391. u32 savePP_ON;
  392. u32 savePP_OFF;
  393. u32 savePP_CONTROL;
  394. u32 savePP_DIVISOR;
  395. u32 savePFIT_CONTROL;
  396. u32 save_palette_a[256];
  397. u32 save_palette_b[256];
  398. u32 saveDPFC_CB_BASE;
  399. u32 saveFBC_CFB_BASE;
  400. u32 saveFBC_LL_BASE;
  401. u32 saveFBC_CONTROL;
  402. u32 saveFBC_CONTROL2;
  403. u32 saveIER;
  404. u32 saveIIR;
  405. u32 saveIMR;
  406. u32 saveDEIER;
  407. u32 saveDEIMR;
  408. u32 saveGTIER;
  409. u32 saveGTIMR;
  410. u32 saveFDI_RXA_IMR;
  411. u32 saveFDI_RXB_IMR;
  412. u32 saveCACHE_MODE_0;
  413. u32 saveMI_ARB_STATE;
  414. u32 saveSWF0[16];
  415. u32 saveSWF1[16];
  416. u32 saveSWF2[3];
  417. u8 saveMSR;
  418. u8 saveSR[8];
  419. u8 saveGR[25];
  420. u8 saveAR_INDEX;
  421. u8 saveAR[21];
  422. u8 saveDACMASK;
  423. u8 saveCR[37];
  424. uint64_t saveFENCE[16];
  425. u32 saveCURACNTR;
  426. u32 saveCURAPOS;
  427. u32 saveCURABASE;
  428. u32 saveCURBCNTR;
  429. u32 saveCURBPOS;
  430. u32 saveCURBBASE;
  431. u32 saveCURSIZE;
  432. u32 saveDP_B;
  433. u32 saveDP_C;
  434. u32 saveDP_D;
  435. u32 savePIPEA_GMCH_DATA_M;
  436. u32 savePIPEB_GMCH_DATA_M;
  437. u32 savePIPEA_GMCH_DATA_N;
  438. u32 savePIPEB_GMCH_DATA_N;
  439. u32 savePIPEA_DP_LINK_M;
  440. u32 savePIPEB_DP_LINK_M;
  441. u32 savePIPEA_DP_LINK_N;
  442. u32 savePIPEB_DP_LINK_N;
  443. u32 saveFDI_RXA_CTL;
  444. u32 saveFDI_TXA_CTL;
  445. u32 saveFDI_RXB_CTL;
  446. u32 saveFDI_TXB_CTL;
  447. u32 savePFA_CTL_1;
  448. u32 savePFB_CTL_1;
  449. u32 savePFA_WIN_SZ;
  450. u32 savePFB_WIN_SZ;
  451. u32 savePFA_WIN_POS;
  452. u32 savePFB_WIN_POS;
  453. u32 savePCH_DREF_CONTROL;
  454. u32 saveDISP_ARB_CTL;
  455. u32 savePIPEA_DATA_M1;
  456. u32 savePIPEA_DATA_N1;
  457. u32 savePIPEA_LINK_M1;
  458. u32 savePIPEA_LINK_N1;
  459. u32 savePIPEB_DATA_M1;
  460. u32 savePIPEB_DATA_N1;
  461. u32 savePIPEB_LINK_M1;
  462. u32 savePIPEB_LINK_N1;
  463. u32 saveMCHBAR_RENDER_STANDBY;
  464. struct {
  465. /** Bridge to intel-gtt-ko */
  466. struct intel_gtt *gtt;
  467. /** Memory allocator for GTT stolen memory */
  468. struct drm_mm vram;
  469. /** Memory allocator for GTT */
  470. struct drm_mm gtt_space;
  471. struct io_mapping *gtt_mapping;
  472. int gtt_mtrr;
  473. /**
  474. * Membership on list of all loaded devices, used to evict
  475. * inactive buffers under memory pressure.
  476. *
  477. * Modifications should only be done whilst holding the
  478. * shrink_list_lock spinlock.
  479. */
  480. struct list_head shrink_list;
  481. /**
  482. * List of objects which are not in the ringbuffer but which
  483. * still have a write_domain which needs to be flushed before
  484. * unbinding.
  485. *
  486. * last_rendering_seqno is 0 while an object is in this list.
  487. *
  488. * A reference is held on the buffer while on this list.
  489. */
  490. struct list_head flushing_list;
  491. /**
  492. * List of objects currently pending a GPU write flush.
  493. *
  494. * All elements on this list will belong to either the
  495. * active_list or flushing_list, last_rendering_seqno can
  496. * be used to differentiate between the two elements.
  497. */
  498. struct list_head gpu_write_list;
  499. /**
  500. * LRU list of objects which are not in the ringbuffer and
  501. * are ready to unbind, but are still in the GTT.
  502. *
  503. * last_rendering_seqno is 0 while an object is in this list.
  504. *
  505. * A reference is not held on the buffer while on this list,
  506. * as merely being GTT-bound shouldn't prevent its being
  507. * freed, and we'll pull it off the list in the free path.
  508. */
  509. struct list_head inactive_list;
  510. /**
  511. * LRU list of objects which are not in the ringbuffer but
  512. * are still pinned in the GTT.
  513. */
  514. struct list_head pinned_list;
  515. /** LRU list of objects with fence regs on them. */
  516. struct list_head fence_list;
  517. /**
  518. * List of objects currently pending being freed.
  519. *
  520. * These objects are no longer in use, but due to a signal
  521. * we were prevented from freeing them at the appointed time.
  522. */
  523. struct list_head deferred_free_list;
  524. /**
  525. * We leave the user IRQ off as much as possible,
  526. * but this means that requests will finish and never
  527. * be retired once the system goes idle. Set a timer to
  528. * fire periodically while the ring is running. When it
  529. * fires, go retire requests.
  530. */
  531. struct delayed_work retire_work;
  532. /**
  533. * Waiting sequence number, if any
  534. */
  535. uint32_t waiting_gem_seqno;
  536. /**
  537. * Last seq seen at irq time
  538. */
  539. uint32_t irq_gem_seqno;
  540. /**
  541. * Flag if the X Server, and thus DRM, is not currently in
  542. * control of the device.
  543. *
  544. * This is set between LeaveVT and EnterVT. It needs to be
  545. * replaced with a semaphore. It also needs to be
  546. * transitioned away from for kernel modesetting.
  547. */
  548. int suspended;
  549. /**
  550. * Flag if the hardware appears to be wedged.
  551. *
  552. * This is set when attempts to idle the device timeout.
  553. * It prevents command submission from occuring and makes
  554. * every pending request fail
  555. */
  556. atomic_t wedged;
  557. /** Bit 6 swizzling required for X tiling */
  558. uint32_t bit_6_swizzle_x;
  559. /** Bit 6 swizzling required for Y tiling */
  560. uint32_t bit_6_swizzle_y;
  561. /* storage for physical objects */
  562. struct drm_i915_gem_phys_object *phys_objs[I915_MAX_PHYS_OBJECT];
  563. uint32_t flush_rings;
  564. } mm;
  565. struct sdvo_device_mapping sdvo_mappings[2];
  566. /* indicate whether the LVDS_BORDER should be enabled or not */
  567. unsigned int lvds_border_bits;
  568. /* Panel fitter placement and size for Ironlake+ */
  569. u32 pch_pf_pos, pch_pf_size;
  570. struct drm_crtc *plane_to_crtc_mapping[2];
  571. struct drm_crtc *pipe_to_crtc_mapping[2];
  572. wait_queue_head_t pending_flip_queue;
  573. bool flip_pending_is_done;
  574. /* Reclocking support */
  575. bool render_reclock_avail;
  576. bool lvds_downclock_avail;
  577. /* indicates the reduced downclock for LVDS*/
  578. int lvds_downclock;
  579. struct work_struct idle_work;
  580. struct timer_list idle_timer;
  581. bool busy;
  582. u16 orig_clock;
  583. int child_dev_num;
  584. struct child_device_config *child_dev;
  585. struct drm_connector *int_lvds_connector;
  586. bool mchbar_need_disable;
  587. u8 cur_delay;
  588. u8 min_delay;
  589. u8 max_delay;
  590. u8 fmax;
  591. u8 fstart;
  592. u64 last_count1;
  593. unsigned long last_time1;
  594. u64 last_count2;
  595. struct timespec last_time2;
  596. unsigned long gfx_power;
  597. int c_m;
  598. int r_t;
  599. u8 corr;
  600. spinlock_t *mchdev_lock;
  601. enum no_fbc_reason no_fbc_reason;
  602. struct drm_mm_node *compressed_fb;
  603. struct drm_mm_node *compressed_llb;
  604. /* list of fbdev register on this device */
  605. struct intel_fbdev *fbdev;
  606. } drm_i915_private_t;
  607. /** driver private structure attached to each drm_gem_object */
  608. struct drm_i915_gem_object {
  609. struct drm_gem_object base;
  610. /** Current space allocated to this object in the GTT, if any. */
  611. struct drm_mm_node *gtt_space;
  612. /** This object's place on the active/flushing/inactive lists */
  613. struct list_head list;
  614. /** This object's place on GPU write list */
  615. struct list_head gpu_write_list;
  616. /** This object's place on eviction list */
  617. struct list_head evict_list;
  618. /**
  619. * This is set if the object is on the active or flushing lists
  620. * (has pending rendering), and is not set if it's on inactive (ready
  621. * to be unbound).
  622. */
  623. unsigned int active : 1;
  624. /**
  625. * This is set if the object has been written to since last bound
  626. * to the GTT
  627. */
  628. unsigned int dirty : 1;
  629. /**
  630. * Fence register bits (if any) for this object. Will be set
  631. * as needed when mapped into the GTT.
  632. * Protected by dev->struct_mutex.
  633. *
  634. * Size: 4 bits for 16 fences + sign (for FENCE_REG_NONE)
  635. */
  636. signed int fence_reg : 5;
  637. /**
  638. * Used for checking the object doesn't appear more than once
  639. * in an execbuffer object list.
  640. */
  641. unsigned int in_execbuffer : 1;
  642. /**
  643. * Advice: are the backing pages purgeable?
  644. */
  645. unsigned int madv : 2;
  646. /**
  647. * Refcount for the pages array. With the current locking scheme, there
  648. * are at most two concurrent users: Binding a bo to the gtt and
  649. * pwrite/pread using physical addresses. So two bits for a maximum
  650. * of two users are enough.
  651. */
  652. unsigned int pages_refcount : 2;
  653. #define DRM_I915_GEM_OBJECT_MAX_PAGES_REFCOUNT 0x3
  654. /**
  655. * Current tiling mode for the object.
  656. */
  657. unsigned int tiling_mode : 2;
  658. /** How many users have pinned this object in GTT space. The following
  659. * users can each hold at most one reference: pwrite/pread, pin_ioctl
  660. * (via user_pin_count), execbuffer (objects are not allowed multiple
  661. * times for the same batchbuffer), and the framebuffer code. When
  662. * switching/pageflipping, the framebuffer code has at most two buffers
  663. * pinned per crtc.
  664. *
  665. * In the worst case this is 1 + 1 + 1 + 2*2 = 7. That would fit into 3
  666. * bits with absolutely no headroom. So use 4 bits. */
  667. unsigned int pin_count : 4;
  668. #define DRM_I915_GEM_OBJECT_MAX_PIN_COUNT 0xf
  669. /** AGP memory structure for our GTT binding. */
  670. DRM_AGP_MEM *agp_mem;
  671. struct page **pages;
  672. /**
  673. * Current offset of the object in GTT space.
  674. *
  675. * This is the same as gtt_space->start
  676. */
  677. uint32_t gtt_offset;
  678. /* Which ring is refering to is this object */
  679. struct intel_ring_buffer *ring;
  680. /**
  681. * Fake offset for use by mmap(2)
  682. */
  683. uint64_t mmap_offset;
  684. /** Breadcrumb of last rendering to the buffer. */
  685. uint32_t last_rendering_seqno;
  686. /** Current tiling stride for the object, if it's tiled. */
  687. uint32_t stride;
  688. /** Record of address bit 17 of each page at last unbind. */
  689. unsigned long *bit_17;
  690. /** AGP mapping type (AGP_USER_MEMORY or AGP_USER_CACHED_MEMORY */
  691. uint32_t agp_type;
  692. /**
  693. * If present, while GEM_DOMAIN_CPU is in the read domain this array
  694. * flags which individual pages are valid.
  695. */
  696. uint8_t *page_cpu_valid;
  697. /** User space pin count and filp owning the pin */
  698. uint32_t user_pin_count;
  699. struct drm_file *pin_filp;
  700. /** for phy allocated objects */
  701. struct drm_i915_gem_phys_object *phys_obj;
  702. /**
  703. * Number of crtcs where this object is currently the fb, but
  704. * will be page flipped away on the next vblank. When it
  705. * reaches 0, dev_priv->pending_flip_queue will be woken up.
  706. */
  707. atomic_t pending_flip;
  708. };
  709. #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
  710. /**
  711. * Request queue structure.
  712. *
  713. * The request queue allows us to note sequence numbers that have been emitted
  714. * and may be associated with active buffers to be retired.
  715. *
  716. * By keeping this list, we can avoid having to do questionable
  717. * sequence-number comparisons on buffer last_rendering_seqnos, and associate
  718. * an emission time with seqnos for tracking how far ahead of the GPU we are.
  719. */
  720. struct drm_i915_gem_request {
  721. /** On Which ring this request was generated */
  722. struct intel_ring_buffer *ring;
  723. /** GEM sequence number associated with this request. */
  724. uint32_t seqno;
  725. /** Time at which this request was emitted, in jiffies. */
  726. unsigned long emitted_jiffies;
  727. /** global list entry for this request */
  728. struct list_head list;
  729. /** file_priv list entry for this request */
  730. struct list_head client_list;
  731. };
  732. struct drm_i915_file_private {
  733. struct {
  734. struct list_head request_list;
  735. } mm;
  736. };
  737. enum intel_chip_family {
  738. CHIP_I8XX = 0x01,
  739. CHIP_I9XX = 0x02,
  740. CHIP_I915 = 0x04,
  741. CHIP_I965 = 0x08,
  742. };
  743. extern struct drm_ioctl_desc i915_ioctls[];
  744. extern int i915_max_ioctl;
  745. extern unsigned int i915_fbpercrtc;
  746. extern unsigned int i915_powersave;
  747. extern unsigned int i915_lvds_downclock;
  748. extern int i915_suspend(struct drm_device *dev, pm_message_t state);
  749. extern int i915_resume(struct drm_device *dev);
  750. extern void i915_save_display(struct drm_device *dev);
  751. extern void i915_restore_display(struct drm_device *dev);
  752. extern int i915_master_create(struct drm_device *dev, struct drm_master *master);
  753. extern void i915_master_destroy(struct drm_device *dev, struct drm_master *master);
  754. /* i915_dma.c */
  755. extern void i915_kernel_lost_context(struct drm_device * dev);
  756. extern int i915_driver_load(struct drm_device *, unsigned long flags);
  757. extern int i915_driver_unload(struct drm_device *);
  758. extern int i915_driver_open(struct drm_device *dev, struct drm_file *file_priv);
  759. extern void i915_driver_lastclose(struct drm_device * dev);
  760. extern void i915_driver_preclose(struct drm_device *dev,
  761. struct drm_file *file_priv);
  762. extern void i915_driver_postclose(struct drm_device *dev,
  763. struct drm_file *file_priv);
  764. extern int i915_driver_device_is_agp(struct drm_device * dev);
  765. extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
  766. unsigned long arg);
  767. extern int i915_emit_box(struct drm_device *dev,
  768. struct drm_clip_rect *boxes,
  769. int i, int DR1, int DR4);
  770. extern int i915_reset(struct drm_device *dev, u8 flags);
  771. extern unsigned long i915_chipset_val(struct drm_i915_private *dev_priv);
  772. extern unsigned long i915_mch_val(struct drm_i915_private *dev_priv);
  773. extern unsigned long i915_gfx_val(struct drm_i915_private *dev_priv);
  774. extern void i915_update_gfx_val(struct drm_i915_private *dev_priv);
  775. /* i915_irq.c */
  776. void i915_hangcheck_elapsed(unsigned long data);
  777. extern int i915_irq_emit(struct drm_device *dev, void *data,
  778. struct drm_file *file_priv);
  779. extern int i915_irq_wait(struct drm_device *dev, void *data,
  780. struct drm_file *file_priv);
  781. void i915_trace_irq_get(struct drm_device *dev, u32 seqno);
  782. extern void i915_enable_interrupt (struct drm_device *dev);
  783. extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS);
  784. extern void i915_driver_irq_preinstall(struct drm_device * dev);
  785. extern int i915_driver_irq_postinstall(struct drm_device *dev);
  786. extern void i915_driver_irq_uninstall(struct drm_device * dev);
  787. extern int i915_vblank_pipe_set(struct drm_device *dev, void *data,
  788. struct drm_file *file_priv);
  789. extern int i915_vblank_pipe_get(struct drm_device *dev, void *data,
  790. struct drm_file *file_priv);
  791. extern int i915_enable_vblank(struct drm_device *dev, int crtc);
  792. extern void i915_disable_vblank(struct drm_device *dev, int crtc);
  793. extern u32 i915_get_vblank_counter(struct drm_device *dev, int crtc);
  794. extern u32 gm45_get_vblank_counter(struct drm_device *dev, int crtc);
  795. extern int i915_vblank_swap(struct drm_device *dev, void *data,
  796. struct drm_file *file_priv);
  797. extern void i915_enable_irq(drm_i915_private_t *dev_priv, u32 mask);
  798. extern void i915_disable_irq(drm_i915_private_t *dev_priv, u32 mask);
  799. extern void ironlake_enable_graphics_irq(drm_i915_private_t *dev_priv,
  800. u32 mask);
  801. extern void ironlake_disable_graphics_irq(drm_i915_private_t *dev_priv,
  802. u32 mask);
  803. void
  804. i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask);
  805. void
  806. i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask);
  807. void intel_enable_asle (struct drm_device *dev);
  808. #ifdef CONFIG_DEBUG_FS
  809. extern void i915_destroy_error_state(struct drm_device *dev);
  810. #else
  811. #define i915_destroy_error_state(x)
  812. #endif
  813. /* i915_mem.c */
  814. extern int i915_mem_alloc(struct drm_device *dev, void *data,
  815. struct drm_file *file_priv);
  816. extern int i915_mem_free(struct drm_device *dev, void *data,
  817. struct drm_file *file_priv);
  818. extern int i915_mem_init_heap(struct drm_device *dev, void *data,
  819. struct drm_file *file_priv);
  820. extern int i915_mem_destroy_heap(struct drm_device *dev, void *data,
  821. struct drm_file *file_priv);
  822. extern void i915_mem_takedown(struct mem_block **heap);
  823. extern void i915_mem_release(struct drm_device * dev,
  824. struct drm_file *file_priv, struct mem_block *heap);
  825. /* i915_gem.c */
  826. int i915_gem_init_ioctl(struct drm_device *dev, void *data,
  827. struct drm_file *file_priv);
  828. int i915_gem_create_ioctl(struct drm_device *dev, void *data,
  829. struct drm_file *file_priv);
  830. int i915_gem_pread_ioctl(struct drm_device *dev, void *data,
  831. struct drm_file *file_priv);
  832. int i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  833. struct drm_file *file_priv);
  834. int i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
  835. struct drm_file *file_priv);
  836. int i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data,
  837. struct drm_file *file_priv);
  838. int i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  839. struct drm_file *file_priv);
  840. int i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
  841. struct drm_file *file_priv);
  842. int i915_gem_execbuffer(struct drm_device *dev, void *data,
  843. struct drm_file *file_priv);
  844. int i915_gem_execbuffer2(struct drm_device *dev, void *data,
  845. struct drm_file *file_priv);
  846. int i915_gem_pin_ioctl(struct drm_device *dev, void *data,
  847. struct drm_file *file_priv);
  848. int i915_gem_unpin_ioctl(struct drm_device *dev, void *data,
  849. struct drm_file *file_priv);
  850. int i915_gem_busy_ioctl(struct drm_device *dev, void *data,
  851. struct drm_file *file_priv);
  852. int i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
  853. struct drm_file *file_priv);
  854. int i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
  855. struct drm_file *file_priv);
  856. int i915_gem_entervt_ioctl(struct drm_device *dev, void *data,
  857. struct drm_file *file_priv);
  858. int i915_gem_leavevt_ioctl(struct drm_device *dev, void *data,
  859. struct drm_file *file_priv);
  860. int i915_gem_set_tiling(struct drm_device *dev, void *data,
  861. struct drm_file *file_priv);
  862. int i915_gem_get_tiling(struct drm_device *dev, void *data,
  863. struct drm_file *file_priv);
  864. int i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
  865. struct drm_file *file_priv);
  866. void i915_gem_load(struct drm_device *dev);
  867. int i915_gem_init_object(struct drm_gem_object *obj);
  868. struct drm_gem_object * i915_gem_alloc_object(struct drm_device *dev,
  869. size_t size);
  870. void i915_gem_free_object(struct drm_gem_object *obj);
  871. int i915_gem_object_pin(struct drm_gem_object *obj, uint32_t alignment);
  872. void i915_gem_object_unpin(struct drm_gem_object *obj);
  873. int i915_gem_object_unbind(struct drm_gem_object *obj);
  874. void i915_gem_release_mmap(struct drm_gem_object *obj);
  875. void i915_gem_lastclose(struct drm_device *dev);
  876. uint32_t i915_get_gem_seqno(struct drm_device *dev,
  877. struct intel_ring_buffer *ring);
  878. bool i915_seqno_passed(uint32_t seq1, uint32_t seq2);
  879. int i915_gem_object_get_fence_reg(struct drm_gem_object *obj,
  880. bool interruptible);
  881. int i915_gem_object_put_fence_reg(struct drm_gem_object *obj,
  882. bool interruptible);
  883. void i915_gem_retire_requests(struct drm_device *dev);
  884. void i915_gem_reset_lists(struct drm_device *dev);
  885. void i915_gem_clflush_object(struct drm_gem_object *obj);
  886. int i915_gem_object_set_domain(struct drm_gem_object *obj,
  887. uint32_t read_domains,
  888. uint32_t write_domain);
  889. int i915_gem_init_ringbuffer(struct drm_device *dev);
  890. void i915_gem_cleanup_ringbuffer(struct drm_device *dev);
  891. int i915_gem_do_init(struct drm_device *dev, unsigned long start,
  892. unsigned long end);
  893. int i915_gpu_idle(struct drm_device *dev);
  894. int i915_gem_idle(struct drm_device *dev);
  895. uint32_t i915_add_request(struct drm_device *dev,
  896. struct drm_file *file_priv,
  897. struct drm_i915_gem_request *request,
  898. struct intel_ring_buffer *ring);
  899. int i915_do_wait_request(struct drm_device *dev,
  900. uint32_t seqno,
  901. bool interruptible,
  902. struct intel_ring_buffer *ring);
  903. int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
  904. int i915_gem_object_set_to_gtt_domain(struct drm_gem_object *obj,
  905. int write);
  906. int i915_gem_object_set_to_display_plane(struct drm_gem_object *obj,
  907. bool pipelined);
  908. int i915_gem_attach_phys_object(struct drm_device *dev,
  909. struct drm_gem_object *obj,
  910. int id,
  911. int align);
  912. void i915_gem_detach_phys_object(struct drm_device *dev,
  913. struct drm_gem_object *obj);
  914. void i915_gem_free_all_phys_object(struct drm_device *dev);
  915. int i915_gem_object_get_pages(struct drm_gem_object *obj, gfp_t gfpmask);
  916. void i915_gem_object_put_pages(struct drm_gem_object *obj);
  917. void i915_gem_release(struct drm_device * dev, struct drm_file *file_priv);
  918. void i915_gem_shrinker_init(void);
  919. void i915_gem_shrinker_exit(void);
  920. /* i915_gem_evict.c */
  921. int i915_gem_evict_something(struct drm_device *dev, int min_size, unsigned alignment);
  922. int i915_gem_evict_everything(struct drm_device *dev);
  923. int i915_gem_evict_inactive(struct drm_device *dev);
  924. /* i915_gem_tiling.c */
  925. void i915_gem_detect_bit_6_swizzle(struct drm_device *dev);
  926. void i915_gem_object_do_bit_17_swizzle(struct drm_gem_object *obj);
  927. void i915_gem_object_save_bit_17_swizzle(struct drm_gem_object *obj);
  928. bool i915_tiling_ok(struct drm_device *dev, int stride, int size,
  929. int tiling_mode);
  930. bool i915_gem_object_fence_offset_ok(struct drm_gem_object *obj,
  931. int tiling_mode);
  932. /* i915_gem_debug.c */
  933. void i915_gem_dump_object(struct drm_gem_object *obj, int len,
  934. const char *where, uint32_t mark);
  935. #if WATCH_INACTIVE
  936. void i915_verify_inactive(struct drm_device *dev, char *file, int line);
  937. #else
  938. #define i915_verify_inactive(dev, file, line)
  939. #endif
  940. void i915_gem_object_check_coherency(struct drm_gem_object *obj, int handle);
  941. void i915_gem_dump_object(struct drm_gem_object *obj, int len,
  942. const char *where, uint32_t mark);
  943. void i915_dump_lru(struct drm_device *dev, const char *where);
  944. /* i915_debugfs.c */
  945. int i915_debugfs_init(struct drm_minor *minor);
  946. void i915_debugfs_cleanup(struct drm_minor *minor);
  947. /* i915_suspend.c */
  948. extern int i915_save_state(struct drm_device *dev);
  949. extern int i915_restore_state(struct drm_device *dev);
  950. /* i915_suspend.c */
  951. extern int i915_save_state(struct drm_device *dev);
  952. extern int i915_restore_state(struct drm_device *dev);
  953. /* intel_i2c.c */
  954. extern int intel_setup_gmbus(struct drm_device *dev);
  955. extern void intel_teardown_gmbus(struct drm_device *dev);
  956. extern void intel_i2c_reset(struct drm_device *dev);
  957. /* intel_opregion.c */
  958. extern int intel_opregion_setup(struct drm_device *dev);
  959. #ifdef CONFIG_ACPI
  960. extern void intel_opregion_init(struct drm_device *dev);
  961. extern void intel_opregion_fini(struct drm_device *dev);
  962. extern void intel_opregion_asle_intr(struct drm_device *dev);
  963. extern void intel_opregion_gse_intr(struct drm_device *dev);
  964. extern void intel_opregion_enable_asle(struct drm_device *dev);
  965. #else
  966. static inline void intel_opregion_init(struct drm_device *dev) { return; }
  967. static inline void intel_opregion_fini(struct drm_device *dev) { return; }
  968. static inline void intel_opregion_asle_intr(struct drm_device *dev) { return; }
  969. static inline void intel_opregion_gse_intr(struct drm_device *dev) { return; }
  970. static inline void intel_opregion_enable_asle(struct drm_device *dev) { return; }
  971. #endif
  972. /* modesetting */
  973. extern void intel_modeset_init(struct drm_device *dev);
  974. extern void intel_modeset_cleanup(struct drm_device *dev);
  975. extern int intel_modeset_vga_set_state(struct drm_device *dev, bool state);
  976. extern void i8xx_disable_fbc(struct drm_device *dev);
  977. extern void g4x_disable_fbc(struct drm_device *dev);
  978. extern void ironlake_disable_fbc(struct drm_device *dev);
  979. extern void intel_disable_fbc(struct drm_device *dev);
  980. extern void intel_enable_fbc(struct drm_crtc *crtc, unsigned long interval);
  981. extern bool intel_fbc_enabled(struct drm_device *dev);
  982. extern bool ironlake_set_drps(struct drm_device *dev, u8 val);
  983. extern void intel_detect_pch (struct drm_device *dev);
  984. extern int intel_trans_dp_port_sel (struct drm_crtc *crtc);
  985. /* overlay */
  986. #ifdef CONFIG_DEBUG_FS
  987. extern struct intel_overlay_error_state *intel_overlay_capture_error_state(struct drm_device *dev);
  988. extern void intel_overlay_print_error_state(struct seq_file *m, struct intel_overlay_error_state *error);
  989. #endif
  990. /**
  991. * Lock test for when it's just for synchronization of ring access.
  992. *
  993. * In that case, we don't need to do it when GEM is initialized as nobody else
  994. * has access to the ring.
  995. */
  996. #define RING_LOCK_TEST_WITH_RETURN(dev, file_priv) do { \
  997. if (((drm_i915_private_t *)dev->dev_private)->render_ring.gem_object \
  998. == NULL) \
  999. LOCK_TEST_WITH_RETURN(dev, file_priv); \
  1000. } while (0)
  1001. static inline u32 i915_read(struct drm_i915_private *dev_priv, u32 reg)
  1002. {
  1003. u32 val;
  1004. val = readl(dev_priv->regs + reg);
  1005. if (dev_priv->debug_flags & I915_DEBUG_READ)
  1006. printk(KERN_ERR "read 0x%08x from 0x%08x\n", val, reg);
  1007. return val;
  1008. }
  1009. static inline void i915_write(struct drm_i915_private *dev_priv, u32 reg,
  1010. u32 val)
  1011. {
  1012. writel(val, dev_priv->regs + reg);
  1013. if (dev_priv->debug_flags & I915_DEBUG_WRITE)
  1014. printk(KERN_ERR "wrote 0x%08x to 0x%08x\n", val, reg);
  1015. }
  1016. #define I915_READ(reg) i915_read(dev_priv, (reg))
  1017. #define I915_WRITE(reg, val) i915_write(dev_priv, (reg), (val))
  1018. #define I915_READ16(reg) readw(dev_priv->regs + (reg))
  1019. #define I915_WRITE16(reg, val) writel(val, dev_priv->regs + (reg))
  1020. #define I915_READ8(reg) readb(dev_priv->regs + (reg))
  1021. #define I915_WRITE8(reg, val) writeb(val, dev_priv->regs + (reg))
  1022. #define I915_WRITE64(reg, val) writeq(val, dev_priv->regs + (reg))
  1023. #define I915_READ64(reg) readq(dev_priv->regs + (reg))
  1024. #define POSTING_READ(reg) (void)I915_READ(reg)
  1025. #define POSTING_READ16(reg) (void)I915_READ16(reg)
  1026. #define I915_DEBUG_ENABLE_IO() (dev_priv->debug_flags |= I915_DEBUG_READ | \
  1027. I915_DEBUG_WRITE)
  1028. #define I915_DEBUG_DISABLE_IO() (dev_priv->debug_flags &= ~(I915_DEBUG_READ | \
  1029. I915_DEBUG_WRITE))
  1030. #define I915_VERBOSE 0
  1031. #define BEGIN_LP_RING(n) do { \
  1032. drm_i915_private_t *dev_priv__ = dev->dev_private; \
  1033. if (I915_VERBOSE) \
  1034. DRM_DEBUG(" BEGIN_LP_RING %x\n", (int)(n)); \
  1035. intel_ring_begin(dev, &dev_priv__->render_ring, (n)); \
  1036. } while (0)
  1037. #define OUT_RING(x) do { \
  1038. drm_i915_private_t *dev_priv__ = dev->dev_private; \
  1039. if (I915_VERBOSE) \
  1040. DRM_DEBUG(" OUT_RING %x\n", (int)(x)); \
  1041. intel_ring_emit(dev, &dev_priv__->render_ring, x); \
  1042. } while (0)
  1043. #define ADVANCE_LP_RING() do { \
  1044. drm_i915_private_t *dev_priv__ = dev->dev_private; \
  1045. if (I915_VERBOSE) \
  1046. DRM_DEBUG("ADVANCE_LP_RING %x\n", \
  1047. dev_priv__->render_ring.tail); \
  1048. intel_ring_advance(dev, &dev_priv__->render_ring); \
  1049. } while(0)
  1050. /**
  1051. * Reads a dword out of the status page, which is written to from the command
  1052. * queue by automatic updates, MI_REPORT_HEAD, MI_STORE_DATA_INDEX, or
  1053. * MI_STORE_DATA_IMM.
  1054. *
  1055. * The following dwords have a reserved meaning:
  1056. * 0x00: ISR copy, updated when an ISR bit not set in the HWSTAM changes.
  1057. * 0x04: ring 0 head pointer
  1058. * 0x05: ring 1 head pointer (915-class)
  1059. * 0x06: ring 2 head pointer (915-class)
  1060. * 0x10-0x1b: Context status DWords (GM45)
  1061. * 0x1f: Last written status offset. (GM45)
  1062. *
  1063. * The area from dword 0x20 to 0x3ff is available for driver usage.
  1064. */
  1065. #define READ_HWSP(dev_priv, reg) (((volatile u32 *)\
  1066. (dev_priv->render_ring.status_page.page_addr))[reg])
  1067. #define READ_BREADCRUMB(dev_priv) READ_HWSP(dev_priv, I915_BREADCRUMB_INDEX)
  1068. #define I915_GEM_HWS_INDEX 0x20
  1069. #define I915_BREADCRUMB_INDEX 0x21
  1070. #define INTEL_INFO(dev) (((struct drm_i915_private *) (dev)->dev_private)->info)
  1071. #define IS_I830(dev) ((dev)->pci_device == 0x3577)
  1072. #define IS_845G(dev) ((dev)->pci_device == 0x2562)
  1073. #define IS_I85X(dev) (INTEL_INFO(dev)->is_i85x)
  1074. #define IS_I865G(dev) ((dev)->pci_device == 0x2572)
  1075. #define IS_I915G(dev) (INTEL_INFO(dev)->is_i915g)
  1076. #define IS_I915GM(dev) ((dev)->pci_device == 0x2592)
  1077. #define IS_I945G(dev) ((dev)->pci_device == 0x2772)
  1078. #define IS_I945GM(dev) (INTEL_INFO(dev)->is_i945gm)
  1079. #define IS_BROADWATER(dev) (INTEL_INFO(dev)->is_broadwater)
  1080. #define IS_CRESTLINE(dev) (INTEL_INFO(dev)->is_crestline)
  1081. #define IS_GM45(dev) ((dev)->pci_device == 0x2A42)
  1082. #define IS_G4X(dev) (INTEL_INFO(dev)->is_g4x)
  1083. #define IS_PINEVIEW_G(dev) ((dev)->pci_device == 0xa001)
  1084. #define IS_PINEVIEW_M(dev) ((dev)->pci_device == 0xa011)
  1085. #define IS_PINEVIEW(dev) (INTEL_INFO(dev)->is_pineview)
  1086. #define IS_G33(dev) (INTEL_INFO(dev)->is_g33)
  1087. #define IS_IRONLAKE_D(dev) ((dev)->pci_device == 0x0042)
  1088. #define IS_IRONLAKE_M(dev) ((dev)->pci_device == 0x0046)
  1089. #define IS_IRONLAKE(dev) (INTEL_INFO(dev)->is_ironlake)
  1090. #define IS_MOBILE(dev) (INTEL_INFO(dev)->is_mobile)
  1091. #define IS_GEN2(dev) (INTEL_INFO(dev)->gen == 2)
  1092. #define IS_GEN3(dev) (INTEL_INFO(dev)->gen == 3)
  1093. #define IS_GEN4(dev) (INTEL_INFO(dev)->gen == 4)
  1094. #define IS_GEN5(dev) (INTEL_INFO(dev)->gen == 5)
  1095. #define IS_GEN6(dev) (INTEL_INFO(dev)->gen == 6)
  1096. #define HAS_BSD(dev) (INTEL_INFO(dev)->has_bsd_ring)
  1097. #define I915_NEED_GFX_HWS(dev) (INTEL_INFO(dev)->need_gfx_hws)
  1098. #define HAS_OVERLAY(dev) (INTEL_INFO(dev)->has_overlay)
  1099. #define OVERLAY_NEEDS_PHYSICAL(dev) (INTEL_INFO(dev)->overlay_needs_physical)
  1100. /* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte
  1101. * rows, which changed the alignment requirements and fence programming.
  1102. */
  1103. #define HAS_128_BYTE_Y_TILING(dev) (!IS_GEN2(dev) && !(IS_I915G(dev) || \
  1104. IS_I915GM(dev)))
  1105. #define SUPPORTS_DIGITAL_OUTPUTS(dev) (!IS_GEN2(dev) && !IS_PINEVIEW(dev))
  1106. #define SUPPORTS_INTEGRATED_HDMI(dev) (IS_G4X(dev) || IS_IRONLAKE(dev))
  1107. #define SUPPORTS_INTEGRATED_DP(dev) (IS_G4X(dev) || IS_IRONLAKE(dev))
  1108. #define SUPPORTS_EDP(dev) (IS_IRONLAKE_M(dev))
  1109. #define SUPPORTS_TV(dev) (INTEL_INFO(dev)->supports_tv)
  1110. #define I915_HAS_HOTPLUG(dev) (INTEL_INFO(dev)->has_hotplug)
  1111. /* dsparb controlled by hw only */
  1112. #define DSPARB_HWCONTROL(dev) (IS_G4X(dev) || IS_IRONLAKE(dev))
  1113. #define HAS_FW_BLC(dev) (INTEL_INFO(dev)->gen > 2)
  1114. #define HAS_PIPE_CXSR(dev) (INTEL_INFO(dev)->has_pipe_cxsr)
  1115. #define I915_HAS_FBC(dev) (INTEL_INFO(dev)->has_fbc)
  1116. #define I915_HAS_RC6(dev) (INTEL_INFO(dev)->has_rc6)
  1117. #define HAS_PCH_SPLIT(dev) (IS_IRONLAKE(dev) || \
  1118. IS_GEN6(dev))
  1119. #define HAS_PIPE_CONTROL(dev) (IS_IRONLAKE(dev) || IS_GEN6(dev))
  1120. #define INTEL_PCH_TYPE(dev) (((struct drm_i915_private *)(dev)->dev_private)->pch_type)
  1121. #define HAS_PCH_CPT(dev) (INTEL_PCH_TYPE(dev) == PCH_CPT)
  1122. #define PRIMARY_RINGBUFFER_SIZE (128*1024)
  1123. #endif