direct-io.hg

changeset 13964:f9c079fca143

Bring TPM driver files to 2.6.18 level. Remove the tpm.c so that the
one from the kernel can be used and reduce changes to a minimum
required to compile the xen-specific driver.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author kfraser@localhost.localdomain
date Thu Feb 15 14:21:50 2007 +0000 (2007-02-15)
parents 296d7aa451a3
children 1f5e6fb9c652
files linux-2.6-xen-sparse/drivers/char/tpm/Kconfig linux-2.6-xen-sparse/drivers/char/tpm/tpm.c linux-2.6-xen-sparse/drivers/char/tpm/tpm.h linux-2.6-xen-sparse/drivers/char/tpm/tpm_vtpm.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/char/tpm/Kconfig	Thu Feb 15 14:20:05 2007 +0000
     1.2 +++ b/linux-2.6-xen-sparse/drivers/char/tpm/Kconfig	Thu Feb 15 14:21:50 2007 +0000
     1.3 @@ -22,7 +22,7 @@ config TCG_TPM
     1.4  
     1.5  config TCG_TIS
     1.6  	tristate "TPM Interface Specification 1.2 Interface"
     1.7 -	depends on TCG_TPM
     1.8 +	depends on TCG_TPM && PNPACPI
     1.9  	---help---
    1.10  	  If you have a TPM security chip that is compliant with the
    1.11  	  TCG TIS 1.2 TPM specification say Yes and it will be accessible
     2.1 --- a/linux-2.6-xen-sparse/drivers/char/tpm/tpm.c	Thu Feb 15 14:20:05 2007 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,1222 +0,0 @@
     2.4 -/*
     2.5 - * Copyright (C) 2004 IBM Corporation
     2.6 - *
     2.7 - * Authors:
     2.8 - * Leendert van Doorn <leendert@watson.ibm.com>
     2.9 - * Dave Safford <safford@watson.ibm.com>
    2.10 - * Reiner Sailer <sailer@watson.ibm.com>
    2.11 - * Kylene Hall <kjhall@us.ibm.com>
    2.12 - *
    2.13 - * Maintained by: <tpmdd_devel@lists.sourceforge.net>
    2.14 - *
    2.15 - * Device driver for TCG/TCPA TPM (trusted platform module).
    2.16 - * Specifications at www.trustedcomputinggroup.org	 
    2.17 - *
    2.18 - * This program is free software; you can redistribute it and/or
    2.19 - * modify it under the terms of the GNU General Public License as
    2.20 - * published by the Free Software Foundation, version 2 of the
    2.21 - * License.
    2.22 - * 
    2.23 - * Note, the TPM chip is not interrupt driven (only polling)
    2.24 - * and can have very long timeouts (minutes!). Hence the unusual
    2.25 - * calls to msleep.
    2.26 - *
    2.27 - */
    2.28 -
    2.29 -#include <linux/sched.h>
    2.30 -#include <linux/poll.h>
    2.31 -#include <linux/spinlock.h>
    2.32 -#include "tpm.h"
    2.33 -
    2.34 -enum tpm_const {
    2.35 -	TPM_MINOR = 224,	/* officially assigned */
    2.36 -#ifndef CONFIG_XEN
    2.37 -	TPM_BUFSIZE = 2048,
    2.38 -#endif
    2.39 -	TPM_NUM_DEVICES = 256,
    2.40 -};
    2.41 -
    2.42 -enum tpm_duration {
    2.43 -	TPM_SHORT = 0,
    2.44 -	TPM_MEDIUM = 1,
    2.45 -	TPM_LONG = 2,
    2.46 -	TPM_UNDEFINED,
    2.47 -};
    2.48 -
    2.49 -#define TPM_MAX_ORDINAL 243
    2.50 -#define TPM_MAX_PROTECTED_ORDINAL 12
    2.51 -#define TPM_PROTECTED_ORDINAL_MASK 0xFF
    2.52 -
    2.53 -static LIST_HEAD(tpm_chip_list);
    2.54 -static DEFINE_SPINLOCK(driver_lock);
    2.55 -static DECLARE_BITMAP(dev_mask, TPM_NUM_DEVICES);
    2.56 -
    2.57 -/*
    2.58 - * Array with one entry per ordinal defining the maximum amount
    2.59 - * of time the chip could take to return the result.  The ordinal
    2.60 - * designation of short, medium or long is defined in a table in
    2.61 - * TCG Specification TPM Main Part 2 TPM Structures Section 17. The
    2.62 - * values of the SHORT, MEDIUM, and LONG durations are retrieved
    2.63 - * from the chip during initialization with a call to tpm_get_timeouts.
    2.64 - */
    2.65 -static const u8 tpm_protected_ordinal_duration[TPM_MAX_PROTECTED_ORDINAL] = {
    2.66 -	TPM_UNDEFINED,		/* 0 */
    2.67 -	TPM_UNDEFINED,
    2.68 -	TPM_UNDEFINED,
    2.69 -	TPM_UNDEFINED,
    2.70 -	TPM_UNDEFINED,
    2.71 -	TPM_UNDEFINED,		/* 5 */
    2.72 -	TPM_UNDEFINED,
    2.73 -	TPM_UNDEFINED,
    2.74 -	TPM_UNDEFINED,
    2.75 -	TPM_UNDEFINED,
    2.76 -	TPM_SHORT,		/* 10 */
    2.77 -	TPM_SHORT,
    2.78 -};
    2.79 -
    2.80 -static const u8 tpm_ordinal_duration[TPM_MAX_ORDINAL] = {
    2.81 -	TPM_UNDEFINED,		/* 0 */
    2.82 -	TPM_UNDEFINED,
    2.83 -	TPM_UNDEFINED,
    2.84 -	TPM_UNDEFINED,
    2.85 -	TPM_UNDEFINED,
    2.86 -	TPM_UNDEFINED,		/* 5 */
    2.87 -	TPM_UNDEFINED,
    2.88 -	TPM_UNDEFINED,
    2.89 -	TPM_UNDEFINED,
    2.90 -	TPM_UNDEFINED,
    2.91 -	TPM_SHORT,		/* 10 */
    2.92 -	TPM_SHORT,
    2.93 -	TPM_MEDIUM,
    2.94 -	TPM_LONG,
    2.95 -	TPM_LONG,
    2.96 -	TPM_MEDIUM,		/* 15 */
    2.97 -	TPM_SHORT,
    2.98 -	TPM_SHORT,
    2.99 -	TPM_MEDIUM,
   2.100 -	TPM_LONG,
   2.101 -	TPM_SHORT,		/* 20 */
   2.102 -	TPM_SHORT,
   2.103 -	TPM_MEDIUM,
   2.104 -	TPM_MEDIUM,
   2.105 -	TPM_MEDIUM,
   2.106 -	TPM_SHORT,		/* 25 */
   2.107 -	TPM_SHORT,
   2.108 -	TPM_MEDIUM,
   2.109 -	TPM_SHORT,
   2.110 -	TPM_SHORT,
   2.111 -	TPM_MEDIUM,		/* 30 */
   2.112 -	TPM_LONG,
   2.113 -	TPM_MEDIUM,
   2.114 -	TPM_SHORT,
   2.115 -	TPM_SHORT,
   2.116 -	TPM_SHORT,		/* 35 */
   2.117 -	TPM_MEDIUM,
   2.118 -	TPM_MEDIUM,
   2.119 -	TPM_UNDEFINED,
   2.120 -	TPM_UNDEFINED,
   2.121 -	TPM_MEDIUM,		/* 40 */
   2.122 -	TPM_LONG,
   2.123 -	TPM_MEDIUM,
   2.124 -	TPM_SHORT,
   2.125 -	TPM_SHORT,
   2.126 -	TPM_SHORT,		/* 45 */
   2.127 -	TPM_SHORT,
   2.128 -	TPM_SHORT,
   2.129 -	TPM_SHORT,
   2.130 -	TPM_LONG,
   2.131 -	TPM_MEDIUM,		/* 50 */
   2.132 -	TPM_MEDIUM,
   2.133 -	TPM_UNDEFINED,
   2.134 -	TPM_UNDEFINED,
   2.135 -	TPM_UNDEFINED,
   2.136 -	TPM_UNDEFINED,		/* 55 */
   2.137 -	TPM_UNDEFINED,
   2.138 -	TPM_UNDEFINED,
   2.139 -	TPM_UNDEFINED,
   2.140 -	TPM_UNDEFINED,
   2.141 -	TPM_MEDIUM,		/* 60 */
   2.142 -	TPM_MEDIUM,
   2.143 -	TPM_MEDIUM,
   2.144 -	TPM_SHORT,
   2.145 -	TPM_SHORT,
   2.146 -	TPM_MEDIUM,		/* 65 */
   2.147 -	TPM_UNDEFINED,
   2.148 -	TPM_UNDEFINED,
   2.149 -	TPM_UNDEFINED,
   2.150 -	TPM_UNDEFINED,
   2.151 -	TPM_SHORT,		/* 70 */
   2.152 -	TPM_SHORT,
   2.153 -	TPM_UNDEFINED,
   2.154 -	TPM_UNDEFINED,
   2.155 -	TPM_UNDEFINED,
   2.156 -	TPM_UNDEFINED,		/* 75 */
   2.157 -	TPM_UNDEFINED,
   2.158 -	TPM_UNDEFINED,
   2.159 -	TPM_UNDEFINED,
   2.160 -	TPM_UNDEFINED,
   2.161 -	TPM_LONG,		/* 80 */
   2.162 -	TPM_UNDEFINED,
   2.163 -	TPM_MEDIUM,
   2.164 -	TPM_LONG,
   2.165 -	TPM_SHORT,
   2.166 -	TPM_UNDEFINED,		/* 85 */
   2.167 -	TPM_UNDEFINED,
   2.168 -	TPM_UNDEFINED,
   2.169 -	TPM_UNDEFINED,
   2.170 -	TPM_UNDEFINED,
   2.171 -	TPM_SHORT,		/* 90 */
   2.172 -	TPM_SHORT,
   2.173 -	TPM_SHORT,
   2.174 -	TPM_SHORT,
   2.175 -	TPM_SHORT,
   2.176 -	TPM_UNDEFINED,		/* 95 */
   2.177 -	TPM_UNDEFINED,
   2.178 -	TPM_UNDEFINED,
   2.179 -	TPM_UNDEFINED,
   2.180 -	TPM_UNDEFINED,
   2.181 -	TPM_MEDIUM,		/* 100 */
   2.182 -	TPM_SHORT,
   2.183 -	TPM_SHORT,
   2.184 -	TPM_UNDEFINED,
   2.185 -	TPM_UNDEFINED,
   2.186 -	TPM_UNDEFINED,		/* 105 */
   2.187 -	TPM_UNDEFINED,
   2.188 -	TPM_UNDEFINED,
   2.189 -	TPM_UNDEFINED,
   2.190 -	TPM_UNDEFINED,
   2.191 -	TPM_SHORT,		/* 110 */
   2.192 -	TPM_SHORT,
   2.193 -	TPM_SHORT,
   2.194 -	TPM_SHORT,
   2.195 -	TPM_SHORT,
   2.196 -	TPM_SHORT,		/* 115 */
   2.197 -	TPM_SHORT,
   2.198 -	TPM_SHORT,
   2.199 -	TPM_UNDEFINED,
   2.200 -	TPM_UNDEFINED,
   2.201 -	TPM_LONG,		/* 120 */
   2.202 -	TPM_LONG,
   2.203 -	TPM_MEDIUM,
   2.204 -	TPM_UNDEFINED,
   2.205 -	TPM_SHORT,
   2.206 -	TPM_SHORT,		/* 125 */
   2.207 -	TPM_SHORT,
   2.208 -	TPM_LONG,
   2.209 -	TPM_SHORT,
   2.210 -	TPM_SHORT,
   2.211 -	TPM_SHORT,		/* 130 */
   2.212 -	TPM_MEDIUM,
   2.213 -	TPM_UNDEFINED,
   2.214 -	TPM_SHORT,
   2.215 -	TPM_MEDIUM,
   2.216 -	TPM_UNDEFINED,		/* 135 */
   2.217 -	TPM_UNDEFINED,
   2.218 -	TPM_UNDEFINED,
   2.219 -	TPM_UNDEFINED,
   2.220 -	TPM_UNDEFINED,
   2.221 -	TPM_SHORT,		/* 140 */
   2.222 -	TPM_SHORT,
   2.223 -	TPM_UNDEFINED,
   2.224 -	TPM_UNDEFINED,
   2.225 -	TPM_UNDEFINED,
   2.226 -	TPM_UNDEFINED,		/* 145 */
   2.227 -	TPM_UNDEFINED,
   2.228 -	TPM_UNDEFINED,
   2.229 -	TPM_UNDEFINED,
   2.230 -	TPM_UNDEFINED,
   2.231 -	TPM_SHORT,		/* 150 */
   2.232 -	TPM_MEDIUM,
   2.233 -	TPM_MEDIUM,
   2.234 -	TPM_SHORT,
   2.235 -	TPM_SHORT,
   2.236 -	TPM_UNDEFINED,		/* 155 */
   2.237 -	TPM_UNDEFINED,
   2.238 -	TPM_UNDEFINED,
   2.239 -	TPM_UNDEFINED,
   2.240 -	TPM_UNDEFINED,
   2.241 -	TPM_SHORT,		/* 160 */
   2.242 -	TPM_SHORT,
   2.243 -	TPM_SHORT,
   2.244 -	TPM_SHORT,
   2.245 -	TPM_UNDEFINED,
   2.246 -	TPM_UNDEFINED,		/* 165 */
   2.247 -	TPM_UNDEFINED,
   2.248 -	TPM_UNDEFINED,
   2.249 -	TPM_UNDEFINED,
   2.250 -	TPM_UNDEFINED,
   2.251 -	TPM_LONG,		/* 170 */
   2.252 -	TPM_UNDEFINED,
   2.253 -	TPM_UNDEFINED,
   2.254 -	TPM_UNDEFINED,
   2.255 -	TPM_UNDEFINED,
   2.256 -	TPM_UNDEFINED,		/* 175 */
   2.257 -	TPM_UNDEFINED,
   2.258 -	TPM_UNDEFINED,
   2.259 -	TPM_UNDEFINED,
   2.260 -	TPM_UNDEFINED,
   2.261 -	TPM_MEDIUM,		/* 180 */
   2.262 -	TPM_SHORT,
   2.263 -	TPM_MEDIUM,
   2.264 -	TPM_MEDIUM,
   2.265 -	TPM_MEDIUM,
   2.266 -	TPM_MEDIUM,		/* 185 */
   2.267 -	TPM_SHORT,
   2.268 -	TPM_UNDEFINED,
   2.269 -	TPM_UNDEFINED,
   2.270 -	TPM_UNDEFINED,
   2.271 -	TPM_UNDEFINED,		/* 190 */
   2.272 -	TPM_UNDEFINED,
   2.273 -	TPM_UNDEFINED,
   2.274 -	TPM_UNDEFINED,
   2.275 -	TPM_UNDEFINED,
   2.276 -	TPM_UNDEFINED,		/* 195 */
   2.277 -	TPM_UNDEFINED,
   2.278 -	TPM_UNDEFINED,
   2.279 -	TPM_UNDEFINED,
   2.280 -	TPM_UNDEFINED,
   2.281 -	TPM_SHORT,		/* 200 */
   2.282 -	TPM_UNDEFINED,
   2.283 -	TPM_UNDEFINED,
   2.284 -	TPM_UNDEFINED,
   2.285 -	TPM_SHORT,
   2.286 -	TPM_SHORT,		/* 205 */
   2.287 -	TPM_SHORT,
   2.288 -	TPM_SHORT,
   2.289 -	TPM_SHORT,
   2.290 -	TPM_SHORT,
   2.291 -	TPM_MEDIUM,		/* 210 */
   2.292 -	TPM_UNDEFINED,
   2.293 -	TPM_MEDIUM,
   2.294 -	TPM_MEDIUM,
   2.295 -	TPM_MEDIUM,
   2.296 -	TPM_UNDEFINED,		/* 215 */
   2.297 -	TPM_MEDIUM,
   2.298 -	TPM_UNDEFINED,
   2.299 -	TPM_UNDEFINED,
   2.300 -	TPM_SHORT,
   2.301 -	TPM_SHORT,		/* 220 */
   2.302 -	TPM_SHORT,
   2.303 -	TPM_SHORT,
   2.304 -	TPM_SHORT,
   2.305 -	TPM_SHORT,
   2.306 -	TPM_UNDEFINED,		/* 225 */
   2.307 -	TPM_UNDEFINED,
   2.308 -	TPM_UNDEFINED,
   2.309 -	TPM_UNDEFINED,
   2.310 -	TPM_UNDEFINED,
   2.311 -	TPM_SHORT,		/* 230 */
   2.312 -	TPM_LONG,
   2.313 -	TPM_MEDIUM,
   2.314 -	TPM_UNDEFINED,
   2.315 -	TPM_UNDEFINED,
   2.316 -	TPM_UNDEFINED,		/* 235 */
   2.317 -	TPM_UNDEFINED,
   2.318 -	TPM_UNDEFINED,
   2.319 -	TPM_UNDEFINED,
   2.320 -	TPM_UNDEFINED,
   2.321 -	TPM_SHORT,		/* 240 */
   2.322 -	TPM_UNDEFINED,
   2.323 -	TPM_MEDIUM,
   2.324 -};
   2.325 -
   2.326 -static void user_reader_timeout(unsigned long ptr)
   2.327 -{
   2.328 -	struct tpm_chip *chip = (struct tpm_chip *) ptr;
   2.329 -
   2.330 -	schedule_work(&chip->work);
   2.331 -}
   2.332 -
   2.333 -static void timeout_work(void *ptr)
   2.334 -{
   2.335 -	struct tpm_chip *chip = ptr;
   2.336 -
   2.337 -	down(&chip->buffer_mutex);
   2.338 -	atomic_set(&chip->data_pending, 0);
   2.339 -#ifndef CONFIG_XEN
   2.340 -	memset(chip->data_buffer, 0, TPM_BUFSIZE);
   2.341 -#else
   2.342 -	memset(chip->data_buffer, 0, get_chip_buffersize(chip));
   2.343 -#endif
   2.344 -	up(&chip->buffer_mutex);
   2.345 -}
   2.346 -
   2.347 -/*
   2.348 - * Returns max number of jiffies to wait
   2.349 - */
   2.350 -unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip,
   2.351 -					   u32 ordinal)
   2.352 -{
   2.353 -	int duration_idx = TPM_UNDEFINED;
   2.354 -	int duration = 0;
   2.355 -
   2.356 -	if (ordinal < TPM_MAX_ORDINAL)
   2.357 -		duration_idx = tpm_ordinal_duration[ordinal];
   2.358 -	else if ((ordinal & TPM_PROTECTED_ORDINAL_MASK) <
   2.359 -		 TPM_MAX_PROTECTED_ORDINAL)
   2.360 -		duration_idx =
   2.361 -		    tpm_protected_ordinal_duration[ordinal &
   2.362 -						   TPM_PROTECTED_ORDINAL_MASK];
   2.363 -
   2.364 -	if (duration_idx != TPM_UNDEFINED)
   2.365 -		duration = chip->vendor.duration[duration_idx];
   2.366 -	if (duration <= 0)
   2.367 -		return 2 * 60 * HZ;
   2.368 -	else
   2.369 -		return duration;
   2.370 -}
   2.371 -EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration);
   2.372 -
   2.373 -/*
   2.374 - * Internal kernel interface to transmit TPM commands
   2.375 - */
   2.376 -static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
   2.377 -			    size_t bufsiz)
   2.378 -{
   2.379 -	ssize_t rc;
   2.380 -	u32 count, ordinal;
   2.381 -	unsigned long stop;
   2.382 -
   2.383 -	count = be32_to_cpu(*((__be32 *) (buf + 2)));
   2.384 -	ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
   2.385 -	if (count == 0)
   2.386 -		return -ENODATA;
   2.387 -	if (count > bufsiz) {
   2.388 -		dev_err(chip->dev,
   2.389 -			"invalid count value %x %zx \n", count, bufsiz);
   2.390 -		return -E2BIG;
   2.391 -	}
   2.392 -
   2.393 -	down(&chip->tpm_mutex);
   2.394 -
   2.395 -	if ((rc = chip->vendor.send(chip, (u8 *) buf, count)) < 0) {
   2.396 -		dev_err(chip->dev,
   2.397 -			"tpm_transmit: tpm_send: error %zd\n", rc);
   2.398 -		goto out;
   2.399 -	}
   2.400 -
   2.401 -	if (chip->vendor.irq)
   2.402 -		goto out_recv;
   2.403 -
   2.404 -	stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal);
   2.405 -	do {
   2.406 -		u8 status = chip->vendor.status(chip);
   2.407 -		if ((status & chip->vendor.req_complete_mask) ==
   2.408 -		    chip->vendor.req_complete_val)
   2.409 -			goto out_recv;
   2.410 -
   2.411 -		if ((status == chip->vendor.req_canceled)) {
   2.412 -			dev_err(chip->dev, "Operation Canceled\n");
   2.413 -			rc = -ECANCELED;
   2.414 -			goto out;
   2.415 -		}
   2.416 -
   2.417 -		msleep(TPM_TIMEOUT);	/* CHECK */
   2.418 -		rmb();
   2.419 -	} while (time_before(jiffies, stop));
   2.420 -
   2.421 -	chip->vendor.cancel(chip);
   2.422 -	dev_err(chip->dev, "Operation Timed out\n");
   2.423 -	rc = -ETIME;
   2.424 -	goto out;
   2.425 -
   2.426 -out_recv:
   2.427 -	rc = chip->vendor.recv(chip, (u8 *) buf, bufsiz);
   2.428 -	if (rc < 0)
   2.429 -		dev_err(chip->dev,
   2.430 -			"tpm_transmit: tpm_recv: error %zd\n", rc);
   2.431 -out:
   2.432 -	up(&chip->tpm_mutex);
   2.433 -	return rc;
   2.434 -}
   2.435 -
   2.436 -#define TPM_DIGEST_SIZE 20
   2.437 -#define TPM_ERROR_SIZE 10
   2.438 -#define TPM_RET_CODE_IDX 6
   2.439 -#define TPM_GET_CAP_RET_SIZE_IDX 10
   2.440 -#define TPM_GET_CAP_RET_UINT32_1_IDX 14
   2.441 -#define TPM_GET_CAP_RET_UINT32_2_IDX 18
   2.442 -#define TPM_GET_CAP_RET_UINT32_3_IDX 22
   2.443 -#define TPM_GET_CAP_RET_UINT32_4_IDX 26
   2.444 -#define TPM_GET_CAP_PERM_DISABLE_IDX 16
   2.445 -#define TPM_GET_CAP_PERM_INACTIVE_IDX 18
   2.446 -#define TPM_GET_CAP_RET_BOOL_1_IDX 14
   2.447 -#define TPM_GET_CAP_TEMP_INACTIVE_IDX 16
   2.448 -
   2.449 -#define TPM_CAP_IDX 13
   2.450 -#define TPM_CAP_SUBCAP_IDX 21
   2.451 -
   2.452 -enum tpm_capabilities {
   2.453 -	TPM_CAP_FLAG = 4,
   2.454 -	TPM_CAP_PROP = 5,
   2.455 -};
   2.456 -
   2.457 -enum tpm_sub_capabilities {
   2.458 -	TPM_CAP_PROP_PCR = 0x1,
   2.459 -	TPM_CAP_PROP_MANUFACTURER = 0x3,
   2.460 -	TPM_CAP_FLAG_PERM = 0x8,
   2.461 -	TPM_CAP_FLAG_VOL = 0x9,
   2.462 -	TPM_CAP_PROP_OWNER = 0x11,
   2.463 -	TPM_CAP_PROP_TIS_TIMEOUT = 0x15,
   2.464 -	TPM_CAP_PROP_TIS_DURATION = 0x20,
   2.465 -};
   2.466 -
   2.467 -/*
   2.468 - * This is a semi generic GetCapability command for use
   2.469 - * with the capability type TPM_CAP_PROP or TPM_CAP_FLAG
   2.470 - * and their associated sub_capabilities.
   2.471 - */
   2.472 -
   2.473 -static const u8 tpm_cap[] = {
   2.474 -	0, 193,			/* TPM_TAG_RQU_COMMAND */
   2.475 -	0, 0, 0, 22,		/* length */
   2.476 -	0, 0, 0, 101,		/* TPM_ORD_GetCapability */
   2.477 -	0, 0, 0, 0,		/* TPM_CAP_<TYPE> */
   2.478 -	0, 0, 0, 4,		/* TPM_CAP_SUB_<TYPE> size */
   2.479 -	0, 0, 1, 0		/* TPM_CAP_SUB_<TYPE> */
   2.480 -};
   2.481 -
   2.482 -static ssize_t transmit_cmd(struct tpm_chip *chip, u8 *data, int len,
   2.483 -			    char *desc)
   2.484 -{
   2.485 -	int err;
   2.486 -
   2.487 -	len = tpm_transmit(chip, data, len);
   2.488 -	if (len <  0)
   2.489 -		return len;
   2.490 -	if (len == TPM_ERROR_SIZE) {
   2.491 -		err = be32_to_cpu(*((__be32 *) (data + TPM_RET_CODE_IDX)));
   2.492 -		dev_dbg(chip->dev, "A TPM error (%d) occurred %s\n", err, desc);
   2.493 -		return err;
   2.494 -	}
   2.495 -	return 0;
   2.496 -}
   2.497 -
   2.498 -void tpm_gen_interrupt(struct tpm_chip *chip)
   2.499 -{
   2.500 -	u8 data[max_t(int, ARRAY_SIZE(tpm_cap), 30)];
   2.501 -	ssize_t rc;
   2.502 -
   2.503 -	memcpy(data, tpm_cap, sizeof(tpm_cap));
   2.504 -	data[TPM_CAP_IDX] = TPM_CAP_PROP;
   2.505 -	data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_TIS_TIMEOUT;
   2.506 -
   2.507 -	rc = transmit_cmd(chip, data, sizeof(data),
   2.508 -			"attempting to determine the timeouts");
   2.509 -}
   2.510 -EXPORT_SYMBOL_GPL(tpm_gen_interrupt);
   2.511 -
   2.512 -void tpm_get_timeouts(struct tpm_chip *chip)
   2.513 -{
   2.514 -	u8 data[max_t(int, ARRAY_SIZE(tpm_cap), 30)];
   2.515 -	ssize_t rc;
   2.516 -	u32 timeout;
   2.517 -
   2.518 -	memcpy(data, tpm_cap, sizeof(tpm_cap));
   2.519 -	data[TPM_CAP_IDX] = TPM_CAP_PROP;
   2.520 -	data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_TIS_TIMEOUT;
   2.521 -
   2.522 -	rc = transmit_cmd(chip, data, sizeof(data),
   2.523 -			"attempting to determine the timeouts");
   2.524 -	if (rc)
   2.525 -		goto duration;
   2.526 -
   2.527 -	if (be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_SIZE_IDX)))
   2.528 -	    != 4 * sizeof(u32))
   2.529 -		goto duration;
   2.530 -
   2.531 -	/* Don't overwrite default if value is 0 */
   2.532 -	timeout =
   2.533 -	    be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX)));
   2.534 -	if (timeout)
   2.535 -		chip->vendor.timeout_a = msecs_to_jiffies(timeout);
   2.536 -	timeout =
   2.537 -	    be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_2_IDX)));
   2.538 -	if (timeout)
   2.539 -		chip->vendor.timeout_b = msecs_to_jiffies(timeout);
   2.540 -	timeout =
   2.541 -	    be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_3_IDX)));
   2.542 -	if (timeout)
   2.543 -		chip->vendor.timeout_c = msecs_to_jiffies(timeout);
   2.544 -	timeout =
   2.545 -	    be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_4_IDX)));
   2.546 -	if (timeout)
   2.547 -		chip->vendor.timeout_d = msecs_to_jiffies(timeout);
   2.548 -
   2.549 -duration:
   2.550 -	memcpy(data, tpm_cap, sizeof(tpm_cap));
   2.551 -	data[TPM_CAP_IDX] = TPM_CAP_PROP;
   2.552 -	data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_TIS_DURATION;
   2.553 -
   2.554 -	rc = transmit_cmd(chip, data, sizeof(data),
   2.555 -			"attempting to determine the durations");
   2.556 -	if (rc)
   2.557 -		return;
   2.558 -
   2.559 -	if (be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_SIZE_IDX)))
   2.560 -	    != 3 * sizeof(u32))
   2.561 -		return;
   2.562 -
   2.563 -	chip->vendor.duration[TPM_SHORT] =
   2.564 -	    msecs_to_jiffies(be32_to_cpu
   2.565 -			     (*((__be32 *) (data +
   2.566 -					    TPM_GET_CAP_RET_UINT32_1_IDX))));
   2.567 -	chip->vendor.duration[TPM_MEDIUM] =
   2.568 -	    msecs_to_jiffies(be32_to_cpu
   2.569 -			     (*((__be32 *) (data +
   2.570 -					    TPM_GET_CAP_RET_UINT32_2_IDX))));
   2.571 -	chip->vendor.duration[TPM_LONG] =
   2.572 -	    msecs_to_jiffies(be32_to_cpu
   2.573 -			     (*((__be32 *) (data +
   2.574 -					    TPM_GET_CAP_RET_UINT32_3_IDX))));
   2.575 -}
   2.576 -EXPORT_SYMBOL_GPL(tpm_get_timeouts);
   2.577 -
   2.578 -void tpm_continue_selftest(struct tpm_chip *chip)
   2.579 -{
   2.580 -	u8 data[] = {
   2.581 -		0, 193,			/* TPM_TAG_RQU_COMMAND */
   2.582 -		0, 0, 0, 10,		/* length */
   2.583 -		0, 0, 0, 83,		/* TPM_ORD_GetCapability */
   2.584 -	};
   2.585 -
   2.586 -	tpm_transmit(chip, data, sizeof(data));
   2.587 -}
   2.588 -EXPORT_SYMBOL_GPL(tpm_continue_selftest);
   2.589 -
   2.590 -ssize_t tpm_show_enabled(struct device * dev, struct device_attribute * attr,
   2.591 -			char *buf)
   2.592 -{
   2.593 -	u8 data[max_t(int, ARRAY_SIZE(tpm_cap), 35)];
   2.594 -	ssize_t rc;
   2.595 -
   2.596 -	struct tpm_chip *chip = dev_get_drvdata(dev);
   2.597 -	if (chip == NULL)
   2.598 -		return -ENODEV;
   2.599 -
   2.600 -	memcpy(data, tpm_cap, sizeof(tpm_cap));
   2.601 -	data[TPM_CAP_IDX] = TPM_CAP_FLAG;
   2.602 -	data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_FLAG_PERM;
   2.603 -
   2.604 -	rc = transmit_cmd(chip, data, sizeof(data),
   2.605 -			"attemtping to determine the permanent state");
   2.606 -	if (rc)
   2.607 -		return 0;
   2.608 -	return sprintf(buf, "%d\n", !data[TPM_GET_CAP_PERM_DISABLE_IDX]);
   2.609 -}
   2.610 -EXPORT_SYMBOL_GPL(tpm_show_enabled);
   2.611 -
   2.612 -ssize_t tpm_show_active(struct device * dev, struct device_attribute * attr,
   2.613 -			char *buf)
   2.614 -{
   2.615 -	u8 data[max_t(int, ARRAY_SIZE(tpm_cap), 35)];
   2.616 -	ssize_t rc;
   2.617 -
   2.618 -	struct tpm_chip *chip = dev_get_drvdata(dev);
   2.619 -	if (chip == NULL)
   2.620 -		return -ENODEV;
   2.621 -
   2.622 -	memcpy(data, tpm_cap, sizeof(tpm_cap));
   2.623 -	data[TPM_CAP_IDX] = TPM_CAP_FLAG;
   2.624 -	data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_FLAG_PERM;
   2.625 -
   2.626 -	rc = transmit_cmd(chip, data, sizeof(data),
   2.627 -			"attemtping to determine the permanent state");
   2.628 -	if (rc)
   2.629 -		return 0;
   2.630 -	return sprintf(buf, "%d\n", !data[TPM_GET_CAP_PERM_INACTIVE_IDX]);
   2.631 -}
   2.632 -EXPORT_SYMBOL_GPL(tpm_show_active);
   2.633 -
   2.634 -ssize_t tpm_show_owned(struct device * dev, struct device_attribute * attr,
   2.635 -			char *buf)
   2.636 -{
   2.637 -	u8 data[sizeof(tpm_cap)];
   2.638 -	ssize_t rc;
   2.639 -
   2.640 -	struct tpm_chip *chip = dev_get_drvdata(dev);
   2.641 -	if (chip == NULL)
   2.642 -		return -ENODEV;
   2.643 -
   2.644 -	memcpy(data, tpm_cap, sizeof(tpm_cap));
   2.645 -	data[TPM_CAP_IDX] = TPM_CAP_PROP;
   2.646 -	data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_OWNER;
   2.647 -
   2.648 -	rc = transmit_cmd(chip, data, sizeof(data),
   2.649 -			"attempting to determine the owner state");
   2.650 -	if (rc)
   2.651 -		return 0;
   2.652 -	return sprintf(buf, "%d\n", data[TPM_GET_CAP_RET_BOOL_1_IDX]);
   2.653 -}
   2.654 -EXPORT_SYMBOL_GPL(tpm_show_owned);
   2.655 -
   2.656 -ssize_t tpm_show_temp_deactivated(struct device * dev,
   2.657 -				struct device_attribute * attr, char *buf)
   2.658 -{
   2.659 -	u8 data[sizeof(tpm_cap)];
   2.660 -	ssize_t rc;
   2.661 -
   2.662 -	struct tpm_chip *chip = dev_get_drvdata(dev);
   2.663 -	if (chip == NULL)
   2.664 -		return -ENODEV;
   2.665 -
   2.666 -	memcpy(data, tpm_cap, sizeof(tpm_cap));
   2.667 -	data[TPM_CAP_IDX] = TPM_CAP_FLAG;
   2.668 -	data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_FLAG_VOL;
   2.669 -
   2.670 -	rc = transmit_cmd(chip, data, sizeof(data),
   2.671 -			"attempting to determine the temporary state");
   2.672 -	if (rc)
   2.673 -		return 0;
   2.674 -	return sprintf(buf, "%d\n", data[TPM_GET_CAP_TEMP_INACTIVE_IDX]);
   2.675 -}
   2.676 -EXPORT_SYMBOL_GPL(tpm_show_temp_deactivated);
   2.677 -
   2.678 -static const u8 pcrread[] = {
   2.679 -	0, 193,			/* TPM_TAG_RQU_COMMAND */
   2.680 -	0, 0, 0, 14,		/* length */
   2.681 -	0, 0, 0, 21,		/* TPM_ORD_PcrRead */
   2.682 -	0, 0, 0, 0		/* PCR index */
   2.683 -};
   2.684 -
   2.685 -ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr,
   2.686 -		      char *buf)
   2.687 -{
   2.688 -	u8 data[max_t(int, max(ARRAY_SIZE(tpm_cap), ARRAY_SIZE(pcrread)), 30)];
   2.689 -	ssize_t rc;
   2.690 -	int i, j, num_pcrs;
   2.691 -	__be32 index;
   2.692 -	char *str = buf;
   2.693 -
   2.694 -	struct tpm_chip *chip = dev_get_drvdata(dev);
   2.695 -	if (chip == NULL)
   2.696 -		return -ENODEV;
   2.697 -
   2.698 -	memcpy(data, tpm_cap, sizeof(tpm_cap));
   2.699 -	data[TPM_CAP_IDX] = TPM_CAP_PROP;
   2.700 -	data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_PCR;
   2.701 -
   2.702 -	rc = transmit_cmd(chip, data, sizeof(data),
   2.703 -			"attempting to determine the number of PCRS");
   2.704 -	if (rc)
   2.705 -		return 0;
   2.706 -
   2.707 -	num_pcrs = be32_to_cpu(*((__be32 *) (data + 14)));
   2.708 -	for (i = 0; i < num_pcrs; i++) {
   2.709 -		memcpy(data, pcrread, sizeof(pcrread));
   2.710 -		index = cpu_to_be32(i);
   2.711 -		memcpy(data + 10, &index, 4);
   2.712 -		rc = transmit_cmd(chip, data, sizeof(data),
   2.713 -				"attempting to read a PCR");
   2.714 -		if (rc)
   2.715 -			goto out;
   2.716 -		str += sprintf(str, "PCR-%02d: ", i);
   2.717 -		for (j = 0; j < TPM_DIGEST_SIZE; j++)
   2.718 -			str += sprintf(str, "%02X ", *(data + 10 + j));
   2.719 -		str += sprintf(str, "\n");
   2.720 -	}
   2.721 -out:
   2.722 -	return str - buf;
   2.723 -}
   2.724 -EXPORT_SYMBOL_GPL(tpm_show_pcrs);
   2.725 -
   2.726 -#define  READ_PUBEK_RESULT_SIZE 314
   2.727 -static const u8 readpubek[] = {
   2.728 -	0, 193,			/* TPM_TAG_RQU_COMMAND */
   2.729 -	0, 0, 0, 30,		/* length */
   2.730 -	0, 0, 0, 124,		/* TPM_ORD_ReadPubek */
   2.731 -};
   2.732 -
   2.733 -ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr,
   2.734 -		       char *buf)
   2.735 -{
   2.736 -	u8 *data;
   2.737 -	ssize_t err;
   2.738 -	int i, rc;
   2.739 -	char *str = buf;
   2.740 -
   2.741 -	struct tpm_chip *chip = dev_get_drvdata(dev);
   2.742 -	if (chip == NULL)
   2.743 -		return -ENODEV;
   2.744 -
   2.745 -	data = kzalloc(READ_PUBEK_RESULT_SIZE, GFP_KERNEL);
   2.746 -	if (!data)
   2.747 -		return -ENOMEM;
   2.748 -
   2.749 -	memcpy(data, readpubek, sizeof(readpubek));
   2.750 -
   2.751 -	err = transmit_cmd(chip, data, READ_PUBEK_RESULT_SIZE,
   2.752 -			"attempting to read the PUBEK");
   2.753 -	if (err)
   2.754 -		goto out;
   2.755 -
   2.756 -	/* 
   2.757 -	   ignore header 10 bytes
   2.758 -	   algorithm 32 bits (1 == RSA )
   2.759 -	   encscheme 16 bits
   2.760 -	   sigscheme 16 bits
   2.761 -	   parameters (RSA 12->bytes: keybit, #primes, expbit)  
   2.762 -	   keylenbytes 32 bits
   2.763 -	   256 byte modulus
   2.764 -	   ignore checksum 20 bytes
   2.765 -	 */
   2.766 -
   2.767 -	str +=
   2.768 -	    sprintf(str,
   2.769 -		    "Algorithm: %02X %02X %02X %02X\nEncscheme: %02X %02X\n"
   2.770 -		    "Sigscheme: %02X %02X\nParameters: %02X %02X %02X %02X"
   2.771 -		    " %02X %02X %02X %02X %02X %02X %02X %02X\n"
   2.772 -		    "Modulus length: %d\nModulus: \n",
   2.773 -		    data[10], data[11], data[12], data[13], data[14],
   2.774 -		    data[15], data[16], data[17], data[22], data[23],
   2.775 -		    data[24], data[25], data[26], data[27], data[28],
   2.776 -		    data[29], data[30], data[31], data[32], data[33],
   2.777 -		    be32_to_cpu(*((__be32 *) (data + 34))));
   2.778 -
   2.779 -	for (i = 0; i < 256; i++) {
   2.780 -		str += sprintf(str, "%02X ", data[i + 38]);
   2.781 -		if ((i + 1) % 16 == 0)
   2.782 -			str += sprintf(str, "\n");
   2.783 -	}
   2.784 -out:
   2.785 -	rc = str - buf;
   2.786 -	kfree(data);
   2.787 -	return rc;
   2.788 -}
   2.789 -EXPORT_SYMBOL_GPL(tpm_show_pubek);
   2.790 -
   2.791 -#define CAP_VERSION_1_1 6
   2.792 -#define CAP_VERSION_1_2 0x1A
   2.793 -#define CAP_VERSION_IDX 13
   2.794 -static const u8 cap_version[] = {
   2.795 -	0, 193,			/* TPM_TAG_RQU_COMMAND */
   2.796 -	0, 0, 0, 18,		/* length */
   2.797 -	0, 0, 0, 101,		/* TPM_ORD_GetCapability */
   2.798 -	0, 0, 0, 0,
   2.799 -	0, 0, 0, 0
   2.800 -};
   2.801 -
   2.802 -ssize_t tpm_show_caps(struct device *dev, struct device_attribute *attr,
   2.803 -		      char *buf)
   2.804 -{
   2.805 -	u8 data[max_t(int, max(ARRAY_SIZE(tpm_cap), ARRAY_SIZE(cap_version)), 30)];
   2.806 -	ssize_t rc;
   2.807 -	char *str = buf;
   2.808 -
   2.809 -	struct tpm_chip *chip = dev_get_drvdata(dev);
   2.810 -	if (chip == NULL)
   2.811 -		return -ENODEV;
   2.812 -
   2.813 -	memcpy(data, tpm_cap, sizeof(tpm_cap));
   2.814 -	data[TPM_CAP_IDX] = TPM_CAP_PROP;
   2.815 -	data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_MANUFACTURER;
   2.816 -
   2.817 -	rc = transmit_cmd(chip, data, sizeof(data),
   2.818 -			"attempting to determine the manufacturer");
   2.819 -	if (rc)
   2.820 -		return 0;
   2.821 -
   2.822 -	str += sprintf(str, "Manufacturer: 0x%x\n",
   2.823 -		       be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX))));
   2.824 -
   2.825 -	memcpy(data, cap_version, sizeof(cap_version));
   2.826 -	data[CAP_VERSION_IDX] = CAP_VERSION_1_1;
   2.827 -	rc = transmit_cmd(chip, data, sizeof(data),
   2.828 -			"attempting to determine the 1.1 version");
   2.829 -	if (rc)
   2.830 -		goto out;
   2.831 -
   2.832 -	str += sprintf(str,
   2.833 -		       "TCG version: %d.%d\nFirmware version: %d.%d\n",
   2.834 -		       (int) data[14], (int) data[15], (int) data[16],
   2.835 -		       (int) data[17]);
   2.836 -
   2.837 -out:
   2.838 -	return str - buf;
   2.839 -}
   2.840 -EXPORT_SYMBOL_GPL(tpm_show_caps);
   2.841 -
   2.842 -ssize_t tpm_show_caps_1_2(struct device * dev,
   2.843 -			  struct device_attribute * attr, char *buf)
   2.844 -{
   2.845 -	u8 data[max_t(int, max(ARRAY_SIZE(tpm_cap), ARRAY_SIZE(cap_version)), 30)];
   2.846 -	ssize_t len;
   2.847 -	char *str = buf;
   2.848 -
   2.849 -	struct tpm_chip *chip = dev_get_drvdata(dev);
   2.850 -	if (chip == NULL)
   2.851 -		return -ENODEV;
   2.852 -
   2.853 -	memcpy(data, tpm_cap, sizeof(tpm_cap));
   2.854 -	data[TPM_CAP_IDX] = TPM_CAP_PROP;
   2.855 -	data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_MANUFACTURER;
   2.856 -
   2.857 -	if ((len = tpm_transmit(chip, data, sizeof(data))) <=
   2.858 -	    TPM_ERROR_SIZE) {
   2.859 -		dev_dbg(chip->dev, "A TPM error (%d) occurred "
   2.860 -			"attempting to determine the manufacturer\n",
   2.861 -			be32_to_cpu(*((__be32 *) (data + TPM_RET_CODE_IDX))));
   2.862 -		return 0;
   2.863 -	}
   2.864 -
   2.865 -	str += sprintf(str, "Manufacturer: 0x%x\n",
   2.866 -		       be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX))));
   2.867 -
   2.868 -	memcpy(data, cap_version, sizeof(cap_version));
   2.869 -	data[CAP_VERSION_IDX] = CAP_VERSION_1_2;
   2.870 -
   2.871 -	if ((len = tpm_transmit(chip, data, sizeof(data))) <=
   2.872 -	    TPM_ERROR_SIZE) {
   2.873 -		dev_err(chip->dev, "A TPM error (%d) occurred "
   2.874 -			"attempting to determine the 1.2 version\n",
   2.875 -			be32_to_cpu(*((__be32 *) (data + TPM_RET_CODE_IDX))));
   2.876 -		goto out;
   2.877 -	}
   2.878 -	str += sprintf(str,
   2.879 -		       "TCG version: %d.%d\nFirmware version: %d.%d\n",
   2.880 -		       (int) data[16], (int) data[17], (int) data[18],
   2.881 -		       (int) data[19]);
   2.882 -
   2.883 -out:
   2.884 -	return str - buf;
   2.885 -}
   2.886 -EXPORT_SYMBOL_GPL(tpm_show_caps_1_2);
   2.887 -
   2.888 -ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr,
   2.889 -			const char *buf, size_t count)
   2.890 -{
   2.891 -	struct tpm_chip *chip = dev_get_drvdata(dev);
   2.892 -	if (chip == NULL)
   2.893 -		return 0;
   2.894 -
   2.895 -	chip->vendor.cancel(chip);
   2.896 -	return count;
   2.897 -}
   2.898 -EXPORT_SYMBOL_GPL(tpm_store_cancel);
   2.899 -
   2.900 -/*
   2.901 - * Device file system interface to the TPM
   2.902 - */
   2.903 -int tpm_open(struct inode *inode, struct file *file)
   2.904 -{
   2.905 -	int rc = 0, minor = iminor(inode);
   2.906 -	struct tpm_chip *chip = NULL, *pos;
   2.907 -
   2.908 -	spin_lock(&driver_lock);
   2.909 -
   2.910 -	list_for_each_entry(pos, &tpm_chip_list, list) {
   2.911 -		if (pos->vendor.miscdev.minor == minor) {
   2.912 -			chip = pos;
   2.913 -			break;
   2.914 -		}
   2.915 -	}
   2.916 -
   2.917 -	if (chip == NULL) {
   2.918 -		rc = -ENODEV;
   2.919 -		goto err_out;
   2.920 -	}
   2.921 -
   2.922 -	if (chip->num_opens) {
   2.923 -		dev_dbg(chip->dev, "Another process owns this TPM\n");
   2.924 -		rc = -EBUSY;
   2.925 -		goto err_out;
   2.926 -	}
   2.927 -
   2.928 -	chip->num_opens++;
   2.929 -	get_device(chip->dev);
   2.930 -
   2.931 -	spin_unlock(&driver_lock);
   2.932 -
   2.933 -#ifndef CONFIG_XEN
   2.934 -	chip->data_buffer = kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL);
   2.935 -#else
   2.936 -	chip->data_buffer = kmalloc(get_chip_buffersize(chip) * sizeof(u8),
   2.937 -	                            GFP_KERNEL);
   2.938 -#endif
   2.939 -	if (chip->data_buffer == NULL) {
   2.940 -		chip->num_opens--;
   2.941 -		put_device(chip->dev);
   2.942 -		return -ENOMEM;
   2.943 -	}
   2.944 -
   2.945 -	atomic_set(&chip->data_pending, 0);
   2.946 -
   2.947 -	file->private_data = chip;
   2.948 -	return 0;
   2.949 -
   2.950 -err_out:
   2.951 -	spin_unlock(&driver_lock);
   2.952 -	return rc;
   2.953 -}
   2.954 -EXPORT_SYMBOL_GPL(tpm_open);
   2.955 -
   2.956 -int tpm_release(struct inode *inode, struct file *file)
   2.957 -{
   2.958 -	struct tpm_chip *chip = file->private_data;
   2.959 -
   2.960 -	spin_lock(&driver_lock);
   2.961 -	file->private_data = NULL;
   2.962 -	chip->num_opens--;
   2.963 -	del_singleshot_timer_sync(&chip->user_read_timer);
   2.964 -	flush_scheduled_work();
   2.965 -	atomic_set(&chip->data_pending, 0);
   2.966 -	put_device(chip->dev);
   2.967 -	kfree(chip->data_buffer);
   2.968 -	spin_unlock(&driver_lock);
   2.969 -	return 0;
   2.970 -}
   2.971 -EXPORT_SYMBOL_GPL(tpm_release);
   2.972 -
   2.973 -ssize_t tpm_write(struct file *file, const char __user *buf,
   2.974 -		  size_t size, loff_t *off)
   2.975 -{
   2.976 -	struct tpm_chip *chip = file->private_data;
   2.977 -	int in_size = size, out_size;
   2.978 -
   2.979 -	/* cannot perform a write until the read has cleared
   2.980 -	   either via tpm_read or a user_read_timer timeout */
   2.981 -	while (atomic_read(&chip->data_pending) != 0)
   2.982 -		msleep(TPM_TIMEOUT);
   2.983 -
   2.984 -	down(&chip->buffer_mutex);
   2.985 -
   2.986 -#ifndef CONFIG_XEN
   2.987 -	if (in_size > TPM_BUFSIZE)
   2.988 -		in_size = TPM_BUFSIZE;
   2.989 -#else
   2.990 -	if (in_size > get_chip_buffersize(chip))
   2.991 -		in_size = get_chip_buffersize(chip);
   2.992 -#endif
   2.993 -
   2.994 -	if (copy_from_user
   2.995 -	    (chip->data_buffer, (void __user *) buf, in_size)) {
   2.996 -		up(&chip->buffer_mutex);
   2.997 -		return -EFAULT;
   2.998 -	}
   2.999 -
  2.1000 -	/* atomic tpm command send and result receive */
  2.1001 -#ifndef CONFIG_XEN
  2.1002 -	out_size = tpm_transmit(chip, chip->data_buffer, TPM_BUFSIZE);
  2.1003 -#else
  2.1004 -	out_size = tpm_transmit(chip, chip->data_buffer,
  2.1005 -	                        get_chip_buffersize(chip));
  2.1006 -#endif
  2.1007 -
  2.1008 -	atomic_set(&chip->data_pending, out_size);
  2.1009 -#ifdef CONFIG_XEN
  2.1010 -	atomic_set(&chip->data_position, 0);
  2.1011 -#endif
  2.1012 -	up(&chip->buffer_mutex);
  2.1013 -
  2.1014 -	/* Set a timeout by which the reader must come claim the result */
  2.1015 -	mod_timer(&chip->user_read_timer, jiffies + (60 * HZ));
  2.1016 -
  2.1017 -	return in_size;
  2.1018 -}
  2.1019 -EXPORT_SYMBOL_GPL(tpm_write);
  2.1020 -
  2.1021 -ssize_t tpm_read(struct file *file, char __user *buf,
  2.1022 -		 size_t size, loff_t *off)
  2.1023 -{
  2.1024 -	struct tpm_chip *chip = file->private_data;
  2.1025 -	int ret_size;
  2.1026 -#ifdef CONFIG_XEN
  2.1027 -	int pos, pending = 0;
  2.1028 -#endif
  2.1029 -
  2.1030 -#ifndef CONFIG_XEN
  2.1031 -	del_singleshot_timer_sync(&chip->user_read_timer);
  2.1032 -	flush_scheduled_work();
  2.1033 -#endif
  2.1034 -	ret_size = atomic_read(&chip->data_pending);
  2.1035 -#ifndef CONFIG_XEN
  2.1036 -	atomic_set(&chip->data_pending, 0);
  2.1037 -#endif
  2.1038 -	if (ret_size > 0) {	/* relay data */
  2.1039 -		if (size < ret_size)
  2.1040 -			ret_size = size;
  2.1041 -
  2.1042 -#ifdef CONFIG_XEN
  2.1043 -		pos = atomic_read(&chip->data_position);
  2.1044 -#endif
  2.1045 -		down(&chip->buffer_mutex);
  2.1046 -#ifndef CONFIG_XEN
  2.1047 -		if (copy_to_user(buf, chip->data_buffer, ret_size))
  2.1048 -#else
  2.1049 -		if (copy_to_user(buf, &chip->data_buffer[pos], ret_size)) {
  2.1050 -#endif
  2.1051 -			ret_size = -EFAULT;
  2.1052 -#ifdef CONFIG_XEN
  2.1053 -		} else {
  2.1054 -			pending = atomic_read(&chip->data_pending) - ret_size;
  2.1055 -			if ( pending ) {
  2.1056 -				atomic_set(&chip->data_pending, pending);
  2.1057 -				atomic_set(&chip->data_position,
  2.1058 -				           pos+ret_size);
  2.1059 -			}
  2.1060 -		}
  2.1061 -#endif
  2.1062 -		up(&chip->buffer_mutex);
  2.1063 -	}
  2.1064 -
  2.1065 -#ifdef CONFIG_XEN
  2.1066 - 	if ( ret_size <= 0 || pending == 0 ) {
  2.1067 -		atomic_set(&chip->data_pending, 0);
  2.1068 -		del_singleshot_timer_sync(&chip->user_read_timer);
  2.1069 -		flush_scheduled_work();
  2.1070 -	}
  2.1071 -#endif
  2.1072 -	return ret_size;
  2.1073 -}
  2.1074 -EXPORT_SYMBOL_GPL(tpm_read);
  2.1075 -
  2.1076 -void tpm_remove_hardware(struct device *dev)
  2.1077 -{
  2.1078 -	struct tpm_chip *chip = dev_get_drvdata(dev);
  2.1079 -
  2.1080 -	if (chip == NULL) {
  2.1081 -		dev_err(dev, "No device data found\n");
  2.1082 -		return;
  2.1083 -	}
  2.1084 -
  2.1085 -	spin_lock(&driver_lock);
  2.1086 -
  2.1087 -	list_del(&chip->list);
  2.1088 -
  2.1089 -	spin_unlock(&driver_lock);
  2.1090 -
  2.1091 -	dev_set_drvdata(dev, NULL);
  2.1092 -	misc_deregister(&chip->vendor.miscdev);
  2.1093 -	kfree(chip->vendor.miscdev.name);
  2.1094 -
  2.1095 -	sysfs_remove_group(&dev->kobj, chip->vendor.attr_group);
  2.1096 -	tpm_bios_log_teardown(chip->bios_dir);
  2.1097 -
  2.1098 -	clear_bit(chip->dev_num, dev_mask);
  2.1099 -
  2.1100 -	kfree(chip);
  2.1101 -
  2.1102 -	put_device(dev);
  2.1103 -}
  2.1104 -EXPORT_SYMBOL_GPL(tpm_remove_hardware);
  2.1105 -
  2.1106 -static u8 savestate[] = {
  2.1107 -	0, 193,			/* TPM_TAG_RQU_COMMAND */
  2.1108 -	0, 0, 0, 10,		/* blob length (in bytes) */
  2.1109 -	0, 0, 0, 152		/* TPM_ORD_SaveState */
  2.1110 -};
  2.1111 -
  2.1112 -/*
  2.1113 - * We are about to suspend. Save the TPM state
  2.1114 - * so that it can be restored.
  2.1115 - */
  2.1116 -int tpm_pm_suspend(struct device *dev, pm_message_t pm_state)
  2.1117 -{
  2.1118 -	struct tpm_chip *chip = dev_get_drvdata(dev);
  2.1119 -	if (chip == NULL)
  2.1120 -		return -ENODEV;
  2.1121 -
  2.1122 -	tpm_transmit(chip, savestate, sizeof(savestate));
  2.1123 -	return 0;
  2.1124 -}
  2.1125 -EXPORT_SYMBOL_GPL(tpm_pm_suspend);
  2.1126 -
  2.1127 -/*
  2.1128 - * Resume from a power safe. The BIOS already restored
  2.1129 - * the TPM state.
  2.1130 - */
  2.1131 -int tpm_pm_resume(struct device *dev)
  2.1132 -{
  2.1133 -	struct tpm_chip *chip = dev_get_drvdata(dev);
  2.1134 -
  2.1135 -	if (chip == NULL)
  2.1136 -		return -ENODEV;
  2.1137 -
  2.1138 -	return 0;
  2.1139 -}
  2.1140 -EXPORT_SYMBOL_GPL(tpm_pm_resume);
  2.1141 -
  2.1142 -/*
  2.1143 - * Called from tpm_<specific>.c probe function only for devices 
  2.1144 - * the driver has determined it should claim.  Prior to calling
  2.1145 - * this function the specific probe function has called pci_enable_device
  2.1146 - * upon errant exit from this function specific probe function should call
  2.1147 - * pci_disable_device
  2.1148 - */
  2.1149 -struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vendor_specific
  2.1150 -				       *entry)
  2.1151 -{
  2.1152 -#define DEVNAME_SIZE 7
  2.1153 -
  2.1154 -	char *devname;
  2.1155 -	struct tpm_chip *chip;
  2.1156 -
  2.1157 -	/* Driver specific per-device data */
  2.1158 -	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  2.1159 -	if (chip == NULL)
  2.1160 -		return NULL;
  2.1161 -
  2.1162 -	init_MUTEX(&chip->buffer_mutex);
  2.1163 -	init_MUTEX(&chip->tpm_mutex);
  2.1164 -	INIT_LIST_HEAD(&chip->list);
  2.1165 -
  2.1166 -	INIT_WORK(&chip->work, timeout_work, chip);
  2.1167 -
  2.1168 -	init_timer(&chip->user_read_timer);
  2.1169 -	chip->user_read_timer.function = user_reader_timeout;
  2.1170 -	chip->user_read_timer.data = (unsigned long) chip;
  2.1171 -
  2.1172 -	memcpy(&chip->vendor, entry, sizeof(struct tpm_vendor_specific));
  2.1173 -
  2.1174 -	chip->dev_num = find_first_zero_bit(dev_mask, TPM_NUM_DEVICES);
  2.1175 -
  2.1176 -	if (chip->dev_num >= TPM_NUM_DEVICES) {
  2.1177 -		dev_err(dev, "No available tpm device numbers\n");
  2.1178 -		kfree(chip);
  2.1179 -		return NULL;
  2.1180 -	} else if (chip->dev_num == 0)
  2.1181 -		chip->vendor.miscdev.minor = TPM_MINOR;
  2.1182 -	else
  2.1183 -		chip->vendor.miscdev.minor = MISC_DYNAMIC_MINOR;
  2.1184 -
  2.1185 -	set_bit(chip->dev_num, dev_mask);
  2.1186 -
  2.1187 -	devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL);
  2.1188 -	scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num);
  2.1189 -	chip->vendor.miscdev.name = devname;
  2.1190 -
  2.1191 -	chip->vendor.miscdev.dev = dev;
  2.1192 -	chip->dev = get_device(dev);
  2.1193 -
  2.1194 -	if (misc_register(&chip->vendor.miscdev)) {
  2.1195 -		dev_err(chip->dev,
  2.1196 -			"unable to misc_register %s, minor %d\n",
  2.1197 -			chip->vendor.miscdev.name,
  2.1198 -			chip->vendor.miscdev.minor);
  2.1199 -		put_device(dev);
  2.1200 -		clear_bit(chip->dev_num, dev_mask);
  2.1201 -		kfree(chip);
  2.1202 -		kfree(devname);
  2.1203 -		return NULL;
  2.1204 -	}
  2.1205 -
  2.1206 -	spin_lock(&driver_lock);
  2.1207 -
  2.1208 -	dev_set_drvdata(dev, chip);
  2.1209 -
  2.1210 -	list_add(&chip->list, &tpm_chip_list);
  2.1211 -
  2.1212 -	spin_unlock(&driver_lock);
  2.1213 -
  2.1214 -	sysfs_create_group(&dev->kobj, chip->vendor.attr_group);
  2.1215 -
  2.1216 -	chip->bios_dir = tpm_bios_log_setup(devname);
  2.1217 -
  2.1218 -	return chip;
  2.1219 -}
  2.1220 -EXPORT_SYMBOL_GPL(tpm_register_hardware);
  2.1221 -
  2.1222 -MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
  2.1223 -MODULE_DESCRIPTION("TPM Driver");
  2.1224 -MODULE_VERSION("2.0");
  2.1225 -MODULE_LICENSE("GPL");
     3.1 --- a/linux-2.6-xen-sparse/drivers/char/tpm/tpm.h	Thu Feb 15 14:20:05 2007 +0000
     3.2 +++ b/linux-2.6-xen-sparse/drivers/char/tpm/tpm.h	Thu Feb 15 14:21:50 2007 +0000
     3.3 @@ -26,13 +26,6 @@
     3.4  #include <linux/platform_device.h>
     3.5  #include <linux/io.h>
     3.6  
     3.7 -#ifdef CONFIG_XEN
     3.8 -enum tpm_bufsize {
     3.9 -	TPM_MIN_BUFFERSIZE = 2048,
    3.10 -	TPM_MAX_BUFFERSIZE = 64 * 1024,
    3.11 -};
    3.12 -#endif
    3.13 -
    3.14  enum tpm_timeout {
    3.15  	TPM_TIMEOUT = 5,	/* msecs */
    3.16  };
    3.17 @@ -68,9 +61,6 @@ struct tpm_vendor_specific {
    3.18  	const u8 req_complete_mask;
    3.19  	const u8 req_complete_val;
    3.20  	const u8 req_canceled;
    3.21 -#ifdef CONFIG_XEN
    3.22 -	u32 buffersize;
    3.23 -#endif
    3.24  	void __iomem *iobase;		/* ioremapped address */
    3.25  	unsigned long base;		/* TPM base address */
    3.26  
    3.27 @@ -104,9 +94,6 @@ struct tpm_chip {
    3.28  	/* Data passed to and from the tpm via the read/write calls */
    3.29  	u8 *data_buffer;
    3.30  	atomic_t data_pending;
    3.31 -#ifdef CONFIG_XEN
    3.32 -	atomic_t data_position;
    3.33 -#endif
    3.34  	struct semaphore buffer_mutex;
    3.35  
    3.36  	struct timer_list user_read_timer;	/* user needs to claim result */
    3.37 @@ -138,17 +125,6 @@ static inline void tpm_write_index(int b
    3.38  }
    3.39  
    3.40  #ifdef CONFIG_XEN
    3.41 -static inline u32 get_chip_buffersize(struct tpm_chip *chip)
    3.42 -{
    3.43 -	u32 size = chip->vendor.buffersize;
    3.44 -	if (size > TPM_MAX_BUFFERSIZE) {
    3.45 -		return TPM_MAX_BUFFERSIZE;
    3.46 -	} else if (size < TPM_MIN_BUFFERSIZE) {
    3.47 -		return TPM_MIN_BUFFERSIZE;
    3.48 -	}
    3.49 -	return size;
    3.50 -}
    3.51 -
    3.52  static inline void *chip_get_private(const struct tpm_chip *chip)
    3.53  {
    3.54  	return chip->priv;
     4.1 --- a/linux-2.6-xen-sparse/drivers/char/tpm/tpm_vtpm.c	Thu Feb 15 14:20:05 2007 +0000
     4.2 +++ b/linux-2.6-xen-sparse/drivers/char/tpm/tpm_vtpm.c	Thu Feb 15 14:21:50 2007 +0000
     4.3 @@ -519,9 +519,6 @@ struct tpm_chip *init_vtpm(struct device
     4.4  	vtpms->tpmvd = tvd;
     4.5  	vtpms->tpm_private = tp;
     4.6  
     4.7 -	if (tvd)
     4.8 -		tpm_vtpm.buffersize = tvd->max_tx_size;
     4.9 -
    4.10  	chip = tpm_register_hardware(dev, &tpm_vtpm);
    4.11  	if (!chip) {
    4.12  		rc = -ENODEV;