Mercurial > mplayer.hg
comparison libdha/sysdep/pci_linux.c @ 8503:9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
author | alex |
---|---|
date | Fri, 20 Dec 2002 21:07:27 +0000 |
parents | d09c74452323 |
children | 22f8732b5d97 |
comparison
equal
deleted
inserted
replaced
8502:3158c0e8e7e1 | 8503:9dbb9c710480 |
---|---|
18 #include <fcntl.h> | 18 #include <fcntl.h> |
19 int dhahelper_initialized = 0; | 19 int dhahelper_initialized = 0; |
20 int dhahelper_fd = 0; | 20 int dhahelper_fd = 0; |
21 #endif | 21 #endif |
22 | 22 |
23 #ifdef CONFIG_SVGAHELPER | |
24 #include <svgalib_helper.h> | |
25 #ifdef __linux__ | |
26 #include <linux/ioctl.h> | |
27 #endif | |
28 #include <fcntl.h> | |
29 int svgahelper_initialized = 0; | |
30 int svgahelper_fd = 0; | |
31 | |
32 static int pci_config_type(void) | |
33 { | |
34 return 1; | |
35 } | |
36 | |
37 static long pci_config_read_long( | |
38 unsigned char bus, | |
39 unsigned char dev, | |
40 int func, | |
41 unsigned cmd) | |
42 { | |
43 unsigned long config_cmd; | |
44 pcic_t p; | |
45 | |
46 p.address = cmd; | |
47 p.pcipos = (bus << 8) | dev | (func << 5); | |
48 | |
49 if (ioctl(svgahelper_fd, SVGALIB_HELPER_IOCGPCIINL, &p)) | |
50 return -1; | |
51 | |
52 return p.val; | |
53 } | |
54 | |
55 static int pci_get_vendor( | |
56 unsigned char bus, | |
57 unsigned char dev, | |
58 int func) | |
59 { | |
60 return pci_config_read_long(bus, dev, func, 0); | |
61 } | |
62 #endif | |
63 | |
23 static __inline__ int enable_os_io(void) | 64 static __inline__ int enable_os_io(void) |
24 { | 65 { |
66 #ifdef CONFIG_SVGAHELPER | |
67 svgahelper_fd = open(DEV_SVGA, O_RDWR); | |
68 if (svgahelper_fd > 0) | |
69 { | |
70 svgahelper_initialized = 1; | |
71 return(0); | |
72 } | |
73 svgahelper_initialized = -1; | |
74 #endif | |
75 | |
25 #ifdef CONFIG_DHAHELPER | 76 #ifdef CONFIG_DHAHELPER |
26 dhahelper_fd = open("/dev/dhahelper", O_RDWR); | 77 dhahelper_fd = open("/dev/dhahelper", O_RDWR); |
27 if (dhahelper_fd > 0) | 78 if (dhahelper_fd > 0) |
28 { | 79 { |
29 dhahelper_initialized = 1; | 80 dhahelper_initialized = 1; |
41 return(0); | 92 return(0); |
42 } | 93 } |
43 | 94 |
44 static __inline__ int disable_os_io(void) | 95 static __inline__ int disable_os_io(void) |
45 { | 96 { |
97 #ifdef CONFIG_SVGAHELPER | |
98 if (svgahelper_initialized == 1) | |
99 close(svgahelper_fd); | |
100 else | |
101 #endif | |
46 #ifdef CONFIG_DHAHELPER | 102 #ifdef CONFIG_DHAHELPER |
47 if (dhahelper_initialized == 1) | 103 if (dhahelper_initialized == 1) |
48 close(dhahelper_fd); | 104 close(dhahelper_fd); |
49 else | 105 else |
50 #endif | 106 #endif |
54 if (iopl(0) != 0) | 110 if (iopl(0) != 0) |
55 return(errno); | 111 return(errno); |
56 #endif | 112 #endif |
57 return(0); | 113 return(0); |
58 } | 114 } |
115 | |
116 #if (defined(__powerpc__) || defined(__sparc__) || defined(__sparc64__)) \ | |
117 && defined(__linux__) && !defined(CONFIG_SVGAHELPER) | |
118 #define CONFIG_PCI_LINUX_PROC | |
119 #endif | |
120 | |
121 #if defined(CONFIG_PCI_LINUX_PROC) | |
122 static int pci_config_type( void ) { return 1; } | |
123 | |
124 /* pci operations for (powerpc) Linux | |
125 questions, suggestions etc: | |
126 mplayer-dev-eng@mplayerhq.hu, colin@colino.net*/ | |
127 #include <fcntl.h> | |
128 //#include <sys/io.h> | |
129 #include <linux/pci.h> | |
130 #include "../../bswap.h" | |
131 | |
132 static int pci_get_vendor( | |
133 unsigned char bus, | |
134 unsigned char dev, | |
135 int func) | |
136 { | |
137 int retval; | |
138 char path[100]; | |
139 int fd; | |
140 short vendor, device; | |
141 sprintf(path,"/proc/bus/pci/%02d/%02x.0", bus, dev); | |
142 fd = open(path,O_RDONLY|O_SYNC); | |
143 if (fd == -1) { | |
144 retval=0xFFFF; | |
145 } | |
146 else if (pread(fd, &vendor, 2, PCI_VENDOR_ID) == 2 && | |
147 pread(fd, &device, 2, PCI_DEVICE_ID) == 2) { | |
148 vendor = le2me_16(vendor); | |
149 device = le2me_16(device); | |
150 retval = vendor + (device<<16); /*no worries about byte order, | |
151 all ppc are bigendian*/ | |
152 } else { | |
153 retval = 0xFFFF; | |
154 } | |
155 if (fd > 0) { | |
156 close(fd); | |
157 } | |
158 return retval; | |
159 } | |
160 | |
161 static long pci_config_read_long( | |
162 unsigned char bus, | |
163 unsigned char dev, | |
164 int func, | |
165 unsigned cmd) | |
166 { | |
167 long retval; | |
168 char path[100]; | |
169 int fd; | |
170 sprintf(path,"/proc/bus/pci/%02d/%02x.0", bus, dev); | |
171 fd = open(path,O_RDONLY|O_SYNC); | |
172 if (fd == -1) { | |
173 retval=0; | |
174 } | |
175 else if (pread(fd, &retval, 4, cmd) == 4) { | |
176 retval = le2me_32(retval); | |
177 } else { | |
178 retval = 0; | |
179 } | |
180 if (fd > 0) { | |
181 close(fd); | |
182 } | |
183 return retval; | |
184 } | |
185 #endif |