4164
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 1 /* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_video.c,v 3.14 2000/10/28 01:42:28 mvojkovi Exp $ */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 2 /* Modified for libdha by Nick Kurshev. */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 3 /*
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 4 * (c) Copyright 1994,1999 by Holger Veit
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 5 * <Holger.Veit@gmd.de>
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 6 * Modified 1996 by Sebastien Marineau <marineau@genie.uottawa.ca>
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 7 *
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 8 * Permission is hereby granted, free of charge, to any person obtaining a
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 9 * copy of this software and associated documentation files (the "Software"),
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 10 * to deal in the Software without restriction, including without limitation
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 12 * and/or sell copies of the Software, and to permit persons to whom the
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 13 * Software is furnished to do so, subject to the following conditions:
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 14 *
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 15 * The above copyright notice and this permission notice shall be included in
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 16 * all copies or substantial portions of the Software.
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 17 *
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 21 * HOLGER VEIT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 24 * SOFTWARE.
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 25 *
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 26 * Except as contained in this notice, the name of Holger Veit shall not be
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 27 * used in advertising or otherwise to promote the sale, use or other dealings
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 28 * in this Software without prior written authorization from Holger Veit.
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 29 *
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 30 */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 31 /* $XConsortium: os2_video.c /main/8 1996/10/27 11:49:02 kaleb $ */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 32
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 33 #define INCL_DOSFILEMGR
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 34 #include "os2.h"
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 35
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 36 /***************************************************************************/
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 37 /* Video Memory Mapping helper functions */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 38 /***************************************************************************/
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 39
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 40 /* This section uses the xf86sup.sys driver developed for xfree86.
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 41 * The driver allows mapping of physical memory
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 42 * You must install it with a line DEVICE=path\xf86sup.sys in config.sys.
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 43 */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 44
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 45 static HFILE mapdev = -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 46 static ULONG stored_virt_addr;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 47 static char* mappath = "\\DEV\\PMAP$";
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 48 static HFILE open_mmap()
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 49 {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 50 APIRET rc;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 51 ULONG action;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 52
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 53 if (mapdev != -1)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 54 return mapdev;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 55
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 56 rc = DosOpen((PSZ)mappath, (PHFILE)&mapdev, (PULONG)&action,
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 57 (ULONG)0, FILE_SYSTEM, FILE_OPEN,
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 58 OPEN_SHARE_DENYNONE|OPEN_FLAGS_NOINHERIT|OPEN_ACCESS_READONLY,
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 59 (ULONG)0);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 60 if (rc!=0)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 61 mapdev = -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 62 return mapdev;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 63 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 64
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 65 static void close_mmap()
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 66 {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 67 if (mapdev != -1)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 68 DosClose(mapdev);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 69 mapdev = -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 70 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 71
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 72 /* this structure is used as a parameter packet for the direct access
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 73 * ioctl of pmap$
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 74 */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 75
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 76 /* Changed here for structure of driver PMAP$ */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 77
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 78 typedef struct{
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 79 ULONG addr;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 80 ULONG size;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 81 } DIOParPkt;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 82
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 83 /* This is the data packet for the mapping function */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 84
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 85 typedef struct {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 86 ULONG addr;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 87 USHORT sel;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 88 } DIODtaPkt;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 89
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 90 /***************************************************************************/
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 91 /* Video Memory Mapping section */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 92 /***************************************************************************/
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 93
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 94 static long callcount = 0L;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 95
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 96 /* ARGSUSED */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 97 void * map_phys_mem(unsigned long base, unsigned long size)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 98 {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 99 DIOParPkt par;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 100 ULONG plen;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 101 DIODtaPkt dta;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 102 ULONG dlen;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 103 static BOOL ErrRedir = FALSE;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 104 APIRET rc;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 105
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 106 par.addr = (ULONG)base;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 107 par.size = (ULONG)size;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 108 plen = sizeof(par);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 109 dlen = sizeof(dta);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 110
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 111 open_mmap();
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 112 if (mapdev == -1)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 113 {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 114 perror("libdha: device xf86sup.sys is not installed");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 115 exit(1);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 116 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 117 if ((rc=DosDevIOCtl(mapdev, (ULONG)0x76, (ULONG)0x44,
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 118 (PVOID)&par, (ULONG)plen, (PULONG)&plen,
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 119 (PVOID)&dta, (ULONG)dlen, (PULONG)&dlen)) == 0) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 120 if (dlen==sizeof(dta)) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 121 callcount++;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 122 return (void *)dta.addr;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 123 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 124 /*else fail*/
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 125 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 126 return (void *)-1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 127 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 128
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 129 /* ARGSUSED */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 130 void unmap_phys_mem(void * base, unsigned long size)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 131 {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 132 DIOParPkt par;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 133 ULONG plen,vmaddr;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 134
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 135 /* We need here the VIRTADDR for unmapping, not the physical address */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 136 /* This should be taken care of either here by keeping track of allocated */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 137 /* pointers, but this is also already done in the driver... Thus it would */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 138 /* be a waste to do this tracking twice. Can this be changed when the fn. */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 139 /* is called? This would require tracking this function in all servers, */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 140 /* and changing it appropriately to call this with the virtual adress */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 141 /* If the above mapping function is only called once, then we can store */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 142 /* the virtual adress and use it here.... */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 143
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 144 par.addr = (ULONG)base;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 145 par.size = 0xffffffff; /* This is the virtual address parameter. Set this to ignore */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 146 plen = sizeof(par);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 147
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 148 if (mapdev != -1)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 149 {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 150 DosDevIOCtl(mapdev, (ULONG)0x76, (ULONG)0x46,
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 151 (PVOID)&par, (ULONG)plen, (PULONG)&plen,
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 152 &vmaddr, sizeof(ULONG), &plen);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 153 callcount--;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 154 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 155 /* Now if more than one region has been allocated and we close the driver,
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 156 * the other pointers will immediately become invalid. We avoid closing
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 157 * driver for now, but this should be fixed for server exit
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 158 */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 159
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 160 if(!callcount) close_mmap();
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 161 }