sst-match-acpi.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * sst_match_apci.c - SST (LPE) match for ACPI enumeration.
  3. *
  4. * Copyright (c) 2013-15, Intel Corporation.
  5. *
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. */
  16. #include "sst-acpi.h"
  17. static acpi_status sst_acpi_find_name(acpi_handle handle, u32 level,
  18. void *context, void **ret)
  19. {
  20. struct acpi_device *adev;
  21. const char *name = NULL;
  22. if (acpi_bus_get_device(handle, &adev))
  23. return AE_OK;
  24. if (adev->status.present && adev->status.functional) {
  25. name = acpi_dev_name(adev);
  26. *(const char **)ret = name;
  27. return AE_CTRL_TERMINATE;
  28. }
  29. return AE_OK;
  30. }
  31. const char *sst_acpi_find_name_from_hid(const u8 hid[ACPI_ID_LEN])
  32. {
  33. const char *name = NULL;
  34. acpi_status status;
  35. status = acpi_get_devices(hid, sst_acpi_find_name, NULL,
  36. (void **)&name);
  37. if (ACPI_FAILURE(status) || name[0] == '\0')
  38. return NULL;
  39. return name;
  40. }
  41. EXPORT_SYMBOL_GPL(sst_acpi_find_name_from_hid);
  42. static acpi_status sst_acpi_mach_match(acpi_handle handle, u32 level,
  43. void *context, void **ret)
  44. {
  45. unsigned long long sta;
  46. acpi_status status;
  47. *(bool *)context = true;
  48. status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
  49. if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_PRESENT))
  50. *(bool *)context = false;
  51. return AE_OK;
  52. }
  53. struct sst_acpi_mach *sst_acpi_find_machine(struct sst_acpi_mach *machines)
  54. {
  55. struct sst_acpi_mach *mach;
  56. bool found = false;
  57. for (mach = machines; mach->id[0]; mach++)
  58. if (ACPI_SUCCESS(acpi_get_devices(mach->id,
  59. sst_acpi_mach_match,
  60. &found, NULL)) && found)
  61. return mach;
  62. return NULL;
  63. }
  64. EXPORT_SYMBOL_GPL(sst_acpi_find_machine);
  65. MODULE_LICENSE("GPL v2");
  66. MODULE_DESCRIPTION("Intel Common ACPI Match module");