Re: [PATCH] drm/nouveau: Add support for clockgating on Fermi+
From: Lyude Paul
Date: Wed Apr 26 2017 - 14:31:30 EST
On Wed, 2017-04-26 at 00:49 +0200, Karol Herbst wrote:
> Hi Lyude,
>
> thanks for the great work. Just a view comments inline.
>
> 2017-04-25 20:38 GMT+02:00 Lyude <lyude@xxxxxxxxxx>:
> > This adds support for enabling automatic clockgating on nvidia GPUs
> > for
> > Fermi and later generations. This saves a little bit of power,
> > bringing
> > my fermi GPU's power consumption from ~28.3W on idle to ~27W, and
> > my
> > kepler's idle power consumption from ~23.6W to ~21.65W.
> >
> > Similar to how the nvidia driver seems to handle this, we enable
> > clockgating for each engine that supports it after it's
> > initialization.
> >
> > Signed-off-by: Lyude <lyude@xxxxxxxxxx>
> > ---
> > Â.../gpu/drm/nouveau/include/nvkm/subdev/therm.hÂÂÂÂ|ÂÂ4 ++
> > Âdrivers/gpu/drm/nouveau/nvkm/core/engine.cÂÂÂÂÂÂÂÂÂ| 20 +++++-
> > Âdrivers/gpu/drm/nouveau/nvkm/engine/device/base.cÂÂ| 14 ++--
> > Âdrivers/gpu/drm/nouveau/nvkm/subdev/therm/KbuildÂÂÂ|ÂÂ2 +
> > Âdrivers/gpu/drm/nouveau/nvkm/subdev/therm/base.cÂÂÂ|ÂÂ2 +
> > Â.../gpu/drm/nouveau/nvkm/subdev/therm/clkgate.cÂÂÂÂ| 49
> > ++++++++++++++
> > Âdrivers/gpu/drm/nouveau/nvkm/subdev/therm/gf100.cÂÂ| 77
> > ++++++++++++++++++++++
> > Âdrivers/gpu/drm/nouveau/nvkm/subdev/therm/gf119.cÂÂ|ÂÂ2 +
> > Âdrivers/gpu/drm/nouveau/nvkm/subdev/therm/gm107.cÂÂ|ÂÂ2 +
> > Âdrivers/gpu/drm/nouveau/nvkm/subdev/therm/gt215.cÂÂ|ÂÂ2 +-
> > Âdrivers/gpu/drm/nouveau/nvkm/subdev/therm/priv.hÂÂÂ| 10 +++
> > Â11 files changed, 175 insertions(+), 9 deletions(-)
> > Âcreate mode 100644
> > drivers/gpu/drm/nouveau/nvkm/subdev/therm/clkgate.c
> > Âcreate mode 100644
> > drivers/gpu/drm/nouveau/nvkm/subdev/therm/gf100.c
> >
> > diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h
> > b/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h
> > index b268b96..904aa56 100644
> > --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h
> > +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h
> > @@ -84,6 +84,9 @@ struct nvkm_therm {
> >
> > ÂÂÂÂÂÂÂÂint (*attr_get)(struct nvkm_therm *, enum
> > nvkm_therm_attr_type);
> > ÂÂÂÂÂÂÂÂint (*attr_set)(struct nvkm_therm *, enum
> > nvkm_therm_attr_type, int);
> > +
> > +ÂÂÂÂÂÂÂintÂÂ(*clkgate_engine)(struct nvkm_therm *, enum
> > nvkm_devidx);
> > +ÂÂÂÂÂÂÂvoid (*clkgate_set)(struct nvkm_therm *, int gate_idx, bool
> > enable);
>
> remove those and have a simple "nvkm_therm_clkgate_engine" function
>
> This way you know that every user calls this function and don't have
> to check for silly function pointers like you currently do in
> engine.c
>
> > Â};
> >
> > Âint nvkm_therm_temp_get(struct nvkm_therm *);
> > @@ -94,6 +97,7 @@ int nv40_therm_new(struct nvkm_device *, int,
> > struct nvkm_therm **);
> > Âint nv50_therm_new(struct nvkm_device *, int, struct nvkm_therm
> > **);
> > Âint g84_therm_new(struct nvkm_device *, int, struct nvkm_therm
> > **);
> > Âint gt215_therm_new(struct nvkm_device *, int, struct nvkm_therm
> > **);
> > +int gf100_therm_new(struct nvkm_device *, int, struct nvkm_therm
> > **);
> > Âint gf119_therm_new(struct nvkm_device *, int, struct nvkm_therm
> > **);
> > Âint gm107_therm_new(struct nvkm_device *, int, struct nvkm_therm
> > **);
> > Â#endif
> > diff --git a/drivers/gpu/drm/nouveau/nvkm/core/engine.c
> > b/drivers/gpu/drm/nouveau/nvkm/core/engine.c
> > index b6c9169..473ad3e 100644
> > --- a/drivers/gpu/drm/nouveau/nvkm/core/engine.c
> > +++ b/drivers/gpu/drm/nouveau/nvkm/core/engine.c
> > @@ -26,6 +26,7 @@
> > Â#include <core/option.h>
> >
> > Â#include <subdev/fb.h>
> > +#include <subdev/therm.h>
> >
> > Âbool
> > Ânvkm_engine_chsw_load(struct nvkm_engine *engine)
> > @@ -86,6 +87,13 @@ static int
> > Ânvkm_engine_fini(struct nvkm_subdev *subdev, bool suspend)
> > Â{
> > ÂÂÂÂÂÂÂÂstruct nvkm_engine *engine = nvkm_engine(subdev);
> > +ÂÂÂÂÂÂÂstruct nvkm_therm *therm = subdev->device->therm;
> > +ÂÂÂÂÂÂÂint gate_idx;
> > +
> > +ÂÂÂÂÂÂÂgate_idx = therm->clkgate_engine(therm, subdev->index);
> > +ÂÂÂÂÂÂÂif (gate_idx != -1)
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂtherm->clkgate_set(therm, gate_idx, false);
> > +
>
> move this code inside "nvkm_therm_clkgate_engine". Nobody outside
> nvkm_therm should even care about the index.
>
> > ÂÂÂÂÂÂÂÂif (engine->func->fini)
> > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreturn engine->func->fini(engine, suspend);
> > ÂÂÂÂÂÂÂÂreturn 0;
> > @@ -96,12 +104,13 @@ nvkm_engine_init(struct nvkm_subdev *subdev)
> > Â{
> > ÂÂÂÂÂÂÂÂstruct nvkm_engine *engine = nvkm_engine(subdev);
> > ÂÂÂÂÂÂÂÂstruct nvkm_fb *fb = subdev->device->fb;
> > +ÂÂÂÂÂÂÂstruct nvkm_therm *therm = subdev->device->therm;
> > ÂÂÂÂÂÂÂÂint ret = 0, i;
> > ÂÂÂÂÂÂÂÂs64 time;
> >
> > ÂÂÂÂÂÂÂÂif (!engine->usecount) {
> > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂnvkm_trace(subdev, "init skipped, engine has no
> > users\n");
> > -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreturn ret;
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂgoto finish;
> > ÂÂÂÂÂÂÂÂ}
> >
> > ÂÂÂÂÂÂÂÂif (engine->func->oneinit && !engine->subdev.oneinit) {
> > @@ -123,6 +132,15 @@ nvkm_engine_init(struct nvkm_subdev *subdev)
> >
> > ÂÂÂÂÂÂÂÂfor (i = 0; fb && i < fb->tile.regions; i++)
> > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂnvkm_engine_tile(engine, i);
> > +
> > +finish:
> > +ÂÂÂÂÂÂÂif (!ret) {
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂint gate_idx = therm->clkgate_engine(therm, subdev-
> > >index);
> > +
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂif (gate_idx != -1)
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂtherm->clkgate_set(therm, gate_idx, true);
> > +ÂÂÂÂÂÂÂ}
> > +
>
> same code as above. More code sharing!
>
> > ÂÂÂÂÂÂÂÂreturn ret;
> > Â}
> >
> > diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/device/base.c
> > b/drivers/gpu/drm/nouveau/nvkm/engine/device/base.c
> > index b690bc1..d133016 100644
> > --- a/drivers/gpu/drm/nouveau/nvkm/engine/device/base.c
> > +++ b/drivers/gpu/drm/nouveau/nvkm/engine/device/base.c
> > @@ -1355,7 +1355,7 @@ nvc0_chipset = {
> > ÂÂÂÂÂÂÂÂ.mxm = nv50_mxm_new,
> > ÂÂÂÂÂÂÂÂ.pci = gf100_pci_new,
> > ÂÂÂÂÂÂÂÂ.pmu = gf100_pmu_new,
> > -ÂÂÂÂÂÂÂ.therm = gt215_therm_new,
> > +ÂÂÂÂÂÂÂ.therm = gf100_therm_new,
> > ÂÂÂÂÂÂÂÂ.timer = nv41_timer_new,
> > ÂÂÂÂÂÂÂÂ.volt = gf100_volt_new,
> > ÂÂÂÂÂÂÂÂ.ce[0] = gf100_ce_new,
> > @@ -1392,7 +1392,7 @@ nvc1_chipset = {
> > ÂÂÂÂÂÂÂÂ.mxm = nv50_mxm_new,
> > ÂÂÂÂÂÂÂÂ.pci = gf106_pci_new,
> > ÂÂÂÂÂÂÂÂ.pmu = gf100_pmu_new,
> > -ÂÂÂÂÂÂÂ.therm = gt215_therm_new,
> > +ÂÂÂÂÂÂÂ.therm = gf100_therm_new,
> > ÂÂÂÂÂÂÂÂ.timer = nv41_timer_new,
> > ÂÂÂÂÂÂÂÂ.volt = gf100_volt_new,
> > ÂÂÂÂÂÂÂÂ.ce[0] = gf100_ce_new,
> > @@ -1428,7 +1428,7 @@ nvc3_chipset = {
> > ÂÂÂÂÂÂÂÂ.mxm = nv50_mxm_new,
> > ÂÂÂÂÂÂÂÂ.pci = gf106_pci_new,
> > ÂÂÂÂÂÂÂÂ.pmu = gf100_pmu_new,
> > -ÂÂÂÂÂÂÂ.therm = gt215_therm_new,
> > +ÂÂÂÂÂÂÂ.therm = gf100_therm_new,
> > ÂÂÂÂÂÂÂÂ.timer = nv41_timer_new,
> > ÂÂÂÂÂÂÂÂ.volt = gf100_volt_new,
> > ÂÂÂÂÂÂÂÂ.ce[0] = gf100_ce_new,
> > @@ -1464,7 +1464,7 @@ nvc4_chipset = {
> > ÂÂÂÂÂÂÂÂ.mxm = nv50_mxm_new,
> > ÂÂÂÂÂÂÂÂ.pci = gf100_pci_new,
> > ÂÂÂÂÂÂÂÂ.pmu = gf100_pmu_new,
> > -ÂÂÂÂÂÂÂ.therm = gt215_therm_new,
> > +ÂÂÂÂÂÂÂ.therm = gf100_therm_new,
> > ÂÂÂÂÂÂÂÂ.timer = nv41_timer_new,
> > ÂÂÂÂÂÂÂÂ.volt = gf100_volt_new,
> > ÂÂÂÂÂÂÂÂ.ce[0] = gf100_ce_new,
> > @@ -1501,7 +1501,7 @@ nvc8_chipset = {
> > ÂÂÂÂÂÂÂÂ.mxm = nv50_mxm_new,
> > ÂÂÂÂÂÂÂÂ.pci = gf100_pci_new,
> > ÂÂÂÂÂÂÂÂ.pmu = gf100_pmu_new,
> > -ÂÂÂÂÂÂÂ.therm = gt215_therm_new,
> > +ÂÂÂÂÂÂÂ.therm = gf100_therm_new,
> > ÂÂÂÂÂÂÂÂ.timer = nv41_timer_new,
> > ÂÂÂÂÂÂÂÂ.volt = gf100_volt_new,
> > ÂÂÂÂÂÂÂÂ.ce[0] = gf100_ce_new,
> > @@ -1538,7 +1538,7 @@ nvce_chipset = {
> > ÂÂÂÂÂÂÂÂ.mxm = nv50_mxm_new,
> > ÂÂÂÂÂÂÂÂ.pci = gf100_pci_new,
> > ÂÂÂÂÂÂÂÂ.pmu = gf100_pmu_new,
> > -ÂÂÂÂÂÂÂ.therm = gt215_therm_new,
> > +ÂÂÂÂÂÂÂ.therm = gf100_therm_new,
> > ÂÂÂÂÂÂÂÂ.timer = nv41_timer_new,
> > ÂÂÂÂÂÂÂÂ.volt = gf100_volt_new,
> > ÂÂÂÂÂÂÂÂ.ce[0] = gf100_ce_new,
> > @@ -1575,7 +1575,7 @@ nvcf_chipset = {
> > ÂÂÂÂÂÂÂÂ.mxm = nv50_mxm_new,
> > ÂÂÂÂÂÂÂÂ.pci = gf106_pci_new,
> > ÂÂÂÂÂÂÂÂ.pmu = gf100_pmu_new,
> > -ÂÂÂÂÂÂÂ.therm = gt215_therm_new,
> > +ÂÂÂÂÂÂÂ.therm = gf100_therm_new,
> > ÂÂÂÂÂÂÂÂ.timer = nv41_timer_new,
> > ÂÂÂÂÂÂÂÂ.volt = gf100_volt_new,
> > ÂÂÂÂÂÂÂÂ.ce[0] = gf100_ce_new,
> > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/Kbuild
> > b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/Kbuild
> > index 135758b..cbb9465 100644
> > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/Kbuild
> > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/Kbuild
> > @@ -1,4 +1,5 @@
> > Ânvkm-y += nvkm/subdev/therm/base.o
> > +nvkm-y += nvkm/subdev/therm/clkgate.o
> > Ânvkm-y += nvkm/subdev/therm/fan.o
> > Ânvkm-y += nvkm/subdev/therm/fannil.o
> > Ânvkm-y += nvkm/subdev/therm/fanpwm.o
> > @@ -9,5 +10,6 @@ nvkm-y += nvkm/subdev/therm/nv40.o
> > Ânvkm-y += nvkm/subdev/therm/nv50.o
> > Ânvkm-y += nvkm/subdev/therm/g84.o
> > Ânvkm-y += nvkm/subdev/therm/gt215.o
> > +nvkm-y += nvkm/subdev/therm/gf100.o
> > Ânvkm-y += nvkm/subdev/therm/gf119.o
> > Ânvkm-y += nvkm/subdev/therm/gm107.o
> > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c
> > b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c
> > index df949fa..723c0c1 100644
> > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c
> > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c
> > @@ -393,6 +393,8 @@ nvkm_therm_new_(const struct nvkm_therm_func
> > *func, struct nvkm_device *device,
> > ÂÂÂÂÂÂÂÂtherm->fan_set = nvkm_therm_fan_user_set;
> > ÂÂÂÂÂÂÂÂtherm->attr_get = nvkm_therm_attr_get;
> > ÂÂÂÂÂÂÂÂtherm->attr_set = nvkm_therm_attr_set;
> > +ÂÂÂÂÂÂÂtherm->clkgate_engine = nvkm_therm_clkgate_engine;
> > +ÂÂÂÂÂÂÂtherm->clkgate_set = nvkm_therm_clkgate_set;
>
> remove those, because we should only have a nvkm_therm_clkgate_engine
> call
>
> > ÂÂÂÂÂÂÂÂtherm->mode = therm->suspend = -1; /* undefined */
> > ÂÂÂÂÂÂÂÂreturn 0;
> > Â}
> > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/clkgate.c
> > b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/clkgate.c
> > new file mode 100644
> > index 0000000..c030ea9
> > --- /dev/null
> > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/clkgate.c
> > @@ -0,0 +1,49 @@
> > +/*
> > + * Copyright 2017 Red Hat Inc.
> > + *
> > + * Permission is hereby granted, free of charge, to any person
> > obtaining a
> > + * copy of this software and associated documentation files (the
> > "Software"),
> > + * to deal in the Software without restriction, including without
> > limitation
> > + * the rights to use, copy, modify, merge, publish, distribute,
> > sublicense,
> > + * and/or sell copies of the Software, and to permit persons to
> > whom the
> > + * Software is furnished to do so, subject to the following
> > conditions:
> > + *
> > + * The above copyright notice and this permission notice shall be
> > included in
> > + * all copies or substantial portions of the Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> > EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> > MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.ÂÂIN NO
> > EVENT SHALL
> > + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM,
> > DAMAGES OR
> > + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
> > OTHERWISE,
> > + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
> > USE OR
> > + * OTHER DEALINGS IN THE SOFTWARE.
> > + *
> > + * Authors: Lyude Paul
> > + */
> > +#include "priv.h"
> > +
> > +int
> > +nvkm_therm_clkgate_engine(struct nvkm_therm *therm, enum
> > nvkm_devidx subdev)
> > +{
> > +ÂÂÂÂÂÂÂif (!therm->func->clkgate_engine)
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreturn -1;
> > +
> > +ÂÂÂÂÂÂÂreturn therm->func->clkgate_engine(subdev);
> > +}
> > +
> > +void
> > +nvkm_therm_clkgate_set(struct nvkm_therm *therm, int gate_idx,
> > bool enable)
> > +{
> > +ÂÂÂÂÂÂÂif (!therm->func->clkgate_set)
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreturn;
> > +
> > +ÂÂÂÂÂÂÂif (enable)
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂnvkm_trace(&therm->subdev,
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"Enabling clockgating for gate 0x%x\n",
> > gate_idx);
> > +ÂÂÂÂÂÂÂelse
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂnvkm_trace(&therm->subdev,
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"Disabling clockgating for gate 0x%x\n",
> > gate_idx);
> > +
> > +ÂÂÂÂÂÂÂtherm->func->clkgate_set(therm, gate_idx, enable);
> > +}
> > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gf100.c
> > b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gf100.c
> > new file mode 100644
> > index 0000000..820934f
> > --- /dev/null
> > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gf100.c
> > @@ -0,0 +1,77 @@
> > +/*
> > + * Copyright 2017 Red Hat Inc.
> > + *
> > + * Permission is hereby granted, free of charge, to any person
> > obtaining a
> > + * copy of this software and associated documentation files (the
> > "Software"),
> > + * to deal in the Software without restriction, including without
> > limitation
> > + * the rights to use, copy, modify, merge, publish, distribute,
> > sublicense,
> > + * and/or sell copies of the Software, and to permit persons to
> > whom the
> > + * Software is furnished to do so, subject to the following
> > conditions:
> > + *
> > + * The above copyright notice and this permission notice shall be
> > included in
> > + * all copies or substantial portions of the Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> > EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> > MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.ÂÂIN NO
> > EVENT SHALL
> > + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM,
> > DAMAGES OR
> > + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
> > OTHERWISE,
> > + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
> > USE OR
> > + * OTHER DEALINGS IN THE SOFTWARE.
> > + *
> > + * Authors: Lyude Paul
> > + */
> > +#include <core/device.h>
> > +
> > +#include "priv.h"
> > +
> > +int
> > +gf100_clkgate_engine(enum nvkm_devidx subdev)
> > +{
> > +ÂÂÂÂÂÂÂswitch (subdev) {
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂcase NVKM_ENGINE_GR:ÂÂÂÂÂreturn 0x00;
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂcase NVKM_ENGINE_MSPDEC: return 0x04;
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂcase NVKM_ENGINE_MSPPP:ÂÂreturn 0x08;
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂcase NVKM_ENGINE_MSVLD:ÂÂreturn 0x0c;
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂcase NVKM_ENGINE_CE0:ÂÂÂÂreturn 0x10;
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂcase NVKM_ENGINE_CE1:ÂÂÂÂreturn 0x14;
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂcase NVKM_ENGINE_MSENC:ÂÂreturn 0x18;
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂcase NVKM_ENGINE_CE2:ÂÂÂÂreturn 0x1c;
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂdefault:ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreturn -1;
> > +ÂÂÂÂÂÂÂ}
> > +}
> > +
> > +void
> > +gf100_clkgate_set(struct nvkm_therm *therm, int gate_idx, bool
> > enable)
> > +{
> > +ÂÂÂÂÂÂÂu8 data;
> > +
> > +ÂÂÂÂÂÂÂif (enable) /* ENG_CLK=auto, BLK_CLK=auto, ENG_PWR=run,
> > BLK_PWR=auto */
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂdata = 0x45;
> > +ÂÂÂÂÂÂÂelseÂÂÂÂÂÂÂÂ/* ENG_CLK=run, BLK_CLK=run, ENG_PWR=run,
> > BLK_PWR=run */
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂdata = 0x0;
>
> I would rather use 0x44 here as Nvidia does? I don't think they
> disable it completly, maybe they only leave it on kepler? not quite
> sure.
JFYI: according to the vbios repo the nvidia blob actually uses 0x45
for everything except for PTHERM.UNK254_CG_CTRL:
./nv136/<REDACTED>/gp106_mmiotrace.xz: [1] 854.334687 MMIO32 W 0x020200 0x2772ed45 PTHERM.PGRAPH_CG_CTRL <= { ENG_CLK = AUTO | BLK_CLK = AUTO | ENG_PWR = RUN | BLK_PWR = AUTO | ENG_FILTER = 0xd | ENG_MANT = 0x7 | ENG_DLY_BEFORE = 0x2 | ENG_DLY_AFTER = 0x7 | BLK_DLY_BEFORE = 0x7 | BLK_DLY_AFTER = 0x2 }
vs
./nv136/<REDACTED>/gp106_mmiotrace.xz: [1] 854.251848 MMIO32 W 0x020254 0x27722444 PTHERM.UNK254_CG_CTRL <= { ENG_CLK = RUN | BLK_CLK = AUTO | ENG_PWR = RUN | BLK_PWR = AUTO | ENG_FILTER = 0x4 | ENG_MANT = 0x1 | ENG_DLY_BEFORE = 0x2 | ENG_DLY_AFTER = 0x7 | BLK_DLY_BEFORE = 0x7 | BLK_DLY_AFTER = 0x2 }
>
> > +
> > +ÂÂÂÂÂÂÂnvkm_mask(therm->subdev.device, 0x20200 + gate_idx, 0xff,
> > data);
> > +}
> > +
> > +static const struct nvkm_therm_func
> > +gf100_therm = {
> > +ÂÂÂÂÂÂÂ.init = gt215_therm_init,
> > +ÂÂÂÂÂÂÂ.fini = g84_therm_fini,
> > +ÂÂÂÂÂÂÂ.pwm_ctrl = nv50_fan_pwm_ctrl,
> > +ÂÂÂÂÂÂÂ.pwm_get = nv50_fan_pwm_get,
> > +ÂÂÂÂÂÂÂ.pwm_set = nv50_fan_pwm_set,
> > +ÂÂÂÂÂÂÂ.pwm_clock = nv50_fan_pwm_clock,
> > +ÂÂÂÂÂÂÂ.temp_get = g84_temp_get,
> > +ÂÂÂÂÂÂÂ.fan_sense = gt215_therm_fan_sense,
> > +ÂÂÂÂÂÂÂ.program_alarms = nvkm_therm_program_alarms_polling,
> > +ÂÂÂÂÂÂÂ.clkgate_engine = gf100_clkgate_engine,
> > +ÂÂÂÂÂÂÂ.clkgate_set = gf100_clkgate_set,
> > +};
> > +
> > +int
> > +gf100_therm_new(struct nvkm_device *device, int index,
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂstruct nvkm_therm **ptherm)
> > +{
> > +ÂÂÂÂÂÂÂreturn nvkm_therm_new_(&gf100_therm, device, index,
> > ptherm);
> > +}
> > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gf119.c
> > b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gf119.c
> > index 06dcfd6..a2626fb 100644
> > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gf119.c
> > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gf119.c
> > @@ -143,6 +143,8 @@ gf119_therm = {
> > ÂÂÂÂÂÂÂÂ.temp_get = g84_temp_get,
> > ÂÂÂÂÂÂÂÂ.fan_sense = gt215_therm_fan_sense,
> > ÂÂÂÂÂÂÂÂ.program_alarms = nvkm_therm_program_alarms_polling,
> > +ÂÂÂÂÂÂÂ.clkgate_engine = gf100_clkgate_engine,
> > +ÂÂÂÂÂÂÂ.clkgate_set = gf100_clkgate_set,
> > Â};
> >
> > Âint
> > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gm107.c
> > b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gm107.c
> > index 86848ec..c580c39 100644
> > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gm107.c
> > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gm107.c
> > @@ -65,6 +65,8 @@ gm107_therm = {
> > ÂÂÂÂÂÂÂÂ.temp_get = g84_temp_get,
> > ÂÂÂÂÂÂÂÂ.fan_sense = gt215_therm_fan_sense,
> > ÂÂÂÂÂÂÂÂ.program_alarms = nvkm_therm_program_alarms_polling,
> > +ÂÂÂÂÂÂÂ.clkgate_engine = gf100_clkgate_engine,
> > +ÂÂÂÂÂÂÂ.clkgate_set = gf100_clkgate_set,
> > Â};
> >
> > Âint
> > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gt215.c
> > b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gt215.c
> > index c08097f..4caf401 100644
> > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gt215.c
> > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gt215.c
> > @@ -36,7 +36,7 @@ gt215_therm_fan_sense(struct nvkm_therm *therm)
> > ÂÂÂÂÂÂÂÂreturn -ENODEV;
> > Â}
> >
> > -static void
> > +void
> > Âgt215_therm_init(struct nvkm_therm *therm)
> > Â{
> > ÂÂÂÂÂÂÂÂstruct nvkm_device *device = therm->subdev.device;
> > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/priv.h
> > b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/priv.h
> > index 235a5d8..80367a7 100644
> > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/priv.h
> > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/priv.h
> > @@ -81,6 +81,9 @@ void nvkm_therm_sensor_event(struct nvkm_therm *,
> > enum nvkm_therm_thrs,
> > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂenum nvkm_therm_thrs_direction);
> > Âvoid nvkm_therm_program_alarms_polling(struct nvkm_therm *);
> >
> > +intÂÂnvkm_therm_clkgate_engine(struct nvkm_therm *, enum
> > nvkm_devidx);
> > +void nvkm_therm_clkgate_set(struct nvkm_therm *, int gate_idx,
> > bool enable);
> > +
> > Âstruct nvkm_therm_func {
> > ÂÂÂÂÂÂÂÂvoid (*init)(struct nvkm_therm *);
> > ÂÂÂÂÂÂÂÂvoid (*fini)(struct nvkm_therm *);
> > @@ -96,6 +99,9 @@ struct nvkm_therm_func {
> > ÂÂÂÂÂÂÂÂint (*fan_sense)(struct nvkm_therm *);
> >
> > ÂÂÂÂÂÂÂÂvoid (*program_alarms)(struct nvkm_therm *);
> > +
> > +ÂÂÂÂÂÂÂint (*clkgate_engine)(enum nvkm_devidx);
> > +ÂÂÂÂÂÂÂvoid (*clkgate_set)(struct nvkm_therm *, int, bool);
> > Â};
> >
> > Âvoid nv40_therm_intr(struct nvkm_therm *);
> > @@ -110,6 +116,10 @@ void g84_sensor_setup(struct nvkm_therm *);
> > Âvoid g84_therm_fini(struct nvkm_therm *);
> >
> > Âint gt215_therm_fan_sense(struct nvkm_therm *);
> > +void gt215_therm_init(struct nvkm_therm *);
> > +
> > +intÂÂgf100_clkgate_engine(enum nvkm_devidx);
> > +void gf100_clkgate_set(struct nvkm_therm *, int, bool);
> >
> > Âvoid gf119_therm_init(struct nvkm_therm *);
> >
> > --
> > 2.9.3
> >
--
Cheers,
Lyude