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
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
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.
31 //#include <sys/perm.h> doesn't exist on libc5 systems
34 #if !defined(__sparc__) && !defined(__powerpc__) && !defined(__x86_64__)
45 #ifdef CONFIG_DHAHELPER
47 int dhahelper_initialized
= 0;
51 #ifdef CONFIG_SVGAHELPER
52 #include <svgalib_helper.h>
54 #include <linux/ioctl.h>
57 #ifndef SVGALIB_HELPER_IOC_MAGIC
58 /* svgalib 1.9.18+ compatibility ::atmos */
59 #define SVGALIB_HELPER_IOCGPCIINL SVGAHELPER_PCIINL
61 int svgahelper_initialized
= 0;
62 int svgahelper_fd
= 0;
64 static int pci_config_type(void)
69 static long pci_config_read_long(
78 p
.pcipos
= (bus
<< 8) | dev
| (func
<< 5);
80 if (ioctl(svgahelper_fd
, SVGALIB_HELPER_IOCGPCIINL
, &p
))
86 static int pci_get_vendor(
91 return pci_config_read_long(bus
, dev
, func
, 0);
93 #endif /* CONFIG_SVGAHELPER */
95 static __inline__
int enable_os_io(void)
97 #ifdef CONFIG_SVGAHELPER
98 svgahelper_fd
= open(DEV_SVGA
, O_RDWR
);
99 if (svgahelper_fd
> 0)
101 svgahelper_initialized
= 1;
104 svgahelper_initialized
= -1;
107 #ifdef CONFIG_DHAHELPER
108 dhahelper_fd
= open("/dev/dhahelper", O_RDWR
);
109 if (dhahelper_fd
> 0)
111 dhahelper_initialized
= 1;
114 dhahelper_initialized
= -1;
117 #if defined(__powerpc__) && defined(__linux__)
118 /* should be fixed? */
126 static __inline__
int disable_os_io(void)
128 #ifdef CONFIG_SVGAHELPER
129 if (svgahelper_initialized
== 1)
130 close(svgahelper_fd
);
133 #ifdef CONFIG_DHAHELPER
134 if (dhahelper_initialized
== 1)
138 #if defined(__powerpc__) && defined(__linux__)
139 /* should be fixed? */
147 #if (defined(__powerpc__) || defined(__sparc__) || defined(__sparc64__) \
148 || defined(__x86_64__) || defined(__sh__)) && defined(__linux__) && !defined(CONFIG_SVGAHELPER)
149 #define CONFIG_PCI_LINUX_PROC
152 #if defined(CONFIG_PCI_LINUX_PROC)
153 static int pci_config_type( void ) { return 1; }
155 /* pci operations for (powerpc) Linux
156 questions, suggestions etc:
157 mplayer-dev-eng@mplayerhq.hu, colin@colino.net*/
159 //#include <sys/io.h>
160 #include <linux/pci.h>
161 #include "libavutil/common.h"
164 static int pci_get_vendor(
172 short vendor
, device
;
173 sprintf(path
,"/proc/bus/pci/%02d/%02x.0", bus
, dev
);
174 fd
= open(path
,O_RDONLY
|O_SYNC
);
178 else if (pread(fd
, &vendor
, 2, PCI_VENDOR_ID
) == 2 &&
179 pread(fd
, &device
, 2, PCI_DEVICE_ID
) == 2) {
180 vendor
= le2me_16(vendor
);
181 device
= le2me_16(device
);
182 retval
= vendor
+ (device
<<16); /*no worries about byte order,
183 all ppc are bigendian*/
193 static long pci_config_read_long(
202 sprintf(path
,"/proc/bus/pci/%02d/%02x.0", bus
, dev
);
203 fd
= open(path
,O_RDONLY
|O_SYNC
);
207 else if (pread(fd
, &retval
, 4, cmd
) == 4) {
208 retval
= le2me_32(retval
);
217 #endif /* defined(CONFIG_PCI_LINUX_PROC) */