Commit 6295d607 authored by Daniel Vetter's avatar Daniel Vetter

drm: Add modeset object iterators

And roll them out across drm_* files. The point here isn't code
prettification (it helps with that too) but that some of these lists
aren't static any more. And having macros will gives us a convenient
place to put locking checks into.

I didn't add an iterator for props since that's only used by a
list_for_each_entry_safe in the driver teardown code.

Search&replace was done with the below cocci spatch. Note that there's
a bunch more places that didn't match and which would need some manual
changes, but I've intentially left these out for this mostly automated
patch.

iterator name drm_for_each_crtc;
struct drm_crtc *crtc;
struct drm_device *dev;
expression head;
@@
- list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
+ drm_for_each_crtc (crtc, dev) {
...
}

@@
iterator name drm_for_each_encoder;
struct drm_encoder *encoder;
struct drm_device *dev;
expression head;
@@
- list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
+ drm_for_each_encoder (encoder, dev) {
...
}

@@
iterator name drm_for_each_fb;
struct drm_framebuffer *fb;
struct drm_device *dev;
expression head;
@@
- list_for_each_entry(fb, &dev->mode_config.fb_list, head) {
+ drm_for_each_fb (fb, dev) {
...
}

@@
iterator name drm_for_each_connector;
struct drm_connector *connector;
struct drm_device *dev;
expression head;
@@
- list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
+ drm_for_each_connector (connector, dev) {
...
}
Reviewed-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
parent 4ea50e99
...@@ -615,7 +615,7 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb) ...@@ -615,7 +615,7 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb)
if (atomic_read(&fb->refcount.refcount) > 1) { if (atomic_read(&fb->refcount.refcount) > 1) {
drm_modeset_lock_all(dev); drm_modeset_lock_all(dev);
/* remove from any CRTC */ /* remove from any CRTC */
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { drm_for_each_crtc(crtc, dev) {
if (crtc->primary->fb == fb) { if (crtc->primary->fb == fb) {
/* should turn off the crtc */ /* should turn off the crtc */
memset(&set, 0, sizeof(struct drm_mode_set)); memset(&set, 0, sizeof(struct drm_mode_set));
...@@ -627,7 +627,7 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb) ...@@ -627,7 +627,7 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb)
} }
} }
list_for_each_entry(plane, &dev->mode_config.plane_list, head) { drm_for_each_plane(plane, dev) {
if (plane->fb == fb) if (plane->fb == fb)
drm_plane_force_disable(plane); drm_plane_force_disable(plane);
} }
...@@ -1305,7 +1305,7 @@ drm_plane_from_index(struct drm_device *dev, int idx) ...@@ -1305,7 +1305,7 @@ drm_plane_from_index(struct drm_device *dev, int idx)
struct drm_plane *plane; struct drm_plane *plane;
unsigned int i = 0; unsigned int i = 0;
list_for_each_entry(plane, &dev->mode_config.plane_list, head) { drm_for_each_plane(plane, dev) {
if (i == idx) if (i == idx)
return plane; return plane;
i++; i++;
...@@ -1838,8 +1838,7 @@ int drm_mode_getresources(struct drm_device *dev, void *data, ...@@ -1838,8 +1838,7 @@ int drm_mode_getresources(struct drm_device *dev, void *data,
copied = 0; copied = 0;
crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr; crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr;
if (!mode_group) { if (!mode_group) {
list_for_each_entry(crtc, &dev->mode_config.crtc_list, drm_for_each_crtc(crtc, dev) {
head) {
DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id); DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
if (put_user(crtc->base.id, crtc_id + copied)) { if (put_user(crtc->base.id, crtc_id + copied)) {
ret = -EFAULT; ret = -EFAULT;
...@@ -1865,9 +1864,7 @@ int drm_mode_getresources(struct drm_device *dev, void *data, ...@@ -1865,9 +1864,7 @@ int drm_mode_getresources(struct drm_device *dev, void *data,
copied = 0; copied = 0;
encoder_id = (uint32_t __user *)(unsigned long)card_res->encoder_id_ptr; encoder_id = (uint32_t __user *)(unsigned long)card_res->encoder_id_ptr;
if (!mode_group) { if (!mode_group) {
list_for_each_entry(encoder, drm_for_each_encoder(encoder, dev) {
&dev->mode_config.encoder_list,
head) {
DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder->base.id, DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder->base.id,
encoder->name); encoder->name);
if (put_user(encoder->base.id, encoder_id + if (put_user(encoder->base.id, encoder_id +
...@@ -1896,9 +1893,7 @@ int drm_mode_getresources(struct drm_device *dev, void *data, ...@@ -1896,9 +1893,7 @@ int drm_mode_getresources(struct drm_device *dev, void *data,
copied = 0; copied = 0;
connector_id = (uint32_t __user *)(unsigned long)card_res->connector_id_ptr; connector_id = (uint32_t __user *)(unsigned long)card_res->connector_id_ptr;
if (!mode_group) { if (!mode_group) {
list_for_each_entry(connector, drm_for_each_connector(connector, dev) {
&dev->mode_config.connector_list,
head) {
DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
connector->base.id, connector->base.id,
connector->name); connector->name);
...@@ -2187,7 +2182,7 @@ static struct drm_crtc *drm_encoder_get_crtc(struct drm_encoder *encoder) ...@@ -2187,7 +2182,7 @@ static struct drm_crtc *drm_encoder_get_crtc(struct drm_encoder *encoder)
/* For atomic drivers only state objects are synchronously updated and /* For atomic drivers only state objects are synchronously updated and
* protected by modeset locks, so check those first. */ * protected by modeset locks, so check those first. */
list_for_each_entry(connector, &dev->mode_config.connector_list, head) { drm_for_each_connector(connector, dev) {
if (!connector->state) if (!connector->state)
continue; continue;
...@@ -5393,7 +5388,7 @@ void drm_mode_config_reset(struct drm_device *dev) ...@@ -5393,7 +5388,7 @@ void drm_mode_config_reset(struct drm_device *dev)
if (encoder->funcs->reset) if (encoder->funcs->reset)
encoder->funcs->reset(encoder); encoder->funcs->reset(encoder);
list_for_each_entry(connector, &dev->mode_config.connector_list, head) { drm_for_each_connector(connector, dev) {
connector->status = connector_status_unknown; connector->status = connector_status_unknown;
if (connector->funcs->reset) if (connector->funcs->reset)
......
...@@ -180,7 +180,7 @@ static void __drm_helper_disable_unused_functions(struct drm_device *dev) ...@@ -180,7 +180,7 @@ static void __drm_helper_disable_unused_functions(struct drm_device *dev)
drm_warn_on_modeset_not_all_locked(dev); drm_warn_on_modeset_not_all_locked(dev);
list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { drm_for_each_encoder(encoder, dev) {
if (!drm_helper_encoder_in_use(encoder)) { if (!drm_helper_encoder_in_use(encoder)) {
drm_encoder_disable(encoder); drm_encoder_disable(encoder);
/* disconnect encoder from any connector */ /* disconnect encoder from any connector */
...@@ -188,7 +188,7 @@ static void __drm_helper_disable_unused_functions(struct drm_device *dev) ...@@ -188,7 +188,7 @@ static void __drm_helper_disable_unused_functions(struct drm_device *dev)
} }
} }
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { drm_for_each_crtc(crtc, dev) {
const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
crtc->enabled = drm_helper_crtc_in_use(crtc); crtc->enabled = drm_helper_crtc_in_use(crtc);
if (!crtc->enabled) { if (!crtc->enabled) {
...@@ -230,7 +230,7 @@ drm_crtc_prepare_encoders(struct drm_device *dev) ...@@ -230,7 +230,7 @@ drm_crtc_prepare_encoders(struct drm_device *dev)
const struct drm_encoder_helper_funcs *encoder_funcs; const struct drm_encoder_helper_funcs *encoder_funcs;
struct drm_encoder *encoder; struct drm_encoder *encoder;
list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { drm_for_each_encoder(encoder, dev) {
encoder_funcs = encoder->helper_private; encoder_funcs = encoder->helper_private;
/* Disable unused encoders */ /* Disable unused encoders */
if (encoder->crtc == NULL) if (encoder->crtc == NULL)
...@@ -305,7 +305,7 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc, ...@@ -305,7 +305,7 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
* adjust it according to limitations or connector properties, and also * adjust it according to limitations or connector properties, and also
* a chance to reject the mode entirely. * a chance to reject the mode entirely.
*/ */
list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { drm_for_each_encoder(encoder, dev) {
if (encoder->crtc != crtc) if (encoder->crtc != crtc)
continue; continue;
...@@ -334,7 +334,7 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc, ...@@ -334,7 +334,7 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
crtc->hwmode = *adjusted_mode; crtc->hwmode = *adjusted_mode;
/* Prepare the encoders and CRTCs before setting the mode. */ /* Prepare the encoders and CRTCs before setting the mode. */
list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { drm_for_each_encoder(encoder, dev) {
if (encoder->crtc != crtc) if (encoder->crtc != crtc)
continue; continue;
...@@ -359,7 +359,7 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc, ...@@ -359,7 +359,7 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
if (!ret) if (!ret)
goto done; goto done;
list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { drm_for_each_encoder(encoder, dev) {
if (encoder->crtc != crtc) if (encoder->crtc != crtc)
continue; continue;
...@@ -376,7 +376,7 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc, ...@@ -376,7 +376,7 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
/* Now enable the clocks, plane, pipe, and connectors that we set up. */ /* Now enable the clocks, plane, pipe, and connectors that we set up. */
crtc_funcs->commit(crtc); crtc_funcs->commit(crtc);
list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { drm_for_each_encoder(encoder, dev) {
if (encoder->crtc != crtc) if (encoder->crtc != crtc)
continue; continue;
...@@ -418,11 +418,11 @@ drm_crtc_helper_disable(struct drm_crtc *crtc) ...@@ -418,11 +418,11 @@ drm_crtc_helper_disable(struct drm_crtc *crtc)
struct drm_encoder *encoder; struct drm_encoder *encoder;
/* Decouple all encoders and their attached connectors from this crtc */ /* Decouple all encoders and their attached connectors from this crtc */
list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { drm_for_each_encoder(encoder, dev) {
if (encoder->crtc != crtc) if (encoder->crtc != crtc)
continue; continue;
list_for_each_entry(connector, &dev->mode_config.connector_list, head) { drm_for_each_connector(connector, dev) {
if (connector->encoder != encoder) if (connector->encoder != encoder)
continue; continue;
...@@ -519,12 +519,12 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set) ...@@ -519,12 +519,12 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
* restored, not the drivers personal bookkeeping. * restored, not the drivers personal bookkeeping.
*/ */
count = 0; count = 0;
list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { drm_for_each_encoder(encoder, dev) {
save_encoders[count++] = *encoder; save_encoders[count++] = *encoder;
} }
count = 0; count = 0;
list_for_each_entry(connector, &dev->mode_config.connector_list, head) { drm_for_each_connector(connector, dev) {
save_connectors[count++] = *connector; save_connectors[count++] = *connector;
} }
...@@ -562,7 +562,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set) ...@@ -562,7 +562,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
/* a) traverse passed in connector list and get encoders for them */ /* a) traverse passed in connector list and get encoders for them */
count = 0; count = 0;
list_for_each_entry(connector, &dev->mode_config.connector_list, head) { drm_for_each_connector(connector, dev) {
const struct drm_connector_helper_funcs *connector_funcs = const struct drm_connector_helper_funcs *connector_funcs =
connector->helper_private; connector->helper_private;
new_encoder = connector->encoder; new_encoder = connector->encoder;
...@@ -602,7 +602,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set) ...@@ -602,7 +602,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
} }
count = 0; count = 0;
list_for_each_entry(connector, &dev->mode_config.connector_list, head) { drm_for_each_connector(connector, dev) {
if (!connector->encoder) if (!connector->encoder)
continue; continue;
...@@ -685,12 +685,12 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set) ...@@ -685,12 +685,12 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
fail: fail:
/* Restore all previous data. */ /* Restore all previous data. */
count = 0; count = 0;
list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { drm_for_each_encoder(encoder, dev) {
*encoder = save_encoders[count++]; *encoder = save_encoders[count++];
} }
count = 0; count = 0;
list_for_each_entry(connector, &dev->mode_config.connector_list, head) { drm_for_each_connector(connector, dev) {
*connector = save_connectors[count++]; *connector = save_connectors[count++];
} }
...@@ -862,7 +862,7 @@ void drm_helper_resume_force_mode(struct drm_device *dev) ...@@ -862,7 +862,7 @@ void drm_helper_resume_force_mode(struct drm_device *dev)
bool ret; bool ret;
drm_modeset_lock_all(dev); drm_modeset_lock_all(dev);
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { drm_for_each_crtc(crtc, dev) {
if (!crtc->enabled) if (!crtc->enabled)
continue; continue;
...@@ -876,7 +876,7 @@ void drm_helper_resume_force_mode(struct drm_device *dev) ...@@ -876,7 +876,7 @@ void drm_helper_resume_force_mode(struct drm_device *dev)
/* Turn off outputs that were already powered off */ /* Turn off outputs that were already powered off */
if (drm_helper_choose_crtc_dpms(crtc)) { if (drm_helper_choose_crtc_dpms(crtc)) {
list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { drm_for_each_encoder(encoder, dev) {
if(encoder->crtc != crtc) if(encoder->crtc != crtc)
continue; continue;
......
...@@ -98,7 +98,7 @@ int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper) ...@@ -98,7 +98,7 @@ int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
struct drm_connector *connector; struct drm_connector *connector;
int i; int i;
list_for_each_entry(connector, &dev->mode_config.connector_list, head) { drm_for_each_connector(connector, dev) {
struct drm_fb_helper_connector *fb_helper_connector; struct drm_fb_helper_connector *fb_helper_connector;
fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL); fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL);
...@@ -269,7 +269,7 @@ static struct drm_framebuffer *drm_mode_config_fb(struct drm_crtc *crtc) ...@@ -269,7 +269,7 @@ static struct drm_framebuffer *drm_mode_config_fb(struct drm_crtc *crtc)
struct drm_device *dev = crtc->dev; struct drm_device *dev = crtc->dev;
struct drm_crtc *c; struct drm_crtc *c;
list_for_each_entry(c, &dev->mode_config.crtc_list, head) { drm_for_each_crtc(c, dev) {
if (crtc->base.id == c->base.id) if (crtc->base.id == c->base.id)
return c->primary->fb; return c->primary->fb;
} }
...@@ -321,7 +321,7 @@ static bool restore_fbdev_mode(struct drm_fb_helper *fb_helper) ...@@ -321,7 +321,7 @@ static bool restore_fbdev_mode(struct drm_fb_helper *fb_helper)
drm_warn_on_modeset_not_all_locked(dev); drm_warn_on_modeset_not_all_locked(dev);
list_for_each_entry(plane, &dev->mode_config.plane_list, head) { drm_for_each_plane(plane, dev) {
if (plane->type != DRM_PLANE_TYPE_PRIMARY) if (plane->type != DRM_PLANE_TYPE_PRIMARY)
drm_plane_force_disable(plane); drm_plane_force_disable(plane);
...@@ -458,7 +458,7 @@ static bool drm_fb_helper_is_bound(struct drm_fb_helper *fb_helper) ...@@ -458,7 +458,7 @@ static bool drm_fb_helper_is_bound(struct drm_fb_helper *fb_helper)
if (dev->primary->master) if (dev->primary->master)
return false; return false;
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { drm_for_each_crtc(crtc, dev) {
if (crtc->primary->fb) if (crtc->primary->fb)
crtcs_bound++; crtcs_bound++;
if (crtc->primary->fb == fb_helper->fb) if (crtc->primary->fb == fb_helper->fb)
...@@ -655,7 +655,7 @@ int drm_fb_helper_init(struct drm_device *dev, ...@@ -655,7 +655,7 @@ int drm_fb_helper_init(struct drm_device *dev,
} }
i = 0; i = 0;
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { drm_for_each_crtc(crtc, dev) {
fb_helper->crtc_info[i].mode_set.crtc = crtc; fb_helper->crtc_info[i].mode_set.crtc = crtc;
i++; i++;
} }
......
...@@ -19,7 +19,7 @@ static uint32_t drm_crtc_port_mask(struct drm_device *dev, ...@@ -19,7 +19,7 @@ static uint32_t drm_crtc_port_mask(struct drm_device *dev,
unsigned int index = 0; unsigned int index = 0;
struct drm_crtc *tmp; struct drm_crtc *tmp;
list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) { drm_for_each_crtc(tmp, dev) {
if (tmp->port == port) if (tmp->port == port)
return 1 << index; return 1 << index;
......
...@@ -312,7 +312,7 @@ static void output_poll_execute(struct work_struct *work) ...@@ -312,7 +312,7 @@ static void output_poll_execute(struct work_struct *work)
goto out; goto out;
mutex_lock(&dev->mode_config.mutex); mutex_lock(&dev->mode_config.mutex);
list_for_each_entry(connector, &dev->mode_config.connector_list, head) { drm_for_each_connector(connector, dev) {
/* Ignore forced connectors. */ /* Ignore forced connectors. */
if (connector->force) if (connector->force)
...@@ -413,7 +413,7 @@ void drm_kms_helper_poll_enable(struct drm_device *dev) ...@@ -413,7 +413,7 @@ void drm_kms_helper_poll_enable(struct drm_device *dev)
if (!dev->mode_config.poll_enabled || !drm_kms_helper_poll) if (!dev->mode_config.poll_enabled || !drm_kms_helper_poll)
return; return;
list_for_each_entry(connector, &dev->mode_config.connector_list, head) { drm_for_each_connector(connector, dev) {
if (connector->polled & (DRM_CONNECTOR_POLL_CONNECT | if (connector->polled & (DRM_CONNECTOR_POLL_CONNECT |
DRM_CONNECTOR_POLL_DISCONNECT)) DRM_CONNECTOR_POLL_DISCONNECT))
poll = true; poll = true;
...@@ -495,7 +495,7 @@ bool drm_helper_hpd_irq_event(struct drm_device *dev) ...@@ -495,7 +495,7 @@ bool drm_helper_hpd_irq_event(struct drm_device *dev)
return false; return false;
mutex_lock(&dev->mode_config.mutex); mutex_lock(&dev->mode_config.mutex);
list_for_each_entry(connector, &dev->mode_config.connector_list, head) { drm_for_each_connector(connector, dev) {
/* Only handle HPD capable connectors. */ /* Only handle HPD capable connectors. */
if (!(connector->polled & DRM_CONNECTOR_POLL_HPD)) if (!(connector->polled & DRM_CONNECTOR_POLL_HPD))
......
...@@ -1583,4 +1583,19 @@ static inline struct drm_property *drm_property_find(struct drm_device *dev, ...@@ -1583,4 +1583,19 @@ static inline struct drm_property *drm_property_find(struct drm_device *dev,
list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \ list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
if (plane->type == DRM_PLANE_TYPE_OVERLAY) if (plane->type == DRM_PLANE_TYPE_OVERLAY)
#define drm_for_each_plane(plane, dev) \
list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
#define drm_for_each_crtc(crtc, dev) \
list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
#define drm_for_each_connector(connector, dev) \
list_for_each_entry(connector, &(dev)->mode_config.connector_list, head)
#define drm_for_each_encoder(encoder, dev) \
list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
#define drm_for_each_fb(fb, dev) \
list_for_each_entry(fb, &(dev)->mode_config.fb_list, head)
#endif /* __DRM_CRTC_H__ */ #endif /* __DRM_CRTC_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment