1/*
2 * Acceleration for the Creator and Creator3D framebuffer - fifo macros.
3 *
4 * Copyright (C) 1998,1999 Jakub Jelinek (jakub@redhat.com)
5 * Copyright (C) 1999 David S. Miller (davem@redhat.com)
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20 * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 * IN THE SOFTWARE.
24 */
25
26#ifndef FFBFIFO_H
27#define FFBFIFO_H
28
29#include "ffb.h"
30
31/* This is the smallest FFB fifo size I know of. -DaveM */
32#define FFB_FIFO_MIN	124
33
34#define FFBFifo(__fpriv, __n) \
35do { 	int __cur_slots = (__fpriv)->fifo_cache; \
36	if((__cur_slots - (__n)) < 0) { \
37		ffb_fbcPtr __ffb = pFfb->regs; \
38		do {	__cur_slots = (((int)__ffb->ucsr & FFB_UCSR_FIFO_MASK) - 4); \
39		} while((__cur_slots - (__n)) < 0); \
40	} (__fpriv)->fifo_cache = (__cur_slots - (__n)); \
41} while(0)
42
43/* While we are polling for the raster processor to idle, cache the
44 * fifo count as well.
45 */
46#define FFBWait(__fpriv, __ffb) \
47if ((__fpriv)->rp_active != 0) { \
48	unsigned int __regval = (__ffb)->ucsr; \
49	while((__regval & FFB_UCSR_RP_BUSY) != 0) { \
50		__regval = (__ffb)->ucsr; \
51	} \
52	(__fpriv)->fifo_cache = ((int)(__regval & FFB_UCSR_FIFO_MASK)) - 4; \
53	(__fpriv)->rp_active = 0; \
54} while(0)
55
56/* DEBUGGING:  You can use this if you suspect corruption is occurring
57 *             because someone is touching the framebuffer while the
58 *	       raster processor is active.  If you enable this and the
59 *	       problem goes away, odds are your suspicions are correct.
60 */
61#undef FORCE_WAIT_EVERY_ROP
62#ifdef FORCE_WAIT_EVERY_ROP
63#define FFBSync(__fpriv, __ffb)	FFBWait(__fpriv, __ffb)
64#else
65#define FFBSync(__fpriv, __ffb)	do { } while(0)
66#endif
67
68#endif /* FFBFIFO_H */
69