drm/atomic: Add for_each_{connector,crtc,plane}_in_state helper macros

This saves some typing whenever a iteration over all the connector,
crtc or plane states in the atomic state is written, which happens
quite often.

Cc: dri-devel@lists.freedesktop.org
Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
Ander Conselvan de Oliveira 2015-04-10 14:58:39 +03:00 committed by Daniel Vetter
parent 0578be680c
commit df63b9994e
3 changed files with 117 additions and 222 deletions

View File

@ -909,14 +909,13 @@ int
drm_atomic_connectors_for_crtc(struct drm_atomic_state *state, drm_atomic_connectors_for_crtc(struct drm_atomic_state *state,
struct drm_crtc *crtc) struct drm_crtc *crtc)
{ {
struct drm_connector *connector;
struct drm_connector_state *conn_state;
int i, num_connected_connectors = 0; int i, num_connected_connectors = 0;
for (i = 0; i < state->num_connector; i++) { for_each_connector_in_state(state, connector, conn_state, i) {
struct drm_connector_state *conn_state; if (conn_state->crtc == crtc)
conn_state = state->connector_states[i];
if (conn_state && conn_state->crtc == crtc)
num_connected_connectors++; num_connected_connectors++;
} }
@ -968,19 +967,16 @@ int drm_atomic_check_only(struct drm_atomic_state *state)
{ {
struct drm_device *dev = state->dev; struct drm_device *dev = state->dev;
struct drm_mode_config *config = &dev->mode_config; struct drm_mode_config *config = &dev->mode_config;
int nplanes = config->num_total_plane; struct drm_plane *plane;
int ncrtcs = config->num_crtc; struct drm_plane_state *plane_state;
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
int i, ret = 0; int i, ret = 0;
DRM_DEBUG_ATOMIC("checking %p\n", state); DRM_DEBUG_ATOMIC("checking %p\n", state);
for (i = 0; i < nplanes; i++) { for_each_plane_in_state(state, plane, plane_state, i) {
struct drm_plane *plane = state->planes[i]; ret = drm_atomic_plane_check(plane, plane_state);
if (!plane)
continue;
ret = drm_atomic_plane_check(plane, state->plane_states[i]);
if (ret) { if (ret) {
DRM_DEBUG_ATOMIC("[PLANE:%d] atomic core check failed\n", DRM_DEBUG_ATOMIC("[PLANE:%d] atomic core check failed\n",
plane->base.id); plane->base.id);
@ -988,13 +984,8 @@ int drm_atomic_check_only(struct drm_atomic_state *state)
} }
} }
for (i = 0; i < ncrtcs; i++) { for_each_crtc_in_state(state, crtc, crtc_state, i) {
struct drm_crtc *crtc = state->crtcs[i]; ret = drm_atomic_crtc_check(crtc, crtc_state);
if (!crtc)
continue;
ret = drm_atomic_crtc_check(crtc, state->crtc_states[i]);
if (ret) { if (ret) {
DRM_DEBUG_ATOMIC("[CRTC:%d] atomic core check failed\n", DRM_DEBUG_ATOMIC("[CRTC:%d] atomic core check failed\n",
crtc->base.id); crtc->base.id);
@ -1006,13 +997,7 @@ int drm_atomic_check_only(struct drm_atomic_state *state)
ret = config->funcs->atomic_check(state->dev, state); ret = config->funcs->atomic_check(state->dev, state);
if (!state->allow_modeset) { if (!state->allow_modeset) {
for (i = 0; i < ncrtcs; i++) { for_each_crtc_in_state(state, crtc, crtc_state, i) {
struct drm_crtc *crtc = state->crtcs[i];
struct drm_crtc_state *crtc_state = state->crtc_states[i];
if (!crtc)
continue;
if (crtc_state->mode_changed || if (crtc_state->mode_changed ||
crtc_state->active_changed) { crtc_state->active_changed) {
DRM_DEBUG_ATOMIC("[CRTC:%d] requires full modeset\n", DRM_DEBUG_ATOMIC("[CRTC:%d] requires full modeset\n",
@ -1210,6 +1195,8 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
struct drm_atomic_state *state; struct drm_atomic_state *state;
struct drm_modeset_acquire_ctx ctx; struct drm_modeset_acquire_ctx ctx;
struct drm_plane *plane; struct drm_plane *plane;
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
unsigned plane_mask = 0; unsigned plane_mask = 0;
int ret = 0; int ret = 0;
unsigned int i, j; unsigned int i, j;
@ -1313,15 +1300,9 @@ retry:
} }
if (arg->flags & DRM_MODE_PAGE_FLIP_EVENT) { if (arg->flags & DRM_MODE_PAGE_FLIP_EVENT) {
int ncrtcs = dev->mode_config.num_crtc; for_each_crtc_in_state(state, crtc, crtc_state, i) {
for (i = 0; i < ncrtcs; i++) {
struct drm_crtc_state *crtc_state = state->crtc_states[i];
struct drm_pending_vblank_event *e; struct drm_pending_vblank_event *e;
if (!crtc_state)
continue;
e = create_vblank_event(dev, file_priv, arg->user_data); e = create_vblank_event(dev, file_priv, arg->user_data);
if (!e) { if (!e) {
ret = -ENOMEM; ret = -ENOMEM;
@ -1373,14 +1354,7 @@ fail:
goto backoff; goto backoff;
if (arg->flags & DRM_MODE_PAGE_FLIP_EVENT) { if (arg->flags & DRM_MODE_PAGE_FLIP_EVENT) {
int ncrtcs = dev->mode_config.num_crtc; for_each_crtc_in_state(state, crtc, crtc_state, i) {
for (i = 0; i < ncrtcs; i++) {
struct drm_crtc_state *crtc_state = state->crtc_states[i];
if (!crtc_state)
continue;
destroy_vblank_event(dev, file_priv, crtc_state->event); destroy_vblank_event(dev, file_priv, crtc_state->event);
crtc_state->event = NULL; crtc_state->event = NULL;
} }

View File

@ -248,30 +248,24 @@ update_connector_routing(struct drm_atomic_state *state, int conn_idx)
static int static int
mode_fixup(struct drm_atomic_state *state) mode_fixup(struct drm_atomic_state *state)
{ {
int ncrtcs = state->dev->mode_config.num_crtc; struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state; struct drm_crtc_state *crtc_state;
struct drm_connector *connector;
struct drm_connector_state *conn_state; struct drm_connector_state *conn_state;
int i; int i;
bool ret; bool ret;
for (i = 0; i < ncrtcs; i++) { for_each_crtc_in_state(state, crtc, crtc_state, i) {
crtc_state = state->crtc_states[i]; if (!crtc_state->mode_changed)
if (!crtc_state || !crtc_state->mode_changed)
continue; continue;
drm_mode_copy(&crtc_state->adjusted_mode, &crtc_state->mode); drm_mode_copy(&crtc_state->adjusted_mode, &crtc_state->mode);
} }
for (i = 0; i < state->num_connector; i++) { for_each_connector_in_state(state, connector, conn_state, i) {
const struct drm_encoder_helper_funcs *funcs; const struct drm_encoder_helper_funcs *funcs;
struct drm_encoder *encoder; struct drm_encoder *encoder;
conn_state = state->connector_states[i];
if (!conn_state)
continue;
WARN_ON(!!conn_state->best_encoder != !!conn_state->crtc); WARN_ON(!!conn_state->best_encoder != !!conn_state->crtc);
if (!conn_state->crtc || !conn_state->best_encoder) if (!conn_state->crtc || !conn_state->best_encoder)
@ -316,14 +310,10 @@ mode_fixup(struct drm_atomic_state *state)
} }
} }
for (i = 0; i < ncrtcs; i++) { for_each_crtc_in_state(state, crtc, crtc_state, i) {
const struct drm_crtc_helper_funcs *funcs; const struct drm_crtc_helper_funcs *funcs;
struct drm_crtc *crtc;
crtc_state = state->crtc_states[i]; if (!crtc_state->mode_changed)
crtc = state->crtcs[i];
if (!crtc_state || !crtc_state->mode_changed)
continue; continue;
funcs = crtc->helper_private; funcs = crtc->helper_private;
@ -371,18 +361,13 @@ int
drm_atomic_helper_check_modeset(struct drm_device *dev, drm_atomic_helper_check_modeset(struct drm_device *dev,
struct drm_atomic_state *state) struct drm_atomic_state *state)
{ {
int ncrtcs = dev->mode_config.num_crtc;
struct drm_crtc *crtc; struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state; struct drm_crtc_state *crtc_state;
struct drm_connector *connector;
struct drm_connector_state *connector_state;
int i, ret; int i, ret;
for (i = 0; i < ncrtcs; i++) { for_each_crtc_in_state(state, crtc, crtc_state, i) {
crtc = state->crtcs[i];
crtc_state = state->crtc_states[i];
if (!crtc)
continue;
if (!drm_mode_equal(&crtc->state->mode, &crtc_state->mode)) { if (!drm_mode_equal(&crtc->state->mode, &crtc_state->mode)) {
DRM_DEBUG_ATOMIC("[CRTC:%d] mode changed\n", DRM_DEBUG_ATOMIC("[CRTC:%d] mode changed\n",
crtc->base.id); crtc->base.id);
@ -396,7 +381,7 @@ drm_atomic_helper_check_modeset(struct drm_device *dev,
} }
} }
for (i = 0; i < state->num_connector; i++) { for_each_connector_in_state(state, connector, connector_state, i) {
/* /*
* This only sets crtc->mode_changed for routing changes, * This only sets crtc->mode_changed for routing changes,
* drivers must set crtc->mode_changed themselves when connector * drivers must set crtc->mode_changed themselves when connector
@ -413,15 +398,9 @@ drm_atomic_helper_check_modeset(struct drm_device *dev,
* configuration. This must be done before calling mode_fixup in case a * configuration. This must be done before calling mode_fixup in case a
* crtc only changed its mode but has the same set of connectors. * crtc only changed its mode but has the same set of connectors.
*/ */
for (i = 0; i < ncrtcs; i++) { for_each_crtc_in_state(state, crtc, crtc_state, i) {
int num_connectors; int num_connectors;
crtc = state->crtcs[i];
crtc_state = state->crtc_states[i];
if (!crtc)
continue;
/* /*
* We must set ->active_changed after walking connectors for * We must set ->active_changed after walking connectors for
* otherwise an update that only changes active would result in * otherwise an update that only changes active would result in
@ -476,17 +455,14 @@ int
drm_atomic_helper_check_planes(struct drm_device *dev, drm_atomic_helper_check_planes(struct drm_device *dev,
struct drm_atomic_state *state) struct drm_atomic_state *state)
{ {
int nplanes = dev->mode_config.num_total_plane; struct drm_crtc *crtc;
int ncrtcs = dev->mode_config.num_crtc; struct drm_crtc_state *crtc_state;
struct drm_plane *plane;
struct drm_plane_state *plane_state;
int i, ret = 0; int i, ret = 0;
for (i = 0; i < nplanes; i++) { for_each_plane_in_state(state, plane, plane_state, i) {
const struct drm_plane_helper_funcs *funcs; const struct drm_plane_helper_funcs *funcs;
struct drm_plane *plane = state->planes[i];
struct drm_plane_state *plane_state = state->plane_states[i];
if (!plane)
continue;
funcs = plane->helper_private; funcs = plane->helper_private;
@ -503,12 +479,8 @@ drm_atomic_helper_check_planes(struct drm_device *dev,
} }
} }
for (i = 0; i < ncrtcs; i++) { for_each_crtc_in_state(state, crtc, crtc_state, i) {
const struct drm_crtc_helper_funcs *funcs; const struct drm_crtc_helper_funcs *funcs;
struct drm_crtc *crtc = state->crtcs[i];
if (!crtc)
continue;
funcs = crtc->helper_private; funcs = crtc->helper_private;
@ -567,22 +539,20 @@ EXPORT_SYMBOL(drm_atomic_helper_check);
static void static void
disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state) disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state)
{ {
int ncrtcs = old_state->dev->mode_config.num_crtc; struct drm_connector *connector;
struct drm_connector_state *old_conn_state;
struct drm_crtc *crtc;
struct drm_crtc_state *old_crtc_state;
int i; int i;
for (i = 0; i < old_state->num_connector; i++) { for_each_connector_in_state(old_state, connector, old_conn_state, i) {
const struct drm_encoder_helper_funcs *funcs; const struct drm_encoder_helper_funcs *funcs;
struct drm_connector_state *old_conn_state;
struct drm_connector *connector;
struct drm_encoder *encoder; struct drm_encoder *encoder;
struct drm_crtc_state *old_crtc_state; struct drm_crtc_state *old_crtc_state;
old_conn_state = old_state->connector_states[i];
connector = old_state->connectors[i];
/* Shut down everything that's in the changeset and currently /* Shut down everything that's in the changeset and currently
* still on. So need to check the old, saved state. */ * still on. So need to check the old, saved state. */
if (!old_conn_state || !old_conn_state->crtc) if (!old_conn_state->crtc)
continue; continue;
old_crtc_state = old_state->crtc_states[drm_crtc_index(old_conn_state->crtc)]; old_crtc_state = old_state->crtc_states[drm_crtc_index(old_conn_state->crtc)];
@ -623,16 +593,11 @@ disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state)
encoder->bridge->funcs->post_disable(encoder->bridge); encoder->bridge->funcs->post_disable(encoder->bridge);
} }
for (i = 0; i < ncrtcs; i++) { for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
const struct drm_crtc_helper_funcs *funcs; const struct drm_crtc_helper_funcs *funcs;
struct drm_crtc *crtc;
struct drm_crtc_state *old_crtc_state;
crtc = old_state->crtcs[i];
old_crtc_state = old_state->crtc_states[i];
/* Shut down everything that needs a full modeset. */ /* Shut down everything that needs a full modeset. */
if (!crtc || !needs_modeset(crtc->state)) if (!needs_modeset(crtc->state))
continue; continue;
if (!old_crtc_state->active) if (!old_crtc_state->active)
@ -657,16 +622,15 @@ disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state)
static void static void
set_routing_links(struct drm_device *dev, struct drm_atomic_state *old_state) set_routing_links(struct drm_device *dev, struct drm_atomic_state *old_state)
{ {
int ncrtcs = old_state->dev->mode_config.num_crtc; struct drm_connector *connector;
struct drm_connector_state *old_conn_state;
struct drm_crtc *crtc;
struct drm_crtc_state *old_crtc_state;
int i; int i;
/* clear out existing links */ /* clear out existing links */
for (i = 0; i < old_state->num_connector; i++) { for_each_connector_in_state(old_state, connector, old_conn_state, i) {
struct drm_connector *connector; if (!connector->encoder)
connector = old_state->connectors[i];
if (!connector || !connector->encoder)
continue; continue;
WARN_ON(!connector->encoder->crtc); WARN_ON(!connector->encoder->crtc);
@ -676,12 +640,8 @@ set_routing_links(struct drm_device *dev, struct drm_atomic_state *old_state)
} }
/* set new links */ /* set new links */
for (i = 0; i < old_state->num_connector; i++) { for_each_connector_in_state(old_state, connector, old_conn_state, i) {
struct drm_connector *connector; if (!connector->state->crtc)
connector = old_state->connectors[i];
if (!connector || !connector->state->crtc)
continue; continue;
if (WARN_ON(!connector->state->best_encoder)) if (WARN_ON(!connector->state->best_encoder))
@ -692,14 +652,7 @@ set_routing_links(struct drm_device *dev, struct drm_atomic_state *old_state)
} }
/* set legacy state in the crtc structure */ /* set legacy state in the crtc structure */
for (i = 0; i < ncrtcs; i++) { for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
struct drm_crtc *crtc;
crtc = old_state->crtcs[i];
if (!crtc)
continue;
crtc->mode = crtc->state->mode; crtc->mode = crtc->state->mode;
crtc->enabled = crtc->state->enable; crtc->enabled = crtc->state->enable;
crtc->x = crtc->primary->state->src_x >> 16; crtc->x = crtc->primary->state->src_x >> 16;
@ -710,16 +663,16 @@ set_routing_links(struct drm_device *dev, struct drm_atomic_state *old_state)
static void static void
crtc_set_mode(struct drm_device *dev, struct drm_atomic_state *old_state) crtc_set_mode(struct drm_device *dev, struct drm_atomic_state *old_state)
{ {
int ncrtcs = old_state->dev->mode_config.num_crtc; struct drm_crtc *crtc;
struct drm_crtc_state *old_crtc_state;
struct drm_connector *connector;
struct drm_connector_state *old_conn_state;
int i; int i;
for (i = 0; i < ncrtcs; i++) { for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
const struct drm_crtc_helper_funcs *funcs; const struct drm_crtc_helper_funcs *funcs;
struct drm_crtc *crtc;
crtc = old_state->crtcs[i]; if (!crtc->state->mode_changed)
if (!crtc || !crtc->state->mode_changed)
continue; continue;
funcs = crtc->helper_private; funcs = crtc->helper_private;
@ -732,16 +685,13 @@ crtc_set_mode(struct drm_device *dev, struct drm_atomic_state *old_state)
} }
} }
for (i = 0; i < old_state->num_connector; i++) { for_each_connector_in_state(old_state, connector, old_conn_state, i) {
const struct drm_encoder_helper_funcs *funcs; const struct drm_encoder_helper_funcs *funcs;
struct drm_connector *connector;
struct drm_crtc_state *new_crtc_state; struct drm_crtc_state *new_crtc_state;
struct drm_encoder *encoder; struct drm_encoder *encoder;
struct drm_display_mode *mode, *adjusted_mode; struct drm_display_mode *mode, *adjusted_mode;
connector = old_state->connectors[i]; if (!connector->state->best_encoder)
if (!connector || !connector->state->best_encoder)
continue; continue;
encoder = connector->state->best_encoder; encoder = connector->state->best_encoder;
@ -809,17 +759,17 @@ EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_disables);
void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev,
struct drm_atomic_state *old_state) struct drm_atomic_state *old_state)
{ {
int ncrtcs = old_state->dev->mode_config.num_crtc; struct drm_crtc *crtc;
struct drm_crtc_state *old_crtc_state;
struct drm_connector *connector;
struct drm_connector_state *old_conn_state;
int i; int i;
for (i = 0; i < ncrtcs; i++) { for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
const struct drm_crtc_helper_funcs *funcs; const struct drm_crtc_helper_funcs *funcs;
struct drm_crtc *crtc;
crtc = old_state->crtcs[i];
/* Need to filter out CRTCs where only planes change. */ /* Need to filter out CRTCs where only planes change. */
if (!crtc || !needs_modeset(crtc->state)) if (!needs_modeset(crtc->state))
continue; continue;
if (!crtc->state->active) if (!crtc->state->active)
@ -838,14 +788,11 @@ void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev,
} }
} }
for (i = 0; i < old_state->num_connector; i++) { for_each_connector_in_state(old_state, connector, old_conn_state, i) {
const struct drm_encoder_helper_funcs *funcs; const struct drm_encoder_helper_funcs *funcs;
struct drm_connector *connector;
struct drm_encoder *encoder; struct drm_encoder *encoder;
connector = old_state->connectors[i]; if (!connector->state->best_encoder)
if (!connector || !connector->state->best_encoder)
continue; continue;
if (!connector->state->crtc->state->active || if (!connector->state->crtc->state->active ||
@ -879,13 +826,12 @@ EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_enables);
static void wait_for_fences(struct drm_device *dev, static void wait_for_fences(struct drm_device *dev,
struct drm_atomic_state *state) struct drm_atomic_state *state)
{ {
int nplanes = dev->mode_config.num_total_plane; struct drm_plane *plane;
struct drm_plane_state *plane_state;
int i; int i;
for (i = 0; i < nplanes; i++) { for_each_plane_in_state(state, plane, plane_state, i) {
struct drm_plane *plane = state->planes[i]; if (!plane->state->fence)
if (!plane || !plane->state->fence)
continue; continue;
WARN_ON(!plane->state->fb); WARN_ON(!plane->state->fb);
@ -902,16 +848,9 @@ static bool framebuffer_changed(struct drm_device *dev,
{ {
struct drm_plane *plane; struct drm_plane *plane;
struct drm_plane_state *old_plane_state; struct drm_plane_state *old_plane_state;
int nplanes = old_state->dev->mode_config.num_total_plane;
int i; int i;
for (i = 0; i < nplanes; i++) { for_each_plane_in_state(old_state, plane, old_plane_state, i) {
plane = old_state->planes[i];
old_plane_state = old_state->plane_states[i];
if (!plane)
continue;
if (plane->state->crtc != crtc && if (plane->state->crtc != crtc &&
old_plane_state->crtc != crtc) old_plane_state->crtc != crtc)
continue; continue;
@ -940,16 +879,9 @@ drm_atomic_helper_wait_for_vblanks(struct drm_device *dev,
{ {
struct drm_crtc *crtc; struct drm_crtc *crtc;
struct drm_crtc_state *old_crtc_state; struct drm_crtc_state *old_crtc_state;
int ncrtcs = old_state->dev->mode_config.num_crtc;
int i, ret; int i, ret;
for (i = 0; i < ncrtcs; i++) { for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
crtc = old_state->crtcs[i];
old_crtc_state = old_state->crtc_states[i];
if (!crtc)
continue;
/* No one cares about the old state, so abuse it for tracking /* No one cares about the old state, so abuse it for tracking
* and store whether we hold a vblank reference (and should do a * and store whether we hold a vblank reference (and should do a
* vblank wait) in the ->enable boolean. */ * vblank wait) in the ->enable boolean. */
@ -974,11 +906,8 @@ drm_atomic_helper_wait_for_vblanks(struct drm_device *dev,
old_crtc_state->last_vblank_count = drm_vblank_count(dev, i); old_crtc_state->last_vblank_count = drm_vblank_count(dev, i);
} }
for (i = 0; i < ncrtcs; i++) { for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
crtc = old_state->crtcs[i]; if (!old_crtc_state->enable)
old_crtc_state = old_state->crtc_states[i];
if (!crtc || !old_crtc_state->enable)
continue; continue;
ret = wait_event_timeout(dev->vblank[i].queue, ret = wait_event_timeout(dev->vblank[i].queue,
@ -1176,16 +1105,14 @@ EXPORT_SYMBOL(drm_atomic_helper_prepare_planes);
void drm_atomic_helper_commit_planes(struct drm_device *dev, void drm_atomic_helper_commit_planes(struct drm_device *dev,
struct drm_atomic_state *old_state) struct drm_atomic_state *old_state)
{ {
int nplanes = dev->mode_config.num_total_plane; struct drm_crtc *crtc;
int ncrtcs = dev->mode_config.num_crtc; struct drm_crtc_state *old_crtc_state;
struct drm_plane *plane;
struct drm_plane_state *old_plane_state;
int i; int i;
for (i = 0; i < ncrtcs; i++) { for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
const struct drm_crtc_helper_funcs *funcs; const struct drm_crtc_helper_funcs *funcs;
struct drm_crtc *crtc = old_state->crtcs[i];
if (!crtc)
continue;
funcs = crtc->helper_private; funcs = crtc->helper_private;
@ -1195,13 +1122,8 @@ void drm_atomic_helper_commit_planes(struct drm_device *dev,
funcs->atomic_begin(crtc); funcs->atomic_begin(crtc);
} }
for (i = 0; i < nplanes; i++) { for_each_plane_in_state(old_state, plane, old_plane_state, i) {
const struct drm_plane_helper_funcs *funcs; const struct drm_plane_helper_funcs *funcs;
struct drm_plane *plane = old_state->planes[i];
struct drm_plane_state *old_plane_state;
if (!plane)
continue;
funcs = plane->helper_private; funcs = plane->helper_private;
@ -1220,12 +1142,8 @@ void drm_atomic_helper_commit_planes(struct drm_device *dev,
funcs->atomic_update(plane, old_plane_state); funcs->atomic_update(plane, old_plane_state);
} }
for (i = 0; i < ncrtcs; i++) { for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
const struct drm_crtc_helper_funcs *funcs; const struct drm_crtc_helper_funcs *funcs;
struct drm_crtc *crtc = old_state->crtcs[i];
if (!crtc)
continue;
funcs = crtc->helper_private; funcs = crtc->helper_private;
@ -1252,18 +1170,14 @@ EXPORT_SYMBOL(drm_atomic_helper_commit_planes);
void drm_atomic_helper_cleanup_planes(struct drm_device *dev, void drm_atomic_helper_cleanup_planes(struct drm_device *dev,
struct drm_atomic_state *old_state) struct drm_atomic_state *old_state)
{ {
int nplanes = dev->mode_config.num_total_plane; struct drm_plane *plane;
struct drm_plane_state *plane_state;
int i; int i;
for (i = 0; i < nplanes; i++) { for_each_plane_in_state(old_state, plane, plane_state, i) {
const struct drm_plane_helper_funcs *funcs; const struct drm_plane_helper_funcs *funcs;
struct drm_plane *plane = old_state->planes[i];
struct drm_plane_state *plane_state = old_state->plane_states[i];
struct drm_framebuffer *old_fb; struct drm_framebuffer *old_fb;
if (!plane)
continue;
funcs = plane->helper_private; funcs = plane->helper_private;
old_fb = plane_state->fb; old_fb = plane_state->fb;
@ -1512,8 +1426,10 @@ static int update_output_state(struct drm_atomic_state *state,
struct drm_mode_set *set) struct drm_mode_set *set)
{ {
struct drm_device *dev = set->crtc->dev; struct drm_device *dev = set->crtc->dev;
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
struct drm_connector *connector;
struct drm_connector_state *conn_state; struct drm_connector_state *conn_state;
int ncrtcs = state->dev->mode_config.num_crtc;
int ret, i, j; int ret, i, j;
ret = drm_modeset_lock(&dev->mode_config.connection_mutex, ret = drm_modeset_lock(&dev->mode_config.connection_mutex,
@ -1529,27 +1445,14 @@ static int update_output_state(struct drm_atomic_state *state,
return PTR_ERR(conn_state); return PTR_ERR(conn_state);
} }
for (i = 0; i < ncrtcs; i++) { for_each_crtc_in_state(state, crtc, crtc_state, i) {
struct drm_crtc *crtc = state->crtcs[i];
if (!crtc)
continue;
ret = drm_atomic_add_affected_connectors(state, crtc); ret = drm_atomic_add_affected_connectors(state, crtc);
if (ret) if (ret)
return ret; return ret;
} }
/* Then recompute connector->crtc links and crtc enabling state. */ /* Then recompute connector->crtc links and crtc enabling state. */
for (i = 0; i < state->num_connector; i++) { for_each_connector_in_state(state, connector, conn_state, i) {
struct drm_connector *connector;
connector = state->connectors[i];
conn_state = state->connector_states[i];
if (!connector)
continue;
if (conn_state->crtc == set->crtc) { if (conn_state->crtc == set->crtc) {
ret = drm_atomic_set_crtc_for_connector(conn_state, ret = drm_atomic_set_crtc_for_connector(conn_state,
NULL); NULL);
@ -1568,13 +1471,7 @@ static int update_output_state(struct drm_atomic_state *state,
} }
} }
for (i = 0; i < ncrtcs; i++) { for_each_crtc_in_state(state, crtc, crtc_state, i) {
struct drm_crtc *crtc = state->crtcs[i];
struct drm_crtc_state *crtc_state = state->crtc_states[i];
if (!crtc)
continue;
/* Don't update ->enable for the CRTC in the set_config request, /* Don't update ->enable for the CRTC in the set_config request,
* since a mismatch would indicate a bug in the upper layers. * since a mismatch would indicate a bug in the upper layers.
* The actual modeset code later on will catch any * The actual modeset code later on will catch any

View File

@ -75,4 +75,28 @@ int __must_check drm_atomic_check_only(struct drm_atomic_state *state);
int __must_check drm_atomic_commit(struct drm_atomic_state *state); int __must_check drm_atomic_commit(struct drm_atomic_state *state);
int __must_check drm_atomic_async_commit(struct drm_atomic_state *state); int __must_check drm_atomic_async_commit(struct drm_atomic_state *state);
#define for_each_connector_in_state(state, connector, connector_state, __i) \
for ((__i) = 0; \
(connector) = (state)->connectors[__i], \
(connector_state) = (state)->connector_states[__i], \
(__i) < (state)->num_connector; \
(__i)++) \
if (connector)
#define for_each_crtc_in_state(state, crtc, crtc_state, __i) \
for ((__i) = 0; \
(crtc) = (state)->crtcs[__i], \
(crtc_state) = (state)->crtc_states[__i], \
(__i) < (state)->dev->mode_config.num_crtc; \
(__i)++) \
if (crtc_state)
#define for_each_plane_in_state(state, plane, plane_state, __i) \
for ((__i) = 0; \
(plane) = (state)->planes[__i], \
(plane_state) = (state)->plane_states[__i], \
(__i) < (state)->dev->mode_config.num_total_plane; \
(__i)++) \
if (plane_state)
#endif /* DRM_ATOMIC_H_ */ #endif /* DRM_ATOMIC_H_ */