Mercurial > mplayer.hg
annotate libdha/libdha.c @ 5767:97de70b5377f
added pegasus codecs
author | alex |
---|---|
date | Sun, 21 Apr 2002 16:10:50 +0000 |
parents | 567de708ab3a |
children | 9dbb9c710480 |
rev | line source |
---|---|
3973 | 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. | |
8 | |
9 2002 - library implementation by Nick Kurshev | |
4474 | 10 - dhahelper and some changes by Alex Beregszaszi |
3973 | 11 |
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 | |
18 */ | |
19 | |
4474 | 20 #include "config.h" |
21 | |
3973 | 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> | |
5702 | 30 #ifdef ARCH_ALPHA |
31 #include <sys/io.h> | |
32 #endif | |
3973 | 33 #include <unistd.h> |
34 | |
4174
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4164
diff
changeset
|
35 /* instead exit() use libdha_exit, and do the 'mother-application' deinit |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4164
diff
changeset
|
36 only in this code */ |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4164
diff
changeset
|
37 void libdha_exit(const char *message, int level) |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4164
diff
changeset
|
38 { |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4164
diff
changeset
|
39 printf("libdha: FATAL: %s\n", message); |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4164
diff
changeset
|
40 exit(level); /* FIXME */ |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4164
diff
changeset
|
41 } |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4164
diff
changeset
|
42 |
4164 | 43 #if defined(_WIN32) |
44 #include "sysdep/libdha_win32.c" | |
45 #elif defined (__EMX__) | |
46 #include "sysdep/libdha_os2.c" | |
47 #else | |
3973 | 48 |
4164 | 49 #if defined(SVR4) || defined(SCO325) |
50 # if !(defined(sun) && defined (i386) && defined (SVR4)) | |
51 # define DEV_MEM "/dev/pmem" | |
52 # elif defined(PowerMAX_OS) | |
53 # define DEV_MEM "/dev/iomem" | |
54 # endif | |
55 # ifdef SCO325 | |
56 # undef DEV_MEM | |
57 # define DEV_MEM "/dev/mem" | |
58 # endif | |
59 # endif /* SVR4 */ | |
3973 | 60 |
4164 | 61 /* Generic version */ |
62 #include <sys/mman.h> | |
3973 | 63 |
4164 | 64 #ifndef DEV_MEM |
65 #define DEV_MEM "/dev/mem" | |
66 #endif | |
3973 | 67 |
4474 | 68 #ifdef CONFIG_DHAHELPER |
4938 | 69 |
70 #include "kernelhelper/dhahelper.h" | |
71 | |
3973 | 72 static int mem=-1; |
5702 | 73 void *map_phys_mem(unsigned long base, unsigned long size) |
3973 | 74 { |
5702 | 75 #ifdef ARCH_ALPHA |
76 /* TODO: move it into sysdep */ | |
77 base += bus_base(); | |
78 #endif | |
4474 | 79 if ( (mem = open("/dev/dhahelper",O_RDWR)) < 0) |
80 { | |
81 if ( (mem = open(DEV_MEM,O_RDWR)) == -1) { | |
82 perror("libdha: open(/dev/mem) failed") ; exit(1) ; | |
83 } | |
84 } | |
85 else | |
86 { | |
87 dhahelper_memory_t mem_req; | |
88 | |
89 mem_req.operation = MEMORY_OP_MAP; | |
90 mem_req.start = base; | |
91 mem_req.offset = 0; | |
92 mem_req.size = size; | |
93 | |
94 if (ioctl(mem, DHAHELPER_MEMORY, &mem_req) < 0) | |
95 { | |
96 perror("libdha: failed mapping throught kernel helper"); | |
97 return NULL; | |
98 } | |
99 } | |
100 return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem,base) ; | |
101 } | |
102 #else | |
103 | |
104 static int mem=-1; | |
5702 | 105 void *map_phys_mem(unsigned long base, unsigned long size) |
4474 | 106 { |
5702 | 107 #ifdef ARCH_ALPHA |
108 /* TODO: move it into sysdep */ | |
109 base += bus_base(); | |
110 #endif | |
4164 | 111 if ( (mem = open(DEV_MEM,O_RDWR)) == -1) { |
3973 | 112 perror("libdha: open(/dev/mem) failed") ; exit(1) ; |
113 } | |
4164 | 114 return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem,base) ; |
3973 | 115 } |
4474 | 116 #endif /* CONFIG_DHAHELPER */ |
3973 | 117 |
5702 | 118 void unmap_phys_mem(void *ptr, unsigned long size) |
3973 | 119 { |
120 int res=munmap(ptr,size) ; | |
121 if (res == -1) { perror("libdha: munmap() failed") ; exit(1) ; } | |
122 close(mem); | |
123 } | |
124 #endif | |
125 | |
3995 | 126 unsigned char INPORT8(unsigned idx) |
3973 | 127 { |
128 return inb(idx); | |
129 } | |
130 | |
3995 | 131 unsigned short INPORT16(unsigned idx) |
3973 | 132 { |
133 return inw(idx); | |
134 } | |
135 | |
3995 | 136 unsigned INPORT32(unsigned idx) |
3973 | 137 { |
138 return inl(idx); | |
139 } | |
140 | |
3995 | 141 void OUTPORT8(unsigned idx,unsigned char val) |
3973 | 142 { |
143 outb(idx,val); | |
144 } | |
145 | |
3995 | 146 void OUTPORT16(unsigned idx,unsigned short val) |
3973 | 147 { |
148 outw(idx,val); | |
149 } | |
150 | |
3995 | 151 void OUTPORT32(unsigned idx,unsigned val) |
3973 | 152 { |
153 outl(idx,val); | |
154 } | |
4174
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4164
diff
changeset
|
155 |