i915_drv.h 11 KB

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