ia64/xen-unstable

changeset 17266:26a7a2d154e1

x86 ACPI sleep: Fix a bug when ACPI registers in System_Memory

Some ACPI registers may be in System_Memory but not System_IO space,
For these machines S3 fails since current Xen use I/O instructions (e.g.
inb(), outb(), etc.) to access ACPI registers. The patch attached fix
the bug by adding GAS (generic address structure) support ported from
Linux, which should also benefit later ACPI activity within Xen.

Signed-off-by: Huacai Chen <huacai.chen@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Mar 19 10:33:13 2008 +0000 (2008-03-19)
parents 70f9a2110421
children d1e91aba2758
files xen/arch/x86/acpi/boot.c xen/arch/x86/acpi/power.c xen/drivers/acpi/Makefile xen/drivers/acpi/hwregs.c xen/drivers/acpi/osl.c xen/include/asm-x86/acpi.h
line diff
     1.1 --- a/xen/arch/x86/acpi/boot.c	Wed Mar 19 10:22:49 2008 +0000
     1.2 +++ b/xen/arch/x86/acpi/boot.c	Wed Mar 19 10:33:13 2008 +0000
     1.3 @@ -349,10 +349,10 @@ static int __init acpi_parse_hpet(unsign
     1.4  	}
     1.5  
     1.6  #if 0/*def	CONFIG_X86_64*/
     1.7 -        vxtime.hpet_address = hpet_tbl->address.address;
     1.8 +	vxtime.hpet_address = hpet_tbl->address.address;
     1.9  
    1.10 -        printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
    1.11 -               hpet_tbl->id, vxtime.hpet_address);
    1.12 +	printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
    1.13 +	       hpet_tbl->id, vxtime.hpet_address);
    1.14  #else	/* X86 */
    1.15  	{
    1.16  		extern unsigned long hpet_address;
    1.17 @@ -389,32 +389,37 @@ acpi_fadt_parse_sleep_info(struct acpi_t
    1.18  	rsdp = __va(rsdp_phys);
    1.19  
    1.20  	if (fadt->header.revision >= FADT2_REVISION_ID) {
    1.21 -		/* Sanity check on FADT Rev. 2 */
    1.22 -		if ((fadt->xpm1a_control_block.space_id !=
    1.23 -		     ACPI_ADR_SPACE_SYSTEM_IO) ||
    1.24 -		    (fadt->xpm1b_control_block.space_id !=
    1.25 -		     ACPI_ADR_SPACE_SYSTEM_IO) ||
    1.26 -		    (fadt->xpm1a_event_block.space_id !=
    1.27 -		     ACPI_ADR_SPACE_SYSTEM_IO) ||
    1.28 -		    (fadt->xpm1b_event_block.space_id !=
    1.29 -		     ACPI_ADR_SPACE_SYSTEM_IO))
    1.30 -			goto bad; 
    1.31 -
    1.32 -		acpi_sinfo.pm1a_cnt = (uint16_t)fadt->xpm1a_control_block.address;
    1.33 -		acpi_sinfo.pm1b_cnt = (uint16_t)fadt->xpm1b_control_block.address;
    1.34 -		acpi_sinfo.pm1a_evt = (uint16_t)fadt->xpm1a_event_block.address;
    1.35 -		acpi_sinfo.pm1b_evt = (uint16_t)fadt->xpm1b_event_block.address;
    1.36 +		memcpy(&acpi_sinfo.pm1a_cnt_blk, &fadt->xpm1a_control_block,
    1.37 +			sizeof(struct acpi_generic_address));
    1.38 +		memcpy(&acpi_sinfo.pm1b_cnt_blk, &fadt->xpm1b_control_block,
    1.39 +			sizeof(struct acpi_generic_address));
    1.40 +		memcpy(&acpi_sinfo.pm1a_evt_blk, &fadt->xpm1a_event_block,
    1.41 +			sizeof(struct acpi_generic_address));
    1.42 +		memcpy(&acpi_sinfo.pm1b_evt_blk, &fadt->xpm1b_event_block,
    1.43 +			sizeof(struct acpi_generic_address));
    1.44 +	} else {
    1.45 +		acpi_sinfo.pm1a_cnt_blk.address = fadt->pm1a_control_block;
    1.46 +		acpi_sinfo.pm1b_cnt_blk.address = fadt->pm1b_control_block;
    1.47 +		acpi_sinfo.pm1a_evt_blk.address = fadt->pm1a_event_block;
    1.48 +		acpi_sinfo.pm1b_evt_blk.address = fadt->pm1b_event_block;
    1.49 +		acpi_sinfo.pm1a_cnt_blk.space_id = ACPI_ADR_SPACE_SYSTEM_IO;
    1.50 +		acpi_sinfo.pm1b_cnt_blk.space_id = ACPI_ADR_SPACE_SYSTEM_IO;
    1.51 +		acpi_sinfo.pm1a_evt_blk.space_id = ACPI_ADR_SPACE_SYSTEM_IO;
    1.52 +		acpi_sinfo.pm1b_evt_blk.space_id = ACPI_ADR_SPACE_SYSTEM_IO;
    1.53 +		acpi_sinfo.pm1a_cnt_blk.bit_width = 16;
    1.54 +		acpi_sinfo.pm1b_cnt_blk.bit_width = 16;
    1.55 +		acpi_sinfo.pm1a_evt_blk.bit_width = 16;
    1.56 +		acpi_sinfo.pm1b_evt_blk.bit_width = 16;
    1.57 +		acpi_sinfo.pm1a_cnt_blk.bit_offset = 0;
    1.58 +		acpi_sinfo.pm1b_cnt_blk.bit_offset = 0;
    1.59 +		acpi_sinfo.pm1a_evt_blk.bit_offset = 0;
    1.60 +		acpi_sinfo.pm1b_evt_blk.bit_offset = 0;
    1.61 +		acpi_sinfo.pm1a_cnt_blk.access_width = 0;
    1.62 +		acpi_sinfo.pm1b_cnt_blk.access_width = 0;
    1.63 +		acpi_sinfo.pm1a_evt_blk.access_width = 0;
    1.64 +		acpi_sinfo.pm1b_evt_blk.access_width = 0;
    1.65  	}
    1.66  
    1.67 -	if (!acpi_sinfo.pm1a_cnt)
    1.68 -		acpi_sinfo.pm1a_cnt = (uint16_t)fadt->pm1a_control_block;
    1.69 -	if (!acpi_sinfo.pm1b_cnt)
    1.70 -		acpi_sinfo.pm1b_cnt = (uint16_t)fadt->pm1b_control_block;
    1.71 -	if (!acpi_sinfo.pm1a_evt)
    1.72 -		acpi_sinfo.pm1a_evt = (uint16_t)fadt->pm1a_event_block;
    1.73 -	if (!acpi_sinfo.pm1b_evt)
    1.74 -		acpi_sinfo.pm1b_evt = (uint16_t)fadt->pm1b_event_block;
    1.75 -
    1.76  	/* Now FACS... */
    1.77  	if (fadt->header.revision >= FADT2_REVISION_ID)
    1.78  		facs_pa = fadt->Xfacs;
    1.79 @@ -456,9 +461,12 @@ acpi_fadt_parse_sleep_info(struct acpi_t
    1.80  	}
    1.81  
    1.82  	printk(KERN_INFO PREFIX
    1.83 -	       "ACPI SLEEP INFO: pm1x_cnt[%x,%x], pm1x_evt[%x,%x]\n",
    1.84 -	       acpi_sinfo.pm1a_cnt, acpi_sinfo.pm1b_cnt,
    1.85 -	       acpi_sinfo.pm1a_evt, acpi_sinfo.pm1b_cnt);
    1.86 +	       "ACPI SLEEP INFO: pm1x_cnt[%"PRIx64",%"PRIx64"], "
    1.87 +	       "pm1x_evt[%"PRIx64",%"PRIx64"]\n",
    1.88 +	       acpi_sinfo.pm1a_cnt_blk.address,
    1.89 +	       acpi_sinfo.pm1b_cnt_blk.address,
    1.90 +	       acpi_sinfo.pm1a_evt_blk.address,
    1.91 +	       acpi_sinfo.pm1b_evt_blk.address);
    1.92  	printk(KERN_INFO PREFIX
    1.93  	       "                 wakeup_vec[%"PRIx64"], vec_size[%x]\n",
    1.94  	       acpi_sinfo.wakeup_vector, acpi_sinfo.vector_width);
     2.1 --- a/xen/arch/x86/acpi/power.c	Wed Mar 19 10:22:49 2008 +0000
     2.2 +++ b/xen/arch/x86/acpi/power.c	Wed Mar 19 10:33:13 2008 +0000
     2.3 @@ -106,7 +106,7 @@ static void acpi_sleep_prepare(u32 state
     2.4              *(uint64_t *)wakeup_vector_va =
     2.5                  tboot_in_measured_env() ?
     2.6                  (uint64_t)g_tboot_shared->s3_tb_wakeup_entry :
     2.7 -	        (uint64_t)bootsym_phys(wakeup_start);
     2.8 +                (uint64_t)bootsym_phys(wakeup_start);
     2.9      }
    2.10  }
    2.11  
    2.12 @@ -198,7 +198,7 @@ static long enter_state_helper(void *dat
    2.13   */
    2.14  int acpi_enter_sleep(struct xenpf_enter_acpi_sleep *sleep)
    2.15  {
    2.16 -    if ( !IS_PRIV(current->domain) || !acpi_sinfo.pm1a_cnt )
    2.17 +    if ( !IS_PRIV(current->domain) || !acpi_sinfo.pm1a_cnt_blk.address )
    2.18          return -EPERM;
    2.19  
    2.20      /* Sanity check */
    2.21 @@ -222,10 +222,14 @@ int acpi_enter_sleep(struct xenpf_enter_
    2.22  
    2.23  static int acpi_get_wake_status(void)
    2.24  {
    2.25 -    uint16_t val;
    2.26 +    uint32_t val;
    2.27 +    acpi_status status;
    2.28  
    2.29      /* Wake status is the 15th bit of PM1 status register. (ACPI spec 3.0) */
    2.30 -    val = inw(acpi_sinfo.pm1a_evt) | inw(acpi_sinfo.pm1b_evt);
    2.31 +    status = acpi_hw_register_read(ACPI_REGISTER_PM1_STATUS, &val);
    2.32 +    if ( ACPI_FAILURE(status) )
    2.33 +        return 0;
    2.34 +
    2.35      val &= ACPI_BITMASK_WAKE_STATUS;
    2.36      val >>= ACPI_BITPOSITION_WAKE_STATUS;
    2.37      return val;
    2.38 @@ -243,7 +247,7 @@ static void tboot_sleep(u8 sleep_state)
    2.39         case ACPI_STATE_S3:
    2.40             shutdown_type = TB_SHUTDOWN_S3;
    2.41             g_tboot_shared->s3_k_wakeup_entry =
    2.42 -	       (uint32_t)bootsym_phys(wakeup_start);
    2.43 +               (uint32_t)bootsym_phys(wakeup_start);
    2.44             break;
    2.45         case ACPI_STATE_S4:
    2.46             shutdown_type = TB_SHUTDOWN_S4;
    2.47 @@ -261,6 +265,8 @@ static void tboot_sleep(u8 sleep_state)
    2.48  /* System is really put into sleep state by this stub */
    2.49  acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
    2.50  {
    2.51 +    acpi_status status;
    2.52 +
    2.53      if ( tboot_in_measured_env() )
    2.54      {
    2.55          tboot_sleep(sleep_state);
    2.56 @@ -270,9 +276,18 @@ acpi_status asmlinkage acpi_enter_sleep_
    2.57  
    2.58      ACPI_FLUSH_CPU_CACHE();
    2.59  
    2.60 -    outw((u16)acpi_sinfo.pm1a_cnt_val, acpi_sinfo.pm1a_cnt);
    2.61 -    if ( acpi_sinfo.pm1b_cnt )
    2.62 -        outw((u16)acpi_sinfo.pm1b_cnt_val, acpi_sinfo.pm1b_cnt);
    2.63 +    status = acpi_hw_register_write(ACPI_REGISTER_PM1A_CONTROL, 
    2.64 +                                    acpi_sinfo.pm1a_cnt_val);
    2.65 +    if ( ACPI_FAILURE(status) )
    2.66 +        return_ACPI_STATUS(AE_ERROR);
    2.67 +
    2.68 +    if ( acpi_sinfo.pm1b_cnt_blk.address )
    2.69 +    {
    2.70 +        status = acpi_hw_register_write(ACPI_REGISTER_PM1B_CONTROL, 
    2.71 +                                        acpi_sinfo.pm1b_cnt_val);
    2.72 +        if ( ACPI_FAILURE(status) )
    2.73 +            return_ACPI_STATUS(AE_ERROR);
    2.74 +    }
    2.75  
    2.76      /* Wait until we enter sleep state, and spin until we wake */
    2.77      while ( !acpi_get_wake_status() )
     3.1 --- a/xen/drivers/acpi/Makefile	Wed Mar 19 10:22:49 2008 +0000
     3.2 +++ b/xen/drivers/acpi/Makefile	Wed Mar 19 10:33:13 2008 +0000
     3.3 @@ -1,2 +1,4 @@
     3.4  obj-y += tables.o
     3.5  obj-y += numa.o
     3.6 +obj-y += hwregs.o
     3.7 +obj-y += osl.o
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/xen/drivers/acpi/hwregs.c	Wed Mar 19 10:33:13 2008 +0000
     4.3 @@ -0,0 +1,385 @@
     4.4 +
     4.5 +/*******************************************************************************
     4.6 + *
     4.7 + * Module Name: hwregs - Read/write access functions for the various ACPI
     4.8 + *                       control and status registers.
     4.9 + *
    4.10 + ******************************************************************************/
    4.11 +
    4.12 +/*
    4.13 + * Copyright (C) 2000 - 2006, R. Byron Moore
    4.14 + * All rights reserved.
    4.15 + *
    4.16 + * Redistribution and use in source and binary forms, with or without
    4.17 + * modification, are permitted provided that the following conditions
    4.18 + * are met:
    4.19 + * 1. Redistributions of source code must retain the above copyright
    4.20 + *    notice, this list of conditions, and the following disclaimer,
    4.21 + *    without modification.
    4.22 + * 2. Redistributions in binary form must reproduce at minimum a disclaimer
    4.23 + *    substantially similar to the "NO WARRANTY" disclaimer below
    4.24 + *    ("Disclaimer") and any redistribution must be conditioned upon
    4.25 + *    including a substantially similar Disclaimer requirement for further
    4.26 + *    binary redistribution.
    4.27 + * 3. Neither the names of the above-listed copyright holders nor the names
    4.28 + *    of any contributors may be used to endorse or promote products derived
    4.29 + *    from this software without specific prior written permission.
    4.30 + *
    4.31 + * Alternatively, this software may be distributed under the terms of the
    4.32 + * GNU General Public License ("GPL") version 2 as published by the Free
    4.33 + * Software Foundation.
    4.34 + *
    4.35 + * NO WARRANTY
    4.36 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    4.37 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    4.38 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
    4.39 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    4.40 + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    4.41 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    4.42 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    4.43 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    4.44 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
    4.45 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    4.46 + * POSSIBILITY OF SUCH DAMAGES.
    4.47 + */
    4.48 +
    4.49 +#include <asm/io.h>
    4.50 +#include <xen/config.h>
    4.51 +#include <xen/init.h>
    4.52 +#include <xen/types.h>
    4.53 +#include <xen/errno.h>
    4.54 +#include <acpi/acpi.h>
    4.55 +
    4.56 +#define _COMPONENT          ACPI_HARDWARE
    4.57 +ACPI_MODULE_NAME("hwregs")
    4.58 +
    4.59 +/******************************************************************************
    4.60 + *
    4.61 + * FUNCTION:    acpi_hw_register_read
    4.62 + *
    4.63 + * PARAMETERS:  register_id         - ACPI Register ID
    4.64 + *              return_value        - Where the register value is returned
    4.65 + *
    4.66 + * RETURN:      Status and the value read.
    4.67 + *
    4.68 + * DESCRIPTION: Read from the specified ACPI register
    4.69 + *
    4.70 + ******************************************************************************/
    4.71 +acpi_status
    4.72 +acpi_hw_register_read(u32 register_id, u32 * return_value)
    4.73 +{
    4.74 +	u32 value1 = 0;
    4.75 +	u32 value2 = 0;
    4.76 +	acpi_status status;
    4.77 +
    4.78 +	ACPI_FUNCTION_TRACE(hw_register_read);
    4.79 +
    4.80 +	switch (register_id) {
    4.81 +	case ACPI_REGISTER_PM1_STATUS:	/* 16-bit access */
    4.82 +
    4.83 +		status =
    4.84 +		    acpi_hw_low_level_read(16, &value1,
    4.85 +					   &acpi_sinfo.pm1a_evt_blk);
    4.86 +		if (ACPI_FAILURE(status)) {
    4.87 +			goto exit;
    4.88 +		}
    4.89 +
    4.90 +		/* PM1B is optional */
    4.91 +
    4.92 +		status =
    4.93 +		    acpi_hw_low_level_read(16, &value2,
    4.94 +					   &acpi_sinfo.pm1b_evt_blk);
    4.95 +		value1 |= value2;
    4.96 +		break;
    4.97 +
    4.98 +
    4.99 +	case ACPI_REGISTER_PM1_CONTROL:	/* 16-bit access */
   4.100 +
   4.101 +		status =
   4.102 +		    acpi_hw_low_level_read(16, &value1,
   4.103 +					   &acpi_sinfo.pm1a_cnt_blk);
   4.104 +		if (ACPI_FAILURE(status)) {
   4.105 +			goto exit;
   4.106 +		}
   4.107 +
   4.108 +		status =
   4.109 +		    acpi_hw_low_level_read(16, &value2,
   4.110 +					   &acpi_sinfo.pm1b_cnt_blk);
   4.111 +		value1 |= value2;
   4.112 +		break;
   4.113 +
   4.114 +
   4.115 +	default:
   4.116 +		status = AE_BAD_PARAMETER;
   4.117 +		break;
   4.118 +	}
   4.119 +
   4.120 +      exit:
   4.121 +
   4.122 +	if (ACPI_SUCCESS(status)) {
   4.123 +		*return_value = value1;
   4.124 +	}
   4.125 +
   4.126 +	return_ACPI_STATUS(status);
   4.127 +}
   4.128 +
   4.129 +/******************************************************************************
   4.130 + *
   4.131 + * FUNCTION:    acpi_hw_register_write
   4.132 + *
   4.133 + * PARAMETERS:  register_id         - ACPI Register ID 
   4.134 + *              Value               - The value to write
   4.135 + *
   4.136 + * RETURN:      Status
   4.137 + *
   4.138 + * DESCRIPTION: Write to the specified ACPI register
   4.139 + *
   4.140 + * NOTE: In accordance with the ACPI specification, this function automatically
   4.141 + * preserves the value of the following bits, meaning that these bits cannot be
   4.142 + * changed via this interface:
   4.143 + *
   4.144 + * PM1_CONTROL[0] = SCI_EN
   4.145 + * PM1_CONTROL[9]
   4.146 + * PM1_STATUS[11]
   4.147 + *
   4.148 + * ACPI References:
   4.149 + * 1) Hardware Ignored Bits: When software writes to a register with ignored
   4.150 + *      bit fields, it preserves the ignored bit fields
   4.151 + * 2) SCI_EN: OSPM always preserves this bit position
   4.152 + *
   4.153 + ******************************************************************************/
   4.154 +
   4.155 +acpi_status acpi_hw_register_write(u32 register_id, u32 value)
   4.156 +{
   4.157 +	acpi_status status;
   4.158 +	u32 read_value;
   4.159 +
   4.160 +	ACPI_FUNCTION_TRACE(hw_register_write);
   4.161 +
   4.162 +	switch (register_id) {   //By now we just need handle PM1 status/PM1 control
   4.163 +	case ACPI_REGISTER_PM1_STATUS:	/* 16-bit access */
   4.164 +
   4.165 +		/* Perform a read first to preserve certain bits (per ACPI spec) */
   4.166 +
   4.167 +		status = acpi_hw_register_read(ACPI_REGISTER_PM1_STATUS,
   4.168 +					       &read_value);
   4.169 +		if (ACPI_FAILURE(status)) {
   4.170 +			goto exit;
   4.171 +		}
   4.172 +
   4.173 +		/* Insert the bits to be preserved */
   4.174 +
   4.175 +		ACPI_INSERT_BITS(value, ACPI_PM1_STATUS_PRESERVED_BITS,
   4.176 +				 read_value);
   4.177 +
   4.178 +		/* Now we can write the data */
   4.179 +
   4.180 +		status =
   4.181 +		    acpi_hw_low_level_write(16, value,
   4.182 +					    &acpi_sinfo.pm1a_evt_blk);
   4.183 +		if (ACPI_FAILURE(status)) {
   4.184 +			goto exit;
   4.185 +		}
   4.186 +
   4.187 +		/* PM1B is optional */
   4.188 +
   4.189 +		status =
   4.190 +		    acpi_hw_low_level_write(16, value,
   4.191 +					    &acpi_sinfo.pm1b_evt_blk);
   4.192 +		break;
   4.193 +
   4.194 +
   4.195 +	case ACPI_REGISTER_PM1_CONTROL:	/* 16-bit access */
   4.196 +
   4.197 +		/*
   4.198 +		 * Perform a read first to preserve certain bits (per ACPI spec)
   4.199 +		 *
   4.200 +		 * Note: This includes SCI_EN, we never want to change this bit
   4.201 +		 */
   4.202 +		status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL,
   4.203 +					       &read_value);
   4.204 +		if (ACPI_FAILURE(status)) {
   4.205 +			goto exit;
   4.206 +		}
   4.207 +
   4.208 +		/* Insert the bits to be preserved */
   4.209 +
   4.210 +		ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS,
   4.211 +				 read_value);
   4.212 +
   4.213 +		/* Now we can write the data */
   4.214 +
   4.215 +		status =
   4.216 +		    acpi_hw_low_level_write(16, value,
   4.217 +					    &acpi_sinfo.pm1a_cnt_blk);
   4.218 +		if (ACPI_FAILURE(status)) {
   4.219 +			goto exit;
   4.220 +		}
   4.221 +
   4.222 +		status =
   4.223 +		    acpi_hw_low_level_write(16, value,
   4.224 +					    &acpi_sinfo.pm1b_cnt_blk);
   4.225 +		break;
   4.226 +
   4.227 +	case ACPI_REGISTER_PM1A_CONTROL:	/* 16-bit access */
   4.228 +
   4.229 +		status =
   4.230 +		    acpi_hw_low_level_write(16, value,
   4.231 +					    &acpi_sinfo.pm1a_cnt_blk);
   4.232 +		break;
   4.233 +
   4.234 +	case ACPI_REGISTER_PM1B_CONTROL:	/* 16-bit access */
   4.235 +
   4.236 +		status =
   4.237 +		    acpi_hw_low_level_write(16, value,
   4.238 +					    &acpi_sinfo.pm1b_cnt_blk);
   4.239 +		break;
   4.240 +
   4.241 +
   4.242 +	default:
   4.243 +		status = AE_BAD_PARAMETER;
   4.244 +		break;
   4.245 +	}
   4.246 +
   4.247 +      exit:
   4.248 +
   4.249 +	return_ACPI_STATUS(status);
   4.250 +}
   4.251 +
   4.252 +/******************************************************************************
   4.253 + *
   4.254 + * FUNCTION:    acpi_hw_low_level_read
   4.255 + *
   4.256 + * PARAMETERS:  Width               - 8, 16, or 32
   4.257 + *              Value               - Where the value is returned
   4.258 + *              Reg                 - GAS register structure
   4.259 + *
   4.260 + * RETURN:      Status
   4.261 + *
   4.262 + * DESCRIPTION: Read from either memory or IO space.
   4.263 + *
   4.264 + ******************************************************************************/
   4.265 +
   4.266 +acpi_status
   4.267 +acpi_hw_low_level_read(u32 width, u32 * value, struct acpi_generic_address *reg)
   4.268 +{
   4.269 +	u64 address;
   4.270 +	acpi_status status;
   4.271 +
   4.272 +	ACPI_FUNCTION_NAME(hw_low_level_read);
   4.273 +
   4.274 +	/*
   4.275 +	 * Must have a valid pointer to a GAS structure, and
   4.276 +	 * a non-zero address within. However, don't return an error
   4.277 +	 * because the PM1A/B code must not fail if B isn't present.
   4.278 +	 */
   4.279 +	if (!reg) {
   4.280 +		return (AE_OK);
   4.281 +	}
   4.282 +
   4.283 +	/* Get a local copy of the address. Handles possible alignment issues */
   4.284 +
   4.285 +	ACPI_MOVE_64_TO_64(&address, &reg->address);
   4.286 +	if (!address) {
   4.287 +		return (AE_OK);
   4.288 +	}
   4.289 +	*value = 0;
   4.290 +
   4.291 +	/*
   4.292 +	 * Two address spaces supported: Memory or IO.
   4.293 +	 * PCI_Config is not supported here because the GAS struct is insufficient
   4.294 +	 */
   4.295 +	switch (reg->space_id) {
   4.296 +	case ACPI_ADR_SPACE_SYSTEM_MEMORY:
   4.297 +
   4.298 +		status = acpi_os_read_memory((acpi_physical_address) address,
   4.299 +					     value, width);
   4.300 +		break;
   4.301 +
   4.302 +	case ACPI_ADR_SPACE_SYSTEM_IO:
   4.303 +
   4.304 +		status = acpi_os_read_port((acpi_io_address) address,
   4.305 +					   value, width);
   4.306 +		break;
   4.307 +
   4.308 +	default:
   4.309 +
   4.310 +		return (AE_BAD_PARAMETER);
   4.311 +	}
   4.312 +
   4.313 +	ACPI_DEBUG_PRINT((ACPI_DB_IO,
   4.314 +			  "Read:  %8.8X width %2d from %8.8X%8.8X (%s)\n",
   4.315 +			  *value, width,
   4.316 +			  ACPI_FORMAT_UINT64(address),
   4.317 +			  acpi_ut_get_region_name(reg->address_space_id)));
   4.318 +
   4.319 +	return (status);
   4.320 +}
   4.321 +
   4.322 +/******************************************************************************
   4.323 + *
   4.324 + * FUNCTION:    acpi_hw_low_level_write
   4.325 + *
   4.326 + * PARAMETERS:  Width               - 8, 16, or 32
   4.327 + *              Value               - To be written
   4.328 + *              Reg                 - GAS register structure
   4.329 + *
   4.330 + * RETURN:      Status
   4.331 + *
   4.332 + * DESCRIPTION: Write to either memory or IO space.
   4.333 + *
   4.334 + ******************************************************************************/
   4.335 +
   4.336 +acpi_status
   4.337 +acpi_hw_low_level_write(u32 width, u32 value, struct acpi_generic_address * reg)
   4.338 +{
   4.339 +	u64 address;
   4.340 +	acpi_status status;
   4.341 +
   4.342 +	ACPI_FUNCTION_NAME(hw_low_level_write);
   4.343 +
   4.344 +	/*
   4.345 +	 * Must have a valid pointer to a GAS structure, and
   4.346 +	 * a non-zero address within. However, don't return an error
   4.347 +	 * because the PM1A/B code must not fail if B isn't present.
   4.348 +	 */
   4.349 +	if (!reg) {
   4.350 +		return (AE_OK);
   4.351 +	}
   4.352 +
   4.353 +	/* Get a local copy of the address. Handles possible alignment issues */
   4.354 +
   4.355 +	ACPI_MOVE_64_TO_64(&address, &reg->address);
   4.356 +	if (!address) {
   4.357 +		return (AE_OK);
   4.358 +	}
   4.359 +
   4.360 +	/*
   4.361 +	 * Two address spaces supported: Memory or IO.
   4.362 +	 * PCI_Config is not supported here because the GAS struct is insufficient
   4.363 +	 */
   4.364 +	switch (reg->space_id) {
   4.365 +	case ACPI_ADR_SPACE_SYSTEM_MEMORY:
   4.366 +
   4.367 +		status = acpi_os_write_memory((acpi_physical_address) address,
   4.368 +					      value, width);
   4.369 +		break;
   4.370 +
   4.371 +	case ACPI_ADR_SPACE_SYSTEM_IO:
   4.372 +
   4.373 +		status = acpi_os_write_port((acpi_io_address) address,
   4.374 +					    value, width);
   4.375 +		break;
   4.376 +
   4.377 +	default:
   4.378 +		return (AE_BAD_PARAMETER);
   4.379 +	}
   4.380 +
   4.381 +	ACPI_DEBUG_PRINT((ACPI_DB_IO,
   4.382 +			  "Wrote: %8.8X width %2d   to %8.8X%8.8X (%s)\n",
   4.383 +			  value, width,
   4.384 +			  ACPI_FORMAT_UINT64(address),
   4.385 +			  acpi_ut_get_region_name(reg->address_space_id)));
   4.386 +
   4.387 +	return (status);
   4.388 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/xen/drivers/acpi/osl.c	Wed Mar 19 10:33:13 2008 +0000
     5.3 @@ -0,0 +1,183 @@
     5.4 +/*
     5.5 + *  acpi_osl.c - OS-dependent functions ($Revision: 83 $)
     5.6 + *
     5.7 + *  Copyright (C) 2000       Andrew Henroid
     5.8 + *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
     5.9 + *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
    5.10 + *
    5.11 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    5.12 + *
    5.13 + *  This program is free software; you can redistribute it and/or modify
    5.14 + *  it under the terms of the GNU General Public License as published by
    5.15 + *  the Free Software Foundation; either version 2 of the License, or
    5.16 + *  (at your option) any later version.
    5.17 + *
    5.18 + *  This program is distributed in the hope that it will be useful,
    5.19 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.20 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.21 + *  GNU General Public License for more details.
    5.22 + *
    5.23 + *  You should have received a copy of the GNU General Public License
    5.24 + *  along with this program; if not, write to the Free Software
    5.25 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    5.26 + *
    5.27 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    5.28 + *
    5.29 + */
    5.30 +#include <asm/io.h>
    5.31 +#include <xen/config.h>
    5.32 +#include <xen/init.h>
    5.33 +#include <xen/types.h>
    5.34 +#include <xen/errno.h>
    5.35 +#include <xen/acpi.h>
    5.36 +#include <xen/numa.h>
    5.37 +#include <acpi/acpi_bus.h>
    5.38 +#include <acpi/acmacros.h>
    5.39 +#include <acpi/acpiosxf.h>
    5.40 +#include <acpi/platform/aclinux.h>
    5.41 +#include <xen/spinlock.h>
    5.42 +#include <xen/domain_page.h>
    5.43 +
    5.44 +#define _COMPONENT		ACPI_OS_SERVICES
    5.45 +ACPI_MODULE_NAME("osl")
    5.46 +#define PREFIX		"ACPI: "
    5.47 +struct acpi_os_dpc {
    5.48 +	acpi_osd_exec_callback function;
    5.49 +	void *context;
    5.50 +};
    5.51 +
    5.52 +#ifdef CONFIG_ACPI_CUSTOM_DSDT
    5.53 +#include CONFIG_ACPI_CUSTOM_DSDT_FILE
    5.54 +#endif
    5.55 +
    5.56 +#ifdef ENABLE_DEBUGGER
    5.57 +#include <linux/kdb.h>
    5.58 +
    5.59 +/* stuff for debugger support */
    5.60 +int acpi_in_debugger;
    5.61 +EXPORT_SYMBOL(acpi_in_debugger);
    5.62 +
    5.63 +extern char line_buf[80];
    5.64 +#endif				/*ENABLE_DEBUGGER */
    5.65 +
    5.66 +int acpi_specific_hotkey_enabled = TRUE;
    5.67 +EXPORT_SYMBOL(acpi_specific_hotkey_enabled);
    5.68 +
    5.69 +
    5.70 +acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
    5.71 +{
    5.72 +	u32 dummy;
    5.73 +
    5.74 +	if (!value)
    5.75 +		value = &dummy;
    5.76 +
    5.77 +	*value = 0;
    5.78 +	if (width <= 8) {
    5.79 +		*(u8 *) value = inb(port);
    5.80 +	} else if (width <= 16) {
    5.81 +		*(u16 *) value = inw(port);
    5.82 +	} else if (width <= 32) {
    5.83 +		*(u32 *) value = inl(port);
    5.84 +	} else {
    5.85 +		BUG();
    5.86 +	}
    5.87 +
    5.88 +	return AE_OK;
    5.89 +}
    5.90 +
    5.91 +EXPORT_SYMBOL(acpi_os_read_port);
    5.92 +
    5.93 +acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
    5.94 +{
    5.95 +	if (width <= 8) {
    5.96 +		outb(value, port);
    5.97 +	} else if (width <= 16) {
    5.98 +		outw(value, port);
    5.99 +	} else if (width <= 32) {
   5.100 +		outl(value, port);
   5.101 +	} else {
   5.102 +		BUG();
   5.103 +	}
   5.104 +
   5.105 +	return AE_OK;
   5.106 +}
   5.107 +
   5.108 +EXPORT_SYMBOL(acpi_os_write_port);
   5.109 +
   5.110 +acpi_status
   5.111 +acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
   5.112 +{
   5.113 +	u32 dummy;
   5.114 +	void __iomem *virt_addr;
   5.115 +
   5.116 +	virt_addr = map_domain_page(phys_addr>>PAGE_SHIFT);
   5.117 +	if (!value)
   5.118 +		value = &dummy;
   5.119 +
   5.120 +	switch (width) {
   5.121 +	case 8:
   5.122 +		*(u8 *) value = readb(virt_addr);
   5.123 +		break;
   5.124 +	case 16:
   5.125 +		*(u16 *) value = readw(virt_addr);
   5.126 +		break;
   5.127 +	case 32:
   5.128 +		*(u32 *) value = readl(virt_addr);
   5.129 +		break;
   5.130 +	default:
   5.131 +		BUG();
   5.132 +	}
   5.133 +
   5.134 +	unmap_domain_page(virt_addr);
   5.135 +
   5.136 +	return AE_OK;
   5.137 +}
   5.138 +
   5.139 +acpi_status
   5.140 +acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
   5.141 +{
   5.142 +	void __iomem *virt_addr;
   5.143 +
   5.144 +	virt_addr = map_domain_page(phys_addr>>PAGE_SHIFT);
   5.145 +
   5.146 +	switch (width) {
   5.147 +	case 8:
   5.148 +		writeb(value, virt_addr);
   5.149 +		break;
   5.150 +	case 16:
   5.151 +		writew(value, virt_addr);
   5.152 +		break;
   5.153 +	case 32:
   5.154 +		writel(value, virt_addr);
   5.155 +		break;
   5.156 +	default:
   5.157 +		BUG();
   5.158 +	}
   5.159 +
   5.160 +	unmap_domain_page(virt_addr);
   5.161 +
   5.162 +	return AE_OK;
   5.163 +}
   5.164 +
   5.165 +/*
   5.166 + * Acquire a spinlock.
   5.167 + *
   5.168 + * handle is a pointer to the spinlock_t.
   5.169 + */
   5.170 +
   5.171 +acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
   5.172 +{
   5.173 +	acpi_cpu_flags flags;
   5.174 +	spin_lock_irqsave(lockp, flags);
   5.175 +	return flags;
   5.176 +}
   5.177 +
   5.178 +/*
   5.179 + * Release a spinlock. See above.
   5.180 + */
   5.181 +
   5.182 +void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
   5.183 +{
   5.184 +	spin_unlock_irqrestore(lockp, flags);
   5.185 +}
   5.186 +
     6.1 --- a/xen/include/asm-x86/acpi.h	Wed Mar 19 10:22:49 2008 +0000
     6.2 +++ b/xen/include/asm-x86/acpi.h	Wed Mar 19 10:33:13 2008 +0000
     6.3 @@ -26,6 +26,8 @@
     6.4  
     6.5  #include <xen/config.h>
     6.6  #include <acpi/pdc_intel.h>
     6.7 +#include <acpi/acconfig.h>
     6.8 +#include <acpi/actbl.h>
     6.9  
    6.10  #define COMPILER_DEPENDENT_INT64   long long
    6.11  #define COMPILER_DEPENDENT_UINT64  unsigned long long
    6.12 @@ -146,10 +148,10 @@ extern int acpi_enter_sleep(struct xenpf
    6.13  extern int acpi_enter_state(u32 state);
    6.14  
    6.15  struct acpi_sleep_info {
    6.16 -    uint16_t pm1a_cnt;
    6.17 -    uint16_t pm1b_cnt;
    6.18 -    uint16_t pm1a_evt;
    6.19 -    uint16_t pm1b_evt;
    6.20 +    struct acpi_generic_address pm1a_cnt_blk;
    6.21 +    struct acpi_generic_address pm1b_cnt_blk;
    6.22 +    struct acpi_generic_address pm1a_evt_blk;
    6.23 +    struct acpi_generic_address pm1b_evt_blk;
    6.24      uint16_t pm1a_cnt_val;
    6.25      uint16_t pm1b_cnt_val;
    6.26      uint32_t sleep_state;