tpm: Create a tpm_class_ops structure and use it in the drivers
authorJason Gunthorpe <jgunthorpe@obsidianresearch.com>
Tue, 26 Nov 2013 20:30:43 +0000 (13:30 -0700)
committerPeter Huewe <peterhuewe@gmx.de>
Mon, 6 Jan 2014 13:37:25 +0000 (14:37 +0100)
This replaces the static initialization of a tpm_vendor_specific
structure in the drivers with the standard Linux idiom of providing
a const structure of function pointers.

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Reviewed-by: Joel Schopp <jschopp@linux.vnet.ibm.com>
Reviewed-by: Ashley Lai <adlai@linux.vnet.ibm.com>
[phuewe: did apply manually due to commit
191ffc6bde3 tpm/tpm_i2c_atmel: fix coccinelle warnings]
Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
13 files changed:
drivers/char/tpm/tpm-interface.c
drivers/char/tpm/tpm.h
drivers/char/tpm/tpm_atmel.c
drivers/char/tpm/tpm_i2c_atmel.c
drivers/char/tpm/tpm_i2c_infineon.c
drivers/char/tpm/tpm_i2c_nuvoton.c
drivers/char/tpm/tpm_i2c_stm_st33.c
drivers/char/tpm/tpm_ibmvtpm.c
drivers/char/tpm/tpm_infineon.c
drivers/char/tpm/tpm_nsc.c
drivers/char/tpm/tpm_tis.c
drivers/char/tpm/xen-tpmfront.c
include/linux/tpm.h

index 389d483a887c7dce8d3caa8ae6d2a6d7bdc30ffd..1b012463da7c7cac8c07645c1842da42c28546a1 100644 (file)
@@ -1060,7 +1060,7 @@ static void tpm_dev_release(struct device *dev)
  * pci_disable_device
  */
 struct tpm_chip *tpm_register_hardware(struct device *dev,
-                                       const struct tpm_vendor_specific *entry)
+                                      const struct tpm_class_ops *ops)
 {
        struct tpm_chip *chip;
 
@@ -1073,7 +1073,13 @@ struct tpm_chip *tpm_register_hardware(struct device *dev,
        mutex_init(&chip->tpm_mutex);
        INIT_LIST_HEAD(&chip->list);
 
-       memcpy(&chip->vendor, entry, sizeof(struct tpm_vendor_specific));
+       chip->vendor.req_complete_mask = ops->req_complete_mask;
+       chip->vendor.req_complete_val = ops->req_complete_val;
+       chip->vendor.req_canceled = ops->req_canceled;
+       chip->vendor.recv = ops->recv;
+       chip->vendor.send = ops->send;
+       chip->vendor.cancel = ops->cancel;
+       chip->vendor.status = ops->status;
 
        chip->dev_num = find_first_zero_bit(dev_mask, TPM_NUM_DEVICES);
 
index 14ba1627d78e392b725dc3c117b37211ac9ecd38..a56af2c135183dd507388a0118118a565e717b20 100644 (file)
@@ -64,8 +64,8 @@ enum tpm_duration {
 struct tpm_chip;
 
 struct tpm_vendor_specific {
-       const u8 req_complete_mask;
-       const u8 req_complete_val;
+       u8 req_complete_mask;
+       u8 req_complete_val;
        bool (*req_canceled)(struct tpm_chip *chip, u8 status);
        void __iomem *iobase;           /* ioremapped address */
        unsigned long base;             /* TPM base address */
@@ -336,7 +336,7 @@ extern void tpm_gen_interrupt(struct tpm_chip *);
 extern int tpm_do_selftest(struct tpm_chip *);
 extern unsigned long tpm_calc_ordinal_duration(struct tpm_chip *, u32);
 extern struct tpm_chip* tpm_register_hardware(struct device *,
-                                const struct tpm_vendor_specific *);
+                                             const struct tpm_class_ops *ops);
 extern void tpm_dev_vendor_release(struct tpm_chip *);
 extern void tpm_remove_hardware(struct device *);
 extern int tpm_pm_suspend(struct device *);
index 7e665d047c93cf77009db8c12c93ff1441e1c6cc..6069d13ae4ac5ea657db7e9b22d745fea46390c7 100644 (file)
@@ -121,7 +121,7 @@ static bool tpm_atml_req_canceled(struct tpm_chip *chip, u8 status)
        return (status == ATML_STATUS_READY);
 }
 
-static const struct tpm_vendor_specific tpm_atmel = {
+static const struct tpm_class_ops tpm_atmel = {
        .recv = tpm_atml_recv,
        .send = tpm_atml_send,
        .cancel = tpm_atml_cancel,
index fe8bdce7d24fdf857c096c98bbb7432be7859ffb..77272925dee6dd1f13679acbdacc5dd8d8f73ac9 100644 (file)
@@ -140,7 +140,7 @@ static bool i2c_atmel_req_canceled(struct tpm_chip *chip, u8 status)
        return false;
 }
 
-static const struct tpm_vendor_specific i2c_atmel = {
+static const struct tpm_class_ops i2c_atmel = {
        .status = i2c_atmel_read_status,
        .recv = i2c_atmel_recv,
        .send = i2c_atmel_send,
index ac1218f41afe780510865fb4cb2145ee49396381..52b9b2b2f30045d94be453785df66e54b0cc6e0b 100644 (file)
@@ -566,7 +566,7 @@ static bool tpm_tis_i2c_req_canceled(struct tpm_chip *chip, u8 status)
        return (status == TPM_STS_COMMAND_READY);
 }
 
-static struct tpm_vendor_specific tpm_tis_i2c = {
+static const struct tpm_class_ops tpm_tis_i2c = {
        .status = tpm_tis_i2c_status,
        .recv = tpm_tis_i2c_recv,
        .send = tpm_tis_i2c_send,
index 1e6905ba0deacb9686482acf04e1b04a4ceb73f2..7b158efd49f7ad5599d96caa025921eb60e22510 100644 (file)
@@ -455,7 +455,7 @@ static bool i2c_nuvoton_req_canceled(struct tpm_chip *chip, u8 status)
        return (status == TPM_STS_COMMAND_READY);
 }
 
-static const struct tpm_vendor_specific tpm_i2c = {
+static const struct tpm_class_ops tpm_i2c = {
        .status = i2c_nuvoton_read_status,
        .recv = i2c_nuvoton_recv,
        .send = i2c_nuvoton_send,
index 6902f7b11e4814329fa24ba7518a790aa155b336..874b3be330bcaca267d1a69afa42458a35b7a70b 100644 (file)
@@ -574,7 +574,7 @@ static bool tpm_st33_i2c_req_canceled(struct tpm_chip *chip, u8 status)
        return (status == TPM_STS_COMMAND_READY);
 }
 
-static struct tpm_vendor_specific st_i2c_tpm = {
+static const struct tpm_class_ops st_i2c_tpm = {
        .send = tpm_stm_i2c_send,
        .recv = tpm_stm_i2c_recv,
        .cancel = tpm_stm_i2c_cancel,
index ff064f08b48e81b8d4bccaab34575463b4a942d0..af74c57e509094a389cccfada0bf8a9a3b3f1734 100644 (file)
@@ -403,7 +403,7 @@ static bool tpm_ibmvtpm_req_canceled(struct tpm_chip *chip, u8 status)
        return (status == 0);
 }
 
-static const struct tpm_vendor_specific tpm_ibmvtpm = {
+static const struct tpm_class_ops tpm_ibmvtpm = {
        .recv = tpm_ibmvtpm_recv,
        .send = tpm_ibmvtpm_send,
        .cancel = tpm_ibmvtpm_cancel,
index 9525be5c136c6adaf710b42280f88b36f637892c..dc0a2554034ea2fe1fc51a769d24c0d05805950a 100644 (file)
@@ -371,7 +371,7 @@ static u8 tpm_inf_status(struct tpm_chip *chip)
        return tpm_data_in(STAT);
 }
 
-static const struct tpm_vendor_specific tpm_inf = {
+static const struct tpm_class_ops tpm_inf = {
        .recv = tpm_inf_recv,
        .send = tpm_inf_send,
        .cancel = tpm_inf_cancel,
index ad980be553dc394cba60c8f49d30533513b7ae86..3179ec9cffdcbba1f3539df3474d9752b7c6599a 100644 (file)
@@ -232,7 +232,7 @@ static bool tpm_nsc_req_canceled(struct tpm_chip *chip, u8 status)
        return (status == NSC_STATUS_RDY);
 }
 
-static const struct tpm_vendor_specific tpm_nsc = {
+static const struct tpm_class_ops tpm_nsc = {
        .recv = tpm_nsc_recv,
        .send = tpm_nsc_send,
        .cancel = tpm_nsc_cancel,
index a362edec58d4203bca97be880bd575a162f33d95..8094b081a8be08327bc094ebd5be5d72de9d7f51 100644 (file)
@@ -432,7 +432,7 @@ static bool tpm_tis_req_canceled(struct tpm_chip *chip, u8 status)
        }
 }
 
-static struct tpm_vendor_specific tpm_tis = {
+static const struct tpm_class_ops tpm_tis = {
        .status = tpm_tis_status,
        .recv = tpm_tis_recv,
        .send = tpm_tis_send,
index d4f6b521344373a62c0b0e63f98365af00f0262a..92b097064df544e895cfe9de2371f393f163ab7a 100644 (file)
@@ -143,7 +143,7 @@ static int vtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
        return length;
 }
 
-static const struct tpm_vendor_specific tpm_vtpm = {
+static const struct tpm_class_ops tpm_vtpm = {
        .status = vtpm_status,
        .recv = vtpm_recv,
        .send = vtpm_send,
index 9a9051bb1a03be1ad8df3bc407ee9f8895df8a07..fff1d0976f80fe7c66ec5c260e25baf154ab79bc 100644 (file)
  */
 #define        TPM_ANY_NUM 0xFFFF
 
+struct tpm_chip;
+
+struct tpm_class_ops {
+       const u8 req_complete_mask;
+       const u8 req_complete_val;
+       bool (*req_canceled)(struct tpm_chip *chip, u8 status);
+       int (*recv) (struct tpm_chip *chip, u8 *buf, size_t len);
+       int (*send) (struct tpm_chip *chip, u8 *buf, size_t len);
+       void (*cancel) (struct tpm_chip *chip);
+       u8 (*status) (struct tpm_chip *chip);
+};
+
 #if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
 
 extern int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf);