summaryrefslogtreecommitdiff
path: root/xc/programs/Xserver/hw/xfree86/os-support/sco/sco_video.c
blob: 88136e2dd00de343120b00411dad26102a24eaa9 (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
252
253
254
255
256
/* $XConsortium$ */
/*
 * Copyright 1993 by David McCullough <davidm@stallion.oz.au>
 * Copyright 1993 by David Wexelblat <dwex@goblin.org>
 *
 * 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 names of David McCullough and David Wexelblat 
 * not be used in advertising or publicity pertaining to distribution of the 
 * software without specific, written prior permission.  David McCullough and
 * David Wexelblat makes no representations about the suitability of this 
 * software for any purpose.  It is provided "as is" without express or 
 * implied warranty.
 *
 * DAVID MCCULLOUGH AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD 
 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
 * AND FITNESS, IN NO EVENT SHALL DAVID MCCULLOUGH OR DAVID WEXELBLAT 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.
 *
 */


#include "X.h"
#include "input.h"
#include "scrnintstr.h"

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

/***************************************************************************/
/* Video Memory Mapping section                                            */
/***************************************************************************/

static struct kd_memloc	MapDSC[MAXSCREENS][NUM_REGIONS];
static int		ver_once = 1;

/***************************************************************************/
/*
 * To map the video-memory, we use the MAP_CLASS ioctl.
 * Different drivers may have to do another one of these
 * for their own special registers (ie., ATI).  To find
 * out which strings are valid look in /etc/conf/pack.d/cn/class.h
 *
 * if we fail to find one of these we try for the dmmap driver
 */

struct {
	unsigned long base, size;
	char *class;
} SCO_Mapping[] = {
	{0xA0000, 0x10000, "SVGA"},
	{0xB0000, 0x08000, "HGA"},
	{0x0,     0x0,     ""},
};

/* ARGSUSED */
pointer xf86MapVidMem(ScreenNum, Region, Base, Size)
int ScreenNum;
int Region;
pointer Base;
unsigned long Size;
{
	int i;
	char *class = (char *)NULL;
	pointer base;

	for (i=0; SCO_Mapping[i].base != 0; i++)
	{
		if (((pointer)SCO_Mapping[i].base == Base) &&
		    (SCO_Mapping[i].size == Size))
		{
			class = SCO_Mapping[i].class;
			break;
		}
	}
	if (class == (char *)NULL)
	{
		int		fd;

		MapDSC[ScreenNum][Region].vaddr    = (char *) NULL;
		MapDSC[ScreenNum][Region].physaddr = (char *) Base;
		MapDSC[ScreenNum][Region].length   = Size;
		MapDSC[ScreenNum][Region].ioflg    = 1;
		if ((fd = open("/dev/dmmap", O_RDWR)) >= 0) {
		    if (ioctl(fd, KDMAPDISP, &MapDSC[ScreenNum][Region]) == -1)
			ErrorF("xf86MapVidMem: dmmap KDMAPDISP failed (%s)\n",
			       strerror(errno));
		    else {
			if (ver_once)
			    ErrorF("Using dmmap version 0x%04x.\n",
				   ioctl(fd, -1));
			ver_once = 0;
			close(fd);
			return(MapDSC[ScreenNum][Region].vaddr);
		    }
		    close(fd);
		}
		FatalError("xf86MapVidMem:No class map defined for (%x,%x)\n",
			   Base, Size);
		/* NOTREACHED */
	}
	base = (pointer)ioctl(xf86Info.consoleFd, MAP_CLASS, class);
	if ((int)base == -1)
	{
		FatalError("xf86MapVidMem:Failed to map video mem class %s\n",
			   class);
		/* NOTREACHED */
	}
	return(base);
}

/*
 * Nothing to do here if it wasn't mapped using the dmmap driver
 */
/* ARGSUSED */
void xf86UnMapVidMem(ScreenNum, Region, Base, Size)
int ScreenNum;
int Region;
pointer Base;
unsigned long Size;
{
	int	fd;

	if (MapDSC[ScreenNum][Region].vaddr) {
	    if ((fd = open("/dev/dmmap", O_RDWR)) < 0) {
		if (ioctl(fd, KDUNMAPDISP, &MapDSC[ScreenNum][Region]) == -1)
		    ErrorF("xf86UnMapVidMem: dmmap KDUNMAPDISP failed (%s)\n",
			   strerror(errno));
		close(fd);
	    }
	    MapDSC[ScreenNum][Region].vaddr    = (char *) NULL;
	    MapDSC[ScreenNum][Region].physaddr = (char *) NULL;
	    MapDSC[ScreenNum][Region].length   = 0;
	    MapDSC[ScreenNum][Region].ioflg    = 0;
	}
	return;
}

/* ARGSUSED */
Bool xf86LinearVidMem()
{
	int		fd, ver;

	if ((fd = open("/dev/dmmap", O_RDWR)) >= 0) {
		ver = ioctl(fd, -1);
		close(fd);
		if (ver >= 0) {
			if (ver_once)
				ErrorF("Using dmmap version 0x%04x.\n", ver);
			ver_once = 0;
			return(TRUE);
		}
	}
	return(FALSE);
}

/***************************************************************************/
/* I/O Permissions section                                                 */
/***************************************************************************/

static Bool ScreenEnabled[MAXSCREENS];
static Bool IOEnabled = FALSE;
static Bool InitDone = FALSE;

void xf86ClearIOPortList(ScreenNum)
int ScreenNum;
{
	int i;

	if (!InitDone)
	{
		for (i = 0; i < MAXSCREENS; i++)
			ScreenEnabled[i] = FALSE;
		InitDone = TRUE;
	}
}

/* ARGSUSED */
void xf86AddIOPorts(ScreenNum, NumPorts, Ports)
int ScreenNum;
int NumPorts;
unsigned *Ports;
{
}

void xf86EnableIOPorts(ScreenNum)
int ScreenNum;
{
	ScreenEnabled[ScreenNum] = TRUE;

	if (IOEnabled)
		return;

	if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0)
		FatalError("Failed to set IOPL for extended I/O\n");
	IOEnabled = TRUE;
	return;
}

void xf86DisableIOPorts(ScreenNum)
int ScreenNum;
{
	int i;

	ScreenEnabled[ScreenNum] = FALSE;

	if (!IOEnabled)
		return;

	for (i = 0; i < MAXSCREENS; i++)
		if (ScreenEnabled[i])
			return;
	sysi86(SI86V86, V86SC_IOPL, 0);
	IOEnabled = FALSE;
	return;
}

void xf86DisableIOPrivs()
{
	if (IOEnabled)
		sysi86(SI86V86, V86SC_IOPL, 0);
	return;
}

/***************************************************************************/
/* Interrupt Handling section                                              */
/***************************************************************************/

Bool xf86DisableInterrupts()
{
#ifdef __GNUC__
	__asm__ __volatile__("cli");
#else 
	asm("cli");
#endif /* __GNUC__ */
	
	return(TRUE);
}

void xf86EnableInterrupts()
{
#ifdef __GNUC__
	__asm__ __volatile__("sti");
#else 
	asm("sti");
#endif /* __GNUC__ */

	return;
}