tbfind.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /******************************************************************************
  2. *
  3. * Module Name: tbfind - find table
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2007, R. Byron Moore
  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 <acpi/actables.h>
  44. #define _COMPONENT ACPI_TABLES
  45. ACPI_MODULE_NAME("tbfind")
  46. /*******************************************************************************
  47. *
  48. * FUNCTION: acpi_tb_find_table
  49. *
  50. * PARAMETERS: Signature - String with ACPI table signature
  51. * oem_id - String with the table OEM ID
  52. * oem_table_id - String with the OEM Table ID
  53. * table_index - Where the table index is returned
  54. *
  55. * RETURN: Status and table index
  56. *
  57. * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
  58. * Signature, OEM ID and OEM Table ID. Returns an index that can
  59. * be used to get the table header or entire table.
  60. *
  61. ******************************************************************************/
  62. acpi_status
  63. acpi_tb_find_table(char *signature,
  64. char *oem_id,
  65. char *oem_table_id, acpi_native_uint * table_index)
  66. {
  67. acpi_native_uint i;
  68. acpi_status status;
  69. ACPI_FUNCTION_TRACE(tb_find_table);
  70. for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
  71. if (ACPI_MEMCMP(&(acpi_gbl_root_table_list.tables[i].signature),
  72. signature, ACPI_NAME_SIZE)) {
  73. /* Not the requested table */
  74. continue;
  75. }
  76. /* Table with matching signature has been found */
  77. if (!acpi_gbl_root_table_list.tables[i].pointer) {
  78. /* Table is not currently mapped, map it */
  79. status =
  80. acpi_tb_verify_table(&acpi_gbl_root_table_list.
  81. tables[i]);
  82. if (ACPI_FAILURE(status)) {
  83. return_ACPI_STATUS(status);
  84. }
  85. if (!acpi_gbl_root_table_list.tables[i].pointer) {
  86. continue;
  87. }
  88. }
  89. /* Check for table match on all IDs */
  90. if (!ACPI_MEMCMP
  91. (acpi_gbl_root_table_list.tables[i].pointer->signature,
  92. signature, ACPI_NAME_SIZE) && (!oem_id[0]
  93. ||
  94. !ACPI_MEMCMP
  95. (acpi_gbl_root_table_list.
  96. tables[i].pointer->oem_id,
  97. oem_id, ACPI_OEM_ID_SIZE))
  98. && (!oem_table_id[0]
  99. || !ACPI_MEMCMP(acpi_gbl_root_table_list.tables[i].
  100. pointer->oem_table_id, oem_table_id,
  101. ACPI_OEM_TABLE_ID_SIZE))) {
  102. *table_index = i;
  103. ACPI_DEBUG_PRINT((ACPI_DB_TABLES,
  104. "Found table [%4.4s]\n", signature));
  105. return_ACPI_STATUS(AE_OK);
  106. }
  107. }
  108. return_ACPI_STATUS(AE_NOT_FOUND);
  109. }