blob: 94abffb2cca56859ded7d19631b77f39af2396cf [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* r128_drv.h -- Private header for r128 driver -*- linux-c -*-
2 * Created: Mon Dec 13 09:51:11 1999 by faith@precisioninsight.com
Dave Airlief26c4732006-01-02 17:18:39 +11003 */
4/* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * 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 * PRECISION INSIGHT 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 OTHER
25 * DEALINGS IN THE SOFTWARE.
26 *
27 * Authors:
28 * Rickard E. (Rik) Faith <faith@valinux.com>
29 * Kevin E. Martin <martin@valinux.com>
30 * Gareth Hughes <gareth@valinux.com>
31 * Michel D�zer <daenzerm@student.ethz.ch>
32 */
33
34#ifndef __R128_DRV_H__
35#define __R128_DRV_H__
36
37/* General customization:
38 */
39#define DRIVER_AUTHOR "Gareth Hughes, VA Linux Systems Inc."
40
41#define DRIVER_NAME "r128"
42#define DRIVER_DESC "ATI Rage 128"
43#define DRIVER_DATE "20030725"
44
45/* Interface history:
46 *
47 * ?? - ??
48 * 2.4 - Add support for ycbcr textures (no new ioctls)
49 * 2.5 - Add FLIP ioctl, disable FULLSCREEN.
50 */
51#define DRIVER_MAJOR 2
52#define DRIVER_MINOR 5
53#define DRIVER_PATCHLEVEL 0
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#define GET_RING_HEAD(dev_priv) R128_READ( R128_PM4_BUFFER_DL_RPTR )
56
57typedef struct drm_r128_freelist {
Dave Airlieb5e89ed2005-09-25 14:28:13 +100058 unsigned int age;
59 drm_buf_t *buf;
60 struct drm_r128_freelist *next;
61 struct drm_r128_freelist *prev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062} drm_r128_freelist_t;
63
64typedef struct drm_r128_ring_buffer {
65 u32 *start;
66 u32 *end;
67 int size;
68 int size_l2qw;
69
70 u32 tail;
71 u32 tail_mask;
72 int space;
73
74 int high_mark;
75} drm_r128_ring_buffer_t;
76
77typedef struct drm_r128_private {
78 drm_r128_ring_buffer_t ring;
79 drm_r128_sarea_t *sarea_priv;
80
81 int cce_mode;
82 int cce_fifo_size;
83 int cce_running;
84
Dave Airlieb5e89ed2005-09-25 14:28:13 +100085 drm_r128_freelist_t *head;
86 drm_r128_freelist_t *tail;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 int usec_timeout;
89 int is_pci;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 unsigned long cce_buffers_offset;
91
92 atomic_t idle_count;
93
94 int page_flipping;
95 int current_page;
96 u32 crtc_offset;
97 u32 crtc_offset_cntl;
98
99 u32 color_fmt;
100 unsigned int front_offset;
101 unsigned int front_pitch;
102 unsigned int back_offset;
103 unsigned int back_pitch;
104
105 u32 depth_fmt;
106 unsigned int depth_offset;
107 unsigned int depth_pitch;
108 unsigned int span_offset;
109
110 u32 front_pitch_offset_c;
111 u32 back_pitch_offset_c;
112 u32 depth_pitch_offset_c;
113 u32 span_pitch_offset_c;
114
115 drm_local_map_t *sarea;
116 drm_local_map_t *mmio;
117 drm_local_map_t *cce_ring;
118 drm_local_map_t *ring_rptr;
119 drm_local_map_t *agp_textures;
Dave Airlieea98a922005-09-11 20:28:11 +1000120 drm_ati_pcigart_info gart_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121} drm_r128_private_t;
122
123typedef struct drm_r128_buf_priv {
124 u32 age;
125 int prim;
126 int discard;
127 int dispatched;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000128 drm_r128_freelist_t *list_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129} drm_r128_buf_priv_t;
130
Dave Airlieb3a83632005-09-30 18:37:36 +1000131extern drm_ioctl_desc_t r128_ioctls[];
132extern int r128_max_ioctl;
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 /* r128_cce.c */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000135extern int r128_cce_init(DRM_IOCTL_ARGS);
136extern int r128_cce_start(DRM_IOCTL_ARGS);
137extern int r128_cce_stop(DRM_IOCTL_ARGS);
138extern int r128_cce_reset(DRM_IOCTL_ARGS);
139extern int r128_cce_idle(DRM_IOCTL_ARGS);
140extern int r128_engine_reset(DRM_IOCTL_ARGS);
141extern int r128_fullscreen(DRM_IOCTL_ARGS);
142extern int r128_cce_buffers(DRM_IOCTL_ARGS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000144extern void r128_freelist_reset(drm_device_t * dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000146extern int r128_wait_ring(drm_r128_private_t * dev_priv, int n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000148extern int r128_do_cce_idle(drm_r128_private_t * dev_priv);
149extern int r128_do_cleanup_cce(drm_device_t * dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000151extern int r128_driver_vblank_wait(drm_device_t * dev, unsigned int *sequence);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000153extern irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS);
154extern void r128_driver_irq_preinstall(drm_device_t * dev);
155extern void r128_driver_irq_postinstall(drm_device_t * dev);
156extern void r128_driver_irq_uninstall(drm_device_t * dev);
Dave Airlie22eae942005-11-10 22:16:34 +1100157extern void r128_driver_lastclose(drm_device_t * dev);
158extern void r128_driver_preclose(drm_device_t * dev, DRMFILE filp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000160extern long r128_compat_ioctl(struct file *filp, unsigned int cmd,
161 unsigned long arg);
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163/* Register definitions, register access macros and drmAddMap constants
164 * for Rage 128 kernel driver.
165 */
166
167#define R128_AUX_SC_CNTL 0x1660
168# define R128_AUX1_SC_EN (1 << 0)
169# define R128_AUX1_SC_MODE_OR (0 << 1)
170# define R128_AUX1_SC_MODE_NAND (1 << 1)
171# define R128_AUX2_SC_EN (1 << 2)
172# define R128_AUX2_SC_MODE_OR (0 << 3)
173# define R128_AUX2_SC_MODE_NAND (1 << 3)
174# define R128_AUX3_SC_EN (1 << 4)
175# define R128_AUX3_SC_MODE_OR (0 << 5)
176# define R128_AUX3_SC_MODE_NAND (1 << 5)
177#define R128_AUX1_SC_LEFT 0x1664
178#define R128_AUX1_SC_RIGHT 0x1668
179#define R128_AUX1_SC_TOP 0x166c
180#define R128_AUX1_SC_BOTTOM 0x1670
181#define R128_AUX2_SC_LEFT 0x1674
182#define R128_AUX2_SC_RIGHT 0x1678
183#define R128_AUX2_SC_TOP 0x167c
184#define R128_AUX2_SC_BOTTOM 0x1680
185#define R128_AUX3_SC_LEFT 0x1684
186#define R128_AUX3_SC_RIGHT 0x1688
187#define R128_AUX3_SC_TOP 0x168c
188#define R128_AUX3_SC_BOTTOM 0x1690
189
190#define R128_BRUSH_DATA0 0x1480
191#define R128_BUS_CNTL 0x0030
192# define R128_BUS_MASTER_DIS (1 << 6)
193
194#define R128_CLOCK_CNTL_INDEX 0x0008
195#define R128_CLOCK_CNTL_DATA 0x000c
196# define R128_PLL_WR_EN (1 << 7)
197#define R128_CONSTANT_COLOR_C 0x1d34
198#define R128_CRTC_OFFSET 0x0224
199#define R128_CRTC_OFFSET_CNTL 0x0228
200# define R128_CRTC_OFFSET_FLIP_CNTL (1 << 16)
201
202#define R128_DP_GUI_MASTER_CNTL 0x146c
203# define R128_GMC_SRC_PITCH_OFFSET_CNTL (1 << 0)
204# define R128_GMC_DST_PITCH_OFFSET_CNTL (1 << 1)
205# define R128_GMC_BRUSH_SOLID_COLOR (13 << 4)
206# define R128_GMC_BRUSH_NONE (15 << 4)
207# define R128_GMC_DST_16BPP (4 << 8)
208# define R128_GMC_DST_24BPP (5 << 8)
209# define R128_GMC_DST_32BPP (6 << 8)
210# define R128_GMC_DST_DATATYPE_SHIFT 8
211# define R128_GMC_SRC_DATATYPE_COLOR (3 << 12)
212# define R128_DP_SRC_SOURCE_MEMORY (2 << 24)
213# define R128_DP_SRC_SOURCE_HOST_DATA (3 << 24)
214# define R128_GMC_CLR_CMP_CNTL_DIS (1 << 28)
215# define R128_GMC_AUX_CLIP_DIS (1 << 29)
216# define R128_GMC_WR_MSK_DIS (1 << 30)
217# define R128_ROP3_S 0x00cc0000
218# define R128_ROP3_P 0x00f00000
219#define R128_DP_WRITE_MASK 0x16cc
220#define R128_DST_PITCH_OFFSET_C 0x1c80
221# define R128_DST_TILE (1 << 31)
222
223#define R128_GEN_INT_CNTL 0x0040
224# define R128_CRTC_VBLANK_INT_EN (1 << 0)
225#define R128_GEN_INT_STATUS 0x0044
226# define R128_CRTC_VBLANK_INT (1 << 0)
227# define R128_CRTC_VBLANK_INT_AK (1 << 0)
228#define R128_GEN_RESET_CNTL 0x00f0
229# define R128_SOFT_RESET_GUI (1 << 0)
230
231#define R128_GUI_SCRATCH_REG0 0x15e0
232#define R128_GUI_SCRATCH_REG1 0x15e4
233#define R128_GUI_SCRATCH_REG2 0x15e8
234#define R128_GUI_SCRATCH_REG3 0x15ec
235#define R128_GUI_SCRATCH_REG4 0x15f0
236#define R128_GUI_SCRATCH_REG5 0x15f4
237
238#define R128_GUI_STAT 0x1740
239# define R128_GUI_FIFOCNT_MASK 0x0fff
240# define R128_GUI_ACTIVE (1 << 31)
241
242#define R128_MCLK_CNTL 0x000f
243# define R128_FORCE_GCP (1 << 16)
244# define R128_FORCE_PIPE3D_CP (1 << 17)
245# define R128_FORCE_RCP (1 << 18)
246
247#define R128_PC_GUI_CTLSTAT 0x1748
248#define R128_PC_NGUI_CTLSTAT 0x0184
249# define R128_PC_FLUSH_GUI (3 << 0)
250# define R128_PC_RI_GUI (1 << 2)
251# define R128_PC_FLUSH_ALL 0x00ff
252# define R128_PC_BUSY (1 << 31)
253
254#define R128_PCI_GART_PAGE 0x017c
255#define R128_PRIM_TEX_CNTL_C 0x1cb0
256
257#define R128_SCALE_3D_CNTL 0x1a00
258#define R128_SEC_TEX_CNTL_C 0x1d00
259#define R128_SEC_TEXTURE_BORDER_COLOR_C 0x1d3c
260#define R128_SETUP_CNTL 0x1bc4
261#define R128_STEN_REF_MASK_C 0x1d40
262
263#define R128_TEX_CNTL_C 0x1c9c
264# define R128_TEX_CACHE_FLUSH (1 << 23)
265
266#define R128_WAIT_UNTIL 0x1720
267# define R128_EVENT_CRTC_OFFSET (1 << 0)
268#define R128_WINDOW_XY_OFFSET 0x1bcc
269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270/* CCE registers
271 */
272#define R128_PM4_BUFFER_OFFSET 0x0700
273#define R128_PM4_BUFFER_CNTL 0x0704
274# define R128_PM4_MASK (15 << 28)
275# define R128_PM4_NONPM4 (0 << 28)
276# define R128_PM4_192PIO (1 << 28)
277# define R128_PM4_192BM (2 << 28)
278# define R128_PM4_128PIO_64INDBM (3 << 28)
279# define R128_PM4_128BM_64INDBM (4 << 28)
280# define R128_PM4_64PIO_128INDBM (5 << 28)
281# define R128_PM4_64BM_128INDBM (6 << 28)
282# define R128_PM4_64PIO_64VCBM_64INDBM (7 << 28)
283# define R128_PM4_64BM_64VCBM_64INDBM (8 << 28)
284# define R128_PM4_64PIO_64VCPIO_64INDPIO (15 << 28)
285# define R128_PM4_BUFFER_CNTL_NOUPDATE (1 << 27)
286
287#define R128_PM4_BUFFER_WM_CNTL 0x0708
288# define R128_WMA_SHIFT 0
289# define R128_WMB_SHIFT 8
290# define R128_WMC_SHIFT 16
291# define R128_WB_WM_SHIFT 24
292
293#define R128_PM4_BUFFER_DL_RPTR_ADDR 0x070c
294#define R128_PM4_BUFFER_DL_RPTR 0x0710
295#define R128_PM4_BUFFER_DL_WPTR 0x0714
296# define R128_PM4_BUFFER_DL_DONE (1 << 31)
297
298#define R128_PM4_VC_FPU_SETUP 0x071c
299
300#define R128_PM4_IW_INDOFF 0x0738
301#define R128_PM4_IW_INDSIZE 0x073c
302
303#define R128_PM4_STAT 0x07b8
304# define R128_PM4_FIFOCNT_MASK 0x0fff
305# define R128_PM4_BUSY (1 << 16)
306# define R128_PM4_GUI_ACTIVE (1 << 31)
307
308#define R128_PM4_MICROCODE_ADDR 0x07d4
309#define R128_PM4_MICROCODE_RADDR 0x07d8
310#define R128_PM4_MICROCODE_DATAH 0x07dc
311#define R128_PM4_MICROCODE_DATAL 0x07e0
312
313#define R128_PM4_BUFFER_ADDR 0x07f0
314#define R128_PM4_MICRO_CNTL 0x07fc
315# define R128_PM4_MICRO_FREERUN (1 << 30)
316
317#define R128_PM4_FIFO_DATA_EVEN 0x1000
318#define R128_PM4_FIFO_DATA_ODD 0x1004
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320/* CCE command packets
321 */
322#define R128_CCE_PACKET0 0x00000000
323#define R128_CCE_PACKET1 0x40000000
324#define R128_CCE_PACKET2 0x80000000
325#define R128_CCE_PACKET3 0xC0000000
326# define R128_CNTL_HOSTDATA_BLT 0x00009400
327# define R128_CNTL_PAINT_MULTI 0x00009A00
328# define R128_CNTL_BITBLT_MULTI 0x00009B00
329# define R128_3D_RNDR_GEN_INDX_PRIM 0x00002300
330
331#define R128_CCE_PACKET_MASK 0xC0000000
332#define R128_CCE_PACKET_COUNT_MASK 0x3fff0000
333#define R128_CCE_PACKET0_REG_MASK 0x000007ff
334#define R128_CCE_PACKET1_REG0_MASK 0x000007ff
335#define R128_CCE_PACKET1_REG1_MASK 0x003ff800
336
337#define R128_CCE_VC_CNTL_PRIM_TYPE_NONE 0x00000000
338#define R128_CCE_VC_CNTL_PRIM_TYPE_POINT 0x00000001
339#define R128_CCE_VC_CNTL_PRIM_TYPE_LINE 0x00000002
340#define R128_CCE_VC_CNTL_PRIM_TYPE_POLY_LINE 0x00000003
341#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_LIST 0x00000004
342#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_FAN 0x00000005
343#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_STRIP 0x00000006
344#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_TYPE2 0x00000007
345#define R128_CCE_VC_CNTL_PRIM_WALK_IND 0x00000010
346#define R128_CCE_VC_CNTL_PRIM_WALK_LIST 0x00000020
347#define R128_CCE_VC_CNTL_PRIM_WALK_RING 0x00000030
348#define R128_CCE_VC_CNTL_NUM_SHIFT 16
349
350#define R128_DATATYPE_VQ 0
351#define R128_DATATYPE_CI4 1
352#define R128_DATATYPE_CI8 2
353#define R128_DATATYPE_ARGB1555 3
354#define R128_DATATYPE_RGB565 4
355#define R128_DATATYPE_RGB888 5
356#define R128_DATATYPE_ARGB8888 6
357#define R128_DATATYPE_RGB332 7
358#define R128_DATATYPE_Y8 8
359#define R128_DATATYPE_RGB8 9
360#define R128_DATATYPE_CI16 10
361#define R128_DATATYPE_YVYU422 11
362#define R128_DATATYPE_VYUY422 12
363#define R128_DATATYPE_AYUV444 14
364#define R128_DATATYPE_ARGB4444 15
365
366/* Constants */
367#define R128_AGP_OFFSET 0x02000000
368
369#define R128_WATERMARK_L 16
370#define R128_WATERMARK_M 8
371#define R128_WATERMARK_N 8
372#define R128_WATERMARK_K 128
373
374#define R128_MAX_USEC_TIMEOUT 100000 /* 100 ms */
375
376#define R128_LAST_FRAME_REG R128_GUI_SCRATCH_REG0
377#define R128_LAST_DISPATCH_REG R128_GUI_SCRATCH_REG1
378#define R128_MAX_VB_AGE 0x7fffffff
379#define R128_MAX_VB_VERTS (0xffff)
380
381#define R128_RING_HIGH_MARK 128
382
383#define R128_PERFORMANCE_BOXES 0
384
385#define R128_READ(reg) DRM_READ32( dev_priv->mmio, (reg) )
386#define R128_WRITE(reg,val) DRM_WRITE32( dev_priv->mmio, (reg), (val) )
387#define R128_READ8(reg) DRM_READ8( dev_priv->mmio, (reg) )
388#define R128_WRITE8(reg,val) DRM_WRITE8( dev_priv->mmio, (reg), (val) )
389
390#define R128_WRITE_PLL(addr,val) \
391do { \
392 R128_WRITE8(R128_CLOCK_CNTL_INDEX, \
393 ((addr) & 0x1f) | R128_PLL_WR_EN); \
394 R128_WRITE(R128_CLOCK_CNTL_DATA, (val)); \
395} while (0)
396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397#define CCE_PACKET0( reg, n ) (R128_CCE_PACKET0 | \
398 ((n) << 16) | ((reg) >> 2))
399#define CCE_PACKET1( reg0, reg1 ) (R128_CCE_PACKET1 | \
400 (((reg1) >> 2) << 11) | ((reg0) >> 2))
401#define CCE_PACKET2() (R128_CCE_PACKET2)
402#define CCE_PACKET3( pkt, n ) (R128_CCE_PACKET3 | \
403 (pkt) | ((n) << 16))
404
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000405static __inline__ void r128_update_ring_snapshot(drm_r128_private_t * dev_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
407 drm_r128_ring_buffer_t *ring = &dev_priv->ring;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000408 ring->space = (GET_RING_HEAD(dev_priv) - ring->tail) * sizeof(u32);
409 if (ring->space <= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 ring->space += ring->size;
411}
412
413/* ================================================================
414 * Misc helper macros
415 */
416
417#define RING_SPACE_TEST_WITH_RETURN( dev_priv ) \
418do { \
419 drm_r128_ring_buffer_t *ring = &dev_priv->ring; int i; \
420 if ( ring->space < ring->high_mark ) { \
421 for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) { \
422 r128_update_ring_snapshot( dev_priv ); \
423 if ( ring->space >= ring->high_mark ) \
424 goto __ring_space_done; \
425 DRM_UDELAY(1); \
426 } \
427 DRM_ERROR( "ring space check failed!\n" ); \
428 return DRM_ERR(EBUSY); \
429 } \
430 __ring_space_done: \
431 ; \
432} while (0)
433
434#define VB_AGE_TEST_WITH_RETURN( dev_priv ) \
435do { \
436 drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; \
437 if ( sarea_priv->last_dispatch >= R128_MAX_VB_AGE ) { \
438 int __ret = r128_do_cce_idle( dev_priv ); \
439 if ( __ret ) return __ret; \
440 sarea_priv->last_dispatch = 0; \
441 r128_freelist_reset( dev ); \
442 } \
443} while (0)
444
445#define R128_WAIT_UNTIL_PAGE_FLIPPED() do { \
446 OUT_RING( CCE_PACKET0( R128_WAIT_UNTIL, 0 ) ); \
447 OUT_RING( R128_EVENT_CRTC_OFFSET ); \
448} while (0)
449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450/* ================================================================
451 * Ring control
452 */
453
454#define R128_VERBOSE 0
455
456#define RING_LOCALS \
457 int write, _nr; unsigned int tail_mask; volatile u32 *ring;
458
459#define BEGIN_RING( n ) do { \
460 if ( R128_VERBOSE ) { \
461 DRM_INFO( "BEGIN_RING( %d ) in %s\n", \
462 (n), __FUNCTION__ ); \
463 } \
464 if ( dev_priv->ring.space <= (n) * sizeof(u32) ) { \
465 COMMIT_RING(); \
466 r128_wait_ring( dev_priv, (n) * sizeof(u32) ); \
467 } \
468 _nr = n; dev_priv->ring.space -= (n) * sizeof(u32); \
469 ring = dev_priv->ring.start; \
470 write = dev_priv->ring.tail; \
471 tail_mask = dev_priv->ring.tail_mask; \
472} while (0)
473
474/* You can set this to zero if you want. If the card locks up, you'll
475 * need to keep this set. It works around a bug in early revs of the
476 * Rage 128 chipset, where the CCE would read 32 dwords past the end of
477 * the ring buffer before wrapping around.
478 */
479#define R128_BROKEN_CCE 1
480
481#define ADVANCE_RING() do { \
482 if ( R128_VERBOSE ) { \
483 DRM_INFO( "ADVANCE_RING() wr=0x%06x tail=0x%06x\n", \
484 write, dev_priv->ring.tail ); \
485 } \
486 if ( R128_BROKEN_CCE && write < 32 ) { \
487 memcpy( dev_priv->ring.end, \
488 dev_priv->ring.start, \
489 write * sizeof(u32) ); \
490 } \
491 if (((dev_priv->ring.tail + _nr) & tail_mask) != write) { \
492 DRM_ERROR( \
493 "ADVANCE_RING(): mismatch: nr: %x write: %x line: %d\n", \
494 ((dev_priv->ring.tail + _nr) & tail_mask), \
495 write, __LINE__); \
496 } else \
497 dev_priv->ring.tail = write; \
498} while (0)
499
500#define COMMIT_RING() do { \
501 if ( R128_VERBOSE ) { \
502 DRM_INFO( "COMMIT_RING() tail=0x%06x\n", \
503 dev_priv->ring.tail ); \
504 } \
505 DRM_MEMORYBARRIER(); \
506 R128_WRITE( R128_PM4_BUFFER_DL_WPTR, dev_priv->ring.tail ); \
507 R128_READ( R128_PM4_BUFFER_DL_WPTR ); \
508} while (0)
509
510#define OUT_RING( x ) do { \
511 if ( R128_VERBOSE ) { \
512 DRM_INFO( " OUT_RING( 0x%08x ) at 0x%x\n", \
513 (unsigned int)(x), write ); \
514 } \
515 ring[write++] = cpu_to_le32( x ); \
516 write &= tail_mask; \
517} while (0)
518
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000519#endif /* __R128_DRV_H__ */