Re: [Nouveau] [PATCH 3/3] hwmon: expose power_max and power_crit

2016-10-24 Thread Martin Peres

On 25/10/16 00:11, Karol Herbst wrote:

Signed-off-by: Karol Herbst 
---
 drm/nouveau/nouveau_hwmon.c | 44 
 1 file changed, 44 insertions(+)

diff --git a/drm/nouveau/nouveau_hwmon.c b/drm/nouveau/nouveau_hwmon.c
index 71f764b..3d4672a 100644
--- a/drm/nouveau/nouveau_hwmon.c
+++ b/drm/nouveau/nouveau_hwmon.c
@@ -596,6 +596,32 @@ nouveau_hwmon_get_power1_input(struct device *d, struct 
device_attribute *a,
 static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO,
  nouveau_hwmon_get_power1_input, NULL, 0);

+static ssize_t
+nouveau_hwmon_get_power1_max(struct device *d, struct device_attribute *a,
+char *buf)
+{
+   struct drm_device *dev = dev_get_drvdata(d);
+   struct nouveau_drm *drm = nouveau_drm(dev);
+   struct nvkm_iccsense *iccsense = nvxx_iccsense(>device);
+   return sprintf(buf, "%i\n", iccsense->power_w_max);
+}
+
+static SENSOR_DEVICE_ATTR(power1_max, S_IRUGO,
+ nouveau_hwmon_get_power1_max, NULL, 0);
+
+static ssize_t
+nouveau_hwmon_get_power1_crit(struct device *d, struct device_attribute *a,
+ char *buf)
+{
+   struct drm_device *dev = dev_get_drvdata(d);
+   struct nouveau_drm *drm = nouveau_drm(dev);
+   struct nvkm_iccsense *iccsense = nvxx_iccsense(>device);
+   return sprintf(buf, "%i\n", iccsense->power_w_crit);
+}
+
+static SENSOR_DEVICE_ATTR(power1_crit, S_IRUGO,
+ nouveau_hwmon_get_power1_crit, NULL, 0);
+
 static struct attribute *hwmon_default_attributes[] = {
_dev_attr_name.dev_attr.attr,
_dev_attr_update_rate.dev_attr.attr,
@@ -639,6 +665,12 @@ static struct attribute *hwmon_power_attributes[] = {
NULL
 };

+static struct attribute *hwmon_power_caps_attributes[] = {
+   _dev_attr_power1_max.dev_attr.attr,
+   _dev_attr_power1_crit.dev_attr.attr,
+   NULL
+};
+
 static const struct attribute_group hwmon_default_attrgroup = {
.attrs = hwmon_default_attributes,
 };
@@ -657,6 +689,9 @@ static const struct attribute_group hwmon_in0_attrgroup = {
 static const struct attribute_group hwmon_power_attrgroup = {
.attrs = hwmon_power_attributes,
 };
+static const struct attribute_group hwmon_power_caps_attrgroup = {
+   .attrs = hwmon_power_caps_attributes,
+};
 #endif

 int
@@ -728,8 +763,16 @@ nouveau_hwmon_init(struct drm_device *dev)
if (iccsense && iccsense->data_valid && !list_empty(>rails)) {
ret = sysfs_create_group(_dev->kobj,
 _power_attrgroup);
+
if (ret)
goto error;
+
+   if (iccsense->power_w_max && iccsense->power_w_crit) {
+   ret = sysfs_create_group(_dev->kobj,
+_power_caps_attrgroup);
+   if (ret)
+   goto error;
+   }
}

hwmon->hwmon = hwmon_dev;
@@ -759,6 +802,7 @@ nouveau_hwmon_fini(struct drm_device *dev)
sysfs_remove_group(>hwmon->kobj, 
_fan_rpm_attrgroup);
sysfs_remove_group(>hwmon->kobj, _in0_attrgroup);
sysfs_remove_group(>hwmon->kobj, _power_attrgroup);
+   sysfs_remove_group(>hwmon->kobj, 
_power_caps_attrgroup);

hwmon_device_unregister(hwmon->hwmon);
}



So, you wanted to make a cache because you felt you may want to let the 
user edit the values?


Not sure we should ever allow this :s At least, a RO file is a very good 
idea to help debugging and just letting the user know about such 
limitations.


So, in my opinion, I think we should just kill patch 2 and use directly 
the output of the bios table here. Maybe you can write a helper function 
in patch 1 to get the min, avg and max values and return -1 if it is not 
valid? This way, you can access this info very easily in multiple places 
without duplicating this 0xff check.



___
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [PATCH 2/3] subdev/iccsense: Parse max and crit power level

2016-10-24 Thread Martin Peres

On 25/10/16 00:11, Karol Herbst wrote:

Signed-off-by: Karol Herbst 
---
 drm/nouveau/include/nvkm/subdev/iccsense.h |  3 +++
 drm/nouveau/nvkm/subdev/iccsense/base.c| 13 -
 2 files changed, 15 insertions(+), 1 deletion(-)


What is the point of duplicating values here? Just store the parsed bios 
table, like we do for fan management.


___
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [PATCH 1/3] nvbios/power_budget: Add basic power budget parsing

2016-10-24 Thread Martin Peres

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 = 

Re: [Nouveau] RFC [PATCH 0/3] Expose power budget cap via hwmon

2016-10-24 Thread Martin Peres

On 25/10/16 00:11, Karol Herbst wrote:

There is an optinal header field in the power budget table we can use to
read out the power cap of the GPU.

Sadly it is optional and if that field isn't sad, things beome


oh why would it be sad? Poor little one :p


complicated.

Anyhow, this is good enough for most cards and we can use it later for
capping the power consumption of the GPUs, but first, just export those
values through hwmon.

First design, will change stuff, want comments. Thanks.


Thanks for doing this!



Karol Herbst (3):
  nvbios/power_budget: Add basic power budget parsing
  subdev/iccsense: Parse max and crit power level
  hwmon: expose power_max and power_crit

 .../include/nvkm/subdev/bios/power_budget.h|  20 
 drm/nouveau/include/nvkm/subdev/iccsense.h |   3 +
 drm/nouveau/nouveau_hwmon.c|  44 +
 drm/nouveau/nvkm/subdev/bios/Kbuild|   1 +
 drm/nouveau/nvkm/subdev/bios/power_budget.c| 108 +
 drm/nouveau/nvkm/subdev/iccsense/base.c|  13 ++-
 6 files changed, 188 insertions(+), 1 deletion(-)
 create mode 100644 drm/nouveau/include/nvkm/subdev/bios/power_budget.h
 create mode 100644 drm/nouveau/nvkm/subdev/bios/power_budget.c



___
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [PATCH 01/17] drm/nouveau/core: add missing header dependencies

2016-10-24 Thread Baoyou Xie
On 24 October 2016 at 23:43, Karol Herbst  wrote:

> 2016-10-24 9:13 GMT+02:00 Baoyou Xie :
> >
> >
> > On 23 October 2016 at 01:32, Karol Herbst  wrote:
> >>
> >> I think it would be better to squash those commits:
> >> 1. for the includes
> >> 2. for static declerations
> >>
> > OK, I have resent new patch that squash those commits.
> >
>
> thanks, this is much easier to review and keeps the git history clean :)
> Will try to make a test with those patches over the next days, but it
> looks fine as it is already.
>
>
I worked them out on next-20161021.


> >>
> >> 2016-10-22 11:41 GMT+02:00 Baoyou Xie :
> >> > We get 2 warnings when building kernel with W=1:
> >> > drivers/gpu/drm/nouveau/nvkm/core/firmware.c:34:1: warning: no
> previous
> >> > prototype for 'nvkm_firmware_get' [-Wmissing-prototypes]
> >> > drivers/gpu/drm/nouveau/nvkm/core/firmware.c:58:1: warning: no
> previous
> >> > prototype for 'nvkm_firmware_put' [-Wmissing-prototypes]
> >> >
> >> > In fact, these functions are declared in
> >> > drivers/gpu/drm/nouveau/include/nvkm/core/firmware.h.
> >> > So this patch adds missing header dependencies.
> >> >
> >> > Signed-off-by: Baoyou Xie 
> >> > ---
> >> >  drivers/gpu/drm/nouveau/nvkm/core/firmware.c | 1 +
> >> >  1 file changed, 1 insertion(+)
> >> >
> >> > diff --git a/drivers/gpu/drm/nouveau/nvkm/core/firmware.c
> >> > b/drivers/gpu/drm/nouveau/nvkm/core/firmware.c
> >> > index 34ecd4a..058ff46 100644
> >> > --- a/drivers/gpu/drm/nouveau/nvkm/core/firmware.c
> >> > +++ b/drivers/gpu/drm/nouveau/nvkm/core/firmware.c
> >> > @@ -20,6 +20,7 @@
> >> >   * DEALINGS IN THE SOFTWARE.
> >> >   */
> >> >  #include 
> >> > +#include 
> >> >
> >> >  /**
> >> >   * nvkm_firmware_get - load firmware from the official nvidia/chip/
> >> > directory
> >> > --
> >> > 2.7.4
> >> >
> >> > ___
> >> > 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


[Nouveau] [PATCH 2/3] subdev/iccsense: Parse max and crit power level

2016-10-24 Thread Karol Herbst
Signed-off-by: Karol Herbst 
---
 drm/nouveau/include/nvkm/subdev/iccsense.h |  3 +++
 drm/nouveau/nvkm/subdev/iccsense/base.c| 13 -
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/drm/nouveau/include/nvkm/subdev/iccsense.h 
b/drm/nouveau/include/nvkm/subdev/iccsense.h
index 3c2ddd9..b7a9b04 100644
--- a/drm/nouveau/include/nvkm/subdev/iccsense.h
+++ b/drm/nouveau/include/nvkm/subdev/iccsense.h
@@ -8,6 +8,9 @@ struct nvkm_iccsense {
bool data_valid;
struct list_head sensors;
struct list_head rails;
+
+   u32 power_w_max;
+   u32 power_w_crit;
 };
 
 int gf100_iccsense_new(struct nvkm_device *, int index, struct nvkm_iccsense 
**);
diff --git a/drm/nouveau/nvkm/subdev/iccsense/base.c 
b/drm/nouveau/nvkm/subdev/iccsense/base.c
index 658355f..4e2b074 100644
--- a/drm/nouveau/nvkm/subdev/iccsense/base.c
+++ b/drm/nouveau/nvkm/subdev/iccsense/base.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 static bool
@@ -216,10 +217,20 @@ nvkm_iccsense_oneinit(struct nvkm_subdev *subdev)
 {
struct nvkm_iccsense *iccsense = nvkm_iccsense(subdev);
struct nvkm_bios *bios = subdev->device->bios;
+   struct nvbios_power_budget budget;
struct nvbios_iccsense stbl;
int i;
 
-   if (!bios || nvbios_iccsense_parse(bios, ) || !stbl.nr_entry)
+   if (!bios)
+   return 0;
+
+   if (!nvbios_power_budget_parse(bios, ) && budget.nr_entry &&
+   budget.cap_entry != 0xff) {
+   iccsense->power_w_max  = budget.entries[budget.cap_entry].avg_w;
+   iccsense->power_w_crit = budget.entries[budget.cap_entry].max_w;
+   }
+
+   if (nvbios_iccsense_parse(bios, ) || !stbl.nr_entry)
return 0;
 
iccsense->data_valid = true;
-- 
2.10.0

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH 3/3] hwmon: expose power_max and power_crit

2016-10-24 Thread Karol Herbst
Signed-off-by: Karol Herbst 
---
 drm/nouveau/nouveau_hwmon.c | 44 
 1 file changed, 44 insertions(+)

diff --git a/drm/nouveau/nouveau_hwmon.c b/drm/nouveau/nouveau_hwmon.c
index 71f764b..3d4672a 100644
--- a/drm/nouveau/nouveau_hwmon.c
+++ b/drm/nouveau/nouveau_hwmon.c
@@ -596,6 +596,32 @@ nouveau_hwmon_get_power1_input(struct device *d, struct 
device_attribute *a,
 static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO,
  nouveau_hwmon_get_power1_input, NULL, 0);
 
+static ssize_t
+nouveau_hwmon_get_power1_max(struct device *d, struct device_attribute *a,
+char *buf)
+{
+   struct drm_device *dev = dev_get_drvdata(d);
+   struct nouveau_drm *drm = nouveau_drm(dev);
+   struct nvkm_iccsense *iccsense = nvxx_iccsense(>device);
+   return sprintf(buf, "%i\n", iccsense->power_w_max);
+}
+
+static SENSOR_DEVICE_ATTR(power1_max, S_IRUGO,
+ nouveau_hwmon_get_power1_max, NULL, 0);
+
+static ssize_t
+nouveau_hwmon_get_power1_crit(struct device *d, struct device_attribute *a,
+ char *buf)
+{
+   struct drm_device *dev = dev_get_drvdata(d);
+   struct nouveau_drm *drm = nouveau_drm(dev);
+   struct nvkm_iccsense *iccsense = nvxx_iccsense(>device);
+   return sprintf(buf, "%i\n", iccsense->power_w_crit);
+}
+
+static SENSOR_DEVICE_ATTR(power1_crit, S_IRUGO,
+ nouveau_hwmon_get_power1_crit, NULL, 0);
+
 static struct attribute *hwmon_default_attributes[] = {
_dev_attr_name.dev_attr.attr,
_dev_attr_update_rate.dev_attr.attr,
@@ -639,6 +665,12 @@ static struct attribute *hwmon_power_attributes[] = {
NULL
 };
 
+static struct attribute *hwmon_power_caps_attributes[] = {
+   _dev_attr_power1_max.dev_attr.attr,
+   _dev_attr_power1_crit.dev_attr.attr,
+   NULL
+};
+
 static const struct attribute_group hwmon_default_attrgroup = {
.attrs = hwmon_default_attributes,
 };
@@ -657,6 +689,9 @@ static const struct attribute_group hwmon_in0_attrgroup = {
 static const struct attribute_group hwmon_power_attrgroup = {
.attrs = hwmon_power_attributes,
 };
+static const struct attribute_group hwmon_power_caps_attrgroup = {
+   .attrs = hwmon_power_caps_attributes,
+};
 #endif
 
 int
@@ -728,8 +763,16 @@ nouveau_hwmon_init(struct drm_device *dev)
if (iccsense && iccsense->data_valid && !list_empty(>rails)) {
ret = sysfs_create_group(_dev->kobj,
 _power_attrgroup);
+
if (ret)
goto error;
+
+   if (iccsense->power_w_max && iccsense->power_w_crit) {
+   ret = sysfs_create_group(_dev->kobj,
+_power_caps_attrgroup);
+   if (ret)
+   goto error;
+   }
}
 
hwmon->hwmon = hwmon_dev;
@@ -759,6 +802,7 @@ nouveau_hwmon_fini(struct drm_device *dev)
sysfs_remove_group(>hwmon->kobj, 
_fan_rpm_attrgroup);
sysfs_remove_group(>hwmon->kobj, _in0_attrgroup);
sysfs_remove_group(>hwmon->kobj, _power_attrgroup);
+   sysfs_remove_group(>hwmon->kobj, 
_power_caps_attrgroup);
 
hwmon_device_unregister(hwmon->hwmon);
}
-- 
2.10.0

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] RFC [PATCH 0/3] Expose power budget cap via hwmon

2016-10-24 Thread Karol Herbst
There is an optinal header field in the power budget table we can use to
read out the power cap of the GPU.

Sadly it is optional and if that field isn't sad, things beome
complicated.

Anyhow, this is good enough for most cards and we can use it later for
capping the power consumption of the GPUs, but first, just export those
values through hwmon.

First design, will change stuff, want comments. Thanks.

Karol Herbst (3):
  nvbios/power_budget: Add basic power budget parsing
  subdev/iccsense: Parse max and crit power level
  hwmon: expose power_max and power_crit

 .../include/nvkm/subdev/bios/power_budget.h|  20 
 drm/nouveau/include/nvkm/subdev/iccsense.h |   3 +
 drm/nouveau/nouveau_hwmon.c|  44 +
 drm/nouveau/nvkm/subdev/bios/Kbuild|   1 +
 drm/nouveau/nvkm/subdev/bios/power_budget.c| 108 +
 drm/nouveau/nvkm/subdev/iccsense/base.c|  13 ++-
 6 files changed, 188 insertions(+), 1 deletion(-)
 create mode 100644 drm/nouveau/include/nvkm/subdev/bios/power_budget.h
 create mode 100644 drm/nouveau/nvkm/subdev/bios/power_budget.c

-- 
2.10.0

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH 1/3] nvbios/power_budget: Add basic power budget parsing

2016-10-24 Thread Karol Herbst
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 * 

Re: [Nouveau] [PATCH] nouveau: hide gcc-4.9 -Wmaybe-uninitialized

2016-10-24 Thread Karol Herbst
uhh, that function looks so odd, ... yeah. Change looks fine.

Reviewed-By: Karol Herbst 

2016-10-24 17:30 GMT+02:00 Arnd Bergmann :
> gcc-4.9 notices that the validate_init() function returns unintialized
> data when called with a zero 'nr_buffers' argument, when called with the
> -Wmaybe-uninitialized flag:
>
> drivers/gpu/drm/nouveau/nouveau_gem.c: In function ‘validate_init.isra.6’:
> drivers/gpu/drm/nouveau/nouveau_gem.c:457:5: error: ‘ret’ may be used 
> uninitialized in this function [-Werror=maybe-uninitialized]
>
> However, the only caller of this function always passes a nonzero
> argument, and gcc-6 is clever enough to take this into account and
> not warn about it any more.
>
> Adding an explicit initialization to -EINVAL here is correct even if
> the caller changed, and it avoids the warning on gcc-4.9 as well.
>
> Signed-off-by: Arnd Bergmann 
> ---
>  drivers/gpu/drm/nouveau/nouveau_gem.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c 
> b/drivers/gpu/drm/nouveau/nouveau_gem.c
> index 0bd7164bc817..4f3c5f3eaa16 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
> @@ -369,7 +369,7 @@ validate_init(struct nouveau_channel *chan, struct 
> drm_file *file_priv,
>  {
> struct nouveau_cli *cli = nouveau_cli(file_priv);
> int trycnt = 0;
> -   int ret, i;
> +   int ret = -EINVAL, i;
> struct nouveau_bo *res_bo = NULL;
> LIST_HEAD(gart_list);
> LIST_HEAD(vram_list);
> --
> 2.9.0
>
> ___
> 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


Re: [Nouveau] [PATCH 01/17] drm/nouveau/core: add missing header dependencies

2016-10-24 Thread Karol Herbst
2016-10-24 9:13 GMT+02:00 Baoyou Xie :
>
>
> On 23 October 2016 at 01:32, Karol Herbst  wrote:
>>
>> I think it would be better to squash those commits:
>> 1. for the includes
>> 2. for static declerations
>>
> OK, I have resent new patch that squash those commits.
>

thanks, this is much easier to review and keeps the git history clean :)
Will try to make a test with those patches over the next days, but it
looks fine as it is already.

>>
>> 2016-10-22 11:41 GMT+02:00 Baoyou Xie :
>> > We get 2 warnings when building kernel with W=1:
>> > drivers/gpu/drm/nouveau/nvkm/core/firmware.c:34:1: warning: no previous
>> > prototype for 'nvkm_firmware_get' [-Wmissing-prototypes]
>> > drivers/gpu/drm/nouveau/nvkm/core/firmware.c:58:1: warning: no previous
>> > prototype for 'nvkm_firmware_put' [-Wmissing-prototypes]
>> >
>> > In fact, these functions are declared in
>> > drivers/gpu/drm/nouveau/include/nvkm/core/firmware.h.
>> > So this patch adds missing header dependencies.
>> >
>> > Signed-off-by: Baoyou Xie 
>> > ---
>> >  drivers/gpu/drm/nouveau/nvkm/core/firmware.c | 1 +
>> >  1 file changed, 1 insertion(+)
>> >
>> > diff --git a/drivers/gpu/drm/nouveau/nvkm/core/firmware.c
>> > b/drivers/gpu/drm/nouveau/nvkm/core/firmware.c
>> > index 34ecd4a..058ff46 100644
>> > --- a/drivers/gpu/drm/nouveau/nvkm/core/firmware.c
>> > +++ b/drivers/gpu/drm/nouveau/nvkm/core/firmware.c
>> > @@ -20,6 +20,7 @@
>> >   * DEALINGS IN THE SOFTWARE.
>> >   */
>> >  #include 
>> > +#include 
>> >
>> >  /**
>> >   * nvkm_firmware_get - load firmware from the official nvidia/chip/
>> > directory
>> > --
>> > 2.7.4
>> >
>> > ___
>> > 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


[Nouveau] [PATCH] nouveau: hide gcc-4.9 -Wmaybe-uninitialized

2016-10-24 Thread Arnd Bergmann
gcc-4.9 notices that the validate_init() function returns unintialized
data when called with a zero 'nr_buffers' argument, when called with the
-Wmaybe-uninitialized flag:

drivers/gpu/drm/nouveau/nouveau_gem.c: In function ‘validate_init.isra.6’:
drivers/gpu/drm/nouveau/nouveau_gem.c:457:5: error: ‘ret’ may be used 
uninitialized in this function [-Werror=maybe-uninitialized]

However, the only caller of this function always passes a nonzero
argument, and gcc-6 is clever enough to take this into account and
not warn about it any more.

Adding an explicit initialization to -EINVAL here is correct even if
the caller changed, and it avoids the warning on gcc-4.9 as well.

Signed-off-by: Arnd Bergmann 
---
 drivers/gpu/drm/nouveau/nouveau_gem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c 
b/drivers/gpu/drm/nouveau/nouveau_gem.c
index 0bd7164bc817..4f3c5f3eaa16 100644
--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
@@ -369,7 +369,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file 
*file_priv,
 {
struct nouveau_cli *cli = nouveau_cli(file_priv);
int trycnt = 0;
-   int ret, i;
+   int ret = -EINVAL, i;
struct nouveau_bo *res_bo = NULL;
LIST_HEAD(gart_list);
LIST_HEAD(vram_list);
-- 
2.9.0

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [Bug 98398] Acer Aspire V7-582PG (Haswell, GTX 750M) fails to power off GPU with runtime PM

2016-10-24 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=98398

--- Comment #9 from rick.2...@gmail.com ---
Sure, I'll have another test run with 4.7 this week.

-- 
You are receiving this mail because:
You are the assignee for the bug.___
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [Bug 98398] Acer Aspire V7-582PG (Haswell, GTX 750M) fails to power off GPU with runtime PM

2016-10-24 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=98398

Peter Wu  changed:

   What|Removed |Added

Summary|[Nouveau] Vgaswitcharoo |Acer Aspire V7-582PG
   |fails to turn off GPU   |(Haswell, GTX 750M) fails
   |properly|to power off GPU with
   ||runtime PM
 CC||pe...@lekensteyn.nl

--- Comment #8 from Peter Wu  ---
Pablo, the issues that bbswitch has is different from the one reported here.
bbswitch is not updated for 4.8 requiring the pcie_port_pm=off workaround.

There are more details for this bug from the reporter in IRC (search for
NanoSector):
https://people.freedesktop.org/~cbrill/dri-log/index.php?channel=nouveau=2016-10-22

In particular, Rick reported that the issue apparently also appears with older
kernels, including 4.3 to 4.8. This is significant and a surprising result
because kernel 4.8 plus pcie_port_pm=off (or the d3cold_allowed change) should
have the same result as 4.7 or before. Rick, can you re-test it with 4.7?

It also occurs to me that older kernels might not support your GPU, so be sure
to keep a dmesg around.

-- 
You are receiving this mail because:
You are the assignee for the bug.___
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [PATCH 01/17] drm/nouveau/core: add missing header dependencies

2016-10-24 Thread Baoyou Xie
On 23 October 2016 at 01:32, Karol Herbst  wrote:

> I think it would be better to squash those commits:
> 1. for the includes
> 2. for static declerations
>
> OK, I have resent new patch that squash those commits.


> 2016-10-22 11:41 GMT+02:00 Baoyou Xie :
> > We get 2 warnings when building kernel with W=1:
> > drivers/gpu/drm/nouveau/nvkm/core/firmware.c:34:1: warning: no previous
> prototype for 'nvkm_firmware_get' [-Wmissing-prototypes]
> > drivers/gpu/drm/nouveau/nvkm/core/firmware.c:58:1: warning: no previous
> prototype for 'nvkm_firmware_put' [-Wmissing-prototypes]
> >
> > In fact, these functions are declared in
> > drivers/gpu/drm/nouveau/include/nvkm/core/firmware.h.
> > So this patch adds missing header dependencies.
> >
> > Signed-off-by: Baoyou Xie 
> > ---
> >  drivers/gpu/drm/nouveau/nvkm/core/firmware.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/gpu/drm/nouveau/nvkm/core/firmware.c
> b/drivers/gpu/drm/nouveau/nvkm/core/firmware.c
> > index 34ecd4a..058ff46 100644
> > --- a/drivers/gpu/drm/nouveau/nvkm/core/firmware.c
> > +++ b/drivers/gpu/drm/nouveau/nvkm/core/firmware.c
> > @@ -20,6 +20,7 @@
> >   * DEALINGS IN THE SOFTWARE.
> >   */
> >  #include 
> > +#include 
> >
> >  /**
> >   * nvkm_firmware_get - load firmware from the official nvidia/chip/
> directory
> > --
> > 2.7.4
> >
> > ___
> > 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


[Nouveau] [Bug 94990] [GM204] GTX 970 + 4GB VRAM fails at secboot (v4.6+)

2016-10-24 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=94990

--- Comment #79 from Karol Herbst  ---
yeah, this would be also the workaround _I_ would suggest, not the other ones
above.

-- 
You are receiving this mail because:
You are the assignee for the bug.___
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [Bug 94990] [GM204] GTX 970 + 4GB VRAM fails at secboot (v4.6+)

2016-10-24 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=94990

--- Comment #78 from Ilia Guterman  ---
Comment on attachment 127508
  --> https://bugs.freedesktop.org/attachment.cgi?id=127508
limit ram to 3 bars

Zach Wolfe: one method is to limit the ram usage, but its a bandage not a fix.

-- 
You are receiving this mail because:
You are the assignee for the bug.___
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [Bug 94990] [GM204] GTX 970 + 4GB VRAM fails at secboot (v4.6+)

2016-10-24 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=94990

--- Comment #77 from Ilia Guterman  ---
Created attachment 127508
  --> https://bugs.freedesktop.org/attachment.cgi?id=127508=edit
limit ram to 3 bars

-- 
You are receiving this mail because:
You are the assignee for the bug.___
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau