Commit 01ad1fa75dd243909d62dba25a93254b20d5fe81

Authored by Jason Gunthorpe
Committed by Peter Huewe
1 parent 1e3b73a957

tpm: Create a tpm_class_ops structure and use it in the drivers

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>

Showing 13 changed files with 33 additions and 15 deletions Side-by-side Diff

drivers/char/tpm/tpm-interface.c
... ... @@ -1060,7 +1060,7 @@
1060 1060 * pci_disable_device
1061 1061 */
1062 1062 struct tpm_chip *tpm_register_hardware(struct device *dev,
1063   - const struct tpm_vendor_specific *entry)
  1063 + const struct tpm_class_ops *ops)
1064 1064 {
1065 1065 struct tpm_chip *chip;
1066 1066  
... ... @@ -1073,7 +1073,13 @@
1073 1073 mutex_init(&chip->tpm_mutex);
1074 1074 INIT_LIST_HEAD(&chip->list);
1075 1075  
1076   - memcpy(&chip->vendor, entry, sizeof(struct tpm_vendor_specific));
  1076 + chip->vendor.req_complete_mask = ops->req_complete_mask;
  1077 + chip->vendor.req_complete_val = ops->req_complete_val;
  1078 + chip->vendor.req_canceled = ops->req_canceled;
  1079 + chip->vendor.recv = ops->recv;
  1080 + chip->vendor.send = ops->send;
  1081 + chip->vendor.cancel = ops->cancel;
  1082 + chip->vendor.status = ops->status;
1077 1083  
1078 1084 chip->dev_num = find_first_zero_bit(dev_mask, TPM_NUM_DEVICES);
1079 1085  
drivers/char/tpm/tpm.h
... ... @@ -64,8 +64,8 @@
64 64 struct tpm_chip;
65 65  
66 66 struct tpm_vendor_specific {
67   - const u8 req_complete_mask;
68   - const u8 req_complete_val;
  67 + u8 req_complete_mask;
  68 + u8 req_complete_val;
69 69 bool (*req_canceled)(struct tpm_chip *chip, u8 status);
70 70 void __iomem *iobase; /* ioremapped address */
71 71 unsigned long base; /* TPM base address */
... ... @@ -336,7 +336,7 @@
336 336 extern int tpm_do_selftest(struct tpm_chip *);
337 337 extern unsigned long tpm_calc_ordinal_duration(struct tpm_chip *, u32);
338 338 extern struct tpm_chip* tpm_register_hardware(struct device *,
339   - const struct tpm_vendor_specific *);
  339 + const struct tpm_class_ops *ops);
340 340 extern void tpm_dev_vendor_release(struct tpm_chip *);
341 341 extern void tpm_remove_hardware(struct device *);
342 342 extern int tpm_pm_suspend(struct device *);
drivers/char/tpm/tpm_atmel.c
... ... @@ -121,7 +121,7 @@
121 121 return (status == ATML_STATUS_READY);
122 122 }
123 123  
124   -static const struct tpm_vendor_specific tpm_atmel = {
  124 +static const struct tpm_class_ops tpm_atmel = {
125 125 .recv = tpm_atml_recv,
126 126 .send = tpm_atml_send,
127 127 .cancel = tpm_atml_cancel,
drivers/char/tpm/tpm_i2c_atmel.c
... ... @@ -140,7 +140,7 @@
140 140 return false;
141 141 }
142 142  
143   -static const struct tpm_vendor_specific i2c_atmel = {
  143 +static const struct tpm_class_ops i2c_atmel = {
144 144 .status = i2c_atmel_read_status,
145 145 .recv = i2c_atmel_recv,
146 146 .send = i2c_atmel_send,
drivers/char/tpm/tpm_i2c_infineon.c
... ... @@ -566,7 +566,7 @@
566 566 return (status == TPM_STS_COMMAND_READY);
567 567 }
568 568  
569   -static struct tpm_vendor_specific tpm_tis_i2c = {
  569 +static const struct tpm_class_ops tpm_tis_i2c = {
570 570 .status = tpm_tis_i2c_status,
571 571 .recv = tpm_tis_i2c_recv,
572 572 .send = tpm_tis_i2c_send,
drivers/char/tpm/tpm_i2c_nuvoton.c
... ... @@ -455,7 +455,7 @@
455 455 return (status == TPM_STS_COMMAND_READY);
456 456 }
457 457  
458   -static const struct tpm_vendor_specific tpm_i2c = {
  458 +static const struct tpm_class_ops tpm_i2c = {
459 459 .status = i2c_nuvoton_read_status,
460 460 .recv = i2c_nuvoton_recv,
461 461 .send = i2c_nuvoton_send,
drivers/char/tpm/tpm_i2c_stm_st33.c
... ... @@ -574,7 +574,7 @@
574 574 return (status == TPM_STS_COMMAND_READY);
575 575 }
576 576  
577   -static struct tpm_vendor_specific st_i2c_tpm = {
  577 +static const struct tpm_class_ops st_i2c_tpm = {
578 578 .send = tpm_stm_i2c_send,
579 579 .recv = tpm_stm_i2c_recv,
580 580 .cancel = tpm_stm_i2c_cancel,
drivers/char/tpm/tpm_ibmvtpm.c
... ... @@ -403,7 +403,7 @@
403 403 return (status == 0);
404 404 }
405 405  
406   -static const struct tpm_vendor_specific tpm_ibmvtpm = {
  406 +static const struct tpm_class_ops tpm_ibmvtpm = {
407 407 .recv = tpm_ibmvtpm_recv,
408 408 .send = tpm_ibmvtpm_send,
409 409 .cancel = tpm_ibmvtpm_cancel,
drivers/char/tpm/tpm_infineon.c
... ... @@ -371,7 +371,7 @@
371 371 return tpm_data_in(STAT);
372 372 }
373 373  
374   -static const struct tpm_vendor_specific tpm_inf = {
  374 +static const struct tpm_class_ops tpm_inf = {
375 375 .recv = tpm_inf_recv,
376 376 .send = tpm_inf_send,
377 377 .cancel = tpm_inf_cancel,
drivers/char/tpm/tpm_nsc.c
... ... @@ -232,7 +232,7 @@
232 232 return (status == NSC_STATUS_RDY);
233 233 }
234 234  
235   -static const struct tpm_vendor_specific tpm_nsc = {
  235 +static const struct tpm_class_ops tpm_nsc = {
236 236 .recv = tpm_nsc_recv,
237 237 .send = tpm_nsc_send,
238 238 .cancel = tpm_nsc_cancel,
drivers/char/tpm/tpm_tis.c
... ... @@ -432,7 +432,7 @@
432 432 }
433 433 }
434 434  
435   -static struct tpm_vendor_specific tpm_tis = {
  435 +static const struct tpm_class_ops tpm_tis = {
436 436 .status = tpm_tis_status,
437 437 .recv = tpm_tis_recv,
438 438 .send = tpm_tis_send,
drivers/char/tpm/xen-tpmfront.c
... ... @@ -143,7 +143,7 @@
143 143 return length;
144 144 }
145 145  
146   -static const struct tpm_vendor_specific tpm_vtpm = {
  146 +static const struct tpm_class_ops tpm_vtpm = {
147 147 .status = vtpm_status,
148 148 .recv = vtpm_recv,
149 149 .send = vtpm_send,
... ... @@ -29,6 +29,18 @@
29 29 */
30 30 #define TPM_ANY_NUM 0xFFFF
31 31  
  32 +struct tpm_chip;
  33 +
  34 +struct tpm_class_ops {
  35 + const u8 req_complete_mask;
  36 + const u8 req_complete_val;
  37 + bool (*req_canceled)(struct tpm_chip *chip, u8 status);
  38 + int (*recv) (struct tpm_chip *chip, u8 *buf, size_t len);
  39 + int (*send) (struct tpm_chip *chip, u8 *buf, size_t len);
  40 + void (*cancel) (struct tpm_chip *chip);
  41 + u8 (*status) (struct tpm_chip *chip);
  42 +};
  43 +
32 44 #if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
33 45  
34 46 extern int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf);