blob: 0cb43ef5f79a6e141f68cfd1f3c8abb782931179 [file] [log] [blame]
Kent Yodere5dcd872012-07-11 10:08:12 -05001/*
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 Jain02ae13822016-11-14 05:00:54 -05009 * Nayna Jain <nayna@linux.vnet.ibm.com>
Kent Yodere5dcd872012-07-11 10:08:12 -050010 *
11 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
12 *
Nayna Jain748935e2016-11-14 05:00:52 -050013 * Access to the event log extended by the TCG BIOS of PC platform
Kent Yodere5dcd872012-07-11 10:08:12 -050014 *
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 Zheng8b484632013-12-03 08:49:16 +080027#include <linux/acpi.h>
Kent Yodere5dcd872012-07-11 10:08:12 -050028
29#include "tpm.h"
30#include "tpm_eventlog.h"
31
32struct acpi_tcpa {
33 struct acpi_table_header hdr;
34 u16 platform_class;
35 union {
36 struct client_hdr {
Jason Gunthorpe348df8d2012-11-21 13:56:45 -070037 u32 log_max_len __packed;
38 u64 log_start_addr __packed;
Kent Yodere5dcd872012-07-11 10:08:12 -050039 } client;
40 struct server_hdr {
41 u16 reserved;
Jason Gunthorpe348df8d2012-11-21 13:56:45 -070042 u64 log_max_len __packed;
43 u64 log_start_addr __packed;
Kent Yodere5dcd872012-07-11 10:08:12 -050044 } server;
45 };
46};
47
48/* read binary bios log */
Nayna Jain02ae13822016-11-14 05:00:54 -050049int tpm_read_log_acpi(struct tpm_chip *chip)
Kent Yodere5dcd872012-07-11 10:08:12 -050050{
51 struct acpi_tcpa *buff;
52 acpi_status status;
Kent Yodera40695e2012-09-04 11:18:21 -050053 void __iomem *virt;
Kent Yodere5dcd872012-07-11 10:08:12 -050054 u64 len, start;
Nayna Jain748935e2016-11-14 05:00:52 -050055 struct tpm_bios_log *log;
Kent Yodere5dcd872012-07-11 10:08:12 -050056
Nayna Jain748935e2016-11-14 05:00:52 -050057 log = &chip->log;
Kent Yodere5dcd872012-07-11 10:08:12 -050058
59 /* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */
60 status = acpi_get_table(ACPI_SIG_TCPA, 1,
61 (struct acpi_table_header **)&buff);
62
Nayna Jain5efae7d2016-11-14 05:00:56 -050063 if (ACPI_FAILURE(status))
Kent Yodere5dcd872012-07-11 10:08:12 -050064 return -EIO;
Kent Yodere5dcd872012-07-11 10:08:12 -050065
66 switch(buff->platform_class) {
67 case BIOS_SERVER:
68 len = buff->server.log_max_len;
69 start = buff->server.log_start_addr;
70 break;
71 case BIOS_CLIENT:
72 default:
73 len = buff->client.log_max_len;
74 start = buff->client.log_start_addr;
75 break;
76 }
77 if (!len) {
Nayna Jain5efae7d2016-11-14 05:00:56 -050078 dev_warn(&chip->dev, "%s: TCPA log area empty\n", __func__);
Kent Yodere5dcd872012-07-11 10:08:12 -050079 return -EIO;
80 }
81
82 /* malloc EventLog space */
83 log->bios_event_log = kmalloc(len, GFP_KERNEL);
Nayna Jain5efae7d2016-11-14 05:00:56 -050084 if (!log->bios_event_log)
Kent Yodere5dcd872012-07-11 10:08:12 -050085 return -ENOMEM;
Kent Yodere5dcd872012-07-11 10:08:12 -050086
87 log->bios_event_log_end = log->bios_event_log + len;
88
Lv Zhenga2383172014-05-20 15:39:41 +080089 virt = acpi_os_map_iomem(start, len);
Nayna Jain5efae7d2016-11-14 05:00:56 -050090 if (!virt)
Nayna Jain748935e2016-11-14 05:00:52 -050091 goto err;
Kent Yodere5dcd872012-07-11 10:08:12 -050092
Kent Yodera40695e2012-09-04 11:18:21 -050093 memcpy_fromio(log->bios_event_log, virt, len);
Kent Yodere5dcd872012-07-11 10:08:12 -050094
Lv Zhenga2383172014-05-20 15:39:41 +080095 acpi_os_unmap_iomem(virt, len);
Kent Yodere5dcd872012-07-11 10:08:12 -050096 return 0;
Nayna Jain748935e2016-11-14 05:00:52 -050097
98err:
99 kfree(log->bios_event_log);
100 log->bios_event_log = NULL;
101 return -EIO;
102
Kent Yodere5dcd872012-07-11 10:08:12 -0500103}