Commit | Line | Data |
---|---|---|
092d01da DV |
1 | /* |
2 | * Copyright © 2006 Keith Packard | |
3 | * Copyright © 2007-2008 Dave Airlie | |
4 | * Copyright © 2007-2008 Intel Corporation | |
5 | * Jesse Barnes <jesse.barnes@intel.com> | |
6 | * Copyright © 2011-2013 Intel Corporation | |
7 | * Copyright © 2015 Intel Corporation | |
8 | * Daniel Vetter <daniel.vetter@ffwll.ch> | |
9 | * | |
10 | * Permission is hereby granted, free of charge, to any person obtaining a | |
11 | * copy of this software and associated documentation files (the "Software"), | |
12 | * to deal in the Software without restriction, including without limitation | |
13 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
14 | * and/or sell copies of the Software, and to permit persons to whom the | |
15 | * Software is furnished to do so, subject to the following conditions: | |
16 | * | |
17 | * The above copyright notice and this permission notice shall be included in | |
18 | * all copies or substantial portions of the Software. | |
19 | * | |
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
23 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
24 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
25 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
26 | * OTHER DEALINGS IN THE SOFTWARE. | |
27 | */ | |
28 | ||
29 | #ifndef __DRM_MODESET_HELPER_VTABLES_H__ | |
30 | #define __DRM_MODESET_HELPER_VTABLES_H__ | |
31 | ||
32 | #include <drm/drm_crtc.h> | |
33 | ||
34 | /** | |
35 | * DOC: overview | |
36 | * | |
37 | * The DRM mode setting helper functions are common code for drivers to use if | |
38 | * they wish. Drivers are not forced to use this code in their | |
39 | * implementations but it would be useful if the code they do use at least | |
40 | * provides a consistent interface and operation to userspace. Therefore it is | |
41 | * highly recommended to use the provided helpers as much as possible. | |
42 | * | |
43 | * Because there is only one pointer per modeset object to hold a vfunc table | |
44 | * for helper libraries they are by necessity shared among the different | |
45 | * helpers. | |
46 | * | |
47 | * To make this clear all the helper vtables are pulled together in this location here. | |
48 | */ | |
49 | ||
50 | enum mode_set_atomic; | |
51 | ||
52 | /** | |
53 | * struct drm_crtc_helper_funcs - helper operations for CRTCs | |
54 | * @dpms: set power state | |
55 | * @prepare: prepare the CRTC, called before @mode_set | |
56 | * @commit: commit changes to CRTC, called after @mode_set | |
57 | * @mode_fixup: try to fixup proposed mode for this CRTC | |
58 | * @mode_set: set this mode | |
59 | * @mode_set_nofb: set mode only (no scanout buffer attached) | |
60 | * @mode_set_base: update the scanout buffer | |
61 | * @mode_set_base_atomic: non-blocking mode set (used for kgdb support) | |
62 | * @load_lut: load color palette | |
63 | * @disable: disable CRTC when no longer in use | |
64 | * @enable: enable CRTC | |
65 | * @atomic_check: check for validity of an atomic state | |
66 | * @atomic_begin: begin atomic update | |
67 | * @atomic_flush: flush atomic update | |
68 | * | |
69 | * The helper operations are called by the mid-layer CRTC helper. | |
70 | * | |
71 | * Note that with atomic helpers @dpms, @prepare and @commit hooks are | |
72 | * deprecated. Used @enable and @disable instead exclusively. | |
73 | * | |
74 | * With legacy crtc helpers there's a big semantic difference between @disable | |
75 | * and the other hooks: @disable also needs to release any resources acquired in | |
76 | * @mode_set (like shared PLLs). | |
77 | */ | |
78 | struct drm_crtc_helper_funcs { | |
79 | /* | |
80 | * Control power levels on the CRTC. If the mode passed in is | |
81 | * unsupported, the provider must use the next lowest power level. | |
82 | */ | |
83 | void (*dpms)(struct drm_crtc *crtc, int mode); | |
84 | void (*prepare)(struct drm_crtc *crtc); | |
85 | void (*commit)(struct drm_crtc *crtc); | |
86 | ||
87 | /* Provider can fixup or change mode timings before modeset occurs */ | |
88 | bool (*mode_fixup)(struct drm_crtc *crtc, | |
89 | const struct drm_display_mode *mode, | |
90 | struct drm_display_mode *adjusted_mode); | |
91 | /* Actually set the mode */ | |
92 | int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode, | |
93 | struct drm_display_mode *adjusted_mode, int x, int y, | |
94 | struct drm_framebuffer *old_fb); | |
95 | /* Actually set the mode for atomic helpers, optional */ | |
96 | void (*mode_set_nofb)(struct drm_crtc *crtc); | |
97 | ||
98 | /* Move the crtc on the current fb to the given position *optional* */ | |
99 | int (*mode_set_base)(struct drm_crtc *crtc, int x, int y, | |
100 | struct drm_framebuffer *old_fb); | |
101 | int (*mode_set_base_atomic)(struct drm_crtc *crtc, | |
102 | struct drm_framebuffer *fb, int x, int y, | |
103 | enum mode_set_atomic); | |
104 | ||
105 | /* reload the current crtc LUT */ | |
106 | void (*load_lut)(struct drm_crtc *crtc); | |
107 | ||
108 | void (*disable)(struct drm_crtc *crtc); | |
109 | void (*enable)(struct drm_crtc *crtc); | |
110 | ||
111 | /* atomic helpers */ | |
112 | int (*atomic_check)(struct drm_crtc *crtc, | |
113 | struct drm_crtc_state *state); | |
114 | void (*atomic_begin)(struct drm_crtc *crtc, | |
115 | struct drm_crtc_state *old_crtc_state); | |
116 | void (*atomic_flush)(struct drm_crtc *crtc, | |
117 | struct drm_crtc_state *old_crtc_state); | |
118 | }; | |
119 | ||
120 | /** | |
121 | * drm_crtc_helper_add - sets the helper vtable for a crtc | |
122 | * @crtc: DRM CRTC | |
123 | * @funcs: helper vtable to set for @crtc | |
124 | */ | |
125 | static inline void drm_crtc_helper_add(struct drm_crtc *crtc, | |
126 | const struct drm_crtc_helper_funcs *funcs) | |
127 | { | |
128 | crtc->helper_private = funcs; | |
129 | } | |
130 | ||
131 | /** | |
132 | * struct drm_encoder_helper_funcs - helper operations for encoders | |
133 | * @dpms: set power state | |
092d01da DV |
134 | * @mode_fixup: try to fixup proposed mode for this connector |
135 | * @prepare: part of the disable sequence, called before the CRTC modeset | |
136 | * @commit: called after the CRTC modeset | |
137 | * @mode_set: set this mode, optional for atomic helpers | |
138 | * @get_crtc: return CRTC that the encoder is currently attached to | |
139 | * @detect: connection status detection | |
140 | * @disable: disable encoder when not in use (overrides DPMS off) | |
141 | * @enable: enable encoder | |
142 | * @atomic_check: check for validity of an atomic update | |
143 | * | |
144 | * The helper operations are called by the mid-layer CRTC helper. | |
145 | * | |
146 | * Note that with atomic helpers @dpms, @prepare and @commit hooks are | |
147 | * deprecated. Used @enable and @disable instead exclusively. | |
148 | * | |
149 | * With legacy crtc helpers there's a big semantic difference between @disable | |
150 | * and the other hooks: @disable also needs to release any resources acquired in | |
151 | * @mode_set (like shared PLLs). | |
152 | */ | |
153 | struct drm_encoder_helper_funcs { | |
154 | void (*dpms)(struct drm_encoder *encoder, int mode); | |
092d01da DV |
155 | |
156 | bool (*mode_fixup)(struct drm_encoder *encoder, | |
157 | const struct drm_display_mode *mode, | |
158 | struct drm_display_mode *adjusted_mode); | |
159 | void (*prepare)(struct drm_encoder *encoder); | |
160 | void (*commit)(struct drm_encoder *encoder); | |
161 | void (*mode_set)(struct drm_encoder *encoder, | |
162 | struct drm_display_mode *mode, | |
163 | struct drm_display_mode *adjusted_mode); | |
164 | struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder); | |
165 | /* detect for DAC style encoders */ | |
166 | enum drm_connector_status (*detect)(struct drm_encoder *encoder, | |
167 | struct drm_connector *connector); | |
168 | void (*disable)(struct drm_encoder *encoder); | |
169 | ||
170 | void (*enable)(struct drm_encoder *encoder); | |
171 | ||
172 | /* atomic helpers */ | |
173 | int (*atomic_check)(struct drm_encoder *encoder, | |
174 | struct drm_crtc_state *crtc_state, | |
175 | struct drm_connector_state *conn_state); | |
176 | }; | |
177 | ||
178 | /** | |
179 | * drm_encoder_helper_add - sets the helper vtable for a encoder | |
180 | * @encoder: DRM encoder | |
181 | * @funcs: helper vtable to set for @encoder | |
182 | */ | |
183 | static inline void drm_encoder_helper_add(struct drm_encoder *encoder, | |
184 | const struct drm_encoder_helper_funcs *funcs) | |
185 | { | |
186 | encoder->helper_private = funcs; | |
187 | } | |
188 | ||
189 | /** | |
190 | * struct drm_connector_helper_funcs - helper operations for connectors | |
191 | * @get_modes: get mode list for this connector | |
192 | * @mode_valid: is this mode valid on the given connector? (optional) | |
193 | * @best_encoder: return the preferred encoder for this connector | |
194 | * @atomic_best_encoder: atomic version of @best_encoder | |
195 | * | |
196 | * The helper operations are called by the mid-layer CRTC helper. | |
197 | */ | |
198 | struct drm_connector_helper_funcs { | |
199 | int (*get_modes)(struct drm_connector *connector); | |
200 | enum drm_mode_status (*mode_valid)(struct drm_connector *connector, | |
201 | struct drm_display_mode *mode); | |
202 | struct drm_encoder *(*best_encoder)(struct drm_connector *connector); | |
203 | struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector, | |
204 | struct drm_connector_state *connector_state); | |
205 | }; | |
206 | ||
207 | /** | |
208 | * drm_connector_helper_add - sets the helper vtable for a connector | |
209 | * @connector: DRM connector | |
210 | * @funcs: helper vtable to set for @connector | |
211 | */ | |
212 | static inline void drm_connector_helper_add(struct drm_connector *connector, | |
213 | const struct drm_connector_helper_funcs *funcs) | |
214 | { | |
215 | connector->helper_private = funcs; | |
216 | } | |
217 | ||
218 | /** | |
219 | * struct drm_plane_helper_funcs - helper operations for CRTCs | |
220 | * @prepare_fb: prepare a framebuffer for use by the plane | |
221 | * @cleanup_fb: cleanup a framebuffer when it's no longer used by the plane | |
222 | * @atomic_check: check that a given atomic state is valid and can be applied | |
223 | * @atomic_update: apply an atomic state to the plane (mandatory) | |
224 | * @atomic_disable: disable the plane | |
225 | * | |
226 | * The helper operations are called by the mid-layer CRTC helper. | |
227 | */ | |
228 | struct drm_plane_helper_funcs { | |
229 | int (*prepare_fb)(struct drm_plane *plane, | |
230 | const struct drm_plane_state *new_state); | |
231 | void (*cleanup_fb)(struct drm_plane *plane, | |
232 | const struct drm_plane_state *old_state); | |
233 | ||
234 | int (*atomic_check)(struct drm_plane *plane, | |
235 | struct drm_plane_state *state); | |
236 | void (*atomic_update)(struct drm_plane *plane, | |
237 | struct drm_plane_state *old_state); | |
238 | void (*atomic_disable)(struct drm_plane *plane, | |
239 | struct drm_plane_state *old_state); | |
240 | }; | |
241 | ||
242 | /** | |
243 | * drm_plane_helper_add - sets the helper vtable for a plane | |
244 | * @plane: DRM plane | |
245 | * @funcs: helper vtable to set for @plane | |
246 | */ | |
247 | static inline void drm_plane_helper_add(struct drm_plane *plane, | |
248 | const struct drm_plane_helper_funcs *funcs) | |
249 | { | |
250 | plane->helper_private = funcs; | |
251 | } | |
252 | ||
253 | #endif |