tbfind.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /******************************************************************************
  2. *
  3. * Module Name: tbfind - find table
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "actables.h"
  45. #define _COMPONENT ACPI_TABLES
  46. ACPI_MODULE_NAME("tbfind")
  47. /*******************************************************************************
  48. *
  49. * FUNCTION: acpi_tb_find_table
  50. *
  51. * PARAMETERS: signature - String with ACPI table signature
  52. * oem_id - String with the table OEM ID
  53. * oem_table_id - String with the OEM Table ID
  54. * table_index - Where the table index is returned
  55. *
  56. * RETURN: Status and table index
  57. *
  58. * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
  59. * Signature, OEM ID and OEM Table ID. Returns an index that can
  60. * be used to get the table header or entire table.
  61. *
  62. ******************************************************************************/
  63. acpi_status
  64. acpi_tb_find_table(char *signature,
  65. char *oem_id, char *oem_table_id, u32 *table_index)
  66. {
  67. acpi_status status;
  68. struct acpi_table_header header;
  69. u32 i;
  70. ACPI_FUNCTION_TRACE(tb_find_table);
  71. /* Validate the input table signature */
  72. if (!acpi_is_valid_signature(signature)) {
  73. return_ACPI_STATUS(AE_BAD_SIGNATURE);
  74. }
  75. /* Don't allow the OEM strings to be too long */
  76. if ((strlen(oem_id) > ACPI_OEM_ID_SIZE) ||
  77. (strlen(oem_table_id) > ACPI_OEM_TABLE_ID_SIZE)) {
  78. return_ACPI_STATUS(AE_AML_STRING_LIMIT);
  79. }
  80. /* Normalize the input strings */
  81. memset(&header, 0, sizeof(struct acpi_table_header));
  82. ACPI_MOVE_NAME(header.signature, signature);
  83. strncpy(header.oem_id, oem_id, ACPI_OEM_ID_SIZE);
  84. strncpy(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
  85. /* Search for the table */
  86. for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
  87. if (memcmp(&(acpi_gbl_root_table_list.tables[i].signature),
  88. header.signature, ACPI_NAME_SIZE)) {
  89. /* Not the requested table */
  90. continue;
  91. }
  92. /* Table with matching signature has been found */
  93. if (!acpi_gbl_root_table_list.tables[i].pointer) {
  94. /* Table is not currently mapped, map it */
  95. status =
  96. acpi_tb_validate_table(&acpi_gbl_root_table_list.
  97. tables[i]);
  98. if (ACPI_FAILURE(status)) {
  99. return_ACPI_STATUS(status);
  100. }
  101. if (!acpi_gbl_root_table_list.tables[i].pointer) {
  102. continue;
  103. }
  104. }
  105. /* Check for table match on all IDs */
  106. if (!memcmp
  107. (acpi_gbl_root_table_list.tables[i].pointer->signature,
  108. header.signature, ACPI_NAME_SIZE) && (!oem_id[0]
  109. ||
  110. !memcmp
  111. (acpi_gbl_root_table_list.
  112. tables[i].pointer->
  113. oem_id,
  114. header.oem_id,
  115. ACPI_OEM_ID_SIZE))
  116. && (!oem_table_id[0]
  117. || !memcmp(acpi_gbl_root_table_list.tables[i].pointer->
  118. oem_table_id, header.oem_table_id,
  119. ACPI_OEM_TABLE_ID_SIZE))) {
  120. *table_index = i;
  121. ACPI_DEBUG_PRINT((ACPI_DB_TABLES,
  122. "Found table [%4.4s]\n",
  123. header.signature));
  124. return_ACPI_STATUS(AE_OK);
  125. }
  126. }
  127. return_ACPI_STATUS(AE_NOT_FOUND);
  128. }