1// SPDX-License-Identifier: MIT 2/* 3 * Copyright �� 2022 Intel Corporation 4 */ 5 6#include <drm/drm_device.h> 7#include <linux/device.h> 8#include <linux/kobject.h> 9#include <linux/printk.h> 10#include <linux/sysfs.h> 11 12#include "i915_drv.h" 13#include "i915_sysfs.h" 14#include "intel_gt.h" 15#include "intel_gt_print.h" 16#include "intel_gt_sysfs.h" 17#include "intel_gt_sysfs_pm.h" 18#include "intel_gt_types.h" 19#include "intel_rc6.h" 20 21#ifdef notyet 22 23bool is_object_gt(struct kobject *kobj) 24{ 25 return !strncmp(kobj->name, "gt", 2); 26} 27 28struct intel_gt *intel_gt_sysfs_get_drvdata(struct kobject *kobj, 29 const char *name) 30{ 31 /* 32 * We are interested at knowing from where the interface 33 * has been called, whether it's called from gt/ or from 34 * the parent directory. 35 * From the interface position it depends also the value of 36 * the private data. 37 * If the interface is called from gt/ then private data is 38 * of the "struct intel_gt *" type, otherwise it's * a 39 * "struct drm_i915_private *" type. 40 */ 41 if (!is_object_gt(kobj)) { 42 struct device *dev = kobj_to_dev(kobj); 43 struct drm_i915_private *i915 = kdev_minor_to_i915(dev); 44 45 return to_gt(i915); 46 } 47 48 return kobj_to_gt(kobj); 49} 50 51static struct kobject *gt_get_parent_obj(struct intel_gt *gt) 52{ 53 return >->i915->drm.primary->kdev->kobj; 54} 55 56static ssize_t id_show(struct kobject *kobj, 57 struct kobj_attribute *attr, 58 char *buf) 59{ 60 struct intel_gt *gt = intel_gt_sysfs_get_drvdata(kobj, attr->attr.name); 61 62 return sysfs_emit(buf, "%u\n", gt->info.id); 63} 64static struct kobj_attribute attr_id = __ATTR_RO(id); 65 66static struct attribute *id_attrs[] = { 67 &attr_id.attr, 68 NULL, 69}; 70ATTRIBUTE_GROUPS(id); 71 72/* A kobject needs a release() method even if it does nothing */ 73static void kobj_gt_release(struct kobject *kobj) 74{ 75} 76 77static const struct kobj_type kobj_gt_type = { 78 .release = kobj_gt_release, 79 .sysfs_ops = &kobj_sysfs_ops, 80 .default_groups = id_groups, 81}; 82 83#endif /* notyet */ 84 85void intel_gt_sysfs_register(struct intel_gt *gt) 86{ 87#ifdef notyet 88 /* 89 * We need to make things right with the 90 * ABI compatibility. The files were originally 91 * generated under the parent directory. 92 * 93 * We generate the files only for gt 0 94 * to avoid duplicates. 95 */ 96 if (gt_is_root(gt)) 97 intel_gt_sysfs_pm_init(gt, gt_get_parent_obj(gt)); 98 99 /* init and xfer ownership to sysfs tree */ 100 if (kobject_init_and_add(>->sysfs_gt, &kobj_gt_type, 101 gt->i915->sysfs_gt, "gt%d", gt->info.id)) 102 goto exit_fail; 103 104 gt->sysfs_defaults = kobject_create_and_add(".defaults", >->sysfs_gt); 105 if (!gt->sysfs_defaults) 106 goto exit_fail; 107 108 intel_gt_sysfs_pm_init(gt, >->sysfs_gt); 109 110 return; 111 112exit_fail: 113 kobject_put(>->sysfs_gt); 114 gt_warn(gt, "failed to initialize sysfs root\n"); 115#endif 116} 117 118void intel_gt_sysfs_unregister(struct intel_gt *gt) 119{ 120#ifdef notyet 121 kobject_put(gt->sysfs_defaults); 122 kobject_put(>->sysfs_gt); 123#endif 124} 125