2 * Copyright (C) 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_MEMORY_TYPES_H__
12 #define __MALI_MEMORY_TYPES_H__
16 #if defined(CONFIG_MALI400_UMP)
17 #include "ump_kernel_interface.h"
20 typedef u32 mali_address_t;
22 typedef enum mali_mem_type {
33 typedef struct mali_block_item {
34 /* for block type, the block_phy is alway page size align
35 * so use low 12bit used for ref_cout.
37 unsigned long phy_addr;
41 * idx is used to locate the given page in the address space of swap file.
42 * ref_count is used to mark how many memory backends are using this item.
44 typedef struct mali_swap_item {
51 typedef enum mali_page_node_type {
55 } mali_page_node_type;
57 typedef struct mali_page_node {
58 struct list_head list;
61 mali_block_item *blk_it; /*pointer to block item*/
62 mali_swap_item *swap_it;
68 typedef struct mali_mem_os_mem {
69 struct list_head pages;
73 typedef struct mali_mem_dma_buf {
74 #if defined(CONFIG_DMA_SHARED_BUFFER)
75 struct mali_dma_buf_attachment *attachment;
79 typedef struct mali_mem_external {
84 typedef struct mali_mem_ump {
85 #if defined(CONFIG_MALI400_UMP)
90 typedef struct block_allocator_allocation {
91 /* The list will be released in reverse order */
92 struct block_info *last_allocated;
94 struct block_allocator *info;
95 } block_allocator_allocation;
97 typedef struct mali_mem_block_mem {
98 struct list_head pfns;
100 } mali_mem_block_mem;
102 typedef struct mali_mem_virt_mali_mapping {
103 mali_address_t addr; /* Virtual Mali address */
104 u32 properties; /* MMU Permissions + cache, must match MMU HW */
105 } mali_mem_virt_mali_mapping;
107 typedef struct mali_mem_virt_cpu_mapping {
109 struct vm_area_struct *vma;
110 } mali_mem_virt_cpu_mapping;
112 #define MALI_MEM_ALLOCATION_VALID_MAGIC 0xdeda110c
113 #define MALI_MEM_ALLOCATION_FREED_MAGIC 0x10101010
115 typedef struct mali_mm_node {
116 /* MALI GPU vaddr start, use u32 for mmu only support 32bit address*/
117 uint32_t start; /* GPU vaddr */
118 uint32_t size; /* GPU allocation virtual size */
119 unsigned allocated : 1;
122 typedef struct mali_vma_node {
123 struct mali_mm_node vm_node;
124 struct rb_node vm_rb;
128 typedef struct mali_mem_allocation {
129 MALI_DEBUG_CODE(u32 magic);
130 mali_mem_type type; /**< Type of memory */
131 u32 flags; /**< Flags for this allocation */
133 struct mali_session_data *session; /**< Pointer to session that owns the allocation */
135 mali_mem_virt_cpu_mapping cpu_mapping; /**< CPU mapping */
136 mali_mem_virt_mali_mapping mali_mapping; /**< Mali mapping */
138 /* add for new memory system */
139 struct mali_vma_node mali_vma_node;
140 u32 vsize; /* virtual size*/
141 u32 psize; /* physical backend memory size*/
142 struct list_head list;
143 s32 backend_handle; /* idr for mem_backend */
144 _mali_osk_atomic_t mem_alloc_refcount;
145 } mali_mem_allocation;
147 struct mali_mem_os_allocator {
148 spinlock_t pool_lock;
149 struct list_head pool_pages;
152 atomic_t allocated_pages;
153 size_t allocation_limit;
155 struct shrinker shrinker;
156 struct delayed_work timed_shrinker;
157 struct workqueue_struct *wq;
160 /* COW backend memory type */
161 typedef struct mali_mem_cow {
162 struct list_head pages; /**< all pages for this cow backend allocation,
163 including new allocated pages for modified range*/
164 u32 count; /**< number of pages */
168 typedef struct mali_mem_swap {
169 struct list_head pages;
173 #define MALI_MEM_BACKEND_FLAG_COWED (0x1) /* COW has happen on this backend */
174 #define MALI_MEM_BACKEND_FLAG_COW_CPU_NO_WRITE (0x2) /* This is an COW backend, mapped as not allowed cpu to write */
175 #define MALI_MEM_BACKEND_FLAG_SWAP_COWED (0x4) /* Mark the given backend is cowed from swappable memory. */
176 /* Mark this backend is not swapped_in in MALI driver, and before using it,
177 * we should swap it in and set up corresponding page table. */
178 #define MALI_MEM_BACKEND_FLAG_UNSWAPPED_IN (0x8)
179 #define MALI_MEM_BACKEND_FLAG_NOT_BINDED (0x1 << 5) /* this backend it not back with physical memory, used for defer bind */
180 #define MALI_MEM_BACKEND_FLAG_BINDED (0x1 << 6) /* this backend it back with physical memory, used for defer bind */
182 typedef struct mali_mem_backend {
183 mali_mem_type type; /**< Type of backend memory */
184 u32 flags; /**< Flags for this allocation */
186 /* Union selected by type. */
188 mali_mem_os_mem os_mem; /**< MALI_MEM_OS */
189 mali_mem_external ext_mem; /**< MALI_MEM_EXTERNAL */
190 mali_mem_dma_buf dma_buf; /**< MALI_MEM_DMA_BUF */
191 mali_mem_ump ump_mem; /**< MALI_MEM_UMP */
192 mali_mem_block_mem block_mem; /**< MALI_MEM_BLOCK */
193 mali_mem_cow cow_mem;
194 mali_mem_swap swap_mem;
196 mali_mem_allocation *mali_allocation;
198 mali_mem_type cow_type;
200 struct list_head list; /**< Used to link swappable memory backend to the global swappable list */
201 int using_count; /**< Mark how many PP jobs are using this memory backend */
202 u32 start_idx; /**< If the correspondign vma of this backend is linear, this value will be used to set vma->vm_pgoff */
205 #define MALI_MEM_FLAG_MALI_GUARD_PAGE (_MALI_MAP_EXTERNAL_MAP_GUARD_PAGE)
206 #define MALI_MEM_FLAG_DONT_CPU_MAP (1 << 1)
207 #define MALI_MEM_FLAG_CAN_RESIZE (_MALI_MEMORY_ALLOCATE_RESIZEABLE)
208 #endif /* __MALI_MEMORY_TYPES__ */