1 | /* $NetBSD: nouveau_core_parent.c,v 1.1.1.1 2014/08/06 12:36:24 riastradh Exp $ */ |
2 | |
3 | /* |
4 | * Copyright 2012 Red Hat Inc. |
5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
7 | * copy of this software and associated documentation files (the "Software"), |
8 | * to deal in the Software without restriction, including without limitation |
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
10 | * and/or sell copies of the Software, and to permit persons to whom the |
11 | * Software is furnished to do so, subject to the following conditions: |
12 | * |
13 | * The above copyright notice and this permission notice shall be included in |
14 | * all copies or substantial portions of the Software. |
15 | * |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
22 | * OTHER DEALINGS IN THE SOFTWARE. |
23 | * |
24 | * Authors: Ben Skeggs |
25 | */ |
26 | |
27 | #include <sys/cdefs.h> |
28 | __KERNEL_RCSID(0, "$NetBSD: nouveau_core_parent.c,v 1.1.1.1 2014/08/06 12:36:24 riastradh Exp $" ); |
29 | |
30 | #include <core/object.h> |
31 | #include <core/parent.h> |
32 | #include <core/client.h> |
33 | |
34 | int |
35 | nouveau_parent_sclass(struct nouveau_object *parent, u16 handle, |
36 | struct nouveau_object **pengine, |
37 | struct nouveau_oclass **poclass) |
38 | { |
39 | struct nouveau_sclass *sclass; |
40 | struct nouveau_engine *engine; |
41 | struct nouveau_oclass *oclass; |
42 | u64 mask; |
43 | |
44 | sclass = nv_parent(parent)->sclass; |
45 | while (sclass) { |
46 | if ((sclass->oclass->handle & 0xffff) == handle) { |
47 | *pengine = parent->engine; |
48 | *poclass = sclass->oclass; |
49 | return 0; |
50 | } |
51 | |
52 | sclass = sclass->sclass; |
53 | } |
54 | |
55 | mask = nv_parent(parent)->engine; |
56 | while (mask) { |
57 | int i = __ffs64(mask); |
58 | |
59 | if (nv_iclass(parent, NV_CLIENT_CLASS)) |
60 | engine = nv_engine(nv_client(parent)->device); |
61 | else |
62 | engine = nouveau_engine(parent, i); |
63 | |
64 | if (engine) { |
65 | oclass = engine->sclass; |
66 | while (oclass->ofuncs) { |
67 | if ((oclass->handle & 0xffff) == handle) { |
68 | *pengine = nv_object(engine); |
69 | *poclass = oclass; |
70 | return 0; |
71 | } |
72 | oclass++; |
73 | } |
74 | } |
75 | |
76 | mask &= ~(1ULL << i); |
77 | } |
78 | |
79 | return -EINVAL; |
80 | } |
81 | |
82 | int |
83 | nouveau_parent_create_(struct nouveau_object *parent, |
84 | struct nouveau_object *engine, |
85 | struct nouveau_oclass *oclass, u32 pclass, |
86 | struct nouveau_oclass *sclass, u64 engcls, |
87 | int size, void **pobject) |
88 | { |
89 | struct nouveau_parent *object; |
90 | struct nouveau_sclass *nclass; |
91 | int ret; |
92 | |
93 | ret = nouveau_object_create_(parent, engine, oclass, pclass | |
94 | NV_PARENT_CLASS, size, pobject); |
95 | object = *pobject; |
96 | if (ret) |
97 | return ret; |
98 | |
99 | while (sclass && sclass->ofuncs) { |
100 | nclass = kzalloc(sizeof(*nclass), GFP_KERNEL); |
101 | if (!nclass) |
102 | return -ENOMEM; |
103 | |
104 | nclass->sclass = object->sclass; |
105 | object->sclass = nclass; |
106 | nclass->engine = engine ? nv_engine(engine) : NULL; |
107 | nclass->oclass = sclass; |
108 | sclass++; |
109 | } |
110 | |
111 | object->engine = engcls; |
112 | return 0; |
113 | } |
114 | |
115 | void |
116 | nouveau_parent_destroy(struct nouveau_parent *parent) |
117 | { |
118 | struct nouveau_sclass *sclass; |
119 | |
120 | while ((sclass = parent->sclass)) { |
121 | parent->sclass = sclass->sclass; |
122 | kfree(sclass); |
123 | } |
124 | |
125 | nouveau_object_destroy(&parent->base); |
126 | } |
127 | |
128 | |
129 | void |
130 | _nouveau_parent_dtor(struct nouveau_object *object) |
131 | { |
132 | nouveau_parent_destroy(nv_parent(object)); |
133 | } |
134 | |