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