Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005 IBM Corporation |
| 3 | * |
| 4 | * Authors: |
| 5 | * Seiji Munetoh <munetoh@jp.ibm.com> |
| 6 | * Stefan Berger <stefanb@us.ibm.com> |
| 7 | * Reiner Sailer <sailer@watson.ibm.com> |
| 8 | * Kylene Hall <kjhall@us.ibm.com> |
Nayna Jain | 02ae1382 | 2016-11-14 05:00:54 -0500 | [diff] [blame] | 9 | * Nayna Jain <nayna@linux.vnet.ibm.com> |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 10 | * |
| 11 | * Maintained by: <tpmdd-devel@lists.sourceforge.net> |
| 12 | * |
Nayna Jain | 748935e | 2016-11-14 05:00:52 -0500 | [diff] [blame] | 13 | * Access to the event log extended by the TCG BIOS of PC platform |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 14 | * |
| 15 | * This program is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU General Public License |
| 17 | * as published by the Free Software Foundation; either version |
| 18 | * 2 of the License, or (at your option) any later version. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <linux/seq_file.h> |
| 23 | #include <linux/fs.h> |
| 24 | #include <linux/security.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/slab.h> |
Lv Zheng | 8b48463 | 2013-12-03 08:49:16 +0800 | [diff] [blame] | 27 | #include <linux/acpi.h> |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 28 | |
| 29 | #include "tpm.h" |
| 30 | #include "tpm_eventlog.h" |
| 31 | |
| 32 | struct acpi_tcpa { |
| 33 | struct acpi_table_header hdr; |
| 34 | u16 platform_class; |
| 35 | union { |
| 36 | struct client_hdr { |
Jason Gunthorpe | 348df8d | 2012-11-21 13:56:45 -0700 | [diff] [blame] | 37 | u32 log_max_len __packed; |
| 38 | u64 log_start_addr __packed; |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 39 | } client; |
| 40 | struct server_hdr { |
| 41 | u16 reserved; |
Jason Gunthorpe | 348df8d | 2012-11-21 13:56:45 -0700 | [diff] [blame] | 42 | u64 log_max_len __packed; |
| 43 | u64 log_start_addr __packed; |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 44 | } server; |
| 45 | }; |
| 46 | }; |
| 47 | |
| 48 | /* read binary bios log */ |
Nayna Jain | 02ae1382 | 2016-11-14 05:00:54 -0500 | [diff] [blame] | 49 | int tpm_read_log_acpi(struct tpm_chip *chip) |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 50 | { |
| 51 | struct acpi_tcpa *buff; |
| 52 | acpi_status status; |
Kent Yoder | a40695e | 2012-09-04 11:18:21 -0500 | [diff] [blame] | 53 | void __iomem *virt; |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 54 | u64 len, start; |
Nayna Jain | 748935e | 2016-11-14 05:00:52 -0500 | [diff] [blame] | 55 | struct tpm_bios_log *log; |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 56 | |
Nayna Jain | 4d23cc3 | 2017-01-23 02:26:27 -0500 | [diff] [blame] | 57 | if (chip->flags & TPM_CHIP_FLAG_TPM2) |
| 58 | return -ENODEV; |
| 59 | |
Nayna Jain | 748935e | 2016-11-14 05:00:52 -0500 | [diff] [blame] | 60 | log = &chip->log; |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 61 | |
Jason Gunthorpe | 0cf577a | 2016-11-19 11:18:28 -0700 | [diff] [blame] | 62 | /* Unfortuntely ACPI does not associate the event log with a specific |
| 63 | * TPM, like PPI. Thus all ACPI TPMs will read the same log. |
| 64 | */ |
| 65 | if (!chip->acpi_dev_handle) |
| 66 | return -ENODEV; |
| 67 | |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 68 | /* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */ |
| 69 | status = acpi_get_table(ACPI_SIG_TCPA, 1, |
| 70 | (struct acpi_table_header **)&buff); |
| 71 | |
Nayna Jain | 5efae7d | 2016-11-14 05:00:56 -0500 | [diff] [blame] | 72 | if (ACPI_FAILURE(status)) |
Jason Gunthorpe | 0cf577a | 2016-11-19 11:18:28 -0700 | [diff] [blame] | 73 | return -ENODEV; |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 74 | |
| 75 | switch(buff->platform_class) { |
| 76 | case BIOS_SERVER: |
| 77 | len = buff->server.log_max_len; |
| 78 | start = buff->server.log_start_addr; |
| 79 | break; |
| 80 | case BIOS_CLIENT: |
| 81 | default: |
| 82 | len = buff->client.log_max_len; |
| 83 | start = buff->client.log_start_addr; |
| 84 | break; |
| 85 | } |
| 86 | if (!len) { |
Nayna Jain | 5efae7d | 2016-11-14 05:00:56 -0500 | [diff] [blame] | 87 | dev_warn(&chip->dev, "%s: TCPA log area empty\n", __func__); |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 88 | return -EIO; |
| 89 | } |
| 90 | |
| 91 | /* malloc EventLog space */ |
| 92 | log->bios_event_log = kmalloc(len, GFP_KERNEL); |
Nayna Jain | 5efae7d | 2016-11-14 05:00:56 -0500 | [diff] [blame] | 93 | if (!log->bios_event_log) |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 94 | return -ENOMEM; |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 95 | |
| 96 | log->bios_event_log_end = log->bios_event_log + len; |
| 97 | |
Lv Zheng | a238317 | 2014-05-20 15:39:41 +0800 | [diff] [blame] | 98 | virt = acpi_os_map_iomem(start, len); |
Nayna Jain | 5efae7d | 2016-11-14 05:00:56 -0500 | [diff] [blame] | 99 | if (!virt) |
Nayna Jain | 748935e | 2016-11-14 05:00:52 -0500 | [diff] [blame] | 100 | goto err; |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 101 | |
Kent Yoder | a40695e | 2012-09-04 11:18:21 -0500 | [diff] [blame] | 102 | memcpy_fromio(log->bios_event_log, virt, len); |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 103 | |
Lv Zheng | a238317 | 2014-05-20 15:39:41 +0800 | [diff] [blame] | 104 | acpi_os_unmap_iomem(virt, len); |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 105 | return 0; |
Nayna Jain | 748935e | 2016-11-14 05:00:52 -0500 | [diff] [blame] | 106 | |
| 107 | err: |
| 108 | kfree(log->bios_event_log); |
| 109 | log->bios_event_log = NULL; |
| 110 | return -EIO; |
| 111 | |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 112 | } |