Merge pull request #444 from BlivionIaG/pr/gv11b-hwmon-platform

hwmon: generalize adapter slot registration to bus-agnostic struct device
This commit is contained in:
morebrackets
2026-12-03 08:51:43 -08:00
2 changed files with 31 additions and 15 deletions

View File

@ -46,7 +46,7 @@ extern int nv_rs_ga10x_hwmon_poll(u32 gpu_id, struct nv_rs_hwmon_sample *out);
struct nv_rs_hwmon_slot {
bool in_use;
u32 gpu_id;
struct pci_dev *pdev;
struct device *dev;
struct device *hwmon_dev;
struct mutex poll_lock;
spinlock_t sample_lock;
@ -357,23 +357,23 @@ static struct attribute *nv_rs_hwmon_extra_attrs[] = {
};
ATTRIBUTE_GROUPS(nv_rs_hwmon_extra);
int nv_rs_hwmon_register(struct pci_dev *pdev)
int nv_rs_hwmon_register_dev(struct device *dev, u32 gpu_id)
{
u32 gpu_id;
int i;
struct nv_rs_hwmon_slot *slot = NULL;
struct device *hwmon;
if (!pdev)
if (!dev)
return -EINVAL;
gpu_id = nv_rs_hwmon_gpu_id(pdev);
mutex_lock(&nv_rs_hwmon_lock);
for (i = 0; i < NV_RS_HWMON_MAX_GPUS; i++) {
if (!nv_rs_hwmon_slots[i].in_use) {
slot = &nv_rs_hwmon_slots[i];
break;
if (nv_rs_hwmon_slots[i].in_use && nv_rs_hwmon_slots[i].dev == dev) {
mutex_unlock(&nv_rs_hwmon_lock);
return -EEXIST;
}
if (!slot && !nv_rs_hwmon_slots[i].in_use)
slot = &nv_rs_hwmon_slots[i];
}
if (!slot) {
mutex_unlock(&nv_rs_hwmon_lock);
@ -384,7 +384,7 @@ int nv_rs_hwmon_register(struct pci_dev *pdev)
spin_lock_init(&slot->sample_lock);
slot->mirror_seq = 0;
slot->gpu_id = gpu_id;
slot->pdev = pdev;
slot->dev = dev;
/* Start with valid_mask = 0 (-ENODATA for every sensor) until live telemetry
* arrives; never publish fabricated placeholder readings (#141). */
slot->has_poll = false;
@ -403,13 +403,13 @@ int nv_rs_hwmon_register(struct pci_dev *pdev)
atomic_set(&slot->pstate, 0);
slot->in_use = true;
hwmon = hwmon_device_register_with_info(&pdev->dev, "nvdriver", slot,
hwmon = hwmon_device_register_with_info(dev, "nvdriver", slot,
&nv_rs_hwmon_chip_info,
nv_rs_hwmon_extra_groups);
if (IS_ERR(hwmon)) {
int err = PTR_ERR(hwmon);
slot->in_use = false;
slot->pdev = NULL;
slot->dev = NULL;
slot->gpu_id = 0;
mutex_unlock(&nv_rs_hwmon_lock);
return err;
@ -422,18 +422,18 @@ int nv_rs_hwmon_register(struct pci_dev *pdev)
return 0;
}
void nv_rs_hwmon_unregister(struct pci_dev *pdev)
void nv_rs_hwmon_unregister_dev(struct device *dev)
{
int i;
if (!pdev)
if (!dev)
return;
mutex_lock(&nv_rs_hwmon_lock);
for (i = 0; i < NV_RS_HWMON_MAX_GPUS; i++) {
if (nv_rs_hwmon_slots[i].in_use && nv_rs_hwmon_slots[i].pdev == pdev) {
if (nv_rs_hwmon_slots[i].in_use && nv_rs_hwmon_slots[i].dev == dev) {
struct device *hwmon = nv_rs_hwmon_slots[i].hwmon_dev;
nv_rs_hwmon_slots[i].hwmon_dev = NULL;
nv_rs_hwmon_slots[i].pdev = NULL;
nv_rs_hwmon_slots[i].dev = NULL;
WRITE_ONCE(nv_rs_hwmon_slots[i].gpu_id, 0);
mutex_unlock(&nv_rs_hwmon_lock);
if (hwmon)
@ -447,6 +447,19 @@ void nv_rs_hwmon_unregister(struct pci_dev *pdev)
mutex_unlock(&nv_rs_hwmon_lock);
}
int nv_rs_hwmon_register(struct pci_dev *pdev)
{
if (!pdev)
return -EINVAL;
return nv_rs_hwmon_register_dev(&pdev->dev, nv_rs_hwmon_gpu_id(pdev));
}
void nv_rs_hwmon_unregister(struct pci_dev *pdev)
{
if (pdev)
nv_rs_hwmon_unregister_dev(&pdev->dev);
}
void nv_rs_hwmon_update(u32 gpu_id,
u32 temp_c,
u32 power_mw,

View File

@ -4,6 +4,7 @@
#include <linux/types.h>
struct device;
struct pci_dev;
/* Bitmask bits for nv_rs_hwmon_sample::valid_mask (must match gpu::hwmon_telemetry). */
@ -36,6 +37,8 @@ struct nv_rs_hwmon_sample {
};
/* Register/unregister a standard Linux /sys/class/hwmon sensor node per GPU. */
int nv_rs_hwmon_register_dev(struct device *dev, u32 gpu_id);
void nv_rs_hwmon_unregister_dev(struct device *dev);
int nv_rs_hwmon_register(struct pci_dev *pdev);
void nv_rs_hwmon_unregister(struct pci_dev *pdev);