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_lclass(struct nouveau_object *parent, u32 *lclass, int size)
80 struct nouveau_sclass *sclass;
81 struct nouveau_engine *engine;
82 struct nouveau_oclass *oclass;
86 sclass = nv_parent(parent)->sclass;
89 lclass[nr] = sclass->oclass->handle;
90 sclass = sclass->sclass;
93 mask = nv_parent(parent)->engine;
94 while (i = __ffs64(mask), mask) {
95 engine = nouveau_engine(parent, i);
96 if (engine && (oclass = engine->sclass)) {
97 while (oclass->ofuncs) {
99 lclass[nr] = oclass->handle;
104 mask &= ~(1ULL << i);
111 nouveau_parent_create_(struct nouveau_object *parent,
112 struct nouveau_object *engine,
113 struct nouveau_oclass *oclass, u32 pclass,
114 struct nouveau_oclass *sclass, u64 engcls,
115 int size, void **pobject)
117 struct nouveau_parent *object;
118 struct nouveau_sclass *nclass;
121 ret = nouveau_object_create_(parent, engine, oclass, pclass |
122 NV_PARENT_CLASS, size, pobject);
127 while (sclass && sclass->ofuncs) {
128 nclass = kzalloc(sizeof(*nclass), GFP_KERNEL);
132 nclass->sclass = object->sclass;
133 object->sclass = nclass;
134 nclass->engine = engine ? nv_engine(engine) : NULL;
135 nclass->oclass = sclass;
139 object->engine = engcls;
144 nouveau_parent_destroy(struct nouveau_parent *parent)
146 struct nouveau_sclass *sclass;
148 while ((sclass = parent->sclass)) {
149 parent->sclass = sclass->sclass;
153 nouveau_object_destroy(&parent->base);
158 _nouveau_parent_dtor(struct nouveau_object *object)
160 nouveau_parent_destroy(nv_parent(object));