drm/nouveau/core: object.engine is always a nouveau_engine now
[deliverable/linux.git] / drivers / gpu / drm / nouveau / core / core / parent.c
CommitLineData
9274f4a9
BS
1/*
2 * Copyright 2012 Red Hat Inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
22 * Authors: Ben Skeggs
23 */
24
25#include <core/object.h>
26#include <core/parent.h>
9aecbada 27#include <core/client.h>
9274f4a9
BS
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) {
ec0e5542 42 *pengine = &parent->engine->subdev.object;
9274f4a9
BS
43 *poclass = sclass->oclass;
44 return 0;
45 }
46
47 sclass = sclass->sclass;
48 }
49
50 mask = nv_parent(parent)->engine;
51 while (mask) {
73970c47 52 int i = __ffs64(mask);
9274f4a9 53
9aecbada
BS
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) {
9274f4a9
BS
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
29dff2f5
BS
77int
78nouveau_parent_lclass(struct nouveau_object *parent, u32 *lclass, int size)
79{
80 struct nouveau_sclass *sclass;
81 struct nouveau_engine *engine;
82 struct nouveau_oclass *oclass;
83 int nr = -1, i;
84 u64 mask;
85
86 sclass = nv_parent(parent)->sclass;
87 while (sclass) {
88 if (++nr < size)
2acc8683 89 lclass[nr] = sclass->oclass->handle & 0xffff;
29dff2f5
BS
90 sclass = sclass->sclass;
91 }
92
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) {
98 if (++nr < size)
2acc8683 99 lclass[nr] = oclass->handle & 0xffff;
29dff2f5
BS
100 oclass++;
101 }
102 }
103
104 mask &= ~(1ULL << i);
105 }
106
107 return nr + 1;
108}
109
9274f4a9
BS
110int
111nouveau_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)
116{
117 struct nouveau_parent *object;
118 struct nouveau_sclass *nclass;
119 int ret;
120
121 ret = nouveau_object_create_(parent, engine, oclass, pclass |
122 NV_PARENT_CLASS, size, pobject);
123 object = *pobject;
124 if (ret)
125 return ret;
126
127 while (sclass && sclass->ofuncs) {
128 nclass = kzalloc(sizeof(*nclass), GFP_KERNEL);
129 if (!nclass)
130 return -ENOMEM;
131
132 nclass->sclass = object->sclass;
133 object->sclass = nclass;
134 nclass->engine = engine ? nv_engine(engine) : NULL;
135 nclass->oclass = sclass;
136 sclass++;
137 }
138
139 object->engine = engcls;
140 return 0;
141}
142
9274f4a9
BS
143void
144nouveau_parent_destroy(struct nouveau_parent *parent)
145{
146 struct nouveau_sclass *sclass;
147
148 while ((sclass = parent->sclass)) {
149 parent->sclass = sclass->sclass;
150 kfree(sclass);
151 }
152
587f7a5b 153 nouveau_object_destroy(&parent->object);
9274f4a9
BS
154}
155
156
157void
158_nouveau_parent_dtor(struct nouveau_object *object)
159{
160 nouveau_parent_destroy(nv_parent(object));
161}
This page took 0.164763 seconds and 5 git commands to generate.