2 * Copyright 2012 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
25 #include <core/object.h>
26 #include <core/parent.h>
27 #include <core/client.h>
30 nouveau_parent_sclass(struct nouveau_object *parent, u16 handle,
31 struct nouveau_object **pengine,
32 struct nouveau_oclass **poclass)
34 struct nouveau_sclass *sclass;
35 struct nouveau_engine *engine;
36 struct nouveau_oclass *oclass;
39 sclass = nv_parent(parent)->sclass;
41 if ((sclass->oclass->handle & 0xffff) == handle) {
42 *pengine = parent->engine;
43 *poclass = sclass->oclass;
47 sclass = sclass->sclass;
50 mask = nv_parent(parent)->engine;
52 int i = __ffs64(mask);
54 if (nv_iclass(parent, NV_CLIENT_CLASS))
55 engine = nv_engine(nv_client(parent)->device);
57 engine = nouveau_engine(parent, i);
60 oclass = engine->sclass;
61 while (oclass->ofuncs) {
62 if ((oclass->handle & 0xffff) == handle) {
63 *pengine = nv_object(engine);
78 nouveau_parent_create_(struct nouveau_object *parent,
79 struct nouveau_object *engine,
80 struct nouveau_oclass *oclass, u32 pclass,
81 struct nouveau_oclass *sclass, u64 engcls,
82 int size, void **pobject)
84 struct nouveau_parent *object;
85 struct nouveau_sclass *nclass;
88 ret = nouveau_object_create_(parent, engine, oclass, pclass |
89 NV_PARENT_CLASS, size, pobject);
94 while (sclass && sclass->ofuncs) {
95 nclass = kzalloc(sizeof(*nclass), GFP_KERNEL);
99 nclass->sclass = object->sclass;
100 object->sclass = nclass;
101 nclass->engine = engine ? nv_engine(engine) : NULL;
102 nclass->oclass = sclass;
106 object->engine = engcls;
111 nouveau_parent_destroy(struct nouveau_parent *parent)
113 struct nouveau_sclass *sclass;
115 while ((sclass = parent->sclass)) {
116 parent->sclass = sclass->sclass;
120 nouveau_object_destroy(&parent->base);
125 _nouveau_parent_dtor(struct nouveau_object *object)
127 nouveau_parent_destroy(nv_parent(object));