savage_drv.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. /* savage_drv.h -- Private header for the savage driver */
  2. /*
  3. * Copyright 2004 Felix Kuehling
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sub license,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial portions
  15. * of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NON-INFRINGEMENT. IN NO EVENT SHALL FELIX KUEHLING BE LIABLE FOR
  21. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  22. * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef __SAVAGE_DRV_H__
  26. #define __SAVAGE_DRV_H__
  27. #define DRIVER_AUTHOR "Felix Kuehling"
  28. #define DRIVER_NAME "savage"
  29. #define DRIVER_DESC "Savage3D/MX/IX, Savage4, SuperSavage, Twister, ProSavage[DDR]"
  30. #define DRIVER_DATE "20050313"
  31. #define DRIVER_MAJOR 2
  32. #define DRIVER_MINOR 4
  33. #define DRIVER_PATCHLEVEL 1
  34. /* Interface history:
  35. *
  36. * 1.x The DRM driver from the VIA/S3 code drop, basically a dummy
  37. * 2.0 The first real DRM
  38. * 2.1 Scissors registers managed by the DRM, 3D operations clipped by
  39. * cliprects of the cmdbuf ioctl
  40. * 2.2 Implemented SAVAGE_CMD_DMA_IDX and SAVAGE_CMD_VB_IDX
  41. * 2.3 Event counters used by BCI_EVENT_EMIT/WAIT ioctls are now 32 bits
  42. * wide and thus very long lived (unlikely to ever wrap). The size
  43. * in the struct was 32 bits before, but only 16 bits were used
  44. * 2.4 Implemented command DMA. Now drm_savage_init_t.cmd_dma_offset is
  45. * actually used
  46. */
  47. typedef struct drm_savage_age {
  48. uint16_t event;
  49. unsigned int wrap;
  50. } drm_savage_age_t;
  51. typedef struct drm_savage_buf_priv {
  52. struct drm_savage_buf_priv *next;
  53. struct drm_savage_buf_priv *prev;
  54. drm_savage_age_t age;
  55. struct drm_buf *buf;
  56. } drm_savage_buf_priv_t;
  57. typedef struct drm_savage_dma_page {
  58. drm_savage_age_t age;
  59. unsigned int used, flushed;
  60. } drm_savage_dma_page_t;
  61. #define SAVAGE_DMA_PAGE_SIZE 1024 /* in dwords */
  62. /* Fake DMA buffer size in bytes. 4 pages. Allows a maximum command
  63. * size of 16kbytes or 4k entries. Minimum requirement would be
  64. * 10kbytes for 255 40-byte vertices in one drawing command. */
  65. #define SAVAGE_FAKE_DMA_SIZE (SAVAGE_DMA_PAGE_SIZE*4*4)
  66. /* interesting bits of hardware state that are saved in dev_priv */
  67. typedef union {
  68. struct drm_savage_common_state {
  69. uint32_t vbaddr;
  70. } common;
  71. struct {
  72. unsigned char pad[sizeof(struct drm_savage_common_state)];
  73. uint32_t texctrl, texaddr;
  74. uint32_t scstart, new_scstart;
  75. uint32_t scend, new_scend;
  76. } s3d;
  77. struct {
  78. unsigned char pad[sizeof(struct drm_savage_common_state)];
  79. uint32_t texdescr, texaddr0, texaddr1;
  80. uint32_t drawctrl0, new_drawctrl0;
  81. uint32_t drawctrl1, new_drawctrl1;
  82. } s4;
  83. } drm_savage_state_t;
  84. /* these chip tags should match the ones in the 2D driver in savage_regs.h. */
  85. enum savage_family {
  86. S3_UNKNOWN = 0,
  87. S3_SAVAGE3D,
  88. S3_SAVAGE_MX,
  89. S3_SAVAGE4,
  90. S3_PROSAVAGE,
  91. S3_TWISTER,
  92. S3_PROSAVAGEDDR,
  93. S3_SUPERSAVAGE,
  94. S3_SAVAGE2000,
  95. S3_LAST
  96. };
  97. extern struct drm_ioctl_desc savage_ioctls[];
  98. extern int savage_max_ioctl;
  99. #define S3_SAVAGE3D_SERIES(chip) ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE_MX))
  100. #define S3_SAVAGE4_SERIES(chip) ((chip==S3_SAVAGE4) \
  101. || (chip==S3_PROSAVAGE) \
  102. || (chip==S3_TWISTER) \
  103. || (chip==S3_PROSAVAGEDDR))
  104. #define S3_SAVAGE_MOBILE_SERIES(chip) ((chip==S3_SAVAGE_MX) || (chip==S3_SUPERSAVAGE))
  105. #define S3_SAVAGE_SERIES(chip) ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE2000))
  106. #define S3_MOBILE_TWISTER_SERIES(chip) ((chip==S3_TWISTER) \
  107. ||(chip==S3_PROSAVAGEDDR))
  108. /* flags */
  109. #define SAVAGE_IS_AGP 1
  110. typedef struct drm_savage_private {
  111. drm_savage_sarea_t *sarea_priv;
  112. drm_savage_buf_priv_t head, tail;
  113. /* who am I? */
  114. enum savage_family chipset;
  115. unsigned int cob_size;
  116. unsigned int bci_threshold_lo, bci_threshold_hi;
  117. unsigned int dma_type;
  118. /* frame buffer layout */
  119. unsigned int fb_bpp;
  120. unsigned int front_offset, front_pitch;
  121. unsigned int back_offset, back_pitch;
  122. unsigned int depth_bpp;
  123. unsigned int depth_offset, depth_pitch;
  124. /* bitmap descriptors for swap and clear */
  125. unsigned int front_bd, back_bd, depth_bd;
  126. /* local textures */
  127. unsigned int texture_offset;
  128. unsigned int texture_size;
  129. /* memory regions in physical memory */
  130. drm_local_map_t *sarea;
  131. drm_local_map_t *mmio;
  132. drm_local_map_t *fb;
  133. drm_local_map_t *aperture;
  134. drm_local_map_t *status;
  135. drm_local_map_t *agp_textures;
  136. drm_local_map_t *cmd_dma;
  137. drm_local_map_t fake_dma;
  138. struct {
  139. int handle;
  140. unsigned long base, size;
  141. } mtrr[3];
  142. /* BCI and status-related stuff */
  143. volatile uint32_t *status_ptr, *bci_ptr;
  144. uint32_t status_used_mask;
  145. uint16_t event_counter;
  146. unsigned int event_wrap;
  147. /* Savage4 command DMA */
  148. drm_savage_dma_page_t *dma_pages;
  149. unsigned int nr_dma_pages, first_dma_page, current_dma_page;
  150. drm_savage_age_t last_dma_age;
  151. /* saved hw state for global/local check on S3D */
  152. uint32_t hw_draw_ctrl, hw_zbuf_ctrl;
  153. /* and for scissors (global, so don't emit if not changed) */
  154. uint32_t hw_scissors_start, hw_scissors_end;
  155. drm_savage_state_t state;
  156. /* after emitting a wait cmd Savage3D needs 63 nops before next DMA */
  157. unsigned int waiting;
  158. /* config/hardware-dependent function pointers */
  159. int (*wait_fifo) (struct drm_savage_private * dev_priv, unsigned int n);
  160. int (*wait_evnt) (struct drm_savage_private * dev_priv, uint16_t e);
  161. /* Err, there is a macro wait_event in include/linux/wait.h.
  162. * Avoid unwanted macro expansion. */
  163. void (*emit_clip_rect) (struct drm_savage_private * dev_priv,
  164. const struct drm_clip_rect * pbox);
  165. void (*dma_flush) (struct drm_savage_private * dev_priv);
  166. } drm_savage_private_t;
  167. /* ioctls */
  168. extern int savage_bci_cmdbuf(struct drm_device *dev, void *data, struct drm_file *file_priv);
  169. extern int savage_bci_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv);
  170. /* BCI functions */
  171. extern uint16_t savage_bci_emit_event(drm_savage_private_t * dev_priv,
  172. unsigned int flags);
  173. extern void savage_freelist_put(struct drm_device * dev, struct drm_buf * buf);
  174. extern void savage_dma_reset(drm_savage_private_t * dev_priv);
  175. extern void savage_dma_wait(drm_savage_private_t * dev_priv, unsigned int page);
  176. extern uint32_t *savage_dma_alloc(drm_savage_private_t * dev_priv,
  177. unsigned int n);
  178. extern int savage_driver_load(struct drm_device *dev, unsigned long chipset);
  179. extern int savage_driver_firstopen(struct drm_device *dev);
  180. extern void savage_driver_lastclose(struct drm_device *dev);
  181. extern int savage_driver_unload(struct drm_device *dev);
  182. extern void savage_reclaim_buffers(struct drm_device *dev,
  183. struct drm_file *file_priv);
  184. /* state functions */
  185. extern void savage_emit_clip_rect_s3d(drm_savage_private_t * dev_priv,
  186. const struct drm_clip_rect * pbox);
  187. extern void savage_emit_clip_rect_s4(drm_savage_private_t * dev_priv,
  188. const struct drm_clip_rect * pbox);
  189. #define SAVAGE_FB_SIZE_S3 0x01000000 /* 16MB */
  190. #define SAVAGE_FB_SIZE_S4 0x02000000 /* 32MB */
  191. #define SAVAGE_MMIO_SIZE 0x00080000 /* 512kB */
  192. #define SAVAGE_APERTURE_OFFSET 0x02000000 /* 32MB */
  193. #define SAVAGE_APERTURE_SIZE 0x05000000 /* 5 tiled surfaces, 16MB each */
  194. #define SAVAGE_BCI_OFFSET 0x00010000 /* offset of the BCI region
  195. * inside the MMIO region */
  196. #define SAVAGE_BCI_FIFO_SIZE 32 /* number of entries in on-chip
  197. * BCI FIFO */
  198. /*
  199. * MMIO registers
  200. */
  201. #define SAVAGE_STATUS_WORD0 0x48C00
  202. #define SAVAGE_STATUS_WORD1 0x48C04
  203. #define SAVAGE_ALT_STATUS_WORD0 0x48C60
  204. #define SAVAGE_FIFO_USED_MASK_S3D 0x0001ffff
  205. #define SAVAGE_FIFO_USED_MASK_S4 0x001fffff
  206. /* Copied from savage_bci.h in the 2D driver with some renaming. */
  207. /* Bitmap descriptors */
  208. #define SAVAGE_BD_STRIDE_SHIFT 0
  209. #define SAVAGE_BD_BPP_SHIFT 16
  210. #define SAVAGE_BD_TILE_SHIFT 24
  211. #define SAVAGE_BD_BW_DISABLE (1<<28)
  212. /* common: */
  213. #define SAVAGE_BD_TILE_LINEAR 0
  214. /* savage4, MX, IX, 3D */
  215. #define SAVAGE_BD_TILE_16BPP 2
  216. #define SAVAGE_BD_TILE_32BPP 3
  217. /* twister, prosavage, DDR, supersavage, 2000 */
  218. #define SAVAGE_BD_TILE_DEST 1
  219. #define SAVAGE_BD_TILE_TEXTURE 2
  220. /* GBD - BCI enable */
  221. /* savage4, MX, IX, 3D */
  222. #define SAVAGE_GBD_BCI_ENABLE 8
  223. /* twister, prosavage, DDR, supersavage, 2000 */
  224. #define SAVAGE_GBD_BCI_ENABLE_TWISTER 0
  225. #define SAVAGE_GBD_BIG_ENDIAN 4
  226. #define SAVAGE_GBD_LITTLE_ENDIAN 0
  227. #define SAVAGE_GBD_64 1
  228. /* Global Bitmap Descriptor */
  229. #define SAVAGE_BCI_GLB_BD_LOW 0x8168
  230. #define SAVAGE_BCI_GLB_BD_HIGH 0x816C
  231. /*
  232. * BCI registers
  233. */
  234. /* Savage4/Twister/ProSavage 3D registers */
  235. #define SAVAGE_DRAWLOCALCTRL_S4 0x1e
  236. #define SAVAGE_TEXPALADDR_S4 0x1f
  237. #define SAVAGE_TEXCTRL0_S4 0x20
  238. #define SAVAGE_TEXCTRL1_S4 0x21
  239. #define SAVAGE_TEXADDR0_S4 0x22
  240. #define SAVAGE_TEXADDR1_S4 0x23
  241. #define SAVAGE_TEXBLEND0_S4 0x24
  242. #define SAVAGE_TEXBLEND1_S4 0x25
  243. #define SAVAGE_TEXXPRCLR_S4 0x26 /* never used */
  244. #define SAVAGE_TEXDESCR_S4 0x27
  245. #define SAVAGE_FOGTABLE_S4 0x28
  246. #define SAVAGE_FOGCTRL_S4 0x30
  247. #define SAVAGE_STENCILCTRL_S4 0x31
  248. #define SAVAGE_ZBUFCTRL_S4 0x32
  249. #define SAVAGE_ZBUFOFF_S4 0x33
  250. #define SAVAGE_DESTCTRL_S4 0x34
  251. #define SAVAGE_DRAWCTRL0_S4 0x35
  252. #define SAVAGE_DRAWCTRL1_S4 0x36
  253. #define SAVAGE_ZWATERMARK_S4 0x37
  254. #define SAVAGE_DESTTEXRWWATERMARK_S4 0x38
  255. #define SAVAGE_TEXBLENDCOLOR_S4 0x39
  256. /* Savage3D/MX/IX 3D registers */
  257. #define SAVAGE_TEXPALADDR_S3D 0x18
  258. #define SAVAGE_TEXXPRCLR_S3D 0x19 /* never used */
  259. #define SAVAGE_TEXADDR_S3D 0x1A
  260. #define SAVAGE_TEXDESCR_S3D 0x1B
  261. #define SAVAGE_TEXCTRL_S3D 0x1C
  262. #define SAVAGE_FOGTABLE_S3D 0x20
  263. #define SAVAGE_FOGCTRL_S3D 0x30
  264. #define SAVAGE_DRAWCTRL_S3D 0x31
  265. #define SAVAGE_ZBUFCTRL_S3D 0x32
  266. #define SAVAGE_ZBUFOFF_S3D 0x33
  267. #define SAVAGE_DESTCTRL_S3D 0x34
  268. #define SAVAGE_SCSTART_S3D 0x35
  269. #define SAVAGE_SCEND_S3D 0x36
  270. #define SAVAGE_ZWATERMARK_S3D 0x37
  271. #define SAVAGE_DESTTEXRWWATERMARK_S3D 0x38
  272. /* common stuff */
  273. #define SAVAGE_VERTBUFADDR 0x3e
  274. #define SAVAGE_BITPLANEWTMASK 0xd7
  275. #define SAVAGE_DMABUFADDR 0x51
  276. /* texture enable bits (needed for tex addr checking) */
  277. #define SAVAGE_TEXCTRL_TEXEN_MASK 0x00010000 /* S3D */
  278. #define SAVAGE_TEXDESCR_TEX0EN_MASK 0x02000000 /* S4 */
  279. #define SAVAGE_TEXDESCR_TEX1EN_MASK 0x04000000 /* S4 */
  280. /* Global fields in Savage4/Twister/ProSavage 3D registers:
  281. *
  282. * All texture registers and DrawLocalCtrl are local. All other
  283. * registers are global. */
  284. /* Global fields in Savage3D/MX/IX 3D registers:
  285. *
  286. * All texture registers are local. DrawCtrl and ZBufCtrl are
  287. * partially local. All other registers are global.
  288. *
  289. * DrawCtrl global fields: cullMode, alphaTestCmpFunc, alphaTestEn, alphaRefVal
  290. * ZBufCtrl global fields: zCmpFunc, zBufEn
  291. */
  292. #define SAVAGE_DRAWCTRL_S3D_GLOBAL 0x03f3c00c
  293. #define SAVAGE_ZBUFCTRL_S3D_GLOBAL 0x00000027
  294. /* Masks for scissor bits (drawCtrl[01] on s4, scissorStart/End on s3d)
  295. */
  296. #define SAVAGE_SCISSOR_MASK_S4 0x00fff7ff
  297. #define SAVAGE_SCISSOR_MASK_S3D 0x07ff07ff
  298. /*
  299. * BCI commands
  300. */
  301. #define BCI_CMD_NOP 0x40000000
  302. #define BCI_CMD_RECT 0x48000000
  303. #define BCI_CMD_RECT_XP 0x01000000
  304. #define BCI_CMD_RECT_YP 0x02000000
  305. #define BCI_CMD_SCANLINE 0x50000000
  306. #define BCI_CMD_LINE 0x5C000000
  307. #define BCI_CMD_LINE_LAST_PIXEL 0x58000000
  308. #define BCI_CMD_BYTE_TEXT 0x63000000
  309. #define BCI_CMD_NT_BYTE_TEXT 0x67000000
  310. #define BCI_CMD_BIT_TEXT 0x6C000000
  311. #define BCI_CMD_GET_ROP(cmd) (((cmd) >> 16) & 0xFF)
  312. #define BCI_CMD_SET_ROP(cmd, rop) ((cmd) |= ((rop & 0xFF) << 16))
  313. #define BCI_CMD_SEND_COLOR 0x00008000
  314. #define BCI_CMD_CLIP_NONE 0x00000000
  315. #define BCI_CMD_CLIP_CURRENT 0x00002000
  316. #define BCI_CMD_CLIP_LR 0x00004000
  317. #define BCI_CMD_CLIP_NEW 0x00006000
  318. #define BCI_CMD_DEST_GBD 0x00000000
  319. #define BCI_CMD_DEST_PBD 0x00000800
  320. #define BCI_CMD_DEST_PBD_NEW 0x00000C00
  321. #define BCI_CMD_DEST_SBD 0x00001000
  322. #define BCI_CMD_DEST_SBD_NEW 0x00001400
  323. #define BCI_CMD_SRC_TRANSPARENT 0x00000200
  324. #define BCI_CMD_SRC_SOLID 0x00000000
  325. #define BCI_CMD_SRC_GBD 0x00000020
  326. #define BCI_CMD_SRC_COLOR 0x00000040
  327. #define BCI_CMD_SRC_MONO 0x00000060
  328. #define BCI_CMD_SRC_PBD_COLOR 0x00000080
  329. #define BCI_CMD_SRC_PBD_MONO 0x000000A0
  330. #define BCI_CMD_SRC_PBD_COLOR_NEW 0x000000C0
  331. #define BCI_CMD_SRC_PBD_MONO_NEW 0x000000E0
  332. #define BCI_CMD_SRC_SBD_COLOR 0x00000100
  333. #define BCI_CMD_SRC_SBD_MONO 0x00000120
  334. #define BCI_CMD_SRC_SBD_COLOR_NEW 0x00000140
  335. #define BCI_CMD_SRC_SBD_MONO_NEW 0x00000160
  336. #define BCI_CMD_PAT_TRANSPARENT 0x00000010
  337. #define BCI_CMD_PAT_NONE 0x00000000
  338. #define BCI_CMD_PAT_COLOR 0x00000002
  339. #define BCI_CMD_PAT_MONO 0x00000003
  340. #define BCI_CMD_PAT_PBD_COLOR 0x00000004
  341. #define BCI_CMD_PAT_PBD_MONO 0x00000005
  342. #define BCI_CMD_PAT_PBD_COLOR_NEW 0x00000006
  343. #define BCI_CMD_PAT_PBD_MONO_NEW 0x00000007
  344. #define BCI_CMD_PAT_SBD_COLOR 0x00000008
  345. #define BCI_CMD_PAT_SBD_MONO 0x00000009
  346. #define BCI_CMD_PAT_SBD_COLOR_NEW 0x0000000A
  347. #define BCI_CMD_PAT_SBD_MONO_NEW 0x0000000B
  348. #define BCI_BD_BW_DISABLE 0x10000000
  349. #define BCI_BD_TILE_MASK 0x03000000
  350. #define BCI_BD_TILE_NONE 0x00000000
  351. #define BCI_BD_TILE_16 0x02000000
  352. #define BCI_BD_TILE_32 0x03000000
  353. #define BCI_BD_GET_BPP(bd) (((bd) >> 16) & 0xFF)
  354. #define BCI_BD_SET_BPP(bd, bpp) ((bd) |= (((bpp) & 0xFF) << 16))
  355. #define BCI_BD_GET_STRIDE(bd) ((bd) & 0xFFFF)
  356. #define BCI_BD_SET_STRIDE(bd, st) ((bd) |= ((st) & 0xFFFF))
  357. #define BCI_CMD_SET_REGISTER 0x96000000
  358. #define BCI_CMD_WAIT 0xC0000000
  359. #define BCI_CMD_WAIT_3D 0x00010000
  360. #define BCI_CMD_WAIT_2D 0x00020000
  361. #define BCI_CMD_UPDATE_EVENT_TAG 0x98000000
  362. #define BCI_CMD_DRAW_PRIM 0x80000000
  363. #define BCI_CMD_DRAW_INDEXED_PRIM 0x88000000
  364. #define BCI_CMD_DRAW_CONT 0x01000000
  365. #define BCI_CMD_DRAW_TRILIST 0x00000000
  366. #define BCI_CMD_DRAW_TRISTRIP 0x02000000
  367. #define BCI_CMD_DRAW_TRIFAN 0x04000000
  368. #define BCI_CMD_DRAW_SKIPFLAGS 0x000000ff
  369. #define BCI_CMD_DRAW_NO_Z 0x00000001
  370. #define BCI_CMD_DRAW_NO_W 0x00000002
  371. #define BCI_CMD_DRAW_NO_CD 0x00000004
  372. #define BCI_CMD_DRAW_NO_CS 0x00000008
  373. #define BCI_CMD_DRAW_NO_U0 0x00000010
  374. #define BCI_CMD_DRAW_NO_V0 0x00000020
  375. #define BCI_CMD_DRAW_NO_UV0 0x00000030
  376. #define BCI_CMD_DRAW_NO_U1 0x00000040
  377. #define BCI_CMD_DRAW_NO_V1 0x00000080
  378. #define BCI_CMD_DRAW_NO_UV1 0x000000c0
  379. #define BCI_CMD_DMA 0xa8000000
  380. #define BCI_W_H(w, h) ((((h) << 16) | (w)) & 0x0FFF0FFF)
  381. #define BCI_X_Y(x, y) ((((y) << 16) | (x)) & 0x0FFF0FFF)
  382. #define BCI_X_W(x, y) ((((w) << 16) | (x)) & 0x0FFF0FFF)
  383. #define BCI_CLIP_LR(l, r) ((((r) << 16) | (l)) & 0x0FFF0FFF)
  384. #define BCI_CLIP_TL(t, l) ((((t) << 16) | (l)) & 0x0FFF0FFF)
  385. #define BCI_CLIP_BR(b, r) ((((b) << 16) | (r)) & 0x0FFF0FFF)
  386. #define BCI_LINE_X_Y(x, y) (((y) << 16) | ((x) & 0xFFFF))
  387. #define BCI_LINE_STEPS(diag, axi) (((axi) << 16) | ((diag) & 0xFFFF))
  388. #define BCI_LINE_MISC(maj, ym, xp, yp, err) \
  389. (((maj) & 0x1FFF) | \
  390. ((ym) ? 1<<13 : 0) | \
  391. ((xp) ? 1<<14 : 0) | \
  392. ((yp) ? 1<<15 : 0) | \
  393. ((err) << 16))
  394. /*
  395. * common commands
  396. */
  397. #define BCI_SET_REGISTERS( first, n ) \
  398. BCI_WRITE(BCI_CMD_SET_REGISTER | \
  399. ((uint32_t)(n) & 0xff) << 16 | \
  400. ((uint32_t)(first) & 0xffff))
  401. #define DMA_SET_REGISTERS( first, n ) \
  402. DMA_WRITE(BCI_CMD_SET_REGISTER | \
  403. ((uint32_t)(n) & 0xff) << 16 | \
  404. ((uint32_t)(first) & 0xffff))
  405. #define BCI_DRAW_PRIMITIVE(n, type, skip) \
  406. BCI_WRITE(BCI_CMD_DRAW_PRIM | (type) | (skip) | \
  407. ((n) << 16))
  408. #define DMA_DRAW_PRIMITIVE(n, type, skip) \
  409. DMA_WRITE(BCI_CMD_DRAW_PRIM | (type) | (skip) | \
  410. ((n) << 16))
  411. #define BCI_DRAW_INDICES_S3D(n, type, i0) \
  412. BCI_WRITE(BCI_CMD_DRAW_INDEXED_PRIM | (type) | \
  413. ((n) << 16) | (i0))
  414. #define BCI_DRAW_INDICES_S4(n, type, skip) \
  415. BCI_WRITE(BCI_CMD_DRAW_INDEXED_PRIM | (type) | \
  416. (skip) | ((n) << 16))
  417. #define BCI_DMA(n) \
  418. BCI_WRITE(BCI_CMD_DMA | (((n) >> 1) - 1))
  419. /*
  420. * access to MMIO
  421. */
  422. #define SAVAGE_READ(reg) DRM_READ32( dev_priv->mmio, (reg) )
  423. #define SAVAGE_WRITE(reg) DRM_WRITE32( dev_priv->mmio, (reg) )
  424. /*
  425. * access to the burst command interface (BCI)
  426. */
  427. #define SAVAGE_BCI_DEBUG 1
  428. #define BCI_LOCALS volatile uint32_t *bci_ptr;
  429. #define BEGIN_BCI( n ) do { \
  430. dev_priv->wait_fifo(dev_priv, (n)); \
  431. bci_ptr = dev_priv->bci_ptr; \
  432. } while(0)
  433. #define BCI_WRITE( val ) *bci_ptr++ = (uint32_t)(val)
  434. /*
  435. * command DMA support
  436. */
  437. #define SAVAGE_DMA_DEBUG 1
  438. #define DMA_LOCALS uint32_t *dma_ptr;
  439. #define BEGIN_DMA( n ) do { \
  440. unsigned int cur = dev_priv->current_dma_page; \
  441. unsigned int rest = SAVAGE_DMA_PAGE_SIZE - \
  442. dev_priv->dma_pages[cur].used; \
  443. if ((n) > rest) { \
  444. dma_ptr = savage_dma_alloc(dev_priv, (n)); \
  445. } else { /* fast path for small allocations */ \
  446. dma_ptr = (uint32_t *)dev_priv->cmd_dma->handle + \
  447. cur * SAVAGE_DMA_PAGE_SIZE + \
  448. dev_priv->dma_pages[cur].used; \
  449. if (dev_priv->dma_pages[cur].used == 0) \
  450. savage_dma_wait(dev_priv, cur); \
  451. dev_priv->dma_pages[cur].used += (n); \
  452. } \
  453. } while(0)
  454. #define DMA_WRITE( val ) *dma_ptr++ = (uint32_t)(val)
  455. #define DMA_COPY(src, n) do { \
  456. memcpy(dma_ptr, (src), (n)*4); \
  457. dma_ptr += n; \
  458. } while(0)
  459. #if SAVAGE_DMA_DEBUG
  460. #define DMA_COMMIT() do { \
  461. unsigned int cur = dev_priv->current_dma_page; \
  462. uint32_t *expected = (uint32_t *)dev_priv->cmd_dma->handle + \
  463. cur * SAVAGE_DMA_PAGE_SIZE + \
  464. dev_priv->dma_pages[cur].used; \
  465. if (dma_ptr != expected) { \
  466. DRM_ERROR("DMA allocation and use don't match: " \
  467. "%p != %p\n", expected, dma_ptr); \
  468. savage_dma_reset(dev_priv); \
  469. } \
  470. } while(0)
  471. #else
  472. #define DMA_COMMIT() do {/* nothing */} while(0)
  473. #endif
  474. #define DMA_FLUSH() dev_priv->dma_flush(dev_priv)
  475. /* Buffer aging via event tag
  476. */
  477. #define UPDATE_EVENT_COUNTER( ) do { \
  478. if (dev_priv->status_ptr) { \
  479. uint16_t count; \
  480. /* coordinate with Xserver */ \
  481. count = dev_priv->status_ptr[1023]; \
  482. if (count < dev_priv->event_counter) \
  483. dev_priv->event_wrap++; \
  484. dev_priv->event_counter = count; \
  485. } \
  486. } while(0)
  487. #define SET_AGE( age, e, w ) do { \
  488. (age)->event = e; \
  489. (age)->wrap = w; \
  490. } while(0)
  491. #define TEST_AGE( age, e, w ) \
  492. ( (age)->wrap < (w) || ( (age)->wrap == (w) && (age)->event <= (e) ) )
  493. #endif /* __SAVAGE_DRV_H__ */