platform-driver-x86.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/10] drm: Add privacy-screen class and connector properties
@ 2021-10-05 20:23 Hans de Goede
  2021-10-05 20:23 ` [PATCH 01/10] drm/connector: Add support for privacy-screen properties (v4) Hans de Goede
                   ` (9 more replies)
  0 siblings, 10 replies; 24+ messages in thread
From: Hans de Goede @ 2021-10-05 20:23 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Rajat Jain,
	Jani Nikula, Lyude, Joonas Lahtinen, Rodrigo Vivi,
	Ville Syrjälä,
	Mark Gross, Andy Shevchenko
  Cc: Hans de Goede, Daniel Vetter, David Airlie, Pekka Paalanen,
	Mario Limonciello, Mark Pearson, Sebastien Bacher,
	Marco Trevisan, Emil Velikov, intel-gfx, dri-devel,
	platform-driver-x86

Hi all,

Here is a new version of my privacy-screen series, addressing the
review-remark from Ville on patch 10/10 from the version posted on
October 2nd. This new version contains the following changes:

- drm/i915: Add privacy-screen support (v3)
 - Move drm_privacy_screen_get() call to intel_ddi_init_dp_connector()

Ville, can you (re)review "[PATCH 10/10] drm/i915: Add privacy-screen
support (v3)" please ?

For anyone just tuning in, here is some more info from the previous
cover-letters:

The first userspace consumer of the new properties is now fully ready
for merging (it is just waiting for the kernel bits to land first):

 - https://gitlab.gnome.org/GNOME/gsettings-desktop-schemas/-/merge_requests/49
 - https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1952
 - https://gitlab.gnome.org/GNOME/gnome-control-center/-/merge_requests/1032

The new API works as designed and add the following features to GNOME:

1. Showing an OSD notification when the privacy-screen is toggled on/off
   through hotkeys handled by the embedded-controller
2. Allowing control of the privacy-screen from the GNOME control-panel,
   including the on/off slider shown there updating to match the hw-setting
   when the setting is changed with the control-panel open.
3. Restoring the last user-setting at login

This series consists of a number of different parts:

1. A new version of Rajat's privacy-screen connector properties patch,
this adds new userspace API in the form of new properties

2. Since on most devices the privacy screen is actually controlled by
some vendor specific ACPI/WMI interface which has a driver under
drivers/platform/x86, we need some "glue" code to make this functionality
available to KMS drivers. Patches 2-4 add a new privacy-screen class for
this, which allows non KMS drivers (and possibly KMS drivers too) to
register a privacy-screen device and also adds an interface for KMS drivers
to get access to the privacy-screen associated with a specific connector.
This is modelled similar to how we deal with e.g. PWMs and GPIOs in the
kernel, including separate includes for consumers and providers(drivers).

3. Some drm_connector helper functions to keep the actual changes needed
for this in individual KMS drivers as small as possible (patch 5).

4. Make the thinkpad_acpi code register a privacy-screen device on
ThinkPads with a privacy-screen (patches 6-8)

5. Make the i915 driver export the privacy-screen functionality through
the connector properties on the eDP connector.

I believe that it would be best to merge the entire series, including
the thinkpad_acpi changes through drm-misc in one go. As the pdx86
subsys maintainer I hereby give my ack for merging the thinkpad_acpi
changes through drm-misc.

There is one small caveat with this series, which it is good to be
aware of. The i915 driver will now return -EPROBE_DEFER on Thinkpads
with an eprivacy screen, until the thinkpad_acpi driver is loaded.
This means that initrd generation tools will need to be updated to
include thinkpad_acpi when the i915 driver is added to the initrd.
Without this the loading of the i915 driver will be delayed to after
the switch to real rootfs.

Regards,

Hans


Hans de Goede (9):
  drm: Add privacy-screen class (v4)
  drm/privacy-screen: Add X86 specific arch init code
  drm/privacy-screen: Add notifier support (v2)
  drm/connector: Add a drm_connector privacy-screen helper functions
    (v2)
  platform/x86: thinkpad_acpi: Add hotkey_notify_extended_hotkey()
    helper
  platform/x86: thinkpad_acpi: Get privacy-screen / lcdshadow ACPI
    handles only once
  platform/x86: thinkpad_acpi: Register a privacy-screen device
  drm/i915: Add intel_modeset_probe_defer() helper
  drm/i915: Add privacy-screen support (v3)

Rajat Jain (1):
  drm/connector: Add support for privacy-screen properties (v4)

 Documentation/gpu/drm-kms-helpers.rst        |  15 +
 Documentation/gpu/drm-kms.rst                |   2 +
 MAINTAINERS                                  |   8 +
 drivers/gpu/drm/Kconfig                      |   4 +
 drivers/gpu/drm/Makefile                     |   1 +
 drivers/gpu/drm/drm_atomic_uapi.c            |   4 +
 drivers/gpu/drm/drm_connector.c              | 203 ++++++++
 drivers/gpu/drm/drm_drv.c                    |   4 +
 drivers/gpu/drm/drm_privacy_screen.c         | 467 +++++++++++++++++++
 drivers/gpu/drm/drm_privacy_screen_x86.c     |  86 ++++
 drivers/gpu/drm/i915/display/intel_atomic.c  |   1 +
 drivers/gpu/drm/i915/display/intel_ddi.c     |  15 +
 drivers/gpu/drm/i915/display/intel_display.c |  23 +
 drivers/gpu/drm/i915/display/intel_display.h |   1 +
 drivers/gpu/drm/i915/i915_pci.c              |   9 +-
 drivers/platform/x86/Kconfig                 |   2 +
 drivers/platform/x86/thinkpad_acpi.c         | 137 ++++--
 include/drm/drm_connector.h                  |  55 +++
 include/drm/drm_privacy_screen_consumer.h    |  65 +++
 include/drm/drm_privacy_screen_driver.h      |  84 ++++
 include/drm/drm_privacy_screen_machine.h     |  46 ++
 21 files changed, 1183 insertions(+), 49 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_privacy_screen.c
 create mode 100644 drivers/gpu/drm/drm_privacy_screen_x86.c
 create mode 100644 include/drm/drm_privacy_screen_consumer.h
 create mode 100644 include/drm/drm_privacy_screen_driver.h
 create mode 100644 include/drm/drm_privacy_screen_machine.h

-- 
2.31.1


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 01/10] drm/connector: Add support for privacy-screen properties (v4)
  2021-10-05 20:23 [PATCH 00/10] drm: Add privacy-screen class and connector properties Hans de Goede
@ 2021-10-05 20:23 ` Hans de Goede
  2021-10-05 20:23 ` [PATCH 02/10] drm: Add privacy-screen class (v4) Hans de Goede
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 24+ messages in thread
From: Hans de Goede @ 2021-10-05 20:23 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Rajat Jain,
	Jani Nikula, Lyude, Joonas Lahtinen, Rodrigo Vivi,
	Ville Syrjälä,
	Mark Gross, Andy Shevchenko
  Cc: Hans de Goede, Daniel Vetter, David Airlie, Pekka Paalanen,
	Mario Limonciello, Mark Pearson, Sebastien Bacher,
	Marco Trevisan, Emil Velikov, intel-gfx, dri-devel,
	platform-driver-x86, Mario Limonciello

From: Rajat Jain <rajatja@google.com>

Add support for generic electronic privacy screen properties, that
can be added by systems that have an integrated EPS.

Changes in v2 (Hans de Goede)
- Create 2 properties, "privacy-screen sw-state" and
  "privacy-screen hw-state", to deal with devices where the OS might be
  locked out of making state changes
- Write kerneldoc explaining how the 2 properties work together, what
  happens when changes to the state are made outside of the DRM code's
  control, etc.

Changes in v3 (Hans de Goede)
- Some small tweaks to the kerneldoc describing the 2 properties

Changes in v4 (Hans de Goede)
- Change the "Enabled, locked" and "Disabled, locked" hw-state enum value
  names to "Enabled-locked" and "Disabled-locked". The xrandr command shows
  all possible enum values separated by commas in its output, so having a
  comma in an enum name is not a good idea.
- Do not add a privacy_screen_hw_state member to drm_connector_state
  since this property is immutable its value must be directly stored in the
  obj->properties->values array

Signed-off-by: Rajat Jain <rajatja@google.com>
Acked-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Reviewed-by: Mario Limonciello <Mario.limonciello@dell.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Co-developed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 Documentation/gpu/drm-kms.rst     |   2 +
 drivers/gpu/drm/drm_atomic_uapi.c |   4 ++
 drivers/gpu/drm/drm_connector.c   | 101 ++++++++++++++++++++++++++++++
 include/drm/drm_connector.h       |  44 +++++++++++++
 4 files changed, 151 insertions(+)

diff --git a/Documentation/gpu/drm-kms.rst b/Documentation/gpu/drm-kms.rst
index 1ef7951ded5e..d14bf1c35d7e 100644
--- a/Documentation/gpu/drm-kms.rst
+++ b/Documentation/gpu/drm-kms.rst
@@ -506,6 +506,8 @@ Property Types and Blob Property Support
 .. kernel-doc:: drivers/gpu/drm/drm_property.c
    :export:
 
+.. _standard_connector_properties:
+
 Standard Connector Properties
 -----------------------------
 
diff --git a/drivers/gpu/drm/drm_atomic_uapi.c b/drivers/gpu/drm/drm_atomic_uapi.c
index 909f31833181..cdd31fc78bfc 100644
--- a/drivers/gpu/drm/drm_atomic_uapi.c
+++ b/drivers/gpu/drm/drm_atomic_uapi.c
@@ -797,6 +797,8 @@ static int drm_atomic_connector_set_property(struct drm_connector *connector,
 						   fence_ptr);
 	} else if (property == connector->max_bpc_property) {
 		state->max_requested_bpc = val;
+	} else if (property == connector->privacy_screen_sw_state_property) {
+		state->privacy_screen_sw_state = val;
 	} else if (connector->funcs->atomic_set_property) {
 		return connector->funcs->atomic_set_property(connector,
 				state, property, val);
@@ -874,6 +876,8 @@ drm_atomic_connector_get_property(struct drm_connector *connector,
 		*val = 0;
 	} else if (property == connector->max_bpc_property) {
 		*val = state->max_requested_bpc;
+	} else if (property == connector->privacy_screen_sw_state_property) {
+		*val = state->privacy_screen_sw_state;
 	} else if (connector->funcs->atomic_get_property) {
 		return connector->funcs->atomic_get_property(connector,
 				state, property, val);
diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index 3bc782b630b9..b2f1f1b1bfb4 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -1264,6 +1264,46 @@ static const struct drm_prop_enum_list dp_colorspaces[] = {
  *	For DVI-I and TVout there is also a matching property "select subconnector"
  *	allowing to switch between signal types.
  *	DP subconnector corresponds to a downstream port.
+ *
+ * privacy-screen sw-state, privacy-screen hw-state:
+ *	These 2 optional properties can be used to query the state of the
+ *	electronic privacy screen that is available on some displays; and in
+ *	some cases also control the state. If a driver implements these
+ *	properties then both properties must be present.
+ *
+ *	"privacy-screen hw-state" is read-only and reflects the actual state
+ *	of the privacy-screen, possible values: "Enabled", "Disabled,
+ *	"Enabled-locked", "Disabled-locked". The locked states indicate
+ *	that the state cannot be changed through the DRM API. E.g. there
+ *	might be devices where the firmware-setup options, or a hardware
+ *	slider-switch, offer always on / off modes.
+ *
+ *	"privacy-screen sw-state" can be set to change the privacy-screen state
+ *	when not locked. In this case the driver must update the hw-state
+ *	property to reflect the new state on completion of the commit of the
+ *	sw-state property. Setting the sw-state property when the hw-state is
+ *	locked must be interpreted by the driver as a request to change the
+ *	state to the set state when the hw-state becomes unlocked. E.g. if
+ *	"privacy-screen hw-state" is "Enabled-locked" and the sw-state
+ *	gets set to "Disabled" followed by the user unlocking the state by
+ *	changing the slider-switch position, then the driver must set the
+ *	state to "Disabled" upon receiving the unlock event.
+ *
+ *	In some cases the privacy-screen's actual state might change outside of
+ *	control of the DRM code. E.g. there might be a firmware handled hotkey
+ *	which toggles the actual state, or the actual state might be changed
+ *	through another userspace API such as writing /proc/acpi/ibm/lcdshadow.
+ *	In this case the driver must update both the hw-state and the sw-state
+ *	to reflect the new value, overwriting any pending state requests in the
+ *	sw-state. Any pending sw-state requests are thus discarded.
+ *
+ *	Note that the ability for the state to change outside of control of
+ *	the DRM master process means that userspace must not cache the value
+ *	of the sw-state. Caching the sw-state value and including it in later
+ *	atomic commits may lead to overriding a state change done through e.g.
+ *	a firmware handled hotkey. Therefor userspace must not include the
+ *	privacy-screen sw-state in an atomic commit unless it wants to change
+ *	its value.
  */
 
 int drm_connector_create_standard_properties(struct drm_device *dev)
@@ -2341,6 +2381,67 @@ int drm_connector_set_panel_orientation_with_quirk(
 }
 EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk);
 
+static const struct drm_prop_enum_list privacy_screen_enum[] = {
+	{ PRIVACY_SCREEN_DISABLED,		"Disabled" },
+	{ PRIVACY_SCREEN_ENABLED,		"Enabled" },
+	{ PRIVACY_SCREEN_DISABLED_LOCKED,	"Disabled-locked" },
+	{ PRIVACY_SCREEN_ENABLED_LOCKED,	"Enabled-locked" },
+};
+
+/**
+ * drm_connector_create_privacy_screen_properties - create the drm connecter's
+ *    privacy-screen properties.
+ * @connector: connector for which to create the privacy-screen properties
+ *
+ * This function creates the "privacy-screen sw-state" and "privacy-screen
+ * hw-state" properties for the connector. They are not attached.
+ */
+void
+drm_connector_create_privacy_screen_properties(struct drm_connector *connector)
+{
+	if (connector->privacy_screen_sw_state_property)
+		return;
+
+	/* Note sw-state only supports the first 2 values of the enum */
+	connector->privacy_screen_sw_state_property =
+		drm_property_create_enum(connector->dev, DRM_MODE_PROP_ENUM,
+				"privacy-screen sw-state",
+				privacy_screen_enum, 2);
+
+	connector->privacy_screen_hw_state_property =
+		drm_property_create_enum(connector->dev,
+				DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ENUM,
+				"privacy-screen hw-state",
+				privacy_screen_enum,
+				ARRAY_SIZE(privacy_screen_enum));
+}
+EXPORT_SYMBOL(drm_connector_create_privacy_screen_properties);
+
+/**
+ * drm_connector_attach_privacy_screen_properties - attach the drm connecter's
+ *    privacy-screen properties.
+ * @connector: connector on which to attach the privacy-screen properties
+ *
+ * This function attaches the "privacy-screen sw-state" and "privacy-screen
+ * hw-state" properties to the connector. The initial state of both is set
+ * to "Disabled".
+ */
+void
+drm_connector_attach_privacy_screen_properties(struct drm_connector *connector)
+{
+	if (!connector->privacy_screen_sw_state_property)
+		return;
+
+	drm_object_attach_property(&connector->base,
+				   connector->privacy_screen_sw_state_property,
+				   PRIVACY_SCREEN_DISABLED);
+
+	drm_object_attach_property(&connector->base,
+				   connector->privacy_screen_hw_state_property,
+				   PRIVACY_SCREEN_DISABLED);
+}
+EXPORT_SYMBOL(drm_connector_attach_privacy_screen_properties);
+
 int drm_connector_set_obj_prop(struct drm_mode_object *obj,
 				    struct drm_property *property,
 				    uint64_t value)
diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h
index 379746d3266f..a79aec55ea40 100644
--- a/include/drm/drm_connector.h
+++ b/include/drm/drm_connector.h
@@ -320,6 +320,30 @@ struct drm_monitor_range_info {
 	u8 max_vfreq;
 };
 
+/**
+ * enum drm_privacy_screen_status - privacy screen status
+ *
+ * This enum is used to track and control the state of the integrated privacy
+ * screen present on some display panels, via the "privacy-screen sw-state"
+ * and "privacy-screen hw-state" properties. Note the _LOCKED enum values
+ * are only valid for the "privacy-screen hw-state" property.
+ *
+ * @PRIVACY_SCREEN_DISABLED:
+ *  The privacy-screen on the panel is disabled
+ * @PRIVACY_SCREEN_ENABLED:
+ *  The privacy-screen on the panel is enabled
+ * @PRIVACY_SCREEN_DISABLED_LOCKED:
+ *  The privacy-screen on the panel is disabled and locked (cannot be changed)
+ * @PRIVACY_SCREEN_ENABLED_LOCKED:
+ *  The privacy-screen on the panel is enabled and locked (cannot be changed)
+ */
+enum drm_privacy_screen_status {
+	PRIVACY_SCREEN_DISABLED = 0,
+	PRIVACY_SCREEN_ENABLED,
+	PRIVACY_SCREEN_DISABLED_LOCKED,
+	PRIVACY_SCREEN_ENABLED_LOCKED,
+};
+
 /*
  * This is a consolidated colorimetry list supported by HDMI and
  * DP protocol standard. The respective connectors will register
@@ -793,6 +817,12 @@ struct drm_connector_state {
 	 */
 	u8 max_bpc;
 
+	/**
+	 * @privacy_screen_sw_state: See :ref:`Standard Connector
+	 * Properties<standard_connector_properties>`
+	 */
+	enum drm_privacy_screen_status privacy_screen_sw_state;
+
 	/**
 	 * @hdr_output_metadata:
 	 * DRM blob property for HDR output metadata
@@ -1421,6 +1451,18 @@ struct drm_connector {
 	 */
 	struct drm_property *max_bpc_property;
 
+	/**
+	 * @privacy_screen_sw_state_property: Optional atomic property for the
+	 * connector to control the integrated privacy screen.
+	 */
+	struct drm_property *privacy_screen_sw_state_property;
+
+	/**
+	 * @privacy_screen_hw_state_property: Optional atomic property for the
+	 * connector to report the actual integrated privacy screen state.
+	 */
+	struct drm_property *privacy_screen_hw_state_property;
+
 #define DRM_CONNECTOR_POLL_HPD (1 << 0)
 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
@@ -1744,6 +1786,8 @@ int drm_connector_set_panel_orientation_with_quirk(
 	int width, int height);
 int drm_connector_attach_max_bpc_property(struct drm_connector *connector,
 					  int min, int max);
+void drm_connector_create_privacy_screen_properties(struct drm_connector *conn);
+void drm_connector_attach_privacy_screen_properties(struct drm_connector *conn);
 
 /**
  * struct drm_tile_group - Tile group metadata
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 02/10] drm: Add privacy-screen class (v4)
  2021-10-05 20:23 [PATCH 00/10] drm: Add privacy-screen class and connector properties Hans de Goede
  2021-10-05 20:23 ` [PATCH 01/10] drm/connector: Add support for privacy-screen properties (v4) Hans de Goede
@ 2021-10-05 20:23 ` Hans de Goede
  2021-11-17 14:28   ` Rajat Jain
  2021-12-10 10:12   ` Thorsten Leemhuis
  2021-10-05 20:23 ` [PATCH 03/10] drm/privacy-screen: Add X86 specific arch init code Hans de Goede
                   ` (7 subsequent siblings)
  9 siblings, 2 replies; 24+ messages in thread
From: Hans de Goede @ 2021-10-05 20:23 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Rajat Jain,
	Jani Nikula, Lyude, Joonas Lahtinen, Rodrigo Vivi,
	Ville Syrjälä,
	Mark Gross, Andy Shevchenko
  Cc: Hans de Goede, Daniel Vetter, David Airlie, Pekka Paalanen,
	Mario Limonciello, Mark Pearson, Sebastien Bacher,
	Marco Trevisan, Emil Velikov, intel-gfx, dri-devel,
	platform-driver-x86

On some new laptops the LCD panel has a builtin electronic privacy-screen.
We want to export this functionality as a property on the drm connector
object. But often this functionality is not exposed on the GPU but on some
other (ACPI) device.

This commit adds a privacy-screen class allowing the driver for these
other devices to register themselves as a privacy-screen provider; and
allowing the drm/kms code to get a privacy-screen provider associated
with a specific GPU/connector combo.

Changes in v2:
- Make CONFIG_DRM_PRIVACY_SCREEN a bool which controls if the drm_privacy
  code gets built as part of the main drm module rather then making it
  a tristate which builds its own module.
- Add a #if IS_ENABLED(CONFIG_DRM_PRIVACY_SCREEN) check to
  drm_privacy_screen_consumer.h and define stubs when the check fails.
  Together these 2 changes fix several dependency issues.
- Remove module related code now that this is part of the main drm.ko
- Use drm_class as class for the privacy-screen devices instead of
  adding a separate class for this

Changes in v3:
- Make the static inline drm_privacy_screen_get_state() stub set sw_state
  and hw_state to PRIVACY_SCREEN_DISABLED to squelch an uninitialized
  variable warning when CONFIG_DRM_PRIVICAY_SCREEN is not set

Changes in v4:
- Make drm_privacy_screen_set_sw_state() skip calling out to the hw if
  hw_state == new_sw_state

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 Documentation/gpu/drm-kms-helpers.rst     |  15 +
 MAINTAINERS                               |   8 +
 drivers/gpu/drm/Kconfig                   |   4 +
 drivers/gpu/drm/Makefile                  |   1 +
 drivers/gpu/drm/drm_drv.c                 |   4 +
 drivers/gpu/drm/drm_privacy_screen.c      | 403 ++++++++++++++++++++++
 include/drm/drm_privacy_screen_consumer.h |  50 +++
 include/drm/drm_privacy_screen_driver.h   |  80 +++++
 include/drm/drm_privacy_screen_machine.h  |  41 +++
 9 files changed, 606 insertions(+)
 create mode 100644 drivers/gpu/drm/drm_privacy_screen.c
 create mode 100644 include/drm/drm_privacy_screen_consumer.h
 create mode 100644 include/drm/drm_privacy_screen_driver.h
 create mode 100644 include/drm/drm_privacy_screen_machine.h

diff --git a/Documentation/gpu/drm-kms-helpers.rst b/Documentation/gpu/drm-kms-helpers.rst
index ec2f65b31930..5bb55ec1b9b5 100644
--- a/Documentation/gpu/drm-kms-helpers.rst
+++ b/Documentation/gpu/drm-kms-helpers.rst
@@ -435,3 +435,18 @@ Legacy CRTC/Modeset Helper Functions Reference
 
 .. kernel-doc:: drivers/gpu/drm/drm_crtc_helper.c
    :export:
+
+Privacy-screen class
+====================
+
+.. kernel-doc:: drivers/gpu/drm/drm_privacy_screen.c
+   :doc: overview
+
+.. kernel-doc:: include/drm/drm_privacy_screen_driver.h
+   :internal:
+
+.. kernel-doc:: include/drm/drm_privacy_screen_machine.h
+   :internal:
+
+.. kernel-doc:: drivers/gpu/drm/drm_privacy_screen.c
+   :export:
diff --git a/MAINTAINERS b/MAINTAINERS
index 28e5f0ae1009..cb94bb3b8724 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6423,6 +6423,14 @@ F:	drivers/gpu/drm/drm_panel.c
 F:	drivers/gpu/drm/panel/
 F:	include/drm/drm_panel.h
 
+DRM PRIVACY-SCREEN CLASS
+M:	Hans de Goede <hdegoede@redhat.com>
+L:	dri-devel@lists.freedesktop.org
+S:	Maintained
+T:	git git://anongit.freedesktop.org/drm/drm-misc
+F:	drivers/gpu/drm/drm_privacy_screen*
+F:	include/drm/drm_privacy_screen*
+
 DRM TTM SUBSYSTEM
 M:	Christian Koenig <christian.koenig@amd.com>
 M:	Huang Rui <ray.huang@amd.com>
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 2a926d0de423..c686c08447ac 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -481,3 +481,7 @@ config DRM_PANEL_ORIENTATION_QUIRKS
 config DRM_LIB_RANDOM
 	bool
 	default n
+
+config DRM_PRIVACY_SCREEN
+	bool
+	default n
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 0dff40bb863c..788fc37096f6 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -32,6 +32,7 @@ drm-$(CONFIG_OF) += drm_of.o
 drm-$(CONFIG_PCI) += drm_pci.o
 drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
 drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
+drm-$(CONFIG_DRM_PRIVACY_SCREEN) += drm_privacy_screen.o
 
 obj-$(CONFIG_DRM_DP_AUX_BUS) += drm_dp_aux_bus.o
 
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 7a5097467ba5..dc293b771c3f 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -43,6 +43,7 @@
 #include <drm/drm_managed.h>
 #include <drm/drm_mode_object.h>
 #include <drm/drm_print.h>
+#include <drm/drm_privacy_screen_machine.h>
 
 #include "drm_crtc_internal.h"
 #include "drm_internal.h"
@@ -1029,6 +1030,7 @@ static const struct file_operations drm_stub_fops = {
 
 static void drm_core_exit(void)
 {
+	drm_privacy_screen_lookup_exit();
 	unregister_chrdev(DRM_MAJOR, "drm");
 	debugfs_remove(drm_debugfs_root);
 	drm_sysfs_destroy();
@@ -1056,6 +1058,8 @@ static int __init drm_core_init(void)
 	if (ret < 0)
 		goto error;
 
+	drm_privacy_screen_lookup_init();
+
 	drm_core_init_complete = true;
 
 	DRM_DEBUG("Initialized\n");
diff --git a/drivers/gpu/drm/drm_privacy_screen.c b/drivers/gpu/drm/drm_privacy_screen.c
new file mode 100644
index 000000000000..183a6011adf0
--- /dev/null
+++ b/drivers/gpu/drm/drm_privacy_screen.c
@@ -0,0 +1,403 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright (C) 2020 - 2021 Red Hat, Inc.
+ *
+ * Authors:
+ * Hans de Goede <hdegoede@redhat.com>
+ */
+
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <drm/drm_privacy_screen_machine.h>
+#include <drm/drm_privacy_screen_consumer.h>
+#include <drm/drm_privacy_screen_driver.h>
+#include "drm_internal.h"
+
+/**
+ * DOC: overview
+ *
+ * This class allows non KMS drivers, from e.g. drivers/platform/x86 to
+ * register a privacy-screen device, which the KMS drivers can then use
+ * to implement the standard privacy-screen properties, see
+ * :ref:`Standard Connector Properties<standard_connector_properties>`.
+ *
+ * KMS drivers using a privacy-screen class device are advised to use the
+ * drm_connector_attach_privacy_screen_provider() and
+ * drm_connector_update_privacy_screen() helpers for dealing with this.
+ */
+
+#define to_drm_privacy_screen(dev) \
+	container_of(dev, struct drm_privacy_screen, dev)
+
+static DEFINE_MUTEX(drm_privacy_screen_lookup_lock);
+static LIST_HEAD(drm_privacy_screen_lookup_list);
+
+static DEFINE_MUTEX(drm_privacy_screen_devs_lock);
+static LIST_HEAD(drm_privacy_screen_devs);
+
+/*** drm_privacy_screen_machine.h functions ***/
+
+/**
+ * drm_privacy_screen_lookup_add - add an entry to the static privacy-screen
+ *    lookup list
+ * @lookup: lookup list entry to add
+ *
+ * Add an entry to the static privacy-screen lookup list. Note the
+ * &struct list_head which is part of the &struct drm_privacy_screen_lookup
+ * gets added to a list owned by the privacy-screen core. So the passed in
+ * &struct drm_privacy_screen_lookup must not be free-ed until it is removed
+ * from the lookup list by calling drm_privacy_screen_lookup_remove().
+ */
+void drm_privacy_screen_lookup_add(struct drm_privacy_screen_lookup *lookup)
+{
+	mutex_lock(&drm_privacy_screen_lookup_lock);
+	list_add(&lookup->list, &drm_privacy_screen_lookup_list);
+	mutex_unlock(&drm_privacy_screen_lookup_lock);
+}
+EXPORT_SYMBOL(drm_privacy_screen_lookup_add);
+
+/**
+ * drm_privacy_screen_lookup_remove - remove an entry to the static
+ *    privacy-screen lookup list
+ * @lookup: lookup list entry to remove
+ *
+ * Remove an entry previously added with drm_privacy_screen_lookup_add()
+ * from the static privacy-screen lookup list.
+ */
+void drm_privacy_screen_lookup_remove(struct drm_privacy_screen_lookup *lookup)
+{
+	mutex_lock(&drm_privacy_screen_lookup_lock);
+	list_del(&lookup->list);
+	mutex_unlock(&drm_privacy_screen_lookup_lock);
+}
+EXPORT_SYMBOL(drm_privacy_screen_lookup_remove);
+
+/*** drm_privacy_screen_consumer.h functions ***/
+
+static struct drm_privacy_screen *drm_privacy_screen_get_by_name(
+	const char *name)
+{
+	struct drm_privacy_screen *priv;
+	struct device *dev = NULL;
+
+	mutex_lock(&drm_privacy_screen_devs_lock);
+
+	list_for_each_entry(priv, &drm_privacy_screen_devs, list) {
+		if (strcmp(dev_name(&priv->dev), name) == 0) {
+			dev = get_device(&priv->dev);
+			break;
+		}
+	}
+
+	mutex_unlock(&drm_privacy_screen_devs_lock);
+
+	return dev ? to_drm_privacy_screen(dev) : NULL;
+}
+
+/**
+ * drm_privacy_screen_get - get a privacy-screen provider
+ * @dev: consumer-device for which to get a privacy-screen provider
+ * @con_id: (video)connector name for which to get a privacy-screen provider
+ *
+ * Get a privacy-screen provider for a privacy-screen attached to the
+ * display described by the @dev and @con_id parameters.
+ *
+ * Return:
+ * * A pointer to a &struct drm_privacy_screen on success.
+ * * ERR_PTR(-ENODEV) if no matching privacy-screen is found
+ * * ERR_PTR(-EPROBE_DEFER) if there is a matching privacy-screen,
+ *                          but it has not been registered yet.
+ */
+struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
+						  const char *con_id)
+{
+	const char *dev_id = dev ? dev_name(dev) : NULL;
+	struct drm_privacy_screen_lookup *l;
+	struct drm_privacy_screen *priv;
+	const char *provider = NULL;
+	int match, best = -1;
+
+	/*
+	 * For now we only support using a static lookup table, which is
+	 * populated by the drm_privacy_screen_arch_init() call. This should
+	 * be extended with device-tree / fw_node lookup when support is added
+	 * for device-tree using hardware with a privacy-screen.
+	 *
+	 * The lookup algorithm was shamelessly taken from the clock
+	 * framework:
+	 *
+	 * We do slightly fuzzy matching here:
+	 *  An entry with a NULL ID is assumed to be a wildcard.
+	 *  If an entry has a device ID, it must match
+	 *  If an entry has a connection ID, it must match
+	 * Then we take the most specific entry - with the following order
+	 * of precedence: dev+con > dev only > con only.
+	 */
+	mutex_lock(&drm_privacy_screen_lookup_lock);
+
+	list_for_each_entry(l, &drm_privacy_screen_lookup_list, list) {
+		match = 0;
+
+		if (l->dev_id) {
+			if (!dev_id || strcmp(l->dev_id, dev_id))
+				continue;
+
+			match += 2;
+		}
+
+		if (l->con_id) {
+			if (!con_id || strcmp(l->con_id, con_id))
+				continue;
+
+			match += 1;
+		}
+
+		if (match > best) {
+			provider = l->provider;
+			best = match;
+		}
+	}
+
+	mutex_unlock(&drm_privacy_screen_lookup_lock);
+
+	if (!provider)
+		return ERR_PTR(-ENODEV);
+
+	priv = drm_privacy_screen_get_by_name(provider);
+	if (!priv)
+		return ERR_PTR(-EPROBE_DEFER);
+
+	return priv;
+}
+EXPORT_SYMBOL(drm_privacy_screen_get);
+
+/**
+ * drm_privacy_screen_put - release a privacy-screen reference
+ * @priv: privacy screen reference to release
+ *
+ * Release a privacy-screen provider reference gotten through
+ * drm_privacy_screen_get(). May be called with a NULL or ERR_PTR,
+ * in which case it is a no-op.
+ */
+void drm_privacy_screen_put(struct drm_privacy_screen *priv)
+{
+	if (IS_ERR_OR_NULL(priv))
+		return;
+
+	put_device(&priv->dev);
+}
+EXPORT_SYMBOL(drm_privacy_screen_put);
+
+/**
+ * drm_privacy_screen_set_sw_state - set a privacy-screen's sw-state
+ * @priv: privacy screen to set the sw-state for
+ * @sw_state: new sw-state value to set
+ *
+ * Set the sw-state of a privacy screen. If the privacy-screen is not
+ * in a locked hw-state, then the actual and hw-state of the privacy-screen
+ * will be immediately updated to the new value. If the privacy-screen is
+ * in a locked hw-state, then the new sw-state will be remembered as the
+ * requested state to put the privacy-screen in when it becomes unlocked.
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
+				    enum drm_privacy_screen_status sw_state)
+{
+	int ret = 0;
+
+	mutex_lock(&priv->lock);
+
+	if (!priv->ops) {
+		ret = -ENODEV;
+		goto out;
+	}
+
+	/*
+	 * As per the DRM connector properties documentation, setting the
+	 * sw_state while the hw_state is locked is allowed. In this case
+	 * it is a no-op other then storing the new sw_state so that it
+	 * can be honored when the state gets unlocked.
+	 * Also skip the set if the hw already is in the desired state.
+	 */
+	if (priv->hw_state >= PRIVACY_SCREEN_DISABLED_LOCKED ||
+	    priv->hw_state == sw_state) {
+		priv->sw_state = sw_state;
+		goto out;
+	}
+
+	ret = priv->ops->set_sw_state(priv, sw_state);
+out:
+	mutex_unlock(&priv->lock);
+	return ret;
+}
+EXPORT_SYMBOL(drm_privacy_screen_set_sw_state);
+
+/**
+ * drm_privacy_screen_get_state - get privacy-screen's current state
+ * @priv: privacy screen to get the state for
+ * @sw_state_ret: address where to store the privacy-screens current sw-state
+ * @hw_state_ret: address where to store the privacy-screens current hw-state
+ *
+ * Get the current state of a privacy-screen, both the sw-state and the
+ * hw-state.
+ */
+void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
+				  enum drm_privacy_screen_status *sw_state_ret,
+				  enum drm_privacy_screen_status *hw_state_ret)
+{
+	mutex_lock(&priv->lock);
+	*sw_state_ret = priv->sw_state;
+	*hw_state_ret = priv->hw_state;
+	mutex_unlock(&priv->lock);
+}
+EXPORT_SYMBOL(drm_privacy_screen_get_state);
+
+/*** drm_privacy_screen_driver.h functions ***/
+
+static ssize_t sw_state_show(struct device *dev,
+			     struct device_attribute *attr, char *buf)
+{
+	struct drm_privacy_screen *priv = to_drm_privacy_screen(dev);
+	const char * const sw_state_names[] = {
+		"Disabled",
+		"Enabled",
+	};
+	ssize_t ret;
+
+	mutex_lock(&priv->lock);
+
+	if (!priv->ops)
+		ret = -ENODEV;
+	else if (WARN_ON(priv->sw_state >= ARRAY_SIZE(sw_state_names)))
+		ret = -ENXIO;
+	else
+		ret = sprintf(buf, "%s\n", sw_state_names[priv->sw_state]);
+
+	mutex_unlock(&priv->lock);
+	return ret;
+}
+/*
+ * RO: Do not allow setting the sw_state through sysfs, this MUST be done
+ * through the drm_properties on the drm_connector.
+ */
+static DEVICE_ATTR_RO(sw_state);
+
+static ssize_t hw_state_show(struct device *dev,
+			     struct device_attribute *attr, char *buf)
+{
+	struct drm_privacy_screen *priv = to_drm_privacy_screen(dev);
+	const char * const hw_state_names[] = {
+		"Disabled",
+		"Enabled",
+		"Disabled, locked",
+		"Enabled, locked",
+	};
+	ssize_t ret;
+
+	mutex_lock(&priv->lock);
+
+	if (!priv->ops)
+		ret = -ENODEV;
+	else if (WARN_ON(priv->hw_state >= ARRAY_SIZE(hw_state_names)))
+		ret = -ENXIO;
+	else
+		ret = sprintf(buf, "%s\n", hw_state_names[priv->hw_state]);
+
+	mutex_unlock(&priv->lock);
+	return ret;
+}
+static DEVICE_ATTR_RO(hw_state);
+
+static struct attribute *drm_privacy_screen_attrs[] = {
+	&dev_attr_sw_state.attr,
+	&dev_attr_hw_state.attr,
+	NULL
+};
+ATTRIBUTE_GROUPS(drm_privacy_screen);
+
+static struct device_type drm_privacy_screen_type = {
+	.name = "privacy_screen",
+	.groups = drm_privacy_screen_groups,
+};
+
+static void drm_privacy_screen_device_release(struct device *dev)
+{
+	struct drm_privacy_screen *priv = to_drm_privacy_screen(dev);
+
+	kfree(priv);
+}
+
+/**
+ * drm_privacy_screen_register - register a privacy-screen
+ * @parent: parent-device for the privacy-screen
+ * @ops: &struct drm_privacy_screen_ops pointer with ops for the privacy-screen
+ *
+ * Create and register a privacy-screen.
+ *
+ * Return:
+ * * A pointer to the created privacy-screen on success.
+ * * 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 drm_privacy_screen *priv;
+	int ret;
+
+	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return ERR_PTR(-ENOMEM);
+
+	mutex_init(&priv->lock);
+
+	priv->dev.class = drm_class;
+	priv->dev.type = &drm_privacy_screen_type;
+	priv->dev.parent = parent;
+	priv->dev.release = drm_privacy_screen_device_release;
+	dev_set_name(&priv->dev, "privacy_screen-%s", dev_name(parent));
+	priv->ops = ops;
+
+	priv->ops->get_hw_state(priv);
+
+	ret = device_register(&priv->dev);
+	if (ret) {
+		put_device(&priv->dev);
+		return ERR_PTR(ret);
+	}
+
+	mutex_lock(&drm_privacy_screen_devs_lock);
+	list_add(&priv->list, &drm_privacy_screen_devs);
+	mutex_unlock(&drm_privacy_screen_devs_lock);
+
+	return priv;
+}
+EXPORT_SYMBOL(drm_privacy_screen_register);
+
+/**
+ * drm_privacy_screen_unregister - unregister privacy-screen
+ * @priv: privacy-screen to unregister
+ *
+ * Unregister a privacy-screen registered with drm_privacy_screen_register().
+ * May be called with a NULL or ERR_PTR, in which case it is a no-op.
+ */
+void drm_privacy_screen_unregister(struct drm_privacy_screen *priv)
+{
+	if (IS_ERR_OR_NULL(priv))
+		return;
+
+	mutex_lock(&drm_privacy_screen_devs_lock);
+	list_del(&priv->list);
+	mutex_unlock(&drm_privacy_screen_devs_lock);
+
+	mutex_lock(&priv->lock);
+	priv->ops = NULL;
+	mutex_unlock(&priv->lock);
+
+	device_unregister(&priv->dev);
+}
+EXPORT_SYMBOL(drm_privacy_screen_unregister);
diff --git a/include/drm/drm_privacy_screen_consumer.h b/include/drm/drm_privacy_screen_consumer.h
new file mode 100644
index 000000000000..0cbd23b0453d
--- /dev/null
+++ b/include/drm/drm_privacy_screen_consumer.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright (C) 2020 Red Hat, Inc.
+ *
+ * Authors:
+ * Hans de Goede <hdegoede@redhat.com>
+ */
+
+#ifndef __DRM_PRIVACY_SCREEN_CONSUMER_H__
+#define __DRM_PRIVACY_SCREEN_CONSUMER_H__
+
+#include <linux/device.h>
+#include <drm/drm_connector.h>
+
+struct drm_privacy_screen;
+
+#if IS_ENABLED(CONFIG_DRM_PRIVACY_SCREEN)
+struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
+						  const char *con_id);
+void drm_privacy_screen_put(struct drm_privacy_screen *priv);
+
+int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
+				    enum drm_privacy_screen_status sw_state);
+void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
+				  enum drm_privacy_screen_status *sw_state_ret,
+				  enum drm_privacy_screen_status *hw_state_ret);
+#else
+static inline struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
+								const char *con_id)
+{
+	return ERR_PTR(-ENODEV);
+}
+static inline void drm_privacy_screen_put(struct drm_privacy_screen *priv)
+{
+}
+static inline int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
+						  enum drm_privacy_screen_status sw_state)
+{
+	return -ENODEV;
+}
+static inline void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
+						enum drm_privacy_screen_status *sw_state_ret,
+						enum drm_privacy_screen_status *hw_state_ret)
+{
+	*sw_state_ret = PRIVACY_SCREEN_DISABLED;
+	*hw_state_ret = PRIVACY_SCREEN_DISABLED;
+}
+#endif
+
+#endif
diff --git a/include/drm/drm_privacy_screen_driver.h b/include/drm/drm_privacy_screen_driver.h
new file mode 100644
index 000000000000..5187ae52eb03
--- /dev/null
+++ b/include/drm/drm_privacy_screen_driver.h
@@ -0,0 +1,80 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright (C) 2020 Red Hat, Inc.
+ *
+ * Authors:
+ * Hans de Goede <hdegoede@redhat.com>
+ */
+
+#ifndef __DRM_PRIVACY_SCREEN_DRIVER_H__
+#define __DRM_PRIVACY_SCREEN_DRIVER_H__
+
+#include <linux/device.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <drm/drm_connector.h>
+
+struct drm_privacy_screen;
+
+/**
+ * struct drm_privacy_screen_ops - drm_privacy_screen operations
+ *
+ * Defines the operations which the privacy-screen class code may call.
+ * These functions should be implemented by the privacy-screen driver.
+ */
+struct drm_privacy_screen_ops {
+	/**
+	 * @set_sw_state: Called to request a change of the privacy-screen
+	 * state. The privacy-screen class code contains a check to avoid this
+	 * getting called when the hw_state reports the state is locked.
+	 * It is the driver's responsibility to update sw_state and hw_state.
+	 * This is always called with the drm_privacy_screen's lock held.
+	 */
+	int (*set_sw_state)(struct drm_privacy_screen *priv,
+			    enum drm_privacy_screen_status sw_state);
+	/**
+	 * @get_hw_state: Called to request that the driver gets the current
+	 * privacy-screen state from the hardware and then updates sw_state and
+	 * hw_state accordingly. This will be called by the core just before
+	 * the privacy-screen is registered in sysfs.
+	 */
+	void (*get_hw_state)(struct drm_privacy_screen *priv);
+};
+
+/**
+ * struct drm_privacy_screen - central privacy-screen structure
+ *
+ * Central privacy-screen structure, this contains the struct device used
+ * to register the screen in sysfs, the screen's state, ops, etc.
+ */
+struct drm_privacy_screen {
+	/** @dev: device used to register the privacy-screen in sysfs. */
+	struct device dev;
+	/** @lock: mutex protection all fields in this struct. */
+	struct mutex lock;
+	/** @list: privacy-screen devices list list-entry. */
+	struct list_head list;
+	/**
+	 * @ops: &struct drm_privacy_screen_ops for this privacy-screen.
+	 * This is NULL if the driver has unregistered the privacy-screen.
+	 */
+	const struct drm_privacy_screen_ops *ops;
+	/**
+	 * @sw_state: The privacy-screen's software state, see
+	 * :ref:`Standard Connector Properties<standard_connector_properties>`
+	 * for more info.
+	 */
+	enum drm_privacy_screen_status sw_state;
+	/**
+	 * @hw_state: The privacy-screen's hardware state, see
+	 * :ref:`Standard Connector Properties<standard_connector_properties>`
+	 * for more info.
+	 */
+	enum drm_privacy_screen_status hw_state;
+};
+
+struct drm_privacy_screen *drm_privacy_screen_register(
+	struct device *parent, const struct drm_privacy_screen_ops *ops);
+void drm_privacy_screen_unregister(struct drm_privacy_screen *priv);
+
+#endif
diff --git a/include/drm/drm_privacy_screen_machine.h b/include/drm/drm_privacy_screen_machine.h
new file mode 100644
index 000000000000..aaa0d38cce92
--- /dev/null
+++ b/include/drm/drm_privacy_screen_machine.h
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright (C) 2020 Red Hat, Inc.
+ *
+ * Authors:
+ * Hans de Goede <hdegoede@redhat.com>
+ */
+
+#ifndef __DRM_PRIVACY_SCREEN_MACHINE_H__
+#define __DRM_PRIVACY_SCREEN_MACHINE_H__
+
+#include <linux/list.h>
+
+/**
+ * struct drm_privacy_screen_lookup -  static privacy-screen lookup list entry
+ *
+ * Used for the static lookup-list for mapping privacy-screen consumer
+ * dev-connector pairs to a privacy-screen provider.
+ */
+struct drm_privacy_screen_lookup {
+	/** @list: Lookup list list-entry. */
+	struct list_head list;
+	/** @dev_id: Consumer device name or NULL to match all devices. */
+	const char *dev_id;
+	/** @con_id: Consumer connector name or NULL to match all connectors. */
+	const char *con_id;
+	/** @provider: dev_name() of the privacy_screen provider. */
+	const char *provider;
+};
+
+void drm_privacy_screen_lookup_add(struct drm_privacy_screen_lookup *lookup);
+void drm_privacy_screen_lookup_remove(struct drm_privacy_screen_lookup *lookup);
+
+static inline void drm_privacy_screen_lookup_init(void)
+{
+}
+static inline void drm_privacy_screen_lookup_exit(void)
+{
+}
+
+#endif
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 03/10] drm/privacy-screen: Add X86 specific arch init code
  2021-10-05 20:23 [PATCH 00/10] drm: Add privacy-screen class and connector properties Hans de Goede
  2021-10-05 20:23 ` [PATCH 01/10] drm/connector: Add support for privacy-screen properties (v4) Hans de Goede
  2021-10-05 20:23 ` [PATCH 02/10] drm: Add privacy-screen class (v4) Hans de Goede
@ 2021-10-05 20:23 ` Hans de Goede
  2021-11-17 14:13   ` Rajat Jain
  2021-10-05 20:23 ` [PATCH 04/10] drm/privacy-screen: Add notifier support (v2) Hans de Goede
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 24+ messages in thread
From: Hans de Goede @ 2021-10-05 20:23 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Rajat Jain,
	Jani Nikula, Lyude, Joonas Lahtinen, Rodrigo Vivi,
	Ville Syrjälä,
	Mark Gross, Andy Shevchenko
  Cc: Hans de Goede, Daniel Vetter, David Airlie, Pekka Paalanen,
	Mario Limonciello, Mark Pearson, Sebastien Bacher,
	Marco Trevisan, Emil Velikov, intel-gfx, dri-devel,
	platform-driver-x86

Add X86 specific arch init code, which fills the privacy-screen lookup
table by checking for various vendor specific ACPI interfaces for
controlling the privacy-screen.

This initial version only checks for the Lenovo Thinkpad specific ACPI
methods for privacy-screen control.

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/gpu/drm/Makefile                 |  2 +-
 drivers/gpu/drm/drm_privacy_screen_x86.c | 86 ++++++++++++++++++++++++
 include/drm/drm_privacy_screen_machine.h |  5 ++
 3 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/drm_privacy_screen_x86.c

diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 788fc37096f6..12997ca5670d 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -32,7 +32,7 @@ drm-$(CONFIG_OF) += drm_of.o
 drm-$(CONFIG_PCI) += drm_pci.o
 drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
 drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
-drm-$(CONFIG_DRM_PRIVACY_SCREEN) += drm_privacy_screen.o
+drm-$(CONFIG_DRM_PRIVACY_SCREEN) += drm_privacy_screen.o drm_privacy_screen_x86.o
 
 obj-$(CONFIG_DRM_DP_AUX_BUS) += drm_dp_aux_bus.o
 
diff --git a/drivers/gpu/drm/drm_privacy_screen_x86.c b/drivers/gpu/drm/drm_privacy_screen_x86.c
new file mode 100644
index 000000000000..a2cafb294ca6
--- /dev/null
+++ b/drivers/gpu/drm/drm_privacy_screen_x86.c
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright (C) 2020 Red Hat, Inc.
+ *
+ * Authors:
+ * Hans de Goede <hdegoede@redhat.com>
+ */
+
+#include <linux/acpi.h>
+#include <drm/drm_privacy_screen_machine.h>
+
+#ifdef CONFIG_X86
+static struct drm_privacy_screen_lookup arch_lookup;
+
+struct arch_init_data {
+	struct drm_privacy_screen_lookup lookup;
+	bool (*detect)(void);
+};
+
+#if IS_ENABLED(CONFIG_THINKPAD_ACPI)
+static acpi_status __init acpi_set_handle(acpi_handle handle, u32 level,
+					  void *context, void **return_value)
+{
+	*(acpi_handle *)return_value = handle;
+	return AE_CTRL_TERMINATE;
+}
+
+static bool __init detect_thinkpad_privacy_screen(void)
+{
+	union acpi_object obj = { .type = ACPI_TYPE_INTEGER };
+	struct acpi_object_list args = { .count = 1, .pointer = &obj, };
+	acpi_handle ec_handle = NULL;
+	unsigned long long output;
+	acpi_status status;
+
+	/* Get embedded-controller handle */
+	status = acpi_get_devices("PNP0C09", acpi_set_handle, NULL, &ec_handle);
+	if (ACPI_FAILURE(status) || !ec_handle)
+		return false;
+
+	/* And call the privacy-screen get-status method */
+	status = acpi_evaluate_integer(ec_handle, "HKEY.GSSS", &args, &output);
+	if (ACPI_FAILURE(status))
+		return false;
+
+	return (output & 0x10000) ? true : false;
+}
+#endif
+
+static const struct arch_init_data arch_init_data[] __initconst = {
+#if IS_ENABLED(CONFIG_THINKPAD_ACPI)
+	{
+		.lookup = {
+			.dev_id = NULL,
+			.con_id = NULL,
+			.provider = "privacy_screen-thinkpad_acpi",
+		},
+		.detect = detect_thinkpad_privacy_screen,
+	},
+#endif
+};
+
+void __init drm_privacy_screen_lookup_init(void)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(arch_init_data); i++) {
+		if (!arch_init_data[i].detect())
+			continue;
+
+		pr_info("Found '%s' privacy-screen provider\n",
+			arch_init_data[i].lookup.provider);
+
+		/* Make a copy because arch_init_data is __initconst */
+		arch_lookup = arch_init_data[i].lookup;
+		drm_privacy_screen_lookup_add(&arch_lookup);
+		break;
+	}
+}
+
+void drm_privacy_screen_lookup_exit(void)
+{
+	if (arch_lookup.provider)
+		drm_privacy_screen_lookup_remove(&arch_lookup);
+}
+#endif /* ifdef CONFIG_X86 */
diff --git a/include/drm/drm_privacy_screen_machine.h b/include/drm/drm_privacy_screen_machine.h
index aaa0d38cce92..02e5371904d3 100644
--- a/include/drm/drm_privacy_screen_machine.h
+++ b/include/drm/drm_privacy_screen_machine.h
@@ -31,11 +31,16 @@ struct drm_privacy_screen_lookup {
 void drm_privacy_screen_lookup_add(struct drm_privacy_screen_lookup *lookup);
 void drm_privacy_screen_lookup_remove(struct drm_privacy_screen_lookup *lookup);
 
+#if IS_ENABLED(CONFIG_DRM_PRIVACY_SCREEN) && IS_ENABLED(CONFIG_X86)
+void drm_privacy_screen_lookup_init(void);
+void drm_privacy_screen_lookup_exit(void);
+#else
 static inline void drm_privacy_screen_lookup_init(void)
 {
 }
 static inline void drm_privacy_screen_lookup_exit(void)
 {
 }
+#endif
 
 #endif
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 04/10] drm/privacy-screen: Add notifier support (v2)
  2021-10-05 20:23 [PATCH 00/10] drm: Add privacy-screen class and connector properties Hans de Goede
                   ` (2 preceding siblings ...)
  2021-10-05 20:23 ` [PATCH 03/10] drm/privacy-screen: Add X86 specific arch init code Hans de Goede
@ 2021-10-05 20:23 ` Hans de Goede
  2021-10-05 20:23 ` [PATCH 05/10] drm/connector: Add a drm_connector privacy-screen helper functions (v2) Hans de Goede
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 24+ messages in thread
From: Hans de Goede @ 2021-10-05 20:23 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Rajat Jain,
	Jani Nikula, Lyude, Joonas Lahtinen, Rodrigo Vivi,
	Ville Syrjälä,
	Mark Gross, Andy Shevchenko
  Cc: Hans de Goede, Daniel Vetter, David Airlie, Pekka Paalanen,
	Mario Limonciello, Mark Pearson, Sebastien Bacher,
	Marco Trevisan, Emil Velikov, intel-gfx, dri-devel,
	platform-driver-x86

Add support for privacy-screen consumers to register a notifier to
be notified of external (e.g. done by the hw itself on a hotkey press)
state changes.

Changes in v2:
- Drop WARN_ON(mutex_is_locked(&priv->lock)) check in
  drm_privacy_screen_call_notifier_chain() it may be locked by
  another thread, which would lead to a false-positive triggering
  of the check

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/gpu/drm/drm_privacy_screen.c      | 64 +++++++++++++++++++++++
 include/drm/drm_privacy_screen_consumer.h | 15 ++++++
 include/drm/drm_privacy_screen_driver.h   |  4 ++
 3 files changed, 83 insertions(+)

diff --git a/drivers/gpu/drm/drm_privacy_screen.c b/drivers/gpu/drm/drm_privacy_screen.c
index 183a6011adf0..beaf99e9120a 100644
--- a/drivers/gpu/drm/drm_privacy_screen.c
+++ b/drivers/gpu/drm/drm_privacy_screen.c
@@ -257,6 +257,49 @@ void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
 }
 EXPORT_SYMBOL(drm_privacy_screen_get_state);
 
+/**
+ * drm_privacy_screen_register_notifier - register a notifier
+ * @priv: Privacy screen to register the notifier with
+ * @nb: Notifier-block for the notifier to register
+ *
+ * Register a notifier with the privacy-screen to be notified of changes made
+ * to the privacy-screen state from outside of the privacy-screen class.
+ * E.g. the state may be changed by the hardware itself in response to a
+ * hotkey press.
+ *
+ * The notifier is called with no locks held. The new hw_state and sw_state
+ * can be retrieved using the drm_privacy_screen_get_state() function.
+ * A pointer to the drm_privacy_screen's struct is passed as the void *data
+ * argument of the notifier_block's notifier_call.
+ *
+ * The notifier will NOT be called when changes are made through
+ * drm_privacy_screen_set_sw_state(). It is only called for external changes.
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+int drm_privacy_screen_register_notifier(struct drm_privacy_screen *priv,
+					 struct notifier_block *nb)
+{
+	return blocking_notifier_chain_register(&priv->notifier_head, nb);
+}
+EXPORT_SYMBOL(drm_privacy_screen_register_notifier);
+
+/**
+ * drm_privacy_screen_unregister_notifier - unregister a notifier
+ * @priv: Privacy screen to register the notifier with
+ * @nb: Notifier-block for the notifier to register
+ *
+ * Unregister a notifier registered with drm_privacy_screen_register_notifier().
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+int drm_privacy_screen_unregister_notifier(struct drm_privacy_screen *priv,
+					   struct notifier_block *nb)
+{
+	return blocking_notifier_chain_unregister(&priv->notifier_head, nb);
+}
+EXPORT_SYMBOL(drm_privacy_screen_unregister_notifier);
+
 /*** drm_privacy_screen_driver.h functions ***/
 
 static ssize_t sw_state_show(struct device *dev,
@@ -354,6 +397,7 @@ struct drm_privacy_screen *drm_privacy_screen_register(
 		return ERR_PTR(-ENOMEM);
 
 	mutex_init(&priv->lock);
+	BLOCKING_INIT_NOTIFIER_HEAD(&priv->notifier_head);
 
 	priv->dev.class = drm_class;
 	priv->dev.type = &drm_privacy_screen_type;
@@ -401,3 +445,23 @@ void drm_privacy_screen_unregister(struct drm_privacy_screen *priv)
 	device_unregister(&priv->dev);
 }
 EXPORT_SYMBOL(drm_privacy_screen_unregister);
+
+/**
+ * drm_privacy_screen_call_notifier_chain - notify consumers of state change
+ * @priv: Privacy screen to register the notifier with
+ *
+ * A privacy-screen provider driver can call this functions upon external
+ * changes to the privacy-screen state. E.g. the state may be changed by the
+ * hardware itself in response to a hotkey press.
+ * This function must be called without holding the privacy-screen lock.
+ * the driver must update sw_state and hw_state to reflect the new state before
+ * calling this function.
+ * The expected behavior from the driver upon receiving an external state
+ * change event is: 1. Take the lock; 2. Update sw_state and hw_state;
+ * 3. Release the lock. 4. Call drm_privacy_screen_call_notifier_chain().
+ */
+void drm_privacy_screen_call_notifier_chain(struct drm_privacy_screen *priv)
+{
+	blocking_notifier_call_chain(&priv->notifier_head, 0, priv);
+}
+EXPORT_SYMBOL(drm_privacy_screen_call_notifier_chain);
diff --git a/include/drm/drm_privacy_screen_consumer.h b/include/drm/drm_privacy_screen_consumer.h
index 0cbd23b0453d..7f66a90d15b7 100644
--- a/include/drm/drm_privacy_screen_consumer.h
+++ b/include/drm/drm_privacy_screen_consumer.h
@@ -24,6 +24,11 @@ int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
 void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
 				  enum drm_privacy_screen_status *sw_state_ret,
 				  enum drm_privacy_screen_status *hw_state_ret);
+
+int drm_privacy_screen_register_notifier(struct drm_privacy_screen *priv,
+					 struct notifier_block *nb);
+int drm_privacy_screen_unregister_notifier(struct drm_privacy_screen *priv,
+					   struct notifier_block *nb);
 #else
 static inline struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
 								const char *con_id)
@@ -45,6 +50,16 @@ static inline void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
 	*sw_state_ret = PRIVACY_SCREEN_DISABLED;
 	*hw_state_ret = PRIVACY_SCREEN_DISABLED;
 }
+static inline int drm_privacy_screen_register_notifier(struct drm_privacy_screen *priv,
+						       struct notifier_block *nb)
+{
+	return -ENODEV;
+}
+static inline int drm_privacy_screen_unregister_notifier(struct drm_privacy_screen *priv,
+							 struct notifier_block *nb)
+{
+	return -ENODEV;
+}
 #endif
 
 #endif
diff --git a/include/drm/drm_privacy_screen_driver.h b/include/drm/drm_privacy_screen_driver.h
index 5187ae52eb03..24591b607675 100644
--- a/include/drm/drm_privacy_screen_driver.h
+++ b/include/drm/drm_privacy_screen_driver.h
@@ -54,6 +54,8 @@ struct drm_privacy_screen {
 	struct mutex lock;
 	/** @list: privacy-screen devices list list-entry. */
 	struct list_head list;
+	/** @notifier_head: privacy-screen notifier head. */
+	struct blocking_notifier_head notifier_head;
 	/**
 	 * @ops: &struct drm_privacy_screen_ops for this privacy-screen.
 	 * This is NULL if the driver has unregistered the privacy-screen.
@@ -77,4 +79,6 @@ struct drm_privacy_screen *drm_privacy_screen_register(
 	struct device *parent, const struct drm_privacy_screen_ops *ops);
 void drm_privacy_screen_unregister(struct drm_privacy_screen *priv);
 
+void drm_privacy_screen_call_notifier_chain(struct drm_privacy_screen *priv);
+
 #endif
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 05/10] drm/connector: Add a drm_connector privacy-screen helper functions (v2)
  2021-10-05 20:23 [PATCH 00/10] drm: Add privacy-screen class and connector properties Hans de Goede
                   ` (3 preceding siblings ...)
  2021-10-05 20:23 ` [PATCH 04/10] drm/privacy-screen: Add notifier support (v2) Hans de Goede
@ 2021-10-05 20:23 ` Hans de Goede
  2021-10-05 20:23 ` [PATCH 06/10] platform/x86: thinkpad_acpi: Add hotkey_notify_extended_hotkey() helper Hans de Goede
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 24+ messages in thread
From: Hans de Goede @ 2021-10-05 20:23 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Rajat Jain,
	Jani Nikula, Lyude, Joonas Lahtinen, Rodrigo Vivi,
	Ville Syrjälä,
	Mark Gross, Andy Shevchenko
  Cc: Hans de Goede, Daniel Vetter, David Airlie, Pekka Paalanen,
	Mario Limonciello, Mark Pearson, Sebastien Bacher,
	Marco Trevisan, Emil Velikov, intel-gfx, dri-devel,
	platform-driver-x86

Add 2 drm_connector privacy-screen helper functions:

1. drm_connector_attach_privacy_screen_provider(), this function creates
and attaches the standard privacy-screen properties and registers a
generic notifier for generating sysfs-connector-status-events on external
changes to the privacy-screen status.

2. drm_connector_update_privacy_screen(), update the privacy-screen's
sw_state if the connector has a privacy-screen.

Changes in v2:
- Do not update connector->state->privacy_screen_sw_state on
  atomic-commits.
- Change drm_connector_update_privacy_screen() to take drm_connector_state
  as argument instead of a full drm_atomic_state. This allows the helper
  to be called by drivers when they are enabling crtcs/encoders/connectors.

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/gpu/drm/drm_connector.c | 102 ++++++++++++++++++++++++++++++++
 include/drm/drm_connector.h     |  11 ++++
 2 files changed, 113 insertions(+)

diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index b2f1f1b1bfb4..00cf3b6135f6 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -28,6 +28,7 @@
 #include <drm/drm_print.h>
 #include <drm/drm_drv.h>
 #include <drm/drm_file.h>
+#include <drm/drm_privacy_screen_consumer.h>
 #include <drm/drm_sysfs.h>
 
 #include <linux/uaccess.h>
@@ -462,6 +463,11 @@ void drm_connector_cleanup(struct drm_connector *connector)
 		    DRM_CONNECTOR_REGISTERED))
 		drm_connector_unregister(connector);
 
+	if (connector->privacy_screen) {
+		drm_privacy_screen_put(connector->privacy_screen);
+		connector->privacy_screen = NULL;
+	}
+
 	if (connector->tile_group) {
 		drm_mode_put_tile_group(dev, connector->tile_group);
 		connector->tile_group = NULL;
@@ -543,6 +549,10 @@ int drm_connector_register(struct drm_connector *connector)
 	/* Let userspace know we have a new connector */
 	drm_sysfs_hotplug_event(connector->dev);
 
+	if (connector->privacy_screen)
+		drm_privacy_screen_register_notifier(connector->privacy_screen,
+					   &connector->privacy_screen_notifier);
+
 	mutex_lock(&connector_list_lock);
 	list_add_tail(&connector->global_connector_list_entry, &connector_list);
 	mutex_unlock(&connector_list_lock);
@@ -578,6 +588,11 @@ void drm_connector_unregister(struct drm_connector *connector)
 	list_del_init(&connector->global_connector_list_entry);
 	mutex_unlock(&connector_list_lock);
 
+	if (connector->privacy_screen)
+		drm_privacy_screen_unregister_notifier(
+					connector->privacy_screen,
+					&connector->privacy_screen_notifier);
+
 	if (connector->funcs->early_unregister)
 		connector->funcs->early_unregister(connector);
 
@@ -2442,6 +2457,93 @@ drm_connector_attach_privacy_screen_properties(struct drm_connector *connector)
 }
 EXPORT_SYMBOL(drm_connector_attach_privacy_screen_properties);
 
+static void drm_connector_update_privacy_screen_properties(
+	struct drm_connector *connector, bool set_sw_state)
+{
+	enum drm_privacy_screen_status sw_state, hw_state;
+
+	drm_privacy_screen_get_state(connector->privacy_screen,
+				     &sw_state, &hw_state);
+
+	if (set_sw_state)
+		connector->state->privacy_screen_sw_state = sw_state;
+	drm_object_property_set_value(&connector->base,
+			connector->privacy_screen_hw_state_property, hw_state);
+}
+
+static int drm_connector_privacy_screen_notifier(
+	struct notifier_block *nb, unsigned long action, void *data)
+{
+	struct drm_connector *connector =
+		container_of(nb, struct drm_connector, privacy_screen_notifier);
+	struct drm_device *dev = connector->dev;
+
+	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
+	drm_connector_update_privacy_screen_properties(connector, true);
+	drm_modeset_unlock(&dev->mode_config.connection_mutex);
+
+	drm_sysfs_connector_status_event(connector,
+				connector->privacy_screen_sw_state_property);
+	drm_sysfs_connector_status_event(connector,
+				connector->privacy_screen_hw_state_property);
+
+	return NOTIFY_DONE;
+}
+
+/**
+ * drm_connector_attach_privacy_screen_provider - attach a privacy-screen to
+ *    the connector
+ * @connector: connector to attach the privacy-screen to
+ * @priv: drm_privacy_screen to attach
+ *
+ * Create and attach the standard privacy-screen properties and register
+ * a generic notifier for generating sysfs-connector-status-events
+ * on external changes to the privacy-screen status.
+ * This function takes ownership of the passed in drm_privacy_screen and will
+ * call drm_privacy_screen_put() on it when the connector is destroyed.
+ */
+void drm_connector_attach_privacy_screen_provider(
+	struct drm_connector *connector, struct drm_privacy_screen *priv)
+{
+	connector->privacy_screen = priv;
+	connector->privacy_screen_notifier.notifier_call =
+		drm_connector_privacy_screen_notifier;
+
+	drm_connector_create_privacy_screen_properties(connector);
+	drm_connector_update_privacy_screen_properties(connector, true);
+	drm_connector_attach_privacy_screen_properties(connector);
+}
+EXPORT_SYMBOL(drm_connector_attach_privacy_screen_provider);
+
+/**
+ * drm_connector_update_privacy_screen - update connector's privacy-screen sw-state
+ * @connector_state: connector-state to update the privacy-screen for
+ *
+ * This function calls drm_privacy_screen_set_sw_state() on the connector's
+ * privacy-screen.
+ *
+ * If the connector has no privacy-screen, then this is a no-op.
+ */
+void drm_connector_update_privacy_screen(const struct drm_connector_state *connector_state)
+{
+	struct drm_connector *connector = connector_state->connector;
+	int ret;
+
+	if (!connector->privacy_screen)
+		return;
+
+	ret = drm_privacy_screen_set_sw_state(connector->privacy_screen,
+					      connector_state->privacy_screen_sw_state);
+	if (ret) {
+		drm_err(connector->dev, "Error updating privacy-screen sw_state\n");
+		return;
+	}
+
+	/* The hw_state property value may have changed, update it. */
+	drm_connector_update_privacy_screen_properties(connector, false);
+}
+EXPORT_SYMBOL(drm_connector_update_privacy_screen);
+
 int drm_connector_set_obj_prop(struct drm_mode_object *obj,
 				    struct drm_property *property,
 				    uint64_t value)
diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h
index a79aec55ea40..b501d0badaea 100644
--- a/include/drm/drm_connector.h
+++ b/include/drm/drm_connector.h
@@ -27,6 +27,7 @@
 #include <linux/llist.h>
 #include <linux/ctype.h>
 #include <linux/hdmi.h>
+#include <linux/notifier.h>
 #include <drm/drm_mode_object.h>
 #include <drm/drm_util.h>
 
@@ -40,6 +41,7 @@ struct drm_encoder;
 struct drm_property;
 struct drm_property_blob;
 struct drm_printer;
+struct drm_privacy_screen;
 struct edid;
 struct i2c_adapter;
 
@@ -1451,6 +1453,12 @@ struct drm_connector {
 	 */
 	struct drm_property *max_bpc_property;
 
+	/** @privacy_screen: drm_privacy_screen for this connector, or NULL. */
+	struct drm_privacy_screen *privacy_screen;
+
+	/** @privacy_screen_notifier: privacy-screen notifier_block */
+	struct notifier_block privacy_screen_notifier;
+
 	/**
 	 * @privacy_screen_sw_state_property: Optional atomic property for the
 	 * connector to control the integrated privacy screen.
@@ -1788,6 +1796,9 @@ int drm_connector_attach_max_bpc_property(struct drm_connector *connector,
 					  int min, int max);
 void drm_connector_create_privacy_screen_properties(struct drm_connector *conn);
 void drm_connector_attach_privacy_screen_properties(struct drm_connector *conn);
+void drm_connector_attach_privacy_screen_provider(
+	struct drm_connector *connector, struct drm_privacy_screen *priv);
+void drm_connector_update_privacy_screen(const struct drm_connector_state *connector_state);
 
 /**
  * struct drm_tile_group - Tile group metadata
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 06/10] platform/x86: thinkpad_acpi: Add hotkey_notify_extended_hotkey() helper
  2021-10-05 20:23 [PATCH 00/10] drm: Add privacy-screen class and connector properties Hans de Goede
                   ` (4 preceding siblings ...)
  2021-10-05 20:23 ` [PATCH 05/10] drm/connector: Add a drm_connector privacy-screen helper functions (v2) Hans de Goede
@ 2021-10-05 20:23 ` Hans de Goede
  2021-10-05 20:23 ` [PATCH 07/10] platform/x86: thinkpad_acpi: Get privacy-screen / lcdshadow ACPI handles only once Hans de Goede
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 24+ messages in thread
From: Hans de Goede @ 2021-10-05 20:23 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Rajat Jain,
	Jani Nikula, Lyude, Joonas Lahtinen, Rodrigo Vivi,
	Ville Syrjälä,
	Mark Gross, Andy Shevchenko
  Cc: Hans de Goede, Daniel Vetter, David Airlie, Pekka Paalanen,
	Mario Limonciello, Mark Pearson, Sebastien Bacher,
	Marco Trevisan, Emil Velikov, intel-gfx, dri-devel,
	platform-driver-x86

Factor the extended hotkey handling out of hotkey_notify_hotkey() and
into a new hotkey_notify_extended_hotkey() helper.

This is a preparation patch for adding support the privacy-screen hotkey
toggle (which needs some special handling, it should NOT send an evdev
key-event to userspace...).

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/platform/x86/thinkpad_acpi.c | 30 ++++++++++++++++++----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 50ff04c84650..83c88a8ebaf2 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3885,6 +3885,24 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode)
 	}
 }
 
+static bool hotkey_notify_extended_hotkey(const u32 hkey)
+{
+	unsigned int scancode;
+
+	/* Extended keycodes start at 0x300 and our offset into the map
+	 * TP_ACPI_HOTKEYSCAN_EXTENDED_START. The calculated scancode
+	 * will be positive, but might not be in the correct range.
+	 */
+	scancode = (hkey & 0xfff) - (0x300 - TP_ACPI_HOTKEYSCAN_EXTENDED_START);
+	if (scancode >= TP_ACPI_HOTKEYSCAN_EXTENDED_START &&
+	    scancode < TPACPI_HOTKEY_MAP_LEN) {
+		tpacpi_input_send_key(scancode);
+		return true;
+	}
+
+	return false;
+}
+
 static bool hotkey_notify_hotkey(const u32 hkey,
 				 bool *send_acpi_ev,
 				 bool *ignore_acpi_ev)
@@ -3919,17 +3937,7 @@ static bool hotkey_notify_hotkey(const u32 hkey,
 		return adaptive_keyboard_hotkey_notify_hotkey(scancode);
 
 	case 3:
-		/* Extended keycodes start at 0x300 and our offset into the map
-		 * TP_ACPI_HOTKEYSCAN_EXTENDED_START. The calculated scancode
-		 * will be positive, but might not be in the correct range.
-		 */
-		scancode -= (0x300 - TP_ACPI_HOTKEYSCAN_EXTENDED_START);
-		if (scancode >= TP_ACPI_HOTKEYSCAN_EXTENDED_START &&
-		    scancode < TPACPI_HOTKEY_MAP_LEN) {
-			tpacpi_input_send_key(scancode);
-			return true;
-		}
-		break;
+		return hotkey_notify_extended_hotkey(hkey);
 	}
 
 	return false;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 07/10] platform/x86: thinkpad_acpi: Get privacy-screen / lcdshadow ACPI handles only once
  2021-10-05 20:23 [PATCH 00/10] drm: Add privacy-screen class and connector properties Hans de Goede
                   ` (5 preceding siblings ...)
  2021-10-05 20:23 ` [PATCH 06/10] platform/x86: thinkpad_acpi: Add hotkey_notify_extended_hotkey() helper Hans de Goede
@ 2021-10-05 20:23 ` Hans de Goede
  2021-10-05 20:23 ` [PATCH 08/10] platform/x86: thinkpad_acpi: Register a privacy-screen device Hans de Goede
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 24+ messages in thread
From: Hans de Goede @ 2021-10-05 20:23 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Rajat Jain,
	Jani Nikula, Lyude, Joonas Lahtinen, Rodrigo Vivi,
	Ville Syrjälä,
	Mark Gross, Andy Shevchenko
  Cc: Hans de Goede, Daniel Vetter, David Airlie, Pekka Paalanen,
	Mario Limonciello, Mark Pearson, Sebastien Bacher,
	Marco Trevisan, Emil Velikov, intel-gfx, dri-devel,
	platform-driver-x86

Get the privacy-screen / lcdshadow ACPI handles once and cache them,
instead of retrieving them every time we need them.

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/platform/x86/thinkpad_acpi.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 83c88a8ebaf2..b8f2556c4797 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -9819,19 +9819,15 @@ static struct ibm_struct battery_driver_data = {
  * LCD Shadow subdriver, for the Lenovo PrivacyGuard feature
  */
 
+static acpi_handle lcdshadow_get_handle;
+static acpi_handle lcdshadow_set_handle;
 static int lcdshadow_state;
 
 static int lcdshadow_on_off(bool state)
 {
-	acpi_handle set_shadow_handle;
 	int output;
 
-	if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "SSSS", &set_shadow_handle))) {
-		pr_warn("Thinkpad ACPI has no %s interface.\n", "SSSS");
-		return -EIO;
-	}
-
-	if (!acpi_evalf(set_shadow_handle, &output, NULL, "dd", (int)state))
+	if (!acpi_evalf(lcdshadow_set_handle, &output, NULL, "dd", (int)state))
 		return -EIO;
 
 	lcdshadow_state = state;
@@ -9849,15 +9845,17 @@ static int lcdshadow_set(bool on)
 
 static int tpacpi_lcdshadow_init(struct ibm_init_struct *iibm)
 {
-	acpi_handle get_shadow_handle;
+	acpi_status status1, status2;
 	int output;
 
-	if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "GSSS", &get_shadow_handle))) {
+	status1 = acpi_get_handle(hkey_handle, "GSSS", &lcdshadow_get_handle);
+	status2 = acpi_get_handle(hkey_handle, "SSSS", &lcdshadow_set_handle);
+	if (ACPI_FAILURE(status1) || ACPI_FAILURE(status2)) {
 		lcdshadow_state = -ENODEV;
 		return 0;
 	}
 
-	if (!acpi_evalf(get_shadow_handle, &output, NULL, "dd", 0)) {
+	if (!acpi_evalf(lcdshadow_get_handle, &output, NULL, "dd", 0)) {
 		lcdshadow_state = -EIO;
 		return -EIO;
 	}
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 08/10] platform/x86: thinkpad_acpi: Register a privacy-screen device
  2021-10-05 20:23 [PATCH 00/10] drm: Add privacy-screen class and connector properties Hans de Goede
                   ` (6 preceding siblings ...)
  2021-10-05 20:23 ` [PATCH 07/10] platform/x86: thinkpad_acpi: Get privacy-screen / lcdshadow ACPI handles only once Hans de Goede
@ 2021-10-05 20:23 ` Hans de Goede
  2021-10-05 20:23 ` [PATCH 09/10] drm/i915: Add intel_modeset_probe_defer() helper Hans de Goede
  2021-10-05 20:23 ` [PATCH 10/10] drm/i915: Add privacy-screen support (v3) Hans de Goede
  9 siblings, 0 replies; 24+ messages in thread
From: Hans de Goede @ 2021-10-05 20:23 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Rajat Jain,
	Jani Nikula, Lyude, Joonas Lahtinen, Rodrigo Vivi,
	Ville Syrjälä,
	Mark Gross, Andy Shevchenko
  Cc: Hans de Goede, Daniel Vetter, David Airlie, Pekka Paalanen,
	Mario Limonciello, Mark Pearson, Sebastien Bacher,
	Marco Trevisan, Emil Velikov, intel-gfx, dri-devel,
	platform-driver-x86

Register a privacy-screen device on laptops with a privacy-screen,
this exports the PrivacyGuard features to user-space using a
standardized vendor-agnostic sysfs interface. Note the sysfs interface
is read-only.

Registering a privacy-screen device with the new privacy-screen class
code will also allow the GPU driver to get a handle to it and export
the privacy-screen setting as a property on the DRM connector object
for the LCD panel. This DRM connector property is a new standardized
interface which all user-space code should use to query and control
the privacy-screen.

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v3:
- On receiving a TP_HKEY_EV_PRIVACYGUARD_TOGGLE event only call
  drm_privacy_screen_call_notifier_chain() if the privacy-screen state
  has actually changed

Changes in v2:
- Make the new lcdshadow_set_sw_state, lcdshadow_get_hw_state and
  lcdshadow_ops symbols static
- Update state and call drm_privacy_screen_call_notifier_chain()
  when the state is changed by pressing the Fn + D hotkey combo
---
 drivers/platform/x86/Kconfig         |  2 +
 drivers/platform/x86/thinkpad_acpi.c | 97 +++++++++++++++++++++-------
 2 files changed, 74 insertions(+), 25 deletions(-)

diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index e21ea3d23e6f..20208207e366 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -501,7 +501,9 @@ config THINKPAD_ACPI
 	depends on ACPI_VIDEO || ACPI_VIDEO = n
 	depends on BACKLIGHT_CLASS_DEVICE
 	depends on I2C
+	depends on DRM
 	select ACPI_PLATFORM_PROFILE
+	select DRM_PRIVACY_SCREEN
 	select HWMON
 	select NVRAM
 	select NEW_LEDS
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index b8f2556c4797..291cd18c9c8f 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -73,6 +73,7 @@
 #include <linux/uaccess.h>
 #include <acpi/battery.h>
 #include <acpi/video.h>
+#include <drm/drm_privacy_screen_driver.h>
 #include "dual_accel_detect.h"
 
 /* ThinkPad CMOS commands */
@@ -157,6 +158,7 @@ enum tpacpi_hkey_event_t {
 	TP_HKEY_EV_VOL_UP		= 0x1015, /* Volume up or unmute */
 	TP_HKEY_EV_VOL_DOWN		= 0x1016, /* Volume down or unmute */
 	TP_HKEY_EV_VOL_MUTE		= 0x1017, /* Mixer output mute */
+	TP_HKEY_EV_PRIVACYGUARD_TOGGLE	= 0x130f, /* Toggle priv.guard on/off */
 
 	/* Reasons for waking up from S3/S4 */
 	TP_HKEY_EV_WKUP_S3_UNDOCK	= 0x2304, /* undock requested, S3 */
@@ -3889,6 +3891,12 @@ static bool hotkey_notify_extended_hotkey(const u32 hkey)
 {
 	unsigned int scancode;
 
+	switch (hkey) {
+	case TP_HKEY_EV_PRIVACYGUARD_TOGGLE:
+		tpacpi_driver_event(hkey);
+		return true;
+	}
+
 	/* Extended keycodes start at 0x300 and our offset into the map
 	 * TP_ACPI_HOTKEYSCAN_EXTENDED_START. The calculated scancode
 	 * will be positive, but might not be in the correct range.
@@ -9819,30 +9827,40 @@ static struct ibm_struct battery_driver_data = {
  * LCD Shadow subdriver, for the Lenovo PrivacyGuard feature
  */
 
+static struct drm_privacy_screen *lcdshadow_dev;
 static acpi_handle lcdshadow_get_handle;
 static acpi_handle lcdshadow_set_handle;
-static int lcdshadow_state;
 
-static int lcdshadow_on_off(bool state)
+static int lcdshadow_set_sw_state(struct drm_privacy_screen *priv,
+				  enum drm_privacy_screen_status state)
 {
 	int output;
 
+	if (WARN_ON(!mutex_is_locked(&priv->lock)))
+		return -EIO;
+
 	if (!acpi_evalf(lcdshadow_set_handle, &output, NULL, "dd", (int)state))
 		return -EIO;
 
-	lcdshadow_state = state;
+	priv->hw_state = priv->sw_state = state;
 	return 0;
 }
 
-static int lcdshadow_set(bool on)
+static void lcdshadow_get_hw_state(struct drm_privacy_screen *priv)
 {
-	if (lcdshadow_state < 0)
-		return lcdshadow_state;
-	if (lcdshadow_state == on)
-		return 0;
-	return lcdshadow_on_off(on);
+	int output;
+
+	if (!acpi_evalf(lcdshadow_get_handle, &output, NULL, "dd", 0))
+		return;
+
+	priv->hw_state = priv->sw_state = output & 0x1;
 }
 
+static const struct drm_privacy_screen_ops lcdshadow_ops = {
+	.set_sw_state = lcdshadow_set_sw_state,
+	.get_hw_state = lcdshadow_get_hw_state,
+};
+
 static int tpacpi_lcdshadow_init(struct ibm_init_struct *iibm)
 {
 	acpi_status status1, status2;
@@ -9850,36 +9868,44 @@ static int tpacpi_lcdshadow_init(struct ibm_init_struct *iibm)
 
 	status1 = acpi_get_handle(hkey_handle, "GSSS", &lcdshadow_get_handle);
 	status2 = acpi_get_handle(hkey_handle, "SSSS", &lcdshadow_set_handle);
-	if (ACPI_FAILURE(status1) || ACPI_FAILURE(status2)) {
-		lcdshadow_state = -ENODEV;
+	if (ACPI_FAILURE(status1) || ACPI_FAILURE(status2))
 		return 0;
-	}
 
-	if (!acpi_evalf(lcdshadow_get_handle, &output, NULL, "dd", 0)) {
-		lcdshadow_state = -EIO;
+	if (!acpi_evalf(lcdshadow_get_handle, &output, NULL, "dd", 0))
 		return -EIO;
-	}
-	if (!(output & 0x10000)) {
-		lcdshadow_state = -ENODEV;
+
+	if (!(output & 0x10000))
 		return 0;
-	}
-	lcdshadow_state = output & 0x1;
+
+	lcdshadow_dev = drm_privacy_screen_register(&tpacpi_pdev->dev,
+						    &lcdshadow_ops);
+	if (IS_ERR(lcdshadow_dev))
+		return PTR_ERR(lcdshadow_dev);
 
 	return 0;
 }
 
+static void lcdshadow_exit(void)
+{
+	drm_privacy_screen_unregister(lcdshadow_dev);
+}
+
 static void lcdshadow_resume(void)
 {
-	if (lcdshadow_state >= 0)
-		lcdshadow_on_off(lcdshadow_state);
+	if (!lcdshadow_dev)
+		return;
+
+	mutex_lock(&lcdshadow_dev->lock);
+	lcdshadow_set_sw_state(lcdshadow_dev, lcdshadow_dev->sw_state);
+	mutex_unlock(&lcdshadow_dev->lock);
 }
 
 static int lcdshadow_read(struct seq_file *m)
 {
-	if (lcdshadow_state < 0) {
+	if (!lcdshadow_dev) {
 		seq_puts(m, "status:\t\tnot supported\n");
 	} else {
-		seq_printf(m, "status:\t\t%d\n", lcdshadow_state);
+		seq_printf(m, "status:\t\t%d\n", lcdshadow_dev->hw_state);
 		seq_puts(m, "commands:\t0, 1\n");
 	}
 
@@ -9891,7 +9917,7 @@ static int lcdshadow_write(char *buf)
 	char *cmd;
 	int res, state = -EINVAL;
 
-	if (lcdshadow_state < 0)
+	if (!lcdshadow_dev)
 		return -ENODEV;
 
 	while ((cmd = strsep(&buf, ","))) {
@@ -9903,11 +9929,18 @@ static int lcdshadow_write(char *buf)
 	if (state >= 2 || state < 0)
 		return -EINVAL;
 
-	return lcdshadow_set(state);
+	mutex_lock(&lcdshadow_dev->lock);
+	res = lcdshadow_set_sw_state(lcdshadow_dev, state);
+	mutex_unlock(&lcdshadow_dev->lock);
+
+	drm_privacy_screen_call_notifier_chain(lcdshadow_dev);
+
+	return res;
 }
 
 static struct ibm_struct lcdshadow_driver_data = {
 	.name = "lcdshadow",
+	.exit = lcdshadow_exit,
 	.resume = lcdshadow_resume,
 	.read = lcdshadow_read,
 	.write = lcdshadow_write,
@@ -10717,6 +10750,20 @@ static void tpacpi_driver_event(const unsigned int hkey_event)
 		if (!atomic_add_unless(&dytc_ignore_event, -1, 0))
 			dytc_profile_refresh();
 	}
+
+	if (lcdshadow_dev && hkey_event == TP_HKEY_EV_PRIVACYGUARD_TOGGLE) {
+		enum drm_privacy_screen_status old_hw_state;
+		bool changed;
+
+		mutex_lock(&lcdshadow_dev->lock);
+		old_hw_state = lcdshadow_dev->hw_state;
+		lcdshadow_get_hw_state(lcdshadow_dev);
+		changed = lcdshadow_dev->hw_state != old_hw_state;
+		mutex_unlock(&lcdshadow_dev->lock);
+
+		if (changed)
+			drm_privacy_screen_call_notifier_chain(lcdshadow_dev);
+	}
 }
 
 static void hotkey_driver_event(const unsigned int scancode)
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 09/10] drm/i915: Add intel_modeset_probe_defer() helper
  2021-10-05 20:23 [PATCH 00/10] drm: Add privacy-screen class and connector properties Hans de Goede
                   ` (7 preceding siblings ...)
  2021-10-05 20:23 ` [PATCH 08/10] platform/x86: thinkpad_acpi: Register a privacy-screen device Hans de Goede
@ 2021-10-05 20:23 ` Hans de Goede
  2021-10-05 20:23 ` [PATCH 10/10] drm/i915: Add privacy-screen support (v3) Hans de Goede
  9 siblings, 0 replies; 24+ messages in thread
From: Hans de Goede @ 2021-10-05 20:23 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Rajat Jain,
	Jani Nikula, Lyude, Joonas Lahtinen, Rodrigo Vivi,
	Ville Syrjälä,
	Mark Gross, Andy Shevchenko
  Cc: Hans de Goede, Daniel Vetter, David Airlie, Pekka Paalanen,
	Mario Limonciello, Mark Pearson, Sebastien Bacher,
	Marco Trevisan, Emil Velikov, intel-gfx, dri-devel,
	platform-driver-x86

The upcoming privacy-screen support adds another check for
deferring probe till some other drivers have bound first.

Factor out the current vga_switcheroo_client_probe_defer() check
into an intel_modeset_probe_defer() helper, so that further
probe-deferral checks can be added there.

Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/gpu/drm/i915/display/intel_display.c | 13 +++++++++++++
 drivers/gpu/drm/i915/display/intel_display.h |  1 +
 drivers/gpu/drm/i915/i915_pci.c              |  9 ++-------
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c
index 4f0badb11bbb..86dbe366a907 100644
--- a/drivers/gpu/drm/i915/display/intel_display.c
+++ b/drivers/gpu/drm/i915/display/intel_display.c
@@ -32,6 +32,7 @@
 #include <linux/module.h>
 #include <linux/dma-resv.h>
 #include <linux/slab.h>
+#include <linux/vga_switcheroo.h>
 
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
@@ -12766,6 +12767,18 @@ void intel_modeset_driver_remove_nogem(struct drm_i915_private *i915)
 	intel_bios_driver_remove(i915);
 }
 
+bool intel_modeset_probe_defer(struct pci_dev *pdev)
+{
+	/*
+	 * apple-gmux is needed on dual GPU MacBook Pro
+	 * to probe the panel if we're the inactive GPU.
+	 */
+	if (vga_switcheroo_client_probe_defer(pdev))
+		return true;
+
+	return false;
+}
+
 void intel_display_driver_register(struct drm_i915_private *i915)
 {
 	if (!HAS_DISPLAY(i915))
diff --git a/drivers/gpu/drm/i915/display/intel_display.h b/drivers/gpu/drm/i915/display/intel_display.h
index 3028072c2cf3..d3d34acb6c08 100644
--- a/drivers/gpu/drm/i915/display/intel_display.h
+++ b/drivers/gpu/drm/i915/display/intel_display.h
@@ -633,6 +633,7 @@ void intel_display_driver_register(struct drm_i915_private *i915);
 void intel_display_driver_unregister(struct drm_i915_private *i915);
 
 /* modesetting */
+bool intel_modeset_probe_defer(struct pci_dev *pdev);
 void intel_modeset_init_hw(struct drm_i915_private *i915);
 int intel_modeset_init_noirq(struct drm_i915_private *i915);
 int intel_modeset_init_nogem(struct drm_i915_private *i915);
diff --git a/drivers/gpu/drm/i915/i915_pci.c b/drivers/gpu/drm/i915/i915_pci.c
index 169837de395d..8fc45d8119b6 100644
--- a/drivers/gpu/drm/i915/i915_pci.c
+++ b/drivers/gpu/drm/i915/i915_pci.c
@@ -22,8 +22,6 @@
  *
  */
 
-#include <linux/vga_switcheroo.h>
-
 #include <drm/drm_drv.h>
 #include <drm/i915_pciids.h>
 
@@ -1189,11 +1187,8 @@ static int i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (PCI_FUNC(pdev->devfn))
 		return -ENODEV;
 
-	/*
-	 * apple-gmux is needed on dual GPU MacBook Pro
-	 * to probe the panel if we're the inactive GPU.
-	 */
-	if (vga_switcheroo_client_probe_defer(pdev))
+	/* Detect if we need to wait for other drivers early on */
+	if (intel_modeset_probe_defer(pdev))
 		return -EPROBE_DEFER;
 
 	err = i915_driver_probe(pdev, ent);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 10/10] drm/i915: Add privacy-screen support (v3)
  2021-10-05 20:23 [PATCH 00/10] drm: Add privacy-screen class and connector properties Hans de Goede
                   ` (8 preceding siblings ...)
  2021-10-05 20:23 ` [PATCH 09/10] drm/i915: Add intel_modeset_probe_defer() helper Hans de Goede
@ 2021-10-05 20:23 ` Hans de Goede
  2021-10-13 21:59   ` Ville Syrjälä
  2021-11-17 13:59   ` Rajat Jain
  9 siblings, 2 replies; 24+ messages in thread
From: Hans de Goede @ 2021-10-05 20:23 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Rajat Jain,
	Jani Nikula, Lyude, Joonas Lahtinen, Rodrigo Vivi,
	Ville Syrjälä,
	Mark Gross, Andy Shevchenko
  Cc: Hans de Goede, Daniel Vetter, David Airlie, Pekka Paalanen,
	Mario Limonciello, Mark Pearson, Sebastien Bacher,
	Marco Trevisan, Emil Velikov, intel-gfx, dri-devel,
	platform-driver-x86

Add support for eDP panels with a built-in privacy screen using the
new drm_privacy_screen class.

Changes in v3:
- Move drm_privacy_screen_get() call to intel_ddi_init_dp_connector()

Changes in v2:
- Call drm_connector_update_privacy_screen() from
  intel_enable_ddi_dp() / intel_ddi_update_pipe_dp() instead of adding a
  for_each_new_connector_in_state() loop to intel_atomic_commit_tail()
- Move the probe-deferral check to the intel_modeset_probe_defer() helper

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/gpu/drm/i915/display/intel_atomic.c  |  1 +
 drivers/gpu/drm/i915/display/intel_ddi.c     | 16 ++++++++++++++++
 drivers/gpu/drm/i915/display/intel_display.c | 10 ++++++++++
 3 files changed, 27 insertions(+)

diff --git a/drivers/gpu/drm/i915/display/intel_atomic.c b/drivers/gpu/drm/i915/display/intel_atomic.c
index b4e7ac51aa31..a62550711e98 100644
--- a/drivers/gpu/drm/i915/display/intel_atomic.c
+++ b/drivers/gpu/drm/i915/display/intel_atomic.c
@@ -139,6 +139,7 @@ int intel_digital_connector_atomic_check(struct drm_connector *conn,
 	    new_conn_state->base.picture_aspect_ratio != old_conn_state->base.picture_aspect_ratio ||
 	    new_conn_state->base.content_type != old_conn_state->base.content_type ||
 	    new_conn_state->base.scaling_mode != old_conn_state->base.scaling_mode ||
+	    new_conn_state->base.privacy_screen_sw_state != old_conn_state->base.privacy_screen_sw_state ||
 	    !drm_connector_atomic_hdr_metadata_equal(old_state, new_state))
 		crtc_state->mode_changed = true;
 
diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c b/drivers/gpu/drm/i915/display/intel_ddi.c
index 0d4cf7fa8720..272714e07cc6 100644
--- a/drivers/gpu/drm/i915/display/intel_ddi.c
+++ b/drivers/gpu/drm/i915/display/intel_ddi.c
@@ -25,6 +25,7 @@
  *
  */
 
+#include <drm/drm_privacy_screen_consumer.h>
 #include <drm/drm_scdc_helper.h>
 
 #include "i915_drv.h"
@@ -2946,6 +2947,7 @@ static void intel_enable_ddi_dp(struct intel_atomic_state *state,
 	if (port == PORT_A && DISPLAY_VER(dev_priv) < 9)
 		intel_dp_stop_link_train(intel_dp, crtc_state);
 
+	drm_connector_update_privacy_screen(conn_state);
 	intel_edp_backlight_on(crtc_state, conn_state);
 
 	if (!dig_port->lspcon.active || dig_port->dp.has_hdmi_sink)
@@ -3161,6 +3163,7 @@ static void intel_ddi_update_pipe_dp(struct intel_atomic_state *state,
 	intel_drrs_update(intel_dp, crtc_state);
 
 	intel_backlight_update(state, encoder, crtc_state, conn_state);
+	drm_connector_update_privacy_screen(conn_state);
 }
 
 void intel_ddi_update_pipe(struct intel_atomic_state *state,
@@ -3979,6 +3982,19 @@ intel_ddi_init_dp_connector(struct intel_digital_port *dig_port)
 		return NULL;
 	}
 
+	if (dig_port->base.type == INTEL_OUTPUT_EDP) {
+		struct drm_device *dev = dig_port->base.base.dev;
+		struct drm_privacy_screen *privacy_screen;
+
+		privacy_screen = drm_privacy_screen_get(dev->dev, NULL);
+		if (!IS_ERR(privacy_screen)) {
+			drm_connector_attach_privacy_screen_provider(&connector->base,
+								     privacy_screen);
+		} else if (PTR_ERR(privacy_screen) != -ENODEV) {
+			drm_warn(dev, "Error getting privacy-screen\n");
+		}
+	}
+
 	return connector;
 }
 
diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c
index 86dbe366a907..84715a779d9d 100644
--- a/drivers/gpu/drm/i915/display/intel_display.c
+++ b/drivers/gpu/drm/i915/display/intel_display.c
@@ -42,6 +42,7 @@
 #include <drm/drm_edid.h>
 #include <drm/drm_fourcc.h>
 #include <drm/drm_plane_helper.h>
+#include <drm/drm_privacy_screen_consumer.h>
 #include <drm/drm_probe_helper.h>
 #include <drm/drm_rect.h>
 
@@ -12769,6 +12770,8 @@ void intel_modeset_driver_remove_nogem(struct drm_i915_private *i915)
 
 bool intel_modeset_probe_defer(struct pci_dev *pdev)
 {
+	struct drm_privacy_screen *privacy_screen;
+
 	/*
 	 * apple-gmux is needed on dual GPU MacBook Pro
 	 * to probe the panel if we're the inactive GPU.
@@ -12776,6 +12779,13 @@ bool intel_modeset_probe_defer(struct pci_dev *pdev)
 	if (vga_switcheroo_client_probe_defer(pdev))
 		return true;
 
+	/* If the LCD panel has a privacy-screen, wait for it */
+	privacy_screen = drm_privacy_screen_get(&pdev->dev, NULL);
+	if (IS_ERR(privacy_screen) && PTR_ERR(privacy_screen) == -EPROBE_DEFER)
+		return true;
+
+	drm_privacy_screen_put(privacy_screen);
+
 	return false;
 }
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH 10/10] drm/i915: Add privacy-screen support (v3)
  2021-10-05 20:23 ` [PATCH 10/10] drm/i915: Add privacy-screen support (v3) Hans de Goede
@ 2021-10-13 21:59   ` Ville Syrjälä
  2021-11-03 23:16     ` Rajat Jain
  2021-11-17 13:59   ` Rajat Jain
  1 sibling, 1 reply; 24+ messages in thread
From: Ville Syrjälä @ 2021-10-13 21:59 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Rajat Jain,
	Jani Nikula, Lyude, Joonas Lahtinen, Rodrigo Vivi, Mark Gross,
	Andy Shevchenko, Daniel Vetter, David Airlie, Pekka Paalanen,
	Mario Limonciello, Mark Pearson, Sebastien Bacher,
	Marco Trevisan, Emil Velikov, intel-gfx, dri-devel,
	platform-driver-x86

On Tue, Oct 05, 2021 at 10:23:22PM +0200, Hans de Goede wrote:
> Add support for eDP panels with a built-in privacy screen using the
> new drm_privacy_screen class.
> 
> Changes in v3:
> - Move drm_privacy_screen_get() call to intel_ddi_init_dp_connector()
> 
> Changes in v2:
> - Call drm_connector_update_privacy_screen() from
>   intel_enable_ddi_dp() / intel_ddi_update_pipe_dp() instead of adding a
>   for_each_new_connector_in_state() loop to intel_atomic_commit_tail()
> - Move the probe-deferral check to the intel_modeset_probe_defer() helper
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/gpu/drm/i915/display/intel_atomic.c  |  1 +
>  drivers/gpu/drm/i915/display/intel_ddi.c     | 16 ++++++++++++++++
>  drivers/gpu/drm/i915/display/intel_display.c | 10 ++++++++++
>  3 files changed, 27 insertions(+)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_atomic.c b/drivers/gpu/drm/i915/display/intel_atomic.c
> index b4e7ac51aa31..a62550711e98 100644
> --- a/drivers/gpu/drm/i915/display/intel_atomic.c
> +++ b/drivers/gpu/drm/i915/display/intel_atomic.c
> @@ -139,6 +139,7 @@ int intel_digital_connector_atomic_check(struct drm_connector *conn,
>  	    new_conn_state->base.picture_aspect_ratio != old_conn_state->base.picture_aspect_ratio ||
>  	    new_conn_state->base.content_type != old_conn_state->base.content_type ||
>  	    new_conn_state->base.scaling_mode != old_conn_state->base.scaling_mode ||
> +	    new_conn_state->base.privacy_screen_sw_state != old_conn_state->base.privacy_screen_sw_state ||
>  	    !drm_connector_atomic_hdr_metadata_equal(old_state, new_state))
>  		crtc_state->mode_changed = true;
>  
> diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c b/drivers/gpu/drm/i915/display/intel_ddi.c
> index 0d4cf7fa8720..272714e07cc6 100644
> --- a/drivers/gpu/drm/i915/display/intel_ddi.c
> +++ b/drivers/gpu/drm/i915/display/intel_ddi.c
> @@ -25,6 +25,7 @@
>   *
>   */
>  
> +#include <drm/drm_privacy_screen_consumer.h>
>  #include <drm/drm_scdc_helper.h>
>  
>  #include "i915_drv.h"
> @@ -2946,6 +2947,7 @@ static void intel_enable_ddi_dp(struct intel_atomic_state *state,
>  	if (port == PORT_A && DISPLAY_VER(dev_priv) < 9)
>  		intel_dp_stop_link_train(intel_dp, crtc_state);
>  
> +	drm_connector_update_privacy_screen(conn_state);
>  	intel_edp_backlight_on(crtc_state, conn_state);
>  
>  	if (!dig_port->lspcon.active || dig_port->dp.has_hdmi_sink)
> @@ -3161,6 +3163,7 @@ static void intel_ddi_update_pipe_dp(struct intel_atomic_state *state,
>  	intel_drrs_update(intel_dp, crtc_state);
>  
>  	intel_backlight_update(state, encoder, crtc_state, conn_state);
> +	drm_connector_update_privacy_screen(conn_state);
>  }
>  
>  void intel_ddi_update_pipe(struct intel_atomic_state *state,
> @@ -3979,6 +3982,19 @@ intel_ddi_init_dp_connector(struct intel_digital_port *dig_port)
>  		return NULL;
>  	}
>  
> +	if (dig_port->base.type == INTEL_OUTPUT_EDP) {

Connector type check would be a bit more consistent with what this is
about I think. But there's is 1:1 correspondence with the encoder type
for eDP so not a particularly important point.

Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

> +		struct drm_device *dev = dig_port->base.base.dev;
> +		struct drm_privacy_screen *privacy_screen;
> +
> +		privacy_screen = drm_privacy_screen_get(dev->dev, NULL);
> +		if (!IS_ERR(privacy_screen)) {
> +			drm_connector_attach_privacy_screen_provider(&connector->base,
> +								     privacy_screen);
> +		} else if (PTR_ERR(privacy_screen) != -ENODEV) {
> +			drm_warn(dev, "Error getting privacy-screen\n");
> +		}
> +	}
> +
>  	return connector;
>  }
>  
> diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c
> index 86dbe366a907..84715a779d9d 100644
> --- a/drivers/gpu/drm/i915/display/intel_display.c
> +++ b/drivers/gpu/drm/i915/display/intel_display.c
> @@ -42,6 +42,7 @@
>  #include <drm/drm_edid.h>
>  #include <drm/drm_fourcc.h>
>  #include <drm/drm_plane_helper.h>
> +#include <drm/drm_privacy_screen_consumer.h>
>  #include <drm/drm_probe_helper.h>
>  #include <drm/drm_rect.h>
>  
> @@ -12769,6 +12770,8 @@ void intel_modeset_driver_remove_nogem(struct drm_i915_private *i915)
>  
>  bool intel_modeset_probe_defer(struct pci_dev *pdev)
>  {
> +	struct drm_privacy_screen *privacy_screen;
> +
>  	/*
>  	 * apple-gmux is needed on dual GPU MacBook Pro
>  	 * to probe the panel if we're the inactive GPU.
> @@ -12776,6 +12779,13 @@ bool intel_modeset_probe_defer(struct pci_dev *pdev)
>  	if (vga_switcheroo_client_probe_defer(pdev))
>  		return true;
>  
> +	/* If the LCD panel has a privacy-screen, wait for it */
> +	privacy_screen = drm_privacy_screen_get(&pdev->dev, NULL);
> +	if (IS_ERR(privacy_screen) && PTR_ERR(privacy_screen) == -EPROBE_DEFER)
> +		return true;
> +
> +	drm_privacy_screen_put(privacy_screen);
> +
>  	return false;
>  }
>  
> -- 
> 2.31.1

-- 
Ville Syrjälä
Intel

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 10/10] drm/i915: Add privacy-screen support (v3)
  2021-10-13 21:59   ` Ville Syrjälä
@ 2021-11-03 23:16     ` Rajat Jain
  2021-11-04  8:56       ` Hans de Goede
  0 siblings, 1 reply; 24+ messages in thread
From: Rajat Jain @ 2021-11-03 23:16 UTC (permalink / raw)
  To: Ville Syrjälä
  Cc: Hans de Goede, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, Jani Nikula, Lyude, Joonas Lahtinen,
	Rodrigo Vivi, Mark Gross, Andy Shevchenko, Daniel Vetter,
	David Airlie, Pekka Paalanen, Mario Limonciello, Mark Pearson,
	Sebastien Bacher, Marco Trevisan, Emil Velikov, intel-gfx,
	dri-devel, platform-driver-x86

Hello Hans,

Thanks a lot for working on this diligently and getting almost all of
it finally merged!

On Wed, Oct 13, 2021 at 2:59 PM Ville Syrjälä
<ville.syrjala@linux.intel.com> wrote:
>
> On Tue, Oct 05, 2021 at 10:23:22PM +0200, Hans de Goede wrote:
> > Add support for eDP panels with a built-in privacy screen using the
> > new drm_privacy_screen class.
> >
> > Changes in v3:
> > - Move drm_privacy_screen_get() call to intel_ddi_init_dp_connector()
> >
> > Changes in v2:
> > - Call drm_connector_update_privacy_screen() from
> >   intel_enable_ddi_dp() / intel_ddi_update_pipe_dp() instead of adding a
> >   for_each_new_connector_in_state() loop to intel_atomic_commit_tail()
> > - Move the probe-deferral check to the intel_modeset_probe_defer() helper
> >
> > Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> > ---
> >  drivers/gpu/drm/i915/display/intel_atomic.c  |  1 +
> >  drivers/gpu/drm/i915/display/intel_ddi.c     | 16 ++++++++++++++++
> >  drivers/gpu/drm/i915/display/intel_display.c | 10 ++++++++++
> >  3 files changed, 27 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/i915/display/intel_atomic.c b/drivers/gpu/drm/i915/display/intel_atomic.c
> > index b4e7ac51aa31..a62550711e98 100644
> > --- a/drivers/gpu/drm/i915/display/intel_atomic.c
> > +++ b/drivers/gpu/drm/i915/display/intel_atomic.c
> > @@ -139,6 +139,7 @@ int intel_digital_connector_atomic_check(struct drm_connector *conn,
> >           new_conn_state->base.picture_aspect_ratio != old_conn_state->base.picture_aspect_ratio ||
> >           new_conn_state->base.content_type != old_conn_state->base.content_type ||
> >           new_conn_state->base.scaling_mode != old_conn_state->base.scaling_mode ||
> > +         new_conn_state->base.privacy_screen_sw_state != old_conn_state->base.privacy_screen_sw_state ||
> >           !drm_connector_atomic_hdr_metadata_equal(old_state, new_state))
> >               crtc_state->mode_changed = true;
> >
> > diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c b/drivers/gpu/drm/i915/display/intel_ddi.c
> > index 0d4cf7fa8720..272714e07cc6 100644
> > --- a/drivers/gpu/drm/i915/display/intel_ddi.c
> > +++ b/drivers/gpu/drm/i915/display/intel_ddi.c
> > @@ -25,6 +25,7 @@
> >   *
> >   */
> >
> > +#include <drm/drm_privacy_screen_consumer.h>
> >  #include <drm/drm_scdc_helper.h>
> >
> >  #include "i915_drv.h"
> > @@ -2946,6 +2947,7 @@ static void intel_enable_ddi_dp(struct intel_atomic_state *state,
> >       if (port == PORT_A && DISPLAY_VER(dev_priv) < 9)
> >               intel_dp_stop_link_train(intel_dp, crtc_state);
> >
> > +     drm_connector_update_privacy_screen(conn_state);
> >       intel_edp_backlight_on(crtc_state, conn_state);
> >
> >       if (!dig_port->lspcon.active || dig_port->dp.has_hdmi_sink)
> > @@ -3161,6 +3163,7 @@ static void intel_ddi_update_pipe_dp(struct intel_atomic_state *state,
> >       intel_drrs_update(intel_dp, crtc_state);
> >
> >       intel_backlight_update(state, encoder, crtc_state, conn_state);
> > +     drm_connector_update_privacy_screen(conn_state);
> >  }
> >
> >  void intel_ddi_update_pipe(struct intel_atomic_state *state,
> > @@ -3979,6 +3982,19 @@ intel_ddi_init_dp_connector(struct intel_digital_port *dig_port)
> >               return NULL;
> >       }
> >
> > +     if (dig_port->base.type == INTEL_OUTPUT_EDP) {
>
> Connector type check would be a bit more consistent with what this is
> about I think. But there's is 1:1 correspondence with the encoder type
> for eDP so not a particularly important point.
>
> Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

I see only 8 out of 10 patches in this series were applied to drm-tip.
I'm curious if there is any reason for which the last 2 patches were
not applied:

[Patch 9/10]: drm/i915: Add intel_modeset_probe_defer() helper
[Patch 10/10]: drm/i915: Add privacy-screen support (v3)

I look forward to getting them merged so that I can use them.

Thanks & Best regards,

Rajat

>
> > +             struct drm_device *dev = dig_port->base.base.dev;
> > +             struct drm_privacy_screen *privacy_screen;
> > +
> > +             privacy_screen = drm_privacy_screen_get(dev->dev, NULL);
> > +             if (!IS_ERR(privacy_screen)) {
> > +                     drm_connector_attach_privacy_screen_provider(&connector->base,
> > +                                                                  privacy_screen);
> > +             } else if (PTR_ERR(privacy_screen) != -ENODEV) {
> > +                     drm_warn(dev, "Error getting privacy-screen\n");
> > +             }
> > +     }
> > +
> >       return connector;
> >  }
> >
> > diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c
> > index 86dbe366a907..84715a779d9d 100644
> > --- a/drivers/gpu/drm/i915/display/intel_display.c
> > +++ b/drivers/gpu/drm/i915/display/intel_display.c
> > @@ -42,6 +42,7 @@
> >  #include <drm/drm_edid.h>
> >  #include <drm/drm_fourcc.h>
> >  #include <drm/drm_plane_helper.h>
> > +#include <drm/drm_privacy_screen_consumer.h>
> >  #include <drm/drm_probe_helper.h>
> >  #include <drm/drm_rect.h>
> >
> > @@ -12769,6 +12770,8 @@ void intel_modeset_driver_remove_nogem(struct drm_i915_private *i915)
> >
> >  bool intel_modeset_probe_defer(struct pci_dev *pdev)
> >  {
> > +     struct drm_privacy_screen *privacy_screen;
> > +
> >       /*
> >        * apple-gmux is needed on dual GPU MacBook Pro
> >        * to probe the panel if we're the inactive GPU.
> > @@ -12776,6 +12779,13 @@ bool intel_modeset_probe_defer(struct pci_dev *pdev)
> >       if (vga_switcheroo_client_probe_defer(pdev))
> >               return true;
> >
> > +     /* If the LCD panel has a privacy-screen, wait for it */
> > +     privacy_screen = drm_privacy_screen_get(&pdev->dev, NULL);
> > +     if (IS_ERR(privacy_screen) && PTR_ERR(privacy_screen) == -EPROBE_DEFER)
> > +             return true;
> > +
> > +     drm_privacy_screen_put(privacy_screen);
> > +
> >       return false;
> >  }
> >
> > --
> > 2.31.1
>
> --
> Ville Syrjälä
> Intel

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 10/10] drm/i915: Add privacy-screen support (v3)
  2021-11-03 23:16     ` Rajat Jain
@ 2021-11-04  8:56       ` Hans de Goede
  0 siblings, 0 replies; 24+ messages in thread
From: Hans de Goede @ 2021-11-04  8:56 UTC (permalink / raw)
  To: Rajat Jain, Ville Syrjälä
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jani Nikula,
	Lyude, Joonas Lahtinen, Rodrigo Vivi, Mark Gross,
	Andy Shevchenko, Daniel Vetter, David Airlie, Pekka Paalanen,
	Mario Limonciello, Mark Pearson, Sebastien Bacher,
	Marco Trevisan, Emil Velikov, intel-gfx, dri-devel,
	platform-driver-x86

Hi,

On 11/4/21 00:16, Rajat Jain wrote:
> Hello Hans,
> 
> Thanks a lot for working on this diligently and getting almost all of
> it finally merged!
> 
> On Wed, Oct 13, 2021 at 2:59 PM Ville Syrjälä
> <ville.syrjala@linux.intel.com> wrote:
>>
>> On Tue, Oct 05, 2021 at 10:23:22PM +0200, Hans de Goede wrote:
>>> Add support for eDP panels with a built-in privacy screen using the
>>> new drm_privacy_screen class.
>>>
>>> Changes in v3:
>>> - Move drm_privacy_screen_get() call to intel_ddi_init_dp_connector()
>>>
>>> Changes in v2:
>>> - Call drm_connector_update_privacy_screen() from
>>>   intel_enable_ddi_dp() / intel_ddi_update_pipe_dp() instead of adding a
>>>   for_each_new_connector_in_state() loop to intel_atomic_commit_tail()
>>> - Move the probe-deferral check to the intel_modeset_probe_defer() helper
>>>
>>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>>> ---
>>>  drivers/gpu/drm/i915/display/intel_atomic.c  |  1 +
>>>  drivers/gpu/drm/i915/display/intel_ddi.c     | 16 ++++++++++++++++
>>>  drivers/gpu/drm/i915/display/intel_display.c | 10 ++++++++++
>>>  3 files changed, 27 insertions(+)
>>>
>>> diff --git a/drivers/gpu/drm/i915/display/intel_atomic.c b/drivers/gpu/drm/i915/display/intel_atomic.c
>>> index b4e7ac51aa31..a62550711e98 100644
>>> --- a/drivers/gpu/drm/i915/display/intel_atomic.c
>>> +++ b/drivers/gpu/drm/i915/display/intel_atomic.c
>>> @@ -139,6 +139,7 @@ int intel_digital_connector_atomic_check(struct drm_connector *conn,
>>>           new_conn_state->base.picture_aspect_ratio != old_conn_state->base.picture_aspect_ratio ||
>>>           new_conn_state->base.content_type != old_conn_state->base.content_type ||
>>>           new_conn_state->base.scaling_mode != old_conn_state->base.scaling_mode ||
>>> +         new_conn_state->base.privacy_screen_sw_state != old_conn_state->base.privacy_screen_sw_state ||
>>>           !drm_connector_atomic_hdr_metadata_equal(old_state, new_state))
>>>               crtc_state->mode_changed = true;
>>>
>>> diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c b/drivers/gpu/drm/i915/display/intel_ddi.c
>>> index 0d4cf7fa8720..272714e07cc6 100644
>>> --- a/drivers/gpu/drm/i915/display/intel_ddi.c
>>> +++ b/drivers/gpu/drm/i915/display/intel_ddi.c
>>> @@ -25,6 +25,7 @@
>>>   *
>>>   */
>>>
>>> +#include <drm/drm_privacy_screen_consumer.h>
>>>  #include <drm/drm_scdc_helper.h>
>>>
>>>  #include "i915_drv.h"
>>> @@ -2946,6 +2947,7 @@ static void intel_enable_ddi_dp(struct intel_atomic_state *state,
>>>       if (port == PORT_A && DISPLAY_VER(dev_priv) < 9)
>>>               intel_dp_stop_link_train(intel_dp, crtc_state);
>>>
>>> +     drm_connector_update_privacy_screen(conn_state);
>>>       intel_edp_backlight_on(crtc_state, conn_state);
>>>
>>>       if (!dig_port->lspcon.active || dig_port->dp.has_hdmi_sink)
>>> @@ -3161,6 +3163,7 @@ static void intel_ddi_update_pipe_dp(struct intel_atomic_state *state,
>>>       intel_drrs_update(intel_dp, crtc_state);
>>>
>>>       intel_backlight_update(state, encoder, crtc_state, conn_state);
>>> +     drm_connector_update_privacy_screen(conn_state);
>>>  }
>>>
>>>  void intel_ddi_update_pipe(struct intel_atomic_state *state,
>>> @@ -3979,6 +3982,19 @@ intel_ddi_init_dp_connector(struct intel_digital_port *dig_port)
>>>               return NULL;
>>>       }
>>>
>>> +     if (dig_port->base.type == INTEL_OUTPUT_EDP) {
>>
>> Connector type check would be a bit more consistent with what this is
>> about I think. But there's is 1:1 correspondence with the encoder type
>> for eDP so not a particularly important point.
>>
>> Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> I see only 8 out of 10 patches in this series were applied to drm-tip.
> I'm curious if there is any reason for which the last 2 patches were
> not applied:
> 
> [Patch 9/10]: drm/i915: Add intel_modeset_probe_defer() helper
> [Patch 10/10]: drm/i915: Add privacy-screen support (v3)
> 
> I look forward to getting them merged so that I can use them.

The main-parts of the patch-set were merged through drm-misc-next,
the 2 i915 patches had a conflict there since the series was
based on drm-tip and some of the surrounding i915 code had some
small changes in drm-intel-next which was not in drm-misc-next yet.

Once drm-intel-next merges in recent drm-misc-next changes 
(after the merge window closes) I will push the remaining 2 patches
through drm-intel-next and then everything will be in drm-tip and
on its way to 5.17 .

Regards,

Hans



>>> +             struct drm_device *dev = dig_port->base.base.dev;
>>> +             struct drm_privacy_screen *privacy_screen;
>>> +
>>> +             privacy_screen = drm_privacy_screen_get(dev->dev, NULL);
>>> +             if (!IS_ERR(privacy_screen)) {
>>> +                     drm_connector_attach_privacy_screen_provider(&connector->base,
>>> +                                                                  privacy_screen);
>>> +             } else if (PTR_ERR(privacy_screen) != -ENODEV) {
>>> +                     drm_warn(dev, "Error getting privacy-screen\n");
>>> +             }
>>> +     }
>>> +
>>>       return connector;
>>>  }
>>>
>>> diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c
>>> index 86dbe366a907..84715a779d9d 100644
>>> --- a/drivers/gpu/drm/i915/display/intel_display.c
>>> +++ b/drivers/gpu/drm/i915/display/intel_display.c
>>> @@ -42,6 +42,7 @@
>>>  #include <drm/drm_edid.h>
>>>  #include <drm/drm_fourcc.h>
>>>  #include <drm/drm_plane_helper.h>
>>> +#include <drm/drm_privacy_screen_consumer.h>
>>>  #include <drm/drm_probe_helper.h>
>>>  #include <drm/drm_rect.h>
>>>
>>> @@ -12769,6 +12770,8 @@ void intel_modeset_driver_remove_nogem(struct drm_i915_private *i915)
>>>
>>>  bool intel_modeset_probe_defer(struct pci_dev *pdev)
>>>  {
>>> +     struct drm_privacy_screen *privacy_screen;
>>> +
>>>       /*
>>>        * apple-gmux is needed on dual GPU MacBook Pro
>>>        * to probe the panel if we're the inactive GPU.
>>> @@ -12776,6 +12779,13 @@ bool intel_modeset_probe_defer(struct pci_dev *pdev)
>>>       if (vga_switcheroo_client_probe_defer(pdev))
>>>               return true;
>>>
>>> +     /* If the LCD panel has a privacy-screen, wait for it */
>>> +     privacy_screen = drm_privacy_screen_get(&pdev->dev, NULL);
>>> +     if (IS_ERR(privacy_screen) && PTR_ERR(privacy_screen) == -EPROBE_DEFER)
>>> +             return true;
>>> +
>>> +     drm_privacy_screen_put(privacy_screen);
>>> +
>>>       return false;
>>>  }
>>>
>>> --
>>> 2.31.1
>>
>> --
>> Ville Syrjälä
>> Intel
> 


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 10/10] drm/i915: Add privacy-screen support (v3)
  2021-10-05 20:23 ` [PATCH 10/10] drm/i915: Add privacy-screen support (v3) Hans de Goede
  2021-10-13 21:59   ` Ville Syrjälä
@ 2021-11-17 13:59   ` Rajat Jain
  2021-11-17 16:18     ` Hans de Goede
  1 sibling, 1 reply; 24+ messages in thread
From: Rajat Jain @ 2021-11-17 13:59 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jani Nikula,
	Lyude, Joonas Lahtinen, Rodrigo Vivi, Ville Syrjälä,
	Mark Gross, Andy Shevchenko, Daniel Vetter, David Airlie,
	Pekka Paalanen, Mario Limonciello, Mark Pearson,
	Sebastien Bacher, Marco Trevisan, Emil Velikov, intel-gfx,
	dri-devel, platform-driver-x86

Hello Hans,

I'm working on my platform's privacy-screen support based on your
patches, and had some (I know late) questions. Would be great if you
could please help answer. Please see inline.

On Tue, Oct 5, 2021 at 1:25 PM Hans de Goede <hdegoede@redhat.com> wrote:
>
> Add support for eDP panels with a built-in privacy screen using the
> new drm_privacy_screen class.
>
> Changes in v3:
> - Move drm_privacy_screen_get() call to intel_ddi_init_dp_connector()
>
> Changes in v2:
> - Call drm_connector_update_privacy_screen() from
>   intel_enable_ddi_dp() / intel_ddi_update_pipe_dp() instead of adding a
>   for_each_new_connector_in_state() loop to intel_atomic_commit_tail()
> - Move the probe-deferral check to the intel_modeset_probe_defer() helper
>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/gpu/drm/i915/display/intel_atomic.c  |  1 +
>  drivers/gpu/drm/i915/display/intel_ddi.c     | 16 ++++++++++++++++
>  drivers/gpu/drm/i915/display/intel_display.c | 10 ++++++++++
>  3 files changed, 27 insertions(+)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_atomic.c b/drivers/gpu/drm/i915/display/intel_atomic.c
> index b4e7ac51aa31..a62550711e98 100644
> --- a/drivers/gpu/drm/i915/display/intel_atomic.c
> +++ b/drivers/gpu/drm/i915/display/intel_atomic.c
> @@ -139,6 +139,7 @@ int intel_digital_connector_atomic_check(struct drm_connector *conn,
>             new_conn_state->base.picture_aspect_ratio != old_conn_state->base.picture_aspect_ratio ||
>             new_conn_state->base.content_type != old_conn_state->base.content_type ||
>             new_conn_state->base.scaling_mode != old_conn_state->base.scaling_mode ||
> +           new_conn_state->base.privacy_screen_sw_state != old_conn_state->base.privacy_screen_sw_state ||
>             !drm_connector_atomic_hdr_metadata_equal(old_state, new_state))
>                 crtc_state->mode_changed = true;
>
> diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c b/drivers/gpu/drm/i915/display/intel_ddi.c
> index 0d4cf7fa8720..272714e07cc6 100644
> --- a/drivers/gpu/drm/i915/display/intel_ddi.c
> +++ b/drivers/gpu/drm/i915/display/intel_ddi.c
> @@ -25,6 +25,7 @@
>   *
>   */
>
> +#include <drm/drm_privacy_screen_consumer.h>
>  #include <drm/drm_scdc_helper.h>
>
>  #include "i915_drv.h"
> @@ -2946,6 +2947,7 @@ static void intel_enable_ddi_dp(struct intel_atomic_state *state,
>         if (port == PORT_A && DISPLAY_VER(dev_priv) < 9)
>                 intel_dp_stop_link_train(intel_dp, crtc_state);
>
> +       drm_connector_update_privacy_screen(conn_state);
>         intel_edp_backlight_on(crtc_state, conn_state);
>
>         if (!dig_port->lspcon.active || dig_port->dp.has_hdmi_sink)
> @@ -3161,6 +3163,7 @@ static void intel_ddi_update_pipe_dp(struct intel_atomic_state *state,
>         intel_drrs_update(intel_dp, crtc_state);
>
>         intel_backlight_update(state, encoder, crtc_state, conn_state);
> +       drm_connector_update_privacy_screen(conn_state);
>  }
>
>  void intel_ddi_update_pipe(struct intel_atomic_state *state,
> @@ -3979,6 +3982,19 @@ intel_ddi_init_dp_connector(struct intel_digital_port *dig_port)
>                 return NULL;
>         }
>
> +       if (dig_port->base.type == INTEL_OUTPUT_EDP) {
> +               struct drm_device *dev = dig_port->base.base.dev;
> +               struct drm_privacy_screen *privacy_screen;
> +
> +               privacy_screen = drm_privacy_screen_get(dev->dev, NULL);

Why pass NULL for con_id? Can we pass something more meaningful (e.g.
"eDP-1") so that the non-KMS platform components that provide the
privacy-screen can provide a more specific lookup? Or is that
information (connector name) not available at the time this call is
being made?

Thanks,

Rajat


> +               if (!IS_ERR(privacy_screen)) {
> +                       drm_connector_attach_privacy_screen_provider(&connector->base,
> +                                                                    privacy_screen);
> +               } else if (PTR_ERR(privacy_screen) != -ENODEV) {
> +                       drm_warn(dev, "Error getting privacy-screen\n");
> +               }
> +       }
> +
>         return connector;
>  }
>
> diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c
> index 86dbe366a907..84715a779d9d 100644
> --- a/drivers/gpu/drm/i915/display/intel_display.c
> +++ b/drivers/gpu/drm/i915/display/intel_display.c
> @@ -42,6 +42,7 @@
>  #include <drm/drm_edid.h>
>  #include <drm/drm_fourcc.h>
>  #include <drm/drm_plane_helper.h>
> +#include <drm/drm_privacy_screen_consumer.h>
>  #include <drm/drm_probe_helper.h>
>  #include <drm/drm_rect.h>
>
> @@ -12769,6 +12770,8 @@ void intel_modeset_driver_remove_nogem(struct drm_i915_private *i915)
>
>  bool intel_modeset_probe_defer(struct pci_dev *pdev)
>  {
> +       struct drm_privacy_screen *privacy_screen;
> +
>         /*
>          * apple-gmux is needed on dual GPU MacBook Pro
>          * to probe the panel if we're the inactive GPU.
> @@ -12776,6 +12779,13 @@ bool intel_modeset_probe_defer(struct pci_dev *pdev)
>         if (vga_switcheroo_client_probe_defer(pdev))
>                 return true;
>
> +       /* If the LCD panel has a privacy-screen, wait for it */
> +       privacy_screen = drm_privacy_screen_get(&pdev->dev, NULL);
> +       if (IS_ERR(privacy_screen) && PTR_ERR(privacy_screen) == -EPROBE_DEFER)
> +               return true;
> +
> +       drm_privacy_screen_put(privacy_screen);
> +
>         return false;
>  }
>
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 03/10] drm/privacy-screen: Add X86 specific arch init code
  2021-10-05 20:23 ` [PATCH 03/10] drm/privacy-screen: Add X86 specific arch init code Hans de Goede
@ 2021-11-17 14:13   ` Rajat Jain
  2021-11-17 16:33     ` Hans de Goede
  0 siblings, 1 reply; 24+ messages in thread
From: Rajat Jain @ 2021-11-17 14:13 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jani Nikula,
	Lyude, Joonas Lahtinen, Rodrigo Vivi, Ville Syrjälä,
	Mark Gross, Andy Shevchenko, Daniel Vetter, David Airlie,
	Pekka Paalanen, Mario Limonciello, Mark Pearson,
	Sebastien Bacher, Marco Trevisan, Emil Velikov, intel-gfx,
	dri-devel, platform-driver-x86

Hello Hans,

On Tue, Oct 5, 2021 at 1:23 PM Hans de Goede <hdegoede@redhat.com> wrote:
>
> Add X86 specific arch init code, which fills the privacy-screen lookup
> table by checking for various vendor specific ACPI interfaces for
> controlling the privacy-screen.
>
> This initial version only checks for the Lenovo Thinkpad specific ACPI
> methods for privacy-screen control.
>
> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
> Reviewed-by: Lyude Paul <lyude@redhat.com>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/gpu/drm/Makefile                 |  2 +-
>  drivers/gpu/drm/drm_privacy_screen_x86.c | 86 ++++++++++++++++++++++++
>  include/drm/drm_privacy_screen_machine.h |  5 ++
>  3 files changed, 92 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/gpu/drm/drm_privacy_screen_x86.c
>
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index 788fc37096f6..12997ca5670d 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -32,7 +32,7 @@ drm-$(CONFIG_OF) += drm_of.o
>  drm-$(CONFIG_PCI) += drm_pci.o
>  drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
>  drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
> -drm-$(CONFIG_DRM_PRIVACY_SCREEN) += drm_privacy_screen.o
> +drm-$(CONFIG_DRM_PRIVACY_SCREEN) += drm_privacy_screen.o drm_privacy_screen_x86.o
>
>  obj-$(CONFIG_DRM_DP_AUX_BUS) += drm_dp_aux_bus.o
>
> diff --git a/drivers/gpu/drm/drm_privacy_screen_x86.c b/drivers/gpu/drm/drm_privacy_screen_x86.c
> new file mode 100644
> index 000000000000..a2cafb294ca6
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_privacy_screen_x86.c
> @@ -0,0 +1,86 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright (C) 2020 Red Hat, Inc.
> + *
> + * Authors:
> + * Hans de Goede <hdegoede@redhat.com>
> + */
> +
> +#include <linux/acpi.h>
> +#include <drm/drm_privacy_screen_machine.h>
> +
> +#ifdef CONFIG_X86
> +static struct drm_privacy_screen_lookup arch_lookup;
> +
> +struct arch_init_data {
> +       struct drm_privacy_screen_lookup lookup;
> +       bool (*detect)(void);
> +};
> +
> +#if IS_ENABLED(CONFIG_THINKPAD_ACPI)
> +static acpi_status __init acpi_set_handle(acpi_handle handle, u32 level,
> +                                         void *context, void **return_value)
> +{
> +       *(acpi_handle *)return_value = handle;
> +       return AE_CTRL_TERMINATE;
> +}
> +
> +static bool __init detect_thinkpad_privacy_screen(void)
> +{
> +       union acpi_object obj = { .type = ACPI_TYPE_INTEGER };
> +       struct acpi_object_list args = { .count = 1, .pointer = &obj, };
> +       acpi_handle ec_handle = NULL;
> +       unsigned long long output;
> +       acpi_status status;
> +
> +       /* Get embedded-controller handle */
> +       status = acpi_get_devices("PNP0C09", acpi_set_handle, NULL, &ec_handle);
> +       if (ACPI_FAILURE(status) || !ec_handle)
> +               return false;
> +
> +       /* And call the privacy-screen get-status method */
> +       status = acpi_evaluate_integer(ec_handle, "HKEY.GSSS", &args, &output);
> +       if (ACPI_FAILURE(status))
> +               return false;
> +
> +       return (output & 0x10000) ? true : false;
> +}
> +#endif
> +
> +static const struct arch_init_data arch_init_data[] __initconst = {
> +#if IS_ENABLED(CONFIG_THINKPAD_ACPI)
> +       {
> +               .lookup = {
> +                       .dev_id = NULL,
> +                       .con_id = NULL,
> +                       .provider = "privacy_screen-thinkpad_acpi",
> +               },
> +               .detect = detect_thinkpad_privacy_screen,
> +       },
> +#endif
> +};

As I'm trying to add privacy-screen support for my platform, I'm
trying to understand if my platform needs to make an entry in this
static list.

Do I understand it right that the reason you needed this static list
(and this whole file really), instead of just doing a
drm_privacy_screen_lookup_add() in the platform code in
thinkpad_acpi.c, was because that code was executed AFTER the
drm_connectors had already initialized?

In other words, the privacy-screen providers (platform code) need to
register a privacy-screen and a lookup structure, BEFORE the drm
connectors are initialized. If the platform code that provides a
privacy-screen is executed AFTER the drm-connector initializes, then
we need an entry in this static list, so that the drm probe (for i915
atleast) is DEFERRED until the privacy-screen provider registers the
privacy-screen?

OTOH, if the platform can register a privacy-screen and a lookup
function (via drm_privacy_screen_lookup_add()) BEFORE drm probe, then
I do not need an entry in this static list.

Is this correct understanding?

Thanks & Best Regards,

Rajat

> +
> +void __init drm_privacy_screen_lookup_init(void)
> +{
> +       int i;
> +
> +       for (i = 0; i < ARRAY_SIZE(arch_init_data); i++) {
> +               if (!arch_init_data[i].detect())
> +                       continue;
> +
> +               pr_info("Found '%s' privacy-screen provider\n",
> +                       arch_init_data[i].lookup.provider);
> +
> +               /* Make a copy because arch_init_data is __initconst */
> +               arch_lookup = arch_init_data[i].lookup;
> +               drm_privacy_screen_lookup_add(&arch_lookup);
> +               break;
> +       }
> +}
> +
> +void drm_privacy_screen_lookup_exit(void)
> +{
> +       if (arch_lookup.provider)
> +               drm_privacy_screen_lookup_remove(&arch_lookup);
> +}
> +#endif /* ifdef CONFIG_X86 */
> diff --git a/include/drm/drm_privacy_screen_machine.h b/include/drm/drm_privacy_screen_machine.h
> index aaa0d38cce92..02e5371904d3 100644
> --- a/include/drm/drm_privacy_screen_machine.h
> +++ b/include/drm/drm_privacy_screen_machine.h
> @@ -31,11 +31,16 @@ struct drm_privacy_screen_lookup {
>  void drm_privacy_screen_lookup_add(struct drm_privacy_screen_lookup *lookup);
>  void drm_privacy_screen_lookup_remove(struct drm_privacy_screen_lookup *lookup);
>
> +#if IS_ENABLED(CONFIG_DRM_PRIVACY_SCREEN) && IS_ENABLED(CONFIG_X86)
> +void drm_privacy_screen_lookup_init(void);
> +void drm_privacy_screen_lookup_exit(void);
> +#else
>  static inline void drm_privacy_screen_lookup_init(void)
>  {
>  }
>  static inline void drm_privacy_screen_lookup_exit(void)
>  {
>  }
> +#endif
>
>  #endif
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 02/10] drm: Add privacy-screen class (v4)
  2021-10-05 20:23 ` [PATCH 02/10] drm: Add privacy-screen class (v4) Hans de Goede
@ 2021-11-17 14:28   ` Rajat Jain
  2021-11-17 16:39     ` Hans de Goede
  2021-12-10 10:12   ` Thorsten Leemhuis
  1 sibling, 1 reply; 24+ messages in thread
From: Rajat Jain @ 2021-11-17 14:28 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jani Nikula,
	Lyude, Joonas Lahtinen, Rodrigo Vivi, Ville Syrjälä,
	Mark Gross, Andy Shevchenko, Daniel Vetter, David Airlie,
	Pekka Paalanen, Mario Limonciello, Mark Pearson,
	Sebastien Bacher, Marco Trevisan, Emil Velikov, intel-gfx,
	dri-devel, platform-driver-x86, Heikki Krogerus

+Heikki Krogerus

Hello Hans, Heikki,

I have a question below, which isn't really a problem, but more of an
attempt to understand the current code and its limitations.

On Tue, Oct 5, 2021 at 1:23 PM Hans de Goede <hdegoede@redhat.com> wrote:
>
> On some new laptops the LCD panel has a builtin electronic privacy-screen.
> We want to export this functionality as a property on the drm connector
> object. But often this functionality is not exposed on the GPU but on some
> other (ACPI) device.
>
> This commit adds a privacy-screen class allowing the driver for these
> other devices to register themselves as a privacy-screen provider; and
> allowing the drm/kms code to get a privacy-screen provider associated
> with a specific GPU/connector combo.
>
> Changes in v2:
> - Make CONFIG_DRM_PRIVACY_SCREEN a bool which controls if the drm_privacy
>   code gets built as part of the main drm module rather then making it
>   a tristate which builds its own module.
> - Add a #if IS_ENABLED(CONFIG_DRM_PRIVACY_SCREEN) check to
>   drm_privacy_screen_consumer.h and define stubs when the check fails.
>   Together these 2 changes fix several dependency issues.
> - Remove module related code now that this is part of the main drm.ko
> - Use drm_class as class for the privacy-screen devices instead of
>   adding a separate class for this
>
> Changes in v3:
> - Make the static inline drm_privacy_screen_get_state() stub set sw_state
>   and hw_state to PRIVACY_SCREEN_DISABLED to squelch an uninitialized
>   variable warning when CONFIG_DRM_PRIVICAY_SCREEN is not set
>
> Changes in v4:
> - Make drm_privacy_screen_set_sw_state() skip calling out to the hw if
>   hw_state == new_sw_state
>
> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
> Reviewed-by: Lyude Paul <lyude@redhat.com>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  Documentation/gpu/drm-kms-helpers.rst     |  15 +
>  MAINTAINERS                               |   8 +
>  drivers/gpu/drm/Kconfig                   |   4 +
>  drivers/gpu/drm/Makefile                  |   1 +
>  drivers/gpu/drm/drm_drv.c                 |   4 +
>  drivers/gpu/drm/drm_privacy_screen.c      | 403 ++++++++++++++++++++++
>  include/drm/drm_privacy_screen_consumer.h |  50 +++
>  include/drm/drm_privacy_screen_driver.h   |  80 +++++
>  include/drm/drm_privacy_screen_machine.h  |  41 +++
>  9 files changed, 606 insertions(+)
>  create mode 100644 drivers/gpu/drm/drm_privacy_screen.c
>  create mode 100644 include/drm/drm_privacy_screen_consumer.h
>  create mode 100644 include/drm/drm_privacy_screen_driver.h
>  create mode 100644 include/drm/drm_privacy_screen_machine.h
>
> diff --git a/Documentation/gpu/drm-kms-helpers.rst b/Documentation/gpu/drm-kms-helpers.rst
> index ec2f65b31930..5bb55ec1b9b5 100644
> --- a/Documentation/gpu/drm-kms-helpers.rst
> +++ b/Documentation/gpu/drm-kms-helpers.rst
> @@ -435,3 +435,18 @@ Legacy CRTC/Modeset Helper Functions Reference
>
>  .. kernel-doc:: drivers/gpu/drm/drm_crtc_helper.c
>     :export:
> +
> +Privacy-screen class
> +====================
> +
> +.. kernel-doc:: drivers/gpu/drm/drm_privacy_screen.c
> +   :doc: overview
> +
> +.. kernel-doc:: include/drm/drm_privacy_screen_driver.h
> +   :internal:
> +
> +.. kernel-doc:: include/drm/drm_privacy_screen_machine.h
> +   :internal:
> +
> +.. kernel-doc:: drivers/gpu/drm/drm_privacy_screen.c
> +   :export:
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 28e5f0ae1009..cb94bb3b8724 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -6423,6 +6423,14 @@ F:       drivers/gpu/drm/drm_panel.c
>  F:     drivers/gpu/drm/panel/
>  F:     include/drm/drm_panel.h
>
> +DRM PRIVACY-SCREEN CLASS
> +M:     Hans de Goede <hdegoede@redhat.com>
> +L:     dri-devel@lists.freedesktop.org
> +S:     Maintained
> +T:     git git://anongit.freedesktop.org/drm/drm-misc
> +F:     drivers/gpu/drm/drm_privacy_screen*
> +F:     include/drm/drm_privacy_screen*
> +
>  DRM TTM SUBSYSTEM
>  M:     Christian Koenig <christian.koenig@amd.com>
>  M:     Huang Rui <ray.huang@amd.com>
> diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
> index 2a926d0de423..c686c08447ac 100644
> --- a/drivers/gpu/drm/Kconfig
> +++ b/drivers/gpu/drm/Kconfig
> @@ -481,3 +481,7 @@ config DRM_PANEL_ORIENTATION_QUIRKS
>  config DRM_LIB_RANDOM
>         bool
>         default n
> +
> +config DRM_PRIVACY_SCREEN
> +       bool
> +       default n
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index 0dff40bb863c..788fc37096f6 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -32,6 +32,7 @@ drm-$(CONFIG_OF) += drm_of.o
>  drm-$(CONFIG_PCI) += drm_pci.o
>  drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
>  drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
> +drm-$(CONFIG_DRM_PRIVACY_SCREEN) += drm_privacy_screen.o
>
>  obj-$(CONFIG_DRM_DP_AUX_BUS) += drm_dp_aux_bus.o
>
> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> index 7a5097467ba5..dc293b771c3f 100644
> --- a/drivers/gpu/drm/drm_drv.c
> +++ b/drivers/gpu/drm/drm_drv.c
> @@ -43,6 +43,7 @@
>  #include <drm/drm_managed.h>
>  #include <drm/drm_mode_object.h>
>  #include <drm/drm_print.h>
> +#include <drm/drm_privacy_screen_machine.h>
>
>  #include "drm_crtc_internal.h"
>  #include "drm_internal.h"
> @@ -1029,6 +1030,7 @@ static const struct file_operations drm_stub_fops = {
>
>  static void drm_core_exit(void)
>  {
> +       drm_privacy_screen_lookup_exit();
>         unregister_chrdev(DRM_MAJOR, "drm");
>         debugfs_remove(drm_debugfs_root);
>         drm_sysfs_destroy();
> @@ -1056,6 +1058,8 @@ static int __init drm_core_init(void)
>         if (ret < 0)
>                 goto error;
>
> +       drm_privacy_screen_lookup_init();
> +
>         drm_core_init_complete = true;
>
>         DRM_DEBUG("Initialized\n");
> diff --git a/drivers/gpu/drm/drm_privacy_screen.c b/drivers/gpu/drm/drm_privacy_screen.c
> new file mode 100644
> index 000000000000..183a6011adf0
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_privacy_screen.c
> @@ -0,0 +1,403 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright (C) 2020 - 2021 Red Hat, Inc.
> + *
> + * Authors:
> + * Hans de Goede <hdegoede@redhat.com>
> + */
> +
> +#include <linux/device.h>
> +#include <linux/kernel.h>
> +#include <linux/list.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/slab.h>
> +#include <drm/drm_privacy_screen_machine.h>
> +#include <drm/drm_privacy_screen_consumer.h>
> +#include <drm/drm_privacy_screen_driver.h>
> +#include "drm_internal.h"
> +
> +/**
> + * DOC: overview
> + *
> + * This class allows non KMS drivers, from e.g. drivers/platform/x86 to
> + * register a privacy-screen device, which the KMS drivers can then use
> + * to implement the standard privacy-screen properties, see
> + * :ref:`Standard Connector Properties<standard_connector_properties>`.
> + *
> + * KMS drivers using a privacy-screen class device are advised to use the
> + * drm_connector_attach_privacy_screen_provider() and
> + * drm_connector_update_privacy_screen() helpers for dealing with this.
> + */
> +
> +#define to_drm_privacy_screen(dev) \
> +       container_of(dev, struct drm_privacy_screen, dev)
> +
> +static DEFINE_MUTEX(drm_privacy_screen_lookup_lock);
> +static LIST_HEAD(drm_privacy_screen_lookup_list);
> +
> +static DEFINE_MUTEX(drm_privacy_screen_devs_lock);
> +static LIST_HEAD(drm_privacy_screen_devs);
> +
> +/*** drm_privacy_screen_machine.h functions ***/
> +
> +/**
> + * drm_privacy_screen_lookup_add - add an entry to the static privacy-screen
> + *    lookup list
> + * @lookup: lookup list entry to add
> + *
> + * Add an entry to the static privacy-screen lookup list. Note the
> + * &struct list_head which is part of the &struct drm_privacy_screen_lookup
> + * gets added to a list owned by the privacy-screen core. So the passed in
> + * &struct drm_privacy_screen_lookup must not be free-ed until it is removed
> + * from the lookup list by calling drm_privacy_screen_lookup_remove().
> + */
> +void drm_privacy_screen_lookup_add(struct drm_privacy_screen_lookup *lookup)
> +{
> +       mutex_lock(&drm_privacy_screen_lookup_lock);
> +       list_add(&lookup->list, &drm_privacy_screen_lookup_list);
> +       mutex_unlock(&drm_privacy_screen_lookup_lock);
> +}
> +EXPORT_SYMBOL(drm_privacy_screen_lookup_add);
> +
> +/**
> + * drm_privacy_screen_lookup_remove - remove an entry to the static
> + *    privacy-screen lookup list
> + * @lookup: lookup list entry to remove
> + *
> + * Remove an entry previously added with drm_privacy_screen_lookup_add()
> + * from the static privacy-screen lookup list.
> + */
> +void drm_privacy_screen_lookup_remove(struct drm_privacy_screen_lookup *lookup)
> +{
> +       mutex_lock(&drm_privacy_screen_lookup_lock);
> +       list_del(&lookup->list);
> +       mutex_unlock(&drm_privacy_screen_lookup_lock);
> +}
> +EXPORT_SYMBOL(drm_privacy_screen_lookup_remove);
> +
> +/*** drm_privacy_screen_consumer.h functions ***/
> +
> +static struct drm_privacy_screen *drm_privacy_screen_get_by_name(
> +       const char *name)
> +{
> +       struct drm_privacy_screen *priv;
> +       struct device *dev = NULL;
> +
> +       mutex_lock(&drm_privacy_screen_devs_lock);
> +
> +       list_for_each_entry(priv, &drm_privacy_screen_devs, list) {
> +               if (strcmp(dev_name(&priv->dev), name) == 0) {
> +                       dev = get_device(&priv->dev);
> +                       break;
> +               }
> +       }
> +
> +       mutex_unlock(&drm_privacy_screen_devs_lock);
> +
> +       return dev ? to_drm_privacy_screen(dev) : NULL;
> +}
> +
> +/**
> + * drm_privacy_screen_get - get a privacy-screen provider
> + * @dev: consumer-device for which to get a privacy-screen provider
> + * @con_id: (video)connector name for which to get a privacy-screen provider
> + *
> + * Get a privacy-screen provider for a privacy-screen attached to the
> + * display described by the @dev and @con_id parameters.
> + *
> + * Return:
> + * * A pointer to a &struct drm_privacy_screen on success.
> + * * ERR_PTR(-ENODEV) if no matching privacy-screen is found
> + * * ERR_PTR(-EPROBE_DEFER) if there is a matching privacy-screen,
> + *                          but it has not been registered yet.
> + */
> +struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
> +                                                 const char *con_id)
> +{
> +       const char *dev_id = dev ? dev_name(dev) : NULL;
> +       struct drm_privacy_screen_lookup *l;
> +       struct drm_privacy_screen *priv;
> +       const char *provider = NULL;
> +       int match, best = -1;
> +
> +       /*
> +        * For now we only support using a static lookup table, which is
> +        * populated by the drm_privacy_screen_arch_init() call. This should()
> +        * be extended with device-tree / fw_node lookup when support is added
> +        * for device-tree using hardware with a privacy-screen.

Do I understand it right that given the state of affairs today, the
drm_connector->fwnode gets populated AFTER the drm_connectors are
initialized and the connector properties have already been attached?
[intel_acpi_assign_connector_fwnodes() gets called later]. If so, the
fwnode, can't really be used to tweak certain properties of the
drm-connector?

Specifically, if someone wants to use device-tree / fwnodes for
drm_connector to provide a privacy-screen property, we have a
chicken-and-egg situation because:
 - privacy-screen providers need to register privacy-screen, BEFORE
drm_connector begins to probe and attach properties.
 - the drm_connector->fwnode gets assigned AFTER drm_connector has
attached the properties.

Is the above a correct understanding of the current situation?

Thanks & Best regards,

Rajat

> +        *
> +        * The lookup algorithm was shamelessly taken from the clock
> +        * framework:
> +        *
> +        * We do slightly fuzzy matching here:
> +        *  An entry with a NULL ID is assumed to be a wildcard.
> +        *  If an entry has a device ID, it must match
> +        *  If an entry has a connection ID, it must match
> +        * Then we take the most specific entry - with the following order
> +        * of precedence: dev+con > dev only > con only.
> +        */
> +       mutex_lock(&drm_privacy_screen_lookup_lock);
> +
> +       list_for_each_entry(l, &drm_privacy_screen_lookup_list, list) {
> +               match = 0;
> +
> +               if (l->dev_id) {
> +                       if (!dev_id || strcmp(l->dev_id, dev_id))
> +                               continue;
> +
> +                       match += 2;
> +               }
> +
> +               if (l->con_id) {
> +                       if (!con_id || strcmp(l->con_id, con_id))
> +                               continue;
> +
> +                       match += 1;
> +               }
> +
> +               if (match > best) {
> +                       provider = l->provider;
> +                       best = match;
> +               }
> +       }
> +
> +       mutex_unlock(&drm_privacy_screen_lookup_lock);
> +
> +       if (!provider)
> +               return ERR_PTR(-ENODEV);
> +
> +       priv = drm_privacy_screen_get_by_name(provider);
> +       if (!priv)
> +               return ERR_PTR(-EPROBE_DEFER);
> +
> +       return priv;
> +}
> +EXPORT_SYMBOL(drm_privacy_screen_get);
> +
> +/**
> + * drm_privacy_screen_put - release a privacy-screen reference
> + * @priv: privacy screen reference to release
> + *
> + * Release a privacy-screen provider reference gotten through
> + * drm_privacy_screen_get(). May be called with a NULL or ERR_PTR,
> + * in which case it is a no-op.
> + */
> +void drm_privacy_screen_put(struct drm_privacy_screen *priv)
> +{
> +       if (IS_ERR_OR_NULL(priv))
> +               return;
> +
> +       put_device(&priv->dev);
> +}
> +EXPORT_SYMBOL(drm_privacy_screen_put);
> +
> +/**
> + * drm_privacy_screen_set_sw_state - set a privacy-screen's sw-state
> + * @priv: privacy screen to set the sw-state for
> + * @sw_state: new sw-state value to set
> + *
> + * Set the sw-state of a privacy screen. If the privacy-screen is not
> + * in a locked hw-state, then the actual and hw-state of the privacy-screen
> + * will be immediately updated to the new value. If the privacy-screen is
> + * in a locked hw-state, then the new sw-state will be remembered as the
> + * requested state to put the privacy-screen in when it becomes unlocked.
> + *
> + * Return: 0 on success, negative error code on failure.
> + */
> +int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
> +                                   enum drm_privacy_screen_status sw_state)
> +{
> +       int ret = 0;
> +
> +       mutex_lock(&priv->lock);
> +
> +       if (!priv->ops) {
> +               ret = -ENODEV;
> +               goto out;
> +       }
> +
> +       /*
> +        * As per the DRM connector properties documentation, setting the
> +        * sw_state while the hw_state is locked is allowed. In this case
> +        * it is a no-op other then storing the new sw_state so that it
> +        * can be honored when the state gets unlocked.
> +        * Also skip the set if the hw already is in the desired state.
> +        */
> +       if (priv->hw_state >= PRIVACY_SCREEN_DISABLED_LOCKED ||
> +           priv->hw_state == sw_state) {
> +               priv->sw_state = sw_state;
> +               goto out;
> +       }
> +
> +       ret = priv->ops->set_sw_state(priv, sw_state);
> +out:
> +       mutex_unlock(&priv->lock);
> +       return ret;
> +}
> +EXPORT_SYMBOL(drm_privacy_screen_set_sw_state);
> +
> +/**
> + * drm_privacy_screen_get_state - get privacy-screen's current state
> + * @priv: privacy screen to get the state for
> + * @sw_state_ret: address where to store the privacy-screens current sw-state
> + * @hw_state_ret: address where to store the privacy-screens current hw-state
> + *
> + * Get the current state of a privacy-screen, both the sw-state and the
> + * hw-state.
> + */
> +void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
> +                                 enum drm_privacy_screen_status *sw_state_ret,
> +                                 enum drm_privacy_screen_status *hw_state_ret)
> +{
> +       mutex_lock(&priv->lock);
> +       *sw_state_ret = priv->sw_state;
> +       *hw_state_ret = priv->hw_state;
> +       mutex_unlock(&priv->lock);
> +}
> +EXPORT_SYMBOL(drm_privacy_screen_get_state);
> +
> +/*** drm_privacy_screen_driver.h functions ***/
> +
> +static ssize_t sw_state_show(struct device *dev,
> +                            struct device_attribute *attr, char *buf)
> +{
> +       struct drm_privacy_screen *priv = to_drm_privacy_screen(dev);
> +       const char * const sw_state_names[] = {
> +               "Disabled",
> +               "Enabled",
> +       };
> +       ssize_t ret;
> +
> +       mutex_lock(&priv->lock);
> +
> +       if (!priv->ops)
> +               ret = -ENODEV;
> +       else if (WARN_ON(priv->sw_state >= ARRAY_SIZE(sw_state_names)))
> +               ret = -ENXIO;
> +       else
> +               ret = sprintf(buf, "%s\n", sw_state_names[priv->sw_state]);
> +
> +       mutex_unlock(&priv->lock);
> +       return ret;
> +}
> +/*
> + * RO: Do not allow setting the sw_state through sysfs, this MUST be done
> + * through the drm_properties on the drm_connector.
> + */
> +static DEVICE_ATTR_RO(sw_state);
> +
> +static ssize_t hw_state_show(struct device *dev,
> +                            struct device_attribute *attr, char *buf)
> +{
> +       struct drm_privacy_screen *priv = to_drm_privacy_screen(dev);
> +       const char * const hw_state_names[] = {
> +               "Disabled",
> +               "Enabled",
> +               "Disabled, locked",
> +               "Enabled, locked",
> +       };
> +       ssize_t ret;
> +
> +       mutex_lock(&priv->lock);
> +
> +       if (!priv->ops)
> +               ret = -ENODEV;
> +       else if (WARN_ON(priv->hw_state >= ARRAY_SIZE(hw_state_names)))
> +               ret = -ENXIO;
> +       else
> +               ret = sprintf(buf, "%s\n", hw_state_names[priv->hw_state]);
> +
> +       mutex_unlock(&priv->lock);
> +       return ret;
> +}
> +static DEVICE_ATTR_RO(hw_state);
> +
> +static struct attribute *drm_privacy_screen_attrs[] = {
> +       &dev_attr_sw_state.attr,
> +       &dev_attr_hw_state.attr,
> +       NULL
> +};
> +ATTRIBUTE_GROUPS(drm_privacy_screen);
> +
> +static struct device_type drm_privacy_screen_type = {
> +       .name = "privacy_screen",
> +       .groups = drm_privacy_screen_groups,
> +};
> +
> +static void drm_privacy_screen_device_release(struct device *dev)
> +{
> +       struct drm_privacy_screen *priv = to_drm_privacy_screen(dev);
> +
> +       kfree(priv);
> +}
> +
> +/**
> + * drm_privacy_screen_register - register a privacy-screen
> + * @parent: parent-device for the privacy-screen
> + * @ops: &struct drm_privacy_screen_ops pointer with ops for the privacy-screen
> + *
> + * Create and register a privacy-screen.
> + *
> + * Return:
> + * * A pointer to the created privacy-screen on success.
> + * * 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 drm_privacy_screen *priv;
> +       int ret;
> +
> +       priv = kzalloc(sizeof(*priv), GFP_KERNEL);
> +       if (!priv)
> +               return ERR_PTR(-ENOMEM);
> +
> +       mutex_init(&priv->lock);
> +
> +       priv->dev.class = drm_class;
> +       priv->dev.type = &drm_privacy_screen_type;
> +       priv->dev.parent = parent;
> +       priv->dev.release = drm_privacy_screen_device_release;
> +       dev_set_name(&priv->dev, "privacy_screen-%s", dev_name(parent));
> +       priv->ops = ops;
> +
> +       priv->ops->get_hw_state(priv);
> +
> +       ret = device_register(&priv->dev);
> +       if (ret) {
> +               put_device(&priv->dev);
> +               return ERR_PTR(ret);
> +       }
> +
> +       mutex_lock(&drm_privacy_screen_devs_lock);
> +       list_add(&priv->list, &drm_privacy_screen_devs);
> +       mutex_unlock(&drm_privacy_screen_devs_lock);
> +
> +       return priv;
> +}
> +EXPORT_SYMBOL(drm_privacy_screen_register);
> +
> +/**
> + * drm_privacy_screen_unregister - unregister privacy-screen
> + * @priv: privacy-screen to unregister
> + *
> + * Unregister a privacy-screen registered with drm_privacy_screen_register().
> + * May be called with a NULL or ERR_PTR, in which case it is a no-op.
> + */
> +void drm_privacy_screen_unregister(struct drm_privacy_screen *priv)
> +{
> +       if (IS_ERR_OR_NULL(priv))
> +               return;
> +
> +       mutex_lock(&drm_privacy_screen_devs_lock);
> +       list_del(&priv->list);
> +       mutex_unlock(&drm_privacy_screen_devs_lock);
> +
> +       mutex_lock(&priv->lock);
> +       priv->ops = NULL;
> +       mutex_unlock(&priv->lock);
> +
> +       device_unregister(&priv->dev);
> +}
> +EXPORT_SYMBOL(drm_privacy_screen_unregister);
> diff --git a/include/drm/drm_privacy_screen_consumer.h b/include/drm/drm_privacy_screen_consumer.h
> new file mode 100644
> index 000000000000..0cbd23b0453d
> --- /dev/null
> +++ b/include/drm/drm_privacy_screen_consumer.h
> @@ -0,0 +1,50 @@
> +/* SPDX-License-Identifier: MIT */
> +/*
> + * Copyright (C) 2020 Red Hat, Inc.
> + *
> + * Authors:
> + * Hans de Goede <hdegoede@redhat.com>
> + */
> +
> +#ifndef __DRM_PRIVACY_SCREEN_CONSUMER_H__
> +#define __DRM_PRIVACY_SCREEN_CONSUMER_H__
> +
> +#include <linux/device.h>
> +#include <drm/drm_connector.h>
> +
> +struct drm_privacy_screen;
> +
> +#if IS_ENABLED(CONFIG_DRM_PRIVACY_SCREEN)
> +struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
> +                                                 const char *con_id);
> +void drm_privacy_screen_put(struct drm_privacy_screen *priv);
> +
> +int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
> +                                   enum drm_privacy_screen_status sw_state);
> +void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
> +                                 enum drm_privacy_screen_status *sw_state_ret,
> +                                 enum drm_privacy_screen_status *hw_state_ret);
> +#else
> +static inline struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
> +                                                               const char *con_id)
> +{
> +       return ERR_PTR(-ENODEV);
> +}
> +static inline void drm_privacy_screen_put(struct drm_privacy_screen *priv)
> +{
> +}
> +static inline int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
> +                                                 enum drm_privacy_screen_status sw_state)
> +{
> +       return -ENODEV;
> +}
> +static inline void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
> +                                               enum drm_privacy_screen_status *sw_state_ret,
> +                                               enum drm_privacy_screen_status *hw_state_ret)
> +{
> +       *sw_state_ret = PRIVACY_SCREEN_DISABLED;
> +       *hw_state_ret = PRIVACY_SCREEN_DISABLED;
> +}
> +#endif
> +
> +#endif
> diff --git a/include/drm/drm_privacy_screen_driver.h b/include/drm/drm_privacy_screen_driver.h
> new file mode 100644
> index 000000000000..5187ae52eb03
> --- /dev/null
> +++ b/include/drm/drm_privacy_screen_driver.h
> @@ -0,0 +1,80 @@
> +/* SPDX-License-Identifier: MIT */
> +/*
> + * Copyright (C) 2020 Red Hat, Inc.
> + *
> + * Authors:
> + * Hans de Goede <hdegoede@redhat.com>
> + */
> +
> +#ifndef __DRM_PRIVACY_SCREEN_DRIVER_H__
> +#define __DRM_PRIVACY_SCREEN_DRIVER_H__
> +
> +#include <linux/device.h>
> +#include <linux/list.h>
> +#include <linux/mutex.h>
> +#include <drm/drm_connector.h>
> +
> +struct drm_privacy_screen;
> +
> +/**
> + * struct drm_privacy_screen_ops - drm_privacy_screen operations
> + *
> + * Defines the operations which the privacy-screen class code may call.
> + * These functions should be implemented by the privacy-screen driver.
> + */
> +struct drm_privacy_screen_ops {
> +       /**
> +        * @set_sw_state: Called to request a change of the privacy-screen
> +        * state. The privacy-screen class code contains a check to avoid this
> +        * getting called when the hw_state reports the state is locked.
> +        * It is the driver's responsibility to update sw_state and hw_state.
> +        * This is always called with the drm_privacy_screen's lock held.
> +        */
> +       int (*set_sw_state)(struct drm_privacy_screen *priv,
> +                           enum drm_privacy_screen_status sw_state);
> +       /**
> +        * @get_hw_state: Called to request that the driver gets the current
> +        * privacy-screen state from the hardware and then updates sw_state and
> +        * hw_state accordingly. This will be called by the core just before
> +        * the privacy-screen is registered in sysfs.
> +        */
> +       void (*get_hw_state)(struct drm_privacy_screen *priv);
> +};
> +
> +/**
> + * struct drm_privacy_screen - central privacy-screen structure
> + *
> + * Central privacy-screen structure, this contains the struct device used
> + * to register the screen in sysfs, the screen's state, ops, etc.
> + */
> +struct drm_privacy_screen {
> +       /** @dev: device used to register the privacy-screen in sysfs. */
> +       struct device dev;
> +       /** @lock: mutex protection all fields in this struct. */
> +       struct mutex lock;
> +       /** @list: privacy-screen devices list list-entry. */
> +       struct list_head list;
> +       /**
> +        * @ops: &struct drm_privacy_screen_ops for this privacy-screen.
> +        * This is NULL if the driver has unregistered the privacy-screen.
> +        */
> +       const struct drm_privacy_screen_ops *ops;
> +       /**
> +        * @sw_state: The privacy-screen's software state, see
> +        * :ref:`Standard Connector Properties<standard_connector_properties>`
> +        * for more info.
> +        */
> +       enum drm_privacy_screen_status sw_state;
> +       /**
> +        * @hw_state: The privacy-screen's hardware state, see
> +        * :ref:`Standard Connector Properties<standard_connector_properties>`
> +        * for more info.
> +        */
> +       enum drm_privacy_screen_status hw_state;
> +};
> +
> +struct drm_privacy_screen *drm_privacy_screen_register(
> +       struct device *parent, const struct drm_privacy_screen_ops *ops);
> +void drm_privacy_screen_unregister(struct drm_privacy_screen *priv);
> +
> +#endif
> diff --git a/include/drm/drm_privacy_screen_machine.h b/include/drm/drm_privacy_screen_machine.h
> new file mode 100644
> index 000000000000..aaa0d38cce92
> --- /dev/null
> +++ b/include/drm/drm_privacy_screen_machine.h
> @@ -0,0 +1,41 @@
> +/* SPDX-License-Identifier: MIT */
> +/*
> + * Copyright (C) 2020 Red Hat, Inc.
> + *
> + * Authors:
> + * Hans de Goede <hdegoede@redhat.com>
> + */
> +
> +#ifndef __DRM_PRIVACY_SCREEN_MACHINE_H__
> +#define __DRM_PRIVACY_SCREEN_MACHINE_H__
> +
> +#include <linux/list.h>
> +
> +/**
> + * struct drm_privacy_screen_lookup -  static privacy-screen lookup list entry
> + *
> + * Used for the static lookup-list for mapping privacy-screen consumer
> + * dev-connector pairs to a privacy-screen provider.
> + */
> +struct drm_privacy_screen_lookup {
> +       /** @list: Lookup list list-entry. */
> +       struct list_head list;
> +       /** @dev_id: Consumer device name or NULL to match all devices. */
> +       const char *dev_id;
> +       /** @con_id: Consumer connector name or NULL to match all connectors. */
> +       const char *con_id;
> +       /** @provider: dev_name() of the privacy_screen provider. */
> +       const char *provider;
> +};
> +
> +void drm_privacy_screen_lookup_add(struct drm_privacy_screen_lookup *lookup);
> +void drm_privacy_screen_lookup_remove(struct drm_privacy_screen_lookup *lookup);
> +
> +static inline void drm_privacy_screen_lookup_init(void)
> +{
> +}
> +static inline void drm_privacy_screen_lookup_exit(void)
> +{
> +}
> +
> +#endif
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 10/10] drm/i915: Add privacy-screen support (v3)
  2021-11-17 13:59   ` Rajat Jain
@ 2021-11-17 16:18     ` Hans de Goede
  0 siblings, 0 replies; 24+ messages in thread
From: Hans de Goede @ 2021-11-17 16:18 UTC (permalink / raw)
  To: Rajat Jain
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jani Nikula,
	Lyude, Joonas Lahtinen, Rodrigo Vivi, Ville Syrjälä,
	Mark Gross, Andy Shevchenko, Daniel Vetter, David Airlie,
	Pekka Paalanen, Mario Limonciello, Mark Pearson,
	Sebastien Bacher, Marco Trevisan, Emil Velikov, intel-gfx,
	dri-devel, platform-driver-x86

Hi Rajat,

On 11/17/21 14:59, Rajat Jain wrote:
> Hello Hans,
> 
> I'm working on my platform's privacy-screen support based on your
> patches, and had some (I know late) questions. Would be great if you
> could please help answer. Please see inline.
> 
> On Tue, Oct 5, 2021 at 1:25 PM Hans de Goede <hdegoede@redhat.com> wrote:
>>
>> Add support for eDP panels with a built-in privacy screen using the
>> new drm_privacy_screen class.
>>
>> Changes in v3:
>> - Move drm_privacy_screen_get() call to intel_ddi_init_dp_connector()
>>
>> Changes in v2:
>> - Call drm_connector_update_privacy_screen() from
>>   intel_enable_ddi_dp() / intel_ddi_update_pipe_dp() instead of adding a
>>   for_each_new_connector_in_state() loop to intel_atomic_commit_tail()
>> - Move the probe-deferral check to the intel_modeset_probe_defer() helper
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>  drivers/gpu/drm/i915/display/intel_atomic.c  |  1 +
>>  drivers/gpu/drm/i915/display/intel_ddi.c     | 16 ++++++++++++++++
>>  drivers/gpu/drm/i915/display/intel_display.c | 10 ++++++++++
>>  3 files changed, 27 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/i915/display/intel_atomic.c b/drivers/gpu/drm/i915/display/intel_atomic.c
>> index b4e7ac51aa31..a62550711e98 100644
>> --- a/drivers/gpu/drm/i915/display/intel_atomic.c
>> +++ b/drivers/gpu/drm/i915/display/intel_atomic.c
>> @@ -139,6 +139,7 @@ int intel_digital_connector_atomic_check(struct drm_connector *conn,
>>             new_conn_state->base.picture_aspect_ratio != old_conn_state->base.picture_aspect_ratio ||
>>             new_conn_state->base.content_type != old_conn_state->base.content_type ||
>>             new_conn_state->base.scaling_mode != old_conn_state->base.scaling_mode ||
>> +           new_conn_state->base.privacy_screen_sw_state != old_conn_state->base.privacy_screen_sw_state ||
>>             !drm_connector_atomic_hdr_metadata_equal(old_state, new_state))
>>                 crtc_state->mode_changed = true;
>>
>> diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c b/drivers/gpu/drm/i915/display/intel_ddi.c
>> index 0d4cf7fa8720..272714e07cc6 100644
>> --- a/drivers/gpu/drm/i915/display/intel_ddi.c
>> +++ b/drivers/gpu/drm/i915/display/intel_ddi.c
>> @@ -25,6 +25,7 @@
>>   *
>>   */
>>
>> +#include <drm/drm_privacy_screen_consumer.h>
>>  #include <drm/drm_scdc_helper.h>
>>
>>  #include "i915_drv.h"
>> @@ -2946,6 +2947,7 @@ static void intel_enable_ddi_dp(struct intel_atomic_state *state,
>>         if (port == PORT_A && DISPLAY_VER(dev_priv) < 9)
>>                 intel_dp_stop_link_train(intel_dp, crtc_state);
>>
>> +       drm_connector_update_privacy_screen(conn_state);
>>         intel_edp_backlight_on(crtc_state, conn_state);
>>
>>         if (!dig_port->lspcon.active || dig_port->dp.has_hdmi_sink)
>> @@ -3161,6 +3163,7 @@ static void intel_ddi_update_pipe_dp(struct intel_atomic_state *state,
>>         intel_drrs_update(intel_dp, crtc_state);
>>
>>         intel_backlight_update(state, encoder, crtc_state, conn_state);
>> +       drm_connector_update_privacy_screen(conn_state);
>>  }
>>
>>  void intel_ddi_update_pipe(struct intel_atomic_state *state,
>> @@ -3979,6 +3982,19 @@ intel_ddi_init_dp_connector(struct intel_digital_port *dig_port)
>>                 return NULL;
>>         }
>>
>> +       if (dig_port->base.type == INTEL_OUTPUT_EDP) {
>> +               struct drm_device *dev = dig_port->base.base.dev;
>> +               struct drm_privacy_screen *privacy_screen;
>> +
>> +               privacy_screen = drm_privacy_screen_get(dev->dev, NULL);
> 
> Why pass NULL for con_id? Can we pass something more meaningful (e.g.
> "eDP-1") so that the non-KMS platform components that provide the
> privacy-screen can provide a more specific lookup? Or is that
> information (connector name) not available at the time this call is
> being made?

For the x86 ACPI case it does not matter because the static lookups
added by drivers/gpu/drm/drm_privacy_screen_x86.c do not set
a con_id in the lookup and if the lookup lack a con_id then
the value passed to drm_privacy_screen_get() is a no-op.

So, if it helps you to pass a connector-name then go for it.

As for the connecter_name already being set at this point,
I don't know, you need to check.

But also see below.

>> +               if (!IS_ERR(privacy_screen)) {
>> +                       drm_connector_attach_privacy_screen_provider(&connector->base,
>> +                                                                    privacy_screen);
>> +               } else if (PTR_ERR(privacy_screen) != -ENODEV) {
>> +                       drm_warn(dev, "Error getting privacy-screen\n");
>> +               }
>> +       }
>> +
>>         return connector;
>>  }
>>
>> diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c
>> index 86dbe366a907..84715a779d9d 100644
>> --- a/drivers/gpu/drm/i915/display/intel_display.c
>> +++ b/drivers/gpu/drm/i915/display/intel_display.c
>> @@ -42,6 +42,7 @@
>>  #include <drm/drm_edid.h>
>>  #include <drm/drm_fourcc.h>
>>  #include <drm/drm_plane_helper.h>
>> +#include <drm/drm_privacy_screen_consumer.h>
>>  #include <drm/drm_probe_helper.h>
>>  #include <drm/drm_rect.h>
>>
>> @@ -12769,6 +12770,8 @@ void intel_modeset_driver_remove_nogem(struct drm_i915_private *i915)
>>
>>  bool intel_modeset_probe_defer(struct pci_dev *pdev)
>>  {
>> +       struct drm_privacy_screen *privacy_screen;
>> +
>>         /*
>>          * apple-gmux is needed on dual GPU MacBook Pro
>>          * to probe the panel if we're the inactive GPU.
>> @@ -12776,6 +12779,13 @@ bool intel_modeset_probe_defer(struct pci_dev *pdev)
>>         if (vga_switcheroo_client_probe_defer(pdev))
>>                 return true;
>>
>> +       /* If the LCD panel has a privacy-screen, wait for it */
>> +       privacy_screen = drm_privacy_screen_get(&pdev->dev, NULL);
>> +       if (IS_ERR(privacy_screen) && PTR_ERR(privacy_screen) == -EPROBE_DEFER)
>> +               return true;
>> +
>> +       drm_privacy_screen_put(privacy_screen);
>> +
>>         return false;
>>  }

So this is also going to be an interesting challenge for your device-tree (ish)
case. We cannot delay returning the -EPROBE_DEFER until the code in
intel_ddi_init_dp_connector() gets called because much of the i915 code is not
ready to deal with tearing down the house again once we are at that point (AFAIK).

For now I guess you/we could just hardcode "eDP-1" here. That is likely going
to be correct in all relevant cases (for now).

Regards,

Hans


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 03/10] drm/privacy-screen: Add X86 specific arch init code
  2021-11-17 14:13   ` Rajat Jain
@ 2021-11-17 16:33     ` Hans de Goede
  0 siblings, 0 replies; 24+ messages in thread
From: Hans de Goede @ 2021-11-17 16:33 UTC (permalink / raw)
  To: Rajat Jain
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jani Nikula,
	Lyude, Joonas Lahtinen, Rodrigo Vivi, Ville Syrjälä,
	Mark Gross, Andy Shevchenko, Daniel Vetter, David Airlie,
	Pekka Paalanen, Mario Limonciello, Mark Pearson,
	Sebastien Bacher, Marco Trevisan, Emil Velikov, intel-gfx,
	dri-devel, platform-driver-x86

Hi Rajat,

On 11/17/21 15:13, Rajat Jain wrote:
> Hello Hans,
> 
> On Tue, Oct 5, 2021 at 1:23 PM Hans de Goede <hdegoede@redhat.com> wrote:
>>
>> Add X86 specific arch init code, which fills the privacy-screen lookup
>> table by checking for various vendor specific ACPI interfaces for
>> controlling the privacy-screen.
>>
>> This initial version only checks for the Lenovo Thinkpad specific ACPI
>> methods for privacy-screen control.
>>
>> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
>> Reviewed-by: Lyude Paul <lyude@redhat.com>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>  drivers/gpu/drm/Makefile                 |  2 +-
>>  drivers/gpu/drm/drm_privacy_screen_x86.c | 86 ++++++++++++++++++++++++
>>  include/drm/drm_privacy_screen_machine.h |  5 ++
>>  3 files changed, 92 insertions(+), 1 deletion(-)
>>  create mode 100644 drivers/gpu/drm/drm_privacy_screen_x86.c
>>
>> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
>> index 788fc37096f6..12997ca5670d 100644
>> --- a/drivers/gpu/drm/Makefile
>> +++ b/drivers/gpu/drm/Makefile
>> @@ -32,7 +32,7 @@ drm-$(CONFIG_OF) += drm_of.o
>>  drm-$(CONFIG_PCI) += drm_pci.o
>>  drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
>>  drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
>> -drm-$(CONFIG_DRM_PRIVACY_SCREEN) += drm_privacy_screen.o
>> +drm-$(CONFIG_DRM_PRIVACY_SCREEN) += drm_privacy_screen.o drm_privacy_screen_x86.o
>>
>>  obj-$(CONFIG_DRM_DP_AUX_BUS) += drm_dp_aux_bus.o
>>
>> diff --git a/drivers/gpu/drm/drm_privacy_screen_x86.c b/drivers/gpu/drm/drm_privacy_screen_x86.c
>> new file mode 100644
>> index 000000000000..a2cafb294ca6
>> --- /dev/null
>> +++ b/drivers/gpu/drm/drm_privacy_screen_x86.c
>> @@ -0,0 +1,86 @@
>> +// SPDX-License-Identifier: MIT
>> +/*
>> + * Copyright (C) 2020 Red Hat, Inc.
>> + *
>> + * Authors:
>> + * Hans de Goede <hdegoede@redhat.com>
>> + */
>> +
>> +#include <linux/acpi.h>
>> +#include <drm/drm_privacy_screen_machine.h>
>> +
>> +#ifdef CONFIG_X86
>> +static struct drm_privacy_screen_lookup arch_lookup;
>> +
>> +struct arch_init_data {
>> +       struct drm_privacy_screen_lookup lookup;
>> +       bool (*detect)(void);
>> +};
>> +
>> +#if IS_ENABLED(CONFIG_THINKPAD_ACPI)
>> +static acpi_status __init acpi_set_handle(acpi_handle handle, u32 level,
>> +                                         void *context, void **return_value)
>> +{
>> +       *(acpi_handle *)return_value = handle;
>> +       return AE_CTRL_TERMINATE;
>> +}
>> +
>> +static bool __init detect_thinkpad_privacy_screen(void)
>> +{
>> +       union acpi_object obj = { .type = ACPI_TYPE_INTEGER };
>> +       struct acpi_object_list args = { .count = 1, .pointer = &obj, };
>> +       acpi_handle ec_handle = NULL;
>> +       unsigned long long output;
>> +       acpi_status status;
>> +
>> +       /* Get embedded-controller handle */
>> +       status = acpi_get_devices("PNP0C09", acpi_set_handle, NULL, &ec_handle);
>> +       if (ACPI_FAILURE(status) || !ec_handle)
>> +               return false;
>> +
>> +       /* And call the privacy-screen get-status method */
>> +       status = acpi_evaluate_integer(ec_handle, "HKEY.GSSS", &args, &output);
>> +       if (ACPI_FAILURE(status))
>> +               return false;
>> +
>> +       return (output & 0x10000) ? true : false;
>> +}
>> +#endif
>> +
>> +static const struct arch_init_data arch_init_data[] __initconst = {
>> +#if IS_ENABLED(CONFIG_THINKPAD_ACPI)
>> +       {
>> +               .lookup = {
>> +                       .dev_id = NULL,
>> +                       .con_id = NULL,
>> +                       .provider = "privacy_screen-thinkpad_acpi",
>> +               },
>> +               .detect = detect_thinkpad_privacy_screen,
>> +       },
>> +#endif
>> +};
> 
> As I'm trying to add privacy-screen support for my platform, I'm
> trying to understand if my platform needs to make an entry in this
> static list.
> 
> Do I understand it right that the reason you needed this static list
> (and this whole file really), instead of just doing a
> drm_privacy_screen_lookup_add() in the platform code in
> thinkpad_acpi.c, was because that code was executed AFTER the
> drm_connectors had already initialized> 
> In other words, the privacy-screen providers (platform code) need to
> register a privacy-screen and a lookup structure, BEFORE the drm
> connectors are initialized. If the platform code that provides a
> privacy-screen is executed AFTER the drm-connector initializes, then
> we need an entry in this static list, so that the drm probe (for i915
> atleast) is DEFERRED until the privacy-screen provider registers the
> privacy-screen?
> 
> OTOH, if the platform can register a privacy-screen and a lookup
> function (via drm_privacy_screen_lookup_add()) BEFORE drm probe, then
> I do not need an entry in this static list.
> 
> Is this correct understanding?

Yes, this is all here to deal with probe-ordering.

On a platform where the link between connectors and device-tree
is available in something like devicetree this all becomes
much easier.

The i915 code does a:

       privacy_screen = drm_privacy_screen_get(&pdev->dev, NULL);
       if (IS_ERR(privacy_screen) && PTR_ERR(privacy_screen) == -EPROBE_DEFER)
               return true;

Early on to determine if there is a privacy_screen device it needs
to wait for.

With devicetree you can just scan for connector fwnodes under
pdev->dev.fwnode and if any of those declare a link to a privacy_screen
check if the provider if that screen is ready and if not return -EPROBE_DEFER.

Rather then hardcoding "eDP-1" as con_id as I suggested before I guess
it would be good to have a generic:

int drm_privacy_screen_providers_ready(struct device *dev);

helper which always returns either 0 or -EPROBE_DEFER.

For devicetree this could check all connector fwnodes and for
non-devicetree fallsback to the current:

       privacy_screen = drm_privacy_screen_get(&pdev->dev, NULL);
       if (IS_ERR(privacy_screen) && PTR_ERR(privacy_screen) == -EPROBE_DEFER)
               return -EPROBE_DEFER;

code.

Then there is no need to hardcode "eDP-1" here.

This way you won't even have to ensure that the privacy_screen gets
registered first, instead you are correctly having the i915 probe defer
until the privacy_screen(s) get registered.

Either way you definitely should NOT need to add entries to this static
table on a devicetree based platform.

I hope this helps, if anything is not clear please keep asking questions.

Regards,

Hans


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 02/10] drm: Add privacy-screen class (v4)
  2021-11-17 14:28   ` Rajat Jain
@ 2021-11-17 16:39     ` Hans de Goede
  0 siblings, 0 replies; 24+ messages in thread
From: Hans de Goede @ 2021-11-17 16:39 UTC (permalink / raw)
  To: Rajat Jain
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Jani Nikula,
	Lyude, Joonas Lahtinen, Rodrigo Vivi, Ville Syrjälä,
	Mark Gross, Andy Shevchenko, Daniel Vetter, David Airlie,
	Pekka Paalanen, Mario Limonciello, Mark Pearson,
	Sebastien Bacher, Marco Trevisan, Emil Velikov, intel-gfx,
	dri-devel, platform-driver-x86, Heikki Krogerus

Hi Rajat,

On 11/17/21 15:28, Rajat Jain wrote:
> +Heikki Krogerus
> 
> Hello Hans, Heikki,
> 
> I have a question below, which isn't really a problem, but more of an
> attempt to understand the current code and its limitations.
> 
> On Tue, Oct 5, 2021 at 1:23 PM Hans de Goede <hdegoede@redhat.com> wrote:
>>
>> On some new laptops the LCD panel has a builtin electronic privacy-screen.
>> We want to export this functionality as a property on the drm connector
>> object. But often this functionality is not exposed on the GPU but on some
>> other (ACPI) device.
>>
>> This commit adds a privacy-screen class allowing the driver for these
>> other devices to register themselves as a privacy-screen provider; and
>> allowing the drm/kms code to get a privacy-screen provider associated
>> with a specific GPU/connector combo.
>>
>> Changes in v2:
>> - Make CONFIG_DRM_PRIVACY_SCREEN a bool which controls if the drm_privacy
>>   code gets built as part of the main drm module rather then making it
>>   a tristate which builds its own module.
>> - Add a #if IS_ENABLED(CONFIG_DRM_PRIVACY_SCREEN) check to
>>   drm_privacy_screen_consumer.h and define stubs when the check fails.
>>   Together these 2 changes fix several dependency issues.
>> - Remove module related code now that this is part of the main drm.ko
>> - Use drm_class as class for the privacy-screen devices instead of
>>   adding a separate class for this
>>
>> Changes in v3:
>> - Make the static inline drm_privacy_screen_get_state() stub set sw_state
>>   and hw_state to PRIVACY_SCREEN_DISABLED to squelch an uninitialized
>>   variable warning when CONFIG_DRM_PRIVICAY_SCREEN is not set
>>
>> Changes in v4:
>> - Make drm_privacy_screen_set_sw_state() skip calling out to the hw if
>>   hw_state == new_sw_state
>>
>> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
>> Reviewed-by: Lyude Paul <lyude@redhat.com>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>  Documentation/gpu/drm-kms-helpers.rst     |  15 +
>>  MAINTAINERS                               |   8 +
>>  drivers/gpu/drm/Kconfig                   |   4 +
>>  drivers/gpu/drm/Makefile                  |   1 +
>>  drivers/gpu/drm/drm_drv.c                 |   4 +
>>  drivers/gpu/drm/drm_privacy_screen.c      | 403 ++++++++++++++++++++++
>>  include/drm/drm_privacy_screen_consumer.h |  50 +++
>>  include/drm/drm_privacy_screen_driver.h   |  80 +++++
>>  include/drm/drm_privacy_screen_machine.h  |  41 +++
>>  9 files changed, 606 insertions(+)
>>  create mode 100644 drivers/gpu/drm/drm_privacy_screen.c
>>  create mode 100644 include/drm/drm_privacy_screen_consumer.h
>>  create mode 100644 include/drm/drm_privacy_screen_driver.h
>>  create mode 100644 include/drm/drm_privacy_screen_machine.h
>>
>> diff --git a/Documentation/gpu/drm-kms-helpers.rst b/Documentation/gpu/drm-kms-helpers.rst
>> index ec2f65b31930..5bb55ec1b9b5 100644
>> --- a/Documentation/gpu/drm-kms-helpers.rst
>> +++ b/Documentation/gpu/drm-kms-helpers.rst
>> @@ -435,3 +435,18 @@ Legacy CRTC/Modeset Helper Functions Reference
>>
>>  .. kernel-doc:: drivers/gpu/drm/drm_crtc_helper.c
>>     :export:
>> +
>> +Privacy-screen class
>> +====================
>> +
>> +.. kernel-doc:: drivers/gpu/drm/drm_privacy_screen.c
>> +   :doc: overview
>> +
>> +.. kernel-doc:: include/drm/drm_privacy_screen_driver.h
>> +   :internal:
>> +
>> +.. kernel-doc:: include/drm/drm_privacy_screen_machine.h
>> +   :internal:
>> +
>> +.. kernel-doc:: drivers/gpu/drm/drm_privacy_screen.c
>> +   :export:
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 28e5f0ae1009..cb94bb3b8724 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -6423,6 +6423,14 @@ F:       drivers/gpu/drm/drm_panel.c
>>  F:     drivers/gpu/drm/panel/
>>  F:     include/drm/drm_panel.h
>>
>> +DRM PRIVACY-SCREEN CLASS
>> +M:     Hans de Goede <hdegoede@redhat.com>
>> +L:     dri-devel@lists.freedesktop.org
>> +S:     Maintained
>> +T:     git git://anongit.freedesktop.org/drm/drm-misc
>> +F:     drivers/gpu/drm/drm_privacy_screen*
>> +F:     include/drm/drm_privacy_screen*
>> +
>>  DRM TTM SUBSYSTEM
>>  M:     Christian Koenig <christian.koenig@amd.com>
>>  M:     Huang Rui <ray.huang@amd.com>
>> diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
>> index 2a926d0de423..c686c08447ac 100644
>> --- a/drivers/gpu/drm/Kconfig
>> +++ b/drivers/gpu/drm/Kconfig
>> @@ -481,3 +481,7 @@ config DRM_PANEL_ORIENTATION_QUIRKS
>>  config DRM_LIB_RANDOM
>>         bool
>>         default n
>> +
>> +config DRM_PRIVACY_SCREEN
>> +       bool
>> +       default n
>> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
>> index 0dff40bb863c..788fc37096f6 100644
>> --- a/drivers/gpu/drm/Makefile
>> +++ b/drivers/gpu/drm/Makefile
>> @@ -32,6 +32,7 @@ drm-$(CONFIG_OF) += drm_of.o
>>  drm-$(CONFIG_PCI) += drm_pci.o
>>  drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
>>  drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
>> +drm-$(CONFIG_DRM_PRIVACY_SCREEN) += drm_privacy_screen.o
>>
>>  obj-$(CONFIG_DRM_DP_AUX_BUS) += drm_dp_aux_bus.o
>>
>> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
>> index 7a5097467ba5..dc293b771c3f 100644
>> --- a/drivers/gpu/drm/drm_drv.c
>> +++ b/drivers/gpu/drm/drm_drv.c
>> @@ -43,6 +43,7 @@
>>  #include <drm/drm_managed.h>
>>  #include <drm/drm_mode_object.h>
>>  #include <drm/drm_print.h>
>> +#include <drm/drm_privacy_screen_machine.h>
>>
>>  #include "drm_crtc_internal.h"
>>  #include "drm_internal.h"
>> @@ -1029,6 +1030,7 @@ static const struct file_operations drm_stub_fops = {
>>
>>  static void drm_core_exit(void)
>>  {
>> +       drm_privacy_screen_lookup_exit();
>>         unregister_chrdev(DRM_MAJOR, "drm");
>>         debugfs_remove(drm_debugfs_root);
>>         drm_sysfs_destroy();
>> @@ -1056,6 +1058,8 @@ static int __init drm_core_init(void)
>>         if (ret < 0)
>>                 goto error;
>>
>> +       drm_privacy_screen_lookup_init();
>> +
>>         drm_core_init_complete = true;
>>
>>         DRM_DEBUG("Initialized\n");
>> diff --git a/drivers/gpu/drm/drm_privacy_screen.c b/drivers/gpu/drm/drm_privacy_screen.c
>> new file mode 100644
>> index 000000000000..183a6011adf0
>> --- /dev/null
>> +++ b/drivers/gpu/drm/drm_privacy_screen.c
>> @@ -0,0 +1,403 @@
>> +// SPDX-License-Identifier: MIT
>> +/*
>> + * Copyright (C) 2020 - 2021 Red Hat, Inc.
>> + *
>> + * Authors:
>> + * Hans de Goede <hdegoede@redhat.com>
>> + */
>> +
>> +#include <linux/device.h>
>> +#include <linux/kernel.h>
>> +#include <linux/list.h>
>> +#include <linux/module.h>
>> +#include <linux/mutex.h>
>> +#include <linux/slab.h>
>> +#include <drm/drm_privacy_screen_machine.h>
>> +#include <drm/drm_privacy_screen_consumer.h>
>> +#include <drm/drm_privacy_screen_driver.h>
>> +#include "drm_internal.h"
>> +
>> +/**
>> + * DOC: overview
>> + *
>> + * This class allows non KMS drivers, from e.g. drivers/platform/x86 to
>> + * register a privacy-screen device, which the KMS drivers can then use
>> + * to implement the standard privacy-screen properties, see
>> + * :ref:`Standard Connector Properties<standard_connector_properties>`.
>> + *
>> + * KMS drivers using a privacy-screen class device are advised to use the
>> + * drm_connector_attach_privacy_screen_provider() and
>> + * drm_connector_update_privacy_screen() helpers for dealing with this.
>> + */
>> +
>> +#define to_drm_privacy_screen(dev) \
>> +       container_of(dev, struct drm_privacy_screen, dev)
>> +
>> +static DEFINE_MUTEX(drm_privacy_screen_lookup_lock);
>> +static LIST_HEAD(drm_privacy_screen_lookup_list);
>> +
>> +static DEFINE_MUTEX(drm_privacy_screen_devs_lock);
>> +static LIST_HEAD(drm_privacy_screen_devs);
>> +
>> +/*** drm_privacy_screen_machine.h functions ***/
>> +
>> +/**
>> + * drm_privacy_screen_lookup_add - add an entry to the static privacy-screen
>> + *    lookup list
>> + * @lookup: lookup list entry to add
>> + *
>> + * Add an entry to the static privacy-screen lookup list. Note the
>> + * &struct list_head which is part of the &struct drm_privacy_screen_lookup
>> + * gets added to a list owned by the privacy-screen core. So the passed in
>> + * &struct drm_privacy_screen_lookup must not be free-ed until it is removed
>> + * from the lookup list by calling drm_privacy_screen_lookup_remove().
>> + */
>> +void drm_privacy_screen_lookup_add(struct drm_privacy_screen_lookup *lookup)
>> +{
>> +       mutex_lock(&drm_privacy_screen_lookup_lock);
>> +       list_add(&lookup->list, &drm_privacy_screen_lookup_list);
>> +       mutex_unlock(&drm_privacy_screen_lookup_lock);
>> +}
>> +EXPORT_SYMBOL(drm_privacy_screen_lookup_add);
>> +
>> +/**
>> + * drm_privacy_screen_lookup_remove - remove an entry to the static
>> + *    privacy-screen lookup list
>> + * @lookup: lookup list entry to remove
>> + *
>> + * Remove an entry previously added with drm_privacy_screen_lookup_add()
>> + * from the static privacy-screen lookup list.
>> + */
>> +void drm_privacy_screen_lookup_remove(struct drm_privacy_screen_lookup *lookup)
>> +{
>> +       mutex_lock(&drm_privacy_screen_lookup_lock);
>> +       list_del(&lookup->list);
>> +       mutex_unlock(&drm_privacy_screen_lookup_lock);
>> +}
>> +EXPORT_SYMBOL(drm_privacy_screen_lookup_remove);
>> +
>> +/*** drm_privacy_screen_consumer.h functions ***/
>> +
>> +static struct drm_privacy_screen *drm_privacy_screen_get_by_name(
>> +       const char *name)
>> +{
>> +       struct drm_privacy_screen *priv;
>> +       struct device *dev = NULL;
>> +
>> +       mutex_lock(&drm_privacy_screen_devs_lock);
>> +
>> +       list_for_each_entry(priv, &drm_privacy_screen_devs, list) {
>> +               if (strcmp(dev_name(&priv->dev), name) == 0) {
>> +                       dev = get_device(&priv->dev);
>> +                       break;
>> +               }
>> +       }
>> +
>> +       mutex_unlock(&drm_privacy_screen_devs_lock);
>> +
>> +       return dev ? to_drm_privacy_screen(dev) : NULL;
>> +}
>> +
>> +/**
>> + * drm_privacy_screen_get - get a privacy-screen provider
>> + * @dev: consumer-device for which to get a privacy-screen provider
>> + * @con_id: (video)connector name for which to get a privacy-screen provider
>> + *
>> + * Get a privacy-screen provider for a privacy-screen attached to the
>> + * display described by the @dev and @con_id parameters.
>> + *
>> + * Return:
>> + * * A pointer to a &struct drm_privacy_screen on success.
>> + * * ERR_PTR(-ENODEV) if no matching privacy-screen is found
>> + * * ERR_PTR(-EPROBE_DEFER) if there is a matching privacy-screen,
>> + *                          but it has not been registered yet.
>> + */
>> +struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
>> +                                                 const char *con_id)
>> +{
>> +       const char *dev_id = dev ? dev_name(dev) : NULL;
>> +       struct drm_privacy_screen_lookup *l;
>> +       struct drm_privacy_screen *priv;
>> +       const char *provider = NULL;
>> +       int match, best = -1;
>> +
>> +       /*
>> +        * For now we only support using a static lookup table, which is
>> +        * populated by the drm_privacy_screen_arch_init() call. This should()
>> +        * be extended with device-tree / fw_node lookup when support is added
>> +        * for device-tree using hardware with a privacy-screen.
> 
> Do I understand it right that given the state of affairs today, the
> drm_connector->fwnode gets populated AFTER the drm_connectors are
> initialized and the connector properties have already been attached?
> [intel_acpi_assign_connector_fwnodes() gets called later]. If so, the
> fwnode, can't really be used to tweak certain properties of the
> drm-connector?
> 
> Specifically, if someone wants to use device-tree / fwnodes for
> drm_connector to provide a privacy-screen property, we have a
> chicken-and-egg situation because:
>  - privacy-screen providers need to register privacy-screen, BEFORE
> drm_connector begins to probe and attach properties.
>  - the drm_connector->fwnode gets assigned AFTER drm_connector has
> attached the properties.
> 
> Is the above a correct understanding of the current situation?

the drm_connector->fwnode pointer is atm only used for 
drm_connector_find_by_fwnode() which in turn is only used together
with drm_connector_oob_hotplug_event() for some Type-c setups.

For privacy-screens stuff the idea would be that at some points
the i915 code calls:

	privacy_screen = drm_privacy_screen_get(dev->dev, con_id);

And then drm_privacy_screen_get() would check for "connector"
child fwnode-s under dev->dev.fwnode and search for the one which
has a name / con_id property matching the passed in con_id and
then it has found the fwnode for the connector without needing
to use the drm_connector->fwnode link.

So I believe that for a devicetree privacy_screen implementation
the whole drm_connector->fwnode link is not needed.

Regards,

Hans


p.s.

It would probably still be nice to also set drm_connector->fwnode
on devicetree based platforms so that drm_connector_find_by_fwnode()
works and can be used on those platforms if we need it there.



>> +        *
>> +        * The lookup algorithm was shamelessly taken from the clock
>> +        * framework:
>> +        *
>> +        * We do slightly fuzzy matching here:
>> +        *  An entry with a NULL ID is assumed to be a wildcard.
>> +        *  If an entry has a device ID, it must match
>> +        *  If an entry has a connection ID, it must match
>> +        * Then we take the most specific entry - with the following order
>> +        * of precedence: dev+con > dev only > con only.
>> +        */
>> +       mutex_lock(&drm_privacy_screen_lookup_lock);
>> +
>> +       list_for_each_entry(l, &drm_privacy_screen_lookup_list, list) {
>> +               match = 0;
>> +
>> +               if (l->dev_id) {
>> +                       if (!dev_id || strcmp(l->dev_id, dev_id))
>> +                               continue;
>> +
>> +                       match += 2;
>> +               }
>> +
>> +               if (l->con_id) {
>> +                       if (!con_id || strcmp(l->con_id, con_id))
>> +                               continue;
>> +
>> +                       match += 1;
>> +               }
>> +
>> +               if (match > best) {
>> +                       provider = l->provider;
>> +                       best = match;
>> +               }
>> +       }
>> +
>> +       mutex_unlock(&drm_privacy_screen_lookup_lock);
>> +
>> +       if (!provider)
>> +               return ERR_PTR(-ENODEV);
>> +
>> +       priv = drm_privacy_screen_get_by_name(provider);
>> +       if (!priv)
>> +               return ERR_PTR(-EPROBE_DEFER);
>> +
>> +       return priv;
>> +}
>> +EXPORT_SYMBOL(drm_privacy_screen_get);
>> +
>> +/**
>> + * drm_privacy_screen_put - release a privacy-screen reference
>> + * @priv: privacy screen reference to release
>> + *
>> + * Release a privacy-screen provider reference gotten through
>> + * drm_privacy_screen_get(). May be called with a NULL or ERR_PTR,
>> + * in which case it is a no-op.
>> + */
>> +void drm_privacy_screen_put(struct drm_privacy_screen *priv)
>> +{
>> +       if (IS_ERR_OR_NULL(priv))
>> +               return;
>> +
>> +       put_device(&priv->dev);
>> +}
>> +EXPORT_SYMBOL(drm_privacy_screen_put);
>> +
>> +/**
>> + * drm_privacy_screen_set_sw_state - set a privacy-screen's sw-state
>> + * @priv: privacy screen to set the sw-state for
>> + * @sw_state: new sw-state value to set
>> + *
>> + * Set the sw-state of a privacy screen. If the privacy-screen is not
>> + * in a locked hw-state, then the actual and hw-state of the privacy-screen
>> + * will be immediately updated to the new value. If the privacy-screen is
>> + * in a locked hw-state, then the new sw-state will be remembered as the
>> + * requested state to put the privacy-screen in when it becomes unlocked.
>> + *
>> + * Return: 0 on success, negative error code on failure.
>> + */
>> +int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
>> +                                   enum drm_privacy_screen_status sw_state)
>> +{
>> +       int ret = 0;
>> +
>> +       mutex_lock(&priv->lock);
>> +
>> +       if (!priv->ops) {
>> +               ret = -ENODEV;
>> +               goto out;
>> +       }
>> +
>> +       /*
>> +        * As per the DRM connector properties documentation, setting the
>> +        * sw_state while the hw_state is locked is allowed. In this case
>> +        * it is a no-op other then storing the new sw_state so that it
>> +        * can be honored when the state gets unlocked.
>> +        * Also skip the set if the hw already is in the desired state.
>> +        */
>> +       if (priv->hw_state >= PRIVACY_SCREEN_DISABLED_LOCKED ||
>> +           priv->hw_state == sw_state) {
>> +               priv->sw_state = sw_state;
>> +               goto out;
>> +       }
>> +
>> +       ret = priv->ops->set_sw_state(priv, sw_state);
>> +out:
>> +       mutex_unlock(&priv->lock);
>> +       return ret;
>> +}
>> +EXPORT_SYMBOL(drm_privacy_screen_set_sw_state);
>> +
>> +/**
>> + * drm_privacy_screen_get_state - get privacy-screen's current state
>> + * @priv: privacy screen to get the state for
>> + * @sw_state_ret: address where to store the privacy-screens current sw-state
>> + * @hw_state_ret: address where to store the privacy-screens current hw-state
>> + *
>> + * Get the current state of a privacy-screen, both the sw-state and the
>> + * hw-state.
>> + */
>> +void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
>> +                                 enum drm_privacy_screen_status *sw_state_ret,
>> +                                 enum drm_privacy_screen_status *hw_state_ret)
>> +{
>> +       mutex_lock(&priv->lock);
>> +       *sw_state_ret = priv->sw_state;
>> +       *hw_state_ret = priv->hw_state;
>> +       mutex_unlock(&priv->lock);
>> +}
>> +EXPORT_SYMBOL(drm_privacy_screen_get_state);
>> +
>> +/*** drm_privacy_screen_driver.h functions ***/
>> +
>> +static ssize_t sw_state_show(struct device *dev,
>> +                            struct device_attribute *attr, char *buf)
>> +{
>> +       struct drm_privacy_screen *priv = to_drm_privacy_screen(dev);
>> +       const char * const sw_state_names[] = {
>> +               "Disabled",
>> +               "Enabled",
>> +       };
>> +       ssize_t ret;
>> +
>> +       mutex_lock(&priv->lock);
>> +
>> +       if (!priv->ops)
>> +               ret = -ENODEV;
>> +       else if (WARN_ON(priv->sw_state >= ARRAY_SIZE(sw_state_names)))
>> +               ret = -ENXIO;
>> +       else
>> +               ret = sprintf(buf, "%s\n", sw_state_names[priv->sw_state]);
>> +
>> +       mutex_unlock(&priv->lock);
>> +       return ret;
>> +}
>> +/*
>> + * RO: Do not allow setting the sw_state through sysfs, this MUST be done
>> + * through the drm_properties on the drm_connector.
>> + */
>> +static DEVICE_ATTR_RO(sw_state);
>> +
>> +static ssize_t hw_state_show(struct device *dev,
>> +                            struct device_attribute *attr, char *buf)
>> +{
>> +       struct drm_privacy_screen *priv = to_drm_privacy_screen(dev);
>> +       const char * const hw_state_names[] = {
>> +               "Disabled",
>> +               "Enabled",
>> +               "Disabled, locked",
>> +               "Enabled, locked",
>> +       };
>> +       ssize_t ret;
>> +
>> +       mutex_lock(&priv->lock);
>> +
>> +       if (!priv->ops)
>> +               ret = -ENODEV;
>> +       else if (WARN_ON(priv->hw_state >= ARRAY_SIZE(hw_state_names)))
>> +               ret = -ENXIO;
>> +       else
>> +               ret = sprintf(buf, "%s\n", hw_state_names[priv->hw_state]);
>> +
>> +       mutex_unlock(&priv->lock);
>> +       return ret;
>> +}
>> +static DEVICE_ATTR_RO(hw_state);
>> +
>> +static struct attribute *drm_privacy_screen_attrs[] = {
>> +       &dev_attr_sw_state.attr,
>> +       &dev_attr_hw_state.attr,
>> +       NULL
>> +};
>> +ATTRIBUTE_GROUPS(drm_privacy_screen);
>> +
>> +static struct device_type drm_privacy_screen_type = {
>> +       .name = "privacy_screen",
>> +       .groups = drm_privacy_screen_groups,
>> +};
>> +
>> +static void drm_privacy_screen_device_release(struct device *dev)
>> +{
>> +       struct drm_privacy_screen *priv = to_drm_privacy_screen(dev);
>> +
>> +       kfree(priv);
>> +}
>> +
>> +/**
>> + * drm_privacy_screen_register - register a privacy-screen
>> + * @parent: parent-device for the privacy-screen
>> + * @ops: &struct drm_privacy_screen_ops pointer with ops for the privacy-screen
>> + *
>> + * Create and register a privacy-screen.
>> + *
>> + * Return:
>> + * * A pointer to the created privacy-screen on success.
>> + * * 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 drm_privacy_screen *priv;
>> +       int ret;
>> +
>> +       priv = kzalloc(sizeof(*priv), GFP_KERNEL);
>> +       if (!priv)
>> +               return ERR_PTR(-ENOMEM);
>> +
>> +       mutex_init(&priv->lock);
>> +
>> +       priv->dev.class = drm_class;
>> +       priv->dev.type = &drm_privacy_screen_type;
>> +       priv->dev.parent = parent;
>> +       priv->dev.release = drm_privacy_screen_device_release;
>> +       dev_set_name(&priv->dev, "privacy_screen-%s", dev_name(parent));
>> +       priv->ops = ops;
>> +
>> +       priv->ops->get_hw_state(priv);
>> +
>> +       ret = device_register(&priv->dev);
>> +       if (ret) {
>> +               put_device(&priv->dev);
>> +               return ERR_PTR(ret);
>> +       }
>> +
>> +       mutex_lock(&drm_privacy_screen_devs_lock);
>> +       list_add(&priv->list, &drm_privacy_screen_devs);
>> +       mutex_unlock(&drm_privacy_screen_devs_lock);
>> +
>> +       return priv;
>> +}
>> +EXPORT_SYMBOL(drm_privacy_screen_register);
>> +
>> +/**
>> + * drm_privacy_screen_unregister - unregister privacy-screen
>> + * @priv: privacy-screen to unregister
>> + *
>> + * Unregister a privacy-screen registered with drm_privacy_screen_register().
>> + * May be called with a NULL or ERR_PTR, in which case it is a no-op.
>> + */
>> +void drm_privacy_screen_unregister(struct drm_privacy_screen *priv)
>> +{
>> +       if (IS_ERR_OR_NULL(priv))
>> +               return;
>> +
>> +       mutex_lock(&drm_privacy_screen_devs_lock);
>> +       list_del(&priv->list);
>> +       mutex_unlock(&drm_privacy_screen_devs_lock);
>> +
>> +       mutex_lock(&priv->lock);
>> +       priv->ops = NULL;
>> +       mutex_unlock(&priv->lock);
>> +
>> +       device_unregister(&priv->dev);
>> +}
>> +EXPORT_SYMBOL(drm_privacy_screen_unregister);
>> diff --git a/include/drm/drm_privacy_screen_consumer.h b/include/drm/drm_privacy_screen_consumer.h
>> new file mode 100644
>> index 000000000000..0cbd23b0453d
>> --- /dev/null
>> +++ b/include/drm/drm_privacy_screen_consumer.h
>> @@ -0,0 +1,50 @@
>> +/* SPDX-License-Identifier: MIT */
>> +/*
>> + * Copyright (C) 2020 Red Hat, Inc.
>> + *
>> + * Authors:
>> + * Hans de Goede <hdegoede@redhat.com>
>> + */
>> +
>> +#ifndef __DRM_PRIVACY_SCREEN_CONSUMER_H__
>> +#define __DRM_PRIVACY_SCREEN_CONSUMER_H__
>> +
>> +#include <linux/device.h>
>> +#include <drm/drm_connector.h>
>> +
>> +struct drm_privacy_screen;
>> +
>> +#if IS_ENABLED(CONFIG_DRM_PRIVACY_SCREEN)
>> +struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
>> +                                                 const char *con_id);
>> +void drm_privacy_screen_put(struct drm_privacy_screen *priv);
>> +
>> +int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
>> +                                   enum drm_privacy_screen_status sw_state);
>> +void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
>> +                                 enum drm_privacy_screen_status *sw_state_ret,
>> +                                 enum drm_privacy_screen_status *hw_state_ret);
>> +#else
>> +static inline struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
>> +                                                               const char *con_id)
>> +{
>> +       return ERR_PTR(-ENODEV);
>> +}
>> +static inline void drm_privacy_screen_put(struct drm_privacy_screen *priv)
>> +{
>> +}
>> +static inline int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
>> +                                                 enum drm_privacy_screen_status sw_state)
>> +{
>> +       return -ENODEV;
>> +}
>> +static inline void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
>> +                                               enum drm_privacy_screen_status *sw_state_ret,
>> +                                               enum drm_privacy_screen_status *hw_state_ret)
>> +{
>> +       *sw_state_ret = PRIVACY_SCREEN_DISABLED;
>> +       *hw_state_ret = PRIVACY_SCREEN_DISABLED;
>> +}
>> +#endif
>> +
>> +#endif
>> diff --git a/include/drm/drm_privacy_screen_driver.h b/include/drm/drm_privacy_screen_driver.h
>> new file mode 100644
>> index 000000000000..5187ae52eb03
>> --- /dev/null
>> +++ b/include/drm/drm_privacy_screen_driver.h
>> @@ -0,0 +1,80 @@
>> +/* SPDX-License-Identifier: MIT */
>> +/*
>> + * Copyright (C) 2020 Red Hat, Inc.
>> + *
>> + * Authors:
>> + * Hans de Goede <hdegoede@redhat.com>
>> + */
>> +
>> +#ifndef __DRM_PRIVACY_SCREEN_DRIVER_H__
>> +#define __DRM_PRIVACY_SCREEN_DRIVER_H__
>> +
>> +#include <linux/device.h>
>> +#include <linux/list.h>
>> +#include <linux/mutex.h>
>> +#include <drm/drm_connector.h>
>> +
>> +struct drm_privacy_screen;
>> +
>> +/**
>> + * struct drm_privacy_screen_ops - drm_privacy_screen operations
>> + *
>> + * Defines the operations which the privacy-screen class code may call.
>> + * These functions should be implemented by the privacy-screen driver.
>> + */
>> +struct drm_privacy_screen_ops {
>> +       /**
>> +        * @set_sw_state: Called to request a change of the privacy-screen
>> +        * state. The privacy-screen class code contains a check to avoid this
>> +        * getting called when the hw_state reports the state is locked.
>> +        * It is the driver's responsibility to update sw_state and hw_state.
>> +        * This is always called with the drm_privacy_screen's lock held.
>> +        */
>> +       int (*set_sw_state)(struct drm_privacy_screen *priv,
>> +                           enum drm_privacy_screen_status sw_state);
>> +       /**
>> +        * @get_hw_state: Called to request that the driver gets the current
>> +        * privacy-screen state from the hardware and then updates sw_state and
>> +        * hw_state accordingly. This will be called by the core just before
>> +        * the privacy-screen is registered in sysfs.
>> +        */
>> +       void (*get_hw_state)(struct drm_privacy_screen *priv);
>> +};
>> +
>> +/**
>> + * struct drm_privacy_screen - central privacy-screen structure
>> + *
>> + * Central privacy-screen structure, this contains the struct device used
>> + * to register the screen in sysfs, the screen's state, ops, etc.
>> + */
>> +struct drm_privacy_screen {
>> +       /** @dev: device used to register the privacy-screen in sysfs. */
>> +       struct device dev;
>> +       /** @lock: mutex protection all fields in this struct. */
>> +       struct mutex lock;
>> +       /** @list: privacy-screen devices list list-entry. */
>> +       struct list_head list;
>> +       /**
>> +        * @ops: &struct drm_privacy_screen_ops for this privacy-screen.
>> +        * This is NULL if the driver has unregistered the privacy-screen.
>> +        */
>> +       const struct drm_privacy_screen_ops *ops;
>> +       /**
>> +        * @sw_state: The privacy-screen's software state, see
>> +        * :ref:`Standard Connector Properties<standard_connector_properties>`
>> +        * for more info.
>> +        */
>> +       enum drm_privacy_screen_status sw_state;
>> +       /**
>> +        * @hw_state: The privacy-screen's hardware state, see
>> +        * :ref:`Standard Connector Properties<standard_connector_properties>`
>> +        * for more info.
>> +        */
>> +       enum drm_privacy_screen_status hw_state;
>> +};
>> +
>> +struct drm_privacy_screen *drm_privacy_screen_register(
>> +       struct device *parent, const struct drm_privacy_screen_ops *ops);
>> +void drm_privacy_screen_unregister(struct drm_privacy_screen *priv);
>> +
>> +#endif
>> diff --git a/include/drm/drm_privacy_screen_machine.h b/include/drm/drm_privacy_screen_machine.h
>> new file mode 100644
>> index 000000000000..aaa0d38cce92
>> --- /dev/null
>> +++ b/include/drm/drm_privacy_screen_machine.h
>> @@ -0,0 +1,41 @@
>> +/* SPDX-License-Identifier: MIT */
>> +/*
>> + * Copyright (C) 2020 Red Hat, Inc.
>> + *
>> + * Authors:
>> + * Hans de Goede <hdegoede@redhat.com>
>> + */
>> +
>> +#ifndef __DRM_PRIVACY_SCREEN_MACHINE_H__
>> +#define __DRM_PRIVACY_SCREEN_MACHINE_H__
>> +
>> +#include <linux/list.h>
>> +
>> +/**
>> + * struct drm_privacy_screen_lookup -  static privacy-screen lookup list entry
>> + *
>> + * Used for the static lookup-list for mapping privacy-screen consumer
>> + * dev-connector pairs to a privacy-screen provider.
>> + */
>> +struct drm_privacy_screen_lookup {
>> +       /** @list: Lookup list list-entry. */
>> +       struct list_head list;
>> +       /** @dev_id: Consumer device name or NULL to match all devices. */
>> +       const char *dev_id;
>> +       /** @con_id: Consumer connector name or NULL to match all connectors. */
>> +       const char *con_id;
>> +       /** @provider: dev_name() of the privacy_screen provider. */
>> +       const char *provider;
>> +};
>> +
>> +void drm_privacy_screen_lookup_add(struct drm_privacy_screen_lookup *lookup);
>> +void drm_privacy_screen_lookup_remove(struct drm_privacy_screen_lookup *lookup);
>> +
>> +static inline void drm_privacy_screen_lookup_init(void)
>> +{
>> +}
>> +static inline void drm_privacy_screen_lookup_exit(void)
>> +{
>> +}
>> +
>> +#endif
>> --
>> 2.31.1
>>
> 


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 02/10] drm: Add privacy-screen class (v4)
  2021-10-05 20:23 ` [PATCH 02/10] drm: Add privacy-screen class (v4) Hans de Goede
  2021-11-17 14:28   ` Rajat Jain
@ 2021-12-10 10:12   ` Thorsten Leemhuis
  2021-12-10 10:46     ` Hans de Goede
  1 sibling, 1 reply; 24+ messages in thread
From: Thorsten Leemhuis @ 2021-12-10 10:12 UTC (permalink / raw)
  To: Hans de Goede, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, Rajat Jain, Jani Nikula, Lyude,
	Joonas Lahtinen, Rodrigo Vivi, Ville Syrjälä,
	Mark Gross, Andy Shevchenko
  Cc: Daniel Vetter, David Airlie, Pekka Paalanen, Mario Limonciello,
	Mark Pearson, Sebastien Bacher, Marco Trevisan, Emil Velikov,
	intel-gfx, dri-devel, platform-driver-x86

Hi, this is your Linux kernel regression tracker speaking.

Top-posting for once, to make this easy accessible to everyone.

Hans, I stumbled upon your blog post about something that afaics is
related to below patch:
https://hansdegoede.livejournal.com/25948.html

To quote:

> To avoid any regressions distors should modify their initrd
> generation tools to include privacy screen provider drivers in the
> initrd (at least on systems with a privacy screen), before 5.17
> kernels start showing up in their repos.
> 
> If this change is not made, then users using a graphical bootsplash
> (plymouth) will get an extra boot-delay of up to 8 seconds
> (DeviceTimeout in plymouthd.defaults) before plymouth will show and
> when using disk-encryption where the LUKS password is requested from
> the initrd, the system will fallback to text-mode after these 8
> seconds.

Sorry for intruding, but to me as the kernel's regression tracker that
blog post sounds a whole lot like "by kernel development standards this
is not allowed due to the 'no regression rule', as users should never be
required to update something in userspace when updating the kernel".

But I'm not totally sure that's the case here. Could you please clarify
what happens when a user doesn't update the initramfs. E.g. what happens
besides the mentioned delay and the text mode (which are bad already,
but might be a accetable compormise here -- but that's up for Linus to
decide)? Does everything start to work normally shortly after the kernel
mounted the rootfs and finally can load the missing module?

tia!

Ciao, Thorsten

On 05.10.21 22:23, Hans de Goede wrote:
> On some new laptops the LCD panel has a builtin electronic privacy-screen.
> We want to export this functionality as a property on the drm connector
> object. But often this functionality is not exposed on the GPU but on some
> other (ACPI) device.
> 
> This commit adds a privacy-screen class allowing the driver for these
> other devices to register themselves as a privacy-screen provider; and
> allowing the drm/kms code to get a privacy-screen provider associated
> with a specific GPU/connector combo.
> 
> Changes in v2:
> - Make CONFIG_DRM_PRIVACY_SCREEN a bool which controls if the drm_privacy
>   code gets built as part of the main drm module rather then making it
>   a tristate which builds its own module.
> - Add a #if IS_ENABLED(CONFIG_DRM_PRIVACY_SCREEN) check to
>   drm_privacy_screen_consumer.h and define stubs when the check fails.
>   Together these 2 changes fix several dependency issues.
> - Remove module related code now that this is part of the main drm.ko
> - Use drm_class as class for the privacy-screen devices instead of
>   adding a separate class for this
> 
> Changes in v3:
> - Make the static inline drm_privacy_screen_get_state() stub set sw_state
>   and hw_state to PRIVACY_SCREEN_DISABLED to squelch an uninitialized
>   variable warning when CONFIG_DRM_PRIVICAY_SCREEN is not set
> 
> Changes in v4:
> - Make drm_privacy_screen_set_sw_state() skip calling out to the hw if
>   hw_state == new_sw_state
> 
> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
> Reviewed-by: Lyude Paul <lyude@redhat.com>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  Documentation/gpu/drm-kms-helpers.rst     |  15 +
>  MAINTAINERS                               |   8 +
>  drivers/gpu/drm/Kconfig                   |   4 +
>  drivers/gpu/drm/Makefile                  |   1 +
>  drivers/gpu/drm/drm_drv.c                 |   4 +
>  drivers/gpu/drm/drm_privacy_screen.c      | 403 ++++++++++++++++++++++
>  include/drm/drm_privacy_screen_consumer.h |  50 +++
>  include/drm/drm_privacy_screen_driver.h   |  80 +++++
>  include/drm/drm_privacy_screen_machine.h  |  41 +++
>  9 files changed, 606 insertions(+)
>  create mode 100644 drivers/gpu/drm/drm_privacy_screen.c
>  create mode 100644 include/drm/drm_privacy_screen_consumer.h
>  create mode 100644 include/drm/drm_privacy_screen_driver.h
>  create mode 100644 include/drm/drm_privacy_screen_machine.h
> 
> diff --git a/Documentation/gpu/drm-kms-helpers.rst b/Documentation/gpu/drm-kms-helpers.rst
> index ec2f65b31930..5bb55ec1b9b5 100644
> --- a/Documentation/gpu/drm-kms-helpers.rst
> +++ b/Documentation/gpu/drm-kms-helpers.rst
> @@ -435,3 +435,18 @@ Legacy CRTC/Modeset Helper Functions Reference
>  
>  .. kernel-doc:: drivers/gpu/drm/drm_crtc_helper.c
>     :export:
> +
> +Privacy-screen class
> +====================
> +
> +.. kernel-doc:: drivers/gpu/drm/drm_privacy_screen.c
> +   :doc: overview
> +
> +.. kernel-doc:: include/drm/drm_privacy_screen_driver.h
> +   :internal:
> +
> +.. kernel-doc:: include/drm/drm_privacy_screen_machine.h
> +   :internal:
> +
> +.. kernel-doc:: drivers/gpu/drm/drm_privacy_screen.c
> +   :export:
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 28e5f0ae1009..cb94bb3b8724 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -6423,6 +6423,14 @@ F:	drivers/gpu/drm/drm_panel.c
>  F:	drivers/gpu/drm/panel/
>  F:	include/drm/drm_panel.h
>  
> +DRM PRIVACY-SCREEN CLASS
> +M:	Hans de Goede <hdegoede@redhat.com>
> +L:	dri-devel@lists.freedesktop.org
> +S:	Maintained
> +T:	git git://anongit.freedesktop.org/drm/drm-misc
> +F:	drivers/gpu/drm/drm_privacy_screen*
> +F:	include/drm/drm_privacy_screen*
> +
>  DRM TTM SUBSYSTEM
>  M:	Christian Koenig <christian.koenig@amd.com>
>  M:	Huang Rui <ray.huang@amd.com>
> diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
> index 2a926d0de423..c686c08447ac 100644
> --- a/drivers/gpu/drm/Kconfig
> +++ b/drivers/gpu/drm/Kconfig
> @@ -481,3 +481,7 @@ config DRM_PANEL_ORIENTATION_QUIRKS
>  config DRM_LIB_RANDOM
>  	bool
>  	default n
> +
> +config DRM_PRIVACY_SCREEN
> +	bool
> +	default n
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index 0dff40bb863c..788fc37096f6 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -32,6 +32,7 @@ drm-$(CONFIG_OF) += drm_of.o
>  drm-$(CONFIG_PCI) += drm_pci.o
>  drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
>  drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
> +drm-$(CONFIG_DRM_PRIVACY_SCREEN) += drm_privacy_screen.o
>  
>  obj-$(CONFIG_DRM_DP_AUX_BUS) += drm_dp_aux_bus.o
>  
> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> index 7a5097467ba5..dc293b771c3f 100644
> --- a/drivers/gpu/drm/drm_drv.c
> +++ b/drivers/gpu/drm/drm_drv.c
> @@ -43,6 +43,7 @@
>  #include <drm/drm_managed.h>
>  #include <drm/drm_mode_object.h>
>  #include <drm/drm_print.h>
> +#include <drm/drm_privacy_screen_machine.h>
>  
>  #include "drm_crtc_internal.h"
>  #include "drm_internal.h"
> @@ -1029,6 +1030,7 @@ static const struct file_operations drm_stub_fops = {
>  
>  static void drm_core_exit(void)
>  {
> +	drm_privacy_screen_lookup_exit();
>  	unregister_chrdev(DRM_MAJOR, "drm");
>  	debugfs_remove(drm_debugfs_root);
>  	drm_sysfs_destroy();
> @@ -1056,6 +1058,8 @@ static int __init drm_core_init(void)
>  	if (ret < 0)
>  		goto error;
>  
> +	drm_privacy_screen_lookup_init();
> +
>  	drm_core_init_complete = true;
>  
>  	DRM_DEBUG("Initialized\n");
> diff --git a/drivers/gpu/drm/drm_privacy_screen.c b/drivers/gpu/drm/drm_privacy_screen.c
> new file mode 100644
> index 000000000000..183a6011adf0
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_privacy_screen.c
> @@ -0,0 +1,403 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright (C) 2020 - 2021 Red Hat, Inc.
> + *
> + * Authors:
> + * Hans de Goede <hdegoede@redhat.com>
> + */
> +
> +#include <linux/device.h>
> +#include <linux/kernel.h>
> +#include <linux/list.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/slab.h>
> +#include <drm/drm_privacy_screen_machine.h>
> +#include <drm/drm_privacy_screen_consumer.h>
> +#include <drm/drm_privacy_screen_driver.h>
> +#include "drm_internal.h"
> +
> +/**
> + * DOC: overview
> + *
> + * This class allows non KMS drivers, from e.g. drivers/platform/x86 to
> + * register a privacy-screen device, which the KMS drivers can then use
> + * to implement the standard privacy-screen properties, see
> + * :ref:`Standard Connector Properties<standard_connector_properties>`.
> + *
> + * KMS drivers using a privacy-screen class device are advised to use the
> + * drm_connector_attach_privacy_screen_provider() and
> + * drm_connector_update_privacy_screen() helpers for dealing with this.
> + */
> +
> +#define to_drm_privacy_screen(dev) \
> +	container_of(dev, struct drm_privacy_screen, dev)
> +
> +static DEFINE_MUTEX(drm_privacy_screen_lookup_lock);
> +static LIST_HEAD(drm_privacy_screen_lookup_list);
> +
> +static DEFINE_MUTEX(drm_privacy_screen_devs_lock);
> +static LIST_HEAD(drm_privacy_screen_devs);
> +
> +/*** drm_privacy_screen_machine.h functions ***/
> +
> +/**
> + * drm_privacy_screen_lookup_add - add an entry to the static privacy-screen
> + *    lookup list
> + * @lookup: lookup list entry to add
> + *
> + * Add an entry to the static privacy-screen lookup list. Note the
> + * &struct list_head which is part of the &struct drm_privacy_screen_lookup
> + * gets added to a list owned by the privacy-screen core. So the passed in
> + * &struct drm_privacy_screen_lookup must not be free-ed until it is removed
> + * from the lookup list by calling drm_privacy_screen_lookup_remove().
> + */
> +void drm_privacy_screen_lookup_add(struct drm_privacy_screen_lookup *lookup)
> +{
> +	mutex_lock(&drm_privacy_screen_lookup_lock);
> +	list_add(&lookup->list, &drm_privacy_screen_lookup_list);
> +	mutex_unlock(&drm_privacy_screen_lookup_lock);
> +}
> +EXPORT_SYMBOL(drm_privacy_screen_lookup_add);
> +
> +/**
> + * drm_privacy_screen_lookup_remove - remove an entry to the static
> + *    privacy-screen lookup list
> + * @lookup: lookup list entry to remove
> + *
> + * Remove an entry previously added with drm_privacy_screen_lookup_add()
> + * from the static privacy-screen lookup list.
> + */
> +void drm_privacy_screen_lookup_remove(struct drm_privacy_screen_lookup *lookup)
> +{
> +	mutex_lock(&drm_privacy_screen_lookup_lock);
> +	list_del(&lookup->list);
> +	mutex_unlock(&drm_privacy_screen_lookup_lock);
> +}
> +EXPORT_SYMBOL(drm_privacy_screen_lookup_remove);
> +
> +/*** drm_privacy_screen_consumer.h functions ***/
> +
> +static struct drm_privacy_screen *drm_privacy_screen_get_by_name(
> +	const char *name)
> +{
> +	struct drm_privacy_screen *priv;
> +	struct device *dev = NULL;
> +
> +	mutex_lock(&drm_privacy_screen_devs_lock);
> +
> +	list_for_each_entry(priv, &drm_privacy_screen_devs, list) {
> +		if (strcmp(dev_name(&priv->dev), name) == 0) {
> +			dev = get_device(&priv->dev);
> +			break;
> +		}
> +	}
> +
> +	mutex_unlock(&drm_privacy_screen_devs_lock);
> +
> +	return dev ? to_drm_privacy_screen(dev) : NULL;
> +}
> +
> +/**
> + * drm_privacy_screen_get - get a privacy-screen provider
> + * @dev: consumer-device for which to get a privacy-screen provider
> + * @con_id: (video)connector name for which to get a privacy-screen provider
> + *
> + * Get a privacy-screen provider for a privacy-screen attached to the
> + * display described by the @dev and @con_id parameters.
> + *
> + * Return:
> + * * A pointer to a &struct drm_privacy_screen on success.
> + * * ERR_PTR(-ENODEV) if no matching privacy-screen is found
> + * * ERR_PTR(-EPROBE_DEFER) if there is a matching privacy-screen,
> + *                          but it has not been registered yet.
> + */
> +struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
> +						  const char *con_id)
> +{
> +	const char *dev_id = dev ? dev_name(dev) : NULL;
> +	struct drm_privacy_screen_lookup *l;
> +	struct drm_privacy_screen *priv;
> +	const char *provider = NULL;
> +	int match, best = -1;
> +
> +	/*
> +	 * For now we only support using a static lookup table, which is
> +	 * populated by the drm_privacy_screen_arch_init() call. This should
> +	 * be extended with device-tree / fw_node lookup when support is added
> +	 * for device-tree using hardware with a privacy-screen.
> +	 *
> +	 * The lookup algorithm was shamelessly taken from the clock
> +	 * framework:
> +	 *
> +	 * We do slightly fuzzy matching here:
> +	 *  An entry with a NULL ID is assumed to be a wildcard.
> +	 *  If an entry has a device ID, it must match
> +	 *  If an entry has a connection ID, it must match
> +	 * Then we take the most specific entry - with the following order
> +	 * of precedence: dev+con > dev only > con only.
> +	 */
> +	mutex_lock(&drm_privacy_screen_lookup_lock);
> +
> +	list_for_each_entry(l, &drm_privacy_screen_lookup_list, list) {
> +		match = 0;
> +
> +		if (l->dev_id) {
> +			if (!dev_id || strcmp(l->dev_id, dev_id))
> +				continue;
> +
> +			match += 2;
> +		}
> +
> +		if (l->con_id) {
> +			if (!con_id || strcmp(l->con_id, con_id))
> +				continue;
> +
> +			match += 1;
> +		}
> +
> +		if (match > best) {
> +			provider = l->provider;
> +			best = match;
> +		}
> +	}
> +
> +	mutex_unlock(&drm_privacy_screen_lookup_lock);
> +
> +	if (!provider)
> +		return ERR_PTR(-ENODEV);
> +
> +	priv = drm_privacy_screen_get_by_name(provider);
> +	if (!priv)
> +		return ERR_PTR(-EPROBE_DEFER);
> +
> +	return priv;
> +}
> +EXPORT_SYMBOL(drm_privacy_screen_get);
> +
> +/**
> + * drm_privacy_screen_put - release a privacy-screen reference
> + * @priv: privacy screen reference to release
> + *
> + * Release a privacy-screen provider reference gotten through
> + * drm_privacy_screen_get(). May be called with a NULL or ERR_PTR,
> + * in which case it is a no-op.
> + */
> +void drm_privacy_screen_put(struct drm_privacy_screen *priv)
> +{
> +	if (IS_ERR_OR_NULL(priv))
> +		return;
> +
> +	put_device(&priv->dev);
> +}
> +EXPORT_SYMBOL(drm_privacy_screen_put);
> +
> +/**
> + * drm_privacy_screen_set_sw_state - set a privacy-screen's sw-state
> + * @priv: privacy screen to set the sw-state for
> + * @sw_state: new sw-state value to set
> + *
> + * Set the sw-state of a privacy screen. If the privacy-screen is not
> + * in a locked hw-state, then the actual and hw-state of the privacy-screen
> + * will be immediately updated to the new value. If the privacy-screen is
> + * in a locked hw-state, then the new sw-state will be remembered as the
> + * requested state to put the privacy-screen in when it becomes unlocked.
> + *
> + * Return: 0 on success, negative error code on failure.
> + */
> +int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
> +				    enum drm_privacy_screen_status sw_state)
> +{
> +	int ret = 0;
> +
> +	mutex_lock(&priv->lock);
> +
> +	if (!priv->ops) {
> +		ret = -ENODEV;
> +		goto out;
> +	}
> +
> +	/*
> +	 * As per the DRM connector properties documentation, setting the
> +	 * sw_state while the hw_state is locked is allowed. In this case
> +	 * it is a no-op other then storing the new sw_state so that it
> +	 * can be honored when the state gets unlocked.
> +	 * Also skip the set if the hw already is in the desired state.
> +	 */
> +	if (priv->hw_state >= PRIVACY_SCREEN_DISABLED_LOCKED ||
> +	    priv->hw_state == sw_state) {
> +		priv->sw_state = sw_state;
> +		goto out;
> +	}
> +
> +	ret = priv->ops->set_sw_state(priv, sw_state);
> +out:
> +	mutex_unlock(&priv->lock);
> +	return ret;
> +}
> +EXPORT_SYMBOL(drm_privacy_screen_set_sw_state);
> +
> +/**
> + * drm_privacy_screen_get_state - get privacy-screen's current state
> + * @priv: privacy screen to get the state for
> + * @sw_state_ret: address where to store the privacy-screens current sw-state
> + * @hw_state_ret: address where to store the privacy-screens current hw-state
> + *
> + * Get the current state of a privacy-screen, both the sw-state and the
> + * hw-state.
> + */
> +void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
> +				  enum drm_privacy_screen_status *sw_state_ret,
> +				  enum drm_privacy_screen_status *hw_state_ret)
> +{
> +	mutex_lock(&priv->lock);
> +	*sw_state_ret = priv->sw_state;
> +	*hw_state_ret = priv->hw_state;
> +	mutex_unlock(&priv->lock);
> +}
> +EXPORT_SYMBOL(drm_privacy_screen_get_state);
> +
> +/*** drm_privacy_screen_driver.h functions ***/
> +
> +static ssize_t sw_state_show(struct device *dev,
> +			     struct device_attribute *attr, char *buf)
> +{
> +	struct drm_privacy_screen *priv = to_drm_privacy_screen(dev);
> +	const char * const sw_state_names[] = {
> +		"Disabled",
> +		"Enabled",
> +	};
> +	ssize_t ret;
> +
> +	mutex_lock(&priv->lock);
> +
> +	if (!priv->ops)
> +		ret = -ENODEV;
> +	else if (WARN_ON(priv->sw_state >= ARRAY_SIZE(sw_state_names)))
> +		ret = -ENXIO;
> +	else
> +		ret = sprintf(buf, "%s\n", sw_state_names[priv->sw_state]);
> +
> +	mutex_unlock(&priv->lock);
> +	return ret;
> +}
> +/*
> + * RO: Do not allow setting the sw_state through sysfs, this MUST be done
> + * through the drm_properties on the drm_connector.
> + */
> +static DEVICE_ATTR_RO(sw_state);
> +
> +static ssize_t hw_state_show(struct device *dev,
> +			     struct device_attribute *attr, char *buf)
> +{
> +	struct drm_privacy_screen *priv = to_drm_privacy_screen(dev);
> +	const char * const hw_state_names[] = {
> +		"Disabled",
> +		"Enabled",
> +		"Disabled, locked",
> +		"Enabled, locked",
> +	};
> +	ssize_t ret;
> +
> +	mutex_lock(&priv->lock);
> +
> +	if (!priv->ops)
> +		ret = -ENODEV;
> +	else if (WARN_ON(priv->hw_state >= ARRAY_SIZE(hw_state_names)))
> +		ret = -ENXIO;
> +	else
> +		ret = sprintf(buf, "%s\n", hw_state_names[priv->hw_state]);
> +
> +	mutex_unlock(&priv->lock);
> +	return ret;
> +}
> +static DEVICE_ATTR_RO(hw_state);
> +
> +static struct attribute *drm_privacy_screen_attrs[] = {
> +	&dev_attr_sw_state.attr,
> +	&dev_attr_hw_state.attr,
> +	NULL
> +};
> +ATTRIBUTE_GROUPS(drm_privacy_screen);
> +
> +static struct device_type drm_privacy_screen_type = {
> +	.name = "privacy_screen",
> +	.groups = drm_privacy_screen_groups,
> +};
> +
> +static void drm_privacy_screen_device_release(struct device *dev)
> +{
> +	struct drm_privacy_screen *priv = to_drm_privacy_screen(dev);
> +
> +	kfree(priv);
> +}
> +
> +/**
> + * drm_privacy_screen_register - register a privacy-screen
> + * @parent: parent-device for the privacy-screen
> + * @ops: &struct drm_privacy_screen_ops pointer with ops for the privacy-screen
> + *
> + * Create and register a privacy-screen.
> + *
> + * Return:
> + * * A pointer to the created privacy-screen on success.
> + * * 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 drm_privacy_screen *priv;
> +	int ret;
> +
> +	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
> +	if (!priv)
> +		return ERR_PTR(-ENOMEM);
> +
> +	mutex_init(&priv->lock);
> +
> +	priv->dev.class = drm_class;
> +	priv->dev.type = &drm_privacy_screen_type;
> +	priv->dev.parent = parent;
> +	priv->dev.release = drm_privacy_screen_device_release;
> +	dev_set_name(&priv->dev, "privacy_screen-%s", dev_name(parent));
> +	priv->ops = ops;
> +
> +	priv->ops->get_hw_state(priv);
> +
> +	ret = device_register(&priv->dev);
> +	if (ret) {
> +		put_device(&priv->dev);
> +		return ERR_PTR(ret);
> +	}
> +
> +	mutex_lock(&drm_privacy_screen_devs_lock);
> +	list_add(&priv->list, &drm_privacy_screen_devs);
> +	mutex_unlock(&drm_privacy_screen_devs_lock);
> +
> +	return priv;
> +}
> +EXPORT_SYMBOL(drm_privacy_screen_register);
> +
> +/**
> + * drm_privacy_screen_unregister - unregister privacy-screen
> + * @priv: privacy-screen to unregister
> + *
> + * Unregister a privacy-screen registered with drm_privacy_screen_register().
> + * May be called with a NULL or ERR_PTR, in which case it is a no-op.
> + */
> +void drm_privacy_screen_unregister(struct drm_privacy_screen *priv)
> +{
> +	if (IS_ERR_OR_NULL(priv))
> +		return;
> +
> +	mutex_lock(&drm_privacy_screen_devs_lock);
> +	list_del(&priv->list);
> +	mutex_unlock(&drm_privacy_screen_devs_lock);
> +
> +	mutex_lock(&priv->lock);
> +	priv->ops = NULL;
> +	mutex_unlock(&priv->lock);
> +
> +	device_unregister(&priv->dev);
> +}
> +EXPORT_SYMBOL(drm_privacy_screen_unregister);
> diff --git a/include/drm/drm_privacy_screen_consumer.h b/include/drm/drm_privacy_screen_consumer.h
> new file mode 100644
> index 000000000000..0cbd23b0453d
> --- /dev/null
> +++ b/include/drm/drm_privacy_screen_consumer.h
> @@ -0,0 +1,50 @@
> +/* SPDX-License-Identifier: MIT */
> +/*
> + * Copyright (C) 2020 Red Hat, Inc.
> + *
> + * Authors:
> + * Hans de Goede <hdegoede@redhat.com>
> + */
> +
> +#ifndef __DRM_PRIVACY_SCREEN_CONSUMER_H__
> +#define __DRM_PRIVACY_SCREEN_CONSUMER_H__
> +
> +#include <linux/device.h>
> +#include <drm/drm_connector.h>
> +
> +struct drm_privacy_screen;
> +
> +#if IS_ENABLED(CONFIG_DRM_PRIVACY_SCREEN)
> +struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
> +						  const char *con_id);
> +void drm_privacy_screen_put(struct drm_privacy_screen *priv);
> +
> +int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
> +				    enum drm_privacy_screen_status sw_state);
> +void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
> +				  enum drm_privacy_screen_status *sw_state_ret,
> +				  enum drm_privacy_screen_status *hw_state_ret);
> +#else
> +static inline struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
> +								const char *con_id)
> +{
> +	return ERR_PTR(-ENODEV);
> +}
> +static inline void drm_privacy_screen_put(struct drm_privacy_screen *priv)
> +{
> +}
> +static inline int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
> +						  enum drm_privacy_screen_status sw_state)
> +{
> +	return -ENODEV;
> +}
> +static inline void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
> +						enum drm_privacy_screen_status *sw_state_ret,
> +						enum drm_privacy_screen_status *hw_state_ret)
> +{
> +	*sw_state_ret = PRIVACY_SCREEN_DISABLED;
> +	*hw_state_ret = PRIVACY_SCREEN_DISABLED;
> +}
> +#endif
> +
> +#endif
> diff --git a/include/drm/drm_privacy_screen_driver.h b/include/drm/drm_privacy_screen_driver.h
> new file mode 100644
> index 000000000000..5187ae52eb03
> --- /dev/null
> +++ b/include/drm/drm_privacy_screen_driver.h
> @@ -0,0 +1,80 @@
> +/* SPDX-License-Identifier: MIT */
> +/*
> + * Copyright (C) 2020 Red Hat, Inc.
> + *
> + * Authors:
> + * Hans de Goede <hdegoede@redhat.com>
> + */
> +
> +#ifndef __DRM_PRIVACY_SCREEN_DRIVER_H__
> +#define __DRM_PRIVACY_SCREEN_DRIVER_H__
> +
> +#include <linux/device.h>
> +#include <linux/list.h>
> +#include <linux/mutex.h>
> +#include <drm/drm_connector.h>
> +
> +struct drm_privacy_screen;
> +
> +/**
> + * struct drm_privacy_screen_ops - drm_privacy_screen operations
> + *
> + * Defines the operations which the privacy-screen class code may call.
> + * These functions should be implemented by the privacy-screen driver.
> + */
> +struct drm_privacy_screen_ops {
> +	/**
> +	 * @set_sw_state: Called to request a change of the privacy-screen
> +	 * state. The privacy-screen class code contains a check to avoid this
> +	 * getting called when the hw_state reports the state is locked.
> +	 * It is the driver's responsibility to update sw_state and hw_state.
> +	 * This is always called with the drm_privacy_screen's lock held.
> +	 */
> +	int (*set_sw_state)(struct drm_privacy_screen *priv,
> +			    enum drm_privacy_screen_status sw_state);
> +	/**
> +	 * @get_hw_state: Called to request that the driver gets the current
> +	 * privacy-screen state from the hardware and then updates sw_state and
> +	 * hw_state accordingly. This will be called by the core just before
> +	 * the privacy-screen is registered in sysfs.
> +	 */
> +	void (*get_hw_state)(struct drm_privacy_screen *priv);
> +};
> +
> +/**
> + * struct drm_privacy_screen - central privacy-screen structure
> + *
> + * Central privacy-screen structure, this contains the struct device used
> + * to register the screen in sysfs, the screen's state, ops, etc.
> + */
> +struct drm_privacy_screen {
> +	/** @dev: device used to register the privacy-screen in sysfs. */
> +	struct device dev;
> +	/** @lock: mutex protection all fields in this struct. */
> +	struct mutex lock;
> +	/** @list: privacy-screen devices list list-entry. */
> +	struct list_head list;
> +	/**
> +	 * @ops: &struct drm_privacy_screen_ops for this privacy-screen.
> +	 * This is NULL if the driver has unregistered the privacy-screen.
> +	 */
> +	const struct drm_privacy_screen_ops *ops;
> +	/**
> +	 * @sw_state: The privacy-screen's software state, see
> +	 * :ref:`Standard Connector Properties<standard_connector_properties>`
> +	 * for more info.
> +	 */
> +	enum drm_privacy_screen_status sw_state;
> +	/**
> +	 * @hw_state: The privacy-screen's hardware state, see
> +	 * :ref:`Standard Connector Properties<standard_connector_properties>`
> +	 * for more info.
> +	 */
> +	enum drm_privacy_screen_status hw_state;
> +};
> +
> +struct drm_privacy_screen *drm_privacy_screen_register(
> +	struct device *parent, const struct drm_privacy_screen_ops *ops);
> +void drm_privacy_screen_unregister(struct drm_privacy_screen *priv);
> +
> +#endif
> diff --git a/include/drm/drm_privacy_screen_machine.h b/include/drm/drm_privacy_screen_machine.h
> new file mode 100644
> index 000000000000..aaa0d38cce92
> --- /dev/null
> +++ b/include/drm/drm_privacy_screen_machine.h
> @@ -0,0 +1,41 @@
> +/* SPDX-License-Identifier: MIT */
> +/*
> + * Copyright (C) 2020 Red Hat, Inc.
> + *
> + * Authors:
> + * Hans de Goede <hdegoede@redhat.com>
> + */
> +
> +#ifndef __DRM_PRIVACY_SCREEN_MACHINE_H__
> +#define __DRM_PRIVACY_SCREEN_MACHINE_H__
> +
> +#include <linux/list.h>
> +
> +/**
> + * struct drm_privacy_screen_lookup -  static privacy-screen lookup list entry
> + *
> + * Used for the static lookup-list for mapping privacy-screen consumer
> + * dev-connector pairs to a privacy-screen provider.
> + */
> +struct drm_privacy_screen_lookup {
> +	/** @list: Lookup list list-entry. */
> +	struct list_head list;
> +	/** @dev_id: Consumer device name or NULL to match all devices. */
> +	const char *dev_id;
> +	/** @con_id: Consumer connector name or NULL to match all connectors. */
> +	const char *con_id;
> +	/** @provider: dev_name() of the privacy_screen provider. */
> +	const char *provider;
> +};
> +
> +void drm_privacy_screen_lookup_add(struct drm_privacy_screen_lookup *lookup);
> +void drm_privacy_screen_lookup_remove(struct drm_privacy_screen_lookup *lookup);
> +
> +static inline void drm_privacy_screen_lookup_init(void)
> +{
> +}
> +static inline void drm_privacy_screen_lookup_exit(void)
> +{
> +}
> +
> +#endif
> 


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 02/10] drm: Add privacy-screen class (v4)
  2021-12-10 10:12   ` Thorsten Leemhuis
@ 2021-12-10 10:46     ` Hans de Goede
  2021-12-10 11:22       ` Thorsten Leemhuis
  0 siblings, 1 reply; 24+ messages in thread
From: Hans de Goede @ 2021-12-10 10:46 UTC (permalink / raw)
  To: Thorsten Leemhuis, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, Rajat Jain, Jani Nikula, Lyude,
	Joonas Lahtinen, Rodrigo Vivi, Ville Syrjälä,
	Mark Gross, Andy Shevchenko
  Cc: Daniel Vetter, David Airlie, Pekka Paalanen, Mario Limonciello,
	Mark Pearson, Sebastien Bacher, Marco Trevisan, Emil Velikov,
	intel-gfx, dri-devel, platform-driver-x86

Hi Thorsten,

On 12/10/21 11:12, Thorsten Leemhuis wrote:
> Hi, this is your Linux kernel regression tracker speaking.
> 
> Top-posting for once, to make this easy accessible to everyone.
> 
> Hans, I stumbled upon your blog post about something that afaics is
> related to below patch:
> https://hansdegoede.livejournal.com/25948.html
> 
> To quote:
> 
>> To avoid any regressions distors should modify their initrd
>> generation tools to include privacy screen provider drivers in the
>> initrd (at least on systems with a privacy screen), before 5.17
>> kernels start showing up in their repos.
>>
>> If this change is not made, then users using a graphical bootsplash
>> (plymouth) will get an extra boot-delay of up to 8 seconds
>> (DeviceTimeout in plymouthd.defaults) before plymouth will show and
>> when using disk-encryption where the LUKS password is requested from
>> the initrd, the system will fallback to text-mode after these 8
>> seconds.
> 
> Sorry for intruding, but to me as the kernel's regression tracker that
> blog post sounds a whole lot like "by kernel development standards this
> is not allowed due to the 'no regression rule', as users should never be
> required to update something in userspace when updating the kernel".

I completely understand where you are coming from here, but AFAIK
the initrd generation has always been a bit of an exception here.

For example (IIRC) over time we have seen the radeon module growing
a runtime dependency on the amdkfd module which also required updated
initrd generation tools.

Another example (which I'm sure of) is the i915 driver gaining a softdep
on kvmgt (which is now gone again) which required new enough kmod tools
to understand this as well as initrd generation tools updates to also
take softdeps into account:
https://github.com/dracutdevs/dracut/commit/4cdee66c8ed5f82bbd0638e30d867318343b0e6c

More in general if you look at e.g. dracut's git history, there are
various other cases where dracut needed to be updated to adjust
to kernel changes. For example dracut decides if a module is a block
driver and thus may be necessary to have in the initrd based on a
list of kernel-symbols the module links to and sometimes those
symbols change due to refactoring of kernel internals, see e.g. :
https://github.com/dracutdevs/dracut/commit/b292ce7295f18192124e64e5ec31161d09492160

TL;DR: initrd-generators and the kernel are simply tied together so much
that users cannot expect to be able to jump to the latest kernel without
either updating the initrd-generator, or adding some modules as modules
which must always be added to the initrd in the initrd-generator config
file (as a workaround).

Declaring kernel changes which break initrd-generation in some way as
being regressions, would mean that e.g. we cannot introduce any
kernel changes which causes some drm/block/whatever drivers to use
some new register helper functions which are not yet on the list of
symbols which dracut uses to identify drm/block/whatever drivers.

The only difference between previous initrd-generator breaking changes
and this one, is that I decided that it would be good for everyone
to be aware of this before hand; and now I get the feeling that I'm
being punished for warning people about this instead of just letting
things break silently. I know you don't intend your email this way in
any way, but still.

Also AFAIK drivers may also at some point drop support for (much) older
firmware versions requiring installing a recent linux-firmware together
with a new kernel.

In my reading of the rules the 'users should never be required to update
something in userspace when updating the kernel' rule is about keeping
people's normal programs working, IOW not breaking userspace ABI and that
is not happening here.

> But I'm not totally sure that's the case here. Could you please clarify
> what happens when a user doesn't update the initramfs. E.g. what happens
> besides the mentioned delay and the text mode (which are bad already,
> but might be a accetable compormise here -- but that's up for Linus to
> decide)? Does everything start to work normally shortly after the kernel
> mounted the rootfs and finally can load the missing module?

Yes everything will work normally once the rootfs gets mounted and the
missing module gets loaded.

Regards,

Hans



> On 05.10.21 22:23, Hans de Goede wrote:
>> On some new laptops the LCD panel has a builtin electronic privacy-screen.
>> We want to export this functionality as a property on the drm connector
>> object. But often this functionality is not exposed on the GPU but on some
>> other (ACPI) device.
>>
>> This commit adds a privacy-screen class allowing the driver for these
>> other devices to register themselves as a privacy-screen provider; and
>> allowing the drm/kms code to get a privacy-screen provider associated
>> with a specific GPU/connector combo.
>>
>> Changes in v2:
>> - Make CONFIG_DRM_PRIVACY_SCREEN a bool which controls if the drm_privacy
>>   code gets built as part of the main drm module rather then making it
>>   a tristate which builds its own module.
>> - Add a #if IS_ENABLED(CONFIG_DRM_PRIVACY_SCREEN) check to
>>   drm_privacy_screen_consumer.h and define stubs when the check fails.
>>   Together these 2 changes fix several dependency issues.
>> - Remove module related code now that this is part of the main drm.ko
>> - Use drm_class as class for the privacy-screen devices instead of
>>   adding a separate class for this
>>
>> Changes in v3:
>> - Make the static inline drm_privacy_screen_get_state() stub set sw_state
>>   and hw_state to PRIVACY_SCREEN_DISABLED to squelch an uninitialized
>>   variable warning when CONFIG_DRM_PRIVICAY_SCREEN is not set
>>
>> Changes in v4:
>> - Make drm_privacy_screen_set_sw_state() skip calling out to the hw if
>>   hw_state == new_sw_state
>>
>> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
>> Reviewed-by: Lyude Paul <lyude@redhat.com>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>  Documentation/gpu/drm-kms-helpers.rst     |  15 +
>>  MAINTAINERS                               |   8 +
>>  drivers/gpu/drm/Kconfig                   |   4 +
>>  drivers/gpu/drm/Makefile                  |   1 +
>>  drivers/gpu/drm/drm_drv.c                 |   4 +
>>  drivers/gpu/drm/drm_privacy_screen.c      | 403 ++++++++++++++++++++++
>>  include/drm/drm_privacy_screen_consumer.h |  50 +++
>>  include/drm/drm_privacy_screen_driver.h   |  80 +++++
>>  include/drm/drm_privacy_screen_machine.h  |  41 +++
>>  9 files changed, 606 insertions(+)
>>  create mode 100644 drivers/gpu/drm/drm_privacy_screen.c
>>  create mode 100644 include/drm/drm_privacy_screen_consumer.h
>>  create mode 100644 include/drm/drm_privacy_screen_driver.h
>>  create mode 100644 include/drm/drm_privacy_screen_machine.h
>>
>> diff --git a/Documentation/gpu/drm-kms-helpers.rst b/Documentation/gpu/drm-kms-helpers.rst
>> index ec2f65b31930..5bb55ec1b9b5 100644
>> --- a/Documentation/gpu/drm-kms-helpers.rst
>> +++ b/Documentation/gpu/drm-kms-helpers.rst
>> @@ -435,3 +435,18 @@ Legacy CRTC/Modeset Helper Functions Reference
>>  
>>  .. kernel-doc:: drivers/gpu/drm/drm_crtc_helper.c
>>     :export:
>> +
>> +Privacy-screen class
>> +====================
>> +
>> +.. kernel-doc:: drivers/gpu/drm/drm_privacy_screen.c
>> +   :doc: overview
>> +
>> +.. kernel-doc:: include/drm/drm_privacy_screen_driver.h
>> +   :internal:
>> +
>> +.. kernel-doc:: include/drm/drm_privacy_screen_machine.h
>> +   :internal:
>> +
>> +.. kernel-doc:: drivers/gpu/drm/drm_privacy_screen.c
>> +   :export:
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 28e5f0ae1009..cb94bb3b8724 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -6423,6 +6423,14 @@ F:	drivers/gpu/drm/drm_panel.c
>>  F:	drivers/gpu/drm/panel/
>>  F:	include/drm/drm_panel.h
>>  
>> +DRM PRIVACY-SCREEN CLASS
>> +M:	Hans de Goede <hdegoede@redhat.com>
>> +L:	dri-devel@lists.freedesktop.org
>> +S:	Maintained
>> +T:	git git://anongit.freedesktop.org/drm/drm-misc
>> +F:	drivers/gpu/drm/drm_privacy_screen*
>> +F:	include/drm/drm_privacy_screen*
>> +
>>  DRM TTM SUBSYSTEM
>>  M:	Christian Koenig <christian.koenig@amd.com>
>>  M:	Huang Rui <ray.huang@amd.com>
>> diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
>> index 2a926d0de423..c686c08447ac 100644
>> --- a/drivers/gpu/drm/Kconfig
>> +++ b/drivers/gpu/drm/Kconfig
>> @@ -481,3 +481,7 @@ config DRM_PANEL_ORIENTATION_QUIRKS
>>  config DRM_LIB_RANDOM
>>  	bool
>>  	default n
>> +
>> +config DRM_PRIVACY_SCREEN
>> +	bool
>> +	default n
>> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
>> index 0dff40bb863c..788fc37096f6 100644
>> --- a/drivers/gpu/drm/Makefile
>> +++ b/drivers/gpu/drm/Makefile
>> @@ -32,6 +32,7 @@ drm-$(CONFIG_OF) += drm_of.o
>>  drm-$(CONFIG_PCI) += drm_pci.o
>>  drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
>>  drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
>> +drm-$(CONFIG_DRM_PRIVACY_SCREEN) += drm_privacy_screen.o
>>  
>>  obj-$(CONFIG_DRM_DP_AUX_BUS) += drm_dp_aux_bus.o
>>  
>> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
>> index 7a5097467ba5..dc293b771c3f 100644
>> --- a/drivers/gpu/drm/drm_drv.c
>> +++ b/drivers/gpu/drm/drm_drv.c
>> @@ -43,6 +43,7 @@
>>  #include <drm/drm_managed.h>
>>  #include <drm/drm_mode_object.h>
>>  #include <drm/drm_print.h>
>> +#include <drm/drm_privacy_screen_machine.h>
>>  
>>  #include "drm_crtc_internal.h"
>>  #include "drm_internal.h"
>> @@ -1029,6 +1030,7 @@ static const struct file_operations drm_stub_fops = {
>>  
>>  static void drm_core_exit(void)
>>  {
>> +	drm_privacy_screen_lookup_exit();
>>  	unregister_chrdev(DRM_MAJOR, "drm");
>>  	debugfs_remove(drm_debugfs_root);
>>  	drm_sysfs_destroy();
>> @@ -1056,6 +1058,8 @@ static int __init drm_core_init(void)
>>  	if (ret < 0)
>>  		goto error;
>>  
>> +	drm_privacy_screen_lookup_init();
>> +
>>  	drm_core_init_complete = true;
>>  
>>  	DRM_DEBUG("Initialized\n");
>> diff --git a/drivers/gpu/drm/drm_privacy_screen.c b/drivers/gpu/drm/drm_privacy_screen.c
>> new file mode 100644
>> index 000000000000..183a6011adf0
>> --- /dev/null
>> +++ b/drivers/gpu/drm/drm_privacy_screen.c
>> @@ -0,0 +1,403 @@
>> +// SPDX-License-Identifier: MIT
>> +/*
>> + * Copyright (C) 2020 - 2021 Red Hat, Inc.
>> + *
>> + * Authors:
>> + * Hans de Goede <hdegoede@redhat.com>
>> + */
>> +
>> +#include <linux/device.h>
>> +#include <linux/kernel.h>
>> +#include <linux/list.h>
>> +#include <linux/module.h>
>> +#include <linux/mutex.h>
>> +#include <linux/slab.h>
>> +#include <drm/drm_privacy_screen_machine.h>
>> +#include <drm/drm_privacy_screen_consumer.h>
>> +#include <drm/drm_privacy_screen_driver.h>
>> +#include "drm_internal.h"
>> +
>> +/**
>> + * DOC: overview
>> + *
>> + * This class allows non KMS drivers, from e.g. drivers/platform/x86 to
>> + * register a privacy-screen device, which the KMS drivers can then use
>> + * to implement the standard privacy-screen properties, see
>> + * :ref:`Standard Connector Properties<standard_connector_properties>`.
>> + *
>> + * KMS drivers using a privacy-screen class device are advised to use the
>> + * drm_connector_attach_privacy_screen_provider() and
>> + * drm_connector_update_privacy_screen() helpers for dealing with this.
>> + */
>> +
>> +#define to_drm_privacy_screen(dev) \
>> +	container_of(dev, struct drm_privacy_screen, dev)
>> +
>> +static DEFINE_MUTEX(drm_privacy_screen_lookup_lock);
>> +static LIST_HEAD(drm_privacy_screen_lookup_list);
>> +
>> +static DEFINE_MUTEX(drm_privacy_screen_devs_lock);
>> +static LIST_HEAD(drm_privacy_screen_devs);
>> +
>> +/*** drm_privacy_screen_machine.h functions ***/
>> +
>> +/**
>> + * drm_privacy_screen_lookup_add - add an entry to the static privacy-screen
>> + *    lookup list
>> + * @lookup: lookup list entry to add
>> + *
>> + * Add an entry to the static privacy-screen lookup list. Note the
>> + * &struct list_head which is part of the &struct drm_privacy_screen_lookup
>> + * gets added to a list owned by the privacy-screen core. So the passed in
>> + * &struct drm_privacy_screen_lookup must not be free-ed until it is removed
>> + * from the lookup list by calling drm_privacy_screen_lookup_remove().
>> + */
>> +void drm_privacy_screen_lookup_add(struct drm_privacy_screen_lookup *lookup)
>> +{
>> +	mutex_lock(&drm_privacy_screen_lookup_lock);
>> +	list_add(&lookup->list, &drm_privacy_screen_lookup_list);
>> +	mutex_unlock(&drm_privacy_screen_lookup_lock);
>> +}
>> +EXPORT_SYMBOL(drm_privacy_screen_lookup_add);
>> +
>> +/**
>> + * drm_privacy_screen_lookup_remove - remove an entry to the static
>> + *    privacy-screen lookup list
>> + * @lookup: lookup list entry to remove
>> + *
>> + * Remove an entry previously added with drm_privacy_screen_lookup_add()
>> + * from the static privacy-screen lookup list.
>> + */
>> +void drm_privacy_screen_lookup_remove(struct drm_privacy_screen_lookup *lookup)
>> +{
>> +	mutex_lock(&drm_privacy_screen_lookup_lock);
>> +	list_del(&lookup->list);
>> +	mutex_unlock(&drm_privacy_screen_lookup_lock);
>> +}
>> +EXPORT_SYMBOL(drm_privacy_screen_lookup_remove);
>> +
>> +/*** drm_privacy_screen_consumer.h functions ***/
>> +
>> +static struct drm_privacy_screen *drm_privacy_screen_get_by_name(
>> +	const char *name)
>> +{
>> +	struct drm_privacy_screen *priv;
>> +	struct device *dev = NULL;
>> +
>> +	mutex_lock(&drm_privacy_screen_devs_lock);
>> +
>> +	list_for_each_entry(priv, &drm_privacy_screen_devs, list) {
>> +		if (strcmp(dev_name(&priv->dev), name) == 0) {
>> +			dev = get_device(&priv->dev);
>> +			break;
>> +		}
>> +	}
>> +
>> +	mutex_unlock(&drm_privacy_screen_devs_lock);
>> +
>> +	return dev ? to_drm_privacy_screen(dev) : NULL;
>> +}
>> +
>> +/**
>> + * drm_privacy_screen_get - get a privacy-screen provider
>> + * @dev: consumer-device for which to get a privacy-screen provider
>> + * @con_id: (video)connector name for which to get a privacy-screen provider
>> + *
>> + * Get a privacy-screen provider for a privacy-screen attached to the
>> + * display described by the @dev and @con_id parameters.
>> + *
>> + * Return:
>> + * * A pointer to a &struct drm_privacy_screen on success.
>> + * * ERR_PTR(-ENODEV) if no matching privacy-screen is found
>> + * * ERR_PTR(-EPROBE_DEFER) if there is a matching privacy-screen,
>> + *                          but it has not been registered yet.
>> + */
>> +struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
>> +						  const char *con_id)
>> +{
>> +	const char *dev_id = dev ? dev_name(dev) : NULL;
>> +	struct drm_privacy_screen_lookup *l;
>> +	struct drm_privacy_screen *priv;
>> +	const char *provider = NULL;
>> +	int match, best = -1;
>> +
>> +	/*
>> +	 * For now we only support using a static lookup table, which is
>> +	 * populated by the drm_privacy_screen_arch_init() call. This should
>> +	 * be extended with device-tree / fw_node lookup when support is added
>> +	 * for device-tree using hardware with a privacy-screen.
>> +	 *
>> +	 * The lookup algorithm was shamelessly taken from the clock
>> +	 * framework:
>> +	 *
>> +	 * We do slightly fuzzy matching here:
>> +	 *  An entry with a NULL ID is assumed to be a wildcard.
>> +	 *  If an entry has a device ID, it must match
>> +	 *  If an entry has a connection ID, it must match
>> +	 * Then we take the most specific entry - with the following order
>> +	 * of precedence: dev+con > dev only > con only.
>> +	 */
>> +	mutex_lock(&drm_privacy_screen_lookup_lock);
>> +
>> +	list_for_each_entry(l, &drm_privacy_screen_lookup_list, list) {
>> +		match = 0;
>> +
>> +		if (l->dev_id) {
>> +			if (!dev_id || strcmp(l->dev_id, dev_id))
>> +				continue;
>> +
>> +			match += 2;
>> +		}
>> +
>> +		if (l->con_id) {
>> +			if (!con_id || strcmp(l->con_id, con_id))
>> +				continue;
>> +
>> +			match += 1;
>> +		}
>> +
>> +		if (match > best) {
>> +			provider = l->provider;
>> +			best = match;
>> +		}
>> +	}
>> +
>> +	mutex_unlock(&drm_privacy_screen_lookup_lock);
>> +
>> +	if (!provider)
>> +		return ERR_PTR(-ENODEV);
>> +
>> +	priv = drm_privacy_screen_get_by_name(provider);
>> +	if (!priv)
>> +		return ERR_PTR(-EPROBE_DEFER);
>> +
>> +	return priv;
>> +}
>> +EXPORT_SYMBOL(drm_privacy_screen_get);
>> +
>> +/**
>> + * drm_privacy_screen_put - release a privacy-screen reference
>> + * @priv: privacy screen reference to release
>> + *
>> + * Release a privacy-screen provider reference gotten through
>> + * drm_privacy_screen_get(). May be called with a NULL or ERR_PTR,
>> + * in which case it is a no-op.
>> + */
>> +void drm_privacy_screen_put(struct drm_privacy_screen *priv)
>> +{
>> +	if (IS_ERR_OR_NULL(priv))
>> +		return;
>> +
>> +	put_device(&priv->dev);
>> +}
>> +EXPORT_SYMBOL(drm_privacy_screen_put);
>> +
>> +/**
>> + * drm_privacy_screen_set_sw_state - set a privacy-screen's sw-state
>> + * @priv: privacy screen to set the sw-state for
>> + * @sw_state: new sw-state value to set
>> + *
>> + * Set the sw-state of a privacy screen. If the privacy-screen is not
>> + * in a locked hw-state, then the actual and hw-state of the privacy-screen
>> + * will be immediately updated to the new value. If the privacy-screen is
>> + * in a locked hw-state, then the new sw-state will be remembered as the
>> + * requested state to put the privacy-screen in when it becomes unlocked.
>> + *
>> + * Return: 0 on success, negative error code on failure.
>> + */
>> +int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
>> +				    enum drm_privacy_screen_status sw_state)
>> +{
>> +	int ret = 0;
>> +
>> +	mutex_lock(&priv->lock);
>> +
>> +	if (!priv->ops) {
>> +		ret = -ENODEV;
>> +		goto out;
>> +	}
>> +
>> +	/*
>> +	 * As per the DRM connector properties documentation, setting the
>> +	 * sw_state while the hw_state is locked is allowed. In this case
>> +	 * it is a no-op other then storing the new sw_state so that it
>> +	 * can be honored when the state gets unlocked.
>> +	 * Also skip the set if the hw already is in the desired state.
>> +	 */
>> +	if (priv->hw_state >= PRIVACY_SCREEN_DISABLED_LOCKED ||
>> +	    priv->hw_state == sw_state) {
>> +		priv->sw_state = sw_state;
>> +		goto out;
>> +	}
>> +
>> +	ret = priv->ops->set_sw_state(priv, sw_state);
>> +out:
>> +	mutex_unlock(&priv->lock);
>> +	return ret;
>> +}
>> +EXPORT_SYMBOL(drm_privacy_screen_set_sw_state);
>> +
>> +/**
>> + * drm_privacy_screen_get_state - get privacy-screen's current state
>> + * @priv: privacy screen to get the state for
>> + * @sw_state_ret: address where to store the privacy-screens current sw-state
>> + * @hw_state_ret: address where to store the privacy-screens current hw-state
>> + *
>> + * Get the current state of a privacy-screen, both the sw-state and the
>> + * hw-state.
>> + */
>> +void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
>> +				  enum drm_privacy_screen_status *sw_state_ret,
>> +				  enum drm_privacy_screen_status *hw_state_ret)
>> +{
>> +	mutex_lock(&priv->lock);
>> +	*sw_state_ret = priv->sw_state;
>> +	*hw_state_ret = priv->hw_state;
>> +	mutex_unlock(&priv->lock);
>> +}
>> +EXPORT_SYMBOL(drm_privacy_screen_get_state);
>> +
>> +/*** drm_privacy_screen_driver.h functions ***/
>> +
>> +static ssize_t sw_state_show(struct device *dev,
>> +			     struct device_attribute *attr, char *buf)
>> +{
>> +	struct drm_privacy_screen *priv = to_drm_privacy_screen(dev);
>> +	const char * const sw_state_names[] = {
>> +		"Disabled",
>> +		"Enabled",
>> +	};
>> +	ssize_t ret;
>> +
>> +	mutex_lock(&priv->lock);
>> +
>> +	if (!priv->ops)
>> +		ret = -ENODEV;
>> +	else if (WARN_ON(priv->sw_state >= ARRAY_SIZE(sw_state_names)))
>> +		ret = -ENXIO;
>> +	else
>> +		ret = sprintf(buf, "%s\n", sw_state_names[priv->sw_state]);
>> +
>> +	mutex_unlock(&priv->lock);
>> +	return ret;
>> +}
>> +/*
>> + * RO: Do not allow setting the sw_state through sysfs, this MUST be done
>> + * through the drm_properties on the drm_connector.
>> + */
>> +static DEVICE_ATTR_RO(sw_state);
>> +
>> +static ssize_t hw_state_show(struct device *dev,
>> +			     struct device_attribute *attr, char *buf)
>> +{
>> +	struct drm_privacy_screen *priv = to_drm_privacy_screen(dev);
>> +	const char * const hw_state_names[] = {
>> +		"Disabled",
>> +		"Enabled",
>> +		"Disabled, locked",
>> +		"Enabled, locked",
>> +	};
>> +	ssize_t ret;
>> +
>> +	mutex_lock(&priv->lock);
>> +
>> +	if (!priv->ops)
>> +		ret = -ENODEV;
>> +	else if (WARN_ON(priv->hw_state >= ARRAY_SIZE(hw_state_names)))
>> +		ret = -ENXIO;
>> +	else
>> +		ret = sprintf(buf, "%s\n", hw_state_names[priv->hw_state]);
>> +
>> +	mutex_unlock(&priv->lock);
>> +	return ret;
>> +}
>> +static DEVICE_ATTR_RO(hw_state);
>> +
>> +static struct attribute *drm_privacy_screen_attrs[] = {
>> +	&dev_attr_sw_state.attr,
>> +	&dev_attr_hw_state.attr,
>> +	NULL
>> +};
>> +ATTRIBUTE_GROUPS(drm_privacy_screen);
>> +
>> +static struct device_type drm_privacy_screen_type = {
>> +	.name = "privacy_screen",
>> +	.groups = drm_privacy_screen_groups,
>> +};
>> +
>> +static void drm_privacy_screen_device_release(struct device *dev)
>> +{
>> +	struct drm_privacy_screen *priv = to_drm_privacy_screen(dev);
>> +
>> +	kfree(priv);
>> +}
>> +
>> +/**
>> + * drm_privacy_screen_register - register a privacy-screen
>> + * @parent: parent-device for the privacy-screen
>> + * @ops: &struct drm_privacy_screen_ops pointer with ops for the privacy-screen
>> + *
>> + * Create and register a privacy-screen.
>> + *
>> + * Return:
>> + * * A pointer to the created privacy-screen on success.
>> + * * 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 drm_privacy_screen *priv;
>> +	int ret;
>> +
>> +	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
>> +	if (!priv)
>> +		return ERR_PTR(-ENOMEM);
>> +
>> +	mutex_init(&priv->lock);
>> +
>> +	priv->dev.class = drm_class;
>> +	priv->dev.type = &drm_privacy_screen_type;
>> +	priv->dev.parent = parent;
>> +	priv->dev.release = drm_privacy_screen_device_release;
>> +	dev_set_name(&priv->dev, "privacy_screen-%s", dev_name(parent));
>> +	priv->ops = ops;
>> +
>> +	priv->ops->get_hw_state(priv);
>> +
>> +	ret = device_register(&priv->dev);
>> +	if (ret) {
>> +		put_device(&priv->dev);
>> +		return ERR_PTR(ret);
>> +	}
>> +
>> +	mutex_lock(&drm_privacy_screen_devs_lock);
>> +	list_add(&priv->list, &drm_privacy_screen_devs);
>> +	mutex_unlock(&drm_privacy_screen_devs_lock);
>> +
>> +	return priv;
>> +}
>> +EXPORT_SYMBOL(drm_privacy_screen_register);
>> +
>> +/**
>> + * drm_privacy_screen_unregister - unregister privacy-screen
>> + * @priv: privacy-screen to unregister
>> + *
>> + * Unregister a privacy-screen registered with drm_privacy_screen_register().
>> + * May be called with a NULL or ERR_PTR, in which case it is a no-op.
>> + */
>> +void drm_privacy_screen_unregister(struct drm_privacy_screen *priv)
>> +{
>> +	if (IS_ERR_OR_NULL(priv))
>> +		return;
>> +
>> +	mutex_lock(&drm_privacy_screen_devs_lock);
>> +	list_del(&priv->list);
>> +	mutex_unlock(&drm_privacy_screen_devs_lock);
>> +
>> +	mutex_lock(&priv->lock);
>> +	priv->ops = NULL;
>> +	mutex_unlock(&priv->lock);
>> +
>> +	device_unregister(&priv->dev);
>> +}
>> +EXPORT_SYMBOL(drm_privacy_screen_unregister);
>> diff --git a/include/drm/drm_privacy_screen_consumer.h b/include/drm/drm_privacy_screen_consumer.h
>> new file mode 100644
>> index 000000000000..0cbd23b0453d
>> --- /dev/null
>> +++ b/include/drm/drm_privacy_screen_consumer.h
>> @@ -0,0 +1,50 @@
>> +/* SPDX-License-Identifier: MIT */
>> +/*
>> + * Copyright (C) 2020 Red Hat, Inc.
>> + *
>> + * Authors:
>> + * Hans de Goede <hdegoede@redhat.com>
>> + */
>> +
>> +#ifndef __DRM_PRIVACY_SCREEN_CONSUMER_H__
>> +#define __DRM_PRIVACY_SCREEN_CONSUMER_H__
>> +
>> +#include <linux/device.h>
>> +#include <drm/drm_connector.h>
>> +
>> +struct drm_privacy_screen;
>> +
>> +#if IS_ENABLED(CONFIG_DRM_PRIVACY_SCREEN)
>> +struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
>> +						  const char *con_id);
>> +void drm_privacy_screen_put(struct drm_privacy_screen *priv);
>> +
>> +int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
>> +				    enum drm_privacy_screen_status sw_state);
>> +void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
>> +				  enum drm_privacy_screen_status *sw_state_ret,
>> +				  enum drm_privacy_screen_status *hw_state_ret);
>> +#else
>> +static inline struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
>> +								const char *con_id)
>> +{
>> +	return ERR_PTR(-ENODEV);
>> +}
>> +static inline void drm_privacy_screen_put(struct drm_privacy_screen *priv)
>> +{
>> +}
>> +static inline int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
>> +						  enum drm_privacy_screen_status sw_state)
>> +{
>> +	return -ENODEV;
>> +}
>> +static inline void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
>> +						enum drm_privacy_screen_status *sw_state_ret,
>> +						enum drm_privacy_screen_status *hw_state_ret)
>> +{
>> +	*sw_state_ret = PRIVACY_SCREEN_DISABLED;
>> +	*hw_state_ret = PRIVACY_SCREEN_DISABLED;
>> +}
>> +#endif
>> +
>> +#endif
>> diff --git a/include/drm/drm_privacy_screen_driver.h b/include/drm/drm_privacy_screen_driver.h
>> new file mode 100644
>> index 000000000000..5187ae52eb03
>> --- /dev/null
>> +++ b/include/drm/drm_privacy_screen_driver.h
>> @@ -0,0 +1,80 @@
>> +/* SPDX-License-Identifier: MIT */
>> +/*
>> + * Copyright (C) 2020 Red Hat, Inc.
>> + *
>> + * Authors:
>> + * Hans de Goede <hdegoede@redhat.com>
>> + */
>> +
>> +#ifndef __DRM_PRIVACY_SCREEN_DRIVER_H__
>> +#define __DRM_PRIVACY_SCREEN_DRIVER_H__
>> +
>> +#include <linux/device.h>
>> +#include <linux/list.h>
>> +#include <linux/mutex.h>
>> +#include <drm/drm_connector.h>
>> +
>> +struct drm_privacy_screen;
>> +
>> +/**
>> + * struct drm_privacy_screen_ops - drm_privacy_screen operations
>> + *
>> + * Defines the operations which the privacy-screen class code may call.
>> + * These functions should be implemented by the privacy-screen driver.
>> + */
>> +struct drm_privacy_screen_ops {
>> +	/**
>> +	 * @set_sw_state: Called to request a change of the privacy-screen
>> +	 * state. The privacy-screen class code contains a check to avoid this
>> +	 * getting called when the hw_state reports the state is locked.
>> +	 * It is the driver's responsibility to update sw_state and hw_state.
>> +	 * This is always called with the drm_privacy_screen's lock held.
>> +	 */
>> +	int (*set_sw_state)(struct drm_privacy_screen *priv,
>> +			    enum drm_privacy_screen_status sw_state);
>> +	/**
>> +	 * @get_hw_state: Called to request that the driver gets the current
>> +	 * privacy-screen state from the hardware and then updates sw_state and
>> +	 * hw_state accordingly. This will be called by the core just before
>> +	 * the privacy-screen is registered in sysfs.
>> +	 */
>> +	void (*get_hw_state)(struct drm_privacy_screen *priv);
>> +};
>> +
>> +/**
>> + * struct drm_privacy_screen - central privacy-screen structure
>> + *
>> + * Central privacy-screen structure, this contains the struct device used
>> + * to register the screen in sysfs, the screen's state, ops, etc.
>> + */
>> +struct drm_privacy_screen {
>> +	/** @dev: device used to register the privacy-screen in sysfs. */
>> +	struct device dev;
>> +	/** @lock: mutex protection all fields in this struct. */
>> +	struct mutex lock;
>> +	/** @list: privacy-screen devices list list-entry. */
>> +	struct list_head list;
>> +	/**
>> +	 * @ops: &struct drm_privacy_screen_ops for this privacy-screen.
>> +	 * This is NULL if the driver has unregistered the privacy-screen.
>> +	 */
>> +	const struct drm_privacy_screen_ops *ops;
>> +	/**
>> +	 * @sw_state: The privacy-screen's software state, see
>> +	 * :ref:`Standard Connector Properties<standard_connector_properties>`
>> +	 * for more info.
>> +	 */
>> +	enum drm_privacy_screen_status sw_state;
>> +	/**
>> +	 * @hw_state: The privacy-screen's hardware state, see
>> +	 * :ref:`Standard Connector Properties<standard_connector_properties>`
>> +	 * for more info.
>> +	 */
>> +	enum drm_privacy_screen_status hw_state;
>> +};
>> +
>> +struct drm_privacy_screen *drm_privacy_screen_register(
>> +	struct device *parent, const struct drm_privacy_screen_ops *ops);
>> +void drm_privacy_screen_unregister(struct drm_privacy_screen *priv);
>> +
>> +#endif
>> diff --git a/include/drm/drm_privacy_screen_machine.h b/include/drm/drm_privacy_screen_machine.h
>> new file mode 100644
>> index 000000000000..aaa0d38cce92
>> --- /dev/null
>> +++ b/include/drm/drm_privacy_screen_machine.h
>> @@ -0,0 +1,41 @@
>> +/* SPDX-License-Identifier: MIT */
>> +/*
>> + * Copyright (C) 2020 Red Hat, Inc.
>> + *
>> + * Authors:
>> + * Hans de Goede <hdegoede@redhat.com>
>> + */
>> +
>> +#ifndef __DRM_PRIVACY_SCREEN_MACHINE_H__
>> +#define __DRM_PRIVACY_SCREEN_MACHINE_H__
>> +
>> +#include <linux/list.h>
>> +
>> +/**
>> + * struct drm_privacy_screen_lookup -  static privacy-screen lookup list entry
>> + *
>> + * Used for the static lookup-list for mapping privacy-screen consumer
>> + * dev-connector pairs to a privacy-screen provider.
>> + */
>> +struct drm_privacy_screen_lookup {
>> +	/** @list: Lookup list list-entry. */
>> +	struct list_head list;
>> +	/** @dev_id: Consumer device name or NULL to match all devices. */
>> +	const char *dev_id;
>> +	/** @con_id: Consumer connector name or NULL to match all connectors. */
>> +	const char *con_id;
>> +	/** @provider: dev_name() of the privacy_screen provider. */
>> +	const char *provider;
>> +};
>> +
>> +void drm_privacy_screen_lookup_add(struct drm_privacy_screen_lookup *lookup);
>> +void drm_privacy_screen_lookup_remove(struct drm_privacy_screen_lookup *lookup);
>> +
>> +static inline void drm_privacy_screen_lookup_init(void)
>> +{
>> +}
>> +static inline void drm_privacy_screen_lookup_exit(void)
>> +{
>> +}
>> +
>> +#endif
>>
> 


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 02/10] drm: Add privacy-screen class (v4)
  2021-12-10 10:46     ` Hans de Goede
@ 2021-12-10 11:22       ` Thorsten Leemhuis
  0 siblings, 0 replies; 24+ messages in thread
From: Thorsten Leemhuis @ 2021-12-10 11:22 UTC (permalink / raw)
  To: Hans de Goede, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, Rajat Jain, Jani Nikula, Lyude,
	Joonas Lahtinen, Rodrigo Vivi, Ville Syrjälä,
	Mark Gross, Andy Shevchenko
  Cc: Daniel Vetter, David Airlie, Pekka Paalanen, Mario Limonciello,
	Mark Pearson, Sebastien Bacher, Marco Trevisan, Emil Velikov,
	intel-gfx, dri-devel, platform-driver-x86

On 10.12.21 11:46, Hans de Goede wrote:
> On 12/10/21 11:12, Thorsten Leemhuis wrote:
>> Hi, this is your Linux kernel regression tracker speaking.
>>
>> Top-posting for once, to make this easy accessible to everyone.
>>
>> Hans, I stumbled upon your blog post about something that afaics is
>> related to below patch:
>> https://hansdegoede.livejournal.com/25948.html
>>
>> To quote:
>>
>>> To avoid any regressions distors should modify their initrd
>>> generation tools to include privacy screen provider drivers in the
>>> initrd (at least on systems with a privacy screen), before 5.17
>>> kernels start showing up in their repos.
>>>
>>> If this change is not made, then users using a graphical bootsplash
>>> (plymouth) will get an extra boot-delay of up to 8 seconds
>>> (DeviceTimeout in plymouthd.defaults) before plymouth will show and
>>> when using disk-encryption where the LUKS password is requested from
>>> the initrd, the system will fallback to text-mode after these 8
>>> seconds.
>>
>> Sorry for intruding, but to me as the kernel's regression tracker that
>> blog post sounds a whole lot like "by kernel development standards this
>> is not allowed due to the 'no regression rule', as users should never be
>> required to update something in userspace when updating the kernel".
> 
> I completely understand where you are coming from here, but AFAIK
> the initrd generation has always been a bit of an exception here.

Many thx for the clarification. Yeah, kinda, but it afaics also partly
depends on what kind of breakage users have to endure -- which according
to the description is not that bad in this case, so I guess in this case
everything is fine as it is.

Again, thx for your answer.

Ciao, Thorsten

> For example (IIRC) over time we have seen the radeon module growing
> a runtime dependency on the amdkfd module which also required updated
> initrd generation tools.
> 
> Another example (which I'm sure of) is the i915 driver gaining a softdep
> on kvmgt (which is now gone again) which required new enough kmod tools
> to understand this as well as initrd generation tools updates to also
> take softdeps into account:
> https://github.com/dracutdevs/dracut/commit/4cdee66c8ed5f82bbd0638e30d867318343b0e6c
> 
> More in general if you look at e.g. dracut's git history, there are
> various other cases where dracut needed to be updated to adjust
> to kernel changes. For example dracut decides if a module is a block
> driver and thus may be necessary to have in the initrd based on a
> list of kernel-symbols the module links to and sometimes those
> symbols change due to refactoring of kernel internals, see e.g. :
> https://github.com/dracutdevs/dracut/commit/b292ce7295f18192124e64e5ec31161d09492160
> 
> TL;DR: initrd-generators and the kernel are simply tied together so much
> that users cannot expect to be able to jump to the latest kernel without
> either updating the initrd-generator, or adding some modules as modules
> which must always be added to the initrd in the initrd-generator config
> file (as a workaround).
> 
> Declaring kernel changes which break initrd-generation in some way as
> being regressions, would mean that e.g. we cannot introduce any
> kernel changes which causes some drm/block/whatever drivers to use
> some new register helper functions which are not yet on the list of
> symbols which dracut uses to identify drm/block/whatever drivers.
> 
> The only difference between previous initrd-generator breaking changes
> and this one, is that I decided that it would be good for everyone
> to be aware of this before hand; and now I get the feeling that I'm
> being punished for warning people about this instead of just letting
> things break silently. I know you don't intend your email this way in
> any way, but still.
> 
> Also AFAIK drivers may also at some point drop support for (much) older
> firmware versions requiring installing a recent linux-firmware together
> with a new kernel.
> 
> In my reading of the rules the 'users should never be required to update
> something in userspace when updating the kernel' rule is about keeping
> people's normal programs working, IOW not breaking userspace ABI and that
> is not happening here.
> 
>> But I'm not totally sure that's the case here. Could you please clarify
>> what happens when a user doesn't update the initramfs. E.g. what happens
>> besides the mentioned delay and the text mode (which are bad already,
>> but might be a accetable compormise here -- but that's up for Linus to
>> decide)? Does everything start to work normally shortly after the kernel
>> mounted the rootfs and finally can load the missing module?
> 
> Yes everything will work normally once the rootfs gets mounted and the
> missing module gets loaded.
> 
> Regards,
> 
> Hans
> 
> 
> 
>> On 05.10.21 22:23, Hans de Goede wrote:
>>> On some new laptops the LCD panel has a builtin electronic privacy-screen.
>>> We want to export this functionality as a property on the drm connector
>>> object. But often this functionality is not exposed on the GPU but on some
>>> other (ACPI) device.
>>>
>>> This commit adds a privacy-screen class allowing the driver for these
>>> other devices to register themselves as a privacy-screen provider; and
>>> allowing the drm/kms code to get a privacy-screen provider associated
>>> with a specific GPU/connector combo.
>>>
>>> Changes in v2:
>>> - Make CONFIG_DRM_PRIVACY_SCREEN a bool which controls if the drm_privacy
>>>   code gets built as part of the main drm module rather then making it
>>>   a tristate which builds its own module.
>>> - Add a #if IS_ENABLED(CONFIG_DRM_PRIVACY_SCREEN) check to
>>>   drm_privacy_screen_consumer.h and define stubs when the check fails.
>>>   Together these 2 changes fix several dependency issues.
>>> - Remove module related code now that this is part of the main drm.ko
>>> - Use drm_class as class for the privacy-screen devices instead of
>>>   adding a separate class for this
>>>
>>> Changes in v3:
>>> - Make the static inline drm_privacy_screen_get_state() stub set sw_state
>>>   and hw_state to PRIVACY_SCREEN_DISABLED to squelch an uninitialized
>>>   variable warning when CONFIG_DRM_PRIVICAY_SCREEN is not set
>>>
>>> Changes in v4:
>>> - Make drm_privacy_screen_set_sw_state() skip calling out to the hw if
>>>   hw_state == new_sw_state
>>>
>>> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
>>> Reviewed-by: Lyude Paul <lyude@redhat.com>
>>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>>> ---
>>>  Documentation/gpu/drm-kms-helpers.rst     |  15 +
>>>  MAINTAINERS                               |   8 +
>>>  drivers/gpu/drm/Kconfig                   |   4 +
>>>  drivers/gpu/drm/Makefile                  |   1 +
>>>  drivers/gpu/drm/drm_drv.c                 |   4 +
>>>  drivers/gpu/drm/drm_privacy_screen.c      | 403 ++++++++++++++++++++++
>>>  include/drm/drm_privacy_screen_consumer.h |  50 +++
>>>  include/drm/drm_privacy_screen_driver.h   |  80 +++++
>>>  include/drm/drm_privacy_screen_machine.h  |  41 +++
>>>  9 files changed, 606 insertions(+)
>>>  create mode 100644 drivers/gpu/drm/drm_privacy_screen.c
>>>  create mode 100644 include/drm/drm_privacy_screen_consumer.h
>>>  create mode 100644 include/drm/drm_privacy_screen_driver.h
>>>  create mode 100644 include/drm/drm_privacy_screen_machine.h
>>>
>>> diff --git a/Documentation/gpu/drm-kms-helpers.rst b/Documentation/gpu/drm-kms-helpers.rst
>>> index ec2f65b31930..5bb55ec1b9b5 100644
>>> --- a/Documentation/gpu/drm-kms-helpers.rst
>>> +++ b/Documentation/gpu/drm-kms-helpers.rst
>>> @@ -435,3 +435,18 @@ Legacy CRTC/Modeset Helper Functions Reference
>>>  
>>>  .. kernel-doc:: drivers/gpu/drm/drm_crtc_helper.c
>>>     :export:
>>> +
>>> +Privacy-screen class
>>> +====================
>>> +
>>> +.. kernel-doc:: drivers/gpu/drm/drm_privacy_screen.c
>>> +   :doc: overview
>>> +
>>> +.. kernel-doc:: include/drm/drm_privacy_screen_driver.h
>>> +   :internal:
>>> +
>>> +.. kernel-doc:: include/drm/drm_privacy_screen_machine.h
>>> +   :internal:
>>> +
>>> +.. kernel-doc:: drivers/gpu/drm/drm_privacy_screen.c
>>> +   :export:
>>> diff --git a/MAINTAINERS b/MAINTAINERS
>>> index 28e5f0ae1009..cb94bb3b8724 100644
>>> --- a/MAINTAINERS
>>> +++ b/MAINTAINERS
>>> @@ -6423,6 +6423,14 @@ F:	drivers/gpu/drm/drm_panel.c
>>>  F:	drivers/gpu/drm/panel/
>>>  F:	include/drm/drm_panel.h
>>>  
>>> +DRM PRIVACY-SCREEN CLASS
>>> +M:	Hans de Goede <hdegoede@redhat.com>
>>> +L:	dri-devel@lists.freedesktop.org
>>> +S:	Maintained
>>> +T:	git git://anongit.freedesktop.org/drm/drm-misc
>>> +F:	drivers/gpu/drm/drm_privacy_screen*
>>> +F:	include/drm/drm_privacy_screen*
>>> +
>>>  DRM TTM SUBSYSTEM
>>>  M:	Christian Koenig <christian.koenig@amd.com>
>>>  M:	Huang Rui <ray.huang@amd.com>
>>> diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
>>> index 2a926d0de423..c686c08447ac 100644
>>> --- a/drivers/gpu/drm/Kconfig
>>> +++ b/drivers/gpu/drm/Kconfig
>>> @@ -481,3 +481,7 @@ config DRM_PANEL_ORIENTATION_QUIRKS
>>>  config DRM_LIB_RANDOM
>>>  	bool
>>>  	default n
>>> +
>>> +config DRM_PRIVACY_SCREEN
>>> +	bool
>>> +	default n
>>> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
>>> index 0dff40bb863c..788fc37096f6 100644
>>> --- a/drivers/gpu/drm/Makefile
>>> +++ b/drivers/gpu/drm/Makefile
>>> @@ -32,6 +32,7 @@ drm-$(CONFIG_OF) += drm_of.o
>>>  drm-$(CONFIG_PCI) += drm_pci.o
>>>  drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
>>>  drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
>>> +drm-$(CONFIG_DRM_PRIVACY_SCREEN) += drm_privacy_screen.o
>>>  
>>>  obj-$(CONFIG_DRM_DP_AUX_BUS) += drm_dp_aux_bus.o
>>>  
>>> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
>>> index 7a5097467ba5..dc293b771c3f 100644
>>> --- a/drivers/gpu/drm/drm_drv.c
>>> +++ b/drivers/gpu/drm/drm_drv.c
>>> @@ -43,6 +43,7 @@
>>>  #include <drm/drm_managed.h>
>>>  #include <drm/drm_mode_object.h>
>>>  #include <drm/drm_print.h>
>>> +#include <drm/drm_privacy_screen_machine.h>
>>>  
>>>  #include "drm_crtc_internal.h"
>>>  #include "drm_internal.h"
>>> @@ -1029,6 +1030,7 @@ static const struct file_operations drm_stub_fops = {
>>>  
>>>  static void drm_core_exit(void)
>>>  {
>>> +	drm_privacy_screen_lookup_exit();
>>>  	unregister_chrdev(DRM_MAJOR, "drm");
>>>  	debugfs_remove(drm_debugfs_root);
>>>  	drm_sysfs_destroy();
>>> @@ -1056,6 +1058,8 @@ static int __init drm_core_init(void)
>>>  	if (ret < 0)
>>>  		goto error;
>>>  
>>> +	drm_privacy_screen_lookup_init();
>>> +
>>>  	drm_core_init_complete = true;
>>>  
>>>  	DRM_DEBUG("Initialized\n");
>>> diff --git a/drivers/gpu/drm/drm_privacy_screen.c b/drivers/gpu/drm/drm_privacy_screen.c
>>> new file mode 100644
>>> index 000000000000..183a6011adf0
>>> --- /dev/null
>>> +++ b/drivers/gpu/drm/drm_privacy_screen.c
>>> @@ -0,0 +1,403 @@
>>> +// SPDX-License-Identifier: MIT
>>> +/*
>>> + * Copyright (C) 2020 - 2021 Red Hat, Inc.
>>> + *
>>> + * Authors:
>>> + * Hans de Goede <hdegoede@redhat.com>
>>> + */
>>> +
>>> +#include <linux/device.h>
>>> +#include <linux/kernel.h>
>>> +#include <linux/list.h>
>>> +#include <linux/module.h>
>>> +#include <linux/mutex.h>
>>> +#include <linux/slab.h>
>>> +#include <drm/drm_privacy_screen_machine.h>
>>> +#include <drm/drm_privacy_screen_consumer.h>
>>> +#include <drm/drm_privacy_screen_driver.h>
>>> +#include "drm_internal.h"
>>> +
>>> +/**
>>> + * DOC: overview
>>> + *
>>> + * This class allows non KMS drivers, from e.g. drivers/platform/x86 to
>>> + * register a privacy-screen device, which the KMS drivers can then use
>>> + * to implement the standard privacy-screen properties, see
>>> + * :ref:`Standard Connector Properties<standard_connector_properties>`.
>>> + *
>>> + * KMS drivers using a privacy-screen class device are advised to use the
>>> + * drm_connector_attach_privacy_screen_provider() and
>>> + * drm_connector_update_privacy_screen() helpers for dealing with this.
>>> + */
>>> +
>>> +#define to_drm_privacy_screen(dev) \
>>> +	container_of(dev, struct drm_privacy_screen, dev)
>>> +
>>> +static DEFINE_MUTEX(drm_privacy_screen_lookup_lock);
>>> +static LIST_HEAD(drm_privacy_screen_lookup_list);
>>> +
>>> +static DEFINE_MUTEX(drm_privacy_screen_devs_lock);
>>> +static LIST_HEAD(drm_privacy_screen_devs);
>>> +
>>> +/*** drm_privacy_screen_machine.h functions ***/
>>> +
>>> +/**
>>> + * drm_privacy_screen_lookup_add - add an entry to the static privacy-screen
>>> + *    lookup list
>>> + * @lookup: lookup list entry to add
>>> + *
>>> + * Add an entry to the static privacy-screen lookup list. Note the
>>> + * &struct list_head which is part of the &struct drm_privacy_screen_lookup
>>> + * gets added to a list owned by the privacy-screen core. So the passed in
>>> + * &struct drm_privacy_screen_lookup must not be free-ed until it is removed
>>> + * from the lookup list by calling drm_privacy_screen_lookup_remove().
>>> + */
>>> +void drm_privacy_screen_lookup_add(struct drm_privacy_screen_lookup *lookup)
>>> +{
>>> +	mutex_lock(&drm_privacy_screen_lookup_lock);
>>> +	list_add(&lookup->list, &drm_privacy_screen_lookup_list);
>>> +	mutex_unlock(&drm_privacy_screen_lookup_lock);
>>> +}
>>> +EXPORT_SYMBOL(drm_privacy_screen_lookup_add);
>>> +
>>> +/**
>>> + * drm_privacy_screen_lookup_remove - remove an entry to the static
>>> + *    privacy-screen lookup list
>>> + * @lookup: lookup list entry to remove
>>> + *
>>> + * Remove an entry previously added with drm_privacy_screen_lookup_add()
>>> + * from the static privacy-screen lookup list.
>>> + */
>>> +void drm_privacy_screen_lookup_remove(struct drm_privacy_screen_lookup *lookup)
>>> +{
>>> +	mutex_lock(&drm_privacy_screen_lookup_lock);
>>> +	list_del(&lookup->list);
>>> +	mutex_unlock(&drm_privacy_screen_lookup_lock);
>>> +}
>>> +EXPORT_SYMBOL(drm_privacy_screen_lookup_remove);
>>> +
>>> +/*** drm_privacy_screen_consumer.h functions ***/
>>> +
>>> +static struct drm_privacy_screen *drm_privacy_screen_get_by_name(
>>> +	const char *name)
>>> +{
>>> +	struct drm_privacy_screen *priv;
>>> +	struct device *dev = NULL;
>>> +
>>> +	mutex_lock(&drm_privacy_screen_devs_lock);
>>> +
>>> +	list_for_each_entry(priv, &drm_privacy_screen_devs, list) {
>>> +		if (strcmp(dev_name(&priv->dev), name) == 0) {
>>> +			dev = get_device(&priv->dev);
>>> +			break;
>>> +		}
>>> +	}
>>> +
>>> +	mutex_unlock(&drm_privacy_screen_devs_lock);
>>> +
>>> +	return dev ? to_drm_privacy_screen(dev) : NULL;
>>> +}
>>> +
>>> +/**
>>> + * drm_privacy_screen_get - get a privacy-screen provider
>>> + * @dev: consumer-device for which to get a privacy-screen provider
>>> + * @con_id: (video)connector name for which to get a privacy-screen provider
>>> + *
>>> + * Get a privacy-screen provider for a privacy-screen attached to the
>>> + * display described by the @dev and @con_id parameters.
>>> + *
>>> + * Return:
>>> + * * A pointer to a &struct drm_privacy_screen on success.
>>> + * * ERR_PTR(-ENODEV) if no matching privacy-screen is found
>>> + * * ERR_PTR(-EPROBE_DEFER) if there is a matching privacy-screen,
>>> + *                          but it has not been registered yet.
>>> + */
>>> +struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
>>> +						  const char *con_id)
>>> +{
>>> +	const char *dev_id = dev ? dev_name(dev) : NULL;
>>> +	struct drm_privacy_screen_lookup *l;
>>> +	struct drm_privacy_screen *priv;
>>> +	const char *provider = NULL;
>>> +	int match, best = -1;
>>> +
>>> +	/*
>>> +	 * For now we only support using a static lookup table, which is
>>> +	 * populated by the drm_privacy_screen_arch_init() call. This should
>>> +	 * be extended with device-tree / fw_node lookup when support is added
>>> +	 * for device-tree using hardware with a privacy-screen.
>>> +	 *
>>> +	 * The lookup algorithm was shamelessly taken from the clock
>>> +	 * framework:
>>> +	 *
>>> +	 * We do slightly fuzzy matching here:
>>> +	 *  An entry with a NULL ID is assumed to be a wildcard.
>>> +	 *  If an entry has a device ID, it must match
>>> +	 *  If an entry has a connection ID, it must match
>>> +	 * Then we take the most specific entry - with the following order
>>> +	 * of precedence: dev+con > dev only > con only.
>>> +	 */
>>> +	mutex_lock(&drm_privacy_screen_lookup_lock);
>>> +
>>> +	list_for_each_entry(l, &drm_privacy_screen_lookup_list, list) {
>>> +		match = 0;
>>> +
>>> +		if (l->dev_id) {
>>> +			if (!dev_id || strcmp(l->dev_id, dev_id))
>>> +				continue;
>>> +
>>> +			match += 2;
>>> +		}
>>> +
>>> +		if (l->con_id) {
>>> +			if (!con_id || strcmp(l->con_id, con_id))
>>> +				continue;
>>> +
>>> +			match += 1;
>>> +		}
>>> +
>>> +		if (match > best) {
>>> +			provider = l->provider;
>>> +			best = match;
>>> +		}
>>> +	}
>>> +
>>> +	mutex_unlock(&drm_privacy_screen_lookup_lock);
>>> +
>>> +	if (!provider)
>>> +		return ERR_PTR(-ENODEV);
>>> +
>>> +	priv = drm_privacy_screen_get_by_name(provider);
>>> +	if (!priv)
>>> +		return ERR_PTR(-EPROBE_DEFER);
>>> +
>>> +	return priv;
>>> +}
>>> +EXPORT_SYMBOL(drm_privacy_screen_get);
>>> +
>>> +/**
>>> + * drm_privacy_screen_put - release a privacy-screen reference
>>> + * @priv: privacy screen reference to release
>>> + *
>>> + * Release a privacy-screen provider reference gotten through
>>> + * drm_privacy_screen_get(). May be called with a NULL or ERR_PTR,
>>> + * in which case it is a no-op.
>>> + */
>>> +void drm_privacy_screen_put(struct drm_privacy_screen *priv)
>>> +{
>>> +	if (IS_ERR_OR_NULL(priv))
>>> +		return;
>>> +
>>> +	put_device(&priv->dev);
>>> +}
>>> +EXPORT_SYMBOL(drm_privacy_screen_put);
>>> +
>>> +/**
>>> + * drm_privacy_screen_set_sw_state - set a privacy-screen's sw-state
>>> + * @priv: privacy screen to set the sw-state for
>>> + * @sw_state: new sw-state value to set
>>> + *
>>> + * Set the sw-state of a privacy screen. If the privacy-screen is not
>>> + * in a locked hw-state, then the actual and hw-state of the privacy-screen
>>> + * will be immediately updated to the new value. If the privacy-screen is
>>> + * in a locked hw-state, then the new sw-state will be remembered as the
>>> + * requested state to put the privacy-screen in when it becomes unlocked.
>>> + *
>>> + * Return: 0 on success, negative error code on failure.
>>> + */
>>> +int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
>>> +				    enum drm_privacy_screen_status sw_state)
>>> +{
>>> +	int ret = 0;
>>> +
>>> +	mutex_lock(&priv->lock);
>>> +
>>> +	if (!priv->ops) {
>>> +		ret = -ENODEV;
>>> +		goto out;
>>> +	}
>>> +
>>> +	/*
>>> +	 * As per the DRM connector properties documentation, setting the
>>> +	 * sw_state while the hw_state is locked is allowed. In this case
>>> +	 * it is a no-op other then storing the new sw_state so that it
>>> +	 * can be honored when the state gets unlocked.
>>> +	 * Also skip the set if the hw already is in the desired state.
>>> +	 */
>>> +	if (priv->hw_state >= PRIVACY_SCREEN_DISABLED_LOCKED ||
>>> +	    priv->hw_state == sw_state) {
>>> +		priv->sw_state = sw_state;
>>> +		goto out;
>>> +	}
>>> +
>>> +	ret = priv->ops->set_sw_state(priv, sw_state);
>>> +out:
>>> +	mutex_unlock(&priv->lock);
>>> +	return ret;
>>> +}
>>> +EXPORT_SYMBOL(drm_privacy_screen_set_sw_state);
>>> +
>>> +/**
>>> + * drm_privacy_screen_get_state - get privacy-screen's current state
>>> + * @priv: privacy screen to get the state for
>>> + * @sw_state_ret: address where to store the privacy-screens current sw-state
>>> + * @hw_state_ret: address where to store the privacy-screens current hw-state
>>> + *
>>> + * Get the current state of a privacy-screen, both the sw-state and the
>>> + * hw-state.
>>> + */
>>> +void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
>>> +				  enum drm_privacy_screen_status *sw_state_ret,
>>> +				  enum drm_privacy_screen_status *hw_state_ret)
>>> +{
>>> +	mutex_lock(&priv->lock);
>>> +	*sw_state_ret = priv->sw_state;
>>> +	*hw_state_ret = priv->hw_state;
>>> +	mutex_unlock(&priv->lock);
>>> +}
>>> +EXPORT_SYMBOL(drm_privacy_screen_get_state);
>>> +
>>> +/*** drm_privacy_screen_driver.h functions ***/
>>> +
>>> +static ssize_t sw_state_show(struct device *dev,
>>> +			     struct device_attribute *attr, char *buf)
>>> +{
>>> +	struct drm_privacy_screen *priv = to_drm_privacy_screen(dev);
>>> +	const char * const sw_state_names[] = {
>>> +		"Disabled",
>>> +		"Enabled",
>>> +	};
>>> +	ssize_t ret;
>>> +
>>> +	mutex_lock(&priv->lock);
>>> +
>>> +	if (!priv->ops)
>>> +		ret = -ENODEV;
>>> +	else if (WARN_ON(priv->sw_state >= ARRAY_SIZE(sw_state_names)))
>>> +		ret = -ENXIO;
>>> +	else
>>> +		ret = sprintf(buf, "%s\n", sw_state_names[priv->sw_state]);
>>> +
>>> +	mutex_unlock(&priv->lock);
>>> +	return ret;
>>> +}
>>> +/*
>>> + * RO: Do not allow setting the sw_state through sysfs, this MUST be done
>>> + * through the drm_properties on the drm_connector.
>>> + */
>>> +static DEVICE_ATTR_RO(sw_state);
>>> +
>>> +static ssize_t hw_state_show(struct device *dev,
>>> +			     struct device_attribute *attr, char *buf)
>>> +{
>>> +	struct drm_privacy_screen *priv = to_drm_privacy_screen(dev);
>>> +	const char * const hw_state_names[] = {
>>> +		"Disabled",
>>> +		"Enabled",
>>> +		"Disabled, locked",
>>> +		"Enabled, locked",
>>> +	};
>>> +	ssize_t ret;
>>> +
>>> +	mutex_lock(&priv->lock);
>>> +
>>> +	if (!priv->ops)
>>> +		ret = -ENODEV;
>>> +	else if (WARN_ON(priv->hw_state >= ARRAY_SIZE(hw_state_names)))
>>> +		ret = -ENXIO;
>>> +	else
>>> +		ret = sprintf(buf, "%s\n", hw_state_names[priv->hw_state]);
>>> +
>>> +	mutex_unlock(&priv->lock);
>>> +	return ret;
>>> +}
>>> +static DEVICE_ATTR_RO(hw_state);
>>> +
>>> +static struct attribute *drm_privacy_screen_attrs[] = {
>>> +	&dev_attr_sw_state.attr,
>>> +	&dev_attr_hw_state.attr,
>>> +	NULL
>>> +};
>>> +ATTRIBUTE_GROUPS(drm_privacy_screen);
>>> +
>>> +static struct device_type drm_privacy_screen_type = {
>>> +	.name = "privacy_screen",
>>> +	.groups = drm_privacy_screen_groups,
>>> +};
>>> +
>>> +static void drm_privacy_screen_device_release(struct device *dev)
>>> +{
>>> +	struct drm_privacy_screen *priv = to_drm_privacy_screen(dev);
>>> +
>>> +	kfree(priv);
>>> +}
>>> +
>>> +/**
>>> + * drm_privacy_screen_register - register a privacy-screen
>>> + * @parent: parent-device for the privacy-screen
>>> + * @ops: &struct drm_privacy_screen_ops pointer with ops for the privacy-screen
>>> + *
>>> + * Create and register a privacy-screen.
>>> + *
>>> + * Return:
>>> + * * A pointer to the created privacy-screen on success.
>>> + * * 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 drm_privacy_screen *priv;
>>> +	int ret;
>>> +
>>> +	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
>>> +	if (!priv)
>>> +		return ERR_PTR(-ENOMEM);
>>> +
>>> +	mutex_init(&priv->lock);
>>> +
>>> +	priv->dev.class = drm_class;
>>> +	priv->dev.type = &drm_privacy_screen_type;
>>> +	priv->dev.parent = parent;
>>> +	priv->dev.release = drm_privacy_screen_device_release;
>>> +	dev_set_name(&priv->dev, "privacy_screen-%s", dev_name(parent));
>>> +	priv->ops = ops;
>>> +
>>> +	priv->ops->get_hw_state(priv);
>>> +
>>> +	ret = device_register(&priv->dev);
>>> +	if (ret) {
>>> +		put_device(&priv->dev);
>>> +		return ERR_PTR(ret);
>>> +	}
>>> +
>>> +	mutex_lock(&drm_privacy_screen_devs_lock);
>>> +	list_add(&priv->list, &drm_privacy_screen_devs);
>>> +	mutex_unlock(&drm_privacy_screen_devs_lock);
>>> +
>>> +	return priv;
>>> +}
>>> +EXPORT_SYMBOL(drm_privacy_screen_register);
>>> +
>>> +/**
>>> + * drm_privacy_screen_unregister - unregister privacy-screen
>>> + * @priv: privacy-screen to unregister
>>> + *
>>> + * Unregister a privacy-screen registered with drm_privacy_screen_register().
>>> + * May be called with a NULL or ERR_PTR, in which case it is a no-op.
>>> + */
>>> +void drm_privacy_screen_unregister(struct drm_privacy_screen *priv)
>>> +{
>>> +	if (IS_ERR_OR_NULL(priv))
>>> +		return;
>>> +
>>> +	mutex_lock(&drm_privacy_screen_devs_lock);
>>> +	list_del(&priv->list);
>>> +	mutex_unlock(&drm_privacy_screen_devs_lock);
>>> +
>>> +	mutex_lock(&priv->lock);
>>> +	priv->ops = NULL;
>>> +	mutex_unlock(&priv->lock);
>>> +
>>> +	device_unregister(&priv->dev);
>>> +}
>>> +EXPORT_SYMBOL(drm_privacy_screen_unregister);
>>> diff --git a/include/drm/drm_privacy_screen_consumer.h b/include/drm/drm_privacy_screen_consumer.h
>>> new file mode 100644
>>> index 000000000000..0cbd23b0453d
>>> --- /dev/null
>>> +++ b/include/drm/drm_privacy_screen_consumer.h
>>> @@ -0,0 +1,50 @@
>>> +/* SPDX-License-Identifier: MIT */
>>> +/*
>>> + * Copyright (C) 2020 Red Hat, Inc.
>>> + *
>>> + * Authors:
>>> + * Hans de Goede <hdegoede@redhat.com>
>>> + */
>>> +
>>> +#ifndef __DRM_PRIVACY_SCREEN_CONSUMER_H__
>>> +#define __DRM_PRIVACY_SCREEN_CONSUMER_H__
>>> +
>>> +#include <linux/device.h>
>>> +#include <drm/drm_connector.h>
>>> +
>>> +struct drm_privacy_screen;
>>> +
>>> +#if IS_ENABLED(CONFIG_DRM_PRIVACY_SCREEN)
>>> +struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
>>> +						  const char *con_id);
>>> +void drm_privacy_screen_put(struct drm_privacy_screen *priv);
>>> +
>>> +int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
>>> +				    enum drm_privacy_screen_status sw_state);
>>> +void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
>>> +				  enum drm_privacy_screen_status *sw_state_ret,
>>> +				  enum drm_privacy_screen_status *hw_state_ret);
>>> +#else
>>> +static inline struct drm_privacy_screen *drm_privacy_screen_get(struct device *dev,
>>> +								const char *con_id)
>>> +{
>>> +	return ERR_PTR(-ENODEV);
>>> +}
>>> +static inline void drm_privacy_screen_put(struct drm_privacy_screen *priv)
>>> +{
>>> +}
>>> +static inline int drm_privacy_screen_set_sw_state(struct drm_privacy_screen *priv,
>>> +						  enum drm_privacy_screen_status sw_state)
>>> +{
>>> +	return -ENODEV;
>>> +}
>>> +static inline void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
>>> +						enum drm_privacy_screen_status *sw_state_ret,
>>> +						enum drm_privacy_screen_status *hw_state_ret)
>>> +{
>>> +	*sw_state_ret = PRIVACY_SCREEN_DISABLED;
>>> +	*hw_state_ret = PRIVACY_SCREEN_DISABLED;
>>> +}
>>> +#endif
>>> +
>>> +#endif
>>> diff --git a/include/drm/drm_privacy_screen_driver.h b/include/drm/drm_privacy_screen_driver.h
>>> new file mode 100644
>>> index 000000000000..5187ae52eb03
>>> --- /dev/null
>>> +++ b/include/drm/drm_privacy_screen_driver.h
>>> @@ -0,0 +1,80 @@
>>> +/* SPDX-License-Identifier: MIT */
>>> +/*
>>> + * Copyright (C) 2020 Red Hat, Inc.
>>> + *
>>> + * Authors:
>>> + * Hans de Goede <hdegoede@redhat.com>
>>> + */
>>> +
>>> +#ifndef __DRM_PRIVACY_SCREEN_DRIVER_H__
>>> +#define __DRM_PRIVACY_SCREEN_DRIVER_H__
>>> +
>>> +#include <linux/device.h>
>>> +#include <linux/list.h>
>>> +#include <linux/mutex.h>
>>> +#include <drm/drm_connector.h>
>>> +
>>> +struct drm_privacy_screen;
>>> +
>>> +/**
>>> + * struct drm_privacy_screen_ops - drm_privacy_screen operations
>>> + *
>>> + * Defines the operations which the privacy-screen class code may call.
>>> + * These functions should be implemented by the privacy-screen driver.
>>> + */
>>> +struct drm_privacy_screen_ops {
>>> +	/**
>>> +	 * @set_sw_state: Called to request a change of the privacy-screen
>>> +	 * state. The privacy-screen class code contains a check to avoid this
>>> +	 * getting called when the hw_state reports the state is locked.
>>> +	 * It is the driver's responsibility to update sw_state and hw_state.
>>> +	 * This is always called with the drm_privacy_screen's lock held.
>>> +	 */
>>> +	int (*set_sw_state)(struct drm_privacy_screen *priv,
>>> +			    enum drm_privacy_screen_status sw_state);
>>> +	/**
>>> +	 * @get_hw_state: Called to request that the driver gets the current
>>> +	 * privacy-screen state from the hardware and then updates sw_state and
>>> +	 * hw_state accordingly. This will be called by the core just before
>>> +	 * the privacy-screen is registered in sysfs.
>>> +	 */
>>> +	void (*get_hw_state)(struct drm_privacy_screen *priv);
>>> +};
>>> +
>>> +/**
>>> + * struct drm_privacy_screen - central privacy-screen structure
>>> + *
>>> + * Central privacy-screen structure, this contains the struct device used
>>> + * to register the screen in sysfs, the screen's state, ops, etc.
>>> + */
>>> +struct drm_privacy_screen {
>>> +	/** @dev: device used to register the privacy-screen in sysfs. */
>>> +	struct device dev;
>>> +	/** @lock: mutex protection all fields in this struct. */
>>> +	struct mutex lock;
>>> +	/** @list: privacy-screen devices list list-entry. */
>>> +	struct list_head list;
>>> +	/**
>>> +	 * @ops: &struct drm_privacy_screen_ops for this privacy-screen.
>>> +	 * This is NULL if the driver has unregistered the privacy-screen.
>>> +	 */
>>> +	const struct drm_privacy_screen_ops *ops;
>>> +	/**
>>> +	 * @sw_state: The privacy-screen's software state, see
>>> +	 * :ref:`Standard Connector Properties<standard_connector_properties>`
>>> +	 * for more info.
>>> +	 */
>>> +	enum drm_privacy_screen_status sw_state;
>>> +	/**
>>> +	 * @hw_state: The privacy-screen's hardware state, see
>>> +	 * :ref:`Standard Connector Properties<standard_connector_properties>`
>>> +	 * for more info.
>>> +	 */
>>> +	enum drm_privacy_screen_status hw_state;
>>> +};
>>> +
>>> +struct drm_privacy_screen *drm_privacy_screen_register(
>>> +	struct device *parent, const struct drm_privacy_screen_ops *ops);
>>> +void drm_privacy_screen_unregister(struct drm_privacy_screen *priv);
>>> +
>>> +#endif
>>> diff --git a/include/drm/drm_privacy_screen_machine.h b/include/drm/drm_privacy_screen_machine.h
>>> new file mode 100644
>>> index 000000000000..aaa0d38cce92
>>> --- /dev/null
>>> +++ b/include/drm/drm_privacy_screen_machine.h
>>> @@ -0,0 +1,41 @@
>>> +/* SPDX-License-Identifier: MIT */
>>> +/*
>>> + * Copyright (C) 2020 Red Hat, Inc.
>>> + *
>>> + * Authors:
>>> + * Hans de Goede <hdegoede@redhat.com>
>>> + */
>>> +
>>> +#ifndef __DRM_PRIVACY_SCREEN_MACHINE_H__
>>> +#define __DRM_PRIVACY_SCREEN_MACHINE_H__
>>> +
>>> +#include <linux/list.h>
>>> +
>>> +/**
>>> + * struct drm_privacy_screen_lookup -  static privacy-screen lookup list entry
>>> + *
>>> + * Used for the static lookup-list for mapping privacy-screen consumer
>>> + * dev-connector pairs to a privacy-screen provider.
>>> + */
>>> +struct drm_privacy_screen_lookup {
>>> +	/** @list: Lookup list list-entry. */
>>> +	struct list_head list;
>>> +	/** @dev_id: Consumer device name or NULL to match all devices. */
>>> +	const char *dev_id;
>>> +	/** @con_id: Consumer connector name or NULL to match all connectors. */
>>> +	const char *con_id;
>>> +	/** @provider: dev_name() of the privacy_screen provider. */
>>> +	const char *provider;
>>> +};
>>> +
>>> +void drm_privacy_screen_lookup_add(struct drm_privacy_screen_lookup *lookup);
>>> +void drm_privacy_screen_lookup_remove(struct drm_privacy_screen_lookup *lookup);
>>> +
>>> +static inline void drm_privacy_screen_lookup_init(void)
>>> +{
>>> +}
>>> +static inline void drm_privacy_screen_lookup_exit(void)
>>> +{
>>> +}
>>> +
>>> +#endif
>>>
>>
> 
> 

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 00/10] drm: Add privacy-screen class and connector properties
@ 2021-10-02 16:36 Hans de Goede
  0 siblings, 0 replies; 24+ messages in thread
From: Hans de Goede @ 2021-10-02 16:36 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Rajat Jain,
	Jani Nikula, Lyude, Joonas Lahtinen, Rodrigo Vivi,
	Ville Syrjälä,
	Mark Gross, Andy Shevchenko
  Cc: Hans de Goede, Daniel Vetter, David Airlie, Pekka Paalanen,
	Mario Limonciello, Mark Pearson, Sebastien Bacher,
	Marco Trevisan, Emil Velikov, intel-gfx, dri-devel,
	platform-driver-x86

Hi all,

Here is a new version of my privacy-screen series, addressing the
(few) review-remarks from the version posted on September 6th.
This new version contains the following changes:

- drm: Add privacy-screen class (v4)
 - Make drm_privacy_screen_set_sw_state() skip calling out to the hw if
   hw_state == new_sw_state

- drm/privacy-screen: Add notifier support (v2)
 - Drop WARN_ON(mutex_is_locked(&priv->lock)) check in
   drm_privacy_screen_call_notifier_chain() it may be locked by
   another thread, which would lead to a false-positive triggering
   of the check (change requested by Lyude)

- drm/connector: Add a drm_connector privacy-screen helper functions (v2)
 - Do not update connector->state->privacy_screen_sw_state on
   atomic-commits (change requested by Ville)
 - Change drm_connector_update_privacy_screen() to take drm_connector_state
   as argument instead of a full drm_atomic_state. This allows the helper
   to be called by drivers when they are enabling crtcs/encoders/connectors.

- platform/x86: thinkpad_acpi: Register a privacy-screen device (v3)
 - On receiving a TP_HKEY_EV_PRIVACYGUARD_TOGGLE event only call
   drm_privacy_screen_call_notifier_chain() if the privacy-screen state
   has actually changed

- drm/i915: Add intel_modeset_probe_defer() helper
 - New patch in this version of the series (change requested by Jani)

- drm/i915: Add privacy-screen support (v2)
 - Call drm_connector_update_privacy_screen() from
   intel_enable_ddi_dp() / intel_ddi_update_pipe_dp() instead of adding a
   for_each_new_connector_in_state() loop to intel_atomic_commit_tail()
   (change requested by Ville)
 - Move the probe-deferral check to the intel_modeset_probe_defer() helper
   (change requested by Jani)

With these changes I believe that this series now is fully ready for
merging, but the last 2 patches need to be (re)reviewed.

Here is some more info from the previous cover-letters:

The first userspace consumer of the new properties is now fully ready
for merging (it is just waiting for the kernel bits to land first):

 - https://gitlab.gnome.org/GNOME/gsettings-desktop-schemas/-/merge_requests/49
 - https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1952
 - https://gitlab.gnome.org/GNOME/gnome-control-center/-/merge_requests/1032

The new API works as designed and add the following features to GNOME:

1. Showing an OSD notification when the privacy-screen is toggled on/off
   through hotkeys handled by the embedded-controller
2. Allowing control of the privacy-screen from the GNOME control-panel,
   including the on/off slider shown there updating to match the hw-setting
   when the setting is changed with the control-panel open.
3. Restoring the last user-setting at login

This series consists of a number of different parts:

1. A new version of Rajat's privacy-screen connector properties patch,
this adds new userspace API in the form of new properties

2. Since on most devices the privacy screen is actually controlled by
some vendor specific ACPI/WMI interface which has a driver under
drivers/platform/x86, we need some "glue" code to make this functionality
available to KMS drivers. Patches 2-4 add a new privacy-screen class for
this, which allows non KMS drivers (and possibly KMS drivers too) to
register a privacy-screen device and also adds an interface for KMS drivers
to get access to the privacy-screen associated with a specific connector.
This is modelled similar to how we deal with e.g. PWMs and GPIOs in the
kernel, including separate includes for consumers and providers(drivers).

3. Some drm_connector helper functions to keep the actual changes needed
for this in individual KMS drivers as small as possible (patch 5).

4. Make the thinkpad_acpi code register a privacy-screen device on
ThinkPads with a privacy-screen (patches 6-8)

5. Make the i915 driver export the privacy-screen functionality through
the connector properties on the eDP connector.

I believe that it would be best to merge the entire series, including
the thinkpad_acpi changes through drm-misc in one go. As the pdx86
subsys maintainer I hereby give my ack for merging the thinkpad_acpi
changes through drm-misc.

There is one small caveat with this series, which it is good to be
aware of. The i915 driver will now return -EPROBE_DEFER on Thinkpads
with an eprivacy screen, until the thinkpad_acpi driver is loaded.
This means that initrd generation tools will need to be updated to
include thinkpad_acpi when the i915 driver is added to the initrd.
Without this the loading of the i915 driver will be delayed to after
the switch to real rootfs.

Regards,

Hans


Hans de Goede (9):
  drm: Add privacy-screen class (v4)
  drm/privacy-screen: Add X86 specific arch init code
  drm/privacy-screen: Add notifier support (v2)
  drm/connector: Add a drm_connector privacy-screen helper functions
    (v2)
  platform/x86: thinkpad_acpi: Add hotkey_notify_extended_hotkey()
    helper
  platform/x86: thinkpad_acpi: Get privacy-screen / lcdshadow ACPI
    handles only once
  platform/x86: thinkpad_acpi: Register a privacy-screen device
  drm/i915: Add intel_modeset_probe_defer() helper
  drm/i915: Add privacy-screen support (v2)

Rajat Jain (1):
  drm/connector: Add support for privacy-screen properties (v4)

 Documentation/gpu/drm-kms-helpers.rst        |  15 +
 Documentation/gpu/drm-kms.rst                |   2 +
 MAINTAINERS                                  |   8 +
 drivers/gpu/drm/Kconfig                      |   4 +
 drivers/gpu/drm/Makefile                     |   1 +
 drivers/gpu/drm/drm_atomic_uapi.c            |   4 +
 drivers/gpu/drm/drm_connector.c              | 203 ++++++++
 drivers/gpu/drm/drm_drv.c                    |   4 +
 drivers/gpu/drm/drm_privacy_screen.c         | 467 +++++++++++++++++++
 drivers/gpu/drm/drm_privacy_screen_x86.c     |  86 ++++
 drivers/gpu/drm/i915/display/intel_atomic.c  |   1 +
 drivers/gpu/drm/i915/display/intel_ddi.c     |   3 +
 drivers/gpu/drm/i915/display/intel_display.c |  23 +
 drivers/gpu/drm/i915/display/intel_display.h |   1 +
 drivers/gpu/drm/i915/display/intel_dp.c      |  10 +
 drivers/gpu/drm/i915/i915_pci.c              |   9 +-
 drivers/platform/x86/Kconfig                 |   2 +
 drivers/platform/x86/thinkpad_acpi.c         | 137 ++++--
 include/drm/drm_connector.h                  |  55 +++
 include/drm/drm_privacy_screen_consumer.h    |  65 +++
 include/drm/drm_privacy_screen_driver.h      |  84 ++++
 include/drm/drm_privacy_screen_machine.h     |  46 ++
 22 files changed, 1181 insertions(+), 49 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_privacy_screen.c
 create mode 100644 drivers/gpu/drm/drm_privacy_screen_x86.c
 create mode 100644 include/drm/drm_privacy_screen_consumer.h
 create mode 100644 include/drm/drm_privacy_screen_driver.h
 create mode 100644 include/drm/drm_privacy_screen_machine.h

-- 
2.31.1


^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2021-12-10 11:22 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-05 20:23 [PATCH 00/10] drm: Add privacy-screen class and connector properties Hans de Goede
2021-10-05 20:23 ` [PATCH 01/10] drm/connector: Add support for privacy-screen properties (v4) Hans de Goede
2021-10-05 20:23 ` [PATCH 02/10] drm: Add privacy-screen class (v4) Hans de Goede
2021-11-17 14:28   ` Rajat Jain
2021-11-17 16:39     ` Hans de Goede
2021-12-10 10:12   ` Thorsten Leemhuis
2021-12-10 10:46     ` Hans de Goede
2021-12-10 11:22       ` Thorsten Leemhuis
2021-10-05 20:23 ` [PATCH 03/10] drm/privacy-screen: Add X86 specific arch init code Hans de Goede
2021-11-17 14:13   ` Rajat Jain
2021-11-17 16:33     ` Hans de Goede
2021-10-05 20:23 ` [PATCH 04/10] drm/privacy-screen: Add notifier support (v2) Hans de Goede
2021-10-05 20:23 ` [PATCH 05/10] drm/connector: Add a drm_connector privacy-screen helper functions (v2) Hans de Goede
2021-10-05 20:23 ` [PATCH 06/10] platform/x86: thinkpad_acpi: Add hotkey_notify_extended_hotkey() helper Hans de Goede
2021-10-05 20:23 ` [PATCH 07/10] platform/x86: thinkpad_acpi: Get privacy-screen / lcdshadow ACPI handles only once Hans de Goede
2021-10-05 20:23 ` [PATCH 08/10] platform/x86: thinkpad_acpi: Register a privacy-screen device Hans de Goede
2021-10-05 20:23 ` [PATCH 09/10] drm/i915: Add intel_modeset_probe_defer() helper Hans de Goede
2021-10-05 20:23 ` [PATCH 10/10] drm/i915: Add privacy-screen support (v3) Hans de Goede
2021-10-13 21:59   ` Ville Syrjälä
2021-11-03 23:16     ` Rajat Jain
2021-11-04  8:56       ` Hans de Goede
2021-11-17 13:59   ` Rajat Jain
2021-11-17 16:18     ` Hans de Goede
  -- strict thread matches above, loose matches on Subject: below --
2021-10-02 16:36 [PATCH 00/10] drm: Add privacy-screen class and connector properties Hans de Goede

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).