drm_crtc.c (de65d816aa44f9ddd79861ae21d75010cc1fd003) | drm_crtc.c (6aed8ec3f76a22217c9ae183d32b1aa990bed069) |
---|---|
1/* 2 * Copyright (c) 2006-2008 Intel Corporation 3 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie> 4 * Copyright (c) 2008 Red Hat Inc. 5 * 6 * DRM core CRTC related functions 7 * 8 * Permission to use, copy, modify, distribute, and sell this software and its --- 23 unchanged lines hidden (view full) --- 32#include <linux/list.h> 33#include <linux/slab.h> 34#include <linux/export.h> 35#include <drm/drmP.h> 36#include <drm/drm_crtc.h> 37#include <drm/drm_edid.h> 38#include <drm/drm_fourcc.h> 39 | 1/* 2 * Copyright (c) 2006-2008 Intel Corporation 3 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie> 4 * Copyright (c) 2008 Red Hat Inc. 5 * 6 * DRM core CRTC related functions 7 * 8 * Permission to use, copy, modify, distribute, and sell this software and its --- 23 unchanged lines hidden (view full) --- 32#include <linux/list.h> 33#include <linux/slab.h> 34#include <linux/export.h> 35#include <drm/drmP.h> 36#include <drm/drm_crtc.h> 37#include <drm/drm_edid.h> 38#include <drm/drm_fourcc.h> 39 |
40/** 41 * drm_modeset_lock_all - take all modeset locks 42 * @dev: drm device 43 * 44 * This function takes all modeset locks, suitable where a more fine-grained 45 * scheme isn't (yet) implemented. 46 */ 47void drm_modeset_lock_all(struct drm_device *dev) 48{ 49 struct drm_crtc *crtc; 50 51 mutex_lock(&dev->mode_config.mutex); 52 53 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) 54 mutex_lock_nest_lock(&crtc->mutex, &dev->mode_config.mutex); 55} 56EXPORT_SYMBOL(drm_modeset_lock_all); 57 58/** 59 * drm_modeset_unlock_all - drop all modeset locks 60 * @dev: device 61 */ 62void drm_modeset_unlock_all(struct drm_device *dev) 63{ 64 struct drm_crtc *crtc; 65 66 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) 67 mutex_unlock(&crtc->mutex); 68 69 mutex_unlock(&dev->mode_config.mutex); 70} 71EXPORT_SYMBOL(drm_modeset_unlock_all); 72 73/** 74 * drm_warn_on_modeset_not_all_locked - check that all modeset locks are locked 75 * @dev: device 76 */ 77void drm_warn_on_modeset_not_all_locked(struct drm_device *dev) 78{ 79 struct drm_crtc *crtc; 80 81 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) 82 WARN_ON(!mutex_is_locked(&crtc->mutex)); 83 84 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex)); 85} 86EXPORT_SYMBOL(drm_warn_on_modeset_not_all_locked); 87 |
|
40/* Avoid boilerplate. I'm tired of typing. */ 41#define DRM_ENUM_NAME_FN(fnname, list) \ 42 char *fnname(int val) \ 43 { \ 44 int i; \ 45 for (i = 0; i < ARRAY_SIZE(list); i++) { \ 46 if (list[i].type == val) \ 47 return list[i].name; \ --- 150 unchanged lines hidden (view full) --- 198 return "connected"; 199 else if (status == connector_status_disconnected) 200 return "disconnected"; 201 else 202 return "unknown"; 203} 204 205/** | 88/* Avoid boilerplate. I'm tired of typing. */ 89#define DRM_ENUM_NAME_FN(fnname, list) \ 90 char *fnname(int val) \ 91 { \ 92 int i; \ 93 for (i = 0; i < ARRAY_SIZE(list); i++) { \ 94 if (list[i].type == val) \ 95 return list[i].name; \ --- 150 unchanged lines hidden (view full) --- 246 return "connected"; 247 else if (status == connector_status_disconnected) 248 return "disconnected"; 249 else 250 return "unknown"; 251} 252 253/** |
206 * drm_mode_object_get - allocate a new identifier | 254 * drm_mode_object_get - allocate a new modeset identifier |
207 * @dev: DRM device | 255 * @dev: DRM device |
208 * @ptr: object pointer, used to generate unique ID 209 * @type: object type | 256 * @obj: object pointer, used to generate unique ID 257 * @obj_type: object type |
210 * | 258 * |
211 * LOCKING: 212 * | |
213 * Create a unique identifier based on @ptr in @dev's identifier space. Used 214 * for tracking modes, CRTCs and connectors. 215 * 216 * RETURNS: 217 * New unique (relative to other objects in @dev) integer identifier for the 218 * object. 219 */ 220static int drm_mode_object_get(struct drm_device *dev, --- 5 unchanged lines hidden (view full) --- 226again: 227 if (idr_pre_get(&dev->mode_config.crtc_idr, GFP_KERNEL) == 0) { 228 DRM_ERROR("Ran out memory getting a mode number\n"); 229 return -ENOMEM; 230 } 231 232 mutex_lock(&dev->mode_config.idr_mutex); 233 ret = idr_get_new_above(&dev->mode_config.crtc_idr, obj, 1, &new_id); | 259 * Create a unique identifier based on @ptr in @dev's identifier space. Used 260 * for tracking modes, CRTCs and connectors. 261 * 262 * RETURNS: 263 * New unique (relative to other objects in @dev) integer identifier for the 264 * object. 265 */ 266static int drm_mode_object_get(struct drm_device *dev, --- 5 unchanged lines hidden (view full) --- 272again: 273 if (idr_pre_get(&dev->mode_config.crtc_idr, GFP_KERNEL) == 0) { 274 DRM_ERROR("Ran out memory getting a mode number\n"); 275 return -ENOMEM; 276 } 277 278 mutex_lock(&dev->mode_config.idr_mutex); 279 ret = idr_get_new_above(&dev->mode_config.crtc_idr, obj, 1, &new_id); |
280 281 if (!ret) { 282 /* 283 * Set up the object linking under the protection of the idr 284 * lock so that other users can't see inconsistent state. 285 */ 286 obj->id = new_id; 287 obj->type = obj_type; 288 } |
|
234 mutex_unlock(&dev->mode_config.idr_mutex); | 289 mutex_unlock(&dev->mode_config.idr_mutex); |
290 |
|
235 if (ret == -EAGAIN) 236 goto again; | 291 if (ret == -EAGAIN) 292 goto again; |
237 else if (ret) 238 return ret; | |
239 | 293 |
240 obj->id = new_id; 241 obj->type = obj_type; 242 return 0; | 294 return ret; |
243} 244 245/** | 295} 296 297/** |
246 * drm_mode_object_put - free an identifer | 298 * drm_mode_object_put - free a modeset identifer |
247 * @dev: DRM device | 299 * @dev: DRM device |
248 * @id: ID to free | 300 * @object: object to free |
249 * | 301 * |
250 * LOCKING: 251 * Caller must hold DRM mode_config lock. 252 * | |
253 * Free @id from @dev's unique identifier pool. 254 */ 255static void drm_mode_object_put(struct drm_device *dev, 256 struct drm_mode_object *object) 257{ 258 mutex_lock(&dev->mode_config.idr_mutex); 259 idr_remove(&dev->mode_config.crtc_idr, object->id); 260 mutex_unlock(&dev->mode_config.idr_mutex); 261} 262 | 302 * Free @id from @dev's unique identifier pool. 303 */ 304static void drm_mode_object_put(struct drm_device *dev, 305 struct drm_mode_object *object) 306{ 307 mutex_lock(&dev->mode_config.idr_mutex); 308 idr_remove(&dev->mode_config.crtc_idr, object->id); 309 mutex_unlock(&dev->mode_config.idr_mutex); 310} 311 |
312/** 313 * drm_mode_object_find - look up a drm object with static lifetime 314 * @dev: drm device 315 * @id: id of the mode object 316 * @type: type of the mode object 317 * 318 * Note that framebuffers cannot be looked up with this functions - since those 319 * are reference counted, they need special treatment. 320 */ |
|
263struct drm_mode_object *drm_mode_object_find(struct drm_device *dev, 264 uint32_t id, uint32_t type) 265{ 266 struct drm_mode_object *obj = NULL; 267 | 321struct drm_mode_object *drm_mode_object_find(struct drm_device *dev, 322 uint32_t id, uint32_t type) 323{ 324 struct drm_mode_object *obj = NULL; 325 |
326 /* Framebuffers are reference counted and need their own lookup 327 * function.*/ 328 WARN_ON(type == DRM_MODE_OBJECT_FB); 329 |
|
268 mutex_lock(&dev->mode_config.idr_mutex); 269 obj = idr_find(&dev->mode_config.crtc_idr, id); 270 if (!obj || (obj->type != type) || (obj->id != id)) 271 obj = NULL; 272 mutex_unlock(&dev->mode_config.idr_mutex); 273 274 return obj; 275} 276EXPORT_SYMBOL(drm_mode_object_find); 277 278/** 279 * drm_framebuffer_init - initialize a framebuffer 280 * @dev: DRM device | 330 mutex_lock(&dev->mode_config.idr_mutex); 331 obj = idr_find(&dev->mode_config.crtc_idr, id); 332 if (!obj || (obj->type != type) || (obj->id != id)) 333 obj = NULL; 334 mutex_unlock(&dev->mode_config.idr_mutex); 335 336 return obj; 337} 338EXPORT_SYMBOL(drm_mode_object_find); 339 340/** 341 * drm_framebuffer_init - initialize a framebuffer 342 * @dev: DRM device |
343 * @fb: framebuffer to be initialized 344 * @funcs: ... with these functions |
|
281 * | 345 * |
282 * LOCKING: 283 * Caller must hold mode config lock. 284 * | |
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. 287 * | 346 * Allocates an ID for the framebuffer's parent mode object, sets its mode 347 * functions & device file and adds it to the master fd list. 348 * |
349 * IMPORTANT: 350 * This functions publishes the fb and makes it available for concurrent access 351 * by other users. Which means by this point the fb _must_ be fully set up - 352 * since all the fb attributes are invariant over its lifetime, no further 353 * locking but only correct reference counting is required. 354 * |
|
288 * RETURNS: 289 * Zero on success, error code on failure. 290 */ 291int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb, 292 const struct drm_framebuffer_funcs *funcs) 293{ 294 int ret; 295 | 355 * RETURNS: 356 * Zero on success, error code on failure. 357 */ 358int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb, 359 const struct drm_framebuffer_funcs *funcs) 360{ 361 int ret; 362 |
363 mutex_lock(&dev->mode_config.fb_lock); |
|
296 kref_init(&fb->refcount); | 364 kref_init(&fb->refcount); |
365 INIT_LIST_HEAD(&fb->filp_head); 366 fb->dev = dev; 367 fb->funcs = funcs; |
|
297 298 ret = drm_mode_object_get(dev, &fb->base, DRM_MODE_OBJECT_FB); 299 if (ret) | 368 369 ret = drm_mode_object_get(dev, &fb->base, DRM_MODE_OBJECT_FB); 370 if (ret) |
300 return ret; | 371 goto out; |
301 | 372 |
302 fb->dev = dev; 303 fb->funcs = funcs; | 373 /* Grab the idr reference. */ 374 drm_framebuffer_reference(fb); 375 |
304 dev->mode_config.num_fb++; 305 list_add(&fb->head, &dev->mode_config.fb_list); | 376 dev->mode_config.num_fb++; 377 list_add(&fb->head, &dev->mode_config.fb_list); |
378out: 379 mutex_unlock(&dev->mode_config.fb_lock); |
|
306 307 return 0; 308} 309EXPORT_SYMBOL(drm_framebuffer_init); 310 311static void drm_framebuffer_free(struct kref *kref) 312{ 313 struct drm_framebuffer *fb = 314 container_of(kref, struct drm_framebuffer, refcount); 315 fb->funcs->destroy(fb); 316} 317 | 380 381 return 0; 382} 383EXPORT_SYMBOL(drm_framebuffer_init); 384 385static void drm_framebuffer_free(struct kref *kref) 386{ 387 struct drm_framebuffer *fb = 388 container_of(kref, struct drm_framebuffer, refcount); 389 fb->funcs->destroy(fb); 390} 391 |
392static struct drm_framebuffer *__drm_framebuffer_lookup(struct drm_device *dev, 393 uint32_t id) 394{ 395 struct drm_mode_object *obj = NULL; 396 struct drm_framebuffer *fb; 397 398 mutex_lock(&dev->mode_config.idr_mutex); 399 obj = idr_find(&dev->mode_config.crtc_idr, id); 400 if (!obj || (obj->type != DRM_MODE_OBJECT_FB) || (obj->id != id)) 401 fb = NULL; 402 else 403 fb = obj_to_fb(obj); 404 mutex_unlock(&dev->mode_config.idr_mutex); 405 406 return fb; 407} 408 |
|
318/** | 409/** |
410 * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference 411 * @dev: drm device 412 * @id: id of the fb object 413 * 414 * If successful, this grabs an additional reference to the framebuffer - 415 * callers need to make sure to eventually unreference the returned framebuffer 416 * again. 417 */ 418struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev, 419 uint32_t id) 420{ 421 struct drm_framebuffer *fb; 422 423 mutex_lock(&dev->mode_config.fb_lock); 424 fb = __drm_framebuffer_lookup(dev, id); 425 if (fb) 426 kref_get(&fb->refcount); 427 mutex_unlock(&dev->mode_config.fb_lock); 428 429 return fb; 430} 431EXPORT_SYMBOL(drm_framebuffer_lookup); 432 433/** |
|
319 * drm_framebuffer_unreference - unref a framebuffer | 434 * drm_framebuffer_unreference - unref a framebuffer |
435 * @fb: framebuffer to unref |
|
320 * | 436 * |
321 * LOCKING: 322 * Caller must hold mode config lock. | 437 * This functions decrements the fb's refcount and frees it if it drops to zero. |
323 */ 324void drm_framebuffer_unreference(struct drm_framebuffer *fb) 325{ | 438 */ 439void drm_framebuffer_unreference(struct drm_framebuffer *fb) 440{ |
326 struct drm_device *dev = fb->dev; | |
327 DRM_DEBUG("FB ID: %d\n", fb->base.id); | 441 DRM_DEBUG("FB ID: %d\n", fb->base.id); |
328 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex)); | |
329 kref_put(&fb->refcount, drm_framebuffer_free); 330} 331EXPORT_SYMBOL(drm_framebuffer_unreference); 332 333/** 334 * drm_framebuffer_reference - incr the fb refcnt | 442 kref_put(&fb->refcount, drm_framebuffer_free); 443} 444EXPORT_SYMBOL(drm_framebuffer_unreference); 445 446/** 447 * drm_framebuffer_reference - incr the fb refcnt |
448 * @fb: framebuffer |
|
335 */ 336void drm_framebuffer_reference(struct drm_framebuffer *fb) 337{ 338 DRM_DEBUG("FB ID: %d\n", fb->base.id); 339 kref_get(&fb->refcount); 340} 341EXPORT_SYMBOL(drm_framebuffer_reference); 342 | 449 */ 450void drm_framebuffer_reference(struct drm_framebuffer *fb) 451{ 452 DRM_DEBUG("FB ID: %d\n", fb->base.id); 453 kref_get(&fb->refcount); 454} 455EXPORT_SYMBOL(drm_framebuffer_reference); 456 |
457static void drm_framebuffer_free_bug(struct kref *kref) 458{ 459 BUG(); 460} 461 462static void __drm_framebuffer_unreference(struct drm_framebuffer *fb) 463{ 464 DRM_DEBUG("FB ID: %d\n", fb->base.id); 465 kref_put(&fb->refcount, drm_framebuffer_free_bug); 466} 467 468/* dev->mode_config.fb_lock must be held! */ 469static void __drm_framebuffer_unregister(struct drm_device *dev, 470 struct drm_framebuffer *fb) 471{ 472 mutex_lock(&dev->mode_config.idr_mutex); 473 idr_remove(&dev->mode_config.crtc_idr, fb->base.id); 474 mutex_unlock(&dev->mode_config.idr_mutex); 475 476 fb->base.id = 0; 477 478 __drm_framebuffer_unreference(fb); 479} 480 |
|
343/** | 481/** |
482 * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr 483 * @fb: fb to unregister 484 * 485 * Drivers need to call this when cleaning up driver-private framebuffers, e.g. 486 * those used for fbdev. Note that the caller must hold a reference of it's own, 487 * i.e. the object may not be destroyed through this call (since it'll lead to a 488 * locking inversion). 489 */ 490void drm_framebuffer_unregister_private(struct drm_framebuffer *fb) 491{ 492 struct drm_device *dev = fb->dev; 493 494 mutex_lock(&dev->mode_config.fb_lock); 495 /* Mark fb as reaped and drop idr ref. */ 496 __drm_framebuffer_unregister(dev, fb); 497 mutex_unlock(&dev->mode_config.fb_lock); 498} 499EXPORT_SYMBOL(drm_framebuffer_unregister_private); 500 501/** |
|
344 * drm_framebuffer_cleanup - remove a framebuffer object 345 * @fb: framebuffer to remove 346 * | 502 * drm_framebuffer_cleanup - remove a framebuffer object 503 * @fb: framebuffer to remove 504 * |
347 * LOCKING: 348 * Caller must hold mode config lock. | 505 * Cleanup references to a user-created framebuffer. This function is intended 506 * to be used from the drivers ->destroy callback. |
349 * | 507 * |
350 * Scans all the CRTCs in @dev's mode_config. If they're using @fb, removes 351 * it, setting it to NULL. | 508 * Note that this function does not remove the fb from active usuage - if it is 509 * still used anywhere, hilarity can ensue since userspace could call getfb on 510 * the id and get back -EINVAL. Obviously no concern at driver unload time. 511 * 512 * Also, the framebuffer will not be removed from the lookup idr - for 513 * user-created framebuffers this will happen in in the rmfb ioctl. For 514 * driver-private objects (e.g. for fbdev) drivers need to explicitly call 515 * drm_framebuffer_unregister_private. |
352 */ 353void drm_framebuffer_cleanup(struct drm_framebuffer *fb) 354{ 355 struct drm_device *dev = fb->dev; | 516 */ 517void drm_framebuffer_cleanup(struct drm_framebuffer *fb) 518{ 519 struct drm_device *dev = fb->dev; |
356 /* 357 * This could be moved to drm_framebuffer_remove(), but for 358 * debugging is nice to keep around the list of fb's that are 359 * no longer associated w/ a drm_file but are not unreferenced 360 * yet. (i915 and omapdrm have debugfs files which will show 361 * this.) 362 */ 363 drm_mode_object_put(dev, &fb->base); | 520 521 mutex_lock(&dev->mode_config.fb_lock); |
364 list_del(&fb->head); 365 dev->mode_config.num_fb--; | 522 list_del(&fb->head); 523 dev->mode_config.num_fb--; |
524 mutex_unlock(&dev->mode_config.fb_lock); |
|
366} 367EXPORT_SYMBOL(drm_framebuffer_cleanup); 368 369/** 370 * drm_framebuffer_remove - remove and unreference a framebuffer object 371 * @fb: framebuffer to remove 372 * | 525} 526EXPORT_SYMBOL(drm_framebuffer_cleanup); 527 528/** 529 * drm_framebuffer_remove - remove and unreference a framebuffer object 530 * @fb: framebuffer to remove 531 * |
373 * LOCKING: 374 * Caller must hold mode config lock. 375 * | |
376 * Scans all the CRTCs and planes in @dev's mode_config. If they're | 532 * Scans all the CRTCs and planes in @dev's mode_config. If they're |
377 * using @fb, removes it, setting it to NULL. | 533 * using @fb, removes it, setting it to NULL. Then drops the reference to the 534 * passed-in framebuffer. Might take the modeset locks. 535 * 536 * Note that this function optimizes the cleanup away if the caller holds the 537 * last reference to the framebuffer. It is also guaranteed to not take the 538 * modeset locks in this case. |
378 */ 379void drm_framebuffer_remove(struct drm_framebuffer *fb) 380{ 381 struct drm_device *dev = fb->dev; 382 struct drm_crtc *crtc; 383 struct drm_plane *plane; 384 struct drm_mode_set set; 385 int ret; 386 | 539 */ 540void drm_framebuffer_remove(struct drm_framebuffer *fb) 541{ 542 struct drm_device *dev = fb->dev; 543 struct drm_crtc *crtc; 544 struct drm_plane *plane; 545 struct drm_mode_set set; 546 int ret; 547 |
387 /* remove from any CRTC */ 388 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 389 if (crtc->fb == fb) { 390 /* should turn off the crtc */ 391 memset(&set, 0, sizeof(struct drm_mode_set)); 392 set.crtc = crtc; 393 set.fb = NULL; 394 ret = crtc->funcs->set_config(&set); 395 if (ret) 396 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc); | 548 WARN_ON(!list_empty(&fb->filp_head)); 549 550 /* 551 * drm ABI mandates that we remove any deleted framebuffers from active 552 * useage. But since most sane clients only remove framebuffers they no 553 * longer need, try to optimize this away. 554 * 555 * Since we're holding a reference ourselves, observing a refcount of 1 556 * means that we're the last holder and can skip it. Also, the refcount 557 * can never increase from 1 again, so we don't need any barriers or 558 * locks. 559 * 560 * Note that userspace could try to race with use and instate a new 561 * usage _after_ we've cleared all current ones. End result will be an 562 * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot 563 * in this manner. 564 */ 565 if (atomic_read(&fb->refcount.refcount) > 1) { 566 drm_modeset_lock_all(dev); 567 /* remove from any CRTC */ 568 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 569 if (crtc->fb == fb) { 570 /* should turn off the crtc */ 571 memset(&set, 0, sizeof(struct drm_mode_set)); 572 set.crtc = crtc; 573 set.fb = NULL; 574 ret = drm_mode_set_config_internal(&set); 575 if (ret) 576 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc); 577 } |
397 } | 578 } |
398 } | |
399 | 579 |
400 list_for_each_entry(plane, &dev->mode_config.plane_list, head) { 401 if (plane->fb == fb) { 402 /* should turn off the crtc */ 403 ret = plane->funcs->disable_plane(plane); 404 if (ret) 405 DRM_ERROR("failed to disable plane with busy fb\n"); 406 /* disconnect the plane from the fb and crtc: */ 407 plane->fb = NULL; 408 plane->crtc = NULL; | 580 list_for_each_entry(plane, &dev->mode_config.plane_list, head) { 581 if (plane->fb == fb) { 582 /* should turn off the crtc */ 583 ret = plane->funcs->disable_plane(plane); 584 if (ret) 585 DRM_ERROR("failed to disable plane with busy fb\n"); 586 /* disconnect the plane from the fb and crtc: */ 587 __drm_framebuffer_unreference(plane->fb); 588 plane->fb = NULL; 589 plane->crtc = NULL; 590 } |
409 } | 591 } |
592 drm_modeset_unlock_all(dev); |
|
410 } 411 | 593 } 594 |
412 list_del(&fb->filp_head); 413 | |
414 drm_framebuffer_unreference(fb); 415} 416EXPORT_SYMBOL(drm_framebuffer_remove); 417 418/** 419 * drm_crtc_init - Initialise a new CRTC object 420 * @dev: DRM device 421 * @crtc: CRTC object to init 422 * @funcs: callbacks for the new CRTC 423 * | 595 drm_framebuffer_unreference(fb); 596} 597EXPORT_SYMBOL(drm_framebuffer_remove); 598 599/** 600 * drm_crtc_init - Initialise a new CRTC object 601 * @dev: DRM device 602 * @crtc: CRTC object to init 603 * @funcs: callbacks for the new CRTC 604 * |
424 * LOCKING: 425 * Takes mode_config lock. 426 * | |
427 * Inits a new object created as base part of an driver crtc object. 428 * 429 * RETURNS: 430 * Zero on success, error code on failure. 431 */ 432int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, 433 const struct drm_crtc_funcs *funcs) 434{ 435 int ret; 436 437 crtc->dev = dev; 438 crtc->funcs = funcs; 439 crtc->invert_dimensions = false; 440 | 605 * Inits a new object created as base part of an driver crtc object. 606 * 607 * RETURNS: 608 * Zero on success, error code on failure. 609 */ 610int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, 611 const struct drm_crtc_funcs *funcs) 612{ 613 int ret; 614 615 crtc->dev = dev; 616 crtc->funcs = funcs; 617 crtc->invert_dimensions = false; 618 |
441 mutex_lock(&dev->mode_config.mutex); | 619 drm_modeset_lock_all(dev); 620 mutex_init(&crtc->mutex); 621 mutex_lock_nest_lock(&crtc->mutex, &dev->mode_config.mutex); |
442 443 ret = drm_mode_object_get(dev, &crtc->base, DRM_MODE_OBJECT_CRTC); 444 if (ret) 445 goto out; 446 447 crtc->base.properties = &crtc->properties; 448 449 list_add_tail(&crtc->head, &dev->mode_config.crtc_list); 450 dev->mode_config.num_crtc++; 451 452 out: | 622 623 ret = drm_mode_object_get(dev, &crtc->base, DRM_MODE_OBJECT_CRTC); 624 if (ret) 625 goto out; 626 627 crtc->base.properties = &crtc->properties; 628 629 list_add_tail(&crtc->head, &dev->mode_config.crtc_list); 630 dev->mode_config.num_crtc++; 631 632 out: |
453 mutex_unlock(&dev->mode_config.mutex); | 633 drm_modeset_unlock_all(dev); |
454 455 return ret; 456} 457EXPORT_SYMBOL(drm_crtc_init); 458 459/** 460 * drm_crtc_cleanup - Cleans up the core crtc usage. 461 * @crtc: CRTC to cleanup 462 * | 634 635 return ret; 636} 637EXPORT_SYMBOL(drm_crtc_init); 638 639/** 640 * drm_crtc_cleanup - Cleans up the core crtc usage. 641 * @crtc: CRTC to cleanup 642 * |
463 * LOCKING: 464 * Caller must hold mode config lock. 465 * | |
466 * Cleanup @crtc. Removes from drm modesetting space 467 * does NOT free object, caller does that. 468 */ 469void drm_crtc_cleanup(struct drm_crtc *crtc) 470{ 471 struct drm_device *dev = crtc->dev; 472 473 kfree(crtc->gamma_store); --- 5 unchanged lines hidden (view full) --- 479} 480EXPORT_SYMBOL(drm_crtc_cleanup); 481 482/** 483 * drm_mode_probed_add - add a mode to a connector's probed mode list 484 * @connector: connector the new mode 485 * @mode: mode data 486 * | 643 * Cleanup @crtc. Removes from drm modesetting space 644 * does NOT free object, caller does that. 645 */ 646void drm_crtc_cleanup(struct drm_crtc *crtc) 647{ 648 struct drm_device *dev = crtc->dev; 649 650 kfree(crtc->gamma_store); --- 5 unchanged lines hidden (view full) --- 656} 657EXPORT_SYMBOL(drm_crtc_cleanup); 658 659/** 660 * drm_mode_probed_add - add a mode to a connector's probed mode list 661 * @connector: connector the new mode 662 * @mode: mode data 663 * |
487 * LOCKING: 488 * Caller must hold mode config lock. 489 * | |
490 * Add @mode to @connector's mode list for later use. 491 */ 492void drm_mode_probed_add(struct drm_connector *connector, 493 struct drm_display_mode *mode) 494{ 495 list_add(&mode->head, &connector->probed_modes); 496} 497EXPORT_SYMBOL(drm_mode_probed_add); 498 499/** 500 * drm_mode_remove - remove and free a mode 501 * @connector: connector list to modify 502 * @mode: mode to remove 503 * | 664 * Add @mode to @connector's mode list for later use. 665 */ 666void drm_mode_probed_add(struct drm_connector *connector, 667 struct drm_display_mode *mode) 668{ 669 list_add(&mode->head, &connector->probed_modes); 670} 671EXPORT_SYMBOL(drm_mode_probed_add); 672 673/** 674 * drm_mode_remove - remove and free a mode 675 * @connector: connector list to modify 676 * @mode: mode to remove 677 * |
504 * LOCKING: 505 * Caller must hold mode config lock. 506 * | |
507 * Remove @mode from @connector's mode list, then free it. 508 */ 509void drm_mode_remove(struct drm_connector *connector, 510 struct drm_display_mode *mode) 511{ 512 list_del(&mode->head); 513 drm_mode_destroy(connector->dev, mode); 514} 515EXPORT_SYMBOL(drm_mode_remove); 516 517/** 518 * drm_connector_init - Init a preallocated connector 519 * @dev: DRM device 520 * @connector: the connector to init 521 * @funcs: callbacks for this connector | 678 * Remove @mode from @connector's mode list, then free it. 679 */ 680void drm_mode_remove(struct drm_connector *connector, 681 struct drm_display_mode *mode) 682{ 683 list_del(&mode->head); 684 drm_mode_destroy(connector->dev, mode); 685} 686EXPORT_SYMBOL(drm_mode_remove); 687 688/** 689 * drm_connector_init - Init a preallocated connector 690 * @dev: DRM device 691 * @connector: the connector to init 692 * @funcs: callbacks for this connector |
522 * @name: user visible name of the connector | 693 * @connector_type: user visible type of the connector |
523 * | 694 * |
524 * LOCKING: 525 * Takes mode config lock. 526 * | |
527 * Initialises a preallocated connector. Connectors should be 528 * subclassed as part of driver connector objects. 529 * 530 * RETURNS: 531 * Zero on success, error code on failure. 532 */ 533int drm_connector_init(struct drm_device *dev, 534 struct drm_connector *connector, 535 const struct drm_connector_funcs *funcs, 536 int connector_type) 537{ 538 int ret; 539 | 695 * Initialises a preallocated connector. Connectors should be 696 * subclassed as part of driver connector objects. 697 * 698 * RETURNS: 699 * Zero on success, error code on failure. 700 */ 701int drm_connector_init(struct drm_device *dev, 702 struct drm_connector *connector, 703 const struct drm_connector_funcs *funcs, 704 int connector_type) 705{ 706 int ret; 707 |
540 mutex_lock(&dev->mode_config.mutex); | 708 drm_modeset_lock_all(dev); |
541 542 ret = drm_mode_object_get(dev, &connector->base, DRM_MODE_OBJECT_CONNECTOR); 543 if (ret) 544 goto out; 545 546 connector->base.properties = &connector->properties; 547 connector->dev = dev; 548 connector->funcs = funcs; --- 13 unchanged lines hidden (view full) --- 562 drm_object_attach_property(&connector->base, 563 dev->mode_config.edid_property, 564 0); 565 566 drm_object_attach_property(&connector->base, 567 dev->mode_config.dpms_property, 0); 568 569 out: | 709 710 ret = drm_mode_object_get(dev, &connector->base, DRM_MODE_OBJECT_CONNECTOR); 711 if (ret) 712 goto out; 713 714 connector->base.properties = &connector->properties; 715 connector->dev = dev; 716 connector->funcs = funcs; --- 13 unchanged lines hidden (view full) --- 730 drm_object_attach_property(&connector->base, 731 dev->mode_config.edid_property, 732 0); 733 734 drm_object_attach_property(&connector->base, 735 dev->mode_config.dpms_property, 0); 736 737 out: |
570 mutex_unlock(&dev->mode_config.mutex); | 738 drm_modeset_unlock_all(dev); |
571 572 return ret; 573} 574EXPORT_SYMBOL(drm_connector_init); 575 576/** 577 * drm_connector_cleanup - cleans up an initialised connector 578 * @connector: connector to cleanup 579 * | 739 740 return ret; 741} 742EXPORT_SYMBOL(drm_connector_init); 743 744/** 745 * drm_connector_cleanup - cleans up an initialised connector 746 * @connector: connector to cleanup 747 * |
580 * LOCKING: 581 * Takes mode config lock. 582 * | |
583 * Cleans up the connector but doesn't free the object. 584 */ 585void drm_connector_cleanup(struct drm_connector *connector) 586{ 587 struct drm_device *dev = connector->dev; 588 struct drm_display_mode *mode, *t; 589 590 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) 591 drm_mode_remove(connector, mode); 592 593 list_for_each_entry_safe(mode, t, &connector->modes, head) 594 drm_mode_remove(connector, mode); 595 596 list_for_each_entry_safe(mode, t, &connector->user_modes, head) 597 drm_mode_remove(connector, mode); 598 | 748 * Cleans up the connector but doesn't free the object. 749 */ 750void drm_connector_cleanup(struct drm_connector *connector) 751{ 752 struct drm_device *dev = connector->dev; 753 struct drm_display_mode *mode, *t; 754 755 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) 756 drm_mode_remove(connector, mode); 757 758 list_for_each_entry_safe(mode, t, &connector->modes, head) 759 drm_mode_remove(connector, mode); 760 761 list_for_each_entry_safe(mode, t, &connector->user_modes, head) 762 drm_mode_remove(connector, mode); 763 |
599 mutex_lock(&dev->mode_config.mutex); | |
600 drm_mode_object_put(dev, &connector->base); 601 list_del(&connector->head); 602 dev->mode_config.num_connector--; | 764 drm_mode_object_put(dev, &connector->base); 765 list_del(&connector->head); 766 dev->mode_config.num_connector--; |
603 mutex_unlock(&dev->mode_config.mutex); | |
604} 605EXPORT_SYMBOL(drm_connector_cleanup); 606 607void drm_connector_unplug_all(struct drm_device *dev) 608{ 609 struct drm_connector *connector; 610 611 /* taking the mode config mutex ends up in a clash with sysfs */ --- 5 unchanged lines hidden (view full) --- 617 618int drm_encoder_init(struct drm_device *dev, 619 struct drm_encoder *encoder, 620 const struct drm_encoder_funcs *funcs, 621 int encoder_type) 622{ 623 int ret; 624 | 767} 768EXPORT_SYMBOL(drm_connector_cleanup); 769 770void drm_connector_unplug_all(struct drm_device *dev) 771{ 772 struct drm_connector *connector; 773 774 /* taking the mode config mutex ends up in a clash with sysfs */ --- 5 unchanged lines hidden (view full) --- 780 781int drm_encoder_init(struct drm_device *dev, 782 struct drm_encoder *encoder, 783 const struct drm_encoder_funcs *funcs, 784 int encoder_type) 785{ 786 int ret; 787 |
625 mutex_lock(&dev->mode_config.mutex); | 788 drm_modeset_lock_all(dev); |
626 627 ret = drm_mode_object_get(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER); 628 if (ret) 629 goto out; 630 631 encoder->dev = dev; 632 encoder->encoder_type = encoder_type; 633 encoder->funcs = funcs; 634 635 list_add_tail(&encoder->head, &dev->mode_config.encoder_list); 636 dev->mode_config.num_encoder++; 637 638 out: | 789 790 ret = drm_mode_object_get(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER); 791 if (ret) 792 goto out; 793 794 encoder->dev = dev; 795 encoder->encoder_type = encoder_type; 796 encoder->funcs = funcs; 797 798 list_add_tail(&encoder->head, &dev->mode_config.encoder_list); 799 dev->mode_config.num_encoder++; 800 801 out: |
639 mutex_unlock(&dev->mode_config.mutex); | 802 drm_modeset_unlock_all(dev); |
640 641 return ret; 642} 643EXPORT_SYMBOL(drm_encoder_init); 644 645void drm_encoder_cleanup(struct drm_encoder *encoder) 646{ 647 struct drm_device *dev = encoder->dev; | 803 804 return ret; 805} 806EXPORT_SYMBOL(drm_encoder_init); 807 808void drm_encoder_cleanup(struct drm_encoder *encoder) 809{ 810 struct drm_device *dev = encoder->dev; |
648 mutex_lock(&dev->mode_config.mutex); | 811 drm_modeset_lock_all(dev); |
649 drm_mode_object_put(dev, &encoder->base); 650 list_del(&encoder->head); 651 dev->mode_config.num_encoder--; | 812 drm_mode_object_put(dev, &encoder->base); 813 list_del(&encoder->head); 814 dev->mode_config.num_encoder--; |
652 mutex_unlock(&dev->mode_config.mutex); | 815 drm_modeset_unlock_all(dev); |
653} 654EXPORT_SYMBOL(drm_encoder_cleanup); 655 656int drm_plane_init(struct drm_device *dev, struct drm_plane *plane, 657 unsigned long possible_crtcs, 658 const struct drm_plane_funcs *funcs, 659 const uint32_t *formats, uint32_t format_count, 660 bool priv) 661{ 662 int ret; 663 | 816} 817EXPORT_SYMBOL(drm_encoder_cleanup); 818 819int drm_plane_init(struct drm_device *dev, struct drm_plane *plane, 820 unsigned long possible_crtcs, 821 const struct drm_plane_funcs *funcs, 822 const uint32_t *formats, uint32_t format_count, 823 bool priv) 824{ 825 int ret; 826 |
664 mutex_lock(&dev->mode_config.mutex); | 827 drm_modeset_lock_all(dev); |
665 666 ret = drm_mode_object_get(dev, &plane->base, DRM_MODE_OBJECT_PLANE); 667 if (ret) 668 goto out; 669 670 plane->base.properties = &plane->properties; 671 plane->dev = dev; 672 plane->funcs = funcs; --- 17 unchanged lines hidden (view full) --- 690 if (!priv) { 691 list_add_tail(&plane->head, &dev->mode_config.plane_list); 692 dev->mode_config.num_plane++; 693 } else { 694 INIT_LIST_HEAD(&plane->head); 695 } 696 697 out: | 828 829 ret = drm_mode_object_get(dev, &plane->base, DRM_MODE_OBJECT_PLANE); 830 if (ret) 831 goto out; 832 833 plane->base.properties = &plane->properties; 834 plane->dev = dev; 835 plane->funcs = funcs; --- 17 unchanged lines hidden (view full) --- 853 if (!priv) { 854 list_add_tail(&plane->head, &dev->mode_config.plane_list); 855 dev->mode_config.num_plane++; 856 } else { 857 INIT_LIST_HEAD(&plane->head); 858 } 859 860 out: |
698 mutex_unlock(&dev->mode_config.mutex); | 861 drm_modeset_unlock_all(dev); |
699 700 return ret; 701} 702EXPORT_SYMBOL(drm_plane_init); 703 704void drm_plane_cleanup(struct drm_plane *plane) 705{ 706 struct drm_device *dev = plane->dev; 707 | 862 863 return ret; 864} 865EXPORT_SYMBOL(drm_plane_init); 866 867void drm_plane_cleanup(struct drm_plane *plane) 868{ 869 struct drm_device *dev = plane->dev; 870 |
708 mutex_lock(&dev->mode_config.mutex); | 871 drm_modeset_lock_all(dev); |
709 kfree(plane->format_types); 710 drm_mode_object_put(dev, &plane->base); 711 /* if not added to a list, it must be a private plane */ 712 if (!list_empty(&plane->head)) { 713 list_del(&plane->head); 714 dev->mode_config.num_plane--; 715 } | 872 kfree(plane->format_types); 873 drm_mode_object_put(dev, &plane->base); 874 /* if not added to a list, it must be a private plane */ 875 if (!list_empty(&plane->head)) { 876 list_del(&plane->head); 877 dev->mode_config.num_plane--; 878 } |
716 mutex_unlock(&dev->mode_config.mutex); | 879 drm_modeset_unlock_all(dev); |
717} 718EXPORT_SYMBOL(drm_plane_cleanup); 719 720/** 721 * drm_mode_create - create a new display mode 722 * @dev: DRM device 723 * | 880} 881EXPORT_SYMBOL(drm_plane_cleanup); 882 883/** 884 * drm_mode_create - create a new display mode 885 * @dev: DRM device 886 * |
724 * LOCKING: 725 * Caller must hold DRM mode_config lock. 726 * | |
727 * Create a new drm_display_mode, give it an ID, and return it. 728 * 729 * RETURNS: 730 * Pointer to new mode on success, NULL on error. 731 */ 732struct drm_display_mode *drm_mode_create(struct drm_device *dev) 733{ 734 struct drm_display_mode *nmode; --- 11 unchanged lines hidden (view full) --- 746} 747EXPORT_SYMBOL(drm_mode_create); 748 749/** 750 * drm_mode_destroy - remove a mode 751 * @dev: DRM device 752 * @mode: mode to remove 753 * | 887 * Create a new drm_display_mode, give it an ID, and return it. 888 * 889 * RETURNS: 890 * Pointer to new mode on success, NULL on error. 891 */ 892struct drm_display_mode *drm_mode_create(struct drm_device *dev) 893{ 894 struct drm_display_mode *nmode; --- 11 unchanged lines hidden (view full) --- 906} 907EXPORT_SYMBOL(drm_mode_create); 908 909/** 910 * drm_mode_destroy - remove a mode 911 * @dev: DRM device 912 * @mode: mode to remove 913 * |
754 * LOCKING: 755 * Caller must hold mode config lock. 756 * | |
757 * Free @mode's unique identifier, then free it. 758 */ 759void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode) 760{ 761 if (!mode) 762 return; 763 764 drm_mode_object_put(dev, &mode->base); --- 208 unchanged lines hidden (view full) --- 973 return 0; 974} 975EXPORT_SYMBOL(drm_mode_create_dirty_info_property); 976 977/** 978 * drm_mode_config_init - initialize DRM mode_configuration structure 979 * @dev: DRM device 980 * | 914 * Free @mode's unique identifier, then free it. 915 */ 916void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode) 917{ 918 if (!mode) 919 return; 920 921 drm_mode_object_put(dev, &mode->base); --- 208 unchanged lines hidden (view full) --- 1130 return 0; 1131} 1132EXPORT_SYMBOL(drm_mode_create_dirty_info_property); 1133 1134/** 1135 * drm_mode_config_init - initialize DRM mode_configuration structure 1136 * @dev: DRM device 1137 * |
981 * LOCKING: 982 * None, should happen single threaded at init time. 983 * | |
984 * Initialize @dev's mode_config structure, used for tracking the graphics 985 * configuration of @dev. | 1138 * Initialize @dev's mode_config structure, used for tracking the graphics 1139 * configuration of @dev. |
1140 * 1141 * Since this initializes the modeset locks, no locking is possible. Which is no 1142 * problem, since this should happen single threaded at init time. It is the 1143 * driver's problem to ensure this guarantee. 1144 * |
|
986 */ 987void drm_mode_config_init(struct drm_device *dev) 988{ 989 mutex_init(&dev->mode_config.mutex); 990 mutex_init(&dev->mode_config.idr_mutex); | 1145 */ 1146void drm_mode_config_init(struct drm_device *dev) 1147{ 1148 mutex_init(&dev->mode_config.mutex); 1149 mutex_init(&dev->mode_config.idr_mutex); |
1150 mutex_init(&dev->mode_config.fb_lock); |
|
991 INIT_LIST_HEAD(&dev->mode_config.fb_list); 992 INIT_LIST_HEAD(&dev->mode_config.crtc_list); 993 INIT_LIST_HEAD(&dev->mode_config.connector_list); 994 INIT_LIST_HEAD(&dev->mode_config.encoder_list); 995 INIT_LIST_HEAD(&dev->mode_config.property_list); 996 INIT_LIST_HEAD(&dev->mode_config.property_blob_list); 997 INIT_LIST_HEAD(&dev->mode_config.plane_list); 998 idr_init(&dev->mode_config.crtc_idr); 999 | 1151 INIT_LIST_HEAD(&dev->mode_config.fb_list); 1152 INIT_LIST_HEAD(&dev->mode_config.crtc_list); 1153 INIT_LIST_HEAD(&dev->mode_config.connector_list); 1154 INIT_LIST_HEAD(&dev->mode_config.encoder_list); 1155 INIT_LIST_HEAD(&dev->mode_config.property_list); 1156 INIT_LIST_HEAD(&dev->mode_config.property_blob_list); 1157 INIT_LIST_HEAD(&dev->mode_config.plane_list); 1158 idr_init(&dev->mode_config.crtc_idr); 1159 |
1000 mutex_lock(&dev->mode_config.mutex); | 1160 drm_modeset_lock_all(dev); |
1001 drm_mode_create_standard_connector_properties(dev); | 1161 drm_mode_create_standard_connector_properties(dev); |
1002 mutex_unlock(&dev->mode_config.mutex); | 1162 drm_modeset_unlock_all(dev); |
1003 1004 /* Just to be sure */ 1005 dev->mode_config.num_fb = 0; 1006 dev->mode_config.num_connector = 0; 1007 dev->mode_config.num_crtc = 0; 1008 dev->mode_config.num_encoder = 0; 1009} 1010EXPORT_SYMBOL(drm_mode_config_init); --- 41 unchanged lines hidden (view full) --- 1052 return 0; 1053} 1054EXPORT_SYMBOL(drm_mode_group_init_legacy_group); 1055 1056/** 1057 * drm_mode_config_cleanup - free up DRM mode_config info 1058 * @dev: DRM device 1059 * | 1163 1164 /* Just to be sure */ 1165 dev->mode_config.num_fb = 0; 1166 dev->mode_config.num_connector = 0; 1167 dev->mode_config.num_crtc = 0; 1168 dev->mode_config.num_encoder = 0; 1169} 1170EXPORT_SYMBOL(drm_mode_config_init); --- 41 unchanged lines hidden (view full) --- 1212 return 0; 1213} 1214EXPORT_SYMBOL(drm_mode_group_init_legacy_group); 1215 1216/** 1217 * drm_mode_config_cleanup - free up DRM mode_config info 1218 * @dev: DRM device 1219 * |
1060 * LOCKING: 1061 * Caller must hold mode config lock. 1062 * | |
1063 * Free up all the connectors and CRTCs associated with this DRM device, then 1064 * free up the framebuffers and associated buffer objects. 1065 * | 1220 * Free up all the connectors and CRTCs associated with this DRM device, then 1221 * free up the framebuffers and associated buffer objects. 1222 * |
1223 * Note that since this /should/ happen single-threaded at driver/device 1224 * teardown time, no locking is required. It's the driver's job to ensure that 1225 * this guarantee actually holds true. 1226 * |
|
1066 * FIXME: cleanup any dangling user buffer objects too 1067 */ 1068void drm_mode_config_cleanup(struct drm_device *dev) 1069{ 1070 struct drm_connector *connector, *ot; 1071 struct drm_crtc *crtc, *ct; 1072 struct drm_encoder *encoder, *enct; 1073 struct drm_framebuffer *fb, *fbt; --- 10 unchanged lines hidden (view full) --- 1084 connector->funcs->destroy(connector); 1085 } 1086 1087 list_for_each_entry_safe(property, pt, &dev->mode_config.property_list, 1088 head) { 1089 drm_property_destroy(dev, property); 1090 } 1091 | 1227 * FIXME: cleanup any dangling user buffer objects too 1228 */ 1229void drm_mode_config_cleanup(struct drm_device *dev) 1230{ 1231 struct drm_connector *connector, *ot; 1232 struct drm_crtc *crtc, *ct; 1233 struct drm_encoder *encoder, *enct; 1234 struct drm_framebuffer *fb, *fbt; --- 10 unchanged lines hidden (view full) --- 1245 connector->funcs->destroy(connector); 1246 } 1247 1248 list_for_each_entry_safe(property, pt, &dev->mode_config.property_list, 1249 head) { 1250 drm_property_destroy(dev, property); 1251 } 1252 |
1253 /* 1254 * Single-threaded teardown context, so it's not required to grab the 1255 * fb_lock to protect against concurrent fb_list access. Contrary, it 1256 * would actually deadlock with the drm_framebuffer_cleanup function. 1257 * 1258 * Also, if there are any framebuffers left, that's a driver leak now, 1259 * so politely WARN about this. 1260 */ 1261 WARN_ON(!list_empty(&dev->mode_config.fb_list)); |
|
1092 list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) { 1093 drm_framebuffer_remove(fb); 1094 } 1095 1096 list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list, 1097 head) { 1098 plane->funcs->destroy(plane); 1099 } --- 7 unchanged lines hidden (view full) --- 1107} 1108EXPORT_SYMBOL(drm_mode_config_cleanup); 1109 1110/** 1111 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo 1112 * @out: drm_mode_modeinfo struct to return to the user 1113 * @in: drm_display_mode to use 1114 * | 1262 list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) { 1263 drm_framebuffer_remove(fb); 1264 } 1265 1266 list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list, 1267 head) { 1268 plane->funcs->destroy(plane); 1269 } --- 7 unchanged lines hidden (view full) --- 1277} 1278EXPORT_SYMBOL(drm_mode_config_cleanup); 1279 1280/** 1281 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo 1282 * @out: drm_mode_modeinfo struct to return to the user 1283 * @in: drm_display_mode to use 1284 * |
1115 * LOCKING: 1116 * None. 1117 * | |
1118 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to 1119 * the user. 1120 */ 1121static void drm_crtc_convert_to_umode(struct drm_mode_modeinfo *out, 1122 const struct drm_display_mode *in) 1123{ 1124 WARN(in->hdisplay > USHRT_MAX || in->hsync_start > USHRT_MAX || 1125 in->hsync_end > USHRT_MAX || in->htotal > USHRT_MAX || --- 20 unchanged lines hidden (view full) --- 1146 out->name[DRM_DISPLAY_MODE_LEN-1] = 0; 1147} 1148 1149/** 1150 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode 1151 * @out: drm_display_mode to return to the user 1152 * @in: drm_mode_modeinfo to use 1153 * | 1285 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to 1286 * the user. 1287 */ 1288static void drm_crtc_convert_to_umode(struct drm_mode_modeinfo *out, 1289 const struct drm_display_mode *in) 1290{ 1291 WARN(in->hdisplay > USHRT_MAX || in->hsync_start > USHRT_MAX || 1292 in->hsync_end > USHRT_MAX || in->htotal > USHRT_MAX || --- 20 unchanged lines hidden (view full) --- 1313 out->name[DRM_DISPLAY_MODE_LEN-1] = 0; 1314} 1315 1316/** 1317 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode 1318 * @out: drm_display_mode to return to the user 1319 * @in: drm_mode_modeinfo to use 1320 * |
1154 * LOCKING: 1155 * None. 1156 * | |
1157 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to 1158 * the caller. 1159 * 1160 * RETURNS: 1161 * Zero on success, errno on failure. 1162 */ 1163static int drm_crtc_convert_umode(struct drm_display_mode *out, 1164 const struct drm_mode_modeinfo *in) --- 18 unchanged lines hidden (view full) --- 1183 strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN); 1184 out->name[DRM_DISPLAY_MODE_LEN-1] = 0; 1185 1186 return 0; 1187} 1188 1189/** 1190 * drm_mode_getresources - get graphics configuration | 1321 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to 1322 * the caller. 1323 * 1324 * RETURNS: 1325 * Zero on success, errno on failure. 1326 */ 1327static int drm_crtc_convert_umode(struct drm_display_mode *out, 1328 const struct drm_mode_modeinfo *in) --- 18 unchanged lines hidden (view full) --- 1347 strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN); 1348 out->name[DRM_DISPLAY_MODE_LEN-1] = 0; 1349 1350 return 0; 1351} 1352 1353/** 1354 * drm_mode_getresources - get graphics configuration |
1191 * @inode: inode from the ioctl 1192 * @filp: file * from the ioctl 1193 * @cmd: cmd from ioctl 1194 * @arg: arg from ioctl | 1355 * @dev: drm device for the ioctl 1356 * @data: data pointer for the ioctl 1357 * @file_priv: drm file for the ioctl call |
1195 * | 1358 * |
1196 * LOCKING: 1197 * Takes mode config lock. 1198 * | |
1199 * Construct a set of configuration description structures and return 1200 * them to the user, including CRTC, connector and framebuffer configuration. 1201 * 1202 * Called by the user via ioctl. 1203 * 1204 * RETURNS: 1205 * Zero on success, errno on failure. 1206 */ --- 16 unchanged lines hidden (view full) --- 1223 uint32_t __user *crtc_id; 1224 uint32_t __user *connector_id; 1225 uint32_t __user *encoder_id; 1226 struct drm_mode_group *mode_group; 1227 1228 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 1229 return -EINVAL; 1230 | 1359 * Construct a set of configuration description structures and return 1360 * them to the user, including CRTC, connector and framebuffer configuration. 1361 * 1362 * Called by the user via ioctl. 1363 * 1364 * RETURNS: 1365 * Zero on success, errno on failure. 1366 */ --- 16 unchanged lines hidden (view full) --- 1383 uint32_t __user *crtc_id; 1384 uint32_t __user *connector_id; 1385 uint32_t __user *encoder_id; 1386 struct drm_mode_group *mode_group; 1387 1388 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 1389 return -EINVAL; 1390 |
1231 mutex_lock(&dev->mode_config.mutex); | |
1232 | 1391 |
1392 mutex_lock(&file_priv->fbs_lock); |
|
1233 /* 1234 * For the non-control nodes we need to limit the list of resources 1235 * by IDs in the group list for this node 1236 */ 1237 list_for_each(lh, &file_priv->fbs) 1238 fb_count++; 1239 | 1393 /* 1394 * For the non-control nodes we need to limit the list of resources 1395 * by IDs in the group list for this node 1396 */ 1397 list_for_each(lh, &file_priv->fbs) 1398 fb_count++; 1399 |
1400 /* handle this in 4 parts */ 1401 /* FBs */ 1402 if (card_res->count_fbs >= fb_count) { 1403 copied = 0; 1404 fb_id = (uint32_t __user *)(unsigned long)card_res->fb_id_ptr; 1405 list_for_each_entry(fb, &file_priv->fbs, filp_head) { 1406 if (put_user(fb->base.id, fb_id + copied)) { 1407 mutex_unlock(&file_priv->fbs_lock); 1408 return -EFAULT; 1409 } 1410 copied++; 1411 } 1412 } 1413 card_res->count_fbs = fb_count; 1414 mutex_unlock(&file_priv->fbs_lock); 1415 1416 drm_modeset_lock_all(dev); |
|
1240 mode_group = &file_priv->master->minor->mode_group; 1241 if (file_priv->master->minor->type == DRM_MINOR_CONTROL) { 1242 1243 list_for_each(lh, &dev->mode_config.crtc_list) 1244 crtc_count++; 1245 1246 list_for_each(lh, &dev->mode_config.connector_list) 1247 connector_count++; --- 7 unchanged lines hidden (view full) --- 1255 encoder_count = mode_group->num_encoders; 1256 } 1257 1258 card_res->max_height = dev->mode_config.max_height; 1259 card_res->min_height = dev->mode_config.min_height; 1260 card_res->max_width = dev->mode_config.max_width; 1261 card_res->min_width = dev->mode_config.min_width; 1262 | 1417 mode_group = &file_priv->master->minor->mode_group; 1418 if (file_priv->master->minor->type == DRM_MINOR_CONTROL) { 1419 1420 list_for_each(lh, &dev->mode_config.crtc_list) 1421 crtc_count++; 1422 1423 list_for_each(lh, &dev->mode_config.connector_list) 1424 connector_count++; --- 7 unchanged lines hidden (view full) --- 1432 encoder_count = mode_group->num_encoders; 1433 } 1434 1435 card_res->max_height = dev->mode_config.max_height; 1436 card_res->min_height = dev->mode_config.min_height; 1437 card_res->max_width = dev->mode_config.max_width; 1438 card_res->min_width = dev->mode_config.min_width; 1439 |
1263 /* handle this in 4 parts */ 1264 /* FBs */ 1265 if (card_res->count_fbs >= fb_count) { 1266 copied = 0; 1267 fb_id = (uint32_t __user *)(unsigned long)card_res->fb_id_ptr; 1268 list_for_each_entry(fb, &file_priv->fbs, filp_head) { 1269 if (put_user(fb->base.id, fb_id + copied)) { 1270 ret = -EFAULT; 1271 goto out; 1272 } 1273 copied++; 1274 } 1275 } 1276 card_res->count_fbs = fb_count; 1277 | |
1278 /* CRTCs */ 1279 if (card_res->count_crtcs >= crtc_count) { 1280 copied = 0; 1281 crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr; 1282 if (file_priv->master->minor->type == DRM_MINOR_CONTROL) { 1283 list_for_each_entry(crtc, &dev->mode_config.crtc_list, 1284 head) { 1285 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id); --- 79 unchanged lines hidden (view full) --- 1365 } 1366 } 1367 card_res->count_connectors = connector_count; 1368 1369 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res->count_crtcs, 1370 card_res->count_connectors, card_res->count_encoders); 1371 1372out: | 1440 /* CRTCs */ 1441 if (card_res->count_crtcs >= crtc_count) { 1442 copied = 0; 1443 crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr; 1444 if (file_priv->master->minor->type == DRM_MINOR_CONTROL) { 1445 list_for_each_entry(crtc, &dev->mode_config.crtc_list, 1446 head) { 1447 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id); --- 79 unchanged lines hidden (view full) --- 1527 } 1528 } 1529 card_res->count_connectors = connector_count; 1530 1531 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res->count_crtcs, 1532 card_res->count_connectors, card_res->count_encoders); 1533 1534out: |
1373 mutex_unlock(&dev->mode_config.mutex); | 1535 drm_modeset_unlock_all(dev); |
1374 return ret; 1375} 1376 1377/** 1378 * drm_mode_getcrtc - get CRTC configuration | 1536 return ret; 1537} 1538 1539/** 1540 * drm_mode_getcrtc - get CRTC configuration |
1379 * @inode: inode from the ioctl 1380 * @filp: file * from the ioctl 1381 * @cmd: cmd from ioctl 1382 * @arg: arg from ioctl | 1541 * @dev: drm device for the ioctl 1542 * @data: data pointer for the ioctl 1543 * @file_priv: drm file for the ioctl call |
1383 * | 1544 * |
1384 * LOCKING: 1385 * Takes mode config lock. 1386 * | |
1387 * Construct a CRTC configuration structure to return to the user. 1388 * 1389 * Called by the user via ioctl. 1390 * 1391 * RETURNS: 1392 * Zero on success, errno on failure. 1393 */ 1394int drm_mode_getcrtc(struct drm_device *dev, 1395 void *data, struct drm_file *file_priv) 1396{ 1397 struct drm_mode_crtc *crtc_resp = data; 1398 struct drm_crtc *crtc; 1399 struct drm_mode_object *obj; 1400 int ret = 0; 1401 1402 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 1403 return -EINVAL; 1404 | 1545 * Construct a CRTC configuration structure to return to the user. 1546 * 1547 * Called by the user via ioctl. 1548 * 1549 * RETURNS: 1550 * Zero on success, errno on failure. 1551 */ 1552int drm_mode_getcrtc(struct drm_device *dev, 1553 void *data, struct drm_file *file_priv) 1554{ 1555 struct drm_mode_crtc *crtc_resp = data; 1556 struct drm_crtc *crtc; 1557 struct drm_mode_object *obj; 1558 int ret = 0; 1559 1560 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 1561 return -EINVAL; 1562 |
1405 mutex_lock(&dev->mode_config.mutex); | 1563 drm_modeset_lock_all(dev); |
1406 1407 obj = drm_mode_object_find(dev, crtc_resp->crtc_id, 1408 DRM_MODE_OBJECT_CRTC); 1409 if (!obj) { 1410 ret = -EINVAL; 1411 goto out; 1412 } 1413 crtc = obj_to_crtc(obj); --- 11 unchanged lines hidden (view full) --- 1425 drm_crtc_convert_to_umode(&crtc_resp->mode, &crtc->mode); 1426 crtc_resp->mode_valid = 1; 1427 1428 } else { 1429 crtc_resp->mode_valid = 0; 1430 } 1431 1432out: | 1564 1565 obj = drm_mode_object_find(dev, crtc_resp->crtc_id, 1566 DRM_MODE_OBJECT_CRTC); 1567 if (!obj) { 1568 ret = -EINVAL; 1569 goto out; 1570 } 1571 crtc = obj_to_crtc(obj); --- 11 unchanged lines hidden (view full) --- 1583 drm_crtc_convert_to_umode(&crtc_resp->mode, &crtc->mode); 1584 crtc_resp->mode_valid = 1; 1585 1586 } else { 1587 crtc_resp->mode_valid = 0; 1588 } 1589 1590out: |
1433 mutex_unlock(&dev->mode_config.mutex); | 1591 drm_modeset_unlock_all(dev); |
1434 return ret; 1435} 1436 1437/** 1438 * drm_mode_getconnector - get connector configuration | 1592 return ret; 1593} 1594 1595/** 1596 * drm_mode_getconnector - get connector configuration |
1439 * @inode: inode from the ioctl 1440 * @filp: file * from the ioctl 1441 * @cmd: cmd from ioctl 1442 * @arg: arg from ioctl | 1597 * @dev: drm device for the ioctl 1598 * @data: data pointer for the ioctl 1599 * @file_priv: drm file for the ioctl call |
1443 * | 1600 * |
1444 * LOCKING: 1445 * Takes mode config lock. 1446 * | |
1447 * Construct a connector configuration structure to return to the user. 1448 * 1449 * Called by the user via ioctl. 1450 * 1451 * RETURNS: 1452 * Zero on success, errno on failure. 1453 */ 1454int drm_mode_getconnector(struct drm_device *dev, void *data, --- 115 unchanged lines hidden (view full) --- 1570 copied++; 1571 } 1572 } 1573 } 1574 out_resp->count_encoders = encoders_count; 1575 1576out: 1577 mutex_unlock(&dev->mode_config.mutex); | 1601 * Construct a connector configuration structure to return to the user. 1602 * 1603 * Called by the user via ioctl. 1604 * 1605 * RETURNS: 1606 * Zero on success, errno on failure. 1607 */ 1608int drm_mode_getconnector(struct drm_device *dev, void *data, --- 115 unchanged lines hidden (view full) --- 1724 copied++; 1725 } 1726 } 1727 } 1728 out_resp->count_encoders = encoders_count; 1729 1730out: 1731 mutex_unlock(&dev->mode_config.mutex); |
1732 |
|
1578 return ret; 1579} 1580 1581int drm_mode_getencoder(struct drm_device *dev, void *data, 1582 struct drm_file *file_priv) 1583{ 1584 struct drm_mode_get_encoder *enc_resp = data; 1585 struct drm_mode_object *obj; 1586 struct drm_encoder *encoder; 1587 int ret = 0; 1588 1589 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 1590 return -EINVAL; 1591 | 1733 return ret; 1734} 1735 1736int drm_mode_getencoder(struct drm_device *dev, void *data, 1737 struct drm_file *file_priv) 1738{ 1739 struct drm_mode_get_encoder *enc_resp = data; 1740 struct drm_mode_object *obj; 1741 struct drm_encoder *encoder; 1742 int ret = 0; 1743 1744 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 1745 return -EINVAL; 1746 |
1592 mutex_lock(&dev->mode_config.mutex); | 1747 drm_modeset_lock_all(dev); |
1593 obj = drm_mode_object_find(dev, enc_resp->encoder_id, 1594 DRM_MODE_OBJECT_ENCODER); 1595 if (!obj) { 1596 ret = -EINVAL; 1597 goto out; 1598 } 1599 encoder = obj_to_encoder(obj); 1600 1601 if (encoder->crtc) 1602 enc_resp->crtc_id = encoder->crtc->base.id; 1603 else 1604 enc_resp->crtc_id = 0; 1605 enc_resp->encoder_type = encoder->encoder_type; 1606 enc_resp->encoder_id = encoder->base.id; 1607 enc_resp->possible_crtcs = encoder->possible_crtcs; 1608 enc_resp->possible_clones = encoder->possible_clones; 1609 1610out: | 1748 obj = drm_mode_object_find(dev, enc_resp->encoder_id, 1749 DRM_MODE_OBJECT_ENCODER); 1750 if (!obj) { 1751 ret = -EINVAL; 1752 goto out; 1753 } 1754 encoder = obj_to_encoder(obj); 1755 1756 if (encoder->crtc) 1757 enc_resp->crtc_id = encoder->crtc->base.id; 1758 else 1759 enc_resp->crtc_id = 0; 1760 enc_resp->encoder_type = encoder->encoder_type; 1761 enc_resp->encoder_id = encoder->base.id; 1762 enc_resp->possible_crtcs = encoder->possible_crtcs; 1763 enc_resp->possible_clones = encoder->possible_clones; 1764 1765out: |
1611 mutex_unlock(&dev->mode_config.mutex); | 1766 drm_modeset_unlock_all(dev); |
1612 return ret; 1613} 1614 1615/** 1616 * drm_mode_getplane_res - get plane info 1617 * @dev: DRM device 1618 * @data: ioctl data 1619 * @file_priv: DRM file info 1620 * | 1767 return ret; 1768} 1769 1770/** 1771 * drm_mode_getplane_res - get plane info 1772 * @dev: DRM device 1773 * @data: ioctl data 1774 * @file_priv: DRM file info 1775 * |
1621 * LOCKING: 1622 * Takes mode config lock. 1623 * | |
1624 * Return an plane count and set of IDs. 1625 */ 1626int drm_mode_getplane_res(struct drm_device *dev, void *data, 1627 struct drm_file *file_priv) 1628{ 1629 struct drm_mode_get_plane_res *plane_resp = data; 1630 struct drm_mode_config *config; 1631 struct drm_plane *plane; 1632 uint32_t __user *plane_ptr; 1633 int copied = 0, ret = 0; 1634 1635 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 1636 return -EINVAL; 1637 | 1776 * Return an plane count and set of IDs. 1777 */ 1778int drm_mode_getplane_res(struct drm_device *dev, void *data, 1779 struct drm_file *file_priv) 1780{ 1781 struct drm_mode_get_plane_res *plane_resp = data; 1782 struct drm_mode_config *config; 1783 struct drm_plane *plane; 1784 uint32_t __user *plane_ptr; 1785 int copied = 0, ret = 0; 1786 1787 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 1788 return -EINVAL; 1789 |
1638 mutex_lock(&dev->mode_config.mutex); | 1790 drm_modeset_lock_all(dev); |
1639 config = &dev->mode_config; 1640 1641 /* 1642 * This ioctl is called twice, once to determine how much space is 1643 * needed, and the 2nd time to fill it. 1644 */ 1645 if (config->num_plane && 1646 (plane_resp->count_planes >= config->num_plane)) { --- 5 unchanged lines hidden (view full) --- 1652 goto out; 1653 } 1654 copied++; 1655 } 1656 } 1657 plane_resp->count_planes = config->num_plane; 1658 1659out: | 1791 config = &dev->mode_config; 1792 1793 /* 1794 * This ioctl is called twice, once to determine how much space is 1795 * needed, and the 2nd time to fill it. 1796 */ 1797 if (config->num_plane && 1798 (plane_resp->count_planes >= config->num_plane)) { --- 5 unchanged lines hidden (view full) --- 1804 goto out; 1805 } 1806 copied++; 1807 } 1808 } 1809 plane_resp->count_planes = config->num_plane; 1810 1811out: |
1660 mutex_unlock(&dev->mode_config.mutex); | 1812 drm_modeset_unlock_all(dev); |
1661 return ret; 1662} 1663 1664/** 1665 * drm_mode_getplane - get plane info 1666 * @dev: DRM device 1667 * @data: ioctl data 1668 * @file_priv: DRM file info 1669 * | 1813 return ret; 1814} 1815 1816/** 1817 * drm_mode_getplane - get plane info 1818 * @dev: DRM device 1819 * @data: ioctl data 1820 * @file_priv: DRM file info 1821 * |
1670 * LOCKING: 1671 * Takes mode config lock. 1672 * | |
1673 * Return plane info, including formats supported, gamma size, any 1674 * current fb, etc. 1675 */ 1676int drm_mode_getplane(struct drm_device *dev, void *data, 1677 struct drm_file *file_priv) 1678{ 1679 struct drm_mode_get_plane *plane_resp = data; 1680 struct drm_mode_object *obj; 1681 struct drm_plane *plane; 1682 uint32_t __user *format_ptr; 1683 int ret = 0; 1684 1685 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 1686 return -EINVAL; 1687 | 1822 * Return plane info, including formats supported, gamma size, any 1823 * current fb, etc. 1824 */ 1825int drm_mode_getplane(struct drm_device *dev, void *data, 1826 struct drm_file *file_priv) 1827{ 1828 struct drm_mode_get_plane *plane_resp = data; 1829 struct drm_mode_object *obj; 1830 struct drm_plane *plane; 1831 uint32_t __user *format_ptr; 1832 int ret = 0; 1833 1834 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 1835 return -EINVAL; 1836 |
1688 mutex_lock(&dev->mode_config.mutex); | 1837 drm_modeset_lock_all(dev); |
1689 obj = drm_mode_object_find(dev, plane_resp->plane_id, 1690 DRM_MODE_OBJECT_PLANE); 1691 if (!obj) { 1692 ret = -ENOENT; 1693 goto out; 1694 } 1695 plane = obj_to_plane(obj); 1696 --- 23 unchanged lines hidden (view full) --- 1720 sizeof(uint32_t) * plane->format_count)) { 1721 ret = -EFAULT; 1722 goto out; 1723 } 1724 } 1725 plane_resp->count_format_types = plane->format_count; 1726 1727out: | 1838 obj = drm_mode_object_find(dev, plane_resp->plane_id, 1839 DRM_MODE_OBJECT_PLANE); 1840 if (!obj) { 1841 ret = -ENOENT; 1842 goto out; 1843 } 1844 plane = obj_to_plane(obj); 1845 --- 23 unchanged lines hidden (view full) --- 1869 sizeof(uint32_t) * plane->format_count)) { 1870 ret = -EFAULT; 1871 goto out; 1872 } 1873 } 1874 plane_resp->count_format_types = plane->format_count; 1875 1876out: |
1728 mutex_unlock(&dev->mode_config.mutex); | 1877 drm_modeset_unlock_all(dev); |
1729 return ret; 1730} 1731 1732/** 1733 * drm_mode_setplane - set up or tear down an plane 1734 * @dev: DRM device 1735 * @data: ioctl data* | 1878 return ret; 1879} 1880 1881/** 1882 * drm_mode_setplane - set up or tear down an plane 1883 * @dev: DRM device 1884 * @data: ioctl data* |
1736 * @file_prive: DRM file info | 1885 * @file_priv: DRM file info |
1737 * | 1886 * |
1738 * LOCKING: 1739 * Takes mode config lock. 1740 * | |
1741 * Set plane info, including placement, fb, scaling, and other factors. 1742 * Or pass a NULL fb to disable. 1743 */ 1744int drm_mode_setplane(struct drm_device *dev, void *data, 1745 struct drm_file *file_priv) 1746{ 1747 struct drm_mode_set_plane *plane_req = data; 1748 struct drm_mode_object *obj; 1749 struct drm_plane *plane; 1750 struct drm_crtc *crtc; | 1887 * Set plane info, including placement, fb, scaling, and other factors. 1888 * Or pass a NULL fb to disable. 1889 */ 1890int drm_mode_setplane(struct drm_device *dev, void *data, 1891 struct drm_file *file_priv) 1892{ 1893 struct drm_mode_set_plane *plane_req = data; 1894 struct drm_mode_object *obj; 1895 struct drm_plane *plane; 1896 struct drm_crtc *crtc; |
1751 struct drm_framebuffer *fb; | 1897 struct drm_framebuffer *fb = NULL, *old_fb = NULL; |
1752 int ret = 0; 1753 unsigned int fb_width, fb_height; 1754 int i; 1755 1756 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 1757 return -EINVAL; 1758 | 1898 int ret = 0; 1899 unsigned int fb_width, fb_height; 1900 int i; 1901 1902 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 1903 return -EINVAL; 1904 |
1759 mutex_lock(&dev->mode_config.mutex); 1760 | |
1761 /* 1762 * First, find the plane, crtc, and fb objects. If not available, 1763 * we don't bother to call the driver. 1764 */ 1765 obj = drm_mode_object_find(dev, plane_req->plane_id, 1766 DRM_MODE_OBJECT_PLANE); 1767 if (!obj) { 1768 DRM_DEBUG_KMS("Unknown plane ID %d\n", 1769 plane_req->plane_id); | 1905 /* 1906 * First, find the plane, crtc, and fb objects. If not available, 1907 * we don't bother to call the driver. 1908 */ 1909 obj = drm_mode_object_find(dev, plane_req->plane_id, 1910 DRM_MODE_OBJECT_PLANE); 1911 if (!obj) { 1912 DRM_DEBUG_KMS("Unknown plane ID %d\n", 1913 plane_req->plane_id); |
1770 ret = -ENOENT; 1771 goto out; | 1914 return -ENOENT; |
1772 } 1773 plane = obj_to_plane(obj); 1774 1775 /* No fb means shut it down */ 1776 if (!plane_req->fb_id) { | 1915 } 1916 plane = obj_to_plane(obj); 1917 1918 /* No fb means shut it down */ 1919 if (!plane_req->fb_id) { |
1920 drm_modeset_lock_all(dev); 1921 old_fb = plane->fb; |
|
1777 plane->funcs->disable_plane(plane); 1778 plane->crtc = NULL; 1779 plane->fb = NULL; | 1922 plane->funcs->disable_plane(plane); 1923 plane->crtc = NULL; 1924 plane->fb = NULL; |
1925 drm_modeset_unlock_all(dev); |
|
1780 goto out; 1781 } 1782 1783 obj = drm_mode_object_find(dev, plane_req->crtc_id, 1784 DRM_MODE_OBJECT_CRTC); 1785 if (!obj) { 1786 DRM_DEBUG_KMS("Unknown crtc ID %d\n", 1787 plane_req->crtc_id); 1788 ret = -ENOENT; 1789 goto out; 1790 } 1791 crtc = obj_to_crtc(obj); 1792 | 1926 goto out; 1927 } 1928 1929 obj = drm_mode_object_find(dev, plane_req->crtc_id, 1930 DRM_MODE_OBJECT_CRTC); 1931 if (!obj) { 1932 DRM_DEBUG_KMS("Unknown crtc ID %d\n", 1933 plane_req->crtc_id); 1934 ret = -ENOENT; 1935 goto out; 1936 } 1937 crtc = obj_to_crtc(obj); 1938 |
1793 obj = drm_mode_object_find(dev, plane_req->fb_id, 1794 DRM_MODE_OBJECT_FB); 1795 if (!obj) { | 1939 fb = drm_framebuffer_lookup(dev, plane_req->fb_id); 1940 if (!fb) { |
1796 DRM_DEBUG_KMS("Unknown framebuffer ID %d\n", 1797 plane_req->fb_id); 1798 ret = -ENOENT; 1799 goto out; 1800 } | 1941 DRM_DEBUG_KMS("Unknown framebuffer ID %d\n", 1942 plane_req->fb_id); 1943 ret = -ENOENT; 1944 goto out; 1945 } |
1801 fb = obj_to_fb(obj); | |
1802 1803 /* Check whether this plane supports the fb pixel format. */ 1804 for (i = 0; i < plane->format_count; i++) 1805 if (fb->pixel_format == plane->format_types[i]) 1806 break; 1807 if (i == plane->format_count) { 1808 DRM_DEBUG_KMS("Invalid pixel format 0x%08x\n", fb->pixel_format); 1809 ret = -EINVAL; --- 29 unchanged lines hidden (view full) --- 1839 plane_req->crtc_y > INT_MAX - (int32_t) plane_req->crtc_h) { 1840 DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n", 1841 plane_req->crtc_w, plane_req->crtc_h, 1842 plane_req->crtc_x, plane_req->crtc_y); 1843 ret = -ERANGE; 1844 goto out; 1845 } 1846 | 1946 1947 /* Check whether this plane supports the fb pixel format. */ 1948 for (i = 0; i < plane->format_count; i++) 1949 if (fb->pixel_format == plane->format_types[i]) 1950 break; 1951 if (i == plane->format_count) { 1952 DRM_DEBUG_KMS("Invalid pixel format 0x%08x\n", fb->pixel_format); 1953 ret = -EINVAL; --- 29 unchanged lines hidden (view full) --- 1983 plane_req->crtc_y > INT_MAX - (int32_t) plane_req->crtc_h) { 1984 DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n", 1985 plane_req->crtc_w, plane_req->crtc_h, 1986 plane_req->crtc_x, plane_req->crtc_y); 1987 ret = -ERANGE; 1988 goto out; 1989 } 1990 |
1991 drm_modeset_lock_all(dev); |
|
1847 ret = plane->funcs->update_plane(plane, crtc, fb, 1848 plane_req->crtc_x, plane_req->crtc_y, 1849 plane_req->crtc_w, plane_req->crtc_h, 1850 plane_req->src_x, plane_req->src_y, 1851 plane_req->src_w, plane_req->src_h); 1852 if (!ret) { | 1992 ret = plane->funcs->update_plane(plane, crtc, fb, 1993 plane_req->crtc_x, plane_req->crtc_y, 1994 plane_req->crtc_w, plane_req->crtc_h, 1995 plane_req->src_x, plane_req->src_y, 1996 plane_req->src_w, plane_req->src_h); 1997 if (!ret) { |
1998 old_fb = plane->fb; 1999 fb = NULL; |
|
1853 plane->crtc = crtc; 1854 plane->fb = fb; 1855 } | 2000 plane->crtc = crtc; 2001 plane->fb = fb; 2002 } |
2003 drm_modeset_unlock_all(dev); |
|
1856 1857out: | 2004 2005out: |
1858 mutex_unlock(&dev->mode_config.mutex); | 2006 if (fb) 2007 drm_framebuffer_unreference(fb); 2008 if (old_fb) 2009 drm_framebuffer_unreference(old_fb); |
1859 1860 return ret; 1861} 1862 1863/** | 2010 2011 return ret; 2012} 2013 2014/** |
2015 * drm_mode_set_config_internal - helper to call ->set_config 2016 * @set: modeset config to set 2017 * 2018 * This is a little helper to wrap internal calls to the ->set_config driver 2019 * interface. The only thing it adds is correct refcounting dance. 2020 */ 2021int drm_mode_set_config_internal(struct drm_mode_set *set) 2022{ 2023 struct drm_crtc *crtc = set->crtc; 2024 struct drm_framebuffer *fb, *old_fb; 2025 int ret; 2026 2027 old_fb = crtc->fb; 2028 fb = set->fb; 2029 2030 ret = crtc->funcs->set_config(set); 2031 if (ret == 0) { 2032 if (old_fb) 2033 drm_framebuffer_unreference(old_fb); 2034 if (fb) 2035 drm_framebuffer_reference(fb); 2036 } 2037 2038 return ret; 2039} 2040EXPORT_SYMBOL(drm_mode_set_config_internal); 2041 2042/** |
|
1864 * drm_mode_setcrtc - set CRTC configuration | 2043 * drm_mode_setcrtc - set CRTC configuration |
1865 * @inode: inode from the ioctl 1866 * @filp: file * from the ioctl 1867 * @cmd: cmd from ioctl 1868 * @arg: arg from ioctl | 2044 * @dev: drm device for the ioctl 2045 * @data: data pointer for the ioctl 2046 * @file_priv: drm file for the ioctl call |
1869 * | 2047 * |
1870 * LOCKING: 1871 * Takes mode config lock. 1872 * | |
1873 * Build a new CRTC configuration based on user request. 1874 * 1875 * Called by the user via ioctl. 1876 * 1877 * RETURNS: 1878 * Zero on success, errno on failure. 1879 */ 1880int drm_mode_setcrtc(struct drm_device *dev, void *data, --- 13 unchanged lines hidden (view full) --- 1894 1895 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 1896 return -EINVAL; 1897 1898 /* For some reason crtc x/y offsets are signed internally. */ 1899 if (crtc_req->x > INT_MAX || crtc_req->y > INT_MAX) 1900 return -ERANGE; 1901 | 2048 * Build a new CRTC configuration based on user request. 2049 * 2050 * Called by the user via ioctl. 2051 * 2052 * RETURNS: 2053 * Zero on success, errno on failure. 2054 */ 2055int drm_mode_setcrtc(struct drm_device *dev, void *data, --- 13 unchanged lines hidden (view full) --- 2069 2070 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 2071 return -EINVAL; 2072 2073 /* For some reason crtc x/y offsets are signed internally. */ 2074 if (crtc_req->x > INT_MAX || crtc_req->y > INT_MAX) 2075 return -ERANGE; 2076 |
1902 mutex_lock(&dev->mode_config.mutex); | 2077 drm_modeset_lock_all(dev); |
1903 obj = drm_mode_object_find(dev, crtc_req->crtc_id, 1904 DRM_MODE_OBJECT_CRTC); 1905 if (!obj) { 1906 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id); 1907 ret = -EINVAL; 1908 goto out; 1909 } 1910 crtc = obj_to_crtc(obj); --- 5 unchanged lines hidden (view full) --- 1916 /* If we pass -1, set the mode with the currently bound fb */ 1917 if (crtc_req->fb_id == -1) { 1918 if (!crtc->fb) { 1919 DRM_DEBUG_KMS("CRTC doesn't have current FB\n"); 1920 ret = -EINVAL; 1921 goto out; 1922 } 1923 fb = crtc->fb; | 2078 obj = drm_mode_object_find(dev, crtc_req->crtc_id, 2079 DRM_MODE_OBJECT_CRTC); 2080 if (!obj) { 2081 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id); 2082 ret = -EINVAL; 2083 goto out; 2084 } 2085 crtc = obj_to_crtc(obj); --- 5 unchanged lines hidden (view full) --- 2091 /* If we pass -1, set the mode with the currently bound fb */ 2092 if (crtc_req->fb_id == -1) { 2093 if (!crtc->fb) { 2094 DRM_DEBUG_KMS("CRTC doesn't have current FB\n"); 2095 ret = -EINVAL; 2096 goto out; 2097 } 2098 fb = crtc->fb; |
2099 /* Make refcounting symmetric with the lookup path. */ 2100 drm_framebuffer_reference(fb); |
|
1924 } else { | 2101 } else { |
1925 obj = drm_mode_object_find(dev, crtc_req->fb_id, 1926 DRM_MODE_OBJECT_FB); 1927 if (!obj) { | 2102 fb = drm_framebuffer_lookup(dev, crtc_req->fb_id); 2103 if (!fb) { |
1928 DRM_DEBUG_KMS("Unknown FB ID%d\n", 1929 crtc_req->fb_id); 1930 ret = -EINVAL; 1931 goto out; 1932 } | 2104 DRM_DEBUG_KMS("Unknown FB ID%d\n", 2105 crtc_req->fb_id); 2106 ret = -EINVAL; 2107 goto out; 2108 } |
1933 fb = obj_to_fb(obj); | |
1934 } 1935 1936 mode = drm_mode_create(dev); 1937 if (!mode) { 1938 ret = -ENOMEM; 1939 goto out; 1940 } 1941 --- 80 unchanged lines hidden (view full) --- 2022 2023 set.crtc = crtc; 2024 set.x = crtc_req->x; 2025 set.y = crtc_req->y; 2026 set.mode = mode; 2027 set.connectors = connector_set; 2028 set.num_connectors = crtc_req->count_connectors; 2029 set.fb = fb; | 2109 } 2110 2111 mode = drm_mode_create(dev); 2112 if (!mode) { 2113 ret = -ENOMEM; 2114 goto out; 2115 } 2116 --- 80 unchanged lines hidden (view full) --- 2197 2198 set.crtc = crtc; 2199 set.x = crtc_req->x; 2200 set.y = crtc_req->y; 2201 set.mode = mode; 2202 set.connectors = connector_set; 2203 set.num_connectors = crtc_req->count_connectors; 2204 set.fb = fb; |
2030 ret = crtc->funcs->set_config(&set); | 2205 ret = drm_mode_set_config_internal(&set); |
2031 2032out: | 2206 2207out: |
2208 if (fb) 2209 drm_framebuffer_unreference(fb); 2210 |
|
2033 kfree(connector_set); 2034 drm_mode_destroy(dev, mode); | 2211 kfree(connector_set); 2212 drm_mode_destroy(dev, mode); |
2035 mutex_unlock(&dev->mode_config.mutex); | 2213 drm_modeset_unlock_all(dev); |
2036 return ret; 2037} 2038 2039int drm_mode_cursor_ioctl(struct drm_device *dev, 2040 void *data, struct drm_file *file_priv) 2041{ 2042 struct drm_mode_cursor *req = data; 2043 struct drm_mode_object *obj; 2044 struct drm_crtc *crtc; 2045 int ret = 0; 2046 2047 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 2048 return -EINVAL; 2049 2050 if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags)) 2051 return -EINVAL; 2052 | 2214 return ret; 2215} 2216 2217int drm_mode_cursor_ioctl(struct drm_device *dev, 2218 void *data, struct drm_file *file_priv) 2219{ 2220 struct drm_mode_cursor *req = data; 2221 struct drm_mode_object *obj; 2222 struct drm_crtc *crtc; 2223 int ret = 0; 2224 2225 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 2226 return -EINVAL; 2227 2228 if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags)) 2229 return -EINVAL; 2230 |
2053 mutex_lock(&dev->mode_config.mutex); | |
2054 obj = drm_mode_object_find(dev, req->crtc_id, DRM_MODE_OBJECT_CRTC); 2055 if (!obj) { 2056 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id); | 2231 obj = drm_mode_object_find(dev, req->crtc_id, DRM_MODE_OBJECT_CRTC); 2232 if (!obj) { 2233 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id); |
2057 ret = -EINVAL; 2058 goto out; | 2234 return -EINVAL; |
2059 } 2060 crtc = obj_to_crtc(obj); 2061 | 2235 } 2236 crtc = obj_to_crtc(obj); 2237 |
2238 mutex_lock(&crtc->mutex); |
|
2062 if (req->flags & DRM_MODE_CURSOR_BO) { 2063 if (!crtc->funcs->cursor_set) { 2064 ret = -ENXIO; 2065 goto out; 2066 } 2067 /* Turns off the cursor if handle is 0 */ 2068 ret = crtc->funcs->cursor_set(crtc, file_priv, req->handle, 2069 req->width, req->height); 2070 } 2071 2072 if (req->flags & DRM_MODE_CURSOR_MOVE) { 2073 if (crtc->funcs->cursor_move) { 2074 ret = crtc->funcs->cursor_move(crtc, req->x, req->y); 2075 } else { 2076 ret = -EFAULT; 2077 goto out; 2078 } 2079 } 2080out: | 2239 if (req->flags & DRM_MODE_CURSOR_BO) { 2240 if (!crtc->funcs->cursor_set) { 2241 ret = -ENXIO; 2242 goto out; 2243 } 2244 /* Turns off the cursor if handle is 0 */ 2245 ret = crtc->funcs->cursor_set(crtc, file_priv, req->handle, 2246 req->width, req->height); 2247 } 2248 2249 if (req->flags & DRM_MODE_CURSOR_MOVE) { 2250 if (crtc->funcs->cursor_move) { 2251 ret = crtc->funcs->cursor_move(crtc, req->x, req->y); 2252 } else { 2253 ret = -EFAULT; 2254 goto out; 2255 } 2256 } 2257out: |
2081 mutex_unlock(&dev->mode_config.mutex); | 2258 mutex_unlock(&crtc->mutex); 2259 |
2082 return ret; 2083} 2084 2085/* Original addfb only supported RGB formats, so figure out which one */ 2086uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth) 2087{ 2088 uint32_t fmt; 2089 --- 25 unchanged lines hidden (view full) --- 2115 } 2116 2117 return fmt; 2118} 2119EXPORT_SYMBOL(drm_mode_legacy_fb_format); 2120 2121/** 2122 * drm_mode_addfb - add an FB to the graphics configuration | 2260 return ret; 2261} 2262 2263/* Original addfb only supported RGB formats, so figure out which one */ 2264uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth) 2265{ 2266 uint32_t fmt; 2267 --- 25 unchanged lines hidden (view full) --- 2293 } 2294 2295 return fmt; 2296} 2297EXPORT_SYMBOL(drm_mode_legacy_fb_format); 2298 2299/** 2300 * drm_mode_addfb - add an FB to the graphics configuration |
2123 * @inode: inode from the ioctl 2124 * @filp: file * from the ioctl 2125 * @cmd: cmd from ioctl 2126 * @arg: arg from ioctl | 2301 * @dev: drm device for the ioctl 2302 * @data: data pointer for the ioctl 2303 * @file_priv: drm file for the ioctl call |
2127 * | 2304 * |
2128 * LOCKING: 2129 * Takes mode config lock. 2130 * | |
2131 * Add a new FB to the specified CRTC, given a user request. 2132 * 2133 * Called by the user via ioctl. 2134 * 2135 * RETURNS: 2136 * Zero on success, errno on failure. 2137 */ 2138int drm_mode_addfb(struct drm_device *dev, --- 17 unchanged lines hidden (view full) --- 2156 return -EINVAL; 2157 2158 if ((config->min_width > r.width) || (r.width > config->max_width)) 2159 return -EINVAL; 2160 2161 if ((config->min_height > r.height) || (r.height > config->max_height)) 2162 return -EINVAL; 2163 | 2305 * Add a new FB to the specified CRTC, given a user request. 2306 * 2307 * Called by the user via ioctl. 2308 * 2309 * RETURNS: 2310 * Zero on success, errno on failure. 2311 */ 2312int drm_mode_addfb(struct drm_device *dev, --- 17 unchanged lines hidden (view full) --- 2330 return -EINVAL; 2331 2332 if ((config->min_width > r.width) || (r.width > config->max_width)) 2333 return -EINVAL; 2334 2335 if ((config->min_height > r.height) || (r.height > config->max_height)) 2336 return -EINVAL; 2337 |
2164 mutex_lock(&dev->mode_config.mutex); 2165 2166 /* TODO check buffer is sufficiently large */ 2167 /* TODO setup destructor callback */ 2168 | |
2169 fb = dev->mode_config.funcs->fb_create(dev, file_priv, &r); 2170 if (IS_ERR(fb)) { 2171 DRM_DEBUG_KMS("could not create framebuffer\n"); | 2338 fb = dev->mode_config.funcs->fb_create(dev, file_priv, &r); 2339 if (IS_ERR(fb)) { 2340 DRM_DEBUG_KMS("could not create framebuffer\n"); |
2172 ret = PTR_ERR(fb); 2173 goto out; | 2341 drm_modeset_unlock_all(dev); 2342 return PTR_ERR(fb); |
2174 } 2175 | 2343 } 2344 |
2345 mutex_lock(&file_priv->fbs_lock); |
|
2176 or->fb_id = fb->base.id; 2177 list_add(&fb->filp_head, &file_priv->fbs); 2178 DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id); | 2346 or->fb_id = fb->base.id; 2347 list_add(&fb->filp_head, &file_priv->fbs); 2348 DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id); |
2349 mutex_unlock(&file_priv->fbs_lock); |
|
2179 | 2350 |
2180out: 2181 mutex_unlock(&dev->mode_config.mutex); | |
2182 return ret; 2183} 2184 2185static int format_check(const struct drm_mode_fb_cmd2 *r) 2186{ 2187 uint32_t format = r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN; 2188 2189 switch (format) { --- 109 unchanged lines hidden (view full) --- 2299 } 2300 } 2301 2302 return 0; 2303} 2304 2305/** 2306 * drm_mode_addfb2 - add an FB to the graphics configuration | 2351 return ret; 2352} 2353 2354static int format_check(const struct drm_mode_fb_cmd2 *r) 2355{ 2356 uint32_t format = r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN; 2357 2358 switch (format) { --- 109 unchanged lines hidden (view full) --- 2468 } 2469 } 2470 2471 return 0; 2472} 2473 2474/** 2475 * drm_mode_addfb2 - add an FB to the graphics configuration |
2307 * @inode: inode from the ioctl 2308 * @filp: file * from the ioctl 2309 * @cmd: cmd from ioctl 2310 * @arg: arg from ioctl | 2476 * @dev: drm device for the ioctl 2477 * @data: data pointer for the ioctl 2478 * @file_priv: drm file for the ioctl call |
2311 * | 2479 * |
2312 * LOCKING: 2313 * Takes mode config lock. 2314 * | |
2315 * Add a new FB to the specified CRTC, given a user request with format. 2316 * 2317 * Called by the user via ioctl. 2318 * 2319 * RETURNS: 2320 * Zero on success, errno on failure. 2321 */ 2322int drm_mode_addfb2(struct drm_device *dev, --- 22 unchanged lines hidden (view full) --- 2345 r->height, config->min_height, config->max_height); 2346 return -EINVAL; 2347 } 2348 2349 ret = framebuffer_check(r); 2350 if (ret) 2351 return ret; 2352 | 2480 * Add a new FB to the specified CRTC, given a user request with format. 2481 * 2482 * Called by the user via ioctl. 2483 * 2484 * RETURNS: 2485 * Zero on success, errno on failure. 2486 */ 2487int drm_mode_addfb2(struct drm_device *dev, --- 22 unchanged lines hidden (view full) --- 2510 r->height, config->min_height, config->max_height); 2511 return -EINVAL; 2512 } 2513 2514 ret = framebuffer_check(r); 2515 if (ret) 2516 return ret; 2517 |
2353 mutex_lock(&dev->mode_config.mutex); 2354 | |
2355 fb = dev->mode_config.funcs->fb_create(dev, file_priv, r); 2356 if (IS_ERR(fb)) { 2357 DRM_DEBUG_KMS("could not create framebuffer\n"); | 2518 fb = dev->mode_config.funcs->fb_create(dev, file_priv, r); 2519 if (IS_ERR(fb)) { 2520 DRM_DEBUG_KMS("could not create framebuffer\n"); |
2358 ret = PTR_ERR(fb); 2359 goto out; | 2521 drm_modeset_unlock_all(dev); 2522 return PTR_ERR(fb); |
2360 } 2361 | 2523 } 2524 |
2525 mutex_lock(&file_priv->fbs_lock); |
|
2362 r->fb_id = fb->base.id; 2363 list_add(&fb->filp_head, &file_priv->fbs); 2364 DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id); | 2526 r->fb_id = fb->base.id; 2527 list_add(&fb->filp_head, &file_priv->fbs); 2528 DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id); |
2529 mutex_unlock(&file_priv->fbs_lock); |
|
2365 | 2530 |
2366out: 2367 mutex_unlock(&dev->mode_config.mutex); | 2531 |
2368 return ret; 2369} 2370 2371/** 2372 * drm_mode_rmfb - remove an FB from the configuration | 2532 return ret; 2533} 2534 2535/** 2536 * drm_mode_rmfb - remove an FB from the configuration |
2373 * @inode: inode from the ioctl 2374 * @filp: file * from the ioctl 2375 * @cmd: cmd from ioctl 2376 * @arg: arg from ioctl | 2537 * @dev: drm device for the ioctl 2538 * @data: data pointer for the ioctl 2539 * @file_priv: drm file for the ioctl call |
2377 * | 2540 * |
2378 * LOCKING: 2379 * Takes mode config lock. 2380 * | |
2381 * Remove the FB specified by the user. 2382 * 2383 * Called by the user via ioctl. 2384 * 2385 * RETURNS: 2386 * Zero on success, errno on failure. 2387 */ 2388int drm_mode_rmfb(struct drm_device *dev, 2389 void *data, struct drm_file *file_priv) 2390{ | 2541 * Remove the FB specified by the user. 2542 * 2543 * Called by the user via ioctl. 2544 * 2545 * RETURNS: 2546 * Zero on success, errno on failure. 2547 */ 2548int drm_mode_rmfb(struct drm_device *dev, 2549 void *data, struct drm_file *file_priv) 2550{ |
2391 struct drm_mode_object *obj; | |
2392 struct drm_framebuffer *fb = NULL; 2393 struct drm_framebuffer *fbl = NULL; 2394 uint32_t *id = data; | 2551 struct drm_framebuffer *fb = NULL; 2552 struct drm_framebuffer *fbl = NULL; 2553 uint32_t *id = data; |
2395 int ret = 0; | |
2396 int found = 0; 2397 2398 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 2399 return -EINVAL; 2400 | 2554 int found = 0; 2555 2556 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 2557 return -EINVAL; 2558 |
2401 mutex_lock(&dev->mode_config.mutex); 2402 obj = drm_mode_object_find(dev, *id, DRM_MODE_OBJECT_FB); 2403 /* TODO check that we really get a framebuffer back. */ 2404 if (!obj) { 2405 ret = -EINVAL; 2406 goto out; 2407 } 2408 fb = obj_to_fb(obj); | 2559 mutex_lock(&file_priv->fbs_lock); 2560 mutex_lock(&dev->mode_config.fb_lock); 2561 fb = __drm_framebuffer_lookup(dev, *id); 2562 if (!fb) 2563 goto fail_lookup; |
2409 2410 list_for_each_entry(fbl, &file_priv->fbs, filp_head) 2411 if (fb == fbl) 2412 found = 1; | 2564 2565 list_for_each_entry(fbl, &file_priv->fbs, filp_head) 2566 if (fb == fbl) 2567 found = 1; |
2568 if (!found) 2569 goto fail_lookup; |
|
2413 | 2570 |
2414 if (!found) { 2415 ret = -EINVAL; 2416 goto out; 2417 } | 2571 /* Mark fb as reaped, we still have a ref from fpriv->fbs. */ 2572 __drm_framebuffer_unregister(dev, fb); |
2418 | 2573 |
2574 list_del_init(&fb->filp_head); 2575 mutex_unlock(&dev->mode_config.fb_lock); 2576 mutex_unlock(&file_priv->fbs_lock); 2577 |
|
2419 drm_framebuffer_remove(fb); 2420 | 2578 drm_framebuffer_remove(fb); 2579 |
2421out: 2422 mutex_unlock(&dev->mode_config.mutex); 2423 return ret; | 2580 return 0; 2581 2582fail_lookup: 2583 mutex_unlock(&dev->mode_config.fb_lock); 2584 mutex_unlock(&file_priv->fbs_lock); 2585 2586 return -EINVAL; |
2424} 2425 2426/** 2427 * drm_mode_getfb - get FB info | 2587} 2588 2589/** 2590 * drm_mode_getfb - get FB info |
2428 * @inode: inode from the ioctl 2429 * @filp: file * from the ioctl 2430 * @cmd: cmd from ioctl 2431 * @arg: arg from ioctl | 2591 * @dev: drm device for the ioctl 2592 * @data: data pointer for the ioctl 2593 * @file_priv: drm file for the ioctl call |
2432 * | 2594 * |
2433 * LOCKING: 2434 * Takes mode config lock. 2435 * | |
2436 * Lookup the FB given its ID and return info about it. 2437 * 2438 * Called by the user via ioctl. 2439 * 2440 * RETURNS: 2441 * Zero on success, errno on failure. 2442 */ 2443int drm_mode_getfb(struct drm_device *dev, 2444 void *data, struct drm_file *file_priv) 2445{ 2446 struct drm_mode_fb_cmd *r = data; | 2595 * Lookup the FB given its ID and return info about it. 2596 * 2597 * Called by the user via ioctl. 2598 * 2599 * RETURNS: 2600 * Zero on success, errno on failure. 2601 */ 2602int drm_mode_getfb(struct drm_device *dev, 2603 void *data, struct drm_file *file_priv) 2604{ 2605 struct drm_mode_fb_cmd *r = data; |
2447 struct drm_mode_object *obj; | |
2448 struct drm_framebuffer *fb; | 2606 struct drm_framebuffer *fb; |
2449 int ret = 0; | 2607 int ret; |
2450 2451 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 2452 return -EINVAL; 2453 | 2608 2609 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 2610 return -EINVAL; 2611 |
2454 mutex_lock(&dev->mode_config.mutex); 2455 obj = drm_mode_object_find(dev, r->fb_id, DRM_MODE_OBJECT_FB); 2456 if (!obj) { 2457 ret = -EINVAL; 2458 goto out; 2459 } 2460 fb = obj_to_fb(obj); | 2612 fb = drm_framebuffer_lookup(dev, r->fb_id); 2613 if (!fb) 2614 return -EINVAL; |
2461 2462 r->height = fb->height; 2463 r->width = fb->width; 2464 r->depth = fb->depth; 2465 r->bpp = fb->bits_per_pixel; 2466 r->pitch = fb->pitches[0]; | 2615 2616 r->height = fb->height; 2617 r->width = fb->width; 2618 r->depth = fb->depth; 2619 r->bpp = fb->bits_per_pixel; 2620 r->pitch = fb->pitches[0]; |
2467 fb->funcs->create_handle(fb, file_priv, &r->handle); | 2621 if (fb->funcs->create_handle) 2622 ret = fb->funcs->create_handle(fb, file_priv, &r->handle); 2623 else 2624 ret = -ENODEV; |
2468 | 2625 |
2469out: 2470 mutex_unlock(&dev->mode_config.mutex); | 2626 drm_framebuffer_unreference(fb); 2627 |
2471 return ret; 2472} 2473 2474int drm_mode_dirtyfb_ioctl(struct drm_device *dev, 2475 void *data, struct drm_file *file_priv) 2476{ 2477 struct drm_clip_rect __user *clips_ptr; 2478 struct drm_clip_rect *clips = NULL; 2479 struct drm_mode_fb_dirty_cmd *r = data; | 2628 return ret; 2629} 2630 2631int drm_mode_dirtyfb_ioctl(struct drm_device *dev, 2632 void *data, struct drm_file *file_priv) 2633{ 2634 struct drm_clip_rect __user *clips_ptr; 2635 struct drm_clip_rect *clips = NULL; 2636 struct drm_mode_fb_dirty_cmd *r = data; |
2480 struct drm_mode_object *obj; | |
2481 struct drm_framebuffer *fb; 2482 unsigned flags; 2483 int num_clips; 2484 int ret; 2485 2486 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 2487 return -EINVAL; 2488 | 2637 struct drm_framebuffer *fb; 2638 unsigned flags; 2639 int num_clips; 2640 int ret; 2641 2642 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 2643 return -EINVAL; 2644 |
2489 mutex_lock(&dev->mode_config.mutex); 2490 obj = drm_mode_object_find(dev, r->fb_id, DRM_MODE_OBJECT_FB); 2491 if (!obj) { 2492 ret = -EINVAL; 2493 goto out_err1; 2494 } 2495 fb = obj_to_fb(obj); | 2645 fb = drm_framebuffer_lookup(dev, r->fb_id); 2646 if (!fb) 2647 return -EINVAL; |
2496 2497 num_clips = r->num_clips; 2498 clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr; 2499 2500 if (!num_clips != !clips_ptr) { 2501 ret = -EINVAL; 2502 goto out_err1; 2503 } --- 21 unchanged lines hidden (view full) --- 2525 num_clips * sizeof(*clips)); 2526 if (ret) { 2527 ret = -EFAULT; 2528 goto out_err2; 2529 } 2530 } 2531 2532 if (fb->funcs->dirty) { | 2648 2649 num_clips = r->num_clips; 2650 clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr; 2651 2652 if (!num_clips != !clips_ptr) { 2653 ret = -EINVAL; 2654 goto out_err1; 2655 } --- 21 unchanged lines hidden (view full) --- 2677 num_clips * sizeof(*clips)); 2678 if (ret) { 2679 ret = -EFAULT; 2680 goto out_err2; 2681 } 2682 } 2683 2684 if (fb->funcs->dirty) { |
2685 drm_modeset_lock_all(dev); |
|
2533 ret = fb->funcs->dirty(fb, file_priv, flags, r->color, 2534 clips, num_clips); | 2686 ret = fb->funcs->dirty(fb, file_priv, flags, r->color, 2687 clips, num_clips); |
2688 drm_modeset_unlock_all(dev); |
|
2535 } else { 2536 ret = -ENOSYS; | 2689 } else { 2690 ret = -ENOSYS; |
2537 goto out_err2; | |
2538 } 2539 2540out_err2: 2541 kfree(clips); 2542out_err1: | 2691 } 2692 2693out_err2: 2694 kfree(clips); 2695out_err1: |
2543 mutex_unlock(&dev->mode_config.mutex); | 2696 drm_framebuffer_unreference(fb); 2697 |
2544 return ret; 2545} 2546 2547 2548/** 2549 * drm_fb_release - remove and free the FBs on this file | 2698 return ret; 2699} 2700 2701 2702/** 2703 * drm_fb_release - remove and free the FBs on this file |
2550 * @filp: file * from the ioctl | 2704 * @priv: drm file for the ioctl |
2551 * | 2705 * |
2552 * LOCKING: 2553 * Takes mode config lock. 2554 * | |
2555 * Destroy all the FBs associated with @filp. 2556 * 2557 * Called by the user via ioctl. 2558 * 2559 * RETURNS: 2560 * Zero on success, errno on failure. 2561 */ 2562void drm_fb_release(struct drm_file *priv) 2563{ 2564 struct drm_device *dev = priv->minor->dev; 2565 struct drm_framebuffer *fb, *tfb; 2566 | 2706 * Destroy all the FBs associated with @filp. 2707 * 2708 * Called by the user via ioctl. 2709 * 2710 * RETURNS: 2711 * Zero on success, errno on failure. 2712 */ 2713void drm_fb_release(struct drm_file *priv) 2714{ 2715 struct drm_device *dev = priv->minor->dev; 2716 struct drm_framebuffer *fb, *tfb; 2717 |
2567 mutex_lock(&dev->mode_config.mutex); | 2718 mutex_lock(&priv->fbs_lock); |
2568 list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) { | 2719 list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) { |
2720 2721 mutex_lock(&dev->mode_config.fb_lock); 2722 /* Mark fb as reaped, we still have a ref from fpriv->fbs. */ 2723 __drm_framebuffer_unregister(dev, fb); 2724 mutex_unlock(&dev->mode_config.fb_lock); 2725 2726 list_del_init(&fb->filp_head); 2727 2728 /* This will also drop the fpriv->fbs reference. */ |
|
2569 drm_framebuffer_remove(fb); 2570 } | 2729 drm_framebuffer_remove(fb); 2730 } |
2571 mutex_unlock(&dev->mode_config.mutex); | 2731 mutex_unlock(&priv->fbs_lock); |
2572} 2573 2574/** 2575 * drm_mode_attachmode - add a mode to the user mode list 2576 * @dev: DRM device 2577 * @connector: connector to add the mode to 2578 * @mode: mode to add 2579 * --- 75 unchanged lines hidden (view full) --- 2655 drm_mode_detachmode(dev, connector, mode); 2656 } 2657 return 0; 2658} 2659EXPORT_SYMBOL(drm_mode_detachmode_crtc); 2660 2661/** 2662 * drm_fb_attachmode - Attach a user mode to an connector | 2732} 2733 2734/** 2735 * drm_mode_attachmode - add a mode to the user mode list 2736 * @dev: DRM device 2737 * @connector: connector to add the mode to 2738 * @mode: mode to add 2739 * --- 75 unchanged lines hidden (view full) --- 2815 drm_mode_detachmode(dev, connector, mode); 2816 } 2817 return 0; 2818} 2819EXPORT_SYMBOL(drm_mode_detachmode_crtc); 2820 2821/** 2822 * drm_fb_attachmode - Attach a user mode to an connector |
2663 * @inode: inode from the ioctl 2664 * @filp: file * from the ioctl 2665 * @cmd: cmd from ioctl 2666 * @arg: arg from ioctl | 2823 * @dev: drm device for the ioctl 2824 * @data: data pointer for the ioctl 2825 * @file_priv: drm file for the ioctl call |
2667 * 2668 * This attaches a user specified mode to an connector. 2669 * Called by the user via ioctl. 2670 * 2671 * RETURNS: 2672 * Zero on success, errno on failure. 2673 */ 2674int drm_mode_attachmode_ioctl(struct drm_device *dev, --- 4 unchanged lines hidden (view full) --- 2679 struct drm_display_mode *mode; 2680 struct drm_mode_object *obj; 2681 struct drm_mode_modeinfo *umode = &mode_cmd->mode; 2682 int ret; 2683 2684 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 2685 return -EINVAL; 2686 | 2826 * 2827 * This attaches a user specified mode to an connector. 2828 * Called by the user via ioctl. 2829 * 2830 * RETURNS: 2831 * Zero on success, errno on failure. 2832 */ 2833int drm_mode_attachmode_ioctl(struct drm_device *dev, --- 4 unchanged lines hidden (view full) --- 2838 struct drm_display_mode *mode; 2839 struct drm_mode_object *obj; 2840 struct drm_mode_modeinfo *umode = &mode_cmd->mode; 2841 int ret; 2842 2843 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 2844 return -EINVAL; 2845 |
2687 mutex_lock(&dev->mode_config.mutex); | 2846 drm_modeset_lock_all(dev); |
2688 2689 obj = drm_mode_object_find(dev, mode_cmd->connector_id, DRM_MODE_OBJECT_CONNECTOR); 2690 if (!obj) { 2691 ret = -EINVAL; 2692 goto out; 2693 } 2694 connector = obj_to_connector(obj); 2695 --- 7 unchanged lines hidden (view full) --- 2703 if (ret) { 2704 DRM_DEBUG_KMS("Invalid mode\n"); 2705 drm_mode_destroy(dev, mode); 2706 goto out; 2707 } 2708 2709 drm_mode_attachmode(dev, connector, mode); 2710out: | 2847 2848 obj = drm_mode_object_find(dev, mode_cmd->connector_id, DRM_MODE_OBJECT_CONNECTOR); 2849 if (!obj) { 2850 ret = -EINVAL; 2851 goto out; 2852 } 2853 connector = obj_to_connector(obj); 2854 --- 7 unchanged lines hidden (view full) --- 2862 if (ret) { 2863 DRM_DEBUG_KMS("Invalid mode\n"); 2864 drm_mode_destroy(dev, mode); 2865 goto out; 2866 } 2867 2868 drm_mode_attachmode(dev, connector, mode); 2869out: |
2711 mutex_unlock(&dev->mode_config.mutex); | 2870 drm_modeset_unlock_all(dev); |
2712 return ret; 2713} 2714 2715 2716/** 2717 * drm_fb_detachmode - Detach a user specified mode from an connector | 2871 return ret; 2872} 2873 2874 2875/** 2876 * drm_fb_detachmode - Detach a user specified mode from an connector |
2718 * @inode: inode from the ioctl 2719 * @filp: file * from the ioctl 2720 * @cmd: cmd from ioctl 2721 * @arg: arg from ioctl | 2877 * @dev: drm device for the ioctl 2878 * @data: data pointer for the ioctl 2879 * @file_priv: drm file for the ioctl call |
2722 * 2723 * Called by the user via ioctl. 2724 * 2725 * RETURNS: 2726 * Zero on success, errno on failure. 2727 */ 2728int drm_mode_detachmode_ioctl(struct drm_device *dev, 2729 void *data, struct drm_file *file_priv) 2730{ 2731 struct drm_mode_object *obj; 2732 struct drm_mode_mode_cmd *mode_cmd = data; 2733 struct drm_connector *connector; 2734 struct drm_display_mode mode; 2735 struct drm_mode_modeinfo *umode = &mode_cmd->mode; 2736 int ret; 2737 2738 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 2739 return -EINVAL; 2740 | 2880 * 2881 * Called by the user via ioctl. 2882 * 2883 * RETURNS: 2884 * Zero on success, errno on failure. 2885 */ 2886int drm_mode_detachmode_ioctl(struct drm_device *dev, 2887 void *data, struct drm_file *file_priv) 2888{ 2889 struct drm_mode_object *obj; 2890 struct drm_mode_mode_cmd *mode_cmd = data; 2891 struct drm_connector *connector; 2892 struct drm_display_mode mode; 2893 struct drm_mode_modeinfo *umode = &mode_cmd->mode; 2894 int ret; 2895 2896 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 2897 return -EINVAL; 2898 |
2741 mutex_lock(&dev->mode_config.mutex); | 2899 drm_modeset_lock_all(dev); |
2742 2743 obj = drm_mode_object_find(dev, mode_cmd->connector_id, DRM_MODE_OBJECT_CONNECTOR); 2744 if (!obj) { 2745 ret = -EINVAL; 2746 goto out; 2747 } 2748 connector = obj_to_connector(obj); 2749 2750 ret = drm_crtc_convert_umode(&mode, umode); 2751 if (ret) { 2752 DRM_DEBUG_KMS("Invalid mode\n"); 2753 goto out; 2754 } 2755 2756 ret = drm_mode_detachmode(dev, connector, &mode); 2757out: | 2900 2901 obj = drm_mode_object_find(dev, mode_cmd->connector_id, DRM_MODE_OBJECT_CONNECTOR); 2902 if (!obj) { 2903 ret = -EINVAL; 2904 goto out; 2905 } 2906 connector = obj_to_connector(obj); 2907 2908 ret = drm_crtc_convert_umode(&mode, umode); 2909 if (ret) { 2910 DRM_DEBUG_KMS("Invalid mode\n"); 2911 goto out; 2912 } 2913 2914 ret = drm_mode_detachmode(dev, connector, &mode); 2915out: |
2758 mutex_unlock(&dev->mode_config.mutex); | 2916 drm_modeset_unlock_all(dev); |
2759 return ret; 2760} 2761 2762struct drm_property *drm_property_create(struct drm_device *dev, int flags, 2763 const char *name, int num_values) 2764{ 2765 struct drm_property *property = NULL; 2766 int ret; --- 229 unchanged lines hidden (view full) --- 2996 struct drm_property_blob *prop_blob; 2997 uint32_t __user *blob_id_ptr; 2998 uint64_t __user *values_ptr; 2999 uint32_t __user *blob_length_ptr; 3000 3001 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 3002 return -EINVAL; 3003 | 2917 return ret; 2918} 2919 2920struct drm_property *drm_property_create(struct drm_device *dev, int flags, 2921 const char *name, int num_values) 2922{ 2923 struct drm_property *property = NULL; 2924 int ret; --- 229 unchanged lines hidden (view full) --- 3154 struct drm_property_blob *prop_blob; 3155 uint32_t __user *blob_id_ptr; 3156 uint64_t __user *values_ptr; 3157 uint32_t __user *blob_length_ptr; 3158 3159 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 3160 return -EINVAL; 3161 |
3004 mutex_lock(&dev->mode_config.mutex); | 3162 drm_modeset_lock_all(dev); |
3005 obj = drm_mode_object_find(dev, out_resp->prop_id, DRM_MODE_OBJECT_PROPERTY); 3006 if (!obj) { 3007 ret = -EINVAL; 3008 goto done; 3009 } 3010 property = obj_to_property(obj); 3011 3012 if (property->flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)) { --- 61 unchanged lines hidden (view full) --- 3074 } 3075 3076 copied++; 3077 } 3078 } 3079 out_resp->count_enum_blobs = blob_count; 3080 } 3081done: | 3163 obj = drm_mode_object_find(dev, out_resp->prop_id, DRM_MODE_OBJECT_PROPERTY); 3164 if (!obj) { 3165 ret = -EINVAL; 3166 goto done; 3167 } 3168 property = obj_to_property(obj); 3169 3170 if (property->flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)) { --- 61 unchanged lines hidden (view full) --- 3232 } 3233 3234 copied++; 3235 } 3236 } 3237 out_resp->count_enum_blobs = blob_count; 3238 } 3239done: |
3082 mutex_unlock(&dev->mode_config.mutex); | 3240 drm_modeset_unlock_all(dev); |
3083 return ret; 3084} 3085 3086static struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, int length, 3087 void *data) 3088{ 3089 struct drm_property_blob *blob; 3090 int ret; --- 34 unchanged lines hidden (view full) --- 3125 struct drm_mode_get_blob *out_resp = data; 3126 struct drm_property_blob *blob; 3127 int ret = 0; 3128 void __user *blob_ptr; 3129 3130 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 3131 return -EINVAL; 3132 | 3241 return ret; 3242} 3243 3244static struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, int length, 3245 void *data) 3246{ 3247 struct drm_property_blob *blob; 3248 int ret; --- 34 unchanged lines hidden (view full) --- 3283 struct drm_mode_get_blob *out_resp = data; 3284 struct drm_property_blob *blob; 3285 int ret = 0; 3286 void __user *blob_ptr; 3287 3288 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 3289 return -EINVAL; 3290 |
3133 mutex_lock(&dev->mode_config.mutex); | 3291 drm_modeset_lock_all(dev); |
3134 obj = drm_mode_object_find(dev, out_resp->blob_id, DRM_MODE_OBJECT_BLOB); 3135 if (!obj) { 3136 ret = -EINVAL; 3137 goto done; 3138 } 3139 blob = obj_to_blob(obj); 3140 3141 if (out_resp->length == blob->length) { 3142 blob_ptr = (void __user *)(unsigned long)out_resp->data; 3143 if (copy_to_user(blob_ptr, blob->data, blob->length)){ 3144 ret = -EFAULT; 3145 goto done; 3146 } 3147 } 3148 out_resp->length = blob->length; 3149 3150done: | 3292 obj = drm_mode_object_find(dev, out_resp->blob_id, DRM_MODE_OBJECT_BLOB); 3293 if (!obj) { 3294 ret = -EINVAL; 3295 goto done; 3296 } 3297 blob = obj_to_blob(obj); 3298 3299 if (out_resp->length == blob->length) { 3300 blob_ptr = (void __user *)(unsigned long)out_resp->data; 3301 if (copy_to_user(blob_ptr, blob->data, blob->length)){ 3302 ret = -EFAULT; 3303 goto done; 3304 } 3305 } 3306 out_resp->length = blob->length; 3307 3308done: |
3151 mutex_unlock(&dev->mode_config.mutex); | 3309 drm_modeset_unlock_all(dev); |
3152 return ret; 3153} 3154 3155int drm_mode_connector_update_edid_property(struct drm_connector *connector, 3156 struct edid *edid) 3157{ 3158 struct drm_device *dev = connector->dev; 3159 int ret, size; --- 125 unchanged lines hidden (view full) --- 3285 int copied = 0; 3286 int props_count = 0; 3287 uint32_t __user *props_ptr; 3288 uint64_t __user *prop_values_ptr; 3289 3290 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 3291 return -EINVAL; 3292 | 3310 return ret; 3311} 3312 3313int drm_mode_connector_update_edid_property(struct drm_connector *connector, 3314 struct edid *edid) 3315{ 3316 struct drm_device *dev = connector->dev; 3317 int ret, size; --- 125 unchanged lines hidden (view full) --- 3443 int copied = 0; 3444 int props_count = 0; 3445 uint32_t __user *props_ptr; 3446 uint64_t __user *prop_values_ptr; 3447 3448 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 3449 return -EINVAL; 3450 |
3293 mutex_lock(&dev->mode_config.mutex); | 3451 drm_modeset_lock_all(dev); |
3294 3295 obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type); 3296 if (!obj) { 3297 ret = -EINVAL; 3298 goto out; 3299 } 3300 if (!obj->properties) { 3301 ret = -EINVAL; --- 20 unchanged lines hidden (view full) --- 3322 ret = -EFAULT; 3323 goto out; 3324 } 3325 copied++; 3326 } 3327 } 3328 arg->count_props = props_count; 3329out: | 3452 3453 obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type); 3454 if (!obj) { 3455 ret = -EINVAL; 3456 goto out; 3457 } 3458 if (!obj->properties) { 3459 ret = -EINVAL; --- 20 unchanged lines hidden (view full) --- 3480 ret = -EFAULT; 3481 goto out; 3482 } 3483 copied++; 3484 } 3485 } 3486 arg->count_props = props_count; 3487out: |
3330 mutex_unlock(&dev->mode_config.mutex); | 3488 drm_modeset_unlock_all(dev); |
3331 return ret; 3332} 3333 3334int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data, 3335 struct drm_file *file_priv) 3336{ 3337 struct drm_mode_obj_set_property *arg = data; 3338 struct drm_mode_object *arg_obj; 3339 struct drm_mode_object *prop_obj; 3340 struct drm_property *property; 3341 int ret = -EINVAL; 3342 int i; 3343 3344 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 3345 return -EINVAL; 3346 | 3489 return ret; 3490} 3491 3492int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data, 3493 struct drm_file *file_priv) 3494{ 3495 struct drm_mode_obj_set_property *arg = data; 3496 struct drm_mode_object *arg_obj; 3497 struct drm_mode_object *prop_obj; 3498 struct drm_property *property; 3499 int ret = -EINVAL; 3500 int i; 3501 3502 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 3503 return -EINVAL; 3504 |
3347 mutex_lock(&dev->mode_config.mutex); | 3505 drm_modeset_lock_all(dev); |
3348 3349 arg_obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type); 3350 if (!arg_obj) 3351 goto out; 3352 if (!arg_obj->properties) 3353 goto out; 3354 3355 for (i = 0; i < arg_obj->properties->count; i++) --- 21 unchanged lines hidden (view full) --- 3377 ret = drm_mode_crtc_set_obj_prop(arg_obj, property, arg->value); 3378 break; 3379 case DRM_MODE_OBJECT_PLANE: 3380 ret = drm_mode_plane_set_obj_prop(arg_obj, property, arg->value); 3381 break; 3382 } 3383 3384out: | 3506 3507 arg_obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type); 3508 if (!arg_obj) 3509 goto out; 3510 if (!arg_obj->properties) 3511 goto out; 3512 3513 for (i = 0; i < arg_obj->properties->count; i++) --- 21 unchanged lines hidden (view full) --- 3535 ret = drm_mode_crtc_set_obj_prop(arg_obj, property, arg->value); 3536 break; 3537 case DRM_MODE_OBJECT_PLANE: 3538 ret = drm_mode_plane_set_obj_prop(arg_obj, property, arg->value); 3539 break; 3540 } 3541 3542out: |
3385 mutex_unlock(&dev->mode_config.mutex); | 3543 drm_modeset_unlock_all(dev); |
3386 return ret; 3387} 3388 3389int drm_mode_connector_attach_encoder(struct drm_connector *connector, 3390 struct drm_encoder *encoder) 3391{ 3392 int i; 3393 --- 45 unchanged lines hidden (view full) --- 3439 struct drm_crtc *crtc; 3440 void *r_base, *g_base, *b_base; 3441 int size; 3442 int ret = 0; 3443 3444 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 3445 return -EINVAL; 3446 | 3544 return ret; 3545} 3546 3547int drm_mode_connector_attach_encoder(struct drm_connector *connector, 3548 struct drm_encoder *encoder) 3549{ 3550 int i; 3551 --- 45 unchanged lines hidden (view full) --- 3597 struct drm_crtc *crtc; 3598 void *r_base, *g_base, *b_base; 3599 int size; 3600 int ret = 0; 3601 3602 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 3603 return -EINVAL; 3604 |
3447 mutex_lock(&dev->mode_config.mutex); | 3605 drm_modeset_lock_all(dev); |
3448 obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC); 3449 if (!obj) { 3450 ret = -EINVAL; 3451 goto out; 3452 } 3453 crtc = obj_to_crtc(obj); 3454 3455 if (crtc->funcs->gamma_set == NULL) { --- 24 unchanged lines hidden (view full) --- 3480 if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) { 3481 ret = -EFAULT; 3482 goto out; 3483 } 3484 3485 crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size); 3486 3487out: | 3606 obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC); 3607 if (!obj) { 3608 ret = -EINVAL; 3609 goto out; 3610 } 3611 crtc = obj_to_crtc(obj); 3612 3613 if (crtc->funcs->gamma_set == NULL) { --- 24 unchanged lines hidden (view full) --- 3638 if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) { 3639 ret = -EFAULT; 3640 goto out; 3641 } 3642 3643 crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size); 3644 3645out: |
3488 mutex_unlock(&dev->mode_config.mutex); | 3646 drm_modeset_unlock_all(dev); |
3489 return ret; 3490 3491} 3492 3493int drm_mode_gamma_get_ioctl(struct drm_device *dev, 3494 void *data, struct drm_file *file_priv) 3495{ 3496 struct drm_mode_crtc_lut *crtc_lut = data; 3497 struct drm_mode_object *obj; 3498 struct drm_crtc *crtc; 3499 void *r_base, *g_base, *b_base; 3500 int size; 3501 int ret = 0; 3502 3503 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 3504 return -EINVAL; 3505 | 3647 return ret; 3648 3649} 3650 3651int drm_mode_gamma_get_ioctl(struct drm_device *dev, 3652 void *data, struct drm_file *file_priv) 3653{ 3654 struct drm_mode_crtc_lut *crtc_lut = data; 3655 struct drm_mode_object *obj; 3656 struct drm_crtc *crtc; 3657 void *r_base, *g_base, *b_base; 3658 int size; 3659 int ret = 0; 3660 3661 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 3662 return -EINVAL; 3663 |
3506 mutex_lock(&dev->mode_config.mutex); | 3664 drm_modeset_lock_all(dev); |
3507 obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC); 3508 if (!obj) { 3509 ret = -EINVAL; 3510 goto out; 3511 } 3512 crtc = obj_to_crtc(obj); 3513 3514 /* memcpy into gamma store */ --- 16 unchanged lines hidden (view full) --- 3531 } 3532 3533 b_base = g_base + size; 3534 if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) { 3535 ret = -EFAULT; 3536 goto out; 3537 } 3538out: | 3665 obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC); 3666 if (!obj) { 3667 ret = -EINVAL; 3668 goto out; 3669 } 3670 crtc = obj_to_crtc(obj); 3671 3672 /* memcpy into gamma store */ --- 16 unchanged lines hidden (view full) --- 3689 } 3690 3691 b_base = g_base + size; 3692 if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) { 3693 ret = -EFAULT; 3694 goto out; 3695 } 3696out: |
3539 mutex_unlock(&dev->mode_config.mutex); | 3697 drm_modeset_unlock_all(dev); |
3540 return ret; 3541} 3542 3543int drm_mode_page_flip_ioctl(struct drm_device *dev, 3544 void *data, struct drm_file *file_priv) 3545{ 3546 struct drm_mode_crtc_page_flip *page_flip = data; 3547 struct drm_mode_object *obj; 3548 struct drm_crtc *crtc; | 3698 return ret; 3699} 3700 3701int drm_mode_page_flip_ioctl(struct drm_device *dev, 3702 void *data, struct drm_file *file_priv) 3703{ 3704 struct drm_mode_crtc_page_flip *page_flip = data; 3705 struct drm_mode_object *obj; 3706 struct drm_crtc *crtc; |
3549 struct drm_framebuffer *fb; | 3707 struct drm_framebuffer *fb = NULL, *old_fb = NULL; |
3550 struct drm_pending_vblank_event *e = NULL; 3551 unsigned long flags; 3552 int hdisplay, vdisplay; 3553 int ret = -EINVAL; 3554 3555 if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS || 3556 page_flip->reserved != 0) 3557 return -EINVAL; 3558 | 3708 struct drm_pending_vblank_event *e = NULL; 3709 unsigned long flags; 3710 int hdisplay, vdisplay; 3711 int ret = -EINVAL; 3712 3713 if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS || 3714 page_flip->reserved != 0) 3715 return -EINVAL; 3716 |
3559 mutex_lock(&dev->mode_config.mutex); | |
3560 obj = drm_mode_object_find(dev, page_flip->crtc_id, DRM_MODE_OBJECT_CRTC); 3561 if (!obj) | 3717 obj = drm_mode_object_find(dev, page_flip->crtc_id, DRM_MODE_OBJECT_CRTC); 3718 if (!obj) |
3562 goto out; | 3719 return -EINVAL; |
3563 crtc = obj_to_crtc(obj); 3564 | 3720 crtc = obj_to_crtc(obj); 3721 |
3722 mutex_lock(&crtc->mutex); |
|
3565 if (crtc->fb == NULL) { 3566 /* The framebuffer is currently unbound, presumably 3567 * due to a hotplug event, that userspace has not 3568 * yet discovered. 3569 */ 3570 ret = -EBUSY; 3571 goto out; 3572 } 3573 3574 if (crtc->funcs->page_flip == NULL) 3575 goto out; 3576 | 3723 if (crtc->fb == NULL) { 3724 /* The framebuffer is currently unbound, presumably 3725 * due to a hotplug event, that userspace has not 3726 * yet discovered. 3727 */ 3728 ret = -EBUSY; 3729 goto out; 3730 } 3731 3732 if (crtc->funcs->page_flip == NULL) 3733 goto out; 3734 |
3577 obj = drm_mode_object_find(dev, page_flip->fb_id, DRM_MODE_OBJECT_FB); 3578 if (!obj) | 3735 fb = drm_framebuffer_lookup(dev, page_flip->fb_id); 3736 if (!fb) |
3579 goto out; | 3737 goto out; |
3580 fb = obj_to_fb(obj); | |
3581 3582 hdisplay = crtc->mode.hdisplay; 3583 vdisplay = crtc->mode.vdisplay; 3584 3585 if (crtc->invert_dimensions) 3586 swap(hdisplay, vdisplay); 3587 3588 if (hdisplay > fb->width || --- 29 unchanged lines hidden (view full) --- 3618 e->event.base.length = sizeof e->event; 3619 e->event.user_data = page_flip->user_data; 3620 e->base.event = &e->event.base; 3621 e->base.file_priv = file_priv; 3622 e->base.destroy = 3623 (void (*) (struct drm_pending_event *)) kfree; 3624 } 3625 | 3738 3739 hdisplay = crtc->mode.hdisplay; 3740 vdisplay = crtc->mode.vdisplay; 3741 3742 if (crtc->invert_dimensions) 3743 swap(hdisplay, vdisplay); 3744 3745 if (hdisplay > fb->width || --- 29 unchanged lines hidden (view full) --- 3775 e->event.base.length = sizeof e->event; 3776 e->event.user_data = page_flip->user_data; 3777 e->base.event = &e->event.base; 3778 e->base.file_priv = file_priv; 3779 e->base.destroy = 3780 (void (*) (struct drm_pending_event *)) kfree; 3781 } 3782 |
3783 old_fb = crtc->fb; |
|
3626 ret = crtc->funcs->page_flip(crtc, fb, e); 3627 if (ret) { 3628 if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) { 3629 spin_lock_irqsave(&dev->event_lock, flags); 3630 file_priv->event_space += sizeof e->event; 3631 spin_unlock_irqrestore(&dev->event_lock, flags); 3632 kfree(e); 3633 } | 3784 ret = crtc->funcs->page_flip(crtc, fb, e); 3785 if (ret) { 3786 if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) { 3787 spin_lock_irqsave(&dev->event_lock, flags); 3788 file_priv->event_space += sizeof e->event; 3789 spin_unlock_irqrestore(&dev->event_lock, flags); 3790 kfree(e); 3791 } |
3792 /* Keep the old fb, don't unref it. */ 3793 old_fb = NULL; 3794 } else { 3795 /* Unref only the old framebuffer. */ 3796 fb = NULL; |
|
3634 } 3635 3636out: | 3797 } 3798 3799out: |
3637 mutex_unlock(&dev->mode_config.mutex); | 3800 if (fb) 3801 drm_framebuffer_unreference(fb); 3802 if (old_fb) 3803 drm_framebuffer_unreference(old_fb); 3804 mutex_unlock(&crtc->mutex); 3805 |
3638 return ret; 3639} 3640 3641void drm_mode_config_reset(struct drm_device *dev) 3642{ 3643 struct drm_crtc *crtc; 3644 struct drm_encoder *encoder; 3645 struct drm_connector *connector; --- 259 unchanged lines hidden --- | 3806 return ret; 3807} 3808 3809void drm_mode_config_reset(struct drm_device *dev) 3810{ 3811 struct drm_crtc *crtc; 3812 struct drm_encoder *encoder; 3813 struct drm_connector *connector; --- 259 unchanged lines hidden --- |