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 | struct drm_device *dev, | 475 | struct drm_device *dev, |
| 476 | struct drm_mode_create_dumb *args) | 476 | struct drm_mode_create_dumb *args) |
| 477 | { | 477 | { |
| 478 | int min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8); | ||
| 479 | struct vc4_bo *bo = NULL; | 478 | struct vc4_bo *bo = NULL; |
| 480 | int ret; | 479 | int ret; |
| 481 | 480 | ||
| 482 | if (args->pitch < min_pitch) | 481 | ret = vc4_dumb_fixup_args(args); |
| 483 | args->pitch = min_pitch; | 482 | if (ret) |
| 484 | 483 | return ret; | |
| 485 | if (args->size < args->pitch * args->height) | ||
| 486 | args->size = args->pitch * args->height; | ||
| 487 | 484 | ||
| 488 | bo = vc4_bo_create(dev, args->size, false, VC4_BO_TYPE_DUMB); | 485 | bo = vc4_bo_create(dev, args->size, false, VC4_BO_TYPE_DUMB); |
| 489 | if (IS_ERR(bo)) | 486 | if (IS_ERR(bo)) |
| @@ -63,6 +63,19 @@ void __iomem *vc4_ioremap_regs(struct platform_device *pdev, int index) · 62 unmodified lines | |||
| 63 | return map; | 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 | static int vc4_get_param_ioctl(struct drm_device *dev, void *data, | 79 | static int vc4_get_param_ioctl(struct drm_device *dev, void *data, |
| 67 | struct drm_file *file_priv) | 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 | /* vc4_drv.c */ | 886 | /* vc4_drv.c */ |
| 887 | void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index); | 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 | /* vc4_dpi.c */ | 890 | /* vc4_dpi.c */ |
| 890 | extern struct platform_driver vc4_dpi_driver; | 891 | extern struct platform_driver vc4_dpi_driver; |