tpm_of.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2012 IBM Corporation
  3. *
  4. * Author: Ashley Lai <ashleydlai@gmail.com>
  5. *
  6. * Maintained by: <tpmdd-devel@lists.sourceforge.net>
  7. *
  8. * Read the event log created by the firmware on PPC64
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version
  13. * 2 of the License, or (at your option) any later version.
  14. *
  15. */
  16. #include <linux/slab.h>
  17. #include <linux/of.h>
  18. #include "tpm.h"
  19. #include "tpm_eventlog.h"
  20. int read_log(struct tpm_bios_log *log)
  21. {
  22. struct device_node *np;
  23. const u32 *sizep;
  24. const u64 *basep;
  25. if (log->bios_event_log != NULL) {
  26. pr_err("%s: ERROR - Eventlog already initialized\n", __func__);
  27. return -EFAULT;
  28. }
  29. np = of_find_node_by_name(NULL, "vtpm");
  30. if (!np) {
  31. pr_err("%s: ERROR - IBMVTPM not supported\n", __func__);
  32. return -ENODEV;
  33. }
  34. sizep = of_get_property(np, "linux,sml-size", NULL);
  35. if (sizep == NULL) {
  36. pr_err("%s: ERROR - SML size not found\n", __func__);
  37. goto cleanup_eio;
  38. }
  39. if (*sizep == 0) {
  40. pr_err("%s: ERROR - event log area empty\n", __func__);
  41. goto cleanup_eio;
  42. }
  43. basep = of_get_property(np, "linux,sml-base", NULL);
  44. if (basep == NULL) {
  45. pr_err("%s: ERROR - SML not found\n", __func__);
  46. goto cleanup_eio;
  47. }
  48. log->bios_event_log = kmalloc(*sizep, GFP_KERNEL);
  49. if (!log->bios_event_log) {
  50. pr_err("%s: ERROR - Not enough memory for BIOS measurements\n",
  51. __func__);
  52. of_node_put(np);
  53. return -ENOMEM;
  54. }
  55. log->bios_event_log_end = log->bios_event_log + *sizep;
  56. memcpy(log->bios_event_log, __va(*basep), *sizep);
  57. of_node_put(np);
  58. return 0;
  59. cleanup_eio:
  60. of_node_put(np);
  61. return -EIO;
  62. }