=== modified file 'grub_lib.c'
--- grub_lib.c	2010-09-21 18:00:15 +0000
+++ grub_lib.c	2010-11-05 20:40:01 +0000
@@ -27,6 +27,7 @@
 #include <grub/normal.h>
 #include <grub/file.h>
 #include <grub/device.h>
+#include <grub/pci.h>
 
 /* Updates the globals grub_errno and grub_msg, leaving their values on the 
    top of the stack, and clears grub_errno. When grub_errno is zero, grub_msg
@@ -251,6 +252,53 @@
 }
 
 static int
+grub_lua_enum_pci (lua_State *state)
+{
+  auto int NESTED_FUNC_ATTR enum_pci (grub_pci_device_t dev, grub_pci_id_t pciid);
+  int NESTED_FUNC_ATTR enum_pci (grub_pci_device_t dev, grub_pci_id_t pciid)
+  {
+    int result;
+    grub_pci_address_t addr;
+    grub_pci_id_t sub_pciid;
+    grub_uint32_t class;
+
+    lua_pushvalue (state, 1);
+    lua_pushinteger (state, grub_pci_get_bus (dev));
+    lua_pushinteger (state, grub_pci_get_device (dev));
+    lua_pushinteger (state, grub_pci_get_function (dev));
+
+    /* vendor ID */
+    lua_pushinteger (state, pciid & 0xFFFF);
+    /* device ID */
+    lua_pushinteger (state, pciid >> 16);
+
+    addr = grub_pci_make_address (dev, GRUB_PCI_REG_SUBVENDOR);
+    sub_pciid = grub_pci_read (addr);
+    /* subvendor ID */
+    lua_pushinteger (state, sub_pciid & 0xFFFF);
+    /* subdevice ID */
+    lua_pushinteger (state, sub_pciid >> 16);
+
+    addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
+    class = grub_pci_read (addr);
+    /* base class */
+    lua_pushinteger (state, class >> 24);
+    /* sub class */
+    lua_pushinteger (state, 0xFF & (class >> 16));
+
+    lua_call (state, 9, 1);
+    result = lua_tointeger (state, -1);
+    lua_pop (state, 1);
+
+    return result;
+  }
+
+  luaL_checktype (state, 1, LUA_TFUNCTION);
+  grub_pci_iterate (enum_pci);
+  return push_result (state);
+}
+
+static int
 grub_lua_file_open (lua_State *state)
 {
   grub_file_t file;
@@ -446,6 +494,7 @@
     {"setenv", grub_lua_setenv},
     {"enum_device", grub_lua_enum_device},
     {"enum_file", grub_lua_enum_file},
+    {"enum_pci", grub_lua_enum_pci},
     {"file_open", grub_lua_file_open},
     {"file_close", grub_lua_file_close},
     {"file_seek", grub_lua_file_seek},

