diff options
author | Philippe Langlais <philippe.langlais@stericsson.com> | 2012-04-06 11:44:14 +0200 |
---|---|---|
committer | Philippe Langlais <philippe.langlais@stericsson.com> | 2012-04-06 11:44:14 +0200 |
commit | 70526554173aa46c8b13a59992b6fbc555fd4ee0 (patch) | |
tree | 21f0af1030935e2841b1427861905fef216e149f /drivers/gpu/mali/mali400ko/driver/src/devicedrv/mali/common/mali_kernel_mem_os.c | |
parent | 2ee8379b83e5afb57dd19192109380736c1c4431 (diff) | |
parent | a613e39784b04863a3e885be0b21b5966b7ff174 (diff) |
Merge branch 'mali-android' into stable-android-ux500-3.3-1
Diffstat (limited to 'drivers/gpu/mali/mali400ko/driver/src/devicedrv/mali/common/mali_kernel_mem_os.c')
-rw-r--r-- | drivers/gpu/mali/mali400ko/driver/src/devicedrv/mali/common/mali_kernel_mem_os.c | 59 |
1 files changed, 48 insertions, 11 deletions
diff --git a/drivers/gpu/mali/mali400ko/driver/src/devicedrv/mali/common/mali_kernel_mem_os.c b/drivers/gpu/mali/mali400ko/driver/src/devicedrv/mali/common/mali_kernel_mem_os.c index 845de935ec9..65958576c7a 100644 --- a/drivers/gpu/mali/mali400ko/driver/src/devicedrv/mali/common/mali_kernel_mem_os.c +++ b/drivers/gpu/mali/mali400ko/driver/src/devicedrv/mali/common/mali_kernel_mem_os.c @@ -44,6 +44,7 @@ static mali_physical_memory_allocation_result os_allocator_allocate_page_table_b static void os_allocator_release(void * ctx, void * handle); static void os_allocator_page_table_block_release( mali_page_table_block *page_table_block ); static void os_allocator_destroy(mali_physical_memory_allocator * allocator); +static u32 os_allocator_stat(mali_physical_memory_allocator * allocator); mali_physical_memory_allocator * mali_os_allocator_create(u32 max_allocation, u32 cpu_usage_adjust, const char *name) { @@ -70,6 +71,7 @@ mali_physical_memory_allocator * mali_os_allocator_create(u32 max_allocation, u3 allocator->allocate = os_allocator_allocate; allocator->allocate_page_table_block = os_allocator_allocate_page_table_block; allocator->destroy = os_allocator_destroy; + allocator->stat = os_allocator_stat; allocator->ctx = info; allocator->name = name; @@ -83,6 +85,13 @@ mali_physical_memory_allocator * mali_os_allocator_create(u32 max_allocation, u3 return NULL; } +static u32 os_allocator_stat(mali_physical_memory_allocator * allocator) +{ + os_allocator * info; + info = (os_allocator*)allocator->ctx; + return info->num_pages_allocated * _MALI_OSK_MALI_PAGE_SIZE; +} + static void os_allocator_destroy(mali_physical_memory_allocator * allocator) { os_allocator * info; @@ -158,6 +167,9 @@ static mali_physical_memory_allocation_result os_allocator_allocate(void* ctx, m *offset += _MALI_OSK_CPU_PAGE_SIZE; } + if (left) MALI_PRINT(("Out of memory. Mali memory allocated: %d kB Configured maximum OS memory usage: %d kB\n", + (info->num_pages_allocated * _MALI_OSK_CPU_PAGE_SIZE)/1024, (info->num_pages_max* _MALI_OSK_CPU_PAGE_SIZE)/1024)); + /* Loop termination; decide on result */ if (pages_allocated) { @@ -167,7 +179,7 @@ static mali_physical_memory_allocation_result os_allocator_allocate(void* ctx, m /* Some OS do not perform a full cache flush (including all outer caches) for uncached mapped memory. * They zero the memory through a cached mapping, then flush the inner caches but not the outer caches. - * This is required for MALI to have the correct view of the memory. + * This is required for MALI to have the correct view of the memory. */ _mali_osk_cache_ensure_uncached_range_flushed( (void *)descriptor, allocation->offset_start, pages_allocated *_MALI_OSK_CPU_PAGE_SIZE ); allocation->num_pages = pages_allocated; @@ -231,10 +243,9 @@ static void os_allocator_release(void * ctx, void * handle) static mali_physical_memory_allocation_result os_allocator_allocate_page_table_block(void * ctx, mali_page_table_block * block) { - const int allocation_order = 6; /* _MALI_OSK_CPU_PAGE_SIZE << 6 */ - void *virt; - const u32 pages_to_allocate = 1 << allocation_order; - const u32 size = _MALI_OSK_CPU_PAGE_SIZE << allocation_order; + int allocation_order = 6; /* _MALI_OSK_CPU_PAGE_SIZE << 6 */ + void *virt = NULL; + u32 size = _MALI_OSK_CPU_PAGE_SIZE << allocation_order; os_allocator * info; u32 cpu_phys_base; @@ -245,22 +256,48 @@ static mali_physical_memory_allocation_result os_allocator_allocate_page_table_b /* Ensure we don't allocate more than we're supposed to from the ctx */ if (_MALI_OSK_ERR_OK != _mali_osk_lock_wait(info->mutex, _MALI_OSK_LOCKMODE_RW)) return MALI_MEM_ALLOC_INTERNAL_FAILURE; - if ( (info->num_pages_allocated + pages_to_allocate > info->num_pages_max) && _mali_osk_mem_check_allocated(info->num_pages_max * _MALI_OSK_CPU_PAGE_SIZE) ) + /* if the number of pages to be requested lead to exceeding the memory + * limit in info->num_pages_max, reduce the size that is to be requested. */ + while ( (info->num_pages_allocated + (1 << allocation_order) > info->num_pages_max) + && _mali_osk_mem_check_allocated(info->num_pages_max * _MALI_OSK_CPU_PAGE_SIZE) ) { - /* return OOM */ - _mali_osk_lock_signal(info->mutex, _MALI_OSK_LOCKMODE_RW); - return MALI_MEM_ALLOC_NONE; + if ( allocation_order > 0 ) { + --allocation_order; + } else { + /* return OOM */ + _mali_osk_lock_signal(info->mutex, _MALI_OSK_LOCKMODE_RW); + return MALI_MEM_ALLOC_NONE; + } } - virt = _mali_osk_mem_allocioregion( &cpu_phys_base, size ); + /* try to allocate 2^(allocation_order) pages, if that fails, try + * allocation_order-1 to allocation_order 0 (inclusive) */ + while ( allocation_order >= 0 ) + { + size = _MALI_OSK_CPU_PAGE_SIZE << allocation_order; + virt = _mali_osk_mem_allocioregion( &cpu_phys_base, size ); + + if (NULL != virt) break; + + --allocation_order; + } if ( NULL == virt ) { + MALI_DEBUG_PRINT(1, ("Failed to allocate consistent memory. Is CONSISTENT_DMA_SIZE set too low?\n")); /* return OOM */ _mali_osk_lock_signal(info->mutex, _MALI_OSK_LOCKMODE_RW); return MALI_MEM_ALLOC_NONE; } + MALI_DEBUG_PRINT(5, ("os_allocator_allocate_page_table_block: Allocation of order %i succeeded\n", + allocation_order)); + + /* we now know the size of the allocation since we know for what + * allocation_order the allocation succeeded */ + size = _MALI_OSK_CPU_PAGE_SIZE << allocation_order; + + block->release = os_allocator_page_table_block_release; block->ctx = ctx; block->handle = (void*)allocation_order; @@ -268,7 +305,7 @@ static mali_physical_memory_allocation_result os_allocator_allocate_page_table_b block->phys_base = cpu_phys_base - info->cpu_usage_adjust; block->mapping = virt; - info->num_pages_allocated += pages_to_allocate; + info->num_pages_allocated += (1 << allocation_order); _mali_osk_lock_signal(info->mutex, _MALI_OSK_LOCKMODE_RW); |