r128_drv.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. /* r128_drv.h -- Private header for r128 driver -*- linux-c -*-
  2. * Created: Mon Dec 13 09:51:11 1999 by faith@precisioninsight.com
  3. */
  4. /*
  5. * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  6. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  7. * All rights reserved.
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a
  10. * copy of this software and associated documentation files (the "Software"),
  11. * to deal in the Software without restriction, including without limitation
  12. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13. * and/or sell copies of the Software, and to permit persons to whom the
  14. * Software is furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice (including the next
  17. * paragraph) shall be included in all copies or substantial portions of the
  18. * Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  23. * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  24. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  25. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  26. * DEALINGS IN THE SOFTWARE.
  27. *
  28. * Authors:
  29. * Rickard E. (Rik) Faith <faith@valinux.com>
  30. * Kevin E. Martin <martin@valinux.com>
  31. * Gareth Hughes <gareth@valinux.com>
  32. * Michel D�zer <daenzerm@student.ethz.ch>
  33. */
  34. #ifndef __R128_DRV_H__
  35. #define __R128_DRV_H__
  36. /* General customization:
  37. */
  38. #define DRIVER_AUTHOR "Gareth Hughes, VA Linux Systems Inc."
  39. #define DRIVER_NAME "r128"
  40. #define DRIVER_DESC "ATI Rage 128"
  41. #define DRIVER_DATE "20030725"
  42. /* Interface history:
  43. *
  44. * ?? - ??
  45. * 2.4 - Add support for ycbcr textures (no new ioctls)
  46. * 2.5 - Add FLIP ioctl, disable FULLSCREEN.
  47. */
  48. #define DRIVER_MAJOR 2
  49. #define DRIVER_MINOR 5
  50. #define DRIVER_PATCHLEVEL 0
  51. #define GET_RING_HEAD(dev_priv) R128_READ(R128_PM4_BUFFER_DL_RPTR)
  52. typedef struct drm_r128_freelist {
  53. unsigned int age;
  54. struct drm_buf *buf;
  55. struct drm_r128_freelist *next;
  56. struct drm_r128_freelist *prev;
  57. } drm_r128_freelist_t;
  58. typedef struct drm_r128_ring_buffer {
  59. u32 *start;
  60. u32 *end;
  61. int size;
  62. int size_l2qw;
  63. u32 tail;
  64. u32 tail_mask;
  65. int space;
  66. int high_mark;
  67. } drm_r128_ring_buffer_t;
  68. typedef struct drm_r128_private {
  69. drm_r128_ring_buffer_t ring;
  70. drm_r128_sarea_t *sarea_priv;
  71. int cce_mode;
  72. int cce_fifo_size;
  73. int cce_running;
  74. drm_r128_freelist_t *head;
  75. drm_r128_freelist_t *tail;
  76. int usec_timeout;
  77. int is_pci;
  78. unsigned long cce_buffers_offset;
  79. atomic_t idle_count;
  80. int page_flipping;
  81. int current_page;
  82. u32 crtc_offset;
  83. u32 crtc_offset_cntl;
  84. atomic_t vbl_received;
  85. u32 color_fmt;
  86. unsigned int front_offset;
  87. unsigned int front_pitch;
  88. unsigned int back_offset;
  89. unsigned int back_pitch;
  90. u32 depth_fmt;
  91. unsigned int depth_offset;
  92. unsigned int depth_pitch;
  93. unsigned int span_offset;
  94. u32 front_pitch_offset_c;
  95. u32 back_pitch_offset_c;
  96. u32 depth_pitch_offset_c;
  97. u32 span_pitch_offset_c;
  98. drm_local_map_t *sarea;
  99. drm_local_map_t *mmio;
  100. drm_local_map_t *cce_ring;
  101. drm_local_map_t *ring_rptr;
  102. drm_local_map_t *agp_textures;
  103. struct drm_ati_pcigart_info gart_info;
  104. } drm_r128_private_t;
  105. typedef struct drm_r128_buf_priv {
  106. u32 age;
  107. int prim;
  108. int discard;
  109. int dispatched;
  110. drm_r128_freelist_t *list_entry;
  111. } drm_r128_buf_priv_t;
  112. extern struct drm_ioctl_desc r128_ioctls[];
  113. extern int r128_max_ioctl;
  114. /* r128_cce.c */
  115. extern int r128_cce_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
  116. extern int r128_cce_start(struct drm_device *dev, void *data, struct drm_file *file_priv);
  117. extern int r128_cce_stop(struct drm_device *dev, void *data, struct drm_file *file_priv);
  118. extern int r128_cce_reset(struct drm_device *dev, void *data, struct drm_file *file_priv);
  119. extern int r128_cce_idle(struct drm_device *dev, void *data, struct drm_file *file_priv);
  120. extern int r128_engine_reset(struct drm_device *dev, void *data, struct drm_file *file_priv);
  121. extern int r128_fullscreen(struct drm_device *dev, void *data, struct drm_file *file_priv);
  122. extern int r128_cce_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv);
  123. extern void r128_freelist_reset(struct drm_device *dev);
  124. extern int r128_wait_ring(drm_r128_private_t *dev_priv, int n);
  125. extern int r128_do_cce_idle(drm_r128_private_t *dev_priv);
  126. extern int r128_do_cleanup_cce(struct drm_device *dev);
  127. extern int r128_enable_vblank(struct drm_device *dev, int crtc);
  128. extern void r128_disable_vblank(struct drm_device *dev, int crtc);
  129. extern u32 r128_get_vblank_counter(struct drm_device *dev, int crtc);
  130. extern irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS);
  131. extern void r128_driver_irq_preinstall(struct drm_device *dev);
  132. extern int r128_driver_irq_postinstall(struct drm_device *dev);
  133. extern void r128_driver_irq_uninstall(struct drm_device *dev);
  134. extern void r128_driver_lastclose(struct drm_device *dev);
  135. extern int r128_driver_load(struct drm_device *dev, unsigned long flags);
  136. extern void r128_driver_preclose(struct drm_device *dev,
  137. struct drm_file *file_priv);
  138. extern long r128_compat_ioctl(struct file *filp, unsigned int cmd,
  139. unsigned long arg);
  140. /* Register definitions, register access macros and drmAddMap constants
  141. * for Rage 128 kernel driver.
  142. */
  143. #define R128_AUX_SC_CNTL 0x1660
  144. # define R128_AUX1_SC_EN (1 << 0)
  145. # define R128_AUX1_SC_MODE_OR (0 << 1)
  146. # define R128_AUX1_SC_MODE_NAND (1 << 1)
  147. # define R128_AUX2_SC_EN (1 << 2)
  148. # define R128_AUX2_SC_MODE_OR (0 << 3)
  149. # define R128_AUX2_SC_MODE_NAND (1 << 3)
  150. # define R128_AUX3_SC_EN (1 << 4)
  151. # define R128_AUX3_SC_MODE_OR (0 << 5)
  152. # define R128_AUX3_SC_MODE_NAND (1 << 5)
  153. #define R128_AUX1_SC_LEFT 0x1664
  154. #define R128_AUX1_SC_RIGHT 0x1668
  155. #define R128_AUX1_SC_TOP 0x166c
  156. #define R128_AUX1_SC_BOTTOM 0x1670
  157. #define R128_AUX2_SC_LEFT 0x1674
  158. #define R128_AUX2_SC_RIGHT 0x1678
  159. #define R128_AUX2_SC_TOP 0x167c
  160. #define R128_AUX2_SC_BOTTOM 0x1680
  161. #define R128_AUX3_SC_LEFT 0x1684
  162. #define R128_AUX3_SC_RIGHT 0x1688
  163. #define R128_AUX3_SC_TOP 0x168c
  164. #define R128_AUX3_SC_BOTTOM 0x1690
  165. #define R128_BRUSH_DATA0 0x1480
  166. #define R128_BUS_CNTL 0x0030
  167. # define R128_BUS_MASTER_DIS (1 << 6)
  168. #define R128_CLOCK_CNTL_INDEX 0x0008
  169. #define R128_CLOCK_CNTL_DATA 0x000c
  170. # define R128_PLL_WR_EN (1 << 7)
  171. #define R128_CONSTANT_COLOR_C 0x1d34
  172. #define R128_CRTC_OFFSET 0x0224
  173. #define R128_CRTC_OFFSET_CNTL 0x0228
  174. # define R128_CRTC_OFFSET_FLIP_CNTL (1 << 16)
  175. #define R128_DP_GUI_MASTER_CNTL 0x146c
  176. # define R128_GMC_SRC_PITCH_OFFSET_CNTL (1 << 0)
  177. # define R128_GMC_DST_PITCH_OFFSET_CNTL (1 << 1)
  178. # define R128_GMC_BRUSH_SOLID_COLOR (13 << 4)
  179. # define R128_GMC_BRUSH_NONE (15 << 4)
  180. # define R128_GMC_DST_16BPP (4 << 8)
  181. # define R128_GMC_DST_24BPP (5 << 8)
  182. # define R128_GMC_DST_32BPP (6 << 8)
  183. # define R128_GMC_DST_DATATYPE_SHIFT 8
  184. # define R128_GMC_SRC_DATATYPE_COLOR (3 << 12)
  185. # define R128_DP_SRC_SOURCE_MEMORY (2 << 24)
  186. # define R128_DP_SRC_SOURCE_HOST_DATA (3 << 24)
  187. # define R128_GMC_CLR_CMP_CNTL_DIS (1 << 28)
  188. # define R128_GMC_AUX_CLIP_DIS (1 << 29)
  189. # define R128_GMC_WR_MSK_DIS (1 << 30)
  190. # define R128_ROP3_S 0x00cc0000
  191. # define R128_ROP3_P 0x00f00000
  192. #define R128_DP_WRITE_MASK 0x16cc
  193. #define R128_DST_PITCH_OFFSET_C 0x1c80
  194. # define R128_DST_TILE (1 << 31)
  195. #define R128_GEN_INT_CNTL 0x0040
  196. # define R128_CRTC_VBLANK_INT_EN (1 << 0)
  197. #define R128_GEN_INT_STATUS 0x0044
  198. # define R128_CRTC_VBLANK_INT (1 << 0)
  199. # define R128_CRTC_VBLANK_INT_AK (1 << 0)
  200. #define R128_GEN_RESET_CNTL 0x00f0
  201. # define R128_SOFT_RESET_GUI (1 << 0)
  202. #define R128_GUI_SCRATCH_REG0 0x15e0
  203. #define R128_GUI_SCRATCH_REG1 0x15e4
  204. #define R128_GUI_SCRATCH_REG2 0x15e8
  205. #define R128_GUI_SCRATCH_REG3 0x15ec
  206. #define R128_GUI_SCRATCH_REG4 0x15f0
  207. #define R128_GUI_SCRATCH_REG5 0x15f4
  208. #define R128_GUI_STAT 0x1740
  209. # define R128_GUI_FIFOCNT_MASK 0x0fff
  210. # define R128_GUI_ACTIVE (1 << 31)
  211. #define R128_MCLK_CNTL 0x000f
  212. # define R128_FORCE_GCP (1 << 16)
  213. # define R128_FORCE_PIPE3D_CP (1 << 17)
  214. # define R128_FORCE_RCP (1 << 18)
  215. #define R128_PC_GUI_CTLSTAT 0x1748
  216. #define R128_PC_NGUI_CTLSTAT 0x0184
  217. # define R128_PC_FLUSH_GUI (3 << 0)
  218. # define R128_PC_RI_GUI (1 << 2)
  219. # define R128_PC_FLUSH_ALL 0x00ff
  220. # define R128_PC_BUSY (1 << 31)
  221. #define R128_PCI_GART_PAGE 0x017c
  222. #define R128_PRIM_TEX_CNTL_C 0x1cb0
  223. #define R128_SCALE_3D_CNTL 0x1a00
  224. #define R128_SEC_TEX_CNTL_C 0x1d00
  225. #define R128_SEC_TEXTURE_BORDER_COLOR_C 0x1d3c
  226. #define R128_SETUP_CNTL 0x1bc4
  227. #define R128_STEN_REF_MASK_C 0x1d40
  228. #define R128_TEX_CNTL_C 0x1c9c
  229. # define R128_TEX_CACHE_FLUSH (1 << 23)
  230. #define R128_WAIT_UNTIL 0x1720
  231. # define R128_EVENT_CRTC_OFFSET (1 << 0)
  232. #define R128_WINDOW_XY_OFFSET 0x1bcc
  233. /* CCE registers
  234. */
  235. #define R128_PM4_BUFFER_OFFSET 0x0700
  236. #define R128_PM4_BUFFER_CNTL 0x0704
  237. # define R128_PM4_MASK (15 << 28)
  238. # define R128_PM4_NONPM4 (0 << 28)
  239. # define R128_PM4_192PIO (1 << 28)
  240. # define R128_PM4_192BM (2 << 28)
  241. # define R128_PM4_128PIO_64INDBM (3 << 28)
  242. # define R128_PM4_128BM_64INDBM (4 << 28)
  243. # define R128_PM4_64PIO_128INDBM (5 << 28)
  244. # define R128_PM4_64BM_128INDBM (6 << 28)
  245. # define R128_PM4_64PIO_64VCBM_64INDBM (7 << 28)
  246. # define R128_PM4_64BM_64VCBM_64INDBM (8 << 28)
  247. # define R128_PM4_64PIO_64VCPIO_64INDPIO (15 << 28)
  248. # define R128_PM4_BUFFER_CNTL_NOUPDATE (1 << 27)
  249. #define R128_PM4_BUFFER_WM_CNTL 0x0708
  250. # define R128_WMA_SHIFT 0
  251. # define R128_WMB_SHIFT 8
  252. # define R128_WMC_SHIFT 16
  253. # define R128_WB_WM_SHIFT 24
  254. #define R128_PM4_BUFFER_DL_RPTR_ADDR 0x070c
  255. #define R128_PM4_BUFFER_DL_RPTR 0x0710
  256. #define R128_PM4_BUFFER_DL_WPTR 0x0714
  257. # define R128_PM4_BUFFER_DL_DONE (1 << 31)
  258. #define R128_PM4_VC_FPU_SETUP 0x071c
  259. #define R128_PM4_IW_INDOFF 0x0738
  260. #define R128_PM4_IW_INDSIZE 0x073c
  261. #define R128_PM4_STAT 0x07b8
  262. # define R128_PM4_FIFOCNT_MASK 0x0fff
  263. # define R128_PM4_BUSY (1 << 16)
  264. # define R128_PM4_GUI_ACTIVE (1 << 31)
  265. #define R128_PM4_MICROCODE_ADDR 0x07d4
  266. #define R128_PM4_MICROCODE_RADDR 0x07d8
  267. #define R128_PM4_MICROCODE_DATAH 0x07dc
  268. #define R128_PM4_MICROCODE_DATAL 0x07e0
  269. #define R128_PM4_BUFFER_ADDR 0x07f0
  270. #define R128_PM4_MICRO_CNTL 0x07fc
  271. # define R128_PM4_MICRO_FREERUN (1 << 30)
  272. #define R128_PM4_FIFO_DATA_EVEN 0x1000
  273. #define R128_PM4_FIFO_DATA_ODD 0x1004
  274. /* CCE command packets
  275. */
  276. #define R128_CCE_PACKET0 0x00000000
  277. #define R128_CCE_PACKET1 0x40000000
  278. #define R128_CCE_PACKET2 0x80000000
  279. #define R128_CCE_PACKET3 0xC0000000
  280. # define R128_CNTL_HOSTDATA_BLT 0x00009400
  281. # define R128_CNTL_PAINT_MULTI 0x00009A00
  282. # define R128_CNTL_BITBLT_MULTI 0x00009B00
  283. # define R128_3D_RNDR_GEN_INDX_PRIM 0x00002300
  284. #define R128_CCE_PACKET_MASK 0xC0000000
  285. #define R128_CCE_PACKET_COUNT_MASK 0x3fff0000
  286. #define R128_CCE_PACKET0_REG_MASK 0x000007ff
  287. #define R128_CCE_PACKET1_REG0_MASK 0x000007ff
  288. #define R128_CCE_PACKET1_REG1_MASK 0x003ff800
  289. #define R128_CCE_VC_CNTL_PRIM_TYPE_NONE 0x00000000
  290. #define R128_CCE_VC_CNTL_PRIM_TYPE_POINT 0x00000001
  291. #define R128_CCE_VC_CNTL_PRIM_TYPE_LINE 0x00000002
  292. #define R128_CCE_VC_CNTL_PRIM_TYPE_POLY_LINE 0x00000003
  293. #define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_LIST 0x00000004
  294. #define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_FAN 0x00000005
  295. #define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_STRIP 0x00000006
  296. #define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_TYPE2 0x00000007
  297. #define R128_CCE_VC_CNTL_PRIM_WALK_IND 0x00000010
  298. #define R128_CCE_VC_CNTL_PRIM_WALK_LIST 0x00000020
  299. #define R128_CCE_VC_CNTL_PRIM_WALK_RING 0x00000030
  300. #define R128_CCE_VC_CNTL_NUM_SHIFT 16
  301. #define R128_DATATYPE_VQ 0
  302. #define R128_DATATYPE_CI4 1
  303. #define R128_DATATYPE_CI8 2
  304. #define R128_DATATYPE_ARGB1555 3
  305. #define R128_DATATYPE_RGB565 4
  306. #define R128_DATATYPE_RGB888 5
  307. #define R128_DATATYPE_ARGB8888 6
  308. #define R128_DATATYPE_RGB332 7
  309. #define R128_DATATYPE_Y8 8
  310. #define R128_DATATYPE_RGB8 9
  311. #define R128_DATATYPE_CI16 10
  312. #define R128_DATATYPE_YVYU422 11
  313. #define R128_DATATYPE_VYUY422 12
  314. #define R128_DATATYPE_AYUV444 14
  315. #define R128_DATATYPE_ARGB4444 15
  316. /* Constants */
  317. #define R128_AGP_OFFSET 0x02000000
  318. #define R128_WATERMARK_L 16
  319. #define R128_WATERMARK_M 8
  320. #define R128_WATERMARK_N 8
  321. #define R128_WATERMARK_K 128
  322. #define R128_MAX_USEC_TIMEOUT 100000 /* 100 ms */
  323. #define R128_LAST_FRAME_REG R128_GUI_SCRATCH_REG0
  324. #define R128_LAST_DISPATCH_REG R128_GUI_SCRATCH_REG1
  325. #define R128_MAX_VB_AGE 0x7fffffff
  326. #define R128_MAX_VB_VERTS (0xffff)
  327. #define R128_RING_HIGH_MARK 128
  328. #define R128_PERFORMANCE_BOXES 0
  329. #define R128_PCIGART_TABLE_SIZE 32768
  330. #define R128_READ(reg) DRM_READ32(dev_priv->mmio, (reg))
  331. #define R128_WRITE(reg, val) DRM_WRITE32(dev_priv->mmio, (reg), (val))
  332. #define R128_READ8(reg) DRM_READ8(dev_priv->mmio, (reg))
  333. #define R128_WRITE8(reg, val) DRM_WRITE8(dev_priv->mmio, (reg), (val))
  334. #define R128_WRITE_PLL(addr, val) \
  335. do { \
  336. R128_WRITE8(R128_CLOCK_CNTL_INDEX, \
  337. ((addr) & 0x1f) | R128_PLL_WR_EN); \
  338. R128_WRITE(R128_CLOCK_CNTL_DATA, (val)); \
  339. } while (0)
  340. #define CCE_PACKET0(reg, n) (R128_CCE_PACKET0 | \
  341. ((n) << 16) | ((reg) >> 2))
  342. #define CCE_PACKET1(reg0, reg1) (R128_CCE_PACKET1 | \
  343. (((reg1) >> 2) << 11) | ((reg0) >> 2))
  344. #define CCE_PACKET2() (R128_CCE_PACKET2)
  345. #define CCE_PACKET3(pkt, n) (R128_CCE_PACKET3 | \
  346. (pkt) | ((n) << 16))
  347. static __inline__ void r128_update_ring_snapshot(drm_r128_private_t *dev_priv)
  348. {
  349. drm_r128_ring_buffer_t *ring = &dev_priv->ring;
  350. ring->space = (GET_RING_HEAD(dev_priv) - ring->tail) * sizeof(u32);
  351. if (ring->space <= 0)
  352. ring->space += ring->size;
  353. }
  354. /* ================================================================
  355. * Misc helper macros
  356. */
  357. #define DEV_INIT_TEST_WITH_RETURN(_dev_priv) \
  358. do { \
  359. if (!_dev_priv) { \
  360. DRM_ERROR("called with no initialization\n"); \
  361. return -EINVAL; \
  362. } \
  363. } while (0)
  364. #define RING_SPACE_TEST_WITH_RETURN(dev_priv) \
  365. do { \
  366. drm_r128_ring_buffer_t *ring = &dev_priv->ring; int i; \
  367. if (ring->space < ring->high_mark) { \
  368. for (i = 0 ; i < dev_priv->usec_timeout ; i++) { \
  369. r128_update_ring_snapshot(dev_priv); \
  370. if (ring->space >= ring->high_mark) \
  371. goto __ring_space_done; \
  372. DRM_UDELAY(1); \
  373. } \
  374. DRM_ERROR("ring space check failed!\n"); \
  375. return -EBUSY; \
  376. } \
  377. __ring_space_done: \
  378. ; \
  379. } while (0)
  380. #define VB_AGE_TEST_WITH_RETURN(dev_priv) \
  381. do { \
  382. drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; \
  383. if (sarea_priv->last_dispatch >= R128_MAX_VB_AGE) { \
  384. int __ret = r128_do_cce_idle(dev_priv); \
  385. if (__ret) \
  386. return __ret; \
  387. sarea_priv->last_dispatch = 0; \
  388. r128_freelist_reset(dev); \
  389. } \
  390. } while (0)
  391. #define R128_WAIT_UNTIL_PAGE_FLIPPED() do { \
  392. OUT_RING(CCE_PACKET0(R128_WAIT_UNTIL, 0)); \
  393. OUT_RING(R128_EVENT_CRTC_OFFSET); \
  394. } while (0)
  395. /* ================================================================
  396. * Ring control
  397. */
  398. #define R128_VERBOSE 0
  399. #define RING_LOCALS \
  400. int write, _nr; unsigned int tail_mask; volatile u32 *ring;
  401. #define BEGIN_RING(n) do { \
  402. if (R128_VERBOSE) \
  403. DRM_INFO("BEGIN_RING(%d)\n", (n)); \
  404. if (dev_priv->ring.space <= (n) * sizeof(u32)) { \
  405. COMMIT_RING(); \
  406. r128_wait_ring(dev_priv, (n) * sizeof(u32)); \
  407. } \
  408. _nr = n; dev_priv->ring.space -= (n) * sizeof(u32); \
  409. ring = dev_priv->ring.start; \
  410. write = dev_priv->ring.tail; \
  411. tail_mask = dev_priv->ring.tail_mask; \
  412. } while (0)
  413. /* You can set this to zero if you want. If the card locks up, you'll
  414. * need to keep this set. It works around a bug in early revs of the
  415. * Rage 128 chipset, where the CCE would read 32 dwords past the end of
  416. * the ring buffer before wrapping around.
  417. */
  418. #define R128_BROKEN_CCE 1
  419. #define ADVANCE_RING() do { \
  420. if (R128_VERBOSE) \
  421. DRM_INFO("ADVANCE_RING() wr=0x%06x tail=0x%06x\n", \
  422. write, dev_priv->ring.tail); \
  423. if (R128_BROKEN_CCE && write < 32) \
  424. memcpy(dev_priv->ring.end, \
  425. dev_priv->ring.start, \
  426. write * sizeof(u32)); \
  427. if (((dev_priv->ring.tail + _nr) & tail_mask) != write) \
  428. DRM_ERROR( \
  429. "ADVANCE_RING(): mismatch: nr: %x write: %x line: %d\n", \
  430. ((dev_priv->ring.tail + _nr) & tail_mask), \
  431. write, __LINE__); \
  432. else \
  433. dev_priv->ring.tail = write; \
  434. } while (0)
  435. #define COMMIT_RING() do { \
  436. if (R128_VERBOSE) \
  437. DRM_INFO("COMMIT_RING() tail=0x%06x\n", \
  438. dev_priv->ring.tail); \
  439. DRM_MEMORYBARRIER(); \
  440. R128_WRITE(R128_PM4_BUFFER_DL_WPTR, dev_priv->ring.tail); \
  441. R128_READ(R128_PM4_BUFFER_DL_WPTR); \
  442. } while (0)
  443. #define OUT_RING(x) do { \
  444. if (R128_VERBOSE) \
  445. DRM_INFO(" OUT_RING( 0x%08x ) at 0x%x\n", \
  446. (unsigned int)(x), write); \
  447. ring[write++] = cpu_to_le32(x); \
  448. write &= tail_mask; \
  449. } while (0)
  450. #endif /* __R128_DRV_H__ */