Skip to content

Commit a2b34e2

Browse files
robclarkairlied
authored andcommitted
drm: helpers to find mode objects
Add a few more useful helpers to find mode objects. Signed-off-by: Rob Clark <robdclark@gmail.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
1 parent d5ab2b4 commit a2b34e2

File tree

2 files changed

+61
-62
lines changed

2 files changed

+61
-62
lines changed

drivers/gpu/drm/drm_crtc.c

Lines changed: 28 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,21 +1692,18 @@ int drm_mode_getcrtc(struct drm_device *dev,
16921692
{
16931693
struct drm_mode_crtc *crtc_resp = data;
16941694
struct drm_crtc *crtc;
1695-
struct drm_mode_object *obj;
16961695
int ret = 0;
16971696

16981697
if (!drm_core_check_feature(dev, DRIVER_MODESET))
16991698
return -EINVAL;
17001699

17011700
drm_modeset_lock_all(dev);
17021701

1703-
obj = drm_mode_object_find(dev, crtc_resp->crtc_id,
1704-
DRM_MODE_OBJECT_CRTC);
1705-
if (!obj) {
1702+
crtc = drm_crtc_find(dev, crtc_resp->crtc_id);
1703+
if (!crtc) {
17061704
ret = -ENOENT;
17071705
goto out;
17081706
}
1709-
crtc = obj_to_crtc(obj);
17101707

17111708
crtc_resp->x = crtc->x;
17121709
crtc_resp->y = crtc->y;
@@ -1760,7 +1757,6 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
17601757
struct drm_file *file_priv)
17611758
{
17621759
struct drm_mode_get_connector *out_resp = data;
1763-
struct drm_mode_object *obj;
17641760
struct drm_connector *connector;
17651761
struct drm_display_mode *mode;
17661762
int mode_count = 0;
@@ -1784,13 +1780,11 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
17841780

17851781
mutex_lock(&dev->mode_config.mutex);
17861782

1787-
obj = drm_mode_object_find(dev, out_resp->connector_id,
1788-
DRM_MODE_OBJECT_CONNECTOR);
1789-
if (!obj) {
1783+
connector = drm_connector_find(dev, out_resp->connector_id);
1784+
if (!connector) {
17901785
ret = -ENOENT;
17911786
goto out;
17921787
}
1793-
connector = obj_to_connector(obj);
17941788

17951789
props_count = connector->properties.count;
17961790

@@ -1905,21 +1899,18 @@ int drm_mode_getencoder(struct drm_device *dev, void *data,
19051899
struct drm_file *file_priv)
19061900
{
19071901
struct drm_mode_get_encoder *enc_resp = data;
1908-
struct drm_mode_object *obj;
19091902
struct drm_encoder *encoder;
19101903
int ret = 0;
19111904

19121905
if (!drm_core_check_feature(dev, DRIVER_MODESET))
19131906
return -EINVAL;
19141907

19151908
drm_modeset_lock_all(dev);
1916-
obj = drm_mode_object_find(dev, enc_resp->encoder_id,
1917-
DRM_MODE_OBJECT_ENCODER);
1918-
if (!obj) {
1909+
encoder = drm_encoder_find(dev, enc_resp->encoder_id);
1910+
if (!encoder) {
19191911
ret = -ENOENT;
19201912
goto out;
19211913
}
1922-
encoder = obj_to_encoder(obj);
19231914

19241915
if (encoder->crtc)
19251916
enc_resp->crtc_id = encoder->crtc->base.id;
@@ -2017,7 +2008,6 @@ int drm_mode_getplane(struct drm_device *dev, void *data,
20172008
struct drm_file *file_priv)
20182009
{
20192010
struct drm_mode_get_plane *plane_resp = data;
2020-
struct drm_mode_object *obj;
20212011
struct drm_plane *plane;
20222012
uint32_t __user *format_ptr;
20232013
int ret = 0;
@@ -2026,13 +2016,11 @@ int drm_mode_getplane(struct drm_device *dev, void *data,
20262016
return -EINVAL;
20272017

20282018
drm_modeset_lock_all(dev);
2029-
obj = drm_mode_object_find(dev, plane_resp->plane_id,
2030-
DRM_MODE_OBJECT_PLANE);
2031-
if (!obj) {
2019+
plane = drm_plane_find(dev, plane_resp->plane_id);
2020+
if (!plane) {
20322021
ret = -ENOENT;
20332022
goto out;
20342023
}
2035-
plane = obj_to_plane(obj);
20362024

20372025
if (plane->crtc)
20382026
plane_resp->crtc_id = plane->crtc->base.id;
@@ -2085,7 +2073,6 @@ int drm_mode_setplane(struct drm_device *dev, void *data,
20852073
struct drm_file *file_priv)
20862074
{
20872075
struct drm_mode_set_plane *plane_req = data;
2088-
struct drm_mode_object *obj;
20892076
struct drm_plane *plane;
20902077
struct drm_crtc *crtc;
20912078
struct drm_framebuffer *fb = NULL, *old_fb = NULL;
@@ -2100,14 +2087,12 @@ int drm_mode_setplane(struct drm_device *dev, void *data,
21002087
* First, find the plane, crtc, and fb objects. If not available,
21012088
* we don't bother to call the driver.
21022089
*/
2103-
obj = drm_mode_object_find(dev, plane_req->plane_id,
2104-
DRM_MODE_OBJECT_PLANE);
2105-
if (!obj) {
2090+
plane = drm_plane_find(dev, plane_req->plane_id);
2091+
if (!plane) {
21062092
DRM_DEBUG_KMS("Unknown plane ID %d\n",
21072093
plane_req->plane_id);
21082094
return -ENOENT;
21092095
}
2110-
plane = obj_to_plane(obj);
21112096

21122097
/* No fb means shut it down */
21132098
if (!plane_req->fb_id) {
@@ -2124,15 +2109,13 @@ int drm_mode_setplane(struct drm_device *dev, void *data,
21242109
goto out;
21252110
}
21262111

2127-
obj = drm_mode_object_find(dev, plane_req->crtc_id,
2128-
DRM_MODE_OBJECT_CRTC);
2129-
if (!obj) {
2112+
crtc = drm_crtc_find(dev, plane_req->crtc_id);
2113+
if (!crtc) {
21302114
DRM_DEBUG_KMS("Unknown crtc ID %d\n",
21312115
plane_req->crtc_id);
21322116
ret = -ENOENT;
21332117
goto out;
21342118
}
2135-
crtc = obj_to_crtc(obj);
21362119

21372120
fb = drm_framebuffer_lookup(dev, plane_req->fb_id);
21382121
if (!fb) {
@@ -2319,7 +2302,6 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
23192302
{
23202303
struct drm_mode_config *config = &dev->mode_config;
23212304
struct drm_mode_crtc *crtc_req = data;
2322-
struct drm_mode_object *obj;
23232305
struct drm_crtc *crtc;
23242306
struct drm_connector **connector_set = NULL, *connector;
23252307
struct drm_framebuffer *fb = NULL;
@@ -2337,14 +2319,12 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
23372319
return -ERANGE;
23382320

23392321
drm_modeset_lock_all(dev);
2340-
obj = drm_mode_object_find(dev, crtc_req->crtc_id,
2341-
DRM_MODE_OBJECT_CRTC);
2342-
if (!obj) {
2322+
crtc = drm_crtc_find(dev, crtc_req->crtc_id);
2323+
if (!crtc) {
23432324
DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id);
23442325
ret = -ENOENT;
23452326
goto out;
23462327
}
2347-
crtc = obj_to_crtc(obj);
23482328
DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
23492329

23502330
if (crtc_req->mode_valid) {
@@ -2427,15 +2407,13 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
24272407
goto out;
24282408
}
24292409

2430-
obj = drm_mode_object_find(dev, out_id,
2431-
DRM_MODE_OBJECT_CONNECTOR);
2432-
if (!obj) {
2410+
connector = drm_connector_find(dev, out_id);
2411+
if (!connector) {
24332412
DRM_DEBUG_KMS("Connector id %d unknown\n",
24342413
out_id);
24352414
ret = -ENOENT;
24362415
goto out;
24372416
}
2438-
connector = obj_to_connector(obj);
24392417
DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
24402418
connector->base.id,
24412419
connector->name);
@@ -2467,7 +2445,6 @@ static int drm_mode_cursor_common(struct drm_device *dev,
24672445
struct drm_mode_cursor2 *req,
24682446
struct drm_file *file_priv)
24692447
{
2470-
struct drm_mode_object *obj;
24712448
struct drm_crtc *crtc;
24722449
int ret = 0;
24732450

@@ -2477,12 +2454,11 @@ static int drm_mode_cursor_common(struct drm_device *dev,
24772454
if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags))
24782455
return -EINVAL;
24792456

2480-
obj = drm_mode_object_find(dev, req->crtc_id, DRM_MODE_OBJECT_CRTC);
2481-
if (!obj) {
2457+
crtc = drm_crtc_find(dev, req->crtc_id);
2458+
if (!crtc) {
24822459
DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id);
24832460
return -ENOENT;
24842461
}
2485-
crtc = obj_to_crtc(obj);
24862462

24872463
mutex_lock(&crtc->mutex);
24882464
if (req->flags & DRM_MODE_CURSOR_BO) {
@@ -3439,7 +3415,6 @@ EXPORT_SYMBOL(drm_object_property_get_value);
34393415
int drm_mode_getproperty_ioctl(struct drm_device *dev,
34403416
void *data, struct drm_file *file_priv)
34413417
{
3442-
struct drm_mode_object *obj;
34433418
struct drm_mode_get_property *out_resp = data;
34443419
struct drm_property *property;
34453420
int enum_count = 0;
@@ -3458,12 +3433,11 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
34583433
return -EINVAL;
34593434

34603435
drm_modeset_lock_all(dev);
3461-
obj = drm_mode_object_find(dev, out_resp->prop_id, DRM_MODE_OBJECT_PROPERTY);
3462-
if (!obj) {
3436+
property = drm_property_find(dev, out_resp->prop_id);
3437+
if (!property) {
34633438
ret = -ENOENT;
34643439
goto done;
34653440
}
3466-
property = obj_to_property(obj);
34673441

34683442
if (property->flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)) {
34693443
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,
35913565
int drm_mode_getblob_ioctl(struct drm_device *dev,
35923566
void *data, struct drm_file *file_priv)
35933567
{
3594-
struct drm_mode_object *obj;
35953568
struct drm_mode_get_blob *out_resp = data;
35963569
struct drm_property_blob *blob;
35973570
int ret = 0;
@@ -3601,12 +3574,11 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
36013574
return -EINVAL;
36023575

36033576
drm_modeset_lock_all(dev);
3604-
obj = drm_mode_object_find(dev, out_resp->blob_id, DRM_MODE_OBJECT_BLOB);
3605-
if (!obj) {
3577+
blob = drm_property_blob_find(dev, out_resp->blob_id);
3578+
if (!blob) {
36063579
ret = -ENOENT;
36073580
goto done;
36083581
}
3609-
blob = obj_to_blob(obj);
36103582

36113583
if (out_resp->length == blob->length) {
36123584
blob_ptr = (void __user *)(unsigned long)out_resp->data;
@@ -3988,7 +3960,6 @@ int drm_mode_gamma_set_ioctl(struct drm_device *dev,
39883960
void *data, struct drm_file *file_priv)
39893961
{
39903962
struct drm_mode_crtc_lut *crtc_lut = data;
3991-
struct drm_mode_object *obj;
39923963
struct drm_crtc *crtc;
39933964
void *r_base, *g_base, *b_base;
39943965
int size;
@@ -3998,12 +3969,11 @@ int drm_mode_gamma_set_ioctl(struct drm_device *dev,
39983969
return -EINVAL;
39993970

40003971
drm_modeset_lock_all(dev);
4001-
obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC);
4002-
if (!obj) {
3972+
crtc = drm_crtc_find(dev, crtc_lut->crtc_id);
3973+
if (!crtc) {
40033974
ret = -ENOENT;
40043975
goto out;
40053976
}
4006-
crtc = obj_to_crtc(obj);
40073977

40083978
if (crtc->funcs->gamma_set == NULL) {
40093979
ret = -ENOSYS;
@@ -4062,7 +4032,6 @@ int drm_mode_gamma_get_ioctl(struct drm_device *dev,
40624032
void *data, struct drm_file *file_priv)
40634033
{
40644034
struct drm_mode_crtc_lut *crtc_lut = data;
4065-
struct drm_mode_object *obj;
40664035
struct drm_crtc *crtc;
40674036
void *r_base, *g_base, *b_base;
40684037
int size;
@@ -4072,12 +4041,11 @@ int drm_mode_gamma_get_ioctl(struct drm_device *dev,
40724041
return -EINVAL;
40734042

40744043
drm_modeset_lock_all(dev);
4075-
obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC);
4076-
if (!obj) {
4044+
crtc = drm_crtc_find(dev, crtc_lut->crtc_id);
4045+
if (!crtc) {
40774046
ret = -ENOENT;
40784047
goto out;
40794048
}
4080-
crtc = obj_to_crtc(obj);
40814049

40824050
/* memcpy into gamma store */
40834051
if (crtc_lut->gamma_size != crtc->gamma_size) {
@@ -4130,7 +4098,6 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
41304098
void *data, struct drm_file *file_priv)
41314099
{
41324100
struct drm_mode_crtc_page_flip *page_flip = data;
4133-
struct drm_mode_object *obj;
41344101
struct drm_crtc *crtc;
41354102
struct drm_framebuffer *fb = NULL, *old_fb = NULL;
41364103
struct drm_pending_vblank_event *e = NULL;
@@ -4144,10 +4111,9 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
41444111
if ((page_flip->flags & DRM_MODE_PAGE_FLIP_ASYNC) && !dev->mode_config.async_page_flip)
41454112
return -EINVAL;
41464113

4147-
obj = drm_mode_object_find(dev, page_flip->crtc_id, DRM_MODE_OBJECT_CRTC);
4148-
if (!obj)
4114+
crtc = drm_crtc_find(dev, page_flip->crtc_id);
4115+
if (!crtc)
41494116
return -ENOENT;
4150-
crtc = obj_to_crtc(obj);
41514117

41524118
mutex_lock(&crtc->mutex);
41534119
if (crtc->primary->fb == NULL) {

include/drm/drm_crtc.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,15 @@ extern int drm_format_vert_chroma_subsampling(uint32_t format);
10611061
extern const char *drm_get_format_name(uint32_t format);
10621062

10631063
/* Helpers */
1064+
1065+
static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
1066+
uint32_t id)
1067+
{
1068+
struct drm_mode_object *mo;
1069+
mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
1070+
return mo ? obj_to_plane(mo) : NULL;
1071+
}
1072+
10641073
static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
10651074
uint32_t id)
10661075
{
@@ -1077,6 +1086,30 @@ static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
10771086
return mo ? obj_to_encoder(mo) : NULL;
10781087
}
10791088

1089+
static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
1090+
uint32_t id)
1091+
{
1092+
struct drm_mode_object *mo;
1093+
mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
1094+
return mo ? obj_to_connector(mo) : NULL;
1095+
}
1096+
1097+
static inline struct drm_property *drm_property_find(struct drm_device *dev,
1098+
uint32_t id)
1099+
{
1100+
struct drm_mode_object *mo;
1101+
mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
1102+
return mo ? obj_to_property(mo) : NULL;
1103+
}
1104+
1105+
static inline struct drm_property_blob *
1106+
drm_property_blob_find(struct drm_device *dev, uint32_t id)
1107+
{
1108+
struct drm_mode_object *mo;
1109+
mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_BLOB);
1110+
return mo ? obj_to_blob(mo) : NULL;
1111+
}
1112+
10801113
/* Plane list iterator for legacy (overlay only) planes. */
10811114
#define drm_for_each_legacy_plane(plane, planelist) \
10821115
list_for_each_entry(plane, planelist, head) \

0 commit comments

Comments
 (0)