tpm_acpi.c 2.5 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. *
  10. * Maintained by: <tpmdd-devel@lists.sourceforge.net>
  11. *
  12. * Access to the eventlog extended by the TCG BIOS of PC platform
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version
  17. * 2 of the License, or (at your option) any later version.
  18. *
  19. */
  20. #include <linux/seq_file.h>
  21. #include <linux/fs.h>
  22. #include <linux/security.h>
  23. #include <linux/module.h>
  24. #include <linux/slab.h>
  25. #include <linux/acpi.h>
  26. #include "tpm.h"
  27. #include "tpm_eventlog.h"
  28. struct acpi_tcpa {
  29. struct acpi_table_header hdr;
  30. u16 platform_class;
  31. union {
  32. struct client_hdr {
  33. u32 log_max_len __packed;
  34. u64 log_start_addr __packed;
  35. } client;
  36. struct server_hdr {
  37. u16 reserved;
  38. u64 log_max_len __packed;
  39. u64 log_start_addr __packed;
  40. } server;
  41. };
  42. };
  43. /* read binary bios log */
  44. int read_log(struct tpm_bios_log *log)
  45. {
  46. struct acpi_tcpa *buff;
  47. acpi_status status;
  48. void __iomem *virt;
  49. u64 len, start;
  50. if (log->bios_event_log != NULL) {
  51. printk(KERN_ERR
  52. "%s: ERROR - Eventlog already initialized\n",
  53. __func__);
  54. return -EFAULT;
  55. }
  56. /* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */
  57. status = acpi_get_table(ACPI_SIG_TCPA, 1,
  58. (struct acpi_table_header **)&buff);
  59. if (ACPI_FAILURE(status)) {
  60. printk(KERN_ERR "%s: ERROR - Could not get TCPA table\n",
  61. __func__);
  62. return -EIO;
  63. }
  64. switch(buff->platform_class) {
  65. case BIOS_SERVER:
  66. len = buff->server.log_max_len;
  67. start = buff->server.log_start_addr;
  68. break;
  69. case BIOS_CLIENT:
  70. default:
  71. len = buff->client.log_max_len;
  72. start = buff->client.log_start_addr;
  73. break;
  74. }
  75. if (!len) {
  76. printk(KERN_ERR "%s: ERROR - TCPA log area empty\n", __func__);
  77. return -EIO;
  78. }
  79. /* malloc EventLog space */
  80. log->bios_event_log = kmalloc(len, GFP_KERNEL);
  81. if (!log->bios_event_log) {
  82. printk("%s: ERROR - Not enough Memory for BIOS measurements\n",
  83. __func__);
  84. return -ENOMEM;
  85. }
  86. log->bios_event_log_end = log->bios_event_log + len;
  87. virt = acpi_os_map_iomem(start, len);
  88. if (!virt) {
  89. kfree(log->bios_event_log);
  90. printk("%s: ERROR - Unable to map memory\n", __func__);
  91. return -EIO;
  92. }
  93. memcpy_fromio(log->bios_event_log, virt, len);
  94. acpi_os_unmap_iomem(virt, len);
  95. return 0;
  96. }