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 #include "xe_vram_freq.h" 13 14 static void xe_tile_sysfs_kobj_release(struct kobject *kobj) 15 { 16 kfree(kobj); 17 } 18 19 static const struct kobj_type xe_tile_sysfs_kobj_type = { 20 .release = xe_tile_sysfs_kobj_release, 21 .sysfs_ops = &kobj_sysfs_ops, 22 }; 23 24 static void tile_sysfs_fini(struct drm_device *drm, void *arg) 25 { 26 struct xe_tile *tile = arg; 27 28 kobject_put(tile->sysfs); 29 } 30 31 void xe_tile_sysfs_init(struct xe_tile *tile) 32 { 33 struct xe_device *xe = tile_to_xe(tile); 34 struct device *dev = xe->drm.dev; 35 struct kobj_tile *kt; 36 int err; 37 38 kt = kzalloc(sizeof(*kt), GFP_KERNEL); 39 if (!kt) 40 return; 41 42 kobject_init(&kt->base, &xe_tile_sysfs_kobj_type); 43 kt->tile = tile; 44 45 err = kobject_add(&kt->base, &dev->kobj, "tile%d", tile->id); 46 if (err) { 47 kobject_put(&kt->base); 48 drm_warn(&xe->drm, "failed to register TILE sysfs directory, err: %d\n", err); 49 return; 50 } 51 52 tile->sysfs = &kt->base; 53 54 xe_vram_freq_sysfs_init(tile); 55 56 err = drmm_add_action_or_reset(&xe->drm, tile_sysfs_fini, tile); 57 if (err) 58 drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed, err: %d\n", 59 __func__, err); 60 } 61