Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/vkms: fix 32bit compilation error by replacing macros

Replace vkms_formats macro for fixed-point operations with functions
from drm/drm_fixed.h to do the same job and fix 32-bit compilation
errors.

v2:
- don't cast results to s32 (Igor)
- add missing drm_fixp2int conversion (Igor)

Fixes: a19c2ac9858 ("drm: vkms: Add support to the RGB565 format")
Tested-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com> (v1)
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v1)
Reported-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Melissa Wen <mwen@igalia.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220910190303.682897-1-mwen@igalia.com

authored by

Melissa Wen and committed by
Dave Airlie
89b03aea fb34d8a0

+19 -34
+19 -34
drivers/gpu/drm/vkms/vkms_formats.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0+ 2 2 3 - #include <drm/drm_rect.h> 3 + #include <linux/kernel.h> 4 4 #include <linux/minmax.h> 5 + #include <drm/drm_rect.h> 6 + #include <drm/drm_fixed.h> 5 7 6 8 #include "vkms_formats.h" 7 - 8 - /* The following macros help doing fixed point arithmetic. */ 9 - /* 10 - * With Fixed-Point scale 15 we have 17 and 15 bits of integer and fractional 11 - * parts respectively. 12 - * | 0000 0000 0000 0000 0.000 0000 0000 0000 | 13 - * 31 0 14 - */ 15 - #define SHIFT 15 16 - 17 - #define INT_TO_FIXED(a) ((a) << SHIFT) 18 - #define FIXED_MUL(a, b) ((s32)(((s64)(a) * (b)) >> SHIFT)) 19 - #define FIXED_DIV(a, b) ((s32)(((s64)(a) << SHIFT) / (b))) 20 - /* This macro converts a fixed point number to int, and round half up it */ 21 - #define FIXED_TO_INT_ROUND(a) (((a) + (1 << (SHIFT - 1))) >> SHIFT) 22 - #define INT_TO_FIXED_DIV(a, b) (FIXED_DIV(INT_TO_FIXED(a), INT_TO_FIXED(b))) 23 - #define INT_TO_FIXED_DIV(a, b) (FIXED_DIV(INT_TO_FIXED(a), INT_TO_FIXED(b))) 24 9 25 10 static size_t pixel_offset(const struct vkms_frame_info *frame_info, int x, int y) 26 11 { ··· 122 137 int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst), 123 138 stage_buffer->n_pixels); 124 139 125 - s32 fp_rb_ratio = INT_TO_FIXED_DIV(65535, 31); 126 - s32 fp_g_ratio = INT_TO_FIXED_DIV(65535, 63); 140 + s64 fp_rb_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(31)); 141 + s64 fp_g_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(63)); 127 142 128 143 for (size_t x = 0; x < x_limit; x++, src_pixels++) { 129 144 u16 rgb_565 = le16_to_cpu(*src_pixels); 130 - s32 fp_r = INT_TO_FIXED((rgb_565 >> 11) & 0x1f); 131 - s32 fp_g = INT_TO_FIXED((rgb_565 >> 5) & 0x3f); 132 - s32 fp_b = INT_TO_FIXED(rgb_565 & 0x1f); 145 + s64 fp_r = drm_int2fixp((rgb_565 >> 11) & 0x1f); 146 + s64 fp_g = drm_int2fixp((rgb_565 >> 5) & 0x3f); 147 + s64 fp_b = drm_int2fixp(rgb_565 & 0x1f); 133 148 134 149 out_pixels[x].a = (u16)0xffff; 135 - out_pixels[x].r = FIXED_TO_INT_ROUND(FIXED_MUL(fp_r, fp_rb_ratio)); 136 - out_pixels[x].g = FIXED_TO_INT_ROUND(FIXED_MUL(fp_g, fp_g_ratio)); 137 - out_pixels[x].b = FIXED_TO_INT_ROUND(FIXED_MUL(fp_b, fp_rb_ratio)); 150 + out_pixels[x].r = drm_fixp2int(drm_fixp_mul(fp_r, fp_rb_ratio)); 151 + out_pixels[x].g = drm_fixp2int(drm_fixp_mul(fp_g, fp_g_ratio)); 152 + out_pixels[x].b = drm_fixp2int(drm_fixp_mul(fp_b, fp_rb_ratio)); 138 153 } 139 154 } 140 155 ··· 233 248 int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst), 234 249 src_buffer->n_pixels); 235 250 236 - s32 fp_rb_ratio = INT_TO_FIXED_DIV(65535, 31); 237 - s32 fp_g_ratio = INT_TO_FIXED_DIV(65535, 63); 251 + s64 fp_rb_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(31)); 252 + s64 fp_g_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(63)); 238 253 239 254 for (size_t x = 0; x < x_limit; x++, dst_pixels++) { 240 - s32 fp_r = INT_TO_FIXED(in_pixels[x].r); 241 - s32 fp_g = INT_TO_FIXED(in_pixels[x].g); 242 - s32 fp_b = INT_TO_FIXED(in_pixels[x].b); 255 + s64 fp_r = drm_int2fixp(in_pixels[x].r); 256 + s64 fp_g = drm_int2fixp(in_pixels[x].g); 257 + s64 fp_b = drm_int2fixp(in_pixels[x].b); 243 258 244 - u16 r = FIXED_TO_INT_ROUND(FIXED_DIV(fp_r, fp_rb_ratio)); 245 - u16 g = FIXED_TO_INT_ROUND(FIXED_DIV(fp_g, fp_g_ratio)); 246 - u16 b = FIXED_TO_INT_ROUND(FIXED_DIV(fp_b, fp_rb_ratio)); 259 + u16 r = drm_fixp2int(drm_fixp_div(fp_r, fp_rb_ratio)); 260 + u16 g = drm_fixp2int(drm_fixp_div(fp_g, fp_g_ratio)); 261 + u16 b = drm_fixp2int(drm_fixp_div(fp_b, fp_rb_ratio)); 247 262 248 263 *dst_pixels = cpu_to_le16(r << 11 | g << 5 | b); 249 264 }