First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / os-support / bsd / ppc_video.c
blob06be654e1f007308077a008a88070647dfbcb7df
1 /*
2 * Copyright 1992 by Rich Murphey <Rich@Rice.edu>
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
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the names of Rich Murphey and David Wexelblat
10 * not be used in advertising or publicity pertaining to distribution of
11 * the software without specific, written prior permission. Rich Murphey and
12 * David Wexelblat make no representations about the suitability of this
13 * software for any purpose. It is provided "as is" without express or
14 * implied warranty.
16 * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO
17 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR
19 * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
21 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26 #ifdef HAVE_XORG_CONFIG_H
27 #include <xorg-config.h>
28 #endif
30 #include <X11/X.h>
31 #include "xf86.h"
32 #include "xf86Priv.h"
34 #include "xf86_OSlib.h"
35 #include "xf86OSpriv.h"
37 #include "bus/Pci.h"
39 #ifndef MAP_FAILED
40 #define MAP_FAILED ((caddr_t)-1)
41 #endif
44 /***************************************************************************/
45 /* Video Memory Mapping section */
46 /***************************************************************************/
48 #ifndef __OpenBSD__
49 #define DEV_MEM "/dev/mem"
50 #else
51 #define DEV_MEM "/dev/xf86"
52 #endif
54 static pointer ppcMapVidMem(int, unsigned long, unsigned long, int flags);
55 static void ppcUnmapVidMem(int, pointer, unsigned long);
57 Bool xf86EnableIO(void);
58 void xf86DisableIO(void);
60 void
61 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
63 pVidMem->linearSupported = TRUE;
64 pVidMem->mapMem = ppcMapVidMem;
65 pVidMem->unmapMem = ppcUnmapVidMem;
66 pVidMem->initialised = TRUE;
67 xf86EnableIO();
71 _X_EXPORT volatile unsigned char *ioBase = MAP_FAILED;
73 static pointer
74 ppcMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
76 int fd = xf86Info.screenFd;
77 pointer base;
78 #ifdef DEBUG
79 xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d",
80 Base, Size, fd);
81 #endif
83 base = mmap(0, Size,
84 (flags & VIDMEM_READONLY) ?
85 PROT_READ : (PROT_READ | PROT_WRITE),
86 MAP_SHARED, fd, Base);
87 if (base == MAP_FAILED)
88 FatalError("%s: could not mmap screen [s=%x,a=%x] (%s)",
89 "xf86MapVidMem", Size, Base, strerror(errno));
91 return base;
94 static void
95 ppcUnmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
97 munmap(Base, Size);
100 _X_EXPORT int
101 xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
102 int Len)
104 int rv;
105 static int kmem = -1;
107 if (kmem == -1) {
108 kmem = open(DEV_MEM, 2);
109 if (kmem == -1) {
110 FatalError("xf86ReadBIOS: open %s", DEV_MEM);
114 #ifdef DEBUG
115 xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS() %lx %lx, %x\n",
116 Base, Offset, Len);
117 #endif
120 lseek(kmem, Base + Offset, 0);
121 rv = read(kmem, Buf, Len);
123 return rv;
126 /***************************************************************************/
127 /* Interrupt Handling section */
128 /***************************************************************************/
130 _X_EXPORT Bool
131 xf86DisableInterrupts()
134 return(TRUE);
137 _X_EXPORT void
138 xf86EnableInterrupts()
141 return;
144 Bool xf86EnableIO()
146 int fd = xf86Info.screenFd;
148 xf86MsgVerb(X_WARNING, 3, "xf86EnableIO %d\n", fd);
149 if (ioBase == MAP_FAILED)
151 ioBase=mmap(NULL, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, fd,
152 0xf2000000);
153 xf86MsgVerb(X_INFO, 3, "xf86EnableIO: %08x\n", ioBase);
154 if (ioBase == MAP_FAILED) {
155 xf86MsgVerb(X_WARNING, 3, "Can't map IO space!\n");
156 return FALSE;
159 return TRUE;
162 void xf86DisableIO()
165 if (ioBase != MAP_FAILED)
167 munmap(__UNVOLATILE(ioBase), 0x10000);
168 ioBase = MAP_FAILED;