summaryrefslogtreecommitdiff
path: root/drivers/acpi/hardware
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/acpi/hardware
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/acpi/hardware')
-rw-r--r--drivers/acpi/hardware/Makefile9
-rw-r--r--drivers/acpi/hardware/hwacpi.c230
-rw-r--r--drivers/acpi/hardware/hwgpe.c444
-rw-r--r--drivers/acpi/hardware/hwregs.c850
-rw-r--r--drivers/acpi/hardware/hwsleep.c582
-rw-r--r--drivers/acpi/hardware/hwtimer.c203
6 files changed, 2318 insertions, 0 deletions
diff --git a/drivers/acpi/hardware/Makefile b/drivers/acpi/hardware/Makefile
new file mode 100644
index 00000000000..438ad373b9a
--- /dev/null
+++ b/drivers/acpi/hardware/Makefile
@@ -0,0 +1,9 @@
+#
+# Makefile for all Linux ACPI interpreter subdirectories
+#
+
+obj-y := hwacpi.o hwgpe.o hwregs.o hwsleep.o
+
+obj-$(ACPI_FUTURE_USAGE) += hwtimer.o
+
+EXTRA_CFLAGS += $(ACPI_CFLAGS)
diff --git a/drivers/acpi/hardware/hwacpi.c b/drivers/acpi/hardware/hwacpi.c
new file mode 100644
index 00000000000..529e922bdc8
--- /dev/null
+++ b/drivers/acpi/hardware/hwacpi.c
@@ -0,0 +1,230 @@
+
+/******************************************************************************
+ *
+ * Module Name: hwacpi - ACPI Hardware Initialization/Mode Interface
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2005, R. Byron Moore
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions, and the following disclaimer,
+ * without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ * substantially similar to the "NO WARRANTY" disclaimer below
+ * ("Disclaimer") and any redistribution must be conditioned upon
+ * including a substantially similar Disclaimer requirement for further
+ * binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ * of any contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ */
+
+
+#include <acpi/acpi.h>
+
+
+#define _COMPONENT ACPI_HARDWARE
+ ACPI_MODULE_NAME ("hwacpi")
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_hw_initialize
+ *
+ * PARAMETERS: None
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Initialize and validate various ACPI registers
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_hw_initialize (
+ void)
+{
+ acpi_status status;
+
+
+ ACPI_FUNCTION_TRACE ("hw_initialize");
+
+
+ /* We must have the ACPI tables by the time we get here */
+
+ if (!acpi_gbl_FADT) {
+ ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "A FADT is not loaded\n"));
+
+ return_ACPI_STATUS (AE_NO_ACPI_TABLES);
+ }
+
+ /* Sanity check the FADT for valid values */
+
+ status = acpi_ut_validate_fadt ();
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+
+ return_ACPI_STATUS (AE_OK);
+}
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_hw_set_mode
+ *
+ * PARAMETERS: Mode - SYS_MODE_ACPI or SYS_MODE_LEGACY
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Transitions the system into the requested mode.
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_hw_set_mode (
+ u32 mode)
+{
+
+ acpi_status status;
+ u32 retry;
+
+
+ ACPI_FUNCTION_TRACE ("hw_set_mode");
+
+ /*
+ * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
+ * system does not support mode transition.
+ */
+ if (!acpi_gbl_FADT->smi_cmd) {
+ ACPI_REPORT_ERROR (("No SMI_CMD in FADT, mode transition failed.\n"));
+ return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
+ }
+
+ /*
+ * ACPI 2.0 clarified the meaning of ACPI_ENABLE and ACPI_DISABLE
+ * in FADT: If it is zero, enabling or disabling is not supported.
+ * As old systems may have used zero for mode transition,
+ * we make sure both the numbers are zero to determine these
+ * transitions are not supported.
+ */
+ if (!acpi_gbl_FADT->acpi_enable && !acpi_gbl_FADT->acpi_disable) {
+ ACPI_REPORT_ERROR (("No ACPI mode transition supported in this system (enable/disable both zero)\n"));
+ return_ACPI_STATUS (AE_OK);
+ }
+
+ switch (mode) {
+ case ACPI_SYS_MODE_ACPI:
+
+ /* BIOS should have disabled ALL fixed and GP events */
+
+ status = acpi_os_write_port (acpi_gbl_FADT->smi_cmd,
+ (u32) acpi_gbl_FADT->acpi_enable, 8);
+ ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Attempting to enable ACPI mode\n"));
+ break;
+
+ case ACPI_SYS_MODE_LEGACY:
+
+ /*
+ * BIOS should clear all fixed status bits and restore fixed event
+ * enable bits to default
+ */
+ status = acpi_os_write_port (acpi_gbl_FADT->smi_cmd,
+ (u32) acpi_gbl_FADT->acpi_disable, 8);
+ ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
+ "Attempting to enable Legacy (non-ACPI) mode\n"));
+ break;
+
+ default:
+ return_ACPI_STATUS (AE_BAD_PARAMETER);
+ }
+
+ if (ACPI_FAILURE (status)) {
+ ACPI_REPORT_ERROR (("Could not write mode change, %s\n", acpi_format_exception (status)));
+ return_ACPI_STATUS (status);
+ }
+
+ /*
+ * Some hardware takes a LONG time to switch modes. Give them 3 sec to
+ * do so, but allow faster systems to proceed more quickly.
+ */
+ retry = 3000;
+ while (retry) {
+ if (acpi_hw_get_mode() == mode) {
+ ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Mode %X successfully enabled\n", mode));
+ return_ACPI_STATUS (AE_OK);
+ }
+ acpi_os_stall(1000);
+ retry--;
+ }
+
+ ACPI_REPORT_ERROR (("Hardware never changed modes\n"));
+ return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
+}
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_hw_get_mode
+ *
+ * PARAMETERS: none
+ *
+ * RETURN: SYS_MODE_ACPI or SYS_MODE_LEGACY
+ *
+ * DESCRIPTION: Return current operating state of system. Determined by
+ * querying the SCI_EN bit.
+ *
+ ******************************************************************************/
+
+u32
+acpi_hw_get_mode (void)
+{
+ acpi_status status;
+ u32 value;
+
+
+ ACPI_FUNCTION_TRACE ("hw_get_mode");
+
+
+ /*
+ * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
+ * system does not support mode transition.
+ */
+ if (!acpi_gbl_FADT->smi_cmd) {
+ return_VALUE (ACPI_SYS_MODE_ACPI);
+ }
+
+ status = acpi_get_register (ACPI_BITREG_SCI_ENABLE, &value, ACPI_MTX_LOCK);
+ if (ACPI_FAILURE (status)) {
+ return_VALUE (ACPI_SYS_MODE_LEGACY);
+ }
+
+ if (value) {
+ return_VALUE (ACPI_SYS_MODE_ACPI);
+ }
+ else {
+ return_VALUE (ACPI_SYS_MODE_LEGACY);
+ }
+}
diff --git a/drivers/acpi/hardware/hwgpe.c b/drivers/acpi/hardware/hwgpe.c
new file mode 100644
index 00000000000..9ac1d639bf5
--- /dev/null
+++ b/drivers/acpi/hardware/hwgpe.c
@@ -0,0 +1,444 @@
+
+/******************************************************************************
+ *
+ * Module Name: hwgpe - Low level GPE enable/disable/clear functions
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2005, R. Byron Moore
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions, and the following disclaimer,
+ * without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ * substantially similar to the "NO WARRANTY" disclaimer below
+ * ("Disclaimer") and any redistribution must be conditioned upon
+ * including a substantially similar Disclaimer requirement for further
+ * binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ * of any contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ */
+
+#include <acpi/acpi.h>
+#include <acpi/acevents.h>
+
+#define _COMPONENT ACPI_HARDWARE
+ ACPI_MODULE_NAME ("hwgpe")
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_hw_write_gpe_enable_reg
+ *
+ * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Write a GPE enable register. Note: The bit for this GPE must
+ * already be cleared or set in the parent register
+ * enable_for_run mask.
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_hw_write_gpe_enable_reg (
+ struct acpi_gpe_event_info *gpe_event_info)
+{
+ struct acpi_gpe_register_info *gpe_register_info;
+ acpi_status status;
+
+
+ ACPI_FUNCTION_ENTRY ();
+
+
+ /* Get the info block for the entire GPE register */
+
+ gpe_register_info = gpe_event_info->register_info;
+ if (!gpe_register_info) {
+ return (AE_NOT_EXIST);
+ }
+
+ /* Write the entire GPE (runtime) enable register */
+
+ status = acpi_hw_low_level_write (8, gpe_register_info->enable_for_run,
+ &gpe_register_info->enable_address);
+
+ return (status);
+}
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_hw_clear_gpe
+ *
+ * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Clear the status bit for a single GPE.
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_hw_clear_gpe (
+ struct acpi_gpe_event_info *gpe_event_info)
+{
+ acpi_status status;
+
+
+ ACPI_FUNCTION_ENTRY ();
+
+
+ /*
+ * Write a one to the appropriate bit in the status register to
+ * clear this GPE.
+ */
+ status = acpi_hw_low_level_write (8, gpe_event_info->register_bit,
+ &gpe_event_info->register_info->status_address);
+
+ return (status);
+}
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_hw_get_gpe_status
+ *
+ * PARAMETERS: gpe_event_info - Info block for the GPE to queried
+ * event_status - Where the GPE status is returned
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Return the status of a single GPE.
+ *
+ ******************************************************************************/
+#ifdef ACPI_FUTURE_USAGE
+acpi_status
+acpi_hw_get_gpe_status (
+ struct acpi_gpe_event_info *gpe_event_info,
+ acpi_event_status *event_status)
+{
+ u32 in_byte;
+ u8 register_bit;
+ struct acpi_gpe_register_info *gpe_register_info;
+ acpi_status status;
+ acpi_event_status local_event_status = 0;
+
+
+ ACPI_FUNCTION_ENTRY ();
+
+
+ if (!event_status) {
+ return (AE_BAD_PARAMETER);
+ }
+
+ /* Get the info block for the entire GPE register */
+
+ gpe_register_info = gpe_event_info->register_info;
+
+ /* Get the register bitmask for this GPE */
+
+ register_bit = gpe_event_info->register_bit;
+
+ /* GPE currently enabled? (enabled for runtime?) */
+
+ if (register_bit & gpe_register_info->enable_for_run) {
+ local_event_status |= ACPI_EVENT_FLAG_ENABLED;
+ }
+
+ /* GPE enabled for wake? */
+
+ if (register_bit & gpe_register_info->enable_for_wake) {
+ local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED;
+ }
+
+ /* GPE currently active (status bit == 1)? */
+
+ status = acpi_hw_low_level_read (8, &in_byte, &gpe_register_info->status_address);
+ if (ACPI_FAILURE (status)) {
+ goto unlock_and_exit;
+ }
+
+ if (register_bit & in_byte) {
+ local_event_status |= ACPI_EVENT_FLAG_SET;
+ }
+
+ /* Set return value */
+
+ (*event_status) = local_event_status;
+
+
+unlock_and_exit:
+ return (status);
+}
+#endif /* ACPI_FUTURE_USAGE */
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_hw_disable_gpe_block
+ *
+ * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
+ * gpe_block - Gpe Block info
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Disable all GPEs within a GPE block
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_hw_disable_gpe_block (
+ struct acpi_gpe_xrupt_info *gpe_xrupt_info,
+ struct acpi_gpe_block_info *gpe_block)
+{
+ u32 i;
+ acpi_status status;
+
+
+ /* Examine each GPE Register within the block */
+
+ for (i = 0; i < gpe_block->register_count; i++) {
+ /* Disable all GPEs in this register */
+
+ status = acpi_hw_low_level_write (8, 0x00,
+ &gpe_block->register_info[i].enable_address);
+ if (ACPI_FAILURE (status)) {
+ return (status);
+ }
+ }
+
+ return (AE_OK);
+}
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_hw_clear_gpe_block
+ *
+ * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
+ * gpe_block - Gpe Block info
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Clear status bits for all GPEs within a GPE block
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_hw_clear_gpe_block (
+ struct acpi_gpe_xrupt_info *gpe_xrupt_info,
+ struct acpi_gpe_block_info *gpe_block)
+{
+ u32 i;
+ acpi_status status;
+
+
+ /* Examine each GPE Register within the block */
+
+ for (i = 0; i < gpe_block->register_count; i++) {
+ /* Clear status on all GPEs in this register */
+
+ status = acpi_hw_low_level_write (8, 0xFF,
+ &gpe_block->register_info[i].status_address);
+ if (ACPI_FAILURE (status)) {
+ return (status);
+ }
+ }
+
+ return (AE_OK);
+}
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_hw_enable_runtime_gpe_block
+ *
+ * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
+ * gpe_block - Gpe Block info
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Enable all "runtime" GPEs within a GPE block. (Includes
+ * combination wake/run GPEs.)
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_hw_enable_runtime_gpe_block (
+ struct acpi_gpe_xrupt_info *gpe_xrupt_info,
+ struct acpi_gpe_block_info *gpe_block)
+{
+ u32 i;
+ acpi_status status;
+
+
+ /* NOTE: assumes that all GPEs are currently disabled */
+
+ /* Examine each GPE Register within the block */
+
+ for (i = 0; i < gpe_block->register_count; i++) {
+ if (!gpe_block->register_info[i].enable_for_run) {
+ continue;
+ }
+
+ /* Enable all "runtime" GPEs in this register */
+
+ status = acpi_hw_low_level_write (8, gpe_block->register_info[i].enable_for_run,
+ &gpe_block->register_info[i].enable_address);
+ if (ACPI_FAILURE (status)) {
+ return (status);
+ }
+ }
+
+ return (AE_OK);
+}
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_hw_enable_wakeup_gpe_block
+ *
+ * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
+ * gpe_block - Gpe Block info
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Enable all "wake" GPEs within a GPE block. (Includes
+ * combination wake/run GPEs.)
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_hw_enable_wakeup_gpe_block (
+ struct acpi_gpe_xrupt_info *gpe_xrupt_info,
+ struct acpi_gpe_block_info *gpe_block)
+{
+ u32 i;
+ acpi_status status;
+
+
+ /* Examine each GPE Register within the block */
+
+ for (i = 0; i < gpe_block->register_count; i++) {
+ if (!gpe_block->register_info[i].enable_for_wake) {
+ continue;
+ }
+
+ /* Enable all "wake" GPEs in this register */
+
+ status = acpi_hw_low_level_write (8, gpe_block->register_info[i].enable_for_wake,
+ &gpe_block->register_info[i].enable_address);
+ if (ACPI_FAILURE (status)) {
+ return (status);
+ }
+ }
+
+ return (AE_OK);
+}
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_hw_disable_all_gpes
+ *
+ * PARAMETERS: Flags - ACPI_NOT_ISR or ACPI_ISR
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Disable and clear all GPEs
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_hw_disable_all_gpes (
+ u32 flags)
+{
+ acpi_status status;
+
+
+ ACPI_FUNCTION_TRACE ("hw_disable_all_gpes");
+
+
+ status = acpi_ev_walk_gpe_list (acpi_hw_disable_gpe_block, flags);
+ status = acpi_ev_walk_gpe_list (acpi_hw_clear_gpe_block, flags);
+ return_ACPI_STATUS (status);
+}
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_hw_enable_all_runtime_gpes
+ *
+ * PARAMETERS: Flags - ACPI_NOT_ISR or ACPI_ISR
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Enable all GPEs of the given type
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_hw_enable_all_runtime_gpes (
+ u32 flags)
+{
+ acpi_status status;
+
+
+ ACPI_FUNCTION_TRACE ("hw_enable_all_runtime_gpes");
+
+
+ status = acpi_ev_walk_gpe_list (acpi_hw_enable_runtime_gpe_block, flags);
+ return_ACPI_STATUS (status);
+}
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_hw_enable_all_wakeup_gpes
+ *
+ * PARAMETERS: Flags - ACPI_NOT_ISR or ACPI_ISR
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Enable all GPEs of the given type
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_hw_enable_all_wakeup_gpes (
+ u32 flags)
+{
+ acpi_status status;
+
+
+ ACPI_FUNCTION_TRACE ("hw_enable_all_wakeup_gpes");
+
+
+ status = acpi_ev_walk_gpe_list (acpi_hw_enable_wakeup_gpe_block, flags);
+ return_ACPI_STATUS (status);
+}
+
diff --git a/drivers/acpi/hardware/hwregs.c b/drivers/acpi/hardware/hwregs.c
new file mode 100644
index 00000000000..91af0c2ddcf
--- /dev/null
+++ b/drivers/acpi/hardware/hwregs.c
@@ -0,0 +1,850 @@
+
+/*******************************************************************************
+ *
+ * Module Name: hwregs - Read/write access functions for the various ACPI
+ * control and status registers.
+ *
+ ******************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2005, R. Byron Moore
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions, and the following disclaimer,
+ * without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ * substantially similar to the "NO WARRANTY" disclaimer below
+ * ("Disclaimer") and any redistribution must be conditioned upon
+ * including a substantially similar Disclaimer requirement for further
+ * binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ * of any contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ */
+
+#include <linux/module.h>
+
+#include <acpi/acpi.h>
+#include <acpi/acnamesp.h>
+#include <acpi/acevents.h>
+
+#define _COMPONENT ACPI_HARDWARE
+ ACPI_MODULE_NAME ("hwregs")
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: acpi_hw_clear_acpi_status
+ *
+ * PARAMETERS: Flags - Lock the hardware or not
+ *
+ * RETURN: none
+ *
+ * DESCRIPTION: Clears all fixed and general purpose status bits
+ * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_hw_clear_acpi_status (
+ u32 flags)
+{
+ acpi_status status;
+
+
+ ACPI_FUNCTION_TRACE ("hw_clear_acpi_status");
+
+
+ ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %04X to %04X\n",
+ ACPI_BITMASK_ALL_FIXED_STATUS,
+ (u16) acpi_gbl_FADT->xpm1a_evt_blk.address));
+
+ if (flags & ACPI_MTX_LOCK) {
+ status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+ }
+
+ status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_STATUS,
+ ACPI_BITMASK_ALL_FIXED_STATUS);
+ if (ACPI_FAILURE (status)) {
+ goto unlock_and_exit;
+ }
+
+ /* Clear the fixed events */
+
+ if (acpi_gbl_FADT->xpm1b_evt_blk.address) {
+ status = acpi_hw_low_level_write (16, ACPI_BITMASK_ALL_FIXED_STATUS,
+ &acpi_gbl_FADT->xpm1b_evt_blk);
+ if (ACPI_FAILURE (status)) {
+ goto unlock_and_exit;
+ }
+ }
+
+ /* Clear the GPE Bits in all GPE registers in all GPE blocks */
+
+ status = acpi_ev_walk_gpe_list (acpi_hw_clear_gpe_block, ACPI_ISR);
+
+unlock_and_exit:
+ if (flags & ACPI_MTX_LOCK) {
+ (void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
+ }
+ return_ACPI_STATUS (status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: acpi_get_sleep_type_data
+ *
+ * PARAMETERS: sleep_state - Numeric sleep state
+ * *sleep_type_a - Where SLP_TYPa is returned
+ * *sleep_type_b - Where SLP_TYPb is returned
+ *
+ * RETURN: Status - ACPI status
+ *
+ * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
+ * state.
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_get_sleep_type_data (
+ u8 sleep_state,
+ u8 *sleep_type_a,
+ u8 *sleep_type_b)
+{
+ acpi_status status = AE_OK;
+ struct acpi_parameter_info info;
+
+
+ ACPI_FUNCTION_TRACE ("acpi_get_sleep_type_data");
+
+
+ /*
+ * Validate parameters
+ */
+ if ((sleep_state > ACPI_S_STATES_MAX) ||
+ !sleep_type_a || !sleep_type_b) {
+ return_ACPI_STATUS (AE_BAD_PARAMETER);
+ }
+
+ /*
+ * Evaluate the namespace object containing the values for this state
+ */
+ info.parameters = NULL;
+ status = acpi_ns_evaluate_by_name ((char *) acpi_gbl_sleep_state_names[sleep_state],
+ &info);
+ if (ACPI_FAILURE (status)) {
+ ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s while evaluating sleep_state [%s]\n",
+ acpi_format_exception (status), acpi_gbl_sleep_state_names[sleep_state]));
+
+ return_ACPI_STATUS (status);
+ }
+
+ /* Must have a return object */
+
+ if (!info.return_object) {
+ ACPI_REPORT_ERROR (("Missing Sleep State object\n"));
+ status = AE_NOT_EXIST;
+ }
+
+ /* It must be of type Package */
+
+ else if (ACPI_GET_OBJECT_TYPE (info.return_object) != ACPI_TYPE_PACKAGE) {
+ ACPI_REPORT_ERROR (("Sleep State object not a Package\n"));
+ status = AE_AML_OPERAND_TYPE;
+ }
+
+ /* The package must have at least two elements */
+
+ else if (info.return_object->package.count < 2) {
+ ACPI_REPORT_ERROR (("Sleep State package does not have at least two elements\n"));
+ status = AE_AML_NO_OPERAND;
+ }
+
+ /* The first two elements must both be of type Integer */
+
+ else if ((ACPI_GET_OBJECT_TYPE (info.return_object->package.elements[0]) != ACPI_TYPE_INTEGER) ||
+ (ACPI_GET_OBJECT_TYPE (info.return_object->package.elements[1]) != ACPI_TYPE_INTEGER)) {
+ ACPI_REPORT_ERROR (("Sleep State package elements are not both Integers (%s, %s)\n",
+ acpi_ut_get_object_type_name (info.return_object->package.elements[0]),
+ acpi_ut_get_object_type_name (info.return_object->package.elements[1])));
+ status = AE_AML_OPERAND_TYPE;
+ }
+ else {
+ /*
+ * Valid _Sx_ package size, type, and value
+ */
+ *sleep_type_a = (u8) (info.return_object->package.elements[0])->integer.value;
+ *sleep_type_b = (u8) (info.return_object->package.elements[1])->integer.value;
+ }
+
+ if (ACPI_FAILURE (status)) {
+ ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
+ "While evaluating sleep_state [%s], bad Sleep object %p type %s\n",
+ acpi_gbl_sleep_state_names[sleep_state], info.return_object,
+ acpi_ut_get_object_type_name (info.return_object)));
+ }
+
+ acpi_ut_remove_reference (info.return_object);
+ return_ACPI_STATUS (status);
+}
+EXPORT_SYMBOL(acpi_get_sleep_type_data);
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: acpi_hw_get_register_bit_mask
+ *
+ * PARAMETERS: register_id - Index of ACPI Register to access
+ *
+ * RETURN: The bit mask to be used when accessing the register
+ *
+ * DESCRIPTION: Map register_id into a register bit mask.
+ *
+ ******************************************************************************/
+
+struct acpi_bit_register_info *
+acpi_hw_get_bit_register_info (
+ u32 register_id)
+{
+ ACPI_FUNCTION_NAME ("hw_get_bit_register_info");
+
+
+ if (register_id > ACPI_BITREG_MAX) {
+ ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid bit_register ID: %X\n", register_id));
+ return (NULL);
+ }
+
+ return (&acpi_gbl_bit_register_info[register_id]);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: acpi_get_register
+ *
+ * PARAMETERS: register_id - ID of ACPI bit_register to access
+ * return_value - Value that was read from the register
+ * Flags - Lock the hardware or not
+ *
+ * RETURN: Status and the value read from specified Register. Value
+ * returned is normalized to bit0 (is shifted all the way right)
+ *
+ * DESCRIPTION: ACPI bit_register read function.
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_get_register (
+ u32 register_id,
+ u32 *return_value,
+ u32 flags)
+{
+ u32 register_value = 0;
+ struct acpi_bit_register_info *bit_reg_info;
+ acpi_status status;
+
+
+ ACPI_FUNCTION_TRACE ("acpi_get_register");
+
+
+ /* Get the info structure corresponding to the requested ACPI Register */
+
+ bit_reg_info = acpi_hw_get_bit_register_info (register_id);
+ if (!bit_reg_info) {
+ return_ACPI_STATUS (AE_BAD_PARAMETER);
+ }
+
+ if (flags & ACPI_MTX_LOCK) {
+ status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+ }
+
+ /* Read from the register */
+
+ status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK,
+ bit_reg_info->parent_register, &register_value);
+
+ if (flags & ACPI_MTX_LOCK) {
+ (void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
+ }
+
+ if (ACPI_SUCCESS (status)) {
+ /* Normalize the value that was read */
+
+ register_value = ((register_value & bit_reg_info->access_bit_mask)
+ >> bit_reg_info->bit_position);
+
+ *return_value = register_value;
+
+ ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Read value %8.8X register %X\n",
+ register_value, bit_reg_info->parent_register));
+ }
+
+ return_ACPI_STATUS (status);
+}
+EXPORT_SYMBOL(acpi_get_register);
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: acpi_set_register
+ *
+ * PARAMETERS: register_id - ID of ACPI bit_register to access
+ * Value - (only used on write) value to write to the
+ * Register, NOT pre-normalized to the bit pos
+ * Flags - Lock the hardware or not
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: ACPI Bit Register write function.
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_set_register (
+ u32 register_id,
+ u32 value,
+ u32 flags)
+{
+ u32 register_value = 0;
+ struct acpi_bit_register_info *bit_reg_info;
+ acpi_status status;
+
+
+ ACPI_FUNCTION_TRACE_U32 ("acpi_set_register", register_id);
+
+
+ /* Get the info structure corresponding to the requested ACPI Register */
+
+ bit_reg_info = acpi_hw_get_bit_register_info (register_id);
+ if (!bit_reg_info) {
+ ACPI_REPORT_ERROR (("Bad ACPI HW register_id: %X\n", register_id));
+ return_ACPI_STATUS (AE_BAD_PARAMETER);
+ }
+
+ if (flags & ACPI_MTX_LOCK) {
+ status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+ }
+
+ /* Always do a register read first so we can insert the new bits */
+
+ status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK,
+ bit_reg_info->parent_register, &register_value);
+ if (ACPI_FAILURE (status)) {
+ goto unlock_and_exit;
+ }
+
+ /*
+ * Decode the Register ID
+ * Register ID = [Register block ID] | [bit ID]
+ *
+ * Check bit ID to fine locate Register offset.
+ * Check Mask to determine Register offset, and then read-write.
+ */
+ switch (bit_reg_info->parent_register) {
+ case ACPI_REGISTER_PM1_STATUS:
+
+ /*
+ * Status Registers are different from the rest. Clear by
+ * writing 1, and writing 0 has no effect. So, the only relevant
+ * information is the single bit we're interested in, all others should
+ * be written as 0 so they will be left unchanged.
+ */
+ value = ACPI_REGISTER_PREPARE_BITS (value,
+ bit_reg_info->bit_position, bit_reg_info->access_bit_mask);
+ if (value) {
+ status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
+ ACPI_REGISTER_PM1_STATUS, (u16) value);
+ register_value = 0;
+ }
+ break;
+
+
+ case ACPI_REGISTER_PM1_ENABLE:
+
+ ACPI_REGISTER_INSERT_VALUE (register_value, bit_reg_info->bit_position,
+ bit_reg_info->access_bit_mask, value);
+
+ status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
+ ACPI_REGISTER_PM1_ENABLE, (u16) register_value);
+ break;
+
+
+ case ACPI_REGISTER_PM1_CONTROL:
+
+ /*
+ * Write the PM1 Control register.
+ * Note that at this level, the fact that there are actually TWO
+ * registers (A and B - and B may not exist) is abstracted.
+ */
+ ACPI_DEBUG_PRINT ((ACPI_DB_IO, "PM1 control: Read %X\n", register_value));
+
+ ACPI_REGISTER_INSERT_VALUE (register_value, bit_reg_info->bit_position,
+ bit_reg_info->access_bit_mask, value);
+
+ status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
+ ACPI_REGISTER_PM1_CONTROL, (u16) register_value);
+ break;
+
+
+ case ACPI_REGISTER_PM2_CONTROL:
+
+ status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK,
+ ACPI_REGISTER_PM2_CONTROL, &register_value);
+ if (ACPI_FAILURE (status)) {
+ goto unlock_and_exit;
+ }
+
+ ACPI_DEBUG_PRINT ((ACPI_DB_IO, "PM2 control: Read %X from %8.8X%8.8X\n",
+ register_value,
+ ACPI_FORMAT_UINT64 (acpi_gbl_FADT->xpm2_cnt_blk.address)));
+
+ ACPI_REGISTER_INSERT_VALUE (register_value, bit_reg_info->bit_position,
+ bit_reg_info->access_bit_mask, value);
+
+ ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %4.4X to %8.8X%8.8X\n",
+ register_value,
+ ACPI_FORMAT_UINT64 (acpi_gbl_FADT->xpm2_cnt_blk.address)));
+
+ status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
+ ACPI_REGISTER_PM2_CONTROL, (u8) (register_value));
+ break;
+
+
+ default:
+ break;
+ }
+
+
+unlock_and_exit:
+
+ if (flags & ACPI_MTX_LOCK) {
+ (void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
+ }
+
+ /* Normalize the value that was read */
+
+ ACPI_DEBUG_EXEC (register_value = ((register_value & bit_reg_info->access_bit_mask) >> bit_reg_info->bit_position));
+
+ ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Set bits: %8.8X actual %8.8X register %X\n",
+ value, register_value, bit_reg_info->parent_register));
+ return_ACPI_STATUS (status);
+}
+EXPORT_SYMBOL(acpi_set_register);
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_hw_register_read
+ *
+ * PARAMETERS: use_lock - Mutex hw access
+ * register_id - register_iD + Offset
+ * return_value - Value that was read from the register
+ *
+ * RETURN: Status and the value read.
+ *
+ * DESCRIPTION: Acpi register read function. Registers are read at the
+ * given offset.
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_hw_register_read (
+ u8 use_lock,
+ u32 register_id,
+ u32 *return_value)
+{
+ u32 value1 = 0;
+ u32 value2 = 0;
+ acpi_status status;
+
+
+ ACPI_FUNCTION_TRACE ("hw_register_read");
+
+
+ if (ACPI_MTX_LOCK == use_lock) {
+ status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+ }
+
+ switch (register_id) {
+ case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
+
+ status = acpi_hw_low_level_read (16, &value1, &acpi_gbl_FADT->xpm1a_evt_blk);
+ if (ACPI_FAILURE (status)) {
+ goto unlock_and_exit;
+ }
+
+ /* PM1B is optional */
+
+ status = acpi_hw_low_level_read (16, &value2, &acpi_gbl_FADT->xpm1b_evt_blk);
+ value1 |= value2;
+ break;
+
+
+ case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */
+
+ status = acpi_hw_low_level_read (16, &value1, &acpi_gbl_xpm1a_enable);
+ if (ACPI_FAILURE (status)) {
+ goto unlock_and_exit;
+ }
+
+ /* PM1B is optional */
+
+ status = acpi_hw_low_level_read (16, &value2, &acpi_gbl_xpm1b_enable);
+ value1 |= value2;
+ break;
+
+
+ case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
+
+ status = acpi_hw_low_level_read (16, &value1, &acpi_gbl_FADT->xpm1a_cnt_blk);
+ if (ACPI_FAILURE (status)) {
+ goto unlock_and_exit;
+ }
+
+ status = acpi_hw_low_level_read (16, &value2, &acpi_gbl_FADT->xpm1b_cnt_blk);
+ value1 |= value2;
+ break;
+
+
+ case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
+
+ status = acpi_hw_low_level_read (8, &value1, &acpi_gbl_FADT->xpm2_cnt_blk);
+ break;
+
+
+ case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
+
+ status = acpi_hw_low_level_read (32, &value1, &acpi_gbl_FADT->xpm_tmr_blk);
+ break;
+
+ case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
+
+ status = acpi_os_read_port (acpi_gbl_FADT->smi_cmd, &value1, 8);
+ break;
+
+ default:
+ ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Register ID: %X\n", register_id));
+ status = AE_BAD_PARAMETER;
+ break;
+ }
+
+unlock_and_exit:
+ if (ACPI_MTX_LOCK == use_lock) {
+ (void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
+ }
+
+ if (ACPI_SUCCESS (status)) {
+ *return_value = value1;
+ }
+
+ return_ACPI_STATUS (status);
+}
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_hw_register_write
+ *
+ * PARAMETERS: use_lock - Mutex hw access
+ * register_id - register_iD + Offset
+ * Value - The value to write
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Acpi register Write function. Registers are written at the
+ * given offset.
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_hw_register_write (
+ u8 use_lock,
+ u32 register_id,
+ u32 value)
+{
+ acpi_status status;
+
+
+ ACPI_FUNCTION_TRACE ("hw_register_write");
+
+
+ if (ACPI_MTX_LOCK == use_lock) {
+ status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+ }
+
+ switch (register_id) {
+ case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
+
+ status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1a_evt_blk);
+ if (ACPI_FAILURE (status)) {
+ goto unlock_and_exit;
+ }
+
+ /* PM1B is optional */
+
+ status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1b_evt_blk);
+ break;
+
+
+ case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access*/
+
+ status = acpi_hw_low_level_write (16, value, &acpi_gbl_xpm1a_enable);
+ if (ACPI_FAILURE (status)) {
+ goto unlock_and_exit;
+ }
+
+ /* PM1B is optional */
+
+ status = acpi_hw_low_level_write (16, value, &acpi_gbl_xpm1b_enable);
+ break;
+
+
+ case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
+
+ status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1a_cnt_blk);
+ if (ACPI_FAILURE (status)) {
+ goto unlock_and_exit;
+ }
+
+ status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1b_cnt_blk);
+ break;
+
+
+ case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */
+
+ status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1a_cnt_blk);
+ break;
+
+
+ case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */
+
+ status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1b_cnt_blk);
+ break;
+
+
+ case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
+
+ status = acpi_hw_low_level_write (8, value, &acpi_gbl_FADT->xpm2_cnt_blk);
+ break;
+
+
+ case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
+
+ status = acpi_hw_low_level_write (32, value, &acpi_gbl_FADT->xpm_tmr_blk);
+ break;
+
+
+ case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
+
+ /* SMI_CMD is currently always in IO space */
+
+ status = acpi_os_write_port (acpi_gbl_FADT->smi_cmd, value, 8);
+ break;
+
+
+ default:
+ status = AE_BAD_PARAMETER;
+ break;
+ }
+
+unlock_and_exit:
+ if (ACPI_MTX_LOCK == use_lock) {
+ (void) acpi_ut_release_mutex (ACPI_MTX_HARDWARE);
+ }
+
+ return_ACPI_STATUS (status);
+}
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_hw_low_level_read
+ *
+ * PARAMETERS: Width - 8, 16, or 32
+ * Value - Where the value is returned
+ * Reg - GAS register structure
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Read from either memory or IO space.
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_hw_low_level_read (
+ u32 width,
+ u32 *value,
+ struct acpi_generic_address *reg)
+{
+ u64 address;
+ acpi_status status;
+
+
+ ACPI_FUNCTION_NAME ("hw_low_level_read");
+
+
+ /*
+ * Must have a valid pointer to a GAS structure, and
+ * a non-zero address within. However, don't return an error
+ * because the PM1A/B code must not fail if B isn't present.
+ */
+ if (!reg) {
+ return (AE_OK);
+ }
+
+ /* Get a local copy of the address. Handles possible alignment issues */
+
+ ACPI_MOVE_64_TO_64 (&address, &reg->address);
+ if (!address) {
+ return (AE_OK);
+ }
+ *value = 0;
+
+ /*
+ * Two address spaces supported: Memory or IO.
+ * PCI_Config is not supported here because the GAS struct is insufficient
+ */
+ switch (reg->address_space_id) {
+ case ACPI_ADR_SPACE_SYSTEM_MEMORY:
+
+ status = acpi_os_read_memory (
+ (acpi_physical_address) address,
+ value, width);
+ break;
+
+
+ case ACPI_ADR_SPACE_SYSTEM_IO:
+
+ status = acpi_os_read_port ((acpi_io_address) address,
+ value, width);
+ break;
+
+
+ default:
+ ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
+ "Unsupported address space: %X\n", reg->address_space_id));
+ return (AE_BAD_PARAMETER);
+ }
+
+ ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
+ *value, width,
+ ACPI_FORMAT_UINT64 (address),
+ acpi_ut_get_region_name (reg->address_space_id)));
+
+ return (status);
+}
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_hw_low_level_write
+ *
+ * PARAMETERS: Width - 8, 16, or 32
+ * Value - To be written
+ * Reg - GAS register structure
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Write to either memory or IO space.
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_hw_low_level_write (
+ u32 width,
+ u32 value,
+ struct acpi_generic_address *reg)
+{
+ u64 address;
+ acpi_status status;
+
+
+ ACPI_FUNCTION_NAME ("hw_low_level_write");
+
+
+ /*
+ * Must have a valid pointer to a GAS structure, and
+ * a non-zero address within. However, don't return an error
+ * because the PM1A/B code must not fail if B isn't present.
+ */
+ if (!reg) {
+ return (AE_OK);
+ }
+
+ /* Get a local copy of the address. Handles possible alignment issues */
+
+ ACPI_MOVE_64_TO_64 (&address, &reg->address);
+ if (!address) {
+ return (AE_OK);
+ }
+
+ /*
+ * Two address spaces supported: Memory or IO.
+ * PCI_Config is not supported here because the GAS struct is insufficient
+ */
+ switch (reg->address_space_id) {
+ case ACPI_ADR_SPACE_SYSTEM_MEMORY:
+
+ status = acpi_os_write_memory (
+ (acpi_physical_address) address,
+ value, width);
+ break;
+
+
+ case ACPI_ADR_SPACE_SYSTEM_IO:
+
+ status = acpi_os_write_port ((acpi_io_address) address,
+ value, width);
+ break;
+
+
+ default:
+ ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
+ "Unsupported address space: %X\n", reg->address_space_id));
+ return (AE_BAD_PARAMETER);
+ }
+
+ ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
+ value, width,
+ ACPI_FORMAT_UINT64 (address),
+ acpi_ut_get_region_name (reg->address_space_id)));
+
+ return (status);
+}
diff --git a/drivers/acpi/hardware/hwsleep.c b/drivers/acpi/hardware/hwsleep.c
new file mode 100644
index 00000000000..77b3e9a8550
--- /dev/null
+++ b/drivers/acpi/hardware/hwsleep.c
@@ -0,0 +1,582 @@
+
+/******************************************************************************
+ *
+ * Name: hwsleep.c - ACPI Hardware Sleep/Wake Interface
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2005, R. Byron Moore
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions, and the following disclaimer,
+ * without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ * substantially similar to the "NO WARRANTY" disclaimer below
+ * ("Disclaimer") and any redistribution must be conditioned upon
+ * including a substantially similar Disclaimer requirement for further
+ * binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ * of any contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ */
+
+#include <linux/module.h>
+
+#include <acpi/acpi.h>
+
+#define _COMPONENT ACPI_HARDWARE
+ ACPI_MODULE_NAME ("hwsleep")
+
+
+#define METHOD_NAME__BFS "\\_BFS"
+#define METHOD_NAME__GTS "\\_GTS"
+#define METHOD_NAME__PTS "\\_PTS"
+#define METHOD_NAME__SST "\\_SI._SST"
+#define METHOD_NAME__WAK "\\_WAK"
+
+#define ACPI_SST_INDICATOR_OFF 0
+#define ACPI_SST_WORKING 1
+#define ACPI_SST_WAKING 2
+#define ACPI_SST_SLEEPING 3
+#define ACPI_SST_SLEEP_CONTEXT 4
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_set_firmware_waking_vector
+ *
+ * PARAMETERS: physical_address - Physical address of ACPI real mode
+ * entry point.
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: access function for d_firmware_waking_vector field in FACS
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_set_firmware_waking_vector (
+ acpi_physical_address physical_address)
+{
+
+ ACPI_FUNCTION_TRACE ("acpi_set_firmware_waking_vector");
+
+
+ /* Set the vector */
+
+ if (acpi_gbl_common_fACS.vector_width == 32) {
+ *(ACPI_CAST_PTR (u32, acpi_gbl_common_fACS.firmware_waking_vector))
+ = (u32) physical_address;
+ }
+ else {
+ *acpi_gbl_common_fACS.firmware_waking_vector
+ = physical_address;
+ }
+
+ return_ACPI_STATUS (AE_OK);
+}
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_get_firmware_waking_vector
+ *
+ * PARAMETERS: *physical_address - Output buffer where contents of
+ * the firmware_waking_vector field of
+ * the FACS will be stored.
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Access function for firmware_waking_vector field in FACS
+ *
+ ******************************************************************************/
+#ifdef ACPI_FUTURE_USAGE
+acpi_status
+acpi_get_firmware_waking_vector (
+ acpi_physical_address *physical_address)
+{
+
+ ACPI_FUNCTION_TRACE ("acpi_get_firmware_waking_vector");
+
+
+ if (!physical_address) {
+ return_ACPI_STATUS (AE_BAD_PARAMETER);
+ }
+
+ /* Get the vector */
+
+ if (acpi_gbl_common_fACS.vector_width == 32) {
+ *physical_address = (acpi_physical_address)
+ *(ACPI_CAST_PTR (u32, acpi_gbl_common_fACS.firmware_waking_vector));
+ }
+ else {
+ *physical_address =
+ *acpi_gbl_common_fACS.firmware_waking_vector;
+ }
+
+ return_ACPI_STATUS (AE_OK);
+}
+#endif
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_enter_sleep_state_prep
+ *
+ * PARAMETERS: sleep_state - Which sleep state to enter
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Prepare to enter a system sleep state (see ACPI 2.0 spec p 231)
+ * This function must execute with interrupts enabled.
+ * We break sleeping into 2 stages so that OSPM can handle
+ * various OS-specific tasks between the two steps.
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_enter_sleep_state_prep (
+ u8 sleep_state)
+{
+ acpi_status status;
+ struct acpi_object_list arg_list;
+ union acpi_object arg;
+
+
+ ACPI_FUNCTION_TRACE ("acpi_enter_sleep_state_prep");
+
+
+ /*
+ * _PSW methods could be run here to enable wake-on keyboard, LAN, etc.
+ */
+ status = acpi_get_sleep_type_data (sleep_state,
+ &acpi_gbl_sleep_type_a, &acpi_gbl_sleep_type_b);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+
+ /* Setup parameter object */
+
+ arg_list.count = 1;
+ arg_list.pointer = &arg;
+
+ arg.type = ACPI_TYPE_INTEGER;
+ arg.integer.value = sleep_state;
+
+ /* Run the _PTS and _GTS methods */
+
+ status = acpi_evaluate_object (NULL, METHOD_NAME__PTS, &arg_list, NULL);
+ if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
+ return_ACPI_STATUS (status);
+ }
+
+ status = acpi_evaluate_object (NULL, METHOD_NAME__GTS, &arg_list, NULL);
+ if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
+ return_ACPI_STATUS (status);
+ }
+
+ /* Setup the argument to _SST */
+
+ switch (sleep_state) {
+ case ACPI_STATE_S0:
+ arg.integer.value = ACPI_SST_WORKING;
+ break;
+
+ case ACPI_STATE_S1:
+ case ACPI_STATE_S2:
+ case ACPI_STATE_S3:
+ arg.integer.value = ACPI_SST_SLEEPING;
+ break;
+
+ case ACPI_STATE_S4:
+ arg.integer.value = ACPI_SST_SLEEP_CONTEXT;
+ break;
+
+ default:
+ arg.integer.value = ACPI_SST_INDICATOR_OFF; /* Default is indicator off */
+ break;
+ }
+
+ /* Set the system indicators to show the desired sleep state. */
+
+ status = acpi_evaluate_object (NULL, METHOD_NAME__SST, &arg_list, NULL);
+ if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
+ ACPI_REPORT_ERROR (("Method _SST failed, %s\n", acpi_format_exception (status)));
+ }
+
+ return_ACPI_STATUS (AE_OK);
+}
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_enter_sleep_state
+ *
+ * PARAMETERS: sleep_state - Which sleep state to enter
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Enter a system sleep state (see ACPI 2.0 spec p 231)
+ * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
+ *
+ ******************************************************************************/
+
+acpi_status asmlinkage
+acpi_enter_sleep_state (
+ u8 sleep_state)
+{
+ u32 PM1Acontrol;
+ u32 PM1Bcontrol;
+ struct acpi_bit_register_info *sleep_type_reg_info;
+ struct acpi_bit_register_info *sleep_enable_reg_info;
+ u32 in_value;
+ acpi_status status;
+
+
+ ACPI_FUNCTION_TRACE ("acpi_enter_sleep_state");
+
+
+ if ((acpi_gbl_sleep_type_a > ACPI_SLEEP_TYPE_MAX) ||
+ (acpi_gbl_sleep_type_b > ACPI_SLEEP_TYPE_MAX)) {
+ ACPI_REPORT_ERROR (("Sleep values out of range: A=%X B=%X\n",
+ acpi_gbl_sleep_type_a, acpi_gbl_sleep_type_b));
+ return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
+ }
+
+ sleep_type_reg_info = acpi_hw_get_bit_register_info (ACPI_BITREG_SLEEP_TYPE_A);
+ sleep_enable_reg_info = acpi_hw_get_bit_register_info (ACPI_BITREG_SLEEP_ENABLE);
+
+ /* Clear wake status */
+
+ status = acpi_set_register (ACPI_BITREG_WAKE_STATUS, 1, ACPI_MTX_DO_NOT_LOCK);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+
+ /* Clear all fixed and general purpose status bits */
+
+ status = acpi_hw_clear_acpi_status (ACPI_MTX_DO_NOT_LOCK);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+
+ /*
+ * 1) Disable/Clear all GPEs
+ * 2) Enable all wakeup GPEs
+ */
+ status = acpi_hw_disable_all_gpes (ACPI_ISR);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+ acpi_gbl_system_awake_and_running = FALSE;
+
+ status = acpi_hw_enable_all_wakeup_gpes (ACPI_ISR);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+
+ /* Get current value of PM1A control */
+
+ status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_CONTROL, &PM1Acontrol);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+ ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Entering sleep state [S%d]\n", sleep_state));
+
+ /* Clear SLP_EN and SLP_TYP fields */
+
+ PM1Acontrol &= ~(sleep_type_reg_info->access_bit_mask | sleep_enable_reg_info->access_bit_mask);
+ PM1Bcontrol = PM1Acontrol;
+
+ /* Insert SLP_TYP bits */
+
+ PM1Acontrol |= (acpi_gbl_sleep_type_a << sleep_type_reg_info->bit_position);
+ PM1Bcontrol |= (acpi_gbl_sleep_type_b << sleep_type_reg_info->bit_position);
+
+ /*
+ * We split the writes of SLP_TYP and SLP_EN to workaround
+ * poorly implemented hardware.
+ */
+
+ /* Write #1: fill in SLP_TYP data */
+
+ status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1A_CONTROL, PM1Acontrol);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+
+ status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1B_CONTROL, PM1Bcontrol);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+
+ /* Insert SLP_ENABLE bit */
+
+ PM1Acontrol |= sleep_enable_reg_info->access_bit_mask;
+ PM1Bcontrol |= sleep_enable_reg_info->access_bit_mask;
+
+ /* Write #2: SLP_TYP + SLP_EN */
+
+ ACPI_FLUSH_CPU_CACHE ();
+
+ status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1A_CONTROL, PM1Acontrol);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+
+ status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1B_CONTROL, PM1Bcontrol);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+
+ if (sleep_state > ACPI_STATE_S3) {
+ /*
+ * We wanted to sleep > S3, but it didn't happen (by virtue of the fact that
+ * we are still executing!)
+ *
+ * Wait ten seconds, then try again. This is to get S4/S5 to work on all machines.
+ *
+ * We wait so long to allow chipsets that poll this reg very slowly to
+ * still read the right value. Ideally, this block would go
+ * away entirely.
+ */
+ acpi_os_stall (10000000);
+
+ status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_CONTROL,
+ sleep_enable_reg_info->access_bit_mask);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+ }
+
+ /* Wait until we enter sleep state */
+
+ do {
+ status = acpi_get_register (ACPI_BITREG_WAKE_STATUS, &in_value, ACPI_MTX_DO_NOT_LOCK);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+
+ /* Spin until we wake */
+
+ } while (!in_value);
+
+ return_ACPI_STATUS (AE_OK);
+}
+EXPORT_SYMBOL(acpi_enter_sleep_state);
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_enter_sleep_state_s4bios
+ *
+ * PARAMETERS: None
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Perform a S4 bios request.
+ * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
+ *
+ ******************************************************************************/
+
+acpi_status asmlinkage
+acpi_enter_sleep_state_s4bios (
+ void)
+{
+ u32 in_value;
+ acpi_status status;
+
+
+ ACPI_FUNCTION_TRACE ("acpi_enter_sleep_state_s4bios");
+
+
+ status = acpi_set_register (ACPI_BITREG_WAKE_STATUS, 1, ACPI_MTX_DO_NOT_LOCK);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+
+ status = acpi_hw_clear_acpi_status (ACPI_MTX_DO_NOT_LOCK);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+
+ /*
+ * 1) Disable/Clear all GPEs
+ * 2) Enable all wakeup GPEs
+ */
+ status = acpi_hw_disable_all_gpes (ACPI_ISR);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+ acpi_gbl_system_awake_and_running = FALSE;
+
+ status = acpi_hw_enable_all_wakeup_gpes (ACPI_ISR);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+
+ ACPI_FLUSH_CPU_CACHE ();
+
+ status = acpi_os_write_port (acpi_gbl_FADT->smi_cmd, (u32) acpi_gbl_FADT->S4bios_req, 8);
+
+ do {
+ acpi_os_stall(1000);
+ status = acpi_get_register (ACPI_BITREG_WAKE_STATUS, &in_value, ACPI_MTX_DO_NOT_LOCK);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+ } while (!in_value);
+
+ return_ACPI_STATUS (AE_OK);
+}
+EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios);
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_leave_sleep_state
+ *
+ * PARAMETERS: sleep_state - Which sleep state we just exited
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
+ * Called with interrupts ENABLED.
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_leave_sleep_state (
+ u8 sleep_state)
+{
+ struct acpi_object_list arg_list;
+ union acpi_object arg;
+ acpi_status status;
+ struct acpi_bit_register_info *sleep_type_reg_info;
+ struct acpi_bit_register_info *sleep_enable_reg_info;
+ u32 PM1Acontrol;
+ u32 PM1Bcontrol;
+
+
+ ACPI_FUNCTION_TRACE ("acpi_leave_sleep_state");
+
+
+ /*
+ * Set SLP_TYPE and SLP_EN to state S0.
+ * This is unclear from the ACPI Spec, but it is required
+ * by some machines.
+ */
+ status = acpi_get_sleep_type_data (ACPI_STATE_S0,
+ &acpi_gbl_sleep_type_a, &acpi_gbl_sleep_type_b);
+ if (ACPI_SUCCESS (status)) {
+ sleep_type_reg_info = acpi_hw_get_bit_register_info (ACPI_BITREG_SLEEP_TYPE_A);
+ sleep_enable_reg_info = acpi_hw_get_bit_register_info (ACPI_BITREG_SLEEP_ENABLE);
+
+ /* Get current value of PM1A control */
+
+ status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK,
+ ACPI_REGISTER_PM1_CONTROL, &PM1Acontrol);
+ if (ACPI_SUCCESS (status)) {
+ /* Clear SLP_EN and SLP_TYP fields */
+
+ PM1Acontrol &= ~(sleep_type_reg_info->access_bit_mask |
+ sleep_enable_reg_info->access_bit_mask);
+ PM1Bcontrol = PM1Acontrol;
+
+ /* Insert SLP_TYP bits */
+
+ PM1Acontrol |= (acpi_gbl_sleep_type_a << sleep_type_reg_info->bit_position);
+ PM1Bcontrol |= (acpi_gbl_sleep_type_b << sleep_type_reg_info->bit_position);
+
+ /* Just ignore any errors */
+
+ (void) acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
+ ACPI_REGISTER_PM1A_CONTROL, PM1Acontrol);
+ (void) acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
+ ACPI_REGISTER_PM1B_CONTROL, PM1Bcontrol);
+ }
+ }
+
+ /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */
+
+ acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID;
+
+ /* Setup parameter object */
+
+ arg_list.count = 1;
+ arg_list.pointer = &arg;
+ arg.type = ACPI_TYPE_INTEGER;
+
+ /* Ignore any errors from these methods */
+
+ arg.integer.value = ACPI_SST_WAKING;
+ status = acpi_evaluate_object (NULL, METHOD_NAME__SST, &arg_list, NULL);
+ if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
+ ACPI_REPORT_ERROR (("Method _SST failed, %s\n", acpi_format_exception (status)));
+ }
+
+ arg.integer.value = sleep_state;
+ status = acpi_evaluate_object (NULL, METHOD_NAME__BFS, &arg_list, NULL);
+ if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
+ ACPI_REPORT_ERROR (("Method _BFS failed, %s\n", acpi_format_exception (status)));
+ }
+
+ status = acpi_evaluate_object (NULL, METHOD_NAME__WAK, &arg_list, NULL);
+ if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
+ ACPI_REPORT_ERROR (("Method _WAK failed, %s\n", acpi_format_exception (status)));
+ }
+ /* TBD: _WAK "sometimes" returns stuff - do we want to look at it? */
+
+ /*
+ * Restore the GPEs:
+ * 1) Disable/Clear all GPEs
+ * 2) Enable all runtime GPEs
+ */
+ status = acpi_hw_disable_all_gpes (ACPI_NOT_ISR);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+ acpi_gbl_system_awake_and_running = TRUE;
+
+ status = acpi_hw_enable_all_runtime_gpes (ACPI_NOT_ISR);
+ if (ACPI_FAILURE (status)) {
+ return_ACPI_STATUS (status);
+ }
+
+ /* Enable power button */
+
+ (void) acpi_set_register(acpi_gbl_fixed_event_info[ACPI_EVENT_POWER_BUTTON].enable_register_id,
+ 1, ACPI_MTX_DO_NOT_LOCK);
+ (void) acpi_set_register(acpi_gbl_fixed_event_info[ACPI_EVENT_POWER_BUTTON].status_register_id,
+ 1, ACPI_MTX_DO_NOT_LOCK);
+
+ arg.integer.value = ACPI_SST_WORKING;
+ status = acpi_evaluate_object (NULL, METHOD_NAME__SST, &arg_list, NULL);
+ if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
+ ACPI_REPORT_ERROR (("Method _SST failed, %s\n", acpi_format_exception (status)));
+ }
+
+ return_ACPI_STATUS (status);
+}
diff --git a/drivers/acpi/hardware/hwtimer.c b/drivers/acpi/hardware/hwtimer.c
new file mode 100644
index 00000000000..1906167d729
--- /dev/null
+++ b/drivers/acpi/hardware/hwtimer.c
@@ -0,0 +1,203 @@
+
+/******************************************************************************
+ *
+ * Name: hwtimer.c - ACPI Power Management Timer Interface
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2005, R. Byron Moore
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions, and the following disclaimer,
+ * without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ * substantially similar to the "NO WARRANTY" disclaimer below
+ * ("Disclaimer") and any redistribution must be conditioned upon
+ * including a substantially similar Disclaimer requirement for further
+ * binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ * of any contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ */
+
+#include <linux/module.h>
+
+#include <acpi/acpi.h>
+
+#define _COMPONENT ACPI_HARDWARE
+ ACPI_MODULE_NAME ("hwtimer")
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_get_timer_resolution
+ *
+ * PARAMETERS: Resolution - Where the resolution is returned
+ *
+ * RETURN: Status and timer resolution
+ *
+ * DESCRIPTION: Obtains resolution of the ACPI PM Timer (24 or 32 bits).
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_get_timer_resolution (
+ u32 *resolution)
+{
+ ACPI_FUNCTION_TRACE ("acpi_get_timer_resolution");
+
+
+ if (!resolution) {
+ return_ACPI_STATUS (AE_BAD_PARAMETER);
+ }
+
+ if (0 == acpi_gbl_FADT->tmr_val_ext) {
+ *resolution = 24;
+ }
+ else {
+ *resolution = 32;
+ }
+
+ return_ACPI_STATUS (AE_OK);
+}
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_get_timer
+ *
+ * PARAMETERS: Ticks - Where the timer value is returned
+ *
+ * RETURN: Status and current ticks
+ *
+ * DESCRIPTION: Obtains current value of ACPI PM Timer (in ticks).
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_get_timer (
+ u32 *ticks)
+{
+ acpi_status status;
+
+
+ ACPI_FUNCTION_TRACE ("acpi_get_timer");
+
+
+ if (!ticks) {
+ return_ACPI_STATUS (AE_BAD_PARAMETER);
+ }
+
+ status = acpi_hw_low_level_read (32, ticks, &acpi_gbl_FADT->xpm_tmr_blk);
+
+ return_ACPI_STATUS (status);
+}
+EXPORT_SYMBOL(acpi_get_timer);
+
+
+/******************************************************************************
+ *
+ * FUNCTION: acpi_get_timer_duration
+ *
+ * PARAMETERS: start_ticks - Starting timestamp
+ * end_ticks - End timestamp
+ * time_elapsed - Where the elapsed time is returned
+ *
+ * RETURN: Status and time_elapsed
+ *
+ * DESCRIPTION: Computes the time elapsed (in microseconds) between two
+ * PM Timer time stamps, taking into account the possibility of
+ * rollovers, the timer resolution, and timer frequency.
+ *
+ * The PM Timer's clock ticks at roughly 3.6 times per
+ * _microsecond_, and its clock continues through Cx state
+ * transitions (unlike many CPU timestamp counters) -- making it
+ * a versatile and accurate timer.
+ *
+ * Note that this function accommodates only a single timer
+ * rollover. Thus for 24-bit timers, this function should only
+ * be used for calculating durations less than ~4.6 seconds
+ * (~20 minutes for 32-bit timers) -- calculations below:
+ *
+ * 2**24 Ticks / 3,600,000 Ticks/Sec = 4.66 sec
+ * 2**32 Ticks / 3,600,000 Ticks/Sec = 1193 sec or 19.88 minutes
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_get_timer_duration (
+ u32 start_ticks,
+ u32 end_ticks,
+ u32 *time_elapsed)
+{
+ acpi_status status;
+ u32 delta_ticks;
+ acpi_integer quotient;
+
+
+ ACPI_FUNCTION_TRACE ("acpi_get_timer_duration");
+
+
+ if (!time_elapsed) {
+ return_ACPI_STATUS (AE_BAD_PARAMETER);
+ }
+
+ /*
+ * Compute Tick Delta:
+ * Handle (max one) timer rollovers on 24-bit versus 32-bit timers.
+ */
+ if (start_ticks < end_ticks) {
+ delta_ticks = end_ticks - start_ticks;
+ }
+ else if (start_ticks > end_ticks) {
+ if (0 == acpi_gbl_FADT->tmr_val_ext) {
+ /* 24-bit Timer */
+
+ delta_ticks = (((0x00FFFFFF - start_ticks) + end_ticks) & 0x00FFFFFF);
+ }
+ else {
+ /* 32-bit Timer */
+
+ delta_ticks = (0xFFFFFFFF - start_ticks) + end_ticks;
+ }
+ }
+ else /* start_ticks == end_ticks */ {
+ *time_elapsed = 0;
+ return_ACPI_STATUS (AE_OK);
+ }
+
+ /*
+ * Compute Duration (Requires a 64-bit multiply and divide):
+ *
+ * time_elapsed = (delta_ticks * 1000000) / PM_TIMER_FREQUENCY;
+ */
+ status = acpi_ut_short_divide (((u64) delta_ticks) * 1000000,
+ PM_TIMER_FREQUENCY, &quotient, NULL);
+
+ *time_elapsed = (u32) quotient;
+ return_ACPI_STATUS (status);
+}
+EXPORT_SYMBOL(acpi_get_timer_duration);
+