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.
24 #include <core/parent.h>
25 #include <core/client.h>
26 #include <core/engine.h>
29 nvkm_parent_sclass(struct nvkm_object
*parent
, u16 handle
,
30 struct nvkm_object
**pengine
,
31 struct nvkm_oclass
**poclass
)
33 struct nvkm_sclass
*sclass
;
34 struct nvkm_engine
*engine
;
35 struct nvkm_oclass
*oclass
;
38 sclass
= nv_parent(parent
)->sclass
;
40 if ((sclass
->oclass
->handle
& 0xffff) == handle
) {
41 *pengine
= &parent
->engine
->subdev
.object
;
42 *poclass
= sclass
->oclass
;
46 sclass
= sclass
->sclass
;
49 mask
= nv_parent(parent
)->engine
;
51 int i
= __ffs64(mask
);
53 if (nv_iclass(parent
, NV_CLIENT_CLASS
))
54 engine
= nv_engine(nv_client(parent
)->device
);
56 engine
= nvkm_engine(parent
, i
);
59 oclass
= engine
->sclass
;
60 while (oclass
->ofuncs
) {
61 if ((oclass
->handle
& 0xffff) == handle
) {
62 *pengine
= nv_object(engine
);
77 nvkm_parent_lclass(struct nvkm_object
*parent
, u32
*lclass
, int size
)
79 struct nvkm_sclass
*sclass
;
80 struct nvkm_engine
*engine
;
81 struct nvkm_oclass
*oclass
;
85 sclass
= nv_parent(parent
)->sclass
;
88 lclass
[nr
] = sclass
->oclass
->handle
& 0xffff;
89 sclass
= sclass
->sclass
;
92 mask
= nv_parent(parent
)->engine
;
93 while (i
= __ffs64(mask
), mask
) {
94 engine
= nvkm_engine(parent
, i
);
95 if (engine
&& (oclass
= engine
->sclass
)) {
96 while (oclass
->ofuncs
) {
98 lclass
[nr
] = oclass
->handle
& 0xffff;
103 mask
&= ~(1ULL << i
);
110 nvkm_parent_create_(struct nvkm_object
*parent
, struct nvkm_object
*engine
,
111 struct nvkm_oclass
*oclass
, u32 pclass
,
112 struct nvkm_oclass
*sclass
, u64 engcls
,
113 int size
, void **pobject
)
115 struct nvkm_parent
*object
;
116 struct nvkm_sclass
*nclass
;
119 ret
= nvkm_object_create_(parent
, engine
, oclass
, pclass
|
120 NV_PARENT_CLASS
, size
, pobject
);
125 while (sclass
&& sclass
->ofuncs
) {
126 nclass
= kzalloc(sizeof(*nclass
), GFP_KERNEL
);
130 nclass
->sclass
= object
->sclass
;
131 object
->sclass
= nclass
;
132 nclass
->engine
= engine
? nv_engine(engine
) : NULL
;
133 nclass
->oclass
= sclass
;
137 object
->engine
= engcls
;
142 nvkm_parent_destroy(struct nvkm_parent
*parent
)
144 struct nvkm_sclass
*sclass
;
146 while ((sclass
= parent
->sclass
)) {
147 parent
->sclass
= sclass
->sclass
;
151 nvkm_object_destroy(&parent
->object
);
156 _nvkm_parent_dtor(struct nvkm_object
*object
)
158 nvkm_parent_destroy(nv_parent(object
));