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