From nobody Sat Feb 17 21:33:17 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Tchqf1TFZz59lH2; Sat, 17 Feb 2024 21:33:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Tchqd6FHvz4hxR; Sat, 17 Feb 2024 21:33:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708205597; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=MA6u48oDy0tLZpkObbEbd46uMOscoE/fb19U7MxT45Q=; b=GktJ9hcE8vfBd1Tyesa0zYfiJub6wdQmoIGS94B8Czpj4G8S4jnI/oOz4Boz/JwUBSh3VJ CBGF2m/o0IiAWGnP8M6fWqIl3sJj4Ggrj/5MbOlS7KjUgc/onycOedlYmXwD314Xz8hLrp k7c08gPOHWt6V5uDZiBYbBL49vuRJU2qzIT82K8H4piFslNnb0OMKayk3AuJEtuphwhgfv lcGaatAm2XwVJqMISIkbIqEm3LJfsQJWlvfHSQJ2lyoqLLxQQhcD+8E8T3GHPVtQQr8SPK xQIa9vCBlpixh0W95/y88Dy7IaePpXcYck+t8Xs1RjfZftVlkvd0FrZYa3jjhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708205597; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=MA6u48oDy0tLZpkObbEbd46uMOscoE/fb19U7MxT45Q=; b=H6QOeMZzl1ORjbzfPt1lNI0BM3sbAFzi1eKkeZ12eXfi1TRT3YvmlrHLtv0iK6tSUncAim aeUsM/fSSESh1ifnXjDcj+Z6Y0gy/3w1bUeDJlJUDahhrbs4ruHNje4ItEeqE11iRI3uKE AWZvyQeaUUGU7CwJ+OhTcU+9hApLwZXYfEPs0KweiBjyNxGx1ctfxZNivCSPvwHVwS8Gh/ Q1Wyz4Yg0/8PH8q1oI8OSYhy83yKmkHDVVi0LVaHlNO3EP3btFbJkoHt7LuWlvZkxHpwBH hBn7x5vVTxh0kYGYTRlQaBt690HncI2NKE0aiiub4cKQ9eN90hOTgjYrAj9shA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708205597; a=rsa-sha256; cv=none; b=hWh0Kzev/qJSy7ZxKFSjmtJcXoerca61pCwECEVlTxtkIWsz+OWSU/D/ZWWDkSn6wYI6vl mMZK3Z5z7jUiWV3vSYCowM5iueJ92kGsHTMzy1d5WGNnR8YnekMlnlCqMc5snWk5B3r5Dd SzV31TTXvr2YxpiExePIKdZSrQMwqGy2QjQDW0yG5bK8zZtPnwOfbWaelDpXxCbqqINAjc kMeTgP0Q27wnEyFiB0l1sv3ZrcBd2hp+kkqUjwUo4cEnUM+uJU6A5iXyOHffN5EpeyyIh8 T6STseZ1Lamfd3KY7BYFQufXJizQY6hMsmBcMy6PUpCPoCDMyB1TG/Be+k/Yeg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Tchqd5L0JzPJn; Sat, 17 Feb 2024 21:33:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41HLXHAw021484; Sat, 17 Feb 2024 21:33:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41HLXHvh021481; Sat, 17 Feb 2024 21:33:17 GMT (envelope-from git) Date: Sat, 17 Feb 2024 21:33:17 GMT Message-Id: <202402172133.41HLXHvh021481@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Vladimir Kondratyev Subject: git: 455fa56ad4fe - stable/14 - LinuxKPI: Add acpi_dev_present() function. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 455fa56ad4fecadeb8bf099c883d64d7a6bf9988 Auto-Submitted: auto-generated The branch stable/14 has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=455fa56ad4fecadeb8bf099c883d64d7a6bf9988 commit 455fa56ad4fecadeb8bf099c883d64d7a6bf9988 Author: Vladimir Kondratyev AuthorDate: 2023-12-24 08:20:00 +0000 Commit: Vladimir Kondratyev CommitDate: 2024-02-17 20:58:39 +0000 LinuxKPI: Add acpi_dev_present() function. acpi_dev_present detects that a given ACPI device is present based on Hardware ID, Unique ID and Hardware Revision of the device. Sponsored by: Serenity Cyber Security, LLC Reviewed by: manu MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D42823 (cherry picked from commit 04952a9456e226460d1d95c42ea53861b1133b1a) --- sys/compat/linuxkpi/common/include/acpi/acpi_bus.h | 4 ++ sys/compat/linuxkpi/common/src/linux_acpi.c | 79 ++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/acpi/acpi_bus.h b/sys/compat/linuxkpi/common/include/acpi/acpi_bus.h index 3db8e7df58f4..f107902a26ad 100644 --- a/sys/compat/linuxkpi/common/include/acpi/acpi_bus.h +++ b/sys/compat/linuxkpi/common/include/acpi/acpi_bus.h @@ -37,6 +37,8 @@ struct acpi_bus_event { uint32_t data; }; +#define acpi_dev_present(...) lkpi_acpi_dev_present(__VA_ARGS__) + ACPI_HANDLE bsd_acpi_get_handle(device_t bsddev); bool acpi_check_dsm(ACPI_HANDLE handle, const char *uuid, int rev, uint64_t funcs); @@ -46,5 +48,7 @@ ACPI_OBJECT * acpi_evaluate_dsm_typed(ACPI_HANDLE handle, const char *uuid, int register_acpi_notifier(struct notifier_block *nb); int unregister_acpi_notifier(struct notifier_block *nb); uint32_t acpi_target_system_state(void); +bool lkpi_acpi_dev_present(const char *hid, const char *uid, + int64_t hrv); #endif /* _LINUXKPI_ACPI_ACPI_BUS_H_ */ diff --git a/sys/compat/linuxkpi/common/src/linux_acpi.c b/sys/compat/linuxkpi/common/src/linux_acpi.c index 6e342c8e2caa..e7b6854ecf13 100644 --- a/sys/compat/linuxkpi/common/src/linux_acpi.c +++ b/sys/compat/linuxkpi/common/src/linux_acpi.c @@ -174,6 +174,79 @@ acpi_target_system_state(void) return (linux_acpi_target_sleep_state); } +struct acpi_dev_present_ctx { + const char *hid; + const char *uid; + int64_t hrv; +}; + +static ACPI_STATUS +acpi_dev_present_cb(ACPI_HANDLE handle, UINT32 level, void *context, + void **result) +{ + ACPI_DEVICE_INFO *devinfo; + struct acpi_dev_present_ctx *match = context; + bool present = false; + UINT32 sta, hrv; + int i; + + if (handle == NULL) + return (AE_OK); + + if (!ACPI_FAILURE(acpi_GetInteger(handle, "_STA", &sta)) && + !ACPI_DEVICE_PRESENT(sta)) + return (AE_OK); + + if (ACPI_FAILURE(AcpiGetObjectInfo(handle, &devinfo))) + return (AE_OK); + + if ((devinfo->Valid & ACPI_VALID_HID) != 0 && + strcmp(match->hid, devinfo->HardwareId.String) == 0) { + present = true; + } else if ((devinfo->Valid & ACPI_VALID_CID) != 0) { + for (i = 0; i < devinfo->CompatibleIdList.Count; i++) { + if (strcmp(match->hid, + devinfo->CompatibleIdList.Ids[i].String) == 0) { + present = true; + break; + } + } + } + if (present && match->uid != NULL && + ((devinfo->Valid & ACPI_VALID_UID) == 0 || + strcmp(match->uid, devinfo->UniqueId.String) != 0)) + present = false; + + AcpiOsFree(devinfo); + if (!present) + return (AE_OK); + + if (match->hrv != -1) { + if (ACPI_FAILURE(acpi_GetInteger(handle, "_HRV", &hrv))) + return (AE_OK); + if (hrv != match->hrv) + return (AE_OK); + } + + return (AE_ERROR); +} + +bool +lkpi_acpi_dev_present(const char *hid, const char *uid, int64_t hrv) +{ + struct acpi_dev_present_ctx match; + int rv; + + match.hid = hid; + match.uid = uid; + match.hrv = hrv; + + rv = AcpiWalkNamespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, + ACPI_UINT32_MAX, acpi_dev_present_cb, NULL, &match, NULL); + + return (rv == AE_ERROR); +} + static void linux_register_acpi_event_handlers(void *arg __unused) { @@ -241,4 +314,10 @@ acpi_target_system_state(void) return (ACPI_STATE_S0); } +bool +lkpi_acpi_dev_present(const char *hid, const char *uid, int64_t hrv) +{ + return (false); +} + #endif /* !DEV_ACPI */