2 * Copyright (C) 2004 IBM Corporation
4 * Leendert van Doorn <leendert@watson.ibm.com>
5 * Dave Safford <safford@watson.ibm.com>
6 * Reiner Sailer <sailer@watson.ibm.com>
7 * Kylene Hall <kjhall@us.ibm.com>
9 * Copyright (C) 2013 Obsidian Research Corp
10 * Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
12 * Device file system interface to the TPM
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation, version 2 of the
20 #include <linux/slab.h>
23 static int tpm_open(struct inode *inode, struct file *file)
25 struct tpm_chip *chip;
26 struct file_priv *priv;
28 chip = container_of(inode->i_cdev, struct tpm_chip, cdev);
30 /* It's assured that the chip will be opened just once,
31 * by the check of is_open variable, which is protected
33 if (test_and_set_bit(0, &chip->is_open)) {
34 dev_dbg(&chip->dev, "Another process owns this TPM\n");
38 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
42 tpm_common_open(file, chip, priv, NULL);
47 clear_bit(0, &chip->is_open);
52 * Called on file close
54 static int tpm_release(struct inode *inode, struct file *file)
56 struct file_priv *priv = file->private_data;
58 tpm_common_release(file, priv);
59 clear_bit(0, &priv->chip->is_open);
65 const struct file_operations tpm_fops = {
69 .read = tpm_common_read,
70 .write = tpm_common_write,
71 .poll = tpm_common_poll,
72 .release = tpm_release,