Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 IBM Corporation |
| 3 | * |
Ashley Lai | 1a0f1b2 | 2014-12-04 21:01:51 -0600 | [diff] [blame] | 4 | * Author: Ashley Lai <ashleydlai@gmail.com> |
Nayna Jain | 02ae1382 | 2016-11-14 05:00:54 -0500 | [diff] [blame] | 5 | * Nayna Jain <nayna@linux.vnet.ibm.com> |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 6 | * |
| 7 | * Maintained by: <tpmdd-devel@lists.sourceforge.net> |
| 8 | * |
| 9 | * Read the event log created by the firmware on PPC64 |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License |
| 13 | * as published by the Free Software Foundation; either version |
| 14 | * 2 of the License, or (at your option) any later version. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/of.h> |
| 20 | |
| 21 | #include "tpm.h" |
| 22 | #include "tpm_eventlog.h" |
| 23 | |
Nayna Jain | 02ae1382 | 2016-11-14 05:00:54 -0500 | [diff] [blame] | 24 | int tpm_read_log_of(struct tpm_chip *chip) |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 25 | { |
| 26 | struct device_node *np; |
| 27 | const u32 *sizep; |
Hon Ching \(Vicky\) Lo | d72c3911 | 2015-06-17 18:17:09 -0400 | [diff] [blame] | 28 | const u64 *basep; |
Nayna Jain | 748935e | 2016-11-14 05:00:52 -0500 | [diff] [blame] | 29 | struct tpm_bios_log *log; |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 30 | |
Nayna Jain | 748935e | 2016-11-14 05:00:52 -0500 | [diff] [blame] | 31 | log = &chip->log; |
Nayna Jain | ed4fdb4 | 2016-11-14 05:00:55 -0500 | [diff] [blame] | 32 | if (chip->dev.parent->of_node) |
| 33 | np = chip->dev.parent->of_node; |
Colin Ian King | 79eec5b | 2016-11-15 13:27:22 +0000 | [diff] [blame^] | 34 | else |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 35 | return -ENODEV; |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 36 | |
| 37 | sizep = of_get_property(np, "linux,sml-size", NULL); |
Nayna Jain | 5efae7d | 2016-11-14 05:00:56 -0500 | [diff] [blame] | 38 | if (sizep == NULL) |
| 39 | return -EIO; |
| 40 | |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 41 | if (*sizep == 0) { |
Nayna Jain | 5efae7d | 2016-11-14 05:00:56 -0500 | [diff] [blame] | 42 | dev_warn(&chip->dev, "%s: Event log area empty\n", __func__); |
| 43 | return -EIO; |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | basep = of_get_property(np, "linux,sml-base", NULL); |
Nayna Jain | 5efae7d | 2016-11-14 05:00:56 -0500 | [diff] [blame] | 47 | if (basep == NULL) |
| 48 | return -EIO; |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 49 | |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 50 | log->bios_event_log = kmalloc(*sizep, GFP_KERNEL); |
Nayna Jain | 5efae7d | 2016-11-14 05:00:56 -0500 | [diff] [blame] | 51 | if (!log->bios_event_log) |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 52 | return -ENOMEM; |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 53 | |
| 54 | log->bios_event_log_end = log->bios_event_log + *sizep; |
| 55 | |
Hon Ching \(Vicky\) Lo | d72c3911 | 2015-06-17 18:17:09 -0400 | [diff] [blame] | 56 | memcpy(log->bios_event_log, __va(*basep), *sizep); |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 57 | |
| 58 | return 0; |
Ashley Lai | c5df392 | 2012-08-14 18:35:32 -0500 | [diff] [blame] | 59 | } |