ia64/xen-unstable
changeset 18192:979e098dfb92
rombios: Obtain S3 wake vector from >1MB.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Tue Jul 29 16:03:58 2008 +0100 (2008-07-29) |
parents | a538185695ed |
children | 39cb0de3ee2f |
files | tools/firmware/rombios/32bit/32bitbios.c tools/firmware/rombios/32bit/tcgbios/tcgbios.c tools/firmware/rombios/32bit/tcgbios/tcgbios.h tools/firmware/rombios/32bit/util.c tools/firmware/rombios/32bit/util.h tools/firmware/rombios/32bitgateway.c tools/firmware/rombios/32bitprotos.h tools/firmware/rombios/rombios.c |
line diff
1.1 --- a/tools/firmware/rombios/32bit/32bitbios.c Tue Jul 29 15:10:58 2008 +0100 1.2 +++ b/tools/firmware/rombios/32bit/32bitbios.c Tue Jul 29 16:03:58 2008 +0100 1.3 @@ -47,5 +47,7 @@ uint32_t jumptable[IDX_LAST+1] __attribu 1.4 1.5 TABLE_ENTRY(IDX_TCPA_INITIALIZE_TPM, tcpa_initialize_tpm), 1.6 1.7 + TABLE_ENTRY(IDX_GET_S3_WAKING_VECTOR, get_s3_waking_vector), 1.8 + 1.9 TABLE_ENTRY(IDX_LAST , 0) /* keep last */ 1.10 };
2.1 --- a/tools/firmware/rombios/32bit/tcgbios/tcgbios.c Tue Jul 29 15:10:58 2008 +0100 2.2 +++ b/tools/firmware/rombios/32bit/tcgbios/tcgbios.c Tue Jul 29 16:03:58 2008 +0100 2.3 @@ -24,10 +24,9 @@ 2.4 #include "rombios_compat.h" 2.5 #include "tpm_drivers.h" 2.6 2.7 +#include "util.h" 2.8 #include "tcgbios.h" 2.9 #include "32bitprotos.h" 2.10 -#include "util.h" 2.11 - 2.12 2.13 /* local structure and variables */ 2.14 struct ptti_cust { 2.15 @@ -135,7 +134,7 @@ static inline uint32_t bswap(uint32_t a) 2.16 *******************************************************/ 2.17 2.18 typedef struct { 2.19 - struct acpi_20_tcpa *tcpa_ptr; 2.20 + struct acpi_20_tcpa_clisrv *tcpa_ptr; 2.21 unsigned char *lasa_last_ptr; 2.22 uint16_t entry_count; 2.23 uint16_t flags; 2.24 @@ -260,45 +259,19 @@ uint8_t acpi_validate_entry(struct acpi_ 2.25 } 2.26 2.27 2.28 -/* 2.29 - * Search for the RSDP ACPI table in the memory starting at addr and 2.30 - * ending at addr + len - 1. 2.31 - */ 2.32 -static struct acpi_20_rsdp *find_rsdp(const void *start, unsigned int len) 2.33 -{ 2.34 - char *rsdp = (char *)start; 2.35 - char *end = rsdp + len; 2.36 - /* scan memory in steps of 16 bytes */ 2.37 - while (rsdp < end) { 2.38 - /* check for expected string */ 2.39 - if (!strncmp( rsdp, "RSD PTR ", 8)) 2.40 - return (struct acpi_20_rsdp *)rsdp; 2.41 - rsdp += 0x10; 2.42 - } 2.43 - return 0; 2.44 -} 2.45 - 2.46 void tcpa_acpi_init(void) 2.47 { 2.48 struct acpi_20_rsdt *rsdt; 2.49 - struct acpi_20_tcpa *tcpa = (void *)0; 2.50 + struct acpi_20_tcpa_clisrv *tcpa = (void *)0; 2.51 struct acpi_20_rsdp *rsdp; 2.52 uint32_t length; 2.53 uint16_t off; 2.54 int found = 0; 2.55 - uint16_t ebda_seg; 2.56 - 2.57 - if (MA_IsTPMPresent() == 0) { 2.58 - return; 2.59 - } 2.60 2.61 - /* RSDP in EBDA? */ 2.62 - ebda_seg = *(uint16_t *)ADDR_FROM_SEG_OFF(0x40, 0xe); 2.63 - rsdp = find_rsdp((void *)(ebda_seg << 16), 1024); 2.64 + if (MA_IsTPMPresent() == 0) 2.65 + return; 2.66 2.67 - if (!rsdp) 2.68 - rsdp = find_rsdp((void *)(ACPI_SEGMENT << 4), 0x20000); 2.69 - 2.70 + rsdp = find_rsdp(); 2.71 if (rsdp) { 2.72 uint32_t ctr = 0; 2.73 /* get RSDT from RSDP */ 2.74 @@ -307,7 +280,7 @@ void tcpa_acpi_init(void) 2.75 off = 36; 2.76 while ((off + 3) < length) { 2.77 /* try all pointers to structures */ 2.78 - tcpa = (struct acpi_20_tcpa *)rsdt->entry[ctr]; 2.79 + tcpa = (struct acpi_20_tcpa_clisrv *)rsdt->entry[ctr]; 2.80 /* valid TCPA ACPI table ? */ 2.81 if (ACPI_2_0_TCPA_SIGNATURE == tcpa->header.signature 2.82 && acpi_validate_entry(&tcpa->header) == 0) { 2.83 @@ -398,7 +371,7 @@ static 2.84 unsigned char *tcpa_get_lasa_base_ptr(void) 2.85 { 2.86 unsigned char *lasa = 0; 2.87 - struct acpi_20_tcpa *tcpa = tcpa_acpi.tcpa_ptr; 2.88 + struct acpi_20_tcpa_clisrv *tcpa = tcpa_acpi.tcpa_ptr; 2.89 if (tcpa != 0) { 2.90 uint32_t class = tcpa->platform_class; 2.91 if (class == TCPA_ACPI_CLASS_CLIENT) { 2.92 @@ -416,7 +389,7 @@ static 2.93 uint32_t tcpa_get_laml(void) 2.94 { 2.95 uint32_t laml = 0; 2.96 - struct acpi_20_tcpa *tcpa = tcpa_acpi.tcpa_ptr; 2.97 + struct acpi_20_tcpa_clisrv *tcpa = tcpa_acpi.tcpa_ptr; 2.98 if (tcpa != 0) { 2.99 uint32_t class = tcpa->platform_class; 2.100 if (class == TCPA_ACPI_CLASS_CLIENT) {
3.1 --- a/tools/firmware/rombios/32bit/tcgbios/tcgbios.h Tue Jul 29 15:10:58 2008 +0100 3.2 +++ b/tools/firmware/rombios/32bit/tcgbios/tcgbios.h Tue Jul 29 16:03:58 2008 +0100 3.3 @@ -1,7 +1,6 @@ 3.4 #ifndef TCGBIOS_H 3.5 #define TCGBIOS_H 3.6 3.7 - 3.8 /* TCPA ACPI definitions */ 3.9 #define TCPA_ACPI_CLASS_CLIENT 0 3.10 #define TCPA_ACPI_CLASS_SERVER 1 3.11 @@ -117,15 +116,8 @@ 3.12 /* address of locality 0 (TIS) */ 3.13 #define TPM_TIS_BASE_ADDRESS 0xfed40000 3.14 3.15 -#define ASCII32(a,b,c,d) ((((Bit32u)a) << 0) | (((Bit32u)b) << 8) | \ 3.16 - (((Bit32u)c) << 16) | (((Bit32u)d) << 24) ) 3.17 -#define ACPI_2_0_TCPA_SIGNATURE ASCII32('T','C','P','A') /* "TCPA" */ 3.18 - 3.19 - 3.20 #define STATUS_FLAG_SHUTDOWN (1 << 0) 3.21 3.22 -#define ACPI_SEGMENT 0xE000 3.23 - 3.24 /* Input and Output blocks for the TCG BIOS commands */ 3.25 3.26 struct hleei_short 3.27 @@ -232,37 +224,6 @@ struct pcpes 3.28 uint32_t event; 3.29 } __attribute__((packed)); 3.30 3.31 - 3.32 -struct acpi_header 3.33 -{ 3.34 - uint32_t signature; 3.35 - uint32_t length; 3.36 - uint8_t revision; 3.37 - uint8_t checksum; 3.38 - uint8_t oem_id[6]; 3.39 - uint64_t oem_table_id; 3.40 - uint32_t oem_revision; 3.41 - uint32_t creator_id; 3.42 - uint32_t creator_revision; 3.43 -} __attribute__((packed)); 3.44 - 3.45 -struct acpi_20_rsdt { 3.46 - struct acpi_header header; 3.47 - uint32_t entry[1]; 3.48 -} __attribute__((packed)); 3.49 - 3.50 -struct acpi_20_rsdp { 3.51 - uint64_t signature; 3.52 - uint8_t checksum; 3.53 - uint8_t oem_id[6]; 3.54 - uint8_t revision; 3.55 - uint32_t rsdt_address; 3.56 - uint32_t length; 3.57 - uint64_t xsdt_address; 3.58 - uint8_t extended_checksum; 3.59 - uint8_t reserved[3]; 3.60 -} __attribute__((packed)); 3.61 - 3.62 struct acpi_20_tcpa_client { 3.63 uint32_t laml; 3.64 uint64_t lasa; 3.65 @@ -275,7 +236,7 @@ struct acpi_20_tcpa_server { 3.66 /* more here */ 3.67 } __attribute__((packed)); 3.68 3.69 -struct acpi_20_tcpa { 3.70 +struct acpi_20_tcpa_clisrv { 3.71 struct acpi_header header; 3.72 uint16_t platform_class; 3.73 union {
4.1 --- a/tools/firmware/rombios/32bit/util.c Tue Jul 29 15:10:58 2008 +0100 4.2 +++ b/tools/firmware/rombios/32bit/util.c Tue Jul 29 16:03:58 2008 +0100 4.3 @@ -19,6 +19,7 @@ 4.4 */ 4.5 #include <stdarg.h> 4.6 #include <stdint.h> 4.7 +#include "rombios_compat.h" 4.8 #include "util.h" 4.9 4.10 static void putchar(char c); 4.11 @@ -92,11 +93,11 @@ int strcmp(const char *cs, const char *c 4.12 4.13 int strncmp(const char *s1, const char *s2, uint32_t n) 4.14 { 4.15 - uint32_t ctr; 4.16 - for (ctr = 0; ctr < n; ctr++) 4.17 - if (s1[ctr] != s2[ctr]) 4.18 - return (int)(s1[ctr] - s2[ctr]); 4.19 - return 0; 4.20 + uint32_t ctr; 4.21 + for (ctr = 0; ctr < n; ctr++) 4.22 + if (s1[ctr] != s2[ctr]) 4.23 + return (int)(s1[ctr] - s2[ctr]); 4.24 + return 0; 4.25 } 4.26 4.27 void *memcpy(void *dest, const void *src, unsigned n) 4.28 @@ -402,3 +403,64 @@ void mssleep(uint32_t waittime) 4.29 y = x; 4.30 } 4.31 } 4.32 + 4.33 +/* 4.34 + * Search for the RSDP ACPI table in the memory starting at addr and 4.35 + * ending at addr + len - 1. 4.36 + */ 4.37 +static struct acpi_20_rsdp *__find_rsdp(const void *start, unsigned int len) 4.38 +{ 4.39 + char *rsdp = (char *)start; 4.40 + char *end = rsdp + len; 4.41 + /* scan memory in steps of 16 bytes */ 4.42 + while (rsdp < end) { 4.43 + /* check for expected string */ 4.44 + if (!strncmp(rsdp, "RSD PTR ", 8)) 4.45 + return (struct acpi_20_rsdp *)rsdp; 4.46 + rsdp += 0x10; 4.47 + } 4.48 + return 0; 4.49 +} 4.50 + 4.51 +struct acpi_20_rsdp *find_rsdp(void) 4.52 +{ 4.53 + struct acpi_20_rsdp *rsdp; 4.54 + uint16_t ebda_seg; 4.55 + 4.56 + ebda_seg = *(uint16_t *)ADDR_FROM_SEG_OFF(0x40, 0xe); 4.57 + rsdp = __find_rsdp((void *)(ebda_seg << 16), 1024); 4.58 + if (!rsdp) 4.59 + rsdp = __find_rsdp((void *)0xE0000, 0x20000); 4.60 + 4.61 + return rsdp; 4.62 +} 4.63 + 4.64 +uint32_t get_s3_waking_vector(void) 4.65 +{ 4.66 + struct acpi_20_rsdp *rsdp = find_rsdp(); 4.67 + struct acpi_20_xsdt *xsdt; 4.68 + struct acpi_20_fadt *fadt; 4.69 + struct acpi_20_facs *facs; 4.70 + uint32_t vector; 4.71 + 4.72 + if (!rsdp) 4.73 + return 0; 4.74 + 4.75 + xsdt = (struct acpi_20_xsdt *)(long)rsdp->xsdt_address; 4.76 + if (!xsdt) 4.77 + return 0; 4.78 + 4.79 + fadt = (struct acpi_20_fadt *)(long)xsdt->entry[0]; 4.80 + if (!fadt || (fadt->header.signature != ACPI_2_0_FADT_SIGNATURE)) 4.81 + return 0; 4.82 + 4.83 + facs = (struct acpi_20_facs *)(long)fadt->x_firmware_ctrl; 4.84 + if (!facs) 4.85 + return 0; 4.86 + 4.87 + vector = facs->x_firmware_waking_vector; 4.88 + if (!vector) 4.89 + vector = facs->firmware_waking_vector; 4.90 + 4.91 + return vector; 4.92 +}
5.1 --- a/tools/firmware/rombios/32bit/util.h Tue Jul 29 15:10:58 2008 +0100 5.2 +++ b/tools/firmware/rombios/32bit/util.h Tue Jul 29 16:03:58 2008 +0100 5.3 @@ -1,6 +1,8 @@ 5.4 #ifndef UTIL_H 5.5 #define UTIL_H 5.6 5.7 +#include "../hvmloader/acpi/acpi2_0.h" 5.8 + 5.9 void outb(uint16_t addr, uint8_t val); 5.10 void outw(uint16_t addr, uint16_t val); 5.11 void outl(uint16_t addr, uint32_t val); 5.12 @@ -39,5 +41,6 @@ static inline uint32_t mmio_readl(uint32 5.13 return *(volatile uint32_t *)addr; 5.14 } 5.15 5.16 +struct acpi_20_rsdp *find_rsdp(void); 5.17 5.18 #endif
6.1 --- a/tools/firmware/rombios/32bitgateway.c Tue Jul 29 15:10:58 2008 +0100 6.2 +++ b/tools/firmware/rombios/32bitgateway.c Tue Jul 29 16:03:58 2008 +0100 6.3 @@ -356,6 +356,9 @@ Upcall: 6.4 call _store_returnaddress ; store away 6.5 pop ax 6.6 6.7 + ; XXX GDT munging requires ROM to be writable! 6.8 + call _enable_rom_write_access 6.9 + 6.10 rol bx, #2 6.11 mov si, #jmptable 6.12 seg cs 6.13 @@ -382,6 +385,8 @@ Upcall: 6.14 mov bp,sp 6.15 push eax ; preserve work register 6.16 6.17 + call _disable_rom_write_access 6.18 + 6.19 call _get_returnaddress 6.20 mov 2[bp], ax ; 16bit return address onto stack 6.21 6.22 @@ -408,3 +413,10 @@ ASM_END 6.23 #include "32bitgateway.h" 6.24 6.25 #include "tcgbios.c" 6.26 + 6.27 +Bit32u get_s3_waking_vector() 6.28 +{ 6.29 + ASM_START 6.30 + DoUpcall(IDX_GET_S3_WAKING_VECTOR) 6.31 + ASM_END 6.32 +}
7.1 --- a/tools/firmware/rombios/32bitprotos.h Tue Jul 29 15:10:58 2008 +0100 7.2 +++ b/tools/firmware/rombios/32bitprotos.h Tue Jul 29 16:03:58 2008 +0100 7.3 @@ -17,8 +17,8 @@ 7.4 #define IDX_TCPA_IPL 10 7.5 #define IDX_TCPA_INITIALIZE_TPM 11 7.6 #define IDX_TCPA_MEASURE_POST 12 7.7 - 7.8 -#define IDX_LAST 13 /* keep last! */ 7.9 +#define IDX_GET_S3_WAKING_VECTOR 13 7.10 +#define IDX_LAST 14 /* keep last! */ 7.11 7.12 #ifdef GCC_PROTOS 7.13 #define PARMS(x...) x 7.14 @@ -42,4 +42,6 @@ void tcpa_ipl( PARMS(Bit32u bootcd,Bit32 7.15 void tcpa_measure_post( PARMS(Bit32u from, Bit32u to) ); 7.16 Bit32u tcpa_initialize_tpm( PARMS(Bit32u physpres) ); 7.17 7.18 +Bit32u get_s3_waking_vector( PARMS(void) ); 7.19 + 7.20 #endif
8.1 --- a/tools/firmware/rombios/rombios.c Tue Jul 29 15:10:58 2008 +0100 8.2 +++ b/tools/firmware/rombios/rombios.c Tue Jul 29 16:03:58 2008 +0100 8.3 @@ -1482,6 +1482,16 @@ ASM_START 8.4 out dx,al 8.5 ASM_END 8.6 } 8.7 + 8.8 +void enable_rom_write_access() 8.9 +{ 8.10 + set_rom_write_access(0); 8.11 +} 8.12 + 8.13 +void disable_rom_write_access() 8.14 +{ 8.15 + set_rom_write_access(PFFLAG_ROM_LOCK); 8.16 +} 8.17 8.18 #endif /* HVMASSIST */ 8.19 8.20 @@ -2378,14 +2388,9 @@ ASM_END 8.21 if (s3_resume_flag != CMOS_SHUTDOWN_S3) 8.22 return; 8.23 8.24 - /* get x_firmware_waking_vector */ 8.25 - s3_wakeup_vector = facs_get32(ACPI_FACS_OFFSET+24); 8.26 - if (!s3_wakeup_vector) { 8.27 - /* get firmware_waking_vector */ 8.28 - s3_wakeup_vector = facs_get32(ACPI_FACS_OFFSET+12); 8.29 - if (!s3_wakeup_vector) 8.30 - return; 8.31 - } 8.32 + s3_wakeup_vector = get_s3_waking_vector(); 8.33 + if (!s3_wakeup_vector) 8.34 + return; 8.35 8.36 s3_wakeup_ip = s3_wakeup_vector & 0xF; 8.37 s3_wakeup_cs = s3_wakeup_vector >> 4; 8.38 @@ -9927,9 +9932,7 @@ normal_post: 8.39 call _log_bios_start 8.40 8.41 #ifdef HVMASSIST 8.42 - push #0 8.43 - call _set_rom_write_access 8.44 - add sp,#2 8.45 + call _enable_rom_write_access 8.46 #endif 8.47 8.48 call _clobber_entry_point 8.49 @@ -10128,9 +10131,7 @@ post_default_ints: 8.50 #ifdef HVMASSIST 8.51 call _copy_e820_table 8.52 call smbios_init 8.53 - push #PFFLAG_ROM_LOCK 8.54 - call _set_rom_write_access 8.55 - add sp,#2 8.56 + call _disable_rom_write_access 8.57 #endif 8.58 8.59 call _init_boot_vectors