The vc4_bo_dumb_create() both fixes up the allocation arguments to match the hardware constraints and actually performs the allocation. Since we're going to introduce a new function that uses a different allocator, let's split the arguments fixup to a separate function we will be able to reuse.
Unified · Split
| @@ -475,15 +475,12 @@ int vc4_bo_dumb_create(struct drm_file *file_priv, · 474 unmodified lines | ||
| 475 | 475 | struct drm_device *dev, |
| 476 | 476 | struct drm_mode_create_dumb *args) |
| 477 | 477 | { |
| 478 | − int min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8); | |
| 479 | 478 | struct vc4_bo *bo = NULL; |
| 480 | 479 | int ret; |
| 481 | 480 | |
| 482 | − if (args->pitch < min_pitch) | |
| 483 | − args->pitch = min_pitch; | |
| 484 | − | |
| 485 | − if (args->size < args->pitch * args->height) | |
| 486 | − args->size = args->pitch * args->height; | |
| 481 | + ret = vc4_dumb_fixup_args(args); | |
| 482 | + if (ret) | |
| 483 | + return ret; | |
| 487 | 484 | |
| 488 | 485 | bo = vc4_bo_create(dev, args->size, false, VC4_BO_TYPE_DUMB); |
| 489 | 486 | if (IS_ERR(bo)) |
| @@ -63,6 +63,19 @@ void __iomem *vc4_ioremap_regs(struct platform_device *pdev, int index) · 62 unmodified lines | ||
| 63 | 63 | return map; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | +int vc4_dumb_fixup_args(struct drm_mode_create_dumb *args) | |
| 67 | +{ | |
| 68 | + int min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8); | |
| 69 | + | |
| 70 | + if (args->pitch < min_pitch) | |
| 71 | + args->pitch = min_pitch; | |
| 72 | + | |
| 73 | + if (args->size < args->pitch * args->height) | |
| 74 | + args->size = args->pitch * args->height; | |
| 75 | + | |
| 76 | + return 0; | |
| 77 | +} | |
| 78 | + | |
| 66 | 79 | static int vc4_get_param_ioctl(struct drm_device *dev, void *data, |
| 67 | 80 | struct drm_file *file_priv) |
| 68 | 81 | { |
| @@ -885,6 +885,7 @@ static inline void vc4_debugfs_add_regset32(struct drm_device *drm, · 884 unmodified lines | ||
| 885 | 885 | |
| 886 | 886 | /* vc4_drv.c */ |
| 887 | 887 | void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index); |
| 888 | +int vc4_dumb_fixup_args(struct drm_mode_create_dumb *args); | |
| 888 | 889 | |
| 889 | 890 | /* vc4_dpi.c */ |
| 890 | 891 | extern struct platform_driver vc4_dpi_driver; |