annotate vidix/sysdep/libdha_os2.c @ 28615:15e7abed4291

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