Re: [Nouveau] [PATCH 1/3] nvbios/power_budget: Add basic power budget parsing
2016-11-12 12:58 GMT+01:00 Pierre Moreau: > On 11:55 am - Nov 12 2016, Karol Herbst wrote: >> v2: Set entry to 0xff if not found >> Add cap entry for ver 0x30 tables >> Rework to fix memory leak >> >> Signed-off-by: Karol Herbst >> --- >> .../include/nvkm/subdev/bios/power_budget.h| 24 >> drm/nouveau/nvkm/subdev/bios/Kbuild| 1 + >> drm/nouveau/nvkm/subdev/bios/power_budget.c| 122 >> + >> 3 files changed, 147 insertions(+) >> create mode 100644 drm/nouveau/include/nvkm/subdev/bios/power_budget.h >> create mode 100644 drm/nouveau/nvkm/subdev/bios/power_budget.c >> >> diff --git a/drm/nouveau/include/nvkm/subdev/bios/power_budget.h >> b/drm/nouveau/include/nvkm/subdev/bios/power_budget.h >> new file mode 100644 >> index 000..f295cc7 >> --- /dev/null >> +++ b/drm/nouveau/include/nvkm/subdev/bios/power_budget.h >> @@ -0,0 +1,24 @@ >> +#ifndef __NVBIOS_POWER_BUDGET_H__ >> +#define __NVBIOS_POWER_BUDGET_H__ >> + >> +#include >> + >> +struct nvbios_power_budget_entry { >> + u32 min_w; >> + u32 avg_w; >> + u32 max_w; >> +}; >> + >> +struct nvbios_power_budget { >> + u32 offset; >> + u8 header_len; >> + u8 entry_len; >> + u8 entry_count; >> + u8 cap_entry; >> +}; >> + >> +int nvbios_power_budget_header(struct nvkm_bios *, struct >> nvbios_power_budget *); >> +int nvbios_power_budget_entry(struct nvkm_bios *, struct >> nvbios_power_budget *, >> + u8 idx, struct nvbios_power_budget_entry *); >> + >> +#endif >> diff --git a/drm/nouveau/nvkm/subdev/bios/Kbuild >> b/drm/nouveau/nvkm/subdev/bios/Kbuild >> index be57220..6b4f1e0 100644 >> --- a/drm/nouveau/nvkm/subdev/bios/Kbuild >> +++ b/drm/nouveau/nvkm/subdev/bios/Kbuild >> @@ -19,6 +19,7 @@ nvkm-y += nvkm/subdev/bios/pcir.o >> nvkm-y += nvkm/subdev/bios/perf.o >> nvkm-y += nvkm/subdev/bios/pll.o >> nvkm-y += nvkm/subdev/bios/pmu.o >> +nvkm-y += nvkm/subdev/bios/power_budget.o >> nvkm-y += nvkm/subdev/bios/ramcfg.o >> nvkm-y += nvkm/subdev/bios/rammap.o >> nvkm-y += nvkm/subdev/bios/shadow.o >> diff --git a/drm/nouveau/nvkm/subdev/bios/power_budget.c >> b/drm/nouveau/nvkm/subdev/bios/power_budget.c >> new file mode 100644 >> index 000..ed9760e >> --- /dev/null >> +++ b/drm/nouveau/nvkm/subdev/bios/power_budget.c >> @@ -0,0 +1,122 @@ >> +/* >> + * Copyright 2016 Karol Herbst >> + * >> + * 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: Karol Herbst >> + */ >> +#include >> +#include >> +#include >> + >> +static u32 >> +nvbios_power_budget_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, >> + u8 *len) >> +{ >> + struct bit_entry bit_P; >> + u32 power_budget; >> + >> + if (bit_entry(bios, 'P', _P) || bit_P.version != 2 || >> + bit_P.length < 0x2c) >> + return 0; >> + >> + power_budget = nvbios_rd32(bios, bit_P.offset + 0x2c); >> + if (!power_budget) >> + return 0; >> + >> + *ver = nvbios_rd08(bios, power_budget); >> + switch (*ver) { >> + case 0x10: >> + case 0x20: >> + case 0x30: >> + *hdr = nvbios_rd08(bios, power_budget + 0x1); >> + *len = nvbios_rd08(bios, power_budget + 0x2); >> + *cnt = nvbios_rd08(bios, power_budget + 0x3); >> + return power_budget; >> + default: >> + break; >> + } >> + >> + return 0; >> +} >> + >> +int >> +nvbios_power_budget_header(struct nvkm_bios *bios, >> + struct nvbios_power_budget *budget) >> +{ >> + struct nvkm_subdev *subdev = >subdev; >> + u8 ver, hdr, cnt, len, cap_entry; >> + u32 header; >> + >> + header = nvbios_power_budget_table(bios, , , , ); >> + if (!header || !cnt) > > Should there be a check for
Re: [Nouveau] [PATCH 1/3] nvbios/power_budget: Add basic power budget parsing
On 11:55 am - Nov 12 2016, Karol Herbst wrote: > v2: Set entry to 0xff if not found > Add cap entry for ver 0x30 tables > Rework to fix memory leak > > Signed-off-by: Karol Herbst> --- > .../include/nvkm/subdev/bios/power_budget.h| 24 > drm/nouveau/nvkm/subdev/bios/Kbuild| 1 + > drm/nouveau/nvkm/subdev/bios/power_budget.c| 122 > + > 3 files changed, 147 insertions(+) > create mode 100644 drm/nouveau/include/nvkm/subdev/bios/power_budget.h > create mode 100644 drm/nouveau/nvkm/subdev/bios/power_budget.c > > diff --git a/drm/nouveau/include/nvkm/subdev/bios/power_budget.h > b/drm/nouveau/include/nvkm/subdev/bios/power_budget.h > new file mode 100644 > index 000..f295cc7 > --- /dev/null > +++ b/drm/nouveau/include/nvkm/subdev/bios/power_budget.h > @@ -0,0 +1,24 @@ > +#ifndef __NVBIOS_POWER_BUDGET_H__ > +#define __NVBIOS_POWER_BUDGET_H__ > + > +#include > + > +struct nvbios_power_budget_entry { > + u32 min_w; > + u32 avg_w; > + u32 max_w; > +}; > + > +struct nvbios_power_budget { > + u32 offset; > + u8 header_len; > + u8 entry_len; > + u8 entry_count; > + u8 cap_entry; > +}; > + > +int nvbios_power_budget_header(struct nvkm_bios *, struct > nvbios_power_budget *); > +int nvbios_power_budget_entry(struct nvkm_bios *, struct nvbios_power_budget > *, > + u8 idx, struct nvbios_power_budget_entry *); > + > +#endif > diff --git a/drm/nouveau/nvkm/subdev/bios/Kbuild > b/drm/nouveau/nvkm/subdev/bios/Kbuild > index be57220..6b4f1e0 100644 > --- a/drm/nouveau/nvkm/subdev/bios/Kbuild > +++ b/drm/nouveau/nvkm/subdev/bios/Kbuild > @@ -19,6 +19,7 @@ nvkm-y += nvkm/subdev/bios/pcir.o > nvkm-y += nvkm/subdev/bios/perf.o > nvkm-y += nvkm/subdev/bios/pll.o > nvkm-y += nvkm/subdev/bios/pmu.o > +nvkm-y += nvkm/subdev/bios/power_budget.o > nvkm-y += nvkm/subdev/bios/ramcfg.o > nvkm-y += nvkm/subdev/bios/rammap.o > nvkm-y += nvkm/subdev/bios/shadow.o > diff --git a/drm/nouveau/nvkm/subdev/bios/power_budget.c > b/drm/nouveau/nvkm/subdev/bios/power_budget.c > new file mode 100644 > index 000..ed9760e > --- /dev/null > +++ b/drm/nouveau/nvkm/subdev/bios/power_budget.c > @@ -0,0 +1,122 @@ > +/* > + * Copyright 2016 Karol Herbst > + * > + * 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: Karol Herbst > + */ > +#include > +#include > +#include > + > +static u32 > +nvbios_power_budget_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, > + u8 *len) > +{ > + struct bit_entry bit_P; > + u32 power_budget; > + > + if (bit_entry(bios, 'P', _P) || bit_P.version != 2 || > + bit_P.length < 0x2c) > + return 0; > + > + power_budget = nvbios_rd32(bios, bit_P.offset + 0x2c); > + if (!power_budget) > + return 0; > + > + *ver = nvbios_rd08(bios, power_budget); > + switch (*ver) { > + case 0x10: > + case 0x20: > + case 0x30: > + *hdr = nvbios_rd08(bios, power_budget + 0x1); > + *len = nvbios_rd08(bios, power_budget + 0x2); > + *cnt = nvbios_rd08(bios, power_budget + 0x3); > + return power_budget; > + default: > + break; > + } > + > + return 0; > +} > + > +int > +nvbios_power_budget_header(struct nvkm_bios *bios, > + struct nvbios_power_budget *budget) > +{ > + struct nvkm_subdev *subdev = >subdev; > + u8 ver, hdr, cnt, len, cap_entry; > + u32 header; > + > + header = nvbios_power_budget_table(bios, , , , ); > + if (!header || !cnt) Should there be a check for `budget` being `NULL` here, similarly to `nvbios_power_budger_entry()`? (I haven’t looked at the other patches yet.) > + return -ENODEV; > + > + budget->offset = header; > + budget->header_len = hdr; >
[Nouveau] [PATCH 1/3] nvbios/power_budget: Add basic power budget parsing
v2: Set entry to 0xff if not found Add cap entry for ver 0x30 tables Rework to fix memory leak Signed-off-by: Karol Herbst--- .../include/nvkm/subdev/bios/power_budget.h| 24 drm/nouveau/nvkm/subdev/bios/Kbuild| 1 + drm/nouveau/nvkm/subdev/bios/power_budget.c| 122 + 3 files changed, 147 insertions(+) create mode 100644 drm/nouveau/include/nvkm/subdev/bios/power_budget.h create mode 100644 drm/nouveau/nvkm/subdev/bios/power_budget.c diff --git a/drm/nouveau/include/nvkm/subdev/bios/power_budget.h b/drm/nouveau/include/nvkm/subdev/bios/power_budget.h new file mode 100644 index 000..f295cc7 --- /dev/null +++ b/drm/nouveau/include/nvkm/subdev/bios/power_budget.h @@ -0,0 +1,24 @@ +#ifndef __NVBIOS_POWER_BUDGET_H__ +#define __NVBIOS_POWER_BUDGET_H__ + +#include + +struct nvbios_power_budget_entry { + u32 min_w; + u32 avg_w; + u32 max_w; +}; + +struct nvbios_power_budget { + u32 offset; + u8 header_len; + u8 entry_len; + u8 entry_count; + u8 cap_entry; +}; + +int nvbios_power_budget_header(struct nvkm_bios *, struct nvbios_power_budget *); +int nvbios_power_budget_entry(struct nvkm_bios *, struct nvbios_power_budget *, + u8 idx, struct nvbios_power_budget_entry *); + +#endif diff --git a/drm/nouveau/nvkm/subdev/bios/Kbuild b/drm/nouveau/nvkm/subdev/bios/Kbuild index be57220..6b4f1e0 100644 --- a/drm/nouveau/nvkm/subdev/bios/Kbuild +++ b/drm/nouveau/nvkm/subdev/bios/Kbuild @@ -19,6 +19,7 @@ nvkm-y += nvkm/subdev/bios/pcir.o nvkm-y += nvkm/subdev/bios/perf.o nvkm-y += nvkm/subdev/bios/pll.o nvkm-y += nvkm/subdev/bios/pmu.o +nvkm-y += nvkm/subdev/bios/power_budget.o nvkm-y += nvkm/subdev/bios/ramcfg.o nvkm-y += nvkm/subdev/bios/rammap.o nvkm-y += nvkm/subdev/bios/shadow.o diff --git a/drm/nouveau/nvkm/subdev/bios/power_budget.c b/drm/nouveau/nvkm/subdev/bios/power_budget.c new file mode 100644 index 000..ed9760e --- /dev/null +++ b/drm/nouveau/nvkm/subdev/bios/power_budget.c @@ -0,0 +1,122 @@ +/* + * Copyright 2016 Karol Herbst + * + * 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: Karol Herbst + */ +#include +#include +#include + +static u32 +nvbios_power_budget_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, + u8 *len) +{ + struct bit_entry bit_P; + u32 power_budget; + + if (bit_entry(bios, 'P', _P) || bit_P.version != 2 || + bit_P.length < 0x2c) + return 0; + + power_budget = nvbios_rd32(bios, bit_P.offset + 0x2c); + if (!power_budget) + return 0; + + *ver = nvbios_rd08(bios, power_budget); + switch (*ver) { + case 0x10: + case 0x20: + case 0x30: + *hdr = nvbios_rd08(bios, power_budget + 0x1); + *len = nvbios_rd08(bios, power_budget + 0x2); + *cnt = nvbios_rd08(bios, power_budget + 0x3); + return power_budget; + default: + break; + } + + return 0; +} + +int +nvbios_power_budget_header(struct nvkm_bios *bios, + struct nvbios_power_budget *budget) +{ + struct nvkm_subdev *subdev = >subdev; + u8 ver, hdr, cnt, len, cap_entry; + u32 header; + + header = nvbios_power_budget_table(bios, , , , ); + if (!header || !cnt) + return -ENODEV; + + budget->offset = header; + budget->header_len = hdr; + budget->entry_len = len; + budget->entry_count = cnt; + + switch (ver) { + case 0x20: + cap_entry = nvbios_rd08(bios, header + 0x9); + break; + case 0x30: + cap_entry = nvbios_rd08(bios, header + 0xa); + break; + default: + cap_entry = 0xff; + } + + if (cap_entry < cnt) +
Re: [Nouveau] [PATCH 1/3] nvbios/power_budget: Add basic power budget parsing
On 25 October 2016 7:25:46 a.m. GMT+02:00, Martin Pereswrote: >On 25/10/16 00:11, Karol Herbst wrote: >> Signed-off-by: Karol Herbst >> --- >> .../include/nvkm/subdev/bios/power_budget.h| 20 >> drm/nouveau/nvkm/subdev/bios/Kbuild| 1 + >> drm/nouveau/nvkm/subdev/bios/power_budget.c| 108 >+ >> 3 files changed, 129 insertions(+) >> create mode 100644 >drm/nouveau/include/nvkm/subdev/bios/power_budget.h >> create mode 100644 drm/nouveau/nvkm/subdev/bios/power_budget.c >> >> diff --git a/drm/nouveau/include/nvkm/subdev/bios/power_budget.h >b/drm/nouveau/include/nvkm/subdev/bios/power_budget.h >> new file mode 100644 >> index 000..dd65c08 >> --- /dev/null >> +++ b/drm/nouveau/include/nvkm/subdev/bios/power_budget.h >> @@ -0,0 +1,20 @@ >> +#ifndef __NVBIOS_POWER_BUDGET_H__ >> +#define __NVBIOS_POWER_BUDGET_H__ >> + >> +#include >> + >> +struct nvbios_power_budget_entry { >> +u32 min_w; >> +u32 avg_w; >> +u32 max_w; >> +}; >> + >> +struct nvbios_power_budget { >> +u8 nr_entry; >> +u8 cap_entry; >> +struct nvbios_power_budget_entry *entries; >> +}; >> + >> +int nvbios_power_budget_parse(struct nvkm_bios *, struct >nvbios_power_budget *); >> + >> +#endif >> diff --git a/drm/nouveau/nvkm/subdev/bios/Kbuild >b/drm/nouveau/nvkm/subdev/bios/Kbuild >> index be57220..6b4f1e0 100644 >> --- a/drm/nouveau/nvkm/subdev/bios/Kbuild >> +++ b/drm/nouveau/nvkm/subdev/bios/Kbuild >> @@ -19,6 +19,7 @@ nvkm-y += nvkm/subdev/bios/pcir.o >> nvkm-y += nvkm/subdev/bios/perf.o >> nvkm-y += nvkm/subdev/bios/pll.o >> nvkm-y += nvkm/subdev/bios/pmu.o >> +nvkm-y += nvkm/subdev/bios/power_budget.o >> nvkm-y += nvkm/subdev/bios/ramcfg.o >> nvkm-y += nvkm/subdev/bios/rammap.o >> nvkm-y += nvkm/subdev/bios/shadow.o >> diff --git a/drm/nouveau/nvkm/subdev/bios/power_budget.c >b/drm/nouveau/nvkm/subdev/bios/power_budget.c >> new file mode 100644 >> index 000..538497b >> --- /dev/null >> +++ b/drm/nouveau/nvkm/subdev/bios/power_budget.c >> @@ -0,0 +1,108 @@ >> +/* >> + * Copyright 2015 Karol Herbst >> + * >> + * 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: Karol Herbst >> + */ >> +#include >> +#include >> +#include >> + >> +static u32 >> +nvbios_power_budget_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, >u8 *cnt, >> + u8 *len) >> +{ >> +struct bit_entry bit_P; >> +u32 power_budget; >> + >> +if (bit_entry(bios, 'P', _P) || bit_P.version != 2 || >> +bit_P.length < 0x2c) >> +return 0; >> + >> +power_budget = nvbios_rd32(bios, bit_P.offset + 0x2c); >> +if (!power_budget) >> +return 0; >> + >> +*ver = nvbios_rd08(bios, power_budget); >> +switch (*ver) { >> +case 0x10: >> +case 0x20: >> +case 0x30: >> +*hdr = nvbios_rd08(bios, power_budget + 0x1); >> +*len = nvbios_rd08(bios, power_budget + 0x2); >> +*cnt = nvbios_rd08(bios, power_budget + 0x3); >> +return power_budget; >> +default: >> +break; >> +} >> + >> +return 0; >> +} >> + >> +int >> +nvbios_power_budget_parse(struct nvkm_bios *bios, struct >nvbios_power_budget *budget) >> +{ >> +struct nvkm_subdev *subdev = >subdev; >> +u8 ver, hdr, cnt, len, i, cap_entry; >> +u32 header; >> + >> +header = nvbios_power_budget_table(bios, , , , ); >> +if (!header || !cnt) >> +return -ENODEV; >> + >> +budget->entries = kmalloc_array(cnt, sizeof(*budget->entries), >GFP_KERNEL); >> +if (!budget->entries) >> +return -ENOMEM; >> + >> +budget->nr_entry = cnt; >> +switch (ver) { >> +case 0x20: >> +cap_entry = nvbios_rd08(bios, header + 0x9); >> +break; >> +default: >> +cap_entry = 0; > >Are
Re: [Nouveau] [PATCH 1/3] nvbios/power_budget: Add basic power budget parsing
On 25/10/16 00:11, Karol Herbst wrote: Signed-off-by: Karol Herbst--- .../include/nvkm/subdev/bios/power_budget.h| 20 drm/nouveau/nvkm/subdev/bios/Kbuild| 1 + drm/nouveau/nvkm/subdev/bios/power_budget.c| 108 + 3 files changed, 129 insertions(+) create mode 100644 drm/nouveau/include/nvkm/subdev/bios/power_budget.h create mode 100644 drm/nouveau/nvkm/subdev/bios/power_budget.c diff --git a/drm/nouveau/include/nvkm/subdev/bios/power_budget.h b/drm/nouveau/include/nvkm/subdev/bios/power_budget.h new file mode 100644 index 000..dd65c08 --- /dev/null +++ b/drm/nouveau/include/nvkm/subdev/bios/power_budget.h @@ -0,0 +1,20 @@ +#ifndef __NVBIOS_POWER_BUDGET_H__ +#define __NVBIOS_POWER_BUDGET_H__ + +#include + +struct nvbios_power_budget_entry { + u32 min_w; + u32 avg_w; + u32 max_w; +}; + +struct nvbios_power_budget { + u8 nr_entry; + u8 cap_entry; + struct nvbios_power_budget_entry *entries; +}; + +int nvbios_power_budget_parse(struct nvkm_bios *, struct nvbios_power_budget *); + +#endif diff --git a/drm/nouveau/nvkm/subdev/bios/Kbuild b/drm/nouveau/nvkm/subdev/bios/Kbuild index be57220..6b4f1e0 100644 --- a/drm/nouveau/nvkm/subdev/bios/Kbuild +++ b/drm/nouveau/nvkm/subdev/bios/Kbuild @@ -19,6 +19,7 @@ nvkm-y += nvkm/subdev/bios/pcir.o nvkm-y += nvkm/subdev/bios/perf.o nvkm-y += nvkm/subdev/bios/pll.o nvkm-y += nvkm/subdev/bios/pmu.o +nvkm-y += nvkm/subdev/bios/power_budget.o nvkm-y += nvkm/subdev/bios/ramcfg.o nvkm-y += nvkm/subdev/bios/rammap.o nvkm-y += nvkm/subdev/bios/shadow.o diff --git a/drm/nouveau/nvkm/subdev/bios/power_budget.c b/drm/nouveau/nvkm/subdev/bios/power_budget.c new file mode 100644 index 000..538497b --- /dev/null +++ b/drm/nouveau/nvkm/subdev/bios/power_budget.c @@ -0,0 +1,108 @@ +/* + * Copyright 2015 Karol Herbst + * + * 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: Karol Herbst + */ +#include +#include +#include + +static u32 +nvbios_power_budget_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, + u8 *len) +{ + struct bit_entry bit_P; + u32 power_budget; + + if (bit_entry(bios, 'P', _P) || bit_P.version != 2 || + bit_P.length < 0x2c) + return 0; + + power_budget = nvbios_rd32(bios, bit_P.offset + 0x2c); + if (!power_budget) + return 0; + + *ver = nvbios_rd08(bios, power_budget); + switch (*ver) { + case 0x10: + case 0x20: + case 0x30: + *hdr = nvbios_rd08(bios, power_budget + 0x1); + *len = nvbios_rd08(bios, power_budget + 0x2); + *cnt = nvbios_rd08(bios, power_budget + 0x3); + return power_budget; + default: + break; + } + + return 0; +} + +int +nvbios_power_budget_parse(struct nvkm_bios *bios, struct nvbios_power_budget *budget) +{ + struct nvkm_subdev *subdev = >subdev; + u8 ver, hdr, cnt, len, i, cap_entry; + u32 header; + + header = nvbios_power_budget_table(bios, , , , ); + if (!header || !cnt) + return -ENODEV; + + budget->entries = kmalloc_array(cnt, sizeof(*budget->entries), GFP_KERNEL); + if (!budget->entries) + return -ENOMEM; + + budget->nr_entry = cnt; + switch (ver) { + case 0x20: + cap_entry = nvbios_rd08(bios, header + 0x9); + break; + default: + cap_entry = 0; Are you sure about this? How about setting it to 0xff instead? + } + + if (cap_entry < cnt) + budget->cap_entry = cap_entry; + else { + if (cap_entry != 0xff) + nvkm_warn(subdev, + "invalid cap_entry in power budget table found\n"); + budget->cap_entry =
[Nouveau] [PATCH 1/3] nvbios/power_budget: Add basic power budget parsing
Signed-off-by: Karol Herbst--- .../include/nvkm/subdev/bios/power_budget.h| 20 drm/nouveau/nvkm/subdev/bios/Kbuild| 1 + drm/nouveau/nvkm/subdev/bios/power_budget.c| 108 + 3 files changed, 129 insertions(+) create mode 100644 drm/nouveau/include/nvkm/subdev/bios/power_budget.h create mode 100644 drm/nouveau/nvkm/subdev/bios/power_budget.c diff --git a/drm/nouveau/include/nvkm/subdev/bios/power_budget.h b/drm/nouveau/include/nvkm/subdev/bios/power_budget.h new file mode 100644 index 000..dd65c08 --- /dev/null +++ b/drm/nouveau/include/nvkm/subdev/bios/power_budget.h @@ -0,0 +1,20 @@ +#ifndef __NVBIOS_POWER_BUDGET_H__ +#define __NVBIOS_POWER_BUDGET_H__ + +#include + +struct nvbios_power_budget_entry { + u32 min_w; + u32 avg_w; + u32 max_w; +}; + +struct nvbios_power_budget { + u8 nr_entry; + u8 cap_entry; + struct nvbios_power_budget_entry *entries; +}; + +int nvbios_power_budget_parse(struct nvkm_bios *, struct nvbios_power_budget *); + +#endif diff --git a/drm/nouveau/nvkm/subdev/bios/Kbuild b/drm/nouveau/nvkm/subdev/bios/Kbuild index be57220..6b4f1e0 100644 --- a/drm/nouveau/nvkm/subdev/bios/Kbuild +++ b/drm/nouveau/nvkm/subdev/bios/Kbuild @@ -19,6 +19,7 @@ nvkm-y += nvkm/subdev/bios/pcir.o nvkm-y += nvkm/subdev/bios/perf.o nvkm-y += nvkm/subdev/bios/pll.o nvkm-y += nvkm/subdev/bios/pmu.o +nvkm-y += nvkm/subdev/bios/power_budget.o nvkm-y += nvkm/subdev/bios/ramcfg.o nvkm-y += nvkm/subdev/bios/rammap.o nvkm-y += nvkm/subdev/bios/shadow.o diff --git a/drm/nouveau/nvkm/subdev/bios/power_budget.c b/drm/nouveau/nvkm/subdev/bios/power_budget.c new file mode 100644 index 000..538497b --- /dev/null +++ b/drm/nouveau/nvkm/subdev/bios/power_budget.c @@ -0,0 +1,108 @@ +/* + * Copyright 2015 Karol Herbst + * + * 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: Karol Herbst + */ +#include +#include +#include + +static u32 +nvbios_power_budget_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, + u8 *len) +{ + struct bit_entry bit_P; + u32 power_budget; + + if (bit_entry(bios, 'P', _P) || bit_P.version != 2 || + bit_P.length < 0x2c) + return 0; + + power_budget = nvbios_rd32(bios, bit_P.offset + 0x2c); + if (!power_budget) + return 0; + + *ver = nvbios_rd08(bios, power_budget); + switch (*ver) { + case 0x10: + case 0x20: + case 0x30: + *hdr = nvbios_rd08(bios, power_budget + 0x1); + *len = nvbios_rd08(bios, power_budget + 0x2); + *cnt = nvbios_rd08(bios, power_budget + 0x3); + return power_budget; + default: + break; + } + + return 0; +} + +int +nvbios_power_budget_parse(struct nvkm_bios *bios, struct nvbios_power_budget *budget) +{ + struct nvkm_subdev *subdev = >subdev; + u8 ver, hdr, cnt, len, i, cap_entry; + u32 header; + + header = nvbios_power_budget_table(bios, , , , ); + if (!header || !cnt) + return -ENODEV; + + budget->entries = kmalloc_array(cnt, sizeof(*budget->entries), GFP_KERNEL); + if (!budget->entries) + return -ENOMEM; + + budget->nr_entry = cnt; + switch (ver) { + case 0x20: + cap_entry = nvbios_rd08(bios, header + 0x9); + break; + default: + cap_entry = 0; + } + + if (cap_entry < cnt) + budget->cap_entry = cap_entry; + else { + if (cap_entry != 0xff) + nvkm_warn(subdev, + "invalid cap_entry in power budget table found\n"); + budget->cap_entry = 0xff; + } + + for (i = 0; i < cnt; ++i) { + u32 entry_offset = header + hdr + i *