Re: [Nouveau] [PATCH v2 1/2] drm/nouveau: return temperatures in temp_get() via parameter
On Thu, Sep 17, 2020 at 4:11 PM Jeremy Cline wrote: > > On Wed, Sep 16, 2020 at 10:03:22PM +0200, Karol Herbst wrote: > > On Wed, Sep 16, 2020 at 10:01 PM Karol Herbst wrote: > > > > > > On Wed, Sep 16, 2020 at 9:47 PM Jeremy Cline wrote: > > > > > > > > The temp_get() function currently returns negative error numbers or a > > > > temperature. However, the thermal sensors can (in theory) measure > > > > negative temperatures. Some implementations of temp_get() correctly > > > > clamp negative temperature readings to 0 so that users do not mistake > > > > them for errors, but some, like gp100_temp_get(), do not. > > > > > > > > Rather than relying on implementations remembering to clamp values, > > > > dedicate the function return value to error codes and accept a pointer > > > > to an integer where the temperature reading should be stored. > > > > > > > > Signed-off-by: Jeremy Cline > > > > --- > > > > .../drm/nouveau/include/nvkm/subdev/therm.h | 2 +- > > > > drivers/gpu/drm/nouveau/nouveau_hwmon.c | 12 ++-- > > > > .../gpu/drm/nouveau/nvkm/subdev/therm/base.c | 19 ++- > > > > .../gpu/drm/nouveau/nvkm/subdev/therm/g84.c | 11 ++- > > > > .../gpu/drm/nouveau/nvkm/subdev/therm/gp100.c | 11 ++- > > > > .../gpu/drm/nouveau/nvkm/subdev/therm/nv40.c | 9 +++-- > > > > .../gpu/drm/nouveau/nvkm/subdev/therm/nv50.c | 9 +++-- > > > > .../gpu/drm/nouveau/nvkm/subdev/therm/priv.h | 17 +++-- > > > > .../gpu/drm/nouveau/nvkm/subdev/therm/temp.c | 12 > > > > 9 files changed, 62 insertions(+), 40 deletions(-) > > > > > > > > diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > > > > b/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > > > > index 62c34f98c930..bfe9779216fc 100644 > > > > --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > > > > +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > > > > @@ -99,7 +99,7 @@ struct nvkm_therm { > > > > bool clkgating_enabled; > > > > }; > > > > > > > > -int nvkm_therm_temp_get(struct nvkm_therm *); > > > > +int nvkm_therm_temp_get(struct nvkm_therm *therm, int *temp); > > > > int nvkm_therm_fan_sense(struct nvkm_therm *); > > > > int nvkm_therm_cstate(struct nvkm_therm *, int, int); > > > > void nvkm_therm_clkgate_init(struct nvkm_therm *, > > > > diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c > > > > b/drivers/gpu/drm/nouveau/nouveau_hwmon.c > > > > index 1c3104d20571..aff6aa296678 100644 > > > > --- a/drivers/gpu/drm/nouveau/nouveau_hwmon.c > > > > +++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.c > > > > @@ -325,7 +325,7 @@ nouveau_temp_is_visible(const void *data, u32 attr, > > > > int channel) > > > > struct nouveau_drm *drm = nouveau_drm((struct drm_device > > > > *)data); > > > > struct nvkm_therm *therm = nvxx_therm(>client.device); > > > > > > > > - if (!therm || !therm->attr_get || nvkm_therm_temp_get(therm) < > > > > 0) > > > > + if (!therm || !therm->attr_get || nvkm_therm_temp_get(therm, > > > > NULL) < 0) > > > > return 0; > > > > > > > > switch (attr) { > > > > @@ -419,7 +419,7 @@ nouveau_temp_read(struct device *dev, u32 attr, int > > > > channel, long *val) > > > > struct drm_device *drm_dev = dev_get_drvdata(dev); > > > > struct nouveau_drm *drm = nouveau_drm(drm_dev); > > > > struct nvkm_therm *therm = nvxx_therm(>client.device); > > > > - int ret; > > > > + int ret = 0, temp; > > > > > > > > if (!therm || !therm->attr_get) > > > > return -EOPNOTSUPP; > > > > @@ -428,8 +428,8 @@ nouveau_temp_read(struct device *dev, u32 attr, int > > > > channel, long *val) > > > > case hwmon_temp_input: > > > > if (drm_dev->switch_power_state != DRM_SWITCH_POWER_ON) > > > > return -EINVAL; > > > > - ret = nvkm_therm_temp_get(therm); > > > > - *val = ret < 0 ? ret : (ret * 1000); > > > > + ret = nvkm_therm_temp_get(therm, ); > > > > + *val = temp * 1000; > > > > break; > > > > case hwmon_temp_max: > > > > *val = therm->attr_get(therm, > > > > NVKM_THERM_ATTR_THRS_DOWN_CLK) > > > > @@ -459,7 +459,7 @@ nouveau_temp_read(struct device *dev, u32 attr, int > > > > channel, long *val) > > > > return -EOPNOTSUPP; > > > > } > > > > > > > > - return 0; > > > > + return ret; > > > > } > > > > > > > > static int > > > > @@ -735,7 +735,7 @@ nouveau_hwmon_init(struct drm_device *dev) > > > > hwmon->dev = dev; > > > > > > > > if (therm && therm->attr_get && therm->attr_set) { > > > > - if (nvkm_therm_temp_get(therm) >= 0) > > > > + if (nvkm_therm_temp_get(therm, NULL) >= 0) > > > > special_groups[i++] = > > > > _auto_point_sensor_group; > > > > if
Re: [Nouveau] [PATCH v2 1/2] drm/nouveau: return temperatures in temp_get() via parameter
On Wed, Sep 16, 2020 at 10:03:22PM +0200, Karol Herbst wrote: > On Wed, Sep 16, 2020 at 10:01 PM Karol Herbst wrote: > > > > On Wed, Sep 16, 2020 at 9:47 PM Jeremy Cline wrote: > > > > > > The temp_get() function currently returns negative error numbers or a > > > temperature. However, the thermal sensors can (in theory) measure > > > negative temperatures. Some implementations of temp_get() correctly > > > clamp negative temperature readings to 0 so that users do not mistake > > > them for errors, but some, like gp100_temp_get(), do not. > > > > > > Rather than relying on implementations remembering to clamp values, > > > dedicate the function return value to error codes and accept a pointer > > > to an integer where the temperature reading should be stored. > > > > > > Signed-off-by: Jeremy Cline > > > --- > > > .../drm/nouveau/include/nvkm/subdev/therm.h | 2 +- > > > drivers/gpu/drm/nouveau/nouveau_hwmon.c | 12 ++-- > > > .../gpu/drm/nouveau/nvkm/subdev/therm/base.c | 19 ++- > > > .../gpu/drm/nouveau/nvkm/subdev/therm/g84.c | 11 ++- > > > .../gpu/drm/nouveau/nvkm/subdev/therm/gp100.c | 11 ++- > > > .../gpu/drm/nouveau/nvkm/subdev/therm/nv40.c | 9 +++-- > > > .../gpu/drm/nouveau/nvkm/subdev/therm/nv50.c | 9 +++-- > > > .../gpu/drm/nouveau/nvkm/subdev/therm/priv.h | 17 +++-- > > > .../gpu/drm/nouveau/nvkm/subdev/therm/temp.c | 12 > > > 9 files changed, 62 insertions(+), 40 deletions(-) > > > > > > diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > > > b/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > > > index 62c34f98c930..bfe9779216fc 100644 > > > --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > > > +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > > > @@ -99,7 +99,7 @@ struct nvkm_therm { > > > bool clkgating_enabled; > > > }; > > > > > > -int nvkm_therm_temp_get(struct nvkm_therm *); > > > +int nvkm_therm_temp_get(struct nvkm_therm *therm, int *temp); > > > int nvkm_therm_fan_sense(struct nvkm_therm *); > > > int nvkm_therm_cstate(struct nvkm_therm *, int, int); > > > void nvkm_therm_clkgate_init(struct nvkm_therm *, > > > diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c > > > b/drivers/gpu/drm/nouveau/nouveau_hwmon.c > > > index 1c3104d20571..aff6aa296678 100644 > > > --- a/drivers/gpu/drm/nouveau/nouveau_hwmon.c > > > +++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.c > > > @@ -325,7 +325,7 @@ nouveau_temp_is_visible(const void *data, u32 attr, > > > int channel) > > > struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data); > > > struct nvkm_therm *therm = nvxx_therm(>client.device); > > > > > > - if (!therm || !therm->attr_get || nvkm_therm_temp_get(therm) < 0) > > > + if (!therm || !therm->attr_get || nvkm_therm_temp_get(therm, > > > NULL) < 0) > > > return 0; > > > > > > switch (attr) { > > > @@ -419,7 +419,7 @@ nouveau_temp_read(struct device *dev, u32 attr, int > > > channel, long *val) > > > struct drm_device *drm_dev = dev_get_drvdata(dev); > > > struct nouveau_drm *drm = nouveau_drm(drm_dev); > > > struct nvkm_therm *therm = nvxx_therm(>client.device); > > > - int ret; > > > + int ret = 0, temp; > > > > > > if (!therm || !therm->attr_get) > > > return -EOPNOTSUPP; > > > @@ -428,8 +428,8 @@ nouveau_temp_read(struct device *dev, u32 attr, int > > > channel, long *val) > > > case hwmon_temp_input: > > > if (drm_dev->switch_power_state != DRM_SWITCH_POWER_ON) > > > return -EINVAL; > > > - ret = nvkm_therm_temp_get(therm); > > > - *val = ret < 0 ? ret : (ret * 1000); > > > + ret = nvkm_therm_temp_get(therm, ); > > > + *val = temp * 1000; > > > break; > > > case hwmon_temp_max: > > > *val = therm->attr_get(therm, > > > NVKM_THERM_ATTR_THRS_DOWN_CLK) > > > @@ -459,7 +459,7 @@ nouveau_temp_read(struct device *dev, u32 attr, int > > > channel, long *val) > > > return -EOPNOTSUPP; > > > } > > > > > > - return 0; > > > + return ret; > > > } > > > > > > static int > > > @@ -735,7 +735,7 @@ nouveau_hwmon_init(struct drm_device *dev) > > > hwmon->dev = dev; > > > > > > if (therm && therm->attr_get && therm->attr_set) { > > > - if (nvkm_therm_temp_get(therm) >= 0) > > > + if (nvkm_therm_temp_get(therm, NULL) >= 0) > > > special_groups[i++] = > > > _auto_point_sensor_group; > > > if (therm->fan_get && therm->fan_get(therm) >= 0) > > > special_groups[i++] = _fan_sensor_group; > > > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c > > > b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c > > > index 4a4d1e224126..e7ffea1512e6
Re: [Nouveau] [PATCH v2 1/2] drm/nouveau: return temperatures in temp_get() via parameter
On Wed, Sep 16, 2020 at 10:01 PM Karol Herbst wrote: > > On Wed, Sep 16, 2020 at 9:47 PM Jeremy Cline wrote: > > > > The temp_get() function currently returns negative error numbers or a > > temperature. However, the thermal sensors can (in theory) measure > > negative temperatures. Some implementations of temp_get() correctly > > clamp negative temperature readings to 0 so that users do not mistake > > them for errors, but some, like gp100_temp_get(), do not. > > > > Rather than relying on implementations remembering to clamp values, > > dedicate the function return value to error codes and accept a pointer > > to an integer where the temperature reading should be stored. > > > > Signed-off-by: Jeremy Cline > > --- > > .../drm/nouveau/include/nvkm/subdev/therm.h | 2 +- > > drivers/gpu/drm/nouveau/nouveau_hwmon.c | 12 ++-- > > .../gpu/drm/nouveau/nvkm/subdev/therm/base.c | 19 ++- > > .../gpu/drm/nouveau/nvkm/subdev/therm/g84.c | 11 ++- > > .../gpu/drm/nouveau/nvkm/subdev/therm/gp100.c | 11 ++- > > .../gpu/drm/nouveau/nvkm/subdev/therm/nv40.c | 9 +++-- > > .../gpu/drm/nouveau/nvkm/subdev/therm/nv50.c | 9 +++-- > > .../gpu/drm/nouveau/nvkm/subdev/therm/priv.h | 17 +++-- > > .../gpu/drm/nouveau/nvkm/subdev/therm/temp.c | 12 > > 9 files changed, 62 insertions(+), 40 deletions(-) > > > > diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > > b/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > > index 62c34f98c930..bfe9779216fc 100644 > > --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > > +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > > @@ -99,7 +99,7 @@ struct nvkm_therm { > > bool clkgating_enabled; > > }; > > > > -int nvkm_therm_temp_get(struct nvkm_therm *); > > +int nvkm_therm_temp_get(struct nvkm_therm *therm, int *temp); > > int nvkm_therm_fan_sense(struct nvkm_therm *); > > int nvkm_therm_cstate(struct nvkm_therm *, int, int); > > void nvkm_therm_clkgate_init(struct nvkm_therm *, > > diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c > > b/drivers/gpu/drm/nouveau/nouveau_hwmon.c > > index 1c3104d20571..aff6aa296678 100644 > > --- a/drivers/gpu/drm/nouveau/nouveau_hwmon.c > > +++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.c > > @@ -325,7 +325,7 @@ nouveau_temp_is_visible(const void *data, u32 attr, int > > channel) > > struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data); > > struct nvkm_therm *therm = nvxx_therm(>client.device); > > > > - if (!therm || !therm->attr_get || nvkm_therm_temp_get(therm) < 0) > > + if (!therm || !therm->attr_get || nvkm_therm_temp_get(therm, NULL) > > < 0) > > return 0; > > > > switch (attr) { > > @@ -419,7 +419,7 @@ nouveau_temp_read(struct device *dev, u32 attr, int > > channel, long *val) > > struct drm_device *drm_dev = dev_get_drvdata(dev); > > struct nouveau_drm *drm = nouveau_drm(drm_dev); > > struct nvkm_therm *therm = nvxx_therm(>client.device); > > - int ret; > > + int ret = 0, temp; > > > > if (!therm || !therm->attr_get) > > return -EOPNOTSUPP; > > @@ -428,8 +428,8 @@ nouveau_temp_read(struct device *dev, u32 attr, int > > channel, long *val) > > case hwmon_temp_input: > > if (drm_dev->switch_power_state != DRM_SWITCH_POWER_ON) > > return -EINVAL; > > - ret = nvkm_therm_temp_get(therm); > > - *val = ret < 0 ? ret : (ret * 1000); > > + ret = nvkm_therm_temp_get(therm, ); > > + *val = temp * 1000; > > break; > > case hwmon_temp_max: > > *val = therm->attr_get(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK) > > @@ -459,7 +459,7 @@ nouveau_temp_read(struct device *dev, u32 attr, int > > channel, long *val) > > return -EOPNOTSUPP; > > } > > > > - return 0; > > + return ret; > > } > > > > static int > > @@ -735,7 +735,7 @@ nouveau_hwmon_init(struct drm_device *dev) > > hwmon->dev = dev; > > > > if (therm && therm->attr_get && therm->attr_set) { > > - if (nvkm_therm_temp_get(therm) >= 0) > > + if (nvkm_therm_temp_get(therm, NULL) >= 0) > > special_groups[i++] = > > _auto_point_sensor_group; > > if (therm->fan_get && therm->fan_get(therm) >= 0) > > special_groups[i++] = _fan_sensor_group; > > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c > > b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c > > index 4a4d1e224126..e7ffea1512e6 100644 > > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c > > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c > > @@ -27,10 +27,15 @@ > > #include > > > > int > > -nvkm_therm_temp_get(struct nvkm_therm *therm) > > +nvkm_therm_temp_get(struct nvkm_therm
Re: [Nouveau] [PATCH v2 1/2] drm/nouveau: return temperatures in temp_get() via parameter
On Wed, Sep 16, 2020 at 9:47 PM Jeremy Cline wrote: > > The temp_get() function currently returns negative error numbers or a > temperature. However, the thermal sensors can (in theory) measure > negative temperatures. Some implementations of temp_get() correctly > clamp negative temperature readings to 0 so that users do not mistake > them for errors, but some, like gp100_temp_get(), do not. > > Rather than relying on implementations remembering to clamp values, > dedicate the function return value to error codes and accept a pointer > to an integer where the temperature reading should be stored. > > Signed-off-by: Jeremy Cline > --- > .../drm/nouveau/include/nvkm/subdev/therm.h | 2 +- > drivers/gpu/drm/nouveau/nouveau_hwmon.c | 12 ++-- > .../gpu/drm/nouveau/nvkm/subdev/therm/base.c | 19 ++- > .../gpu/drm/nouveau/nvkm/subdev/therm/g84.c | 11 ++- > .../gpu/drm/nouveau/nvkm/subdev/therm/gp100.c | 11 ++- > .../gpu/drm/nouveau/nvkm/subdev/therm/nv40.c | 9 +++-- > .../gpu/drm/nouveau/nvkm/subdev/therm/nv50.c | 9 +++-- > .../gpu/drm/nouveau/nvkm/subdev/therm/priv.h | 17 +++-- > .../gpu/drm/nouveau/nvkm/subdev/therm/temp.c | 12 > 9 files changed, 62 insertions(+), 40 deletions(-) > > diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > b/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > index 62c34f98c930..bfe9779216fc 100644 > --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h > @@ -99,7 +99,7 @@ struct nvkm_therm { > bool clkgating_enabled; > }; > > -int nvkm_therm_temp_get(struct nvkm_therm *); > +int nvkm_therm_temp_get(struct nvkm_therm *therm, int *temp); > int nvkm_therm_fan_sense(struct nvkm_therm *); > int nvkm_therm_cstate(struct nvkm_therm *, int, int); > void nvkm_therm_clkgate_init(struct nvkm_therm *, > diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c > b/drivers/gpu/drm/nouveau/nouveau_hwmon.c > index 1c3104d20571..aff6aa296678 100644 > --- a/drivers/gpu/drm/nouveau/nouveau_hwmon.c > +++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.c > @@ -325,7 +325,7 @@ nouveau_temp_is_visible(const void *data, u32 attr, int > channel) > struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data); > struct nvkm_therm *therm = nvxx_therm(>client.device); > > - if (!therm || !therm->attr_get || nvkm_therm_temp_get(therm) < 0) > + if (!therm || !therm->attr_get || nvkm_therm_temp_get(therm, NULL) < > 0) > return 0; > > switch (attr) { > @@ -419,7 +419,7 @@ nouveau_temp_read(struct device *dev, u32 attr, int > channel, long *val) > struct drm_device *drm_dev = dev_get_drvdata(dev); > struct nouveau_drm *drm = nouveau_drm(drm_dev); > struct nvkm_therm *therm = nvxx_therm(>client.device); > - int ret; > + int ret = 0, temp; > > if (!therm || !therm->attr_get) > return -EOPNOTSUPP; > @@ -428,8 +428,8 @@ nouveau_temp_read(struct device *dev, u32 attr, int > channel, long *val) > case hwmon_temp_input: > if (drm_dev->switch_power_state != DRM_SWITCH_POWER_ON) > return -EINVAL; > - ret = nvkm_therm_temp_get(therm); > - *val = ret < 0 ? ret : (ret * 1000); > + ret = nvkm_therm_temp_get(therm, ); > + *val = temp * 1000; > break; > case hwmon_temp_max: > *val = therm->attr_get(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK) > @@ -459,7 +459,7 @@ nouveau_temp_read(struct device *dev, u32 attr, int > channel, long *val) > return -EOPNOTSUPP; > } > > - return 0; > + return ret; > } > > static int > @@ -735,7 +735,7 @@ nouveau_hwmon_init(struct drm_device *dev) > hwmon->dev = dev; > > if (therm && therm->attr_get && therm->attr_set) { > - if (nvkm_therm_temp_get(therm) >= 0) > + if (nvkm_therm_temp_get(therm, NULL) >= 0) > special_groups[i++] = _auto_point_sensor_group; > if (therm->fan_get && therm->fan_get(therm) >= 0) > special_groups[i++] = _fan_sensor_group; > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c > b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c > index 4a4d1e224126..e7ffea1512e6 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c > @@ -27,10 +27,15 @@ > #include > > int > -nvkm_therm_temp_get(struct nvkm_therm *therm) > +nvkm_therm_temp_get(struct nvkm_therm *therm, int *temp) > { > + int ignored_reading; > + > + if (temp == NULL) > + temp = _reading; > + > if (therm->func->temp_get) > - return therm->func->temp_get(therm); > + return therm->func->temp_get(therm, temp);
[Nouveau] [PATCH v2 1/2] drm/nouveau: return temperatures in temp_get() via parameter
The temp_get() function currently returns negative error numbers or a temperature. However, the thermal sensors can (in theory) measure negative temperatures. Some implementations of temp_get() correctly clamp negative temperature readings to 0 so that users do not mistake them for errors, but some, like gp100_temp_get(), do not. Rather than relying on implementations remembering to clamp values, dedicate the function return value to error codes and accept a pointer to an integer where the temperature reading should be stored. Signed-off-by: Jeremy Cline --- .../drm/nouveau/include/nvkm/subdev/therm.h | 2 +- drivers/gpu/drm/nouveau/nouveau_hwmon.c | 12 ++-- .../gpu/drm/nouveau/nvkm/subdev/therm/base.c | 19 ++- .../gpu/drm/nouveau/nvkm/subdev/therm/g84.c | 11 ++- .../gpu/drm/nouveau/nvkm/subdev/therm/gp100.c | 11 ++- .../gpu/drm/nouveau/nvkm/subdev/therm/nv40.c | 9 +++-- .../gpu/drm/nouveau/nvkm/subdev/therm/nv50.c | 9 +++-- .../gpu/drm/nouveau/nvkm/subdev/therm/priv.h | 17 +++-- .../gpu/drm/nouveau/nvkm/subdev/therm/temp.c | 12 9 files changed, 62 insertions(+), 40 deletions(-) diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h b/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h index 62c34f98c930..bfe9779216fc 100644 --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h @@ -99,7 +99,7 @@ struct nvkm_therm { bool clkgating_enabled; }; -int nvkm_therm_temp_get(struct nvkm_therm *); +int nvkm_therm_temp_get(struct nvkm_therm *therm, int *temp); int nvkm_therm_fan_sense(struct nvkm_therm *); int nvkm_therm_cstate(struct nvkm_therm *, int, int); void nvkm_therm_clkgate_init(struct nvkm_therm *, diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c b/drivers/gpu/drm/nouveau/nouveau_hwmon.c index 1c3104d20571..aff6aa296678 100644 --- a/drivers/gpu/drm/nouveau/nouveau_hwmon.c +++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.c @@ -325,7 +325,7 @@ nouveau_temp_is_visible(const void *data, u32 attr, int channel) struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data); struct nvkm_therm *therm = nvxx_therm(>client.device); - if (!therm || !therm->attr_get || nvkm_therm_temp_get(therm) < 0) + if (!therm || !therm->attr_get || nvkm_therm_temp_get(therm, NULL) < 0) return 0; switch (attr) { @@ -419,7 +419,7 @@ nouveau_temp_read(struct device *dev, u32 attr, int channel, long *val) struct drm_device *drm_dev = dev_get_drvdata(dev); struct nouveau_drm *drm = nouveau_drm(drm_dev); struct nvkm_therm *therm = nvxx_therm(>client.device); - int ret; + int ret = 0, temp; if (!therm || !therm->attr_get) return -EOPNOTSUPP; @@ -428,8 +428,8 @@ nouveau_temp_read(struct device *dev, u32 attr, int channel, long *val) case hwmon_temp_input: if (drm_dev->switch_power_state != DRM_SWITCH_POWER_ON) return -EINVAL; - ret = nvkm_therm_temp_get(therm); - *val = ret < 0 ? ret : (ret * 1000); + ret = nvkm_therm_temp_get(therm, ); + *val = temp * 1000; break; case hwmon_temp_max: *val = therm->attr_get(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK) @@ -459,7 +459,7 @@ nouveau_temp_read(struct device *dev, u32 attr, int channel, long *val) return -EOPNOTSUPP; } - return 0; + return ret; } static int @@ -735,7 +735,7 @@ nouveau_hwmon_init(struct drm_device *dev) hwmon->dev = dev; if (therm && therm->attr_get && therm->attr_set) { - if (nvkm_therm_temp_get(therm) >= 0) + if (nvkm_therm_temp_get(therm, NULL) >= 0) special_groups[i++] = _auto_point_sensor_group; if (therm->fan_get && therm->fan_get(therm) >= 0) special_groups[i++] = _fan_sensor_group; diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c index 4a4d1e224126..e7ffea1512e6 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c @@ -27,10 +27,15 @@ #include int -nvkm_therm_temp_get(struct nvkm_therm *therm) +nvkm_therm_temp_get(struct nvkm_therm *therm, int *temp) { + int ignored_reading; + + if (temp == NULL) + temp = _reading; + if (therm->func->temp_get) - return therm->func->temp_get(therm); + return therm->func->temp_get(therm, temp); return -ENODEV; } @@ -40,9 +45,11 @@ nvkm_therm_update_trip(struct nvkm_therm *therm) struct nvbios_therm_trip_point *trip = therm->fan->bios.trip, *cur_trip = NULL,