GRUB-1.98 changes
[grub2/jjazz.git] / util / pci.c
blob420ae320ba52aa20d697436d5c7df8adead8e847
1 /* pci.c - Generic PCI interfaces. */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2007,2009 Free Software Foundation, Inc.
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.
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.
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/>.
20 #include <grub/pci.h>
21 #include <grub/dl.h>
22 #include <grub/util/misc.h>
24 grub_pci_address_t
25 grub_pci_make_address (grub_pci_device_t dev, int reg)
27 grub_pci_address_t ret;
28 ret.dev = dev;
29 ret.pos = reg;
30 return ret;
33 void
34 grub_pci_iterate (grub_pci_iteratefunc_t hook)
36 struct pci_device_iterator *iter;
37 struct pci_slot_match slot;
38 struct pci_device *dev;
39 slot.domain = PCI_MATCH_ANY;
40 slot.bus = PCI_MATCH_ANY;
41 slot.dev = PCI_MATCH_ANY;
42 slot.func = PCI_MATCH_ANY;
43 iter = pci_slot_match_iterator_create (&slot);
44 while ((dev = pci_device_next (iter)))
45 hook (dev, dev->vendor_id | (dev->device_id << 16));
46 pci_iterator_destroy (iter);
49 void *
50 grub_pci_device_map_range (grub_pci_device_t dev, grub_addr_t base,
51 grub_size_t size)
53 void *addr;
54 int err;
55 err = pci_device_map_range (dev, base, size, PCI_DEV_MAP_FLAG_WRITABLE, &addr);
56 if (err)
57 grub_util_error ("mapping 0x%x failed (error %d)\n", base, err);
58 return addr;
61 void
62 grub_pci_device_unmap_range (grub_pci_device_t dev, void *mem,
63 grub_size_t size)
65 pci_device_unmap_range (dev, mem, size);
68 GRUB_MOD_INIT (pci)
70 pci_system_init ();
73 GRUB_MOD_FINI (pci)
75 pci_system_cleanup ();