On Sat, Jul 22, 2017 at 2:23 AM, Ilia Mirkin <imir...@alum.mit.edu> wrote:
> On Fri, Jul 21, 2017 at 5:55 PM, Karol Herbst <karolher...@gmail.com> wrote:
>> Signed-off-by: Karol Herbst <karolher...@gmail.com>
>> ---
>>  drm/nouveau/include/nvkm/subdev/clk.h |  2 ++
>>  drm/nouveau/nvkm/subdev/clk/base.c    | 42 
>> +++++++++++++++++++++++++++++++++++
>>  2 files changed, 44 insertions(+)
>>
>> diff --git a/drm/nouveau/include/nvkm/subdev/clk.h 
>> b/drm/nouveau/include/nvkm/subdev/clk.h
>> index f35518c3..f5ff1fd9 100644
>> --- a/drm/nouveau/include/nvkm/subdev/clk.h
>> +++ b/drm/nouveau/include/nvkm/subdev/clk.h
>> @@ -104,6 +104,8 @@ struct nvkm_clk {
>>         struct nvkm_cstate *cstate;
>>         int exp_cstateid;
>>         u8  temp;
>> +       u8  max_temp;
>> +       u8  relax_temp;
>>
>>         bool allow_reclock;
>>  #define NVKM_CLK_BOOST_NONE 0x0
>> diff --git a/drm/nouveau/nvkm/subdev/clk/base.c 
>> b/drm/nouveau/nvkm/subdev/clk/base.c
>> index 81093e13..60edb57b 100644
>> --- a/drm/nouveau/nvkm/subdev/clk/base.c
>> +++ b/drm/nouveau/nvkm/subdev/clk/base.c
>> @@ -27,6 +27,7 @@
>>  #include <subdev/bios/boost.h>
>>  #include <subdev/bios/cstep.h>
>>  #include <subdev/bios/perf.h>
>> +#include <subdev/bios/thermal_policies.h>
>>  #include <subdev/bios/vpstate.h>
>>  #include <subdev/fb.h>
>>  #include <subdev/therm.h>
>> @@ -669,6 +670,44 @@ nvkm_clk = {
>>         .fini = nvkm_clk_fini,
>>  };
>>
>> +static void
>> +nvkm_clk_parse_max_temp(struct nvkm_clk *clk)
>> +{
>> +       struct nvkm_subdev *subdev = &clk->subdev;
>> +       struct nvkm_bios *bios = subdev->device->bios;
>> +       struct nvbios_thermal_policies_header header;
>> +       struct nvbios_thermal_policies_entry entry;
>> +       u8 i;
>> +       s16 mt = 0xff;
>> +       s16 rt = 0xff;
>> +
>> +       if (nvbios_thermal_policies_parse(bios, &header))
>> +               return;
>> +
>> +       if (!header.ecount)
>> +               return;
>> +
>> +       for (i = 0; i < header.ecount; i++) {
>> +               if (nvbios_thermal_policies_entry(bios, &header, i, &entry))
>> +                       return;
>> +
>> +               if (entry.mode != 1)
>> +                       continue;
>> +
>> +               mt = min(mt, (s16)((entry.t0 + entry.down_offset) / 32));
>> +               rt = min(rt, (s16)((entry.t0 + entry.up_offset) / 32));
>
> I believe you're looking for
>
> min_t(s16, rt, foo)
>

okay thanks, this looks at least a little better

>> +       }
>> +
>> +       if (mt == 0xff || rt == 0xff)
>> +               return;
>> +
>> +       clk->max_temp = mt;
>> +       clk->relax_temp = rt;
>> +
>> +       nvkm_debug(subdev, "setting up sw throttling thresholds (%u/%u°C)\n",
>> +                  clk->max_temp, clk->relax_temp);
>> +}
>> +
>>  int
>>  nvkm_clk_ctor(const struct nvkm_clk_func *func, struct nvkm_device *device,
>>               int index, bool allow_reclock, struct nvkm_clk *clk)
>> @@ -743,6 +782,9 @@ nvkm_clk_ctor(const struct nvkm_clk_func *func, struct 
>> nvkm_device *device,
>>
>>         clk->boost_mode = nvkm_longopt(device->cfgopt, "NvBoost",
>>                                        NVKM_CLK_BOOST_NONE);
>> +
>> +       nvkm_clk_parse_max_temp(clk);
>> +
>>         return 0;
>>  }
>>
>> --
>> 2.13.2
>>
>> _______________________________________________
>> Nouveau mailing list
>> Nouveau@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/nouveau
_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

Reply via email to