Skip to content

Commit 58cd0cb

Browse files
committed
drm: Add helpers for q4 fixed point values
Add helpers to convert between q4 fixed point and integer/fraction values. Also add the format/argument macros required to printk q4 fixed point variables. The q4 notation is based on the short variant described by https://en.wikipedia.org/wiki/Q_(number_format) where only the number of fraction bits in the fixed point value are defined, while the full size is deducted from the container type, that is the size of int for these helpers. Using the fxp_ prefix, which makes moving these helpers outside of drm to a more generic place easier, if they prove to be useful. These are needed by later patches dumping the Display Stream Compression configuration in DRM core and in the i915 driver to replace the corresponding bpp_x16 helpers defined locally in the driver. v2: Use the more generic/descriptive fxp_q4 prefix instead of drm_x16. (Jani) Cc: Jani Nikula <[email protected]> Acked-by: Jani Nikula <[email protected]> Signed-off-by: Imre Deak <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent ddf9834 commit 58cd0cb

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

drivers/gpu/drm/display/drm_dp_helper.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <drm/display/drm_dp_helper.h>
3636
#include <drm/display/drm_dp_mst_helper.h>
3737
#include <drm/drm_edid.h>
38+
#include <drm/drm_fixed.h>
3839
#include <drm/drm_print.h>
3940
#include <drm/drm_vblank.h>
4041
#include <drm/drm_panel.h>
@@ -4151,9 +4152,9 @@ int drm_dp_bw_overhead(int lane_count, int hactive,
41514152
int symbol_cycles;
41524153

41534154
if (lane_count == 0 || hactive == 0 || bpp_x16 == 0) {
4154-
DRM_DEBUG_KMS("Invalid BW overhead params: lane_count %d, hactive %d, bpp_x16 %d.%04d\n",
4155+
DRM_DEBUG_KMS("Invalid BW overhead params: lane_count %d, hactive %d, bpp_x16 " FXP_Q4_FMT "\n",
41554156
lane_count, hactive,
4156-
bpp_x16 >> 4, (bpp_x16 & 0xf) * 625);
4157+
FXP_Q4_ARGS(bpp_x16));
41574158
return 0;
41584159
}
41594160

include/drm/drm_fixed.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,27 @@ static inline s64 drm_fixp_exp(s64 x)
214214
return sum;
215215
}
216216

217+
static inline int fxp_q4_from_int(int val_int)
218+
{
219+
return val_int << 4;
220+
}
221+
222+
static inline int fxp_q4_to_int(int val_q4)
223+
{
224+
return val_q4 >> 4;
225+
}
226+
227+
static inline int fxp_q4_to_int_roundup(int val_q4)
228+
{
229+
return (val_q4 + 0xf) >> 4;
230+
}
231+
232+
static inline int fxp_q4_to_frac(int val_q4)
233+
{
234+
return val_q4 & 0xf;
235+
}
236+
237+
#define FXP_Q4_FMT "%d.%04d"
238+
#define FXP_Q4_ARGS(val_q4) fxp_q4_to_int(val_q4), (fxp_q4_to_frac(val_q4) * 625)
239+
217240
#endif

0 commit comments

Comments
 (0)