compat.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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. #include <linux/types.h>
  9. #include <linux/kernel.h>
  10. #include <linux/pci.h>
  11. int
  12. pcibios_present(void)
  13. {
  14. return !list_empty(&pci_devices);
  15. }
  16. int
  17. pcibios_find_class(unsigned int class, unsigned short index, unsigned char *bus, unsigned char *devfn)
  18. {
  19. const struct pci_dev *dev = NULL;
  20. int cnt = 0;
  21. while ((dev = pci_find_class(class, dev)))
  22. if (index == cnt++) {
  23. *bus = dev->bus->number;
  24. *devfn = dev->devfn;
  25. return PCIBIOS_SUCCESSFUL;
  26. }
  27. return PCIBIOS_DEVICE_NOT_FOUND;
  28. }
  29. int
  30. pcibios_find_device(unsigned short vendor, unsigned short device, unsigned short index,
  31.     unsigned char *bus, unsigned char *devfn)
  32. {
  33. const struct pci_dev *dev = NULL;
  34. int cnt = 0;
  35. while ((dev = pci_find_device(vendor, device, dev)))
  36. if (index == cnt++) {
  37. *bus = dev->bus->number;
  38. *devfn = dev->devfn;
  39. return PCIBIOS_SUCCESSFUL;
  40. }
  41. return PCIBIOS_DEVICE_NOT_FOUND;
  42. }
  43. #define PCI_OP(rw,size,type)
  44. int pcibios_##rw##_config_##size (unsigned char bus, unsigned char dev_fn,
  45.   unsigned char where, unsigned type val)
  46. {
  47. struct pci_dev *dev = pci_find_slot(bus, dev_fn);
  48. if (!dev) return PCIBIOS_DEVICE_NOT_FOUND;
  49. return pci_##rw##_config_##size(dev, where, val);
  50. }
  51. PCI_OP(read, byte, char *)
  52. PCI_OP(read, word, short *)
  53. PCI_OP(read, dword, int *)
  54. PCI_OP(write, byte, char)
  55. PCI_OP(write, word, short)
  56. PCI_OP(write, dword, int)