Mercurial > mplayer.hg
annotate libdha/libdha.c @ 22819:71f9c67d689a
mention vidix in Solaris/x86
author | nicodvb |
---|---|
date | Wed, 28 Mar 2007 19:16:38 +0000 |
parents | a59deec120cc |
children |
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 | |
12069 | 35 #if defined(WIN32) |
4164 | 36 #include "sysdep/libdha_win32.c" |
37 #elif defined (__EMX__) | |
38 #include "sysdep/libdha_os2.c" | |
39 #else | |
3973 | 40 |
4164 | 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 | |
22817
a59deec120cc
in solaris the I/O device to mmap() is /dev/xsvc, not /dev/mem
nicodvb
parents:
14567
diff
changeset
|
51 #elif defined(sun) && defined (i386) |
a59deec120cc
in solaris the I/O device to mmap() is /dev/xsvc, not /dev/mem
nicodvb
parents:
14567
diff
changeset
|
52 #define DEV_MEM "/dev/xsvc" |
4164 | 53 # endif /* SVR4 */ |
3973 | 54 |
14567 | 55 #if defined(__OpenBSD__) |
56 #define DEV_APERTURE "/dev/xf86" | |
57 #endif | |
58 | |
4164 | 59 /* Generic version */ |
60 #include <sys/mman.h> | |
3973 | 61 |
4164 | 62 #ifndef DEV_MEM |
63 #define DEV_MEM "/dev/mem" | |
64 #endif | |
3973 | 65 |
4474 | 66 #ifdef CONFIG_DHAHELPER |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
67 #include "kernelhelper/dhahelper.h" |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
68 #endif |
4938 | 69 |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
70 #ifdef CONFIG_SVGAHELPER |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
71 #include <svgalib_helper.h> |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
72 #endif |
4938 | 73 |
9025
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
74 static int mem_fd = -1; |
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
75 |
5702 | 76 void *map_phys_mem(unsigned long base, unsigned long size) |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
77 { |
5702 | 78 #ifdef ARCH_ALPHA |
79 /* TODO: move it into sysdep */ | |
80 base += bus_base(); | |
81 #endif | |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
82 |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
83 #ifdef CONFIG_SVGAHELPER |
9025
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
84 if ( (mem_fd = open(DEV_SVGA,O_RDWR)) == -1) { |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
85 perror("libdha: SVGAlib kernelhelper failed"); |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
86 #ifdef CONFIG_DHAHELPER |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
87 goto dha_helper_way; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
88 #else |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
89 goto dev_mem_way; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
90 #endif |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
91 } |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
92 else |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
93 goto mmap; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
94 #endif |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
95 |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
96 #ifdef CONFIG_DHAHELPER |
9219
4a5b01c405b6
compiler warning fixes by Domink and some other changes by me
alex
parents:
9025
diff
changeset
|
97 #ifdef CONFIG_SVGAHELPER |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
98 dha_helper_way: |
9219
4a5b01c405b6
compiler warning fixes by Domink and some other changes by me
alex
parents:
9025
diff
changeset
|
99 #endif |
9025
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
100 if ( (mem_fd = open("/dev/dhahelper",O_RDWR)) < 0) |
4474 | 101 { |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
102 perror("libdha: DHA kernelhelper failed"); |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
103 goto dev_mem_way; |
4474 | 104 } |
105 else | |
106 { | |
107 dhahelper_memory_t mem_req; | |
108 | |
109 mem_req.operation = MEMORY_OP_MAP; | |
110 mem_req.start = base; | |
111 mem_req.offset = 0; | |
112 mem_req.size = size; | |
113 | |
9025
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
114 if (ioctl(mem_fd, DHAHELPER_MEMORY, &mem_req) < 0) |
4474 | 115 { |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
116 perror("libdha: DHA kernelhelper failed"); |
9025
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
117 close(mem_fd); |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
118 goto dev_mem_way; |
4474 | 119 } |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
120 else |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
121 goto mmap; |
4474 | 122 } |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
123 #endif |
4474 | 124 |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
125 dev_mem_way: |
14567 | 126 #ifdef DEV_APERTURE |
127 if ((mem_fd = open(DEV_APERTURE, O_RDWR)) == -1) | |
128 perror("libdha: opening aperture failed"); | |
129 else { | |
130 void *p = mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem_fd,base); | |
131 | |
132 if (p == MAP_FAILED) { | |
133 perror("libdha: mapping aperture failed"); | |
134 close(mem_fd); | |
135 } else | |
136 return p; | |
137 } | |
138 #endif | |
139 | |
9025
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
140 if ( (mem_fd = open(DEV_MEM,O_RDWR)) == -1) |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
141 { |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
142 perror("libdha: opening /dev/mem failed"); |
9219
4a5b01c405b6
compiler warning fixes by Domink and some other changes by me
alex
parents:
9025
diff
changeset
|
143 return MAP_FAILED; |
3973 | 144 } |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
145 |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
146 mmap: |
9025
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
147 return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem_fd,base); |
3973 | 148 } |
149 | |
5702 | 150 void unmap_phys_mem(void *ptr, unsigned long size) |
3973 | 151 { |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
152 int res = munmap(ptr,size); |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
153 |
9219
4a5b01c405b6
compiler warning fixes by Domink and some other changes by me
alex
parents:
9025
diff
changeset
|
154 if (res == (int)MAP_FAILED) |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
155 { |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
156 perror("libdha: unmapping memory failed"); |
9219
4a5b01c405b6
compiler warning fixes by Domink and some other changes by me
alex
parents:
9025
diff
changeset
|
157 return; |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
158 } |
9025
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
159 |
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
160 close(mem_fd); |
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
161 mem_fd = -1; |
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
162 |
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
163 return; |
3973 | 164 } |
165 | |
10980 | 166 #endif /* Generic mmap (not win32, nor os2) */ |
167 | |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
168 unsigned char INPORT8(unsigned idx) |
3973 | 169 { |
170 return inb(idx); | |
171 } | |
172 | |
3995 | 173 unsigned short INPORT16(unsigned idx) |
3973 | 174 { |
175 return inw(idx); | |
176 } | |
177 | |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
178 unsigned INPORT32(unsigned idx) |
3973 | 179 { |
180 return inl(idx); | |
181 } | |
182 | |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
183 void OUTPORT8(unsigned idx,unsigned char val) |
3973 | 184 { |
185 outb(idx,val); | |
186 } | |
187 | |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
188 void OUTPORT16(unsigned idx,unsigned short val) |
3973 | 189 { |
190 outw(idx,val); | |
191 } | |
192 | |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
193 void OUTPORT32(unsigned idx,unsigned val) |
3973 | 194 { |
195 outl(idx,val); | |
196 } |