]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
lspci works in grub-emu
authorphcoder <phcoder@debian.bg45.phnet>
Wed, 14 Oct 2009 08:36:37 +0000 (10:36 +0200)
committerphcoder <phcoder@debian.bg45.phnet>
Wed, 14 Oct 2009 08:36:37 +0000 (10:36 +0200)
commands/lspci.c
configure.ac
include/grub/i386/pci.h
include/grub/pciutils.h [new file with mode: 0644]
util/pci.c

index 10618c7a95371b4e3635fcb4d20a309c55ee87fe..bcaafa4f83fa96ca3fcec194dfafc2535b5e4bab 100644 (file)
@@ -143,8 +143,6 @@ grub_lspci_iter (grub_pci_device_t dev, grub_pci_id_t pciid)
 
   grub_printf ("\n");
 
-  grub_pci_close (dev);
-
   return 0;
 }
 
@@ -159,13 +157,13 @@ grub_cmd_lspci (grub_command_t cmd __attribute__ ((unused)),
 
 static grub_command_t cmd;
 
-GRUB_MOD_INIT(pci)
+GRUB_MOD_INIT(lspci)
 {
   cmd = grub_register_command ("lspci", grub_cmd_lspci,
                               0, "List PCI devices");
 }
 
-GRUB_MOD_FINI(pci)
+GRUB_MOD_FINI(lspci)
 {
   grub_unregister_command (cmd);
 }
index 5a98e34331f7cea1ac82c77d1e96d79dd83d5c2b..ceb81881aa526a28bcb9a749993050d307726c0f 100644 (file)
@@ -531,9 +531,14 @@ else
 enable_grub_emu=no
 grub_emu_usb_excuse="grub-emu isn't built"
 fi
+if test x"$enable_grub_emu_pci" = xyes ; then
+   grub_emu_usb_excuse="conflicts with PCI support"
+fi
+
 if test x"$enable_grub_emu_usb" = xno ; then
   grub_emu_usb_excuse="explicitly disabled"
 fi
+
 [if [ x"$grub_emu_usb_excuse" = x ]; then
     # Check for libusb libraries.]
 AC_CHECK_LIB([usb], [usb_claim_interface], [LIBUSB="-lusb"],
@@ -555,7 +560,29 @@ enable_grub_emu_usb=no
 fi
 
 if test x"$enable_grub_emu_pci" != xyes ; then
-   enable_grub_emu_pci = no
+   grub_emu_pci_excuse="not enabled"
+fi
+
+if test x"$enable_grub_emu_usb" = xyes ; then
+   grub_emu_pci_excuse="conflicts with USB support"
+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])
+[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"]])
+[fi]
+
+if test x"$grub_emu_pci_excuse" = x ; then
+enable_grub_emu_pci=yes
+else
+enable_grub_emu_pci=no
 fi
 
 AC_SUBST([enable_grub_emu])
@@ -634,6 +661,12 @@ echo USB support for grub-emu: Yes
 else
 echo USB support for grub-emu: No "($grub_emu_usb_excuse)"
 fi
+if [ x"$grub_emu_pci_excuse" = x ]; then
+echo PCI support for grub-emu: Yes
+else
+echo PCI support for grub-emu: No "($grub_emu_pci_excuse)"
+fi
+
 if [ x"$enable_mm_debug" = xyes ]; then
 echo With memory debugging: Yes
 else
index c8de9ff327f2bbcd8061c4aaaf2f674b1842f959..996f642455fa043f0488665fcb26d30f382cc5c4 100644 (file)
@@ -67,9 +67,4 @@ 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_close (grub_pci_device_t dev __attribute__ ((unused)))
-{
-}
-
 #endif /* GRUB_CPU_PCI_H */
diff --git a/include/grub/pciutils.h b/include/grub/pciutils.h
new file mode 100644 (file)
index 0000000..5ce612f
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2008,2009  Free Software Foundation, Inc.
+ *
+ *  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/>.
+ */
+
+#ifndef        GRUB_PCIUTILS_H
+#define        GRUB_PCIUTILS_H 1
+
+#include <pci/pci.h>
+
+typedef struct pci_dev *grub_pci_device_t;
+
+static inline int
+grub_pci_get_bus (grub_pci_device_t dev)
+{
+  return dev->bus;
+}
+
+static inline int
+grub_pci_get_device (grub_pci_device_t dev)
+{
+  return dev->dev;
+}
+
+static inline int
+grub_pci_get_function (grub_pci_device_t dev)
+{
+  return dev->func;
+}
+
+struct grub_pci_address
+{
+  grub_pci_device_t dev;
+  int pos;
+};
+
+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);
+}
+
+static inline grub_uint16_t
+grub_pci_read_word (grub_pci_address_t addr)
+{
+  return pci_read_word (addr.dev, addr.pos);
+}
+
+static inline grub_uint8_t
+grub_pci_read_byte (grub_pci_address_t addr)
+{
+  return pci_read_byte (addr.dev, addr.pos);
+}
+
+static inline void
+grub_pci_write (grub_pci_address_t addr, grub_uint32_t data)
+{
+  pci_write_long (addr.dev, addr.pos, data);
+}
+
+static inline void
+grub_pci_write_word (grub_pci_address_t addr, grub_uint16_t data)
+{
+  pci_write_word (addr.dev, addr.pos, data);
+}
+
+static inline void
+grub_pci_write_byte (grub_pci_address_t addr, grub_uint8_t data)
+{
+  pci_write_byte (addr.dev, addr.pos, data);
+}
+
+#endif /* GRUB_PCIUTILS_H */
index 99962c31dcd88a21981bf9d4a6d04c834c019c65..e1706814929609e2dd09b261f17da0197fc2bba2 100644 (file)
@@ -31,12 +31,6 @@ grub_pci_make_address (grub_pci_device_t dev, int reg)
   return ret;
 }
 
-void
-grub_pci_close (grub_pci_device_t dev)
-{
-  pci_free_dev (dev);
-}
-
 void
 grub_pci_iterate (grub_pci_iteratefunc_t hook)
 {
@@ -49,6 +43,7 @@ GRUB_MOD_INIT (pci)
 {
   acc = pci_alloc ();
   pci_init (acc);
+  pci_scan_bus (acc);
 }
 
 GRUB_MOD_FINI (pci)