Commit | Line | Data |
---|---|---|
a09e091a JB |
1 | /* |
2 | * Copyright 1992 by Rich Murphey <Rich@Rice.edu> | |
3 | * Copyright 1993 by David Wexelblat <dwex@goblin.org> | |
4 | * | |
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. | |
15 | * | |
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. | |
23 | * | |
24 | */ | |
25 | ||
26 | #ifdef HAVE_XORG_CONFIG_H | |
27 | #include <xorg-config.h> | |
28 | #endif | |
29 | ||
30 | #include <X11/X.h> | |
31 | #include "xf86.h" | |
32 | #include "xf86Priv.h" | |
33 | ||
34 | #include "xf86_OSlib.h" | |
35 | #include "xf86OSpriv.h" | |
36 | ||
37 | #include "bus/Pci.h" | |
38 | ||
39 | /***************************************************************************/ | |
40 | /* Video Memory Mapping section */ | |
41 | /***************************************************************************/ | |
42 | ||
43 | #ifdef __OpenBSD__ | |
44 | #define DEV_MEM "/dev/xf86" | |
45 | #endif | |
46 | ||
47 | static pointer ppcMapVidMem(int, unsigned long, unsigned long, int flags); | |
48 | static void ppcUnmapVidMem(int, pointer, unsigned long); | |
49 | ||
50 | Bool xf86EnableIO(void); | |
51 | void xf86DisableIO(void); | |
52 | ||
53 | void | |
54 | xf86OSInitVidMem(VidMemInfoPtr pVidMem) | |
55 | { | |
56 | pVidMem->linearSupported = TRUE; | |
57 | pVidMem->mapMem = ppcMapVidMem; | |
58 | pVidMem->unmapMem = ppcUnmapVidMem; | |
59 | pVidMem->initialised = TRUE; | |
60 | xf86EnableIO(); | |
61 | } | |
62 | ||
63 | volatile unsigned char *ioBase = MAP_FAILED; | |
64 | ||
65 | static pointer | |
66 | ppcMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) | |
67 | { | |
68 | int fd = xf86Info.consoleFd; | |
69 | pointer base; | |
70 | ||
71 | #ifdef DEBUG | |
72 | xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d", Base, Size, fd); | |
73 | #endif | |
74 | ||
75 | base = mmap(0, Size, | |
76 | (flags & VIDMEM_READONLY) ? | |
77 | PROT_READ : (PROT_READ | PROT_WRITE), MAP_SHARED, fd, Base); | |
78 | if (base == MAP_FAILED) | |
79 | FatalError("%s: could not mmap screen [s=%x,a=%x] (%s)", | |
80 | "xf86MapVidMem", Size, Base, strerror(errno)); | |
81 | ||
82 | return base; | |
83 | } | |
84 | ||
85 | static void | |
86 | ppcUnmapVidMem(int ScreenNum, pointer Base, unsigned long Size) | |
87 | { | |
88 | munmap(Base, Size); | |
89 | } | |
90 | ||
91 | int | |
92 | xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, | |
93 | int Len) | |
94 | { | |
95 | int rv; | |
96 | static int kmem = -1; | |
97 | ||
98 | if (kmem == -1) { | |
99 | kmem = open(DEV_MEM, 2); | |
100 | if (kmem == -1) { | |
101 | FatalError("xf86ReadBIOS: open %s", DEV_MEM); | |
102 | } | |
103 | } | |
104 | ||
105 | #ifdef DEBUG | |
106 | xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS() %lx %lx, %x\n", Base, Offset, Len); | |
107 | #endif | |
108 | ||
109 | lseek(kmem, Base + Offset, 0); | |
110 | rv = read(kmem, Buf, Len); | |
111 | ||
112 | return rv; | |
113 | } | |
114 | ||
115 | Bool | |
116 | xf86EnableIO() | |
117 | { | |
118 | int fd = xf86Info.consoleFd; | |
119 | ||
120 | xf86MsgVerb(X_WARNING, 3, "xf86EnableIO %d\n", fd); | |
121 | if (ioBase == MAP_FAILED) { | |
122 | ioBase = mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, | |
123 | 0xf2000000); | |
124 | xf86MsgVerb(X_INFO, 3, "xf86EnableIO: %08x\n", ioBase); | |
125 | if (ioBase == MAP_FAILED) { | |
126 | xf86MsgVerb(X_WARNING, 3, "Can't map IO space!\n"); | |
127 | return FALSE; | |
128 | } | |
129 | } | |
130 | return TRUE; | |
131 | } | |
132 | ||
133 | void | |
134 | xf86DisableIO() | |
135 | { | |
136 | ||
137 | if (ioBase != MAP_FAILED) { | |
138 | munmap(__UNVOLATILE(ioBase), 0x10000); | |
139 | ioBase = MAP_FAILED; | |
140 | } | |
141 | } |