Commit db91d68c authored by Ben Skeggs's avatar Ben Skeggs

drm/nouveau/core: rebase object ref/use counts after ctor/init/fini events

This is intended to support named (with a handle, etc) objects having
children that don't have an outside reference.

This will replace the various hacks around the place where subdev
objects have children, and have to manually drop the self-refs so
that they can be destroyed etc when all the outside refs have gone.
Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent 43e6e51c
...@@ -136,26 +136,30 @@ nouveau_object_ctor(struct nouveau_object *parent, ...@@ -136,26 +136,30 @@ nouveau_object_ctor(struct nouveau_object *parent,
struct nouveau_object **pobject) struct nouveau_object **pobject)
{ {
struct nouveau_ofuncs *ofuncs = oclass->ofuncs; struct nouveau_ofuncs *ofuncs = oclass->ofuncs;
struct nouveau_object *object = NULL;
int ret; int ret;
*pobject = NULL; ret = ofuncs->ctor(parent, engine, oclass, data, size, &object);
*pobject = object;
ret = ofuncs->ctor(parent, engine, oclass, data, size, pobject);
if (ret < 0) { if (ret < 0) {
if (ret != -ENODEV) { if (ret != -ENODEV) {
nv_error(parent, "failed to create 0x%08x, %d\n", nv_error(parent, "failed to create 0x%08x, %d\n",
oclass->handle, ret); oclass->handle, ret);
} }
if (*pobject) { if (object) {
ofuncs->dtor(*pobject); ofuncs->dtor(object);
*pobject = NULL; *pobject = NULL;
} }
return ret; return ret;
} }
nv_debug(*pobject, "created\n"); if (ret == 0) {
nv_debug(object, "created\n");
atomic_set(&object->refcount, 1);
}
return 0; return 0;
} }
...@@ -327,6 +331,7 @@ nouveau_object_inc(struct nouveau_object *object) ...@@ -327,6 +331,7 @@ nouveau_object_inc(struct nouveau_object *object)
} }
ret = nv_ofuncs(object)->init(object); ret = nv_ofuncs(object)->init(object);
atomic_set(&object->usecount, 1);
if (ret) { if (ret) {
nv_error(object, "init failed, %d\n", ret); nv_error(object, "init failed, %d\n", ret);
goto fail_self; goto fail_self;
...@@ -357,6 +362,7 @@ nouveau_object_decf(struct nouveau_object *object) ...@@ -357,6 +362,7 @@ nouveau_object_decf(struct nouveau_object *object)
nv_trace(object, "stopping...\n"); nv_trace(object, "stopping...\n");
ret = nv_ofuncs(object)->fini(object, false); ret = nv_ofuncs(object)->fini(object, false);
atomic_set(&object->usecount, 0);
if (ret) if (ret)
nv_warn(object, "failed fini, %d\n", ret); nv_warn(object, "failed fini, %d\n", ret);
...@@ -381,6 +387,7 @@ nouveau_object_decs(struct nouveau_object *object) ...@@ -381,6 +387,7 @@ nouveau_object_decs(struct nouveau_object *object)
nv_trace(object, "suspending...\n"); nv_trace(object, "suspending...\n");
ret = nv_ofuncs(object)->fini(object, true); ret = nv_ofuncs(object)->fini(object, true);
atomic_set(&object->usecount, 0);
if (ret) { if (ret) {
nv_error(object, "failed suspend, %d\n", ret); nv_error(object, "failed suspend, %d\n", ret);
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment