Skip to content

Commit a345c59

Browse files
vsyrjalametux
authored andcommitted
modesetting: Parse the IN_FORMATS_ASYNC blob
The kernel has gained another format/modifier blob to indicate which formats/modifiers support async flips since Linux 6.16. Parse it. Signed-off-by: notbabaisyou <[email protected]>
1 parent a87fb75 commit a345c59

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

hw/xfree86/drivers/video/modesetting/drmmode_display.c

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,19 @@ get_opaque_format(uint32_t format)
118118
}
119119
}
120120

121+
static drmmode_format_ptr
122+
drmmode_crtc_get_format(drmmode_crtc_private_ptr drmmode_crtc,
123+
Bool async_flip, int i)
124+
{
125+
if (async_flip && drmmode_crtc->formats_async)
126+
return &drmmode_crtc->formats_async[i];
127+
else
128+
return &drmmode_crtc->formats[i];
129+
}
130+
121131
Bool
122-
drmmode_is_format_supported(ScrnInfoPtr scrn, uint32_t format, uint64_t modifier)
132+
drmmode_is_format_supported(ScrnInfoPtr scrn, uint32_t format,
133+
uint64_t modifier, Bool async_flip)
123134
{
124135
xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
125136
int c, i, j;
@@ -139,7 +150,7 @@ drmmode_is_format_supported(ScrnInfoPtr scrn, uint32_t format, uint64_t modifier
139150
continue;
140151

141152
for (i = 0; i < drmmode_crtc->num_formats; i++) {
142-
drmmode_format_ptr iter = &drmmode_crtc->formats[i];
153+
drmmode_format_ptr iter = drmmode_crtc_get_format(drmmode_crtc, async_flip, i);
143154

144155
if (iter->format != format)
145156
continue;
@@ -170,7 +181,7 @@ drmmode_is_format_supported(ScrnInfoPtr scrn, uint32_t format, uint64_t modifier
170181
#ifdef GBM_BO_WITH_MODIFIERS
171182
static uint32_t
172183
get_modifiers_set(ScrnInfoPtr scrn, uint32_t format, uint64_t **modifiers,
173-
Bool enabled_crtc_only, Bool exclude_multiplane)
184+
Bool enabled_crtc_only, Bool exclude_multiplane, Bool async_flip)
174185
{
175186
xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
176187
modesettingPtr ms = modesettingPTR(scrn);
@@ -190,7 +201,7 @@ get_modifiers_set(ScrnInfoPtr scrn, uint32_t format, uint64_t **modifiers,
190201
continue;
191202

192203
for (i = 0; i < drmmode_crtc->num_formats; i++) {
193-
drmmode_format_ptr iter = &drmmode_crtc->formats[i];
204+
drmmode_format_ptr iter = drmmode_crtc_get_format(drmmode_crtc, async_flip, i);
194205

195206
if (iter->format != format)
196207
continue;
@@ -245,7 +256,8 @@ get_drawable_modifiers(DrawablePtr draw, uint32_t format,
245256
return TRUE;
246257
}
247258

248-
*num_modifiers = get_modifiers_set(scrn, format, modifiers, TRUE, FALSE);
259+
*num_modifiers = get_modifiers_set(scrn, format, modifiers,
260+
TRUE, FALSE, FALSE);
249261
return TRUE;
250262
}
251263
#endif
@@ -2404,7 +2416,7 @@ is_plane_assigned(ScrnInfoPtr scrn, int plane_id)
24042416
*/
24052417
static Bool
24062418
populate_format_modifiers(xf86CrtcPtr crtc, const drmModePlane *kplane,
2407-
uint32_t blob_id)
2419+
drmmode_format_rec *formats, uint32_t blob_id)
24082420
{
24092421
drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
24102422
drmmode_ptr drmmode = drmmode_crtc->drmmode;
@@ -2450,9 +2462,9 @@ populate_format_modifiers(xf86CrtcPtr crtc, const drmModePlane *kplane,
24502462
modifiers[num_modifiers - 1] = mod->modifier;
24512463
}
24522464

2453-
drmmode_crtc->formats[i].format = blob_formats[i];
2454-
drmmode_crtc->formats[i].modifiers = modifiers;
2455-
drmmode_crtc->formats[i].num_modifiers = num_modifiers;
2465+
formats[i].format = blob_formats[i];
2466+
formats[i].modifiers = modifiers;
2467+
formats[i].num_modifiers = num_modifiers;
24562468
}
24572469

24582470
drmModeFreePropertyBlob(blob);
@@ -2624,7 +2636,7 @@ drmmode_crtc_create_planes(xf86CrtcPtr crtc, int num)
26242636
drmModePlaneRes *kplane_res;
26252637
drmModePlane *kplane, *best_kplane = NULL;
26262638
drmModeObjectProperties *props;
2627-
uint32_t i, type, blob_id;
2639+
uint32_t i, type, blob_id, async_blob_id;
26282640
int current_crtc, best_plane = 0;
26292641

26302642
static drmmode_prop_enum_info_rec plane_type_enums[] = {
@@ -2647,6 +2659,7 @@ drmmode_crtc_create_planes(xf86CrtcPtr crtc, int num)
26472659
[DRMMODE_PLANE_FB_ID] = { .name = "FB_ID", },
26482660
[DRMMODE_PLANE_CRTC_ID] = { .name = "CRTC_ID", },
26492661
[DRMMODE_PLANE_IN_FORMATS] = { .name = "IN_FORMATS", },
2662+
[DRMMODE_PLANE_IN_FORMATS_ASYNC] = { .name = "IN_FORMATS_ASYNC", },
26502663
[DRMMODE_PLANE_SRC_X] = { .name = "SRC_X", },
26512664
[DRMMODE_PLANE_SRC_Y] = { .name = "SRC_Y", },
26522665
[DRMMODE_PLANE_SRC_W] = { .name = "SRC_W", },
@@ -2723,6 +2736,8 @@ drmmode_crtc_create_planes(xf86CrtcPtr crtc, int num)
27232736
best_kplane = kplane;
27242737
blob_id = drmmode_prop_get_value(&tmp_props[DRMMODE_PLANE_IN_FORMATS],
27252738
props, 0);
2739+
async_blob_id = drmmode_prop_get_value(&tmp_props[DRMMODE_PLANE_IN_FORMATS_ASYNC],
2740+
props, 0);
27262741
drmmode_prop_info_copy(drmmode_crtc->props_plane, tmp_props,
27272742
DRMMODE_PLANE__COUNT, 1);
27282743
drmModeFreeObjectProperties(props);
@@ -2734,6 +2749,8 @@ drmmode_crtc_create_planes(xf86CrtcPtr crtc, int num)
27342749
best_kplane = kplane;
27352750
blob_id = drmmode_prop_get_value(&tmp_props[DRMMODE_PLANE_IN_FORMATS],
27362751
props, 0);
2752+
async_blob_id = drmmode_prop_get_value(&tmp_props[DRMMODE_PLANE_IN_FORMATS_ASYNC],
2753+
props, 0);
27372754
drmmode_prop_info_copy(drmmode_crtc->props_plane, tmp_props,
27382755
DRMMODE_PLANE__COUNT, 1);
27392756
} else {
@@ -2748,9 +2765,18 @@ drmmode_crtc_create_planes(xf86CrtcPtr crtc, int num)
27482765
drmmode_crtc->num_formats = best_kplane->count_formats;
27492766
drmmode_crtc->formats = calloc(best_kplane->count_formats,
27502767
sizeof(drmmode_format_rec));
2751-
if (!populate_format_modifiers(crtc, best_kplane, blob_id)) {
2768+
if (!populate_format_modifiers(crtc, best_kplane,
2769+
drmmode_crtc->formats, blob_id)) {
27522770
for (i = 0; i < best_kplane->count_formats; i++)
27532771
drmmode_crtc->formats[i].format = best_kplane->formats[i];
2772+
} else {
2773+
drmmode_crtc->formats_async = calloc(best_kplane->count_formats,
2774+
sizeof(drmmode_format_rec));
2775+
if (!populate_format_modifiers(crtc, best_kplane,
2776+
drmmode_crtc->formats_async, async_blob_id)) {
2777+
free(drmmode_crtc->formats_async);
2778+
drmmode_crtc->formats_async = NULL;
2779+
}
27542780
}
27552781
drmModeFreePlane(best_kplane);
27562782
}

hw/xfree86/drivers/video/modesetting/drmmode_display.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ enum drmmode_plane_property {
4242
DRMMODE_PLANE_TYPE = 0,
4343
DRMMODE_PLANE_FB_ID,
4444
DRMMODE_PLANE_IN_FORMATS,
45+
DRMMODE_PLANE_IN_FORMATS_ASYNC,
4546
DRMMODE_PLANE_CRTC_ID,
4647
DRMMODE_PLANE_SRC_X,
4748
DRMMODE_PLANE_SRC_Y,
@@ -211,6 +212,7 @@ typedef struct {
211212
drmmode_mode_ptr current_mode;
212213
uint32_t num_formats;
213214
drmmode_format_rec *formats;
215+
drmmode_format_rec *formats_async;
214216

215217
drmmode_bo rotate_bo;
216218
unsigned rotate_fb_id;
@@ -316,7 +318,7 @@ typedef struct _msSpritePriv {
316318
extern miPointerSpriteFuncRec drmmode_sprite_funcs;
317319

318320
Bool drmmode_is_format_supported(ScrnInfoPtr scrn, uint32_t format,
319-
uint64_t modifier);
321+
uint64_t modifier, Bool async_flip);
320322
int drmmode_bo_import(drmmode_ptr drmmode, drmmode_bo *bo,
321323
uint32_t *fb_id);
322324
int drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo);

hw/xfree86/drivers/video/modesetting/present.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ ms_present_check_unflip(RRCrtcPtr crtc,
294294
modifier = gbm_bo_get_modifier(gbm);
295295
gbm_bo_destroy(gbm);
296296

297-
if (!drmmode_is_format_supported(scrn, format, modifier)) {
297+
if (!drmmode_is_format_supported(scrn, format, modifier, FALSE)) {
298298
if (reason)
299299
*reason = PRESENT_FLIP_REASON_BUFFER_FORMAT;
300300
return FALSE;

0 commit comments

Comments
 (0)