Skip to content

Commit e27dde3

Browse files
mattroperobclark
authored andcommitted
drm: Add support for multiple plane types (v2)
The DRM core currently only tracks "overlay"-style planes. Start refactoring the plane handling to allow other plane types (primary and cursor) to also be placed on the DRM plane list. v2: Add drm_for_each_legacy_plane() iterator to smooth transition of drivers with plane loops. Signed-off-by: Matt Roper <matthew.d.roper@intel.com> Reviewed-by: Rob Clark <robdclark@gmail.com>
1 parent c32fc9c commit e27dde3

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

drivers/gpu/drm/drm_crtc.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,14 +1044,17 @@ int drm_plane_init(struct drm_device *dev, struct drm_plane *plane,
10441044
memcpy(plane->format_types, formats, format_count * sizeof(uint32_t));
10451045
plane->format_count = format_count;
10461046
plane->possible_crtcs = possible_crtcs;
1047+
plane->type = DRM_PLANE_TYPE_OVERLAY;
10471048

10481049
/* private planes are not exposed to userspace, but depending on
10491050
* display hardware, might be convenient to allow sharing programming
10501051
* for the scanout engine with the crtc implementation.
10511052
*/
10521053
if (!priv) {
10531054
list_add_tail(&plane->head, &dev->mode_config.plane_list);
1054-
dev->mode_config.num_plane++;
1055+
dev->mode_config.num_total_plane++;
1056+
if (plane->type == DRM_PLANE_TYPE_OVERLAY)
1057+
dev->mode_config.num_overlay_plane++;
10551058
} else {
10561059
INIT_LIST_HEAD(&plane->head);
10571060
}
@@ -1081,7 +1084,9 @@ void drm_plane_cleanup(struct drm_plane *plane)
10811084
/* if not added to a list, it must be a private plane */
10821085
if (!list_empty(&plane->head)) {
10831086
list_del(&plane->head);
1084-
dev->mode_config.num_plane--;
1087+
dev->mode_config.num_total_plane--;
1088+
if (plane->type == DRM_PLANE_TYPE_OVERLAY)
1089+
dev->mode_config.num_overlay_plane--;
10851090
}
10861091
drm_modeset_unlock_all(dev);
10871092
}
@@ -1908,19 +1913,23 @@ int drm_mode_getplane_res(struct drm_device *dev, void *data,
19081913
* This ioctl is called twice, once to determine how much space is
19091914
* needed, and the 2nd time to fill it.
19101915
*/
1911-
if (config->num_plane &&
1912-
(plane_resp->count_planes >= config->num_plane)) {
1916+
if (config->num_overlay_plane &&
1917+
(plane_resp->count_planes >= config->num_overlay_plane)) {
19131918
plane_ptr = (uint32_t __user *)(unsigned long)plane_resp->plane_id_ptr;
19141919

19151920
list_for_each_entry(plane, &config->plane_list, head) {
1921+
/* Only advertise overlays to userspace for now. */
1922+
if (plane->type != DRM_PLANE_TYPE_OVERLAY)
1923+
continue;
1924+
19161925
if (put_user(plane->base.id, plane_ptr + copied)) {
19171926
ret = -EFAULT;
19181927
goto out;
19191928
}
19201929
copied++;
19211930
}
19221931
}
1923-
plane_resp->count_planes = config->num_plane;
1932+
plane_resp->count_planes = config->num_overlay_plane;
19241933

19251934
out:
19261935
drm_modeset_unlock_all(dev);
@@ -4534,6 +4543,8 @@ void drm_mode_config_init(struct drm_device *dev)
45344543
dev->mode_config.num_connector = 0;
45354544
dev->mode_config.num_crtc = 0;
45364545
dev->mode_config.num_encoder = 0;
4546+
dev->mode_config.num_overlay_plane = 0;
4547+
dev->mode_config.num_total_plane = 0;
45374548
}
45384549
EXPORT_SYMBOL(drm_mode_config_init);
45394550

drivers/gpu/drm/drm_fb_helper.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ bool drm_fb_helper_restore_fbdev_mode(struct drm_fb_helper *fb_helper)
291291
drm_warn_on_modeset_not_all_locked(dev);
292292

293293
list_for_each_entry(plane, &dev->mode_config.plane_list, head)
294-
drm_plane_force_disable(plane);
294+
if (plane->type != DRM_PLANE_TYPE_PRIMARY)
295+
drm_plane_force_disable(plane);
295296

296297
for (i = 0; i < fb_helper->crtc_count; i++) {
297298
struct drm_mode_set *mode_set = &fb_helper->crtc_info[i].mode_set;

include/drm/drm_crtc.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,12 @@ struct drm_plane_funcs {
541541
struct drm_property *property, uint64_t val);
542542
};
543543

544+
enum drm_plane_type {
545+
DRM_PLANE_TYPE_OVERLAY,
546+
DRM_PLANE_TYPE_PRIMARY,
547+
DRM_PLANE_TYPE_CURSOR,
548+
};
549+
544550
/**
545551
* drm_plane - central DRM plane control structure
546552
* @dev: DRM device this plane belongs to
@@ -553,6 +559,7 @@ struct drm_plane_funcs {
553559
* @fb: currently bound fb
554560
* @funcs: helper functions
555561
* @properties: property tracking for this plane
562+
* @type: type of plane (overlay, primary, cursor)
556563
*/
557564
struct drm_plane {
558565
struct drm_device *dev;
@@ -570,6 +577,8 @@ struct drm_plane {
570577
const struct drm_plane_funcs *funcs;
571578

572579
struct drm_object_properties properties;
580+
581+
enum drm_plane_type type;
573582
};
574583

575584
/**
@@ -732,7 +741,15 @@ struct drm_mode_config {
732741
struct list_head bridge_list;
733742
int num_encoder;
734743
struct list_head encoder_list;
735-
int num_plane;
744+
745+
/*
746+
* Track # of overlay planes separately from # of total planes. By
747+
* default we only advertise overlay planes to userspace; if userspace
748+
* sets the "universal plane" capability bit, we'll go ahead and
749+
* expose all planes.
750+
*/
751+
int num_overlay_plane;
752+
int num_total_plane;
736753
struct list_head plane_list;
737754

738755
int num_crtc;
@@ -1036,4 +1053,9 @@ static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
10361053
return mo ? obj_to_encoder(mo) : NULL;
10371054
}
10381055

1056+
/* Plane list iterator for legacy (overlay only) planes. */
1057+
#define drm_for_each_legacy_plane(plane, planelist) \
1058+
list_for_each_entry(plane, planelist, head) \
1059+
if (plane->type == DRM_PLANE_TYPE_OVERLAY)
1060+
10391061
#endif /* __DRM_CRTC_H__ */

0 commit comments

Comments
 (0)