1494N/A * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. 1494N/A * Copyright (c) 2006-2008, 2013, Intel Corporation 1494N/A * Copyright (c) 2007 Dave Airlie <airlied@linux.ie> 1494N/A * Copyright (c) 2008 Red Hat Inc. 1494N/A * DRM core CRTC related functions 1494N/A * Permission to use, copy, modify, distribute, and sell this software and its 1494N/A * documentation for any purpose is hereby granted without fee, provided that 1494N/A * the above copyright notice appear in all copies and that both that copyright 1494N/A * notice and this permission notice appear in supporting documentation, and 1494N/A * that the name of the copyright holders not be used in advertising or 1494N/A * publicity pertaining to distribution of the software without specific, 1494N/A * written prior permission. The copyright holders make no representations 1494N/A * about the suitability of this software for any purpose. It is provided "as 1494N/A * is" without express or implied warranty. 1494N/A * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 1494N/A * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 1494N/A * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 1494N/A * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 1494N/A * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 1494N/A * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 1494N/A * Eric Anholt <eric@anholt.net> 1494N/A * Dave Airlie <airlied@linux.ie> 1494N/A * Jesse Barnes <jesse.barnes@intel.com> 1494N/A * drm_modeset_lock_all - take all modeset locks 1494N/A * This function takes all modeset locks, suitable where a more fine-grained 1494N/A * scheme isn't (yet) implemented. 1494N/A * drm_modeset_unlock_all - drop all modeset locks 1494N/A/* Avoid boilerplate. I'm tired of typing. */ 1494N/A * Non-global properties, but "required" for certain connectors. 1494N/A * Connector and encoder types. 1494N/A "%c%c%c%c %s-endian (0x%08x)",
1494N/A * drm_mode_object_get - allocate a new modeset identifier 1494N/A * @obj: object pointer, used to generate unique ID 1494N/A * Create a unique identifier based on @ptr in @dev's identifier space. Used 1494N/A * for tracking modes, CRTCs and connectors. 1494N/A * New unique (relative to other objects in @dev) integer identifier for the 1494N/A * Set up the object linking under the protection of the idr 1494N/A * lock so that other users can't see inconsistent state. 1494N/A * drm_mode_object_put - free an identifer 1494N/A * Free @id from @dev's unique identifier pool. 1494N/A * drm_mode_object_find - look up a drm object with static lifetime 1494N/A * @id: id of the mode object 1494N/A * @type: type of the mode object 1494N/A * Note that framebuffers cannot be looked up with this functions - since those 1494N/A * are reference counted, they need special treatment. 1494N/A /* Framebuffers are reference counted and need their own lookup 1494N/A * drm_framebuffer_init - initialize a framebuffer 1494N/A * Allocates an ID for the framebuffer's parent mode object, sets its mode 1494N/A * functions & device file and adds it to the master fd list. 1494N/A * This functions publishes the fb and makes it available for concurrent access 1494N/A * by other users. Which means by this point the fb _must_ be fully set up - 1494N/A * since all the fb attributes are invariant over its lifetime, no further 1494N/A * locking but only correct reference counting is required. 1494N/A * Zero on success, error code on failure. 1494N/A /* Grab the idr reference. */ 1494N/A * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference 1494N/A * If successful, this grabs an additional reference to the framebuffer - 1494N/A * callers need to make sure to eventually unreference the returned framebuffer 1494N/A * drm_framebuffer_unreference - unref a framebuffer 1494N/A * drm_framebuffer_reference - incr the fb refcnt 1494N/A/* LINTED E_FUNC_ARG_UNUSED */ 1494N/A/* dev->mode_config.fb_lock must be held! */ 1494N/A * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr 1494N/A * Drivers need to call this when cleaning up driver-private framebuffers, e.g. 1494N/A * those used for fbdev. Note that the caller must hold a reference of it's own, 1494N/A * i.e. the object may not be destroyed through this call (since it'll lead to a 1494N/A /* Mark fb as reaped and drop idr ref. */ 1494N/A * drm_framebuffer_cleanup - remove a framebuffer object 1494N/A * @fb: framebuffer to remove 1494N/A * Cleanup references to a user-created framebuffer. This function is intended 1494N/A * to be used from the drivers ->destroy callback. 1494N/A * Note that this function does not remove the fb from active usuage - if it is 1494N/A * still used anywhere, hilarity can ensue since userspace could call getfb on 1494N/A * the id and get back -EINVAL. Obviously no concern at driver unload time. 1494N/A * Also, the framebuffer will not be removed from the lookup idr - for 1494N/A * user-created framebuffers this will happen in in the rmfb ioctl. For 1494N/A * driver-private objects (e.g. for fbdev) drivers need to explicitly call 1494N/A * drm_framebuffer_unregister_private. 1494N/A * drm_framebuffer_remove - remove and unreference a framebuffer object 1494N/A * @fb: framebuffer to remove 1494N/A * using @fb, removes it, setting it to NULL. Then drops the reference to the 1494N/A * passed-in framebuffer. Might take the modeset locks. 1494N/A * Note that this function optimizes the cleanup away if the caller holds the 1494N/A * last reference to the framebuffer. It is also guaranteed to not take the 1494N/A * modeset locks in this case. 1494N/A * drm ABI mandates that we remove any deleted framebuffers from active 1494N/A * useage. But since most sane clients only remove framebuffers they no 1494N/A * longer need, try to optimize this away. 1494N/A * Since we're holding a reference ourselves, observing a refcount of 1 1494N/A * means that we're the last holder and can skip it. Also, the refcount 1494N/A * can never increase from 1 again, so we don't need any barriers or 1494N/A * Note that userspace could try to race with use and instate a new 1494N/A * usage _after_ we've cleared all current ones. End result will be an 1494N/A * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot 1494N/A /* should turn off the crtc */ 1494N/A * drm_crtc_init - Initialise a new CRTC object 1494N/A * @crtc: CRTC object to init 1494N/A * @funcs: callbacks for the new CRTC 1494N/A * Inits a new object created as base part of an driver crtc object. 1494N/A * drm_crtc_cleanup - Cleans up the core crtc usage. 1494N/A * Cleanup @crtc. Removes from drm modesetting space 1494N/A * does NOT free object, caller does that. 1494N/A * drm_mode_probed_add - add a mode to a connector's probed mode list 1494N/A * @connector: connector the new mode 1494N/A * Add @mode to @connector's mode list for later use. 1494N/A * drm_mode_remove - remove and free a mode 1494N/A * @connector: connector list to modify 1494N/A * Remove @mode from @connector's mode list, then free it. 1494N/A * drm_connector_init - Init a preallocated connector 1494N/A * @connector: the connector to init 1494N/A * @funcs: callbacks for this connector 1494N/A * @name: user visible name of the connector 1494N/A * Initialises a preallocated connector. Connectors should be 1494N/A * subclassed as part of driver connector objects. 1494N/A * Zero on success, error code on failure. 1494N/A * drm_connector_cleanup - cleans up an initialised connector 1494N/A * @connector: connector to cleanup 1494N/A * Cleans up the connector but doesn't free the object. 1494N/A/* LINTED E_FUNC_ARG_UNUSED */ 1494N/A struct drm_connector *connector; 1494N/A /* taking the mode config mutex ends up in a clash with sysfs */ 1494N/A list_for_each_entry(connector, struct drm_connector, &dev->mode_config.connector_list, head) 1494N/A drm_sysfs_connector_remove(connector); 1494N/A * drm_plane_init - Initialise a new plane object 1494N/A * @plane: plane object to init 1494N/A * @possible_crtcs: bitmask of possible CRTCs 1494N/A * @funcs: callbacks for the new plane 1494N/A * @formats: array of supported formats (%DRM_FORMAT_*) 1494N/A * @format_count: number of elements in @formats 1494N/A * @priv: plane is private (hidden from userspace)? 1494N/A * Inits a new object created as base part of a driver plane object. 1494N/A * Zero on success, error code on failure. 1494N/A /* private planes are not exposed to userspace, but depending on 1494N/A * display hardware, might be convenient to allow sharing programming 1494N/A * for the scanout engine with the crtc implementation. 1494N/A * drm_plane_cleanup - Clean up the core plane usage 1494N/A * This function cleans up @plane and removes it from the DRM mode setting 1494N/A * core. Note that the function does *not* free the plane structure itself, 1494N/A * this is the responsibility of the caller. 1494N/A /* if not added to a list, it must be a private plane */ 1494N/A * drm_plane_force_disable - Forcibly disable a plane 1494N/A * Forces the plane to be disabled. 1494N/A * Used when the plane's current framebuffer is destroyed, 1494N/A * and when restoring fbdev mode. 1494N/A /* disconnect the plane from the fb and crtc: */ 1494N/A * drm_mode_create - create a new display mode 1494N/A * Create a new drm_display_mode, give it an ID, and return it. 1494N/A * Pointer to new mode on success, NULL on error. 1494N/A * drm_mode_destroy - remove a mode 1494N/A * Free @mode's unique identifier, then free it. 1494N/A * Standard properties (apply to all connectors) 1494N/A * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties 1494N/A * Called by a driver the first time a DVI-I connector is made. 1494N/A * drm_create_tv_properties - create TV specific connector properties 1494N/A * @num_modes: number of different TV formats (modes) supported 1494N/A * @modes: array of pointers to strings containing name of each format 1494N/A * Called by a driver's TV initialization routine, this function creates 1494N/A * the TV specific connector properties for a given device. Caller is 1494N/A * responsible for allocating a list of format names and passing them to 1494N/A * Basic connector properties 1494N/A * Other, TV specific properties: margins & TV modes. 1494N/A * drm_mode_create_scaling_mode_property - create scaling mode property 1494N/A * Called by a driver the first time it's needed, must be attached to desired 1494N/A * drm_mode_create_dithering_property - create dithering property 1494N/A * Called by a driver the first time it's needed, must be attached to desired 1494N/A * drm_mode_create_dirty_property - create dirty property 1494N/A * Called by a driver the first time it's needed, must be attached to desired 1494N/A * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo 1494N/A * @out: drm_mode_modeinfo struct to return to the user 1494N/A * @in: drm_display_mode to use 1494N/A * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to 1494N/A * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode 1494N/A * @out: drm_display_mode to return to the user 1494N/A * @in: drm_mode_modeinfo to use 1494N/A * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to 1494N/A * drm_mode_getresources - get graphics configuration 1494N/A * @inode: inode from the ioctl 1494N/A * @filp: file * from the ioctl 1494N/A * Construct a set of configuration description structures and return 1494N/A * them to the user, including CRTC, connector and framebuffer configuration. 1494N/A * Called by the user via ioctl. 1494N/A * Zero on success, errno on failure. 1494N/A/* LINTED E_FUNC_ARG_UNUSED */ 1494N/A * For the non-control nodes we need to limit the list of resources 1494N/A * by IDs in the group list for this node 1494N/A /* handle this in 4 parts */ 1494N/A * drm_mode_getcrtc - get CRTC configuration 1494N/A * @inode: inode from the ioctl 1494N/A * @filp: file * from the ioctl 1494N/A * Construct a CRTC configuration structure to return to the user. 1494N/A * Called by the user via ioctl. 1494N/A * Zero on success, errno on failure. 1494N/A/* LINTED E_FUNC_ARG_UNUSED */ 1494N/A * drm_mode_getconnector - get connector configuration 1494N/A * @inode: inode from the ioctl 1494N/A * @filp: file * from the ioctl 1494N/A * Construct a connector configuration structure to return to the user. 1494N/A * Called by the user via ioctl. 1494N/A * Zero on success, errno on failure. 1494N/A/* LINTED E_FUNC_ARG_UNUSED */ 1494N/A /* delayed so we get modes regardless of pre-fill_modes state */ 1494N/A * This ioctl is called twice, once to determine how much space is 1494N/A * needed, and the 2nd time to fill it. 1494N/A/* LINTED E_FUNC_ARG_UNUSED */ 1494N/A * drm_mode_getplane_res - get plane info 1494N/A * @file_priv: DRM file info 1494N/A * Return an plane count and set of IDs. 1494N/A/* LINTED E_FUNC_ARG_UNUSED */ 1494N/A * This ioctl is called twice, once to determine how much space is 1494N/A * needed, and the 2nd time to fill it. 1494N/A * drm_mode_getplane - get plane info 1494N/A * @file_priv: DRM file info 1494N/A * Return plane info, including formats supported, gamma size, any 1494N/A/* LINTED E_FUNC_ARG_UNUSED */ 1494N/A * This ioctl is called twice, once to determine how much space is 1494N/A * needed, and the 2nd time to fill it. 1494N/A * drm_mode_setplane - set up or tear down an plane 1494N/A * @file_prive: DRM file info 1494N/A * Set plane info, including placement, fb, scaling, and other factors. 1494N/A * Or pass a NULL fb to disable. 1494N/A/* LINTED E_FUNC_ARG_UNUSED */ 1494N/A * First, find the plane, crtc, and fb objects. If not available, 1494N/A * we don't bother to call the driver. 1494N/A /* No fb means shut it down */ 1494N/A /* Check whether this plane supports the fb pixel format. */ 1494N/A /* Make sure source coordinates are inside the fb. */ 1494N/A "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
1494N/A /* Give drivers some help against integer overflows */ 1494N/A * drm_mode_set_config_internal - helper to call ->set_config 1494N/A * @set: modeset config to set 1494N/A * This is a little helper to wrap internal calls to the ->set_config driver 1494N/A * interface. The only thing it adds is correct refcounting dance. 1494N/A * NOTE: ->set_config can also disable other crtcs (if we steal all 1494N/A * connectors from it), hence we need to refcount the fbs across all 1494N/A * crtcs. Atomic modeset will have saner semantics ... 1494N/A /* crtc->fb must be updated by ->set_config, enforces this. */ 1494N/A * drm_mode_setcrtc - set CRTC configuration 1494N/A * @inode: inode from the ioctl 1494N/A * @filp: file * from the ioctl 1494N/A * Build a new CRTC configuration based on user request. 1494N/A * Called by the user via ioctl. 1494N/A * Zero on success, errno on failure. 1494N/A/* LINTED E_FUNC_ARG_UNUSED */ 1494N/A /* For some reason crtc x/y offsets are signed internally. */ 1494N/A /* If we have a mode we need a framebuffer. */ 1494N/A /* If we pass -1, set the mode with the currently bound fb */ 1494N/A /* Make refcounting symmetric with the lookup path. */ 1494N/A /* Avoid unbounded kernel memory allocation */ 1494N/A /* Turns off the cursor if handle is 0 */ 1494N/A/* LINTED E_FUNC_ARG_UNUSED */ 1494N/A/* LINTED E_FUNC_ARG_UNUSED */ 1494N/A/* Original addfb only supported RGB formats, so figure out which one */ 1494N/A * drm_mode_addfb - add an FB to the graphics configuration 1494N/A * @inode: inode from the ioctl 1494N/A * @filp: file * from the ioctl 1494N/A * Add a new FB to the specified CRTC, given a user request. 1494N/A * Called by the user via ioctl. 1494N/A * Zero on success, errno on failure. 1494N/A/* LINTED E_FUNC_ARG_UNUSED */ 1494N/A /* Use new struct with format internally */ 1494N/A * drm_mode_addfb2 - add an FB to the graphics configuration 1494N/A * @inode: inode from the ioctl 1494N/A * @filp: file * from the ioctl 1494N/A * Add a new FB to the specified CRTC, given a user request with format. 1494N/A * Called by the user via ioctl. 1494N/A * Zero on success, errno on failure. 1494N/A/* LINTED E_FUNC_ARG_UNUSED */ 1494N/A * drm_mode_rmfb - remove an FB from the configuration 1494N/A * @inode: inode from the ioctl 1494N/A * @filp: file * from the ioctl 1494N/A * Remove the FB specified by the user. 1494N/A * Called by the user via ioctl. 1494N/A * Zero on success, errno on failure. 1494N/A /* Mark fb as reaped, we still have a ref from fpriv->fbs. */ 1494N/A * drm_mode_getfb - get FB info 1494N/A * @inode: inode from the ioctl 1494N/A * @filp: file * from the ioctl 1494N/A * Lookup the FB given its ID and return info about it. 1494N/A * Called by the user via ioctl. 1494N/A * Zero on success, errno on failure. 1494N/A /* If userspace annotates copy, clips must come in pairs */ 1494N/A * drm_fb_release - remove and free the FBs on this file 1494N/A * @filp: file * from the ioctl 1494N/A * Destroy all the FBs associated with @filp. 1494N/A * Called by the user via ioctl. 1494N/A * Zero on success, errno on failure. 1494N/A /* Mark fb as reaped, we still have a ref from fpriv->fbs. */ 1494N/A /* This will also drop the fpriv->fbs reference. */ 1494N/A * Bitmask enum properties have the additional constraint of values 1494N/A "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time " 1494N/A "you see this message on the same object type.\n",
1494N/A /* Delete edid, when there is none. */ 1494N/A /* Only the driver knows */ 1494N/A /* It does all the locking and checking we need */ 1494N/A /* store the property value if successful */ 1494N/A /* This ioctl is called twice, once to determine how much space is 1494N/A * needed, and the 2nd time to fill it. */ 1494N/A /* memcpy into gamma store */ 1494N/A /* memcpy into gamma store */ 1494N/A /* The framebuffer is currently unbound, presumably 1494N/A * due to a hotplug event, that userspace has not 1494N/A /* Keep the old fb, don't unref it. */ 1494N/A * Warn if the driver hasn't properly updated the crtc->fb 1494N/A * field to reflect that the new framebuffer is now used. 1494N/A * Failing to do so will screw with the reference counting 1494N/A /* Unref only the old framebuffer. */ 1494N/A/* LINTED E_FUNC_ARG_UNUSED */ 1494N/A/* LINTED E_FUNC_ARG_UNUSED */ 1494N/A /* call driver ioctl to get mmap offset */ 1494N/A/* LINTED E_FUNC_ARG_UNUSED */ 1494N/A * Just need to support RGB formats here for compat with code that doesn't 1494N/A * use pixel formats directly yet. 1494N/A * drm_format_num_planes - get the number of planes for format 1494N/A * @format: pixel format (DRM_FORMAT_*) 1494N/A * The number of planes used by the specified pixel format. 1494N/A * drm_format_plane_cpp - determine the bytes per pixel value 1494N/A * @format: pixel format (DRM_FORMAT_*) 1494N/A * The bytes per pixel value for the specified plane. 1494N/A * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor 1494N/A * @format: pixel format (DRM_FORMAT_*) 1494N/A * The horizontal chroma subsampling factor for the 1494N/A * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor 1494N/A * @format: pixel format (DRM_FORMAT_*) 1494N/A * The vertical chroma subsampling factor for the 1494N/A * drm_mode_config_init - initialize DRM mode_configuration structure 1494N/A * Initialize @dev's mode_config structure, used for tracking the graphics 1494N/A * Since this initializes the modeset locks, no locking is possible. Which is no 1494N/A * problem, since this should happen single threaded at init time. It is the 1494N/A * driver's problem to ensure this guarantee. 1494N/A * drm_mode_config_cleanup - free up DRM mode_config info 1494N/A * Free up all the connectors and CRTCs associated with this DRM device, then 1494N/A * free up the framebuffers and associated buffer objects. 1494N/A * teardown time, no locking is required. It's the driver's job to ensure that 1494N/A * this guarantee actually holds true. 1494N/A * FIXME: cleanup any dangling user buffer objects too 1494N/A * Single-threaded teardown context, so it's not required to grab the 1494N/A * fb_lock to protect against concurrent fb_list access. Contrary, it 1494N/A * would actually deadlock with the drm_framebuffer_cleanup function. 1494N/A * Also, if there are any framebuffers left, that's a driver leak now, 1494N/A * so politely WARN about this.