Commit 01ad1fa75dd243909d62dba25a93254b20d5fe81
Committed by
Peter Huewe
1 parent
1e3b73a957
Exists in
master
and in
16 other branches
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
- 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
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
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
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
... | ... | @@ -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); |