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; |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 49 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
| 50 | drm_i915_sarea_t *sarea_priv = master_priv->sarea_priv; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 51 | struct drm_tex_region *list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | unsigned shift, nr; |
| 53 | unsigned start; |
| 54 | unsigned end; |
| 55 | unsigned i; |
| 56 | int age; |
| 57 | |
| 58 | shift = dev_priv->tex_lru_log_granularity; |
| 59 | nr = I915_NR_TEX_REGIONS; |
| 60 | |
| 61 | start = p->start >> shift; |
| 62 | end = (p->start + p->size - 1) >> shift; |
| 63 | |
| 64 | age = ++sarea_priv->texAge; |
| 65 | list = sarea_priv->texList; |
| 66 | |
| 67 | /* Mark the regions with the new flag and update their age. Move |
| 68 | * them to head of list to preserve LRU semantics. |
| 69 | */ |
| 70 | for (i = start; i <= end; i++) { |
| 71 | list[i].in_use = in_use; |
| 72 | list[i].age = age; |
| 73 | |
| 74 | /* remove_from_list(i) |
| 75 | */ |
| 76 | list[(unsigned)list[i].next].prev = list[i].prev; |
| 77 | list[(unsigned)list[i].prev].next = list[i].next; |
| 78 | |
| 79 | /* insert_at_head(list, i) |
| 80 | */ |
| 81 | list[i].prev = nr; |
| 82 | list[i].next = list[nr].next; |
| 83 | list[(unsigned)list[nr].next].prev = i; |
| 84 | list[nr].next = i; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | /* Very simple allocator for agp memory, working on a static range |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 89 | * already mapped into each client's address space. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | */ |
| 91 | |
| 92 | 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] | 93 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
| 95 | /* Maybe cut off the start of an existing block */ |
| 96 | if (start > p->start) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 97 | struct mem_block *newblock = |
| 98 | drm_alloc(sizeof(*newblock), DRM_MEM_BUFLISTS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | if (!newblock) |
| 100 | goto out; |
| 101 | newblock->start = start; |
| 102 | newblock->size = p->size - (start - p->start); |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 103 | newblock->file_priv = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | newblock->next = p->next; |
| 105 | newblock->prev = p; |
| 106 | p->next->prev = newblock; |
| 107 | p->next = newblock; |
| 108 | p->size -= newblock->size; |
| 109 | p = newblock; |
| 110 | } |
| 111 | |
| 112 | /* Maybe cut off the end of an existing block */ |
| 113 | if (size < p->size) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 114 | struct mem_block *newblock = |
| 115 | drm_alloc(sizeof(*newblock), DRM_MEM_BUFLISTS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | if (!newblock) |
| 117 | goto out; |
| 118 | newblock->start = start + size; |
| 119 | newblock->size = p->size - size; |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 120 | newblock->file_priv = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | newblock->next = p->next; |
| 122 | newblock->prev = p; |
| 123 | p->next->prev = newblock; |
| 124 | p->next = newblock; |
| 125 | p->size = size; |
| 126 | } |
| 127 | |
| 128 | out: |
| 129 | /* Our block is in the middle */ |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 130 | p->file_priv = file_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | return p; |
| 132 | } |
| 133 | |
| 134 | static struct mem_block *alloc_block(struct mem_block *heap, int size, |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 135 | int align2, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | { |
| 137 | struct mem_block *p; |
| 138 | int mask = (1 << align2) - 1; |
| 139 | |
| 140 | for (p = heap->next; p != heap; p = p->next) { |
| 141 | int start = (p->start + mask) & ~mask; |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 142 | if (p->file_priv == NULL && start + size <= p->start + p->size) |
| 143 | return split_block(p, start, size, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | return NULL; |
| 147 | } |
| 148 | |
| 149 | static struct mem_block *find_block(struct mem_block *heap, int start) |
| 150 | { |
| 151 | struct mem_block *p; |
| 152 | |
| 153 | for (p = heap->next; p != heap; p = p->next) |
| 154 | if (p->start == start) |
| 155 | return p; |
| 156 | |
| 157 | return NULL; |
| 158 | } |
| 159 | |
| 160 | static void free_block(struct mem_block *p) |
| 161 | { |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 162 | p->file_priv = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 164 | /* Assumes a single contiguous range. Needs a special file_priv in |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | * 'heap' to stop it being subsumed. |
| 166 | */ |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 167 | if (p->next->file_priv == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | struct mem_block *q = p->next; |
| 169 | p->size += q->size; |
| 170 | p->next = q->next; |
| 171 | p->next->prev = p; |
| 172 | drm_free(q, sizeof(*q), DRM_MEM_BUFLISTS); |
| 173 | } |
| 174 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 175 | if (p->prev->file_priv == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | struct mem_block *q = p->prev; |
| 177 | q->size += p->size; |
| 178 | q->next = p->next; |
| 179 | q->next->prev = q; |
| 180 | drm_free(p, sizeof(*q), DRM_MEM_BUFLISTS); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | /* Initialize. How to check for an uninitialized heap? |
| 185 | */ |
| 186 | static int init_heap(struct mem_block **heap, int start, int size) |
| 187 | { |
| 188 | struct mem_block *blocks = drm_alloc(sizeof(*blocks), DRM_MEM_BUFLISTS); |
| 189 | |
| 190 | if (!blocks) |
| 191 | return -ENOMEM; |
| 192 | |
| 193 | *heap = drm_alloc(sizeof(**heap), DRM_MEM_BUFLISTS); |
| 194 | if (!*heap) { |
| 195 | drm_free(blocks, sizeof(*blocks), DRM_MEM_BUFLISTS); |
| 196 | return -ENOMEM; |
| 197 | } |
| 198 | |
| 199 | blocks->start = start; |
| 200 | blocks->size = size; |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 201 | blocks->file_priv = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | blocks->next = blocks->prev = *heap; |
| 203 | |
| 204 | memset(*heap, 0, sizeof(**heap)); |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 205 | (*heap)->file_priv = (struct drm_file *) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | (*heap)->next = (*heap)->prev = blocks; |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | /* Free all blocks associated with the releasing file. |
| 211 | */ |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 212 | void i915_mem_release(struct drm_device * dev, struct drm_file *file_priv, |
| 213 | struct mem_block *heap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
| 215 | struct mem_block *p; |
| 216 | |
| 217 | if (!heap || !heap->next) |
| 218 | return; |
| 219 | |
| 220 | for (p = heap->next; p != heap; p = p->next) { |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 221 | if (p->file_priv == file_priv) { |
| 222 | p->file_priv = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | mark_block(dev, p, 0); |
| 224 | } |
| 225 | } |
| 226 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 227 | /* Assumes a single contiguous range. Needs a special file_priv in |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | * 'heap' to stop it being subsumed. |
| 229 | */ |
| 230 | for (p = heap->next; p != heap; p = p->next) { |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 231 | while (p->file_priv == NULL && p->next->file_priv == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | struct mem_block *q = p->next; |
| 233 | p->size += q->size; |
| 234 | p->next = q->next; |
| 235 | p->next->prev = p; |
| 236 | drm_free(q, sizeof(*q), DRM_MEM_BUFLISTS); |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | /* Shutdown. |
| 242 | */ |
| 243 | void i915_mem_takedown(struct mem_block **heap) |
| 244 | { |
| 245 | struct mem_block *p; |
| 246 | |
| 247 | if (!*heap) |
| 248 | return; |
| 249 | |
| 250 | for (p = (*heap)->next; p != *heap;) { |
| 251 | struct mem_block *q = p; |
| 252 | p = p->next; |
| 253 | drm_free(q, sizeof(*q), DRM_MEM_BUFLISTS); |
| 254 | } |
| 255 | |
| 256 | drm_free(*heap, sizeof(**heap), DRM_MEM_BUFLISTS); |
| 257 | *heap = NULL; |
| 258 | } |
| 259 | |
| 260 | static struct mem_block **get_heap(drm_i915_private_t * dev_priv, int region) |
| 261 | { |
| 262 | switch (region) { |
| 263 | case I915_MEM_REGION_AGP: |
| 264 | return &dev_priv->agp_heap; |
| 265 | default: |
| 266 | return NULL; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | /* IOCTL HANDLERS */ |
| 271 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 272 | int i915_mem_alloc(struct drm_device *dev, void *data, |
| 273 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 276 | drm_i915_mem_alloc_t *alloc = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | struct mem_block *block, **heap; |
| 278 | |
| 279 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 280 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 281 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 284 | heap = get_heap(dev_priv, alloc->region); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | if (!heap || !*heap) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 286 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | /* Make things easier on ourselves: all allocations at least |
| 289 | * 4k aligned. |
| 290 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 291 | if (alloc->alignment < 12) |
| 292 | alloc->alignment = 12; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 294 | block = alloc_block(*heap, alloc->size, alloc->alignment, file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
| 296 | if (!block) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 297 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
| 299 | mark_block(dev, block, 1); |
| 300 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 301 | if (DRM_COPY_TO_USER(alloc->region_offset, &block->start, |
| 302 | sizeof(int))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | DRM_ERROR("copy_to_user\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 304 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 310 | int i915_mem_free(struct drm_device *dev, void *data, |
| 311 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 314 | drm_i915_mem_free_t *memfree = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | struct mem_block *block, **heap; |
| 316 | |
| 317 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 318 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 319 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 322 | heap = get_heap(dev_priv, memfree->region); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | if (!heap || !*heap) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 324 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 326 | block = find_block(*heap, memfree->region_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | if (!block) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 328 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 330 | if (block->file_priv != file_priv) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 331 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
| 333 | mark_block(dev, block, 0); |
| 334 | free_block(block); |
| 335 | return 0; |
| 336 | } |
| 337 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 338 | int i915_mem_init_heap(struct drm_device *dev, void *data, |
| 339 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 342 | drm_i915_mem_init_heap_t *initheap = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | struct mem_block **heap; |
| 344 | |
| 345 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 346 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 347 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 350 | heap = get_heap(dev_priv, initheap->region); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | if (!heap) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 352 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
| 354 | if (*heap) { |
| 355 | DRM_ERROR("heap already initialized?"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 356 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 359 | return init_heap(heap, initheap->start, initheap->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 361 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 362 | int i915_mem_destroy_heap( struct drm_device *dev, void *data, |
| 363 | struct drm_file *file_priv ) |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 364 | { |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 365 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 366 | drm_i915_mem_destroy_heap_t *destroyheap = data; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 367 | struct mem_block **heap; |
| 368 | |
| 369 | if ( !dev_priv ) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 370 | DRM_ERROR( "called with no initialization\n" ); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 371 | return -EINVAL; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 372 | } |
| 373 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 374 | heap = get_heap( dev_priv, destroyheap->region ); |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 375 | if (!heap) { |
| 376 | DRM_ERROR("get_heap failed"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 377 | return -EFAULT; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 378 | } |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 379 | |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 380 | if (!*heap) { |
| 381 | DRM_ERROR("heap not initialized?"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 382 | return -EFAULT; |
Dave Airlie | de227f5 | 2006-01-25 15:31:43 +1100 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | i915_mem_takedown( heap ); |
| 386 | return 0; |
| 387 | } |