2 * Copyright (c) 2006-2007 Intel Corporation
3 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
5 * DRM core CRTC related functions
7 * Permission to use, copy, modify, distribute, and sell this software and its
8 * documentation for any purpose is hereby granted without fee, provided that
9 * the above copyright notice appear in all copies and that both that copyright
10 * notice and this permission notice appear in supporting documentation, and
11 * that the name of the copyright holders not be used in advertising or
12 * publicity pertaining to distribution of the software without specific,
13 * written prior permission. The copyright holders make no representations
14 * about the suitability of this software for any purpose. It is provided "as
15 * is" without express or implied warranty.
17 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
19 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
20 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
27 * Eric Anholt <eric@anholt.net>
28 * Dave Airlie <airlied@linux.ie>
29 * Jesse Barnes <jesse.barnes@intel.com>
31 #include <linux/list.h>
37 * drm_idr_get - allocate a new identifier
39 * @ptr: object pointer, used to generate unique ID
42 * Caller must hold DRM mode_config lock.
44 * Create a unique identifier based on @ptr in @dev's identifier space. Used
45 * for tracking modes, CRTCs and outputs.
48 * New unique (relative to other objects in @dev) integer identifier for the
51 int drm_idr_get(struct drm_device *dev, void *ptr)
56 if (idr_pre_get(&dev->mode_config.crtc_idr, GFP_KERNEL) == 0) {
57 DRM_ERROR("Ran out memory getting a mode number\n");
61 ret = idr_get_new_above(&dev->mode_config.crtc_idr, ptr, 1, &new_id);
69 * drm_idr_put - free an identifer
74 * Caller must hold DRM mode_config lock.
76 * Free @id from @dev's unique identifier pool.
78 void drm_idr_put(struct drm_device *dev, int id)
80 idr_remove(&dev->mode_config.crtc_idr, id);
84 * drm_crtc_from_fb - find the CRTC structure associated with an fb
86 * @fb: framebuffer in question
89 * Caller must hold mode_config lock.
91 * Find CRTC in the mode_config structure that matches @fb.
94 * Pointer to the CRTC or NULL if it wasn't found.
96 struct drm_crtc *drm_crtc_from_fb(struct drm_device *dev,
97 struct drm_framebuffer *fb)
99 struct drm_crtc *crtc;
101 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
109 * drm_framebuffer_create - create a new framebuffer object
113 * Caller must hold mode config lock.
115 * Creates a new framebuffer objects and adds it to @dev's DRM mode_config.
118 * Pointer to new framebuffer or NULL on error.
120 struct drm_framebuffer *drm_framebuffer_create(struct drm_device *dev)
122 struct drm_framebuffer *fb;
124 /* Limit to single framebuffer for now */
125 if (dev->mode_config.num_fb > 1) {
126 mutex_unlock(&dev->mode_config.mutex);
127 DRM_ERROR("Attempt to add multiple framebuffers failed\n");
131 fb = kzalloc(sizeof(struct drm_framebuffer), GFP_KERNEL);
135 fb->id = drm_idr_get(dev, fb);
137 dev->mode_config.num_fb++;
138 list_add(&fb->head, &dev->mode_config.fb_list);
142 EXPORT_SYMBOL(drm_framebuffer_create);
145 * drm_framebuffer_destroy - remove a framebuffer object
146 * @fb: framebuffer to remove
149 * Caller must hold mode config lock.
151 * Scans all the CRTCs in @dev's mode_config. If they're using @fb, removes
152 * it, setting it to NULL.
154 void drm_framebuffer_destroy(struct drm_framebuffer *fb)
156 struct drm_device *dev = fb->dev;
157 struct drm_crtc *crtc;
159 /* remove from any CRTC */
160 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
165 drm_idr_put(dev, fb->id);
167 dev->mode_config.num_fb--;
171 EXPORT_SYMBOL(drm_framebuffer_destroy);
174 * drm_crtc_create - create a new CRTC object
176 * @funcs: callbacks for the new CRTC
179 * Caller must hold mode config lock.
181 * Creates a new CRTC object and adds it to @dev's mode_config structure.
184 * Pointer to new CRTC object or NULL on error.
186 struct drm_crtc *drm_crtc_create(struct drm_device *dev,
187 const struct drm_crtc_funcs *funcs)
189 struct drm_crtc *crtc;
191 crtc = kzalloc(sizeof(struct drm_crtc), GFP_KERNEL);
198 crtc->id = drm_idr_get(dev, crtc);
200 list_add_tail(&crtc->head, &dev->mode_config.crtc_list);
201 dev->mode_config.num_crtc++;
205 EXPORT_SYMBOL(drm_crtc_create);
208 * drm_crtc_destroy - remove a CRTC object
209 * @crtc: CRTC to remove
212 * Caller must hold mode config lock.
214 * Cleanup @crtc. Calls @crtc's cleanup function, then removes @crtc from
215 * its associated DRM device's mode_config. Frees it afterwards.
217 void drm_crtc_destroy(struct drm_crtc *crtc)
219 struct drm_device *dev = crtc->dev;
221 if (crtc->funcs->cleanup)
222 (*crtc->funcs->cleanup)(crtc);
224 drm_idr_put(dev, crtc->id);
225 list_del(&crtc->head);
226 dev->mode_config.num_crtc--;
229 EXPORT_SYMBOL(drm_crtc_destroy);
232 * drm_crtc_in_use - check if a given CRTC is in a mode_config
233 * @crtc: CRTC to check
236 * Caller must hold mode config lock.
238 * Walk @crtc's DRM device's mode_config and see if it's in use.
241 * True if @crtc is part of the mode_config, false otherwise.
243 bool drm_crtc_in_use(struct drm_crtc *crtc)
245 struct drm_output *output;
246 struct drm_device *dev = crtc->dev;
247 /* FIXME: Locking around list access? */
248 list_for_each_entry(output, &dev->mode_config.output_list, head)
249 if (output->crtc == crtc)
253 EXPORT_SYMBOL(drm_crtc_in_use);
256 * Detailed mode info for a standard 640x480@60Hz monitor
258 static struct drm_display_mode std_mode[] = {
259 { DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 25200, 640, 656,
260 752, 800, 0, 480, 490, 492, 525, 0,
261 V_NHSYNC | V_NVSYNC) }, /* 640x480@60Hz */
265 * drm_crtc_probe_output_modes - get complete set of display modes
267 * @maxX: max width for modes
268 * @maxY: max height for modes
271 * Caller must hold mode config lock.
273 * Based on @dev's mode_config layout, scan all the outputs and try to detect
274 * modes on them. Modes will first be added to the output's probed_modes
275 * list, then culled (based on validity and the @maxX, @maxY parameters) and
276 * put into the normal modes list.
278 * Intended to be used either at bootup time or when major configuration
279 * changes have occurred.
281 * FIXME: take into account monitor limits
283 void drm_crtc_probe_output_modes(struct drm_device *dev, int maxX, int maxY)
285 struct drm_output *output;
286 struct drm_display_mode *mode, *t;
288 //if (maxX == 0 || maxY == 0)
291 list_for_each_entry(output, &dev->mode_config.output_list, head) {
293 /* set all modes to the unverified state */
294 list_for_each_entry_safe(mode, t, &output->modes, head)
295 mode->status = MODE_UNVERIFIED;
297 output->status = (*output->funcs->detect)(output);
299 if (output->status == output_status_disconnected) {
300 DRM_DEBUG("%s is disconnected\n", output->name);
301 /* TODO set EDID to NULL */
305 ret = (*output->funcs->get_modes)(output);
308 drm_mode_output_list_update(output);
312 drm_mode_validate_size(dev, &output->modes, maxX,
314 list_for_each_entry_safe(mode, t, &output->modes, head) {
315 if (mode->status == MODE_OK)
316 mode->status = (*output->funcs->mode_valid)(output,mode);
320 drm_mode_prune_invalid(dev, &output->modes, TRUE);
322 if (list_empty(&output->modes)) {
323 struct drm_display_mode *stdmode;
325 DRM_DEBUG("No valid modes on %s\n", output->name);
327 /* Should we do this here ???
328 * When no valid EDID modes are available we end up
329 * here and bailed in the past, now we add a standard
330 * 640x480@60Hz mode and carry on.
332 stdmode = drm_mode_duplicate(dev, &std_mode[0]);
333 drm_mode_probed_add(output, stdmode);
334 drm_mode_list_concat(&output->probed_modes,
337 DRM_DEBUG("Adding standard 640x480 @ 60Hz to %s\n",
341 drm_mode_sort(&output->modes);
343 DRM_DEBUG("Probed modes for %s\n", output->name);
344 list_for_each_entry_safe(mode, t, &output->modes, head) {
345 mode->vrefresh = drm_mode_vrefresh(mode);
347 drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
348 drm_mode_debug_printmodeline(dev, mode);
354 * drm_crtc_set_mode - set a mode
355 * @crtc: CRTC to program
361 * Caller must hold mode config lock.
363 * Try to set @mode on @crtc. Give @crtc and its associated outputs a chance
364 * to fixup or reject the mode prior to trying to set it.
367 * True if the mode was set successfully, or false otherwise.
369 bool drm_crtc_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
372 struct drm_device *dev = crtc->dev;
373 struct drm_display_mode *adjusted_mode, saved_mode;
374 int saved_x, saved_y;
375 bool didLock = false;
377 struct drm_output *output;
379 adjusted_mode = drm_mode_duplicate(dev, mode);
381 crtc->enabled = drm_crtc_in_use(crtc);
383 if (!crtc->enabled) {
387 didLock = crtc->funcs->lock(crtc);
389 saved_mode = crtc->mode;
393 /* Update crtc values up front so the driver can rely on them for mode
400 /* XXX short-circuit changes to base location only */
402 /* Pass our mode to the outputs and the CRTC to give them a chance to
403 * adjust it according to limitations or output properties, and also
404 * a chance to reject the mode entirely.
406 list_for_each_entry(output, &dev->mode_config.output_list, head) {
408 if (output->crtc != crtc)
411 if (!output->funcs->mode_fixup(output, mode, adjusted_mode)) {
416 if (!crtc->funcs->mode_fixup(crtc, mode, adjusted_mode)) {
420 /* Prepare the outputs and CRTCs before setting the mode. */
421 list_for_each_entry(output, &dev->mode_config.output_list, head) {
423 if (output->crtc != crtc)
426 /* Disable the output as the first thing we do. */
427 output->funcs->prepare(output);
430 crtc->funcs->prepare(crtc);
432 /* Set up the DPLL and any output state that needs to adjust or depend
435 crtc->funcs->mode_set(crtc, mode, adjusted_mode, x, y);
437 list_for_each_entry(output, &dev->mode_config.output_list, head) {
439 if (output->crtc != crtc)
442 DRM_INFO("%s: set mode %s\n", output->name, mode->name);
444 output->funcs->mode_set(output, mode, adjusted_mode);
447 /* Now, enable the clocks, plane, pipe, and outputs that we set up. */
448 crtc->funcs->commit(crtc);
450 list_for_each_entry(output, &dev->mode_config.output_list, head) {
452 if (output->crtc != crtc)
455 output->funcs->commit(output);
457 #if 0 // TODO def RANDR_12_INTERFACE
458 if (output->randr_output)
459 RRPostPendingProperties (output->randr_output);
463 /* XXX free adjustedmode */
464 drm_mode_destroy(dev, adjusted_mode);
467 // if (scrn->pScreen)
468 // drm_crtc_set_screen_sub_pixel_order(dev);
474 crtc->mode = saved_mode;
478 crtc->funcs->unlock (crtc);
482 EXPORT_SYMBOL(drm_crtc_set_mode);
485 * drm_disable_unused_functions - disable unused objects
489 * Caller must hold mode config lock.
491 * If an output or CRTC isn't part of @dev's mode_config, it can be disabled
492 * by calling its dpms function, which should power it off.
494 void drm_disable_unused_functions(struct drm_device *dev)
496 struct drm_output *output;
497 struct drm_crtc *crtc;
499 list_for_each_entry(output, &dev->mode_config.output_list, head) {
501 (*output->funcs->dpms)(output, DPMSModeOff);
504 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
506 crtc->funcs->dpms(crtc, DPMSModeOff);
511 * drm_mode_probed_add - add a mode to the specified output's probed mode list
512 * @output: output the new mode
516 * Caller must hold mode config lock.
518 * Add @mode to @output's mode list for later use.
520 void drm_mode_probed_add(struct drm_output *output,
521 struct drm_display_mode *mode)
523 list_add(&mode->head, &output->probed_modes);
525 EXPORT_SYMBOL(drm_mode_probed_add);
528 * drm_mode_remove - remove and free a mode
529 * @output: output list to modify
530 * @mode: mode to remove
533 * Caller must hold mode config lock.
535 * Remove @mode from @output's mode list, then free it.
537 void drm_mode_remove(struct drm_output *output, struct drm_display_mode *mode)
539 list_del(&mode->head);
542 EXPORT_SYMBOL(drm_mode_remove);
545 * drm_output_create - create a new output
547 * @funcs: callbacks for this output
548 * @name: user visible name of the output
551 * Caller must hold @dev's mode_config lock.
553 * Creates a new drm_output structure and adds it to @dev's mode_config
557 * Pointer to the new output or NULL on error.
559 struct drm_output *drm_output_create(struct drm_device *dev,
560 const struct drm_output_funcs *funcs,
563 struct drm_output *output = NULL;
565 output = kzalloc(sizeof(struct drm_output), GFP_KERNEL);
570 output->funcs = funcs;
571 output->id = drm_idr_get(dev, output);
573 strncpy(output->name, name, DRM_OUTPUT_LEN);
574 output->name[DRM_OUTPUT_LEN - 1] = 0;
575 output->subpixel_order = SubPixelUnknown;
576 INIT_LIST_HEAD(&output->probed_modes);
577 INIT_LIST_HEAD(&output->modes);
579 /* output_set_monitor(output)? */
580 /* check for output_ignored(output)? */
582 mutex_lock(&dev->mode_config.mutex);
583 list_add_tail(&output->head, &dev->mode_config.output_list);
584 dev->mode_config.num_output++;
586 mutex_unlock(&dev->mode_config.mutex);
591 EXPORT_SYMBOL(drm_output_create);
594 * drm_output_destroy - remove an output
595 * @output: output to remove
598 * Caller must hold @dev's mode_config lock.
600 * Call @output's cleanup function, then remove the output from the DRM
601 * mode_config after freeing @output's modes.
603 void drm_output_destroy(struct drm_output *output)
605 struct drm_device *dev = output->dev;
606 struct drm_display_mode *mode, *t;
608 if (*output->funcs->cleanup)
609 (*output->funcs->cleanup)(output);
611 list_for_each_entry_safe(mode, t, &output->probed_modes, head)
612 drm_mode_remove(output, mode);
614 list_for_each_entry_safe(mode, t, &output->modes, head)
615 drm_mode_remove(output, mode);
617 mutex_lock(&dev->mode_config.mutex);
618 drm_idr_put(dev, output->id);
619 list_del(&output->head);
620 mutex_unlock(&dev->mode_config.mutex);
623 EXPORT_SYMBOL(drm_output_destroy);
626 * drm_output_rename - rename an output
627 * @output: output to rename
628 * @name: new user visible name
633 * Simply stuff a new name into @output's name field, based on @name.
636 * True if the name was changed, false otherwise.
638 bool drm_output_rename(struct drm_output *output, const char *name)
643 strncpy(output->name, name, DRM_OUTPUT_LEN);
644 output->name[DRM_OUTPUT_LEN - 1] = 0;
646 DRM_DEBUG("Changed name to %s\n", output->name);
647 // drm_output_set_monitor(output);
648 // if (drm_output_ignored(output))
653 EXPORT_SYMBOL(drm_output_rename);
656 * drm_mode_create - create a new display mode
662 * Create a new drm_display_mode, give it an ID, and return it.
665 * Pointer to new mode on success, NULL on error.
667 struct drm_display_mode *drm_mode_create(struct drm_device *dev)
669 struct drm_display_mode *nmode;
671 nmode = kzalloc(sizeof(struct drm_display_mode), GFP_KERNEL);
675 nmode->mode_id = drm_idr_get(dev, nmode);
678 EXPORT_SYMBOL(drm_mode_create);
681 * drm_mode_destroy - remove a mode
683 * @mode: mode to remove
686 * Caller must hold mode config lock.
688 * Free @mode's unique identifier, then free it.
690 void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode)
692 drm_idr_put(dev, mode->mode_id);
696 EXPORT_SYMBOL(drm_mode_destroy);
699 * drm_mode_config_init - initialize DRM mode_configuration structure
703 * None, should happen single threaded at init time.
705 * Initialize @dev's mode_config structure, used for tracking the graphics
706 * configuration of @dev.
708 void drm_mode_config_init(struct drm_device *dev)
710 mutex_init(&dev->mode_config.mutex);
711 INIT_LIST_HEAD(&dev->mode_config.fb_list);
712 INIT_LIST_HEAD(&dev->mode_config.crtc_list);
713 INIT_LIST_HEAD(&dev->mode_config.output_list);
714 INIT_LIST_HEAD(&dev->mode_config.usermode_list);
715 idr_init(&dev->mode_config.crtc_idr);
717 EXPORT_SYMBOL(drm_mode_config_init);
720 * drm_get_buffer_object - find the buffer object for a given handle
722 * @bo: pointer to caller's buffer_object pointer
723 * @handle: handle to lookup
726 * Must take @dev's struct_mutex to protect buffer object lookup.
728 * Given @handle, lookup the buffer object in @dev and put it in the caller's
732 * Zero on success, -EINVAL if the handle couldn't be found.
734 static int drm_get_buffer_object(struct drm_device *dev, struct drm_buffer_object **bo, unsigned long handle)
736 struct drm_user_object *uo;
737 struct drm_hash_item *hash;
742 mutex_lock(&dev->struct_mutex);
743 ret = drm_ht_find_item(&dev->object_hash, handle, &hash);
745 DRM_ERROR("Couldn't find handle.\n");
750 uo = drm_hash_entry(hash, struct drm_user_object, hash);
751 if (uo->type != drm_buffer_type) {
756 *bo = drm_user_object_entry(uo, struct drm_buffer_object, base);
759 mutex_unlock(&dev->struct_mutex);
764 * drm_pick_crtcs - pick crtcs for output devices
768 * Caller must hold mode config lock.
770 static void drm_pick_crtcs (struct drm_device *dev)
773 struct drm_output *output, *output_equal;
774 struct drm_crtc *crtc;
775 struct drm_display_mode *des_mode = NULL, *modes, *modes_equal;
777 list_for_each_entry(output, &dev->mode_config.output_list, head) {
780 /* Don't hook up outputs that are disconnected ??
782 * This is debateable. Do we want fixed /dev/fbX or
783 * dynamic on hotplug (need mode code for that though) ?
785 * If we don't hook up outputs now, then we only create
786 * /dev/fbX for the output that's enabled, that's good as
787 * the users console will be on that output.
789 * If we do hook up outputs that are disconnected now, then
790 * the user may end up having to muck about with the fbcon
791 * map flags to assign his console to the enabled output. Ugh.
793 if (output->status != output_status_connected)
797 list_for_each_entry(des_mode, &output->modes, head) {
798 if (des_mode->type & DRM_MODE_TYPE_PREFERRED)
802 /* No preferred mode, let's just select the first available */
803 if (!des_mode || !(des_mode->type & DRM_MODE_TYPE_PREFERRED)) {
804 list_for_each_entry(des_mode, &output->modes, head) {
811 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
815 if ((output->possible_crtcs & (1 << c)) == 0)
818 list_for_each_entry(output_equal, &dev->mode_config.output_list, head) {
819 if (output->id == output_equal->id)
822 /* Find out if crtc has been assigned before */
823 if (output_equal->crtc == crtc)
827 #if 1 /* continue for now */
833 list_for_each_entry(output_equal, &dev->mode_config.output_list, head) {
835 if (output->id == output_equal->id)
838 list_for_each_entry(modes, &output->modes, head) {
839 list_for_each_entry(modes_equal, &output_equal->modes, head) {
840 if (drm_mode_equal (modes, modes_equal)) {
841 if ((output->possible_clones & output_equal->possible_clones) && (output_equal->crtc == crtc)) {
842 printk("Cloning %s (0x%lx) to %s (0x%lx)\n",output->name,output->possible_clones,output_equal->name,output_equal->possible_clones);
852 /* crtc has been assigned skip it */
856 /* Found a CRTC to attach to, do it ! */
858 output->crtc->desired_mode = des_mode;
859 output->initial_x = 0;
860 output->initial_y = 0;
861 DRM_DEBUG("Desired mode for CRTC %d is %s\n",c,des_mode->name);
869 * drm_initial_config - setup a sane initial output configuration
871 * @can_grow: this configuration is growable
874 * Called at init time, must take mode config lock.
876 * Scan the CRTCs and outputs and try to put together an initial setup.
877 * At the moment, this is a cloned configuration across all heads with
878 * a new framebuffer object as the backing store.
881 * Zero if everything went ok, nonzero otherwise.
883 bool drm_initial_config(struct drm_device *dev, bool can_grow)
885 struct drm_output *output;
886 struct drm_crtc *crtc;
889 mutex_lock(&dev->mode_config.mutex);
891 drm_crtc_probe_output_modes(dev, 2048, 2048);
895 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
897 /* can't setup the crtc if there's no assigned mode */
898 if (!crtc->desired_mode)
901 /* Now setup the fbdev for attached crtcs */
902 dev->driver->fb_probe(dev, crtc);
905 /* This is a little screwy, as we've already walked the outputs
906 * above, but it's a little bit of magic too. There's the potential
907 * for things not to get setup above if an existing device gets
908 * re-assigned thus confusing the hardware. By walking the outputs
909 * this fixes up their crtc's.
911 list_for_each_entry(output, &dev->mode_config.output_list, head) {
913 /* can't setup the output if there's no assigned mode */
914 if (!output->crtc || !output->crtc->desired_mode)
917 /* and needs an attached fb */
918 if (output->crtc->fb)
919 drm_crtc_set_mode(output->crtc, output->crtc->desired_mode, 0, 0);
922 drm_disable_unused_functions(dev);
924 mutex_unlock(&dev->mode_config.mutex);
927 EXPORT_SYMBOL(drm_initial_config);
930 * drm_mode_config_cleanup - free up DRM mode_config info
934 * Caller must hold mode config lock.
936 * Free up all the outputs and CRTCs associated with this DRM device, then
937 * free up the framebuffers and associated buffer objects.
939 * FIXME: cleanup any dangling user buffer objects too
941 void drm_mode_config_cleanup(struct drm_device *dev)
943 struct drm_output *output, *ot;
944 struct drm_crtc *crtc, *ct;
945 struct drm_framebuffer *fb, *fbt;
946 struct drm_display_mode *mode, *mt;
947 list_for_each_entry_safe(output, ot, &dev->mode_config.output_list, head) {
948 drm_output_destroy(output);
951 list_for_each_entry_safe(mode, mt, &dev->mode_config.usermode_list, head) {
952 drm_mode_destroy(dev, mode);
955 list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) {
956 if (fb->bo->type != drm_bo_type_kernel)
957 drm_framebuffer_destroy(fb);
959 dev->driver->fb_remove(dev, drm_crtc_from_fb(dev, fb));
962 list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) {
963 drm_crtc_destroy(crtc);
967 EXPORT_SYMBOL(drm_mode_config_cleanup);
970 * drm_crtc_set_config - set a new config from userspace
971 * @crtc: CRTC to setup
972 * @crtc_info: user provided configuration
973 * @new_mode: new mode to set
974 * @output_set: set of outputs for the new config
975 * @fb: new framebuffer
978 * Caller must hold mode config lock.
980 * Setup a new configuration, provided by the user in @crtc_info, and enable
986 int drm_crtc_set_config(struct drm_crtc *crtc, struct drm_mode_crtc *crtc_info, struct drm_display_mode *new_mode, struct drm_output **output_set, struct drm_framebuffer *fb)
988 struct drm_device *dev = crtc->dev;
989 struct drm_crtc **save_crtcs, *new_crtc;
990 bool save_enabled = crtc->enabled;
992 struct drm_output *output;
995 save_crtcs = kzalloc(dev->mode_config.num_crtc * sizeof(struct drm_crtc *), GFP_KERNEL);
1002 if (crtc_info->x != crtc->x || crtc_info->y != crtc->y)
1005 if (new_mode && (crtc->mode.mode_id != new_mode->mode_id))
1008 list_for_each_entry(output, &dev->mode_config.output_list, head) {
1009 save_crtcs[count++] = output->crtc;
1011 if (output->crtc == crtc)
1014 new_crtc = output->crtc;
1016 for (ro = 0; ro < crtc_info->count_outputs; ro++) {
1017 if (output_set[ro] == output)
1020 if (new_crtc != output->crtc) {
1022 output->crtc = new_crtc;
1028 crtc->enabled = (new_mode != NULL);
1029 if (new_mode != NULL) {
1030 DRM_DEBUG("attempting to set mode from userspace\n");
1031 drm_mode_debug_printmodeline(dev, new_mode);
1032 if (!drm_crtc_set_mode(crtc, new_mode, crtc_info->x,
1034 crtc->enabled = save_enabled;
1036 list_for_each_entry(output, &dev->mode_config.output_list, head)
1037 output->crtc = save_crtcs[count++];
1041 crtc->desired_x = crtc_info->x;
1042 crtc->desired_y = crtc_info->y;
1043 crtc->desired_mode = new_mode;
1045 drm_disable_unused_functions(dev);
1052 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
1053 * @out: drm_mode_modeinfo struct to return to the user
1054 * @in: drm_display_mode to use
1059 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
1062 void drm_crtc_convert_to_umode(struct drm_mode_modeinfo *out, struct drm_display_mode *in)
1065 out->id = in->mode_id;
1066 out->clock = in->clock;
1067 out->hdisplay = in->hdisplay;
1068 out->hsync_start = in->hsync_start;
1069 out->hsync_end = in->hsync_end;
1070 out->htotal = in->htotal;
1071 out->hskew = in->hskew;
1072 out->vdisplay = in->vdisplay;
1073 out->vsync_start = in->vsync_start;
1074 out->vsync_end = in->vsync_end;
1075 out->vtotal = in->vtotal;
1076 out->vscan = in->vscan;
1077 out->vrefresh = in->vrefresh;
1078 out->flags = in->flags;
1079 out->type = in->type;
1080 strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
1081 out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
1085 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
1086 * @out: drm_display_mode to return to the user
1087 * @in: drm_mode_modeinfo to use
1092 * Convert a drmo_mode_modeinfo into a drm_display_mode structure to return to
1095 void drm_crtc_convert_umode(struct drm_display_mode *out, struct drm_mode_modeinfo *in)
1097 out->clock = in->clock;
1098 out->hdisplay = in->hdisplay;
1099 out->hsync_start = in->hsync_start;
1100 out->hsync_end = in->hsync_end;
1101 out->htotal = in->htotal;
1102 out->hskew = in->hskew;
1103 out->vdisplay = in->vdisplay;
1104 out->vsync_start = in->vsync_start;
1105 out->vsync_end = in->vsync_end;
1106 out->vtotal = in->vtotal;
1107 out->vscan = in->vscan;
1108 out->vrefresh = in->vrefresh;
1109 out->flags = in->flags;
1110 out->type = in->type;
1111 strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
1112 out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
1116 * drm_mode_getresources - get graphics configuration
1117 * @inode: inode from the ioctl
1118 * @filp: file * from the ioctl
1119 * @cmd: cmd from ioctl
1120 * @arg: arg from ioctl
1123 * Takes mode config lock.
1125 * Construct a set of configuration description structures and return
1126 * them to the user, including CRTC, output and framebuffer configuration.
1128 * Called by the user via ioctl.
1131 * Zero on success, errno on failure.
1133 int drm_mode_getresources(struct drm_device *dev,
1134 void *data, struct drm_file *file_priv)
1136 struct drm_mode_card_res *card_res = data;
1137 struct list_head *lh;
1138 struct drm_framebuffer *fb;
1139 struct drm_output *output;
1140 struct drm_crtc *crtc;
1141 struct drm_mode_modeinfo u_mode;
1142 struct drm_display_mode *mode;
1145 int output_count = 0;
1150 memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
1152 mutex_lock(&dev->mode_config.mutex);
1154 list_for_each(lh, &dev->mode_config.fb_list)
1157 list_for_each(lh, &dev->mode_config.crtc_list)
1160 list_for_each_entry(output, &dev->mode_config.output_list,
1163 list_for_each(lh, &output->modes)
1166 list_for_each(lh, &dev->mode_config.usermode_list)
1169 if (card_res->count_modes == 0) {
1170 DRM_DEBUG("probing modes %dx%d\n", dev->mode_config.max_width, dev->mode_config.max_height);
1171 drm_crtc_probe_output_modes(dev, dev->mode_config.max_width, dev->mode_config.max_height);
1173 list_for_each_entry(output, &dev->mode_config.output_list, head) {
1174 list_for_each(lh, &output->modes)
1177 list_for_each(lh, &dev->mode_config.usermode_list)
1181 /* handle this in 4 parts */
1183 if (card_res->count_fbs >= fb_count) {
1185 list_for_each_entry(fb, &dev->mode_config.fb_list, head) {
1186 if (put_user(fb->id, card_res->fb_id + copied))
1191 card_res->count_fbs = fb_count;
1194 if (card_res->count_crtcs >= crtc_count) {
1196 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head){
1197 DRM_DEBUG("CRTC ID is %d\n", crtc->id);
1198 if (put_user(crtc->id, card_res->crtc_id + copied))
1203 card_res->count_crtcs = crtc_count;
1207 if (card_res->count_outputs >= output_count) {
1209 list_for_each_entry(output, &dev->mode_config.output_list,
1211 DRM_DEBUG("OUTPUT ID is %d\n", output->id);
1212 if (put_user(output->id, card_res->output_id + copied))
1217 card_res->count_outputs = output_count;
1220 if (card_res->count_modes >= mode_count) {
1222 list_for_each_entry(output, &dev->mode_config.output_list,
1224 list_for_each_entry(mode, &output->modes, head) {
1225 drm_crtc_convert_to_umode(&u_mode, mode);
1226 if (copy_to_user(card_res->modes + copied,
1227 &u_mode, sizeof(u_mode)))
1232 /* add in user modes */
1233 list_for_each_entry(mode, &dev->mode_config.usermode_list, head) {
1234 drm_crtc_convert_to_umode(&u_mode, mode);
1235 if (copy_to_user(card_res->modes + copied, &u_mode,
1241 card_res->count_modes = mode_count;
1243 DRM_DEBUG("Counted %d %d %d\n", card_res->count_crtcs,
1244 card_res->count_outputs,
1245 card_res->count_modes);
1247 mutex_unlock(&dev->mode_config.mutex);
1252 * drm_mode_getcrtc - get CRTC configuration
1253 * @inode: inode from the ioctl
1254 * @filp: file * from the ioctl
1255 * @cmd: cmd from ioctl
1256 * @arg: arg from ioctl
1261 * Construct a CRTC configuration structure to return to the user.
1263 * Called by the user via ioctl.
1266 * Zero on success, errno on failure.
1268 int drm_mode_getcrtc(struct drm_device *dev,
1269 void *data, struct drm_file *file_priv)
1271 struct drm_mode_crtc *crtc_resp = data;
1272 struct drm_crtc *crtc;
1273 struct drm_output *output;
1277 mutex_lock(&dev->mode_config.mutex);
1278 crtc = idr_find(&dev->mode_config.crtc_idr, crtc_resp->crtc_id);
1279 if (!crtc || (crtc->id != crtc_resp->crtc_id)) {
1284 crtc_resp->x = crtc->x;
1285 crtc_resp->y = crtc->y;
1288 crtc_resp->fb_id = crtc->fb->id;
1290 crtc_resp->fb_id = 0;
1292 crtc_resp->outputs = 0;
1293 if (crtc->enabled) {
1295 crtc_resp->mode = crtc->mode.mode_id;
1297 list_for_each_entry(output, &dev->mode_config.output_list, head) {
1298 if (output->crtc == crtc)
1299 crtc_resp->outputs |= 1 << (ocount++);
1302 crtc_resp->mode = 0;
1306 mutex_unlock(&dev->mode_config.mutex);
1311 * drm_mode_getoutput - get output configuration
1312 * @inode: inode from the ioctl
1313 * @filp: file * from the ioctl
1314 * @cmd: cmd from ioctl
1315 * @arg: arg from ioctl
1320 * Construct a output configuration structure to return to the user.
1322 * Called by the user via ioctl.
1325 * Zero on success, errno on failure.
1327 int drm_mode_getoutput(struct drm_device *dev,
1328 void *data, struct drm_file *file_priv)
1330 struct drm_mode_get_output *out_resp = data;
1331 struct drm_output *output;
1332 struct drm_display_mode *mode;
1338 DRM_DEBUG("output id %d:\n", out_resp->output);
1340 mutex_lock(&dev->mode_config.mutex);
1341 output= idr_find(&dev->mode_config.crtc_idr, out_resp->output);
1342 if (!output || (output->id != out_resp->output)) {
1347 list_for_each_entry(mode, &output->modes, head)
1350 for (i = 0; i < DRM_OUTPUT_MAX_UMODES; i++)
1351 if (output->user_mode_ids[i] != 0)
1354 strncpy(out_resp->name, output->name, DRM_OUTPUT_NAME_LEN);
1355 out_resp->name[DRM_OUTPUT_NAME_LEN-1] = 0;
1357 out_resp->mm_width = output->mm_width;
1358 out_resp->mm_height = output->mm_height;
1359 out_resp->subpixel = output->subpixel_order;
1360 out_resp->connection = output->status;
1362 out_resp->crtc = output->crtc->id;
1366 out_resp->crtcs = output->possible_crtcs;
1367 out_resp->clones = output->possible_clones;
1368 if ((out_resp->count_modes >= mode_count) && mode_count) {
1370 list_for_each_entry(mode, &output->modes, head) {
1371 out_resp->modes[copied++] = mode->mode_id;
1373 for (i = 0; i < DRM_OUTPUT_MAX_UMODES; i++) {
1374 if (output->user_mode_ids[i] != 0)
1375 out_resp->modes[copied++] = output->user_mode_ids[i];
1379 out_resp->count_modes = mode_count;
1382 mutex_unlock(&dev->mode_config.mutex);
1387 * drm_mode_setcrtc - set CRTC configuration
1388 * @inode: inode from the ioctl
1389 * @filp: file * from the ioctl
1390 * @cmd: cmd from ioctl
1391 * @arg: arg from ioctl
1396 * Build a new CRTC configuration based on user request.
1398 * Called by the user via ioctl.
1401 * Zero on success, errno on failure.
1403 int drm_mode_setcrtc(struct drm_device *dev,
1404 void *data, struct drm_file *file_priv)
1406 struct drm_mode_crtc *crtc_req = data;
1407 struct drm_crtc *crtc;
1408 struct drm_output **output_set = NULL, *output;
1409 struct drm_display_mode *mode;
1410 struct drm_framebuffer *fb = NULL;
1414 mutex_lock(&dev->mode_config.mutex);
1415 crtc = idr_find(&dev->mode_config.crtc_idr, crtc_req->crtc_id);
1416 if (!crtc || (crtc->id != crtc_req->crtc_id)) {
1417 DRM_DEBUG("Unknown CRTC ID %d\n", crtc_req->crtc_id);
1422 if (crtc_req->mode) {
1423 /* if we have a mode we need a framebuffer */
1424 if (crtc_req->fb_id) {
1425 fb = idr_find(&dev->mode_config.crtc_idr, crtc_req->fb_id);
1426 if (!fb || (fb->id != crtc_req->fb_id)) {
1427 DRM_DEBUG("Unknown FB ID%d\n", crtc_req->fb_id);
1432 mode = idr_find(&dev->mode_config.crtc_idr, crtc_req->mode);
1433 if (!mode || (mode->mode_id != crtc_req->mode)) {
1434 struct drm_output *output;
1436 list_for_each_entry(output,
1437 &dev->mode_config.output_list,
1439 list_for_each_entry(mode, &output->modes,
1441 drm_mode_debug_printmodeline(dev,
1446 DRM_DEBUG("Unknown mode id %d, %p\n", crtc_req->mode, mode);
1453 if (crtc_req->count_outputs == 0 && mode) {
1454 DRM_DEBUG("Count outputs is 0 but mode set\n");
1459 if (crtc_req->count_outputs > 0 && !mode && !fb) {
1460 DRM_DEBUG("Count outputs is %d but no mode or fb set\n", crtc_req->count_outputs);
1465 if (crtc_req->count_outputs > 0) {
1467 output_set = kmalloc(crtc_req->count_outputs *
1468 sizeof(struct drm_output *), GFP_KERNEL);
1474 for (i = 0; i < crtc_req->count_outputs; i++) {
1475 if (get_user(out_id, &crtc_req->set_outputs[i])) {
1480 output = idr_find(&dev->mode_config.crtc_idr, out_id);
1481 if (!output || (out_id != output->id)) {
1482 DRM_DEBUG("Output id %d unknown\n", out_id);
1487 output_set[i] = output;
1491 ret = drm_crtc_set_config(crtc, crtc_req, mode, output_set, fb);
1494 mutex_unlock(&dev->mode_config.mutex);
1499 * drm_mode_addfb - add an FB to the graphics configuration
1500 * @inode: inode from the ioctl
1501 * @filp: file * from the ioctl
1502 * @cmd: cmd from ioctl
1503 * @arg: arg from ioctl
1506 * Takes mode config lock.
1508 * Add a new FB to the specified CRTC, given a user request.
1510 * Called by the user via ioctl.
1513 * Zero on success, errno on failure.
1515 int drm_mode_addfb(struct drm_device *dev,
1516 void *data, struct drm_file *file_priv)
1518 struct drm_mode_fb_cmd *r = data;
1519 struct drm_mode_config *config = &dev->mode_config;
1520 struct drm_framebuffer *fb;
1521 struct drm_buffer_object *bo;
1522 struct drm_crtc *crtc;
1525 if ((config->min_width > r->width) || (r->width > config->max_width)) {
1526 DRM_ERROR("mode new framebuffer width not within limits\n");
1529 if ((config->min_height > r->height) || (r->height > config->max_height)) {
1530 DRM_ERROR("mode new framebuffer height not within limits\n");
1534 mutex_lock(&dev->mode_config.mutex);
1535 /* TODO check limits are okay */
1536 ret = drm_get_buffer_object(dev, &bo, r->handle);
1542 /* TODO check buffer is sufficently large */
1543 /* TODO setup destructor callback */
1545 fb = drm_framebuffer_create(dev);
1551 fb->width = r->width;
1552 fb->height = r->height;
1553 fb->pitch = r->pitch;
1554 fb->bits_per_pixel = r->bpp;
1555 fb->depth = r->depth;
1556 fb->offset = bo->offset;
1559 r->buffer_id = fb->id;
1561 list_add(&fb->filp_head, &file_priv->fbs);
1563 /* FIXME: bind the fb to the right crtc */
1564 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
1566 dev->driver->fb_probe(dev, crtc);
1570 mutex_unlock(&dev->mode_config.mutex);
1575 * drm_mode_rmfb - remove an FB from the configuration
1576 * @inode: inode from the ioctl
1577 * @filp: file * from the ioctl
1578 * @cmd: cmd from ioctl
1579 * @arg: arg from ioctl
1582 * Takes mode config lock.
1584 * Remove the FB specified by the user.
1586 * Called by the user via ioctl.
1589 * Zero on success, errno on failure.
1591 int drm_mode_rmfb(struct drm_device *dev,
1592 void *data, struct drm_file *file_priv)
1594 struct drm_framebuffer *fb = 0;
1595 uint32_t *id = data;
1598 mutex_lock(&dev->mode_config.mutex);
1599 fb = idr_find(&dev->mode_config.crtc_idr, *id);
1600 /* TODO check that we realy get a framebuffer back. */
1601 if (!fb || (*id != fb->id)) {
1602 DRM_ERROR("mode invalid framebuffer id\n");
1607 /* TODO check if we own the buffer */
1608 /* TODO release all crtc connected to the framebuffer */
1609 /* bind the fb to the crtc for now */
1610 /* TODO unhock the destructor from the buffer object */
1612 if (fb->bo->type != drm_bo_type_kernel)
1613 drm_framebuffer_destroy(fb);
1615 dev->driver->fb_remove(dev, drm_crtc_from_fb(dev, fb));
1618 mutex_unlock(&dev->mode_config.mutex);
1623 * drm_mode_getfb - get FB info
1624 * @inode: inode from the ioctl
1625 * @filp: file * from the ioctl
1626 * @cmd: cmd from ioctl
1627 * @arg: arg from ioctl
1632 * Lookup the FB given its ID and return info about it.
1634 * Called by the user via ioctl.
1637 * Zero on success, errno on failure.
1639 int drm_mode_getfb(struct drm_device *dev,
1640 void *data, struct drm_file *file_priv)
1642 struct drm_mode_fb_cmd *r = data;
1643 struct drm_framebuffer *fb;
1646 mutex_lock(&dev->mode_config.mutex);
1647 fb = idr_find(&dev->mode_config.crtc_idr, r->buffer_id);
1648 if (!fb || (r->buffer_id != fb->id)) {
1649 DRM_ERROR("invalid framebuffer id\n");
1654 r->height = fb->height;
1655 r->width = fb->width;
1656 r->depth = fb->depth;
1657 r->bpp = fb->bits_per_pixel;
1658 r->handle = fb->bo->base.hash.key;
1659 r->pitch = fb->pitch;
1662 mutex_unlock(&dev->mode_config.mutex);
1667 * drm_fb_release - remove and free the FBs on this file
1668 * @filp: file * from the ioctl
1671 * Takes mode config lock.
1673 * Destroy all the FBs associated with @filp.
1675 * Called by the user via ioctl.
1678 * Zero on success, errno on failure.
1680 void drm_fb_release(struct file *filp)
1682 struct drm_file *priv = filp->private_data;
1683 struct drm_device *dev = priv->head->dev;
1684 struct drm_framebuffer *fb, *tfb;
1686 mutex_lock(&dev->mode_config.mutex);
1687 list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) {
1688 list_del(&fb->filp_head);
1689 if (fb->bo->type != drm_bo_type_kernel)
1690 drm_framebuffer_destroy(fb);
1692 dev->driver->fb_remove(dev, drm_crtc_from_fb(dev, fb));
1694 mutex_unlock(&dev->mode_config.mutex);
1698 * drm_fb_newmode - adds a user defined mode
1699 * @inode: inode from the ioctl
1700 * @filp: file * from the ioctl
1701 * @cmd: cmd from ioctl
1702 * @arg: arg from ioctl
1704 * Adds a user specified mode to the kernel.
1706 * Called by the user via ioctl.
1709 * writes new mode id into arg.
1710 * Zero on success, errno on failure.
1712 int drm_mode_addmode(struct drm_device *dev,
1713 void *data, struct drm_file *file_priv)
1715 struct drm_mode_modeinfo *new_mode = data;
1716 struct drm_display_mode *user_mode;
1719 mutex_lock(&dev->mode_config.mutex);
1720 user_mode = drm_mode_create(dev);
1726 drm_crtc_convert_umode(user_mode, new_mode);
1727 user_mode->type |= DRM_MODE_TYPE_USERDEF;
1729 user_mode->output_count = 0;
1731 list_add(&user_mode->head, &dev->mode_config.usermode_list);
1733 new_mode->id = user_mode->mode_id;
1736 mutex_unlock(&dev->mode_config.mutex);
1741 * drm_fb_rmmode - removes a user defined mode
1742 * @inode: inode from the ioctl
1743 * @filp: file * from the ioctl
1744 * @cmd: cmd from ioctl
1745 * @arg: arg from ioctl
1747 * Remove the user defined mode specified by the user.
1749 * Called by the user via ioctl
1752 * Zero on success, errno on failure.
1754 int drm_mode_rmmode(struct drm_device *dev,
1755 void *data, struct drm_file *file_priv)
1757 uint32_t *id = data;
1758 struct drm_display_mode *mode, *t;
1761 mutex_lock(&dev->mode_config.mutex);
1762 mode = idr_find(&dev->mode_config.crtc_idr, *id);
1763 if (!mode || (*id != mode->mode_id)) {
1768 if (!(mode->type & DRM_MODE_TYPE_USERDEF)) {
1773 if (mode->output_count) {
1778 list_for_each_entry(t, &dev->mode_config.usermode_list, head) {
1780 list_del(&mode->head);
1781 drm_mode_destroy(dev, mode);
1788 mutex_unlock(&dev->mode_config.mutex);
1793 * drm_fb_attachmode - Attach a user mode to an output
1794 * @inode: inode from the ioctl
1795 * @filp: file * from the ioctl
1796 * @cmd: cmd from ioctl
1797 * @arg: arg from ioctl
1799 * This attaches a user specified mode to an output.
1800 * Called by the user via ioctl.
1803 * Zero on success, errno on failure.
1805 int drm_mode_attachmode(struct drm_device *dev,
1806 void *data, struct drm_file *file_priv)
1808 struct drm_mode_mode_cmd *mode_cmd = data;
1809 struct drm_output *output;
1810 struct drm_display_mode *mode;
1813 mutex_lock(&dev->mode_config.mutex);
1815 mode = idr_find(&dev->mode_config.crtc_idr, mode_cmd->mode_id);
1816 if (!mode || (mode->mode_id != mode_cmd->mode_id)) {
1821 output = idr_find(&dev->mode_config.crtc_idr, mode_cmd->output_id);
1822 if (!output || (output->id != mode_cmd->output_id)) {
1827 for (i = 0; i < DRM_OUTPUT_MAX_UMODES; i++) {
1828 if (output->user_mode_ids[i] == 0) {
1829 output->user_mode_ids[i] = mode->mode_id;
1830 mode->output_count++;
1835 if (i == DRM_OUTPUT_MAX_UMODES)
1839 mutex_unlock(&dev->mode_config.mutex);
1845 * drm_fb_detachmode - Detach a user specified mode from an output
1846 * @inode: inode from the ioctl
1847 * @filp: file * from the ioctl
1848 * @cmd: cmd from ioctl
1849 * @arg: arg from ioctl
1851 * Called by the user via ioctl.
1854 * Zero on success, errno on failure.
1856 int drm_mode_detachmode(struct drm_device *dev,
1857 void *data, struct drm_file *file_priv)
1859 struct drm_mode_mode_cmd *mode_cmd = data;
1860 struct drm_output *output;
1861 struct drm_display_mode *mode;
1862 int i, found = 0, ret = 0;
1864 mutex_lock(&dev->mode_config.mutex);
1866 mode = idr_find(&dev->mode_config.crtc_idr, mode_cmd->mode_id);
1867 if (!mode || (mode->mode_id != mode_cmd->mode_id)) {
1872 output = idr_find(&dev->mode_config.crtc_idr, mode_cmd->output_id);
1873 if (!output || (output->id != mode_cmd->output_id)) {
1879 for (i = 0; i < DRM_OUTPUT_MAX_UMODES; i++) {
1880 if (output->user_mode_ids[i] == mode->mode_id) {
1881 output->user_mode_ids[i] = 0;
1882 mode->output_count--;
1891 mutex_unlock(&dev->mode_config.mutex);