Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
| 3 | * Copyright 2006 Tungsten Graphics, Inc., Bismarck., ND., USA. |
| 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sub license, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
| 13 | * |
| 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 NON-INFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, |
| 18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 19 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 20 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | * |
| 22 | * The above copyright notice and this permission notice (including the |
| 23 | * next paragraph) shall be included in all copies or substantial portions |
| 24 | * of the Software. |
| 25 | * |
| 26 | * |
| 27 | **************************************************************************/ |
| 28 | /* |
| 29 | * Simple memory manager interface that keeps track on allocate regions on a |
| 30 | * per "owner" basis. All regions associated with an "owner" can be released |
| 31 | * with a simple call. Typically if the "owner" exists. The owner is any |
| 32 | * "unsigned long" identifier. Can typically be a pointer to a file private |
| 33 | * struct or a context identifier. |
| 34 | * |
| 35 | * Authors: |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 36 | * Thomas Hellström <thomas-at-tungstengraphics-dot-com> |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 37 | */ |
| 38 | |
| 39 | #include "drm_sman.h" |
| 40 | |
Dave Airlie | e0be428 | 2007-07-12 10:26:44 +1000 | [diff] [blame] | 41 | struct drm_owner_item { |
| 42 | struct drm_hash_item owner_hash; |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 43 | struct list_head sman_list; |
| 44 | struct list_head mem_blocks; |
Dave Airlie | e0be428 | 2007-07-12 10:26:44 +1000 | [diff] [blame] | 45 | }; |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 46 | |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 47 | void drm_sman_takedown(struct drm_sman * sman) |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 48 | { |
| 49 | drm_ht_remove(&sman->user_hash_tab); |
| 50 | drm_ht_remove(&sman->owner_hash_tab); |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 51 | kfree(sman->mm); |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | EXPORT_SYMBOL(drm_sman_takedown); |
| 55 | |
| 56 | int |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 57 | drm_sman_init(struct drm_sman * sman, unsigned int num_managers, |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 58 | unsigned int user_order, unsigned int owner_order) |
| 59 | { |
| 60 | int ret = 0; |
| 61 | |
Jesper Juhl | 288db88 | 2010-11-09 00:08:25 +0100 | [diff] [blame] | 62 | sman->mm = kcalloc(num_managers, sizeof(*sman->mm), GFP_KERNEL); |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 63 | if (!sman->mm) { |
| 64 | ret = -ENOMEM; |
| 65 | goto out; |
| 66 | } |
| 67 | sman->num_managers = num_managers; |
| 68 | INIT_LIST_HEAD(&sman->owner_items); |
| 69 | ret = drm_ht_create(&sman->owner_hash_tab, owner_order); |
| 70 | if (ret) |
| 71 | goto out1; |
| 72 | ret = drm_ht_create(&sman->user_hash_tab, user_order); |
| 73 | if (!ret) |
| 74 | goto out; |
| 75 | |
| 76 | drm_ht_remove(&sman->owner_hash_tab); |
| 77 | out1: |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 78 | kfree(sman->mm); |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 79 | out: |
| 80 | return ret; |
| 81 | } |
| 82 | |
| 83 | EXPORT_SYMBOL(drm_sman_init); |
| 84 | |
| 85 | static void *drm_sman_mm_allocate(void *private, unsigned long size, |
| 86 | unsigned alignment) |
| 87 | { |
Dave Airlie | 5591051 | 2007-07-11 16:53:40 +1000 | [diff] [blame] | 88 | struct drm_mm *mm = (struct drm_mm *) private; |
| 89 | struct drm_mm_node *tmp; |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 90 | |
Andrew Morton | a1d0fcf | 2006-08-14 11:35:15 +1000 | [diff] [blame] | 91 | tmp = drm_mm_search_free(mm, size, alignment, 1); |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 92 | if (!tmp) { |
| 93 | return NULL; |
| 94 | } |
| 95 | tmp = drm_mm_get_block(tmp, size, alignment); |
| 96 | return tmp; |
| 97 | } |
| 98 | |
| 99 | static void drm_sman_mm_free(void *private, void *ref) |
| 100 | { |
Dave Airlie | 5591051 | 2007-07-11 16:53:40 +1000 | [diff] [blame] | 101 | struct drm_mm_node *node = (struct drm_mm_node *) ref; |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 102 | |
Thomas Hellstrom | 1d58420 | 2007-01-08 22:25:47 +1100 | [diff] [blame] | 103 | drm_mm_put_block(node); |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | static void drm_sman_mm_destroy(void *private) |
| 107 | { |
Dave Airlie | 5591051 | 2007-07-11 16:53:40 +1000 | [diff] [blame] | 108 | struct drm_mm *mm = (struct drm_mm *) private; |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 109 | drm_mm_takedown(mm); |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 110 | kfree(mm); |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 111 | } |
| 112 | |
Adrian Bunk | fb41e54 | 2006-08-16 11:55:18 +1000 | [diff] [blame] | 113 | static unsigned long drm_sman_mm_offset(void *private, void *ref) |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 114 | { |
Dave Airlie | 5591051 | 2007-07-11 16:53:40 +1000 | [diff] [blame] | 115 | struct drm_mm_node *node = (struct drm_mm_node *) ref; |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 116 | return node->start; |
| 117 | } |
| 118 | |
| 119 | int |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 120 | drm_sman_set_range(struct drm_sman * sman, unsigned int manager, |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 121 | unsigned long start, unsigned long size) |
| 122 | { |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 123 | struct drm_sman_mm *sman_mm; |
Dave Airlie | 5591051 | 2007-07-11 16:53:40 +1000 | [diff] [blame] | 124 | struct drm_mm *mm; |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 125 | int ret; |
| 126 | |
| 127 | BUG_ON(manager >= sman->num_managers); |
| 128 | |
| 129 | sman_mm = &sman->mm[manager]; |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 130 | mm = kzalloc(sizeof(*mm), GFP_KERNEL); |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 131 | if (!mm) { |
| 132 | return -ENOMEM; |
| 133 | } |
| 134 | sman_mm->private = mm; |
| 135 | ret = drm_mm_init(mm, start, size); |
| 136 | |
| 137 | if (ret) { |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 138 | kfree(mm); |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 139 | return ret; |
| 140 | } |
| 141 | |
| 142 | sman_mm->allocate = drm_sman_mm_allocate; |
| 143 | sman_mm->free = drm_sman_mm_free; |
| 144 | sman_mm->destroy = drm_sman_mm_destroy; |
| 145 | sman_mm->offset = drm_sman_mm_offset; |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | EXPORT_SYMBOL(drm_sman_set_range); |
| 151 | |
| 152 | int |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 153 | drm_sman_set_manager(struct drm_sman * sman, unsigned int manager, |
| 154 | struct drm_sman_mm * allocator) |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 155 | { |
| 156 | BUG_ON(manager >= sman->num_managers); |
| 157 | sman->mm[manager] = *allocator; |
| 158 | |
| 159 | return 0; |
| 160 | } |
Andrew Morton | a1e8537 | 2006-12-06 20:31:33 -0800 | [diff] [blame] | 161 | EXPORT_SYMBOL(drm_sman_set_manager); |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 162 | |
Dave Airlie | e0be428 | 2007-07-12 10:26:44 +1000 | [diff] [blame] | 163 | static struct drm_owner_item *drm_sman_get_owner_item(struct drm_sman * sman, |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 164 | unsigned long owner) |
| 165 | { |
| 166 | int ret; |
Dave Airlie | e0be428 | 2007-07-12 10:26:44 +1000 | [diff] [blame] | 167 | struct drm_hash_item *owner_hash_item; |
| 168 | struct drm_owner_item *owner_item; |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 169 | |
| 170 | ret = drm_ht_find_item(&sman->owner_hash_tab, owner, &owner_hash_item); |
| 171 | if (!ret) { |
Dave Airlie | e0be428 | 2007-07-12 10:26:44 +1000 | [diff] [blame] | 172 | return drm_hash_entry(owner_hash_item, struct drm_owner_item, |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 173 | owner_hash); |
| 174 | } |
| 175 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 176 | owner_item = kzalloc(sizeof(*owner_item), GFP_KERNEL); |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 177 | if (!owner_item) |
| 178 | goto out; |
| 179 | |
| 180 | INIT_LIST_HEAD(&owner_item->mem_blocks); |
| 181 | owner_item->owner_hash.key = owner; |
| 182 | if (drm_ht_insert_item(&sman->owner_hash_tab, &owner_item->owner_hash)) |
| 183 | goto out1; |
| 184 | |
| 185 | list_add_tail(&owner_item->sman_list, &sman->owner_items); |
| 186 | return owner_item; |
| 187 | |
| 188 | out1: |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 189 | kfree(owner_item); |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 190 | out: |
| 191 | return NULL; |
| 192 | } |
| 193 | |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 194 | struct drm_memblock_item *drm_sman_alloc(struct drm_sman *sman, unsigned int manager, |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 195 | unsigned long size, unsigned alignment, |
| 196 | unsigned long owner) |
| 197 | { |
| 198 | void *tmp; |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 199 | struct drm_sman_mm *sman_mm; |
Dave Airlie | e0be428 | 2007-07-12 10:26:44 +1000 | [diff] [blame] | 200 | struct drm_owner_item *owner_item; |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 201 | struct drm_memblock_item *memblock; |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 202 | |
| 203 | BUG_ON(manager >= sman->num_managers); |
| 204 | |
| 205 | sman_mm = &sman->mm[manager]; |
| 206 | tmp = sman_mm->allocate(sman_mm->private, size, alignment); |
| 207 | |
| 208 | if (!tmp) { |
| 209 | return NULL; |
| 210 | } |
| 211 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 212 | memblock = kzalloc(sizeof(*memblock), GFP_KERNEL); |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 213 | |
| 214 | if (!memblock) |
| 215 | goto out; |
| 216 | |
| 217 | memblock->mm_info = tmp; |
| 218 | memblock->mm = sman_mm; |
| 219 | memblock->sman = sman; |
| 220 | |
| 221 | if (drm_ht_just_insert_please |
| 222 | (&sman->user_hash_tab, &memblock->user_hash, |
| 223 | (unsigned long)memblock, 32, 0, 0)) |
| 224 | goto out1; |
| 225 | |
| 226 | owner_item = drm_sman_get_owner_item(sman, owner); |
| 227 | if (!owner_item) |
| 228 | goto out2; |
| 229 | |
| 230 | list_add_tail(&memblock->owner_list, &owner_item->mem_blocks); |
| 231 | |
| 232 | return memblock; |
| 233 | |
| 234 | out2: |
| 235 | drm_ht_remove_item(&sman->user_hash_tab, &memblock->user_hash); |
| 236 | out1: |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 237 | kfree(memblock); |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 238 | out: |
| 239 | sman_mm->free(sman_mm->private, tmp); |
| 240 | |
| 241 | return NULL; |
| 242 | } |
| 243 | |
| 244 | EXPORT_SYMBOL(drm_sman_alloc); |
| 245 | |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 246 | static void drm_sman_free(struct drm_memblock_item *item) |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 247 | { |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 248 | struct drm_sman *sman = item->sman; |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 249 | |
| 250 | list_del(&item->owner_list); |
| 251 | drm_ht_remove_item(&sman->user_hash_tab, &item->user_hash); |
| 252 | item->mm->free(item->mm->private, item->mm_info); |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 253 | kfree(item); |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 254 | } |
| 255 | |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 256 | int drm_sman_free_key(struct drm_sman *sman, unsigned int key) |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 257 | { |
Dave Airlie | e0be428 | 2007-07-12 10:26:44 +1000 | [diff] [blame] | 258 | struct drm_hash_item *hash_item; |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 259 | struct drm_memblock_item *memblock_item; |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 260 | |
| 261 | if (drm_ht_find_item(&sman->user_hash_tab, key, &hash_item)) |
| 262 | return -EINVAL; |
| 263 | |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 264 | memblock_item = drm_hash_entry(hash_item, struct drm_memblock_item, |
| 265 | user_hash); |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 266 | drm_sman_free(memblock_item); |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | EXPORT_SYMBOL(drm_sman_free_key); |
| 271 | |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 272 | static void drm_sman_remove_owner(struct drm_sman *sman, |
Dave Airlie | e0be428 | 2007-07-12 10:26:44 +1000 | [diff] [blame] | 273 | struct drm_owner_item *owner_item) |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 274 | { |
| 275 | list_del(&owner_item->sman_list); |
| 276 | drm_ht_remove_item(&sman->owner_hash_tab, &owner_item->owner_hash); |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 277 | kfree(owner_item); |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 278 | } |
| 279 | |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 280 | int drm_sman_owner_clean(struct drm_sman *sman, unsigned long owner) |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 281 | { |
| 282 | |
Dave Airlie | e0be428 | 2007-07-12 10:26:44 +1000 | [diff] [blame] | 283 | struct drm_hash_item *hash_item; |
| 284 | struct drm_owner_item *owner_item; |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 285 | |
| 286 | if (drm_ht_find_item(&sman->owner_hash_tab, owner, &hash_item)) { |
| 287 | return -1; |
| 288 | } |
| 289 | |
Dave Airlie | e0be428 | 2007-07-12 10:26:44 +1000 | [diff] [blame] | 290 | owner_item = drm_hash_entry(hash_item, struct drm_owner_item, owner_hash); |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 291 | if (owner_item->mem_blocks.next == &owner_item->mem_blocks) { |
| 292 | drm_sman_remove_owner(sman, owner_item); |
| 293 | return -1; |
| 294 | } |
| 295 | |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | EXPORT_SYMBOL(drm_sman_owner_clean); |
| 300 | |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 301 | static void drm_sman_do_owner_cleanup(struct drm_sman *sman, |
Dave Airlie | e0be428 | 2007-07-12 10:26:44 +1000 | [diff] [blame] | 302 | struct drm_owner_item *owner_item) |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 303 | { |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 304 | struct drm_memblock_item *entry, *next; |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 305 | |
| 306 | list_for_each_entry_safe(entry, next, &owner_item->mem_blocks, |
| 307 | owner_list) { |
| 308 | drm_sman_free(entry); |
| 309 | } |
| 310 | drm_sman_remove_owner(sman, owner_item); |
| 311 | } |
| 312 | |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 313 | void drm_sman_owner_cleanup(struct drm_sman *sman, unsigned long owner) |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 314 | { |
| 315 | |
Dave Airlie | e0be428 | 2007-07-12 10:26:44 +1000 | [diff] [blame] | 316 | struct drm_hash_item *hash_item; |
| 317 | struct drm_owner_item *owner_item; |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 318 | |
| 319 | if (drm_ht_find_item(&sman->owner_hash_tab, owner, &hash_item)) { |
| 320 | |
| 321 | return; |
| 322 | } |
| 323 | |
Dave Airlie | e0be428 | 2007-07-12 10:26:44 +1000 | [diff] [blame] | 324 | owner_item = drm_hash_entry(hash_item, struct drm_owner_item, owner_hash); |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 325 | drm_sman_do_owner_cleanup(sman, owner_item); |
| 326 | } |
| 327 | |
| 328 | EXPORT_SYMBOL(drm_sman_owner_cleanup); |
| 329 | |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 330 | void drm_sman_cleanup(struct drm_sman *sman) |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 331 | { |
Dave Airlie | e0be428 | 2007-07-12 10:26:44 +1000 | [diff] [blame] | 332 | struct drm_owner_item *entry, *next; |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 333 | unsigned int i; |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 334 | struct drm_sman_mm *sman_mm; |
Thomas Hellstrom | 3a1bd92 | 2006-08-07 21:30:28 +1000 | [diff] [blame] | 335 | |
| 336 | list_for_each_entry_safe(entry, next, &sman->owner_items, sman_list) { |
| 337 | drm_sman_do_owner_cleanup(sman, entry); |
| 338 | } |
| 339 | if (sman->mm) { |
| 340 | for (i = 0; i < sman->num_managers; ++i) { |
| 341 | sman_mm = &sman->mm[i]; |
| 342 | if (sman_mm->private) { |
| 343 | sman_mm->destroy(sman_mm->private); |
| 344 | sman_mm->private = NULL; |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | EXPORT_SYMBOL(drm_sman_cleanup); |