1/**************************************************************************
2
3Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
4Copyright © 2002 David Dawes
5
6All Rights Reserved.
7
8Permission is hereby granted, free of charge, to any person obtaining a
9copy of this software and associated documentation files (the
10"Software"), to deal in the Software without restriction, including
11without limitation the rights to use, copy, modify, merge, publish,
12distribute, sub license, and/or sell copies of the Software, and to
13permit persons to whom the Software is furnished to do so, subject to
14the following conditions:
15
16The above copyright notice and this permission notice (including the
17next paragraph) shall be included in all copies or substantial portions
18of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
24ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28**************************************************************************/
29
30#ifndef _INTEL_RING_H
31#define _INTEL_RING_H
32
33#define OUT_RING(n) do {						\
34    if (I810_DEBUG & DEBUG_VERBOSE_RING)				\
35	ErrorF("OUT_RING %lx: %x, (mask %x)\n",				\
36	       (unsigned long)(outring), (unsigned int)(n), ringmask);	\
37    *(volatile unsigned int *)(virt + outring) = n;			\
38    outring += 4; ringused += 4;					\
39    outring &= ringmask;						\
40} while (0)
41
42#define ADVANCE_LP_RING() do {						\
43    if (ringused > needed)						\
44	FatalError("%s: ADVANCE_LP_RING: exceeded allocation %d/%d\n ",	\
45		   __FUNCTION__, ringused, needed);   			\
46    else if (ringused < needed)						\
47	FatalError("%s: ADVANCE_LP_RING: under-used allocation %d/%d\n ", \
48		   __FUNCTION__, ringused, needed);   			\
49    pI810->LpRing->tail = outring;					\
50    pI810->LpRing->space -= ringused;					\
51    if (outring & 0x07)							\
52	FatalError("%s: ADVANCE_LP_RING: "				\
53		   "outring (0x%x) isn't on a QWord boundary\n",	\
54		   __FUNCTION__, outring);				\
55    OUTREG(LP_RING + RING_TAIL, outring);				\
56} while (0)
57
58/*
59 * XXX Note: the head/tail masks are different for 810 and i830.
60 * If the i810 always sets the higher bits to 0, then this shouldn't be
61 * a problem.  Check this!
62 */
63#define DO_RING_IDLE() do {						\
64    int _head;								\
65    int _tail;								\
66    do {								\
67	_head = INREG(LP_RING + RING_HEAD) & I830_HEAD_MASK;		\
68	_tail = INREG(LP_RING + RING_TAIL) & I830_TAIL_MASK;		\
69	DELAY(10);							\
70    } while (_head != _tail);						\
71} while( 0)
72
73#define BEGIN_LP_RING(n)						\
74    unsigned int outring, ringmask, ringused = 0;			\
75    volatile unsigned char *virt;					\
76    int needed;								\
77    if ((n) & 1)							\
78	ErrorF("BEGIN_LP_RING called with odd argument: %d\n", n);	\
79    if ((n) > 2 && (I810_DEBUG&DEBUG_ALWAYS_SYNC))			\
80	DO_RING_IDLE();							\
81    needed = (n) * 4;							\
82    if (pI810->LpRing->space < needed)					\
83	WaitRingFunc(pScrn, needed, 0);					\
84    outring = pI810->LpRing->tail;					\
85    ringmask = pI810->LpRing->tail_mask;				\
86    virt = pI810->LpRing->virtual_start;				\
87    if (I810_DEBUG & DEBUG_VERBOSE_RING)				\
88	ErrorF( "BEGIN_LP_RING %d in %s\n", n, FUNCTION_NAME);
89
90#endif /* _INTEL_RING_H */
91