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