Print the version string after the command line has been parsed.
[mplayer/glamo.git] / vidix / dha.c
blob8a2d8fd1cdd199ec0521b9eaeee86311a44264d4
1 /*
2 * VIDIX Direct Hardware Access (DHA).
3 * Copyright (C) 2002 Nick Kurshev
5 * 1996/10/27 - Robin Cutshaw (robin@xfree86.org)
6 * XFree86 3.3.3 implementation
7 * 1999 - Øyvind Aabling.
8 * Modified for GATOS/win/gfxdump.
10 * 2002 - library implementation by Nick Kurshev
11 * - dhahelper and some changes by Alex Beregszaszi
13 * supported OSes: SVR4, UnixWare, SCO, Solaris,
14 * FreeBSD, NetBSD, 386BSD, BSDI BSD/386,
15 * Linux, Mach/386, ISC
16 * DOS (WATCOM 9.5 compiler), Win9x (with mapdev.vxd)
17 * original location: www.linuxvideo.org/gatos
19 * This file is part of MPlayer.
21 * MPlayer is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 2 of the License, or
24 * (at your option) any later version.
26 * MPlayer is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License along
32 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
33 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
36 #include "config.h"
38 #include "dha.h"
39 #include "AsmMacros.h"
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include <fcntl.h>
44 #include <sys/stat.h>
45 #include <sys/types.h>
46 #if ARCH_ALPHA
47 #include <sys/io.h>
48 #endif
49 #include <unistd.h>
51 #if defined(__MINGW32__) || defined(__CYGWIN__)
52 #include "sysdep/libdha_win32.c"
53 #elif defined (__EMX__)
54 #include "sysdep/libdha_os2.c"
55 #else
57 #if defined(SVR4) || defined(SCO325)
58 # if !(defined(sun) && defined (i386) && defined (SVR4))
59 # define DEV_MEM "/dev/pmem"
60 # elif defined(PowerMAX_OS)
61 # define DEV_MEM "/dev/iomem"
62 # endif
63 # ifdef SCO325
64 # undef DEV_MEM
65 # define DEV_MEM "/dev/mem"
66 # endif
67 #elif defined(sun) && defined (i386)
68 #define DEV_MEM "/dev/xsvc"
69 # endif /* SVR4 */
71 #if defined(__OpenBSD__)
72 #define DEV_APERTURE "/dev/xf86"
73 #endif
75 /* Generic version */
76 #include <sys/mman.h>
78 #ifndef DEV_MEM
79 #define DEV_MEM "/dev/mem"
80 #endif
82 #ifdef CONFIG_DHAHELPER
83 #include "dhahelper/dhahelper.h"
84 #endif
86 #ifdef CONFIG_SVGAHELPER
87 #include <svgalib_helper.h>
88 #endif
90 static int mem_fd = -1;
92 void *map_phys_mem(unsigned long base, unsigned long size)
94 #if ARCH_ALPHA
95 /* TODO: move it into sysdep */
96 base += bus_base();
97 #endif
99 #ifdef CONFIG_SVGAHELPER
100 if ( (mem_fd = open(DEV_SVGA,O_RDWR)) == -1) {
101 perror("libdha: SVGAlib kernelhelper failed");
102 #ifdef CONFIG_DHAHELPER
103 goto dha_helper_way;
104 #else
105 goto dev_mem_way;
106 #endif
108 else
109 goto mmap;
110 #endif
112 #ifdef CONFIG_DHAHELPER
113 #ifdef CONFIG_SVGAHELPER
114 dha_helper_way:
115 #endif
116 if ( (mem_fd = open("/dev/dhahelper",O_RDWR)) < 0)
118 perror("libdha: DHA kernelhelper failed");
119 goto dev_mem_way;
121 else
123 dhahelper_memory_t mem_req;
125 mem_req.operation = MEMORY_OP_MAP;
126 mem_req.start = base;
127 mem_req.offset = 0;
128 mem_req.size = size;
130 if (ioctl(mem_fd, DHAHELPER_MEMORY, &mem_req) < 0)
132 perror("libdha: DHA kernelhelper failed");
133 close(mem_fd);
134 goto dev_mem_way;
136 else
137 goto mmap;
139 #endif
141 #if defined(CONFIG_DHAHELPER) || defined (CONFIG_SVGAHELPER)
142 dev_mem_way:
143 #endif
144 #ifdef DEV_APERTURE
145 if ((mem_fd = open(DEV_APERTURE, O_RDWR)) == -1)
146 perror("libdha: opening aperture failed");
147 else {
148 void *p = mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem_fd,base);
150 if (p == MAP_FAILED) {
151 perror("libdha: mapping aperture failed");
152 close(mem_fd);
153 } else
154 return p;
156 #endif
158 if ( (mem_fd = open(DEV_MEM,O_RDWR)) == -1)
160 perror("libdha: opening /dev/mem failed");
161 return MAP_FAILED;
164 #if defined(CONFIG_DHAHELPER) || defined (CONFIG_SVGAHELPER)
165 mmap:
166 #endif
167 return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem_fd,base);
170 void unmap_phys_mem(void *ptr, unsigned long size)
172 int res = munmap(ptr,size);
174 if (res == (int)MAP_FAILED)
176 perror("libdha: unmapping memory failed");
177 return;
180 close(mem_fd);
181 mem_fd = -1;
183 return;
186 #endif /* Generic mmap (not win32, nor os2) */
188 #if !defined(__alpha__) && !defined(__powerpc__) && !defined(__sh__)
189 unsigned char INPORT8(unsigned idx)
191 return inb(idx);
194 unsigned short INPORT16(unsigned idx)
196 return inw(idx);
199 unsigned INPORT32(unsigned idx)
201 return inl(idx);
204 void OUTPORT8(unsigned idx,unsigned char val)
206 outb(idx,val);
209 void OUTPORT16(unsigned idx,unsigned short val)
211 outw(idx,val);
214 void OUTPORT32(unsigned idx,unsigned val)
216 outl(idx,val);
218 #endif