Mercurial > mplayer.hg
annotate libdha/sysdep/pci_linux.c @ 16593:1c13fb2ba5a9
Allow specifying a custom (ppm) texture for texture unit 3
author | reimar |
---|---|
date | Sun, 25 Sep 2005 16:31:58 +0000 |
parents | cb35163ef0a1 |
children | c6dca3153ddb |
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__ |
11455 | 8 // is this needed? #include <sys/perm.h> |
4164 | 9 #else |
12687 | 10 #if !defined(__sparc__) && !defined(__powerpc__) && !defined(__x86_64__) |
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> |
12078
62705b2298ff
svgalib 1.9.18 compile fix, still wont work for me though...
atmos4
parents:
11455
diff
changeset
|
29 #ifndef SVGALIB_HELPER_IOC_MAGIC |
62705b2298ff
svgalib 1.9.18 compile fix, still wont work for me though...
atmos4
parents:
11455
diff
changeset
|
30 /* svgalib 1.9.18+ compatibility ::atmos */ |
62705b2298ff
svgalib 1.9.18 compile fix, still wont work for me though...
atmos4
parents:
11455
diff
changeset
|
31 #define SVGALIB_HELPER_IOCGPCIINL SVGAHELPER_PCIINL |
62705b2298ff
svgalib 1.9.18 compile fix, still wont work for me though...
atmos4
parents:
11455
diff
changeset
|
32 #endif |
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
|
33 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
|
34 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
|
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 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
|
37 { |
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 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
|
39 } |
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 |
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 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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 { |
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 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
|
48 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
|
49 |
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 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
|
51 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
|
52 |
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 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
|
54 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
|
55 |
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 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
|
57 } |
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 |
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 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
|
60 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
|
61 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
|
62 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
|
63 { |
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
|
64 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
|
65 } |
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 #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
|
67 |
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
|
68 static __inline__ int enable_os_io(void) |
4164 | 69 { |
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
|
70 #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
|
71 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
|
72 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
|
73 { |
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 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
|
75 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
|
76 } |
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
|
77 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
|
78 #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
|
79 |
4474 | 80 #ifdef CONFIG_DHAHELPER |
81 dhahelper_fd = open("/dev/dhahelper", O_RDWR); | |
82 if (dhahelper_fd > 0) | |
83 { | |
84 dhahelper_initialized = 1; | |
85 return(0); | |
86 } | |
87 dhahelper_initialized = -1; | |
88 #endif | |
89 | |
7837
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
6613
diff
changeset
|
90 #if defined(__powerpc__) && defined(__linux__) |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
6613
diff
changeset
|
91 /* should be fixed? */ |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
6613
diff
changeset
|
92 #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
|
93 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
|
94 return(errno); |
7837
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
6613
diff
changeset
|
95 #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
|
96 return(0); |
4164 | 97 } |
98 | |
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
|
99 static __inline__ int disable_os_io(void) |
4164 | 100 { |
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
|
101 #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
|
102 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
|
103 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
|
104 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
|
105 #endif |
4474 | 106 #ifdef CONFIG_DHAHELPER |
107 if (dhahelper_initialized == 1) | |
108 close(dhahelper_fd); | |
109 else | |
110 #endif | |
7837
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
6613
diff
changeset
|
111 #if defined(__powerpc__) && defined(__linux__) |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
6613
diff
changeset
|
112 /* should be fixed? */ |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
6613
diff
changeset
|
113 #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
|
114 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
|
115 return(errno); |
7837
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
6613
diff
changeset
|
116 #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
|
117 return(0); |
4164 | 118 } |
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
|
119 |
12687 | 120 #if (defined(__powerpc__) || defined(__sparc__) || defined(__sparc64__) \ |
121 || defined(__x86_64__)) && defined(__linux__) && !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:
8460
diff
changeset
|
122 #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
|
123 #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
|
124 |
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 #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
|
126 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
|
127 |
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 /* 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
|
129 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
|
130 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
|
131 #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
|
132 //#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
|
133 #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
|
134 #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
|
135 |
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 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
|
137 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
|
138 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
|
139 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
|
140 { |
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 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 } |
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 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 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
|
156 } 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
|
157 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
|
158 } |
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 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
|
160 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
|
161 } |
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 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
|
163 } |
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 |
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 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 { |
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 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 } |
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 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
|
180 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
|
181 } 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
|
182 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
|
183 } |
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 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
|
185 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
|
186 } |
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
|
187 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
|
188 } |
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
|
189 #endif |