]>
Commit | Line | Data |
---|---|---|
58c69220 | 1 | /* pci.c - Generic PCI interfaces. */ |
2 | /* | |
3 | * GRUB -- GRand Unified Bootloader | |
58bc8bd5 | 4 | * Copyright (C) 2007,2009 Free Software Foundation, Inc. |
58c69220 | 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 | ||
20 | #include <grub/dl.h> | |
21 | #include <grub/pci.h> | |
22 | ||
23 | grub_pci_address_t | |
3affd0ec | 24 | grub_pci_make_address (grub_pci_device_t dev, int reg) |
58c69220 | 25 | { |
3affd0ec | 26 | return (1 << 31) | (dev.bus << 16) | (dev.device << 11) |
fbb8a887 | 27 | | (dev.function << 8) | reg; |
58c69220 | 28 | } |
29 | ||
30 | void | |
31 | grub_pci_iterate (grub_pci_iteratefunc_t hook) | |
32 | { | |
3affd0ec | 33 | grub_pci_device_t dev; |
58c69220 | 34 | grub_pci_address_t addr; |
35 | grub_pci_id_t id; | |
f6ce7629 | 36 | grub_uint32_t hdr; |
58c69220 | 37 | |
810d8224 | 38 | for (dev.bus = 0; dev.bus < GRUB_PCI_NUM_BUS; dev.bus++) |
58c69220 | 39 | { |
810d8224 | 40 | for (dev.device = 0; dev.device < GRUB_PCI_NUM_DEVICES; dev.device++) |
58c69220 | 41 | { |
3affd0ec | 42 | for (dev.function = 0; dev.function < 8; dev.function++) |
58c69220 | 43 | { |
fbb8a887 | 44 | addr = grub_pci_make_address (dev, GRUB_PCI_REG_PCI_ID); |
58c69220 | 45 | id = grub_pci_read (addr); |
46 | ||
47 | /* Check if there is a device present. */ | |
48 | if (id >> 16 == 0xFFFF) | |
49 | continue; | |
50 | ||
3affd0ec | 51 | if (hook (dev, id)) |
58c69220 | 52 | return; |
f6ce7629 | 53 | |
54 | /* Probe only func = 0 if the device if not multifunction */ | |
3affd0ec | 55 | if (dev.function == 0) |
f6ce7629 | 56 | { |
fbb8a887 | 57 | addr = grub_pci_make_address (dev, GRUB_PCI_REG_CACHELINE); |
f6ce7629 | 58 | hdr = grub_pci_read (addr); |
59 | if (!(hdr & 0x800000)) | |
60 | break; | |
61 | } | |
58c69220 | 62 | } |
63 | } | |
64 | } | |
65 | } |