aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/dri/nouveau/nouveau_fifo.c
blob: cc77b577ca43b859a827bf46e2dbc657121bed51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**************************************************************************

Copyright 2006 Stephane Marchesin
All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
on the rights to use, copy, modify, merge, publish, distribute, sub
license, and/or sell copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.

**************************************************************************/


#include "nouveau_fifo.h"
#include "nouveau_lock.h"
#include "vblank.h"

#define RING_SKIPS 8

void WAIT_RING(nouveauContextPtr nmesa,u_int32_t size)
{
	u_int32_t fifo_get;
	while(nmesa->fifo.free < size+1) {
		fifo_get = NV_FIFO_READ(NV03_FIFO_REGS_DMAGET);

		if(nmesa->fifo.put >= fifo_get) {
			nmesa->fifo.free = nmesa->fifo.max - nmesa->fifo.current;
			if(nmesa->fifo.free < size+1) {
				OUT_RING(NV03_FIFO_CMD_REWIND);							\
				if(fifo_get <= RING_SKIPS) {
					if(nmesa->fifo.put <= RING_SKIPS) /* corner case - will be idle */
						NV_FIFO_WRITE(NV03_FIFO_REGS_DMAPUT, RING_SKIPS + 1);
					do { fifo_get = NV_FIFO_READ(NV03_FIFO_REGS_DMAGET); }
					while(fifo_get <= RING_SKIPS);
				}
				NV_FIFO_WRITE(NV03_FIFO_REGS_DMAPUT, RING_SKIPS);
				nmesa->fifo.current = nmesa->fifo.put = RING_SKIPS;
				nmesa->fifo.free = fifo_get - (RING_SKIPS + 1);
			}
		} else 
			nmesa->fifo.free = fifo_get - nmesa->fifo.current - 1;
	}
}

/* 
 * Wait for the card to be idle 
 * XXX we should also wait for an empty fifo
 */
void nouveauWaitForIdleLocked(nouveauContextPtr nmesa)
{
	int i,status;

	for(i=0;i<1000000;i++) /* 1 second */
	{
		switch(nmesa->screen->card_type)
		{
			case NV_03:
				status=NV_READ(NV03_STATUS);
				break;
			case NV_04:
			case NV_05:
			case NV_10:
			case NV_20:
			case NV_30:
			case NV_40:
			case G_70:
			default:
				status=NV_READ(NV04_STATUS);
				break;
		}
		if (status)
			return;
		DO_USLEEP(1);
	}
}

void nouveauWaitForIdle(nouveauContextPtr nmesa)
{
	LOCK_HARDWARE(nmesa);
	nouveauWaitForIdleLocked(nmesa);
	UNLOCK_HARDWARE(nmesa);
}