Vinod Koul | 95f0980 | 2015-11-05 21:34:11 +0530 | [diff] [blame] | 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 | */ |
Vinod Koul | 95f0980 | 2015-11-05 21:34:11 +0530 | [diff] [blame] | 16 | |
| 17 | #include "sst-acpi.h" |
| 18 | |
Pierre-Louis Bossart | 1fdb7c1 | 2016-03-03 21:36:36 -0600 | [diff] [blame] | 19 | static acpi_status sst_acpi_find_name(acpi_handle handle, u32 level, |
| 20 | void *context, void **ret) |
| 21 | { |
| 22 | struct acpi_device *adev; |
| 23 | const char *name = NULL; |
| 24 | |
| 25 | if (acpi_bus_get_device(handle, &adev)) |
| 26 | return AE_OK; |
| 27 | |
| 28 | if (adev->status.present && adev->status.functional) { |
| 29 | name = acpi_dev_name(adev); |
| 30 | *(const char **)ret = name; |
| 31 | return AE_CTRL_TERMINATE; |
| 32 | } |
| 33 | |
| 34 | return AE_OK; |
| 35 | } |
| 36 | |
| 37 | const char *sst_acpi_find_name_from_hid(const u8 hid[ACPI_ID_LEN]) |
| 38 | { |
| 39 | const char *name = NULL; |
| 40 | acpi_status status; |
| 41 | |
| 42 | status = acpi_get_devices(hid, sst_acpi_find_name, NULL, |
| 43 | (void **)&name); |
| 44 | |
| 45 | if (ACPI_FAILURE(status) || name[0] == '\0') |
| 46 | return NULL; |
| 47 | |
| 48 | return name; |
| 49 | } |
| 50 | EXPORT_SYMBOL_GPL(sst_acpi_find_name_from_hid); |
| 51 | |
Vinod Koul | 95f0980 | 2015-11-05 21:34:11 +0530 | [diff] [blame] | 52 | static acpi_status sst_acpi_mach_match(acpi_handle handle, u32 level, |
| 53 | void *context, void **ret) |
| 54 | { |
Pierre-Louis Bossart | cab4738 | 2016-03-03 21:36:34 -0600 | [diff] [blame] | 55 | unsigned long long sta; |
| 56 | acpi_status status; |
| 57 | |
Vinod Koul | 95f0980 | 2015-11-05 21:34:11 +0530 | [diff] [blame] | 58 | *(bool *)context = true; |
Pierre-Louis Bossart | cab4738 | 2016-03-03 21:36:34 -0600 | [diff] [blame] | 59 | status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); |
| 60 | if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_PRESENT)) |
| 61 | *(bool *)context = false; |
| 62 | |
Vinod Koul | 95f0980 | 2015-11-05 21:34:11 +0530 | [diff] [blame] | 63 | return AE_OK; |
| 64 | } |
| 65 | |
Naveen M | 915ae2b | 2017-05-15 13:42:13 +0530 | [diff] [blame] | 66 | bool sst_acpi_check_hid(const u8 hid[ACPI_ID_LEN]) |
| 67 | { |
| 68 | acpi_status status; |
| 69 | bool found = false; |
| 70 | |
| 71 | status = acpi_get_devices(hid, sst_acpi_mach_match, &found, NULL); |
| 72 | |
| 73 | if (ACPI_FAILURE(status)) |
| 74 | return false; |
| 75 | |
| 76 | return found; |
| 77 | } |
| 78 | EXPORT_SYMBOL_GPL(sst_acpi_check_hid); |
| 79 | |
Vinod Koul | 95f0980 | 2015-11-05 21:34:11 +0530 | [diff] [blame] | 80 | struct sst_acpi_mach *sst_acpi_find_machine(struct sst_acpi_mach *machines) |
| 81 | { |
| 82 | struct sst_acpi_mach *mach; |
Vinod Koul | 95f0980 | 2015-11-05 21:34:11 +0530 | [diff] [blame] | 83 | |
Naveen M | 7827d66 | 2017-05-15 13:42:14 +0530 | [diff] [blame^] | 84 | for (mach = machines; mach->id[0]; mach++) { |
| 85 | if (sst_acpi_check_hid(mach->id) == true) { |
| 86 | if (mach->machine_quirk == NULL) |
| 87 | return mach; |
| 88 | |
| 89 | if (mach->machine_quirk(mach) != NULL) |
| 90 | return mach; |
| 91 | } |
| 92 | } |
Vinod Koul | 95f0980 | 2015-11-05 21:34:11 +0530 | [diff] [blame] | 93 | return NULL; |
| 94 | } |
| 95 | EXPORT_SYMBOL_GPL(sst_acpi_find_machine); |
Vinod Koul | 8ceffd2 | 2016-02-08 10:45:39 +0530 | [diff] [blame] | 96 | |
Pierre-Louis Bossart | 3421894 | 2016-11-12 18:07:44 -0600 | [diff] [blame] | 97 | static acpi_status sst_acpi_find_package(acpi_handle handle, u32 level, |
| 98 | void *context, void **ret) |
| 99 | { |
| 100 | struct acpi_device *adev; |
| 101 | acpi_status status = AE_OK; |
| 102 | struct sst_acpi_package_context *pkg_ctx = context; |
| 103 | |
| 104 | pkg_ctx->data_valid = false; |
| 105 | |
| 106 | if (acpi_bus_get_device(handle, &adev)) |
| 107 | return AE_OK; |
| 108 | |
| 109 | if (adev->status.present && adev->status.functional) { |
| 110 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 111 | union acpi_object *myobj = NULL; |
| 112 | |
| 113 | status = acpi_evaluate_object_typed(handle, pkg_ctx->name, |
| 114 | NULL, &buffer, |
| 115 | ACPI_TYPE_PACKAGE); |
| 116 | if (ACPI_FAILURE(status)) |
| 117 | return AE_OK; |
| 118 | |
| 119 | myobj = buffer.pointer; |
| 120 | if (!myobj || myobj->package.count != pkg_ctx->length) { |
| 121 | kfree(buffer.pointer); |
| 122 | return AE_OK; |
| 123 | } |
| 124 | |
| 125 | status = acpi_extract_package(myobj, |
| 126 | pkg_ctx->format, pkg_ctx->state); |
| 127 | if (ACPI_FAILURE(status)) { |
| 128 | kfree(buffer.pointer); |
| 129 | return AE_OK; |
| 130 | } |
| 131 | |
| 132 | kfree(buffer.pointer); |
| 133 | pkg_ctx->data_valid = true; |
| 134 | return AE_CTRL_TERMINATE; |
| 135 | } |
| 136 | |
| 137 | return AE_OK; |
| 138 | } |
| 139 | |
| 140 | bool sst_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN], |
| 141 | struct sst_acpi_package_context *ctx) |
| 142 | { |
| 143 | acpi_status status; |
| 144 | |
| 145 | status = acpi_get_devices(hid, sst_acpi_find_package, ctx, NULL); |
| 146 | |
| 147 | if (ACPI_FAILURE(status) || !ctx->data_valid) |
| 148 | return false; |
| 149 | |
| 150 | return true; |
| 151 | } |
| 152 | EXPORT_SYMBOL_GPL(sst_acpi_find_package_from_hid); |
| 153 | |
Vinod Koul | 8ceffd2 | 2016-02-08 10:45:39 +0530 | [diff] [blame] | 154 | MODULE_LICENSE("GPL v2"); |
| 155 | MODULE_DESCRIPTION("Intel Common ACPI Match module"); |