mga_drm.h 13 KB

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