acpi.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2005 IBM Corporation
  3. *
  4. * Authors:
  5. * Seiji Munetoh <munetoh@jp.ibm.com>
  6. * Stefan Berger <stefanb@us.ibm.com>
  7. * Reiner Sailer <sailer@watson.ibm.com>
  8. * Kylene Hall <kjhall@us.ibm.com>
  9. * Nayna Jain <nayna@linux.vnet.ibm.com>
  10. *
  11. * Maintained by: <tpmdd-devel@lists.sourceforge.net>
  12. *
  13. * Access to the event log extended by the TCG BIOS of PC platform
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * as published by the Free Software Foundation; either version
  18. * 2 of the License, or (at your option) any later version.
  19. *
  20. */
  21. #include <linux/seq_file.h>
  22. #include <linux/fs.h>
  23. #include <linux/security.h>
  24. #include <linux/module.h>
  25. #include <linux/slab.h>
  26. #include <linux/acpi.h>
  27. #include <linux/tpm_eventlog.h>
  28. #include "../tpm.h"
  29. #include "common.h"
  30. struct acpi_tcpa {
  31. struct acpi_table_header hdr;
  32. u16 platform_class;
  33. union {
  34. struct client_hdr {
  35. u32 log_max_len __packed;
  36. u64 log_start_addr __packed;
  37. } client;
  38. struct server_hdr {
  39. u16 reserved;
  40. u64 log_max_len __packed;
  41. u64 log_start_addr __packed;
  42. } server;
  43. };
  44. };
  45. /* read binary bios log */
  46. int tpm_read_log_acpi(struct tpm_chip *chip)
  47. {
  48. struct acpi_tcpa *buff;
  49. acpi_status status;
  50. void __iomem *virt;
  51. u64 len, start;
  52. struct tpm_bios_log *log;
  53. if (chip->flags & TPM_CHIP_FLAG_TPM2)
  54. return -ENODEV;
  55. log = &chip->log;
  56. /* Unfortuntely ACPI does not associate the event log with a specific
  57. * TPM, like PPI. Thus all ACPI TPMs will read the same log.
  58. */
  59. if (!chip->acpi_dev_handle)
  60. return -ENODEV;
  61. /* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */
  62. status = acpi_get_table(ACPI_SIG_TCPA, 1,
  63. (struct acpi_table_header **)&buff);
  64. if (ACPI_FAILURE(status))
  65. return -ENODEV;
  66. switch(buff->platform_class) {
  67. case BIOS_SERVER:
  68. len = buff->server.log_max_len;
  69. start = buff->server.log_start_addr;
  70. break;
  71. case BIOS_CLIENT:
  72. default:
  73. len = buff->client.log_max_len;
  74. start = buff->client.log_start_addr;
  75. break;
  76. }
  77. if (!len) {
  78. dev_warn(&chip->dev, "%s: TCPA log area empty\n", __func__);
  79. return -EIO;
  80. }
  81. /* malloc EventLog space */
  82. log->bios_event_log = kmalloc(len, GFP_KERNEL);
  83. if (!log->bios_event_log)
  84. return -ENOMEM;
  85. log->bios_event_log_end = log->bios_event_log + len;
  86. virt = acpi_os_map_iomem(start, len);
  87. if (!virt)
  88. goto err;
  89. memcpy_fromio(log->bios_event_log, virt, len);
  90. acpi_os_unmap_iomem(virt, len);
  91. return EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2;
  92. err:
  93. kfree(log->bios_event_log);
  94. log->bios_event_log = NULL;
  95. return -EIO;
  96. }