Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* i915_mem.c -- Simple agp/fb memory manager for i915 -*- linux-c -*- |
| 2 | */ |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 3 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. |
| 5 | * All Rights Reserved. |
Dave Airlie | bc54fd1 | 2005-06-23 22:46:46 +1000 | [diff] [blame] | 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the |
| 9 | * "Software"), to deal in the Software without restriction, including |
| 10 | * without limitation the rights to use, copy, modify, merge, publish, |
| 11 | * distribute, sub license, and/or sell copies of the Software, and to |
| 12 | * permit persons to whom the Software is furnished to do so, subject to |
| 13 | * the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice (including the |
| 16 | * next paragraph) shall be included in all copies or substantial portions |
| 17 | * of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
| 22 | * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR |
| 23 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 24 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 25 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 26 | * |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 27 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | #include "drmP.h" |
| 30 | #include "drm.h" |
| 31 | #include "i915_drm.h" |
| 32 | #include "i915_drv.h" |
| 33 | |
| 34 | /* This memory manager is integrated into the global/local lru |
| 35 | * mechanisms used by the clients. Specifically, it operates by |
| 36 | * setting the 'in_use' fields of the global LRU to indicate whether |
| 37 | * this region is privately allocated to a client. |
| 38 | * |
| 39 | * This does require the client to actually respect that field. |
| 40 | * |
| 41 | * Currently no effort is made to allocate 'private' memory in any |
| 42 | * clever way - the LRU information isn't used to determine which |
| 43 | * block to allocate, and the ring is drained prior to allocations -- |
| 44 | * in other words allocation is expensive. |
| 45 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 46 | static void mark_block(struct drm_device * dev, struct mem_block *p, int in_use) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
| 48 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 49 | drm_i915_sarea_t *sarea_priv = dev_priv->sarea_priv; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 50 | struct drm_tex_region *list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | unsigned shift, nr; |
| 52 | unsigned start; |
| 53 | unsigned end; |
| 54 | unsigned i; |
| 55 | int age; |
| 56 | |
| 57 | shift = dev_priv->tex_lru_log_granularity; |
| 58 | nr = I915_NR_TEX_REGIONS; |
| 59 | |
| 60 | start = p->start >> shift; |
| 61 | end = (p->start + p->size - 1) >> shift; |
| 62 | |
| 63 | age = ++sarea_priv->texAge; |
| 64 | list = sarea_priv->texList; |
| 65 | |
| 66 | /* Mark the regions with the new flag and update their age. Move |
| 67 | * them to head of list to preserve LRU semantics. |
| 68 | */ |
| 69 | for (i = start; i <= end; i++) { |
| 70 | list[i].in_use = in_use; |
| 71 | list[i].age = age; |
| 72 | |
| 73 | /* remove_from_list(i) |
| 74 | */ |
| 75 | list[(unsigned)list[i].next].prev = list[i].prev; |
| 76 | list[(unsigned)list[i].prev].next = list[i].next; |
| 77 | |
| 78 | /* insert_at_head(list, i) |
| 79 | */ |
| 80 | list[i].prev = nr; |
| 81 | list[i].next = list[nr].next; |
| 82 | list[(unsigned)list[nr].next].prev = i; |
| 83 | list[nr].next = i; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /* Very simple allocator for agp memory, working on a static range |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 88 | * already mapped into each client's address space. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | */ |
| 90 | |
| 91 | static struct mem_block *split_block(struct mem_block *p, int start, int size, |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 92 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
| 94 | /* Maybe cut off the start of an existing block */ |
| 95 | if (start > p->start) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 96 | struct mem_block *newblock = |
| 97 | drm_alloc(sizeof(*newblock), DRM_MEM_BUFLISTS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | if (!newblock) |
| 99 | goto out; |
| 100 | newblock->start = start; |
| 101 | newblock->size = p->size - (start - p->start); |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 102 | newblock->file_priv = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | newblock->next = p->next; |
| 104 | newblock->prev = p; |
| 105 | p->next->prev = newblock; |
| 106 | p->next = newblock; |
| 107 | p->size -= newblock->size; |
| 108 | p = newblock; |
| 109 | } |
| 110 | |
| 111 | /* Maybe cut off the end of an existing block */ |
| 112 | if (size < p->size) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 113 | struct mem_block *newblock = |
| 114 | drm_alloc(sizeof(*newblock), DRM_MEM_BUFLISTS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | if (!newblock) |
| 116 | goto out; |
| 117 | newblock->start = start + size; |
| 118 | newblock->size = p->size - size; |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 119 | newblock->file_priv = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | newblock->next = p->next; |
| 121 | newblock->prev = p; |
| 122 | p->next->prev = newblock; |
| 123 | p->next = newblock; |
| 124 | p->size = size; |
| 125 | } |
| 126 | |
| 127 | out: |
| 128 | /* Our block is in the middle */ |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 129 | p->file_priv = file_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | return p; |
| 131 | } |
| 132 | |
| 133 | static struct mem_block *alloc_block(struct mem_block *heap, int size, |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 134 | int align2, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | { |
| 136 | struct mem_block *p; |
| 137 | int mask = (1 << align2) - 1; |
| 138 | |
| 139 | for (p = heap->next; p != heap; p = p->next) { |
| 140 | int start = (p->start + mask) & ~mask; |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 141 | if (p->file_priv == NULL && start + size <= p->start + p->size) |
| 142 | return split_block(p, start, size, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | return NULL; |
| 146 | } |
| 147 | |
| 148 | static struct mem_block *find_block(struct mem_block *heap, int start) |
| 149 | { |
| 150 | struct mem_block *p; |
| 151 | |
| 152 | for (p = heap->next; p != heap; p = p->next) |
| 153 | if (p->start == start) |
| 154 | return p; |
| 155 | |
| 156 | return NULL; |
| 157 | } |
| 158 | |
| 159 | static void free_block(struct mem_block *p) |
| 160 | { |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 161 | p->file_priv = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 163 | /* Assumes a single contiguous range. Needs a special file_priv in |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | * 'heap' to stop it being subsumed. |
| 165 | */ |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 166 | if (p->next->file_priv == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | struct mem_block *q = p->next; |
| 168 | p->size += q->size; |
| 169 | p->next = q->next; |
| 170 | p->next->prev = p; |
| 171 | drm_free(q, sizeof(*q), DRM_MEM_BUFLISTS); |
| 172 | } |
| 173 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 174 | if (p->prev->file_priv == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | struct mem_block *q = p->prev; |
| 176 | q->size += p->size; |
| 177 | q->next = p->next; |
| 178 | q->next->prev = q; |
| 179 | drm_free(p, sizeof(*q), DRM_MEM_BUFLISTS); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | /* Initialize. How to check for an uninitialized heap? |
| 184 | */ |
| 185 | static int init_heap(struct mem_block **heap, int start, int size) |
| 186 | { |
| 187 | struct mem_block *blocks = drm_alloc(sizeof(*blocks), DRM_MEM_BUFLISTS); |
| 188 | |
| 189 | if (!blocks) |
| 190 | return -ENOMEM; |
| 191 | |
| 192 | *heap = drm_alloc(sizeof(**heap), DRM_MEM_BUFLISTS); |
| 193 | if (!*heap) { |
| 194 | drm_free(blocks, sizeof(*blocks), DRM_MEM_BUFLISTS); |
| 195 | return -ENOMEM; |
| 196 | } |
| 197 | |
| 198 | blocks->start = start; |
| 199 | blocks->size = size; |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 200 | blocks->file_priv = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | blocks->next = blocks->prev = *heap; |
| 202 | |
| 203 | memset(*heap, 0, sizeof(**heap)); |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 204 | (*heap)->file_priv = (struct drm_file *) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | (*heap)->next = (*heap)->prev = blocks; |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | /* Free all blocks associated with the releasing file. |
| 210 | */ |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 211 | void i915_mem_release(struct drm_device * dev, struct drm_file *file_priv, |
| 212 | struct mem_block *heap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | { |
| 214 | struct mem_block *p; |
| 215 | |
| 216 | if (!heap || !heap->next) |
| 217 | return; |
| 218 | |
| 219 | for (p = heap->next; p != heap; p = p->next) { |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 220 | if (p->file_priv == file_priv) { |
| 221 | p->file_priv = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | mark_block(dev, p, 0); |
| 223 | } |
| 224 | } |
| 225 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 226 | /* Assumes a single contiguous range. Needs a special file_priv in |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | * 'heap' to stop it being subsumed. |
| 228 | */ |
| 229 | for (p = heap->next; p != heap; p = p->next) { |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 230 | while (p->file_priv == NULL && p->next->file_priv == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | struct mem_block *q = p->next; |
| 232 | p->size += q->size; |
| 233 | p->next = q->next; |
| 234 | p->next->prev = p; |
| 235 | drm_free(q, sizeof(*q), DRM_MEM_BUFLISTS); |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | /* Shutdown. |
| 241 | */ |
| 242 | void i915_mem_takedown(struct mem_block **heap) |
| 243 | { |
| 244 | struct mem_block *p; |
| 245 | |
| 246 | if (!*heap) |
| 247 | return; |
| 248 | |
| 249 | for (p = (*heap)->next; p != *heap;) { |
| 250 | struct mem_block *q = p; |
| 251 | p = p->next; |
| 252 | drm_free(q, sizeof(*q), DRM_MEM_BUFLISTS); |
| 253 | } |
| 254 | |
| 255 | drm_free(*heap, sizeof(**heap), DRM_MEM_BUFLISTS); |
| 256 | *heap = NULL; |
| 257 | } |
| 258 | |
| 259 | static struct mem_block **get_heap(drm_i915_private_t * dev_priv, int region) |
| 260 | { |
| 261 | switch (region) { |
| 262 | case I915_MEM_REGION_AGP: |
| 263 | return &dev_priv->agp_heap; |
| 264 | default: |
| 265 | return NULL; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | /* IOCTL HANDLERS */ |
| 270 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 271 | int i915_mem_alloc(struct drm_device *dev, void *data, |
| 272 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 275 | drm_i915_mem_alloc_t *alloc = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | struct mem_block *block, **heap; |
| 277 | |
| 278 | if (!dev_priv) { |
| 279 | DRM_ERROR("%s called with no initialization\n", __FUNCTION__); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 280 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 283 | heap = get_heap(dev_priv, alloc->region); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | if (!heap || !*heap) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 285 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
| 287 | /* Make things easier on ourselves: all allocations at least |
| 288 | * 4k aligned. |
| 289 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 290 | if (alloc->alignment < 12) |
| 291 | alloc->alignment = 12; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 293 | block = alloc_block(*heap, alloc->size, alloc->alignment, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
| 295 | if (!block) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 296 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
| 298 | mark_block(dev, block, 1); |
| 299 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 300 | if (DRM_COPY_TO_USER(alloc->region_offset, &block->start, |
| 301 | sizeof(int))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | DRM_ERROR("copy_to_user\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 303 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | return 0; |
| 307 | } |
| 308 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 309 | int i915_mem_free(struct drm_device *dev, void *data, |
| 310 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 313 | drm_i915_mem_free_t *memfree = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | struct mem_block *block, **heap; |
| 315 | |
| 316 | if (!dev_priv) { |
| 317 | DRM_ERROR("%s called with no initialization\n", __FUNCTION__); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 318 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 321 | heap = get_heap(dev_priv, memfree->region); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | if (!heap || !*heap) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 323 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 325 | block = find_block(*heap, memfree->region_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | if (!block) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 327 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 329 | if (block->file_priv != file_priv) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 330 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
| 332 | mark_block(dev, block, 0); |
| 333 | free_block(block); |
| 334 | return 0; |
| 335 | } |
| 336 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 337 | int i915_mem_init_heap(struct drm_device *dev, void *data, |
| 338 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 341 | drm_i915_mem_init_heap_t *initheap = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | struct mem_block **heap; |
| 343 | |
| 344 | if (!dev_priv) { |
| 345 | DRM_ERROR("%s called with no initialization\n", __FUNCTION__); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 346 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 349 | heap = get_heap(dev_priv, initheap->region); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | if (!heap) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 351 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
| 353 | if (*heap) { |
| 354 | DRM_ERROR("heap already initialized?"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 355 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 358 | return init_heap(heap, initheap->start, initheap->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 360 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 361 | int i915_mem_destroy_heap( struct drm_device *dev, void *data, |
| 362 | struct drm_file *file_priv ) |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 363 | { |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 364 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 365 | drm_i915_mem_destroy_heap_t *destroyheap = data; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 366 | struct mem_block **heap; |
| 367 | |
| 368 | if ( !dev_priv ) { |
| 369 | DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ ); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 370 | return -EINVAL; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 371 | } |
| 372 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 373 | heap = get_heap( dev_priv, destroyheap->region ); |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 374 | if (!heap) { |
| 375 | DRM_ERROR("get_heap failed"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 376 | return -EFAULT; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | if (!*heap) { |
| 380 | DRM_ERROR("heap not initialized?"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 381 | return -EFAULT; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | i915_mem_takedown( heap ); |
| 385 | return 0; |
| 386 | } |
| 387 | |