aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/programs/Xserver/hw/xfree86/os-support/pmax/pmax_ppc.c
blob: aa286d4ac2391f6d987590049b340b3a3d18cb95 (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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/pmax/pmax_ppc.c,v 1.3 1998/07/25 16:56:56 dawes Exp $ */
/*
 * Copyright 1998 by Concurrent Computer Corporation
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and that
 * both that copyright notice and this permission notice appear in
 * supporting documentation, and that the name of Concurrent Computer
 * Corporation not be used in advertising or publicity pertaining to
 * distribution of the software without specific, written prior
 * permission.  Concurrent Computer Corporation makes no representations
 * about the suitability of this software for any purpose.  It is
 * provided "as is" without express or implied warranty.
 *
 * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE
 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 *
 * Copyright 1998 by Metro Link Incorporated
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and that
 * both that copyright notice and this permission notice appear in
 * supporting documentation, and that the name of Metro Link
 * Incorporated not be used in advertising or publicity pertaining to
 * distribution of the software without specific, written prior
 * permission.  Metro Link Incorporated makes no representations
 * about the suitability of this software for any purpose.  It is
 * provided "as is" without express or implied warranty.
 *
 * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */

#ifdef HAVE_XORG_CONFIG_H
#include <xorg-config.h>
#endif

#include <sys/types.h>
#include <errno.h>

#include <sys/prosrfs.h>
#include <sys/cpu.h>

#include "compiler.h"

#include "xf86.h"
#include "xf86Priv.h"
#include "xf86_OSlib.h"

volatile unsigned char *ioBase = MAP_FAILED;  /* Also referenced by compiler.h */
unsigned long ioSize = 0;

#undef outb
#undef outw
#undef outl
#undef inb
#undef inw
#undef inl

void
outb(unsigned int a, unsigned char b)
{
	if (ioBase == MAP_FAILED) {
		ErrorF("outb(0x%04X, 0x%02X) fails.  Uninitialized ioBase\n", a, b);
		return;
	}
	
	*((volatile unsigned char *)(ioBase + a)) = b; eieio();
}	

void
outw(unsigned int a, unsigned short w) 
{
	if (ioBase == MAP_FAILED) {
		ErrorF("outw(0x%04X, 0x%04X) fails.  Unitialized ioBase\n", a, w);
		return;
	}
	
	stw_brx(w,ioBase,a); eieio();
}

void
outl(unsigned int a, unsigned int l) 
{
	if (ioBase == MAP_FAILED) {
		ErrorF("outl(0x%04X, 0x%08X) fails.  Unitialized ioBase\n", a, l);
		return;
	}
	
	stl_brx(l,ioBase,a); eieio();
}

unsigned char
inb(unsigned int a) 
{
	unsigned char b;

	if (ioBase == MAP_FAILED) {
		FatalError("%s(0x%04X) fails.  Unitialized ioBase\n", "inb", a);
		/*NOTREACHED*/
	}
	
	b = *((volatile unsigned char *)(ioBase + a));
	
	return(b);
}

unsigned short
inw(unsigned int a) 
{
	unsigned short w;

	if (ioBase == MAP_FAILED) {
		FatalError("%s(0x%04X) fails.  Unitialized ioBase\n", "inw", a);
		/*NOTREACHED*/
	}
	
	w = ldw_brx(ioBase,a);
	return(w);
}

unsigned int
inl(unsigned int a) 
{
	unsigned int l;
	
	if (ioBase == MAP_FAILED) {
		FatalError("%s(0x%04X) fails.  Unitialized ioBase\n", "inl", a);
		/*NOTREACHED*/
	}
	
	l = ldl_brx(ioBase, a);
	return(l);
}

#ifdef PPCIO_DEBUG

void
debug_outb(unsigned int a, unsigned char b, int line, char *file)
{
	if (xf86Verbose > 3)
		ErrorF("outb(0x%04X, 0x%02X) at line %d, file \"%s\"\n", a, b, line, file);
	
	outb(a,b);
}	

void
debug_outw(unsigned int a, unsigned short w, int line, char *file) 
{
	if (xf86Verbose > 3)
		ErrorF("outw(0x%04X, 0x%04X) at line %d, file \"%s\"\n", a, w, line, file);
	
	outw(a,w);
}

void
debug_outl(unsigned int a, unsigned int l, int line, char *file)
{
	if (xf86Verbose > 3)
		ErrorF("outl(0x%04X, 0x%08X) at line %d, file \"%s\"\n", a, l, line, file);

	outl(a,l);
}


unsigned char
debug_inb(unsigned int a, int line, char *file)
{
	unsigned char b;
	
	if (xf86Verbose > 4)
		ErrorF("Calling %s(0x%04x) at line %d, file \"%s\" ...\n", "inb", a, line, file);

	b = inb(a);
	
	if (xf86Verbose > 3)
		ErrorF("... %s(0x%04X) returns 0x%02X\n", "inb", a, b);

	return(b);
}

unsigned short
debug_inw(unsigned int a, int line, char *file) 
{
	unsigned short w;
	
	if (xf86Verbose > 4)
		ErrorF("Calling %s(0x%04x) at line %d, file \"%s\" ...\n", "inw", a, line, file);

	w = inw(a);
	
	if (xf86Verbose > 3)
		ErrorF("... %s(0x%04X) returns 0x%04X\n", "inw", a, w);

	return(w);
}

unsigned int
debug_inl(unsigned int a, int line, char *file) 
{
	unsigned int l;
	
	if (xf86Verbose > 4)
		ErrorF("Calling %s(0x%04x) at line %d, file \"%s\" ...\n", "inl", a, line, file);

	l = inl(a);
	
	if (xf86Verbose > 3)
		ErrorF("... %s(0x%04X) returns 0x%08X\n", "inl", a, l);
	
	return(l);
}

#endif /* PPCIO_DEBUG */

/*
 * This is neccessary on the PPC 604 (and 604e) because they have
 * separate I and D caches and the caches must be manually synchronized
 * when applying relocation to the instruction portion of loaded modules.
 */
#define LINESIZE        32
#define CACHE_LINE(a)   (((unsigned long)a) & ~(LINESIZE-1))

void
ppc_flush_icache(char *addr)
{
	/* Flush D-cache to memory */
	__inst_dcbf (addr, 0);
	__inst_dcbf (addr, LINESIZE);
	__inst_sync ();
	
	/* Invalidate I-cache */
	__inst_icbi (addr, 0);
	__inst_icbi (addr, LINESIZE);
	__inst_sync ();
	__inst_isync ();
}