Subversion Repositories Kolibri OS

Rev

Rev 1963 | Rev 2160 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1963 Rev 2004
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 "drm.h"
34
#include "drm.h"
35
#include "drmP.h"
35
#include "drmP.h"
36
#include "drm_crtc.h"
36
#include "drm_crtc.h"
37
#include "drm_edid.h"
37
#include "drm_edid.h"
38
 
38
 
39
struct drm_prop_enum_list {
39
struct drm_prop_enum_list {
40
	int type;
40
	int type;
41
	char *name;
41
	char *name;
42
};
42
};
43
 
43
 
44
/* Avoid boilerplate.  I'm tired of typing. */
44
/* Avoid boilerplate.  I'm tired of typing. */
45
#define DRM_ENUM_NAME_FN(fnname, list)				\
45
#define DRM_ENUM_NAME_FN(fnname, list)				\
46
	char *fnname(int val)					\
46
	char *fnname(int val)					\
47
	{							\
47
	{							\
48
		int i;						\
48
		int i;						\
49
		for (i = 0; i < ARRAY_SIZE(list); i++) {	\
49
		for (i = 0; i < ARRAY_SIZE(list); i++) {	\
50
			if (list[i].type == val)		\
50
			if (list[i].type == val)		\
51
				return list[i].name;		\
51
				return list[i].name;		\
52
		}						\
52
		}						\
53
		return "(unknown)";				\
53
		return "(unknown)";				\
54
	}
54
	}
55
 
55
 
56
/*
56
/*
57
 * Global properties
57
 * Global properties
58
 */
58
 */
59
static struct drm_prop_enum_list drm_dpms_enum_list[] =
59
static struct drm_prop_enum_list drm_dpms_enum_list[] =
60
{	{ DRM_MODE_DPMS_ON, "On" },
60
{	{ DRM_MODE_DPMS_ON, "On" },
61
	{ DRM_MODE_DPMS_STANDBY, "Standby" },
61
	{ DRM_MODE_DPMS_STANDBY, "Standby" },
62
	{ DRM_MODE_DPMS_SUSPEND, "Suspend" },
62
	{ DRM_MODE_DPMS_SUSPEND, "Suspend" },
63
	{ DRM_MODE_DPMS_OFF, "Off" }
63
	{ DRM_MODE_DPMS_OFF, "Off" }
64
};
64
};
65
 
65
 
66
DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
66
DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
67
 
67
 
68
/*
68
/*
69
 * Optional properties
69
 * Optional properties
70
 */
70
 */
71
static struct drm_prop_enum_list drm_scaling_mode_enum_list[] =
71
static struct drm_prop_enum_list drm_scaling_mode_enum_list[] =
72
{
72
{
73
	{ DRM_MODE_SCALE_NONE, "None" },
73
	{ DRM_MODE_SCALE_NONE, "None" },
74
	{ DRM_MODE_SCALE_FULLSCREEN, "Full" },
74
	{ DRM_MODE_SCALE_FULLSCREEN, "Full" },
75
	{ DRM_MODE_SCALE_CENTER, "Center" },
75
	{ DRM_MODE_SCALE_CENTER, "Center" },
76
	{ DRM_MODE_SCALE_ASPECT, "Full aspect" },
76
	{ DRM_MODE_SCALE_ASPECT, "Full aspect" },
77
};
77
};
78
 
78
 
79
static struct drm_prop_enum_list drm_dithering_mode_enum_list[] =
79
static struct drm_prop_enum_list drm_dithering_mode_enum_list[] =
80
{
80
{
81
	{ DRM_MODE_DITHERING_OFF, "Off" },
81
	{ DRM_MODE_DITHERING_OFF, "Off" },
82
	{ DRM_MODE_DITHERING_ON, "On" },
82
	{ DRM_MODE_DITHERING_ON, "On" },
83
	{ DRM_MODE_DITHERING_AUTO, "Automatic" },
83
	{ DRM_MODE_DITHERING_AUTO, "Automatic" },
84
};
84
};
85
 
85
 
86
/*
86
/*
87
 * Non-global properties, but "required" for certain connectors.
87
 * Non-global properties, but "required" for certain connectors.
88
 */
88
 */
89
static struct drm_prop_enum_list drm_dvi_i_select_enum_list[] =
89
static struct drm_prop_enum_list drm_dvi_i_select_enum_list[] =
90
{
90
{
91
	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
91
	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
92
	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
92
	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
93
	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
93
	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
94
};
94
};
95
 
95
 
96
DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
96
DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
97
 
97
 
98
static struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] =
98
static struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] =
99
{
99
{
100
	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I and TV-out */
100
	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I and TV-out */
101
	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
101
	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
102
	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
102
	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
103
};
103
};
104
 
104
 
105
DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
105
DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
106
		 drm_dvi_i_subconnector_enum_list)
106
		 drm_dvi_i_subconnector_enum_list)
107
 
107
 
108
static struct drm_prop_enum_list drm_tv_select_enum_list[] =
108
static struct drm_prop_enum_list drm_tv_select_enum_list[] =
109
{
109
{
110
	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
110
	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
111
	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
111
	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
112
	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
112
	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
113
	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
113
	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
114
	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
114
	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
115
};
115
};
116
 
116
 
117
DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
117
DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
118
 
118
 
119
static struct drm_prop_enum_list drm_tv_subconnector_enum_list[] =
119
static struct drm_prop_enum_list drm_tv_subconnector_enum_list[] =
120
{
120
{
121
	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I and TV-out */
121
	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I and TV-out */
122
	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
122
	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
123
	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
123
	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
124
	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
124
	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
125
	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
125
	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
126
};
126
};
127
 
127
 
128
DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
128
DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
129
		 drm_tv_subconnector_enum_list)
129
		 drm_tv_subconnector_enum_list)
130
 
130
 
131
static struct drm_prop_enum_list drm_dirty_info_enum_list[] = {
131
static struct drm_prop_enum_list drm_dirty_info_enum_list[] = {
132
	{ DRM_MODE_DIRTY_OFF,      "Off"      },
132
	{ DRM_MODE_DIRTY_OFF,      "Off"      },
133
	{ DRM_MODE_DIRTY_ON,       "On"       },
133
	{ DRM_MODE_DIRTY_ON,       "On"       },
134
	{ DRM_MODE_DIRTY_ANNOTATE, "Annotate" },
134
	{ DRM_MODE_DIRTY_ANNOTATE, "Annotate" },
135
};
135
};
136
 
136
 
137
DRM_ENUM_NAME_FN(drm_get_dirty_info_name,
137
DRM_ENUM_NAME_FN(drm_get_dirty_info_name,
138
		 drm_dirty_info_enum_list)
138
		 drm_dirty_info_enum_list)
139
 
139
 
140
struct drm_conn_prop_enum_list {
140
struct drm_conn_prop_enum_list {
141
	int type;
141
	int type;
142
	char *name;
142
	char *name;
143
	int count;
143
	int count;
144
};
144
};
145
 
145
 
146
/*
146
/*
147
 * Connector and encoder types.
147
 * Connector and encoder types.
148
 */
148
 */
149
static struct drm_conn_prop_enum_list drm_connector_enum_list[] =
149
static struct drm_conn_prop_enum_list drm_connector_enum_list[] =
150
{	{ DRM_MODE_CONNECTOR_Unknown, "Unknown", 0 },
150
{	{ DRM_MODE_CONNECTOR_Unknown, "Unknown", 0 },
151
	{ DRM_MODE_CONNECTOR_VGA, "VGA", 0 },
151
	{ DRM_MODE_CONNECTOR_VGA, "VGA", 0 },
152
	{ DRM_MODE_CONNECTOR_DVII, "DVI-I", 0 },
152
	{ DRM_MODE_CONNECTOR_DVII, "DVI-I", 0 },
153
	{ DRM_MODE_CONNECTOR_DVID, "DVI-D", 0 },
153
	{ DRM_MODE_CONNECTOR_DVID, "DVI-D", 0 },
154
	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A", 0 },
154
	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A", 0 },
155
	{ DRM_MODE_CONNECTOR_Composite, "Composite", 0 },
155
	{ DRM_MODE_CONNECTOR_Composite, "Composite", 0 },
156
	{ DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO", 0 },
156
	{ DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO", 0 },
157
	{ DRM_MODE_CONNECTOR_LVDS, "LVDS", 0 },
157
	{ DRM_MODE_CONNECTOR_LVDS, "LVDS", 0 },
158
	{ DRM_MODE_CONNECTOR_Component, "Component", 0 },
158
	{ DRM_MODE_CONNECTOR_Component, "Component", 0 },
159
	{ DRM_MODE_CONNECTOR_9PinDIN, "DIN", 0 },
159
	{ DRM_MODE_CONNECTOR_9PinDIN, "DIN", 0 },
160
	{ DRM_MODE_CONNECTOR_DisplayPort, "DP", 0 },
160
	{ DRM_MODE_CONNECTOR_DisplayPort, "DP", 0 },
161
	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A", 0 },
161
	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A", 0 },
162
	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B", 0 },
162
	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B", 0 },
163
	{ DRM_MODE_CONNECTOR_TV, "TV", 0 },
163
	{ DRM_MODE_CONNECTOR_TV, "TV", 0 },
164
	{ DRM_MODE_CONNECTOR_eDP, "eDP", 0 },
164
	{ DRM_MODE_CONNECTOR_eDP, "eDP", 0 },
165
};
165
};
166
 
166
 
167
static struct drm_prop_enum_list drm_encoder_enum_list[] =
167
static struct drm_prop_enum_list drm_encoder_enum_list[] =
168
{	{ DRM_MODE_ENCODER_NONE, "None" },
168
{	{ DRM_MODE_ENCODER_NONE, "None" },
169
	{ DRM_MODE_ENCODER_DAC, "DAC" },
169
	{ DRM_MODE_ENCODER_DAC, "DAC" },
170
	{ DRM_MODE_ENCODER_TMDS, "TMDS" },
170
	{ DRM_MODE_ENCODER_TMDS, "TMDS" },
171
	{ DRM_MODE_ENCODER_LVDS, "LVDS" },
171
	{ DRM_MODE_ENCODER_LVDS, "LVDS" },
172
	{ DRM_MODE_ENCODER_TVDAC, "TV" },
172
	{ DRM_MODE_ENCODER_TVDAC, "TV" },
173
};
173
};
174
 
174
 
175
char *drm_get_encoder_name(struct drm_encoder *encoder)
175
char *drm_get_encoder_name(struct drm_encoder *encoder)
176
{
176
{
177
	static char buf[32];
177
	static char buf[32];
178
 
178
 
179
	snprintf(buf, 32, "%s-%d",
179
	snprintf(buf, 32, "%s-%d",
180
		 drm_encoder_enum_list[encoder->encoder_type].name,
180
		 drm_encoder_enum_list[encoder->encoder_type].name,
181
		 encoder->base.id);
181
		 encoder->base.id);
182
	return buf;
182
	return buf;
183
}
183
}
184
EXPORT_SYMBOL(drm_get_encoder_name);
184
EXPORT_SYMBOL(drm_get_encoder_name);
185
 
185
 
186
char *drm_get_connector_name(struct drm_connector *connector)
186
char *drm_get_connector_name(struct drm_connector *connector)
187
{
187
{
188
	static char buf[32];
188
	static char buf[32];
189
 
189
 
190
	snprintf(buf, 32, "%s-%d",
190
	snprintf(buf, 32, "%s-%d",
191
		 drm_connector_enum_list[connector->connector_type].name,
191
		 drm_connector_enum_list[connector->connector_type].name,
192
		 connector->connector_type_id);
192
		 connector->connector_type_id);
193
	return buf;
193
	return buf;
194
}
194
}
195
EXPORT_SYMBOL(drm_get_connector_name);
195
EXPORT_SYMBOL(drm_get_connector_name);
196
 
196
 
197
char *drm_get_connector_status_name(enum drm_connector_status status)
197
char *drm_get_connector_status_name(enum drm_connector_status status)
198
{
198
{
199
	if (status == connector_status_connected)
199
	if (status == connector_status_connected)
200
		return "connected";
200
		return "connected";
201
	else if (status == connector_status_disconnected)
201
	else if (status == connector_status_disconnected)
202
		return "disconnected";
202
		return "disconnected";
203
	else
203
	else
204
		return "unknown";
204
		return "unknown";
205
}
205
}
206
 
206
 
207
/**
207
/**
208
 * drm_mode_object_get - allocate a new identifier
208
 * drm_mode_object_get - allocate a new identifier
209
 * @dev: DRM device
209
 * @dev: DRM device
210
 * @ptr: object pointer, used to generate unique ID
210
 * @ptr: object pointer, used to generate unique ID
211
 * @type: object type
211
 * @type: object type
212
 *
212
 *
213
 * LOCKING:
213
 * LOCKING:
214
 *
214
 *
215
 * Create a unique identifier based on @ptr in @dev's identifier space.  Used
215
 * Create a unique identifier based on @ptr in @dev's identifier space.  Used
216
 * for tracking modes, CRTCs and connectors.
216
 * for tracking modes, CRTCs and connectors.
217
 *
217
 *
218
 * RETURNS:
218
 * RETURNS:
219
 * New unique (relative to other objects in @dev) integer identifier for the
219
 * New unique (relative to other objects in @dev) integer identifier for the
220
 * object.
220
 * object.
221
 */
221
 */
222
static int drm_mode_object_get(struct drm_device *dev,
222
static int drm_mode_object_get(struct drm_device *dev,
223
			       struct drm_mode_object *obj, uint32_t obj_type)
223
			       struct drm_mode_object *obj, uint32_t obj_type)
224
{
224
{
225
	int new_id = 0;
225
	int new_id = 0;
226
	int ret;
226
	int ret;
227
 
227
 
228
again:
228
again:
229
	if (idr_pre_get(&dev->mode_config.crtc_idr, GFP_KERNEL) == 0) {
229
	if (idr_pre_get(&dev->mode_config.crtc_idr, GFP_KERNEL) == 0) {
230
		DRM_ERROR("Ran out memory getting a mode number\n");
230
		DRM_ERROR("Ran out memory getting a mode number\n");
231
		return -EINVAL;
231
		return -EINVAL;
232
	}
232
	}
233
 
233
 
234
	mutex_lock(&dev->mode_config.idr_mutex);
234
	mutex_lock(&dev->mode_config.idr_mutex);
235
	ret = idr_get_new_above(&dev->mode_config.crtc_idr, obj, 1, &new_id);
235
	ret = idr_get_new_above(&dev->mode_config.crtc_idr, obj, 1, &new_id);
236
	mutex_unlock(&dev->mode_config.idr_mutex);
236
	mutex_unlock(&dev->mode_config.idr_mutex);
237
	if (ret == -EAGAIN)
237
	if (ret == -EAGAIN)
238
        goto again;
238
        goto again;
239
 
239
 
240
	obj->id = new_id;
240
	obj->id = new_id;
241
	obj->type = obj_type;
241
	obj->type = obj_type;
242
    return 0;
242
    return 0;
243
}
243
}
244
 
244
 
245
/**
245
/**
246
 * drm_mode_object_put - free an identifer
246
 * drm_mode_object_put - free an identifer
247
 * @dev: DRM device
247
 * @dev: DRM device
248
 * @id: ID to free
248
 * @id: ID to free
249
 *
249
 *
250
 * LOCKING:
250
 * LOCKING:
251
 * Caller must hold DRM mode_config lock.
251
 * Caller must hold DRM mode_config lock.
252
 *
252
 *
253
 * Free @id from @dev's unique identifier pool.
253
 * Free @id from @dev's unique identifier pool.
254
 */
254
 */
255
static void drm_mode_object_put(struct drm_device *dev,
255
static void drm_mode_object_put(struct drm_device *dev,
256
				struct drm_mode_object *object)
256
				struct drm_mode_object *object)
257
{
257
{
258
	mutex_lock(&dev->mode_config.idr_mutex);
258
	mutex_lock(&dev->mode_config.idr_mutex);
259
	idr_remove(&dev->mode_config.crtc_idr, object->id);
259
	idr_remove(&dev->mode_config.crtc_idr, object->id);
260
	mutex_unlock(&dev->mode_config.idr_mutex);
260
	mutex_unlock(&dev->mode_config.idr_mutex);
261
}
261
}
262
 
262
 
263
struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
263
struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
264
		uint32_t id, uint32_t type)
264
		uint32_t id, uint32_t type)
265
{
265
{
266
	struct drm_mode_object *obj = NULL;
266
	struct drm_mode_object *obj = NULL;
267
 
267
 
268
	mutex_lock(&dev->mode_config.idr_mutex);
268
	mutex_lock(&dev->mode_config.idr_mutex);
269
	obj = idr_find(&dev->mode_config.crtc_idr, id);
269
	obj = idr_find(&dev->mode_config.crtc_idr, id);
270
	if (!obj || (obj->type != type) || (obj->id != id))
270
	if (!obj || (obj->type != type) || (obj->id != id))
271
		obj = NULL;
271
		obj = NULL;
272
	mutex_unlock(&dev->mode_config.idr_mutex);
272
	mutex_unlock(&dev->mode_config.idr_mutex);
273
 
273
 
274
	return obj;
274
	return obj;
275
}
275
}
276
EXPORT_SYMBOL(drm_mode_object_find);
276
EXPORT_SYMBOL(drm_mode_object_find);
277
 
277
 
278
/**
278
/**
279
 * drm_framebuffer_init - initialize a framebuffer
279
 * drm_framebuffer_init - initialize a framebuffer
280
 * @dev: DRM device
280
 * @dev: DRM device
281
 *
281
 *
282
 * LOCKING:
282
 * LOCKING:
283
 * Caller must hold mode config lock.
283
 * Caller must hold mode config lock.
284
 *
284
 *
285
 * Allocates an ID for the framebuffer's parent mode object, sets its mode
285
 * Allocates an ID for the framebuffer's parent mode object, sets its mode
286
 * functions & device file and adds it to the master fd list.
286
 * functions & device file and adds it to the master fd list.
287
 *
287
 *
288
 * RETURNS:
288
 * RETURNS:
289
 * Zero on success, error code on failure.
289
 * Zero on success, error code on failure.
290
 */
290
 */
291
int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb,
291
int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb,
292
			 const struct drm_framebuffer_funcs *funcs)
292
			 const struct drm_framebuffer_funcs *funcs)
293
{
293
{
294
	int ret;
294
	int ret;
295
 
295
 
296
	ret = drm_mode_object_get(dev, &fb->base, DRM_MODE_OBJECT_FB);
296
	ret = drm_mode_object_get(dev, &fb->base, DRM_MODE_OBJECT_FB);
297
	if (ret) {
297
	if (ret) {
298
		return ret;
298
		return ret;
299
	}
299
	}
300
 
300
 
301
	fb->dev = dev;
301
	fb->dev = dev;
302
	fb->funcs = funcs;
302
	fb->funcs = funcs;
303
	dev->mode_config.num_fb++;
303
	dev->mode_config.num_fb++;
304
	list_add(&fb->head, &dev->mode_config.fb_list);
304
	list_add(&fb->head, &dev->mode_config.fb_list);
305
 
305
 
306
	return 0;
306
	return 0;
307
}
307
}
308
EXPORT_SYMBOL(drm_framebuffer_init);
308
EXPORT_SYMBOL(drm_framebuffer_init);
309
 
309
 
310
/**
310
/**
311
 * drm_framebuffer_cleanup - remove a framebuffer object
311
 * drm_framebuffer_cleanup - remove a framebuffer object
312
 * @fb: framebuffer to remove
312
 * @fb: framebuffer to remove
313
 *
313
 *
314
 * LOCKING:
314
 * LOCKING:
315
 * Caller must hold mode config lock.
315
 * Caller must hold mode config lock.
316
 *
316
 *
317
 * Scans all the CRTCs in @dev's mode_config.  If they're using @fb, removes
317
 * Scans all the CRTCs in @dev's mode_config.  If they're using @fb, removes
318
 * it, setting it to NULL.
318
 * it, setting it to NULL.
319
 */
319
 */
320
void drm_framebuffer_cleanup(struct drm_framebuffer *fb)
320
void drm_framebuffer_cleanup(struct drm_framebuffer *fb)
321
{
321
{
322
	struct drm_device *dev = fb->dev;
322
	struct drm_device *dev = fb->dev;
323
	struct drm_crtc *crtc;
323
	struct drm_crtc *crtc;
324
	struct drm_mode_set set;
324
	struct drm_mode_set set;
325
	int ret;
325
	int ret;
326
 
326
 
327
	/* remove from any CRTC */
327
	/* remove from any CRTC */
328
	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
328
	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
329
		if (crtc->fb == fb) {
329
		if (crtc->fb == fb) {
330
			/* should turn off the crtc */
330
			/* should turn off the crtc */
331
			memset(&set, 0, sizeof(struct drm_mode_set));
331
			memset(&set, 0, sizeof(struct drm_mode_set));
332
			set.crtc = crtc;
332
			set.crtc = crtc;
333
			set.fb = NULL;
333
			set.fb = NULL;
334
			ret = crtc->funcs->set_config(&set);
334
			ret = crtc->funcs->set_config(&set);
335
			if (ret)
335
			if (ret)
336
				DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc);
336
				DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc);
337
	   }
337
	   }
338
	}
338
	}
339
 
339
 
340
	drm_mode_object_put(dev, &fb->base);
340
	drm_mode_object_put(dev, &fb->base);
341
	list_del(&fb->head);
341
	list_del(&fb->head);
342
	dev->mode_config.num_fb--;
342
	dev->mode_config.num_fb--;
343
}
343
}
344
EXPORT_SYMBOL(drm_framebuffer_cleanup);
344
EXPORT_SYMBOL(drm_framebuffer_cleanup);
345
 
345
 
346
/**
346
/**
347
 * drm_crtc_init - Initialise a new CRTC object
347
 * drm_crtc_init - Initialise a new CRTC object
348
 * @dev: DRM device
348
 * @dev: DRM device
349
 * @crtc: CRTC object to init
349
 * @crtc: CRTC object to init
350
 * @funcs: callbacks for the new CRTC
350
 * @funcs: callbacks for the new CRTC
351
 *
351
 *
352
 * LOCKING:
352
 * LOCKING:
353
 * Caller must hold mode config lock.
353
 * Caller must hold mode config lock.
354
 *
354
 *
355
 * Inits a new object created as base part of an driver crtc object.
355
 * Inits a new object created as base part of an driver crtc object.
356
 */
356
 */
357
void drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
357
void drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
358
		   const struct drm_crtc_funcs *funcs)
358
		   const struct drm_crtc_funcs *funcs)
359
{
359
{
360
	crtc->dev = dev;
360
	crtc->dev = dev;
361
	crtc->funcs = funcs;
361
	crtc->funcs = funcs;
362
 
362
 
363
	mutex_lock(&dev->mode_config.mutex);
363
	mutex_lock(&dev->mode_config.mutex);
364
	drm_mode_object_get(dev, &crtc->base, DRM_MODE_OBJECT_CRTC);
364
	drm_mode_object_get(dev, &crtc->base, DRM_MODE_OBJECT_CRTC);
365
 
365
 
366
	list_add_tail(&crtc->head, &dev->mode_config.crtc_list);
366
	list_add_tail(&crtc->head, &dev->mode_config.crtc_list);
367
	dev->mode_config.num_crtc++;
367
	dev->mode_config.num_crtc++;
368
	mutex_unlock(&dev->mode_config.mutex);
368
	mutex_unlock(&dev->mode_config.mutex);
369
}
369
}
370
EXPORT_SYMBOL(drm_crtc_init);
370
EXPORT_SYMBOL(drm_crtc_init);
371
 
371
 
372
/**
372
/**
373
 * drm_crtc_cleanup - Cleans up the core crtc usage.
373
 * drm_crtc_cleanup - Cleans up the core crtc usage.
374
 * @crtc: CRTC to cleanup
374
 * @crtc: CRTC to cleanup
375
 *
375
 *
376
 * LOCKING:
376
 * LOCKING:
377
 * Caller must hold mode config lock.
377
 * Caller must hold mode config lock.
378
 *
378
 *
379
 * Cleanup @crtc. Removes from drm modesetting space
379
 * Cleanup @crtc. Removes from drm modesetting space
380
 * does NOT free object, caller does that.
380
 * does NOT free object, caller does that.
381
 */
381
 */
382
void drm_crtc_cleanup(struct drm_crtc *crtc)
382
void drm_crtc_cleanup(struct drm_crtc *crtc)
383
{
383
{
384
	struct drm_device *dev = crtc->dev;
384
	struct drm_device *dev = crtc->dev;
385
 
385
 
386
	if (crtc->gamma_store) {
386
	if (crtc->gamma_store) {
387
		kfree(crtc->gamma_store);
387
		kfree(crtc->gamma_store);
388
		crtc->gamma_store = NULL;
388
		crtc->gamma_store = NULL;
389
	}
389
	}
390
 
390
 
391
	drm_mode_object_put(dev, &crtc->base);
391
	drm_mode_object_put(dev, &crtc->base);
392
	list_del(&crtc->head);
392
	list_del(&crtc->head);
393
	dev->mode_config.num_crtc--;
393
	dev->mode_config.num_crtc--;
394
}
394
}
395
EXPORT_SYMBOL(drm_crtc_cleanup);
395
EXPORT_SYMBOL(drm_crtc_cleanup);
396
 
396
 
397
/**
397
/**
398
 * drm_mode_probed_add - add a mode to a connector's probed mode list
398
 * drm_mode_probed_add - add a mode to a connector's probed mode list
399
 * @connector: connector the new mode
399
 * @connector: connector the new mode
400
 * @mode: mode data
400
 * @mode: mode data
401
 *
401
 *
402
 * LOCKING:
402
 * LOCKING:
403
 * Caller must hold mode config lock.
403
 * Caller must hold mode config lock.
404
 *
404
 *
405
 * Add @mode to @connector's mode list for later use.
405
 * Add @mode to @connector's mode list for later use.
406
 */
406
 */
407
void drm_mode_probed_add(struct drm_connector *connector,
407
void drm_mode_probed_add(struct drm_connector *connector,
408
			 struct drm_display_mode *mode)
408
			 struct drm_display_mode *mode)
409
{
409
{
410
	list_add(&mode->head, &connector->probed_modes);
410
	list_add(&mode->head, &connector->probed_modes);
411
}
411
}
412
EXPORT_SYMBOL(drm_mode_probed_add);
412
EXPORT_SYMBOL(drm_mode_probed_add);
413
 
413
 
414
/**
414
/**
415
 * drm_mode_remove - remove and free a mode
415
 * drm_mode_remove - remove and free a mode
416
 * @connector: connector list to modify
416
 * @connector: connector list to modify
417
 * @mode: mode to remove
417
 * @mode: mode to remove
418
 *
418
 *
419
 * LOCKING:
419
 * LOCKING:
420
 * Caller must hold mode config lock.
420
 * Caller must hold mode config lock.
421
 *
421
 *
422
 * Remove @mode from @connector's mode list, then free it.
422
 * Remove @mode from @connector's mode list, then free it.
423
 */
423
 */
424
void drm_mode_remove(struct drm_connector *connector,
424
void drm_mode_remove(struct drm_connector *connector,
425
		     struct drm_display_mode *mode)
425
		     struct drm_display_mode *mode)
426
{
426
{
427
	list_del(&mode->head);
427
	list_del(&mode->head);
428
	kfree(mode);
428
	kfree(mode);
429
}
429
}
430
EXPORT_SYMBOL(drm_mode_remove);
430
EXPORT_SYMBOL(drm_mode_remove);
431
 
431
 
432
/**
432
/**
433
 * drm_connector_init - Init a preallocated connector
433
 * drm_connector_init - Init a preallocated connector
434
 * @dev: DRM device
434
 * @dev: DRM device
435
 * @connector: the connector to init
435
 * @connector: the connector to init
436
 * @funcs: callbacks for this connector
436
 * @funcs: callbacks for this connector
437
 * @name: user visible name of the connector
437
 * @name: user visible name of the connector
438
 *
438
 *
439
 * LOCKING:
439
 * LOCKING:
440
 * Caller must hold @dev's mode_config lock.
440
 * Caller must hold @dev's mode_config lock.
441
 *
441
 *
442
 * Initialises a preallocated connector. Connectors should be
442
 * Initialises a preallocated connector. Connectors should be
443
 * subclassed as part of driver connector objects.
443
 * subclassed as part of driver connector objects.
444
 */
444
 */
445
void drm_connector_init(struct drm_device *dev,
445
void drm_connector_init(struct drm_device *dev,
446
		     struct drm_connector *connector,
446
		     struct drm_connector *connector,
447
		     const struct drm_connector_funcs *funcs,
447
		     const struct drm_connector_funcs *funcs,
448
		     int connector_type)
448
		     int connector_type)
449
{
449
{
450
	mutex_lock(&dev->mode_config.mutex);
450
	mutex_lock(&dev->mode_config.mutex);
451
 
451
 
452
	connector->dev = dev;
452
	connector->dev = dev;
453
	connector->funcs = funcs;
453
	connector->funcs = funcs;
454
	drm_mode_object_get(dev, &connector->base, DRM_MODE_OBJECT_CONNECTOR);
454
	drm_mode_object_get(dev, &connector->base, DRM_MODE_OBJECT_CONNECTOR);
455
	connector->connector_type = connector_type;
455
	connector->connector_type = connector_type;
456
	connector->connector_type_id =
456
	connector->connector_type_id =
457
		++drm_connector_enum_list[connector_type].count; /* TODO */
457
		++drm_connector_enum_list[connector_type].count; /* TODO */
458
	INIT_LIST_HEAD(&connector->user_modes);
458
	INIT_LIST_HEAD(&connector->user_modes);
459
	INIT_LIST_HEAD(&connector->probed_modes);
459
	INIT_LIST_HEAD(&connector->probed_modes);
460
	INIT_LIST_HEAD(&connector->modes);
460
	INIT_LIST_HEAD(&connector->modes);
461
	connector->edid_blob_ptr = NULL;
461
	connector->edid_blob_ptr = NULL;
462
 
462
 
463
	list_add_tail(&connector->head, &dev->mode_config.connector_list);
463
	list_add_tail(&connector->head, &dev->mode_config.connector_list);
464
	dev->mode_config.num_connector++;
464
	dev->mode_config.num_connector++;
465
 
465
 
466
	drm_connector_attach_property(connector,
466
	drm_connector_attach_property(connector,
467
				      dev->mode_config.edid_property, 0);
467
				      dev->mode_config.edid_property, 0);
468
 
468
 
469
	drm_connector_attach_property(connector,
469
	drm_connector_attach_property(connector,
470
				      dev->mode_config.dpms_property, 0);
470
				      dev->mode_config.dpms_property, 0);
471
 
471
 
472
	mutex_unlock(&dev->mode_config.mutex);
472
	mutex_unlock(&dev->mode_config.mutex);
473
}
473
}
474
EXPORT_SYMBOL(drm_connector_init);
474
EXPORT_SYMBOL(drm_connector_init);
475
 
475
 
476
/**
476
/**
477
 * drm_connector_cleanup - cleans up an initialised connector
477
 * drm_connector_cleanup - cleans up an initialised connector
478
 * @connector: connector to cleanup
478
 * @connector: connector to cleanup
479
 *
479
 *
480
 * LOCKING:
480
 * LOCKING:
481
 * Caller must hold @dev's mode_config lock.
481
 * Caller must hold @dev's mode_config lock.
482
 *
482
 *
483
 * Cleans up the connector but doesn't free the object.
483
 * Cleans up the connector but doesn't free the object.
484
 */
484
 */
485
void drm_connector_cleanup(struct drm_connector *connector)
485
void drm_connector_cleanup(struct drm_connector *connector)
486
{
486
{
487
	struct drm_device *dev = connector->dev;
487
	struct drm_device *dev = connector->dev;
488
	struct drm_display_mode *mode, *t;
488
	struct drm_display_mode *mode, *t;
489
 
489
 
490
	list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
490
	list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
491
		drm_mode_remove(connector, mode);
491
		drm_mode_remove(connector, mode);
492
 
492
 
493
	list_for_each_entry_safe(mode, t, &connector->modes, head)
493
	list_for_each_entry_safe(mode, t, &connector->modes, head)
494
		drm_mode_remove(connector, mode);
494
		drm_mode_remove(connector, mode);
495
 
495
 
496
	list_for_each_entry_safe(mode, t, &connector->user_modes, head)
496
	list_for_each_entry_safe(mode, t, &connector->user_modes, head)
497
		drm_mode_remove(connector, mode);
497
		drm_mode_remove(connector, mode);
498
 
498
 
499
	mutex_lock(&dev->mode_config.mutex);
499
	mutex_lock(&dev->mode_config.mutex);
500
	drm_mode_object_put(dev, &connector->base);
500
	drm_mode_object_put(dev, &connector->base);
501
	list_del(&connector->head);
501
	list_del(&connector->head);
502
	mutex_unlock(&dev->mode_config.mutex);
502
	mutex_unlock(&dev->mode_config.mutex);
503
}
503
}
504
EXPORT_SYMBOL(drm_connector_cleanup);
504
EXPORT_SYMBOL(drm_connector_cleanup);
505
 
505
 
506
void drm_encoder_init(struct drm_device *dev,
506
void drm_encoder_init(struct drm_device *dev,
507
		      struct drm_encoder *encoder,
507
		      struct drm_encoder *encoder,
508
		      const struct drm_encoder_funcs *funcs,
508
		      const struct drm_encoder_funcs *funcs,
509
		      int encoder_type)
509
		      int encoder_type)
510
{
510
{
511
	mutex_lock(&dev->mode_config.mutex);
511
	mutex_lock(&dev->mode_config.mutex);
512
 
512
 
513
	encoder->dev = dev;
513
	encoder->dev = dev;
514
 
514
 
515
	drm_mode_object_get(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER);
515
	drm_mode_object_get(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER);
516
	encoder->encoder_type = encoder_type;
516
	encoder->encoder_type = encoder_type;
517
	encoder->funcs = funcs;
517
	encoder->funcs = funcs;
518
 
518
 
519
	list_add_tail(&encoder->head, &dev->mode_config.encoder_list);
519
	list_add_tail(&encoder->head, &dev->mode_config.encoder_list);
520
	dev->mode_config.num_encoder++;
520
	dev->mode_config.num_encoder++;
521
 
521
 
522
	mutex_unlock(&dev->mode_config.mutex);
522
	mutex_unlock(&dev->mode_config.mutex);
523
}
523
}
524
EXPORT_SYMBOL(drm_encoder_init);
524
EXPORT_SYMBOL(drm_encoder_init);
525
 
525
 
526
void drm_encoder_cleanup(struct drm_encoder *encoder)
526
void drm_encoder_cleanup(struct drm_encoder *encoder)
527
{
527
{
528
	struct drm_device *dev = encoder->dev;
528
	struct drm_device *dev = encoder->dev;
529
	mutex_lock(&dev->mode_config.mutex);
529
	mutex_lock(&dev->mode_config.mutex);
530
	drm_mode_object_put(dev, &encoder->base);
530
	drm_mode_object_put(dev, &encoder->base);
531
	list_del(&encoder->head);
531
	list_del(&encoder->head);
532
	mutex_unlock(&dev->mode_config.mutex);
532
	mutex_unlock(&dev->mode_config.mutex);
533
}
533
}
534
EXPORT_SYMBOL(drm_encoder_cleanup);
534
EXPORT_SYMBOL(drm_encoder_cleanup);
535
 
535
 
536
/**
536
/**
537
 * drm_mode_create - create a new display mode
537
 * drm_mode_create - create a new display mode
538
 * @dev: DRM device
538
 * @dev: DRM device
539
 *
539
 *
540
 * LOCKING:
540
 * LOCKING:
541
 * Caller must hold DRM mode_config lock.
541
 * Caller must hold DRM mode_config lock.
542
 *
542
 *
543
 * Create a new drm_display_mode, give it an ID, and return it.
543
 * Create a new drm_display_mode, give it an ID, and return it.
544
 *
544
 *
545
 * RETURNS:
545
 * RETURNS:
546
 * Pointer to new mode on success, NULL on error.
546
 * Pointer to new mode on success, NULL on error.
547
 */
547
 */
548
struct drm_display_mode *drm_mode_create(struct drm_device *dev)
548
struct drm_display_mode *drm_mode_create(struct drm_device *dev)
549
{
549
{
550
	struct drm_display_mode *nmode;
550
	struct drm_display_mode *nmode;
551
 
551
 
552
	nmode = kzalloc(sizeof(struct drm_display_mode), GFP_KERNEL);
552
	nmode = kzalloc(sizeof(struct drm_display_mode), GFP_KERNEL);
553
	if (!nmode)
553
	if (!nmode)
554
		return NULL;
554
		return NULL;
555
 
555
 
556
	drm_mode_object_get(dev, &nmode->base, DRM_MODE_OBJECT_MODE);
556
	drm_mode_object_get(dev, &nmode->base, DRM_MODE_OBJECT_MODE);
557
	return nmode;
557
	return nmode;
558
}
558
}
559
EXPORT_SYMBOL(drm_mode_create);
559
EXPORT_SYMBOL(drm_mode_create);
560
 
560
 
561
/**
561
/**
562
 * drm_mode_destroy - remove a mode
562
 * drm_mode_destroy - remove a mode
563
 * @dev: DRM device
563
 * @dev: DRM device
564
 * @mode: mode to remove
564
 * @mode: mode to remove
565
 *
565
 *
566
 * LOCKING:
566
 * LOCKING:
567
 * Caller must hold mode config lock.
567
 * Caller must hold mode config lock.
568
 *
568
 *
569
 * Free @mode's unique identifier, then free it.
569
 * Free @mode's unique identifier, then free it.
570
 */
570
 */
571
void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode)
571
void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode)
572
{
572
{
573
	drm_mode_object_put(dev, &mode->base);
573
	drm_mode_object_put(dev, &mode->base);
574
 
574
 
575
	kfree(mode);
575
	kfree(mode);
576
}
576
}
577
EXPORT_SYMBOL(drm_mode_destroy);
577
EXPORT_SYMBOL(drm_mode_destroy);
578
 
578
 
579
static int drm_mode_create_standard_connector_properties(struct drm_device *dev)
579
static int drm_mode_create_standard_connector_properties(struct drm_device *dev)
580
{
580
{
581
	struct drm_property *edid;
581
	struct drm_property *edid;
582
	struct drm_property *dpms;
582
	struct drm_property *dpms;
583
	int i;
583
	int i;
584
 
584
 
585
	/*
585
	/*
586
	 * Standard properties (apply to all connectors)
586
	 * Standard properties (apply to all connectors)
587
	 */
587
	 */
588
	edid = drm_property_create(dev, DRM_MODE_PROP_BLOB |
588
	edid = drm_property_create(dev, DRM_MODE_PROP_BLOB |
589
				   DRM_MODE_PROP_IMMUTABLE,
589
				   DRM_MODE_PROP_IMMUTABLE,
590
				   "EDID", 0);
590
				   "EDID", 0);
591
	dev->mode_config.edid_property = edid;
591
	dev->mode_config.edid_property = edid;
592
 
592
 
593
	dpms = drm_property_create(dev, DRM_MODE_PROP_ENUM,
593
	dpms = drm_property_create(dev, DRM_MODE_PROP_ENUM,
594
				   "DPMS", ARRAY_SIZE(drm_dpms_enum_list));
594
				   "DPMS", ARRAY_SIZE(drm_dpms_enum_list));
595
	for (i = 0; i < ARRAY_SIZE(drm_dpms_enum_list); i++)
595
	for (i = 0; i < ARRAY_SIZE(drm_dpms_enum_list); i++)
596
		drm_property_add_enum(dpms, i, drm_dpms_enum_list[i].type,
596
		drm_property_add_enum(dpms, i, drm_dpms_enum_list[i].type,
597
				      drm_dpms_enum_list[i].name);
597
				      drm_dpms_enum_list[i].name);
598
	dev->mode_config.dpms_property = dpms;
598
	dev->mode_config.dpms_property = dpms;
599
 
599
 
600
	return 0;
600
	return 0;
601
}
601
}
602
 
602
 
603
/**
603
/**
604
 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
604
 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
605
 * @dev: DRM device
605
 * @dev: DRM device
606
 *
606
 *
607
 * Called by a driver the first time a DVI-I connector is made.
607
 * Called by a driver the first time a DVI-I connector is made.
608
 */
608
 */
609
int drm_mode_create_dvi_i_properties(struct drm_device *dev)
609
int drm_mode_create_dvi_i_properties(struct drm_device *dev)
610
{
610
{
611
	struct drm_property *dvi_i_selector;
611
	struct drm_property *dvi_i_selector;
612
	struct drm_property *dvi_i_subconnector;
612
	struct drm_property *dvi_i_subconnector;
613
	int i;
613
	int i;
614
 
614
 
615
	if (dev->mode_config.dvi_i_select_subconnector_property)
615
	if (dev->mode_config.dvi_i_select_subconnector_property)
616
		return 0;
616
		return 0;
617
 
617
 
618
	dvi_i_selector =
618
	dvi_i_selector =
619
		drm_property_create(dev, DRM_MODE_PROP_ENUM,
619
		drm_property_create(dev, DRM_MODE_PROP_ENUM,
620
				    "select subconnector",
620
				    "select subconnector",
621
				    ARRAY_SIZE(drm_dvi_i_select_enum_list));
621
				    ARRAY_SIZE(drm_dvi_i_select_enum_list));
622
	for (i = 0; i < ARRAY_SIZE(drm_dvi_i_select_enum_list); i++)
622
	for (i = 0; i < ARRAY_SIZE(drm_dvi_i_select_enum_list); i++)
623
		drm_property_add_enum(dvi_i_selector, i,
623
		drm_property_add_enum(dvi_i_selector, i,
624
				      drm_dvi_i_select_enum_list[i].type,
624
				      drm_dvi_i_select_enum_list[i].type,
625
				      drm_dvi_i_select_enum_list[i].name);
625
				      drm_dvi_i_select_enum_list[i].name);
626
	dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
626
	dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
627
 
627
 
628
	dvi_i_subconnector =
628
	dvi_i_subconnector =
629
		drm_property_create(dev, DRM_MODE_PROP_ENUM |
629
		drm_property_create(dev, DRM_MODE_PROP_ENUM |
630
				    DRM_MODE_PROP_IMMUTABLE,
630
				    DRM_MODE_PROP_IMMUTABLE,
631
				    "subconnector",
631
				    "subconnector",
632
				    ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
632
				    ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
633
	for (i = 0; i < ARRAY_SIZE(drm_dvi_i_subconnector_enum_list); i++)
633
	for (i = 0; i < ARRAY_SIZE(drm_dvi_i_subconnector_enum_list); i++)
634
		drm_property_add_enum(dvi_i_subconnector, i,
634
		drm_property_add_enum(dvi_i_subconnector, i,
635
				      drm_dvi_i_subconnector_enum_list[i].type,
635
				      drm_dvi_i_subconnector_enum_list[i].type,
636
				      drm_dvi_i_subconnector_enum_list[i].name);
636
				      drm_dvi_i_subconnector_enum_list[i].name);
637
	dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
637
	dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
638
 
638
 
639
	return 0;
639
	return 0;
640
}
640
}
641
EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
641
EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
642
 
642
 
643
/**
643
/**
644
 * drm_create_tv_properties - create TV specific connector properties
644
 * drm_create_tv_properties - create TV specific connector properties
645
 * @dev: DRM device
645
 * @dev: DRM device
646
 * @num_modes: number of different TV formats (modes) supported
646
 * @num_modes: number of different TV formats (modes) supported
647
 * @modes: array of pointers to strings containing name of each format
647
 * @modes: array of pointers to strings containing name of each format
648
 *
648
 *
649
 * Called by a driver's TV initialization routine, this function creates
649
 * Called by a driver's TV initialization routine, this function creates
650
 * the TV specific connector properties for a given device.  Caller is
650
 * the TV specific connector properties for a given device.  Caller is
651
 * responsible for allocating a list of format names and passing them to
651
 * responsible for allocating a list of format names and passing them to
652
 * this routine.
652
 * this routine.
653
 */
653
 */
654
int drm_mode_create_tv_properties(struct drm_device *dev, int num_modes,
654
int drm_mode_create_tv_properties(struct drm_device *dev, int num_modes,
655
				  char *modes[])
655
				  char *modes[])
656
{
656
{
657
	struct drm_property *tv_selector;
657
	struct drm_property *tv_selector;
658
	struct drm_property *tv_subconnector;
658
	struct drm_property *tv_subconnector;
659
	int i;
659
	int i;
660
 
660
 
661
	if (dev->mode_config.tv_select_subconnector_property)
661
	if (dev->mode_config.tv_select_subconnector_property)
662
		return 0;
662
		return 0;
663
 
663
 
664
	/*
664
	/*
665
	 * Basic connector properties
665
	 * Basic connector properties
666
	 */
666
	 */
667
	tv_selector = drm_property_create(dev, DRM_MODE_PROP_ENUM,
667
	tv_selector = drm_property_create(dev, DRM_MODE_PROP_ENUM,
668
					  "select subconnector",
668
					  "select subconnector",
669
					  ARRAY_SIZE(drm_tv_select_enum_list));
669
					  ARRAY_SIZE(drm_tv_select_enum_list));
670
	for (i = 0; i < ARRAY_SIZE(drm_tv_select_enum_list); i++)
670
	for (i = 0; i < ARRAY_SIZE(drm_tv_select_enum_list); i++)
671
		drm_property_add_enum(tv_selector, i,
671
		drm_property_add_enum(tv_selector, i,
672
				      drm_tv_select_enum_list[i].type,
672
				      drm_tv_select_enum_list[i].type,
673
				      drm_tv_select_enum_list[i].name);
673
				      drm_tv_select_enum_list[i].name);
674
	dev->mode_config.tv_select_subconnector_property = tv_selector;
674
	dev->mode_config.tv_select_subconnector_property = tv_selector;
675
 
675
 
676
	tv_subconnector =
676
	tv_subconnector =
677
		drm_property_create(dev, DRM_MODE_PROP_ENUM |
677
		drm_property_create(dev, DRM_MODE_PROP_ENUM |
678
				    DRM_MODE_PROP_IMMUTABLE, "subconnector",
678
				    DRM_MODE_PROP_IMMUTABLE, "subconnector",
679
				    ARRAY_SIZE(drm_tv_subconnector_enum_list));
679
				    ARRAY_SIZE(drm_tv_subconnector_enum_list));
680
	for (i = 0; i < ARRAY_SIZE(drm_tv_subconnector_enum_list); i++)
680
	for (i = 0; i < ARRAY_SIZE(drm_tv_subconnector_enum_list); i++)
681
		drm_property_add_enum(tv_subconnector, i,
681
		drm_property_add_enum(tv_subconnector, i,
682
				      drm_tv_subconnector_enum_list[i].type,
682
				      drm_tv_subconnector_enum_list[i].type,
683
				      drm_tv_subconnector_enum_list[i].name);
683
				      drm_tv_subconnector_enum_list[i].name);
684
	dev->mode_config.tv_subconnector_property = tv_subconnector;
684
	dev->mode_config.tv_subconnector_property = tv_subconnector;
685
 
685
 
686
	/*
686
	/*
687
	 * Other, TV specific properties: margins & TV modes.
687
	 * Other, TV specific properties: margins & TV modes.
688
	 */
688
	 */
689
	dev->mode_config.tv_left_margin_property =
689
	dev->mode_config.tv_left_margin_property =
690
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
690
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
691
				    "left margin", 2);
691
				    "left margin", 2);
692
	dev->mode_config.tv_left_margin_property->values[0] = 0;
692
	dev->mode_config.tv_left_margin_property->values[0] = 0;
693
	dev->mode_config.tv_left_margin_property->values[1] = 100;
693
	dev->mode_config.tv_left_margin_property->values[1] = 100;
694
 
694
 
695
	dev->mode_config.tv_right_margin_property =
695
	dev->mode_config.tv_right_margin_property =
696
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
696
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
697
				    "right margin", 2);
697
				    "right margin", 2);
698
	dev->mode_config.tv_right_margin_property->values[0] = 0;
698
	dev->mode_config.tv_right_margin_property->values[0] = 0;
699
	dev->mode_config.tv_right_margin_property->values[1] = 100;
699
	dev->mode_config.tv_right_margin_property->values[1] = 100;
700
 
700
 
701
	dev->mode_config.tv_top_margin_property =
701
	dev->mode_config.tv_top_margin_property =
702
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
702
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
703
				    "top margin", 2);
703
				    "top margin", 2);
704
	dev->mode_config.tv_top_margin_property->values[0] = 0;
704
	dev->mode_config.tv_top_margin_property->values[0] = 0;
705
	dev->mode_config.tv_top_margin_property->values[1] = 100;
705
	dev->mode_config.tv_top_margin_property->values[1] = 100;
706
 
706
 
707
	dev->mode_config.tv_bottom_margin_property =
707
	dev->mode_config.tv_bottom_margin_property =
708
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
708
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
709
				    "bottom margin", 2);
709
				    "bottom margin", 2);
710
	dev->mode_config.tv_bottom_margin_property->values[0] = 0;
710
	dev->mode_config.tv_bottom_margin_property->values[0] = 0;
711
	dev->mode_config.tv_bottom_margin_property->values[1] = 100;
711
	dev->mode_config.tv_bottom_margin_property->values[1] = 100;
712
 
712
 
713
	dev->mode_config.tv_mode_property =
713
	dev->mode_config.tv_mode_property =
714
		drm_property_create(dev, DRM_MODE_PROP_ENUM,
714
		drm_property_create(dev, DRM_MODE_PROP_ENUM,
715
				    "mode", num_modes);
715
				    "mode", num_modes);
716
	for (i = 0; i < num_modes; i++)
716
	for (i = 0; i < num_modes; i++)
717
		drm_property_add_enum(dev->mode_config.tv_mode_property, i,
717
		drm_property_add_enum(dev->mode_config.tv_mode_property, i,
718
				      i, modes[i]);
718
				      i, modes[i]);
719
 
719
 
720
	dev->mode_config.tv_brightness_property =
720
	dev->mode_config.tv_brightness_property =
721
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
721
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
722
				    "brightness", 2);
722
				    "brightness", 2);
723
	dev->mode_config.tv_brightness_property->values[0] = 0;
723
	dev->mode_config.tv_brightness_property->values[0] = 0;
724
	dev->mode_config.tv_brightness_property->values[1] = 100;
724
	dev->mode_config.tv_brightness_property->values[1] = 100;
725
 
725
 
726
	dev->mode_config.tv_contrast_property =
726
	dev->mode_config.tv_contrast_property =
727
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
727
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
728
				    "contrast", 2);
728
				    "contrast", 2);
729
	dev->mode_config.tv_contrast_property->values[0] = 0;
729
	dev->mode_config.tv_contrast_property->values[0] = 0;
730
	dev->mode_config.tv_contrast_property->values[1] = 100;
730
	dev->mode_config.tv_contrast_property->values[1] = 100;
731
 
731
 
732
	dev->mode_config.tv_flicker_reduction_property =
732
	dev->mode_config.tv_flicker_reduction_property =
733
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
733
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
734
				    "flicker reduction", 2);
734
				    "flicker reduction", 2);
735
	dev->mode_config.tv_flicker_reduction_property->values[0] = 0;
735
	dev->mode_config.tv_flicker_reduction_property->values[0] = 0;
736
	dev->mode_config.tv_flicker_reduction_property->values[1] = 100;
736
	dev->mode_config.tv_flicker_reduction_property->values[1] = 100;
737
 
737
 
738
	dev->mode_config.tv_overscan_property =
738
	dev->mode_config.tv_overscan_property =
739
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
739
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
740
				    "overscan", 2);
740
				    "overscan", 2);
741
	dev->mode_config.tv_overscan_property->values[0] = 0;
741
	dev->mode_config.tv_overscan_property->values[0] = 0;
742
	dev->mode_config.tv_overscan_property->values[1] = 100;
742
	dev->mode_config.tv_overscan_property->values[1] = 100;
743
 
743
 
744
	dev->mode_config.tv_saturation_property =
744
	dev->mode_config.tv_saturation_property =
745
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
745
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
746
				    "saturation", 2);
746
				    "saturation", 2);
747
	dev->mode_config.tv_saturation_property->values[0] = 0;
747
	dev->mode_config.tv_saturation_property->values[0] = 0;
748
	dev->mode_config.tv_saturation_property->values[1] = 100;
748
	dev->mode_config.tv_saturation_property->values[1] = 100;
749
 
749
 
750
	dev->mode_config.tv_hue_property =
750
	dev->mode_config.tv_hue_property =
751
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
751
		drm_property_create(dev, DRM_MODE_PROP_RANGE,
752
				    "hue", 2);
752
				    "hue", 2);
753
	dev->mode_config.tv_hue_property->values[0] = 0;
753
	dev->mode_config.tv_hue_property->values[0] = 0;
754
	dev->mode_config.tv_hue_property->values[1] = 100;
754
	dev->mode_config.tv_hue_property->values[1] = 100;
755
 
755
 
756
	return 0;
756
	return 0;
757
}
757
}
758
EXPORT_SYMBOL(drm_mode_create_tv_properties);
758
EXPORT_SYMBOL(drm_mode_create_tv_properties);
759
 
759
 
760
/**
760
/**
761
 * drm_mode_create_scaling_mode_property - create scaling mode property
761
 * drm_mode_create_scaling_mode_property - create scaling mode property
762
 * @dev: DRM device
762
 * @dev: DRM device
763
 *
763
 *
764
 * Called by a driver the first time it's needed, must be attached to desired
764
 * Called by a driver the first time it's needed, must be attached to desired
765
 * connectors.
765
 * connectors.
766
 */
766
 */
767
int drm_mode_create_scaling_mode_property(struct drm_device *dev)
767
int drm_mode_create_scaling_mode_property(struct drm_device *dev)
768
{
768
{
769
	struct drm_property *scaling_mode;
769
	struct drm_property *scaling_mode;
770
	int i;
770
	int i;
771
 
771
 
772
	if (dev->mode_config.scaling_mode_property)
772
	if (dev->mode_config.scaling_mode_property)
773
		return 0;
773
		return 0;
774
 
774
 
775
	scaling_mode =
775
	scaling_mode =
776
		drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
776
		drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
777
				    ARRAY_SIZE(drm_scaling_mode_enum_list));
777
				    ARRAY_SIZE(drm_scaling_mode_enum_list));
778
	for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++)
778
	for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++)
779
		drm_property_add_enum(scaling_mode, i,
779
		drm_property_add_enum(scaling_mode, i,
780
				      drm_scaling_mode_enum_list[i].type,
780
				      drm_scaling_mode_enum_list[i].type,
781
				      drm_scaling_mode_enum_list[i].name);
781
				      drm_scaling_mode_enum_list[i].name);
782
 
782
 
783
	dev->mode_config.scaling_mode_property = scaling_mode;
783
	dev->mode_config.scaling_mode_property = scaling_mode;
784
 
784
 
785
	return 0;
785
	return 0;
786
}
786
}
787
EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
787
EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
788
 
788
 
789
/**
789
/**
790
 * drm_mode_create_dithering_property - create dithering property
790
 * drm_mode_create_dithering_property - create dithering property
791
 * @dev: DRM device
791
 * @dev: DRM device
792
 *
792
 *
793
 * Called by a driver the first time it's needed, must be attached to desired
793
 * Called by a driver the first time it's needed, must be attached to desired
794
 * connectors.
794
 * connectors.
795
 */
795
 */
796
int drm_mode_create_dithering_property(struct drm_device *dev)
796
int drm_mode_create_dithering_property(struct drm_device *dev)
797
{
797
{
798
	struct drm_property *dithering_mode;
798
	struct drm_property *dithering_mode;
799
	int i;
799
	int i;
800
 
800
 
801
	if (dev->mode_config.dithering_mode_property)
801
	if (dev->mode_config.dithering_mode_property)
802
		return 0;
802
		return 0;
803
 
803
 
804
	dithering_mode =
804
	dithering_mode =
805
		drm_property_create(dev, DRM_MODE_PROP_ENUM, "dithering",
805
		drm_property_create(dev, DRM_MODE_PROP_ENUM, "dithering",
806
				    ARRAY_SIZE(drm_dithering_mode_enum_list));
806
				    ARRAY_SIZE(drm_dithering_mode_enum_list));
807
	for (i = 0; i < ARRAY_SIZE(drm_dithering_mode_enum_list); i++)
807
	for (i = 0; i < ARRAY_SIZE(drm_dithering_mode_enum_list); i++)
808
		drm_property_add_enum(dithering_mode, i,
808
		drm_property_add_enum(dithering_mode, i,
809
				      drm_dithering_mode_enum_list[i].type,
809
				      drm_dithering_mode_enum_list[i].type,
810
				      drm_dithering_mode_enum_list[i].name);
810
				      drm_dithering_mode_enum_list[i].name);
811
	dev->mode_config.dithering_mode_property = dithering_mode;
811
	dev->mode_config.dithering_mode_property = dithering_mode;
812
 
812
 
813
	return 0;
813
	return 0;
814
}
814
}
815
EXPORT_SYMBOL(drm_mode_create_dithering_property);
815
EXPORT_SYMBOL(drm_mode_create_dithering_property);
816
 
816
 
817
/**
817
/**
818
 * drm_mode_create_dirty_property - create dirty property
818
 * drm_mode_create_dirty_property - create dirty property
819
 * @dev: DRM device
819
 * @dev: DRM device
820
 *
820
 *
821
 * Called by a driver the first time it's needed, must be attached to desired
821
 * Called by a driver the first time it's needed, must be attached to desired
822
 * connectors.
822
 * connectors.
823
 */
823
 */
824
int drm_mode_create_dirty_info_property(struct drm_device *dev)
824
int drm_mode_create_dirty_info_property(struct drm_device *dev)
825
{
825
{
826
	struct drm_property *dirty_info;
826
	struct drm_property *dirty_info;
827
	int i;
827
	int i;
828
 
828
 
829
	if (dev->mode_config.dirty_info_property)
829
	if (dev->mode_config.dirty_info_property)
830
		return 0;
830
		return 0;
831
 
831
 
832
	dirty_info =
832
	dirty_info =
833
		drm_property_create(dev, DRM_MODE_PROP_ENUM |
833
		drm_property_create(dev, DRM_MODE_PROP_ENUM |
834
				    DRM_MODE_PROP_IMMUTABLE,
834
				    DRM_MODE_PROP_IMMUTABLE,
835
				    "dirty",
835
				    "dirty",
836
				    ARRAY_SIZE(drm_dirty_info_enum_list));
836
				    ARRAY_SIZE(drm_dirty_info_enum_list));
837
	for (i = 0; i < ARRAY_SIZE(drm_dirty_info_enum_list); i++)
837
	for (i = 0; i < ARRAY_SIZE(drm_dirty_info_enum_list); i++)
838
		drm_property_add_enum(dirty_info, i,
838
		drm_property_add_enum(dirty_info, i,
839
				      drm_dirty_info_enum_list[i].type,
839
				      drm_dirty_info_enum_list[i].type,
840
				      drm_dirty_info_enum_list[i].name);
840
				      drm_dirty_info_enum_list[i].name);
841
	dev->mode_config.dirty_info_property = dirty_info;
841
	dev->mode_config.dirty_info_property = dirty_info;
842
 
842
 
843
	return 0;
843
	return 0;
844
}
844
}
845
EXPORT_SYMBOL(drm_mode_create_dirty_info_property);
845
EXPORT_SYMBOL(drm_mode_create_dirty_info_property);
846
 
846
 
847
/**
847
/**
848
 * drm_mode_config_init - initialize DRM mode_configuration structure
848
 * drm_mode_config_init - initialize DRM mode_configuration structure
849
 * @dev: DRM device
849
 * @dev: DRM device
850
 *
850
 *
851
 * LOCKING:
851
 * LOCKING:
852
 * None, should happen single threaded at init time.
852
 * None, should happen single threaded at init time.
853
 *
853
 *
854
 * Initialize @dev's mode_config structure, used for tracking the graphics
854
 * Initialize @dev's mode_config structure, used for tracking the graphics
855
 * configuration of @dev.
855
 * configuration of @dev.
856
 */
856
 */
857
void drm_mode_config_init(struct drm_device *dev)
857
void drm_mode_config_init(struct drm_device *dev)
858
{
858
{
859
	mutex_init(&dev->mode_config.mutex);
859
	mutex_init(&dev->mode_config.mutex);
860
	mutex_init(&dev->mode_config.idr_mutex);
860
	mutex_init(&dev->mode_config.idr_mutex);
861
	INIT_LIST_HEAD(&dev->mode_config.fb_list);
861
	INIT_LIST_HEAD(&dev->mode_config.fb_list);
862
	INIT_LIST_HEAD(&dev->mode_config.crtc_list);
862
	INIT_LIST_HEAD(&dev->mode_config.crtc_list);
863
	INIT_LIST_HEAD(&dev->mode_config.connector_list);
863
	INIT_LIST_HEAD(&dev->mode_config.connector_list);
864
	INIT_LIST_HEAD(&dev->mode_config.encoder_list);
864
	INIT_LIST_HEAD(&dev->mode_config.encoder_list);
865
	INIT_LIST_HEAD(&dev->mode_config.property_list);
865
	INIT_LIST_HEAD(&dev->mode_config.property_list);
866
	INIT_LIST_HEAD(&dev->mode_config.property_blob_list);
866
	INIT_LIST_HEAD(&dev->mode_config.property_blob_list);
867
	idr_init(&dev->mode_config.crtc_idr);
867
	idr_init(&dev->mode_config.crtc_idr);
868
 
868
 
869
	mutex_lock(&dev->mode_config.mutex);
869
	mutex_lock(&dev->mode_config.mutex);
870
	drm_mode_create_standard_connector_properties(dev);
870
	drm_mode_create_standard_connector_properties(dev);
871
	mutex_unlock(&dev->mode_config.mutex);
871
	mutex_unlock(&dev->mode_config.mutex);
872
 
872
 
873
	/* Just to be sure */
873
	/* Just to be sure */
874
	dev->mode_config.num_fb = 0;
874
	dev->mode_config.num_fb = 0;
875
	dev->mode_config.num_connector = 0;
875
	dev->mode_config.num_connector = 0;
876
	dev->mode_config.num_crtc = 0;
876
	dev->mode_config.num_crtc = 0;
877
	dev->mode_config.num_encoder = 0;
877
	dev->mode_config.num_encoder = 0;
878
}
878
}
879
EXPORT_SYMBOL(drm_mode_config_init);
879
EXPORT_SYMBOL(drm_mode_config_init);
880
 
880
 
881
int drm_mode_group_init(struct drm_device *dev, struct drm_mode_group *group)
881
int drm_mode_group_init(struct drm_device *dev, struct drm_mode_group *group)
882
{
882
{
883
	uint32_t total_objects = 0;
883
	uint32_t total_objects = 0;
884
 
884
 
885
	total_objects += dev->mode_config.num_crtc;
885
	total_objects += dev->mode_config.num_crtc;
886
	total_objects += dev->mode_config.num_connector;
886
	total_objects += dev->mode_config.num_connector;
887
	total_objects += dev->mode_config.num_encoder;
887
	total_objects += dev->mode_config.num_encoder;
888
 
-
 
889
	if (total_objects == 0)
-
 
890
		return -EINVAL;
-
 
891
 
888
 
892
	group->id_list = kzalloc(total_objects * sizeof(uint32_t), GFP_KERNEL);
889
	group->id_list = kzalloc(total_objects * sizeof(uint32_t), GFP_KERNEL);
893
	if (!group->id_list)
890
	if (!group->id_list)
894
		return -ENOMEM;
891
		return -ENOMEM;
895
 
892
 
896
	group->num_crtcs = 0;
893
	group->num_crtcs = 0;
897
	group->num_connectors = 0;
894
	group->num_connectors = 0;
898
	group->num_encoders = 0;
895
	group->num_encoders = 0;
899
	return 0;
896
	return 0;
900
}
897
}
901
 
898
 
902
int drm_mode_group_init_legacy_group(struct drm_device *dev,
899
int drm_mode_group_init_legacy_group(struct drm_device *dev,
903
				     struct drm_mode_group *group)
900
				     struct drm_mode_group *group)
904
{
901
{
905
	struct drm_crtc *crtc;
902
	struct drm_crtc *crtc;
906
	struct drm_encoder *encoder;
903
	struct drm_encoder *encoder;
907
	struct drm_connector *connector;
904
	struct drm_connector *connector;
908
	int ret;
905
	int ret;
909
 
906
 
910
	if ((ret = drm_mode_group_init(dev, group)))
907
	if ((ret = drm_mode_group_init(dev, group)))
911
		return ret;
908
		return ret;
912
 
909
 
913
	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
910
	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
914
		group->id_list[group->num_crtcs++] = crtc->base.id;
911
		group->id_list[group->num_crtcs++] = crtc->base.id;
915
 
912
 
916
	list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
913
	list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
917
		group->id_list[group->num_crtcs + group->num_encoders++] =
914
		group->id_list[group->num_crtcs + group->num_encoders++] =
918
		encoder->base.id;
915
		encoder->base.id;
919
 
916
 
920
	list_for_each_entry(connector, &dev->mode_config.connector_list, head)
917
	list_for_each_entry(connector, &dev->mode_config.connector_list, head)
921
		group->id_list[group->num_crtcs + group->num_encoders +
918
		group->id_list[group->num_crtcs + group->num_encoders +
922
			       group->num_connectors++] = connector->base.id;
919
			       group->num_connectors++] = connector->base.id;
923
 
920
 
924
	return 0;
921
	return 0;
925
}
922
}
926
 
923
 
927
/**
924
/**
928
 * drm_mode_config_cleanup - free up DRM mode_config info
925
 * drm_mode_config_cleanup - free up DRM mode_config info
929
 * @dev: DRM device
926
 * @dev: DRM device
930
 *
927
 *
931
 * LOCKING:
928
 * LOCKING:
932
 * Caller must hold mode config lock.
929
 * Caller must hold mode config lock.
933
 *
930
 *
934
 * Free up all the connectors and CRTCs associated with this DRM device, then
931
 * Free up all the connectors and CRTCs associated with this DRM device, then
935
 * free up the framebuffers and associated buffer objects.
932
 * free up the framebuffers and associated buffer objects.
936
 *
933
 *
937
 * FIXME: cleanup any dangling user buffer objects too
934
 * FIXME: cleanup any dangling user buffer objects too
938
 */
935
 */
939
void drm_mode_config_cleanup(struct drm_device *dev)
936
void drm_mode_config_cleanup(struct drm_device *dev)
940
{
937
{
941
	struct drm_connector *connector, *ot;
938
	struct drm_connector *connector, *ot;
942
	struct drm_crtc *crtc, *ct;
939
	struct drm_crtc *crtc, *ct;
943
	struct drm_encoder *encoder, *enct;
940
	struct drm_encoder *encoder, *enct;
944
	struct drm_framebuffer *fb, *fbt;
941
	struct drm_framebuffer *fb, *fbt;
945
	struct drm_property *property, *pt;
942
	struct drm_property *property, *pt;
946
 
943
 
947
	list_for_each_entry_safe(encoder, enct, &dev->mode_config.encoder_list,
944
	list_for_each_entry_safe(encoder, enct, &dev->mode_config.encoder_list,
948
				 head) {
945
				 head) {
949
		encoder->funcs->destroy(encoder);
946
		encoder->funcs->destroy(encoder);
950
	}
947
	}
951
 
948
 
952
	list_for_each_entry_safe(connector, ot,
949
	list_for_each_entry_safe(connector, ot,
953
				 &dev->mode_config.connector_list, head) {
950
				 &dev->mode_config.connector_list, head) {
954
		connector->funcs->destroy(connector);
951
		connector->funcs->destroy(connector);
955
	}
952
	}
956
 
953
 
957
	list_for_each_entry_safe(property, pt, &dev->mode_config.property_list,
954
	list_for_each_entry_safe(property, pt, &dev->mode_config.property_list,
958
				 head) {
955
				 head) {
959
		drm_property_destroy(dev, property);
956
		drm_property_destroy(dev, property);
960
	}
957
	}
961
 
958
 
962
	list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) {
959
	list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) {
963
		fb->funcs->destroy(fb);
960
		fb->funcs->destroy(fb);
964
	}
961
	}
965
 
962
 
966
	list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) {
963
	list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) {
967
		crtc->funcs->destroy(crtc);
964
		crtc->funcs->destroy(crtc);
968
	}
965
	}
969
 
966
 
970
}
967
}
971
EXPORT_SYMBOL(drm_mode_config_cleanup);
968
EXPORT_SYMBOL(drm_mode_config_cleanup);
972
 
969
 
973
/**
970
/**
974
 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
971
 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
975
 * @out: drm_mode_modeinfo struct to return to the user
972
 * @out: drm_mode_modeinfo struct to return to the user
976
 * @in: drm_display_mode to use
973
 * @in: drm_display_mode to use
977
 *
974
 *
978
 * LOCKING:
975
 * LOCKING:
979
 * None.
976
 * None.
980
 *
977
 *
981
 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
978
 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
982
 * the user.
979
 * the user.
983
 */
980
 */
984
void drm_crtc_convert_to_umode(struct drm_mode_modeinfo *out,
981
void drm_crtc_convert_to_umode(struct drm_mode_modeinfo *out,
985
			       struct drm_display_mode *in)
982
			       struct drm_display_mode *in)
986
{
983
{
987
	out->clock = in->clock;
984
	out->clock = in->clock;
988
	out->hdisplay = in->hdisplay;
985
	out->hdisplay = in->hdisplay;
989
	out->hsync_start = in->hsync_start;
986
	out->hsync_start = in->hsync_start;
990
	out->hsync_end = in->hsync_end;
987
	out->hsync_end = in->hsync_end;
991
	out->htotal = in->htotal;
988
	out->htotal = in->htotal;
992
	out->hskew = in->hskew;
989
	out->hskew = in->hskew;
993
	out->vdisplay = in->vdisplay;
990
	out->vdisplay = in->vdisplay;
994
	out->vsync_start = in->vsync_start;
991
	out->vsync_start = in->vsync_start;
995
	out->vsync_end = in->vsync_end;
992
	out->vsync_end = in->vsync_end;
996
	out->vtotal = in->vtotal;
993
	out->vtotal = in->vtotal;
997
	out->vscan = in->vscan;
994
	out->vscan = in->vscan;
998
	out->vrefresh = in->vrefresh;
995
	out->vrefresh = in->vrefresh;
999
	out->flags = in->flags;
996
	out->flags = in->flags;
1000
	out->type = in->type;
997
	out->type = in->type;
1001
	strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
998
	strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
1002
	out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
999
	out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
1003
}
1000
}
1004
 
1001
 
1005
/**
1002
/**
1006
 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
1003
 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
1007
 * @out: drm_display_mode to return to the user
1004
 * @out: drm_display_mode to return to the user
1008
 * @in: drm_mode_modeinfo to use
1005
 * @in: drm_mode_modeinfo to use
1009
 *
1006
 *
1010
 * LOCKING:
1007
 * LOCKING:
1011
 * None.
1008
 * None.
1012
 *
1009
 *
1013
 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1010
 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1014
 * the caller.
1011
 * the caller.
1015
 */
1012
 */
1016
void drm_crtc_convert_umode(struct drm_display_mode *out,
1013
void drm_crtc_convert_umode(struct drm_display_mode *out,
1017
			    struct drm_mode_modeinfo *in)
1014
			    struct drm_mode_modeinfo *in)
1018
{
1015
{
1019
	out->clock = in->clock;
1016
	out->clock = in->clock;
1020
	out->hdisplay = in->hdisplay;
1017
	out->hdisplay = in->hdisplay;
1021
	out->hsync_start = in->hsync_start;
1018
	out->hsync_start = in->hsync_start;
1022
	out->hsync_end = in->hsync_end;
1019
	out->hsync_end = in->hsync_end;
1023
	out->htotal = in->htotal;
1020
	out->htotal = in->htotal;
1024
	out->hskew = in->hskew;
1021
	out->hskew = in->hskew;
1025
	out->vdisplay = in->vdisplay;
1022
	out->vdisplay = in->vdisplay;
1026
	out->vsync_start = in->vsync_start;
1023
	out->vsync_start = in->vsync_start;
1027
	out->vsync_end = in->vsync_end;
1024
	out->vsync_end = in->vsync_end;
1028
	out->vtotal = in->vtotal;
1025
	out->vtotal = in->vtotal;
1029
	out->vscan = in->vscan;
1026
	out->vscan = in->vscan;
1030
	out->vrefresh = in->vrefresh;
1027
	out->vrefresh = in->vrefresh;
1031
	out->flags = in->flags;
1028
	out->flags = in->flags;
1032
	out->type = in->type;
1029
	out->type = in->type;
1033
	strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
1030
	strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
1034
	out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
1031
	out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
1035
}
1032
}
1036
 
1033
 
1037
 
1034
 
1038
#if 0
1035
#if 0
1039
/**
1036
/**
1040
 * drm_mode_getresources - get graphics configuration
1037
 * drm_mode_getresources - get graphics configuration
1041
 * @inode: inode from the ioctl
1038
 * @inode: inode from the ioctl
1042
 * @filp: file * from the ioctl
1039
 * @filp: file * from the ioctl
1043
 * @cmd: cmd from ioctl
1040
 * @cmd: cmd from ioctl
1044
 * @arg: arg from ioctl
1041
 * @arg: arg from ioctl
1045
 *
1042
 *
1046
 * LOCKING:
1043
 * LOCKING:
1047
 * Takes mode config lock.
1044
 * Takes mode config lock.
1048
 *
1045
 *
1049
 * Construct a set of configuration description structures and return
1046
 * Construct a set of configuration description structures and return
1050
 * them to the user, including CRTC, connector and framebuffer configuration.
1047
 * them to the user, including CRTC, connector and framebuffer configuration.
1051
 *
1048
 *
1052
 * Called by the user via ioctl.
1049
 * Called by the user via ioctl.
1053
 *
1050
 *
1054
 * RETURNS:
1051
 * RETURNS:
1055
 * Zero on success, errno on failure.
1052
 * Zero on success, errno on failure.
1056
 */
1053
 */
1057
int drm_mode_getresources(struct drm_device *dev, void *data,
1054
int drm_mode_getresources(struct drm_device *dev, void *data,
1058
			  struct drm_file *file_priv)
1055
			  struct drm_file *file_priv)
1059
{
1056
{
1060
	struct drm_mode_card_res *card_res = data;
1057
	struct drm_mode_card_res *card_res = data;
1061
	struct list_head *lh;
1058
	struct list_head *lh;
1062
	struct drm_framebuffer *fb;
1059
	struct drm_framebuffer *fb;
1063
	struct drm_connector *connector;
1060
	struct drm_connector *connector;
1064
	struct drm_crtc *crtc;
1061
	struct drm_crtc *crtc;
1065
	struct drm_encoder *encoder;
1062
	struct drm_encoder *encoder;
1066
	int ret = 0;
1063
	int ret = 0;
1067
	int connector_count = 0;
1064
	int connector_count = 0;
1068
	int crtc_count = 0;
1065
	int crtc_count = 0;
1069
	int fb_count = 0;
1066
	int fb_count = 0;
1070
	int encoder_count = 0;
1067
	int encoder_count = 0;
1071
	int copied = 0, i;
1068
	int copied = 0, i;
1072
	uint32_t __user *fb_id;
1069
	uint32_t __user *fb_id;
1073
	uint32_t __user *crtc_id;
1070
	uint32_t __user *crtc_id;
1074
	uint32_t __user *connector_id;
1071
	uint32_t __user *connector_id;
1075
	uint32_t __user *encoder_id;
1072
	uint32_t __user *encoder_id;
1076
	struct drm_mode_group *mode_group;
1073
	struct drm_mode_group *mode_group;
1077
 
1074
 
1078
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
1075
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
1079
		return -EINVAL;
1076
		return -EINVAL;
1080
 
1077
 
1081
	mutex_lock(&dev->mode_config.mutex);
1078
	mutex_lock(&dev->mode_config.mutex);
1082
 
1079
 
1083
	/*
1080
	/*
1084
	 * For the non-control nodes we need to limit the list of resources
1081
	 * For the non-control nodes we need to limit the list of resources
1085
	 * by IDs in the group list for this node
1082
	 * by IDs in the group list for this node
1086
	 */
1083
	 */
1087
	list_for_each(lh, &file_priv->fbs)
1084
	list_for_each(lh, &file_priv->fbs)
1088
		fb_count++;
1085
		fb_count++;
1089
 
1086
 
1090
	mode_group = &file_priv->master->minor->mode_group;
1087
	mode_group = &file_priv->master->minor->mode_group;
1091
	if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
1088
	if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
1092
 
1089
 
1093
		list_for_each(lh, &dev->mode_config.crtc_list)
1090
		list_for_each(lh, &dev->mode_config.crtc_list)
1094
			crtc_count++;
1091
			crtc_count++;
1095
 
1092
 
1096
		list_for_each(lh, &dev->mode_config.connector_list)
1093
		list_for_each(lh, &dev->mode_config.connector_list)
1097
			connector_count++;
1094
			connector_count++;
1098
 
1095
 
1099
		list_for_each(lh, &dev->mode_config.encoder_list)
1096
		list_for_each(lh, &dev->mode_config.encoder_list)
1100
			encoder_count++;
1097
			encoder_count++;
1101
	} else {
1098
	} else {
1102
 
1099
 
1103
		crtc_count = mode_group->num_crtcs;
1100
		crtc_count = mode_group->num_crtcs;
1104
		connector_count = mode_group->num_connectors;
1101
		connector_count = mode_group->num_connectors;
1105
		encoder_count = mode_group->num_encoders;
1102
		encoder_count = mode_group->num_encoders;
1106
	}
1103
	}
1107
 
1104
 
1108
	card_res->max_height = dev->mode_config.max_height;
1105
	card_res->max_height = dev->mode_config.max_height;
1109
	card_res->min_height = dev->mode_config.min_height;
1106
	card_res->min_height = dev->mode_config.min_height;
1110
	card_res->max_width = dev->mode_config.max_width;
1107
	card_res->max_width = dev->mode_config.max_width;
1111
	card_res->min_width = dev->mode_config.min_width;
1108
	card_res->min_width = dev->mode_config.min_width;
1112
 
1109
 
1113
	/* handle this in 4 parts */
1110
	/* handle this in 4 parts */
1114
	/* FBs */
1111
	/* FBs */
1115
	if (card_res->count_fbs >= fb_count) {
1112
	if (card_res->count_fbs >= fb_count) {
1116
		copied = 0;
1113
		copied = 0;
1117
		fb_id = (uint32_t __user *)(unsigned long)card_res->fb_id_ptr;
1114
		fb_id = (uint32_t __user *)(unsigned long)card_res->fb_id_ptr;
1118
		list_for_each_entry(fb, &file_priv->fbs, filp_head) {
1115
		list_for_each_entry(fb, &file_priv->fbs, filp_head) {
1119
			if (put_user(fb->base.id, fb_id + copied)) {
1116
			if (put_user(fb->base.id, fb_id + copied)) {
1120
				ret = -EFAULT;
1117
				ret = -EFAULT;
1121
				goto out;
1118
				goto out;
1122
			}
1119
			}
1123
			copied++;
1120
			copied++;
1124
		}
1121
		}
1125
	}
1122
	}
1126
	card_res->count_fbs = fb_count;
1123
	card_res->count_fbs = fb_count;
1127
 
1124
 
1128
	/* CRTCs */
1125
	/* CRTCs */
1129
	if (card_res->count_crtcs >= crtc_count) {
1126
	if (card_res->count_crtcs >= crtc_count) {
1130
		copied = 0;
1127
		copied = 0;
1131
		crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr;
1128
		crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr;
1132
		if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
1129
		if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
1133
			list_for_each_entry(crtc, &dev->mode_config.crtc_list,
1130
			list_for_each_entry(crtc, &dev->mode_config.crtc_list,
1134
					    head) {
1131
					    head) {
1135
				DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
1132
				DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
1136
				if (put_user(crtc->base.id, crtc_id + copied)) {
1133
				if (put_user(crtc->base.id, crtc_id + copied)) {
1137
					ret = -EFAULT;
1134
					ret = -EFAULT;
1138
					goto out;
1135
					goto out;
1139
				}
1136
				}
1140
				copied++;
1137
				copied++;
1141
			}
1138
			}
1142
		} else {
1139
		} else {
1143
			for (i = 0; i < mode_group->num_crtcs; i++) {
1140
			for (i = 0; i < mode_group->num_crtcs; i++) {
1144
				if (put_user(mode_group->id_list[i],
1141
				if (put_user(mode_group->id_list[i],
1145
					     crtc_id + copied)) {
1142
					     crtc_id + copied)) {
1146
					ret = -EFAULT;
1143
					ret = -EFAULT;
1147
					goto out;
1144
					goto out;
1148
				}
1145
				}
1149
				copied++;
1146
				copied++;
1150
			}
1147
			}
1151
		}
1148
		}
1152
	}
1149
	}
1153
	card_res->count_crtcs = crtc_count;
1150
	card_res->count_crtcs = crtc_count;
1154
 
1151
 
1155
	/* Encoders */
1152
	/* Encoders */
1156
	if (card_res->count_encoders >= encoder_count) {
1153
	if (card_res->count_encoders >= encoder_count) {
1157
		copied = 0;
1154
		copied = 0;
1158
		encoder_id = (uint32_t __user *)(unsigned long)card_res->encoder_id_ptr;
1155
		encoder_id = (uint32_t __user *)(unsigned long)card_res->encoder_id_ptr;
1159
		if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
1156
		if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
1160
			list_for_each_entry(encoder,
1157
			list_for_each_entry(encoder,
1161
					    &dev->mode_config.encoder_list,
1158
					    &dev->mode_config.encoder_list,
1162
					    head) {
1159
					    head) {
1163
				DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder->base.id,
1160
				DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder->base.id,
1164
						drm_get_encoder_name(encoder));
1161
						drm_get_encoder_name(encoder));
1165
				if (put_user(encoder->base.id, encoder_id +
1162
				if (put_user(encoder->base.id, encoder_id +
1166
					     copied)) {
1163
					     copied)) {
1167
					ret = -EFAULT;
1164
					ret = -EFAULT;
1168
					goto out;
1165
					goto out;
1169
				}
1166
				}
1170
				copied++;
1167
				copied++;
1171
			}
1168
			}
1172
		} else {
1169
		} else {
1173
			for (i = mode_group->num_crtcs; i < mode_group->num_crtcs + mode_group->num_encoders; i++) {
1170
			for (i = mode_group->num_crtcs; i < mode_group->num_crtcs + mode_group->num_encoders; i++) {
1174
				if (put_user(mode_group->id_list[i],
1171
				if (put_user(mode_group->id_list[i],
1175
					     encoder_id + copied)) {
1172
					     encoder_id + copied)) {
1176
					ret = -EFAULT;
1173
					ret = -EFAULT;
1177
					goto out;
1174
					goto out;
1178
				}
1175
				}
1179
				copied++;
1176
				copied++;
1180
			}
1177
			}
1181
 
1178
 
1182
		}
1179
		}
1183
	}
1180
	}
1184
	card_res->count_encoders = encoder_count;
1181
	card_res->count_encoders = encoder_count;
1185
 
1182
 
1186
	/* Connectors */
1183
	/* Connectors */
1187
	if (card_res->count_connectors >= connector_count) {
1184
	if (card_res->count_connectors >= connector_count) {
1188
		copied = 0;
1185
		copied = 0;
1189
		connector_id = (uint32_t __user *)(unsigned long)card_res->connector_id_ptr;
1186
		connector_id = (uint32_t __user *)(unsigned long)card_res->connector_id_ptr;
1190
		if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
1187
		if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
1191
			list_for_each_entry(connector,
1188
			list_for_each_entry(connector,
1192
					    &dev->mode_config.connector_list,
1189
					    &dev->mode_config.connector_list,
1193
					    head) {
1190
					    head) {
1194
				DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1191
				DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1195
					connector->base.id,
1192
					connector->base.id,
1196
					drm_get_connector_name(connector));
1193
					drm_get_connector_name(connector));
1197
				if (put_user(connector->base.id,
1194
				if (put_user(connector->base.id,
1198
					     connector_id + copied)) {
1195
					     connector_id + copied)) {
1199
					ret = -EFAULT;
1196
					ret = -EFAULT;
1200
					goto out;
1197
					goto out;
1201
				}
1198
				}
1202
				copied++;
1199
				copied++;
1203
			}
1200
			}
1204
		} else {
1201
		} else {
1205
			int start = mode_group->num_crtcs +
1202
			int start = mode_group->num_crtcs +
1206
				mode_group->num_encoders;
1203
				mode_group->num_encoders;
1207
			for (i = start; i < start + mode_group->num_connectors; i++) {
1204
			for (i = start; i < start + mode_group->num_connectors; i++) {
1208
				if (put_user(mode_group->id_list[i],
1205
				if (put_user(mode_group->id_list[i],
1209
					     connector_id + copied)) {
1206
					     connector_id + copied)) {
1210
					ret = -EFAULT;
1207
					ret = -EFAULT;
1211
					goto out;
1208
					goto out;
1212
				}
1209
				}
1213
				copied++;
1210
				copied++;
1214
			}
1211
			}
1215
		}
1212
		}
1216
	}
1213
	}
1217
	card_res->count_connectors = connector_count;
1214
	card_res->count_connectors = connector_count;
1218
 
1215
 
1219
	DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res->count_crtcs,
1216
	DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res->count_crtcs,
1220
		  card_res->count_connectors, card_res->count_encoders);
1217
		  card_res->count_connectors, card_res->count_encoders);
1221
 
1218
 
1222
out:
1219
out:
1223
	mutex_unlock(&dev->mode_config.mutex);
1220
	mutex_unlock(&dev->mode_config.mutex);
1224
	return ret;
1221
	return ret;
1225
}
1222
}
1226
 
1223
 
1227
/**
1224
/**
1228
 * drm_mode_getcrtc - get CRTC configuration
1225
 * drm_mode_getcrtc - get CRTC configuration
1229
 * @inode: inode from the ioctl
1226
 * @inode: inode from the ioctl
1230
 * @filp: file * from the ioctl
1227
 * @filp: file * from the ioctl
1231
 * @cmd: cmd from ioctl
1228
 * @cmd: cmd from ioctl
1232
 * @arg: arg from ioctl
1229
 * @arg: arg from ioctl
1233
 *
1230
 *
1234
 * LOCKING:
1231
 * LOCKING:
1235
 * Caller? (FIXME)
1232
 * Caller? (FIXME)
1236
 *
1233
 *
1237
 * Construct a CRTC configuration structure to return to the user.
1234
 * Construct a CRTC configuration structure to return to the user.
1238
 *
1235
 *
1239
 * Called by the user via ioctl.
1236
 * Called by the user via ioctl.
1240
 *
1237
 *
1241
 * RETURNS:
1238
 * RETURNS:
1242
 * Zero on success, errno on failure.
1239
 * Zero on success, errno on failure.
1243
 */
1240
 */
1244
int drm_mode_getcrtc(struct drm_device *dev,
1241
int drm_mode_getcrtc(struct drm_device *dev,
1245
		     void *data, struct drm_file *file_priv)
1242
		     void *data, struct drm_file *file_priv)
1246
{
1243
{
1247
	struct drm_mode_crtc *crtc_resp = data;
1244
	struct drm_mode_crtc *crtc_resp = data;
1248
	struct drm_crtc *crtc;
1245
	struct drm_crtc *crtc;
1249
	struct drm_mode_object *obj;
1246
	struct drm_mode_object *obj;
1250
	int ret = 0;
1247
	int ret = 0;
1251
 
1248
 
1252
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
1249
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
1253
		return -EINVAL;
1250
		return -EINVAL;
1254
 
1251
 
1255
	mutex_lock(&dev->mode_config.mutex);
1252
	mutex_lock(&dev->mode_config.mutex);
1256
 
1253
 
1257
	obj = drm_mode_object_find(dev, crtc_resp->crtc_id,
1254
	obj = drm_mode_object_find(dev, crtc_resp->crtc_id,
1258
				   DRM_MODE_OBJECT_CRTC);
1255
				   DRM_MODE_OBJECT_CRTC);
1259
	if (!obj) {
1256
	if (!obj) {
1260
		ret = -EINVAL;
1257
		ret = -EINVAL;
1261
		goto out;
1258
		goto out;
1262
	}
1259
	}
1263
	crtc = obj_to_crtc(obj);
1260
	crtc = obj_to_crtc(obj);
1264
 
1261
 
1265
	crtc_resp->x = crtc->x;
1262
	crtc_resp->x = crtc->x;
1266
	crtc_resp->y = crtc->y;
1263
	crtc_resp->y = crtc->y;
1267
	crtc_resp->gamma_size = crtc->gamma_size;
1264
	crtc_resp->gamma_size = crtc->gamma_size;
1268
	if (crtc->fb)
1265
	if (crtc->fb)
1269
		crtc_resp->fb_id = crtc->fb->base.id;
1266
		crtc_resp->fb_id = crtc->fb->base.id;
1270
	else
1267
	else
1271
		crtc_resp->fb_id = 0;
1268
		crtc_resp->fb_id = 0;
1272
 
1269
 
1273
	if (crtc->enabled) {
1270
	if (crtc->enabled) {
1274
 
1271
 
1275
		drm_crtc_convert_to_umode(&crtc_resp->mode, &crtc->mode);
1272
		drm_crtc_convert_to_umode(&crtc_resp->mode, &crtc->mode);
1276
		crtc_resp->mode_valid = 1;
1273
		crtc_resp->mode_valid = 1;
1277
 
1274
 
1278
	} else {
1275
	} else {
1279
		crtc_resp->mode_valid = 0;
1276
		crtc_resp->mode_valid = 0;
1280
	}
1277
	}
1281
 
1278
 
1282
out:
1279
out:
1283
	mutex_unlock(&dev->mode_config.mutex);
1280
	mutex_unlock(&dev->mode_config.mutex);
1284
	return ret;
1281
	return ret;
1285
}
1282
}
1286
 
1283
 
1287
/**
1284
/**
1288
 * drm_mode_getconnector - get connector configuration
1285
 * drm_mode_getconnector - get connector configuration
1289
 * @inode: inode from the ioctl
1286
 * @inode: inode from the ioctl
1290
 * @filp: file * from the ioctl
1287
 * @filp: file * from the ioctl
1291
 * @cmd: cmd from ioctl
1288
 * @cmd: cmd from ioctl
1292
 * @arg: arg from ioctl
1289
 * @arg: arg from ioctl
1293
 *
1290
 *
1294
 * LOCKING:
1291
 * LOCKING:
1295
 * Caller? (FIXME)
1292
 * Caller? (FIXME)
1296
 *
1293
 *
1297
 * Construct a connector configuration structure to return to the user.
1294
 * Construct a connector configuration structure to return to the user.
1298
 *
1295
 *
1299
 * Called by the user via ioctl.
1296
 * Called by the user via ioctl.
1300
 *
1297
 *
1301
 * RETURNS:
1298
 * RETURNS:
1302
 * Zero on success, errno on failure.
1299
 * Zero on success, errno on failure.
1303
 */
1300
 */
1304
int drm_mode_getconnector(struct drm_device *dev, void *data,
1301
int drm_mode_getconnector(struct drm_device *dev, void *data,
1305
			  struct drm_file *file_priv)
1302
			  struct drm_file *file_priv)
1306
{
1303
{
1307
	struct drm_mode_get_connector *out_resp = data;
1304
	struct drm_mode_get_connector *out_resp = data;
1308
	struct drm_mode_object *obj;
1305
	struct drm_mode_object *obj;
1309
	struct drm_connector *connector;
1306
	struct drm_connector *connector;
1310
	struct drm_display_mode *mode;
1307
	struct drm_display_mode *mode;
1311
	int mode_count = 0;
1308
	int mode_count = 0;
1312
	int props_count = 0;
1309
	int props_count = 0;
1313
	int encoders_count = 0;
1310
	int encoders_count = 0;
1314
	int ret = 0;
1311
	int ret = 0;
1315
	int copied = 0;
1312
	int copied = 0;
1316
	int i;
1313
	int i;
1317
	struct drm_mode_modeinfo u_mode;
1314
	struct drm_mode_modeinfo u_mode;
1318
	struct drm_mode_modeinfo __user *mode_ptr;
1315
	struct drm_mode_modeinfo __user *mode_ptr;
1319
	uint32_t __user *prop_ptr;
1316
	uint32_t __user *prop_ptr;
1320
	uint64_t __user *prop_values;
1317
	uint64_t __user *prop_values;
1321
	uint32_t __user *encoder_ptr;
1318
	uint32_t __user *encoder_ptr;
1322
 
1319
 
1323
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
1320
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
1324
		return -EINVAL;
1321
		return -EINVAL;
1325
 
1322
 
1326
	memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
1323
	memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
1327
 
1324
 
1328
	DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp->connector_id);
1325
	DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp->connector_id);
1329
 
1326
 
1330
	mutex_lock(&dev->mode_config.mutex);
1327
	mutex_lock(&dev->mode_config.mutex);
1331
 
1328
 
1332
	obj = drm_mode_object_find(dev, out_resp->connector_id,
1329
	obj = drm_mode_object_find(dev, out_resp->connector_id,
1333
				   DRM_MODE_OBJECT_CONNECTOR);
1330
				   DRM_MODE_OBJECT_CONNECTOR);
1334
	if (!obj) {
1331
	if (!obj) {
1335
		ret = -EINVAL;
1332
		ret = -EINVAL;
1336
		goto out;
1333
		goto out;
1337
	}
1334
	}
1338
	connector = obj_to_connector(obj);
1335
	connector = obj_to_connector(obj);
1339
 
1336
 
1340
	for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
1337
	for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
1341
		if (connector->property_ids[i] != 0) {
1338
		if (connector->property_ids[i] != 0) {
1342
			props_count++;
1339
			props_count++;
1343
		}
1340
		}
1344
	}
1341
	}
1345
 
1342
 
1346
	for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1343
	for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1347
		if (connector->encoder_ids[i] != 0) {
1344
		if (connector->encoder_ids[i] != 0) {
1348
			encoders_count++;
1345
			encoders_count++;
1349
		}
1346
		}
1350
	}
1347
	}
1351
 
1348
 
1352
	if (out_resp->count_modes == 0) {
1349
	if (out_resp->count_modes == 0) {
1353
		connector->funcs->fill_modes(connector,
1350
		connector->funcs->fill_modes(connector,
1354
					     dev->mode_config.max_width,
1351
					     dev->mode_config.max_width,
1355
					     dev->mode_config.max_height);
1352
					     dev->mode_config.max_height);
1356
	}
1353
	}
1357
 
1354
 
1358
	/* delayed so we get modes regardless of pre-fill_modes state */
1355
	/* delayed so we get modes regardless of pre-fill_modes state */
1359
	list_for_each_entry(mode, &connector->modes, head)
1356
	list_for_each_entry(mode, &connector->modes, head)
1360
		mode_count++;
1357
		mode_count++;
1361
 
1358
 
1362
	out_resp->connector_id = connector->base.id;
1359
	out_resp->connector_id = connector->base.id;
1363
	out_resp->connector_type = connector->connector_type;
1360
	out_resp->connector_type = connector->connector_type;
1364
	out_resp->connector_type_id = connector->connector_type_id;
1361
	out_resp->connector_type_id = connector->connector_type_id;
1365
	out_resp->mm_width = connector->display_info.width_mm;
1362
	out_resp->mm_width = connector->display_info.width_mm;
1366
	out_resp->mm_height = connector->display_info.height_mm;
1363
	out_resp->mm_height = connector->display_info.height_mm;
1367
	out_resp->subpixel = connector->display_info.subpixel_order;
1364
	out_resp->subpixel = connector->display_info.subpixel_order;
1368
	out_resp->connection = connector->status;
1365
	out_resp->connection = connector->status;
1369
	if (connector->encoder)
1366
	if (connector->encoder)
1370
		out_resp->encoder_id = connector->encoder->base.id;
1367
		out_resp->encoder_id = connector->encoder->base.id;
1371
	else
1368
	else
1372
		out_resp->encoder_id = 0;
1369
		out_resp->encoder_id = 0;
1373
 
1370
 
1374
	/*
1371
	/*
1375
	 * This ioctl is called twice, once to determine how much space is
1372
	 * This ioctl is called twice, once to determine how much space is
1376
	 * needed, and the 2nd time to fill it.
1373
	 * needed, and the 2nd time to fill it.
1377
	 */
1374
	 */
1378
	if ((out_resp->count_modes >= mode_count) && mode_count) {
1375
	if ((out_resp->count_modes >= mode_count) && mode_count) {
1379
		copied = 0;
1376
		copied = 0;
1380
		mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
1377
		mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
1381
		list_for_each_entry(mode, &connector->modes, head) {
1378
		list_for_each_entry(mode, &connector->modes, head) {
1382
			drm_crtc_convert_to_umode(&u_mode, mode);
1379
			drm_crtc_convert_to_umode(&u_mode, mode);
1383
			if (copy_to_user(mode_ptr + copied,
1380
			if (copy_to_user(mode_ptr + copied,
1384
					 &u_mode, sizeof(u_mode))) {
1381
					 &u_mode, sizeof(u_mode))) {
1385
				ret = -EFAULT;
1382
				ret = -EFAULT;
1386
				goto out;
1383
				goto out;
1387
			}
1384
			}
1388
			copied++;
1385
			copied++;
1389
		}
1386
		}
1390
	}
1387
	}
1391
	out_resp->count_modes = mode_count;
1388
	out_resp->count_modes = mode_count;
1392
 
1389
 
1393
	if ((out_resp->count_props >= props_count) && props_count) {
1390
	if ((out_resp->count_props >= props_count) && props_count) {
1394
		copied = 0;
1391
		copied = 0;
1395
		prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
1392
		prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
1396
		prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
1393
		prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
1397
		for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
1394
		for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
1398
			if (connector->property_ids[i] != 0) {
1395
			if (connector->property_ids[i] != 0) {
1399
				if (put_user(connector->property_ids[i],
1396
				if (put_user(connector->property_ids[i],
1400
					     prop_ptr + copied)) {
1397
					     prop_ptr + copied)) {
1401
					ret = -EFAULT;
1398
					ret = -EFAULT;
1402
					goto out;
1399
					goto out;
1403
				}
1400
				}
1404
 
1401
 
1405
				if (put_user(connector->property_values[i],
1402
				if (put_user(connector->property_values[i],
1406
					     prop_values + copied)) {
1403
					     prop_values + copied)) {
1407
					ret = -EFAULT;
1404
					ret = -EFAULT;
1408
					goto out;
1405
					goto out;
1409
				}
1406
				}
1410
				copied++;
1407
				copied++;
1411
			}
1408
			}
1412
		}
1409
		}
1413
	}
1410
	}
1414
	out_resp->count_props = props_count;
1411
	out_resp->count_props = props_count;
1415
 
1412
 
1416
	if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
1413
	if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
1417
		copied = 0;
1414
		copied = 0;
1418
		encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
1415
		encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
1419
		for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1416
		for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1420
			if (connector->encoder_ids[i] != 0) {
1417
			if (connector->encoder_ids[i] != 0) {
1421
				if (put_user(connector->encoder_ids[i],
1418
				if (put_user(connector->encoder_ids[i],
1422
					     encoder_ptr + copied)) {
1419
					     encoder_ptr + copied)) {
1423
					ret = -EFAULT;
1420
					ret = -EFAULT;
1424
					goto out;
1421
					goto out;
1425
				}
1422
				}
1426
				copied++;
1423
				copied++;
1427
			}
1424
			}
1428
		}
1425
		}
1429
	}
1426
	}
1430
	out_resp->count_encoders = encoders_count;
1427
	out_resp->count_encoders = encoders_count;
1431
 
1428
 
1432
out:
1429
out:
1433
	mutex_unlock(&dev->mode_config.mutex);
1430
	mutex_unlock(&dev->mode_config.mutex);
1434
	return ret;
1431
	return ret;
1435
}
1432
}
1436
 
1433
 
1437
int drm_mode_getencoder(struct drm_device *dev, void *data,
1434
int drm_mode_getencoder(struct drm_device *dev, void *data,
1438
			struct drm_file *file_priv)
1435
			struct drm_file *file_priv)
1439
{
1436
{
1440
	struct drm_mode_get_encoder *enc_resp = data;
1437
	struct drm_mode_get_encoder *enc_resp = data;
1441
	struct drm_mode_object *obj;
1438
	struct drm_mode_object *obj;
1442
	struct drm_encoder *encoder;
1439
	struct drm_encoder *encoder;
1443
	int ret = 0;
1440
	int ret = 0;
1444
 
1441
 
1445
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
1442
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
1446
		return -EINVAL;
1443
		return -EINVAL;
1447
 
1444
 
1448
	mutex_lock(&dev->mode_config.mutex);
1445
	mutex_lock(&dev->mode_config.mutex);
1449
	obj = drm_mode_object_find(dev, enc_resp->encoder_id,
1446
	obj = drm_mode_object_find(dev, enc_resp->encoder_id,
1450
				   DRM_MODE_OBJECT_ENCODER);
1447
				   DRM_MODE_OBJECT_ENCODER);
1451
	if (!obj) {
1448
	if (!obj) {
1452
		ret = -EINVAL;
1449
		ret = -EINVAL;
1453
		goto out;
1450
		goto out;
1454
	}
1451
	}
1455
	encoder = obj_to_encoder(obj);
1452
	encoder = obj_to_encoder(obj);
1456
 
1453
 
1457
	if (encoder->crtc)
1454
	if (encoder->crtc)
1458
		enc_resp->crtc_id = encoder->crtc->base.id;
1455
		enc_resp->crtc_id = encoder->crtc->base.id;
1459
	else
1456
	else
1460
		enc_resp->crtc_id = 0;
1457
		enc_resp->crtc_id = 0;
1461
	enc_resp->encoder_type = encoder->encoder_type;
1458
	enc_resp->encoder_type = encoder->encoder_type;
1462
	enc_resp->encoder_id = encoder->base.id;
1459
	enc_resp->encoder_id = encoder->base.id;
1463
	enc_resp->possible_crtcs = encoder->possible_crtcs;
1460
	enc_resp->possible_crtcs = encoder->possible_crtcs;
1464
	enc_resp->possible_clones = encoder->possible_clones;
1461
	enc_resp->possible_clones = encoder->possible_clones;
1465
 
1462
 
1466
out:
1463
out:
1467
	mutex_unlock(&dev->mode_config.mutex);
1464
	mutex_unlock(&dev->mode_config.mutex);
1468
	return ret;
1465
	return ret;
1469
}
1466
}
1470
 
1467
 
1471
/**
1468
/**
1472
 * drm_mode_setcrtc - set CRTC configuration
1469
 * drm_mode_setcrtc - set CRTC configuration
1473
 * @inode: inode from the ioctl
1470
 * @inode: inode from the ioctl
1474
 * @filp: file * from the ioctl
1471
 * @filp: file * from the ioctl
1475
 * @cmd: cmd from ioctl
1472
 * @cmd: cmd from ioctl
1476
 * @arg: arg from ioctl
1473
 * @arg: arg from ioctl
1477
 *
1474
 *
1478
 * LOCKING:
1475
 * LOCKING:
1479
 * Caller? (FIXME)
1476
 * Caller? (FIXME)
1480
 *
1477
 *
1481
 * Build a new CRTC configuration based on user request.
1478
 * Build a new CRTC configuration based on user request.
1482
 *
1479
 *
1483
 * Called by the user via ioctl.
1480
 * Called by the user via ioctl.
1484
 *
1481
 *
1485
 * RETURNS:
1482
 * RETURNS:
1486
 * Zero on success, errno on failure.
1483
 * Zero on success, errno on failure.
1487
 */
1484
 */
1488
int drm_mode_setcrtc(struct drm_device *dev, void *data,
1485
int drm_mode_setcrtc(struct drm_device *dev, void *data,
1489
		     struct drm_file *file_priv)
1486
		     struct drm_file *file_priv)
1490
{
1487
{
1491
	struct drm_mode_config *config = &dev->mode_config;
1488
	struct drm_mode_config *config = &dev->mode_config;
1492
	struct drm_mode_crtc *crtc_req = data;
1489
	struct drm_mode_crtc *crtc_req = data;
1493
	struct drm_mode_object *obj;
1490
	struct drm_mode_object *obj;
1494
	struct drm_crtc *crtc, *crtcfb;
1491
	struct drm_crtc *crtc, *crtcfb;
1495
	struct drm_connector **connector_set = NULL, *connector;
1492
	struct drm_connector **connector_set = NULL, *connector;
1496
	struct drm_framebuffer *fb = NULL;
1493
	struct drm_framebuffer *fb = NULL;
1497
	struct drm_display_mode *mode = NULL;
1494
	struct drm_display_mode *mode = NULL;
1498
	struct drm_mode_set set;
1495
	struct drm_mode_set set;
1499
	uint32_t __user *set_connectors_ptr;
1496
	uint32_t __user *set_connectors_ptr;
1500
	int ret = 0;
1497
	int ret = 0;
1501
	int i;
1498
	int i;
1502
 
1499
 
1503
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
1500
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
1504
		return -EINVAL;
1501
		return -EINVAL;
1505
 
1502
 
1506
	mutex_lock(&dev->mode_config.mutex);
1503
	mutex_lock(&dev->mode_config.mutex);
1507
	obj = drm_mode_object_find(dev, crtc_req->crtc_id,
1504
	obj = drm_mode_object_find(dev, crtc_req->crtc_id,
1508
				   DRM_MODE_OBJECT_CRTC);
1505
				   DRM_MODE_OBJECT_CRTC);
1509
	if (!obj) {
1506
	if (!obj) {
1510
		DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id);
1507
		DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id);
1511
		ret = -EINVAL;
1508
		ret = -EINVAL;
1512
		goto out;
1509
		goto out;
1513
	}
1510
	}
1514
	crtc = obj_to_crtc(obj);
1511
	crtc = obj_to_crtc(obj);
1515
	DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
1512
	DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
1516
 
1513
 
1517
	if (crtc_req->mode_valid) {
1514
	if (crtc_req->mode_valid) {
1518
		/* If we have a mode we need a framebuffer. */
1515
		/* If we have a mode we need a framebuffer. */
1519
		/* If we pass -1, set the mode with the currently bound fb */
1516
		/* If we pass -1, set the mode with the currently bound fb */
1520
		if (crtc_req->fb_id == -1) {
1517
		if (crtc_req->fb_id == -1) {
1521
			list_for_each_entry(crtcfb,
1518
			list_for_each_entry(crtcfb,
1522
					    &dev->mode_config.crtc_list, head) {
1519
					    &dev->mode_config.crtc_list, head) {
1523
				if (crtcfb == crtc) {
1520
				if (crtcfb == crtc) {
1524
					DRM_DEBUG_KMS("Using current fb for "
1521
					DRM_DEBUG_KMS("Using current fb for "
1525
							"setmode\n");
1522
							"setmode\n");
1526
					fb = crtc->fb;
1523
					fb = crtc->fb;
1527
				}
1524
				}
1528
			}
1525
			}
1529
		} else {
1526
		} else {
1530
			obj = drm_mode_object_find(dev, crtc_req->fb_id,
1527
			obj = drm_mode_object_find(dev, crtc_req->fb_id,
1531
						   DRM_MODE_OBJECT_FB);
1528
						   DRM_MODE_OBJECT_FB);
1532
			if (!obj) {
1529
			if (!obj) {
1533
				DRM_DEBUG_KMS("Unknown FB ID%d\n",
1530
				DRM_DEBUG_KMS("Unknown FB ID%d\n",
1534
						crtc_req->fb_id);
1531
						crtc_req->fb_id);
1535
				ret = -EINVAL;
1532
				ret = -EINVAL;
1536
				goto out;
1533
				goto out;
1537
			}
1534
			}
1538
			fb = obj_to_fb(obj);
1535
			fb = obj_to_fb(obj);
1539
		}
1536
		}
1540
 
1537
 
1541
		mode = drm_mode_create(dev);
1538
		mode = drm_mode_create(dev);
1542
		drm_crtc_convert_umode(mode, &crtc_req->mode);
1539
		drm_crtc_convert_umode(mode, &crtc_req->mode);
1543
		drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
1540
		drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
1544
	}
1541
	}
1545
 
1542
 
1546
	if (crtc_req->count_connectors == 0 && mode) {
1543
	if (crtc_req->count_connectors == 0 && mode) {
1547
		DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
1544
		DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
1548
		ret = -EINVAL;
1545
		ret = -EINVAL;
1549
		goto out;
1546
		goto out;
1550
	}
1547
	}
1551
 
1548
 
1552
	if (crtc_req->count_connectors > 0 && (!mode || !fb)) {
1549
	if (crtc_req->count_connectors > 0 && (!mode || !fb)) {
1553
		DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
1550
		DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
1554
			  crtc_req->count_connectors);
1551
			  crtc_req->count_connectors);
1555
		ret = -EINVAL;
1552
		ret = -EINVAL;
1556
		goto out;
1553
		goto out;
1557
	}
1554
	}
1558
 
1555
 
1559
	if (crtc_req->count_connectors > 0) {
1556
	if (crtc_req->count_connectors > 0) {
1560
		u32 out_id;
1557
		u32 out_id;
1561
 
1558
 
1562
		/* Avoid unbounded kernel memory allocation */
1559
		/* Avoid unbounded kernel memory allocation */
1563
		if (crtc_req->count_connectors > config->num_connector) {
1560
		if (crtc_req->count_connectors > config->num_connector) {
1564
			ret = -EINVAL;
1561
			ret = -EINVAL;
1565
			goto out;
1562
			goto out;
1566
		}
1563
		}
1567
 
1564
 
1568
		connector_set = kmalloc(crtc_req->count_connectors *
1565
		connector_set = kmalloc(crtc_req->count_connectors *
1569
					sizeof(struct drm_connector *),
1566
					sizeof(struct drm_connector *),
1570
					GFP_KERNEL);
1567
					GFP_KERNEL);
1571
		if (!connector_set) {
1568
		if (!connector_set) {
1572
			ret = -ENOMEM;
1569
			ret = -ENOMEM;
1573
			goto out;
1570
			goto out;
1574
		}
1571
		}
1575
 
1572
 
1576
		for (i = 0; i < crtc_req->count_connectors; i++) {
1573
		for (i = 0; i < crtc_req->count_connectors; i++) {
1577
			set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
1574
			set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
1578
			if (get_user(out_id, &set_connectors_ptr[i])) {
1575
			if (get_user(out_id, &set_connectors_ptr[i])) {
1579
				ret = -EFAULT;
1576
				ret = -EFAULT;
1580
				goto out;
1577
				goto out;
1581
			}
1578
			}
1582
 
1579
 
1583
			obj = drm_mode_object_find(dev, out_id,
1580
			obj = drm_mode_object_find(dev, out_id,
1584
						   DRM_MODE_OBJECT_CONNECTOR);
1581
						   DRM_MODE_OBJECT_CONNECTOR);
1585
			if (!obj) {
1582
			if (!obj) {
1586
				DRM_DEBUG_KMS("Connector id %d unknown\n",
1583
				DRM_DEBUG_KMS("Connector id %d unknown\n",
1587
						out_id);
1584
						out_id);
1588
				ret = -EINVAL;
1585
				ret = -EINVAL;
1589
				goto out;
1586
				goto out;
1590
			}
1587
			}
1591
			connector = obj_to_connector(obj);
1588
			connector = obj_to_connector(obj);
1592
			DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1589
			DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1593
					connector->base.id,
1590
					connector->base.id,
1594
					drm_get_connector_name(connector));
1591
					drm_get_connector_name(connector));
1595
 
1592
 
1596
			connector_set[i] = connector;
1593
			connector_set[i] = connector;
1597
		}
1594
		}
1598
	}
1595
	}
1599
 
1596
 
1600
	set.crtc = crtc;
1597
	set.crtc = crtc;
1601
	set.x = crtc_req->x;
1598
	set.x = crtc_req->x;
1602
	set.y = crtc_req->y;
1599
	set.y = crtc_req->y;
1603
	set.mode = mode;
1600
	set.mode = mode;
1604
	set.connectors = connector_set;
1601
	set.connectors = connector_set;
1605
	set.num_connectors = crtc_req->count_connectors;
1602
	set.num_connectors = crtc_req->count_connectors;
1606
	set.fb = fb;
1603
	set.fb = fb;
1607
	ret = crtc->funcs->set_config(&set);
1604
	ret = crtc->funcs->set_config(&set);
1608
 
1605
 
1609
out:
1606
out:
1610
	kfree(connector_set);
1607
	kfree(connector_set);
1611
	mutex_unlock(&dev->mode_config.mutex);
1608
	mutex_unlock(&dev->mode_config.mutex);
1612
	return ret;
1609
	return ret;
1613
}
1610
}
1614
 
1611
 
1615
int drm_mode_cursor_ioctl(struct drm_device *dev,
1612
int drm_mode_cursor_ioctl(struct drm_device *dev,
1616
			void *data, struct drm_file *file_priv)
1613
			void *data, struct drm_file *file_priv)
1617
{
1614
{
1618
	struct drm_mode_cursor *req = data;
1615
	struct drm_mode_cursor *req = data;
1619
	struct drm_mode_object *obj;
1616
	struct drm_mode_object *obj;
1620
	struct drm_crtc *crtc;
1617
	struct drm_crtc *crtc;
1621
	int ret = 0;
1618
	int ret = 0;
1622
 
1619
 
1623
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
1620
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
1624
		return -EINVAL;
1621
		return -EINVAL;
1625
 
1622
 
1626
	if (!req->flags) {
1623
	if (!req->flags) {
1627
		DRM_ERROR("no operation set\n");
1624
		DRM_ERROR("no operation set\n");
1628
		return -EINVAL;
1625
		return -EINVAL;
1629
	}
1626
	}
1630
 
1627
 
1631
	mutex_lock(&dev->mode_config.mutex);
1628
	mutex_lock(&dev->mode_config.mutex);
1632
	obj = drm_mode_object_find(dev, req->crtc_id, DRM_MODE_OBJECT_CRTC);
1629
	obj = drm_mode_object_find(dev, req->crtc_id, DRM_MODE_OBJECT_CRTC);
1633
	if (!obj) {
1630
	if (!obj) {
1634
		DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id);
1631
		DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id);
1635
		ret = -EINVAL;
1632
		ret = -EINVAL;
1636
		goto out;
1633
		goto out;
1637
	}
1634
	}
1638
	crtc = obj_to_crtc(obj);
1635
	crtc = obj_to_crtc(obj);
1639
 
1636
 
1640
	if (req->flags & DRM_MODE_CURSOR_BO) {
1637
	if (req->flags & DRM_MODE_CURSOR_BO) {
1641
		if (!crtc->funcs->cursor_set) {
1638
		if (!crtc->funcs->cursor_set) {
1642
			DRM_ERROR("crtc does not support cursor\n");
1639
			DRM_ERROR("crtc does not support cursor\n");
1643
			ret = -ENXIO;
1640
			ret = -ENXIO;
1644
			goto out;
1641
			goto out;
1645
		}
1642
		}
1646
		/* Turns off the cursor if handle is 0 */
1643
		/* Turns off the cursor if handle is 0 */
1647
		ret = crtc->funcs->cursor_set(crtc, file_priv, req->handle,
1644
		ret = crtc->funcs->cursor_set(crtc, file_priv, req->handle,
1648
					      req->width, req->height);
1645
					      req->width, req->height);
1649
	}
1646
	}
1650
 
1647
 
1651
	if (req->flags & DRM_MODE_CURSOR_MOVE) {
1648
	if (req->flags & DRM_MODE_CURSOR_MOVE) {
1652
		if (crtc->funcs->cursor_move) {
1649
		if (crtc->funcs->cursor_move) {
1653
			ret = crtc->funcs->cursor_move(crtc, req->x, req->y);
1650
			ret = crtc->funcs->cursor_move(crtc, req->x, req->y);
1654
		} else {
1651
		} else {
1655
			DRM_ERROR("crtc does not support cursor\n");
1652
			DRM_ERROR("crtc does not support cursor\n");
1656
			ret = -EFAULT;
1653
			ret = -EFAULT;
1657
			goto out;
1654
			goto out;
1658
		}
1655
		}
1659
	}
1656
	}
1660
out:
1657
out:
1661
	mutex_unlock(&dev->mode_config.mutex);
1658
	mutex_unlock(&dev->mode_config.mutex);
1662
	return ret;
1659
	return ret;
1663
}
1660
}
1664
 
1661
 
1665
/**
1662
/**
1666
 * drm_mode_addfb - add an FB to the graphics configuration
1663
 * drm_mode_addfb - add an FB to the graphics configuration
1667
 * @inode: inode from the ioctl
1664
 * @inode: inode from the ioctl
1668
 * @filp: file * from the ioctl
1665
 * @filp: file * from the ioctl
1669
 * @cmd: cmd from ioctl
1666
 * @cmd: cmd from ioctl
1670
 * @arg: arg from ioctl
1667
 * @arg: arg from ioctl
1671
 *
1668
 *
1672
 * LOCKING:
1669
 * LOCKING:
1673
 * Takes mode config lock.
1670
 * Takes mode config lock.
1674
 *
1671
 *
1675
 * Add a new FB to the specified CRTC, given a user request.
1672
 * Add a new FB to the specified CRTC, given a user request.
1676
 *
1673
 *
1677
 * Called by the user via ioctl.
1674
 * Called by the user via ioctl.
1678
 *
1675
 *
1679
 * RETURNS:
1676
 * RETURNS:
1680
 * Zero on success, errno on failure.
1677
 * Zero on success, errno on failure.
1681
 */
1678
 */
1682
int drm_mode_addfb(struct drm_device *dev,
1679
int drm_mode_addfb(struct drm_device *dev,
1683
		   void *data, struct drm_file *file_priv)
1680
		   void *data, struct drm_file *file_priv)
1684
{
1681
{
1685
	struct drm_mode_fb_cmd *r = data;
1682
	struct drm_mode_fb_cmd *r = data;
1686
	struct drm_mode_config *config = &dev->mode_config;
1683
	struct drm_mode_config *config = &dev->mode_config;
1687
	struct drm_framebuffer *fb;
1684
	struct drm_framebuffer *fb;
1688
	int ret = 0;
1685
	int ret = 0;
1689
 
1686
 
1690
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
1687
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
1691
		return -EINVAL;
1688
		return -EINVAL;
1692
 
1689
 
1693
	if ((config->min_width > r->width) || (r->width > config->max_width)) {
1690
	if ((config->min_width > r->width) || (r->width > config->max_width)) {
1694
		DRM_ERROR("mode new framebuffer width not within limits\n");
1691
		DRM_ERROR("mode new framebuffer width not within limits\n");
1695
		return -EINVAL;
1692
		return -EINVAL;
1696
	}
1693
	}
1697
	if ((config->min_height > r->height) || (r->height > config->max_height)) {
1694
	if ((config->min_height > r->height) || (r->height > config->max_height)) {
1698
		DRM_ERROR("mode new framebuffer height not within limits\n");
1695
		DRM_ERROR("mode new framebuffer height not within limits\n");
1699
		return -EINVAL;
1696
		return -EINVAL;
1700
	}
1697
	}
1701
 
1698
 
1702
	mutex_lock(&dev->mode_config.mutex);
1699
	mutex_lock(&dev->mode_config.mutex);
1703
 
1700
 
1704
	/* TODO check buffer is sufficiently large */
1701
	/* TODO check buffer is sufficiently large */
1705
	/* TODO setup destructor callback */
1702
	/* TODO setup destructor callback */
1706
 
1703
 
1707
	fb = dev->mode_config.funcs->fb_create(dev, file_priv, r);
1704
	fb = dev->mode_config.funcs->fb_create(dev, file_priv, r);
1708
	if (IS_ERR(fb)) {
1705
	if (IS_ERR(fb)) {
1709
		DRM_ERROR("could not create framebuffer\n");
1706
		DRM_ERROR("could not create framebuffer\n");
1710
		ret = PTR_ERR(fb);
1707
		ret = PTR_ERR(fb);
1711
		goto out;
1708
		goto out;
1712
	}
1709
	}
1713
 
1710
 
1714
	r->fb_id = fb->base.id;
1711
	r->fb_id = fb->base.id;
1715
	list_add(&fb->filp_head, &file_priv->fbs);
1712
	list_add(&fb->filp_head, &file_priv->fbs);
1716
	DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id);
1713
	DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id);
1717
 
1714
 
1718
out:
1715
out:
1719
	mutex_unlock(&dev->mode_config.mutex);
1716
	mutex_unlock(&dev->mode_config.mutex);
1720
	return ret;
1717
	return ret;
1721
}
1718
}
1722
 
1719
 
1723
/**
1720
/**
1724
 * drm_mode_rmfb - remove an FB from the configuration
1721
 * drm_mode_rmfb - remove an FB from the configuration
1725
 * @inode: inode from the ioctl
1722
 * @inode: inode from the ioctl
1726
 * @filp: file * from the ioctl
1723
 * @filp: file * from the ioctl
1727
 * @cmd: cmd from ioctl
1724
 * @cmd: cmd from ioctl
1728
 * @arg: arg from ioctl
1725
 * @arg: arg from ioctl
1729
 *
1726
 *
1730
 * LOCKING:
1727
 * LOCKING:
1731
 * Takes mode config lock.
1728
 * Takes mode config lock.
1732
 *
1729
 *
1733
 * Remove the FB specified by the user.
1730
 * Remove the FB specified by the user.
1734
 *
1731
 *
1735
 * Called by the user via ioctl.
1732
 * Called by the user via ioctl.
1736
 *
1733
 *
1737
 * RETURNS:
1734
 * RETURNS:
1738
 * Zero on success, errno on failure.
1735
 * Zero on success, errno on failure.
1739
 */
1736
 */
1740
int drm_mode_rmfb(struct drm_device *dev,
1737
int drm_mode_rmfb(struct drm_device *dev,
1741
		   void *data, struct drm_file *file_priv)
1738
		   void *data, struct drm_file *file_priv)
1742
{
1739
{
1743
	struct drm_mode_object *obj;
1740
	struct drm_mode_object *obj;
1744
	struct drm_framebuffer *fb = NULL;
1741
	struct drm_framebuffer *fb = NULL;
1745
	struct drm_framebuffer *fbl = NULL;
1742
	struct drm_framebuffer *fbl = NULL;
1746
	uint32_t *id = data;
1743
	uint32_t *id = data;
1747
	int ret = 0;
1744
	int ret = 0;
1748
	int found = 0;
1745
	int found = 0;
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
	mutex_lock(&dev->mode_config.mutex);
1750
	mutex_lock(&dev->mode_config.mutex);
1754
	obj = drm_mode_object_find(dev, *id, DRM_MODE_OBJECT_FB);
1751
	obj = drm_mode_object_find(dev, *id, DRM_MODE_OBJECT_FB);
1755
	/* TODO check that we really get a framebuffer back. */
1752
	/* TODO check that we really get a framebuffer back. */
1756
	if (!obj) {
1753
	if (!obj) {
1757
		DRM_ERROR("mode invalid framebuffer id\n");
1754
		DRM_ERROR("mode invalid framebuffer id\n");
1758
		ret = -EINVAL;
1755
		ret = -EINVAL;
1759
		goto out;
1756
		goto out;
1760
	}
1757
	}
1761
	fb = obj_to_fb(obj);
1758
	fb = obj_to_fb(obj);
1762
 
1759
 
1763
	list_for_each_entry(fbl, &file_priv->fbs, filp_head)
1760
	list_for_each_entry(fbl, &file_priv->fbs, filp_head)
1764
		if (fb == fbl)
1761
		if (fb == fbl)
1765
			found = 1;
1762
			found = 1;
1766
 
1763
 
1767
	if (!found) {
1764
	if (!found) {
1768
		DRM_ERROR("tried to remove a fb that we didn't own\n");
1765
		DRM_ERROR("tried to remove a fb that we didn't own\n");
1769
		ret = -EINVAL;
1766
		ret = -EINVAL;
1770
		goto out;
1767
		goto out;
1771
	}
1768
	}
1772
 
1769
 
1773
	/* TODO release all crtc connected to the framebuffer */
1770
	/* TODO release all crtc connected to the framebuffer */
1774
	/* TODO unhock the destructor from the buffer object */
1771
	/* TODO unhock the destructor from the buffer object */
1775
 
1772
 
1776
	list_del(&fb->filp_head);
1773
	list_del(&fb->filp_head);
1777
	fb->funcs->destroy(fb);
1774
	fb->funcs->destroy(fb);
1778
 
1775
 
1779
out:
1776
out:
1780
	mutex_unlock(&dev->mode_config.mutex);
1777
	mutex_unlock(&dev->mode_config.mutex);
1781
	return ret;
1778
	return ret;
1782
}
1779
}
1783
 
1780
 
1784
/**
1781
/**
1785
 * drm_mode_getfb - get FB info
1782
 * drm_mode_getfb - get FB info
1786
 * @inode: inode from the ioctl
1783
 * @inode: inode from the ioctl
1787
 * @filp: file * from the ioctl
1784
 * @filp: file * from the ioctl
1788
 * @cmd: cmd from ioctl
1785
 * @cmd: cmd from ioctl
1789
 * @arg: arg from ioctl
1786
 * @arg: arg from ioctl
1790
 *
1787
 *
1791
 * LOCKING:
1788
 * LOCKING:
1792
 * Caller? (FIXME)
1789
 * Caller? (FIXME)
1793
 *
1790
 *
1794
 * Lookup the FB given its ID and return info about it.
1791
 * Lookup the FB given its ID and return info about it.
1795
 *
1792
 *
1796
 * Called by the user via ioctl.
1793
 * Called by the user via ioctl.
1797
 *
1794
 *
1798
 * RETURNS:
1795
 * RETURNS:
1799
 * Zero on success, errno on failure.
1796
 * Zero on success, errno on failure.
1800
 */
1797
 */
1801
int drm_mode_getfb(struct drm_device *dev,
1798
int drm_mode_getfb(struct drm_device *dev,
1802
		   void *data, struct drm_file *file_priv)
1799
		   void *data, struct drm_file *file_priv)
1803
{
1800
{
1804
	struct drm_mode_fb_cmd *r = data;
1801
	struct drm_mode_fb_cmd *r = data;
1805
	struct drm_mode_object *obj;
1802
	struct drm_mode_object *obj;
1806
	struct drm_framebuffer *fb;
1803
	struct drm_framebuffer *fb;
1807
	int ret = 0;
1804
	int ret = 0;
1808
 
1805
 
1809
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
1806
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
1810
		return -EINVAL;
1807
		return -EINVAL;
1811
 
1808
 
1812
	mutex_lock(&dev->mode_config.mutex);
1809
	mutex_lock(&dev->mode_config.mutex);
1813
	obj = drm_mode_object_find(dev, r->fb_id, DRM_MODE_OBJECT_FB);
1810
	obj = drm_mode_object_find(dev, r->fb_id, DRM_MODE_OBJECT_FB);
1814
	if (!obj) {
1811
	if (!obj) {
1815
		DRM_ERROR("invalid framebuffer id\n");
1812
		DRM_ERROR("invalid framebuffer id\n");
1816
		ret = -EINVAL;
1813
		ret = -EINVAL;
1817
		goto out;
1814
		goto out;
1818
	}
1815
	}
1819
	fb = obj_to_fb(obj);
1816
	fb = obj_to_fb(obj);
1820
 
1817
 
1821
	r->height = fb->height;
1818
	r->height = fb->height;
1822
	r->width = fb->width;
1819
	r->width = fb->width;
1823
	r->depth = fb->depth;
1820
	r->depth = fb->depth;
1824
	r->bpp = fb->bits_per_pixel;
1821
	r->bpp = fb->bits_per_pixel;
1825
	r->pitch = fb->pitch;
1822
	r->pitch = fb->pitch;
1826
	fb->funcs->create_handle(fb, file_priv, &r->handle);
1823
	fb->funcs->create_handle(fb, file_priv, &r->handle);
1827
 
1824
 
1828
out:
1825
out:
1829
	mutex_unlock(&dev->mode_config.mutex);
1826
	mutex_unlock(&dev->mode_config.mutex);
1830
	return ret;
1827
	return ret;
1831
}
1828
}
1832
 
1829
 
1833
int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
1830
int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
1834
			   void *data, struct drm_file *file_priv)
1831
			   void *data, struct drm_file *file_priv)
1835
{
1832
{
1836
	struct drm_clip_rect __user *clips_ptr;
1833
	struct drm_clip_rect __user *clips_ptr;
1837
	struct drm_clip_rect *clips = NULL;
1834
	struct drm_clip_rect *clips = NULL;
1838
	struct drm_mode_fb_dirty_cmd *r = data;
1835
	struct drm_mode_fb_dirty_cmd *r = data;
1839
	struct drm_mode_object *obj;
1836
	struct drm_mode_object *obj;
1840
	struct drm_framebuffer *fb;
1837
	struct drm_framebuffer *fb;
1841
	unsigned flags;
1838
	unsigned flags;
1842
	int num_clips;
1839
	int num_clips;
1843
	int ret = 0;
1840
	int ret = 0;
1844
 
1841
 
1845
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
1842
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
1846
		return -EINVAL;
1843
		return -EINVAL;
1847
 
1844
 
1848
	mutex_lock(&dev->mode_config.mutex);
1845
	mutex_lock(&dev->mode_config.mutex);
1849
	obj = drm_mode_object_find(dev, r->fb_id, DRM_MODE_OBJECT_FB);
1846
	obj = drm_mode_object_find(dev, r->fb_id, DRM_MODE_OBJECT_FB);
1850
	if (!obj) {
1847
	if (!obj) {
1851
		DRM_ERROR("invalid framebuffer id\n");
1848
		DRM_ERROR("invalid framebuffer id\n");
1852
		ret = -EINVAL;
1849
		ret = -EINVAL;
1853
		goto out_err1;
1850
		goto out_err1;
1854
	}
1851
	}
1855
	fb = obj_to_fb(obj);
1852
	fb = obj_to_fb(obj);
1856
 
1853
 
1857
	num_clips = r->num_clips;
1854
	num_clips = r->num_clips;
1858
	clips_ptr = (struct drm_clip_rect *)(unsigned long)r->clips_ptr;
1855
	clips_ptr = (struct drm_clip_rect *)(unsigned long)r->clips_ptr;
1859
 
1856
 
1860
	if (!num_clips != !clips_ptr) {
1857
	if (!num_clips != !clips_ptr) {
1861
		ret = -EINVAL;
1858
		ret = -EINVAL;
1862
		goto out_err1;
1859
		goto out_err1;
1863
	}
1860
	}
1864
 
1861
 
1865
	flags = DRM_MODE_FB_DIRTY_FLAGS & r->flags;
1862
	flags = DRM_MODE_FB_DIRTY_FLAGS & r->flags;
1866
 
1863
 
1867
	/* If userspace annotates copy, clips must come in pairs */
1864
	/* If userspace annotates copy, clips must come in pairs */
1868
	if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY && (num_clips % 2)) {
1865
	if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY && (num_clips % 2)) {
1869
		ret = -EINVAL;
1866
		ret = -EINVAL;
1870
		goto out_err1;
1867
		goto out_err1;
1871
	}
1868
	}
1872
 
1869
 
1873
	if (num_clips && clips_ptr) {
1870
	if (num_clips && clips_ptr) {
1874
		clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
1871
		clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
1875
		if (!clips) {
1872
		if (!clips) {
1876
			ret = -ENOMEM;
1873
			ret = -ENOMEM;
1877
			goto out_err1;
1874
			goto out_err1;
1878
		}
1875
		}
1879
 
1876
 
1880
		ret = copy_from_user(clips, clips_ptr,
1877
		ret = copy_from_user(clips, clips_ptr,
1881
				     num_clips * sizeof(*clips));
1878
				     num_clips * sizeof(*clips));
1882
		if (ret) {
1879
		if (ret) {
1883
			ret = -EFAULT;
1880
			ret = -EFAULT;
1884
			goto out_err2;
1881
			goto out_err2;
1885
	}
1882
	}
1886
	}
1883
	}
1887
 
1884
 
1888
	if (fb->funcs->dirty) {
1885
	if (fb->funcs->dirty) {
1889
		ret = fb->funcs->dirty(fb, file_priv, flags, r->color,
1886
		ret = fb->funcs->dirty(fb, file_priv, flags, r->color,
1890
				       clips, num_clips);
1887
				       clips, num_clips);
1891
	} else {
1888
	} else {
1892
		ret = -ENOSYS;
1889
		ret = -ENOSYS;
1893
		goto out_err2;
1890
		goto out_err2;
1894
	}
1891
	}
1895
 
1892
 
1896
out_err2:
1893
out_err2:
1897
	kfree(clips);
1894
	kfree(clips);
1898
out_err1:
1895
out_err1:
1899
	mutex_unlock(&dev->mode_config.mutex);
1896
	mutex_unlock(&dev->mode_config.mutex);
1900
	return ret;
1897
	return ret;
1901
}
1898
}
1902
 
1899
 
1903
 
1900
 
1904
/**
1901
/**
1905
 * drm_fb_release - remove and free the FBs on this file
1902
 * drm_fb_release - remove and free the FBs on this file
1906
 * @filp: file * from the ioctl
1903
 * @filp: file * from the ioctl
1907
 *
1904
 *
1908
 * LOCKING:
1905
 * LOCKING:
1909
 * Takes mode config lock.
1906
 * Takes mode config lock.
1910
 *
1907
 *
1911
 * Destroy all the FBs associated with @filp.
1908
 * Destroy all the FBs associated with @filp.
1912
 *
1909
 *
1913
 * Called by the user via ioctl.
1910
 * Called by the user via ioctl.
1914
 *
1911
 *
1915
 * RETURNS:
1912
 * RETURNS:
1916
 * Zero on success, errno on failure.
1913
 * Zero on success, errno on failure.
1917
 */
1914
 */
1918
void drm_fb_release(struct drm_file *priv)
1915
void drm_fb_release(struct drm_file *priv)
1919
{
1916
{
1920
	struct drm_device *dev = priv->minor->dev;
1917
	struct drm_device *dev = priv->minor->dev;
1921
	struct drm_framebuffer *fb, *tfb;
1918
	struct drm_framebuffer *fb, *tfb;
1922
 
1919
 
1923
	mutex_lock(&dev->mode_config.mutex);
1920
	mutex_lock(&dev->mode_config.mutex);
1924
	list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) {
1921
	list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) {
1925
		list_del(&fb->filp_head);
1922
		list_del(&fb->filp_head);
1926
		fb->funcs->destroy(fb);
1923
		fb->funcs->destroy(fb);
1927
	}
1924
	}
1928
	mutex_unlock(&dev->mode_config.mutex);
1925
	mutex_unlock(&dev->mode_config.mutex);
1929
}
1926
}
1930
#endif
1927
#endif
1931
 
1928
 
1932
/**
1929
/**
1933
 * drm_mode_attachmode - add a mode to the user mode list
1930
 * drm_mode_attachmode - add a mode to the user mode list
1934
 * @dev: DRM device
1931
 * @dev: DRM device
1935
 * @connector: connector to add the mode to
1932
 * @connector: connector to add the mode to
1936
 * @mode: mode to add
1933
 * @mode: mode to add
1937
 *
1934
 *
1938
 * Add @mode to @connector's user mode list.
1935
 * Add @mode to @connector's user mode list.
1939
 */
1936
 */
1940
static int drm_mode_attachmode(struct drm_device *dev,
1937
static int drm_mode_attachmode(struct drm_device *dev,
1941
			       struct drm_connector *connector,
1938
			       struct drm_connector *connector,
1942
			       struct drm_display_mode *mode)
1939
			       struct drm_display_mode *mode)
1943
{
1940
{
1944
	int ret = 0;
1941
	int ret = 0;
1945
 
1942
 
1946
	list_add_tail(&mode->head, &connector->user_modes);
1943
	list_add_tail(&mode->head, &connector->user_modes);
1947
	return ret;
1944
	return ret;
1948
}
1945
}
1949
 
1946
 
1950
int drm_mode_attachmode_crtc(struct drm_device *dev, struct drm_crtc *crtc,
1947
int drm_mode_attachmode_crtc(struct drm_device *dev, struct drm_crtc *crtc,
1951
			     struct drm_display_mode *mode)
1948
			     struct drm_display_mode *mode)
1952
{
1949
{
1953
	struct drm_connector *connector;
1950
	struct drm_connector *connector;
1954
	int ret = 0;
1951
	int ret = 0;
1955
	struct drm_display_mode *dup_mode;
1952
	struct drm_display_mode *dup_mode;
1956
	int need_dup = 0;
1953
	int need_dup = 0;
1957
	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1954
	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1958
		if (!connector->encoder)
1955
		if (!connector->encoder)
1959
			break;
1956
			break;
1960
		if (connector->encoder->crtc == crtc) {
1957
		if (connector->encoder->crtc == crtc) {
1961
			if (need_dup)
1958
			if (need_dup)
1962
				dup_mode = drm_mode_duplicate(dev, mode);
1959
				dup_mode = drm_mode_duplicate(dev, mode);
1963
			else
1960
			else
1964
				dup_mode = mode;
1961
				dup_mode = mode;
1965
			ret = drm_mode_attachmode(dev, connector, dup_mode);
1962
			ret = drm_mode_attachmode(dev, connector, dup_mode);
1966
			if (ret)
1963
			if (ret)
1967
				return ret;
1964
				return ret;
1968
			need_dup = 1;
1965
			need_dup = 1;
1969
		}
1966
		}
1970
	}
1967
	}
1971
	return 0;
1968
	return 0;
1972
}
1969
}
1973
EXPORT_SYMBOL(drm_mode_attachmode_crtc);
1970
EXPORT_SYMBOL(drm_mode_attachmode_crtc);
1974
 
1971
 
1975
static int drm_mode_detachmode(struct drm_device *dev,
1972
static int drm_mode_detachmode(struct drm_device *dev,
1976
			       struct drm_connector *connector,
1973
			       struct drm_connector *connector,
1977
			       struct drm_display_mode *mode)
1974
			       struct drm_display_mode *mode)
1978
{
1975
{
1979
	int found = 0;
1976
	int found = 0;
1980
	int ret = 0;
1977
	int ret = 0;
1981
	struct drm_display_mode *match_mode, *t;
1978
	struct drm_display_mode *match_mode, *t;
1982
 
1979
 
1983
	list_for_each_entry_safe(match_mode, t, &connector->user_modes, head) {
1980
	list_for_each_entry_safe(match_mode, t, &connector->user_modes, head) {
1984
		if (drm_mode_equal(match_mode, mode)) {
1981
		if (drm_mode_equal(match_mode, mode)) {
1985
			list_del(&match_mode->head);
1982
			list_del(&match_mode->head);
1986
			drm_mode_destroy(dev, match_mode);
1983
			drm_mode_destroy(dev, match_mode);
1987
			found = 1;
1984
			found = 1;
1988
			break;
1985
			break;
1989
		}
1986
		}
1990
	}
1987
	}
1991
 
1988
 
1992
	if (!found)
1989
	if (!found)
1993
		ret = -EINVAL;
1990
		ret = -EINVAL;
1994
 
1991
 
1995
	return ret;
1992
	return ret;
1996
}
1993
}
1997
 
1994
 
1998
int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode)
1995
int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode)
1999
{
1996
{
2000
	struct drm_connector *connector;
1997
	struct drm_connector *connector;
2001
 
1998
 
2002
	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1999
	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2003
		drm_mode_detachmode(dev, connector, mode);
2000
		drm_mode_detachmode(dev, connector, mode);
2004
	}
2001
	}
2005
	return 0;
2002
	return 0;
2006
}
2003
}
2007
EXPORT_SYMBOL(drm_mode_detachmode_crtc);
2004
EXPORT_SYMBOL(drm_mode_detachmode_crtc);
2008
 
2005
 
2009
#if 0
2006
#if 0
2010
 
2007
 
2011
/**
2008
/**
2012
 * drm_fb_attachmode - Attach a user mode to an connector
2009
 * drm_fb_attachmode - Attach a user mode to an connector
2013
 * @inode: inode from the ioctl
2010
 * @inode: inode from the ioctl
2014
 * @filp: file * from the ioctl
2011
 * @filp: file * from the ioctl
2015
 * @cmd: cmd from ioctl
2012
 * @cmd: cmd from ioctl
2016
 * @arg: arg from ioctl
2013
 * @arg: arg from ioctl
2017
 *
2014
 *
2018
 * This attaches a user specified mode to an connector.
2015
 * This attaches a user specified mode to an connector.
2019
 * Called by the user via ioctl.
2016
 * Called by the user via ioctl.
2020
 *
2017
 *
2021
 * RETURNS:
2018
 * RETURNS:
2022
 * Zero on success, errno on failure.
2019
 * Zero on success, errno on failure.
2023
 */
2020
 */
2024
int drm_mode_attachmode_ioctl(struct drm_device *dev,
2021
int drm_mode_attachmode_ioctl(struct drm_device *dev,
2025
			      void *data, struct drm_file *file_priv)
2022
			      void *data, struct drm_file *file_priv)
2026
{
2023
{
2027
	struct drm_mode_mode_cmd *mode_cmd = data;
2024
	struct drm_mode_mode_cmd *mode_cmd = data;
2028
	struct drm_connector *connector;
2025
	struct drm_connector *connector;
2029
	struct drm_display_mode *mode;
2026
	struct drm_display_mode *mode;
2030
	struct drm_mode_object *obj;
2027
	struct drm_mode_object *obj;
2031
	struct drm_mode_modeinfo *umode = &mode_cmd->mode;
2028
	struct drm_mode_modeinfo *umode = &mode_cmd->mode;
2032
	int ret = 0;
2029
	int ret = 0;
2033
 
2030
 
2034
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
2031
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
2035
		return -EINVAL;
2032
		return -EINVAL;
2036
 
2033
 
2037
	mutex_lock(&dev->mode_config.mutex);
2034
	mutex_lock(&dev->mode_config.mutex);
2038
 
2035
 
2039
	obj = drm_mode_object_find(dev, mode_cmd->connector_id, DRM_MODE_OBJECT_CONNECTOR);
2036
	obj = drm_mode_object_find(dev, mode_cmd->connector_id, DRM_MODE_OBJECT_CONNECTOR);
2040
	if (!obj) {
2037
	if (!obj) {
2041
		ret = -EINVAL;
2038
		ret = -EINVAL;
2042
		goto out;
2039
		goto out;
2043
	}
2040
	}
2044
	connector = obj_to_connector(obj);
2041
	connector = obj_to_connector(obj);
2045
 
2042
 
2046
	mode = drm_mode_create(dev);
2043
	mode = drm_mode_create(dev);
2047
	if (!mode) {
2044
	if (!mode) {
2048
		ret = -ENOMEM;
2045
		ret = -ENOMEM;
2049
		goto out;
2046
		goto out;
2050
	}
2047
	}
2051
 
2048
 
2052
	drm_crtc_convert_umode(mode, umode);
2049
	drm_crtc_convert_umode(mode, umode);
2053
 
2050
 
2054
	ret = drm_mode_attachmode(dev, connector, mode);
2051
	ret = drm_mode_attachmode(dev, connector, mode);
2055
out:
2052
out:
2056
	mutex_unlock(&dev->mode_config.mutex);
2053
	mutex_unlock(&dev->mode_config.mutex);
2057
	return ret;
2054
	return ret;
2058
}
2055
}
2059
 
2056
 
2060
 
2057
 
2061
/**
2058
/**
2062
 * drm_fb_detachmode - Detach a user specified mode from an connector
2059
 * drm_fb_detachmode - Detach a user specified mode from an connector
2063
 * @inode: inode from the ioctl
2060
 * @inode: inode from the ioctl
2064
 * @filp: file * from the ioctl
2061
 * @filp: file * from the ioctl
2065
 * @cmd: cmd from ioctl
2062
 * @cmd: cmd from ioctl
2066
 * @arg: arg from ioctl
2063
 * @arg: arg from ioctl
2067
 *
2064
 *
2068
 * Called by the user via ioctl.
2065
 * Called by the user via ioctl.
2069
 *
2066
 *
2070
 * RETURNS:
2067
 * RETURNS:
2071
 * Zero on success, errno on failure.
2068
 * Zero on success, errno on failure.
2072
 */
2069
 */
2073
int drm_mode_detachmode_ioctl(struct drm_device *dev,
2070
int drm_mode_detachmode_ioctl(struct drm_device *dev,
2074
			      void *data, struct drm_file *file_priv)
2071
			      void *data, struct drm_file *file_priv)
2075
{
2072
{
2076
	struct drm_mode_object *obj;
2073
	struct drm_mode_object *obj;
2077
	struct drm_mode_mode_cmd *mode_cmd = data;
2074
	struct drm_mode_mode_cmd *mode_cmd = data;
2078
	struct drm_connector *connector;
2075
	struct drm_connector *connector;
2079
	struct drm_display_mode mode;
2076
	struct drm_display_mode mode;
2080
	struct drm_mode_modeinfo *umode = &mode_cmd->mode;
2077
	struct drm_mode_modeinfo *umode = &mode_cmd->mode;
2081
	int ret = 0;
2078
	int ret = 0;
2082
 
2079
 
2083
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
2080
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
2084
		return -EINVAL;
2081
		return -EINVAL;
2085
 
2082
 
2086
	mutex_lock(&dev->mode_config.mutex);
2083
	mutex_lock(&dev->mode_config.mutex);
2087
 
2084
 
2088
	obj = drm_mode_object_find(dev, mode_cmd->connector_id, DRM_MODE_OBJECT_CONNECTOR);
2085
	obj = drm_mode_object_find(dev, mode_cmd->connector_id, DRM_MODE_OBJECT_CONNECTOR);
2089
	if (!obj) {
2086
	if (!obj) {
2090
		ret = -EINVAL;
2087
		ret = -EINVAL;
2091
		goto out;
2088
		goto out;
2092
	}
2089
	}
2093
	connector = obj_to_connector(obj);
2090
	connector = obj_to_connector(obj);
2094
 
2091
 
2095
	drm_crtc_convert_umode(&mode, umode);
2092
	drm_crtc_convert_umode(&mode, umode);
2096
	ret = drm_mode_detachmode(dev, connector, &mode);
2093
	ret = drm_mode_detachmode(dev, connector, &mode);
2097
out:
2094
out:
2098
	mutex_unlock(&dev->mode_config.mutex);
2095
	mutex_unlock(&dev->mode_config.mutex);
2099
	return ret;
2096
	return ret;
2100
}
2097
}
2101
#endif
2098
#endif
2102
 
2099
 
2103
struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2100
struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2104
					 const char *name, int num_values)
2101
					 const char *name, int num_values)
2105
{
2102
{
2106
	struct drm_property *property = NULL;
2103
	struct drm_property *property = NULL;
2107
 
2104
 
2108
	property = kzalloc(sizeof(struct drm_property), GFP_KERNEL);
2105
	property = kzalloc(sizeof(struct drm_property), GFP_KERNEL);
2109
	if (!property)
2106
	if (!property)
2110
		return NULL;
2107
		return NULL;
2111
 
2108
 
2112
	if (num_values) {
2109
	if (num_values) {
2113
		property->values = kzalloc(sizeof(uint64_t)*num_values, GFP_KERNEL);
2110
		property->values = kzalloc(sizeof(uint64_t)*num_values, GFP_KERNEL);
2114
		if (!property->values)
2111
		if (!property->values)
2115
			goto fail;
2112
			goto fail;
2116
	}
2113
	}
2117
 
2114
 
2118
	drm_mode_object_get(dev, &property->base, DRM_MODE_OBJECT_PROPERTY);
2115
	drm_mode_object_get(dev, &property->base, DRM_MODE_OBJECT_PROPERTY);
2119
	property->flags = flags;
2116
	property->flags = flags;
2120
	property->num_values = num_values;
2117
	property->num_values = num_values;
2121
	INIT_LIST_HEAD(&property->enum_blob_list);
2118
	INIT_LIST_HEAD(&property->enum_blob_list);
2122
 
2119
 
2123
	if (name)
2120
	if (name)
2124
		strncpy(property->name, name, DRM_PROP_NAME_LEN);
2121
		strncpy(property->name, name, DRM_PROP_NAME_LEN);
2125
 
2122
 
2126
	list_add_tail(&property->head, &dev->mode_config.property_list);
2123
	list_add_tail(&property->head, &dev->mode_config.property_list);
2127
	return property;
2124
	return property;
2128
fail:
2125
fail:
2129
	kfree(property);
2126
	kfree(property);
2130
	return NULL;
2127
	return NULL;
2131
}
2128
}
2132
EXPORT_SYMBOL(drm_property_create);
2129
EXPORT_SYMBOL(drm_property_create);
2133
 
2130
 
2134
int drm_property_add_enum(struct drm_property *property, int index,
2131
int drm_property_add_enum(struct drm_property *property, int index,
2135
			  uint64_t value, const char *name)
2132
			  uint64_t value, const char *name)
2136
{
2133
{
2137
	struct drm_property_enum *prop_enum;
2134
	struct drm_property_enum *prop_enum;
2138
 
2135
 
2139
	if (!(property->flags & DRM_MODE_PROP_ENUM))
2136
	if (!(property->flags & DRM_MODE_PROP_ENUM))
2140
		return -EINVAL;
2137
		return -EINVAL;
2141
 
2138
 
2142
	if (!list_empty(&property->enum_blob_list)) {
2139
	if (!list_empty(&property->enum_blob_list)) {
2143
		list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
2140
		list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
2144
			if (prop_enum->value == value) {
2141
			if (prop_enum->value == value) {
2145
				strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN);
2142
				strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN);
2146
				prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0';
2143
				prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0';
2147
				return 0;
2144
				return 0;
2148
			}
2145
			}
2149
		}
2146
		}
2150
	}
2147
	}
2151
 
2148
 
2152
	prop_enum = kzalloc(sizeof(struct drm_property_enum), GFP_KERNEL);
2149
	prop_enum = kzalloc(sizeof(struct drm_property_enum), GFP_KERNEL);
2153
	if (!prop_enum)
2150
	if (!prop_enum)
2154
		return -ENOMEM;
2151
		return -ENOMEM;
2155
 
2152
 
2156
	strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN);
2153
	strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN);
2157
	prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0';
2154
	prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0';
2158
	prop_enum->value = value;
2155
	prop_enum->value = value;
2159
 
2156
 
2160
	property->values[index] = value;
2157
	property->values[index] = value;
2161
	list_add_tail(&prop_enum->head, &property->enum_blob_list);
2158
	list_add_tail(&prop_enum->head, &property->enum_blob_list);
2162
	return 0;
2159
	return 0;
2163
}
2160
}
2164
EXPORT_SYMBOL(drm_property_add_enum);
2161
EXPORT_SYMBOL(drm_property_add_enum);
2165
 
2162
 
2166
void drm_property_destroy(struct drm_device *dev, struct drm_property *property)
2163
void drm_property_destroy(struct drm_device *dev, struct drm_property *property)
2167
{
2164
{
2168
	struct drm_property_enum *prop_enum, *pt;
2165
	struct drm_property_enum *prop_enum, *pt;
2169
 
2166
 
2170
	list_for_each_entry_safe(prop_enum, pt, &property->enum_blob_list, head) {
2167
	list_for_each_entry_safe(prop_enum, pt, &property->enum_blob_list, head) {
2171
		list_del(&prop_enum->head);
2168
		list_del(&prop_enum->head);
2172
		kfree(prop_enum);
2169
		kfree(prop_enum);
2173
	}
2170
	}
2174
 
2171
 
2175
	if (property->num_values)
2172
	if (property->num_values)
2176
		kfree(property->values);
2173
		kfree(property->values);
2177
	drm_mode_object_put(dev, &property->base);
2174
	drm_mode_object_put(dev, &property->base);
2178
	list_del(&property->head);
2175
	list_del(&property->head);
2179
	kfree(property);
2176
	kfree(property);
2180
}
2177
}
2181
EXPORT_SYMBOL(drm_property_destroy);
2178
EXPORT_SYMBOL(drm_property_destroy);
2182
 
2179
 
2183
int drm_connector_attach_property(struct drm_connector *connector,
2180
int drm_connector_attach_property(struct drm_connector *connector,
2184
			       struct drm_property *property, uint64_t init_val)
2181
			       struct drm_property *property, uint64_t init_val)
2185
{
2182
{
2186
	int i;
2183
	int i;
2187
 
2184
 
2188
	for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
2185
	for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
2189
		if (connector->property_ids[i] == 0) {
2186
		if (connector->property_ids[i] == 0) {
2190
			connector->property_ids[i] = property->base.id;
2187
			connector->property_ids[i] = property->base.id;
2191
			connector->property_values[i] = init_val;
2188
			connector->property_values[i] = init_val;
2192
			break;
2189
			break;
2193
		}
2190
		}
2194
	}
2191
	}
2195
 
2192
 
2196
	if (i == DRM_CONNECTOR_MAX_PROPERTY)
2193
	if (i == DRM_CONNECTOR_MAX_PROPERTY)
2197
		return -EINVAL;
2194
		return -EINVAL;
2198
	return 0;
2195
	return 0;
2199
}
2196
}
2200
EXPORT_SYMBOL(drm_connector_attach_property);
2197
EXPORT_SYMBOL(drm_connector_attach_property);
2201
 
2198
 
2202
int drm_connector_property_set_value(struct drm_connector *connector,
2199
int drm_connector_property_set_value(struct drm_connector *connector,
2203
				  struct drm_property *property, uint64_t value)
2200
				  struct drm_property *property, uint64_t value)
2204
{
2201
{
2205
	int i;
2202
	int i;
2206
 
2203
 
2207
	for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
2204
	for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
2208
		if (connector->property_ids[i] == property->base.id) {
2205
		if (connector->property_ids[i] == property->base.id) {
2209
			connector->property_values[i] = value;
2206
			connector->property_values[i] = value;
2210
			break;
2207
			break;
2211
		}
2208
		}
2212
	}
2209
	}
2213
 
2210
 
2214
	if (i == DRM_CONNECTOR_MAX_PROPERTY)
2211
	if (i == DRM_CONNECTOR_MAX_PROPERTY)
2215
		return -EINVAL;
2212
		return -EINVAL;
2216
	return 0;
2213
	return 0;
2217
}
2214
}
2218
EXPORT_SYMBOL(drm_connector_property_set_value);
2215
EXPORT_SYMBOL(drm_connector_property_set_value);
2219
 
2216
 
2220
int drm_connector_property_get_value(struct drm_connector *connector,
2217
int drm_connector_property_get_value(struct drm_connector *connector,
2221
				  struct drm_property *property, uint64_t *val)
2218
				  struct drm_property *property, uint64_t *val)
2222
{
2219
{
2223
	int i;
2220
	int i;
2224
 
2221
 
2225
	for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
2222
	for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
2226
		if (connector->property_ids[i] == property->base.id) {
2223
		if (connector->property_ids[i] == property->base.id) {
2227
			*val = connector->property_values[i];
2224
			*val = connector->property_values[i];
2228
			break;
2225
			break;
2229
		}
2226
		}
2230
	}
2227
	}
2231
 
2228
 
2232
	if (i == DRM_CONNECTOR_MAX_PROPERTY)
2229
	if (i == DRM_CONNECTOR_MAX_PROPERTY)
2233
		return -EINVAL;
2230
		return -EINVAL;
2234
	return 0;
2231
	return 0;
2235
}
2232
}
2236
EXPORT_SYMBOL(drm_connector_property_get_value);
2233
EXPORT_SYMBOL(drm_connector_property_get_value);
2237
 
2234
 
2238
#if 0
2235
#if 0
2239
int drm_mode_getproperty_ioctl(struct drm_device *dev,
2236
int drm_mode_getproperty_ioctl(struct drm_device *dev,
2240
			       void *data, struct drm_file *file_priv)
2237
			       void *data, struct drm_file *file_priv)
2241
{
2238
{
2242
	struct drm_mode_object *obj;
2239
	struct drm_mode_object *obj;
2243
	struct drm_mode_get_property *out_resp = data;
2240
	struct drm_mode_get_property *out_resp = data;
2244
	struct drm_property *property;
2241
	struct drm_property *property;
2245
	int enum_count = 0;
2242
	int enum_count = 0;
2246
	int blob_count = 0;
2243
	int blob_count = 0;
2247
	int value_count = 0;
2244
	int value_count = 0;
2248
	int ret = 0, i;
2245
	int ret = 0, i;
2249
	int copied;
2246
	int copied;
2250
	struct drm_property_enum *prop_enum;
2247
	struct drm_property_enum *prop_enum;
2251
	struct drm_mode_property_enum __user *enum_ptr;
2248
	struct drm_mode_property_enum __user *enum_ptr;
2252
	struct drm_property_blob *prop_blob;
2249
	struct drm_property_blob *prop_blob;
2253
	uint32_t *blob_id_ptr;
2250
	uint32_t *blob_id_ptr;
2254
	uint64_t __user *values_ptr;
2251
	uint64_t __user *values_ptr;
2255
	uint32_t __user *blob_length_ptr;
2252
	uint32_t __user *blob_length_ptr;
2256
 
2253
 
2257
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
2254
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
2258
		return -EINVAL;
2255
		return -EINVAL;
2259
 
2256
 
2260
	mutex_lock(&dev->mode_config.mutex);
2257
	mutex_lock(&dev->mode_config.mutex);
2261
	obj = drm_mode_object_find(dev, out_resp->prop_id, DRM_MODE_OBJECT_PROPERTY);
2258
	obj = drm_mode_object_find(dev, out_resp->prop_id, DRM_MODE_OBJECT_PROPERTY);
2262
	if (!obj) {
2259
	if (!obj) {
2263
		ret = -EINVAL;
2260
		ret = -EINVAL;
2264
		goto done;
2261
		goto done;
2265
	}
2262
	}
2266
	property = obj_to_property(obj);
2263
	property = obj_to_property(obj);
2267
 
2264
 
2268
	if (property->flags & DRM_MODE_PROP_ENUM) {
2265
	if (property->flags & DRM_MODE_PROP_ENUM) {
2269
		list_for_each_entry(prop_enum, &property->enum_blob_list, head)
2266
		list_for_each_entry(prop_enum, &property->enum_blob_list, head)
2270
			enum_count++;
2267
			enum_count++;
2271
	} else if (property->flags & DRM_MODE_PROP_BLOB) {
2268
	} else if (property->flags & DRM_MODE_PROP_BLOB) {
2272
		list_for_each_entry(prop_blob, &property->enum_blob_list, head)
2269
		list_for_each_entry(prop_blob, &property->enum_blob_list, head)
2273
			blob_count++;
2270
			blob_count++;
2274
	}
2271
	}
2275
 
2272
 
2276
	value_count = property->num_values;
2273
	value_count = property->num_values;
2277
 
2274
 
2278
	strncpy(out_resp->name, property->name, DRM_PROP_NAME_LEN);
2275
	strncpy(out_resp->name, property->name, DRM_PROP_NAME_LEN);
2279
	out_resp->name[DRM_PROP_NAME_LEN-1] = 0;
2276
	out_resp->name[DRM_PROP_NAME_LEN-1] = 0;
2280
	out_resp->flags = property->flags;
2277
	out_resp->flags = property->flags;
2281
 
2278
 
2282
	if ((out_resp->count_values >= value_count) && value_count) {
2279
	if ((out_resp->count_values >= value_count) && value_count) {
2283
		values_ptr = (uint64_t *)(unsigned long)out_resp->values_ptr;
2280
		values_ptr = (uint64_t *)(unsigned long)out_resp->values_ptr;
2284
		for (i = 0; i < value_count; i++) {
2281
		for (i = 0; i < value_count; i++) {
2285
			if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
2282
			if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
2286
				ret = -EFAULT;
2283
				ret = -EFAULT;
2287
				goto done;
2284
				goto done;
2288
			}
2285
			}
2289
		}
2286
		}
2290
	}
2287
	}
2291
	out_resp->count_values = value_count;
2288
	out_resp->count_values = value_count;
2292
 
2289
 
2293
	if (property->flags & DRM_MODE_PROP_ENUM) {
2290
	if (property->flags & DRM_MODE_PROP_ENUM) {
2294
		if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
2291
		if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
2295
			copied = 0;
2292
			copied = 0;
2296
			enum_ptr = (struct drm_mode_property_enum *)(unsigned long)out_resp->enum_blob_ptr;
2293
			enum_ptr = (struct drm_mode_property_enum *)(unsigned long)out_resp->enum_blob_ptr;
2297
			list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
2294
			list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
2298
 
2295
 
2299
				if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
2296
				if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
2300
					ret = -EFAULT;
2297
					ret = -EFAULT;
2301
					goto done;
2298
					goto done;
2302
				}
2299
				}
2303
 
2300
 
2304
				if (copy_to_user(&enum_ptr[copied].name,
2301
				if (copy_to_user(&enum_ptr[copied].name,
2305
						 &prop_enum->name, DRM_PROP_NAME_LEN)) {
2302
						 &prop_enum->name, DRM_PROP_NAME_LEN)) {
2306
					ret = -EFAULT;
2303
					ret = -EFAULT;
2307
					goto done;
2304
					goto done;
2308
				}
2305
				}
2309
				copied++;
2306
				copied++;
2310
			}
2307
			}
2311
		}
2308
		}
2312
		out_resp->count_enum_blobs = enum_count;
2309
		out_resp->count_enum_blobs = enum_count;
2313
	}
2310
	}
2314
 
2311
 
2315
	if (property->flags & DRM_MODE_PROP_BLOB) {
2312
	if (property->flags & DRM_MODE_PROP_BLOB) {
2316
		if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
2313
		if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
2317
			copied = 0;
2314
			copied = 0;
2318
			blob_id_ptr = (uint32_t *)(unsigned long)out_resp->enum_blob_ptr;
2315
			blob_id_ptr = (uint32_t *)(unsigned long)out_resp->enum_blob_ptr;
2319
			blob_length_ptr = (uint32_t *)(unsigned long)out_resp->values_ptr;
2316
			blob_length_ptr = (uint32_t *)(unsigned long)out_resp->values_ptr;
2320
 
2317
 
2321
			list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
2318
			list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
2322
				if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
2319
				if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
2323
					ret = -EFAULT;
2320
					ret = -EFAULT;
2324
					goto done;
2321
					goto done;
2325
				}
2322
				}
2326
 
2323
 
2327
				if (put_user(prop_blob->length, blob_length_ptr + copied)) {
2324
				if (put_user(prop_blob->length, blob_length_ptr + copied)) {
2328
					ret = -EFAULT;
2325
					ret = -EFAULT;
2329
					goto done;
2326
					goto done;
2330
				}
2327
				}
2331
 
2328
 
2332
				copied++;
2329
				copied++;
2333
			}
2330
			}
2334
		}
2331
		}
2335
		out_resp->count_enum_blobs = blob_count;
2332
		out_resp->count_enum_blobs = blob_count;
2336
	}
2333
	}
2337
done:
2334
done:
2338
	mutex_unlock(&dev->mode_config.mutex);
2335
	mutex_unlock(&dev->mode_config.mutex);
2339
	return ret;
2336
	return ret;
2340
}
2337
}
2341
#endif
2338
#endif
2342
 
2339
 
2343
static struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, int length,
2340
static struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, int length,
2344
							  void *data)
2341
							  void *data)
2345
{
2342
{
2346
	struct drm_property_blob *blob;
2343
	struct drm_property_blob *blob;
2347
 
2344
 
2348
	if (!length || !data)
2345
	if (!length || !data)
2349
		return NULL;
2346
		return NULL;
2350
 
2347
 
2351
	blob = kzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL);
2348
	blob = kzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL);
2352
	if (!blob)
2349
	if (!blob)
2353
		return NULL;
2350
		return NULL;
2354
 
2351
 
2355
	blob->data = (void *)((char *)blob + sizeof(struct drm_property_blob));
2352
	blob->data = (void *)((char *)blob + sizeof(struct drm_property_blob));
2356
	blob->length = length;
2353
	blob->length = length;
2357
 
2354
 
2358
	memcpy(blob->data, data, length);
2355
	memcpy(blob->data, data, length);
2359
 
2356
 
2360
	drm_mode_object_get(dev, &blob->base, DRM_MODE_OBJECT_BLOB);
2357
	drm_mode_object_get(dev, &blob->base, DRM_MODE_OBJECT_BLOB);
2361
 
2358
 
2362
	list_add_tail(&blob->head, &dev->mode_config.property_blob_list);
2359
	list_add_tail(&blob->head, &dev->mode_config.property_blob_list);
2363
	return blob;
2360
	return blob;
2364
}
2361
}
2365
 
2362
 
2366
static void drm_property_destroy_blob(struct drm_device *dev,
2363
static void drm_property_destroy_blob(struct drm_device *dev,
2367
			       struct drm_property_blob *blob)
2364
			       struct drm_property_blob *blob)
2368
{
2365
{
2369
	drm_mode_object_put(dev, &blob->base);
2366
	drm_mode_object_put(dev, &blob->base);
2370
	list_del(&blob->head);
2367
	list_del(&blob->head);
2371
	kfree(blob);
2368
	kfree(blob);
2372
}
2369
}
2373
 
2370
 
2374
#if 0
2371
#if 0
2375
int drm_mode_getblob_ioctl(struct drm_device *dev,
2372
int drm_mode_getblob_ioctl(struct drm_device *dev,
2376
			   void *data, struct drm_file *file_priv)
2373
			   void *data, struct drm_file *file_priv)
2377
{
2374
{
2378
	struct drm_mode_object *obj;
2375
	struct drm_mode_object *obj;
2379
	struct drm_mode_get_blob *out_resp = data;
2376
	struct drm_mode_get_blob *out_resp = data;
2380
	struct drm_property_blob *blob;
2377
	struct drm_property_blob *blob;
2381
	int ret = 0;
2378
	int ret = 0;
2382
	void *blob_ptr;
2379
	void *blob_ptr;
2383
 
2380
 
2384
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
2381
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
2385
		return -EINVAL;
2382
		return -EINVAL;
2386
 
2383
 
2387
	mutex_lock(&dev->mode_config.mutex);
2384
	mutex_lock(&dev->mode_config.mutex);
2388
	obj = drm_mode_object_find(dev, out_resp->blob_id, DRM_MODE_OBJECT_BLOB);
2385
	obj = drm_mode_object_find(dev, out_resp->blob_id, DRM_MODE_OBJECT_BLOB);
2389
	if (!obj) {
2386
	if (!obj) {
2390
		ret = -EINVAL;
2387
		ret = -EINVAL;
2391
		goto done;
2388
		goto done;
2392
	}
2389
	}
2393
	blob = obj_to_blob(obj);
2390
	blob = obj_to_blob(obj);
2394
 
2391
 
2395
	if (out_resp->length == blob->length) {
2392
	if (out_resp->length == blob->length) {
2396
		blob_ptr = (void *)(unsigned long)out_resp->data;
2393
		blob_ptr = (void *)(unsigned long)out_resp->data;
2397
		if (copy_to_user(blob_ptr, blob->data, blob->length)){
2394
		if (copy_to_user(blob_ptr, blob->data, blob->length)){
2398
			ret = -EFAULT;
2395
			ret = -EFAULT;
2399
			goto done;
2396
			goto done;
2400
		}
2397
		}
2401
	}
2398
	}
2402
	out_resp->length = blob->length;
2399
	out_resp->length = blob->length;
2403
 
2400
 
2404
done:
2401
done:
2405
	mutex_unlock(&dev->mode_config.mutex);
2402
	mutex_unlock(&dev->mode_config.mutex);
2406
	return ret;
2403
	return ret;
2407
}
2404
}
2408
#endif
2405
#endif
2409
 
2406
 
2410
int drm_mode_connector_update_edid_property(struct drm_connector *connector,
2407
int drm_mode_connector_update_edid_property(struct drm_connector *connector,
2411
					    struct edid *edid)
2408
					    struct edid *edid)
2412
{
2409
{
2413
	struct drm_device *dev = connector->dev;
2410
	struct drm_device *dev = connector->dev;
2414
	int ret = 0, size;
2411
	int ret = 0, size;
2415
 
2412
 
2416
	if (connector->edid_blob_ptr)
2413
	if (connector->edid_blob_ptr)
2417
		drm_property_destroy_blob(dev, connector->edid_blob_ptr);
2414
		drm_property_destroy_blob(dev, connector->edid_blob_ptr);
2418
 
2415
 
2419
	/* Delete edid, when there is none. */
2416
	/* Delete edid, when there is none. */
2420
	if (!edid) {
2417
	if (!edid) {
2421
		connector->edid_blob_ptr = NULL;
2418
		connector->edid_blob_ptr = NULL;
2422
		ret = drm_connector_property_set_value(connector, dev->mode_config.edid_property, 0);
2419
		ret = drm_connector_property_set_value(connector, dev->mode_config.edid_property, 0);
2423
		return ret;
2420
		return ret;
2424
	}
2421
	}
2425
 
2422
 
2426
	size = EDID_LENGTH * (1 + edid->extensions);
2423
	size = EDID_LENGTH * (1 + edid->extensions);
2427
	connector->edid_blob_ptr = drm_property_create_blob(connector->dev,
2424
	connector->edid_blob_ptr = drm_property_create_blob(connector->dev,
2428
							    size, edid);
2425
							    size, edid);
2429
 
2426
 
2430
	ret = drm_connector_property_set_value(connector,
2427
	ret = drm_connector_property_set_value(connector,
2431
					       dev->mode_config.edid_property,
2428
					       dev->mode_config.edid_property,
2432
					       connector->edid_blob_ptr->base.id);
2429
					       connector->edid_blob_ptr->base.id);
2433
 
2430
 
2434
	return ret;
2431
	return ret;
2435
}
2432
}
2436
EXPORT_SYMBOL(drm_mode_connector_update_edid_property);
2433
EXPORT_SYMBOL(drm_mode_connector_update_edid_property);
2437
 
2434
 
2438
#if 0
2435
#if 0
2439
int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
2436
int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
2440
				       void *data, struct drm_file *file_priv)
2437
				       void *data, struct drm_file *file_priv)
2441
{
2438
{
2442
	struct drm_mode_connector_set_property *out_resp = data;
2439
	struct drm_mode_connector_set_property *out_resp = data;
2443
	struct drm_mode_object *obj;
2440
	struct drm_mode_object *obj;
2444
	struct drm_property *property;
2441
	struct drm_property *property;
2445
	struct drm_connector *connector;
2442
	struct drm_connector *connector;
2446
	int ret = -EINVAL;
2443
	int ret = -EINVAL;
2447
	int i;
2444
	int i;
2448
 
2445
 
2449
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
2446
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
2450
		return -EINVAL;
2447
		return -EINVAL;
2451
 
2448
 
2452
	mutex_lock(&dev->mode_config.mutex);
2449
	mutex_lock(&dev->mode_config.mutex);
2453
 
2450
 
2454
	obj = drm_mode_object_find(dev, out_resp->connector_id, DRM_MODE_OBJECT_CONNECTOR);
2451
	obj = drm_mode_object_find(dev, out_resp->connector_id, DRM_MODE_OBJECT_CONNECTOR);
2455
	if (!obj) {
2452
	if (!obj) {
2456
		goto out;
2453
		goto out;
2457
	}
2454
	}
2458
	connector = obj_to_connector(obj);
2455
	connector = obj_to_connector(obj);
2459
 
2456
 
2460
	for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
2457
	for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
2461
		if (connector->property_ids[i] == out_resp->prop_id)
2458
		if (connector->property_ids[i] == out_resp->prop_id)
2462
			break;
2459
			break;
2463
	}
2460
	}
2464
 
2461
 
2465
	if (i == DRM_CONNECTOR_MAX_PROPERTY) {
2462
	if (i == DRM_CONNECTOR_MAX_PROPERTY) {
2466
		goto out;
2463
		goto out;
2467
	}
2464
	}
2468
 
2465
 
2469
	obj = drm_mode_object_find(dev, out_resp->prop_id, DRM_MODE_OBJECT_PROPERTY);
2466
	obj = drm_mode_object_find(dev, out_resp->prop_id, DRM_MODE_OBJECT_PROPERTY);
2470
	if (!obj) {
2467
	if (!obj) {
2471
		goto out;
2468
		goto out;
2472
	}
2469
	}
2473
	property = obj_to_property(obj);
2470
	property = obj_to_property(obj);
2474
 
2471
 
2475
	if (property->flags & DRM_MODE_PROP_IMMUTABLE)
2472
	if (property->flags & DRM_MODE_PROP_IMMUTABLE)
2476
		goto out;
2473
		goto out;
2477
 
2474
 
2478
	if (property->flags & DRM_MODE_PROP_RANGE) {
2475
	if (property->flags & DRM_MODE_PROP_RANGE) {
2479
		if (out_resp->value < property->values[0])
2476
		if (out_resp->value < property->values[0])
2480
			goto out;
2477
			goto out;
2481
 
2478
 
2482
		if (out_resp->value > property->values[1])
2479
		if (out_resp->value > property->values[1])
2483
			goto out;
2480
			goto out;
2484
	} else {
2481
	} else {
2485
		int found = 0;
2482
		int found = 0;
2486
		for (i = 0; i < property->num_values; i++) {
2483
		for (i = 0; i < property->num_values; i++) {
2487
			if (property->values[i] == out_resp->value) {
2484
			if (property->values[i] == out_resp->value) {
2488
				found = 1;
2485
				found = 1;
2489
				break;
2486
				break;
2490
			}
2487
			}
2491
		}
2488
		}
2492
		if (!found) {
2489
		if (!found) {
2493
			goto out;
2490
			goto out;
2494
		}
2491
		}
2495
	}
2492
	}
2496
 
2493
 
2497
	/* Do DPMS ourselves */
2494
	/* Do DPMS ourselves */
2498
	if (property == connector->dev->mode_config.dpms_property) {
2495
	if (property == connector->dev->mode_config.dpms_property) {
2499
		if (connector->funcs->dpms)
2496
		if (connector->funcs->dpms)
2500
			(*connector->funcs->dpms)(connector, (int) out_resp->value);
2497
			(*connector->funcs->dpms)(connector, (int) out_resp->value);
2501
		ret = 0;
2498
		ret = 0;
2502
	} else if (connector->funcs->set_property)
2499
	} else if (connector->funcs->set_property)
2503
		ret = connector->funcs->set_property(connector, property, out_resp->value);
2500
		ret = connector->funcs->set_property(connector, property, out_resp->value);
2504
 
2501
 
2505
	/* store the property value if successful */
2502
	/* store the property value if successful */
2506
	if (!ret)
2503
	if (!ret)
2507
		drm_connector_property_set_value(connector, property, out_resp->value);
2504
		drm_connector_property_set_value(connector, property, out_resp->value);
2508
out:
2505
out:
2509
	mutex_unlock(&dev->mode_config.mutex);
2506
	mutex_unlock(&dev->mode_config.mutex);
2510
	return ret;
2507
	return ret;
2511
}
2508
}
2512
#endif
2509
#endif
2513
 
2510
 
2514
int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2511
int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2515
				      struct drm_encoder *encoder)
2512
				      struct drm_encoder *encoder)
2516
{
2513
{
2517
	int i;
2514
	int i;
2518
 
2515
 
2519
	for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
2516
	for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
2520
		if (connector->encoder_ids[i] == 0) {
2517
		if (connector->encoder_ids[i] == 0) {
2521
			connector->encoder_ids[i] = encoder->base.id;
2518
			connector->encoder_ids[i] = encoder->base.id;
2522
			return 0;
2519
			return 0;
2523
		}
2520
		}
2524
	}
2521
	}
2525
	return -ENOMEM;
2522
	return -ENOMEM;
2526
}
2523
}
2527
EXPORT_SYMBOL(drm_mode_connector_attach_encoder);
2524
EXPORT_SYMBOL(drm_mode_connector_attach_encoder);
2528
 
2525
 
2529
void drm_mode_connector_detach_encoder(struct drm_connector *connector,
2526
void drm_mode_connector_detach_encoder(struct drm_connector *connector,
2530
				    struct drm_encoder *encoder)
2527
				    struct drm_encoder *encoder)
2531
{
2528
{
2532
	int i;
2529
	int i;
2533
	for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
2530
	for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
2534
		if (connector->encoder_ids[i] == encoder->base.id) {
2531
		if (connector->encoder_ids[i] == encoder->base.id) {
2535
			connector->encoder_ids[i] = 0;
2532
			connector->encoder_ids[i] = 0;
2536
			if (connector->encoder == encoder)
2533
			if (connector->encoder == encoder)
2537
				connector->encoder = NULL;
2534
				connector->encoder = NULL;
2538
			break;
2535
			break;
2539
		}
2536
		}
2540
	}
2537
	}
2541
}
2538
}
2542
EXPORT_SYMBOL(drm_mode_connector_detach_encoder);
2539
EXPORT_SYMBOL(drm_mode_connector_detach_encoder);
2543
 
2540
 
2544
bool drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
2541
bool drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
2545
				  int gamma_size)
2542
				  int gamma_size)
2546
{
2543
{
2547
	crtc->gamma_size = gamma_size;
2544
	crtc->gamma_size = gamma_size;
2548
 
2545
 
2549
	crtc->gamma_store = kzalloc(gamma_size * sizeof(uint16_t) * 3, GFP_KERNEL);
2546
	crtc->gamma_store = kzalloc(gamma_size * sizeof(uint16_t) * 3, GFP_KERNEL);
2550
	if (!crtc->gamma_store) {
2547
	if (!crtc->gamma_store) {
2551
		crtc->gamma_size = 0;
2548
		crtc->gamma_size = 0;
2552
		return false;
2549
		return false;
2553
	}
2550
	}
2554
 
2551
 
2555
	return true;
2552
	return true;
2556
}
2553
}
2557
EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size);
2554
EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size);
2558
 
2555
 
2559
#if 0
2556
#if 0
2560
int drm_mode_gamma_set_ioctl(struct drm_device *dev,
2557
int drm_mode_gamma_set_ioctl(struct drm_device *dev,
2561
			     void *data, struct drm_file *file_priv)
2558
			     void *data, struct drm_file *file_priv)
2562
{
2559
{
2563
	struct drm_mode_crtc_lut *crtc_lut = data;
2560
	struct drm_mode_crtc_lut *crtc_lut = data;
2564
	struct drm_mode_object *obj;
2561
	struct drm_mode_object *obj;
2565
	struct drm_crtc *crtc;
2562
	struct drm_crtc *crtc;
2566
	void *r_base, *g_base, *b_base;
2563
	void *r_base, *g_base, *b_base;
2567
	int size;
2564
	int size;
2568
	int ret = 0;
2565
	int ret = 0;
2569
 
2566
 
2570
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
2567
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
2571
		return -EINVAL;
2568
		return -EINVAL;
2572
 
2569
 
2573
	mutex_lock(&dev->mode_config.mutex);
2570
	mutex_lock(&dev->mode_config.mutex);
2574
	obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC);
2571
	obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC);
2575
	if (!obj) {
2572
	if (!obj) {
2576
		ret = -EINVAL;
2573
		ret = -EINVAL;
2577
		goto out;
2574
		goto out;
2578
	}
2575
	}
2579
	crtc = obj_to_crtc(obj);
2576
	crtc = obj_to_crtc(obj);
2580
 
2577
 
2581
	/* memcpy into gamma store */
2578
	/* memcpy into gamma store */
2582
	if (crtc_lut->gamma_size != crtc->gamma_size) {
2579
	if (crtc_lut->gamma_size != crtc->gamma_size) {
2583
		ret = -EINVAL;
2580
		ret = -EINVAL;
2584
		goto out;
2581
		goto out;
2585
	}
2582
	}
2586
 
2583
 
2587
	size = crtc_lut->gamma_size * (sizeof(uint16_t));
2584
	size = crtc_lut->gamma_size * (sizeof(uint16_t));
2588
	r_base = crtc->gamma_store;
2585
	r_base = crtc->gamma_store;
2589
	if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) {
2586
	if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) {
2590
		ret = -EFAULT;
2587
		ret = -EFAULT;
2591
		goto out;
2588
		goto out;
2592
	}
2589
	}
2593
 
2590
 
2594
	g_base = r_base + size;
2591
	g_base = r_base + size;
2595
	if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) {
2592
	if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) {
2596
		ret = -EFAULT;
2593
		ret = -EFAULT;
2597
		goto out;
2594
		goto out;
2598
	}
2595
	}
2599
 
2596
 
2600
	b_base = g_base + size;
2597
	b_base = g_base + size;
2601
	if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) {
2598
	if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) {
2602
		ret = -EFAULT;
2599
		ret = -EFAULT;
2603
		goto out;
2600
		goto out;
2604
	}
2601
	}
2605
 
2602
 
2606
	crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size);
2603
	crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size);
2607
 
2604
 
2608
out:
2605
out:
2609
	mutex_unlock(&dev->mode_config.mutex);
2606
	mutex_unlock(&dev->mode_config.mutex);
2610
	return ret;
2607
	return ret;
2611
 
2608
 
2612
}
2609
}
2613
 
2610
 
2614
int drm_mode_gamma_get_ioctl(struct drm_device *dev,
2611
int drm_mode_gamma_get_ioctl(struct drm_device *dev,
2615
			     void *data, struct drm_file *file_priv)
2612
			     void *data, struct drm_file *file_priv)
2616
{
2613
{
2617
	struct drm_mode_crtc_lut *crtc_lut = data;
2614
	struct drm_mode_crtc_lut *crtc_lut = data;
2618
	struct drm_mode_object *obj;
2615
	struct drm_mode_object *obj;
2619
	struct drm_crtc *crtc;
2616
	struct drm_crtc *crtc;
2620
	void *r_base, *g_base, *b_base;
2617
	void *r_base, *g_base, *b_base;
2621
	int size;
2618
	int size;
2622
	int ret = 0;
2619
	int ret = 0;
2623
 
2620
 
2624
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
2621
	if (!drm_core_check_feature(dev, DRIVER_MODESET))
2625
		return -EINVAL;
2622
		return -EINVAL;
2626
 
2623
 
2627
	mutex_lock(&dev->mode_config.mutex);
2624
	mutex_lock(&dev->mode_config.mutex);
2628
	obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC);
2625
	obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC);
2629
	if (!obj) {
2626
	if (!obj) {
2630
		ret = -EINVAL;
2627
		ret = -EINVAL;
2631
		goto out;
2628
		goto out;
2632
	}
2629
	}
2633
	crtc = obj_to_crtc(obj);
2630
	crtc = obj_to_crtc(obj);
2634
 
2631
 
2635
	/* memcpy into gamma store */
2632
	/* memcpy into gamma store */
2636
	if (crtc_lut->gamma_size != crtc->gamma_size) {
2633
	if (crtc_lut->gamma_size != crtc->gamma_size) {
2637
		ret = -EINVAL;
2634
		ret = -EINVAL;
2638
		goto out;
2635
		goto out;
2639
	}
2636
	}
2640
 
2637
 
2641
	size = crtc_lut->gamma_size * (sizeof(uint16_t));
2638
	size = crtc_lut->gamma_size * (sizeof(uint16_t));
2642
	r_base = crtc->gamma_store;
2639
	r_base = crtc->gamma_store;
2643
	if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) {
2640
	if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) {
2644
		ret = -EFAULT;
2641
		ret = -EFAULT;
2645
		goto out;
2642
		goto out;
2646
	}
2643
	}
2647
 
2644
 
2648
	g_base = r_base + size;
2645
	g_base = r_base + size;
2649
	if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) {
2646
	if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) {
2650
		ret = -EFAULT;
2647
		ret = -EFAULT;
2651
		goto out;
2648
		goto out;
2652
	}
2649
	}
2653
 
2650
 
2654
	b_base = g_base + size;
2651
	b_base = g_base + size;
2655
	if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) {
2652
	if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) {
2656
		ret = -EFAULT;
2653
		ret = -EFAULT;
2657
		goto out;
2654
		goto out;
2658
	}
2655
	}
2659
out:
2656
out:
2660
	mutex_unlock(&dev->mode_config.mutex);
2657
	mutex_unlock(&dev->mode_config.mutex);
2661
	return ret;
2658
	return ret;
2662
}
2659
}
2663
 
2660
 
2664
#endif
2661
#endif
2665
 
2662
 
2666
 
2663
 
2667
void drm_mode_config_reset(struct drm_device *dev)
2664
void drm_mode_config_reset(struct drm_device *dev)
2668
{
2665
{
2669
	struct drm_crtc *crtc;
2666
	struct drm_crtc *crtc;
2670
	struct drm_encoder *encoder;
2667
	struct drm_encoder *encoder;
2671
	struct drm_connector *connector;
2668
	struct drm_connector *connector;
2672
 
2669
 
2673
	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
2670
	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
2674
		if (crtc->funcs->reset)
2671
		if (crtc->funcs->reset)
2675
			crtc->funcs->reset(crtc);
2672
			crtc->funcs->reset(crtc);
2676
 
2673
 
2677
	list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
2674
	list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
2678
		if (encoder->funcs->reset)
2675
		if (encoder->funcs->reset)
2679
			encoder->funcs->reset(encoder);
2676
			encoder->funcs->reset(encoder);
2680
 
2677
 
2681
	list_for_each_entry(connector, &dev->mode_config.connector_list, head)
2678
	list_for_each_entry(connector, &dev->mode_config.connector_list, head)
2682
		if (connector->funcs->reset)
2679
		if (connector->funcs->reset)
2683
			connector->funcs->reset(connector);
2680
			connector->funcs->reset(connector);
2684
}
2681
}
2685
EXPORT_SYMBOL(drm_mode_config_reset);
2682
EXPORT_SYMBOL(drm_mode_config_reset);