Linux Audio

Check our new training course

Loading...
Note: File does not exist in v3.1.
  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
 17#include "sst-acpi.h"
 18
 19static 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
 37const 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}
 50EXPORT_SYMBOL_GPL(sst_acpi_find_name_from_hid);
 51
 52static acpi_status sst_acpi_mach_match(acpi_handle handle, u32 level,
 53				       void *context, void **ret)
 54{
 55	unsigned long long sta;
 56	acpi_status status;
 57
 58	*(bool *)context = true;
 59	status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
 60	if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_PRESENT))
 61		*(bool *)context = false;
 62
 63	return AE_OK;
 64}
 65
 66struct sst_acpi_mach *sst_acpi_find_machine(struct sst_acpi_mach *machines)
 67{
 68	struct sst_acpi_mach *mach;
 69	bool found = false;
 70
 71	for (mach = machines; mach->id[0]; mach++)
 72		if (ACPI_SUCCESS(acpi_get_devices(mach->id,
 73						  sst_acpi_mach_match,
 74						  &found, NULL)) && found)
 75			return mach;
 76	return NULL;
 77}
 78EXPORT_SYMBOL_GPL(sst_acpi_find_machine);
 79
 80static acpi_status sst_acpi_find_package(acpi_handle handle, u32 level,
 81					void *context, void **ret)
 82{
 83	struct acpi_device *adev;
 84	acpi_status status = AE_OK;
 85	struct sst_acpi_package_context *pkg_ctx = context;
 86
 87	pkg_ctx->data_valid = false;
 88
 89	if (acpi_bus_get_device(handle, &adev))
 90		return AE_OK;
 91
 92	if (adev->status.present && adev->status.functional) {
 93		struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
 94		union acpi_object  *myobj = NULL;
 95
 96		status = acpi_evaluate_object_typed(handle, pkg_ctx->name,
 97						NULL, &buffer,
 98						ACPI_TYPE_PACKAGE);
 99		if (ACPI_FAILURE(status))
100			return AE_OK;
101
102		myobj = buffer.pointer;
103		if (!myobj || myobj->package.count != pkg_ctx->length) {
104			kfree(buffer.pointer);
105			return AE_OK;
106		}
107
108		status = acpi_extract_package(myobj,
109					pkg_ctx->format, pkg_ctx->state);
110		if (ACPI_FAILURE(status)) {
111			kfree(buffer.pointer);
112			return AE_OK;
113		}
114
115		kfree(buffer.pointer);
116		pkg_ctx->data_valid = true;
117		return AE_CTRL_TERMINATE;
118	}
119
120	return AE_OK;
121}
122
123bool sst_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
124				struct sst_acpi_package_context *ctx)
125{
126	acpi_status status;
127
128	status = acpi_get_devices(hid, sst_acpi_find_package, ctx, NULL);
129
130	if (ACPI_FAILURE(status) || !ctx->data_valid)
131		return false;
132
133	return true;
134}
135EXPORT_SYMBOL_GPL(sst_acpi_find_package_from_hid);
136
137MODULE_LICENSE("GPL v2");
138MODULE_DESCRIPTION("Intel Common ACPI Match module");