summaryrefslogtreecommitdiff
path: root/xc/lib/GL/mesa/src/drv/i810/i810ring.c
blob: 2e5909e9f9f05391d5b1d92e7b2003215d8e7275 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/mman.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>

#include "mm.h"
#include "i810dd.h"
#include "i810lib.h"
#include "i810state.h"


#include "i810dma.h"

static void 
I810PrintErrorState( void )
{
   fprintf(stderr,  "pgetbl_ctl: 0x%x pgetbl_err: 0x%x\n", 
	   INREG(PGETBL_CTL),
	   INREG(PGE_ERR));

   fprintf(stderr,  "ipeir: %x iphdr: %x\n", 
	   INREG(IPEIR),
	   INREG(IPEHR));

   fprintf(stderr,  "LP ring tail: %x head: %x len: %x start %x\n",
	   INREG(LP_RING + RING_TAIL),
	   INREG(LP_RING + RING_HEAD) & HEAD_ADDR,
	   INREG(LP_RING + RING_LEN),
	   INREG(LP_RING + RING_START));

   fprintf(stderr,  "eir: %x esr: %x emr: %x\n",
	   INREG16(EIR),
	   INREG16(ESR),
	   INREG16(EMR));

   fprintf(stderr,  "instdone: %x instpm: %x\n",
	   INREG16(INST_DONE),
	   INREG8(INST_PM));

   fprintf(stderr,  "memmode: %x instps: %x\n",
	   INREG(MEMMODE),
	   INREG(INST_PS));

   fprintf(stderr,  "hwstam: %x ier: %x imr: %x iir: %x\n",
	   INREG16(HWSTAM),
	   INREG16(IER),
	   INREG16(IMR),
	   INREG16(IIR));
}




static int
I810USec( void ) 
{
   struct timeval tv;
   struct timezone tz;	
   gettimeofday( &tv, &tz );
   return (tv.tv_sec & 2047) * 1000000 + tv.tv_usec;
}



void
_I810RefreshLpRing( i810ContextPtr imesa, int update )
{
	struct i810_ring_buffer *ring = &(i810glx.LpRing);
	
	ring->head = INREG(LP_RING + RING_HEAD) & HEAD_ADDR;
	ring->tail = INREG(LP_RING + RING_TAIL);
	ring->space = ring->head - (ring->tail+8);

	if (ring->space < 0) {
		ring->space += ring->mem.Size;
		if (update)
			imesa->sarea->lastWrap = ++imesa->sarea->ringAge;
	}
}	

int
_I810WaitLpRing( i810ContextPtr imesa, int n, int timeout_usec )
{
	struct i810_ring_buffer *ring = &(i810glx.LpRing);
	int iters = 0;
	int startTime = 0;
	int curTime = 0;
   
	if (timeout_usec == 0)
		timeout_usec = 15000000;

	if (I810_DEBUG & DEBUG_VERBOSE_API)
		fprintf(stderr, "I810WaitLpRing %d\n", n);

	while (ring->space < n) 
	{
		int i;

		ring->head = INREG(LP_RING + RING_HEAD) & HEAD_ADDR;
		ring->space = ring->head - (ring->tail+8);

		if (ring->space < 0) {
			imesa->sarea->lastWrap = ++imesa->sarea->ringAge;
			ring->space += ring->mem.Size;
		}
      
		iters++;
		curTime = I810USec();
		if ( startTime == 0 || curTime < startTime /*wrap case*/) {
			startTime = curTime;
		} else if ( curTime - startTime > timeout_usec ) { 
			I810PrintErrorState();
			fprintf(stderr, "space: %d wanted %d\n", 
				ring->space, n );
			UNLOCK_HARDWARE(imesa);
			exit(1);
		}

		for (i = 0 ; i < 2000 ; i++)
			;
	}

	return iters;
}

int
_I810Sync( i810ContextPtr imesa ) 
{
	int rv;

	if (I810_DEBUG & DEBUG_VERBOSE_API)
		fprintf(stderr, "I810Sync\n");
   
	/* Send a flush instruction and then wait till the ring is empty.
	 * This is stronger than waiting for the blitter to finish as it also
	 * flushes the internal graphics caches.
	 */
	{
		BEGIN_LP_RING( imesa, 2 );   
		OUT_RING( INST_PARSER_CLIENT | INST_OP_FLUSH );
		OUT_RING( 0 );		/* pad to quadword */
		ADVANCE_LP_RING();
	}


	i810glx.LpRing.synced = 1;	/* ?? */

	rv =  _I810WaitLpRing( imesa, i810glx.LpRing.mem.Size - 8, 0 );	
	imesa->sarea->lastSync = ++imesa->sarea->ringAge;

	return rv;
}