aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/gpu/drm-kms-helpers.rst9
-rw-r--r--drivers/gpu/drm/Makefile2
-rw-r--r--drivers/gpu/drm/drm_crtc_helper.c56
-rw-r--r--drivers/gpu/drm/drm_modeset_helper.c153
-rw-r--r--drivers/gpu/drm/drm_plane_helper.c66
-rw-r--r--include/drm/drm_atomic_helper.h2
-rw-r--r--include/drm/drm_crtc_helper.h6
-rw-r--r--include/drm/drm_modeset_helper.h36
-rw-r--r--include/drm/drm_plane_helper.h4
9 files changed, 203 insertions, 131 deletions
diff --git a/Documentation/gpu/drm-kms-helpers.rst b/Documentation/gpu/drm-kms-helpers.rst
index 34f755bc9133..59fa3c11efab 100644
--- a/Documentation/gpu/drm-kms-helpers.rst
+++ b/Documentation/gpu/drm-kms-helpers.rst
@@ -258,3 +258,12 @@ Tile group
258 258
259.. kernel-doc:: drivers/gpu/drm/drm_crtc.c 259.. kernel-doc:: drivers/gpu/drm/drm_crtc.c
260 :doc: Tile group 260 :doc: Tile group
261
262Auxiliary Modeset Helpers
263=========================
264
265.. kernel-doc:: drivers/gpu/drm/drm_modeset_helper.c
266 :doc: aux kms helpers
267
268.. kernel-doc:: drivers/gpu/drm/drm_modeset_helper.c
269 :export:
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 0238bf8bc8c3..a5824d926dc9 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -24,7 +24,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o
24drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \ 24drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
25 drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \ 25 drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \
26 drm_kms_helper_common.o drm_dp_dual_mode_helper.o \ 26 drm_kms_helper_common.o drm_dp_dual_mode_helper.o \
27 drm_simple_kms_helper.o drm_blend.o 27 drm_simple_kms_helper.o drm_blend.o drm_modeset_helper.o
28 28
29drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o 29drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
30drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o 30drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
index 604d3ef72ffa..5d2cb138eba6 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -75,35 +75,6 @@
75 */ 75 */
76 76
77/** 77/**
78 * drm_helper_move_panel_connectors_to_head() - move panels to the front in the
79 * connector list
80 * @dev: drm device to operate on
81 *
82 * Some userspace presumes that the first connected connector is the main
83 * display, where it's supposed to display e.g. the login screen. For
84 * laptops, this should be the main panel. Use this function to sort all
85 * (eDP/LVDS) panels to the front of the connector list, instead of
86 * painstakingly trying to initialize them in the right order.
87 */
88void drm_helper_move_panel_connectors_to_head(struct drm_device *dev)
89{
90 struct drm_connector *connector, *tmp;
91 struct list_head panel_list;
92
93 INIT_LIST_HEAD(&panel_list);
94
95 list_for_each_entry_safe(connector, tmp,
96 &dev->mode_config.connector_list, head) {
97 if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS ||
98 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
99 list_move_tail(&connector->head, &panel_list);
100 }
101
102 list_splice(&panel_list, &dev->mode_config.connector_list);
103}
104EXPORT_SYMBOL(drm_helper_move_panel_connectors_to_head);
105
106/**
107 * drm_helper_encoder_in_use - check if a given encoder is in use 78 * drm_helper_encoder_in_use - check if a given encoder is in use
108 * @encoder: encoder to check 79 * @encoder: encoder to check
109 * 80 *
@@ -913,33 +884,6 @@ int drm_helper_connector_dpms(struct drm_connector *connector, int mode)
913EXPORT_SYMBOL(drm_helper_connector_dpms); 884EXPORT_SYMBOL(drm_helper_connector_dpms);
914 885
915/** 886/**
916 * drm_helper_mode_fill_fb_struct - fill out framebuffer metadata
917 * @fb: drm_framebuffer object to fill out
918 * @mode_cmd: metadata from the userspace fb creation request
919 *
920 * This helper can be used in a drivers fb_create callback to pre-fill the fb's
921 * metadata fields.
922 */
923void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
924 const struct drm_mode_fb_cmd2 *mode_cmd)
925{
926 int i;
927
928 fb->width = mode_cmd->width;
929 fb->height = mode_cmd->height;
930 for (i = 0; i < 4; i++) {
931 fb->pitches[i] = mode_cmd->pitches[i];
932 fb->offsets[i] = mode_cmd->offsets[i];
933 fb->modifier[i] = mode_cmd->modifier[i];
934 }
935 drm_fb_get_bpp_depth(mode_cmd->pixel_format, &fb->depth,
936 &fb->bits_per_pixel);
937 fb->pixel_format = mode_cmd->pixel_format;
938 fb->flags = mode_cmd->flags;
939}
940EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct);
941
942/**
943 * drm_helper_resume_force_mode - force-restore mode setting configuration 887 * drm_helper_resume_force_mode - force-restore mode setting configuration
944 * @dev: drm_device which should be restored 888 * @dev: drm_device which should be restored
945 * 889 *
diff --git a/drivers/gpu/drm/drm_modeset_helper.c b/drivers/gpu/drm/drm_modeset_helper.c
new file mode 100644
index 000000000000..1d45738f8f98
--- /dev/null
+++ b/drivers/gpu/drm/drm_modeset_helper.c
@@ -0,0 +1,153 @@
1/*
2 * Copyright (c) 2016 Intel Corporation
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23#include <drm/drm_modeset_helper.h>
24#include <drm/drm_plane_helper.h>
25
26/**
27 * DOC: aux kms helpers
28 *
29 * This helper library contains various one-off functions which don't really fit
30 * anywhere else in the DRM modeset helper library.
31 */
32
33/**
34 * drm_helper_move_panel_connectors_to_head() - move panels to the front in the
35 * connector list
36 * @dev: drm device to operate on
37 *
38 * Some userspace presumes that the first connected connector is the main
39 * display, where it's supposed to display e.g. the login screen. For
40 * laptops, this should be the main panel. Use this function to sort all
41 * (eDP/LVDS) panels to the front of the connector list, instead of
42 * painstakingly trying to initialize them in the right order.
43 */
44void drm_helper_move_panel_connectors_to_head(struct drm_device *dev)
45{
46 struct drm_connector *connector, *tmp;
47 struct list_head panel_list;
48
49 INIT_LIST_HEAD(&panel_list);
50
51 list_for_each_entry_safe(connector, tmp,
52 &dev->mode_config.connector_list, head) {
53 if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS ||
54 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
55 list_move_tail(&connector->head, &panel_list);
56 }
57
58 list_splice(&panel_list, &dev->mode_config.connector_list);
59}
60EXPORT_SYMBOL(drm_helper_move_panel_connectors_to_head);
61
62/**
63 * drm_helper_mode_fill_fb_struct - fill out framebuffer metadata
64 * @fb: drm_framebuffer object to fill out
65 * @mode_cmd: metadata from the userspace fb creation request
66 *
67 * This helper can be used in a drivers fb_create callback to pre-fill the fb's
68 * metadata fields.
69 */
70void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
71 const struct drm_mode_fb_cmd2 *mode_cmd)
72{
73 int i;
74
75 fb->width = mode_cmd->width;
76 fb->height = mode_cmd->height;
77 for (i = 0; i < 4; i++) {
78 fb->pitches[i] = mode_cmd->pitches[i];
79 fb->offsets[i] = mode_cmd->offsets[i];
80 fb->modifier[i] = mode_cmd->modifier[i];
81 }
82 drm_fb_get_bpp_depth(mode_cmd->pixel_format, &fb->depth,
83 &fb->bits_per_pixel);
84 fb->pixel_format = mode_cmd->pixel_format;
85 fb->flags = mode_cmd->flags;
86}
87EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct);
88
89/*
90 * This is the minimal list of formats that seem to be safe for modeset use
91 * with all current DRM drivers. Most hardware can actually support more
92 * formats than this and drivers may specify a more accurate list when
93 * creating the primary plane. However drivers that still call
94 * drm_plane_init() will use this minimal format list as the default.
95 */
96static const uint32_t safe_modeset_formats[] = {
97 DRM_FORMAT_XRGB8888,
98 DRM_FORMAT_ARGB8888,
99};
100
101static struct drm_plane *create_primary_plane(struct drm_device *dev)
102{
103 struct drm_plane *primary;
104 int ret;
105
106 primary = kzalloc(sizeof(*primary), GFP_KERNEL);
107 if (primary == NULL) {
108 DRM_DEBUG_KMS("Failed to allocate primary plane\n");
109 return NULL;
110 }
111
112 /*
113 * Remove the format_default field from drm_plane when dropping
114 * this helper.
115 */
116 primary->format_default = true;
117
118 /* possible_crtc's will be filled in later by crtc_init */
119 ret = drm_universal_plane_init(dev, primary, 0,
120 &drm_primary_helper_funcs,
121 safe_modeset_formats,
122 ARRAY_SIZE(safe_modeset_formats),
123 DRM_PLANE_TYPE_PRIMARY, NULL);
124 if (ret) {
125 kfree(primary);
126 primary = NULL;
127 }
128
129 return primary;
130}
131
132/**
133 * drm_crtc_init - Legacy CRTC initialization function
134 * @dev: DRM device
135 * @crtc: CRTC object to init
136 * @funcs: callbacks for the new CRTC
137 *
138 * Initialize a CRTC object with a default helper-provided primary plane and no
139 * cursor plane.
140 *
141 * Returns:
142 * Zero on success, error code on failure.
143 */
144int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
145 const struct drm_crtc_funcs *funcs)
146{
147 struct drm_plane *primary;
148
149 primary = create_primary_plane(dev);
150 return drm_crtc_init_with_planes(dev, crtc, primary, NULL, funcs,
151 NULL);
152}
153EXPORT_SYMBOL(drm_crtc_init);
diff --git a/drivers/gpu/drm/drm_plane_helper.c b/drivers/gpu/drm/drm_plane_helper.c
index b522aabd1ab0..50b9c1bfc6f6 100644
--- a/drivers/gpu/drm/drm_plane_helper.c
+++ b/drivers/gpu/drm/drm_plane_helper.c
@@ -64,18 +64,6 @@
64 */ 64 */
65 65
66/* 66/*
67 * This is the minimal list of formats that seem to be safe for modeset use
68 * with all current DRM drivers. Most hardware can actually support more
69 * formats than this and drivers may specify a more accurate list when
70 * creating the primary plane. However drivers that still call
71 * drm_plane_init() will use this minimal format list as the default.
72 */
73static const uint32_t safe_modeset_formats[] = {
74 DRM_FORMAT_XRGB8888,
75 DRM_FORMAT_ARGB8888,
76};
77
78/*
79 * Returns the connectors currently associated with a CRTC. This function 67 * Returns the connectors currently associated with a CRTC. This function
80 * should be called twice: once with a NULL connector list to retrieve 68 * should be called twice: once with a NULL connector list to retrieve
81 * the list size, and once with the properly allocated list to be filled in. 69 * the list size, and once with the properly allocated list to be filled in.
@@ -438,60 +426,6 @@ const struct drm_plane_funcs drm_primary_helper_funcs = {
438}; 426};
439EXPORT_SYMBOL(drm_primary_helper_funcs); 427EXPORT_SYMBOL(drm_primary_helper_funcs);
440 428
441static struct drm_plane *create_primary_plane(struct drm_device *dev)
442{
443 struct drm_plane *primary;
444 int ret;
445
446 primary = kzalloc(sizeof(*primary), GFP_KERNEL);
447 if (primary == NULL) {
448 DRM_DEBUG_KMS("Failed to allocate primary plane\n");
449 return NULL;
450 }
451
452 /*
453 * Remove the format_default field from drm_plane when dropping
454 * this helper.
455 */
456 primary->format_default = true;
457
458 /* possible_crtc's will be filled in later by crtc_init */
459 ret = drm_universal_plane_init(dev, primary, 0,
460 &drm_primary_helper_funcs,
461 safe_modeset_formats,
462 ARRAY_SIZE(safe_modeset_formats),
463 DRM_PLANE_TYPE_PRIMARY, NULL);
464 if (ret) {
465 kfree(primary);
466 primary = NULL;
467 }
468
469 return primary;
470}
471
472/**
473 * drm_crtc_init - Legacy CRTC initialization function
474 * @dev: DRM device
475 * @crtc: CRTC object to init
476 * @funcs: callbacks for the new CRTC
477 *
478 * Initialize a CRTC object with a default helper-provided primary plane and no
479 * cursor plane.
480 *
481 * Returns:
482 * Zero on success, error code on failure.
483 */
484int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
485 const struct drm_crtc_funcs *funcs)
486{
487 struct drm_plane *primary;
488
489 primary = create_primary_plane(dev);
490 return drm_crtc_init_with_planes(dev, crtc, primary, NULL, funcs,
491 NULL);
492}
493EXPORT_SYMBOL(drm_crtc_init);
494
495int drm_plane_helper_commit(struct drm_plane *plane, 429int drm_plane_helper_commit(struct drm_plane *plane,
496 struct drm_plane_state *plane_state, 430 struct drm_plane_state *plane_state,
497 struct drm_framebuffer *old_fb) 431 struct drm_framebuffer *old_fb)
diff --git a/include/drm/drm_atomic_helper.h b/include/drm/drm_atomic_helper.h
index d86ae5dcd7b4..5a02e499f32b 100644
--- a/include/drm/drm_atomic_helper.h
+++ b/include/drm/drm_atomic_helper.h
@@ -29,6 +29,8 @@
29#define DRM_ATOMIC_HELPER_H_ 29#define DRM_ATOMIC_HELPER_H_
30 30
31#include <drm/drm_crtc.h> 31#include <drm/drm_crtc.h>
32#include <drm/drm_modeset_helper_vtables.h>
33#include <drm/drm_modeset_helper.h>
32 34
33struct drm_atomic_state; 35struct drm_atomic_state;
34 36
diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
index 4b37afa2b73b..982c299e435a 100644
--- a/include/drm/drm_crtc_helper.h
+++ b/include/drm/drm_crtc_helper.h
@@ -41,6 +41,7 @@
41 41
42#include <drm/drm_crtc.h> 42#include <drm/drm_crtc.h>
43#include <drm/drm_modeset_helper_vtables.h> 43#include <drm/drm_modeset_helper_vtables.h>
44#include <drm/drm_modeset_helper.h>
44 45
45extern void drm_helper_disable_unused_functions(struct drm_device *dev); 46extern void drm_helper_disable_unused_functions(struct drm_device *dev);
46extern int drm_crtc_helper_set_config(struct drm_mode_set *set); 47extern int drm_crtc_helper_set_config(struct drm_mode_set *set);
@@ -53,11 +54,6 @@ extern bool drm_helper_encoder_in_use(struct drm_encoder *encoder);
53 54
54extern int drm_helper_connector_dpms(struct drm_connector *connector, int mode); 55extern int drm_helper_connector_dpms(struct drm_connector *connector, int mode);
55 56
56extern void drm_helper_move_panel_connectors_to_head(struct drm_device *);
57
58extern void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
59 const struct drm_mode_fb_cmd2 *mode_cmd);
60
61extern void drm_helper_resume_force_mode(struct drm_device *dev); 57extern void drm_helper_resume_force_mode(struct drm_device *dev);
62 58
63int drm_helper_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode, 59int drm_helper_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode,
diff --git a/include/drm/drm_modeset_helper.h b/include/drm/drm_modeset_helper.h
new file mode 100644
index 000000000000..b8051d5abe10
--- /dev/null
+++ b/include/drm/drm_modeset_helper.h
@@ -0,0 +1,36 @@
1/*
2 * Copyright (c) 2016 Intel Corporation
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23#ifndef __DRM_KMS_HELPER_H__
24#define __DRM_KMS_HELPER_H__
25
26#include <drm/drmP.h>
27
28void drm_helper_move_panel_connectors_to_head(struct drm_device *);
29
30void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
31 const struct drm_mode_fb_cmd2 *mode_cmd);
32
33int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
34 const struct drm_crtc_funcs *funcs);
35
36#endif
diff --git a/include/drm/drm_plane_helper.h b/include/drm/drm_plane_helper.h
index fbc8ecb3e5e8..c18959685c06 100644
--- a/include/drm/drm_plane_helper.h
+++ b/include/drm/drm_plane_helper.h
@@ -27,6 +27,7 @@
27#include <drm/drm_rect.h> 27#include <drm/drm_rect.h>
28#include <drm/drm_crtc.h> 28#include <drm/drm_crtc.h>
29#include <drm/drm_modeset_helper_vtables.h> 29#include <drm/drm_modeset_helper_vtables.h>
30#include <drm/drm_modeset_helper.h>
30 31
31/* 32/*
32 * Drivers that don't allow primary plane scaling may pass this macro in place 33 * Drivers that don't allow primary plane scaling may pass this macro in place
@@ -37,9 +38,6 @@
37 */ 38 */
38#define DRM_PLANE_HELPER_NO_SCALING (1<<16) 39#define DRM_PLANE_HELPER_NO_SCALING (1<<16)
39 40
40int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
41 const struct drm_crtc_funcs *funcs);
42
43int drm_plane_helper_check_state(struct drm_plane_state *state, 41int drm_plane_helper_check_state(struct drm_plane_state *state,
44 const struct drm_rect *clip, 42 const struct drm_rect *clip,
45 int min_scale, int max_scale, 43 int min_scale, int max_scale,