1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2012 IBM Corporation
10 * Read the event log created by the firmware on PPC64
13 #include <linux/slab.h>
15 #include <linux/tpm_eventlog.h>
20 int tpm_read_log_of(struct tpm_chip *chip)
22 struct device_node *np;
25 struct tpm_bios_log *log;
30 if (chip->dev.parent && chip->dev.parent->of_node)
31 np = chip->dev.parent->of_node;
35 if (of_property_read_bool(np, "powered-while-suspended"))
36 chip->flags |= TPM_CHIP_FLAG_ALWAYS_POWERED;
38 sizep = of_get_property(np, "linux,sml-size", NULL);
39 basep = of_get_property(np, "linux,sml-base", NULL);
40 if (sizep == NULL && basep == NULL)
42 if (sizep == NULL || basep == NULL)
46 * For both vtpm/tpm, firmware has log addr and log size in big
47 * endian format. But in case of vtpm, there is a method called
48 * sml-handover which is run during kernel init even before
49 * device tree is setup. This sml-handover function takes care
50 * of endianness and writes to sml-base and sml-size in little
51 * endian format. For this reason, vtpm doesn't need conversion
52 * but physical tpm needs the conversion.
54 if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0) {
55 size = be32_to_cpup((__force __be32 *)sizep);
56 base = be64_to_cpup((__force __be64 *)basep);
63 dev_warn(&chip->dev, "%s: Event log area empty\n", __func__);
67 log->bios_event_log = kmemdup(__va(base), size, GFP_KERNEL);
68 if (!log->bios_event_log)
71 log->bios_event_log_end = log->bios_event_log + size;
73 if (chip->flags & TPM_CHIP_FLAG_TPM2)
74 return EFI_TCG2_EVENT_LOG_FORMAT_TCG_2;
75 return EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2;