2014-07-25 19:30:38 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Red Hat
|
|
|
|
* Copyright (C) 2014 Intel Corp.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Rob Clark <robdclark@gmail.com>
|
|
|
|
* Daniel Vetter <daniel.vetter@ffwll.ch>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <drm/drmP.h>
|
|
|
|
#include <drm/drm_atomic.h>
|
2016-02-26 17:05:00 +00:00
|
|
|
#include <drm/drm_mode.h>
|
2014-07-25 19:30:38 +00:00
|
|
|
#include <drm/drm_plane_helper.h>
|
2016-11-05 15:08:09 +00:00
|
|
|
#include <drm/drm_print.h>
|
2016-11-15 13:06:39 +00:00
|
|
|
#include <linux/sync_file.h>
|
2014-07-25 19:30:38 +00:00
|
|
|
|
2016-04-28 13:19:56 +00:00
|
|
|
#include "drm_crtc_internal.h"
|
|
|
|
|
2016-12-21 13:03:35 +00:00
|
|
|
void __drm_crtc_commit_free(struct kref *kref)
|
2016-06-08 12:19:00 +00:00
|
|
|
{
|
|
|
|
struct drm_crtc_commit *commit =
|
|
|
|
container_of(kref, struct drm_crtc_commit, ref);
|
|
|
|
|
|
|
|
kfree(commit);
|
|
|
|
}
|
2016-12-21 13:03:35 +00:00
|
|
|
EXPORT_SYMBOL(__drm_crtc_commit_free);
|
2016-06-08 12:19:00 +00:00
|
|
|
|
2015-05-18 08:06:40 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_state_default_release -
|
|
|
|
* release memory initialized by drm_atomic_state_init
|
|
|
|
* @state: atomic state
|
|
|
|
*
|
|
|
|
* Free all the memory allocated by drm_atomic_state_init.
|
|
|
|
* This is useful for drivers that subclass the atomic state.
|
|
|
|
*/
|
|
|
|
void drm_atomic_state_default_release(struct drm_atomic_state *state)
|
2014-07-25 19:30:38 +00:00
|
|
|
{
|
|
|
|
kfree(state->connectors);
|
|
|
|
kfree(state->crtcs);
|
|
|
|
kfree(state->planes);
|
|
|
|
}
|
2015-05-18 08:06:40 +00:00
|
|
|
EXPORT_SYMBOL(drm_atomic_state_default_release);
|
2014-07-25 19:30:38 +00:00
|
|
|
|
|
|
|
/**
|
2015-05-18 08:06:40 +00:00
|
|
|
* drm_atomic_state_init - init new atomic state
|
2014-07-25 19:30:38 +00:00
|
|
|
* @dev: DRM device
|
2015-05-18 08:06:40 +00:00
|
|
|
* @state: atomic state
|
2014-07-25 19:30:38 +00:00
|
|
|
*
|
2015-05-18 08:06:40 +00:00
|
|
|
* Default implementation for filling in a new atomic state.
|
|
|
|
* This is useful for drivers that subclass the atomic state.
|
2014-07-25 19:30:38 +00:00
|
|
|
*/
|
2015-05-18 08:06:40 +00:00
|
|
|
int
|
|
|
|
drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state)
|
2014-07-25 19:30:38 +00:00
|
|
|
{
|
2016-10-14 12:18:18 +00:00
|
|
|
kref_init(&state->ref);
|
|
|
|
|
2014-12-18 21:01:56 +00:00
|
|
|
/* TODO legacy paths should maybe do a better job about
|
|
|
|
* setting this appropriately?
|
|
|
|
*/
|
|
|
|
state->allow_modeset = true;
|
|
|
|
|
2014-07-25 19:30:38 +00:00
|
|
|
state->crtcs = kcalloc(dev->mode_config.num_crtc,
|
|
|
|
sizeof(*state->crtcs), GFP_KERNEL);
|
|
|
|
if (!state->crtcs)
|
|
|
|
goto fail;
|
|
|
|
state->planes = kcalloc(dev->mode_config.num_total_plane,
|
|
|
|
sizeof(*state->planes), GFP_KERNEL);
|
|
|
|
if (!state->planes)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
state->dev = dev;
|
|
|
|
|
2015-05-18 08:06:40 +00:00
|
|
|
DRM_DEBUG_ATOMIC("Allocated atomic state %p\n", state);
|
2014-07-25 19:30:38 +00:00
|
|
|
|
2015-05-18 08:06:40 +00:00
|
|
|
return 0;
|
2014-07-25 19:30:38 +00:00
|
|
|
fail:
|
2015-05-18 08:06:40 +00:00
|
|
|
drm_atomic_state_default_release(state);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_state_init);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_atomic_state_alloc - allocate atomic state
|
|
|
|
* @dev: DRM device
|
|
|
|
*
|
|
|
|
* This allocates an empty atomic state to track updates.
|
|
|
|
*/
|
|
|
|
struct drm_atomic_state *
|
|
|
|
drm_atomic_state_alloc(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct drm_mode_config *config = &dev->mode_config;
|
|
|
|
struct drm_atomic_state *state;
|
|
|
|
|
|
|
|
if (!config->funcs->atomic_state_alloc) {
|
|
|
|
state = kzalloc(sizeof(*state), GFP_KERNEL);
|
|
|
|
if (!state)
|
|
|
|
return NULL;
|
|
|
|
if (drm_atomic_state_init(dev, state) < 0) {
|
|
|
|
kfree(state);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
2014-07-25 19:30:38 +00:00
|
|
|
|
2015-05-18 08:06:40 +00:00
|
|
|
return config->funcs->atomic_state_alloc(dev);
|
2014-07-25 19:30:38 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_state_alloc);
|
|
|
|
|
|
|
|
/**
|
2015-05-18 08:06:40 +00:00
|
|
|
* drm_atomic_state_default_clear - clear base atomic state
|
2014-07-25 19:30:38 +00:00
|
|
|
* @state: atomic state
|
|
|
|
*
|
2015-05-18 08:06:40 +00:00
|
|
|
* Default implementation for clearing atomic state.
|
|
|
|
* This is useful for drivers that subclass the atomic state.
|
2014-07-25 19:30:38 +00:00
|
|
|
*/
|
2015-05-18 08:06:40 +00:00
|
|
|
void drm_atomic_state_default_clear(struct drm_atomic_state *state)
|
2014-07-25 19:30:38 +00:00
|
|
|
{
|
|
|
|
struct drm_device *dev = state->dev;
|
2014-11-19 17:38:07 +00:00
|
|
|
struct drm_mode_config *config = &dev->mode_config;
|
2014-07-25 19:30:38 +00:00
|
|
|
int i;
|
|
|
|
|
2015-02-22 11:24:16 +00:00
|
|
|
DRM_DEBUG_ATOMIC("Clearing atomic state %p\n", state);
|
2014-07-25 19:30:38 +00:00
|
|
|
|
2014-11-19 17:38:08 +00:00
|
|
|
for (i = 0; i < state->num_connector; i++) {
|
2016-06-01 22:06:32 +00:00
|
|
|
struct drm_connector *connector = state->connectors[i].ptr;
|
2014-07-25 19:30:38 +00:00
|
|
|
|
|
|
|
if (!connector)
|
|
|
|
continue;
|
|
|
|
|
2016-04-27 01:27:39 +00:00
|
|
|
connector->funcs->atomic_destroy_state(connector,
|
2016-06-01 22:06:32 +00:00
|
|
|
state->connectors[i].state);
|
|
|
|
state->connectors[i].ptr = NULL;
|
|
|
|
state->connectors[i].state = NULL;
|
2017-02-28 14:46:39 +00:00
|
|
|
drm_connector_put(connector);
|
2014-07-25 19:30:38 +00:00
|
|
|
}
|
|
|
|
|
2014-11-19 17:38:07 +00:00
|
|
|
for (i = 0; i < config->num_crtc; i++) {
|
2016-06-01 22:06:34 +00:00
|
|
|
struct drm_crtc *crtc = state->crtcs[i].ptr;
|
2014-07-25 19:30:38 +00:00
|
|
|
|
|
|
|
if (!crtc)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
crtc->funcs->atomic_destroy_state(crtc,
|
2016-06-01 22:06:34 +00:00
|
|
|
state->crtcs[i].state);
|
2016-06-08 12:19:00 +00:00
|
|
|
|
|
|
|
if (state->crtcs[i].commit) {
|
|
|
|
kfree(state->crtcs[i].commit->event);
|
|
|
|
state->crtcs[i].commit->event = NULL;
|
|
|
|
drm_crtc_commit_put(state->crtcs[i].commit);
|
|
|
|
}
|
|
|
|
|
|
|
|
state->crtcs[i].commit = NULL;
|
2016-06-01 22:06:34 +00:00
|
|
|
state->crtcs[i].ptr = NULL;
|
|
|
|
state->crtcs[i].state = NULL;
|
2014-07-25 19:30:38 +00:00
|
|
|
}
|
|
|
|
|
2014-11-19 17:38:07 +00:00
|
|
|
for (i = 0; i < config->num_total_plane; i++) {
|
2016-06-01 22:06:33 +00:00
|
|
|
struct drm_plane *plane = state->planes[i].ptr;
|
2014-07-25 19:30:38 +00:00
|
|
|
|
|
|
|
if (!plane)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
plane->funcs->atomic_destroy_state(plane,
|
2016-06-01 22:06:33 +00:00
|
|
|
state->planes[i].state);
|
|
|
|
state->planes[i].ptr = NULL;
|
|
|
|
state->planes[i].state = NULL;
|
2014-07-25 19:30:38 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-18 08:06:40 +00:00
|
|
|
EXPORT_SYMBOL(drm_atomic_state_default_clear);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_atomic_state_clear - clear state object
|
|
|
|
* @state: atomic state
|
|
|
|
*
|
|
|
|
* When the w/w mutex algorithm detects a deadlock we need to back off and drop
|
|
|
|
* all locks. So someone else could sneak in and change the current modeset
|
|
|
|
* configuration. Which means that all the state assembled in @state is no
|
|
|
|
* longer an atomic update to the current state, but to some arbitrary earlier
|
2017-01-25 06:26:45 +00:00
|
|
|
* state. Which could break assumptions the driver's
|
|
|
|
* &drm_mode_config_funcs.atomic_check likely relies on.
|
2015-05-18 08:06:40 +00:00
|
|
|
*
|
|
|
|
* Hence we must clear all cached state and completely start over, using this
|
|
|
|
* function.
|
|
|
|
*/
|
|
|
|
void drm_atomic_state_clear(struct drm_atomic_state *state)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = state->dev;
|
|
|
|
struct drm_mode_config *config = &dev->mode_config;
|
|
|
|
|
|
|
|
if (config->funcs->atomic_state_clear)
|
|
|
|
config->funcs->atomic_state_clear(state);
|
|
|
|
else
|
|
|
|
drm_atomic_state_default_clear(state);
|
|
|
|
}
|
2014-07-25 19:30:38 +00:00
|
|
|
EXPORT_SYMBOL(drm_atomic_state_clear);
|
|
|
|
|
|
|
|
/**
|
2016-10-14 12:18:18 +00:00
|
|
|
* __drm_atomic_state_free - free all memory for an atomic state
|
|
|
|
* @ref: This atomic state to deallocate
|
2014-07-25 19:30:38 +00:00
|
|
|
*
|
|
|
|
* This frees all memory associated with an atomic state, including all the
|
|
|
|
* per-object state for planes, crtcs and connectors.
|
|
|
|
*/
|
2016-10-14 12:18:18 +00:00
|
|
|
void __drm_atomic_state_free(struct kref *ref)
|
2014-07-25 19:30:38 +00:00
|
|
|
{
|
2016-10-14 12:18:18 +00:00
|
|
|
struct drm_atomic_state *state = container_of(ref, typeof(*state), ref);
|
|
|
|
struct drm_mode_config *config = &state->dev->mode_config;
|
2015-05-18 08:06:40 +00:00
|
|
|
|
2014-07-25 19:30:38 +00:00
|
|
|
drm_atomic_state_clear(state);
|
|
|
|
|
2015-02-22 11:24:16 +00:00
|
|
|
DRM_DEBUG_ATOMIC("Freeing atomic state %p\n", state);
|
2014-07-25 19:30:38 +00:00
|
|
|
|
2015-05-18 08:06:40 +00:00
|
|
|
if (config->funcs->atomic_state_free) {
|
|
|
|
config->funcs->atomic_state_free(state);
|
|
|
|
} else {
|
|
|
|
drm_atomic_state_default_release(state);
|
|
|
|
kfree(state);
|
|
|
|
}
|
2014-07-25 19:30:38 +00:00
|
|
|
}
|
2016-10-14 12:18:18 +00:00
|
|
|
EXPORT_SYMBOL(__drm_atomic_state_free);
|
2014-07-25 19:30:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_atomic_get_crtc_state - get crtc state
|
|
|
|
* @state: global atomic state object
|
|
|
|
* @crtc: crtc to get state object for
|
|
|
|
*
|
|
|
|
* This function returns the crtc state for the given crtc, allocating it if
|
|
|
|
* needed. It will also grab the relevant crtc lock to make sure that the state
|
|
|
|
* is consistent.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
*
|
|
|
|
* Either the allocated state or the error code encoded into the pointer. When
|
|
|
|
* the error is EDEADLK then the w/w mutex code has detected a deadlock and the
|
|
|
|
* entire atomic sequence must be restarted. All other errors are fatal.
|
|
|
|
*/
|
|
|
|
struct drm_crtc_state *
|
|
|
|
drm_atomic_get_crtc_state(struct drm_atomic_state *state,
|
|
|
|
struct drm_crtc *crtc)
|
|
|
|
{
|
2015-05-13 08:37:25 +00:00
|
|
|
int ret, index = drm_crtc_index(crtc);
|
2014-07-25 19:30:38 +00:00
|
|
|
struct drm_crtc_state *crtc_state;
|
|
|
|
|
2016-05-03 09:12:31 +00:00
|
|
|
WARN_ON(!state->acquire_ctx);
|
|
|
|
|
2015-05-13 08:37:25 +00:00
|
|
|
crtc_state = drm_atomic_get_existing_crtc_state(state, crtc);
|
|
|
|
if (crtc_state)
|
|
|
|
return crtc_state;
|
2014-07-25 19:30:38 +00:00
|
|
|
|
|
|
|
ret = drm_modeset_lock(&crtc->mutex, state->acquire_ctx);
|
|
|
|
if (ret)
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
|
|
|
|
crtc_state = crtc->funcs->atomic_duplicate_state(crtc);
|
|
|
|
if (!crtc_state)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2016-06-01 22:06:34 +00:00
|
|
|
state->crtcs[index].state = crtc_state;
|
2017-01-16 09:37:38 +00:00
|
|
|
state->crtcs[index].old_state = crtc->state;
|
|
|
|
state->crtcs[index].new_state = crtc_state;
|
2016-06-01 22:06:34 +00:00
|
|
|
state->crtcs[index].ptr = crtc;
|
2014-07-25 19:30:38 +00:00
|
|
|
crtc_state->state = state;
|
|
|
|
|
2015-12-08 16:41:53 +00:00
|
|
|
DRM_DEBUG_ATOMIC("Added [CRTC:%d:%s] %p state to %p\n",
|
|
|
|
crtc->base.id, crtc->name, crtc_state, state);
|
2014-07-25 19:30:38 +00:00
|
|
|
|
|
|
|
return crtc_state;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_get_crtc_state);
|
|
|
|
|
2016-11-16 13:00:21 +00:00
|
|
|
static void set_out_fence_for_crtc(struct drm_atomic_state *state,
|
2017-01-13 14:22:09 +00:00
|
|
|
struct drm_crtc *crtc, s32 __user *fence_ptr)
|
2016-11-16 13:00:21 +00:00
|
|
|
{
|
|
|
|
state->crtcs[drm_crtc_index(crtc)].out_fence_ptr = fence_ptr;
|
|
|
|
}
|
|
|
|
|
2017-01-13 14:22:09 +00:00
|
|
|
static s32 __user *get_out_fence_for_crtc(struct drm_atomic_state *state,
|
2016-11-16 13:00:21 +00:00
|
|
|
struct drm_crtc *crtc)
|
|
|
|
{
|
2017-01-13 14:22:09 +00:00
|
|
|
s32 __user *fence_ptr;
|
2016-11-16 13:00:21 +00:00
|
|
|
|
|
|
|
fence_ptr = state->crtcs[drm_crtc_index(crtc)].out_fence_ptr;
|
|
|
|
state->crtcs[drm_crtc_index(crtc)].out_fence_ptr = NULL;
|
|
|
|
|
|
|
|
return fence_ptr;
|
|
|
|
}
|
|
|
|
|
2015-05-26 13:36:48 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_set_mode_for_crtc - set mode for CRTC
|
|
|
|
* @state: the CRTC whose incoming state to update
|
|
|
|
* @mode: kernel-internal mode to use for the CRTC, or NULL to disable
|
|
|
|
*
|
2017-01-31 06:18:38 +00:00
|
|
|
* Set a mode (originating from the kernel) on the desired CRTC state and update
|
|
|
|
* the enable property.
|
2015-05-26 13:36:48 +00:00
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* Zero on success, error code on failure. Cannot return -EDEADLK.
|
|
|
|
*/
|
|
|
|
int drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
|
|
|
|
struct drm_display_mode *mode)
|
|
|
|
{
|
2015-05-25 18:11:51 +00:00
|
|
|
struct drm_mode_modeinfo umode;
|
|
|
|
|
2015-05-26 13:36:48 +00:00
|
|
|
/* Early return for no change. */
|
|
|
|
if (mode && memcmp(&state->mode, mode, sizeof(*mode)) == 0)
|
|
|
|
return 0;
|
|
|
|
|
2017-02-28 14:46:42 +00:00
|
|
|
drm_property_blob_put(state->mode_blob);
|
2015-05-25 18:11:51 +00:00
|
|
|
state->mode_blob = NULL;
|
|
|
|
|
2015-05-26 13:36:48 +00:00
|
|
|
if (mode) {
|
2015-05-25 18:11:51 +00:00
|
|
|
drm_mode_convert_to_umode(&umode, mode);
|
|
|
|
state->mode_blob =
|
|
|
|
drm_property_create_blob(state->crtc->dev,
|
|
|
|
sizeof(umode),
|
|
|
|
&umode);
|
|
|
|
if (IS_ERR(state->mode_blob))
|
|
|
|
return PTR_ERR(state->mode_blob);
|
|
|
|
|
2015-05-26 13:36:48 +00:00
|
|
|
drm_mode_copy(&state->mode, mode);
|
|
|
|
state->enable = true;
|
|
|
|
DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n",
|
|
|
|
mode->name, state);
|
|
|
|
} else {
|
|
|
|
memset(&state->mode, 0, sizeof(state->mode));
|
|
|
|
state->enable = false;
|
|
|
|
DRM_DEBUG_ATOMIC("Set [NOMODE] for CRTC state %p\n",
|
|
|
|
state);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_set_mode_for_crtc);
|
|
|
|
|
2015-05-25 18:11:52 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_set_mode_prop_for_crtc - set mode for CRTC
|
|
|
|
* @state: the CRTC whose incoming state to update
|
|
|
|
* @blob: pointer to blob property to use for mode
|
|
|
|
*
|
|
|
|
* Set a mode (originating from a blob property) on the desired CRTC state.
|
|
|
|
* This function will take a reference on the blob property for the CRTC state,
|
|
|
|
* and release the reference held on the state's existing mode property, if any
|
|
|
|
* was set.
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* Zero on success, error code on failure. Cannot return -EDEADLK.
|
|
|
|
*/
|
|
|
|
int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
|
|
|
|
struct drm_property_blob *blob)
|
|
|
|
{
|
|
|
|
if (blob == state->mode_blob)
|
|
|
|
return 0;
|
|
|
|
|
2017-02-28 14:46:42 +00:00
|
|
|
drm_property_blob_put(state->mode_blob);
|
2015-05-25 18:11:52 +00:00
|
|
|
state->mode_blob = NULL;
|
|
|
|
|
2016-05-31 12:03:17 +00:00
|
|
|
memset(&state->mode, 0, sizeof(state->mode));
|
|
|
|
|
2015-05-25 18:11:52 +00:00
|
|
|
if (blob) {
|
|
|
|
if (blob->length != sizeof(struct drm_mode_modeinfo) ||
|
|
|
|
drm_mode_convert_umode(&state->mode,
|
|
|
|
(const struct drm_mode_modeinfo *)
|
|
|
|
blob->data))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2017-02-28 14:46:42 +00:00
|
|
|
state->mode_blob = drm_property_blob_get(blob);
|
2015-05-25 18:11:52 +00:00
|
|
|
state->enable = true;
|
|
|
|
DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n",
|
|
|
|
state->mode.name, state);
|
|
|
|
} else {
|
|
|
|
state->enable = false;
|
|
|
|
DRM_DEBUG_ATOMIC("Set [NOMODE] for CRTC state %p\n",
|
|
|
|
state);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_set_mode_prop_for_crtc);
|
|
|
|
|
2016-02-26 17:05:00 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_replace_property_blob - replace a blob property
|
|
|
|
* @blob: a pointer to the member blob to be replaced
|
|
|
|
* @new_blob: the new blob to replace with
|
|
|
|
* @replaced: whether the blob has been replaced
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* Zero on success, error code on failure
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
drm_atomic_replace_property_blob(struct drm_property_blob **blob,
|
|
|
|
struct drm_property_blob *new_blob,
|
|
|
|
bool *replaced)
|
|
|
|
{
|
|
|
|
struct drm_property_blob *old_blob = *blob;
|
|
|
|
|
|
|
|
if (old_blob == new_blob)
|
|
|
|
return;
|
|
|
|
|
2017-02-28 14:46:42 +00:00
|
|
|
drm_property_blob_put(old_blob);
|
2016-02-26 17:05:00 +00:00
|
|
|
if (new_blob)
|
2017-02-28 14:46:42 +00:00
|
|
|
drm_property_blob_get(new_blob);
|
2016-02-26 17:05:00 +00:00
|
|
|
*blob = new_blob;
|
|
|
|
*replaced = true;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
drm_atomic_replace_property_blob_from_id(struct drm_crtc *crtc,
|
|
|
|
struct drm_property_blob **blob,
|
|
|
|
uint64_t blob_id,
|
|
|
|
ssize_t expected_size,
|
|
|
|
bool *replaced)
|
|
|
|
{
|
|
|
|
struct drm_property_blob *new_blob = NULL;
|
|
|
|
|
|
|
|
if (blob_id != 0) {
|
2016-10-25 21:28:08 +00:00
|
|
|
new_blob = drm_property_lookup_blob(crtc->dev, blob_id);
|
2016-02-26 17:05:00 +00:00
|
|
|
if (new_blob == NULL)
|
|
|
|
return -EINVAL;
|
2016-10-25 21:28:08 +00:00
|
|
|
|
|
|
|
if (expected_size > 0 && expected_size != new_blob->length) {
|
2017-02-28 14:46:42 +00:00
|
|
|
drm_property_blob_put(new_blob);
|
2016-02-26 17:05:00 +00:00
|
|
|
return -EINVAL;
|
2016-10-25 21:28:08 +00:00
|
|
|
}
|
2016-02-26 17:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
drm_atomic_replace_property_blob(blob, new_blob, replaced);
|
2017-02-28 14:46:42 +00:00
|
|
|
drm_property_blob_put(new_blob);
|
2016-02-26 17:05:00 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-18 21:01:46 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_crtc_set_property - set property on CRTC
|
|
|
|
* @crtc: the drm CRTC to set a property on
|
|
|
|
* @state: the state object to update with the new property value
|
|
|
|
* @property: the property to set
|
|
|
|
* @val: the new property value
|
|
|
|
*
|
2017-01-25 06:26:45 +00:00
|
|
|
* This function handles generic/core properties and calls out to driver's
|
|
|
|
* &drm_crtc_funcs.atomic_set_property for driver properties. To ensure
|
|
|
|
* consistent behavior you must call this function rather than the driver hook
|
|
|
|
* directly.
|
2014-12-18 21:01:46 +00:00
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* Zero on success, error code on failure
|
|
|
|
*/
|
|
|
|
int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
|
|
|
|
struct drm_crtc_state *state, struct drm_property *property,
|
|
|
|
uint64_t val)
|
|
|
|
{
|
2015-01-22 15:36:21 +00:00
|
|
|
struct drm_device *dev = crtc->dev;
|
|
|
|
struct drm_mode_config *config = &dev->mode_config;
|
2016-02-26 17:05:00 +00:00
|
|
|
bool replaced = false;
|
2015-05-25 18:11:52 +00:00
|
|
|
int ret;
|
2015-01-22 15:36:21 +00:00
|
|
|
|
2015-03-19 04:33:26 +00:00
|
|
|
if (property == config->prop_active)
|
2015-01-22 15:36:21 +00:00
|
|
|
state->active = val;
|
2015-05-25 18:11:52 +00:00
|
|
|
else if (property == config->prop_mode_id) {
|
|
|
|
struct drm_property_blob *mode =
|
|
|
|
drm_property_lookup_blob(dev, val);
|
|
|
|
ret = drm_atomic_set_mode_prop_for_crtc(state, mode);
|
2017-02-28 14:46:42 +00:00
|
|
|
drm_property_blob_put(mode);
|
2015-05-25 18:11:52 +00:00
|
|
|
return ret;
|
2016-02-26 17:05:00 +00:00
|
|
|
} else if (property == config->degamma_lut_property) {
|
|
|
|
ret = drm_atomic_replace_property_blob_from_id(crtc,
|
|
|
|
&state->degamma_lut,
|
|
|
|
val,
|
|
|
|
-1,
|
|
|
|
&replaced);
|
2016-08-26 23:02:28 +00:00
|
|
|
state->color_mgmt_changed |= replaced;
|
2016-02-26 17:05:00 +00:00
|
|
|
return ret;
|
|
|
|
} else if (property == config->ctm_property) {
|
|
|
|
ret = drm_atomic_replace_property_blob_from_id(crtc,
|
|
|
|
&state->ctm,
|
|
|
|
val,
|
|
|
|
sizeof(struct drm_color_ctm),
|
|
|
|
&replaced);
|
2016-08-26 23:02:28 +00:00
|
|
|
state->color_mgmt_changed |= replaced;
|
2016-02-26 17:05:00 +00:00
|
|
|
return ret;
|
|
|
|
} else if (property == config->gamma_lut_property) {
|
|
|
|
ret = drm_atomic_replace_property_blob_from_id(crtc,
|
|
|
|
&state->gamma_lut,
|
|
|
|
val,
|
|
|
|
-1,
|
|
|
|
&replaced);
|
2016-08-26 23:02:28 +00:00
|
|
|
state->color_mgmt_changed |= replaced;
|
2016-02-26 17:05:00 +00:00
|
|
|
return ret;
|
2016-11-16 13:00:21 +00:00
|
|
|
} else if (property == config->prop_out_fence_ptr) {
|
2017-01-13 14:22:09 +00:00
|
|
|
s32 __user *fence_ptr = u64_to_user_ptr(val);
|
2016-11-16 13:00:21 +00:00
|
|
|
|
|
|
|
if (!fence_ptr)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (put_user(-1, fence_ptr))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
set_out_fence_for_crtc(state->state, crtc, fence_ptr);
|
2016-02-26 17:05:00 +00:00
|
|
|
} else if (crtc->funcs->atomic_set_property)
|
2014-12-18 21:01:46 +00:00
|
|
|
return crtc->funcs->atomic_set_property(crtc, state, property, val);
|
2015-03-19 04:33:26 +00:00
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
2014-12-18 21:01:46 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_crtc_set_property);
|
|
|
|
|
2015-12-04 08:45:57 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_crtc_get_property - get property value from CRTC state
|
|
|
|
* @crtc: the drm CRTC to set a property on
|
|
|
|
* @state: the state object to get the property value from
|
|
|
|
* @property: the property to set
|
|
|
|
* @val: return location for the property value
|
|
|
|
*
|
2017-01-25 06:26:45 +00:00
|
|
|
* This function handles generic/core properties and calls out to driver's
|
|
|
|
* &drm_crtc_funcs.atomic_get_property for driver properties. To ensure
|
|
|
|
* consistent behavior you must call this function rather than the driver hook
|
|
|
|
* directly.
|
2015-12-04 08:45:57 +00:00
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* Zero on success, error code on failure
|
2014-12-18 21:01:47 +00:00
|
|
|
*/
|
2015-09-24 10:01:03 +00:00
|
|
|
static int
|
|
|
|
drm_atomic_crtc_get_property(struct drm_crtc *crtc,
|
2014-12-18 21:01:47 +00:00
|
|
|
const struct drm_crtc_state *state,
|
|
|
|
struct drm_property *property, uint64_t *val)
|
|
|
|
{
|
2015-03-19 04:33:25 +00:00
|
|
|
struct drm_device *dev = crtc->dev;
|
|
|
|
struct drm_mode_config *config = &dev->mode_config;
|
|
|
|
|
|
|
|
if (property == config->prop_active)
|
|
|
|
*val = state->active;
|
2015-05-25 18:11:52 +00:00
|
|
|
else if (property == config->prop_mode_id)
|
|
|
|
*val = (state->mode_blob) ? state->mode_blob->base.id : 0;
|
2016-02-26 17:05:00 +00:00
|
|
|
else if (property == config->degamma_lut_property)
|
|
|
|
*val = (state->degamma_lut) ? state->degamma_lut->base.id : 0;
|
|
|
|
else if (property == config->ctm_property)
|
|
|
|
*val = (state->ctm) ? state->ctm->base.id : 0;
|
|
|
|
else if (property == config->gamma_lut_property)
|
|
|
|
*val = (state->gamma_lut) ? state->gamma_lut->base.id : 0;
|
2016-11-16 13:00:21 +00:00
|
|
|
else if (property == config->prop_out_fence_ptr)
|
|
|
|
*val = 0;
|
2015-03-19 04:33:25 +00:00
|
|
|
else if (crtc->funcs->atomic_get_property)
|
2014-12-18 21:01:47 +00:00
|
|
|
return crtc->funcs->atomic_get_property(crtc, state, property, val);
|
2015-03-19 04:33:25 +00:00
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
2014-12-18 21:01:47 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 21:01:51 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_crtc_check - check crtc state
|
|
|
|
* @crtc: crtc to check
|
|
|
|
* @state: crtc state to check
|
|
|
|
*
|
|
|
|
* Provides core sanity checks for crtc state.
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* Zero on success, error code on failure
|
|
|
|
*/
|
|
|
|
static int drm_atomic_crtc_check(struct drm_crtc *crtc,
|
|
|
|
struct drm_crtc_state *state)
|
|
|
|
{
|
|
|
|
/* NOTE: we explicitly don't enforce constraints such as primary
|
|
|
|
* layer covering entire screen, since that is something we want
|
|
|
|
* to allow (on hw that supports it). For hw that does not, it
|
|
|
|
* should be checked in driver's crtc->atomic_check() vfunc.
|
|
|
|
*
|
|
|
|
* TODO: Add generic modeset state checks once we support those.
|
|
|
|
*/
|
2015-01-22 15:36:21 +00:00
|
|
|
|
|
|
|
if (state->active && !state->enable) {
|
2015-12-08 16:41:53 +00:00
|
|
|
DRM_DEBUG_ATOMIC("[CRTC:%d:%s] active without enabled\n",
|
|
|
|
crtc->base.id, crtc->name);
|
2015-01-22 15:36:21 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-05-25 18:11:51 +00:00
|
|
|
/* The state->enable vs. state->mode_blob checks can be WARN_ON,
|
|
|
|
* as this is a kernel-internal detail that userspace should never
|
|
|
|
* be able to trigger. */
|
|
|
|
if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) &&
|
|
|
|
WARN_ON(state->enable && !state->mode_blob)) {
|
2015-12-08 16:41:53 +00:00
|
|
|
DRM_DEBUG_ATOMIC("[CRTC:%d:%s] enabled without mode blob\n",
|
|
|
|
crtc->base.id, crtc->name);
|
2015-05-25 18:11:51 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) &&
|
|
|
|
WARN_ON(!state->enable && state->mode_blob)) {
|
2015-12-08 16:41:53 +00:00
|
|
|
DRM_DEBUG_ATOMIC("[CRTC:%d:%s] disabled with mode blob\n",
|
|
|
|
crtc->base.id, crtc->name);
|
2015-05-25 18:11:51 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-12-08 08:49:20 +00:00
|
|
|
/*
|
|
|
|
* Reject event generation for when a CRTC is off and stays off.
|
|
|
|
* It wouldn't be hard to implement this, but userspace has a track
|
|
|
|
* record of happily burning through 100% cpu (or worse, crash) when the
|
|
|
|
* display pipe is suspended. To avoid all that fun just reject updates
|
|
|
|
* that ask for events since likely that indicates a bug in the
|
|
|
|
* compositor's drawing loop. This is consistent with the vblank IOCTL
|
|
|
|
* and legacy page_flip IOCTL which also reject service on a disabled
|
|
|
|
* pipe.
|
|
|
|
*/
|
|
|
|
if (state->event && !state->active && !crtc->state->active) {
|
2017-02-13 12:27:03 +00:00
|
|
|
DRM_DEBUG_ATOMIC("[CRTC:%d:%s] requesting event but off\n",
|
|
|
|
crtc->base.id, crtc->name);
|
2015-12-08 08:49:20 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-12-18 21:01:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-05 15:08:09 +00:00
|
|
|
static void drm_atomic_crtc_print_state(struct drm_printer *p,
|
|
|
|
const struct drm_crtc_state *state)
|
|
|
|
{
|
|
|
|
struct drm_crtc *crtc = state->crtc;
|
|
|
|
|
|
|
|
drm_printf(p, "crtc[%u]: %s\n", crtc->base.id, crtc->name);
|
|
|
|
drm_printf(p, "\tenable=%d\n", state->enable);
|
|
|
|
drm_printf(p, "\tactive=%d\n", state->active);
|
|
|
|
drm_printf(p, "\tplanes_changed=%d\n", state->planes_changed);
|
|
|
|
drm_printf(p, "\tmode_changed=%d\n", state->mode_changed);
|
|
|
|
drm_printf(p, "\tactive_changed=%d\n", state->active_changed);
|
|
|
|
drm_printf(p, "\tconnectors_changed=%d\n", state->connectors_changed);
|
|
|
|
drm_printf(p, "\tcolor_mgmt_changed=%d\n", state->color_mgmt_changed);
|
|
|
|
drm_printf(p, "\tplane_mask=%x\n", state->plane_mask);
|
|
|
|
drm_printf(p, "\tconnector_mask=%x\n", state->connector_mask);
|
|
|
|
drm_printf(p, "\tencoder_mask=%x\n", state->encoder_mask);
|
|
|
|
drm_printf(p, "\tmode: " DRM_MODE_FMT "\n", DRM_MODE_ARG(&state->mode));
|
|
|
|
|
|
|
|
if (crtc->funcs->atomic_print_state)
|
|
|
|
crtc->funcs->atomic_print_state(p, state);
|
|
|
|
}
|
|
|
|
|
2014-07-25 19:30:38 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_get_plane_state - get plane state
|
|
|
|
* @state: global atomic state object
|
|
|
|
* @plane: plane to get state object for
|
|
|
|
*
|
|
|
|
* This function returns the plane state for the given plane, allocating it if
|
|
|
|
* needed. It will also grab the relevant plane lock to make sure that the state
|
|
|
|
* is consistent.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
*
|
|
|
|
* Either the allocated state or the error code encoded into the pointer. When
|
|
|
|
* the error is EDEADLK then the w/w mutex code has detected a deadlock and the
|
|
|
|
* entire atomic sequence must be restarted. All other errors are fatal.
|
|
|
|
*/
|
|
|
|
struct drm_plane_state *
|
|
|
|
drm_atomic_get_plane_state(struct drm_atomic_state *state,
|
|
|
|
struct drm_plane *plane)
|
|
|
|
{
|
2015-05-13 08:37:25 +00:00
|
|
|
int ret, index = drm_plane_index(plane);
|
2014-07-25 19:30:38 +00:00
|
|
|
struct drm_plane_state *plane_state;
|
|
|
|
|
2016-05-03 09:12:31 +00:00
|
|
|
WARN_ON(!state->acquire_ctx);
|
|
|
|
|
2015-05-13 08:37:25 +00:00
|
|
|
plane_state = drm_atomic_get_existing_plane_state(state, plane);
|
|
|
|
if (plane_state)
|
|
|
|
return plane_state;
|
2014-07-25 19:30:38 +00:00
|
|
|
|
2014-11-11 09:12:00 +00:00
|
|
|
ret = drm_modeset_lock(&plane->mutex, state->acquire_ctx);
|
2014-07-25 19:30:38 +00:00
|
|
|
if (ret)
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
|
|
|
|
plane_state = plane->funcs->atomic_duplicate_state(plane);
|
|
|
|
if (!plane_state)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2016-06-01 22:06:33 +00:00
|
|
|
state->planes[index].state = plane_state;
|
|
|
|
state->planes[index].ptr = plane;
|
2017-01-16 09:37:38 +00:00
|
|
|
state->planes[index].old_state = plane->state;
|
|
|
|
state->planes[index].new_state = plane_state;
|
2014-07-25 19:30:38 +00:00
|
|
|
plane_state->state = state;
|
|
|
|
|
2015-12-08 16:41:54 +00:00
|
|
|
DRM_DEBUG_ATOMIC("Added [PLANE:%d:%s] %p state to %p\n",
|
|
|
|
plane->base.id, plane->name, plane_state, state);
|
2014-07-25 19:30:38 +00:00
|
|
|
|
|
|
|
if (plane_state->crtc) {
|
|
|
|
struct drm_crtc_state *crtc_state;
|
|
|
|
|
|
|
|
crtc_state = drm_atomic_get_crtc_state(state,
|
|
|
|
plane_state->crtc);
|
|
|
|
if (IS_ERR(crtc_state))
|
|
|
|
return ERR_CAST(crtc_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
return plane_state;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_get_plane_state);
|
|
|
|
|
2014-12-18 21:01:46 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_plane_set_property - set property on plane
|
|
|
|
* @plane: the drm plane to set a property on
|
|
|
|
* @state: the state object to update with the new property value
|
|
|
|
* @property: the property to set
|
|
|
|
* @val: the new property value
|
|
|
|
*
|
2017-01-25 06:26:45 +00:00
|
|
|
* This function handles generic/core properties and calls out to driver's
|
|
|
|
* &drm_plane_funcs.atomic_set_property for driver properties. To ensure
|
|
|
|
* consistent behavior you must call this function rather than the driver hook
|
|
|
|
* directly.
|
2014-12-18 21:01:46 +00:00
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* Zero on success, error code on failure
|
|
|
|
*/
|
|
|
|
int drm_atomic_plane_set_property(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *state, struct drm_property *property,
|
|
|
|
uint64_t val)
|
|
|
|
{
|
2014-12-18 21:01:53 +00:00
|
|
|
struct drm_device *dev = plane->dev;
|
|
|
|
struct drm_mode_config *config = &dev->mode_config;
|
|
|
|
|
|
|
|
if (property == config->prop_fb_id) {
|
|
|
|
struct drm_framebuffer *fb = drm_framebuffer_lookup(dev, val);
|
|
|
|
drm_atomic_set_fb_for_plane(state, fb);
|
|
|
|
if (fb)
|
2017-02-28 14:46:40 +00:00
|
|
|
drm_framebuffer_put(fb);
|
2016-11-15 13:06:39 +00:00
|
|
|
} else if (property == config->prop_in_fence_fd) {
|
|
|
|
if (state->fence)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (U642I64(val) == -1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
state->fence = sync_file_get_fence(val);
|
|
|
|
if (!state->fence)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2014-12-18 21:01:53 +00:00
|
|
|
} else if (property == config->prop_crtc_id) {
|
|
|
|
struct drm_crtc *crtc = drm_crtc_find(dev, val);
|
|
|
|
return drm_atomic_set_crtc_for_plane(state, crtc);
|
|
|
|
} else if (property == config->prop_crtc_x) {
|
|
|
|
state->crtc_x = U642I64(val);
|
|
|
|
} else if (property == config->prop_crtc_y) {
|
|
|
|
state->crtc_y = U642I64(val);
|
|
|
|
} else if (property == config->prop_crtc_w) {
|
|
|
|
state->crtc_w = val;
|
|
|
|
} else if (property == config->prop_crtc_h) {
|
|
|
|
state->crtc_h = val;
|
|
|
|
} else if (property == config->prop_src_x) {
|
|
|
|
state->src_x = val;
|
|
|
|
} else if (property == config->prop_src_y) {
|
|
|
|
state->src_y = val;
|
|
|
|
} else if (property == config->prop_src_w) {
|
|
|
|
state->src_w = val;
|
|
|
|
} else if (property == config->prop_src_h) {
|
|
|
|
state->src_h = val;
|
2016-10-21 19:22:45 +00:00
|
|
|
} else if (property == plane->rotation_property) {
|
2016-09-26 16:30:47 +00:00
|
|
|
if (!is_power_of_2(val & DRM_ROTATE_MASK))
|
|
|
|
return -EINVAL;
|
2015-01-22 00:35:40 +00:00
|
|
|
state->rotation = val;
|
2016-06-13 09:11:26 +00:00
|
|
|
} else if (property == plane->zpos_property) {
|
|
|
|
state->zpos = val;
|
2014-12-18 21:01:53 +00:00
|
|
|
} else if (plane->funcs->atomic_set_property) {
|
|
|
|
return plane->funcs->atomic_set_property(plane, state,
|
|
|
|
property, val);
|
|
|
|
} else {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2014-12-18 21:01:46 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_plane_set_property);
|
|
|
|
|
2015-12-04 08:45:57 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_plane_get_property - get property value from plane state
|
|
|
|
* @plane: the drm plane to set a property on
|
|
|
|
* @state: the state object to get the property value from
|
|
|
|
* @property: the property to set
|
|
|
|
* @val: return location for the property value
|
|
|
|
*
|
2017-01-25 06:26:45 +00:00
|
|
|
* This function handles generic/core properties and calls out to driver's
|
|
|
|
* &drm_plane_funcs.atomic_get_property for driver properties. To ensure
|
|
|
|
* consistent behavior you must call this function rather than the driver hook
|
|
|
|
* directly.
|
2015-12-04 08:45:57 +00:00
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* Zero on success, error code on failure
|
2014-12-18 21:01:47 +00:00
|
|
|
*/
|
2014-12-18 21:49:02 +00:00
|
|
|
static int
|
|
|
|
drm_atomic_plane_get_property(struct drm_plane *plane,
|
2014-12-18 21:01:47 +00:00
|
|
|
const struct drm_plane_state *state,
|
|
|
|
struct drm_property *property, uint64_t *val)
|
|
|
|
{
|
2014-12-18 21:01:53 +00:00
|
|
|
struct drm_device *dev = plane->dev;
|
|
|
|
struct drm_mode_config *config = &dev->mode_config;
|
|
|
|
|
|
|
|
if (property == config->prop_fb_id) {
|
|
|
|
*val = (state->fb) ? state->fb->base.id : 0;
|
2016-11-15 13:06:39 +00:00
|
|
|
} else if (property == config->prop_in_fence_fd) {
|
|
|
|
*val = -1;
|
2014-12-18 21:01:53 +00:00
|
|
|
} else if (property == config->prop_crtc_id) {
|
|
|
|
*val = (state->crtc) ? state->crtc->base.id : 0;
|
|
|
|
} else if (property == config->prop_crtc_x) {
|
|
|
|
*val = I642U64(state->crtc_x);
|
|
|
|
} else if (property == config->prop_crtc_y) {
|
|
|
|
*val = I642U64(state->crtc_y);
|
|
|
|
} else if (property == config->prop_crtc_w) {
|
|
|
|
*val = state->crtc_w;
|
|
|
|
} else if (property == config->prop_crtc_h) {
|
|
|
|
*val = state->crtc_h;
|
|
|
|
} else if (property == config->prop_src_x) {
|
|
|
|
*val = state->src_x;
|
|
|
|
} else if (property == config->prop_src_y) {
|
|
|
|
*val = state->src_y;
|
|
|
|
} else if (property == config->prop_src_w) {
|
|
|
|
*val = state->src_w;
|
|
|
|
} else if (property == config->prop_src_h) {
|
|
|
|
*val = state->src_h;
|
2016-10-21 19:22:45 +00:00
|
|
|
} else if (property == plane->rotation_property) {
|
2015-02-26 13:49:17 +00:00
|
|
|
*val = state->rotation;
|
2016-06-13 09:11:26 +00:00
|
|
|
} else if (property == plane->zpos_property) {
|
|
|
|
*val = state->zpos;
|
2014-12-18 21:01:53 +00:00
|
|
|
} else if (plane->funcs->atomic_get_property) {
|
2014-12-18 21:01:47 +00:00
|
|
|
return plane->funcs->atomic_get_property(plane, state, property, val);
|
2014-12-18 21:01:53 +00:00
|
|
|
} else {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2014-12-18 21:01:47 +00:00
|
|
|
}
|
|
|
|
|
2015-08-26 19:49:42 +00:00
|
|
|
static bool
|
|
|
|
plane_switching_crtc(struct drm_atomic_state *state,
|
|
|
|
struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *plane_state)
|
|
|
|
{
|
|
|
|
if (!plane->state->crtc || !plane_state->crtc)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (plane->state->crtc == plane_state->crtc)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* This could be refined, but currently there's no helper or driver code
|
|
|
|
* to implement direct switching of active planes nor userspace to take
|
|
|
|
* advantage of more direct plane switching without the intermediate
|
|
|
|
* full OFF state.
|
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-18 21:01:51 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_plane_check - check plane state
|
|
|
|
* @plane: plane to check
|
|
|
|
* @state: plane state to check
|
|
|
|
*
|
|
|
|
* Provides core sanity checks for plane state.
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* Zero on success, error code on failure
|
|
|
|
*/
|
|
|
|
static int drm_atomic_plane_check(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *state)
|
|
|
|
{
|
|
|
|
unsigned int fb_width, fb_height;
|
2015-03-05 00:25:43 +00:00
|
|
|
int ret;
|
2014-12-18 21:01:51 +00:00
|
|
|
|
|
|
|
/* either *both* CRTC and FB must be set, or neither */
|
|
|
|
if (WARN_ON(state->crtc && !state->fb)) {
|
2015-02-22 11:24:16 +00:00
|
|
|
DRM_DEBUG_ATOMIC("CRTC set but no FB\n");
|
2014-12-18 21:01:51 +00:00
|
|
|
return -EINVAL;
|
|
|
|
} else if (WARN_ON(state->fb && !state->crtc)) {
|
2015-02-22 11:24:16 +00:00
|
|
|
DRM_DEBUG_ATOMIC("FB set but no CRTC\n");
|
2014-12-18 21:01:51 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if disabled, we don't care about the rest of the state: */
|
|
|
|
if (!state->crtc)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Check whether this plane is usable on this CRTC */
|
|
|
|
if (!(plane->possible_crtcs & drm_crtc_mask(state->crtc))) {
|
2015-02-22 11:24:16 +00:00
|
|
|
DRM_DEBUG_ATOMIC("Invalid crtc for plane\n");
|
2014-12-18 21:01:51 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check whether this plane supports the fb pixel format. */
|
2016-12-14 21:32:55 +00:00
|
|
|
ret = drm_plane_check_pixel_format(plane, state->fb->format->format);
|
2015-03-05 00:25:43 +00:00
|
|
|
if (ret) {
|
2016-11-12 01:12:56 +00:00
|
|
|
struct drm_format_name_buf format_name;
|
|
|
|
DRM_DEBUG_ATOMIC("Invalid pixel format %s\n",
|
2016-12-14 21:32:55 +00:00
|
|
|
drm_get_format_name(state->fb->format->format,
|
2016-11-12 01:12:56 +00:00
|
|
|
&format_name));
|
2015-03-05 00:25:43 +00:00
|
|
|
return ret;
|
2014-12-18 21:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Give drivers some help against integer overflows */
|
|
|
|
if (state->crtc_w > INT_MAX ||
|
|
|
|
state->crtc_x > INT_MAX - (int32_t) state->crtc_w ||
|
|
|
|
state->crtc_h > INT_MAX ||
|
|
|
|
state->crtc_y > INT_MAX - (int32_t) state->crtc_h) {
|
2015-02-22 11:24:16 +00:00
|
|
|
DRM_DEBUG_ATOMIC("Invalid CRTC coordinates %ux%u+%d+%d\n",
|
|
|
|
state->crtc_w, state->crtc_h,
|
|
|
|
state->crtc_x, state->crtc_y);
|
2014-12-18 21:01:51 +00:00
|
|
|
return -ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
fb_width = state->fb->width << 16;
|
|
|
|
fb_height = state->fb->height << 16;
|
|
|
|
|
|
|
|
/* Make sure source coordinates are inside the fb. */
|
|
|
|
if (state->src_w > fb_width ||
|
|
|
|
state->src_x > fb_width - state->src_w ||
|
|
|
|
state->src_h > fb_height ||
|
|
|
|
state->src_y > fb_height - state->src_h) {
|
2015-02-22 11:24:16 +00:00
|
|
|
DRM_DEBUG_ATOMIC("Invalid source coordinates "
|
|
|
|
"%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
|
|
|
|
state->src_w >> 16, ((state->src_w & 0xffff) * 15625) >> 10,
|
|
|
|
state->src_h >> 16, ((state->src_h & 0xffff) * 15625) >> 10,
|
|
|
|
state->src_x >> 16, ((state->src_x & 0xffff) * 15625) >> 10,
|
|
|
|
state->src_y >> 16, ((state->src_y & 0xffff) * 15625) >> 10);
|
2014-12-18 21:01:51 +00:00
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
|
2015-08-26 19:49:42 +00:00
|
|
|
if (plane_switching_crtc(state->state, plane, state)) {
|
2015-12-08 16:41:54 +00:00
|
|
|
DRM_DEBUG_ATOMIC("[PLANE:%d:%s] switching CRTC directly\n",
|
|
|
|
plane->base.id, plane->name);
|
2015-08-26 19:49:42 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-12-18 21:01:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-05 15:08:09 +00:00
|
|
|
static void drm_atomic_plane_print_state(struct drm_printer *p,
|
|
|
|
const struct drm_plane_state *state)
|
|
|
|
{
|
|
|
|
struct drm_plane *plane = state->plane;
|
|
|
|
struct drm_rect src = drm_plane_state_src(state);
|
|
|
|
struct drm_rect dest = drm_plane_state_dest(state);
|
|
|
|
|
|
|
|
drm_printf(p, "plane[%u]: %s\n", plane->base.id, plane->name);
|
|
|
|
drm_printf(p, "\tcrtc=%s\n", state->crtc ? state->crtc->name : "(null)");
|
|
|
|
drm_printf(p, "\tfb=%u\n", state->fb ? state->fb->base.id : 0);
|
|
|
|
if (state->fb) {
|
|
|
|
struct drm_framebuffer *fb = state->fb;
|
2016-12-14 21:30:22 +00:00
|
|
|
int i, n = fb->format->num_planes;
|
2016-11-12 01:12:56 +00:00
|
|
|
struct drm_format_name_buf format_name;
|
2016-11-05 15:08:09 +00:00
|
|
|
|
|
|
|
drm_printf(p, "\t\tformat=%s\n",
|
2016-12-14 21:32:55 +00:00
|
|
|
drm_get_format_name(fb->format->format, &format_name));
|
2016-11-16 11:33:16 +00:00
|
|
|
drm_printf(p, "\t\t\tmodifier=0x%llx\n", fb->modifier);
|
2016-11-05 15:08:09 +00:00
|
|
|
drm_printf(p, "\t\tsize=%dx%d\n", fb->width, fb->height);
|
|
|
|
drm_printf(p, "\t\tlayers:\n");
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
drm_printf(p, "\t\t\tpitch[%d]=%u\n", i, fb->pitches[i]);
|
|
|
|
drm_printf(p, "\t\t\toffset[%d]=%u\n", i, fb->offsets[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drm_printf(p, "\tcrtc-pos=" DRM_RECT_FMT "\n", DRM_RECT_ARG(&dest));
|
|
|
|
drm_printf(p, "\tsrc-pos=" DRM_RECT_FP_FMT "\n", DRM_RECT_FP_ARG(&src));
|
|
|
|
drm_printf(p, "\trotation=%x\n", state->rotation);
|
|
|
|
|
|
|
|
if (plane->funcs->atomic_print_state)
|
|
|
|
plane->funcs->atomic_print_state(p, state);
|
|
|
|
}
|
|
|
|
|
2014-07-25 19:30:38 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_get_connector_state - get connector state
|
|
|
|
* @state: global atomic state object
|
|
|
|
* @connector: connector to get state object for
|
|
|
|
*
|
|
|
|
* This function returns the connector state for the given connector,
|
|
|
|
* allocating it if needed. It will also grab the relevant connector lock to
|
|
|
|
* make sure that the state is consistent.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
*
|
|
|
|
* Either the allocated state or the error code encoded into the pointer. When
|
|
|
|
* the error is EDEADLK then the w/w mutex code has detected a deadlock and the
|
|
|
|
* entire atomic sequence must be restarted. All other errors are fatal.
|
|
|
|
*/
|
|
|
|
struct drm_connector_state *
|
|
|
|
drm_atomic_get_connector_state(struct drm_atomic_state *state,
|
|
|
|
struct drm_connector *connector)
|
|
|
|
{
|
|
|
|
int ret, index;
|
|
|
|
struct drm_mode_config *config = &connector->dev->mode_config;
|
|
|
|
struct drm_connector_state *connector_state;
|
|
|
|
|
2016-05-03 09:12:31 +00:00
|
|
|
WARN_ON(!state->acquire_ctx);
|
|
|
|
|
2014-11-19 17:38:06 +00:00
|
|
|
ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
|
|
|
|
if (ret)
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
|
2014-07-25 19:30:38 +00:00
|
|
|
index = drm_connector_index(connector);
|
|
|
|
|
2014-11-19 17:38:08 +00:00
|
|
|
if (index >= state->num_connector) {
|
2016-06-01 22:06:32 +00:00
|
|
|
struct __drm_connnectors_state *c;
|
2016-02-17 07:32:05 +00:00
|
|
|
int alloc = max(index + 1, config->num_connector);
|
|
|
|
|
|
|
|
c = krealloc(state->connectors, alloc * sizeof(*state->connectors), GFP_KERNEL);
|
|
|
|
if (!c)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
state->connectors = c;
|
|
|
|
memset(&state->connectors[state->num_connector], 0,
|
|
|
|
sizeof(*state->connectors) * (alloc - state->num_connector));
|
|
|
|
|
|
|
|
state->num_connector = alloc;
|
2014-11-19 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2016-06-01 22:06:32 +00:00
|
|
|
if (state->connectors[index].state)
|
|
|
|
return state->connectors[index].state;
|
2014-07-25 19:30:38 +00:00
|
|
|
|
|
|
|
connector_state = connector->funcs->atomic_duplicate_state(connector);
|
|
|
|
if (!connector_state)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2017-02-28 14:46:39 +00:00
|
|
|
drm_connector_get(connector);
|
2016-06-01 22:06:32 +00:00
|
|
|
state->connectors[index].state = connector_state;
|
2017-01-16 09:37:38 +00:00
|
|
|
state->connectors[index].old_state = connector->state;
|
|
|
|
state->connectors[index].new_state = connector_state;
|
2016-06-01 22:06:32 +00:00
|
|
|
state->connectors[index].ptr = connector;
|
2014-07-25 19:30:38 +00:00
|
|
|
connector_state->state = state;
|
|
|
|
|
2017-02-13 12:27:03 +00:00
|
|
|
DRM_DEBUG_ATOMIC("Added [CONNECTOR:%d:%s] %p state to %p\n",
|
|
|
|
connector->base.id, connector->name,
|
|
|
|
connector_state, state);
|
2014-07-25 19:30:38 +00:00
|
|
|
|
|
|
|
if (connector_state->crtc) {
|
|
|
|
struct drm_crtc_state *crtc_state;
|
|
|
|
|
|
|
|
crtc_state = drm_atomic_get_crtc_state(state,
|
|
|
|
connector_state->crtc);
|
|
|
|
if (IS_ERR(crtc_state))
|
|
|
|
return ERR_CAST(crtc_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
return connector_state;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_get_connector_state);
|
|
|
|
|
2014-12-18 21:01:46 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_connector_set_property - set property on connector.
|
|
|
|
* @connector: the drm connector to set a property on
|
|
|
|
* @state: the state object to update with the new property value
|
|
|
|
* @property: the property to set
|
|
|
|
* @val: the new property value
|
|
|
|
*
|
2017-01-25 06:26:45 +00:00
|
|
|
* This function handles generic/core properties and calls out to driver's
|
|
|
|
* &drm_connector_funcs.atomic_set_property for driver properties. To ensure
|
|
|
|
* consistent behavior you must call this function rather than the driver hook
|
|
|
|
* directly.
|
2014-12-18 21:01:46 +00:00
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* Zero on success, error code on failure
|
|
|
|
*/
|
|
|
|
int drm_atomic_connector_set_property(struct drm_connector *connector,
|
|
|
|
struct drm_connector_state *state, struct drm_property *property,
|
|
|
|
uint64_t val)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = connector->dev;
|
|
|
|
struct drm_mode_config *config = &dev->mode_config;
|
|
|
|
|
2014-12-18 21:01:54 +00:00
|
|
|
if (property == config->prop_crtc_id) {
|
|
|
|
struct drm_crtc *crtc = drm_crtc_find(dev, val);
|
|
|
|
return drm_atomic_set_crtc_for_connector(state, crtc);
|
|
|
|
} else if (property == config->dpms_property) {
|
2014-12-18 21:01:46 +00:00
|
|
|
/* setting DPMS property requires special handling, which
|
|
|
|
* is done in legacy setprop path for us. Disallow (for
|
|
|
|
* now?) atomic writes to DPMS property:
|
|
|
|
*/
|
|
|
|
return -EINVAL;
|
2016-12-02 13:48:09 +00:00
|
|
|
} else if (property == config->tv_select_subconnector_property) {
|
|
|
|
state->tv.subconnector = val;
|
|
|
|
} else if (property == config->tv_left_margin_property) {
|
|
|
|
state->tv.margins.left = val;
|
|
|
|
} else if (property == config->tv_right_margin_property) {
|
|
|
|
state->tv.margins.right = val;
|
|
|
|
} else if (property == config->tv_top_margin_property) {
|
|
|
|
state->tv.margins.top = val;
|
|
|
|
} else if (property == config->tv_bottom_margin_property) {
|
|
|
|
state->tv.margins.bottom = val;
|
|
|
|
} else if (property == config->tv_mode_property) {
|
|
|
|
state->tv.mode = val;
|
|
|
|
} else if (property == config->tv_brightness_property) {
|
|
|
|
state->tv.brightness = val;
|
|
|
|
} else if (property == config->tv_contrast_property) {
|
|
|
|
state->tv.contrast = val;
|
|
|
|
} else if (property == config->tv_flicker_reduction_property) {
|
|
|
|
state->tv.flicker_reduction = val;
|
|
|
|
} else if (property == config->tv_overscan_property) {
|
|
|
|
state->tv.overscan = val;
|
|
|
|
} else if (property == config->tv_saturation_property) {
|
|
|
|
state->tv.saturation = val;
|
|
|
|
} else if (property == config->tv_hue_property) {
|
|
|
|
state->tv.hue = val;
|
drm: Add a new connector atomic property for link status
At the time userspace does setcrtc, we've already promised the mode
would work. The promise is based on the theoretical capabilities of
the link, but it's possible we can't reach this in practice. The DP
spec describes how the link should be reduced, but we can't reduce
the link below the requirements of the mode. Black screen follows.
One idea would be to have setcrtc return a failure. However, it
already should not fail as the atomic checks have passed. It would
also conflict with the idea of making setcrtc asynchronous in the
future, returning before the actual mode setting and link training.
Another idea is to train the link "upfront" at hotplug time, before
pruning the mode list, so that we can do the pruning based on
practical not theoretical capabilities. However, the changes for link
training are pretty drastic, all for the sake of error handling and
DP compliance, when the most common happy day scenario is the current
approach of link training at mode setting time, using the optimal
parameters for the mode. It is also not certain all hardware could do
this without the pipe on; not even all our hardware can do this. Some
of this can be solved, but not trivially.
Both of the above ideas also fail to address link degradation *during*
operation.
The solution is to add a new "link-status" connector property in order
to address link training failure in a way that:
a) changes the current happy day scenario as little as possible, to
avoid regressions, b) can be implemented the same way by all drm
drivers, c) is still opt-in for the drivers and userspace, and opting
out doesn't regress the user experience, d) doesn't prevent drivers
from implementing better or alternate approaches, possibly without
userspace involvement. And, of course, handles all the issues presented.
In the usual happy day scenario, this is always "good". If something
fails during or after a mode set, the kernel driver can set the link
status to "bad" and issue a hotplug uevent for userspace to have it
re-check the valid modes through GET_CONNECTOR IOCTL, and try modeset
again. If the theoretical capabilities of the link can't be reached,
the mode list is trimmed based on that.
v7 by Jani:
* Rebase, simplify set property while at it, checkpatch fix
v6:
* Fix a typo in kernel doc (Sean Paul)
v5:
* Clarify doc for silent rejection of atomic properties by driver (Daniel Vetter)
v4:
* Add comments in kernel-doc format (Daniel Vetter)
* Update the kernel-doc for link-status (Sean Paul)
v3:
* Fixed a build error (Jani Saarinen)
v2:
* Removed connector->link_status (Daniel Vetter)
* Set connector->state->link_status in drm_mode_connector_set_link_status_property
(Daniel Vetter)
* Set the connector_changed flag to true if connector->state->link_status changed.
* Reset link_status to GOOD in update_output_state (Daniel Vetter)
* Never allow userspace to set link status from Good To Bad (Daniel Vetter)
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
Acked-by: Tony Cheng <tony.cheng@amd.com>
Acked-by: Harry Wentland <harry.wentland@amd.com>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Daniel Vetter <daniel.vetter@intel.com>
Cc: Ville Syrjala <ville.syrjala@linux.intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Manasi Navare <manasi.d.navare@intel.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Acked-by: Eric Anholt <eric@anholt.net> (for the -modesetting patch)
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/0182487051aa9f1594820e35a4853de2f8747b4e.1481883920.git.jani.nikula@intel.com
2016-12-16 10:29:06 +00:00
|
|
|
} else if (property == config->link_status_property) {
|
|
|
|
/* Never downgrade from GOOD to BAD on userspace's request here,
|
|
|
|
* only hw issues can do that.
|
|
|
|
*
|
|
|
|
* For an atomic property the userspace doesn't need to be able
|
|
|
|
* to understand all the properties, but needs to be able to
|
|
|
|
* restore the state it wants on VT switch. So if the userspace
|
|
|
|
* tries to change the link_status from GOOD to BAD, driver
|
|
|
|
* silently rejects it and returns a 0. This prevents userspace
|
|
|
|
* from accidently breaking the display when it restores the
|
|
|
|
* state.
|
|
|
|
*/
|
|
|
|
if (state->link_status != DRM_LINK_STATUS_GOOD)
|
|
|
|
state->link_status = val;
|
2014-12-18 21:01:46 +00:00
|
|
|
} else if (connector->funcs->atomic_set_property) {
|
|
|
|
return connector->funcs->atomic_set_property(connector,
|
|
|
|
state, property, val);
|
|
|
|
} else {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2016-12-02 13:48:09 +00:00
|
|
|
|
|
|
|
return 0;
|
2014-12-18 21:01:46 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_connector_set_property);
|
|
|
|
|
2016-11-05 15:08:09 +00:00
|
|
|
static void drm_atomic_connector_print_state(struct drm_printer *p,
|
|
|
|
const struct drm_connector_state *state)
|
|
|
|
{
|
|
|
|
struct drm_connector *connector = state->connector;
|
|
|
|
|
|
|
|
drm_printf(p, "connector[%u]: %s\n", connector->base.id, connector->name);
|
|
|
|
drm_printf(p, "\tcrtc=%s\n", state->crtc ? state->crtc->name : "(null)");
|
|
|
|
|
|
|
|
if (connector->funcs->atomic_print_state)
|
|
|
|
connector->funcs->atomic_print_state(p, state);
|
|
|
|
}
|
|
|
|
|
2015-12-04 08:45:57 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_connector_get_property - get property value from connector state
|
|
|
|
* @connector: the drm connector to set a property on
|
|
|
|
* @state: the state object to get the property value from
|
|
|
|
* @property: the property to set
|
|
|
|
* @val: return location for the property value
|
|
|
|
*
|
2017-01-25 06:26:45 +00:00
|
|
|
* This function handles generic/core properties and calls out to driver's
|
|
|
|
* &drm_connector_funcs.atomic_get_property for driver properties. To ensure
|
|
|
|
* consistent behavior you must call this function rather than the driver hook
|
|
|
|
* directly.
|
2015-12-04 08:45:57 +00:00
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* Zero on success, error code on failure
|
2014-12-18 21:01:47 +00:00
|
|
|
*/
|
2014-12-18 21:49:02 +00:00
|
|
|
static int
|
|
|
|
drm_atomic_connector_get_property(struct drm_connector *connector,
|
2014-12-18 21:01:47 +00:00
|
|
|
const struct drm_connector_state *state,
|
|
|
|
struct drm_property *property, uint64_t *val)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = connector->dev;
|
|
|
|
struct drm_mode_config *config = &dev->mode_config;
|
|
|
|
|
2014-12-18 21:01:54 +00:00
|
|
|
if (property == config->prop_crtc_id) {
|
|
|
|
*val = (state->crtc) ? state->crtc->base.id : 0;
|
|
|
|
} else if (property == config->dpms_property) {
|
2014-12-18 21:01:47 +00:00
|
|
|
*val = connector->dpms;
|
2016-12-02 13:48:09 +00:00
|
|
|
} else if (property == config->tv_select_subconnector_property) {
|
|
|
|
*val = state->tv.subconnector;
|
|
|
|
} else if (property == config->tv_left_margin_property) {
|
|
|
|
*val = state->tv.margins.left;
|
|
|
|
} else if (property == config->tv_right_margin_property) {
|
|
|
|
*val = state->tv.margins.right;
|
|
|
|
} else if (property == config->tv_top_margin_property) {
|
|
|
|
*val = state->tv.margins.top;
|
|
|
|
} else if (property == config->tv_bottom_margin_property) {
|
|
|
|
*val = state->tv.margins.bottom;
|
|
|
|
} else if (property == config->tv_mode_property) {
|
|
|
|
*val = state->tv.mode;
|
|
|
|
} else if (property == config->tv_brightness_property) {
|
|
|
|
*val = state->tv.brightness;
|
|
|
|
} else if (property == config->tv_contrast_property) {
|
|
|
|
*val = state->tv.contrast;
|
|
|
|
} else if (property == config->tv_flicker_reduction_property) {
|
|
|
|
*val = state->tv.flicker_reduction;
|
|
|
|
} else if (property == config->tv_overscan_property) {
|
|
|
|
*val = state->tv.overscan;
|
|
|
|
} else if (property == config->tv_saturation_property) {
|
|
|
|
*val = state->tv.saturation;
|
|
|
|
} else if (property == config->tv_hue_property) {
|
|
|
|
*val = state->tv.hue;
|
drm: Add a new connector atomic property for link status
At the time userspace does setcrtc, we've already promised the mode
would work. The promise is based on the theoretical capabilities of
the link, but it's possible we can't reach this in practice. The DP
spec describes how the link should be reduced, but we can't reduce
the link below the requirements of the mode. Black screen follows.
One idea would be to have setcrtc return a failure. However, it
already should not fail as the atomic checks have passed. It would
also conflict with the idea of making setcrtc asynchronous in the
future, returning before the actual mode setting and link training.
Another idea is to train the link "upfront" at hotplug time, before
pruning the mode list, so that we can do the pruning based on
practical not theoretical capabilities. However, the changes for link
training are pretty drastic, all for the sake of error handling and
DP compliance, when the most common happy day scenario is the current
approach of link training at mode setting time, using the optimal
parameters for the mode. It is also not certain all hardware could do
this without the pipe on; not even all our hardware can do this. Some
of this can be solved, but not trivially.
Both of the above ideas also fail to address link degradation *during*
operation.
The solution is to add a new "link-status" connector property in order
to address link training failure in a way that:
a) changes the current happy day scenario as little as possible, to
avoid regressions, b) can be implemented the same way by all drm
drivers, c) is still opt-in for the drivers and userspace, and opting
out doesn't regress the user experience, d) doesn't prevent drivers
from implementing better or alternate approaches, possibly without
userspace involvement. And, of course, handles all the issues presented.
In the usual happy day scenario, this is always "good". If something
fails during or after a mode set, the kernel driver can set the link
status to "bad" and issue a hotplug uevent for userspace to have it
re-check the valid modes through GET_CONNECTOR IOCTL, and try modeset
again. If the theoretical capabilities of the link can't be reached,
the mode list is trimmed based on that.
v7 by Jani:
* Rebase, simplify set property while at it, checkpatch fix
v6:
* Fix a typo in kernel doc (Sean Paul)
v5:
* Clarify doc for silent rejection of atomic properties by driver (Daniel Vetter)
v4:
* Add comments in kernel-doc format (Daniel Vetter)
* Update the kernel-doc for link-status (Sean Paul)
v3:
* Fixed a build error (Jani Saarinen)
v2:
* Removed connector->link_status (Daniel Vetter)
* Set connector->state->link_status in drm_mode_connector_set_link_status_property
(Daniel Vetter)
* Set the connector_changed flag to true if connector->state->link_status changed.
* Reset link_status to GOOD in update_output_state (Daniel Vetter)
* Never allow userspace to set link status from Good To Bad (Daniel Vetter)
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
Acked-by: Tony Cheng <tony.cheng@amd.com>
Acked-by: Harry Wentland <harry.wentland@amd.com>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Daniel Vetter <daniel.vetter@intel.com>
Cc: Ville Syrjala <ville.syrjala@linux.intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Manasi Navare <manasi.d.navare@intel.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Acked-by: Eric Anholt <eric@anholt.net> (for the -modesetting patch)
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/0182487051aa9f1594820e35a4853de2f8747b4e.1481883920.git.jani.nikula@intel.com
2016-12-16 10:29:06 +00:00
|
|
|
} else if (property == config->link_status_property) {
|
|
|
|
*val = state->link_status;
|
2014-12-18 21:01:47 +00:00
|
|
|
} else if (connector->funcs->atomic_get_property) {
|
|
|
|
return connector->funcs->atomic_get_property(connector,
|
|
|
|
state, property, val);
|
|
|
|
} else {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-18 21:01:50 +00:00
|
|
|
int drm_atomic_get_property(struct drm_mode_object *obj,
|
|
|
|
struct drm_property *property, uint64_t *val)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = property->dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (obj->type) {
|
|
|
|
case DRM_MODE_OBJECT_CONNECTOR: {
|
|
|
|
struct drm_connector *connector = obj_to_connector(obj);
|
|
|
|
WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
|
|
|
|
ret = drm_atomic_connector_get_property(connector,
|
|
|
|
connector->state, property, val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DRM_MODE_OBJECT_CRTC: {
|
|
|
|
struct drm_crtc *crtc = obj_to_crtc(obj);
|
|
|
|
WARN_ON(!drm_modeset_is_locked(&crtc->mutex));
|
|
|
|
ret = drm_atomic_crtc_get_property(crtc,
|
|
|
|
crtc->state, property, val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DRM_MODE_OBJECT_PLANE: {
|
|
|
|
struct drm_plane *plane = obj_to_plane(obj);
|
|
|
|
WARN_ON(!drm_modeset_is_locked(&plane->mutex));
|
|
|
|
ret = drm_atomic_plane_get_property(plane,
|
|
|
|
plane->state, property, val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-07-25 19:30:38 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_set_crtc_for_plane - set crtc for plane
|
2014-11-27 14:49:39 +00:00
|
|
|
* @plane_state: the plane whose incoming state to update
|
2014-07-25 19:30:38 +00:00
|
|
|
* @crtc: crtc to use for the plane
|
|
|
|
*
|
|
|
|
* Changing the assigned crtc for a plane requires us to grab the lock and state
|
|
|
|
* for the new crtc, as needed. This function takes care of all these details
|
|
|
|
* besides updating the pointer in the state object itself.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
|
|
|
|
* then the w/w mutex code has detected a deadlock and the entire atomic
|
|
|
|
* sequence must be restarted. All other errors are fatal.
|
|
|
|
*/
|
|
|
|
int
|
2014-11-27 14:49:39 +00:00
|
|
|
drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state,
|
|
|
|
struct drm_crtc *crtc)
|
2014-07-25 19:30:38 +00:00
|
|
|
{
|
2014-11-27 14:49:39 +00:00
|
|
|
struct drm_plane *plane = plane_state->plane;
|
2014-07-25 19:30:38 +00:00
|
|
|
struct drm_crtc_state *crtc_state;
|
|
|
|
|
2014-11-21 20:28:31 +00:00
|
|
|
if (plane_state->crtc) {
|
|
|
|
crtc_state = drm_atomic_get_crtc_state(plane_state->state,
|
|
|
|
plane_state->crtc);
|
|
|
|
if (WARN_ON(IS_ERR(crtc_state)))
|
|
|
|
return PTR_ERR(crtc_state);
|
|
|
|
|
|
|
|
crtc_state->plane_mask &= ~(1 << drm_plane_index(plane));
|
|
|
|
}
|
|
|
|
|
|
|
|
plane_state->crtc = crtc;
|
|
|
|
|
2014-07-25 19:30:38 +00:00
|
|
|
if (crtc) {
|
|
|
|
crtc_state = drm_atomic_get_crtc_state(plane_state->state,
|
|
|
|
crtc);
|
|
|
|
if (IS_ERR(crtc_state))
|
|
|
|
return PTR_ERR(crtc_state);
|
2014-11-21 20:28:31 +00:00
|
|
|
crtc_state->plane_mask |= (1 << drm_plane_index(plane));
|
2014-07-25 19:30:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (crtc)
|
2015-12-08 16:41:53 +00:00
|
|
|
DRM_DEBUG_ATOMIC("Link plane state %p to [CRTC:%d:%s]\n",
|
|
|
|
plane_state, crtc->base.id, crtc->name);
|
2014-07-25 19:30:38 +00:00
|
|
|
else
|
2015-02-22 11:24:16 +00:00
|
|
|
DRM_DEBUG_ATOMIC("Link plane state %p to [NOCRTC]\n",
|
|
|
|
plane_state);
|
2014-07-25 19:30:38 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_set_crtc_for_plane);
|
|
|
|
|
2014-11-04 21:57:27 +00:00
|
|
|
/**
|
2015-04-07 11:38:50 +00:00
|
|
|
* drm_atomic_set_fb_for_plane - set framebuffer for plane
|
2014-11-04 21:57:27 +00:00
|
|
|
* @plane_state: atomic state object for the plane
|
|
|
|
* @fb: fb to use for the plane
|
|
|
|
*
|
|
|
|
* Changing the assigned framebuffer for a plane requires us to grab a reference
|
|
|
|
* to the new fb and drop the reference to the old fb, if there is one. This
|
|
|
|
* function takes care of all these details besides updating the pointer in the
|
|
|
|
* state object itself.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state,
|
|
|
|
struct drm_framebuffer *fb)
|
|
|
|
{
|
|
|
|
if (fb)
|
2015-02-22 11:24:16 +00:00
|
|
|
DRM_DEBUG_ATOMIC("Set [FB:%d] for plane state %p\n",
|
|
|
|
fb->base.id, plane_state);
|
2014-11-04 21:57:27 +00:00
|
|
|
else
|
2015-02-22 11:24:16 +00:00
|
|
|
DRM_DEBUG_ATOMIC("Set [NOFB] for plane state %p\n",
|
|
|
|
plane_state);
|
2016-11-25 15:32:30 +00:00
|
|
|
|
|
|
|
drm_framebuffer_assign(&plane_state->fb, fb);
|
2014-11-04 21:57:27 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_set_fb_for_plane);
|
|
|
|
|
2016-11-07 10:03:30 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_set_fence_for_plane - set fence for plane
|
|
|
|
* @plane_state: atomic state object for the plane
|
|
|
|
* @fence: dma_fence to use for the plane
|
|
|
|
*
|
|
|
|
* Helper to setup the plane_state fence in case it is not set yet.
|
|
|
|
* By using this drivers doesn't need to worry if the user choose
|
|
|
|
* implicit or explicit fencing.
|
|
|
|
*
|
|
|
|
* This function will not set the fence to the state if it was set
|
2017-01-25 06:26:45 +00:00
|
|
|
* via explicit fencing interfaces on the atomic ioctl. In that case it will
|
|
|
|
* drop the reference to the fence as we are not storing it anywhere.
|
|
|
|
* Otherwise, if &drm_plane_state.fence is not set this function we just set it
|
|
|
|
* with the received implicit fence. In both cases this function consumes a
|
|
|
|
* reference for @fence.
|
2016-11-07 10:03:30 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
drm_atomic_set_fence_for_plane(struct drm_plane_state *plane_state,
|
|
|
|
struct dma_fence *fence)
|
|
|
|
{
|
|
|
|
if (plane_state->fence) {
|
|
|
|
dma_fence_put(fence);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
plane_state->fence = fence;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_set_fence_for_plane);
|
|
|
|
|
2014-07-25 19:30:38 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_set_crtc_for_connector - set crtc for connector
|
|
|
|
* @conn_state: atomic state object for the connector
|
|
|
|
* @crtc: crtc to use for the connector
|
|
|
|
*
|
|
|
|
* Changing the assigned crtc for a connector requires us to grab the lock and
|
|
|
|
* state for the new crtc, as needed. This function takes care of all these
|
|
|
|
* details besides updating the pointer in the state object itself.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
|
|
|
|
* then the w/w mutex code has detected a deadlock and the entire atomic
|
|
|
|
* sequence must be restarted. All other errors are fatal.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
|
|
|
|
struct drm_crtc *crtc)
|
|
|
|
{
|
|
|
|
struct drm_crtc_state *crtc_state;
|
|
|
|
|
2016-05-06 11:47:45 +00:00
|
|
|
if (conn_state->crtc == crtc)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (conn_state->crtc) {
|
2017-03-01 09:22:10 +00:00
|
|
|
crtc_state = drm_atomic_get_new_crtc_state(conn_state->state,
|
|
|
|
conn_state->crtc);
|
2016-01-04 11:53:18 +00:00
|
|
|
|
|
|
|
crtc_state->connector_mask &=
|
|
|
|
~(1 << drm_connector_index(conn_state->connector));
|
2016-05-06 11:47:45 +00:00
|
|
|
|
2017-02-28 14:46:39 +00:00
|
|
|
drm_connector_put(conn_state->connector);
|
2016-05-06 11:47:45 +00:00
|
|
|
conn_state->crtc = NULL;
|
2016-01-04 11:53:18 +00:00
|
|
|
}
|
|
|
|
|
2014-07-25 19:30:38 +00:00
|
|
|
if (crtc) {
|
|
|
|
crtc_state = drm_atomic_get_crtc_state(conn_state->state, crtc);
|
|
|
|
if (IS_ERR(crtc_state))
|
|
|
|
return PTR_ERR(crtc_state);
|
2016-01-04 11:53:18 +00:00
|
|
|
|
|
|
|
crtc_state->connector_mask |=
|
|
|
|
1 << drm_connector_index(conn_state->connector);
|
2014-07-25 19:30:38 +00:00
|
|
|
|
2017-02-28 14:46:39 +00:00
|
|
|
drm_connector_get(conn_state->connector);
|
2016-05-06 11:47:45 +00:00
|
|
|
conn_state->crtc = crtc;
|
2014-07-25 19:30:38 +00:00
|
|
|
|
2015-12-08 16:41:53 +00:00
|
|
|
DRM_DEBUG_ATOMIC("Link connector state %p to [CRTC:%d:%s]\n",
|
|
|
|
conn_state, crtc->base.id, crtc->name);
|
2016-05-06 11:47:45 +00:00
|
|
|
} else {
|
2015-02-22 11:24:16 +00:00
|
|
|
DRM_DEBUG_ATOMIC("Link connector state %p to [NOCRTC]\n",
|
|
|
|
conn_state);
|
2016-05-06 11:47:45 +00:00
|
|
|
}
|
2014-07-25 19:30:38 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_set_crtc_for_connector);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_atomic_add_affected_connectors - add connectors for crtc
|
|
|
|
* @state: atomic state
|
|
|
|
* @crtc: DRM crtc
|
|
|
|
*
|
|
|
|
* This function walks the current configuration and adds all connectors
|
|
|
|
* currently using @crtc to the atomic configuration @state. Note that this
|
|
|
|
* function must acquire the connection mutex. This can potentially cause
|
|
|
|
* unneeded seralization if the update is just for the planes on one crtc. Hence
|
|
|
|
* drivers and helpers should only call this when really needed (e.g. when a
|
|
|
|
* full modeset needs to happen due to some change).
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
|
|
|
|
* then the w/w mutex code has detected a deadlock and the entire atomic
|
|
|
|
* sequence must be restarted. All other errors are fatal.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
|
|
|
|
struct drm_crtc *crtc)
|
|
|
|
{
|
|
|
|
struct drm_mode_config *config = &state->dev->mode_config;
|
|
|
|
struct drm_connector *connector;
|
|
|
|
struct drm_connector_state *conn_state;
|
drm: locking&new iterators for connector_list
The requirements for connector_list locking are a bit tricky:
- We need to be able to jump over zombie conectors (i.e. with refcount
== 0, but not yet removed from the list). If instead we require that
there's no zombies on the list then the final kref_put must happen
under the list protection lock, which means that locking context
leaks all over the place. Not pretty - better to deal with zombies
and wrap the locking just around the list_del in the destructor.
- When we walk the list we must _not_ hold the connector list lock. We
walk the connector list at an absolutely massive amounts of places,
if all those places can't ever call drm_connector_unreference the
code would get unecessarily complicated.
- connector_list needs it own lock, again too many places that walk it
that we could reuse e.g. mode_config.mutex without resulting in
inversions.
- Lots of code uses these loops to look-up a connector, i.e. they want
to be able to call drm_connector_reference. But on the other hand we
want connectors to stay on that list until they're dead (i.e.
connector_list can't hold a full reference), which means despite the
"can't hold lock for the loop body" rule we need to make sure a
connector doesn't suddenly become a zombie.
At first Dave&I discussed various horror-show approaches using srcu,
but turns out it's fairly easy:
- For the loop body we always hold an additional reference to the
current connector. That means it can't zombify, and it also means
it'll stay on the list, which means we can use it as our iterator to
find the next connector.
- When we try to find the next connector we only have to jump over
zombies. To make sure we don't chase bad pointers that entire loop
is protected with the new connect_list_lock spinlock. And because we
know that we're starting out with a non-zombie (need to drop our
reference for the old connector only after we have our new one),
we're guranteed to still be on the connector_list and either find
the next non-zombie or complete the iteration.
- Only downside is that we need to make sure that the temporary
reference for the loop body doesn't leak. iter_get/put() functions +
lockdep make sure that's the case.
- To avoid a flag day the new iterator macro has an _iter postfix. We
can rename it back once all the users of the unsafe version are gone
(there's about 100 list walkers for the connector_list).
For now this patch only converts all the list walking in the core,
leaving helpers and drivers for later patches. The nice thing is that
we can now finally remove 2 FIXME comments from the
register/unregister functions.
v2:
- use irqsafe spinlocks, so that we can use this in drm_state_dump
too.
- nuke drm_modeset_lock_all from drm_connector_init, now entirely
cargo-culted nonsense.
v3:
- do {} while (!kref_get_unless_zero), makes for a tidier loop (Dave).
- pretty kerneldoc
- add EXPORT_SYMBOL, helpers&drivers are supposed to use this.
v4: Change lockdep annotations to only check whether we release the
iter fake lock again (i.e. make sure that iter_put is called), but
not check any locking dependecies itself. That seams to require a
recursive read lock in trylock mode.
Cc: Dave Airlie <airlied@gmail.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20161213230814.19598-6-daniel.vetter@ffwll.ch
2016-12-13 23:08:06 +00:00
|
|
|
struct drm_connector_list_iter conn_iter;
|
2017-01-16 09:37:39 +00:00
|
|
|
struct drm_crtc_state *crtc_state;
|
2014-07-25 19:30:38 +00:00
|
|
|
int ret;
|
|
|
|
|
2017-01-16 09:37:39 +00:00
|
|
|
crtc_state = drm_atomic_get_crtc_state(state, crtc);
|
|
|
|
if (IS_ERR(crtc_state))
|
|
|
|
return PTR_ERR(crtc_state);
|
|
|
|
|
2014-07-25 19:30:38 +00:00
|
|
|
ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-12-08 16:41:53 +00:00
|
|
|
DRM_DEBUG_ATOMIC("Adding all current connectors for [CRTC:%d:%s] to %p\n",
|
|
|
|
crtc->base.id, crtc->name, state);
|
2014-07-25 19:30:38 +00:00
|
|
|
|
|
|
|
/*
|
2017-01-16 09:37:39 +00:00
|
|
|
* Changed connectors are already in @state, so only need to look
|
|
|
|
* at the connector_mask in crtc_state.
|
2014-07-25 19:30:38 +00:00
|
|
|
*/
|
2017-02-28 14:46:43 +00:00
|
|
|
drm_connector_list_iter_begin(state->dev, &conn_iter);
|
drm: locking&new iterators for connector_list
The requirements for connector_list locking are a bit tricky:
- We need to be able to jump over zombie conectors (i.e. with refcount
== 0, but not yet removed from the list). If instead we require that
there's no zombies on the list then the final kref_put must happen
under the list protection lock, which means that locking context
leaks all over the place. Not pretty - better to deal with zombies
and wrap the locking just around the list_del in the destructor.
- When we walk the list we must _not_ hold the connector list lock. We
walk the connector list at an absolutely massive amounts of places,
if all those places can't ever call drm_connector_unreference the
code would get unecessarily complicated.
- connector_list needs it own lock, again too many places that walk it
that we could reuse e.g. mode_config.mutex without resulting in
inversions.
- Lots of code uses these loops to look-up a connector, i.e. they want
to be able to call drm_connector_reference. But on the other hand we
want connectors to stay on that list until they're dead (i.e.
connector_list can't hold a full reference), which means despite the
"can't hold lock for the loop body" rule we need to make sure a
connector doesn't suddenly become a zombie.
At first Dave&I discussed various horror-show approaches using srcu,
but turns out it's fairly easy:
- For the loop body we always hold an additional reference to the
current connector. That means it can't zombify, and it also means
it'll stay on the list, which means we can use it as our iterator to
find the next connector.
- When we try to find the next connector we only have to jump over
zombies. To make sure we don't chase bad pointers that entire loop
is protected with the new connect_list_lock spinlock. And because we
know that we're starting out with a non-zombie (need to drop our
reference for the old connector only after we have our new one),
we're guranteed to still be on the connector_list and either find
the next non-zombie or complete the iteration.
- Only downside is that we need to make sure that the temporary
reference for the loop body doesn't leak. iter_get/put() functions +
lockdep make sure that's the case.
- To avoid a flag day the new iterator macro has an _iter postfix. We
can rename it back once all the users of the unsafe version are gone
(there's about 100 list walkers for the connector_list).
For now this patch only converts all the list walking in the core,
leaving helpers and drivers for later patches. The nice thing is that
we can now finally remove 2 FIXME comments from the
register/unregister functions.
v2:
- use irqsafe spinlocks, so that we can use this in drm_state_dump
too.
- nuke drm_modeset_lock_all from drm_connector_init, now entirely
cargo-culted nonsense.
v3:
- do {} while (!kref_get_unless_zero), makes for a tidier loop (Dave).
- pretty kerneldoc
- add EXPORT_SYMBOL, helpers&drivers are supposed to use this.
v4: Change lockdep annotations to only check whether we release the
iter fake lock again (i.e. make sure that iter_put is called), but
not check any locking dependecies itself. That seams to require a
recursive read lock in trylock mode.
Cc: Dave Airlie <airlied@gmail.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20161213230814.19598-6-daniel.vetter@ffwll.ch
2016-12-13 23:08:06 +00:00
|
|
|
drm_for_each_connector_iter(connector, &conn_iter) {
|
2017-01-16 09:37:39 +00:00
|
|
|
if (!(crtc_state->connector_mask & (1 << drm_connector_index(connector))))
|
2014-07-25 19:30:38 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
conn_state = drm_atomic_get_connector_state(state, connector);
|
drm: locking&new iterators for connector_list
The requirements for connector_list locking are a bit tricky:
- We need to be able to jump over zombie conectors (i.e. with refcount
== 0, but not yet removed from the list). If instead we require that
there's no zombies on the list then the final kref_put must happen
under the list protection lock, which means that locking context
leaks all over the place. Not pretty - better to deal with zombies
and wrap the locking just around the list_del in the destructor.
- When we walk the list we must _not_ hold the connector list lock. We
walk the connector list at an absolutely massive amounts of places,
if all those places can't ever call drm_connector_unreference the
code would get unecessarily complicated.
- connector_list needs it own lock, again too many places that walk it
that we could reuse e.g. mode_config.mutex without resulting in
inversions.
- Lots of code uses these loops to look-up a connector, i.e. they want
to be able to call drm_connector_reference. But on the other hand we
want connectors to stay on that list until they're dead (i.e.
connector_list can't hold a full reference), which means despite the
"can't hold lock for the loop body" rule we need to make sure a
connector doesn't suddenly become a zombie.
At first Dave&I discussed various horror-show approaches using srcu,
but turns out it's fairly easy:
- For the loop body we always hold an additional reference to the
current connector. That means it can't zombify, and it also means
it'll stay on the list, which means we can use it as our iterator to
find the next connector.
- When we try to find the next connector we only have to jump over
zombies. To make sure we don't chase bad pointers that entire loop
is protected with the new connect_list_lock spinlock. And because we
know that we're starting out with a non-zombie (need to drop our
reference for the old connector only after we have our new one),
we're guranteed to still be on the connector_list and either find
the next non-zombie or complete the iteration.
- Only downside is that we need to make sure that the temporary
reference for the loop body doesn't leak. iter_get/put() functions +
lockdep make sure that's the case.
- To avoid a flag day the new iterator macro has an _iter postfix. We
can rename it back once all the users of the unsafe version are gone
(there's about 100 list walkers for the connector_list).
For now this patch only converts all the list walking in the core,
leaving helpers and drivers for later patches. The nice thing is that
we can now finally remove 2 FIXME comments from the
register/unregister functions.
v2:
- use irqsafe spinlocks, so that we can use this in drm_state_dump
too.
- nuke drm_modeset_lock_all from drm_connector_init, now entirely
cargo-culted nonsense.
v3:
- do {} while (!kref_get_unless_zero), makes for a tidier loop (Dave).
- pretty kerneldoc
- add EXPORT_SYMBOL, helpers&drivers are supposed to use this.
v4: Change lockdep annotations to only check whether we release the
iter fake lock again (i.e. make sure that iter_put is called), but
not check any locking dependecies itself. That seams to require a
recursive read lock in trylock mode.
Cc: Dave Airlie <airlied@gmail.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20161213230814.19598-6-daniel.vetter@ffwll.ch
2016-12-13 23:08:06 +00:00
|
|
|
if (IS_ERR(conn_state)) {
|
2017-02-28 14:46:43 +00:00
|
|
|
drm_connector_list_iter_end(&conn_iter);
|
2014-07-25 19:30:38 +00:00
|
|
|
return PTR_ERR(conn_state);
|
drm: locking&new iterators for connector_list
The requirements for connector_list locking are a bit tricky:
- We need to be able to jump over zombie conectors (i.e. with refcount
== 0, but not yet removed from the list). If instead we require that
there's no zombies on the list then the final kref_put must happen
under the list protection lock, which means that locking context
leaks all over the place. Not pretty - better to deal with zombies
and wrap the locking just around the list_del in the destructor.
- When we walk the list we must _not_ hold the connector list lock. We
walk the connector list at an absolutely massive amounts of places,
if all those places can't ever call drm_connector_unreference the
code would get unecessarily complicated.
- connector_list needs it own lock, again too many places that walk it
that we could reuse e.g. mode_config.mutex without resulting in
inversions.
- Lots of code uses these loops to look-up a connector, i.e. they want
to be able to call drm_connector_reference. But on the other hand we
want connectors to stay on that list until they're dead (i.e.
connector_list can't hold a full reference), which means despite the
"can't hold lock for the loop body" rule we need to make sure a
connector doesn't suddenly become a zombie.
At first Dave&I discussed various horror-show approaches using srcu,
but turns out it's fairly easy:
- For the loop body we always hold an additional reference to the
current connector. That means it can't zombify, and it also means
it'll stay on the list, which means we can use it as our iterator to
find the next connector.
- When we try to find the next connector we only have to jump over
zombies. To make sure we don't chase bad pointers that entire loop
is protected with the new connect_list_lock spinlock. And because we
know that we're starting out with a non-zombie (need to drop our
reference for the old connector only after we have our new one),
we're guranteed to still be on the connector_list and either find
the next non-zombie or complete the iteration.
- Only downside is that we need to make sure that the temporary
reference for the loop body doesn't leak. iter_get/put() functions +
lockdep make sure that's the case.
- To avoid a flag day the new iterator macro has an _iter postfix. We
can rename it back once all the users of the unsafe version are gone
(there's about 100 list walkers for the connector_list).
For now this patch only converts all the list walking in the core,
leaving helpers and drivers for later patches. The nice thing is that
we can now finally remove 2 FIXME comments from the
register/unregister functions.
v2:
- use irqsafe spinlocks, so that we can use this in drm_state_dump
too.
- nuke drm_modeset_lock_all from drm_connector_init, now entirely
cargo-culted nonsense.
v3:
- do {} while (!kref_get_unless_zero), makes for a tidier loop (Dave).
- pretty kerneldoc
- add EXPORT_SYMBOL, helpers&drivers are supposed to use this.
v4: Change lockdep annotations to only check whether we release the
iter fake lock again (i.e. make sure that iter_put is called), but
not check any locking dependecies itself. That seams to require a
recursive read lock in trylock mode.
Cc: Dave Airlie <airlied@gmail.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20161213230814.19598-6-daniel.vetter@ffwll.ch
2016-12-13 23:08:06 +00:00
|
|
|
}
|
2014-07-25 19:30:38 +00:00
|
|
|
}
|
2017-02-28 14:46:43 +00:00
|
|
|
drm_connector_list_iter_end(&conn_iter);
|
2014-07-25 19:30:38 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_add_affected_connectors);
|
|
|
|
|
2015-05-19 14:41:02 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_add_affected_planes - add planes for crtc
|
|
|
|
* @state: atomic state
|
|
|
|
* @crtc: DRM crtc
|
|
|
|
*
|
|
|
|
* This function walks the current configuration and adds all planes
|
|
|
|
* currently used by @crtc to the atomic configuration @state. This is useful
|
|
|
|
* when an atomic commit also needs to check all currently enabled plane on
|
|
|
|
* @crtc, e.g. when changing the mode. It's also useful when re-enabling a CRTC
|
|
|
|
* to avoid special code to force-enable all planes.
|
|
|
|
*
|
|
|
|
* Since acquiring a plane state will always also acquire the w/w mutex of the
|
|
|
|
* current CRTC for that plane (if there is any) adding all the plane states for
|
|
|
|
* a CRTC will not reduce parallism of atomic updates.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
|
|
|
|
* then the w/w mutex code has detected a deadlock and the entire atomic
|
|
|
|
* sequence must be restarted. All other errors are fatal.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
drm_atomic_add_affected_planes(struct drm_atomic_state *state,
|
|
|
|
struct drm_crtc *crtc)
|
|
|
|
{
|
|
|
|
struct drm_plane *plane;
|
|
|
|
|
2017-03-01 09:22:10 +00:00
|
|
|
WARN_ON(!drm_atomic_get_new_crtc_state(state, crtc));
|
2015-05-19 14:41:02 +00:00
|
|
|
|
|
|
|
drm_for_each_plane_mask(plane, state->dev, crtc->state->plane_mask) {
|
|
|
|
struct drm_plane_state *plane_state =
|
|
|
|
drm_atomic_get_plane_state(state, plane);
|
|
|
|
|
|
|
|
if (IS_ERR(plane_state))
|
|
|
|
return PTR_ERR(plane_state);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_add_affected_planes);
|
|
|
|
|
2014-07-25 19:30:38 +00:00
|
|
|
/**
|
|
|
|
* drm_atomic_legacy_backoff - locking backoff for legacy ioctls
|
|
|
|
* @state: atomic state
|
|
|
|
*
|
|
|
|
* This function should be used by legacy entry points which don't understand
|
|
|
|
* -EDEADLK semantics. For simplicity this one will grab all modeset locks after
|
2015-04-07 11:38:50 +00:00
|
|
|
* the slowpath completed.
|
2014-07-25 19:30:38 +00:00
|
|
|
*/
|
|
|
|
void drm_atomic_legacy_backoff(struct drm_atomic_state *state)
|
|
|
|
{
|
2016-06-23 11:45:06 +00:00
|
|
|
struct drm_device *dev = state->dev;
|
2014-07-25 19:30:38 +00:00
|
|
|
int ret;
|
2016-06-23 11:45:06 +00:00
|
|
|
bool global = false;
|
|
|
|
|
|
|
|
if (WARN_ON(dev->mode_config.acquire_ctx == state->acquire_ctx)) {
|
|
|
|
global = true;
|
|
|
|
|
|
|
|
dev->mode_config.acquire_ctx = NULL;
|
|
|
|
}
|
2014-07-25 19:30:38 +00:00
|
|
|
|
|
|
|
retry:
|
|
|
|
drm_modeset_backoff(state->acquire_ctx);
|
|
|
|
|
2016-06-23 11:45:06 +00:00
|
|
|
ret = drm_modeset_lock_all_ctx(dev, state->acquire_ctx);
|
2014-07-25 19:30:38 +00:00
|
|
|
if (ret)
|
|
|
|
goto retry;
|
2016-06-23 11:45:06 +00:00
|
|
|
|
|
|
|
if (global)
|
|
|
|
dev->mode_config.acquire_ctx = state->acquire_ctx;
|
2014-07-25 19:30:38 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_legacy_backoff);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_atomic_check_only - check whether a given config would work
|
|
|
|
* @state: atomic configuration to check
|
|
|
|
*
|
|
|
|
* Note that this function can return -EDEADLK if the driver needed to acquire
|
|
|
|
* more locks but encountered a deadlock. The caller must then do the usual w/w
|
|
|
|
* backoff dance and restart. All other errors are fatal.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 0 on success, negative error code on failure.
|
|
|
|
*/
|
|
|
|
int drm_atomic_check_only(struct drm_atomic_state *state)
|
|
|
|
{
|
2014-12-18 21:01:51 +00:00
|
|
|
struct drm_device *dev = state->dev;
|
|
|
|
struct drm_mode_config *config = &dev->mode_config;
|
2015-04-10 11:58:39 +00:00
|
|
|
struct drm_plane *plane;
|
|
|
|
struct drm_plane_state *plane_state;
|
|
|
|
struct drm_crtc *crtc;
|
|
|
|
struct drm_crtc_state *crtc_state;
|
2014-12-18 21:01:51 +00:00
|
|
|
int i, ret = 0;
|
2014-07-25 19:30:38 +00:00
|
|
|
|
2015-02-22 11:24:16 +00:00
|
|
|
DRM_DEBUG_ATOMIC("checking %p\n", state);
|
2014-07-25 19:30:38 +00:00
|
|
|
|
2017-01-16 09:37:40 +00:00
|
|
|
for_each_new_plane_in_state(state, plane, plane_state, i) {
|
2015-04-10 11:58:39 +00:00
|
|
|
ret = drm_atomic_plane_check(plane, plane_state);
|
2014-12-18 21:01:51 +00:00
|
|
|
if (ret) {
|
2015-12-08 16:41:54 +00:00
|
|
|
DRM_DEBUG_ATOMIC("[PLANE:%d:%s] atomic core check failed\n",
|
|
|
|
plane->base.id, plane->name);
|
2014-12-18 21:01:51 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-16 09:37:40 +00:00
|
|
|
for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
|
2015-04-10 11:58:39 +00:00
|
|
|
ret = drm_atomic_crtc_check(crtc, crtc_state);
|
2014-12-18 21:01:51 +00:00
|
|
|
if (ret) {
|
2015-12-08 16:41:53 +00:00
|
|
|
DRM_DEBUG_ATOMIC("[CRTC:%d:%s] atomic core check failed\n",
|
|
|
|
crtc->base.id, crtc->name);
|
2014-12-18 21:01:51 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-25 19:30:38 +00:00
|
|
|
if (config->funcs->atomic_check)
|
2014-12-18 21:01:51 +00:00
|
|
|
ret = config->funcs->atomic_check(state->dev, state);
|
|
|
|
|
2014-12-18 21:01:56 +00:00
|
|
|
if (!state->allow_modeset) {
|
2017-01-16 09:37:40 +00:00
|
|
|
for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
|
2015-06-18 07:58:55 +00:00
|
|
|
if (drm_atomic_crtc_needs_modeset(crtc_state)) {
|
2015-12-08 16:41:53 +00:00
|
|
|
DRM_DEBUG_ATOMIC("[CRTC:%d:%s] requires full modeset\n",
|
|
|
|
crtc->base.id, crtc->name);
|
2014-12-18 21:01:56 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-18 21:01:51 +00:00
|
|
|
return ret;
|
2014-07-25 19:30:38 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_check_only);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_atomic_commit - commit configuration atomically
|
|
|
|
* @state: atomic configuration to check
|
|
|
|
*
|
|
|
|
* Note that this function can return -EDEADLK if the driver needed to acquire
|
|
|
|
* more locks but encountered a deadlock. The caller must then do the usual w/w
|
|
|
|
* backoff dance and restart. All other errors are fatal.
|
|
|
|
*
|
2017-01-04 11:34:00 +00:00
|
|
|
* This function will take its own reference on @state.
|
|
|
|
* Callers should always release their reference with drm_atomic_state_put().
|
2014-07-25 19:30:38 +00:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 0 on success, negative error code on failure.
|
|
|
|
*/
|
|
|
|
int drm_atomic_commit(struct drm_atomic_state *state)
|
|
|
|
{
|
|
|
|
struct drm_mode_config *config = &state->dev->mode_config;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = drm_atomic_check_only(state);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-02-22 11:24:16 +00:00
|
|
|
DRM_DEBUG_ATOMIC("commiting %p\n", state);
|
2014-07-25 19:30:38 +00:00
|
|
|
|
|
|
|
return config->funcs->atomic_commit(state->dev, state, false);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_commit);
|
|
|
|
|
|
|
|
/**
|
2017-01-25 06:26:45 +00:00
|
|
|
* drm_atomic_nonblocking_commit - atomic nonblocking commit
|
2014-07-25 19:30:38 +00:00
|
|
|
* @state: atomic configuration to check
|
|
|
|
*
|
|
|
|
* Note that this function can return -EDEADLK if the driver needed to acquire
|
|
|
|
* more locks but encountered a deadlock. The caller must then do the usual w/w
|
|
|
|
* backoff dance and restart. All other errors are fatal.
|
|
|
|
*
|
2017-01-04 11:34:00 +00:00
|
|
|
* This function will take its own reference on @state.
|
|
|
|
* Callers should always release their reference with drm_atomic_state_put().
|
2014-07-25 19:30:38 +00:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 0 on success, negative error code on failure.
|
|
|
|
*/
|
2016-04-26 14:11:35 +00:00
|
|
|
int drm_atomic_nonblocking_commit(struct drm_atomic_state *state)
|
2014-07-25 19:30:38 +00:00
|
|
|
{
|
|
|
|
struct drm_mode_config *config = &state->dev->mode_config;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = drm_atomic_check_only(state);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2016-04-26 14:11:35 +00:00
|
|
|
DRM_DEBUG_ATOMIC("commiting %p nonblocking\n", state);
|
2014-07-25 19:30:38 +00:00
|
|
|
|
|
|
|
return config->funcs->atomic_commit(state->dev, state, true);
|
|
|
|
}
|
2016-04-26 14:11:35 +00:00
|
|
|
EXPORT_SYMBOL(drm_atomic_nonblocking_commit);
|
2014-12-18 21:01:56 +00:00
|
|
|
|
2016-11-05 15:08:09 +00:00
|
|
|
static void drm_atomic_print_state(const struct drm_atomic_state *state)
|
|
|
|
{
|
|
|
|
struct drm_printer p = drm_info_printer(state->dev->dev);
|
|
|
|
struct drm_plane *plane;
|
|
|
|
struct drm_plane_state *plane_state;
|
|
|
|
struct drm_crtc *crtc;
|
|
|
|
struct drm_crtc_state *crtc_state;
|
|
|
|
struct drm_connector *connector;
|
|
|
|
struct drm_connector_state *connector_state;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
DRM_DEBUG_ATOMIC("checking %p\n", state);
|
|
|
|
|
2017-01-16 09:37:40 +00:00
|
|
|
for_each_new_plane_in_state(state, plane, plane_state, i)
|
2016-11-05 15:08:09 +00:00
|
|
|
drm_atomic_plane_print_state(&p, plane_state);
|
|
|
|
|
2017-01-16 09:37:40 +00:00
|
|
|
for_each_new_crtc_in_state(state, crtc, crtc_state, i)
|
2016-11-05 15:08:09 +00:00
|
|
|
drm_atomic_crtc_print_state(&p, crtc_state);
|
|
|
|
|
2017-01-16 09:37:40 +00:00
|
|
|
for_each_new_connector_in_state(state, connector, connector_state, i)
|
2016-11-05 15:08:09 +00:00
|
|
|
drm_atomic_connector_print_state(&p, connector_state);
|
|
|
|
}
|
|
|
|
|
2017-04-03 08:32:54 +00:00
|
|
|
static void __drm_state_dump(struct drm_device *dev, struct drm_printer *p,
|
|
|
|
bool take_locks)
|
2016-11-05 15:08:10 +00:00
|
|
|
{
|
|
|
|
struct drm_mode_config *config = &dev->mode_config;
|
|
|
|
struct drm_plane *plane;
|
|
|
|
struct drm_crtc *crtc;
|
|
|
|
struct drm_connector *connector;
|
drm: locking&new iterators for connector_list
The requirements for connector_list locking are a bit tricky:
- We need to be able to jump over zombie conectors (i.e. with refcount
== 0, but not yet removed from the list). If instead we require that
there's no zombies on the list then the final kref_put must happen
under the list protection lock, which means that locking context
leaks all over the place. Not pretty - better to deal with zombies
and wrap the locking just around the list_del in the destructor.
- When we walk the list we must _not_ hold the connector list lock. We
walk the connector list at an absolutely massive amounts of places,
if all those places can't ever call drm_connector_unreference the
code would get unecessarily complicated.
- connector_list needs it own lock, again too many places that walk it
that we could reuse e.g. mode_config.mutex without resulting in
inversions.
- Lots of code uses these loops to look-up a connector, i.e. they want
to be able to call drm_connector_reference. But on the other hand we
want connectors to stay on that list until they're dead (i.e.
connector_list can't hold a full reference), which means despite the
"can't hold lock for the loop body" rule we need to make sure a
connector doesn't suddenly become a zombie.
At first Dave&I discussed various horror-show approaches using srcu,
but turns out it's fairly easy:
- For the loop body we always hold an additional reference to the
current connector. That means it can't zombify, and it also means
it'll stay on the list, which means we can use it as our iterator to
find the next connector.
- When we try to find the next connector we only have to jump over
zombies. To make sure we don't chase bad pointers that entire loop
is protected with the new connect_list_lock spinlock. And because we
know that we're starting out with a non-zombie (need to drop our
reference for the old connector only after we have our new one),
we're guranteed to still be on the connector_list and either find
the next non-zombie or complete the iteration.
- Only downside is that we need to make sure that the temporary
reference for the loop body doesn't leak. iter_get/put() functions +
lockdep make sure that's the case.
- To avoid a flag day the new iterator macro has an _iter postfix. We
can rename it back once all the users of the unsafe version are gone
(there's about 100 list walkers for the connector_list).
For now this patch only converts all the list walking in the core,
leaving helpers and drivers for later patches. The nice thing is that
we can now finally remove 2 FIXME comments from the
register/unregister functions.
v2:
- use irqsafe spinlocks, so that we can use this in drm_state_dump
too.
- nuke drm_modeset_lock_all from drm_connector_init, now entirely
cargo-culted nonsense.
v3:
- do {} while (!kref_get_unless_zero), makes for a tidier loop (Dave).
- pretty kerneldoc
- add EXPORT_SYMBOL, helpers&drivers are supposed to use this.
v4: Change lockdep annotations to only check whether we release the
iter fake lock again (i.e. make sure that iter_put is called), but
not check any locking dependecies itself. That seams to require a
recursive read lock in trylock mode.
Cc: Dave Airlie <airlied@gmail.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20161213230814.19598-6-daniel.vetter@ffwll.ch
2016-12-13 23:08:06 +00:00
|
|
|
struct drm_connector_list_iter conn_iter;
|
2016-11-05 15:08:10 +00:00
|
|
|
|
|
|
|
if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
|
|
|
|
return;
|
|
|
|
|
2017-04-03 08:32:54 +00:00
|
|
|
list_for_each_entry(plane, &config->plane_list, head) {
|
|
|
|
if (take_locks)
|
|
|
|
drm_modeset_lock(&plane->mutex, NULL);
|
2016-11-05 15:08:10 +00:00
|
|
|
drm_atomic_plane_print_state(p, plane->state);
|
2017-04-03 08:32:54 +00:00
|
|
|
if (take_locks)
|
|
|
|
drm_modeset_unlock(&plane->mutex);
|
|
|
|
}
|
2016-11-05 15:08:10 +00:00
|
|
|
|
2017-04-03 08:32:54 +00:00
|
|
|
list_for_each_entry(crtc, &config->crtc_list, head) {
|
|
|
|
if (take_locks)
|
|
|
|
drm_modeset_lock(&crtc->mutex, NULL);
|
2016-11-05 15:08:10 +00:00
|
|
|
drm_atomic_crtc_print_state(p, crtc->state);
|
2017-04-03 08:32:54 +00:00
|
|
|
if (take_locks)
|
|
|
|
drm_modeset_unlock(&crtc->mutex);
|
|
|
|
}
|
2016-11-05 15:08:10 +00:00
|
|
|
|
2017-02-28 14:46:43 +00:00
|
|
|
drm_connector_list_iter_begin(dev, &conn_iter);
|
2017-04-03 08:32:54 +00:00
|
|
|
if (take_locks)
|
|
|
|
drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
|
drm: locking&new iterators for connector_list
The requirements for connector_list locking are a bit tricky:
- We need to be able to jump over zombie conectors (i.e. with refcount
== 0, but not yet removed from the list). If instead we require that
there's no zombies on the list then the final kref_put must happen
under the list protection lock, which means that locking context
leaks all over the place. Not pretty - better to deal with zombies
and wrap the locking just around the list_del in the destructor.
- When we walk the list we must _not_ hold the connector list lock. We
walk the connector list at an absolutely massive amounts of places,
if all those places can't ever call drm_connector_unreference the
code would get unecessarily complicated.
- connector_list needs it own lock, again too many places that walk it
that we could reuse e.g. mode_config.mutex without resulting in
inversions.
- Lots of code uses these loops to look-up a connector, i.e. they want
to be able to call drm_connector_reference. But on the other hand we
want connectors to stay on that list until they're dead (i.e.
connector_list can't hold a full reference), which means despite the
"can't hold lock for the loop body" rule we need to make sure a
connector doesn't suddenly become a zombie.
At first Dave&I discussed various horror-show approaches using srcu,
but turns out it's fairly easy:
- For the loop body we always hold an additional reference to the
current connector. That means it can't zombify, and it also means
it'll stay on the list, which means we can use it as our iterator to
find the next connector.
- When we try to find the next connector we only have to jump over
zombies. To make sure we don't chase bad pointers that entire loop
is protected with the new connect_list_lock spinlock. And because we
know that we're starting out with a non-zombie (need to drop our
reference for the old connector only after we have our new one),
we're guranteed to still be on the connector_list and either find
the next non-zombie or complete the iteration.
- Only downside is that we need to make sure that the temporary
reference for the loop body doesn't leak. iter_get/put() functions +
lockdep make sure that's the case.
- To avoid a flag day the new iterator macro has an _iter postfix. We
can rename it back once all the users of the unsafe version are gone
(there's about 100 list walkers for the connector_list).
For now this patch only converts all the list walking in the core,
leaving helpers and drivers for later patches. The nice thing is that
we can now finally remove 2 FIXME comments from the
register/unregister functions.
v2:
- use irqsafe spinlocks, so that we can use this in drm_state_dump
too.
- nuke drm_modeset_lock_all from drm_connector_init, now entirely
cargo-culted nonsense.
v3:
- do {} while (!kref_get_unless_zero), makes for a tidier loop (Dave).
- pretty kerneldoc
- add EXPORT_SYMBOL, helpers&drivers are supposed to use this.
v4: Change lockdep annotations to only check whether we release the
iter fake lock again (i.e. make sure that iter_put is called), but
not check any locking dependecies itself. That seams to require a
recursive read lock in trylock mode.
Cc: Dave Airlie <airlied@gmail.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20161213230814.19598-6-daniel.vetter@ffwll.ch
2016-12-13 23:08:06 +00:00
|
|
|
drm_for_each_connector_iter(connector, &conn_iter)
|
2016-11-05 15:08:10 +00:00
|
|
|
drm_atomic_connector_print_state(p, connector->state);
|
2017-04-03 08:32:54 +00:00
|
|
|
if (take_locks)
|
|
|
|
drm_modeset_unlock(&dev->mode_config.connection_mutex);
|
2017-02-28 14:46:43 +00:00
|
|
|
drm_connector_list_iter_end(&conn_iter);
|
2016-11-05 15:08:10 +00:00
|
|
|
}
|
2017-04-03 08:32:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_state_dump - dump entire device atomic state
|
|
|
|
* @dev: the drm device
|
|
|
|
* @p: where to print the state to
|
|
|
|
*
|
|
|
|
* Just for debugging. Drivers might want an option to dump state
|
|
|
|
* to dmesg in case of error irq's. (Hint, you probably want to
|
|
|
|
* ratelimit this!)
|
|
|
|
*
|
|
|
|
* The caller must drm_modeset_lock_all(), or if this is called
|
|
|
|
* from error irq handler, it should not be enabled by default.
|
|
|
|
* (Ie. if you are debugging errors you might not care that this
|
|
|
|
* is racey. But calling this without all modeset locks held is
|
|
|
|
* not inherently safe.)
|
|
|
|
*/
|
|
|
|
void drm_state_dump(struct drm_device *dev, struct drm_printer *p)
|
|
|
|
{
|
|
|
|
__drm_state_dump(dev, p, false);
|
|
|
|
}
|
2016-11-05 15:08:10 +00:00
|
|
|
EXPORT_SYMBOL(drm_state_dump);
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
static int drm_state_info(struct seq_file *m, void *data)
|
|
|
|
{
|
|
|
|
struct drm_info_node *node = (struct drm_info_node *) m->private;
|
|
|
|
struct drm_device *dev = node->minor->dev;
|
|
|
|
struct drm_printer p = drm_seq_file_printer(m);
|
|
|
|
|
2017-04-03 08:32:54 +00:00
|
|
|
__drm_state_dump(dev, &p, true);
|
2016-11-05 15:08:10 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* any use in debugfs files to dump individual planes/crtc/etc? */
|
|
|
|
static const struct drm_info_list drm_atomic_debugfs_list[] = {
|
|
|
|
{"state", drm_state_info, 0},
|
|
|
|
};
|
|
|
|
|
|
|
|
int drm_atomic_debugfs_init(struct drm_minor *minor)
|
|
|
|
{
|
|
|
|
return drm_debugfs_create_files(drm_atomic_debugfs_list,
|
|
|
|
ARRAY_SIZE(drm_atomic_debugfs_list),
|
|
|
|
minor->debugfs_root, minor);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-12-18 21:01:56 +00:00
|
|
|
/*
|
|
|
|
* The big monstor ioctl
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct drm_pending_vblank_event *create_vblank_event(
|
2016-11-16 13:00:21 +00:00
|
|
|
struct drm_device *dev, uint64_t user_data)
|
2014-12-18 21:01:56 +00:00
|
|
|
{
|
|
|
|
struct drm_pending_vblank_event *e = NULL;
|
|
|
|
|
|
|
|
e = kzalloc(sizeof *e, GFP_KERNEL);
|
2016-01-11 21:40:56 +00:00
|
|
|
if (!e)
|
|
|
|
return NULL;
|
2014-12-18 21:01:56 +00:00
|
|
|
|
|
|
|
e->event.base.type = DRM_EVENT_FLIP_COMPLETE;
|
2016-01-11 21:40:56 +00:00
|
|
|
e->event.base.length = sizeof(e->event);
|
2014-12-18 21:01:56 +00:00
|
|
|
e->event.user_data = user_data;
|
|
|
|
|
2016-01-11 21:40:56 +00:00
|
|
|
return e;
|
2014-12-18 21:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int atomic_set_prop(struct drm_atomic_state *state,
|
|
|
|
struct drm_mode_object *obj, struct drm_property *prop,
|
|
|
|
uint64_t prop_value)
|
|
|
|
{
|
|
|
|
struct drm_mode_object *ref;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!drm_property_change_valid_get(prop, prop_value, &ref))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
switch (obj->type) {
|
|
|
|
case DRM_MODE_OBJECT_CONNECTOR: {
|
|
|
|
struct drm_connector *connector = obj_to_connector(obj);
|
|
|
|
struct drm_connector_state *connector_state;
|
|
|
|
|
|
|
|
connector_state = drm_atomic_get_connector_state(state, connector);
|
|
|
|
if (IS_ERR(connector_state)) {
|
|
|
|
ret = PTR_ERR(connector_state);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = drm_atomic_connector_set_property(connector,
|
|
|
|
connector_state, prop, prop_value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DRM_MODE_OBJECT_CRTC: {
|
|
|
|
struct drm_crtc *crtc = obj_to_crtc(obj);
|
|
|
|
struct drm_crtc_state *crtc_state;
|
|
|
|
|
|
|
|
crtc_state = drm_atomic_get_crtc_state(state, crtc);
|
|
|
|
if (IS_ERR(crtc_state)) {
|
|
|
|
ret = PTR_ERR(crtc_state);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = drm_atomic_crtc_set_property(crtc,
|
|
|
|
crtc_state, prop, prop_value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DRM_MODE_OBJECT_PLANE: {
|
|
|
|
struct drm_plane *plane = obj_to_plane(obj);
|
|
|
|
struct drm_plane_state *plane_state;
|
|
|
|
|
|
|
|
plane_state = drm_atomic_get_plane_state(state, plane);
|
|
|
|
if (IS_ERR(plane_state)) {
|
|
|
|
ret = PTR_ERR(plane_state);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = drm_atomic_plane_set_property(plane,
|
|
|
|
plane_state, prop, prop_value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
drm_property_change_valid_put(prop, ref);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-11-11 10:29:09 +00:00
|
|
|
/**
|
2015-11-24 09:34:34 +00:00
|
|
|
* drm_atomic_clean_old_fb -- Unset old_fb pointers and set plane->fb pointers.
|
2015-11-11 10:29:09 +00:00
|
|
|
*
|
|
|
|
* @dev: drm device to check.
|
|
|
|
* @plane_mask: plane mask for planes that were updated.
|
|
|
|
* @ret: return value, can be -EDEADLK for a retry.
|
|
|
|
*
|
2017-01-25 06:26:45 +00:00
|
|
|
* Before doing an update &drm_plane.old_fb is set to &drm_plane.fb, but before
|
|
|
|
* dropping the locks old_fb needs to be set to NULL and plane->fb updated. This
|
|
|
|
* is a common operation for each atomic update, so this call is split off as a
|
|
|
|
* helper.
|
2015-11-11 10:29:09 +00:00
|
|
|
*/
|
|
|
|
void drm_atomic_clean_old_fb(struct drm_device *dev,
|
|
|
|
unsigned plane_mask,
|
|
|
|
int ret)
|
|
|
|
{
|
|
|
|
struct drm_plane *plane;
|
|
|
|
|
|
|
|
/* if succeeded, fixup legacy plane crtc/fb ptrs before dropping
|
|
|
|
* locks (ie. while it is still safe to deref plane->state). We
|
|
|
|
* need to do this here because the driver entry points cannot
|
|
|
|
* distinguish between legacy and atomic ioctls.
|
|
|
|
*/
|
|
|
|
drm_for_each_plane_mask(plane, dev, plane_mask) {
|
|
|
|
if (ret == 0) {
|
|
|
|
struct drm_framebuffer *new_fb = plane->state->fb;
|
|
|
|
if (new_fb)
|
2017-02-28 14:46:40 +00:00
|
|
|
drm_framebuffer_get(new_fb);
|
2015-11-11 10:29:09 +00:00
|
|
|
plane->fb = new_fb;
|
|
|
|
plane->crtc = plane->state->crtc;
|
|
|
|
|
|
|
|
if (plane->old_fb)
|
2017-02-28 14:46:40 +00:00
|
|
|
drm_framebuffer_put(plane->old_fb);
|
2015-11-11 10:29:09 +00:00
|
|
|
}
|
|
|
|
plane->old_fb = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_clean_old_fb);
|
|
|
|
|
2016-11-22 00:11:28 +00:00
|
|
|
/**
|
|
|
|
* DOC: explicit fencing properties
|
|
|
|
*
|
|
|
|
* Explicit fencing allows userspace to control the buffer synchronization
|
|
|
|
* between devices. A Fence or a group of fences are transfered to/from
|
|
|
|
* userspace using Sync File fds and there are two DRM properties for that.
|
|
|
|
* IN_FENCE_FD on each DRM Plane to send fences to the kernel and
|
|
|
|
* OUT_FENCE_PTR on each DRM CRTC to receive fences from the kernel.
|
|
|
|
*
|
|
|
|
* As a contrast, with implicit fencing the kernel keeps track of any
|
|
|
|
* ongoing rendering, and automatically ensures that the atomic update waits
|
|
|
|
* for any pending rendering to complete. For shared buffers represented with
|
2017-01-25 06:26:45 +00:00
|
|
|
* a &struct dma_buf this is tracked in &struct reservation_object.
|
2016-11-22 00:11:28 +00:00
|
|
|
* Implicit syncing is how Linux traditionally worked (e.g. DRI2/3 on X.org),
|
|
|
|
* whereas explicit fencing is what Android wants.
|
|
|
|
*
|
|
|
|
* "IN_FENCE_FD”:
|
|
|
|
* Use this property to pass a fence that DRM should wait on before
|
|
|
|
* proceeding with the Atomic Commit request and show the framebuffer for
|
|
|
|
* the plane on the screen. The fence can be either a normal fence or a
|
|
|
|
* merged one, the sync_file framework will handle both cases and use a
|
|
|
|
* fence_array if a merged fence is received. Passing -1 here means no
|
|
|
|
* fences to wait on.
|
|
|
|
*
|
|
|
|
* If the Atomic Commit request has the DRM_MODE_ATOMIC_TEST_ONLY flag
|
|
|
|
* it will only check if the Sync File is a valid one.
|
|
|
|
*
|
|
|
|
* On the driver side the fence is stored on the @fence parameter of
|
2016-12-29 20:48:26 +00:00
|
|
|
* &struct drm_plane_state. Drivers which also support implicit fencing
|
2016-11-22 00:11:28 +00:00
|
|
|
* should set the implicit fence using drm_atomic_set_fence_for_plane(),
|
|
|
|
* to make sure there's consistent behaviour between drivers in precedence
|
|
|
|
* of implicit vs. explicit fencing.
|
|
|
|
*
|
|
|
|
* "OUT_FENCE_PTR”:
|
|
|
|
* Use this property to pass a file descriptor pointer to DRM. Once the
|
|
|
|
* Atomic Commit request call returns OUT_FENCE_PTR will be filled with
|
|
|
|
* the file descriptor number of a Sync File. This Sync File contains the
|
|
|
|
* CRTC fence that will be signaled when all framebuffers present on the
|
|
|
|
* Atomic Commit * request for that given CRTC are scanned out on the
|
|
|
|
* screen.
|
|
|
|
*
|
|
|
|
* The Atomic Commit request fails if a invalid pointer is passed. If the
|
|
|
|
* Atomic Commit request fails for any other reason the out fence fd
|
|
|
|
* returned will be -1. On a Atomic Commit with the
|
|
|
|
* DRM_MODE_ATOMIC_TEST_ONLY flag the out fence will also be set to -1.
|
|
|
|
*
|
|
|
|
* Note that out-fences don't have a special interface to drivers and are
|
2016-12-29 20:48:26 +00:00
|
|
|
* internally represented by a &struct drm_pending_vblank_event in struct
|
2016-11-22 00:11:28 +00:00
|
|
|
* &drm_crtc_state, which is also used by the nonblocking atomic commit
|
|
|
|
* helpers and for the DRM event handling for existing userspace.
|
|
|
|
*/
|
|
|
|
|
2016-11-16 13:00:21 +00:00
|
|
|
struct drm_out_fence_state {
|
2017-01-13 14:22:09 +00:00
|
|
|
s32 __user *out_fence_ptr;
|
2016-11-16 13:00:21 +00:00
|
|
|
struct sync_file *sync_file;
|
|
|
|
int fd;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int setup_out_fence(struct drm_out_fence_state *fence_state,
|
|
|
|
struct dma_fence *fence)
|
|
|
|
{
|
|
|
|
fence_state->fd = get_unused_fd_flags(O_CLOEXEC);
|
|
|
|
if (fence_state->fd < 0)
|
|
|
|
return fence_state->fd;
|
|
|
|
|
|
|
|
if (put_user(fence_state->fd, fence_state->out_fence_ptr))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
fence_state->sync_file = sync_file_create(fence);
|
|
|
|
if (!fence_state->sync_file)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int prepare_crtc_signaling(struct drm_device *dev,
|
|
|
|
struct drm_atomic_state *state,
|
|
|
|
struct drm_mode_atomic *arg,
|
|
|
|
struct drm_file *file_priv,
|
|
|
|
struct drm_out_fence_state **fence_state,
|
|
|
|
unsigned int *num_fences)
|
|
|
|
{
|
|
|
|
struct drm_crtc *crtc;
|
|
|
|
struct drm_crtc_state *crtc_state;
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)
|
|
|
|
return 0;
|
|
|
|
|
2017-01-16 09:37:40 +00:00
|
|
|
for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
|
2017-01-13 14:22:09 +00:00
|
|
|
s32 __user *fence_ptr;
|
2016-11-16 13:00:21 +00:00
|
|
|
|
|
|
|
fence_ptr = get_out_fence_for_crtc(crtc_state->state, crtc);
|
|
|
|
|
|
|
|
if (arg->flags & DRM_MODE_PAGE_FLIP_EVENT || fence_ptr) {
|
|
|
|
struct drm_pending_vblank_event *e;
|
|
|
|
|
|
|
|
e = create_vblank_event(dev, arg->user_data);
|
|
|
|
if (!e)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
crtc_state->event = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg->flags & DRM_MODE_PAGE_FLIP_EVENT) {
|
|
|
|
struct drm_pending_vblank_event *e = crtc_state->event;
|
|
|
|
|
|
|
|
if (!file_priv)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ret = drm_event_reserve_init(dev, file_priv, &e->base,
|
|
|
|
&e->event.base);
|
|
|
|
if (ret) {
|
|
|
|
kfree(e);
|
|
|
|
crtc_state->event = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fence_ptr) {
|
|
|
|
struct dma_fence *fence;
|
|
|
|
struct drm_out_fence_state *f;
|
|
|
|
|
|
|
|
f = krealloc(*fence_state, sizeof(**fence_state) *
|
|
|
|
(*num_fences + 1), GFP_KERNEL);
|
|
|
|
if (!f)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
memset(&f[*num_fences], 0, sizeof(*f));
|
|
|
|
|
|
|
|
f[*num_fences].out_fence_ptr = fence_ptr;
|
|
|
|
*fence_state = f;
|
|
|
|
|
2016-12-06 17:47:17 +00:00
|
|
|
fence = drm_crtc_create_fence(crtc);
|
2016-11-16 13:00:21 +00:00
|
|
|
if (!fence)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ret = setup_out_fence(&f[(*num_fences)++], fence);
|
|
|
|
if (ret) {
|
|
|
|
dma_fence_put(fence);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
crtc_state->event->base.fence = fence;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void complete_crtc_signaling(struct drm_device *dev,
|
|
|
|
struct drm_atomic_state *state,
|
|
|
|
struct drm_out_fence_state *fence_state,
|
|
|
|
unsigned int num_fences,
|
|
|
|
bool install_fds)
|
|
|
|
{
|
|
|
|
struct drm_crtc *crtc;
|
|
|
|
struct drm_crtc_state *crtc_state;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (install_fds) {
|
|
|
|
for (i = 0; i < num_fences; i++)
|
|
|
|
fd_install(fence_state[i].fd,
|
|
|
|
fence_state[i].sync_file->file);
|
|
|
|
|
|
|
|
kfree(fence_state);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-16 09:37:40 +00:00
|
|
|
for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
|
2017-01-31 09:25:25 +00:00
|
|
|
struct drm_pending_vblank_event *event = crtc_state->event;
|
2016-11-16 13:00:21 +00:00
|
|
|
/*
|
2017-01-31 09:25:25 +00:00
|
|
|
* Free the allocated event. drm_atomic_helper_setup_commit
|
|
|
|
* can allocate an event too, so only free it if it's ours
|
|
|
|
* to prevent a double free in drm_atomic_state_clear.
|
2016-11-16 13:00:21 +00:00
|
|
|
*/
|
2017-01-31 09:25:25 +00:00
|
|
|
if (event && (event->base.fence || event->base.file_priv)) {
|
|
|
|
drm_event_cancel_free(dev, &event->base);
|
|
|
|
crtc_state->event = NULL;
|
|
|
|
}
|
2016-11-16 13:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!fence_state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < num_fences; i++) {
|
|
|
|
if (fence_state[i].sync_file)
|
|
|
|
fput(fence_state[i].sync_file->file);
|
|
|
|
if (fence_state[i].fd >= 0)
|
|
|
|
put_unused_fd(fence_state[i].fd);
|
|
|
|
|
|
|
|
/* If this fails log error to the user */
|
|
|
|
if (fence_state[i].out_fence_ptr &&
|
|
|
|
put_user(-1, fence_state[i].out_fence_ptr))
|
|
|
|
DRM_DEBUG_ATOMIC("Couldn't clear out_fence_ptr\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(fence_state);
|
|
|
|
}
|
|
|
|
|
2014-12-18 21:01:56 +00:00
|
|
|
int drm_mode_atomic_ioctl(struct drm_device *dev,
|
|
|
|
void *data, struct drm_file *file_priv)
|
|
|
|
{
|
|
|
|
struct drm_mode_atomic *arg = data;
|
|
|
|
uint32_t __user *objs_ptr = (uint32_t __user *)(unsigned long)(arg->objs_ptr);
|
|
|
|
uint32_t __user *count_props_ptr = (uint32_t __user *)(unsigned long)(arg->count_props_ptr);
|
|
|
|
uint32_t __user *props_ptr = (uint32_t __user *)(unsigned long)(arg->props_ptr);
|
|
|
|
uint64_t __user *prop_values_ptr = (uint64_t __user *)(unsigned long)(arg->prop_values_ptr);
|
|
|
|
unsigned int copied_objs, copied_props;
|
|
|
|
struct drm_atomic_state *state;
|
|
|
|
struct drm_modeset_acquire_ctx ctx;
|
|
|
|
struct drm_plane *plane;
|
2016-11-16 13:00:21 +00:00
|
|
|
struct drm_out_fence_state *fence_state = NULL;
|
2015-11-11 10:29:08 +00:00
|
|
|
unsigned plane_mask;
|
2014-12-18 21:01:56 +00:00
|
|
|
int ret = 0;
|
2016-11-16 13:00:21 +00:00
|
|
|
unsigned int i, j, num_fences = 0;
|
2014-12-18 21:01:56 +00:00
|
|
|
|
|
|
|
/* disallow for drivers not supporting atomic: */
|
|
|
|
if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* disallow for userspace that has not enabled atomic cap (even
|
|
|
|
* though this may be a bit overkill, since legacy userspace
|
|
|
|
* wouldn't know how to call this ioctl)
|
|
|
|
*/
|
|
|
|
if (!file_priv->atomic)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (arg->flags & ~DRM_MODE_ATOMIC_FLAGS)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (arg->reserved)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if ((arg->flags & DRM_MODE_PAGE_FLIP_ASYNC) &&
|
|
|
|
!dev->mode_config.async_page_flip)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* can't test and expect an event at the same time. */
|
|
|
|
if ((arg->flags & DRM_MODE_ATOMIC_TEST_ONLY) &&
|
|
|
|
(arg->flags & DRM_MODE_PAGE_FLIP_EVENT))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
drm_modeset_acquire_init(&ctx, 0);
|
|
|
|
|
|
|
|
state = drm_atomic_state_alloc(dev);
|
|
|
|
if (!state)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
state->acquire_ctx = &ctx;
|
|
|
|
state->allow_modeset = !!(arg->flags & DRM_MODE_ATOMIC_ALLOW_MODESET);
|
|
|
|
|
|
|
|
retry:
|
2015-11-11 10:29:08 +00:00
|
|
|
plane_mask = 0;
|
2014-12-18 21:01:56 +00:00
|
|
|
copied_objs = 0;
|
|
|
|
copied_props = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < arg->count_objs; i++) {
|
|
|
|
uint32_t obj_id, count_props;
|
|
|
|
struct drm_mode_object *obj;
|
|
|
|
|
|
|
|
if (get_user(obj_id, objs_ptr + copied_objs)) {
|
|
|
|
ret = -EFAULT;
|
2015-06-24 06:59:25 +00:00
|
|
|
goto out;
|
2014-12-18 21:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
obj = drm_mode_object_find(dev, obj_id, DRM_MODE_OBJECT_ANY);
|
2016-04-27 01:10:09 +00:00
|
|
|
if (!obj) {
|
|
|
|
ret = -ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!obj->properties) {
|
2017-02-28 14:46:38 +00:00
|
|
|
drm_mode_object_put(obj);
|
2014-12-18 21:01:56 +00:00
|
|
|
ret = -ENOENT;
|
2015-06-24 06:59:25 +00:00
|
|
|
goto out;
|
2014-12-18 21:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (get_user(count_props, count_props_ptr + copied_objs)) {
|
2017-02-28 14:46:38 +00:00
|
|
|
drm_mode_object_put(obj);
|
2014-12-18 21:01:56 +00:00
|
|
|
ret = -EFAULT;
|
2015-06-24 06:59:25 +00:00
|
|
|
goto out;
|
2014-12-18 21:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
copied_objs++;
|
|
|
|
|
|
|
|
for (j = 0; j < count_props; j++) {
|
|
|
|
uint32_t prop_id;
|
|
|
|
uint64_t prop_value;
|
|
|
|
struct drm_property *prop;
|
|
|
|
|
|
|
|
if (get_user(prop_id, props_ptr + copied_props)) {
|
2017-02-28 14:46:38 +00:00
|
|
|
drm_mode_object_put(obj);
|
2014-12-18 21:01:56 +00:00
|
|
|
ret = -EFAULT;
|
2015-06-24 06:59:25 +00:00
|
|
|
goto out;
|
2014-12-18 21:01:56 +00:00
|
|
|
}
|
|
|
|
|
2016-09-08 10:30:01 +00:00
|
|
|
prop = drm_mode_obj_find_prop_id(obj, prop_id);
|
2014-12-18 21:01:56 +00:00
|
|
|
if (!prop) {
|
2017-02-28 14:46:38 +00:00
|
|
|
drm_mode_object_put(obj);
|
2014-12-18 21:01:56 +00:00
|
|
|
ret = -ENOENT;
|
2015-06-24 06:59:25 +00:00
|
|
|
goto out;
|
2014-12-18 21:01:56 +00:00
|
|
|
}
|
|
|
|
|
2015-01-13 05:12:17 +00:00
|
|
|
if (copy_from_user(&prop_value,
|
|
|
|
prop_values_ptr + copied_props,
|
|
|
|
sizeof(prop_value))) {
|
2017-02-28 14:46:38 +00:00
|
|
|
drm_mode_object_put(obj);
|
2014-12-18 21:01:56 +00:00
|
|
|
ret = -EFAULT;
|
2015-06-24 06:59:25 +00:00
|
|
|
goto out;
|
2014-12-18 21:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = atomic_set_prop(state, obj, prop, prop_value);
|
2016-04-27 01:10:09 +00:00
|
|
|
if (ret) {
|
2017-02-28 14:46:38 +00:00
|
|
|
drm_mode_object_put(obj);
|
2015-06-24 06:59:25 +00:00
|
|
|
goto out;
|
2016-04-27 01:10:09 +00:00
|
|
|
}
|
2014-12-18 21:01:56 +00:00
|
|
|
|
|
|
|
copied_props++;
|
|
|
|
}
|
2015-06-24 06:59:24 +00:00
|
|
|
|
2015-08-31 10:25:04 +00:00
|
|
|
if (obj->type == DRM_MODE_OBJECT_PLANE && count_props &&
|
|
|
|
!(arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)) {
|
2015-06-24 06:59:24 +00:00
|
|
|
plane = obj_to_plane(obj);
|
|
|
|
plane_mask |= (1 << drm_plane_index(plane));
|
|
|
|
plane->old_fb = plane->fb;
|
|
|
|
}
|
2017-02-28 14:46:38 +00:00
|
|
|
drm_mode_object_put(obj);
|
2014-12-18 21:01:56 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 13:00:21 +00:00
|
|
|
ret = prepare_crtc_signaling(dev, state, arg, file_priv, &fence_state,
|
|
|
|
&num_fences);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
2014-12-18 21:01:56 +00:00
|
|
|
|
|
|
|
if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY) {
|
|
|
|
ret = drm_atomic_check_only(state);
|
|
|
|
} else if (arg->flags & DRM_MODE_ATOMIC_NONBLOCK) {
|
2016-04-26 14:11:35 +00:00
|
|
|
ret = drm_atomic_nonblocking_commit(state);
|
2014-12-18 21:01:56 +00:00
|
|
|
} else {
|
2016-11-05 15:08:09 +00:00
|
|
|
if (unlikely(drm_debug & DRM_UT_STATE))
|
|
|
|
drm_atomic_print_state(state);
|
|
|
|
|
2014-12-18 21:01:56 +00:00
|
|
|
ret = drm_atomic_commit(state);
|
|
|
|
}
|
|
|
|
|
2015-06-24 06:59:25 +00:00
|
|
|
out:
|
2015-11-11 10:29:09 +00:00
|
|
|
drm_atomic_clean_old_fb(dev, plane_mask, ret);
|
2014-12-18 21:01:56 +00:00
|
|
|
|
2016-11-16 13:00:21 +00:00
|
|
|
complete_crtc_signaling(dev, state, fence_state, num_fences, !ret);
|
2015-08-31 10:25:04 +00:00
|
|
|
|
2015-06-24 06:59:25 +00:00
|
|
|
if (ret == -EDEADLK) {
|
|
|
|
drm_atomic_state_clear(state);
|
|
|
|
drm_modeset_backoff(&ctx);
|
|
|
|
goto retry;
|
|
|
|
}
|
2014-12-18 21:01:56 +00:00
|
|
|
|
2016-10-14 12:18:18 +00:00
|
|
|
drm_atomic_state_put(state);
|
2014-12-18 21:01:56 +00:00
|
|
|
|
|
|
|
drm_modeset_drop_locks(&ctx);
|
|
|
|
drm_modeset_acquire_fini(&ctx);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|