AFBC support for Rockchip
Subsystems (6)
v4 cover AFBC support for Rockchip
This series adds AFBC support for Rockchip. It is inspired by:
This is the fourth iteration of the afbc series. This time a lot of rework has been done, the main goal of which is to move all afbc-related checks to helpers, so that core does not deal with it.
Struct drm_framebuffer gains a new "modifier_info" pointer (overlaid in an union). That member can be used to store driver-specific data, which, for afbc, will be a struct drm_afbc. Because of that, in drivers that wish to use this feature, the struct drm_framebuffer must be allocated directly in the driver code rather than inside helpers, so the first portion of the patchset does the necessary refactoring.
Then, there are 3 users of afbc: komeda, malidp and, finally, rockchip, the latter being the ultimate purpose of this work and the 3 subsequent portions of the patchset move komeda and malidp to generic helpers and add afbc support to rockchip.
The idea is to make all afbc users follow a similar pattern. In fb_create() they allocate struct drm_framebuffer with struct drm_afbc in one chunk of memory (to ease freeing later), do their specific checks which can be done before object lookups, do object lookups and a special version of a size check, which understands struct drm_afbc, followed by any other driver-specific checks and initializing the gem object. The helpers for the common parts are factored out so that drivers can use them.
The komeda driver has been the farthest away from such a pattern, so it required most changes. However, due to the fact that I don't have any komeda hardware I did the changes to komeda in an incremental fashion with a series of (usually) very small, easy to understand steps. malidp was pretty straightforward, and rockchip's afbc checks follow the pattern.
I kindly ask for reviewing the series. I need to mention that my ultimate goal is merging afbc for rockchip and I don't have other hardware, so some help from malidp and komeda developers/maintainers would be appreciated.
Rebased onto drm-misc-next.
v3..v4:
- addressed (some) comments from Daniel Stone, Ezequiel Garcia, Daniel Vetter and James Qian Wang - thank you for input
- refactored helpers to ease accommodating drivers with afbc needs
- moved afbc checks to helpers
- converted komeda, malidp and (the newly added) rockchip to use the afbc helpers
- eliminated a separate, dedicated source code file
v2..v3:
- addressed (some) comments from Daniel Stone, Liviu Dudau, Daniel Vetter and Brian Starkey - thank you all
In this iteration some rework has been done. The checking logic is now moved to framebuffer_check() so it is common to all drivers. But the common part is not good for komeda, so this series is not good for merging yet. I kindly ask for feedback whether the changes are in the right direction. I also kindly ask for input on how to accommodate komeda.
The CONFIG_DRM_AFBC option has been eliminated in favour of adding drm_afbc.c to drm_kms_helper.
v1..v2:
- addressed comments from Daniel Stone, Ayan Halder, Mihail Atanassov
- coding style fixes
Andrzej Pietrasiewicz (36):
drm/framebuffer: Add optional modifier info
drm/core: Add afbc helper functions
drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on
their own
drm/gem-fb-helper: Add special version of drm_gem_fb_size_check drm/gem-fb-helper: Add generic afbc size checks drm/gem-fb-helper: Add method to allocate struct drm_framebuffer drm/komeda: Use afbc helper
drm/komeda: Move checking src coordinates to komeda_fb_create drm/komeda: Use the already available local variable drm/komeda: Retrieve drm_format_info once
drm/komeda: Explicitly require 1 plane for AFBC drm/komeda: Move pitches comparison to komeda_fb_create drm/komeda: Provide and use komeda_fb_get_pixel_addr variant not
requiring a fb
drm/komeda: Factor out object lookups for non-afbc case drm/komeda: Make komeda_fb_none_size_check independent from
framebuffer
drm/komeda: Factor out object lookups for afbc case drm/komeda: Free komeda_fb_afbc_size_check from framebuffer dependency drm/komeda: Simplify error handling
drm/komeda: Move object lookup before size checks drm/komeda: Move object assignments to framebuffer to after size
checks
drm/komeda: Make the size checks independent from framebuffer
structure
drm/komeda: Move helper invocation to after size checks drm/komeda: Use helper for common tasks
drm/komeda: Use return value of drm_gem_fb_lookup drm/komeda: Use special helper for non-afbc size checks drm/komeda: Factor in the invocation of special helper drm/komeda: Use special helper for afbc case size check drm/komeda: Factor in the invocation of special helper, afbc case drm/komeda: Move special helper invocation outside if-else drm/komeda: Move to helper checking afbc buffer size drm/arm/malidp: Make verify funcitons invocations independent drm/arm/malidp: Integrate verify functions
drm/arm/malidp: Factor in afbc framebuffer verification drm/arm/malidp: Use generic helpers for afbc checks drm/rockchip: Use helper for common task
drm/rockchip: Add support for afbc
.../arm/display/komeda/d71/d71_component.c | 7 +- .../arm/display/komeda/komeda_framebuffer.c | 285 ++++++++--------- .../arm/display/komeda/komeda_framebuffer.h | 15 +- .../display/komeda/komeda_pipeline_state.c | 11 +- drivers/gpu/drm/arm/malidp_drv.c | 155 ++++----- drivers/gpu/drm/drm_fourcc.c | 63 +++- drivers/gpu/drm/drm_framebuffer.c | 3 + drivers/gpu/drm/drm_gem_framebuffer_helper.c | 301 +++++++++++++++--- drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 109 ++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 141 +++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop.h | 12 + drivers/gpu/drm/rockchip/rockchip_vop_reg.c | 84 ++++- include/drm/drm_fourcc.h | 4 + include/drm/drm_framebuffer.h | 16 + include/drm/drm_gem_framebuffer_helper.h | 50 +++ 15 files changed, 933 insertions(+), 323 deletions(-)
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 1/36 drm/framebuffer: Add optional modifier info
modifier_info is a pointer to an optional modifier-related information. Managing the memory needed for that information is the responsibility of drivers.
--- include/drm/drm_framebuffer.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
include/drm/drm_framebuffer.h +16 -0
@@ -29,6 +29,7 @@#include <drm/drm_mode_object.h> +struct drm_afbc ;struct drm_clip_rect ;struct drm_device ;struct drm_file ;
@@ -139,6 +140,21 @@ struct drm_framebuffer {* @format: framebuffer format information */ const struct drm_format_info *format; + +union { +/** +* @modifier_info: pointer to an optional modifier-related +* information. Managing the memory holding that information +* is driver's responsibility. +*/ +void *modifier_info; + +/** +* @afbc_info: afbc-specific pointer +*/ +struct drm_afbc *afbc_info; + }; +/** * @funcs: framebuffer vfunc table */
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv4,01/36] drm/framebuffer: Add optional modifier info
Hi Andrzej:
Sorry for late due to the outbreak of coronavirus in china.
James.
Quoted 33 lines · Andrzej Pietrasiewicz
modifier_infois a pointer to an optional modifier-related information. Managing the memory needed for that information is the responsibility of drivers.Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- include/drm/drm_framebuffer.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)include/drm/drm_framebuffer.h +9
-0@@ -29,6 +29,7 @@#include <drm/drm_mode_object.h> +struct drm_afbc ;struct drm_clip_rect ;struct drm_device ;struct drm_file ;@@ -139,6 +140,21 @@ struct drm_framebuffer {* @format: framebuffer format information */ const struct drm_format_info *format; + +union { +/** +* @modifier_info: pointer to an optional modifier-related +* information. Managing the memory holding that information +* is driver's responsibility. +*/ +void *modifier_info;
include/drm/drm_framebuffer.h struct drm_framebuffer { · line 160
Quoted 10 lines
include/drm/drm_framebuffer.h +7
-0+ +/** +* @afbc_info: afbc-specific pointer +*/ +struct drm_afbc *afbc_info; + }; +/** * @funcs: framebuffer vfunc table */
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 2/36 drm/core: Add afbc helper functions
In reply to Andrzej PietrasiewiczAdd checking if a modifier is afbc and getting afbc block size.
--- drivers/gpu/drm/drm_fourcc.c | 53 ++++++++++++++++++++++++++++++++++++ include/drm/drm_fourcc.h | 4 +++ 2 files changed, 57 insertions(+)
drivers/gpu/drm/drm_fourcc.c +53 -0
@@ -29,6 +29,7 @@#include <drm/drm_device.h> #include <drm/drm_fourcc.h> +#include <drm/drm_print.h> static char printable_char (int c) {
@@ -393,3 +394,55 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, drm_format_info_block_height(info, plane)); }EXPORT_SYMBOL (drm_format_info_min_pitch); + +/** +* drm_is_afbc - test if the modifier describes an afbc buffer +* @modifier - modifier to be tested +* +* Returns: true if the modifier describes an afbc buffer +*/ +bool drm_is_afbc (u64 modifier) +{ +/* is it ARM AFBC? */ +if ((modifier &DRM_FORMAT_MOD_ARM_AFBC (0 )) ==0 ) +return false; + +/* Block size must be known */ +if ((modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ) ==0 ) +return false; + +return true; +} +EXPORT_SYMBOL_GPL (drm_is_afbc); + +/** +* drm_afbc_get_superblock_wh - extract afbc block width/height from modifier +* @modifier: the modifier to be looked at +* @w: address of a place to store the block width +* @h: address of a place to store the block height +* +* Returns: true if the modifier describes a supported block size +*/ +bool drm_afbc_get_superblock_wh (u64 modifier,u32 *w,u32 *h) +{ +switch (modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ) { +case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16: + *w =16 ; + *h =16 ; +break ; +case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8: + *w =32 ; + *h =8 ; +break ; +case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4: +/* fall through */ +case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4: +/* fall through */ +default : +DRM_DEBUG_KMS ("Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n" , + modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ); +return false; + } +return true; +} +EXPORT_SYMBOL_GPL (drm_afbc_get_superblock_wh);
include/drm/drm_fourcc.h +4 -0
@@ -320,4 +320,8 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, int plane, unsigned int buffer_width);const char *drm_get_format_name (uint32_t format,struct drm_format_name_buf *buf); +bool drm_is_afbc (u64 modifier); + +bool drm_afbc_get_superblock_wh (u64 modifier,u32 *w,u32 *h); +#endif /* __DRM_FOURCC_H__ */
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv4,02/36] drm/core: Add afbc helper functions
Quoted 30 lines · Andrzej Pietrasiewicz
Add checking if a modifier is afbc and getting afbc block size.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- drivers/gpu/drm/drm_fourcc.c | 53 ++++++++++++++++++++++++++++++++++++ include/drm/drm_fourcc.h | 4 +++ 2 files changed, 57 insertions(+)drivers/gpu/drm/drm_fourcc.c +7
-0@@ -29,6 +29,7 @@#include <drm/drm_device.h> #include <drm/drm_fourcc.h> +#include <drm/drm_print.h> static char printable_char (int c) {@@ -393,3 +394,55 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, drm_format_info_block_height(info, plane)); }EXPORT_SYMBOL (drm_format_info_min_pitch); + +/** +* drm_is_afbc - test if the modifier describes an afbc buffer +* @modifier - modifier to be tested +* +* Returns: true if the modifier describes an afbc buffer
drivers/gpu/drm/drm_fourcc.c uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, · line 412
Quoted 10 lines
drivers/gpu/drm/drm_fourcc.c +10
-0+*/ +bool drm_is_afbc (u64 modifier) +{ +/* is it ARM AFBC? */ +if ((modifier &DRM_FORMAT_MOD_ARM_AFBC (0 )) ==0 ) +return false; + +/* Block size must be known */ +if ((modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ) ==0 ) +return false;
Do we really need this block size check here ?
Since modifier with ARM AFBC modifier but have no BLOCK_SIZE which should be an error, but this check returns such error to NONE-AFBC. And i saw you already have such error check in func get_superblock_wh(), so I think we can del this size check in this func.
James.
Quoted 41 lines
drivers/gpu/drm/drm_fourcc.c +36
-0+ +return true; +} +EXPORT_SYMBOL_GPL (drm_is_afbc); + +/** +* drm_afbc_get_superblock_wh - extract afbc block width/height from modifier +* @modifier: the modifier to be looked at +* @w: address of a place to store the block width +* @h: address of a place to store the block height +* +* Returns: true if the modifier describes a supported block size +*/ +bool drm_afbc_get_superblock_wh (u64 modifier,u32 *w,u32 *h) +{ +switch (modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ) { +case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16: + *w =16 ; + *h =16 ; +break ; +case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8: + *w =32 ; + *h =8 ; +break ; +case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4: +/* fall through */ +case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4: +/* fall through */ +default : +DRM_DEBUG_KMS ("Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n" , + modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ); +return false; + } +return true; +} +EXPORT_SYMBOL_GPL (drm_afbc_get_superblock_wh);include/drm/drm_fourcc.h +0
-0
include/drm/drm_fourcc.h uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, · line 327
Quoted 8 lines
include/drm/drm_fourcc.h +4
-0@@ -320,4 +320,8 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, int plane, unsigned int buffer_width);const char *drm_get_format_name (uint32_t format,struct drm_format_name_buf *buf); +bool drm_is_afbc (u64 modifier); + +bool drm_afbc_get_superblock_wh (u64 modifier,u32 *w,u32 *h); +#endif /* __DRM_FOURCC_H__ */
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 3/36 drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own
In reply to Andrzej PietrasiewiczPrepare tools for drivers which need to allocate a struct drm_framebuffer (or a container of struct drm_framebuffer) explicitly, before calling helpers. In such a case we need new helpers which omit allocating the struct drm_framebuffer and this patch provides them. Consequently, they are used also inside the helpers themselves.
The interested drivers will likely need to be able to perform object lookups and size checks in separate invocations and this patch provides that as well. Helpers themselves are updated, too.
--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 184 ++++++++++++++----- include/drm/drm_gem_framebuffer_helper.h | 17 ++ 2 files changed, 153 insertions(+), 48 deletions(-)
drivers/gpu/drm/drm_gem_framebuffer_helper.c +136 -48
@@ -54,6 +54,44 @@ struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, }EXPORT_SYMBOL_GPL (drm_gem_fb_get_obj); +int drm_gem_fb_init_with_funcs (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj, +unsigned int num_planes, +const struct drm_framebuffer_funcs *funcs) +{ +int ret, i; + +drm_helper_mode_fill_fb_struct (dev, fb, mode_cmd); + +for (i =0 ; i < num_planes; i++) + fb->obj[i] = obj[i]; + + ret =drm_framebuffer_init (dev, fb, funcs); +if (ret) +DRM_DEV_ERROR (dev->dev,"Failed to init framebuffer: %d\n" , + ret); + +return ret; +} +EXPORT_SYMBOL_GPL (drm_gem_fb_init_with_funcs); + +static const struct drm_framebuffer_funcs drm_gem_fb_funcs = { + .destroy = drm_gem_fb_destroy, + .create_handle = drm_gem_fb_create_handle, +}; + +int drm_gem_fb_init (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj,unsigned int num_planes) +{ +return drm_gem_fb_init_with_funcs (fb, dev, mode_cmd, obj, num_planes, + &drm_gem_fb_funcs); +} +EXPORT_SYMBOL_GPL (drm_gem_fb_init); +static struct drm_framebuffer * drm_gem_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd,
@@ -61,21 +99,15 @@ drm_gem_fb_alloc(struct drm_device *dev, const struct drm_framebuffer_funcs *funcs) {struct drm_framebuffer *fb; -int ret, i; +int ret; fb =kzalloc (sizeof (*fb),GFP_KERNEL );if (!fb)return ERR_PTR (-ENOMEM ); -drm_helper_mode_fill_fb_struct (dev, fb, mode_cmd); - -for (i =0 ; i < num_planes; i++) - fb->obj[i] = obj[i]; - - ret =drm_framebuffer_init (dev, fb, funcs); + ret =drm_gem_fb_init_with_funcs (fb, dev, mode_cmd, obj, num_planes, + funcs);if (ret) { -DRM_DEV_ERROR (dev->dev,"Failed to init framebuffer: %d\n" , - ret);kfree (fb);return ERR_PTR (ret); }
@@ -124,79 +156,135 @@ int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file,EXPORT_SYMBOL (drm_gem_fb_create_handle);/** -* drm_gem_fb_create_with_funcs() - Helper function for the -* &drm_mode_config_funcs.fb_create -* callback +* drm_gem_fb_lookup() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations * @dev: DRM device * @file: DRM file that holds the GEM handle(s) backing the framebuffer * @mode_cmd: Metadata from the userspace framebuffer creation request -* @funcs: vtable to be used for the new framebuffer object * -* This function can be used to set &drm_framebuffer_funcs for drivers that need -* custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to -* change &drm_framebuffer_funcs. The function does buffer size validation. +* This function can be used to look up the objects for all planes. +* In case an error is returned all the objects are put by the +* function before returning. * * Returns: -* Pointer to a &drm_framebuffer on success or an error pointer on failure. +* Number of planes on success or a negative error code on failure. */ -struct drm_framebuffer * -drm_gem_fb_create_with_funcs (struct drm_device *dev,struct drm_file *file, -const struct drm_mode_fb_cmd2 *mode_cmd, -const struct drm_framebuffer_funcs *funcs) +int drm_gem_fb_lookup (struct drm_device *dev, +struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs) {const struct drm_format_info *info; -struct drm_gem_object *objs[4 ]; -struct drm_framebuffer *fb;int ret, i; info =drm_get_format_info (dev, mode_cmd);if (!info) -return ERR_PTR (-EINVAL ); +return -EINVAL ;for (i =0 ; i < info->num_planes; i++) { -unsigned int width = mode_cmd->width / (i ? info->hsub :1 ); -unsigned int height = mode_cmd->height / (i ? info->vsub :1 ); -unsigned int min_size; - objs[i] =drm_gem_object_lookup (file, mode_cmd->handles[i]);if (!objs[i]) {DRM_DEBUG_KMS ("Failed to lookup GEM object\n" ); ret = -ENOENT ; goto err_gem_object_put; } + } + +return i; + +err_gem_object_put: +for (i--; i >=0 ; i--) +drm_gem_object_put_unlocked (objs[i]); + +return ret; +} +EXPORT_SYMBOL_GPL (drm_gem_fb_lookup); + +/** +* drm_gem_fb_size_check() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations +* @dev: DRM device +* @mode_cmd: Metadata from the userspace framebuffer creation request +* +* This function can be used to verify buffer sizes for all planes. +* It is caller's responsibility to put the objects on failure. +* +* Returns: +* Zero on success or a negative error code on failure. +*/ +int drm_gem_fb_size_check (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs) +{ +const struct drm_format_info *info; +int i; + + info =drm_get_format_info (dev, mode_cmd); +if (!info) +return -EINVAL ; + +for (i =0 ; i < info->num_planes; i++) { +unsigned int width = mode_cmd->width / (i ? info->hsub :1 ); +unsigned int height = mode_cmd->height / (i ? info->vsub :1 ); +unsigned int min_size; min_size = (height -1 ) * mode_cmd->pitches[i] +drm_format_info_min_pitch (info, i, width) + mode_cmd->offsets[i]; -if (objs[i]->size < min_size) { -drm_gem_object_put_unlocked (objs[i]); - ret = -EINVAL ; - goto err_gem_object_put; - } +if (objs[i]->size < min_size) +return -EINVAL ; } - fb =drm_gem_fb_alloc (dev, mode_cmd, objs, i, funcs); -if (IS_ERR (fb)) { - ret =PTR_ERR (fb); - goto err_gem_object_put; - } +return 0 ; -return fb; +} +EXPORT_SYMBOL_GPL (drm_gem_fb_size_check); -err_gem_object_put: -for (i--; i >=0 ; i--) -drm_gem_object_put_unlocked (objs[i]); +/** +* drm_gem_fb_create_with_funcs() - Helper function for the +* &drm_mode_config_funcs.fb_create +* callback +* @dev: DRM device +* @file: DRM file that holds the GEM handle(s) backing the framebuffer +* @mode_cmd: Metadata from the userspace framebuffer creation request +* @funcs: vtable to be used for the new framebuffer object +* +* This function can be used to set &drm_framebuffer_funcs for drivers that need +* custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to +* change &drm_framebuffer_funcs. The function does buffer size validation. +* +* Returns: +* Pointer to a &drm_framebuffer on success or an error pointer on failure. +*/ +struct drm_framebuffer * +drm_gem_fb_create_with_funcs (struct drm_device *dev,struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd, +const struct drm_framebuffer_funcs *funcs) +{ +struct drm_gem_object *objs[4 ]; +struct drm_framebuffer *fb; +int ret, num_planes; + + ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); +if (ret <0 ) +return ERR_PTR (ret); + num_planes = ret; + + ret =drm_gem_fb_size_check (dev, mode_cmd, objs); +if (ret) + fb =ERR_PTR (ret); +else + fb =drm_gem_fb_alloc (dev, mode_cmd, objs, num_planes, funcs); -return ERR_PTR (ret); +if (IS_ERR (fb)) +for (num_planes--; num_planes >=0 ; num_planes--) +drm_gem_object_put_unlocked (objs[num_planes]); + +return fb; }EXPORT_SYMBOL_GPL (drm_gem_fb_create_with_funcs); -static const struct drm_framebuffer_funcs drm_gem_fb_funcs = { - .destroy = drm_gem_fb_destroy, - .create_handle = drm_gem_fb_create_handle, -}; -/** * drm_gem_fb_create() - Helper function for the * &drm_mode_config_funcs.fb_create callback
include/drm/drm_gem_framebuffer_helper.h +17 -0
@@ -14,10 +14,27 @@ struct drm_simple_display_pipe;struct drm_gem_object *drm_gem_fb_get_obj (struct drm_framebuffer *fb,unsigned int plane); +int drm_gem_fb_init_with_funcs (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj, +unsigned int num_planes, +const struct drm_framebuffer_funcs *funcs); +int drm_gem_fb_init (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj,unsigned int num_planes);void drm_gem_fb_destroy (struct drm_framebuffer *fb);int drm_gem_fb_create_handle (struct drm_framebuffer *fb,struct drm_file *file,unsigned int *handle); +int drm_gem_fb_lookup (struct drm_device *dev, +struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs); +int drm_gem_fb_size_check (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs);struct drm_framebuffer * drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd,
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Liviu Dudau
maintainerRe: [PATCHv4 03/36] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own
Hi Andrzej,
Quoted 51 lines · Andrzej Pietrasiewicz
Prepare tools for drivers which need to allocate a struct
drm_framebuffer(or a container of structdrm_framebuffer) explicitly, before calling helpers. In such a case we need new helpers which omit allocating the structdrm_framebufferand this patch provides them. Consequently, they are used also inside the helpers themselves.The interested drivers will likely need to be able to perform object lookups and size checks in separate invocations and this patch provides that as well. Helpers themselves are updated, too.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 184 ++++++++++++++----- include/drm/drm_gem_framebuffer_helper.h | 17 ++ 2 files changed, 153 insertions(+), 48 deletions(-)drivers/gpu/drm/drm_gem_framebuffer_helper.c +27
-0@@ -54,6 +54,44 @@ struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, }EXPORT_SYMBOL_GPL (drm_gem_fb_get_obj); +int drm_gem_fb_init_with_funcs (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj, +unsigned int num_planes, +const struct drm_framebuffer_funcs *funcs) +{ +int ret, i; + +drm_helper_mode_fill_fb_struct (dev, fb, mode_cmd); + +for (i =0 ; i < num_planes; i++) + fb->obj[i] = obj[i]; + + ret =drm_framebuffer_init (dev, fb, funcs); +if (ret) +DRM_DEV_ERROR (dev->dev,"Failed to init framebuffer: %d\n" , + ret); + +return ret; +} +EXPORT_SYMBOL_GPL (drm_gem_fb_init_with_funcs); + +static const struct drm_framebuffer_funcs drm_gem_fb_funcs = { + .destroy = drm_gem_fb_destroy, + .create_handle = drm_gem_fb_create_handle, +};
drivers/gpu/drm/drm_gem_framebuffer_helper.c struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, · line 93
Quoted 10 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +10
-0+ +int drm_gem_fb_init (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj,unsigned int num_planes) +{ +return drm_gem_fb_init_with_funcs (fb, dev, mode_cmd, obj, num_planes, + &drm_gem_fb_funcs); +} +EXPORT_SYMBOL_GPL (drm_gem_fb_init);
If you export these two function they should better have documentation associated with them.
Quoted 85 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +16
-28+static struct drm_framebuffer * drm_gem_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd,@@ -61,21 +99,15 @@ drm_gem_fb_alloc(struct drm_device *dev, const struct drm_framebuffer_funcs *funcs) {struct drm_framebuffer *fb; -int ret, i; +int ret; fb =kzalloc (sizeof (*fb),GFP_KERNEL );if (!fb)return ERR_PTR (-ENOMEM ); -drm_helper_mode_fill_fb_struct (dev, fb, mode_cmd); - -for (i =0 ; i < num_planes; i++) - fb->obj[i] = obj[i]; - - ret =drm_framebuffer_init (dev, fb, funcs); + ret =drm_gem_fb_init_with_funcs (fb, dev, mode_cmd, obj, num_planes, + funcs);if (ret) { -DRM_DEV_ERROR (dev->dev,"Failed to init framebuffer: %d\n" , - ret);kfree (fb);return ERR_PTR (ret); }@@ -124,79 +156,135 @@ int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file,EXPORT_SYMBOL (drm_gem_fb_create_handle);/** -* drm_gem_fb_create_with_funcs() - Helper function for the -* &drm_mode_config_funcs.fb_create -* callback +* drm_gem_fb_lookup() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations * @dev: DRM device * @file: DRM file that holds the GEM handle(s) backing the framebuffer * @mode_cmd: Metadata from the userspace framebuffer creation request -* @funcs: vtable to be used for the new framebuffer object * -* This function can be used to set &drm_framebuffer_funcs for drivers that need -* custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to -* change &drm_framebuffer_funcs. The function does buffer size validation. +* This function can be used to look up the objects for all planes. +* In case an error is returned all the objects are put by the +* function before returning. * * Returns: -* Pointer to a &drm_framebuffer on success or an error pointer on failure. +* Number of planes on success or a negative error code on failure. */ -struct drm_framebuffer * -drm_gem_fb_create_with_funcs (struct drm_device *dev,struct drm_file *file, -const struct drm_mode_fb_cmd2 *mode_cmd, -const struct drm_framebuffer_funcs *funcs) +int drm_gem_fb_lookup (struct drm_device *dev, +struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs) {const struct drm_format_info *info; -struct drm_gem_object *objs[4 ]; -struct drm_framebuffer *fb;int ret, i; info =drm_get_format_info (dev, mode_cmd);if (!info) -return ERR_PTR (-EINVAL ); +return -EINVAL ;for (i =0 ; i < info->num_planes; i++) { -unsigned int width = mode_cmd->width / (i ? info->hsub :1 ); -unsigned int height = mode_cmd->height / (i ? info->vsub :1 ); -unsigned int min_size; - objs[i] =drm_gem_object_lookup (file, mode_cmd->handles[i]);if (!objs[i]) {DRM_DEBUG_KMS ("Failed to lookup GEM object\n" ); ret = -ENOENT ; goto err_gem_object_put; } + }
drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file, · line 201
Quoted 10 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +10
-0+ +return i; + +err_gem_object_put: +for (i--; i >=0 ; i--) +drm_gem_object_put_unlocked (objs[i]); + +return ret; +} +EXPORT_SYMBOL_GPL (drm_gem_fb_lookup);
I'm surprised git generated this mess of a diff. Given that you still have drm_gem_fb_create_with_funcs() further down, maybe you can re-order the functions so that Git creates a more sane diff?
Quoted 77 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +54
-14+ +/** +* drm_gem_fb_size_check() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations +* @dev: DRM device +* @mode_cmd: Metadata from the userspace framebuffer creation request +* +* This function can be used to verify buffer sizes for all planes. +* It is caller's responsibility to put the objects on failure. +* +* Returns: +* Zero on success or a negative error code on failure. +*/ +int drm_gem_fb_size_check (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs) +{ +const struct drm_format_info *info; +int i; + + info =drm_get_format_info (dev, mode_cmd); +if (!info) +return -EINVAL ; + +for (i =0 ; i < info->num_planes; i++) { +unsigned int width = mode_cmd->width / (i ? info->hsub :1 ); +unsigned int height = mode_cmd->height / (i ? info->vsub :1 ); +unsigned int min_size; min_size = (height -1 ) * mode_cmd->pitches[i] +drm_format_info_min_pitch (info, i, width) + mode_cmd->offsets[i]; -if (objs[i]->size < min_size) { -drm_gem_object_put_unlocked (objs[i]); - ret = -EINVAL ; - goto err_gem_object_put; - } +if (objs[i]->size < min_size) +return -EINVAL ; } - fb =drm_gem_fb_alloc (dev, mode_cmd, objs, i, funcs); -if (IS_ERR (fb)) { - ret =PTR_ERR (fb); - goto err_gem_object_put; - } +return 0 ; -return fb; +} +EXPORT_SYMBOL_GPL (drm_gem_fb_size_check); -err_gem_object_put: -for (i--; i >=0 ; i--) -drm_gem_object_put_unlocked (objs[i]); +/** +* drm_gem_fb_create_with_funcs() - Helper function for the +* &drm_mode_config_funcs.fb_create +* callback +* @dev: DRM device +* @file: DRM file that holds the GEM handle(s) backing the framebuffer +* @mode_cmd: Metadata from the userspace framebuffer creation request +* @funcs: vtable to be used for the new framebuffer object +* +* This function can be used to set &drm_framebuffer_funcs for drivers that need +* custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to +* change &drm_framebuffer_funcs. The function does buffer size validation. +* +* Returns: +* Pointer to a &drm_framebuffer on success or an error pointer on failure. +*/ +struct drm_framebuffer * +drm_gem_fb_create_with_funcs (struct drm_device *dev,struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd, +const struct drm_framebuffer_funcs *funcs) +{
drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file, · line 274
Quoted 10 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +10
-0+struct drm_gem_object *objs[4 ]; +struct drm_framebuffer *fb; +int ret, num_planes; + + ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); +if (ret <0 ) +return ERR_PTR (ret); + num_planes = ret; + + ret =drm_gem_fb_size_check (dev, mode_cmd, objs);
if drm_gem_fb_size_check() returns an error, then ...
drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file, · line 278
Quoted 4 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +4
-0+if (ret) + fb =ERR_PTR (ret); +else + fb =drm_gem_fb_alloc (dev, mode_cmd, objs, num_planes, funcs);
.... the else part is not taken, but ...
drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file, · line 282
Quoted 5 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +3
-1-return ERR_PTR (ret); +if (IS_ERR (fb)) +for (num_planes--; num_planes >=0 ; num_planes--) +drm_gem_object_put_unlocked (objs[num_planes]);
... here you'll attempt to dereference the objs. I don't think that is correct.
Quoted 48 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +2
-5+ +return fb; }EXPORT_SYMBOL_GPL (drm_gem_fb_create_with_funcs); -static const struct drm_framebuffer_funcs drm_gem_fb_funcs = { - .destroy = drm_gem_fb_destroy, - .create_handle = drm_gem_fb_create_handle, -}; -/** * drm_gem_fb_create() - Helper function for the * &drm_mode_config_funcs.fb_create callback include/drm/drm_gem_framebuffer_helper.h +17
-0@@ -14,10 +14,27 @@ struct drm_simple_display_pipe;struct drm_gem_object *drm_gem_fb_get_obj (struct drm_framebuffer *fb,unsigned int plane); +int drm_gem_fb_init_with_funcs (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj, +unsigned int num_planes, +const struct drm_framebuffer_funcs *funcs); +int drm_gem_fb_init (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj,unsigned int num_planes);void drm_gem_fb_destroy (struct drm_framebuffer *fb);int drm_gem_fb_create_handle (struct drm_framebuffer *fb,struct drm_file *file,unsigned int *handle); +int drm_gem_fb_lookup (struct drm_device *dev, +struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs); +int drm_gem_fb_size_check (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs);struct drm_framebuffer * drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd,Signature · 1 line
2.17.1
Best regards,
Liviu
Signature · 12 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-develRe: [PATCHv4 03/36] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own
Hi Liviu,
My way of thinking is explained below. Do you still find it problematic?
W dniu 16.12.2019 o 18:08, Liviu Dudau pisze:
Quoted 2 lines
Hi Andrzej,
<snip>
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +4
-0+struct drm_framebuffer * +drm_gem_fb_create_with_funcs (struct drm_device *dev,struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd, +const struct drm_framebuffer_funcs *funcs)
Quoted 8 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file, · line 271
Quoted 8 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +8
-0+{ +struct drm_gem_object *objs[4 ]; +struct drm_framebuffer *fb; +int ret, num_planes; + + ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); +if (ret <0 ) +return ERR_PTR (ret);
here objs is guaranteed to have been filled...
Quoted 6 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file, · line 274
Quoted 3 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +3
-0+ num_planes = ret; + + ret =drm_gem_fb_size_check (dev, mode_cmd, objs);if
drm_gem_fb_size_check()returns an error, then ...
Quoted 6 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file, · line 278
Quoted 4 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +4
-0+if (ret) + fb =ERR_PTR (ret); +else + fb =drm_gem_fb_alloc (dev, mode_cmd, objs, num_planes, funcs);.... the else part is not taken, but ...
... nonetheless objs have already been looked up...
Quoted 8 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file, · line 282
Quoted 6 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +3
-1-return ERR_PTR (ret); +if (IS_ERR (fb)) +for (num_planes--; num_planes >=0 ; num_planes--) +drm_gem_object_put_unlocked (objs[num_planes]);... here you'll attempt to dereference the objs. I don't think that is correct.
... so it is safe to dereference objs here
Regards,
Andrzej
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv4,03/36] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own
In reply to Andrzej PietrasiewiczHi Andrzej:
Good work.
It's a real useful patch, with it seems most vendor-specific fb_create can be simplified by these helper funcs.
Quoted 110 lines · Andrzej Pietrasiewicz
Prepare tools for drivers which need to allocate a struct
drm_framebuffer(or a container of structdrm_framebuffer) explicitly, before calling helpers. In such a case we need new helpers which omit allocating the structdrm_framebufferand this patch provides them. Consequently, they are used also inside the helpers themselves.The interested drivers will likely need to be able to perform object lookups and size checks in separate invocations and this patch provides that as well. Helpers themselves are updated, too.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 184 ++++++++++++++----- include/drm/drm_gem_framebuffer_helper.h | 17 ++ 2 files changed, 153 insertions(+), 48 deletions(-)drivers/gpu/drm/drm_gem_framebuffer_helper.c +46
-16@@ -54,6 +54,44 @@ struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, }EXPORT_SYMBOL_GPL (drm_gem_fb_get_obj); +int drm_gem_fb_init_with_funcs (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj, +unsigned int num_planes, +const struct drm_framebuffer_funcs *funcs) +{ +int ret, i; + +drm_helper_mode_fill_fb_struct (dev, fb, mode_cmd); + +for (i =0 ; i < num_planes; i++) + fb->obj[i] = obj[i]; + + ret =drm_framebuffer_init (dev, fb, funcs); +if (ret) +DRM_DEV_ERROR (dev->dev,"Failed to init framebuffer: %d\n" , + ret); + +return ret; +} +EXPORT_SYMBOL_GPL (drm_gem_fb_init_with_funcs); + +static const struct drm_framebuffer_funcs drm_gem_fb_funcs = { + .destroy = drm_gem_fb_destroy, + .create_handle = drm_gem_fb_create_handle, +}; + +int drm_gem_fb_init (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj,unsigned int num_planes) +{ +return drm_gem_fb_init_with_funcs (fb, dev, mode_cmd, obj, num_planes, + &drm_gem_fb_funcs); +} +EXPORT_SYMBOL_GPL (drm_gem_fb_init); +static struct drm_framebuffer * drm_gem_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd,@@ -61,21 +99,15 @@ drm_gem_fb_alloc(struct drm_device *dev, const struct drm_framebuffer_funcs *funcs) {struct drm_framebuffer *fb; -int ret, i; +int ret; fb =kzalloc (sizeof (*fb),GFP_KERNEL );if (!fb)return ERR_PTR (-ENOMEM ); -drm_helper_mode_fill_fb_struct (dev, fb, mode_cmd); - -for (i =0 ; i < num_planes; i++) - fb->obj[i] = obj[i]; - - ret =drm_framebuffer_init (dev, fb, funcs); + ret =drm_gem_fb_init_with_funcs (fb, dev, mode_cmd, obj, num_planes, + funcs);if (ret) { -DRM_DEV_ERROR (dev->dev,"Failed to init framebuffer: %d\n" , - ret);kfree (fb);return ERR_PTR (ret); }@@ -124,79 +156,135 @@ int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file,EXPORT_SYMBOL (drm_gem_fb_create_handle);/** -* drm_gem_fb_create_with_funcs() - Helper function for the -* &drm_mode_config_funcs.fb_create -* callback +* drm_gem_fb_lookup() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations * @dev: DRM device * @file: DRM file that holds the GEM handle(s) backing the framebuffer * @mode_cmd: Metadata from the userspace framebuffer creation request -* @funcs: vtable to be used for the new framebuffer object * -* This function can be used to set &drm_framebuffer_funcs for drivers that need -* custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to -* change &drm_framebuffer_funcs. The function does buffer size validation. +* This function can be used to look up the objects for all planes. +* In case an error is returned all the objects are put by the +* function before returning.
drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file, · line 172
Quoted 10 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +2
-5* * Returns: -* Pointer to a &drm_framebuffer on success or an error pointer on failure. +* Number of planes on success or a negative error code on failure. */ -struct drm_framebuffer * -drm_gem_fb_create_with_funcs (struct drm_device *dev,struct drm_file *file, -const struct drm_mode_fb_cmd2 *mode_cmd, -const struct drm_framebuffer_funcs *funcs) +int drm_gem_fb_lookup(struct drm_device *dev,
[nit-pick] Maybe name it to drm_gem_fb_objs_lookup()
Quoted 167 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +88
-27+struct drm_file *file, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **objs) { const struct drm_format_info *info; -struct drm_gem_object *objs[4 ]; -struct drm_framebuffer *fb;int ret, i; info =drm_get_format_info (dev, mode_cmd);if (!info) -return ERR_PTR (-EINVAL ); +return -EINVAL ;for (i =0 ; i < info->num_planes; i++) { -unsigned int width = mode_cmd->width / (i ? info->hsub :1 ); -unsigned int height = mode_cmd->height / (i ? info->vsub :1 ); -unsigned int min_size; - objs[i] =drm_gem_object_lookup (file, mode_cmd->handles[i]);if (!objs[i]) {DRM_DEBUG_KMS ("Failed to lookup GEM object\n" ); ret = -ENOENT ; goto err_gem_object_put; } + } + +return i; + +err_gem_object_put: +for (i--; i >=0 ; i--) +drm_gem_object_put_unlocked (objs[i]); + +return ret; +} +EXPORT_SYMBOL_GPL (drm_gem_fb_lookup); + +/** +* drm_gem_fb_size_check() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations +* @dev: DRM device +* @mode_cmd: Metadata from the userspace framebuffer creation request +* +* This function can be used to verify buffer sizes for all planes. +* It is caller's responsibility to put the objects on failure. +* +* Returns: +* Zero on success or a negative error code on failure. +*/ +int drm_gem_fb_size_check (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs) +{ +const struct drm_format_info *info; +int i; + + info =drm_get_format_info (dev, mode_cmd); +if (!info) +return -EINVAL ; + +for (i =0 ; i < info->num_planes; i++) { +unsigned int width = mode_cmd->width / (i ? info->hsub :1 ); +unsigned int height = mode_cmd->height / (i ? info->vsub :1 ); +unsigned int min_size; min_size = (height -1 ) * mode_cmd->pitches[i] +drm_format_info_min_pitch (info, i, width) + mode_cmd->offsets[i]; -if (objs[i]->size < min_size) { -drm_gem_object_put_unlocked (objs[i]); - ret = -EINVAL ; - goto err_gem_object_put; - } +if (objs[i]->size < min_size) +return -EINVAL ; } - fb =drm_gem_fb_alloc (dev, mode_cmd, objs, i, funcs); -if (IS_ERR (fb)) { - ret =PTR_ERR (fb); - goto err_gem_object_put; - } +return 0 ; -return fb; +} +EXPORT_SYMBOL_GPL (drm_gem_fb_size_check); -err_gem_object_put: -for (i--; i >=0 ; i--) -drm_gem_object_put_unlocked (objs[i]); +/** +* drm_gem_fb_create_with_funcs() - Helper function for the +* &drm_mode_config_funcs.fb_create +* callback +* @dev: DRM device +* @file: DRM file that holds the GEM handle(s) backing the framebuffer +* @mode_cmd: Metadata from the userspace framebuffer creation request +* @funcs: vtable to be used for the new framebuffer object +* +* This function can be used to set &drm_framebuffer_funcs for drivers that need +* custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to +* change &drm_framebuffer_funcs. The function does buffer size validation. +* +* Returns: +* Pointer to a &drm_framebuffer on success or an error pointer on failure. +*/ +struct drm_framebuffer * +drm_gem_fb_create_with_funcs (struct drm_device *dev,struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd, +const struct drm_framebuffer_funcs *funcs) +{ +struct drm_gem_object *objs[4 ]; +struct drm_framebuffer *fb; +int ret, num_planes; + + ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); +if (ret <0 ) +return ERR_PTR (ret); + num_planes = ret; + + ret =drm_gem_fb_size_check (dev, mode_cmd, objs); +if (ret) + fb =ERR_PTR (ret); +else + fb =drm_gem_fb_alloc (dev, mode_cmd, objs, num_planes, funcs); -return ERR_PTR (ret); +if (IS_ERR (fb)) +for (num_planes--; num_planes >=0 ; num_planes--) +drm_gem_object_put_unlocked (objs[num_planes]); + +return fb; }EXPORT_SYMBOL_GPL (drm_gem_fb_create_with_funcs); -static const struct drm_framebuffer_funcs drm_gem_fb_funcs = { - .destroy = drm_gem_fb_destroy, - .create_handle = drm_gem_fb_create_handle, -}; -/** * drm_gem_fb_create() - Helper function for the * &drm_mode_config_funcs.fb_create callback include/drm/drm_gem_framebuffer_helper.h +10
-0@@ -14,10 +14,27 @@ struct drm_simple_display_pipe;struct drm_gem_object *drm_gem_fb_get_obj (struct drm_framebuffer *fb,unsigned int plane); +int drm_gem_fb_init_with_funcs (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj, +unsigned int num_planes, +const struct drm_framebuffer_funcs *funcs); +int drm_gem_fb_init (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj,unsigned int num_planes);void drm_gem_fb_destroy (struct drm_framebuffer *fb);int drm_gem_fb_create_handle (struct drm_framebuffer *fb,struct drm_file *file,unsigned int *handle);
include/drm/drm_gem_framebuffer_helper.h struct drm_simple_display_pipe; · line 40
Quoted 10 lines
include/drm/drm_gem_framebuffer_helper.h +7
-0+int drm_gem_fb_lookup (struct drm_device *dev, +struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs); +int drm_gem_fb_size_check (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs);struct drm_framebuffer * drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd,
James.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 4/36 drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
In reply to Andrzej PietrasiewiczThe new version accepts a struct describing deviations from standard way of doing the size checks. The caller must provide the respective values.
--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 47 ++++++++++++++++---- include/drm/drm_gem_framebuffer_helper.h | 16 +++++++ 2 files changed, 55 insertions(+), 8 deletions(-)
drivers/gpu/drm/drm_gem_framebuffer_helper.c +39 -8
@@ -201,8 +201,9 @@ int drm_gem_fb_lookup(struct drm_device *dev,EXPORT_SYMBOL_GPL (drm_gem_fb_lookup);/** -* drm_gem_fb_size_check() - Helper function for use in -* &drm_mode_config_funcs.fb_create implementations +* drm_gem_fb_size_check_special() - Helper function for use in +* &drm_mode_config_funcs.fb_create +* implementations * @dev: DRM device * @mode_cmd: Metadata from the userspace framebuffer creation request *
@@ -212,9 +213,10 @@ EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);* Returns: * Zero on success or a negative error code on failure. */ -int drm_gem_fb_size_check (struct drm_device *dev, -const struct drm_mode_fb_cmd2 *mode_cmd, -struct drm_gem_object **objs) +int drm_gem_fb_size_check_special (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +const struct drm_size_check *check, +struct drm_gem_object **objs) {const struct drm_format_info *info;int i;
@@ -227,10 +229,19 @@ int drm_gem_fb_size_check(struct drm_device *dev,unsigned int width = mode_cmd->width / (i ? info->hsub :1 );unsigned int height = mode_cmd->height / (i ? info->vsub :1 );unsigned int min_size; +u32 pitch = mode_cmd->pitches[i]; + +if (check && check->use_pitch_multiplier) +if ((pitch * check->pitch_multiplier[i]) % + check->pitch_modulo) +return -EINVAL ; - min_size = (height -1 ) * mode_cmd->pitches[i] - +drm_format_info_min_pitch (info, i, width) - + mode_cmd->offsets[i]; +if (check && check->use_min_size) + min_size = check->min_size[i]; +else + min_size = (height -1 ) * pitch + +drm_format_info_min_pitch (info, i, width) + + mode_cmd->offsets[i];if (objs[i]->size < min_size)return -EINVAL ;
@@ -239,6 +250,26 @@ int drm_gem_fb_size_check(struct drm_device *dev,return 0 ; } +EXPORT_SYMBOL_GPL (drm_gem_fb_size_check_special); + +/** +* drm_gem_fb_size_check() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations +* @dev: DRM device +* @mode_cmd: Metadata from the userspace framebuffer creation request +* +* This function can be used to verify buffer sizes for all planes. +* It is caller's responsibility to put the objects on failure. +* +* Returns: +* Zero on success or a negative error code on failure. +*/ +int drm_gem_fb_size_check (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs) +{ +return drm_gem_fb_size_check_special (dev, mode_cmd,NULL , objs); +}EXPORT_SYMBOL_GPL (drm_gem_fb_size_check);/**
include/drm/drm_gem_framebuffer_helper.h +16 -0
@@ -11,6 +11,18 @@ struct drm_mode_fb_cmd2;struct drm_plane ;struct drm_plane_state ;struct drm_simple_display_pipe ; +struct drm_size_check ; + +/** +* struct drm_size_check - Description of special requirements for size checks. +*/ +struct drm_size_check { +unsigned int min_size[4 ]; +bool use_min_size; +u32 pitch_multiplier[4 ]; +u32 pitch_modulo; +bool use_pitch_multiplier; +};struct drm_gem_object *drm_gem_fb_get_obj (struct drm_framebuffer *fb,unsigned int plane);
@@ -32,6 +44,10 @@ int drm_gem_fb_lookup(struct drm_device *dev,struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **objs); +int drm_gem_fb_size_check_special (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +const struct drm_size_check *check, +struct drm_gem_object **objs);int drm_gem_fb_size_check (struct drm_device *dev,const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object **objs);
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Liviu Dudau
maintainerRe: [PATCHv4 04/36] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
Quoted 63 lines · Andrzej Pietrasiewicz
The new version accepts a struct describing deviations from standard way of doing the size checks. The caller must provide the respective values.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 47 ++++++++++++++++---- include/drm/drm_gem_framebuffer_helper.h | 16 +++++++ 2 files changed, 55 insertions(+), 8 deletions(-)drivers/gpu/drm/drm_gem_framebuffer_helper.c +19
-8@@ -201,8 +201,9 @@ int drm_gem_fb_lookup(struct drm_device *dev,EXPORT_SYMBOL_GPL (drm_gem_fb_lookup);/** -* drm_gem_fb_size_check() - Helper function for use in -* &drm_mode_config_funcs.fb_create implementations +* drm_gem_fb_size_check_special() - Helper function for use in +* &drm_mode_config_funcs.fb_create +* implementations * @dev: DRM device * @mode_cmd: Metadata from the userspace framebuffer creation request * @@ -212,9 +213,10 @@ EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);* Returns: * Zero on success or a negative error code on failure. */ -int drm_gem_fb_size_check (struct drm_device *dev, -const struct drm_mode_fb_cmd2 *mode_cmd, -struct drm_gem_object **objs) +int drm_gem_fb_size_check_special (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +const struct drm_size_check *check, +struct drm_gem_object **objs) {const struct drm_format_info *info;int i;@@ -227,10 +229,19 @@ int drm_gem_fb_size_check(struct drm_device *dev,unsigned int width = mode_cmd->width / (i ? info->hsub :1 );unsigned int height = mode_cmd->height / (i ? info->vsub :1 );unsigned int min_size; +u32 pitch = mode_cmd->pitches[i]; + +if (check && check->use_pitch_multiplier) +if ((pitch * check->pitch_multiplier[i]) % + check->pitch_modulo) +return -EINVAL ; - min_size = (height -1 ) * mode_cmd->pitches[i] - +drm_format_info_min_pitch (info, i, width) - + mode_cmd->offsets[i]; +if (check && check->use_min_size) + min_size = check->min_size[i]; +else + min_size = (height -1 ) * pitch + +drm_format_info_min_pitch (info, i, width) + + mode_cmd->offsets[i];if (objs[i]->size < min_size)return -EINVAL ;
drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_size_check(struct drm_device *dev, · line 253
Quoted 4 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +1
-0@@ -239,6 +250,26 @@ int drm_gem_fb_size_check(struct drm_device *dev,return 0 ; } +EXPORT_SYMBOL_GPL (drm_gem_fb_size_check_special);
Hmm, not a big fan of exporting something called foo_special. What about following the tradition of calling it drm_gem_fb_size_check2() ?
Best regards,
Liviu
Quoted 59 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +19
-0+ +/** +* drm_gem_fb_size_check() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations +* @dev: DRM device +* @mode_cmd: Metadata from the userspace framebuffer creation request +* +* This function can be used to verify buffer sizes for all planes. +* It is caller's responsibility to put the objects on failure. +* +* Returns: +* Zero on success or a negative error code on failure. +*/ +int drm_gem_fb_size_check (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs) +{ +return drm_gem_fb_size_check_special (dev, mode_cmd,NULL , objs); +}EXPORT_SYMBOL_GPL (drm_gem_fb_size_check);/** include/drm/drm_gem_framebuffer_helper.h +16
-0@@ -11,6 +11,18 @@ struct drm_mode_fb_cmd2;struct drm_plane ;struct drm_plane_state ;struct drm_simple_display_pipe ; +struct drm_size_check ; + +/** +* struct drm_size_check - Description of special requirements for size checks. +*/ +struct drm_size_check { +unsigned int min_size[4 ]; +bool use_min_size; +u32 pitch_multiplier[4 ]; +u32 pitch_modulo; +bool use_pitch_multiplier; +};struct drm_gem_object *drm_gem_fb_get_obj (struct drm_framebuffer *fb,unsigned int plane);@@ -32,6 +44,10 @@ int drm_gem_fb_lookup(struct drm_device *dev,struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **objs); +int drm_gem_fb_size_check_special (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +const struct drm_size_check *check, +struct drm_gem_object **objs);int drm_gem_fb_size_check (struct drm_device *dev,const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object **objs);Signature · 1 line
2.17.1
Signature · 12 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-develRe: [PATCHv4,04/36] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
In reply to Andrzej PietrasiewiczHi Andrzej:
Really a good idea for introducing this custom size check, it's very useful for some Komeda/malidp format, espcially pitch_multiplier, maybe in future we can add it into into the drm_format_info.
Quoted 26 lines · Andrzej Pietrasiewicz
The new version accepts a struct describing deviations from standard way of doing the size checks. The caller must provide the respective values.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 47 ++++++++++++++++---- include/drm/drm_gem_framebuffer_helper.h | 16 +++++++ 2 files changed, 55 insertions(+), 8 deletions(-)drivers/gpu/drm/drm_gem_framebuffer_helper.c +3
-2@@ -201,8 +201,9 @@ int drm_gem_fb_lookup(struct drm_device *dev,EXPORT_SYMBOL_GPL (drm_gem_fb_lookup);/** -* drm_gem_fb_size_check() - Helper function for use in -* &drm_mode_config_funcs.fb_create implementations +* drm_gem_fb_size_check_special() - Helper function for use in +* &drm_mode_config_funcs.fb_create +* implementations * @dev: DRM device * @mode_cmd: Metadata from the userspace framebuffer creation request *
drivers/gpu/drm/drm_gem_framebuffer_helper.c EXPORT_SYMBOL_GPL(drm_gem_fb_lookup); · line 216
Quoted 7 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +1
-3@@ -212,9 +213,10 @@ EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);* Returns: * Zero on success or a negative error code on failure. */ -int drm_gem_fb_size_check (struct drm_device *dev, -const struct drm_mode_fb_cmd2 *mode_cmd, -struct drm_gem_object **objs) +int drm_gem_fb_size_check_special(struct drm_device *dev,
How about name it to drm_gem_fb_custom_size_check()
Quoted 80 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +35
-3+const struct drm_mode_fb_cmd2 *mode_cmd, + const struct drm_size_check *check, + struct drm_gem_object **objs) { const struct drm_format_info *info;int i;@@ -227,10 +229,19 @@ int drm_gem_fb_size_check(struct drm_device *dev,unsigned int width = mode_cmd->width / (i ? info->hsub :1 );unsigned int height = mode_cmd->height / (i ? info->vsub :1 );unsigned int min_size; +u32 pitch = mode_cmd->pitches[i]; + +if (check && check->use_pitch_multiplier) +if ((pitch * check->pitch_multiplier[i]) % + check->pitch_modulo) +return -EINVAL ; - min_size = (height -1 ) * mode_cmd->pitches[i] - +drm_format_info_min_pitch (info, i, width) - + mode_cmd->offsets[i]; +if (check && check->use_min_size) + min_size = check->min_size[i]; +else + min_size = (height -1 ) * pitch + +drm_format_info_min_pitch (info, i, width) + + mode_cmd->offsets[i];if (objs[i]->size < min_size)return -EINVAL ;@@ -239,6 +250,26 @@ int drm_gem_fb_size_check(struct drm_device *dev,return 0 ; } +EXPORT_SYMBOL_GPL (drm_gem_fb_size_check_special); + +/** +* drm_gem_fb_size_check() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations +* @dev: DRM device +* @mode_cmd: Metadata from the userspace framebuffer creation request +* +* This function can be used to verify buffer sizes for all planes. +* It is caller's responsibility to put the objects on failure. +* +* Returns: +* Zero on success or a negative error code on failure. +*/ +int drm_gem_fb_size_check (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs) +{ +return drm_gem_fb_size_check_special (dev, mode_cmd,NULL , objs); +}EXPORT_SYMBOL_GPL (drm_gem_fb_size_check);/** include/drm/drm_gem_framebuffer_helper.h +12
-0@@ -11,6 +11,18 @@ struct drm_mode_fb_cmd2;struct drm_plane ;struct drm_plane_state ;struct drm_simple_display_pipe ; +struct drm_size_check ; + +/** +* struct drm_size_check - Description of special requirements for size checks. +*/ +struct drm_size_check { +unsigned int min_size[4 ]; +bool use_min_size; +u32 pitch_multiplier[4 ]; +u32 pitch_modulo; +bool use_pitch_multiplier; +};struct drm_gem_object *drm_gem_fb_get_obj (struct drm_framebuffer *fb,unsigned int plane);
include/drm/drm_gem_framebuffer_helper.h int drm_gem_fb_lookup(struct drm_device *dev, · line 53
Quoted 10 lines
include/drm/drm_gem_framebuffer_helper.h +4
-0@@ -32,6 +44,10 @@ int drm_gem_fb_lookup(struct drm_device *dev,struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **objs); +int drm_gem_fb_size_check_special (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +const struct drm_size_check *check, +struct drm_gem_object **objs);int drm_gem_fb_size_check (struct drm_device *dev,const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object **objs);
For this common case can we just define it as a MACRO, or a inline func here in this header.
Thanks
James
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv4,04/36] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
Hi James,
Thank you for the review.
Did you intentionally review patches from the v4 series or you simply didn't notice the v5? There are some differences, the most notable one is using proper way of subclassing a drm_framebuffer.
The v5 series was sent on 17th December 2019.
Andrzej
W dniu 17.02.2020 o 09:16, james qian wang (Arm Technology China) pisze:
Quoted 137 lines
Hi Andrzej:
Really a good idea for introducing this custom size check, it's very useful for some Komeda/malidp format, espcially
pitch_multiplier, maybe in future we can add it into into thedrm_format_info.Quoted 26 lines · Andrzej Pietrasiewicz
The new version accepts a struct describing deviations from standard way of doing the size checks. The caller must provide the respective values.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 47 ++++++++++++++++---- include/drm/drm_gem_framebuffer_helper.h | 16 +++++++ 2 files changed, 55 insertions(+), 8 deletions(-)drivers/gpu/drm/drm_gem_framebuffer_helper.c +3
-2@@ -201,8 +201,9 @@ int drm_gem_fb_lookup(struct drm_device *dev,EXPORT_SYMBOL_GPL (drm_gem_fb_lookup);/** -* drm_gem_fb_size_check() - Helper function for use in -* &drm_mode_config_funcs.fb_create implementations +* drm_gem_fb_size_check_special() - Helper function for use in +* &drm_mode_config_funcs.fb_create +* implementations * @dev: DRM device * @mode_cmd: Metadata from the userspace framebuffer creation request * drivers/gpu/drm/drm_gem_framebuffer_helper.c EXPORT_SYMBOL_GPL(drm_gem_fb_lookup); · line 216
Quoted 7 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +1
-3@@ -212,9 +213,10 @@ EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);* Returns: * Zero on success or a negative error code on failure. */ -int drm_gem_fb_size_check (struct drm_device *dev, -const struct drm_mode_fb_cmd2 *mode_cmd, -struct drm_gem_object **objs) +int drm_gem_fb_size_check_special(struct drm_device *dev,How about name it to
drm_gem_fb_custom_size_check()Quoted 80 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +35
-3+const struct drm_mode_fb_cmd2 *mode_cmd, + const struct drm_size_check *check, + struct drm_gem_object **objs) { const struct drm_format_info *info;int i;@@ -227,10 +229,19 @@ int drm_gem_fb_size_check(struct drm_device *dev,unsigned int width = mode_cmd->width / (i ? info->hsub :1 );unsigned int height = mode_cmd->height / (i ? info->vsub :1 );unsigned int min_size; +u32 pitch = mode_cmd->pitches[i]; + +if (check && check->use_pitch_multiplier) +if ((pitch * check->pitch_multiplier[i]) % + check->pitch_modulo) +return -EINVAL ; - min_size = (height -1 ) * mode_cmd->pitches[i] - +drm_format_info_min_pitch (info, i, width) - + mode_cmd->offsets[i]; +if (check && check->use_min_size) + min_size = check->min_size[i]; +else + min_size = (height -1 ) * pitch + +drm_format_info_min_pitch (info, i, width) + + mode_cmd->offsets[i];if (objs[i]->size < min_size)return -EINVAL ;@@ -239,6 +250,26 @@ int drm_gem_fb_size_check(struct drm_device *dev,return 0 ; } +EXPORT_SYMBOL_GPL (drm_gem_fb_size_check_special); + +/** +* drm_gem_fb_size_check() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations +* @dev: DRM device +* @mode_cmd: Metadata from the userspace framebuffer creation request +* +* This function can be used to verify buffer sizes for all planes. +* It is caller's responsibility to put the objects on failure. +* +* Returns: +* Zero on success or a negative error code on failure. +*/ +int drm_gem_fb_size_check (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs) +{ +return drm_gem_fb_size_check_special (dev, mode_cmd,NULL , objs); +}EXPORT_SYMBOL_GPL (drm_gem_fb_size_check);/** include/drm/drm_gem_framebuffer_helper.h +12
-0@@ -11,6 +11,18 @@ struct drm_mode_fb_cmd2;struct drm_plane ;struct drm_plane_state ;struct drm_simple_display_pipe ; +struct drm_size_check ; + +/** +* struct drm_size_check - Description of special requirements for size checks. +*/ +struct drm_size_check { +unsigned int min_size[4 ]; +bool use_min_size; +u32 pitch_multiplier[4 ]; +u32 pitch_modulo; +bool use_pitch_multiplier; +};struct drm_gem_object *drm_gem_fb_get_obj (struct drm_framebuffer *fb,unsigned int plane);include/drm/drm_gem_framebuffer_helper.h int drm_gem_fb_lookup(struct drm_device *dev, · line 53
Quoted 10 lines
include/drm/drm_gem_framebuffer_helper.h +4
-0@@ -32,6 +44,10 @@ int drm_gem_fb_lookup(struct drm_device *dev,struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **objs); +int drm_gem_fb_size_check_special (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +const struct drm_size_check *check, +struct drm_gem_object **objs);int drm_gem_fb_size_check (struct drm_device *dev,const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object **objs);For this common case can we just define it as a MACRO, or a inline func here in this header.
Quoted 3 lines
Thanks
James
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv4,04/36] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
Quoted 8 lines · Andrzej Pietrasiewicz
Hi James,
Thank you for the review.
Did you intentionally review patches from the v4 series or you simply didn't notice the v5? There are some differences, the most notable one is using proper way of subclassing a
drm_framebuffer.
The v5 series was sent on 17th December 2019.
Hi Andrzej:
Sorry, I did the review based pathwork:
https://patchwork.freedesktop.org/series/70889/#rev35
seems it has problem which only have V4.
I will re-do the review for V5 ASAP.
Sorry again.
James.
Quoted 137 lines
Andrzej
W dniu 17.02.2020 o�09:16, james qian wang (Arm Technology China) pisze:
Quoted 134 lines
Hi Andrzej:
Really a good idea for introducing this custom size check, it's very useful for some Komeda/malidp format, espcially
pitch_multiplier, maybe in future we can add it into into thedrm_format_info.Quoted 25 lines · Andrzej Pietrasiewicz
The new version accepts a struct describing deviations from standard way of doing the size checks. The caller must provide the respective values.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 47 ++++++++++++++++---- include/drm/drm_gem_framebuffer_helper.h | 16 +++++++ 2 files changed, 55 insertions(+), 8 deletions(-)drivers/gpu/drm/drm_gem_framebuffer_helper.c +3
-2@@ -201,8 +201,9 @@ int drm_gem_fb_lookup(struct drm_device *dev,EXPORT_SYMBOL_GPL (drm_gem_fb_lookup);/** -* drm_gem_fb_size_check() - Helper function for use in -* &drm_mode_config_funcs.fb_create implementations +* drm_gem_fb_size_check_special() - Helper function for use in +* &drm_mode_config_funcs.fb_create +* implementations * @dev: DRM device * @mode_cmd: Metadata from the userspace framebuffer creation request * drivers/gpu/drm/drm_gem_framebuffer_helper.c EXPORT_SYMBOL_GPL(drm_gem_fb_lookup); · line 216
Quoted 7 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +1
-3@@ -212,9 +213,10 @@ EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);* Returns: * Zero on success or a negative error code on failure. */ -int drm_gem_fb_size_check (struct drm_device *dev, -const struct drm_mode_fb_cmd2 *mode_cmd, -struct drm_gem_object **objs) +int drm_gem_fb_size_check_special(struct drm_device *dev,How about name it to
drm_gem_fb_custom_size_check()Quoted 75 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +35
-3+const struct drm_mode_fb_cmd2 *mode_cmd, + const struct drm_size_check *check, + struct drm_gem_object **objs) { const struct drm_format_info *info;int i;@@ -227,10 +229,19 @@ int drm_gem_fb_size_check(struct drm_device *dev,unsigned int width = mode_cmd->width / (i ? info->hsub :1 );unsigned int height = mode_cmd->height / (i ? info->vsub :1 );unsigned int min_size; +u32 pitch = mode_cmd->pitches[i]; + +if (check && check->use_pitch_multiplier) +if ((pitch * check->pitch_multiplier[i]) % + check->pitch_modulo) +return -EINVAL ; - min_size = (height -1 ) * mode_cmd->pitches[i] - +drm_format_info_min_pitch (info, i, width) - + mode_cmd->offsets[i]; +if (check && check->use_min_size) + min_size = check->min_size[i]; +else + min_size = (height -1 ) * pitch + +drm_format_info_min_pitch (info, i, width) + + mode_cmd->offsets[i];if (objs[i]->size < min_size)return -EINVAL ;@@ -239,6 +250,26 @@ int drm_gem_fb_size_check(struct drm_device *dev,return 0 ; } +EXPORT_SYMBOL_GPL (drm_gem_fb_size_check_special); + +/** +* drm_gem_fb_size_check() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations +* @dev: DRM device +* @mode_cmd: Metadata from the userspace framebuffer creation request +* +* This function can be used to verify buffer sizes for all planes. +* It is caller's responsibility to put the objects on failure. +* +* Returns: +* Zero on success or a negative error code on failure. +*/ +int drm_gem_fb_size_check (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs) +{ +return drm_gem_fb_size_check_special (dev, mode_cmd,NULL , objs); +}EXPORT_SYMBOL_GPL (drm_gem_fb_size_check);/** include/drm/drm_gem_framebuffer_helper.h +12
-0@@ -11,6 +11,18 @@ struct drm_mode_fb_cmd2;struct drm_plane ;struct drm_plane_state ;struct drm_simple_display_pipe ; +struct drm_size_check ; + +/** +* struct drm_size_check - Description of special requirements for size checks. +*/ +struct drm_size_check { +unsigned int min_size[4 ]; +bool use_min_size; +u32 pitch_multiplier[4 ]; +u32 pitch_modulo; +bool use_pitch_multiplier; +};struct drm_gem_object *drm_gem_fb_get_obj (struct drm_framebuffer *fb,unsigned int plane);include/drm/drm_gem_framebuffer_helper.h int drm_gem_fb_lookup(struct drm_device *dev, · line 53
Quoted 10 lines
include/drm/drm_gem_framebuffer_helper.h +4
-0@@ -32,6 +44,10 @@ int drm_gem_fb_lookup(struct drm_device *dev,struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **objs); +int drm_gem_fb_size_check_special (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +const struct drm_size_check *check, +struct drm_gem_object **objs);int drm_gem_fb_size_check (struct drm_device *dev,const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object **objs);For this common case can we just define it as a MACRO, or a inline func here in this header.
Thanks
James
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 5/36 drm/gem-fb-helper: Add generic afbc size checks
In reply to Andrzej PietrasiewiczExtend the size-checking special function to handle afbc.
--- drivers/gpu/drm/drm_fourcc.c | 10 +++- drivers/gpu/drm/drm_framebuffer.c | 3 + drivers/gpu/drm/drm_gem_framebuffer_helper.c | 60 ++++++++++++++++++-- include/drm/drm_gem_framebuffer_helper.h | 16 ++++++ 4 files changed, 82 insertions(+), 7 deletions(-)
drivers/gpu/drm/drm_fourcc.c +8 -2
@@ -323,8 +323,14 @@ drm_get_format_info(struct drm_device *dev, {const struct drm_format_info *info =NULL ; -if (dev->mode_config.funcs->get_format_info) - info = dev->mode_config.funcs->get_format_info (mode_cmd); +/* bypass driver callback if afbc */ +if (!drm_is_afbc (mode_cmd->modifier[0 ])) +if (dev->mode_config.funcs->get_format_info) { +const struct drm_mode_config_funcs *funcs; + + funcs = dev->mode_config.funcs; + info = funcs->get_format_info (mode_cmd); + }if (!info) info =drm_format_info (mode_cmd->pixel_format);
drivers/gpu/drm/drm_framebuffer.c +3 -0
@@ -204,6 +204,9 @@ static int framebuffer_check(struct drm_device *dev,unsigned int block_size = info->char_per_block[i];u64 min_pitch =drm_format_info_min_pitch (info, i, width); +if (drm_is_afbc (r->modifier[i])) + block_size =0 ; +if (!block_size && (r->modifier[i] ==DRM_FORMAT_MOD_LINEAR )) {DRM_DEBUG_KMS ("Format requires non-linear modifier for plane %d\n" , i);return -EINVAL ;
drivers/gpu/drm/drm_gem_framebuffer_helper.c +55 -5
97 lines not on this page · raw message
include/drm/drm_gem_framebuffer_helper.h +16 -0
@@ -22,6 +22,22 @@ struct drm_size_check {u32 pitch_multiplier[4 ];u32 pitch_modulo;bool use_pitch_multiplier; +void *data; +}; + +/** +* struct drm_afbc - AFBC-specific data. +*/ +struct drm_afbc { +u32 block_width; +u32 block_height; +u32 aligned_width; +u32 aligned_height; +u32 offset; +u32 alignment_header; +u32 afbc_size; +u32 offset_payload; +u32 bpp; }; struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Liviu Dudau
maintainerRe: [PATCHv4 05/36] drm/gem-fb-helper: Add generic afbc size checks
Hi Andrzej,
Quoted 18 lines · Andrzej Pietrasiewicz
Extend the size-checking special function to handle afbc.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- drivers/gpu/drm/drm_fourcc.c | 10 +++- drivers/gpu/drm/drm_framebuffer.c | 3 + drivers/gpu/drm/drm_gem_framebuffer_helper.c | 60 ++++++++++++++++++-- include/drm/drm_gem_framebuffer_helper.h | 16 ++++++ 4 files changed, 82 insertions(+), 7 deletions(-)drivers/gpu/drm/drm_fourcc.c +0
-0@@ -323,8 +323,14 @@ drm_get_format_info(struct drm_device *dev, {const struct drm_format_info *info =NULL ;
drivers/gpu/drm/drm_fourcc.c drm_get_format_info(struct drm_device *dev, · line 333
Quoted 10 lines
drivers/gpu/drm/drm_fourcc.c +8
-2-if (dev->mode_config.funcs->get_format_info) - info = dev->mode_config.funcs->get_format_info (mode_cmd); +/* bypass driver callback if afbc */ +if (!drm_is_afbc (mode_cmd->modifier[0 ])) +if (dev->mode_config.funcs->get_format_info) { +const struct drm_mode_config_funcs *funcs; + + funcs = dev->mode_config.funcs; + info = funcs->get_format_info (mode_cmd); + }
What has this change to do with the rest of the patch? Also, I think this goes against the idea that an AFBC-aware driver might return better data about the format info than the drm_format_info() code.
As a bikeshed, I know it is useful for debugging to turn the oneliner into 3, but it feels like not necessary here.
Best regards,
Liviu
Quoted 152 lines
drivers/gpu/drm/drm_fourcc.c +0
-0if (!info) info =drm_format_info (mode_cmd->pixel_format);drivers/gpu/drm/drm_framebuffer.c +3
-0@@ -204,6 +204,9 @@ static int framebuffer_check(struct drm_device *dev,unsigned int block_size = info->char_per_block[i];u64 min_pitch =drm_format_info_min_pitch (info, i, width); +if (drm_is_afbc (r->modifier[i])) + block_size =0 ; +if (!block_size && (r->modifier[i] ==DRM_FORMAT_MOD_LINEAR )) {DRM_DEBUG_KMS ("Format requires non-linear modifier for plane %d\n" , i);return -EINVAL ;drivers/gpu/drm/drm_gem_framebuffer_helper.c +55
-5@@ -21,6 +21,11 @@#include <drm/drm_modeset_helper.h> #include <drm/drm_simple_kms_helper.h> +#define AFBC_HEADER_SIZE 16 +#define AFBC_TH_LAYOUT_ALIGNMENT 8 +#define AFBC_SUPERBLOCK_PIXELS 256 +#define AFBC_SUPERBLOCK_ALIGNMENT 128 +/** * DOC: overview * @@ -200,6 +205,40 @@ int drm_gem_fb_lookup(struct drm_device *dev, }EXPORT_SYMBOL_GPL (drm_gem_fb_lookup); +static int drm_gem_afbc_min_size (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_afbc *afbc) +{ +u32 n_blocks; + +if (!drm_afbc_get_superblock_wh (mode_cmd->modifier[0 ], + &afbc->block_width, + &afbc->block_height)) { +return -EINVAL ; + } + +/* tiled header afbc */ +if (mode_cmd->modifier[0 ] &AFBC_FORMAT_MOD_TILED ) { + afbc->block_width *=AFBC_TH_LAYOUT_ALIGNMENT ; + afbc->block_height *=AFBC_TH_LAYOUT_ALIGNMENT ; + } + + afbc->aligned_width =ALIGN (mode_cmd->width, afbc->block_width); + afbc->aligned_height =ALIGN (mode_cmd->height, afbc->block_height); + afbc->offset = mode_cmd->offsets[0 ]; + + n_blocks = (afbc->aligned_width * afbc->aligned_height) + /AFBC_SUPERBLOCK_PIXELS ; + afbc->offset_payload =ALIGN (n_blocks *AFBC_HEADER_SIZE , + afbc->alignment_header); + + afbc->afbc_size = afbc->offset_payload + n_blocks * +ALIGN (afbc->bpp *AFBC_SUPERBLOCK_PIXELS /8 , +AFBC_SUPERBLOCK_ALIGNMENT ); + +return 0 ; +} +/** * drm_gem_fb_size_check_special() - Helper function for use in * &drm_mode_config_funcs.fb_create @@ -218,6 +257,7 @@ int drm_gem_fb_size_check_special(struct drm_device *dev,const struct drm_size_check *check, struct drm_gem_object **objs) { +#define CHECK_HAS(field) (check && check->field) const struct drm_format_info *info;int i;@@ -231,24 +271,34 @@ int drm_gem_fb_size_check_special(struct drm_device *dev,unsigned int min_size;u32 pitch = mode_cmd->pitches[i]; -if (check && check->use_pitch_multiplier) +if (CHECK_HAS (use_pitch_multiplier))if ((pitch * check->pitch_multiplier[i]) % check->pitch_modulo)return -EINVAL ; -if (check && check->use_min_size) +if (CHECK_HAS (use_min_size)) { min_size = check->min_size[i]; -else + }else if (CHECK_HAS (data) && +drm_is_afbc (mode_cmd->modifier[0 ])) { +struct drm_afbc *afbc; +int ret; + + afbc = check->data; + ret =drm_gem_afbc_min_size (dev, mode_cmd, afbc); +if (ret <0 ) +return ret; + min_size = ret; + }else { min_size = (height -1 ) * pitch +drm_format_info_min_pitch (info, i, width) + mode_cmd->offsets[i]; - + }if (objs[i]->size < min_size)return -EINVAL ; }return 0 ; - +#undef CHECK_HAS }EXPORT_SYMBOL_GPL (drm_gem_fb_size_check_special);include/drm/drm_gem_framebuffer_helper.h +16
-0@@ -22,6 +22,22 @@ struct drm_size_check {u32 pitch_multiplier[4 ];u32 pitch_modulo;bool use_pitch_multiplier; +void *data; +}; + +/** +* struct drm_afbc - AFBC-specific data. +*/ +struct drm_afbc { +u32 block_width; +u32 block_height; +u32 aligned_width; +u32 aligned_height; +u32 offset; +u32 alignment_header; +u32 afbc_size; +u32 offset_payload; +u32 bpp; }; struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,Signature · 1 line
2.17.1
Signature · 12 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-develRe: [PATCHv4 05/36] drm/gem-fb-helper: Add generic afbc size checks
Hi Liviu,
W dniu 16.12.2019 o 18:19, Liviu Dudau pisze:
Quoted 21 lines
Hi Andrzej,
Quoted 18 lines · Andrzej Pietrasiewicz
Extend the size-checking special function to handle afbc.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- drivers/gpu/drm/drm_fourcc.c | 10 +++- drivers/gpu/drm/drm_framebuffer.c | 3 + drivers/gpu/drm/drm_gem_framebuffer_helper.c | 60 ++++++++++++++++++-- include/drm/drm_gem_framebuffer_helper.h | 16 ++++++ 4 files changed, 82 insertions(+), 7 deletions(-)drivers/gpu/drm/drm_fourcc.c +0
-0@@ -323,8 +323,14 @@ drm_get_format_info(struct drm_device *dev, {const struct drm_format_info *info =NULL ;
Quoted 15 lines
drivers/gpu/drm/drm_fourcc.c drm_get_format_info(struct drm_device *dev, · line 333
Quoted 10 lines
drivers/gpu/drm/drm_fourcc.c +8
-2-if (dev->mode_config.funcs->get_format_info) - info = dev->mode_config.funcs->get_format_info (mode_cmd); +/* bypass driver callback if afbc */ +if (!drm_is_afbc (mode_cmd->modifier[0 ])) +if (dev->mode_config.funcs->get_format_info) { +const struct drm_mode_config_funcs *funcs; + + funcs = dev->mode_config.funcs; + info = funcs->get_format_info (mode_cmd); + }What has this change to do with the rest of the patch? Also, I think this goes against the idea that an AFBC-aware driver might return better data about the format info than the
drm_format_info()code.
The reason is the conclusion of my talk with danvet on irc:
I followed his advice - if I understood him correctly, that is.
Quoted 2 lines
As a bikeshed, I know it is useful for debugging to turn the oneliner into 3, but it feels like not necessary here.
80 chars per line. If kept in one line, the limit is exceeded with an additional indentation level present.
Regards,
Andrzej
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Liviu Dudau
maintainerRe: [PATCHv4 05/36] drm/gem-fb-helper: Add generic afbc size checks
Quoted 39 lines · Andrzej Pietrasiewicz
Hi Liviu,
W dniu 16.12.2019 o 18:19, Liviu Dudau pisze:
Quoted 26 lines
Hi Andrzej,
Quoted 23 lines · Andrzej Pietrasiewicz
Extend the size-checking special function to handle afbc.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- drivers/gpu/drm/drm_fourcc.c | 10 +++- drivers/gpu/drm/drm_framebuffer.c | 3 + drivers/gpu/drm/drm_gem_framebuffer_helper.c | 60 ++++++++++++++++++-- include/drm/drm_gem_framebuffer_helper.h | 16 ++++++ 4 files changed, 82 insertions(+), 7 deletions(-)drivers/gpu/drm/drm_fourcc.c +4
-2@@ -323,8 +323,14 @@ drm_get_format_info(struct drm_device *dev, {const struct drm_format_info *info =NULL ; -if (dev->mode_config.funcs->get_format_info) - info = dev->mode_config.funcs->get_format_info (mode_cmd); +/* bypass driver callback if afbc */ +if (!drm_is_afbc (mode_cmd->modifier[0 ])) +if (dev->mode_config.funcs->get_format_info) { +const struct drm_mode_config_funcs *funcs;Quoted 9 lines
drivers/gpu/drm/drm_fourcc.c drm_get_format_info(struct drm_device *dev, · line 333
Quoted 4 lines
drivers/gpu/drm/drm_fourcc.c +4
-0+ + funcs = dev->mode_config.funcs; + info = funcs->get_format_info (mode_cmd); + }What has this change to do with the rest of the patch? Also, I think this goes against the idea that an AFBC-aware driver might return better data about the format info than the
drm_format_info()code.
Quoted 5 lines
The reason is the conclusion of my talk with danvet on irc:
I followed his advice - if I understood him correctly, that is.
Yeah, I don't necessarily agree with danvet here. I think a better approach is to still let the driver have a say in getting the format info, but if the hook is not present or if it returns NULL then apply the AFBC code before (or as an alternative to) the rest of the generic code.
Quoted 6 lines
Quoted 3 lines
As a bikeshed, I know it is useful for debugging to turn the oneliner into 3, but it feels like not necessary here.
80 chars per line. If kept in one line, the limit is exceeded with an additional indentation level present.
DRM subsystem has never enforced that and there are plenty of instances in the core DRM code where that rule gets ignored. We know that mode_config.funcs is never NULL and that the get_format_info() hook is always populated, so we don't really gain anything from splitting it into multiple lines.
Best regards,
Liviu
Quoted 4 lines
Regards,
Andrzej
Signature · 12 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-develRe: [PATCHv4,05/36] drm/gem-fb-helper: Add generic afbc size checks
In reply to Andrzej PietrasiewiczHi Andrzej:
Quoted 81 lines · Andrzej Pietrasiewicz
Extend the size-checking special function to handle afbc.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- drivers/gpu/drm/drm_fourcc.c | 10 +++- drivers/gpu/drm/drm_framebuffer.c | 3 + drivers/gpu/drm/drm_gem_framebuffer_helper.c | 60 ++++++++++++++++++-- include/drm/drm_gem_framebuffer_helper.h | 16 ++++++ 4 files changed, 82 insertions(+), 7 deletions(-)drivers/gpu/drm/drm_fourcc.c +8
-2@@ -323,8 +323,14 @@ drm_get_format_info(struct drm_device *dev, {const struct drm_format_info *info =NULL ; -if (dev->mode_config.funcs->get_format_info) - info = dev->mode_config.funcs->get_format_info (mode_cmd); +/* bypass driver callback if afbc */ +if (!drm_is_afbc (mode_cmd->modifier[0 ])) +if (dev->mode_config.funcs->get_format_info) { +const struct drm_mode_config_funcs *funcs; + + funcs = dev->mode_config.funcs; + info = funcs->get_format_info (mode_cmd); + }if (!info) info =drm_format_info (mode_cmd->pixel_format);drivers/gpu/drm/drm_framebuffer.c +3
-0@@ -204,6 +204,9 @@ static int framebuffer_check(struct drm_device *dev,unsigned int block_size = info->char_per_block[i];u64 min_pitch =drm_format_info_min_pitch (info, i, width); +if (drm_is_afbc (r->modifier[i])) + block_size =0 ; +if (!block_size && (r->modifier[i] ==DRM_FORMAT_MOD_LINEAR )) {DRM_DEBUG_KMS ("Format requires non-linear modifier for plane %d\n" , i);return -EINVAL ;drivers/gpu/drm/drm_gem_framebuffer_helper.c +21
-0@@ -21,6 +21,11 @@#include <drm/drm_modeset_helper.h> #include <drm/drm_simple_kms_helper.h> +#define AFBC_HEADER_SIZE 16 +#define AFBC_TH_LAYOUT_ALIGNMENT 8 +#define AFBC_SUPERBLOCK_PIXELS 256 +#define AFBC_SUPERBLOCK_ALIGNMENT 128 +/** * DOC: overview * @@ -200,6 +205,40 @@ int drm_gem_fb_lookup(struct drm_device *dev, }EXPORT_SYMBOL_GPL (drm_gem_fb_lookup); +static int drm_gem_afbc_min_size (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_afbc *afbc) +{ +u32 n_blocks; + +if (!drm_afbc_get_superblock_wh (mode_cmd->modifier[0 ], + &afbc->block_width, + &afbc->block_height)) { +return -EINVAL ; + } + +/* tiled header afbc */ +if (mode_cmd->modifier[0 ] &AFBC_FORMAT_MOD_TILED ) { + afbc->block_width *=AFBC_TH_LAYOUT_ALIGNMENT ; + afbc->block_height *=AFBC_TH_LAYOUT_ALIGNMENT ;
drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_lookup(struct drm_device *dev, · line 233
Quoted 10 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +10
-0+ } + + afbc->aligned_width =ALIGN (mode_cmd->width, afbc->block_width); + afbc->aligned_height =ALIGN (mode_cmd->height, afbc->block_height); + afbc->offset = mode_cmd->offsets[0 ]; + + n_blocks = (afbc->aligned_width * afbc->aligned_height) + /AFBC_SUPERBLOCK_PIXELS ; + afbc->offset_payload =ALIGN (n_blocks *AFBC_HEADER_SIZE , + afbc->alignment_header);
After check the references in malidp, rockchip and komeda, seems this afbc->alignment_header is dedicated for komeda only.
This is not true. Per afbc HW spec alignment is essential for all afbc usage. according to the spec the requiremnt are:
AFBC1.0/1.1: 64 byte alignment both for header and body buffer. AFBC1.2 (tiled header enabled): 4096 alignment.
So this alignement is not a vendor specific value, but afbc feature requirement, can be determined by afbc modifier.
(malidp and komeda obeys this spec, not sure about Rockchip, but I think it should be)
But you may see, komeda uses 1024 (not 64) for none-tiled-header afbc, that's because GPU(MALI) changed this value to 1024 for bus performance (sorry I don't know the detail), and komeda changed to 1024 to follow.
Back to display alignment, I think we can just follow the spec, use 64 for none-tiled-header, 4096 for tiled-header, but no need to caller to pass a value.
Quoted 73 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +24
-5+ + afbc->afbc_size = afbc->offset_payload + n_blocks * +ALIGN (afbc->bpp *AFBC_SUPERBLOCK_PIXELS /8 , +AFBC_SUPERBLOCK_ALIGNMENT ); + +return 0 ; +} +/** * drm_gem_fb_size_check_special() - Helper function for use in * &drm_mode_config_funcs.fb_create @@ -218,6 +257,7 @@ int drm_gem_fb_size_check_special(struct drm_device *dev,const struct drm_size_check *check, struct drm_gem_object **objs) { +#define CHECK_HAS(field) (check && check->field) const struct drm_format_info *info;int i;@@ -231,24 +271,34 @@ int drm_gem_fb_size_check_special(struct drm_device *dev,unsigned int min_size;u32 pitch = mode_cmd->pitches[i]; -if (check && check->use_pitch_multiplier) +if (CHECK_HAS (use_pitch_multiplier))if ((pitch * check->pitch_multiplier[i]) % check->pitch_modulo)return -EINVAL ; -if (check && check->use_min_size) +if (CHECK_HAS (use_min_size)) { min_size = check->min_size[i]; -else + }else if (CHECK_HAS (data) && +drm_is_afbc (mode_cmd->modifier[0 ])) { +struct drm_afbc *afbc; +int ret; + + afbc = check->data; + ret =drm_gem_afbc_min_size (dev, mode_cmd, afbc); +if (ret <0 ) +return ret; + min_size = ret; + }else { min_size = (height -1 ) * pitch +drm_format_info_min_pitch (info, i, width) + mode_cmd->offsets[i]; - + }if (objs[i]->size < min_size)return -EINVAL ; }return 0 ; - +#undef CHECK_HAS }EXPORT_SYMBOL_GPL (drm_gem_fb_size_check_special);include/drm/drm_gem_framebuffer_helper.h +6
-0@@ -22,6 +22,22 @@ struct drm_size_check {u32 pitch_multiplier[4 ];u32 pitch_modulo;bool use_pitch_multiplier; +void *data; +}; + +/** +* struct drm_afbc - AFBC-specific data. +*/
include/drm/drm_gem_framebuffer_helper.h struct drm_size_check { · line 40
Quoted 10 lines
include/drm/drm_gem_framebuffer_helper.h +10
-0+struct drm_afbc { +u32 block_width; +u32 block_height; +u32 aligned_width; +u32 aligned_height; +u32 offset; +u32 alignment_header; +u32 afbc_size; +u32 offset_payload; +u32 bpp;
Seems we can remove this bpp if we set the block_size (4x4) for these afbc only formats like DRM_FORMAT_YUV420_8BIT/10BIT in drm_format_info, and then we can calculate the bpp like the pitch calculation, then no need caller to specify bpp anymore, and vendor specific get_bpp() likes in malidp and komeda also can be removed.
for this change maybe we can put it into a new series.
Thanks
James
include/drm/drm_gem_framebuffer_helper.h struct drm_size_check { · line 43
Quoted 3 lines
include/drm/drm_gem_framebuffer_helper.h +0
-0}; struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 6/36 drm/gem-fb-helper: Add method to allocate struct drm_framebuffer
In reply to Andrzej PietrasiewiczSome drivers might want to use the modifier_info field of struct drm_framebuffer to hold struct drm_afbc. The memory for the latter must be managed by the driver. To eliminate the need to modify existing invocations of kfree(fb), add a function to allocate struct drm_framebuffer and its associated struct drm_afbc in one chunk.
--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 32 ++++++++++++++++++++ include/drm/drm_gem_framebuffer_helper.h | 1 + 2 files changed, 33 insertions(+)
drivers/gpu/drm/drm_gem_framebuffer_helper.c +32 -0
@@ -21,6 +21,13 @@#include <drm/drm_modeset_helper.h> #include <drm/drm_simple_kms_helper.h> +#define DRM_ALIGN_MASK (type) \ + (__alignof__(type) - 1) +#define DRM_INFO_OFFSET (type1, type2) \ + ((sizeof(type1) + DRM_ALIGN_MASK(type2)) & ~DRM_ALIGN_MASK(type2)) +#define DRM_COMPOUND_SIZE (type1, type2) \ + (DRM_INFO_OFFSET(type1, type2) + sizeof(type2)) +#define AFBC_HEADER_SIZE 16#define AFBC_TH_LAYOUT_ALIGNMENT 8#define AFBC_SUPERBLOCK_PIXELS 256
@@ -59,6 +66,31 @@ struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, }EXPORT_SYMBOL_GPL (drm_gem_fb_get_obj); +/** +* drm_gem_fb_alloc_with_afbc() - Allocate struct drm_framebuffer together +* with a struct drm_afbc for easier freeing +* and assign drm_framebuffer's modifier_info +* +* Returns: +* Pointer to drm_framebuffer on success or NULL +*/ +struct drm_framebuffer *drm_gem_fb_alloc_with_afbc (void ) +{ +struct drm_framebuffer *fb; + +/* alloc in one chunk to ease freeing */ + fb = kzalloc(DRM_COMPOUND_SIZE(struct drm_framebuffer, struct drm_afbc), +GFP_KERNEL ); +if (!fb) +return NULL ; + + fb->modifier_info = + fb + DRM_INFO_OFFSET(struct drm_framebuffer, struct drm_afbc); + +return fb; +} +EXPORT_SYMBOL_GPL (drm_gem_fb_alloc_with_afbc); + int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb, struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd,
include/drm/drm_gem_framebuffer_helper.h +1 -0
@@ -42,6 +42,7 @@ struct drm_afbc {struct drm_gem_object *drm_gem_fb_get_obj (struct drm_framebuffer *fb,unsigned int plane); +struct drm_framebuffer *drm_gem_fb_alloc_with_afbc (void ); int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb, struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd,
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv4 06/36] drm/gem-fb-helper: Add method to allocate struct drm_framebuffer
Quoted 44 lines · Andrzej Pietrasiewicz
Some drivers might want to use the
modifier_infofield of structdrm_framebufferto hold structdrm_afbc. The memory for the latter must be managed by the driver. To eliminate the need to modify existing invocations of kfree(fb), add a function to allocate structdrm_framebufferand its associated structdrm_afbcin one chunk.Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 32 ++++++++++++++++++++ include/drm/drm_gem_framebuffer_helper.h | 1 + 2 files changed, 33 insertions(+)drivers/gpu/drm/drm_gem_framebuffer_helper.c +17
-0@@ -21,6 +21,13 @@#include <drm/drm_modeset_helper.h> #include <drm/drm_simple_kms_helper.h> +#define DRM_ALIGN_MASK (type) \ + (__alignof__(type) - 1) +#define DRM_INFO_OFFSET (type1, type2) \ + ((sizeof(type1) + DRM_ALIGN_MASK(type2)) & ~DRM_ALIGN_MASK(type2)) +#define DRM_COMPOUND_SIZE (type1, type2) \ + (DRM_INFO_OFFSET(type1, type2) + sizeof(type2)) +#define AFBC_HEADER_SIZE 16#define AFBC_TH_LAYOUT_ALIGNMENT 8#define AFBC_SUPERBLOCK_PIXELS 256@@ -59,6 +66,31 @@ struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, }EXPORT_SYMBOL_GPL (drm_gem_fb_get_obj); +/** +* drm_gem_fb_alloc_with_afbc() - Allocate struct drm_framebuffer together +* with a struct drm_afbc for easier freeing +* and assign drm_framebuffer's modifier_info +* +* Returns: +* Pointer to drm_framebuffer on success or NULL +*/ +struct drm_framebuffer *drm_gem_fb_alloc_with_afbc (void ) +{
drivers/gpu/drm/drm_gem_framebuffer_helper.c struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, · line 88
Quoted 10 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +10
-0+struct drm_framebuffer *fb; + +/* alloc in one chunk to ease freeing */ + fb = kzalloc(DRM_COMPOUND_SIZE(struct drm_framebuffer, struct drm_afbc), +GFP_KERNEL ); +if (!fb) +return NULL ; + + fb->modifier_info = + fb + DRM_INFO_OFFSET(struct drm_framebuffer, struct drm_afbc);
That's not how we do subclassing in general ... (so also no on patch 1). What I mean here is:
struct drm_afbc {
struct drm_framebuffer base;
/* additional afbc information goes here, _not_ into struct
* drm_framebuffer */
}#define drm_framebuffer_to_afbc(fb) container_of(fb, struct drm_afbc, base)
Both probably best stuffed into drm_plane.h
Aside from that style issue I think the core/helper work of this patch series is getting there. But I didn't read the details (and probably wont get to that before the new year because stuff and vacations).
Cheers, Daniel
Quoted 23 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +5
-0+ +return fb; +} +EXPORT_SYMBOL_GPL (drm_gem_fb_alloc_with_afbc); + int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb, struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd,include/drm/drm_gem_framebuffer_helper.h +1
-0@@ -42,6 +42,7 @@ struct drm_afbc {struct drm_gem_object *drm_gem_fb_get_obj (struct drm_framebuffer *fb,unsigned int plane); +struct drm_framebuffer *drm_gem_fb_alloc_with_afbc (void ); int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb, struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd,Signature · 1 line
2.17.1
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
v5 cover Add AFBC support for Rockchip
This series adds AFBC support for Rockchip. It is inspired by:
This is the fifth iteration of the afbc series. Between v3 and v4 a lot of rework has been done, the main goal of which was to move all afbc-related checks to helpers, so that core does not deal with it.
A new struct drm_afbc_framebuffer is added, which stores afbc-related driver-specific data. Because of that, in drivers that wish to use this feature, the struct must be allocated directly in the driver code rather than inside helpers, so the first portion of the patchset does the necessary refactoring.
Then, there are 3 users of afbc: komeda, malidp and, finally, rockchip, the latter being the ultimate purpose of this work and the 3 subsequent portions of the patchset move komeda and malidp to generic helpers and add afbc support to rockchip.
The idea is to make all afbc users follow a similar pattern. In fb_create() they allocate struct drm_afbc_framebuffer, do their specific checks which can be done before object lookups, do object lookups and a special version of a size check, which understands struct drm_afbc_framebuffer, followed by any other driver-specific checks and initializing the gem object. The helpers for the common parts are factored out so that drivers can use them.
The komeda driver has been the farthest away from such a pattern, so it required most changes. However, due to the fact that I don't have any komeda hardware I did the changes to komeda in an incremental fashion with a series of (usually) very small, easy to understand steps. malidp was pretty straightforward, and rockchip's afbc checks follow the pattern.
I kindly ask for reviewing the series. I need to mention that my ultimate goal is merging afbc for rockchip and I don't have other hardware, so some help from malidp and komeda developers/maintainers would be appreciated.
@Liviu, @James, @Mihail, @Brian: a kind request to you to have a look and test the patchset, as I don't have appropriate hardware.
Rebased onto drm-misc-next.
v4..v5:
- used proper way of subclassing drm_framebuffer (Daniel Vetter)
- added documentation to exported functions (Liviu Dudau)
- reordered new functions in drm_gem_framebuffer_helper.c to make a saner diff (Liviu Dudau)
- used "2" suffix instead of "_special" for the special version of size checks (Liviu Dudau)
- dropped unnecessarily added condition in drm_get_format_info() (Liviu Dudau)
- dropped "block_size = 0;" trick in framebuffer_check() (Daniel Vetter)
- relaxed sticking to 80 characters per line rule in some cases
v3..v4:
- addressed (some) comments from Daniel Stone, Ezequiel Garcia, Daniel Vetter and James Qian Wang - thank you for input
- refactored helpers to ease accommodating drivers with afbc needs
- moved afbc checks to helpers
- converted komeda, malidp and (the newly added) rockchip to use the afbc helpers
- eliminated a separate, dedicated source code file
v2..v3:
- addressed (some) comments from Daniel Stone, Liviu Dudau, Daniel Vetter and Brian Starkey - thank you all
In this iteration some rework has been done. The checking logic is now moved to framebuffer_check() so it is common to all drivers. But the common part is not good for komeda, so this series is not good for merging yet. I kindly ask for feedback whether the changes are in the right direction. I also kindly ask for input on how to accommodate komeda.
The CONFIG_DRM_AFBC option has been eliminated in favour of adding drm_afbc.c to drm_kms_helper.
v1..v2:
- addressed comments from Daniel Stone, Ayan Halder, Mihail Atanassov
- coding style fixes** BLURB HERE ***
Andrzej Pietrasiewicz (34):
drm/core: Add afbc helper functions
drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on
their own
drm/gem-fb-helper: Add special version of drm_gem_fb_size_check drm/gem-fb-helper: Add generic afbc size checks drm/komeda: Use afbc helper
drm/komeda: Move checking src coordinates to komeda_fb_create drm/komeda: Use the already available local variable drm/komeda: Retrieve drm_format_info once
drm/komeda: Explicitly require 1 plane for AFBC drm/komeda: Move pitches comparison to komeda_fb_create drm/komeda: Provide and use komeda_fb_get_pixel_addr variant not
requiring a fb
drm/komeda: Factor out object lookups for non-afbc case drm/komeda: Make komeda_fb_none_size_check independent from
framebuffer
drm/komeda: Factor out object lookups for afbc case drm/komeda: Free komeda_fb_afbc_size_check from framebuffer dependency drm/komeda: Simplify error handling
drm/komeda: Move object lookup before size checks drm/komeda: Move object assignments to framebuffer to after size
checks
drm/komeda: Make the size checks independent from framebuffer
structure
drm/komeda: Move helper invocation to after size checks drm/komeda: Use helper for common tasks
drm/komeda: Use return value of drm_gem_fb_lookup drm/komeda: Use special helper for non-afbc size checks drm/komeda: Factor in the invocation of special helper drm/komeda: Use special helper for afbc case size check drm/komeda: Factor in the invocation of special helper, afbc case drm/komeda: Move special helper invocation outside if-else drm/komeda: Move to helper checking afbc buffer size drm/arm/malidp: Make verify funcitons invocations independent drm/arm/malidp: Integrate verify functions
drm/arm/malidp: Factor in afbc framebuffer verification drm/arm/malidp: Use generic helpers for afbc checks drm/rockchip: Use helper for common task
drm/rockchip: Add support for afbc
.../arm/display/komeda/d71/d71_component.c | 6 +- .../arm/display/komeda/komeda_framebuffer.c | 273 ++++++++--------- .../arm/display/komeda/komeda_framebuffer.h | 21 +- .../display/komeda/komeda_pipeline_state.c | 14 +- drivers/gpu/drm/arm/malidp_drv.c | 155 ++++------ drivers/gpu/drm/drm_fourcc.c | 53 ++++ drivers/gpu/drm/drm_gem_framebuffer_helper.c | 287 ++++++++++++++---- drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 111 ++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 147 ++++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop.h | 12 + drivers/gpu/drm/rockchip/rockchip_vop_reg.c | 83 ++++- include/drm/drm_fourcc.h | 4 + include/drm/drm_framebuffer.h | 50 +++ include/drm/drm_gem_framebuffer_helper.h | 34 +++ 14 files changed, 907 insertions(+), 343 deletions(-)
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 1/34 drm/core: Add afbc helper functions
Add checking if a modifier is afbc and getting afbc block size.
--- drivers/gpu/drm/drm_fourcc.c | 53 ++++++++++++++++++++++++++++++++++++ include/drm/drm_fourcc.h | 4 +++ 2 files changed, 57 insertions(+)
drivers/gpu/drm/drm_fourcc.c +53 -0
@@ -29,6 +29,7 @@#include <drm/drm_device.h> #include <drm/drm_fourcc.h> +#include <drm/drm_print.h> static char printable_char (int c) {
@@ -393,3 +394,55 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, drm_format_info_block_height(info, plane)); }EXPORT_SYMBOL (drm_format_info_min_pitch); + +/** +* drm_is_afbc - test if the modifier describes an afbc buffer +* @modifier - modifier to be tested +* +* Returns: true if the modifier describes an afbc buffer +*/ +bool drm_is_afbc (u64 modifier) +{ +/* is it ARM AFBC? */ +if ((modifier &DRM_FORMAT_MOD_ARM_AFBC (0 )) ==0 ) +return false; + +/* Block size must be known */ +if ((modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ) ==0 ) +return false; + +return true; +} +EXPORT_SYMBOL_GPL (drm_is_afbc); + +/** +* drm_afbc_get_superblock_wh - extract afbc block width/height from modifier +* @modifier: the modifier to be looked at +* @w: address of a place to store the block width +* @h: address of a place to store the block height +* +* Returns: true if the modifier describes a supported block size +*/ +bool drm_afbc_get_superblock_wh (u64 modifier,u32 *w,u32 *h) +{ +switch (modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ) { +case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16: + *w =16 ; + *h =16 ; +break ; +case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8: + *w =32 ; + *h =8 ; +break ; +case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4: +/* fall through */ +case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4: +/* fall through */ +default : +DRM_DEBUG_KMS ("Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n" , + modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ); +return false; + } +return true; +} +EXPORT_SYMBOL_GPL (drm_afbc_get_superblock_wh);
include/drm/drm_fourcc.h +4 -0
@@ -320,4 +320,8 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, int plane, unsigned int buffer_width);const char *drm_get_format_name (uint32_t format,struct drm_format_name_buf *buf); +bool drm_is_afbc (u64 modifier); + +bool drm_afbc_get_superblock_wh (u64 modifier,u32 *w,u32 *h); +#endif /* __DRM_FOURCC_H__ */
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv5 01/34] drm/core: Add afbc helper functions
Hi Andrzej:
Quoted 30 lines · Andrzej Pietrasiewicz
Add checking if a modifier is afbc and getting afbc block size.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- drivers/gpu/drm/drm_fourcc.c | 53 ++++++++++++++++++++++++++++++++++++ include/drm/drm_fourcc.h | 4 +++ 2 files changed, 57 insertions(+)drivers/gpu/drm/drm_fourcc.c +7
-0@@ -29,6 +29,7 @@#include <drm/drm_device.h> #include <drm/drm_fourcc.h> +#include <drm/drm_print.h> static char printable_char (int c) {@@ -393,3 +394,55 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, drm_format_info_block_height(info, plane)); }EXPORT_SYMBOL (drm_format_info_min_pitch); + +/** +* drm_is_afbc - test if the modifier describes an afbc buffer +* @modifier - modifier to be tested +* +* Returns: true if the modifier describes an afbc buffer
drivers/gpu/drm/drm_fourcc.c uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, · line 412
Quoted 10 lines
drivers/gpu/drm/drm_fourcc.c +10
-0+*/ +bool drm_is_afbc (u64 modifier) +{ +/* is it ARM AFBC? */ +if ((modifier &DRM_FORMAT_MOD_ARM_AFBC (0 )) ==0 ) +return false; + +/* Block size must be known */ +if ((modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ) ==0 ) +return false;
Do we really need this block size check here ?
Since modifier with ARM AFBC modifier but have no BLOCK_SIZE which should be an error, but this check returns such error to NONE-AFBC.
And I saw you already have such error check in func get_superblock_wh(), so I think we can del this size check in this func.
James.
Quoted 51 lines
drivers/gpu/drm/drm_fourcc.c +36
-0+ +return true; +} +EXPORT_SYMBOL_GPL (drm_is_afbc); + +/** +* drm_afbc_get_superblock_wh - extract afbc block width/height from modifier +* @modifier: the modifier to be looked at +* @w: address of a place to store the block width +* @h: address of a place to store the block height +* +* Returns: true if the modifier describes a supported block size +*/ +bool drm_afbc_get_superblock_wh (u64 modifier,u32 *w,u32 *h) +{ +switch (modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ) { +case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16: + *w =16 ; + *h =16 ; +break ; +case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8: + *w =32 ; + *h =8 ; +break ; +case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4: +/* fall through */ +case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4: +/* fall through */ +default : +DRM_DEBUG_KMS ("Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n" , + modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ); +return false; + } +return true; +} +EXPORT_SYMBOL_GPL (drm_afbc_get_superblock_wh);include/drm/drm_fourcc.h +4
-0@@ -320,4 +320,8 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, int plane, unsigned int buffer_width);const char *drm_get_format_name (uint32_t format,struct drm_format_name_buf *buf); +bool drm_is_afbc (u64 modifier); + +bool drm_afbc_get_superblock_wh (u64 modifier,u32 *w,u32 *h); +#endif /* __DRM_FOURCC_H__ */ Signature · 1 line
2.17.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv5 01/34] drm/core: Add afbc helper functions
In reply to Andrzej PietrasiewiczQuoted 25 lines · On Tue, 17 Dec 2019 15:49:47 +0100 Andrzej Pietrasiewicz…
Add checking if a modifier is afbc and getting afbc block size.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- drivers/gpu/drm/drm_fourcc.c | 53 ++++++++++++++++++++++++++++++++++++ include/drm/drm_fourcc.h | 4 +++ 2 files changed, 57 insertions(+)drivers/gpu/drm/drm_fourcc.c +2
-0@@ -29,6 +29,7 @@#include <drm/drm_device.h> #include <drm/drm_fourcc.h> +#include <drm/drm_print.h> static char printable_char (int c) {@@ -393,3 +394,55 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, drm_format_info_block_height(info, plane)); }EXPORT_SYMBOL (drm_format_info_min_pitch); +
drivers/gpu/drm/drm_fourcc.c uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, · line 407
Quoted 10 lines
drivers/gpu/drm/drm_fourcc.c +10
-0+/** +* drm_is_afbc - test if the modifier describes an afbc buffer +* @modifier - modifier to be tested +* +* Returns: true if the modifier describes an afbc buffer +*/ +bool drm_is_afbc (u64 modifier) +{ +/* is it ARM AFBC? */ +if ((modifier &DRM_FORMAT_MOD_ARM_AFBC (0 )) ==0 )
Hm, it's not doing what you describe. The test should be something like
#define VENDOR_AND_TYPE_MASK GENMASK_ULL(63, 52)
if ((mod & VENDOR_AND_TYPE_MASK) == DRM_FORMAT_MOD_ARM_AFBC(0))
Quoted 23 lines
drivers/gpu/drm/drm_fourcc.c +23
-0+return false; + +/* Block size must be known */ +if ((modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ) ==0 ) +return false; + +return true; +} +EXPORT_SYMBOL_GPL (drm_is_afbc); + +/** +* drm_afbc_get_superblock_wh - extract afbc block width/height from modifier +* @modifier: the modifier to be looked at +* @w: address of a place to store the block width +* @h: address of a place to store the block height +* +* Returns: true if the modifier describes a supported block size +*/ +bool drm_afbc_get_superblock_wh (u64 modifier,u32 *w,u32 *h) +{ +switch (modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ) { +case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16: + *w =16 ;
drivers/gpu/drm/drm_fourcc.c uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, · line 440
Quoted 10 lines
drivers/gpu/drm/drm_fourcc.c +10
-0+ *h =16 ; +break ; +case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8: + *w =32 ; + *h =8 ; +break ; +case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4: +/* fall through */ +case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4: +/* fall through */
Any reason for not supporting those block sizes? It probably deserves a comment, and a mention in the commit message.
Quoted 13 lines
drivers/gpu/drm/drm_fourcc.c +8
-0+default : +DRM_DEBUG_KMS ("Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n" , + modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ); +return false; + } +return true; +} +EXPORT_SYMBOL_GPL (drm_afbc_get_superblock_wh);include/drm/drm_fourcc.h +0
-0
include/drm/drm_fourcc.h uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, · line 327
Quoted 8 lines
include/drm/drm_fourcc.h +4
-0@@ -320,4 +320,8 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, int plane, unsigned int buffer_width);const char *drm_get_format_name (uint32_t format,struct drm_format_name_buf *buf); +bool drm_is_afbc (u64 modifier); + +bool drm_afbc_get_superblock_wh (u64 modifier,u32 *w,u32 *h); +#endif /* __DRM_FOURCC_H__ */
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv5 01/34] drm/core: Add afbc helper functions
In reply to Andrzej Pietrasiewiczdrivers/gpu/drm/drm_fourcc.c uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, · line 426
Quoted 9 lines · On Tue, 17 Dec 2019 15:49:47 +0100 Andrzej Pietrasiewicz…
drivers/gpu/drm/drm_fourcc.c +9
-0+/** +* drm_afbc_get_superblock_wh - extract afbc block width/height from modifier +* @modifier: the modifier to be looked at +* @w: address of a place to store the block width +* @h: address of a place to store the block height +* +* Returns: true if the modifier describes a supported block size +*/ +bool drm_afbc_get_superblock_wh (u64 modifier,u32 *w,u32 *h)
You should probably take the multiplane case into account now. Maybe introduce the following struct and pass a pointer to such a struct instead of the w/h pointers:
struct afbc_block_size {
struct {
u32 w;
u32 h;
} plane[2];
};Note that you could also directly return a
const struct afbc_block_size * and consider the NULL case as 'invalid format'.
Quoted 4 lines
drivers/gpu/drm/drm_fourcc.c +4
-0+{ +switch (modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ) { +case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16: + *w =16 ;
drivers/gpu/drm/drm_fourcc.c uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, · line 440
Quoted 10 lines
drivers/gpu/drm/drm_fourcc.c +10
-0+ *h =16 ; +break ; +case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8: + *w =32 ; + *h =8 ; +break ; +case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4: +/* fall through */ +case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4: +/* fall through */
I guess display controllers might support a subset of what's actually defined in the spec, so maybe it makes sense to pass a 'const u8 *supported_block_sizes' and then do something like:
block_size_id = modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK;
for (i = 0; i < num_supported_block_sizes; i++) {
if (supported_block_sizes[i] == block_size_id)
break;
}
if (i == num_supported_block_sizes)
return false;The above switch-case can also be replaced by an array of structs encoding the block size:
static const struct afbc_block_size block_sizes[] = {
[AFBC_FORMAT_MOD_BLOCK_SIZE_16x16] = { { 16, 16 } },
[AFBC_FORMAT_MOD_BLOCK_SIZE_32x8] = { { 32, 8 } },
[AFBC_FORMAT_MOD_BLOCK_SIZE_64x4] = { { 64, 4 } },
[AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4] = { { 32, 8 }, { 64, 4} },
};
*block_size = block_sizes[block_size_id];
return true;drivers/gpu/drm/drm_fourcc.c uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, · line 447
Quoted 7 lines
drivers/gpu/drm/drm_fourcc.c +7
-0+default : +DRM_DEBUG_KMS ("Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n" , + modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ); +return false; + } +return true; +}
To sum-up, this would give something like (not even compile-tested):
struct afbc_block_size {
struct {
u32 width;
u32 height;
} plane[2];
};static const struct afbc_block_size superblock_sizes[] = {
[AFBC_FORMAT_MOD_BLOCK_SIZE_16x16] = { { 16, 16 } },
[AFBC_FORMAT_MOD_BLOCK_SIZE_32x8] = { { 32, 8 } },
[AFBC_FORMAT_MOD_BLOCK_SIZE_64x4] = { { 64, 4 } },
[AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4] = { { 32, 8 }, { 64, 4} },
};const struct afbc_block_size * drm_afbc_get_superblock_info(u64 modifier,
const u8 *supported_sb_sizes, unsigned int num_supported_sb_sizes)
{
u8 block_size_id = modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK;
if (!block_size_id ||
block_size_id >= ARRAY_SIZE(superblock_sizes)) {
DRM_DEBUG_KMS("Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n",
modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK);
return NULL;
}
for (i = 0; i < num_supported_sb_sizes; i++) {
if (supported_sb_sizes[i] == block_size_id)
break;
}
if (i == num_supported_sb_sizes) {
DRM_DEBUG_KMS("Unsupported AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n",
modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK);
return NULL;
}
return &superblock_sizes[block_size_id];
}_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 2/34 drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own
In reply to Andrzej PietrasiewiczPrepare tools for drivers which need to allocate a struct drm_framebuffer (or a container of struct drm_framebuffer) explicitly, before calling helpers. In such a case we need new helpers which omit allocating the struct drm_framebuffer and this patch provides them. Consequently, they are used also inside the helpers themselves.
The interested drivers will likely need to be able to perform object lookups and size checks in separate invocations and this patch provides that as well. Helpers themselves are updated, too.
--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 216 ++++++++++++++----- include/drm/drm_gem_framebuffer_helper.h | 17 ++ 2 files changed, 181 insertions(+), 52 deletions(-)
drivers/gpu/drm/drm_gem_framebuffer_helper.c +164 -52
@@ -54,6 +54,69 @@ struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, }EXPORT_SYMBOL_GPL (drm_gem_fb_get_obj); +/** +* drm_gem_fb_init_with_funcs() - Initialize an already allocated framebuffer +* @fb: Framebuffer +* @dev: DRM device +* @mode_cmd: Metadata from the userspace framebuffer creation request +* @obj: GEM objects to be assigned to the framebuffer +* @num_planes: number of planes +* @funcs: vtable to be used for the framebuffer object +* +* This variant of the function allows passing a custom vtable. +* +* Returns: +* 0 on success or a negative error code +*/ +int drm_gem_fb_init_with_funcs (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj, +unsigned int num_planes, +const struct drm_framebuffer_funcs *funcs) +{ +int ret, i; + +drm_helper_mode_fill_fb_struct (dev, fb, mode_cmd); + +for (i =0 ; i < num_planes; i++) + fb->obj[i] = obj[i]; + + ret =drm_framebuffer_init (dev, fb, funcs); +if (ret) +DRM_DEV_ERROR (dev->dev,"Failed to init framebuffer: %d\n" , ret); + +return ret; +} +EXPORT_SYMBOL_GPL (drm_gem_fb_init_with_funcs); + +static const struct drm_framebuffer_funcs drm_gem_fb_funcs = { + .destroy = drm_gem_fb_destroy, + .create_handle = drm_gem_fb_create_handle, +}; + +/** +* drm_gem_fb_init() - Initialize an already allocated framebuffer +* @fb: Framebuffer +* @dev: DRM device +* @mode_cmd: Metadata from the userspace framebuffer creation request +* @obj: GEM objects to be assigned to the framebuffer +* @num_planes: number of planes +* +* This variant of the function uses a default vtable. +* +* Returns: +* 0 on success or a negative error code +*/ +int drm_gem_fb_init (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj,unsigned int num_planes) +{ +return drm_gem_fb_init_with_funcs (fb, dev, mode_cmd, obj, num_planes, &drm_gem_fb_funcs); +} +EXPORT_SYMBOL_GPL (drm_gem_fb_init); +static struct drm_framebuffer * drm_gem_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd,
@@ -61,21 +124,14 @@ drm_gem_fb_alloc(struct drm_device *dev, const struct drm_framebuffer_funcs *funcs) {struct drm_framebuffer *fb; -int ret, i; +int ret; fb =kzalloc (sizeof (*fb),GFP_KERNEL );if (!fb)return ERR_PTR (-ENOMEM ); -drm_helper_mode_fill_fb_struct (dev, fb, mode_cmd); - -for (i =0 ; i < num_planes; i++) - fb->obj[i] = obj[i]; - - ret =drm_framebuffer_init (dev, fb, funcs); + ret =drm_gem_fb_init_with_funcs (fb, dev, mode_cmd, obj, num_planes, funcs);if (ret) { -DRM_DEV_ERROR (dev->dev,"Failed to init framebuffer: %d\n" , - ret);kfree (fb);return ERR_PTR (ret); }
@@ -144,59 +200,29 @@ drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd, const struct drm_framebuffer_funcs *funcs) { - const struct drm_format_info *info; struct drm_gem_object *objs[4];struct drm_framebuffer *fb; -int ret, i; - - info =drm_get_format_info (dev, mode_cmd); -if (!info) -return ERR_PTR (-EINVAL ); - -for (i =0 ; i < info->num_planes; i++) { -unsigned int width = mode_cmd->width / (i ? info->hsub :1 ); -unsigned int height = mode_cmd->height / (i ? info->vsub :1 ); -unsigned int min_size; +int ret, num_planes; - objs[i] =drm_gem_object_lookup (file, mode_cmd->handles[i]); -if (!objs[i]) { -DRM_DEBUG_KMS ("Failed to lookup GEM object\n" ); - ret = -ENOENT ; - goto err_gem_object_put; - } - - min_size = (height -1 ) * mode_cmd->pitches[i] - +drm_format_info_min_pitch (info, i, width) - + mode_cmd->offsets[i]; + ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); +if (ret <0 ) +return ERR_PTR (ret); + num_planes = ret; -if (objs[i]->size < min_size) { -drm_gem_object_put_unlocked (objs[i]); - ret = -EINVAL ; - goto err_gem_object_put; - } - } + ret =drm_gem_fb_size_check (dev, mode_cmd, objs); +if (ret) + fb =ERR_PTR (ret); +else + fb =drm_gem_fb_alloc (dev, mode_cmd, objs, num_planes, funcs); - fb =drm_gem_fb_alloc (dev, mode_cmd, objs, i, funcs); -if (IS_ERR (fb)) { - ret =PTR_ERR (fb); - goto err_gem_object_put; - } +if (IS_ERR (fb)) +for (num_planes--; num_planes >=0 ; num_planes--) +drm_gem_object_put_unlocked (objs[num_planes]);return fb; - -err_gem_object_put: -for (i--; i >=0 ; i--) -drm_gem_object_put_unlocked (objs[i]); - -return ERR_PTR (ret); }EXPORT_SYMBOL_GPL (drm_gem_fb_create_with_funcs); -static const struct drm_framebuffer_funcs drm_gem_fb_funcs = { - .destroy = drm_gem_fb_destroy, - .create_handle = drm_gem_fb_create_handle, -}; -/** * drm_gem_fb_create() - Helper function for the * &drm_mode_config_funcs.fb_create callback
@@ -228,6 +254,92 @@ drm_gem_fb_create(struct drm_device *dev, struct drm_file *file, }EXPORT_SYMBOL_GPL (drm_gem_fb_create); +/** +* drm_gem_fb_lookup() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations +* @dev: DRM device +* @file: DRM file that holds the GEM handle(s) backing the framebuffer +* @mode_cmd: Metadata from the userspace framebuffer creation request +* +* This function can be used to look up the objects for all planes. +* In case an error is returned all the objects are put by the +* function before returning. +* +* Returns: +* Number of planes on success or a negative error code on failure. +*/ +int drm_gem_fb_lookup (struct drm_device *dev, +struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs) +{ +const struct drm_format_info *info; +int ret, i; + + info =drm_get_format_info (dev, mode_cmd); +if (!info) +return -EINVAL ; + +for (i =0 ; i < info->num_planes; i++) { + objs[i] =drm_gem_object_lookup (file, mode_cmd->handles[i]); +if (!objs[i]) { +DRM_DEBUG_KMS ("Failed to lookup GEM object\n" ); + ret = -ENOENT ; + goto err_gem_object_put; + } + } + +return i; + +err_gem_object_put: +for (i--; i >=0 ; i--) +drm_gem_object_put_unlocked (objs[i]); + +return ret; +} +EXPORT_SYMBOL_GPL (drm_gem_fb_lookup); + +/** +* drm_gem_fb_size_check() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations +* @dev: DRM device +* @mode_cmd: Metadata from the userspace framebuffer creation request +* +* This function can be used to verify buffer sizes for all planes. +* It is caller's responsibility to put the objects on failure. +* +* Returns: +* Zero on success or a negative error code on failure. +*/ +int drm_gem_fb_size_check (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs) +{ +const struct drm_format_info *info; +int i; + + info =drm_get_format_info (dev, mode_cmd); +if (!info) +return -EINVAL ; + +for (i =0 ; i < info->num_planes; i++) { +unsigned int width = mode_cmd->width / (i ? info->hsub :1 ); +unsigned int height = mode_cmd->height / (i ? info->vsub :1 ); +unsigned int min_size; + + min_size = (height -1 ) * mode_cmd->pitches[i] + +drm_format_info_min_pitch (info, i, width) + + mode_cmd->offsets[i]; + +if (objs[i]->size < min_size) +return -EINVAL ; + } + +return 0 ; + +} +EXPORT_SYMBOL_GPL (drm_gem_fb_size_check); +static const struct drm_framebuffer_funcs drm_gem_fb_funcs_dirtyfb = { .destroy = drm_gem_fb_destroy, .create_handle = drm_gem_fb_create_handle,
include/drm/drm_gem_framebuffer_helper.h +17 -0
@@ -14,10 +14,27 @@ struct drm_simple_display_pipe;struct drm_gem_object *drm_gem_fb_get_obj (struct drm_framebuffer *fb,unsigned int plane); +int drm_gem_fb_init_with_funcs (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj, +unsigned int num_planes, +const struct drm_framebuffer_funcs *funcs); +int drm_gem_fb_init (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj,unsigned int num_planes);void drm_gem_fb_destroy (struct drm_framebuffer *fb);int drm_gem_fb_create_handle (struct drm_framebuffer *fb,struct drm_file *file,unsigned int *handle); +int drm_gem_fb_lookup (struct drm_device *dev, +struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs); +int drm_gem_fb_size_check (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs);struct drm_framebuffer * drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd,
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv5 02/34] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own
Hi Andrzej:
Quoted 196 lines · Andrzej Pietrasiewicz
Prepare tools for drivers which need to allocate a struct
drm_framebuffer(or a container of structdrm_framebuffer) explicitly, before calling helpers. In such a case we need new helpers which omit allocating the structdrm_framebufferand this patch provides them. Consequently, they are used also inside the helpers themselves.The interested drivers will likely need to be able to perform object lookups and size checks in separate invocations and this patch provides that as well. Helpers themselves are updated, too.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 216 ++++++++++++++----- include/drm/drm_gem_framebuffer_helper.h | 17 ++ 2 files changed, 181 insertions(+), 52 deletions(-)drivers/gpu/drm/drm_gem_framebuffer_helper.c +83
-52@@ -54,6 +54,69 @@ struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, }EXPORT_SYMBOL_GPL (drm_gem_fb_get_obj); +/** +* drm_gem_fb_init_with_funcs() - Initialize an already allocated framebuffer +* @fb: Framebuffer +* @dev: DRM device +* @mode_cmd: Metadata from the userspace framebuffer creation request +* @obj: GEM objects to be assigned to the framebuffer +* @num_planes: number of planes +* @funcs: vtable to be used for the framebuffer object +* +* This variant of the function allows passing a custom vtable. +* +* Returns: +* 0 on success or a negative error code +*/ +int drm_gem_fb_init_with_funcs (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj, +unsigned int num_planes, +const struct drm_framebuffer_funcs *funcs) +{ +int ret, i; + +drm_helper_mode_fill_fb_struct (dev, fb, mode_cmd); + +for (i =0 ; i < num_planes; i++) + fb->obj[i] = obj[i]; + + ret =drm_framebuffer_init (dev, fb, funcs); +if (ret) +DRM_DEV_ERROR (dev->dev,"Failed to init framebuffer: %d\n" , ret); + +return ret; +} +EXPORT_SYMBOL_GPL (drm_gem_fb_init_with_funcs); + +static const struct drm_framebuffer_funcs drm_gem_fb_funcs = { + .destroy = drm_gem_fb_destroy, + .create_handle = drm_gem_fb_create_handle, +}; + +/** +* drm_gem_fb_init() - Initialize an already allocated framebuffer +* @fb: Framebuffer +* @dev: DRM device +* @mode_cmd: Metadata from the userspace framebuffer creation request +* @obj: GEM objects to be assigned to the framebuffer +* @num_planes: number of planes +* +* This variant of the function uses a default vtable. +* +* Returns: +* 0 on success or a negative error code +*/ +int drm_gem_fb_init (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj,unsigned int num_planes) +{ +return drm_gem_fb_init_with_funcs (fb, dev, mode_cmd, obj, num_planes, &drm_gem_fb_funcs); +} +EXPORT_SYMBOL_GPL (drm_gem_fb_init); +static struct drm_framebuffer * drm_gem_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd,@@ -61,21 +124,14 @@ drm_gem_fb_alloc(struct drm_device *dev, const struct drm_framebuffer_funcs *funcs) {struct drm_framebuffer *fb; -int ret, i; +int ret; fb =kzalloc (sizeof (*fb),GFP_KERNEL );if (!fb)return ERR_PTR (-ENOMEM ); -drm_helper_mode_fill_fb_struct (dev, fb, mode_cmd); - -for (i =0 ; i < num_planes; i++) - fb->obj[i] = obj[i]; - - ret =drm_framebuffer_init (dev, fb, funcs); + ret =drm_gem_fb_init_with_funcs (fb, dev, mode_cmd, obj, num_planes, funcs);if (ret) { -DRM_DEV_ERROR (dev->dev,"Failed to init framebuffer: %d\n" , - ret);kfree (fb);return ERR_PTR (ret); }@@ -144,59 +200,29 @@ drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd, const struct drm_framebuffer_funcs *funcs) { - const struct drm_format_info *info; struct drm_gem_object *objs[4];struct drm_framebuffer *fb; -int ret, i; - - info =drm_get_format_info (dev, mode_cmd); -if (!info) -return ERR_PTR (-EINVAL ); - -for (i =0 ; i < info->num_planes; i++) { -unsigned int width = mode_cmd->width / (i ? info->hsub :1 ); -unsigned int height = mode_cmd->height / (i ? info->vsub :1 ); -unsigned int min_size; +int ret, num_planes; - objs[i] =drm_gem_object_lookup (file, mode_cmd->handles[i]); -if (!objs[i]) { -DRM_DEBUG_KMS ("Failed to lookup GEM object\n" ); - ret = -ENOENT ; - goto err_gem_object_put; - } - - min_size = (height -1 ) * mode_cmd->pitches[i] - +drm_format_info_min_pitch (info, i, width) - + mode_cmd->offsets[i]; + ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); +if (ret <0 ) +return ERR_PTR (ret); + num_planes = ret; -if (objs[i]->size < min_size) { -drm_gem_object_put_unlocked (objs[i]); - ret = -EINVAL ; - goto err_gem_object_put; - } - } + ret =drm_gem_fb_size_check (dev, mode_cmd, objs); +if (ret) + fb =ERR_PTR (ret); +else + fb =drm_gem_fb_alloc (dev, mode_cmd, objs, num_planes, funcs); - fb =drm_gem_fb_alloc (dev, mode_cmd, objs, i, funcs); -if (IS_ERR (fb)) { - ret =PTR_ERR (fb); - goto err_gem_object_put; - } +if (IS_ERR (fb)) +for (num_planes--; num_planes >=0 ; num_planes--) +drm_gem_object_put_unlocked (objs[num_planes]);return fb; - -err_gem_object_put: -for (i--; i >=0 ; i--) -drm_gem_object_put_unlocked (objs[i]); - -return ERR_PTR (ret); }EXPORT_SYMBOL_GPL (drm_gem_fb_create_with_funcs); -static const struct drm_framebuffer_funcs drm_gem_fb_funcs = { - .destroy = drm_gem_fb_destroy, - .create_handle = drm_gem_fb_create_handle, -}; -/** * drm_gem_fb_create() - Helper function for the * &drm_mode_config_funcs.fb_create callback @@ -228,6 +254,92 @@ drm_gem_fb_create(struct drm_device *dev, struct drm_file *file, }EXPORT_SYMBOL_GPL (drm_gem_fb_create); +/** +* drm_gem_fb_lookup() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations +* @dev: DRM device +* @file: DRM file that holds the GEM handle(s) backing the framebuffer
drivers/gpu/drm/drm_gem_framebuffer_helper.c drm_gem_fb_create(struct drm_device *dev, struct drm_file *file, · line 271
Quoted 10 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +10
-0+* @mode_cmd: Metadata from the userspace framebuffer creation request +* +* This function can be used to look up the objects for all planes. +* In case an error is returned all the objects are put by the +* function before returning. +* +* Returns: +* Number of planes on success or a negative error code on failure. +*/ +int drm_gem_fb_lookup(struct drm_device *dev,
[nit-pick] How about name it to drm_gem_fb_objs_lookup() ?
Quoted 96 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +71
-0+struct drm_file *file, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **objs) +{ + const struct drm_format_info *info; +int ret, i; + + info =drm_get_format_info (dev, mode_cmd); +if (!info) +return -EINVAL ; + +for (i =0 ; i < info->num_planes; i++) { + objs[i] =drm_gem_object_lookup (file, mode_cmd->handles[i]); +if (!objs[i]) { +DRM_DEBUG_KMS ("Failed to lookup GEM object\n" ); + ret = -ENOENT ; + goto err_gem_object_put; + } + } + +return i; + +err_gem_object_put: +for (i--; i >=0 ; i--) +drm_gem_object_put_unlocked (objs[i]); + +return ret; +} +EXPORT_SYMBOL_GPL (drm_gem_fb_lookup); + +/** +* drm_gem_fb_size_check() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations +* @dev: DRM device +* @mode_cmd: Metadata from the userspace framebuffer creation request +* +* This function can be used to verify buffer sizes for all planes. +* It is caller's responsibility to put the objects on failure. +* +* Returns: +* Zero on success or a negative error code on failure. +*/ +int drm_gem_fb_size_check (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs) +{ +const struct drm_format_info *info; +int i; + + info =drm_get_format_info (dev, mode_cmd); +if (!info) +return -EINVAL ; + +for (i =0 ; i < info->num_planes; i++) { +unsigned int width = mode_cmd->width / (i ? info->hsub :1 ); +unsigned int height = mode_cmd->height / (i ? info->vsub :1 ); +unsigned int min_size; + + min_size = (height -1 ) * mode_cmd->pitches[i] + +drm_format_info_min_pitch (info, i, width) + + mode_cmd->offsets[i]; + +if (objs[i]->size < min_size) +return -EINVAL ; + } + +return 0 ; + +} +EXPORT_SYMBOL_GPL (drm_gem_fb_size_check); +static const struct drm_framebuffer_funcs drm_gem_fb_funcs_dirtyfb = { .destroy = drm_gem_fb_destroy, .create_handle = drm_gem_fb_create_handle,include/drm/drm_gem_framebuffer_helper.h +10
-0@@ -14,10 +14,27 @@ struct drm_simple_display_pipe;struct drm_gem_object *drm_gem_fb_get_obj (struct drm_framebuffer *fb,unsigned int plane); +int drm_gem_fb_init_with_funcs (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj, +unsigned int num_planes, +const struct drm_framebuffer_funcs *funcs); +int drm_gem_fb_init (struct drm_framebuffer *fb, +struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **obj,unsigned int num_planes);void drm_gem_fb_destroy (struct drm_framebuffer *fb);int drm_gem_fb_create_handle (struct drm_framebuffer *fb,struct drm_file *file,unsigned int *handle);
include/drm/drm_gem_framebuffer_helper.h struct drm_simple_display_pipe; · line 40
Quoted 10 lines
include/drm/drm_gem_framebuffer_helper.h +7
-0+int drm_gem_fb_lookup (struct drm_device *dev, +struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs); +int drm_gem_fb_size_check (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs);struct drm_framebuffer * drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd,
James.
Quoted 2 lines
Signature · 1 line
2.17.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv5 02/34] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own
In reply to Andrzej PietrasiewiczQuoted 5 lines · On Tue, 17 Dec 2019 15:49:48 +0100 Andrzej Pietrasiewicz…
drivers/gpu/drm/drm_gem_framebuffer_helper.c +5
-0+/** +* drm_gem_fb_size_check() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations +* @dev: DRM device +* @mode_cmd: Metadata from the userspace framebuffer creation request
drivers/gpu/drm/drm_gem_framebuffer_helper.c drm_gem_fb_create(struct drm_device *dev, struct drm_file *file, · line 316
Quoted 10 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +10
-0+* +* This function can be used to verify buffer sizes for all planes. +* It is caller's responsibility to put the objects on failure. +* +* Returns: +* Zero on success or a negative error code on failure. +*/ +int drm_gem_fb_size_check (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs)
Maybe we should rename that one drm_gem_fb_linear_size_check().
Quoted 16 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +16
-0+{ +const struct drm_format_info *info; +int i; + + info =drm_get_format_info (dev, mode_cmd); +if (!info) +return -EINVAL ; + +for (i =0 ; i < info->num_planes; i++) { +unsigned int width = mode_cmd->width / (i ? info->hsub :1 ); +unsigned int height = mode_cmd->height / (i ? info->vsub :1 ); +unsigned int min_size; + + min_size = (height -1 ) * mode_cmd->pitches[i] + +drm_format_info_min_pitch (info, i, width) + + mode_cmd->offsets[i];
drivers/gpu/drm/drm_gem_framebuffer_helper.c drm_gem_fb_create(struct drm_device *dev, struct drm_file *file, · line 342
Quoted 10 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +10
-0+ +if (objs[i]->size < min_size) +return -EINVAL ; + } + +return 0 ; + +} +EXPORT_SYMBOL_GPL (drm_gem_fb_size_check); +
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 3/34 drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
In reply to Andrzej PietrasiewiczThe new version accepts a struct describing deviations from standard way of doing the size checks. The caller must provide the respective values.
--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 46 ++++++++++++++++---- include/drm/drm_gem_framebuffer_helper.h | 16 +++++++ 2 files changed, 54 insertions(+), 8 deletions(-)
drivers/gpu/drm/drm_gem_framebuffer_helper.c +38 -8
@@ -300,8 +300,8 @@ int drm_gem_fb_lookup(struct drm_device *dev,EXPORT_SYMBOL_GPL (drm_gem_fb_lookup);/** -* drm_gem_fb_size_check() - Helper function for use in -* &drm_mode_config_funcs.fb_create implementations +* drm_gem_fb_size_check2() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations * @dev: DRM device * @mode_cmd: Metadata from the userspace framebuffer creation request *
@@ -311,9 +311,10 @@ EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);* Returns: * Zero on success or a negative error code on failure. */ -int drm_gem_fb_size_check (struct drm_device *dev, -const struct drm_mode_fb_cmd2 *mode_cmd, -struct drm_gem_object **objs) +int drm_gem_fb_size_check2 (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +const struct drm_size_check *check, +struct drm_gem_object **objs) {const struct drm_format_info *info;int i;
@@ -326,10 +327,19 @@ int drm_gem_fb_size_check(struct drm_device *dev,unsigned int width = mode_cmd->width / (i ? info->hsub :1 );unsigned int height = mode_cmd->height / (i ? info->vsub :1 );unsigned int min_size; +u32 pitch = mode_cmd->pitches[i]; + +if (check && check->use_pitch_multiplier) +if ((pitch * check->pitch_multiplier[i]) % + check->pitch_modulo) +return -EINVAL ; - min_size = (height -1 ) * mode_cmd->pitches[i] - +drm_format_info_min_pitch (info, i, width) - + mode_cmd->offsets[i]; +if (check && check->use_min_size) + min_size = check->min_size[i]; +else + min_size = (height -1 ) * pitch + +drm_format_info_min_pitch (info, i, width) + + mode_cmd->offsets[i];if (objs[i]->size < min_size)return -EINVAL ;
@@ -338,6 +348,26 @@ int drm_gem_fb_size_check(struct drm_device *dev,return 0 ; } +EXPORT_SYMBOL_GPL (drm_gem_fb_size_check2); + +/** +* drm_gem_fb_size_check() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations +* @dev: DRM device +* @mode_cmd: Metadata from the userspace framebuffer creation request +* +* This function can be used to verify buffer sizes for all planes. +* It is caller's responsibility to put the objects on failure. +* +* Returns: +* Zero on success or a negative error code on failure. +*/ +int drm_gem_fb_size_check (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs) +{ +return drm_gem_fb_size_check2 (dev, mode_cmd,NULL , objs); +}EXPORT_SYMBOL_GPL (drm_gem_fb_size_check);static const struct drm_framebuffer_funcs drm_gem_fb_funcs_dirtyfb = {
include/drm/drm_gem_framebuffer_helper.h +16 -0
@@ -11,6 +11,18 @@ struct drm_mode_fb_cmd2;struct drm_plane ;struct drm_plane_state ;struct drm_simple_display_pipe ; +struct drm_size_check ; + +/** +* struct drm_size_check - Description of special requirements for size checks. +*/ +struct drm_size_check { +unsigned int min_size[4 ]; +bool use_min_size; +u32 pitch_multiplier[4 ]; +u32 pitch_modulo; +bool use_pitch_multiplier; +};struct drm_gem_object *drm_gem_fb_get_obj (struct drm_framebuffer *fb,unsigned int plane);
@@ -32,6 +44,10 @@ int drm_gem_fb_lookup(struct drm_device *dev,struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **objs); +int drm_gem_fb_size_check2 (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +const struct drm_size_check *check, +struct drm_gem_object **objs);int drm_gem_fb_size_check (struct drm_device *dev,const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object **objs);
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv5 03/34] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
Quoted 25 lines · Andrzej Pietrasiewicz
The new version accepts a struct describing deviations from standard way of doing the size checks. The caller must provide the respective values.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 46 ++++++++++++++++---- include/drm/drm_gem_framebuffer_helper.h | 16 +++++++ 2 files changed, 54 insertions(+), 8 deletions(-)drivers/gpu/drm/drm_gem_framebuffer_helper.c +2
-2@@ -300,8 +300,8 @@ int drm_gem_fb_lookup(struct drm_device *dev,EXPORT_SYMBOL_GPL (drm_gem_fb_lookup);/** -* drm_gem_fb_size_check() - Helper function for use in -* &drm_mode_config_funcs.fb_create implementations +* drm_gem_fb_size_check2() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations * @dev: DRM device * @mode_cmd: Metadata from the userspace framebuffer creation request *
drivers/gpu/drm/drm_gem_framebuffer_helper.c EXPORT_SYMBOL_GPL(drm_gem_fb_lookup); · line 314
Quoted 7 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +1
-3@@ -311,9 +311,10 @@ EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);* Returns: * Zero on success or a negative error code on failure. */ -int drm_gem_fb_size_check (struct drm_device *dev, -const struct drm_mode_fb_cmd2 *mode_cmd, -struct drm_gem_object **objs) +int drm_gem_fb_size_check2(struct drm_device *dev,
[nit-pick]: how about name it to drm_gem_fb_custom_size_check()
James.
Quoted 92 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +35
-3+const struct drm_mode_fb_cmd2 *mode_cmd, + const struct drm_size_check *check, + struct drm_gem_object **objs) { const struct drm_format_info *info;int i;@@ -326,10 +327,19 @@ int drm_gem_fb_size_check(struct drm_device *dev,unsigned int width = mode_cmd->width / (i ? info->hsub :1 );unsigned int height = mode_cmd->height / (i ? info->vsub :1 );unsigned int min_size; +u32 pitch = mode_cmd->pitches[i]; + +if (check && check->use_pitch_multiplier) +if ((pitch * check->pitch_multiplier[i]) % + check->pitch_modulo) +return -EINVAL ; - min_size = (height -1 ) * mode_cmd->pitches[i] - +drm_format_info_min_pitch (info, i, width) - + mode_cmd->offsets[i]; +if (check && check->use_min_size) + min_size = check->min_size[i]; +else + min_size = (height -1 ) * pitch + +drm_format_info_min_pitch (info, i, width) + + mode_cmd->offsets[i];if (objs[i]->size < min_size)return -EINVAL ;@@ -338,6 +348,26 @@ int drm_gem_fb_size_check(struct drm_device *dev,return 0 ; } +EXPORT_SYMBOL_GPL (drm_gem_fb_size_check2); + +/** +* drm_gem_fb_size_check() - Helper function for use in +* &drm_mode_config_funcs.fb_create implementations +* @dev: DRM device +* @mode_cmd: Metadata from the userspace framebuffer creation request +* +* This function can be used to verify buffer sizes for all planes. +* It is caller's responsibility to put the objects on failure. +* +* Returns: +* Zero on success or a negative error code on failure. +*/ +int drm_gem_fb_size_check (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object **objs) +{ +return drm_gem_fb_size_check2 (dev, mode_cmd,NULL , objs); +}EXPORT_SYMBOL_GPL (drm_gem_fb_size_check);static const struct drm_framebuffer_funcs drm_gem_fb_funcs_dirtyfb = {include/drm/drm_gem_framebuffer_helper.h +16
-0@@ -11,6 +11,18 @@ struct drm_mode_fb_cmd2;struct drm_plane ;struct drm_plane_state ;struct drm_simple_display_pipe ; +struct drm_size_check ; + +/** +* struct drm_size_check - Description of special requirements for size checks. +*/ +struct drm_size_check { +unsigned int min_size[4 ]; +bool use_min_size; +u32 pitch_multiplier[4 ]; +u32 pitch_modulo; +bool use_pitch_multiplier; +};struct drm_gem_object *drm_gem_fb_get_obj (struct drm_framebuffer *fb,unsigned int plane);@@ -32,6 +44,10 @@ int drm_gem_fb_lookup(struct drm_device *dev,struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **objs); +int drm_gem_fb_size_check2 (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +const struct drm_size_check *check, +struct drm_gem_object **objs);int drm_gem_fb_size_check (struct drm_device *dev,const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object **objs);Signature · 1 line
2.17.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv5 03/34] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
In reply to Andrzej PietrasiewiczQuoted 12 lines · On Tue, 17 Dec 2019 15:49:49 +0100 Andrzej Pietrasiewicz…
static const struct
drm_framebuffer_funcsdrm_gem_fb_funcs_dirtyfb= {include/drm/drm_gem_framebuffer_helper.h +2
-0@@ -11,6 +11,18 @@ struct drm_mode_fb_cmd2;struct drm_plane ;struct drm_plane_state ;struct drm_simple_display_pipe ; +struct drm_size_check ; +
include/drm/drm_gem_framebuffer_helper.h struct drm_mode_fb_cmd2; · line 25
Quoted 10 lines
include/drm/drm_gem_framebuffer_helper.h +10
-0+/** +* struct drm_size_check - Description of special requirements for size checks. +*/ +struct drm_size_check { +unsigned int min_size[4 ]; +bool use_min_size; +u32 pitch_multiplier[4 ]; +u32 pitch_modulo; +bool use_pitch_multiplier; +};
How about adding a ->size_check() hook to drm_framebuffer_funcs so that each driver can provide its custom size_check logic. That sounds more future-prood than trying to make all kind of size-checking fit in this size-constraint descriptor, plus you wouldn't need this new drm_gem_fb_size_check2 function.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 4/34 drm/gem-fb-helper: Add generic afbc size checks
In reply to Andrzej PietrasiewiczExtend the size-checking special function to handle afbc.
--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 49 +++++++++++++++++-- include/drm/drm_framebuffer.h | 50 ++++++++++++++++++++ include/drm/drm_gem_framebuffer_helper.h | 1 + 3 files changed, 96 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_gem_framebuffer_helper.c +45 -4
@@ -21,6 +21,11 @@#include <drm/drm_modeset_helper.h> #include <drm/drm_simple_kms_helper.h> +#define AFBC_HEADER_SIZE 16 +#define AFBC_TH_LAYOUT_ALIGNMENT 8 +#define AFBC_SUPERBLOCK_PIXELS 256 +#define AFBC_SUPERBLOCK_ALIGNMENT 128 +/** * DOC: overview *
@@ -299,6 +304,34 @@ int drm_gem_fb_lookup(struct drm_device *dev, }EXPORT_SYMBOL_GPL (drm_gem_fb_lookup); +static int drm_gem_afbc_min_size (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_afbc_framebuffer *afbc_fb) +{ +u32 n_blocks; + +if (!drm_afbc_get_superblock_wh (mode_cmd->modifier[0 ], &afbc_fb->block_width, &afbc_fb->block_height)) +return -EINVAL ; + +/* tiled header afbc */ +if (mode_cmd->modifier[0 ] &AFBC_FORMAT_MOD_TILED ) { + afbc_fb->block_width *=AFBC_TH_LAYOUT_ALIGNMENT ; + afbc_fb->block_height *=AFBC_TH_LAYOUT_ALIGNMENT ; + } + + afbc_fb->aligned_width =ALIGN (mode_cmd->width, afbc_fb->block_width); + afbc_fb->aligned_height =ALIGN (mode_cmd->height, afbc_fb->block_height); + afbc_fb->offset = mode_cmd->offsets[0 ]; + + n_blocks = (afbc_fb->aligned_width * afbc_fb->aligned_height) /AFBC_SUPERBLOCK_PIXELS ; + afbc_fb->offset_payload =ALIGN (n_blocks *AFBC_HEADER_SIZE , afbc_fb->alignment_header); + + afbc_fb->afbc_size = afbc_fb->offset_payload + + n_blocks *ALIGN (afbc_fb->bpp *AFBC_SUPERBLOCK_PIXELS /8 ,AFBC_SUPERBLOCK_ALIGNMENT ); + +return 0 ; +} +/** * drm_gem_fb_size_check2() - Helper function for use in * &drm_mode_config_funcs.fb_create implementations
@@ -334,19 +367,27 @@ int drm_gem_fb_size_check2(struct drm_device *dev, check->pitch_modulo)return -EINVAL ; -if (check && check->use_min_size) +if (check && check->use_min_size) { min_size = check->min_size[i]; -else + }else if (check && check->data &&drm_is_afbc (mode_cmd->modifier[0 ])) { +struct drm_afbc_framebuffer *afbc_fb; +int ret; + + afbc_fb = check->data; + ret =drm_gem_afbc_min_size (dev, mode_cmd, afbc_fb); +if (ret <0 ) +return ret; + min_size = ret; + }else { min_size = (height -1 ) * pitch +drm_format_info_min_pitch (info, i, width) + mode_cmd->offsets[i]; - + }if (objs[i]->size < min_size)return -EINVAL ; }return 0 ; - }EXPORT_SYMBOL_GPL (drm_gem_fb_size_check2);
include/drm/drm_framebuffer.h +50 -0
54 lines not on this page · raw message
include/drm/drm_gem_framebuffer_helper.h +1 -0
@@ -22,6 +22,7 @@ struct drm_size_check {u32 pitch_multiplier[4 ];u32 pitch_modulo;bool use_pitch_multiplier; +void *data; }; struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv5 04/34] drm/gem-fb-helper: Add generic afbc size checks
Hi Andrzej:
Quoted 33 lines · Andrzej Pietrasiewicz
Extend the size-checking special function to handle afbc.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 49 +++++++++++++++++-- include/drm/drm_framebuffer.h | 50 ++++++++++++++++++++ include/drm/drm_gem_framebuffer_helper.h | 1 + 3 files changed, 96 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_gem_framebuffer_helper.c +9
-0@@ -21,6 +21,11 @@#include <drm/drm_modeset_helper.h> #include <drm/drm_simple_kms_helper.h> +#define AFBC_HEADER_SIZE 16 +#define AFBC_TH_LAYOUT_ALIGNMENT 8 +#define AFBC_SUPERBLOCK_PIXELS 256 +#define AFBC_SUPERBLOCK_ALIGNMENT 128 +/** * DOC: overview * @@ -299,6 +304,34 @@ int drm_gem_fb_lookup(struct drm_device *dev, }EXPORT_SYMBOL_GPL (drm_gem_fb_lookup); +static int drm_gem_afbc_min_size (struct drm_device *dev, +const struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_afbc_framebuffer *afbc_fb) +{
drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_lookup(struct drm_device *dev, · line 320
Quoted 10 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +10
-0+u32 n_blocks; + +if (!drm_afbc_get_superblock_wh (mode_cmd->modifier[0 ], &afbc_fb->block_width, &afbc_fb->block_height)) +return -EINVAL ; + +/* tiled header afbc */ +if (mode_cmd->modifier[0 ] &AFBC_FORMAT_MOD_TILED ) { + afbc_fb->block_width *=AFBC_TH_LAYOUT_ALIGNMENT ; + afbc_fb->block_height *=AFBC_TH_LAYOUT_ALIGNMENT ; + }
TBH, here caculated afbc_fb->block_with/height are not block_width/height, but fb w/h alignment.
Per my understanding, afbc only has block size: 16x16, 32x8, 64x4 ... generally the afbc w/h alignment according the the block_size, but once the tiled header enabled, since one tiled header describes 8x8 superblocks, so the alignment of w/h need to mutiple 8.
So I think we'd better name the variable to width/height_alignment.
BTW: no matter block_w/h or w/h_alignmtent are only for size calculation, seems no need to store them to afbc_fb.
drivers/gpu/drm/drm_gem_framebuffer_helper.c int drm_gem_fb_lookup(struct drm_device *dev, · line 328
Quoted 8 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +8
-0+ + afbc_fb->aligned_width =ALIGN (mode_cmd->width, afbc_fb->block_width); + afbc_fb->aligned_height =ALIGN (mode_cmd->height, afbc_fb->block_height); + afbc_fb->offset = mode_cmd->offsets[0 ]; + + n_blocks = (afbc_fb->aligned_width * afbc_fb->aligned_height) /AFBC_SUPERBLOCK_PIXELS ; + afbc_fb->offset_payload =ALIGN (n_blocks *AFBC_HEADER_SIZE , afbc_fb->alignment_header); +
After check the references in malidp, rockchip and komeda, seems this afbc->alignment_header is dedicated for komeda only and a pass in argument.
This is not true. Per afbc HW spec alignment is essential for all afbc usage. according to the spec the requiremnt are:
AFBC1.0/1.1: 64 byte alignment both for header and body buffer. AFBC1.2 (tiled header enabled): 4096 alignment.
So this alignement is not a vendor specific value, but afbc feature requirement, can be determined by afbc modifier.
(malidp and komeda obeys this spec, not sure about Rockchip, but I think it should be)
But you may see, komeda uses 1024 (not 64) for none-tiled-header afbc, that's because GPU(MALI) changed this value to 1024 for bus performance (sorry I don't know the detail), and komeda changed to 1024 to follow.
Back to alignment_header here, I think we can just follow the spec, use 64 for none-tiled-header, 4096 for tiled-header, and no need to let the caller to specify it
Quoted 69 lines
drivers/gpu/drm/drm_gem_framebuffer_helper.c +18
-4+ afbc_fb->afbc_size = afbc_fb->offset_payload + + n_blocks *ALIGN (afbc_fb->bpp *AFBC_SUPERBLOCK_PIXELS /8 ,AFBC_SUPERBLOCK_ALIGNMENT ); + +return 0 ; +} +/** * drm_gem_fb_size_check2() - Helper function for use in * &drm_mode_config_funcs.fb_create implementations @@ -334,19 +367,27 @@ int drm_gem_fb_size_check2(struct drm_device *dev, check->pitch_modulo)return -EINVAL ; -if (check && check->use_min_size) +if (check && check->use_min_size) { min_size = check->min_size[i]; -else + }else if (check && check->data &&drm_is_afbc (mode_cmd->modifier[0 ])) { +struct drm_afbc_framebuffer *afbc_fb; +int ret; + + afbc_fb = check->data; + ret =drm_gem_afbc_min_size (dev, mode_cmd, afbc_fb); +if (ret <0 ) +return ret; + min_size = ret; + }else { min_size = (height -1 ) * pitch +drm_format_info_min_pitch (info, i, width) + mode_cmd->offsets[i]; - + }if (objs[i]->size < min_size)return -EINVAL ; }return 0 ; - }EXPORT_SYMBOL_GPL (drm_gem_fb_size_check2);include/drm/drm_framebuffer.h +20
-0@@ -297,4 +297,54 @@ int drm_framebuffer_plane_width(int width,int drm_framebuffer_plane_height (int height,const struct drm_framebuffer *fb,int plane); +/** +* struct drm_afbc_framebuffer - a special afbc frame buffer object +* +* A derived class of struct drm_framebuffer, dedicated for afbc use cases. +*/ +struct drm_afbc_framebuffer { +/** +* @base: base framebuffer structure. +*/ +struct drm_framebuffer base; +/** +* @block_widht: width of a single afbc block +*/ +u32 block_width; +/** +* @block_widht: height of a single afbc block +*/ +u32 block_height; +/** +* @aligned_width: aligned frame buffer width
include/drm/drm_framebuffer.h int drm_framebuffer_plane_width(int width, · line 329
Quoted 10 lines
include/drm/drm_framebuffer.h +10
-0+*/ +u32 aligned_width; +/** +* @aligned_height: aligned frame buffer height +*/ +u32 aligned_height; +/** +* @offset: offset of the first afbc header +*/ +u32 offset;
Since malidp and komeda have no requirement for none-zero offset, so I think we can reject none zero offset as error like did in rockchip in afbc_size_check().
Quoted 6 lines
include/drm/drm_framebuffer.h +6
-0+/** +* @alignment_header: required alignment for afbc headers +*/ +u32 alignment_header; +/** +* @afbc_size: minimum size of afbc buffer
include/drm/drm_framebuffer.h int drm_framebuffer_plane_width(int width, · line 345
Quoted 10 lines
include/drm/drm_framebuffer.h +10
-0+*/ +u32 afbc_size; +/** +* @offset_payload: start of afbc body buffer +*/ +u32 offset_payload; +/** +* @bpp: bpp value for this afbc buffer +*/ +u32 bpp;
Seems we can remove this bpp or no need to define it as a pass in argument for size check, maybe the komeda/malidp get_afbc_bpp() function mislead you that afbc formats may have vendor specific bpp.
But the story is:
for afbc only formats like DRM_FORMAT_YUV420_8BIT/10BIT, we have set nothing in drm_format_info, neither cpp nor block_size, so both malidp or komeda introduce a get_bpp(), but actually the two funcs basically are same.
So my suggestion is we can temporary use the get_afbc_bpp() in malidp or komeda. and eventually I think we'd better set the block size for these formats, then we can defines a common get_bpp() like pitch
Thanks
James
Quoted 19 lines
include/drm/drm_framebuffer.h +4
-0+}; + +#define fb_to_afbc_fb (x) container_of(x, struct drm_afbc_framebuffer, base) +#endif include/drm/drm_gem_framebuffer_helper.h +1
-0@@ -22,6 +22,7 @@ struct drm_size_check {u32 pitch_multiplier[4 ];u32 pitch_modulo;bool use_pitch_multiplier; +void *data; }; struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,Signature · 1 line
2.17.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 5/34 drm/komeda: Use afbc helper
In reply to Andrzej PietrasiewiczMakes the code shorter and more readable.
--- .../drm/arm/display/komeda/komeda_framebuffer.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +2 -14
@@ -52,20 +52,8 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,return -ENOENT ; } -switch (fb->modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ) { -case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8: - alignment_w =32 ; - alignment_h =8 ; -break ; -case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16: - alignment_w =16 ; - alignment_h =16 ; -break ; -default : -WARN (1 ,"Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n" , - fb->modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ); -break ; - } +if (!drm_afbc_get_superblock_wh (fb->modifier, &alignment_w, &alignment_h)) +return -EINVAL ;/* tiled header afbc */ if (fb->modifier &AFBC_FORMAT_MOD_TILED ) {
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 6/34 drm/komeda: Move checking src coordinates to komeda_fb_create
In reply to Andrzej PietrasiewiczNext step towards unifying afbc and non-afbc cases as much as possible.
--- .../drm/arm/display/komeda/komeda_framebuffer.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +9 -5
@@ -106,9 +106,6 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb,u32 i, block_h;u64 min_size; -if (komeda_fb_check_src_coords (kfb,0 ,0 , fb->width, fb->height)) -return -EINVAL ; -for (i =0 ; i < info->num_planes; i++) { obj =drm_gem_object_lookup (file, mode_cmd->handles[i]);if (!obj) {
@@ -167,10 +164,17 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,drm_helper_mode_fill_fb_struct (dev, &kfb->base, mode_cmd); -if (kfb->base.modifier) +if (kfb->base.modifier) { ret =komeda_fb_afbc_size_check (kfb, file, mode_cmd); -else + }else { +if (komeda_fb_check_src_coords (kfb,0 ,0 , kfb->base.width, + kfb->base.height)) { +kfree (kfb); +return ERR_PTR (-EINVAL ); + } + ret =komeda_fb_none_afbc_size_check (mdev, kfb, file, mode_cmd); + }if (ret <0 ) goto err_cleanup;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 7/34 drm/komeda: Use the already available local variable
In reply to Andrzej PietrasiewiczThere is a local "info" variable which is exactly fb->format, so use it.
--- drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +1 -1
@@ -130,7 +130,7 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb, } } -if (fb->format->num_planes ==3 ) { +if (info->num_planes ==3 ) {if (fb->pitches[1 ] != fb->pitches[2 ]) {DRM_DEBUG_KMS ("The pitch[1] and [2] are not same\n" );return -EINVAL ;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 8/34 drm/komeda: Retrieve drm_format_info once
In reply to Andrzej PietrasiewiczNext step towards unifying afbc and non-afbc cases as much as possible.
--- .../drm/arm/display/komeda/komeda_framebuffer.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +11 -6
@@ -37,11 +37,12 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = { };static int -komeda_fb_afbc_size_check (struct komeda_fb *kfb,struct drm_file *file, +komeda_fb_afbc_size_check (struct komeda_fb *kfb, +const struct drm_format_info *info, +struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd) {struct drm_framebuffer *fb = &kfb->base; -const struct drm_format_info *info = fb->format;struct drm_gem_object *obj;u32 alignment_w =0 , alignment_h =0 , alignment_header, n_blocks, bpp;u64 min_size;
@@ -96,12 +97,13 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, }static int -komeda_fb_none_afbc_size_check (struct komeda_dev *mdev,struct komeda_fb *kfb, +komeda_fb_none_afbc_size_check (struct komeda_dev *mdev, +struct komeda_fb *kfb, +const struct drm_format_info *info,struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd) {struct drm_framebuffer *fb = &kfb->base; -const struct drm_format_info *info = fb->format;struct drm_gem_object *obj;u32 i, block_h;u64 min_size;
@@ -146,6 +148,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, {struct komeda_dev *mdev = dev->dev_private;struct komeda_fb *kfb; +const struct drm_format_info *info;int ret =0 , i; kfb =kzalloc (sizeof (*kfb),GFP_KERNEL );
@@ -163,9 +166,10 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, }drm_helper_mode_fill_fb_struct (dev, &kfb->base, mode_cmd); + info = kfb->base.format;if (kfb->base.modifier) { - ret =komeda_fb_afbc_size_check (kfb, file, mode_cmd); + ret =komeda_fb_afbc_size_check (kfb, info, file, mode_cmd); }else {if (komeda_fb_check_src_coords (kfb,0 ,0 , kfb->base.width, kfb->base.height)) {
@@ -173,7 +177,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,return ERR_PTR (-EINVAL ); } - ret =komeda_fb_none_afbc_size_check (mdev, kfb, file, mode_cmd); + ret =komeda_fb_none_afbc_size_check (mdev, kfb, info, file, + mode_cmd); }if (ret <0 ) goto err_cleanup;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 9/34 drm/komeda: Explicitly require 1 plane for AFBC
In reply to Andrzej PietrasiewiczApparently komeda silently assumes that there is only 1 plane in an AFBC buffer. Make this assumption explicit.
--- drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +5 -0
@@ -169,6 +169,11 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, info = kfb->base.format;if (kfb->base.modifier) { +if (info->num_planes !=1 ) { +DRM_DEBUG_KMS ("AFBC requires exactly 1 plane.\n" ); +kfree (kfb); +return ERR_PTR (-EINVAL ); + } ret =komeda_fb_afbc_size_check (kfb, info, file, mode_cmd); }else { if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 10/34 drm/komeda: Move pitches comparison to komeda_fb_create
In reply to Andrzej PietrasiewiczFor AFBC case num_planes equals 1 so the check will not affect it.
--- .../drm/arm/display/komeda/komeda_framebuffer.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +7 -7
@@ -132,13 +132,6 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, } } -if (info->num_planes ==3 ) { -if (fb->pitches[1 ] != fb->pitches[2 ]) { -DRM_DEBUG_KMS ("The pitch[1] and [2] are not same\n" ); -return -EINVAL ; - } - } -return 0 ; }
@@ -188,6 +181,13 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,if (ret <0 ) goto err_cleanup; +if (info->num_planes ==3 ) +if (kfb->base.pitches[1 ] != kfb->base.pitches[2 ]) { +DRM_DEBUG_KMS ("The pitch[1] and [2] are not same\n" ); + ret = -EINVAL ; + goto err_cleanup; + } + ret =drm_framebuffer_init (dev, &kfb->base, &komeda_fb_funcs);if (ret <0 ) {DRM_DEBUG_KMS ("failed to initialize fb\n" );
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 11/34 drm/komeda: Provide and use komeda_fb_get_pixel_addr variant not requiring a fb
In reply to Andrzej PietrasiewiczAdd a variant of the function which doesn't need neither struct drm_framebuffer nor container_of it. Maintain current interface for existing users.
--- .../arm/display/komeda/komeda_framebuffer.c | 68 +++++++++++++++---- .../arm/display/komeda/komeda_framebuffer.h | 7 ++ 2 files changed, 61 insertions(+), 14 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +54 -14
@@ -123,7 +123,12 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,return -EINVAL ; } - min_size =komeda_fb_get_pixel_addr (kfb,0 , fb->height, i) + min_size =komeda_fb_get_pixel_addr_nofb (info, + mode_cmd->modifier[0 ], + mode_cmd->pitches, + mode_cmd->offsets, + obj, +0 , mode_cmd->height, i) -to_drm_gem_cma_obj (obj)->paddr;if (obj->size < min_size) { DRM_DEBUG_KMS("The fb->obj[%d] size: 0x%zx lower than the minimum requirement: 0x%llx.\n",
@@ -237,12 +242,56 @@ int komeda_fb_check_src_coords(const struct komeda_fb *kfb,return 0 ; } +dma_addr_t +komeda_fb_get_pixel_addr_impl (const struct drm_format_info *format, +u64 modifier, +const unsigned int *pitches, +const unsigned int *offsets, +const struct drm_gem_cma_object *obj, +int x,int y,int plane) +{ +u32 offset, plane_x, plane_y, block_w, block_sz; + + offset = offsets[plane]; +if (modifier) { + block_w =drm_format_info_block_width (format, plane); + block_sz = format->char_per_block[plane]; + plane_x = x / (plane ? format->hsub :1 ); + plane_y = y / (plane ? format->vsub :1 ); + + offset += (plane_x / block_w) * block_sz + + plane_y * pitches[plane]; + } + +return obj->paddr + offset; +} + +dma_addr_t +komeda_fb_get_pixel_addr_nofb (const struct drm_format_info *format, +u64 modifier, +const unsigned int *pitches, +const unsigned int *offsets, +struct drm_gem_object *obj, +int x,int y,int plane) +{ +const struct drm_gem_cma_object *cma_obj; + +if (plane >= format->num_planes) { +DRM_DEBUG_KMS ("Out of max plane num.\n" ); +return -EINVAL ; + } + + cma_obj =to_drm_gem_cma_obj (obj); + +return komeda_fb_get_pixel_addr_impl (format, modifier, pitches, offsets, + cma_obj, x, y, plane); +} +dma_addr_t komeda_fb_get_pixel_addr (struct komeda_fb *kfb,int x,int y,int plane) {struct drm_framebuffer *fb = &kfb->base;const struct drm_gem_cma_object *obj; -u32 offset, plane_x, plane_y, block_w, block_sz;if (plane >= fb->format->num_planes) {DRM_DEBUG_KMS ("Out of max plane num.\n" );
@@ -251,18 +300,9 @@ komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane) obj =drm_fb_cma_get_gem_obj (fb, plane); - offset = fb->offsets[plane]; -if (!fb->modifier) { - block_w =drm_format_info_block_width (fb->format, plane); - block_sz = fb->format->char_per_block[plane]; - plane_x = x / (plane ? fb->format->hsub :1 ); - plane_y = y / (plane ? fb->format->vsub :1 ); - - offset += (plane_x / block_w) * block_sz - + plane_y * fb->pitches[plane]; - } - -return obj->paddr + offset; +return komeda_fb_get_pixel_addr_impl (fb->format, fb->modifier, + fb->pitches, fb->offsets, + obj, x, y, plane); }/* if the fb can be supported by a specific layer */
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h +7 -0
@@ -42,6 +42,13 @@ int komeda_fb_check_src_coords(const struct komeda_fb *kfb, u32 src_x, u32 src_y, u32 src_w, u32 src_h);dma_addr_t komeda_fb_get_pixel_addr (struct komeda_fb *kfb,int x,int y,int plane); +dma_addr_t +komeda_fb_get_pixel_addr_nofb (const struct drm_format_info *format, +u64 modifier, +const unsigned int *pitches, +const unsigned int *offsets, +struct drm_gem_object *obj, +int x,int y,int plane);bool komeda_fb_is_layer_supported (struct komeda_fb *kfb,u32 layer_type,u32 rot);
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 12/34 drm/komeda: Factor out object lookups for non-afbc case
In reply to Andrzej PietrasiewiczUltimately we want lookups happening only once in komeda's fb_create implementation.
--- .../arm/display/komeda/komeda_framebuffer.c | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +13 -8
@@ -100,6 +100,7 @@ static int komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb, const struct drm_format_info *info, + struct drm_gem_object **objs, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) {
@@ -109,12 +110,7 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,u64 min_size;for (i =0 ; i < info->num_planes; i++) { - obj =drm_gem_object_lookup (file, mode_cmd->handles[i]); -if (!obj) { -DRM_DEBUG_KMS ("Failed to lookup GEM object\n" ); -return -ENOENT ; - } - fb->obj[i] = obj; + obj = objs[i]; block_h =drm_format_info_block_height (info, i);if ((fb->pitches[i] * block_h) % mdev->chip.bus_width) {
@@ -174,14 +170,23 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, } ret =komeda_fb_afbc_size_check (kfb, info, file, mode_cmd); }else { +struct drm_gem_object *objs[4 ]; +if (komeda_fb_check_src_coords (kfb,0 ,0 , kfb->base.width, kfb->base.height)) {kfree (kfb);return ERR_PTR (-EINVAL ); } + ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); +if (ret <0 ) { +kfree (kfb); +return ERR_PTR (ret); + } - ret =komeda_fb_none_afbc_size_check (mdev, kfb, info, file, - mode_cmd); + ret =komeda_fb_none_afbc_size_check (mdev, kfb, info, objs, + file, mode_cmd); +for (i =0 ; i < info->num_planes; ++i) + kfb->base.obj[i] = objs[i]; }if (ret <0 ) goto err_cleanup;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 13/34 drm/komeda: Make komeda_fb_none_size_check independent from framebuffer
In reply to Andrzej PietrasiewiczAll necessary data is now available in other data structures.
--- drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +4 -5
@@ -98,13 +98,11 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,static int komeda_fb_none_afbc_size_check (struct komeda_dev *mdev, -struct komeda_fb *kfb,const struct drm_format_info *info,struct drm_gem_object **objs,struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd) { -struct drm_framebuffer *fb = &kfb->base;struct drm_gem_object *obj;u32 i, block_h;u64 min_size;
@@ -113,9 +111,10 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, obj = objs[i]; block_h =drm_format_info_block_height (info, i); -if ((fb->pitches[i] * block_h) % mdev->chip.bus_width) { +if ((mode_cmd->pitches[i] * block_h) % mdev->chip.bus_width) {DRM_DEBUG_KMS ("Pitch[%d]: 0x%x doesn't align to 0x%x\n" , - i, fb->pitches[i], mdev->chip.bus_width); + i, mode_cmd->pitches[i], + mdev->chip.bus_width);return -EINVAL ; }
@@ -183,7 +182,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,return ERR_PTR (ret); } - ret =komeda_fb_none_afbc_size_check (mdev, kfb, info, objs, + ret =komeda_fb_none_afbc_size_check (mdev, info, objs, file, mode_cmd);for (i =0 ; i < info->num_planes; ++i) kfb->base.obj[i] = objs[i];
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 14/34 drm/komeda: Factor out object lookups for afbc case
In reply to Andrzej PietrasiewiczUltimately we want lookups happening only once in komeda's fb_create implementation.
--- .../arm/display/komeda/komeda_framebuffer.c | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +17 -13
@@ -39,6 +39,7 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = {static int komeda_fb_afbc_size_check (struct komeda_fb *kfb,const struct drm_format_info *info, +struct drm_gem_object **objs,struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd) {
@@ -47,11 +48,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,u32 alignment_w =0 , alignment_h =0 , alignment_header, n_blocks, bpp;u64 min_size; - obj =drm_gem_object_lookup (file, mode_cmd->handles[0 ]); -if (!obj) { -DRM_DEBUG_KMS ("Failed to lookup GEM object\n" ); -return -ENOENT ; - } + obj = objs[0 ];if (!drm_afbc_get_superblock_wh (fb->modifier, &alignment_w, &alignment_h))return -EINVAL ;
@@ -70,7 +67,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,if (fb->offsets[0 ] % alignment_header) {DRM_DEBUG_KMS ("afbc offset alignment check failed.\n" ); - goto check_failed; +return -EINVAL ; } n_blocks = (kfb->aligned_w * kfb->aligned_h) /AFBC_SUPERBLK_PIXELS ;
@@ -85,15 +82,10 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,if (min_size > obj->size) {DRM_DEBUG_KMS ("afbc size check failed, obj_size: 0x%zx. min_size 0x%llx.\n" , obj->size, min_size); - goto check_failed; +return -EINVAL ; } - fb->obj[0 ] = obj;return 0 ; - -check_failed: -drm_gem_object_put_unlocked (obj); -return -EINVAL ; } static int
@@ -162,12 +154,24 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, info = kfb->base.format;if (kfb->base.modifier) { +struct drm_gem_object *objs[4 ]; +if (info->num_planes !=1 ) {DRM_DEBUG_KMS ("AFBC requires exactly 1 plane.\n" );kfree (kfb);return ERR_PTR (-EINVAL ); } - ret =komeda_fb_afbc_size_check (kfb, info, file, mode_cmd); + + ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); +if (ret <0 ) { +kfree (kfb); +return ERR_PTR (ret); + } + + ret =komeda_fb_afbc_size_check (kfb, info, objs, file, + mode_cmd); +for (i =0 ; i < info->num_planes; ++i) + kfb->base.obj[i] = objs[i]; }else {struct drm_gem_object *objs[4 ];
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 15/34 drm/komeda: Free komeda_fb_afbc_size_check from framebuffer dependency
In reply to Andrzej PietrasiewiczIt does still depend on komeda_fb, but only for komeda-specific parameters.
--- .../drm/arm/display/komeda/komeda_framebuffer.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +7 -8
@@ -43,18 +43,17 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { - struct drm_framebuffer *fb = &kfb->base; struct drm_gem_object *obj;u32 alignment_w =0 , alignment_h =0 , alignment_header, n_blocks, bpp;u64 min_size; obj = objs[0 ]; -if (!drm_afbc_get_superblock_wh (fb->modifier, &alignment_w, &alignment_h)) +if (!drm_afbc_get_superblock_wh (mode_cmd->modifier[0 ], &alignment_w, &alignment_h))return -EINVAL ;/* tiled header afbc */ -if (fb->modifier &AFBC_FORMAT_MOD_TILED ) { +if (mode_cmd->modifier[0 ] &AFBC_FORMAT_MOD_TILED ) { alignment_w *=AFBC_TH_LAYOUT_ALIGNMENT ; alignment_h *=AFBC_TH_LAYOUT_ALIGNMENT ; alignment_header =AFBC_TH_BODY_START_ALIGNMENT ;
@@ -62,10 +61,10 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, alignment_header =AFBC_BODY_START_ALIGNMENT ; } - kfb->aligned_w =ALIGN (fb->width, alignment_w); - kfb->aligned_h =ALIGN (fb->height, alignment_h); + kfb->aligned_w =ALIGN (mode_cmd->width, alignment_w); + kfb->aligned_h =ALIGN (mode_cmd->height, alignment_h); -if (fb->offsets[0 ] % alignment_header) { +if (mode_cmd->offsets[0 ] % alignment_header) {DRM_DEBUG_KMS ("afbc offset alignment check failed.\n" );return -EINVAL ; }
@@ -74,11 +73,11 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, kfb->offset_payload =ALIGN (n_blocks *AFBC_HEADER_SIZE , alignment_header); - bpp =komeda_get_afbc_format_bpp (info, fb->modifier); + bpp =komeda_get_afbc_format_bpp (info, mode_cmd->modifier[0 ]); kfb->afbc_size = kfb->offset_payload + n_blocks *ALIGN (bpp *AFBC_SUPERBLK_PIXELS /8 ,AFBC_SUPERBLK_ALIGNMENT ); - min_size = kfb->afbc_size + fb->offsets[0 ]; + min_size = kfb->afbc_size + mode_cmd->offsets[0 ];if (min_size > obj->size) {DRM_DEBUG_KMS ("afbc size check failed, obj_size: 0x%zx. min_size 0x%llx.\n" , obj->size, min_size);
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 16/34 drm/komeda: Simplify error handling
In reply to Andrzej PietrasiewiczUse less code to handle errors.
--- .../arm/display/komeda/komeda_framebuffer.c | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +14 -18
@@ -145,8 +145,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,if (!kfb->format_caps) {DRM_DEBUG_KMS ("FMT %x is not supported.\n" , mode_cmd->pixel_format); -kfree (kfb); -return ERR_PTR (-EINVAL ); + ret = -EINVAL ; + goto err_free; }drm_helper_mode_fill_fb_struct (dev, &kfb->base, mode_cmd);
@@ -157,15 +157,13 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,if (info->num_planes !=1 ) {DRM_DEBUG_KMS ("AFBC requires exactly 1 plane.\n" ); -kfree (kfb); -return ERR_PTR (-EINVAL ); + ret = -EINVAL ; + goto err_free; } ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); -if (ret <0 ) { -kfree (kfb); -return ERR_PTR (ret); - } +if (ret <0 ) + goto err_free; ret =komeda_fb_afbc_size_check (kfb, info, objs, file, mode_cmd);
@@ -174,16 +172,14 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, }else {struct drm_gem_object *objs[4 ]; -if (komeda_fb_check_src_coords (kfb,0 ,0 , kfb->base.width, - kfb->base.height)) { -kfree (kfb); -return ERR_PTR (-EINVAL ); - } + ret =komeda_fb_check_src_coords (kfb,0 ,0 , kfb->base.width, + kfb->base.height); +if (ret) + goto err_free; + ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); -if (ret <0 ) { -kfree (kfb); -return ERR_PTR (ret); - } +if (ret <0 ) + goto err_free; ret =komeda_fb_none_afbc_size_check (mdev, info, objs, file, mode_cmd);
@@ -214,7 +210,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, err_cleanup:for (i =0 ; i < kfb->base.format->num_planes; i++)drm_gem_object_put_unlocked (kfb->base.obj[i]); - +err_free:kfree (kfb);return ERR_PTR (ret); }
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 17/34 drm/komeda: Move object lookup before size checks
In reply to Andrzej PietrasiewiczThe lookup is performed the same way in both branches of the "if" statement, so move the lookup to before the "if". err_cleanup case is adjusted accordingly.
--- .../arm/display/komeda/komeda_framebuffer.c | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +8 -15
@@ -131,6 +131,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) {struct komeda_dev *mdev = dev->dev_private; +struct drm_gem_object *objs[4 ];struct komeda_fb *kfb;const struct drm_format_info *info;int ret =0 , i;
@@ -149,37 +150,29 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_free; } + ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); +if (ret <0 ) + goto err_free; +drm_helper_mode_fill_fb_struct (dev, &kfb->base, mode_cmd); info = kfb->base.format;if (kfb->base.modifier) { -struct drm_gem_object *objs[4 ]; -if (info->num_planes !=1 ) {DRM_DEBUG_KMS ("AFBC requires exactly 1 plane.\n" ); ret = -EINVAL ; - goto err_free; + goto err_cleanup; } - ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); -if (ret <0 ) - goto err_free; - ret =komeda_fb_afbc_size_check (kfb, info, objs, file, mode_cmd);for (i =0 ; i < info->num_planes; ++i) kfb->base.obj[i] = objs[i]; }else { -struct drm_gem_object *objs[4 ]; - ret =komeda_fb_check_src_coords (kfb,0 ,0 , kfb->base.width, kfb->base.height);if (ret) - goto err_free; - - ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); -if (ret <0 ) - goto err_free; + goto err_cleanup; ret =komeda_fb_none_afbc_size_check (mdev, info, objs, file, mode_cmd);
@@ -209,7 +202,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, err_cleanup:for (i =0 ; i < kfb->base.format->num_planes; i++) -drm_gem_object_put_unlocked (kfb->base.obj[i]); +drm_gem_object_put_unlocked (objs[i]); err_free:kfree (kfb);return ERR_PTR (ret);
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 18/34 drm/komeda: Move object assignments to framebuffer to after size checks
In reply to Andrzej PietrasiewiczThe assignments are the same in both branches of the "if" statement and nothing depends on them between their original position and the new position, so this can be safely done.
--- drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +3 -4
@@ -166,8 +166,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret =komeda_fb_afbc_size_check (kfb, info, objs, file, mode_cmd); -for (i =0 ; i < info->num_planes; ++i) - kfb->base.obj[i] = objs[i]; }else { ret =komeda_fb_check_src_coords (kfb,0 ,0 , kfb->base.width, kfb->base.height);
@@ -176,8 +174,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret =komeda_fb_none_afbc_size_check (mdev, info, objs, file, mode_cmd); -for (i =0 ; i < info->num_planes; ++i) - kfb->base.obj[i] = objs[i]; }if (ret <0 ) goto err_cleanup;
@@ -189,6 +185,9 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; } +for (i =0 ; i < info->num_planes; ++i) + kfb->base.obj[i] = objs[i]; + ret =drm_framebuffer_init (dev, &kfb->base, &komeda_fb_funcs);if (ret <0 ) {DRM_DEBUG_KMS ("failed to initialize fb\n" );
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 19/34 drm/komeda: Make the size checks independent from framebuffer structure
In reply to Andrzej PietrasiewiczThe same data is available in mode_cmd.
--- .../gpu/drm/arm/display/komeda/komeda_framebuffer.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +5 -5
@@ -155,9 +155,9 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_free;drm_helper_mode_fill_fb_struct (dev, &kfb->base, mode_cmd); - info = kfb->base.format; + info =drm_get_format_info (dev, mode_cmd); -if (kfb->base.modifier) { +if (mode_cmd->modifier[0 ]) {if (info->num_planes !=1 ) {DRM_DEBUG_KMS ("AFBC requires exactly 1 plane.\n" ); ret = -EINVAL ;
@@ -167,8 +167,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret =komeda_fb_afbc_size_check (kfb, info, objs, file, mode_cmd); }else { - ret =komeda_fb_check_src_coords (kfb,0 ,0 , kfb->base.width, - kfb->base.height); + ret =komeda_fb_check_src_coords (kfb,0 ,0 , mode_cmd->width, + mode_cmd->height);if (ret) goto err_cleanup;
@@ -179,7 +179,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup;if (info->num_planes ==3 ) -if (kfb->base.pitches[1 ] != kfb->base.pitches[2 ]) { +if (mode_cmd->pitches[1 ] != mode_cmd->pitches[2 ]) {DRM_DEBUG_KMS ("The pitch[1] and [2] are not same\n" ); ret = -EINVAL ; goto err_cleanup;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 20/34 drm/komeda: Move helper invocation to after size checks
In reply to Andrzej PietrasiewiczBetween the old and new place nothing depends on data retrieved with the helper, so it is safe to move its invocation.
The err_cleanup case is changed accordingly.
--- drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +3 -2
@@ -154,7 +154,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,if (ret <0 ) goto err_free; -drm_helper_mode_fill_fb_struct (dev, &kfb->base, mode_cmd); info =drm_get_format_info (dev, mode_cmd);if (mode_cmd->modifier[0 ]) {
@@ -185,6 +184,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; } +drm_helper_mode_fill_fb_struct (dev, &kfb->base, mode_cmd); +for (i =0 ; i < info->num_planes; ++i) kfb->base.obj[i] = objs[i];
@@ -200,7 +201,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,return &kfb->base; err_cleanup: -for (i =0 ; i < kfb->base.format->num_planes; i++) +for (i =0 ; i < info->num_planes; i++)drm_gem_object_put_unlocked (objs[i]); err_free:kfree (kfb);
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 21/34 drm/komeda: Use helper for common tasks
In reply to Andrzej PietrasiewiczThe replaced fragment is 1:1 with the helper code.
--- .../gpu/drm/arm/display/komeda/komeda_framebuffer.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +3 -10
@@ -184,17 +184,10 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; } -drm_helper_mode_fill_fb_struct (dev, &kfb->base, mode_cmd); - -for (i =0 ; i < info->num_planes; ++i) - kfb->base.obj[i] = objs[i]; - - ret =drm_framebuffer_init (dev, &kfb->base, &komeda_fb_funcs); -if (ret <0 ) { -DRM_DEBUG_KMS ("failed to initialize fb\n" ); - + ret =drm_gem_fb_init_with_funcs (&kfb->base, dev, mode_cmd, objs, + info->num_planes, &komeda_fb_funcs); +if (ret <0 ) goto err_cleanup; - } kfb->is_va = mdev->iommu ? true : false;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 22/34 drm/komeda: Use return value of drm_gem_fb_lookup
In reply to Andrzej PietrasiewiczReduce dependency of the function on the "info" variable as much as possible.
--- .../gpu/drm/arm/display/komeda/komeda_framebuffer.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +6 -5
@@ -134,7 +134,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,struct drm_gem_object *objs[4 ];struct komeda_fb *kfb;const struct drm_format_info *info; -int ret =0 , i; +int ret =0 , i, num_planes; kfb =kzalloc (sizeof (*kfb),GFP_KERNEL );if (!kfb)
@@ -153,11 +153,12 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs);if (ret <0 ) goto err_free; + num_planes = ret; info =drm_get_format_info (dev, mode_cmd);if (mode_cmd->modifier[0 ]) { -if (info->num_planes !=1 ) { +if (num_planes !=1 ) {DRM_DEBUG_KMS ("AFBC requires exactly 1 plane.\n" ); ret = -EINVAL ; goto err_cleanup;
@@ -177,7 +178,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,if (ret <0 ) goto err_cleanup; -if (info->num_planes ==3 ) +if (num_planes ==3 )if (mode_cmd->pitches[1 ] != mode_cmd->pitches[2 ]) {DRM_DEBUG_KMS ("The pitch[1] and [2] are not same\n" ); ret = -EINVAL ;
@@ -185,7 +186,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, } ret =drm_gem_fb_init_with_funcs (&kfb->base, dev, mode_cmd, objs, - info->num_planes, &komeda_fb_funcs); + num_planes, &komeda_fb_funcs);if (ret <0 ) goto err_cleanup;
@@ -194,7 +195,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,return &kfb->base; err_cleanup: -for (i =0 ; i < info->num_planes; i++) +for (i =0 ; i < num_planes; i++)drm_gem_object_put_unlocked (objs[i]); err_free:kfree (kfb);
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 23/34 drm/komeda: Use special helper for non-afbc size checks
In reply to Andrzej PietrasiewiczUse the generic helper code.
--- .../arm/display/komeda/komeda_framebuffer.c | 46 +++++++++---------- 1 file changed, 21 insertions(+), 25 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +21 -25
@@ -88,42 +88,38 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, }static int -komeda_fb_none_afbc_size_check (struct komeda_dev *mdev, +komeda_fb_none_afbc_size_check (struct drm_device *dev,const struct drm_format_info *info,struct drm_gem_object **objs,struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd) { +struct komeda_dev *mdev = dev->dev_private; +struct drm_size_check check = {0 };struct drm_gem_object *obj; -u32 i, block_h; -u64 min_size; +u32 i;for (i =0 ; i < info->num_planes; i++) { obj = objs[i]; - block_h =drm_format_info_block_height (info, i); -if ((mode_cmd->pitches[i] * block_h) % mdev->chip.bus_width) { -DRM_DEBUG_KMS ("Pitch[%d]: 0x%x doesn't align to 0x%x\n" , - i, mode_cmd->pitches[i], - mdev->chip.bus_width); -return -EINVAL ; - } - - min_size =komeda_fb_get_pixel_addr_nofb (info, - mode_cmd->modifier[0 ], - mode_cmd->pitches, - mode_cmd->offsets, - obj, -0 , mode_cmd->height, i) - -to_drm_gem_cma_obj (obj)->paddr; -if (obj->size < min_size) { -DRM_DEBUG_KMS ("The fb->obj[%d] size: 0x%zx lower than the minimum requirement: 0x%llx.\n" , - i, obj->size, min_size); -return -EINVAL ; - } + check.pitch_multiplier[i] = +drm_format_info_block_height (info, i); + + check.min_size[i] = +komeda_fb_get_pixel_addr_nofb (info, + mode_cmd->modifier[0 ], + mode_cmd->pitches, + mode_cmd->offsets, + obj, +0 , mode_cmd->height, i) + -to_drm_gem_cma_obj (obj)->paddr; } -return 0 ; + check.pitch_modulo = mdev->chip.bus_width; + check.use_pitch_multiplier = true; + check.use_min_size = true; + +return drm_gem_fb_size_check2 (dev, mode_cmd, &check, objs); } struct drm_framebuffer *
@@ -172,7 +168,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,if (ret) goto err_cleanup; - ret =komeda_fb_none_afbc_size_check (mdev, info, objs, + ret =komeda_fb_none_afbc_size_check (dev, info, objs, file, mode_cmd); }if (ret <0 )
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 24/34 drm/komeda: Factor in the invocation of special helper
In reply to Andrzej PietrasiewiczDon't use a separate function to call the helper. The ultimate goal is to unify non-afbc and afbc cases as much as possible and then moving the helper invocation outside the if-else clause.
--- .../arm/display/komeda/komeda_framebuffer.c | 57 +++++++------------ 1 file changed, 20 insertions(+), 37 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +20 -37
@@ -87,41 +87,6 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,return 0 ; } -static int -komeda_fb_none_afbc_size_check (struct drm_device *dev, -const struct drm_format_info *info, -struct drm_gem_object **objs, -struct drm_file *file, -const struct drm_mode_fb_cmd2 *mode_cmd) -{ -struct komeda_dev *mdev = dev->dev_private; -struct drm_size_check check = {0 }; -struct drm_gem_object *obj; -u32 i; - -for (i =0 ; i < info->num_planes; i++) { - obj = objs[i]; - - check.pitch_multiplier[i] = -drm_format_info_block_height (info, i); - - check.min_size[i] = -komeda_fb_get_pixel_addr_nofb (info, - mode_cmd->modifier[0 ], - mode_cmd->pitches, - mode_cmd->offsets, - obj, -0 , mode_cmd->height, i) - -to_drm_gem_cma_obj (obj)->paddr; - } - - check.pitch_modulo = mdev->chip.bus_width; - check.use_pitch_multiplier = true; - check.use_min_size = true; - -return drm_gem_fb_size_check2 (dev, mode_cmd, &check, objs); -} -struct drm_framebuffer *komeda_fb_create (struct drm_device *dev,struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd)
@@ -163,13 +128,31 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret =komeda_fb_afbc_size_check (kfb, info, objs, file, mode_cmd); }else { +struct drm_size_check check = {0 }; + ret =komeda_fb_check_src_coords (kfb,0 ,0 , mode_cmd->width, mode_cmd->height);if (ret) goto err_cleanup; - ret =komeda_fb_none_afbc_size_check (dev, info, objs, - file, mode_cmd); +for (i =0 ; i < num_planes; i++) { + check.pitch_multiplier[i] = +drm_format_info_block_height (info, i); + + check.min_size[i] = +komeda_fb_get_pixel_addr_nofb (info, + mode_cmd->modifier[0 ], + mode_cmd->pitches, + mode_cmd->offsets, objs[i], +0 , mode_cmd->height, i) + -to_drm_gem_cma_obj (objs[i])->paddr; + } + + check.pitch_modulo = mdev->chip.bus_width; + check.use_pitch_multiplier = true; + check.use_min_size = true; + + ret =drm_gem_fb_size_check2 (dev, mode_cmd, &check, objs); }if (ret <0 ) goto err_cleanup;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 25/34 drm/komeda: Use special helper for afbc case size check
In reply to Andrzej PietrasiewiczUse generic helper code.
--- .../arm/display/komeda/komeda_framebuffer.c | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +8 -14
@@ -37,17 +37,15 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = { };static int -komeda_fb_afbc_size_check (struct komeda_fb *kfb, +komeda_fb_afbc_size_check (struct drm_device *dev, +struct komeda_fb *kfb,const struct drm_format_info *info,struct drm_gem_object **objs,struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd) { -struct drm_gem_object *obj; +struct drm_size_check check = {0 };u32 alignment_w =0 , alignment_h =0 , alignment_header, n_blocks, bpp; -u64 min_size; - - obj = objs[0 ];if (!drm_afbc_get_superblock_wh (mode_cmd->modifier[0 ], &alignment_w, &alignment_h))return -EINVAL ;
@@ -77,14 +75,10 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, kfb->afbc_size = kfb->offset_payload + n_blocks *ALIGN (bpp *AFBC_SUPERBLK_PIXELS /8 ,AFBC_SUPERBLK_ALIGNMENT ); - min_size = kfb->afbc_size + mode_cmd->offsets[0 ]; -if (min_size > obj->size) { -DRM_DEBUG_KMS ("afbc size check failed, obj_size: 0x%zx. min_size 0x%llx.\n" , - obj->size, min_size); -return -EINVAL ; - } + check.min_size[0 ] = kfb->afbc_size + mode_cmd->offsets[0 ]; + check.use_min_size = true; -return 0 ; +return drm_gem_fb_size_check2 (dev, mode_cmd, &check, objs); } struct drm_framebuffer *
@@ -125,8 +119,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; } - ret =komeda_fb_afbc_size_check (kfb, info, objs, file, - mode_cmd); + ret =komeda_fb_afbc_size_check (dev, kfb, info, objs, + file, mode_cmd); }else {struct drm_size_check check = {0 };
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 26/34 drm/komeda: Factor in the invocation of special helper, afbc case
In reply to Andrzej PietrasiewiczPrepare for unification with non-afbc case.
--- .../arm/display/komeda/komeda_framebuffer.c | 84 ++++++++----------- 1 file changed, 37 insertions(+), 47 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +37 -47
@@ -36,51 +36,6 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = { .create_handle = komeda_fb_create_handle, }; -static int -komeda_fb_afbc_size_check (struct drm_device *dev, -struct komeda_fb *kfb, -const struct drm_format_info *info, -struct drm_gem_object **objs, -struct drm_file *file, -const struct drm_mode_fb_cmd2 *mode_cmd) -{ -struct drm_size_check check = {0 }; -u32 alignment_w =0 , alignment_h =0 , alignment_header, n_blocks, bpp; - -if (!drm_afbc_get_superblock_wh (mode_cmd->modifier[0 ], &alignment_w, &alignment_h)) -return -EINVAL ; - -/* tiled header afbc */ -if (mode_cmd->modifier[0 ] &AFBC_FORMAT_MOD_TILED ) { - alignment_w *=AFBC_TH_LAYOUT_ALIGNMENT ; - alignment_h *=AFBC_TH_LAYOUT_ALIGNMENT ; - alignment_header =AFBC_TH_BODY_START_ALIGNMENT ; - }else { - alignment_header =AFBC_BODY_START_ALIGNMENT ; - } - - kfb->aligned_w =ALIGN (mode_cmd->width, alignment_w); - kfb->aligned_h =ALIGN (mode_cmd->height, alignment_h); - -if (mode_cmd->offsets[0 ] % alignment_header) { -DRM_DEBUG_KMS ("afbc offset alignment check failed.\n" ); -return -EINVAL ; - } - - n_blocks = (kfb->aligned_w * kfb->aligned_h) /AFBC_SUPERBLK_PIXELS ; - kfb->offset_payload =ALIGN (n_blocks *AFBC_HEADER_SIZE , - alignment_header); - - bpp =komeda_get_afbc_format_bpp (info, mode_cmd->modifier[0 ]); - kfb->afbc_size = kfb->offset_payload + n_blocks * -ALIGN (bpp *AFBC_SUPERBLK_PIXELS /8 , -AFBC_SUPERBLK_ALIGNMENT ); - check.min_size[0 ] = kfb->afbc_size + mode_cmd->offsets[0 ]; - check.use_min_size = true; - -return drm_gem_fb_size_check2 (dev, mode_cmd, &check, objs); -} -struct drm_framebuffer *komeda_fb_create (struct drm_device *dev,struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd)
@@ -113,14 +68,49 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, info =drm_get_format_info (dev, mode_cmd);if (mode_cmd->modifier[0 ]) { +struct drm_size_check check = {0 }; +u32 alignment_w =0 , alignment_h =0 ; +u32 alignment_header, n_blocks, bpp; +if (num_planes !=1 ) {DRM_DEBUG_KMS ("AFBC requires exactly 1 plane.\n" ); ret = -EINVAL ; goto err_cleanup; } - ret =komeda_fb_afbc_size_check (dev, kfb, info, objs, - file, mode_cmd); +if (!drm_afbc_get_superblock_wh (mode_cmd->modifier[0 ], &alignment_w, &alignment_h)) { + ret = -EINVAL ; + goto err_cleanup; + } + +/* tiled header afbc */ +if (mode_cmd->modifier[0 ] &AFBC_FORMAT_MOD_TILED ) { + alignment_w *=AFBC_TH_LAYOUT_ALIGNMENT ; + alignment_h *=AFBC_TH_LAYOUT_ALIGNMENT ; + alignment_header =AFBC_TH_BODY_START_ALIGNMENT ; + }else { + alignment_header =AFBC_BODY_START_ALIGNMENT ; + } + + kfb->aligned_w =ALIGN (mode_cmd->width, alignment_w); + kfb->aligned_h =ALIGN (mode_cmd->height, alignment_h); + +if (mode_cmd->offsets[0 ] % alignment_header) { +DRM_DEBUG_KMS ("afbc offset alignment check failed.\n" ); + ret = -EINVAL ; + goto err_cleanup; + } + + n_blocks = (kfb->aligned_w * kfb->aligned_h) /AFBC_SUPERBLK_PIXELS ; + kfb->offset_payload =ALIGN (n_blocks *AFBC_HEADER_SIZE , alignment_header); + + bpp =komeda_get_afbc_format_bpp (info, mode_cmd->modifier[0 ]); + kfb->afbc_size = kfb->offset_payload + + n_blocks *ALIGN (bpp *AFBC_SUPERBLK_PIXELS /8 ,AFBC_SUPERBLK_ALIGNMENT ); + check.min_size[0 ] = kfb->afbc_size + mode_cmd->offsets[0 ]; + check.use_min_size = true; + + ret =drm_gem_fb_size_check2 (dev, mode_cmd, &check, objs); }else {struct drm_size_check check = {0 };
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 27/34 drm/komeda: Move special helper invocation outside if-else
In reply to Andrzej PietrasiewiczThe invocation is the same in both cases and is the last thing inside a block, so move it outside the if-else clause.
--- .../gpu/drm/arm/display/komeda/komeda_framebuffer.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +3 -7
@@ -44,6 +44,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,struct drm_gem_object *objs[4 ];struct komeda_fb *kfb;const struct drm_format_info *info; +struct drm_size_check check = {0 }; +int ret =0 , i, num_planes; kfb =kzalloc (sizeof (*kfb),GFP_KERNEL );
@@ -68,7 +70,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, info =drm_get_format_info (dev, mode_cmd);if (mode_cmd->modifier[0 ]) { -struct drm_size_check check = {0 };u32 alignment_w =0 , alignment_h =0 ;u32 alignment_header, n_blocks, bpp;
@@ -109,11 +110,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, + n_blocks *ALIGN (bpp *AFBC_SUPERBLK_PIXELS /8 ,AFBC_SUPERBLK_ALIGNMENT ); check.min_size[0 ] = kfb->afbc_size + mode_cmd->offsets[0 ]; check.use_min_size = true; - - ret =drm_gem_fb_size_check2 (dev, mode_cmd, &check, objs); }else { -struct drm_size_check check = {0 }; - ret =komeda_fb_check_src_coords (kfb,0 ,0 , mode_cmd->width, mode_cmd->height);if (ret)
@@ -135,9 +132,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, check.pitch_modulo = mdev->chip.bus_width; check.use_pitch_multiplier = true; check.use_min_size = true; - - ret =drm_gem_fb_size_check2 (dev, mode_cmd, &check, objs); } + ret =drm_gem_fb_size_check2 (dev, mode_cmd, &check, objs);if (ret <0 ) goto err_cleanup;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 28/34 drm/komeda: Move to helper checking afbc buffer size
In reply to Andrzej PietrasiewiczUse generic helper code. Adapt struct komeda_fb users to new location of respective data members.
--- .../arm/display/komeda/d71/d71_component.c | 6 +-- .../arm/display/komeda/komeda_framebuffer.c | 44 +++++-------------- .../arm/display/komeda/komeda_framebuffer.h | 14 ++---- .../display/komeda/komeda_pipeline_state.c | 14 +++--- 4 files changed, 26 insertions(+), 52 deletions(-)
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +3 -3
@@ -186,7 +186,7 @@ static void d71_layer_update_fb(struct komeda_component *c,struct komeda_fb *kfb, dma_addr_t *addr) { - struct drm_framebuffer *fb = &kfb->base; + struct drm_framebuffer *fb = &kfb->base.base;const struct drm_format_info *info = fb->format;u32 __iomem *reg = c->reg;int block_h;
@@ -234,9 +234,9 @@ static void d71_layer_update(struct komeda_component *c, st->afbc_crop_b));/* afbc 1.2 wants payload, afbc 1.0/1.1 wants end_addr */ if (fb->modifier &AFBC_FORMAT_MOD_TILED ) - addr = st->addr[0 ] + kfb->offset_payload; + addr = st->addr[0 ] + kfb->base.offset_payload;else - addr = st->addr[0 ] + kfb->afbc_size -1 ; + addr = st->addr[0 ] + kfb->base.afbc_size -1 ;malidp_write32 (reg,BLK_P1_PTR_LOW ,lower_32_bits (addr));malidp_write32 (reg,BLK_P1_PTR_HIGH ,upper_32_bits (addr));
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +12 -32
93 lines not on this page · raw message
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h +3 -11
@@ -14,8 +14,8 @@* struct komeda_fb - Entending drm_framebuffer with komeda attribute */ struct komeda_fb { -/** @base: &drm_framebuffer */ -struct drm_framebuffer base; +/** @base: &drm_afbc_framebuffer */ +struct drm_afbc_framebuffer base;/** * @format_caps: * extends drm_format_info for komeda specific information
@@ -23,17 +23,9 @@ struct komeda_fb {const struct komeda_format_caps *format_caps;/** @is_va: if smmu is enabled, it will be true */ bool is_va; -/** @aligned_w: aligned frame buffer width */ -u32 aligned_w; -/** @aligned_h: aligned frame buffer height */ -u32 aligned_h; -/** @afbc_size: minimum size of afbc */ -u32 afbc_size; -/** @offset_payload: start of afbc body buffer */ -u32 offset_payload; }; -#define to_kfb (dfb) container_of(dfb, struct komeda_fb, base) +#define to_kfb (dfb) container_of(dfb, struct komeda_fb, base.base)struct drm_framebuffer * komeda_fb_create(struct drm_device *dev, struct drm_file *file,
drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c +8 -6
@@ -320,7 +320,7 @@ komeda_layer_check_cfg(struct komeda_layer *layer,else line_sz = dflow->in_w; -if (kfb->base.format->hsub >1 ) +if (kfb->base.base.format->hsub >1 ) max_line_sz = layer->yuv_line_sz;else max_line_sz = layer->line_sz;
@@ -360,12 +360,14 @@ komeda_layer_validate(struct komeda_layer *layer, st->rot = dflow->rot;if (fb->modifier) { - st->hsize = kfb->aligned_w; - st->vsize = kfb->aligned_h; + st->hsize = kfb->base.aligned_width; + st->vsize = kfb->base.aligned_height; st->afbc_crop_l = dflow->in_x; - st->afbc_crop_r = kfb->aligned_w - dflow->in_x - dflow->in_w; + st->afbc_crop_r = kfb->base.aligned_width + - dflow->in_x - dflow->in_w; st->afbc_crop_t = dflow->in_y; - st->afbc_crop_b = kfb->aligned_h - dflow->in_y - dflow->in_h; + st->afbc_crop_b = kfb->base.aligned_height + - dflow->in_y - dflow->in_h; }else { st->hsize = dflow->in_w; st->vsize = dflow->in_h;
@@ -419,7 +421,7 @@ komeda_wb_layer_validate(struct komeda_layer *wb_layer, st->hsize = dflow->out_w; st->vsize = dflow->out_h; -for (i =0 ; i < kfb->base.format->num_planes; i++) +for (i =0 ; i < kfb->base.base.format->num_planes; i++) st->addr[i] =komeda_fb_get_pixel_addr (kfb, dflow->out_x, dflow->out_y, i);
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 29/34 drm/arm/malidp: Make verify funcitons invocations independent
In reply to Andrzej PietrasiewiczThis will make it easier to transition to generic afbc-aware helpers.
--- drivers/gpu/drm/arm/malidp_drv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/arm/malidp_drv.c +3 -3
@@ -362,10 +362,10 @@ static bool malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { - if (malidp_verify_afbc_framebuffer_caps(dev, mode_cmd)) - return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd); + if (!malidp_verify_afbc_framebuffer_caps(dev, mode_cmd)) + return false; -return false; + return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd); } static struct drm_framebuffer *
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv5 29/34] drm/arm/malidp: Make verify funcitons invocations independent
In the subject: s/funcitons/functions/
Quoted 3 lines · On Tue, 17 Dec 2019 15:50:15 +0100 Andrzej Pietrasiewicz…
This will make it easier to transition to generic afbc-aware helpers.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>
Quoted 12 lines
--- drivers/gpu/drm/arm/malidp_drv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/arm/malidp_drv.c +0
-0@@ -362,10 +362,10 @@ static bool malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) {
drivers/gpu/drm/arm/malidp_drv.c static bool · line 371
Quoted 10 lines
drivers/gpu/drm/arm/malidp_drv.c +3
-3-if (malidp_verify_afbc_framebuffer_caps (dev, mode_cmd)) -return malidp_verify_afbc_framebuffer_size (dev, file, mode_cmd); +if (!malidp_verify_afbc_framebuffer_caps (dev, mode_cmd)) +return false; -return false; +return malidp_verify_afbc_framebuffer_size (dev, file, mode_cmd); } static struct drm_framebuffer *
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv5 29/34] drm/arm/malidp: Make verify funcitons invocations independent
Quoted 10 lines · On Thu, 20 Feb 2020 12:26:01 +0100 Boris Brezillon…
In the subject: s/funcitons/functions/
Quoted 3 lines · On Tue, 17 Dec 2019 15:50:15 +0100 Andrzej Pietrasiewicz…
This will make it easier to transition to generic afbc-aware helpers.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>Reviewed-by Boris Brezillon <[email protected]>
Wait, patch 30 is this patch completely irrelevant, so I take R-b back :-). You can just squash that one in patch 30.
Quoted 22 lines
Quoted 22 lines
--- drivers/gpu/drm/arm/malidp_drv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/arm/malidp_drv.c +3
-3@@ -362,10 +362,10 @@ static bool malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { - if (malidp_verify_afbc_framebuffer_caps(dev, mode_cmd)) - return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd); + if (!malidp_verify_afbc_framebuffer_caps(dev, mode_cmd)) + return false; -return false; + return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd); }
Quoted 6 lines
drivers/gpu/drm/arm/malidp_drv.c static bool · line 371
Quoted 1 line
drivers/gpu/drm/arm/malidp_drv.c +0
-0static struct drm_framebuffer *_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv5 29/34] drm/arm/malidp: Make verify funcitons invocations independent
Quoted 8 lines · On Thu, 20 Feb 2020 12:29:13 +0100 Boris Brezillon…
Quoted 5 lines · On Thu, 20 Feb 2020 12:26:01 +0100 Boris Brezillon…
In the subject: s/funcitons/functions/
On Tue, 17 Dec 2019 15:50:15 +0100
Andrzej Pietrasiewicz <[email protected]> wrote:
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
This will make it easier to transition to generic afbc-aware helpers.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>Reviewed-by Boris Brezillon <[email protected]>Wait, patch 30 is this patch completely irrelevant, so I take R-b back
s/patch 30 is this patch completely irrelevant/this patch is completely irrelevant if patch 30 is applied/
Quoted 31 lines
:-). You can just squash that one in patch 30.
Quoted 22 lines
Quoted 22 lines
--- drivers/gpu/drm/arm/malidp_drv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/arm/malidp_drv.c +3
-3@@ -362,10 +362,10 @@ static bool malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { - if (malidp_verify_afbc_framebuffer_caps(dev, mode_cmd)) - return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd); + if (!malidp_verify_afbc_framebuffer_caps(dev, mode_cmd)) + return false; -return false; + return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd); }Quoted 6 lines
drivers/gpu/drm/arm/malidp_drv.c static bool · line 371
Quoted 1 line
drivers/gpu/drm/arm/malidp_drv.c +0
-0static struct drm_framebuffer *_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 30/34 drm/arm/malidp: Integrate verify functions
In reply to Andrzej PietrasiewiczThe next step towards using generic afbc-aware helpers.
--- drivers/gpu/drm/arm/malidp_drv.c | 36 ++++++++------------------------ 1 file changed, 9 insertions(+), 27 deletions(-)
drivers/gpu/drm/arm/malidp_drv.c +9 -27
@@ -270,9 +270,16 @@ static const struct drm_mode_config_helper_funcs malidp_mode_config_helpers = { };static bool -malidp_verify_afbc_framebuffer_caps (struct drm_device *dev, -const struct drm_mode_fb_cmd2 *mode_cmd) +malidp_verify_afbc_framebuffer (struct drm_device *dev,struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd) { +int n_superblocks =0 ; +const struct drm_format_info *info; +struct drm_gem_object *objs =NULL ; +u32 afbc_superblock_size =0 , afbc_superblock_height =0 ; +u32 afbc_superblock_width =0 , afbc_size =0 ; +int bpp =0 ; +if (malidp_format_mod_supported (dev, mode_cmd->pixel_format, mode_cmd->modifier[0 ]) == false)return false;
@@ -294,21 +301,6 @@ malidp_verify_afbc_framebuffer_caps(struct drm_device *dev,return false; } -return true; -} - -static bool -malidp_verify_afbc_framebuffer_size (struct drm_device *dev, -struct drm_file *file, -const struct drm_mode_fb_cmd2 *mode_cmd) -{ -int n_superblocks =0 ; -const struct drm_format_info *info; -struct drm_gem_object *objs =NULL ; -u32 afbc_superblock_size =0 , afbc_superblock_height =0 ; -u32 afbc_superblock_width =0 , afbc_size =0 ; -int bpp =0 ; -switch (mode_cmd->modifier[0 ] &AFBC_SIZE_MASK ) {case AFBC_SIZE_16X16 : afbc_superblock_height =16 ;
@@ -358,16 +350,6 @@ malidp_verify_afbc_framebuffer_size(struct drm_device *dev,return true; } -static bool -malidp_verify_afbc_framebuffer (struct drm_device *dev,struct drm_file *file, -const struct drm_mode_fb_cmd2 *mode_cmd) -{ -if (!malidp_verify_afbc_framebuffer_caps (dev, mode_cmd)) -return false; - -return malidp_verify_afbc_framebuffer_size (dev, file, mode_cmd); -} -static struct drm_framebuffer *malidp_fb_create (struct drm_device *dev,struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd)
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 31/34 drm/arm/malidp: Factor in afbc framebuffer verification
In reply to Andrzej PietrasiewiczPrepare for using generic afbc-aware helpers.
--- drivers/gpu/drm/arm/malidp_drv.c | 142 +++++++++++++++---------------- 1 file changed, 68 insertions(+), 74 deletions(-)
drivers/gpu/drm/arm/malidp_drv.c +68 -74
@@ -269,94 +269,88 @@ static const struct drm_mode_config_helper_funcs malidp_mode_config_helpers = { .atomic_commit_tail = malidp_atomic_commit_tail, }; -static bool -malidp_verify_afbc_framebuffer (struct drm_device *dev,struct drm_file *file, -const struct drm_mode_fb_cmd2 *mode_cmd) +static struct drm_framebuffer * +malidp_fb_create (struct drm_device *dev,struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd) { -int n_superblocks =0 ; -const struct drm_format_info *info; -struct drm_gem_object *objs =NULL ; -u32 afbc_superblock_size =0 , afbc_superblock_height =0 ; -u32 afbc_superblock_width =0 , afbc_size =0 ; -int bpp =0 ; - -if (malidp_format_mod_supported (dev, mode_cmd->pixel_format, - mode_cmd->modifier[0 ]) == false) -return false; - -if (mode_cmd->offsets[0 ] !=0 ) { -DRM_DEBUG_KMS ("AFBC buffers' plane offset should be 0\n" ); -return false; - } +if (mode_cmd->modifier[0 ]) { +int n_superblocks =0 ; +const struct drm_format_info *info; +struct drm_gem_object *objs =NULL ; +u32 afbc_superblock_size =0 , afbc_superblock_height =0 ; +u32 afbc_superblock_width =0 , afbc_size =0 ; +int bpp =0 ; + +if (malidp_format_mod_supported (dev, mode_cmd->pixel_format, + mode_cmd->modifier[0 ]) == false) +return ERR_PTR (-EINVAL ); -switch (mode_cmd->modifier[0 ] &AFBC_SIZE_MASK ) { -case AFBC_SIZE_16X16 : -if ((mode_cmd->width %16 ) || (mode_cmd->height %16 )) { -DRM_DEBUG_KMS ("AFBC buffers must be aligned to 16 pixels\n" ); -return false; +if (mode_cmd->offsets[0 ] !=0 ) { +DRM_DEBUG_KMS ("AFBC buffers' plane offset should be 0\n" ); +return ERR_PTR (-EINVAL ); } -break ; -default : -DRM_DEBUG_KMS ("Unsupported AFBC block size\n" ); -return false; - } -switch (mode_cmd->modifier[0 ] &AFBC_SIZE_MASK ) { -case AFBC_SIZE_16X16 : - afbc_superblock_height =16 ; - afbc_superblock_width =16 ; -break ; -default : -DRM_DEBUG_KMS ("AFBC superblock size is not supported\n" ); -return false; - } +switch (mode_cmd->modifier[0 ] &AFBC_SIZE_MASK ) { +case AFBC_SIZE_16X16 : +if ((mode_cmd->width %16 ) || (mode_cmd->height %16 )) { +DRM_DEBUG_KMS ("AFBC buffers must be aligned to 16 pixels\n" ); +return ERR_PTR (-EINVAL ); + } +break ; +default : +DRM_DEBUG_KMS ("Unsupported AFBC block size\n" ); +return ERR_PTR (-EINVAL ); + } - info =drm_get_format_info (dev, mode_cmd); +switch (mode_cmd->modifier[0 ] &AFBC_SIZE_MASK ) { +case AFBC_SIZE_16X16 : + afbc_superblock_height =16 ; + afbc_superblock_width =16 ; +break ; +default : +DRM_DEBUG_KMS ("AFBC superblock size is not supported\n" ); +return ERR_PTR (-EINVAL ); + } - n_superblocks = (mode_cmd->width / afbc_superblock_width) * - (mode_cmd->height / afbc_superblock_height); + info =drm_get_format_info (dev, mode_cmd); - bpp =malidp_format_get_bpp (info->format); + n_superblocks = (mode_cmd->width / afbc_superblock_width) * + (mode_cmd->height / afbc_superblock_height); - afbc_superblock_size = (bpp * afbc_superblock_width * afbc_superblock_height) - /BITS_PER_BYTE ; + bpp =malidp_format_get_bpp (info->format); - afbc_size =ALIGN (n_superblocks *AFBC_HEADER_SIZE ,AFBC_SUPERBLK_ALIGNMENT ); - afbc_size += n_superblocks *ALIGN (afbc_superblock_size,AFBC_SUPERBLK_ALIGNMENT ); + afbc_superblock_size = + (bpp * afbc_superblock_width * afbc_superblock_height) + /BITS_PER_BYTE ; -if ((mode_cmd->width * bpp) != (mode_cmd->pitches[0 ] *BITS_PER_BYTE )) { -DRM_DEBUG_KMS ("Invalid value of (pitch * BITS_PER_BYTE) (=%u) " -"should be same as width (=%u) * bpp (=%u)\n" , - (mode_cmd->pitches[0 ] *BITS_PER_BYTE ), - mode_cmd->width, bpp); -return false; - } + afbc_size =ALIGN (n_superblocks *AFBC_HEADER_SIZE , +AFBC_SUPERBLK_ALIGNMENT ); + afbc_size += n_superblocks + *ALIGN (afbc_superblock_size,AFBC_SUPERBLK_ALIGNMENT ); - objs =drm_gem_object_lookup (file, mode_cmd->handles[0 ]); -if (!objs) { -DRM_DEBUG_KMS ("Failed to lookup GEM object\n" ); -return false; - } - -if (objs->size < afbc_size) { -DRM_DEBUG_KMS ("buffer size (%zu) too small for AFBC buffer size = %u\n" , - objs->size, afbc_size); -drm_gem_object_put_unlocked (objs); -return false; - } - -drm_gem_object_put_unlocked (objs); +if ((mode_cmd->width * bpp) != + (mode_cmd->pitches[0 ] *BITS_PER_BYTE )) { +DRM_DEBUG_KMS ("Invalid value of (pitch * BITS_PER_BYTE) (=%u) " +"should be same as width (=%u) * bpp (=%u)\n" , + (mode_cmd->pitches[0 ] *BITS_PER_BYTE ), + mode_cmd->width, bpp); +return ERR_PTR (-EINVAL ); + } -return true; -} + objs =drm_gem_object_lookup (file, mode_cmd->handles[0 ]); +if (!objs) { +DRM_DEBUG_KMS ("Failed to lookup GEM object\n" ); +return ERR_PTR (-EINVAL ); + } -static struct drm_framebuffer * -malidp_fb_create (struct drm_device *dev,struct drm_file *file, -const struct drm_mode_fb_cmd2 *mode_cmd) -{ -if (mode_cmd->modifier[0 ]) { -if (!malidp_verify_afbc_framebuffer (dev, file, mode_cmd)) +if (objs->size < afbc_size) { +DRM_DEBUG_KMS ("buffer size (%zu) too small for AFBC buffer size = %u\n" , + objs->size, afbc_size); +drm_gem_object_put_unlocked (objs);return ERR_PTR (-EINVAL ); + } + +drm_gem_object_put_unlocked (objs); }return drm_gem_fb_create (dev, file, mode_cmd);
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 32/34 drm/arm/malidp: Use generic helpers for afbc checks
In reply to Andrzej PietrasiewiczHelpers are now available for checking afbc buffer properties. Use those.
--- drivers/gpu/drm/arm/malidp_drv.c | 71 ++++++++++++++------------------ 1 file changed, 30 insertions(+), 41 deletions(-)
drivers/gpu/drm/arm/malidp_drv.c +30 -41
@@ -273,12 +273,17 @@ static struct drm_framebuffer * malidp_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { + struct drm_size_check check = { 0 }; +struct drm_gem_object *objs[4 ]; +struct drm_afbc_framebuffer *afbc_fb; +int ret, i, num_planes; + + afbc_fb =kzalloc (sizeof (*afbc_fb),GFP_KERNEL ); +if (!afbc_fb) +return ERR_PTR (-ENOMEM ); +if (mode_cmd->modifier[0 ]) { - int n_superblocks = 0;const struct drm_format_info *info; -struct drm_gem_object *objs =NULL ; -u32 afbc_superblock_size =0 , afbc_superblock_height =0 ; -u32 afbc_superblock_width =0 , afbc_size =0 ;int bpp =0 ; if (malidp_format_mod_supported(dev, mode_cmd->pixel_format,
@@ -302,32 +307,9 @@ malidp_fb_create(struct drm_device *dev, struct drm_file *file,return ERR_PTR (-EINVAL ); } -switch (mode_cmd->modifier[0 ] &AFBC_SIZE_MASK ) { -case AFBC_SIZE_16X16 : - afbc_superblock_height =16 ; - afbc_superblock_width =16 ; -break ; -default : -DRM_DEBUG_KMS ("AFBC superblock size is not supported\n" ); -return ERR_PTR (-EINVAL ); - } - info =drm_get_format_info (dev, mode_cmd); - - n_superblocks = (mode_cmd->width / afbc_superblock_width) * - (mode_cmd->height / afbc_superblock_height); - bpp =malidp_format_get_bpp (info->format); - afbc_superblock_size = - (bpp * afbc_superblock_width * afbc_superblock_height) - /BITS_PER_BYTE ; - - afbc_size =ALIGN (n_superblocks *AFBC_HEADER_SIZE , -AFBC_SUPERBLK_ALIGNMENT ); - afbc_size += n_superblocks - *ALIGN (afbc_superblock_size,AFBC_SUPERBLK_ALIGNMENT ); -if ((mode_cmd->width * bpp) != (mode_cmd->pitches[0 ] *BITS_PER_BYTE )) { DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE) (=%u) "
@@ -336,24 +318,31 @@ malidp_fb_create(struct drm_device *dev, struct drm_file *file, mode_cmd->width, bpp);return ERR_PTR (-EINVAL ); } + afbc_fb->bpp = bpp; + check.data = afbc_fb; + } - objs =drm_gem_object_lookup (file, mode_cmd->handles[0 ]); -if (!objs) { -DRM_DEBUG_KMS ("Failed to lookup GEM object\n" ); -return ERR_PTR (-EINVAL ); - } + ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); +if (ret <0 ) + goto err_free; + num_planes = ret; -if (objs->size < afbc_size) { -DRM_DEBUG_KMS ("buffer size (%zu) too small for AFBC buffer size = %u\n" , - objs->size, afbc_size); -drm_gem_object_put_unlocked (objs); -return ERR_PTR (-EINVAL ); - } + ret =drm_gem_fb_size_check2 (dev, mode_cmd, &check, objs); +if (ret <0 ) + goto err_cleanup; -drm_gem_object_put_unlocked (objs); - } + ret =drm_gem_fb_init (&afbc_fb->base, dev, mode_cmd, objs, num_planes); +if (ret <0 ) + goto err_cleanup; + +return &afbc_fb->base; -return drm_gem_fb_create (dev, file, mode_cmd); +err_cleanup: +for (i =0 ; i < num_planes; ++i) +drm_gem_object_put_unlocked (objs[i]); +err_free: +kfree (afbc_fb); +return ERR_PTR (ret); }static const struct drm_mode_config_funcs malidp_mode_config_funcs = {
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 33/34 drm/rockchip: Use helper for common task
In reply to Andrzej PietrasiewiczUse generic helper code.
--- drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +2 -10
@@ -18,6 +18,7 @@#include "rockchip_drm_fb.h" #include "rockchip_drm_gem.h" +static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = { .destroy = drm_gem_fb_destroy, .create_handle = drm_gem_fb_create_handle,
@@ -30,22 +31,13 @@ rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cm {struct drm_framebuffer *fb;int ret; -int i; fb =kzalloc (sizeof (*fb),GFP_KERNEL );if (!fb)return ERR_PTR (-ENOMEM ); -drm_helper_mode_fill_fb_struct (dev, fb, mode_cmd); - -for (i =0 ; i < num_planes; i++) - fb->obj[i] = obj[i]; - - ret =drm_framebuffer_init (dev, fb, &rockchip_drm_fb_funcs); + ret =drm_gem_fb_init_with_funcs (fb, dev, mode_cmd, obj, num_planes, &rockchip_drm_fb_funcs);if (ret) { -DRM_DEV_ERROR (dev->dev, -"Failed to initialize framebuffer: %d\n" , - ret);kfree (fb);return ERR_PTR (ret); }
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv5 33/34] drm/rockchip: Use helper for common task
Quoted 12 lines · On Tue, 17 Dec 2019 15:50:19 +0100 Andrzej Pietrasiewicz…
Use generic helper code.
Signed-off-by Andrzej Pietrasiewicz <[email protected]>--- drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)drivers/gpu/drm/rockchip/rockchip_drm_fb.c +0
-0
drivers/gpu/drm/rockchip/rockchip_drm_fb.c line 21
Quoted 4 lines
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +1
-0@@ -18,6 +18,7 @@#include "rockchip_drm_fb.h" #include "rockchip_drm_gem.h" +
You can drop this blank line. Looks good otherwise, but I'll wait for v6 (with the new ->check_size() maybe) before giving my R-b.
Quoted 17 lines
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +0
-5static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = { .destroy = drm_gem_fb_destroy, .create_handle = drm_gem_fb_create_handle,@@ -30,22 +31,13 @@ rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cm {struct drm_framebuffer *fb;int ret; -int i; fb =kzalloc (sizeof (*fb),GFP_KERNEL );if (!fb)return ERR_PTR (-ENOMEM ); -drm_helper_mode_fill_fb_struct (dev, fb, mode_cmd); - -for (i =0 ; i < num_planes; i++) - fb->obj[i] = obj[i];
drivers/gpu/drm/rockchip/rockchip_drm_fb.c rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cm · line 43
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +1
-5- - ret =drm_framebuffer_init (dev, fb, &rockchip_drm_fb_funcs); + ret =drm_gem_fb_init_with_funcs (fb, dev, mode_cmd, obj, num_planes, &rockchip_drm_fb_funcs);if (ret) { -DRM_DEV_ERROR (dev->dev, -"Failed to initialize framebuffer: %d\n" , - ret);kfree (fb);return ERR_PTR (ret); }
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v5 34/34 drm/rockchip: Add support for afbc
In reply to Andrzej PietrasiewiczThis patch adds support for afbc handling. afbc is a compressed format which reduces the necessary memory bandwidth.
# Conflicts:
# drivers/gpu/drm/rockchip/rockchip_drm_fb.c
--- drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 105 +++++++++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 147 ++++++++++++++++++-- drivers/gpu/drm/rockchip/rockchip_drm_vop.h | 12 ++ drivers/gpu/drm/rockchip/rockchip_vop_reg.c | 83 ++++++++++- 4 files changed, 329 insertions(+), 18 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +98 -7
@@ -18,6 +18,7 @@#include "rockchip_drm_fb.h" #include "rockchip_drm_gem.h" +#define ROCKCHIP_MAX_AFBC_WIDTH 2560static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = { .destroy = drm_gem_fb_destroy,
@@ -25,32 +26,122 @@ static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = { .dirty = drm_atomic_helper_dirtyfb, }; +static int rockchip_afbc_post_check (struct drm_afbc_framebuffer *afbc_fb) +{ +if (afbc_fb->offset) { +DRM_WARN ("AFBC plane offset must be zero!\n" ); +return -EINVAL ; + } + +if (afbc_fb->block_width !=16 || afbc_fb->block_height !=16 ) { +DRM_WARN ("Unsupported AFBC block w/h [%d/%d]\n" , afbc_fb->block_width, afbc_fb->block_height); +return -EINVAL ; + } + +if (afbc_fb->aligned_width >ROCKCHIP_MAX_AFBC_WIDTH ) { +DRM_WARN ("Unsupported width %d>%d\n" , afbc_fb->aligned_width,ROCKCHIP_MAX_AFBC_WIDTH ); +return -EINVAL ; + } + +return 0 ; +} +static struct drm_framebuffer *rockchip_fb_alloc (struct drm_device *dev,const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object **obj,unsigned int num_planes) { -struct drm_framebuffer *fb; +struct drm_afbc_framebuffer *afbc_fb; +struct drm_size_check check = {0 };int ret; - fb =kzalloc (sizeof (*fb),GFP_KERNEL ); -if (!fb) + afbc_fb =kzalloc (sizeof (*afbc_fb),GFP_KERNEL ); +if (!afbc_fb)return ERR_PTR (-ENOMEM ); - ret =drm_gem_fb_init_with_funcs (fb, dev, mode_cmd, obj, num_planes, &rockchip_drm_fb_funcs); +if (drm_is_afbc (mode_cmd->modifier[0 ])) { +const struct drm_format_info *info =drm_get_format_info (dev, mode_cmd); + + afbc_fb->bpp = info->cpp[0 ] *8 ; + check.data = afbc_fb; + } + + ret =drm_gem_fb_size_check2 (dev, mode_cmd, &check, obj);if (ret) { -kfree (fb); +kfree (afbc_fb);return ERR_PTR (ret); } -return fb; +if (drm_is_afbc (mode_cmd->modifier[0 ])) +if (rockchip_afbc_post_check (afbc_fb)) { +kfree (afbc_fb); +return ERR_PTR (-EINVAL ); + } + + ret =drm_gem_fb_init_with_funcs (&afbc_fb->base, dev, mode_cmd, obj, num_planes, &rockchip_drm_fb_funcs); +if (ret) { +kfree (afbc_fb); +return ERR_PTR (ret); + } + +return &afbc_fb->base; }static const struct drm_mode_config_helper_funcs rockchip_mode_config_helpers = { .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm, }; + +static struct drm_framebuffer * +rockchip_fb_create (struct drm_device *dev,struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd) +{ +struct drm_afbc_framebuffer *afbc_fb; +struct drm_size_check check = {0 }; +struct drm_gem_object *objs[4 ]; +int ret, i, num_planes; + + afbc_fb =kzalloc (sizeof (*afbc_fb),GFP_KERNEL ); +if (!afbc_fb) +return ERR_PTR (-ENOMEM ); + +if (drm_is_afbc (mode_cmd->modifier[0 ])) { +const struct drm_format_info *info =drm_get_format_info (dev, mode_cmd); + + afbc_fb->bpp = info->cpp[0 ] *8 ; + check.data = afbc_fb; + } + + ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); +if (ret <0 ) + goto err_free; + num_planes = ret; + + ret =drm_gem_fb_size_check2 (dev, mode_cmd, &check, objs); +if (ret) + goto err_cleanup; + +if (drm_is_afbc (mode_cmd->modifier[0 ])) +if (rockchip_afbc_post_check (afbc_fb)) { + ret = -EINVAL ; + goto err_cleanup; + } + + ret =drm_gem_fb_init_with_funcs (&afbc_fb->base, dev, mode_cmd, objs, num_planes, &rockchip_drm_fb_funcs); +if (ret) + goto err_cleanup; + +return &afbc_fb->base; + +err_cleanup: +for (i =0 ; i < num_planes; ++i) +drm_gem_object_put_unlocked (objs[i]); +err_free: +kfree (afbc_fb); +return ERR_PTR (ret); +} +static const struct drm_mode_config_funcs rockchip_drm_mode_config_funcs = { - .fb_create = drm_gem_fb_create_with_dirty, + .fb_create = rockchip_fb_create, .output_poll_changed = drm_fb_helper_output_poll_changed, .atomic_check = drm_atomic_helper_check, .atomic_commit = drm_atomic_helper_commit,
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +138 -9
240 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_vop.h +12 -0
@@ -34,6 +34,16 @@ struct vop_reg {bool relaxed; }; +struct vop_afbc { +struct vop_reg enable; +struct vop_reg win_sel; +struct vop_reg format; +struct vop_reg hreg_block_split; +struct vop_reg pic_size; +struct vop_reg hdr_ptr; +struct vop_reg rstn; +}; +struct vop_modeset {struct vop_reg htotal_pw;struct vop_reg hact_st_end;
@@ -134,6 +144,7 @@ struct vop_win_phy {const struct vop_scl_regs *scl;const uint32_t *data_formats;uint32_t nformats; +const uint64_t *format_modifiers;struct vop_reg enable;struct vop_reg gate;
@@ -173,6 +184,7 @@ struct vop_data {const struct vop_misc *misc;const struct vop_modeset *modeset;const struct vop_output *output; +const struct vop_afbc *afbc;const struct vop_win_yuv2yuv_data *win_yuv2yuv;const struct vop_win_data *win;unsigned int win_size;
drivers/gpu/drm/rockchip/rockchip_vop_reg.c +81 -2
198 lines not on this page · raw message
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv5 34/34] drm/rockchip: Add support for afbc
Quoted 33 lines · On Tue, 17 Dec 2019 15:50:20 +0100 Andrzej Pietrasiewicz…
static const struct
drm_mode_config_funcsrockchip_drm_mode_config_funcs= {drivers/gpu/drm/rockchip/rockchip_drm_fb.c +1
-1- .fb_create = drm_gem_fb_create_with_dirty, + .fb_create = rockchip_fb_create, .output_poll_changed = drm_fb_helper_output_poll_changed, .atomic_check = drm_atomic_helper_check, .atomic_commit = drm_atomic_helper_commit,drivers/gpu/drm/rockchip/rockchip_drm_vop.c +12
-0@@ -91,9 +91,21 @@#define VOP_WIN_TO_INDEX (vop_win) \ ((vop_win) - (vop_win)->vop->win) +#define VOP_AFBC_SET (vop, name, v) \ + do { \ + if ((vop)->data->afbc) \ + vop_reg_set((vop), &(vop)->data->afbc->name, 0, ~0, v, #name); \ + } while (0) +#define to_vop (x) container_of(x, struct vop, crtc)#define to_vop_win (x) container_of(x, struct vop_win, base) +#define AFBC_FMT_RGB565 0x0 +#define AFBC_FMT_U8U8U8U8 0x5 +#define AFBC_FMT_U8U8U8 0x4 + +#define AFBC_TILE_16x16 BIT(4) +/* * The coefficients of the following matrix are all fixed points. * The format is S2.10 for the 3x3 part of the matrix, and S9.12 for the offsets.
drivers/gpu/drm/rockchip/rockchip_drm_vop.c struct vop { · line 181
Quoted 4 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +1
-0@@ -166,6 +178,7 @@ struct vop {/* optional internal rgb encoder */ struct rockchip_rgb *rgb; +struct vop_win *afbc_win;
Looks like something that should be in the VOP specialized crtc_state. Also, do we really need a vop_win pointer or can it be replaced by an index directly?
Quoted 70 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +49
-0struct vop_win win[]; };@@ -274,6 +287,29 @@ static enum vop_data_format vop_convert_format(uint32_t format) } } +static int vop_convert_afbc_format (uint32_t format) +{ +switch (format) { +case DRM_FORMAT_XRGB8888 : +case DRM_FORMAT_ARGB8888 : +case DRM_FORMAT_XBGR8888 : +case DRM_FORMAT_ABGR8888 : +return AFBC_FMT_U8U8U8U8 ; +case DRM_FORMAT_RGB888 : +case DRM_FORMAT_BGR888 : +return AFBC_FMT_U8U8U8 ; +case DRM_FORMAT_RGB565 : +case DRM_FORMAT_BGR565 : +return AFBC_FMT_RGB565 ; +/* either of the below should not be reachable */ +default : +DRM_WARN_ONCE ("unsupported AFBC format[%08x]\n" , format); +return -EINVAL ; + } + +return -EINVAL ; +} +static uint16_t scl_vop_cal_scale (enum scale_mode mode,uint32_t src,uint32_t dst,bool is_horizontal,int vsu_mode,int *vskiplines)@@ -598,6 +634,15 @@ static int vop_enable(struct drm_crtc *crtc, struct drm_crtc_state *old_state)vop_win_disable (vop, vop_win); } } + +if (vop->data->afbc) { +/* +* Disable AFBC and forget there was a vop window with AFBC +*/ +VOP_AFBC_SET (vop, enable,0 ); + vop->afbc_win =NULL ; + } +spin_unlock (&vop->reg_lock);vop_cfg_done (vop);@@ -710,6 +755,37 @@ static void vop_plane_destroy(struct drm_plane *plane)drm_plane_cleanup (plane); } +static bool rockchip_afbc (u64 modifier) +{ +return modifier ==DRM_FORMAT_MOD_ARM_AFBC (AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 |AFBC_FORMAT_MOD_SPARSE ); +} + +static bool rockchip_mod_supported (struct drm_plane *plane, +u32 format,u64 modifier) +{ +const struct drm_format_info *info; + +if (WARN_ON (modifier ==DRM_FORMAT_MOD_INVALID )) +return false; + +if (modifier ==DRM_FORMAT_MOD_LINEAR ) +return true; + +if (!rockchip_afbc (modifier)) {
drivers/gpu/drm/rockchip/rockchip_drm_vop.c static void vop_plane_destroy(struct drm_plane *plane) · line 784
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +10
-0+DRM_DEBUG_KMS ("Unsupported format modifer 0x%llx\n" , modifier); + +return false; + } + + info =drm_format_info (format); +if (info->num_planes !=1 ) { +DRM_DEBUG_KMS ("AFBC buffers expect one plane\n" ); +return false; + }
Should we have a call to vop_convert_afbc_format() to make sure AFBC can be applied to this specific format?
Quoted 8 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +4
-0+ +return true; +} +static int vop_plane_atomic_check (struct drm_plane *plane,struct drm_plane_state *state) {
drivers/gpu/drm/rockchip/rockchip_drm_vop.c static int vop_plane_atomic_check(struct drm_plane *plane, · line 799
Quoted 9 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +2
-4@@ -719,10 +795,8 @@ static int vop_plane_atomic_check(struct drm_plane *plane,struct vop_win *vop_win =to_vop_win (plane);const struct vop_win_data *win = vop_win->data;int ret; -int min_scale = win->phy->scl ?FRAC_16_16 (1 ,8 ) : -DRM_PLANE_HELPER_NO_SCALING ; -int max_scale = win->phy->scl ?FRAC_16_16 (8 ,1 ) : -DRM_PLANE_HELPER_NO_SCALING ; +int min_scale = win->phy->scl ?FRAC_16_16 (1 ,8 ) :DRM_PLANE_HELPER_NO_SCALING ; +int max_scale = win->phy->scl ?FRAC_16_16 (8 ,1 ) :DRM_PLANE_HELPER_NO_SCALING ;
Looks like those coding-style fixes have nothing to do in this patch :).
drivers/gpu/drm/rockchip/rockchip_drm_vop.c static int vop_plane_atomic_check(struct drm_plane *plane, · line 808
Quoted 11 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +1
-3if (!crtc || !fb)return 0 ;@@ -731,9 +805,7 @@ static int vop_plane_atomic_check(struct drm_plane *plane,if (WARN_ON (!crtc_state))return -EINVAL ; - ret =drm_atomic_helper_check_plane_state (state, crtc_state, - min_scale, max_scale, - true, true); + ret =drm_atomic_helper_check_plane_state (state, crtc_state, min_scale, max_scale, true, true);
Same here, plus, following the 80 char rule when it doesn't hurt readability is a good thing I think.
Quoted 12 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +5
-0if (ret)return ret;@@ -758,6 +830,31 @@ static int vop_plane_atomic_check(struct drm_plane *plane,return -EINVAL ; } +if (rockchip_afbc (fb->modifier)) { +struct vop *vop =to_vop (crtc); + +if (!vop->data->afbc) { +DRM_ERROR ("vop does not support AFBC\n" );
drivers/gpu/drm/rockchip/rockchip_drm_vop.c static int vop_plane_atomic_check(struct drm_plane *plane, · line 847
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +10
-0+return -EINVAL ; + } + + ret =vop_convert_afbc_format (fb->format->format); +if (ret <0 ) +return ret; + +if (state->src.x1 || state->src.y1) { +DRM_ERROR ("afbc does not support offset display\n" ); +DRM_ERROR ("xpos=%d, ypos=%d, offset=%d\n" , state->src.x1, state->src.y1, fb->offsets[0 ]);
Why splitting that in 2 error messages?
drivers/gpu/drm/rockchip/rockchip_drm_vop.c static int vop_plane_atomic_check(struct drm_plane *plane, · line 853
Quoted 6 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +6
-0+return -EINVAL ; + } + +if (state->rotation && state->rotation !=DRM_MODE_ROTATE_0 ) { +DRM_ERROR ("afbc does not support rotation\n" ); +DRM_ERROR ("rotation=%d\n" , state->rotation);
Ditto.
Quoted 34 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +16
-0+return -EINVAL ; + } + } +return 0 ; }@@ -773,6 +870,11 @@ static void vop_plane_atomic_disable(struct drm_plane *plane,spin_lock (&vop->reg_lock);vop_win_disable (vop, vop_win); +/* +* Forget about the AFBC window if it is being disabled +*/ +if (vop_win == vop->afbc_win) + vop->afbc_win =NULL ;spin_unlock (&vop->reg_lock); }@@ -812,6 +914,13 @@ static void vop_plane_atomic_update(struct drm_plane *plane,if (WARN_ON (!vop->is_enabled))return ; +/* +* If updating the AFBC window then assume that +* after the update there will be no AFBC window. +*/ +if (vop_win == vop->afbc_win) + vop->afbc_win =NULL ; +if (!state->visible) {vop_plane_atomic_disable (plane, old_state);return ;
drivers/gpu/drm/rockchip/rockchip_drm_vop.c static void vop_plane_atomic_update(struct drm_plane *plane, · line 963
Quoted 9 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +6
-0@@ -846,6 +955,21 @@ static void vop_plane_atomic_update(struct drm_plane *plane,spin_lock (&vop->reg_lock); +if (rockchip_afbc (fb->modifier)) { +int afbc_format =vop_convert_afbc_format (fb->format->format); + +VOP_AFBC_SET (vop, format, afbc_format | AFBC_TILE_16x16); +VOP_AFBC_SET (vop, hreg_block_split,0 ); +VOP_AFBC_SET (vop, win_sel,VOP_WIN_TO_INDEX (vop_win));
IIUC, only one plane can use AFBC at a given time, but you don't seem to check the value of vop->afbc_win in your atomic_check. What happens if the user tries to enable this modifier on 2+ planes?
Quoted 13 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +9
-0+VOP_AFBC_SET (vop, hdr_ptr, dma_addr); +VOP_AFBC_SET (vop, pic_size, act_info); + +/* +* The window being udated becomes the AFBC window +*/ + vop->afbc_win = vop_win; + } +VOP_WIN_SET (vop, win, format, format);VOP_WIN_SET (vop, win, yrgb_vir,DIV_ROUND_UP (fb->pitches[0 ],4 ));VOP_WIN_SET (vop, win, yrgb_mst, dma_addr);
drivers/gpu/drm/rockchip/rockchip_drm_vop.c static const struct drm_plane_funcs vop_plane_funcs = { · line 1129
Quoted 5 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +1
-0@@ -1001,6 +1125,7 @@ static const struct drm_plane_funcs vop_plane_funcs = { .reset = drm_atomic_helper_plane_reset, .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, + .format_mod_supported = rockchip_mod_supported, };
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv5 00/34] Add AFBC support for Rockchip
In reply to Andrzej PietrasiewiczHi All,
A gentle reminder.
Please also see inline:
W dniu 17.12.2019 o 15:49, Andrzej Pietrasiewicz pisze:
Quoted 14 lines
This series adds AFBC support for Rockchip. It is inspired by:
This is the fifth iteration of the afbc series. Between v3 and v4 a lot of rework has been done, the main goal of which was to move all afbc-related checks to helpers, so that core does not deal with it.
A new struct
drm_afbc_framebufferis added, which stores afbc-related driver-specific data. Because of that, in drivers that wish to use this feature, the struct must be allocated directly in the driver code rather than inside helpers, so the first portion of the patchset does the necessary refactoring.
Quoted 4 lines
Then, there are 3 users of afbc: komeda, malidp and, finally, rockchip, the latter being the ultimate purpose of this work and the 3 subsequent portions of the patchset move komeda and malidp to generic helpers and add afbc support to rockchip.
If changes in komeda and malidp is too much to digest at a time I can focus on rockchip only. This would amount to patches 1-4 and 33-34. After all the ultimate purpose of this work and time spent on it is landing afbc support for rockchip.
Regards,
Andrzej
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Liviu Dudau
maintainerRe: [PATCHv5 00/34] Add AFBC support for Rockchip
Hi Andrzej,
Sorry for the delay in reviewing the patches. I am hoping to get through the review early next week if that is OK with you.
Best regards,
Liviu
Quoted 34 lines · Andrzej Pietrasiewicz
Hi All,
A gentle reminder.
Please also see inline:
W dniu 17.12.2019 o 15:49, Andrzej Pietrasiewicz pisze:
Quoted 14 lines
This series adds AFBC support for Rockchip. It is inspired by:
This is the fifth iteration of the afbc series. Between v3 and v4 a lot of rework has been done, the main goal of which was to move all afbc-related checks to helpers, so that core does not deal with it.
A new struct
drm_afbc_framebufferis added, which stores afbc-related driver-specific data. Because of that, in drivers that wish to use this feature, the struct must be allocated directly in the driver code rather than inside helpers, so the first portion of the patchset does the necessary refactoring.Quoted 4 lines
Then, there are 3 users of afbc: komeda, malidp and, finally, rockchip, the latter being the ultimate purpose of this work and the 3 subsequent portions of the patchset move komeda and malidp to generic helpers and add afbc support to rockchip.
If changes in komeda and malidp is too much to digest at a time I can focus on rockchip only. This would amount to patches 1-4 and 33-34. After all the ultimate purpose of this work and time spent on it is landing afbc support for rockchip.
Regards,
Andrzej
Signature · 12 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-develRe: [PATCHv5 00/34] Add AFBC support for Rockchip
Hi Liviu,
W dniu 30.01.2020 o 12:44, Liviu Dudau pisze:
Quoted 4 lines
Hi Andrzej,
Sorry for the delay in reviewing the patches. I am hoping to get through the review early next week if that is OK with you.
Thanks, that would be great.
Andrzej
Quoted 40 lines
Best regards,
LiviuQuoted 34 lines · Andrzej Pietrasiewicz
Hi All,
A gentle reminder.
Please also see inline:
W dniu 17.12.2019 o 15:49, Andrzej Pietrasiewicz pisze:
Quoted 14 lines
This series adds AFBC support for Rockchip. It is inspired by:
This is the fifth iteration of the afbc series. Between v3 and v4 a lot of rework has been done, the main goal of which was to move all afbc-related checks to helpers, so that core does not deal with it.
A new struct
drm_afbc_framebufferis added, which stores afbc-related driver-specific data. Because of that, in drivers that wish to use this feature, the struct must be allocated directly in the driver code rather than inside helpers, so the first portion of the patchset does the necessary refactoring.Quoted 4 lines
Then, there are 3 users of afbc: komeda, malidp and, finally, rockchip, the latter being the ultimate purpose of this work and the 3 subsequent portions of the patchset move komeda and malidp to generic helpers and add afbc support to rockchip.
If changes in komeda and malidp is too much to digest at a time I can focus on rockchip only. This would amount to patches 1-4 and 33-34. After all the ultimate purpose of this work and time spent on it is landing afbc support for rockchip.
Regards,
Andrzej
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv5 00/34] Add AFBC support for Rockchip
In reply to Andrzej PietrasiewiczHi All again,
@malidp and komeda folks: I kindly ask you to have your say. If there is no interest from you (which is ok with me) I will resend the series dropping the komeda and malidp part.
Andrzej
W dniu 30.01.2020 o 10:08, Andrzej Pietrasiewicz pisze:
Quoted 27 lines
Hi All,
A gentle reminder.
Please also see inline:
W dniu 17.12.2019 o 15:49, Andrzej Pietrasiewicz pisze:
Quoted 15 lines
This series adds AFBC support for Rockchip. It is inspired by:
This is the fifth iteration of the afbc series. Between v3 and v4 a lot of rework has been done, the main goal of which was to move all afbc-related checks to helpers, so that core does not deal with it.
A new struct
drm_afbc_framebufferis added, which stores afbc-related driver-specific data. Because of that, in drivers that wish to use this feature, the struct must be allocated directly in the driver code rather than inside helpers, so the first portion of the patchset does the necessary refactoring.Quoted 4 lines
Then, there are 3 users of afbc: komeda, malidp and, finally, rockchip, the latter being the ultimate purpose of this work and the 3 subsequent portions of the patchset move komeda and malidp to generic helpers and add afbc support to rockchip.
Quoted 8 lines
If changes in komeda and malidp is too much to digest at a time I can focus on rockchip only. This would amount to patches 1-4 and 33-34. After all the ultimate purpose of this work and time spent on it is landing afbc support for rockchip.
Regards,
Andrzej
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Liviu Dudau
maintainerRe: [PATCHv5 00/34] Add AFBC support for Rockchip
Quoted 1 line · Andrzej Pietrasiewicz
Hi All again,
Hi Andrzej,
Quoted 4 lines
@malidp and komeda folks: I kindly ask you to have your say. If there is no interest from you (which is ok with me) I will resend the series dropping the komeda and malidp part.
I *am* trying to test your patches, unfortunately my colleagues in China have been kept out of the office for longer than I thought they will, so it is a bit difficult to coordinate.
As a backup, if I don't manage to give you feedback by end of Tuesday, please re-send the patches with malidp and rockchip and skip the komeda ones.
Best regards,
Liviu
Quoted 40 lines
Andrzej
W dniu 30.01.2020 o 10:08, Andrzej Pietrasiewicz pisze:
Quoted 35 lines
Hi All,
A gentle reminder.
Please also see inline:
W dniu 17.12.2019 o 15:49, Andrzej Pietrasiewicz pisze:
Quoted 15 lines
This series adds AFBC support for Rockchip. It is inspired by:
This is the fifth iteration of the afbc series. Between v3 and v4 a lot of rework has been done, the main goal of which was to move all afbc-related checks to helpers, so that core does not deal with it.
A new struct
drm_afbc_framebufferis added, which stores afbc-related driver-specific data. Because of that, in drivers that wish to use this feature, the struct must be allocated directly in the driver code rather than inside helpers, so the first portion of the patchset does the necessary refactoring.Quoted 4 lines
Then, there are 3 users of afbc: komeda, malidp and, finally, rockchip, the latter being the ultimate purpose of this work and the 3 subsequent portions of the patchset move komeda and malidp to generic helpers and add afbc support to rockchip.
If changes in komeda and malidp is too much to digest at a time I can focus on rockchip only. This would amount to patches 1-4 and 33-34. After all the ultimate purpose of this work and time spent on it is landing afbc support for rockchip.
Regards,
Andrzej
Signature · 12 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-develRe: [PATCHv5 00/34] Add AFBC support for Rockchip
In reply to Andrzej PietrasiewiczQuoted 125 lines · Andrzej Pietrasiewicz
This series adds AFBC support for Rockchip. It is inspired by:
This is the fifth iteration of the afbc series. Between v3 and v4 a lot of rework has been done, the main goal of which was to move all afbc-related checks to helpers, so that core does not deal with it.
A new struct
drm_afbc_framebufferis added, which stores afbc-related driver-specific data. Because of that, in drivers that wish to use this feature, the struct must be allocated directly in the driver code rather than inside helpers, so the first portion of the patchset does the necessary refactoring.Then, there are 3 users of afbc: komeda, malidp and, finally, rockchip, the latter being the ultimate purpose of this work and the 3 subsequent portions of the patchset move komeda and malidp to generic helpers and add afbc support to rockchip.
The idea is to make all afbc users follow a similar pattern. In
fb_create()they allocate structdrm_afbc_framebuffer, do their specific checks which can be done before object lookups, do object lookups and a special version of a size check, which understands structdrm_afbc_framebuffer, followed by any other driver-specific checks and initializing the gem object. The helpers for the common parts are factored out so that drivers can use them.The komeda driver has been the farthest away from such a pattern, so it required most changes. However, due to the fact that I don't have any komeda hardware I did the changes to komeda in an incremental fashion with a series of (usually) very small, easy to understand steps. malidp was pretty straightforward, and rockchip's afbc checks follow the pattern.
I kindly ask for reviewing the series. I need to mention that my ultimate goal is merging afbc for rockchip and I don't have other hardware, so some help from malidp and komeda developers/maintainers would be appreciated.
@Liviu, @James, @Mihail, @Brian: a kind request to you to have a look and test the patchset, as I don't have appropriate hardware.
Rebased onto drm-misc-next.
v4..v5:
- used proper way of subclassingdrm_framebuffer(Daniel Vetter)
- added documentation to exported functions (Liviu Dudau)
- reordered new functions indrm_gem_framebuffer_helper.cto make a saner diff (Liviu Dudau)
- used "2" suffix instead of "_special" for the special version of size checks (Liviu Dudau)
- dropped unnecessarily added condition indrm_get_format_info()(Liviu Dudau)
- dropped "block_size= 0;" trick inframebuffer_check()(Daniel Vetter)
- relaxed sticking to 80 characters per line rule in some casesv3..v4:
- addressed (some) comments from Daniel Stone, Ezequiel Garcia, Daniel Vetter and James Qian Wang - thank you for input
- refactored helpers to ease accommodating drivers with afbc needs
- moved afbc checks to helpers
- converted komeda, malidp and (the newly added) rockchip to use the afbc helpers
- eliminated a separate, dedicated source code filev2..v3:
- addressed (some) comments from Daniel Stone, Liviu Dudau, Daniel Vetter and Brian Starkey - thank you all
In this iteration some rework has been done. The checking logic is now moved to
framebuffer_check()so it is common to all drivers. But the common part is not good for komeda, so this series is not good for merging yet. I kindly ask for feedback whether the changes are in the right direction. I also kindly ask for input on how to accommodate komeda.The
CONFIG_DRM_AFBCoption has been eliminated in favour of addingdrm_afbc.ctodrm_kms_helper.v1..v2:
- addressed comments from Daniel Stone, Ayan Halder, Mihail Atanassov
- coding style fixes** BLURB HERE ***Andrzej Pietrasiewicz (34):
drm/core: Add afbc helper functions
drm/gem-fb-helper: Allow drivers to allocate structdrm_framebufferon
their own
drm/gem-fb-helper: Add special version ofdrm_gem_fb_size_checkdrm/gem-fb-helper: Add generic afbc size checks drm/komeda: Use afbc helper
drm/komeda: Move checking src coordinates tokomeda_fb_createdrm/komeda: Use the already available local variable drm/komeda: Retrievedrm_format_infoonce
drm/komeda: Explicitly require 1 plane for AFBC drm/komeda: Move pitches comparison tokomeda_fb_createdrm/komeda: Provide and usekomeda_fb_get_pixel_addrvariant not
requiring a fb
drm/komeda: Factor out object lookups for non-afbc case drm/komeda: Makekomeda_fb_none_size_checkindependent from
framebuffer
drm/komeda: Factor out object lookups for afbc case drm/komeda: Freekomeda_fb_afbc_size_checkfrom framebuffer dependency drm/komeda: Simplify error handling
drm/komeda: Move object lookup before size checks drm/komeda: Move object assignments to framebuffer to after size
checks
drm/komeda: Make the size checks independent from framebuffer
structure
drm/komeda: Move helper invocation to after size checks drm/komeda: Use helper for common tasks
drm/komeda: Use return value ofdrm_gem_fb_lookupdrm/komeda: Use special helper for non-afbc size checks drm/komeda: Factor in the invocation of special helper drm/komeda: Use special helper for afbc case size check drm/komeda: Factor in the invocation of special helper, afbc case drm/komeda: Move special helper invocation outside if-else drm/komeda: Move to helper checking afbc buffer size drm/arm/malidp: Make verify funcitons invocations independent drm/arm/malidp: Integrate verify functions
drm/arm/malidp: Factor in afbc framebuffer verification drm/arm/malidp: Use generic helpers for afbc checks drm/rockchip: Use helper for common task
drm/rockchip: Add support for afbc
Quoted 15 lines
.../arm/display/komeda/d71/d71_component.c | 6 +- .../arm/display/komeda/komeda_framebuffer.c | 273 ++++++++--------- .../arm/display/komeda/komeda_framebuffer.h | 21 +- .../display/komeda/komeda_pipeline_state.c | 14 +- drivers/gpu/drm/arm/malidp_drv.c | 155 ++++------ drivers/gpu/drm/drm_fourcc.c | 53 ++++ drivers/gpu/drm/drm_gem_framebuffer_helper.c | 287 ++++++++++++++---- drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 111 ++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 147 ++++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop.h | 12 + drivers/gpu/drm/rockchip/rockchip_vop_reg.c | 83 ++++- include/drm/drm_fourcc.h | 4 + include/drm/drm_framebuffer.h | 50 +++ include/drm/drm_gem_framebuffer_helper.h | 34 +++ 14 files changed, 907 insertions(+), 343 deletions(-)
I think this isn't achieving it's goal. Even if we take out the rockchip enabling patch at the ent it's still like 200 lines more for something that's supposed to unify and clean code up.
Plus it looks enormously complicated, something that I missed in my previous quick glance. Hence proposal for all the things you're going to add to drm core/helpers, and not a bit more :-)
int
drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb,
struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd, const struct drm_framebuffer_funcs *funcs);
This is going to do _exactly_ what drm_gem_fb_create_with_funcs already does, except it doesn't do the kzalloc (so that would need to be moved out so we can share code). No other additional sub-parts exposed, I think that's just not worth it in this case. So none of this size check stuff.
2nd piece, your drm_afbc_framebuffer as in patch 4, with the subclassing.
3rd piece, again in drm_gem_framebuffer_helper.c:
int drm_gem_afbc_init(struct drm_afbc_framebuffer *afbc_fb);
Drivers are supposed to call this after they've a) allocated their fb structure, containing the drm_afbc_framebuffer somewhere and b) called drm_gem_fb_init_with_funcs(). This function is going to fill out all the additional fields, and this function is also going to do all the size validation and everything else.
Nothing else, so no finer split up of helper check functions, or of afbc computation functions, or of anything else. That mix of split-out stuff and mix of computed values in drm_afbc_framebuffer but also functions that compute afbc values from modifiers and fb sizes seems to just lead to a huge confusion and not actually to a code reduction. So
- none of the functions exported in patch 1, just stuff them into drm_gem_framebuffer_helper.c.
- none of the helper subfunctions you export in patch 2, or adapt in patch 3
- Also not this size check structure with the data pointer you add in patch 4.
The bikeshed I'm still seeing here is whether drm_afbc_framebuffer and the drm_gem_afbc_init() function should be considered core stuff or not, I guess you can make an argument for either.
This should also make conversion easier since as a first steps you'd do:
- Put the new drm_afbc_framebuffer in place and adjust all tha fb_to_komeda functions and upcasting (this should be mechanically)
- Add the call to drm_gem_afbc_init().
- Starting using the new values in drm_afbc_framebuffer and slowly delete code
- Optional, but would be nice to do: Convert driver over to drm_gem_fb_init_with_funcs().
Thoughts?
Cheers, Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCHv5 00/34] Add AFBC support for Rockchip
Quoted 197 lines · Daniel Vetter
Quoted 125 lines · Andrzej Pietrasiewicz
This series adds AFBC support for Rockchip. It is inspired by:
This is the fifth iteration of the afbc series. Between v3 and v4 a lot of rework has been done, the main goal of which was to move all afbc-related checks to helpers, so that core does not deal with it.
A new struct
drm_afbc_framebufferis added, which stores afbc-related driver-specific data. Because of that, in drivers that wish to use this feature, the struct must be allocated directly in the driver code rather than inside helpers, so the first portion of the patchset does the necessary refactoring.Then, there are 3 users of afbc: komeda, malidp and, finally, rockchip, the latter being the ultimate purpose of this work and the 3 subsequent portions of the patchset move komeda and malidp to generic helpers and add afbc support to rockchip.
The idea is to make all afbc users follow a similar pattern. In
fb_create()they allocate structdrm_afbc_framebuffer, do their specific checks which can be done before object lookups, do object lookups and a special version of a size check, which understands structdrm_afbc_framebuffer, followed by any other driver-specific checks and initializing the gem object. The helpers for the common parts are factored out so that drivers can use them.The komeda driver has been the farthest away from such a pattern, so it required most changes. However, due to the fact that I don't have any komeda hardware I did the changes to komeda in an incremental fashion with a series of (usually) very small, easy to understand steps. malidp was pretty straightforward, and rockchip's afbc checks follow the pattern.
I kindly ask for reviewing the series. I need to mention that my ultimate goal is merging afbc for rockchip and I don't have other hardware, so some help from malidp and komeda developers/maintainers would be appreciated.
@Liviu, @James, @Mihail, @Brian: a kind request to you to have a look and test the patchset, as I don't have appropriate hardware.
Rebased onto drm-misc-next.
v4..v5:
- used proper way of subclassingdrm_framebuffer(Daniel Vetter)
- added documentation to exported functions (Liviu Dudau)
- reordered new functions indrm_gem_framebuffer_helper.cto make a saner diff (Liviu Dudau)
- used "2" suffix instead of "_special" for the special version of size checks (Liviu Dudau)
- dropped unnecessarily added condition indrm_get_format_info()(Liviu Dudau)
- dropped "block_size= 0;" trick inframebuffer_check()(Daniel Vetter)
- relaxed sticking to 80 characters per line rule in some casesv3..v4:
- addressed (some) comments from Daniel Stone, Ezequiel Garcia, Daniel Vetter and James Qian Wang - thank you for input
- refactored helpers to ease accommodating drivers with afbc needs
- moved afbc checks to helpers
- converted komeda, malidp and (the newly added) rockchip to use the afbc helpers
- eliminated a separate, dedicated source code filev2..v3:
- addressed (some) comments from Daniel Stone, Liviu Dudau, Daniel Vetter and Brian Starkey - thank you all
In this iteration some rework has been done. The checking logic is now moved to
framebuffer_check()so it is common to all drivers. But the common part is not good for komeda, so this series is not good for merging yet. I kindly ask for feedback whether the changes are in the right direction. I also kindly ask for input on how to accommodate komeda.The
CONFIG_DRM_AFBCoption has been eliminated in favour of addingdrm_afbc.ctodrm_kms_helper.v1..v2:
- addressed comments from Daniel Stone, Ayan Halder, Mihail Atanassov
- coding style fixes** BLURB HERE ***Andrzej Pietrasiewicz (34):
drm/core: Add afbc helper functions
drm/gem-fb-helper: Allow drivers to allocate structdrm_framebufferon
their own
drm/gem-fb-helper: Add special version ofdrm_gem_fb_size_checkdrm/gem-fb-helper: Add generic afbc size checks drm/komeda: Use afbc helper
drm/komeda: Move checking src coordinates tokomeda_fb_createdrm/komeda: Use the already available local variable drm/komeda: Retrievedrm_format_infoonce
drm/komeda: Explicitly require 1 plane for AFBC drm/komeda: Move pitches comparison tokomeda_fb_createdrm/komeda: Provide and usekomeda_fb_get_pixel_addrvariant not
requiring a fb
drm/komeda: Factor out object lookups for non-afbc case drm/komeda: Makekomeda_fb_none_size_checkindependent from
framebuffer
drm/komeda: Factor out object lookups for afbc case drm/komeda: Freekomeda_fb_afbc_size_checkfrom framebuffer dependency drm/komeda: Simplify error handling
drm/komeda: Move object lookup before size checks drm/komeda: Move object assignments to framebuffer to after size
checks
drm/komeda: Make the size checks independent from framebuffer
structure
drm/komeda: Move helper invocation to after size checks drm/komeda: Use helper for common tasks
drm/komeda: Use return value ofdrm_gem_fb_lookupdrm/komeda: Use special helper for non-afbc size checks drm/komeda: Factor in the invocation of special helper drm/komeda: Use special helper for afbc case size check drm/komeda: Factor in the invocation of special helper, afbc case drm/komeda: Move special helper invocation outside if-else drm/komeda: Move to helper checking afbc buffer size drm/arm/malidp: Make verify funcitons invocations independent drm/arm/malidp: Integrate verify functions
drm/arm/malidp: Factor in afbc framebuffer verification drm/arm/malidp: Use generic helpers for afbc checks drm/rockchip: Use helper for common task
drm/rockchip: Add support for afbcQuoted 15 lines
.../arm/display/komeda/d71/d71_component.c | 6 +- .../arm/display/komeda/komeda_framebuffer.c | 273 ++++++++--------- .../arm/display/komeda/komeda_framebuffer.h | 21 +- .../display/komeda/komeda_pipeline_state.c | 14 +- drivers/gpu/drm/arm/malidp_drv.c | 155 ++++------ drivers/gpu/drm/drm_fourcc.c | 53 ++++ drivers/gpu/drm/drm_gem_framebuffer_helper.c | 287 ++++++++++++++---- drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 111 ++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 147 ++++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop.h | 12 + drivers/gpu/drm/rockchip/rockchip_vop_reg.c | 83 ++++- include/drm/drm_fourcc.h | 4 + include/drm/drm_framebuffer.h | 50 +++ include/drm/drm_gem_framebuffer_helper.h | 34 +++ 14 files changed, 907 insertions(+), 343 deletions(-)I think this isn't achieving it's goal. Even if we take out the rockchip enabling patch at the ent it's still like 200 lines more for something that's supposed to unify and clean code up.
Plus it looks enormously complicated, something that I missed in my previous quick glance. Hence proposal for all the things you're going to add to drm core/helpers, and not a bit more :-)
int
drm_gem_fb_init_with_funcs(structdrm_framebuffer*fb,
structdrm_device*dev, structdrm_file*file, const structdrm_mode_fb_cmd2*mode_cmd, const structdrm_framebuffer_funcs*funcs);This is going to do _exactly_ what
drm_gem_fb_create_with_funcsalready does, except it doesn't do the kzalloc (so that would need to be moved out so we can share code). No other additional sub-parts exposed, I think that's just not worth it in this case. So none of this size check stuff.2nd piece, your
drm_afbc_framebufferas in patch 4, with the subclassing.3rd piece, again in
drm_gem_framebuffer_helper.c:int
drm_gem_afbc_init(struct drm_afbc_framebuffer *afbc_fb);Drivers are supposed to call this after they've a) allocated their fb structure, containing the
drm_afbc_framebuffersomewhere and b) calleddrm_gem_fb_init_with_funcs(). This function is going to fill out all the additional fields, and this function is also going to do all the size validation and everything else.Nothing else, so no finer split up of helper check functions, or of afbc computation functions, or of anything else. That mix of split-out stuff and mix of computed values in
drm_afbc_framebufferbut also functions that compute afbc values from modifiers and fb sizes seems to just lead to a huge confusion and not actually to a code reduction. So
- none of the functions exported in patch 1, just stuff them intodrm_gem_framebuffer_helper.c.
- none of the helper subfunctions you export in patch 2, or adapt in patch 3
- Also not this size check structure with the data pointer you add in patch 4.The bikeshed I'm still seeing here is whether
drm_afbc_framebufferand thedrm_gem_afbc_init()function should be considered core stuff or not, I guess you can make an argument for either.This should also make conversion easier since as a first steps you'd do:
- Put the new
drm_afbc_framebufferin place and adjust all thafb_to_komedafunctions and upcasting (this should be mechanically)- Add the call to
drm_gem_afbc_init().
Quoted 7 lines
- Starting using the new values in
drm_afbc_framebufferand slowly delete code- Optional, but would be nice to do: Convert driver over to
drm_gem_fb_init_with_funcs().Thoughts?
I forgot to add that maybe we'll need a ->get_format_info implementation which supplies a suitable structure (with block_size == 0 to disable the checks). But I'm kinda assume that the buffer will be bigger than a compressed one, since you also have the compression metadata on top. So just keeping the size checks for uncompressed buffer, and then doing the additional validation on top, might work out.
But yeah if that fails we'll need a drm_afbc_gem_get_format_info() hook that drivers can set up.
-Daniel
Quoted 6 lines
Cheers, Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 7/36 drm/komeda: Use afbc helper
In reply to Andrzej PietrasiewiczMakes the code shorter and more readable.
--- .../drm/arm/display/komeda/komeda_framebuffer.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +3 -14
@@ -52,20 +52,9 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,return -ENOENT ; } -switch (fb->modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ) { -case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8: - alignment_w =32 ; - alignment_h =8 ; -break ; -case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16: - alignment_w =16 ; - alignment_h =16 ; -break ; -default : -WARN (1 ,"Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n" , - fb->modifier &AFBC_FORMAT_MOD_BLOCK_SIZE_MASK ); -break ; - } +if (!drm_afbc_get_superblock_wh (fb->modifier, + &alignment_w, &alignment_h)) +return -EINVAL ;/* tiled header afbc */ if (fb->modifier &AFBC_FORMAT_MOD_TILED ) {
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 8/36 drm/komeda: Move checking src coordinates to komeda_fb_create
In reply to Andrzej PietrasiewiczNext step towards unifying afbc and non-afbc cases as much as possible.
--- .../drm/arm/display/komeda/komeda_framebuffer.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +9 -5
@@ -107,9 +107,6 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb,u32 i, block_h;u64 min_size; -if (komeda_fb_check_src_coords (kfb,0 ,0 , fb->width, fb->height)) -return -EINVAL ; -for (i =0 ; i < info->num_planes; i++) { obj =drm_gem_object_lookup (file, mode_cmd->handles[i]);if (!obj) {
@@ -168,10 +165,17 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,drm_helper_mode_fill_fb_struct (dev, &kfb->base, mode_cmd); -if (kfb->base.modifier) +if (kfb->base.modifier) { ret =komeda_fb_afbc_size_check (kfb, file, mode_cmd); -else + }else { +if (komeda_fb_check_src_coords (kfb,0 ,0 , kfb->base.width, + kfb->base.height)) { +kfree (kfb); +return ERR_PTR (-EINVAL ); + } + ret =komeda_fb_none_afbc_size_check (mdev, kfb, file, mode_cmd); + }if (ret <0 ) goto err_cleanup;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 9/36 drm/komeda: Use the already available local variable
In reply to Andrzej PietrasiewiczThere is a local "info" variable which is exactly fb->format, so use it.
--- drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +1 -1
@@ -131,7 +131,7 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb, } } -if (fb->format->num_planes ==3 ) { +if (info->num_planes ==3 ) {if (fb->pitches[1 ] != fb->pitches[2 ]) {DRM_DEBUG_KMS ("The pitch[1] and [2] are not same\n" );return -EINVAL ;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 10/36 drm/komeda: Retrieve drm_format_info once
In reply to Andrzej PietrasiewiczNext step towards unifying afbc and non-afbc cases as much as possible.
--- .../drm/arm/display/komeda/komeda_framebuffer.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +11 -6
@@ -37,11 +37,12 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = { };static int -komeda_fb_afbc_size_check (struct komeda_fb *kfb,struct drm_file *file, +komeda_fb_afbc_size_check (struct komeda_fb *kfb, +const struct drm_format_info *info, +struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd) {struct drm_framebuffer *fb = &kfb->base; -const struct drm_format_info *info = fb->format;struct drm_gem_object *obj;u32 alignment_w =0 , alignment_h =0 , alignment_header, n_blocks, bpp;u64 min_size;
@@ -97,12 +98,13 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, }static int -komeda_fb_none_afbc_size_check (struct komeda_dev *mdev,struct komeda_fb *kfb, +komeda_fb_none_afbc_size_check (struct komeda_dev *mdev, +struct komeda_fb *kfb, +const struct drm_format_info *info,struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd) {struct drm_framebuffer *fb = &kfb->base; -const struct drm_format_info *info = fb->format;struct drm_gem_object *obj;u32 i, block_h;u64 min_size;
@@ -147,6 +149,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, {struct komeda_dev *mdev = dev->dev_private;struct komeda_fb *kfb; +const struct drm_format_info *info;int ret =0 , i; kfb =kzalloc (sizeof (*kfb),GFP_KERNEL );
@@ -164,9 +167,10 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, }drm_helper_mode_fill_fb_struct (dev, &kfb->base, mode_cmd); + info = kfb->base.format;if (kfb->base.modifier) { - ret =komeda_fb_afbc_size_check (kfb, file, mode_cmd); + ret =komeda_fb_afbc_size_check (kfb, info, file, mode_cmd); }else {if (komeda_fb_check_src_coords (kfb,0 ,0 , kfb->base.width, kfb->base.height)) {
@@ -174,7 +178,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,return ERR_PTR (-EINVAL ); } - ret =komeda_fb_none_afbc_size_check (mdev, kfb, file, mode_cmd); + ret =komeda_fb_none_afbc_size_check (mdev, kfb, info, file, + mode_cmd); }if (ret <0 ) goto err_cleanup;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 11/36 drm/komeda: Explicitly require 1 plane for AFBC
In reply to Andrzej PietrasiewiczApparently komeda silently assumes that there is only 1 plane in an AFBC buffer. Make this assumption explicit.
--- drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +5 -0
@@ -170,6 +170,11 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, info = kfb->base.format;if (kfb->base.modifier) { +if (info->num_planes !=1 ) { +DRM_DEBUG_KMS ("AFBC requires exactly 1 plane.\n" ); +kfree (kfb); +return ERR_PTR (-EINVAL ); + } ret =komeda_fb_afbc_size_check (kfb, info, file, mode_cmd); }else { if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 12/36 drm/komeda: Move pitches comparison to komeda_fb_create
In reply to Andrzej PietrasiewiczFor AFBC case num_planes equals 1 so the check will not affect it.
--- .../drm/arm/display/komeda/komeda_framebuffer.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +7 -7
@@ -133,13 +133,6 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, } } -if (info->num_planes ==3 ) { -if (fb->pitches[1 ] != fb->pitches[2 ]) { -DRM_DEBUG_KMS ("The pitch[1] and [2] are not same\n" ); -return -EINVAL ; - } - } -return 0 ; }
@@ -189,6 +182,13 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,if (ret <0 ) goto err_cleanup; +if (info->num_planes ==3 ) +if (kfb->base.pitches[1 ] != kfb->base.pitches[2 ]) { +DRM_DEBUG_KMS ("The pitch[1] and [2] are not same\n" ); + ret = -EINVAL ; + goto err_cleanup; + } + ret =drm_framebuffer_init (dev, &kfb->base, &komeda_fb_funcs);if (ret <0 ) {DRM_DEBUG_KMS ("failed to initialize fb\n" );
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 13/36 drm/komeda: Provide and use komeda_fb_get_pixel_addr variant not requiring a fb
In reply to Andrzej PietrasiewiczAdd a variant of the function which doesn't need neither struct drm_framebuffer nor container_of it. Maintain current interface for existing users.
--- .../arm/display/komeda/komeda_framebuffer.c | 68 +++++++++++++++---- .../arm/display/komeda/komeda_framebuffer.h | 7 ++ 2 files changed, 61 insertions(+), 14 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +54 -14
@@ -124,7 +124,12 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,return -EINVAL ; } - min_size =komeda_fb_get_pixel_addr (kfb,0 , fb->height, i) + min_size =komeda_fb_get_pixel_addr_nofb (info, + mode_cmd->modifier[0 ], + mode_cmd->pitches, + mode_cmd->offsets, + obj, +0 , mode_cmd->height, i) -to_drm_gem_cma_obj (obj)->paddr;if (obj->size < min_size) { DRM_DEBUG_KMS("The fb->obj[%d] size: 0x%zx lower than the minimum requirement: 0x%llx.\n",
@@ -238,12 +243,56 @@ int komeda_fb_check_src_coords(const struct komeda_fb *kfb,return 0 ; } +dma_addr_t +komeda_fb_get_pixel_addr_impl (const struct drm_format_info *format, +u64 modifier, +const unsigned int *pitches, +const unsigned int *offsets, +const struct drm_gem_cma_object *obj, +int x,int y,int plane) +{ +u32 offset, plane_x, plane_y, block_w, block_sz; + + offset = offsets[plane]; +if (modifier) { + block_w =drm_format_info_block_width (format, plane); + block_sz = format->char_per_block[plane]; + plane_x = x / (plane ? format->hsub :1 ); + plane_y = y / (plane ? format->vsub :1 ); + + offset += (plane_x / block_w) * block_sz + + plane_y * pitches[plane]; + } + +return obj->paddr + offset; +} + +dma_addr_t +komeda_fb_get_pixel_addr_nofb (const struct drm_format_info *format, +u64 modifier, +const unsigned int *pitches, +const unsigned int *offsets, +struct drm_gem_object *obj, +int x,int y,int plane) +{ +const struct drm_gem_cma_object *cma_obj; + +if (plane >= format->num_planes) { +DRM_DEBUG_KMS ("Out of max plane num.\n" ); +return -EINVAL ; + } + + cma_obj =to_drm_gem_cma_obj (obj); + +return komeda_fb_get_pixel_addr_impl (format, modifier, pitches, offsets, + cma_obj, x, y, plane); +} +dma_addr_t komeda_fb_get_pixel_addr (struct komeda_fb *kfb,int x,int y,int plane) {struct drm_framebuffer *fb = &kfb->base;const struct drm_gem_cma_object *obj; -u32 offset, plane_x, plane_y, block_w, block_sz;if (plane >= fb->format->num_planes) {DRM_DEBUG_KMS ("Out of max plane num.\n" );
@@ -252,18 +301,9 @@ komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane) obj =drm_fb_cma_get_gem_obj (fb, plane); - offset = fb->offsets[plane]; -if (!fb->modifier) { - block_w =drm_format_info_block_width (fb->format, plane); - block_sz = fb->format->char_per_block[plane]; - plane_x = x / (plane ? fb->format->hsub :1 ); - plane_y = y / (plane ? fb->format->vsub :1 ); - - offset += (plane_x / block_w) * block_sz - + plane_y * fb->pitches[plane]; - } - -return obj->paddr + offset; +return komeda_fb_get_pixel_addr_impl (fb->format, fb->modifier, + fb->pitches, fb->offsets, + obj, x, y, plane); }/* if the fb can be supported by a specific layer */
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h +7 -0
@@ -42,6 +42,13 @@ int komeda_fb_check_src_coords(const struct komeda_fb *kfb, u32 src_x, u32 src_y, u32 src_w, u32 src_h);dma_addr_t komeda_fb_get_pixel_addr (struct komeda_fb *kfb,int x,int y,int plane); +dma_addr_t +komeda_fb_get_pixel_addr_nofb (const struct drm_format_info *format, +u64 modifier, +const unsigned int *pitches, +const unsigned int *offsets, +struct drm_gem_object *obj, +int x,int y,int plane);bool komeda_fb_is_layer_supported (struct komeda_fb *kfb,u32 layer_type,u32 rot);
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 14/36 drm/komeda: Factor out object lookups for non-afbc case
In reply to Andrzej PietrasiewiczUltimately we want lookups happening only once in komeda's fb_create implementation.
--- .../arm/display/komeda/komeda_framebuffer.c | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +13 -8
@@ -101,6 +101,7 @@ static int komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb, const struct drm_format_info *info, + struct drm_gem_object **objs, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) {
@@ -110,12 +111,7 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,u64 min_size;for (i =0 ; i < info->num_planes; i++) { - obj =drm_gem_object_lookup (file, mode_cmd->handles[i]); -if (!obj) { -DRM_DEBUG_KMS ("Failed to lookup GEM object\n" ); -return -ENOENT ; - } - fb->obj[i] = obj; + obj = objs[i]; block_h =drm_format_info_block_height (info, i);if ((fb->pitches[i] * block_h) % mdev->chip.bus_width) {
@@ -175,14 +171,23 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, } ret =komeda_fb_afbc_size_check (kfb, info, file, mode_cmd); }else { +struct drm_gem_object *objs[4 ]; +if (komeda_fb_check_src_coords (kfb,0 ,0 , kfb->base.width, kfb->base.height)) {kfree (kfb);return ERR_PTR (-EINVAL ); } + ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); +if (ret <0 ) { +kfree (kfb); +return ERR_PTR (ret); + } - ret =komeda_fb_none_afbc_size_check (mdev, kfb, info, file, - mode_cmd); + ret =komeda_fb_none_afbc_size_check (mdev, kfb, info, objs, + file, mode_cmd); +for (i =0 ; i < info->num_planes; ++i) + kfb->base.obj[i] = objs[i]; }if (ret <0 ) goto err_cleanup;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 15/36 drm/komeda: Make komeda_fb_none_size_check independent from framebuffer
In reply to Andrzej PietrasiewiczAll necessary data is now available in other data structures.
--- drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +4 -5
@@ -99,13 +99,11 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,static int komeda_fb_none_afbc_size_check (struct komeda_dev *mdev, -struct komeda_fb *kfb,const struct drm_format_info *info,struct drm_gem_object **objs,struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd) { -struct drm_framebuffer *fb = &kfb->base;struct drm_gem_object *obj;u32 i, block_h;u64 min_size;
@@ -114,9 +112,10 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, obj = objs[i]; block_h =drm_format_info_block_height (info, i); -if ((fb->pitches[i] * block_h) % mdev->chip.bus_width) { +if ((mode_cmd->pitches[i] * block_h) % mdev->chip.bus_width) {DRM_DEBUG_KMS ("Pitch[%d]: 0x%x doesn't align to 0x%x\n" , - i, fb->pitches[i], mdev->chip.bus_width); + i, mode_cmd->pitches[i], + mdev->chip.bus_width);return -EINVAL ; }
@@ -184,7 +183,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,return ERR_PTR (ret); } - ret =komeda_fb_none_afbc_size_check (mdev, kfb, info, objs, + ret =komeda_fb_none_afbc_size_check (mdev, info, objs, file, mode_cmd);for (i =0 ; i < info->num_planes; ++i) kfb->base.obj[i] = objs[i];
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 16/36 drm/komeda: Factor out object lookups for afbc case
In reply to Andrzej PietrasiewiczUltimately we want lookups happening only once in komeda's fb_create implementation.
--- .../arm/display/komeda/komeda_framebuffer.c | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +17 -13
@@ -39,6 +39,7 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = {static int komeda_fb_afbc_size_check (struct komeda_fb *kfb,const struct drm_format_info *info, +struct drm_gem_object **objs,struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd) {
@@ -47,11 +48,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,u32 alignment_w =0 , alignment_h =0 , alignment_header, n_blocks, bpp;u64 min_size; - obj =drm_gem_object_lookup (file, mode_cmd->handles[0 ]); -if (!obj) { -DRM_DEBUG_KMS ("Failed to lookup GEM object\n" ); -return -ENOENT ; - } + obj = objs[0 ];if (!drm_afbc_get_superblock_wh (fb->modifier, &alignment_w, &alignment_h))
@@ -71,7 +68,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,if (fb->offsets[0 ] % alignment_header) {DRM_DEBUG_KMS ("afbc offset alignment check failed.\n" ); - goto check_failed; +return -EINVAL ; } n_blocks = (kfb->aligned_w * kfb->aligned_h) /AFBC_SUPERBLK_PIXELS ;
@@ -86,15 +83,10 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,if (min_size > obj->size) {DRM_DEBUG_KMS ("afbc size check failed, obj_size: 0x%zx. min_size 0x%llx.\n" , obj->size, min_size); - goto check_failed; +return -EINVAL ; } - fb->obj[0 ] = obj;return 0 ; - -check_failed: -drm_gem_object_put_unlocked (obj); -return -EINVAL ; } static int
@@ -163,12 +155,24 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, info = kfb->base.format;if (kfb->base.modifier) { +struct drm_gem_object *objs[4 ]; +if (info->num_planes !=1 ) {DRM_DEBUG_KMS ("AFBC requires exactly 1 plane.\n" );kfree (kfb);return ERR_PTR (-EINVAL ); } - ret =komeda_fb_afbc_size_check (kfb, info, file, mode_cmd); + + ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); +if (ret <0 ) { +kfree (kfb); +return ERR_PTR (ret); + } + + ret =komeda_fb_afbc_size_check (kfb, info, objs, file, + mode_cmd); +for (i =0 ; i < info->num_planes; ++i) + kfb->base.obj[i] = objs[i]; }else {struct drm_gem_object *objs[4 ];
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 17/36 drm/komeda: Free komeda_fb_afbc_size_check from framebuffer dependency
In reply to Andrzej PietrasiewiczIt does still depend on komeda_fb, but only for komeda-specific parameters.
--- .../drm/arm/display/komeda/komeda_framebuffer.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +7 -8
@@ -43,19 +43,18 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { - struct drm_framebuffer *fb = &kfb->base; struct drm_gem_object *obj;u32 alignment_w =0 , alignment_h =0 , alignment_header, n_blocks, bpp;u64 min_size; obj = objs[0 ]; -if (!drm_afbc_get_superblock_wh (fb->modifier, +if (!drm_afbc_get_superblock_wh (mode_cmd->modifier[0 ], &alignment_w, &alignment_h))return -EINVAL ;/* tiled header afbc */ -if (fb->modifier &AFBC_FORMAT_MOD_TILED ) { +if (mode_cmd->modifier[0 ] &AFBC_FORMAT_MOD_TILED ) { alignment_w *=AFBC_TH_LAYOUT_ALIGNMENT ; alignment_h *=AFBC_TH_LAYOUT_ALIGNMENT ; alignment_header =AFBC_TH_BODY_START_ALIGNMENT ;
@@ -63,10 +62,10 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, alignment_header =AFBC_BODY_START_ALIGNMENT ; } - kfb->aligned_w =ALIGN (fb->width, alignment_w); - kfb->aligned_h =ALIGN (fb->height, alignment_h); + kfb->aligned_w =ALIGN (mode_cmd->width, alignment_w); + kfb->aligned_h =ALIGN (mode_cmd->height, alignment_h); -if (fb->offsets[0 ] % alignment_header) { +if (mode_cmd->offsets[0 ] % alignment_header) {DRM_DEBUG_KMS ("afbc offset alignment check failed.\n" );return -EINVAL ; }
@@ -75,11 +74,11 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, kfb->offset_payload =ALIGN (n_blocks *AFBC_HEADER_SIZE , alignment_header); - bpp =komeda_get_afbc_format_bpp (info, fb->modifier); + bpp =komeda_get_afbc_format_bpp (info, mode_cmd->modifier[0 ]); kfb->afbc_size = kfb->offset_payload + n_blocks *ALIGN (bpp *AFBC_SUPERBLK_PIXELS /8 ,AFBC_SUPERBLK_ALIGNMENT ); - min_size = kfb->afbc_size + fb->offsets[0 ]; + min_size = kfb->afbc_size + mode_cmd->offsets[0 ];if (min_size > obj->size) {DRM_DEBUG_KMS ("afbc size check failed, obj_size: 0x%zx. min_size 0x%llx.\n" , obj->size, min_size);
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 18/36 drm/komeda: Simplify error handling
In reply to Andrzej PietrasiewiczUse less code to handle errors.
--- .../arm/display/komeda/komeda_framebuffer.c | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +14 -18
@@ -146,8 +146,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,if (!kfb->format_caps) {DRM_DEBUG_KMS ("FMT %x is not supported.\n" , mode_cmd->pixel_format); -kfree (kfb); -return ERR_PTR (-EINVAL ); + ret = -EINVAL ; + goto err_free; }drm_helper_mode_fill_fb_struct (dev, &kfb->base, mode_cmd);
@@ -158,15 +158,13 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,if (info->num_planes !=1 ) {DRM_DEBUG_KMS ("AFBC requires exactly 1 plane.\n" ); -kfree (kfb); -return ERR_PTR (-EINVAL ); + ret = -EINVAL ; + goto err_free; } ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); -if (ret <0 ) { -kfree (kfb); -return ERR_PTR (ret); - } +if (ret <0 ) + goto err_free; ret =komeda_fb_afbc_size_check (kfb, info, objs, file, mode_cmd);
@@ -175,16 +173,14 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, }else {struct drm_gem_object *objs[4 ]; -if (komeda_fb_check_src_coords (kfb,0 ,0 , kfb->base.width, - kfb->base.height)) { -kfree (kfb); -return ERR_PTR (-EINVAL ); - } + ret =komeda_fb_check_src_coords (kfb,0 ,0 , kfb->base.width, + kfb->base.height); +if (ret) + goto err_free; + ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); -if (ret <0 ) { -kfree (kfb); -return ERR_PTR (ret); - } +if (ret <0 ) + goto err_free; ret =komeda_fb_none_afbc_size_check (mdev, info, objs, file, mode_cmd);
@@ -215,7 +211,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, err_cleanup:for (i =0 ; i < kfb->base.format->num_planes; i++)drm_gem_object_put_unlocked (kfb->base.obj[i]); - +err_free:kfree (kfb);return ERR_PTR (ret); }
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 19/36 drm/komeda: Move object lookup before size checks
In reply to Andrzej PietrasiewiczThe lookup is performed the same way in both branches of the "if" statement, so move the lookup to before the "if". err_cleanup case is adjusted accordingly.
--- .../arm/display/komeda/komeda_framebuffer.c | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +8 -15
@@ -132,6 +132,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) {struct komeda_dev *mdev = dev->dev_private; +struct drm_gem_object *objs[4 ];struct komeda_fb *kfb;const struct drm_format_info *info;int ret =0 , i;
@@ -150,37 +151,29 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_free; } + ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); +if (ret <0 ) + goto err_free; +drm_helper_mode_fill_fb_struct (dev, &kfb->base, mode_cmd); info = kfb->base.format;if (kfb->base.modifier) { -struct drm_gem_object *objs[4 ]; -if (info->num_planes !=1 ) {DRM_DEBUG_KMS ("AFBC requires exactly 1 plane.\n" ); ret = -EINVAL ; - goto err_free; + goto err_cleanup; } - ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); -if (ret <0 ) - goto err_free; - ret =komeda_fb_afbc_size_check (kfb, info, objs, file, mode_cmd);for (i =0 ; i < info->num_planes; ++i) kfb->base.obj[i] = objs[i]; }else { -struct drm_gem_object *objs[4 ]; - ret =komeda_fb_check_src_coords (kfb,0 ,0 , kfb->base.width, kfb->base.height);if (ret) - goto err_free; - - ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); -if (ret <0 ) - goto err_free; + goto err_cleanup; ret =komeda_fb_none_afbc_size_check (mdev, info, objs, file, mode_cmd);
@@ -210,7 +203,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, err_cleanup:for (i =0 ; i < kfb->base.format->num_planes; i++) -drm_gem_object_put_unlocked (kfb->base.obj[i]); +drm_gem_object_put_unlocked (objs[i]); err_free:kfree (kfb);return ERR_PTR (ret);
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 20/36 drm/komeda: Move object assignments to framebuffer to after size checks
In reply to Andrzej PietrasiewiczThe assignments are the same in both branches of the "if" statement and nothing depends on them between their original position and the new position, so this can be safely done.
--- drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +3 -4
@@ -167,8 +167,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret =komeda_fb_afbc_size_check (kfb, info, objs, file, mode_cmd); -for (i =0 ; i < info->num_planes; ++i) - kfb->base.obj[i] = objs[i]; }else { ret =komeda_fb_check_src_coords (kfb,0 ,0 , kfb->base.width, kfb->base.height);
@@ -177,8 +175,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret =komeda_fb_none_afbc_size_check (mdev, info, objs, file, mode_cmd); -for (i =0 ; i < info->num_planes; ++i) - kfb->base.obj[i] = objs[i]; }if (ret <0 ) goto err_cleanup;
@@ -190,6 +186,9 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; } +for (i =0 ; i < info->num_planes; ++i) + kfb->base.obj[i] = objs[i]; + ret =drm_framebuffer_init (dev, &kfb->base, &komeda_fb_funcs);if (ret <0 ) {DRM_DEBUG_KMS ("failed to initialize fb\n" );
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 21/36 drm/komeda: Make the size checks independent from framebuffer structure
In reply to Andrzej PietrasiewiczThe same data is available in mode_cmd.
--- .../gpu/drm/arm/display/komeda/komeda_framebuffer.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +5 -5
@@ -156,9 +156,9 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_free;drm_helper_mode_fill_fb_struct (dev, &kfb->base, mode_cmd); - info = kfb->base.format; + info =drm_get_format_info (dev, mode_cmd); -if (kfb->base.modifier) { +if (mode_cmd->modifier[0 ]) {if (info->num_planes !=1 ) {DRM_DEBUG_KMS ("AFBC requires exactly 1 plane.\n" ); ret = -EINVAL ;
@@ -168,8 +168,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret =komeda_fb_afbc_size_check (kfb, info, objs, file, mode_cmd); }else { - ret =komeda_fb_check_src_coords (kfb,0 ,0 , kfb->base.width, - kfb->base.height); + ret =komeda_fb_check_src_coords (kfb,0 ,0 , mode_cmd->width, + mode_cmd->height);if (ret) goto err_cleanup;
@@ -180,7 +180,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup;if (info->num_planes ==3 ) -if (kfb->base.pitches[1 ] != kfb->base.pitches[2 ]) { +if (mode_cmd->pitches[1 ] != mode_cmd->pitches[2 ]) {DRM_DEBUG_KMS ("The pitch[1] and [2] are not same\n" ); ret = -EINVAL ; goto err_cleanup;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 22/36 drm/komeda: Move helper invocation to after size checks
In reply to Andrzej PietrasiewiczBetween the old and new place nothing depends on data retrieved with the helper, so it is safe to move its invocation.
The err_cleanup case is changed accordingly.
--- drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +3 -2
@@ -155,7 +155,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,if (ret <0 ) goto err_free; -drm_helper_mode_fill_fb_struct (dev, &kfb->base, mode_cmd); info =drm_get_format_info (dev, mode_cmd);if (mode_cmd->modifier[0 ]) {
@@ -186,6 +185,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; } +drm_helper_mode_fill_fb_struct (dev, &kfb->base, mode_cmd); +for (i =0 ; i < info->num_planes; ++i) kfb->base.obj[i] = objs[i];
@@ -201,7 +202,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,return &kfb->base; err_cleanup: -for (i =0 ; i < kfb->base.format->num_planes; i++) +for (i =0 ; i < info->num_planes; i++)drm_gem_object_put_unlocked (objs[i]); err_free:kfree (kfb);
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 23/36 drm/komeda: Use helper for common tasks
In reply to Andrzej PietrasiewiczThe replaced fragment is 1:1 with the helper code.
--- .../gpu/drm/arm/display/komeda/komeda_framebuffer.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +3 -10
@@ -185,17 +185,10 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; } -drm_helper_mode_fill_fb_struct (dev, &kfb->base, mode_cmd); - -for (i =0 ; i < info->num_planes; ++i) - kfb->base.obj[i] = objs[i]; - - ret =drm_framebuffer_init (dev, &kfb->base, &komeda_fb_funcs); -if (ret <0 ) { -DRM_DEBUG_KMS ("failed to initialize fb\n" ); - + ret =drm_gem_fb_init_with_funcs (&kfb->base, dev, mode_cmd, objs, + info->num_planes, &komeda_fb_funcs); +if (ret <0 ) goto err_cleanup; - } kfb->is_va = mdev->iommu ? true : false;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 24/36 drm/komeda: Use return value of drm_gem_fb_lookup
In reply to Andrzej PietrasiewiczReduce dependency of the function on the "info" variable as much as possible.
--- .../gpu/drm/arm/display/komeda/komeda_framebuffer.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +6 -5
@@ -135,7 +135,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,struct drm_gem_object *objs[4 ];struct komeda_fb *kfb;const struct drm_format_info *info; -int ret =0 , i; +int ret =0 , i, num_planes; kfb =kzalloc (sizeof (*kfb),GFP_KERNEL );if (!kfb)
@@ -154,11 +154,12 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs);if (ret <0 ) goto err_free; + num_planes = ret; info =drm_get_format_info (dev, mode_cmd);if (mode_cmd->modifier[0 ]) { -if (info->num_planes !=1 ) { +if (num_planes !=1 ) {DRM_DEBUG_KMS ("AFBC requires exactly 1 plane.\n" ); ret = -EINVAL ; goto err_cleanup;
@@ -178,7 +179,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,if (ret <0 ) goto err_cleanup; -if (info->num_planes ==3 ) +if (num_planes ==3 )if (mode_cmd->pitches[1 ] != mode_cmd->pitches[2 ]) {DRM_DEBUG_KMS ("The pitch[1] and [2] are not same\n" ); ret = -EINVAL ;
@@ -186,7 +187,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, } ret =drm_gem_fb_init_with_funcs (&kfb->base, dev, mode_cmd, objs, - info->num_planes, &komeda_fb_funcs); + num_planes, &komeda_fb_funcs);if (ret <0 ) goto err_cleanup;
@@ -195,7 +196,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,return &kfb->base; err_cleanup: -for (i =0 ; i < info->num_planes; i++) +for (i =0 ; i < num_planes; i++)drm_gem_object_put_unlocked (objs[i]); err_free:kfree (kfb);
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 25/36 drm/komeda: Use special helper for non-afbc size checks
In reply to Andrzej PietrasiewiczUse the generic helper code.
--- .../arm/display/komeda/komeda_framebuffer.c | 46 +++++++++---------- 1 file changed, 21 insertions(+), 25 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +21 -25
@@ -89,42 +89,38 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, }static int -komeda_fb_none_afbc_size_check (struct komeda_dev *mdev, +komeda_fb_none_afbc_size_check (struct drm_device *dev,const struct drm_format_info *info,struct drm_gem_object **objs,struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd) { +struct komeda_dev *mdev = dev->dev_private; +struct drm_size_check check = {0 };struct drm_gem_object *obj; -u32 i, block_h; -u64 min_size; +u32 i;for (i =0 ; i < info->num_planes; i++) { obj = objs[i]; - block_h =drm_format_info_block_height (info, i); -if ((mode_cmd->pitches[i] * block_h) % mdev->chip.bus_width) { -DRM_DEBUG_KMS ("Pitch[%d]: 0x%x doesn't align to 0x%x\n" , - i, mode_cmd->pitches[i], - mdev->chip.bus_width); -return -EINVAL ; - } - - min_size =komeda_fb_get_pixel_addr_nofb (info, - mode_cmd->modifier[0 ], - mode_cmd->pitches, - mode_cmd->offsets, - obj, -0 , mode_cmd->height, i) - -to_drm_gem_cma_obj (obj)->paddr; -if (obj->size < min_size) { -DRM_DEBUG_KMS ("The fb->obj[%d] size: 0x%zx lower than the minimum requirement: 0x%llx.\n" , - i, obj->size, min_size); -return -EINVAL ; - } + check.pitch_multiplier[i] = +drm_format_info_block_height (info, i); + + check.min_size[i] = +komeda_fb_get_pixel_addr_nofb (info, + mode_cmd->modifier[0 ], + mode_cmd->pitches, + mode_cmd->offsets, + obj, +0 , mode_cmd->height, i) + -to_drm_gem_cma_obj (obj)->paddr; } -return 0 ; + check.pitch_modulo = mdev->chip.bus_width; + check.use_pitch_multiplier = true; + check.use_min_size = true; + +return drm_gem_fb_size_check_special (dev, mode_cmd, &check, objs); } struct drm_framebuffer *
@@ -173,7 +169,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,if (ret) goto err_cleanup; - ret =komeda_fb_none_afbc_size_check (mdev, info, objs, + ret =komeda_fb_none_afbc_size_check (dev, info, objs, file, mode_cmd); }if (ret <0 )
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 26/36 drm/komeda: Factor in the invocation of special helper
In reply to Andrzej PietrasiewiczDon't use a separate function to call the helper. The ultimate goal is to unify non-afbc and afbc cases as much as possible and then moving the helper invocation outside the if-else clause.
--- .../arm/display/komeda/komeda_framebuffer.c | 58 +++++++------------ 1 file changed, 21 insertions(+), 37 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +21 -37
@@ -88,41 +88,6 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,return 0 ; } -static int -komeda_fb_none_afbc_size_check (struct drm_device *dev, -const struct drm_format_info *info, -struct drm_gem_object **objs, -struct drm_file *file, -const struct drm_mode_fb_cmd2 *mode_cmd) -{ -struct komeda_dev *mdev = dev->dev_private; -struct drm_size_check check = {0 }; -struct drm_gem_object *obj; -u32 i; - -for (i =0 ; i < info->num_planes; i++) { - obj = objs[i]; - - check.pitch_multiplier[i] = -drm_format_info_block_height (info, i); - - check.min_size[i] = -komeda_fb_get_pixel_addr_nofb (info, - mode_cmd->modifier[0 ], - mode_cmd->pitches, - mode_cmd->offsets, - obj, -0 , mode_cmd->height, i) - -to_drm_gem_cma_obj (obj)->paddr; - } - - check.pitch_modulo = mdev->chip.bus_width; - check.use_pitch_multiplier = true; - check.use_min_size = true; - -return drm_gem_fb_size_check_special (dev, mode_cmd, &check, objs); -} -struct drm_framebuffer *komeda_fb_create (struct drm_device *dev,struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd)
@@ -164,13 +129,32 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret =komeda_fb_afbc_size_check (kfb, info, objs, file, mode_cmd); }else { +struct drm_size_check check = {0 }; + ret =komeda_fb_check_src_coords (kfb,0 ,0 , mode_cmd->width, mode_cmd->height);if (ret) goto err_cleanup; - ret =komeda_fb_none_afbc_size_check (dev, info, objs, - file, mode_cmd); +for (i =0 ; i < num_planes; i++) { + check.pitch_multiplier[i] = +drm_format_info_block_height (info, i); + + check.min_size[i] = +komeda_fb_get_pixel_addr_nofb (info, + mode_cmd->modifier[0 ], + mode_cmd->pitches, + mode_cmd->offsets, objs[i], +0 , mode_cmd->height, i) + -to_drm_gem_cma_obj (objs[i])->paddr; + } + + check.pitch_modulo = mdev->chip.bus_width; + check.use_pitch_multiplier = true; + check.use_min_size = true; + + ret =drm_gem_fb_size_check_special (dev, mode_cmd, &check, + objs); }if (ret <0 ) goto err_cleanup;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 27/36 drm/komeda: Use special helper for afbc case size check
In reply to Andrzej PietrasiewiczUse generic helper code.
--- .../arm/display/komeda/komeda_framebuffer.c | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +8 -14
@@ -37,17 +37,15 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = { };static int -komeda_fb_afbc_size_check (struct komeda_fb *kfb, +komeda_fb_afbc_size_check (struct drm_device *dev, +struct komeda_fb *kfb,const struct drm_format_info *info,struct drm_gem_object **objs,struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd) { -struct drm_gem_object *obj; +struct drm_size_check check = {0 };u32 alignment_w =0 , alignment_h =0 , alignment_header, n_blocks, bpp; -u64 min_size; - - obj = objs[0 ];if (!drm_afbc_get_superblock_wh (mode_cmd->modifier[0 ], &alignment_w, &alignment_h))
@@ -78,14 +76,10 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, kfb->afbc_size = kfb->offset_payload + n_blocks *ALIGN (bpp *AFBC_SUPERBLK_PIXELS /8 ,AFBC_SUPERBLK_ALIGNMENT ); - min_size = kfb->afbc_size + mode_cmd->offsets[0 ]; -if (min_size > obj->size) { -DRM_DEBUG_KMS ("afbc size check failed, obj_size: 0x%zx. min_size 0x%llx.\n" , - obj->size, min_size); -return -EINVAL ; - } + check.min_size[0 ] = kfb->afbc_size + mode_cmd->offsets[0 ]; + check.use_min_size = true; -return 0 ; +return drm_gem_fb_size_check_special (dev, mode_cmd, &check, objs); } struct drm_framebuffer *
@@ -126,8 +120,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; } - ret =komeda_fb_afbc_size_check (kfb, info, objs, file, - mode_cmd); + ret =komeda_fb_afbc_size_check (dev, kfb, info, objs, + file, mode_cmd); }else {struct drm_size_check check = {0 };
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 28/36 drm/komeda: Factor in the invocation of special helper, afbc case
In reply to Andrzej PietrasiewiczPrepare for unification with non-afbc case.
--- .../arm/display/komeda/komeda_framebuffer.c | 90 +++++++++---------- 1 file changed, 42 insertions(+), 48 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +42 -48
@@ -36,52 +36,6 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = { .create_handle = komeda_fb_create_handle, }; -static int -komeda_fb_afbc_size_check (struct drm_device *dev, -struct komeda_fb *kfb, -const struct drm_format_info *info, -struct drm_gem_object **objs, -struct drm_file *file, -const struct drm_mode_fb_cmd2 *mode_cmd) -{ -struct drm_size_check check = {0 }; -u32 alignment_w =0 , alignment_h =0 , alignment_header, n_blocks, bpp; - -if (!drm_afbc_get_superblock_wh (mode_cmd->modifier[0 ], - &alignment_w, &alignment_h)) -return -EINVAL ; - -/* tiled header afbc */ -if (mode_cmd->modifier[0 ] &AFBC_FORMAT_MOD_TILED ) { - alignment_w *=AFBC_TH_LAYOUT_ALIGNMENT ; - alignment_h *=AFBC_TH_LAYOUT_ALIGNMENT ; - alignment_header =AFBC_TH_BODY_START_ALIGNMENT ; - }else { - alignment_header =AFBC_BODY_START_ALIGNMENT ; - } - - kfb->aligned_w =ALIGN (mode_cmd->width, alignment_w); - kfb->aligned_h =ALIGN (mode_cmd->height, alignment_h); - -if (mode_cmd->offsets[0 ] % alignment_header) { -DRM_DEBUG_KMS ("afbc offset alignment check failed.\n" ); -return -EINVAL ; - } - - n_blocks = (kfb->aligned_w * kfb->aligned_h) /AFBC_SUPERBLK_PIXELS ; - kfb->offset_payload =ALIGN (n_blocks *AFBC_HEADER_SIZE , - alignment_header); - - bpp =komeda_get_afbc_format_bpp (info, mode_cmd->modifier[0 ]); - kfb->afbc_size = kfb->offset_payload + n_blocks * -ALIGN (bpp *AFBC_SUPERBLK_PIXELS /8 , -AFBC_SUPERBLK_ALIGNMENT ); - check.min_size[0 ] = kfb->afbc_size + mode_cmd->offsets[0 ]; - check.use_min_size = true; - -return drm_gem_fb_size_check_special (dev, mode_cmd, &check, objs); -} -struct drm_framebuffer *komeda_fb_create (struct drm_device *dev,struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd)
@@ -114,14 +68,54 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, info =drm_get_format_info (dev, mode_cmd);if (mode_cmd->modifier[0 ]) { +struct drm_size_check check = {0 }; +u32 alignment_w =0 , alignment_h =0 ; +u32 alignment_header, n_blocks, bpp; +if (num_planes !=1 ) {DRM_DEBUG_KMS ("AFBC requires exactly 1 plane.\n" ); ret = -EINVAL ; goto err_cleanup; } - ret =komeda_fb_afbc_size_check (dev, kfb, info, objs, - file, mode_cmd); +if (!drm_afbc_get_superblock_wh (mode_cmd->modifier[0 ], + &alignment_w, &alignment_h)) { + ret = -EINVAL ; + goto err_cleanup; + } + +/* tiled header afbc */ +if (mode_cmd->modifier[0 ] &AFBC_FORMAT_MOD_TILED ) { + alignment_w *=AFBC_TH_LAYOUT_ALIGNMENT ; + alignment_h *=AFBC_TH_LAYOUT_ALIGNMENT ; + alignment_header =AFBC_TH_BODY_START_ALIGNMENT ; + }else { + alignment_header =AFBC_BODY_START_ALIGNMENT ; + } + + kfb->aligned_w =ALIGN (mode_cmd->width, alignment_w); + kfb->aligned_h =ALIGN (mode_cmd->height, alignment_h); + +if (mode_cmd->offsets[0 ] % alignment_header) { +DRM_DEBUG_KMS ("afbc offset alignment check failed.\n" ); + ret = -EINVAL ; + goto err_cleanup; + } + + n_blocks = (kfb->aligned_w * kfb->aligned_h) + /AFBC_SUPERBLK_PIXELS ; + kfb->offset_payload =ALIGN (n_blocks *AFBC_HEADER_SIZE , + alignment_header); + + bpp =komeda_get_afbc_format_bpp (info, mode_cmd->modifier[0 ]); + kfb->afbc_size = kfb->offset_payload + n_blocks * +ALIGN (bpp *AFBC_SUPERBLK_PIXELS /8 , +AFBC_SUPERBLK_ALIGNMENT ); + check.min_size[0 ] = kfb->afbc_size + mode_cmd->offsets[0 ]; + check.use_min_size = true; + + ret =drm_gem_fb_size_check_special (dev, mode_cmd, &check, + objs); }else {struct drm_size_check check = {0 };
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 29/36 drm/komeda: Move special helper invocation outside if-else
In reply to Andrzej PietrasiewiczThe invocation is the same in both cases and is the last thing inside a block, so move it outside the if-else clause.
--- .../gpu/drm/arm/display/komeda/komeda_framebuffer.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +3 -9
@@ -44,6 +44,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,struct drm_gem_object *objs[4 ];struct komeda_fb *kfb;const struct drm_format_info *info; +struct drm_size_check check = {0 }; +int ret =0 , i, num_planes; kfb =kzalloc (sizeof (*kfb),GFP_KERNEL );
@@ -68,7 +70,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, info =drm_get_format_info (dev, mode_cmd);if (mode_cmd->modifier[0 ]) { -struct drm_size_check check = {0 };u32 alignment_w =0 , alignment_h =0 ;u32 alignment_header, n_blocks, bpp;
@@ -113,12 +114,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, AFBC_SUPERBLK_ALIGNMENT); check.min_size[0 ] = kfb->afbc_size + mode_cmd->offsets[0 ]; check.use_min_size = true; - - ret =drm_gem_fb_size_check_special (dev, mode_cmd, &check, - objs); }else { -struct drm_size_check check = {0 }; - ret =komeda_fb_check_src_coords (kfb,0 ,0 , mode_cmd->width, mode_cmd->height);if (ret)
@@ -140,10 +136,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, check.pitch_modulo = mdev->chip.bus_width; check.use_pitch_multiplier = true; check.use_min_size = true; - - ret =drm_gem_fb_size_check_special (dev, mode_cmd, &check, - objs); } + ret =drm_gem_fb_size_check_special (dev, mode_cmd, &check, objs);if (ret <0 ) goto err_cleanup;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 30/36 drm/komeda: Move to helper checking afbc buffer size
In reply to Andrzej PietrasiewiczUse generic helper code. Adapt struct komeda_fb users to new location of respective data members.
--- .../arm/display/komeda/d71/d71_component.c | 7 ++- .../arm/display/komeda/komeda_framebuffer.c | 60 +++++++++---------- .../arm/display/komeda/komeda_framebuffer.h | 8 --- .../display/komeda/komeda_pipeline_state.c | 11 ++-- 4 files changed, 39 insertions(+), 47 deletions(-)
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +5 -2
@@ -4,6 +4,8 @@* Author: James.Qian.Wang <[email protected]> * */ +#include <linux/types.h> +#include <drm/drm_gem_framebuffer_helper.h> #include "d71_dev.h" #include "komeda_kms.h" #include "malidp_io.h"
@@ -234,9 +236,10 @@ static void d71_layer_update(struct komeda_component *c, st->afbc_crop_b));/* afbc 1.2 wants payload, afbc 1.0/1.1 wants end_addr */ if (fb->modifier &AFBC_FORMAT_MOD_TILED ) - addr = st->addr[0 ] + kfb->offset_payload; + addr = st->addr[0 ] + + kfb->base.afbc_info->offset_payload;else - addr = st->addr[0 ] + kfb->afbc_size -1 ; + addr = st->addr[0 ] + kfb->base.afbc_info->afbc_size -1 ;malidp_write32 (reg,BLK_P1_PTR_LOW ,lower_32_bits (addr));malidp_write32 (reg,BLK_P1_PTR_HIGH ,upper_32_bits (addr));
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +27 -33
98 lines not on this page · raw message
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h +0 -8
@@ -23,14 +23,6 @@ struct komeda_fb {const struct komeda_format_caps *format_caps;/** @is_va: if smmu is enabled, it will be true */ bool is_va; -/** @aligned_w: aligned frame buffer width */ -u32 aligned_w; -/** @aligned_h: aligned frame buffer height */ -u32 aligned_h; -/** @afbc_size: minimum size of afbc */ -u32 afbc_size; -/** @offset_payload: start of afbc body buffer */ -u32 offset_payload; };#define to_kfb (dfb) container_of(dfb, struct komeda_fb, base)
drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c +7 -4
@@ -6,6 +6,7 @@*/ #include <drm/drm_print.h> +#include <drm/drm_gem_framebuffer_helper.h> #include <linux/clk.h> #include "komeda_dev.h" #include "komeda_kms.h"
@@ -360,12 +361,14 @@ komeda_layer_validate(struct komeda_layer *layer, st->rot = dflow->rot;if (fb->modifier) { - st->hsize = kfb->aligned_w; - st->vsize = kfb->aligned_h; + st->hsize = kfb->base.afbc_info->aligned_width; + st->vsize = kfb->base.afbc_info->aligned_height; st->afbc_crop_l = dflow->in_x; - st->afbc_crop_r = kfb->aligned_w - dflow->in_x - dflow->in_w; + st->afbc_crop_r = kfb->base.afbc_info->aligned_width + - dflow->in_x - dflow->in_w; st->afbc_crop_t = dflow->in_y; - st->afbc_crop_b = kfb->aligned_h - dflow->in_y - dflow->in_h; + st->afbc_crop_b = kfb->base.afbc_info->aligned_height + - dflow->in_y - dflow->in_h; }else { st->hsize = dflow->in_w; st->vsize = dflow->in_h;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 31/36 drm/arm/malidp: Make verify funcitons invocations independent
In reply to Andrzej PietrasiewiczThis will make it easier to transition to generic afbc-aware helpers.
--- drivers/gpu/drm/arm/malidp_drv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/arm/malidp_drv.c +3 -3
@@ -362,10 +362,10 @@ static bool malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { - if (malidp_verify_afbc_framebuffer_caps(dev, mode_cmd)) - return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd); + if (!malidp_verify_afbc_framebuffer_caps(dev, mode_cmd)) + return false; -return false; + return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd); } static struct drm_framebuffer *
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 32/36 drm/arm/malidp: Integrate verify functions
In reply to Andrzej PietrasiewiczThe next step towards using generic afbc-aware helpers.
--- drivers/gpu/drm/arm/malidp_drv.c | 36 ++++++++------------------------ 1 file changed, 9 insertions(+), 27 deletions(-)
drivers/gpu/drm/arm/malidp_drv.c +9 -27
@@ -270,9 +270,16 @@ static const struct drm_mode_config_helper_funcs malidp_mode_config_helpers = { };static bool -malidp_verify_afbc_framebuffer_caps (struct drm_device *dev, -const struct drm_mode_fb_cmd2 *mode_cmd) +malidp_verify_afbc_framebuffer (struct drm_device *dev,struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd) { +int n_superblocks =0 ; +const struct drm_format_info *info; +struct drm_gem_object *objs =NULL ; +u32 afbc_superblock_size =0 , afbc_superblock_height =0 ; +u32 afbc_superblock_width =0 , afbc_size =0 ; +int bpp =0 ; +if (malidp_format_mod_supported (dev, mode_cmd->pixel_format, mode_cmd->modifier[0 ]) == false)return false;
@@ -294,21 +301,6 @@ malidp_verify_afbc_framebuffer_caps(struct drm_device *dev,return false; } -return true; -} - -static bool -malidp_verify_afbc_framebuffer_size (struct drm_device *dev, -struct drm_file *file, -const struct drm_mode_fb_cmd2 *mode_cmd) -{ -int n_superblocks =0 ; -const struct drm_format_info *info; -struct drm_gem_object *objs =NULL ; -u32 afbc_superblock_size =0 , afbc_superblock_height =0 ; -u32 afbc_superblock_width =0 , afbc_size =0 ; -int bpp =0 ; -switch (mode_cmd->modifier[0 ] &AFBC_SIZE_MASK ) {case AFBC_SIZE_16X16 : afbc_superblock_height =16 ;
@@ -358,16 +350,6 @@ malidp_verify_afbc_framebuffer_size(struct drm_device *dev,return true; } -static bool -malidp_verify_afbc_framebuffer (struct drm_device *dev,struct drm_file *file, -const struct drm_mode_fb_cmd2 *mode_cmd) -{ -if (!malidp_verify_afbc_framebuffer_caps (dev, mode_cmd)) -return false; - -return malidp_verify_afbc_framebuffer_size (dev, file, mode_cmd); -} -static struct drm_framebuffer *malidp_fb_create (struct drm_device *dev,struct drm_file *file,const struct drm_mode_fb_cmd2 *mode_cmd)
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 33/36 drm/arm/malidp: Factor in afbc framebuffer verification
In reply to Andrzej PietrasiewiczPrepare for using generic afbc-aware helpers.
--- drivers/gpu/drm/arm/malidp_drv.c | 142 +++++++++++++++---------------- 1 file changed, 68 insertions(+), 74 deletions(-)
drivers/gpu/drm/arm/malidp_drv.c +68 -74
@@ -269,94 +269,88 @@ static const struct drm_mode_config_helper_funcs malidp_mode_config_helpers = { .atomic_commit_tail = malidp_atomic_commit_tail, }; -static bool -malidp_verify_afbc_framebuffer (struct drm_device *dev,struct drm_file *file, -const struct drm_mode_fb_cmd2 *mode_cmd) +static struct drm_framebuffer * +malidp_fb_create (struct drm_device *dev,struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd) { -int n_superblocks =0 ; -const struct drm_format_info *info; -struct drm_gem_object *objs =NULL ; -u32 afbc_superblock_size =0 , afbc_superblock_height =0 ; -u32 afbc_superblock_width =0 , afbc_size =0 ; -int bpp =0 ; - -if (malidp_format_mod_supported (dev, mode_cmd->pixel_format, - mode_cmd->modifier[0 ]) == false) -return false; - -if (mode_cmd->offsets[0 ] !=0 ) { -DRM_DEBUG_KMS ("AFBC buffers' plane offset should be 0\n" ); -return false; - } +if (mode_cmd->modifier[0 ]) { +int n_superblocks =0 ; +const struct drm_format_info *info; +struct drm_gem_object *objs =NULL ; +u32 afbc_superblock_size =0 , afbc_superblock_height =0 ; +u32 afbc_superblock_width =0 , afbc_size =0 ; +int bpp =0 ; + +if (malidp_format_mod_supported (dev, mode_cmd->pixel_format, + mode_cmd->modifier[0 ]) == false) +return ERR_PTR (-EINVAL ); -switch (mode_cmd->modifier[0 ] &AFBC_SIZE_MASK ) { -case AFBC_SIZE_16X16 : -if ((mode_cmd->width %16 ) || (mode_cmd->height %16 )) { -DRM_DEBUG_KMS ("AFBC buffers must be aligned to 16 pixels\n" ); -return false; +if (mode_cmd->offsets[0 ] !=0 ) { +DRM_DEBUG_KMS ("AFBC buffers' plane offset should be 0\n" ); +return ERR_PTR (-EINVAL ); } -break ; -default : -DRM_DEBUG_KMS ("Unsupported AFBC block size\n" ); -return false; - } -switch (mode_cmd->modifier[0 ] &AFBC_SIZE_MASK ) { -case AFBC_SIZE_16X16 : - afbc_superblock_height =16 ; - afbc_superblock_width =16 ; -break ; -default : -DRM_DEBUG_KMS ("AFBC superblock size is not supported\n" ); -return false; - } +switch (mode_cmd->modifier[0 ] &AFBC_SIZE_MASK ) { +case AFBC_SIZE_16X16 : +if ((mode_cmd->width %16 ) || (mode_cmd->height %16 )) { +DRM_DEBUG_KMS ("AFBC buffers must be aligned to 16 pixels\n" ); +return ERR_PTR (-EINVAL ); + } +break ; +default : +DRM_DEBUG_KMS ("Unsupported AFBC block size\n" ); +return ERR_PTR (-EINVAL ); + } - info =drm_get_format_info (dev, mode_cmd); +switch (mode_cmd->modifier[0 ] &AFBC_SIZE_MASK ) { +case AFBC_SIZE_16X16 : + afbc_superblock_height =16 ; + afbc_superblock_width =16 ; +break ; +default : +DRM_DEBUG_KMS ("AFBC superblock size is not supported\n" ); +return ERR_PTR (-EINVAL ); + } - n_superblocks = (mode_cmd->width / afbc_superblock_width) * - (mode_cmd->height / afbc_superblock_height); + info =drm_get_format_info (dev, mode_cmd); - bpp =malidp_format_get_bpp (info->format); + n_superblocks = (mode_cmd->width / afbc_superblock_width) * + (mode_cmd->height / afbc_superblock_height); - afbc_superblock_size = (bpp * afbc_superblock_width * afbc_superblock_height) - /BITS_PER_BYTE ; + bpp =malidp_format_get_bpp (info->format); - afbc_size =ALIGN (n_superblocks *AFBC_HEADER_SIZE ,AFBC_SUPERBLK_ALIGNMENT ); - afbc_size += n_superblocks *ALIGN (afbc_superblock_size,AFBC_SUPERBLK_ALIGNMENT ); + afbc_superblock_size = + (bpp * afbc_superblock_width * afbc_superblock_height) + /BITS_PER_BYTE ; -if ((mode_cmd->width * bpp) != (mode_cmd->pitches[0 ] *BITS_PER_BYTE )) { -DRM_DEBUG_KMS ("Invalid value of (pitch * BITS_PER_BYTE) (=%u) " -"should be same as width (=%u) * bpp (=%u)\n" , - (mode_cmd->pitches[0 ] *BITS_PER_BYTE ), - mode_cmd->width, bpp); -return false; - } + afbc_size =ALIGN (n_superblocks *AFBC_HEADER_SIZE , +AFBC_SUPERBLK_ALIGNMENT ); + afbc_size += n_superblocks + *ALIGN (afbc_superblock_size,AFBC_SUPERBLK_ALIGNMENT ); - objs =drm_gem_object_lookup (file, mode_cmd->handles[0 ]); -if (!objs) { -DRM_DEBUG_KMS ("Failed to lookup GEM object\n" ); -return false; - } - -if (objs->size < afbc_size) { -DRM_DEBUG_KMS ("buffer size (%zu) too small for AFBC buffer size = %u\n" , - objs->size, afbc_size); -drm_gem_object_put_unlocked (objs); -return false; - } - -drm_gem_object_put_unlocked (objs); +if ((mode_cmd->width * bpp) != + (mode_cmd->pitches[0 ] *BITS_PER_BYTE )) { +DRM_DEBUG_KMS ("Invalid value of (pitch * BITS_PER_BYTE) (=%u) " +"should be same as width (=%u) * bpp (=%u)\n" , + (mode_cmd->pitches[0 ] *BITS_PER_BYTE ), + mode_cmd->width, bpp); +return ERR_PTR (-EINVAL ); + } -return true; -} + objs =drm_gem_object_lookup (file, mode_cmd->handles[0 ]); +if (!objs) { +DRM_DEBUG_KMS ("Failed to lookup GEM object\n" ); +return ERR_PTR (-EINVAL ); + } -static struct drm_framebuffer * -malidp_fb_create (struct drm_device *dev,struct drm_file *file, -const struct drm_mode_fb_cmd2 *mode_cmd) -{ -if (mode_cmd->modifier[0 ]) { -if (!malidp_verify_afbc_framebuffer (dev, file, mode_cmd)) +if (objs->size < afbc_size) { +DRM_DEBUG_KMS ("buffer size (%zu) too small for AFBC buffer size = %u\n" , + objs->size, afbc_size); +drm_gem_object_put_unlocked (objs);return ERR_PTR (-EINVAL ); + } + +drm_gem_object_put_unlocked (objs); }return drm_gem_fb_create (dev, file, mode_cmd);
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 34/36 drm/arm/malidp: Use generic helpers for afbc checks
In reply to Andrzej PietrasiewiczHelpers are now available for checking afbc buffer properties. Use those.
--- drivers/gpu/drm/arm/malidp_drv.c | 71 ++++++++++++++------------------ 1 file changed, 30 insertions(+), 41 deletions(-)
drivers/gpu/drm/arm/malidp_drv.c +30 -41
@@ -273,12 +273,17 @@ static struct drm_framebuffer * malidp_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { + struct drm_size_check check = { 0 }; +struct drm_gem_object *objs[4 ]; +struct drm_framebuffer *fb; +int ret, i, num_planes; + + fb =drm_gem_fb_alloc_with_afbc (); +if (!fb) +return ERR_PTR (-ENOMEM ); +if (mode_cmd->modifier[0 ]) { - int n_superblocks = 0;const struct drm_format_info *info; -struct drm_gem_object *objs =NULL ; -u32 afbc_superblock_size =0 , afbc_superblock_height =0 ; -u32 afbc_superblock_width =0 , afbc_size =0 ;int bpp =0 ; if (malidp_format_mod_supported(dev, mode_cmd->pixel_format,
@@ -302,32 +307,9 @@ malidp_fb_create(struct drm_device *dev, struct drm_file *file,return ERR_PTR (-EINVAL ); } -switch (mode_cmd->modifier[0 ] &AFBC_SIZE_MASK ) { -case AFBC_SIZE_16X16 : - afbc_superblock_height =16 ; - afbc_superblock_width =16 ; -break ; -default : -DRM_DEBUG_KMS ("AFBC superblock size is not supported\n" ); -return ERR_PTR (-EINVAL ); - } - info =drm_get_format_info (dev, mode_cmd); - - n_superblocks = (mode_cmd->width / afbc_superblock_width) * - (mode_cmd->height / afbc_superblock_height); - bpp =malidp_format_get_bpp (info->format); - afbc_superblock_size = - (bpp * afbc_superblock_width * afbc_superblock_height) - /BITS_PER_BYTE ; - - afbc_size =ALIGN (n_superblocks *AFBC_HEADER_SIZE , -AFBC_SUPERBLK_ALIGNMENT ); - afbc_size += n_superblocks - *ALIGN (afbc_superblock_size,AFBC_SUPERBLK_ALIGNMENT ); -if ((mode_cmd->width * bpp) != (mode_cmd->pitches[0 ] *BITS_PER_BYTE )) { DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE) (=%u) "
@@ -336,24 +318,31 @@ malidp_fb_create(struct drm_device *dev, struct drm_file *file, mode_cmd->width, bpp);return ERR_PTR (-EINVAL ); } + fb->afbc_info->bpp = bpp; + check.data = fb->afbc_info; + } - objs =drm_gem_object_lookup (file, mode_cmd->handles[0 ]); -if (!objs) { -DRM_DEBUG_KMS ("Failed to lookup GEM object\n" ); -return ERR_PTR (-EINVAL ); - } + ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); +if (ret <0 ) + goto err_free; + num_planes = ret; -if (objs->size < afbc_size) { -DRM_DEBUG_KMS ("buffer size (%zu) too small for AFBC buffer size = %u\n" , - objs->size, afbc_size); -drm_gem_object_put_unlocked (objs); -return ERR_PTR (-EINVAL ); - } + ret =drm_gem_fb_size_check_special (dev, mode_cmd, &check, objs); +if (ret <0 ) + goto err_cleanup; -drm_gem_object_put_unlocked (objs); - } + ret =drm_gem_fb_init (fb, dev, mode_cmd, objs, num_planes); +if (ret <0 ) + goto err_cleanup; + +return fb; -return drm_gem_fb_create (dev, file, mode_cmd); +err_cleanup: +for (i =0 ; i < num_planes; ++i) +drm_gem_object_put_unlocked (objs[i]); +err_free: +kfree (fb); +return ERR_PTR (ret); }static const struct drm_mode_config_funcs malidp_mode_config_funcs = {
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 35/36 drm/rockchip: Use helper for common task
In reply to Andrzej PietrasiewiczUse generic helper code.
--- drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +3 -10
@@ -18,6 +18,7 @@#include "rockchip_drm_fb.h" #include "rockchip_drm_gem.h" +static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = { .destroy = drm_gem_fb_destroy, .create_handle = drm_gem_fb_create_handle,
@@ -30,22 +31,14 @@ rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cm {struct drm_framebuffer *fb;int ret; -int i; fb =kzalloc (sizeof (*fb),GFP_KERNEL );if (!fb)return ERR_PTR (-ENOMEM ); -drm_helper_mode_fill_fb_struct (dev, fb, mode_cmd); - -for (i =0 ; i < num_planes; i++) - fb->obj[i] = obj[i]; - - ret =drm_framebuffer_init (dev, fb, &rockchip_drm_fb_funcs); + ret =drm_gem_fb_init_with_funcs (fb, dev, mode_cmd, obj, num_planes, + &rockchip_drm_fb_funcs);if (ret) { -DRM_DEV_ERROR (dev->dev, -"Failed to initialize framebuffer: %d\n" , - ret);kfree (fb);return ERR_PTR (ret); }
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 36/36 drm/rockchip: Add support for afbc
In reply to Andrzej PietrasiewiczThis patch adds support for afbc handling. afbc is a compressed format which reduces the necessary memory bandwidth.
--- drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 100 +++++++++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 141 +++++++++++++++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop.h | 12 ++ drivers/gpu/drm/rockchip/rockchip_vop_reg.c | 84 +++++++++++- 4 files changed, 331 insertions(+), 6 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +98 -2
@@ -18,6 +18,7 @@#include "rockchip_drm_fb.h" #include "rockchip_drm_gem.h" +#define ROCKCHIP_MAX_AFBC_WIDTH 2560static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = { .destroy = drm_gem_fb_destroy,
@@ -25,17 +26,60 @@ static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = { .dirty = drm_atomic_helper_dirtyfb, }; +static int rockchip_afbc_post_check (struct drm_afbc *afbc) +{ +if (afbc->offset) { +DRM_WARN ("AFBC plane offset must be zero!\n" ); +return -EINVAL ; + } + +if (afbc->block_width !=16 || afbc->block_height !=16 ) { +DRM_WARN ("Unsupported AFBC block w/h [%d/%d]\n" , + afbc->block_width, afbc->block_height); +return -EINVAL ; + } + +if (afbc->aligned_width >ROCKCHIP_MAX_AFBC_WIDTH ) { +DRM_WARN ("Unsupported width %d>%d\n" , + afbc->aligned_width,ROCKCHIP_MAX_AFBC_WIDTH ); +return -EINVAL ; + } + +return 0 ; +} +static struct drm_framebuffer *rockchip_fb_alloc (struct drm_device *dev,const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object **obj,unsigned int num_planes) {struct drm_framebuffer *fb; +struct drm_size_check check = {0 };int ret; - fb =kzalloc (sizeof (*fb),GFP_KERNEL ); + fb =drm_gem_fb_alloc_with_afbc ();if (!fb)return ERR_PTR (-ENOMEM ); +if (drm_is_afbc (mode_cmd->modifier[0 ])) { +const struct drm_format_info *info = +drm_get_format_info (dev, mode_cmd); + + fb->afbc_info->bpp = info->cpp[0 ] *8 ; + check.data = fb->afbc_info; + } + + ret =drm_gem_fb_size_check_special (dev, mode_cmd, &check, obj); +if (ret) { +kfree (fb); +return ERR_PTR (ret); + } + +if (drm_is_afbc (mode_cmd->modifier[0 ])) +if (rockchip_afbc_post_check (fb->afbc_info)) { +kfree (fb); +return ERR_PTR (-EINVAL ); + } + ret =drm_gem_fb_init_with_funcs (fb, dev, mode_cmd, obj, num_planes, &rockchip_drm_fb_funcs);if (ret) {
@@ -50,8 +94,60 @@ static const struct drm_mode_config_helper_funcs rockchip_mode_config_helpers = .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm, }; + +static struct drm_framebuffer * +rockchip_fb_create (struct drm_device *dev,struct drm_file *file, +const struct drm_mode_fb_cmd2 *mode_cmd) +{ +struct drm_framebuffer *fb; +struct drm_size_check check = {0 }; +struct drm_gem_object *objs[4 ]; +int ret, i, num_planes; + + fb =drm_gem_fb_alloc_with_afbc (); +if (!fb) +return ERR_PTR (-ENOMEM ); + +if (drm_is_afbc (mode_cmd->modifier[0 ])) { +const struct drm_format_info *info = +drm_get_format_info (dev, mode_cmd); + + fb->afbc_info->bpp = info->cpp[0 ] *8 ; + check.data = fb->afbc_info; + } + + ret =drm_gem_fb_lookup (dev, file, mode_cmd, objs); +if (ret <0 ) + goto err_free; + num_planes = ret; + + ret =drm_gem_fb_size_check_special (dev, mode_cmd, &check, objs); +if (ret) + goto err_cleanup; + +if (drm_is_afbc (mode_cmd->modifier[0 ])) +if (rockchip_afbc_post_check (fb->afbc_info)) { + ret = -EINVAL ; + goto err_cleanup; + } + + ret =drm_gem_fb_init_with_funcs (fb, dev, mode_cmd, objs, num_planes, + &rockchip_drm_fb_funcs); +if (ret) + goto err_cleanup; + +return fb; + +err_cleanup: +for (i =0 ; i < num_planes; ++i) +drm_gem_object_put_unlocked (objs[i]); +err_free: +kfree (fb); +return ERR_PTR (ret); +} +static const struct drm_mode_config_funcs rockchip_drm_mode_config_funcs = { - .fb_create = drm_gem_fb_create_with_dirty, + .fb_create = rockchip_fb_create, .output_poll_changed = drm_fb_helper_output_poll_changed, .atomic_check = drm_atomic_helper_check, .atomic_commit = drm_atomic_helper_commit,
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +139 -2
222 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_vop.h +12 -0
@@ -34,6 +34,16 @@ struct vop_reg {bool relaxed; }; +struct vop_afbc { +struct vop_reg enable; +struct vop_reg win_sel; +struct vop_reg format; +struct vop_reg hreg_block_split; +struct vop_reg pic_size; +struct vop_reg hdr_ptr; +struct vop_reg rstn; +}; +struct vop_modeset {struct vop_reg htotal_pw;struct vop_reg hact_st_end;
@@ -134,6 +144,7 @@ struct vop_win_phy {const struct vop_scl_regs *scl;const uint32_t *data_formats;uint32_t nformats; +const uint64_t *format_modifiers;struct vop_reg enable;struct vop_reg gate;
@@ -173,6 +184,7 @@ struct vop_data {const struct vop_misc *misc;const struct vop_modeset *modeset;const struct vop_output *output; +const struct vop_afbc *afbc;const struct vop_win_yuv2yuv_data *win_yuv2yuv;const struct vop_win_data *win;unsigned int win_size;
drivers/gpu/drm/rockchip/rockchip_vop_reg.c +82 -2
199 lines not on this page · raw message
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel