Skip to content

Commit b36552b

Browse files
mattropedanvet
authored andcommitted
drm: Refactor setplane to allow internal use (v3)
Refactor DRM setplane code into a new setplane_internal() function that takes DRM objects directly as parameters rather than looking them up by ID. We'll use this in a future patch when we implement legacy cursor ioctls on top of the universal plane interface. v3: - Move integer overflow checking from setplane_internal to setplane ioctl. The upcoming legacy cursor support via universal planes needs to maintain current cursor ioctl semantics and not return error for these extreme values (found via intel-gpu-tools kms_cursor_crc test). v2: - Allow planes to be disabled without a valid crtc again (and add mention of this to setplane's kerneldoc, since it doesn't seem to be mentioned anywhere else). - Reformat some parameter line wrap Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Matt Roper <matthew.d.roper@intel.com> Reviewed-by: Pallavi G<pallavi.g@intel.com> Acked-by: Dave Airlie <airlied@linux.ie> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
1 parent c394c2b commit b36552b

1 file changed

Lines changed: 102 additions & 74 deletions

File tree

‎drivers/gpu/drm/drm_crtc.c‎

Lines changed: 102 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,45 +2122,32 @@ int drm_mode_getplane(struct drm_device *dev, void *data,
21222122
return ret;
21232123
}
21242124

2125-
/**
2126-
* drm_mode_setplane - configure a plane's configuration
2127-
* @dev: DRM device
2128-
* @data: ioctl data*
2129-
* @file_priv: DRM file info
2125+
/*
2126+
* setplane_internal - setplane handler for internal callers
21302127
*
2131-
* Set plane configuration, including placement, fb, scaling, and other factors.
2132-
* Or pass a NULL fb to disable.
2128+
* Note that we assume an extra reference has already been taken on fb. If the
2129+
* update fails, this reference will be dropped before return; if it succeeds,
2130+
* the previous framebuffer (if any) will be unreferenced instead.
21332131
*
2134-
* Returns:
2135-
* Zero on success, errno on failure.
2132+
* src_{x,y,w,h} are provided in 16.16 fixed point format
21362133
*/
2137-
int drm_mode_setplane(struct drm_device *dev, void *data,
2138-
struct drm_file *file_priv)
2134+
static int setplane_internal(struct drm_crtc *crtc,
2135+
struct drm_plane *plane,
2136+
struct drm_framebuffer *fb,
2137+
int32_t crtc_x, int32_t crtc_y,
2138+
uint32_t crtc_w, uint32_t crtc_h,
2139+
/* src_{x,y,w,h} values are 16.16 fixed point */
2140+
uint32_t src_x, uint32_t src_y,
2141+
uint32_t src_w, uint32_t src_h)
21392142
{
2140-
struct drm_mode_set_plane *plane_req = data;
2141-
struct drm_plane *plane;
2142-
struct drm_crtc *crtc;
2143-
struct drm_framebuffer *fb = NULL, *old_fb = NULL;
2143+
struct drm_device *dev = crtc->dev;
2144+
struct drm_framebuffer *old_fb = NULL;
21442145
int ret = 0;
21452146
unsigned int fb_width, fb_height;
21462147
int i;
21472148

2148-
if (!drm_core_check_feature(dev, DRIVER_MODESET))
2149-
return -EINVAL;
2150-
2151-
/*
2152-
* First, find the plane, crtc, and fb objects. If not available,
2153-
* we don't bother to call the driver.
2154-
*/
2155-
plane = drm_plane_find(dev, plane_req->plane_id);
2156-
if (!plane) {
2157-
DRM_DEBUG_KMS("Unknown plane ID %d\n",
2158-
plane_req->plane_id);
2159-
return -ENOENT;
2160-
}
2161-
21622149
/* No fb means shut it down */
2163-
if (!plane_req->fb_id) {
2150+
if (!fb) {
21642151
drm_modeset_lock_all(dev);
21652152
old_fb = plane->fb;
21662153
ret = plane->funcs->disable_plane(plane);
@@ -2174,29 +2161,13 @@ int drm_mode_setplane(struct drm_device *dev, void *data,
21742161
goto out;
21752162
}
21762163

2177-
crtc = drm_crtc_find(dev, plane_req->crtc_id);
2178-
if (!crtc) {
2179-
DRM_DEBUG_KMS("Unknown crtc ID %d\n",
2180-
plane_req->crtc_id);
2181-
ret = -ENOENT;
2182-
goto out;
2183-
}
2184-
21852164
/* Check whether this plane is usable on this CRTC */
21862165
if (!(plane->possible_crtcs & drm_crtc_mask(crtc))) {
21872166
DRM_DEBUG_KMS("Invalid crtc for plane\n");
21882167
ret = -EINVAL;
21892168
goto out;
21902169
}
21912170

2192-
fb = drm_framebuffer_lookup(dev, plane_req->fb_id);
2193-
if (!fb) {
2194-
DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
2195-
plane_req->fb_id);
2196-
ret = -ENOENT;
2197-
goto out;
2198-
}
2199-
22002171
/* Check whether this plane supports the fb pixel format. */
22012172
for (i = 0; i < plane->format_count; i++)
22022173
if (fb->pixel_format == plane->format_types[i])
@@ -2212,43 +2183,25 @@ int drm_mode_setplane(struct drm_device *dev, void *data,
22122183
fb_height = fb->height << 16;
22132184

22142185
/* Make sure source coordinates are inside the fb. */
2215-
if (plane_req->src_w > fb_width ||
2216-
plane_req->src_x > fb_width - plane_req->src_w ||
2217-
plane_req->src_h > fb_height ||
2218-
plane_req->src_y > fb_height - plane_req->src_h) {
2186+
if (src_w > fb_width ||
2187+
src_x > fb_width - src_w ||
2188+
src_h > fb_height ||
2189+
src_y > fb_height - src_h) {
22192190
DRM_DEBUG_KMS("Invalid source coordinates "
22202191
"%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
2221-
plane_req->src_w >> 16,
2222-
((plane_req->src_w & 0xffff) * 15625) >> 10,
2223-
plane_req->src_h >> 16,
2224-
((plane_req->src_h & 0xffff) * 15625) >> 10,
2225-
plane_req->src_x >> 16,
2226-
((plane_req->src_x & 0xffff) * 15625) >> 10,
2227-
plane_req->src_y >> 16,
2228-
((plane_req->src_y & 0xffff) * 15625) >> 10);
2192+
src_w >> 16, ((src_w & 0xffff) * 15625) >> 10,
2193+
src_h >> 16, ((src_h & 0xffff) * 15625) >> 10,
2194+
src_x >> 16, ((src_x & 0xffff) * 15625) >> 10,
2195+
src_y >> 16, ((src_y & 0xffff) * 15625) >> 10);
22292196
ret = -ENOSPC;
22302197
goto out;
22312198
}
22322199

2233-
/* Give drivers some help against integer overflows */
2234-
if (plane_req->crtc_w > INT_MAX ||
2235-
plane_req->crtc_x > INT_MAX - (int32_t) plane_req->crtc_w ||
2236-
plane_req->crtc_h > INT_MAX ||
2237-
plane_req->crtc_y > INT_MAX - (int32_t) plane_req->crtc_h) {
2238-
DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n",
2239-
plane_req->crtc_w, plane_req->crtc_h,
2240-
plane_req->crtc_x, plane_req->crtc_y);
2241-
ret = -ERANGE;
2242-
goto out;
2243-
}
2244-
22452200
drm_modeset_lock_all(dev);
22462201
old_fb = plane->fb;
22472202
ret = plane->funcs->update_plane(plane, crtc, fb,
2248-
plane_req->crtc_x, plane_req->crtc_y,
2249-
plane_req->crtc_w, plane_req->crtc_h,
2250-
plane_req->src_x, plane_req->src_y,
2251-
plane_req->src_w, plane_req->src_h);
2203+
crtc_x, crtc_y, crtc_w, crtc_h,
2204+
src_x, src_y, src_w, src_h);
22522205
if (!ret) {
22532206
plane->crtc = crtc;
22542207
plane->fb = fb;
@@ -2265,6 +2218,81 @@ int drm_mode_setplane(struct drm_device *dev, void *data,
22652218
drm_framebuffer_unreference(old_fb);
22662219

22672220
return ret;
2221+
2222+
}
2223+
2224+
/**
2225+
* drm_mode_setplane - configure a plane's configuration
2226+
* @dev: DRM device
2227+
* @data: ioctl data*
2228+
* @file_priv: DRM file info
2229+
*
2230+
* Set plane configuration, including placement, fb, scaling, and other factors.
2231+
* Or pass a NULL fb to disable (planes may be disabled without providing a
2232+
* valid crtc).
2233+
*
2234+
* Returns:
2235+
* Zero on success, errno on failure.
2236+
*/
2237+
int drm_mode_setplane(struct drm_device *dev, void *data,
2238+
struct drm_file *file_priv)
2239+
{
2240+
struct drm_mode_set_plane *plane_req = data;
2241+
struct drm_mode_object *obj;
2242+
struct drm_plane *plane;
2243+
struct drm_crtc *crtc = NULL;
2244+
struct drm_framebuffer *fb = NULL;
2245+
2246+
if (!drm_core_check_feature(dev, DRIVER_MODESET))
2247+
return -EINVAL;
2248+
2249+
/* Give drivers some help against integer overflows */
2250+
if (plane_req->crtc_w > INT_MAX ||
2251+
plane_req->crtc_x > INT_MAX - (int32_t) plane_req->crtc_w ||
2252+
plane_req->crtc_h > INT_MAX ||
2253+
plane_req->crtc_y > INT_MAX - (int32_t) plane_req->crtc_h) {
2254+
DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n",
2255+
plane_req->crtc_w, plane_req->crtc_h,
2256+
plane_req->crtc_x, plane_req->crtc_y);
2257+
return -ERANGE;
2258+
}
2259+
2260+
/*
2261+
* First, find the plane, crtc, and fb objects. If not available,
2262+
* we don't bother to call the driver.
2263+
*/
2264+
obj = drm_mode_object_find(dev, plane_req->plane_id,
2265+
DRM_MODE_OBJECT_PLANE);
2266+
if (!obj) {
2267+
DRM_DEBUG_KMS("Unknown plane ID %d\n",
2268+
plane_req->plane_id);
2269+
return -ENOENT;
2270+
}
2271+
plane = obj_to_plane(obj);
2272+
2273+
if (plane_req->fb_id) {
2274+
fb = drm_framebuffer_lookup(dev, plane_req->fb_id);
2275+
if (!fb) {
2276+
DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
2277+
plane_req->fb_id);
2278+
return -ENOENT;
2279+
}
2280+
2281+
obj = drm_mode_object_find(dev, plane_req->crtc_id,
2282+
DRM_MODE_OBJECT_CRTC);
2283+
if (!obj) {
2284+
DRM_DEBUG_KMS("Unknown crtc ID %d\n",
2285+
plane_req->crtc_id);
2286+
return -ENOENT;
2287+
}
2288+
crtc = obj_to_crtc(obj);
2289+
}
2290+
2291+
return setplane_internal(crtc, plane, fb,
2292+
plane_req->crtc_x, plane_req->crtc_y,
2293+
plane_req->crtc_w, plane_req->crtc_h,
2294+
plane_req->src_x, plane_req->src_y,
2295+
plane_req->src_w, plane_req->src_h);
22682296
}
22692297

22702298
/**

0 commit comments

Comments
 (0)