[Nouveau] [Bug 92126] [NVE4] GTX 760 Auto fan speed stays at 10% until temp hits 90C

2016-04-18 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=92126

--- Comment #6 from daemon32  ---
(In reply to Karol Herbst from comment #5)
> Is this bug fixed in recent kernels? (4.5 I think?)

Well, sort of, the fan spins up, but it takes off like a jet engine at a mere
50° C. (I'm using your out-of-tree module currently)

-- 
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] [PATCH v4 29/37] clk: we should pass the pstate id around not the index in the list

2016-04-18 Thread Karol Herbst
this makes the code easier, because we can compare the id with pstate->pstate
and safe us the trouble iterating over the entire pstate list

Signed-off-by: Karol Herbst 
---
 drm/nouveau/nouveau_debugfs.c  |  6 ++---
 drm/nouveau/nvkm/subdev/clk/base.c | 49 +++---
 2 files changed, 17 insertions(+), 38 deletions(-)

diff --git a/drm/nouveau/nouveau_debugfs.c b/drm/nouveau/nouveau_debugfs.c
index 31b309f..334b472 100644
--- a/drm/nouveau/nouveau_debugfs.c
+++ b/drm/nouveau/nouveau_debugfs.c
@@ -96,11 +96,11 @@ nouveau_debugfs_pstate_get(struct seq_file *m, void *data)
} while (attr.index);
 
if (state >= 0) {
-   if (info.ustate_ac == state)
+   if (info.ustate_ac == attr.state)
seq_printf(m, " AC");
-   if (info.ustate_dc == state)
+   if (info.ustate_dc == attr.state)
seq_printf(m, " DC");
-   if (info.pstate == state)
+   if (info.pstate == attr.state)
seq_printf(m, " *");
} else {
if (info.ustate_ac < -1)
diff --git a/drm/nouveau/nvkm/subdev/clk/base.c 
b/drm/nouveau/nvkm/subdev/clk/base.c
index 23f4cfe..7f86e41 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -280,23 +280,26 @@ nvkm_cstate_new(struct nvkm_clk *clk, int idx, struct 
nvkm_pstate *pstate)
  * P-States
  */
 static int
-nvkm_pstate_prog(struct nvkm_clk *clk, int pstatei)
+nvkm_pstate_prog(struct nvkm_clk *clk, int pstateid)
 {
struct nvkm_subdev *subdev = >subdev;
struct nvkm_fb *fb = subdev->device->fb;
struct nvkm_pci *pci = subdev->device->pci;
struct nvkm_pstate *pstate;
-   int ret, idx = 0;
+   int ret;
 
-   if (pstatei == -1)
+   if (pstateid == -1)
return 0;
 
list_for_each_entry(pstate, >states, head) {
-   if (idx++ == pstatei)
+   if (pstate->pstate == pstateid)
break;
}
 
-   nvkm_debug(subdev, "setting performance state %d\n", pstatei);
+   if (!pstate)
+   return -EINVAL;
+
+   nvkm_debug(subdev, "setting performance state %x\n", pstateid);
clk->pstate = pstate;
 
nvkm_pcie_set_link(pci, pstate->pcie_speed, pstate->pcie_width);
@@ -496,30 +499,6 @@ nvkm_pstate_new(struct nvkm_clk *clk, int idx)
  * Adjustment triggers
  */
 static int
-nvkm_clk_ustate_update(struct nvkm_clk *clk, int req)
-{
-   struct nvkm_pstate *pstate;
-   int i = 0;
-
-   if (!clk->allow_reclock)
-   return -ENOSYS;
-
-   if (req != -1 && req != -2) {
-   list_for_each_entry(pstate, >states, head) {
-   if (pstate->pstate == req)
-   break;
-   i++;
-   }
-
-   if (pstate->pstate != req)
-   return -EINVAL;
-   req = i;
-   }
-
-   return req + 2;
-}
-
-static int
 nvkm_clk_nstate(struct nvkm_clk *clk, const char *mode, int arglen)
 {
int ret = 1;
@@ -533,23 +512,23 @@ nvkm_clk_nstate(struct nvkm_clk *clk, const char *mode, 
int arglen)
 
((char *)mode)[arglen] = '\0';
if (!kstrtol(mode, 0, )) {
-   ret = nvkm_clk_ustate_update(clk, v);
+   ret = v;
if (ret < 0)
ret = 1;
}
((char *)mode)[arglen] = save;
}
 
-   return ret - 2;
+   return ret;
 }
 
 int
 nvkm_clk_ustate(struct nvkm_clk *clk, int req, int pwr)
 {
-   int ret = nvkm_clk_ustate_update(clk, req);
+   int ret = req;
if (ret >= 0) {
-   if (ret -= 2, pwr) clk->ustate_ac = ret;
-   else   clk->ustate_dc = ret;
+   if (pwr) clk->ustate_ac = ret;
+   else clk->ustate_dc = ret;
clk->exp_cstate = NVKM_CLK_CSTATE_HIGHEST;
return nvkm_clk_update(clk, true);
}
@@ -623,7 +602,7 @@ nvkm_clk_init(struct nvkm_subdev *subdev)
if (clk->func->init)
return clk->func->init(clk);
 
-   clk->astate = clk->state_nr - 1;
+   clk->astate = -1;
clk->pstate = NULL;
clk->exp_cstate = NVKM_CLK_CSTATE_DEFAULT;
clk->set_cstate = NULL;
-- 
2.8.1

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


[Nouveau] [PATCH v4 24/37] debugfs: add boost interface to change the boost_mode

2016-04-18 Thread Karol Herbst
Signed-off-by: Karol Herbst 
Reviewed-by: Martin Peres 
---
 drm/nouveau/nouveau_debugfs.c | 76 +++
 1 file changed, 76 insertions(+)

diff --git a/drm/nouveau/nouveau_debugfs.c b/drm/nouveau/nouveau_debugfs.c
index 3d0dc19..31b309f 100644
--- a/drm/nouveau/nouveau_debugfs.c
+++ b/drm/nouveau/nouveau_debugfs.c
@@ -180,6 +180,81 @@ static const struct file_operations nouveau_pstate_fops = {
.write = nouveau_debugfs_pstate_set,
 };
 
+static void
+nouveau_debugfs_boost_get_entry(struct seq_file *m, u8 mode, u8 entry, u16 
value)
+{
+   if (value) {
+   if (mode == entry)
+   seq_printf(m, "*%i", entry);
+   else
+   seq_printf(m, " %i", entry);
+   seq_printf(m, ": %u MHz\n", value);
+   }
+}
+
+static int
+nouveau_debugfs_boost_get(struct seq_file *m, void *data)
+{
+   struct drm_info_node *node = (struct drm_info_node *) m->private;
+   struct nouveau_debugfs *debugfs = nouveau_debugfs(node->minor->dev);
+   struct nvif_object *ctrl = >ctrl;
+   struct nvif_control_boost_info_v0 info = {};
+   int ret;
+
+   ret = nvif_mthd(ctrl, NVIF_CONTROL_BOOST_INFO, , sizeof(info));
+   if (ret)
+   return ret;
+
+   nouveau_debugfs_boost_get_entry(m, info.mode, 0, info.base_mhz);
+   nouveau_debugfs_boost_get_entry(m, info.mode, 1, info.boost_mhz);
+   nouveau_debugfs_boost_get_entry(m, info.mode, 2, info.max_mhz);
+   return 0;
+}
+
+static ssize_t
+nouveau_debugfs_boost_set(struct file *file, const char __user *ubuf,
+ size_t len, loff_t *offp)
+{
+   struct seq_file *m = file->private_data;
+   struct drm_info_node *node = (struct drm_info_node *) m->private;
+   struct nouveau_debugfs *debugfs = nouveau_debugfs(node->minor->dev);
+   struct nvif_object *ctrl = >ctrl;
+   struct nvif_control_boost_set_v0 args = {};
+   char buf[3] = {};
+   int ret;
+   u8 value;
+
+   if (len >= sizeof(buf))
+   return -EINVAL;
+
+   if (copy_from_user(buf, ubuf, len))
+   return -EFAULT;
+
+   ret = kstrtou8(buf, 10, );
+   if (ret)
+   return ret;
+
+   args.mode = value;
+   ret = nvif_mthd(ctrl, NVIF_CONTROL_BOOST_SET, , sizeof(args));
+   if (ret)
+   return ret;
+
+   return len;
+}
+
+static int
+nouveau_debugfs_boost_open(struct inode *inode, struct file *file)
+{
+   return single_open(file, nouveau_debugfs_boost_get, inode->i_private);
+}
+
+static const struct file_operations nouveau_boost_fops = {
+   .owner = THIS_MODULE,
+   .open = nouveau_debugfs_boost_open,
+   .read = seq_read,
+   .write = nouveau_debugfs_boost_set,
+};
+
 static struct drm_info_list nouveau_debugfs_list[] = {
{ "vbios.rom", nouveau_debugfs_vbios_image, 0, NULL },
 };
@@ -189,6 +264,7 @@ static const struct nouveau_debugfs_files {
const char *name;
const struct file_operations *fops;
 } nouveau_debugfs_files[] = {
+   {"boost", _boost_fops},
{"pstate", _pstate_fops},
 };
 
-- 
2.8.1

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


[Nouveau] [PATCH v4 18/37] volt: add speedo

2016-04-18 Thread Karol Herbst
Signed-off-by: Karol Herbst 
---
 bin/nv_cmp_volt.c  |  2 +-
 drm/nouveau/include/nvkm/subdev/volt.h |  2 ++
 drm/nouveau/nvkm/subdev/volt/base.c| 12 
 drm/nouveau/nvkm/subdev/volt/priv.h|  1 +
 4 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/bin/nv_cmp_volt.c b/bin/nv_cmp_volt.c
index 34147b9..e61056c 100644
--- a/bin/nv_cmp_volt.c
+++ b/bin/nv_cmp_volt.c
@@ -53,7 +53,7 @@ main(int argc, char **argv)
 
ret = u_device("lib", argv[0], "error", true, true,
(1ULL << NVKM_SUBDEV_CLK) |
-//   (1ULL << NVKM_SUBDEV_FUSE) |
+   (1ULL << NVKM_SUBDEV_FUSE) |
(1ULL << NVKM_SUBDEV_GPIO) |
 //   (1ULL << NVKM_SUBDEV_I2C) |
(1ULL << NVKM_SUBDEV_PCI) |
diff --git a/drm/nouveau/include/nvkm/subdev/volt.h 
b/drm/nouveau/include/nvkm/subdev/volt.h
index f223577..4cb0292 100644
--- a/drm/nouveau/include/nvkm/subdev/volt.h
+++ b/drm/nouveau/include/nvkm/subdev/volt.h
@@ -20,6 +20,8 @@ struct nvkm_volt {
u8 max0_id;
u8 max1_id;
u8 max2_id;
+
+   int speedo;
 };
 
 int nvkm_volt_map(struct nvkm_volt *volt, u8 id, u8 temperature);
diff --git a/drm/nouveau/nvkm/subdev/volt/base.c 
b/drm/nouveau/nvkm/subdev/volt/base.c
index 028c6e2..cecfac6 100644
--- a/drm/nouveau/nvkm/subdev/volt/base.c
+++ b/drm/nouveau/nvkm/subdev/volt/base.c
@@ -201,6 +201,14 @@ nvkm_volt_parse_bios(struct nvkm_bios *bios, struct 
nvkm_volt *volt)
 }
 
 static int
+nvkm_volt_speedo_read(struct nvkm_volt *volt)
+{
+   if (volt->func->speedo_read)
+   return volt->func->speedo_read(volt);
+   return -EINVAL;
+}
+
+static int
 nvkm_volt_init(struct nvkm_subdev *subdev)
 {
struct nvkm_volt *volt = nvkm_volt(subdev);
@@ -262,6 +270,10 @@ nvkm_volt_ctor(const struct nvkm_volt_func *func, struct 
nvkm_device *device,
   volt->vid[i].vid, volt->vid[i].uv);
}
}
+
+   volt->speedo = nvkm_volt_speedo_read(volt);
+   if (volt->speedo > 0)
+   nvkm_debug(>subdev, "speedo %x\n", volt->speedo);
 }
 
 int
diff --git a/drm/nouveau/nvkm/subdev/volt/priv.h 
b/drm/nouveau/nvkm/subdev/volt/priv.h
index d5140d9..9b34e9f 100644
--- a/drm/nouveau/nvkm/subdev/volt/priv.h
+++ b/drm/nouveau/nvkm/subdev/volt/priv.h
@@ -14,6 +14,7 @@ struct nvkm_volt_func {
int (*vid_get)(struct nvkm_volt *);
int (*vid_set)(struct nvkm_volt *, u8 vid);
int (*set_id)(struct nvkm_volt *, u8 id, int condition);
+   int (*speedo_read)(struct nvkm_volt *);
 };
 
 int nvkm_voltgpio_init(struct nvkm_volt *);
-- 
2.8.1

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


[Nouveau] [PATCH v4 07/37] volt: add min_id parameter to nvkm_volt_set_id

2016-04-18 Thread Karol Herbst
Each pstate has its own voltage map entry like each cstate has.

The voltages of those entries act as a floor value for the currently selected
pstate and nvidia never sets a voltage below them.

Signed-off-by: Karol Herbst 
Reviewed-by: Martin Peres 
---
 drm/nouveau/include/nvkm/subdev/volt.h | 2 +-
 drm/nouveau/nvkm/subdev/clk/base.c | 6 --
 drm/nouveau/nvkm/subdev/volt/base.c| 5 -
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drm/nouveau/include/nvkm/subdev/volt.h 
b/drm/nouveau/include/nvkm/subdev/volt.h
index 285c6bf..ec9d87d 100644
--- a/drm/nouveau/include/nvkm/subdev/volt.h
+++ b/drm/nouveau/include/nvkm/subdev/volt.h
@@ -24,7 +24,7 @@ struct nvkm_volt {
 
 int nvkm_volt_map_min(struct nvkm_volt *volt, u8 id);
 int nvkm_volt_get(struct nvkm_volt *);
-int nvkm_volt_set_id(struct nvkm_volt *, u8 id, int condition);
+int nvkm_volt_set_id(struct nvkm_volt *, u8 id, u8 min_id, int condition);
 
 int nv40_volt_new(struct nvkm_device *, int, struct nvkm_volt **);
 int gk104_volt_new(struct nvkm_device *, int, struct nvkm_volt **);
diff --git a/drm/nouveau/nvkm/subdev/clk/base.c 
b/drm/nouveau/nvkm/subdev/clk/base.c
index 763e1bf..e2c9fea 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -99,7 +99,8 @@ nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate 
*pstate, int cstatei)
}
 
if (volt) {
-   ret = nvkm_volt_set_id(volt, cstate->voltage, +1);
+   ret = nvkm_volt_set_id(volt, cstate->voltage,
+  pstate->base.voltage, +1);
if (ret && ret != -ENODEV) {
nvkm_error(subdev, "failed to raise voltage: %d\n", 
ret);
return ret;
@@ -113,7 +114,8 @@ nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate 
*pstate, int cstatei)
}
 
if (volt) {
-   ret = nvkm_volt_set_id(volt, cstate->voltage, -1);
+   ret = nvkm_volt_set_id(volt, cstate->voltage,
+  pstate->base.voltage, -1);
if (ret && ret != -ENODEV)
nvkm_error(subdev, "failed to lower voltage: %d\n", 
ret);
}
diff --git a/drm/nouveau/nvkm/subdev/volt/base.c 
b/drm/nouveau/nvkm/subdev/volt/base.c
index 63fffb8..1690c1c 100644
--- a/drm/nouveau/nvkm/subdev/volt/base.c
+++ b/drm/nouveau/nvkm/subdev/volt/base.c
@@ -110,7 +110,7 @@ nvkm_volt_map(struct nvkm_volt *volt, u8 id)
 }
 
 int
-nvkm_volt_set_id(struct nvkm_volt *volt, u8 id, int condition)
+nvkm_volt_set_id(struct nvkm_volt *volt, u8 id, u8 min_id, int condition)
 {
int ret;
 
@@ -123,6 +123,9 @@ nvkm_volt_set_id(struct nvkm_volt *volt, u8 id, int 
condition)
if (!condition || prev < 0 ||
(condition < 0 && ret < prev) ||
(condition > 0 && ret > prev)) {
+   int min = nvkm_volt_map(volt, min_id);
+   if (min >= 0)
+   ret = max(min, ret);
ret = nvkm_volt_set(volt, ret);
} else {
ret = 0;
-- 
2.8.1

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


[Nouveau] [PATCH v4 32/37] clk: only do partial reclocks as required

2016-04-18 Thread Karol Herbst
we don't want to reclock to the same pstate or cstate over and over again, so
only do things we actually have to do.

v4: move into gf100

Signed-off-by: Karol Herbst 
---
 drm/nouveau/nvkm/subdev/clk/base.c  | 11 +--
 drm/nouveau/nvkm/subdev/clk/gf100.c | 62 -
 drm/nouveau/nvkm/subdev/clk/gk104.c |  2 +-
 drm/nouveau/nvkm/subdev/clk/nv40.c  |  3 ++
 drm/nouveau/nvkm/subdev/clk/priv.h  |  4 +++
 5 files changed, 77 insertions(+), 5 deletions(-)

diff --git a/drm/nouveau/nvkm/subdev/clk/base.c 
b/drm/nouveau/nvkm/subdev/clk/base.c
index 3c40f67..2776d79 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -107,7 +107,7 @@ nvkm_cstate_valid(struct nvkm_clk *clk, struct nvkm_cstate 
*cstate, u32 max_volt
   voltage >= volt->min_uv;
 }
 
-static struct nvkm_cstate *
+struct nvkm_cstate *
 nvkm_cstate_find_best(struct nvkm_clk *clk, struct nvkm_pstate *pstate,
  struct nvkm_cstate *start)
 {
@@ -148,7 +148,7 @@ nvkm_cstate_find_best(struct nvkm_clk *clk, struct 
nvkm_pstate *pstate,
return cstate;
 }
 
-static struct nvkm_cstate *
+struct nvkm_cstate *
 nvkm_cstate_get(struct nvkm_clk *clk, struct nvkm_pstate *pstate, int cstatei)
 {
struct nvkm_cstate *cstate;
@@ -168,7 +168,7 @@ nvkm_cstate_get(struct nvkm_clk *clk, struct nvkm_pstate 
*pstate, int cstatei)
return NULL;
 }
 
-static int
+int
 nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate *pstate, int cstatei)
 {
struct nvkm_subdev *subdev = >subdev;
@@ -188,6 +188,11 @@ nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate 
*pstate, int cstatei)
cstate = >base;
}
 
+   if (!cstate) {
+   nvkm_error(subdev, "failed to set cstate %d\n", cstatei);
+   return -EINVAL;
+   }
+
if (therm) {
ret = nvkm_therm_cstate(therm, pstate->fanspeed, +1);
if (ret && ret != -ENODEV) {
diff --git a/drm/nouveau/nvkm/subdev/clk/gf100.c 
b/drm/nouveau/nvkm/subdev/clk/gf100.c
index 808e1ed..5025dcc 100644
--- a/drm/nouveau/nvkm/subdev/clk/gf100.c
+++ b/drm/nouveau/nvkm/subdev/clk/gf100.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct gf100_clk_info {
u32 freq;
@@ -431,13 +432,72 @@ gf100_clk_tidy(struct nvkm_clk *base)
memset(clk->eng, 0x00, sizeof(clk->eng));
 }
 
+static int
+gf100_clk_update_volt(struct nvkm_clk *clk)
+{
+   struct nvkm_subdev *subdev = >subdev;
+   struct nvkm_volt *volt = subdev->device->volt;
+   struct nvkm_therm *therm = subdev->device->therm;
+
+   if (!volt || !therm || !clk->pstate || !clk->set_cstate)
+   return -EINVAL;
+
+   return nvkm_volt_set_id(volt, clk->set_cstate->voltage,
+   clk->pstate->base.voltage, 0);
+}
+
+void
+gf100_clk_update(struct nvkm_clk *clk, int pstate)
+{
+   struct nvkm_subdev *subdev = >subdev;
+   int ret;
+
+   if (!clk->pstate || clk->pstate->pstate != pstate) {
+   nvkm_trace(subdev, "-> P %d\n", pstate);
+   ret = nvkm_pstate_prog(clk, pstate);
+   if (ret) {
+   nvkm_error(subdev, "error setting pstate %d: %d\n",
+  pstate, ret);
+   }
+   } else if (!clk->set_cstate ||
+  clk->set_cstate->cstate != clk->exp_cstate) {
+
+   struct nvkm_cstate *cstate = nvkm_cstate_get(clk, clk->pstate, 
clk->exp_cstate);
+   if (!cstate) {
+   nvkm_error(subdev, "can't find cstate %i\n",
+  clk->exp_cstate);
+   return;
+   }
+
+   cstate = nvkm_cstate_find_best(clk, clk->pstate, cstate);
+   if (!cstate) {
+   nvkm_error(subdev, "can't find best cstate for %i\n",
+  cstate->cstate);
+   return;
+   }
+
+   if (cstate != clk->set_cstate) {
+   nvkm_trace(subdev, "-> C %d\n", cstate->cstate);
+   ret = nvkm_cstate_prog(clk, clk->pstate, 
cstate->cstate);
+   if (ret) {
+   nvkm_error(subdev, "error setting cstate %d: 
%d\n",
+  cstate->cstate, ret);
+   }
+   } else {
+   gf100_clk_update_volt(clk);
+   }
+   } else {
+   gf100_clk_update_volt(clk);
+   }
+}
+
 static const struct nvkm_clk_func
 gf100_clk = {
.read = gf100_clk_read,
.calc = gf100_clk_calc,
.prog = gf100_clk_prog,
.tidy = gf100_clk_tidy,
-   .update = nv40_clk_update,
+   .update = gf100_clk_update,
.domains = {
{ nv_clk_src_crystal, 0xff },
{ nv_clk_src_href  

[Nouveau] [PATCH v4 33/37] therm: trigger reclock in temperature daemon

2016-04-18 Thread Karol Herbst
depending on the temperature, cstates might become unreachable or the maped
voltage of a cstate changes. We want to adjust to that.

Signed-off-by: Karol Herbst 
---
 drm/nouveau/nvkm/subdev/therm/base.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drm/nouveau/nvkm/subdev/therm/base.c 
b/drm/nouveau/nvkm/subdev/therm/base.c
index 0c0feec..566fe5d 100644
--- a/drm/nouveau/nvkm/subdev/therm/base.c
+++ b/drm/nouveau/nvkm/subdev/therm/base.c
@@ -23,6 +23,8 @@
  */
 #include "priv.h"
 
+#include 
+
 int
 nvkm_therm_temp_get(struct nvkm_therm *therm)
 {
@@ -153,7 +155,10 @@ nvkm_therm_alarm(struct nvkm_alarm *alarm)
 {
struct nvkm_therm *therm =
   container_of(alarm, struct nvkm_therm, alarm);
+   struct nvkm_clk *clk = therm->subdev.device->clk;
nvkm_therm_update(therm, -1);
+   if (clk)
+   nvkm_clk_update(clk, false);
 }
 
 int
-- 
2.8.1

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


[Nouveau] [PATCH v4 17/37] bios/vmap: unk0 field is the mode

2016-04-18 Thread Karol Herbst
this selects which formula is used to calculate the voltage.

depending on the value, the entry maps to a different voltage and even enables
if the temperature has any effect or not. This is easy to observe with the
binary driver.

Signed-off-by: Karol Herbst 
---
 drm/nouveau/include/nvkm/subdev/bios/vmap.h | 2 +-
 drm/nouveau/nvkm/subdev/bios/vmap.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drm/nouveau/include/nvkm/subdev/bios/vmap.h 
b/drm/nouveau/include/nvkm/subdev/bios/vmap.h
index ae2f27b..8fa1294 100644
--- a/drm/nouveau/include/nvkm/subdev/bios/vmap.h
+++ b/drm/nouveau/include/nvkm/subdev/bios/vmap.h
@@ -11,7 +11,7 @@ u16 nvbios_vmap_parse(struct nvkm_bios *, u8 *ver, u8 *hdr, 
u8 *cnt, u8 *len,
  struct nvbios_vmap *);
 
 struct nvbios_vmap_entry {
-   u8  unk0;
+   u8  mode;
u8  link;
u32 min;
u32 max;
diff --git a/drm/nouveau/nvkm/subdev/bios/vmap.c 
b/drm/nouveau/nvkm/subdev/bios/vmap.c
index f2295e1..32bd8b1 100644
--- a/drm/nouveau/nvkm/subdev/bios/vmap.c
+++ b/drm/nouveau/nvkm/subdev/bios/vmap.c
@@ -105,7 +105,7 @@ nvbios_vmap_entry_parse(struct nvkm_bios *bios, int idx, u8 
*ver, u8 *len,
info->arg[2] = nvbios_rd32(bios, vmap + 0x10);
break;
case 0x20:
-   info->unk0   = nvbios_rd08(bios, vmap + 0x00);
+   info->mode   = nvbios_rd08(bios, vmap + 0x00);
info->link   = nvbios_rd08(bios, vmap + 0x01);
info->min= nvbios_rd32(bios, vmap + 0x02);
info->max= nvbios_rd32(bios, vmap + 0x06);
-- 
2.8.1

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


[Nouveau] [PATCH v4 15/37] clk: allow boosting only when NvBoost is set

2016-04-18 Thread Karol Herbst
0: base clock from the vbios is max clock
1: boost only to boost clock from the vbios (default)
2: boost to max clock available

v2: moved into nvkm_cstate_valid
v4: check the existence of the clocks before limiting

Signed-off-by: Karol Herbst 
Reviewed-by: Martin Peres 
---
 drm/nouveau/include/nvkm/subdev/clk.h |  9 -
 drm/nouveau/nvkm/subdev/clk/base.c| 33 -
 drm/nouveau/nvkm/subdev/clk/gf100.c   |  2 +-
 drm/nouveau/nvkm/subdev/clk/gk104.c   |  2 +-
 4 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/drm/nouveau/include/nvkm/subdev/clk.h 
b/drm/nouveau/include/nvkm/subdev/clk.h
index 6226f0d..99ee05c 100644
--- a/drm/nouveau/include/nvkm/subdev/clk.h
+++ b/drm/nouveau/include/nvkm/subdev/clk.h
@@ -68,7 +68,8 @@ struct nvkm_pstate {
 struct nvkm_domain {
enum nv_clk_src name;
u8 bios; /* 0xff for none */
-#define NVKM_CLK_DOM_FLAG_CORE 0x01
+#define NVKM_CLK_DOM_FLAG_CORE0x01
+#define NVKM_CLK_DOM_FLAG_BASECLK 0x02
u8 flags;
const char *mname;
int mdiv;
@@ -98,6 +99,12 @@ struct nvkm_clk {
int dstate; /* display adjustment (min+) */
 
bool allow_reclock;
+#define NVKM_CLK_BOOST_NONE 0x0
+#define NVKM_CLK_BOOST_AVG  0x1
+#define NVKM_CLK_BOOST_FULL 0x2
+   u8  boost_mode;
+   u32 base_khz;
+   u32 boost_khz;
 
/*XXX: die, these are here *only* to support the completely
 * bat-shit insane what-was-nouveau_hw.c code
diff --git a/drm/nouveau/nvkm/subdev/clk/base.c 
b/drm/nouveau/nvkm/subdev/clk/base.c
index 21f6369..a9a3666 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -24,6 +24,7 @@
 #include "priv.h"
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -77,9 +78,25 @@ nvkm_clk_adjust(struct nvkm_clk *clk, bool adjust,
 static bool
 nvkm_cstate_valid(struct nvkm_clk *clk, struct nvkm_cstate *cstate, u32 
max_volt, int temp)
 {
+   const struct nvkm_domain *domain = clk->domains;
struct nvkm_volt *volt = clk->subdev.device->volt;
int voltage;
 
+   while (domain && domain->name != nv_clk_src_max) {
+   if (domain->flags & NVKM_CLK_DOM_FLAG_BASECLK) {
+   u32 freq = cstate->domain[domain->name];
+   switch (clk->boost_mode) {
+   case NVKM_CLK_BOOST_NONE:
+   if (clk->base_khz && freq > clk->base_khz)
+   return false;
+   case NVKM_CLK_BOOST_AVG:
+   if (clk->boost_khz && freq > clk->boost_khz)
+   return false;
+   }
+   }
+   domain++;
+   }
+
if (!volt)
return true;
 
@@ -641,10 +658,24 @@ int
 nvkm_clk_ctor(const struct nvkm_clk_func *func, struct nvkm_device *device,
  int index, bool allow_reclock, struct nvkm_clk *clk)
 {
+   struct nvkm_subdev *subdev = >subdev;
+   struct nvkm_bios *bios = device->bios;
int ret, idx, arglen;
const char *mode;
+   struct nvbios_baseclk_header h;
+
+   nvkm_subdev_ctor(_clk, device, index, subdev);
+
+   clk->boost_mode = nvkm_longopt(device->cfgopt, "NvBoost",
+  NVKM_CLK_BOOST_AVG);
+   if (bios && !nvbios_baseclock_parse(bios, )) {
+   struct nvbios_baseclk_entry base, boost;
+   if (!nvbios_baseclock_entry(bios, , h.boost_id, ))
+   clk->boost_khz = boost.clock_mhz * 1000;
+   if (!nvbios_baseclock_entry(bios, , h.base_id, ))
+   clk->base_khz = base.clock_mhz * 1000;
+   }
 
-   nvkm_subdev_ctor(_clk, device, index, >subdev);
clk->func = func;
INIT_LIST_HEAD(>states);
clk->domains = func->domains;
diff --git a/drm/nouveau/nvkm/subdev/clk/gf100.c 
b/drm/nouveau/nvkm/subdev/clk/gf100.c
index 78c449b..71b7c9f 100644
--- a/drm/nouveau/nvkm/subdev/clk/gf100.c
+++ b/drm/nouveau/nvkm/subdev/clk/gf100.c
@@ -443,7 +443,7 @@ gf100_clk = {
{ nv_clk_src_hubk06 , 0x00 },
{ nv_clk_src_hubk01 , 0x01 },
{ nv_clk_src_copy   , 0x02 },
-   { nv_clk_src_gpc, 0x03, 0, "core", 2000 },
+   { nv_clk_src_gpc, 0x03, NVKM_CLK_DOM_FLAG_BASECLK, "core", 
2000 },
{ nv_clk_src_rop, 0x04 },
{ nv_clk_src_mem, 0x05, 0, "memory", 1000 },
{ nv_clk_src_vdec   , 0x06 },
diff --git a/drm/nouveau/nvkm/subdev/clk/gk104.c 
b/drm/nouveau/nvkm/subdev/clk/gk104.c
index 975c401..639234f 100644
--- a/drm/nouveau/nvkm/subdev/clk/gk104.c
+++ b/drm/nouveau/nvkm/subdev/clk/gk104.c
@@ -485,7 +485,7 @@ gk104_clk = {
.domains = {
{ nv_clk_src_crystal, 0xff },
{ nv_clk_src_href   , 0xff },
-  

[Nouveau] [PATCH v4 10/37] add daemon to compare nouveau with blob voltage

2016-04-18 Thread Karol Herbst
this tool can be run alongside the nvidia driver to print information about
the current p/cstate, which voltage was set by nvidia and what nouveau would
set in the same situation.

v4: parse default options

Signed-off-by: Karol Herbst 
---
 bin/nv_cmp_volt.c | 139 ++
 1 file changed, 139 insertions(+)
 create mode 100644 bin/nv_cmp_volt.c

diff --git a/bin/nv_cmp_volt.c b/bin/nv_cmp_volt.c
new file mode 100644
index 000..c63d91b
--- /dev/null
+++ b/bin/nv_cmp_volt.c
@@ -0,0 +1,139 @@
+/*
+ * 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 
+
+#include 
+
+#include "util.h"
+
+int
+main(int argc, char **argv)
+{
+   struct nvif_client if_client;
+   struct nvif_device if_device;
+   struct nvkm_clk *clk;
+   struct nvkm_volt *volt;
+   struct nvkm_device *device;
+   int ret, c;
+   int old_voltage = 0, old_nouveau_voltage = 0, old_pstate = 0;
+   int old_cstate = 0, old_temp = 0;
+
+   while ((c = getopt(argc, argv, U_GETOPT)) != -1) {
+   switch (c) {
+   default:
+   if (!u_option(c))
+   return 1;
+   break;
+   }
+   }
+
+   ret = u_device("lib", argv[0], "error", true, true,
+   (1ULL << NVKM_SUBDEV_CLK) |
+//   (1ULL << NVKM_SUBDEV_FUSE) |
+   (1ULL << NVKM_SUBDEV_GPIO) |
+//   (1ULL << NVKM_SUBDEV_I2C) |
+   (1ULL << NVKM_SUBDEV_PCI) |
+//   (1ULL << NVKM_SUBDEV_THERM) |
+//   (1ULL << NVKM_SUBDEV_TIMER) |
+   (1ULL << NVKM_SUBDEV_VBIOS) |
+   (1ULL << NVKM_SUBDEV_VOLT),
+   0x, _client, _device);
+
+   if (ret < 0)
+   return ret;
+
+   device = nvxx_device(_device);
+   clk = device->clk;
+// therm = device->therm;
+   volt = device->volt;
+
+   printf("current voltage (µV), expected voltage (µV), abs diff (µV),"
+  "rel diff nouveau/nvidia (%%), pstate, cstate, temperature"
+  "(°C)\n");
+   while (true) {
+   int gpc_clock = nvkm_clk_read(clk, nv_clk_src_gpc);
+   int mem_clock = nvkm_clk_read(clk, nv_clk_src_mem);
+   struct nvkm_pstate *pstate = NULL, *best_pstate = NULL;
+   struct nvkm_cstate *cstate = NULL, *best_cstate = NULL;
+   int mem_err, gpc_err;
+   int new_voltage, new_nouveau_voltage, new_pstate, new_cstate;
+   int new_temp;
+
+   list_for_each_entry(pstate, >states, head) {
+   list_for_each_entry(cstate, >list, head) {
+   if (!best_pstate) {
+   best_pstate = pstate;
+   best_cstate = cstate;
+   gpc_err = 
abs(cstate->domain[nv_clk_src_gpc] - gpc_clock);
+   mem_err = 
abs(cstate->domain[nv_clk_src_mem] - mem_clock);
+   continue;
+   }
+
+   if (abs(cstate->domain[nv_clk_src_gpc] - 
gpc_clock) <= gpc_err &&
+   abs(cstate->domain[nv_clk_src_mem] - 
mem_clock) <= mem_err) {
+   best_pstate = pstate;
+   best_cstate = cstate;
+   gpc_err = 
abs(cstate->domain[nv_clk_src_gpc] - gpc_clock);
+   mem_err = 
abs(cstate->domain[nv_clk_src_mem] - mem_clock);
+   }
+   }
+
+  

[Nouveau] [PATCH v4 05/37] clk: don't create cstates whit voltages higher than what the gpu can do

2016-04-18 Thread Karol Herbst
Signed-off-by: Karol Herbst 
Reviewed-by: Martin Peres 
Tested-by: Pierre Moreau 
---
 drm/nouveau/nvkm/subdev/clk/base.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drm/nouveau/nvkm/subdev/clk/base.c 
b/drm/nouveau/nvkm/subdev/clk/base.c
index 7102c25..763e1bf 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -138,6 +138,7 @@ static int
 nvkm_cstate_new(struct nvkm_clk *clk, int idx, struct nvkm_pstate *pstate)
 {
struct nvkm_bios *bios = clk->subdev.device->bios;
+   struct nvkm_volt *volt = clk->subdev.device->volt;
const struct nvkm_domain *domain = clk->domains;
struct nvkm_cstate *cstate = NULL;
struct nvbios_cstepX cstepX;
@@ -148,6 +149,9 @@ nvkm_cstate_new(struct nvkm_clk *clk, int idx, struct 
nvkm_pstate *pstate)
if (!data)
return -ENOENT;
 
+   if (volt && nvkm_volt_map_min(volt, cstepX.voltage) > volt->max_uv)
+   return -EINVAL;
+
cstate = kzalloc(sizeof(*cstate), GFP_KERNEL);
if (!cstate)
return -ENOMEM;
-- 
2.8.1

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


[Nouveau] [PATCH v4 34/37] mc: fix NULL pointer access in libnouveau

2016-04-18 Thread Karol Herbst
Signed-off-by: Karol Herbst 
---
 drm/nouveau/nvkm/subdev/mc/base.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drm/nouveau/nvkm/subdev/mc/base.c 
b/drm/nouveau/nvkm/subdev/mc/base.c
index aa394af..88bc1cc 100644
--- a/drm/nouveau/nvkm/subdev/mc/base.c
+++ b/drm/nouveau/nvkm/subdev/mc/base.c
@@ -90,10 +90,15 @@ nvkm_mc_intr(struct nvkm_mc *mc, bool *handled)
 void
 nvkm_mc_reset(struct nvkm_mc *mc, enum nvkm_devidx devidx)
 {
-   struct nvkm_device *device = mc->subdev.device;
+   struct nvkm_device *device;
const struct nvkm_mc_map *map;
u64 pmc_enable;
 
+   if (!mc)
+   return;
+
+   device = mc->subdev.device;
+
if (!(pmc_enable = nvkm_top_reset(device->top, devidx))) {
for (map = mc->func->reset; map && map->stat; map++) {
if (map->unit == devidx) {
-- 
2.8.1

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


[Nouveau] [PATCH v4 14/37] bios: add parsing of BASE CLOCK table

2016-04-18 Thread Karol Herbst
this table contains three important clocks:

base  clock: this is the non boosted max clock
tdp   clock: the clock at wich the vbios guarentees the TDP won't ever be
 exceeded at max load (seems to be always the same as the base
 clock, but behaves differently).
boost clock: the avg clock the gpu will stay boosted to. It doesn't seem to
 affect the behaviour of the nvidia driver at all though.

v2: make clear that base/boost/tdp fields are ids

Signed-off-by: Karol Herbst 
Reviewed-by: Martin Peres 
---
 drm/nouveau/include/nvkm/subdev/bios/baseclock.h | 24 +++
 drm/nouveau/nvkm/subdev/bios/Kbuild  |  1 +
 drm/nouveau/nvkm/subdev/bios/baseclock.c | 82 
 3 files changed, 107 insertions(+)
 create mode 100644 drm/nouveau/include/nvkm/subdev/bios/baseclock.h
 create mode 100644 drm/nouveau/nvkm/subdev/bios/baseclock.c

diff --git a/drm/nouveau/include/nvkm/subdev/bios/baseclock.h 
b/drm/nouveau/include/nvkm/subdev/bios/baseclock.h
new file mode 100644
index 000..ed6a3e6
--- /dev/null
+++ b/drm/nouveau/include/nvkm/subdev/bios/baseclock.h
@@ -0,0 +1,24 @@
+#ifndef __NVBIOS_BASECLOCK_H__
+#define __NVBIOS_BASECLOCK_H__
+struct nvbios_baseclk_header {
+   u16 offset;
+
+   u8 version;
+   u8 hlen;
+   u8 ecount;
+   u8 elen;
+   u8 scount;
+   u8 slen;
+
+   u8 base_id;
+   u8 boost_id;
+   u8 tdp_id;
+};
+struct nvbios_baseclk_entry {
+   u8  pstate;
+   u16 clock_mhz;
+};
+int nvbios_baseclock_parse(struct nvkm_bios *, struct nvbios_baseclk_header *);
+int nvbios_baseclock_entry(struct nvkm_bios *, struct nvbios_baseclk_header *,
+  u8 idx, struct nvbios_baseclk_entry *);
+#endif
diff --git a/drm/nouveau/nvkm/subdev/bios/Kbuild 
b/drm/nouveau/nvkm/subdev/bios/Kbuild
index dbcb0ef..6cb3beb 100644
--- a/drm/nouveau/nvkm/subdev/bios/Kbuild
+++ b/drm/nouveau/nvkm/subdev/bios/Kbuild
@@ -1,4 +1,5 @@
 nvkm-y += nvkm/subdev/bios/base.o
+nvkm-y += nvkm/subdev/bios/baseclock.o
 nvkm-y += nvkm/subdev/bios/bit.o
 nvkm-y += nvkm/subdev/bios/boost.o
 nvkm-y += nvkm/subdev/bios/conn.o
diff --git a/drm/nouveau/nvkm/subdev/bios/baseclock.c 
b/drm/nouveau/nvkm/subdev/bios/baseclock.c
new file mode 100644
index 000..3c961e2
--- /dev/null
+++ b/drm/nouveau/nvkm/subdev/bios/baseclock.c
@@ -0,0 +1,82 @@
+/*
+ * 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 u16
+nvbios_baseclock_offset(struct nvkm_bios *b)
+{
+   struct bit_entry bit_P;
+
+   if (!bit_entry(b, 'P', _P)) {
+   if (bit_P.version == 2)
+   return nvbios_rd16(b, bit_P.offset + 0x38);
+   }
+
+   return 0x;
+}
+
+int
+nvbios_baseclock_parse(struct nvkm_bios *b, struct nvbios_baseclk_header *h)
+{
+   if (!h)
+   return -EINVAL;
+
+   h->offset = nvbios_baseclock_offset(b);
+   if (!h->offset)
+   return -ENODEV;
+
+   h->version = nvbios_rd08(b, h->offset);
+   switch (h->version) {
+   case 0x10:
+   h->hlen = nvbios_rd08(b, h->offset + 0x1);
+   h->elen = nvbios_rd08(b, h->offset + 0x2);
+   h->slen = nvbios_rd08(b, h->offset + 0x3);
+   h->scount   = nvbios_rd08(b, h->offset + 0x4);
+   h->ecount   = nvbios_rd08(b, h->offset + 0x5);
+
+   h->base_id  = nvbios_rd08(b, h->offset + 0x0f);
+   h->boost_id = nvbios_rd08(b, h->offset + 0x10);
+   h->tdp_id   = nvbios_rd08(b, h->offset + 0x11);
+   return 0;
+   default:
+   return -EINVAL;
+   }
+}
+
+int
+nvbios_baseclock_entry(struct nvkm_bios *b, struct nvbios_baseclk_header *h,
+  u8 idx, struct nvbios_baseclk_entry *e)
+{

[Nouveau] [PATCH v4 36/37] WIP volt/gk104: readout speedo

2016-04-18 Thread Karol Herbst
this gk104 volt implementation has to be reworked a little, because the speedo
readout in maxwell doesn't need those strange 0 and 41 writes into 0x122634,
but it needs this PWM thing.

Maybe Maxwell is PWM only and we could just simplify it there, but without
proper knowledge there has some refactoring to be made.

Signed-off-by: Karol Herbst 
---
 drm/nouveau/nvkm/subdev/volt/gk104.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/drm/nouveau/nvkm/subdev/volt/gk104.c 
b/drm/nouveau/nvkm/subdev/volt/gk104.c
index b735173..81788c2 100644
--- a/drm/nouveau/nvkm/subdev/volt/gk104.c
+++ b/drm/nouveau/nvkm/subdev/volt/gk104.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define gk104_volt(p) container_of((p), struct gk104_volt, base)
 struct gk104_volt {
@@ -64,13 +65,31 @@ gk104_volt_set(struct nvkm_volt *base, u32 uv)
return 0;
 }
 
+static int
+gk104_volt_speedo_read(struct nvkm_volt *volt)
+{
+   struct nvkm_device *device = volt->subdev.device;
+   struct nvkm_fuse *fuse = device->fuse;
+   int ret;
+
+   if (!fuse)
+   return -EINVAL;
+
+   nvkm_wr32(device, 0x122634, 0x0);
+   ret = nvkm_fuse_read(fuse, 0x3a8);
+   nvkm_wr32(device, 0x122634, 0x41);
+   return ret;
+}
+
 static const struct nvkm_volt_func
 gk104_volt_pwm = {
.volt_get = gk104_volt_get,
.volt_set = gk104_volt_set,
+   .speedo_read = gk104_volt_speedo_read,
 }, gk104_volt_gpio = {
.vid_get = nvkm_voltgpio_get,
.vid_set = nvkm_voltgpio_set,
+   .speedo_read = gk104_volt_speedo_read,
 };
 
 int
-- 
2.8.1

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


[Nouveau] [PATCH v4 19/37] volt: add gf100 subdev with speedo

2016-04-18 Thread Karol Herbst
Signed-off-by: Karol Herbst 
---
 drm/nouveau/include/nvkm/subdev/volt.h |  1 +
 drm/nouveau/nvkm/engine/device/base.c  | 17 +-
 drm/nouveau/nvkm/subdev/volt/Kbuild|  1 +
 drm/nouveau/nvkm/subdev/volt/gf100.c   | 59 ++
 4 files changed, 70 insertions(+), 8 deletions(-)
 create mode 100644 drm/nouveau/nvkm/subdev/volt/gf100.c

diff --git a/drm/nouveau/include/nvkm/subdev/volt.h 
b/drm/nouveau/include/nvkm/subdev/volt.h
index 4cb0292..25588c7 100644
--- a/drm/nouveau/include/nvkm/subdev/volt.h
+++ b/drm/nouveau/include/nvkm/subdev/volt.h
@@ -30,6 +30,7 @@ int nvkm_volt_get(struct nvkm_volt *);
 int nvkm_volt_set_id(struct nvkm_volt *, u8 id, u8 min_id, int condition);
 
 int nv40_volt_new(struct nvkm_device *, int, struct nvkm_volt **);
+int gf100_volt_new(struct nvkm_device *, int, struct nvkm_volt **);
 int gk104_volt_new(struct nvkm_device *, int, struct nvkm_volt **);
 int gk20a_volt_new(struct nvkm_device *, int, struct nvkm_volt **);
 int gm20b_volt_new(struct nvkm_device *, int, struct nvkm_volt **);
diff --git a/drm/nouveau/nvkm/engine/device/base.c 
b/drm/nouveau/nvkm/engine/device/base.c
index a364efe..528780c 100644
--- a/drm/nouveau/nvkm/engine/device/base.c
+++ b/drm/nouveau/nvkm/engine/device/base.c
@@ -1357,7 +1357,7 @@ nvc0_chipset = {
.pmu = gf100_pmu_new,
.therm = gt215_therm_new,
.timer = nv41_timer_new,
-   .volt = nv40_volt_new,
+   .volt = gf100_volt_new,
.ce[0] = gf100_ce_new,
.ce[1] = gf100_ce_new,
.disp = gt215_disp_new,
@@ -1394,7 +1394,7 @@ nvc1_chipset = {
.pmu = gf100_pmu_new,
.therm = gt215_therm_new,
.timer = nv41_timer_new,
-   .volt = nv40_volt_new,
+   .volt = gf100_volt_new,
.ce[0] = gf100_ce_new,
.disp = gt215_disp_new,
.dma = gf100_dma_new,
@@ -1430,7 +1430,7 @@ nvc3_chipset = {
.pmu = gf100_pmu_new,
.therm = gt215_therm_new,
.timer = nv41_timer_new,
-   .volt = nv40_volt_new,
+   .volt = gf100_volt_new,
.ce[0] = gf100_ce_new,
.disp = gt215_disp_new,
.dma = gf100_dma_new,
@@ -1466,7 +1466,7 @@ nvc4_chipset = {
.pmu = gf100_pmu_new,
.therm = gt215_therm_new,
.timer = nv41_timer_new,
-   .volt = nv40_volt_new,
+   .volt = gf100_volt_new,
.ce[0] = gf100_ce_new,
.ce[1] = gf100_ce_new,
.disp = gt215_disp_new,
@@ -1503,7 +1503,7 @@ nvc8_chipset = {
.pmu = gf100_pmu_new,
.therm = gt215_therm_new,
.timer = nv41_timer_new,
-   .volt = nv40_volt_new,
+   .volt = gf100_volt_new,
.ce[0] = gf100_ce_new,
.ce[1] = gf100_ce_new,
.disp = gt215_disp_new,
@@ -1540,7 +1540,7 @@ nvce_chipset = {
.pmu = gf100_pmu_new,
.therm = gt215_therm_new,
.timer = nv41_timer_new,
-   .volt = nv40_volt_new,
+   .volt = gf100_volt_new,
.ce[0] = gf100_ce_new,
.ce[1] = gf100_ce_new,
.disp = gt215_disp_new,
@@ -1577,7 +1577,7 @@ nvcf_chipset = {
.pmu = gf100_pmu_new,
.therm = gt215_therm_new,
.timer = nv41_timer_new,
-   .volt = nv40_volt_new,
+   .volt = gf100_volt_new,
.ce[0] = gf100_ce_new,
.disp = gt215_disp_new,
.dma = gf100_dma_new,
@@ -1612,6 +1612,7 @@ nvd7_chipset = {
.pci = gf106_pci_new,
.therm = gf119_therm_new,
.timer = nv41_timer_new,
+   .volt = gf100_volt_new,
.ce[0] = gf100_ce_new,
.disp = gf119_disp_new,
.dma = gf119_dma_new,
@@ -1647,7 +1648,7 @@ nvd9_chipset = {
.pmu = gf119_pmu_new,
.therm = gf119_therm_new,
.timer = nv41_timer_new,
-   .volt = nv40_volt_new,
+   .volt = gf100_volt_new,
.ce[0] = gf100_ce_new,
.disp = gf119_disp_new,
.dma = gf119_dma_new,
diff --git a/drm/nouveau/nvkm/subdev/volt/Kbuild 
b/drm/nouveau/nvkm/subdev/volt/Kbuild
index c340762..bcd179b 100644
--- a/drm/nouveau/nvkm/subdev/volt/Kbuild
+++ b/drm/nouveau/nvkm/subdev/volt/Kbuild
@@ -1,6 +1,7 @@
 nvkm-y += nvkm/subdev/volt/base.o
 nvkm-y += nvkm/subdev/volt/gpio.o
 nvkm-y += nvkm/subdev/volt/nv40.o
+nvkm-y += nvkm/subdev/volt/gf100.o
 nvkm-y += nvkm/subdev/volt/gk104.o
 nvkm-y += nvkm/subdev/volt/gk20a.o
 nvkm-y += nvkm/subdev/volt/gm20b.o
diff --git a/drm/nouveau/nvkm/subdev/volt/gf100.c 
b/drm/nouveau/nvkm/subdev/volt/gf100.c
new file mode 100644
index 000..16dc0f1
--- /dev/null
+++ b/drm/nouveau/nvkm/subdev/volt/gf100.c
@@ -0,0 +1,59 @@
+/*
+ * 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

[Nouveau] [PATCH v4 31/37] clk: split out update code to nv40

2016-04-18 Thread Karol Herbst
this code will change for gf100 and newer

Signed-off-by: Karol Herbst 
---
 drm/nouveau/nvkm/subdev/clk/base.c  | 14 ++
 drm/nouveau/nvkm/subdev/clk/g84.c   |  1 +
 drm/nouveau/nvkm/subdev/clk/gf100.c |  1 +
 drm/nouveau/nvkm/subdev/clk/gk104.c |  1 +
 drm/nouveau/nvkm/subdev/clk/gk20a.c |  1 +
 drm/nouveau/nvkm/subdev/clk/gm20b.c |  1 +
 drm/nouveau/nvkm/subdev/clk/gt215.c |  1 +
 drm/nouveau/nvkm/subdev/clk/mcp77.c |  1 +
 drm/nouveau/nvkm/subdev/clk/nv40.c  | 15 +++
 drm/nouveau/nvkm/subdev/clk/nv50.c  |  1 +
 drm/nouveau/nvkm/subdev/clk/priv.h  |  5 +
 11 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/drm/nouveau/nvkm/subdev/clk/base.c 
b/drm/nouveau/nvkm/subdev/clk/base.c
index d6f239f..3c40f67 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -279,7 +279,7 @@ nvkm_cstate_new(struct nvkm_clk *clk, int idx, struct 
nvkm_pstate *pstate)
 /**
  * P-States
  */
-static int
+int
 nvkm_pstate_prog(struct nvkm_clk *clk, int pstateid)
 {
struct nvkm_subdev *subdev = >subdev;
@@ -322,7 +322,10 @@ static void
 nvkm_clk_update_impl(struct nvkm_clk *clk)
 {
struct nvkm_subdev *subdev = >subdev;
-   int pstate, ret;
+   int pstate;
+
+   if (!clk->func->update)
+   return;
 
clk->pwrsrc = power_supply_is_system_supplied();
 
@@ -341,12 +344,7 @@ nvkm_clk_update_impl(struct nvkm_clk *clk)
pstate = -1;
}
 
-   nvkm_trace(subdev, "-> %d\n", pstate);
-   ret = nvkm_pstate_prog(clk, pstate);
-   if (ret) {
-   nvkm_error(subdev, "error setting pstate %d: %d\n",
-  pstate, ret);
-   }
+   clk->func->update(clk, pstate);
 }
 
 static void
diff --git a/drm/nouveau/nvkm/subdev/clk/g84.c 
b/drm/nouveau/nvkm/subdev/clk/g84.c
index f97e3ec..7b9b30d 100644
--- a/drm/nouveau/nvkm/subdev/clk/g84.c
+++ b/drm/nouveau/nvkm/subdev/clk/g84.c
@@ -29,6 +29,7 @@ g84_clk = {
.calc = nv50_clk_calc,
.prog = nv50_clk_prog,
.tidy = nv50_clk_tidy,
+   .update = nv40_clk_update,
.domains = {
{ nv_clk_src_crystal, 0xff },
{ nv_clk_src_href   , 0xff },
diff --git a/drm/nouveau/nvkm/subdev/clk/gf100.c 
b/drm/nouveau/nvkm/subdev/clk/gf100.c
index 71b7c9f..808e1ed 100644
--- a/drm/nouveau/nvkm/subdev/clk/gf100.c
+++ b/drm/nouveau/nvkm/subdev/clk/gf100.c
@@ -437,6 +437,7 @@ gf100_clk = {
.calc = gf100_clk_calc,
.prog = gf100_clk_prog,
.tidy = gf100_clk_tidy,
+   .update = nv40_clk_update,
.domains = {
{ nv_clk_src_crystal, 0xff },
{ nv_clk_src_href   , 0xff },
diff --git a/drm/nouveau/nvkm/subdev/clk/gk104.c 
b/drm/nouveau/nvkm/subdev/clk/gk104.c
index 639234f..8448a88 100644
--- a/drm/nouveau/nvkm/subdev/clk/gk104.c
+++ b/drm/nouveau/nvkm/subdev/clk/gk104.c
@@ -482,6 +482,7 @@ gk104_clk = {
.calc = gk104_clk_calc,
.prog = gk104_clk_prog,
.tidy = gk104_clk_tidy,
+   .update = nv40_clk_update,
.domains = {
{ nv_clk_src_crystal, 0xff },
{ nv_clk_src_href   , 0xff },
diff --git a/drm/nouveau/nvkm/subdev/clk/gk20a.c 
b/drm/nouveau/nvkm/subdev/clk/gk20a.c
index 5f0ee24..8b64cc9 100644
--- a/drm/nouveau/nvkm/subdev/clk/gk20a.c
+++ b/drm/nouveau/nvkm/subdev/clk/gk20a.c
@@ -636,6 +636,7 @@ gk20a_clk = {
.calc = gk20a_clk_calc,
.prog = gk20a_clk_prog,
.tidy = gk20a_clk_tidy,
+   .update = nv40_clk_update,
.pstates = gk20a_pstates,
.nr_pstates = ARRAY_SIZE(gk20a_pstates),
.domains = {
diff --git a/drm/nouveau/nvkm/subdev/clk/gm20b.c 
b/drm/nouveau/nvkm/subdev/clk/gm20b.c
index 71b2bbb..8c8eb8c 100644
--- a/drm/nouveau/nvkm/subdev/clk/gm20b.c
+++ b/drm/nouveau/nvkm/subdev/clk/gm20b.c
@@ -168,6 +168,7 @@ gm20b_clk_speedo0 = {
.calc = gk20a_clk_calc,
.prog = gk20a_clk_prog,
.tidy = gk20a_clk_tidy,
+   .update = nv40_clk_update,
.pstates = gm20b_pstates,
.nr_pstates = ARRAY_SIZE(gm20b_pstates) - 1,
.domains = {
diff --git a/drm/nouveau/nvkm/subdev/clk/gt215.c 
b/drm/nouveau/nvkm/subdev/clk/gt215.c
index 056702e..8913afa 100644
--- a/drm/nouveau/nvkm/subdev/clk/gt215.c
+++ b/drm/nouveau/nvkm/subdev/clk/gt215.c
@@ -520,6 +520,7 @@ gt215_clk = {
.calc = gt215_clk_calc,
.prog = gt215_clk_prog,
.tidy = gt215_clk_tidy,
+   .update = nv40_clk_update,
.domains = {
{ nv_clk_src_crystal  , 0xff },
{ nv_clk_src_core , 0x00, 0, "core", 1000 },
diff --git a/drm/nouveau/nvkm/subdev/clk/mcp77.c 
b/drm/nouveau/nvkm/subdev/clk/mcp77.c
index 1c21b8b..e80b68e 100644
--- a/drm/nouveau/nvkm/subdev/clk/mcp77.c
+++ 

[Nouveau] [PATCH v4 28/37] clk: hold information about the current cstate status

2016-04-18 Thread Karol Herbst
Signed-off-by: Karol Herbst 
---
 drm/nouveau/include/nvkm/subdev/clk.h |  5 +
 drm/nouveau/nvkm/subdev/clk/base.c| 32 +---
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/drm/nouveau/include/nvkm/subdev/clk.h 
b/drm/nouveau/include/nvkm/subdev/clk.h
index 4fb2c1b..6deda96 100644
--- a/drm/nouveau/include/nvkm/subdev/clk.h
+++ b/drm/nouveau/include/nvkm/subdev/clk.h
@@ -95,6 +95,11 @@ struct nvkm_clk {
int ustate_ac; /* user-requested (-1 disabled, -2 perfmon) */
int ustate_dc; /* user-requested (-1 disabled, -2 perfmon) */
int astate; /* perfmon adjustment (base) */
+   struct nvkm_cstate *set_cstate;
+#define NVKM_CLK_CSTATE_DEFAULT -1
+#define NVKM_CLK_CSTATE_BASE-2
+#define NVKM_CLK_CSTATE_HIGHEST -3
+   int exp_cstate;
 
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 762dfe2..23f4cfe 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -152,9 +152,14 @@ static struct nvkm_cstate *
 nvkm_cstate_get(struct nvkm_clk *clk, struct nvkm_pstate *pstate, int cstatei)
 {
struct nvkm_cstate *cstate;
-   if (cstatei == -1)
+   switch (cstatei) {
+   case NVKM_CLK_CSTATE_HIGHEST:
return list_entry(pstate->list.prev, typeof(*cstate), head);
-   else {
+   case NVKM_CLK_CSTATE_BASE:
+   return >base;
+   case NVKM_CLK_CSTATE_DEFAULT:
+   return NULL;
+   default:
list_for_each_entry(cstate, >list, head) {
if (cstate->cstate == cstatei)
return cstate;
@@ -173,6 +178,9 @@ nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate 
*pstate, int cstatei)
struct nvkm_cstate *cstate;
int ret;
 
+   if (cstatei == NVKM_CLK_CSTATE_DEFAULT)
+   return 0;
+
if (!list_empty(>list)) {
cstate = nvkm_cstate_get(clk, pstate, cstatei);
cstate = nvkm_cstate_find_best(clk, pstate, cstate);
@@ -199,6 +207,7 @@ nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate 
*pstate, int cstatei)
 
ret = clk->func->calc(clk, cstate);
if (ret == 0) {
+   clk->set_cstate = cstate;
ret = clk->func->prog(clk);
clk->func->tidy(clk);
}
@@ -303,7 +312,7 @@ nvkm_pstate_prog(struct nvkm_clk *clk, int pstatei)
ram->func->tidy(ram);
}
 
-   return nvkm_cstate_prog(clk, pstate, -1);
+   return nvkm_cstate_prog(clk, pstate, clk->exp_cstate);
 }
 
 static void
@@ -321,9 +330,9 @@ nvkm_clk_update_work(struct work_struct *work)
pstate = clk->pstate->pstate;
else
pstate = -1;
-   nvkm_trace(subdev, "P %d PWR %d U(AC) %d U(DC) %d A %d\n",
+   nvkm_trace(subdev, "P %d PWR %d U(AC) %d U(DC) %d A %d C %d\n",
   pstate, clk->pwrsrc, clk->ustate_ac, clk->ustate_dc,
-  clk->astate);
+  clk->astate, clk->exp_cstate);
 
pstate = clk->pwrsrc ? clk->ustate_ac : clk->ustate_dc;
if (clk->state_nr && pstate != -1) {
@@ -541,6 +550,7 @@ nvkm_clk_ustate(struct nvkm_clk *clk, int req, int pwr)
if (ret >= 0) {
if (ret -= 2, pwr) clk->ustate_ac = ret;
else   clk->ustate_dc = ret;
+   clk->exp_cstate = NVKM_CLK_CSTATE_HIGHEST;
return nvkm_clk_update(clk, true);
}
return ret;
@@ -553,6 +563,7 @@ nvkm_clk_astate(struct nvkm_clk *clk, int req, int rel, 
bool wait)
if ( rel) clk->astate += rel;
clk->astate = min(clk->astate, clk->state_nr - 1);
clk->astate = max(clk->astate, 0);
+   clk->exp_cstate = NVKM_CLK_CSTATE_BASE;
return nvkm_clk_update(clk, wait);
 }
 
@@ -614,6 +625,8 @@ nvkm_clk_init(struct nvkm_subdev *subdev)
 
clk->astate = clk->state_nr - 1;
clk->pstate = NULL;
+   clk->exp_cstate = NVKM_CLK_CSTATE_DEFAULT;
+   clk->set_cstate = NULL;
nvkm_clk_update(clk, true);
return 0;
 }
@@ -698,15 +711,20 @@ nvkm_clk_ctor(const struct nvkm_clk_func *func, struct 
nvkm_device *device,
if (mode) {
clk->ustate_ac = nvkm_clk_nstate(clk, mode, arglen);
clk->ustate_dc = nvkm_clk_nstate(clk, mode, arglen);
+   clk->exp_cstate = NVKM_CLK_CSTATE_HIGHEST;
}
 
mode = nvkm_stropt(device->cfgopt, "NvClkModeAC", );
-   if (mode)
+   if (mode) {
clk->ustate_ac = nvkm_clk_nstate(clk, mode, arglen);
+   clk->exp_cstate = NVKM_CLK_CSTATE_HIGHEST;
+   }
 
mode = nvkm_stropt(device->cfgopt, "NvClkModeDC", );
-   if (mode)
+   if (mode) {
clk->ustate_dc = nvkm_clk_nstate(clk, mode, arglen);
+   

[Nouveau] [PATCH v4 11/37] volt: add temperature parameter to nvkm_volt_map

2016-04-18 Thread Karol Herbst
the voltage entries actually may map to a different voltage depending on the
current temperature.

v2: only read the temperatue when actually needed

Signed-off-by: Karol Herbst 
---
 bin/nv_cmp_volt.c  |  2 +-
 drm/nouveau/include/nvkm/subdev/volt.h |  2 +-
 drm/nouveau/nvkm/subdev/volt/base.c| 14 ++
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/bin/nv_cmp_volt.c b/bin/nv_cmp_volt.c
index c63d91b..34147b9 100644
--- a/bin/nv_cmp_volt.c
+++ b/bin/nv_cmp_volt.c
@@ -117,7 +117,7 @@ main(int argc, char **argv)
 
new_voltage = nvkm_volt_get(volt);
new_temp = nvkm_rd32(device, 
0x20400);//nvkm_therm_temp_get(therm);
-   new_nouveau_voltage = max(nvkm_volt_map(volt, 
best_cstate->voltage), nvkm_volt_map(volt, best_pstate->base.voltage));
+   new_nouveau_voltage = max(nvkm_volt_map(volt, 
best_cstate->voltage, new_temp), nvkm_volt_map(volt, best_pstate->base.voltage, 
new_temp));
new_pstate = best_pstate->pstate;
new_cstate = best_cstate->cstate;
 
diff --git a/drm/nouveau/include/nvkm/subdev/volt.h 
b/drm/nouveau/include/nvkm/subdev/volt.h
index 870d212..f223577 100644
--- a/drm/nouveau/include/nvkm/subdev/volt.h
+++ b/drm/nouveau/include/nvkm/subdev/volt.h
@@ -22,7 +22,7 @@ struct nvkm_volt {
u8 max2_id;
 };
 
-int nvkm_volt_map(struct nvkm_volt *volt, u8 id);
+int nvkm_volt_map(struct nvkm_volt *volt, u8 id, u8 temperature);
 int nvkm_volt_map_min(struct nvkm_volt *volt, u8 id);
 int nvkm_volt_get(struct nvkm_volt *);
 int nvkm_volt_set_id(struct nvkm_volt *, u8 id, u8 min_id, int condition);
diff --git a/drm/nouveau/nvkm/subdev/volt/base.c 
b/drm/nouveau/nvkm/subdev/volt/base.c
index 6fb9d2e..d72bd4a 100644
--- a/drm/nouveau/nvkm/subdev/volt/base.c
+++ b/drm/nouveau/nvkm/subdev/volt/base.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 int
 nvkm_volt_get(struct nvkm_volt *volt)
@@ -88,7 +89,7 @@ nvkm_volt_map_min(struct nvkm_volt *volt, u8 id)
 }
 
 int
-nvkm_volt_map(struct nvkm_volt *volt, u8 id)
+nvkm_volt_map(struct nvkm_volt *volt, u8 id, u8 temp)
 {
struct nvkm_bios *bios = volt->subdev.device->bios;
struct nvbios_vmap_entry info;
@@ -98,7 +99,7 @@ nvkm_volt_map(struct nvkm_volt *volt, u8 id)
vmap = nvbios_vmap_entry_parse(bios, id, , , );
if (vmap) {
if (info.link != 0xff) {
-   int ret = nvkm_volt_map(volt, info.link);
+   int ret = nvkm_volt_map(volt, info.link, temp);
if (ret < 0)
return ret;
info.min += ret;
@@ -112,18 +113,23 @@ nvkm_volt_map(struct nvkm_volt *volt, u8 id)
 int
 nvkm_volt_set_id(struct nvkm_volt *volt, u8 id, u8 min_id, int condition)
 {
+   struct nvkm_therm *therm = volt->subdev.device->therm;
int ret;
+   int temp = 0;
 
if (volt->func->set_id)
return volt->func->set_id(volt, id, condition);
 
-   ret = nvkm_volt_map(volt, id);
+   if (therm)
+   temp = nvkm_therm_temp_get(therm);
+
+   ret = nvkm_volt_map(volt, id, max(temp, 0));
if (ret >= 0) {
int prev = nvkm_volt_get(volt);
if (!condition || prev < 0 ||
(condition < 0 && ret < prev) ||
(condition > 0 && ret > prev)) {
-   int min = nvkm_volt_map(volt, min_id);
+   int min = nvkm_volt_map(volt, min_id, max(temp, 0));
if (min >= 0)
ret = max(min, ret);
ret = nvkm_volt_set(volt, ret);
-- 
2.8.1

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


[Nouveau] [PATCH v4 12/37] clk: fixup cstate selection

2016-04-18 Thread Karol Herbst
now the cstatei parameter can be used of the nvkm_cstate_prog function to
select a specific cstate.

-1 is a magic value, which will always select the highest currently possible
cstate

Signed-off-by: Karol Herbst 
---
 drm/nouveau/nvkm/subdev/clk/base.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drm/nouveau/nvkm/subdev/clk/base.c 
b/drm/nouveau/nvkm/subdev/clk/base.c
index 0eb4c16..fecf58f 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -85,7 +85,15 @@ nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate 
*pstate, int cstatei)
int ret;
 
if (!list_empty(>list)) {
-   cstate = list_entry(pstate->list.prev, typeof(*cstate), head);
+   if (cstatei == -1)
+   cstate = list_entry(pstate->list.prev, typeof(*cstate),
+   head);
+   else {
+   list_for_each_entry(cstate, >list, head) {
+   if (cstate->cstate == cstatei)
+   break;
+   }
+   }
} else {
cstate = >base;
}
@@ -207,7 +215,7 @@ nvkm_pstate_prog(struct nvkm_clk *clk, int pstatei)
ram->func->tidy(ram);
}
 
-   return nvkm_cstate_prog(clk, pstate, 0);
+   return nvkm_cstate_prog(clk, pstate, -1);
 }
 
 static void
-- 
2.8.1

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


[Nouveau] [PATCH v4 37/37] volt: add NvVoltOffsetmV option

2016-04-18 Thread Karol Herbst
This option can be used to adjust the calculated voltage or the cstate voltage
calculation

Signed-off-by: Karol Herbst 
---
 bin/nv_cmp_volt.c  |  2 +-
 drm/nouveau/include/nvkm/subdev/volt.h |  4 +++-
 drm/nouveau/nvkm/subdev/clk/base.c |  8 
 drm/nouveau/nvkm/subdev/volt/base.c| 25 -
 4 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/bin/nv_cmp_volt.c b/bin/nv_cmp_volt.c
index e61056c..d1a0402 100644
--- a/bin/nv_cmp_volt.c
+++ b/bin/nv_cmp_volt.c
@@ -117,7 +117,7 @@ main(int argc, char **argv)
 
new_voltage = nvkm_volt_get(volt);
new_temp = nvkm_rd32(device, 
0x20400);//nvkm_therm_temp_get(therm);
-   new_nouveau_voltage = max(nvkm_volt_map(volt, 
best_cstate->voltage, new_temp), nvkm_volt_map(volt, best_pstate->base.voltage, 
new_temp));
+   new_nouveau_voltage = max(nvkm_volt_map(volt, 
best_cstate->voltage, new_temp, true), nvkm_volt_map(volt, 
best_pstate->base.voltage, new_temp, false));
new_pstate = best_pstate->pstate;
new_cstate = best_cstate->cstate;
 
diff --git a/drm/nouveau/include/nvkm/subdev/volt.h 
b/drm/nouveau/include/nvkm/subdev/volt.h
index 25588c7..f34fd39 100644
--- a/drm/nouveau/include/nvkm/subdev/volt.h
+++ b/drm/nouveau/include/nvkm/subdev/volt.h
@@ -22,9 +22,11 @@ struct nvkm_volt {
u8 max2_id;
 
int speedo;
+
+   int volt_offset_mv;
 };
 
-int nvkm_volt_map(struct nvkm_volt *volt, u8 id, u8 temperature);
+int nvkm_volt_map(struct nvkm_volt *volt, u8 id, u8 temperature, bool 
enableOffset);
 int nvkm_volt_map_min(struct nvkm_volt *volt, u8 id);
 int nvkm_volt_get(struct nvkm_volt *);
 int nvkm_volt_set_id(struct nvkm_volt *, u8 id, u8 min_id, int condition);
diff --git a/drm/nouveau/nvkm/subdev/clk/base.c 
b/drm/nouveau/nvkm/subdev/clk/base.c
index d5440a9..7937155 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -100,7 +100,7 @@ nvkm_cstate_valid(struct nvkm_clk *clk, struct nvkm_cstate 
*cstate, u32 max_volt
if (!volt)
return true;
 
-   voltage = nvkm_volt_map(volt, cstate->voltage, temp);
+   voltage = nvkm_volt_map(volt, cstate->voltage, temp, true);
if (voltage < 0)
return false;
return voltage <= min(max_volt, volt->max_uv) &&
@@ -131,13 +131,13 @@ nvkm_cstate_find_best(struct nvkm_clk *clk, struct 
nvkm_pstate *pstate,
max_volt = volt->max_uv;
if (volt->max0_id != 0xff)
max_volt = min(max_volt,
-  nvkm_volt_map(volt, volt->max0_id, temp));
+  nvkm_volt_map(volt, volt->max0_id, temp, false));
if (volt->max1_id != 0xff)
max_volt = min(max_volt,
-  nvkm_volt_map(volt, volt->max1_id, temp));
+  nvkm_volt_map(volt, volt->max1_id, temp, false));
if (volt->max2_id != 0xff)
max_volt = min(max_volt,
-  nvkm_volt_map(volt, volt->max2_id, temp));
+  nvkm_volt_map(volt, volt->max2_id, temp, false));
 
for (cstate = start; >head != >list;
 cstate = list_entry(cstate->head.prev, typeof(*cstate), head)) {
diff --git a/drm/nouveau/nvkm/subdev/volt/base.c 
b/drm/nouveau/nvkm/subdev/volt/base.c
index 5e35d96..7d5e6c8 100644
--- a/drm/nouveau/nvkm/subdev/volt/base.c
+++ b/drm/nouveau/nvkm/subdev/volt/base.c
@@ -23,6 +23,8 @@
  */
 #include "priv.h"
 
+#include 
+
 #include 
 #include 
 #include 
@@ -100,8 +102,8 @@ nvkm_volt_map_min(struct nvkm_volt *volt, u8 id)
return id ? id * 1 : -ENODEV;
 }
 
-int
-nvkm_volt_map(struct nvkm_volt *volt, u8 id, u8 temp)
+static int
+nvkm_volt_map_impl(struct nvkm_volt *volt, u8 id, u8 temp)
 {
struct nvkm_bios *bios = volt->subdev.device->bios;
struct nvbios_vmap_entry info;
@@ -145,7 +147,7 @@ nvkm_volt_map(struct nvkm_volt *volt, u8 id, u8 temp)
result = min(max(result, (s64)info.min), (s64)info.max);
 
if (info.link != 0xff) {
-   int ret = nvkm_volt_map(volt, info.link, temp);
+   int ret = nvkm_volt_map_impl(volt, info.link, temp);
if (ret < 0)
return ret;
result += ret;
@@ -157,6 +159,15 @@ nvkm_volt_map(struct nvkm_volt *volt, u8 id, u8 temp)
 }
 
 int
+nvkm_volt_map(struct nvkm_volt *volt, u8 id, u8 temp, bool enable_offset)
+{
+   int res = nvkm_volt_map_impl(volt, id, temp);
+   if (enable_offset)
+   res += volt->volt_offset_mv * 1000;
+   return res;
+}
+
+int
 nvkm_volt_set_id(struct nvkm_volt *volt, u8 id, u8 min_id, int condition)
 {
struct nvkm_therm *therm = volt->subdev.device->therm;
@@ -169,13 +180,13 @@ nvkm_volt_set_id(struct nvkm_volt *volt, u8 id, 

[Nouveau] [PATCH v4 27/37] clk: make pstate a pointer to nvkm_pstate

2016-04-18 Thread Karol Herbst
we will access the current set cstate at least every second and this safes us
some CPU cycles looking them up every second.

Signed-off-by: Karol Herbst 
---
 drm/nouveau/include/nvkm/subdev/clk.h |  2 +-
 drm/nouveau/nvkm/engine/device/ctrl.c |  5 -
 drm/nouveau/nvkm/subdev/clk/base.c| 12 
 drm/nouveau/nvkm/subdev/pmu/gk20a.c   | 23 +++
 4 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/drm/nouveau/include/nvkm/subdev/clk.h 
b/drm/nouveau/include/nvkm/subdev/clk.h
index db52e65..4fb2c1b 100644
--- a/drm/nouveau/include/nvkm/subdev/clk.h
+++ b/drm/nouveau/include/nvkm/subdev/clk.h
@@ -91,7 +91,7 @@ struct nvkm_clk {
 
struct nvkm_notify pwrsrc_ntfy;
int pwrsrc;
-   int pstate; /* current */
+   struct nvkm_pstate *pstate; /* current */
int ustate_ac; /* user-requested (-1 disabled, -2 perfmon) */
int ustate_dc; /* user-requested (-1 disabled, -2 perfmon) */
int astate; /* perfmon adjustment (base) */
diff --git a/drm/nouveau/nvkm/engine/device/ctrl.c 
b/drm/nouveau/nvkm/engine/device/ctrl.c
index 039e8a4..cb85266 100644
--- a/drm/nouveau/nvkm/engine/device/ctrl.c
+++ b/drm/nouveau/nvkm/engine/device/ctrl.c
@@ -52,7 +52,10 @@ nvkm_control_mthd_pstate_info(struct nvkm_control *ctrl, 
void *data, u32 size)
args->v0.ustate_ac = clk->ustate_ac;
args->v0.ustate_dc = clk->ustate_dc;
args->v0.pwrsrc = clk->pwrsrc;
-   args->v0.pstate = clk->pstate;
+   if (clk->pstate)
+   args->v0.pstate = clk->pstate->pstate;
+   else
+   args->v0.pstate = -1;
} else {
args->v0.count = 0;
args->v0.ustate_ac = NVIF_CONTROL_PSTATE_INFO_V0_USTATE_DISABLE;
diff --git a/drm/nouveau/nvkm/subdev/clk/base.c 
b/drm/nouveau/nvkm/subdev/clk/base.c
index 3867ab7..762dfe2 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -288,7 +288,7 @@ nvkm_pstate_prog(struct nvkm_clk *clk, int pstatei)
}
 
nvkm_debug(subdev, "setting performance state %d\n", pstatei);
-   clk->pstate = pstatei;
+   clk->pstate = pstate;
 
nvkm_pcie_set_link(pci, pstate->pcie_speed, pstate->pcie_width);
 
@@ -317,15 +317,19 @@ nvkm_clk_update_work(struct work_struct *work)
return;
clk->pwrsrc = power_supply_is_system_supplied();
 
+   if (clk->pstate)
+   pstate = clk->pstate->pstate;
+   else
+   pstate = -1;
nvkm_trace(subdev, "P %d PWR %d U(AC) %d U(DC) %d A %d\n",
-  clk->pstate, clk->pwrsrc, clk->ustate_ac, clk->ustate_dc,
+  pstate, clk->pwrsrc, clk->ustate_ac, clk->ustate_dc,
   clk->astate);
 
pstate = clk->pwrsrc ? clk->ustate_ac : clk->ustate_dc;
if (clk->state_nr && pstate != -1) {
pstate = (pstate < 0) ? clk->astate : pstate;
} else {
-   pstate = clk->pstate = -1;
+   pstate = -1;
}
 
nvkm_trace(subdev, "-> %d\n", pstate);
@@ -609,7 +613,7 @@ nvkm_clk_init(struct nvkm_subdev *subdev)
return clk->func->init(clk);
 
clk->astate = clk->state_nr - 1;
-   clk->pstate = -1;
+   clk->pstate = NULL;
nvkm_clk_update(clk, true);
return 0;
 }
diff --git a/drm/nouveau/nvkm/subdev/pmu/gk20a.c 
b/drm/nouveau/nvkm/subdev/pmu/gk20a.c
index f996d90..6f0d290 100644
--- a/drm/nouveau/nvkm/subdev/pmu/gk20a.c
+++ b/drm/nouveau/nvkm/subdev/pmu/gk20a.c
@@ -57,24 +57,21 @@ gk20a_pmu_dvfs_target(struct gk20a_pmu *pmu, int *state)
 }
 
 static int
-gk20a_pmu_dvfs_get_cur_state(struct gk20a_pmu *pmu, int *state)
-{
-   struct nvkm_clk *clk = pmu->base.subdev.device->clk;
-
-   *state = clk->pstate;
-   return 0;
-}
-
-static int
 gk20a_pmu_dvfs_get_target_state(struct gk20a_pmu *pmu,
int *state, int load)
 {
struct gk20a_pmu_dvfs_data *data = pmu->data;
struct nvkm_clk *clk = pmu->base.subdev.device->clk;
+   struct nvkm_pstate *pstate = clk->pstate;
int cur_level, level;
 
+   if (!pstate) {
+   *state = 0;
+   return 1;
+   }
+
/* For GK20A, the performance level is directly mapped to pstate */
-   level = cur_level = clk->pstate;
+   level = cur_level = clk->pstate->pstate;
 
if (load > data->p_load_max) {
level = min(clk->state_nr - 1, level + (clk->state_nr / 3));
@@ -150,12 +147,6 @@ gk20a_pmu_dvfs_work(struct nvkm_alarm *alarm)
nvkm_trace(subdev, "utilization = %d %%, avg_load = %d %%\n",
   utilization, data->avg_load);
 
-   ret = gk20a_pmu_dvfs_get_cur_state(pmu, );
-   if (ret) {
-   nvkm_warn(subdev, "failed to get current state\n");
-   goto resched;
-   }
-
if 

[Nouveau] [PATCH v4 00/37] Volting/Clocking improvements for Fermi and newer

2016-04-18 Thread Karol Herbst
We are slowly getting there!

v4 of the series with some realy good improvements, so I am sure this is like
95% done and only needs some proper polishing and proper Reviews!

I also added the NvVoltOffsetmV module parameter, so that a user is able to
over and !under!-volt the GPU. Overvolting makes sense, when there are still
some reclocking issues left, which might be solved by a higher voltage.

Undervolting makes sense to decrease the used voltage for each Cstate and to
make more C-States available on a handfull cards. This is some sort of really
basic Overclocking support, which comes at the cost of stability, but has
nearly no impact on the power consumption or heat production.

But because this doesn't add new stuff and only directly modifies the voltage
calculation, it is all still according to the vbios and doesn't add new clocks
or something like that.

If anything is unclear how I REed or got the information, please leave a note
so that I can provide additional information in the commits.

This series can be found on my "stable_reclocking_kepler_v4" branch on github

Happy testing and happy reviewing!

v3: adjust to temperature and minor fixes in the commits
v4: add speedo values
add proper coefficients based on speedo
refactor some code in clk to not affect pre-fermi chips
add NvVoltOffsetmV option

Karol Herbst (37):
  bios/volt: handle voltage table version 0x50 with 0ed header
  volt: properly detect entry based voltage tables
  volt: save the voltage range we are able to set
  volt: add nvkm_volt_map_min function
  clk: don't create cstates whit voltages higher than what the gpu can
do
  volt: parse the max voltage map entries
  volt: add min_id parameter to nvkm_volt_set_id
  clk: export nvkm_volt_map
  clk: add index field to nvkm_cstate
  add daemon to compare nouveau with blob voltage
  volt: add temperature parameter to nvkm_volt_map
  clk: fixup cstate selection
  clk: respect voltage limits in nvkm_cstate_prog
  bios: add parsing of BASE CLOCK table
  clk: allow boosting only when NvBoost is set
  volt: don't require perfect fit
  bios/vmap: unk0 field is the mode
  volt: add speedo
  volt: add gf100 subdev with speedo
  volt: add coefficients
  clk: save the max clock we can set
  clk: rename nvkm_pstate_calc to nvkm_clk_update
  nvif: add boost info and set operations
  debugfs: add boost interface to change the boost_mode
  clk: remove dstate and tstate
  therm: don't cancel the timer
  clk: make pstate a pointer to nvkm_pstate
  clk: hold information about the current cstate status
  clk: we should pass the pstate id around not the index in the list
  clk: seperate the locking from the implementation in nvkm_clk_update
  clk: split out update code to nv40
  clk: only do partial reclocks as required
  therm: trigger reclock in temperature daemon
  mc: fix NULL pointer access in libnouveau
  clk: set clocks to pre suspend state after suspend
  WIP volt/gk104: readout speedo
  volt: add NvVoltOffsetmV option

 bin/nv_cmp_volt.c| 139 +++
 drm/nouveau/include/nvif/if0001.h|  15 ++
 drm/nouveau/include/nvkm/subdev/bios/baseclock.h |  24 ++
 drm/nouveau/include/nvkm/subdev/bios/vmap.h  |   5 +-
 drm/nouveau/include/nvkm/subdev/bios/volt.h  |   5 +-
 drm/nouveau/include/nvkm/subdev/clk.h|  23 +-
 drm/nouveau/include/nvkm/subdev/volt.h   |  17 +-
 drm/nouveau/nouveau_debugfs.c|  82 ++-
 drm/nouveau/nvkm/engine/device/base.c|  17 +-
 drm/nouveau/nvkm/engine/device/ctrl.c|  60 -
 drm/nouveau/nvkm/subdev/bios/Kbuild  |   1 +
 drm/nouveau/nvkm/subdev/bios/baseclock.c |  82 +++
 drm/nouveau/nvkm/subdev/bios/vmap.c  |  12 +-
 drm/nouveau/nvkm/subdev/bios/volt.c  |  45 ++--
 drm/nouveau/nvkm/subdev/clk/base.c   | 298 ---
 drm/nouveau/nvkm/subdev/clk/g84.c|   1 +
 drm/nouveau/nvkm/subdev/clk/gf100.c  |  63 -
 drm/nouveau/nvkm/subdev/clk/gk104.c  |   3 +-
 drm/nouveau/nvkm/subdev/clk/gk20a.c  |   1 +
 drm/nouveau/nvkm/subdev/clk/gm20b.c  |   1 +
 drm/nouveau/nvkm/subdev/clk/gt215.c  |   1 +
 drm/nouveau/nvkm/subdev/clk/mcp77.c  |   1 +
 drm/nouveau/nvkm/subdev/clk/nv40.c   |  18 ++
 drm/nouveau/nvkm/subdev/clk/nv50.c   |   1 +
 drm/nouveau/nvkm/subdev/clk/priv.h   |   9 +
 drm/nouveau/nvkm/subdev/mc/base.c|   7 +-
 drm/nouveau/nvkm/subdev/pmu/gk20a.c  |  23 +-
 drm/nouveau/nvkm/subdev/therm/base.c |  14 +-
 drm/nouveau/nvkm/subdev/volt/Kbuild  |   1 +
 drm/nouveau/nvkm/subdev/volt/base.c  | 159 +++-
 drm/nouveau/nvkm/subdev/volt/gf100.c |  59 +
 drm/nouveau/nvkm/subdev/volt/gk104.c |  19 ++
 drm/nouveau/nvkm/subdev/volt/priv.h  |   1 

[Nouveau] [PATCH v4 08/37] clk: export nvkm_volt_map

2016-04-18 Thread Karol Herbst
before clocking to a cstate, we have to check if the voltage is within the
allowed range.

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

diff --git a/drm/nouveau/include/nvkm/subdev/volt.h 
b/drm/nouveau/include/nvkm/subdev/volt.h
index ec9d87d..870d212 100644
--- a/drm/nouveau/include/nvkm/subdev/volt.h
+++ b/drm/nouveau/include/nvkm/subdev/volt.h
@@ -22,6 +22,7 @@ struct nvkm_volt {
u8 max2_id;
 };
 
+int nvkm_volt_map(struct nvkm_volt *volt, u8 id);
 int nvkm_volt_map_min(struct nvkm_volt *volt, u8 id);
 int nvkm_volt_get(struct nvkm_volt *);
 int nvkm_volt_set_id(struct nvkm_volt *, u8 id, u8 min_id, int condition);
diff --git a/drm/nouveau/nvkm/subdev/volt/base.c 
b/drm/nouveau/nvkm/subdev/volt/base.c
index 1690c1c..6fb9d2e 100644
--- a/drm/nouveau/nvkm/subdev/volt/base.c
+++ b/drm/nouveau/nvkm/subdev/volt/base.c
@@ -87,7 +87,7 @@ nvkm_volt_map_min(struct nvkm_volt *volt, u8 id)
return id ? id * 1 : -ENODEV;
 }
 
-static int
+int
 nvkm_volt_map(struct nvkm_volt *volt, u8 id)
 {
struct nvkm_bios *bios = volt->subdev.device->bios;
-- 
2.8.1

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


[Nouveau] [PATCH v4 20/37] volt: add coefficients

2016-04-18 Thread Karol Herbst
I am sure that those are a bit different, but while testing the biggest error
compared to nvidia was -1.5%.

Without this change we are most of the time around 10% below nvidias voltage,
so this change causes no harm and improves the situation a lot already.

These coefficients were REed by modifing the voltage map entries and by
calculating the set voltage back until I was able to forecast which voltage
nvidia sets for a given voltage map entry.

v4: use better coefficients and speedo

Signed-off-by: Karol Herbst 
---
 drm/nouveau/nvkm/subdev/volt/base.c | 38 +++--
 1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/drm/nouveau/nvkm/subdev/volt/base.c 
b/drm/nouveau/nvkm/subdev/volt/base.c
index cecfac6..5e35d96 100644
--- a/drm/nouveau/nvkm/subdev/volt/base.c
+++ b/drm/nouveau/nvkm/subdev/volt/base.c
@@ -110,13 +110,47 @@ nvkm_volt_map(struct nvkm_volt *volt, u8 id, u8 temp)
 
vmap = nvbios_vmap_entry_parse(bios, id, , , );
if (vmap) {
+   s64 result;
+
+   if (volt->speedo < 0)
+   return volt->speedo;
+
+   if (ver == 0x10 || (ver == 0x20 && info.mode == 0)) {
+   result  =  (s64)info.arg[0] / 10;
+   result += ((s64)info.arg[1] * volt->speedo) / 10;
+   result += ((s64)info.arg[2] * volt->speedo * 
volt->speedo) / 10;
+   } else if (ver == 0x20) {
+   switch (info.mode) {
+   /* 0x0 handled above! */
+   case 0x1:
+   result =  ((s64)info.arg[0] * 15625) >> 18;
+   result += ((s64)info.arg[1] * volt->speedo * 
15625) >> 18;
+   result += ((s64)info.arg[2] * temp * 15625) >> 
10;
+   result += ((s64)info.arg[3] * volt->speedo * 
temp * 15625) >> 18;
+   result += ((s64)info.arg[4] * volt->speedo * 
volt->speedo * 15625) >> 30;
+   result += ((s64)info.arg[5] * temp * temp * 
15625) >> 18;
+   break;
+   case 0x3:
+   result = (info.min + info.max) / 2;
+   break;
+   case 0x2:
+   default:
+   result = info.min;
+   break;
+   }
+   } else {
+   return -ENODEV;
+   }
+
+   result = min(max(result, (s64)info.min), (s64)info.max);
+
if (info.link != 0xff) {
int ret = nvkm_volt_map(volt, info.link, temp);
if (ret < 0)
return ret;
-   info.min += ret;
+   result += ret;
}
-   return info.min;
+   return result;
}
 
return id ? id * 1 : -ENODEV;
-- 
2.8.1

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


[Nouveau] [PATCH v4 26/37] therm: don't cancel the timer

2016-04-18 Thread Karol Herbst
we will need a always running therm daemon to adjust the voltage/clocks on the
fly.

Signed-off-by: Karol Herbst 
---
 drm/nouveau/nvkm/subdev/therm/base.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drm/nouveau/nvkm/subdev/therm/base.c 
b/drm/nouveau/nvkm/subdev/therm/base.c
index 8894fee..0c0feec 100644
--- a/drm/nouveau/nvkm/subdev/therm/base.c
+++ b/drm/nouveau/nvkm/subdev/therm/base.c
@@ -92,7 +92,6 @@ nvkm_therm_update(struct nvkm_therm *therm, int mode)
struct nvkm_timer *tmr = subdev->device->timer;
unsigned long flags;
bool immd = true;
-   bool poll = true;
int duty = -1;
 
spin_lock_irqsave(>lock, flags);
@@ -102,11 +101,9 @@ nvkm_therm_update(struct nvkm_therm *therm, int mode)
 
switch (mode) {
case NVKM_THERM_CTRL_MANUAL:
-   nvkm_timer_alarm_cancel(tmr, >alarm);
duty = nvkm_therm_fan_get(therm);
if (duty < 0)
duty = 100;
-   poll = false;
break;
case NVKM_THERM_CTRL_AUTO:
switch(therm->fan->bios.fan_mode) {
@@ -119,18 +116,16 @@ nvkm_therm_update(struct nvkm_therm *therm, int mode)
case NVBIOS_THERM_FAN_OTHER:
if (therm->cstate)
duty = therm->cstate;
-   poll = false;
break;
}
immd = false;
break;
case NVKM_THERM_CTRL_NONE:
default:
-   nvkm_timer_alarm_cancel(tmr, >alarm);
-   poll = false;
+   break;
}
 
-   if (list_empty(>alarm.head) && poll)
+   if (list_empty(>alarm.head))
nvkm_timer_alarm(tmr, 10ULL, >alarm);
spin_unlock_irqrestore(>lock, flags);
 
-- 
2.8.1

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


[Nouveau] [PATCH v4 23/37] nvif: add boost info and set operations

2016-04-18 Thread Karol Herbst
Signed-off-by: Karol Herbst 
Reviewed-by: Martin Peres 
---
 drm/nouveau/include/nvif/if0001.h | 15 ++
 drm/nouveau/nvkm/engine/device/ctrl.c | 55 +++
 2 files changed, 70 insertions(+)

diff --git a/drm/nouveau/include/nvif/if0001.h 
b/drm/nouveau/include/nvif/if0001.h
index bd5b641..e4acd19 100644
--- a/drm/nouveau/include/nvif/if0001.h
+++ b/drm/nouveau/include/nvif/if0001.h
@@ -4,6 +4,8 @@
 #define NVIF_CONTROL_PSTATE_INFO   0x00
 #define NVIF_CONTROL_PSTATE_ATTR   0x01
 #define NVIF_CONTROL_PSTATE_USER   0x02
+#define NVIF_CONTROL_BOOST_INFO0x03
+#define NVIF_CONTROL_BOOST_SET 0x04
 
 struct nvif_control_pstate_info_v0 {
__u8  version;
@@ -43,4 +45,17 @@ struct nvif_control_pstate_user_v0 {
__s8  pwrsrc; /*  in: target power source */
__u8  pad03[5];
 };
+
+struct nvif_control_boost_info_v0 {
+   __u8  version;
+   __u8  mode;
+   __u16 base_mhz;
+   __u16 boost_mhz;
+   __u16 max_mhz;
+};
+
+struct nvif_control_boost_set_v0 {
+   __u8  version;
+   __u8  mode;
+};
 #endif
diff --git a/drm/nouveau/nvkm/engine/device/ctrl.c 
b/drm/nouveau/nvkm/engine/device/ctrl.c
index b0ece71..039e8a4 100644
--- a/drm/nouveau/nvkm/engine/device/ctrl.c
+++ b/drm/nouveau/nvkm/engine/device/ctrl.c
@@ -167,6 +167,57 @@ nvkm_control_mthd_pstate_user(struct nvkm_control *ctrl, 
void *data, u32 size)
 }
 
 static int
+nvkm_control_mthd_boost_info(struct nvkm_control *ctrl, void *data, u32 size)
+{
+   union {
+   struct nvif_control_boost_info_v0 v0;
+   } *args = data;
+   struct nvkm_clk *clk = ctrl->device->clk;
+   int ret = -ENOSYS;
+
+   nvif_ioctl(>object, "control boost info size %d\n", size);
+   if (!(ret = nvif_unpack(ret, , , args->v0, 0, 0, false))) {
+   nvif_ioctl(>object, "control boost info vers %d\n",
+  args->v0.version);
+   } else
+   return ret;
+
+   if (!clk)
+   return -ENODEV;
+
+   args->v0.mode = clk->boost_mode;
+   args->v0.base_mhz = clk->base_khz / 2000;
+   args->v0.boost_mhz = clk->boost_khz / 2000;
+   args->v0.max_mhz = clk->max_khz / 2000;
+   return 0;
+}
+
+static int
+nvkm_control_mthd_boost_set(struct nvkm_control *ctrl, void *data, u32 size)
+{
+   union {
+   struct nvif_control_boost_set_v0 v0;
+   } *args = data;
+   struct nvkm_clk *clk = ctrl->device->clk;
+   int ret = -ENOSYS;
+
+   nvif_ioctl(>object, "control boost set size %d\n", size);
+   if (!(ret = nvif_unpack(ret, , , args->v0, 0, 0, false))) {
+   nvif_ioctl(>object, "control boost set vers %d\n",
+  args->v0.version);
+   } else
+   return ret;
+
+   if (!clk)
+   return -ENODEV;
+
+   if (args->v0.mode > 2)
+   return -EINVAL;
+   clk->boost_mode = args->v0.mode;
+   return nvkm_clk_update(clk, true);
+}
+
+static int
 nvkm_control_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size)
 {
struct nvkm_control *ctrl = nvkm_control(object);
@@ -177,6 +228,10 @@ nvkm_control_mthd(struct nvkm_object *object, u32 mthd, 
void *data, u32 size)
return nvkm_control_mthd_pstate_attr(ctrl, data, size);
case NVIF_CONTROL_PSTATE_USER:
return nvkm_control_mthd_pstate_user(ctrl, data, size);
+   case NVIF_CONTROL_BOOST_INFO:
+   return nvkm_control_mthd_boost_info(ctrl, data, size);
+   case NVIF_CONTROL_BOOST_SET:
+   return nvkm_control_mthd_boost_set(ctrl, data, size);
default:
break;
}
-- 
2.8.1

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


[Nouveau] [PATCH v4 13/37] clk: respect voltage limits in nvkm_cstate_prog

2016-04-18 Thread Karol Herbst
we should never allow to select a cstate which current voltage (depending on
the temperature) is higher than

1. the max volt entries in the voltage map table
2. what tha gpu actually can volt to.

this resolves all remaining volting errors on fermi and newer.

v3: use find_best for all cstates before actually trying
add nvkm_cstate_get function to get cstate by index

Signed-off-by: Karol Herbst 
---
 drm/nouveau/nvkm/subdev/clk/base.c | 83 +-
 1 file changed, 74 insertions(+), 9 deletions(-)

diff --git a/drm/nouveau/nvkm/subdev/clk/base.c 
b/drm/nouveau/nvkm/subdev/clk/base.c
index fecf58f..21f6369 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -74,6 +74,78 @@ nvkm_clk_adjust(struct nvkm_clk *clk, bool adjust,
 /**
  * C-States
  */
+static bool
+nvkm_cstate_valid(struct nvkm_clk *clk, struct nvkm_cstate *cstate, u32 
max_volt, int temp)
+{
+   struct nvkm_volt *volt = clk->subdev.device->volt;
+   int voltage;
+
+   if (!volt)
+   return true;
+
+   voltage = nvkm_volt_map(volt, cstate->voltage, temp);
+   if (voltage < 0)
+   return false;
+   return voltage <= min(max_volt, volt->max_uv) &&
+  voltage >= volt->min_uv;
+}
+
+static struct nvkm_cstate *
+nvkm_cstate_find_best(struct nvkm_clk *clk, struct nvkm_pstate *pstate,
+ struct nvkm_cstate *start)
+{
+   struct nvkm_device *device = clk->subdev.device;
+   struct nvkm_therm *therm = device->therm;
+   struct nvkm_volt *volt = device->volt;
+   struct nvkm_cstate *cstate;
+   int max_volt, temp = 0;
+
+   if (!pstate || !start)
+   return NULL;
+
+   if (!volt)
+   return start;
+
+   if (therm) {
+   /* ignore error code */
+   temp = max(0, nvkm_therm_temp_get(therm));
+   }
+
+   max_volt = volt->max_uv;
+   if (volt->max0_id != 0xff)
+   max_volt = min(max_volt,
+  nvkm_volt_map(volt, volt->max0_id, temp));
+   if (volt->max1_id != 0xff)
+   max_volt = min(max_volt,
+  nvkm_volt_map(volt, volt->max1_id, temp));
+   if (volt->max2_id != 0xff)
+   max_volt = min(max_volt,
+  nvkm_volt_map(volt, volt->max2_id, temp));
+
+   for (cstate = start; >head != >list;
+cstate = list_entry(cstate->head.prev, typeof(*cstate), head)) {
+   if (nvkm_cstate_valid(clk, cstate, max_volt, temp))
+   break;
+   }
+
+   return cstate;
+}
+
+static struct nvkm_cstate *
+nvkm_cstate_get(struct nvkm_clk *clk, struct nvkm_pstate *pstate, int cstatei)
+{
+   struct nvkm_cstate *cstate;
+   if (cstatei == -1)
+   return list_entry(pstate->list.prev, typeof(*cstate), head);
+   else {
+   list_for_each_entry(cstate, >list, head) {
+   if (cstate->cstate == cstatei)
+   return cstate;
+   }
+   }
+   return NULL;
+}
+
 static int
 nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate *pstate, int cstatei)
 {
@@ -85,15 +157,8 @@ nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate 
*pstate, int cstatei)
int ret;
 
if (!list_empty(>list)) {
-   if (cstatei == -1)
-   cstate = list_entry(pstate->list.prev, typeof(*cstate),
-   head);
-   else {
-   list_for_each_entry(cstate, >list, head) {
-   if (cstate->cstate == cstatei)
-   break;
-   }
-   }
+   cstate = nvkm_cstate_get(clk, pstate, cstatei);
+   cstate = nvkm_cstate_find_best(clk, pstate, cstate);
} else {
cstate = >base;
}
-- 
2.8.1

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


[Nouveau] [PATCH v4 09/37] clk: add index field to nvkm_cstate

2016-04-18 Thread Karol Herbst
Signed-off-by: Karol Herbst 
---
 drm/nouveau/include/nvkm/subdev/clk.h | 1 +
 drm/nouveau/nvkm/subdev/clk/base.c| 1 +
 2 files changed, 2 insertions(+)

diff --git a/drm/nouveau/include/nvkm/subdev/clk.h 
b/drm/nouveau/include/nvkm/subdev/clk.h
index fb54417..6226f0d 100644
--- a/drm/nouveau/include/nvkm/subdev/clk.h
+++ b/drm/nouveau/include/nvkm/subdev/clk.h
@@ -52,6 +52,7 @@ struct nvkm_cstate {
struct list_head head;
u8  voltage;
u32 domain[nv_clk_src_max];
+   u8  cstate;
 };
 
 struct nvkm_pstate {
diff --git a/drm/nouveau/nvkm/subdev/clk/base.c 
b/drm/nouveau/nvkm/subdev/clk/base.c
index e2c9fea..0eb4c16 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -160,6 +160,7 @@ nvkm_cstate_new(struct nvkm_clk *clk, int idx, struct 
nvkm_pstate *pstate)
 
*cstate = pstate->base;
cstate->voltage = cstepX.voltage;
+   cstate->cstate = idx;
 
while (domain && domain->name != nv_clk_src_max) {
if (domain->flags & NVKM_CLK_DOM_FLAG_CORE) {
-- 
2.8.1

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


[Nouveau] [PATCH v4 22/37] clk: rename nvkm_pstate_calc to nvkm_clk_update

2016-04-18 Thread Karol Herbst
this function will be used to update the current clock state.

This will happen for various reasons:
 * temperature changes (may change cstate and/or voltage)
 * user changes boost mode
 * load changes

v2: add wait parameter

Signed-off-by: Karol Herbst 
---
 drm/nouveau/include/nvkm/subdev/clk.h |  1 +
 drm/nouveau/nvkm/subdev/clk/base.c| 46 ---
 2 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/drm/nouveau/include/nvkm/subdev/clk.h 
b/drm/nouveau/include/nvkm/subdev/clk.h
index 61d99fd..77d94c1 100644
--- a/drm/nouveau/include/nvkm/subdev/clk.h
+++ b/drm/nouveau/include/nvkm/subdev/clk.h
@@ -120,6 +120,7 @@ int nvkm_clk_ustate(struct nvkm_clk *, int req, int pwr);
 int nvkm_clk_astate(struct nvkm_clk *, int req, int rel, bool wait);
 int nvkm_clk_dstate(struct nvkm_clk *, int req, int rel);
 int nvkm_clk_tstate(struct nvkm_clk *, int req, int rel);
+int nvkm_clk_update(struct nvkm_clk *, bool wait);
 
 int nv04_clk_new(struct nvkm_device *, int, struct nvkm_clk **);
 int nv40_clk_new(struct nvkm_device *, int, struct nvkm_clk **);
diff --git a/drm/nouveau/nvkm/subdev/clk/base.c 
b/drm/nouveau/nvkm/subdev/clk/base.c
index 1ca25dd..bfc6a49 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -274,11 +274,14 @@ static int
 nvkm_pstate_prog(struct nvkm_clk *clk, int pstatei)
 {
struct nvkm_subdev *subdev = >subdev;
-   struct nvkm_ram *ram = subdev->device->fb->ram;
+   struct nvkm_fb *fb = subdev->device->fb;
struct nvkm_pci *pci = subdev->device->pci;
struct nvkm_pstate *pstate;
int ret, idx = 0;
 
+   if (pstatei == -1)
+   return 0;
+
list_for_each_entry(pstate, >states, head) {
if (idx++ == pstatei)
break;
@@ -289,7 +292,8 @@ nvkm_pstate_prog(struct nvkm_clk *clk, int pstatei)
 
nvkm_pcie_set_link(pci, pstate->pcie_speed, pstate->pcie_width);
 
-   if (ram && ram->func->calc) {
+   if (fb && fb->ram && fb->ram->func->calc) {
+   struct nvkm_ram *ram = fb->ram;
int khz = pstate->base.domain[nv_clk_src_mem];
do {
ret = ram->func->calc(ram, khz);
@@ -303,11 +307,11 @@ nvkm_pstate_prog(struct nvkm_clk *clk, int pstatei)
 }
 
 static void
-nvkm_pstate_work(struct work_struct *work)
+nvkm_clk_update_work(struct work_struct *work)
 {
struct nvkm_clk *clk = container_of(work, typeof(*clk), work);
struct nvkm_subdev *subdev = >subdev;
-   int pstate;
+   int pstate, ret;
 
if (!atomic_xchg(>waiting, 0))
return;
@@ -327,21 +331,25 @@ nvkm_pstate_work(struct work_struct *work)
}
 
nvkm_trace(subdev, "-> %d\n", pstate);
-   if (pstate != clk->pstate) {
-   int ret = nvkm_pstate_prog(clk, pstate);
-   if (ret) {
-   nvkm_error(subdev, "error setting pstate %d: %d\n",
-  pstate, ret);
-   }
+   ret = nvkm_pstate_prog(clk, pstate);
+   if (ret) {
+   nvkm_error(subdev, "error setting pstate %d: %d\n",
+  pstate, ret);
}
 
wake_up_all(>wait);
nvkm_notify_get(>pwrsrc_ntfy);
 }
 
-static int
-nvkm_pstate_calc(struct nvkm_clk *clk, bool wait)
+int
+nvkm_clk_update(struct nvkm_clk *clk, bool wait)
 {
+   if (!clk)
+   return -EINVAL;
+
+   if (!clk->allow_reclock)
+   return -ENODEV;
+
atomic_set(>waiting, 1);
schedule_work(>work);
if (wait)
@@ -531,7 +539,7 @@ nvkm_clk_ustate(struct nvkm_clk *clk, int req, int pwr)
if (ret >= 0) {
if (ret -= 2, pwr) clk->ustate_ac = ret;
else   clk->ustate_dc = ret;
-   return nvkm_pstate_calc(clk, true);
+   return nvkm_clk_update(clk, true);
}
return ret;
 }
@@ -543,7 +551,7 @@ nvkm_clk_astate(struct nvkm_clk *clk, int req, int rel, 
bool wait)
if ( rel) clk->astate += rel;
clk->astate = min(clk->astate, clk->state_nr - 1);
clk->astate = max(clk->astate, 0);
-   return nvkm_pstate_calc(clk, wait);
+   return nvkm_clk_update(clk, wait);
 }
 
 int
@@ -553,7 +561,7 @@ nvkm_clk_tstate(struct nvkm_clk *clk, int req, int rel)
if ( rel) clk->tstate += rel;
clk->tstate = min(clk->tstate, 0);
clk->tstate = max(clk->tstate, -(clk->state_nr - 1));
-   return nvkm_pstate_calc(clk, true);
+   return nvkm_clk_update(clk, true);
 }
 
 int
@@ -563,7 +571,7 @@ nvkm_clk_dstate(struct nvkm_clk *clk, int req, int rel)
if ( rel) clk->dstate += rel;
clk->dstate = min(clk->dstate, clk->state_nr - 1);
clk->dstate = max(clk->dstate, 0);
-   return nvkm_pstate_calc(clk, true);
+   return nvkm_clk_update(clk, true);
 }
 
 static int
@@ -571,7 +579,7 @@ 

[Nouveau] [PATCH v4 06/37] volt: parse the max voltage map entries

2016-04-18 Thread Karol Herbst
There are at least three "max" entries, which specify the max voltage. Because
they are actually normal voltage map entries, they can also be affected by the
temperature.

Nvidia respects those entries and if they get changed, nvidia uses the lower
voltage from both.

We shouldn't exceed those voltages at any given time.

v2: state what those entries do in the source
v3: add the third max entry

Signed-off-by: Karol Herbst 
---
 drm/nouveau/include/nvkm/subdev/bios/vmap.h |  3 +++
 drm/nouveau/include/nvkm/subdev/volt.h  |  5 +
 drm/nouveau/nvkm/subdev/bios/vmap.c | 10 ++
 drm/nouveau/nvkm/subdev/volt/base.c | 13 +
 4 files changed, 31 insertions(+)

diff --git a/drm/nouveau/include/nvkm/subdev/bios/vmap.h 
b/drm/nouveau/include/nvkm/subdev/bios/vmap.h
index 6633c6d..ae2f27b 100644
--- a/drm/nouveau/include/nvkm/subdev/bios/vmap.h
+++ b/drm/nouveau/include/nvkm/subdev/bios/vmap.h
@@ -1,6 +1,9 @@
 #ifndef __NVBIOS_VMAP_H__
 #define __NVBIOS_VMAP_H__
 struct nvbios_vmap {
+   u8  max0;
+   u8  max1;
+   u8  max2;
 };
 
 u16 nvbios_vmap_table(struct nvkm_bios *, u8 *ver, u8 *hdr, u8 *cnt, u8 *len);
diff --git a/drm/nouveau/include/nvkm/subdev/volt.h 
b/drm/nouveau/include/nvkm/subdev/volt.h
index fc68825..285c6bf 100644
--- a/drm/nouveau/include/nvkm/subdev/volt.h
+++ b/drm/nouveau/include/nvkm/subdev/volt.h
@@ -15,6 +15,11 @@ struct nvkm_volt {
 
u32 max_uv;
u32 min_uv;
+
+   /* max voltage map entries, might be affected by temperature */
+   u8 max0_id;
+   u8 max1_id;
+   u8 max2_id;
 };
 
 int nvkm_volt_map_min(struct nvkm_volt *volt, u8 id);
diff --git a/drm/nouveau/nvkm/subdev/bios/vmap.c 
b/drm/nouveau/nvkm/subdev/bios/vmap.c
index 2f13db7..f2295e1 100644
--- a/drm/nouveau/nvkm/subdev/bios/vmap.c
+++ b/drm/nouveau/nvkm/subdev/bios/vmap.c
@@ -61,7 +61,17 @@ nvbios_vmap_parse(struct nvkm_bios *bios, u8 *ver, u8 *hdr, 
u8 *cnt, u8 *len,
memset(info, 0x00, sizeof(*info));
switch (!!vmap * *ver) {
case 0x10:
+   info->max0 = 0xff;
+   info->max1 = 0xff;
+   info->max2 = 0xff;
+   break;
case 0x20:
+   info->max0 = nvbios_rd08(bios, vmap + 0x7);
+   info->max1 = nvbios_rd08(bios, vmap + 0x8);
+   if (*len >= 0xc)
+   info->max2 = nvbios_rd08(bios, vmap + 0xc);
+   else
+   info->max2 = 0xff;
break;
}
return vmap;
diff --git a/drm/nouveau/nvkm/subdev/volt/base.c 
b/drm/nouveau/nvkm/subdev/volt/base.c
index ecf4cb4..63fffb8 100644
--- a/drm/nouveau/nvkm/subdev/volt/base.c
+++ b/drm/nouveau/nvkm/subdev/volt/base.c
@@ -217,9 +217,22 @@ nvkm_volt_ctor(const struct nvkm_volt_func *func, struct 
nvkm_device *device,
 
/* Assuming the non-bios device should build the voltage table later */
if (bios) {
+   u8 ver, hdr, cnt, len;
+   struct nvbios_vmap vmap;
+
nvkm_volt_parse_bios(bios, volt);
nvkm_debug(>subdev, "min: %iuv max: %iuv\n",
   volt->min_uv, volt->max_uv);
+
+   if (nvbios_vmap_parse(bios, , , , , )) {
+   volt->max0_id = vmap.max0;
+   volt->max1_id = vmap.max1;
+   volt->max2_id = vmap.max2;
+   } else {
+   volt->max0_id = 0xff;
+   volt->max1_id = 0xff;
+   volt->max2_id = 0xff;
+   }
}
 
if (volt->vid_nr) {
-- 
2.8.1

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


[Nouveau] [PATCH v4 02/37] volt: properly detect entry based voltage tables

2016-04-18 Thread Karol Herbst
there is a field in the voltage table which tells us if the VIDs are taken from
the entries or calculated through the header.

v2: don't break older versions

Signed-off-by: Karol Herbst 
Reviewed-by: Martin Peres 
Tested-by: Pierre Moreau 
---
 drm/nouveau/include/nvkm/subdev/bios/volt.h |  5 ++--
 drm/nouveau/nvkm/subdev/bios/volt.c | 42 -
 drm/nouveau/nvkm/subdev/volt/base.c |  8 --
 3 files changed, 33 insertions(+), 22 deletions(-)

diff --git a/drm/nouveau/include/nvkm/subdev/bios/volt.h 
b/drm/nouveau/include/nvkm/subdev/bios/volt.h
index b0df610..0d91c24 100644
--- a/drm/nouveau/include/nvkm/subdev/bios/volt.h
+++ b/drm/nouveau/include/nvkm/subdev/bios/volt.h
@@ -13,8 +13,9 @@ struct nvbios_volt {
u32 base;
 
/* GPIO mode */
-   u8  vidmask;
-   s16 step;
+   bool entry_based;
+   u8   vidmask;
+   s16  step;
 
/* PWM mode */
u32 pwm_freq;
diff --git a/drm/nouveau/nvkm/subdev/bios/volt.c 
b/drm/nouveau/nvkm/subdev/bios/volt.c
index 81a47b2..70e1f9d 100644
--- a/drm/nouveau/nvkm/subdev/bios/volt.c
+++ b/drm/nouveau/nvkm/subdev/bios/volt.c
@@ -73,30 +73,34 @@ nvbios_volt_parse(struct nvkm_bios *bios, u8 *ver, u8 *hdr, 
u8 *cnt, u8 *len,
memset(info, 0x00, sizeof(*info));
switch (!!volt * *ver) {
case 0x12:
-   info->type= NVBIOS_VOLT_GPIO;
-   info->vidmask = nvbios_rd08(bios, volt + 0x04);
+   info->type= NVBIOS_VOLT_GPIO;
+   info->vidmask = nvbios_rd08(bios, volt + 0x04);
+   info->entry_based = true;
break;
case 0x20:
-   info->type= NVBIOS_VOLT_GPIO;
-   info->vidmask = nvbios_rd08(bios, volt + 0x05);
+   info->type= NVBIOS_VOLT_GPIO;
+   info->vidmask = nvbios_rd08(bios, volt + 0x05);
+   info->entry_based = true;
break;
case 0x30:
-   info->type= NVBIOS_VOLT_GPIO;
-   info->vidmask = nvbios_rd08(bios, volt + 0x04);
+   info->type= NVBIOS_VOLT_GPIO;
+   info->vidmask = nvbios_rd08(bios, volt + 0x04);
+   info->entry_based = true;
break;
case 0x40:
-   info->type= NVBIOS_VOLT_GPIO;
-   info->base= nvbios_rd32(bios, volt + 0x04);
-   info->step= nvbios_rd16(bios, volt + 0x08);
-   info->vidmask = nvbios_rd08(bios, volt + 0x0b);
+   info->type= NVBIOS_VOLT_GPIO;
+   info->base= nvbios_rd32(bios, volt + 0x04);
+   info->step= nvbios_rd16(bios, volt + 0x08);
+   info->vidmask = nvbios_rd08(bios, volt + 0x0b);
+   info->entry_based = false; /* XXX: find the flag byte */
/*XXX*/
-   info->min = 0;
-   info->max = info->base;
+   info->min = 0;
+   info->max = info->base;
break;
case 0x50:
-   info->min = nvbios_rd32(bios, volt + 0x0a);
-   info->max = nvbios_rd32(bios, volt + 0x0e);
-   info->base= nvbios_rd32(bios, volt + 0x12) & 0x00ff;
+   info->min  = nvbios_rd32(bios, volt + 0x0a);
+   info->max  = nvbios_rd32(bios, volt + 0x0e);
+   info->base = nvbios_rd32(bios, volt + 0x12) & 0x00ff;
 
/* offset 4 seems to be a flag byte */
if (nvbios_rd32(bios, volt + 0x4) & 1) {
@@ -104,9 +108,11 @@ nvbios_volt_parse(struct nvkm_bios *bios, u8 *ver, u8 
*hdr, u8 *cnt, u8 *len,
info->pwm_freq  = nvbios_rd32(bios, volt + 0x5) / 1000;
info->pwm_range = nvbios_rd32(bios, volt + 0x16);
} else {
-   info->type  = NVBIOS_VOLT_GPIO;
-   info->vidmask   = nvbios_rd08(bios, volt + 0x06);
-   info->step  = nvbios_rd16(bios, volt + 0x16);
+   info->type= NVBIOS_VOLT_GPIO;
+   info->vidmask = nvbios_rd08(bios, volt + 0x06);
+   info->step= nvbios_rd16(bios, volt + 0x16);
+   info->entry_based =
+   !(nvbios_rd08(bios, volt + 0x4) & 0x2);
}
break;
}
diff --git a/drm/nouveau/nvkm/subdev/volt/base.c 
b/drm/nouveau/nvkm/subdev/volt/base.c
index 6b2d753..915a605 100644
--- a/drm/nouveau/nvkm/subdev/volt/base.c
+++ b/drm/nouveau/nvkm/subdev/volt/base.c
@@ -112,6 +112,7 @@ nvkm_volt_set_id(struct nvkm_volt *volt, u8 id, int 
condition)
 static void
 nvkm_volt_parse_bios(struct nvkm_bios *bios, struct nvkm_volt *volt)
 {
+   struct nvkm_subdev *subdev = >subdev;

[Nouveau] [PATCH v4 25/37] clk: remove dstate and tstate

2016-04-18 Thread Karol Herbst
we won't need them, because we will adjust the clocks depending on engine loads
later on anyway. It also simplifies the clocking logic.

Signed-off-by: Karol Herbst 
---
 drm/nouveau/include/nvkm/subdev/clk.h |  4 
 drm/nouveau/nvkm/subdev/clk/base.c| 28 ++--
 2 files changed, 2 insertions(+), 30 deletions(-)

diff --git a/drm/nouveau/include/nvkm/subdev/clk.h 
b/drm/nouveau/include/nvkm/subdev/clk.h
index 77d94c1..db52e65 100644
--- a/drm/nouveau/include/nvkm/subdev/clk.h
+++ b/drm/nouveau/include/nvkm/subdev/clk.h
@@ -95,8 +95,6 @@ struct nvkm_clk {
int ustate_ac; /* user-requested (-1 disabled, -2 perfmon) */
int ustate_dc; /* user-requested (-1 disabled, -2 perfmon) */
int astate; /* perfmon adjustment (base) */
-   int tstate; /* thermal adjustment (max-) */
-   int dstate; /* display adjustment (min+) */
 
bool allow_reclock;
 #define NVKM_CLK_BOOST_NONE 0x0
@@ -118,8 +116,6 @@ struct nvkm_clk {
 int nvkm_clk_read(struct nvkm_clk *, enum nv_clk_src);
 int nvkm_clk_ustate(struct nvkm_clk *, int req, int pwr);
 int nvkm_clk_astate(struct nvkm_clk *, int req, int rel, bool wait);
-int nvkm_clk_dstate(struct nvkm_clk *, int req, int rel);
-int nvkm_clk_tstate(struct nvkm_clk *, int req, int rel);
 int nvkm_clk_update(struct nvkm_clk *, bool wait);
 
 int nv04_clk_new(struct nvkm_device *, int, struct nvkm_clk **);
diff --git a/drm/nouveau/nvkm/subdev/clk/base.c 
b/drm/nouveau/nvkm/subdev/clk/base.c
index bfc6a49..3867ab7 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -317,15 +317,13 @@ nvkm_clk_update_work(struct work_struct *work)
return;
clk->pwrsrc = power_supply_is_system_supplied();
 
-   nvkm_trace(subdev, "P %d PWR %d U(AC) %d U(DC) %d A %d T %d D %d\n",
+   nvkm_trace(subdev, "P %d PWR %d U(AC) %d U(DC) %d A %d\n",
   clk->pstate, clk->pwrsrc, clk->ustate_ac, clk->ustate_dc,
-  clk->astate, clk->tstate, clk->dstate);
+  clk->astate);
 
pstate = clk->pwrsrc ? clk->ustate_ac : clk->ustate_dc;
if (clk->state_nr && pstate != -1) {
pstate = (pstate < 0) ? clk->astate : pstate;
-   pstate = min(pstate, clk->state_nr - 1 + clk->tstate);
-   pstate = max(pstate, clk->dstate);
} else {
pstate = clk->pstate = -1;
}
@@ -554,26 +552,6 @@ nvkm_clk_astate(struct nvkm_clk *clk, int req, int rel, 
bool wait)
return nvkm_clk_update(clk, wait);
 }
 
-int
-nvkm_clk_tstate(struct nvkm_clk *clk, int req, int rel)
-{
-   if (!rel) clk->tstate  = req;
-   if ( rel) clk->tstate += rel;
-   clk->tstate = min(clk->tstate, 0);
-   clk->tstate = max(clk->tstate, -(clk->state_nr - 1));
-   return nvkm_clk_update(clk, true);
-}
-
-int
-nvkm_clk_dstate(struct nvkm_clk *clk, int req, int rel)
-{
-   if (!rel) clk->dstate  = req;
-   if ( rel) clk->dstate += rel;
-   clk->dstate = min(clk->dstate, clk->state_nr - 1);
-   clk->dstate = max(clk->dstate, 0);
-   return nvkm_clk_update(clk, true);
-}
-
 static int
 nvkm_clk_pwrsrc(struct nvkm_notify *notify)
 {
@@ -631,8 +609,6 @@ nvkm_clk_init(struct nvkm_subdev *subdev)
return clk->func->init(clk);
 
clk->astate = clk->state_nr - 1;
-   clk->tstate = 0;
-   clk->dstate = 0;
clk->pstate = -1;
nvkm_clk_update(clk, true);
return 0;
-- 
2.8.1

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


[Nouveau] [PATCH v4 21/37] clk: save the max clock we can set

2016-04-18 Thread Karol Herbst
Signed-off-by: Karol Herbst 
---
 drm/nouveau/include/nvkm/subdev/clk.h | 1 +
 drm/nouveau/nvkm/subdev/clk/base.c| 2 ++
 2 files changed, 3 insertions(+)

diff --git a/drm/nouveau/include/nvkm/subdev/clk.h 
b/drm/nouveau/include/nvkm/subdev/clk.h
index 99ee05c..61d99fd 100644
--- a/drm/nouveau/include/nvkm/subdev/clk.h
+++ b/drm/nouveau/include/nvkm/subdev/clk.h
@@ -105,6 +105,7 @@ struct nvkm_clk {
u8  boost_mode;
u32 base_khz;
u32 boost_khz;
+   u32 max_khz;
 
/*XXX: die, these are here *only* to support the completely
 * bat-shit insane what-was-nouveau_hw.c code
diff --git a/drm/nouveau/nvkm/subdev/clk/base.c 
b/drm/nouveau/nvkm/subdev/clk/base.c
index a9a3666..1ca25dd 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -257,6 +257,8 @@ nvkm_cstate_new(struct nvkm_clk *clk, int idx, struct 
nvkm_pstate *pstate)
u32 freq = nvkm_clk_adjust(clk, true, pstate->pstate,
   domain->bios, cstepX.freq);
cstate->domain[domain->name] = freq;
+   if (domain->flags & NVKM_CLK_DOM_FLAG_BASECLK)
+   clk->max_khz = max(clk->max_khz, freq);
}
domain++;
}
-- 
2.8.1

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


[Nouveau] [PATCH v4 04/37] volt: add nvkm_volt_map_min function

2016-04-18 Thread Karol Herbst
this is a copy of nvkm_volt_map, which always returns the lowest possible
voltage for a cstate.

nvkm_volt_map will get a temperature parameter there later and also fix the
voltage calculation, so that this functions will be completly different later.

Signed-off-by: Karol Herbst 
Reviewed-by: Martin Peres 
Tested-by: Pierre Moreau 
---
 drm/nouveau/include/nvkm/subdev/volt.h |  1 +
 drm/nouveau/nvkm/subdev/volt/base.c| 22 ++
 2 files changed, 23 insertions(+)

diff --git a/drm/nouveau/include/nvkm/subdev/volt.h 
b/drm/nouveau/include/nvkm/subdev/volt.h
index b765f4f..fc68825 100644
--- a/drm/nouveau/include/nvkm/subdev/volt.h
+++ b/drm/nouveau/include/nvkm/subdev/volt.h
@@ -17,6 +17,7 @@ struct nvkm_volt {
u32 min_uv;
 };
 
+int nvkm_volt_map_min(struct nvkm_volt *volt, u8 id);
 int nvkm_volt_get(struct nvkm_volt *);
 int nvkm_volt_set_id(struct nvkm_volt *, u8 id, int condition);
 
diff --git a/drm/nouveau/nvkm/subdev/volt/base.c 
b/drm/nouveau/nvkm/subdev/volt/base.c
index b7dd3ac..ecf4cb4 100644
--- a/drm/nouveau/nvkm/subdev/volt/base.c
+++ b/drm/nouveau/nvkm/subdev/volt/base.c
@@ -65,6 +65,28 @@ nvkm_volt_set(struct nvkm_volt *volt, u32 uv)
return ret;
 }
 
+int
+nvkm_volt_map_min(struct nvkm_volt *volt, u8 id)
+{
+   struct nvkm_bios *bios = volt->subdev.device->bios;
+   struct nvbios_vmap_entry info;
+   u8  ver, len;
+   u16 vmap;
+
+   vmap = nvbios_vmap_entry_parse(bios, id, , , );
+   if (vmap) {
+   if (info.link != 0xff) {
+   int ret = nvkm_volt_map_min(volt, info.link);
+   if (ret < 0)
+   return ret;
+   info.min += ret;
+   }
+   return info.min;
+   }
+
+   return id ? id * 1 : -ENODEV;
+}
+
 static int
 nvkm_volt_map(struct nvkm_volt *volt, u8 id)
 {
-- 
2.8.1

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


[Nouveau] [PATCH v4 03/37] volt: save the voltage range we are able to set

2016-04-18 Thread Karol Herbst
We shouldn't set voltages below the min or above the max voltage the gpu is
able to set, so save the range.

Signed-off-by: Karol Herbst 
Reviewed-by: Martin Peres 
Tested-by: Pierre Moreau 
---
 drm/nouveau/include/nvkm/subdev/volt.h |  3 +++
 drm/nouveau/nvkm/subdev/volt/base.c| 14 +-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/drm/nouveau/include/nvkm/subdev/volt.h 
b/drm/nouveau/include/nvkm/subdev/volt.h
index feff55c..b765f4f 100644
--- a/drm/nouveau/include/nvkm/subdev/volt.h
+++ b/drm/nouveau/include/nvkm/subdev/volt.h
@@ -12,6 +12,9 @@ struct nvkm_volt {
u32 uv;
u8 vid;
} vid[256];
+
+   u32 max_uv;
+   u32 min_uv;
 };
 
 int nvkm_volt_get(struct nvkm_volt *);
diff --git a/drm/nouveau/nvkm/subdev/volt/base.c 
b/drm/nouveau/nvkm/subdev/volt/base.c
index 915a605..b7dd3ac 100644
--- a/drm/nouveau/nvkm/subdev/volt/base.c
+++ b/drm/nouveau/nvkm/subdev/volt/base.c
@@ -123,6 +123,8 @@ nvkm_volt_parse_bios(struct nvkm_bios *bios, struct 
nvkm_volt *volt)
if (data && info.vidmask && info.base && info.step
&& !info.entry_based) {
nvkm_debug(subdev, "found header based VIDs\n");
+   volt->min_uv = info.min;
+   volt->max_uv = info.max;
for (i = 0; i < info.vidmask + 1; i++) {
if (info.base >= info.min &&
info.base <= info.max) {
@@ -135,6 +137,8 @@ nvkm_volt_parse_bios(struct nvkm_bios *bios, struct 
nvkm_volt *volt)
volt->vid_mask = info.vidmask;
} else if (data && info.vidmask && info.entry_based) {
nvkm_debug(subdev, "found entry based VIDs\n");
+   volt->min_uv = 0x;
+   volt->max_uv = 0;
for (i = 0; i < cnt; i++) {
data = nvbios_volt_entry_parse(bios, i, , ,
   );
@@ -142,9 +146,14 @@ nvkm_volt_parse_bios(struct nvkm_bios *bios, struct 
nvkm_volt *volt)
volt->vid[volt->vid_nr].uv = ivid.voltage;
volt->vid[volt->vid_nr].vid = ivid.vid;
volt->vid_nr++;
+   volt->min_uv = min(volt->min_uv, ivid.voltage);
+   volt->max_uv = max(volt->max_uv, ivid.voltage);
}
}
volt->vid_mask = info.vidmask;
+   } else if (data && info.type == NVBIOS_VOLT_PWM) {
+   volt->min_uv = info.base;
+   volt->max_uv = info.base + info.pwm_range;
}
 }
 
@@ -185,8 +194,11 @@ nvkm_volt_ctor(const struct nvkm_volt_func *func, struct 
nvkm_device *device,
volt->func = func;
 
/* Assuming the non-bios device should build the voltage table later */
-   if (bios)
+   if (bios) {
nvkm_volt_parse_bios(bios, volt);
+   nvkm_debug(>subdev, "min: %iuv max: %iuv\n",
+  volt->min_uv, volt->max_uv);
+   }
 
if (volt->vid_nr) {
for (i = 0; i < volt->vid_nr; i++) {
-- 
2.8.1

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


[Nouveau] [Bug 91523] [NVE7] driver cannot initialize gpu(failed to parse ramcfg data)

2016-04-18 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=91523

--- Comment #4 from Ilia Bozhinov  ---
I tested a kernel build with the relevant code commented(right after the
comment I posted) and indeed the kernel module works! (it loads and DRI_PRIME=1
allows me to run glxgears/glxinfo). What is more, now I get better power
savings because when driver is loaded vgaswitcheroo can turn off the nvidia
card.

-- 
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] Latest 4.6rc4 kernel, no booting on gtx970

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

--- Comment #1 from Ilia Mirkin  ---
Does it work fine on a cold boot, but only fails on a warm boot? (Is that what
you mean by "after rebooting"?)

-- 
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] New: Latest 4.6rc4 kernel, no booting on gtx970

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

Bug ID: 94990
   Summary: Latest 4.6rc4 kernel, no booting on gtx970
   Product: xorg
   Version: git
  Hardware: Other
OS: All
Status: NEW
  Severity: normal
  Priority: medium
 Component: Driver/nouveau
  Assignee: nouveau@lists.freedesktop.org
  Reporter: mirkorol...@googlemail.com
QA Contact: xorg-t...@lists.x.org

Created attachment 123026
  --> https://bugs.freedesktop.org/attachment.cgi?id=123026=edit
dmesg

Hi Iam testing the latest 4.6rc4 kernel and the nouveau kernel module. I
installed the latest /lib/firmware from git.   After rebooting, screen goes
black, monitor goes to sleep.

Hardware ASUS Z97 Mainboard
Nvidia GTX970


2.587816] nouveau :01:00.0: fifo: read fault at 00ffba engine 1f []
client 12 [PMU] reason 0d [REGION_VIOLATION] on channel -1 [00 unknown]
[2.687724] nouveau :01:00.0: timeout at
drivers/gpu/drm/nouveau/nvkm/subdev/secboot/base.c:145/nvkm_secboot_falcon_run()!
[2.687736] nouveau :01:00.0: fifo: write fault at 30d000 engine 05
[BAR3] client 08 [HOST_CPU_NB] reason 0d [REGION_VIOLATION] on channel -1
[00ffbf5000 unknown]
[2.687752] nouveau :01:00.0: fifo: write fault at 011000 engine 05
[BAR3] client 08 [HOST_CPU_NB] reason 0d [REGION_VIOLATION] on channel -1
[00ffbf5000 unknown]


Full dmesg output:
http://pastebin.com/pWD1wuTL

-- 
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] GM108GLM?

2016-04-18 Thread Sune Mølgaard
Is there anything I can do in this regard?

/smo

On 2016-03-31 23:12, Pierre Moreau wrote:
> Oh, hum, GM108 is NV118 and not NV108 which is Gk208… My bad!
> 
> SMF from the bug report seemed to have some working setup, and since he didn't
> pinged back, I guess it's working nicely. But some more checking might still 
> be
> needed?
> 
> On 04:59 PM - Mar 31 2016, Ilia Mirkin wrote:
>> Actually GM108 is not one of the recognized chips. Someone needs to go
>> through and check that its goldens didn't change. Nobody's done that.
>>
>> See https://bugs.freedesktop.org/show_bug.cgi?id=89558
>>
>> On Thu, Mar 31, 2016 at 4:57 PM, Pierre Moreau  wrote:
>>> Hello,
>>>
>>> Acceleration support for GM107 was merged in kernel 4.1, and modesetting
>>> support was added to 3.15. Which kernel version did you try? The GM108 
>>> chipset
>>> seems to be recognised since at least 2015/08/20.
>>>
>>> Regards,
>>>
>>> Pierre Moreau
>>>
>>>
>>> On 02:55 PM - Mar 29 2016, Sune Mølgaard wrote:
 Hiya,

 Is there any change for Quadro K620M support at some point in time, and
 what can I do to help, apart from the info below?

 Best regards,

 Sune Mølgaard

 dmesg |grep -i nouveau
 [1.164919] nouveau :08:00.0: unknown chipset (1183a0a2)
 [1.164943] nouveau: probe of :08:00.0 failed with error -12

 lspci|grep -i nvidi
 08:00.0 3D controller: NVIDIA Corporation GM108GLM [Quadro K620M] (rev a2)
 ___
 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 mailing list
>> Nouveau@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/nouveau




signature.asc
Description: OpenPGP digital signature
___
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau