Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/agpgart
[pandora-kernel.git] / drivers / char / tpm / tpm.c
index 049d128..303f158 100644 (file)
@@ -64,7 +64,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
        if (count == 0)
                return -ENODATA;
        if (count > bufsiz) {
-               dev_err(&chip->pci_dev->dev,
+               dev_err(chip->dev,
                        "invalid count value %x %zx \n", count, bufsiz);
                return -E2BIG;
        }
@@ -72,21 +72,21 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
        down(&chip->tpm_mutex);
 
        if ((rc = chip->vendor->send(chip, (u8 *) buf, count)) < 0) {
-               dev_err(&chip->pci_dev->dev,
+               dev_err(chip->dev,
                        "tpm_transmit: tpm_send: error %zd\n", rc);
                goto out;
        }
 
        stop = jiffies + 2 * 60 * HZ;
        do {
-               u8 status = inb(chip->vendor->base + 1);
+               u8 status = chip->vendor->status(chip);
                if ((status & chip->vendor->req_complete_mask) ==
                    chip->vendor->req_complete_val) {
                        goto out_recv;
                }
 
                if ((status == chip->vendor->req_canceled)) {
-                       dev_err(&chip->pci_dev->dev, "Operation Canceled\n");
+                       dev_err(chip->dev, "Operation Canceled\n");
                        rc = -ECANCELED;
                        goto out;
                }
@@ -97,14 +97,14 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
 
 
        chip->vendor->cancel(chip);
-       dev_err(&chip->pci_dev->dev, "Operation Timed out\n");
+       dev_err(chip->dev, "Operation Timed out\n");
        rc = -ETIME;
        goto out;
 
 out_recv:
        rc = chip->vendor->recv(chip, (u8 *) buf, bufsiz);
        if (rc < 0)
-               dev_err(&chip->pci_dev->dev,
+               dev_err(chip->dev,
                        "tpm_transmit: tpm_recv: error %zd\n", rc);
 out:
        up(&chip->tpm_mutex);
@@ -139,15 +139,14 @@ ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr,
        __be32 index;
        char *str = buf;
 
-       struct tpm_chip *chip =
-           pci_get_drvdata(to_pci_dev(dev));
+       struct tpm_chip *chip = dev_get_drvdata(dev);
        if (chip == NULL)
                return -ENODEV;
 
        memcpy(data, cap_pcr, sizeof(cap_pcr));
        if ((len = tpm_transmit(chip, data, sizeof(data)))
            < CAP_PCR_RESULT_SIZE) {
-               dev_dbg(&chip->pci_dev->dev, "A TPM error (%d) occurred "
+               dev_dbg(chip->dev, "A TPM error (%d) occurred "
                                "attempting to determine the number of PCRS\n",
                        be32_to_cpu(*((__be32 *) (data + 6))));
                return 0;
@@ -161,9 +160,10 @@ ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr,
                memcpy(data + 10, &index, 4);
                if ((len = tpm_transmit(chip, data, sizeof(data)))
                    < READ_PCR_RESULT_SIZE){
-                       dev_dbg(&chip->pci_dev->dev, "A TPM error (%d) occurred"
+                       dev_dbg(chip->dev, "A TPM error (%d) occurred"
                                " attempting to read PCR %d of %d\n",
-                               be32_to_cpu(*((__be32 *) (data + 6))), i, num_pcrs);
+                               be32_to_cpu(*((__be32 *) (data + 6))),
+                               i, num_pcrs);
                        goto out;
                }
                str += sprintf(str, "PCR-%02d: ", i);
@@ -191,21 +191,19 @@ ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr,
        int i, rc;
        char *str = buf;
 
-       struct tpm_chip *chip =
-           pci_get_drvdata(to_pci_dev(dev));
+       struct tpm_chip *chip = dev_get_drvdata(dev);
        if (chip == NULL)
                return -ENODEV;
 
-       data = kmalloc(READ_PUBEK_RESULT_SIZE, GFP_KERNEL);
+       data = kzalloc(READ_PUBEK_RESULT_SIZE, GFP_KERNEL);
        if (!data)
                return -ENOMEM;
 
        memcpy(data, readpubek, sizeof(readpubek));
-       memset(data + sizeof(readpubek), 0, 20);        /* zero nonce */
 
        if ((len = tpm_transmit(chip, data, READ_PUBEK_RESULT_SIZE)) <
            READ_PUBEK_RESULT_SIZE) {
-               dev_dbg(&chip->pci_dev->dev, "A TPM error (%d) occurred "
+               dev_dbg(chip->dev, "A TPM error (%d) occurred "
                                "attempting to read the PUBEK\n",
                            be32_to_cpu(*((__be32 *) (data + 6))));
                rc = 0;
@@ -245,7 +243,6 @@ out:
        kfree(data);
        return rc;
 }
-
 EXPORT_SYMBOL_GPL(tpm_show_pubek);
 
 #define CAP_VER_RESULT_SIZE 18
@@ -274,8 +271,7 @@ ssize_t tpm_show_caps(struct device *dev, struct device_attribute *attr,
        ssize_t len;
        char *str = buf;
 
-       struct tpm_chip *chip =
-           pci_get_drvdata(to_pci_dev(dev));
+       struct tpm_chip *chip = dev_get_drvdata(dev);
        if (chip == NULL)
                return -ENODEV;
 
@@ -315,7 +311,6 @@ ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr,
 }
 EXPORT_SYMBOL_GPL(tpm_store_cancel);
 
-
 /*
  * Device file system interface to the TPM
  */
@@ -339,21 +334,20 @@ int tpm_open(struct inode *inode, struct file *file)
        }
 
        if (chip->num_opens) {
-               dev_dbg(&chip->pci_dev->dev,
-                       "Another process owns this TPM\n");
+               dev_dbg(chip->dev, "Another process owns this TPM\n");
                rc = -EBUSY;
                goto err_out;
        }
 
        chip->num_opens++;
-       pci_dev_get(chip->pci_dev);
+       get_device(chip->dev);
 
        spin_unlock(&driver_lock);
 
        chip->data_buffer = kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL);
        if (chip->data_buffer == NULL) {
                chip->num_opens--;
-               pci_dev_put(chip->pci_dev);
+               put_device(chip->dev);
                return -ENOMEM;
        }
 
@@ -366,7 +360,6 @@ err_out:
        spin_unlock(&driver_lock);
        return rc;
 }
-
 EXPORT_SYMBOL_GPL(tpm_open);
 
 int tpm_release(struct inode *inode, struct file *file)
@@ -378,15 +371,14 @@ int tpm_release(struct inode *inode, struct file *file)
        chip->num_opens--;
        del_singleshot_timer_sync(&chip->user_read_timer);
        atomic_set(&chip->data_pending, 0);
-       pci_dev_put(chip->pci_dev);
+       put_device(chip->dev);
        kfree(chip->data_buffer);
        spin_unlock(&driver_lock);
        return 0;
 }
-
 EXPORT_SYMBOL_GPL(tpm_release);
 
-ssize_t tpm_write(struct file * file, const char __user * buf,
+ssize_t tpm_write(struct file *file, const char __user *buf,
                  size_t size, loff_t * off)
 {
        struct tpm_chip *chip = file->private_data;
@@ -422,7 +414,7 @@ ssize_t tpm_write(struct file * file, const char __user * buf,
 
 EXPORT_SYMBOL_GPL(tpm_write);
 
-ssize_t tpm_read(struct file * file, char __user * buf,
+ssize_t tpm_read(struct file * file, char __user *buf,
                 size_t size, loff_t * off)
 {
        struct tpm_chip *chip = file->private_data;
@@ -444,15 +436,14 @@ ssize_t tpm_read(struct file * file, char __user * buf,
 
        return ret_size;
 }
-
 EXPORT_SYMBOL_GPL(tpm_read);
 
-void __devexit tpm_remove(struct pci_dev *pci_dev)
+void tpm_remove_hardware(struct device *dev)
 {
-       struct tpm_chip *chip = pci_get_drvdata(pci_dev);
+       struct tpm_chip *chip = dev_get_drvdata(dev);
 
        if (chip == NULL) {
-               dev_err(&pci_dev->dev, "No device data found\n");
+               dev_err(dev, "No device data found\n");
                return;
        }
 
@@ -462,22 +453,20 @@ void __devexit tpm_remove(struct pci_dev *pci_dev)
 
        spin_unlock(&driver_lock);
 
-       pci_set_drvdata(pci_dev, NULL);
+       dev_set_drvdata(dev, NULL);
        misc_deregister(&chip->vendor->miscdev);
        kfree(chip->vendor->miscdev.name);
 
-       sysfs_remove_group(&pci_dev->dev.kobj, chip->vendor->attr_group);
+       sysfs_remove_group(&dev->kobj, chip->vendor->attr_group);
 
-       pci_disable_device(pci_dev);
-
-       dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES ] &= !(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES));
+       dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES ] &=
+               !(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES));
 
        kfree(chip);
 
-       pci_dev_put(pci_dev);
+       put_device(dev);
 }
-
-EXPORT_SYMBOL_GPL(tpm_remove);
+EXPORT_SYMBOL_GPL(tpm_remove_hardware);
 
 static u8 savestate[] = {
        0, 193,                 /* TPM_TAG_RQU_COMMAND */
@@ -489,32 +478,30 @@ static u8 savestate[] = {
  * We are about to suspend. Save the TPM state
  * so that it can be restored.
  */
-int tpm_pm_suspend(struct pci_dev *pci_dev, pm_message_t pm_state)
+int tpm_pm_suspend(struct device *dev, pm_message_t pm_state)
 {
-       struct tpm_chip *chip = pci_get_drvdata(pci_dev);
+       struct tpm_chip *chip = dev_get_drvdata(dev);
        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.
  */
-int tpm_pm_resume(struct pci_dev *pci_dev)
+int tpm_pm_resume(struct device *dev)
 {
-       struct tpm_chip *chip = pci_get_drvdata(pci_dev);
+       struct tpm_chip *chip = dev_get_drvdata(dev);
 
        if (chip == NULL)
                return -ENODEV;
 
        return 0;
 }
-
 EXPORT_SYMBOL_GPL(tpm_pm_resume);
 
 /*
@@ -524,8 +511,7 @@ EXPORT_SYMBOL_GPL(tpm_pm_resume);
  * upon errant exit from this function specific probe function should call
  * pci_disable_device
  */
-int tpm_register_hardware(struct pci_dev *pci_dev,
-                         struct tpm_vendor_specific *entry)
+int tpm_register_hardware(struct device *dev, struct tpm_vendor_specific *entry)
 {
 #define DEVNAME_SIZE 7
 
@@ -534,12 +520,10 @@ int tpm_register_hardware(struct pci_dev *pci_dev,
        int i, j;
 
        /* Driver specific per-device data */
-       chip = kmalloc(sizeof(*chip), GFP_KERNEL);
+       chip = kzalloc(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);
@@ -563,8 +547,7 @@ int tpm_register_hardware(struct pci_dev *pci_dev,
 
 dev_num_search_complete:
        if (chip->dev_num < 0) {
-               dev_err(&pci_dev->dev,
-                       "No available tpm device numbers\n");
+               dev_err(dev, "No available tpm device numbers\n");
                kfree(chip);
                return -ENODEV;
        } else if (chip->dev_num == 0)
@@ -576,15 +559,15 @@ dev_num_search_complete:
        scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num);
        chip->vendor->miscdev.name = devname;
 
-       chip->vendor->miscdev.dev = &(pci_dev->dev);
-       chip->pci_dev = pci_dev_get(pci_dev);
+       chip->vendor->miscdev.dev = dev;
+       chip->dev = get_device(dev);
 
        if (misc_register(&chip->vendor->miscdev)) {
-               dev_err(&chip->pci_dev->dev,
+               dev_err(chip->dev,
                        "unable to misc_register %s, minor %d\n",
                        chip->vendor->miscdev.name,
                        chip->vendor->miscdev.minor);
-               pci_dev_put(pci_dev);
+               put_device(dev);
                kfree(chip);
                dev_mask[i] &= !(1 << j);
                return -ENODEV;
@@ -592,17 +575,16 @@ dev_num_search_complete:
 
        spin_lock(&driver_lock);
 
-       pci_set_drvdata(pci_dev, chip);
+       dev_set_drvdata(dev, chip);
 
        list_add(&chip->list, &tpm_chip_list);
 
        spin_unlock(&driver_lock);
 
-       sysfs_create_group(&pci_dev->dev.kobj, chip->vendor->attr_group);
+       sysfs_create_group(&dev->kobj, chip->vendor->attr_group);
 
        return 0;
 }
-
 EXPORT_SYMBOL_GPL(tpm_register_hardware);
 
 MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");