of.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright 2012 IBM Corporation
  4. *
  5. * Author: Ashley Lai <[email protected]>
  6. * Nayna Jain <[email protected]>
  7. *
  8. * Maintained by: <[email protected]>
  9. *
  10. * Read the event log created by the firmware on PPC64
  11. */
  12. #include <linux/slab.h>
  13. #include <linux/of.h>
  14. #include <linux/tpm_eventlog.h>
  15. #include "../tpm.h"
  16. #include "common.h"
  17. int tpm_read_log_of(struct tpm_chip *chip)
  18. {
  19. struct device_node *np;
  20. const u32 *sizep;
  21. const u64 *basep;
  22. struct tpm_bios_log *log;
  23. u32 size;
  24. u64 base;
  25. log = &chip->log;
  26. if (chip->dev.parent && chip->dev.parent->of_node)
  27. np = chip->dev.parent->of_node;
  28. else
  29. return -ENODEV;
  30. if (of_property_read_bool(np, "powered-while-suspended"))
  31. chip->flags |= TPM_CHIP_FLAG_ALWAYS_POWERED;
  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. /*
  39. * For both vtpm/tpm, firmware has log addr and log size in big
  40. * endian format. But in case of vtpm, there is a method called
  41. * sml-handover which is run during kernel init even before
  42. * device tree is setup. This sml-handover function takes care
  43. * of endianness and writes to sml-base and sml-size in little
  44. * endian format. For this reason, vtpm doesn't need conversion
  45. * but physical tpm needs the conversion.
  46. */
  47. if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0 &&
  48. of_property_match_string(np, "compatible", "IBM,vtpm20") < 0) {
  49. size = be32_to_cpup((__force __be32 *)sizep);
  50. base = be64_to_cpup((__force __be64 *)basep);
  51. } else {
  52. size = *sizep;
  53. base = *basep;
  54. }
  55. if (size == 0) {
  56. dev_warn(&chip->dev, "%s: Event log area empty\n", __func__);
  57. return -EIO;
  58. }
  59. log->bios_event_log = kmemdup(__va(base), size, GFP_KERNEL);
  60. if (!log->bios_event_log)
  61. return -ENOMEM;
  62. log->bios_event_log_end = log->bios_event_log + size;
  63. if (chip->flags & TPM_CHIP_FLAG_TPM2)
  64. return EFI_TCG2_EVENT_LOG_FORMAT_TCG_2;
  65. return EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2;
  66. }