added mtd driver
[linux-2.4.git] / drivers / pci / compat.c
1 /*
2  *      $Id: compat.c,v 1.1 1998/02/16 10:35:50 mj Exp $
3  *
4  *      PCI Bus Services -- Function For Backward Compatibility
5  *
6  *      Copyright 1998--2000 Martin Mares <mj@ucw.cz>
7  */
8
9 #include <linux/types.h>
10 #include <linux/kernel.h>
11 #include <linux/pci.h>
12
13 int
14 pcibios_present(void)
15 {
16         return !list_empty(&pci_devices);
17 }
18
19 int
20 pcibios_find_class(unsigned int class, unsigned short index, unsigned char *bus, unsigned char *devfn)
21 {
22         const struct pci_dev *dev = NULL;
23         int cnt = 0;
24
25         while ((dev = pci_find_class(class, dev)))
26                 if (index == cnt++) {
27                         *bus = dev->bus->number;
28                         *devfn = dev->devfn;
29                         return PCIBIOS_SUCCESSFUL;
30                 }
31         return PCIBIOS_DEVICE_NOT_FOUND;
32 }
33
34
35 int
36 pcibios_find_device(unsigned short vendor, unsigned short device, unsigned short index,
37                     unsigned char *bus, unsigned char *devfn)
38 {
39         const struct pci_dev *dev = NULL;
40         int cnt = 0;
41
42         while ((dev = pci_find_device(vendor, device, dev)))
43                 if (index == cnt++) {
44                         *bus = dev->bus->number;
45                         *devfn = dev->devfn;
46                         return PCIBIOS_SUCCESSFUL;
47                 }
48         return PCIBIOS_DEVICE_NOT_FOUND;
49 }
50
51 #define PCI_OP(rw,size,type)                                                    \
52 int pcibios_##rw##_config_##size (unsigned char bus, unsigned char dev_fn,      \
53                                   unsigned char where, unsigned type val)       \
54 {                                                                               \
55         struct pci_dev *dev = pci_find_slot(bus, dev_fn);                       \
56         if (!dev) return PCIBIOS_DEVICE_NOT_FOUND;                              \
57         return pci_##rw##_config_##size(dev, where, val);                       \
58 }
59
60 PCI_OP(read, byte, char *)
61 PCI_OP(read, word, short *)
62 PCI_OP(read, dword, int *)
63 PCI_OP(write, byte, char)
64 PCI_OP(write, word, short)
65 PCI_OP(write, dword, int)