libvo: register X11 connection fd in input event system
[mplayer/glamo.git] / vidix / sysdep / pci_linux.c
blobbd5c14fabf5470ee9d481c43fbc7b35eef22ab7e
1 /*
2 This file is based on:
3 $XFree86: xc/programs/Xserver/hw/xfree86/etc/scanpci.c,v 3.34.2.17 1998/11/10 11:55:40 dawes Exp $
4 Modified for readability by Nick Kurshev
5 */
6 /*
7 * Copyright 1995 by Robin Cutshaw <robin@XFree86.Org>
9 * Permission to use, copy, modify, distribute, and sell this software and its
10 * documentation for any purpose is hereby granted without fee, provided that
11 * the above copyright notice appear in all copies and that both that
12 * copyright notice and this permission notice appear in supporting
13 * documentation, and that the names of the above listed copyright holder(s)
14 * not be used in advertising or publicity pertaining to distribution of
15 * the software without specific, written prior permission. The above listed
16 * copyright holder(s) make(s) no representations about the suitability of this
17 * software for any purpose. It is provided "as is" without express or
18 * implied warranty.
20 * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM(S) ALL WARRANTIES WITH REGARD
21 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
22 * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
23 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
24 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
25 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
26 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 #include <errno.h>
30 #if ARCH_X86
31 //#include <sys/perm.h> doesn't exist on libc5 systems
32 int iopl();
33 #elif defined(__sh__)
34 #define iopl(x) 1
35 #else
36 #if !defined(__sparc__) && !defined(__powerpc__) && !defined(__x86_64__)
37 #include <sys/io.h>
38 #endif
39 #endif
41 #include "config.h"
43 #ifdef CONFIG_DHAHELPER
44 #include <fcntl.h>
45 int dhahelper_initialized = 0;
46 int dhahelper_fd = 0;
47 #endif
49 #ifdef CONFIG_SVGAHELPER
50 #include <svgalib_helper.h>
51 #include <linux/ioctl.h>
52 #include <fcntl.h>
53 #ifndef SVGALIB_HELPER_IOC_MAGIC
54 /* svgalib 1.9.18+ compatibility ::atmos */
55 #define SVGALIB_HELPER_IOCGPCIINL SVGAHELPER_PCIINL
56 #endif
57 int svgahelper_initialized = 0;
58 int svgahelper_fd = 0;
60 static int pci_config_type(void)
62 return 1;
65 static long pci_config_read_long(
66 unsigned char bus,
67 unsigned char dev,
68 int func,
69 unsigned cmd)
71 pcic_t p;
73 p.address = cmd;
74 p.pcipos = (bus << 8) | dev | (func << 5);
76 if (ioctl(svgahelper_fd, SVGALIB_HELPER_IOCGPCIINL, &p))
77 return -1;
79 return p.val;
82 static int pci_get_vendor(
83 unsigned char bus,
84 unsigned char dev,
85 int func)
87 return pci_config_read_long(bus, dev, func, 0);
89 #endif /* CONFIG_SVGAHELPER */
91 static __inline__ int enable_os_io(void)
93 #ifdef CONFIG_SVGAHELPER
94 svgahelper_fd = open(DEV_SVGA, O_RDWR);
95 if (svgahelper_fd > 0)
97 svgahelper_initialized = 1;
98 return 0;
100 svgahelper_initialized = -1;
101 #endif
103 #ifdef CONFIG_DHAHELPER
104 dhahelper_fd = open("/dev/dhahelper", O_RDWR);
105 if (dhahelper_fd > 0)
107 dhahelper_initialized = 1;
108 return 0;
110 dhahelper_initialized = -1;
111 #endif
113 #if defined(__powerpc__) && defined(__linux__)
114 /* should be fixed? */
115 #else
116 if (iopl(3) != 0)
117 return errno;
118 #endif
119 return 0;
122 static __inline__ int disable_os_io(void)
124 #ifdef CONFIG_SVGAHELPER
125 if (svgahelper_initialized == 1)
126 close(svgahelper_fd);
127 else
128 #endif
129 #ifdef CONFIG_DHAHELPER
130 if (dhahelper_initialized == 1)
131 close(dhahelper_fd);
132 else
133 #endif
134 #if defined(__powerpc__) && defined(__linux__)
135 /* should be fixed? */
136 #else
137 if (iopl(0) != 0)
138 return errno;
139 #endif
140 return 0;
143 #if (defined(__powerpc__) || defined(__sparc__) || defined(__sparc64__) \
144 || defined(__x86_64__) || defined(__sh__)) && defined(__linux__) && !defined(CONFIG_SVGAHELPER)
145 #define CONFIG_PCI_LINUX_PROC
146 #endif
148 #if defined(CONFIG_PCI_LINUX_PROC)
149 static int pci_config_type( void ) { return 1; }
151 /* pci operations for (powerpc) Linux
152 questions, suggestions etc:
153 mplayer-dev-eng@mplayerhq.hu, colin@colino.net*/
154 #include <fcntl.h>
155 //#include <sys/io.h>
156 #include <linux/pci.h>
157 #include "libavutil/common.h"
158 #include "mpbswap.h"
160 static int pci_get_vendor(
161 unsigned char bus,
162 unsigned char dev,
163 int func)
165 int retval;
166 char path[100];
167 int fd;
168 short vendor, device;
169 sprintf(path,"/proc/bus/pci/%02d/%02x.0", bus, dev);
170 fd = open(path,O_RDONLY|O_SYNC);
171 if (fd == -1) {
172 retval=0xFFFF;
174 else if (pread(fd, &vendor, 2, PCI_VENDOR_ID) == 2 &&
175 pread(fd, &device, 2, PCI_DEVICE_ID) == 2) {
176 vendor = le2me_16(vendor);
177 device = le2me_16(device);
178 retval = vendor + (device<<16); /*no worries about byte order,
179 all ppc are bigendian*/
180 } else {
181 retval = 0xFFFF;
183 if (fd > 0) {
184 close(fd);
186 return retval;
189 static long pci_config_read_long(
190 unsigned char bus,
191 unsigned char dev,
192 int func,
193 unsigned cmd)
195 long retval;
196 char path[100];
197 int fd;
198 sprintf(path,"/proc/bus/pci/%02d/%02x.0", bus, dev);
199 fd = open(path,O_RDONLY|O_SYNC);
200 if (fd == -1) {
201 retval=0;
203 else if (pread(fd, &retval, 4, cmd) == 4) {
204 retval = le2me_32(retval);
205 } else {
206 retval = 0;
208 if (fd > 0) {
209 close(fd);
211 return retval;
213 #endif /* defined(CONFIG_PCI_LINUX_PROC) */