2009-08-08 Robert Millan <rmh.grub@aybabtu.com>
[grub2/phcoder/solaris.git] / bus / pci.c
blob2c29c03ab22d4855337fd19e2c32f1bc932b7ac6
1 /* pci.c - Generic PCI interfaces. */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2007 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/dl.h>
21 #include <grub/pci.h>
23 grub_pci_address_t
24 grub_pci_make_address (int bus, int device, int function, int reg)
26 return (1 << 31) | (bus << 16) | (device << 11) | (function << 8) | (reg << 2);
29 void
30 grub_pci_iterate (grub_pci_iteratefunc_t hook)
32 int bus;
33 int dev;
34 int func;
35 grub_pci_address_t addr;
36 grub_pci_id_t id;
37 grub_uint32_t hdr;
39 for (bus = 0; bus < 256; bus++)
41 for (dev = 0; dev < 32; dev++)
43 for (func = 0; func < 8; func++)
45 addr = grub_pci_make_address (bus, dev, func, 0);
46 id = grub_pci_read (addr);
48 /* Check if there is a device present. */
49 if (id >> 16 == 0xFFFF)
50 continue;
52 if (hook (bus, dev, func, id))
53 return;
55 /* Probe only func = 0 if the device if not multifunction */
56 if (func == 0)
58 addr = grub_pci_make_address (bus, dev, func, 3);
59 hdr = grub_pci_read (addr);
60 if (!(hdr & 0x800000))
61 break;