Mercurial > mplayer.hg
annotate libdha/libdha.c @ 4667:95fa3901cafc
add vsync support for doublebuffering to vo_vesa
author | atmos4 |
---|---|
date | Tue, 12 Feb 2002 15:06:04 +0000 |
parents | 05ac3586db02 |
children | b782efa10c60 |
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> | |
30 #include <unistd.h> | |
31 | |
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
|
32 /* 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
|
33 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
|
34 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
|
35 { |
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 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
|
37 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
|
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 |
4164 | 40 #if defined(_WIN32) |
41 #include "sysdep/libdha_win32.c" | |
42 #elif defined (__EMX__) | |
43 #include "sysdep/libdha_os2.c" | |
44 #else | |
3973 | 45 |
4164 | 46 #if defined(SVR4) || defined(SCO325) |
47 # if !(defined(sun) && defined (i386) && defined (SVR4)) | |
48 # define DEV_MEM "/dev/pmem" | |
49 # elif defined(PowerMAX_OS) | |
50 # define DEV_MEM "/dev/iomem" | |
51 # endif | |
52 # ifdef SCO325 | |
53 # undef DEV_MEM | |
54 # define DEV_MEM "/dev/mem" | |
55 # endif | |
56 # endif /* SVR4 */ | |
3973 | 57 |
4164 | 58 /* Generic version */ |
59 #include <sys/mman.h> | |
3973 | 60 |
4164 | 61 #ifndef DEV_MEM |
62 #define DEV_MEM "/dev/mem" | |
63 #endif | |
3973 | 64 |
4474 | 65 #ifdef CONFIG_DHAHELPER |
3973 | 66 static int mem=-1; |
67 void *map_phys_mem(unsigned base, unsigned size) | |
68 { | |
4474 | 69 if ( (mem = open("/dev/dhahelper",O_RDWR)) < 0) |
70 { | |
71 if ( (mem = open(DEV_MEM,O_RDWR)) == -1) { | |
72 perror("libdha: open(/dev/mem) failed") ; exit(1) ; | |
73 } | |
74 } | |
75 else | |
76 { | |
77 dhahelper_memory_t mem_req; | |
78 | |
79 mem_req.operation = MEMORY_OP_MAP; | |
80 mem_req.start = base; | |
81 mem_req.offset = 0; | |
82 mem_req.size = size; | |
83 | |
84 if (ioctl(mem, DHAHELPER_MEMORY, &mem_req) < 0) | |
85 { | |
86 perror("libdha: failed mapping throught kernel helper"); | |
87 return NULL; | |
88 } | |
89 } | |
90 return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem,base) ; | |
91 } | |
92 #else | |
93 | |
94 static int mem=-1; | |
95 void *map_phys_mem(unsigned base, unsigned size) | |
96 { | |
4164 | 97 if ( (mem = open(DEV_MEM,O_RDWR)) == -1) { |
3973 | 98 perror("libdha: open(/dev/mem) failed") ; exit(1) ; |
99 } | |
4164 | 100 return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem,base) ; |
3973 | 101 } |
4474 | 102 #endif /* CONFIG_DHAHELPER */ |
3973 | 103 |
104 void unmap_phys_mem(void *ptr, unsigned size) | |
105 { | |
106 int res=munmap(ptr,size) ; | |
107 if (res == -1) { perror("libdha: munmap() failed") ; exit(1) ; } | |
108 close(mem); | |
109 } | |
110 #endif | |
111 | |
3995 | 112 unsigned char INPORT8(unsigned idx) |
3973 | 113 { |
114 return inb(idx); | |
115 } | |
116 | |
3995 | 117 unsigned short INPORT16(unsigned idx) |
3973 | 118 { |
119 return inw(idx); | |
120 } | |
121 | |
3995 | 122 unsigned INPORT32(unsigned idx) |
3973 | 123 { |
124 return inl(idx); | |
125 } | |
126 | |
3995 | 127 void OUTPORT8(unsigned idx,unsigned char val) |
3973 | 128 { |
129 outb(idx,val); | |
130 } | |
131 | |
3995 | 132 void OUTPORT16(unsigned idx,unsigned short val) |
3973 | 133 { |
134 outw(idx,val); | |
135 } | |
136 | |
3995 | 137 void OUTPORT32(unsigned idx,unsigned val) |
3973 | 138 { |
139 outl(idx,val); | |
140 } | |
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
|
141 |