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