1 // SPDX-License-Identifier: MIT
3 * Copyright © 2023 Intel Corporation
6 #include <linux/kobject.h>
8 #include <linux/sysfs.h>
10 #include <drm/drm_managed.h>
12 #include "xe_device.h"
13 #include "xe_device_sysfs.h"
17 * DOC: Xe device sysfs
18 * Xe driver requires exposing certain tunable knobs controlled by user space for
19 * each graphics device. Considering this, we need to add sysfs attributes at device
21 * These sysfs attributes will be available under pci device kobj directory.
23 * vram_d3cold_threshold - Report/change vram used threshold(in MB) below
24 * which vram save/restore is permissible during runtime D3cold entry/exit.
28 vram_d3cold_threshold_show(struct device *dev,
29 struct device_attribute *attr, char *buf)
31 struct pci_dev *pdev = to_pci_dev(dev);
32 struct xe_device *xe = pdev_to_xe_device(pdev);
38 ret = sysfs_emit(buf, "%d\n", xe->d3cold.vram_threshold);
44 vram_d3cold_threshold_store(struct device *dev, struct device_attribute *attr,
45 const char *buff, size_t count)
47 struct pci_dev *pdev = to_pci_dev(dev);
48 struct xe_device *xe = pdev_to_xe_device(pdev);
49 u32 vram_d3cold_threshold;
55 ret = kstrtou32(buff, 0, &vram_d3cold_threshold);
59 drm_dbg(&xe->drm, "vram_d3cold_threshold: %u\n", vram_d3cold_threshold);
61 ret = xe_pm_set_vram_threshold(xe, vram_d3cold_threshold);
66 static DEVICE_ATTR_RW(vram_d3cold_threshold);
68 static void xe_device_sysfs_fini(struct drm_device *drm, void *arg)
70 struct xe_device *xe = arg;
72 sysfs_remove_file(&xe->drm.dev->kobj, &dev_attr_vram_d3cold_threshold.attr);
75 void xe_device_sysfs_init(struct xe_device *xe)
77 struct device *dev = xe->drm.dev;
80 ret = sysfs_create_file(&dev->kobj, &dev_attr_vram_d3cold_threshold.attr);
82 drm_warn(&xe->drm, "Failed to create sysfs file\n");
86 ret = drmm_add_action_or_reset(&xe->drm, xe_device_sysfs_fini, xe);
88 drm_warn(&xe->drm, "Failed to add sysfs fini drm action\n");