pciaccess

This commit is contained in:
phcoder 2009-10-14 18:17:18 +02:00
parent 325c8258e7
commit 459fed4b98
6 changed files with 78 additions and 23 deletions

View file

@ -100,7 +100,7 @@ endif
AWK = @AWK@
LIBCURSES = @LIBCURSES@
LIBUSB = @LIBUSB@
LIBPCI = @LIBPCI@
LIBPCIACCESS = @LIBPCIACCESS@
YACC = @YACC@
UNIFONT_BDF = @UNIFONT_BDF@

View file

@ -170,7 +170,7 @@ endif
ifeq ($(enable_grub_emu_pci), yes)
grub_emu_SOURCES += util/pci.c commands/lspci.c
grub_emu_LDFLAGS += $(LIBPCI)
grub_emu_LDFLAGS += $(LIBPCIACCESS)
endif
# Scripts.

View file

@ -569,14 +569,14 @@ fi
[if [ x"$grub_emu_pci_excuse" = x ]; then
# Check for libpci libraries.]
AC_CHECK_LIB([pci], [pci_alloc], [LIBPCI="-lpci"],
[grub_emu_pci_excuse=["need libpci library"]])
AC_SUBST([LIBPCI])
AC_CHECK_LIB([pciaccess], [pci_system_init], [LIBPCIACCESS="-lpciaccess"],
[grub_emu_pci_excuse=["need libpciaccess library"]])
AC_SUBST([LIBPCIACCESS])
[fi]
[if [ x"$grub_emu_pci_excuse" = x ]; then
# Check for headers.]
AC_CHECK_HEADERS([pci/pci.h], [],
[grub_emu_pci_excuse=["need libpci headers"]])
[grub_emu_pci_excuse=["need libpciaccess headers"]])
[fi]
if test x"$grub_emu_pci_excuse" = x ; then

View file

@ -67,4 +67,20 @@ grub_pci_write_byte (grub_pci_address_t addr, grub_uint8_t data)
grub_outb (data, GRUB_PCI_DATA_REG + (addr & 3));
}
static inline void *
grub_pci_device_map_range (grub_pci_device_t dev __attribute__ ((unused)),
grub_addr_t base,
grub_size_t size __attribute__ ((unused)))
{
return (void *) base;
}
static inline void
grub_pci_device_unmap_range (grub_pci_device_t dev __attribute__ ((unused)),
void *mem __attribute__ ((unused)),
grub_size_t size __attribute__ ((unused)))
{
}
#endif /* GRUB_CPU_PCI_H */

View file

@ -19,9 +19,9 @@
#ifndef GRUB_PCIUTILS_H
#define GRUB_PCIUTILS_H 1
#include <pci/pci.h>
#include <pciaccess.h>
typedef struct pci_dev *grub_pci_device_t;
typedef struct pci_device *grub_pci_device_t;
static inline int
grub_pci_get_bus (grub_pci_device_t dev)
@ -52,37 +52,52 @@ typedef struct grub_pci_address grub_pci_address_t;
static inline grub_uint32_t
grub_pci_read (grub_pci_address_t addr)
{
return pci_read_long (addr.dev, addr.pos);
grub_uint32_t ret;
pci_device_cfg_read_u32 (addr.dev, &ret, addr.pos);
return ret;
}
static inline grub_uint16_t
grub_pci_read_word (grub_pci_address_t addr)
{
return pci_read_word (addr.dev, addr.pos);
grub_uint16_t ret;
pci_device_cfg_read_u16 (addr.dev, &ret, addr.pos);
return ret;
}
static inline grub_uint8_t
grub_pci_read_byte (grub_pci_address_t addr)
{
return pci_read_byte (addr.dev, addr.pos);
grub_uint8_t ret;
pci_device_cfg_read_u8 (addr.dev, &ret, addr.pos);
return ret;
}
static inline void
grub_pci_write (grub_pci_address_t addr, grub_uint32_t data)
{
pci_write_long (addr.dev, addr.pos, data);
pci_device_cfg_write_u32 (addr.dev, data, addr.pos);
}
static inline void
grub_pci_write_word (grub_pci_address_t addr, grub_uint16_t data)
{
pci_write_word (addr.dev, addr.pos, data);
pci_device_cfg_write_u16 (addr.dev, data, addr.pos);
}
static inline void
grub_pci_write_byte (grub_pci_address_t addr, grub_uint8_t data)
{
pci_write_byte (addr.dev, addr.pos, data);
pci_device_cfg_write_u8 (addr.dev, data, addr.pos);
}
void *
grub_pci_device_map_range (grub_pci_device_t dev, grub_addr_t base,
grub_size_t size);
void
grub_pci_device_unmap_range (grub_pci_device_t dev, void *mem,
grub_size_t size);
#endif /* GRUB_PCIUTILS_H */

View file

@ -19,8 +19,7 @@
#include <grub/pci.h>
#include <grub/dl.h>
struct pci_access *acc = 0;
#include <grub/util/misc.h>
grub_pci_address_t
grub_pci_make_address (grub_pci_device_t dev, int reg)
@ -34,19 +33,44 @@ grub_pci_make_address (grub_pci_device_t dev, int reg)
void
grub_pci_iterate (grub_pci_iteratefunc_t hook)
{
grub_pci_device_t cur;
for (cur = acc->devices; cur; cur = cur->next)
hook (cur, cur->vendor_id|(cur->device_id << 16));
struct pci_device_iterator *iter;
struct pci_slot_match slot;
struct pci_device *dev;
slot.domain = PCI_MATCH_ANY;
slot.bus = PCI_MATCH_ANY;
slot.dev = PCI_MATCH_ANY;
slot.func = PCI_MATCH_ANY;
iter = pci_slot_match_iterator_create (&slot);
while ((dev = pci_device_next (iter)))
hook (dev, dev->vendor_id | (dev->device_id << 16));
pci_iterator_destroy (iter);
}
void *
grub_pci_device_map_range (grub_pci_device_t dev, grub_addr_t base,
grub_size_t size)
{
void *addr;
int err;
err = pci_device_map_range(dev, base, size, PCI_DEV_MAP_FLAG_WRITABLE, &addr);
if (err)
grub_util_error ("mapping 0x%x failed (error %d)\n", base, err);
return addr;
}
void
grub_pci_device_unmap_range (grub_pci_device_t dev, void *mem,
grub_size_t size)
{
pci_device_unmap_range (dev, mem, size);
}
GRUB_MOD_INIT (pci)
{
acc = pci_alloc ();
pci_init (acc);
pci_scan_bus (acc);
pci_system_init ();
}
GRUB_MOD_FINI (pci)
{
pci_cleanup (acc);
pci_system_cleanup ();
}