tpm.c 13.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Copyright (C) 2004 IBM Corporation
 *
 * Authors:
 * Leendert van Doorn <leendert@watson.ibm.com>
 * Dave Safford <safford@watson.ibm.com>
 * Reiner Sailer <sailer@watson.ibm.com>
 * Kylene Hall <kjhall@us.ibm.com>
 *
 * Maintained by: <tpmdd_devel@lists.sourceforge.net>
 *
 * Device driver for TCG/TCPA TPM (trusted platform module).
 * Specifications at www.trustedcomputinggroup.org	 
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, version 2 of the
 * License.
 * 
 * Note, the TPM chip is not interrupt driven (only polling)
 * and can have very long timeouts (minutes!). Hence the unusual
22
 * calls to msleep.
L
Linus Torvalds 已提交
23 24 25 26 27 28 29 30
 *
 */

#include <linux/sched.h>
#include <linux/poll.h>
#include <linux/spinlock.h>
#include "tpm.h"

31 32 33 34 35 36
enum tpm_const {
	TPM_MINOR = 224,	/* officially assigned */
	TPM_BUFSIZE = 2048,
	TPM_NUM_DEVICES = 256,
	TPM_NUM_MASK_ENTRIES = TPM_NUM_DEVICES / (8 * sizeof(int))
};
L
Linus Torvalds 已提交
37 38 39

static LIST_HEAD(tpm_chip_list);
static DEFINE_SPINLOCK(driver_lock);
40
static int dev_mask[TPM_NUM_MASK_ENTRIES];
L
Linus Torvalds 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

static void user_reader_timeout(unsigned long ptr)
{
	struct tpm_chip *chip = (struct tpm_chip *) ptr;

	down(&chip->buffer_mutex);
	atomic_set(&chip->data_pending, 0);
	memset(chip->data_buffer, 0, TPM_BUFSIZE);
	up(&chip->buffer_mutex);
}

/*
 * Internal kernel interface to transmit TPM commands
 */
static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
			    size_t bufsiz)
{
K
Kylene Hall 已提交
58
	ssize_t rc;
L
Linus Torvalds 已提交
59
	u32 count;
60
	unsigned long stop;
L
Linus Torvalds 已提交
61

62
	count = be32_to_cpu(*((__be32 *) (buf + 2)));
L
Linus Torvalds 已提交
63 64 65 66

	if (count == 0)
		return -ENODATA;
	if (count > bufsiz) {
67
		dev_err(chip->dev,
A
Al Viro 已提交
68
			"invalid count value %x %zx \n", count, bufsiz);
L
Linus Torvalds 已提交
69 70 71 72 73
		return -E2BIG;
	}

	down(&chip->tpm_mutex);

K
Kylene Hall 已提交
74
	if ((rc = chip->vendor->send(chip, (u8 *) buf, count)) < 0) {
75
		dev_err(chip->dev,
K
Kylene Hall 已提交
76 77
			"tpm_transmit: tpm_send: error %zd\n", rc);
		goto out;
L
Linus Torvalds 已提交
78 79
	}

80
	stop = jiffies + 2 * 60 * HZ;
L
Linus Torvalds 已提交
81
	do {
82
		u8 status = chip->vendor->status(chip);
L
Linus Torvalds 已提交
83 84 85 86
		if ((status & chip->vendor->req_complete_mask) ==
		    chip->vendor->req_complete_val) {
			goto out_recv;
		}
K
Kylene Hall 已提交
87 88

		if ((status == chip->vendor->req_canceled)) {
89
			dev_err(chip->dev, "Operation Canceled\n");
K
Kylene Hall 已提交
90 91 92 93 94
			rc = -ECANCELED;
			goto out;
		}

		msleep(TPM_TIMEOUT);	/* CHECK */
L
Linus Torvalds 已提交
95
		rmb();
96
	} while (time_before(jiffies, stop));
L
Linus Torvalds 已提交
97 98 99


	chip->vendor->cancel(chip);
100
	dev_err(chip->dev, "Operation Timed out\n");
K
Kylene Hall 已提交
101 102
	rc = -ETIME;
	goto out;
L
Linus Torvalds 已提交
103 104

out_recv:
K
Kylene Hall 已提交
105 106
	rc = chip->vendor->recv(chip, (u8 *) buf, bufsiz);
	if (rc < 0)
107
		dev_err(chip->dev,
K
Kylene Hall 已提交
108 109
			"tpm_transmit: tpm_recv: error %zd\n", rc);
out:
L
Linus Torvalds 已提交
110
	up(&chip->tpm_mutex);
K
Kylene Hall 已提交
111
	return rc;
L
Linus Torvalds 已提交
112 113 114 115
}

#define TPM_DIGEST_SIZE 20
#define CAP_PCR_RESULT_SIZE 18
116
static const u8 cap_pcr[] = {
L
Linus Torvalds 已提交
117 118 119 120 121 122 123 124 125
	0, 193,			/* TPM_TAG_RQU_COMMAND */
	0, 0, 0, 22,		/* length */
	0, 0, 0, 101,		/* TPM_ORD_GetCapability */
	0, 0, 0, 5,
	0, 0, 0, 4,
	0, 0, 1, 1
};

#define READ_PCR_RESULT_SIZE 30
126
static const u8 pcrread[] = {
L
Linus Torvalds 已提交
127 128 129 130 131 132
	0, 193,			/* TPM_TAG_RQU_COMMAND */
	0, 0, 0, 14,		/* length */
	0, 0, 0, 21,		/* TPM_ORD_PcrRead */
	0, 0, 0, 0		/* PCR index */
};

133 134
ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr,
		      char *buf)
L
Linus Torvalds 已提交
135 136 137
{
	u8 data[READ_PCR_RESULT_SIZE];
	ssize_t len;
138 139
	int i, j, num_pcrs;
	__be32 index;
L
Linus Torvalds 已提交
140 141
	char *str = buf;

142
	struct tpm_chip *chip = dev_get_drvdata(dev);
L
Linus Torvalds 已提交
143 144 145 146 147
	if (chip == NULL)
		return -ENODEV;

	memcpy(data, cap_pcr, sizeof(cap_pcr));
	if ((len = tpm_transmit(chip, data, sizeof(data)))
K
Kylene Hall 已提交
148
	    < CAP_PCR_RESULT_SIZE) {
149
		dev_dbg(chip->dev, "A TPM error (%d) occurred "
K
Kylene Hall 已提交
150 151 152 153
				"attempting to determine the number of PCRS\n",
			be32_to_cpu(*((__be32 *) (data + 6))));
		return 0;
	}
L
Linus Torvalds 已提交
154

155
	num_pcrs = be32_to_cpu(*((__be32 *) (data + 14)));
L
Linus Torvalds 已提交
156 157 158 159 160 161

	for (i = 0; i < num_pcrs; i++) {
		memcpy(data, pcrread, sizeof(pcrread));
		index = cpu_to_be32(i);
		memcpy(data + 10, &index, 4);
		if ((len = tpm_transmit(chip, data, sizeof(data)))
K
Kylene Hall 已提交
162
		    < READ_PCR_RESULT_SIZE){
163
			dev_dbg(chip->dev, "A TPM error (%d) occurred"
K
Kylene Hall 已提交
164 165 166 167
				" attempting to read PCR %d of %d\n",
				be32_to_cpu(*((__be32 *) (data + 6))), i, num_pcrs);
			goto out;
		}
L
Linus Torvalds 已提交
168 169 170 171 172
		str += sprintf(str, "PCR-%02d: ", i);
		for (j = 0; j < TPM_DIGEST_SIZE; j++)
			str += sprintf(str, "%02X ", *(data + 10 + j));
		str += sprintf(str, "\n");
	}
K
Kylene Hall 已提交
173
out:
L
Linus Torvalds 已提交
174 175
	return str - buf;
}
176
EXPORT_SYMBOL_GPL(tpm_show_pcrs);
L
Linus Torvalds 已提交
177 178

#define  READ_PUBEK_RESULT_SIZE 314
179
static const u8 readpubek[] = {
L
Linus Torvalds 已提交
180 181 182 183 184
	0, 193,			/* TPM_TAG_RQU_COMMAND */
	0, 0, 0, 30,		/* length */
	0, 0, 0, 124,		/* TPM_ORD_ReadPubek */
};

185 186
ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr,
		       char *buf)
L
Linus Torvalds 已提交
187
{
K
Kylene Hall 已提交
188
	u8 *data;
L
Linus Torvalds 已提交
189
	ssize_t len;
190
	int i, rc;
L
Linus Torvalds 已提交
191 192
	char *str = buf;

193
	struct tpm_chip *chip = dev_get_drvdata(dev);
L
Linus Torvalds 已提交
194 195 196
	if (chip == NULL)
		return -ENODEV;

K
Kylene Hall 已提交
197 198 199 200
	data = kmalloc(READ_PUBEK_RESULT_SIZE, GFP_KERNEL);
	if (!data)
		return -ENOMEM;

L
Linus Torvalds 已提交
201 202 203
	memcpy(data, readpubek, sizeof(readpubek));
	memset(data + sizeof(readpubek), 0, 20);	/* zero nonce */

K
Kylene Hall 已提交
204 205
	if ((len = tpm_transmit(chip, data, READ_PUBEK_RESULT_SIZE)) <
	    READ_PUBEK_RESULT_SIZE) {
206
		dev_dbg(chip->dev, "A TPM error (%d) occurred "
K
Kylene Hall 已提交
207 208
				"attempting to read the PUBEK\n",
			    be32_to_cpu(*((__be32 *) (data + 6))));
209 210
		rc = 0;
		goto out;
K
Kylene Hall 已提交
211
	}
L
Linus Torvalds 已提交
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233

	/* 
	   ignore header 10 bytes
	   algorithm 32 bits (1 == RSA )
	   encscheme 16 bits
	   sigscheme 16 bits
	   parameters (RSA 12->bytes: keybit, #primes, expbit)  
	   keylenbytes 32 bits
	   256 byte modulus
	   ignore checksum 20 bytes
	 */

	str +=
	    sprintf(str,
		    "Algorithm: %02X %02X %02X %02X\nEncscheme: %02X %02X\n"
		    "Sigscheme: %02X %02X\nParameters: %02X %02X %02X %02X"
		    " %02X %02X %02X %02X %02X %02X %02X %02X\n"
		    "Modulus length: %d\nModulus: \n",
		    data[10], data[11], data[12], data[13], data[14],
		    data[15], data[16], data[17], data[22], data[23],
		    data[24], data[25], data[26], data[27], data[28],
		    data[29], data[30], data[31], data[32], data[33],
K
Kylene Jo Hall 已提交
234
		    be32_to_cpu(*((__be32 *) (data + 34))));
L
Linus Torvalds 已提交
235 236

	for (i = 0; i < 256; i++) {
K
Kylene Jo Hall 已提交
237
		str += sprintf(str, "%02X ", data[i + 38]);
L
Linus Torvalds 已提交
238 239 240
		if ((i + 1) % 16 == 0)
			str += sprintf(str, "\n");
	}
K
Kylene Hall 已提交
241
	rc = str - buf;
242
out:
K
Kylene Hall 已提交
243 244
	kfree(data);
	return rc;
L
Linus Torvalds 已提交
245 246
}

247
EXPORT_SYMBOL_GPL(tpm_show_pubek);
L
Linus Torvalds 已提交
248 249

#define CAP_VER_RESULT_SIZE 18
250
static const u8 cap_version[] = {
L
Linus Torvalds 已提交
251 252 253 254 255 256 257 258
	0, 193,			/* TPM_TAG_RQU_COMMAND */
	0, 0, 0, 18,		/* length */
	0, 0, 0, 101,		/* TPM_ORD_GetCapability */
	0, 0, 0, 6,
	0, 0, 0, 0
};

#define CAP_MANUFACTURER_RESULT_SIZE 18
259
static const u8 cap_manufacturer[] = {
L
Linus Torvalds 已提交
260 261 262 263 264 265 266 267
	0, 193,			/* TPM_TAG_RQU_COMMAND */
	0, 0, 0, 22,		/* length */
	0, 0, 0, 101,		/* TPM_ORD_GetCapability */
	0, 0, 0, 5,
	0, 0, 0, 4,
	0, 0, 1, 3
};

268 269
ssize_t tpm_show_caps(struct device *dev, struct device_attribute *attr,
		      char *buf)
L
Linus Torvalds 已提交
270
{
K
Kylene Hall 已提交
271
	u8 data[sizeof(cap_manufacturer)];
L
Linus Torvalds 已提交
272 273 274
	ssize_t len;
	char *str = buf;

275
	struct tpm_chip *chip = dev_get_drvdata(dev);
L
Linus Torvalds 已提交
276 277 278 279 280 281 282 283 284 285
	if (chip == NULL)
		return -ENODEV;

	memcpy(data, cap_manufacturer, sizeof(cap_manufacturer));

	if ((len = tpm_transmit(chip, data, sizeof(data))) <
	    CAP_MANUFACTURER_RESULT_SIZE)
		return len;

	str += sprintf(str, "Manufacturer: 0x%x\n",
286
		       be32_to_cpu(*((__be32 *) (data + 14))));
L
Linus Torvalds 已提交
287 288 289 290 291 292 293 294 295 296 297 298 299 300

	memcpy(data, cap_version, sizeof(cap_version));

	if ((len = tpm_transmit(chip, data, sizeof(data))) <
	    CAP_VER_RESULT_SIZE)
		return len;

	str +=
	    sprintf(str, "TCG version: %d.%d\nFirmware version: %d.%d\n",
		    (int) data[14], (int) data[15], (int) data[16],
		    (int) data[17]);

	return str - buf;
}
301 302 303 304 305 306 307 308 309 310 311 312 313
EXPORT_SYMBOL_GPL(tpm_show_caps);

ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr,
			const char *buf, size_t count)
{
	struct tpm_chip *chip = dev_get_drvdata(dev);
	if (chip == NULL)
		return 0;

	chip->vendor->cancel(chip);
	return count;
}
EXPORT_SYMBOL_GPL(tpm_store_cancel);
L
Linus Torvalds 已提交
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338


/*
 * Device file system interface to the TPM
 */
int tpm_open(struct inode *inode, struct file *file)
{
	int rc = 0, minor = iminor(inode);
	struct tpm_chip *chip = NULL, *pos;

	spin_lock(&driver_lock);

	list_for_each_entry(pos, &tpm_chip_list, list) {
		if (pos->vendor->miscdev.minor == minor) {
			chip = pos;
			break;
		}
	}

	if (chip == NULL) {
		rc = -ENODEV;
		goto err_out;
	}

	if (chip->num_opens) {
339
		dev_dbg(chip->dev,
L
Linus Torvalds 已提交
340 341 342 343 344 345
			"Another process owns this TPM\n");
		rc = -EBUSY;
		goto err_out;
	}

	chip->num_opens++;
346
	get_device(chip->dev);
L
Linus Torvalds 已提交
347 348 349 350 351 352

	spin_unlock(&driver_lock);

	chip->data_buffer = kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL);
	if (chip->data_buffer == NULL) {
		chip->num_opens--;
353
		put_device(chip->dev);
L
Linus Torvalds 已提交
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
		return -ENOMEM;
	}

	atomic_set(&chip->data_pending, 0);

	file->private_data = chip;
	return 0;

err_out:
	spin_unlock(&driver_lock);
	return rc;
}

EXPORT_SYMBOL_GPL(tpm_open);

int tpm_release(struct inode *inode, struct file *file)
{
	struct tpm_chip *chip = file->private_data;

	spin_lock(&driver_lock);
K
Kylene Hall 已提交
374
	file->private_data = NULL;
L
Linus Torvalds 已提交
375
	chip->num_opens--;
376
	del_singleshot_timer_sync(&chip->user_read_timer);
L
Linus Torvalds 已提交
377
	atomic_set(&chip->data_pending, 0);
378
	put_device(chip->dev);
K
Kylene Hall 已提交
379 380
	kfree(chip->data_buffer);
	spin_unlock(&driver_lock);
L
Linus Torvalds 已提交
381 382 383 384 385 386 387 388 389 390 391 392 393
	return 0;
}

EXPORT_SYMBOL_GPL(tpm_release);

ssize_t tpm_write(struct file * file, const char __user * buf,
		  size_t size, loff_t * off)
{
	struct tpm_chip *chip = file->private_data;
	int in_size = size, out_size;

	/* cannot perform a write until the read has cleared
	   either via tpm_read or a user_read_timer timeout */
394 395
	while (atomic_read(&chip->data_pending) != 0)
		msleep(TPM_TIMEOUT);
L
Linus Torvalds 已提交
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414

	down(&chip->buffer_mutex);

	if (in_size > TPM_BUFSIZE)
		in_size = TPM_BUFSIZE;

	if (copy_from_user
	    (chip->data_buffer, (void __user *) buf, in_size)) {
		up(&chip->buffer_mutex);
		return -EFAULT;
	}

	/* atomic tpm command send and result receive */
	out_size = tpm_transmit(chip, chip->data_buffer, TPM_BUFSIZE);

	atomic_set(&chip->data_pending, out_size);
	up(&chip->buffer_mutex);

	/* Set a timeout by which the reader must come claim the result */
415
	mod_timer(&chip->user_read_timer, jiffies + (60 * HZ));
L
Linus Torvalds 已提交
416 417 418 419 420 421 422 423 424 425

	return in_size;
}

EXPORT_SYMBOL_GPL(tpm_write);

ssize_t tpm_read(struct file * file, char __user * buf,
		 size_t size, loff_t * off)
{
	struct tpm_chip *chip = file->private_data;
426
	int ret_size;
L
Linus Torvalds 已提交
427

428 429 430 431 432 433
	del_singleshot_timer_sync(&chip->user_read_timer);
	ret_size = atomic_read(&chip->data_pending);
	atomic_set(&chip->data_pending, 0);
	if (ret_size > 0) {	/* relay data */
		if (size < ret_size)
			ret_size = size;
L
Linus Torvalds 已提交
434 435

		down(&chip->buffer_mutex);
436 437 438
		if (copy_to_user
		    ((void __user *) buf, chip->data_buffer, ret_size))
			ret_size = -EFAULT;
L
Linus Torvalds 已提交
439 440 441 442 443 444 445 446
		up(&chip->buffer_mutex);
	}

	return ret_size;
}

EXPORT_SYMBOL_GPL(tpm_read);

447
void tpm_remove_hardware(struct device *dev)
L
Linus Torvalds 已提交
448
{
449
	struct tpm_chip *chip = dev_get_drvdata(dev);
L
Linus Torvalds 已提交
450 451

	if (chip == NULL) {
452
		dev_err(dev, "No device data found\n");
L
Linus Torvalds 已提交
453 454 455 456 457 458 459 460 461
		return;
	}

	spin_lock(&driver_lock);

	list_del(&chip->list);

	spin_unlock(&driver_lock);

462
	dev_set_drvdata(dev, NULL);
L
Linus Torvalds 已提交
463
	misc_deregister(&chip->vendor->miscdev);
464
	kfree(chip->vendor->miscdev.name);
L
Linus Torvalds 已提交
465

466
	sysfs_remove_group(&dev->kobj, chip->vendor->attr_group);
L
Linus Torvalds 已提交
467

468
	dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES ] &= !(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES));
L
Linus Torvalds 已提交
469 470 471

	kfree(chip);

472
	put_device(dev);
L
Linus Torvalds 已提交
473 474
}

475
EXPORT_SYMBOL_GPL(tpm_remove_hardware);
L
Linus Torvalds 已提交
476 477 478 479 480 481 482 483 484 485 486

static u8 savestate[] = {
	0, 193,			/* TPM_TAG_RQU_COMMAND */
	0, 0, 0, 10,		/* blob length (in bytes) */
	0, 0, 0, 152		/* TPM_ORD_SaveState */
};

/*
 * We are about to suspend. Save the TPM state
 * so that it can be restored.
 */
487
int tpm_pm_suspend(struct device *dev, pm_message_t pm_state)
L
Linus Torvalds 已提交
488
{
489
	struct tpm_chip *chip = dev_get_drvdata(dev);
L
Linus Torvalds 已提交
490 491 492 493 494 495 496 497 498 499 500 501 502
	if (chip == NULL)
		return -ENODEV;

	tpm_transmit(chip, savestate, sizeof(savestate));
	return 0;
}

EXPORT_SYMBOL_GPL(tpm_pm_suspend);

/*
 * Resume from a power safe. The BIOS already restored
 * the TPM state.
 */
503
int tpm_pm_resume(struct device *dev)
L
Linus Torvalds 已提交
504
{
505
	struct tpm_chip *chip = dev_get_drvdata(dev);
L
Linus Torvalds 已提交
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521

	if (chip == NULL)
		return -ENODEV;

	return 0;
}

EXPORT_SYMBOL_GPL(tpm_pm_resume);

/*
 * Called from tpm_<specific>.c probe function only for devices 
 * the driver has determined it should claim.  Prior to calling
 * this function the specific probe function has called pci_enable_device
 * upon errant exit from this function specific probe function should call
 * pci_disable_device
 */
522
int tpm_register_hardware(struct device *dev,
L
Linus Torvalds 已提交
523 524
			  struct tpm_vendor_specific *entry)
{
525 526 527
#define DEVNAME_SIZE 7

	char *devname;
L
Linus Torvalds 已提交
528 529 530 531 532 533 534 535 536 537 538 539 540 541
	struct tpm_chip *chip;
	int i, j;

	/* Driver specific per-device data */
	chip = kmalloc(sizeof(*chip), GFP_KERNEL);
	if (chip == NULL)
		return -ENOMEM;

	memset(chip, 0, sizeof(struct tpm_chip));

	init_MUTEX(&chip->buffer_mutex);
	init_MUTEX(&chip->tpm_mutex);
	INIT_LIST_HEAD(&chip->list);

542 543 544 545
	init_timer(&chip->user_read_timer);
	chip->user_read_timer.function = user_reader_timeout;
	chip->user_read_timer.data = (unsigned long) chip;

L
Linus Torvalds 已提交
546 547 548 549
	chip->vendor = entry;

	chip->dev_num = -1;

550 551
	for (i = 0; i < TPM_NUM_MASK_ENTRIES; i++)
		for (j = 0; j < 8 * sizeof(int); j++)
L
Linus Torvalds 已提交
552
			if ((dev_mask[i] & (1 << j)) == 0) {
553 554
				chip->dev_num =
				    i * TPM_NUM_MASK_ENTRIES + j;
L
Linus Torvalds 已提交
555 556 557 558 559 560
				dev_mask[i] |= 1 << j;
				goto dev_num_search_complete;
			}

dev_num_search_complete:
	if (chip->dev_num < 0) {
561
		dev_err(dev,
L
Linus Torvalds 已提交
562 563 564 565 566 567 568 569
			"No available tpm device numbers\n");
		kfree(chip);
		return -ENODEV;
	} else if (chip->dev_num == 0)
		chip->vendor->miscdev.minor = TPM_MINOR;
	else
		chip->vendor->miscdev.minor = MISC_DYNAMIC_MINOR;

570 571
	devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL);
	scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num);
L
Linus Torvalds 已提交
572 573
	chip->vendor->miscdev.name = devname;

574 575
	chip->vendor->miscdev.dev = dev;
	chip->dev = get_device(dev);
L
Linus Torvalds 已提交
576 577

	if (misc_register(&chip->vendor->miscdev)) {
578
		dev_err(chip->dev,
L
Linus Torvalds 已提交
579 580 581
			"unable to misc_register %s, minor %d\n",
			chip->vendor->miscdev.name,
			chip->vendor->miscdev.minor);
582
		put_device(dev);
L
Linus Torvalds 已提交
583 584 585 586 587
		kfree(chip);
		dev_mask[i] &= !(1 << j);
		return -ENODEV;
	}

K
Kylene Hall 已提交
588 589
	spin_lock(&driver_lock);

590
	dev_set_drvdata(dev, chip);
L
Linus Torvalds 已提交
591 592 593

	list_add(&chip->list, &tpm_chip_list);

K
Kylene Hall 已提交
594 595
	spin_unlock(&driver_lock);

596
	sysfs_create_group(&dev->kobj, chip->vendor->attr_group);
L
Linus Torvalds 已提交
597 598 599 600 601 602 603 604 605 606

	return 0;
}

EXPORT_SYMBOL_GPL(tpm_register_hardware);

MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
MODULE_DESCRIPTION("TPM Driver");
MODULE_VERSION("2.0");
MODULE_LICENSE("GPL");