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