Mercurial > mplayer.hg
annotate libdha/pci.c @ 8637:0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
patch by Andreas Hess <jaska@gmx.net>
author | arpi |
---|---|
date | Sun, 29 Dec 2002 15:32:56 +0000 |
parents | 9dbb9c710480 |
children | 298208d7a703 |
rev | line source |
---|---|
3973 | 1 /* |
2 (C) 2002 - library implementation by Nick Kyrshev | |
3 XFree86 3.3.3 scanpci.c, modified for GATOS/win/gfxdump by Øyvind Aabling. | |
4 */ | |
5 /* $XConsortium: scanpci.c /main/25 1996/10/27 11:48:40 kaleb $ */ | |
6 /* | |
7 * name: scanpci.c | |
8 * | |
9 * purpose: This program will scan for and print details of | |
10 * devices on the PCI bus. | |
11 | |
12 * author: Robin Cutshaw (robin@xfree86.org) | |
13 * | |
14 * supported O/S's: SVR4, UnixWare, SCO, Solaris, | |
15 * FreeBSD, NetBSD, 386BSD, BSDI BSD/386, | |
16 * Linux, Mach/386, ISC | |
17 * DOS (WATCOM 9.5 compiler) | |
18 * | |
19 * compiling: [g]cc scanpci.c -o scanpci | |
20 * for SVR4 (not Solaris), UnixWare use: | |
21 * [g]cc -DSVR4 scanpci.c -o scanpci | |
22 * for DOS, watcom 9.5: | |
23 * wcc386p -zq -omaxet -7 -4s -s -w3 -d2 name.c | |
24 * and link with PharLap or other dos extender for exe | |
25 * | |
26 */ | |
27 | |
28 /* $XFree86: xc/programs/Xserver/hw/xfree86/etc/scanpci.c,v 3.34.2.17 1998/11/10 11:55:40 dawes Exp $ */ | |
29 | |
30 /* | |
31 * Copyright 1995 by Robin Cutshaw <robin@XFree86.Org> | |
32 * | |
33 * Permission to use, copy, modify, distribute, and sell this software and its | |
34 * documentation for any purpose is hereby granted without fee, provided that | |
35 * the above copyright notice appear in all copies and that both that | |
36 * copyright notice and this permission notice appear in supporting | |
37 * documentation, and that the names of the above listed copyright holder(s) | |
38 * not be used in advertising or publicity pertaining to distribution of | |
39 * the software without specific, written prior permission. The above listed | |
40 * copyright holder(s) make(s) no representations about the suitability of this | |
41 * software for any purpose. It is provided "as is" without express or | |
42 * implied warranty. | |
43 * | |
44 * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM(S) ALL WARRANTIES WITH REGARD | |
45 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | |
46 * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE | |
47 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY | |
48 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER | |
49 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING | |
50 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
51 * | |
52 */ | |
53 | |
4164 | 54 #include "libdha.h" |
55 #include <errno.h> | |
56 #include <string.h> | |
57 #include <stdio.h> | |
58 #ifdef __unix__ | |
59 #include <unistd.h> | |
60 #endif | |
61 #include "AsmMacros.h" | |
62 /* OS depended stuff */ | |
63 #if defined (linux) | |
64 #include "sysdep/pci_linux.c" | |
65 #elif defined (__FreeBSD__) | |
66 #include "sysdep/pci_freebsd.c" | |
67 #elif defined (__386BSD__) | |
68 #include "sysdep/pci_386bsd.c" | |
69 #elif defined (__NetBSD__) | |
70 #include "sysdep/pci_netbsd.c" | |
71 #elif defined (__OpenBSD__) | |
72 #include "sysdep/pci_openbsd.c" | |
73 #elif defined (__bsdi__) | |
74 #include "sysdep/pci_bsdi.c" | |
75 #elif defined (Lynx) | |
76 #include "sysdep/pci_lynx.c" | |
77 #elif defined (MACH386) | |
78 #include "sysdep/pci_mach386.c" | |
79 #elif defined (__SVR4) | |
3973 | 80 #if !defined(SVR4) |
81 #define SVR4 | |
82 #endif | |
4164 | 83 #include "sysdep/pci_svr4.c" |
84 #elif defined (SCO) | |
85 #include "sysdep/pci_sco.c" | |
86 #elif defined (ISC) | |
87 #include "sysdep/pci_isc.c" | |
88 #elif defined (__EMX__) | |
89 #include "sysdep/pci_os2.c" | |
4173 | 90 #elif defined (_WIN32) || defined(__CYGWIN__) |
4164 | 91 #include "sysdep/pci_win32.c" |
3973 | 92 #endif |
4164 | 93 |
94 #if 0 | |
3973 | 95 #if defined(__SUNPRO_C) || defined(sun) || defined(__sun) |
96 #include <sys/psw.h> | |
97 #else | |
98 #include <sys/seg.h> | |
99 #endif | |
100 #include <sys/v86.h> | |
101 #endif | |
102 | |
103 #if defined(Lynx) && defined(__powerpc__) | |
104 /* let's mimick the Linux Alpha stuff for LynxOS so we don't have | |
105 * to change too much code | |
106 */ | |
107 #include <smem.h> | |
108 | |
109 static unsigned char *pciConfBase; | |
110 | |
111 static __inline__ unsigned long | |
112 static swapl(unsigned long val) | |
113 { | |
114 unsigned char *p = (unsigned char *)&val; | |
115 return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | (p[0] << 0)); | |
116 } | |
117 | |
118 | |
119 #define BUS(tag) (((tag)>>16)&0xff) | |
120 #define DFN(tag) (((tag)>>8)&0xff) | |
121 | |
122 #define PCIBIOS_DEVICE_NOT_FOUND 0x86 | |
123 #define PCIBIOS_SUCCESSFUL 0x00 | |
124 | |
4174
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
125 int pciconfig_read( |
3973 | 126 unsigned char bus, |
127 unsigned char dev, | |
128 unsigned char offset, | |
129 int len, /* unused, alway 4 */ | |
130 unsigned long *val) | |
131 { | |
132 unsigned long _val; | |
133 unsigned long *ptr; | |
134 | |
135 dev >>= 3; | |
136 if (bus || dev >= 16) { | |
137 *val = 0xFFFFFFFF; | |
138 return PCIBIOS_DEVICE_NOT_FOUND; | |
139 } else { | |
140 ptr = (unsigned long *)(pciConfBase + ((1<<dev) | offset)); | |
141 _val = swapl(*ptr); | |
142 } | |
143 *val = _val; | |
144 return PCIBIOS_SUCCESSFUL; | |
145 } | |
146 | |
4174
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
147 int pciconfig_write( |
3973 | 148 unsigned char bus, |
149 unsigned char dev, | |
150 unsigned char offset, | |
151 int len, /* unused, alway 4 */ | |
152 unsigned long val) | |
153 { | |
154 unsigned long _val; | |
155 unsigned long *ptr; | |
156 | |
157 dev >>= 3; | |
158 _val = swapl(val); | |
159 if (bus || dev >= 16) { | |
160 return PCIBIOS_DEVICE_NOT_FOUND; | |
161 } else { | |
162 ptr = (unsigned long *)(pciConfBase + ((1<<dev) | offset)); | |
163 *ptr = _val; | |
164 } | |
165 return PCIBIOS_SUCCESSFUL; | |
166 } | |
167 #endif | |
168 | |
169 #if !defined(__powerpc__) | |
170 struct pci_config_reg { | |
171 /* start of official PCI config space header */ | |
172 union { | |
173 unsigned long device_vendor; | |
174 struct { | |
175 unsigned short vendor; | |
176 unsigned short device; | |
177 } dv; | |
178 } dv_id; | |
179 #define _device_vendor dv_id.device_vendor | |
180 #define _vendor dv_id.dv.vendor | |
181 #define _device dv_id.dv.device | |
182 union { | |
183 unsigned long status_command; | |
184 struct { | |
185 unsigned short command; | |
186 unsigned short status; | |
187 } sc; | |
188 } stat_cmd; | |
189 #define _status_command stat_cmd.status_command | |
190 #define _command stat_cmd.sc.command | |
191 #define _status stat_cmd.sc.status | |
192 union { | |
193 unsigned long class_revision; | |
194 struct { | |
195 unsigned char rev_id; | |
196 unsigned char prog_if; | |
197 unsigned char sub_class; | |
198 unsigned char base_class; | |
199 } cr; | |
200 } class_rev; | |
201 #define _class_revision class_rev.class_revision | |
202 #define _rev_id class_rev.cr.rev_id | |
203 #define _prog_if class_rev.cr.prog_if | |
204 #define _sub_class class_rev.cr.sub_class | |
205 #define _base_class class_rev.cr.base_class | |
206 union { | |
207 unsigned long bist_header_latency_cache; | |
208 struct { | |
209 unsigned char cache_line_size; | |
210 unsigned char latency_timer; | |
211 unsigned char header_type; | |
212 unsigned char bist; | |
213 } bhlc; | |
214 } bhlc; | |
215 #define _bist_header_latency_cache bhlc.bist_header_latency_cache | |
216 #define _cache_line_size bhlc.bhlc.cache_line_size | |
217 #define _latency_timer bhlc.bhlc.latency_timer | |
218 #define _header_type bhlc.bhlc.header_type | |
219 #define _bist bhlc.bhlc.bist | |
220 union { | |
221 struct { | |
222 unsigned long dv_base0; | |
223 unsigned long dv_base1; | |
224 unsigned long dv_base2; | |
225 unsigned long dv_base3; | |
226 unsigned long dv_base4; | |
227 unsigned long dv_base5; | |
228 } dv; | |
229 struct { | |
230 unsigned long bg_rsrvd[2]; | |
231 unsigned char primary_bus_number; | |
232 unsigned char secondary_bus_number; | |
233 unsigned char subordinate_bus_number; | |
234 unsigned char secondary_latency_timer; | |
235 unsigned char io_base; | |
236 unsigned char io_limit; | |
237 unsigned short secondary_status; | |
238 unsigned short mem_base; | |
239 unsigned short mem_limit; | |
240 unsigned short prefetch_mem_base; | |
241 unsigned short prefetch_mem_limit; | |
242 } bg; | |
243 } bc; | |
244 #define _base0 bc.dv.dv_base0 | |
245 #define _base1 bc.dv.dv_base1 | |
246 #define _base2 bc.dv.dv_base2 | |
247 #define _base3 bc.dv.dv_base3 | |
248 #define _base4 bc.dv.dv_base4 | |
249 #define _base5 bc.dv.dv_base5 | |
250 #define _primary_bus_number bc.bg.primary_bus_number | |
251 #define _secondary_bus_number bc.bg.secondary_bus_number | |
252 #define _subordinate_bus_number bc.bg.subordinate_bus_number | |
253 #define _secondary_latency_timer bc.bg.secondary_latency_timer | |
254 #define _io_base bc.bg.io_base | |
255 #define _io_limit bc.bg.io_limit | |
256 #define _secondary_status bc.bg.secondary_status | |
257 #define _mem_base bc.bg.mem_base | |
258 #define _mem_limit bc.bg.mem_limit | |
259 #define _prefetch_mem_base bc.bg.prefetch_mem_base | |
260 #define _prefetch_mem_limit bc.bg.prefetch_mem_limit | |
261 unsigned long rsvd1; | |
262 unsigned long rsvd2; | |
263 unsigned long _baserom; | |
264 unsigned long rsvd3; | |
265 unsigned long rsvd4; | |
266 union { | |
267 unsigned long max_min_ipin_iline; | |
268 struct { | |
269 unsigned char int_line; | |
270 unsigned char int_pin; | |
271 unsigned char min_gnt; | |
272 unsigned char max_lat; | |
273 } mmii; | |
274 } mmii; | |
275 #define _max_min_ipin_iline mmii.max_min_ipin_iline | |
276 #define _int_line mmii.mmii.int_line | |
277 #define _int_pin mmii.mmii.int_pin | |
278 #define _min_gnt mmii.mmii.min_gnt | |
279 #define _max_lat mmii.mmii.max_lat | |
280 /* I don't know how accurate or standard this is (DHD) */ | |
281 union { | |
282 unsigned long user_config; | |
283 struct { | |
284 unsigned char user_config_0; | |
285 unsigned char user_config_1; | |
286 unsigned char user_config_2; | |
287 unsigned char user_config_3; | |
288 } uc; | |
289 } uc; | |
290 #define _user_config uc.user_config | |
291 #define _user_config_0 uc.uc.user_config_0 | |
292 #define _user_config_1 uc.uc.user_config_1 | |
293 #define _user_config_2 uc.uc.user_config_2 | |
294 #define _user_config_3 uc.uc.user_config_3 | |
295 /* end of official PCI config space header */ | |
296 unsigned long _pcibusidx; | |
297 unsigned long _pcinumbus; | |
298 unsigned long _pcibuses[16]; | |
299 unsigned short _configtype; /* config type found */ | |
300 unsigned short _ioaddr; /* config type 1 - private I/O addr */ | |
301 unsigned long _cardnum; /* config type 2 - private card number */ | |
302 }; | |
303 #else | |
304 /* ppc is big endian, swapping bytes is not quite enough | |
305 * to interpret the PCI config registers... | |
306 */ | |
307 struct pci_config_reg { | |
308 /* start of official PCI config space header */ | |
309 union { | |
310 unsigned long device_vendor; | |
311 struct { | |
312 unsigned short device; | |
313 unsigned short vendor; | |
314 } dv; | |
315 } dv_id; | |
316 #define _device_vendor dv_id.device_vendor | |
317 #define _vendor dv_id.dv.vendor | |
318 #define _device dv_id.dv.device | |
319 union { | |
320 unsigned long status_command; | |
321 struct { | |
322 unsigned short status; | |
323 unsigned short command; | |
324 } sc; | |
325 } stat_cmd; | |
326 #define _status_command stat_cmd.status_command | |
327 #define _command stat_cmd.sc.command | |
328 #define _status stat_cmd.sc.status | |
329 union { | |
330 unsigned long class_revision; | |
331 struct { | |
332 unsigned char base_class; | |
333 unsigned char sub_class; | |
334 unsigned char prog_if; | |
335 unsigned char rev_id; | |
336 } cr; | |
337 } class_rev; | |
338 #define _class_revision class_rev.class_revision | |
339 #define _rev_id class_rev.cr.rev_id | |
340 #define _prog_if class_rev.cr.prog_if | |
341 #define _sub_class class_rev.cr.sub_class | |
342 #define _base_class class_rev.cr.base_class | |
343 union { | |
344 unsigned long bist_header_latency_cache; | |
345 struct { | |
346 unsigned char bist; | |
347 unsigned char header_type; | |
348 unsigned char latency_timer; | |
349 unsigned char cache_line_size; | |
350 } bhlc; | |
351 } bhlc; | |
352 #define _bist_header_latency_cache bhlc.bist_header_latency_cache | |
353 #define _cache_line_size bhlc.bhlc.cache_line_size | |
354 #define _latency_timer bhlc.bhlc.latency_timer | |
355 #define _header_type bhlc.bhlc.header_type | |
356 #define _bist bhlc.bhlc.bist | |
357 union { | |
358 struct { | |
359 unsigned long dv_base0; | |
360 unsigned long dv_base1; | |
361 unsigned long dv_base2; | |
362 unsigned long dv_base3; | |
363 unsigned long dv_base4; | |
364 unsigned long dv_base5; | |
365 } dv; | |
366 /* ?? */ | |
367 struct { | |
368 unsigned long bg_rsrvd[2]; | |
369 | |
370 unsigned char secondary_latency_timer; | |
371 unsigned char subordinate_bus_number; | |
372 unsigned char secondary_bus_number; | |
373 unsigned char primary_bus_number; | |
374 | |
375 unsigned short secondary_status; | |
376 unsigned char io_limit; | |
377 unsigned char io_base; | |
378 | |
379 unsigned short mem_limit; | |
380 unsigned short mem_base; | |
381 | |
382 unsigned short prefetch_mem_limit; | |
383 unsigned short prefetch_mem_base; | |
384 } bg; | |
385 } bc; | |
386 #define _base0 bc.dv.dv_base0 | |
387 #define _base1 bc.dv.dv_base1 | |
388 #define _base2 bc.dv.dv_base2 | |
389 #define _base3 bc.dv.dv_base3 | |
390 #define _base4 bc.dv.dv_base4 | |
391 #define _base5 bc.dv.dv_base5 | |
392 #define _primary_bus_number bc.bg.primary_bus_number | |
393 #define _secondary_bus_number bc.bg.secondary_bus_number | |
394 #define _subordinate_bus_number bc.bg.subordinate_bus_number | |
395 #define _secondary_latency_timer bc.bg.secondary_latency_timer | |
396 #define _io_base bc.bg.io_base | |
397 #define _io_limit bc.bg.io_limit | |
398 #define _secondary_status bc.bg.secondary_status | |
399 #define _mem_base bc.bg.mem_base | |
400 #define _mem_limit bc.bg.mem_limit | |
401 #define _prefetch_mem_base bc.bg.prefetch_mem_base | |
402 #define _prefetch_mem_limit bc.bg.prefetch_mem_limit | |
403 unsigned long rsvd1; | |
404 unsigned long rsvd2; | |
405 unsigned long _baserom; | |
406 unsigned long rsvd3; | |
407 unsigned long rsvd4; | |
408 union { | |
409 unsigned long max_min_ipin_iline; | |
410 struct { | |
411 unsigned char max_lat; | |
412 unsigned char min_gnt; | |
413 unsigned char int_pin; | |
414 unsigned char int_line; | |
415 } mmii; | |
416 } mmii; | |
417 #define _max_min_ipin_iline mmii.max_min_ipin_iline | |
418 #define _int_line mmii.mmii.int_line | |
419 #define _int_pin mmii.mmii.int_pin | |
420 #define _min_gnt mmii.mmii.min_gnt | |
421 #define _max_lat mmii.mmii.max_lat | |
422 /* I don't know how accurate or standard this is (DHD) */ | |
423 union { | |
424 unsigned long user_config; | |
425 struct { | |
426 unsigned char user_config_3; | |
427 unsigned char user_config_2; | |
428 unsigned char user_config_1; | |
429 unsigned char user_config_0; | |
430 } uc; | |
431 } uc; | |
432 #define _user_config uc.user_config | |
433 #define _user_config_0 uc.uc.user_config_0 | |
434 #define _user_config_1 uc.uc.user_config_1 | |
435 #define _user_config_2 uc.uc.user_config_2 | |
436 #define _user_config_3 uc.uc.user_config_3 | |
437 /* end of official PCI config space header */ | |
438 unsigned long _pcibusidx; | |
439 unsigned long _pcinumbus; | |
440 unsigned long _pcibuses[16]; | |
441 unsigned short _ioaddr; /* config type 1 - private I/O addr */ | |
442 unsigned short _configtype; /* config type found */ | |
443 unsigned long _cardnum; /* config type 2 - private card number */ | |
444 }; | |
445 #endif | |
446 | |
447 #define MAX_DEV_PER_VENDOR_CFG1 64 | |
448 #define MAX_PCI_DEVICES_PER_BUS 32 | |
449 #define MAX_PCI_DEVICES 64 | |
450 #define NF ((void (*)())NULL), { 0.0, 0, 0, NULL } | |
451 #define PCI_MULTIFUNC_DEV 0x80 | |
452 #define PCI_ID_REG 0x00 | |
453 #define PCI_CMD_STAT_REG 0x04 | |
454 #define PCI_CLASS_REG 0x08 | |
455 #define PCI_HEADER_MISC 0x0C | |
456 #define PCI_MAP_REG_START 0x10 | |
457 #define PCI_MAP_ROM_REG 0x30 | |
458 #define PCI_INTERRUPT_REG 0x3C | |
459 #define PCI_REG_USERCONFIG 0x40 | |
460 | |
461 static int pcibus=-1, pcicard=-1, pcifunc=-1 ; | |
462 /*static struct pci_device *pcidev=NULL ;*/ | |
463 | |
464 #if defined(__alpha__) | |
465 #define PCI_EN 0x00000000 | |
466 #else | |
467 #define PCI_EN 0x80000000 | |
468 #endif | |
469 | |
470 #define PCI_MODE1_ADDRESS_REG 0xCF8 | |
471 #define PCI_MODE1_DATA_REG 0xCFC | |
472 | |
473 #define PCI_MODE2_ENABLE_REG 0xCF8 | |
474 #ifdef PC98 | |
475 #define PCI_MODE2_FORWARD_REG 0xCF9 | |
476 #else | |
477 #define PCI_MODE2_FORWARD_REG 0xCFA | |
478 #endif | |
4164 | 479 |
480 /* cpu depended stuff */ | |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
481 #ifndef CONFIG_SVGAHELPER |
4164 | 482 #if defined(__alpha__) |
483 #include "sysdep/pci_alpha.c" | |
484 #elif defined(__ia64__) | |
485 #include "sysdep/pci_ia64.c" | |
486 #elif defined(__sparc__) | |
487 #include "sysdep/pci_sparc.c" | |
488 #elif defined( __arm32__ ) | |
489 #include "sysdep/pci_arm32.c" | |
490 #elif defined(__powerpc__) | |
491 #include "sysdep/pci_powerpc.c" | |
492 #else | |
493 #include "sysdep/pci_x86.c" | |
494 #endif | |
8503
9dbb9c710480
svgalib kernelhelper support (based on patch by Matan Ziv-Av <matan@svgalib.org>) and some reordering/cleanup (part #1 ;)
alex
parents:
5702
diff
changeset
|
495 #endif |
3973 | 496 |
497 static int pcicards=0 ; | |
498 static pciinfo_t *pci_lst; | |
499 | |
500 static void identify_card(struct pci_config_reg *pcr) | |
501 { | |
502 | |
503 if (pcicards>=MAX_PCI_DEVICES) return ; | |
504 | |
505 pci_lst[pcicards].bus = pcibus ; | |
506 pci_lst[pcicards].card = pcicard ; | |
507 pci_lst[pcicards].func = pcifunc ; | |
508 pci_lst[pcicards].vendor = pcr->_vendor ; | |
509 pci_lst[pcicards].device = pcr->_device ; | |
510 pci_lst[pcicards].base0 = 0xFFFFFFFF ; | |
511 pci_lst[pcicards].base1 = 0xFFFFFFFF ; | |
512 pci_lst[pcicards].base2 = 0xFFFFFFFF ; | |
513 pci_lst[pcicards].baserom = 0x000C0000 ; | |
514 if (pcr->_base0) pci_lst[pcicards].base0 = pcr->_base0 & | |
515 ((pcr->_base0&0x1) ? 0xFFFFFFFC : 0xFFFFFFF0) ; | |
516 if (pcr->_base1) pci_lst[pcicards].base1 = pcr->_base1 & | |
517 ((pcr->_base1&0x1) ? 0xFFFFFFFC : 0xFFFFFFF0) ; | |
518 if (pcr->_base2) pci_lst[pcicards].base2 = pcr->_base2 & | |
519 ((pcr->_base2&0x1) ? 0xFFFFFFFC : 0xFFFFFFF0) ; | |
520 if (pcr->_baserom) pci_lst[pcicards].baserom = pcr->_baserom ; | |
521 | |
522 pcicards++; | |
523 } | |
524 | |
525 /*main(int argc, char *argv[])*/ | |
526 int pci_scan(pciinfo_t *pci_list,unsigned *num_pci) | |
527 { | |
528 unsigned int idx; | |
529 struct pci_config_reg pcr; | |
530 int do_mode1_scan = 0, do_mode2_scan = 0; | |
531 int func, hostbridges=0; | |
4174
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
532 int ret = -1; |
3973 | 533 |
534 pci_lst = pci_list; | |
535 | |
4174
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
536 ret = enable_os_io(); |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
537 if (ret != 0) |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
538 return(ret); |
4164 | 539 |
540 if((pcr._configtype = pci_config_type()) == 0xFFFF) return ENODEV; | |
3973 | 541 |
542 /* Try pci config 1 probe first */ | |
543 | |
544 if ((pcr._configtype == 1) || do_mode1_scan) { | |
545 /*printf("\nPCI probing configuration type 1\n");*/ | |
546 | |
547 pcr._ioaddr = 0xFFFF; | |
548 | |
549 pcr._pcibuses[0] = 0; | |
550 pcr._pcinumbus = 1; | |
551 pcr._pcibusidx = 0; | |
552 idx = 0; | |
553 | |
554 do { | |
555 /*printf("Probing for devices on PCI bus %d:\n\n", pcr._pcibusidx);*/ | |
556 | |
557 for (pcr._cardnum = 0x0; pcr._cardnum < MAX_PCI_DEVICES_PER_BUS; | |
558 pcr._cardnum += 0x1) { | |
559 func = 0; | |
560 do { /* loop over the different functions, if present */ | |
4164 | 561 pcr._device_vendor = pci_get_vendor(pcr._pcibuses[pcr._pcibusidx], pcr._cardnum, |
562 func); | |
3973 | 563 if ((pcr._vendor == 0xFFFF) || (pcr._device == 0xFFFF)) |
564 break; /* nothing there */ | |
565 | |
566 /*printf("\npci bus 0x%x cardnum 0x%02x function 0x%04x: vendor 0x%04x device 0x%04x\n", | |
567 pcr._pcibuses[pcr._pcibusidx], pcr._cardnum, func, | |
568 pcr._vendor, pcr._device);*/ | |
4164 | 569 pcibus = pcr._pcibuses[pcr._pcibusidx]; |
570 pcicard = pcr._cardnum; | |
571 pcifunc = func; | |
3973 | 572 |
4164 | 573 pcr._status_command = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx], |
574 pcr._cardnum,func,PCI_CMD_STAT_REG); | |
575 pcr._class_revision = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx], | |
576 pcr._cardnum,func,PCI_CLASS_REG); | |
577 pcr._bist_header_latency_cache = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx], | |
578 pcr._cardnum,func,PCI_HEADER_MISC); | |
579 pcr._base0 = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx], | |
580 pcr._cardnum,func,PCI_MAP_REG_START); | |
581 pcr._base1 = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx], | |
582 pcr._cardnum,func,PCI_MAP_REG_START+4); | |
583 pcr._base2 = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx], | |
584 pcr._cardnum,func,PCI_MAP_REG_START+8); | |
585 pcr._base3 = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx], | |
586 pcr._cardnum,func,PCI_MAP_REG_START+0x0C); | |
587 pcr._base4 = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx], | |
588 pcr._cardnum,func,PCI_MAP_REG_START+0x10); | |
589 pcr._base5 = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx], | |
590 pcr._cardnum,func,PCI_MAP_REG_START+0x14); | |
591 pcr._baserom = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx], | |
592 pcr._cardnum,func,PCI_MAP_ROM_REG); | |
593 pcr._max_min_ipin_iline = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx], | |
594 pcr._cardnum,func,PCI_INTERRUPT_REG); | |
595 pcr._user_config = pci_config_read_long(pcr._pcibuses[pcr._pcibusidx], | |
596 pcr._cardnum,func,PCI_REG_USERCONFIG); | |
3973 | 597 /* check for pci-pci bridges */ |
598 #define PCI_CLASS_MASK 0xff000000 | |
599 #define PCI_SUBCLASS_MASK 0x00ff0000 | |
600 #define PCI_CLASS_BRIDGE 0x06000000 | |
601 #define PCI_SUBCLASS_BRIDGE_PCI 0x00040000 | |
602 switch(pcr._class_revision & (PCI_CLASS_MASK|PCI_SUBCLASS_MASK)) { | |
603 case PCI_CLASS_BRIDGE|PCI_SUBCLASS_BRIDGE_PCI: | |
604 if (pcr._secondary_bus_number > 0) { | |
605 pcr._pcibuses[pcr._pcinumbus++] = pcr._secondary_bus_number; | |
606 } | |
607 break; | |
608 case PCI_CLASS_BRIDGE: | |
609 if ( ++hostbridges > 1) { | |
610 pcr._pcibuses[pcr._pcinumbus] = pcr._pcinumbus; | |
611 pcr._pcinumbus++; | |
612 } | |
613 break; | |
614 default: | |
615 break; | |
616 } | |
617 if((func==0) && ((pcr._header_type & PCI_MULTIFUNC_DEV) == 0)) { | |
618 /* not a multi function device */ | |
619 func = 8; | |
620 } else { | |
621 func++; | |
622 } | |
623 | |
624 if (idx++ >= MAX_PCI_DEVICES) | |
625 continue; | |
626 | |
627 identify_card(&pcr); | |
628 } while( func < 8 ); | |
629 } | |
630 } while (++pcr._pcibusidx < pcr._pcinumbus); | |
631 } | |
632 | |
633 #if !defined(__alpha__) && !defined(__powerpc__) | |
634 /* Now try pci config 2 probe (deprecated) */ | |
635 | |
636 if ((pcr._configtype == 2) || do_mode2_scan) { | |
637 outb(PCI_MODE2_ENABLE_REG, 0xF1); | |
638 outb(PCI_MODE2_FORWARD_REG, 0x00); /* bus 0 for now */ | |
639 | |
640 /*printf("\nPCI probing configuration type 2\n");*/ | |
641 | |
642 pcr._pcibuses[0] = 0; | |
643 pcr._pcinumbus = 1; | |
644 pcr._pcibusidx = 0; | |
645 idx = 0; | |
646 | |
647 do { | |
648 for (pcr._ioaddr = 0xC000; pcr._ioaddr < 0xD000; pcr._ioaddr += 0x0100){ | |
649 outb(PCI_MODE2_FORWARD_REG, pcr._pcibuses[pcr._pcibusidx]); /* bus 0 for now */ | |
650 pcr._device_vendor = inl(pcr._ioaddr); | |
651 outb(PCI_MODE2_FORWARD_REG, 0x00); /* bus 0 for now */ | |
652 | |
653 if ((pcr._vendor == 0xFFFF) || (pcr._device == 0xFFFF)) | |
654 continue; | |
655 if ((pcr._vendor == 0xF0F0) || (pcr._device == 0xF0F0)) | |
656 continue; /* catch ASUS P55TP4XE motherboards */ | |
657 | |
658 /*printf("\npci bus 0x%x slot at 0x%04x, vendor 0x%04x device 0x%04x\n", | |
659 pcr._pcibuses[pcr._pcibusidx], pcr._ioaddr, pcr._vendor, | |
660 pcr._device);*/ | |
661 pcibus = pcr._pcibuses[pcr._pcibusidx] ; | |
662 pcicard = pcr._ioaddr ; pcifunc = 0 ; | |
663 | |
664 outb(PCI_MODE2_FORWARD_REG, pcr._pcibuses[pcr._pcibusidx]); /* bus 0 for now */ | |
665 pcr._status_command = inl(pcr._ioaddr + 0x04); | |
666 pcr._class_revision = inl(pcr._ioaddr + 0x08); | |
667 pcr._bist_header_latency_cache = inl(pcr._ioaddr + 0x0C); | |
668 pcr._base0 = inl(pcr._ioaddr + 0x10); | |
669 pcr._base1 = inl(pcr._ioaddr + 0x14); | |
670 pcr._base2 = inl(pcr._ioaddr + 0x18); | |
671 pcr._base3 = inl(pcr._ioaddr + 0x1C); | |
672 pcr._base4 = inl(pcr._ioaddr + 0x20); | |
673 pcr._base5 = inl(pcr._ioaddr + 0x24); | |
674 pcr._baserom = inl(pcr._ioaddr + 0x30); | |
675 pcr._max_min_ipin_iline = inl(pcr._ioaddr + 0x3C); | |
676 pcr._user_config = inl(pcr._ioaddr + 0x40); | |
677 outb(PCI_MODE2_FORWARD_REG, 0x00); /* bus 0 for now */ | |
678 | |
679 /* check for pci-pci bridges (currently we only know Digital) */ | |
680 if ((pcr._vendor == 0x1011) && (pcr._device == 0x0001)) | |
681 if (pcr._secondary_bus_number > 0) | |
682 pcr._pcibuses[pcr._pcinumbus++] = pcr._secondary_bus_number; | |
683 | |
684 if (idx++ >= MAX_PCI_DEVICES) | |
685 continue; | |
686 | |
687 identify_card(&pcr); | |
688 } | |
689 } while (++pcr._pcibusidx < pcr._pcinumbus); | |
690 | |
691 outb(PCI_MODE2_ENABLE_REG, 0x00); | |
692 } | |
693 | |
694 #endif /* __alpha__ */ | |
695 | |
696 disable_os_io(); | |
697 *num_pci = pcicards; | |
698 | |
699 return 0 ; | |
700 | |
701 } | |
4174
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
702 |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
703 #if !defined(ENOTSUP) |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
704 #if defined(EOPNOTSUPP) |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
705 #define ENOTSUP EOPNOTSUPP |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
706 #else |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
707 #warning "ENOTSUP nor EOPNOTSUPP defined!" |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
708 #endif |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
709 #endif |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
710 |
4277 | 711 int pci_config_read(unsigned char bus, unsigned char dev, unsigned char func, |
712 unsigned char cmd, int len, unsigned long *val) | |
4174
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
713 { |
4277 | 714 int ret; |
715 | |
4174
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
716 if (len != 4) |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
717 { |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
718 printf("pci_config_read: reading non-dword not supported!\n"); |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
719 return(ENOTSUP); |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
720 } |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
721 |
4277 | 722 ret = enable_os_io(); |
723 if (ret != 0) | |
724 return(ret); | |
725 ret = pci_config_read_long(bus, dev, func, cmd); | |
726 disable_os_io(); | |
727 | |
728 *val = ret; | |
4174
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
729 return(0); |
4cfb6b9a6da3
api changed: enable/disable_os_io returns error-code (or zero if ok) and pciconfig_read exported for mga_vid
alex
parents:
4173
diff
changeset
|
730 } |
4192 | 731 |
732 int enable_app_io( void ) | |
733 { | |
734 return enable_os_io(); | |
735 } | |
736 | |
737 int disable_app_io( void ) | |
738 { | |
739 return disable_os_io(); | |
5702 | 740 } |