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 {
34 typedef struct mali_block_item {
35 /* for block type, the block_phy is alway page size align
36 * so use low 12bit used for ref_cout.
38 unsigned long phy_addr;
42 * idx is used to locate the given page in the address space of swap file.
43 * ref_count is used to mark how many memory backends are using this item.
45 typedef struct mali_swap_item {
52 typedef enum mali_page_node_type {
56 } mali_page_node_type;
58 typedef struct mali_page_node {
59 struct list_head list;
62 mali_block_item *blk_it; /*pointer to block item*/
63 mali_swap_item *swap_it;
69 typedef struct mali_mem_os_mem {
70 struct list_head pages;
74 typedef struct mali_mem_dma_buf {
75 #if defined(CONFIG_DMA_SHARED_BUFFER)
76 struct mali_dma_buf_attachment *attachment;
80 typedef struct mali_mem_external {
85 typedef struct mali_mem_ump {
86 #if defined(CONFIG_MALI400_UMP)
91 typedef struct block_allocator_allocation {
92 /* The list will be released in reverse order */
93 struct block_info *last_allocated;
95 struct block_allocator *info;
96 } block_allocator_allocation;
98 typedef struct mali_mem_block_mem {
99 struct list_head pfns;
101 } mali_mem_block_mem;
103 typedef struct mali_mem_virt_mali_mapping {
104 mali_address_t addr; /* Virtual Mali address */
105 u32 properties; /* MMU Permissions + cache, must match MMU HW */
106 } mali_mem_virt_mali_mapping;
108 typedef struct mali_mem_virt_cpu_mapping {
110 struct vm_area_struct *vma;
111 } mali_mem_virt_cpu_mapping;
113 #define MALI_MEM_ALLOCATION_VALID_MAGIC 0xdeda110c
114 #define MALI_MEM_ALLOCATION_FREED_MAGIC 0x10101010
116 typedef struct mali_mm_node {
117 /* MALI GPU vaddr start, use u32 for mmu only support 32bit address*/
118 uint32_t start; /* GPU vaddr */
119 uint32_t size; /* GPU allocation virtual size */
120 unsigned allocated : 1;
123 typedef struct mali_vma_node {
124 struct mali_mm_node vm_node;
125 struct rb_node vm_rb;
129 typedef struct mali_mem_allocation {
130 MALI_DEBUG_CODE(u32 magic);
131 mali_mem_type type; /**< Type of memory */
132 u32 flags; /**< Flags for this allocation */
134 struct mali_session_data *session; /**< Pointer to session that owns the allocation */
136 mali_mem_virt_cpu_mapping cpu_mapping; /**< CPU mapping */
137 mali_mem_virt_mali_mapping mali_mapping; /**< Mali mapping */
139 /* add for new memory system */
140 struct mali_vma_node mali_vma_node;
141 u32 vsize; /* virtual size*/
142 u32 psize; /* physical backend memory size*/
143 struct list_head list;
144 s32 backend_handle; /* idr for mem_backend */
145 _mali_osk_atomic_t mem_alloc_refcount;
146 } mali_mem_allocation;
148 struct mali_mem_os_allocator {
149 spinlock_t pool_lock;
150 struct list_head pool_pages;
153 atomic_t allocated_pages;
154 size_t allocation_limit;
156 struct shrinker shrinker;
157 struct delayed_work timed_shrinker;
158 struct workqueue_struct *wq;
161 /* COW backend memory type */
162 typedef struct mali_mem_cow {
163 struct list_head pages; /**< all pages for this cow backend allocation,
164 including new allocated pages for modified range*/
165 u32 count; /**< number of pages */
169 typedef struct mali_mem_swap {
170 struct list_head pages;
174 typedef struct mali_mem_secure {
175 #if defined(CONFIG_DMA_SHARED_BUFFER)
177 struct dma_buf_attachment *attachment;
178 struct sg_table *sgt;
183 #define MALI_MEM_BACKEND_FLAG_COWED (0x1) /* COW has happen on this backend */
184 #define MALI_MEM_BACKEND_FLAG_COW_CPU_NO_WRITE (0x2) /* This is an COW backend, mapped as not allowed cpu to write */
185 #define MALI_MEM_BACKEND_FLAG_SWAP_COWED (0x4) /* Mark the given backend is cowed from swappable memory. */
186 /* Mark this backend is not swapped_in in MALI driver, and before using it,
187 * we should swap it in and set up corresponding page table. */
188 #define MALI_MEM_BACKEND_FLAG_UNSWAPPED_IN (0x8)
189 #define MALI_MEM_BACKEND_FLAG_NOT_BINDED (0x1 << 5) /* this backend it not back with physical memory, used for defer bind */
190 #define MALI_MEM_BACKEND_FLAG_BINDED (0x1 << 6) /* this backend it back with physical memory, used for defer bind */
192 typedef struct mali_mem_backend {
193 mali_mem_type type; /**< Type of backend memory */
194 u32 flags; /**< Flags for this allocation */
196 /* Union selected by type. */
198 mali_mem_os_mem os_mem; /**< MALI_MEM_OS */
199 mali_mem_external ext_mem; /**< MALI_MEM_EXTERNAL */
200 mali_mem_dma_buf dma_buf; /**< MALI_MEM_DMA_BUF */
201 mali_mem_ump ump_mem; /**< MALI_MEM_UMP */
202 mali_mem_block_mem block_mem; /**< MALI_MEM_BLOCK */
203 mali_mem_cow cow_mem;
204 mali_mem_swap swap_mem;
205 mali_mem_secure secure_mem;
207 mali_mem_allocation *mali_allocation;
209 mali_mem_type cow_type;
211 struct list_head list; /**< Used to link swappable memory backend to the global swappable list */
212 int using_count; /**< Mark how many PP jobs are using this memory backend */
213 u32 start_idx; /**< If the correspondign vma of this backend is linear, this value will be used to set vma->vm_pgoff */
216 #define MALI_MEM_FLAG_MALI_GUARD_PAGE (_MALI_MAP_EXTERNAL_MAP_GUARD_PAGE)
217 #define MALI_MEM_FLAG_DONT_CPU_MAP (1 << 1)
218 #define MALI_MEM_FLAG_CAN_RESIZE (_MALI_MEMORY_ALLOCATE_RESIZEABLE)
219 #endif /* __MALI_MEMORY_TYPES__ */