i915_drv.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. /* General customization:
  33. */
  34. #define DRIVER_AUTHOR "Tungsten Graphics, Inc."
  35. #define DRIVER_NAME "i915"
  36. #define DRIVER_DESC "Intel Graphics"
  37. #define DRIVER_DATE "20060119"
  38. /* Interface history:
  39. *
  40. * 1.1: Original.
  41. * 1.2: Add Power Management
  42. * 1.3: Add vblank support
  43. * 1.4: Fix cmdbuffer path, add heap destroy
  44. * 1.5: Add vblank pipe configuration
  45. * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
  46. * - Support vertical blank on secondary display pipe
  47. */
  48. #define DRIVER_MAJOR 1
  49. #define DRIVER_MINOR 6
  50. #define DRIVER_PATCHLEVEL 0
  51. typedef struct _drm_i915_ring_buffer {
  52. int tail_mask;
  53. unsigned long Start;
  54. unsigned long End;
  55. unsigned long Size;
  56. u8 *virtual_start;
  57. int head;
  58. int tail;
  59. int space;
  60. drm_local_map_t map;
  61. } drm_i915_ring_buffer_t;
  62. struct mem_block {
  63. struct mem_block *next;
  64. struct mem_block *prev;
  65. int start;
  66. int size;
  67. struct drm_file *file_priv; /* NULL: free, -1: heap, other: real files */
  68. };
  69. typedef struct _drm_i915_vbl_swap {
  70. struct list_head head;
  71. drm_drawable_t drw_id;
  72. unsigned int pipe;
  73. unsigned int sequence;
  74. } drm_i915_vbl_swap_t;
  75. typedef struct drm_i915_private {
  76. drm_local_map_t *sarea;
  77. drm_local_map_t *mmio_map;
  78. drm_i915_sarea_t *sarea_priv;
  79. drm_i915_ring_buffer_t ring;
  80. drm_dma_handle_t *status_page_dmah;
  81. void *hw_status_page;
  82. dma_addr_t dma_status_page;
  83. unsigned long counter;
  84. unsigned int status_gfx_addr;
  85. drm_local_map_t hws_map;
  86. unsigned int cpp;
  87. int back_offset;
  88. int front_offset;
  89. int current_page;
  90. int page_flipping;
  91. wait_queue_head_t irq_queue;
  92. atomic_t irq_received;
  93. atomic_t irq_emitted;
  94. /** Protects user_irq_refcount and irq_mask_reg */
  95. spinlock_t user_irq_lock;
  96. /** Refcount for i915_user_irq_get() versus i915_user_irq_put(). */
  97. int user_irq_refcount;
  98. /** Cached value of IMR to avoid reads in updating the bitfield */
  99. u32 irq_mask_reg;
  100. int tex_lru_log_granularity;
  101. int allow_batchbuffer;
  102. struct mem_block *agp_heap;
  103. unsigned int sr01, adpa, ppcr, dvob, dvoc, lvds;
  104. int vblank_pipe;
  105. spinlock_t swaps_lock;
  106. drm_i915_vbl_swap_t vbl_swaps;
  107. unsigned int swaps_pending;
  108. /* Register state */
  109. u8 saveLBB;
  110. u32 saveDSPACNTR;
  111. u32 saveDSPBCNTR;
  112. u32 saveDSPARB;
  113. u32 savePIPEACONF;
  114. u32 savePIPEBCONF;
  115. u32 savePIPEASRC;
  116. u32 savePIPEBSRC;
  117. u32 saveFPA0;
  118. u32 saveFPA1;
  119. u32 saveDPLL_A;
  120. u32 saveDPLL_A_MD;
  121. u32 saveHTOTAL_A;
  122. u32 saveHBLANK_A;
  123. u32 saveHSYNC_A;
  124. u32 saveVTOTAL_A;
  125. u32 saveVBLANK_A;
  126. u32 saveVSYNC_A;
  127. u32 saveBCLRPAT_A;
  128. u32 savePIPEASTAT;
  129. u32 saveDSPASTRIDE;
  130. u32 saveDSPASIZE;
  131. u32 saveDSPAPOS;
  132. u32 saveDSPAADDR;
  133. u32 saveDSPASURF;
  134. u32 saveDSPATILEOFF;
  135. u32 savePFIT_PGM_RATIOS;
  136. u32 saveBLC_PWM_CTL;
  137. u32 saveBLC_PWM_CTL2;
  138. u32 saveFPB0;
  139. u32 saveFPB1;
  140. u32 saveDPLL_B;
  141. u32 saveDPLL_B_MD;
  142. u32 saveHTOTAL_B;
  143. u32 saveHBLANK_B;
  144. u32 saveHSYNC_B;
  145. u32 saveVTOTAL_B;
  146. u32 saveVBLANK_B;
  147. u32 saveVSYNC_B;
  148. u32 saveBCLRPAT_B;
  149. u32 savePIPEBSTAT;
  150. u32 saveDSPBSTRIDE;
  151. u32 saveDSPBSIZE;
  152. u32 saveDSPBPOS;
  153. u32 saveDSPBADDR;
  154. u32 saveDSPBSURF;
  155. u32 saveDSPBTILEOFF;
  156. u32 saveVGA0;
  157. u32 saveVGA1;
  158. u32 saveVGA_PD;
  159. u32 saveVGACNTRL;
  160. u32 saveADPA;
  161. u32 saveLVDS;
  162. u32 savePP_ON_DELAYS;
  163. u32 savePP_OFF_DELAYS;
  164. u32 saveDVOA;
  165. u32 saveDVOB;
  166. u32 saveDVOC;
  167. u32 savePP_ON;
  168. u32 savePP_OFF;
  169. u32 savePP_CONTROL;
  170. u32 savePP_DIVISOR;
  171. u32 savePFIT_CONTROL;
  172. u32 save_palette_a[256];
  173. u32 save_palette_b[256];
  174. u32 saveFBC_CFB_BASE;
  175. u32 saveFBC_LL_BASE;
  176. u32 saveFBC_CONTROL;
  177. u32 saveFBC_CONTROL2;
  178. u32 saveIER;
  179. u32 saveIIR;
  180. u32 saveIMR;
  181. u32 saveCACHE_MODE_0;
  182. u32 saveD_STATE;
  183. u32 saveCG_2D_DIS;
  184. u32 saveMI_ARB_STATE;
  185. u32 saveSWF0[16];
  186. u32 saveSWF1[16];
  187. u32 saveSWF2[3];
  188. u8 saveMSR;
  189. u8 saveSR[8];
  190. u8 saveGR[25];
  191. u8 saveAR_INDEX;
  192. u8 saveAR[21];
  193. u8 saveDACMASK;
  194. u8 saveDACDATA[256*3]; /* 256 3-byte colors */
  195. u8 saveCR[37];
  196. } drm_i915_private_t;
  197. extern struct drm_ioctl_desc i915_ioctls[];
  198. extern int i915_max_ioctl;
  199. /* i915_dma.c */
  200. extern void i915_kernel_lost_context(struct drm_device * dev);
  201. extern int i915_driver_load(struct drm_device *, unsigned long flags);
  202. extern int i915_driver_unload(struct drm_device *);
  203. extern void i915_driver_lastclose(struct drm_device * dev);
  204. extern void i915_driver_preclose(struct drm_device *dev,
  205. struct drm_file *file_priv);
  206. extern int i915_driver_device_is_agp(struct drm_device * dev);
  207. extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
  208. unsigned long arg);
  209. /* i915_irq.c */
  210. extern int i915_irq_emit(struct drm_device *dev, void *data,
  211. struct drm_file *file_priv);
  212. extern int i915_irq_wait(struct drm_device *dev, void *data,
  213. struct drm_file *file_priv);
  214. extern int i915_driver_vblank_wait(struct drm_device *dev, unsigned int *sequence);
  215. extern int i915_driver_vblank_wait2(struct drm_device *dev, unsigned int *sequence);
  216. extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS);
  217. extern void i915_driver_irq_preinstall(struct drm_device * dev);
  218. extern void i915_driver_irq_postinstall(struct drm_device * dev);
  219. extern void i915_driver_irq_uninstall(struct drm_device * dev);
  220. extern int i915_vblank_pipe_set(struct drm_device *dev, void *data,
  221. struct drm_file *file_priv);
  222. extern int i915_vblank_pipe_get(struct drm_device *dev, void *data,
  223. struct drm_file *file_priv);
  224. extern int i915_vblank_swap(struct drm_device *dev, void *data,
  225. struct drm_file *file_priv);
  226. /* i915_mem.c */
  227. extern int i915_mem_alloc(struct drm_device *dev, void *data,
  228. struct drm_file *file_priv);
  229. extern int i915_mem_free(struct drm_device *dev, void *data,
  230. struct drm_file *file_priv);
  231. extern int i915_mem_init_heap(struct drm_device *dev, void *data,
  232. struct drm_file *file_priv);
  233. extern int i915_mem_destroy_heap(struct drm_device *dev, void *data,
  234. struct drm_file *file_priv);
  235. extern void i915_mem_takedown(struct mem_block **heap);
  236. extern void i915_mem_release(struct drm_device * dev,
  237. struct drm_file *file_priv, struct mem_block *heap);
  238. #define I915_READ(reg) DRM_READ32(dev_priv->mmio_map, (reg))
  239. #define I915_WRITE(reg,val) DRM_WRITE32(dev_priv->mmio_map, (reg), (val))
  240. #define I915_READ16(reg) DRM_READ16(dev_priv->mmio_map, (reg))
  241. #define I915_WRITE16(reg,val) DRM_WRITE16(dev_priv->mmio_map, (reg), (val))
  242. #define I915_VERBOSE 0
  243. #define RING_LOCALS unsigned int outring, ringmask, outcount; \
  244. volatile char *virt;
  245. #define BEGIN_LP_RING(n) do { \
  246. if (I915_VERBOSE) \
  247. DRM_DEBUG("BEGIN_LP_RING(%d)\n", (n)); \
  248. if (dev_priv->ring.space < (n)*4) \
  249. i915_wait_ring(dev, (n)*4, __func__); \
  250. outcount = 0; \
  251. outring = dev_priv->ring.tail; \
  252. ringmask = dev_priv->ring.tail_mask; \
  253. virt = dev_priv->ring.virtual_start; \
  254. } while (0)
  255. #define OUT_RING(n) do { \
  256. if (I915_VERBOSE) DRM_DEBUG(" OUT_RING %x\n", (int)(n)); \
  257. *(volatile unsigned int *)(virt + outring) = (n); \
  258. outcount++; \
  259. outring += 4; \
  260. outring &= ringmask; \
  261. } while (0)
  262. #define ADVANCE_LP_RING() do { \
  263. if (I915_VERBOSE) DRM_DEBUG("ADVANCE_LP_RING %x\n", outring); \
  264. dev_priv->ring.tail = outring; \
  265. dev_priv->ring.space -= outcount * 4; \
  266. I915_WRITE(PRB0_TAIL, outring); \
  267. } while(0)
  268. /**
  269. * Reads a dword out of the status page, which is written to from the command
  270. * queue by automatic updates, MI_REPORT_HEAD, MI_STORE_DATA_INDEX, or
  271. * MI_STORE_DATA_IMM.
  272. *
  273. * The following dwords have a reserved meaning:
  274. * 0: ISR copy, updated when an ISR bit not set in the HWSTAM changes.
  275. * 4: ring 0 head pointer
  276. * 5: ring 1 head pointer (915-class)
  277. * 6: ring 2 head pointer (915-class)
  278. *
  279. * The area from dword 0x10 to 0x3ff is available for driver usage.
  280. */
  281. #define READ_HWSP(dev_priv, reg) (((volatile u32*)(dev_priv->hw_status_page))[reg])
  282. #define READ_BREADCRUMB(dev_priv) READ_HWSP(dev_priv, 5)
  283. extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller);
  284. #define IS_I830(dev) ((dev)->pci_device == 0x3577)
  285. #define IS_845G(dev) ((dev)->pci_device == 0x2562)
  286. #define IS_I85X(dev) ((dev)->pci_device == 0x3582)
  287. #define IS_I855(dev) ((dev)->pci_device == 0x3582)
  288. #define IS_I865G(dev) ((dev)->pci_device == 0x2572)
  289. #define IS_I915G(dev) ((dev)->pci_device == 0x2582 || (dev)->pci_device == 0x258a)
  290. #define IS_I915GM(dev) ((dev)->pci_device == 0x2592)
  291. #define IS_I945G(dev) ((dev)->pci_device == 0x2772)
  292. #define IS_I945GM(dev) ((dev)->pci_device == 0x27A2 ||\
  293. (dev)->pci_device == 0x27AE)
  294. #define IS_I965G(dev) ((dev)->pci_device == 0x2972 || \
  295. (dev)->pci_device == 0x2982 || \
  296. (dev)->pci_device == 0x2992 || \
  297. (dev)->pci_device == 0x29A2 || \
  298. (dev)->pci_device == 0x2A02 || \
  299. (dev)->pci_device == 0x2A12 || \
  300. (dev)->pci_device == 0x2A42 || \
  301. (dev)->pci_device == 0x2E02 || \
  302. (dev)->pci_device == 0x2E12 || \
  303. (dev)->pci_device == 0x2E22)
  304. #define IS_I965GM(dev) ((dev)->pci_device == 0x2A02)
  305. #define IS_IGD_GM(dev) ((dev)->pci_device == 0x2A42)
  306. #define IS_G4X(dev) ((dev)->pci_device == 0x2E02 || \
  307. (dev)->pci_device == 0x2E12 || \
  308. (dev)->pci_device == 0x2E22)
  309. #define IS_G33(dev) ((dev)->pci_device == 0x29C2 || \
  310. (dev)->pci_device == 0x29B2 || \
  311. (dev)->pci_device == 0x29D2)
  312. #define IS_I9XX(dev) (IS_I915G(dev) || IS_I915GM(dev) || IS_I945G(dev) || \
  313. IS_I945GM(dev) || IS_I965G(dev) || IS_G33(dev))
  314. #define IS_MOBILE(dev) (IS_I830(dev) || IS_I85X(dev) || IS_I915GM(dev) || \
  315. IS_I945GM(dev) || IS_I965GM(dev) || IS_IGD_GM(dev))
  316. #define I915_NEED_GFX_HWS(dev) (IS_G33(dev) || IS_IGD_GM(dev) || IS_G4X(dev))
  317. #define PRIMARY_RINGBUFFER_SIZE (128*1024)
  318. #endif