From owner-svn-src-head@freebsd.org Mon Oct 22 03:29:55 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 941EEFE59F2; Mon, 22 Oct 2018 03:29:55 +0000 (UTC) (envelope-from bwidawsk@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4A062851E5; Mon, 22 Oct 2018 03:29:55 +0000 (UTC) (envelope-from bwidawsk@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 44FC616BE9; Mon, 22 Oct 2018 03:29:55 +0000 (UTC) (envelope-from bwidawsk@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w9M3TtSP070475; Mon, 22 Oct 2018 03:29:55 GMT (envelope-from bwidawsk@FreeBSD.org) Received: (from bwidawsk@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w9M3Tsx4070473; Mon, 22 Oct 2018 03:29:54 GMT (envelope-from bwidawsk@FreeBSD.org) Message-Id: <201810220329.w9M3Tsx4070473@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bwidawsk set sender to bwidawsk@FreeBSD.org using -f From: Ben Widawsky Date: Mon, 22 Oct 2018 03:29:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339577 - head/sys/dev/acpica X-SVN-Group: head X-SVN-Commit-Author: bwidawsk X-SVN-Commit-Paths: head/sys/dev/acpica X-SVN-Commit-Revision: 339577 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Oct 2018 03:29:55 -0000 Author: bwidawsk Date: Mon Oct 22 03:29:54 2018 New Revision: 339577 URL: https://svnweb.freebsd.org/changeset/base/339577 Log: acpi: Add an interface to obtain DSM information The Device Specific Method (_DSM) is on optional object that defines device specific controls. This will be useful for our power management controller in upcoming patches. More information can be found in ACPI spec 6.2 section 9.1.1 https://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf This patch had a minor modification changing ENOMEM to AE_NO_MEMORY after it got review and approval but before committing. Test Plan: Tested in my s0ix branch Reviewed by: kib Approved by: emaste (mentor) Differential Revision: https://reviews.freebsd.org/D17121 Modified: head/sys/dev/acpica/acpi.c head/sys/dev/acpica/acpivar.h Modified: head/sys/dev/acpica/acpi.c ============================================================================== --- head/sys/dev/acpica/acpi.c Mon Oct 22 02:42:14 2018 (r339576) +++ head/sys/dev/acpica/acpi.c Mon Oct 22 03:29:54 2018 (r339577) @@ -2570,6 +2570,98 @@ acpi_AppendBufferResource(ACPI_BUFFER *buf, ACPI_RESOU return (AE_OK); } +UINT8 +acpi_DSMQuery(ACPI_HANDLE h, uint8_t *uuid, int revision) +{ + /* + * ACPI spec 9.1.1 defines this. + * + * "Arg2: Function Index Represents a specific function whose meaning is + * specific to the UUID and Revision ID. Function indices should start + * with 1. Function number zero is a query function (see the special + * return code defined below)." + */ + ACPI_BUFFER buf; + ACPI_OBJECT *obj; + UINT8 ret = 0; + + if (!ACPI_SUCCESS(acpi_EvaluateDSM(h, uuid, revision, 0, NULL, &buf))) { + ACPI_INFO(("Failed to enumerate DSM functions\n")); + return (0); + } + + obj = (ACPI_OBJECT *)buf.Pointer; + KASSERT(obj, ("Object not allowed to be NULL\n")); + + /* + * From ACPI 6.2 spec 9.1.1: + * If Function Index = 0, a Buffer containing a function index bitfield. + * Otherwise, the return value and type depends on the UUID and revision + * ID (see below). + */ + switch (obj->Type) { + case ACPI_TYPE_BUFFER: + ret = *(uint8_t *)obj->Buffer.Pointer; + break; + case ACPI_TYPE_INTEGER: + ACPI_BIOS_WARNING((AE_INFO, + "Possibly buggy BIOS with ACPI_TYPE_INTEGER for function enumeration\n")); + ret = obj->Integer.Value & 0xFF; + break; + default: + ACPI_WARNING((AE_INFO, "Unexpected return type %u\n", obj->Type)); + }; + + AcpiOsFree(obj); + return ret; +} + +/* + * DSM may return multiple types depending on the function. It is therefore + * unsafe to use the typed evaluation. It is highly recommended that the caller + * check the type of the returned object. + */ +ACPI_STATUS +acpi_EvaluateDSM(ACPI_HANDLE handle, uint8_t *uuid, int revision, + uint64_t function, union acpi_object *package, ACPI_BUFFER *out_buf) +{ + ACPI_OBJECT arg[4]; + ACPI_OBJECT_LIST arglist; + ACPI_BUFFER buf; + ACPI_STATUS status; + + if (out_buf == NULL) + return (AE_NO_MEMORY); + + arg[0].Type = ACPI_TYPE_BUFFER; + arg[0].Buffer.Length = ACPI_UUID_LENGTH; + arg[0].Buffer.Pointer = uuid; + arg[1].Type = ACPI_TYPE_INTEGER; + arg[1].Integer.Value = revision; + arg[2].Type = ACPI_TYPE_INTEGER; + arg[2].Integer.Value = function; + if (package) { + arg[3] = *package; + } else { + arg[3].Type = ACPI_TYPE_PACKAGE; + arg[3].Package.Count = 0; + arg[3].Package.Elements = NULL; + } + + arglist.Pointer = arg; + arglist.Count = 4; + buf.Pointer = NULL; + buf.Length = ACPI_ALLOCATE_BUFFER; + status = AcpiEvaluateObject(handle, "_DSM", &arglist, &buf); + if (ACPI_FAILURE(status)) + return (status); + + KASSERT(ACPI_SUCCESS(status), ("Unexpected status")); + + *out_buf = buf; + return (status); +} + ACPI_STATUS acpi_EvaluateOSC(ACPI_HANDLE handle, uint8_t *uuid, int revision, int count, uint32_t *caps_in, uint32_t *caps_out, bool query) Modified: head/sys/dev/acpica/acpivar.h ============================================================================== --- head/sys/dev/acpica/acpivar.h Mon Oct 22 02:42:14 2018 (r339576) +++ head/sys/dev/acpica/acpivar.h Mon Oct 22 03:29:54 2018 (r339577) @@ -349,6 +349,10 @@ ACPI_STATUS acpi_FindIndexedResource(ACPI_BUFFER *buf, ACPI_RESOURCE **resp); ACPI_STATUS acpi_AppendBufferResource(ACPI_BUFFER *buf, ACPI_RESOURCE *res); +UINT8 acpi_DSMQuery(ACPI_HANDLE h, uint8_t *uuid, int revision); +ACPI_STATUS acpi_EvaluateDSM(ACPI_HANDLE handle, uint8_t *uuid, + int revision, uint64_t function, union acpi_object *package, + ACPI_BUFFER *out_buf); ACPI_STATUS acpi_EvaluateOSC(ACPI_HANDLE handle, uint8_t *uuid, int revision, int count, uint32_t *caps_in, uint32_t *caps_out, bool query);