Skip to content

Commit 24c478e

Browse files
committed
drm/fourcc: Pass the format_info pointer to drm_format_plane_cpp
So far, the drm_format_plane_cpp function was operating on the format's fourcc and was doing a lookup to retrieve the drm_format_info structure and return the cpp. However, this is inefficient since in most cases, we will have the drm_format_info pointer already available so we shouldn't have to perform a new lookup. Some drm_fourcc functions also already operate on the drm_format_info pointer for that reason, so the API is quite inconsistent there. Let's follow the latter pattern and remove the extra lookup while being a bit more consistent. In order to be extra consistent, also rename that function to drm_format_info_plane_cpp and to a static function in the header to match the current policy. Reviewed-by: Emil Velikov <emil.velikov@collabora.com> Reviewed-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com> Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com> Link: https://patchwork.freedesktop.org/patch/msgid/32aa13e53dbc98a90207fd290aa8e79f785fb11e.1558002671.git-series.maxime.ripard@bootlin.com
1 parent f3e9632 commit 24c478e

18 files changed

Lines changed: 42 additions & 38 deletions

File tree

‎drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ static int amdgpufb_create_pinned_object(struct amdgpu_fbdev *rfbdev,
121121
struct drm_mode_fb_cmd2 *mode_cmd,
122122
struct drm_gem_object **gobj_p)
123123
{
124+
const struct drm_format_info *info = drm_get_format_info(dev,
125+
mode_cmd);
124126
struct amdgpu_device *adev = rfbdev->adev;
125127
struct drm_gem_object *gobj = NULL;
126128
struct amdgpu_bo *abo = NULL;
@@ -131,7 +133,7 @@ static int amdgpufb_create_pinned_object(struct amdgpu_fbdev *rfbdev,
131133
int height = mode_cmd->height;
132134
u32 cpp;
133135

134-
cpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0);
136+
cpp = drm_format_info_plane_cpp(info, 0);
135137

136138
/* need to align pitch with crtc limits */
137139
mode_cmd->pitches[0] = amdgpu_align_pitch(adev, mode_cmd->width, cpp,

‎drivers/gpu/drm/arm/malidp_hw.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@ static void malidp500_modeset(struct malidp_hw_device *hwdev, struct videomode *
382382

383383
int malidp_format_get_bpp(u32 fmt)
384384
{
385-
int bpp = drm_format_plane_cpp(fmt, 0) * 8;
385+
const struct drm_format_info *info = drm_format_info(fmt);
386+
int bpp = drm_format_info_plane_cpp(info, 0) * 8;
386387

387388
if (bpp == 0) {
388389
switch (fmt) {

‎drivers/gpu/drm/arm/malidp_planes.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ bool malidp_format_mod_supported(struct drm_device *drm,
227227

228228
if (modifier & AFBC_SPLIT) {
229229
if (!info->is_yuv) {
230-
if (drm_format_plane_cpp(format, 0) <= 2) {
230+
if (drm_format_info_plane_cpp(info, 0) <= 2) {
231231
DRM_DEBUG_KMS("RGB formats <= 16bpp are not supported with SPLIT\n");
232232
return false;
233233
}

‎drivers/gpu/drm/drm_client.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ static void drm_client_buffer_delete(struct drm_client_buffer *buffer)
243243
static struct drm_client_buffer *
244244
drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format)
245245
{
246+
const struct drm_format_info *info = drm_format_info(format);
246247
struct drm_mode_create_dumb dumb_args = { };
247248
struct drm_device *dev = client->dev;
248249
struct drm_client_buffer *buffer;
@@ -258,7 +259,7 @@ drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u
258259

259260
dumb_args.width = width;
260261
dumb_args.height = height;
261-
dumb_args.bpp = drm_format_plane_cpp(format, 0) * 8;
262+
dumb_args.bpp = drm_format_info_plane_cpp(info, 0) * 8;
262263
ret = drm_mode_create_dumb(dev, &dumb_args, client->file);
263264
if (ret)
264265
goto err_delete;

‎drivers/gpu/drm/drm_fb_helper.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ static void drm_fb_helper_dirty_blit_real(struct drm_fb_helper *fb_helper,
813813
struct drm_clip_rect *clip)
814814
{
815815
struct drm_framebuffer *fb = fb_helper->fb;
816-
unsigned int cpp = drm_format_plane_cpp(fb->format->format, 0);
816+
unsigned int cpp = drm_format_info_plane_cpp(fb->format, 0);
817817
size_t offset = clip->y1 * fb->pitches[0] + clip->x1 * cpp;
818818
void *src = fb_helper->fbdev->screen_buffer + offset;
819819
void *dst = fb_helper->buffer->vaddr + offset;

‎drivers/gpu/drm/drm_format_helper.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static unsigned int clip_offset(struct drm_rect *clip,
3636
void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
3737
struct drm_rect *clip)
3838
{
39-
unsigned int cpp = drm_format_plane_cpp(fb->format->format, 0);
39+
unsigned int cpp = drm_format_info_plane_cpp(fb->format, 0);
4040
size_t len = (clip->x2 - clip->x1) * cpp;
4141
unsigned int y, lines = clip->y2 - clip->y1;
4242

@@ -63,7 +63,7 @@ void drm_fb_memcpy_dstclip(void __iomem *dst, void *vaddr,
6363
struct drm_framebuffer *fb,
6464
struct drm_rect *clip)
6565
{
66-
unsigned int cpp = drm_format_plane_cpp(fb->format->format, 0);
66+
unsigned int cpp = drm_format_info_plane_cpp(fb->format, 0);
6767
unsigned int offset = clip_offset(clip, fb->pitches[0], cpp);
6868
size_t len = (clip->x2 - clip->x1) * cpp;
6969
unsigned int y, lines = clip->y2 - clip->y1;

‎drivers/gpu/drm/drm_fourcc.c‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -332,26 +332,6 @@ drm_get_format_info(struct drm_device *dev,
332332
}
333333
EXPORT_SYMBOL(drm_get_format_info);
334334

335-
/**
336-
* drm_format_plane_cpp - determine the bytes per pixel value
337-
* @format: pixel format (DRM_FORMAT_*)
338-
* @plane: plane index
339-
*
340-
* Returns:
341-
* The bytes per pixel value for the specified plane.
342-
*/
343-
int drm_format_plane_cpp(uint32_t format, int plane)
344-
{
345-
const struct drm_format_info *info;
346-
347-
info = drm_format_info(format);
348-
if (!info || plane >= info->num_planes)
349-
return 0;
350-
351-
return info->cpp[plane];
352-
}
353-
EXPORT_SYMBOL(drm_format_plane_cpp);
354-
355335
/**
356336
* drm_format_plane_width - width of the plane given the first plane
357337
* @width: width of the first plane

‎drivers/gpu/drm/i915/intel_sprite.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ skl_plane_max_stride(struct intel_plane *plane,
325325
u32 pixel_format, u64 modifier,
326326
unsigned int rotation)
327327
{
328-
int cpp = drm_format_plane_cpp(pixel_format, 0);
328+
const struct drm_format_info *info = drm_format_info(pixel_format);
329+
int cpp = drm_format_info_plane_cpp(info, 0);
329330

330331
/*
331332
* "The stride in bytes must not exceed the

‎drivers/gpu/drm/mediatek/mtk_drm_fb.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct drm_framebuffer *mtk_drm_mode_fb_create(struct drm_device *dev,
104104
if (!gem)
105105
return ERR_PTR(-ENOENT);
106106

107-
bpp = drm_format_plane_cpp(cmd->pixel_format, 0);
107+
bpp = drm_format_info_plane_cpp(info, 0);
108108
size = (height - 1) * cmd->pitches[0] + width * bpp;
109109
size += cmd->offsets[0];
110110

‎drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ static void get_roi(struct drm_crtc *crtc, uint32_t *roi_w, uint32_t *roi_h)
782782

783783
static void mdp5_crtc_restore_cursor(struct drm_crtc *crtc)
784784
{
785+
const struct drm_format_info *info = drm_format_info(DRM_FORMAT_ARGB8888);
785786
struct mdp5_crtc_state *mdp5_cstate = to_mdp5_crtc_state(crtc->state);
786787
struct mdp5_crtc *mdp5_crtc = to_mdp5_crtc(crtc);
787788
struct mdp5_kms *mdp5_kms = get_kms(crtc);
@@ -800,7 +801,7 @@ static void mdp5_crtc_restore_cursor(struct drm_crtc *crtc)
800801
width = mdp5_crtc->cursor.width;
801802
height = mdp5_crtc->cursor.height;
802803

803-
stride = width * drm_format_plane_cpp(DRM_FORMAT_ARGB8888, 0);
804+
stride = width * drm_format_info_plane_cpp(info, 0);
804805

805806
get_roi(crtc, &roi_w, &roi_h);
806807

0 commit comments

Comments
 (0)