From: Daniel Vetter <daniel@ffwll.ch>
To: Rob Clark <robdclark@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 06/17] drm: helpers to find mode objects
Date: Mon, 26 May 2014 10:37:28 +0200 [thread overview]
Message-ID: <20140526083728.GZ14357@phenom.ffwll.local> (raw)
In-Reply-To: <1400956226-28053-7-git-send-email-robdclark@gmail.com>
On Sat, May 24, 2014 at 02:30:15PM -0400, Rob Clark wrote:
> Add a few more useful helpers to find mode objects.
>
> Signed-off-by: Rob Clark <robdclark@gmail.com>
There's a pile more in drivers for these. I like this, but imo we should
also convert drivers while at it. Also, docbook is missing. And since it's
a cleanup I think it's better to do this first, directly on top of
drm-next. The patch itself looks good.
-Daniel
> ---
> drivers/gpu/drm/drm_crtc.c | 97 ++++++++++++++--------------------------------
> include/drm/drm_crtc.h | 33 ++++++++++++++++
> 2 files changed, 63 insertions(+), 67 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index fa86fba..bd12185 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -1736,7 +1736,6 @@ int drm_mode_getcrtc(struct drm_device *dev,
> {
> struct drm_mode_crtc *crtc_resp = data;
> struct drm_crtc *crtc;
> - struct drm_mode_object *obj;
> int ret = 0;
>
> if (!drm_core_check_feature(dev, DRIVER_MODESET))
> @@ -1744,13 +1743,11 @@ int drm_mode_getcrtc(struct drm_device *dev,
>
> drm_modeset_lock_all(dev);
>
> - obj = drm_mode_object_find(dev, crtc_resp->crtc_id,
> - DRM_MODE_OBJECT_CRTC);
> - if (!obj) {
> + crtc = drm_crtc_find(dev, crtc_resp->crtc_id);
> + if (!crtc) {
> ret = -ENOENT;
> goto out;
> }
> - crtc = obj_to_crtc(obj);
>
> crtc_resp->x = crtc->x;
> crtc_resp->y = crtc->y;
> @@ -1804,7 +1801,6 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
> struct drm_file *file_priv)
> {
> struct drm_mode_get_connector *out_resp = data;
> - struct drm_mode_object *obj;
> struct drm_connector *connector;
> struct drm_display_mode *mode;
> int mode_count = 0;
> @@ -1828,13 +1824,11 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
>
> drm_modeset_lock(&dev->mode_config.mutex, NULL);
>
> - obj = drm_mode_object_find(dev, out_resp->connector_id,
> - DRM_MODE_OBJECT_CONNECTOR);
> - if (!obj) {
> + connector = drm_connector_find(dev, out_resp->connector_id);
> + if (!connector) {
> ret = -ENOENT;
> goto out;
> }
> - connector = obj_to_connector(obj);
>
> props_count = connector->properties.count;
>
> @@ -1949,7 +1943,6 @@ int drm_mode_getencoder(struct drm_device *dev, void *data,
> struct drm_file *file_priv)
> {
> struct drm_mode_get_encoder *enc_resp = data;
> - struct drm_mode_object *obj;
> struct drm_encoder *encoder;
> int ret = 0;
>
> @@ -1957,13 +1950,11 @@ int drm_mode_getencoder(struct drm_device *dev, void *data,
> return -EINVAL;
>
> drm_modeset_lock_all(dev);
> - obj = drm_mode_object_find(dev, enc_resp->encoder_id,
> - DRM_MODE_OBJECT_ENCODER);
> - if (!obj) {
> + encoder = drm_encoder_find(dev, enc_resp->encoder_id);
> + if (!encoder) {
> ret = -ENOENT;
> goto out;
> }
> - encoder = obj_to_encoder(obj);
>
> if (encoder->crtc)
> enc_resp->crtc_id = encoder->crtc->base.id;
> @@ -2061,7 +2052,6 @@ int drm_mode_getplane(struct drm_device *dev, void *data,
> struct drm_file *file_priv)
> {
> struct drm_mode_get_plane *plane_resp = data;
> - struct drm_mode_object *obj;
> struct drm_plane *plane;
> uint32_t __user *format_ptr;
> int ret = 0;
> @@ -2070,13 +2060,11 @@ int drm_mode_getplane(struct drm_device *dev, void *data,
> return -EINVAL;
>
> drm_modeset_lock_all(dev);
> - obj = drm_mode_object_find(dev, plane_resp->plane_id,
> - DRM_MODE_OBJECT_PLANE);
> - if (!obj) {
> + plane = drm_plane_find(dev, plane_resp->plane_id);
> + if (!plane) {
> ret = -ENOENT;
> goto out;
> }
> - plane = obj_to_plane(obj);
>
> if (plane->crtc)
> plane_resp->crtc_id = plane->crtc->base.id;
> @@ -2129,7 +2117,6 @@ int drm_mode_setplane(struct drm_device *dev, void *data,
> struct drm_file *file_priv)
> {
> struct drm_mode_set_plane *plane_req = data;
> - struct drm_mode_object *obj;
> struct drm_plane *plane;
> struct drm_crtc *crtc;
> struct drm_framebuffer *fb = NULL, *old_fb = NULL;
> @@ -2144,14 +2131,12 @@ int drm_mode_setplane(struct drm_device *dev, void *data,
> * First, find the plane, crtc, and fb objects. If not available,
> * we don't bother to call the driver.
> */
> - obj = drm_mode_object_find(dev, plane_req->plane_id,
> - DRM_MODE_OBJECT_PLANE);
> - if (!obj) {
> + plane = drm_plane_find(dev, plane_req->plane_id);
> + if (!plane) {
> DRM_DEBUG_KMS("Unknown plane ID %d\n",
> plane_req->plane_id);
> return -ENOENT;
> }
> - plane = obj_to_plane(obj);
>
> /* No fb means shut it down */
> if (!plane_req->fb_id) {
> @@ -2168,15 +2153,13 @@ int drm_mode_setplane(struct drm_device *dev, void *data,
> goto out;
> }
>
> - obj = drm_mode_object_find(dev, plane_req->crtc_id,
> - DRM_MODE_OBJECT_CRTC);
> - if (!obj) {
> + crtc = drm_crtc_find(dev, plane_req->crtc_id);
> + if (!crtc) {
> DRM_DEBUG_KMS("Unknown crtc ID %d\n",
> plane_req->crtc_id);
> ret = -ENOENT;
> goto out;
> }
> - crtc = obj_to_crtc(obj);
>
> fb = drm_framebuffer_lookup(dev, plane_req->fb_id);
> if (!fb) {
> @@ -2363,7 +2346,6 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
> {
> struct drm_mode_config *config = &dev->mode_config;
> struct drm_mode_crtc *crtc_req = data;
> - struct drm_mode_object *obj;
> struct drm_crtc *crtc;
> struct drm_connector **connector_set = NULL, *connector;
> struct drm_framebuffer *fb = NULL;
> @@ -2381,14 +2363,12 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
> return -ERANGE;
>
> drm_modeset_lock_all(dev);
> - obj = drm_mode_object_find(dev, crtc_req->crtc_id,
> - DRM_MODE_OBJECT_CRTC);
> - if (!obj) {
> + crtc = drm_crtc_find(dev, crtc_req->crtc_id);
> + if (!crtc) {
> DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id);
> ret = -ENOENT;
> goto out;
> }
> - crtc = obj_to_crtc(obj);
> DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
>
> if (crtc_req->mode_valid) {
> @@ -2471,15 +2451,13 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
> goto out;
> }
>
> - obj = drm_mode_object_find(dev, out_id,
> - DRM_MODE_OBJECT_CONNECTOR);
> - if (!obj) {
> + connector = drm_connector_find(dev, out_id);
> + if (!connector) {
> DRM_DEBUG_KMS("Connector id %d unknown\n",
> out_id);
> ret = -ENOENT;
> goto out;
> }
> - connector = obj_to_connector(obj);
> DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
> connector->base.id,
> drm_get_connector_name(connector));
> @@ -2511,7 +2489,6 @@ static int drm_mode_cursor_common(struct drm_device *dev,
> struct drm_mode_cursor2 *req,
> struct drm_file *file_priv)
> {
> - struct drm_mode_object *obj;
> struct drm_crtc *crtc;
> int ret = 0;
>
> @@ -2521,12 +2498,11 @@ static int drm_mode_cursor_common(struct drm_device *dev,
> if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags))
> return -EINVAL;
>
> - obj = drm_mode_object_find(dev, req->crtc_id, DRM_MODE_OBJECT_CRTC);
> - if (!obj) {
> + crtc = drm_crtc_find(dev, req->crtc_id);
> + if (!crtc) {
> DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id);
> return -ENOENT;
> }
> - crtc = obj_to_crtc(obj);
>
> drm_modeset_lock(&crtc->mutex, NULL);
> if (req->flags & DRM_MODE_CURSOR_BO) {
> @@ -3522,7 +3498,6 @@ EXPORT_SYMBOL(drm_object_property_get_value);
> int drm_mode_getproperty_ioctl(struct drm_device *dev,
> void *data, struct drm_file *file_priv)
> {
> - struct drm_mode_object *obj;
> struct drm_mode_get_property *out_resp = data;
> struct drm_property *property;
> int enum_count = 0;
> @@ -3541,12 +3516,11 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
> return -EINVAL;
>
> drm_modeset_lock_all(dev);
> - obj = drm_mode_object_find(dev, out_resp->prop_id, DRM_MODE_OBJECT_PROPERTY);
> - if (!obj) {
> + property = drm_property_find(dev, out_resp->prop_id);
> + if (!property) {
> ret = -ENOENT;
> goto done;
> }
> - property = obj_to_property(obj);
>
> if (drm_property_type_is(property, DRM_MODE_PROP_ENUM) ||
> drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) {
> @@ -3676,7 +3650,6 @@ static void drm_property_destroy_blob(struct drm_device *dev,
> int drm_mode_getblob_ioctl(struct drm_device *dev,
> void *data, struct drm_file *file_priv)
> {
> - struct drm_mode_object *obj;
> struct drm_mode_get_blob *out_resp = data;
> struct drm_property_blob *blob;
> int ret = 0;
> @@ -3686,12 +3659,11 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
> return -EINVAL;
>
> drm_modeset_lock_all(dev);
> - obj = drm_mode_object_find(dev, out_resp->blob_id, DRM_MODE_OBJECT_BLOB);
> - if (!obj) {
> + blob = drm_property_blob_find(dev, out_resp->blob_id);
> + if (!blob) {
> ret = -ENOENT;
> goto done;
> }
> - blob = obj_to_blob(obj);
>
> if (out_resp->length == blob->length) {
> blob_ptr = (void __user *)(unsigned long)out_resp->data;
> @@ -3898,7 +3870,6 @@ static int drm_mode_set_obj_prop_id(struct drm_device *dev,
> uint32_t prop_id, uint64_t value, void *blob_data)
> {
> struct drm_mode_object *arg_obj;
> - struct drm_mode_object *prop_obj;
> struct drm_property *property;
> int i;
>
> @@ -3915,11 +3886,9 @@ static int drm_mode_set_obj_prop_id(struct drm_device *dev,
> if (i == arg_obj->properties->count)
> return -EINVAL;
>
> - prop_obj = drm_mode_object_find(dev, prop_id,
> - DRM_MODE_OBJECT_PROPERTY);
> - if (!prop_obj)
> + property = drm_property_find(dev, prop_id);
> + if (!property)
> return -ENOENT;
> - property = obj_to_property(prop_obj);
>
> return drm_mode_set_obj_prop(arg_obj, state, property,
> value, blob_data);
> @@ -4126,7 +4095,6 @@ int drm_mode_gamma_set_ioctl(struct drm_device *dev,
> void *data, struct drm_file *file_priv)
> {
> struct drm_mode_crtc_lut *crtc_lut = data;
> - struct drm_mode_object *obj;
> struct drm_crtc *crtc;
> void *r_base, *g_base, *b_base;
> int size;
> @@ -4136,12 +4104,11 @@ int drm_mode_gamma_set_ioctl(struct drm_device *dev,
> return -EINVAL;
>
> drm_modeset_lock_all(dev);
> - obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC);
> - if (!obj) {
> + crtc = drm_crtc_find(dev, crtc_lut->crtc_id);
> + if (!crtc) {
> ret = -ENOENT;
> goto out;
> }
> - crtc = obj_to_crtc(obj);
>
> if (crtc->funcs->gamma_set == NULL) {
> ret = -ENOSYS;
> @@ -4200,7 +4167,6 @@ int drm_mode_gamma_get_ioctl(struct drm_device *dev,
> void *data, struct drm_file *file_priv)
> {
> struct drm_mode_crtc_lut *crtc_lut = data;
> - struct drm_mode_object *obj;
> struct drm_crtc *crtc;
> void *r_base, *g_base, *b_base;
> int size;
> @@ -4210,12 +4176,11 @@ int drm_mode_gamma_get_ioctl(struct drm_device *dev,
> return -EINVAL;
>
> drm_modeset_lock_all(dev);
> - obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC);
> - if (!obj) {
> + crtc = drm_crtc_find(dev, crtc_lut->crtc_id);
> + if (!crtc) {
> ret = -ENOENT;
> goto out;
> }
> - crtc = obj_to_crtc(obj);
>
> /* memcpy into gamma store */
> if (crtc_lut->gamma_size != crtc->gamma_size) {
> @@ -4268,7 +4233,6 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
> void *data, struct drm_file *file_priv)
> {
> struct drm_mode_crtc_page_flip *page_flip = data;
> - struct drm_mode_object *obj;
> struct drm_crtc *crtc;
> struct drm_framebuffer *fb = NULL, *old_fb = NULL;
> struct drm_pending_vblank_event *e = NULL;
> @@ -4282,10 +4246,9 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
> if ((page_flip->flags & DRM_MODE_PAGE_FLIP_ASYNC) && !dev->mode_config.async_page_flip)
> return -EINVAL;
>
> - obj = drm_mode_object_find(dev, page_flip->crtc_id, DRM_MODE_OBJECT_CRTC);
> - if (!obj)
> + crtc = drm_crtc_find(dev, page_flip->crtc_id);
> + if (!crtc)
> return -ENOENT;
> - crtc = obj_to_crtc(obj);
>
> drm_modeset_lock(&crtc->mutex, NULL);
> if (crtc->primary->fb == NULL) {
> diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
> index cd4a61a..b940a29 100644
> --- a/include/drm/drm_crtc.h
> +++ b/include/drm/drm_crtc.h
> @@ -1112,6 +1112,15 @@ extern int drm_format_vert_chroma_subsampling(uint32_t format);
> extern const char *drm_get_format_name(uint32_t format);
>
> /* Helpers */
> +
> +static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
> + uint32_t id)
> +{
> + struct drm_mode_object *mo;
> + mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
> + return mo ? obj_to_plane(mo) : NULL;
> +}
> +
> static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
> uint32_t id)
> {
> @@ -1128,6 +1137,30 @@ static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
> return mo ? obj_to_encoder(mo) : NULL;
> }
>
> +static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
> + uint32_t id)
> +{
> + struct drm_mode_object *mo;
> + mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
> + return mo ? obj_to_connector(mo) : NULL;
> +}
> +
> +static inline struct drm_property *drm_property_find(struct drm_device *dev,
> + uint32_t id)
> +{
> + struct drm_mode_object *mo;
> + mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
> + return mo ? obj_to_property(mo) : NULL;
> +}
> +
> +static inline struct drm_property_blob *
> +drm_property_blob_find(struct drm_device *dev, uint32_t id)
> +{
> + struct drm_mode_object *mo;
> + mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_BLOB);
> + return mo ? obj_to_blob(mo) : NULL;
> +}
> +
> /* Plane list iterator for legacy (overlay only) planes. */
> #define drm_for_each_legacy_plane(plane, planelist) \
> list_for_each_entry(plane, planelist, head) \
> --
> 1.9.0
>
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
next prev parent reply other threads:[~2014-05-26 8:37 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-24 18:30 [PATCH 00/17] prepare for atomic/nuclear modeset/pageflip Rob Clark
2014-05-24 18:30 ` [PATCH 01/17] drm: fix typo Rob Clark
2014-05-24 18:30 ` [PATCH 02/17] drm: add atomic fxns Rob Clark
2014-05-24 18:30 ` [PATCH 03/17] drm: convert crtc and mode_config to ww_mutex Rob Clark
2014-05-25 22:10 ` Daniel Vetter
2014-05-25 23:16 ` Rob Clark
2014-05-26 8:23 ` Daniel Vetter
2014-05-26 11:56 ` Rob Clark
2014-05-26 14:35 ` Daniel Vetter
2014-05-26 14:36 ` Daniel Vetter
2014-05-26 15:04 ` Rob Clark
2014-05-26 15:07 ` Daniel Vetter
2014-05-26 15:20 ` Rob Clark
2014-05-26 15:35 ` Daniel Vetter
2014-05-26 15:49 ` Rob Clark
2014-05-26 16:09 ` Daniel Vetter
2014-05-24 18:30 ` [PATCH 04/17] drm: add object property type Rob Clark
2014-05-26 8:29 ` Daniel Vetter
2014-05-26 8:33 ` Daniel Vetter
2014-05-26 11:06 ` Rob Clark
2014-05-24 18:30 ` [PATCH 05/17] drm: add signed-range " Rob Clark
2014-05-24 18:30 ` [PATCH 06/17] drm: helpers to find mode objects Rob Clark
2014-05-26 8:37 ` Daniel Vetter [this message]
2014-05-26 8:55 ` Daniel Vetter
2014-05-26 11:12 ` Rob Clark
2014-05-24 18:30 ` [PATCH 07/17] drm: split propvals out and blob property support Rob Clark
2014-05-24 18:30 ` [PATCH 08/17] drm: Allow drm_mode_object_find() to look up an object of any type Rob Clark
2014-05-24 18:30 ` [PATCH 09/17] drm: Refactor object property check code Rob Clark
2014-05-24 18:30 ` [PATCH 10/17] drm: allow FB's in drm_mode_object_find Rob Clark
2014-05-26 8:39 ` Daniel Vetter
2014-05-24 18:30 ` [PATCH 11/17] drm: convert plane to properties/state Rob Clark
2014-05-26 9:12 ` Daniel Vetter
2014-05-26 11:32 ` Rob Clark
2014-05-26 14:52 ` Daniel Vetter
2014-05-24 18:30 ` [PATCH 12/17] drm: convert crtc " Rob Clark
2014-05-26 9:31 ` Daniel Vetter
2014-05-26 11:35 ` Rob Clark
2014-05-26 14:56 ` Daniel Vetter
2014-05-26 15:15 ` Rob Clark
2014-05-26 15:23 ` Ville Syrjälä
2014-05-26 15:37 ` Daniel Vetter
2014-05-26 15:42 ` Rob Clark
2014-05-26 15:46 ` Ville Syrjälä
2014-05-26 16:12 ` Daniel Vetter
2014-05-24 18:30 ` [PATCH 13/17] drm: push locking down into restore_fbdev_mode Rob Clark
2014-05-26 9:34 ` Daniel Vetter
2014-05-24 18:30 ` [PATCH 14/17] drm/msm: add atomic support Rob Clark
2014-05-26 17:54 ` Daniel Vetter
2014-05-27 15:58 ` Rob Clark
2014-05-27 17:50 ` Daniel Vetter
2014-05-27 18:48 ` Rob Clark
2014-05-27 19:26 ` Daniel Vetter
2014-05-27 20:06 ` Rob Clark
2014-05-27 22:09 ` Daniel Vetter
2014-05-27 23:32 ` Rob Clark
2014-05-28 13:21 ` Daniel Vetter
2014-05-28 14:14 ` Ville Syrjälä
2014-05-28 14:50 ` Daniel Vetter
2014-05-28 15:19 ` Rob Clark
2014-05-27 23:47 ` Rob Clark
2014-05-28 13:32 ` Daniel Vetter
2014-05-24 18:30 ` [PATCH 15/17] drm: spiff out FB refcnting traces Rob Clark
2014-05-24 18:30 ` [PATCH 16/17] drm: more conservative locking Rob Clark
2014-05-24 18:30 ` [PATCH 17/17] drm: Fix up the atomic legacy paths so they work Rob Clark
2014-05-26 10:40 ` [PATCH 00/17] prepare for atomic/nuclear modeset/pageflip Daniel Vetter
2014-05-26 12:48 ` Rob Clark
2014-05-26 15:24 ` Daniel Vetter
2014-05-26 16:12 ` Rob Clark
2014-05-26 17:36 ` Daniel Vetter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140526083728.GZ14357@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=robdclark@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox