pciaccess
This commit is contained in:
parent
325c8258e7
commit
459fed4b98
6 changed files with 78 additions and 23 deletions
|
@ -100,7 +100,7 @@ endif
|
||||||
AWK = @AWK@
|
AWK = @AWK@
|
||||||
LIBCURSES = @LIBCURSES@
|
LIBCURSES = @LIBCURSES@
|
||||||
LIBUSB = @LIBUSB@
|
LIBUSB = @LIBUSB@
|
||||||
LIBPCI = @LIBPCI@
|
LIBPCIACCESS = @LIBPCIACCESS@
|
||||||
YACC = @YACC@
|
YACC = @YACC@
|
||||||
UNIFONT_BDF = @UNIFONT_BDF@
|
UNIFONT_BDF = @UNIFONT_BDF@
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,7 @@ endif
|
||||||
|
|
||||||
ifeq ($(enable_grub_emu_pci), yes)
|
ifeq ($(enable_grub_emu_pci), yes)
|
||||||
grub_emu_SOURCES += util/pci.c commands/lspci.c
|
grub_emu_SOURCES += util/pci.c commands/lspci.c
|
||||||
grub_emu_LDFLAGS += $(LIBPCI)
|
grub_emu_LDFLAGS += $(LIBPCIACCESS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Scripts.
|
# Scripts.
|
||||||
|
|
|
@ -569,14 +569,14 @@ fi
|
||||||
|
|
||||||
[if [ x"$grub_emu_pci_excuse" = x ]; then
|
[if [ x"$grub_emu_pci_excuse" = x ]; then
|
||||||
# Check for libpci libraries.]
|
# Check for libpci libraries.]
|
||||||
AC_CHECK_LIB([pci], [pci_alloc], [LIBPCI="-lpci"],
|
AC_CHECK_LIB([pciaccess], [pci_system_init], [LIBPCIACCESS="-lpciaccess"],
|
||||||
[grub_emu_pci_excuse=["need libpci library"]])
|
[grub_emu_pci_excuse=["need libpciaccess library"]])
|
||||||
AC_SUBST([LIBPCI])
|
AC_SUBST([LIBPCIACCESS])
|
||||||
[fi]
|
[fi]
|
||||||
[if [ x"$grub_emu_pci_excuse" = x ]; then
|
[if [ x"$grub_emu_pci_excuse" = x ]; then
|
||||||
# Check for headers.]
|
# Check for headers.]
|
||||||
AC_CHECK_HEADERS([pci/pci.h], [],
|
AC_CHECK_HEADERS([pci/pci.h], [],
|
||||||
[grub_emu_pci_excuse=["need libpci headers"]])
|
[grub_emu_pci_excuse=["need libpciaccess headers"]])
|
||||||
[fi]
|
[fi]
|
||||||
|
|
||||||
if test x"$grub_emu_pci_excuse" = x ; then
|
if test x"$grub_emu_pci_excuse" = x ; then
|
||||||
|
|
|
@ -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));
|
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 */
|
#endif /* GRUB_CPU_PCI_H */
|
||||||
|
|
|
@ -19,9 +19,9 @@
|
||||||
#ifndef GRUB_PCIUTILS_H
|
#ifndef GRUB_PCIUTILS_H
|
||||||
#define GRUB_PCIUTILS_H 1
|
#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
|
static inline int
|
||||||
grub_pci_get_bus (grub_pci_device_t dev)
|
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
|
static inline grub_uint32_t
|
||||||
grub_pci_read (grub_pci_address_t addr)
|
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
|
static inline grub_uint16_t
|
||||||
grub_pci_read_word (grub_pci_address_t addr)
|
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
|
static inline grub_uint8_t
|
||||||
grub_pci_read_byte (grub_pci_address_t addr)
|
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
|
static inline void
|
||||||
grub_pci_write (grub_pci_address_t addr, grub_uint32_t data)
|
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
|
static inline void
|
||||||
grub_pci_write_word (grub_pci_address_t addr, grub_uint16_t data)
|
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
|
static inline void
|
||||||
grub_pci_write_byte (grub_pci_address_t addr, grub_uint8_t data)
|
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 */
|
#endif /* GRUB_PCIUTILS_H */
|
||||||
|
|
42
util/pci.c
42
util/pci.c
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
#include <grub/pci.h>
|
#include <grub/pci.h>
|
||||||
#include <grub/dl.h>
|
#include <grub/dl.h>
|
||||||
|
#include <grub/util/misc.h>
|
||||||
struct pci_access *acc = 0;
|
|
||||||
|
|
||||||
grub_pci_address_t
|
grub_pci_address_t
|
||||||
grub_pci_make_address (grub_pci_device_t dev, int reg)
|
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
|
void
|
||||||
grub_pci_iterate (grub_pci_iteratefunc_t hook)
|
grub_pci_iterate (grub_pci_iteratefunc_t hook)
|
||||||
{
|
{
|
||||||
grub_pci_device_t cur;
|
struct pci_device_iterator *iter;
|
||||||
for (cur = acc->devices; cur; cur = cur->next)
|
struct pci_slot_match slot;
|
||||||
hook (cur, cur->vendor_id|(cur->device_id << 16));
|
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)
|
GRUB_MOD_INIT (pci)
|
||||||
{
|
{
|
||||||
acc = pci_alloc ();
|
pci_system_init ();
|
||||||
pci_init (acc);
|
|
||||||
pci_scan_bus (acc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GRUB_MOD_FINI (pci)
|
GRUB_MOD_FINI (pci)
|
||||||
{
|
{
|
||||||
pci_cleanup (acc);
|
pci_system_cleanup ();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue