// SPDX-License-Identifier: MIT /* * Copyright © 2022 Intel Corporation */ #include #include #include #include "xe_gt.h" #include "xe_gt_sysfs.h" static void xe_gt_sysfs_kobj_release(struct kobject *kobj) { kfree(kobj); } static struct kobj_type xe_gt_sysfs_kobj_type = { .release = xe_gt_sysfs_kobj_release, .sysfs_ops = &kobj_sysfs_ops, }; static void gt_sysfs_fini(struct drm_device *drm, void *arg) { struct xe_gt *gt = arg; kobject_put(gt->sysfs); } int xe_gt_sysfs_init(struct xe_gt *gt) { struct device *dev = gt_to_xe(gt)->drm.dev; struct kobj_gt *kg; int err; kg = kzalloc(sizeof(*kg), GFP_KERNEL); if (!kg) return -ENOMEM; kobject_init(&kg->base, &xe_gt_sysfs_kobj_type); kg->gt = gt; err = kobject_add(&kg->base, &dev->kobj, "gt%d", gt->info.id); if (err) { kobject_put(&kg->base); return err; } gt->sysfs = &kg->base; err = drmm_add_action_or_reset(>_to_xe(gt)->drm, gt_sysfs_fini, gt); if (err) return err; return 0; }