Commit a2b34e22 authored by Rob Clark's avatar Rob Clark Committed by Dave Airlie

drm: helpers to find mode objects

Add a few more useful helpers to find mode objects.
Signed-off-by: default avatarRob Clark <robdclark@gmail.com>
Reviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent d5ab2b43
...@@ -1692,7 +1692,6 @@ int drm_mode_getcrtc(struct drm_device *dev, ...@@ -1692,7 +1692,6 @@ int drm_mode_getcrtc(struct drm_device *dev,
{ {
struct drm_mode_crtc *crtc_resp = data; struct drm_mode_crtc *crtc_resp = data;
struct drm_crtc *crtc; struct drm_crtc *crtc;
struct drm_mode_object *obj;
int ret = 0; int ret = 0;
if (!drm_core_check_feature(dev, DRIVER_MODESET)) if (!drm_core_check_feature(dev, DRIVER_MODESET))
...@@ -1700,13 +1699,11 @@ int drm_mode_getcrtc(struct drm_device *dev, ...@@ -1700,13 +1699,11 @@ int drm_mode_getcrtc(struct drm_device *dev,
drm_modeset_lock_all(dev); drm_modeset_lock_all(dev);
obj = drm_mode_object_find(dev, crtc_resp->crtc_id, crtc = drm_crtc_find(dev, crtc_resp->crtc_id);
DRM_MODE_OBJECT_CRTC); if (!crtc) {
if (!obj) {
ret = -ENOENT; ret = -ENOENT;
goto out; goto out;
} }
crtc = obj_to_crtc(obj);
crtc_resp->x = crtc->x; crtc_resp->x = crtc->x;
crtc_resp->y = crtc->y; crtc_resp->y = crtc->y;
...@@ -1760,7 +1757,6 @@ int drm_mode_getconnector(struct drm_device *dev, void *data, ...@@ -1760,7 +1757,6 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
struct drm_file *file_priv) struct drm_file *file_priv)
{ {
struct drm_mode_get_connector *out_resp = data; struct drm_mode_get_connector *out_resp = data;
struct drm_mode_object *obj;
struct drm_connector *connector; struct drm_connector *connector;
struct drm_display_mode *mode; struct drm_display_mode *mode;
int mode_count = 0; int mode_count = 0;
...@@ -1784,13 +1780,11 @@ int drm_mode_getconnector(struct drm_device *dev, void *data, ...@@ -1784,13 +1780,11 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
mutex_lock(&dev->mode_config.mutex); mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, out_resp->connector_id, connector = drm_connector_find(dev, out_resp->connector_id);
DRM_MODE_OBJECT_CONNECTOR); if (!connector) {
if (!obj) {
ret = -ENOENT; ret = -ENOENT;
goto out; goto out;
} }
connector = obj_to_connector(obj);
props_count = connector->properties.count; props_count = connector->properties.count;
...@@ -1905,7 +1899,6 @@ int drm_mode_getencoder(struct drm_device *dev, void *data, ...@@ -1905,7 +1899,6 @@ int drm_mode_getencoder(struct drm_device *dev, void *data,
struct drm_file *file_priv) struct drm_file *file_priv)
{ {
struct drm_mode_get_encoder *enc_resp = data; struct drm_mode_get_encoder *enc_resp = data;
struct drm_mode_object *obj;
struct drm_encoder *encoder; struct drm_encoder *encoder;
int ret = 0; int ret = 0;
...@@ -1913,13 +1906,11 @@ int drm_mode_getencoder(struct drm_device *dev, void *data, ...@@ -1913,13 +1906,11 @@ int drm_mode_getencoder(struct drm_device *dev, void *data,
return -EINVAL; return -EINVAL;
drm_modeset_lock_all(dev); drm_modeset_lock_all(dev);
obj = drm_mode_object_find(dev, enc_resp->encoder_id, encoder = drm_encoder_find(dev, enc_resp->encoder_id);
DRM_MODE_OBJECT_ENCODER); if (!encoder) {
if (!obj) {
ret = -ENOENT; ret = -ENOENT;
goto out; goto out;
} }
encoder = obj_to_encoder(obj);
if (encoder->crtc) if (encoder->crtc)
enc_resp->crtc_id = encoder->crtc->base.id; enc_resp->crtc_id = encoder->crtc->base.id;
...@@ -2017,7 +2008,6 @@ int drm_mode_getplane(struct drm_device *dev, void *data, ...@@ -2017,7 +2008,6 @@ int drm_mode_getplane(struct drm_device *dev, void *data,
struct drm_file *file_priv) struct drm_file *file_priv)
{ {
struct drm_mode_get_plane *plane_resp = data; struct drm_mode_get_plane *plane_resp = data;
struct drm_mode_object *obj;
struct drm_plane *plane; struct drm_plane *plane;
uint32_t __user *format_ptr; uint32_t __user *format_ptr;
int ret = 0; int ret = 0;
...@@ -2026,13 +2016,11 @@ int drm_mode_getplane(struct drm_device *dev, void *data, ...@@ -2026,13 +2016,11 @@ int drm_mode_getplane(struct drm_device *dev, void *data,
return -EINVAL; return -EINVAL;
drm_modeset_lock_all(dev); drm_modeset_lock_all(dev);
obj = drm_mode_object_find(dev, plane_resp->plane_id, plane = drm_plane_find(dev, plane_resp->plane_id);
DRM_MODE_OBJECT_PLANE); if (!plane) {
if (!obj) {
ret = -ENOENT; ret = -ENOENT;
goto out; goto out;
} }
plane = obj_to_plane(obj);
if (plane->crtc) if (plane->crtc)
plane_resp->crtc_id = plane->crtc->base.id; plane_resp->crtc_id = plane->crtc->base.id;
...@@ -2085,7 +2073,6 @@ int drm_mode_setplane(struct drm_device *dev, void *data, ...@@ -2085,7 +2073,6 @@ int drm_mode_setplane(struct drm_device *dev, void *data,
struct drm_file *file_priv) struct drm_file *file_priv)
{ {
struct drm_mode_set_plane *plane_req = data; struct drm_mode_set_plane *plane_req = data;
struct drm_mode_object *obj;
struct drm_plane *plane; struct drm_plane *plane;
struct drm_crtc *crtc; struct drm_crtc *crtc;
struct drm_framebuffer *fb = NULL, *old_fb = NULL; struct drm_framebuffer *fb = NULL, *old_fb = NULL;
...@@ -2100,14 +2087,12 @@ int drm_mode_setplane(struct drm_device *dev, void *data, ...@@ -2100,14 +2087,12 @@ int drm_mode_setplane(struct drm_device *dev, void *data,
* First, find the plane, crtc, and fb objects. If not available, * First, find the plane, crtc, and fb objects. If not available,
* we don't bother to call the driver. * we don't bother to call the driver.
*/ */
obj = drm_mode_object_find(dev, plane_req->plane_id, plane = drm_plane_find(dev, plane_req->plane_id);
DRM_MODE_OBJECT_PLANE); if (!plane) {
if (!obj) {
DRM_DEBUG_KMS("Unknown plane ID %d\n", DRM_DEBUG_KMS("Unknown plane ID %d\n",
plane_req->plane_id); plane_req->plane_id);
return -ENOENT; return -ENOENT;
} }
plane = obj_to_plane(obj);
/* No fb means shut it down */ /* No fb means shut it down */
if (!plane_req->fb_id) { if (!plane_req->fb_id) {
...@@ -2124,15 +2109,13 @@ int drm_mode_setplane(struct drm_device *dev, void *data, ...@@ -2124,15 +2109,13 @@ int drm_mode_setplane(struct drm_device *dev, void *data,
goto out; goto out;
} }
obj = drm_mode_object_find(dev, plane_req->crtc_id, crtc = drm_crtc_find(dev, plane_req->crtc_id);
DRM_MODE_OBJECT_CRTC); if (!crtc) {
if (!obj) {
DRM_DEBUG_KMS("Unknown crtc ID %d\n", DRM_DEBUG_KMS("Unknown crtc ID %d\n",
plane_req->crtc_id); plane_req->crtc_id);
ret = -ENOENT; ret = -ENOENT;
goto out; goto out;
} }
crtc = obj_to_crtc(obj);
fb = drm_framebuffer_lookup(dev, plane_req->fb_id); fb = drm_framebuffer_lookup(dev, plane_req->fb_id);
if (!fb) { if (!fb) {
...@@ -2319,7 +2302,6 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, ...@@ -2319,7 +2302,6 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
{ {
struct drm_mode_config *config = &dev->mode_config; struct drm_mode_config *config = &dev->mode_config;
struct drm_mode_crtc *crtc_req = data; struct drm_mode_crtc *crtc_req = data;
struct drm_mode_object *obj;
struct drm_crtc *crtc; struct drm_crtc *crtc;
struct drm_connector **connector_set = NULL, *connector; struct drm_connector **connector_set = NULL, *connector;
struct drm_framebuffer *fb = NULL; struct drm_framebuffer *fb = NULL;
...@@ -2337,14 +2319,12 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, ...@@ -2337,14 +2319,12 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
return -ERANGE; return -ERANGE;
drm_modeset_lock_all(dev); drm_modeset_lock_all(dev);
obj = drm_mode_object_find(dev, crtc_req->crtc_id, crtc = drm_crtc_find(dev, crtc_req->crtc_id);
DRM_MODE_OBJECT_CRTC); if (!crtc) {
if (!obj) {
DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id); DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id);
ret = -ENOENT; ret = -ENOENT;
goto out; goto out;
} }
crtc = obj_to_crtc(obj);
DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id); DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
if (crtc_req->mode_valid) { if (crtc_req->mode_valid) {
...@@ -2427,15 +2407,13 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, ...@@ -2427,15 +2407,13 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
goto out; goto out;
} }
obj = drm_mode_object_find(dev, out_id, connector = drm_connector_find(dev, out_id);
DRM_MODE_OBJECT_CONNECTOR); if (!connector) {
if (!obj) {
DRM_DEBUG_KMS("Connector id %d unknown\n", DRM_DEBUG_KMS("Connector id %d unknown\n",
out_id); out_id);
ret = -ENOENT; ret = -ENOENT;
goto out; goto out;
} }
connector = obj_to_connector(obj);
DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
connector->base.id, connector->base.id,
connector->name); connector->name);
...@@ -2467,7 +2445,6 @@ static int drm_mode_cursor_common(struct drm_device *dev, ...@@ -2467,7 +2445,6 @@ static int drm_mode_cursor_common(struct drm_device *dev,
struct drm_mode_cursor2 *req, struct drm_mode_cursor2 *req,
struct drm_file *file_priv) struct drm_file *file_priv)
{ {
struct drm_mode_object *obj;
struct drm_crtc *crtc; struct drm_crtc *crtc;
int ret = 0; int ret = 0;
...@@ -2477,12 +2454,11 @@ static int drm_mode_cursor_common(struct drm_device *dev, ...@@ -2477,12 +2454,11 @@ static int drm_mode_cursor_common(struct drm_device *dev,
if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags)) if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags))
return -EINVAL; return -EINVAL;
obj = drm_mode_object_find(dev, req->crtc_id, DRM_MODE_OBJECT_CRTC); crtc = drm_crtc_find(dev, req->crtc_id);
if (!obj) { if (!crtc) {
DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id); DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id);
return -ENOENT; return -ENOENT;
} }
crtc = obj_to_crtc(obj);
mutex_lock(&crtc->mutex); mutex_lock(&crtc->mutex);
if (req->flags & DRM_MODE_CURSOR_BO) { if (req->flags & DRM_MODE_CURSOR_BO) {
...@@ -3439,7 +3415,6 @@ EXPORT_SYMBOL(drm_object_property_get_value); ...@@ -3439,7 +3415,6 @@ EXPORT_SYMBOL(drm_object_property_get_value);
int drm_mode_getproperty_ioctl(struct drm_device *dev, int drm_mode_getproperty_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv) void *data, struct drm_file *file_priv)
{ {
struct drm_mode_object *obj;
struct drm_mode_get_property *out_resp = data; struct drm_mode_get_property *out_resp = data;
struct drm_property *property; struct drm_property *property;
int enum_count = 0; int enum_count = 0;
...@@ -3458,12 +3433,11 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev, ...@@ -3458,12 +3433,11 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
return -EINVAL; return -EINVAL;
drm_modeset_lock_all(dev); drm_modeset_lock_all(dev);
obj = drm_mode_object_find(dev, out_resp->prop_id, DRM_MODE_OBJECT_PROPERTY); property = drm_property_find(dev, out_resp->prop_id);
if (!obj) { if (!property) {
ret = -ENOENT; ret = -ENOENT;
goto done; goto done;
} }
property = obj_to_property(obj);
if (property->flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)) { if (property->flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)) {
list_for_each_entry(prop_enum, &property->enum_blob_list, head) list_for_each_entry(prop_enum, &property->enum_blob_list, head)
...@@ -3591,7 +3565,6 @@ static void drm_property_destroy_blob(struct drm_device *dev, ...@@ -3591,7 +3565,6 @@ static void drm_property_destroy_blob(struct drm_device *dev,
int drm_mode_getblob_ioctl(struct drm_device *dev, int drm_mode_getblob_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv) void *data, struct drm_file *file_priv)
{ {
struct drm_mode_object *obj;
struct drm_mode_get_blob *out_resp = data; struct drm_mode_get_blob *out_resp = data;
struct drm_property_blob *blob; struct drm_property_blob *blob;
int ret = 0; int ret = 0;
...@@ -3601,12 +3574,11 @@ int drm_mode_getblob_ioctl(struct drm_device *dev, ...@@ -3601,12 +3574,11 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
return -EINVAL; return -EINVAL;
drm_modeset_lock_all(dev); drm_modeset_lock_all(dev);
obj = drm_mode_object_find(dev, out_resp->blob_id, DRM_MODE_OBJECT_BLOB); blob = drm_property_blob_find(dev, out_resp->blob_id);
if (!obj) { if (!blob) {
ret = -ENOENT; ret = -ENOENT;
goto done; goto done;
} }
blob = obj_to_blob(obj);
if (out_resp->length == blob->length) { if (out_resp->length == blob->length) {
blob_ptr = (void __user *)(unsigned long)out_resp->data; blob_ptr = (void __user *)(unsigned long)out_resp->data;
...@@ -3988,7 +3960,6 @@ int drm_mode_gamma_set_ioctl(struct drm_device *dev, ...@@ -3988,7 +3960,6 @@ int drm_mode_gamma_set_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv) void *data, struct drm_file *file_priv)
{ {
struct drm_mode_crtc_lut *crtc_lut = data; struct drm_mode_crtc_lut *crtc_lut = data;
struct drm_mode_object *obj;
struct drm_crtc *crtc; struct drm_crtc *crtc;
void *r_base, *g_base, *b_base; void *r_base, *g_base, *b_base;
int size; int size;
...@@ -3998,12 +3969,11 @@ int drm_mode_gamma_set_ioctl(struct drm_device *dev, ...@@ -3998,12 +3969,11 @@ int drm_mode_gamma_set_ioctl(struct drm_device *dev,
return -EINVAL; return -EINVAL;
drm_modeset_lock_all(dev); drm_modeset_lock_all(dev);
obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC); crtc = drm_crtc_find(dev, crtc_lut->crtc_id);
if (!obj) { if (!crtc) {
ret = -ENOENT; ret = -ENOENT;
goto out; goto out;
} }
crtc = obj_to_crtc(obj);
if (crtc->funcs->gamma_set == NULL) { if (crtc->funcs->gamma_set == NULL) {
ret = -ENOSYS; ret = -ENOSYS;
...@@ -4062,7 +4032,6 @@ int drm_mode_gamma_get_ioctl(struct drm_device *dev, ...@@ -4062,7 +4032,6 @@ int drm_mode_gamma_get_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv) void *data, struct drm_file *file_priv)
{ {
struct drm_mode_crtc_lut *crtc_lut = data; struct drm_mode_crtc_lut *crtc_lut = data;
struct drm_mode_object *obj;
struct drm_crtc *crtc; struct drm_crtc *crtc;
void *r_base, *g_base, *b_base; void *r_base, *g_base, *b_base;
int size; int size;
...@@ -4072,12 +4041,11 @@ int drm_mode_gamma_get_ioctl(struct drm_device *dev, ...@@ -4072,12 +4041,11 @@ int drm_mode_gamma_get_ioctl(struct drm_device *dev,
return -EINVAL; return -EINVAL;
drm_modeset_lock_all(dev); drm_modeset_lock_all(dev);
obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC); crtc = drm_crtc_find(dev, crtc_lut->crtc_id);
if (!obj) { if (!crtc) {
ret = -ENOENT; ret = -ENOENT;
goto out; goto out;
} }
crtc = obj_to_crtc(obj);
/* memcpy into gamma store */ /* memcpy into gamma store */
if (crtc_lut->gamma_size != crtc->gamma_size) { if (crtc_lut->gamma_size != crtc->gamma_size) {
...@@ -4130,7 +4098,6 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, ...@@ -4130,7 +4098,6 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv) void *data, struct drm_file *file_priv)
{ {
struct drm_mode_crtc_page_flip *page_flip = data; struct drm_mode_crtc_page_flip *page_flip = data;
struct drm_mode_object *obj;
struct drm_crtc *crtc; struct drm_crtc *crtc;
struct drm_framebuffer *fb = NULL, *old_fb = NULL; struct drm_framebuffer *fb = NULL, *old_fb = NULL;
struct drm_pending_vblank_event *e = NULL; struct drm_pending_vblank_event *e = NULL;
...@@ -4144,10 +4111,9 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, ...@@ -4144,10 +4111,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) if ((page_flip->flags & DRM_MODE_PAGE_FLIP_ASYNC) && !dev->mode_config.async_page_flip)
return -EINVAL; return -EINVAL;
obj = drm_mode_object_find(dev, page_flip->crtc_id, DRM_MODE_OBJECT_CRTC); crtc = drm_crtc_find(dev, page_flip->crtc_id);
if (!obj) if (!crtc)
return -ENOENT; return -ENOENT;
crtc = obj_to_crtc(obj);
mutex_lock(&crtc->mutex); mutex_lock(&crtc->mutex);
if (crtc->primary->fb == NULL) { if (crtc->primary->fb == NULL) {
......
...@@ -1061,6 +1061,15 @@ extern int drm_format_vert_chroma_subsampling(uint32_t format); ...@@ -1061,6 +1061,15 @@ extern int drm_format_vert_chroma_subsampling(uint32_t format);
extern const char *drm_get_format_name(uint32_t format); extern const char *drm_get_format_name(uint32_t format);
/* Helpers */ /* 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, static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
uint32_t id) uint32_t id)
{ {
...@@ -1077,6 +1086,30 @@ static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev, ...@@ -1077,6 +1086,30 @@ static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
return mo ? obj_to_encoder(mo) : NULL; 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. */ /* Plane list iterator for legacy (overlay only) planes. */
#define drm_for_each_legacy_plane(plane, planelist) \ #define drm_for_each_legacy_plane(plane, planelist) \
list_for_each_entry(plane, planelist, head) \ list_for_each_entry(plane, planelist, head) \
......
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