diff options
author | Daniel Vetter <daniel.vetter@ffwll.ch> | 2010-04-09 15:05:04 -0400 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2010-04-19 23:19:25 -0400 |
commit | 1d397043bcc2c8cdccb584a8ef73131f28f18e4c (patch) | |
tree | 564c09e78bffef21ff65988ea76380db132cc02a | |
parent | 153549b8b63d71a9c5d8cbde887097b995c32bd6 (diff) |
drm: extract drm_gem_object_init
This function can be used by drivers who allocate the drm gem object
on their own. No functional change in here, just preparation.
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Acked-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Dave Airlie <airlied@redhat.com>
-rw-r--r-- | drivers/gpu/drm/drm_gem.c | 39 | ||||
-rw-r--r-- | include/drm/drmP.h | 2 |
2 files changed, 31 insertions, 10 deletions
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index aa89d4b0b4c4..3b64d0ef1998 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c | |||
@@ -124,6 +124,31 @@ drm_gem_destroy(struct drm_device *dev) | |||
124 | } | 124 | } |
125 | 125 | ||
126 | /** | 126 | /** |
127 | * Initialize an already allocate GEM object of the specified size with | ||
128 | * shmfs backing store. | ||
129 | */ | ||
130 | int drm_gem_object_init(struct drm_device *dev, | ||
131 | struct drm_gem_object *obj, size_t size) | ||
132 | { | ||
133 | BUG_ON((size & (PAGE_SIZE - 1)) != 0); | ||
134 | |||
135 | obj->dev = dev; | ||
136 | obj->filp = shmem_file_setup("drm mm object", size, VM_NORESERVE); | ||
137 | if (IS_ERR(obj->filp)) | ||
138 | return -ENOMEM; | ||
139 | |||
140 | kref_init(&obj->refcount); | ||
141 | kref_init(&obj->handlecount); | ||
142 | obj->size = size; | ||
143 | |||
144 | atomic_inc(&dev->object_count); | ||
145 | atomic_add(obj->size, &dev->object_memory); | ||
146 | |||
147 | return 0; | ||
148 | } | ||
149 | EXPORT_SYMBOL(drm_gem_object_init); | ||
150 | |||
151 | /** | ||
127 | * Allocate a GEM object of the specified size with shmfs backing store | 152 | * Allocate a GEM object of the specified size with shmfs backing store |
128 | */ | 153 | */ |
129 | struct drm_gem_object * | 154 | struct drm_gem_object * |
@@ -131,28 +156,22 @@ drm_gem_object_alloc(struct drm_device *dev, size_t size) | |||
131 | { | 156 | { |
132 | struct drm_gem_object *obj; | 157 | struct drm_gem_object *obj; |
133 | 158 | ||
134 | BUG_ON((size & (PAGE_SIZE - 1)) != 0); | ||
135 | |||
136 | obj = kzalloc(sizeof(*obj), GFP_KERNEL); | 159 | obj = kzalloc(sizeof(*obj), GFP_KERNEL); |
137 | if (!obj) | 160 | if (!obj) |
138 | goto free; | 161 | goto free; |
139 | 162 | ||
140 | obj->dev = dev; | 163 | if (drm_gem_object_init(dev, obj, size) != 0) |
141 | obj->filp = shmem_file_setup("drm mm object", size, VM_NORESERVE); | ||
142 | if (IS_ERR(obj->filp)) | ||
143 | goto free; | 164 | goto free; |
144 | 165 | ||
145 | kref_init(&obj->refcount); | ||
146 | kref_init(&obj->handlecount); | ||
147 | obj->size = size; | ||
148 | if (dev->driver->gem_init_object != NULL && | 166 | if (dev->driver->gem_init_object != NULL && |
149 | dev->driver->gem_init_object(obj) != 0) { | 167 | dev->driver->gem_init_object(obj) != 0) { |
150 | goto fput; | 168 | goto fput; |
151 | } | 169 | } |
152 | atomic_inc(&dev->object_count); | ||
153 | atomic_add(obj->size, &dev->object_memory); | ||
154 | return obj; | 170 | return obj; |
155 | fput: | 171 | fput: |
172 | /* Object_init mangles the global counters - readjust them. */ | ||
173 | atomic_dec(&dev->object_count); | ||
174 | atomic_sub(obj->size, &dev->object_memory); | ||
156 | fput(obj->filp); | 175 | fput(obj->filp); |
157 | free: | 176 | free: |
158 | kfree(obj); | 177 | kfree(obj); |
diff --git a/include/drm/drmP.h b/include/drm/drmP.h index 2f3b3a00b7a3..b3b57b561b92 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h | |||
@@ -1432,6 +1432,8 @@ void drm_gem_object_free(struct kref *kref); | |||
1432 | void drm_gem_object_free_unlocked(struct kref *kref); | 1432 | void drm_gem_object_free_unlocked(struct kref *kref); |
1433 | struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev, | 1433 | struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev, |
1434 | size_t size); | 1434 | size_t size); |
1435 | int drm_gem_object_init(struct drm_device *dev, | ||
1436 | struct drm_gem_object *obj, size_t size); | ||
1435 | void drm_gem_object_handle_free(struct kref *kref); | 1437 | void drm_gem_object_handle_free(struct kref *kref); |
1436 | void drm_gem_vm_open(struct vm_area_struct *vma); | 1438 | void drm_gem_vm_open(struct vm_area_struct *vma); |
1437 | void drm_gem_vm_close(struct vm_area_struct *vma); | 1439 | void drm_gem_vm_close(struct vm_area_struct *vma); |