[PATCH 073/156] drm/nouveau/nvif: rework ctrl "pstate user" api
Ben Skeggs
bskeggs at nvidia.com
Tue Apr 16 23:38:39 UTC 2024
- transition from "ioctl" interface
Signed-off-by: Ben Skeggs <bskeggs at nvidia.com>
---
.../gpu/drm/nouveau/include/nvif/driverif.h | 9 ++++
drivers/gpu/drm/nouveau/include/nvif/if0001.h | 15 ------
drivers/gpu/drm/nouveau/nouveau_debugfs.c | 10 ++--
drivers/gpu/drm/nouveau/nvkm/device/ctrl.c | 51 ++++---------------
4 files changed, 24 insertions(+), 61 deletions(-)
delete mode 100644 drivers/gpu/drm/nouveau/include/nvif/if0001.h
diff --git a/drivers/gpu/drm/nouveau/include/nvif/driverif.h b/drivers/gpu/drm/nouveau/include/nvif/driverif.h
index bfa22c977323..e22e0347f623 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/driverif.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/driverif.h
@@ -23,6 +23,14 @@ struct nvif_mapinfo {
u64 length;
};
+struct nvif_control_pstate_user {
+ u8 version;
+#define NVIF_CONTROL_PSTATE_USER_STATE_UNKNOWN (-1)
+#define NVIF_CONTROL_PSTATE_USER_STATE_PERFMON (-2)
+ s8 ustate; /* in: pstate identifier */
+ s8 pwrsrc; /* in: target power source */
+};
+
struct nvif_control_pstate_attr {
u8 version;
#define NVIF_CONTROL_PSTATE_ATTR_STATE_CURRENT (-1)
@@ -57,6 +65,7 @@ struct nvif_control_impl {
struct {
void (*info)(struct nvif_control_priv *, struct nvif_control_pstate_info *);
int (*attr)(struct nvif_control_priv *, struct nvif_control_pstate_attr *);
+ int (*user)(struct nvif_control_priv *, struct nvif_control_pstate_user *);
} pstate;
};
diff --git a/drivers/gpu/drm/nouveau/include/nvif/if0001.h b/drivers/gpu/drm/nouveau/include/nvif/if0001.h
deleted file mode 100644
index b84da0b7d079..000000000000
--- a/drivers/gpu/drm/nouveau/include/nvif/if0001.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/* SPDX-License-Identifier: MIT */
-#ifndef __NVIF_IF0001_H__
-#define __NVIF_IF0001_H__
-
-#define NVIF_CONTROL_PSTATE_USER 0x02
-
-struct nvif_control_pstate_user_v0 {
- __u8 version;
-#define NVIF_CONTROL_PSTATE_USER_V0_STATE_UNKNOWN (-1)
-#define NVIF_CONTROL_PSTATE_USER_V0_STATE_PERFMON (-2)
- __s8 ustate; /* in: pstate identifier */
- __s8 pwrsrc; /* in: target power source */
- __u8 pad03[5];
-};
-#endif
diff --git a/drivers/gpu/drm/nouveau/nouveau_debugfs.c b/drivers/gpu/drm/nouveau/nouveau_debugfs.c
index 33a64f95f64f..837653ca1753 100644
--- a/drivers/gpu/drm/nouveau/nouveau_debugfs.c
+++ b/drivers/gpu/drm/nouveau/nouveau_debugfs.c
@@ -29,7 +29,6 @@
*/
#include <linux/debugfs.h>
-#include <nvif/if0001.h>
#include "nouveau_debugfs.h"
#include "nouveau_drv.h"
@@ -138,7 +137,7 @@ nouveau_debugfs_pstate_set(struct file *file, const char __user *ubuf,
struct seq_file *m = file->private_data;
struct drm_device *drm = m->private;
struct nouveau_debugfs *debugfs = nouveau_debugfs(drm);
- struct nvif_control_pstate_user_v0 args = { .pwrsrc = -EINVAL };
+ struct nvif_control_pstate_user args = { .pwrsrc = -EINVAL };
char buf[32] = {}, *tmp, *cur = buf;
long value, ret;
@@ -164,10 +163,10 @@ nouveau_debugfs_pstate_set(struct file *file, const char __user *ubuf,
}
if (!strcasecmp(cur, "none"))
- args.ustate = NVIF_CONTROL_PSTATE_USER_V0_STATE_UNKNOWN;
+ args.ustate = NVIF_CONTROL_PSTATE_USER_STATE_UNKNOWN;
else
if (!strcasecmp(cur, "auto"))
- args.ustate = NVIF_CONTROL_PSTATE_USER_V0_STATE_PERFMON;
+ args.ustate = NVIF_CONTROL_PSTATE_USER_STATE_PERFMON;
else {
ret = kstrtol(cur, 16, &value);
if (ret)
@@ -181,8 +180,7 @@ nouveau_debugfs_pstate_set(struct file *file, const char __user *ubuf,
return ret;
}
- ret = nvif_mthd(&debugfs->ctrl, NVIF_CONTROL_PSTATE_USER,
- &args, sizeof(args));
+ ret = debugfs->impl->pstate.user(debugfs->priv, &args);
pm_runtime_put_autosuspend(drm->dev);
if (ret < 0)
return ret;
diff --git a/drivers/gpu/drm/nouveau/nvkm/device/ctrl.c b/drivers/gpu/drm/nouveau/nvkm/device/ctrl.c
index 8c279cb797e9..4ba1d5934a87 100644
--- a/drivers/gpu/drm/nouveau/nvkm/device/ctrl.c
+++ b/drivers/gpu/drm/nouveau/nvkm/device/ctrl.c
@@ -26,12 +26,6 @@
#include <core/client.h>
#include <subdev/clk.h>
-#include <nvif/if0001.h>
-#include <nvif/ioctl.h>
-#include <nvif/unpack.h>
-
-#define nvkm_control nvif_control_priv
-
struct nvif_control_priv {
struct nvkm_object object;
struct nvkm_device *device;
@@ -121,50 +115,26 @@ nvkm_control_pstate_attr(struct nvif_control_priv *ctrl, struct nvif_control_pst
}
static int
-nvkm_control_mthd_pstate_user(struct nvkm_control *ctrl, void *data, u32 size)
+nvkm_control_pstate_user(struct nvif_control_priv *ctrl, struct nvif_control_pstate_user *user)
{
- union {
- struct nvif_control_pstate_user_v0 v0;
- } *args = data;
struct nvkm_clk *clk = ctrl->device->clk;
- int ret = -ENOSYS;
-
- nvif_ioctl(&ctrl->object, "control pstate user size %d\n", size);
- if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
- nvif_ioctl(&ctrl->object,
- "control pstate user vers %d ustate %d pwrsrc %d\n",
- args->v0.version, args->v0.ustate, args->v0.pwrsrc);
- if (!clk)
- return -ENODEV;
- } else
- return ret;
-
- if (args->v0.pwrsrc >= 0) {
- ret |= nvkm_clk_ustate(clk, args->v0.ustate, args->v0.pwrsrc);
+ int ret = 0;
+
+ if (!clk)
+ return -ENODEV;
+
+ if (user->pwrsrc >= 0) {
+ ret |= nvkm_clk_ustate(clk, user->ustate, user->pwrsrc);
} else {
- ret |= nvkm_clk_ustate(clk, args->v0.ustate, 0);
- ret |= nvkm_clk_ustate(clk, args->v0.ustate, 1);
+ ret |= nvkm_clk_ustate(clk, user->ustate, 0);
+ ret |= nvkm_clk_ustate(clk, user->ustate, 1);
}
return ret;
}
-static int
-nvkm_control_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size)
-{
- struct nvif_control_priv *ctrl = container_of(object, typeof(*ctrl), object);
- switch (mthd) {
- case NVIF_CONTROL_PSTATE_USER:
- return nvkm_control_mthd_pstate_user(ctrl, data, size);
- default:
- break;
- }
- return -EINVAL;
-}
-
static const struct nvkm_object_func
nvkm_control = {
- .mthd = nvkm_control_mthd,
};
static void
@@ -180,6 +150,7 @@ nvkm_control_impl = {
.del = nvkm_control_del,
.pstate.info = nvkm_control_pstate_info,
.pstate.attr = nvkm_control_pstate_attr,
+ .pstate.user = nvkm_control_pstate_user,
};
int
--
2.41.0
More information about the Nouveau
mailing list