Set memory attributes on page
[pscnv.git] / pscnv / pscnv_gem.c
blob0ef5cdee356bc4ea4ec501856ead06070d130873
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2010 PathScale Inc. All rights reserved.
24 * Use is subject to license terms.
27 #include "drm.h"
28 #include "nouveau_drv.h"
29 #include "pscnv_gem.h"
30 #include "pscnv_mem.h"
31 #include "pscnv_drm.h"
33 void pscnv_gem_free_object (struct drm_gem_object *obj) {
34 struct pscnv_bo *vo = obj->driver_private;
35 #ifndef PSCNV_KAPI_DRM_GEM_OBJECT_HANDLE_COUNT
36 atomic_dec(&obj->handle_count);
37 #endif
38 if (!vo->chan)
39 pscnv_mem_free(vo);
40 else
41 vo->gem = 0;
42 #ifndef __linux__
43 drm_gem_free_mmap_offset(obj);
44 #endif
45 drm_gem_object_release(obj);
46 kfree(obj);
49 struct drm_gem_object *pscnv_gem_wrap(struct drm_device *dev, struct pscnv_bo *vo)
51 struct drm_gem_object *obj;
53 obj = drm_gem_object_alloc(dev, vo->size);
54 if (!obj)
55 return 0;
56 #ifndef __linux__
57 if (drm_gem_create_mmap_offset(obj) != 0) {
58 drm_gem_object_handle_unreference_unlocked(obj);
59 return 0;
61 #endif
63 #ifndef PSCNV_KAPI_DRM_GEM_OBJECT_HANDLE_COUNT
64 atomic_inc(&obj->handle_count);
65 #endif
66 obj->driver_private = vo;
67 vo->gem = obj;
68 return obj;
71 struct drm_gem_object *pscnv_gem_new(struct drm_device *dev, uint64_t size, uint32_t flags,
72 uint32_t tile_flags, uint32_t cookie, uint32_t *user)
74 int i;
75 struct pscnv_bo *vo = pscnv_mem_alloc(dev, size, flags, tile_flags, cookie);
76 struct drm_gem_object *obj;
77 if (!vo)
78 return 0;
80 if (!(obj = pscnv_gem_wrap(dev, vo)))
81 pscnv_mem_free(vo);
82 else if (user)
83 for (i = 0; i < DRM_ARRAY_SIZE(vo->user); i++)
84 vo->user[i] = user[i];
85 else
86 for (i = 0; i < DRM_ARRAY_SIZE(vo->user); i++)
87 vo->user[i] = 0;
89 return obj;