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
*chan
, uint32_t handle
,
30 int class, struct nouveau_grobj
**grobj
)
32 struct nouveau_device_priv
*nvdev
= nouveau_device(chan
->device
);
33 struct nouveau_grobj_priv
*nvgrobj
;
34 struct drm_nouveau_grobj_alloc g
;
37 if (!nvdev
|| !grobj
|| *grobj
)
40 nvgrobj
= calloc(1, sizeof(*nvgrobj
));
43 nvgrobj
->base
.channel
= chan
;
44 nvgrobj
->base
.handle
= handle
;
45 nvgrobj
->base
.grclass
= class;
50 ret
= drmCommandWrite(nvdev
->fd
, DRM_NOUVEAU_GROBJ_ALLOC
,
53 nouveau_grobj_free((void *)&nvgrobj
);
57 *grobj
= &nvgrobj
->base
;
62 nouveau_grobj_ref(struct nouveau_channel
*chan
, uint32_t handle
,
63 struct nouveau_grobj
**grobj
)
65 struct nouveau_grobj_priv
*nvgrobj
;
67 if (!chan
|| !grobj
|| *grobj
)
70 nvgrobj
= calloc(1, sizeof(struct nouveau_grobj_priv
));
73 nvgrobj
->base
.channel
= chan
;
74 nvgrobj
->base
.handle
= handle
;
75 nvgrobj
->base
.grclass
= 0;
77 *grobj
= &nvgrobj
->base
;
82 nouveau_grobj_free(struct nouveau_grobj
**grobj
)
84 struct nouveau_device_priv
*nvdev
;
85 struct nouveau_channel_priv
*chan
;
86 struct nouveau_grobj_priv
*nvgrobj
;
88 if (!grobj
|| !*grobj
)
90 nvgrobj
= nouveau_grobj(*grobj
);
94 chan
= nouveau_channel(nvgrobj
->base
.channel
);
95 nvdev
= nouveau_device(chan
->base
.device
);
97 if (nvgrobj
->base
.grclass
) {
98 struct drm_nouveau_gpuobj_free f
;
100 f
.channel
= chan
->drm
.channel
;
101 f
.handle
= nvgrobj
->base
.handle
;
102 drmCommandWrite(nvdev
->fd
, DRM_NOUVEAU_GPUOBJ_FREE
,