Skip to content

Commit e2a9854

Browse files
committed
drm/xe/configfs: Allow to select by class only
For a future configfs attribute, it's desirable to select by engine mask only as the instance doesn't make sense. Rename the function lookup_engine_mask() to lookup_engine_info() and make it return the entry. This allows parse_engine() to still return an item if the caller wants to allow parsing a class-only string like "rcs", "bcs", "ccs", etc. Reviewed-by: Raag Jadav <raag.jadav@intel.com> Link: https://lore.kernel.org/r/20250916-wa-bb-cmds-v5-2-306bddbc15da@intel.com Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
1 parent 7166cc3 commit e2a9854

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

drivers/gpu/drm/xe/xe_configfs.c

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,20 @@ static void set_device_defaults(struct xe_config_device *config)
152152
struct engine_info {
153153
const char *cls;
154154
u64 mask;
155+
enum xe_engine_class engine_class;
155156
};
156157

157158
/* Some helpful macros to aid on the sizing of buffer allocation when parsing */
158159
#define MAX_ENGINE_CLASS_CHARS 5
159160
#define MAX_ENGINE_INSTANCE_CHARS 2
160161

161162
static const struct engine_info engine_info[] = {
162-
{ .cls = "rcs", .mask = XE_HW_ENGINE_RCS_MASK },
163-
{ .cls = "bcs", .mask = XE_HW_ENGINE_BCS_MASK },
164-
{ .cls = "vcs", .mask = XE_HW_ENGINE_VCS_MASK },
165-
{ .cls = "vecs", .mask = XE_HW_ENGINE_VECS_MASK },
166-
{ .cls = "ccs", .mask = XE_HW_ENGINE_CCS_MASK },
167-
{ .cls = "gsccs", .mask = XE_HW_ENGINE_GSCCS_MASK },
163+
{ .cls = "rcs", .mask = XE_HW_ENGINE_RCS_MASK, .engine_class = XE_ENGINE_CLASS_RENDER },
164+
{ .cls = "bcs", .mask = XE_HW_ENGINE_BCS_MASK, .engine_class = XE_ENGINE_CLASS_COPY },
165+
{ .cls = "vcs", .mask = XE_HW_ENGINE_VCS_MASK, .engine_class = XE_ENGINE_CLASS_VIDEO_DECODE },
166+
{ .cls = "vecs", .mask = XE_HW_ENGINE_VECS_MASK, .engine_class = XE_ENGINE_CLASS_VIDEO_ENHANCE },
167+
{ .cls = "ccs", .mask = XE_HW_ENGINE_CCS_MASK, .engine_class = XE_ENGINE_CLASS_COMPUTE },
168+
{ .cls = "gsccs", .mask = XE_HW_ENGINE_GSCCS_MASK, .engine_class = XE_ENGINE_CLASS_OTHER },
168169
};
169170

170171
static struct xe_config_group_device *to_xe_config_group_device(struct config_item *item)
@@ -253,7 +254,18 @@ static ssize_t engines_allowed_show(struct config_item *item, char *page)
253254
return p - page;
254255
}
255256

256-
static bool lookup_engine_mask(const char *pattern, u64 *mask)
257+
/*
258+
* Lookup engine_info. If @mask is not NULL, reduce the mask according to the
259+
* instance in @pattern.
260+
*
261+
* Examples of inputs:
262+
* - lookup_engine_info("rcs0", &mask): return "rcs" entry from @engine_info and
263+
* mask == BIT_ULL(XE_HW_ENGINE_RCS0)
264+
* - lookup_engine_info("rcs*", &mask): return "rcs" entry from @engine_info and
265+
* mask == XE_HW_ENGINE_RCS_MASK
266+
* - lookup_engine_info("rcs", NULL): return "rcs" entry from @engine_info
267+
*/
268+
static const struct engine_info *lookup_engine_info(const char *pattern, u64 *mask)
257269
{
258270
for (size_t i = 0; i < ARRAY_SIZE(engine_info); i++) {
259271
u8 instance;
@@ -263,29 +275,33 @@ static bool lookup_engine_mask(const char *pattern, u64 *mask)
263275
continue;
264276

265277
pattern += strlen(engine_info[i].cls);
278+
if (!mask && !*pattern)
279+
return &engine_info[i];
266280

267281
if (!strcmp(pattern, "*")) {
268282
*mask = engine_info[i].mask;
269-
return true;
283+
return &engine_info[i];
270284
}
271285

272286
if (kstrtou8(pattern, 10, &instance))
273-
return false;
287+
return NULL;
274288

275289
bit = __ffs64(engine_info[i].mask) + instance;
276290
if (bit >= fls64(engine_info[i].mask))
277-
return false;
291+
return NULL;
278292

279293
*mask = BIT_ULL(bit);
280-
return true;
294+
return &engine_info[i];
281295
}
282296

283-
return false;
297+
return NULL;
284298
}
285299

286-
static int parse_engine(const char *s, const char *end_chars, u64 *mask)
300+
static int parse_engine(const char *s, const char *end_chars, u64 *mask,
301+
const struct engine_info **pinfo)
287302
{
288303
char buf[MAX_ENGINE_CLASS_CHARS + MAX_ENGINE_INSTANCE_CHARS + 1];
304+
const struct engine_info *info;
289305
size_t len;
290306

291307
len = strcspn(s, end_chars);
@@ -295,9 +311,13 @@ static int parse_engine(const char *s, const char *end_chars, u64 *mask)
295311
memcpy(buf, s, len);
296312
buf[len] = '\0';
297313

298-
if (!lookup_engine_mask(buf, mask))
314+
info = lookup_engine_info(buf, mask);
315+
if (!info)
299316
return -ENOENT;
300317

318+
if (pinfo)
319+
*pinfo = info;
320+
301321
return len;
302322
}
303323

@@ -309,7 +329,7 @@ static ssize_t engines_allowed_store(struct config_item *item, const char *page,
309329
u64 mask, val = 0;
310330

311331
for (p = 0; p < len; p += patternlen + 1) {
312-
patternlen = parse_engine(page + p, ",\n", &mask);
332+
patternlen = parse_engine(page + p, ",\n", &mask, NULL);
313333
if (patternlen < 0)
314334
return -EINVAL;
315335

0 commit comments

Comments
 (0)