Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Copyright 2012 IBM Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Author: Ashley Lai <ashleydlai@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  *         Nayna Jain <nayna@linux.vnet.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  * Maintained by: <tpmdd-devel@lists.sourceforge.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)  * Read the event log created by the firmware on PPC64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/tpm_eventlog.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "../tpm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) int tpm_read_log_of(struct tpm_chip *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	const u32 *sizep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	const u64 *basep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	struct tpm_bios_log *log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	u32 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 	u64 base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	log = &chip->log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	if (chip->dev.parent && chip->dev.parent->of_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 		np = chip->dev.parent->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	if (of_property_read_bool(np, "powered-while-suspended"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 		chip->flags |= TPM_CHIP_FLAG_ALWAYS_POWERED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	sizep = of_get_property(np, "linux,sml-size", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	basep = of_get_property(np, "linux,sml-base", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	if (sizep == NULL && basep == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	if (sizep == NULL || basep == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	 * For both vtpm/tpm, firmware has log addr and log size in big
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	 * endian format. But in case of vtpm, there is a method called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	 * sml-handover which is run during kernel init even before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	 * device tree is setup. This sml-handover function takes care
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	 * of endianness and writes to sml-base and sml-size in little
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	 * endian format. For this reason, vtpm doesn't need conversion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	 * but physical tpm needs the conversion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	    of_property_match_string(np, "compatible", "IBM,vtpm20") < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 		size = be32_to_cpup((__force __be32 *)sizep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 		base = be64_to_cpup((__force __be64 *)basep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 		size = *sizep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 		base = *basep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	if (size == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 		dev_warn(&chip->dev, "%s: Event log area empty\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 	log->bios_event_log = kmemdup(__va(base), size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	if (!log->bios_event_log)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	log->bios_event_log_end = log->bios_event_log + size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 	if (chip->flags & TPM_CHIP_FLAG_TPM2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 		return EFI_TCG2_EVENT_LOG_FORMAT_TCG_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 	return EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }