提交 5ffeb84b 编写于 作者: B Ben Skeggs

drm/nouveau/pm: convert user classes to new-style nvkm_object

Signed-off-by: NBen Skeggs <bskeggs@redhat.com>
上级 218f978d
#ifndef __NVKM_PM_H__ #ifndef __NVKM_PM_H__
#define __NVKM_PM_H__ #define __NVKM_PM_H__
#define nvkm_pm(p) container_of((p), struct nvkm_pm, engine)
#include <core/engine.h> #include <core/engine.h>
struct nvkm_perfdom; struct nvkm_perfdom;
...@@ -7,20 +8,13 @@ struct nvkm_perfctr; ...@@ -7,20 +8,13 @@ struct nvkm_perfctr;
struct nvkm_pm { struct nvkm_pm {
struct nvkm_engine engine; struct nvkm_engine engine;
struct nvkm_perfctx *context; struct nvkm_object *perfmon;
void *profile_data;
struct list_head domains; struct list_head domains;
struct list_head sources; struct list_head sources;
u32 sequence; u32 sequence;
}; };
static inline struct nvkm_pm *
nvkm_pm(void *obj)
{
return (void *)nvkm_engine(obj, NVDEV_ENGINE_PM);
}
extern struct nvkm_oclass *nv40_pm_oclass; extern struct nvkm_oclass *nv40_pm_oclass;
extern struct nvkm_oclass *nv50_pm_oclass; extern struct nvkm_oclass *nv50_pm_oclass;
extern struct nvkm_oclass *g84_pm_oclass; extern struct nvkm_oclass *g84_pm_oclass;
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include <core/client.h> #include <core/client.h>
#include <core/option.h> #include <core/option.h>
#include <core/parent.h>
#include <nvif/class.h> #include <nvif/class.h>
#include <nvif/ioctl.h> #include <nvif/ioctl.h>
...@@ -304,11 +303,11 @@ nvkm_perfdom_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size) ...@@ -304,11 +303,11 @@ nvkm_perfdom_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size)
return -EINVAL; return -EINVAL;
} }
static void static void *
nvkm_perfdom_dtor(struct nvkm_object *object) nvkm_perfdom_dtor(struct nvkm_object *base)
{ {
struct nvkm_pm *pm = (void *)object->engine; struct nvkm_perfdom *dom = nvkm_perfdom(base);
struct nvkm_perfdom *dom = (void *)object; struct nvkm_pm *pm = dom->perfmon->pm;
int i; int i;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
...@@ -320,7 +319,8 @@ nvkm_perfdom_dtor(struct nvkm_object *object) ...@@ -320,7 +319,8 @@ nvkm_perfdom_dtor(struct nvkm_object *object)
} }
kfree(ctr); kfree(ctr);
} }
nvkm_object_destroy(&dom->base);
return dom;
} }
static int static int
...@@ -353,15 +353,22 @@ nvkm_perfctr_new(struct nvkm_perfdom *dom, int slot, u8 domain, ...@@ -353,15 +353,22 @@ nvkm_perfctr_new(struct nvkm_perfdom *dom, int slot, u8 domain,
return 0; return 0;
} }
static const struct nvkm_object_func
nvkm_perfdom = {
.dtor = nvkm_perfdom_dtor,
.mthd = nvkm_perfdom_mthd,
};
static int static int
nvkm_perfdom_ctor(struct nvkm_object *parent, struct nvkm_object *engine, nvkm_perfdom_new_(struct nvkm_perfmon *perfmon,
struct nvkm_oclass *oclass, void *data, u32 size, const struct nvkm_oclass *oclass, void *data, u32 size,
struct nvkm_object **pobject) struct nvkm_object **pobject)
{ {
union { union {
struct nvif_perfdom_v0 v0; struct nvif_perfdom_v0 v0;
} *args = data; } *args = data;
struct nvkm_pm *pm = (void *)engine; struct nvkm_pm *pm = perfmon->pm;
struct nvkm_object *parent = oclass->parent;
struct nvkm_perfdom *sdom = NULL; struct nvkm_perfdom *sdom = NULL;
struct nvkm_perfctr *ctr[4] = {}; struct nvkm_perfctr *ctr[4] = {};
struct nvkm_perfdom *dom; struct nvkm_perfdom *dom;
...@@ -403,10 +410,11 @@ nvkm_perfdom_ctor(struct nvkm_object *parent, struct nvkm_object *engine, ...@@ -403,10 +410,11 @@ nvkm_perfdom_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
if (!sdom) if (!sdom)
return -EINVAL; return -EINVAL;
ret = nvkm_object_create(parent, engine, oclass, 0, &dom); if (!(dom = kzalloc(sizeof(*dom), GFP_KERNEL)))
*pobject = nv_object(dom); return -ENOMEM;
if (ret) nvkm_object_ctor(&nvkm_perfdom, oclass, &dom->object);
return ret; dom->perfmon = perfmon;
*pobject = &dom->object;
dom->func = sdom->func; dom->func = sdom->func;
dom->addr = sdom->addr; dom->addr = sdom->addr;
...@@ -416,25 +424,18 @@ nvkm_perfdom_ctor(struct nvkm_object *parent, struct nvkm_object *engine, ...@@ -416,25 +424,18 @@ nvkm_perfdom_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
return 0; return 0;
} }
static struct nvkm_ofuncs
nvkm_perfdom_ofuncs = {
.ctor = nvkm_perfdom_ctor,
.dtor = nvkm_perfdom_dtor,
.init = _nvkm_object_init,
.fini = _nvkm_object_fini,
.mthd = nvkm_perfdom_mthd,
};
/******************************************************************************* /*******************************************************************************
* Perfmon object classes * Perfmon object classes
******************************************************************************/ ******************************************************************************/
static int static int
nvkm_perfmon_mthd_query_domain(struct nvkm_object *object, void *data, u32 size) nvkm_perfmon_mthd_query_domain(struct nvkm_perfmon *perfmon,
void *data, u32 size)
{ {
union { union {
struct nvif_perfmon_query_domain_v0 v0; struct nvif_perfmon_query_domain_v0 v0;
} *args = data; } *args = data;
struct nvkm_pm *pm = (void *)object->engine; struct nvkm_object *object = &perfmon->object;
struct nvkm_pm *pm = perfmon->pm;
struct nvkm_perfdom *dom; struct nvkm_perfdom *dom;
u8 domain_nr; u8 domain_nr;
int di, ret; int di, ret;
...@@ -475,13 +476,15 @@ nvkm_perfmon_mthd_query_domain(struct nvkm_object *object, void *data, u32 size) ...@@ -475,13 +476,15 @@ nvkm_perfmon_mthd_query_domain(struct nvkm_object *object, void *data, u32 size)
} }
static int static int
nvkm_perfmon_mthd_query_signal(struct nvkm_object *object, void *data, u32 size) nvkm_perfmon_mthd_query_signal(struct nvkm_perfmon *perfmon,
void *data, u32 size)
{ {
union { union {
struct nvif_perfmon_query_signal_v0 v0; struct nvif_perfmon_query_signal_v0 v0;
} *args = data; } *args = data;
struct nvkm_device *device = nv_device(object); struct nvkm_object *object = &perfmon->object;
struct nvkm_pm *pm = (void *)object->engine; struct nvkm_pm *pm = perfmon->pm;
struct nvkm_device *device = pm->engine.subdev.device;
struct nvkm_perfdom *dom; struct nvkm_perfdom *dom;
struct nvkm_perfsig *sig; struct nvkm_perfsig *sig;
const bool all = nvkm_boolopt(device->cfgopt, "NvPmShowAll", false); const bool all = nvkm_boolopt(device->cfgopt, "NvPmShowAll", false);
...@@ -527,12 +530,14 @@ nvkm_perfmon_mthd_query_signal(struct nvkm_object *object, void *data, u32 size) ...@@ -527,12 +530,14 @@ nvkm_perfmon_mthd_query_signal(struct nvkm_object *object, void *data, u32 size)
} }
static int static int
nvkm_perfmon_mthd_query_source(struct nvkm_object *object, void *data, u32 size) nvkm_perfmon_mthd_query_source(struct nvkm_perfmon *perfmon,
void *data, u32 size)
{ {
union { union {
struct nvif_perfmon_query_source_v0 v0; struct nvif_perfmon_query_source_v0 v0;
} *args = data; } *args = data;
struct nvkm_pm *pm = (void *)object->engine; struct nvkm_object *object = &perfmon->object;
struct nvkm_pm *pm = perfmon->pm;
struct nvkm_perfdom *dom = NULL; struct nvkm_perfdom *dom = NULL;
struct nvkm_perfsig *sig; struct nvkm_perfsig *sig;
struct nvkm_perfsrc *src; struct nvkm_perfsrc *src;
...@@ -579,117 +584,118 @@ nvkm_perfmon_mthd_query_source(struct nvkm_object *object, void *data, u32 size) ...@@ -579,117 +584,118 @@ nvkm_perfmon_mthd_query_source(struct nvkm_object *object, void *data, u32 size)
static int static int
nvkm_perfmon_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size) nvkm_perfmon_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size)
{ {
struct nvkm_perfmon *perfmon = nvkm_perfmon(object);
switch (mthd) { switch (mthd) {
case NVIF_PERFMON_V0_QUERY_DOMAIN: case NVIF_PERFMON_V0_QUERY_DOMAIN:
return nvkm_perfmon_mthd_query_domain(object, data, size); return nvkm_perfmon_mthd_query_domain(perfmon, data, size);
case NVIF_PERFMON_V0_QUERY_SIGNAL: case NVIF_PERFMON_V0_QUERY_SIGNAL:
return nvkm_perfmon_mthd_query_signal(object, data, size); return nvkm_perfmon_mthd_query_signal(perfmon, data, size);
case NVIF_PERFMON_V0_QUERY_SOURCE: case NVIF_PERFMON_V0_QUERY_SOURCE:
return nvkm_perfmon_mthd_query_source(object, data, size); return nvkm_perfmon_mthd_query_source(perfmon, data, size);
default: default:
break; break;
} }
return -EINVAL; return -EINVAL;
} }
static struct nvkm_oclass static int
nvkm_perfmon_sclass[] = { nvkm_perfmon_child_new(const struct nvkm_oclass *oclass, void *data, u32 size,
{ .handle = NVIF_IOCTL_NEW_V0_PERFDOM, struct nvkm_object **pobject)
.ofuncs = &nvkm_perfdom_ofuncs, {
}, struct nvkm_perfmon *perfmon = nvkm_perfmon(oclass->parent);
{} return nvkm_perfdom_new_(perfmon, oclass, data, size, pobject);
}; }
static int static int
nvkm_perfmon_ctor(struct nvkm_object *parent, struct nvkm_object *engine, nvkm_perfmon_child_get(struct nvkm_object *base, int index,
struct nvkm_oclass *oclass, void *data, u32 size, struct nvkm_oclass *oclass)
struct nvkm_object **pobject)
{ {
struct nvkm_parent *perfmon; if (index == 0) {
int ret = nvkm_parent_create(parent, engine, oclass, 0, oclass->base.oclass = NVIF_IOCTL_NEW_V0_PERFDOM;
nvkm_perfmon_sclass, 0, &perfmon); oclass->base.minver = 0;
*pobject = perfmon ? &perfmon->object : NULL; oclass->base.maxver = 0;
return ret; oclass->ctor = nvkm_perfmon_child_new;
return 0;
}
return -EINVAL;
} }
static struct nvkm_ofuncs static void *
nvkm_perfmon_ofuncs = { nvkm_perfmon_dtor(struct nvkm_object *base)
.ctor = nvkm_perfmon_ctor, {
.dtor = _nvkm_parent_dtor, struct nvkm_perfmon *perfmon = nvkm_perfmon(base);
.init = _nvkm_parent_init, struct nvkm_pm *pm = perfmon->pm;
.fini = _nvkm_parent_fini, mutex_lock(&pm->engine.subdev.mutex);
.mthd = nvkm_perfmon_mthd, if (pm->perfmon == &perfmon->object)
}; pm->perfmon = NULL;
mutex_unlock(&pm->engine.subdev.mutex);
return perfmon;
}
struct nvkm_oclass static struct nvkm_object_func
nvkm_pm_sclass[] = { nvkm_perfmon = {
{ .dtor = nvkm_perfmon_dtor,
.handle = NVIF_IOCTL_NEW_V0_PERFMON, .mthd = nvkm_perfmon_mthd,
.ofuncs = &nvkm_perfmon_ofuncs, .sclass = nvkm_perfmon_child_get,
},
{},
}; };
/******************************************************************************* static int
* PPM context nvkm_perfmon_new(struct nvkm_pm *pm, const struct nvkm_oclass *oclass,
******************************************************************************/ void *data, u32 size, struct nvkm_object **pobject)
static void
nvkm_perfctx_dtor(struct nvkm_object *object)
{ {
struct nvkm_pm *pm = (void *)object->engine; struct nvkm_perfmon *perfmon;
struct nvkm_perfctx *ctx = (void *)object;
nvkm_gpuobj_destroy(&ctx->base); if (!(perfmon = kzalloc(sizeof(*perfmon), GFP_KERNEL)))
mutex_lock(&nv_subdev(pm)->mutex); return -ENOMEM;
if (pm->context == ctx) nvkm_object_ctor(&nvkm_perfmon, oclass, &perfmon->object);
pm->context = NULL; perfmon->pm = pm;
mutex_unlock(&nv_subdev(pm)->mutex); *pobject = &perfmon->object;
return 0;
} }
/*******************************************************************************
* PPM engine/subdev functions
******************************************************************************/
static int static int
nvkm_perfctx_ctor(struct nvkm_object *parent, struct nvkm_object *engine, nvkm_pm_oclass_new(struct nvkm_device *device, const struct nvkm_oclass *oclass,
struct nvkm_oclass *oclass, void *data, u32 size, void *data, u32 size, struct nvkm_object **pobject)
struct nvkm_object **pobject)
{ {
struct nvkm_pm *pm = (void *)engine; struct nvkm_pm *pm = nvkm_pm(oclass->engine);
struct nvkm_perfctx *ctx;
int ret; int ret;
/* no context needed for perfdom objects... */ ret = nvkm_perfmon_new(pm, oclass, data, size, pobject);
if (parent->parent != &nvkm_client(parent)->object) {
atomic_inc(&parent->refcount);
*pobject = parent;
return 1;
}
ret = nvkm_gpuobj_create(parent, engine, oclass, 0, NULL, 0, 0, 0, &ctx);
*pobject = nv_object(ctx);
if (ret) if (ret)
return ret; return ret;
mutex_lock(&nv_subdev(pm)->mutex); mutex_lock(&pm->engine.subdev.mutex);
if (pm->context == NULL) if (pm->perfmon == NULL)
pm->context = ctx; pm->perfmon = *pobject;
if (ctx != pm->context) ret = (pm->perfmon == *pobject) ? 0 : -EBUSY;
ret = -EBUSY; mutex_unlock(&pm->engine.subdev.mutex);
mutex_unlock(&nv_subdev(pm)->mutex);
return ret; return ret;
} }
struct nvkm_oclass static const struct nvkm_device_oclass
nvkm_pm_cclass = { nvkm_pm_oclass = {
.ofuncs = &(struct nvkm_ofuncs) { .base.oclass = NVIF_IOCTL_NEW_V0_PERFMON,
.ctor = nvkm_perfctx_ctor, .base.minver = -1,
.dtor = nvkm_perfctx_dtor, .base.maxver = -1,
.init = _nvkm_gpuobj_init, .ctor = nvkm_pm_oclass_new,
.fini = _nvkm_gpuobj_fini,
},
}; };
/******************************************************************************* static int
* PPM engine/subdev functions nvkm_pm_oclass_get(struct nvkm_oclass *oclass, int index,
******************************************************************************/ const struct nvkm_device_oclass **class)
{
if (index == 0) {
oclass->base = nvkm_pm_oclass.base;
*class = &nvkm_pm_oclass;
return index;
}
return 1;
}
int int
nvkm_perfsrc_new(struct nvkm_pm *pm, struct nvkm_perfsig *sig, nvkm_perfsrc_new(struct nvkm_pm *pm, struct nvkm_perfsig *sig,
const struct nvkm_specsrc *spec) const struct nvkm_specsrc *spec)
...@@ -845,6 +851,11 @@ _nvkm_pm_dtor(struct nvkm_object *object) ...@@ -845,6 +851,11 @@ _nvkm_pm_dtor(struct nvkm_object *object)
nvkm_engine_destroy(&pm->engine); nvkm_engine_destroy(&pm->engine);
} }
static const struct nvkm_engine_func
nvkm_pm = {
.base.sclass = nvkm_pm_oclass_get,
};
int int
nvkm_pm_create_(struct nvkm_object *parent, struct nvkm_object *engine, nvkm_pm_create_(struct nvkm_object *parent, struct nvkm_object *engine,
struct nvkm_oclass *oclass, int length, void **pobject) struct nvkm_oclass *oclass, int length, void **pobject)
...@@ -858,6 +869,8 @@ nvkm_pm_create_(struct nvkm_object *parent, struct nvkm_object *engine, ...@@ -858,6 +869,8 @@ nvkm_pm_create_(struct nvkm_object *parent, struct nvkm_object *engine,
if (ret) if (ret)
return ret; return ret;
pm->engine.func = &nvkm_pm;
INIT_LIST_HEAD(&pm->domains); INIT_LIST_HEAD(&pm->domains);
INIT_LIST_HEAD(&pm->sources); INIT_LIST_HEAD(&pm->sources);
return 0; return 0;
......
...@@ -226,8 +226,6 @@ gf100_pm_ctor(struct nvkm_object *parent, struct nvkm_object *engine, ...@@ -226,8 +226,6 @@ gf100_pm_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
if (ret) if (ret)
return ret; return ret;
nv_engine(pm)->cclass = &nvkm_pm_cclass;
nv_engine(pm)->sclass = nvkm_pm_sclass;
return 0; return 0;
} }
......
...@@ -36,8 +36,6 @@ gk110_pm_ctor(struct nvkm_object *parent, struct nvkm_object *engine, ...@@ -36,8 +36,6 @@ gk110_pm_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
if (ret) if (ret)
return ret; return ret;
nv_engine(pm)->cclass = &nvkm_pm_cclass;
nv_engine(pm)->sclass = nvkm_pm_sclass;
return 0; return 0;
} }
......
...@@ -112,8 +112,6 @@ nv40_pm_ctor(struct nvkm_object *parent, struct nvkm_object *engine, ...@@ -112,8 +112,6 @@ nv40_pm_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
if (ret) if (ret)
return ret; return ret;
nv_engine(pm)->cclass = &nvkm_pm_cclass;
nv_engine(pm)->sclass = nvkm_pm_sclass;
return 0; return 0;
} }
......
...@@ -12,16 +12,6 @@ struct nvkm_perfctr { ...@@ -12,16 +12,6 @@ struct nvkm_perfctr {
u32 ctr; u32 ctr;
}; };
extern struct nvkm_oclass nvkm_pm_sclass[];
#include <core/gpuobj.h>
struct nvkm_perfctx {
struct nvkm_gpuobj base;
};
extern struct nvkm_oclass nvkm_pm_cclass;
struct nvkm_specmux { struct nvkm_specmux {
u32 mask; u32 mask;
u8 shift; u8 shift;
...@@ -68,8 +58,11 @@ struct nvkm_specdom { ...@@ -68,8 +58,11 @@ struct nvkm_specdom {
const struct nvkm_funcdom *func; const struct nvkm_funcdom *func;
}; };
#define nvkm_perfdom(p) container_of((p), struct nvkm_perfdom, object)
struct nvkm_perfdom { struct nvkm_perfdom {
struct nvkm_object base; struct nvkm_object object;
struct nvkm_perfmon *perfmon;
struct list_head head; struct list_head head;
struct list_head list; struct list_head list;
const struct nvkm_funcdom *func; const struct nvkm_funcdom *func;
...@@ -93,6 +86,13 @@ struct nvkm_funcdom { ...@@ -93,6 +86,13 @@ struct nvkm_funcdom {
int nvkm_perfdom_new(struct nvkm_pm *, const char *, u32, u32, u32, u32, int nvkm_perfdom_new(struct nvkm_pm *, const char *, u32, u32, u32, u32,
const struct nvkm_specdom *); const struct nvkm_specdom *);
#define nvkm_perfmon(p) container_of((p), struct nvkm_perfmon, object)
struct nvkm_perfmon {
struct nvkm_object object;
struct nvkm_pm *pm;
};
#define nvkm_pm_create(p,e,o,d) \ #define nvkm_pm_create(p,e,o,d) \
nvkm_pm_create_((p), (e), (o), sizeof(**d), (void **)d) nvkm_pm_create_((p), (e), (o), sizeof(**d), (void **)d)
#define nvkm_pm_dtor(p) ({ \ #define nvkm_pm_dtor(p) ({ \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册