1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2022 Intel Corporation 4 */ 5 6 #include "xe_gt_sysfs.h" 7 8 #include <linux/kobject.h> 9 #include <linux/sysfs.h> 10 11 #include <drm/drm_managed.h> 12 13 #include "xe_gt.h" 14 15 static void xe_gt_sysfs_kobj_release(struct kobject *kobj) 16 { 17 kfree(kobj); 18 } 19 20 static const struct kobj_type xe_gt_sysfs_kobj_type = { 21 .release = xe_gt_sysfs_kobj_release, 22 .sysfs_ops = &kobj_sysfs_ops, 23 }; 24 25 static void gt_sysfs_fini(struct drm_device *drm, void *arg) 26 { 27 struct xe_gt *gt = arg; 28 29 kobject_put(gt->sysfs); 30 } 31 32 void xe_gt_sysfs_init(struct xe_gt *gt) 33 { 34 struct xe_tile *tile = gt_to_tile(gt); 35 struct xe_device *xe = gt_to_xe(gt); 36 struct kobj_gt *kg; 37 int err; 38 39 kg = kzalloc(sizeof(*kg), GFP_KERNEL); 40 if (!kg) 41 return; 42 43 kobject_init(&kg->base, &xe_gt_sysfs_kobj_type); 44 kg->gt = gt; 45 46 err = kobject_add(&kg->base, tile->sysfs, "gt%d", gt->info.id); 47 if (err) { 48 drm_warn(&xe->drm, "failed to add GT sysfs directory, err: %d\n", err); 49 kobject_put(&kg->base); 50 return; 51 } 52 53 gt->sysfs = &kg->base; 54 55 err = drmm_add_action_or_reset(&xe->drm, gt_sysfs_fini, gt); 56 if (err) { 57 drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed, err: %d\n", 58 __func__, err); 59 return; 60 } 61 } 62