Skip to contentSkip to conversation

drm/privacy_screen: Add drvdata in drm_privacy_screen

PATCH In review Rajat Jain 4 participants 9 messages Jan 7, 2022 – Jan 10, 2022

Subsystems (5)
lore
Share & tools
lore

Rajat Jain

author
#0 lore raw

PATCH v5 1/3 drm/privacy_screen: Add drvdata in drm_privacy_screen

Allow a privacy screen provider to stash its private data pointer in the drm_privacy_screen, and update the drm_privacy_screen_register() call to accept that. Also introduce a *_get_drvdata() so that it can retrieved back when needed.

This also touches the IBM Thinkpad platform driver, the only user of privacy screen today, to pass NULL for now to the updated API.

---
v5: Same as v4
v4: Added "Reviewed-by" from Hans
v3: Initial version. Came up due to review comments on v2 of other patches.
v2: No v2
v1: No v1

 drivers/gpu/drm/drm_privacy_screen.c    |  5 ++++-
 drivers/platform/x86/thinkpad_acpi.c    |  2 +-
 include/drm/drm_privacy_screen_driver.h | 13 ++++++++++++-
 3 files changed, 17 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_privacy_screen.c +4 -1
index beaf99e9120a..03b149cc455b 100644
@@ -387,7 +387,8 @@ static void drm_privacy_screen_device_release(struct device *dev)
  * * An ERR_PTR(errno) on failure.
  */
 struct drm_privacy_screen *drm_privacy_screen_register(
-	struct device *parent, const struct drm_privacy_screen_ops *ops)
+	struct device *parent, const struct drm_privacy_screen_ops *ops,
+	void *data)
 {
 	struct drm_privacy_screen *priv;
 	int ret;
@@ -404,6 +405,7 @@ struct drm_privacy_screen *drm_privacy_screen_register(
 	priv->dev.parent = parent;
 	priv->dev.release = drm_privacy_screen_device_release;
 	dev_set_name(&priv->dev, "privacy_screen-%s", dev_name(parent));
+	priv->drvdata = data;
 	priv->ops = ops;
 
 	priv->ops->get_hw_state(priv);
@@ -439,6 +441,7 @@ void drm_privacy_screen_unregister(struct drm_privacy_screen *priv)
 	mutex_unlock(&drm_privacy_screen_devs_lock);
 
 	mutex_lock(&priv->lock);
+	priv->drvdata = NULL;
 	priv->ops = NULL;
 	mutex_unlock(&priv->lock);
 
drivers/platform/x86/thinkpad_acpi.c +1 -1
index 341655d711ce..ccbfda2b0095 100644
@@ -9782,7 +9782,7 @@ static int tpacpi_lcdshadow_init(struct ibm_init_struct *iibm)
 		return 0;
 
 	lcdshadow_dev = drm_privacy_screen_register(&tpacpi_pdev->dev,
-						    &lcdshadow_ops);
+						    &lcdshadow_ops, NULL);
 	if (IS_ERR(lcdshadow_dev))
 		return PTR_ERR(lcdshadow_dev);
 
include/drm/drm_privacy_screen_driver.h +12 -1
index 24591b607675..4ef246d5706f 100644
@@ -73,10 +73,21 @@ struct drm_privacy_screen {
 	 * for more info.
 	 */
 	enum drm_privacy_screen_status hw_state;
+	/**
+	 * @drvdata: Private data owned by the privacy screen provider
+	 */
+	void *drvdata;
 };
 
+static inline
+void *drm_privacy_screen_get_drvdata(struct drm_privacy_screen *priv)
+{
+	return priv->drvdata;
+}
+
 struct drm_privacy_screen *drm_privacy_screen_register(
-	struct device *parent, const struct drm_privacy_screen_ops *ops);
+	struct device *parent, const struct drm_privacy_screen_ops *ops,
+	void *data);
 void drm_privacy_screen_unregister(struct drm_privacy_screen *priv);
 
 void drm_privacy_screen_call_notifier_chain(struct drm_privacy_screen *priv);
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
author
#1 lore raw

PATCH v5 2/3 platform/chrome: Add driver for ChromeOS privacy-screen

This adds the ACPI driver for the ChromeOS privacy screen that is present on some chromeos devices.

Note that ideally, we'd want this privacy screen driver to be probed BEFORE the drm probe in order to avoid a drm probe deferral:
https://hansdegoede.livejournal.com/25948.html

In practise, I found that ACPI drivers are bound to their devices AFTER the drm probe on chromebooks. So on chromebooks with privacy-screen, this patch along with the other one in this series results in a probe deferral of about 250ms for i915 driver. However, it did not result in any user noticeable delay of splash screen in my personal experience.

In future if this probe deferral turns out to be an issue, we can consider turning this ACPI driver into something that is probed earlier than the drm drivers.

---
v5: * Add blank line, 2 more vowels to the driver name as per comments
* Add Dmitry's "Reviewed by"
v4: Same as v3 (No changes)
v3: * Renamed everything chromeos_priv_scrn_* to chromeos_privacy_screen_*
(and added line breaks to accommodate longer names within 80 chars)
* Cleanup / Added few comments
* Use the newly added drm_privacy_screen_get_drvdata()
* Provide the cleanup function chromeos_privacy_screen_remove()
v2: * Reword the commit log
* Make the Kconfig into a tristate
* Reorder the patches in the series.

 drivers/platform/chrome/Kconfig               |  11 ++
 drivers/platform/chrome/Makefile              |   1 +
 .../platform/chrome/chromeos_privacy_screen.c | 153 ++++++++++++++++++
 3 files changed, 165 insertions(+)
 create mode 100644 drivers/platform/chrome/chromeos_privacy_screen.c
drivers/platform/chrome/Kconfig +11 -0
index ccc23d8686e8..75e93efd669f 100644
@@ -243,6 +243,17 @@ config CROS_USBPD_NOTIFY
 	  To compile this driver as a module, choose M here: the
 	  module will be called cros_usbpd_notify.
 
+config CHROMEOS_PRIVACY_SCREEN
+	tristate "ChromeOS Privacy Screen support"
+	depends on ACPI
+	depends on DRM
+	select DRM_PRIVACY_SCREEN
+	help
+	  This driver provides the support needed for the in-built electronic
+	  privacy screen that is present on some ChromeOS devices. When enabled,
+	  this should probably always be built into the kernel to avoid or
+	  minimize drm probe deferral.
+
 source "drivers/platform/chrome/wilco_ec/Kconfig"
 
 endif # CHROMEOS_PLATFORMS
drivers/platform/chrome/Makefile +1 -0
index f901d2e43166..5d4be9735d9d 100644
@@ -4,6 +4,7 @@
 CFLAGS_cros_ec_trace.o:=		-I$(src)
 
 obj-$(CONFIG_CHROMEOS_LAPTOP)		+= chromeos_laptop.o
+obj-$(CONFIG_CHROMEOS_PRIVACY_SCREEN)	+= chromeos_privacy_screen.o
 obj-$(CONFIG_CHROMEOS_PSTORE)		+= chromeos_pstore.o
 obj-$(CONFIG_CHROMEOS_TBMC)		+= chromeos_tbmc.o
 obj-$(CONFIG_CROS_EC)			+= cros_ec.o
drivers/platform/chrome/chromeos_privacy_screen.c new file +153 -0

153 lines not on this page · raw message

Signature · 1 line
2.34.1.575.g55b058a8bb-goog
author
#3 lore raw

PATCH v5 3/3 drm/privacy_screen_x86: Add entry for ChromeOS privacy-screen

In reply to Rajat Jain

Add a static entry in the x86 table, to detect and wait for privacy-screen on some ChromeOS platforms.

Please note that this means that if CONFIG_CHROMEOS_PRIVACY_SCREEN is enabled, and if "GOOG0010" device is found in ACPI, then the i915 probe shall return EPROBE_DEFER until a platform driver actually registers the
privacy-screen: https://hansdegoede.livejournal.com/25948.html

---
v5: * Add Hans' "Reviewed by"
v4: * Simplify the detect_chromeos_privacy_screen() function
* Don't change the existing print statement
v3: * Remove the pr_info() from detect_chromeos_privacy_screen(), instead
enhance the one already present in drm_privacy_screen_lookup_init()
v2: * Use #if instead of #elif
* Reorder the patches in the series.
* Rebased on drm-tip

 drivers/gpu/drm/drm_privacy_screen_x86.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/gpu/drm/drm_privacy_screen_x86.c +17 -0
index a2cafb294ca6..88802cd7a1ee 100644
@@ -47,6 +47,13 @@ static bool __init detect_thinkpad_privacy_screen(void)
 }
 #endif
 
+#if IS_ENABLED(CONFIG_CHROMEOS_PRIVACY_SCREEN)
+static bool __init detect_chromeos_privacy_screen(void)
+{
+	return acpi_dev_present("GOOG0010", NULL, -1);
+}
+#endif
+
 static const struct arch_init_data arch_init_data[] __initconst = {
 #if IS_ENABLED(CONFIG_THINKPAD_ACPI)
 	{
@@ -58,6 +65,16 @@ static const struct arch_init_data arch_init_data[] __initconst = {
 		.detect = detect_thinkpad_privacy_screen,
 	},
 #endif
+#if IS_ENABLED(CONFIG_CHROMEOS_PRIVACY_SCREEN)
+	{
+		.lookup = {
+			.dev_id = NULL,
+			.con_id = NULL,
+			.provider = "privacy_screen-GOOG0010:00",
+		},
+		.detect = detect_chromeos_privacy_screen,
+	},
+#endif
 };
 
 void __init drm_privacy_screen_lookup_init(void)
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
Acked-by on v5 3/3
#4 lore raw

Re: [PATCH v5 3/3] drm/privacy_screen_x86: Add entry for ChromeOS privacy-screen

Hi Rajat,

Thanks for your changes here.

Quoted 10 lines · Rajat Jain

Add a static entry in the x86 table, to detect and wait for privacy-screen on some ChromeOS platforms.

Please note that this means that if CONFIG_CHROMEOS_PRIVACY_SCREEN is enabled, and if "GOOG0010" device is found in ACPI, then the i915 probe shall return EPROBE_DEFER until a platform driver actually registers the
privacy-screen: https://hansdegoede.livejournal.com/25948.html

Hi Hans,

Since this change depends on the privacy screen changes staged for v5.17, I'm OK as platform/chrome maintainer to have this go through the drm tree.

Quoted 51 lines

---
v5: * Add Hans' "Reviewed by"
v4: * Simplify the detect_chromeos_privacy_screen() function
* Don't change the existing print statement
v3: * Remove the pr_info() from detect_chromeos_privacy_screen(), instead
enhance the one already present in drm_privacy_screen_lookup_init()
v2: * Use #if instead of #elif
* Reorder the patches in the series.
* Rebased on drm-tip

 drivers/gpu/drm/drm_privacy_screen_x86.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/gpu/drm/drm_privacy_screen_x86.c +17 -0
index a2cafb294ca6..88802cd7a1ee 100644
@@ -47,6 +47,13 @@ static bool __init detect_thinkpad_privacy_screen(void)
 }
 #endif
 
+#if IS_ENABLED(CONFIG_CHROMEOS_PRIVACY_SCREEN)
+static bool __init detect_chromeos_privacy_screen(void)
+{
+	return acpi_dev_present("GOOG0010", NULL, -1);
+}
+#endif
+
 static const struct arch_init_data arch_init_data[] __initconst = {
 #if IS_ENABLED(CONFIG_THINKPAD_ACPI)
 	{
@@ -58,6 +65,16 @@ static const struct arch_init_data arch_init_data[] __initconst = {
 		.detect = detect_thinkpad_privacy_screen,
 	},
 #endif
+#if IS_ENABLED(CONFIG_CHROMEOS_PRIVACY_SCREEN)
+	{
+		.lookup = {
+			.dev_id = NULL,
+			.con_id = NULL,
+			.provider = "privacy_screen-GOOG0010:00",
+		},
+		.detect = detect_chromeos_privacy_screen,
+	},
+#endif
 };
 
 void __init drm_privacy_screen_lookup_init(void)
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
Signature · 7 lines
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
[email protected]
Chromium OS Project
[email protected]
Acked-by on v5 2/3
#2 lore raw

Re: [PATCH v5 2/3] platform/chrome: Add driver for ChromeOS privacy-screen

In reply to Rajat Jain

Hi Rajat,

Quoted 13 lines · Rajat Jain

This adds the ACPI driver for the ChromeOS privacy screen that is present on some chromeos devices.

Note that ideally, we'd want this privacy screen driver to be probed BEFORE the drm probe in order to avoid a drm probe deferral:
https://hansdegoede.livejournal.com/25948.html

In practise, I found that ACPI drivers are bound to their devices AFTER the drm probe on chromebooks. So on chromebooks with privacy-screen, this patch along with the other one in this series results in a probe deferral of about 250ms for i915 driver. However, it did not result in any user noticeable delay of splash screen in my personal experience.

Quoted 6 lines

In future if this probe deferral turns out to be an issue, we can consider turning this ACPI driver into something that is probed earlier than the drm drivers.

Hi Hans,

Could you take this patch? This new driver in platform/chrome depends on the drm/drm_privacy_screen_driver.h header in your tree.

Thanks!

Quoted 215 lines

---
v5: * Add blank line, 2 more vowels to the driver name as per comments
* Add Dmitry's "Reviewed by"
v4: Same as v3 (No changes)
v3: * Renamed everything chromeos_priv_scrn_* to chromeos_privacy_screen_*
(and added line breaks to accommodate longer names within 80 chars)
* Cleanup / Added few comments
* Use the newly added drm_privacy_screen_get_drvdata()
* Provide the cleanup function chromeos_privacy_screen_remove()
v2: * Reword the commit log
* Make the Kconfig into a tristate
* Reorder the patches in the series.

 drivers/platform/chrome/Kconfig               |  11 ++
 drivers/platform/chrome/Makefile              |   1 +
 .../platform/chrome/chromeos_privacy_screen.c | 153 ++++++++++++++++++
 3 files changed, 165 insertions(+)
 create mode 100644 drivers/platform/chrome/chromeos_privacy_screen.c
drivers/platform/chrome/Kconfig +11 -0
index ccc23d8686e8..75e93efd669f 100644
@@ -243,6 +243,17 @@ config CROS_USBPD_NOTIFY
 	  To compile this driver as a module, choose M here: the
 	  module will be called cros_usbpd_notify.
 
+config CHROMEOS_PRIVACY_SCREEN
+	tristate "ChromeOS Privacy Screen support"
+	depends on ACPI
+	depends on DRM
+	select DRM_PRIVACY_SCREEN
+	help
+	  This driver provides the support needed for the in-built electronic
+	  privacy screen that is present on some ChromeOS devices. When enabled,
+	  this should probably always be built into the kernel to avoid or
+	  minimize drm probe deferral.
+
 source "drivers/platform/chrome/wilco_ec/Kconfig"
 
 endif # CHROMEOS_PLATFORMS
drivers/platform/chrome/Makefile +1 -0
index f901d2e43166..5d4be9735d9d 100644
@@ -4,6 +4,7 @@
 CFLAGS_cros_ec_trace.o:=		-I$(src)
 
 obj-$(CONFIG_CHROMEOS_LAPTOP)		+= chromeos_laptop.o
+obj-$(CONFIG_CHROMEOS_PRIVACY_SCREEN)	+= chromeos_privacy_screen.o
 obj-$(CONFIG_CHROMEOS_PSTORE)		+= chromeos_pstore.o
 obj-$(CONFIG_CHROMEOS_TBMC)		+= chromeos_tbmc.o
 obj-$(CONFIG_CROS_EC)			+= cros_ec.o
drivers/platform/chrome/chromeos_privacy_screen.c new file +153 -0
new file mode 100644
index 000000000000..77e9f5ee8e33
@@ -0,0 +1,153 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ *  ChromeOS Privacy Screen support
+ *
+ * Copyright (C) 2022 Google LLC
+ *
+ * This is the Chromeos privacy screen provider, present on certain chromebooks,
+ * represented by a GOOG0010 device in the ACPI. This ACPI device, if present,
+ * will cause the i915 drm driver to probe defer until this driver registers
+ * the privacy-screen.
+ */
+
+#include <linux/acpi.h>
+#include <drm/drm_privacy_screen_driver.h>
+
+/*
+ * The DSM (Device Specific Method) constants below are the agreed API with
+ * the firmware team, on how to control privacy screen using ACPI methods.
+ */
+#define PRIV_SCRN_DSM_REVID		1	/* DSM version */
+#define PRIV_SCRN_DSM_FN_GET_STATUS	1	/* Get privacy screen status */
+#define PRIV_SCRN_DSM_FN_ENABLE		2	/* Enable privacy screen */
+#define PRIV_SCRN_DSM_FN_DISABLE	3	/* Disable privacy screen */
+
+static const guid_t chromeos_privacy_screen_dsm_guid =
+		    GUID_INIT(0xc7033113, 0x8720, 0x4ceb,
+			      0x90, 0x90, 0x9d, 0x52, 0xb3, 0xe5, 0x2d, 0x73);
+
+static void
+chromeos_privacy_screen_get_hw_state(struct drm_privacy_screen
+				     *drm_privacy_screen)
+{
+	union acpi_object *obj;
+	acpi_handle handle;
+	struct device *privacy_screen =
+		drm_privacy_screen_get_drvdata(drm_privacy_screen);
+
+	handle = acpi_device_handle(to_acpi_device(privacy_screen));
+	obj = acpi_evaluate_dsm(handle, &chromeos_privacy_screen_dsm_guid,
+				PRIV_SCRN_DSM_REVID,
+				PRIV_SCRN_DSM_FN_GET_STATUS, NULL);
+	if (!obj) {
+		dev_err(privacy_screen,
+			"_DSM failed to get privacy-screen state\n");
+		return;
+	}
+
+	if (obj->type != ACPI_TYPE_INTEGER)
+		dev_err(privacy_screen,
+			"Bad _DSM to get privacy-screen state\n");
+	else if (obj->integer.value == 1)
+		drm_privacy_screen->hw_state = drm_privacy_screen->sw_state =
+			PRIVACY_SCREEN_ENABLED;
+	else
+		drm_privacy_screen->hw_state = drm_privacy_screen->sw_state =
+			PRIVACY_SCREEN_DISABLED;
+
+	ACPI_FREE(obj);
+}
+
+static int
+chromeos_privacy_screen_set_sw_state(struct drm_privacy_screen
+				     *drm_privacy_screen,
+				     enum drm_privacy_screen_status state)
+{
+	union acpi_object *obj = NULL;
+	acpi_handle handle;
+	struct device *privacy_screen =
+		drm_privacy_screen_get_drvdata(drm_privacy_screen);
+
+	handle = acpi_device_handle(to_acpi_device(privacy_screen));
+
+	if (state == PRIVACY_SCREEN_DISABLED) {
+		obj = acpi_evaluate_dsm(handle,
+					&chromeos_privacy_screen_dsm_guid,
+					PRIV_SCRN_DSM_REVID,
+					PRIV_SCRN_DSM_FN_DISABLE, NULL);
+	} else if (state == PRIVACY_SCREEN_ENABLED) {
+		obj = acpi_evaluate_dsm(handle,
+					&chromeos_privacy_screen_dsm_guid,
+					PRIV_SCRN_DSM_REVID,
+					PRIV_SCRN_DSM_FN_ENABLE, NULL);
+	} else {
+		dev_err(privacy_screen,
+			"Bad attempt to set privacy-screen status to %u\n",
+			state);
+		return -EINVAL;
+	}
+
+	if (!obj) {
+		dev_err(privacy_screen,
+			"_DSM failed to set privacy-screen state\n");
+		return -EIO;
+	}
+
+	drm_privacy_screen->hw_state = drm_privacy_screen->sw_state = state;
+	ACPI_FREE(obj);
+	return 0;
+}
+
+static const struct drm_privacy_screen_ops chromeos_privacy_screen_ops = {
+	.get_hw_state = chromeos_privacy_screen_get_hw_state,
+	.set_sw_state = chromeos_privacy_screen_set_sw_state,
+};
+
+static int chromeos_privacy_screen_add(struct acpi_device *adev)
+{
+	struct drm_privacy_screen *drm_privacy_screen =
+		drm_privacy_screen_register(&adev->dev,
+					    &chromeos_privacy_screen_ops,
+					    &adev->dev);
+
+	if (IS_ERR(drm_privacy_screen)) {
+		dev_err(&adev->dev, "Error registering privacy-screen\n");
+		return PTR_ERR(drm_privacy_screen);
+	}
+
+	adev->driver_data = drm_privacy_screen;
+	dev_info(&adev->dev, "registered privacy-screen '%s'\n",
+		 dev_name(&drm_privacy_screen->dev));
+
+	return 0;
+}
+
+static int chromeos_privacy_screen_remove(struct acpi_device *adev)
+{
+	struct drm_privacy_screen *drm_privacy_screen =	acpi_driver_data(adev);
+
+	drm_privacy_screen_unregister(drm_privacy_screen);
+	return 0;
+}
+
+static const struct acpi_device_id chromeos_privacy_screen_device_ids[] = {
+	{"GOOG0010", 0}, /* Google's electronic privacy screen for eDP-1 */
+	{}
+};
+MODULE_DEVICE_TABLE(acpi, chromeos_privacy_screen_device_ids);
+
+static struct acpi_driver chromeos_privacy_screen_driver = {
+	.name = "chromeos_privacy_screen_driver",
+	.class = "ChromeOS",
+	.ids = chromeos_privacy_screen_device_ids,
+	.ops = {
+		.add = chromeos_privacy_screen_add,
+		.remove = chromeos_privacy_screen_remove,
+	},
+};
+
+module_acpi_driver(chromeos_privacy_screen_driver);
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("ChromeOS ACPI Privacy Screen driver");
+MODULE_AUTHOR("Rajat Jain <[email protected]>");
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
Signature · 7 lines
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
[email protected]
Chromium OS Project
[email protected]
#5 lore raw

Re: [PATCH v5 3/3] drm/privacy_screen_x86: Add entry for ChromeOS privacy-screen

In reply to Benson Leung

Hi All,

Quoted 16 lines · Benson Leung

Hi Rajat,

Thanks for your changes here.

Quoted 10 lines · Rajat Jain

Add a static entry in the x86 table, to detect and wait for privacy-screen on some ChromeOS platforms.

Please note that this means that if CONFIG_CHROMEOS_PRIVACY_SCREEN is enabled, and if "GOOG0010" device is found in ACPI, then the i915 probe shall return EPROBE_DEFER until a platform driver actually registers the
privacy-screen: https://hansdegoede.livejournal.com/25948.html

Quoted 6 lines

Hi Hans,

Since this change depends on the privacy screen changes staged for v5.17, I'm OK as platform/chrome maintainer to have this go through the drm tree.

Ok, I will merge this into drm-misc-next coming Monday.

Note I'm afraid that it is too late for 5.17, the drm-misc maintainers have already created the final drm-misc tag for the 5.17 pull-req.

Regards,

Hans

Quoted 54 lines
Quoted 53 lines

---
v5: * Add Hans' "Reviewed by"
v4: * Simplify the detect_chromeos_privacy_screen() function
* Don't change the existing print statement
v3: * Remove the pr_info() from detect_chromeos_privacy_screen(), instead
enhance the one already present in drm_privacy_screen_lookup_init()
v2: * Use #if instead of #elif
* Reorder the patches in the series.
* Rebased on drm-tip

 drivers/gpu/drm/drm_privacy_screen_x86.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/gpu/drm/drm_privacy_screen_x86.c +17 -0
index a2cafb294ca6..88802cd7a1ee 100644
@@ -47,6 +47,13 @@ static bool __init detect_thinkpad_privacy_screen(void)
 }
 #endif
 
+#if IS_ENABLED(CONFIG_CHROMEOS_PRIVACY_SCREEN)
+static bool __init detect_chromeos_privacy_screen(void)
+{
+	return acpi_dev_present("GOOG0010", NULL, -1);
+}
+#endif
+
 static const struct arch_init_data arch_init_data[] __initconst = {
 #if IS_ENABLED(CONFIG_THINKPAD_ACPI)
 	{
@@ -58,6 +65,16 @@ static const struct arch_init_data arch_init_data[] __initconst = {
 		.detect = detect_thinkpad_privacy_screen,
 	},
 #endif
+#if IS_ENABLED(CONFIG_CHROMEOS_PRIVACY_SCREEN)
+	{
+		.lookup = {
+			.dev_id = NULL,
+			.con_id = NULL,
+			.provider = "privacy_screen-GOOG0010:00",
+		},
+		.detect = detect_chromeos_privacy_screen,
+	},
+#endif
 };
 
 void __init drm_privacy_screen_lookup_init(void)
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
author
#6 lore raw

Re: [PATCH v5 3/3] drm/privacy_screen_x86: Add entry for ChromeOS privacy-screen

Quoted 20 lines · Hans de Goede

Hi All,

Quoted 16 lines · Benson Leung

Hi Rajat,

Thanks for your changes here.

Quoted 10 lines · Rajat Jain

Add a static entry in the x86 table, to detect and wait for privacy-screen on some ChromeOS platforms.

Please note that this means that if CONFIG_CHROMEOS_PRIVACY_SCREEN is enabled, and if "GOOG0010" device is found in ACPI, then the i915 probe shall return EPROBE_DEFER until a platform driver actually registers the
privacy-screen: https://hansdegoede.livejournal.com/25948.html

Quoted 8 lines
Quoted 6 lines

Hi Hans,

Since this change depends on the privacy screen changes staged for v5.17, I'm OK as platform/chrome maintainer to have this go through the drm tree.

Ok, I will merge this into drm-misc-next coming Monday.

Thank you so much for your help!

Quoted 3 lines

Note I'm afraid that it is too late for 5.17, the drm-misc maintainers have already created the final drm-misc tag for the 5.17 pull-req.

No problem, this works.

Thanks & Best Regards,

Rajat

Quoted 61 lines

Regards,

Hans

Quoted 54 lines
Quoted 53 lines

---
v5: * Add Hans' "Reviewed by"
v4: * Simplify the detect_chromeos_privacy_screen() function
* Don't change the existing print statement
v3: * Remove the pr_info() from detect_chromeos_privacy_screen(), instead
enhance the one already present in drm_privacy_screen_lookup_init()
v2: * Use #if instead of #elif
* Reorder the patches in the series.
* Rebased on drm-tip

 drivers/gpu/drm/drm_privacy_screen_x86.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/gpu/drm/drm_privacy_screen_x86.c +17 -1
index a2cafb294ca6..88802cd7a1ee 100644
@@ -47,6 +47,13 @@ static bool __init detect_thinkpad_privacy_screen(void)
 }
 #endif
 
+#if IS_ENABLED(CONFIG_CHROMEOS_PRIVACY_SCREEN)
+static bool __init detect_chromeos_privacy_screen(void)
+{
+    return acpi_dev_present("GOOG0010", NULL, -1);
+}
+#endif
+
 static const struct arch_init_data arch_init_data[] __initconst = {
 #if IS_ENABLED(CONFIG_THINKPAD_ACPI)
     {
@@ -58,6 +65,16 @@ static const struct arch_init_data arch_init_data[] __initconst = {
             .detect = detect_thinkpad_privacy_screen,
     },
 #endif
+#if IS_ENABLED(CONFIG_CHROMEOS_PRIVACY_SCREEN)
+    {
+            .lookup = {
+                    .dev_id = NULL,
+                    .con_id = NULL,
+                    .provider = "privacy_screen-GOOG0010:00",
+            },
+            .detect = detect_chromeos_privacy_screen,
+    },
+#endif
 };
 
 void __init drm_privacy_screen_lookup_init(void)
--

2.34.1.575.g55b058a8bb-goog

#7 lore raw
In reply to Rajat Jain

Hi All,

Quoted 10 lines · Rajat Jain

Allow a privacy screen provider to stash its private data pointer in the drm_privacy_screen, and update the drm_privacy_screen_register() call to accept that. Also introduce a *_get_drvdata() so that it can retrieved back when needed.

This also touches the IBM Thinkpad platform driver, the only user of privacy screen today, to pass NULL for now to the updated API.

I've pushed this series to drm-misc-next now.

Regards,

Hans

Quoted 83 lines

---
v5: Same as v4
v4: Added "Reviewed-by" from Hans
v3: Initial version. Came up due to review comments on v2 of other patches.
v2: No v2
v1: No v1

 drivers/gpu/drm/drm_privacy_screen.c    |  5 ++++-
 drivers/platform/x86/thinkpad_acpi.c    |  2 +-
 include/drm/drm_privacy_screen_driver.h | 13 ++++++++++++-
 3 files changed, 17 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_privacy_screen.c +4 -1
index beaf99e9120a..03b149cc455b 100644
@@ -387,7 +387,8 @@ static void drm_privacy_screen_device_release(struct device *dev)
  * * An ERR_PTR(errno) on failure.
  */
 struct drm_privacy_screen *drm_privacy_screen_register(
-	struct device *parent, const struct drm_privacy_screen_ops *ops)
+	struct device *parent, const struct drm_privacy_screen_ops *ops,
+	void *data)
 {
 	struct drm_privacy_screen *priv;
 	int ret;
@@ -404,6 +405,7 @@ struct drm_privacy_screen *drm_privacy_screen_register(
 	priv->dev.parent = parent;
 	priv->dev.release = drm_privacy_screen_device_release;
 	dev_set_name(&priv->dev, "privacy_screen-%s", dev_name(parent));
+	priv->drvdata = data;
 	priv->ops = ops;
 
 	priv->ops->get_hw_state(priv);
@@ -439,6 +441,7 @@ void drm_privacy_screen_unregister(struct drm_privacy_screen *priv)
 	mutex_unlock(&drm_privacy_screen_devs_lock);
 
 	mutex_lock(&priv->lock);
+	priv->drvdata = NULL;
 	priv->ops = NULL;
 	mutex_unlock(&priv->lock);
 
drivers/platform/x86/thinkpad_acpi.c +1 -1
index 341655d711ce..ccbfda2b0095 100644
@@ -9782,7 +9782,7 @@ static int tpacpi_lcdshadow_init(struct ibm_init_struct *iibm)
 		return 0;
 
 	lcdshadow_dev = drm_privacy_screen_register(&tpacpi_pdev->dev,
-						    &lcdshadow_ops);
+						    &lcdshadow_ops, NULL);
 	if (IS_ERR(lcdshadow_dev))
 		return PTR_ERR(lcdshadow_dev);
 
include/drm/drm_privacy_screen_driver.h +12 -1
index 24591b607675..4ef246d5706f 100644
@@ -73,10 +73,21 @@ struct drm_privacy_screen {
 	 * for more info.
 	 */
 	enum drm_privacy_screen_status hw_state;
+	/**
+	 * @drvdata: Private data owned by the privacy screen provider
+	 */
+	void *drvdata;
 };
 
+static inline
+void *drm_privacy_screen_get_drvdata(struct drm_privacy_screen *priv)
+{
+	return priv->drvdata;
+}
+
 struct drm_privacy_screen *drm_privacy_screen_register(
-	struct device *parent, const struct drm_privacy_screen_ops *ops);
+	struct device *parent, const struct drm_privacy_screen_ops *ops,
+	void *data);
 void drm_privacy_screen_unregister(struct drm_privacy_screen *priv);
 
 void drm_privacy_screen_call_notifier_chain(struct drm_privacy_screen *priv);
#8 lore raw
Quoted 9 lines · Hans de Goede

Hi All,

Quoted 5 lines · Rajat Jain

Allow a privacy screen provider to stash its private data pointer in the drm_privacy_screen, and update the drm_privacy_screen_register() call to accept that. Also introduce a *_get_drvdata() so that it can retrieved back when needed.

Quoted 7 lines
Quoted 5 lines

This also touches the IBM Thinkpad platform driver, the only user of privacy screen today, to pass NULL for now to the updated API.

I've pushed this series to drm-misc-next now.

Thank you so much. I see it.

Thanks & Best Regards,

Rajat

Quoted 91 lines

Regards,

Hans

Quoted 83 lines

---
v5: Same as v4
v4: Added "Reviewed-by" from Hans
v3: Initial version. Came up due to review comments on v2 of other patches.
v2: No v2
v1: No v1

 drivers/gpu/drm/drm_privacy_screen.c    |  5 ++++-
 drivers/platform/x86/thinkpad_acpi.c    |  2 +-
 include/drm/drm_privacy_screen_driver.h | 13 ++++++++++++-
 3 files changed, 17 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_privacy_screen.c +4 -1
index beaf99e9120a..03b149cc455b 100644
@@ -387,7 +387,8 @@ static void drm_privacy_screen_device_release(struct device *dev)
  * * An ERR_PTR(errno) on failure.
  */
 struct drm_privacy_screen *drm_privacy_screen_register(
-     struct device *parent, const struct drm_privacy_screen_ops *ops)
+     struct device *parent, const struct drm_privacy_screen_ops *ops,
+     void *data)
 {
      struct drm_privacy_screen *priv;
      int ret;
@@ -404,6 +405,7 @@ struct drm_privacy_screen *drm_privacy_screen_register(
      priv->dev.parent = parent;
      priv->dev.release = drm_privacy_screen_device_release;
      dev_set_name(&priv->dev, "privacy_screen-%s", dev_name(parent));
+     priv->drvdata = data;
      priv->ops = ops;
 
      priv->ops->get_hw_state(priv);
@@ -439,6 +441,7 @@ void drm_privacy_screen_unregister(struct drm_privacy_screen *priv)
      mutex_unlock(&drm_privacy_screen_devs_lock);
 
      mutex_lock(&priv->lock);
+     priv->drvdata = NULL;
      priv->ops = NULL;
      mutex_unlock(&priv->lock);
 
drivers/platform/x86/thinkpad_acpi.c +1 -1
index 341655d711ce..ccbfda2b0095 100644
@@ -9782,7 +9782,7 @@ static int tpacpi_lcdshadow_init(struct ibm_init_struct *iibm)
              return 0;
 
      lcdshadow_dev = drm_privacy_screen_register(&tpacpi_pdev->dev,
-                                                 &lcdshadow_ops);
+                                                 &lcdshadow_ops, NULL);
      if (IS_ERR(lcdshadow_dev))
              return PTR_ERR(lcdshadow_dev);
 
include/drm/drm_privacy_screen_driver.h +12 -1
index 24591b607675..4ef246d5706f 100644
@@ -73,10 +73,21 @@ struct drm_privacy_screen {
       * for more info.
       */
      enum drm_privacy_screen_status hw_state;
+     /**
+      * @drvdata: Private data owned by the privacy screen provider
+      */
+     void *drvdata;
 };
 
+static inline
+void *drm_privacy_screen_get_drvdata(struct drm_privacy_screen *priv)
+{
+     return priv->drvdata;
+}
+
 struct drm_privacy_screen *drm_privacy_screen_register(
-     struct device *parent, const struct drm_privacy_screen_ops *ops);
+     struct device *parent, const struct drm_privacy_screen_ops *ops,
+     void *data);
 void drm_privacy_screen_unregister(struct drm_privacy_screen *priv);
 
 void drm_privacy_screen_call_notifier_chain(struct drm_privacy_screen *priv);