Skip to content

Commit a5c71fd

Browse files
tejasuplucasdemarchi
authored andcommitted
drm/xe/hw_engine: define sysfs_ops on all directories
Sysfs_ops needs to be defined on all directories which can have attr files with set/get method. Add sysfs_ops to even those directories which is currently empty but would have attr files with set/get method in future. Leave .default with default sysfs_ops as it will never have setter method. V2(Himal/Rodrigo): - use single sysfs_ops for all dir and attr with set/get - add default ops as ./default does not need runtime pm at all Fixes: 3f0e146 ("drm/xe: Runtime PM wake on every sysfs call") Reviewed-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20250327122647.886637-1-tejas.upadhyay@intel.com Signed-off-by: Tejas Upadhyay <tejas.upadhyay@intel.com> (cherry picked from commit 40780b9) Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
1 parent 20659d3 commit a5c71fd

File tree

1 file changed

+52
-56
lines changed

1 file changed

+52
-56
lines changed

drivers/gpu/drm/xe/xe_hw_engine_class_sysfs.c

Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,61 @@ bool xe_hw_engine_timeout_in_range(u64 timeout, u64 min, u64 max)
3232
return timeout >= min && timeout <= max;
3333
}
3434

35-
static void kobj_xe_hw_engine_release(struct kobject *kobj)
35+
static void xe_hw_engine_sysfs_kobj_release(struct kobject *kobj)
3636
{
3737
kfree(kobj);
3838
}
3939

40+
static ssize_t xe_hw_engine_class_sysfs_attr_show(struct kobject *kobj,
41+
struct attribute *attr,
42+
char *buf)
43+
{
44+
struct xe_device *xe = kobj_to_xe(kobj);
45+
struct kobj_attribute *kattr;
46+
ssize_t ret = -EIO;
47+
48+
kattr = container_of(attr, struct kobj_attribute, attr);
49+
if (kattr->show) {
50+
xe_pm_runtime_get(xe);
51+
ret = kattr->show(kobj, kattr, buf);
52+
xe_pm_runtime_put(xe);
53+
}
54+
55+
return ret;
56+
}
57+
58+
static ssize_t xe_hw_engine_class_sysfs_attr_store(struct kobject *kobj,
59+
struct attribute *attr,
60+
const char *buf,
61+
size_t count)
62+
{
63+
struct xe_device *xe = kobj_to_xe(kobj);
64+
struct kobj_attribute *kattr;
65+
ssize_t ret = -EIO;
66+
67+
kattr = container_of(attr, struct kobj_attribute, attr);
68+
if (kattr->store) {
69+
xe_pm_runtime_get(xe);
70+
ret = kattr->store(kobj, kattr, buf, count);
71+
xe_pm_runtime_put(xe);
72+
}
73+
74+
return ret;
75+
}
76+
77+
static const struct sysfs_ops xe_hw_engine_class_sysfs_ops = {
78+
.show = xe_hw_engine_class_sysfs_attr_show,
79+
.store = xe_hw_engine_class_sysfs_attr_store,
80+
};
81+
4082
static const struct kobj_type kobj_xe_hw_engine_type = {
41-
.release = kobj_xe_hw_engine_release,
42-
.sysfs_ops = &kobj_sysfs_ops
83+
.release = xe_hw_engine_sysfs_kobj_release,
84+
.sysfs_ops = &xe_hw_engine_class_sysfs_ops,
85+
};
86+
87+
static const struct kobj_type kobj_xe_hw_engine_type_def = {
88+
.release = xe_hw_engine_sysfs_kobj_release,
89+
.sysfs_ops = &kobj_sysfs_ops,
4390
};
4491

4592
static ssize_t job_timeout_max_store(struct kobject *kobj,
@@ -543,7 +590,7 @@ static int xe_add_hw_engine_class_defaults(struct xe_device *xe,
543590
if (!kobj)
544591
return -ENOMEM;
545592

546-
kobject_init(kobj, &kobj_xe_hw_engine_type);
593+
kobject_init(kobj, &kobj_xe_hw_engine_type_def);
547594
err = kobject_add(kobj, parent, "%s", ".defaults");
548595
if (err)
549596
goto err_object;
@@ -559,57 +606,6 @@ static int xe_add_hw_engine_class_defaults(struct xe_device *xe,
559606
return err;
560607
}
561608

562-
static void xe_hw_engine_sysfs_kobj_release(struct kobject *kobj)
563-
{
564-
kfree(kobj);
565-
}
566-
567-
static ssize_t xe_hw_engine_class_sysfs_attr_show(struct kobject *kobj,
568-
struct attribute *attr,
569-
char *buf)
570-
{
571-
struct xe_device *xe = kobj_to_xe(kobj);
572-
struct kobj_attribute *kattr;
573-
ssize_t ret = -EIO;
574-
575-
kattr = container_of(attr, struct kobj_attribute, attr);
576-
if (kattr->show) {
577-
xe_pm_runtime_get(xe);
578-
ret = kattr->show(kobj, kattr, buf);
579-
xe_pm_runtime_put(xe);
580-
}
581-
582-
return ret;
583-
}
584-
585-
static ssize_t xe_hw_engine_class_sysfs_attr_store(struct kobject *kobj,
586-
struct attribute *attr,
587-
const char *buf,
588-
size_t count)
589-
{
590-
struct xe_device *xe = kobj_to_xe(kobj);
591-
struct kobj_attribute *kattr;
592-
ssize_t ret = -EIO;
593-
594-
kattr = container_of(attr, struct kobj_attribute, attr);
595-
if (kattr->store) {
596-
xe_pm_runtime_get(xe);
597-
ret = kattr->store(kobj, kattr, buf, count);
598-
xe_pm_runtime_put(xe);
599-
}
600-
601-
return ret;
602-
}
603-
604-
static const struct sysfs_ops xe_hw_engine_class_sysfs_ops = {
605-
.show = xe_hw_engine_class_sysfs_attr_show,
606-
.store = xe_hw_engine_class_sysfs_attr_store,
607-
};
608-
609-
static const struct kobj_type xe_hw_engine_sysfs_kobj_type = {
610-
.release = xe_hw_engine_sysfs_kobj_release,
611-
.sysfs_ops = &xe_hw_engine_class_sysfs_ops,
612-
};
613609

614610
static void hw_engine_class_sysfs_fini(void *arg)
615611
{
@@ -640,7 +636,7 @@ int xe_hw_engine_class_sysfs_init(struct xe_gt *gt)
640636
if (!kobj)
641637
return -ENOMEM;
642638

643-
kobject_init(kobj, &xe_hw_engine_sysfs_kobj_type);
639+
kobject_init(kobj, &kobj_xe_hw_engine_type);
644640

645641
err = kobject_add(kobj, gt->sysfs, "engines");
646642
if (err)

0 commit comments

Comments
 (0)