Mercurial > mplayer.hg
annotate libdha/sysdep/pci_linux.c @ 10801:6c56b4aff706
Jacosub files can have the extension '.js' too. Patch by Vladimir Mosgalin <mosgalin@VM10124.spb.edu>
author | alex |
---|---|
date | Tue, 02 Sep 2003 17:26:33 +0000 |
parents | 9dbb9c710480 |
children | 22f8732b5d97 |
rev | line source |
---|---|
4164 | 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 */ | |
4174
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4164
diff
changeset
|
6 #include <errno.h> |
4164 | 7 #ifdef __i386__ |
8 #include <sys/perm.h> | |
9 #else | |
8460
d09c74452323
this fixes compilation for me (and it works), hope it didn't breaks for LinuxPPC (i use Debian/PPC with 2.4.20 kernel)
alex
parents:
7837
diff
changeset
|
10 #if !defined(__sparc__) && !defined(__powerpc__) |
4164 | 11 #include <sys/io.h> |
12 #endif | |
6613
5cf616a755ac
Linux for Sparc fix by Adam Di Carlo <adam at onshore-devel.com>
alex
parents:
4474
diff
changeset
|
13 #endif |
4164 | 14 |
4474 | 15 #include "config.h" |
16 | |
17 #ifdef CONFIG_DHAHELPER | |
18 #include <fcntl.h> | |
19 int dhahelper_initialized = 0; | |
20 int dhahelper_fd = 0; | |
21 #endif | |
22 | |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
23 #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:
8460
diff
changeset
|
24 #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:
8460
diff
changeset
|
25 #ifdef __linux__ |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
26 #include <linux/ioctl.h> |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
27 #endif |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
28 #include <fcntl.h> |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
29 int svgahelper_initialized = 0; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
30 int svgahelper_fd = 0; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
31 |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
32 static int pci_config_type(void) |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
33 { |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
34 return 1; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
35 } |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
36 |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
37 static long pci_config_read_long( |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
38 unsigned char bus, |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
39 unsigned char dev, |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
40 int func, |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
41 unsigned cmd) |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
42 { |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
43 unsigned long config_cmd; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
44 pcic_t p; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
45 |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
46 p.address = cmd; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
47 p.pcipos = (bus << 8) | dev | (func << 5); |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
48 |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
49 if (ioctl(svgahelper_fd, SVGALIB_HELPER_IOCGPCIINL, &p)) |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
50 return -1; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
51 |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
52 return p.val; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
53 } |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
54 |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
55 static int pci_get_vendor( |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
56 unsigned char bus, |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
57 unsigned char dev, |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
58 int func) |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
59 { |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
60 return pci_config_read_long(bus, dev, func, 0); |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
61 } |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
62 #endif |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
63 |
4174
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4164
diff
changeset
|
64 static __inline__ int enable_os_io(void) |
4164 | 65 { |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
66 #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:
8460
diff
changeset
|
67 svgahelper_fd = open(DEV_SVGA, O_RDWR); |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
68 if (svgahelper_fd > 0) |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
69 { |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
70 svgahelper_initialized = 1; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
71 return(0); |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
72 } |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
73 svgahelper_initialized = -1; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
74 #endif |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
75 |
4474 | 76 #ifdef CONFIG_DHAHELPER |
77 dhahelper_fd = open("/dev/dhahelper", O_RDWR); | |
78 if (dhahelper_fd > 0) | |
79 { | |
80 dhahelper_initialized = 1; | |
81 return(0); | |
82 } | |
83 dhahelper_initialized = -1; | |
84 #endif | |
85 | |
7837
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
6613
diff
changeset
|
86 #if defined(__powerpc__) && defined(__linux__) |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
6613
diff
changeset
|
87 /* should be fixed? */ |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
6613
diff
changeset
|
88 #else |
4174
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4164
diff
changeset
|
89 if (iopl(3) != 0) |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4164
diff
changeset
|
90 return(errno); |
7837
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
6613
diff
changeset
|
91 #endif |
4174
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4164
diff
changeset
|
92 return(0); |
4164 | 93 } |
94 | |
4174
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4164
diff
changeset
|
95 static __inline__ int disable_os_io(void) |
4164 | 96 { |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
97 #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:
8460
diff
changeset
|
98 if (svgahelper_initialized == 1) |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
99 close(svgahelper_fd); |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
100 else |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
101 #endif |
4474 | 102 #ifdef CONFIG_DHAHELPER |
103 if (dhahelper_initialized == 1) | |
104 close(dhahelper_fd); | |
105 else | |
106 #endif | |
7837
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
6613
diff
changeset
|
107 #if defined(__powerpc__) && defined(__linux__) |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
6613
diff
changeset
|
108 /* should be fixed? */ |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
6613
diff
changeset
|
109 #else |
4174
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4164
diff
changeset
|
110 if (iopl(0) != 0) |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4164
diff
changeset
|
111 return(errno); |
7837
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
6613
diff
changeset
|
112 #endif |
4174
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4164
diff
changeset
|
113 return(0); |
4164 | 114 } |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
115 |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
116 #if (defined(__powerpc__) || defined(__sparc__) || defined(__sparc64__)) \ |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
117 && defined(__linux__) && !defined(CONFIG_SVGAHELPER) |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
118 #define CONFIG_PCI_LINUX_PROC |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
119 #endif |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
120 |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
121 #if defined(CONFIG_PCI_LINUX_PROC) |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
122 static int pci_config_type( void ) { return 1; } |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
123 |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
124 /* pci operations for (powerpc) Linux |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
125 questions, suggestions etc: |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
126 mplayer-dev-eng@mplayerhq.hu, colin@colino.net*/ |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
127 #include <fcntl.h> |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
128 //#include <sys/io.h> |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
129 #include <linux/pci.h> |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
130 #include "../../bswap.h" |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
131 |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
132 static int pci_get_vendor( |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
133 unsigned char bus, |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
134 unsigned char dev, |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
135 int func) |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
136 { |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
137 int retval; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
138 char path[100]; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
139 int fd; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
140 short vendor, device; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
141 sprintf(path,"/proc/bus/pci/%02d/%02x.0", bus, dev); |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
142 fd = open(path,O_RDONLY|O_SYNC); |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
143 if (fd == -1) { |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
144 retval=0xFFFF; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
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:
8460
diff
changeset
|
146 else if (pread(fd, &vendor, 2, PCI_VENDOR_ID) == 2 && |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
147 pread(fd, &device, 2, PCI_DEVICE_ID) == 2) { |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
148 vendor = le2me_16(vendor); |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
149 device = le2me_16(device); |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
150 retval = vendor + (device<<16); /*no worries about byte order, |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
151 all ppc are bigendian*/ |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
152 } else { |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
153 retval = 0xFFFF; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
154 } |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
155 if (fd > 0) { |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
156 close(fd); |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
157 } |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
158 return retval; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
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:
8460
diff
changeset
|
160 |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
161 static long pci_config_read_long( |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
162 unsigned char bus, |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
163 unsigned char dev, |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
164 int func, |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
165 unsigned cmd) |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
166 { |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
167 long retval; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
168 char path[100]; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
169 int fd; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
170 sprintf(path,"/proc/bus/pci/%02d/%02x.0", bus, dev); |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
171 fd = open(path,O_RDONLY|O_SYNC); |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
172 if (fd == -1) { |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
173 retval=0; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
174 } |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
175 else if (pread(fd, &retval, 4, cmd) == 4) { |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
176 retval = le2me_32(retval); |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
177 } else { |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
178 retval = 0; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
179 } |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
180 if (fd > 0) { |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
181 close(fd); |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
182 } |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
183 return retval; |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
184 } |
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
8460
diff
changeset
|
185 #endif |