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.
39 #include "AsmMacros.h"
45 #include <sys/types.h>
51 #if defined(__MINGW32__) || defined(__CYGWIN__)
52 #include "sysdep/libdha_win32.c"
53 #elif defined (__EMX__)
54 #include "sysdep/libdha_os2.c"
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"
65 # define DEV_MEM "/dev/mem"
67 #elif defined(sun) && defined (i386)
68 #define DEV_MEM "/dev/xsvc"
71 #if defined(__OpenBSD__)
72 #define DEV_APERTURE "/dev/xf86"
79 #define DEV_MEM "/dev/mem"
82 #ifdef CONFIG_DHAHELPER
83 #include "dhahelper/dhahelper.h"
86 #ifdef CONFIG_SVGAHELPER
87 #include <svgalib_helper.h>
90 static int mem_fd
= -1;
92 void *map_phys_mem(unsigned long base
, unsigned long size
)
95 /* TODO: move it into sysdep */
99 #ifdef CONFIG_SVGAHELPER
100 if ( (mem_fd
= open(DEV_SVGA
,O_RDWR
)) == -1) {
101 perror("libdha: SVGAlib kernelhelper failed");
102 #ifdef CONFIG_DHAHELPER
112 #ifdef CONFIG_DHAHELPER
113 #ifdef CONFIG_SVGAHELPER
116 if ( (mem_fd
= open("/dev/dhahelper",O_RDWR
)) < 0)
118 perror("libdha: DHA kernelhelper failed");
123 dhahelper_memory_t mem_req
;
125 mem_req
.operation
= MEMORY_OP_MAP
;
126 mem_req
.start
= base
;
130 if (ioctl(mem_fd
, DHAHELPER_MEMORY
, &mem_req
) < 0)
132 perror("libdha: DHA kernelhelper failed");
141 #if defined(CONFIG_DHAHELPER) || defined (CONFIG_SVGAHELPER)
145 if ((mem_fd
= open(DEV_APERTURE
, O_RDWR
)) == -1)
146 perror("libdha: opening aperture failed");
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");
158 if ( (mem_fd
= open(DEV_MEM
,O_RDWR
)) == -1)
160 perror("libdha: opening /dev/mem failed");
164 #if defined(CONFIG_DHAHELPER) || defined (CONFIG_SVGAHELPER)
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");
186 #endif /* Generic mmap (not win32, nor os2) */
188 #if !defined(__alpha__) && !defined(__powerpc__) && !defined(__sh__)
189 unsigned char INPORT8(unsigned idx
)
194 unsigned short INPORT16(unsigned idx
)
199 unsigned INPORT32(unsigned idx
)
204 void OUTPORT8(unsigned idx
,unsigned char val
)
209 void OUTPORT16(unsigned idx
,unsigned short val
)
214 void OUTPORT32(unsigned idx
,unsigned val
)