2008-02-02 15:33:05 +00:00
|
|
|
/* pci.c - Generic PCI interfaces. */
|
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
2010-01-03 22:05:07 +00:00
|
|
|
* Copyright (C) 2007,2009 Free Software Foundation, Inc.
|
2008-02-02 15:33:05 +00:00
|
|
|
*
|
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <grub/dl.h>
|
|
|
|
#include <grub/pci.h>
|
2010-05-05 08:40:48 +00:00
|
|
|
#include <grub/mm.h>
|
|
|
|
|
|
|
|
#if GRUB_TARGET_SIZEOF_VOID_P == 4
|
|
|
|
struct grub_pci_dma_chunk *
|
|
|
|
grub_memalign_dma32 (grub_size_t align, grub_size_t size)
|
|
|
|
{
|
|
|
|
return grub_memalign (align, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
grub_dma_free (struct grub_pci_dma_chunk *ch)
|
|
|
|
{
|
|
|
|
grub_free (ch);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef GRUB_MACHINE_MIPS_YEELOONG
|
2010-05-22 22:11:47 +00:00
|
|
|
volatile void *
|
2010-05-05 08:40:48 +00:00
|
|
|
grub_dma_get_virt (struct grub_pci_dma_chunk *ch)
|
|
|
|
{
|
|
|
|
return (void *) ((((grub_uint32_t) ch) & 0x1fffffff) | 0xa0000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_uint32_t
|
|
|
|
grub_dma_get_phys (struct grub_pci_dma_chunk *ch)
|
|
|
|
{
|
2010-05-22 22:11:47 +00:00
|
|
|
return (((grub_uint32_t) ch) & 0x1fffffff) | 0x80000000;
|
2010-05-05 08:40:48 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
void *
|
|
|
|
grub_dma_get_virt (struct grub_pci_dma_chunk *ch)
|
|
|
|
{
|
|
|
|
return (void *) ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_uint32_t
|
|
|
|
grub_dma_get_phys (struct grub_pci_dma_chunk *ch)
|
|
|
|
{
|
|
|
|
return (grub_uint32_t) ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2008-02-02 15:33:05 +00:00
|
|
|
|
|
|
|
grub_pci_address_t
|
2009-10-14 08:11:59 +00:00
|
|
|
grub_pci_make_address (grub_pci_device_t dev, int reg)
|
2008-02-02 15:33:05 +00:00
|
|
|
{
|
2009-10-14 08:11:59 +00:00
|
|
|
return (1 << 31) | (dev.bus << 16) | (dev.device << 11)
|
2009-12-22 14:09:25 +00:00
|
|
|
| (dev.function << 8) | reg;
|
2008-02-02 15:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
grub_pci_iterate (grub_pci_iteratefunc_t hook)
|
|
|
|
{
|
2009-10-14 08:11:59 +00:00
|
|
|
grub_pci_device_t dev;
|
2008-02-02 15:33:05 +00:00
|
|
|
grub_pci_address_t addr;
|
|
|
|
grub_pci_id_t id;
|
2008-04-05 07:20:29 +00:00
|
|
|
grub_uint32_t hdr;
|
2008-02-02 15:33:05 +00:00
|
|
|
|
2009-11-02 22:42:07 +00:00
|
|
|
for (dev.bus = 0; dev.bus < GRUB_PCI_NUM_BUS; dev.bus++)
|
2008-02-02 15:33:05 +00:00
|
|
|
{
|
2009-11-02 22:42:07 +00:00
|
|
|
for (dev.device = 0; dev.device < GRUB_PCI_NUM_DEVICES; dev.device++)
|
2008-02-02 15:33:05 +00:00
|
|
|
{
|
2009-10-14 08:11:59 +00:00
|
|
|
for (dev.function = 0; dev.function < 8; dev.function++)
|
2008-02-02 15:33:05 +00:00
|
|
|
{
|
2009-12-22 14:09:25 +00:00
|
|
|
addr = grub_pci_make_address (dev, GRUB_PCI_REG_PCI_ID);
|
2008-02-02 15:33:05 +00:00
|
|
|
id = grub_pci_read (addr);
|
|
|
|
|
|
|
|
/* Check if there is a device present. */
|
|
|
|
if (id >> 16 == 0xFFFF)
|
|
|
|
continue;
|
|
|
|
|
2010-05-22 22:12:33 +00:00
|
|
|
/* Skip ghosts. */
|
|
|
|
if (id == GRUB_YEELOONG_OHCI_PCIID
|
|
|
|
&& dev.function == GRUB_YEELOONG_OHCI_GHOST_FUNCTION)
|
|
|
|
continue;
|
|
|
|
if (id == GRUB_YEELOONG_EHCI_PCIID
|
|
|
|
&& dev.function == GRUB_YEELOONG_EHCI_GHOST_FUNCTION)
|
|
|
|
continue;
|
|
|
|
|
2009-10-14 08:11:59 +00:00
|
|
|
if (hook (dev, id))
|
2008-02-02 15:33:05 +00:00
|
|
|
return;
|
2008-04-05 07:20:29 +00:00
|
|
|
|
|
|
|
/* Probe only func = 0 if the device if not multifunction */
|
2009-10-14 08:11:59 +00:00
|
|
|
if (dev.function == 0)
|
2008-04-05 07:20:29 +00:00
|
|
|
{
|
2009-12-22 14:09:25 +00:00
|
|
|
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CACHELINE);
|
2008-04-05 07:20:29 +00:00
|
|
|
hdr = grub_pci_read (addr);
|
|
|
|
if (!(hdr & 0x800000))
|
|
|
|
break;
|
|
|
|
}
|
2008-02-02 15:33:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|