2 * Copyright 2007 Nouveau Project
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #include "nouveau_drmif.h"
29 nouveau_grobj_alloc(struct nouveau_channel *userchan, uint32_t handle,
30 int class, struct nouveau_grobj **usergrobj)
32 struct nouveau_device_priv *nv = nouveau_device(userchan->device);
33 struct nouveau_grobj_priv *gr;
34 struct drm_nouveau_grobj_alloc g;
37 if (!nv || !usergrobj || *usergrobj)
40 gr = calloc(1, sizeof(*gr));
43 gr->base.channel = userchan;
44 gr->base.handle = handle;
45 gr->base.grclass = class;
47 g.channel = userchan->id;
50 ret = drmCommandWrite(nv->fd, DRM_NOUVEAU_GROBJ_ALLOC, &g, sizeof(g));
52 nouveau_grobj_free((void *)&gr);
56 *usergrobj = &gr->base;
61 nouveau_grobj_ref(struct nouveau_channel *userchan, uint32_t handle,
62 struct nouveau_grobj **usergr)
64 struct nouveau_grobj_priv *gr;
66 if (!userchan || !usergr || *usergr)
69 gr = calloc(1, sizeof(*gr));
72 gr->base.channel = userchan;
73 gr->base.handle = handle;
81 nouveau_grobj_free(struct nouveau_grobj **usergrobj)
83 struct nouveau_grobj_priv *gr;
87 gr = nouveau_grobj(*usergrobj);
91 struct nouveau_channel_priv *chan;
92 struct nouveau_device_priv *nv;
93 struct drm_nouveau_gpuobj_free f;
95 chan = nouveau_channel(gr->base.channel);
96 nv = nouveau_device(chan->base.device);
98 if (gr->base.grclass) {
99 f.channel = chan->drm.channel;
100 f.handle = gr->base.handle;
101 drmCommandWrite(nv->fd, DRM_NOUVEAU_GPUOBJ_FREE,