[05/32] clk: Improve names of pstate/cstate related variables and fields

Submitted by Karol Herbst on Nov. 17, 2017, 12:04 a.m.

Details

Message ID 20171117000436.2432-6-karolherbst@gmail.com
State New
Headers show
Series "Updated State of my clk patches" ( rev: 1 ) in Nouveau

Not browsing as part of any series.

Commit Message

Karol Herbst Nov. 17, 2017, 12:04 a.m.
From: Karol Herbst <kherbst@redhat.com>

id: id of the state
idx: index of the state inside the parent list
pstate/cstate: the struct itself

Signed-off-by: Karol Herbst <kherbst@redhat.com>
---
 drm/nouveau/include/nvkm/subdev/bios/boost.h |  2 +-
 drm/nouveau/include/nvkm/subdev/bios/perf.h  |  2 +-
 drm/nouveau/include/nvkm/subdev/clk.h        |  4 +-
 drm/nouveau/nouveau_debugfs.c                | 14 +++---
 drm/nouveau/nvkm/engine/device/ctrl.c        |  4 +-
 drm/nouveau/nvkm/subdev/bios/boost.c         | 11 +++--
 drm/nouveau/nvkm/subdev/bios/perf.c          |  2 +-
 drm/nouveau/nvkm/subdev/clk/base.c           | 70 ++++++++++++++--------------
 drm/nouveau/nvkm/subdev/clk/gk20a.c          |  2 +-
 drm/nouveau/nvkm/subdev/pmu/gk20a.c          |  4 +-
 10 files changed, 59 insertions(+), 56 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drm/nouveau/include/nvkm/subdev/bios/boost.h b/drm/nouveau/include/nvkm/subdev/bios/boost.h
index 2ff64a20..74791349 100644
--- a/drm/nouveau/include/nvkm/subdev/bios/boost.h
+++ b/drm/nouveau/include/nvkm/subdev/bios/boost.h
@@ -3,7 +3,7 @@ 
 u32 nvbios_boostTe(struct nvkm_bios *, u8 *, u8 *, u8 *, u8 *, u8 *, u8 *);
 
 struct nvbios_boostE {
-	u8  pstate;
+	u8  pstate_id;
 	u32 min;
 	u32 max;
 };
diff --git a/drm/nouveau/include/nvkm/subdev/bios/perf.h b/drm/nouveau/include/nvkm/subdev/bios/perf.h
index 478b1c0d..69800168 100644
--- a/drm/nouveau/include/nvkm/subdev/bios/perf.h
+++ b/drm/nouveau/include/nvkm/subdev/bios/perf.h
@@ -4,7 +4,7 @@  u32 nvbios_perf_table(struct nvkm_bios *, u8 *ver, u8 *hdr,
 		      u8 *cnt, u8 *len, u8 *snr, u8 *ssz);
 
 struct nvbios_perfE {
-	u8  pstate;
+	u8  pstate_id;
 	u8  fanspeed;
 	u8  voltage;
 	u32 core;
diff --git a/drm/nouveau/include/nvkm/subdev/clk.h b/drm/nouveau/include/nvkm/subdev/clk.h
index 506f8cc6..1f4fa5f5 100644
--- a/drm/nouveau/include/nvkm/subdev/clk.h
+++ b/drm/nouveau/include/nvkm/subdev/clk.h
@@ -63,7 +63,7 @@  struct nvkm_pstate {
 	struct list_head head;
 	struct list_head list; /* c-states */
 	struct nvkm_cstate base;
-	u8 pstate;
+	u8 id;
 	u8 fanspeed;
 	enum nvkm_pcie_speed pcie_speed;
 	u8 pcie_width;
@@ -95,7 +95,7 @@  struct nvkm_clk {
 
 	struct nvkm_notify pwrsrc_ntfy;
 	int pwrsrc;
-	int pstate; /* current */
+	int pstate_idx; /* 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/nouveau_debugfs.c b/drm/nouveau/nouveau_debugfs.c
index 9109b69c..df7e2f29 100644
--- a/drm/nouveau/nouveau_debugfs.c
+++ b/drm/nouveau/nouveau_debugfs.c
@@ -63,10 +63,10 @@  nouveau_debugfs_pstate_get(struct seq_file *m, void *data)
 		return ret;
 
 	for (i = 0; i < info.count + 1; i++) {
-		const s32 state = i < info.count ? i :
+		const s32 state_idx = i < info.count ? i :
 			NVIF_CONTROL_PSTATE_ATTR_V0_STATE_CURRENT;
 		struct nvif_control_pstate_attr_v0 attr = {
-			.state = state,
+			.state = state_idx,
 			.index = 0,
 		};
 
@@ -83,7 +83,7 @@  nouveau_debugfs_pstate_get(struct seq_file *m, void *data)
 
 		attr.index = 0;
 		do {
-			attr.state = state;
+			attr.state = state_idx;
 			ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_ATTR,
 					&attr, sizeof(attr));
 			if (ret)
@@ -95,12 +95,12 @@  nouveau_debugfs_pstate_get(struct seq_file *m, void *data)
 			seq_printf(m, " %s", attr.unit);
 		} while (attr.index);
 
-		if (state >= 0) {
-			if (info.ustate_ac == state)
+		if (state_idx >= 0) {
+			if (info.ustate_ac == state_idx)
 				seq_printf(m, " AC");
-			if (info.ustate_dc == state)
+			if (info.ustate_dc == state_idx)
 				seq_printf(m, " DC");
-			if (info.pstate == state)
+			if (info.pstate == state_idx)
 				seq_printf(m, " *");
 		} else {
 			if (info.ustate_ac < -1)
diff --git a/drm/nouveau/nvkm/engine/device/ctrl.c b/drm/nouveau/nvkm/engine/device/ctrl.c
index b0ece71a..e07948e6 100644
--- a/drm/nouveau/nvkm/engine/device/ctrl.c
+++ b/drm/nouveau/nvkm/engine/device/ctrl.c
@@ -52,7 +52,7 @@  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;
+		args->v0.pstate = clk->pstate_idx;
 	} else {
 		args->v0.count = 0;
 		args->v0.ustate_ac = NVIF_CONTROL_PSTATE_INFO_V0_USTATE_DISABLE;
@@ -115,7 +115,7 @@  nvkm_control_mthd_pstate_attr(struct nvkm_control *ctrl, void *data, u32 size)
 			hi = max(hi, cstate->domain[domain->name]);
 		}
 
-		args->v0.state = pstate->pstate;
+		args->v0.state = pstate->id;
 	} else {
 		lo = max(nvkm_clk_read(clk, domain->name), 0);
 		hi = lo;
diff --git a/drm/nouveau/nvkm/subdev/bios/boost.c b/drm/nouveau/nvkm/subdev/bios/boost.c
index 8ab896dd..6554e937 100644
--- a/drm/nouveau/nvkm/subdev/bios/boost.c
+++ b/drm/nouveau/nvkm/subdev/bios/boost.c
@@ -78,20 +78,21 @@  nvbios_boostEp(struct nvkm_bios *bios, int idx,
 	u32 data = nvbios_boostEe(bios, idx, ver, hdr, cnt, len);
 	memset(info, 0x00, sizeof(*info));
 	if (data) {
-		info->pstate = (nvbios_rd16(bios, data + 0x00) & 0x01e0) >> 5;
-		info->min    =  nvbios_rd16(bios, data + 0x02) * 1000;
-		info->max    =  nvbios_rd16(bios, data + 0x04) * 1000;
+		info->pstate_id =
+			(nvbios_rd16(bios, data + 0x00) & 0x01e0) >> 5;
+		info->min       =  nvbios_rd16(bios, data + 0x02) * 1000;
+		info->max       =  nvbios_rd16(bios, data + 0x04) * 1000;
 	}
 	return data;
 }
 
 u32
-nvbios_boostEm(struct nvkm_bios *bios, u8 pstate,
+nvbios_boostEm(struct nvkm_bios *bios, u8 pstate_id,
 	       u8 *ver, u8 *hdr, u8 *cnt, u8 *len, struct nvbios_boostE *info)
 {
 	u32 data, idx = 0;
 	while ((data = nvbios_boostEp(bios, idx++, ver, hdr, cnt, len, info))) {
-		if (info->pstate == pstate)
+		if (info->pstate_id == pstate_id)
 			break;
 	}
 	return data;
diff --git a/drm/nouveau/nvkm/subdev/bios/perf.c b/drm/nouveau/nvkm/subdev/bios/perf.c
index c3068358..82ba4300 100644
--- a/drm/nouveau/nvkm/subdev/bios/perf.c
+++ b/drm/nouveau/nvkm/subdev/bios/perf.c
@@ -97,7 +97,7 @@  nvbios_perfEp(struct nvkm_bios *bios, int idx,
 {
 	u32 perf = nvbios_perf_entry(bios, idx, ver, hdr, cnt, len);
 	memset(info, 0x00, sizeof(*info));
-	info->pstate = nvbios_rd08(bios, perf + 0x00);
+	info->pstate_id = nvbios_rd08(bios, perf + 0x00);
 	switch (!!perf * *ver) {
 	case 0x12:
 	case 0x13:
diff --git a/drm/nouveau/nvkm/subdev/clk/base.c b/drm/nouveau/nvkm/subdev/clk/base.c
index 0b28dbb9..77a0624a 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -39,14 +39,15 @@ 
  *****************************************************************************/
 static u32
 nvkm_clk_adjust(struct nvkm_clk *clk, bool adjust,
-		u8 pstate, u8 domain, u32 input)
+		u8 pstate_id, u8 domain, u32 input)
 {
 	struct nvkm_bios *bios = clk->subdev.device->bios;
 	struct nvbios_boostE boostE;
 	u8  ver, hdr, cnt, len;
 	u32 data;
 
-	data = nvbios_boostEm(bios, pstate, &ver, &hdr, &cnt, &len, &boostE);
+	data = nvbios_boostEm(bios, pstate_id, &ver, &hdr, &cnt, &len,
+			      &boostE);
 	if (data) {
 		struct nvbios_boostS boostS;
 		u8  idx = 0, sver, shdr;
@@ -143,14 +144,14 @@  nvkm_cstate_find_best(struct nvkm_clk *clk, struct nvkm_pstate *pstate,
 }
 
 static struct nvkm_cstate *
-nvkm_cstate_get(struct nvkm_clk *clk, struct nvkm_pstate *pstate, int cstatei)
+nvkm_cstate_get(struct nvkm_clk *clk, struct nvkm_pstate *pstate, int cstate_id)
 {
 	struct nvkm_cstate *cstate;
-	if (cstatei == NVKM_CLK_CSTATE_HIGHEST)
+	if (cstate_id == NVKM_CLK_CSTATE_HIGHEST)
 		return list_last_entry(&pstate->list, typeof(*cstate), head);
 	else {
 		list_for_each_entry(cstate, &pstate->list, head) {
-			if (cstate->id == cstatei)
+			if (cstate->id == cstate_id)
 				return cstate;
 		}
 	}
@@ -158,7 +159,8 @@  nvkm_cstate_get(struct nvkm_clk *clk, struct nvkm_pstate *pstate, int cstatei)
 }
 
 static int
-nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate *pstate, int cstatei)
+nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate *pstate,
+		 int cstate_id)
 {
 	struct nvkm_subdev *subdev = &clk->subdev;
 	struct nvkm_device *device = subdev->device;
@@ -168,7 +170,7 @@  nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate *pstate, int cstatei)
 	int ret;
 
 	if (!list_empty(&pstate->list)) {
-		cstate = nvkm_cstate_get(clk, pstate, cstatei);
+		cstate = nvkm_cstate_get(clk, pstate, cstate_id);
 		cstate = nvkm_cstate_find_best(clk, pstate, cstate);
 	} else {
 		cstate = &pstate->base;
@@ -248,7 +250,7 @@  nvkm_cstate_new(struct nvkm_clk *clk, int idx, struct nvkm_pstate *pstate)
 
 	while (domain && domain->name != nv_clk_src_max) {
 		if (domain->flags & NVKM_CLK_DOM_FLAG_CORE) {
-			u32 freq = nvkm_clk_adjust(clk, true, pstate->pstate,
+			u32 freq = nvkm_clk_adjust(clk, true, pstate->id,
 						   domain->bios, cstepX.freq);
 			cstate->domain[domain->name] = freq;
 		}
@@ -263,7 +265,7 @@  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 pstate_idx)
 {
 	struct nvkm_subdev *subdev = &clk->subdev;
 	struct nvkm_fb *fb = subdev->device->fb;
@@ -272,12 +274,12 @@  nvkm_pstate_prog(struct nvkm_clk *clk, int pstatei)
 	int ret, idx = 0;
 
 	list_for_each_entry(pstate, &clk->states, head) {
-		if (idx++ == pstatei)
+		if (idx++ == pstate_idx)
 			break;
 	}
 
-	nvkm_debug(subdev, "setting performance state %d\n", pstatei);
-	clk->pstate = pstatei;
+	nvkm_debug(subdev, "setting performance state %d\n", pstate_idx);
+	clk->pstate_idx = pstate_idx;
 
 	nvkm_pcie_set_link(pci, pstate->pcie_speed, pstate->pcie_width);
 
@@ -300,31 +302,31 @@  nvkm_pstate_work(struct work_struct *work)
 {
 	struct nvkm_clk *clk = container_of(work, typeof(*clk), work);
 	struct nvkm_subdev *subdev = &clk->subdev;
-	int pstate;
+	int pstate_idx;
 
 	if (!atomic_xchg(&clk->waiting, 0))
 		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°C D %d\n",
-		   clk->pstate, clk->pwrsrc, clk->ustate_ac, clk->ustate_dc,
+		   clk->pstate_idx, clk->pwrsrc, clk->ustate_ac, clk->ustate_dc,
 		   clk->astate, clk->temp, clk->dstate);
 
-	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);
-		pstate = max(pstate, clk->dstate);
+	pstate_idx = clk->pwrsrc ? clk->ustate_ac : clk->ustate_dc;
+	if (clk->state_nr && pstate_idx != -1) {
+		pstate_idx = (pstate_idx < 0) ? clk->astate : pstate_idx;
+		pstate_idx = min(pstate_idx, clk->state_nr - 1);
+		pstate_idx = max(pstate_idx, clk->dstate);
 	} else {
-		pstate = clk->pstate = -1;
+		pstate_idx = clk->pstate_idx = -1;
 	}
 
-	nvkm_trace(subdev, "-> %d\n", pstate);
-	if (pstate != clk->pstate) {
-		int ret = nvkm_pstate_prog(clk, pstate);
+	nvkm_trace(subdev, "-> %d\n", pstate_idx);
+	if (pstate_idx != clk->pstate_idx) {
+		int ret = nvkm_pstate_prog(clk, pstate_idx);
 		if (ret) {
 			nvkm_error(subdev, "error setting pstate %d: %d\n",
-				   pstate, ret);
+				   pstate_idx, ret);
 		}
 	}
 
@@ -352,8 +354,8 @@  nvkm_pstate_info(struct nvkm_clk *clk, struct nvkm_pstate *pstate)
 	char name[4] = "--";
 	int i = -1;
 
-	if (pstate->pstate != 0xff)
-		snprintf(name, sizeof(name), "%02x", pstate->pstate);
+	if (pstate->id != 0xff)
+		snprintf(name, sizeof(name), "%02x", pstate->id);
 
 	while ((++clock)->name != nv_clk_src_max) {
 		u32 lo = pstate->base.domain[clock->name];
@@ -413,7 +415,7 @@  nvkm_pstate_new(struct nvkm_clk *clk, int idx)
 	data = nvbios_perfEp(bios, idx, &ver, &hdr, &cnt, &len, &perfE);
 	if (!data)
 		return -EINVAL;
-	if (perfE.pstate == 0xff)
+	if (perfE.pstate_id == 0xff)
 		return 0;
 
 	pstate = kzalloc(sizeof(*pstate), GFP_KERNEL);
@@ -423,7 +425,7 @@  nvkm_pstate_new(struct nvkm_clk *clk, int idx)
 
 	INIT_LIST_HEAD(&pstate->list);
 
-	pstate->pstate = perfE.pstate;
+	pstate->id = perfE.pstate_id;
 	pstate->fanspeed = perfE.fanspeed;
 	pstate->pcie_speed = perfE.pcie_speed;
 	pstate->pcie_width = perfE.pcie_width;
@@ -444,7 +446,7 @@  nvkm_pstate_new(struct nvkm_clk *clk, int idx)
 
 		if (domain->flags & NVKM_CLK_DOM_FLAG_CORE) {
 			perfS.v40.freq = nvkm_clk_adjust(clk, false,
-							 pstate->pstate,
+							 pstate->id,
 							 domain->bios,
 							 perfS.v40.freq);
 		}
@@ -452,7 +454,7 @@  nvkm_pstate_new(struct nvkm_clk *clk, int idx)
 		cstate->domain[domain->name] = perfS.v40.freq;
 	}
 
-	data = nvbios_cstepEm(bios, pstate->pstate, &ver, &hdr, &cstepE);
+	data = nvbios_cstepEm(bios, pstate->id, &ver, &hdr, &cstepE);
 	if (data) {
 		int idx = cstepE.index;
 		do {
@@ -480,12 +482,12 @@  nvkm_clk_ustate_update(struct nvkm_clk *clk, int req)
 
 	if (req != -1 && req != -2) {
 		list_for_each_entry(pstate, &clk->states, head) {
-			if (pstate->pstate == req)
+			if (pstate->id == req)
 				break;
 			i++;
 		}
 
-		if (pstate->pstate != req)
+		if (pstate->id != req)
 			return -EINVAL;
 		req = i;
 	}
@@ -597,7 +599,7 @@  nvkm_clk_init(struct nvkm_subdev *subdev)
 
 	memset(&clk->bstate, 0x00, sizeof(clk->bstate));
 	INIT_LIST_HEAD(&clk->bstate.list);
-	clk->bstate.pstate = 0xff;
+	clk->bstate.id = 0xff;
 
 	while (clock->name != nv_clk_src_max) {
 		ret = nvkm_clk_read(clk, clock->name);
@@ -616,7 +618,7 @@  nvkm_clk_init(struct nvkm_subdev *subdev)
 
 	clk->astate = clk->state_nr - 1;
 	clk->dstate = 0;
-	clk->pstate = -1;
+	clk->pstate_idx = -1;
 	clk->temp = 90; /* reasonable default value */
 	nvkm_pstate_calc(clk, true);
 	return 0;
diff --git a/drm/nouveau/nvkm/subdev/clk/gk20a.c b/drm/nouveau/nvkm/subdev/clk/gk20a.c
index 218893e3..dc98ad62 100644
--- a/drm/nouveau/nvkm/subdev/clk/gk20a.c
+++ b/drm/nouveau/nvkm/subdev/clk/gk20a.c
@@ -622,7 +622,7 @@  gk20a_clk_ctor(struct nvkm_device *device, int index,
 	/* Finish initializing the pstates */
 	for (i = 0; i < func->nr_pstates; i++) {
 		INIT_LIST_HEAD(&func->pstates[i].list);
-		func->pstates[i].pstate = i + 1;
+		func->pstates[i].id = i + 1;
 	}
 
 	clk->params = params;
diff --git a/drm/nouveau/nvkm/subdev/pmu/gk20a.c b/drm/nouveau/nvkm/subdev/pmu/gk20a.c
index 05e81855..0c169215 100644
--- a/drm/nouveau/nvkm/subdev/pmu/gk20a.c
+++ b/drm/nouveau/nvkm/subdev/pmu/gk20a.c
@@ -60,7 +60,7 @@  gk20a_pmu_dvfs_get_cur_state(struct gk20a_pmu *pmu, int *state)
 {
 	struct nvkm_clk *clk = pmu->base.subdev.device->clk;
 
-	*state = clk->pstate;
+	*state = clk->pstate_idx;
 }
 
 static int
@@ -72,7 +72,7 @@  gk20a_pmu_dvfs_get_target_state(struct gk20a_pmu *pmu,
 	int cur_level, level;
 
 	/* For GK20A, the performance level is directly mapped to pstate */
-	level = cur_level = clk->pstate;
+	level = cur_level = clk->pstate_idx;
 
 	if (load > data->p_load_max) {
 		level = min(clk->state_nr - 1, level + (clk->state_nr / 3));