• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 /* Author: Dan Scally <djrscally@gmail.com> */
3 
4 #include <linux/acpi.h>
5 #include <linux/slab.h>
6 
7 #include "common.h"
8 
skl_int3472_get_acpi_buffer(struct acpi_device * adev,char * id)9 union acpi_object *skl_int3472_get_acpi_buffer(struct acpi_device *adev, char *id)
10 {
11 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
12 	acpi_handle handle = adev->handle;
13 	union acpi_object *obj;
14 	acpi_status status;
15 
16 	status = acpi_evaluate_object(handle, id, NULL, &buffer);
17 	if (ACPI_FAILURE(status))
18 		return ERR_PTR(-ENODEV);
19 
20 	obj = buffer.pointer;
21 	if (!obj)
22 		return ERR_PTR(-ENODEV);
23 
24 	if (obj->type != ACPI_TYPE_BUFFER) {
25 		acpi_handle_err(handle, "%s object is not an ACPI buffer\n", id);
26 		kfree(obj);
27 		return ERR_PTR(-EINVAL);
28 	}
29 
30 	return obj;
31 }
32 
skl_int3472_fill_cldb(struct acpi_device * adev,struct int3472_cldb * cldb)33 int skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb)
34 {
35 	union acpi_object *obj;
36 	int ret;
37 
38 	obj = skl_int3472_get_acpi_buffer(adev, "CLDB");
39 	if (IS_ERR(obj))
40 		return PTR_ERR(obj);
41 
42 	if (obj->buffer.length > sizeof(*cldb)) {
43 		acpi_handle_err(adev->handle, "The CLDB buffer is too large\n");
44 		ret = -EINVAL;
45 		goto out_free_obj;
46 	}
47 
48 	memcpy(cldb, obj->buffer.pointer, obj->buffer.length);
49 	ret = 0;
50 
51 out_free_obj:
52 	kfree(obj);
53 	return ret;
54 }
55