@@ -127,7 +127,7 @@ static void panthor_free_heap_chunk(struct panthor_vm *vm,
127127 heap -> chunk_count -- ;
128128 mutex_unlock (& heap -> lock );
129129
130- panthor_kernel_bo_destroy (vm , chunk -> bo );
130+ panthor_kernel_bo_destroy (chunk -> bo );
131131 kfree (chunk );
132132}
133133
@@ -183,7 +183,7 @@ static int panthor_alloc_heap_chunk(struct panthor_device *ptdev,
183183 return 0 ;
184184
185185err_destroy_bo :
186- panthor_kernel_bo_destroy (vm , chunk -> bo );
186+ panthor_kernel_bo_destroy (chunk -> bo );
187187
188188err_free_chunk :
189189 kfree (chunk );
@@ -253,8 +253,8 @@ int panthor_heap_destroy(struct panthor_heap_pool *pool, u32 handle)
253253 * @pool: Pool to instantiate the heap context from.
254254 * @initial_chunk_count: Number of chunk allocated at initialization time.
255255 * Must be at least 1.
256- * @chunk_size: The size of each chunk. Must be a power of two between 256k
257- * and 2M .
256+ * @chunk_size: The size of each chunk. Must be page-aligned and lie in the
257+ * [128k:8M] range .
258258 * @max_chunks: Maximum number of chunks that can be allocated.
259259 * @target_in_flight: Maximum number of in-flight render passes.
260260 * @heap_ctx_gpu_va: Pointer holding the GPU address of the allocated heap
@@ -281,8 +281,11 @@ int panthor_heap_create(struct panthor_heap_pool *pool,
281281 if (initial_chunk_count == 0 )
282282 return - EINVAL ;
283283
284- if (hweight32 (chunk_size ) != 1 ||
285- chunk_size < SZ_256K || chunk_size > SZ_2M )
284+ if (initial_chunk_count > max_chunks )
285+ return - EINVAL ;
286+
287+ if (!IS_ALIGNED (chunk_size , PAGE_SIZE ) ||
288+ chunk_size < SZ_128K || chunk_size > SZ_8M )
286289 return - EINVAL ;
287290
288291 down_read (& pool -> lock );
@@ -320,7 +323,8 @@ int panthor_heap_create(struct panthor_heap_pool *pool,
320323 if (!pool -> vm ) {
321324 ret = - EINVAL ;
322325 } else {
323- ret = xa_alloc (& pool -> xa , & id , heap , XA_LIMIT (1 , MAX_HEAPS_PER_POOL ), GFP_KERNEL );
326+ ret = xa_alloc (& pool -> xa , & id , heap ,
327+ XA_LIMIT (0 , MAX_HEAPS_PER_POOL - 1 ), GFP_KERNEL );
324328 if (!ret ) {
325329 void * gpu_ctx = panthor_get_heap_ctx (pool , id );
326330
@@ -391,7 +395,7 @@ int panthor_heap_return_chunk(struct panthor_heap_pool *pool,
391395 mutex_unlock (& heap -> lock );
392396
393397 if (removed ) {
394- panthor_kernel_bo_destroy (pool -> vm , chunk -> bo );
398+ panthor_kernel_bo_destroy (chunk -> bo );
395399 kfree (chunk );
396400 ret = 0 ;
397401 } else {
@@ -410,6 +414,13 @@ int panthor_heap_return_chunk(struct panthor_heap_pool *pool,
410414 * @renderpasses_in_flight: Number of render passes currently in-flight.
411415 * @pending_frag_count: Number of fragment jobs waiting for execution/completion.
412416 * @new_chunk_gpu_va: Pointer used to return the chunk VA.
417+ *
418+ * Return:
419+ * - 0 if a new heap was allocated
420+ * - -ENOMEM if the tiler context reached the maximum number of chunks
421+ * or if too many render passes are in-flight
422+ * or if the allocation failed
423+ * - -EINVAL if any of the arguments passed to panthor_heap_grow() is invalid
413424 */
414425int panthor_heap_grow (struct panthor_heap_pool * pool ,
415426 u64 heap_gpu_va ,
@@ -439,10 +450,7 @@ int panthor_heap_grow(struct panthor_heap_pool *pool,
439450 * handler provided by the userspace driver, if any).
440451 */
441452 if (renderpasses_in_flight > heap -> target_in_flight ||
442- (pending_frag_count > 0 && heap -> chunk_count >= heap -> max_chunks )) {
443- ret = - EBUSY ;
444- goto out_unlock ;
445- } else if (heap -> chunk_count >= heap -> max_chunks ) {
453+ heap -> chunk_count >= heap -> max_chunks ) {
446454 ret = - ENOMEM ;
447455 goto out_unlock ;
448456 }
@@ -536,7 +544,7 @@ panthor_heap_pool_create(struct panthor_device *ptdev, struct panthor_vm *vm)
536544 pool -> vm = vm ;
537545 pool -> ptdev = ptdev ;
538546 init_rwsem (& pool -> lock );
539- xa_init_flags (& pool -> xa , XA_FLAGS_ALLOC1 );
547+ xa_init_flags (& pool -> xa , XA_FLAGS_ALLOC );
540548 kref_init (& pool -> refcount );
541549
542550 pool -> gpu_contexts = panthor_kernel_bo_create (ptdev , vm , bosize ,
@@ -587,7 +595,7 @@ void panthor_heap_pool_destroy(struct panthor_heap_pool *pool)
587595 drm_WARN_ON (& pool -> ptdev -> base , panthor_heap_destroy_locked (pool , i ));
588596
589597 if (!IS_ERR_OR_NULL (pool -> gpu_contexts ))
590- panthor_kernel_bo_destroy (pool -> vm , pool -> gpu_contexts );
598+ panthor_kernel_bo_destroy (pool -> gpu_contexts );
591599
592600 /* Reflects the fact the pool has been destroyed. */
593601 pool -> vm = NULL ;
0 commit comments