Commit 10f637bf292ba501f9b9e9df6dfe21d8fa521fbd

Authored by Daniel Vetter
1 parent e6ae8687a8

drm: Add drm_plane/connector_index

In the atomic state we'll have an array of states for crtcs, planes
and connectors and need to be able to at them by their index. We
already have a drm_crtc_index function so add the missing ones for
planes and connectors.

If it later on turns out that the list walking is too expensive we can
add the index to the relevant modeset objects.

Rob Clark doesn't like the loops too much, but we can always add an
obj->idx parameter later on. And for now reiterating is actually safer
since nowadays we have hotpluggable connectors (thanks to DP MST).

v2: Fix embarrassing copypasta fail in kerneldoc and header
declarations, spotted by Matt Roper.

Cc: Matt Roper <matthew.d.roper@intel.com>
Reviewed-by: Matt Roper <matthew.d.roper@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>

Showing 2 changed files with 48 additions and 0 deletions Side-by-side Diff

drivers/gpu/drm/drm_crtc.c
... ... @@ -1022,6 +1022,29 @@
1022 1022 EXPORT_SYMBOL(drm_connector_cleanup);
1023 1023  
1024 1024 /**
  1025 + * drm_connector_index - find the index of a registered connector
  1026 + * @connector: connector to find index for
  1027 + *
  1028 + * Given a registered connector, return the index of that connector within a DRM
  1029 + * device's list of connectors.
  1030 + */
  1031 +unsigned int drm_connector_index(struct drm_connector *connector)
  1032 +{
  1033 + unsigned int index = 0;
  1034 + struct drm_connector *tmp;
  1035 +
  1036 + list_for_each_entry(tmp, &connector->dev->mode_config.connector_list, head) {
  1037 + if (tmp == connector)
  1038 + return index;
  1039 +
  1040 + index++;
  1041 + }
  1042 +
  1043 + BUG();
  1044 +}
  1045 +EXPORT_SYMBOL(drm_connector_index);
  1046 +
  1047 +/**
1025 1048 * drm_connector_register - register a connector
1026 1049 * @connector: the connector to register
1027 1050 *
... ... @@ -1324,6 +1347,29 @@
1324 1347 drm_modeset_unlock_all(dev);
1325 1348 }
1326 1349 EXPORT_SYMBOL(drm_plane_cleanup);
  1350 +
  1351 +/**
  1352 + * drm_plane_index - find the index of a registered plane
  1353 + * @plane: plane to find index for
  1354 + *
  1355 + * Given a registered plane, return the index of that CRTC within a DRM
  1356 + * device's list of planes.
  1357 + */
  1358 +unsigned int drm_plane_index(struct drm_plane *plane)
  1359 +{
  1360 + unsigned int index = 0;
  1361 + struct drm_plane *tmp;
  1362 +
  1363 + list_for_each_entry(tmp, &plane->dev->mode_config.plane_list, head) {
  1364 + if (tmp == plane)
  1365 + return index;
  1366 +
  1367 + index++;
  1368 + }
  1369 +
  1370 + BUG();
  1371 +}
  1372 +EXPORT_SYMBOL(drm_plane_index);
1327 1373  
1328 1374 /**
1329 1375 * drm_plane_force_disable - Forcibly disable a plane
include/drm/drm_crtc.h
... ... @@ -904,6 +904,7 @@
904 904 void drm_connector_unregister(struct drm_connector *connector);
905 905  
906 906 extern void drm_connector_cleanup(struct drm_connector *connector);
  907 +extern unsigned int drm_connector_index(struct drm_connector *connector);
907 908 /* helper to unplug all connectors from sysfs for device */
908 909 extern void drm_connector_unplug_all(struct drm_device *dev);
909 910  
... ... @@ -943,6 +944,7 @@
943 944 const uint32_t *formats, uint32_t format_count,
944 945 bool is_primary);
945 946 extern void drm_plane_cleanup(struct drm_plane *plane);
  947 +extern unsigned int drm_plane_index(struct drm_plane *plane);
946 948 extern void drm_plane_force_disable(struct drm_plane *plane);
947 949 extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
948 950 int x, int y,