1 // SPDX-License-Identifier: MIT
3 * Copyright © 2024 Intel Corporation
5 #include <linux/sysfs.h>
6 #include <drm/drm_managed.h>
8 #include "xe_gt_types.h"
10 #include "xe_pcode_api.h"
12 #include "xe_tile_sysfs.h"
13 #include "xe_vram_freq.h"
18 * Provides sysfs entries for vram frequency in tile
20 * device/tile#/memory/freq0/max_freq - This is maximum frequency. This value is read-only as it
21 * is the fixed fuse point P0. It is not the system
23 * device/tile#/memory/freq0/min_freq - This is minimum frequency. This value is read-only as it
24 * is the fixed fuse point PN. It is not the system
28 static struct xe_tile *dev_to_tile(struct device *dev)
30 return kobj_to_tile(dev->kobj.parent);
33 static ssize_t max_freq_show(struct device *dev, struct device_attribute *attr,
36 struct xe_tile *tile = dev_to_tile(dev);
37 struct xe_gt *gt = tile->primary_gt;
41 mbox = REG_FIELD_PREP(PCODE_MB_COMMAND, PCODE_FREQUENCY_CONFIG)
42 | REG_FIELD_PREP(PCODE_MB_PARAM1, PCODE_MBOX_FC_SC_READ_FUSED_P0)
43 | REG_FIELD_PREP(PCODE_MB_PARAM2, PCODE_MBOX_DOMAIN_HBM);
45 err = xe_pcode_read(gt, mbox, &val, NULL);
49 /* data_out - Fused P0 for domain ID in units of 50 MHz */
52 return sysfs_emit(buf, "%u\n", val);
54 static DEVICE_ATTR_RO(max_freq);
56 static ssize_t min_freq_show(struct device *dev, struct device_attribute *attr,
59 struct xe_tile *tile = dev_to_tile(dev);
60 struct xe_gt *gt = tile->primary_gt;
64 mbox = REG_FIELD_PREP(PCODE_MB_COMMAND, PCODE_FREQUENCY_CONFIG)
65 | REG_FIELD_PREP(PCODE_MB_PARAM1, PCODE_MBOX_FC_SC_READ_FUSED_PN)
66 | REG_FIELD_PREP(PCODE_MB_PARAM2, PCODE_MBOX_DOMAIN_HBM);
68 err = xe_pcode_read(gt, mbox, &val, NULL);
72 /* data_out - Fused Pn for domain ID in units of 50 MHz */
75 return sysfs_emit(buf, "%u\n", val);
77 static DEVICE_ATTR_RO(min_freq);
79 static struct attribute *freq_attrs[] = {
80 &dev_attr_max_freq.attr,
81 &dev_attr_min_freq.attr,
85 static const struct attribute_group freq_group_attrs = {
90 static void vram_freq_sysfs_fini(struct drm_device *drm, void *arg)
92 struct kobject *kobj = arg;
94 sysfs_remove_group(kobj, &freq_group_attrs);
99 * xe_vram_freq_sysfs_init - Initialize vram frequency sysfs component
100 * @tile: Xe Tile object
102 * It needs to be initialized after the main tile component is ready
104 void xe_vram_freq_sysfs_init(struct xe_tile *tile)
106 struct xe_device *xe = tile_to_xe(tile);
107 struct kobject *kobj;
110 if (xe->info.platform != XE_PVC)
113 kobj = kobject_create_and_add("memory", tile->sysfs);
115 drm_warn(&xe->drm, "failed to add memory directory, err: %d\n", -ENOMEM);
117 err = sysfs_create_group(kobj, &freq_group_attrs);
120 drm_warn(&xe->drm, "failed to register vram freq sysfs, err: %d\n", err);
124 err = drmm_add_action_or_reset(&xe->drm, vram_freq_sysfs_fini, kobj);
126 drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed, err: %d\n",