summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/xe/xe_gt_sysfs.c
blob: 2d966d935b8e0582084d5096525ec7efe29bcea6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-License-Identifier: MIT
/*
 * Copyright © 2022 Intel Corporation
 */

#include <linux/kobject.h>
#include <linux/sysfs.h>
#include <drm/drm_managed.h>
#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(&gt_to_xe(gt)->drm, gt_sysfs_fini, gt);
	if (err)
		return err;

	return 0;
}