efi.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (C) 2017 Google
  3. *
  4. * Authors:
  5. * Thiebaud Weksteen <tweek@google.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. *
  12. */
  13. #include <linux/efi.h>
  14. #include <linux/tpm_eventlog.h>
  15. #include "../tpm.h"
  16. #include "common.h"
  17. /* read binary bios log from EFI configuration table */
  18. int tpm_read_log_efi(struct tpm_chip *chip)
  19. {
  20. struct linux_efi_tpm_eventlog *log_tbl;
  21. struct tpm_bios_log *log;
  22. u32 log_size;
  23. u8 tpm_log_version;
  24. if (!(chip->flags & TPM_CHIP_FLAG_TPM2))
  25. return -ENODEV;
  26. if (efi.tpm_log == EFI_INVALID_TABLE_ADDR)
  27. return -ENODEV;
  28. log = &chip->log;
  29. log_tbl = memremap(efi.tpm_log, sizeof(*log_tbl), MEMREMAP_WB);
  30. if (!log_tbl) {
  31. pr_err("Could not map UEFI TPM log table !\n");
  32. return -ENOMEM;
  33. }
  34. log_size = log_tbl->size;
  35. memunmap(log_tbl);
  36. log_tbl = memremap(efi.tpm_log, sizeof(*log_tbl) + log_size,
  37. MEMREMAP_WB);
  38. if (!log_tbl) {
  39. pr_err("Could not map UEFI TPM log table payload!\n");
  40. return -ENOMEM;
  41. }
  42. /* malloc EventLog space */
  43. log->bios_event_log = kmemdup(log_tbl->log, log_size, GFP_KERNEL);
  44. if (!log->bios_event_log)
  45. goto err_memunmap;
  46. log->bios_event_log_end = log->bios_event_log + log_size;
  47. tpm_log_version = log_tbl->version;
  48. memunmap(log_tbl);
  49. return tpm_log_version;
  50. err_memunmap:
  51. memunmap(log_tbl);
  52. return -ENOMEM;
  53. }