Mercurial > mplayer.hg
annotate vidix/dha.c @ 23516:5441be2c507b
caps character after "Explanation:" in tvinput.xml
author | ptt |
---|---|
date | Sun, 10 Jun 2007 17:49:43 +0000 |
parents | cc0627bce6bf |
children | acfe034e5386 |
rev | line source |
---|---|
3973 | 1 /* |
23046
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
2 * VIDIX Direct Hardware Access (DHA). |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
3 * Copyright (C) 2002 Nick Kurshev |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
4 * |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
5 * This file is part of MPlayer. |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
6 * |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
7 * MPlayer is free software; you can redistribute it and/or modify |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
8 * it under the terms of the GNU General Public License as published by |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
9 * the Free Software Foundation; either version 2 of the License, or |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
10 * (at your option) any later version. |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
11 * |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
12 * MPlayer is distributed in the hope that it will be useful, |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
15 * GNU General Public License for more details. |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
16 * |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
17 * You should have received a copy of the GNU General Public License |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
18 * along with MPlayer; if not, write to the Free Software |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
20 * |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
21 * 1996/10/27 - Robin Cutshaw (robin@xfree86.org) |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
22 * XFree86 3.3.3 implementation |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
23 * 1999 - Øyvind Aabling. |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
24 * Modified for GATOS/win/gfxdump. |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
25 * |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
26 * 2002 - library implementation by Nick Kurshev |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
27 * - dhahelper and some changes by Alex Beregszaszi |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
28 * |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
29 * Supported O/S's: SVR4, UnixWare, SCO, Solaris, |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
30 * FreeBSD, NetBSD, 386BSD, BSDI BSD/386, |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
31 * Linux, Mach/386, ISC |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
32 * DOS (WATCOM 9.5 compiler), Win9x (with mapdev.vxd) |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
33 * Original location: www.linuxvideo.org/gatos |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23045
diff
changeset
|
34 */ |
3973 | 35 |
4474 | 36 #include "config.h" |
37 | |
22901 | 38 #include "dha.h" |
3973 | 39 #include "AsmMacros.h" |
40 #include <stdio.h> | |
41 #include <stdlib.h> | |
42 #include <string.h> | |
43 #include <fcntl.h> | |
44 #include <sys/stat.h> | |
45 #include <sys/types.h> | |
5702 | 46 #ifdef ARCH_ALPHA |
47 #include <sys/io.h> | |
48 #endif | |
3973 | 49 #include <unistd.h> |
50 | |
12069 | 51 #if defined(WIN32) |
4164 | 52 #include "sysdep/libdha_win32.c" |
53 #elif defined (__EMX__) | |
54 #include "sysdep/libdha_os2.c" | |
55 #else | |
3973 | 56 |
4164 | 57 #if defined(SVR4) || defined(SCO325) |
58 # if !(defined(sun) && defined (i386) && defined (SVR4)) | |
59 # define DEV_MEM "/dev/pmem" | |
60 # elif defined(PowerMAX_OS) | |
61 # define DEV_MEM "/dev/iomem" | |
62 # endif | |
63 # ifdef SCO325 | |
64 # undef DEV_MEM | |
65 # define DEV_MEM "/dev/mem" | |
66 # endif | |
22817
a59deec120cc
in solaris the I/O device to mmap() is /dev/xsvc, not /dev/mem
nicodvb
parents:
14567
diff
changeset
|
67 #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
|
68 #define DEV_MEM "/dev/xsvc" |
4164 | 69 # endif /* SVR4 */ |
3973 | 70 |
14567 | 71 #if defined(__OpenBSD__) |
72 #define DEV_APERTURE "/dev/xf86" | |
73 #endif | |
74 | |
4164 | 75 /* Generic version */ |
76 #include <sys/mman.h> | |
3973 | 77 |
4164 | 78 #ifndef DEV_MEM |
79 #define DEV_MEM "/dev/mem" | |
80 #endif | |
3973 | 81 |
4474 | 82 #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
|
83 #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
|
84 #endif |
4938 | 85 |
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
|
86 #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
|
87 #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
|
88 #endif |
4938 | 89 |
9025
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
90 static int mem_fd = -1; |
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
91 |
5702 | 92 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
|
93 { |
5702 | 94 #ifdef ARCH_ALPHA |
95 /* TODO: move it into sysdep */ | |
96 base += bus_base(); | |
97 #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
|
98 |
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
|
99 #ifdef CONFIG_SVGAHELPER |
9025
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
100 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
|
101 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
|
102 #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
|
103 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
|
104 #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
|
105 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
|
106 #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
|
107 } |
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
|
108 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
|
109 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
|
110 #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
|
111 |
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
|
112 #ifdef CONFIG_DHAHELPER |
9219
4a5b01c405b6
compiler warning fixes by Domink and some other changes by me
alex
parents:
9025
diff
changeset
|
113 #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
|
114 dha_helper_way: |
9219
4a5b01c405b6
compiler warning fixes by Domink and some other changes by me
alex
parents:
9025
diff
changeset
|
115 #endif |
9025
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
116 if ( (mem_fd = open("/dev/dhahelper",O_RDWR)) < 0) |
4474 | 117 { |
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 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
|
119 goto dev_mem_way; |
4474 | 120 } |
121 else | |
122 { | |
123 dhahelper_memory_t mem_req; | |
124 | |
125 mem_req.operation = MEMORY_OP_MAP; | |
126 mem_req.start = base; | |
127 mem_req.offset = 0; | |
128 mem_req.size = size; | |
129 | |
9025
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
130 if (ioctl(mem_fd, DHAHELPER_MEMORY, &mem_req) < 0) |
4474 | 131 { |
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
|
132 perror("libdha: DHA kernelhelper failed"); |
9025
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
133 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
|
134 goto dev_mem_way; |
4474 | 135 } |
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
|
136 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
|
137 goto mmap; |
4474 | 138 } |
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
|
139 #endif |
4474 | 140 |
23063
cc0627bce6bf
fix dha compilation if SVGAHELPER is used (patch by Carl Eugen Hoyos
ben
parents:
23046
diff
changeset
|
141 #if defined(CONFIG_DHAHELPER) || defined (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
|
142 dev_mem_way: |
23045 | 143 #endif |
14567 | 144 #ifdef DEV_APERTURE |
145 if ((mem_fd = open(DEV_APERTURE, O_RDWR)) == -1) | |
146 perror("libdha: opening aperture failed"); | |
147 else { | |
148 void *p = mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem_fd,base); | |
149 | |
150 if (p == MAP_FAILED) { | |
151 perror("libdha: mapping aperture failed"); | |
152 close(mem_fd); | |
153 } else | |
154 return p; | |
155 } | |
156 #endif | |
157 | |
9025
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
158 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
|
159 { |
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
|
160 perror("libdha: opening /dev/mem failed"); |
9219
4a5b01c405b6
compiler warning fixes by Domink and some other changes by me
alex
parents:
9025
diff
changeset
|
161 return MAP_FAILED; |
3973 | 162 } |
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
|
163 |
23063
cc0627bce6bf
fix dha compilation if SVGAHELPER is used (patch by Carl Eugen Hoyos
ben
parents:
23046
diff
changeset
|
164 #if defined(CONFIG_DHAHELPER) || defined (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
|
165 mmap: |
23045 | 166 #endif |
9025
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
167 return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem_fd,base); |
3973 | 168 } |
169 | |
5702 | 170 void unmap_phys_mem(void *ptr, unsigned long size) |
3973 | 171 { |
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
|
172 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
|
173 |
9219
4a5b01c405b6
compiler warning fixes by Domink and some other changes by me
alex
parents:
9025
diff
changeset
|
174 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
|
175 { |
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
|
176 perror("libdha: unmapping memory failed"); |
9219
4a5b01c405b6
compiler warning fixes by Domink and some other changes by me
alex
parents:
9025
diff
changeset
|
177 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
|
178 } |
9025
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
179 |
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
180 close(mem_fd); |
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
181 mem_fd = -1; |
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
182 |
ae0507e107b7
cleanup and removal of libdha_exit. forgot to commit this
alex
parents:
8503
diff
changeset
|
183 return; |
3973 | 184 } |
185 | |
10980 | 186 #endif /* Generic mmap (not win32, nor os2) */ |
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 unsigned char INPORT8(unsigned idx) |
3973 | 189 { |
190 return inb(idx); | |
191 } | |
192 | |
3995 | 193 unsigned short INPORT16(unsigned idx) |
3973 | 194 { |
195 return inw(idx); | |
196 } | |
197 | |
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
|
198 unsigned INPORT32(unsigned idx) |
3973 | 199 { |
200 return inl(idx); | |
201 } | |
202 | |
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
|
203 void OUTPORT8(unsigned idx,unsigned char val) |
3973 | 204 { |
205 outb(idx,val); | |
206 } | |
207 | |
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
|
208 void OUTPORT16(unsigned idx,unsigned short val) |
3973 | 209 { |
210 outw(idx,val); | |
211 } | |
212 | |
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
|
213 void OUTPORT32(unsigned idx,unsigned val) |
3973 | 214 { |
215 outl(idx,val); | |
216 } |