1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 2 /* Copyright(c) 2021-2023 Realtek Corporation 3 */ 4 5 #include <linux/acpi.h> 6 #include <linux/uuid.h> 7 8 #include "acpi.h" 9 #include "debug.h" 10 11 static const guid_t rtw89_guid = GUID_INIT(0xD2A8C3E8, 0x4B69, 0x4F00, 12 0x82, 0xBD, 0xFE, 0x86, 13 0x07, 0x80, 0x3A, 0xA7); 14 15 static int rtw89_acpi_dsm_get(struct rtw89_dev *rtwdev, union acpi_object *obj, 16 u8 *value) 17 { 18 switch (obj->type) { 19 case ACPI_TYPE_INTEGER: 20 *value = (u8)obj->integer.value; 21 break; 22 case ACPI_TYPE_BUFFER: 23 *value = obj->buffer.pointer[0]; 24 break; 25 default: 26 rtw89_debug(rtwdev, RTW89_DBG_UNEXP, 27 "acpi dsm return unhandled type: %d\n", obj->type); 28 return -EINVAL; 29 } 30 31 return 0; 32 } 33 34 int rtw89_acpi_evaluate_dsm(struct rtw89_dev *rtwdev, 35 enum rtw89_acpi_dsm_func func, u8 *value) 36 { 37 union acpi_object *obj; 38 int ret; 39 40 obj = acpi_evaluate_dsm(ACPI_HANDLE(rtwdev->dev), &rtw89_guid, 41 0, func, NULL); 42 if (!obj) { 43 rtw89_debug(rtwdev, RTW89_DBG_UNEXP, 44 "acpi dsm fail to evaluate func: %d\n", func); 45 return -ENOENT; 46 } 47 48 ret = rtw89_acpi_dsm_get(rtwdev, obj, value); 49 50 ACPI_FREE(obj); 51 return ret; 52 } 53