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