2014-07-26 02:30:38 +07: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>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2019-05-27 00:35:35 +07:00
|
|
|
#include <linux/sync_file.h>
|
|
|
|
|
2014-07-26 02:30:38 +07:00
|
|
|
#include <drm/drm_atomic.h>
|
2018-09-05 20:57:11 +07:00
|
|
|
#include <drm/drm_atomic_uapi.h>
|
2019-05-27 00:35:35 +07:00
|
|
|
#include <drm/drm_debugfs.h>
|
|
|
|
#include <drm/drm_device.h>
|
|
|
|
#include <drm/drm_drv.h>
|
|
|
|
#include <drm/drm_file.h>
|
|
|
|
#include <drm/drm_fourcc.h>
|
2016-02-27 00:05:00 +07:00
|
|
|
#include <drm/drm_mode.h>
|
2016-11-05 22:08:09 +07:00
|
|
|
#include <drm/drm_print.h>
|
2017-03-29 23:42:32 +07:00
|
|
|
#include <drm/drm_writeback.h>
|
2014-07-26 02:30:38 +07:00
|
|
|
|
2016-04-28 20:19:56 +07:00
|
|
|
#include "drm_crtc_internal.h"
|
2017-11-08 02:13:41 +07:00
|
|
|
#include "drm_internal.h"
|
2016-04-28 20:19:56 +07:00
|
|
|
|
2016-12-21 20:03:35 +07:00
|
|
|
void __drm_crtc_commit_free(struct kref *kref)
|
2016-06-08 19:19:00 +07:00
|
|
|
{
|
|
|
|
struct drm_crtc_commit *commit =
|
|
|
|
container_of(kref, struct drm_crtc_commit, ref);
|
|
|
|
|
|
|
|
kfree(commit);
|
|
|
|
}
|
2016-12-21 20:03:35 +07:00
|
|
|
EXPORT_SYMBOL(__drm_crtc_commit_free);
|
2016-06-08 19:19:00 +07:00
|
|
|
|
2015-05-18 15:06:40 +07: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.
|
2017-12-15 03:30:53 +07:00
|
|
|
* This should only be used by drivers which are still subclassing
|
|
|
|
* &drm_atomic_state and haven't switched to &drm_private_state yet.
|
2015-05-18 15:06:40 +07:00
|
|
|
*/
|
|
|
|
void drm_atomic_state_default_release(struct drm_atomic_state *state)
|
2014-07-26 02:30:38 +07:00
|
|
|
{
|
|
|
|
kfree(state->connectors);
|
|
|
|
kfree(state->crtcs);
|
|
|
|
kfree(state->planes);
|
2017-04-21 12:51:30 +07:00
|
|
|
kfree(state->private_objs);
|
2014-07-26 02:30:38 +07:00
|
|
|
}
|
2015-05-18 15:06:40 +07:00
|
|
|
EXPORT_SYMBOL(drm_atomic_state_default_release);
|
2014-07-26 02:30:38 +07:00
|
|
|
|
|
|
|
/**
|
2015-05-18 15:06:40 +07:00
|
|
|
* drm_atomic_state_init - init new atomic state
|
2014-07-26 02:30:38 +07:00
|
|
|
* @dev: DRM device
|
2015-05-18 15:06:40 +07:00
|
|
|
* @state: atomic state
|
2014-07-26 02:30:38 +07:00
|
|
|
*
|
2015-05-18 15:06:40 +07:00
|
|
|
* Default implementation for filling in a new atomic state.
|
2017-12-15 03:30:53 +07:00
|
|
|
* This should only be used by drivers which are still subclassing
|
|
|
|
* &drm_atomic_state and haven't switched to &drm_private_state yet.
|
2014-07-26 02:30:38 +07:00
|
|
|
*/
|
2015-05-18 15:06:40 +07:00
|
|
|
int
|
|
|
|
drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state)
|
2014-07-26 02:30:38 +07:00
|
|
|
{
|
2016-10-14 19:18:18 +07:00
|
|
|
kref_init(&state->ref);
|
|
|
|
|
2014-12-19 04:01:56 +07:00
|
|
|
/* TODO legacy paths should maybe do a better job about
|
|
|
|
* setting this appropriately?
|
|
|
|
*/
|
|
|
|
state->allow_modeset = true;
|
|
|
|
|
2014-07-26 02:30:38 +07: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 15:06:40 +07:00
|
|
|
DRM_DEBUG_ATOMIC("Allocated atomic state %p\n", state);
|
2014-07-26 02:30:38 +07:00
|
|
|
|
2015-05-18 15:06:40 +07:00
|
|
|
return 0;
|
2014-07-26 02:30:38 +07:00
|
|
|
fail:
|
2015-05-18 15:06:40 +07: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;
|
|
|
|
|
|
|
|
if (!config->funcs->atomic_state_alloc) {
|
2017-06-16 00:45:56 +07:00
|
|
|
struct drm_atomic_state *state;
|
|
|
|
|
2015-05-18 15:06:40 +07:00
|
|
|
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-26 02:30:38 +07:00
|
|
|
|
2015-05-18 15:06:40 +07:00
|
|
|
return config->funcs->atomic_state_alloc(dev);
|
2014-07-26 02:30:38 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_state_alloc);
|
|
|
|
|
|
|
|
/**
|
2015-05-18 15:06:40 +07:00
|
|
|
* drm_atomic_state_default_clear - clear base atomic state
|
2014-07-26 02:30:38 +07:00
|
|
|
* @state: atomic state
|
|
|
|
*
|
2015-05-18 15:06:40 +07:00
|
|
|
* Default implementation for clearing atomic state.
|
2017-12-15 03:30:53 +07:00
|
|
|
* This should only be used by drivers which are still subclassing
|
|
|
|
* &drm_atomic_state and haven't switched to &drm_private_state yet.
|
2014-07-26 02:30:38 +07:00
|
|
|
*/
|
2015-05-18 15:06:40 +07:00
|
|
|
void drm_atomic_state_default_clear(struct drm_atomic_state *state)
|
2014-07-26 02:30:38 +07:00
|
|
|
{
|
|
|
|
struct drm_device *dev = state->dev;
|
2014-11-20 00:38:07 +07:00
|
|
|
struct drm_mode_config *config = &dev->mode_config;
|
2014-07-26 02:30:38 +07:00
|
|
|
int i;
|
|
|
|
|
2015-02-22 18:24:16 +07:00
|
|
|
DRM_DEBUG_ATOMIC("Clearing atomic state %p\n", state);
|
2014-07-26 02:30:38 +07:00
|
|
|
|
2014-11-20 00:38:08 +07:00
|
|
|
for (i = 0; i < state->num_connector; i++) {
|
2016-06-02 05:06:32 +07:00
|
|
|
struct drm_connector *connector = state->connectors[i].ptr;
|
2014-07-26 02:30:38 +07:00
|
|
|
|
|
|
|
if (!connector)
|
|
|
|
continue;
|
|
|
|
|
2016-04-27 08:27:39 +07:00
|
|
|
connector->funcs->atomic_destroy_state(connector,
|
2016-06-02 05:06:32 +07:00
|
|
|
state->connectors[i].state);
|
|
|
|
state->connectors[i].ptr = NULL;
|
|
|
|
state->connectors[i].state = NULL;
|
2018-05-03 01:32:47 +07:00
|
|
|
state->connectors[i].old_state = NULL;
|
|
|
|
state->connectors[i].new_state = NULL;
|
2017-02-28 21:46:39 +07:00
|
|
|
drm_connector_put(connector);
|
2014-07-26 02:30:38 +07:00
|
|
|
}
|
|
|
|
|
2014-11-20 00:38:07 +07:00
|
|
|
for (i = 0; i < config->num_crtc; i++) {
|
2016-06-02 05:06:34 +07:00
|
|
|
struct drm_crtc *crtc = state->crtcs[i].ptr;
|
2014-07-26 02:30:38 +07:00
|
|
|
|
|
|
|
if (!crtc)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
crtc->funcs->atomic_destroy_state(crtc,
|
2016-06-02 05:06:34 +07:00
|
|
|
state->crtcs[i].state);
|
2016-06-08 19:19:00 +07:00
|
|
|
|
2016-06-02 05:06:34 +07:00
|
|
|
state->crtcs[i].ptr = NULL;
|
|
|
|
state->crtcs[i].state = NULL;
|
2018-05-03 01:32:47 +07:00
|
|
|
state->crtcs[i].old_state = NULL;
|
|
|
|
state->crtcs[i].new_state = NULL;
|
2018-10-15 20:46:40 +07:00
|
|
|
|
|
|
|
if (state->crtcs[i].commit) {
|
|
|
|
drm_crtc_commit_put(state->crtcs[i].commit);
|
|
|
|
state->crtcs[i].commit = NULL;
|
|
|
|
}
|
2014-07-26 02:30:38 +07:00
|
|
|
}
|
|
|
|
|
2014-11-20 00:38:07 +07:00
|
|
|
for (i = 0; i < config->num_total_plane; i++) {
|
2016-06-02 05:06:33 +07:00
|
|
|
struct drm_plane *plane = state->planes[i].ptr;
|
2014-07-26 02:30:38 +07:00
|
|
|
|
|
|
|
if (!plane)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
plane->funcs->atomic_destroy_state(plane,
|
2016-06-02 05:06:33 +07:00
|
|
|
state->planes[i].state);
|
|
|
|
state->planes[i].ptr = NULL;
|
|
|
|
state->planes[i].state = NULL;
|
2018-05-03 01:32:47 +07:00
|
|
|
state->planes[i].old_state = NULL;
|
|
|
|
state->planes[i].new_state = NULL;
|
2014-07-26 02:30:38 +07:00
|
|
|
}
|
2017-04-21 12:51:30 +07:00
|
|
|
|
|
|
|
for (i = 0; i < state->num_private_objs; i++) {
|
2017-07-12 22:51:02 +07:00
|
|
|
struct drm_private_obj *obj = state->private_objs[i].ptr;
|
2017-04-21 12:51:30 +07:00
|
|
|
|
2017-07-12 22:51:02 +07:00
|
|
|
obj->funcs->atomic_destroy_state(obj,
|
|
|
|
state->private_objs[i].state);
|
|
|
|
state->private_objs[i].ptr = NULL;
|
|
|
|
state->private_objs[i].state = NULL;
|
2018-05-03 01:32:47 +07:00
|
|
|
state->private_objs[i].old_state = NULL;
|
|
|
|
state->private_objs[i].new_state = NULL;
|
2017-04-21 12:51:30 +07:00
|
|
|
}
|
|
|
|
state->num_private_objs = 0;
|
|
|
|
|
2017-09-04 17:48:37 +07:00
|
|
|
if (state->fake_commit) {
|
|
|
|
drm_crtc_commit_put(state->fake_commit);
|
|
|
|
state->fake_commit = NULL;
|
|
|
|
}
|
2014-07-26 02:30:38 +07:00
|
|
|
}
|
2015-05-18 15:06:40 +07: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 13:26:45 +07:00
|
|
|
* state. Which could break assumptions the driver's
|
|
|
|
* &drm_mode_config_funcs.atomic_check likely relies on.
|
2015-05-18 15:06:40 +07: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-26 02:30:38 +07:00
|
|
|
EXPORT_SYMBOL(drm_atomic_state_clear);
|
|
|
|
|
|
|
|
/**
|
2016-10-14 19:18:18 +07:00
|
|
|
* __drm_atomic_state_free - free all memory for an atomic state
|
|
|
|
* @ref: This atomic state to deallocate
|
2014-07-26 02:30:38 +07:00
|
|
|
*
|
|
|
|
* This frees all memory associated with an atomic state, including all the
|
|
|
|
* per-object state for planes, crtcs and connectors.
|
|
|
|
*/
|
2016-10-14 19:18:18 +07:00
|
|
|
void __drm_atomic_state_free(struct kref *ref)
|
2014-07-26 02:30:38 +07:00
|
|
|
{
|
2016-10-14 19:18:18 +07:00
|
|
|
struct drm_atomic_state *state = container_of(ref, typeof(*state), ref);
|
|
|
|
struct drm_mode_config *config = &state->dev->mode_config;
|
2015-05-18 15:06:40 +07:00
|
|
|
|
2014-07-26 02:30:38 +07:00
|
|
|
drm_atomic_state_clear(state);
|
|
|
|
|
2015-02-22 18:24:16 +07:00
|
|
|
DRM_DEBUG_ATOMIC("Freeing atomic state %p\n", state);
|
2014-07-26 02:30:38 +07:00
|
|
|
|
2015-05-18 15:06:40 +07:00
|
|
|
if (config->funcs->atomic_state_free) {
|
|
|
|
config->funcs->atomic_state_free(state);
|
|
|
|
} else {
|
|
|
|
drm_atomic_state_default_release(state);
|
|
|
|
kfree(state);
|
|
|
|
}
|
2014-07-26 02:30:38 +07:00
|
|
|
}
|
2016-10-14 19:18:18 +07:00
|
|
|
EXPORT_SYMBOL(__drm_atomic_state_free);
|
2014-07-26 02:30:38 +07: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 15:37:25 +07:00
|
|
|
int ret, index = drm_crtc_index(crtc);
|
2014-07-26 02:30:38 +07:00
|
|
|
struct drm_crtc_state *crtc_state;
|
|
|
|
|
2016-05-03 16:12:31 +07:00
|
|
|
WARN_ON(!state->acquire_ctx);
|
|
|
|
|
2015-05-13 15:37:25 +07:00
|
|
|
crtc_state = drm_atomic_get_existing_crtc_state(state, crtc);
|
|
|
|
if (crtc_state)
|
|
|
|
return crtc_state;
|
2014-07-26 02:30:38 +07: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-02 05:06:34 +07:00
|
|
|
state->crtcs[index].state = crtc_state;
|
2017-01-16 16:37:38 +07:00
|
|
|
state->crtcs[index].old_state = crtc->state;
|
|
|
|
state->crtcs[index].new_state = crtc_state;
|
2016-06-02 05:06:34 +07:00
|
|
|
state->crtcs[index].ptr = crtc;
|
2014-07-26 02:30:38 +07:00
|
|
|
crtc_state->state = state;
|
|
|
|
|
2015-12-08 23:41:53 +07:00
|
|
|
DRM_DEBUG_ATOMIC("Added [CRTC:%d:%s] %p state to %p\n",
|
|
|
|
crtc->base.id, crtc->name, crtc_state, state);
|
2014-07-26 02:30:38 +07:00
|
|
|
|
|
|
|
return crtc_state;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_get_crtc_state);
|
|
|
|
|
2018-11-02 01:46:45 +07:00
|
|
|
static int drm_atomic_crtc_check(const struct drm_crtc_state *old_crtc_state,
|
|
|
|
const struct drm_crtc_state *new_crtc_state)
|
2014-12-19 04:01:51 +07:00
|
|
|
{
|
2018-11-02 01:46:45 +07:00
|
|
|
struct drm_crtc *crtc = new_crtc_state->crtc;
|
|
|
|
|
2014-12-19 04:01:51 +07:00
|
|
|
/* 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 22:36:21 +07:00
|
|
|
|
2018-11-02 01:46:45 +07:00
|
|
|
if (new_crtc_state->active && !new_crtc_state->enable) {
|
2015-12-08 23:41:53 +07:00
|
|
|
DRM_DEBUG_ATOMIC("[CRTC:%d:%s] active without enabled\n",
|
|
|
|
crtc->base.id, crtc->name);
|
2015-01-22 22:36:21 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-05-26 01:11:51 +07: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) &&
|
2018-11-02 01:46:45 +07:00
|
|
|
WARN_ON(new_crtc_state->enable && !new_crtc_state->mode_blob)) {
|
2015-12-08 23:41:53 +07:00
|
|
|
DRM_DEBUG_ATOMIC("[CRTC:%d:%s] enabled without mode blob\n",
|
|
|
|
crtc->base.id, crtc->name);
|
2015-05-26 01:11:51 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) &&
|
2018-11-02 01:46:45 +07:00
|
|
|
WARN_ON(!new_crtc_state->enable && new_crtc_state->mode_blob)) {
|
2015-12-08 23:41:53 +07:00
|
|
|
DRM_DEBUG_ATOMIC("[CRTC:%d:%s] disabled with mode blob\n",
|
|
|
|
crtc->base.id, crtc->name);
|
2015-05-26 01:11:51 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-12-08 15:49:20 +07: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.
|
|
|
|
*/
|
2018-11-02 01:46:45 +07:00
|
|
|
if (new_crtc_state->event &&
|
|
|
|
!new_crtc_state->active && !old_crtc_state->active) {
|
2017-02-13 19:27:03 +07:00
|
|
|
DRM_DEBUG_ATOMIC("[CRTC:%d:%s] requesting event but off\n",
|
|
|
|
crtc->base.id, crtc->name);
|
2015-12-08 15:49:20 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-12-19 04:01:51 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-05 22:08:09 +07: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);
|
2019-06-12 21:50:19 +07:00
|
|
|
drm_printf(p, "\tself_refresh_active=%d\n", state->self_refresh_active);
|
2016-11-05 22:08:09 +07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-03-29 23:42:32 +07:00
|
|
|
static int drm_atomic_connector_check(struct drm_connector *connector,
|
|
|
|
struct drm_connector_state *state)
|
|
|
|
{
|
|
|
|
struct drm_crtc_state *crtc_state;
|
|
|
|
struct drm_writeback_job *writeback_job = state->writeback_job;
|
2018-10-13 01:42:32 +07:00
|
|
|
const struct drm_display_info *info = &connector->display_info;
|
|
|
|
|
|
|
|
state->max_bpc = info->bpc ? info->bpc : 8;
|
|
|
|
if (connector->max_bpc_property)
|
|
|
|
state->max_bpc = min(state->max_bpc, state->max_requested_bpc);
|
2017-03-29 23:42:32 +07:00
|
|
|
|
|
|
|
if ((connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK) || !writeback_job)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (writeback_job->fb && !state->crtc) {
|
|
|
|
DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] framebuffer without CRTC\n",
|
|
|
|
connector->base.id, connector->name);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state->crtc)
|
|
|
|
crtc_state = drm_atomic_get_existing_crtc_state(state->state,
|
|
|
|
state->crtc);
|
|
|
|
|
|
|
|
if (writeback_job->fb && !crtc_state->active) {
|
|
|
|
DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] has framebuffer, but [CRTC:%d] is off\n",
|
|
|
|
connector->base.id, connector->name,
|
|
|
|
state->crtc->base.id);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-03-29 23:42:33 +07:00
|
|
|
if (writeback_job->out_fence && !writeback_job->fb) {
|
|
|
|
DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] requesting out-fence without framebuffer\n",
|
|
|
|
connector->base.id, connector->name);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-03-29 23:42:32 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-26 02:30:38 +07: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 15:37:25 +07:00
|
|
|
int ret, index = drm_plane_index(plane);
|
2014-07-26 02:30:38 +07:00
|
|
|
struct drm_plane_state *plane_state;
|
|
|
|
|
2016-05-03 16:12:31 +07:00
|
|
|
WARN_ON(!state->acquire_ctx);
|
|
|
|
|
2018-05-26 01:50:45 +07:00
|
|
|
/* the legacy pointers should never be set */
|
|
|
|
WARN_ON(plane->fb);
|
|
|
|
WARN_ON(plane->old_fb);
|
|
|
|
WARN_ON(plane->crtc);
|
|
|
|
|
2015-05-13 15:37:25 +07:00
|
|
|
plane_state = drm_atomic_get_existing_plane_state(state, plane);
|
|
|
|
if (plane_state)
|
|
|
|
return plane_state;
|
2014-07-26 02:30:38 +07:00
|
|
|
|
2014-11-11 16:12:00 +07:00
|
|
|
ret = drm_modeset_lock(&plane->mutex, state->acquire_ctx);
|
2014-07-26 02:30:38 +07:00
|
|
|
if (ret)
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
|
|
|
|
plane_state = plane->funcs->atomic_duplicate_state(plane);
|
|
|
|
if (!plane_state)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2016-06-02 05:06:33 +07:00
|
|
|
state->planes[index].state = plane_state;
|
|
|
|
state->planes[index].ptr = plane;
|
2017-01-16 16:37:38 +07:00
|
|
|
state->planes[index].old_state = plane->state;
|
|
|
|
state->planes[index].new_state = plane_state;
|
2014-07-26 02:30:38 +07:00
|
|
|
plane_state->state = state;
|
|
|
|
|
2015-12-08 23:41:54 +07:00
|
|
|
DRM_DEBUG_ATOMIC("Added [PLANE:%d:%s] %p state to %p\n",
|
|
|
|
plane->base.id, plane->name, plane_state, state);
|
2014-07-26 02:30:38 +07: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);
|
|
|
|
|
2015-08-27 02:49:42 +07:00
|
|
|
static bool
|
2018-11-07 02:16:24 +07:00
|
|
|
plane_switching_crtc(const struct drm_plane_state *old_plane_state,
|
|
|
|
const struct drm_plane_state *new_plane_state)
|
2015-08-27 02:49:42 +07:00
|
|
|
{
|
2018-11-07 02:16:24 +07:00
|
|
|
if (!old_plane_state->crtc || !new_plane_state->crtc)
|
2015-08-27 02:49:42 +07:00
|
|
|
return false;
|
|
|
|
|
2018-11-07 02:16:24 +07:00
|
|
|
if (old_plane_state->crtc == new_plane_state->crtc)
|
2015-08-27 02:49:42 +07:00
|
|
|
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-19 04:01:51 +07:00
|
|
|
/**
|
|
|
|
* drm_atomic_plane_check - check plane state
|
2018-11-07 02:16:24 +07:00
|
|
|
* @old_plane_state: old plane state to check
|
|
|
|
* @new_plane_state: new plane state to check
|
2014-12-19 04:01:51 +07:00
|
|
|
*
|
|
|
|
* Provides core sanity checks for plane state.
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* Zero on success, error code on failure
|
|
|
|
*/
|
2018-11-07 02:16:24 +07:00
|
|
|
static int drm_atomic_plane_check(const struct drm_plane_state *old_plane_state,
|
|
|
|
const struct drm_plane_state *new_plane_state)
|
2014-12-19 04:01:51 +07:00
|
|
|
{
|
2018-11-07 02:16:24 +07:00
|
|
|
struct drm_plane *plane = new_plane_state->plane;
|
|
|
|
struct drm_crtc *crtc = new_plane_state->crtc;
|
|
|
|
const struct drm_framebuffer *fb = new_plane_state->fb;
|
2014-12-19 04:01:51 +07:00
|
|
|
unsigned int fb_width, fb_height;
|
2018-05-24 09:04:08 +07:00
|
|
|
struct drm_mode_rect *clips;
|
|
|
|
uint32_t num_clips;
|
2015-03-05 07:25:43 +07:00
|
|
|
int ret;
|
2014-12-19 04:01:51 +07:00
|
|
|
|
|
|
|
/* either *both* CRTC and FB must be set, or neither */
|
2018-11-07 02:16:24 +07:00
|
|
|
if (crtc && !fb) {
|
2018-06-12 02:34:01 +07:00
|
|
|
DRM_DEBUG_ATOMIC("[PLANE:%d:%s] CRTC set but no FB\n",
|
|
|
|
plane->base.id, plane->name);
|
2014-12-19 04:01:51 +07:00
|
|
|
return -EINVAL;
|
2018-11-07 02:16:24 +07:00
|
|
|
} else if (fb && !crtc) {
|
2018-06-12 02:34:01 +07:00
|
|
|
DRM_DEBUG_ATOMIC("[PLANE:%d:%s] FB set but no CRTC\n",
|
|
|
|
plane->base.id, plane->name);
|
2014-12-19 04:01:51 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if disabled, we don't care about the rest of the state: */
|
2018-11-07 02:16:24 +07:00
|
|
|
if (!crtc)
|
2014-12-19 04:01:51 +07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Check whether this plane is usable on this CRTC */
|
2018-11-07 02:16:24 +07:00
|
|
|
if (!(plane->possible_crtcs & drm_crtc_mask(crtc))) {
|
2018-06-12 02:34:01 +07:00
|
|
|
DRM_DEBUG_ATOMIC("Invalid [CRTC:%d:%s] for [PLANE:%d:%s]\n",
|
2018-11-07 02:16:24 +07:00
|
|
|
crtc->base.id, crtc->name,
|
2018-06-12 02:34:01 +07:00
|
|
|
plane->base.id, plane->name);
|
2014-12-19 04:01:51 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check whether this plane supports the fb pixel format. */
|
2018-11-07 02:16:24 +07:00
|
|
|
ret = drm_plane_check_pixel_format(plane, fb->format->format,
|
|
|
|
fb->modifier);
|
2015-03-05 07:25:43 +07:00
|
|
|
if (ret) {
|
2016-11-12 08:12:56 +07:00
|
|
|
struct drm_format_name_buf format_name;
|
2018-06-12 02:34:01 +07:00
|
|
|
DRM_DEBUG_ATOMIC("[PLANE:%d:%s] invalid pixel format %s, modifier 0x%llx\n",
|
|
|
|
plane->base.id, plane->name,
|
2018-11-07 02:16:24 +07:00
|
|
|
drm_get_format_name(fb->format->format,
|
2017-12-23 02:22:30 +07:00
|
|
|
&format_name),
|
2018-11-07 02:16:24 +07:00
|
|
|
fb->modifier);
|
2015-03-05 07:25:43 +07:00
|
|
|
return ret;
|
2014-12-19 04:01:51 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Give drivers some help against integer overflows */
|
2018-11-07 02:16:24 +07:00
|
|
|
if (new_plane_state->crtc_w > INT_MAX ||
|
|
|
|
new_plane_state->crtc_x > INT_MAX - (int32_t) new_plane_state->crtc_w ||
|
|
|
|
new_plane_state->crtc_h > INT_MAX ||
|
|
|
|
new_plane_state->crtc_y > INT_MAX - (int32_t) new_plane_state->crtc_h) {
|
2018-06-12 02:34:01 +07:00
|
|
|
DRM_DEBUG_ATOMIC("[PLANE:%d:%s] invalid CRTC coordinates %ux%u+%d+%d\n",
|
|
|
|
plane->base.id, plane->name,
|
2018-11-07 02:16:24 +07:00
|
|
|
new_plane_state->crtc_w, new_plane_state->crtc_h,
|
|
|
|
new_plane_state->crtc_x, new_plane_state->crtc_y);
|
2014-12-19 04:01:51 +07:00
|
|
|
return -ERANGE;
|
|
|
|
}
|
|
|
|
|
2018-11-07 02:16:24 +07:00
|
|
|
fb_width = fb->width << 16;
|
|
|
|
fb_height = fb->height << 16;
|
2014-12-19 04:01:51 +07:00
|
|
|
|
|
|
|
/* Make sure source coordinates are inside the fb. */
|
2018-11-07 02:16:24 +07:00
|
|
|
if (new_plane_state->src_w > fb_width ||
|
|
|
|
new_plane_state->src_x > fb_width - new_plane_state->src_w ||
|
|
|
|
new_plane_state->src_h > fb_height ||
|
|
|
|
new_plane_state->src_y > fb_height - new_plane_state->src_h) {
|
2018-06-12 02:34:01 +07:00
|
|
|
DRM_DEBUG_ATOMIC("[PLANE:%d:%s] invalid source coordinates "
|
2017-11-02 01:35:33 +07:00
|
|
|
"%u.%06ux%u.%06u+%u.%06u+%u.%06u (fb %ux%u)\n",
|
2018-06-12 02:34:01 +07:00
|
|
|
plane->base.id, plane->name,
|
2018-11-07 02:16:24 +07:00
|
|
|
new_plane_state->src_w >> 16,
|
|
|
|
((new_plane_state->src_w & 0xffff) * 15625) >> 10,
|
|
|
|
new_plane_state->src_h >> 16,
|
|
|
|
((new_plane_state->src_h & 0xffff) * 15625) >> 10,
|
|
|
|
new_plane_state->src_x >> 16,
|
|
|
|
((new_plane_state->src_x & 0xffff) * 15625) >> 10,
|
|
|
|
new_plane_state->src_y >> 16,
|
|
|
|
((new_plane_state->src_y & 0xffff) * 15625) >> 10,
|
|
|
|
fb->width, fb->height);
|
2014-12-19 04:01:51 +07:00
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
|
2018-05-24 09:04:08 +07:00
|
|
|
clips = drm_plane_get_damage_clips(new_plane_state);
|
|
|
|
num_clips = drm_plane_get_damage_clips_count(new_plane_state);
|
|
|
|
|
|
|
|
/* Make sure damage clips are valid and inside the fb. */
|
|
|
|
while (num_clips > 0) {
|
|
|
|
if (clips->x1 >= clips->x2 ||
|
|
|
|
clips->y1 >= clips->y2 ||
|
|
|
|
clips->x1 < 0 ||
|
|
|
|
clips->y1 < 0 ||
|
|
|
|
clips->x2 > fb_width ||
|
|
|
|
clips->y2 > fb_height) {
|
|
|
|
DRM_DEBUG_ATOMIC("[PLANE:%d:%s] invalid damage clip %d %d %d %d\n",
|
|
|
|
plane->base.id, plane->name, clips->x1,
|
|
|
|
clips->y1, clips->x2, clips->y2);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
clips++;
|
|
|
|
num_clips--;
|
|
|
|
}
|
|
|
|
|
2018-11-07 02:16:24 +07:00
|
|
|
if (plane_switching_crtc(old_plane_state, new_plane_state)) {
|
2015-12-08 23:41:54 +07:00
|
|
|
DRM_DEBUG_ATOMIC("[PLANE:%d:%s] switching CRTC directly\n",
|
|
|
|
plane->base.id, plane->name);
|
2015-08-27 02:49:42 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-12-19 04:01:51 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-05 22:08:09 +07: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);
|
2017-11-08 02:13:41 +07:00
|
|
|
if (state->fb)
|
|
|
|
drm_framebuffer_print_info(p, 2, state->fb);
|
2016-11-05 22:08:09 +07:00
|
|
|
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);
|
2018-06-05 20:54:01 +07:00
|
|
|
drm_printf(p, "\tnormalized-zpos=%x\n", state->normalized_zpos);
|
2018-02-20 03:28:46 +07:00
|
|
|
drm_printf(p, "\tcolor-encoding=%s\n",
|
|
|
|
drm_get_color_encoding_name(state->color_encoding));
|
|
|
|
drm_printf(p, "\tcolor-range=%s\n",
|
|
|
|
drm_get_color_range_name(state->color_range));
|
2016-11-05 22:08:09 +07:00
|
|
|
|
|
|
|
if (plane->funcs->atomic_print_state)
|
|
|
|
plane->funcs->atomic_print_state(p, state);
|
|
|
|
}
|
|
|
|
|
2017-12-15 03:30:53 +07:00
|
|
|
/**
|
|
|
|
* DOC: handling driver private state
|
|
|
|
*
|
|
|
|
* Very often the DRM objects exposed to userspace in the atomic modeset api
|
|
|
|
* (&drm_connector, &drm_crtc and &drm_plane) do not map neatly to the
|
|
|
|
* underlying hardware. Especially for any kind of shared resources (e.g. shared
|
|
|
|
* clocks, scaler units, bandwidth and fifo limits shared among a group of
|
|
|
|
* planes or CRTCs, and so on) it makes sense to model these as independent
|
|
|
|
* objects. Drivers then need to do similar state tracking and commit ordering for
|
|
|
|
* such private (since not exposed to userpace) objects as the atomic core and
|
|
|
|
* helpers already provide for connectors, planes and CRTCs.
|
|
|
|
*
|
|
|
|
* To make this easier on drivers the atomic core provides some support to track
|
|
|
|
* driver private state objects using struct &drm_private_obj, with the
|
|
|
|
* associated state struct &drm_private_state.
|
|
|
|
*
|
|
|
|
* Similar to userspace-exposed objects, private state structures can be
|
|
|
|
* acquired by calling drm_atomic_get_private_obj_state(). Since this function
|
|
|
|
* does not take care of locking, drivers should wrap it for each type of
|
|
|
|
* private state object they have with the required call to drm_modeset_lock()
|
|
|
|
* for the corresponding &drm_modeset_lock.
|
|
|
|
*
|
|
|
|
* All private state structures contained in a &drm_atomic_state update can be
|
|
|
|
* iterated using for_each_oldnew_private_obj_in_state(),
|
|
|
|
* for_each_new_private_obj_in_state() and for_each_old_private_obj_in_state().
|
|
|
|
* Drivers are recommended to wrap these for each type of driver private state
|
|
|
|
* object they have, filtering on &drm_private_obj.funcs using for_each_if(), at
|
|
|
|
* least if they want to iterate over all objects of a given type.
|
|
|
|
*
|
|
|
|
* An earlier way to handle driver private state was by subclassing struct
|
|
|
|
* &drm_atomic_state. But since that encourages non-standard ways to implement
|
|
|
|
* the check/commit split atomic requires (by using e.g. "check and rollback or
|
|
|
|
* commit instead" of "duplicate state, check, then either commit or release
|
|
|
|
* duplicated state) it is deprecated in favour of using &drm_private_state.
|
|
|
|
*/
|
|
|
|
|
2017-07-12 22:51:02 +07:00
|
|
|
/**
|
|
|
|
* drm_atomic_private_obj_init - initialize private object
|
2018-10-22 19:31:22 +07:00
|
|
|
* @dev: DRM device this object will be attached to
|
2017-07-12 22:51:02 +07:00
|
|
|
* @obj: private object
|
|
|
|
* @state: initial private object state
|
|
|
|
* @funcs: pointer to the struct of function pointers that identify the object
|
|
|
|
* type
|
|
|
|
*
|
|
|
|
* Initialize the private object, which can be embedded into any
|
|
|
|
* driver private object that needs its own atomic state.
|
|
|
|
*/
|
|
|
|
void
|
2018-10-22 19:31:22 +07:00
|
|
|
drm_atomic_private_obj_init(struct drm_device *dev,
|
|
|
|
struct drm_private_obj *obj,
|
2017-07-12 22:51:02 +07:00
|
|
|
struct drm_private_state *state,
|
|
|
|
const struct drm_private_state_funcs *funcs)
|
|
|
|
{
|
|
|
|
memset(obj, 0, sizeof(*obj));
|
|
|
|
|
2018-10-22 19:31:22 +07:00
|
|
|
drm_modeset_lock_init(&obj->lock);
|
|
|
|
|
2017-07-12 22:51:02 +07:00
|
|
|
obj->state = state;
|
|
|
|
obj->funcs = funcs;
|
2018-10-22 19:31:22 +07:00
|
|
|
list_add_tail(&obj->head, &dev->mode_config.privobj_list);
|
2017-07-12 22:51:02 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_private_obj_init);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_atomic_private_obj_fini - finalize private object
|
|
|
|
* @obj: private object
|
|
|
|
*
|
|
|
|
* Finalize the private object.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
drm_atomic_private_obj_fini(struct drm_private_obj *obj)
|
|
|
|
{
|
2018-10-22 19:31:22 +07:00
|
|
|
list_del(&obj->head);
|
2017-07-12 22:51:02 +07:00
|
|
|
obj->funcs->atomic_destroy_state(obj, obj->state);
|
2018-10-22 19:31:22 +07:00
|
|
|
drm_modeset_lock_fini(&obj->lock);
|
2017-07-12 22:51:02 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_private_obj_fini);
|
|
|
|
|
2017-04-21 12:51:30 +07:00
|
|
|
/**
|
|
|
|
* drm_atomic_get_private_obj_state - get private object state
|
|
|
|
* @state: global atomic state
|
|
|
|
* @obj: private object to get the state for
|
|
|
|
*
|
|
|
|
* This function returns the private object state for the given private object,
|
2018-10-22 19:31:22 +07:00
|
|
|
* allocating the state if needed. It will also grab the relevant private
|
|
|
|
* object lock to make sure that the state is consistent.
|
2017-04-21 12:51:30 +07:00
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
*
|
|
|
|
* Either the allocated state or the error code encoded into a pointer.
|
|
|
|
*/
|
2017-07-12 22:51:02 +07:00
|
|
|
struct drm_private_state *
|
|
|
|
drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
|
|
|
|
struct drm_private_obj *obj)
|
2017-04-21 12:51:30 +07:00
|
|
|
{
|
2018-10-22 19:31:22 +07:00
|
|
|
int index, num_objs, i, ret;
|
2017-04-21 12:51:30 +07:00
|
|
|
size_t size;
|
|
|
|
struct __drm_private_objs_state *arr;
|
2017-07-12 22:51:02 +07:00
|
|
|
struct drm_private_state *obj_state;
|
2017-04-21 12:51:30 +07:00
|
|
|
|
|
|
|
for (i = 0; i < state->num_private_objs; i++)
|
2017-07-12 22:51:02 +07:00
|
|
|
if (obj == state->private_objs[i].ptr)
|
|
|
|
return state->private_objs[i].state;
|
2017-04-21 12:51:30 +07:00
|
|
|
|
2018-10-22 19:31:22 +07:00
|
|
|
ret = drm_modeset_lock(&obj->lock, state->acquire_ctx);
|
|
|
|
if (ret)
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
|
2017-04-21 12:51:30 +07:00
|
|
|
num_objs = state->num_private_objs + 1;
|
|
|
|
size = sizeof(*state->private_objs) * num_objs;
|
|
|
|
arr = krealloc(state->private_objs, size, GFP_KERNEL);
|
|
|
|
if (!arr)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
state->private_objs = arr;
|
|
|
|
index = state->num_private_objs;
|
|
|
|
memset(&state->private_objs[index], 0, sizeof(*state->private_objs));
|
|
|
|
|
2017-07-12 22:51:02 +07:00
|
|
|
obj_state = obj->funcs->atomic_duplicate_state(obj);
|
|
|
|
if (!obj_state)
|
2017-04-21 12:51:30 +07:00
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2017-07-12 22:51:02 +07:00
|
|
|
state->private_objs[index].state = obj_state;
|
|
|
|
state->private_objs[index].old_state = obj->state;
|
|
|
|
state->private_objs[index].new_state = obj_state;
|
|
|
|
state->private_objs[index].ptr = obj;
|
2018-05-31 00:30:52 +07:00
|
|
|
obj_state->state = state;
|
2017-07-12 22:51:02 +07:00
|
|
|
|
2017-04-21 12:51:30 +07:00
|
|
|
state->num_private_objs = num_objs;
|
|
|
|
|
2017-07-12 22:51:02 +07:00
|
|
|
DRM_DEBUG_ATOMIC("Added new private object %p state %p to %p\n",
|
|
|
|
obj, obj_state, state);
|
2017-04-21 12:51:30 +07:00
|
|
|
|
2017-07-12 22:51:02 +07:00
|
|
|
return obj_state;
|
2017-04-21 12:51:30 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_get_private_obj_state);
|
|
|
|
|
2019-01-22 18:05:41 +07:00
|
|
|
/**
|
|
|
|
* drm_atomic_get_old_private_obj_state
|
|
|
|
* @state: global atomic state object
|
|
|
|
* @obj: private_obj to grab
|
|
|
|
*
|
|
|
|
* This function returns the old private object state for the given private_obj,
|
|
|
|
* or NULL if the private_obj is not part of the global atomic state.
|
|
|
|
*/
|
|
|
|
struct drm_private_state *
|
|
|
|
drm_atomic_get_old_private_obj_state(struct drm_atomic_state *state,
|
|
|
|
struct drm_private_obj *obj)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < state->num_private_objs; i++)
|
|
|
|
if (obj == state->private_objs[i].ptr)
|
|
|
|
return state->private_objs[i].old_state;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_get_old_private_obj_state);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_atomic_get_new_private_obj_state
|
|
|
|
* @state: global atomic state object
|
|
|
|
* @obj: private_obj to grab
|
|
|
|
*
|
|
|
|
* This function returns the new private object state for the given private_obj,
|
|
|
|
* or NULL if the private_obj is not part of the global atomic state.
|
|
|
|
*/
|
|
|
|
struct drm_private_state *
|
|
|
|
drm_atomic_get_new_private_obj_state(struct drm_atomic_state *state,
|
|
|
|
struct drm_private_obj *obj)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < state->num_private_objs; i++)
|
|
|
|
if (obj == state->private_objs[i].ptr)
|
|
|
|
return state->private_objs[i].new_state;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_get_new_private_obj_state);
|
|
|
|
|
2019-06-12 03:51:43 +07:00
|
|
|
/**
|
|
|
|
* drm_atomic_get_old_connector_for_encoder - Get old connector for an encoder
|
|
|
|
* @state: Atomic state
|
|
|
|
* @encoder: The encoder to fetch the connector state for
|
|
|
|
*
|
|
|
|
* This function finds and returns the connector that was connected to @encoder
|
|
|
|
* as specified by the @state.
|
|
|
|
*
|
|
|
|
* If there is no connector in @state which previously had @encoder connected to
|
|
|
|
* it, this function will return NULL. While this may seem like an invalid use
|
|
|
|
* case, it is sometimes useful to differentiate commits which had no prior
|
|
|
|
* connectors attached to @encoder vs ones that did (and to inspect their
|
|
|
|
* state). This is especially true in enable hooks because the pipeline has
|
|
|
|
* changed.
|
|
|
|
*
|
|
|
|
* Returns: The old connector connected to @encoder, or NULL if the encoder is
|
|
|
|
* not connected.
|
|
|
|
*/
|
|
|
|
struct drm_connector *
|
|
|
|
drm_atomic_get_old_connector_for_encoder(struct drm_atomic_state *state,
|
|
|
|
struct drm_encoder *encoder)
|
|
|
|
{
|
|
|
|
struct drm_connector_state *conn_state;
|
|
|
|
struct drm_connector *connector;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for_each_old_connector_in_state(state, connector, conn_state, i) {
|
|
|
|
if (conn_state->best_encoder == encoder)
|
|
|
|
return connector;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_get_old_connector_for_encoder);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_atomic_get_new_connector_for_encoder - Get new connector for an encoder
|
|
|
|
* @state: Atomic state
|
|
|
|
* @encoder: The encoder to fetch the connector state for
|
|
|
|
*
|
|
|
|
* This function finds and returns the connector that will be connected to
|
|
|
|
* @encoder as specified by the @state.
|
|
|
|
*
|
|
|
|
* If there is no connector in @state which will have @encoder connected to it,
|
|
|
|
* this function will return NULL. While this may seem like an invalid use case,
|
|
|
|
* it is sometimes useful to differentiate commits which have no connectors
|
|
|
|
* attached to @encoder vs ones that do (and to inspect their state). This is
|
|
|
|
* especially true in disable hooks because the pipeline will change.
|
|
|
|
*
|
|
|
|
* Returns: The new connector connected to @encoder, or NULL if the encoder is
|
|
|
|
* not connected.
|
|
|
|
*/
|
|
|
|
struct drm_connector *
|
|
|
|
drm_atomic_get_new_connector_for_encoder(struct drm_atomic_state *state,
|
|
|
|
struct drm_encoder *encoder)
|
|
|
|
{
|
|
|
|
struct drm_connector_state *conn_state;
|
|
|
|
struct drm_connector *connector;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for_each_new_connector_in_state(state, connector, conn_state, i) {
|
|
|
|
if (conn_state->best_encoder == encoder)
|
|
|
|
return connector;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_get_new_connector_for_encoder);
|
|
|
|
|
2014-07-26 02:30:38 +07: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 16:12:31 +07:00
|
|
|
WARN_ON(!state->acquire_ctx);
|
|
|
|
|
2014-11-20 00:38:06 +07:00
|
|
|
ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
|
|
|
|
if (ret)
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
|
2014-07-26 02:30:38 +07:00
|
|
|
index = drm_connector_index(connector);
|
|
|
|
|
2014-11-20 00:38:08 +07:00
|
|
|
if (index >= state->num_connector) {
|
2016-06-02 05:06:32 +07:00
|
|
|
struct __drm_connnectors_state *c;
|
2016-02-17 14:32:05 +07: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-20 00:38:08 +07:00
|
|
|
}
|
|
|
|
|
2016-06-02 05:06:32 +07:00
|
|
|
if (state->connectors[index].state)
|
|
|
|
return state->connectors[index].state;
|
2014-07-26 02:30:38 +07:00
|
|
|
|
|
|
|
connector_state = connector->funcs->atomic_duplicate_state(connector);
|
|
|
|
if (!connector_state)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2017-02-28 21:46:39 +07:00
|
|
|
drm_connector_get(connector);
|
2016-06-02 05:06:32 +07:00
|
|
|
state->connectors[index].state = connector_state;
|
2017-01-16 16:37:38 +07:00
|
|
|
state->connectors[index].old_state = connector->state;
|
|
|
|
state->connectors[index].new_state = connector_state;
|
2016-06-02 05:06:32 +07:00
|
|
|
state->connectors[index].ptr = connector;
|
2014-07-26 02:30:38 +07:00
|
|
|
connector_state->state = state;
|
|
|
|
|
2017-02-13 19:27:03 +07:00
|
|
|
DRM_DEBUG_ATOMIC("Added [CONNECTOR:%d:%s] %p state to %p\n",
|
|
|
|
connector->base.id, connector->name,
|
|
|
|
connector_state, state);
|
2014-07-26 02:30:38 +07: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);
|
|
|
|
|
2016-11-05 22:08:09 +07: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)");
|
2019-06-12 21:50:19 +07:00
|
|
|
drm_printf(p, "\tself_refresh_aware=%d\n", state->self_refresh_aware);
|
2016-11-05 22:08:09 +07:00
|
|
|
|
2017-11-02 23:49:51 +07:00
|
|
|
if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
|
|
|
|
if (state->writeback_job && state->writeback_job->fb)
|
|
|
|
drm_printf(p, "\tfb=%d\n", state->writeback_job->fb->base.id);
|
|
|
|
|
2016-11-05 22:08:09 +07:00
|
|
|
if (connector->funcs->atomic_print_state)
|
|
|
|
connector->funcs->atomic_print_state(p, state);
|
|
|
|
}
|
|
|
|
|
2014-07-26 02:30:38 +07:00
|
|
|
/**
|
|
|
|
* 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-14 06:08:06 +07:00
|
|
|
struct drm_connector_list_iter conn_iter;
|
2017-01-16 16:37:39 +07:00
|
|
|
struct drm_crtc_state *crtc_state;
|
2014-07-26 02:30:38 +07:00
|
|
|
int ret;
|
|
|
|
|
2017-01-16 16:37:39 +07:00
|
|
|
crtc_state = drm_atomic_get_crtc_state(state, crtc);
|
|
|
|
if (IS_ERR(crtc_state))
|
|
|
|
return PTR_ERR(crtc_state);
|
|
|
|
|
2014-07-26 02:30:38 +07:00
|
|
|
ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-12-08 23:41:53 +07:00
|
|
|
DRM_DEBUG_ATOMIC("Adding all current connectors for [CRTC:%d:%s] to %p\n",
|
|
|
|
crtc->base.id, crtc->name, state);
|
2014-07-26 02:30:38 +07:00
|
|
|
|
|
|
|
/*
|
2017-01-16 16:37:39 +07:00
|
|
|
* Changed connectors are already in @state, so only need to look
|
|
|
|
* at the connector_mask in crtc_state.
|
2014-07-26 02:30:38 +07:00
|
|
|
*/
|
2017-02-28 21:46:43 +07: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-14 06:08:06 +07:00
|
|
|
drm_for_each_connector_iter(connector, &conn_iter) {
|
2018-06-27 02:47:10 +07:00
|
|
|
if (!(crtc_state->connector_mask & drm_connector_mask(connector)))
|
2014-07-26 02:30:38 +07: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-14 06:08:06 +07:00
|
|
|
if (IS_ERR(conn_state)) {
|
2017-02-28 21:46:43 +07:00
|
|
|
drm_connector_list_iter_end(&conn_iter);
|
2014-07-26 02:30:38 +07: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-14 06:08:06 +07:00
|
|
|
}
|
2014-07-26 02:30:38 +07:00
|
|
|
}
|
2017-02-28 21:46:43 +07:00
|
|
|
drm_connector_list_iter_end(&conn_iter);
|
2014-07-26 02:30:38 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_add_affected_connectors);
|
|
|
|
|
2015-05-19 21:41:02 +07: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)
|
|
|
|
{
|
2018-11-02 01:46:44 +07:00
|
|
|
const struct drm_crtc_state *old_crtc_state =
|
|
|
|
drm_atomic_get_old_crtc_state(state, crtc);
|
2015-05-19 21:41:02 +07:00
|
|
|
struct drm_plane *plane;
|
|
|
|
|
2017-03-01 16:22:10 +07:00
|
|
|
WARN_ON(!drm_atomic_get_new_crtc_state(state, crtc));
|
2015-05-19 21:41:02 +07:00
|
|
|
|
2018-06-12 02:34:01 +07:00
|
|
|
DRM_DEBUG_ATOMIC("Adding all current planes for [CRTC:%d:%s] to %p\n",
|
|
|
|
crtc->base.id, crtc->name, state);
|
|
|
|
|
2018-11-02 01:46:44 +07:00
|
|
|
drm_for_each_plane_mask(plane, state->dev, old_crtc_state->plane_mask) {
|
2015-05-19 21:41:02 +07:00
|
|
|
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-26 02:30:38 +07:00
|
|
|
/**
|
|
|
|
* 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-19 04:01:51 +07:00
|
|
|
struct drm_device *dev = state->dev;
|
|
|
|
struct drm_mode_config *config = &dev->mode_config;
|
2015-04-10 18:58:39 +07:00
|
|
|
struct drm_plane *plane;
|
2018-11-07 02:16:24 +07:00
|
|
|
struct drm_plane_state *old_plane_state;
|
|
|
|
struct drm_plane_state *new_plane_state;
|
2015-04-10 18:58:39 +07:00
|
|
|
struct drm_crtc *crtc;
|
2018-11-02 01:46:45 +07:00
|
|
|
struct drm_crtc_state *old_crtc_state;
|
|
|
|
struct drm_crtc_state *new_crtc_state;
|
2017-03-29 23:42:32 +07:00
|
|
|
struct drm_connector *conn;
|
|
|
|
struct drm_connector_state *conn_state;
|
2014-12-19 04:01:51 +07:00
|
|
|
int i, ret = 0;
|
2014-07-26 02:30:38 +07:00
|
|
|
|
2015-02-22 18:24:16 +07:00
|
|
|
DRM_DEBUG_ATOMIC("checking %p\n", state);
|
2014-07-26 02:30:38 +07:00
|
|
|
|
2018-11-07 02:16:24 +07:00
|
|
|
for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
|
|
|
|
ret = drm_atomic_plane_check(old_plane_state, new_plane_state);
|
2014-12-19 04:01:51 +07:00
|
|
|
if (ret) {
|
2015-12-08 23:41:54 +07:00
|
|
|
DRM_DEBUG_ATOMIC("[PLANE:%d:%s] atomic core check failed\n",
|
|
|
|
plane->base.id, plane->name);
|
2014-12-19 04:01:51 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-02 01:46:45 +07:00
|
|
|
for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
|
|
|
|
ret = drm_atomic_crtc_check(old_crtc_state, new_crtc_state);
|
2014-12-19 04:01:51 +07:00
|
|
|
if (ret) {
|
2015-12-08 23:41:53 +07:00
|
|
|
DRM_DEBUG_ATOMIC("[CRTC:%d:%s] atomic core check failed\n",
|
|
|
|
crtc->base.id, crtc->name);
|
2014-12-19 04:01:51 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 23:42:32 +07:00
|
|
|
for_each_new_connector_in_state(state, conn, conn_state, i) {
|
|
|
|
ret = drm_atomic_connector_check(conn, conn_state);
|
|
|
|
if (ret) {
|
|
|
|
DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] atomic core check failed\n",
|
|
|
|
conn->base.id, conn->name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-12 06:42:40 +07:00
|
|
|
if (config->funcs->atomic_check) {
|
2014-12-19 04:01:51 +07:00
|
|
|
ret = config->funcs->atomic_check(state->dev, state);
|
|
|
|
|
2018-04-12 06:42:40 +07:00
|
|
|
if (ret) {
|
|
|
|
DRM_DEBUG_ATOMIC("atomic driver check for %p failed: %d\n",
|
|
|
|
state, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2017-08-15 16:57:06 +07:00
|
|
|
|
2014-12-19 04:01:56 +07:00
|
|
|
if (!state->allow_modeset) {
|
2018-11-02 01:46:45 +07:00
|
|
|
for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
|
|
|
|
if (drm_atomic_crtc_needs_modeset(new_crtc_state)) {
|
2015-12-08 23:41:53 +07:00
|
|
|
DRM_DEBUG_ATOMIC("[CRTC:%d:%s] requires full modeset\n",
|
|
|
|
crtc->base.id, crtc->name);
|
2014-12-19 04:01:56 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-15 16:57:06 +07:00
|
|
|
return 0;
|
2014-07-26 02:30:38 +07: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 18:34:00 +07:00
|
|
|
* This function will take its own reference on @state.
|
|
|
|
* Callers should always release their reference with drm_atomic_state_put().
|
2014-07-26 02:30:38 +07: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;
|
|
|
|
|
2017-04-12 23:27:22 +07:00
|
|
|
DRM_DEBUG_ATOMIC("committing %p\n", state);
|
2014-07-26 02:30:38 +07:00
|
|
|
|
|
|
|
return config->funcs->atomic_commit(state->dev, state, false);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_atomic_commit);
|
|
|
|
|
|
|
|
/**
|
2017-01-25 13:26:45 +07:00
|
|
|
* drm_atomic_nonblocking_commit - atomic nonblocking commit
|
2014-07-26 02:30:38 +07: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 18:34:00 +07:00
|
|
|
* This function will take its own reference on @state.
|
|
|
|
* Callers should always release their reference with drm_atomic_state_put().
|
2014-07-26 02:30:38 +07:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 0 on success, negative error code on failure.
|
|
|
|
*/
|
2016-04-26 21:11:35 +07:00
|
|
|
int drm_atomic_nonblocking_commit(struct drm_atomic_state *state)
|
2014-07-26 02:30:38 +07:00
|
|
|
{
|
|
|
|
struct drm_mode_config *config = &state->dev->mode_config;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = drm_atomic_check_only(state);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2017-04-12 23:27:22 +07:00
|
|
|
DRM_DEBUG_ATOMIC("committing %p nonblocking\n", state);
|
2014-07-26 02:30:38 +07:00
|
|
|
|
|
|
|
return config->funcs->atomic_commit(state->dev, state, true);
|
|
|
|
}
|
2016-04-26 21:11:35 +07:00
|
|
|
EXPORT_SYMBOL(drm_atomic_nonblocking_commit);
|
2014-12-19 04:01:56 +07:00
|
|
|
|
2019-05-31 21:01:10 +07:00
|
|
|
/* just used from drm-client and atomic-helper: */
|
|
|
|
int __drm_atomic_helper_disable_plane(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *plane_state)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
drm_atomic_set_fb_for_plane(plane_state, NULL);
|
|
|
|
plane_state->crtc_x = 0;
|
|
|
|
plane_state->crtc_y = 0;
|
|
|
|
plane_state->crtc_w = 0;
|
|
|
|
plane_state->crtc_h = 0;
|
|
|
|
plane_state->src_x = 0;
|
|
|
|
plane_state->src_y = 0;
|
|
|
|
plane_state->src_w = 0;
|
|
|
|
plane_state->src_h = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__drm_atomic_helper_disable_plane);
|
|
|
|
|
|
|
|
static int update_output_state(struct drm_atomic_state *state,
|
|
|
|
struct drm_mode_set *set)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = set->crtc->dev;
|
|
|
|
struct drm_crtc *crtc;
|
|
|
|
struct drm_crtc_state *new_crtc_state;
|
|
|
|
struct drm_connector *connector;
|
|
|
|
struct drm_connector_state *new_conn_state;
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
ret = drm_modeset_lock(&dev->mode_config.connection_mutex,
|
|
|
|
state->acquire_ctx);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* First disable all connectors on the target crtc. */
|
|
|
|
ret = drm_atomic_add_affected_connectors(state, set->crtc);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
for_each_new_connector_in_state(state, connector, new_conn_state, i) {
|
|
|
|
if (new_conn_state->crtc == set->crtc) {
|
|
|
|
ret = drm_atomic_set_crtc_for_connector(new_conn_state,
|
|
|
|
NULL);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Make sure legacy setCrtc always re-trains */
|
|
|
|
new_conn_state->link_status = DRM_LINK_STATUS_GOOD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then set all connectors from set->connectors on the target crtc */
|
|
|
|
for (i = 0; i < set->num_connectors; i++) {
|
|
|
|
new_conn_state = drm_atomic_get_connector_state(state,
|
|
|
|
set->connectors[i]);
|
|
|
|
if (IS_ERR(new_conn_state))
|
|
|
|
return PTR_ERR(new_conn_state);
|
|
|
|
|
|
|
|
ret = drm_atomic_set_crtc_for_connector(new_conn_state,
|
|
|
|
set->crtc);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
|
|
|
|
/*
|
|
|
|
* Don't update ->enable for the CRTC in the set_config request,
|
|
|
|
* since a mismatch would indicate a bug in the upper layers.
|
|
|
|
* The actual modeset code later on will catch any
|
|
|
|
* inconsistencies here.
|
|
|
|
*/
|
|
|
|
if (crtc == set->crtc)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!new_crtc_state->connector_mask) {
|
|
|
|
ret = drm_atomic_set_mode_prop_for_crtc(new_crtc_state,
|
|
|
|
NULL);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
new_crtc_state->active = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* just used from drm-client and atomic-helper: */
|
|
|
|
int __drm_atomic_helper_set_config(struct drm_mode_set *set,
|
|
|
|
struct drm_atomic_state *state)
|
|
|
|
{
|
|
|
|
struct drm_crtc_state *crtc_state;
|
|
|
|
struct drm_plane_state *primary_state;
|
|
|
|
struct drm_crtc *crtc = set->crtc;
|
|
|
|
int hdisplay, vdisplay;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
crtc_state = drm_atomic_get_crtc_state(state, crtc);
|
|
|
|
if (IS_ERR(crtc_state))
|
|
|
|
return PTR_ERR(crtc_state);
|
|
|
|
|
|
|
|
primary_state = drm_atomic_get_plane_state(state, crtc->primary);
|
|
|
|
if (IS_ERR(primary_state))
|
|
|
|
return PTR_ERR(primary_state);
|
|
|
|
|
|
|
|
if (!set->mode) {
|
|
|
|
WARN_ON(set->fb);
|
|
|
|
WARN_ON(set->num_connectors);
|
|
|
|
|
|
|
|
ret = drm_atomic_set_mode_for_crtc(crtc_state, NULL);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
crtc_state->active = false;
|
|
|
|
|
|
|
|
ret = drm_atomic_set_crtc_for_plane(primary_state, NULL);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
drm_atomic_set_fb_for_plane(primary_state, NULL);
|
|
|
|
|
|
|
|
goto commit;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN_ON(!set->fb);
|
|
|
|
WARN_ON(!set->num_connectors);
|
|
|
|
|
|
|
|
ret = drm_atomic_set_mode_for_crtc(crtc_state, set->mode);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
crtc_state->active = true;
|
|
|
|
|
|
|
|
ret = drm_atomic_set_crtc_for_plane(primary_state, crtc);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
drm_mode_get_hv_timing(set->mode, &hdisplay, &vdisplay);
|
|
|
|
|
|
|
|
drm_atomic_set_fb_for_plane(primary_state, set->fb);
|
|
|
|
primary_state->crtc_x = 0;
|
|
|
|
primary_state->crtc_y = 0;
|
|
|
|
primary_state->crtc_w = hdisplay;
|
|
|
|
primary_state->crtc_h = vdisplay;
|
|
|
|
primary_state->src_x = set->x << 16;
|
|
|
|
primary_state->src_y = set->y << 16;
|
|
|
|
if (drm_rotation_90_or_270(primary_state->rotation)) {
|
|
|
|
primary_state->src_w = vdisplay << 16;
|
|
|
|
primary_state->src_h = hdisplay << 16;
|
|
|
|
} else {
|
|
|
|
primary_state->src_w = hdisplay << 16;
|
|
|
|
primary_state->src_h = vdisplay << 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
commit:
|
|
|
|
ret = update_output_state(state, set);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__drm_atomic_helper_set_config);
|
|
|
|
|
2018-09-05 20:57:11 +07:00
|
|
|
void drm_atomic_print_state(const struct drm_atomic_state *state)
|
2016-11-05 22:08:09 +07:00
|
|
|
{
|
|
|
|
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 16:37:40 +07:00
|
|
|
for_each_new_plane_in_state(state, plane, plane_state, i)
|
2016-11-05 22:08:09 +07:00
|
|
|
drm_atomic_plane_print_state(&p, plane_state);
|
|
|
|
|
2017-01-16 16:37:40 +07:00
|
|
|
for_each_new_crtc_in_state(state, crtc, crtc_state, i)
|
2016-11-05 22:08:09 +07:00
|
|
|
drm_atomic_crtc_print_state(&p, crtc_state);
|
|
|
|
|
2017-01-16 16:37:40 +07:00
|
|
|
for_each_new_connector_in_state(state, connector, connector_state, i)
|
2016-11-05 22:08:09 +07:00
|
|
|
drm_atomic_connector_print_state(&p, connector_state);
|
|
|
|
}
|
|
|
|
|
2017-04-03 15:32:54 +07:00
|
|
|
static void __drm_state_dump(struct drm_device *dev, struct drm_printer *p,
|
|
|
|
bool take_locks)
|
2016-11-05 22:08:10 +07: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-14 06:08:06 +07:00
|
|
|
struct drm_connector_list_iter conn_iter;
|
2016-11-05 22:08:10 +07:00
|
|
|
|
2018-09-18 00:37:33 +07:00
|
|
|
if (!drm_drv_uses_atomic_modeset(dev))
|
2016-11-05 22:08:10 +07:00
|
|
|
return;
|
|
|
|
|
2017-04-03 15:32:54 +07:00
|
|
|
list_for_each_entry(plane, &config->plane_list, head) {
|
|
|
|
if (take_locks)
|
|
|
|
drm_modeset_lock(&plane->mutex, NULL);
|
2016-11-05 22:08:10 +07:00
|
|
|
drm_atomic_plane_print_state(p, plane->state);
|
2017-04-03 15:32:54 +07:00
|
|
|
if (take_locks)
|
|
|
|
drm_modeset_unlock(&plane->mutex);
|
|
|
|
}
|
2016-11-05 22:08:10 +07:00
|
|
|
|
2017-04-03 15:32:54 +07:00
|
|
|
list_for_each_entry(crtc, &config->crtc_list, head) {
|
|
|
|
if (take_locks)
|
|
|
|
drm_modeset_lock(&crtc->mutex, NULL);
|
2016-11-05 22:08:10 +07:00
|
|
|
drm_atomic_crtc_print_state(p, crtc->state);
|
2017-04-03 15:32:54 +07:00
|
|
|
if (take_locks)
|
|
|
|
drm_modeset_unlock(&crtc->mutex);
|
|
|
|
}
|
2016-11-05 22:08:10 +07:00
|
|
|
|
2017-02-28 21:46:43 +07:00
|
|
|
drm_connector_list_iter_begin(dev, &conn_iter);
|
2017-04-03 15:32:54 +07: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-14 06:08:06 +07:00
|
|
|
drm_for_each_connector_iter(connector, &conn_iter)
|
2016-11-05 22:08:10 +07:00
|
|
|
drm_atomic_connector_print_state(p, connector->state);
|
2017-04-03 15:32:54 +07:00
|
|
|
if (take_locks)
|
|
|
|
drm_modeset_unlock(&dev->mode_config.connection_mutex);
|
2017-02-28 21:46:43 +07:00
|
|
|
drm_connector_list_iter_end(&conn_iter);
|
2016-11-05 22:08:10 +07:00
|
|
|
}
|
2017-04-03 15:32:54 +07: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 22:08:10 +07: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 15:32:54 +07:00
|
|
|
__drm_state_dump(dev, &p, true);
|
2016-11-05 22:08:10 +07: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
|