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