tbfind.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: tbfind - find table
  5. *
  6. * Copyright (C) 2000 - 2018, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #include "actables.h"
  12. #define _COMPONENT ACPI_TABLES
  13. ACPI_MODULE_NAME("tbfind")
  14. /*******************************************************************************
  15. *
  16. * FUNCTION: acpi_tb_find_table
  17. *
  18. * PARAMETERS: signature - String with ACPI table signature
  19. * oem_id - String with the table OEM ID
  20. * oem_table_id - String with the OEM Table ID
  21. * table_index - Where the table index is returned
  22. *
  23. * RETURN: Status and table index
  24. *
  25. * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
  26. * Signature, OEM ID and OEM Table ID. Returns an index that can
  27. * be used to get the table header or entire table.
  28. *
  29. ******************************************************************************/
  30. acpi_status
  31. acpi_tb_find_table(char *signature,
  32. char *oem_id, char *oem_table_id, u32 *table_index)
  33. {
  34. acpi_status status = AE_OK;
  35. struct acpi_table_header header;
  36. u32 i;
  37. ACPI_FUNCTION_TRACE(tb_find_table);
  38. /* Validate the input table signature */
  39. if (!acpi_ut_valid_nameseg(signature)) {
  40. return_ACPI_STATUS(AE_BAD_SIGNATURE);
  41. }
  42. /* Don't allow the OEM strings to be too long */
  43. if ((strlen(oem_id) > ACPI_OEM_ID_SIZE) ||
  44. (strlen(oem_table_id) > ACPI_OEM_TABLE_ID_SIZE)) {
  45. return_ACPI_STATUS(AE_AML_STRING_LIMIT);
  46. }
  47. /* Normalize the input strings */
  48. memset(&header, 0, sizeof(struct acpi_table_header));
  49. ACPI_MOVE_NAME(header.signature, signature);
  50. strncpy(header.oem_id, oem_id, ACPI_OEM_ID_SIZE);
  51. strncpy(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
  52. /* Search for the table */
  53. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  54. for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
  55. if (memcmp(&(acpi_gbl_root_table_list.tables[i].signature),
  56. header.signature, ACPI_NAME_SIZE)) {
  57. /* Not the requested table */
  58. continue;
  59. }
  60. /* Table with matching signature has been found */
  61. if (!acpi_gbl_root_table_list.tables[i].pointer) {
  62. /* Table is not currently mapped, map it */
  63. status =
  64. acpi_tb_validate_table(&acpi_gbl_root_table_list.
  65. tables[i]);
  66. if (ACPI_FAILURE(status)) {
  67. goto unlock_and_exit;
  68. }
  69. if (!acpi_gbl_root_table_list.tables[i].pointer) {
  70. continue;
  71. }
  72. }
  73. /* Check for table match on all IDs */
  74. if (!memcmp
  75. (acpi_gbl_root_table_list.tables[i].pointer->signature,
  76. header.signature, ACPI_NAME_SIZE) && (!oem_id[0]
  77. ||
  78. !memcmp
  79. (acpi_gbl_root_table_list.
  80. tables[i].pointer->
  81. oem_id,
  82. header.oem_id,
  83. ACPI_OEM_ID_SIZE))
  84. && (!oem_table_id[0]
  85. || !memcmp(acpi_gbl_root_table_list.tables[i].pointer->
  86. oem_table_id, header.oem_table_id,
  87. ACPI_OEM_TABLE_ID_SIZE))) {
  88. *table_index = i;
  89. ACPI_DEBUG_PRINT((ACPI_DB_TABLES,
  90. "Found table [%4.4s]\n",
  91. header.signature));
  92. goto unlock_and_exit;
  93. }
  94. }
  95. status = AE_NOT_FOUND;
  96. unlock_and_exit:
  97. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  98. return_ACPI_STATUS(status);
  99. }