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
36 #if !defined(__sparc__) && !defined(__powerpc__) && !defined(__x86_64__)
43 #ifdef CONFIG_DHAHELPER
45 int dhahelper_initialized
= 0;
49 #ifdef CONFIG_SVGAHELPER
50 #include <svgalib_helper.h>
51 #include <linux/ioctl.h>
53 #ifndef SVGALIB_HELPER_IOC_MAGIC
54 /* svgalib 1.9.18+ compatibility ::atmos */
55 #define SVGALIB_HELPER_IOCGPCIINL SVGAHELPER_PCIINL
57 int svgahelper_initialized
= 0;
58 int svgahelper_fd
= 0;
60 static int pci_config_type(void)
65 static long pci_config_read_long(
74 p
.pcipos
= (bus
<< 8) | dev
| (func
<< 5);
76 if (ioctl(svgahelper_fd
, SVGALIB_HELPER_IOCGPCIINL
, &p
))
82 static int pci_get_vendor(
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;
100 svgahelper_initialized
= -1;
103 #ifdef CONFIG_DHAHELPER
104 dhahelper_fd
= open("/dev/dhahelper", O_RDWR
);
105 if (dhahelper_fd
> 0)
107 dhahelper_initialized
= 1;
110 dhahelper_initialized
= -1;
113 #if defined(__powerpc__) && defined(__linux__)
114 /* should be fixed? */
122 static __inline__
int disable_os_io(void)
124 #ifdef CONFIG_SVGAHELPER
125 if (svgahelper_initialized
== 1)
126 close(svgahelper_fd
);
129 #ifdef CONFIG_DHAHELPER
130 if (dhahelper_initialized
== 1)
134 #if defined(__powerpc__) && defined(__linux__)
135 /* should be fixed? */
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
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*/
155 //#include <sys/io.h>
156 #include <linux/pci.h>
157 #include "libavutil/common.h"
160 static int pci_get_vendor(
168 short vendor
, device
;
169 sprintf(path
,"/proc/bus/pci/%02d/%02x.0", bus
, dev
);
170 fd
= open(path
,O_RDONLY
|O_SYNC
);
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*/
189 static long pci_config_read_long(
198 sprintf(path
,"/proc/bus/pci/%02d/%02x.0", bus
, dev
);
199 fd
= open(path
,O_RDONLY
|O_SYNC
);
203 else if (pread(fd
, &retval
, 4, cmd
) == 4) {
204 retval
= le2me_32(retval
);
213 #endif /* defined(CONFIG_PCI_LINUX_PROC) */