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 #if defined(__linux__) 12 static const guid_t rtw89_guid = GUID_INIT(0xD2A8C3E8, 0x4B69, 0x4F00, 13 0x82, 0xBD, 0xFE, 0x86, 14 0x07, 0x80, 0x3A, 0xA7); 15 16 static int rtw89_acpi_dsm_get(struct rtw89_dev *rtwdev, union acpi_object *obj, 17 u8 *value) 18 { 19 switch (obj->type) { 20 case ACPI_TYPE_INTEGER: 21 *value = (u8)obj->integer.value; 22 break; 23 case ACPI_TYPE_BUFFER: 24 *value = obj->buffer.pointer[0]; 25 break; 26 default: 27 rtw89_debug(rtwdev, RTW89_DBG_UNEXP, 28 "acpi dsm return unhandled type: %d\n", obj->type); 29 return -EINVAL; 30 } 31 32 return 0; 33 } 34 35 int rtw89_acpi_evaluate_dsm(struct rtw89_dev *rtwdev, 36 enum rtw89_acpi_dsm_func func, u8 *value) 37 { 38 union acpi_object *obj; 39 int ret; 40 41 obj = acpi_evaluate_dsm(ACPI_HANDLE(rtwdev->dev), &rtw89_guid, 42 0, func, NULL); 43 if (!obj) { 44 rtw89_debug(rtwdev, RTW89_DBG_UNEXP, 45 "acpi dsm fail to evaluate func: %d\n", func); 46 return -ENOENT; 47 } 48 49 ret = rtw89_acpi_dsm_get(rtwdev, obj, value); 50 51 ACPI_FREE(obj); 52 return ret; 53 } 54 #elif defined(__FreeBSD__) 55 int rtw89_acpi_evaluate_dsm(struct rtw89_dev *rtwdev, 56 enum rtw89_acpi_dsm_func func, u8 *value) 57 { 58 return -ENOENT; 59 } 60 #endif 61