tpm_acpi.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 "tpm.h"
  28. #include "tpm_eventlog.h"
  29. struct acpi_tcpa {
  30. struct acpi_table_header hdr;
  31. u16 platform_class;
  32. union {
  33. struct client_hdr {
  34. u32 log_max_len __packed;
  35. u64 log_start_addr __packed;
  36. } client;
  37. struct server_hdr {
  38. u16 reserved;
  39. u64 log_max_len __packed;
  40. u64 log_start_addr __packed;
  41. } server;
  42. };
  43. };
  44. /* read binary bios log */
  45. int tpm_read_log_acpi(struct tpm_chip *chip)
  46. {
  47. struct acpi_tcpa *buff;
  48. acpi_status status;
  49. void __iomem *virt;
  50. u64 len, start;
  51. struct tpm_bios_log *log;
  52. log = &chip->log;
  53. /* Unfortuntely ACPI does not associate the event log with a specific
  54. * TPM, like PPI. Thus all ACPI TPMs will read the same log.
  55. */
  56. if (!chip->acpi_dev_handle)
  57. return -ENODEV;
  58. /* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */
  59. status = acpi_get_table(ACPI_SIG_TCPA, 1,
  60. (struct acpi_table_header **)&buff);
  61. if (ACPI_FAILURE(status))
  62. return -ENODEV;
  63. switch(buff->platform_class) {
  64. case BIOS_SERVER:
  65. len = buff->server.log_max_len;
  66. start = buff->server.log_start_addr;
  67. break;
  68. case BIOS_CLIENT:
  69. default:
  70. len = buff->client.log_max_len;
  71. start = buff->client.log_start_addr;
  72. break;
  73. }
  74. if (!len) {
  75. dev_warn(&chip->dev, "%s: TCPA log area empty\n", __func__);
  76. return -EIO;
  77. }
  78. /* malloc EventLog space */
  79. log->bios_event_log = kmalloc(len, GFP_KERNEL);
  80. if (!log->bios_event_log)
  81. return -ENOMEM;
  82. log->bios_event_log_end = log->bios_event_log + len;
  83. virt = acpi_os_map_iomem(start, len);
  84. if (!virt)
  85. goto err;
  86. memcpy_fromio(log->bios_event_log, virt, len);
  87. acpi_os_unmap_iomem(virt, len);
  88. return 0;
  89. err:
  90. kfree(log->bios_event_log);
  91. log->bios_event_log = NULL;
  92. return -EIO;
  93. }