Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tpm: redefine read_log() to handle ACPI/OF at runtime

Currently, read_log() has two implementations: one for ACPI platforms
and the other for device tree(OF) based platforms. The proper one is
selected at compile time using Kconfig and #ifdef in the Makefile,
which is not the recommended approach.

This patch removes the #ifdef in the Makefile by defining a single
read_log() method, which checks for ACPI/OF event log properties at
runtime.

[jarkko.sakkinen@linux.intel.com: added tpm_ prefix to read_log*]

Suggested-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
Reviewed-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

authored by

Nayna Jain and committed by
Jarkko Sakkinen
02ae1382 f40e68ef

+44 -35
+4 -10
drivers/char/tpm/Makefile
··· 2 2 # Makefile for the kernel tpm device drivers. 3 3 # 4 4 obj-$(CONFIG_TCG_TPM) += tpm.o 5 - tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o 6 - tpm-$(CONFIG_ACPI) += tpm_ppi.o 7 - 8 - ifdef CONFIG_ACPI 9 - tpm-y += tpm_eventlog.o tpm_acpi.o 10 - else 11 - ifdef CONFIG_TCG_IBMVTPM 12 - tpm-y += tpm_eventlog.o tpm_of.o 13 - endif 14 - endif 5 + tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o \ 6 + tpm_eventlog.o 7 + tpm-$(CONFIG_ACPI) += tpm_ppi.o tpm_acpi.o 8 + tpm-$(CONFIG_OF) += tpm_of.o 15 9 obj-$(CONFIG_TCG_TIS_CORE) += tpm_tis_core.o 16 10 obj-$(CONFIG_TCG_TIS) += tpm_tis.o 17 11 obj-$(CONFIG_TCG_TIS_SPI) += tpm_tis_spi.o
+2 -7
drivers/char/tpm/tpm_acpi.c
··· 6 6 * Stefan Berger <stefanb@us.ibm.com> 7 7 * Reiner Sailer <sailer@watson.ibm.com> 8 8 * Kylene Hall <kjhall@us.ibm.com> 9 + * Nayna Jain <nayna@linux.vnet.ibm.com> 9 10 * 10 11 * Maintained by: <tpmdd-devel@lists.sourceforge.net> 11 12 * ··· 46 45 }; 47 46 48 47 /* read binary bios log */ 49 - int read_log(struct tpm_chip *chip) 48 + int tpm_read_log_acpi(struct tpm_chip *chip) 50 49 { 51 50 struct acpi_tcpa *buff; 52 51 acpi_status status; ··· 55 54 struct tpm_bios_log *log; 56 55 57 56 log = &chip->log; 58 - if (log->bios_event_log != NULL) { 59 - printk(KERN_ERR 60 - "%s: ERROR - Eventlog already initialized\n", 61 - __func__); 62 - return -EFAULT; 63 - } 64 57 65 58 /* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */ 66 59 status = acpi_get_table(ACPI_SIG_TCPA, 1,
+21 -1
drivers/char/tpm/tpm_eventlog.c
··· 356 356 .release = tpm_bios_measurements_release, 357 357 }; 358 358 359 + static int tpm_read_log(struct tpm_chip *chip) 360 + { 361 + int rc; 362 + 363 + if (chip->log.bios_event_log != NULL) { 364 + dev_dbg(&chip->dev, 365 + "%s: ERROR - event log already initialized\n", 366 + __func__); 367 + return -EFAULT; 368 + } 369 + 370 + rc = tpm_read_log_acpi(chip); 371 + if ((rc == 0) || (rc == -ENOMEM)) 372 + return rc; 373 + 374 + rc = tpm_read_log_of(chip); 375 + 376 + return rc; 377 + } 378 + 359 379 int tpm_bios_log_setup(struct tpm_chip *chip) 360 380 { 361 381 const char *name = dev_name(&chip->dev); ··· 385 365 if (chip->flags & TPM_CHIP_FLAG_TPM2) 386 366 return 0; 387 367 388 - rc = read_log(chip); 368 + rc = tpm_read_log(chip); 389 369 /* 390 370 * read_log failure means event log is not supported except for ENOMEM. 391 371 */
+15 -11
drivers/char/tpm/tpm_eventlog.h
··· 73 73 HOST_TABLE_OF_DEVICES, 74 74 }; 75 75 76 - int read_log(struct tpm_chip *chip); 77 - 78 - #if defined(CONFIG_TCG_IBMVTPM) || defined(CONFIG_TCG_IBMVTPM_MODULE) || \ 79 - defined(CONFIG_ACPI) 80 - extern int tpm_bios_log_setup(struct tpm_chip *chip); 81 - extern void tpm_bios_log_teardown(struct tpm_chip *chip); 76 + #if defined(CONFIG_ACPI) 77 + int tpm_read_log_acpi(struct tpm_chip *chip); 82 78 #else 83 - static inline int tpm_bios_log_setup(struct tpm_chip *chip) 79 + static inline int tpm_read_log_acpi(struct tpm_chip *chip) 84 80 { 85 - return 0; 86 - } 87 - static inline void tpm_bios_log_teardown(struct tpm_chip *chip) 88 - { 81 + return -ENODEV; 89 82 } 90 83 #endif 84 + #if defined(CONFIG_OF) 85 + int tpm_read_log_of(struct tpm_chip *chip); 86 + #else 87 + static inline int tpm_read_log_of(struct tpm_chip *chip) 88 + { 89 + return -ENODEV; 90 + } 91 + #endif 92 + 93 + int tpm_bios_log_setup(struct tpm_chip *chip); 94 + void tpm_bios_log_teardown(struct tpm_chip *chip); 91 95 92 96 #endif
+2 -6
drivers/char/tpm/tpm_of.c
··· 2 2 * Copyright 2012 IBM Corporation 3 3 * 4 4 * Author: Ashley Lai <ashleydlai@gmail.com> 5 + * Nayna Jain <nayna@linux.vnet.ibm.com> 5 6 * 6 7 * Maintained by: <tpmdd-devel@lists.sourceforge.net> 7 8 * ··· 21 20 #include "tpm.h" 22 21 #include "tpm_eventlog.h" 23 22 24 - int read_log(struct tpm_chip *chip) 23 + int tpm_read_log_of(struct tpm_chip *chip) 25 24 { 26 25 struct device_node *np; 27 26 const u32 *sizep; ··· 29 28 struct tpm_bios_log *log; 30 29 31 30 log = &chip->log; 32 - if (log->bios_event_log != NULL) { 33 - pr_err("%s: ERROR - Eventlog already initialized\n", __func__); 34 - return -EFAULT; 35 - } 36 - 37 31 np = of_find_node_by_name(NULL, "vtpm"); 38 32 if (!np) { 39 33 pr_err("%s: ERROR - IBMVTPM not supported\n", __func__);