drivers/firmware/efi/tpm.c

Source file repositories/reference/linux-study-clean/drivers/firmware/efi/tpm.c

File Facts

System
Linux kernel
Corpus path
drivers/firmware/efi/tpm.c
Extension
.c
Size
2872 bytes
Lines
117
Domain
Driver Families
Bucket
drivers/firmware
Inferred role
Driver Families: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) 2017 Google, Inc.
 *     Thiebaud Weksteen <tweek@google.com>
 */

#define TPM_MEMREMAP(start, size) early_memremap(start, size)
#define TPM_MEMUNMAP(start, size) early_memunmap(start, size)

#include <asm/early_ioremap.h>
#include <linux/efi.h>
#include <linux/init.h>
#include <linux/memblock.h>
#include <linux/tpm_eventlog.h>

int efi_tpm_final_log_size;
EXPORT_SYMBOL(efi_tpm_final_log_size);

static int __init tpm2_calc_event_log_size(void *data, int count, void *size_info)
{
	struct tcg_pcr_event2_head *header;
	u32 event_size, size = 0;

	while (count > 0) {
		header = data + size;
		event_size = __calc_tpm2_event_size(header, size_info, true);
		if (event_size == 0)
			return -1;
		size += event_size;
		count--;
	}

	return size;
}

/*
 * Reserve the memory associated with the TPM Event Log configuration table.
 */
int __init efi_tpm_eventlog_init(void)
{
	struct linux_efi_tpm_eventlog *log_tbl;
	struct efi_tcg2_final_events_table *final_tbl;
	unsigned int tbl_size;
	int final_tbl_size;
	int ret = 0;

	if (efi.tpm_log == EFI_INVALID_TABLE_ADDR) {
		/*
		 * We can't calculate the size of the final events without the
		 * first entry in the TPM log, so bail here.
		 */
		return 0;
	}

	log_tbl = early_memremap(efi.tpm_log, sizeof(*log_tbl));
	if (!log_tbl) {
		pr_err("Failed to map TPM Event Log table @ 0x%lx\n",
		       efi.tpm_log);
		efi.tpm_log = EFI_INVALID_TABLE_ADDR;
		return -ENOMEM;
	}

	tbl_size = sizeof(*log_tbl) + log_tbl->size;
	if (memblock_reserve(efi.tpm_log, tbl_size)) {
		pr_err("TPM Event Log memblock reserve fails (0x%lx, 0x%x)\n",
		       efi.tpm_log, tbl_size);
		ret = -ENOMEM;
		goto out;
	}

	if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR) {
		pr_info("TPM Final Events table not present\n");
		goto out;
	} else if (log_tbl->version != EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) {
		pr_warn(FW_BUG "TPM Final Events table invalid\n");
		goto out;
	}

	final_tbl = early_memremap(efi.tpm_final_log, sizeof(*final_tbl));

	if (!final_tbl) {
		pr_err("Failed to map TPM Final Event Log table @ 0x%lx\n",
		       efi.tpm_final_log);
		efi.tpm_final_log = EFI_INVALID_TABLE_ADDR;
		ret = -ENOMEM;
		goto out;
	}

	final_tbl_size = 0;
	if (final_tbl->nr_events != 0) {

Annotation

Implementation Notes