Skip to content

Commit db1689a

Browse files
bwidawskfooishbar
authored andcommitted
drm: Create a format/modifier blob
Updated blob layout (Rob, Daniel, Kristian, xerpi) v2: * Removed __packed, and alignment (.+) * Fix indent in drm_format_modifier fields (Liviu) * Remove duplicated modifier > 64 check (Liviu) * Change comment about modifier (Liviu) * Remove arguments to blob creation, use plane instead (Liviu) * Fix data types (Ben) * Make the blob part of uapi (Daniel) v3: Remove unused ret field. Change i, and j to unsigned int (Emil) v4: Use plane->modifier_count instead of recounting (Daniel) v5: Rename modifiers to modifiers_property (Ville) Use sizeof(__u32) instead to reflect UAPI nature (Ville) Make BUILD_BUG_ON for blob header size Cc: Rob Clark <robdclark@gmail.com> Cc: Kristian H. Kristensen <hoegsberg@gmail.com> Signed-off-by: Ben Widawsky <ben@bwidawsk.net> Reviewed-by: Daniel Stone <daniels@collabora.com> (v2) Reviewed-by: Liviu Dudau <liviu@dudau.co.uk> (v2) Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> (v3) Signed-off-by: Daniel Stone <daniels@collabora.com> Link: http://patchwork.freedesktop.org/patch/msgid/20170724034641.13369-2-ben@bwidawsk.net
1 parent e6fc3b6 commit db1689a

4 files changed

Lines changed: 147 additions & 0 deletions

File tree

‎drivers/gpu/drm/drm_mode_config.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,13 @@ static int drm_mode_create_standard_properties(struct drm_device *dev)
337337
return -ENOMEM;
338338
dev->mode_config.gamma_lut_size_property = prop;
339339

340+
prop = drm_property_create(dev,
341+
DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_BLOB,
342+
"IN_FORMATS", 0);
343+
if (!prop)
344+
return -ENOMEM;
345+
dev->mode_config.modifiers_property = prop;
346+
340347
return 0;
341348
}
342349

‎drivers/gpu/drm/drm_plane.c‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,87 @@ static unsigned int drm_num_planes(struct drm_device *dev)
6262
return num;
6363
}
6464

65+
static inline u32 *
66+
formats_ptr(struct drm_format_modifier_blob *blob)
67+
{
68+
return (u32 *)(((char *)blob) + blob->formats_offset);
69+
}
70+
71+
static inline struct drm_format_modifier *
72+
modifiers_ptr(struct drm_format_modifier_blob *blob)
73+
{
74+
return (struct drm_format_modifier *)(((char *)blob) + blob->modifiers_offset);
75+
}
76+
77+
static int create_in_format_blob(struct drm_device *dev, struct drm_plane *plane)
78+
{
79+
const struct drm_mode_config *config = &dev->mode_config;
80+
struct drm_property_blob *blob;
81+
struct drm_format_modifier *mod;
82+
size_t blob_size, formats_size, modifiers_size;
83+
struct drm_format_modifier_blob *blob_data;
84+
unsigned int i, j;
85+
86+
formats_size = sizeof(__u32) * plane->format_count;
87+
if (WARN_ON(!formats_size)) {
88+
/* 0 formats are never expected */
89+
return 0;
90+
}
91+
92+
modifiers_size =
93+
sizeof(struct drm_format_modifier) * plane->modifier_count;
94+
95+
blob_size = sizeof(struct drm_format_modifier_blob);
96+
/* Modifiers offset is a pointer to a struct with a 64 bit field so it
97+
* should be naturally aligned to 8B.
98+
*/
99+
BUILD_BUG_ON(sizeof(struct drm_format_modifier_blob) % 8);
100+
blob_size += ALIGN(formats_size, 8);
101+
blob_size += modifiers_size;
102+
103+
blob = drm_property_create_blob(dev, blob_size, NULL);
104+
if (IS_ERR(blob))
105+
return -1;
106+
107+
blob_data = (struct drm_format_modifier_blob *)blob->data;
108+
blob_data->version = FORMAT_BLOB_CURRENT;
109+
blob_data->count_formats = plane->format_count;
110+
blob_data->formats_offset = sizeof(struct drm_format_modifier_blob);
111+
blob_data->count_modifiers = plane->modifier_count;
112+
113+
blob_data->modifiers_offset =
114+
ALIGN(blob_data->formats_offset + formats_size, 8);
115+
116+
memcpy(formats_ptr(blob_data), plane->format_types, formats_size);
117+
118+
/* If we can't determine support, just bail */
119+
if (!plane->funcs->format_mod_supported)
120+
goto done;
121+
122+
mod = modifiers_ptr(blob_data);
123+
for (i = 0; i < plane->modifier_count; i++) {
124+
for (j = 0; j < plane->format_count; j++) {
125+
if (plane->funcs->format_mod_supported(plane,
126+
plane->format_types[j],
127+
plane->modifiers[i])) {
128+
129+
mod->formats |= 1 << j;
130+
}
131+
}
132+
133+
mod->modifier = plane->modifiers[i];
134+
mod->offset = 0;
135+
mod->pad = 0;
136+
mod++;
137+
}
138+
139+
done:
140+
drm_object_attach_property(&plane->base, config->modifiers_property,
141+
blob->base.id);
142+
143+
return 0;
144+
}
145+
65146
/**
66147
* drm_universal_plane_init - Initialize a new universal plane object
67148
* @dev: DRM device
@@ -181,6 +262,9 @@ int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane,
181262
drm_object_attach_property(&plane->base, config->prop_src_h, 0);
182263
}
183264

265+
if (config->allow_fb_modifiers)
266+
create_in_format_blob(dev, plane);
267+
184268
return 0;
185269
}
186270
EXPORT_SYMBOL(drm_universal_plane_init);

‎include/drm/drm_mode_config.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,12 @@ struct drm_mode_config {
757757
*/
758758
bool allow_fb_modifiers;
759759

760+
/**
761+
* @modifiers: Plane property to list support modifier/format
762+
* combination.
763+
*/
764+
struct drm_property *modifiers_property;
765+
760766
/* cursor size */
761767
uint32_t cursor_width, cursor_height;
762768

‎include/uapi/drm/drm_mode.h‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,56 @@ struct drm_mode_atomic {
712712
__u64 user_data;
713713
};
714714

715+
struct drm_format_modifier_blob {
716+
#define FORMAT_BLOB_CURRENT 1
717+
/* Version of this blob format */
718+
u32 version;
719+
720+
/* Flags */
721+
u32 flags;
722+
723+
/* Number of fourcc formats supported */
724+
u32 count_formats;
725+
726+
/* Where in this blob the formats exist (in bytes) */
727+
u32 formats_offset;
728+
729+
/* Number of drm_format_modifiers */
730+
u32 count_modifiers;
731+
732+
/* Where in this blob the modifiers exist (in bytes) */
733+
u32 modifiers_offset;
734+
735+
/* u32 formats[] */
736+
/* struct drm_format_modifier modifiers[] */
737+
};
738+
739+
struct drm_format_modifier {
740+
/* Bitmask of formats in get_plane format list this info applies to. The
741+
* offset allows a sliding window of which 64 formats (bits).
742+
*
743+
* Some examples:
744+
* In today's world with < 65 formats, and formats 0, and 2 are
745+
* supported
746+
* 0x0000000000000005
747+
* ^-offset = 0, formats = 5
748+
*
749+
* If the number formats grew to 128, and formats 98-102 are
750+
* supported with the modifier:
751+
*
752+
* 0x0000003c00000000 0000000000000000
753+
* ^
754+
* |__offset = 64, formats = 0x3c00000000
755+
*
756+
*/
757+
__u64 formats;
758+
__u32 offset;
759+
__u32 pad;
760+
761+
/* The modifier that applies to the >get_plane format list bitmask. */
762+
__u64 modifier;
763+
};
764+
715765
/**
716766
* Create a new 'blob' data property, copying length bytes from data pointer,
717767
* and returning new blob ID.

0 commit comments

Comments
 (0)