of.c 2.2 KB

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