Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2012 IBM Corporation |
| 4 | * |
Ashley Lai | 1a0f1b2 | 2014-12-04 21:01:51 -0600 | [diff] [blame] | 5 | * Author: Ashley Lai <ashleydlai@gmail.com> |
Nayna Jain | 02ae1382 | 2016-11-14 05:00:54 -0500 | [diff] [blame] | 6 | * Nayna Jain <nayna@linux.vnet.ibm.com> |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 7 | * |
| 8 | * Maintained by: <tpmdd-devel@lists.sourceforge.net> |
| 9 | * |
| 10 | * Read the event log created by the firmware on PPC64 |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <linux/slab.h> |
| 14 | #include <linux/of.h> |
Thiebaud Weksteen | fd3ec36 | 2017-09-20 10:13:36 +0200 | [diff] [blame] | 15 | #include <linux/tpm_eventlog.h> |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 16 | |
Thiebaud Weksteen | 0bfb237 | 2018-04-12 12:13:48 +0200 | [diff] [blame] | 17 | #include "../tpm.h" |
Thiebaud Weksteen | 75d647f | 2018-04-12 12:13:50 +0200 | [diff] [blame] | 18 | #include "common.h" |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 19 | |
Nayna Jain | 02ae1382 | 2016-11-14 05:00:54 -0500 | [diff] [blame] | 20 | int tpm_read_log_of(struct tpm_chip *chip) |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 21 | { |
| 22 | struct device_node *np; |
| 23 | const u32 *sizep; |
Hon Ching \(Vicky\) Lo | d72c3911 | 2015-06-17 18:17:09 -0400 | [diff] [blame] | 24 | const u64 *basep; |
Nayna Jain | 748935e | 2016-11-14 05:00:52 -0500 | [diff] [blame] | 25 | struct tpm_bios_log *log; |
Nayna Jain | e46e22f | 2017-01-23 02:26:26 -0500 | [diff] [blame] | 26 | u32 size; |
| 27 | u64 base; |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 28 | |
Nayna Jain | 748935e | 2016-11-14 05:00:52 -0500 | [diff] [blame] | 29 | log = &chip->log; |
Jason Gunthorpe | 0cf577a | 2016-11-19 11:18:28 -0700 | [diff] [blame] | 30 | if (chip->dev.parent && chip->dev.parent->of_node) |
Nayna Jain | ed4fdb4 | 2016-11-14 05:00:55 -0500 | [diff] [blame] | 31 | np = chip->dev.parent->of_node; |
Colin Ian King | 79eec5b | 2016-11-15 13:27:22 +0000 | [diff] [blame] | 32 | else |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 33 | return -ENODEV; |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 34 | |
Enric Balletbo i Serra | b5d0ebc | 2017-06-27 12:27:24 +0200 | [diff] [blame] | 35 | if (of_property_read_bool(np, "powered-while-suspended")) |
| 36 | chip->flags |= TPM_CHIP_FLAG_ALWAYS_POWERED; |
| 37 | |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 38 | sizep = of_get_property(np, "linux,sml-size", NULL); |
Jason Gunthorpe | 0cf577a | 2016-11-19 11:18:28 -0700 | [diff] [blame] | 39 | basep = of_get_property(np, "linux,sml-base", NULL); |
| 40 | if (sizep == NULL && basep == NULL) |
| 41 | return -ENODEV; |
| 42 | if (sizep == NULL || basep == NULL) |
Nayna Jain | 5efae7d | 2016-11-14 05:00:56 -0500 | [diff] [blame] | 43 | return -EIO; |
| 44 | |
Nayna Jain | e46e22f | 2017-01-23 02:26:26 -0500 | [diff] [blame] | 45 | /* |
| 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. |
| 53 | */ |
| 54 | if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0) { |
Thiebaud Weksteen | 09dd144 | 2018-04-25 15:26:41 +0200 | [diff] [blame] | 55 | size = be32_to_cpup((__force __be32 *)sizep); |
| 56 | base = be64_to_cpup((__force __be64 *)basep); |
Nayna Jain | e46e22f | 2017-01-23 02:26:26 -0500 | [diff] [blame] | 57 | } else { |
| 58 | size = *sizep; |
| 59 | base = *basep; |
| 60 | } |
| 61 | |
| 62 | if (size == 0) { |
Nayna Jain | 5efae7d | 2016-11-14 05:00:56 -0500 | [diff] [blame] | 63 | dev_warn(&chip->dev, "%s: Event log area empty\n", __func__); |
| 64 | return -EIO; |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 65 | } |
| 66 | |
Ji-Hun Kim | 6979891 | 2018-05-09 09:12:36 +0900 | [diff] [blame] | 67 | log->bios_event_log = kmemdup(__va(base), size, GFP_KERNEL); |
Nayna Jain | 5efae7d | 2016-11-14 05:00:56 -0500 | [diff] [blame] | 68 | if (!log->bios_event_log) |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 69 | return -ENOMEM; |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 70 | |
Nayna Jain | e46e22f | 2017-01-23 02:26:26 -0500 | [diff] [blame] | 71 | log->bios_event_log_end = log->bios_event_log + size; |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 72 | |
Thiebaud Weksteen | 58cc1e4 | 2017-09-20 10:13:40 +0200 | [diff] [blame] | 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; |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 76 | } |