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
28int
29nouveau_parent_sclass(struct nouveau_object *parent, u16 handle,
30 struct nouveau_object **pengine,
31 struct nouveau_oclass **poclass)
32{
33 struct nouveau_sclass *sclass;
34 struct nouveau_engine *engine;
35 struct nouveau_oclass *oclass;
36 u64 mask;
37
38 sclass = nv_parent(parent)->sclass;
39 while (sclass) {
40 if ((sclass->oclass->handle & 0xffff) == handle) {
41 *pengine = parent->engine;
42 *poclass = sclass->oclass;
43 return 0;
44 }
45
46 sclass = sclass->sclass;
47 }
48
49 mask = nv_parent(parent)->engine;
50 while (mask) {
51 int i = ffsll(mask) - 1;
52
53 if ((engine = nouveau_engine(parent, i))) {
54 oclass = engine->sclass;
55 while (oclass->ofuncs) {
56 if ((oclass->handle & 0xffff) == handle) {
57 *pengine = nv_object(engine);
58 *poclass = oclass;
59 return 0;
60 }
61 oclass++;
62 }
63 }
64
65 mask &= ~(1ULL << i);
66 }
67
68 return -EINVAL;
69}
70
71int
72nouveau_parent_create_(struct nouveau_object *parent,
73 struct nouveau_object *engine,
74 struct nouveau_oclass *oclass, u32 pclass,
75 struct nouveau_oclass *sclass, u64 engcls,
76 int size, void **pobject)
77{
78 struct nouveau_parent *object;
79 struct nouveau_sclass *nclass;
80 int ret;
81
82 ret = nouveau_object_create_(parent, engine, oclass, pclass |
83 NV_PARENT_CLASS, size, pobject);
84 object = *pobject;
85 if (ret)
86 return ret;
87
88 while (sclass && sclass->ofuncs) {
89 nclass = kzalloc(sizeof(*nclass), GFP_KERNEL);
90 if (!nclass)
91 return -ENOMEM;
92
93 nclass->sclass = object->sclass;
94 object->sclass = nclass;
95 nclass->engine = engine ? nv_engine(engine) : NULL;
96 nclass->oclass = sclass;
97 sclass++;
98 }
99
100 object->engine = engcls;
101 return 0;
102}
103
104void
105nouveau_parent_destroy(struct nouveau_parent *parent)
106{
107 struct nouveau_sclass *sclass;
108
109 while ((sclass = parent->sclass)) {
110 parent->sclass = sclass->sclass;
111 kfree(sclass);
112 }
113
114 nouveau_object_destroy(&parent->base);
115}
116
117
118void
119_nouveau_parent_dtor(struct nouveau_object *object)
120{
121 nouveau_parent_destroy(nv_parent(object));
122}
123