2 libgha.c - Library for direct hardware access
4 1996/10/27 - Robin Cutshaw (robin@xfree86.org)
5 XFree86 3.3.3 implementation
6 1999 - Øyvind Aabling.
7 Modified for GATOS/win/gfxdump.
9 2002 - library implementation by Nick Kurshev
10 - dhahelper and some changes by Alex Beregszaszi
12 supported O/S's: SVR4, UnixWare, SCO, Solaris,
13 FreeBSD, NetBSD, 386BSD, BSDI BSD/386,
15 DOS (WATCOM 9.5 compiler), Win9x (with mapdev.vxd)
17 Original location: www.linuxvideo.org/gatos
23 #include "AsmMacros.h"
29 #include <sys/types.h>
36 #include "sysdep/libdha_win32.c"
37 #elif defined (__EMX__)
38 #include "sysdep/libdha_os2.c"
41 #if defined(SVR4) || defined(SCO325)
42 # if !(defined(sun) && defined (i386) && defined (SVR4))
43 # define DEV_MEM "/dev/pmem"
44 # elif defined(PowerMAX_OS)
45 # define DEV_MEM "/dev/iomem"
49 # define DEV_MEM "/dev/mem"
53 #if defined(__OpenBSD__)
54 #define DEV_APERTURE "/dev/xf86"
61 #define DEV_MEM "/dev/mem"
64 #ifdef CONFIG_DHAHELPER
65 #include "kernelhelper/dhahelper.h"
68 #ifdef CONFIG_SVGAHELPER
69 #include <svgalib_helper.h>
72 static int mem_fd
= -1;
74 void *map_phys_mem(unsigned long base
, unsigned long size
)
77 /* TODO: move it into sysdep */
81 #ifdef CONFIG_SVGAHELPER
82 if ( (mem_fd
= open(DEV_SVGA
,O_RDWR
)) == -1) {
83 perror("libdha: SVGAlib kernelhelper failed");
84 #ifdef CONFIG_DHAHELPER
94 #ifdef CONFIG_DHAHELPER
95 #ifdef CONFIG_SVGAHELPER
98 if ( (mem_fd
= open("/dev/dhahelper",O_RDWR
)) < 0)
100 perror("libdha: DHA kernelhelper failed");
105 dhahelper_memory_t mem_req
;
107 mem_req
.operation
= MEMORY_OP_MAP
;
108 mem_req
.start
= base
;
112 if (ioctl(mem_fd
, DHAHELPER_MEMORY
, &mem_req
) < 0)
114 perror("libdha: DHA kernelhelper failed");
125 if ((mem_fd
= open(DEV_APERTURE
, O_RDWR
)) == -1)
126 perror("libdha: opening aperture failed");
128 void *p
= mmap(0,size
,PROT_READ
|PROT_WRITE
,MAP_SHARED
,mem_fd
,base
);
130 if (p
== MAP_FAILED
) {
131 perror("libdha: mapping aperture failed");
138 if ( (mem_fd
= open(DEV_MEM
,O_RDWR
)) == -1)
140 perror("libdha: opening /dev/mem failed");
145 return mmap(0,size
,PROT_READ
|PROT_WRITE
,MAP_SHARED
,mem_fd
,base
);
148 void unmap_phys_mem(void *ptr
, unsigned long size
)
150 int res
= munmap(ptr
,size
);
152 if (res
== (int)MAP_FAILED
)
154 perror("libdha: unmapping memory failed");
164 #endif /* Generic mmap (not win32, nor os2) */
166 unsigned char INPORT8(unsigned idx
)
171 unsigned short INPORT16(unsigned idx
)
176 unsigned INPORT32(unsigned idx
)
181 void OUTPORT8(unsigned idx
,unsigned char val
)
186 void OUTPORT16(unsigned idx
,unsigned short val
)
191 void OUTPORT32(unsigned idx
,unsigned val
)