comparison libdha/sysdep/pci_powerpc.c @ 7837:6d544beb655e

libdha on linux powerpc support by Colin Leroy <colin@colino.net>
author alex
date Tue, 22 Oct 2002 12:22:40 +0000
parents 2e3262002acb
children d09c74452323
comparison
equal deleted inserted replaced
7836:6bfe33dc531e 7837:6d544beb655e
3 $XFree86: xc/programs/Xserver/hw/xfree86/etc/scanpci.c,v 3.34.2.17 1998/11/10 11:55:40 dawes Exp $ 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 4 Modified for readability by Nick Kurshev
5 */ 5 */
6 6
7 static int pci_config_type( void ) { return 1; } 7 static int pci_config_type( void ) { return 1; }
8
9 #if defined(__powerpc__) && defined(__linux__)
10 /* pci operations for powerpc Linux
11 questions, suggestions etc:
12 mplayer-dev-eng@mplayerhq.hu, colin@colino.net*/
13 #include <fcntl.h>
14 #include <sys/io.h>
15 #include <linux/pci.h>
16 #include "../../bswap.h"
17
18 static int pci_get_vendor(
19 unsigned char bus,
20 unsigned char dev,
21 int func)
22 {
23 int retval;
24 char path[100];
25 int fd;
26 short vendor, device;
27 sprintf(path,"/proc/bus/pci/%02d/%02x.0", bus, dev);
28 fd = open(path,O_RDONLY|O_SYNC);
29 if (fd == -1) {
30 retval=0xFFFF;
31 }
32 else if (pread(fd, &vendor, 2, PCI_VENDOR_ID) == 2 &&
33 pread(fd, &device, 2, PCI_DEVICE_ID) == 2) {
34 vendor = bswap_16(vendor);
35 device = bswap_16(device);
36 retval = vendor + (device<<16); /*no worries about byte order,
37 all ppc are bigendian*/
38 } else {
39 retval = 0xFFFF;
40 }
41 if (fd > 0) {
42 close(fd);
43 }
44 return retval;
45 }
46
47 static long pci_config_read_long(
48 unsigned char bus,
49 unsigned char dev,
50 int func,
51 unsigned cmd)
52 {
53 long retval;
54 char path[100];
55 int fd;
56 sprintf(path,"/proc/bus/pci/%02d/%02x.0", bus, dev);
57 fd = open(path,O_RDONLY|O_SYNC);
58 if (fd == -1) {
59 retval=0;
60 }
61 else if (pread(fd, &retval, 4, cmd) == 4) {
62 retval = bswap_32(retval);
63 } else {
64 retval = 0;
65 }
66 if (fd > 0) {
67 close(fd);
68 }
69 return retval;
70 }
71
72 #else /*Lynx/OpenBSD*/
8 73
9 static int pci_get_vendor( 74 static int pci_get_vendor(
10 unsigned char bus, 75 unsigned char bus,
11 unsigned char dev, 76 unsigned char dev,
12 int func) 77 int func)
24 { 89 {
25 long retval; 90 long retval;
26 pciconfig_read(bus, dev<<3, cmd, 4, &retval); 91 pciconfig_read(bus, dev<<3, cmd, 4, &retval);
27 return retval; 92 return retval;
28 } 93 }
94 #endif /*Lynx/OpenBSD*/