Skip to content

Commit 6f5f215

Browse files
mripardpelwell
authored andcommitted
drm/probe-helper: Create a HPD IRQ event helper for a single connector
The drm_helper_hpd_irq_event() function is iterating over all the connectors when an hotplug event is detected. During that iteration, it will call each connector detect function and figure out if its status changed. Finally, if any connector changed, it will notify the user-space and the clients that something changed on the DRM device. This is supposed to be used for drivers that don't have a hotplug interrupt for individual connectors. However, drivers that can use an interrupt for a single connector are left in the dust and can either reimplement the logic used during the iteration for each connector or use that helper and iterate over all connectors all the time. Since both are suboptimal, let's create a helper that will only perform the status detection on a single connector. Signed-off-by: Maxime Ripard <maxime@cerno.tech>
1 parent 35b5286 commit 6f5f215

2 files changed

Lines changed: 82 additions & 32 deletions

File tree

‎drivers/gpu/drm/drm_probe_helper.c‎

Lines changed: 81 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,85 @@ void drm_kms_helper_poll_fini(struct drm_device *dev)
794794
}
795795
EXPORT_SYMBOL(drm_kms_helper_poll_fini);
796796

797+
static bool
798+
_drm_connector_helper_hpd_irq_event(struct drm_connector *connector,
799+
bool notify)
800+
{
801+
struct drm_device *dev = connector->dev;
802+
enum drm_connector_status old_status;
803+
u64 old_epoch_counter;
804+
bool changed = false;
805+
806+
/* Only handle HPD capable connectors. */
807+
drm_WARN_ON(dev, !(connector->polled & DRM_CONNECTOR_POLL_HPD));
808+
809+
drm_WARN_ON(dev, !mutex_is_locked(&dev->mode_config.mutex));
810+
811+
old_status = connector->status;
812+
old_epoch_counter = connector->epoch_counter;
813+
814+
DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Old epoch counter %llu\n",
815+
connector->base.id,
816+
connector->name,
817+
old_epoch_counter);
818+
819+
connector->status = drm_helper_probe_detect(connector, NULL,
820+
false);
821+
DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
822+
connector->base.id,
823+
connector->name,
824+
drm_get_connector_status_name(old_status),
825+
drm_get_connector_status_name(connector->status));
826+
827+
DRM_DEBUG_KMS("[CONNECTOR:%d:%s] New epoch counter %llu\n",
828+
connector->base.id,
829+
connector->name,
830+
connector->epoch_counter);
831+
832+
/*
833+
* Check if epoch counter had changed, meaning that we need
834+
* to send a uevent.
835+
*/
836+
if (old_epoch_counter != connector->epoch_counter)
837+
changed = true;
838+
839+
if (changed && notify) {
840+
drm_kms_helper_hotplug_event(dev);
841+
DRM_DEBUG_KMS("Sent hotplug event\n");
842+
}
843+
844+
return changed;
845+
}
846+
847+
/**
848+
* drm_connector_helper_hpd_irq_event - hotplug processing
849+
* @connector: drm_connector
850+
*
851+
* Drivers can use this helper function to run a detect cycle on a connector
852+
* which has the DRM_CONNECTOR_POLL_HPD flag set in its &polled member.
853+
*
854+
* This helper function is useful for drivers which can track hotplug
855+
* interrupts for a single connector.
856+
*
857+
* This function must be called from process context with no mode
858+
* setting locks held.
859+
*
860+
* Note that a connector can be both polled and probed from the hotplug
861+
* handler, in case the hotplug interrupt is known to be unreliable.
862+
*/
863+
bool drm_connector_helper_hpd_irq_event(struct drm_connector *connector)
864+
{
865+
struct drm_device *dev = connector->dev;
866+
bool changed;
867+
868+
mutex_lock(&dev->mode_config.mutex);
869+
changed = _drm_connector_helper_hpd_irq_event(connector, true);
870+
mutex_unlock(&dev->mode_config.mutex);
871+
872+
return changed;
873+
}
874+
EXPORT_SYMBOL(drm_connector_helper_hpd_irq_event);
875+
797876
/**
798877
* drm_helper_hpd_irq_event - hotplug processing
799878
* @dev: drm_device
@@ -821,47 +900,17 @@ bool drm_helper_hpd_irq_event(struct drm_device *dev)
821900
{
822901
struct drm_connector *connector;
823902
struct drm_connector_list_iter conn_iter;
824-
enum drm_connector_status old_status;
825903
bool changed = false;
826-
u64 old_epoch_counter;
827904

828905
if (!dev->mode_config.poll_enabled)
829906
return false;
830907

831908
mutex_lock(&dev->mode_config.mutex);
832909
drm_connector_list_iter_begin(dev, &conn_iter);
833910
drm_for_each_connector_iter(connector, &conn_iter) {
834-
/* Only handle HPD capable connectors. */
835-
if (!(connector->polled & DRM_CONNECTOR_POLL_HPD))
836-
continue;
837-
838-
old_status = connector->status;
839-
840-
old_epoch_counter = connector->epoch_counter;
841-
842-
DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Old epoch counter %llu\n", connector->base.id,
843-
connector->name,
844-
old_epoch_counter);
845-
846-
connector->status = drm_helper_probe_detect(connector, NULL, false);
847-
DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
848-
connector->base.id,
849-
connector->name,
850-
drm_get_connector_status_name(old_status),
851-
drm_get_connector_status_name(connector->status));
852-
853-
DRM_DEBUG_KMS("[CONNECTOR:%d:%s] New epoch counter %llu\n",
854-
connector->base.id,
855-
connector->name,
856-
connector->epoch_counter);
857-
858-
/*
859-
* Check if epoch counter had changed, meaning that we need
860-
* to send a uevent.
861-
*/
862-
if (old_epoch_counter != connector->epoch_counter)
911+
if (_drm_connector_helper_hpd_irq_event(connector,
912+
false))
863913
changed = true;
864-
865914
}
866915
drm_connector_list_iter_end(&conn_iter);
867916
mutex_unlock(&dev->mode_config.mutex);

‎include/drm/drm_probe_helper.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ int drm_helper_probe_detect(struct drm_connector *connector,
1818
void drm_kms_helper_poll_init(struct drm_device *dev);
1919
void drm_kms_helper_poll_fini(struct drm_device *dev);
2020
bool drm_helper_hpd_irq_event(struct drm_device *dev);
21+
bool drm_connector_helper_hpd_irq_event(struct drm_connector *connector);
2122
void drm_kms_helper_hotplug_event(struct drm_device *dev);
2223

2324
void drm_kms_helper_poll_disable(struct drm_device *dev);

0 commit comments

Comments
 (0)