Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 3f0e14651ab0 ("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 40780b9760b561e093508d07b8b9b06c94ab201e)
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>

authored by

Tejas Upadhyay and committed by
Lucas De Marchi
a5c71fd5 20659d31

+52 -56
+52 -56
drivers/gpu/drm/xe/xe_hw_engine_class_sysfs.c
··· 32 32 return timeout >= min && timeout <= max; 33 33 } 34 34 35 - static void kobj_xe_hw_engine_release(struct kobject *kobj) 35 + static void xe_hw_engine_sysfs_kobj_release(struct kobject *kobj) 36 36 { 37 37 kfree(kobj); 38 38 } 39 39 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 + 40 82 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, 43 90 }; 44 91 45 92 static ssize_t job_timeout_max_store(struct kobject *kobj, ··· 590 543 if (!kobj) 591 544 return -ENOMEM; 592 545 593 - kobject_init(kobj, &kobj_xe_hw_engine_type); 546 + kobject_init(kobj, &kobj_xe_hw_engine_type_def); 594 547 err = kobject_add(kobj, parent, "%s", ".defaults"); 595 548 if (err) 596 549 goto err_object; ··· 606 559 return err; 607 560 } 608 561 609 - static void xe_hw_engine_sysfs_kobj_release(struct kobject *kobj) 610 - { 611 - kfree(kobj); 612 - } 613 - 614 - static ssize_t xe_hw_engine_class_sysfs_attr_show(struct kobject *kobj, 615 - struct attribute *attr, 616 - char *buf) 617 - { 618 - struct xe_device *xe = kobj_to_xe(kobj); 619 - struct kobj_attribute *kattr; 620 - ssize_t ret = -EIO; 621 - 622 - kattr = container_of(attr, struct kobj_attribute, attr); 623 - if (kattr->show) { 624 - xe_pm_runtime_get(xe); 625 - ret = kattr->show(kobj, kattr, buf); 626 - xe_pm_runtime_put(xe); 627 - } 628 - 629 - return ret; 630 - } 631 - 632 - static ssize_t xe_hw_engine_class_sysfs_attr_store(struct kobject *kobj, 633 - struct attribute *attr, 634 - const char *buf, 635 - size_t count) 636 - { 637 - struct xe_device *xe = kobj_to_xe(kobj); 638 - struct kobj_attribute *kattr; 639 - ssize_t ret = -EIO; 640 - 641 - kattr = container_of(attr, struct kobj_attribute, attr); 642 - if (kattr->store) { 643 - xe_pm_runtime_get(xe); 644 - ret = kattr->store(kobj, kattr, buf, count); 645 - xe_pm_runtime_put(xe); 646 - } 647 - 648 - return ret; 649 - } 650 - 651 - static const struct sysfs_ops xe_hw_engine_class_sysfs_ops = { 652 - .show = xe_hw_engine_class_sysfs_attr_show, 653 - .store = xe_hw_engine_class_sysfs_attr_store, 654 - }; 655 - 656 - static const struct kobj_type xe_hw_engine_sysfs_kobj_type = { 657 - .release = xe_hw_engine_sysfs_kobj_release, 658 - .sysfs_ops = &xe_hw_engine_class_sysfs_ops, 659 - }; 660 562 661 563 static void hw_engine_class_sysfs_fini(void *arg) 662 564 { ··· 636 640 if (!kobj) 637 641 return -ENOMEM; 638 642 639 - kobject_init(kobj, &xe_hw_engine_sysfs_kobj_type); 643 + kobject_init(kobj, &kobj_xe_hw_engine_type); 640 644 641 645 err = kobject_add(kobj, gt->sysfs, "engines"); 642 646 if (err)