mga_drm.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. /* mga_drm.h -- Public header for the Matrox g200/g400 driver -*- linux-c -*-
  2. * Created: Tue Jan 25 01:50:01 1999 by jhartmann@precisioninsight.com
  3. *
  4. * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  5. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  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 "Software"),
  10. * to deal in the Software without restriction, including without limitation
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12. * and/or sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice (including the next
  16. * paragraph) shall be included in all copies or substantial portions of the
  17. * Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  22. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  23. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  24. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  25. * OTHER DEALINGS IN THE SOFTWARE.
  26. *
  27. * Authors:
  28. * Jeff Hartmann <jhartmann@valinux.com>
  29. * Keith Whitwell <keith@tungstengraphics.com>
  30. *
  31. * Rewritten by:
  32. * Gareth Hughes <gareth@valinux.com>
  33. */
  34. #ifndef __MGA_DRM_H__
  35. #define __MGA_DRM_H__
  36. #include <drm/drm.h>
  37. /* WARNING: If you change any of these defines, make sure to change the
  38. * defines in the Xserver file (mga_sarea.h)
  39. */
  40. #ifndef __MGA_SAREA_DEFINES__
  41. #define __MGA_SAREA_DEFINES__
  42. /* WARP pipe flags
  43. */
  44. #define MGA_F 0x1 /* fog */
  45. #define MGA_A 0x2 /* alpha */
  46. #define MGA_S 0x4 /* specular */
  47. #define MGA_T2 0x8 /* multitexture */
  48. #define MGA_WARP_TGZ 0
  49. #define MGA_WARP_TGZF (MGA_F)
  50. #define MGA_WARP_TGZA (MGA_A)
  51. #define MGA_WARP_TGZAF (MGA_F|MGA_A)
  52. #define MGA_WARP_TGZS (MGA_S)
  53. #define MGA_WARP_TGZSF (MGA_S|MGA_F)
  54. #define MGA_WARP_TGZSA (MGA_S|MGA_A)
  55. #define MGA_WARP_TGZSAF (MGA_S|MGA_F|MGA_A)
  56. #define MGA_WARP_T2GZ (MGA_T2)
  57. #define MGA_WARP_T2GZF (MGA_T2|MGA_F)
  58. #define MGA_WARP_T2GZA (MGA_T2|MGA_A)
  59. #define MGA_WARP_T2GZAF (MGA_T2|MGA_A|MGA_F)
  60. #define MGA_WARP_T2GZS (MGA_T2|MGA_S)
  61. #define MGA_WARP_T2GZSF (MGA_T2|MGA_S|MGA_F)
  62. #define MGA_WARP_T2GZSA (MGA_T2|MGA_S|MGA_A)
  63. #define MGA_WARP_T2GZSAF (MGA_T2|MGA_S|MGA_F|MGA_A)
  64. #define MGA_MAX_G200_PIPES 8 /* no multitex */
  65. #define MGA_MAX_G400_PIPES 16
  66. #define MGA_MAX_WARP_PIPES MGA_MAX_G400_PIPES
  67. #define MGA_WARP_UCODE_SIZE 32768 /* in bytes */
  68. #define MGA_CARD_TYPE_G200 1
  69. #define MGA_CARD_TYPE_G400 2
  70. #define MGA_CARD_TYPE_G450 3 /* not currently used */
  71. #define MGA_CARD_TYPE_G550 4
  72. #define MGA_FRONT 0x1
  73. #define MGA_BACK 0x2
  74. #define MGA_DEPTH 0x4
  75. /* What needs to be changed for the current vertex dma buffer?
  76. */
  77. #define MGA_UPLOAD_CONTEXT 0x1
  78. #define MGA_UPLOAD_TEX0 0x2
  79. #define MGA_UPLOAD_TEX1 0x4
  80. #define MGA_UPLOAD_PIPE 0x8
  81. #define MGA_UPLOAD_TEX0IMAGE 0x10 /* handled client-side */
  82. #define MGA_UPLOAD_TEX1IMAGE 0x20 /* handled client-side */
  83. #define MGA_UPLOAD_2D 0x40
  84. #define MGA_WAIT_AGE 0x80 /* handled client-side */
  85. #define MGA_UPLOAD_CLIPRECTS 0x100 /* handled client-side */
  86. #if 0
  87. #define MGA_DMA_FLUSH 0x200 /* set when someone gets the lock
  88. quiescent */
  89. #endif
  90. /* 32 buffers of 64k each, total 2 meg.
  91. */
  92. #define MGA_BUFFER_SIZE (1 << 16)
  93. #define MGA_NUM_BUFFERS 128
  94. /* Keep these small for testing.
  95. */
  96. #define MGA_NR_SAREA_CLIPRECTS 8
  97. /* 2 heaps (1 for card, 1 for agp), each divided into up to 128
  98. * regions, subject to a minimum region size of (1<<16) == 64k.
  99. *
  100. * Clients may subdivide regions internally, but when sharing between
  101. * clients, the region size is the minimum granularity.
  102. */
  103. #define MGA_CARD_HEAP 0
  104. #define MGA_AGP_HEAP 1
  105. #define MGA_NR_TEX_HEAPS 2
  106. #define MGA_NR_TEX_REGIONS 16
  107. #define MGA_LOG_MIN_TEX_REGION_SIZE 16
  108. #define DRM_MGA_IDLE_RETRY 2048
  109. #endif /* __MGA_SAREA_DEFINES__ */
  110. /* Setup registers for 3D context
  111. */
  112. typedef struct {
  113. unsigned int dstorg;
  114. unsigned int maccess;
  115. unsigned int plnwt;
  116. unsigned int dwgctl;
  117. unsigned int alphactrl;
  118. unsigned int fogcolor;
  119. unsigned int wflag;
  120. unsigned int tdualstage0;
  121. unsigned int tdualstage1;
  122. unsigned int fcol;
  123. unsigned int stencil;
  124. unsigned int stencilctl;
  125. } drm_mga_context_regs_t;
  126. /* Setup registers for 2D, X server
  127. */
  128. typedef struct {
  129. unsigned int pitch;
  130. } drm_mga_server_regs_t;
  131. /* Setup registers for each texture unit
  132. */
  133. typedef struct {
  134. unsigned int texctl;
  135. unsigned int texctl2;
  136. unsigned int texfilter;
  137. unsigned int texbordercol;
  138. unsigned int texorg;
  139. unsigned int texwidth;
  140. unsigned int texheight;
  141. unsigned int texorg1;
  142. unsigned int texorg2;
  143. unsigned int texorg3;
  144. unsigned int texorg4;
  145. } drm_mga_texture_regs_t;
  146. /* General aging mechanism
  147. */
  148. typedef struct {
  149. unsigned int head; /* Position of head pointer */
  150. unsigned int wrap; /* Primary DMA wrap count */
  151. } drm_mga_age_t;
  152. typedef struct _drm_mga_sarea {
  153. /* The channel for communication of state information to the kernel
  154. * on firing a vertex dma buffer.
  155. */
  156. drm_mga_context_regs_t context_state;
  157. drm_mga_server_regs_t server_state;
  158. drm_mga_texture_regs_t tex_state[2];
  159. unsigned int warp_pipe;
  160. unsigned int dirty;
  161. unsigned int vertsize;
  162. /* The current cliprects, or a subset thereof.
  163. */
  164. struct drm_clip_rect boxes[MGA_NR_SAREA_CLIPRECTS];
  165. unsigned int nbox;
  166. /* Information about the most recently used 3d drawable. The
  167. * client fills in the req_* fields, the server fills in the
  168. * exported_ fields and puts the cliprects into boxes, above.
  169. *
  170. * The client clears the exported_drawable field before
  171. * clobbering the boxes data.
  172. */
  173. unsigned int req_drawable; /* the X drawable id */
  174. unsigned int req_draw_buffer; /* MGA_FRONT or MGA_BACK */
  175. unsigned int exported_drawable;
  176. unsigned int exported_index;
  177. unsigned int exported_stamp;
  178. unsigned int exported_buffers;
  179. unsigned int exported_nfront;
  180. unsigned int exported_nback;
  181. int exported_back_x, exported_front_x, exported_w;
  182. int exported_back_y, exported_front_y, exported_h;
  183. struct drm_clip_rect exported_boxes[MGA_NR_SAREA_CLIPRECTS];
  184. /* Counters for aging textures and for client-side throttling.
  185. */
  186. unsigned int status[4];
  187. unsigned int last_wrap;
  188. drm_mga_age_t last_frame;
  189. unsigned int last_enqueue; /* last time a buffer was enqueued */
  190. unsigned int last_dispatch; /* age of the most recently dispatched buffer */
  191. unsigned int last_quiescent; /* */
  192. /* LRU lists for texture memory in agp space and on the card.
  193. */
  194. struct drm_tex_region texList[MGA_NR_TEX_HEAPS][MGA_NR_TEX_REGIONS + 1];
  195. unsigned int texAge[MGA_NR_TEX_HEAPS];
  196. /* Mechanism to validate card state.
  197. */
  198. int ctxOwner;
  199. } drm_mga_sarea_t;
  200. /* MGA specific ioctls
  201. * The device specific ioctl range is 0x40 to 0x79.
  202. */
  203. #define DRM_MGA_INIT 0x00
  204. #define DRM_MGA_FLUSH 0x01
  205. #define DRM_MGA_RESET 0x02
  206. #define DRM_MGA_SWAP 0x03
  207. #define DRM_MGA_CLEAR 0x04
  208. #define DRM_MGA_VERTEX 0x05
  209. #define DRM_MGA_INDICES 0x06
  210. #define DRM_MGA_ILOAD 0x07
  211. #define DRM_MGA_BLIT 0x08
  212. #define DRM_MGA_GETPARAM 0x09
  213. /* 3.2:
  214. * ioctls for operating on fences.
  215. */
  216. #define DRM_MGA_SET_FENCE 0x0a
  217. #define DRM_MGA_WAIT_FENCE 0x0b
  218. #define DRM_MGA_DMA_BOOTSTRAP 0x0c
  219. #define DRM_IOCTL_MGA_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_INIT, drm_mga_init_t)
  220. #define DRM_IOCTL_MGA_FLUSH DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_FLUSH, struct drm_lock)
  221. #define DRM_IOCTL_MGA_RESET DRM_IO( DRM_COMMAND_BASE + DRM_MGA_RESET)
  222. #define DRM_IOCTL_MGA_SWAP DRM_IO( DRM_COMMAND_BASE + DRM_MGA_SWAP)
  223. #define DRM_IOCTL_MGA_CLEAR DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_CLEAR, drm_mga_clear_t)
  224. #define DRM_IOCTL_MGA_VERTEX DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_VERTEX, drm_mga_vertex_t)
  225. #define DRM_IOCTL_MGA_INDICES DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_INDICES, drm_mga_indices_t)
  226. #define DRM_IOCTL_MGA_ILOAD DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_ILOAD, drm_mga_iload_t)
  227. #define DRM_IOCTL_MGA_BLIT DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_BLIT, drm_mga_blit_t)
  228. #define DRM_IOCTL_MGA_GETPARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_MGA_GETPARAM, drm_mga_getparam_t)
  229. #define DRM_IOCTL_MGA_SET_FENCE DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_SET_FENCE, __u32)
  230. #define DRM_IOCTL_MGA_WAIT_FENCE DRM_IOWR(DRM_COMMAND_BASE + DRM_MGA_WAIT_FENCE, __u32)
  231. #define DRM_IOCTL_MGA_DMA_BOOTSTRAP DRM_IOWR(DRM_COMMAND_BASE + DRM_MGA_DMA_BOOTSTRAP, drm_mga_dma_bootstrap_t)
  232. typedef struct _drm_mga_warp_index {
  233. int installed;
  234. unsigned long phys_addr;
  235. int size;
  236. } drm_mga_warp_index_t;
  237. typedef struct drm_mga_init {
  238. enum {
  239. MGA_INIT_DMA = 0x01,
  240. MGA_CLEANUP_DMA = 0x02
  241. } func;
  242. unsigned long sarea_priv_offset;
  243. int chipset;
  244. int sgram;
  245. unsigned int maccess;
  246. unsigned int fb_cpp;
  247. unsigned int front_offset, front_pitch;
  248. unsigned int back_offset, back_pitch;
  249. unsigned int depth_cpp;
  250. unsigned int depth_offset, depth_pitch;
  251. unsigned int texture_offset[MGA_NR_TEX_HEAPS];
  252. unsigned int texture_size[MGA_NR_TEX_HEAPS];
  253. unsigned long fb_offset;
  254. unsigned long mmio_offset;
  255. unsigned long status_offset;
  256. unsigned long warp_offset;
  257. unsigned long primary_offset;
  258. unsigned long buffers_offset;
  259. } drm_mga_init_t;
  260. typedef struct drm_mga_dma_bootstrap {
  261. /**
  262. * \name AGP texture region
  263. *
  264. * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, these fields will
  265. * be filled in with the actual AGP texture settings.
  266. *
  267. * \warning
  268. * If these fields are non-zero, but dma_mga_dma_bootstrap::agp_mode
  269. * is zero, it means that PCI memory (most likely through the use of
  270. * an IOMMU) is being used for "AGP" textures.
  271. */
  272. /*@{ */
  273. unsigned long texture_handle; /**< Handle used to map AGP textures. */
  274. __u32 texture_size; /**< Size of the AGP texture region. */
  275. /*@} */
  276. /**
  277. * Requested size of the primary DMA region.
  278. *
  279. * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, this field will be
  280. * filled in with the actual AGP mode. If AGP was not available
  281. */
  282. __u32 primary_size;
  283. /**
  284. * Requested number of secondary DMA buffers.
  285. *
  286. * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, this field will be
  287. * filled in with the actual number of secondary DMA buffers
  288. * allocated. Particularly when PCI DMA is used, this may be
  289. * (subtantially) less than the number requested.
  290. */
  291. __u32 secondary_bin_count;
  292. /**
  293. * Requested size of each secondary DMA buffer.
  294. *
  295. * While the kernel \b is free to reduce
  296. * dma_mga_dma_bootstrap::secondary_bin_count, it is \b not allowed
  297. * to reduce dma_mga_dma_bootstrap::secondary_bin_size.
  298. */
  299. __u32 secondary_bin_size;
  300. /**
  301. * Bit-wise mask of AGPSTAT2_* values. Currently only \c AGPSTAT2_1X,
  302. * \c AGPSTAT2_2X, and \c AGPSTAT2_4X are supported. If this value is
  303. * zero, it means that PCI DMA should be used, even if AGP is
  304. * possible.
  305. *
  306. * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, this field will be
  307. * filled in with the actual AGP mode. If AGP was not available
  308. * (i.e., PCI DMA was used), this value will be zero.
  309. */
  310. __u32 agp_mode;
  311. /**
  312. * Desired AGP GART size, measured in megabytes.
  313. */
  314. __u8 agp_size;
  315. } drm_mga_dma_bootstrap_t;
  316. typedef struct drm_mga_clear {
  317. unsigned int flags;
  318. unsigned int clear_color;
  319. unsigned int clear_depth;
  320. unsigned int color_mask;
  321. unsigned int depth_mask;
  322. } drm_mga_clear_t;
  323. typedef struct drm_mga_vertex {
  324. int idx; /* buffer to queue */
  325. int used; /* bytes in use */
  326. int discard; /* client finished with buffer? */
  327. } drm_mga_vertex_t;
  328. typedef struct drm_mga_indices {
  329. int idx; /* buffer to queue */
  330. unsigned int start;
  331. unsigned int end;
  332. int discard; /* client finished with buffer? */
  333. } drm_mga_indices_t;
  334. typedef struct drm_mga_iload {
  335. int idx;
  336. unsigned int dstorg;
  337. unsigned int length;
  338. } drm_mga_iload_t;
  339. typedef struct _drm_mga_blit {
  340. unsigned int planemask;
  341. unsigned int srcorg;
  342. unsigned int dstorg;
  343. int src_pitch, dst_pitch;
  344. int delta_sx, delta_sy;
  345. int delta_dx, delta_dy;
  346. int height, ydir; /* flip image vertically */
  347. int source_pitch, dest_pitch;
  348. } drm_mga_blit_t;
  349. /* 3.1: An ioctl to get parameters that aren't available to the 3d
  350. * client any other way.
  351. */
  352. #define MGA_PARAM_IRQ_NR 1
  353. /* 3.2: Query the actual card type. The DDX only distinguishes between
  354. * G200 chips and non-G200 chips, which it calls G400. It turns out that
  355. * there are some very sublte differences between the G4x0 chips and the G550
  356. * chips. Using this parameter query, a client-side driver can detect the
  357. * difference between a G4x0 and a G550.
  358. */
  359. #define MGA_PARAM_CARD_TYPE 2
  360. typedef struct drm_mga_getparam {
  361. int param;
  362. void __user *value;
  363. } drm_mga_getparam_t;
  364. #endif