mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 23:03:57 -04:00
PCI subsystem is not supposed to call the remove() function when probe fails and doesn't need a protection for that. The only places checking for NULL drvdata, is on 2 sysfs files and they shouldn't be needed since the files are removed and reads on open fds just return an error. For this protection the core driver implementation in drivers/base/dd.c:device_unbind_cleanup() already sets it to NULL, after the release of dev resources. Remove the setting to NULL so it's possible to obtain the xe pointer from callbacks like the component unbind from device_unbind_cleanup(), i.e. after xe_pci_remove() already finished. Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Reviewed-by: Jonathan Cavitt <jonathan.cavitt@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20250222001051.3012936-5-lucas.demarchi@intel.com Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
84 lines
2.0 KiB
C
84 lines
2.0 KiB
C
// SPDX-License-Identifier: MIT
|
|
/*
|
|
* Copyright © 2023 Intel Corporation
|
|
*/
|
|
|
|
#include <linux/kobject.h>
|
|
#include <linux/pci.h>
|
|
#include <linux/sysfs.h>
|
|
|
|
#include <drm/drm_managed.h>
|
|
|
|
#include "xe_device.h"
|
|
#include "xe_device_sysfs.h"
|
|
#include "xe_pm.h"
|
|
|
|
/**
|
|
* DOC: Xe device sysfs
|
|
* Xe driver requires exposing certain tunable knobs controlled by user space for
|
|
* each graphics device. Considering this, we need to add sysfs attributes at device
|
|
* level granularity.
|
|
* These sysfs attributes will be available under pci device kobj directory.
|
|
*
|
|
* vram_d3cold_threshold - Report/change vram used threshold(in MB) below
|
|
* which vram save/restore is permissible during runtime D3cold entry/exit.
|
|
*/
|
|
|
|
static ssize_t
|
|
vram_d3cold_threshold_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
struct xe_device *xe = pdev_to_xe_device(pdev);
|
|
int ret;
|
|
|
|
xe_pm_runtime_get(xe);
|
|
ret = sysfs_emit(buf, "%d\n", xe->d3cold.vram_threshold);
|
|
xe_pm_runtime_put(xe);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static ssize_t
|
|
vram_d3cold_threshold_store(struct device *dev, struct device_attribute *attr,
|
|
const char *buff, size_t count)
|
|
{
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
struct xe_device *xe = pdev_to_xe_device(pdev);
|
|
u32 vram_d3cold_threshold;
|
|
int ret;
|
|
|
|
ret = kstrtou32(buff, 0, &vram_d3cold_threshold);
|
|
if (ret)
|
|
return ret;
|
|
|
|
drm_dbg(&xe->drm, "vram_d3cold_threshold: %u\n", vram_d3cold_threshold);
|
|
|
|
xe_pm_runtime_get(xe);
|
|
ret = xe_pm_set_vram_threshold(xe, vram_d3cold_threshold);
|
|
xe_pm_runtime_put(xe);
|
|
|
|
return ret ?: count;
|
|
}
|
|
|
|
static DEVICE_ATTR_RW(vram_d3cold_threshold);
|
|
|
|
static void xe_device_sysfs_fini(void *arg)
|
|
{
|
|
struct xe_device *xe = arg;
|
|
|
|
sysfs_remove_file(&xe->drm.dev->kobj, &dev_attr_vram_d3cold_threshold.attr);
|
|
}
|
|
|
|
int xe_device_sysfs_init(struct xe_device *xe)
|
|
{
|
|
struct device *dev = xe->drm.dev;
|
|
int ret;
|
|
|
|
ret = sysfs_create_file(&dev->kobj, &dev_attr_vram_d3cold_threshold.attr);
|
|
if (ret)
|
|
return ret;
|
|
|
|
return devm_add_action_or_reset(dev, xe_device_sysfs_fini, xe);
|
|
}
|