Lines Matching refs:pool
15 bool tee_mm_init(tee_mm_pool_t *pool, paddr_t lo, paddr_size_t size, in tee_mm_init() argument
21 if (pool == NULL) in tee_mm_init()
30 *pool = (tee_mm_pool_t){ in tee_mm_init()
37 pool->entry = malloc_flags(pool->flags | MAF_ZERO_INIT, NULL, in tee_mm_init()
40 if (pool->entry == NULL) in tee_mm_init()
43 if (pool->flags & TEE_MM_POOL_HI_ALLOC) in tee_mm_init()
44 pool->entry->offset = ((size - 1) >> shift) + 1; in tee_mm_init()
46 pool->entry->pool = pool; in tee_mm_init()
47 pool->lock = SPINLOCK_UNLOCK; in tee_mm_init()
52 void tee_mm_final(tee_mm_pool_t *pool) in tee_mm_final() argument
54 if (pool == NULL || pool->entry == NULL) in tee_mm_final()
57 while (pool->entry->next != NULL) in tee_mm_final()
58 tee_mm_free(pool->entry->next); in tee_mm_final()
59 free_flags(pool->flags, pool->entry); in tee_mm_final()
60 pool->entry = NULL; in tee_mm_final()
71 static size_t tee_mm_stats_allocated(tee_mm_pool_t *pool) in tee_mm_stats_allocated() argument
76 if (!pool) in tee_mm_stats_allocated()
79 entry = pool->entry; in tee_mm_stats_allocated()
85 return sz << pool->shift; in tee_mm_stats_allocated()
88 void tee_mm_get_pool_stats(tee_mm_pool_t *pool, struct pta_stats_alloc *stats, in tee_mm_get_pool_stats() argument
93 if (!pool) in tee_mm_get_pool_stats()
98 exceptions = cpu_spin_lock_xsave(&pool->lock); in tee_mm_get_pool_stats()
100 stats->size = pool->size; in tee_mm_get_pool_stats()
101 stats->max_allocated = pool->max_allocated; in tee_mm_get_pool_stats()
102 stats->allocated = tee_mm_stats_allocated(pool); in tee_mm_get_pool_stats()
105 pool->max_allocated = 0; in tee_mm_get_pool_stats()
106 cpu_spin_unlock_xrestore(&pool->lock, exceptions); in tee_mm_get_pool_stats()
109 static void update_max_allocated(tee_mm_pool_t *pool) in update_max_allocated() argument
111 size_t sz = tee_mm_stats_allocated(pool); in update_max_allocated()
113 if (sz > pool->max_allocated) in update_max_allocated()
114 pool->max_allocated = sz; in update_max_allocated()
117 static inline void update_max_allocated(tee_mm_pool_t *pool __unused) in update_max_allocated()
122 tee_mm_entry_t *tee_mm_alloc_flags(tee_mm_pool_t *pool, size_t size, in tee_mm_alloc_flags() argument
132 if (!pool || !pool->entry) in tee_mm_alloc_flags()
136 flags |= pool->flags; in tee_mm_alloc_flags()
142 exceptions = cpu_spin_lock_xsave(&pool->lock); in tee_mm_alloc_flags()
144 entry = pool->entry; in tee_mm_alloc_flags()
148 psize = ((size - 1) >> pool->shift) + 1; in tee_mm_alloc_flags()
151 if (pool->flags & TEE_MM_POOL_HI_ALLOC) { in tee_mm_alloc_flags()
164 if (pool->flags & TEE_MM_POOL_HI_ALLOC) { in tee_mm_alloc_flags()
174 if ((entry->offset << pool->shift) < size) { in tee_mm_alloc_flags()
179 if (!pool->size) in tee_mm_alloc_flags()
182 remaining = pool->size; in tee_mm_alloc_flags()
184 pool->shift); in tee_mm_alloc_flags()
195 if (pool->flags & TEE_MM_POOL_HI_ALLOC) in tee_mm_alloc_flags()
200 nn->pool = pool; in tee_mm_alloc_flags()
202 update_max_allocated(pool); in tee_mm_alloc_flags()
204 cpu_spin_unlock_xrestore(&pool->lock, exceptions); in tee_mm_alloc_flags()
207 cpu_spin_unlock_xrestore(&pool->lock, exceptions); in tee_mm_alloc_flags()
212 static inline bool fit_in_gap(tee_mm_pool_t *pool, tee_mm_entry_t *e, in fit_in_gap() argument
215 if (pool->flags & TEE_MM_POOL_HI_ALLOC) { in fit_in_gap()
219 (offshi << pool->shift) - 1 > pool->size) in fit_in_gap()
225 (offshi << pool->shift) > pool->size) in fit_in_gap()
233 tee_mm_entry_t *tee_mm_alloc2(tee_mm_pool_t *pool, paddr_t base, size_t size) in tee_mm_alloc2() argument
242 if (!pool || !pool->entry) in tee_mm_alloc2()
246 if ((base + size) < base || base < pool->lo) in tee_mm_alloc2()
249 mm = malloc_flags(pool->flags, NULL, MALLOC_DEFAULT_ALIGNMENT, in tee_mm_alloc2()
254 exceptions = cpu_spin_lock_xsave(&pool->lock); in tee_mm_alloc2()
256 entry = pool->entry; in tee_mm_alloc2()
257 offslo = (base - pool->lo) >> pool->shift; in tee_mm_alloc2()
258 offshi = ((base - pool->lo + size - 1) >> pool->shift) + 1; in tee_mm_alloc2()
261 if (pool->flags & TEE_MM_POOL_HI_ALLOC) { in tee_mm_alloc2()
271 if (!fit_in_gap(pool, entry, offslo, offshi)) in tee_mm_alloc2()
278 mm->pool = pool; in tee_mm_alloc2()
280 update_max_allocated(pool); in tee_mm_alloc2()
281 cpu_spin_unlock_xrestore(&pool->lock, exceptions); in tee_mm_alloc2()
284 cpu_spin_unlock_xrestore(&pool->lock, exceptions); in tee_mm_alloc2()
285 free_flags(pool->flags, mm); in tee_mm_alloc2()
294 if (!p || !p->pool) in tee_mm_free()
297 exceptions = cpu_spin_lock_xsave(&p->pool->lock); in tee_mm_free()
298 entry = p->pool->entry; in tee_mm_free()
308 cpu_spin_unlock_xrestore(&p->pool->lock, exceptions); in tee_mm_free()
310 free_flags(p->pool->flags, p); in tee_mm_free()
315 if (!mm || !mm->pool) in tee_mm_get_bytes()
318 return mm->size << mm->pool->shift; in tee_mm_get_bytes()
321 bool tee_mm_addr_is_within_range(const tee_mm_pool_t *pool, paddr_t addr) in tee_mm_addr_is_within_range() argument
323 return pool && addr >= pool->lo && in tee_mm_addr_is_within_range()
324 addr <= (pool->lo + (pool->size - 1)); in tee_mm_addr_is_within_range()
327 bool tee_mm_is_empty(tee_mm_pool_t *pool) in tee_mm_is_empty() argument
332 if (pool == NULL || pool->entry == NULL) in tee_mm_is_empty()
335 exceptions = cpu_spin_lock_xsave(&pool->lock); in tee_mm_is_empty()
336 ret = pool->entry == NULL || pool->entry->next == NULL; in tee_mm_is_empty()
337 cpu_spin_unlock_xrestore(&pool->lock, exceptions); in tee_mm_is_empty()
342 tee_mm_entry_t *tee_mm_find(const tee_mm_pool_t *pool, paddr_t addr) in tee_mm_find() argument
344 tee_mm_entry_t *entry = pool->entry; in tee_mm_find()
345 uint16_t offset = (addr - pool->lo) >> pool->shift; in tee_mm_find()
348 if (!tee_mm_addr_is_within_range(pool, addr)) in tee_mm_find()
351 exceptions = cpu_spin_lock_xsave(&((tee_mm_pool_t *)pool)->lock); in tee_mm_find()
358 cpu_spin_unlock_xrestore(&((tee_mm_pool_t *)pool)->lock, in tee_mm_find()
364 cpu_spin_unlock_xrestore(&((tee_mm_pool_t *)pool)->lock, exceptions); in tee_mm_find()
370 return (mm->offset << mm->pool->shift) + mm->pool->lo; in tee_mm_get_smem()