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. */
4 * (c) Copyright 1994,1999 by Holger Veit
6 * Modified 1996 by Sebastien Marineau <marineau@genie.uottawa.ca>
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
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
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.
31 /* $XConsortium: os2_video.c /main/8 1996/10/27 11:49:02 kaleb $ */
33 #define INCL_DOSFILEMGR
36 /***************************************************************************/
37 /* Video Memory Mapping helper functions */
38 /***************************************************************************/
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.
45 static HFILE mapdev
= -1;
46 static ULONG stored_virt_addr
;
47 static char* mappath
= "\\DEV\\PMAP$";
48 static HFILE
open_mmap(void)
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
,
65 static void close_mmap(void)
72 /* this structure is used as a parameter packet for the direct access
76 /* Changed here for structure of driver PMAP$ */
83 /* This is the data packet for the mapping function */
90 /***************************************************************************/
91 /* Video Memory Mapping section */
92 /***************************************************************************/
94 static long callcount
= 0L;
97 void * map_phys_mem(unsigned long base
, unsigned long size
)
103 static BOOL ErrRedir
= FALSE
;
106 par
.addr
= (ULONG
)base
;
107 par
.size
= (ULONG
)size
;
114 perror("libdha: device xf86sup.sys is not installed");
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
)) {
122 return (void *)dta
.addr
;
130 void unmap_phys_mem(void * base
, unsigned long size
)
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.... */
144 par
.addr
= (ULONG
)base
;
145 par
.size
= 0xffffffff; /* This is the virtual address parameter. Set this to ignore */
150 DosDevIOCtl(mapdev
, (ULONG
)0x76, (ULONG
)0x46,
151 (PVOID
)&par
, (ULONG
)plen
, (PULONG
)&plen
,
152 &vmaddr
, sizeof(ULONG
), &plen
);
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
160 if(!callcount
) close_mmap();