annotate vidix/sysdep/pci_linux.c @ 23612:10a64a994a16

Some comment typo fixes
author reimar
date Sun, 24 Jun 2007 10:24:11 +0000
parents a9e111b88c4a
children 9c4ad35fabc5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
1 /*
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
2 This file is based on:
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
3 $XFree86: xc/programs/Xserver/hw/xfree86/etc/scanpci.c,v 3.34.2.17 1998/11/10 11:55:40 dawes Exp $
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
4 Modified for readability by Nick Kurshev
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
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
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
7 #ifdef __i386__
17099
rathann
parents: 12687
diff changeset
8 //#include <sys/perm.h> doesn't exist on libc5 systems
rathann
parents: 12687
diff changeset
9 int iopl();
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
10 #else
12687
cb35163ef0a1 x86-64 (amd64) support by Kenny Root
alex
parents: 12078
diff changeset
11 #if !defined(__sparc__) && !defined(__powerpc__) && !defined(__x86_64__)
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
12 #include <sys/io.h>
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
13 #endif
6613
5cf616a755ac Linux for Sparc fix by Adam Di Carlo <adam at onshore-devel.com>
alex
parents: 4474
diff changeset
14 #endif
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
15
4474
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
16 #include "config.h"
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
17
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
18 #ifdef CONFIG_DHAHELPER
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
19 #include <fcntl.h>
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
20 int dhahelper_initialized = 0;
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
21 int dhahelper_fd = 0;
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
22 #endif
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
23
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
24 #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
25 #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
26 #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
27 #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
28 #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
29 #include <fcntl.h>
12078
62705b2298ff svgalib 1.9.18 compile fix, still wont work for me though...
atmos4
parents: 11455
diff changeset
30 #ifndef SVGALIB_HELPER_IOC_MAGIC
62705b2298ff svgalib 1.9.18 compile fix, still wont work for me though...
atmos4
parents: 11455
diff changeset
31 /* svgalib 1.9.18+ compatibility ::atmos */
62705b2298ff svgalib 1.9.18 compile fix, still wont work for me though...
atmos4
parents: 11455
diff changeset
32 #define SVGALIB_HELPER_IOCGPCIINL SVGAHELPER_PCIINL
62705b2298ff svgalib 1.9.18 compile fix, still wont work for me though...
atmos4
parents: 11455
diff changeset
33 #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
34 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
35 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
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 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
38 {
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 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
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
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 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
43 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
44 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
45 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
46 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
47 {
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 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
49 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
50
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.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
52 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
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 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
55 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
56
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 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
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
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 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
61 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
62 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
63 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
64 {
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 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
66 }
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 #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
68
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
69 static __inline__ int enable_os_io(void)
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
70 {
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
71 #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
72 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
73 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
74 {
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 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
76 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
77 }
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 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
79 #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
80
4474
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
81 #ifdef CONFIG_DHAHELPER
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
82 dhahelper_fd = open("/dev/dhahelper", O_RDWR);
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
83 if (dhahelper_fd > 0)
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
84 {
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
85 dhahelper_initialized = 1;
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
86 return(0);
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
87 }
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
88 dhahelper_initialized = -1;
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
89 #endif
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
90
7837
6d544beb655e libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents: 6613
diff changeset
91 #if defined(__powerpc__) && defined(__linux__)
6d544beb655e libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents: 6613
diff changeset
92 /* should be fixed? */
6d544beb655e libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents: 6613
diff changeset
93 #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
94 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
95 return(errno);
7837
6d544beb655e libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents: 6613
diff changeset
96 #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
97 return(0);
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
98 }
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
99
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
100 static __inline__ int disable_os_io(void)
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
101 {
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
102 #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
103 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
104 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
105 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
106 #endif
4474
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
107 #ifdef CONFIG_DHAHELPER
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
108 if (dhahelper_initialized == 1)
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
109 close(dhahelper_fd);
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
110 else
05ac3586db02 added support for dhahelper
alex
parents: 4174
diff changeset
111 #endif
7837
6d544beb655e libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents: 6613
diff changeset
112 #if defined(__powerpc__) && defined(__linux__)
6d544beb655e libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents: 6613
diff changeset
113 /* should be fixed? */
6d544beb655e libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents: 6613
diff changeset
114 #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
115 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
116 return(errno);
7837
6d544beb655e libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents: 6613
diff changeset
117 #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
118 return(0);
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
119 }
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
120
12687
cb35163ef0a1 x86-64 (amd64) support by Kenny Root
alex
parents: 12078
diff changeset
121 #if (defined(__powerpc__) || defined(__sparc__) || defined(__sparc64__) \
cb35163ef0a1 x86-64 (amd64) support by Kenny Root
alex
parents: 12078
diff changeset
122 || 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
123 #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
124 #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
125
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 #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
127 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
128
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 /* 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
130 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
131 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
132 #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
133 //#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
134 #include <linux/pci.h>
21372
1767c271d710 Remove bswap.h, use libavutil/bswap.h instead.
diego
parents: 17099
diff changeset
135 #include "libavutil/common.h"
21507
fa99b3d31d13 Hack around libavutil/bswap.h compilation problems due to always_inline undefined.
reimar
parents: 21372
diff changeset
136 #include "mpbswap.h"
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
137
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 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
139 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
140 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
141 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
142 {
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 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
144 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
145 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
146 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
147 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
148 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
149 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
150 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
151 }
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 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
153 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
154 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
155 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
156 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
157 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
158 } 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
159 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
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 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
162 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
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 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
165 }
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 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
168 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
169 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
170 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
171 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
172 {
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 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
174 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
175 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
176 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
177 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
178 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
179 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
180 }
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 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
182 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
183 } 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
184 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
185 }
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 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
187 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
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 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
190 }
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
191 #endif