2 * Copyright (C) 2010, 2013, 2015 ARM Limited. All rights reserved.
4 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
7 * A copy of the licence is included with the program, and can also be obtained from Free Software
8 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
11 #ifndef __MALI_BLOCK_ALLOCATOR_H__
12 #define __MALI_BLOCK_ALLOCATOR_H__
14 #include "mali_session.h"
15 #include "mali_memory.h"
16 #include <linux/spinlock.h>
18 #include "mali_memory_types.h"
20 #define MALI_BLOCK_SIZE (PAGE_SIZE) /* 4 kB, manage BLOCK memory as page size */
21 #define MALI_BLOCK_REF_MASK (0xFFF)
22 #define MALI_BLOCK_MAX_REF_COUNT (0xFFF)
26 typedef struct mali_block_allocator {
28 * In free list, each node's ref_count is 0,
29 * ref_count added when allocated or referenced in COW
31 mali_block_item *items; /* information for each block item*/
32 struct list_head free; /*free list of mali_memory_node*/
33 spinlock_t sp_lock; /*lock for reference count & free list opertion*/
34 u32 total_num; /* Number of total pages*/
35 atomic_t free_num; /*number of free pages*/
36 } mali_block_allocator;
38 unsigned long _mali_blk_item_get_phy_addr(mali_block_item *item);
39 unsigned long _mali_blk_item_get_pfn(mali_block_item *item);
40 u32 mali_mem_block_get_ref_count(mali_page_node *node);
41 u32 mali_mem_block_add_ref(mali_page_node *node);
42 u32 mali_mem_block_dec_ref(mali_page_node *node);
43 u32 mali_mem_block_release(mali_mem_backend *mem_bkend);
44 int mali_mem_block_alloc(mali_mem_block_mem *block_mem, u32 size);
45 int mali_mem_block_mali_map(mali_mem_block_mem *block_mem, struct mali_session_data *session, u32 vaddr, u32 props);
46 void mali_mem_block_mali_unmap(mali_mem_allocation *alloc);
48 int mali_mem_block_cpu_map(mali_mem_backend *mem_bkend, struct vm_area_struct *vma);
49 _mali_osk_errcode_t mali_memory_core_resource_dedicated_memory(u32 start, u32 size);
50 mali_bool mali_memory_have_dedicated_memory(void);
51 u32 mali_mem_block_free(mali_mem_block_mem *block_mem);
52 u32 mali_mem_block_free_list(struct list_head *list);
53 void mali_mem_block_free_node(struct mali_page_node *node);
54 void mali_mem_block_allocator_destroy(void);
55 _mali_osk_errcode_t mali_mem_block_unref_node(struct mali_page_node *node);
56 u32 mali_mem_block_allocator_stat(void);
58 #endif /* __MALI_BLOCK_ALLOCATOR_H__ */