1
/* pci.c - Generic PCI interfaces. */
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/>.
24
/* FIXME: correctly support 64-bit architectures. */
25
/* #if GRUB_TARGET_SIZEOF_VOID_P == 4 */
26
struct grub_pci_dma_chunk *
27
grub_memalign_dma32 (grub_size_t align, grub_size_t size)
29
return grub_memalign (align, size);
33
grub_dma_free (struct grub_pci_dma_chunk *ch)
39
#ifdef GRUB_MACHINE_MIPS_YEELOONG
41
grub_dma_get_virt (struct grub_pci_dma_chunk *ch)
43
return (void *) ((((grub_uint32_t) ch) & 0x1fffffff) | 0xa0000000);
47
grub_dma_get_phys (struct grub_pci_dma_chunk *ch)
49
return (((grub_uint32_t) ch) & 0x1fffffff) | 0x80000000;
54
grub_dma_get_virt (struct grub_pci_dma_chunk *ch)
60
grub_dma_get_phys (struct grub_pci_dma_chunk *ch)
62
return (grub_uint32_t) (grub_addr_t) ch;
68
grub_pci_make_address (grub_pci_device_t dev, int reg)
70
return (1 << 31) | (dev.bus << 16) | (dev.device << 11)
71
| (dev.function << 8) | reg;
75
grub_pci_iterate (grub_pci_iteratefunc_t hook)
77
grub_pci_device_t dev;
78
grub_pci_address_t addr;
82
for (dev.bus = 0; dev.bus < GRUB_PCI_NUM_BUS; dev.bus++)
84
for (dev.device = 0; dev.device < GRUB_PCI_NUM_DEVICES; dev.device++)
86
for (dev.function = 0; dev.function < 8; dev.function++)
88
addr = grub_pci_make_address (dev, GRUB_PCI_REG_PCI_ID);
89
id = grub_pci_read (addr);
91
/* Check if there is a device present. */
92
if (id >> 16 == 0xFFFF)
95
#ifdef GRUB_MACHINE_MIPS_YEELOONG
97
if (id == GRUB_YEELOONG_OHCI_PCIID
98
&& dev.function == GRUB_YEELOONG_OHCI_GHOST_FUNCTION)
100
if (id == GRUB_YEELOONG_EHCI_PCIID
101
&& dev.function == GRUB_YEELOONG_EHCI_GHOST_FUNCTION)
108
/* Probe only func = 0 if the device if not multifunction */
109
if (dev.function == 0)
111
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CACHELINE);
112
hdr = grub_pci_read (addr);
113
if (!(hdr & 0x800000))