From patchwork Thu Mar 12 18:56:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rajat Jain X-Patchwork-Id: 11435255 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 612ED161F for ; Thu, 12 Mar 2020 18:56:47 +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 3F3A220663 for ; Thu, 12 Mar 2020 18:56:47 +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="X4iIZhqW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F3A220663 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 BBAF96EB2D; Thu, 12 Mar 2020 18:56:45 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1F21D6EB2B for ; Thu, 12 Mar 2020 18:56:44 +0000 (UTC) Received: by mail-pj1-x1049.google.com with SMTP id gx20so3812472pjb.1 for ; Thu, 12 Mar 2020 11:56:44 -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=fffnx5Rt8GbetlYKB2cd5pIz6essNcsuoAoI5LuF7xg=; b=X4iIZhqW2R1TPVFTKsFPHVJVh7FZrTnez6T3Hnb2ogVxiFULIuQswnb3uNvHTh606L kWRMP1Tx6BAWqOg+Qs0JiEDXcJEU4zM4Ohfw5xl/sm4kMe1n9sPKdfJrN0z1wi5a1Q1T i4qb5AJG01eyY3aVK0eoelJnGDngWShfV9cW6ngScru79A2D+5C1UgLUjsPpHEI5afaH opdD/Mc/z9itjcXznh4HSOtfw6wiOR5CRgE7ukOMRwFZcf+9Kom1/g8UuoRBkRr7ToDv tZfqSwiwYOHvNngd8H1dChskW0VqROywIRFITHq3e8LVkBa3/+oujC2Vj8Mih90Nc1iR 7PIg== 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=fffnx5Rt8GbetlYKB2cd5pIz6essNcsuoAoI5LuF7xg=; b=ZZFV56SPIoOh7C4/eynCxHpAg7wrLwZrzb1a1+UNa1D6yWo6TIwaTHfrt2u97ihfA7 v54DpZVEfYdbSXg2vs/6xBL6ZNO2HwDwB8WHIuMcB2vqjmj1PWt0tEIOq4ZIfb62le1o Hce0eTbZq1hDSclnkvlzyycakVZS2fJwFGfuDluT6p/BiolJbNglsD/sjy8ggdt1zXc/ X2NjrR+9T+UYu79Hopi/lOdq6te1S0lUsKs8KemHugVZuu5ycmQx5/pGSEzKM3IVAvRM 0EkgzmEnKtxsJouCeyVGQoitkN3ekZJcNTnXK74pv+pIdLnKPZNDgyCBsmCDZUGyNTBz ncww== X-Gm-Message-State: ANhLgQ1ZHhJlrc9JBBqr76vQMUMWScw+QcDzjjn3duoq02PLUZqzbmnS MNU2t84kUlqBaqXlqXz/szdrpd3dOtsB X-Google-Smtp-Source: ADFU+vuP6Yt38fE514Tivo5Xppmxjai6z5GkzOYQXVK/NgqjwwtUr734FE8xx1ebnir8TiLeqL2+ALCsxTPU X-Received: by 2002:a17:90b:19ca:: with SMTP id nm10mr5375115pjb.161.1584039403652; Thu, 12 Mar 2020 11:56:43 -0700 (PDT) Date: Thu, 12 Mar 2020 11:56:28 -0700 In-Reply-To: <20200312185629.141280-1-rajatja@google.com> Message-Id: <20200312185629.141280-5-rajatja@google.com> Mime-Version: 1.0 References: <20200312185629.141280-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 v9 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 --- v9: same as v8 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__ */