comparison src/video/Xext/Xxf86dga/XF86DGA.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents ecba4bbaf9c2
children
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
6 6
7 */ 7 */
8 8
9 /* THIS IS NOT AN X CONSORTIUM STANDARD */ 9 /* THIS IS NOT AN X CONSORTIUM STANDARD */
10 10
11 #ifdef __EMX__ /* needed here to override certain constants in X headers */ 11 #ifdef __EMX__ /* needed here to override certain constants in X headers */
12 #define INCL_DOS 12 #define INCL_DOS
13 #define INCL_DOSIOCTL 13 #define INCL_DOSIOCTL
14 #include <os2.h> 14 #include <os2.h>
15 #endif 15 #endif
16 16
17 #if defined(linux) 17 #if defined(linux)
18 #define HAS_MMAP_ANON 18 #define HAS_MMAP_ANON
19 #include <sys/types.h> 19 #include <sys/types.h>
20 #include <sys/mman.h> 20 #include <sys/mman.h>
21 #include <asm/page.h> /* PAGE_SIZE */ 21 #include <asm/page.h> /* PAGE_SIZE */
22 #define HAS_SC_PAGESIZE /* _SC_PAGESIZE may be an enum for Linux */ 22 #define HAS_SC_PAGESIZE /* _SC_PAGESIZE may be an enum for Linux */
23 #define HAS_GETPAGESIZE 23 #define HAS_GETPAGESIZE
24 #endif /* linux */ 24 #endif /* linux */
25 25
26 #if defined(CSRG_BASED) 26 #if defined(CSRG_BASED)
27 #define HAS_MMAP_ANON 27 #define HAS_MMAP_ANON
43 #include <sys/types.h> 43 #include <sys/types.h>
44 #include <sys/mman.h> 44 #include <sys/mman.h>
45 #include <unistd.h> 45 #include <unistd.h>
46 #endif /* SVR4 && !DGUX */ 46 #endif /* SVR4 && !DGUX */
47 47
48 #if defined(sun) && !defined(SVR4) /* SunOS */ 48 #if defined(sun) && !defined(SVR4) /* SunOS */
49 #define MMAP_DEV_ZERO /* doesn't SunOS have MAP_ANON ?? */ 49 #define MMAP_DEV_ZERO /* doesn't SunOS have MAP_ANON ?? */
50 #define HAS_GETPAGESIZE 50 #define HAS_GETPAGESIZE
51 #include <sys/types.h> 51 #include <sys/types.h>
52 #include <sys/mman.h> 52 #include <sys/mman.h>
53 #endif /* sun && !SVR4 */ 53 #endif /* sun && !SVR4 */
54 54
63 #include "../extensions/xf86dga.h" 63 #include "../extensions/xf86dga.h"
64 #include "../extensions/xf86dgastr.h" 64 #include "../extensions/xf86dgastr.h"
65 #include "../extensions/Xext.h" 65 #include "../extensions/Xext.h"
66 #include "../extensions/extutil.h" 66 #include "../extensions/extutil.h"
67 67
68 extern XExtDisplayInfo* SDL_NAME(xdga_find_display)(Display*); 68 extern XExtDisplayInfo *SDL_NAME(xdga_find_display) (Display *);
69 extern char *SDL_NAME(xdga_extension_name); 69 extern char *SDL_NAME(xdga_extension_name);
70 70
71 #define XF86DGACheckExtension(dpy,i,val) \ 71 #define XF86DGACheckExtension(dpy,i,val) \
72 XextCheckExtension (dpy, i, SDL_NAME(xdga_extension_name), val) 72 XextCheckExtension (dpy, i, SDL_NAME(xdga_extension_name), val)
73 73
75 * * 75 * *
76 * public XFree86-DGA Extension routines * 76 * public XFree86-DGA Extension routines *
77 * * 77 * *
78 *****************************************************************************/ 78 *****************************************************************************/
79 79
80 Bool SDL_NAME(XF86DGAQueryExtension) ( 80 Bool SDL_NAME(XF86DGAQueryExtension) (Display * dpy,
81 Display *dpy, 81 int *event_basep, int *error_basep)
82 int *event_basep, 82 {
83 int *error_basep 83 return SDL_NAME(XDGAQueryExtension) (dpy, event_basep, error_basep);
84 ){ 84 }
85 return SDL_NAME(XDGAQueryExtension)(dpy, event_basep, error_basep); 85
86 } 86 Bool SDL_NAME(XF86DGAQueryVersion) (Display * dpy,
87 87 int *majorVersion, int *minorVersion)
88 Bool SDL_NAME(XF86DGAQueryVersion)( 88 {
89 Display* dpy, 89 return SDL_NAME(XDGAQueryVersion) (dpy, majorVersion, minorVersion);
90 int* majorVersion, 90 }
91 int* minorVersion 91
92 ){ 92 Bool SDL_NAME(XF86DGAGetVideoLL) (Display * dpy,
93 return SDL_NAME(XDGAQueryVersion)(dpy, majorVersion, minorVersion); 93 int screen,
94 } 94 int *offset,
95 95 int *width, int *bank_size, int *ram_size)
96 Bool SDL_NAME(XF86DGAGetVideoLL)( 96 {
97 Display* dpy,
98 int screen,
99 int *offset,
100 int *width,
101 int *bank_size,
102 int *ram_size
103 ){
104 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 97 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
105 xXF86DGAGetVideoLLReply rep; 98 xXF86DGAGetVideoLLReply rep;
106 xXF86DGAGetVideoLLReq *req; 99 xXF86DGAGetVideoLLReq *req;
107 100
108 XF86DGACheckExtension (dpy, info, False); 101 XF86DGACheckExtension(dpy, info, False);
109 102
110 LockDisplay(dpy); 103 LockDisplay(dpy);
111 GetReq(XF86DGAGetVideoLL, req); 104 GetReq(XF86DGAGetVideoLL, req);
112 req->reqType = info->codes->major_opcode; 105 req->reqType = info->codes->major_opcode;
113 req->dgaReqType = X_XF86DGAGetVideoLL; 106 req->dgaReqType = X_XF86DGAGetVideoLL;
114 req->screen = screen; 107 req->screen = screen;
115 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 108 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
116 UnlockDisplay(dpy); 109 UnlockDisplay(dpy);
117 SyncHandle(); 110 SyncHandle();
118 return False; 111 return False;
119 } 112 }
120 113
121 *offset = /*(char *)*/rep.offset; 114 *offset = /*(char *) */ rep.offset;
122 *width = rep.width; 115 *width = rep.width;
123 *bank_size = rep.bank_size; 116 *bank_size = rep.bank_size;
124 *ram_size = rep.ram_size; 117 *ram_size = rep.ram_size;
125 118
126 UnlockDisplay(dpy); 119 UnlockDisplay(dpy);
127 SyncHandle(); 120 SyncHandle();
128 return True; 121 return True;
129 } 122 }
130 123
131 124
132 Bool SDL_NAME(XF86DGADirectVideoLL)( 125 Bool SDL_NAME(XF86DGADirectVideoLL) (Display * dpy, int screen, int enable)
133 Display* dpy, 126 {
134 int screen,
135 int enable
136 ){
137 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 127 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
138 xXF86DGADirectVideoReq *req; 128 xXF86DGADirectVideoReq *req;
139 129
140 XF86DGACheckExtension (dpy, info, False); 130 XF86DGACheckExtension(dpy, info, False);
141 131
142 LockDisplay(dpy); 132 LockDisplay(dpy);
143 GetReq(XF86DGADirectVideo, req); 133 GetReq(XF86DGADirectVideo, req);
144 req->reqType = info->codes->major_opcode; 134 req->reqType = info->codes->major_opcode;
145 req->dgaReqType = X_XF86DGADirectVideo; 135 req->dgaReqType = X_XF86DGADirectVideo;
146 req->screen = screen; 136 req->screen = screen;
147 req->enable = enable; 137 req->enable = enable;
148 UnlockDisplay(dpy); 138 UnlockDisplay(dpy);
149 SyncHandle(); 139 SyncHandle();
150 XSync(dpy,False); 140 XSync(dpy, False);
151 return True; 141 return True;
152 } 142 }
153 143
154 Bool SDL_NAME(XF86DGAGetViewPortSize)( 144 Bool SDL_NAME(XF86DGAGetViewPortSize) (Display * dpy,
155 Display* dpy, 145 int screen, int *width, int *height)
156 int screen, 146 {
157 int *width,
158 int *height
159 ){
160 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 147 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
161 xXF86DGAGetViewPortSizeReply rep; 148 xXF86DGAGetViewPortSizeReply rep;
162 xXF86DGAGetViewPortSizeReq *req; 149 xXF86DGAGetViewPortSizeReq *req;
163 150
164 XF86DGACheckExtension (dpy, info, False); 151 XF86DGACheckExtension(dpy, info, False);
165 152
166 LockDisplay(dpy); 153 LockDisplay(dpy);
167 GetReq(XF86DGAGetViewPortSize, req); 154 GetReq(XF86DGAGetViewPortSize, req);
168 req->reqType = info->codes->major_opcode; 155 req->reqType = info->codes->major_opcode;
169 req->dgaReqType = X_XF86DGAGetViewPortSize; 156 req->dgaReqType = X_XF86DGAGetViewPortSize;
170 req->screen = screen; 157 req->screen = screen;
171 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 158 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
172 UnlockDisplay(dpy); 159 UnlockDisplay(dpy);
173 SyncHandle(); 160 SyncHandle();
174 return False; 161 return False;
175 } 162 }
176 163
177 *width = rep.width; 164 *width = rep.width;
178 *height = rep.height; 165 *height = rep.height;
179 166
180 UnlockDisplay(dpy); 167 UnlockDisplay(dpy);
181 SyncHandle(); 168 SyncHandle();
182 return True; 169 return True;
183 } 170 }
184 171
185 172
186 Bool SDL_NAME(XF86DGASetViewPort)( 173 Bool SDL_NAME(XF86DGASetViewPort) (Display * dpy, int screen, int x, int y)
187 Display* dpy, 174 {
188 int screen,
189 int x,
190 int y
191 ){
192 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 175 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
193 xXF86DGASetViewPortReq *req; 176 xXF86DGASetViewPortReq *req;
194 177
195 XF86DGACheckExtension (dpy, info, False); 178 XF86DGACheckExtension(dpy, info, False);
196 179
197 LockDisplay(dpy); 180 LockDisplay(dpy);
198 GetReq(XF86DGASetViewPort, req); 181 GetReq(XF86DGASetViewPort, req);
199 req->reqType = info->codes->major_opcode; 182 req->reqType = info->codes->major_opcode;
200 req->dgaReqType = X_XF86DGASetViewPort; 183 req->dgaReqType = X_XF86DGASetViewPort;
201 req->screen = screen; 184 req->screen = screen;
202 req->x = x; 185 req->x = x;
203 req->y = y; 186 req->y = y;
204 UnlockDisplay(dpy); 187 UnlockDisplay(dpy);
205 SyncHandle(); 188 SyncHandle();
206 XSync(dpy,False); 189 XSync(dpy, False);
207 return True; 190 return True;
208 } 191 }
209 192
210 193
211 Bool SDL_NAME(XF86DGAGetVidPage)( 194 Bool SDL_NAME(XF86DGAGetVidPage) (Display * dpy, int screen, int *vpage)
212 Display* dpy, 195 {
213 int screen,
214 int *vpage
215 ){
216 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 196 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
217 xXF86DGAGetVidPageReply rep; 197 xXF86DGAGetVidPageReply rep;
218 xXF86DGAGetVidPageReq *req; 198 xXF86DGAGetVidPageReq *req;
219 199
220 XF86DGACheckExtension (dpy, info, False); 200 XF86DGACheckExtension(dpy, info, False);
221 201
222 LockDisplay(dpy); 202 LockDisplay(dpy);
223 GetReq(XF86DGAGetVidPage, req); 203 GetReq(XF86DGAGetVidPage, req);
224 req->reqType = info->codes->major_opcode; 204 req->reqType = info->codes->major_opcode;
225 req->dgaReqType = X_XF86DGAGetVidPage; 205 req->dgaReqType = X_XF86DGAGetVidPage;
226 req->screen = screen; 206 req->screen = screen;
227 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 207 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
228 UnlockDisplay(dpy); 208 UnlockDisplay(dpy);
229 SyncHandle(); 209 SyncHandle();
230 return False; 210 return False;
231 } 211 }
232 212
233 *vpage = rep.vpage; 213 *vpage = rep.vpage;
234 UnlockDisplay(dpy); 214 UnlockDisplay(dpy);
235 SyncHandle(); 215 SyncHandle();
236 return True; 216 return True;
237 } 217 }
238 218
239 219
240 Bool SDL_NAME(XF86DGASetVidPage)( 220 Bool SDL_NAME(XF86DGASetVidPage) (Display * dpy, int screen, int vpage)
241 Display* dpy, 221 {
242 int screen,
243 int vpage
244 ){
245 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 222 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
246 xXF86DGASetVidPageReq *req; 223 xXF86DGASetVidPageReq *req;
247 224
248 XF86DGACheckExtension (dpy, info, False); 225 XF86DGACheckExtension(dpy, info, False);
249 226
250 LockDisplay(dpy); 227 LockDisplay(dpy);
251 GetReq(XF86DGASetVidPage, req); 228 GetReq(XF86DGASetVidPage, req);
252 req->reqType = info->codes->major_opcode; 229 req->reqType = info->codes->major_opcode;
253 req->dgaReqType = X_XF86DGASetVidPage; 230 req->dgaReqType = X_XF86DGASetVidPage;
254 req->screen = screen; 231 req->screen = screen;
255 req->vpage = vpage; 232 req->vpage = vpage;
256 UnlockDisplay(dpy); 233 UnlockDisplay(dpy);
257 SyncHandle(); 234 SyncHandle();
258 XSync(dpy,False); 235 XSync(dpy, False);
259 return True; 236 return True;
260 } 237 }
261 238
262 Bool SDL_NAME(XF86DGAInstallColormap)( 239 Bool SDL_NAME(XF86DGAInstallColormap) (Display * dpy,
263 Display* dpy, 240 int screen, Colormap cmap)
264 int screen, 241 {
265 Colormap cmap
266 ){
267 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 242 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
268 xXF86DGAInstallColormapReq *req; 243 xXF86DGAInstallColormapReq *req;
269 244
270 XF86DGACheckExtension (dpy, info, False); 245 XF86DGACheckExtension(dpy, info, False);
271 246
272 LockDisplay(dpy); 247 LockDisplay(dpy);
273 GetReq(XF86DGAInstallColormap, req); 248 GetReq(XF86DGAInstallColormap, req);
274 req->reqType = info->codes->major_opcode; 249 req->reqType = info->codes->major_opcode;
275 req->dgaReqType = X_XF86DGAInstallColormap; 250 req->dgaReqType = X_XF86DGAInstallColormap;
276 req->screen = screen; 251 req->screen = screen;
277 req->id = cmap; 252 req->id = cmap;
278 UnlockDisplay(dpy); 253 UnlockDisplay(dpy);
279 SyncHandle(); 254 SyncHandle();
280 XSync(dpy,False); 255 XSync(dpy, False);
281 return True; 256 return True;
282 } 257 }
283 258
284 Bool SDL_NAME(XF86DGAQueryDirectVideo)( 259 Bool SDL_NAME(XF86DGAQueryDirectVideo) (Display * dpy, int screen, int *flags)
285 Display *dpy, 260 {
286 int screen,
287 int *flags
288 ){
289 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 261 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
290 xXF86DGAQueryDirectVideoReply rep; 262 xXF86DGAQueryDirectVideoReply rep;
291 xXF86DGAQueryDirectVideoReq *req; 263 xXF86DGAQueryDirectVideoReq *req;
292 264
293 XF86DGACheckExtension (dpy, info, False); 265 XF86DGACheckExtension(dpy, info, False);
294 266
295 LockDisplay(dpy); 267 LockDisplay(dpy);
296 GetReq(XF86DGAQueryDirectVideo, req); 268 GetReq(XF86DGAQueryDirectVideo, req);
297 req->reqType = info->codes->major_opcode; 269 req->reqType = info->codes->major_opcode;
298 req->dgaReqType = X_XF86DGAQueryDirectVideo; 270 req->dgaReqType = X_XF86DGAQueryDirectVideo;
299 req->screen = screen; 271 req->screen = screen;
300 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 272 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
301 UnlockDisplay(dpy); 273 UnlockDisplay(dpy);
302 SyncHandle(); 274 SyncHandle();
303 return False; 275 return False;
304 } 276 }
305 *flags = rep.flags; 277 *flags = rep.flags;
306 UnlockDisplay(dpy); 278 UnlockDisplay(dpy);
307 SyncHandle(); 279 SyncHandle();
308 return True; 280 return True;
309 } 281 }
310 282
311 Bool SDL_NAME(XF86DGAViewPortChanged)( 283 Bool SDL_NAME(XF86DGAViewPortChanged) (Display * dpy, int screen, int n)
312 Display *dpy, 284 {
313 int screen,
314 int n
315 ){
316 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 285 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
317 xXF86DGAViewPortChangedReply rep; 286 xXF86DGAViewPortChangedReply rep;
318 xXF86DGAViewPortChangedReq *req; 287 xXF86DGAViewPortChangedReq *req;
319 288
320 XF86DGACheckExtension (dpy, info, False); 289 XF86DGACheckExtension(dpy, info, False);
321 290
322 LockDisplay(dpy); 291 LockDisplay(dpy);
323 GetReq(XF86DGAViewPortChanged, req); 292 GetReq(XF86DGAViewPortChanged, req);
324 req->reqType = info->codes->major_opcode; 293 req->reqType = info->codes->major_opcode;
325 req->dgaReqType = X_XF86DGAViewPortChanged; 294 req->dgaReqType = X_XF86DGAViewPortChanged;
326 req->screen = screen; 295 req->screen = screen;
327 req->n = n; 296 req->n = n;
328 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 297 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
329 UnlockDisplay(dpy); 298 UnlockDisplay(dpy);
330 SyncHandle(); 299 SyncHandle();
331 return False; 300 return False;
332 } 301 }
333 UnlockDisplay(dpy); 302 UnlockDisplay(dpy);
334 SyncHandle(); 303 SyncHandle();
335 return rep.result; 304 return rep.result;
336 } 305 }
342 #include <X11/Xmd.h> 311 #include <X11/Xmd.h>
343 #include "../extensions/xf86dga.h" 312 #include "../extensions/xf86dga.h"
344 #include <stdlib.h> 313 #include <stdlib.h>
345 #include <stdio.h> 314 #include <stdio.h>
346 #include <fcntl.h> 315 #include <fcntl.h>
347 #if defined(ISC) 316 #if defined(ISC)
348 # define HAS_SVR3_MMAP 317 # define HAS_SVR3_MMAP
349 # include <sys/types.h> 318 # include <sys/types.h>
350 # include <errno.h> 319 # include <errno.h>
351 320
352 # include <sys/at_ansi.h> 321 # include <sys/at_ansi.h>
378 #define DEV_MEM "/dev/xsvc" 347 #define DEV_MEM "/dev/xsvc"
379 #else 348 #else
380 #define DEV_MEM "/dev/mem" 349 #define DEV_MEM "/dev/mem"
381 #endif 350 #endif
382 351
383 typedef struct { 352 typedef struct
384 unsigned long physaddr; /* actual requested physical address */ 353 {
385 unsigned long size; /* actual requested map size */ 354 unsigned long physaddr; /* actual requested physical address */
386 unsigned long delta; /* delta to account for page alignment */ 355 unsigned long size; /* actual requested map size */
387 void * vaddr; /* mapped address, without the delta */ 356 unsigned long delta; /* delta to account for page alignment */
388 int refcount; /* reference count */ 357 void *vaddr; /* mapped address, without the delta */
358 int refcount; /* reference count */
389 } MapRec, *MapPtr; 359 } MapRec, *MapPtr;
390 360
391 typedef struct { 361 typedef struct
392 Display * display; 362 {
393 int screen; 363 Display *display;
394 MapPtr map; 364 int screen;
365 MapPtr map;
395 } ScrRec, *ScrPtr; 366 } ScrRec, *ScrPtr;
396 367
397 static int mapFd = -1; 368 static int mapFd = -1;
398 static int numMaps = 0; 369 static int numMaps = 0;
399 static int numScrs = 0; 370 static int numScrs = 0;
406 MapPtr *old; 377 MapPtr *old;
407 378
408 old = mapList; 379 old = mapList;
409 mapList = realloc(mapList, sizeof(MapPtr) * (numMaps + 1)); 380 mapList = realloc(mapList, sizeof(MapPtr) * (numMaps + 1));
410 if (!mapList) { 381 if (!mapList) {
411 mapList = old; 382 mapList = old;
412 return NULL; 383 return NULL;
413 } 384 }
414 mapList[numMaps] = malloc(sizeof(MapRec)); 385 mapList[numMaps] = malloc(sizeof(MapRec));
415 if (!mapList[numMaps]) 386 if (!mapList[numMaps])
416 return NULL; 387 return NULL;
417 return mapList[numMaps++]; 388 return mapList[numMaps++];
418 } 389 }
419 390
420 static ScrPtr 391 static ScrPtr
421 AddScr(void) 392 AddScr(void)
423 ScrPtr *old; 394 ScrPtr *old;
424 395
425 old = scrList; 396 old = scrList;
426 scrList = realloc(scrList, sizeof(ScrPtr) * (numScrs + 1)); 397 scrList = realloc(scrList, sizeof(ScrPtr) * (numScrs + 1));
427 if (!scrList) { 398 if (!scrList) {
428 scrList = old; 399 scrList = old;
429 return NULL; 400 return NULL;
430 } 401 }
431 scrList[numScrs] = malloc(sizeof(ScrRec)); 402 scrList[numScrs] = malloc(sizeof(ScrRec));
432 if (!scrList[numScrs]) 403 if (!scrList[numScrs])
433 return NULL; 404 return NULL;
434 return scrList[numScrs++]; 405 return scrList[numScrs++];
435 } 406 }
436 407
437 static MapPtr 408 static MapPtr
438 FindMap(unsigned long address, unsigned long size) 409 FindMap(unsigned long address, unsigned long size)
439 { 410 {
440 int i; 411 int i;
441 412
442 for (i = 0; i < numMaps; i++) { 413 for (i = 0; i < numMaps; i++) {
443 if (mapList[i]->physaddr == address && 414 if (mapList[i]->physaddr == address && mapList[i]->size == size)
444 mapList[i]->size == size) 415 return mapList[i];
445 return mapList[i];
446 } 416 }
447 return NULL; 417 return NULL;
448 } 418 }
449 419
450 static ScrPtr 420 static ScrPtr
451 FindScr(Display *display, int screen) 421 FindScr(Display * display, int screen)
452 { 422 {
453 int i; 423 int i;
454 424
455 for (i = 0; i < numScrs; i++) { 425 for (i = 0; i < numScrs; i++) {
456 if (scrList[i]->display == display && 426 if (scrList[i]->display == display && scrList[i]->screen == screen)
457 scrList[i]->screen == screen) 427 return scrList[i];
458 return scrList[i];
459 } 428 }
460 return NULL; 429 return NULL;
461 } 430 }
462 431
463 static void * 432 static void *
474 ULONG action; 443 ULONG action;
475 HFILE hfd; 444 HFILE hfd;
476 #endif 445 #endif
477 446
478 if ((mp = FindMap(address, size))) { 447 if ((mp = FindMap(address, size))) {
479 mp->refcount++; 448 mp->refcount++;
480 return (void *)((unsigned long)mp->vaddr + mp->delta); 449 return (void *) ((unsigned long) mp->vaddr + mp->delta);
481 } 450 }
482
483 #if defined(_SC_PAGESIZE) && defined(HAS_SC_PAGESIZE) 451 #if defined(_SC_PAGESIZE) && defined(HAS_SC_PAGESIZE)
484 pagesize = sysconf(_SC_PAGESIZE); 452 pagesize = sysconf(_SC_PAGESIZE);
485 #endif 453 #endif
486 #ifdef _SC_PAGE_SIZE 454 #ifdef _SC_PAGE_SIZE
487 if (pagesize == -1) 455 if (pagesize == -1)
488 pagesize = sysconf(_SC_PAGE_SIZE); 456 pagesize = sysconf(_SC_PAGE_SIZE);
489 #endif 457 #endif
490 #ifdef HAS_GETPAGESIZE 458 #ifdef HAS_GETPAGESIZE
491 if (pagesize == -1) 459 if (pagesize == -1)
492 pagesize = getpagesize(); 460 pagesize = getpagesize();
493 #endif 461 #endif
494 #ifdef PAGE_SIZE 462 #ifdef PAGE_SIZE
495 if (pagesize == -1) 463 if (pagesize == -1)
496 pagesize = PAGE_SIZE; 464 pagesize = PAGE_SIZE;
497 #endif 465 #endif
498 if (pagesize == -1) 466 if (pagesize == -1)
499 pagesize = 4096; 467 pagesize = 4096;
500 468
501 delta = address % pagesize; 469 delta = address % pagesize;
502 offset = address - delta; 470 offset = address - delta;
503 471
504 #if defined(ISC) && defined(HAS_SVR3_MMAP) 472 #if defined(ISC) && defined(HAS_SVR3_MMAP)
505 if (mapFd < 0) { 473 if (mapFd < 0) {
506 if ((mapFd = open("/dev/mmap", O_RDWR)) < 0) 474 if ((mapFd = open("/dev/mmap", O_RDWR)) < 0)
507 return NULL; 475 return NULL;
508 } 476 }
509 mloc.vaddr = (char *)0; 477 mloc.vaddr = (char *) 0;
510 mloc.physaddr = (char *)offset; 478 mloc.physaddr = (char *) offset;
511 mloc.length = size + delta; 479 mloc.length = size + delta;
512 mloc.ioflg=1; 480 mloc.ioflg = 1;
513 481
514 if ((vaddr = (void *)ioctl(mapFd, MAP, &mloc)) == (void *)-1) 482 if ((vaddr = (void *) ioctl(mapFd, MAP, &mloc)) == (void *) -1)
515 return NULL; 483 return NULL;
516 #elif defined (__EMX__) 484 #elif defined (__EMX__)
517 /* 485 /*
518 * Dragon warning here! /dev/pmap$ is never closed, except on progam exit. 486 * Dragon warning here! /dev/pmap$ is never closed, except on progam exit.
519 * Consecutive calling of this routine will make PMAP$ driver run out 487 * Consecutive calling of this routine will make PMAP$ driver run out
520 * of memory handles. Some umap/close mechanism should be provided 488 * of memory handles. Some umap/close mechanism should be provided
521 */ 489 */
522 490
523 rc = DosOpen("/dev/pmap$", &hfd, &action, 0, FILE_NORMAL, FILE_OPEN, 491 rc = DosOpen("/dev/pmap$", &hfd, &action, 0, FILE_NORMAL, FILE_OPEN,
524 OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, (PEAOP2)NULL); 492 OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, (PEAOP2) NULL);
525 if (rc != 0) 493 if (rc != 0)
526 return NULL; 494 return NULL;
527 { 495 {
528 struct map_ioctl { 496 struct map_ioctl
529 union { 497 {
530 ULONG phys; 498 union
531 void* user; 499 {
532 } a; 500 ULONG phys;
533 ULONG size; 501 void *user;
534 } pmap,dmap; 502 } a;
535 ULONG plen,dlen; 503 ULONG size;
504 } pmap, dmap;
505 ULONG plen, dlen;
536 #define XFREE86_PMAP 0x76 506 #define XFREE86_PMAP 0x76
537 #define PMAP_MAP 0x44 507 #define PMAP_MAP 0x44
538 508
539 pmap.a.phys = offset; 509 pmap.a.phys = offset;
540 pmap.size = size + delta; 510 pmap.size = size + delta;
541 rc = DosDevIOCtl(hfd, XFREE86_PMAP, PMAP_MAP, 511 rc = DosDevIOCtl(hfd, XFREE86_PMAP, PMAP_MAP,
542 (PULONG)&pmap, sizeof(pmap), &plen, 512 (PULONG) & pmap, sizeof(pmap), &plen,
543 (PULONG)&dmap, sizeof(dmap), &dlen); 513 (PULONG) & dmap, sizeof(dmap), &dlen);
544 if (rc == 0) { 514 if (rc == 0) {
545 vaddr = dmap.a.user; 515 vaddr = dmap.a.user;
546 } 516 }
547 } 517 }
548 if (rc != 0) 518 if (rc != 0)
549 return NULL; 519 return NULL;
550 #elif defined (Lynx) 520 #elif defined (Lynx)
551 vaddr = (void *)smem_create("XF86DGA", (char *)offset, 521 vaddr = (void *) smem_create("XF86DGA", (char *) offset,
552 size + delta, SM_READ|SM_WRITE); 522 size + delta, SM_READ | SM_WRITE);
553 #else 523 #else
554 #ifndef MAP_FILE 524 #ifndef MAP_FILE
555 #define MAP_FILE 0 525 #define MAP_FILE 0
556 #endif 526 #endif
557 if (mapFd < 0) { 527 if (mapFd < 0) {
558 if ((mapFd = open(DEV_MEM, O_RDWR)) < 0) 528 if ((mapFd = open(DEV_MEM, O_RDWR)) < 0)
559 return NULL; 529 return NULL;
560 } 530 }
561 vaddr = (void *)mmap(NULL, size + delta, PROT_READ | PROT_WRITE, 531 vaddr = (void *) mmap(NULL, size + delta, PROT_READ | PROT_WRITE,
562 MAP_FILE | MAP_SHARED, mapFd, (off_t)offset); 532 MAP_FILE | MAP_SHARED, mapFd, (off_t) offset);
563 if (vaddr == (void *)-1) 533 if (vaddr == (void *) -1)
564 return NULL; 534 return NULL;
565 #endif 535 #endif
566 536
567 if (!vaddr) { 537 if (!vaddr) {
568 if (!(mp = AddMap())) 538 if (!(mp = AddMap()))
569 return NULL; 539 return NULL;
570 mp->physaddr = address; 540 mp->physaddr = address;
571 mp->size = size; 541 mp->size = size;
572 mp->delta = delta; 542 mp->delta = delta;
573 mp->vaddr = vaddr; 543 mp->vaddr = vaddr;
574 mp->refcount = 1; 544 mp->refcount = 1;
575 } 545 }
576 return (void *)((unsigned long)vaddr + delta); 546 return (void *) ((unsigned long) vaddr + delta);
577 } 547 }
578 548
579 /* 549 /*
580 * Still need to find a clean way of detecting the death of a DGA app 550 * Still need to find a clean way of detecting the death of a DGA app
581 * and returning things to normal - Jon 551 * and returning things to normal - Jon
582 * This is here to help debugging without rebooting... Also C-A-BS 552 * This is here to help debugging without rebooting... Also C-A-BS
583 * should restore text mode. 553 * should restore text mode.
584 */ 554 */
585 555
586 int 556 int SDL_NAME(XF86DGAForkApp) (int screen)
587 SDL_NAME(XF86DGAForkApp)(int screen)
588 { 557 {
589 pid_t pid; 558 pid_t pid;
590 int status; 559 int status;
591 int i; 560 int i;
592 561
593 /* fork the app, parent hangs around to clean up */ 562 /* fork the app, parent hangs around to clean up */
594 if ((pid = fork()) > 0) { 563 if ((pid = fork()) > 0) {
595 ScrPtr sp; 564 ScrPtr sp;
596 565
597 waitpid(pid, &status, 0); 566 waitpid(pid, &status, 0);
598 for (i = 0; i < numScrs; i++) { 567 for (i = 0; i < numScrs; i++) {
599 sp = scrList[i]; 568 sp = scrList[i];
600 SDL_NAME(XF86DGADirectVideoLL)(sp->display, sp->screen, 0); 569 SDL_NAME(XF86DGADirectVideoLL) (sp->display, sp->screen, 0);
601 XSync(sp->display, False); 570 XSync(sp->display, False);
602 } 571 }
603 if (WIFEXITED(status)) 572 if (WIFEXITED(status))
604 _exit(0); 573 _exit(0);
605 else 574 else
606 _exit(-1); 575 _exit(-1);
607 } 576 }
608 return pid; 577 return pid;
609 } 578 }
610 579
611 580
612 Bool 581 Bool SDL_NAME(XF86DGADirectVideo) (Display * dis, int screen, int enable)
613 SDL_NAME(XF86DGADirectVideo)( 582 {
614 Display *dis,
615 int screen,
616 int enable
617 ){
618 ScrPtr sp; 583 ScrPtr sp;
619 MapPtr mp = NULL; 584 MapPtr mp = NULL;
620 585
621 if ((sp = FindScr(dis, screen))) 586 if ((sp = FindScr(dis, screen)))
622 mp = sp->map; 587 mp = sp->map;
623 588
624 if (enable & XF86DGADirectGraphics) { 589 if (enable & XF86DGADirectGraphics) {
625 #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \ 590 #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \
626 && !defined(__EMX__) 591 && !defined(__EMX__)
627 if (mp && mp->vaddr) 592 if (mp && mp->vaddr)
628 mprotect(mp->vaddr, mp->size + mp->delta, PROT_READ | PROT_WRITE); 593 mprotect(mp->vaddr, mp->size + mp->delta, PROT_READ | PROT_WRITE);
629 #endif 594 #endif
630 } else { 595 } else {
631 #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \ 596 #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \
632 && !defined(__EMX__) 597 && !defined(__EMX__)
633 if (mp && mp->vaddr) 598 if (mp && mp->vaddr)
634 mprotect(mp->vaddr, mp->size + mp->delta, PROT_READ); 599 mprotect(mp->vaddr, mp->size + mp->delta, PROT_READ);
635 #elif defined(Lynx) 600 #elif defined(Lynx)
636 /* XXX this doesn't allow enable after disable */ 601 /* XXX this doesn't allow enable after disable */
637 smem_create(NULL, mp->vaddr, mp->size + mp->delta, SM_DETACH); 602 smem_create(NULL, mp->vaddr, mp->size + mp->delta, SM_DETACH);
638 smem_remove("XF86DGA"); 603 smem_remove("XF86DGA");
639 #endif 604 #endif
640 } 605 }
641 606
642 SDL_NAME(XF86DGADirectVideoLL)(dis, screen, enable); 607 SDL_NAME(XF86DGADirectVideoLL) (dis, screen, enable);
643 return 1; 608 return 1;
644 } 609 }
645 610
646 611
647 static void 612 static void
650 ScrPtr sp; 615 ScrPtr sp;
651 int i; 616 int i;
652 static char beenhere = 0; 617 static char beenhere = 0;
653 618
654 if (beenhere) 619 if (beenhere)
655 _exit(3); 620 _exit(3);
656 beenhere = 1; 621 beenhere = 1;
657 622
658 for (i = 0; i < numScrs; i++) { 623 for (i = 0; i < numScrs; i++) {
659 sp = scrList[i]; 624 sp = scrList[i];
660 SDL_NAME(XF86DGADirectVideo)(sp->display, sp->screen, 0); 625 SDL_NAME(XF86DGADirectVideo) (sp->display, sp->screen, 0);
661 XSync(sp->display, False); 626 XSync(sp->display, False);
662 } 627 }
663 _exit(3); 628 _exit(3);
664 } 629 }
665 630
666 Bool 631 Bool
667 SDL_NAME(XF86DGAGetVideo)( 632 SDL_NAME(XF86DGAGetVideo) (Display * dis,
668 Display *dis, 633 int screen,
669 int screen, 634 char **addr, int *width, int *bank, int *ram)
670 char **addr, 635 {
671 int *width, 636 /*unsigned long */ int offset;
672 int *bank,
673 int *ram
674 ){
675 /*unsigned long*/ int offset;
676 static int beenHere = 0; 637 static int beenHere = 0;
677 ScrPtr sp; 638 ScrPtr sp;
678 MapPtr mp; 639 MapPtr mp;
679 640
680 if (!(sp = FindScr(dis, screen))) { 641 if (!(sp = FindScr(dis, screen))) {
681 if (!(sp = AddScr())) { 642 if (!(sp = AddScr())) {
682 fprintf(stderr, "XF86DGAGetVideo: malloc failure\n"); 643 fprintf(stderr, "XF86DGAGetVideo: malloc failure\n");
683 exit(-2); 644 exit(-2);
684 } 645 }
685 sp->display = dis; 646 sp->display = dis;
686 sp->screen = screen; 647 sp->screen = screen;
687 sp->map = NULL; 648 sp->map = NULL;
688 } 649 }
689 650
690 SDL_NAME(XF86DGAGetVideoLL)(dis, screen , &offset, width, bank, ram); 651 SDL_NAME(XF86DGAGetVideoLL) (dis, screen, &offset, width, bank, ram);
691 652
692 *addr = MapPhysAddress(offset, *bank); 653 *addr = MapPhysAddress(offset, *bank);
693 if (*addr == NULL) { 654 if (*addr == NULL) {
694 fprintf(stderr, "XF86DGAGetVideo: failed to map video memory (%s)\n", 655 fprintf(stderr,
695 strerror(errno)); 656 "XF86DGAGetVideo: failed to map video memory (%s)\n",
696 exit(-2); 657 strerror(errno));
658 exit(-2);
697 } 659 }
698 660
699 if ((mp = FindMap(offset, *bank))) 661 if ((mp = FindMap(offset, *bank)))
700 sp->map = mp; 662 sp->map = mp;
701 663
702 if (!beenHere) { 664 if (!beenHere) {
703 beenHere = 1; 665 beenHere = 1;
704 atexit((void(*)(void))XF86cleanup); 666 atexit((void (*)(void)) XF86cleanup);
705 /* one shot XF86cleanup attempts */ 667 /* one shot XF86cleanup attempts */
706 signal(SIGSEGV, XF86cleanup); 668 signal(SIGSEGV, XF86cleanup);
707 #ifdef SIGBUS 669 #ifdef SIGBUS
708 signal(SIGBUS, XF86cleanup); 670 signal(SIGBUS, XF86cleanup);
709 #endif 671 #endif
710 signal(SIGHUP, XF86cleanup); 672 signal(SIGHUP, XF86cleanup);
711 signal(SIGFPE, XF86cleanup); 673 signal(SIGFPE, XF86cleanup);
712 } 674 }
713 675
714 return 1; 676 return 1;
715 } 677 }
716 678
679 /* vi: set ts=4 sw=4 expandtab: */