Rev 6283 | Rev 6660 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6283 | Rev 6296 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006-2008 Intel Corporation |
2 | * Copyright (c) 2006-2008 Intel Corporation |
3 | * Copyright (c) 2007 Dave Airlie |
3 | * Copyright (c) 2007 Dave Airlie |
4 | * Copyright (c) 2008 Red Hat Inc. |
4 | * Copyright (c) 2008 Red Hat Inc. |
5 | * |
5 | * |
6 | * DRM core CRTC related functions |
6 | * DRM core CRTC related functions |
7 | * |
7 | * |
8 | * Permission to use, copy, modify, distribute, and sell this software and its |
8 | * Permission to use, copy, modify, distribute, and sell this software and its |
9 | * documentation for any purpose is hereby granted without fee, provided that |
9 | * documentation for any purpose is hereby granted without fee, provided that |
10 | * the above copyright notice appear in all copies and that both that copyright |
10 | * the above copyright notice appear in all copies and that both that copyright |
11 | * notice and this permission notice appear in supporting documentation, and |
11 | * notice and this permission notice appear in supporting documentation, and |
12 | * that the name of the copyright holders not be used in advertising or |
12 | * that the name of the copyright holders not be used in advertising or |
13 | * publicity pertaining to distribution of the software without specific, |
13 | * publicity pertaining to distribution of the software without specific, |
14 | * written prior permission. The copyright holders make no representations |
14 | * written prior permission. The copyright holders make no representations |
15 | * about the suitability of this software for any purpose. It is provided "as |
15 | * about the suitability of this software for any purpose. It is provided "as |
16 | * is" without express or implied warranty. |
16 | * is" without express or implied warranty. |
17 | * |
17 | * |
18 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
18 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
19 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
19 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
20 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
20 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
21 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
21 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
22 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
22 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
23 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
23 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
24 | * OF THIS SOFTWARE. |
24 | * OF THIS SOFTWARE. |
25 | * |
25 | * |
26 | * Authors: |
26 | * Authors: |
27 | * Keith Packard |
27 | * Keith Packard |
28 | * Eric Anholt |
28 | * Eric Anholt |
29 | * Dave Airlie |
29 | * Dave Airlie |
30 | * Jesse Barnes |
30 | * Jesse Barnes |
31 | */ |
31 | */ |
32 | #include |
32 | #include |
33 | #include |
33 | #include |
34 | #include |
34 | #include |
35 | #include |
35 | #include |
36 | #include |
36 | #include |
37 | #include |
37 | #include |
38 | #include |
38 | #include |
39 | #include |
39 | #include |
40 | #include |
40 | #include |
41 | #include |
41 | #include |
42 | 42 | ||
43 | #include "drm_crtc_internal.h" |
43 | #include "drm_crtc_internal.h" |
44 | #include "drm_internal.h" |
44 | #include "drm_internal.h" |
45 | 45 | ||
46 | static struct drm_framebuffer * |
46 | static struct drm_framebuffer * |
47 | internal_framebuffer_create(struct drm_device *dev, |
47 | internal_framebuffer_create(struct drm_device *dev, |
48 | struct drm_mode_fb_cmd2 *r, |
48 | struct drm_mode_fb_cmd2 *r, |
49 | struct drm_file *file_priv); |
49 | struct drm_file *file_priv); |
50 | 50 | ||
51 | /* Avoid boilerplate. I'm tired of typing. */ |
51 | /* Avoid boilerplate. I'm tired of typing. */ |
52 | #define DRM_ENUM_NAME_FN(fnname, list) \ |
52 | #define DRM_ENUM_NAME_FN(fnname, list) \ |
53 | const char *fnname(int val) \ |
53 | const char *fnname(int val) \ |
54 | { \ |
54 | { \ |
55 | int i; \ |
55 | int i; \ |
56 | for (i = 0; i < ARRAY_SIZE(list); i++) { \ |
56 | for (i = 0; i < ARRAY_SIZE(list); i++) { \ |
57 | if (list[i].type == val) \ |
57 | if (list[i].type == val) \ |
58 | return list[i].name; \ |
58 | return list[i].name; \ |
59 | } \ |
59 | } \ |
60 | return "(unknown)"; \ |
60 | return "(unknown)"; \ |
61 | } |
61 | } |
62 | 62 | ||
63 | /* |
63 | /* |
64 | * Global properties |
64 | * Global properties |
65 | */ |
65 | */ |
66 | static const struct drm_prop_enum_list drm_dpms_enum_list[] = { |
66 | static const struct drm_prop_enum_list drm_dpms_enum_list[] = { |
67 | { DRM_MODE_DPMS_ON, "On" }, |
67 | { DRM_MODE_DPMS_ON, "On" }, |
68 | { DRM_MODE_DPMS_STANDBY, "Standby" }, |
68 | { DRM_MODE_DPMS_STANDBY, "Standby" }, |
69 | { DRM_MODE_DPMS_SUSPEND, "Suspend" }, |
69 | { DRM_MODE_DPMS_SUSPEND, "Suspend" }, |
70 | { DRM_MODE_DPMS_OFF, "Off" } |
70 | { DRM_MODE_DPMS_OFF, "Off" } |
71 | }; |
71 | }; |
72 | 72 | ||
73 | DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list) |
73 | DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list) |
74 | 74 | ||
75 | static const struct drm_prop_enum_list drm_plane_type_enum_list[] = { |
75 | static const struct drm_prop_enum_list drm_plane_type_enum_list[] = { |
76 | { DRM_PLANE_TYPE_OVERLAY, "Overlay" }, |
76 | { DRM_PLANE_TYPE_OVERLAY, "Overlay" }, |
77 | { DRM_PLANE_TYPE_PRIMARY, "Primary" }, |
77 | { DRM_PLANE_TYPE_PRIMARY, "Primary" }, |
78 | { DRM_PLANE_TYPE_CURSOR, "Cursor" }, |
78 | { DRM_PLANE_TYPE_CURSOR, "Cursor" }, |
79 | }; |
79 | }; |
80 | 80 | ||
81 | /* |
81 | /* |
82 | * Optional properties |
82 | * Optional properties |
83 | */ |
83 | */ |
84 | static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = { |
84 | static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = { |
85 | { DRM_MODE_SCALE_NONE, "None" }, |
85 | { DRM_MODE_SCALE_NONE, "None" }, |
86 | { DRM_MODE_SCALE_FULLSCREEN, "Full" }, |
86 | { DRM_MODE_SCALE_FULLSCREEN, "Full" }, |
87 | { DRM_MODE_SCALE_CENTER, "Center" }, |
87 | { DRM_MODE_SCALE_CENTER, "Center" }, |
88 | { DRM_MODE_SCALE_ASPECT, "Full aspect" }, |
88 | { DRM_MODE_SCALE_ASPECT, "Full aspect" }, |
89 | }; |
89 | }; |
90 | 90 | ||
91 | static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = { |
91 | static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = { |
92 | { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" }, |
92 | { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" }, |
93 | { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" }, |
93 | { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" }, |
94 | { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" }, |
94 | { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" }, |
95 | }; |
95 | }; |
96 | 96 | ||
97 | /* |
97 | /* |
98 | * Non-global properties, but "required" for certain connectors. |
98 | * Non-global properties, but "required" for certain connectors. |
99 | */ |
99 | */ |
100 | static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = { |
100 | static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = { |
101 | { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ |
101 | { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ |
102 | { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ |
102 | { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ |
103 | { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ |
103 | { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ |
104 | }; |
104 | }; |
105 | 105 | ||
106 | DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list) |
106 | DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list) |
107 | 107 | ||
108 | static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = { |
108 | static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = { |
109 | { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */ |
109 | { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */ |
110 | { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ |
110 | { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ |
111 | { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ |
111 | { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ |
112 | }; |
112 | }; |
113 | 113 | ||
114 | DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name, |
114 | DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name, |
115 | drm_dvi_i_subconnector_enum_list) |
115 | drm_dvi_i_subconnector_enum_list) |
116 | 116 | ||
117 | static const struct drm_prop_enum_list drm_tv_select_enum_list[] = { |
117 | static const struct drm_prop_enum_list drm_tv_select_enum_list[] = { |
118 | { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ |
118 | { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ |
119 | { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ |
119 | { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ |
120 | { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ |
120 | { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ |
121 | { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ |
121 | { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ |
122 | { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ |
122 | { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ |
123 | }; |
123 | }; |
124 | 124 | ||
125 | DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list) |
125 | DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list) |
126 | 126 | ||
127 | static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = { |
127 | static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = { |
128 | { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */ |
128 | { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */ |
129 | { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ |
129 | { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ |
130 | { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ |
130 | { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ |
131 | { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ |
131 | { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ |
132 | { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ |
132 | { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ |
133 | }; |
133 | }; |
134 | 134 | ||
135 | DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name, |
135 | DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name, |
136 | drm_tv_subconnector_enum_list) |
136 | drm_tv_subconnector_enum_list) |
137 | 137 | ||
138 | static const struct drm_prop_enum_list drm_dirty_info_enum_list[] = { |
138 | static const struct drm_prop_enum_list drm_dirty_info_enum_list[] = { |
139 | { DRM_MODE_DIRTY_OFF, "Off" }, |
139 | { DRM_MODE_DIRTY_OFF, "Off" }, |
140 | { DRM_MODE_DIRTY_ON, "On" }, |
140 | { DRM_MODE_DIRTY_ON, "On" }, |
141 | { DRM_MODE_DIRTY_ANNOTATE, "Annotate" }, |
141 | { DRM_MODE_DIRTY_ANNOTATE, "Annotate" }, |
142 | }; |
142 | }; |
143 | 143 | ||
144 | struct drm_conn_prop_enum_list { |
144 | struct drm_conn_prop_enum_list { |
145 | int type; |
145 | int type; |
146 | const char *name; |
146 | const char *name; |
147 | struct ida ida; |
147 | struct ida ida; |
148 | }; |
148 | }; |
149 | 149 | ||
150 | /* |
150 | /* |
151 | * Connector and encoder types. |
151 | * Connector and encoder types. |
152 | */ |
152 | */ |
153 | static struct drm_conn_prop_enum_list drm_connector_enum_list[] = { |
153 | static struct drm_conn_prop_enum_list drm_connector_enum_list[] = { |
154 | { DRM_MODE_CONNECTOR_Unknown, "Unknown" }, |
154 | { DRM_MODE_CONNECTOR_Unknown, "Unknown" }, |
155 | { DRM_MODE_CONNECTOR_VGA, "VGA" }, |
155 | { DRM_MODE_CONNECTOR_VGA, "VGA" }, |
156 | { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, |
156 | { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, |
157 | { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, |
157 | { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, |
158 | { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, |
158 | { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, |
159 | { DRM_MODE_CONNECTOR_Composite, "Composite" }, |
159 | { DRM_MODE_CONNECTOR_Composite, "Composite" }, |
160 | { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" }, |
160 | { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" }, |
161 | { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, |
161 | { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, |
162 | { DRM_MODE_CONNECTOR_Component, "Component" }, |
162 | { DRM_MODE_CONNECTOR_Component, "Component" }, |
163 | { DRM_MODE_CONNECTOR_9PinDIN, "DIN" }, |
163 | { DRM_MODE_CONNECTOR_9PinDIN, "DIN" }, |
164 | { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, |
164 | { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, |
165 | { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, |
165 | { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, |
166 | { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, |
166 | { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, |
167 | { DRM_MODE_CONNECTOR_TV, "TV" }, |
167 | { DRM_MODE_CONNECTOR_TV, "TV" }, |
168 | { DRM_MODE_CONNECTOR_eDP, "eDP" }, |
168 | { DRM_MODE_CONNECTOR_eDP, "eDP" }, |
169 | { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, |
169 | { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, |
170 | { DRM_MODE_CONNECTOR_DSI, "DSI" }, |
170 | { DRM_MODE_CONNECTOR_DSI, "DSI" }, |
171 | }; |
171 | }; |
172 | 172 | ||
173 | static const struct drm_prop_enum_list drm_encoder_enum_list[] = { |
173 | static const struct drm_prop_enum_list drm_encoder_enum_list[] = { |
174 | { DRM_MODE_ENCODER_NONE, "None" }, |
174 | { DRM_MODE_ENCODER_NONE, "None" }, |
175 | { DRM_MODE_ENCODER_DAC, "DAC" }, |
175 | { DRM_MODE_ENCODER_DAC, "DAC" }, |
176 | { DRM_MODE_ENCODER_TMDS, "TMDS" }, |
176 | { DRM_MODE_ENCODER_TMDS, "TMDS" }, |
177 | { DRM_MODE_ENCODER_LVDS, "LVDS" }, |
177 | { DRM_MODE_ENCODER_LVDS, "LVDS" }, |
178 | { DRM_MODE_ENCODER_TVDAC, "TV" }, |
178 | { DRM_MODE_ENCODER_TVDAC, "TV" }, |
179 | { DRM_MODE_ENCODER_VIRTUAL, "Virtual" }, |
179 | { DRM_MODE_ENCODER_VIRTUAL, "Virtual" }, |
180 | { DRM_MODE_ENCODER_DSI, "DSI" }, |
180 | { DRM_MODE_ENCODER_DSI, "DSI" }, |
181 | { DRM_MODE_ENCODER_DPMST, "DP MST" }, |
181 | { DRM_MODE_ENCODER_DPMST, "DP MST" }, |
182 | }; |
182 | }; |
183 | 183 | ||
184 | static const struct drm_prop_enum_list drm_subpixel_enum_list[] = { |
184 | static const struct drm_prop_enum_list drm_subpixel_enum_list[] = { |
185 | { SubPixelUnknown, "Unknown" }, |
185 | { SubPixelUnknown, "Unknown" }, |
186 | { SubPixelHorizontalRGB, "Horizontal RGB" }, |
186 | { SubPixelHorizontalRGB, "Horizontal RGB" }, |
187 | { SubPixelHorizontalBGR, "Horizontal BGR" }, |
187 | { SubPixelHorizontalBGR, "Horizontal BGR" }, |
188 | { SubPixelVerticalRGB, "Vertical RGB" }, |
188 | { SubPixelVerticalRGB, "Vertical RGB" }, |
189 | { SubPixelVerticalBGR, "Vertical BGR" }, |
189 | { SubPixelVerticalBGR, "Vertical BGR" }, |
190 | { SubPixelNone, "None" }, |
190 | { SubPixelNone, "None" }, |
191 | }; |
191 | }; |
192 | 192 | ||
193 | void drm_connector_ida_init(void) |
193 | void drm_connector_ida_init(void) |
194 | { |
194 | { |
195 | int i; |
195 | int i; |
196 | 196 | ||
197 | for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) |
197 | for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) |
198 | ida_init(&drm_connector_enum_list[i].ida); |
198 | ida_init(&drm_connector_enum_list[i].ida); |
199 | } |
199 | } |
200 | 200 | ||
201 | void drm_connector_ida_destroy(void) |
201 | void drm_connector_ida_destroy(void) |
202 | { |
202 | { |
203 | int i; |
203 | int i; |
204 | 204 | ||
205 | for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) |
205 | for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) |
206 | ida_destroy(&drm_connector_enum_list[i].ida); |
206 | ida_destroy(&drm_connector_enum_list[i].ida); |
207 | } |
207 | } |
208 | 208 | ||
209 | /** |
209 | /** |
210 | * drm_get_connector_status_name - return a string for connector status |
210 | * drm_get_connector_status_name - return a string for connector status |
211 | * @status: connector status to compute name of |
211 | * @status: connector status to compute name of |
212 | * |
212 | * |
213 | * In contrast to the other drm_get_*_name functions this one here returns a |
213 | * In contrast to the other drm_get_*_name functions this one here returns a |
214 | * const pointer and hence is threadsafe. |
214 | * const pointer and hence is threadsafe. |
215 | */ |
215 | */ |
216 | const char *drm_get_connector_status_name(enum drm_connector_status status) |
216 | const char *drm_get_connector_status_name(enum drm_connector_status status) |
217 | { |
217 | { |
218 | if (status == connector_status_connected) |
218 | if (status == connector_status_connected) |
219 | return "connected"; |
219 | return "connected"; |
220 | else if (status == connector_status_disconnected) |
220 | else if (status == connector_status_disconnected) |
221 | return "disconnected"; |
221 | return "disconnected"; |
222 | else |
222 | else |
223 | return "unknown"; |
223 | return "unknown"; |
224 | } |
224 | } |
225 | EXPORT_SYMBOL(drm_get_connector_status_name); |
225 | EXPORT_SYMBOL(drm_get_connector_status_name); |
226 | 226 | ||
227 | /** |
227 | /** |
228 | * drm_get_subpixel_order_name - return a string for a given subpixel enum |
228 | * drm_get_subpixel_order_name - return a string for a given subpixel enum |
229 | * @order: enum of subpixel_order |
229 | * @order: enum of subpixel_order |
230 | * |
230 | * |
231 | * Note you could abuse this and return something out of bounds, but that |
231 | * Note you could abuse this and return something out of bounds, but that |
232 | * would be a caller error. No unscrubbed user data should make it here. |
232 | * would be a caller error. No unscrubbed user data should make it here. |
233 | */ |
233 | */ |
234 | const char *drm_get_subpixel_order_name(enum subpixel_order order) |
234 | const char *drm_get_subpixel_order_name(enum subpixel_order order) |
235 | { |
235 | { |
236 | return drm_subpixel_enum_list[order].name; |
236 | return drm_subpixel_enum_list[order].name; |
237 | } |
237 | } |
238 | EXPORT_SYMBOL(drm_get_subpixel_order_name); |
238 | EXPORT_SYMBOL(drm_get_subpixel_order_name); |
239 | 239 | ||
240 | static char printable_char(int c) |
240 | static char printable_char(int c) |
241 | { |
241 | { |
242 | return isascii(c) && isprint(c) ? c : '?'; |
242 | return isascii(c) && isprint(c) ? c : '?'; |
243 | } |
243 | } |
244 | 244 | ||
245 | /** |
245 | /** |
246 | * drm_get_format_name - return a string for drm fourcc format |
246 | * drm_get_format_name - return a string for drm fourcc format |
247 | * @format: format to compute name of |
247 | * @format: format to compute name of |
248 | * |
248 | * |
249 | * Note that the buffer used by this function is globally shared and owned by |
249 | * Note that the buffer used by this function is globally shared and owned by |
250 | * the function itself. |
250 | * the function itself. |
251 | * |
251 | * |
252 | * FIXME: This isn't really multithreading safe. |
252 | * FIXME: This isn't really multithreading safe. |
253 | */ |
253 | */ |
254 | const char *drm_get_format_name(uint32_t format) |
254 | const char *drm_get_format_name(uint32_t format) |
255 | { |
255 | { |
256 | static char buf[32]; |
256 | static char buf[32]; |
257 | 257 | ||
258 | snprintf(buf, sizeof(buf), |
258 | snprintf(buf, sizeof(buf), |
259 | "%c%c%c%c %s-endian (0x%08x)", |
259 | "%c%c%c%c %s-endian (0x%08x)", |
260 | printable_char(format & 0xff), |
260 | printable_char(format & 0xff), |
261 | printable_char((format >> 8) & 0xff), |
261 | printable_char((format >> 8) & 0xff), |
262 | printable_char((format >> 16) & 0xff), |
262 | printable_char((format >> 16) & 0xff), |
263 | printable_char((format >> 24) & 0x7f), |
263 | printable_char((format >> 24) & 0x7f), |
264 | format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little", |
264 | format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little", |
265 | format); |
265 | format); |
266 | 266 | ||
267 | return buf; |
267 | return buf; |
268 | } |
268 | } |
269 | EXPORT_SYMBOL(drm_get_format_name); |
269 | EXPORT_SYMBOL(drm_get_format_name); |
270 | 270 | ||
271 | /* |
271 | /* |
272 | * Internal function to assign a slot in the object idr and optionally |
272 | * Internal function to assign a slot in the object idr and optionally |
273 | * register the object into the idr. |
273 | * register the object into the idr. |
274 | */ |
274 | */ |
275 | static int drm_mode_object_get_reg(struct drm_device *dev, |
275 | static int drm_mode_object_get_reg(struct drm_device *dev, |
276 | struct drm_mode_object *obj, |
276 | struct drm_mode_object *obj, |
277 | uint32_t obj_type, |
277 | uint32_t obj_type, |
278 | bool register_obj) |
278 | bool register_obj) |
279 | { |
279 | { |
280 | int ret; |
280 | int ret; |
281 | 281 | ||
282 | mutex_lock(&dev->mode_config.idr_mutex); |
282 | mutex_lock(&dev->mode_config.idr_mutex); |
283 | ret = idr_alloc(&dev->mode_config.crtc_idr, register_obj ? obj : NULL, 1, 0, GFP_KERNEL); |
283 | ret = idr_alloc(&dev->mode_config.crtc_idr, register_obj ? obj : NULL, 1, 0, GFP_KERNEL); |
284 | if (ret >= 0) { |
284 | if (ret >= 0) { |
285 | /* |
285 | /* |
286 | * Set up the object linking under the protection of the idr |
286 | * Set up the object linking under the protection of the idr |
287 | * lock so that other users can't see inconsistent state. |
287 | * lock so that other users can't see inconsistent state. |
288 | */ |
288 | */ |
289 | obj->id = ret; |
289 | obj->id = ret; |
290 | obj->type = obj_type; |
290 | obj->type = obj_type; |
291 | } |
291 | } |
292 | mutex_unlock(&dev->mode_config.idr_mutex); |
292 | mutex_unlock(&dev->mode_config.idr_mutex); |
293 | 293 | ||
294 | return ret < 0 ? ret : 0; |
294 | return ret < 0 ? ret : 0; |
295 | } |
295 | } |
296 | 296 | ||
297 | /** |
297 | /** |
298 | * drm_mode_object_get - allocate a new modeset identifier |
298 | * drm_mode_object_get - allocate a new modeset identifier |
299 | * @dev: DRM device |
299 | * @dev: DRM device |
300 | * @obj: object pointer, used to generate unique ID |
300 | * @obj: object pointer, used to generate unique ID |
301 | * @obj_type: object type |
301 | * @obj_type: object type |
302 | * |
302 | * |
303 | * Create a unique identifier based on @ptr in @dev's identifier space. Used |
303 | * Create a unique identifier based on @ptr in @dev's identifier space. Used |
304 | * for tracking modes, CRTCs and connectors. Note that despite the _get postfix |
304 | * for tracking modes, CRTCs and connectors. Note that despite the _get postfix |
305 | * modeset identifiers are _not_ reference counted. Hence don't use this for |
305 | * modeset identifiers are _not_ reference counted. Hence don't use this for |
306 | * reference counted modeset objects like framebuffers. |
306 | * reference counted modeset objects like framebuffers. |
307 | * |
307 | * |
308 | * Returns: |
308 | * Returns: |
309 | * Zero on success, error code on failure. |
309 | * Zero on success, error code on failure. |
310 | */ |
310 | */ |
311 | int drm_mode_object_get(struct drm_device *dev, |
311 | int drm_mode_object_get(struct drm_device *dev, |
312 | struct drm_mode_object *obj, uint32_t obj_type) |
312 | struct drm_mode_object *obj, uint32_t obj_type) |
313 | { |
313 | { |
314 | return drm_mode_object_get_reg(dev, obj, obj_type, true); |
314 | return drm_mode_object_get_reg(dev, obj, obj_type, true); |
315 | } |
315 | } |
316 | 316 | ||
317 | static void drm_mode_object_register(struct drm_device *dev, |
317 | static void drm_mode_object_register(struct drm_device *dev, |
318 | struct drm_mode_object *obj) |
318 | struct drm_mode_object *obj) |
319 | { |
319 | { |
320 | mutex_lock(&dev->mode_config.idr_mutex); |
320 | mutex_lock(&dev->mode_config.idr_mutex); |
321 | idr_replace(&dev->mode_config.crtc_idr, obj, obj->id); |
321 | idr_replace(&dev->mode_config.crtc_idr, obj, obj->id); |
322 | mutex_unlock(&dev->mode_config.idr_mutex); |
322 | mutex_unlock(&dev->mode_config.idr_mutex); |
323 | } |
323 | } |
324 | 324 | ||
325 | /** |
325 | /** |
326 | * drm_mode_object_put - free a modeset identifer |
326 | * drm_mode_object_put - free a modeset identifer |
327 | * @dev: DRM device |
327 | * @dev: DRM device |
328 | * @object: object to free |
328 | * @object: object to free |
329 | * |
329 | * |
330 | * Free @id from @dev's unique identifier pool. Note that despite the _get |
330 | * Free @id from @dev's unique identifier pool. Note that despite the _get |
331 | * postfix modeset identifiers are _not_ reference counted. Hence don't use this |
331 | * postfix modeset identifiers are _not_ reference counted. Hence don't use this |
332 | * for reference counted modeset objects like framebuffers. |
332 | * for reference counted modeset objects like framebuffers. |
333 | */ |
333 | */ |
334 | void drm_mode_object_put(struct drm_device *dev, |
334 | void drm_mode_object_put(struct drm_device *dev, |
335 | struct drm_mode_object *object) |
335 | struct drm_mode_object *object) |
336 | { |
336 | { |
337 | mutex_lock(&dev->mode_config.idr_mutex); |
337 | mutex_lock(&dev->mode_config.idr_mutex); |
338 | idr_remove(&dev->mode_config.crtc_idr, object->id); |
338 | idr_remove(&dev->mode_config.crtc_idr, object->id); |
339 | mutex_unlock(&dev->mode_config.idr_mutex); |
339 | mutex_unlock(&dev->mode_config.idr_mutex); |
340 | } |
340 | } |
341 | 341 | ||
342 | static struct drm_mode_object *_object_find(struct drm_device *dev, |
342 | static struct drm_mode_object *_object_find(struct drm_device *dev, |
343 | uint32_t id, uint32_t type) |
343 | uint32_t id, uint32_t type) |
344 | { |
344 | { |
345 | struct drm_mode_object *obj = NULL; |
345 | struct drm_mode_object *obj = NULL; |
346 | 346 | ||
347 | mutex_lock(&dev->mode_config.idr_mutex); |
347 | mutex_lock(&dev->mode_config.idr_mutex); |
348 | obj = idr_find(&dev->mode_config.crtc_idr, id); |
348 | obj = idr_find(&dev->mode_config.crtc_idr, id); |
349 | if (obj && type != DRM_MODE_OBJECT_ANY && obj->type != type) |
349 | if (obj && type != DRM_MODE_OBJECT_ANY && obj->type != type) |
350 | obj = NULL; |
350 | obj = NULL; |
351 | if (obj && obj->id != id) |
351 | if (obj && obj->id != id) |
352 | obj = NULL; |
352 | obj = NULL; |
353 | /* don't leak out unref'd fb's */ |
353 | /* don't leak out unref'd fb's */ |
354 | if (obj && |
354 | if (obj && |
355 | (obj->type == DRM_MODE_OBJECT_FB || |
355 | (obj->type == DRM_MODE_OBJECT_FB || |
356 | obj->type == DRM_MODE_OBJECT_BLOB)) |
356 | obj->type == DRM_MODE_OBJECT_BLOB)) |
357 | obj = NULL; |
357 | obj = NULL; |
358 | mutex_unlock(&dev->mode_config.idr_mutex); |
358 | mutex_unlock(&dev->mode_config.idr_mutex); |
359 | 359 | ||
360 | return obj; |
360 | return obj; |
361 | } |
361 | } |
362 | 362 | ||
363 | /** |
363 | /** |
364 | * drm_mode_object_find - look up a drm object with static lifetime |
364 | * drm_mode_object_find - look up a drm object with static lifetime |
365 | * @dev: drm device |
365 | * @dev: drm device |
366 | * @id: id of the mode object |
366 | * @id: id of the mode object |
367 | * @type: type of the mode object |
367 | * @type: type of the mode object |
368 | * |
368 | * |
369 | * Note that framebuffers cannot be looked up with this functions - since those |
369 | * Note that framebuffers cannot be looked up with this functions - since those |
370 | * are reference counted, they need special treatment. Even with |
370 | * are reference counted, they need special treatment. Even with |
371 | * DRM_MODE_OBJECT_ANY (although that will simply return NULL |
371 | * DRM_MODE_OBJECT_ANY (although that will simply return NULL |
372 | * rather than WARN_ON()). |
372 | * rather than WARN_ON()). |
373 | */ |
373 | */ |
374 | struct drm_mode_object *drm_mode_object_find(struct drm_device *dev, |
374 | struct drm_mode_object *drm_mode_object_find(struct drm_device *dev, |
375 | uint32_t id, uint32_t type) |
375 | uint32_t id, uint32_t type) |
376 | { |
376 | { |
377 | struct drm_mode_object *obj = NULL; |
377 | struct drm_mode_object *obj = NULL; |
378 | 378 | ||
379 | /* Framebuffers are reference counted and need their own lookup |
379 | /* Framebuffers are reference counted and need their own lookup |
380 | * function.*/ |
380 | * function.*/ |
381 | WARN_ON(type == DRM_MODE_OBJECT_FB || type == DRM_MODE_OBJECT_BLOB); |
381 | WARN_ON(type == DRM_MODE_OBJECT_FB || type == DRM_MODE_OBJECT_BLOB); |
382 | obj = _object_find(dev, id, type); |
382 | obj = _object_find(dev, id, type); |
383 | return obj; |
383 | return obj; |
384 | } |
384 | } |
385 | EXPORT_SYMBOL(drm_mode_object_find); |
385 | EXPORT_SYMBOL(drm_mode_object_find); |
386 | 386 | ||
387 | /** |
387 | /** |
388 | * drm_framebuffer_init - initialize a framebuffer |
388 | * drm_framebuffer_init - initialize a framebuffer |
389 | * @dev: DRM device |
389 | * @dev: DRM device |
390 | * @fb: framebuffer to be initialized |
390 | * @fb: framebuffer to be initialized |
391 | * @funcs: ... with these functions |
391 | * @funcs: ... with these functions |
392 | * |
392 | * |
393 | * Allocates an ID for the framebuffer's parent mode object, sets its mode |
393 | * Allocates an ID for the framebuffer's parent mode object, sets its mode |
394 | * functions & device file and adds it to the master fd list. |
394 | * functions & device file and adds it to the master fd list. |
395 | * |
395 | * |
396 | * IMPORTANT: |
396 | * IMPORTANT: |
397 | * This functions publishes the fb and makes it available for concurrent access |
397 | * This functions publishes the fb and makes it available for concurrent access |
398 | * by other users. Which means by this point the fb _must_ be fully set up - |
398 | * by other users. Which means by this point the fb _must_ be fully set up - |
399 | * since all the fb attributes are invariant over its lifetime, no further |
399 | * since all the fb attributes are invariant over its lifetime, no further |
400 | * locking but only correct reference counting is required. |
400 | * locking but only correct reference counting is required. |
401 | * |
401 | * |
402 | * Returns: |
402 | * Returns: |
403 | * Zero on success, error code on failure. |
403 | * Zero on success, error code on failure. |
404 | */ |
404 | */ |
405 | int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb, |
405 | int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb, |
406 | const struct drm_framebuffer_funcs *funcs) |
406 | const struct drm_framebuffer_funcs *funcs) |
407 | { |
407 | { |
408 | int ret; |
408 | int ret; |
409 | 409 | ||
410 | mutex_lock(&dev->mode_config.fb_lock); |
410 | mutex_lock(&dev->mode_config.fb_lock); |
411 | kref_init(&fb->refcount); |
411 | kref_init(&fb->refcount); |
412 | INIT_LIST_HEAD(&fb->filp_head); |
412 | INIT_LIST_HEAD(&fb->filp_head); |
413 | fb->dev = dev; |
413 | fb->dev = dev; |
414 | fb->funcs = funcs; |
414 | fb->funcs = funcs; |
415 | 415 | ||
416 | ret = drm_mode_object_get(dev, &fb->base, DRM_MODE_OBJECT_FB); |
416 | ret = drm_mode_object_get(dev, &fb->base, DRM_MODE_OBJECT_FB); |
417 | if (ret) |
417 | if (ret) |
418 | goto out; |
418 | goto out; |
419 | 419 | ||
420 | dev->mode_config.num_fb++; |
420 | dev->mode_config.num_fb++; |
421 | list_add(&fb->head, &dev->mode_config.fb_list); |
421 | list_add(&fb->head, &dev->mode_config.fb_list); |
422 | out: |
422 | out: |
423 | mutex_unlock(&dev->mode_config.fb_lock); |
423 | mutex_unlock(&dev->mode_config.fb_lock); |
424 | 424 | ||
425 | return ret; |
425 | return ret; |
426 | } |
426 | } |
427 | EXPORT_SYMBOL(drm_framebuffer_init); |
427 | EXPORT_SYMBOL(drm_framebuffer_init); |
428 | 428 | ||
429 | /* dev->mode_config.fb_lock must be held! */ |
429 | /* dev->mode_config.fb_lock must be held! */ |
430 | static void __drm_framebuffer_unregister(struct drm_device *dev, |
430 | static void __drm_framebuffer_unregister(struct drm_device *dev, |
431 | struct drm_framebuffer *fb) |
431 | struct drm_framebuffer *fb) |
432 | { |
432 | { |
433 | mutex_lock(&dev->mode_config.idr_mutex); |
433 | mutex_lock(&dev->mode_config.idr_mutex); |
434 | idr_remove(&dev->mode_config.crtc_idr, fb->base.id); |
434 | idr_remove(&dev->mode_config.crtc_idr, fb->base.id); |
435 | mutex_unlock(&dev->mode_config.idr_mutex); |
435 | mutex_unlock(&dev->mode_config.idr_mutex); |
436 | 436 | ||
437 | fb->base.id = 0; |
437 | fb->base.id = 0; |
438 | } |
438 | } |
439 | 439 | ||
440 | static void drm_framebuffer_free(struct kref *kref) |
440 | static void drm_framebuffer_free(struct kref *kref) |
441 | { |
441 | { |
442 | struct drm_framebuffer *fb = |
442 | struct drm_framebuffer *fb = |
443 | container_of(kref, struct drm_framebuffer, refcount); |
443 | container_of(kref, struct drm_framebuffer, refcount); |
444 | struct drm_device *dev = fb->dev; |
444 | struct drm_device *dev = fb->dev; |
445 | 445 | ||
446 | /* |
446 | /* |
447 | * The lookup idr holds a weak reference, which has not necessarily been |
447 | * The lookup idr holds a weak reference, which has not necessarily been |
448 | * removed at this point. Check for that. |
448 | * removed at this point. Check for that. |
449 | */ |
449 | */ |
450 | mutex_lock(&dev->mode_config.fb_lock); |
450 | mutex_lock(&dev->mode_config.fb_lock); |
451 | if (fb->base.id) { |
451 | if (fb->base.id) { |
452 | /* Mark fb as reaped and drop idr ref. */ |
452 | /* Mark fb as reaped and drop idr ref. */ |
453 | __drm_framebuffer_unregister(dev, fb); |
453 | __drm_framebuffer_unregister(dev, fb); |
454 | } |
454 | } |
455 | mutex_unlock(&dev->mode_config.fb_lock); |
455 | mutex_unlock(&dev->mode_config.fb_lock); |
456 | 456 | ||
457 | fb->funcs->destroy(fb); |
457 | fb->funcs->destroy(fb); |
458 | } |
458 | } |
459 | 459 | ||
460 | static struct drm_framebuffer *__drm_framebuffer_lookup(struct drm_device *dev, |
460 | static struct drm_framebuffer *__drm_framebuffer_lookup(struct drm_device *dev, |
461 | uint32_t id) |
461 | uint32_t id) |
462 | { |
462 | { |
463 | struct drm_mode_object *obj = NULL; |
463 | struct drm_mode_object *obj = NULL; |
464 | struct drm_framebuffer *fb; |
464 | struct drm_framebuffer *fb; |
465 | 465 | ||
466 | mutex_lock(&dev->mode_config.idr_mutex); |
466 | mutex_lock(&dev->mode_config.idr_mutex); |
467 | obj = idr_find(&dev->mode_config.crtc_idr, id); |
467 | obj = idr_find(&dev->mode_config.crtc_idr, id); |
468 | if (!obj || (obj->type != DRM_MODE_OBJECT_FB) || (obj->id != id)) |
468 | if (!obj || (obj->type != DRM_MODE_OBJECT_FB) || (obj->id != id)) |
469 | fb = NULL; |
469 | fb = NULL; |
470 | else |
470 | else |
471 | fb = obj_to_fb(obj); |
471 | fb = obj_to_fb(obj); |
472 | mutex_unlock(&dev->mode_config.idr_mutex); |
472 | mutex_unlock(&dev->mode_config.idr_mutex); |
473 | 473 | ||
474 | return fb; |
474 | return fb; |
475 | } |
475 | } |
476 | 476 | ||
477 | /** |
477 | /** |
478 | * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference |
478 | * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference |
479 | * @dev: drm device |
479 | * @dev: drm device |
480 | * @id: id of the fb object |
480 | * @id: id of the fb object |
481 | * |
481 | * |
482 | * If successful, this grabs an additional reference to the framebuffer - |
482 | * If successful, this grabs an additional reference to the framebuffer - |
483 | * callers need to make sure to eventually unreference the returned framebuffer |
483 | * callers need to make sure to eventually unreference the returned framebuffer |
484 | * again, using @drm_framebuffer_unreference. |
484 | * again, using @drm_framebuffer_unreference. |
485 | */ |
485 | */ |
486 | struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev, |
486 | struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev, |
487 | uint32_t id) |
487 | uint32_t id) |
488 | { |
488 | { |
489 | struct drm_framebuffer *fb; |
489 | struct drm_framebuffer *fb; |
490 | 490 | ||
491 | mutex_lock(&dev->mode_config.fb_lock); |
491 | mutex_lock(&dev->mode_config.fb_lock); |
492 | fb = __drm_framebuffer_lookup(dev, id); |
492 | fb = __drm_framebuffer_lookup(dev, id); |
493 | if (fb) { |
493 | if (fb) { |
494 | if (!kref_get_unless_zero(&fb->refcount)) |
494 | if (!kref_get_unless_zero(&fb->refcount)) |
495 | fb = NULL; |
495 | fb = NULL; |
496 | } |
496 | } |
497 | mutex_unlock(&dev->mode_config.fb_lock); |
497 | mutex_unlock(&dev->mode_config.fb_lock); |
498 | 498 | ||
499 | return fb; |
499 | return fb; |
500 | } |
500 | } |
501 | EXPORT_SYMBOL(drm_framebuffer_lookup); |
501 | EXPORT_SYMBOL(drm_framebuffer_lookup); |
502 | 502 | ||
503 | /** |
503 | /** |
504 | * drm_framebuffer_unreference - unref a framebuffer |
504 | * drm_framebuffer_unreference - unref a framebuffer |
505 | * @fb: framebuffer to unref |
505 | * @fb: framebuffer to unref |
506 | * |
506 | * |
507 | * This functions decrements the fb's refcount and frees it if it drops to zero. |
507 | * This functions decrements the fb's refcount and frees it if it drops to zero. |
508 | */ |
508 | */ |
509 | void drm_framebuffer_unreference(struct drm_framebuffer *fb) |
509 | void drm_framebuffer_unreference(struct drm_framebuffer *fb) |
510 | { |
510 | { |
511 | DRM_DEBUG("%p: FB ID: %d (%d)\n", fb, fb->base.id, atomic_read(&fb->refcount.refcount)); |
511 | DRM_DEBUG("%p: FB ID: %d (%d)\n", fb, fb->base.id, atomic_read(&fb->refcount.refcount)); |
512 | kref_put(&fb->refcount, drm_framebuffer_free); |
512 | kref_put(&fb->refcount, drm_framebuffer_free); |
513 | } |
513 | } |
514 | EXPORT_SYMBOL(drm_framebuffer_unreference); |
514 | EXPORT_SYMBOL(drm_framebuffer_unreference); |
515 | 515 | ||
516 | /** |
516 | /** |
517 | * drm_framebuffer_reference - incr the fb refcnt |
517 | * drm_framebuffer_reference - incr the fb refcnt |
518 | * @fb: framebuffer |
518 | * @fb: framebuffer |
519 | * |
519 | * |
520 | * This functions increments the fb's refcount. |
520 | * This functions increments the fb's refcount. |
521 | */ |
521 | */ |
522 | void drm_framebuffer_reference(struct drm_framebuffer *fb) |
522 | void drm_framebuffer_reference(struct drm_framebuffer *fb) |
523 | { |
523 | { |
524 | DRM_DEBUG("%p: FB ID: %d (%d)\n", fb, fb->base.id, atomic_read(&fb->refcount.refcount)); |
524 | DRM_DEBUG("%p: FB ID: %d (%d)\n", fb, fb->base.id, atomic_read(&fb->refcount.refcount)); |
525 | kref_get(&fb->refcount); |
525 | kref_get(&fb->refcount); |
526 | } |
526 | } |
527 | EXPORT_SYMBOL(drm_framebuffer_reference); |
527 | EXPORT_SYMBOL(drm_framebuffer_reference); |
528 | 528 | ||
529 | /** |
529 | /** |
530 | * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr |
530 | * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr |
531 | * @fb: fb to unregister |
531 | * @fb: fb to unregister |
532 | * |
532 | * |
533 | * Drivers need to call this when cleaning up driver-private framebuffers, e.g. |
533 | * Drivers need to call this when cleaning up driver-private framebuffers, e.g. |
534 | * those used for fbdev. Note that the caller must hold a reference of it's own, |
534 | * those used for fbdev. Note that the caller must hold a reference of it's own, |
535 | * i.e. the object may not be destroyed through this call (since it'll lead to a |
535 | * i.e. the object may not be destroyed through this call (since it'll lead to a |
536 | * locking inversion). |
536 | * locking inversion). |
537 | */ |
537 | */ |
538 | void drm_framebuffer_unregister_private(struct drm_framebuffer *fb) |
538 | void drm_framebuffer_unregister_private(struct drm_framebuffer *fb) |
539 | { |
539 | { |
540 | struct drm_device *dev; |
540 | struct drm_device *dev; |
541 | 541 | ||
542 | if (!fb) |
542 | if (!fb) |
543 | return; |
543 | return; |
544 | 544 | ||
545 | dev = fb->dev; |
545 | dev = fb->dev; |
546 | 546 | ||
547 | mutex_lock(&dev->mode_config.fb_lock); |
547 | mutex_lock(&dev->mode_config.fb_lock); |
548 | /* Mark fb as reaped and drop idr ref. */ |
548 | /* Mark fb as reaped and drop idr ref. */ |
549 | __drm_framebuffer_unregister(dev, fb); |
549 | __drm_framebuffer_unregister(dev, fb); |
550 | mutex_unlock(&dev->mode_config.fb_lock); |
550 | mutex_unlock(&dev->mode_config.fb_lock); |
551 | } |
551 | } |
552 | EXPORT_SYMBOL(drm_framebuffer_unregister_private); |
552 | EXPORT_SYMBOL(drm_framebuffer_unregister_private); |
553 | 553 | ||
554 | /** |
554 | /** |
555 | * drm_framebuffer_cleanup - remove a framebuffer object |
555 | * drm_framebuffer_cleanup - remove a framebuffer object |
556 | * @fb: framebuffer to remove |
556 | * @fb: framebuffer to remove |
557 | * |
557 | * |
558 | * Cleanup framebuffer. This function is intended to be used from the drivers |
558 | * Cleanup framebuffer. This function is intended to be used from the drivers |
559 | * ->destroy callback. It can also be used to clean up driver private |
559 | * ->destroy callback. It can also be used to clean up driver private |
560 | * framebuffers embedded into a larger structure. |
560 | * framebuffers embedded into a larger structure. |
561 | * |
561 | * |
562 | * Note that this function does not remove the fb from active usuage - if it is |
562 | * Note that this function does not remove the fb from active usuage - if it is |
563 | * still used anywhere, hilarity can ensue since userspace could call getfb on |
563 | * still used anywhere, hilarity can ensue since userspace could call getfb on |
564 | * the id and get back -EINVAL. Obviously no concern at driver unload time. |
564 | * the id and get back -EINVAL. Obviously no concern at driver unload time. |
565 | * |
565 | * |
566 | * Also, the framebuffer will not be removed from the lookup idr - for |
566 | * Also, the framebuffer will not be removed from the lookup idr - for |
567 | * user-created framebuffers this will happen in in the rmfb ioctl. For |
567 | * user-created framebuffers this will happen in in the rmfb ioctl. For |
568 | * driver-private objects (e.g. for fbdev) drivers need to explicitly call |
568 | * driver-private objects (e.g. for fbdev) drivers need to explicitly call |
569 | * drm_framebuffer_unregister_private. |
569 | * drm_framebuffer_unregister_private. |
570 | */ |
570 | */ |
571 | void drm_framebuffer_cleanup(struct drm_framebuffer *fb) |
571 | void drm_framebuffer_cleanup(struct drm_framebuffer *fb) |
572 | { |
572 | { |
573 | struct drm_device *dev = fb->dev; |
573 | struct drm_device *dev = fb->dev; |
574 | 574 | ||
575 | mutex_lock(&dev->mode_config.fb_lock); |
575 | mutex_lock(&dev->mode_config.fb_lock); |
576 | list_del(&fb->head); |
576 | list_del(&fb->head); |
577 | dev->mode_config.num_fb--; |
577 | dev->mode_config.num_fb--; |
578 | mutex_unlock(&dev->mode_config.fb_lock); |
578 | mutex_unlock(&dev->mode_config.fb_lock); |
579 | } |
579 | } |
580 | EXPORT_SYMBOL(drm_framebuffer_cleanup); |
580 | EXPORT_SYMBOL(drm_framebuffer_cleanup); |
581 | 581 | ||
582 | /** |
582 | /** |
583 | * drm_framebuffer_remove - remove and unreference a framebuffer object |
583 | * drm_framebuffer_remove - remove and unreference a framebuffer object |
584 | * @fb: framebuffer to remove |
584 | * @fb: framebuffer to remove |
585 | * |
585 | * |
586 | * Scans all the CRTCs and planes in @dev's mode_config. If they're |
586 | * Scans all the CRTCs and planes in @dev's mode_config. If they're |
587 | * using @fb, removes it, setting it to NULL. Then drops the reference to the |
587 | * using @fb, removes it, setting it to NULL. Then drops the reference to the |
588 | * passed-in framebuffer. Might take the modeset locks. |
588 | * passed-in framebuffer. Might take the modeset locks. |
589 | * |
589 | * |
590 | * Note that this function optimizes the cleanup away if the caller holds the |
590 | * Note that this function optimizes the cleanup away if the caller holds the |
591 | * last reference to the framebuffer. It is also guaranteed to not take the |
591 | * last reference to the framebuffer. It is also guaranteed to not take the |
592 | * modeset locks in this case. |
592 | * modeset locks in this case. |
593 | */ |
593 | */ |
594 | void drm_framebuffer_remove(struct drm_framebuffer *fb) |
594 | void drm_framebuffer_remove(struct drm_framebuffer *fb) |
595 | { |
595 | { |
596 | struct drm_device *dev; |
596 | struct drm_device *dev; |
597 | struct drm_crtc *crtc; |
597 | struct drm_crtc *crtc; |
598 | struct drm_plane *plane; |
598 | struct drm_plane *plane; |
599 | struct drm_mode_set set; |
599 | struct drm_mode_set set; |
600 | int ret; |
600 | int ret; |
601 | 601 | ||
602 | if (!fb) |
602 | if (!fb) |
603 | return; |
603 | return; |
604 | 604 | ||
605 | dev = fb->dev; |
605 | dev = fb->dev; |
606 | 606 | ||
607 | WARN_ON(!list_empty(&fb->filp_head)); |
607 | WARN_ON(!list_empty(&fb->filp_head)); |
608 | 608 | ||
609 | /* |
609 | /* |
610 | * drm ABI mandates that we remove any deleted framebuffers from active |
610 | * drm ABI mandates that we remove any deleted framebuffers from active |
611 | * useage. But since most sane clients only remove framebuffers they no |
611 | * useage. But since most sane clients only remove framebuffers they no |
612 | * longer need, try to optimize this away. |
612 | * longer need, try to optimize this away. |
613 | * |
613 | * |
614 | * Since we're holding a reference ourselves, observing a refcount of 1 |
614 | * Since we're holding a reference ourselves, observing a refcount of 1 |
615 | * means that we're the last holder and can skip it. Also, the refcount |
615 | * means that we're the last holder and can skip it. Also, the refcount |
616 | * can never increase from 1 again, so we don't need any barriers or |
616 | * can never increase from 1 again, so we don't need any barriers or |
617 | * locks. |
617 | * locks. |
618 | * |
618 | * |
619 | * Note that userspace could try to race with use and instate a new |
619 | * Note that userspace could try to race with use and instate a new |
620 | * usage _after_ we've cleared all current ones. End result will be an |
620 | * usage _after_ we've cleared all current ones. End result will be an |
621 | * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot |
621 | * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot |
622 | * in this manner. |
622 | * in this manner. |
623 | */ |
623 | */ |
624 | if (atomic_read(&fb->refcount.refcount) > 1) { |
624 | if (atomic_read(&fb->refcount.refcount) > 1) { |
625 | drm_modeset_lock_all(dev); |
625 | drm_modeset_lock_all(dev); |
626 | /* remove from any CRTC */ |
626 | /* remove from any CRTC */ |
627 | drm_for_each_crtc(crtc, dev) { |
627 | drm_for_each_crtc(crtc, dev) { |
628 | if (crtc->primary->fb == fb) { |
628 | if (crtc->primary->fb == fb) { |
629 | /* should turn off the crtc */ |
629 | /* should turn off the crtc */ |
630 | memset(&set, 0, sizeof(struct drm_mode_set)); |
630 | memset(&set, 0, sizeof(struct drm_mode_set)); |
631 | set.crtc = crtc; |
631 | set.crtc = crtc; |
632 | set.fb = NULL; |
632 | set.fb = NULL; |
633 | ret = drm_mode_set_config_internal(&set); |
633 | ret = drm_mode_set_config_internal(&set); |
634 | if (ret) |
634 | if (ret) |
635 | DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc); |
635 | DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc); |
636 | } |
636 | } |
637 | } |
637 | } |
638 | 638 | ||
639 | drm_for_each_plane(plane, dev) { |
639 | drm_for_each_plane(plane, dev) { |
640 | if (plane->fb == fb) |
640 | if (plane->fb == fb) |
641 | drm_plane_force_disable(plane); |
641 | drm_plane_force_disable(plane); |
642 | } |
642 | } |
643 | drm_modeset_unlock_all(dev); |
643 | drm_modeset_unlock_all(dev); |
644 | } |
644 | } |
645 | 645 | ||
646 | drm_framebuffer_unreference(fb); |
646 | drm_framebuffer_unreference(fb); |
647 | } |
647 | } |
648 | EXPORT_SYMBOL(drm_framebuffer_remove); |
648 | EXPORT_SYMBOL(drm_framebuffer_remove); |
649 | 649 | ||
650 | DEFINE_WW_CLASS(crtc_ww_class); |
650 | DEFINE_WW_CLASS(crtc_ww_class); |
651 | 651 | ||
652 | /** |
652 | /** |
653 | * drm_crtc_init_with_planes - Initialise a new CRTC object with |
653 | * drm_crtc_init_with_planes - Initialise a new CRTC object with |
654 | * specified primary and cursor planes. |
654 | * specified primary and cursor planes. |
655 | * @dev: DRM device |
655 | * @dev: DRM device |
656 | * @crtc: CRTC object to init |
656 | * @crtc: CRTC object to init |
657 | * @primary: Primary plane for CRTC |
657 | * @primary: Primary plane for CRTC |
658 | * @cursor: Cursor plane for CRTC |
658 | * @cursor: Cursor plane for CRTC |
659 | * @funcs: callbacks for the new CRTC |
659 | * @funcs: callbacks for the new CRTC |
660 | * |
660 | * |
661 | * Inits a new object created as base part of a driver crtc object. |
661 | * Inits a new object created as base part of a driver crtc object. |
662 | * |
662 | * |
663 | * Returns: |
663 | * Returns: |
664 | * Zero on success, error code on failure. |
664 | * Zero on success, error code on failure. |
665 | */ |
665 | */ |
666 | int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc, |
666 | int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc, |
667 | struct drm_plane *primary, |
667 | struct drm_plane *primary, |
668 | struct drm_plane *cursor, |
668 | struct drm_plane *cursor, |
669 | const struct drm_crtc_funcs *funcs) |
669 | const struct drm_crtc_funcs *funcs) |
670 | { |
670 | { |
671 | struct drm_mode_config *config = &dev->mode_config; |
671 | struct drm_mode_config *config = &dev->mode_config; |
672 | int ret; |
672 | int ret; |
673 | 673 | ||
674 | WARN_ON(primary && primary->type != DRM_PLANE_TYPE_PRIMARY); |
674 | WARN_ON(primary && primary->type != DRM_PLANE_TYPE_PRIMARY); |
675 | WARN_ON(cursor && cursor->type != DRM_PLANE_TYPE_CURSOR); |
675 | WARN_ON(cursor && cursor->type != DRM_PLANE_TYPE_CURSOR); |
676 | 676 | ||
677 | crtc->dev = dev; |
677 | crtc->dev = dev; |
678 | crtc->funcs = funcs; |
678 | crtc->funcs = funcs; |
679 | 679 | ||
680 | drm_modeset_lock_init(&crtc->mutex); |
680 | drm_modeset_lock_init(&crtc->mutex); |
681 | ret = drm_mode_object_get(dev, &crtc->base, DRM_MODE_OBJECT_CRTC); |
681 | ret = drm_mode_object_get(dev, &crtc->base, DRM_MODE_OBJECT_CRTC); |
682 | if (ret) |
682 | if (ret) |
683 | return ret; |
683 | return ret; |
684 | 684 | ||
685 | crtc->base.properties = &crtc->properties; |
685 | crtc->base.properties = &crtc->properties; |
686 | 686 | ||
687 | list_add_tail(&crtc->head, &config->crtc_list); |
687 | list_add_tail(&crtc->head, &config->crtc_list); |
688 | config->num_crtc++; |
688 | config->num_crtc++; |
689 | 689 | ||
690 | crtc->primary = primary; |
690 | crtc->primary = primary; |
691 | crtc->cursor = cursor; |
691 | crtc->cursor = cursor; |
692 | if (primary) |
692 | if (primary) |
693 | primary->possible_crtcs = 1 << drm_crtc_index(crtc); |
693 | primary->possible_crtcs = 1 << drm_crtc_index(crtc); |
694 | if (cursor) |
694 | if (cursor) |
695 | cursor->possible_crtcs = 1 << drm_crtc_index(crtc); |
695 | cursor->possible_crtcs = 1 << drm_crtc_index(crtc); |
696 | 696 | ||
697 | if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { |
697 | if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { |
698 | drm_object_attach_property(&crtc->base, config->prop_active, 0); |
698 | drm_object_attach_property(&crtc->base, config->prop_active, 0); |
699 | drm_object_attach_property(&crtc->base, config->prop_mode_id, 0); |
699 | drm_object_attach_property(&crtc->base, config->prop_mode_id, 0); |
700 | } |
700 | } |
701 | 701 | ||
702 | return 0; |
702 | return 0; |
703 | } |
703 | } |
704 | EXPORT_SYMBOL(drm_crtc_init_with_planes); |
704 | EXPORT_SYMBOL(drm_crtc_init_with_planes); |
705 | 705 | ||
706 | /** |
706 | /** |
707 | * drm_crtc_cleanup - Clean up the core crtc usage |
707 | * drm_crtc_cleanup - Clean up the core crtc usage |
708 | * @crtc: CRTC to cleanup |
708 | * @crtc: CRTC to cleanup |
709 | * |
709 | * |
710 | * This function cleans up @crtc and removes it from the DRM mode setting |
710 | * This function cleans up @crtc and removes it from the DRM mode setting |
711 | * core. Note that the function does *not* free the crtc structure itself, |
711 | * core. Note that the function does *not* free the crtc structure itself, |
712 | * this is the responsibility of the caller. |
712 | * this is the responsibility of the caller. |
713 | */ |
713 | */ |
714 | void drm_crtc_cleanup(struct drm_crtc *crtc) |
714 | void drm_crtc_cleanup(struct drm_crtc *crtc) |
715 | { |
715 | { |
716 | struct drm_device *dev = crtc->dev; |
716 | struct drm_device *dev = crtc->dev; |
717 | 717 | ||
718 | kfree(crtc->gamma_store); |
718 | kfree(crtc->gamma_store); |
719 | crtc->gamma_store = NULL; |
719 | crtc->gamma_store = NULL; |
720 | 720 | ||
721 | drm_modeset_lock_fini(&crtc->mutex); |
721 | drm_modeset_lock_fini(&crtc->mutex); |
722 | 722 | ||
723 | drm_mode_object_put(dev, &crtc->base); |
723 | drm_mode_object_put(dev, &crtc->base); |
724 | list_del(&crtc->head); |
724 | list_del(&crtc->head); |
725 | dev->mode_config.num_crtc--; |
725 | dev->mode_config.num_crtc--; |
726 | 726 | ||
727 | WARN_ON(crtc->state && !crtc->funcs->atomic_destroy_state); |
727 | WARN_ON(crtc->state && !crtc->funcs->atomic_destroy_state); |
728 | if (crtc->state && crtc->funcs->atomic_destroy_state) |
728 | if (crtc->state && crtc->funcs->atomic_destroy_state) |
729 | crtc->funcs->atomic_destroy_state(crtc, crtc->state); |
729 | crtc->funcs->atomic_destroy_state(crtc, crtc->state); |
730 | 730 | ||
731 | memset(crtc, 0, sizeof(*crtc)); |
731 | memset(crtc, 0, sizeof(*crtc)); |
732 | } |
732 | } |
733 | EXPORT_SYMBOL(drm_crtc_cleanup); |
733 | EXPORT_SYMBOL(drm_crtc_cleanup); |
734 | 734 | ||
735 | /** |
735 | /** |
736 | * drm_crtc_index - find the index of a registered CRTC |
736 | * drm_crtc_index - find the index of a registered CRTC |
737 | * @crtc: CRTC to find index for |
737 | * @crtc: CRTC to find index for |
738 | * |
738 | * |
739 | * Given a registered CRTC, return the index of that CRTC within a DRM |
739 | * Given a registered CRTC, return the index of that CRTC within a DRM |
740 | * device's list of CRTCs. |
740 | * device's list of CRTCs. |
741 | */ |
741 | */ |
742 | unsigned int drm_crtc_index(struct drm_crtc *crtc) |
742 | unsigned int drm_crtc_index(struct drm_crtc *crtc) |
743 | { |
743 | { |
744 | unsigned int index = 0; |
744 | unsigned int index = 0; |
745 | struct drm_crtc *tmp; |
745 | struct drm_crtc *tmp; |
746 | 746 | ||
747 | drm_for_each_crtc(tmp, crtc->dev) { |
747 | drm_for_each_crtc(tmp, crtc->dev) { |
748 | if (tmp == crtc) |
748 | if (tmp == crtc) |
749 | return index; |
749 | return index; |
750 | 750 | ||
751 | index++; |
751 | index++; |
752 | } |
752 | } |
753 | 753 | ||
754 | BUG(); |
754 | BUG(); |
755 | } |
755 | } |
756 | EXPORT_SYMBOL(drm_crtc_index); |
756 | EXPORT_SYMBOL(drm_crtc_index); |
757 | 757 | ||
758 | /* |
758 | /* |
759 | * drm_mode_remove - remove and free a mode |
759 | * drm_mode_remove - remove and free a mode |
760 | * @connector: connector list to modify |
760 | * @connector: connector list to modify |
761 | * @mode: mode to remove |
761 | * @mode: mode to remove |
762 | * |
762 | * |
763 | * Remove @mode from @connector's mode list, then free it. |
763 | * Remove @mode from @connector's mode list, then free it. |
764 | */ |
764 | */ |
765 | static void drm_mode_remove(struct drm_connector *connector, |
765 | static void drm_mode_remove(struct drm_connector *connector, |
766 | struct drm_display_mode *mode) |
766 | struct drm_display_mode *mode) |
767 | { |
767 | { |
768 | list_del(&mode->head); |
768 | list_del(&mode->head); |
769 | drm_mode_destroy(connector->dev, mode); |
769 | drm_mode_destroy(connector->dev, mode); |
770 | } |
770 | } |
771 | 771 | ||
772 | /** |
772 | /** |
773 | * drm_display_info_set_bus_formats - set the supported bus formats |
773 | * drm_display_info_set_bus_formats - set the supported bus formats |
774 | * @info: display info to store bus formats in |
774 | * @info: display info to store bus formats in |
775 | * @formats: array containing the supported bus formats |
775 | * @formats: array containing the supported bus formats |
776 | * @num_formats: the number of entries in the fmts array |
776 | * @num_formats: the number of entries in the fmts array |
777 | * |
777 | * |
778 | * Store the supported bus formats in display info structure. |
778 | * Store the supported bus formats in display info structure. |
779 | * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for |
779 | * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for |
780 | * a full list of available formats. |
780 | * a full list of available formats. |
781 | */ |
781 | */ |
782 | int drm_display_info_set_bus_formats(struct drm_display_info *info, |
782 | int drm_display_info_set_bus_formats(struct drm_display_info *info, |
783 | const u32 *formats, |
783 | const u32 *formats, |
784 | unsigned int num_formats) |
784 | unsigned int num_formats) |
785 | { |
785 | { |
786 | u32 *fmts = NULL; |
786 | u32 *fmts = NULL; |
787 | 787 | ||
788 | if (!formats && num_formats) |
788 | if (!formats && num_formats) |
789 | return -EINVAL; |
789 | return -EINVAL; |
790 | 790 | ||
791 | if (formats && num_formats) { |
791 | if (formats && num_formats) { |
792 | fmts = kmemdup(formats, sizeof(*formats) * num_formats, |
792 | fmts = kmemdup(formats, sizeof(*formats) * num_formats, |
793 | GFP_KERNEL); |
793 | GFP_KERNEL); |
794 | if (!fmts) |
794 | if (!fmts) |
795 | return -ENOMEM; |
795 | return -ENOMEM; |
796 | } |
796 | } |
797 | 797 | ||
798 | kfree(info->bus_formats); |
798 | kfree(info->bus_formats); |
799 | info->bus_formats = fmts; |
799 | info->bus_formats = fmts; |
800 | info->num_bus_formats = num_formats; |
800 | info->num_bus_formats = num_formats; |
801 | 801 | ||
802 | return 0; |
802 | return 0; |
803 | } |
803 | } |
804 | EXPORT_SYMBOL(drm_display_info_set_bus_formats); |
804 | EXPORT_SYMBOL(drm_display_info_set_bus_formats); |
805 | 805 | ||
806 | /** |
806 | /** |
807 | * drm_connector_get_cmdline_mode - reads the user's cmdline mode |
807 | * drm_connector_get_cmdline_mode - reads the user's cmdline mode |
808 | * @connector: connector to quwery |
808 | * @connector: connector to quwery |
809 | * |
809 | * |
810 | * The kernel supports per-connector configration of its consoles through |
810 | * The kernel supports per-connector configration of its consoles through |
811 | * use of the video= parameter. This function parses that option and |
811 | * use of the video= parameter. This function parses that option and |
812 | * extracts the user's specified mode (or enable/disable status) for a |
812 | * extracts the user's specified mode (or enable/disable status) for a |
813 | * particular connector. This is typically only used during the early fbdev |
813 | * particular connector. This is typically only used during the early fbdev |
814 | * setup. |
814 | * setup. |
815 | */ |
815 | */ |
816 | static void drm_connector_get_cmdline_mode(struct drm_connector *connector) |
816 | static void drm_connector_get_cmdline_mode(struct drm_connector *connector) |
817 | { |
817 | { |
818 | struct drm_cmdline_mode *mode = &connector->cmdline_mode; |
818 | struct drm_cmdline_mode *mode = &connector->cmdline_mode; |
819 | char *option = NULL; |
819 | char *option = NULL; |
820 | 820 | ||
821 | if (fb_get_options(connector->name, &option)) |
821 | if (fb_get_options(connector->name, &option)) |
822 | return; |
822 | return; |
823 | 823 | ||
824 | if (!drm_mode_parse_command_line_for_connector(option, |
824 | if (!drm_mode_parse_command_line_for_connector(option, |
825 | connector, |
825 | connector, |
826 | mode)) |
826 | mode)) |
827 | return; |
827 | return; |
828 | 828 | ||
829 | if (mode->force) { |
829 | if (mode->force) { |
830 | const char *s; |
830 | const char *s; |
831 | 831 | ||
832 | switch (mode->force) { |
832 | switch (mode->force) { |
833 | case DRM_FORCE_OFF: |
833 | case DRM_FORCE_OFF: |
834 | s = "OFF"; |
834 | s = "OFF"; |
835 | break; |
835 | break; |
836 | case DRM_FORCE_ON_DIGITAL: |
836 | case DRM_FORCE_ON_DIGITAL: |
837 | s = "ON - dig"; |
837 | s = "ON - dig"; |
838 | break; |
838 | break; |
839 | default: |
839 | default: |
840 | case DRM_FORCE_ON: |
840 | case DRM_FORCE_ON: |
841 | s = "ON"; |
841 | s = "ON"; |
842 | break; |
842 | break; |
843 | } |
843 | } |
844 | 844 | ||
845 | DRM_INFO("forcing %s connector %s\n", connector->name, s); |
845 | DRM_INFO("forcing %s connector %s\n", connector->name, s); |
846 | connector->force = mode->force; |
846 | connector->force = mode->force; |
847 | } |
847 | } |
848 | 848 | ||
849 | DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n", |
849 | DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n", |
850 | connector->name, |
850 | connector->name, |
851 | mode->xres, mode->yres, |
851 | mode->xres, mode->yres, |
852 | mode->refresh_specified ? mode->refresh : 60, |
852 | mode->refresh_specified ? mode->refresh : 60, |
853 | mode->rb ? " reduced blanking" : "", |
853 | mode->rb ? " reduced blanking" : "", |
854 | mode->margins ? " with margins" : "", |
854 | mode->margins ? " with margins" : "", |
855 | mode->interlace ? " interlaced" : ""); |
855 | mode->interlace ? " interlaced" : ""); |
856 | } |
856 | } |
857 | 857 | ||
858 | /** |
858 | /** |
859 | * drm_connector_init - Init a preallocated connector |
859 | * drm_connector_init - Init a preallocated connector |
860 | * @dev: DRM device |
860 | * @dev: DRM device |
861 | * @connector: the connector to init |
861 | * @connector: the connector to init |
862 | * @funcs: callbacks for this connector |
862 | * @funcs: callbacks for this connector |
863 | * @connector_type: user visible type of the connector |
863 | * @connector_type: user visible type of the connector |
864 | * |
864 | * |
865 | * Initialises a preallocated connector. Connectors should be |
865 | * Initialises a preallocated connector. Connectors should be |
866 | * subclassed as part of driver connector objects. |
866 | * subclassed as part of driver connector objects. |
867 | * |
867 | * |
868 | * Returns: |
868 | * Returns: |
869 | * Zero on success, error code on failure. |
869 | * Zero on success, error code on failure. |
870 | */ |
870 | */ |
871 | int drm_connector_init(struct drm_device *dev, |
871 | int drm_connector_init(struct drm_device *dev, |
872 | struct drm_connector *connector, |
872 | struct drm_connector *connector, |
873 | const struct drm_connector_funcs *funcs, |
873 | const struct drm_connector_funcs *funcs, |
874 | int connector_type) |
874 | int connector_type) |
875 | { |
875 | { |
876 | struct drm_mode_config *config = &dev->mode_config; |
876 | struct drm_mode_config *config = &dev->mode_config; |
877 | int ret; |
877 | int ret; |
878 | struct ida *connector_ida = |
878 | struct ida *connector_ida = |
879 | &drm_connector_enum_list[connector_type].ida; |
879 | &drm_connector_enum_list[connector_type].ida; |
880 | 880 | ||
881 | drm_modeset_lock_all(dev); |
881 | drm_modeset_lock_all(dev); |
882 | 882 | ||
883 | ret = drm_mode_object_get_reg(dev, &connector->base, DRM_MODE_OBJECT_CONNECTOR, false); |
883 | ret = drm_mode_object_get_reg(dev, &connector->base, DRM_MODE_OBJECT_CONNECTOR, false); |
884 | if (ret) |
884 | if (ret) |
885 | goto out_unlock; |
885 | goto out_unlock; |
886 | 886 | ||
887 | connector->base.properties = &connector->properties; |
887 | connector->base.properties = &connector->properties; |
888 | connector->dev = dev; |
888 | connector->dev = dev; |
889 | connector->funcs = funcs; |
889 | connector->funcs = funcs; |
890 | connector->connector_type = connector_type; |
890 | connector->connector_type = connector_type; |
891 | connector->connector_type_id = |
891 | connector->connector_type_id = |
892 | ida_simple_get(connector_ida, 1, 0, GFP_KERNEL); |
892 | ida_simple_get(connector_ida, 1, 0, GFP_KERNEL); |
893 | if (connector->connector_type_id < 0) { |
893 | if (connector->connector_type_id < 0) { |
894 | ret = connector->connector_type_id; |
894 | ret = connector->connector_type_id; |
895 | goto out_put; |
895 | goto out_put; |
896 | } |
896 | } |
897 | connector->name = |
897 | connector->name = |
898 | kasprintf(GFP_KERNEL, "%s-%d", |
898 | kasprintf(GFP_KERNEL, "%s-%d", |
899 | drm_connector_enum_list[connector_type].name, |
899 | drm_connector_enum_list[connector_type].name, |
900 | connector->connector_type_id); |
900 | connector->connector_type_id); |
901 | if (!connector->name) { |
901 | if (!connector->name) { |
902 | ret = -ENOMEM; |
902 | ret = -ENOMEM; |
903 | goto out_put; |
903 | goto out_put; |
904 | } |
904 | } |
905 | 905 | ||
906 | INIT_LIST_HEAD(&connector->probed_modes); |
906 | INIT_LIST_HEAD(&connector->probed_modes); |
907 | INIT_LIST_HEAD(&connector->modes); |
907 | INIT_LIST_HEAD(&connector->modes); |
908 | connector->edid_blob_ptr = NULL; |
908 | connector->edid_blob_ptr = NULL; |
909 | connector->status = connector_status_unknown; |
909 | connector->status = connector_status_unknown; |
910 | 910 | ||
911 | drm_connector_get_cmdline_mode(connector); |
911 | drm_connector_get_cmdline_mode(connector); |
912 | 912 | ||
913 | /* We should add connectors at the end to avoid upsetting the connector |
913 | /* We should add connectors at the end to avoid upsetting the connector |
914 | * index too much. */ |
914 | * index too much. */ |
915 | list_add_tail(&connector->head, &config->connector_list); |
915 | list_add_tail(&connector->head, &config->connector_list); |
916 | config->num_connector++; |
916 | config->num_connector++; |
917 | 917 | ||
918 | if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL) |
918 | if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL) |
919 | drm_object_attach_property(&connector->base, |
919 | drm_object_attach_property(&connector->base, |
920 | config->edid_property, |
920 | config->edid_property, |
921 | 0); |
921 | 0); |
922 | 922 | ||
923 | drm_object_attach_property(&connector->base, |
923 | drm_object_attach_property(&connector->base, |
924 | config->dpms_property, 0); |
924 | config->dpms_property, 0); |
925 | 925 | ||
926 | if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { |
926 | if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { |
927 | drm_object_attach_property(&connector->base, config->prop_crtc_id, 0); |
927 | drm_object_attach_property(&connector->base, config->prop_crtc_id, 0); |
928 | } |
928 | } |
929 | 929 | ||
930 | connector->debugfs_entry = NULL; |
930 | connector->debugfs_entry = NULL; |
931 | 931 | ||
932 | out_put: |
932 | out_put: |
933 | if (ret) |
933 | if (ret) |
934 | drm_mode_object_put(dev, &connector->base); |
934 | drm_mode_object_put(dev, &connector->base); |
935 | 935 | ||
936 | out_unlock: |
936 | out_unlock: |
937 | drm_modeset_unlock_all(dev); |
937 | drm_modeset_unlock_all(dev); |
938 | 938 | ||
939 | return ret; |
939 | return ret; |
940 | } |
940 | } |
941 | EXPORT_SYMBOL(drm_connector_init); |
941 | EXPORT_SYMBOL(drm_connector_init); |
942 | 942 | ||
943 | /** |
943 | /** |
944 | * drm_connector_cleanup - cleans up an initialised connector |
944 | * drm_connector_cleanup - cleans up an initialised connector |
945 | * @connector: connector to cleanup |
945 | * @connector: connector to cleanup |
946 | * |
946 | * |
947 | * Cleans up the connector but doesn't free the object. |
947 | * Cleans up the connector but doesn't free the object. |
948 | */ |
948 | */ |
949 | void drm_connector_cleanup(struct drm_connector *connector) |
949 | void drm_connector_cleanup(struct drm_connector *connector) |
950 | { |
950 | { |
951 | struct drm_device *dev = connector->dev; |
951 | struct drm_device *dev = connector->dev; |
952 | struct drm_display_mode *mode, *t; |
952 | struct drm_display_mode *mode, *t; |
953 | 953 | ||
954 | if (connector->tile_group) { |
954 | if (connector->tile_group) { |
955 | drm_mode_put_tile_group(dev, connector->tile_group); |
955 | drm_mode_put_tile_group(dev, connector->tile_group); |
956 | connector->tile_group = NULL; |
956 | connector->tile_group = NULL; |
957 | } |
957 | } |
958 | 958 | ||
959 | list_for_each_entry_safe(mode, t, &connector->probed_modes, head) |
959 | list_for_each_entry_safe(mode, t, &connector->probed_modes, head) |
960 | drm_mode_remove(connector, mode); |
960 | drm_mode_remove(connector, mode); |
961 | 961 | ||
962 | list_for_each_entry_safe(mode, t, &connector->modes, head) |
962 | list_for_each_entry_safe(mode, t, &connector->modes, head) |
963 | drm_mode_remove(connector, mode); |
963 | drm_mode_remove(connector, mode); |
964 | 964 | ||
965 | ida_remove(&drm_connector_enum_list[connector->connector_type].ida, |
965 | ida_remove(&drm_connector_enum_list[connector->connector_type].ida, |
966 | connector->connector_type_id); |
966 | connector->connector_type_id); |
967 | 967 | ||
968 | kfree(connector->display_info.bus_formats); |
968 | kfree(connector->display_info.bus_formats); |
969 | drm_mode_object_put(dev, &connector->base); |
969 | drm_mode_object_put(dev, &connector->base); |
970 | kfree(connector->name); |
970 | kfree(connector->name); |
971 | connector->name = NULL; |
971 | connector->name = NULL; |
972 | list_del(&connector->head); |
972 | list_del(&connector->head); |
973 | dev->mode_config.num_connector--; |
973 | dev->mode_config.num_connector--; |
974 | 974 | ||
975 | WARN_ON(connector->state && !connector->funcs->atomic_destroy_state); |
975 | WARN_ON(connector->state && !connector->funcs->atomic_destroy_state); |
976 | if (connector->state && connector->funcs->atomic_destroy_state) |
976 | if (connector->state && connector->funcs->atomic_destroy_state) |
977 | connector->funcs->atomic_destroy_state(connector, |
977 | connector->funcs->atomic_destroy_state(connector, |
978 | connector->state); |
978 | connector->state); |
979 | 979 | ||
980 | memset(connector, 0, sizeof(*connector)); |
980 | memset(connector, 0, sizeof(*connector)); |
981 | } |
981 | } |
982 | EXPORT_SYMBOL(drm_connector_cleanup); |
982 | EXPORT_SYMBOL(drm_connector_cleanup); |
983 | 983 | ||
984 | /** |
984 | /** |
985 | * drm_connector_index - find the index of a registered connector |
985 | * drm_connector_index - find the index of a registered connector |
986 | * @connector: connector to find index for |
986 | * @connector: connector to find index for |
987 | * |
987 | * |
988 | * Given a registered connector, return the index of that connector within a DRM |
988 | * Given a registered connector, return the index of that connector within a DRM |
989 | * device's list of connectors. |
989 | * device's list of connectors. |
990 | */ |
990 | */ |
991 | unsigned int drm_connector_index(struct drm_connector *connector) |
991 | unsigned int drm_connector_index(struct drm_connector *connector) |
992 | { |
992 | { |
993 | unsigned int index = 0; |
993 | unsigned int index = 0; |
994 | struct drm_connector *tmp; |
994 | struct drm_connector *tmp; |
995 | struct drm_mode_config *config = &connector->dev->mode_config; |
995 | struct drm_mode_config *config = &connector->dev->mode_config; |
996 | 996 | ||
997 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
997 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
998 | 998 | ||
999 | drm_for_each_connector(tmp, connector->dev) { |
999 | drm_for_each_connector(tmp, connector->dev) { |
1000 | if (tmp == connector) |
1000 | if (tmp == connector) |
1001 | return index; |
1001 | return index; |
1002 | 1002 | ||
1003 | index++; |
1003 | index++; |
1004 | } |
1004 | } |
1005 | 1005 | ||
1006 | BUG(); |
1006 | BUG(); |
1007 | } |
1007 | } |
1008 | EXPORT_SYMBOL(drm_connector_index); |
1008 | EXPORT_SYMBOL(drm_connector_index); |
1009 | 1009 | ||
1010 | /** |
1010 | /** |
1011 | * drm_connector_register - register a connector |
1011 | * drm_connector_register - register a connector |
1012 | * @connector: the connector to register |
1012 | * @connector: the connector to register |
1013 | * |
1013 | * |
1014 | * Register userspace interfaces for a connector |
1014 | * Register userspace interfaces for a connector |
1015 | * |
1015 | * |
1016 | * Returns: |
1016 | * Returns: |
1017 | * Zero on success, error code on failure. |
1017 | * Zero on success, error code on failure. |
1018 | */ |
1018 | */ |
1019 | int drm_connector_register(struct drm_connector *connector) |
1019 | int drm_connector_register(struct drm_connector *connector) |
1020 | { |
1020 | { |
1021 | int ret; |
1021 | int ret; |
1022 | 1022 | ||
1023 | drm_mode_object_register(connector->dev, &connector->base); |
1023 | drm_mode_object_register(connector->dev, &connector->base); |
1024 | 1024 | ||
1025 | ret = drm_sysfs_connector_add(connector); |
1025 | ret = drm_sysfs_connector_add(connector); |
1026 | if (ret) |
1026 | if (ret) |
1027 | return ret; |
1027 | return ret; |
- | 1028 | ||
- | 1029 | ret = drm_debugfs_connector_add(connector); |
|
- | 1030 | if (ret) { |
|
- | 1031 | drm_sysfs_connector_remove(connector); |
|
- | 1032 | return ret; |
|
- | 1033 | } |
|
- | 1034 | ||
1028 | return 0; |
1035 | return 0; |
1029 | } |
1036 | } |
1030 | EXPORT_SYMBOL(drm_connector_register); |
1037 | EXPORT_SYMBOL(drm_connector_register); |
1031 | 1038 | ||
1032 | /** |
1039 | /** |
1033 | * drm_connector_unregister - unregister a connector |
1040 | * drm_connector_unregister - unregister a connector |
1034 | * @connector: the connector to unregister |
1041 | * @connector: the connector to unregister |
1035 | * |
1042 | * |
1036 | * Unregister userspace interfaces for a connector |
1043 | * Unregister userspace interfaces for a connector |
1037 | */ |
1044 | */ |
1038 | void drm_connector_unregister(struct drm_connector *connector) |
1045 | void drm_connector_unregister(struct drm_connector *connector) |
1039 | { |
1046 | { |
1040 | drm_sysfs_connector_remove(connector); |
1047 | drm_sysfs_connector_remove(connector); |
- | 1048 | drm_debugfs_connector_remove(connector); |
|
1041 | } |
1049 | } |
1042 | EXPORT_SYMBOL(drm_connector_unregister); |
1050 | EXPORT_SYMBOL(drm_connector_unregister); |
1043 | 1051 | ||
1044 | 1052 | ||
1045 | /** |
1053 | /** |
1046 | * drm_connector_unplug_all - unregister connector userspace interfaces |
1054 | * drm_connector_unplug_all - unregister connector userspace interfaces |
1047 | * @dev: drm device |
1055 | * @dev: drm device |
1048 | * |
1056 | * |
1049 | * This function unregisters all connector userspace interfaces in sysfs. Should |
1057 | * This function unregisters all connector userspace interfaces in sysfs. Should |
1050 | * be call when the device is disconnected, e.g. from an usb driver's |
1058 | * be call when the device is disconnected, e.g. from an usb driver's |
1051 | * ->disconnect callback. |
1059 | * ->disconnect callback. |
1052 | */ |
1060 | */ |
1053 | void drm_connector_unplug_all(struct drm_device *dev) |
1061 | void drm_connector_unplug_all(struct drm_device *dev) |
1054 | { |
1062 | { |
1055 | struct drm_connector *connector; |
1063 | struct drm_connector *connector; |
1056 | 1064 | ||
1057 | /* FIXME: taking the mode config mutex ends up in a clash with sysfs */ |
1065 | /* FIXME: taking the mode config mutex ends up in a clash with sysfs */ |
1058 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) |
1066 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) |
1059 | drm_connector_unregister(connector); |
1067 | drm_connector_unregister(connector); |
1060 | 1068 | ||
1061 | } |
1069 | } |
1062 | EXPORT_SYMBOL(drm_connector_unplug_all); |
1070 | EXPORT_SYMBOL(drm_connector_unplug_all); |
1063 | 1071 | ||
1064 | /** |
1072 | /** |
1065 | * drm_encoder_init - Init a preallocated encoder |
1073 | * drm_encoder_init - Init a preallocated encoder |
1066 | * @dev: drm device |
1074 | * @dev: drm device |
1067 | * @encoder: the encoder to init |
1075 | * @encoder: the encoder to init |
1068 | * @funcs: callbacks for this encoder |
1076 | * @funcs: callbacks for this encoder |
1069 | * @encoder_type: user visible type of the encoder |
1077 | * @encoder_type: user visible type of the encoder |
1070 | * |
1078 | * |
1071 | * Initialises a preallocated encoder. Encoder should be |
1079 | * Initialises a preallocated encoder. Encoder should be |
1072 | * subclassed as part of driver encoder objects. |
1080 | * subclassed as part of driver encoder objects. |
1073 | * |
1081 | * |
1074 | * Returns: |
1082 | * Returns: |
1075 | * Zero on success, error code on failure. |
1083 | * Zero on success, error code on failure. |
1076 | */ |
1084 | */ |
1077 | int drm_encoder_init(struct drm_device *dev, |
1085 | int drm_encoder_init(struct drm_device *dev, |
1078 | struct drm_encoder *encoder, |
1086 | struct drm_encoder *encoder, |
1079 | const struct drm_encoder_funcs *funcs, |
1087 | const struct drm_encoder_funcs *funcs, |
1080 | int encoder_type) |
1088 | int encoder_type) |
1081 | { |
1089 | { |
1082 | int ret; |
1090 | int ret; |
1083 | 1091 | ||
1084 | drm_modeset_lock_all(dev); |
1092 | drm_modeset_lock_all(dev); |
1085 | 1093 | ||
1086 | ret = drm_mode_object_get(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER); |
1094 | ret = drm_mode_object_get(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER); |
1087 | if (ret) |
1095 | if (ret) |
1088 | goto out_unlock; |
1096 | goto out_unlock; |
1089 | 1097 | ||
1090 | encoder->dev = dev; |
1098 | encoder->dev = dev; |
1091 | encoder->encoder_type = encoder_type; |
1099 | encoder->encoder_type = encoder_type; |
1092 | encoder->funcs = funcs; |
1100 | encoder->funcs = funcs; |
1093 | encoder->name = kasprintf(GFP_KERNEL, "%s-%d", |
1101 | encoder->name = kasprintf(GFP_KERNEL, "%s-%d", |
1094 | drm_encoder_enum_list[encoder_type].name, |
1102 | drm_encoder_enum_list[encoder_type].name, |
1095 | encoder->base.id); |
1103 | encoder->base.id); |
1096 | if (!encoder->name) { |
1104 | if (!encoder->name) { |
1097 | ret = -ENOMEM; |
1105 | ret = -ENOMEM; |
1098 | goto out_put; |
1106 | goto out_put; |
1099 | } |
1107 | } |
1100 | 1108 | ||
1101 | list_add_tail(&encoder->head, &dev->mode_config.encoder_list); |
1109 | list_add_tail(&encoder->head, &dev->mode_config.encoder_list); |
1102 | dev->mode_config.num_encoder++; |
1110 | dev->mode_config.num_encoder++; |
1103 | 1111 | ||
1104 | out_put: |
1112 | out_put: |
1105 | if (ret) |
1113 | if (ret) |
1106 | drm_mode_object_put(dev, &encoder->base); |
1114 | drm_mode_object_put(dev, &encoder->base); |
1107 | 1115 | ||
1108 | out_unlock: |
1116 | out_unlock: |
1109 | drm_modeset_unlock_all(dev); |
1117 | drm_modeset_unlock_all(dev); |
1110 | 1118 | ||
1111 | return ret; |
1119 | return ret; |
1112 | } |
1120 | } |
1113 | EXPORT_SYMBOL(drm_encoder_init); |
1121 | EXPORT_SYMBOL(drm_encoder_init); |
1114 | 1122 | ||
1115 | /** |
1123 | /** |
1116 | * drm_encoder_cleanup - cleans up an initialised encoder |
1124 | * drm_encoder_cleanup - cleans up an initialised encoder |
1117 | * @encoder: encoder to cleanup |
1125 | * @encoder: encoder to cleanup |
1118 | * |
1126 | * |
1119 | * Cleans up the encoder but doesn't free the object. |
1127 | * Cleans up the encoder but doesn't free the object. |
1120 | */ |
1128 | */ |
1121 | void drm_encoder_cleanup(struct drm_encoder *encoder) |
1129 | void drm_encoder_cleanup(struct drm_encoder *encoder) |
1122 | { |
1130 | { |
1123 | struct drm_device *dev = encoder->dev; |
1131 | struct drm_device *dev = encoder->dev; |
1124 | 1132 | ||
1125 | drm_modeset_lock_all(dev); |
1133 | drm_modeset_lock_all(dev); |
1126 | drm_mode_object_put(dev, &encoder->base); |
1134 | drm_mode_object_put(dev, &encoder->base); |
1127 | kfree(encoder->name); |
1135 | kfree(encoder->name); |
1128 | list_del(&encoder->head); |
1136 | list_del(&encoder->head); |
1129 | dev->mode_config.num_encoder--; |
1137 | dev->mode_config.num_encoder--; |
1130 | drm_modeset_unlock_all(dev); |
1138 | drm_modeset_unlock_all(dev); |
1131 | 1139 | ||
1132 | memset(encoder, 0, sizeof(*encoder)); |
1140 | memset(encoder, 0, sizeof(*encoder)); |
1133 | } |
1141 | } |
1134 | EXPORT_SYMBOL(drm_encoder_cleanup); |
1142 | EXPORT_SYMBOL(drm_encoder_cleanup); |
1135 | 1143 | ||
1136 | /** |
1144 | /** |
1137 | * drm_universal_plane_init - Initialize a new universal plane object |
1145 | * drm_universal_plane_init - Initialize a new universal plane object |
1138 | * @dev: DRM device |
1146 | * @dev: DRM device |
1139 | * @plane: plane object to init |
1147 | * @plane: plane object to init |
1140 | * @possible_crtcs: bitmask of possible CRTCs |
1148 | * @possible_crtcs: bitmask of possible CRTCs |
1141 | * @funcs: callbacks for the new plane |
1149 | * @funcs: callbacks for the new plane |
1142 | * @formats: array of supported formats (%DRM_FORMAT_*) |
1150 | * @formats: array of supported formats (%DRM_FORMAT_*) |
1143 | * @format_count: number of elements in @formats |
1151 | * @format_count: number of elements in @formats |
1144 | * @type: type of plane (overlay, primary, cursor) |
1152 | * @type: type of plane (overlay, primary, cursor) |
1145 | * |
1153 | * |
1146 | * Initializes a plane object of type @type. |
1154 | * Initializes a plane object of type @type. |
1147 | * |
1155 | * |
1148 | * Returns: |
1156 | * Returns: |
1149 | * Zero on success, error code on failure. |
1157 | * Zero on success, error code on failure. |
1150 | */ |
1158 | */ |
1151 | int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane, |
1159 | int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane, |
1152 | unsigned long possible_crtcs, |
1160 | unsigned long possible_crtcs, |
1153 | const struct drm_plane_funcs *funcs, |
1161 | const struct drm_plane_funcs *funcs, |
1154 | const uint32_t *formats, unsigned int format_count, |
1162 | const uint32_t *formats, unsigned int format_count, |
1155 | enum drm_plane_type type) |
1163 | enum drm_plane_type type) |
1156 | { |
1164 | { |
1157 | struct drm_mode_config *config = &dev->mode_config; |
1165 | struct drm_mode_config *config = &dev->mode_config; |
1158 | int ret; |
1166 | int ret; |
1159 | 1167 | ||
1160 | ret = drm_mode_object_get(dev, &plane->base, DRM_MODE_OBJECT_PLANE); |
1168 | ret = drm_mode_object_get(dev, &plane->base, DRM_MODE_OBJECT_PLANE); |
1161 | if (ret) |
1169 | if (ret) |
1162 | return ret; |
1170 | return ret; |
1163 | 1171 | ||
1164 | drm_modeset_lock_init(&plane->mutex); |
1172 | drm_modeset_lock_init(&plane->mutex); |
1165 | 1173 | ||
1166 | plane->base.properties = &plane->properties; |
1174 | plane->base.properties = &plane->properties; |
1167 | plane->dev = dev; |
1175 | plane->dev = dev; |
1168 | plane->funcs = funcs; |
1176 | plane->funcs = funcs; |
1169 | plane->format_types = kmalloc_array(format_count, sizeof(uint32_t), |
1177 | plane->format_types = kmalloc_array(format_count, sizeof(uint32_t), |
1170 | GFP_KERNEL); |
1178 | GFP_KERNEL); |
1171 | if (!plane->format_types) { |
1179 | if (!plane->format_types) { |
1172 | DRM_DEBUG_KMS("out of memory when allocating plane\n"); |
1180 | DRM_DEBUG_KMS("out of memory when allocating plane\n"); |
1173 | drm_mode_object_put(dev, &plane->base); |
1181 | drm_mode_object_put(dev, &plane->base); |
1174 | return -ENOMEM; |
1182 | return -ENOMEM; |
1175 | } |
1183 | } |
1176 | 1184 | ||
1177 | memcpy(plane->format_types, formats, format_count * sizeof(uint32_t)); |
1185 | memcpy(plane->format_types, formats, format_count * sizeof(uint32_t)); |
1178 | plane->format_count = format_count; |
1186 | plane->format_count = format_count; |
1179 | plane->possible_crtcs = possible_crtcs; |
1187 | plane->possible_crtcs = possible_crtcs; |
1180 | plane->type = type; |
1188 | plane->type = type; |
1181 | 1189 | ||
1182 | list_add_tail(&plane->head, &config->plane_list); |
1190 | list_add_tail(&plane->head, &config->plane_list); |
1183 | config->num_total_plane++; |
1191 | config->num_total_plane++; |
1184 | if (plane->type == DRM_PLANE_TYPE_OVERLAY) |
1192 | if (plane->type == DRM_PLANE_TYPE_OVERLAY) |
1185 | config->num_overlay_plane++; |
1193 | config->num_overlay_plane++; |
1186 | 1194 | ||
1187 | drm_object_attach_property(&plane->base, |
1195 | drm_object_attach_property(&plane->base, |
1188 | config->plane_type_property, |
1196 | config->plane_type_property, |
1189 | plane->type); |
1197 | plane->type); |
1190 | 1198 | ||
1191 | if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { |
1199 | if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { |
1192 | drm_object_attach_property(&plane->base, config->prop_fb_id, 0); |
1200 | drm_object_attach_property(&plane->base, config->prop_fb_id, 0); |
1193 | drm_object_attach_property(&plane->base, config->prop_crtc_id, 0); |
1201 | drm_object_attach_property(&plane->base, config->prop_crtc_id, 0); |
1194 | drm_object_attach_property(&plane->base, config->prop_crtc_x, 0); |
1202 | drm_object_attach_property(&plane->base, config->prop_crtc_x, 0); |
1195 | drm_object_attach_property(&plane->base, config->prop_crtc_y, 0); |
1203 | drm_object_attach_property(&plane->base, config->prop_crtc_y, 0); |
1196 | drm_object_attach_property(&plane->base, config->prop_crtc_w, 0); |
1204 | drm_object_attach_property(&plane->base, config->prop_crtc_w, 0); |
1197 | drm_object_attach_property(&plane->base, config->prop_crtc_h, 0); |
1205 | drm_object_attach_property(&plane->base, config->prop_crtc_h, 0); |
1198 | drm_object_attach_property(&plane->base, config->prop_src_x, 0); |
1206 | drm_object_attach_property(&plane->base, config->prop_src_x, 0); |
1199 | drm_object_attach_property(&plane->base, config->prop_src_y, 0); |
1207 | drm_object_attach_property(&plane->base, config->prop_src_y, 0); |
1200 | drm_object_attach_property(&plane->base, config->prop_src_w, 0); |
1208 | drm_object_attach_property(&plane->base, config->prop_src_w, 0); |
1201 | drm_object_attach_property(&plane->base, config->prop_src_h, 0); |
1209 | drm_object_attach_property(&plane->base, config->prop_src_h, 0); |
1202 | } |
1210 | } |
1203 | 1211 | ||
1204 | return 0; |
1212 | return 0; |
1205 | } |
1213 | } |
1206 | EXPORT_SYMBOL(drm_universal_plane_init); |
1214 | EXPORT_SYMBOL(drm_universal_plane_init); |
1207 | 1215 | ||
1208 | /** |
1216 | /** |
1209 | * drm_plane_init - Initialize a legacy plane |
1217 | * drm_plane_init - Initialize a legacy plane |
1210 | * @dev: DRM device |
1218 | * @dev: DRM device |
1211 | * @plane: plane object to init |
1219 | * @plane: plane object to init |
1212 | * @possible_crtcs: bitmask of possible CRTCs |
1220 | * @possible_crtcs: bitmask of possible CRTCs |
1213 | * @funcs: callbacks for the new plane |
1221 | * @funcs: callbacks for the new plane |
1214 | * @formats: array of supported formats (%DRM_FORMAT_*) |
1222 | * @formats: array of supported formats (%DRM_FORMAT_*) |
1215 | * @format_count: number of elements in @formats |
1223 | * @format_count: number of elements in @formats |
1216 | * @is_primary: plane type (primary vs overlay) |
1224 | * @is_primary: plane type (primary vs overlay) |
1217 | * |
1225 | * |
1218 | * Legacy API to initialize a DRM plane. |
1226 | * Legacy API to initialize a DRM plane. |
1219 | * |
1227 | * |
1220 | * New drivers should call drm_universal_plane_init() instead. |
1228 | * New drivers should call drm_universal_plane_init() instead. |
1221 | * |
1229 | * |
1222 | * Returns: |
1230 | * Returns: |
1223 | * Zero on success, error code on failure. |
1231 | * Zero on success, error code on failure. |
1224 | */ |
1232 | */ |
1225 | int drm_plane_init(struct drm_device *dev, struct drm_plane *plane, |
1233 | int drm_plane_init(struct drm_device *dev, struct drm_plane *plane, |
1226 | unsigned long possible_crtcs, |
1234 | unsigned long possible_crtcs, |
1227 | const struct drm_plane_funcs *funcs, |
1235 | const struct drm_plane_funcs *funcs, |
1228 | const uint32_t *formats, unsigned int format_count, |
1236 | const uint32_t *formats, unsigned int format_count, |
1229 | bool is_primary) |
1237 | bool is_primary) |
1230 | { |
1238 | { |
1231 | enum drm_plane_type type; |
1239 | enum drm_plane_type type; |
1232 | 1240 | ||
1233 | type = is_primary ? DRM_PLANE_TYPE_PRIMARY : DRM_PLANE_TYPE_OVERLAY; |
1241 | type = is_primary ? DRM_PLANE_TYPE_PRIMARY : DRM_PLANE_TYPE_OVERLAY; |
1234 | return drm_universal_plane_init(dev, plane, possible_crtcs, funcs, |
1242 | return drm_universal_plane_init(dev, plane, possible_crtcs, funcs, |
1235 | formats, format_count, type); |
1243 | formats, format_count, type); |
1236 | } |
1244 | } |
1237 | EXPORT_SYMBOL(drm_plane_init); |
1245 | EXPORT_SYMBOL(drm_plane_init); |
1238 | 1246 | ||
1239 | /** |
1247 | /** |
1240 | * drm_plane_cleanup - Clean up the core plane usage |
1248 | * drm_plane_cleanup - Clean up the core plane usage |
1241 | * @plane: plane to cleanup |
1249 | * @plane: plane to cleanup |
1242 | * |
1250 | * |
1243 | * This function cleans up @plane and removes it from the DRM mode setting |
1251 | * This function cleans up @plane and removes it from the DRM mode setting |
1244 | * core. Note that the function does *not* free the plane structure itself, |
1252 | * core. Note that the function does *not* free the plane structure itself, |
1245 | * this is the responsibility of the caller. |
1253 | * this is the responsibility of the caller. |
1246 | */ |
1254 | */ |
1247 | void drm_plane_cleanup(struct drm_plane *plane) |
1255 | void drm_plane_cleanup(struct drm_plane *plane) |
1248 | { |
1256 | { |
1249 | struct drm_device *dev = plane->dev; |
1257 | struct drm_device *dev = plane->dev; |
1250 | 1258 | ||
1251 | drm_modeset_lock_all(dev); |
1259 | drm_modeset_lock_all(dev); |
1252 | kfree(plane->format_types); |
1260 | kfree(plane->format_types); |
1253 | drm_mode_object_put(dev, &plane->base); |
1261 | drm_mode_object_put(dev, &plane->base); |
1254 | 1262 | ||
1255 | BUG_ON(list_empty(&plane->head)); |
1263 | BUG_ON(list_empty(&plane->head)); |
1256 | 1264 | ||
1257 | list_del(&plane->head); |
1265 | list_del(&plane->head); |
1258 | dev->mode_config.num_total_plane--; |
1266 | dev->mode_config.num_total_plane--; |
1259 | if (plane->type == DRM_PLANE_TYPE_OVERLAY) |
1267 | if (plane->type == DRM_PLANE_TYPE_OVERLAY) |
1260 | dev->mode_config.num_overlay_plane--; |
1268 | dev->mode_config.num_overlay_plane--; |
1261 | drm_modeset_unlock_all(dev); |
1269 | drm_modeset_unlock_all(dev); |
1262 | 1270 | ||
1263 | WARN_ON(plane->state && !plane->funcs->atomic_destroy_state); |
1271 | WARN_ON(plane->state && !plane->funcs->atomic_destroy_state); |
1264 | if (plane->state && plane->funcs->atomic_destroy_state) |
1272 | if (plane->state && plane->funcs->atomic_destroy_state) |
1265 | plane->funcs->atomic_destroy_state(plane, plane->state); |
1273 | plane->funcs->atomic_destroy_state(plane, plane->state); |
1266 | 1274 | ||
1267 | memset(plane, 0, sizeof(*plane)); |
1275 | memset(plane, 0, sizeof(*plane)); |
1268 | } |
1276 | } |
1269 | EXPORT_SYMBOL(drm_plane_cleanup); |
1277 | EXPORT_SYMBOL(drm_plane_cleanup); |
1270 | 1278 | ||
1271 | /** |
1279 | /** |
1272 | * drm_plane_index - find the index of a registered plane |
1280 | * drm_plane_index - find the index of a registered plane |
1273 | * @plane: plane to find index for |
1281 | * @plane: plane to find index for |
1274 | * |
1282 | * |
1275 | * Given a registered plane, return the index of that CRTC within a DRM |
1283 | * Given a registered plane, return the index of that CRTC within a DRM |
1276 | * device's list of planes. |
1284 | * device's list of planes. |
1277 | */ |
1285 | */ |
1278 | unsigned int drm_plane_index(struct drm_plane *plane) |
1286 | unsigned int drm_plane_index(struct drm_plane *plane) |
1279 | { |
1287 | { |
1280 | unsigned int index = 0; |
1288 | unsigned int index = 0; |
1281 | struct drm_plane *tmp; |
1289 | struct drm_plane *tmp; |
1282 | 1290 | ||
1283 | drm_for_each_plane(tmp, plane->dev) { |
1291 | drm_for_each_plane(tmp, plane->dev) { |
1284 | if (tmp == plane) |
1292 | if (tmp == plane) |
1285 | return index; |
1293 | return index; |
1286 | 1294 | ||
1287 | index++; |
1295 | index++; |
1288 | } |
1296 | } |
1289 | 1297 | ||
1290 | BUG(); |
1298 | BUG(); |
1291 | } |
1299 | } |
1292 | EXPORT_SYMBOL(drm_plane_index); |
1300 | EXPORT_SYMBOL(drm_plane_index); |
1293 | 1301 | ||
1294 | /** |
1302 | /** |
1295 | * drm_plane_from_index - find the registered plane at an index |
1303 | * drm_plane_from_index - find the registered plane at an index |
1296 | * @dev: DRM device |
1304 | * @dev: DRM device |
1297 | * @idx: index of registered plane to find for |
1305 | * @idx: index of registered plane to find for |
1298 | * |
1306 | * |
1299 | * Given a plane index, return the registered plane from DRM device's |
1307 | * Given a plane index, return the registered plane from DRM device's |
1300 | * list of planes with matching index. |
1308 | * list of planes with matching index. |
1301 | */ |
1309 | */ |
1302 | struct drm_plane * |
1310 | struct drm_plane * |
1303 | drm_plane_from_index(struct drm_device *dev, int idx) |
1311 | drm_plane_from_index(struct drm_device *dev, int idx) |
1304 | { |
1312 | { |
1305 | struct drm_plane *plane; |
1313 | struct drm_plane *plane; |
1306 | unsigned int i = 0; |
1314 | unsigned int i = 0; |
1307 | 1315 | ||
1308 | drm_for_each_plane(plane, dev) { |
1316 | drm_for_each_plane(plane, dev) { |
1309 | if (i == idx) |
1317 | if (i == idx) |
1310 | return plane; |
1318 | return plane; |
1311 | i++; |
1319 | i++; |
1312 | } |
1320 | } |
1313 | return NULL; |
1321 | return NULL; |
1314 | } |
1322 | } |
1315 | EXPORT_SYMBOL(drm_plane_from_index); |
1323 | EXPORT_SYMBOL(drm_plane_from_index); |
1316 | 1324 | ||
1317 | /** |
1325 | /** |
1318 | * drm_plane_force_disable - Forcibly disable a plane |
1326 | * drm_plane_force_disable - Forcibly disable a plane |
1319 | * @plane: plane to disable |
1327 | * @plane: plane to disable |
1320 | * |
1328 | * |
1321 | * Forces the plane to be disabled. |
1329 | * Forces the plane to be disabled. |
1322 | * |
1330 | * |
1323 | * Used when the plane's current framebuffer is destroyed, |
1331 | * Used when the plane's current framebuffer is destroyed, |
1324 | * and when restoring fbdev mode. |
1332 | * and when restoring fbdev mode. |
1325 | */ |
1333 | */ |
1326 | void drm_plane_force_disable(struct drm_plane *plane) |
1334 | void drm_plane_force_disable(struct drm_plane *plane) |
1327 | { |
1335 | { |
1328 | int ret; |
1336 | int ret; |
1329 | 1337 | ||
1330 | if (!plane->fb) |
1338 | if (!plane->fb) |
1331 | return; |
1339 | return; |
1332 | 1340 | ||
1333 | plane->old_fb = plane->fb; |
1341 | plane->old_fb = plane->fb; |
1334 | ret = plane->funcs->disable_plane(plane); |
1342 | ret = plane->funcs->disable_plane(plane); |
1335 | if (ret) { |
1343 | if (ret) { |
1336 | DRM_ERROR("failed to disable plane with busy fb\n"); |
1344 | DRM_ERROR("failed to disable plane with busy fb\n"); |
1337 | plane->old_fb = NULL; |
1345 | plane->old_fb = NULL; |
1338 | return; |
1346 | return; |
1339 | } |
1347 | } |
1340 | /* disconnect the plane from the fb and crtc: */ |
1348 | /* disconnect the plane from the fb and crtc: */ |
1341 | drm_framebuffer_unreference(plane->old_fb); |
1349 | drm_framebuffer_unreference(plane->old_fb); |
1342 | plane->old_fb = NULL; |
1350 | plane->old_fb = NULL; |
1343 | plane->fb = NULL; |
1351 | plane->fb = NULL; |
1344 | plane->crtc = NULL; |
1352 | plane->crtc = NULL; |
1345 | } |
1353 | } |
1346 | EXPORT_SYMBOL(drm_plane_force_disable); |
1354 | EXPORT_SYMBOL(drm_plane_force_disable); |
1347 | 1355 | ||
1348 | static int drm_mode_create_standard_properties(struct drm_device *dev) |
1356 | static int drm_mode_create_standard_properties(struct drm_device *dev) |
1349 | { |
1357 | { |
1350 | struct drm_property *prop; |
1358 | struct drm_property *prop; |
1351 | 1359 | ||
1352 | /* |
1360 | /* |
1353 | * Standard properties (apply to all connectors) |
1361 | * Standard properties (apply to all connectors) |
1354 | */ |
1362 | */ |
1355 | prop = drm_property_create(dev, DRM_MODE_PROP_BLOB | |
1363 | prop = drm_property_create(dev, DRM_MODE_PROP_BLOB | |
1356 | DRM_MODE_PROP_IMMUTABLE, |
1364 | DRM_MODE_PROP_IMMUTABLE, |
1357 | "EDID", 0); |
1365 | "EDID", 0); |
1358 | if (!prop) |
1366 | if (!prop) |
1359 | return -ENOMEM; |
1367 | return -ENOMEM; |
1360 | dev->mode_config.edid_property = prop; |
1368 | dev->mode_config.edid_property = prop; |
1361 | 1369 | ||
1362 | prop = drm_property_create_enum(dev, 0, |
1370 | prop = drm_property_create_enum(dev, 0, |
1363 | "DPMS", drm_dpms_enum_list, |
1371 | "DPMS", drm_dpms_enum_list, |
1364 | ARRAY_SIZE(drm_dpms_enum_list)); |
1372 | ARRAY_SIZE(drm_dpms_enum_list)); |
1365 | if (!prop) |
1373 | if (!prop) |
1366 | return -ENOMEM; |
1374 | return -ENOMEM; |
1367 | dev->mode_config.dpms_property = prop; |
1375 | dev->mode_config.dpms_property = prop; |
1368 | 1376 | ||
1369 | prop = drm_property_create(dev, |
1377 | prop = drm_property_create(dev, |
1370 | DRM_MODE_PROP_BLOB | |
1378 | DRM_MODE_PROP_BLOB | |
1371 | DRM_MODE_PROP_IMMUTABLE, |
1379 | DRM_MODE_PROP_IMMUTABLE, |
1372 | "PATH", 0); |
1380 | "PATH", 0); |
1373 | if (!prop) |
1381 | if (!prop) |
1374 | return -ENOMEM; |
1382 | return -ENOMEM; |
1375 | dev->mode_config.path_property = prop; |
1383 | dev->mode_config.path_property = prop; |
1376 | 1384 | ||
1377 | prop = drm_property_create(dev, |
1385 | prop = drm_property_create(dev, |
1378 | DRM_MODE_PROP_BLOB | |
1386 | DRM_MODE_PROP_BLOB | |
1379 | DRM_MODE_PROP_IMMUTABLE, |
1387 | DRM_MODE_PROP_IMMUTABLE, |
1380 | "TILE", 0); |
1388 | "TILE", 0); |
1381 | if (!prop) |
1389 | if (!prop) |
1382 | return -ENOMEM; |
1390 | return -ENOMEM; |
1383 | dev->mode_config.tile_property = prop; |
1391 | dev->mode_config.tile_property = prop; |
1384 | 1392 | ||
1385 | prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
1393 | prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
1386 | "type", drm_plane_type_enum_list, |
1394 | "type", drm_plane_type_enum_list, |
1387 | ARRAY_SIZE(drm_plane_type_enum_list)); |
1395 | ARRAY_SIZE(drm_plane_type_enum_list)); |
1388 | if (!prop) |
1396 | if (!prop) |
1389 | return -ENOMEM; |
1397 | return -ENOMEM; |
1390 | dev->mode_config.plane_type_property = prop; |
1398 | dev->mode_config.plane_type_property = prop; |
1391 | 1399 | ||
1392 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
1400 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
1393 | "SRC_X", 0, UINT_MAX); |
1401 | "SRC_X", 0, UINT_MAX); |
1394 | if (!prop) |
1402 | if (!prop) |
1395 | return -ENOMEM; |
1403 | return -ENOMEM; |
1396 | dev->mode_config.prop_src_x = prop; |
1404 | dev->mode_config.prop_src_x = prop; |
1397 | 1405 | ||
1398 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
1406 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
1399 | "SRC_Y", 0, UINT_MAX); |
1407 | "SRC_Y", 0, UINT_MAX); |
1400 | if (!prop) |
1408 | if (!prop) |
1401 | return -ENOMEM; |
1409 | return -ENOMEM; |
1402 | dev->mode_config.prop_src_y = prop; |
1410 | dev->mode_config.prop_src_y = prop; |
1403 | 1411 | ||
1404 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
1412 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
1405 | "SRC_W", 0, UINT_MAX); |
1413 | "SRC_W", 0, UINT_MAX); |
1406 | if (!prop) |
1414 | if (!prop) |
1407 | return -ENOMEM; |
1415 | return -ENOMEM; |
1408 | dev->mode_config.prop_src_w = prop; |
1416 | dev->mode_config.prop_src_w = prop; |
1409 | 1417 | ||
1410 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
1418 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
1411 | "SRC_H", 0, UINT_MAX); |
1419 | "SRC_H", 0, UINT_MAX); |
1412 | if (!prop) |
1420 | if (!prop) |
1413 | return -ENOMEM; |
1421 | return -ENOMEM; |
1414 | dev->mode_config.prop_src_h = prop; |
1422 | dev->mode_config.prop_src_h = prop; |
1415 | 1423 | ||
1416 | prop = drm_property_create_signed_range(dev, DRM_MODE_PROP_ATOMIC, |
1424 | prop = drm_property_create_signed_range(dev, DRM_MODE_PROP_ATOMIC, |
1417 | "CRTC_X", INT_MIN, INT_MAX); |
1425 | "CRTC_X", INT_MIN, INT_MAX); |
1418 | if (!prop) |
1426 | if (!prop) |
1419 | return -ENOMEM; |
1427 | return -ENOMEM; |
1420 | dev->mode_config.prop_crtc_x = prop; |
1428 | dev->mode_config.prop_crtc_x = prop; |
1421 | 1429 | ||
1422 | prop = drm_property_create_signed_range(dev, DRM_MODE_PROP_ATOMIC, |
1430 | prop = drm_property_create_signed_range(dev, DRM_MODE_PROP_ATOMIC, |
1423 | "CRTC_Y", INT_MIN, INT_MAX); |
1431 | "CRTC_Y", INT_MIN, INT_MAX); |
1424 | if (!prop) |
1432 | if (!prop) |
1425 | return -ENOMEM; |
1433 | return -ENOMEM; |
1426 | dev->mode_config.prop_crtc_y = prop; |
1434 | dev->mode_config.prop_crtc_y = prop; |
1427 | 1435 | ||
1428 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
1436 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
1429 | "CRTC_W", 0, INT_MAX); |
1437 | "CRTC_W", 0, INT_MAX); |
1430 | if (!prop) |
1438 | if (!prop) |
1431 | return -ENOMEM; |
1439 | return -ENOMEM; |
1432 | dev->mode_config.prop_crtc_w = prop; |
1440 | dev->mode_config.prop_crtc_w = prop; |
1433 | 1441 | ||
1434 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
1442 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
1435 | "CRTC_H", 0, INT_MAX); |
1443 | "CRTC_H", 0, INT_MAX); |
1436 | if (!prop) |
1444 | if (!prop) |
1437 | return -ENOMEM; |
1445 | return -ENOMEM; |
1438 | dev->mode_config.prop_crtc_h = prop; |
1446 | dev->mode_config.prop_crtc_h = prop; |
1439 | 1447 | ||
1440 | prop = drm_property_create_object(dev, DRM_MODE_PROP_ATOMIC, |
1448 | prop = drm_property_create_object(dev, DRM_MODE_PROP_ATOMIC, |
1441 | "FB_ID", DRM_MODE_OBJECT_FB); |
1449 | "FB_ID", DRM_MODE_OBJECT_FB); |
1442 | if (!prop) |
1450 | if (!prop) |
1443 | return -ENOMEM; |
1451 | return -ENOMEM; |
1444 | dev->mode_config.prop_fb_id = prop; |
1452 | dev->mode_config.prop_fb_id = prop; |
1445 | 1453 | ||
1446 | prop = drm_property_create_object(dev, DRM_MODE_PROP_ATOMIC, |
1454 | prop = drm_property_create_object(dev, DRM_MODE_PROP_ATOMIC, |
1447 | "CRTC_ID", DRM_MODE_OBJECT_CRTC); |
1455 | "CRTC_ID", DRM_MODE_OBJECT_CRTC); |
1448 | if (!prop) |
1456 | if (!prop) |
1449 | return -ENOMEM; |
1457 | return -ENOMEM; |
1450 | dev->mode_config.prop_crtc_id = prop; |
1458 | dev->mode_config.prop_crtc_id = prop; |
1451 | 1459 | ||
1452 | prop = drm_property_create_bool(dev, DRM_MODE_PROP_ATOMIC, |
1460 | prop = drm_property_create_bool(dev, DRM_MODE_PROP_ATOMIC, |
1453 | "ACTIVE"); |
1461 | "ACTIVE"); |
1454 | if (!prop) |
1462 | if (!prop) |
1455 | return -ENOMEM; |
1463 | return -ENOMEM; |
1456 | dev->mode_config.prop_active = prop; |
1464 | dev->mode_config.prop_active = prop; |
1457 | 1465 | ||
1458 | prop = drm_property_create(dev, |
1466 | prop = drm_property_create(dev, |
1459 | DRM_MODE_PROP_ATOMIC | DRM_MODE_PROP_BLOB, |
1467 | DRM_MODE_PROP_ATOMIC | DRM_MODE_PROP_BLOB, |
1460 | "MODE_ID", 0); |
1468 | "MODE_ID", 0); |
1461 | if (!prop) |
1469 | if (!prop) |
1462 | return -ENOMEM; |
1470 | return -ENOMEM; |
1463 | dev->mode_config.prop_mode_id = prop; |
1471 | dev->mode_config.prop_mode_id = prop; |
1464 | 1472 | ||
1465 | return 0; |
1473 | return 0; |
1466 | } |
1474 | } |
1467 | 1475 | ||
1468 | /** |
1476 | /** |
1469 | * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties |
1477 | * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties |
1470 | * @dev: DRM device |
1478 | * @dev: DRM device |
1471 | * |
1479 | * |
1472 | * Called by a driver the first time a DVI-I connector is made. |
1480 | * Called by a driver the first time a DVI-I connector is made. |
1473 | */ |
1481 | */ |
1474 | int drm_mode_create_dvi_i_properties(struct drm_device *dev) |
1482 | int drm_mode_create_dvi_i_properties(struct drm_device *dev) |
1475 | { |
1483 | { |
1476 | struct drm_property *dvi_i_selector; |
1484 | struct drm_property *dvi_i_selector; |
1477 | struct drm_property *dvi_i_subconnector; |
1485 | struct drm_property *dvi_i_subconnector; |
1478 | 1486 | ||
1479 | if (dev->mode_config.dvi_i_select_subconnector_property) |
1487 | if (dev->mode_config.dvi_i_select_subconnector_property) |
1480 | return 0; |
1488 | return 0; |
1481 | 1489 | ||
1482 | dvi_i_selector = |
1490 | dvi_i_selector = |
1483 | drm_property_create_enum(dev, 0, |
1491 | drm_property_create_enum(dev, 0, |
1484 | "select subconnector", |
1492 | "select subconnector", |
1485 | drm_dvi_i_select_enum_list, |
1493 | drm_dvi_i_select_enum_list, |
1486 | ARRAY_SIZE(drm_dvi_i_select_enum_list)); |
1494 | ARRAY_SIZE(drm_dvi_i_select_enum_list)); |
1487 | dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector; |
1495 | dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector; |
1488 | 1496 | ||
1489 | dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
1497 | dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
1490 | "subconnector", |
1498 | "subconnector", |
1491 | drm_dvi_i_subconnector_enum_list, |
1499 | drm_dvi_i_subconnector_enum_list, |
1492 | ARRAY_SIZE(drm_dvi_i_subconnector_enum_list)); |
1500 | ARRAY_SIZE(drm_dvi_i_subconnector_enum_list)); |
1493 | dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector; |
1501 | dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector; |
1494 | 1502 | ||
1495 | return 0; |
1503 | return 0; |
1496 | } |
1504 | } |
1497 | EXPORT_SYMBOL(drm_mode_create_dvi_i_properties); |
1505 | EXPORT_SYMBOL(drm_mode_create_dvi_i_properties); |
1498 | 1506 | ||
1499 | /** |
1507 | /** |
1500 | * drm_create_tv_properties - create TV specific connector properties |
1508 | * drm_create_tv_properties - create TV specific connector properties |
1501 | * @dev: DRM device |
1509 | * @dev: DRM device |
1502 | * @num_modes: number of different TV formats (modes) supported |
1510 | * @num_modes: number of different TV formats (modes) supported |
1503 | * @modes: array of pointers to strings containing name of each format |
1511 | * @modes: array of pointers to strings containing name of each format |
1504 | * |
1512 | * |
1505 | * Called by a driver's TV initialization routine, this function creates |
1513 | * Called by a driver's TV initialization routine, this function creates |
1506 | * the TV specific connector properties for a given device. Caller is |
1514 | * the TV specific connector properties for a given device. Caller is |
1507 | * responsible for allocating a list of format names and passing them to |
1515 | * responsible for allocating a list of format names and passing them to |
1508 | * this routine. |
1516 | * this routine. |
1509 | */ |
1517 | */ |
1510 | int drm_mode_create_tv_properties(struct drm_device *dev, |
1518 | int drm_mode_create_tv_properties(struct drm_device *dev, |
1511 | unsigned int num_modes, |
1519 | unsigned int num_modes, |
1512 | const char * const modes[]) |
1520 | const char * const modes[]) |
1513 | { |
1521 | { |
1514 | struct drm_property *tv_selector; |
1522 | struct drm_property *tv_selector; |
1515 | struct drm_property *tv_subconnector; |
1523 | struct drm_property *tv_subconnector; |
1516 | unsigned int i; |
1524 | unsigned int i; |
1517 | 1525 | ||
1518 | if (dev->mode_config.tv_select_subconnector_property) |
1526 | if (dev->mode_config.tv_select_subconnector_property) |
1519 | return 0; |
1527 | return 0; |
1520 | 1528 | ||
1521 | /* |
1529 | /* |
1522 | * Basic connector properties |
1530 | * Basic connector properties |
1523 | */ |
1531 | */ |
1524 | tv_selector = drm_property_create_enum(dev, 0, |
1532 | tv_selector = drm_property_create_enum(dev, 0, |
1525 | "select subconnector", |
1533 | "select subconnector", |
1526 | drm_tv_select_enum_list, |
1534 | drm_tv_select_enum_list, |
1527 | ARRAY_SIZE(drm_tv_select_enum_list)); |
1535 | ARRAY_SIZE(drm_tv_select_enum_list)); |
1528 | if (!tv_selector) |
1536 | if (!tv_selector) |
1529 | goto nomem; |
1537 | goto nomem; |
1530 | 1538 | ||
1531 | dev->mode_config.tv_select_subconnector_property = tv_selector; |
1539 | dev->mode_config.tv_select_subconnector_property = tv_selector; |
1532 | 1540 | ||
1533 | tv_subconnector = |
1541 | tv_subconnector = |
1534 | drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
1542 | drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
1535 | "subconnector", |
1543 | "subconnector", |
1536 | drm_tv_subconnector_enum_list, |
1544 | drm_tv_subconnector_enum_list, |
1537 | ARRAY_SIZE(drm_tv_subconnector_enum_list)); |
1545 | ARRAY_SIZE(drm_tv_subconnector_enum_list)); |
1538 | if (!tv_subconnector) |
1546 | if (!tv_subconnector) |
1539 | goto nomem; |
1547 | goto nomem; |
1540 | dev->mode_config.tv_subconnector_property = tv_subconnector; |
1548 | dev->mode_config.tv_subconnector_property = tv_subconnector; |
1541 | 1549 | ||
1542 | /* |
1550 | /* |
1543 | * Other, TV specific properties: margins & TV modes. |
1551 | * Other, TV specific properties: margins & TV modes. |
1544 | */ |
1552 | */ |
1545 | dev->mode_config.tv_left_margin_property = |
1553 | dev->mode_config.tv_left_margin_property = |
1546 | drm_property_create_range(dev, 0, "left margin", 0, 100); |
1554 | drm_property_create_range(dev, 0, "left margin", 0, 100); |
1547 | if (!dev->mode_config.tv_left_margin_property) |
1555 | if (!dev->mode_config.tv_left_margin_property) |
1548 | goto nomem; |
1556 | goto nomem; |
1549 | 1557 | ||
1550 | dev->mode_config.tv_right_margin_property = |
1558 | dev->mode_config.tv_right_margin_property = |
1551 | drm_property_create_range(dev, 0, "right margin", 0, 100); |
1559 | drm_property_create_range(dev, 0, "right margin", 0, 100); |
1552 | if (!dev->mode_config.tv_right_margin_property) |
1560 | if (!dev->mode_config.tv_right_margin_property) |
1553 | goto nomem; |
1561 | goto nomem; |
1554 | 1562 | ||
1555 | dev->mode_config.tv_top_margin_property = |
1563 | dev->mode_config.tv_top_margin_property = |
1556 | drm_property_create_range(dev, 0, "top margin", 0, 100); |
1564 | drm_property_create_range(dev, 0, "top margin", 0, 100); |
1557 | if (!dev->mode_config.tv_top_margin_property) |
1565 | if (!dev->mode_config.tv_top_margin_property) |
1558 | goto nomem; |
1566 | goto nomem; |
1559 | 1567 | ||
1560 | dev->mode_config.tv_bottom_margin_property = |
1568 | dev->mode_config.tv_bottom_margin_property = |
1561 | drm_property_create_range(dev, 0, "bottom margin", 0, 100); |
1569 | drm_property_create_range(dev, 0, "bottom margin", 0, 100); |
1562 | if (!dev->mode_config.tv_bottom_margin_property) |
1570 | if (!dev->mode_config.tv_bottom_margin_property) |
1563 | goto nomem; |
1571 | goto nomem; |
1564 | 1572 | ||
1565 | dev->mode_config.tv_mode_property = |
1573 | dev->mode_config.tv_mode_property = |
1566 | drm_property_create(dev, DRM_MODE_PROP_ENUM, |
1574 | drm_property_create(dev, DRM_MODE_PROP_ENUM, |
1567 | "mode", num_modes); |
1575 | "mode", num_modes); |
1568 | if (!dev->mode_config.tv_mode_property) |
1576 | if (!dev->mode_config.tv_mode_property) |
1569 | goto nomem; |
1577 | goto nomem; |
1570 | 1578 | ||
1571 | for (i = 0; i < num_modes; i++) |
1579 | for (i = 0; i < num_modes; i++) |
1572 | drm_property_add_enum(dev->mode_config.tv_mode_property, i, |
1580 | drm_property_add_enum(dev->mode_config.tv_mode_property, i, |
1573 | i, modes[i]); |
1581 | i, modes[i]); |
1574 | 1582 | ||
1575 | dev->mode_config.tv_brightness_property = |
1583 | dev->mode_config.tv_brightness_property = |
1576 | drm_property_create_range(dev, 0, "brightness", 0, 100); |
1584 | drm_property_create_range(dev, 0, "brightness", 0, 100); |
1577 | if (!dev->mode_config.tv_brightness_property) |
1585 | if (!dev->mode_config.tv_brightness_property) |
1578 | goto nomem; |
1586 | goto nomem; |
1579 | 1587 | ||
1580 | dev->mode_config.tv_contrast_property = |
1588 | dev->mode_config.tv_contrast_property = |
1581 | drm_property_create_range(dev, 0, "contrast", 0, 100); |
1589 | drm_property_create_range(dev, 0, "contrast", 0, 100); |
1582 | if (!dev->mode_config.tv_contrast_property) |
1590 | if (!dev->mode_config.tv_contrast_property) |
1583 | goto nomem; |
1591 | goto nomem; |
1584 | 1592 | ||
1585 | dev->mode_config.tv_flicker_reduction_property = |
1593 | dev->mode_config.tv_flicker_reduction_property = |
1586 | drm_property_create_range(dev, 0, "flicker reduction", 0, 100); |
1594 | drm_property_create_range(dev, 0, "flicker reduction", 0, 100); |
1587 | if (!dev->mode_config.tv_flicker_reduction_property) |
1595 | if (!dev->mode_config.tv_flicker_reduction_property) |
1588 | goto nomem; |
1596 | goto nomem; |
1589 | 1597 | ||
1590 | dev->mode_config.tv_overscan_property = |
1598 | dev->mode_config.tv_overscan_property = |
1591 | drm_property_create_range(dev, 0, "overscan", 0, 100); |
1599 | drm_property_create_range(dev, 0, "overscan", 0, 100); |
1592 | if (!dev->mode_config.tv_overscan_property) |
1600 | if (!dev->mode_config.tv_overscan_property) |
1593 | goto nomem; |
1601 | goto nomem; |
1594 | 1602 | ||
1595 | dev->mode_config.tv_saturation_property = |
1603 | dev->mode_config.tv_saturation_property = |
1596 | drm_property_create_range(dev, 0, "saturation", 0, 100); |
1604 | drm_property_create_range(dev, 0, "saturation", 0, 100); |
1597 | if (!dev->mode_config.tv_saturation_property) |
1605 | if (!dev->mode_config.tv_saturation_property) |
1598 | goto nomem; |
1606 | goto nomem; |
1599 | 1607 | ||
1600 | dev->mode_config.tv_hue_property = |
1608 | dev->mode_config.tv_hue_property = |
1601 | drm_property_create_range(dev, 0, "hue", 0, 100); |
1609 | drm_property_create_range(dev, 0, "hue", 0, 100); |
1602 | if (!dev->mode_config.tv_hue_property) |
1610 | if (!dev->mode_config.tv_hue_property) |
1603 | goto nomem; |
1611 | goto nomem; |
1604 | 1612 | ||
1605 | return 0; |
1613 | return 0; |
1606 | nomem: |
1614 | nomem: |
1607 | return -ENOMEM; |
1615 | return -ENOMEM; |
1608 | } |
1616 | } |
1609 | EXPORT_SYMBOL(drm_mode_create_tv_properties); |
1617 | EXPORT_SYMBOL(drm_mode_create_tv_properties); |
1610 | 1618 | ||
1611 | /** |
1619 | /** |
1612 | * drm_mode_create_scaling_mode_property - create scaling mode property |
1620 | * drm_mode_create_scaling_mode_property - create scaling mode property |
1613 | * @dev: DRM device |
1621 | * @dev: DRM device |
1614 | * |
1622 | * |
1615 | * Called by a driver the first time it's needed, must be attached to desired |
1623 | * Called by a driver the first time it's needed, must be attached to desired |
1616 | * connectors. |
1624 | * connectors. |
1617 | */ |
1625 | */ |
1618 | int drm_mode_create_scaling_mode_property(struct drm_device *dev) |
1626 | int drm_mode_create_scaling_mode_property(struct drm_device *dev) |
1619 | { |
1627 | { |
1620 | struct drm_property *scaling_mode; |
1628 | struct drm_property *scaling_mode; |
1621 | 1629 | ||
1622 | if (dev->mode_config.scaling_mode_property) |
1630 | if (dev->mode_config.scaling_mode_property) |
1623 | return 0; |
1631 | return 0; |
1624 | 1632 | ||
1625 | scaling_mode = |
1633 | scaling_mode = |
1626 | drm_property_create_enum(dev, 0, "scaling mode", |
1634 | drm_property_create_enum(dev, 0, "scaling mode", |
1627 | drm_scaling_mode_enum_list, |
1635 | drm_scaling_mode_enum_list, |
1628 | ARRAY_SIZE(drm_scaling_mode_enum_list)); |
1636 | ARRAY_SIZE(drm_scaling_mode_enum_list)); |
1629 | 1637 | ||
1630 | dev->mode_config.scaling_mode_property = scaling_mode; |
1638 | dev->mode_config.scaling_mode_property = scaling_mode; |
1631 | 1639 | ||
1632 | return 0; |
1640 | return 0; |
1633 | } |
1641 | } |
1634 | EXPORT_SYMBOL(drm_mode_create_scaling_mode_property); |
1642 | EXPORT_SYMBOL(drm_mode_create_scaling_mode_property); |
1635 | 1643 | ||
1636 | /** |
1644 | /** |
1637 | * drm_mode_create_aspect_ratio_property - create aspect ratio property |
1645 | * drm_mode_create_aspect_ratio_property - create aspect ratio property |
1638 | * @dev: DRM device |
1646 | * @dev: DRM device |
1639 | * |
1647 | * |
1640 | * Called by a driver the first time it's needed, must be attached to desired |
1648 | * Called by a driver the first time it's needed, must be attached to desired |
1641 | * connectors. |
1649 | * connectors. |
1642 | * |
1650 | * |
1643 | * Returns: |
1651 | * Returns: |
1644 | * Zero on success, negative errno on failure. |
1652 | * Zero on success, negative errno on failure. |
1645 | */ |
1653 | */ |
1646 | int drm_mode_create_aspect_ratio_property(struct drm_device *dev) |
1654 | int drm_mode_create_aspect_ratio_property(struct drm_device *dev) |
1647 | { |
1655 | { |
1648 | if (dev->mode_config.aspect_ratio_property) |
1656 | if (dev->mode_config.aspect_ratio_property) |
1649 | return 0; |
1657 | return 0; |
1650 | 1658 | ||
1651 | dev->mode_config.aspect_ratio_property = |
1659 | dev->mode_config.aspect_ratio_property = |
1652 | drm_property_create_enum(dev, 0, "aspect ratio", |
1660 | drm_property_create_enum(dev, 0, "aspect ratio", |
1653 | drm_aspect_ratio_enum_list, |
1661 | drm_aspect_ratio_enum_list, |
1654 | ARRAY_SIZE(drm_aspect_ratio_enum_list)); |
1662 | ARRAY_SIZE(drm_aspect_ratio_enum_list)); |
1655 | 1663 | ||
1656 | if (dev->mode_config.aspect_ratio_property == NULL) |
1664 | if (dev->mode_config.aspect_ratio_property == NULL) |
1657 | return -ENOMEM; |
1665 | return -ENOMEM; |
1658 | 1666 | ||
1659 | return 0; |
1667 | return 0; |
1660 | } |
1668 | } |
1661 | EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property); |
1669 | EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property); |
1662 | 1670 | ||
1663 | /** |
1671 | /** |
1664 | * drm_mode_create_dirty_property - create dirty property |
1672 | * drm_mode_create_dirty_property - create dirty property |
1665 | * @dev: DRM device |
1673 | * @dev: DRM device |
1666 | * |
1674 | * |
1667 | * Called by a driver the first time it's needed, must be attached to desired |
1675 | * Called by a driver the first time it's needed, must be attached to desired |
1668 | * connectors. |
1676 | * connectors. |
1669 | */ |
1677 | */ |
1670 | int drm_mode_create_dirty_info_property(struct drm_device *dev) |
1678 | int drm_mode_create_dirty_info_property(struct drm_device *dev) |
1671 | { |
1679 | { |
1672 | struct drm_property *dirty_info; |
1680 | struct drm_property *dirty_info; |
1673 | 1681 | ||
1674 | if (dev->mode_config.dirty_info_property) |
1682 | if (dev->mode_config.dirty_info_property) |
1675 | return 0; |
1683 | return 0; |
1676 | 1684 | ||
1677 | dirty_info = |
1685 | dirty_info = |
1678 | drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
1686 | drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
1679 | "dirty", |
1687 | "dirty", |
1680 | drm_dirty_info_enum_list, |
1688 | drm_dirty_info_enum_list, |
1681 | ARRAY_SIZE(drm_dirty_info_enum_list)); |
1689 | ARRAY_SIZE(drm_dirty_info_enum_list)); |
1682 | dev->mode_config.dirty_info_property = dirty_info; |
1690 | dev->mode_config.dirty_info_property = dirty_info; |
1683 | 1691 | ||
1684 | return 0; |
1692 | return 0; |
1685 | } |
1693 | } |
1686 | EXPORT_SYMBOL(drm_mode_create_dirty_info_property); |
1694 | EXPORT_SYMBOL(drm_mode_create_dirty_info_property); |
1687 | 1695 | ||
1688 | /** |
1696 | /** |
1689 | * drm_mode_create_suggested_offset_properties - create suggests offset properties |
1697 | * drm_mode_create_suggested_offset_properties - create suggests offset properties |
1690 | * @dev: DRM device |
1698 | * @dev: DRM device |
1691 | * |
1699 | * |
1692 | * Create the the suggested x/y offset property for connectors. |
1700 | * Create the the suggested x/y offset property for connectors. |
1693 | */ |
1701 | */ |
1694 | int drm_mode_create_suggested_offset_properties(struct drm_device *dev) |
1702 | int drm_mode_create_suggested_offset_properties(struct drm_device *dev) |
1695 | { |
1703 | { |
1696 | if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property) |
1704 | if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property) |
1697 | return 0; |
1705 | return 0; |
1698 | 1706 | ||
1699 | dev->mode_config.suggested_x_property = |
1707 | dev->mode_config.suggested_x_property = |
1700 | drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff); |
1708 | drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff); |
1701 | 1709 | ||
1702 | dev->mode_config.suggested_y_property = |
1710 | dev->mode_config.suggested_y_property = |
1703 | drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff); |
1711 | drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff); |
1704 | 1712 | ||
1705 | if (dev->mode_config.suggested_x_property == NULL || |
1713 | if (dev->mode_config.suggested_x_property == NULL || |
1706 | dev->mode_config.suggested_y_property == NULL) |
1714 | dev->mode_config.suggested_y_property == NULL) |
1707 | return -ENOMEM; |
1715 | return -ENOMEM; |
1708 | return 0; |
1716 | return 0; |
1709 | } |
1717 | } |
1710 | EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties); |
1718 | EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties); |
1711 | 1719 | ||
1712 | #if 0 |
1720 | #if 0 |
1713 | /** |
1721 | /** |
1714 | * drm_mode_getresources - get graphics configuration |
1722 | * drm_mode_getresources - get graphics configuration |
1715 | * @dev: drm device for the ioctl |
1723 | * @dev: drm device for the ioctl |
1716 | * @data: data pointer for the ioctl |
1724 | * @data: data pointer for the ioctl |
1717 | * @file_priv: drm file for the ioctl call |
1725 | * @file_priv: drm file for the ioctl call |
1718 | * |
1726 | * |
1719 | * Construct a set of configuration description structures and return |
1727 | * Construct a set of configuration description structures and return |
1720 | * them to the user, including CRTC, connector and framebuffer configuration. |
1728 | * them to the user, including CRTC, connector and framebuffer configuration. |
1721 | * |
1729 | * |
1722 | * Called by the user via ioctl. |
1730 | * Called by the user via ioctl. |
1723 | * |
1731 | * |
1724 | * Returns: |
1732 | * Returns: |
1725 | * Zero on success, negative errno on failure. |
1733 | * Zero on success, negative errno on failure. |
1726 | */ |
1734 | */ |
1727 | int drm_mode_getresources(struct drm_device *dev, void *data, |
1735 | int drm_mode_getresources(struct drm_device *dev, void *data, |
1728 | struct drm_file *file_priv) |
1736 | struct drm_file *file_priv) |
1729 | { |
1737 | { |
1730 | struct drm_mode_card_res *card_res = data; |
1738 | struct drm_mode_card_res *card_res = data; |
1731 | struct list_head *lh; |
1739 | struct list_head *lh; |
1732 | struct drm_framebuffer *fb; |
1740 | struct drm_framebuffer *fb; |
1733 | struct drm_connector *connector; |
1741 | struct drm_connector *connector; |
1734 | struct drm_crtc *crtc; |
1742 | struct drm_crtc *crtc; |
1735 | struct drm_encoder *encoder; |
1743 | struct drm_encoder *encoder; |
1736 | int ret = 0; |
1744 | int ret = 0; |
1737 | int connector_count = 0; |
1745 | int connector_count = 0; |
1738 | int crtc_count = 0; |
1746 | int crtc_count = 0; |
1739 | int fb_count = 0; |
1747 | int fb_count = 0; |
1740 | int encoder_count = 0; |
1748 | int encoder_count = 0; |
1741 | int copied = 0; |
1749 | int copied = 0; |
1742 | uint32_t __user *fb_id; |
1750 | uint32_t __user *fb_id; |
1743 | uint32_t __user *crtc_id; |
1751 | uint32_t __user *crtc_id; |
1744 | uint32_t __user *connector_id; |
1752 | uint32_t __user *connector_id; |
1745 | uint32_t __user *encoder_id; |
1753 | uint32_t __user *encoder_id; |
1746 | 1754 | ||
1747 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
1755 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
1748 | return -EINVAL; |
1756 | return -EINVAL; |
1749 | 1757 | ||
1750 | 1758 | ||
1751 | mutex_lock(&file_priv->fbs_lock); |
1759 | mutex_lock(&file_priv->fbs_lock); |
1752 | /* |
1760 | /* |
1753 | * For the non-control nodes we need to limit the list of resources |
1761 | * For the non-control nodes we need to limit the list of resources |
1754 | * by IDs in the group list for this node |
1762 | * by IDs in the group list for this node |
1755 | */ |
1763 | */ |
1756 | list_for_each(lh, &file_priv->fbs) |
1764 | list_for_each(lh, &file_priv->fbs) |
1757 | fb_count++; |
1765 | fb_count++; |
1758 | 1766 | ||
1759 | /* handle this in 4 parts */ |
1767 | /* handle this in 4 parts */ |
1760 | /* FBs */ |
1768 | /* FBs */ |
1761 | if (card_res->count_fbs >= fb_count) { |
1769 | if (card_res->count_fbs >= fb_count) { |
1762 | copied = 0; |
1770 | copied = 0; |
1763 | fb_id = (uint32_t __user *)(unsigned long)card_res->fb_id_ptr; |
1771 | fb_id = (uint32_t __user *)(unsigned long)card_res->fb_id_ptr; |
1764 | list_for_each_entry(fb, &file_priv->fbs, filp_head) { |
1772 | list_for_each_entry(fb, &file_priv->fbs, filp_head) { |
1765 | if (put_user(fb->base.id, fb_id + copied)) { |
1773 | if (put_user(fb->base.id, fb_id + copied)) { |
1766 | mutex_unlock(&file_priv->fbs_lock); |
1774 | mutex_unlock(&file_priv->fbs_lock); |
1767 | return -EFAULT; |
1775 | return -EFAULT; |
1768 | } |
1776 | } |
1769 | copied++; |
1777 | copied++; |
1770 | } |
1778 | } |
1771 | } |
1779 | } |
1772 | card_res->count_fbs = fb_count; |
1780 | card_res->count_fbs = fb_count; |
1773 | mutex_unlock(&file_priv->fbs_lock); |
1781 | mutex_unlock(&file_priv->fbs_lock); |
1774 | 1782 | ||
1775 | /* mode_config.mutex protects the connector list against e.g. DP MST |
1783 | /* mode_config.mutex protects the connector list against e.g. DP MST |
1776 | * connector hot-adding. CRTC/Plane lists are invariant. */ |
1784 | * connector hot-adding. CRTC/Plane lists are invariant. */ |
1777 | mutex_lock(&dev->mode_config.mutex); |
1785 | mutex_lock(&dev->mode_config.mutex); |
1778 | drm_for_each_crtc(crtc, dev) |
1786 | drm_for_each_crtc(crtc, dev) |
1779 | crtc_count++; |
1787 | crtc_count++; |
1780 | 1788 | ||
1781 | drm_for_each_connector(connector, dev) |
1789 | drm_for_each_connector(connector, dev) |
1782 | connector_count++; |
1790 | connector_count++; |
1783 | 1791 | ||
1784 | drm_for_each_encoder(encoder, dev) |
1792 | drm_for_each_encoder(encoder, dev) |
1785 | encoder_count++; |
1793 | encoder_count++; |
1786 | 1794 | ||
1787 | card_res->max_height = dev->mode_config.max_height; |
1795 | card_res->max_height = dev->mode_config.max_height; |
1788 | card_res->min_height = dev->mode_config.min_height; |
1796 | card_res->min_height = dev->mode_config.min_height; |
1789 | card_res->max_width = dev->mode_config.max_width; |
1797 | card_res->max_width = dev->mode_config.max_width; |
1790 | card_res->min_width = dev->mode_config.min_width; |
1798 | card_res->min_width = dev->mode_config.min_width; |
1791 | 1799 | ||
1792 | /* CRTCs */ |
1800 | /* CRTCs */ |
1793 | if (card_res->count_crtcs >= crtc_count) { |
1801 | if (card_res->count_crtcs >= crtc_count) { |
1794 | copied = 0; |
1802 | copied = 0; |
1795 | crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr; |
1803 | crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr; |
1796 | drm_for_each_crtc(crtc, dev) { |
1804 | drm_for_each_crtc(crtc, dev) { |
1797 | DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id); |
1805 | DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id); |
1798 | if (put_user(crtc->base.id, crtc_id + copied)) { |
1806 | if (put_user(crtc->base.id, crtc_id + copied)) { |
1799 | ret = -EFAULT; |
1807 | ret = -EFAULT; |
1800 | goto out; |
1808 | goto out; |
1801 | } |
1809 | } |
1802 | copied++; |
1810 | copied++; |
1803 | } |
1811 | } |
1804 | } |
1812 | } |
1805 | card_res->count_crtcs = crtc_count; |
1813 | card_res->count_crtcs = crtc_count; |
1806 | 1814 | ||
1807 | /* Encoders */ |
1815 | /* Encoders */ |
1808 | if (card_res->count_encoders >= encoder_count) { |
1816 | if (card_res->count_encoders >= encoder_count) { |
1809 | copied = 0; |
1817 | copied = 0; |
1810 | encoder_id = (uint32_t __user *)(unsigned long)card_res->encoder_id_ptr; |
1818 | encoder_id = (uint32_t __user *)(unsigned long)card_res->encoder_id_ptr; |
1811 | drm_for_each_encoder(encoder, dev) { |
1819 | drm_for_each_encoder(encoder, dev) { |
1812 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder->base.id, |
1820 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder->base.id, |
1813 | encoder->name); |
1821 | encoder->name); |
1814 | if (put_user(encoder->base.id, encoder_id + |
1822 | if (put_user(encoder->base.id, encoder_id + |
1815 | copied)) { |
1823 | copied)) { |
1816 | ret = -EFAULT; |
1824 | ret = -EFAULT; |
1817 | goto out; |
1825 | goto out; |
1818 | } |
1826 | } |
1819 | copied++; |
1827 | copied++; |
1820 | } |
1828 | } |
1821 | } |
1829 | } |
1822 | card_res->count_encoders = encoder_count; |
1830 | card_res->count_encoders = encoder_count; |
1823 | 1831 | ||
1824 | /* Connectors */ |
1832 | /* Connectors */ |
1825 | if (card_res->count_connectors >= connector_count) { |
1833 | if (card_res->count_connectors >= connector_count) { |
1826 | copied = 0; |
1834 | copied = 0; |
1827 | connector_id = (uint32_t __user *)(unsigned long)card_res->connector_id_ptr; |
1835 | connector_id = (uint32_t __user *)(unsigned long)card_res->connector_id_ptr; |
1828 | drm_for_each_connector(connector, dev) { |
1836 | drm_for_each_connector(connector, dev) { |
1829 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
1837 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
1830 | connector->base.id, |
1838 | connector->base.id, |
1831 | connector->name); |
1839 | connector->name); |
1832 | if (put_user(connector->base.id, |
1840 | if (put_user(connector->base.id, |
1833 | connector_id + copied)) { |
1841 | connector_id + copied)) { |
1834 | ret = -EFAULT; |
1842 | ret = -EFAULT; |
1835 | goto out; |
1843 | goto out; |
1836 | } |
1844 | } |
1837 | copied++; |
1845 | copied++; |
1838 | } |
1846 | } |
1839 | } |
1847 | } |
1840 | card_res->count_connectors = connector_count; |
1848 | card_res->count_connectors = connector_count; |
1841 | 1849 | ||
1842 | DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res->count_crtcs, |
1850 | DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res->count_crtcs, |
1843 | card_res->count_connectors, card_res->count_encoders); |
1851 | card_res->count_connectors, card_res->count_encoders); |
1844 | 1852 | ||
1845 | out: |
1853 | out: |
1846 | mutex_unlock(&dev->mode_config.mutex); |
1854 | mutex_unlock(&dev->mode_config.mutex); |
1847 | return ret; |
1855 | return ret; |
1848 | } |
1856 | } |
1849 | 1857 | ||
1850 | /** |
1858 | /** |
1851 | * drm_mode_getcrtc - get CRTC configuration |
1859 | * drm_mode_getcrtc - get CRTC configuration |
1852 | * @dev: drm device for the ioctl |
1860 | * @dev: drm device for the ioctl |
1853 | * @data: data pointer for the ioctl |
1861 | * @data: data pointer for the ioctl |
1854 | * @file_priv: drm file for the ioctl call |
1862 | * @file_priv: drm file for the ioctl call |
1855 | * |
1863 | * |
1856 | * Construct a CRTC configuration structure to return to the user. |
1864 | * Construct a CRTC configuration structure to return to the user. |
1857 | * |
1865 | * |
1858 | * Called by the user via ioctl. |
1866 | * Called by the user via ioctl. |
1859 | * |
1867 | * |
1860 | * Returns: |
1868 | * Returns: |
1861 | * Zero on success, negative errno on failure. |
1869 | * Zero on success, negative errno on failure. |
1862 | */ |
1870 | */ |
1863 | int drm_mode_getcrtc(struct drm_device *dev, |
1871 | int drm_mode_getcrtc(struct drm_device *dev, |
1864 | void *data, struct drm_file *file_priv) |
1872 | void *data, struct drm_file *file_priv) |
1865 | { |
1873 | { |
1866 | struct drm_mode_crtc *crtc_resp = data; |
1874 | struct drm_mode_crtc *crtc_resp = data; |
1867 | struct drm_crtc *crtc; |
1875 | struct drm_crtc *crtc; |
1868 | 1876 | ||
1869 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
1877 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
1870 | return -EINVAL; |
1878 | return -EINVAL; |
1871 | 1879 | ||
1872 | crtc = drm_crtc_find(dev, crtc_resp->crtc_id); |
1880 | crtc = drm_crtc_find(dev, crtc_resp->crtc_id); |
1873 | if (!crtc) |
1881 | if (!crtc) |
1874 | return -ENOENT; |
1882 | return -ENOENT; |
1875 | 1883 | ||
1876 | drm_modeset_lock_crtc(crtc, crtc->primary); |
1884 | drm_modeset_lock_crtc(crtc, crtc->primary); |
1877 | crtc_resp->gamma_size = crtc->gamma_size; |
1885 | crtc_resp->gamma_size = crtc->gamma_size; |
1878 | if (crtc->primary->fb) |
1886 | if (crtc->primary->fb) |
1879 | crtc_resp->fb_id = crtc->primary->fb->base.id; |
1887 | crtc_resp->fb_id = crtc->primary->fb->base.id; |
1880 | else |
1888 | else |
1881 | crtc_resp->fb_id = 0; |
1889 | crtc_resp->fb_id = 0; |
1882 | 1890 | ||
1883 | if (crtc->state) { |
1891 | if (crtc->state) { |
1884 | crtc_resp->x = crtc->primary->state->src_x >> 16; |
1892 | crtc_resp->x = crtc->primary->state->src_x >> 16; |
1885 | crtc_resp->y = crtc->primary->state->src_y >> 16; |
1893 | crtc_resp->y = crtc->primary->state->src_y >> 16; |
1886 | if (crtc->state->enable) { |
1894 | if (crtc->state->enable) { |
1887 | drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->state->mode); |
1895 | drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->state->mode); |
1888 | crtc_resp->mode_valid = 1; |
1896 | crtc_resp->mode_valid = 1; |
1889 | 1897 | ||
1890 | } else { |
1898 | } else { |
1891 | crtc_resp->mode_valid = 0; |
1899 | crtc_resp->mode_valid = 0; |
1892 | } |
1900 | } |
1893 | } else { |
1901 | } else { |
1894 | crtc_resp->x = crtc->x; |
1902 | crtc_resp->x = crtc->x; |
1895 | crtc_resp->y = crtc->y; |
1903 | crtc_resp->y = crtc->y; |
1896 | if (crtc->enabled) { |
1904 | if (crtc->enabled) { |
1897 | drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->mode); |
1905 | drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->mode); |
1898 | crtc_resp->mode_valid = 1; |
1906 | crtc_resp->mode_valid = 1; |
1899 | 1907 | ||
1900 | } else { |
1908 | } else { |
1901 | crtc_resp->mode_valid = 0; |
1909 | crtc_resp->mode_valid = 0; |
1902 | } |
1910 | } |
1903 | } |
1911 | } |
1904 | drm_modeset_unlock_crtc(crtc); |
1912 | drm_modeset_unlock_crtc(crtc); |
1905 | 1913 | ||
1906 | return 0; |
1914 | return 0; |
1907 | } |
1915 | } |
1908 | 1916 | ||
1909 | static bool drm_mode_expose_to_userspace(const struct drm_display_mode *mode, |
1917 | static bool drm_mode_expose_to_userspace(const struct drm_display_mode *mode, |
1910 | const struct drm_file *file_priv) |
1918 | const struct drm_file *file_priv) |
1911 | { |
1919 | { |
1912 | /* |
1920 | /* |
1913 | * If user-space hasn't configured the driver to expose the stereo 3D |
1921 | * If user-space hasn't configured the driver to expose the stereo 3D |
1914 | * modes, don't expose them. |
1922 | * modes, don't expose them. |
1915 | */ |
1923 | */ |
1916 | if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode)) |
1924 | if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode)) |
1917 | return false; |
1925 | return false; |
1918 | 1926 | ||
1919 | return true; |
1927 | return true; |
1920 | } |
1928 | } |
1921 | 1929 | ||
1922 | static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector) |
1930 | static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector) |
1923 | { |
1931 | { |
1924 | /* For atomic drivers only state objects are synchronously updated and |
1932 | /* For atomic drivers only state objects are synchronously updated and |
1925 | * protected by modeset locks, so check those first. */ |
1933 | * protected by modeset locks, so check those first. */ |
1926 | if (connector->state) |
1934 | if (connector->state) |
1927 | return connector->state->best_encoder; |
1935 | return connector->state->best_encoder; |
1928 | return connector->encoder; |
1936 | return connector->encoder; |
1929 | } |
1937 | } |
1930 | 1938 | ||
1931 | /* helper for getconnector and getproperties ioctls */ |
1939 | /* helper for getconnector and getproperties ioctls */ |
1932 | static int get_properties(struct drm_mode_object *obj, bool atomic, |
1940 | static int get_properties(struct drm_mode_object *obj, bool atomic, |
1933 | uint32_t __user *prop_ptr, uint64_t __user *prop_values, |
1941 | uint32_t __user *prop_ptr, uint64_t __user *prop_values, |
1934 | uint32_t *arg_count_props) |
1942 | uint32_t *arg_count_props) |
1935 | { |
1943 | { |
1936 | int props_count; |
1944 | int props_count; |
1937 | int i, ret, copied; |
1945 | int i, ret, copied; |
1938 | 1946 | ||
1939 | props_count = obj->properties->count; |
1947 | props_count = obj->properties->count; |
1940 | if (!atomic) |
1948 | if (!atomic) |
1941 | props_count -= obj->properties->atomic_count; |
1949 | props_count -= obj->properties->atomic_count; |
1942 | 1950 | ||
1943 | if ((*arg_count_props >= props_count) && props_count) { |
1951 | if ((*arg_count_props >= props_count) && props_count) { |
1944 | for (i = 0, copied = 0; copied < props_count; i++) { |
1952 | for (i = 0, copied = 0; copied < props_count; i++) { |
1945 | struct drm_property *prop = obj->properties->properties[i]; |
1953 | struct drm_property *prop = obj->properties->properties[i]; |
1946 | uint64_t val; |
1954 | uint64_t val; |
1947 | 1955 | ||
1948 | if ((prop->flags & DRM_MODE_PROP_ATOMIC) && !atomic) |
1956 | if ((prop->flags & DRM_MODE_PROP_ATOMIC) && !atomic) |
1949 | continue; |
1957 | continue; |
1950 | 1958 | ||
1951 | ret = drm_object_property_get_value(obj, prop, &val); |
1959 | ret = drm_object_property_get_value(obj, prop, &val); |
1952 | if (ret) |
1960 | if (ret) |
1953 | return ret; |
1961 | return ret; |
1954 | 1962 | ||
1955 | if (put_user(prop->base.id, prop_ptr + copied)) |
1963 | if (put_user(prop->base.id, prop_ptr + copied)) |
1956 | return -EFAULT; |
1964 | return -EFAULT; |
1957 | 1965 | ||
1958 | if (put_user(val, prop_values + copied)) |
1966 | if (put_user(val, prop_values + copied)) |
1959 | return -EFAULT; |
1967 | return -EFAULT; |
1960 | 1968 | ||
1961 | copied++; |
1969 | copied++; |
1962 | } |
1970 | } |
1963 | } |
1971 | } |
1964 | *arg_count_props = props_count; |
1972 | *arg_count_props = props_count; |
1965 | 1973 | ||
1966 | return 0; |
1974 | return 0; |
1967 | } |
1975 | } |
1968 | 1976 | ||
1969 | /** |
1977 | /** |
1970 | * drm_mode_getconnector - get connector configuration |
1978 | * drm_mode_getconnector - get connector configuration |
1971 | * @dev: drm device for the ioctl |
1979 | * @dev: drm device for the ioctl |
1972 | * @data: data pointer for the ioctl |
1980 | * @data: data pointer for the ioctl |
1973 | * @file_priv: drm file for the ioctl call |
1981 | * @file_priv: drm file for the ioctl call |
1974 | * |
1982 | * |
1975 | * Construct a connector configuration structure to return to the user. |
1983 | * Construct a connector configuration structure to return to the user. |
1976 | * |
1984 | * |
1977 | * Called by the user via ioctl. |
1985 | * Called by the user via ioctl. |
1978 | * |
1986 | * |
1979 | * Returns: |
1987 | * Returns: |
1980 | * Zero on success, negative errno on failure. |
1988 | * Zero on success, negative errno on failure. |
1981 | */ |
1989 | */ |
1982 | int drm_mode_getconnector(struct drm_device *dev, void *data, |
1990 | int drm_mode_getconnector(struct drm_device *dev, void *data, |
1983 | struct drm_file *file_priv) |
1991 | struct drm_file *file_priv) |
1984 | { |
1992 | { |
1985 | struct drm_mode_get_connector *out_resp = data; |
1993 | struct drm_mode_get_connector *out_resp = data; |
1986 | struct drm_connector *connector; |
1994 | struct drm_connector *connector; |
1987 | struct drm_encoder *encoder; |
1995 | struct drm_encoder *encoder; |
1988 | struct drm_display_mode *mode; |
1996 | struct drm_display_mode *mode; |
1989 | int mode_count = 0; |
1997 | int mode_count = 0; |
1990 | int encoders_count = 0; |
1998 | int encoders_count = 0; |
1991 | int ret = 0; |
1999 | int ret = 0; |
1992 | int copied = 0; |
2000 | int copied = 0; |
1993 | int i; |
2001 | int i; |
1994 | struct drm_mode_modeinfo u_mode; |
2002 | struct drm_mode_modeinfo u_mode; |
1995 | struct drm_mode_modeinfo __user *mode_ptr; |
2003 | struct drm_mode_modeinfo __user *mode_ptr; |
1996 | uint32_t __user *encoder_ptr; |
2004 | uint32_t __user *encoder_ptr; |
1997 | 2005 | ||
1998 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
2006 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
1999 | return -EINVAL; |
2007 | return -EINVAL; |
2000 | 2008 | ||
2001 | memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo)); |
2009 | memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo)); |
2002 | 2010 | ||
2003 | DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp->connector_id); |
2011 | DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp->connector_id); |
2004 | 2012 | ||
2005 | mutex_lock(&dev->mode_config.mutex); |
2013 | mutex_lock(&dev->mode_config.mutex); |
2006 | 2014 | ||
2007 | connector = drm_connector_find(dev, out_resp->connector_id); |
2015 | connector = drm_connector_find(dev, out_resp->connector_id); |
2008 | if (!connector) { |
2016 | if (!connector) { |
2009 | ret = -ENOENT; |
2017 | ret = -ENOENT; |
2010 | goto out_unlock; |
2018 | goto out_unlock; |
2011 | } |
2019 | } |
2012 | 2020 | ||
2013 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) |
2021 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) |
2014 | if (connector->encoder_ids[i] != 0) |
2022 | if (connector->encoder_ids[i] != 0) |
2015 | encoders_count++; |
2023 | encoders_count++; |
2016 | 2024 | ||
2017 | if (out_resp->count_modes == 0) { |
2025 | if (out_resp->count_modes == 0) { |
2018 | connector->funcs->fill_modes(connector, |
2026 | connector->funcs->fill_modes(connector, |
2019 | dev->mode_config.max_width, |
2027 | dev->mode_config.max_width, |
2020 | dev->mode_config.max_height); |
2028 | dev->mode_config.max_height); |
2021 | } |
2029 | } |
2022 | 2030 | ||
2023 | /* delayed so we get modes regardless of pre-fill_modes state */ |
2031 | /* delayed so we get modes regardless of pre-fill_modes state */ |
2024 | list_for_each_entry(mode, &connector->modes, head) |
2032 | list_for_each_entry(mode, &connector->modes, head) |
2025 | if (drm_mode_expose_to_userspace(mode, file_priv)) |
2033 | if (drm_mode_expose_to_userspace(mode, file_priv)) |
2026 | mode_count++; |
2034 | mode_count++; |
2027 | 2035 | ||
2028 | out_resp->connector_id = connector->base.id; |
2036 | out_resp->connector_id = connector->base.id; |
2029 | out_resp->connector_type = connector->connector_type; |
2037 | out_resp->connector_type = connector->connector_type; |
2030 | out_resp->connector_type_id = connector->connector_type_id; |
2038 | out_resp->connector_type_id = connector->connector_type_id; |
2031 | out_resp->mm_width = connector->display_info.width_mm; |
2039 | out_resp->mm_width = connector->display_info.width_mm; |
2032 | out_resp->mm_height = connector->display_info.height_mm; |
2040 | out_resp->mm_height = connector->display_info.height_mm; |
2033 | out_resp->subpixel = connector->display_info.subpixel_order; |
2041 | out_resp->subpixel = connector->display_info.subpixel_order; |
2034 | out_resp->connection = connector->status; |
2042 | out_resp->connection = connector->status; |
2035 | 2043 | ||
2036 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
2044 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
2037 | encoder = drm_connector_get_encoder(connector); |
2045 | encoder = drm_connector_get_encoder(connector); |
2038 | if (encoder) |
2046 | if (encoder) |
2039 | out_resp->encoder_id = encoder->base.id; |
2047 | out_resp->encoder_id = encoder->base.id; |
2040 | else |
2048 | else |
2041 | out_resp->encoder_id = 0; |
2049 | out_resp->encoder_id = 0; |
2042 | 2050 | ||
2043 | /* |
2051 | /* |
2044 | * This ioctl is called twice, once to determine how much space is |
2052 | * This ioctl is called twice, once to determine how much space is |
2045 | * needed, and the 2nd time to fill it. |
2053 | * needed, and the 2nd time to fill it. |
2046 | */ |
2054 | */ |
2047 | if ((out_resp->count_modes >= mode_count) && mode_count) { |
2055 | if ((out_resp->count_modes >= mode_count) && mode_count) { |
2048 | copied = 0; |
2056 | copied = 0; |
2049 | mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr; |
2057 | mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr; |
2050 | list_for_each_entry(mode, &connector->modes, head) { |
2058 | list_for_each_entry(mode, &connector->modes, head) { |
2051 | if (!drm_mode_expose_to_userspace(mode, file_priv)) |
2059 | if (!drm_mode_expose_to_userspace(mode, file_priv)) |
2052 | continue; |
2060 | continue; |
2053 | 2061 | ||
2054 | drm_mode_convert_to_umode(&u_mode, mode); |
2062 | drm_mode_convert_to_umode(&u_mode, mode); |
2055 | if (copy_to_user(mode_ptr + copied, |
2063 | if (copy_to_user(mode_ptr + copied, |
2056 | &u_mode, sizeof(u_mode))) { |
2064 | &u_mode, sizeof(u_mode))) { |
2057 | ret = -EFAULT; |
2065 | ret = -EFAULT; |
2058 | goto out; |
2066 | goto out; |
2059 | } |
2067 | } |
2060 | copied++; |
2068 | copied++; |
2061 | } |
2069 | } |
2062 | } |
2070 | } |
2063 | out_resp->count_modes = mode_count; |
2071 | out_resp->count_modes = mode_count; |
2064 | 2072 | ||
2065 | ret = get_properties(&connector->base, file_priv->atomic, |
2073 | ret = get_properties(&connector->base, file_priv->atomic, |
2066 | (uint32_t __user *)(unsigned long)(out_resp->props_ptr), |
2074 | (uint32_t __user *)(unsigned long)(out_resp->props_ptr), |
2067 | (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr), |
2075 | (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr), |
2068 | &out_resp->count_props); |
2076 | &out_resp->count_props); |
2069 | if (ret) |
2077 | if (ret) |
2070 | goto out; |
2078 | goto out; |
2071 | 2079 | ||
2072 | if ((out_resp->count_encoders >= encoders_count) && encoders_count) { |
2080 | if ((out_resp->count_encoders >= encoders_count) && encoders_count) { |
2073 | copied = 0; |
2081 | copied = 0; |
2074 | encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr); |
2082 | encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr); |
2075 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
2083 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
2076 | if (connector->encoder_ids[i] != 0) { |
2084 | if (connector->encoder_ids[i] != 0) { |
2077 | if (put_user(connector->encoder_ids[i], |
2085 | if (put_user(connector->encoder_ids[i], |
2078 | encoder_ptr + copied)) { |
2086 | encoder_ptr + copied)) { |
2079 | ret = -EFAULT; |
2087 | ret = -EFAULT; |
2080 | goto out; |
2088 | goto out; |
2081 | } |
2089 | } |
2082 | copied++; |
2090 | copied++; |
2083 | } |
2091 | } |
2084 | } |
2092 | } |
2085 | } |
2093 | } |
2086 | out_resp->count_encoders = encoders_count; |
2094 | out_resp->count_encoders = encoders_count; |
2087 | 2095 | ||
2088 | out: |
2096 | out: |
2089 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
2097 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
2090 | 2098 | ||
2091 | out_unlock: |
2099 | out_unlock: |
2092 | mutex_unlock(&dev->mode_config.mutex); |
2100 | mutex_unlock(&dev->mode_config.mutex); |
2093 | 2101 | ||
2094 | return ret; |
2102 | return ret; |
2095 | } |
2103 | } |
2096 | 2104 | ||
2097 | static struct drm_crtc *drm_encoder_get_crtc(struct drm_encoder *encoder) |
2105 | static struct drm_crtc *drm_encoder_get_crtc(struct drm_encoder *encoder) |
2098 | { |
2106 | { |
2099 | struct drm_connector *connector; |
2107 | struct drm_connector *connector; |
2100 | struct drm_device *dev = encoder->dev; |
2108 | struct drm_device *dev = encoder->dev; |
2101 | bool uses_atomic = false; |
2109 | bool uses_atomic = false; |
2102 | 2110 | ||
2103 | /* For atomic drivers only state objects are synchronously updated and |
2111 | /* For atomic drivers only state objects are synchronously updated and |
2104 | * protected by modeset locks, so check those first. */ |
2112 | * protected by modeset locks, so check those first. */ |
2105 | drm_for_each_connector(connector, dev) { |
2113 | drm_for_each_connector(connector, dev) { |
2106 | if (!connector->state) |
2114 | if (!connector->state) |
2107 | continue; |
2115 | continue; |
2108 | 2116 | ||
2109 | uses_atomic = true; |
2117 | uses_atomic = true; |
2110 | 2118 | ||
2111 | if (connector->state->best_encoder != encoder) |
2119 | if (connector->state->best_encoder != encoder) |
2112 | continue; |
2120 | continue; |
2113 | 2121 | ||
2114 | return connector->state->crtc; |
2122 | return connector->state->crtc; |
2115 | } |
2123 | } |
2116 | 2124 | ||
2117 | /* Don't return stale data (e.g. pending async disable). */ |
2125 | /* Don't return stale data (e.g. pending async disable). */ |
2118 | if (uses_atomic) |
2126 | if (uses_atomic) |
2119 | return NULL; |
2127 | return NULL; |
2120 | 2128 | ||
2121 | return encoder->crtc; |
2129 | return encoder->crtc; |
2122 | } |
2130 | } |
2123 | 2131 | ||
2124 | /** |
2132 | /** |
2125 | * drm_mode_getencoder - get encoder configuration |
2133 | * drm_mode_getencoder - get encoder configuration |
2126 | * @dev: drm device for the ioctl |
2134 | * @dev: drm device for the ioctl |
2127 | * @data: data pointer for the ioctl |
2135 | * @data: data pointer for the ioctl |
2128 | * @file_priv: drm file for the ioctl call |
2136 | * @file_priv: drm file for the ioctl call |
2129 | * |
2137 | * |
2130 | * Construct a encoder configuration structure to return to the user. |
2138 | * Construct a encoder configuration structure to return to the user. |
2131 | * |
2139 | * |
2132 | * Called by the user via ioctl. |
2140 | * Called by the user via ioctl. |
2133 | * |
2141 | * |
2134 | * Returns: |
2142 | * Returns: |
2135 | * Zero on success, negative errno on failure. |
2143 | * Zero on success, negative errno on failure. |
2136 | */ |
2144 | */ |
2137 | int drm_mode_getencoder(struct drm_device *dev, void *data, |
2145 | int drm_mode_getencoder(struct drm_device *dev, void *data, |
2138 | struct drm_file *file_priv) |
2146 | struct drm_file *file_priv) |
2139 | { |
2147 | { |
2140 | struct drm_mode_get_encoder *enc_resp = data; |
2148 | struct drm_mode_get_encoder *enc_resp = data; |
2141 | struct drm_encoder *encoder; |
2149 | struct drm_encoder *encoder; |
2142 | struct drm_crtc *crtc; |
2150 | struct drm_crtc *crtc; |
2143 | 2151 | ||
2144 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
2152 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
2145 | return -EINVAL; |
2153 | return -EINVAL; |
2146 | 2154 | ||
2147 | encoder = drm_encoder_find(dev, enc_resp->encoder_id); |
2155 | encoder = drm_encoder_find(dev, enc_resp->encoder_id); |
2148 | if (!encoder) |
2156 | if (!encoder) |
2149 | return -ENOENT; |
2157 | return -ENOENT; |
2150 | 2158 | ||
2151 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
2159 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
2152 | crtc = drm_encoder_get_crtc(encoder); |
2160 | crtc = drm_encoder_get_crtc(encoder); |
2153 | if (crtc) |
2161 | if (crtc) |
2154 | enc_resp->crtc_id = crtc->base.id; |
2162 | enc_resp->crtc_id = crtc->base.id; |
2155 | else |
2163 | else |
2156 | enc_resp->crtc_id = 0; |
2164 | enc_resp->crtc_id = 0; |
2157 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
2165 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
2158 | 2166 | ||
2159 | enc_resp->encoder_type = encoder->encoder_type; |
2167 | enc_resp->encoder_type = encoder->encoder_type; |
2160 | enc_resp->encoder_id = encoder->base.id; |
2168 | enc_resp->encoder_id = encoder->base.id; |
2161 | enc_resp->possible_crtcs = encoder->possible_crtcs; |
2169 | enc_resp->possible_crtcs = encoder->possible_crtcs; |
2162 | enc_resp->possible_clones = encoder->possible_clones; |
2170 | enc_resp->possible_clones = encoder->possible_clones; |
2163 | 2171 | ||
2164 | return 0; |
2172 | return 0; |
2165 | } |
2173 | } |
2166 | 2174 | ||
2167 | /** |
2175 | /** |
2168 | * drm_mode_getplane_res - enumerate all plane resources |
2176 | * drm_mode_getplane_res - enumerate all plane resources |
2169 | * @dev: DRM device |
2177 | * @dev: DRM device |
2170 | * @data: ioctl data |
2178 | * @data: ioctl data |
2171 | * @file_priv: DRM file info |
2179 | * @file_priv: DRM file info |
2172 | * |
2180 | * |
2173 | * Construct a list of plane ids to return to the user. |
2181 | * Construct a list of plane ids to return to the user. |
2174 | * |
2182 | * |
2175 | * Called by the user via ioctl. |
2183 | * Called by the user via ioctl. |
2176 | * |
2184 | * |
2177 | * Returns: |
2185 | * Returns: |
2178 | * Zero on success, negative errno on failure. |
2186 | * Zero on success, negative errno on failure. |
2179 | */ |
2187 | */ |
2180 | int drm_mode_getplane_res(struct drm_device *dev, void *data, |
2188 | int drm_mode_getplane_res(struct drm_device *dev, void *data, |
2181 | struct drm_file *file_priv) |
2189 | struct drm_file *file_priv) |
2182 | { |
2190 | { |
2183 | struct drm_mode_get_plane_res *plane_resp = data; |
2191 | struct drm_mode_get_plane_res *plane_resp = data; |
2184 | struct drm_mode_config *config; |
2192 | struct drm_mode_config *config; |
2185 | struct drm_plane *plane; |
2193 | struct drm_plane *plane; |
2186 | uint32_t __user *plane_ptr; |
2194 | uint32_t __user *plane_ptr; |
2187 | int copied = 0; |
2195 | int copied = 0; |
2188 | unsigned num_planes; |
2196 | unsigned num_planes; |
2189 | 2197 | ||
2190 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
2198 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
2191 | return -EINVAL; |
2199 | return -EINVAL; |
2192 | 2200 | ||
2193 | config = &dev->mode_config; |
2201 | config = &dev->mode_config; |
2194 | 2202 | ||
2195 | if (file_priv->universal_planes) |
2203 | if (file_priv->universal_planes) |
2196 | num_planes = config->num_total_plane; |
2204 | num_planes = config->num_total_plane; |
2197 | else |
2205 | else |
2198 | num_planes = config->num_overlay_plane; |
2206 | num_planes = config->num_overlay_plane; |
2199 | 2207 | ||
2200 | /* |
2208 | /* |
2201 | * This ioctl is called twice, once to determine how much space is |
2209 | * This ioctl is called twice, once to determine how much space is |
2202 | * needed, and the 2nd time to fill it. |
2210 | * needed, and the 2nd time to fill it. |
2203 | */ |
2211 | */ |
2204 | if (num_planes && |
2212 | if (num_planes && |
2205 | (plane_resp->count_planes >= num_planes)) { |
2213 | (plane_resp->count_planes >= num_planes)) { |
2206 | plane_ptr = (uint32_t __user *)(unsigned long)plane_resp->plane_id_ptr; |
2214 | plane_ptr = (uint32_t __user *)(unsigned long)plane_resp->plane_id_ptr; |
2207 | 2215 | ||
2208 | /* Plane lists are invariant, no locking needed. */ |
2216 | /* Plane lists are invariant, no locking needed. */ |
2209 | drm_for_each_plane(plane, dev) { |
2217 | drm_for_each_plane(plane, dev) { |
2210 | /* |
2218 | /* |
2211 | * Unless userspace set the 'universal planes' |
2219 | * Unless userspace set the 'universal planes' |
2212 | * capability bit, only advertise overlays. |
2220 | * capability bit, only advertise overlays. |
2213 | */ |
2221 | */ |
2214 | if (plane->type != DRM_PLANE_TYPE_OVERLAY && |
2222 | if (plane->type != DRM_PLANE_TYPE_OVERLAY && |
2215 | !file_priv->universal_planes) |
2223 | !file_priv->universal_planes) |
2216 | continue; |
2224 | continue; |
2217 | 2225 | ||
2218 | if (put_user(plane->base.id, plane_ptr + copied)) |
2226 | if (put_user(plane->base.id, plane_ptr + copied)) |
2219 | return -EFAULT; |
2227 | return -EFAULT; |
2220 | copied++; |
2228 | copied++; |
2221 | } |
2229 | } |
2222 | } |
2230 | } |
2223 | plane_resp->count_planes = num_planes; |
2231 | plane_resp->count_planes = num_planes; |
2224 | 2232 | ||
2225 | return 0; |
2233 | return 0; |
2226 | } |
2234 | } |
2227 | 2235 | ||
2228 | /** |
2236 | /** |
2229 | * drm_mode_getplane - get plane configuration |
2237 | * drm_mode_getplane - get plane configuration |
2230 | * @dev: DRM device |
2238 | * @dev: DRM device |
2231 | * @data: ioctl data |
2239 | * @data: ioctl data |
2232 | * @file_priv: DRM file info |
2240 | * @file_priv: DRM file info |
2233 | * |
2241 | * |
2234 | * Construct a plane configuration structure to return to the user. |
2242 | * Construct a plane configuration structure to return to the user. |
2235 | * |
2243 | * |
2236 | * Called by the user via ioctl. |
2244 | * Called by the user via ioctl. |
2237 | * |
2245 | * |
2238 | * Returns: |
2246 | * Returns: |
2239 | * Zero on success, negative errno on failure. |
2247 | * Zero on success, negative errno on failure. |
2240 | */ |
2248 | */ |
2241 | int drm_mode_getplane(struct drm_device *dev, void *data, |
2249 | int drm_mode_getplane(struct drm_device *dev, void *data, |
2242 | struct drm_file *file_priv) |
2250 | struct drm_file *file_priv) |
2243 | { |
2251 | { |
2244 | struct drm_mode_get_plane *plane_resp = data; |
2252 | struct drm_mode_get_plane *plane_resp = data; |
2245 | struct drm_plane *plane; |
2253 | struct drm_plane *plane; |
2246 | uint32_t __user *format_ptr; |
2254 | uint32_t __user *format_ptr; |
2247 | 2255 | ||
2248 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
2256 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
2249 | return -EINVAL; |
2257 | return -EINVAL; |
2250 | 2258 | ||
2251 | plane = drm_plane_find(dev, plane_resp->plane_id); |
2259 | plane = drm_plane_find(dev, plane_resp->plane_id); |
2252 | if (!plane) |
2260 | if (!plane) |
2253 | return -ENOENT; |
2261 | return -ENOENT; |
2254 | 2262 | ||
2255 | drm_modeset_lock(&plane->mutex, NULL); |
2263 | drm_modeset_lock(&plane->mutex, NULL); |
2256 | if (plane->crtc) |
2264 | if (plane->crtc) |
2257 | plane_resp->crtc_id = plane->crtc->base.id; |
2265 | plane_resp->crtc_id = plane->crtc->base.id; |
2258 | else |
2266 | else |
2259 | plane_resp->crtc_id = 0; |
2267 | plane_resp->crtc_id = 0; |
2260 | 2268 | ||
2261 | if (plane->fb) |
2269 | if (plane->fb) |
2262 | plane_resp->fb_id = plane->fb->base.id; |
2270 | plane_resp->fb_id = plane->fb->base.id; |
2263 | else |
2271 | else |
2264 | plane_resp->fb_id = 0; |
2272 | plane_resp->fb_id = 0; |
2265 | drm_modeset_unlock(&plane->mutex); |
2273 | drm_modeset_unlock(&plane->mutex); |
2266 | 2274 | ||
2267 | plane_resp->plane_id = plane->base.id; |
2275 | plane_resp->plane_id = plane->base.id; |
2268 | plane_resp->possible_crtcs = plane->possible_crtcs; |
2276 | plane_resp->possible_crtcs = plane->possible_crtcs; |
2269 | plane_resp->gamma_size = 0; |
2277 | plane_resp->gamma_size = 0; |
2270 | 2278 | ||
2271 | /* |
2279 | /* |
2272 | * This ioctl is called twice, once to determine how much space is |
2280 | * This ioctl is called twice, once to determine how much space is |
2273 | * needed, and the 2nd time to fill it. |
2281 | * needed, and the 2nd time to fill it. |
2274 | */ |
2282 | */ |
2275 | if (plane->format_count && |
2283 | if (plane->format_count && |
2276 | (plane_resp->count_format_types >= plane->format_count)) { |
2284 | (plane_resp->count_format_types >= plane->format_count)) { |
2277 | format_ptr = (uint32_t __user *)(unsigned long)plane_resp->format_type_ptr; |
2285 | format_ptr = (uint32_t __user *)(unsigned long)plane_resp->format_type_ptr; |
2278 | if (copy_to_user(format_ptr, |
2286 | if (copy_to_user(format_ptr, |
2279 | plane->format_types, |
2287 | plane->format_types, |
2280 | sizeof(uint32_t) * plane->format_count)) { |
2288 | sizeof(uint32_t) * plane->format_count)) { |
2281 | return -EFAULT; |
2289 | return -EFAULT; |
2282 | } |
2290 | } |
2283 | } |
2291 | } |
2284 | plane_resp->count_format_types = plane->format_count; |
2292 | plane_resp->count_format_types = plane->format_count; |
2285 | 2293 | ||
2286 | return 0; |
2294 | return 0; |
2287 | } |
2295 | } |
2288 | #endif |
2296 | #endif |
2289 | 2297 | ||
2290 | /** |
2298 | /** |
2291 | * drm_plane_check_pixel_format - Check if the plane supports the pixel format |
2299 | * drm_plane_check_pixel_format - Check if the plane supports the pixel format |
2292 | * @plane: plane to check for format support |
2300 | * @plane: plane to check for format support |
2293 | * @format: the pixel format |
2301 | * @format: the pixel format |
2294 | * |
2302 | * |
2295 | * Returns: |
2303 | * Returns: |
2296 | * Zero of @plane has @format in its list of supported pixel formats, -EINVAL |
2304 | * Zero of @plane has @format in its list of supported pixel formats, -EINVAL |
2297 | * otherwise. |
2305 | * otherwise. |
2298 | */ |
2306 | */ |
2299 | int drm_plane_check_pixel_format(const struct drm_plane *plane, u32 format) |
2307 | int drm_plane_check_pixel_format(const struct drm_plane *plane, u32 format) |
2300 | { |
2308 | { |
2301 | unsigned int i; |
2309 | unsigned int i; |
2302 | 2310 | ||
2303 | for (i = 0; i < plane->format_count; i++) { |
2311 | for (i = 0; i < plane->format_count; i++) { |
2304 | if (format == plane->format_types[i]) |
2312 | if (format == plane->format_types[i]) |
2305 | return 0; |
2313 | return 0; |
2306 | } |
2314 | } |
2307 | 2315 | ||
2308 | return -EINVAL; |
2316 | return -EINVAL; |
2309 | } |
2317 | } |
2310 | 2318 | ||
2311 | static int check_src_coords(uint32_t src_x, uint32_t src_y, |
2319 | static int check_src_coords(uint32_t src_x, uint32_t src_y, |
2312 | uint32_t src_w, uint32_t src_h, |
2320 | uint32_t src_w, uint32_t src_h, |
2313 | const struct drm_framebuffer *fb) |
2321 | const struct drm_framebuffer *fb) |
2314 | { |
2322 | { |
2315 | unsigned int fb_width, fb_height; |
2323 | unsigned int fb_width, fb_height; |
2316 | 2324 | ||
2317 | fb_width = fb->width << 16; |
2325 | fb_width = fb->width << 16; |
2318 | fb_height = fb->height << 16; |
2326 | fb_height = fb->height << 16; |
2319 | 2327 | ||
2320 | /* Make sure source coordinates are inside the fb. */ |
2328 | /* Make sure source coordinates are inside the fb. */ |
2321 | if (src_w > fb_width || |
2329 | if (src_w > fb_width || |
2322 | src_x > fb_width - src_w || |
2330 | src_x > fb_width - src_w || |
2323 | src_h > fb_height || |
2331 | src_h > fb_height || |
2324 | src_y > fb_height - src_h) { |
2332 | src_y > fb_height - src_h) { |
2325 | DRM_DEBUG_KMS("Invalid source coordinates " |
2333 | DRM_DEBUG_KMS("Invalid source coordinates " |
2326 | "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n", |
2334 | "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n", |
2327 | src_w >> 16, ((src_w & 0xffff) * 15625) >> 10, |
2335 | src_w >> 16, ((src_w & 0xffff) * 15625) >> 10, |
2328 | src_h >> 16, ((src_h & 0xffff) * 15625) >> 10, |
2336 | src_h >> 16, ((src_h & 0xffff) * 15625) >> 10, |
2329 | src_x >> 16, ((src_x & 0xffff) * 15625) >> 10, |
2337 | src_x >> 16, ((src_x & 0xffff) * 15625) >> 10, |
2330 | src_y >> 16, ((src_y & 0xffff) * 15625) >> 10); |
2338 | src_y >> 16, ((src_y & 0xffff) * 15625) >> 10); |
2331 | return -ENOSPC; |
2339 | return -ENOSPC; |
2332 | } |
2340 | } |
2333 | 2341 | ||
2334 | return 0; |
2342 | return 0; |
2335 | } |
2343 | } |
2336 | 2344 | ||
2337 | /* |
2345 | /* |
2338 | * setplane_internal - setplane handler for internal callers |
2346 | * setplane_internal - setplane handler for internal callers |
2339 | * |
2347 | * |
2340 | * Note that we assume an extra reference has already been taken on fb. If the |
2348 | * Note that we assume an extra reference has already been taken on fb. If the |
2341 | * update fails, this reference will be dropped before return; if it succeeds, |
2349 | * update fails, this reference will be dropped before return; if it succeeds, |
2342 | * the previous framebuffer (if any) will be unreferenced instead. |
2350 | * the previous framebuffer (if any) will be unreferenced instead. |
2343 | * |
2351 | * |
2344 | * src_{x,y,w,h} are provided in 16.16 fixed point format |
2352 | * src_{x,y,w,h} are provided in 16.16 fixed point format |
2345 | */ |
2353 | */ |
2346 | static int __setplane_internal(struct drm_plane *plane, |
2354 | static int __setplane_internal(struct drm_plane *plane, |
2347 | struct drm_crtc *crtc, |
2355 | struct drm_crtc *crtc, |
2348 | struct drm_framebuffer *fb, |
2356 | struct drm_framebuffer *fb, |
2349 | int32_t crtc_x, int32_t crtc_y, |
2357 | int32_t crtc_x, int32_t crtc_y, |
2350 | uint32_t crtc_w, uint32_t crtc_h, |
2358 | uint32_t crtc_w, uint32_t crtc_h, |
2351 | /* src_{x,y,w,h} values are 16.16 fixed point */ |
2359 | /* src_{x,y,w,h} values are 16.16 fixed point */ |
2352 | uint32_t src_x, uint32_t src_y, |
2360 | uint32_t src_x, uint32_t src_y, |
2353 | uint32_t src_w, uint32_t src_h) |
2361 | uint32_t src_w, uint32_t src_h) |
2354 | { |
2362 | { |
2355 | int ret = 0; |
2363 | int ret = 0; |
2356 | 2364 | ||
2357 | /* No fb means shut it down */ |
2365 | /* No fb means shut it down */ |
2358 | if (!fb) { |
2366 | if (!fb) { |
2359 | plane->old_fb = plane->fb; |
2367 | plane->old_fb = plane->fb; |
2360 | ret = plane->funcs->disable_plane(plane); |
2368 | ret = plane->funcs->disable_plane(plane); |
2361 | if (!ret) { |
2369 | if (!ret) { |
2362 | plane->crtc = NULL; |
2370 | plane->crtc = NULL; |
2363 | plane->fb = NULL; |
2371 | plane->fb = NULL; |
2364 | } else { |
2372 | } else { |
2365 | plane->old_fb = NULL; |
2373 | plane->old_fb = NULL; |
2366 | } |
2374 | } |
2367 | goto out; |
2375 | goto out; |
2368 | } |
2376 | } |
2369 | 2377 | ||
2370 | /* Check whether this plane is usable on this CRTC */ |
2378 | /* Check whether this plane is usable on this CRTC */ |
2371 | if (!(plane->possible_crtcs & drm_crtc_mask(crtc))) { |
2379 | if (!(plane->possible_crtcs & drm_crtc_mask(crtc))) { |
2372 | DRM_DEBUG_KMS("Invalid crtc for plane\n"); |
2380 | DRM_DEBUG_KMS("Invalid crtc for plane\n"); |
2373 | ret = -EINVAL; |
2381 | ret = -EINVAL; |
2374 | goto out; |
2382 | goto out; |
2375 | } |
2383 | } |
2376 | 2384 | ||
2377 | /* Check whether this plane supports the fb pixel format. */ |
2385 | /* Check whether this plane supports the fb pixel format. */ |
2378 | ret = drm_plane_check_pixel_format(plane, fb->pixel_format); |
2386 | ret = drm_plane_check_pixel_format(plane, fb->pixel_format); |
2379 | if (ret) { |
2387 | if (ret) { |
2380 | DRM_DEBUG_KMS("Invalid pixel format %s\n", |
2388 | DRM_DEBUG_KMS("Invalid pixel format %s\n", |
2381 | drm_get_format_name(fb->pixel_format)); |
2389 | drm_get_format_name(fb->pixel_format)); |
2382 | goto out; |
2390 | goto out; |
2383 | } |
2391 | } |
2384 | 2392 | ||
2385 | /* Give drivers some help against integer overflows */ |
2393 | /* Give drivers some help against integer overflows */ |
2386 | if (crtc_w > INT_MAX || |
2394 | if (crtc_w > INT_MAX || |
2387 | crtc_x > INT_MAX - (int32_t) crtc_w || |
2395 | crtc_x > INT_MAX - (int32_t) crtc_w || |
2388 | crtc_h > INT_MAX || |
2396 | crtc_h > INT_MAX || |
2389 | crtc_y > INT_MAX - (int32_t) crtc_h) { |
2397 | crtc_y > INT_MAX - (int32_t) crtc_h) { |
2390 | DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n", |
2398 | DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n", |
2391 | crtc_w, crtc_h, crtc_x, crtc_y); |
2399 | crtc_w, crtc_h, crtc_x, crtc_y); |
2392 | ret = -ERANGE; |
2400 | ret = -ERANGE; |
2393 | goto out; |
2401 | goto out; |
2394 | } |
2402 | } |
2395 | 2403 | ||
2396 | ret = check_src_coords(src_x, src_y, src_w, src_h, fb); |
2404 | ret = check_src_coords(src_x, src_y, src_w, src_h, fb); |
2397 | if (ret) |
2405 | if (ret) |
2398 | goto out; |
2406 | goto out; |
2399 | 2407 | ||
2400 | plane->old_fb = plane->fb; |
2408 | plane->old_fb = plane->fb; |
2401 | ret = plane->funcs->update_plane(plane, crtc, fb, |
2409 | ret = plane->funcs->update_plane(plane, crtc, fb, |
2402 | crtc_x, crtc_y, crtc_w, crtc_h, |
2410 | crtc_x, crtc_y, crtc_w, crtc_h, |
2403 | src_x, src_y, src_w, src_h); |
2411 | src_x, src_y, src_w, src_h); |
2404 | if (!ret) { |
2412 | if (!ret) { |
2405 | plane->crtc = crtc; |
2413 | plane->crtc = crtc; |
2406 | plane->fb = fb; |
2414 | plane->fb = fb; |
2407 | fb = NULL; |
2415 | fb = NULL; |
2408 | } else { |
2416 | } else { |
2409 | plane->old_fb = NULL; |
2417 | plane->old_fb = NULL; |
2410 | } |
2418 | } |
2411 | 2419 | ||
2412 | out: |
2420 | out: |
2413 | if (fb) |
2421 | if (fb) |
2414 | drm_framebuffer_unreference(fb); |
2422 | drm_framebuffer_unreference(fb); |
2415 | if (plane->old_fb) |
2423 | if (plane->old_fb) |
2416 | drm_framebuffer_unreference(plane->old_fb); |
2424 | drm_framebuffer_unreference(plane->old_fb); |
2417 | plane->old_fb = NULL; |
2425 | plane->old_fb = NULL; |
2418 | 2426 | ||
2419 | return ret; |
2427 | return ret; |
2420 | } |
2428 | } |
2421 | 2429 | ||
2422 | static int setplane_internal(struct drm_plane *plane, |
2430 | static int setplane_internal(struct drm_plane *plane, |
2423 | struct drm_crtc *crtc, |
2431 | struct drm_crtc *crtc, |
2424 | struct drm_framebuffer *fb, |
2432 | struct drm_framebuffer *fb, |
2425 | int32_t crtc_x, int32_t crtc_y, |
2433 | int32_t crtc_x, int32_t crtc_y, |
2426 | uint32_t crtc_w, uint32_t crtc_h, |
2434 | uint32_t crtc_w, uint32_t crtc_h, |
2427 | /* src_{x,y,w,h} values are 16.16 fixed point */ |
2435 | /* src_{x,y,w,h} values are 16.16 fixed point */ |
2428 | uint32_t src_x, uint32_t src_y, |
2436 | uint32_t src_x, uint32_t src_y, |
2429 | uint32_t src_w, uint32_t src_h) |
2437 | uint32_t src_w, uint32_t src_h) |
2430 | { |
2438 | { |
2431 | int ret; |
2439 | int ret; |
2432 | 2440 | ||
2433 | drm_modeset_lock_all(plane->dev); |
2441 | drm_modeset_lock_all(plane->dev); |
2434 | ret = __setplane_internal(plane, crtc, fb, |
2442 | ret = __setplane_internal(plane, crtc, fb, |
2435 | crtc_x, crtc_y, crtc_w, crtc_h, |
2443 | crtc_x, crtc_y, crtc_w, crtc_h, |
2436 | src_x, src_y, src_w, src_h); |
2444 | src_x, src_y, src_w, src_h); |
2437 | drm_modeset_unlock_all(plane->dev); |
2445 | drm_modeset_unlock_all(plane->dev); |
2438 | 2446 | ||
2439 | return ret; |
2447 | return ret; |
2440 | } |
2448 | } |
2441 | 2449 | ||
2442 | /** |
2450 | /** |
2443 | * drm_mode_setplane - configure a plane's configuration |
2451 | * drm_mode_setplane - configure a plane's configuration |
2444 | * @dev: DRM device |
2452 | * @dev: DRM device |
2445 | * @data: ioctl data* |
2453 | * @data: ioctl data* |
2446 | * @file_priv: DRM file info |
2454 | * @file_priv: DRM file info |
2447 | * |
2455 | * |
2448 | * Set plane configuration, including placement, fb, scaling, and other factors. |
2456 | * Set plane configuration, including placement, fb, scaling, and other factors. |
2449 | * Or pass a NULL fb to disable (planes may be disabled without providing a |
2457 | * Or pass a NULL fb to disable (planes may be disabled without providing a |
2450 | * valid crtc). |
2458 | * valid crtc). |
2451 | * |
2459 | * |
2452 | * Returns: |
2460 | * Returns: |
2453 | * Zero on success, negative errno on failure. |
2461 | * Zero on success, negative errno on failure. |
2454 | */ |
2462 | */ |
2455 | int drm_mode_setplane(struct drm_device *dev, void *data, |
2463 | int drm_mode_setplane(struct drm_device *dev, void *data, |
2456 | struct drm_file *file_priv) |
2464 | struct drm_file *file_priv) |
2457 | { |
2465 | { |
2458 | struct drm_mode_set_plane *plane_req = data; |
2466 | struct drm_mode_set_plane *plane_req = data; |
2459 | struct drm_plane *plane; |
2467 | struct drm_plane *plane; |
2460 | struct drm_crtc *crtc = NULL; |
2468 | struct drm_crtc *crtc = NULL; |
2461 | struct drm_framebuffer *fb = NULL; |
2469 | struct drm_framebuffer *fb = NULL; |
2462 | 2470 | ||
2463 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
2471 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
2464 | return -EINVAL; |
2472 | return -EINVAL; |
2465 | 2473 | ||
2466 | /* |
2474 | /* |
2467 | * First, find the plane, crtc, and fb objects. If not available, |
2475 | * First, find the plane, crtc, and fb objects. If not available, |
2468 | * we don't bother to call the driver. |
2476 | * we don't bother to call the driver. |
2469 | */ |
2477 | */ |
2470 | plane = drm_plane_find(dev, plane_req->plane_id); |
2478 | plane = drm_plane_find(dev, plane_req->plane_id); |
2471 | if (!plane) { |
2479 | if (!plane) { |
2472 | DRM_DEBUG_KMS("Unknown plane ID %d\n", |
2480 | DRM_DEBUG_KMS("Unknown plane ID %d\n", |
2473 | plane_req->plane_id); |
2481 | plane_req->plane_id); |
2474 | return -ENOENT; |
2482 | return -ENOENT; |
2475 | } |
2483 | } |
2476 | 2484 | ||
2477 | if (plane_req->fb_id) { |
2485 | if (plane_req->fb_id) { |
2478 | fb = drm_framebuffer_lookup(dev, plane_req->fb_id); |
2486 | fb = drm_framebuffer_lookup(dev, plane_req->fb_id); |
2479 | if (!fb) { |
2487 | if (!fb) { |
2480 | DRM_DEBUG_KMS("Unknown framebuffer ID %d\n", |
2488 | DRM_DEBUG_KMS("Unknown framebuffer ID %d\n", |
2481 | plane_req->fb_id); |
2489 | plane_req->fb_id); |
2482 | return -ENOENT; |
2490 | return -ENOENT; |
2483 | } |
2491 | } |
2484 | 2492 | ||
2485 | crtc = drm_crtc_find(dev, plane_req->crtc_id); |
2493 | crtc = drm_crtc_find(dev, plane_req->crtc_id); |
2486 | if (!crtc) { |
2494 | if (!crtc) { |
2487 | DRM_DEBUG_KMS("Unknown crtc ID %d\n", |
2495 | DRM_DEBUG_KMS("Unknown crtc ID %d\n", |
2488 | plane_req->crtc_id); |
2496 | plane_req->crtc_id); |
2489 | return -ENOENT; |
2497 | return -ENOENT; |
2490 | } |
2498 | } |
2491 | } |
2499 | } |
2492 | 2500 | ||
2493 | /* |
2501 | /* |
2494 | * setplane_internal will take care of deref'ing either the old or new |
2502 | * setplane_internal will take care of deref'ing either the old or new |
2495 | * framebuffer depending on success. |
2503 | * framebuffer depending on success. |
2496 | */ |
2504 | */ |
2497 | return setplane_internal(plane, crtc, fb, |
2505 | return setplane_internal(plane, crtc, fb, |
2498 | plane_req->crtc_x, plane_req->crtc_y, |
2506 | plane_req->crtc_x, plane_req->crtc_y, |
2499 | plane_req->crtc_w, plane_req->crtc_h, |
2507 | plane_req->crtc_w, plane_req->crtc_h, |
2500 | plane_req->src_x, plane_req->src_y, |
2508 | plane_req->src_x, plane_req->src_y, |
2501 | plane_req->src_w, plane_req->src_h); |
2509 | plane_req->src_w, plane_req->src_h); |
2502 | } |
2510 | } |
2503 | 2511 | ||
2504 | /** |
2512 | /** |
2505 | * drm_mode_set_config_internal - helper to call ->set_config |
2513 | * drm_mode_set_config_internal - helper to call ->set_config |
2506 | * @set: modeset config to set |
2514 | * @set: modeset config to set |
2507 | * |
2515 | * |
2508 | * This is a little helper to wrap internal calls to the ->set_config driver |
2516 | * This is a little helper to wrap internal calls to the ->set_config driver |
2509 | * interface. The only thing it adds is correct refcounting dance. |
2517 | * interface. The only thing it adds is correct refcounting dance. |
2510 | * |
2518 | * |
2511 | * Returns: |
2519 | * Returns: |
2512 | * Zero on success, negative errno on failure. |
2520 | * Zero on success, negative errno on failure. |
2513 | */ |
2521 | */ |
2514 | int drm_mode_set_config_internal(struct drm_mode_set *set) |
2522 | int drm_mode_set_config_internal(struct drm_mode_set *set) |
2515 | { |
2523 | { |
2516 | struct drm_crtc *crtc = set->crtc; |
2524 | struct drm_crtc *crtc = set->crtc; |
2517 | struct drm_framebuffer *fb; |
2525 | struct drm_framebuffer *fb; |
2518 | struct drm_crtc *tmp; |
2526 | struct drm_crtc *tmp; |
2519 | int ret; |
2527 | int ret; |
2520 | 2528 | ||
2521 | /* |
2529 | /* |
2522 | * NOTE: ->set_config can also disable other crtcs (if we steal all |
2530 | * NOTE: ->set_config can also disable other crtcs (if we steal all |
2523 | * connectors from it), hence we need to refcount the fbs across all |
2531 | * connectors from it), hence we need to refcount the fbs across all |
2524 | * crtcs. Atomic modeset will have saner semantics ... |
2532 | * crtcs. Atomic modeset will have saner semantics ... |
2525 | */ |
2533 | */ |
2526 | drm_for_each_crtc(tmp, crtc->dev) |
2534 | drm_for_each_crtc(tmp, crtc->dev) |
2527 | tmp->primary->old_fb = tmp->primary->fb; |
2535 | tmp->primary->old_fb = tmp->primary->fb; |
2528 | 2536 | ||
2529 | fb = set->fb; |
2537 | fb = set->fb; |
2530 | 2538 | ||
2531 | ret = crtc->funcs->set_config(set); |
2539 | ret = crtc->funcs->set_config(set); |
2532 | if (ret == 0) { |
2540 | if (ret == 0) { |
2533 | crtc->primary->crtc = crtc; |
2541 | crtc->primary->crtc = crtc; |
2534 | crtc->primary->fb = fb; |
2542 | crtc->primary->fb = fb; |
2535 | } |
2543 | } |
2536 | 2544 | ||
2537 | drm_for_each_crtc(tmp, crtc->dev) { |
2545 | drm_for_each_crtc(tmp, crtc->dev) { |
2538 | if (tmp->primary->fb) |
2546 | if (tmp->primary->fb) |
2539 | drm_framebuffer_reference(tmp->primary->fb); |
2547 | drm_framebuffer_reference(tmp->primary->fb); |
2540 | if (tmp->primary->old_fb) |
2548 | if (tmp->primary->old_fb) |
2541 | drm_framebuffer_unreference(tmp->primary->old_fb); |
2549 | drm_framebuffer_unreference(tmp->primary->old_fb); |
2542 | tmp->primary->old_fb = NULL; |
2550 | tmp->primary->old_fb = NULL; |
2543 | } |
2551 | } |
2544 | 2552 | ||
2545 | return ret; |
2553 | return ret; |
2546 | } |
2554 | } |
2547 | EXPORT_SYMBOL(drm_mode_set_config_internal); |
2555 | EXPORT_SYMBOL(drm_mode_set_config_internal); |
2548 | 2556 | ||
2549 | /** |
2557 | /** |
2550 | * drm_crtc_get_hv_timing - Fetches hdisplay/vdisplay for given mode |
2558 | * drm_crtc_get_hv_timing - Fetches hdisplay/vdisplay for given mode |
2551 | * @mode: mode to query |
2559 | * @mode: mode to query |
2552 | * @hdisplay: hdisplay value to fill in |
2560 | * @hdisplay: hdisplay value to fill in |
2553 | * @vdisplay: vdisplay value to fill in |
2561 | * @vdisplay: vdisplay value to fill in |
2554 | * |
2562 | * |
2555 | * The vdisplay value will be doubled if the specified mode is a stereo mode of |
2563 | * The vdisplay value will be doubled if the specified mode is a stereo mode of |
2556 | * the appropriate layout. |
2564 | * the appropriate layout. |
2557 | */ |
2565 | */ |
2558 | void drm_crtc_get_hv_timing(const struct drm_display_mode *mode, |
2566 | void drm_crtc_get_hv_timing(const struct drm_display_mode *mode, |
2559 | int *hdisplay, int *vdisplay) |
2567 | int *hdisplay, int *vdisplay) |
2560 | { |
2568 | { |
2561 | struct drm_display_mode adjusted; |
2569 | struct drm_display_mode adjusted; |
2562 | 2570 | ||
2563 | drm_mode_copy(&adjusted, mode); |
2571 | drm_mode_copy(&adjusted, mode); |
2564 | drm_mode_set_crtcinfo(&adjusted, CRTC_STEREO_DOUBLE_ONLY); |
2572 | drm_mode_set_crtcinfo(&adjusted, CRTC_STEREO_DOUBLE_ONLY); |
2565 | *hdisplay = adjusted.crtc_hdisplay; |
2573 | *hdisplay = adjusted.crtc_hdisplay; |
2566 | *vdisplay = adjusted.crtc_vdisplay; |
2574 | *vdisplay = adjusted.crtc_vdisplay; |
2567 | } |
2575 | } |
2568 | EXPORT_SYMBOL(drm_crtc_get_hv_timing); |
2576 | EXPORT_SYMBOL(drm_crtc_get_hv_timing); |
2569 | 2577 | ||
2570 | /** |
2578 | /** |
2571 | * drm_crtc_check_viewport - Checks that a framebuffer is big enough for the |
2579 | * drm_crtc_check_viewport - Checks that a framebuffer is big enough for the |
2572 | * CRTC viewport |
2580 | * CRTC viewport |
2573 | * @crtc: CRTC that framebuffer will be displayed on |
2581 | * @crtc: CRTC that framebuffer will be displayed on |
2574 | * @x: x panning |
2582 | * @x: x panning |
2575 | * @y: y panning |
2583 | * @y: y panning |
2576 | * @mode: mode that framebuffer will be displayed under |
2584 | * @mode: mode that framebuffer will be displayed under |
2577 | * @fb: framebuffer to check size of |
2585 | * @fb: framebuffer to check size of |
2578 | */ |
2586 | */ |
2579 | int drm_crtc_check_viewport(const struct drm_crtc *crtc, |
2587 | int drm_crtc_check_viewport(const struct drm_crtc *crtc, |
2580 | int x, int y, |
2588 | int x, int y, |
2581 | const struct drm_display_mode *mode, |
2589 | const struct drm_display_mode *mode, |
2582 | const struct drm_framebuffer *fb) |
2590 | const struct drm_framebuffer *fb) |
2583 | 2591 | ||
2584 | { |
2592 | { |
2585 | int hdisplay, vdisplay; |
2593 | int hdisplay, vdisplay; |
2586 | 2594 | ||
2587 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); |
2595 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); |
2588 | 2596 | ||
2589 | if (crtc->state && |
2597 | if (crtc->state && |
2590 | crtc->primary->state->rotation & (BIT(DRM_ROTATE_90) | |
2598 | crtc->primary->state->rotation & (BIT(DRM_ROTATE_90) | |
2591 | BIT(DRM_ROTATE_270))) |
2599 | BIT(DRM_ROTATE_270))) |
2592 | swap(hdisplay, vdisplay); |
2600 | swap(hdisplay, vdisplay); |
2593 | 2601 | ||
2594 | return check_src_coords(x << 16, y << 16, |
2602 | return check_src_coords(x << 16, y << 16, |
2595 | hdisplay << 16, vdisplay << 16, fb); |
2603 | hdisplay << 16, vdisplay << 16, fb); |
2596 | } |
2604 | } |
2597 | EXPORT_SYMBOL(drm_crtc_check_viewport); |
2605 | EXPORT_SYMBOL(drm_crtc_check_viewport); |
2598 | 2606 | ||
2599 | #if 0 |
2607 | #if 0 |
2600 | /** |
2608 | /** |
2601 | * drm_mode_setcrtc - set CRTC configuration |
2609 | * drm_mode_setcrtc - set CRTC configuration |
2602 | * @dev: drm device for the ioctl |
2610 | * @dev: drm device for the ioctl |
2603 | * @data: data pointer for the ioctl |
2611 | * @data: data pointer for the ioctl |
2604 | * @file_priv: drm file for the ioctl call |
2612 | * @file_priv: drm file for the ioctl call |
2605 | * |
2613 | * |
2606 | * Build a new CRTC configuration based on user request. |
2614 | * Build a new CRTC configuration based on user request. |
2607 | * |
2615 | * |
2608 | * Called by the user via ioctl. |
2616 | * Called by the user via ioctl. |
2609 | * |
2617 | * |
2610 | * Returns: |
2618 | * Returns: |
2611 | * Zero on success, negative errno on failure. |
2619 | * Zero on success, negative errno on failure. |
2612 | */ |
2620 | */ |
2613 | int drm_mode_setcrtc(struct drm_device *dev, void *data, |
2621 | int drm_mode_setcrtc(struct drm_device *dev, void *data, |
2614 | struct drm_file *file_priv) |
2622 | struct drm_file *file_priv) |
2615 | { |
2623 | { |
2616 | struct drm_mode_config *config = &dev->mode_config; |
2624 | struct drm_mode_config *config = &dev->mode_config; |
2617 | struct drm_mode_crtc *crtc_req = data; |
2625 | struct drm_mode_crtc *crtc_req = data; |
2618 | struct drm_crtc *crtc; |
2626 | struct drm_crtc *crtc; |
2619 | struct drm_connector **connector_set = NULL, *connector; |
2627 | struct drm_connector **connector_set = NULL, *connector; |
2620 | struct drm_framebuffer *fb = NULL; |
2628 | struct drm_framebuffer *fb = NULL; |
2621 | struct drm_display_mode *mode = NULL; |
2629 | struct drm_display_mode *mode = NULL; |
2622 | struct drm_mode_set set; |
2630 | struct drm_mode_set set; |
2623 | uint32_t __user *set_connectors_ptr; |
2631 | uint32_t __user *set_connectors_ptr; |
2624 | int ret; |
2632 | int ret; |
2625 | int i; |
2633 | int i; |
2626 | 2634 | ||
2627 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
2635 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
2628 | return -EINVAL; |
2636 | return -EINVAL; |
2629 | 2637 | ||
2630 | /* |
2638 | /* |
2631 | * Universal plane src offsets are only 16.16, prevent havoc for |
2639 | * Universal plane src offsets are only 16.16, prevent havoc for |
2632 | * drivers using universal plane code internally. |
2640 | * drivers using universal plane code internally. |
2633 | */ |
2641 | */ |
2634 | if (crtc_req->x & 0xffff0000 || crtc_req->y & 0xffff0000) |
2642 | if (crtc_req->x & 0xffff0000 || crtc_req->y & 0xffff0000) |
2635 | return -ERANGE; |
2643 | return -ERANGE; |
2636 | 2644 | ||
2637 | drm_modeset_lock_all(dev); |
2645 | drm_modeset_lock_all(dev); |
2638 | crtc = drm_crtc_find(dev, crtc_req->crtc_id); |
2646 | crtc = drm_crtc_find(dev, crtc_req->crtc_id); |
2639 | if (!crtc) { |
2647 | if (!crtc) { |
2640 | DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id); |
2648 | DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id); |
2641 | ret = -ENOENT; |
2649 | ret = -ENOENT; |
2642 | goto out; |
2650 | goto out; |
2643 | } |
2651 | } |
2644 | DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id); |
2652 | DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id); |
2645 | 2653 | ||
2646 | if (crtc_req->mode_valid) { |
2654 | if (crtc_req->mode_valid) { |
2647 | /* If we have a mode we need a framebuffer. */ |
2655 | /* If we have a mode we need a framebuffer. */ |
2648 | /* If we pass -1, set the mode with the currently bound fb */ |
2656 | /* If we pass -1, set the mode with the currently bound fb */ |
2649 | if (crtc_req->fb_id == -1) { |
2657 | if (crtc_req->fb_id == -1) { |
2650 | if (!crtc->primary->fb) { |
2658 | if (!crtc->primary->fb) { |
2651 | DRM_DEBUG_KMS("CRTC doesn't have current FB\n"); |
2659 | DRM_DEBUG_KMS("CRTC doesn't have current FB\n"); |
2652 | ret = -EINVAL; |
2660 | ret = -EINVAL; |
2653 | goto out; |
2661 | goto out; |
2654 | } |
2662 | } |
2655 | fb = crtc->primary->fb; |
2663 | fb = crtc->primary->fb; |
2656 | /* Make refcounting symmetric with the lookup path. */ |
2664 | /* Make refcounting symmetric with the lookup path. */ |
2657 | drm_framebuffer_reference(fb); |
2665 | drm_framebuffer_reference(fb); |
2658 | } else { |
2666 | } else { |
2659 | fb = drm_framebuffer_lookup(dev, crtc_req->fb_id); |
2667 | fb = drm_framebuffer_lookup(dev, crtc_req->fb_id); |
2660 | if (!fb) { |
2668 | if (!fb) { |
2661 | DRM_DEBUG_KMS("Unknown FB ID%d\n", |
2669 | DRM_DEBUG_KMS("Unknown FB ID%d\n", |
2662 | crtc_req->fb_id); |
2670 | crtc_req->fb_id); |
2663 | ret = -ENOENT; |
2671 | ret = -ENOENT; |
2664 | goto out; |
2672 | goto out; |
2665 | } |
2673 | } |
2666 | } |
2674 | } |
2667 | 2675 | ||
2668 | mode = drm_mode_create(dev); |
2676 | mode = drm_mode_create(dev); |
2669 | if (!mode) { |
2677 | if (!mode) { |
2670 | ret = -ENOMEM; |
2678 | ret = -ENOMEM; |
2671 | goto out; |
2679 | goto out; |
2672 | } |
2680 | } |
2673 | 2681 | ||
2674 | ret = drm_mode_convert_umode(mode, &crtc_req->mode); |
2682 | ret = drm_mode_convert_umode(mode, &crtc_req->mode); |
2675 | if (ret) { |
2683 | if (ret) { |
2676 | DRM_DEBUG_KMS("Invalid mode\n"); |
2684 | DRM_DEBUG_KMS("Invalid mode\n"); |
2677 | goto out; |
2685 | goto out; |
2678 | } |
2686 | } |
2679 | 2687 | ||
2680 | drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V); |
2688 | drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V); |
2681 | 2689 | ||
2682 | /* |
2690 | /* |
2683 | * Check whether the primary plane supports the fb pixel format. |
2691 | * Check whether the primary plane supports the fb pixel format. |
2684 | * Drivers not implementing the universal planes API use a |
2692 | * Drivers not implementing the universal planes API use a |
2685 | * default formats list provided by the DRM core which doesn't |
2693 | * default formats list provided by the DRM core which doesn't |
2686 | * match real hardware capabilities. Skip the check in that |
2694 | * match real hardware capabilities. Skip the check in that |
2687 | * case. |
2695 | * case. |
2688 | */ |
2696 | */ |
2689 | if (!crtc->primary->format_default) { |
2697 | if (!crtc->primary->format_default) { |
2690 | ret = drm_plane_check_pixel_format(crtc->primary, |
2698 | ret = drm_plane_check_pixel_format(crtc->primary, |
2691 | fb->pixel_format); |
2699 | fb->pixel_format); |
2692 | if (ret) { |
2700 | if (ret) { |
2693 | DRM_DEBUG_KMS("Invalid pixel format %s\n", |
2701 | DRM_DEBUG_KMS("Invalid pixel format %s\n", |
2694 | drm_get_format_name(fb->pixel_format)); |
2702 | drm_get_format_name(fb->pixel_format)); |
2695 | goto out; |
2703 | goto out; |
2696 | } |
2704 | } |
2697 | } |
2705 | } |
2698 | 2706 | ||
2699 | ret = drm_crtc_check_viewport(crtc, crtc_req->x, crtc_req->y, |
2707 | ret = drm_crtc_check_viewport(crtc, crtc_req->x, crtc_req->y, |
2700 | mode, fb); |
2708 | mode, fb); |
2701 | if (ret) |
2709 | if (ret) |
2702 | goto out; |
2710 | goto out; |
2703 | 2711 | ||
2704 | } |
2712 | } |
2705 | 2713 | ||
2706 | if (crtc_req->count_connectors == 0 && mode) { |
2714 | if (crtc_req->count_connectors == 0 && mode) { |
2707 | DRM_DEBUG_KMS("Count connectors is 0 but mode set\n"); |
2715 | DRM_DEBUG_KMS("Count connectors is 0 but mode set\n"); |
2708 | ret = -EINVAL; |
2716 | ret = -EINVAL; |
2709 | goto out; |
2717 | goto out; |
2710 | } |
2718 | } |
2711 | 2719 | ||
2712 | if (crtc_req->count_connectors > 0 && (!mode || !fb)) { |
2720 | if (crtc_req->count_connectors > 0 && (!mode || !fb)) { |
2713 | DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n", |
2721 | DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n", |
2714 | crtc_req->count_connectors); |
2722 | crtc_req->count_connectors); |
2715 | ret = -EINVAL; |
2723 | ret = -EINVAL; |
2716 | goto out; |
2724 | goto out; |
2717 | } |
2725 | } |
2718 | 2726 | ||
2719 | if (crtc_req->count_connectors > 0) { |
2727 | if (crtc_req->count_connectors > 0) { |
2720 | u32 out_id; |
2728 | u32 out_id; |
2721 | 2729 | ||
2722 | /* Avoid unbounded kernel memory allocation */ |
2730 | /* Avoid unbounded kernel memory allocation */ |
2723 | if (crtc_req->count_connectors > config->num_connector) { |
2731 | if (crtc_req->count_connectors > config->num_connector) { |
2724 | ret = -EINVAL; |
2732 | ret = -EINVAL; |
2725 | goto out; |
2733 | goto out; |
2726 | } |
2734 | } |
2727 | 2735 | ||
2728 | connector_set = kmalloc_array(crtc_req->count_connectors, |
2736 | connector_set = kmalloc_array(crtc_req->count_connectors, |
2729 | sizeof(struct drm_connector *), |
2737 | sizeof(struct drm_connector *), |
2730 | GFP_KERNEL); |
2738 | GFP_KERNEL); |
2731 | if (!connector_set) { |
2739 | if (!connector_set) { |
2732 | ret = -ENOMEM; |
2740 | ret = -ENOMEM; |
2733 | goto out; |
2741 | goto out; |
2734 | } |
2742 | } |
2735 | 2743 | ||
2736 | for (i = 0; i < crtc_req->count_connectors; i++) { |
2744 | for (i = 0; i < crtc_req->count_connectors; i++) { |
2737 | set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr; |
2745 | set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr; |
2738 | // if (get_user(out_id, &set_connectors_ptr[i])) { |
2746 | // if (get_user(out_id, &set_connectors_ptr[i])) { |
2739 | // ret = -EFAULT; |
2747 | // ret = -EFAULT; |
2740 | // goto out; |
2748 | // goto out; |
2741 | // } |
2749 | // } |
2742 | 2750 | ||
2743 | connector = drm_connector_find(dev, out_id); |
2751 | connector = drm_connector_find(dev, out_id); |
2744 | if (!connector) { |
2752 | if (!connector) { |
2745 | DRM_DEBUG_KMS("Connector id %d unknown\n", |
2753 | DRM_DEBUG_KMS("Connector id %d unknown\n", |
2746 | out_id); |
2754 | out_id); |
2747 | ret = -ENOENT; |
2755 | ret = -ENOENT; |
2748 | goto out; |
2756 | goto out; |
2749 | } |
2757 | } |
2750 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
2758 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
2751 | connector->base.id, |
2759 | connector->base.id, |
2752 | connector->name); |
2760 | connector->name); |
2753 | 2761 | ||
2754 | connector_set[i] = connector; |
2762 | connector_set[i] = connector; |
2755 | } |
2763 | } |
2756 | } |
2764 | } |
2757 | 2765 | ||
2758 | set.crtc = crtc; |
2766 | set.crtc = crtc; |
2759 | set.x = crtc_req->x; |
2767 | set.x = crtc_req->x; |
2760 | set.y = crtc_req->y; |
2768 | set.y = crtc_req->y; |
2761 | set.mode = mode; |
2769 | set.mode = mode; |
2762 | set.connectors = connector_set; |
2770 | set.connectors = connector_set; |
2763 | set.num_connectors = crtc_req->count_connectors; |
2771 | set.num_connectors = crtc_req->count_connectors; |
2764 | set.fb = fb; |
2772 | set.fb = fb; |
2765 | ret = drm_mode_set_config_internal(&set); |
2773 | ret = drm_mode_set_config_internal(&set); |
2766 | 2774 | ||
2767 | out: |
2775 | out: |
2768 | if (fb) |
2776 | if (fb) |
2769 | drm_framebuffer_unreference(fb); |
2777 | drm_framebuffer_unreference(fb); |
2770 | 2778 | ||
2771 | kfree(connector_set); |
2779 | kfree(connector_set); |
2772 | drm_mode_destroy(dev, mode); |
2780 | drm_mode_destroy(dev, mode); |
2773 | drm_modeset_unlock_all(dev); |
2781 | drm_modeset_unlock_all(dev); |
2774 | return ret; |
2782 | return ret; |
2775 | } |
2783 | } |
2776 | 2784 | ||
2777 | static int drm_mode_cursor_common(struct drm_device *dev, |
2785 | static int drm_mode_cursor_common(struct drm_device *dev, |
2778 | struct drm_mode_cursor2 *req, |
2786 | struct drm_mode_cursor2 *req, |
2779 | struct drm_file *file_priv) |
2787 | struct drm_file *file_priv) |
2780 | { |
2788 | { |
2781 | struct drm_crtc *crtc; |
2789 | struct drm_crtc *crtc; |
2782 | int ret = 0; |
2790 | int ret = 0; |
2783 | 2791 | ||
2784 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
2792 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
2785 | return -EINVAL; |
2793 | return -EINVAL; |
2786 | 2794 | ||
2787 | if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags)) |
2795 | if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags)) |
2788 | return -EINVAL; |
2796 | return -EINVAL; |
2789 | 2797 | ||
2790 | crtc = drm_crtc_find(dev, req->crtc_id); |
2798 | crtc = drm_crtc_find(dev, req->crtc_id); |
2791 | if (!crtc) { |
2799 | if (!crtc) { |
2792 | DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id); |
2800 | DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id); |
2793 | return -ENOENT; |
2801 | return -ENOENT; |
2794 | } |
2802 | } |
2795 | 2803 | ||
2796 | /* |
2804 | /* |
2797 | * If this crtc has a universal cursor plane, call that plane's update |
2805 | * If this crtc has a universal cursor plane, call that plane's update |
2798 | * handler rather than using legacy cursor handlers. |
2806 | * handler rather than using legacy cursor handlers. |
2799 | */ |
2807 | */ |
2800 | drm_modeset_lock_crtc(crtc, crtc->cursor); |
2808 | drm_modeset_lock_crtc(crtc, crtc->cursor); |
2801 | if (crtc->cursor) { |
2809 | if (crtc->cursor) { |
2802 | ret = drm_mode_cursor_universal(crtc, req, file_priv); |
2810 | ret = drm_mode_cursor_universal(crtc, req, file_priv); |
2803 | goto out; |
2811 | goto out; |
2804 | } |
2812 | } |
2805 | 2813 | ||
2806 | if (req->flags & DRM_MODE_CURSOR_BO) { |
2814 | if (req->flags & DRM_MODE_CURSOR_BO) { |
2807 | if (!crtc->funcs->cursor_set && !crtc->funcs->cursor_set2) { |
2815 | if (!crtc->funcs->cursor_set && !crtc->funcs->cursor_set2) { |
2808 | ret = -ENXIO; |
2816 | ret = -ENXIO; |
2809 | goto out; |
2817 | goto out; |
2810 | } |
2818 | } |
2811 | /* Turns off the cursor if handle is 0 */ |
2819 | /* Turns off the cursor if handle is 0 */ |
2812 | if (crtc->funcs->cursor_set2) |
2820 | if (crtc->funcs->cursor_set2) |
2813 | ret = crtc->funcs->cursor_set2(crtc, file_priv, req->handle, |
2821 | ret = crtc->funcs->cursor_set2(crtc, file_priv, req->handle, |
2814 | req->width, req->height, req->hot_x, req->hot_y); |
2822 | req->width, req->height, req->hot_x, req->hot_y); |
2815 | else |
2823 | else |
2816 | ret = crtc->funcs->cursor_set(crtc, file_priv, req->handle, |
2824 | ret = crtc->funcs->cursor_set(crtc, file_priv, req->handle, |
2817 | req->width, req->height); |
2825 | req->width, req->height); |
2818 | } |
2826 | } |
2819 | 2827 | ||
2820 | if (req->flags & DRM_MODE_CURSOR_MOVE) { |
2828 | if (req->flags & DRM_MODE_CURSOR_MOVE) { |
2821 | if (crtc->funcs->cursor_move) { |
2829 | if (crtc->funcs->cursor_move) { |
2822 | ret = crtc->funcs->cursor_move(crtc, req->x, req->y); |
2830 | ret = crtc->funcs->cursor_move(crtc, req->x, req->y); |
2823 | } else { |
2831 | } else { |
2824 | ret = -EFAULT; |
2832 | ret = -EFAULT; |
2825 | goto out; |
2833 | goto out; |
2826 | } |
2834 | } |
2827 | } |
2835 | } |
2828 | out: |
2836 | out: |
2829 | drm_modeset_unlock_crtc(crtc); |
2837 | drm_modeset_unlock_crtc(crtc); |
2830 | 2838 | ||
2831 | return ret; |
2839 | return ret; |
2832 | 2840 | ||
2833 | } |
2841 | } |
2834 | 2842 | ||
2835 | 2843 | ||
2836 | /** |
2844 | /** |
2837 | * drm_mode_cursor_ioctl - set CRTC's cursor configuration |
2845 | * drm_mode_cursor_ioctl - set CRTC's cursor configuration |
2838 | * @dev: drm device for the ioctl |
2846 | * @dev: drm device for the ioctl |
2839 | * @data: data pointer for the ioctl |
2847 | * @data: data pointer for the ioctl |
2840 | * @file_priv: drm file for the ioctl call |
2848 | * @file_priv: drm file for the ioctl call |
2841 | * |
2849 | * |
2842 | * Set the cursor configuration based on user request. |
2850 | * Set the cursor configuration based on user request. |
2843 | * |
2851 | * |
2844 | * Called by the user via ioctl. |
2852 | * Called by the user via ioctl. |
2845 | * |
2853 | * |
2846 | * Returns: |
2854 | * Returns: |
2847 | * Zero on success, negative errno on failure. |
2855 | * Zero on success, negative errno on failure. |
2848 | */ |
2856 | */ |
2849 | int drm_mode_cursor_ioctl(struct drm_device *dev, |
2857 | int drm_mode_cursor_ioctl(struct drm_device *dev, |
2850 | void *data, struct drm_file *file_priv) |
2858 | void *data, struct drm_file *file_priv) |
2851 | { |
2859 | { |
2852 | struct drm_mode_cursor *req = data; |
2860 | struct drm_mode_cursor *req = data; |
2853 | struct drm_mode_cursor2 new_req; |
2861 | struct drm_mode_cursor2 new_req; |
2854 | 2862 | ||
2855 | memcpy(&new_req, req, sizeof(struct drm_mode_cursor)); |
2863 | memcpy(&new_req, req, sizeof(struct drm_mode_cursor)); |
2856 | new_req.hot_x = new_req.hot_y = 0; |
2864 | new_req.hot_x = new_req.hot_y = 0; |
2857 | 2865 | ||
2858 | return drm_mode_cursor_common(dev, &new_req, file_priv); |
2866 | return drm_mode_cursor_common(dev, &new_req, file_priv); |
2859 | } |
2867 | } |
2860 | 2868 | ||
2861 | /** |
2869 | /** |
2862 | * drm_mode_cursor2_ioctl - set CRTC's cursor configuration |
2870 | * drm_mode_cursor2_ioctl - set CRTC's cursor configuration |
2863 | * @dev: drm device for the ioctl |
2871 | * @dev: drm device for the ioctl |
2864 | * @data: data pointer for the ioctl |
2872 | * @data: data pointer for the ioctl |
2865 | * @file_priv: drm file for the ioctl call |
2873 | * @file_priv: drm file for the ioctl call |
2866 | * |
2874 | * |
2867 | * Set the cursor configuration based on user request. This implements the 2nd |
2875 | * Set the cursor configuration based on user request. This implements the 2nd |
2868 | * version of the cursor ioctl, which allows userspace to additionally specify |
2876 | * version of the cursor ioctl, which allows userspace to additionally specify |
2869 | * the hotspot of the pointer. |
2877 | * the hotspot of the pointer. |
2870 | * |
2878 | * |
2871 | * Called by the user via ioctl. |
2879 | * Called by the user via ioctl. |
2872 | * |
2880 | * |
2873 | * Returns: |
2881 | * Returns: |
2874 | * Zero on success, negative errno on failure. |
2882 | * Zero on success, negative errno on failure. |
2875 | */ |
2883 | */ |
2876 | int drm_mode_cursor2_ioctl(struct drm_device *dev, |
2884 | int drm_mode_cursor2_ioctl(struct drm_device *dev, |
2877 | void *data, struct drm_file *file_priv) |
2885 | void *data, struct drm_file *file_priv) |
2878 | { |
2886 | { |
2879 | struct drm_mode_cursor2 *req = data; |
2887 | struct drm_mode_cursor2 *req = data; |
2880 | 2888 | ||
2881 | return drm_mode_cursor_common(dev, req, file_priv); |
2889 | return drm_mode_cursor_common(dev, req, file_priv); |
2882 | } |
2890 | } |
2883 | #endif |
2891 | #endif |
2884 | 2892 | ||
2885 | /** |
2893 | /** |
2886 | * drm_mode_legacy_fb_format - compute drm fourcc code from legacy description |
2894 | * drm_mode_legacy_fb_format - compute drm fourcc code from legacy description |
2887 | * @bpp: bits per pixels |
2895 | * @bpp: bits per pixels |
2888 | * @depth: bit depth per pixel |
2896 | * @depth: bit depth per pixel |
2889 | * |
2897 | * |
2890 | * Computes a drm fourcc pixel format code for the given @bpp/@depth values. |
2898 | * Computes a drm fourcc pixel format code for the given @bpp/@depth values. |
2891 | * Useful in fbdev emulation code, since that deals in those values. |
2899 | * Useful in fbdev emulation code, since that deals in those values. |
2892 | */ |
2900 | */ |
2893 | uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth) |
2901 | uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth) |
2894 | { |
2902 | { |
2895 | uint32_t fmt; |
2903 | uint32_t fmt; |
2896 | 2904 | ||
2897 | switch (bpp) { |
2905 | switch (bpp) { |
2898 | case 8: |
2906 | case 8: |
2899 | fmt = DRM_FORMAT_C8; |
2907 | fmt = DRM_FORMAT_C8; |
2900 | break; |
2908 | break; |
2901 | case 16: |
2909 | case 16: |
2902 | if (depth == 15) |
2910 | if (depth == 15) |
2903 | fmt = DRM_FORMAT_XRGB1555; |
2911 | fmt = DRM_FORMAT_XRGB1555; |
2904 | else |
2912 | else |
2905 | fmt = DRM_FORMAT_RGB565; |
2913 | fmt = DRM_FORMAT_RGB565; |
2906 | break; |
2914 | break; |
2907 | case 24: |
2915 | case 24: |
2908 | fmt = DRM_FORMAT_RGB888; |
2916 | fmt = DRM_FORMAT_RGB888; |
2909 | break; |
2917 | break; |
2910 | case 32: |
2918 | case 32: |
2911 | if (depth == 24) |
2919 | if (depth == 24) |
2912 | fmt = DRM_FORMAT_XRGB8888; |
2920 | fmt = DRM_FORMAT_XRGB8888; |
2913 | else if (depth == 30) |
2921 | else if (depth == 30) |
2914 | fmt = DRM_FORMAT_XRGB2101010; |
2922 | fmt = DRM_FORMAT_XRGB2101010; |
2915 | else |
2923 | else |
2916 | fmt = DRM_FORMAT_ARGB8888; |
2924 | fmt = DRM_FORMAT_ARGB8888; |
2917 | break; |
2925 | break; |
2918 | default: |
2926 | default: |
2919 | DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n"); |
2927 | DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n"); |
2920 | fmt = DRM_FORMAT_XRGB8888; |
2928 | fmt = DRM_FORMAT_XRGB8888; |
2921 | break; |
2929 | break; |
2922 | } |
2930 | } |
2923 | 2931 | ||
2924 | return fmt; |
2932 | return fmt; |
2925 | } |
2933 | } |
2926 | EXPORT_SYMBOL(drm_mode_legacy_fb_format); |
2934 | EXPORT_SYMBOL(drm_mode_legacy_fb_format); |
2927 | #if 0 |
2935 | #if 0 |
2928 | /** |
2936 | /** |
2929 | * drm_mode_addfb - add an FB to the graphics configuration |
2937 | * drm_mode_addfb - add an FB to the graphics configuration |
2930 | * @dev: drm device for the ioctl |
2938 | * @dev: drm device for the ioctl |
2931 | * @data: data pointer for the ioctl |
2939 | * @data: data pointer for the ioctl |
2932 | * @file_priv: drm file for the ioctl call |
2940 | * @file_priv: drm file for the ioctl call |
2933 | * |
2941 | * |
2934 | * Add a new FB to the specified CRTC, given a user request. This is the |
2942 | * Add a new FB to the specified CRTC, given a user request. This is the |
2935 | * original addfb ioctl which only supported RGB formats. |
2943 | * original addfb ioctl which only supported RGB formats. |
2936 | * |
2944 | * |
2937 | * Called by the user via ioctl. |
2945 | * Called by the user via ioctl. |
2938 | * |
2946 | * |
2939 | * Returns: |
2947 | * Returns: |
2940 | * Zero on success, negative errno on failure. |
2948 | * Zero on success, negative errno on failure. |
2941 | */ |
2949 | */ |
2942 | int drm_mode_addfb(struct drm_device *dev, |
2950 | int drm_mode_addfb(struct drm_device *dev, |
2943 | void *data, struct drm_file *file_priv) |
2951 | void *data, struct drm_file *file_priv) |
2944 | { |
2952 | { |
2945 | struct drm_mode_fb_cmd *or = data; |
2953 | struct drm_mode_fb_cmd *or = data; |
2946 | struct drm_mode_fb_cmd2 r = {}; |
2954 | struct drm_mode_fb_cmd2 r = {}; |
2947 | int ret; |
2955 | int ret; |
2948 | 2956 | ||
2949 | /* convert to new format and call new ioctl */ |
2957 | /* convert to new format and call new ioctl */ |
2950 | r.fb_id = or->fb_id; |
2958 | r.fb_id = or->fb_id; |
2951 | r.width = or->width; |
2959 | r.width = or->width; |
2952 | r.height = or->height; |
2960 | r.height = or->height; |
2953 | r.pitches[0] = or->pitch; |
2961 | r.pitches[0] = or->pitch; |
2954 | r.pixel_format = drm_mode_legacy_fb_format(or->bpp, or->depth); |
2962 | r.pixel_format = drm_mode_legacy_fb_format(or->bpp, or->depth); |
2955 | r.handles[0] = or->handle; |
2963 | r.handles[0] = or->handle; |
2956 | 2964 | ||
2957 | ret = drm_mode_addfb2(dev, &r, file_priv); |
2965 | ret = drm_mode_addfb2(dev, &r, file_priv); |
2958 | if (ret) |
2966 | if (ret) |
2959 | return ret; |
2967 | return ret; |
2960 | 2968 | ||
2961 | or->fb_id = r.fb_id; |
2969 | or->fb_id = r.fb_id; |
2962 | 2970 | ||
2963 | return 0; |
2971 | return 0; |
2964 | } |
2972 | } |
2965 | 2973 | ||
2966 | static int format_check(const struct drm_mode_fb_cmd2 *r) |
2974 | static int format_check(const struct drm_mode_fb_cmd2 *r) |
2967 | { |
2975 | { |
2968 | uint32_t format = r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN; |
2976 | uint32_t format = r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN; |
2969 | 2977 | ||
2970 | switch (format) { |
2978 | switch (format) { |
2971 | case DRM_FORMAT_C8: |
2979 | case DRM_FORMAT_C8: |
2972 | case DRM_FORMAT_RGB332: |
2980 | case DRM_FORMAT_RGB332: |
2973 | case DRM_FORMAT_BGR233: |
2981 | case DRM_FORMAT_BGR233: |
2974 | case DRM_FORMAT_XRGB4444: |
2982 | case DRM_FORMAT_XRGB4444: |
2975 | case DRM_FORMAT_XBGR4444: |
2983 | case DRM_FORMAT_XBGR4444: |
2976 | case DRM_FORMAT_RGBX4444: |
2984 | case DRM_FORMAT_RGBX4444: |
2977 | case DRM_FORMAT_BGRX4444: |
2985 | case DRM_FORMAT_BGRX4444: |
2978 | case DRM_FORMAT_ARGB4444: |
2986 | case DRM_FORMAT_ARGB4444: |
2979 | case DRM_FORMAT_ABGR4444: |
2987 | case DRM_FORMAT_ABGR4444: |
2980 | case DRM_FORMAT_RGBA4444: |
2988 | case DRM_FORMAT_RGBA4444: |
2981 | case DRM_FORMAT_BGRA4444: |
2989 | case DRM_FORMAT_BGRA4444: |
2982 | case DRM_FORMAT_XRGB1555: |
2990 | case DRM_FORMAT_XRGB1555: |
2983 | case DRM_FORMAT_XBGR1555: |
2991 | case DRM_FORMAT_XBGR1555: |
2984 | case DRM_FORMAT_RGBX5551: |
2992 | case DRM_FORMAT_RGBX5551: |
2985 | case DRM_FORMAT_BGRX5551: |
2993 | case DRM_FORMAT_BGRX5551: |
2986 | case DRM_FORMAT_ARGB1555: |
2994 | case DRM_FORMAT_ARGB1555: |
2987 | case DRM_FORMAT_ABGR1555: |
2995 | case DRM_FORMAT_ABGR1555: |
2988 | case DRM_FORMAT_RGBA5551: |
2996 | case DRM_FORMAT_RGBA5551: |
2989 | case DRM_FORMAT_BGRA5551: |
2997 | case DRM_FORMAT_BGRA5551: |
2990 | case DRM_FORMAT_RGB565: |
2998 | case DRM_FORMAT_RGB565: |
2991 | case DRM_FORMAT_BGR565: |
2999 | case DRM_FORMAT_BGR565: |
2992 | case DRM_FORMAT_RGB888: |
3000 | case DRM_FORMAT_RGB888: |
2993 | case DRM_FORMAT_BGR888: |
3001 | case DRM_FORMAT_BGR888: |
2994 | case DRM_FORMAT_XRGB8888: |
3002 | case DRM_FORMAT_XRGB8888: |
2995 | case DRM_FORMAT_XBGR8888: |
3003 | case DRM_FORMAT_XBGR8888: |
2996 | case DRM_FORMAT_RGBX8888: |
3004 | case DRM_FORMAT_RGBX8888: |
2997 | case DRM_FORMAT_BGRX8888: |
3005 | case DRM_FORMAT_BGRX8888: |
2998 | case DRM_FORMAT_ARGB8888: |
3006 | case DRM_FORMAT_ARGB8888: |
2999 | case DRM_FORMAT_ABGR8888: |
3007 | case DRM_FORMAT_ABGR8888: |
3000 | case DRM_FORMAT_RGBA8888: |
3008 | case DRM_FORMAT_RGBA8888: |
3001 | case DRM_FORMAT_BGRA8888: |
3009 | case DRM_FORMAT_BGRA8888: |
3002 | case DRM_FORMAT_XRGB2101010: |
3010 | case DRM_FORMAT_XRGB2101010: |
3003 | case DRM_FORMAT_XBGR2101010: |
3011 | case DRM_FORMAT_XBGR2101010: |
3004 | case DRM_FORMAT_RGBX1010102: |
3012 | case DRM_FORMAT_RGBX1010102: |
3005 | case DRM_FORMAT_BGRX1010102: |
3013 | case DRM_FORMAT_BGRX1010102: |
3006 | case DRM_FORMAT_ARGB2101010: |
3014 | case DRM_FORMAT_ARGB2101010: |
3007 | case DRM_FORMAT_ABGR2101010: |
3015 | case DRM_FORMAT_ABGR2101010: |
3008 | case DRM_FORMAT_RGBA1010102: |
3016 | case DRM_FORMAT_RGBA1010102: |
3009 | case DRM_FORMAT_BGRA1010102: |
3017 | case DRM_FORMAT_BGRA1010102: |
3010 | case DRM_FORMAT_YUYV: |
3018 | case DRM_FORMAT_YUYV: |
3011 | case DRM_FORMAT_YVYU: |
3019 | case DRM_FORMAT_YVYU: |
3012 | case DRM_FORMAT_UYVY: |
3020 | case DRM_FORMAT_UYVY: |
3013 | case DRM_FORMAT_VYUY: |
3021 | case DRM_FORMAT_VYUY: |
3014 | case DRM_FORMAT_AYUV: |
3022 | case DRM_FORMAT_AYUV: |
3015 | case DRM_FORMAT_NV12: |
3023 | case DRM_FORMAT_NV12: |
3016 | case DRM_FORMAT_NV21: |
3024 | case DRM_FORMAT_NV21: |
3017 | case DRM_FORMAT_NV16: |
3025 | case DRM_FORMAT_NV16: |
3018 | case DRM_FORMAT_NV61: |
3026 | case DRM_FORMAT_NV61: |
3019 | case DRM_FORMAT_NV24: |
3027 | case DRM_FORMAT_NV24: |
3020 | case DRM_FORMAT_NV42: |
3028 | case DRM_FORMAT_NV42: |
3021 | case DRM_FORMAT_YUV410: |
3029 | case DRM_FORMAT_YUV410: |
3022 | case DRM_FORMAT_YVU410: |
3030 | case DRM_FORMAT_YVU410: |
3023 | case DRM_FORMAT_YUV411: |
3031 | case DRM_FORMAT_YUV411: |
3024 | case DRM_FORMAT_YVU411: |
3032 | case DRM_FORMAT_YVU411: |
3025 | case DRM_FORMAT_YUV420: |
3033 | case DRM_FORMAT_YUV420: |
3026 | case DRM_FORMAT_YVU420: |
3034 | case DRM_FORMAT_YVU420: |
3027 | case DRM_FORMAT_YUV422: |
3035 | case DRM_FORMAT_YUV422: |
3028 | case DRM_FORMAT_YVU422: |
3036 | case DRM_FORMAT_YVU422: |
3029 | case DRM_FORMAT_YUV444: |
3037 | case DRM_FORMAT_YUV444: |
3030 | case DRM_FORMAT_YVU444: |
3038 | case DRM_FORMAT_YVU444: |
3031 | return 0; |
3039 | return 0; |
3032 | default: |
3040 | default: |
3033 | DRM_DEBUG_KMS("invalid pixel format %s\n", |
3041 | DRM_DEBUG_KMS("invalid pixel format %s\n", |
3034 | drm_get_format_name(r->pixel_format)); |
3042 | drm_get_format_name(r->pixel_format)); |
3035 | return -EINVAL; |
3043 | return -EINVAL; |
3036 | } |
3044 | } |
3037 | } |
3045 | } |
3038 | 3046 | ||
3039 | static int framebuffer_check(const struct drm_mode_fb_cmd2 *r) |
3047 | static int framebuffer_check(const struct drm_mode_fb_cmd2 *r) |
3040 | { |
3048 | { |
3041 | int ret, hsub, vsub, num_planes, i; |
3049 | int ret, hsub, vsub, num_planes, i; |
3042 | 3050 | ||
3043 | ret = format_check(r); |
3051 | ret = format_check(r); |
3044 | if (ret) { |
3052 | if (ret) { |
3045 | DRM_DEBUG_KMS("bad framebuffer format %s\n", |
3053 | DRM_DEBUG_KMS("bad framebuffer format %s\n", |
3046 | drm_get_format_name(r->pixel_format)); |
3054 | drm_get_format_name(r->pixel_format)); |
3047 | return ret; |
3055 | return ret; |
3048 | } |
3056 | } |
3049 | 3057 | ||
3050 | hsub = drm_format_horz_chroma_subsampling(r->pixel_format); |
3058 | hsub = drm_format_horz_chroma_subsampling(r->pixel_format); |
3051 | vsub = drm_format_vert_chroma_subsampling(r->pixel_format); |
3059 | vsub = drm_format_vert_chroma_subsampling(r->pixel_format); |
3052 | num_planes = drm_format_num_planes(r->pixel_format); |
3060 | num_planes = drm_format_num_planes(r->pixel_format); |
3053 | 3061 | ||
3054 | if (r->width == 0 || r->width % hsub) { |
3062 | if (r->width == 0 || r->width % hsub) { |
3055 | DRM_DEBUG_KMS("bad framebuffer width %u\n", r->width); |
3063 | DRM_DEBUG_KMS("bad framebuffer width %u\n", r->width); |
3056 | return -EINVAL; |
3064 | return -EINVAL; |
3057 | } |
3065 | } |
3058 | 3066 | ||
3059 | if (r->height == 0 || r->height % vsub) { |
3067 | if (r->height == 0 || r->height % vsub) { |
3060 | DRM_DEBUG_KMS("bad framebuffer height %u\n", r->height); |
3068 | DRM_DEBUG_KMS("bad framebuffer height %u\n", r->height); |
3061 | return -EINVAL; |
3069 | return -EINVAL; |
3062 | } |
3070 | } |
3063 | 3071 | ||
3064 | for (i = 0; i < num_planes; i++) { |
3072 | for (i = 0; i < num_planes; i++) { |
3065 | unsigned int width = r->width / (i != 0 ? hsub : 1); |
3073 | unsigned int width = r->width / (i != 0 ? hsub : 1); |
3066 | unsigned int height = r->height / (i != 0 ? vsub : 1); |
3074 | unsigned int height = r->height / (i != 0 ? vsub : 1); |
3067 | unsigned int cpp = drm_format_plane_cpp(r->pixel_format, i); |
3075 | unsigned int cpp = drm_format_plane_cpp(r->pixel_format, i); |
3068 | 3076 | ||
3069 | if (!r->handles[i]) { |
3077 | if (!r->handles[i]) { |
3070 | DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i); |
3078 | DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i); |
3071 | return -EINVAL; |
3079 | return -EINVAL; |
3072 | } |
3080 | } |
3073 | 3081 | ||
3074 | if ((uint64_t) width * cpp > UINT_MAX) |
3082 | if ((uint64_t) width * cpp > UINT_MAX) |
3075 | return -ERANGE; |
3083 | return -ERANGE; |
3076 | 3084 | ||
3077 | if ((uint64_t) height * r->pitches[i] + r->offsets[i] > UINT_MAX) |
3085 | if ((uint64_t) height * r->pitches[i] + r->offsets[i] > UINT_MAX) |
3078 | return -ERANGE; |
3086 | return -ERANGE; |
3079 | 3087 | ||
3080 | if (r->pitches[i] < width * cpp) { |
3088 | if (r->pitches[i] < width * cpp) { |
3081 | DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r->pitches[i], i); |
3089 | DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r->pitches[i], i); |
3082 | return -EINVAL; |
3090 | return -EINVAL; |
3083 | } |
3091 | } |
3084 | 3092 | ||
3085 | if (r->modifier[i] && !(r->flags & DRM_MODE_FB_MODIFIERS)) { |
3093 | if (r->modifier[i] && !(r->flags & DRM_MODE_FB_MODIFIERS)) { |
3086 | DRM_DEBUG_KMS("bad fb modifier %llu for plane %d\n", |
3094 | DRM_DEBUG_KMS("bad fb modifier %llu for plane %d\n", |
3087 | r->modifier[i], i); |
3095 | r->modifier[i], i); |
3088 | return -EINVAL; |
3096 | return -EINVAL; |
3089 | } |
3097 | } |
3090 | 3098 | ||
3091 | /* modifier specific checks: */ |
3099 | /* modifier specific checks: */ |
3092 | switch (r->modifier[i]) { |
3100 | switch (r->modifier[i]) { |
3093 | case DRM_FORMAT_MOD_SAMSUNG_64_32_TILE: |
3101 | case DRM_FORMAT_MOD_SAMSUNG_64_32_TILE: |
3094 | /* NOTE: the pitch restriction may be lifted later if it turns |
3102 | /* NOTE: the pitch restriction may be lifted later if it turns |
3095 | * out that no hw has this restriction: |
3103 | * out that no hw has this restriction: |
3096 | */ |
3104 | */ |
3097 | if (r->pixel_format != DRM_FORMAT_NV12 || |
3105 | if (r->pixel_format != DRM_FORMAT_NV12 || |
3098 | width % 128 || height % 32 || |
3106 | width % 128 || height % 32 || |
3099 | r->pitches[i] % 128) { |
3107 | r->pitches[i] % 128) { |
3100 | DRM_DEBUG_KMS("bad modifier data for plane %d\n", i); |
3108 | DRM_DEBUG_KMS("bad modifier data for plane %d\n", i); |
3101 | return -EINVAL; |
3109 | return -EINVAL; |
3102 | } |
3110 | } |
3103 | break; |
3111 | break; |
3104 | 3112 | ||
3105 | default: |
3113 | default: |
3106 | break; |
3114 | break; |
3107 | } |
3115 | } |
3108 | } |
3116 | } |
3109 | 3117 | ||
3110 | for (i = num_planes; i < 4; i++) { |
3118 | for (i = num_planes; i < 4; i++) { |
3111 | if (r->modifier[i]) { |
3119 | if (r->modifier[i]) { |
3112 | DRM_DEBUG_KMS("non-zero modifier for unused plane %d\n", i); |
3120 | DRM_DEBUG_KMS("non-zero modifier for unused plane %d\n", i); |
3113 | return -EINVAL; |
3121 | return -EINVAL; |
3114 | } |
3122 | } |
3115 | 3123 | ||
3116 | /* Pre-FB_MODIFIERS userspace didn't clear the structs properly. */ |
3124 | /* Pre-FB_MODIFIERS userspace didn't clear the structs properly. */ |
3117 | if (!(r->flags & DRM_MODE_FB_MODIFIERS)) |
3125 | if (!(r->flags & DRM_MODE_FB_MODIFIERS)) |
3118 | continue; |
3126 | continue; |
3119 | 3127 | ||
3120 | if (r->handles[i]) { |
3128 | if (r->handles[i]) { |
3121 | DRM_DEBUG_KMS("buffer object handle for unused plane %d\n", i); |
3129 | DRM_DEBUG_KMS("buffer object handle for unused plane %d\n", i); |
3122 | return -EINVAL; |
3130 | return -EINVAL; |
3123 | } |
3131 | } |
3124 | 3132 | ||
3125 | if (r->pitches[i]) { |
3133 | if (r->pitches[i]) { |
3126 | DRM_DEBUG_KMS("non-zero pitch for unused plane %d\n", i); |
3134 | DRM_DEBUG_KMS("non-zero pitch for unused plane %d\n", i); |
3127 | return -EINVAL; |
3135 | return -EINVAL; |
3128 | } |
3136 | } |
3129 | 3137 | ||
3130 | if (r->offsets[i]) { |
3138 | if (r->offsets[i]) { |
3131 | DRM_DEBUG_KMS("non-zero offset for unused plane %d\n", i); |
3139 | DRM_DEBUG_KMS("non-zero offset for unused plane %d\n", i); |
3132 | return -EINVAL; |
3140 | return -EINVAL; |
3133 | } |
3141 | } |
3134 | } |
3142 | } |
3135 | 3143 | ||
3136 | return 0; |
3144 | return 0; |
3137 | } |
3145 | } |
3138 | 3146 | ||
3139 | static struct drm_framebuffer * |
3147 | static struct drm_framebuffer * |
3140 | internal_framebuffer_create(struct drm_device *dev, |
3148 | internal_framebuffer_create(struct drm_device *dev, |
3141 | struct drm_mode_fb_cmd2 *r, |
3149 | struct drm_mode_fb_cmd2 *r, |
3142 | struct drm_file *file_priv) |
3150 | struct drm_file *file_priv) |
3143 | { |
3151 | { |
3144 | struct drm_mode_config *config = &dev->mode_config; |
3152 | struct drm_mode_config *config = &dev->mode_config; |
3145 | struct drm_framebuffer *fb; |
3153 | struct drm_framebuffer *fb; |
3146 | int ret; |
3154 | int ret; |
3147 | 3155 | ||
3148 | if (r->flags & ~(DRM_MODE_FB_INTERLACED | DRM_MODE_FB_MODIFIERS)) { |
3156 | if (r->flags & ~(DRM_MODE_FB_INTERLACED | DRM_MODE_FB_MODIFIERS)) { |
3149 | DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r->flags); |
3157 | DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r->flags); |
3150 | return ERR_PTR(-EINVAL); |
3158 | return ERR_PTR(-EINVAL); |
3151 | } |
3159 | } |
3152 | 3160 | ||
3153 | if ((config->min_width > r->width) || (r->width > config->max_width)) { |
3161 | if ((config->min_width > r->width) || (r->width > config->max_width)) { |
3154 | DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n", |
3162 | DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n", |
3155 | r->width, config->min_width, config->max_width); |
3163 | r->width, config->min_width, config->max_width); |
3156 | return ERR_PTR(-EINVAL); |
3164 | return ERR_PTR(-EINVAL); |
3157 | } |
3165 | } |
3158 | if ((config->min_height > r->height) || (r->height > config->max_height)) { |
3166 | if ((config->min_height > r->height) || (r->height > config->max_height)) { |
3159 | DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n", |
3167 | DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n", |
3160 | r->height, config->min_height, config->max_height); |
3168 | r->height, config->min_height, config->max_height); |
3161 | return ERR_PTR(-EINVAL); |
3169 | return ERR_PTR(-EINVAL); |
3162 | } |
3170 | } |
3163 | 3171 | ||
3164 | if (r->flags & DRM_MODE_FB_MODIFIERS && |
3172 | if (r->flags & DRM_MODE_FB_MODIFIERS && |
3165 | !dev->mode_config.allow_fb_modifiers) { |
3173 | !dev->mode_config.allow_fb_modifiers) { |
3166 | DRM_DEBUG_KMS("driver does not support fb modifiers\n"); |
3174 | DRM_DEBUG_KMS("driver does not support fb modifiers\n"); |
3167 | return ERR_PTR(-EINVAL); |
3175 | return ERR_PTR(-EINVAL); |
3168 | } |
3176 | } |
3169 | 3177 | ||
3170 | ret = framebuffer_check(r); |
3178 | ret = framebuffer_check(r); |
3171 | if (ret) |
3179 | if (ret) |
3172 | return ERR_PTR(ret); |
3180 | return ERR_PTR(ret); |
3173 | 3181 | ||
3174 | fb = dev->mode_config.funcs->fb_create(dev, file_priv, r); |
3182 | fb = dev->mode_config.funcs->fb_create(dev, file_priv, r); |
3175 | if (IS_ERR(fb)) { |
3183 | if (IS_ERR(fb)) { |
3176 | DRM_DEBUG_KMS("could not create framebuffer\n"); |
3184 | DRM_DEBUG_KMS("could not create framebuffer\n"); |
3177 | return fb; |
3185 | return fb; |
3178 | } |
3186 | } |
3179 | 3187 | ||
3180 | return fb; |
3188 | return fb; |
3181 | } |
3189 | } |
3182 | 3190 | ||
3183 | /** |
3191 | /** |
3184 | * drm_mode_addfb2 - add an FB to the graphics configuration |
3192 | * drm_mode_addfb2 - add an FB to the graphics configuration |
3185 | * @dev: drm device for the ioctl |
3193 | * @dev: drm device for the ioctl |
3186 | * @data: data pointer for the ioctl |
3194 | * @data: data pointer for the ioctl |
3187 | * @file_priv: drm file for the ioctl call |
3195 | * @file_priv: drm file for the ioctl call |
3188 | * |
3196 | * |
3189 | * Add a new FB to the specified CRTC, given a user request with format. This is |
3197 | * Add a new FB to the specified CRTC, given a user request with format. This is |
3190 | * the 2nd version of the addfb ioctl, which supports multi-planar framebuffers |
3198 | * the 2nd version of the addfb ioctl, which supports multi-planar framebuffers |
3191 | * and uses fourcc codes as pixel format specifiers. |
3199 | * and uses fourcc codes as pixel format specifiers. |
3192 | * |
3200 | * |
3193 | * Called by the user via ioctl. |
3201 | * Called by the user via ioctl. |
3194 | * |
3202 | * |
3195 | * Returns: |
3203 | * Returns: |
3196 | * Zero on success, negative errno on failure. |
3204 | * Zero on success, negative errno on failure. |
3197 | */ |
3205 | */ |
3198 | int drm_mode_addfb2(struct drm_device *dev, |
3206 | int drm_mode_addfb2(struct drm_device *dev, |
3199 | void *data, struct drm_file *file_priv) |
3207 | void *data, struct drm_file *file_priv) |
3200 | { |
3208 | { |
3201 | struct drm_mode_fb_cmd2 *r = data; |
3209 | struct drm_mode_fb_cmd2 *r = data; |
3202 | struct drm_framebuffer *fb; |
3210 | struct drm_framebuffer *fb; |
3203 | 3211 | ||
3204 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
3212 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
3205 | return -EINVAL; |
3213 | return -EINVAL; |
3206 | 3214 | ||
3207 | fb = internal_framebuffer_create(dev, r, file_priv); |
3215 | fb = internal_framebuffer_create(dev, r, file_priv); |
3208 | if (IS_ERR(fb)) |
3216 | if (IS_ERR(fb)) |
3209 | return PTR_ERR(fb); |
3217 | return PTR_ERR(fb); |
3210 | 3218 | ||
3211 | /* Transfer ownership to the filp for reaping on close */ |
3219 | /* Transfer ownership to the filp for reaping on close */ |
3212 | 3220 | ||
3213 | DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id); |
3221 | DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id); |
3214 | mutex_lock(&file_priv->fbs_lock); |
3222 | mutex_lock(&file_priv->fbs_lock); |
3215 | r->fb_id = fb->base.id; |
3223 | r->fb_id = fb->base.id; |
3216 | list_add(&fb->filp_head, &file_priv->fbs); |
3224 | list_add(&fb->filp_head, &file_priv->fbs); |
3217 | mutex_unlock(&file_priv->fbs_lock); |
3225 | mutex_unlock(&file_priv->fbs_lock); |
3218 | 3226 | ||
3219 | return 0; |
3227 | return 0; |
3220 | } |
3228 | } |
3221 | 3229 | ||
3222 | /** |
3230 | /** |
3223 | * drm_mode_rmfb - remove an FB from the configuration |
3231 | * drm_mode_rmfb - remove an FB from the configuration |
3224 | * @dev: drm device for the ioctl |
3232 | * @dev: drm device for the ioctl |
3225 | * @data: data pointer for the ioctl |
3233 | * @data: data pointer for the ioctl |
3226 | * @file_priv: drm file for the ioctl call |
3234 | * @file_priv: drm file for the ioctl call |
3227 | * |
3235 | * |
3228 | * Remove the FB specified by the user. |
3236 | * Remove the FB specified by the user. |
3229 | * |
3237 | * |
3230 | * Called by the user via ioctl. |
3238 | * Called by the user via ioctl. |
3231 | * |
3239 | * |
3232 | * Returns: |
3240 | * Returns: |
3233 | * Zero on success, negative errno on failure. |
3241 | * Zero on success, negative errno on failure. |
3234 | */ |
3242 | */ |
3235 | int drm_mode_rmfb(struct drm_device *dev, |
3243 | int drm_mode_rmfb(struct drm_device *dev, |
3236 | void *data, struct drm_file *file_priv) |
3244 | void *data, struct drm_file *file_priv) |
3237 | { |
3245 | { |
3238 | struct drm_framebuffer *fb = NULL; |
3246 | struct drm_framebuffer *fb = NULL; |
3239 | struct drm_framebuffer *fbl = NULL; |
3247 | struct drm_framebuffer *fbl = NULL; |
3240 | uint32_t *id = data; |
3248 | uint32_t *id = data; |
3241 | int found = 0; |
3249 | int found = 0; |
3242 | 3250 | ||
3243 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
3251 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
3244 | return -EINVAL; |
3252 | return -EINVAL; |
3245 | 3253 | ||
3246 | mutex_lock(&file_priv->fbs_lock); |
3254 | mutex_lock(&file_priv->fbs_lock); |
3247 | mutex_lock(&dev->mode_config.fb_lock); |
3255 | mutex_lock(&dev->mode_config.fb_lock); |
3248 | fb = __drm_framebuffer_lookup(dev, *id); |
3256 | fb = __drm_framebuffer_lookup(dev, *id); |
3249 | if (!fb) |
3257 | if (!fb) |
3250 | goto fail_lookup; |
3258 | goto fail_lookup; |
3251 | 3259 | ||
3252 | list_for_each_entry(fbl, &file_priv->fbs, filp_head) |
3260 | list_for_each_entry(fbl, &file_priv->fbs, filp_head) |
3253 | if (fb == fbl) |
3261 | if (fb == fbl) |
3254 | found = 1; |
3262 | found = 1; |
3255 | if (!found) |
3263 | if (!found) |
3256 | goto fail_lookup; |
3264 | goto fail_lookup; |
3257 | 3265 | ||
3258 | list_del_init(&fb->filp_head); |
3266 | list_del_init(&fb->filp_head); |
3259 | mutex_unlock(&dev->mode_config.fb_lock); |
3267 | mutex_unlock(&dev->mode_config.fb_lock); |
3260 | mutex_unlock(&file_priv->fbs_lock); |
3268 | mutex_unlock(&file_priv->fbs_lock); |
3261 | 3269 | ||
3262 | drm_framebuffer_unreference(fb); |
3270 | drm_framebuffer_unreference(fb); |
3263 | 3271 | ||
3264 | return 0; |
3272 | return 0; |
3265 | 3273 | ||
3266 | fail_lookup: |
3274 | fail_lookup: |
3267 | mutex_unlock(&dev->mode_config.fb_lock); |
3275 | mutex_unlock(&dev->mode_config.fb_lock); |
3268 | mutex_unlock(&file_priv->fbs_lock); |
3276 | mutex_unlock(&file_priv->fbs_lock); |
3269 | 3277 | ||
3270 | return -ENOENT; |
3278 | return -ENOENT; |
3271 | } |
3279 | } |
3272 | 3280 | ||
3273 | /** |
3281 | /** |
3274 | * drm_mode_getfb - get FB info |
3282 | * drm_mode_getfb - get FB info |
3275 | * @dev: drm device for the ioctl |
3283 | * @dev: drm device for the ioctl |
3276 | * @data: data pointer for the ioctl |
3284 | * @data: data pointer for the ioctl |
3277 | * @file_priv: drm file for the ioctl call |
3285 | * @file_priv: drm file for the ioctl call |
3278 | * |
3286 | * |
3279 | * Lookup the FB given its ID and return info about it. |
3287 | * Lookup the FB given its ID and return info about it. |
3280 | * |
3288 | * |
3281 | * Called by the user via ioctl. |
3289 | * Called by the user via ioctl. |
3282 | * |
3290 | * |
3283 | * Returns: |
3291 | * Returns: |
3284 | * Zero on success, negative errno on failure. |
3292 | * Zero on success, negative errno on failure. |
3285 | */ |
3293 | */ |
3286 | int drm_mode_getfb(struct drm_device *dev, |
3294 | int drm_mode_getfb(struct drm_device *dev, |
3287 | void *data, struct drm_file *file_priv) |
3295 | void *data, struct drm_file *file_priv) |
3288 | { |
3296 | { |
3289 | struct drm_mode_fb_cmd *r = data; |
3297 | struct drm_mode_fb_cmd *r = data; |
3290 | struct drm_framebuffer *fb; |
3298 | struct drm_framebuffer *fb; |
3291 | int ret; |
3299 | int ret; |
3292 | 3300 | ||
3293 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
3301 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
3294 | return -EINVAL; |
3302 | return -EINVAL; |
3295 | 3303 | ||
3296 | fb = drm_framebuffer_lookup(dev, r->fb_id); |
3304 | fb = drm_framebuffer_lookup(dev, r->fb_id); |
3297 | if (!fb) |
3305 | if (!fb) |
3298 | return -ENOENT; |
3306 | return -ENOENT; |
3299 | 3307 | ||
3300 | r->height = fb->height; |
3308 | r->height = fb->height; |
3301 | r->width = fb->width; |
3309 | r->width = fb->width; |
3302 | r->depth = fb->depth; |
3310 | r->depth = fb->depth; |
3303 | r->bpp = fb->bits_per_pixel; |
3311 | r->bpp = fb->bits_per_pixel; |
3304 | r->pitch = fb->pitches[0]; |
3312 | r->pitch = fb->pitches[0]; |
3305 | if (fb->funcs->create_handle) { |
3313 | if (fb->funcs->create_handle) { |
3306 | if (file_priv->is_master || capable(CAP_SYS_ADMIN) || |
3314 | if (file_priv->is_master || capable(CAP_SYS_ADMIN) || |
3307 | drm_is_control_client(file_priv)) { |
3315 | drm_is_control_client(file_priv)) { |
3308 | ret = fb->funcs->create_handle(fb, file_priv, |
3316 | ret = fb->funcs->create_handle(fb, file_priv, |
3309 | &r->handle); |
3317 | &r->handle); |
3310 | } else { |
3318 | } else { |
3311 | /* GET_FB() is an unprivileged ioctl so we must not |
3319 | /* GET_FB() is an unprivileged ioctl so we must not |
3312 | * return a buffer-handle to non-master processes! For |
3320 | * return a buffer-handle to non-master processes! For |
3313 | * backwards-compatibility reasons, we cannot make |
3321 | * backwards-compatibility reasons, we cannot make |
3314 | * GET_FB() privileged, so just return an invalid handle |
3322 | * GET_FB() privileged, so just return an invalid handle |
3315 | * for non-masters. */ |
3323 | * for non-masters. */ |
3316 | r->handle = 0; |
3324 | r->handle = 0; |
3317 | ret = 0; |
3325 | ret = 0; |
3318 | } |
3326 | } |
3319 | } else { |
3327 | } else { |
3320 | ret = -ENODEV; |
3328 | ret = -ENODEV; |
3321 | } |
3329 | } |
3322 | 3330 | ||
3323 | drm_framebuffer_unreference(fb); |
3331 | drm_framebuffer_unreference(fb); |
3324 | 3332 | ||
3325 | return ret; |
3333 | return ret; |
3326 | } |
3334 | } |
3327 | 3335 | ||
3328 | /** |
3336 | /** |
3329 | * drm_mode_dirtyfb_ioctl - flush frontbuffer rendering on an FB |
3337 | * drm_mode_dirtyfb_ioctl - flush frontbuffer rendering on an FB |
3330 | * @dev: drm device for the ioctl |
3338 | * @dev: drm device for the ioctl |
3331 | * @data: data pointer for the ioctl |
3339 | * @data: data pointer for the ioctl |
3332 | * @file_priv: drm file for the ioctl call |
3340 | * @file_priv: drm file for the ioctl call |
3333 | * |
3341 | * |
3334 | * Lookup the FB and flush out the damaged area supplied by userspace as a clip |
3342 | * Lookup the FB and flush out the damaged area supplied by userspace as a clip |
3335 | * rectangle list. Generic userspace which does frontbuffer rendering must call |
3343 | * rectangle list. Generic userspace which does frontbuffer rendering must call |
3336 | * this ioctl to flush out the changes on manual-update display outputs, e.g. |
3344 | * this ioctl to flush out the changes on manual-update display outputs, e.g. |
3337 | * usb display-link, mipi manual update panels or edp panel self refresh modes. |
3345 | * usb display-link, mipi manual update panels or edp panel self refresh modes. |
3338 | * |
3346 | * |
3339 | * Modesetting drivers which always update the frontbuffer do not need to |
3347 | * Modesetting drivers which always update the frontbuffer do not need to |
3340 | * implement the corresponding ->dirty framebuffer callback. |
3348 | * implement the corresponding ->dirty framebuffer callback. |
3341 | * |
3349 | * |
3342 | * Called by the user via ioctl. |
3350 | * Called by the user via ioctl. |
3343 | * |
3351 | * |
3344 | * Returns: |
3352 | * Returns: |
3345 | * Zero on success, negative errno on failure. |
3353 | * Zero on success, negative errno on failure. |
3346 | */ |
3354 | */ |
3347 | int drm_mode_dirtyfb_ioctl(struct drm_device *dev, |
3355 | int drm_mode_dirtyfb_ioctl(struct drm_device *dev, |
3348 | void *data, struct drm_file *file_priv) |
3356 | void *data, struct drm_file *file_priv) |
3349 | { |
3357 | { |
3350 | struct drm_clip_rect __user *clips_ptr; |
3358 | struct drm_clip_rect __user *clips_ptr; |
3351 | struct drm_clip_rect *clips = NULL; |
3359 | struct drm_clip_rect *clips = NULL; |
3352 | struct drm_mode_fb_dirty_cmd *r = data; |
3360 | struct drm_mode_fb_dirty_cmd *r = data; |
3353 | struct drm_framebuffer *fb; |
3361 | struct drm_framebuffer *fb; |
3354 | unsigned flags; |
3362 | unsigned flags; |
3355 | int num_clips; |
3363 | int num_clips; |
3356 | int ret; |
3364 | int ret; |
3357 | 3365 | ||
3358 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
3366 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
3359 | return -EINVAL; |
3367 | return -EINVAL; |
3360 | 3368 | ||
3361 | fb = drm_framebuffer_lookup(dev, r->fb_id); |
3369 | fb = drm_framebuffer_lookup(dev, r->fb_id); |
3362 | if (!fb) |
3370 | if (!fb) |
3363 | return -ENOENT; |
3371 | return -ENOENT; |
3364 | 3372 | ||
3365 | num_clips = r->num_clips; |
3373 | num_clips = r->num_clips; |
3366 | clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr; |
3374 | clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr; |
3367 | 3375 | ||
3368 | if (!num_clips != !clips_ptr) { |
3376 | if (!num_clips != !clips_ptr) { |
3369 | ret = -EINVAL; |
3377 | ret = -EINVAL; |
3370 | goto out_err1; |
3378 | goto out_err1; |
3371 | } |
3379 | } |
3372 | 3380 | ||
3373 | flags = DRM_MODE_FB_DIRTY_FLAGS & r->flags; |
3381 | flags = DRM_MODE_FB_DIRTY_FLAGS & r->flags; |
3374 | 3382 | ||
3375 | /* If userspace annotates copy, clips must come in pairs */ |
3383 | /* If userspace annotates copy, clips must come in pairs */ |
3376 | if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY && (num_clips % 2)) { |
3384 | if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY && (num_clips % 2)) { |
3377 | ret = -EINVAL; |
3385 | ret = -EINVAL; |
3378 | goto out_err1; |
3386 | goto out_err1; |
3379 | } |
3387 | } |
3380 | 3388 | ||
3381 | if (num_clips && clips_ptr) { |
3389 | if (num_clips && clips_ptr) { |
3382 | if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) { |
3390 | if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) { |
3383 | ret = -EINVAL; |
3391 | ret = -EINVAL; |
3384 | goto out_err1; |
3392 | goto out_err1; |
3385 | } |
3393 | } |
3386 | clips = kcalloc(num_clips, sizeof(*clips), GFP_KERNEL); |
3394 | clips = kcalloc(num_clips, sizeof(*clips), GFP_KERNEL); |
3387 | if (!clips) { |
3395 | if (!clips) { |
3388 | ret = -ENOMEM; |
3396 | ret = -ENOMEM; |
3389 | goto out_err1; |
3397 | goto out_err1; |
3390 | } |
3398 | } |
3391 | 3399 | ||
3392 | ret = copy_from_user(clips, clips_ptr, |
3400 | ret = copy_from_user(clips, clips_ptr, |
3393 | num_clips * sizeof(*clips)); |
3401 | num_clips * sizeof(*clips)); |
3394 | if (ret) { |
3402 | if (ret) { |
3395 | ret = -EFAULT; |
3403 | ret = -EFAULT; |
3396 | goto out_err2; |
3404 | goto out_err2; |
3397 | } |
3405 | } |
3398 | } |
3406 | } |
3399 | 3407 | ||
3400 | if (fb->funcs->dirty) { |
3408 | if (fb->funcs->dirty) { |
3401 | ret = fb->funcs->dirty(fb, file_priv, flags, r->color, |
3409 | ret = fb->funcs->dirty(fb, file_priv, flags, r->color, |
3402 | clips, num_clips); |
3410 | clips, num_clips); |
3403 | } else { |
3411 | } else { |
3404 | ret = -ENOSYS; |
3412 | ret = -ENOSYS; |
3405 | } |
3413 | } |
3406 | 3414 | ||
3407 | out_err2: |
3415 | out_err2: |
3408 | kfree(clips); |
3416 | kfree(clips); |
3409 | out_err1: |
3417 | out_err1: |
3410 | drm_framebuffer_unreference(fb); |
3418 | drm_framebuffer_unreference(fb); |
3411 | 3419 | ||
3412 | return ret; |
3420 | return ret; |
3413 | } |
3421 | } |
3414 | 3422 | ||
3415 | 3423 | ||
3416 | /** |
3424 | /** |
3417 | * drm_fb_release - remove and free the FBs on this file |
3425 | * drm_fb_release - remove and free the FBs on this file |
3418 | * @priv: drm file for the ioctl |
3426 | * @priv: drm file for the ioctl |
3419 | * |
3427 | * |
3420 | * Destroy all the FBs associated with @filp. |
3428 | * Destroy all the FBs associated with @filp. |
3421 | * |
3429 | * |
3422 | * Called by the user via ioctl. |
3430 | * Called by the user via ioctl. |
3423 | * |
3431 | * |
3424 | * Returns: |
3432 | * Returns: |
3425 | * Zero on success, negative errno on failure. |
3433 | * Zero on success, negative errno on failure. |
3426 | */ |
3434 | */ |
3427 | void drm_fb_release(struct drm_file *priv) |
3435 | void drm_fb_release(struct drm_file *priv) |
3428 | { |
3436 | { |
3429 | struct drm_framebuffer *fb, *tfb; |
3437 | struct drm_framebuffer *fb, *tfb; |
3430 | 3438 | ||
3431 | /* |
3439 | /* |
3432 | * When the file gets released that means no one else can access the fb |
3440 | * When the file gets released that means no one else can access the fb |
3433 | * list any more, so no need to grab fpriv->fbs_lock. And we need to |
3441 | * list any more, so no need to grab fpriv->fbs_lock. And we need to |
3434 | * avoid upsetting lockdep since the universal cursor code adds a |
3442 | * avoid upsetting lockdep since the universal cursor code adds a |
3435 | * framebuffer while holding mutex locks. |
3443 | * framebuffer while holding mutex locks. |
3436 | * |
3444 | * |
3437 | * Note that a real deadlock between fpriv->fbs_lock and the modeset |
3445 | * Note that a real deadlock between fpriv->fbs_lock and the modeset |
3438 | * locks is impossible here since no one else but this function can get |
3446 | * locks is impossible here since no one else but this function can get |
3439 | * at it any more. |
3447 | * at it any more. |
3440 | */ |
3448 | */ |
3441 | list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) { |
3449 | list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) { |
3442 | list_del_init(&fb->filp_head); |
3450 | list_del_init(&fb->filp_head); |
3443 | 3451 | ||
3444 | /* This drops the fpriv->fbs reference. */ |
3452 | /* This drops the fpriv->fbs reference. */ |
3445 | drm_framebuffer_unreference(fb); |
3453 | drm_framebuffer_unreference(fb); |
3446 | } |
3454 | } |
3447 | } |
3455 | } |
3448 | #endif |
3456 | #endif |
3449 | 3457 | ||
3450 | 3458 | ||
3451 | /** |
3459 | /** |
3452 | * drm_property_create - create a new property type |
3460 | * drm_property_create - create a new property type |
3453 | * @dev: drm device |
3461 | * @dev: drm device |
3454 | * @flags: flags specifying the property type |
3462 | * @flags: flags specifying the property type |
3455 | * @name: name of the property |
3463 | * @name: name of the property |
3456 | * @num_values: number of pre-defined values |
3464 | * @num_values: number of pre-defined values |
3457 | * |
3465 | * |
3458 | * This creates a new generic drm property which can then be attached to a drm |
3466 | * This creates a new generic drm property which can then be attached to a drm |
3459 | * object with drm_object_attach_property. The returned property object must be |
3467 | * object with drm_object_attach_property. The returned property object must be |
3460 | * freed with drm_property_destroy. |
3468 | * freed with drm_property_destroy. |
3461 | * |
3469 | * |
3462 | * Note that the DRM core keeps a per-device list of properties and that, if |
3470 | * Note that the DRM core keeps a per-device list of properties and that, if |
3463 | * drm_mode_config_cleanup() is called, it will destroy all properties created |
3471 | * drm_mode_config_cleanup() is called, it will destroy all properties created |
3464 | * by the driver. |
3472 | * by the driver. |
3465 | * |
3473 | * |
3466 | * Returns: |
3474 | * Returns: |
3467 | * A pointer to the newly created property on success, NULL on failure. |
3475 | * A pointer to the newly created property on success, NULL on failure. |
3468 | */ |
3476 | */ |
3469 | struct drm_property *drm_property_create(struct drm_device *dev, int flags, |
3477 | struct drm_property *drm_property_create(struct drm_device *dev, int flags, |
3470 | const char *name, int num_values) |
3478 | const char *name, int num_values) |
3471 | { |
3479 | { |
3472 | struct drm_property *property = NULL; |
3480 | struct drm_property *property = NULL; |
3473 | int ret; |
3481 | int ret; |
3474 | 3482 | ||
3475 | property = kzalloc(sizeof(struct drm_property), GFP_KERNEL); |
3483 | property = kzalloc(sizeof(struct drm_property), GFP_KERNEL); |
3476 | if (!property) |
3484 | if (!property) |
3477 | return NULL; |
3485 | return NULL; |
3478 | 3486 | ||
3479 | property->dev = dev; |
3487 | property->dev = dev; |
3480 | 3488 | ||
3481 | if (num_values) { |
3489 | if (num_values) { |
3482 | property->values = kcalloc(num_values, sizeof(uint64_t), |
3490 | property->values = kcalloc(num_values, sizeof(uint64_t), |
3483 | GFP_KERNEL); |
3491 | GFP_KERNEL); |
3484 | if (!property->values) |
3492 | if (!property->values) |
3485 | goto fail; |
3493 | goto fail; |
3486 | } |
3494 | } |
3487 | 3495 | ||
3488 | ret = drm_mode_object_get(dev, &property->base, DRM_MODE_OBJECT_PROPERTY); |
3496 | ret = drm_mode_object_get(dev, &property->base, DRM_MODE_OBJECT_PROPERTY); |
3489 | if (ret) |
3497 | if (ret) |
3490 | goto fail; |
3498 | goto fail; |
3491 | 3499 | ||
3492 | property->flags = flags; |
3500 | property->flags = flags; |
3493 | property->num_values = num_values; |
3501 | property->num_values = num_values; |
3494 | INIT_LIST_HEAD(&property->enum_list); |
3502 | INIT_LIST_HEAD(&property->enum_list); |
3495 | 3503 | ||
3496 | if (name) { |
3504 | if (name) { |
3497 | strncpy(property->name, name, DRM_PROP_NAME_LEN); |
3505 | strncpy(property->name, name, DRM_PROP_NAME_LEN); |
3498 | property->name[DRM_PROP_NAME_LEN-1] = '\0'; |
3506 | property->name[DRM_PROP_NAME_LEN-1] = '\0'; |
3499 | } |
3507 | } |
3500 | 3508 | ||
3501 | list_add_tail(&property->head, &dev->mode_config.property_list); |
3509 | list_add_tail(&property->head, &dev->mode_config.property_list); |
3502 | 3510 | ||
3503 | WARN_ON(!drm_property_type_valid(property)); |
3511 | WARN_ON(!drm_property_type_valid(property)); |
3504 | 3512 | ||
3505 | return property; |
3513 | return property; |
3506 | fail: |
3514 | fail: |
3507 | kfree(property->values); |
3515 | kfree(property->values); |
3508 | kfree(property); |
3516 | kfree(property); |
3509 | return NULL; |
3517 | return NULL; |
3510 | } |
3518 | } |
3511 | EXPORT_SYMBOL(drm_property_create); |
3519 | EXPORT_SYMBOL(drm_property_create); |
3512 | 3520 | ||
3513 | /** |
3521 | /** |
3514 | * drm_property_create_enum - create a new enumeration property type |
3522 | * drm_property_create_enum - create a new enumeration property type |
3515 | * @dev: drm device |
3523 | * @dev: drm device |
3516 | * @flags: flags specifying the property type |
3524 | * @flags: flags specifying the property type |
3517 | * @name: name of the property |
3525 | * @name: name of the property |
3518 | * @props: enumeration lists with property values |
3526 | * @props: enumeration lists with property values |
3519 | * @num_values: number of pre-defined values |
3527 | * @num_values: number of pre-defined values |
3520 | * |
3528 | * |
3521 | * This creates a new generic drm property which can then be attached to a drm |
3529 | * This creates a new generic drm property which can then be attached to a drm |
3522 | * object with drm_object_attach_property. The returned property object must be |
3530 | * object with drm_object_attach_property. The returned property object must be |
3523 | * freed with drm_property_destroy. |
3531 | * freed with drm_property_destroy. |
3524 | * |
3532 | * |
3525 | * Userspace is only allowed to set one of the predefined values for enumeration |
3533 | * Userspace is only allowed to set one of the predefined values for enumeration |
3526 | * properties. |
3534 | * properties. |
3527 | * |
3535 | * |
3528 | * Returns: |
3536 | * Returns: |
3529 | * A pointer to the newly created property on success, NULL on failure. |
3537 | * A pointer to the newly created property on success, NULL on failure. |
3530 | */ |
3538 | */ |
3531 | struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags, |
3539 | struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags, |
3532 | const char *name, |
3540 | const char *name, |
3533 | const struct drm_prop_enum_list *props, |
3541 | const struct drm_prop_enum_list *props, |
3534 | int num_values) |
3542 | int num_values) |
3535 | { |
3543 | { |
3536 | struct drm_property *property; |
3544 | struct drm_property *property; |
3537 | int i, ret; |
3545 | int i, ret; |
3538 | 3546 | ||
3539 | flags |= DRM_MODE_PROP_ENUM; |
3547 | flags |= DRM_MODE_PROP_ENUM; |
3540 | 3548 | ||
3541 | property = drm_property_create(dev, flags, name, num_values); |
3549 | property = drm_property_create(dev, flags, name, num_values); |
3542 | if (!property) |
3550 | if (!property) |
3543 | return NULL; |
3551 | return NULL; |
3544 | 3552 | ||
3545 | for (i = 0; i < num_values; i++) { |
3553 | for (i = 0; i < num_values; i++) { |
3546 | ret = drm_property_add_enum(property, i, |
3554 | ret = drm_property_add_enum(property, i, |
3547 | props[i].type, |
3555 | props[i].type, |
3548 | props[i].name); |
3556 | props[i].name); |
3549 | if (ret) { |
3557 | if (ret) { |
3550 | drm_property_destroy(dev, property); |
3558 | drm_property_destroy(dev, property); |
3551 | return NULL; |
3559 | return NULL; |
3552 | } |
3560 | } |
3553 | } |
3561 | } |
3554 | 3562 | ||
3555 | return property; |
3563 | return property; |
3556 | } |
3564 | } |
3557 | EXPORT_SYMBOL(drm_property_create_enum); |
3565 | EXPORT_SYMBOL(drm_property_create_enum); |
3558 | 3566 | ||
3559 | /** |
3567 | /** |
3560 | * drm_property_create_bitmask - create a new bitmask property type |
3568 | * drm_property_create_bitmask - create a new bitmask property type |
3561 | * @dev: drm device |
3569 | * @dev: drm device |
3562 | * @flags: flags specifying the property type |
3570 | * @flags: flags specifying the property type |
3563 | * @name: name of the property |
3571 | * @name: name of the property |
3564 | * @props: enumeration lists with property bitflags |
3572 | * @props: enumeration lists with property bitflags |
3565 | * @num_props: size of the @props array |
3573 | * @num_props: size of the @props array |
3566 | * @supported_bits: bitmask of all supported enumeration values |
3574 | * @supported_bits: bitmask of all supported enumeration values |
3567 | * |
3575 | * |
3568 | * This creates a new bitmask drm property which can then be attached to a drm |
3576 | * This creates a new bitmask drm property which can then be attached to a drm |
3569 | * object with drm_object_attach_property. The returned property object must be |
3577 | * object with drm_object_attach_property. The returned property object must be |
3570 | * freed with drm_property_destroy. |
3578 | * freed with drm_property_destroy. |
3571 | * |
3579 | * |
3572 | * Compared to plain enumeration properties userspace is allowed to set any |
3580 | * Compared to plain enumeration properties userspace is allowed to set any |
3573 | * or'ed together combination of the predefined property bitflag values |
3581 | * or'ed together combination of the predefined property bitflag values |
3574 | * |
3582 | * |
3575 | * Returns: |
3583 | * Returns: |
3576 | * A pointer to the newly created property on success, NULL on failure. |
3584 | * A pointer to the newly created property on success, NULL on failure. |
3577 | */ |
3585 | */ |
3578 | struct drm_property *drm_property_create_bitmask(struct drm_device *dev, |
3586 | struct drm_property *drm_property_create_bitmask(struct drm_device *dev, |
3579 | int flags, const char *name, |
3587 | int flags, const char *name, |
3580 | const struct drm_prop_enum_list *props, |
3588 | const struct drm_prop_enum_list *props, |
3581 | int num_props, |
3589 | int num_props, |
3582 | uint64_t supported_bits) |
3590 | uint64_t supported_bits) |
3583 | { |
3591 | { |
3584 | struct drm_property *property; |
3592 | struct drm_property *property; |
3585 | int i, ret, index = 0; |
3593 | int i, ret, index = 0; |
3586 | int num_values = hweight64(supported_bits); |
3594 | int num_values = hweight64(supported_bits); |
3587 | 3595 | ||
3588 | flags |= DRM_MODE_PROP_BITMASK; |
3596 | flags |= DRM_MODE_PROP_BITMASK; |
3589 | 3597 | ||
3590 | property = drm_property_create(dev, flags, name, num_values); |
3598 | property = drm_property_create(dev, flags, name, num_values); |
3591 | if (!property) |
3599 | if (!property) |
3592 | return NULL; |
3600 | return NULL; |
3593 | for (i = 0; i < num_props; i++) { |
3601 | for (i = 0; i < num_props; i++) { |
3594 | if (!(supported_bits & (1ULL << props[i].type))) |
3602 | if (!(supported_bits & (1ULL << props[i].type))) |
3595 | continue; |
3603 | continue; |
3596 | 3604 | ||
3597 | if (WARN_ON(index >= num_values)) { |
3605 | if (WARN_ON(index >= num_values)) { |
3598 | drm_property_destroy(dev, property); |
3606 | drm_property_destroy(dev, property); |
3599 | return NULL; |
3607 | return NULL; |
3600 | } |
3608 | } |
3601 | 3609 | ||
3602 | ret = drm_property_add_enum(property, index++, |
3610 | ret = drm_property_add_enum(property, index++, |
3603 | props[i].type, |
3611 | props[i].type, |
3604 | props[i].name); |
3612 | props[i].name); |
3605 | if (ret) { |
3613 | if (ret) { |
3606 | drm_property_destroy(dev, property); |
3614 | drm_property_destroy(dev, property); |
3607 | return NULL; |
3615 | return NULL; |
3608 | } |
3616 | } |
3609 | } |
3617 | } |
3610 | 3618 | ||
3611 | return property; |
3619 | return property; |
3612 | } |
3620 | } |
3613 | EXPORT_SYMBOL(drm_property_create_bitmask); |
3621 | EXPORT_SYMBOL(drm_property_create_bitmask); |
3614 | 3622 | ||
3615 | static struct drm_property *property_create_range(struct drm_device *dev, |
3623 | static struct drm_property *property_create_range(struct drm_device *dev, |
3616 | int flags, const char *name, |
3624 | int flags, const char *name, |
3617 | uint64_t min, uint64_t max) |
3625 | uint64_t min, uint64_t max) |
3618 | { |
3626 | { |
3619 | struct drm_property *property; |
3627 | struct drm_property *property; |
3620 | 3628 | ||
3621 | property = drm_property_create(dev, flags, name, 2); |
3629 | property = drm_property_create(dev, flags, name, 2); |
3622 | if (!property) |
3630 | if (!property) |
3623 | return NULL; |
3631 | return NULL; |
3624 | 3632 | ||
3625 | property->values[0] = min; |
3633 | property->values[0] = min; |
3626 | property->values[1] = max; |
3634 | property->values[1] = max; |
3627 | 3635 | ||
3628 | return property; |
3636 | return property; |
3629 | } |
3637 | } |
3630 | 3638 | ||
3631 | /** |
3639 | /** |
3632 | * drm_property_create_range - create a new unsigned ranged property type |
3640 | * drm_property_create_range - create a new unsigned ranged property type |
3633 | * @dev: drm device |
3641 | * @dev: drm device |
3634 | * @flags: flags specifying the property type |
3642 | * @flags: flags specifying the property type |
3635 | * @name: name of the property |
3643 | * @name: name of the property |
3636 | * @min: minimum value of the property |
3644 | * @min: minimum value of the property |
3637 | * @max: maximum value of the property |
3645 | * @max: maximum value of the property |
3638 | * |
3646 | * |
3639 | * This creates a new generic drm property which can then be attached to a drm |
3647 | * This creates a new generic drm property which can then be attached to a drm |
3640 | * object with drm_object_attach_property. The returned property object must be |
3648 | * object with drm_object_attach_property. The returned property object must be |
3641 | * freed with drm_property_destroy. |
3649 | * freed with drm_property_destroy. |
3642 | * |
3650 | * |
3643 | * Userspace is allowed to set any unsigned integer value in the (min, max) |
3651 | * Userspace is allowed to set any unsigned integer value in the (min, max) |
3644 | * range inclusive. |
3652 | * range inclusive. |
3645 | * |
3653 | * |
3646 | * Returns: |
3654 | * Returns: |
3647 | * A pointer to the newly created property on success, NULL on failure. |
3655 | * A pointer to the newly created property on success, NULL on failure. |
3648 | */ |
3656 | */ |
3649 | struct drm_property *drm_property_create_range(struct drm_device *dev, int flags, |
3657 | struct drm_property *drm_property_create_range(struct drm_device *dev, int flags, |
3650 | const char *name, |
3658 | const char *name, |
3651 | uint64_t min, uint64_t max) |
3659 | uint64_t min, uint64_t max) |
3652 | { |
3660 | { |
3653 | return property_create_range(dev, DRM_MODE_PROP_RANGE | flags, |
3661 | return property_create_range(dev, DRM_MODE_PROP_RANGE | flags, |
3654 | name, min, max); |
3662 | name, min, max); |
3655 | } |
3663 | } |
3656 | EXPORT_SYMBOL(drm_property_create_range); |
3664 | EXPORT_SYMBOL(drm_property_create_range); |
3657 | 3665 | ||
3658 | /** |
3666 | /** |
3659 | * drm_property_create_signed_range - create a new signed ranged property type |
3667 | * drm_property_create_signed_range - create a new signed ranged property type |
3660 | * @dev: drm device |
3668 | * @dev: drm device |
3661 | * @flags: flags specifying the property type |
3669 | * @flags: flags specifying the property type |
3662 | * @name: name of the property |
3670 | * @name: name of the property |
3663 | * @min: minimum value of the property |
3671 | * @min: minimum value of the property |
3664 | * @max: maximum value of the property |
3672 | * @max: maximum value of the property |
3665 | * |
3673 | * |
3666 | * This creates a new generic drm property which can then be attached to a drm |
3674 | * This creates a new generic drm property which can then be attached to a drm |
3667 | * object with drm_object_attach_property. The returned property object must be |
3675 | * object with drm_object_attach_property. The returned property object must be |
3668 | * freed with drm_property_destroy. |
3676 | * freed with drm_property_destroy. |
3669 | * |
3677 | * |
3670 | * Userspace is allowed to set any signed integer value in the (min, max) |
3678 | * Userspace is allowed to set any signed integer value in the (min, max) |
3671 | * range inclusive. |
3679 | * range inclusive. |
3672 | * |
3680 | * |
3673 | * Returns: |
3681 | * Returns: |
3674 | * A pointer to the newly created property on success, NULL on failure. |
3682 | * A pointer to the newly created property on success, NULL on failure. |
3675 | */ |
3683 | */ |
3676 | struct drm_property *drm_property_create_signed_range(struct drm_device *dev, |
3684 | struct drm_property *drm_property_create_signed_range(struct drm_device *dev, |
3677 | int flags, const char *name, |
3685 | int flags, const char *name, |
3678 | int64_t min, int64_t max) |
3686 | int64_t min, int64_t max) |
3679 | { |
3687 | { |
3680 | return property_create_range(dev, DRM_MODE_PROP_SIGNED_RANGE | flags, |
3688 | return property_create_range(dev, DRM_MODE_PROP_SIGNED_RANGE | flags, |
3681 | name, I642U64(min), I642U64(max)); |
3689 | name, I642U64(min), I642U64(max)); |
3682 | } |
3690 | } |
3683 | EXPORT_SYMBOL(drm_property_create_signed_range); |
3691 | EXPORT_SYMBOL(drm_property_create_signed_range); |
3684 | 3692 | ||
3685 | /** |
3693 | /** |
3686 | * drm_property_create_object - create a new object property type |
3694 | * drm_property_create_object - create a new object property type |
3687 | * @dev: drm device |
3695 | * @dev: drm device |
3688 | * @flags: flags specifying the property type |
3696 | * @flags: flags specifying the property type |
3689 | * @name: name of the property |
3697 | * @name: name of the property |
3690 | * @type: object type from DRM_MODE_OBJECT_* defines |
3698 | * @type: object type from DRM_MODE_OBJECT_* defines |
3691 | * |
3699 | * |
3692 | * This creates a new generic drm property which can then be attached to a drm |
3700 | * This creates a new generic drm property which can then be attached to a drm |
3693 | * object with drm_object_attach_property. The returned property object must be |
3701 | * object with drm_object_attach_property. The returned property object must be |
3694 | * freed with drm_property_destroy. |
3702 | * freed with drm_property_destroy. |
3695 | * |
3703 | * |
3696 | * Userspace is only allowed to set this to any property value of the given |
3704 | * Userspace is only allowed to set this to any property value of the given |
3697 | * @type. Only useful for atomic properties, which is enforced. |
3705 | * @type. Only useful for atomic properties, which is enforced. |
3698 | * |
3706 | * |
3699 | * Returns: |
3707 | * Returns: |
3700 | * A pointer to the newly created property on success, NULL on failure. |
3708 | * A pointer to the newly created property on success, NULL on failure. |
3701 | */ |
3709 | */ |
3702 | struct drm_property *drm_property_create_object(struct drm_device *dev, |
3710 | struct drm_property *drm_property_create_object(struct drm_device *dev, |
3703 | int flags, const char *name, uint32_t type) |
3711 | int flags, const char *name, uint32_t type) |
3704 | { |
3712 | { |
3705 | struct drm_property *property; |
3713 | struct drm_property *property; |
3706 | 3714 | ||
3707 | flags |= DRM_MODE_PROP_OBJECT; |
3715 | flags |= DRM_MODE_PROP_OBJECT; |
3708 | 3716 | ||
3709 | if (WARN_ON(!(flags & DRM_MODE_PROP_ATOMIC))) |
3717 | if (WARN_ON(!(flags & DRM_MODE_PROP_ATOMIC))) |
3710 | return NULL; |
3718 | return NULL; |
3711 | 3719 | ||
3712 | property = drm_property_create(dev, flags, name, 1); |
3720 | property = drm_property_create(dev, flags, name, 1); |
3713 | if (!property) |
3721 | if (!property) |
3714 | return NULL; |
3722 | return NULL; |
3715 | 3723 | ||
3716 | property->values[0] = type; |
3724 | property->values[0] = type; |
3717 | 3725 | ||
3718 | return property; |
3726 | return property; |
3719 | } |
3727 | } |
3720 | EXPORT_SYMBOL(drm_property_create_object); |
3728 | EXPORT_SYMBOL(drm_property_create_object); |
3721 | 3729 | ||
3722 | /** |
3730 | /** |
3723 | * drm_property_create_bool - create a new boolean property type |
3731 | * drm_property_create_bool - create a new boolean property type |
3724 | * @dev: drm device |
3732 | * @dev: drm device |
3725 | * @flags: flags specifying the property type |
3733 | * @flags: flags specifying the property type |
3726 | * @name: name of the property |
3734 | * @name: name of the property |
3727 | * |
3735 | * |
3728 | * This creates a new generic drm property which can then be attached to a drm |
3736 | * This creates a new generic drm property which can then be attached to a drm |
3729 | * object with drm_object_attach_property. The returned property object must be |
3737 | * object with drm_object_attach_property. The returned property object must be |
3730 | * freed with drm_property_destroy. |
3738 | * freed with drm_property_destroy. |
3731 | * |
3739 | * |
3732 | * This is implemented as a ranged property with only {0, 1} as valid values. |
3740 | * This is implemented as a ranged property with only {0, 1} as valid values. |
3733 | * |
3741 | * |
3734 | * Returns: |
3742 | * Returns: |
3735 | * A pointer to the newly created property on success, NULL on failure. |
3743 | * A pointer to the newly created property on success, NULL on failure. |
3736 | */ |
3744 | */ |
3737 | struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags, |
3745 | struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags, |
3738 | const char *name) |
3746 | const char *name) |
3739 | { |
3747 | { |
3740 | return drm_property_create_range(dev, flags, name, 0, 1); |
3748 | return drm_property_create_range(dev, flags, name, 0, 1); |
3741 | } |
3749 | } |
3742 | EXPORT_SYMBOL(drm_property_create_bool); |
3750 | EXPORT_SYMBOL(drm_property_create_bool); |
3743 | 3751 | ||
3744 | /** |
3752 | /** |
3745 | * drm_property_add_enum - add a possible value to an enumeration property |
3753 | * drm_property_add_enum - add a possible value to an enumeration property |
3746 | * @property: enumeration property to change |
3754 | * @property: enumeration property to change |
3747 | * @index: index of the new enumeration |
3755 | * @index: index of the new enumeration |
3748 | * @value: value of the new enumeration |
3756 | * @value: value of the new enumeration |
3749 | * @name: symbolic name of the new enumeration |
3757 | * @name: symbolic name of the new enumeration |
3750 | * |
3758 | * |
3751 | * This functions adds enumerations to a property. |
3759 | * This functions adds enumerations to a property. |
3752 | * |
3760 | * |
3753 | * It's use is deprecated, drivers should use one of the more specific helpers |
3761 | * It's use is deprecated, drivers should use one of the more specific helpers |
3754 | * to directly create the property with all enumerations already attached. |
3762 | * to directly create the property with all enumerations already attached. |
3755 | * |
3763 | * |
3756 | * Returns: |
3764 | * Returns: |
3757 | * Zero on success, error code on failure. |
3765 | * Zero on success, error code on failure. |
3758 | */ |
3766 | */ |
3759 | int drm_property_add_enum(struct drm_property *property, int index, |
3767 | int drm_property_add_enum(struct drm_property *property, int index, |
3760 | uint64_t value, const char *name) |
3768 | uint64_t value, const char *name) |
3761 | { |
3769 | { |
3762 | struct drm_property_enum *prop_enum; |
3770 | struct drm_property_enum *prop_enum; |
3763 | 3771 | ||
3764 | if (!(drm_property_type_is(property, DRM_MODE_PROP_ENUM) || |
3772 | if (!(drm_property_type_is(property, DRM_MODE_PROP_ENUM) || |
3765 | drm_property_type_is(property, DRM_MODE_PROP_BITMASK))) |
3773 | drm_property_type_is(property, DRM_MODE_PROP_BITMASK))) |
3766 | return -EINVAL; |
3774 | return -EINVAL; |
3767 | 3775 | ||
3768 | /* |
3776 | /* |
3769 | * Bitmask enum properties have the additional constraint of values |
3777 | * Bitmask enum properties have the additional constraint of values |
3770 | * from 0 to 63 |
3778 | * from 0 to 63 |
3771 | */ |
3779 | */ |
3772 | if (drm_property_type_is(property, DRM_MODE_PROP_BITMASK) && |
3780 | if (drm_property_type_is(property, DRM_MODE_PROP_BITMASK) && |
3773 | (value > 63)) |
3781 | (value > 63)) |
3774 | return -EINVAL; |
3782 | return -EINVAL; |
3775 | 3783 | ||
3776 | if (!list_empty(&property->enum_list)) { |
3784 | if (!list_empty(&property->enum_list)) { |
3777 | list_for_each_entry(prop_enum, &property->enum_list, head) { |
3785 | list_for_each_entry(prop_enum, &property->enum_list, head) { |
3778 | if (prop_enum->value == value) { |
3786 | if (prop_enum->value == value) { |
3779 | strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN); |
3787 | strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN); |
3780 | prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0'; |
3788 | prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0'; |
3781 | return 0; |
3789 | return 0; |
3782 | } |
3790 | } |
3783 | } |
3791 | } |
3784 | } |
3792 | } |
3785 | 3793 | ||
3786 | prop_enum = kzalloc(sizeof(struct drm_property_enum), GFP_KERNEL); |
3794 | prop_enum = kzalloc(sizeof(struct drm_property_enum), GFP_KERNEL); |
3787 | if (!prop_enum) |
3795 | if (!prop_enum) |
3788 | return -ENOMEM; |
3796 | return -ENOMEM; |
3789 | 3797 | ||
3790 | strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN); |
3798 | strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN); |
3791 | prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0'; |
3799 | prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0'; |
3792 | prop_enum->value = value; |
3800 | prop_enum->value = value; |
3793 | 3801 | ||
3794 | property->values[index] = value; |
3802 | property->values[index] = value; |
3795 | list_add_tail(&prop_enum->head, &property->enum_list); |
3803 | list_add_tail(&prop_enum->head, &property->enum_list); |
3796 | return 0; |
3804 | return 0; |
3797 | } |
3805 | } |
3798 | EXPORT_SYMBOL(drm_property_add_enum); |
3806 | EXPORT_SYMBOL(drm_property_add_enum); |
3799 | 3807 | ||
3800 | /** |
3808 | /** |
3801 | * drm_property_destroy - destroy a drm property |
3809 | * drm_property_destroy - destroy a drm property |
3802 | * @dev: drm device |
3810 | * @dev: drm device |
3803 | * @property: property to destry |
3811 | * @property: property to destry |
3804 | * |
3812 | * |
3805 | * This function frees a property including any attached resources like |
3813 | * This function frees a property including any attached resources like |
3806 | * enumeration values. |
3814 | * enumeration values. |
3807 | */ |
3815 | */ |
3808 | void drm_property_destroy(struct drm_device *dev, struct drm_property *property) |
3816 | void drm_property_destroy(struct drm_device *dev, struct drm_property *property) |
3809 | { |
3817 | { |
3810 | struct drm_property_enum *prop_enum, *pt; |
3818 | struct drm_property_enum *prop_enum, *pt; |
3811 | 3819 | ||
3812 | list_for_each_entry_safe(prop_enum, pt, &property->enum_list, head) { |
3820 | list_for_each_entry_safe(prop_enum, pt, &property->enum_list, head) { |
3813 | list_del(&prop_enum->head); |
3821 | list_del(&prop_enum->head); |
3814 | kfree(prop_enum); |
3822 | kfree(prop_enum); |
3815 | } |
3823 | } |
3816 | 3824 | ||
3817 | if (property->num_values) |
3825 | if (property->num_values) |
3818 | kfree(property->values); |
3826 | kfree(property->values); |
3819 | drm_mode_object_put(dev, &property->base); |
3827 | drm_mode_object_put(dev, &property->base); |
3820 | list_del(&property->head); |
3828 | list_del(&property->head); |
3821 | kfree(property); |
3829 | kfree(property); |
3822 | } |
3830 | } |
3823 | EXPORT_SYMBOL(drm_property_destroy); |
3831 | EXPORT_SYMBOL(drm_property_destroy); |
3824 | 3832 | ||
3825 | /** |
3833 | /** |
3826 | * drm_object_attach_property - attach a property to a modeset object |
3834 | * drm_object_attach_property - attach a property to a modeset object |
3827 | * @obj: drm modeset object |
3835 | * @obj: drm modeset object |
3828 | * @property: property to attach |
3836 | * @property: property to attach |
3829 | * @init_val: initial value of the property |
3837 | * @init_val: initial value of the property |
3830 | * |
3838 | * |
3831 | * This attaches the given property to the modeset object with the given initial |
3839 | * This attaches the given property to the modeset object with the given initial |
3832 | * value. Currently this function cannot fail since the properties are stored in |
3840 | * value. Currently this function cannot fail since the properties are stored in |
3833 | * a statically sized array. |
3841 | * a statically sized array. |
3834 | */ |
3842 | */ |
3835 | void drm_object_attach_property(struct drm_mode_object *obj, |
3843 | void drm_object_attach_property(struct drm_mode_object *obj, |
3836 | struct drm_property *property, |
3844 | struct drm_property *property, |
3837 | uint64_t init_val) |
3845 | uint64_t init_val) |
3838 | { |
3846 | { |
3839 | int count = obj->properties->count; |
3847 | int count = obj->properties->count; |
3840 | 3848 | ||
3841 | if (count == DRM_OBJECT_MAX_PROPERTY) { |
3849 | if (count == DRM_OBJECT_MAX_PROPERTY) { |
3842 | WARN(1, "Failed to attach object property (type: 0x%x). Please " |
3850 | WARN(1, "Failed to attach object property (type: 0x%x). Please " |
3843 | "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time " |
3851 | "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time " |
3844 | "you see this message on the same object type.\n", |
3852 | "you see this message on the same object type.\n", |
3845 | obj->type); |
3853 | obj->type); |
3846 | return; |
3854 | return; |
3847 | } |
3855 | } |
3848 | 3856 | ||
3849 | obj->properties->properties[count] = property; |
3857 | obj->properties->properties[count] = property; |
3850 | obj->properties->values[count] = init_val; |
3858 | obj->properties->values[count] = init_val; |
3851 | obj->properties->count++; |
3859 | obj->properties->count++; |
3852 | if (property->flags & DRM_MODE_PROP_ATOMIC) |
3860 | if (property->flags & DRM_MODE_PROP_ATOMIC) |
3853 | obj->properties->atomic_count++; |
3861 | obj->properties->atomic_count++; |
3854 | } |
3862 | } |
3855 | EXPORT_SYMBOL(drm_object_attach_property); |
3863 | EXPORT_SYMBOL(drm_object_attach_property); |
3856 | 3864 | ||
3857 | /** |
3865 | /** |
3858 | * drm_object_property_set_value - set the value of a property |
3866 | * drm_object_property_set_value - set the value of a property |
3859 | * @obj: drm mode object to set property value for |
3867 | * @obj: drm mode object to set property value for |
3860 | * @property: property to set |
3868 | * @property: property to set |
3861 | * @val: value the property should be set to |
3869 | * @val: value the property should be set to |
3862 | * |
3870 | * |
3863 | * This functions sets a given property on a given object. This function only |
3871 | * This functions sets a given property on a given object. This function only |
3864 | * changes the software state of the property, it does not call into the |
3872 | * changes the software state of the property, it does not call into the |
3865 | * driver's ->set_property callback. |
3873 | * driver's ->set_property callback. |
3866 | * |
3874 | * |
3867 | * Returns: |
3875 | * Returns: |
3868 | * Zero on success, error code on failure. |
3876 | * Zero on success, error code on failure. |
3869 | */ |
3877 | */ |
3870 | int drm_object_property_set_value(struct drm_mode_object *obj, |
3878 | int drm_object_property_set_value(struct drm_mode_object *obj, |
3871 | struct drm_property *property, uint64_t val) |
3879 | struct drm_property *property, uint64_t val) |
3872 | { |
3880 | { |
3873 | int i; |
3881 | int i; |
3874 | 3882 | ||
3875 | for (i = 0; i < obj->properties->count; i++) { |
3883 | for (i = 0; i < obj->properties->count; i++) { |
3876 | if (obj->properties->properties[i] == property) { |
3884 | if (obj->properties->properties[i] == property) { |
3877 | obj->properties->values[i] = val; |
3885 | obj->properties->values[i] = val; |
3878 | return 0; |
3886 | return 0; |
3879 | } |
3887 | } |
3880 | } |
3888 | } |
3881 | 3889 | ||
3882 | return -EINVAL; |
3890 | return -EINVAL; |
3883 | } |
3891 | } |
3884 | EXPORT_SYMBOL(drm_object_property_set_value); |
3892 | EXPORT_SYMBOL(drm_object_property_set_value); |
3885 | 3893 | ||
3886 | /** |
3894 | /** |
3887 | * drm_object_property_get_value - retrieve the value of a property |
3895 | * drm_object_property_get_value - retrieve the value of a property |
3888 | * @obj: drm mode object to get property value from |
3896 | * @obj: drm mode object to get property value from |
3889 | * @property: property to retrieve |
3897 | * @property: property to retrieve |
3890 | * @val: storage for the property value |
3898 | * @val: storage for the property value |
3891 | * |
3899 | * |
3892 | * This function retrieves the softare state of the given property for the given |
3900 | * This function retrieves the softare state of the given property for the given |
3893 | * property. Since there is no driver callback to retrieve the current property |
3901 | * property. Since there is no driver callback to retrieve the current property |
3894 | * value this might be out of sync with the hardware, depending upon the driver |
3902 | * value this might be out of sync with the hardware, depending upon the driver |
3895 | * and property. |
3903 | * and property. |
3896 | * |
3904 | * |
3897 | * Returns: |
3905 | * Returns: |
3898 | * Zero on success, error code on failure. |
3906 | * Zero on success, error code on failure. |
3899 | */ |
3907 | */ |
3900 | int drm_object_property_get_value(struct drm_mode_object *obj, |
3908 | int drm_object_property_get_value(struct drm_mode_object *obj, |
3901 | struct drm_property *property, uint64_t *val) |
3909 | struct drm_property *property, uint64_t *val) |
3902 | { |
3910 | { |
3903 | int i; |
3911 | int i; |
3904 | 3912 | ||
3905 | /* read-only properties bypass atomic mechanism and still store |
3913 | /* read-only properties bypass atomic mechanism and still store |
3906 | * their value in obj->properties->values[].. mostly to avoid |
3914 | * their value in obj->properties->values[].. mostly to avoid |
3907 | * having to deal w/ EDID and similar props in atomic paths: |
3915 | * having to deal w/ EDID and similar props in atomic paths: |
3908 | */ |
3916 | */ |
3909 | if (drm_core_check_feature(property->dev, DRIVER_ATOMIC) && |
3917 | if (drm_core_check_feature(property->dev, DRIVER_ATOMIC) && |
3910 | !(property->flags & DRM_MODE_PROP_IMMUTABLE)) |
3918 | !(property->flags & DRM_MODE_PROP_IMMUTABLE)) |
3911 | return drm_atomic_get_property(obj, property, val); |
3919 | return drm_atomic_get_property(obj, property, val); |
3912 | 3920 | ||
3913 | for (i = 0; i < obj->properties->count; i++) { |
3921 | for (i = 0; i < obj->properties->count; i++) { |
3914 | if (obj->properties->properties[i] == property) { |
3922 | if (obj->properties->properties[i] == property) { |
3915 | *val = obj->properties->values[i]; |
3923 | *val = obj->properties->values[i]; |
3916 | return 0; |
3924 | return 0; |
3917 | } |
3925 | } |
3918 | } |
3926 | } |
3919 | 3927 | ||
3920 | return -EINVAL; |
3928 | return -EINVAL; |
3921 | } |
3929 | } |
3922 | EXPORT_SYMBOL(drm_object_property_get_value); |
3930 | EXPORT_SYMBOL(drm_object_property_get_value); |
3923 | 3931 | ||
3924 | #if 0 |
3932 | #if 0 |
3925 | /** |
3933 | /** |
3926 | * drm_mode_getproperty_ioctl - get the property metadata |
3934 | * drm_mode_getproperty_ioctl - get the property metadata |
3927 | * @dev: DRM device |
3935 | * @dev: DRM device |
3928 | * @data: ioctl data |
3936 | * @data: ioctl data |
3929 | * @file_priv: DRM file info |
3937 | * @file_priv: DRM file info |
3930 | * |
3938 | * |
3931 | * This function retrieves the metadata for a given property, like the different |
3939 | * This function retrieves the metadata for a given property, like the different |
3932 | * possible values for an enum property or the limits for a range property. |
3940 | * possible values for an enum property or the limits for a range property. |
3933 | * |
3941 | * |
3934 | * Blob properties are special |
3942 | * Blob properties are special |
3935 | * |
3943 | * |
3936 | * Called by the user via ioctl. |
3944 | * Called by the user via ioctl. |
3937 | * |
3945 | * |
3938 | * Returns: |
3946 | * Returns: |
3939 | * Zero on success, negative errno on failure. |
3947 | * Zero on success, negative errno on failure. |
3940 | */ |
3948 | */ |
3941 | int drm_mode_getproperty_ioctl(struct drm_device *dev, |
3949 | int drm_mode_getproperty_ioctl(struct drm_device *dev, |
3942 | void *data, struct drm_file *file_priv) |
3950 | void *data, struct drm_file *file_priv) |
3943 | { |
3951 | { |
3944 | struct drm_mode_get_property *out_resp = data; |
3952 | struct drm_mode_get_property *out_resp = data; |
3945 | struct drm_property *property; |
3953 | struct drm_property *property; |
3946 | int enum_count = 0; |
3954 | int enum_count = 0; |
3947 | int value_count = 0; |
3955 | int value_count = 0; |
3948 | int ret = 0, i; |
3956 | int ret = 0, i; |
3949 | int copied; |
3957 | int copied; |
3950 | struct drm_property_enum *prop_enum; |
3958 | struct drm_property_enum *prop_enum; |
3951 | struct drm_mode_property_enum __user *enum_ptr; |
3959 | struct drm_mode_property_enum __user *enum_ptr; |
3952 | uint64_t __user *values_ptr; |
3960 | uint64_t __user *values_ptr; |
3953 | 3961 | ||
3954 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
3962 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
3955 | return -EINVAL; |
3963 | return -EINVAL; |
3956 | 3964 | ||
3957 | drm_modeset_lock_all(dev); |
3965 | drm_modeset_lock_all(dev); |
3958 | property = drm_property_find(dev, out_resp->prop_id); |
3966 | property = drm_property_find(dev, out_resp->prop_id); |
3959 | if (!property) { |
3967 | if (!property) { |
3960 | ret = -ENOENT; |
3968 | ret = -ENOENT; |
3961 | goto done; |
3969 | goto done; |
3962 | } |
3970 | } |
3963 | 3971 | ||
3964 | if (drm_property_type_is(property, DRM_MODE_PROP_ENUM) || |
3972 | if (drm_property_type_is(property, DRM_MODE_PROP_ENUM) || |
3965 | drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) { |
3973 | drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) { |
3966 | list_for_each_entry(prop_enum, &property->enum_list, head) |
3974 | list_for_each_entry(prop_enum, &property->enum_list, head) |
3967 | enum_count++; |
3975 | enum_count++; |
3968 | } |
3976 | } |
3969 | 3977 | ||
3970 | value_count = property->num_values; |
3978 | value_count = property->num_values; |
3971 | 3979 | ||
3972 | strncpy(out_resp->name, property->name, DRM_PROP_NAME_LEN); |
3980 | strncpy(out_resp->name, property->name, DRM_PROP_NAME_LEN); |
3973 | out_resp->name[DRM_PROP_NAME_LEN-1] = 0; |
3981 | out_resp->name[DRM_PROP_NAME_LEN-1] = 0; |
3974 | out_resp->flags = property->flags; |
3982 | out_resp->flags = property->flags; |
3975 | 3983 | ||
3976 | if ((out_resp->count_values >= value_count) && value_count) { |
3984 | if ((out_resp->count_values >= value_count) && value_count) { |
3977 | values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr; |
3985 | values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr; |
3978 | for (i = 0; i < value_count; i++) { |
3986 | for (i = 0; i < value_count; i++) { |
3979 | if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) { |
3987 | if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) { |
3980 | ret = -EFAULT; |
3988 | ret = -EFAULT; |
3981 | goto done; |
3989 | goto done; |
3982 | } |
3990 | } |
3983 | } |
3991 | } |
3984 | } |
3992 | } |
3985 | out_resp->count_values = value_count; |
3993 | out_resp->count_values = value_count; |
3986 | 3994 | ||
3987 | if (drm_property_type_is(property, DRM_MODE_PROP_ENUM) || |
3995 | if (drm_property_type_is(property, DRM_MODE_PROP_ENUM) || |
3988 | drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) { |
3996 | drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) { |
3989 | if ((out_resp->count_enum_blobs >= enum_count) && enum_count) { |
3997 | if ((out_resp->count_enum_blobs >= enum_count) && enum_count) { |
3990 | copied = 0; |
3998 | copied = 0; |
3991 | enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr; |
3999 | enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr; |
3992 | list_for_each_entry(prop_enum, &property->enum_list, head) { |
4000 | list_for_each_entry(prop_enum, &property->enum_list, head) { |
3993 | 4001 | ||
3994 | if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) { |
4002 | if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) { |
3995 | ret = -EFAULT; |
4003 | ret = -EFAULT; |
3996 | goto done; |
4004 | goto done; |
3997 | } |
4005 | } |
3998 | 4006 | ||
3999 | if (copy_to_user(&enum_ptr[copied].name, |
4007 | if (copy_to_user(&enum_ptr[copied].name, |
4000 | &prop_enum->name, DRM_PROP_NAME_LEN)) { |
4008 | &prop_enum->name, DRM_PROP_NAME_LEN)) { |
4001 | ret = -EFAULT; |
4009 | ret = -EFAULT; |
4002 | goto done; |
4010 | goto done; |
4003 | } |
4011 | } |
4004 | copied++; |
4012 | copied++; |
4005 | } |
4013 | } |
4006 | } |
4014 | } |
4007 | out_resp->count_enum_blobs = enum_count; |
4015 | out_resp->count_enum_blobs = enum_count; |
4008 | } |
4016 | } |
4009 | 4017 | ||
4010 | /* |
4018 | /* |
4011 | * NOTE: The idea seems to have been to use this to read all the blob |
4019 | * NOTE: The idea seems to have been to use this to read all the blob |
4012 | * property values. But nothing ever added them to the corresponding |
4020 | * property values. But nothing ever added them to the corresponding |
4013 | * list, userspace always used the special-purpose get_blob ioctl to |
4021 | * list, userspace always used the special-purpose get_blob ioctl to |
4014 | * read the value for a blob property. It also doesn't make a lot of |
4022 | * read the value for a blob property. It also doesn't make a lot of |
4015 | * sense to return values here when everything else is just metadata for |
4023 | * sense to return values here when everything else is just metadata for |
4016 | * the property itself. |
4024 | * the property itself. |
4017 | */ |
4025 | */ |
4018 | if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) |
4026 | if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) |
4019 | out_resp->count_enum_blobs = 0; |
4027 | out_resp->count_enum_blobs = 0; |
4020 | done: |
4028 | done: |
4021 | drm_modeset_unlock_all(dev); |
4029 | drm_modeset_unlock_all(dev); |
4022 | return ret; |
4030 | return ret; |
4023 | } |
4031 | } |
4024 | #endif |
4032 | #endif |
4025 | 4033 | ||
4026 | /** |
4034 | /** |
4027 | * drm_property_create_blob - Create new blob property |
4035 | * drm_property_create_blob - Create new blob property |
4028 | * |
4036 | * |
4029 | * Creates a new blob property for a specified DRM device, optionally |
4037 | * Creates a new blob property for a specified DRM device, optionally |
4030 | * copying data. |
4038 | * copying data. |
4031 | * |
4039 | * |
4032 | * @dev: DRM device to create property for |
4040 | * @dev: DRM device to create property for |
4033 | * @length: Length to allocate for blob data |
4041 | * @length: Length to allocate for blob data |
4034 | * @data: If specified, copies data into blob |
4042 | * @data: If specified, copies data into blob |
4035 | * |
4043 | * |
4036 | * Returns: |
4044 | * Returns: |
4037 | * New blob property with a single reference on success, or an ERR_PTR |
4045 | * New blob property with a single reference on success, or an ERR_PTR |
4038 | * value on failure. |
4046 | * value on failure. |
4039 | */ |
4047 | */ |
4040 | struct drm_property_blob * |
4048 | struct drm_property_blob * |
4041 | drm_property_create_blob(struct drm_device *dev, size_t length, |
4049 | drm_property_create_blob(struct drm_device *dev, size_t length, |
4042 | const void *data) |
4050 | const void *data) |
4043 | { |
4051 | { |
4044 | struct drm_property_blob *blob; |
4052 | struct drm_property_blob *blob; |
4045 | int ret; |
4053 | int ret; |
4046 | 4054 | ||
4047 | if (!length || length > ULONG_MAX - sizeof(struct drm_property_blob)) |
4055 | if (!length || length > ULONG_MAX - sizeof(struct drm_property_blob)) |
4048 | return ERR_PTR(-EINVAL); |
4056 | return ERR_PTR(-EINVAL); |
4049 | 4057 | ||
4050 | blob = kzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL); |
4058 | blob = kzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL); |
4051 | if (!blob) |
4059 | if (!blob) |
4052 | return ERR_PTR(-ENOMEM); |
4060 | return ERR_PTR(-ENOMEM); |
4053 | 4061 | ||
4054 | /* This must be explicitly initialised, so we can safely call list_del |
4062 | /* This must be explicitly initialised, so we can safely call list_del |
4055 | * on it in the removal handler, even if it isn't in a file list. */ |
4063 | * on it in the removal handler, even if it isn't in a file list. */ |
4056 | INIT_LIST_HEAD(&blob->head_file); |
4064 | INIT_LIST_HEAD(&blob->head_file); |
4057 | blob->length = length; |
4065 | blob->length = length; |
4058 | blob->dev = dev; |
4066 | blob->dev = dev; |
4059 | 4067 | ||
4060 | if (data) |
4068 | if (data) |
4061 | memcpy(blob->data, data, length); |
4069 | memcpy(blob->data, data, length); |
4062 | 4070 | ||
4063 | mutex_lock(&dev->mode_config.blob_lock); |
4071 | mutex_lock(&dev->mode_config.blob_lock); |
4064 | 4072 | ||
4065 | ret = drm_mode_object_get(dev, &blob->base, DRM_MODE_OBJECT_BLOB); |
4073 | ret = drm_mode_object_get(dev, &blob->base, DRM_MODE_OBJECT_BLOB); |
4066 | if (ret) { |
4074 | if (ret) { |
4067 | kfree(blob); |
4075 | kfree(blob); |
4068 | mutex_unlock(&dev->mode_config.blob_lock); |
4076 | mutex_unlock(&dev->mode_config.blob_lock); |
4069 | return ERR_PTR(-EINVAL); |
4077 | return ERR_PTR(-EINVAL); |
4070 | } |
4078 | } |
4071 | 4079 | ||
4072 | kref_init(&blob->refcount); |
4080 | kref_init(&blob->refcount); |
4073 | 4081 | ||
4074 | list_add_tail(&blob->head_global, |
4082 | list_add_tail(&blob->head_global, |
4075 | &dev->mode_config.property_blob_list); |
4083 | &dev->mode_config.property_blob_list); |
4076 | 4084 | ||
4077 | mutex_unlock(&dev->mode_config.blob_lock); |
4085 | mutex_unlock(&dev->mode_config.blob_lock); |
4078 | 4086 | ||
4079 | return blob; |
4087 | return blob; |
4080 | } |
4088 | } |
4081 | EXPORT_SYMBOL(drm_property_create_blob); |
4089 | EXPORT_SYMBOL(drm_property_create_blob); |
4082 | 4090 | ||
4083 | /** |
4091 | /** |
4084 | * drm_property_free_blob - Blob property destructor |
4092 | * drm_property_free_blob - Blob property destructor |
4085 | * |
4093 | * |
4086 | * Internal free function for blob properties; must not be used directly. |
4094 | * Internal free function for blob properties; must not be used directly. |
4087 | * |
4095 | * |
4088 | * @kref: Reference |
4096 | * @kref: Reference |
4089 | */ |
4097 | */ |
4090 | static void drm_property_free_blob(struct kref *kref) |
4098 | static void drm_property_free_blob(struct kref *kref) |
4091 | { |
4099 | { |
4092 | struct drm_property_blob *blob = |
4100 | struct drm_property_blob *blob = |
4093 | container_of(kref, struct drm_property_blob, refcount); |
4101 | container_of(kref, struct drm_property_blob, refcount); |
4094 | 4102 | ||
4095 | WARN_ON(!mutex_is_locked(&blob->dev->mode_config.blob_lock)); |
4103 | WARN_ON(!mutex_is_locked(&blob->dev->mode_config.blob_lock)); |
4096 | 4104 | ||
4097 | list_del(&blob->head_global); |
4105 | list_del(&blob->head_global); |
4098 | list_del(&blob->head_file); |
4106 | list_del(&blob->head_file); |
4099 | drm_mode_object_put(blob->dev, &blob->base); |
4107 | drm_mode_object_put(blob->dev, &blob->base); |
4100 | 4108 | ||
4101 | kfree(blob); |
4109 | kfree(blob); |
4102 | } |
4110 | } |
4103 | 4111 | ||
4104 | /** |
4112 | /** |
4105 | * drm_property_unreference_blob - Unreference a blob property |
4113 | * drm_property_unreference_blob - Unreference a blob property |
4106 | * |
4114 | * |
4107 | * Drop a reference on a blob property. May free the object. |
4115 | * Drop a reference on a blob property. May free the object. |
4108 | * |
4116 | * |
4109 | * @blob: Pointer to blob property |
4117 | * @blob: Pointer to blob property |
4110 | */ |
4118 | */ |
4111 | void drm_property_unreference_blob(struct drm_property_blob *blob) |
4119 | void drm_property_unreference_blob(struct drm_property_blob *blob) |
4112 | { |
4120 | { |
4113 | struct drm_device *dev; |
4121 | struct drm_device *dev; |
4114 | 4122 | ||
4115 | if (!blob) |
4123 | if (!blob) |
4116 | return; |
4124 | return; |
4117 | 4125 | ||
4118 | dev = blob->dev; |
4126 | dev = blob->dev; |
4119 | 4127 | ||
4120 | DRM_DEBUG("%p: blob ID: %d (%d)\n", blob, blob->base.id, atomic_read(&blob->refcount.refcount)); |
4128 | DRM_DEBUG("%p: blob ID: %d (%d)\n", blob, blob->base.id, atomic_read(&blob->refcount.refcount)); |
4121 | 4129 | ||
4122 | if (kref_put_mutex(&blob->refcount, drm_property_free_blob, |
4130 | if (kref_put_mutex(&blob->refcount, drm_property_free_blob, |
4123 | &dev->mode_config.blob_lock)) |
4131 | &dev->mode_config.blob_lock)) |
4124 | mutex_unlock(&dev->mode_config.blob_lock); |
4132 | mutex_unlock(&dev->mode_config.blob_lock); |
4125 | else |
4133 | else |
4126 | might_lock(&dev->mode_config.blob_lock); |
4134 | might_lock(&dev->mode_config.blob_lock); |
4127 | } |
4135 | } |
4128 | EXPORT_SYMBOL(drm_property_unreference_blob); |
4136 | EXPORT_SYMBOL(drm_property_unreference_blob); |
4129 | 4137 | ||
4130 | /** |
4138 | /** |
4131 | * drm_property_unreference_blob_locked - Unreference a blob property with blob_lock held |
4139 | * drm_property_unreference_blob_locked - Unreference a blob property with blob_lock held |
4132 | * |
4140 | * |
4133 | * Drop a reference on a blob property. May free the object. This must be |
4141 | * Drop a reference on a blob property. May free the object. This must be |
4134 | * called with blob_lock held. |
4142 | * called with blob_lock held. |
4135 | * |
4143 | * |
4136 | * @blob: Pointer to blob property |
4144 | * @blob: Pointer to blob property |
4137 | */ |
4145 | */ |
4138 | static void drm_property_unreference_blob_locked(struct drm_property_blob *blob) |
4146 | static void drm_property_unreference_blob_locked(struct drm_property_blob *blob) |
4139 | { |
4147 | { |
4140 | if (!blob) |
4148 | if (!blob) |
4141 | return; |
4149 | return; |
4142 | 4150 | ||
4143 | DRM_DEBUG("%p: blob ID: %d (%d)\n", blob, blob->base.id, atomic_read(&blob->refcount.refcount)); |
4151 | DRM_DEBUG("%p: blob ID: %d (%d)\n", blob, blob->base.id, atomic_read(&blob->refcount.refcount)); |
4144 | 4152 | ||
4145 | kref_put(&blob->refcount, drm_property_free_blob); |
4153 | kref_put(&blob->refcount, drm_property_free_blob); |
4146 | } |
4154 | } |
4147 | 4155 | ||
4148 | /** |
4156 | /** |
4149 | * drm_property_destroy_user_blobs - destroy all blobs created by this client |
4157 | * drm_property_destroy_user_blobs - destroy all blobs created by this client |
4150 | * @dev: DRM device |
4158 | * @dev: DRM device |
4151 | * @file_priv: destroy all blobs owned by this file handle |
4159 | * @file_priv: destroy all blobs owned by this file handle |
4152 | */ |
4160 | */ |
4153 | void drm_property_destroy_user_blobs(struct drm_device *dev, |
4161 | void drm_property_destroy_user_blobs(struct drm_device *dev, |
4154 | struct drm_file *file_priv) |
4162 | struct drm_file *file_priv) |
4155 | { |
4163 | { |
4156 | struct drm_property_blob *blob, *bt; |
4164 | struct drm_property_blob *blob, *bt; |
4157 | 4165 | ||
4158 | mutex_lock(&dev->mode_config.blob_lock); |
4166 | mutex_lock(&dev->mode_config.blob_lock); |
4159 | 4167 | ||
4160 | list_for_each_entry_safe(blob, bt, &file_priv->blobs, head_file) { |
4168 | list_for_each_entry_safe(blob, bt, &file_priv->blobs, head_file) { |
4161 | list_del_init(&blob->head_file); |
4169 | list_del_init(&blob->head_file); |
4162 | drm_property_unreference_blob_locked(blob); |
4170 | drm_property_unreference_blob_locked(blob); |
4163 | } |
4171 | } |
4164 | 4172 | ||
4165 | mutex_unlock(&dev->mode_config.blob_lock); |
4173 | mutex_unlock(&dev->mode_config.blob_lock); |
4166 | } |
4174 | } |
4167 | 4175 | ||
4168 | /** |
4176 | /** |
4169 | * drm_property_reference_blob - Take a reference on an existing property |
4177 | * drm_property_reference_blob - Take a reference on an existing property |
4170 | * |
4178 | * |
4171 | * Take a new reference on an existing blob property. |
4179 | * Take a new reference on an existing blob property. |
4172 | * |
4180 | * |
4173 | * @blob: Pointer to blob property |
4181 | * @blob: Pointer to blob property |
4174 | */ |
4182 | */ |
4175 | struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob) |
4183 | struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob) |
4176 | { |
4184 | { |
4177 | DRM_DEBUG("%p: blob ID: %d (%d)\n", blob, blob->base.id, atomic_read(&blob->refcount.refcount)); |
4185 | DRM_DEBUG("%p: blob ID: %d (%d)\n", blob, blob->base.id, atomic_read(&blob->refcount.refcount)); |
4178 | kref_get(&blob->refcount); |
4186 | kref_get(&blob->refcount); |
4179 | return blob; |
4187 | return blob; |
4180 | } |
4188 | } |
4181 | EXPORT_SYMBOL(drm_property_reference_blob); |
4189 | EXPORT_SYMBOL(drm_property_reference_blob); |
4182 | 4190 | ||
4183 | /* |
4191 | /* |
4184 | * Like drm_property_lookup_blob, but does not return an additional reference. |
4192 | * Like drm_property_lookup_blob, but does not return an additional reference. |
4185 | * Must be called with blob_lock held. |
4193 | * Must be called with blob_lock held. |
4186 | */ |
4194 | */ |
4187 | static struct drm_property_blob *__drm_property_lookup_blob(struct drm_device *dev, |
4195 | static struct drm_property_blob *__drm_property_lookup_blob(struct drm_device *dev, |
4188 | uint32_t id) |
4196 | uint32_t id) |
4189 | { |
4197 | { |
4190 | struct drm_mode_object *obj = NULL; |
4198 | struct drm_mode_object *obj = NULL; |
4191 | struct drm_property_blob *blob; |
4199 | struct drm_property_blob *blob; |
4192 | 4200 | ||
4193 | WARN_ON(!mutex_is_locked(&dev->mode_config.blob_lock)); |
4201 | WARN_ON(!mutex_is_locked(&dev->mode_config.blob_lock)); |
4194 | 4202 | ||
4195 | mutex_lock(&dev->mode_config.idr_mutex); |
4203 | mutex_lock(&dev->mode_config.idr_mutex); |
4196 | obj = idr_find(&dev->mode_config.crtc_idr, id); |
4204 | obj = idr_find(&dev->mode_config.crtc_idr, id); |
4197 | if (!obj || (obj->type != DRM_MODE_OBJECT_BLOB) || (obj->id != id)) |
4205 | if (!obj || (obj->type != DRM_MODE_OBJECT_BLOB) || (obj->id != id)) |
4198 | blob = NULL; |
4206 | blob = NULL; |
4199 | else |
4207 | else |
4200 | blob = obj_to_blob(obj); |
4208 | blob = obj_to_blob(obj); |
4201 | mutex_unlock(&dev->mode_config.idr_mutex); |
4209 | mutex_unlock(&dev->mode_config.idr_mutex); |
4202 | 4210 | ||
4203 | return blob; |
4211 | return blob; |
4204 | } |
4212 | } |
4205 | 4213 | ||
4206 | /** |
4214 | /** |
4207 | * drm_property_lookup_blob - look up a blob property and take a reference |
4215 | * drm_property_lookup_blob - look up a blob property and take a reference |
4208 | * @dev: drm device |
4216 | * @dev: drm device |
4209 | * @id: id of the blob property |
4217 | * @id: id of the blob property |
4210 | * |
4218 | * |
4211 | * If successful, this takes an additional reference to the blob property. |
4219 | * If successful, this takes an additional reference to the blob property. |
4212 | * callers need to make sure to eventually unreference the returned property |
4220 | * callers need to make sure to eventually unreference the returned property |
4213 | * again, using @drm_property_unreference_blob. |
4221 | * again, using @drm_property_unreference_blob. |
4214 | */ |
4222 | */ |
4215 | struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev, |
4223 | struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev, |
4216 | uint32_t id) |
4224 | uint32_t id) |
4217 | { |
4225 | { |
4218 | struct drm_property_blob *blob; |
4226 | struct drm_property_blob *blob; |
4219 | 4227 | ||
4220 | mutex_lock(&dev->mode_config.blob_lock); |
4228 | mutex_lock(&dev->mode_config.blob_lock); |
4221 | blob = __drm_property_lookup_blob(dev, id); |
4229 | blob = __drm_property_lookup_blob(dev, id); |
4222 | if (blob) { |
4230 | if (blob) { |
4223 | if (!kref_get_unless_zero(&blob->refcount)) |
4231 | if (!kref_get_unless_zero(&blob->refcount)) |
4224 | blob = NULL; |
4232 | blob = NULL; |
4225 | } |
4233 | } |
4226 | mutex_unlock(&dev->mode_config.blob_lock); |
4234 | mutex_unlock(&dev->mode_config.blob_lock); |
4227 | 4235 | ||
4228 | return blob; |
4236 | return blob; |
4229 | } |
4237 | } |
4230 | EXPORT_SYMBOL(drm_property_lookup_blob); |
4238 | EXPORT_SYMBOL(drm_property_lookup_blob); |
4231 | 4239 | ||
4232 | /** |
4240 | /** |
4233 | * drm_property_replace_global_blob - atomically replace existing blob property |
4241 | * drm_property_replace_global_blob - atomically replace existing blob property |
4234 | * @dev: drm device |
4242 | * @dev: drm device |
4235 | * @replace: location of blob property pointer to be replaced |
4243 | * @replace: location of blob property pointer to be replaced |
4236 | * @length: length of data for new blob, or 0 for no data |
4244 | * @length: length of data for new blob, or 0 for no data |
4237 | * @data: content for new blob, or NULL for no data |
4245 | * @data: content for new blob, or NULL for no data |
4238 | * @obj_holds_id: optional object for property holding blob ID |
4246 | * @obj_holds_id: optional object for property holding blob ID |
4239 | * @prop_holds_id: optional property holding blob ID |
4247 | * @prop_holds_id: optional property holding blob ID |
4240 | * @return 0 on success or error on failure |
4248 | * @return 0 on success or error on failure |
4241 | * |
4249 | * |
4242 | * This function will atomically replace a global property in the blob list, |
4250 | * This function will atomically replace a global property in the blob list, |
4243 | * optionally updating a property which holds the ID of that property. It is |
4251 | * optionally updating a property which holds the ID of that property. It is |
4244 | * guaranteed to be atomic: no caller will be allowed to see intermediate |
4252 | * guaranteed to be atomic: no caller will be allowed to see intermediate |
4245 | * results, and either the entire operation will succeed and clean up the |
4253 | * results, and either the entire operation will succeed and clean up the |
4246 | * previous property, or it will fail and the state will be unchanged. |
4254 | * previous property, or it will fail and the state will be unchanged. |
4247 | * |
4255 | * |
4248 | * If length is 0 or data is NULL, no new blob will be created, and the holding |
4256 | * If length is 0 or data is NULL, no new blob will be created, and the holding |
4249 | * property, if specified, will be set to 0. |
4257 | * property, if specified, will be set to 0. |
4250 | * |
4258 | * |
4251 | * Access to the replace pointer is assumed to be protected by the caller, e.g. |
4259 | * Access to the replace pointer is assumed to be protected by the caller, e.g. |
4252 | * by holding the relevant modesetting object lock for its parent. |
4260 | * by holding the relevant modesetting object lock for its parent. |
4253 | * |
4261 | * |
4254 | * For example, a drm_connector has a 'PATH' property, which contains the ID |
4262 | * For example, a drm_connector has a 'PATH' property, which contains the ID |
4255 | * of a blob property with the value of the MST path information. Calling this |
4263 | * of a blob property with the value of the MST path information. Calling this |
4256 | * function with replace pointing to the connector's path_blob_ptr, length and |
4264 | * function with replace pointing to the connector's path_blob_ptr, length and |
4257 | * data set for the new path information, obj_holds_id set to the connector's |
4265 | * data set for the new path information, obj_holds_id set to the connector's |
4258 | * base object, and prop_holds_id set to the path property name, will perform |
4266 | * base object, and prop_holds_id set to the path property name, will perform |
4259 | * a completely atomic update. The access to path_blob_ptr is protected by the |
4267 | * a completely atomic update. The access to path_blob_ptr is protected by the |
4260 | * caller holding a lock on the connector. |
4268 | * caller holding a lock on the connector. |
4261 | */ |
4269 | */ |
4262 | static int drm_property_replace_global_blob(struct drm_device *dev, |
4270 | static int drm_property_replace_global_blob(struct drm_device *dev, |
4263 | struct drm_property_blob **replace, |
4271 | struct drm_property_blob **replace, |
4264 | size_t length, |
4272 | size_t length, |
4265 | const void *data, |
4273 | const void *data, |
4266 | struct drm_mode_object *obj_holds_id, |
4274 | struct drm_mode_object *obj_holds_id, |
4267 | struct drm_property *prop_holds_id) |
4275 | struct drm_property *prop_holds_id) |
4268 | { |
4276 | { |
4269 | struct drm_property_blob *new_blob = NULL; |
4277 | struct drm_property_blob *new_blob = NULL; |
4270 | struct drm_property_blob *old_blob = NULL; |
4278 | struct drm_property_blob *old_blob = NULL; |
4271 | int ret; |
4279 | int ret; |
4272 | 4280 | ||
4273 | WARN_ON(replace == NULL); |
4281 | WARN_ON(replace == NULL); |
4274 | 4282 | ||
4275 | old_blob = *replace; |
4283 | old_blob = *replace; |
4276 | 4284 | ||
4277 | if (length && data) { |
4285 | if (length && data) { |
4278 | new_blob = drm_property_create_blob(dev, length, data); |
4286 | new_blob = drm_property_create_blob(dev, length, data); |
4279 | if (IS_ERR(new_blob)) |
4287 | if (IS_ERR(new_blob)) |
4280 | return PTR_ERR(new_blob); |
4288 | return PTR_ERR(new_blob); |
4281 | } |
4289 | } |
4282 | 4290 | ||
4283 | /* This does not need to be synchronised with blob_lock, as the |
4291 | /* This does not need to be synchronised with blob_lock, as the |
4284 | * get_properties ioctl locks all modesetting objects, and |
4292 | * get_properties ioctl locks all modesetting objects, and |
4285 | * obj_holds_id must be locked before calling here, so we cannot |
4293 | * obj_holds_id must be locked before calling here, so we cannot |
4286 | * have its value out of sync with the list membership modified |
4294 | * have its value out of sync with the list membership modified |
4287 | * below under blob_lock. */ |
4295 | * below under blob_lock. */ |
4288 | if (obj_holds_id) { |
4296 | if (obj_holds_id) { |
4289 | ret = drm_object_property_set_value(obj_holds_id, |
4297 | ret = drm_object_property_set_value(obj_holds_id, |
4290 | prop_holds_id, |
4298 | prop_holds_id, |
4291 | new_blob ? |
4299 | new_blob ? |
4292 | new_blob->base.id : 0); |
4300 | new_blob->base.id : 0); |
4293 | if (ret != 0) |
4301 | if (ret != 0) |
4294 | goto err_created; |
4302 | goto err_created; |
4295 | } |
4303 | } |
4296 | 4304 | ||
4297 | drm_property_unreference_blob(old_blob); |
4305 | drm_property_unreference_blob(old_blob); |
4298 | *replace = new_blob; |
4306 | *replace = new_blob; |
4299 | 4307 | ||
4300 | return 0; |
4308 | return 0; |
4301 | 4309 | ||
4302 | err_created: |
4310 | err_created: |
4303 | drm_property_unreference_blob(new_blob); |
4311 | drm_property_unreference_blob(new_blob); |
4304 | return ret; |
4312 | return ret; |
4305 | } |
4313 | } |
4306 | 4314 | ||
4307 | 4315 | ||
4308 | #if 0 |
4316 | #if 0 |
4309 | /** |
4317 | /** |
4310 | * drm_mode_getblob_ioctl - get the contents of a blob property value |
4318 | * drm_mode_getblob_ioctl - get the contents of a blob property value |
4311 | * @dev: DRM device |
4319 | * @dev: DRM device |
4312 | * @data: ioctl data |
4320 | * @data: ioctl data |
4313 | * @file_priv: DRM file info |
4321 | * @file_priv: DRM file info |
4314 | * |
4322 | * |
4315 | * This function retrieves the contents of a blob property. The value stored in |
4323 | * This function retrieves the contents of a blob property. The value stored in |
4316 | * an object's blob property is just a normal modeset object id. |
4324 | * an object's blob property is just a normal modeset object id. |
4317 | * |
4325 | * |
4318 | * Called by the user via ioctl. |
4326 | * Called by the user via ioctl. |
4319 | * |
4327 | * |
4320 | * Returns: |
4328 | * Returns: |
4321 | * Zero on success, negative errno on failure. |
4329 | * Zero on success, negative errno on failure. |
4322 | */ |
4330 | */ |
4323 | int drm_mode_getblob_ioctl(struct drm_device *dev, |
4331 | int drm_mode_getblob_ioctl(struct drm_device *dev, |
4324 | void *data, struct drm_file *file_priv) |
4332 | void *data, struct drm_file *file_priv) |
4325 | { |
4333 | { |
4326 | struct drm_mode_get_blob *out_resp = data; |
4334 | struct drm_mode_get_blob *out_resp = data; |
4327 | struct drm_property_blob *blob; |
4335 | struct drm_property_blob *blob; |
4328 | int ret = 0; |
4336 | int ret = 0; |
4329 | void __user *blob_ptr; |
4337 | void __user *blob_ptr; |
4330 | 4338 | ||
4331 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
4339 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
4332 | return -EINVAL; |
4340 | return -EINVAL; |
4333 | 4341 | ||
4334 | drm_modeset_lock_all(dev); |
4342 | drm_modeset_lock_all(dev); |
4335 | mutex_lock(&dev->mode_config.blob_lock); |
4343 | mutex_lock(&dev->mode_config.blob_lock); |
4336 | blob = __drm_property_lookup_blob(dev, out_resp->blob_id); |
4344 | blob = __drm_property_lookup_blob(dev, out_resp->blob_id); |
4337 | if (!blob) { |
4345 | if (!blob) { |
4338 | ret = -ENOENT; |
4346 | ret = -ENOENT; |
4339 | goto done; |
4347 | goto done; |
4340 | } |
4348 | } |
4341 | 4349 | ||
4342 | if (out_resp->length == blob->length) { |
4350 | if (out_resp->length == blob->length) { |
4343 | blob_ptr = (void __user *)(unsigned long)out_resp->data; |
4351 | blob_ptr = (void __user *)(unsigned long)out_resp->data; |
4344 | if (copy_to_user(blob_ptr, blob->data, blob->length)) { |
4352 | if (copy_to_user(blob_ptr, blob->data, blob->length)) { |
4345 | ret = -EFAULT; |
4353 | ret = -EFAULT; |
4346 | goto done; |
4354 | goto done; |
4347 | } |
4355 | } |
4348 | } |
4356 | } |
4349 | out_resp->length = blob->length; |
4357 | out_resp->length = blob->length; |
4350 | 4358 | ||
4351 | done: |
4359 | done: |
4352 | mutex_unlock(&dev->mode_config.blob_lock); |
4360 | mutex_unlock(&dev->mode_config.blob_lock); |
4353 | drm_modeset_unlock_all(dev); |
4361 | drm_modeset_unlock_all(dev); |
4354 | return ret; |
4362 | return ret; |
4355 | } |
4363 | } |
4356 | #endif |
4364 | #endif |
4357 | 4365 | ||
4358 | /** |
4366 | /** |
4359 | * drm_mode_connector_set_path_property - set tile property on connector |
4367 | * drm_mode_connector_set_path_property - set tile property on connector |
4360 | * @connector: connector to set property on. |
4368 | * @connector: connector to set property on. |
4361 | * @path: path to use for property; must not be NULL. |
4369 | * @path: path to use for property; must not be NULL. |
4362 | * |
4370 | * |
4363 | * This creates a property to expose to userspace to specify a |
4371 | * This creates a property to expose to userspace to specify a |
4364 | * connector path. This is mainly used for DisplayPort MST where |
4372 | * connector path. This is mainly used for DisplayPort MST where |
4365 | * connectors have a topology and we want to allow userspace to give |
4373 | * connectors have a topology and we want to allow userspace to give |
4366 | * them more meaningful names. |
4374 | * them more meaningful names. |
4367 | * |
4375 | * |
4368 | * Returns: |
4376 | * Returns: |
4369 | * Zero on success, negative errno on failure. |
4377 | * Zero on success, negative errno on failure. |
4370 | */ |
4378 | */ |
4371 | int drm_mode_connector_set_path_property(struct drm_connector *connector, |
4379 | int drm_mode_connector_set_path_property(struct drm_connector *connector, |
4372 | const char *path) |
4380 | const char *path) |
4373 | { |
4381 | { |
4374 | struct drm_device *dev = connector->dev; |
4382 | struct drm_device *dev = connector->dev; |
4375 | int ret; |
4383 | int ret; |
4376 | 4384 | ||
4377 | ret = drm_property_replace_global_blob(dev, |
4385 | ret = drm_property_replace_global_blob(dev, |
4378 | &connector->path_blob_ptr, |
4386 | &connector->path_blob_ptr, |
4379 | strlen(path) + 1, |
4387 | strlen(path) + 1, |
4380 | path, |
4388 | path, |
4381 | &connector->base, |
4389 | &connector->base, |
4382 | dev->mode_config.path_property); |
4390 | dev->mode_config.path_property); |
4383 | return ret; |
4391 | return ret; |
4384 | } |
4392 | } |
4385 | EXPORT_SYMBOL(drm_mode_connector_set_path_property); |
4393 | EXPORT_SYMBOL(drm_mode_connector_set_path_property); |
4386 | 4394 | ||
4387 | /** |
4395 | /** |
4388 | * drm_mode_connector_set_tile_property - set tile property on connector |
4396 | * drm_mode_connector_set_tile_property - set tile property on connector |
4389 | * @connector: connector to set property on. |
4397 | * @connector: connector to set property on. |
4390 | * |
4398 | * |
4391 | * This looks up the tile information for a connector, and creates a |
4399 | * This looks up the tile information for a connector, and creates a |
4392 | * property for userspace to parse if it exists. The property is of |
4400 | * property for userspace to parse if it exists. The property is of |
4393 | * the form of 8 integers using ':' as a separator. |
4401 | * the form of 8 integers using ':' as a separator. |
4394 | * |
4402 | * |
4395 | * Returns: |
4403 | * Returns: |
4396 | * Zero on success, errno on failure. |
4404 | * Zero on success, errno on failure. |
4397 | */ |
4405 | */ |
4398 | int drm_mode_connector_set_tile_property(struct drm_connector *connector) |
4406 | int drm_mode_connector_set_tile_property(struct drm_connector *connector) |
4399 | { |
4407 | { |
4400 | struct drm_device *dev = connector->dev; |
4408 | struct drm_device *dev = connector->dev; |
4401 | char tile[256]; |
4409 | char tile[256]; |
4402 | int ret; |
4410 | int ret; |
4403 | 4411 | ||
4404 | if (!connector->has_tile) { |
4412 | if (!connector->has_tile) { |
4405 | ret = drm_property_replace_global_blob(dev, |
4413 | ret = drm_property_replace_global_blob(dev, |
4406 | &connector->tile_blob_ptr, |
4414 | &connector->tile_blob_ptr, |
4407 | 0, |
4415 | 0, |
4408 | NULL, |
4416 | NULL, |
4409 | &connector->base, |
4417 | &connector->base, |
4410 | dev->mode_config.tile_property); |
4418 | dev->mode_config.tile_property); |
4411 | return ret; |
4419 | return ret; |
4412 | } |
4420 | } |
4413 | 4421 | ||
4414 | snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d", |
4422 | snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d", |
4415 | connector->tile_group->id, connector->tile_is_single_monitor, |
4423 | connector->tile_group->id, connector->tile_is_single_monitor, |
4416 | connector->num_h_tile, connector->num_v_tile, |
4424 | connector->num_h_tile, connector->num_v_tile, |
4417 | connector->tile_h_loc, connector->tile_v_loc, |
4425 | connector->tile_h_loc, connector->tile_v_loc, |
4418 | connector->tile_h_size, connector->tile_v_size); |
4426 | connector->tile_h_size, connector->tile_v_size); |
4419 | 4427 | ||
4420 | ret = drm_property_replace_global_blob(dev, |
4428 | ret = drm_property_replace_global_blob(dev, |
4421 | &connector->tile_blob_ptr, |
4429 | &connector->tile_blob_ptr, |
4422 | strlen(tile) + 1, |
4430 | strlen(tile) + 1, |
4423 | tile, |
4431 | tile, |
4424 | &connector->base, |
4432 | &connector->base, |
4425 | dev->mode_config.tile_property); |
4433 | dev->mode_config.tile_property); |
4426 | return ret; |
4434 | return ret; |
4427 | } |
4435 | } |
4428 | EXPORT_SYMBOL(drm_mode_connector_set_tile_property); |
4436 | EXPORT_SYMBOL(drm_mode_connector_set_tile_property); |
4429 | 4437 | ||
4430 | /** |
4438 | /** |
4431 | * drm_mode_connector_update_edid_property - update the edid property of a connector |
4439 | * drm_mode_connector_update_edid_property - update the edid property of a connector |
4432 | * @connector: drm connector |
4440 | * @connector: drm connector |
4433 | * @edid: new value of the edid property |
4441 | * @edid: new value of the edid property |
4434 | * |
4442 | * |
4435 | * This function creates a new blob modeset object and assigns its id to the |
4443 | * This function creates a new blob modeset object and assigns its id to the |
4436 | * connector's edid property. |
4444 | * connector's edid property. |
4437 | * |
4445 | * |
4438 | * Returns: |
4446 | * Returns: |
4439 | * Zero on success, negative errno on failure. |
4447 | * Zero on success, negative errno on failure. |
4440 | */ |
4448 | */ |
4441 | int drm_mode_connector_update_edid_property(struct drm_connector *connector, |
4449 | int drm_mode_connector_update_edid_property(struct drm_connector *connector, |
4442 | const struct edid *edid) |
4450 | const struct edid *edid) |
4443 | { |
4451 | { |
4444 | struct drm_device *dev = connector->dev; |
4452 | struct drm_device *dev = connector->dev; |
4445 | size_t size = 0; |
4453 | size_t size = 0; |
4446 | int ret; |
4454 | int ret; |
4447 | 4455 | ||
4448 | /* ignore requests to set edid when overridden */ |
4456 | /* ignore requests to set edid when overridden */ |
4449 | if (connector->override_edid) |
4457 | if (connector->override_edid) |
4450 | return 0; |
4458 | return 0; |
4451 | 4459 | ||
4452 | if (edid) |
4460 | if (edid) |
4453 | size = EDID_LENGTH * (1 + edid->extensions); |
4461 | size = EDID_LENGTH * (1 + edid->extensions); |
4454 | 4462 | ||
4455 | ret = drm_property_replace_global_blob(dev, |
4463 | ret = drm_property_replace_global_blob(dev, |
4456 | &connector->edid_blob_ptr, |
4464 | &connector->edid_blob_ptr, |
4457 | size, |
4465 | size, |
4458 | edid, |
4466 | edid, |
4459 | &connector->base, |
4467 | &connector->base, |
4460 | dev->mode_config.edid_property); |
4468 | dev->mode_config.edid_property); |
4461 | return ret; |
4469 | return ret; |
4462 | } |
4470 | } |
4463 | EXPORT_SYMBOL(drm_mode_connector_update_edid_property); |
4471 | EXPORT_SYMBOL(drm_mode_connector_update_edid_property); |
4464 | 4472 | ||
4465 | /* Some properties could refer to dynamic refcnt'd objects, or things that |
4473 | /* Some properties could refer to dynamic refcnt'd objects, or things that |
4466 | * need special locking to handle lifetime issues (ie. to ensure the prop |
4474 | * need special locking to handle lifetime issues (ie. to ensure the prop |
4467 | * value doesn't become invalid part way through the property update due to |
4475 | * value doesn't become invalid part way through the property update due to |
4468 | * race). The value returned by reference via 'obj' should be passed back |
4476 | * race). The value returned by reference via 'obj' should be passed back |
4469 | * to drm_property_change_valid_put() after the property is set (and the |
4477 | * to drm_property_change_valid_put() after the property is set (and the |
4470 | * object to which the property is attached has a chance to take it's own |
4478 | * object to which the property is attached has a chance to take it's own |
4471 | * reference). |
4479 | * reference). |
4472 | */ |
4480 | */ |
4473 | bool drm_property_change_valid_get(struct drm_property *property, |
4481 | bool drm_property_change_valid_get(struct drm_property *property, |
4474 | uint64_t value, struct drm_mode_object **ref) |
4482 | uint64_t value, struct drm_mode_object **ref) |
4475 | { |
4483 | { |
4476 | int i; |
4484 | int i; |
4477 | 4485 | ||
4478 | if (property->flags & DRM_MODE_PROP_IMMUTABLE) |
4486 | if (property->flags & DRM_MODE_PROP_IMMUTABLE) |
4479 | return false; |
4487 | return false; |
4480 | 4488 | ||
4481 | *ref = NULL; |
4489 | *ref = NULL; |
4482 | 4490 | ||
4483 | if (drm_property_type_is(property, DRM_MODE_PROP_RANGE)) { |
4491 | if (drm_property_type_is(property, DRM_MODE_PROP_RANGE)) { |
4484 | if (value < property->values[0] || value > property->values[1]) |
4492 | if (value < property->values[0] || value > property->values[1]) |
4485 | return false; |
4493 | return false; |
4486 | return true; |
4494 | return true; |
4487 | } else if (drm_property_type_is(property, DRM_MODE_PROP_SIGNED_RANGE)) { |
4495 | } else if (drm_property_type_is(property, DRM_MODE_PROP_SIGNED_RANGE)) { |
4488 | int64_t svalue = U642I64(value); |
4496 | int64_t svalue = U642I64(value); |
4489 | 4497 | ||
4490 | if (svalue < U642I64(property->values[0]) || |
4498 | if (svalue < U642I64(property->values[0]) || |
4491 | svalue > U642I64(property->values[1])) |
4499 | svalue > U642I64(property->values[1])) |
4492 | return false; |
4500 | return false; |
4493 | return true; |
4501 | return true; |
4494 | } else if (drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) { |
4502 | } else if (drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) { |
4495 | uint64_t valid_mask = 0; |
4503 | uint64_t valid_mask = 0; |
4496 | 4504 | ||
4497 | for (i = 0; i < property->num_values; i++) |
4505 | for (i = 0; i < property->num_values; i++) |
4498 | valid_mask |= (1ULL << property->values[i]); |
4506 | valid_mask |= (1ULL << property->values[i]); |
4499 | return !(value & ~valid_mask); |
4507 | return !(value & ~valid_mask); |
4500 | } else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) { |
4508 | } else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) { |
4501 | struct drm_property_blob *blob; |
4509 | struct drm_property_blob *blob; |
4502 | 4510 | ||
4503 | if (value == 0) |
4511 | if (value == 0) |
4504 | return true; |
4512 | return true; |
4505 | 4513 | ||
4506 | blob = drm_property_lookup_blob(property->dev, value); |
4514 | blob = drm_property_lookup_blob(property->dev, value); |
4507 | if (blob) { |
4515 | if (blob) { |
4508 | *ref = &blob->base; |
4516 | *ref = &blob->base; |
4509 | return true; |
4517 | return true; |
4510 | } else { |
4518 | } else { |
4511 | return false; |
4519 | return false; |
4512 | } |
4520 | } |
4513 | } else if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) { |
4521 | } else if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) { |
4514 | /* a zero value for an object property translates to null: */ |
4522 | /* a zero value for an object property translates to null: */ |
4515 | if (value == 0) |
4523 | if (value == 0) |
4516 | return true; |
4524 | return true; |
4517 | 4525 | ||
4518 | /* handle refcnt'd objects specially: */ |
4526 | /* handle refcnt'd objects specially: */ |
4519 | if (property->values[0] == DRM_MODE_OBJECT_FB) { |
4527 | if (property->values[0] == DRM_MODE_OBJECT_FB) { |
4520 | struct drm_framebuffer *fb; |
4528 | struct drm_framebuffer *fb; |
4521 | fb = drm_framebuffer_lookup(property->dev, value); |
4529 | fb = drm_framebuffer_lookup(property->dev, value); |
4522 | if (fb) { |
4530 | if (fb) { |
4523 | *ref = &fb->base; |
4531 | *ref = &fb->base; |
4524 | return true; |
4532 | return true; |
4525 | } else { |
4533 | } else { |
4526 | return false; |
4534 | return false; |
4527 | } |
4535 | } |
4528 | } else { |
4536 | } else { |
4529 | return _object_find(property->dev, value, property->values[0]) != NULL; |
4537 | return _object_find(property->dev, value, property->values[0]) != NULL; |
4530 | } |
4538 | } |
4531 | } |
4539 | } |
4532 | 4540 | ||
4533 | for (i = 0; i < property->num_values; i++) |
4541 | for (i = 0; i < property->num_values; i++) |
4534 | if (property->values[i] == value) |
4542 | if (property->values[i] == value) |
4535 | return true; |
4543 | return true; |
4536 | return false; |
4544 | return false; |
4537 | } |
4545 | } |
4538 | 4546 | ||
4539 | void drm_property_change_valid_put(struct drm_property *property, |
4547 | void drm_property_change_valid_put(struct drm_property *property, |
4540 | struct drm_mode_object *ref) |
4548 | struct drm_mode_object *ref) |
4541 | { |
4549 | { |
4542 | if (!ref) |
4550 | if (!ref) |
4543 | return; |
4551 | return; |
4544 | 4552 | ||
4545 | if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) { |
4553 | if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) { |
4546 | if (property->values[0] == DRM_MODE_OBJECT_FB) |
4554 | if (property->values[0] == DRM_MODE_OBJECT_FB) |
4547 | drm_framebuffer_unreference(obj_to_fb(ref)); |
4555 | drm_framebuffer_unreference(obj_to_fb(ref)); |
4548 | } else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) |
4556 | } else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) |
4549 | drm_property_unreference_blob(obj_to_blob(ref)); |
4557 | drm_property_unreference_blob(obj_to_blob(ref)); |
4550 | } |
4558 | } |
4551 | 4559 | ||
4552 | 4560 | ||
4553 | 4561 | ||
4554 | static int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj, |
4562 | static int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj, |
4555 | struct drm_property *property, |
4563 | struct drm_property *property, |
4556 | uint64_t value) |
4564 | uint64_t value) |
4557 | { |
4565 | { |
4558 | int ret = -EINVAL; |
4566 | int ret = -EINVAL; |
4559 | struct drm_connector *connector = obj_to_connector(obj); |
4567 | struct drm_connector *connector = obj_to_connector(obj); |
4560 | 4568 | ||
4561 | /* Do DPMS ourselves */ |
4569 | /* Do DPMS ourselves */ |
4562 | if (property == connector->dev->mode_config.dpms_property) { |
4570 | if (property == connector->dev->mode_config.dpms_property) { |
4563 | ret = 0; |
4571 | ret = 0; |
4564 | if (connector->funcs->dpms) |
4572 | if (connector->funcs->dpms) |
4565 | ret = (*connector->funcs->dpms)(connector, (int)value); |
4573 | ret = (*connector->funcs->dpms)(connector, (int)value); |
4566 | } else if (connector->funcs->set_property) |
4574 | } else if (connector->funcs->set_property) |
4567 | ret = connector->funcs->set_property(connector, property, value); |
4575 | ret = connector->funcs->set_property(connector, property, value); |
4568 | 4576 | ||
4569 | /* store the property value if successful */ |
4577 | /* store the property value if successful */ |
4570 | if (!ret) |
4578 | if (!ret) |
4571 | drm_object_property_set_value(&connector->base, property, value); |
4579 | drm_object_property_set_value(&connector->base, property, value); |
4572 | return ret; |
4580 | return ret; |
4573 | } |
4581 | } |
4574 | 4582 | ||
4575 | static int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj, |
4583 | static int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj, |
4576 | struct drm_property *property, |
4584 | struct drm_property *property, |
4577 | uint64_t value) |
4585 | uint64_t value) |
4578 | { |
4586 | { |
4579 | int ret = -EINVAL; |
4587 | int ret = -EINVAL; |
4580 | struct drm_crtc *crtc = obj_to_crtc(obj); |
4588 | struct drm_crtc *crtc = obj_to_crtc(obj); |
4581 | 4589 | ||
4582 | if (crtc->funcs->set_property) |
4590 | if (crtc->funcs->set_property) |
4583 | ret = crtc->funcs->set_property(crtc, property, value); |
4591 | ret = crtc->funcs->set_property(crtc, property, value); |
4584 | if (!ret) |
4592 | if (!ret) |
4585 | drm_object_property_set_value(obj, property, value); |
4593 | drm_object_property_set_value(obj, property, value); |
4586 | 4594 | ||
4587 | return ret; |
4595 | return ret; |
4588 | } |
4596 | } |
4589 | 4597 | ||
4590 | /** |
4598 | /** |
4591 | * drm_mode_plane_set_obj_prop - set the value of a property |
4599 | * drm_mode_plane_set_obj_prop - set the value of a property |
4592 | * @plane: drm plane object to set property value for |
4600 | * @plane: drm plane object to set property value for |
4593 | * @property: property to set |
4601 | * @property: property to set |
4594 | * @value: value the property should be set to |
4602 | * @value: value the property should be set to |
4595 | * |
4603 | * |
4596 | * This functions sets a given property on a given plane object. This function |
4604 | * This functions sets a given property on a given plane object. This function |
4597 | * calls the driver's ->set_property callback and changes the software state of |
4605 | * calls the driver's ->set_property callback and changes the software state of |
4598 | * the property if the callback succeeds. |
4606 | * the property if the callback succeeds. |
4599 | * |
4607 | * |
4600 | * Returns: |
4608 | * Returns: |
4601 | * Zero on success, error code on failure. |
4609 | * Zero on success, error code on failure. |
4602 | */ |
4610 | */ |
4603 | int drm_mode_plane_set_obj_prop(struct drm_plane *plane, |
4611 | int drm_mode_plane_set_obj_prop(struct drm_plane *plane, |
4604 | struct drm_property *property, |
4612 | struct drm_property *property, |
4605 | uint64_t value) |
4613 | uint64_t value) |
4606 | { |
4614 | { |
4607 | int ret = -EINVAL; |
4615 | int ret = -EINVAL; |
4608 | struct drm_mode_object *obj = &plane->base; |
4616 | struct drm_mode_object *obj = &plane->base; |
4609 | 4617 | ||
4610 | if (plane->funcs->set_property) |
4618 | if (plane->funcs->set_property) |
4611 | ret = plane->funcs->set_property(plane, property, value); |
4619 | ret = plane->funcs->set_property(plane, property, value); |
4612 | if (!ret) |
4620 | if (!ret) |
4613 | drm_object_property_set_value(obj, property, value); |
4621 | drm_object_property_set_value(obj, property, value); |
4614 | 4622 | ||
4615 | return ret; |
4623 | return ret; |
4616 | } |
4624 | } |
4617 | EXPORT_SYMBOL(drm_mode_plane_set_obj_prop); |
4625 | EXPORT_SYMBOL(drm_mode_plane_set_obj_prop); |
4618 | 4626 | ||
4619 | #if 0 |
4627 | #if 0 |
4620 | /** |
4628 | /** |
4621 | * drm_mode_obj_get_properties_ioctl - get the current value of a object's property |
4629 | * drm_mode_obj_get_properties_ioctl - get the current value of a object's property |
4622 | * @dev: DRM device |
4630 | * @dev: DRM device |
4623 | * @data: ioctl data |
4631 | * @data: ioctl data |
4624 | * @file_priv: DRM file info |
4632 | * @file_priv: DRM file info |
4625 | * |
4633 | * |
4626 | * This function retrieves the current value for an object's property. Compared |
4634 | * This function retrieves the current value for an object's property. Compared |
4627 | * to the connector specific ioctl this one is extended to also work on crtc and |
4635 | * to the connector specific ioctl this one is extended to also work on crtc and |
4628 | * plane objects. |
4636 | * plane objects. |
4629 | * |
4637 | * |
4630 | * Called by the user via ioctl. |
4638 | * Called by the user via ioctl. |
4631 | * |
4639 | * |
4632 | * Returns: |
4640 | * Returns: |
4633 | * Zero on success, negative errno on failure. |
4641 | * Zero on success, negative errno on failure. |
4634 | */ |
4642 | */ |
4635 | int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data, |
4643 | int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data, |
4636 | struct drm_file *file_priv) |
4644 | struct drm_file *file_priv) |
4637 | { |
4645 | { |
4638 | struct drm_mode_obj_get_properties *arg = data; |
4646 | struct drm_mode_obj_get_properties *arg = data; |
4639 | struct drm_mode_object *obj; |
4647 | struct drm_mode_object *obj; |
4640 | int ret = 0; |
4648 | int ret = 0; |
4641 | 4649 | ||
4642 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
4650 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
4643 | return -EINVAL; |
4651 | return -EINVAL; |
4644 | 4652 | ||
4645 | drm_modeset_lock_all(dev); |
4653 | drm_modeset_lock_all(dev); |
4646 | 4654 | ||
4647 | obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type); |
4655 | obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type); |
4648 | if (!obj) { |
4656 | if (!obj) { |
4649 | ret = -ENOENT; |
4657 | ret = -ENOENT; |
4650 | goto out; |
4658 | goto out; |
4651 | } |
4659 | } |
4652 | if (!obj->properties) { |
4660 | if (!obj->properties) { |
4653 | ret = -EINVAL; |
4661 | ret = -EINVAL; |
4654 | goto out; |
4662 | goto out; |
4655 | } |
4663 | } |
4656 | 4664 | ||
4657 | ret = get_properties(obj, file_priv->atomic, |
4665 | ret = get_properties(obj, file_priv->atomic, |
4658 | (uint32_t __user *)(unsigned long)(arg->props_ptr), |
4666 | (uint32_t __user *)(unsigned long)(arg->props_ptr), |
4659 | (uint64_t __user *)(unsigned long)(arg->prop_values_ptr), |
4667 | (uint64_t __user *)(unsigned long)(arg->prop_values_ptr), |
4660 | &arg->count_props); |
4668 | &arg->count_props); |
4661 | 4669 | ||
4662 | out: |
4670 | out: |
4663 | drm_modeset_unlock_all(dev); |
4671 | drm_modeset_unlock_all(dev); |
4664 | return ret; |
4672 | return ret; |
4665 | } |
4673 | } |
4666 | 4674 | ||
4667 | /** |
4675 | /** |
4668 | * drm_mode_obj_set_property_ioctl - set the current value of an object's property |
4676 | * drm_mode_obj_set_property_ioctl - set the current value of an object's property |
4669 | * @dev: DRM device |
4677 | * @dev: DRM device |
4670 | * @data: ioctl data |
4678 | * @data: ioctl data |
4671 | * @file_priv: DRM file info |
4679 | * @file_priv: DRM file info |
4672 | * |
4680 | * |
4673 | * This function sets the current value for an object's property. It also calls |
4681 | * This function sets the current value for an object's property. It also calls |
4674 | * into a driver's ->set_property callback to update the hardware state. |
4682 | * into a driver's ->set_property callback to update the hardware state. |
4675 | * Compared to the connector specific ioctl this one is extended to also work on |
4683 | * Compared to the connector specific ioctl this one is extended to also work on |
4676 | * crtc and plane objects. |
4684 | * crtc and plane objects. |
4677 | * |
4685 | * |
4678 | * Called by the user via ioctl. |
4686 | * Called by the user via ioctl. |
4679 | * |
4687 | * |
4680 | * Returns: |
4688 | * Returns: |
4681 | * Zero on success, negative errno on failure. |
4689 | * Zero on success, negative errno on failure. |
4682 | */ |
4690 | */ |
4683 | int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data, |
4691 | int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data, |
4684 | struct drm_file *file_priv) |
4692 | struct drm_file *file_priv) |
4685 | { |
4693 | { |
4686 | struct drm_mode_obj_set_property *arg = data; |
4694 | struct drm_mode_obj_set_property *arg = data; |
4687 | struct drm_mode_object *arg_obj; |
4695 | struct drm_mode_object *arg_obj; |
4688 | struct drm_mode_object *prop_obj; |
4696 | struct drm_mode_object *prop_obj; |
4689 | struct drm_property *property; |
4697 | struct drm_property *property; |
4690 | int i, ret = -EINVAL; |
4698 | int i, ret = -EINVAL; |
4691 | struct drm_mode_object *ref; |
4699 | struct drm_mode_object *ref; |
4692 | 4700 | ||
4693 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
4701 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
4694 | return -EINVAL; |
4702 | return -EINVAL; |
4695 | 4703 | ||
4696 | drm_modeset_lock_all(dev); |
4704 | drm_modeset_lock_all(dev); |
4697 | 4705 | ||
4698 | arg_obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type); |
4706 | arg_obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type); |
4699 | if (!arg_obj) { |
4707 | if (!arg_obj) { |
4700 | ret = -ENOENT; |
4708 | ret = -ENOENT; |
4701 | goto out; |
4709 | goto out; |
4702 | } |
4710 | } |
4703 | if (!arg_obj->properties) |
4711 | if (!arg_obj->properties) |
4704 | goto out; |
4712 | goto out; |
4705 | 4713 | ||
4706 | for (i = 0; i < arg_obj->properties->count; i++) |
4714 | for (i = 0; i < arg_obj->properties->count; i++) |
4707 | if (arg_obj->properties->properties[i]->base.id == arg->prop_id) |
4715 | if (arg_obj->properties->properties[i]->base.id == arg->prop_id) |
4708 | break; |
4716 | break; |
4709 | 4717 | ||
4710 | if (i == arg_obj->properties->count) |
4718 | if (i == arg_obj->properties->count) |
4711 | goto out; |
4719 | goto out; |
4712 | 4720 | ||
4713 | prop_obj = drm_mode_object_find(dev, arg->prop_id, |
4721 | prop_obj = drm_mode_object_find(dev, arg->prop_id, |
4714 | DRM_MODE_OBJECT_PROPERTY); |
4722 | DRM_MODE_OBJECT_PROPERTY); |
4715 | if (!prop_obj) { |
4723 | if (!prop_obj) { |
4716 | ret = -ENOENT; |
4724 | ret = -ENOENT; |
4717 | goto out; |
4725 | goto out; |
4718 | } |
4726 | } |
4719 | property = obj_to_property(prop_obj); |
4727 | property = obj_to_property(prop_obj); |
4720 | 4728 | ||
4721 | if (!drm_property_change_valid_get(property, arg->value, &ref)) |
4729 | if (!drm_property_change_valid_get(property, arg->value, &ref)) |
4722 | goto out; |
4730 | goto out; |
4723 | 4731 | ||
4724 | switch (arg_obj->type) { |
4732 | switch (arg_obj->type) { |
4725 | case DRM_MODE_OBJECT_CONNECTOR: |
4733 | case DRM_MODE_OBJECT_CONNECTOR: |
4726 | ret = drm_mode_connector_set_obj_prop(arg_obj, property, |
4734 | ret = drm_mode_connector_set_obj_prop(arg_obj, property, |
4727 | arg->value); |
4735 | arg->value); |
4728 | break; |
4736 | break; |
4729 | case DRM_MODE_OBJECT_CRTC: |
4737 | case DRM_MODE_OBJECT_CRTC: |
4730 | ret = drm_mode_crtc_set_obj_prop(arg_obj, property, arg->value); |
4738 | ret = drm_mode_crtc_set_obj_prop(arg_obj, property, arg->value); |
4731 | break; |
4739 | break; |
4732 | case DRM_MODE_OBJECT_PLANE: |
4740 | case DRM_MODE_OBJECT_PLANE: |
4733 | ret = drm_mode_plane_set_obj_prop(obj_to_plane(arg_obj), |
4741 | ret = drm_mode_plane_set_obj_prop(obj_to_plane(arg_obj), |
4734 | property, arg->value); |
4742 | property, arg->value); |
4735 | break; |
4743 | break; |
4736 | } |
4744 | } |
4737 | 4745 | ||
4738 | drm_property_change_valid_put(property, ref); |
4746 | drm_property_change_valid_put(property, ref); |
4739 | 4747 | ||
4740 | out: |
4748 | out: |
4741 | drm_modeset_unlock_all(dev); |
4749 | drm_modeset_unlock_all(dev); |
4742 | return ret; |
4750 | return ret; |
4743 | } |
4751 | } |
4744 | #endif |
4752 | #endif |
4745 | 4753 | ||
4746 | /** |
4754 | /** |
4747 | * drm_mode_connector_attach_encoder - attach a connector to an encoder |
4755 | * drm_mode_connector_attach_encoder - attach a connector to an encoder |
4748 | * @connector: connector to attach |
4756 | * @connector: connector to attach |
4749 | * @encoder: encoder to attach @connector to |
4757 | * @encoder: encoder to attach @connector to |
4750 | * |
4758 | * |
4751 | * This function links up a connector to an encoder. Note that the routing |
4759 | * This function links up a connector to an encoder. Note that the routing |
4752 | * restrictions between encoders and crtcs are exposed to userspace through the |
4760 | * restrictions between encoders and crtcs are exposed to userspace through the |
4753 | * possible_clones and possible_crtcs bitmasks. |
4761 | * possible_clones and possible_crtcs bitmasks. |
4754 | * |
4762 | * |
4755 | * Returns: |
4763 | * Returns: |
4756 | * Zero on success, negative errno on failure. |
4764 | * Zero on success, negative errno on failure. |
4757 | */ |
4765 | */ |
4758 | int drm_mode_connector_attach_encoder(struct drm_connector *connector, |
4766 | int drm_mode_connector_attach_encoder(struct drm_connector *connector, |
4759 | struct drm_encoder *encoder) |
4767 | struct drm_encoder *encoder) |
4760 | { |
4768 | { |
4761 | int i; |
4769 | int i; |
4762 | 4770 | ||
4763 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
4771 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
4764 | if (connector->encoder_ids[i] == 0) { |
4772 | if (connector->encoder_ids[i] == 0) { |
4765 | connector->encoder_ids[i] = encoder->base.id; |
4773 | connector->encoder_ids[i] = encoder->base.id; |
4766 | return 0; |
4774 | return 0; |
4767 | } |
4775 | } |
4768 | } |
4776 | } |
4769 | return -ENOMEM; |
4777 | return -ENOMEM; |
4770 | } |
4778 | } |
4771 | EXPORT_SYMBOL(drm_mode_connector_attach_encoder); |
4779 | EXPORT_SYMBOL(drm_mode_connector_attach_encoder); |
4772 | 4780 | ||
4773 | /** |
4781 | /** |
4774 | * drm_mode_crtc_set_gamma_size - set the gamma table size |
4782 | * drm_mode_crtc_set_gamma_size - set the gamma table size |
4775 | * @crtc: CRTC to set the gamma table size for |
4783 | * @crtc: CRTC to set the gamma table size for |
4776 | * @gamma_size: size of the gamma table |
4784 | * @gamma_size: size of the gamma table |
4777 | * |
4785 | * |
4778 | * Drivers which support gamma tables should set this to the supported gamma |
4786 | * Drivers which support gamma tables should set this to the supported gamma |
4779 | * table size when initializing the CRTC. Currently the drm core only supports a |
4787 | * table size when initializing the CRTC. Currently the drm core only supports a |
4780 | * fixed gamma table size. |
4788 | * fixed gamma table size. |
4781 | * |
4789 | * |
4782 | * Returns: |
4790 | * Returns: |
4783 | * Zero on success, negative errno on failure. |
4791 | * Zero on success, negative errno on failure. |
4784 | */ |
4792 | */ |
4785 | int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, |
4793 | int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, |
4786 | int gamma_size) |
4794 | int gamma_size) |
4787 | { |
4795 | { |
4788 | crtc->gamma_size = gamma_size; |
4796 | crtc->gamma_size = gamma_size; |
4789 | 4797 | ||
4790 | crtc->gamma_store = kcalloc(gamma_size, sizeof(uint16_t) * 3, |
4798 | crtc->gamma_store = kcalloc(gamma_size, sizeof(uint16_t) * 3, |
4791 | GFP_KERNEL); |
4799 | GFP_KERNEL); |
4792 | if (!crtc->gamma_store) { |
4800 | if (!crtc->gamma_store) { |
4793 | crtc->gamma_size = 0; |
4801 | crtc->gamma_size = 0; |
4794 | return -ENOMEM; |
4802 | return -ENOMEM; |
4795 | } |
4803 | } |
4796 | 4804 | ||
4797 | return 0; |
4805 | return 0; |
4798 | } |
4806 | } |
4799 | EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size); |
4807 | EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size); |
4800 | 4808 | ||
4801 | #if 0 |
4809 | #if 0 |
4802 | /** |
4810 | /** |
4803 | * drm_mode_gamma_set_ioctl - set the gamma table |
4811 | * drm_mode_gamma_set_ioctl - set the gamma table |
4804 | * @dev: DRM device |
4812 | * @dev: DRM device |
4805 | * @data: ioctl data |
4813 | * @data: ioctl data |
4806 | * @file_priv: DRM file info |
4814 | * @file_priv: DRM file info |
4807 | * |
4815 | * |
4808 | * Set the gamma table of a CRTC to the one passed in by the user. Userspace can |
4816 | * Set the gamma table of a CRTC to the one passed in by the user. Userspace can |
4809 | * inquire the required gamma table size through drm_mode_gamma_get_ioctl. |
4817 | * inquire the required gamma table size through drm_mode_gamma_get_ioctl. |
4810 | * |
4818 | * |
4811 | * Called by the user via ioctl. |
4819 | * Called by the user via ioctl. |
4812 | * |
4820 | * |
4813 | * Returns: |
4821 | * Returns: |
4814 | * Zero on success, negative errno on failure. |
4822 | * Zero on success, negative errno on failure. |
4815 | */ |
4823 | */ |
4816 | int drm_mode_gamma_set_ioctl(struct drm_device *dev, |
4824 | int drm_mode_gamma_set_ioctl(struct drm_device *dev, |
4817 | void *data, struct drm_file *file_priv) |
4825 | void *data, struct drm_file *file_priv) |
4818 | { |
4826 | { |
4819 | struct drm_mode_crtc_lut *crtc_lut = data; |
4827 | struct drm_mode_crtc_lut *crtc_lut = data; |
4820 | struct drm_crtc *crtc; |
4828 | struct drm_crtc *crtc; |
4821 | void *r_base, *g_base, *b_base; |
4829 | void *r_base, *g_base, *b_base; |
4822 | int size; |
4830 | int size; |
4823 | int ret = 0; |
4831 | int ret = 0; |
4824 | 4832 | ||
4825 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
4833 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
4826 | return -EINVAL; |
4834 | return -EINVAL; |
4827 | 4835 | ||
4828 | drm_modeset_lock_all(dev); |
4836 | drm_modeset_lock_all(dev); |
4829 | crtc = drm_crtc_find(dev, crtc_lut->crtc_id); |
4837 | crtc = drm_crtc_find(dev, crtc_lut->crtc_id); |
4830 | if (!crtc) { |
4838 | if (!crtc) { |
4831 | ret = -ENOENT; |
4839 | ret = -ENOENT; |
4832 | goto out; |
4840 | goto out; |
4833 | } |
4841 | } |
4834 | 4842 | ||
4835 | if (crtc->funcs->gamma_set == NULL) { |
4843 | if (crtc->funcs->gamma_set == NULL) { |
4836 | ret = -ENOSYS; |
4844 | ret = -ENOSYS; |
4837 | goto out; |
4845 | goto out; |
4838 | } |
4846 | } |
4839 | 4847 | ||
4840 | /* memcpy into gamma store */ |
4848 | /* memcpy into gamma store */ |
4841 | if (crtc_lut->gamma_size != crtc->gamma_size) { |
4849 | if (crtc_lut->gamma_size != crtc->gamma_size) { |
4842 | ret = -EINVAL; |
4850 | ret = -EINVAL; |
4843 | goto out; |
4851 | goto out; |
4844 | } |
4852 | } |
4845 | 4853 | ||
4846 | size = crtc_lut->gamma_size * (sizeof(uint16_t)); |
4854 | size = crtc_lut->gamma_size * (sizeof(uint16_t)); |
4847 | r_base = crtc->gamma_store; |
4855 | r_base = crtc->gamma_store; |
4848 | if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) { |
4856 | if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) { |
4849 | ret = -EFAULT; |
4857 | ret = -EFAULT; |
4850 | goto out; |
4858 | goto out; |
4851 | } |
4859 | } |
4852 | 4860 | ||
4853 | g_base = r_base + size; |
4861 | g_base = r_base + size; |
4854 | if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) { |
4862 | if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) { |
4855 | ret = -EFAULT; |
4863 | ret = -EFAULT; |
4856 | goto out; |
4864 | goto out; |
4857 | } |
4865 | } |
4858 | 4866 | ||
4859 | b_base = g_base + size; |
4867 | b_base = g_base + size; |
4860 | if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) { |
4868 | if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) { |
4861 | ret = -EFAULT; |
4869 | ret = -EFAULT; |
4862 | goto out; |
4870 | goto out; |
4863 | } |
4871 | } |
4864 | 4872 | ||
4865 | crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size); |
4873 | crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size); |
4866 | 4874 | ||
4867 | out: |
4875 | out: |
4868 | drm_modeset_unlock_all(dev); |
4876 | drm_modeset_unlock_all(dev); |
4869 | return ret; |
4877 | return ret; |
4870 | 4878 | ||
4871 | } |
4879 | } |
4872 | 4880 | ||
4873 | /** |
4881 | /** |
4874 | * drm_mode_gamma_get_ioctl - get the gamma table |
4882 | * drm_mode_gamma_get_ioctl - get the gamma table |
4875 | * @dev: DRM device |
4883 | * @dev: DRM device |
4876 | * @data: ioctl data |
4884 | * @data: ioctl data |
4877 | * @file_priv: DRM file info |
4885 | * @file_priv: DRM file info |
4878 | * |
4886 | * |
4879 | * Copy the current gamma table into the storage provided. This also provides |
4887 | * Copy the current gamma table into the storage provided. This also provides |
4880 | * the gamma table size the driver expects, which can be used to size the |
4888 | * the gamma table size the driver expects, which can be used to size the |
4881 | * allocated storage. |
4889 | * allocated storage. |
4882 | * |
4890 | * |
4883 | * Called by the user via ioctl. |
4891 | * Called by the user via ioctl. |
4884 | * |
4892 | * |
4885 | * Returns: |
4893 | * Returns: |
4886 | * Zero on success, negative errno on failure. |
4894 | * Zero on success, negative errno on failure. |
4887 | */ |
4895 | */ |
4888 | int drm_mode_gamma_get_ioctl(struct drm_device *dev, |
4896 | int drm_mode_gamma_get_ioctl(struct drm_device *dev, |
4889 | void *data, struct drm_file *file_priv) |
4897 | void *data, struct drm_file *file_priv) |
4890 | { |
4898 | { |
4891 | struct drm_mode_crtc_lut *crtc_lut = data; |
4899 | struct drm_mode_crtc_lut *crtc_lut = data; |
4892 | struct drm_crtc *crtc; |
4900 | struct drm_crtc *crtc; |
4893 | void *r_base, *g_base, *b_base; |
4901 | void *r_base, *g_base, *b_base; |
4894 | int size; |
4902 | int size; |
4895 | int ret = 0; |
4903 | int ret = 0; |
4896 | 4904 | ||
4897 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
4905 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
4898 | return -EINVAL; |
4906 | return -EINVAL; |
4899 | 4907 | ||
4900 | drm_modeset_lock_all(dev); |
4908 | drm_modeset_lock_all(dev); |
4901 | crtc = drm_crtc_find(dev, crtc_lut->crtc_id); |
4909 | crtc = drm_crtc_find(dev, crtc_lut->crtc_id); |
4902 | if (!crtc) { |
4910 | if (!crtc) { |
4903 | ret = -ENOENT; |
4911 | ret = -ENOENT; |
4904 | goto out; |
4912 | goto out; |
4905 | } |
4913 | } |
4906 | 4914 | ||
4907 | /* memcpy into gamma store */ |
4915 | /* memcpy into gamma store */ |
4908 | if (crtc_lut->gamma_size != crtc->gamma_size) { |
4916 | if (crtc_lut->gamma_size != crtc->gamma_size) { |
4909 | ret = -EINVAL; |
4917 | ret = -EINVAL; |
4910 | goto out; |
4918 | goto out; |
4911 | } |
4919 | } |
4912 | 4920 | ||
4913 | size = crtc_lut->gamma_size * (sizeof(uint16_t)); |
4921 | size = crtc_lut->gamma_size * (sizeof(uint16_t)); |
4914 | r_base = crtc->gamma_store; |
4922 | r_base = crtc->gamma_store; |
4915 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) { |
4923 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) { |
4916 | ret = -EFAULT; |
4924 | ret = -EFAULT; |
4917 | goto out; |
4925 | goto out; |
4918 | } |
4926 | } |
4919 | 4927 | ||
4920 | g_base = r_base + size; |
4928 | g_base = r_base + size; |
4921 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) { |
4929 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) { |
4922 | ret = -EFAULT; |
4930 | ret = -EFAULT; |
4923 | goto out; |
4931 | goto out; |
4924 | } |
4932 | } |
4925 | 4933 | ||
4926 | b_base = g_base + size; |
4934 | b_base = g_base + size; |
4927 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) { |
4935 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) { |
4928 | ret = -EFAULT; |
4936 | ret = -EFAULT; |
4929 | goto out; |
4937 | goto out; |
4930 | } |
4938 | } |
4931 | out: |
4939 | out: |
4932 | drm_modeset_unlock_all(dev); |
4940 | drm_modeset_unlock_all(dev); |
4933 | return ret; |
4941 | return ret; |
4934 | } |
4942 | } |
4935 | 4943 | ||
4936 | #endif |
4944 | #endif |
4937 | 4945 | ||
4938 | 4946 | ||
4939 | /** |
4947 | /** |
4940 | * drm_mode_config_reset - call ->reset callbacks |
4948 | * drm_mode_config_reset - call ->reset callbacks |
4941 | * @dev: drm device |
4949 | * @dev: drm device |
4942 | * |
4950 | * |
4943 | * This functions calls all the crtc's, encoder's and connector's ->reset |
4951 | * This functions calls all the crtc's, encoder's and connector's ->reset |
4944 | * callback. Drivers can use this in e.g. their driver load or resume code to |
4952 | * callback. Drivers can use this in e.g. their driver load or resume code to |
4945 | * reset hardware and software state. |
4953 | * reset hardware and software state. |
4946 | */ |
4954 | */ |
4947 | void drm_mode_config_reset(struct drm_device *dev) |
4955 | void drm_mode_config_reset(struct drm_device *dev) |
4948 | { |
4956 | { |
4949 | struct drm_crtc *crtc; |
4957 | struct drm_crtc *crtc; |
4950 | struct drm_plane *plane; |
4958 | struct drm_plane *plane; |
4951 | struct drm_encoder *encoder; |
4959 | struct drm_encoder *encoder; |
4952 | struct drm_connector *connector; |
4960 | struct drm_connector *connector; |
4953 | 4961 | ||
4954 | drm_for_each_plane(plane, dev) |
4962 | drm_for_each_plane(plane, dev) |
4955 | if (plane->funcs->reset) |
4963 | if (plane->funcs->reset) |
4956 | plane->funcs->reset(plane); |
4964 | plane->funcs->reset(plane); |
4957 | 4965 | ||
4958 | drm_for_each_crtc(crtc, dev) |
4966 | drm_for_each_crtc(crtc, dev) |
4959 | if (crtc->funcs->reset) |
4967 | if (crtc->funcs->reset) |
4960 | crtc->funcs->reset(crtc); |
4968 | crtc->funcs->reset(crtc); |
4961 | 4969 | ||
4962 | drm_for_each_encoder(encoder, dev) |
4970 | drm_for_each_encoder(encoder, dev) |
4963 | if (encoder->funcs->reset) |
4971 | if (encoder->funcs->reset) |
4964 | encoder->funcs->reset(encoder); |
4972 | encoder->funcs->reset(encoder); |
4965 | 4973 | ||
4966 | mutex_lock(&dev->mode_config.mutex); |
4974 | mutex_lock(&dev->mode_config.mutex); |
4967 | drm_for_each_connector(connector, dev) |
4975 | drm_for_each_connector(connector, dev) |
4968 | if (connector->funcs->reset) |
4976 | if (connector->funcs->reset) |
4969 | connector->funcs->reset(connector); |
4977 | connector->funcs->reset(connector); |
4970 | mutex_unlock(&dev->mode_config.mutex); |
4978 | mutex_unlock(&dev->mode_config.mutex); |
4971 | } |
4979 | } |
4972 | EXPORT_SYMBOL(drm_mode_config_reset); |
4980 | EXPORT_SYMBOL(drm_mode_config_reset); |
4973 | /* |
4981 | /* |
4974 | * Just need to support RGB formats here for compat with code that doesn't |
4982 | * Just need to support RGB formats here for compat with code that doesn't |
4975 | * use pixel formats directly yet. |
4983 | * use pixel formats directly yet. |
4976 | */ |
4984 | */ |
4977 | void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, |
4985 | void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, |
4978 | int *bpp) |
4986 | int *bpp) |
4979 | { |
4987 | { |
4980 | switch (format) { |
4988 | switch (format) { |
4981 | case DRM_FORMAT_C8: |
4989 | case DRM_FORMAT_C8: |
4982 | case DRM_FORMAT_RGB332: |
4990 | case DRM_FORMAT_RGB332: |
4983 | case DRM_FORMAT_BGR233: |
4991 | case DRM_FORMAT_BGR233: |
4984 | *depth = 8; |
4992 | *depth = 8; |
4985 | *bpp = 8; |
4993 | *bpp = 8; |
4986 | break; |
4994 | break; |
4987 | case DRM_FORMAT_XRGB1555: |
4995 | case DRM_FORMAT_XRGB1555: |
4988 | case DRM_FORMAT_XBGR1555: |
4996 | case DRM_FORMAT_XBGR1555: |
4989 | case DRM_FORMAT_RGBX5551: |
4997 | case DRM_FORMAT_RGBX5551: |
4990 | case DRM_FORMAT_BGRX5551: |
4998 | case DRM_FORMAT_BGRX5551: |
4991 | case DRM_FORMAT_ARGB1555: |
4999 | case DRM_FORMAT_ARGB1555: |
4992 | case DRM_FORMAT_ABGR1555: |
5000 | case DRM_FORMAT_ABGR1555: |
4993 | case DRM_FORMAT_RGBA5551: |
5001 | case DRM_FORMAT_RGBA5551: |
4994 | case DRM_FORMAT_BGRA5551: |
5002 | case DRM_FORMAT_BGRA5551: |
4995 | *depth = 15; |
5003 | *depth = 15; |
4996 | *bpp = 16; |
5004 | *bpp = 16; |
4997 | break; |
5005 | break; |
4998 | case DRM_FORMAT_RGB565: |
5006 | case DRM_FORMAT_RGB565: |
4999 | case DRM_FORMAT_BGR565: |
5007 | case DRM_FORMAT_BGR565: |
5000 | *depth = 16; |
5008 | *depth = 16; |
5001 | *bpp = 16; |
5009 | *bpp = 16; |
5002 | break; |
5010 | break; |
5003 | case DRM_FORMAT_RGB888: |
5011 | case DRM_FORMAT_RGB888: |
5004 | case DRM_FORMAT_BGR888: |
5012 | case DRM_FORMAT_BGR888: |
5005 | *depth = 24; |
5013 | *depth = 24; |
5006 | *bpp = 24; |
5014 | *bpp = 24; |
5007 | break; |
5015 | break; |
5008 | case DRM_FORMAT_XRGB8888: |
5016 | case DRM_FORMAT_XRGB8888: |
5009 | case DRM_FORMAT_XBGR8888: |
5017 | case DRM_FORMAT_XBGR8888: |
5010 | case DRM_FORMAT_RGBX8888: |
5018 | case DRM_FORMAT_RGBX8888: |
5011 | case DRM_FORMAT_BGRX8888: |
5019 | case DRM_FORMAT_BGRX8888: |
5012 | *depth = 24; |
5020 | *depth = 24; |
5013 | *bpp = 32; |
5021 | *bpp = 32; |
5014 | break; |
5022 | break; |
5015 | case DRM_FORMAT_XRGB2101010: |
5023 | case DRM_FORMAT_XRGB2101010: |
5016 | case DRM_FORMAT_XBGR2101010: |
5024 | case DRM_FORMAT_XBGR2101010: |
5017 | case DRM_FORMAT_RGBX1010102: |
5025 | case DRM_FORMAT_RGBX1010102: |
5018 | case DRM_FORMAT_BGRX1010102: |
5026 | case DRM_FORMAT_BGRX1010102: |
5019 | case DRM_FORMAT_ARGB2101010: |
5027 | case DRM_FORMAT_ARGB2101010: |
5020 | case DRM_FORMAT_ABGR2101010: |
5028 | case DRM_FORMAT_ABGR2101010: |
5021 | case DRM_FORMAT_RGBA1010102: |
5029 | case DRM_FORMAT_RGBA1010102: |
5022 | case DRM_FORMAT_BGRA1010102: |
5030 | case DRM_FORMAT_BGRA1010102: |
5023 | *depth = 30; |
5031 | *depth = 30; |
5024 | *bpp = 32; |
5032 | *bpp = 32; |
5025 | break; |
5033 | break; |
5026 | case DRM_FORMAT_ARGB8888: |
5034 | case DRM_FORMAT_ARGB8888: |
5027 | case DRM_FORMAT_ABGR8888: |
5035 | case DRM_FORMAT_ABGR8888: |
5028 | case DRM_FORMAT_RGBA8888: |
5036 | case DRM_FORMAT_RGBA8888: |
5029 | case DRM_FORMAT_BGRA8888: |
5037 | case DRM_FORMAT_BGRA8888: |
5030 | *depth = 32; |
5038 | *depth = 32; |
5031 | *bpp = 32; |
5039 | *bpp = 32; |
5032 | break; |
5040 | break; |
5033 | default: |
5041 | default: |
5034 | DRM_DEBUG_KMS("unsupported pixel format %s\n", |
5042 | DRM_DEBUG_KMS("unsupported pixel format %s\n", |
5035 | drm_get_format_name(format)); |
5043 | drm_get_format_name(format)); |
5036 | *depth = 0; |
5044 | *depth = 0; |
5037 | *bpp = 0; |
5045 | *bpp = 0; |
5038 | break; |
5046 | break; |
5039 | } |
5047 | } |
5040 | } |
5048 | } |
5041 | EXPORT_SYMBOL(drm_fb_get_bpp_depth); |
5049 | EXPORT_SYMBOL(drm_fb_get_bpp_depth); |
5042 | 5050 | ||
5043 | /** |
5051 | /** |
5044 | * drm_format_num_planes - get the number of planes for format |
5052 | * drm_format_num_planes - get the number of planes for format |
5045 | * @format: pixel format (DRM_FORMAT_*) |
5053 | * @format: pixel format (DRM_FORMAT_*) |
5046 | * |
5054 | * |
5047 | * Returns: |
5055 | * Returns: |
5048 | * The number of planes used by the specified pixel format. |
5056 | * The number of planes used by the specified pixel format. |
5049 | */ |
5057 | */ |
5050 | int drm_format_num_planes(uint32_t format) |
5058 | int drm_format_num_planes(uint32_t format) |
5051 | { |
5059 | { |
5052 | switch (format) { |
5060 | switch (format) { |
5053 | case DRM_FORMAT_YUV410: |
5061 | case DRM_FORMAT_YUV410: |
5054 | case DRM_FORMAT_YVU410: |
5062 | case DRM_FORMAT_YVU410: |
5055 | case DRM_FORMAT_YUV411: |
5063 | case DRM_FORMAT_YUV411: |
5056 | case DRM_FORMAT_YVU411: |
5064 | case DRM_FORMAT_YVU411: |
5057 | case DRM_FORMAT_YUV420: |
5065 | case DRM_FORMAT_YUV420: |
5058 | case DRM_FORMAT_YVU420: |
5066 | case DRM_FORMAT_YVU420: |
5059 | case DRM_FORMAT_YUV422: |
5067 | case DRM_FORMAT_YUV422: |
5060 | case DRM_FORMAT_YVU422: |
5068 | case DRM_FORMAT_YVU422: |
5061 | case DRM_FORMAT_YUV444: |
5069 | case DRM_FORMAT_YUV444: |
5062 | case DRM_FORMAT_YVU444: |
5070 | case DRM_FORMAT_YVU444: |
5063 | return 3; |
5071 | return 3; |
5064 | case DRM_FORMAT_NV12: |
5072 | case DRM_FORMAT_NV12: |
5065 | case DRM_FORMAT_NV21: |
5073 | case DRM_FORMAT_NV21: |
5066 | case DRM_FORMAT_NV16: |
5074 | case DRM_FORMAT_NV16: |
5067 | case DRM_FORMAT_NV61: |
5075 | case DRM_FORMAT_NV61: |
5068 | case DRM_FORMAT_NV24: |
5076 | case DRM_FORMAT_NV24: |
5069 | case DRM_FORMAT_NV42: |
5077 | case DRM_FORMAT_NV42: |
5070 | return 2; |
5078 | return 2; |
5071 | default: |
5079 | default: |
5072 | return 1; |
5080 | return 1; |
5073 | } |
5081 | } |
5074 | } |
5082 | } |
5075 | EXPORT_SYMBOL(drm_format_num_planes); |
5083 | EXPORT_SYMBOL(drm_format_num_planes); |
5076 | 5084 | ||
5077 | /** |
5085 | /** |
5078 | * drm_format_plane_cpp - determine the bytes per pixel value |
5086 | * drm_format_plane_cpp - determine the bytes per pixel value |
5079 | * @format: pixel format (DRM_FORMAT_*) |
5087 | * @format: pixel format (DRM_FORMAT_*) |
5080 | * @plane: plane index |
5088 | * @plane: plane index |
5081 | * |
5089 | * |
5082 | * Returns: |
5090 | * Returns: |
5083 | * The bytes per pixel value for the specified plane. |
5091 | * The bytes per pixel value for the specified plane. |
5084 | */ |
5092 | */ |
5085 | int drm_format_plane_cpp(uint32_t format, int plane) |
5093 | int drm_format_plane_cpp(uint32_t format, int plane) |
5086 | { |
5094 | { |
5087 | unsigned int depth; |
5095 | unsigned int depth; |
5088 | int bpp; |
5096 | int bpp; |
5089 | 5097 | ||
5090 | if (plane >= drm_format_num_planes(format)) |
5098 | if (plane >= drm_format_num_planes(format)) |
5091 | return 0; |
5099 | return 0; |
5092 | 5100 | ||
5093 | switch (format) { |
5101 | switch (format) { |
5094 | case DRM_FORMAT_YUYV: |
5102 | case DRM_FORMAT_YUYV: |
5095 | case DRM_FORMAT_YVYU: |
5103 | case DRM_FORMAT_YVYU: |
5096 | case DRM_FORMAT_UYVY: |
5104 | case DRM_FORMAT_UYVY: |
5097 | case DRM_FORMAT_VYUY: |
5105 | case DRM_FORMAT_VYUY: |
5098 | return 2; |
5106 | return 2; |
5099 | case DRM_FORMAT_NV12: |
5107 | case DRM_FORMAT_NV12: |
5100 | case DRM_FORMAT_NV21: |
5108 | case DRM_FORMAT_NV21: |
5101 | case DRM_FORMAT_NV16: |
5109 | case DRM_FORMAT_NV16: |
5102 | case DRM_FORMAT_NV61: |
5110 | case DRM_FORMAT_NV61: |
5103 | case DRM_FORMAT_NV24: |
5111 | case DRM_FORMAT_NV24: |
5104 | case DRM_FORMAT_NV42: |
5112 | case DRM_FORMAT_NV42: |
5105 | return plane ? 2 : 1; |
5113 | return plane ? 2 : 1; |
5106 | case DRM_FORMAT_YUV410: |
5114 | case DRM_FORMAT_YUV410: |
5107 | case DRM_FORMAT_YVU410: |
5115 | case DRM_FORMAT_YVU410: |
5108 | case DRM_FORMAT_YUV411: |
5116 | case DRM_FORMAT_YUV411: |
5109 | case DRM_FORMAT_YVU411: |
5117 | case DRM_FORMAT_YVU411: |
5110 | case DRM_FORMAT_YUV420: |
5118 | case DRM_FORMAT_YUV420: |
5111 | case DRM_FORMAT_YVU420: |
5119 | case DRM_FORMAT_YVU420: |
5112 | case DRM_FORMAT_YUV422: |
5120 | case DRM_FORMAT_YUV422: |
5113 | case DRM_FORMAT_YVU422: |
5121 | case DRM_FORMAT_YVU422: |
5114 | case DRM_FORMAT_YUV444: |
5122 | case DRM_FORMAT_YUV444: |
5115 | case DRM_FORMAT_YVU444: |
5123 | case DRM_FORMAT_YVU444: |
5116 | return 1; |
5124 | return 1; |
5117 | default: |
5125 | default: |
5118 | drm_fb_get_bpp_depth(format, &depth, &bpp); |
5126 | drm_fb_get_bpp_depth(format, &depth, &bpp); |
5119 | return bpp >> 3; |
5127 | return bpp >> 3; |
5120 | } |
5128 | } |
5121 | } |
5129 | } |
5122 | EXPORT_SYMBOL(drm_format_plane_cpp); |
5130 | EXPORT_SYMBOL(drm_format_plane_cpp); |
5123 | 5131 | ||
5124 | /** |
5132 | /** |
5125 | * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor |
5133 | * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor |
5126 | * @format: pixel format (DRM_FORMAT_*) |
5134 | * @format: pixel format (DRM_FORMAT_*) |
5127 | * |
5135 | * |
5128 | * Returns: |
5136 | * Returns: |
5129 | * The horizontal chroma subsampling factor for the |
5137 | * The horizontal chroma subsampling factor for the |
5130 | * specified pixel format. |
5138 | * specified pixel format. |
5131 | */ |
5139 | */ |
5132 | int drm_format_horz_chroma_subsampling(uint32_t format) |
5140 | int drm_format_horz_chroma_subsampling(uint32_t format) |
5133 | { |
5141 | { |
5134 | switch (format) { |
5142 | switch (format) { |
5135 | case DRM_FORMAT_YUV411: |
5143 | case DRM_FORMAT_YUV411: |
5136 | case DRM_FORMAT_YVU411: |
5144 | case DRM_FORMAT_YVU411: |
5137 | case DRM_FORMAT_YUV410: |
5145 | case DRM_FORMAT_YUV410: |
5138 | case DRM_FORMAT_YVU410: |
5146 | case DRM_FORMAT_YVU410: |
5139 | return 4; |
5147 | return 4; |
5140 | case DRM_FORMAT_YUYV: |
5148 | case DRM_FORMAT_YUYV: |
5141 | case DRM_FORMAT_YVYU: |
5149 | case DRM_FORMAT_YVYU: |
5142 | case DRM_FORMAT_UYVY: |
5150 | case DRM_FORMAT_UYVY: |
5143 | case DRM_FORMAT_VYUY: |
5151 | case DRM_FORMAT_VYUY: |
5144 | case DRM_FORMAT_NV12: |
5152 | case DRM_FORMAT_NV12: |
5145 | case DRM_FORMAT_NV21: |
5153 | case DRM_FORMAT_NV21: |
5146 | case DRM_FORMAT_NV16: |
5154 | case DRM_FORMAT_NV16: |
5147 | case DRM_FORMAT_NV61: |
5155 | case DRM_FORMAT_NV61: |
5148 | case DRM_FORMAT_YUV422: |
5156 | case DRM_FORMAT_YUV422: |
5149 | case DRM_FORMAT_YVU422: |
5157 | case DRM_FORMAT_YVU422: |
5150 | case DRM_FORMAT_YUV420: |
5158 | case DRM_FORMAT_YUV420: |
5151 | case DRM_FORMAT_YVU420: |
5159 | case DRM_FORMAT_YVU420: |
5152 | return 2; |
5160 | return 2; |
5153 | default: |
5161 | default: |
5154 | return 1; |
5162 | return 1; |
5155 | } |
5163 | } |
5156 | } |
5164 | } |
5157 | EXPORT_SYMBOL(drm_format_horz_chroma_subsampling); |
5165 | EXPORT_SYMBOL(drm_format_horz_chroma_subsampling); |
5158 | 5166 | ||
5159 | /** |
5167 | /** |
5160 | * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor |
5168 | * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor |
5161 | * @format: pixel format (DRM_FORMAT_*) |
5169 | * @format: pixel format (DRM_FORMAT_*) |
5162 | * |
5170 | * |
5163 | * Returns: |
5171 | * Returns: |
5164 | * The vertical chroma subsampling factor for the |
5172 | * The vertical chroma subsampling factor for the |
5165 | * specified pixel format. |
5173 | * specified pixel format. |
5166 | */ |
5174 | */ |
5167 | int drm_format_vert_chroma_subsampling(uint32_t format) |
5175 | int drm_format_vert_chroma_subsampling(uint32_t format) |
5168 | { |
5176 | { |
5169 | switch (format) { |
5177 | switch (format) { |
5170 | case DRM_FORMAT_YUV410: |
5178 | case DRM_FORMAT_YUV410: |
5171 | case DRM_FORMAT_YVU410: |
5179 | case DRM_FORMAT_YVU410: |
5172 | return 4; |
5180 | return 4; |
5173 | case DRM_FORMAT_YUV420: |
5181 | case DRM_FORMAT_YUV420: |
5174 | case DRM_FORMAT_YVU420: |
5182 | case DRM_FORMAT_YVU420: |
5175 | case DRM_FORMAT_NV12: |
5183 | case DRM_FORMAT_NV12: |
5176 | case DRM_FORMAT_NV21: |
5184 | case DRM_FORMAT_NV21: |
5177 | return 2; |
5185 | return 2; |
5178 | default: |
5186 | default: |
5179 | return 1; |
5187 | return 1; |
5180 | } |
5188 | } |
5181 | } |
5189 | } |
5182 | EXPORT_SYMBOL(drm_format_vert_chroma_subsampling); |
5190 | EXPORT_SYMBOL(drm_format_vert_chroma_subsampling); |
5183 | 5191 | ||
5184 | /** |
5192 | /** |
5185 | * drm_rotation_simplify() - Try to simplify the rotation |
5193 | * drm_rotation_simplify() - Try to simplify the rotation |
5186 | * @rotation: Rotation to be simplified |
5194 | * @rotation: Rotation to be simplified |
5187 | * @supported_rotations: Supported rotations |
5195 | * @supported_rotations: Supported rotations |
5188 | * |
5196 | * |
5189 | * Attempt to simplify the rotation to a form that is supported. |
5197 | * Attempt to simplify the rotation to a form that is supported. |
5190 | * Eg. if the hardware supports everything except DRM_REFLECT_X |
5198 | * Eg. if the hardware supports everything except DRM_REFLECT_X |
5191 | * one could call this function like this: |
5199 | * one could call this function like this: |
5192 | * |
5200 | * |
5193 | * drm_rotation_simplify(rotation, BIT(DRM_ROTATE_0) | |
5201 | * drm_rotation_simplify(rotation, BIT(DRM_ROTATE_0) | |
5194 | * BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_180) | |
5202 | * BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_180) | |
5195 | * BIT(DRM_ROTATE_270) | BIT(DRM_REFLECT_Y)); |
5203 | * BIT(DRM_ROTATE_270) | BIT(DRM_REFLECT_Y)); |
5196 | * |
5204 | * |
5197 | * to eliminate the DRM_ROTATE_X flag. Depending on what kind of |
5205 | * to eliminate the DRM_ROTATE_X flag. Depending on what kind of |
5198 | * transforms the hardware supports, this function may not |
5206 | * transforms the hardware supports, this function may not |
5199 | * be able to produce a supported transform, so the caller should |
5207 | * be able to produce a supported transform, so the caller should |
5200 | * check the result afterwards. |
5208 | * check the result afterwards. |
5201 | */ |
5209 | */ |
5202 | unsigned int drm_rotation_simplify(unsigned int rotation, |
5210 | unsigned int drm_rotation_simplify(unsigned int rotation, |
5203 | unsigned int supported_rotations) |
5211 | unsigned int supported_rotations) |
5204 | { |
5212 | { |
5205 | if (rotation & ~supported_rotations) { |
5213 | if (rotation & ~supported_rotations) { |
5206 | rotation ^= BIT(DRM_REFLECT_X) | BIT(DRM_REFLECT_Y); |
5214 | rotation ^= BIT(DRM_REFLECT_X) | BIT(DRM_REFLECT_Y); |
5207 | rotation = (rotation & DRM_REFLECT_MASK) | |
5215 | rotation = (rotation & DRM_REFLECT_MASK) | |
5208 | BIT((ffs(rotation & DRM_ROTATE_MASK) + 1) % 4); |
5216 | BIT((ffs(rotation & DRM_ROTATE_MASK) + 1) % 4); |
5209 | } |
5217 | } |
5210 | 5218 | ||
5211 | return rotation; |
5219 | return rotation; |
5212 | } |
5220 | } |
5213 | EXPORT_SYMBOL(drm_rotation_simplify); |
5221 | EXPORT_SYMBOL(drm_rotation_simplify); |
5214 | 5222 | ||
5215 | /** |
5223 | /** |
5216 | * drm_mode_config_init - initialize DRM mode_configuration structure |
5224 | * drm_mode_config_init - initialize DRM mode_configuration structure |
5217 | * @dev: DRM device |
5225 | * @dev: DRM device |
5218 | * |
5226 | * |
5219 | * Initialize @dev's mode_config structure, used for tracking the graphics |
5227 | * Initialize @dev's mode_config structure, used for tracking the graphics |
5220 | * configuration of @dev. |
5228 | * configuration of @dev. |
5221 | * |
5229 | * |
5222 | * Since this initializes the modeset locks, no locking is possible. Which is no |
5230 | * Since this initializes the modeset locks, no locking is possible. Which is no |
5223 | * problem, since this should happen single threaded at init time. It is the |
5231 | * problem, since this should happen single threaded at init time. It is the |
5224 | * driver's problem to ensure this guarantee. |
5232 | * driver's problem to ensure this guarantee. |
5225 | * |
5233 | * |
5226 | */ |
5234 | */ |
5227 | void drm_mode_config_init(struct drm_device *dev) |
5235 | void drm_mode_config_init(struct drm_device *dev) |
5228 | { |
5236 | { |
5229 | mutex_init(&dev->mode_config.mutex); |
5237 | mutex_init(&dev->mode_config.mutex); |
5230 | drm_modeset_lock_init(&dev->mode_config.connection_mutex); |
5238 | drm_modeset_lock_init(&dev->mode_config.connection_mutex); |
5231 | mutex_init(&dev->mode_config.idr_mutex); |
5239 | mutex_init(&dev->mode_config.idr_mutex); |
5232 | mutex_init(&dev->mode_config.fb_lock); |
5240 | mutex_init(&dev->mode_config.fb_lock); |
5233 | mutex_init(&dev->mode_config.blob_lock); |
5241 | mutex_init(&dev->mode_config.blob_lock); |
5234 | INIT_LIST_HEAD(&dev->mode_config.fb_list); |
5242 | INIT_LIST_HEAD(&dev->mode_config.fb_list); |
5235 | INIT_LIST_HEAD(&dev->mode_config.crtc_list); |
5243 | INIT_LIST_HEAD(&dev->mode_config.crtc_list); |
5236 | INIT_LIST_HEAD(&dev->mode_config.connector_list); |
5244 | INIT_LIST_HEAD(&dev->mode_config.connector_list); |
5237 | INIT_LIST_HEAD(&dev->mode_config.encoder_list); |
5245 | INIT_LIST_HEAD(&dev->mode_config.encoder_list); |
5238 | INIT_LIST_HEAD(&dev->mode_config.property_list); |
5246 | INIT_LIST_HEAD(&dev->mode_config.property_list); |
5239 | INIT_LIST_HEAD(&dev->mode_config.property_blob_list); |
5247 | INIT_LIST_HEAD(&dev->mode_config.property_blob_list); |
5240 | INIT_LIST_HEAD(&dev->mode_config.plane_list); |
5248 | INIT_LIST_HEAD(&dev->mode_config.plane_list); |
5241 | idr_init(&dev->mode_config.crtc_idr); |
5249 | idr_init(&dev->mode_config.crtc_idr); |
5242 | idr_init(&dev->mode_config.tile_idr); |
5250 | idr_init(&dev->mode_config.tile_idr); |
5243 | 5251 | ||
5244 | drm_modeset_lock_all(dev); |
5252 | drm_modeset_lock_all(dev); |
5245 | drm_mode_create_standard_properties(dev); |
5253 | drm_mode_create_standard_properties(dev); |
5246 | drm_modeset_unlock_all(dev); |
5254 | drm_modeset_unlock_all(dev); |
5247 | 5255 | ||
5248 | /* Just to be sure */ |
5256 | /* Just to be sure */ |
5249 | dev->mode_config.num_fb = 0; |
5257 | dev->mode_config.num_fb = 0; |
5250 | dev->mode_config.num_connector = 0; |
5258 | dev->mode_config.num_connector = 0; |
5251 | dev->mode_config.num_crtc = 0; |
5259 | dev->mode_config.num_crtc = 0; |
5252 | dev->mode_config.num_encoder = 0; |
5260 | dev->mode_config.num_encoder = 0; |
5253 | dev->mode_config.num_overlay_plane = 0; |
5261 | dev->mode_config.num_overlay_plane = 0; |
5254 | dev->mode_config.num_total_plane = 0; |
5262 | dev->mode_config.num_total_plane = 0; |
5255 | } |
5263 | } |
5256 | EXPORT_SYMBOL(drm_mode_config_init); |
5264 | EXPORT_SYMBOL(drm_mode_config_init); |
5257 | 5265 | ||
5258 | /** |
5266 | /** |
5259 | * drm_mode_config_cleanup - free up DRM mode_config info |
5267 | * drm_mode_config_cleanup - free up DRM mode_config info |
5260 | * @dev: DRM device |
5268 | * @dev: DRM device |
5261 | * |
5269 | * |
5262 | * Free up all the connectors and CRTCs associated with this DRM device, then |
5270 | * Free up all the connectors and CRTCs associated with this DRM device, then |
5263 | * free up the framebuffers and associated buffer objects. |
5271 | * free up the framebuffers and associated buffer objects. |
5264 | * |
5272 | * |
5265 | * Note that since this /should/ happen single-threaded at driver/device |
5273 | * Note that since this /should/ happen single-threaded at driver/device |
5266 | * teardown time, no locking is required. It's the driver's job to ensure that |
5274 | * teardown time, no locking is required. It's the driver's job to ensure that |
5267 | * this guarantee actually holds true. |
5275 | * this guarantee actually holds true. |
5268 | * |
5276 | * |
5269 | * FIXME: cleanup any dangling user buffer objects too |
5277 | * FIXME: cleanup any dangling user buffer objects too |
5270 | */ |
5278 | */ |
5271 | void drm_mode_config_cleanup(struct drm_device *dev) |
5279 | void drm_mode_config_cleanup(struct drm_device *dev) |
5272 | { |
5280 | { |
5273 | struct drm_connector *connector, *ot; |
5281 | struct drm_connector *connector, *ot; |
5274 | struct drm_crtc *crtc, *ct; |
5282 | struct drm_crtc *crtc, *ct; |
5275 | struct drm_encoder *encoder, *enct; |
5283 | struct drm_encoder *encoder, *enct; |
5276 | struct drm_framebuffer *fb, *fbt; |
5284 | struct drm_framebuffer *fb, *fbt; |
5277 | struct drm_property *property, *pt; |
5285 | struct drm_property *property, *pt; |
5278 | struct drm_property_blob *blob, *bt; |
5286 | struct drm_property_blob *blob, *bt; |
5279 | struct drm_plane *plane, *plt; |
5287 | struct drm_plane *plane, *plt; |
5280 | 5288 | ||
5281 | list_for_each_entry_safe(encoder, enct, &dev->mode_config.encoder_list, |
5289 | list_for_each_entry_safe(encoder, enct, &dev->mode_config.encoder_list, |
5282 | head) { |
5290 | head) { |
5283 | encoder->funcs->destroy(encoder); |
5291 | encoder->funcs->destroy(encoder); |
5284 | } |
5292 | } |
5285 | 5293 | ||
5286 | list_for_each_entry_safe(connector, ot, |
5294 | list_for_each_entry_safe(connector, ot, |
5287 | &dev->mode_config.connector_list, head) { |
5295 | &dev->mode_config.connector_list, head) { |
5288 | connector->funcs->destroy(connector); |
5296 | connector->funcs->destroy(connector); |
5289 | } |
5297 | } |
5290 | 5298 | ||
5291 | list_for_each_entry_safe(property, pt, &dev->mode_config.property_list, |
5299 | list_for_each_entry_safe(property, pt, &dev->mode_config.property_list, |
5292 | head) { |
5300 | head) { |
5293 | drm_property_destroy(dev, property); |
5301 | drm_property_destroy(dev, property); |
5294 | } |
5302 | } |
5295 | 5303 | ||
5296 | list_for_each_entry_safe(blob, bt, &dev->mode_config.property_blob_list, |
5304 | list_for_each_entry_safe(blob, bt, &dev->mode_config.property_blob_list, |
5297 | head_global) { |
5305 | head_global) { |
5298 | drm_property_unreference_blob(blob); |
5306 | drm_property_unreference_blob(blob); |
5299 | } |
5307 | } |
5300 | 5308 | ||
5301 | /* |
5309 | /* |
5302 | * Single-threaded teardown context, so it's not required to grab the |
5310 | * Single-threaded teardown context, so it's not required to grab the |
5303 | * fb_lock to protect against concurrent fb_list access. Contrary, it |
5311 | * fb_lock to protect against concurrent fb_list access. Contrary, it |
5304 | * would actually deadlock with the drm_framebuffer_cleanup function. |
5312 | * would actually deadlock with the drm_framebuffer_cleanup function. |
5305 | * |
5313 | * |
5306 | * Also, if there are any framebuffers left, that's a driver leak now, |
5314 | * Also, if there are any framebuffers left, that's a driver leak now, |
5307 | * so politely WARN about this. |
5315 | * so politely WARN about this. |
5308 | */ |
5316 | */ |
5309 | WARN_ON(!list_empty(&dev->mode_config.fb_list)); |
5317 | WARN_ON(!list_empty(&dev->mode_config.fb_list)); |
5310 | list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) { |
5318 | list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) { |
5311 | drm_framebuffer_free(&fb->refcount); |
5319 | drm_framebuffer_free(&fb->refcount); |
5312 | } |
5320 | } |
5313 | 5321 | ||
5314 | list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list, |
5322 | list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list, |
5315 | head) { |
5323 | head) { |
5316 | plane->funcs->destroy(plane); |
5324 | plane->funcs->destroy(plane); |
5317 | } |
5325 | } |
5318 | 5326 | ||
5319 | list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) { |
5327 | list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) { |
5320 | crtc->funcs->destroy(crtc); |
5328 | crtc->funcs->destroy(crtc); |
5321 | } |
5329 | } |
5322 | 5330 | ||
5323 | idr_destroy(&dev->mode_config.tile_idr); |
5331 | idr_destroy(&dev->mode_config.tile_idr); |
5324 | idr_destroy(&dev->mode_config.crtc_idr); |
5332 | idr_destroy(&dev->mode_config.crtc_idr); |
5325 | drm_modeset_lock_fini(&dev->mode_config.connection_mutex); |
5333 | drm_modeset_lock_fini(&dev->mode_config.connection_mutex); |
5326 | } |
5334 | } |
5327 | EXPORT_SYMBOL(drm_mode_config_cleanup); |
5335 | EXPORT_SYMBOL(drm_mode_config_cleanup); |
5328 | 5336 | ||
5329 | struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev, |
5337 | struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev, |
5330 | unsigned int supported_rotations) |
5338 | unsigned int supported_rotations) |
5331 | { |
5339 | { |
5332 | static const struct drm_prop_enum_list props[] = { |
5340 | static const struct drm_prop_enum_list props[] = { |
5333 | { DRM_ROTATE_0, "rotate-0" }, |
5341 | { DRM_ROTATE_0, "rotate-0" }, |
5334 | { DRM_ROTATE_90, "rotate-90" }, |
5342 | { DRM_ROTATE_90, "rotate-90" }, |
5335 | { DRM_ROTATE_180, "rotate-180" }, |
5343 | { DRM_ROTATE_180, "rotate-180" }, |
5336 | { DRM_ROTATE_270, "rotate-270" }, |
5344 | { DRM_ROTATE_270, "rotate-270" }, |
5337 | { DRM_REFLECT_X, "reflect-x" }, |
5345 | { DRM_REFLECT_X, "reflect-x" }, |
5338 | { DRM_REFLECT_Y, "reflect-y" }, |
5346 | { DRM_REFLECT_Y, "reflect-y" }, |
5339 | }; |
5347 | }; |
5340 | 5348 | ||
5341 | return drm_property_create_bitmask(dev, 0, "rotation", |
5349 | return drm_property_create_bitmask(dev, 0, "rotation", |
5342 | props, ARRAY_SIZE(props), |
5350 | props, ARRAY_SIZE(props), |
5343 | supported_rotations); |
5351 | supported_rotations); |
5344 | } |
5352 | } |
5345 | EXPORT_SYMBOL(drm_mode_create_rotation_property); |
5353 | EXPORT_SYMBOL(drm_mode_create_rotation_property); |
5346 | 5354 | ||
5347 | /** |
5355 | /** |
5348 | * DOC: Tile group |
5356 | * DOC: Tile group |
5349 | * |
5357 | * |
5350 | * Tile groups are used to represent tiled monitors with a unique |
5358 | * Tile groups are used to represent tiled monitors with a unique |
5351 | * integer identifier. Tiled monitors using DisplayID v1.3 have |
5359 | * integer identifier. Tiled monitors using DisplayID v1.3 have |
5352 | * a unique 8-byte handle, we store this in a tile group, so we |
5360 | * a unique 8-byte handle, we store this in a tile group, so we |
5353 | * have a common identifier for all tiles in a monitor group. |
5361 | * have a common identifier for all tiles in a monitor group. |
5354 | */ |
5362 | */ |
5355 | static void drm_tile_group_free(struct kref *kref) |
5363 | static void drm_tile_group_free(struct kref *kref) |
5356 | { |
5364 | { |
5357 | struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount); |
5365 | struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount); |
5358 | struct drm_device *dev = tg->dev; |
5366 | struct drm_device *dev = tg->dev; |
5359 | mutex_lock(&dev->mode_config.idr_mutex); |
5367 | mutex_lock(&dev->mode_config.idr_mutex); |
5360 | idr_remove(&dev->mode_config.tile_idr, tg->id); |
5368 | idr_remove(&dev->mode_config.tile_idr, tg->id); |
5361 | mutex_unlock(&dev->mode_config.idr_mutex); |
5369 | mutex_unlock(&dev->mode_config.idr_mutex); |
5362 | kfree(tg); |
5370 | kfree(tg); |
5363 | } |
5371 | } |
5364 | 5372 | ||
5365 | /** |
5373 | /** |
5366 | * drm_mode_put_tile_group - drop a reference to a tile group. |
5374 | * drm_mode_put_tile_group - drop a reference to a tile group. |
5367 | * @dev: DRM device |
5375 | * @dev: DRM device |
5368 | * @tg: tile group to drop reference to. |
5376 | * @tg: tile group to drop reference to. |
5369 | * |
5377 | * |
5370 | * drop reference to tile group and free if 0. |
5378 | * drop reference to tile group and free if 0. |
5371 | */ |
5379 | */ |
5372 | void drm_mode_put_tile_group(struct drm_device *dev, |
5380 | void drm_mode_put_tile_group(struct drm_device *dev, |
5373 | struct drm_tile_group *tg) |
5381 | struct drm_tile_group *tg) |
5374 | { |
5382 | { |
5375 | kref_put(&tg->refcount, drm_tile_group_free); |
5383 | kref_put(&tg->refcount, drm_tile_group_free); |
5376 | } |
5384 | } |
5377 | 5385 | ||
5378 | /** |
5386 | /** |
5379 | * drm_mode_get_tile_group - get a reference to an existing tile group |
5387 | * drm_mode_get_tile_group - get a reference to an existing tile group |
5380 | * @dev: DRM device |
5388 | * @dev: DRM device |
5381 | * @topology: 8-bytes unique per monitor. |
5389 | * @topology: 8-bytes unique per monitor. |
5382 | * |
5390 | * |
5383 | * Use the unique bytes to get a reference to an existing tile group. |
5391 | * Use the unique bytes to get a reference to an existing tile group. |
5384 | * |
5392 | * |
5385 | * RETURNS: |
5393 | * RETURNS: |
5386 | * tile group or NULL if not found. |
5394 | * tile group or NULL if not found. |
5387 | */ |
5395 | */ |
5388 | struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, |
5396 | struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, |
5389 | char topology[8]) |
5397 | char topology[8]) |
5390 | { |
5398 | { |
5391 | struct drm_tile_group *tg; |
5399 | struct drm_tile_group *tg; |
5392 | int id; |
5400 | int id; |
5393 | mutex_lock(&dev->mode_config.idr_mutex); |
5401 | mutex_lock(&dev->mode_config.idr_mutex); |
5394 | idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) { |
5402 | idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) { |
5395 | if (!memcmp(tg->group_data, topology, 8)) { |
5403 | if (!memcmp(tg->group_data, topology, 8)) { |
5396 | if (!kref_get_unless_zero(&tg->refcount)) |
5404 | if (!kref_get_unless_zero(&tg->refcount)) |
5397 | tg = NULL; |
5405 | tg = NULL; |
5398 | mutex_unlock(&dev->mode_config.idr_mutex); |
5406 | mutex_unlock(&dev->mode_config.idr_mutex); |
5399 | return tg; |
5407 | return tg; |
5400 | } |
5408 | } |
5401 | } |
5409 | } |
5402 | mutex_unlock(&dev->mode_config.idr_mutex); |
5410 | mutex_unlock(&dev->mode_config.idr_mutex); |
5403 | return NULL; |
5411 | return NULL; |
5404 | } |
5412 | } |
5405 | EXPORT_SYMBOL(drm_mode_get_tile_group); |
5413 | EXPORT_SYMBOL(drm_mode_get_tile_group); |
5406 | 5414 | ||
5407 | /** |
5415 | /** |
5408 | * drm_mode_create_tile_group - create a tile group from a displayid description |
5416 | * drm_mode_create_tile_group - create a tile group from a displayid description |
5409 | * @dev: DRM device |
5417 | * @dev: DRM device |
5410 | * @topology: 8-bytes unique per monitor. |
5418 | * @topology: 8-bytes unique per monitor. |
5411 | * |
5419 | * |
5412 | * Create a tile group for the unique monitor, and get a unique |
5420 | * Create a tile group for the unique monitor, and get a unique |
5413 | * identifier for the tile group. |
5421 | * identifier for the tile group. |
5414 | * |
5422 | * |
5415 | * RETURNS: |
5423 | * RETURNS: |
5416 | * new tile group or error. |
5424 | * new tile group or error. |
5417 | */ |
5425 | */ |
5418 | struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, |
5426 | struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, |
5419 | char topology[8]) |
5427 | char topology[8]) |
5420 | { |
5428 | { |
5421 | struct drm_tile_group *tg; |
5429 | struct drm_tile_group *tg; |
5422 | int ret; |
5430 | int ret; |
5423 | 5431 | ||
5424 | tg = kzalloc(sizeof(*tg), GFP_KERNEL); |
5432 | tg = kzalloc(sizeof(*tg), GFP_KERNEL); |
5425 | if (!tg) |
5433 | if (!tg) |
5426 | return ERR_PTR(-ENOMEM); |
5434 | return ERR_PTR(-ENOMEM); |
5427 | 5435 | ||
5428 | kref_init(&tg->refcount); |
5436 | kref_init(&tg->refcount); |
5429 | memcpy(tg->group_data, topology, 8); |
5437 | memcpy(tg->group_data, topology, 8); |
5430 | tg->dev = dev; |
5438 | tg->dev = dev; |
5431 | 5439 | ||
5432 | mutex_lock(&dev->mode_config.idr_mutex); |
5440 | mutex_lock(&dev->mode_config.idr_mutex); |
5433 | ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL); |
5441 | ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL); |
5434 | if (ret >= 0) { |
5442 | if (ret >= 0) { |
5435 | tg->id = ret; |
5443 | tg->id = ret; |
5436 | } else { |
5444 | } else { |
5437 | kfree(tg); |
5445 | kfree(tg); |
5438 | tg = ERR_PTR(ret); |
5446 | tg = ERR_PTR(ret); |
5439 | } |
5447 | } |
5440 | 5448 | ||
5441 | mutex_unlock(&dev->mode_config.idr_mutex); |
5449 | mutex_unlock(&dev->mode_config.idr_mutex); |
5442 | return tg; |
5450 | return tg; |
5443 | } |
5451 | } |
5444 | EXPORT_SYMBOL(drm_mode_create_tile_group);>>>><>>>>>>>><>>>>=>=>>>>>><>><>><>><>><>><>>>>>>>><>><>>>>> |
5452 | EXPORT_SYMBOL(drm_mode_create_tile_group);>>>><>>>>>>>><>>>>=>=>>>>>><>><>><>><>><>><>>>>>>>><>><>>>>> |