ia64/xen-unstable

changeset 19114:b86df1139133

tboot: ACPI Generic Address Structure for tboot shutdown

New versions of tboot support ACPI GAS (Generic Address Structure) for
handling sleep states. This required a change to the tboot_shared_t
data structure that is not backwards compatible. This patch requires
that new version makes use of GAS when invoking tboot on shutdown.

Signed-off-by: Shane Wang <shane.wang@intel.com>
Signed-off-by: Joseph Cihula <joseph.cihula@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jan 29 11:35:19 2009 +0000 (2009-01-29)
parents 1dc576b683c6
children 378a85ff1260
files xen/arch/x86/acpi/power.c xen/arch/x86/tboot.c xen/include/asm-x86/tboot.h
line diff
     1.1 --- a/xen/arch/x86/acpi/power.c	Thu Jan 29 11:32:06 2009 +0000
     1.2 +++ b/xen/arch/x86/acpi/power.c	Thu Jan 29 11:35:19 2009 +0000
     1.3 @@ -129,20 +129,15 @@ static void acpi_sleep_prepare(u32 state
     1.4  
     1.5      wakeup_vector_va = __acpi_map_table(
     1.6          acpi_sinfo.wakeup_vector, sizeof(uint64_t));
     1.7 +
     1.8 +    /* TBoot will set resume vector itself (when it is safe to do so). */
     1.9 +    if ( tboot_in_measured_env() )
    1.10 +        return;
    1.11 +
    1.12      if ( acpi_sinfo.vector_width == 32 )
    1.13 -    {
    1.14 -            *(uint32_t *)wakeup_vector_va =
    1.15 -                tboot_in_measured_env() ?
    1.16 -                (uint32_t)g_tboot_shared->s3_tb_wakeup_entry :
    1.17 -                (uint32_t)bootsym_phys(wakeup_start);
    1.18 -    }
    1.19 +        *(uint32_t *)wakeup_vector_va = bootsym_phys(wakeup_start);
    1.20      else
    1.21 -    {
    1.22 -            *(uint64_t *)wakeup_vector_va =
    1.23 -                tboot_in_measured_env() ?
    1.24 -                (uint64_t)g_tboot_shared->s3_tb_wakeup_entry :
    1.25 -                (uint64_t)bootsym_phys(wakeup_start);
    1.26 -    }
    1.27 +        *(uint64_t *)wakeup_vector_va = bootsym_phys(wakeup_start);
    1.28  }
    1.29  
    1.30  static void acpi_sleep_post(u32 state) {}
    1.31 @@ -279,37 +274,47 @@ static int acpi_get_wake_status(void)
    1.32  
    1.33  static void tboot_sleep(u8 sleep_state)
    1.34  {
    1.35 -   uint32_t shutdown_type;
    1.36 +    uint32_t shutdown_type;
    1.37  
    1.38 -   g_tboot_shared->acpi_sinfo.pm1a_cnt =
    1.39 -                           (uint16_t)acpi_sinfo.pm1a_cnt_blk.address;
    1.40 -   g_tboot_shared->acpi_sinfo.pm1b_cnt =
    1.41 -                           (uint16_t)acpi_sinfo.pm1b_cnt_blk.address;
    1.42 -   g_tboot_shared->acpi_sinfo.pm1a_evt =
    1.43 -                           (uint16_t)acpi_sinfo.pm1a_evt_blk.address;
    1.44 -   g_tboot_shared->acpi_sinfo.pm1b_evt =
    1.45 -                           (uint16_t)acpi_sinfo.pm1b_evt_blk.address;
    1.46 -   g_tboot_shared->acpi_sinfo.pm1a_cnt_val = acpi_sinfo.pm1a_cnt_val;
    1.47 -   g_tboot_shared->acpi_sinfo.pm1b_cnt_val = acpi_sinfo.pm1b_cnt_val;
    1.48 +#define TB_COPY_GAS(tbg, g)             \
    1.49 +    tbg.space_id = g.space_id;          \
    1.50 +    tbg.bit_width = g.bit_width;        \
    1.51 +    tbg.bit_offset = g.bit_offset;      \
    1.52 +    tbg.access_width = g.access_width;  \
    1.53 +    tbg.address = g.address;
    1.54  
    1.55 -   switch ( sleep_state )
    1.56 -   {
    1.57 -       case ACPI_STATE_S3:
    1.58 -           shutdown_type = TB_SHUTDOWN_S3;
    1.59 -           g_tboot_shared->s3_k_wakeup_entry =
    1.60 -               (uint32_t)bootsym_phys(wakeup_start);
    1.61 -           break;
    1.62 -       case ACPI_STATE_S4:
    1.63 -           shutdown_type = TB_SHUTDOWN_S4;
    1.64 -           break;
    1.65 -       case ACPI_STATE_S5:
    1.66 -           shutdown_type = TB_SHUTDOWN_S5;
    1.67 -           break;
    1.68 -       default:
    1.69 -           return;
    1.70 -   }
    1.71 +    /* sizes are not same (due to packing) so copy each one */
    1.72 +    TB_COPY_GAS(g_tboot_shared->acpi_sinfo.pm1a_cnt_blk,
    1.73 +                acpi_sinfo.pm1a_cnt_blk);
    1.74 +    TB_COPY_GAS(g_tboot_shared->acpi_sinfo.pm1b_cnt_blk,
    1.75 +                acpi_sinfo.pm1b_cnt_blk);
    1.76 +    TB_COPY_GAS(g_tboot_shared->acpi_sinfo.pm1a_evt_blk,
    1.77 +                acpi_sinfo.pm1a_evt_blk);
    1.78 +    TB_COPY_GAS(g_tboot_shared->acpi_sinfo.pm1b_evt_blk,
    1.79 +                acpi_sinfo.pm1b_evt_blk);
    1.80 +    g_tboot_shared->acpi_sinfo.pm1a_cnt_val = acpi_sinfo.pm1a_cnt_val;
    1.81 +    g_tboot_shared->acpi_sinfo.pm1b_cnt_val = acpi_sinfo.pm1b_cnt_val;
    1.82 +    g_tboot_shared->acpi_sinfo.wakeup_vector = acpi_sinfo.wakeup_vector;
    1.83 +    g_tboot_shared->acpi_sinfo.vector_width = acpi_sinfo.vector_width;
    1.84 +    g_tboot_shared->acpi_sinfo.kernel_s3_resume_vector =
    1.85 +                                              bootsym_phys(wakeup_start);
    1.86  
    1.87 -   tboot_shutdown(shutdown_type);
    1.88 +    switch ( sleep_state )
    1.89 +    {
    1.90 +        case ACPI_STATE_S3:
    1.91 +            shutdown_type = TB_SHUTDOWN_S3;
    1.92 +            break;
    1.93 +        case ACPI_STATE_S4:
    1.94 +            shutdown_type = TB_SHUTDOWN_S4;
    1.95 +            break;
    1.96 +        case ACPI_STATE_S5:
    1.97 +            shutdown_type = TB_SHUTDOWN_S5;
    1.98 +            break;
    1.99 +        default:
   1.100 +            return;
   1.101 +    }
   1.102 +
   1.103 +    tboot_shutdown(shutdown_type);
   1.104  }
   1.105           
   1.106  /* System is really put into sleep state by this stub */
     2.1 --- a/xen/arch/x86/tboot.c	Thu Jan 29 11:32:06 2009 +0000
     2.2 +++ b/xen/arch/x86/tboot.c	Thu Jan 29 11:35:19 2009 +0000
     2.3 @@ -30,23 +30,24 @@ void __init tboot_probe(void)
     2.4      /* Map and check for tboot UUID. */
     2.5      set_fixmap(FIX_TBOOT_SHARED_BASE, p_tboot_shared);
     2.6      tboot_shared = (tboot_shared_t *)fix_to_virt(FIX_TBOOT_SHARED_BASE);
     2.7 +    if ( tboot_shared == NULL )
     2.8 +        return;
     2.9      if ( memcmp(&tboot_shared_uuid, (uuid_t *)tboot_shared, sizeof(uuid_t)) )
    2.10          return;
    2.11  
    2.12 +    /* new tboot_shared (w/ GAS support) is not backwards compatible */
    2.13 +    if ( tboot_shared->version < 3 ) {
    2.14 +        printk("unsupported version of tboot (%u)\n", tboot_shared->version);
    2.15 +        return;
    2.16 +    }
    2.17 +
    2.18      g_tboot_shared = tboot_shared;
    2.19      printk("TBOOT: found shared page at phys addr %lx:\n", p_tboot_shared);
    2.20      printk("  version: %d\n", tboot_shared->version);
    2.21      printk("  log_addr: 0x%08x\n", tboot_shared->log_addr);
    2.22      printk("  shutdown_entry: 0x%08x\n", tboot_shared->shutdown_entry);
    2.23 -    printk("  shutdown_type: %d\n", tboot_shared->shutdown_type);
    2.24 -    printk("  s3_tb_wakeup_entry: 0x%08x\n", tboot_shared->s3_tb_wakeup_entry);
    2.25 -    printk("  s3_k_wakeup_entry: 0x%08x\n", tboot_shared->s3_k_wakeup_entry);
    2.26 -    printk("  &acpi_sinfo: 0x%p\n", &tboot_shared->acpi_sinfo);
    2.27 -    if ( tboot_shared->version >= 0x02 )
    2.28 -    {
    2.29 -        printk("  tboot_base: 0x%08x\n", tboot_shared->tboot_base);
    2.30 -        printk("  tboot_size: 0x%x\n", tboot_shared->tboot_size);
    2.31 -    }
    2.32 +    printk("  tboot_base: 0x%08x\n", tboot_shared->tboot_base);
    2.33 +    printk("  tboot_size: 0x%x\n", tboot_shared->tboot_size);
    2.34  }
    2.35  
    2.36  void tboot_shutdown(uint32_t shutdown_type)
    2.37 @@ -59,16 +60,8 @@ void tboot_shutdown(uint32_t shutdown_ty
    2.38      local_irq_disable();
    2.39  
    2.40      /* Create identity map for tboot shutdown code. */
    2.41 -    if ( g_tboot_shared->version >= 0x02 )
    2.42 -    {
    2.43 -        map_base = PFN_DOWN(g_tboot_shared->tboot_base);
    2.44 -        map_size = PFN_UP(g_tboot_shared->tboot_size);
    2.45 -    }
    2.46 -    else
    2.47 -    {
    2.48 -        map_base = 0;
    2.49 -        map_size = PFN_UP(0xa0000);
    2.50 -    }
    2.51 +    map_base = PFN_DOWN(g_tboot_shared->tboot_base);
    2.52 +    map_size = PFN_UP(g_tboot_shared->tboot_size);
    2.53  
    2.54      err = map_pages_to_xen(map_base << PAGE_SHIFT, map_base, map_size,
    2.55                             __PAGE_HYPERVISOR);
     3.1 --- a/xen/include/asm-x86/tboot.h	Thu Jan 29 11:32:06 2009 +0000
     3.2 +++ b/xen/include/asm-x86/tboot.h	Thu Jan 29 11:35:19 2009 +0000
     3.3 @@ -37,7 +37,11 @@
     3.4  #ifndef __TBOOT_H__
     3.5  #define __TBOOT_H__
     3.6  
     3.7 -typedef struct __attribute__ ((__packed__)) {
     3.8 +#ifndef __packed
     3.9 +#define __packed   __attribute__ ((packed))
    3.10 +#endif
    3.11 +
    3.12 +typedef struct __packed {
    3.13    uint32_t    data1;
    3.14    uint16_t    data2;
    3.15    uint16_t    data3;
    3.16 @@ -47,28 +51,36 @@ typedef struct __attribute__ ((__packed_
    3.17  
    3.18  /* used to communicate between tboot and the launched kernel (i.e. Xen) */
    3.19  
    3.20 -typedef struct __attribute__ ((__packed__)) {
    3.21 -    uint16_t pm1a_cnt;
    3.22 -    uint16_t pm1b_cnt;
    3.23 -    uint16_t pm1a_evt;
    3.24 -    uint16_t pm1b_evt;
    3.25 +/* GAS - Generic Address Structure (ACPI 2.0+) */
    3.26 +typedef struct __packed {
    3.27 +	uint8_t  space_id;
    3.28 +	uint8_t  bit_width;
    3.29 +	uint8_t  bit_offset;
    3.30 +	uint8_t  access_width;
    3.31 +	uint64_t address;
    3.32 +} tboot_acpi_generic_address_t;
    3.33 +
    3.34 +typedef struct __packed {
    3.35 +    tboot_acpi_generic_address_t pm1a_cnt_blk;
    3.36 +    tboot_acpi_generic_address_t pm1b_cnt_blk;
    3.37 +    tboot_acpi_generic_address_t pm1a_evt_blk;
    3.38 +    tboot_acpi_generic_address_t pm1b_evt_blk;
    3.39      uint16_t pm1a_cnt_val;
    3.40      uint16_t pm1b_cnt_val;
    3.41 -} tboot_acpi_sleep_info;
    3.42 +    uint64_t wakeup_vector;
    3.43 +    uint32_t vector_width;
    3.44 +    uint64_t kernel_s3_resume_vector;
    3.45 +} tboot_acpi_sleep_info_t;
    3.46  
    3.47 -typedef struct __attribute__ ((__packed__)) {
    3.48 -    /* version 0x01+ fields: */
    3.49 +typedef struct __packed {
    3.50 +    /* version 3+ fields: */
    3.51      uuid_t    uuid;              /* {663C8DFF-E8B3-4b82-AABF-19EA4D057A08} */
    3.52 -    uint32_t  version;           /* Version number: 0x01, 0x02, ... */
    3.53 +    uint32_t  version;           /* Version number; currently supports 0.3 */
    3.54      uint32_t  log_addr;          /* physical addr of tb_log_t log */
    3.55      uint32_t  shutdown_entry;    /* entry point for tboot shutdown */
    3.56      uint32_t  shutdown_type;     /* type of shutdown (TB_SHUTDOWN_*) */
    3.57 -    uint32_t  s3_tb_wakeup_entry;/* entry point for tboot s3 wake up */
    3.58 -    uint32_t  s3_k_wakeup_entry; /* entry point for xen s3 wake up */
    3.59 -    tboot_acpi_sleep_info
    3.60 +    tboot_acpi_sleep_info_t
    3.61                acpi_sinfo;        /* where kernel put acpi sleep info in Sx */
    3.62 -    uint8_t   reserved[52];      /* this pad is for compat with old field */
    3.63 -    /* version 0x02+ fields: */
    3.64      uint32_t  tboot_base;        /* starting addr for tboot */
    3.65      uint32_t  tboot_size;        /* size of tboot */
    3.66  } tboot_shared_t;