a5bd9f6
From 4a1875b61089e467165be46a7e538e8beb47d8ac Mon Sep 17 00:00:00 2001
a5bd9f6
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
a5bd9f6
Date: Fri, 12 Apr 2013 14:49:33 +0200
a5bd9f6
Subject: [PATCH 286/364] 	Turn off QEMU ACPI-way since new releases
a5bd9f6
 don't have shutdown port 	anymore.
a5bd9f6
a5bd9f6
---
a5bd9f6
 ChangeLog                                   |  5 +++++
a5bd9f6
 Makefile.am                                 | 35 ++++++++++++++---------------
a5bd9f6
 grub-core/lib/i386/halt.c                   | 23 ++++++++++++++++++-
a5bd9f6
 grub-core/tests/boot/kfreebsd.init-i386.S   |  6 ++---
a5bd9f6
 grub-core/tests/boot/kfreebsd.init-x86_64.S |  2 +-
a5bd9f6
 grub-core/tests/boot/qemu-shutdown-x86.S    |  7 +++---
a5bd9f6
 6 files changed, 51 insertions(+), 27 deletions(-)
a5bd9f6
a5bd9f6
diff --git a/ChangeLog b/ChangeLog
a5bd9f6
index 5212955..1c77abf 100644
a5bd9f6
--- a/ChangeLog
a5bd9f6
+++ b/ChangeLog
a5bd9f6
@@ -1,5 +1,10 @@
a5bd9f6
 2013-04-12  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
 
a5bd9f6
+	Turn off QEMU ACPI-way since new releases don't have shutdown port
a5bd9f6
+	anymore.
a5bd9f6
+
a5bd9f6
+2013-04-12  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
+
a5bd9f6
 	* docs/grub.texi: Update coreboot status info.
a5bd9f6
 
a5bd9f6
 2013-04-12  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
diff --git a/Makefile.am b/Makefile.am
a5bd9f6
index 30aa5a7..9d38405 100644
a5bd9f6
--- a/Makefile.am
a5bd9f6
+++ b/Makefile.am
a5bd9f6
@@ -153,10 +153,10 @@ if COND_x86_64_efi
a5bd9f6
 QEMU32=qemu-system-x86_64
a5bd9f6
 endif
a5bd9f6
 
a5bd9f6
-linux.init.x86_64: $(srcdir)/grub-core/tests/boot/linux.init-x86_64.S
a5bd9f6
+linux.init.x86_64: $(srcdir)/grub-core/tests/boot/linux.init-x86_64.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
a5bd9f6
 	$(TARGET_CC) -o $@ $< -m64 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
a5bd9f6
 
a5bd9f6
-linux.init.i386: $(srcdir)/grub-core/tests/boot/linux.init-i386.S
a5bd9f6
+linux.init.i386: $(srcdir)/grub-core/tests/boot/linux.init-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
a5bd9f6
 	$(TARGET_CC) -o $@ $< -m32 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
a5bd9f6
 
a5bd9f6
 linux.init.mips: $(srcdir)/grub-core/tests/boot/linux.init-mips.S
a5bd9f6
@@ -171,46 +171,46 @@ linux.init.mipsel: $(srcdir)/grub-core/tests/boot/linux.init-mips.S
a5bd9f6
 linux.init.loongson: $(srcdir)/grub-core/tests/boot/linux.init-mips.S
a5bd9f6
 	$(TARGET_CC) -o $@ $< -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -DREBOOT=1
a5bd9f6
 
a5bd9f6
-multiboot.elf: $(srcdir)/grub-core/tests/boot/kernel-i386.S
a5bd9f6
+multiboot.elf: $(srcdir)/grub-core/tests/boot/kernel-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
a5bd9f6
 	$(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -DTARGET_MULTIBOOT=1 -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include
a5bd9f6
 
a5bd9f6
-kfreebsd.elf: $(srcdir)/grub-core/tests/boot/kernel-i386.S
a5bd9f6
+kfreebsd.elf: $(srcdir)/grub-core/tests/boot/kernel-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
a5bd9f6
 	$(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include
a5bd9f6
 
a5bd9f6
 kfreebsd.aout: kfreebsd.elf
a5bd9f6
 	$(OBJCOPY) -O a.out-i386-linux $< $@ -R .note.gnu.build-id -R .note.gnu.gold-version
a5bd9f6
 
a5bd9f6
-pc-chainloader.elf: $(srcdir)/grub-core/tests/boot/kernel-8086.S
a5bd9f6
+pc-chainloader.elf: $(srcdir)/grub-core/tests/boot/kernel-8086.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
a5bd9f6
 	$(TARGET_CC) -o $@ $< -DTARGET_CHAINLOADER=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x7c00 -m32
a5bd9f6
 
a5bd9f6
 pc-chainloader.bin: pc-chainloader.elf
a5bd9f6
 	$(OBJCOPY) -O binary --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn -R .note.gnu.gold-version $< $@;
a5bd9f6
 
a5bd9f6
-ntldr.elf: $(srcdir)/grub-core/tests/boot/kernel-8086.S
a5bd9f6
+ntldr.elf: $(srcdir)/grub-core/tests/boot/kernel-8086.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
a5bd9f6
 	$(TARGET_CC) -o $@ $< -DTARGET_NTLDR=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0 -m32
a5bd9f6
 
a5bd9f6
 ntldr.bin: ntldr.elf
a5bd9f6
 	$(OBJCOPY) -O binary --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn -R .note.gnu.gold-version $< $@;
a5bd9f6
 
a5bd9f6
-multiboot2.elf: $(srcdir)/grub-core/tests/boot/kernel-i386.S
a5bd9f6
+multiboot2.elf: $(srcdir)/grub-core/tests/boot/kernel-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
a5bd9f6
 	$(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include -DTARGET_MULTIBOOT2=1
a5bd9f6
 
a5bd9f6
-kfreebsd.init.x86_64: $(srcdir)/grub-core/tests/boot/kfreebsd.init-x86_64.S
a5bd9f6
+kfreebsd.init.x86_64: $(srcdir)/grub-core/tests/boot/kfreebsd.init-x86_64.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
a5bd9f6
 	$(TARGET_CC) -o $@ $< -m64 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" && freebsd-brandelf -t FreeBSD $@
a5bd9f6
 
a5bd9f6
-kfreebsd.init.i386: $(srcdir)/grub-core/tests/boot/kfreebsd.init-i386.S
a5bd9f6
+kfreebsd.init.i386: $(srcdir)/grub-core/tests/boot/kfreebsd.init-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
a5bd9f6
 	$(TARGET_CC) -o $@ $< -m32 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" && freebsd-brandelf -t FreeBSD $@
a5bd9f6
 
a5bd9f6
-knetbsd.init.i386: $(srcdir)/grub-core/tests/boot/kbsd.init-i386.S
a5bd9f6
+knetbsd.init.i386: $(srcdir)/grub-core/tests/boot/kbsd.init-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
a5bd9f6
 	$(TARGET_CC) -o $@ $< -m32 -nostdlib -nostdinc -DTARGET_NETBSD=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
a5bd9f6
 
a5bd9f6
-kopenbsd.init.i386: $(srcdir)/grub-core/tests/boot/kbsd.init-i386.S
a5bd9f6
+kopenbsd.init.i386: $(srcdir)/grub-core/tests/boot/kbsd.init-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
a5bd9f6
 	$(TARGET_CC) -o $@ $< -m32 -nostdlib -nostdinc -DTARGET_OPENBSD=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
a5bd9f6
 
a5bd9f6
-knetbsd.init.x86_64: $(srcdir)/grub-core/tests/boot/kbsd.init-x86_64.S
a5bd9f6
+knetbsd.init.x86_64: $(srcdir)/grub-core/tests/boot/kbsd.init-x86_64.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
a5bd9f6
 	$(TARGET_CC) -o $@ $< -m64 -DTARGET_NETBSD=1 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
a5bd9f6
 
a5bd9f6
-kopenbsd.init.x86_64: $(srcdir)/grub-core/tests/boot/kbsd.init-x86_64.S
a5bd9f6
+kopenbsd.init.x86_64: $(srcdir)/grub-core/tests/boot/kbsd.init-x86_64.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S
a5bd9f6
 	$(TARGET_CC) -o $@ $< -m64 -DTARGET_OPENBSD=1 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
a5bd9f6
 
a5bd9f6
 linux-initramfs.mips: linux.init.mips Makefile
a5bd9f6
@@ -335,18 +335,17 @@ BOOTCHECKS = bootcheck-kfreebsd-aout bootcheck-kopenbsd-i386 bootcheck-kopenbsd-
a5bd9f6
 endif
a5bd9f6
 
a5bd9f6
 if COND_i386_multiboot
a5bd9f6
-# Freebsd crashes because memory at 0-0x1000 is occupied and requires ACPI
a5bd9f6
+# FreeBSD requires ACPI
a5bd9f6
 BOOTCHECKS = bootcheck-kfreebsd-aout bootcheck-kopenbsd-i386 bootcheck-kopenbsd-x86_64 bootcheck-multiboot bootcheck-multiboot2 bootcheck-linux-i386 bootcheck-linux-x86_64 bootcheck-knetbsd-x86_64
a5bd9f6
 endif
a5bd9f6
 
a5bd9f6
 if COND_i386_coreboot
a5bd9f6
-# 64-bit NetBSD crashes because memory at 0-0x1000 is occupied
a5bd9f6
-# Freebsd crashes because memory at 0-0x1000 is occupied and requires ACPI
a5bd9f6
-BOOTCHECKS = bootcheck-kfreebsd-aout bootcheck-kopenbsd-i386 bootcheck-kopenbsd-x86_64 bootcheck-multiboot bootcheck-multiboot2 bootcheck-linux-i386 bootcheck-linux-x86_64
a5bd9f6
+# Freebsd requires ACPI
a5bd9f6
+BOOTCHECKS = bootcheck-kfreebsd-aout bootcheck-kopenbsd-i386 bootcheck-kopenbsd-x86_64 bootcheck-multiboot bootcheck-multiboot2 bootcheck-linux-i386 bootcheck-linux-x86_64 bootcheck-knetbsd-x86_64
a5bd9f6
 endif
a5bd9f6
 
a5bd9f6
 if COND_i386_qemu
a5bd9f6
-# Freebsd crashes because memory at 0-0x1000 is occupied and requires ACPI
a5bd9f6
+# FreeBSD requires ACPI
a5bd9f6
 BOOTCHECKS = bootcheck-kfreebsd-aout bootcheck-kopenbsd-i386 bootcheck-kopenbsd-x86_64 bootcheck-multiboot bootcheck-multiboot2 bootcheck-linux-i386 bootcheck-linux-x86_64 bootcheck-knetbsd-x86_64
a5bd9f6
 endif
a5bd9f6
 
a5bd9f6
diff --git a/grub-core/lib/i386/halt.c b/grub-core/lib/i386/halt.c
a5bd9f6
index bd878c9..9f84054 100644
a5bd9f6
--- a/grub-core/lib/i386/halt.c
a5bd9f6
+++ b/grub-core/lib/i386/halt.c
a5bd9f6
@@ -20,6 +20,8 @@
a5bd9f6
 #include <grub/misc.h>
a5bd9f6
 #include <grub/acpi.h>
a5bd9f6
 #include <grub/i18n.h>
a5bd9f6
+#include <grub/pci.h>
a5bd9f6
+#include <grub/mm.h>
a5bd9f6
 
a5bd9f6
 const char bochs_shutdown[] = "Shutdown";
a5bd9f6
 
a5bd9f6
@@ -37,6 +39,23 @@ stop (void)
a5bd9f6
     }
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
+static int
a5bd9f6
+grub_shutdown_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
a5bd9f6
+			void *data __attribute__ ((unused)))
a5bd9f6
+{
a5bd9f6
+  /* QEMU.  */
a5bd9f6
+  if (pciid == 0x71138086)
a5bd9f6
+    {
a5bd9f6
+      grub_pci_address_t addr;
a5bd9f6
+      addr = grub_pci_make_address (dev, 0x40);
a5bd9f6
+      grub_pci_write (addr, 0x7001);
a5bd9f6
+      addr = grub_pci_make_address (dev, 0x80);
a5bd9f6
+      grub_pci_write (addr, grub_pci_read (addr) | 1);
a5bd9f6
+      grub_outw (0x2000, 0x7004);
a5bd9f6
+    }
a5bd9f6
+  return 0;
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
 void
a5bd9f6
 grub_halt (void)
a5bd9f6
 {
a5bd9f6
@@ -49,10 +68,12 @@ grub_halt (void)
a5bd9f6
   /* Disable interrupts.  */
a5bd9f6
   __asm__ __volatile__ ("cli");
a5bd9f6
 
a5bd9f6
-  /* Bochs, QEMU, etc.  */
a5bd9f6
+  /* Bochs, QEMU, etc. Removed in newer QEMU releases.  */
a5bd9f6
   for (i = 0; i < sizeof (bochs_shutdown) - 1; i++)
a5bd9f6
     grub_outb (bochs_shutdown[i], 0x8900);
a5bd9f6
 
a5bd9f6
+  grub_pci_iterate (grub_shutdown_pci_iter, NULL);
a5bd9f6
+
a5bd9f6
   grub_puts_ (N_("GRUB doesn't know how to halt this machine yet!"));
a5bd9f6
 
a5bd9f6
   /* In order to return we'd have to check what the previous status of IF
a5bd9f6
diff --git a/grub-core/tests/boot/kfreebsd.init-i386.S b/grub-core/tests/boot/kfreebsd.init-i386.S
a5bd9f6
index a448152..7a4baba 100644
a5bd9f6
--- a/grub-core/tests/boot/kfreebsd.init-i386.S
a5bd9f6
+++ b/grub-core/tests/boot/kfreebsd.init-i386.S
a5bd9f6
@@ -65,7 +65,7 @@ _start:
a5bd9f6
 
a5bd9f6
 	/* IOPERM.  */
a5bd9f6
 	movl $SYSCALL_ARCH, %eax
a5bd9f6
-	pushl $iopl_arg1
a5bd9f6
+	pushl $ioperm_arg1
a5bd9f6
 	pushl $SYSCALL_ARCH_IOPERM
a5bd9f6
 	pushl $0
a5bd9f6
 	int $SYSCALL_INT
a5bd9f6
@@ -73,7 +73,7 @@ _start:
a5bd9f6
 
a5bd9f6
 	/* IOPERM.  */
a5bd9f6
 	movl $SYSCALL_ARCH, %eax
a5bd9f6
-	pushl $iopl_arg2
a5bd9f6
+	pushl $ioperm_arg2
a5bd9f6
 	pushl $SYSCALL_ARCH_IOPERM
a5bd9f6
 	pushl $0
a5bd9f6
 	int $SYSCALL_INT
a5bd9f6
@@ -104,6 +104,6 @@ ioperm_arg1:
a5bd9f6
 	.long 8
a5bd9f6
 	.long 1
a5bd9f6
 ioperm_arg2:
a5bd9f6
-	.long 0x1000
a5bd9f6
+	.long 0x7000
a5bd9f6
 	.long 8
a5bd9f6
 	.long 1
a5bd9f6
diff --git a/grub-core/tests/boot/kfreebsd.init-x86_64.S b/grub-core/tests/boot/kfreebsd.init-x86_64.S
a5bd9f6
index de7bab6..05e5760 100644
a5bd9f6
--- a/grub-core/tests/boot/kfreebsd.init-x86_64.S
a5bd9f6
+++ b/grub-core/tests/boot/kfreebsd.init-x86_64.S
a5bd9f6
@@ -85,6 +85,6 @@ ioperm_arg1:
a5bd9f6
 	.long 8
a5bd9f6
 	.long 1
a5bd9f6
 ioperm_arg2:
a5bd9f6
-	.long 0x1000
a5bd9f6
+	.long 0x7000
a5bd9f6
 	.long 8
a5bd9f6
 	.long 1
a5bd9f6
diff --git a/grub-core/tests/boot/qemu-shutdown-x86.S b/grub-core/tests/boot/qemu-shutdown-x86.S
a5bd9f6
index 9f8bc40..e37f5df 100644
a5bd9f6
--- a/grub-core/tests/boot/qemu-shutdown-x86.S
a5bd9f6
+++ b/grub-core/tests/boot/qemu-shutdown-x86.S
a5bd9f6
@@ -1,18 +1,17 @@
a5bd9f6
 	movl $0x80000b80, %eax
a5bd9f6
 	movw $0xcf8, %dx
a5bd9f6
 	outl  %eax, %dx
a5bd9f6
-	movl $0x1001, %eax
a5bd9f6
 	movw $0xcfc, %dx
a5bd9f6
-	inb  %al, %dx
a5bd9f6
+	inb  %dx, %al
a5bd9f6
 	orb  $1, %al
a5bd9f6
 	outb  %al, %dx
a5bd9f6
 
a5bd9f6
 	movl $0x80000b40, %eax
a5bd9f6
 	movw $0xcf8, %dx
a5bd9f6
 	outl  %eax, %dx
a5bd9f6
-	movl $0x1001, %eax
a5bd9f6
+	movl $0x7001, %eax
a5bd9f6
 	movw $0xcfc, %dx
a5bd9f6
 	outl  %eax, %dx
a5bd9f6
 	movw $0x2000, %ax
a5bd9f6
-	movw $0x1004, %dx	
a5bd9f6
+	movw $0x7004, %dx	
a5bd9f6
 	outw  %ax, %dx
a5bd9f6
-- 
a5bd9f6
1.8.1.4
a5bd9f6