ia64/xen-unstable

changeset 13855:e212203d7d34

[TPM] Set tcpa calls in the rombios and other fixes.

This patch places some tcpa calls into the rombios that had previously
not applied anymore or were not set.
Force the reads from MMIO memory locations that the compiler otherwise
optimizes away (-O2) if there was an immediate write to the same
memory location before.
Use #define'd constants wherever possible.
Fix all remaining compiler warnings.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author kfraser@localhost.localdomain
date Tue Feb 06 23:01:35 2007 +0000 (2007-02-06)
parents 3093bd26ae45
children 7379c1174155
files tools/firmware/rombios/32bit/tcgbios/tcgbios.c tools/firmware/rombios/32bit/tcgbios/tpm_drivers.c tools/firmware/rombios/32bit/util.h tools/firmware/rombios/rombios.c
line diff
     1.1 --- a/tools/firmware/rombios/32bit/tcgbios/tcgbios.c	Tue Feb 06 22:59:35 2007 +0000
     1.2 +++ b/tools/firmware/rombios/32bit/tcgbios/tcgbios.c	Tue Feb 06 23:01:35 2007 +0000
     1.3 @@ -146,7 +146,7 @@ static tcpa_acpi_t tcpa_acpi;
     1.4  static int tpm_driver_to_use = TPM_INVALID_DRIVER;
     1.5  
     1.6  static
     1.7 -uint32_t MA_IsTPMPresent()
     1.8 +uint32_t MA_IsTPMPresent(void)
     1.9  {
    1.10  	uint32_t rc = 0;
    1.11  	unsigned int i;
    1.12 @@ -263,11 +263,11 @@ void tcpa_acpi_init(void)
    1.13  {
    1.14  	struct acpi_20_rsdt *rsdt;
    1.15  	uint32_t length;
    1.16 -	struct acpi_20_tcpa *tcpa;
    1.17 +	struct acpi_20_tcpa *tcpa = (void *)0;
    1.18  	uint16_t found = 0;
    1.19  	uint16_t rsdp_off;
    1.20  	uint16_t off;
    1.21 -	struct acpi_20_rsdp *rsdp;
    1.22 +	struct acpi_20_rsdp *rsdp = (void *)0;
    1.23  
    1.24  	if (MA_IsTPMPresent() == 0) {
    1.25  		return;
    1.26 @@ -732,8 +732,8 @@ void tcpa_ipl(Bit32u seg)
    1.27  void tcpa_measure_post(Bit32u from, Bit32u to)
    1.28  {
    1.29  	struct pcpes pcpes; /* PCClientPCREventStruc */
    1.30 +	int len = to - from;
    1.31  	memset(&pcpes, 0x0, sizeof(pcpes));
    1.32 -	int len = to - from;
    1.33  
    1.34  	if (len > 0) {
    1.35  		sha1((unsigned char *)from,
    1.36 @@ -986,7 +986,7 @@ uint32_t PassThroughToTPM32(struct pttti
    1.37  {
    1.38  	uint32_t rc = 0;
    1.39  	uint8_t *cmd32;
    1.40 -	uint32_t resbuflen;
    1.41 +	uint32_t resbuflen = 0;
    1.42  
    1.43  	if (TCG_IsShutdownPreBootInterface() != 0) {
    1.44  		rc = (TCG_PC_TPMERROR |
    1.45 @@ -1277,9 +1277,7 @@ typedef struct _sha1_ctx {
    1.46  } sha1_ctx;
    1.47  
    1.48  
    1.49 -static inline uint32_t rol(val, rol)
    1.50 -  uint32_t val;
    1.51 -  uint16_t rol;
    1.52 +static inline uint32_t rol(uint32_t val, uint16_t rol)
    1.53  {
    1.54  	return (val << rol) | (val >> (32 - rol));
    1.55  }
     2.1 --- a/tools/firmware/rombios/32bit/tcgbios/tpm_drivers.c	Tue Feb 06 22:59:35 2007 +0000
     2.2 +++ b/tools/firmware/rombios/32bit/tcgbios/tpm_drivers.c	Tue Feb 06 23:01:35 2007 +0000
     2.3 @@ -27,12 +27,27 @@
     2.4  #include "tpm_drivers.h"
     2.5  #include "tcgbios.h"
     2.6  
     2.7 +#define STS_VALID                    (1 << 7) /* 0x80 */
     2.8 +#define STS_COMMAND_READY            (1 << 6) /* 0x40 */
     2.9 +#define STS_TPM_GO                   (1 << 5) /* 0x20 */
    2.10 +#define STS_DATA_AVAILABLE           (1 << 4) /* 0x10 */
    2.11 +#define STS_EXPECT                   (1 << 3) /* 0x08 */
    2.12 +#define STS_RESPONSE_RETRY           (1 << 1) /* 0x02 */
    2.13 +
    2.14 +#define ACCESS_TPM_REG_VALID_STS     (1 << 7) /* 0x80 */
    2.15 +#define ACCESS_ACTIVE_LOCALITY       (1 << 5) /* 0x20 */
    2.16 +#define ACCESS_BEEN_SEIZED           (1 << 4) /* 0x10 */
    2.17 +#define ACCESS_SEIZE                 (1 << 3) /* 0x08 */
    2.18 +#define ACCESS_PENDING_REQUEST       (1 << 2) /* 0x04 */
    2.19 +#define ACCESS_REQUEST_USE           (1 << 1) /* 0x02 */
    2.20 +#define ACCESS_TPM_ESTABLISHMENT     (1 << 0) /* 0x01 */
    2.21 +
    2.22  static uint32_t tis_wait_sts(uint8_t *addr, uint32_t time,
    2.23                               uint8_t mask, uint8_t expect)
    2.24  {
    2.25  	uint32_t rc = 0;
    2.26  	while (time > 0) {
    2.27 -		uint8_t sts = addr[TPM_STS];
    2.28 +		uint8_t sts = mmio_readb(&addr[TPM_STS]);
    2.29  		if ((sts & mask) == expect) {
    2.30  			rc = 1;
    2.31  			break;
    2.32 @@ -45,16 +60,17 @@ static uint32_t tis_wait_sts(uint8_t *ad
    2.33  
    2.34  static uint32_t tis_activate(uint32_t baseaddr)
    2.35  {
    2.36 -	uint32_t rc = 0;
    2.37 +	uint32_t rc = 1;
    2.38  	uint8_t *tis_addr = (uint8_t*)baseaddr;
    2.39  	uint8_t acc;
    2.40  	/* request access to locality */
    2.41 -	tis_addr[TPM_ACCESS] = 0x2;
    2.42 +	tis_addr[TPM_ACCESS] = ACCESS_REQUEST_USE;
    2.43  
    2.44 -	acc = tis_addr[TPM_ACCESS];
    2.45 -	if ((acc & 0x20) != 0) {
    2.46 -		tis_addr[TPM_STS] = 0x40;
    2.47 -		rc = tis_wait_sts(tis_addr, 100, 0x40, 0x40);
    2.48 +	acc = mmio_readb(&tis_addr[TPM_ACCESS]);
    2.49 +	if ((acc & ACCESS_ACTIVE_LOCALITY) != 0) {
    2.50 +		tis_addr[TPM_STS] = STS_COMMAND_READY;
    2.51 +		rc = tis_wait_sts(tis_addr, 100,
    2.52 +		                  STS_COMMAND_READY, STS_COMMAND_READY);
    2.53  	}
    2.54  	return rc;
    2.55  }
    2.56 @@ -64,8 +80,8 @@ uint32_t tis_ready(uint32_t baseaddr)
    2.57  	uint32_t rc = 0;
    2.58  	uint8_t *tis_addr = (uint8_t*)baseaddr;
    2.59  
    2.60 -	tis_addr[TPM_STS] = 0x40;
    2.61 -	rc = tis_wait_sts(tis_addr, 100, 0x40, 0x40);
    2.62 +	tis_addr[TPM_STS] = STS_COMMAND_READY;
    2.63 +	rc = tis_wait_sts(tis_addr, 100, STS_COMMAND_READY, STS_COMMAND_READY);
    2.64  
    2.65  	return rc;
    2.66  }
    2.67 @@ -81,8 +97,7 @@ uint32_t tis_senddata(uint32_t baseaddr,
    2.68  		uint16_t burst = 0;
    2.69  		uint32_t ctr = 0;
    2.70  		while (burst == 0 && ctr < 2000) {
    2.71 -			burst = (((uint16_t)tis_addr[TPM_STS+1])     ) +
    2.72 -			        (((uint16_t)tis_addr[TPM_STS+2]) << 8);
    2.73 +			burst = mmio_readw((uint16_t *)&tis_addr[TPM_STS+1]);
    2.74  			if (burst == 0) {
    2.75  				mssleep(1);
    2.76  				ctr++;
    2.77 @@ -120,11 +135,11 @@ uint32_t tis_readresp(uint32_t baseaddr,
    2.78  	uint32_t sts;
    2.79  
    2.80  	while (offset < len) {
    2.81 -		buffer[offset] = tis_addr[TPM_DATA_FIFO];
    2.82 +		buffer[offset] = mmio_readb(&tis_addr[TPM_DATA_FIFO]);
    2.83  		offset++;
    2.84 -		sts = tis_addr[TPM_STS];
    2.85 +		sts = mmio_readb(&tis_addr[TPM_STS]);
    2.86  		/* data left ? */
    2.87 -		if ((sts & 0x10) == 0) {
    2.88 +		if ((sts & STS_DATA_AVAILABLE) == 0) {
    2.89  			break;
    2.90  		}
    2.91  	}
    2.92 @@ -136,7 +151,7 @@ uint32_t tis_waitdatavalid(uint32_t base
    2.93  {
    2.94  	uint8_t *tis_addr = (uint8_t*)baseaddr;
    2.95  	uint32_t rc = 0;
    2.96 -	if (tis_wait_sts(tis_addr, 1000, 0x80, 0x80) == 0) {
    2.97 +	if (tis_wait_sts(tis_addr, 1000, STS_VALID, STS_VALID) == 0) {
    2.98  		rc = TCG_NO_RESPONSE;
    2.99  	}
   2.100  	return rc;
   2.101 @@ -146,8 +161,9 @@ uint32_t tis_waitrespready(uint32_t base
   2.102  {
   2.103  	uint32_t rc = 0;
   2.104  	uint8_t *tis_addr = (uint8_t*)baseaddr;
   2.105 -	tis_addr[TPM_STS] = 0x20;
   2.106 -	if (tis_wait_sts(tis_addr, timeout, 0x10, 0x10) == 0) {
   2.107 +	tis_addr[TPM_STS] = STS_TPM_GO;
   2.108 +	if (tis_wait_sts(tis_addr, timeout,
   2.109 +	                 STS_DATA_AVAILABLE, STS_DATA_AVAILABLE) == 0) {
   2.110  		rc = TCG_NO_RESPONSE;
   2.111  	}
   2.112  	return rc;
   2.113 @@ -158,7 +174,7 @@ uint32_t tis_probe(uint32_t baseaddr)
   2.114  {
   2.115  	uint32_t rc = 0;
   2.116  	uint8_t *tis_addr = (uint8_t*)baseaddr;
   2.117 -	uint32_t didvid = *(uint32_t*)&tis_addr[TPM_DID_VID];
   2.118 +	uint32_t didvid = mmio_readl((uint32_t *)&tis_addr[TPM_DID_VID]);
   2.119  	if ((didvid != 0) && (didvid != 0xffffffff)) {
   2.120  		rc = 1;
   2.121  	}
     3.1 --- a/tools/firmware/rombios/32bit/util.h	Tue Feb 06 22:59:35 2007 +0000
     3.2 +++ b/tools/firmware/rombios/32bit/util.h	Tue Feb 06 23:01:35 2007 +0000
     3.3 @@ -24,5 +24,20 @@ void byte_to_hex(char *digits, uint8_t b
     3.4  void uuid_to_string(char *dest, uint8_t *uuid);
     3.5  int printf(const char *fmt, ...);
     3.6  
     3.7 +static inline uint8_t mmio_readb(uint8_t *addr)
     3.8 +{
     3.9 +	return *(volatile uint8_t *)addr;
    3.10 +}
    3.11 +
    3.12 +static inline uint16_t mmio_readw(uint16_t *addr)
    3.13 +{
    3.14 +	return *(volatile uint16_t *)addr;
    3.15 +}
    3.16 +
    3.17 +static inline uint32_t mmio_readl(uint32_t *addr)
    3.18 +{
    3.19 +	return *(volatile uint32_t *)addr;
    3.20 +}
    3.21 +
    3.22  
    3.23  #endif
     4.1 --- a/tools/firmware/rombios/rombios.c	Tue Feb 06 22:59:35 2007 +0000
     4.2 +++ b/tools/firmware/rombios/rombios.c	Tue Feb 06 23:01:35 2007 +0000
     4.3 @@ -5722,9 +5722,6 @@ int13_cdemu(DS, ES, DI, SI, BP, SP, BX, 
     4.4      goto int13_fail;
     4.5      }
     4.6  
     4.7 -#if BX_TCGBIOS
     4.8 -  tcpa_ipl((Bit32u)bootseg);               /* specs: 8.2.3 steps 4 and 5 */
     4.9 -#endif
    4.10    
    4.11    switch (GET_AH()) {
    4.12  
    4.13 @@ -7741,6 +7738,10 @@ ASM_END
    4.14        }
    4.15      }
    4.16  
    4.17 +#if BX_TCGBIOS
    4.18 +    tcpa_add_bootdevice((Bit32u)0L, (Bit32u)bootdrv);
    4.19 +#endif
    4.20 +
    4.21      /* Canonicalize bootseg:bootip */
    4.22      bootip = (bootseg & 0x0fff) << 4;
    4.23      bootseg &= 0xf000;
    4.24 @@ -7760,6 +7761,9 @@ ASM_END
    4.25      bootdrv = (Bit8u)(status>>8);
    4.26      bootseg = read_word(ebda_seg,&EbdaData->cdemu.load_segment);
    4.27      /* Canonicalize bootseg:bootip */
    4.28 +#if BX_TCGBIOS
    4.29 +    tcpa_add_bootdevice((Bit32u)1L, (Bit32u)0L);
    4.30 +#endif
    4.31      bootip = (bootseg & 0x0fff) << 4;
    4.32      bootseg &= 0xf000;
    4.33      break;
    4.34 @@ -7773,6 +7777,9 @@ ASM_END
    4.35    default: return;
    4.36    }
    4.37  
    4.38 +#if BX_TCGBIOS
    4.39 +  tcpa_ipl((Bit32u)bootseg);               /* specs: 8.2.3 steps 4 and 5 */
    4.40 +#endif
    4.41    /* Debugging info */
    4.42    printf("Booting from %x:%x\n", bootseg, bootip);
    4.43