Commit 90dda520 authored by Kylene Jo Hall's avatar Kylene Jo Hall Committed by Linus Torvalds

[PATCH] tpm: chip struct update

To assist with chip management and better support the possibility of having
multiple TPMs in the system of the same kind, the struct tpm_vendor_specific
member of the tpm_chip was changed from a pointer to an instance.  This patch
changes that declaration and fixes up all accesses to the structure member
except in tpm_infineon which is coming in a patch from Marcel Selhorst.
Signed-off-by: default avatarKylene Hall <kjhall@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent beed53a1
...@@ -78,7 +78,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, ...@@ -78,7 +78,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
down(&chip->tpm_mutex); down(&chip->tpm_mutex);
if ((rc = chip->vendor->send(chip, (u8 *) buf, count)) < 0) { if ((rc = chip->vendor.send(chip, (u8 *) buf, count)) < 0) {
dev_err(chip->dev, dev_err(chip->dev,
"tpm_transmit: tpm_send: error %zd\n", rc); "tpm_transmit: tpm_send: error %zd\n", rc);
goto out; goto out;
...@@ -86,13 +86,12 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, ...@@ -86,13 +86,12 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
stop = jiffies + 2 * 60 * HZ; stop = jiffies + 2 * 60 * HZ;
do { do {
u8 status = chip->vendor->status(chip); u8 status = chip->vendor.status(chip);
if ((status & chip->vendor->req_complete_mask) == if ((status & chip->vendor.req_complete_mask) ==
chip->vendor->req_complete_val) { chip->vendor.req_complete_val)
goto out_recv; goto out_recv;
}
if ((status == chip->vendor->req_canceled)) { if ((status == chip->vendor.req_canceled)) {
dev_err(chip->dev, "Operation Canceled\n"); dev_err(chip->dev, "Operation Canceled\n");
rc = -ECANCELED; rc = -ECANCELED;
goto out; goto out;
...@@ -102,14 +101,13 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, ...@@ -102,14 +101,13 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
rmb(); rmb();
} while (time_before(jiffies, stop)); } while (time_before(jiffies, stop));
chip->vendor.cancel(chip);
chip->vendor->cancel(chip);
dev_err(chip->dev, "Operation Timed out\n"); dev_err(chip->dev, "Operation Timed out\n");
rc = -ETIME; rc = -ETIME;
goto out; goto out;
out_recv: out_recv:
rc = chip->vendor->recv(chip, (u8 *) buf, bufsiz); rc = chip->vendor.recv(chip, (u8 *) buf, bufsiz);
if (rc < 0) if (rc < 0)
dev_err(chip->dev, dev_err(chip->dev,
"tpm_transmit: tpm_recv: error %zd\n", rc); "tpm_transmit: tpm_recv: error %zd\n", rc);
...@@ -340,7 +338,7 @@ ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr, ...@@ -340,7 +338,7 @@ ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr,
if (chip == NULL) if (chip == NULL)
return 0; return 0;
chip->vendor->cancel(chip); chip->vendor.cancel(chip);
return count; return count;
} }
EXPORT_SYMBOL_GPL(tpm_store_cancel); EXPORT_SYMBOL_GPL(tpm_store_cancel);
...@@ -356,7 +354,7 @@ int tpm_open(struct inode *inode, struct file *file) ...@@ -356,7 +354,7 @@ int tpm_open(struct inode *inode, struct file *file)
spin_lock(&driver_lock); spin_lock(&driver_lock);
list_for_each_entry(pos, &tpm_chip_list, list) { list_for_each_entry(pos, &tpm_chip_list, list) {
if (pos->vendor->miscdev.minor == minor) { if (pos->vendor.miscdev.minor == minor) {
chip = pos; chip = pos;
break; break;
} }
...@@ -488,14 +486,14 @@ void tpm_remove_hardware(struct device *dev) ...@@ -488,14 +486,14 @@ void tpm_remove_hardware(struct device *dev)
spin_unlock(&driver_lock); spin_unlock(&driver_lock);
dev_set_drvdata(dev, NULL); dev_set_drvdata(dev, NULL);
misc_deregister(&chip->vendor->miscdev); misc_deregister(&chip->vendor.miscdev);
kfree(chip->vendor->miscdev.name); kfree(chip->vendor.miscdev.name);
sysfs_remove_group(&dev->kobj, chip->vendor->attr_group); sysfs_remove_group(&dev->kobj, chip->vendor.attr_group);
tpm_bios_log_teardown(chip->bios_dir); tpm_bios_log_teardown(chip->bios_dir);
dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES ] &= dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES] &=
~(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES)); ~(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES));
kfree(chip); kfree(chip);
...@@ -569,7 +567,7 @@ int tpm_register_hardware(struct device *dev, struct tpm_vendor_specific *entry) ...@@ -569,7 +567,7 @@ int tpm_register_hardware(struct device *dev, struct tpm_vendor_specific *entry)
chip->user_read_timer.function = user_reader_timeout; chip->user_read_timer.function = user_reader_timeout;
chip->user_read_timer.data = (unsigned long) chip; chip->user_read_timer.data = (unsigned long) chip;
chip->vendor = entry; memcpy(&chip->vendor, entry, sizeof(struct tpm_vendor_specific));
chip->dev_num = -1; chip->dev_num = -1;
...@@ -588,22 +586,22 @@ dev_num_search_complete: ...@@ -588,22 +586,22 @@ dev_num_search_complete:
kfree(chip); kfree(chip);
return -ENODEV; return -ENODEV;
} else if (chip->dev_num == 0) } else if (chip->dev_num == 0)
chip->vendor->miscdev.minor = TPM_MINOR; chip->vendor.miscdev.minor = TPM_MINOR;
else else
chip->vendor->miscdev.minor = MISC_DYNAMIC_MINOR; chip->vendor.miscdev.minor = MISC_DYNAMIC_MINOR;
devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL); devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL);
scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num); scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num);
chip->vendor->miscdev.name = devname; chip->vendor.miscdev.name = devname;
chip->vendor->miscdev.dev = dev; chip->vendor.miscdev.dev = dev;
chip->dev = get_device(dev); chip->dev = get_device(dev);
if (misc_register(&chip->vendor->miscdev)) { if (misc_register(&chip->vendor.miscdev)) {
dev_err(chip->dev, dev_err(chip->dev,
"unable to misc_register %s, minor %d\n", "unable to misc_register %s, minor %d\n",
chip->vendor->miscdev.name, chip->vendor.miscdev.name,
chip->vendor->miscdev.minor); chip->vendor.miscdev.minor);
put_device(dev); put_device(dev);
kfree(chip); kfree(chip);
dev_mask[i] &= !(1 << j); dev_mask[i] &= !(1 << j);
...@@ -618,7 +616,7 @@ dev_num_search_complete: ...@@ -618,7 +616,7 @@ dev_num_search_complete:
spin_unlock(&driver_lock); spin_unlock(&driver_lock);
sysfs_create_group(&dev->kobj, chip->vendor->attr_group); sysfs_create_group(&dev->kobj, chip->vendor.attr_group);
chip->bios_dir = tpm_bios_log_setup(devname); chip->bios_dir = tpm_bios_log_setup(devname);
......
...@@ -81,7 +81,7 @@ struct tpm_chip { ...@@ -81,7 +81,7 @@ struct tpm_chip {
struct work_struct work; struct work_struct work;
struct semaphore tpm_mutex; /* tpm is processing */ struct semaphore tpm_mutex; /* tpm is processing */
struct tpm_vendor_specific *vendor; struct tpm_vendor_specific vendor;
struct dentry **bios_dir; struct dentry **bios_dir;
......
...@@ -47,12 +47,12 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count) ...@@ -47,12 +47,12 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
return -EIO; return -EIO;
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
status = ioread8(chip->vendor->iobase + 1); status = ioread8(chip->vendor.iobase + 1);
if ((status & ATML_STATUS_DATA_AVAIL) == 0) { if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
dev_err(chip->dev, "error reading header\n"); dev_err(chip->dev, "error reading header\n");
return -EIO; return -EIO;
} }
*buf++ = ioread8(chip->vendor->iobase); *buf++ = ioread8(chip->vendor.iobase);
} }
/* size of the data received */ /* size of the data received */
...@@ -63,7 +63,7 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count) ...@@ -63,7 +63,7 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
dev_err(chip->dev, dev_err(chip->dev,
"Recv size(%d) less than available space\n", size); "Recv size(%d) less than available space\n", size);
for (; i < size; i++) { /* clear the waiting data anyway */ for (; i < size; i++) { /* clear the waiting data anyway */
status = ioread8(chip->vendor->iobase + 1); status = ioread8(chip->vendor.iobase + 1);
if ((status & ATML_STATUS_DATA_AVAIL) == 0) { if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
dev_err(chip->dev, "error reading data\n"); dev_err(chip->dev, "error reading data\n");
return -EIO; return -EIO;
...@@ -74,16 +74,16 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count) ...@@ -74,16 +74,16 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
/* read all the data available */ /* read all the data available */
for (; i < size; i++) { for (; i < size; i++) {
status = ioread8(chip->vendor->iobase + 1); status = ioread8(chip->vendor.iobase + 1);
if ((status & ATML_STATUS_DATA_AVAIL) == 0) { if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
dev_err(chip->dev, "error reading data\n"); dev_err(chip->dev, "error reading data\n");
return -EIO; return -EIO;
} }
*buf++ = ioread8(chip->vendor->iobase); *buf++ = ioread8(chip->vendor.iobase);
} }
/* make sure data available is gone */ /* make sure data available is gone */
status = ioread8(chip->vendor->iobase + 1); status = ioread8(chip->vendor.iobase + 1);
if (status & ATML_STATUS_DATA_AVAIL) { if (status & ATML_STATUS_DATA_AVAIL) {
dev_err(chip->dev, "data available is stuck\n"); dev_err(chip->dev, "data available is stuck\n");
...@@ -100,7 +100,7 @@ static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count) ...@@ -100,7 +100,7 @@ static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count)
dev_dbg(chip->dev, "tpm_atml_send:\n"); dev_dbg(chip->dev, "tpm_atml_send:\n");
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
dev_dbg(chip->dev, "%d 0x%x(%d)\n", i, buf[i], buf[i]); dev_dbg(chip->dev, "%d 0x%x(%d)\n", i, buf[i], buf[i]);
iowrite8(buf[i], chip->vendor->iobase); iowrite8(buf[i], chip->vendor.iobase);
} }
return count; return count;
...@@ -108,12 +108,12 @@ static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count) ...@@ -108,12 +108,12 @@ static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count)
static void tpm_atml_cancel(struct tpm_chip *chip) static void tpm_atml_cancel(struct tpm_chip *chip)
{ {
iowrite8(ATML_STATUS_ABORT, chip->vendor->iobase + 1); iowrite8(ATML_STATUS_ABORT, chip->vendor.iobase + 1);
} }
static u8 tpm_atml_status(struct tpm_chip *chip) static u8 tpm_atml_status(struct tpm_chip *chip)
{ {
return ioread8(chip->vendor->iobase + 1); return ioread8(chip->vendor.iobase + 1);
} }
static struct file_operations atmel_ops = { static struct file_operations atmel_ops = {
...@@ -159,10 +159,10 @@ static void atml_plat_remove(void) ...@@ -159,10 +159,10 @@ static void atml_plat_remove(void)
struct tpm_chip *chip = dev_get_drvdata(&pdev->dev); struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
if (chip) { if (chip) {
if (chip->vendor->have_region) if (chip->vendor.have_region)
atmel_release_region(chip->vendor->base, atmel_release_region(chip->vendor.base,
chip->vendor->region_size); chip->vendor.region_size);
atmel_put_base_addr(chip->vendor); atmel_put_base_addr(chip->vendor.iobase);
tpm_remove_hardware(chip->dev); tpm_remove_hardware(chip->dev);
platform_device_unregister(pdev); platform_device_unregister(pdev);
} }
......
...@@ -71,7 +71,7 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data) ...@@ -71,7 +71,7 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data)
unsigned long stop; unsigned long stop;
/* status immediately available check */ /* status immediately available check */
*data = inb(chip->vendor->base + NSC_STATUS); *data = inb(chip->vendor.base + NSC_STATUS);
if ((*data & mask) == val) if ((*data & mask) == val)
return 0; return 0;
...@@ -79,7 +79,7 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data) ...@@ -79,7 +79,7 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data)
stop = jiffies + 10 * HZ; stop = jiffies + 10 * HZ;
do { do {
msleep(TPM_TIMEOUT); msleep(TPM_TIMEOUT);
*data = inb(chip->vendor->base + 1); *data = inb(chip->vendor.base + 1);
if ((*data & mask) == val) if ((*data & mask) == val)
return 0; return 0;
} }
...@@ -94,9 +94,9 @@ static int nsc_wait_for_ready(struct tpm_chip *chip) ...@@ -94,9 +94,9 @@ static int nsc_wait_for_ready(struct tpm_chip *chip)
unsigned long stop; unsigned long stop;
/* status immediately available check */ /* status immediately available check */
status = inb(chip->vendor->base + NSC_STATUS); status = inb(chip->vendor.base + NSC_STATUS);
if (status & NSC_STATUS_OBF) if (status & NSC_STATUS_OBF)
status = inb(chip->vendor->base + NSC_DATA); status = inb(chip->vendor.base + NSC_DATA);
if (status & NSC_STATUS_RDY) if (status & NSC_STATUS_RDY)
return 0; return 0;
...@@ -104,9 +104,9 @@ static int nsc_wait_for_ready(struct tpm_chip *chip) ...@@ -104,9 +104,9 @@ static int nsc_wait_for_ready(struct tpm_chip *chip)
stop = jiffies + 100; stop = jiffies + 100;
do { do {
msleep(TPM_TIMEOUT); msleep(TPM_TIMEOUT);
status = inb(chip->vendor->base + NSC_STATUS); status = inb(chip->vendor.base + NSC_STATUS);
if (status & NSC_STATUS_OBF) if (status & NSC_STATUS_OBF)
status = inb(chip->vendor->base + NSC_DATA); status = inb(chip->vendor.base + NSC_DATA);
if (status & NSC_STATUS_RDY) if (status & NSC_STATUS_RDY)
return 0; return 0;
} }
...@@ -132,7 +132,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count) ...@@ -132,7 +132,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
return -EIO; return -EIO;
} }
if ((data = if ((data =
inb(chip->vendor->base + NSC_DATA)) != NSC_COMMAND_NORMAL) { inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_NORMAL) {
dev_err(chip->dev, "not in normal mode (0x%x)\n", dev_err(chip->dev, "not in normal mode (0x%x)\n",
data); data);
return -EIO; return -EIO;
...@@ -148,7 +148,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count) ...@@ -148,7 +148,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
} }
if (data & NSC_STATUS_F0) if (data & NSC_STATUS_F0)
break; break;
*p = inb(chip->vendor->base + NSC_DATA); *p = inb(chip->vendor.base + NSC_DATA);
} }
if ((data & NSC_STATUS_F0) == 0 && if ((data & NSC_STATUS_F0) == 0 &&
...@@ -156,7 +156,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count) ...@@ -156,7 +156,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
dev_err(chip->dev, "F0 not set\n"); dev_err(chip->dev, "F0 not set\n");
return -EIO; return -EIO;
} }
if ((data = inb(chip->vendor->base + NSC_DATA)) != NSC_COMMAND_EOC) { if ((data = inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_EOC) {
dev_err(chip->dev, dev_err(chip->dev,
"expected end of command(0x%x)\n", data); "expected end of command(0x%x)\n", data);
return -EIO; return -EIO;
...@@ -182,7 +182,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count) ...@@ -182,7 +182,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
* fix it. Not sure why this is needed, we followed the flow * fix it. Not sure why this is needed, we followed the flow
* chart in the manual to the letter. * chart in the manual to the letter.
*/ */
outb(NSC_COMMAND_CANCEL, chip->vendor->base + NSC_COMMAND); outb(NSC_COMMAND_CANCEL, chip->vendor.base + NSC_COMMAND);
if (nsc_wait_for_ready(chip) != 0) if (nsc_wait_for_ready(chip) != 0)
return -EIO; return -EIO;
...@@ -192,7 +192,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count) ...@@ -192,7 +192,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
return -EIO; return -EIO;
} }
outb(NSC_COMMAND_NORMAL, chip->vendor->base + NSC_COMMAND); outb(NSC_COMMAND_NORMAL, chip->vendor.base + NSC_COMMAND);
if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) { if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) {
dev_err(chip->dev, "IBR timeout\n"); dev_err(chip->dev, "IBR timeout\n");
return -EIO; return -EIO;
...@@ -204,26 +204,26 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count) ...@@ -204,26 +204,26 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
"IBF timeout (while writing data)\n"); "IBF timeout (while writing data)\n");
return -EIO; return -EIO;
} }
outb(buf[i], chip->vendor->base + NSC_DATA); outb(buf[i], chip->vendor.base + NSC_DATA);
} }
if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) { if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
dev_err(chip->dev, "IBF timeout\n"); dev_err(chip->dev, "IBF timeout\n");
return -EIO; return -EIO;
} }
outb(NSC_COMMAND_EOC, chip->vendor->base + NSC_COMMAND); outb(NSC_COMMAND_EOC, chip->vendor.base + NSC_COMMAND);
return count; return count;
} }
static void tpm_nsc_cancel(struct tpm_chip *chip) static void tpm_nsc_cancel(struct tpm_chip *chip)
{ {
outb(NSC_COMMAND_CANCEL, chip->vendor->base + NSC_COMMAND); outb(NSC_COMMAND_CANCEL, chip->vendor.base + NSC_COMMAND);
} }
static u8 tpm_nsc_status(struct tpm_chip *chip) static u8 tpm_nsc_status(struct tpm_chip *chip)
{ {
return inb(chip->vendor->base + NSC_STATUS); return inb(chip->vendor.base + NSC_STATUS);
} }
static struct file_operations nsc_ops = { static struct file_operations nsc_ops = {
...@@ -268,7 +268,7 @@ static void __devexit tpm_nsc_remove(struct device *dev) ...@@ -268,7 +268,7 @@ static void __devexit tpm_nsc_remove(struct device *dev)
{ {
struct tpm_chip *chip = dev_get_drvdata(dev); struct tpm_chip *chip = dev_get_drvdata(dev);
if ( chip ) { if ( chip ) {
release_region(chip->vendor->base, 2); release_region(chip->vendor.base, 2);
tpm_remove_hardware(chip->dev); tpm_remove_hardware(chip->dev);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment