diff options
author | Noralf Trønnes <noralf@tronnes.org> | 2016-06-10 10:55:59 -0400 |
---|---|---|
committer | Daniel Vetter <daniel.vetter@ffwll.ch> | 2016-06-10 11:33:17 -0400 |
commit | 5b8090747a1186f8f6a1d3a7e49f792b13ab7b84 (patch) | |
tree | 6af6eb3734ebd8ff14c84debaf90f801d8bfe092 | |
parent | c2a441fe8f7f62571e47ce3f4fa3d97edd092dd9 (diff) |
drm: Add helper for simple display pipeline
Provides helper functions for drivers that have a simple display
pipeline. Plane, crtc and encoder are collapsed into one entity.
Changes since v4:
- Remove drm_connector_register() call
- Forgot to assign pipe->connector
Changes since v3:
- (struct drm_simple_display_pipe *)->funcs should be const
Changes since v2:
- Drop Kconfig knob DRM_KMS_HELPER
- Expand documentation
Changes since v1:
- Add DOC header and add to gpu.tmpl
- Fix docs: @funcs is optional, "negative error code",
"This hook is optional."
- Add checks to drm_simple_kms_plane_atomic_check()
Cc: jsarha@ti.com
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1465570559-14238-1-git-send-email-noralf@tronnes.org
-rw-r--r-- | Documentation/DocBook/gpu.tmpl | 6 | ||||
-rw-r--r-- | drivers/gpu/drm/Makefile | 3 | ||||
-rw-r--r-- | drivers/gpu/drm/drm_simple_kms_helper.c | 205 | ||||
-rw-r--r-- | include/drm/drm_simple_kms_helper.h | 94 |
4 files changed, 307 insertions, 1 deletions
diff --git a/Documentation/DocBook/gpu.tmpl b/Documentation/DocBook/gpu.tmpl index 89585ad69a4b..d09536c91717 100644 --- a/Documentation/DocBook/gpu.tmpl +++ b/Documentation/DocBook/gpu.tmpl | |||
@@ -1688,6 +1688,12 @@ void intel_crt_init(struct drm_device *dev) | |||
1688 | !Edrivers/gpu/drm/drm_panel.c | 1688 | !Edrivers/gpu/drm/drm_panel.c |
1689 | !Pdrivers/gpu/drm/drm_panel.c drm panel | 1689 | !Pdrivers/gpu/drm/drm_panel.c drm panel |
1690 | </sect2> | 1690 | </sect2> |
1691 | <sect2> | ||
1692 | <title>Simple KMS Helper Reference</title> | ||
1693 | !Iinclude/drm/drm_simple_kms_helper.h | ||
1694 | !Edrivers/gpu/drm/drm_simple_kms_helper.c | ||
1695 | !Pdrivers/gpu/drm/drm_simple_kms_helper.c overview | ||
1696 | </sect2> | ||
1691 | </sect1> | 1697 | </sect1> |
1692 | 1698 | ||
1693 | <!-- Internals: kms properties --> | 1699 | <!-- Internals: kms properties --> |
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index aa24af35c068..e3dba6f44a79 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile | |||
@@ -23,7 +23,8 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o | |||
23 | 23 | ||
24 | drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \ | 24 | drm_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 | ||
27 | 28 | ||
28 | drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o | 29 | drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o |
29 | drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o | 30 | drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o |
diff --git a/drivers/gpu/drm/drm_simple_kms_helper.c b/drivers/gpu/drm/drm_simple_kms_helper.c new file mode 100644 index 000000000000..b2071d495ada --- /dev/null +++ b/drivers/gpu/drm/drm_simple_kms_helper.c | |||
@@ -0,0 +1,205 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 Noralf Trønnes | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | */ | ||
9 | |||
10 | #include <drm/drmP.h> | ||
11 | #include <drm/drm_atomic.h> | ||
12 | #include <drm/drm_atomic_helper.h> | ||
13 | #include <drm/drm_crtc_helper.h> | ||
14 | #include <drm/drm_plane_helper.h> | ||
15 | #include <drm/drm_simple_kms_helper.h> | ||
16 | #include <linux/slab.h> | ||
17 | |||
18 | /** | ||
19 | * DOC: overview | ||
20 | * | ||
21 | * This helper library provides helpers for drivers for simple display | ||
22 | * hardware. | ||
23 | * | ||
24 | * drm_simple_display_pipe_init() initializes a simple display pipeline | ||
25 | * which has only one full-screen scanout buffer feeding one output. The | ||
26 | * pipeline is represented by struct &drm_simple_display_pipe and binds | ||
27 | * together &drm_plane, &drm_crtc and &drm_encoder structures into one fixed | ||
28 | * entity. Some flexibility for code reuse is provided through a separately | ||
29 | * allocated &drm_connector object and supporting optional &drm_bridge | ||
30 | * encoder drivers. | ||
31 | */ | ||
32 | |||
33 | static const struct drm_encoder_funcs drm_simple_kms_encoder_funcs = { | ||
34 | .destroy = drm_encoder_cleanup, | ||
35 | }; | ||
36 | |||
37 | static void drm_simple_kms_crtc_enable(struct drm_crtc *crtc) | ||
38 | { | ||
39 | struct drm_simple_display_pipe *pipe; | ||
40 | |||
41 | pipe = container_of(crtc, struct drm_simple_display_pipe, crtc); | ||
42 | if (!pipe->funcs || !pipe->funcs->enable) | ||
43 | return; | ||
44 | |||
45 | pipe->funcs->enable(pipe, crtc->state); | ||
46 | } | ||
47 | |||
48 | static void drm_simple_kms_crtc_disable(struct drm_crtc *crtc) | ||
49 | { | ||
50 | struct drm_simple_display_pipe *pipe; | ||
51 | |||
52 | pipe = container_of(crtc, struct drm_simple_display_pipe, crtc); | ||
53 | if (!pipe->funcs || !pipe->funcs->disable) | ||
54 | return; | ||
55 | |||
56 | pipe->funcs->disable(pipe); | ||
57 | } | ||
58 | |||
59 | static const struct drm_crtc_helper_funcs drm_simple_kms_crtc_helper_funcs = { | ||
60 | .disable = drm_simple_kms_crtc_disable, | ||
61 | .enable = drm_simple_kms_crtc_enable, | ||
62 | }; | ||
63 | |||
64 | static const struct drm_crtc_funcs drm_simple_kms_crtc_funcs = { | ||
65 | .reset = drm_atomic_helper_crtc_reset, | ||
66 | .destroy = drm_crtc_cleanup, | ||
67 | .set_config = drm_atomic_helper_set_config, | ||
68 | .page_flip = drm_atomic_helper_page_flip, | ||
69 | .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, | ||
70 | .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, | ||
71 | }; | ||
72 | |||
73 | static int drm_simple_kms_plane_atomic_check(struct drm_plane *plane, | ||
74 | struct drm_plane_state *plane_state) | ||
75 | { | ||
76 | struct drm_rect src = { | ||
77 | .x1 = plane_state->src_x, | ||
78 | .y1 = plane_state->src_y, | ||
79 | .x2 = plane_state->src_x + plane_state->src_w, | ||
80 | .y2 = plane_state->src_y + plane_state->src_h, | ||
81 | }; | ||
82 | struct drm_rect dest = { | ||
83 | .x1 = plane_state->crtc_x, | ||
84 | .y1 = plane_state->crtc_y, | ||
85 | .x2 = plane_state->crtc_x + plane_state->crtc_w, | ||
86 | .y2 = plane_state->crtc_y + plane_state->crtc_h, | ||
87 | }; | ||
88 | struct drm_rect clip = { 0 }; | ||
89 | struct drm_simple_display_pipe *pipe; | ||
90 | struct drm_crtc_state *crtc_state; | ||
91 | bool visible; | ||
92 | int ret; | ||
93 | |||
94 | pipe = container_of(plane, struct drm_simple_display_pipe, plane); | ||
95 | crtc_state = drm_atomic_get_existing_crtc_state(plane_state->state, | ||
96 | &pipe->crtc); | ||
97 | if (crtc_state->enable != !!plane_state->crtc) | ||
98 | return -EINVAL; /* plane must match crtc enable state */ | ||
99 | |||
100 | if (!crtc_state->enable) | ||
101 | return 0; /* nothing to check when disabling or disabled */ | ||
102 | |||
103 | clip.x2 = crtc_state->adjusted_mode.hdisplay; | ||
104 | clip.y2 = crtc_state->adjusted_mode.vdisplay; | ||
105 | ret = drm_plane_helper_check_update(plane, &pipe->crtc, | ||
106 | plane_state->fb, | ||
107 | &src, &dest, &clip, | ||
108 | DRM_PLANE_HELPER_NO_SCALING, | ||
109 | DRM_PLANE_HELPER_NO_SCALING, | ||
110 | false, true, &visible); | ||
111 | if (ret) | ||
112 | return ret; | ||
113 | |||
114 | if (!visible) | ||
115 | return -EINVAL; | ||
116 | |||
117 | if (!pipe->funcs || !pipe->funcs->check) | ||
118 | return 0; | ||
119 | |||
120 | return pipe->funcs->check(pipe, plane_state, crtc_state); | ||
121 | } | ||
122 | |||
123 | static void drm_simple_kms_plane_atomic_update(struct drm_plane *plane, | ||
124 | struct drm_plane_state *pstate) | ||
125 | { | ||
126 | struct drm_simple_display_pipe *pipe; | ||
127 | |||
128 | pipe = container_of(plane, struct drm_simple_display_pipe, plane); | ||
129 | if (!pipe->funcs || !pipe->funcs->update) | ||
130 | return; | ||
131 | |||
132 | pipe->funcs->update(pipe, pstate); | ||
133 | } | ||
134 | |||
135 | static const struct drm_plane_helper_funcs drm_simple_kms_plane_helper_funcs = { | ||
136 | .atomic_check = drm_simple_kms_plane_atomic_check, | ||
137 | .atomic_update = drm_simple_kms_plane_atomic_update, | ||
138 | }; | ||
139 | |||
140 | static const struct drm_plane_funcs drm_simple_kms_plane_funcs = { | ||
141 | .update_plane = drm_atomic_helper_update_plane, | ||
142 | .disable_plane = drm_atomic_helper_disable_plane, | ||
143 | .destroy = drm_plane_cleanup, | ||
144 | .reset = drm_atomic_helper_plane_reset, | ||
145 | .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, | ||
146 | .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, | ||
147 | }; | ||
148 | |||
149 | /** | ||
150 | * drm_simple_display_pipe_init - Initialize a simple display pipeline | ||
151 | * @dev: DRM device | ||
152 | * @pipe: simple display pipe object to initialize | ||
153 | * @funcs: callbacks for the display pipe (optional) | ||
154 | * @formats: array of supported formats (%DRM_FORMAT_*) | ||
155 | * @format_count: number of elements in @formats | ||
156 | * @connector: connector to attach and register | ||
157 | * | ||
158 | * Sets up a display pipeline which consist of a really simple | ||
159 | * plane-crtc-encoder pipe coupled with the provided connector. | ||
160 | * Teardown of a simple display pipe is all handled automatically by the drm | ||
161 | * core through calling drm_mode_config_cleanup(). Drivers afterwards need to | ||
162 | * release the memory for the structure themselves. | ||
163 | * | ||
164 | * Returns: | ||
165 | * Zero on success, negative error code on failure. | ||
166 | */ | ||
167 | int drm_simple_display_pipe_init(struct drm_device *dev, | ||
168 | struct drm_simple_display_pipe *pipe, | ||
169 | const struct drm_simple_display_pipe_funcs *funcs, | ||
170 | const uint32_t *formats, unsigned int format_count, | ||
171 | struct drm_connector *connector) | ||
172 | { | ||
173 | struct drm_encoder *encoder = &pipe->encoder; | ||
174 | struct drm_plane *plane = &pipe->plane; | ||
175 | struct drm_crtc *crtc = &pipe->crtc; | ||
176 | int ret; | ||
177 | |||
178 | pipe->connector = connector; | ||
179 | pipe->funcs = funcs; | ||
180 | |||
181 | drm_plane_helper_add(plane, &drm_simple_kms_plane_helper_funcs); | ||
182 | ret = drm_universal_plane_init(dev, plane, 0, | ||
183 | &drm_simple_kms_plane_funcs, | ||
184 | formats, format_count, | ||
185 | DRM_PLANE_TYPE_PRIMARY, NULL); | ||
186 | if (ret) | ||
187 | return ret; | ||
188 | |||
189 | drm_crtc_helper_add(crtc, &drm_simple_kms_crtc_helper_funcs); | ||
190 | ret = drm_crtc_init_with_planes(dev, crtc, plane, NULL, | ||
191 | &drm_simple_kms_crtc_funcs, NULL); | ||
192 | if (ret) | ||
193 | return ret; | ||
194 | |||
195 | encoder->possible_crtcs = 1 << drm_crtc_index(crtc); | ||
196 | ret = drm_encoder_init(dev, encoder, &drm_simple_kms_encoder_funcs, | ||
197 | DRM_MODE_ENCODER_NONE, NULL); | ||
198 | if (ret) | ||
199 | return ret; | ||
200 | |||
201 | return drm_mode_connector_attach_encoder(connector, encoder); | ||
202 | } | ||
203 | EXPORT_SYMBOL(drm_simple_display_pipe_init); | ||
204 | |||
205 | MODULE_LICENSE("GPL"); | ||
diff --git a/include/drm/drm_simple_kms_helper.h b/include/drm/drm_simple_kms_helper.h new file mode 100644 index 000000000000..269039722f91 --- /dev/null +++ b/include/drm/drm_simple_kms_helper.h | |||
@@ -0,0 +1,94 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 Noralf Trønnes | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | */ | ||
9 | |||
10 | #ifndef __LINUX_DRM_SIMPLE_KMS_HELPER_H | ||
11 | #define __LINUX_DRM_SIMPLE_KMS_HELPER_H | ||
12 | |||
13 | struct drm_simple_display_pipe; | ||
14 | |||
15 | /** | ||
16 | * struct drm_simple_display_pipe_funcs - helper operations for a simple | ||
17 | * display pipeline | ||
18 | */ | ||
19 | struct drm_simple_display_pipe_funcs { | ||
20 | /** | ||
21 | * @enable: | ||
22 | * | ||
23 | * This function should be used to enable the pipeline. | ||
24 | * It is called when the underlying crtc is enabled. | ||
25 | * This hook is optional. | ||
26 | */ | ||
27 | void (*enable)(struct drm_simple_display_pipe *pipe, | ||
28 | struct drm_crtc_state *crtc_state); | ||
29 | /** | ||
30 | * @disable: | ||
31 | * | ||
32 | * This function should be used to disable the pipeline. | ||
33 | * It is called when the underlying crtc is disabled. | ||
34 | * This hook is optional. | ||
35 | */ | ||
36 | void (*disable)(struct drm_simple_display_pipe *pipe); | ||
37 | |||
38 | /** | ||
39 | * @check: | ||
40 | * | ||
41 | * This function is called in the check phase of an atomic update, | ||
42 | * specifically when the underlying plane is checked. | ||
43 | * The simple display pipeline helpers already check that the plane is | ||
44 | * not scaled, fills the entire visible area and is always enabled | ||
45 | * when the crtc is also enabled. | ||
46 | * This hook is optional. | ||
47 | * | ||
48 | * RETURNS: | ||
49 | * | ||
50 | * 0 on success, -EINVAL if the state or the transition can't be | ||
51 | * supported, -ENOMEM on memory allocation failure and -EDEADLK if an | ||
52 | * attempt to obtain another state object ran into a &drm_modeset_lock | ||
53 | * deadlock. | ||
54 | */ | ||
55 | int (*check)(struct drm_simple_display_pipe *pipe, | ||
56 | struct drm_plane_state *plane_state, | ||
57 | struct drm_crtc_state *crtc_state); | ||
58 | /** | ||
59 | * @update: | ||
60 | * | ||
61 | * This function is called when the underlying plane state is updated. | ||
62 | * This hook is optional. | ||
63 | */ | ||
64 | void (*update)(struct drm_simple_display_pipe *pipe, | ||
65 | struct drm_plane_state *plane_state); | ||
66 | }; | ||
67 | |||
68 | /** | ||
69 | * struct drm_simple_display_pipe - simple display pipeline | ||
70 | * @crtc: CRTC control structure | ||
71 | * @plane: Plane control structure | ||
72 | * @encoder: Encoder control structure | ||
73 | * @connector: Connector control structure | ||
74 | * @funcs: Pipeline control functions (optional) | ||
75 | * | ||
76 | * Simple display pipeline with plane, crtc and encoder collapsed into one | ||
77 | * entity. It should be initialized by calling drm_simple_display_pipe_init(). | ||
78 | */ | ||
79 | struct drm_simple_display_pipe { | ||
80 | struct drm_crtc crtc; | ||
81 | struct drm_plane plane; | ||
82 | struct drm_encoder encoder; | ||
83 | struct drm_connector *connector; | ||
84 | |||
85 | const struct drm_simple_display_pipe_funcs *funcs; | ||
86 | }; | ||
87 | |||
88 | int drm_simple_display_pipe_init(struct drm_device *dev, | ||
89 | struct drm_simple_display_pipe *pipe, | ||
90 | const struct drm_simple_display_pipe_funcs *funcs, | ||
91 | const uint32_t *formats, unsigned int format_count, | ||
92 | struct drm_connector *connector); | ||
93 | |||
94 | #endif /* __LINUX_DRM_SIMPLE_KMS_HELPER_H */ | ||