tpm_eventlog_of.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 <linux/tpm_eventlog.h>
  20. #include "tpm.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. u32 size;
  28. u64 base;
  29. log = &chip->log;
  30. if (chip->dev.parent && chip->dev.parent->of_node)
  31. np = chip->dev.parent->of_node;
  32. else
  33. return -ENODEV;
  34. if (of_property_read_bool(np, "powered-while-suspended"))
  35. chip->flags |= TPM_CHIP_FLAG_ALWAYS_POWERED;
  36. sizep = of_get_property(np, "linux,sml-size", NULL);
  37. basep = of_get_property(np, "linux,sml-base", NULL);
  38. if (sizep == NULL && basep == NULL)
  39. return -ENODEV;
  40. if (sizep == NULL || basep == NULL)
  41. return -EIO;
  42. /*
  43. * For both vtpm/tpm, firmware has log addr and log size in big
  44. * endian format. But in case of vtpm, there is a method called
  45. * sml-handover which is run during kernel init even before
  46. * device tree is setup. This sml-handover function takes care
  47. * of endianness and writes to sml-base and sml-size in little
  48. * endian format. For this reason, vtpm doesn't need conversion
  49. * but physical tpm needs the conversion.
  50. */
  51. if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0) {
  52. size = be32_to_cpup(sizep);
  53. base = be64_to_cpup(basep);
  54. } else {
  55. size = *sizep;
  56. base = *basep;
  57. }
  58. if (size == 0) {
  59. dev_warn(&chip->dev, "%s: Event log area empty\n", __func__);
  60. return -EIO;
  61. }
  62. log->bios_event_log = kmalloc(size, GFP_KERNEL);
  63. if (!log->bios_event_log)
  64. return -ENOMEM;
  65. log->bios_event_log_end = log->bios_event_log + size;
  66. memcpy(log->bios_event_log, __va(base), size);
  67. if (chip->flags & TPM_CHIP_FLAG_TPM2)
  68. return EFI_TCG2_EVENT_LOG_FORMAT_TCG_2;
  69. return EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2;
  70. }