tpm_of.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2012 IBM Corporation
  3. *
  4. * Author: Ashley Lai <ashleydlai@gmail.com>
  5. * Nayna Jain <nayna@linux.vnet.ibm.com>
  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. #include <linux/slab.h>
  18. #include <linux/of.h>
  19. #include "tpm.h"
  20. #include "tpm_eventlog.h"
  21. int tpm_read_log_of(struct tpm_chip *chip)
  22. {
  23. struct device_node *np;
  24. const u32 *sizep;
  25. const u64 *basep;
  26. struct tpm_bios_log *log;
  27. log = &chip->log;
  28. if (chip->dev.parent && chip->dev.parent->of_node)
  29. np = chip->dev.parent->of_node;
  30. else
  31. return -ENODEV;
  32. sizep = of_get_property(np, "linux,sml-size", NULL);
  33. basep = of_get_property(np, "linux,sml-base", NULL);
  34. if (sizep == NULL && basep == NULL)
  35. return -ENODEV;
  36. if (sizep == NULL || basep == NULL)
  37. return -EIO;
  38. if (*sizep == 0) {
  39. dev_warn(&chip->dev, "%s: Event log area empty\n", __func__);
  40. return -EIO;
  41. }
  42. log->bios_event_log = kmalloc(*sizep, GFP_KERNEL);
  43. if (!log->bios_event_log)
  44. return -ENOMEM;
  45. log->bios_event_log_end = log->bios_event_log + *sizep;
  46. memcpy(log->bios_event_log, __va(*basep), *sizep);
  47. return 0;
  48. }