i915_drv.h 12 KB

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