This source file includes following definitions.
- vmw_simple_resource_init
- vmw_simple_resource_free
- vmw_simple_resource_base_release
- vmw_simple_resource_create_ioctl
- vmw_simple_resource_lookup
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
26
27
28 #include "vmwgfx_drv.h"
29 #include "vmwgfx_resource_priv.h"
30
31
32
33
34
35
36
37
38 struct vmw_user_simple_resource {
39 struct ttm_base_object base;
40 size_t account_size;
41 struct vmw_simple_resource simple;
42
43
44
45
46 };
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 static int vmw_simple_resource_init(struct vmw_private *dev_priv,
63 struct vmw_simple_resource *simple,
64 void *data,
65 void (*res_free)(struct vmw_resource *res))
66 {
67 struct vmw_resource *res = &simple->res;
68 int ret;
69
70 ret = vmw_resource_init(dev_priv, res, false, res_free,
71 &simple->func->res_func);
72
73 if (ret) {
74 res_free(res);
75 return ret;
76 }
77
78 ret = simple->func->init(res, data);
79 if (ret) {
80 vmw_resource_unreference(&res);
81 return ret;
82 }
83
84 simple->res.hw_destroy = simple->func->hw_destroy;
85
86 return 0;
87 }
88
89
90
91
92
93
94
95
96 static void vmw_simple_resource_free(struct vmw_resource *res)
97 {
98 struct vmw_user_simple_resource *usimple =
99 container_of(res, struct vmw_user_simple_resource,
100 simple.res);
101 struct vmw_private *dev_priv = res->dev_priv;
102 size_t size = usimple->account_size;
103
104 ttm_base_object_kfree(usimple, base);
105 ttm_mem_global_free(vmw_mem_glob(dev_priv), size);
106 }
107
108
109
110
111
112
113
114
115
116
117 static void vmw_simple_resource_base_release(struct ttm_base_object **p_base)
118 {
119 struct ttm_base_object *base = *p_base;
120 struct vmw_user_simple_resource *usimple =
121 container_of(base, struct vmw_user_simple_resource, base);
122 struct vmw_resource *res = &usimple->simple.res;
123
124 *p_base = NULL;
125 vmw_resource_unreference(&res);
126 }
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142 int
143 vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,
144 struct drm_file *file_priv,
145 const struct vmw_simple_resource_func *func)
146 {
147 struct vmw_private *dev_priv = vmw_priv(dev);
148 struct vmw_user_simple_resource *usimple;
149 struct vmw_resource *res;
150 struct vmw_resource *tmp;
151 struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
152 struct ttm_operation_ctx ctx = {
153 .interruptible = true,
154 .no_wait_gpu = false
155 };
156 size_t alloc_size;
157 size_t account_size;
158 int ret;
159
160 alloc_size = offsetof(struct vmw_user_simple_resource, simple) +
161 func->size;
162 account_size = ttm_round_pot(alloc_size) + VMW_IDA_ACC_SIZE +
163 TTM_OBJ_EXTRA_SIZE;
164
165 ret = ttm_read_lock(&dev_priv->reservation_sem, true);
166 if (ret)
167 return ret;
168
169 ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), account_size,
170 &ctx);
171 ttm_read_unlock(&dev_priv->reservation_sem);
172 if (ret) {
173 if (ret != -ERESTARTSYS)
174 DRM_ERROR("Out of graphics memory for %s"
175 " creation.\n", func->res_func.type_name);
176
177 goto out_ret;
178 }
179
180 usimple = kzalloc(alloc_size, GFP_KERNEL);
181 if (!usimple) {
182 ttm_mem_global_free(vmw_mem_glob(dev_priv),
183 account_size);
184 ret = -ENOMEM;
185 goto out_ret;
186 }
187
188 usimple->simple.func = func;
189 usimple->account_size = account_size;
190 res = &usimple->simple.res;
191 usimple->base.shareable = false;
192 usimple->base.tfile = NULL;
193
194
195
196
197 ret = vmw_simple_resource_init(dev_priv, &usimple->simple,
198 data, vmw_simple_resource_free);
199 if (ret)
200 goto out_ret;
201
202 tmp = vmw_resource_reference(res);
203 ret = ttm_base_object_init(tfile, &usimple->base, false,
204 func->ttm_res_type,
205 &vmw_simple_resource_base_release, NULL);
206
207 if (ret) {
208 vmw_resource_unreference(&tmp);
209 goto out_err;
210 }
211
212 func->set_arg_handle(data, usimple->base.handle);
213 out_err:
214 vmw_resource_unreference(&res);
215 out_ret:
216 return ret;
217 }
218
219
220
221
222
223
224
225
226
227
228
229
230
231 struct vmw_resource *
232 vmw_simple_resource_lookup(struct ttm_object_file *tfile,
233 uint32_t handle,
234 const struct vmw_simple_resource_func *func)
235 {
236 struct vmw_user_simple_resource *usimple;
237 struct ttm_base_object *base;
238 struct vmw_resource *res;
239
240 base = ttm_base_object_lookup(tfile, handle);
241 if (!base) {
242 VMW_DEBUG_USER("Invalid %s handle 0x%08lx.\n",
243 func->res_func.type_name,
244 (unsigned long) handle);
245 return ERR_PTR(-ESRCH);
246 }
247
248 if (ttm_base_object_type(base) != func->ttm_res_type) {
249 ttm_base_object_unref(&base);
250 VMW_DEBUG_USER("Invalid type of %s handle 0x%08lx.\n",
251 func->res_func.type_name,
252 (unsigned long) handle);
253 return ERR_PTR(-EINVAL);
254 }
255
256 usimple = container_of(base, typeof(*usimple), base);
257 res = vmw_resource_reference(&usimple->simple.res);
258 ttm_base_object_unref(&base);
259
260 return res;
261 }