First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / os-support / solaris / sun_vid.c
blob4f2ab871f2c6e60c63fdd3f23c607c1c786352b3
1 /*
2 * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
3 * Copyright 1993 by David Wexelblat <dwex@goblin.org>
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that copyright
8 * notice and this permission notice appear in supporting documentation, and
9 * that the names of the copyright holders not be used in advertising or
10 * publicity pertaining to distribution of the software without specific,
11 * written prior permission. The copyright holders make no representations
12 * about the suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
17 * SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21 * OF THIS SOFTWARE.
25 #ifdef HAVE_XORG_CONFIG_H
26 #include <xorg-config.h>
27 #endif
29 #include <sys/types.h> /* get __x86 definition if not set by compiler */
31 #if defined(i386) || defined(__x86)
32 #define _NEED_SYSI86
33 #endif
34 #include "xf86.h"
35 #include "xf86Priv.h"
36 #include "xf86_OSlib.h"
38 #ifndef MAP_FAILED
39 #define MAP_FAILED ((void *)-1)
40 #endif
42 /***************************************************************************/
43 /* Video Memory Mapping section */
44 /***************************************************************************/
46 char *apertureDevName = NULL;
48 _X_EXPORT Bool
49 xf86LinearVidMem(void)
51 int mmapFd;
53 if (apertureDevName)
54 return TRUE;
56 apertureDevName = "/dev/xsvc";
57 if ((mmapFd = open(apertureDevName, O_RDWR)) < 0)
59 apertureDevName = "/dev/fbs/aperture";
60 if((mmapFd = open(apertureDevName, O_RDWR)) < 0)
62 xf86MsgVerb(X_WARNING, 0,
63 "xf86LinearVidMem: failed to open %s (%s)\n",
64 apertureDevName, strerror(errno));
65 xf86MsgVerb(X_WARNING, 0,
66 "xf86LinearVidMem: either /dev/fbs/aperture or /dev/xsvc"
67 " device driver required\n");
68 xf86MsgVerb(X_WARNING, 0,
69 "xf86LinearVidMem: linear memory access disabled\n");
70 apertureDevName = NULL;
71 return FALSE;
74 close(mmapFd);
75 return TRUE;
78 _X_EXPORT pointer
79 xf86MapVidMem(int ScreenNum, int Flags, unsigned long Base, unsigned long Size)
81 pointer base;
82 int fd;
83 char vtname[20];
86 * Solaris 2.1 x86 SVR4 (10/27/93)
87 * The server must treat the virtual terminal device file as the
88 * standard SVR4 /dev/pmem.
90 * Using the /dev/vtXX device as /dev/pmem only works for the
91 * A0000-FFFFF region - If we wish you mmap the linear aperture
92 * it requires a device driver.
94 * So what we'll do is use /dev/vtXX for the A0000-FFFFF stuff, and
95 * try to use the /dev/fbs/aperture or /dev/xsvc driver if the server
96 * tries to mmap anything > FFFFF. Its very very unlikely that the
97 * server will try to mmap anything below FFFFF that can't be handled
98 * by /dev/vtXX.
100 * DWH - 2/23/94
101 * DWH - 1/31/99 (Gee has it really been 5 years?)
103 * Solaris 2.8 7/26/99
104 * Use /dev/xsvc for everything
106 * DWH - 7/26/99 - Solaris8/dev/xsvc changes
108 * TSI - 2001.09 - SPARC changes
111 #if defined(i386) && !defined(__SOL8__)
112 if(Base < 0xFFFFF)
113 sprintf(vtname, "/dev/vt%02d", xf86Info.vtno);
114 else
115 #endif
117 if (!xf86LinearVidMem())
118 FatalError("xf86MapVidMem: no aperture device\n");
120 strcpy(vtname, apertureDevName);
123 fd = open(vtname, (Flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
124 if (fd < 0)
125 FatalError("xf86MapVidMem: failed to open %s (%s)\n",
126 vtname, strerror(errno));
128 base = mmap(NULL, Size,
129 (Flags & VIDMEM_READONLY) ?
130 PROT_READ : (PROT_READ | PROT_WRITE),
131 MAP_SHARED, fd, (off_t)Base);
132 close(fd);
133 if (base == MAP_FAILED)
134 FatalError("xf86MapVidMem: mmap failure: %s\n",
135 strerror(errno));
137 return(base);
140 /* ARGSUSED */
141 _X_EXPORT void
142 xf86UnMapVidMem(int ScreenNum, pointer Base, unsigned long Size)
144 munmap(Base, Size);
147 /***************************************************************************/
148 /* I/O Permissions section */
149 /***************************************************************************/
151 #if defined(i386) || defined(__x86)
152 static Bool ExtendedEnabled = FALSE;
153 #endif
155 _X_EXPORT Bool
156 xf86EnableIO(void)
158 #if defined(i386) || defined(__x86)
159 if (ExtendedEnabled)
160 return TRUE;
162 if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0) {
163 xf86Msg(X_WARNING,"xf86EnableIOPorts: Failed to set IOPL for I/O\n");
164 return FALSE;
166 ExtendedEnabled = TRUE;
167 #endif /* i386 */
168 return TRUE;
171 _X_EXPORT void
172 xf86DisableIO(void)
174 #if defined(i386) || defined(__x86)
175 if(!ExtendedEnabled)
176 return;
178 sysi86(SI86V86, V86SC_IOPL, 0);
180 ExtendedEnabled = FALSE;
181 #endif /* i386 */
185 /***************************************************************************/
186 /* Interrupt Handling section */
187 /***************************************************************************/
189 _X_EXPORT Bool xf86DisableInterrupts(void)
191 #if defined(i386) || defined(__x86)
192 if (!ExtendedEnabled && (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0))
193 return FALSE;
195 #ifdef __GNUC__
196 __asm__ __volatile__("cli");
197 #else
198 asm("cli");
199 #endif /* __GNUC__ */
201 if (!ExtendedEnabled)
202 sysi86(SI86V86, V86SC_IOPL, 0);
203 #endif /* i386 */
205 return TRUE;
208 _X_EXPORT void xf86EnableInterrupts(void)
210 #if defined(i386) || defined(__x86)
211 if (!ExtendedEnabled && (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0))
212 return;
214 #ifdef __GNUC__
215 __asm__ __volatile__("sti");
216 #else
217 asm("sti");
218 #endif /* __GNUC__ */
220 if (!ExtendedEnabled)
221 sysi86(SI86V86, V86SC_IOPL, 0);
222 #endif /* i386 */
225 _X_EXPORT void
226 xf86MapReadSideEffects(int ScreenNum, int Flags, pointer Base,
227 unsigned long Size)
231 _X_EXPORT Bool
232 xf86CheckMTRR(int ScreenNum)
234 return FALSE;