Mercurial > mplayer.hg
annotate libdha/sysdep/pci_powerpc.c @ 8308:6ea0feac9d42
add stop_xscreensaver
author | pontscho |
---|---|
date | Thu, 28 Nov 2002 21:34:14 +0000 |
parents | 6d544beb655e |
children | d09c74452323 |
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 */ | |
6 | |
7 static int pci_config_type( void ) { return 1; } | |
8 | |
7837
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
9 #if defined(__powerpc__) && defined(__linux__) |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
10 /* pci operations for powerpc Linux |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
11 questions, suggestions etc: |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
12 mplayer-dev-eng@mplayerhq.hu, colin@colino.net*/ |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
13 #include <fcntl.h> |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
14 #include <sys/io.h> |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
15 #include <linux/pci.h> |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
16 #include "../../bswap.h" |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
17 |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
18 static int pci_get_vendor( |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
19 unsigned char bus, |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
20 unsigned char dev, |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
21 int func) |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
22 { |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
23 int retval; |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
24 char path[100]; |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
25 int fd; |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
26 short vendor, device; |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
27 sprintf(path,"/proc/bus/pci/%02d/%02x.0", bus, dev); |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
28 fd = open(path,O_RDONLY|O_SYNC); |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
29 if (fd == -1) { |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
30 retval=0xFFFF; |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
31 } |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
32 else if (pread(fd, &vendor, 2, PCI_VENDOR_ID) == 2 && |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
33 pread(fd, &device, 2, PCI_DEVICE_ID) == 2) { |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
34 vendor = bswap_16(vendor); |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
35 device = bswap_16(device); |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
36 retval = vendor + (device<<16); /*no worries about byte order, |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
37 all ppc are bigendian*/ |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
38 } else { |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
39 retval = 0xFFFF; |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
40 } |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
41 if (fd > 0) { |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
42 close(fd); |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
43 } |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
44 return retval; |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
45 } |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
46 |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
47 static long pci_config_read_long( |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
48 unsigned char bus, |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
49 unsigned char dev, |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
50 int func, |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
51 unsigned cmd) |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
52 { |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
53 long retval; |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
54 char path[100]; |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
55 int fd; |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
56 sprintf(path,"/proc/bus/pci/%02d/%02x.0", bus, dev); |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
57 fd = open(path,O_RDONLY|O_SYNC); |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
58 if (fd == -1) { |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
59 retval=0; |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
60 } |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
61 else if (pread(fd, &retval, 4, cmd) == 4) { |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
62 retval = bswap_32(retval); |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
63 } else { |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
64 retval = 0; |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
65 } |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
66 if (fd > 0) { |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
67 close(fd); |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
68 } |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
69 return retval; |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
70 } |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
71 |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
72 #else /*Lynx/OpenBSD*/ |
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
73 |
4164 | 74 static int pci_get_vendor( |
75 unsigned char bus, | |
76 unsigned char dev, | |
77 int func) | |
78 { | |
79 int retval; | |
80 pciconfig_read(bus, dev<<3, PCI_ID_REG, 4, &retval); | |
81 return retval; | |
82 } | |
83 | |
84 static long pci_config_read_long( | |
85 unsigned char bus, | |
86 unsigned char dev, | |
87 int func, | |
88 unsigned cmd) | |
89 { | |
90 long retval; | |
91 pciconfig_read(bus, dev<<3, cmd, 4, &retval); | |
92 return retval; | |
93 } | |
7837
6d544beb655e
libdha on linux powerpc support by Colin Leroy <colin@colino.net>
alex
parents:
4164
diff
changeset
|
94 #endif /*Lynx/OpenBSD*/ |