pci.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/util/misc.h>
  22. grub_pci_address_t
  23. grub_pci_make_address (grub_pci_device_t dev, int reg)
  24. {
  25. grub_pci_address_t ret;
  26. ret.dev = dev;
  27. ret.pos = reg;
  28. return ret;
  29. }
  30. void
  31. grub_pci_iterate (grub_pci_iteratefunc_t hook)
  32. {
  33. struct pci_device_iterator *iter;
  34. struct pci_slot_match slot;
  35. struct pci_device *dev;
  36. slot.domain = PCI_MATCH_ANY;
  37. slot.bus = PCI_MATCH_ANY;
  38. slot.dev = PCI_MATCH_ANY;
  39. slot.func = PCI_MATCH_ANY;
  40. iter = pci_slot_match_iterator_create (&slot);
  41. while ((dev = pci_device_next (iter)))
  42. hook (dev, dev->vendor_id | (dev->device_id << 16));
  43. pci_iterator_destroy (iter);
  44. }
  45. void *
  46. grub_pci_device_map_range (grub_pci_device_t dev, grub_addr_t base,
  47. grub_size_t size)
  48. {
  49. void *addr;
  50. int err;
  51. err = pci_device_map_range (dev, base, size, PCI_DEV_MAP_FLAG_WRITABLE, &addr);
  52. if (err)
  53. grub_util_error ("mapping 0x%x failed (error %d)\n", base, err);
  54. return addr;
  55. }
  56. void
  57. grub_pci_device_unmap_range (grub_pci_device_t dev, void *mem,
  58. grub_size_t size)
  59. {
  60. pci_device_unmap_range (dev, mem, size);
  61. }
  62. GRUB_MOD_INIT (pci)
  63. {
  64. pci_system_init ();
  65. }
  66. GRUB_MOD_FINI (pci)
  67. {
  68. pci_system_cleanup ();
  69. }