From patchwork Thu Mar 12 00:57:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rajat Jain X-Patchwork-Id: 11433095 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C31A790 for ; Thu, 12 Mar 2020 00:57:40 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6BA252071B for ; Thu, 12 Mar 2020 00:57:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="FYhpNVF+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6BA252071B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 838156EA05; Thu, 12 Mar 2020 00:57:39 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-vk1-xa49.google.com (mail-vk1-xa49.google.com [IPv6:2607:f8b0:4864:20::a49]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1C7FD6EA05 for ; Thu, 12 Mar 2020 00:57:39 +0000 (UTC) Received: by mail-vk1-xa49.google.com with SMTP id n8so1674038vke.13 for ; Wed, 11 Mar 2020 17:57:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=9+NZL60hxKQVqLsC6LWr9zYj9I18UQ9y4TN5uOQMD5E=; b=FYhpNVF+Anhsb+ZCWqSGGuuOKlkVy2qEQjJdcJrxALzcFBRafcG+QuDIFNyefJcE0U oybNevbBU1b91/WoRDa2pk0jYi5b9wfl9FRx2dQKzsyTjFbZGV8p9rF4U+e6m6hswIsL sfWrZK7AnA97wBrPVf7tnBulMSEjwgwpiE2G5SMtkIM27LNmadVR3sLu3yg1SU9J69PW 7tzpcxMROI5Wtiy586p20ZfcGrNN6w9U7b4VQ/vNLIq1LdHFYJWbp+t6skpzs/psb6w2 zf/Lk74SHVUspL8gyI2J/wHOLQn58f0NKyuJ7P20OnoUa/QbEsHa8P4zFakYj7M+cOOM AmSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=9+NZL60hxKQVqLsC6LWr9zYj9I18UQ9y4TN5uOQMD5E=; b=GRPfL1xnyipLB8sADKvOpxypuMDJG/Zg7PYVxjOiYyubXNb3nN9y69BGOgomc6KeN6 YvdHntI+7F1KsjOw1dfRs1rSN3AR3vlLvmaJ5ufWo/Z3jmZSNRu5wKbK/h+rBlFtyj1x cURWEVK9FKAv32nXnkTdwunX809n1laPtjLHcrpyvx11pWYVPmdCVy66T8Wgt1w9Jq3h C/tzkSdg8nI4R6kk2aaenmwSg9+il7YnXdf7qGc7HbqztVhlZEF3w3gIVbsBA6+RoIDH KdG1hcLHN4o3Ocb0ag9XXyyN5NPvLVZYQQDiIQzqP/2lBwbimTC0/YwNO+ezHjMXnclU awoQ== X-Gm-Message-State: ANhLgQ03ODLGvpYcpg1i1WnrbOkl0mCt3EQnIUvHOGfphE6aT4WrgKXz jhZWjlEaN+4PdvbjYTCGPrLT05emh25B X-Google-Smtp-Source: ADFU+vtDaZvaf7oRnHi/dLlI6NjupwIimtwcS2AG3lGB96kzAsYgjBQqUml5Skxbv8u1hHcuXEOQt0Nbt+Ks X-Received: by 2002:a1f:9948:: with SMTP id b69mr3867845vke.13.1583974658082; Wed, 11 Mar 2020 17:57:38 -0700 (PDT) Date: Wed, 11 Mar 2020 17:57:21 -0700 In-Reply-To: <20200312005722.48803-1-rajatja@google.com> Message-Id: <20200312005722.48803-5-rajatja@google.com> Mime-Version: 1.0 References: <20200312005722.48803-1-rajatja@google.com> X-Mailer: git-send-email 2.25.1.481.gfbce0eb801-goog From: Rajat Jain To: Maarten Lankhorst , Maxime Ripard , Sean Paul , David Airlie , Daniel Vetter , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , " =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= " , Chris Wilson , Imre Deak , " =?utf-8?q?Jos=C3=A9_Roberto_de_Souza?= " , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, gregkh@linuxfoundation.org, mathewk@google.com, Daniel Thompson , Jonathan Corbet , Pavel Machek , seanpaul@google.com, Duncan Laurie , jsbarnes@google.com, Thierry Reding , mpearson@lenovo.com, Nitin Joshi1 , Sugumaran Lacshiminarayanan , Tomoki Maruichi Subject: [Intel-gfx] [PATCH v8 4/5] drm/i915: Add helper code for ACPI privacy screen X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: rajatxjain@gmail.com Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Add helper functions that can allow i915 to detect and control an integrated privacy screen via ACPI methods. These shall be used in the next patch. Signed-off-by: Rajat Jain --- v8: Initial version. formed by refactoring the previous patch 4. print the connector name in the debug messages. drivers/gpu/drm/i915/Makefile | 3 +- .../drm/i915/display/intel_privacy_screen.c | 184 ++++++++++++++++++ .../drm/i915/display/intel_privacy_screen.h | 27 +++ 3 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/i915/display/intel_privacy_screen.c create mode 100644 drivers/gpu/drm/i915/display/intel_privacy_screen.h diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile index 9f887a86e555d..da42389107f9c 100644 --- a/drivers/gpu/drm/i915/Makefile +++ b/drivers/gpu/drm/i915/Makefile @@ -209,7 +209,8 @@ i915-y += \ display/intel_vga.o i915-$(CONFIG_ACPI) += \ display/intel_acpi.o \ - display/intel_opregion.o + display/intel_opregion.o \ + display/intel_privacy_screen.o i915-$(CONFIG_DRM_FBDEV_EMULATION) += \ display/intel_fbdev.o diff --git a/drivers/gpu/drm/i915/display/intel_privacy_screen.c b/drivers/gpu/drm/i915/display/intel_privacy_screen.c new file mode 100644 index 0000000000000..66039103c821b --- /dev/null +++ b/drivers/gpu/drm/i915/display/intel_privacy_screen.c @@ -0,0 +1,184 @@ +// SPDX-License-Identifier: GPL-2.0 OR MIT +/* + * Intel ACPI privacy screen code + * + * Copyright © 2020 Google Inc. + * + * This code can help detect and control an integrated EPS (electronic + * privacy screen) via ACPI functions. It expects an ACPI node for the + * drm connector device with the following elements: + * + * UUID should be "c7033113-8720-4ceb-9090-9d52b3e52d73" + * + * _ADR = ACPI address per Spec (also see intel_acpi_device_id_update()) + * https://uefi.org/sites/default/files/resources/ACPI_6_3_final_Jan30.pdf + * Pages 1119 - 1123. + * + * _DSM method that will perform the following functions according to + * Local1 argument passed to it: + * - Local1 = 0 (EPS capabilities): Report EPS presence and capabilities. + * - Local1 = 1 (EPS State) : _DSM returns 1 if EPS is enabled, 0 otherwise. + * - Local1 = 2 (EPS Enable) : _DSM enables EPS + * - Local1 = 3 (EPS Disable): _DSM disables EPS + * + * Here is a sample ACPI node: + * + * Scope (\_SB.PCI0.GFX0) // Intel graphics device (PCI device) + * { + * Method (_DOD, 0, NotSerialized) // _DOD: Display Output Devices + * { + * Return (Package (0x01) + * { + * 0x80010400 + * }) + * } + * + * Device (LCD) + * { + * Name (_ADR, 0x80010400) // _ADR: Address + * Name (_STA, 0x0F) // _STA: Status + * + * Method (EPSP, 0, NotSerialized) // EPS Present + * { + * Return (0x01) + * } + * + * Method (EPSS, 0, NotSerialized) // EPS State + * { + * Local0 = \_SB.PCI0.GRXS (0xCD) + * Return (Local0) + * } + * + * Method (EPSE, 0, NotSerialized) // EPS Enable + * { + * \_SB.PCI0.STXS (0xCD) + * } + * + * Method (EPSD, 0, NotSerialized) // EPS Disable + * { + * \_SB.PCI0.CTXS (0xCD) + * } + * + * Method (_DSM, 4, Serialized) // _DSM: Device-Specific Method + * { + * ToBuffer (Arg0, Local0) + * If ((Local0 == ToUUID ("c7033113-8720-4ceb-9090-9d52b3e52d73"))) + * { + * ToInteger (Arg2, Local1) + * If ((Local1 == Zero)) + * { + * Local2 = EPSP () + * If ((Local2 == One)) + * { + * Return (Buffer (One) + * { + * 0x0F + * }) + * } + * } + * + * If ((Local1 == One)) + * { + * Return (EPSS ()) + * } + * + * If ((Local1 == 0x02)) + * { + * EPSE () + * } + * + * If ((Local1 == 0x03)) + * { + * EPSD () + * } + * + * Return (Buffer (One) + * { + * 0x00 + * }) + * } + * + * Return (Buffer (One) + * { + * 0x00 + * }) + * } + * } + * } + */ + +#include + +#include "intel_privacy_screen.h" + +#define CONN_NAME(conn) \ + (conn->base.kdev ? dev_name(conn->base.kdev) : "NONAME") + +#define CONNECTOR_DSM_REVID 1 + +#define CONNECTOR_DSM_FN_PRIVACY_ENABLE 2 +#define CONNECTOR_DSM_FN_PRIVACY_DISABLE 3 + +static const guid_t drm_conn_dsm_guid = + GUID_INIT(0xC7033113, 0x8720, 0x4CEB, + 0x90, 0x90, 0x9D, 0x52, 0xB3, 0xE5, 0x2D, 0x73); + +/* Makes _DSM call to set privacy screen status */ +static void acpi_privacy_screen_call_dsm(struct intel_connector *connector, + u64 func) +{ + union acpi_object *obj; + acpi_handle acpi_handle = connector->acpi_handle; + struct drm_device *drm = connector->base.dev; + + if (!acpi_handle) + return; + + obj = acpi_evaluate_dsm(acpi_handle, &drm_conn_dsm_guid, + CONNECTOR_DSM_REVID, func, NULL); + if (!obj) { + drm_err(drm, "%s: failed to evaluate _DSM for fn %llx\n", + CONN_NAME(connector), func); + return; + } + + ACPI_FREE(obj); +} + +void intel_privacy_screen_set_val(struct intel_connector *connector, + enum drm_privacy_screen_status val) +{ + struct drm_device *drm = connector->base.dev; + + if (val == PRIVACY_SCREEN_DISABLED) { + drm_dbg_kms(drm, "%s: disabling privacy-screen\n", + CONN_NAME(connector)); + acpi_privacy_screen_call_dsm(connector, + CONNECTOR_DSM_FN_PRIVACY_DISABLE); + } else { + drm_dbg_kms(drm, "%s: enabling privacy-screen\n", + CONN_NAME(connector)); + acpi_privacy_screen_call_dsm(connector, + CONNECTOR_DSM_FN_PRIVACY_ENABLE); + } +} + +bool intel_privacy_screen_present(struct intel_connector *connector) +{ + acpi_handle handle = connector->acpi_handle; + struct drm_device *drm = connector->base.dev; + + if (handle && + acpi_check_dsm(handle, &drm_conn_dsm_guid, + CONNECTOR_DSM_REVID, + 1 << CONNECTOR_DSM_FN_PRIVACY_ENABLE | + 1 << CONNECTOR_DSM_FN_PRIVACY_DISABLE)) { + drm_info(drm, "%s: supports ACPI privacy-screen\n", + CONN_NAME(connector)); + return true; + } + + drm_dbg_kms(drm, "%s: doesn't support ACPI privacy-screen\n", + CONN_NAME(connector)); + return false; +} diff --git a/drivers/gpu/drm/i915/display/intel_privacy_screen.h b/drivers/gpu/drm/i915/display/intel_privacy_screen.h new file mode 100644 index 0000000000000..8655745ff9085 --- /dev/null +++ b/drivers/gpu/drm/i915/display/intel_privacy_screen.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* + * Copyright © 2020 Google Inc. + */ + +#ifndef __DRM_PRIVACY_SCREEN_H__ +#define __DRM_PRIVACY_SCREEN_H__ + +#include "intel_display_types.h" + +#ifdef CONFIG_ACPI +bool intel_privacy_screen_present(struct intel_connector *connector); +void intel_privacy_screen_set_val(struct intel_connector *connector, + enum drm_privacy_screen_status val); +#else +static bool intel_privacy_screen_present(struct intel_connector *connector) +{ + return false; +} + +static void +intel_privacy_screen_set_val(struct intel_connector *connector, + enum drm_privacy_screen_status val) +{ } +#endif /* CONFIG_ACPI */ + +#endif /* __DRM_PRIVACY_SCREEN_H__ */