1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <core/object.h>
26#include <core/parent.h>
27#include <core/client.h>
28
29int
30nouveau_parent_sclass(struct nouveau_object *parent, u16 handle,
31 struct nouveau_object **pengine,
32 struct nouveau_oclass **poclass)
33{
34 struct nouveau_sclass *sclass;
35 struct nouveau_engine *engine;
36 struct nouveau_oclass *oclass;
37 u64 mask;
38
39 sclass = nv_parent(parent)->sclass;
40 while (sclass) {
41 if ((sclass->oclass->handle & 0xffff) == handle) {
42 *pengine = parent->engine;
43 *poclass = sclass->oclass;
44 return 0;
45 }
46
47 sclass = sclass->sclass;
48 }
49
50 mask = nv_parent(parent)->engine;
51 while (mask) {
52 int i = ffsll(mask) - 1;
53
54 if (nv_iclass(parent, NV_CLIENT_CLASS))
55 engine = nv_engine(nv_client(parent)->device);
56 else
57 engine = nouveau_engine(parent, i);
58
59 if (engine) {
60 oclass = engine->sclass;
61 while (oclass->ofuncs) {
62 if ((oclass->handle & 0xffff) == handle) {
63 *pengine = nv_object(engine);
64 *poclass = oclass;
65 return 0;
66 }
67 oclass++;
68 }
69 }
70
71 mask &= ~(1ULL << i);
72 }
73
74 return -EINVAL;
75}
76
77int
78nouveau_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)
83{
84 struct nouveau_parent *object;
85 struct nouveau_sclass *nclass;
86 int ret;
87
88 ret = nouveau_object_create_(parent, engine, oclass, pclass |
89 NV_PARENT_CLASS, size, pobject);
90 object = *pobject;
91 if (ret)
92 return ret;
93
94 while (sclass && sclass->ofuncs) {
95 nclass = kzalloc(sizeof(*nclass), GFP_KERNEL);
96 if (!nclass)
97 return -ENOMEM;
98
99 nclass->sclass = object->sclass;
100 object->sclass = nclass;
101 nclass->engine = engine ? nv_engine(engine) : NULL;
102 nclass->oclass = sclass;
103 sclass++;
104 }
105
106 object->engine = engcls;
107 return 0;
108}
109
110void
111nouveau_parent_destroy(struct nouveau_parent *parent)
112{
113 struct nouveau_sclass *sclass;
114
115 while ((sclass = parent->sclass)) {
116 parent->sclass = sclass->sclass;
117 kfree(sclass);
118 }
119
120 nouveau_object_destroy(&parent->base);
121}
122
123
124void
125_nouveau_parent_dtor(struct nouveau_object *object)
126{
127 nouveau_parent_destroy(nv_parent(object));
128}
129