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