Blame SOURCES/0393-Make-PCI-init-in-i386-qemu-port-more-robust.patch

f96e0b
From d164941306b06f408c3b2fb6a3176d1b8e2412d1 Mon Sep 17 00:00:00 2001
f96e0b
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
f96e0b
Date: Mon, 29 Apr 2013 15:09:39 +0200
f96e0b
Subject: [PATCH 393/482] 	Make PCI init in i386-qemu port more robust.
f96e0b
f96e0b
---
f96e0b
 ChangeLog                           |   6 +-
f96e0b
 grub-core/Makefile.core.def         |   4 +-
f96e0b
 grub-core/bus/usb/uhci.c            |  10 +-
f96e0b
 grub-core/disk/ahci.c               |   3 -
f96e0b
 grub-core/kern/i386/coreboot/init.c |  22 +--
f96e0b
 grub-core/kern/i386/qemu/init.c     | 284 ++++++++++++++++++++++++++++++++++++
f96e0b
 grub-core/kern/mips/loongson/init.c |   3 +-
f96e0b
 grub-core/kern/vga_init.c           |  35 -----
f96e0b
 include/grub/pci.h                  |   1 +
f96e0b
 9 files changed, 299 insertions(+), 69 deletions(-)
f96e0b
 create mode 100644 grub-core/kern/i386/qemu/init.c
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index 86effa0..ece8586 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,4 +1,8 @@
f96e0b
-2013-04-29 Vladimir Testov <vladimir.testov@rosalab.ru>
f96e0b
+2013-04-29  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
+
f96e0b
+	Make PCI init in i386-qemu port more robust.
f96e0b
+
f96e0b
+2013-04-29  Vladimir Testov <vladimir.testov@rosalab.ru>
f96e0b
 
f96e0b
 	* grub-core/gfxmenu/gui_list.c: Refresh first_shown_entry value when
f96e0b
 	cached view is reused.
f96e0b
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
f96e0b
index ebcd01d..7e19acb 100644
f96e0b
--- a/grub-core/Makefile.core.def
f96e0b
+++ b/grub-core/Makefile.core.def
f96e0b
@@ -134,7 +134,9 @@ kernel = {
f96e0b
 
f96e0b
   i386 = kern/i386/dl.c;
f96e0b
 
f96e0b
-  i386_coreboot_multiboot_qemu = kern/i386/coreboot/init.c;
f96e0b
+  i386_coreboot = kern/i386/coreboot/init.c;
f96e0b
+  i386_multiboot = kern/i386/coreboot/init.c;
f96e0b
+  i386_qemu = kern/i386/qemu/init.c;
f96e0b
   i386_coreboot_multiboot_qemu = term/i386/pc/vga_text.c;
f96e0b
 
f96e0b
   efi = disk/efi/efidisk.c;
f96e0b
diff --git a/grub-core/bus/usb/uhci.c b/grub-core/bus/usb/uhci.c
f96e0b
index c2e2e7e..0fca1a1 100644
f96e0b
--- a/grub-core/bus/usb/uhci.c
f96e0b
+++ b/grub-core/bus/usb/uhci.c
f96e0b
@@ -236,15 +236,7 @@ grub_uhci_pci_iter (grub_pci_device_t dev,
f96e0b
     return 0;
f96e0b
 
f96e0b
   if ((base & GRUB_UHCI_IOMASK) == 0)
f96e0b
-    {
f96e0b
-#if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_QEMU)
f96e0b
-      static int ndevs = 0;
f96e0b
-      base = 0x1800 + ndevs++ * 0x100;
f96e0b
-      grub_pci_write (addr, base | GRUB_PCI_ADDR_SPACE_IO);
f96e0b
-#else
f96e0b
-      return 0;
f96e0b
-#endif
f96e0b
-    }
f96e0b
+    return 0;
f96e0b
 
f96e0b
   grub_dprintf ("uhci", "base = %x\n", base);
f96e0b
 
f96e0b
diff --git a/grub-core/disk/ahci.c b/grub-core/disk/ahci.c
f96e0b
index 554fcc5..58bc190 100644
f96e0b
--- a/grub-core/disk/ahci.c
f96e0b
+++ b/grub-core/disk/ahci.c
f96e0b
@@ -185,9 +185,6 @@ grub_ahci_pciinit (grub_pci_device_t dev,
f96e0b
 
f96e0b
   addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG5);
f96e0b
 
f96e0b
-#ifdef GRUB_MACHINE_QEMU
f96e0b
-  grub_pci_write (addr, 0xf4000000);
f96e0b
-#endif
f96e0b
   bar = grub_pci_read (addr);
f96e0b
 
f96e0b
   if ((bar & (GRUB_PCI_ADDR_SPACE_MASK | GRUB_PCI_ADDR_MEM_TYPE_MASK
f96e0b
diff --git a/grub-core/kern/i386/coreboot/init.c b/grub-core/kern/i386/coreboot/init.c
f96e0b
index bfc8f3f..7cd530d 100644
f96e0b
--- a/grub-core/kern/i386/coreboot/init.c
f96e0b
+++ b/grub-core/kern/i386/coreboot/init.c
f96e0b
@@ -1,6 +1,6 @@
f96e0b
 /*
f96e0b
  *  GRUB  --  GRand Unified Bootloader
f96e0b
- *  Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009  Free Software Foundation, Inc.
f96e0b
+ *  Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2013  Free Software Foundation, Inc.
f96e0b
  *
f96e0b
  *  GRUB is free software: you can redistribute it and/or modify
f96e0b
  *  it under the terms of the GNU General Public License as published by
f96e0b
@@ -34,9 +34,6 @@
f96e0b
 #include <grub/cpu/io.h>
f96e0b
 #include <grub/cpu/floppy.h>
f96e0b
 #include <grub/cpu/tsc.h>
f96e0b
-#ifdef GRUB_MACHINE_QEMU
f96e0b
-#include <grub/machine/kernel.h>
f96e0b
-#endif
f96e0b
 
f96e0b
 extern grub_uint8_t _start[];
f96e0b
 extern grub_uint8_t _end[];
f96e0b
@@ -51,12 +48,8 @@ grub_exit (void)
f96e0b
     grub_cpu_idle ();
f96e0b
 }
f96e0b
 
f96e0b
-#ifdef GRUB_MACHINE_QEMU
f96e0b
-grub_addr_t grub_modbase;
f96e0b
-#else
f96e0b
 grub_addr_t grub_modbase = GRUB_KERNEL_I386_COREBOOT_MODULES_ADDR;
f96e0b
 static grub_uint64_t modend;
f96e0b
-#endif
f96e0b
 
f96e0b
 /* Helper for grub_machine_init.  */
f96e0b
 static int
f96e0b
@@ -80,10 +73,8 @@ heap_init (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type,
f96e0b
   if (begin < GRUB_MEMORY_MACHINE_LOWER_SIZE)
f96e0b
     begin = GRUB_MEMORY_MACHINE_LOWER_SIZE;
f96e0b
 
f96e0b
-#ifndef GRUB_MACHINE_QEMU
f96e0b
   if (modend && begin < modend)
f96e0b
     begin = modend;
f96e0b
-#endif
f96e0b
   
f96e0b
   if (end <= begin)
f96e0b
     return 0;
f96e0b
@@ -96,18 +87,11 @@ heap_init (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type,
f96e0b
 void
f96e0b
 grub_machine_init (void)
f96e0b
 {
f96e0b
-#ifdef GRUB_MACHINE_QEMU
f96e0b
-  grub_modbase = grub_core_entry_addr + (_edata - _start);
f96e0b
-
f96e0b
-  grub_qemu_init_cirrus ();
f96e0b
-#endif
f96e0b
-#ifndef GRUB_MACHINE_QEMU
f96e0b
   modend = grub_modules_get_end ();
f96e0b
-#endif
f96e0b
-  /* Initialize the console as early as possible.  */
f96e0b
+
f96e0b
   grub_vga_text_init ();
f96e0b
 
f96e0b
-#if defined (GRUB_MACHINE_MULTIBOOT) || defined (GRUB_MACHINE_QEMU)
f96e0b
+#ifdef GRUB_MACHINE_MULTIBOOT
f96e0b
   grub_machine_mmap_init ();
f96e0b
 #endif
f96e0b
   grub_machine_mmap_iterate (heap_init, NULL);
f96e0b
diff --git a/grub-core/kern/i386/qemu/init.c b/grub-core/kern/i386/qemu/init.c
f96e0b
new file mode 100644
f96e0b
index 0000000..cad6c40
f96e0b
--- /dev/null
f96e0b
+++ b/grub-core/kern/i386/qemu/init.c
f96e0b
@@ -0,0 +1,284 @@
f96e0b
+/*
f96e0b
+ *  GRUB  --  GRand Unified Bootloader
f96e0b
+ *  Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2013  Free Software Foundation, Inc.
f96e0b
+ *
f96e0b
+ *  GRUB is free software: you can redistribute it and/or modify
f96e0b
+ *  it under the terms of the GNU General Public License as published by
f96e0b
+ *  the Free Software Foundation, either version 3 of the License, or
f96e0b
+ *  (at your option) any later version.
f96e0b
+ *
f96e0b
+ *  GRUB is distributed in the hope that it will be useful,
f96e0b
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
f96e0b
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f96e0b
+ *  GNU General Public License for more details.
f96e0b
+ *
f96e0b
+ *  You should have received a copy of the GNU General Public License
f96e0b
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
f96e0b
+ */
f96e0b
+
f96e0b
+#include <grub/kernel.h>
f96e0b
+#include <grub/mm.h>
f96e0b
+#include <grub/machine/time.h>
f96e0b
+#include <grub/machine/memory.h>
f96e0b
+#include <grub/machine/console.h>
f96e0b
+#include <grub/offsets.h>
f96e0b
+#include <grub/types.h>
f96e0b
+#include <grub/err.h>
f96e0b
+#include <grub/dl.h>
f96e0b
+#include <grub/misc.h>
f96e0b
+#include <grub/loader.h>
f96e0b
+#include <grub/env.h>
f96e0b
+#include <grub/cache.h>
f96e0b
+#include <grub/time.h>
f96e0b
+#include <grub/symbol.h>
f96e0b
+#include <grub/cpu/io.h>
f96e0b
+#include <grub/cpu/floppy.h>
f96e0b
+#include <grub/cpu/tsc.h>
f96e0b
+#include <grub/machine/kernel.h>
f96e0b
+#include <grub/pci.h>
f96e0b
+
f96e0b
+extern grub_uint8_t _start[];
f96e0b
+extern grub_uint8_t _end[];
f96e0b
+extern grub_uint8_t _edata[];
f96e0b
+
f96e0b
+void  __attribute__ ((noreturn))
f96e0b
+grub_exit (void)
f96e0b
+{
f96e0b
+  /* We can't use grub_fatal() in this function.  This would create an infinite
f96e0b
+     loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit().  */
f96e0b
+  while (1)
f96e0b
+    grub_cpu_idle ();
f96e0b
+}
f96e0b
+
f96e0b
+grub_addr_t grub_modbase;
f96e0b
+
f96e0b
+/* Helper for grub_machine_init.  */
f96e0b
+static int
f96e0b
+heap_init (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type,
f96e0b
+	   void *data __attribute__ ((unused)))
f96e0b
+{
f96e0b
+  grub_uint64_t begin = addr, end = addr + size;
f96e0b
+
f96e0b
+#if GRUB_CPU_SIZEOF_VOID_P == 4
f96e0b
+  /* Restrict ourselves to 32-bit memory space.  */
f96e0b
+  if (begin > GRUB_ULONG_MAX)
f96e0b
+    return 0;
f96e0b
+  if (end > GRUB_ULONG_MAX)
f96e0b
+    end = GRUB_ULONG_MAX;
f96e0b
+#endif
f96e0b
+
f96e0b
+  if (type != GRUB_MEMORY_AVAILABLE)
f96e0b
+    return 0;
f96e0b
+
f96e0b
+  /* Avoid the lower memory.  */
f96e0b
+  if (begin < GRUB_MEMORY_MACHINE_LOWER_SIZE)
f96e0b
+    begin = GRUB_MEMORY_MACHINE_LOWER_SIZE;
f96e0b
+
f96e0b
+  if (end <= begin)
f96e0b
+    return 0;
f96e0b
+
f96e0b
+  grub_mm_init_region ((void *) (grub_addr_t) begin, (grub_size_t) (end - begin));
f96e0b
+
f96e0b
+  return 0;
f96e0b
+}
f96e0b
+
f96e0b
+struct resource
f96e0b
+{
f96e0b
+  grub_pci_device_t dev;
f96e0b
+  int type;
f96e0b
+  grub_size_t size;
f96e0b
+  int bar;
f96e0b
+};
f96e0b
+
f96e0b
+struct iterator_ctx
f96e0b
+{
f96e0b
+  struct resource *resources;
f96e0b
+  grub_size_t nresources;
f96e0b
+};
f96e0b
+
f96e0b
+static int
f96e0b
+count_cards (grub_pci_device_t dev __attribute__ ((unused)),
f96e0b
+	     grub_pci_id_t pciid __attribute__ ((unused)),
f96e0b
+	     void *data)
f96e0b
+{
f96e0b
+  int *cnt = data;
f96e0b
+
f96e0b
+  (*cnt)++;
f96e0b
+
f96e0b
+  return 0;
f96e0b
+}
f96e0b
+
f96e0b
+static int
f96e0b
+find_resources (grub_pci_device_t dev,
f96e0b
+		grub_pci_id_t pciid __attribute__ ((unused)),
f96e0b
+		void *data)
f96e0b
+{
f96e0b
+  struct iterator_ctx *ctx = data;
f96e0b
+  int bar;
f96e0b
+
f96e0b
+  for (bar = 0; bar < 6; bar++)
f96e0b
+    {
f96e0b
+      grub_pci_address_t addr;
f96e0b
+      grub_uint32_t ones, zeros, mask;
f96e0b
+      struct resource *res;
f96e0b
+      addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0
f96e0b
+				    + 4 * bar);
f96e0b
+      grub_pci_write (addr, 0xffffffff);
f96e0b
+      grub_pci_read (addr);
f96e0b
+      ones = grub_pci_read (addr);
f96e0b
+      grub_pci_write (addr, 0);
f96e0b
+      grub_pci_read (addr);
f96e0b
+      zeros = grub_pci_read (addr);
f96e0b
+      if (ones == zeros)
f96e0b
+	continue;
f96e0b
+      res = &ctx->resources[ctx->nresources++];
f96e0b
+      if ((zeros & GRUB_PCI_ADDR_SPACE_MASK) == GRUB_PCI_ADDR_SPACE_IO)
f96e0b
+	mask = GRUB_PCI_ADDR_SPACE_MASK;
f96e0b
+      else
f96e0b
+	mask = (GRUB_PCI_ADDR_MEM_TYPE_MASK | GRUB_PCI_ADDR_SPACE_MASK | GRUB_PCI_ADDR_MEM_PREFETCH);
f96e0b
+
f96e0b
+      res->type = ones & mask;
f96e0b
+      res->dev = dev;
f96e0b
+      res->bar = bar;
f96e0b
+      res->size = (~((zeros ^ ones)) | mask) + 1;
f96e0b
+      if ((zeros & (GRUB_PCI_ADDR_MEM_TYPE_MASK | GRUB_PCI_ADDR_SPACE_MASK))
f96e0b
+	  == (GRUB_PCI_ADDR_SPACE_MEMORY | GRUB_PCI_ADDR_MEM_TYPE_64))
f96e0b
+	bar++;
f96e0b
+    }
f96e0b
+  return 0;
f96e0b
+}
f96e0b
+
f96e0b
+static int
f96e0b
+enable_cards (grub_pci_device_t dev,
f96e0b
+	      grub_pci_id_t pciid __attribute__ ((unused)),
f96e0b
+	      void *data __attribute__ ((unused)))
f96e0b
+{
f96e0b
+  grub_uint16_t cmd = 0;
f96e0b
+  grub_pci_address_t addr;
f96e0b
+  grub_uint32_t class;
f96e0b
+  int bar;
f96e0b
+
f96e0b
+  for (bar = 0; bar < 6; bar++)
f96e0b
+    {
f96e0b
+      grub_uint32_t val;
f96e0b
+      addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0
f96e0b
+				    + 4 * bar);
f96e0b
+      val = grub_pci_read (addr);
f96e0b
+      if (!val)
f96e0b
+	continue;
f96e0b
+      if ((val & GRUB_PCI_ADDR_SPACE_MASK) == GRUB_PCI_ADDR_SPACE_IO)
f96e0b
+	cmd |= GRUB_PCI_COMMAND_IO_ENABLED;
f96e0b
+      else
f96e0b
+	cmd |= GRUB_PCI_COMMAND_MEM_ENABLED;
f96e0b
+    }
f96e0b
+
f96e0b
+  class = (grub_pci_read (addr) >> 16) & 0xffff;
f96e0b
+
f96e0b
+  if (class == GRUB_PCI_CLASS_SUBCLASS_VGA)
f96e0b
+    cmd |= GRUB_PCI_COMMAND_IO_ENABLED
f96e0b
+      | GRUB_PCI_COMMAND_MEM_ENABLED;
f96e0b
+
f96e0b
+  if (class == GRUB_PCI_CLASS_SUBCLASS_USB)
f96e0b
+    return 0;
f96e0b
+  
f96e0b
+  addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND);
f96e0b
+  grub_pci_write (addr, cmd);
f96e0b
+
f96e0b
+  return 0;
f96e0b
+}
f96e0b
+
f96e0b
+static void
f96e0b
+grub_pci_assign_addresses (void)
f96e0b
+{
f96e0b
+  int ncards = 0;
f96e0b
+  struct iterator_ctx ctx;
f96e0b
+
f96e0b
+  grub_pci_iterate (count_cards, &ncards);
f96e0b
+
f96e0b
+  {
f96e0b
+    struct resource resources[ncards * 6];
f96e0b
+    int done;
f96e0b
+    unsigned i;
f96e0b
+    ctx.nresources = 0;
f96e0b
+    ctx.resources = resources;
f96e0b
+    grub_uint32_t memptr = 0xf0000000;
f96e0b
+    grub_uint16_t ioptr = 0x1000;
f96e0b
+
f96e0b
+    grub_pci_iterate (find_resources, &ctx;;
f96e0b
+    /* FIXME: do we need a better sort here?  */
f96e0b
+    do
f96e0b
+      {
f96e0b
+	done = 0;
f96e0b
+	for (i = 0; i + 1 < ctx.nresources; i++)
f96e0b
+	  if (resources[i].size < resources[i+1].size)
f96e0b
+	    {
f96e0b
+	      struct resource t;
f96e0b
+	      t = resources[i];
f96e0b
+	      resources[i] = resources[i+1];
f96e0b
+	      resources[i+1] = t;
f96e0b
+	      done = 1;
f96e0b
+	    }
f96e0b
+      }
f96e0b
+    while (done);
f96e0b
+
f96e0b
+    for (i = 0; i < ctx.nresources; i++)
f96e0b
+      {
f96e0b
+	grub_pci_address_t addr;
f96e0b
+	addr = grub_pci_make_address (resources[i].dev,
f96e0b
+				      GRUB_PCI_REG_ADDRESS_REG0
f96e0b
+				      + 4 * resources[i].bar);
f96e0b
+	if ((resources[i].type & GRUB_PCI_ADDR_SPACE_MASK)
f96e0b
+	    == GRUB_PCI_ADDR_SPACE_IO)
f96e0b
+	  {
f96e0b
+	    grub_pci_write (addr, ioptr | resources[i].type);
f96e0b
+	    ioptr += resources[i].size;
f96e0b
+	  }
f96e0b
+	else
f96e0b
+	  {
f96e0b
+	    grub_pci_write (addr, memptr | resources[i].type);
f96e0b
+	    memptr += resources[i].size;
f96e0b
+	    if ((resources[i].type & (GRUB_PCI_ADDR_MEM_TYPE_MASK
f96e0b
+				      | GRUB_PCI_ADDR_SPACE_MASK))
f96e0b
+		== (GRUB_PCI_ADDR_SPACE_MEMORY | GRUB_PCI_ADDR_MEM_TYPE_64))
f96e0b
+	      {
f96e0b
+		addr = grub_pci_make_address (resources[i].dev,
f96e0b
+					      GRUB_PCI_REG_ADDRESS_REG0
f96e0b
+					      + 4 * resources[i].bar + 4);
f96e0b
+		grub_pci_write (addr, 0);
f96e0b
+	      }
f96e0b
+	  }	  
f96e0b
+      }
f96e0b
+    grub_pci_iterate (enable_cards, NULL);
f96e0b
+  }
f96e0b
+}
f96e0b
+
f96e0b
+void
f96e0b
+grub_machine_init (void)
f96e0b
+{
f96e0b
+  grub_modbase = grub_core_entry_addr + (_edata - _start);
f96e0b
+
f96e0b
+  grub_pci_assign_addresses ();
f96e0b
+
f96e0b
+  grub_qemu_init_cirrus ();
f96e0b
+
f96e0b
+  grub_vga_text_init ();
f96e0b
+
f96e0b
+  grub_machine_mmap_init ();
f96e0b
+  grub_machine_mmap_iterate (heap_init, NULL);
f96e0b
+
f96e0b
+
f96e0b
+  grub_tsc_init ();
f96e0b
+}
f96e0b
+
f96e0b
+void
f96e0b
+grub_machine_get_bootlocation (char **device __attribute__ ((unused)),
f96e0b
+			       char **path __attribute__ ((unused)))
f96e0b
+{
f96e0b
+}
f96e0b
+
f96e0b
+void
f96e0b
+grub_machine_fini (void)
f96e0b
+{
f96e0b
+  grub_vga_text_fini ();
f96e0b
+  grub_stop_floppy ();
f96e0b
+}
f96e0b
diff --git a/grub-core/kern/mips/loongson/init.c b/grub-core/kern/mips/loongson/init.c
f96e0b
index 1abcf1a..52cbfd4 100644
f96e0b
--- a/grub-core/kern/mips/loongson/init.c
f96e0b
+++ b/grub-core/kern/mips/loongson/init.c
f96e0b
@@ -55,7 +55,8 @@ set_card (grub_pci_device_t dev, grub_pci_id_t pciid,
f96e0b
 	  void *data __attribute__ ((unused)))
f96e0b
 {
f96e0b
   grub_pci_address_t addr;
f96e0b
-  /* FIXME: autoscan for BARs and devices.  */
f96e0b
+  /* We could use grub_pci_assign_addresses for this but we prefer to
f96e0b
+     have exactly same memory map as on pmon.  */
f96e0b
   switch (pciid)
f96e0b
     {
f96e0b
     case GRUB_LOONGSON_OHCI_PCIID:
f96e0b
diff --git a/grub-core/kern/vga_init.c b/grub-core/kern/vga_init.c
f96e0b
index 1119bb3..301721d 100644
f96e0b
--- a/grub-core/kern/vga_init.c
f96e0b
+++ b/grub-core/kern/vga_init.c
f96e0b
@@ -88,44 +88,9 @@ load_palette (void)
f96e0b
     grub_vga_palette_write (i, colors[i].r, colors[i].g, colors[i].b);
f96e0b
 }
f96e0b
 
f96e0b
-#ifndef __mips__
f96e0b
-/* Helper for grub_qemu_init_cirrus.  */
f96e0b
-static int
f96e0b
-find_card (grub_pci_device_t dev, grub_pci_id_t pciid __attribute__ ((unused)),
f96e0b
-	   void *data __attribute__ ((unused)))
f96e0b
-{
f96e0b
-  grub_pci_address_t addr;
f96e0b
-  grub_uint32_t class;
f96e0b
-
f96e0b
-  addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
f96e0b
-  class = grub_pci_read (addr);
f96e0b
-
f96e0b
-  if (((class >> 16) & 0xffff) != GRUB_PCI_CLASS_SUBCLASS_VGA)
f96e0b
-    return 0;
f96e0b
-  
f96e0b
-  /* FIXME: chooose addresses dynamically.  */
f96e0b
-  addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0);
f96e0b
-  grub_pci_write (addr, 0xf0000000 | GRUB_PCI_ADDR_MEM_PREFETCH
f96e0b
-		  | GRUB_PCI_ADDR_SPACE_MEMORY | GRUB_PCI_ADDR_MEM_TYPE_32);
f96e0b
-  addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG1);
f96e0b
-  grub_pci_write (addr, 0xf2000000
f96e0b
-		  | GRUB_PCI_ADDR_SPACE_MEMORY | GRUB_PCI_ADDR_MEM_TYPE_32);
f96e0b
-
f96e0b
-  addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND);
f96e0b
-  grub_pci_write (addr, GRUB_PCI_COMMAND_MEM_ENABLED
f96e0b
-		  | GRUB_PCI_COMMAND_IO_ENABLED);
f96e0b
-  
f96e0b
-  return 1;
f96e0b
-}
f96e0b
-#endif
f96e0b
-
f96e0b
 void
f96e0b
 grub_qemu_init_cirrus (void)
f96e0b
 {
f96e0b
-#ifndef __mips__
f96e0b
-  grub_pci_iterate (find_card, NULL);
f96e0b
-#endif
f96e0b
-
f96e0b
   grub_outb (GRUB_VGA_IO_MISC_COLOR,
f96e0b
 	     GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_MISC_WRITE);
f96e0b
 
f96e0b
diff --git a/include/grub/pci.h b/include/grub/pci.h
f96e0b
index e163d47..70d9a05 100644
f96e0b
--- a/include/grub/pci.h
f96e0b
+++ b/include/grub/pci.h
f96e0b
@@ -81,6 +81,7 @@
f96e0b
 #define  GRUB_PCI_STATUS_DEVSEL_TIMING_SHIFT 9
f96e0b
 #define  GRUB_PCI_STATUS_DEVSEL_TIMING_MASK 0x0600
f96e0b
 #define  GRUB_PCI_CLASS_SUBCLASS_VGA  0x0300
f96e0b
+#define  GRUB_PCI_CLASS_SUBCLASS_USB  0x0c03
f96e0b
 
f96e0b
 #ifndef ASM_FILE
f96e0b
 
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b