1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2005 IBM Corporation
6 * Seiji Munetoh <munetoh@jp.ibm.com>
7 * Stefan Berger <stefanb@us.ibm.com>
8 * Reiner Sailer <sailer@watson.ibm.com>
9 * Kylene Hall <kjhall@us.ibm.com>
10 * Nayna Jain <nayna@linux.vnet.ibm.com>
12 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
14 * Access to the event log extended by the TCG BIOS of PC platform
17 #include <linux/seq_file.h>
19 #include <linux/security.h>
20 #include <linux/module.h>
21 #include <linux/slab.h>
22 #include <linux/acpi.h>
23 #include <linux/tpm_eventlog.h>
29 struct acpi_table_header hdr;
33 u32 log_max_len __packed;
34 u64 log_start_addr __packed;
38 u64 log_max_len __packed;
39 u64 log_start_addr __packed;
44 /* Check that the given log is indeed a TPM2 log. */
45 static bool tpm_is_tpm2_log(void *bios_event_log, u64 len)
47 struct tcg_efi_specid_event_head *efispecid;
48 struct tcg_pcr_event *event_header;
51 if (len < sizeof(*event_header))
53 len -= sizeof(*event_header);
54 event_header = bios_event_log;
56 if (len < sizeof(*efispecid))
58 efispecid = (struct tcg_efi_specid_event_head *)event_header->event;
60 n = memcmp(efispecid->signature, TCG_SPECID_SIG,
61 sizeof(TCG_SPECID_SIG));
65 /* read binary bios log */
66 int tpm_read_log_acpi(struct tpm_chip *chip)
68 struct acpi_tcpa *buff;
72 struct tpm_bios_log *log;
73 struct acpi_table_tpm2 *tbl;
74 struct acpi_tpm2_phy *tpm2_phy;
80 /* Unfortuntely ACPI does not associate the event log with a specific
81 * TPM, like PPI. Thus all ACPI TPMs will read the same log.
83 if (!chip->acpi_dev_handle)
86 if (chip->flags & TPM_CHIP_FLAG_TPM2) {
87 status = acpi_get_table("TPM2", 1,
88 (struct acpi_table_header **)&tbl);
89 if (ACPI_FAILURE(status))
92 if (tbl->header.length <
93 sizeof(*tbl) + sizeof(struct acpi_tpm2_phy))
96 tpm2_phy = (void *)tbl + sizeof(*tbl);
97 len = tpm2_phy->log_area_minimum_length;
99 start = tpm2_phy->log_area_start_address;
103 format = EFI_TCG2_EVENT_LOG_FORMAT_TCG_2;
105 /* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */
106 status = acpi_get_table(ACPI_SIG_TCPA, 1,
107 (struct acpi_table_header **)&buff);
108 if (ACPI_FAILURE(status))
111 switch (buff->platform_class) {
113 len = buff->server.log_max_len;
114 start = buff->server.log_start_addr;
118 len = buff->client.log_max_len;
119 start = buff->client.log_start_addr;
123 format = EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2;
126 dev_warn(&chip->dev, "%s: TCPA log area empty\n", __func__);
130 /* malloc EventLog space */
131 log->bios_event_log = kmalloc(len, GFP_KERNEL);
132 if (!log->bios_event_log)
135 log->bios_event_log_end = log->bios_event_log + len;
138 virt = acpi_os_map_iomem(start, len);
142 memcpy_fromio(log->bios_event_log, virt, len);
144 acpi_os_unmap_iomem(virt, len);
146 if (chip->flags & TPM_CHIP_FLAG_TPM2 &&
147 !tpm_is_tpm2_log(log->bios_event_log, len)) {
148 /* try EFI log next */
156 kfree(log->bios_event_log);
157 log->bios_event_log = NULL;