tpm_of.c 1.3 KB
Newer Older
1 2 3
/*
 * Copyright 2012 IBM Corporation
 *
4
 * Author: Ashley Lai <ashleydlai@gmail.com>
5
 *         Nayna Jain <nayna@linux.vnet.ibm.com>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
 *
 * Read the event log created by the firmware on PPC64
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 *
 */

#include <linux/slab.h>
#include <linux/of.h>

#include "tpm.h"
#include "tpm_eventlog.h"

24
int tpm_read_log_of(struct tpm_chip *chip)
25 26 27
{
	struct device_node *np;
	const u32 *sizep;
28
	const u64 *basep;
N
Nayna Jain 已提交
29
	struct tpm_bios_log *log;
30

N
Nayna Jain 已提交
31
	log = &chip->log;
32 33
	if (chip->dev.parent->of_node)
		np = chip->dev.parent->of_node;
34
	else
35 36 37
		return -ENODEV;

	sizep = of_get_property(np, "linux,sml-size", NULL);
N
Nayna Jain 已提交
38 39 40
	if (sizep == NULL)
		return -EIO;

41
	if (*sizep == 0) {
N
Nayna Jain 已提交
42 43
		dev_warn(&chip->dev, "%s: Event log area empty\n", __func__);
		return -EIO;
44 45 46
	}

	basep = of_get_property(np, "linux,sml-base", NULL);
N
Nayna Jain 已提交
47 48
	if (basep == NULL)
		return -EIO;
49 50

	log->bios_event_log = kmalloc(*sizep, GFP_KERNEL);
N
Nayna Jain 已提交
51
	if (!log->bios_event_log)
52 53 54 55
		return -ENOMEM;

	log->bios_event_log_end = log->bios_event_log + *sizep;

56
	memcpy(log->bios_event_log, __va(*basep), *sizep);
57 58 59

	return 0;
}