• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>
27 #include <core/client.h>
28 
29 int
nouveau_parent_sclass(struct nouveau_object * parent,u16 handle,struct nouveau_object ** pengine,struct nouveau_oclass ** poclass)30 nouveau_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 
77 int
nouveau_parent_create_(struct nouveau_object * parent,struct nouveau_object * engine,struct nouveau_oclass * oclass,u32 pclass,struct nouveau_oclass * sclass,u64 engcls,int size,void ** pobject)78 nouveau_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 
110 void
nouveau_parent_destroy(struct nouveau_parent * parent)111 nouveau_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 
124 void
_nouveau_parent_dtor(struct nouveau_object * object)125 _nouveau_parent_dtor(struct nouveau_object *object)
126 {
127 	nouveau_parent_destroy(nv_parent(object));
128 }
129