rtsp_rtp.c: Add missing avstring include for av_strlcpy
[mplayer.git] / vidix / sysdep / libdha_os2.c
blobf9d166716bb9de37b496ea0490aa74961c265f5a
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>
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
24 * SOFTWARE.
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
34 #include "os2.h"
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)
50 APIRET rc;
51 ULONG action;
53 if (mapdev != -1)
54 return mapdev;
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;
65 static void close_mmap(void)
67 if (mapdev != -1)
68 DosClose(mapdev);
69 mapdev = -1;
72 /* this structure is used as a parameter packet for the direct access
73 * ioctl of pmap$
76 /* Changed here for structure of driver PMAP$ */
78 typedef struct{
79 ULONG addr;
80 ULONG size;
81 } DIOParPkt;
83 /* This is the data packet for the mapping function */
85 typedef struct {
86 ULONG addr;
87 USHORT sel;
88 } DIODtaPkt;
90 /***************************************************************************/
91 /* Video Memory Mapping section */
92 /***************************************************************************/
94 static long callcount = 0L;
96 /* ARGSUSED */
97 void * map_phys_mem(unsigned long base, unsigned long size)
99 DIOParPkt par;
100 ULONG plen;
101 DIODtaPkt dta;
102 ULONG dlen;
103 static BOOL ErrRedir = FALSE;
104 APIRET rc;
106 par.addr = (ULONG)base;
107 par.size = (ULONG)size;
108 plen = sizeof(par);
109 dlen = sizeof(dta);
111 open_mmap();
112 if (mapdev == -1)
114 perror("libdha: device xf86sup.sys is not installed");
115 exit(1);
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;
124 /*else fail*/
126 return (void *)-1;
129 /* ARGSUSED */
130 void unmap_phys_mem(void * base, unsigned long size)
132 DIOParPkt par;
133 ULONG plen,vmaddr;
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 */
146 plen = sizeof(par);
148 if (mapdev != -1)
150 DosDevIOCtl(mapdev, (ULONG)0x76, (ULONG)0x46,
151 (PVOID)&par, (ULONG)plen, (PULONG)&plen,
152 &vmaddr, sizeof(ULONG), &plen);
153 callcount--;
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();