Punctuation. ;)
[mplayer/glamo.git] / libdha / libdha.c
blobfa8efe75eee036e704e23a54a40e68af4e8d2a5e
1 /*
2 libgha.c - Library for direct hardware access
3 Copyrights:
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,
14 Linux, Mach/386, ISC
15 DOS (WATCOM 9.5 compiler), Win9x (with mapdev.vxd)
16 Licence: GPL
17 Original location: www.linuxvideo.org/gatos
20 #include "config.h"
22 #include "libdha.h"
23 #include "AsmMacros.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <fcntl.h>
28 #include <sys/stat.h>
29 #include <sys/types.h>
30 #ifdef ARCH_ALPHA
31 #include <sys/io.h>
32 #endif
33 #include <unistd.h>
35 #if defined(_WIN32)
36 #include "sysdep/libdha_win32.c"
37 #elif defined (__EMX__)
38 #include "sysdep/libdha_os2.c"
39 #else
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"
46 # endif
47 # ifdef SCO325
48 # undef DEV_MEM
49 # define DEV_MEM "/dev/mem"
50 # endif
51 # endif /* SVR4 */
53 /* Generic version */
54 #include <sys/mman.h>
56 #ifndef DEV_MEM
57 #define DEV_MEM "/dev/mem"
58 #endif
60 #ifdef CONFIG_DHAHELPER
61 #include "kernelhelper/dhahelper.h"
62 #endif
64 #ifdef CONFIG_SVGAHELPER
65 #include <svgalib_helper.h>
66 #endif
68 static int mem_fd = -1;
70 void *map_phys_mem(unsigned long base, unsigned long size)
72 #ifdef ARCH_ALPHA
73 /* TODO: move it into sysdep */
74 base += bus_base();
75 #endif
77 #ifdef CONFIG_SVGAHELPER
78 if ( (mem_fd = open(DEV_SVGA,O_RDWR)) == -1) {
79 perror("libdha: SVGAlib kernelhelper failed");
80 #ifdef CONFIG_DHAHELPER
81 goto dha_helper_way;
82 #else
83 goto dev_mem_way;
84 #endif
86 else
87 goto mmap;
88 #endif
90 #ifdef CONFIG_DHAHELPER
91 #ifdef CONFIG_SVGAHELPER
92 dha_helper_way:
93 #endif
94 if ( (mem_fd = open("/dev/dhahelper",O_RDWR)) < 0)
96 perror("libdha: DHA kernelhelper failed");
97 goto dev_mem_way;
99 else
101 dhahelper_memory_t mem_req;
103 mem_req.operation = MEMORY_OP_MAP;
104 mem_req.start = base;
105 mem_req.offset = 0;
106 mem_req.size = size;
108 if (ioctl(mem_fd, DHAHELPER_MEMORY, &mem_req) < 0)
110 perror("libdha: DHA kernelhelper failed");
111 close(mem_fd);
112 goto dev_mem_way;
114 else
115 goto mmap;
117 #endif
119 dev_mem_way:
120 if ( (mem_fd = open(DEV_MEM,O_RDWR)) == -1)
122 perror("libdha: opening /dev/mem failed");
123 return MAP_FAILED;
126 mmap:
127 return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem_fd,base);
130 void unmap_phys_mem(void *ptr, unsigned long size)
132 int res = munmap(ptr,size);
134 if (res == (int)MAP_FAILED)
136 perror("libdha: unmapping memory failed");
137 return;
140 close(mem_fd);
141 mem_fd = -1;
143 return;
146 #endif /* Generic mmap (not win32, nor os2) */
148 unsigned char INPORT8(unsigned idx)
150 return inb(idx);
153 unsigned short INPORT16(unsigned idx)
155 return inw(idx);
158 unsigned INPORT32(unsigned idx)
160 return inl(idx);
163 void OUTPORT8(unsigned idx,unsigned char val)
165 outb(idx,val);
168 void OUTPORT16(unsigned idx,unsigned short val)
170 outw(idx,val);
173 void OUTPORT32(unsigned idx,unsigned val)
175 outl(idx,val);