tpm.c (2a267e7c41aa88215de2b542de797d03d16ecdfd) | tpm.c (c46f3405692de1ac82240d927b9c7a0f9d6a4a36) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) 2017 Google, Inc. 4 * Thiebaud Weksteen <tweek@google.com> 5 */ 6 | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) 2017 Google, Inc. 4 * Thiebaud Weksteen <tweek@google.com> 5 */ 6 |
7#define TPM_MEMREMAP(start, size) early_memremap(start, size) 8#define TPM_MEMUNMAP(start, size) early_memunmap(start, size) 9 10#include <asm/early_ioremap.h> |
|
7#include <linux/efi.h> 8#include <linux/init.h> 9#include <linux/memblock.h> | 11#include <linux/efi.h> 12#include <linux/init.h> 13#include <linux/memblock.h> |
14#include <linux/tpm_eventlog.h> |
|
10 | 15 |
11#include <asm/early_ioremap.h> | 16int efi_tpm_final_log_size; 17EXPORT_SYMBOL(efi_tpm_final_log_size); |
12 | 18 |
19static int tpm2_calc_event_log_size(void *data, int count, void *size_info) 20{ 21 struct tcg_pcr_event2_head *header; 22 int event_size, size = 0; 23 24 while (count > 0) { 25 header = data + size; 26 event_size = __calc_tpm2_event_size(header, size_info, true); 27 if (event_size == 0) 28 return -1; 29 size += event_size; 30 count--; 31 } 32 33 return size; 34} 35 |
|
13/* 14 * Reserve the memory associated with the TPM Event Log configuration table. 15 */ 16int __init efi_tpm_eventlog_init(void) 17{ 18 struct linux_efi_tpm_eventlog *log_tbl; | 36/* 37 * Reserve the memory associated with the TPM Event Log configuration table. 38 */ 39int __init efi_tpm_eventlog_init(void) 40{ 41 struct linux_efi_tpm_eventlog *log_tbl; |
42 struct efi_tcg2_final_events_table *final_tbl; |
|
19 unsigned int tbl_size; | 43 unsigned int tbl_size; |
44 int ret = 0; |
|
20 | 45 |
21 if (efi.tpm_log == EFI_INVALID_TABLE_ADDR) | 46 if (efi.tpm_log == EFI_INVALID_TABLE_ADDR) { 47 /* 48 * We can't calculate the size of the final events without the 49 * first entry in the TPM log, so bail here. 50 */ |
22 return 0; | 51 return 0; |
52 } |
|
23 24 log_tbl = early_memremap(efi.tpm_log, sizeof(*log_tbl)); 25 if (!log_tbl) { 26 pr_err("Failed to map TPM Event Log table @ 0x%lx\n", | 53 54 log_tbl = early_memremap(efi.tpm_log, sizeof(*log_tbl)); 55 if (!log_tbl) { 56 pr_err("Failed to map TPM Event Log table @ 0x%lx\n", |
27 efi.tpm_log); | 57 efi.tpm_log); |
28 efi.tpm_log = EFI_INVALID_TABLE_ADDR; 29 return -ENOMEM; 30 } 31 32 tbl_size = sizeof(*log_tbl) + log_tbl->size; 33 memblock_reserve(efi.tpm_log, tbl_size); | 58 efi.tpm_log = EFI_INVALID_TABLE_ADDR; 59 return -ENOMEM; 60 } 61 62 tbl_size = sizeof(*log_tbl) + log_tbl->size; 63 memblock_reserve(efi.tpm_log, tbl_size); |
64 65 if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR) 66 goto out; 67 68 final_tbl = early_memremap(efi.tpm_final_log, sizeof(*final_tbl)); 69 70 if (!final_tbl) { 71 pr_err("Failed to map TPM Final Event Log table @ 0x%lx\n", 72 efi.tpm_final_log); 73 efi.tpm_final_log = EFI_INVALID_TABLE_ADDR; 74 ret = -ENOMEM; 75 goto out; 76 } 77 78 tbl_size = tpm2_calc_event_log_size((void *)efi.tpm_final_log 79 + sizeof(final_tbl->version) 80 + sizeof(final_tbl->nr_events), 81 final_tbl->nr_events, 82 log_tbl->log); 83 memblock_reserve((unsigned long)final_tbl, 84 tbl_size + sizeof(*final_tbl)); 85 early_memunmap(final_tbl, sizeof(*final_tbl)); 86 efi_tpm_final_log_size = tbl_size; 87 88out: |
|
34 early_memunmap(log_tbl, sizeof(*log_tbl)); | 89 early_memunmap(log_tbl, sizeof(*log_tbl)); |
35 return 0; | 90 return ret; |
36} 37 | 91} 92 |