blob: 36df9df4c472b9738b1d2e375b204677097e61bf [file] [log] [blame]
Ashley Laic5df3922012-08-14 18:35:32 -05001/*
2 * Copyright 2012 IBM Corporation
3 *
Ashley Lai1a0f1b22014-12-04 21:01:51 -06004 * Author: Ashley Lai <ashleydlai@gmail.com>
Nayna Jain02ae13822016-11-14 05:00:54 -05005 * Nayna Jain <nayna@linux.vnet.ibm.com>
Ashley Laic5df3922012-08-14 18:35:32 -05006 *
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 Jain02ae13822016-11-14 05:00:54 -050024int tpm_read_log_of(struct tpm_chip *chip)
Ashley Laic5df3922012-08-14 18:35:32 -050025{
26 struct device_node *np;
27 const u32 *sizep;
Hon Ching \(Vicky\) Lod72c39112015-06-17 18:17:09 -040028 const u64 *basep;
Nayna Jain748935e2016-11-14 05:00:52 -050029 struct tpm_bios_log *log;
Ashley Laic5df3922012-08-14 18:35:32 -050030
Nayna Jain748935e2016-11-14 05:00:52 -050031 log = &chip->log;
Nayna Jained4fdb42016-11-14 05:00:55 -050032 if (chip->dev.parent->of_node)
33 np = chip->dev.parent->of_node;
Colin Ian King79eec5b2016-11-15 13:27:22 +000034 else
Ashley Laic5df3922012-08-14 18:35:32 -050035 return -ENODEV;
Ashley Laic5df3922012-08-14 18:35:32 -050036
37 sizep = of_get_property(np, "linux,sml-size", NULL);
Nayna Jain5efae7d2016-11-14 05:00:56 -050038 if (sizep == NULL)
39 return -EIO;
40
Ashley Laic5df3922012-08-14 18:35:32 -050041 if (*sizep == 0) {
Nayna Jain5efae7d2016-11-14 05:00:56 -050042 dev_warn(&chip->dev, "%s: Event log area empty\n", __func__);
43 return -EIO;
Ashley Laic5df3922012-08-14 18:35:32 -050044 }
45
46 basep = of_get_property(np, "linux,sml-base", NULL);
Nayna Jain5efae7d2016-11-14 05:00:56 -050047 if (basep == NULL)
48 return -EIO;
Ashley Laic5df3922012-08-14 18:35:32 -050049
Ashley Laic5df3922012-08-14 18:35:32 -050050 log->bios_event_log = kmalloc(*sizep, GFP_KERNEL);
Nayna Jain5efae7d2016-11-14 05:00:56 -050051 if (!log->bios_event_log)
Ashley Laic5df3922012-08-14 18:35:32 -050052 return -ENOMEM;
Ashley Laic5df3922012-08-14 18:35:32 -050053
54 log->bios_event_log_end = log->bios_event_log + *sizep;
55
Hon Ching \(Vicky\) Lod72c39112015-06-17 18:17:09 -040056 memcpy(log->bios_event_log, __va(*basep), *sizep);
Ashley Laic5df3922012-08-14 18:35:32 -050057
58 return 0;
Ashley Laic5df3922012-08-14 18:35:32 -050059}