pci.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* pci.c - Generic PCI interfaces. */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2007,2009 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <grub/pci.h>
  20. #include <grub/dl.h>
  21. #include <grub/emu/misc.h>
  22. #include <grub/util/misc.h>
  23. grub_pci_address_t
  24. grub_pci_make_address (grub_pci_device_t dev, int reg)
  25. {
  26. grub_pci_address_t ret;
  27. ret.dev = dev;
  28. ret.pos = reg;
  29. return ret;
  30. }
  31. void
  32. grub_pci_iterate (grub_pci_iteratefunc_t hook, void *hook_data)
  33. {
  34. struct pci_device_iterator *iter;
  35. struct pci_slot_match slot;
  36. struct pci_device *dev;
  37. slot.domain = PCI_MATCH_ANY;
  38. slot.bus = PCI_MATCH_ANY;
  39. slot.dev = PCI_MATCH_ANY;
  40. slot.func = PCI_MATCH_ANY;
  41. iter = pci_slot_match_iterator_create (&slot);
  42. while ((dev = pci_device_next (iter)))
  43. hook (dev, dev->vendor_id | (dev->device_id << 16), hook_data);
  44. pci_iterator_destroy (iter);
  45. }
  46. void *
  47. grub_pci_device_map_range (grub_pci_device_t dev, grub_addr_t base,
  48. grub_size_t size)
  49. {
  50. void *addr;
  51. int err;
  52. err = pci_device_map_range (dev, base, size, PCI_DEV_MAP_FLAG_WRITABLE, &addr);
  53. if (err)
  54. grub_util_error ("mapping 0x%llx failed (error %d)",
  55. (unsigned long long) base, err);
  56. return addr;
  57. }
  58. void
  59. grub_pci_device_unmap_range (grub_pci_device_t dev, void *mem,
  60. grub_size_t size)
  61. {
  62. pci_device_unmap_range (dev, mem, size);
  63. }
  64. GRUB_MOD_INIT (emupci)
  65. {
  66. pci_system_init ();
  67. }
  68. GRUB_MOD_FINI (emupci)
  69. {
  70. pci_system_cleanup ();
  71. }