Index: vmm/include/core/vm.h
===================================================================
--- vmm/include/core/vm.h	(リビジョン 198)
+++ vmm/include/core/vm.h	(作業コピー)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2014 Yuichi Watanabe
+ * Copyright (c) 2010-2012 Yuichi Watanabe
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -39,7 +39,6 @@
 unsigned int vm_get_vcpu_count();
 char *vm_get_name();
 u32 vm_get_id(void);
-void vm_shutdown(void);
 
 /*
  * This function must called from "drivern" init funcs.
Index: vmm/io/acpi_emu.c
===================================================================
--- vmm/io/acpi_emu.c	(リビジョン 198)
+++ vmm/io/acpi_emu.c	(作業コピー)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2014 Yuichi Watanabe
+ * Copyright (c) 2013 Yuichi Watanabe
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,7 +29,6 @@
 
 #include <core/types.h>
 #include <core/initfunc.h>
-#include <core/io.h>
 #include <core/panic.h>
 #include <core/rm.h>
 #include <core/printf.h>
@@ -41,20 +40,12 @@
 #ifdef ACPI_DEBUG
 #define ACPI_DBG(...)						\
 	do {							\
-		printf("ACPIEMU: " __VA_ARGS__);			\
+		printf("ACPI: " __VA_ARGS__);			\
 	} while (0)
 #else
 #define ACPI_DBG(...)
 #endif
 
-#define ACPI_REG_SIZE		0x100
-#define ACPI_PM1A_CNT_OFFSET	0x04
-#define PM1_CNT_SLP_TYPX_MASK	0x1C00
-#define PM1_CNT_SLP_TYPX_SHIFT	10
-#define PM1_CNT_SLP_EN_BIT	0x2000
-#define PM1A_S5_TYPE		0 /* must match a value in
-				     bios/src/ssdt-misc.dsl */
-
 struct acpi_emu {
 	struct resource resource;
 };
@@ -62,45 +53,6 @@
 static drvdata_hdl_t acpi_handle;
 
 static void
-acpi_emu_pm1_sleep (u32 val)
-{
-	u8 type;
-
-	type = (val & PM1_CNT_SLP_TYPX_MASK) >> PM1_CNT_SLP_TYPX_SHIFT;
-	ACPI_DBG("acpi_emu_pm1_sleep 0x%x 0x%x\n", val, type);
-	if (type == PM1A_S5_TYPE) {
-		ACPI_DBG("shutdown\n");
-		vm_shutdown();
-	}
-}
-
-static int
-acpi_emu_pm1_cnt_reg (iotype_t type, ioport_t port, void *data)
-{
-	u32 val;
-
-	ACPI_DBG("acpi_emu_pm1_ctrl_reg 0x%x\n", type);
-
-	switch (type) {
-	case IOTYPE_OUTB:
-		val = *(u8 *)data;
-		break;
-	case IOTYPE_OUTW:
-		val = *(u16 *)data;
-		break;
-	case IOTYPE_OUTL:
-		val = *(u32 *)data;
-		break;
-	default:
-		return 1; /* emulated */
-	}
-	if ((val & PM1_CNT_SLP_EN_BIT) == 0) {
-		acpi_emu_pm1_sleep (val);
-	}
-	return 1; /* emulated */
-}
-
-static void
 acpi_emu_setup(void)
 {
 	struct acpi_emu *acpi;
@@ -113,15 +65,11 @@
 	acpi = vm_get_driver_data(acpi_handle);
 
 	err = rm_alloc_resource(vmrm_io_resource(), &acpi->resource,
-				ACPI_REG_SIZE, ACPI_REG_SIZE,
-				RESOURCE_TYPE_IO, 0,
+				0x100, 0x100, RESOURCE_TYPE_IO, 0,
 				"acpi_emu");
 	if (err != VMMERR_SUCCESS) {
 		panic("Can't find free ioport for ACPI device.");
 	}
-
-	set_iofunc(acpi->resource.start + ACPI_PM1A_CNT_OFFSET,
-		   acpi_emu_pm1_cnt_reg);
 }
 
 ioport_t
Index: vmm/core/acpi_aml.c
===================================================================
--- vmm/core/acpi_aml.c	(リビジョン 198)
+++ vmm/core/acpi_aml.c	(作業コピー)
@@ -139,16 +139,12 @@
 }
 #endif /* TTY_SERIAL */
 
+#ifdef DISABLE_SLEEP
 static int
-sx_callback(struct aml_name *name, va_list ap)
+s2_s3_callback(struct aml_name *name, va_list ap)
 {
 	union aml_object *sx;
-	union aml_object *elem;
-#ifdef DISABLE_SLEEP
 	int saved_flag;
-#endif
-	int sleep;
-	int i;
 
 	aml_print_curname(name);
 	AML_DEBUGPRINT("\n");
@@ -159,62 +155,41 @@
 		return 0; /* continue */
 	}
 
-	sleep = name->namep[2] - '0';
-
-	AML_DEBUGPRINT("elements %d\n", sx->package.elements);
-	for (i = 0; i < sx->package.elements; i++) {
-		if (i >= 2) {
-			continue;
-		}
-		elem = sx->package.objects[i];
-		if (elem->type == aml_t_num) {
-			acpi_sleep[sleep].valid = 1; /* valid */
-			acpi_sleep[sleep].type[i] = elem->num.number;
-			AML_DEBUGPRINT("val %d\n", elem->num.number);
-		}
-	}
-
-#ifdef DISABLE_SLEEP
-	if (sleep < 1 || sleep > 4) {
-		return 0; /* continue */
-	}
 	printf("Disabling ");
 	saved_flag = aml_debug;
 	aml_debug = 1;
 	aml_print_curname(name);
 	aml_debug = saved_flag;
 	printf("\n");
-	memcpy(name->namep, "Sx__", 4);
-	name->namep[1] = '0' + sleep;
-#endif /* DISABLE_SLEEP */
+
+	if (memcmp(name->namep, "_S2_", 4) == 0) {
+		memcpy(name->namep, "S2__", 4);
+	} else if (memcmp(name->namep, "_S3_", 4) == 0) {
+		memcpy(name->namep, "S3__", 4);
+	} else {
+		printf("Unexpected method name. 0x%4.4s\n", name->namep);
+	}
 	return 0; /* continue */
 }
 
 static void
-parse_sx(void)
+disable_s2_s3(void)
 {
 	aml_apply_foreach_found_objects(aml_get_rootname(),
-					"_S0_", sx_callback);
+					"_S2_", s2_s3_callback);
 	aml_apply_foreach_found_objects(aml_get_rootname(),
-					"_S1_", sx_callback);
-	aml_apply_foreach_found_objects(aml_get_rootname(),
-					"_S2_", sx_callback);
-	aml_apply_foreach_found_objects(aml_get_rootname(),
-					"_S3_", sx_callback);
-	aml_apply_foreach_found_objects(aml_get_rootname(),
-					"_S4_", sx_callback);
-	aml_apply_foreach_found_objects(aml_get_rootname(),
-					"_S5_", sx_callback);
+					"_S3_", s2_s3_callback);
 }
+#endif /* DISABLE_SLEEP */
 
-
 void
 acpi_modify_aml(u8 *start, u8 *end)
 {
 	acpi_load_aml(start, end);
-
-	parse_sx();
 #ifdef TTY_SERIAL
 	disable_pnp0501_dis();
 #endif /* TTY_SERIAL */
+#ifdef DISABLE_SLEEP
+	disable_s2_s3();
+#endif /* TTY_SERIAL */
 }
Index: vmm/core/vm.c
===================================================================
--- vmm/core/vm.c	(リビジョン 198)
+++ vmm/core/vm.c	(作業コピー)
@@ -38,12 +38,10 @@
 #include <core/spinlock.h>
 #include <io/pci.h>
 #include "apic.h"
-#include "acpi.h"
 #include "apic_pass.h"
 #include "current.h"
 #include "gbiosloader.h"
 #include "int.h"
-#include "panic.h"
 #include "pcpu.h"
 #include "setup_guestboot.h"
 #include "vm.h"
@@ -53,7 +51,6 @@
 
 static LIST2_DEFINE_HEAD_INIT(struct vm, vm_list);
 static spinlock_t vm_list_lock = SPINLOCK_INITIALIZER;
-int vm_num = 0;
 
 drvdata_hdl_t
 vm_alloc_driver_data(size_t size)
@@ -291,7 +288,6 @@
 
 	spinlock_lock(&vm_list_lock);
 	LIST2_ADD(vm_list, vm_list, vm);
-	vm_num++;
 	spinlock_unlock(&vm_list_lock);
 
 	vm->vbsp_apic_id = get_apic_id();
@@ -395,36 +391,3 @@
 
 	return VMMERR_SUCCESS;
 }
-
-void
-vm_shutdown(void)
-{
-	struct vm *vm;
-	bool all_shutdown;
-
-	printf("Shutdown %s\n", vm_get_name());
-
-	current->vm->shutdown = true;
-
-	if (vm_get_id() != 0) {
-		freeze();
-	}
-
-	for (;;) {
-		all_shutdown = true;
-		spinlock_lock(&vm_list_lock);
-		LIST2_FOREACH(vm_list, vm_list, vm) {
-			if (vm->shutdown == false) {
-				all_shutdown = false;
-			}
-		}
-		spinlock_unlock(&vm_list_lock);
-		if (all_shutdown) {
-			break;
-		}
-		usleep(100);
-	}
-
-	acpi_poweroff();
-	freeze();
-}
Index: vmm/core/vm.h
===================================================================
--- vmm/core/vm.h	(リビジョン 198)
+++ vmm/core/vm.h	(作業コピー)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2014 Yuichi Watanabe
+ * Copyright (c) 2010-2013 Yuichi Watanabe
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -77,8 +77,6 @@
 	volatile bool resetting;
 	struct wait wait;
 
-	volatile bool shutdown;
-
 	u64 driver_data[]; /* variable length array */
 };
 
Index: vmm/core/acpi.c
===================================================================
--- vmm/core/acpi.c	(リビジョン 198)
+++ vmm/core/acpi.c	(作業コピー)
@@ -174,15 +174,11 @@
 static struct acpi_parser parsers[PARSERS_MAX_NUM];
 static uint parsers_num = 0;
 
-static bool pm1a_cnt_found = false;
-static ioport_t pm1a_cnt_ioaddr;
-static bool pm1b_cnt_found = false;
-static ioport_t pm1b_cnt_ioaddr;
 static bool reset_reg_found = false;
 static ioport_t reset_reg_ioaddr;
 static u8 reset_value;
 
-struct acpi_sleep acpi_sleep[6];
+unsigned char acpi_dsdt_system_state[6][5];
 
 static u8
 acpi_checksum (void *p, int len)
@@ -367,90 +363,7 @@
 	}
 }
 
-void
-acpi_poweroff (void)
-{
-	u32 data, typx;
-
-	if (!pm1a_cnt_found)
-		return;
-	if (!acpi_sleep[5].valid)
-		return;
-
-	ACPI_DBG("acpi_poweroff\n");
-	typx = acpi_sleep[5].type[0] << PM1_CNT_SLP_TYPX_SHIFT;
-
-	asm_inl (pm1a_cnt_ioaddr, &data);
-	data &= ~PM1_CNT_SLP_TYPX_MASK;
-	data |= typx & PM1_CNT_SLP_TYPX_MASK;
-	data |= PM1_CNT_SLP_EN_BIT;
-	asm_outl (pm1a_cnt_ioaddr, data);
-
-	if (pm1b_cnt_found) {
-		typx = acpi_sleep[5].type[1] << PM1_CNT_SLP_TYPX_SHIFT;
-		asm_inl (pm1b_cnt_ioaddr, &data);
-		data &= ~PM1_CNT_SLP_TYPX_MASK;
-		data |= typx & PM1_CNT_SLP_TYPX_MASK;
-		data |= PM1_CNT_SLP_EN_BIT;
-		asm_outl (pm1b_cnt_ioaddr, data);
-	}
-
-	freeze();
-}
-
-static void
-acpi_pm1_sleep (ioport_t port, u32 val)
-{
-	u8 type;
-
-	type = (val & PM1_CNT_SLP_TYPX_MASK) >> PM1_CNT_SLP_TYPX_SHIFT;
-	ACPI_DBG("acpi_pm1_sleep 0x%x 0x%x\n", val, type);
-
-	if (acpi_sleep[5].valid == false) {
-		return;
-	}
-	 
-	if ((port == pm1a_cnt_ioaddr && acpi_sleep[5].type[0] == type) ||
-	    (port == pm1b_cnt_ioaddr && acpi_sleep[5].type[1] == type)) {
-		ACPI_DBG("shutdown\n");
-		vm_shutdown();
-	}
-}
-
 static int
-acpi_pm1_cnt_reg (iotype_t type, ioport_t port, void *data)
-{
-	u32 val;
-
-	ACPI_DBG("acpi_pm1_cnt_reg type 0x%x port 0x%x\n", type, port);
-	switch (type) {
-	case IOTYPE_OUTB:
-		val = *(u8 *)data;
-		break;
-	case IOTYPE_OUTW:
-		val = *(u16 *)data;
-		break;
-	case IOTYPE_OUTL:
-		val = *(u32 *)data;
-		break;
-	default:
-		return 0; /* pass */
-	}
-	if ((val & PM1_CNT_SLP_EN_BIT) == 0) {
-		return 0; /* pass */
-	}
-	/*
-	 * If shutdown, the following function never returns.
- 	 */
-	acpi_pm1_sleep (port, val);
-#ifdef DISABLE_SLEEP
-	return 1; /* emulated */
-#else
-	return 0; /* pass */
-#endif
-}
-
-static int
 acpi_reset_reg (iotype_t type, ioport_t port, void *data)
 {
 	u32 v;
@@ -490,69 +403,11 @@
 		return;
 	}
 
-	if (pm1a_cnt_found)
-		set_iofunc (pm1a_cnt_ioaddr, acpi_pm1_cnt_reg);
-	if (pm1b_cnt_found)
-		set_iofunc (pm1b_cnt_ioaddr, acpi_pm1_cnt_reg);
-
 	if (reset_reg_found && reset_reg_ioaddr != 0x64)
 		set_iofunc(reset_reg_ioaddr, acpi_reset_reg);
 }
 
 static void
-get_pm1_cnt_ioaddr (struct facp *q)
-{
-	if (IS_STRUCT_SIZE_OK (q->header.length, q, q->x_pm1a_cnt_blk) &&
-	    q->x_pm1a_cnt_blk.address != 0) {
-		if (q->x_pm1a_cnt_blk.address_space_id !=
-		    ADDRESS_SPACE_ID_IO)
-			printf("X_PM1a_CNT_BLK is not I/O address\n");
-		if (q->x_pm1a_cnt_blk.address > 0xffff) {
-			printf("X_PM1a_CNT_BLK > 0xffff\n");
-		} else {
-			pm1a_cnt_ioaddr = q->x_pm1a_cnt_blk.address;
-			pm1a_cnt_found = true;
-			ACPI_DBG("PM1a control port (x) x%X\n",
-				 pm1a_cnt_ioaddr);
-		}
-	} else if (IS_STRUCT_SIZE_OK (q->header.length, q, q->pm1a_cnt_blk)) {
-		if (q->pm1a_cnt_blk > 0xFFFF) {
-			printf("pm1a_cnt_blk > 0xffff\n");
-		} else if (q->pm1a_cnt_blk == 0) {
-			printf("pm1a_cnt_blk is 0\n");
-		} else {
-			pm1a_cnt_ioaddr = q->pm1a_cnt_blk;
-			pm1a_cnt_found = true;
-			ACPI_DBG("PM1a control port is 0x%X\n",
-				 pm1a_cnt_ioaddr);
-		}
-	}
-	if (IS_STRUCT_SIZE_OK (q->header.length, q, q->x_pm1b_cnt_blk) &&
-	    (q->x_pm1b_cnt_blk.address != 0)) {
-		if (q->x_pm1b_cnt_blk.address_space_id !=
-		    ADDRESS_SPACE_ID_IO)
-			printf("X_PM1b_CNT_BLK is not I/O address\n");
-		if (q->x_pm1b_cnt_blk.address > 0xffff) {
-			printf("X_PM1b_CNT_BLK > 0xffff\n");
-		} else {
-			pm1b_cnt_ioaddr = q->x_pm1b_cnt_blk.address;
-			pm1b_cnt_found = true;
-			ACPI_DBG("PM1b control port (x) is 0x%X\n",
-				 pm1b_cnt_ioaddr);
-		}
-	} else if (IS_STRUCT_SIZE_OK (q->header.length, q, q->pm1b_cnt_blk)) {
-		if (q->pm1b_cnt_blk > 0xFFFF) {
-			printf("pm1b_cnt_blk > 0xffff\n");
-		} else if (q->pm1b_cnt_blk != 0) {
-			pm1b_cnt_ioaddr = q->pm1b_cnt_blk;
-			pm1b_cnt_found = true;
-			ACPI_DBG("PM1b control port is 0x%X\n",
-				 pm1b_cnt_ioaddr);
-		}
-	}
-}
-
-static void
 get_reset_reg_ioaddr (struct facp *facp)
 {
 	if ((facp->flags & ACPI_FACP_FLAG_RESET_REG_SUP) == 0) {
@@ -615,7 +470,6 @@
 #ifdef ACPI_DSDT
 	acpi_dsdt_parse(facp->dsdt);
 #endif
-	get_pm1_cnt_ioaddr(facp);
 	get_reset_reg_ioaddr(facp);
 	if (0)
 		debug_dump(facp, facp->header.length);
Index: vmm/core/acpi.h
===================================================================
--- vmm/core/acpi.h	(リビジョン 198)
+++ vmm/core/acpi.h	(作業コピー)
@@ -33,14 +33,7 @@
 #ifndef _CORE_ACPI_H
 #define _CORE_ACPI_H
 
-struct acpi_sleep {
-	bool valid;
-	char type[2];
-};
-
-extern struct acpi_sleep acpi_sleep[6];
-
+extern unsigned char acpi_dsdt_system_state[6][5];
 void acpi_modify_aml(u8 *start, u8 *end);
-void acpi_poweroff(void);
 
 #endif /* _ACPI_H */
