tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / r4p0_rel0 / linux / mali_memory.h
1 /*
2  * Copyright (C) 2010-2012 ARM Limited. All rights reserved.
3  * 
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.
6  * 
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.
9  */
10
11 #ifndef __MALI_MEMORY_H__
12 #define __MALI_MEMORY_H__
13
14 #include "mali_osk.h"
15 #include "mali_session.h"
16
17 #include <linux/list.h>
18 #include <linux/mm.h>
19
20 #include "mali_memory_types.h"
21 #include "mali_memory_os_alloc.h"
22
23 _mali_osk_errcode_t mali_memory_initialize(void);
24 void mali_memory_terminate(void);
25
26 /** @brief Allocate a page table page
27  *
28  * Allocate a page for use as a page directory or page table. The page is
29  * mapped into kernel space.
30  *
31  * @return _MALI_OSK_ERR_OK on success, otherwise an error code
32  * @param table_page GPU pointer to the allocated page
33  * @param mapping CPU pointer to the mapping of the allocated page
34  */
35 MALI_STATIC_INLINE _mali_osk_errcode_t mali_mmu_get_table_page(u32 *table_page, mali_io_address *mapping)
36 {
37         return mali_mem_os_get_table_page(table_page, mapping);
38 }
39
40 /** @brief Release a page table page
41  *
42  * Release a page table page allocated through \a mali_mmu_get_table_page
43  *
44  * @param pa the GPU address of the page to release
45  */
46 MALI_STATIC_INLINE void mali_mmu_release_table_page(u32 phys, void *virt)
47 {
48         mali_mem_os_release_table_page(phys, virt);
49 }
50
51 /** @brief mmap function
52  *
53  * mmap syscalls on the Mali device node will end up here.
54  *
55  * This function allocates Mali memory and maps it on CPU and Mali.
56  */
57 int mali_mmap(struct file *filp, struct vm_area_struct *vma);
58
59 /** @brief Allocate and initialize a Mali memory descriptor
60  *
61  * @param session Pointer to the session allocating the descriptor
62  * @param type Type of memory the descriptor will represent
63  */
64 mali_mem_allocation *mali_mem_descriptor_create(struct mali_session_data *session, mali_mem_type type);
65
66 /** @brief Destroy a Mali memory descriptor
67  *
68  * This function will only free the descriptor itself, and not the memory it
69  * represents.
70  *
71  * @param descriptor Pointer to the descriptor to destroy
72  */
73 void mali_mem_descriptor_destroy(mali_mem_allocation *descriptor);
74
75 /** @brief Start a new memory session
76  *
77  * Called when a process opens the Mali device node.
78  *
79  * @param session Pointer to session to initialize
80  */
81 _mali_osk_errcode_t mali_memory_session_begin(struct mali_session_data *session);
82
83 /** @brief Close a memory session
84  *
85  * Called when a process closes the Mali device node.
86  *
87  * Memory allocated by the session will be freed
88  *
89  * @param session Pointer to the session to terminate
90  */
91 void mali_memory_session_end(struct mali_session_data *session);
92
93 /** @brief Prepare Mali page tables for mapping
94  *
95  * This function will prepare the Mali page tables for mapping the memory
96  * described by \a descriptor.
97  *
98  * Page tables will be reference counted and allocated, if not yet present.
99  *
100  * @param descriptor Pointer to the memory descriptor to the mapping
101  */
102 _mali_osk_errcode_t mali_mem_mali_map_prepare(mali_mem_allocation *descriptor);
103
104 /** @brief Free Mali page tables for mapping
105  *
106  * This function will unmap pages from Mali memory and free the page tables
107  * that are now unused.
108  *
109  * The updated pages in the Mali L2 cache will be invalidated, and the MMU TLBs will be zapped if necessary.
110  *
111  * @param descriptor Pointer to the memory descriptor to unmap
112  */
113 void mali_mem_mali_map_free(mali_mem_allocation *descriptor);
114
115 /** @brief Parse resource and prepare the OS memory allocator
116  *
117  * @param size Maximum size to allocate for Mali GPU.
118  * @return _MALI_OSK_ERR_OK on success, otherwise failure.
119  */
120 _mali_osk_errcode_t mali_memory_core_resource_os_memory(u32 size);
121
122 /** @brief Parse resource and prepare the dedicated memory allocator
123  *
124  * @param start Physical start address of dedicated Mali GPU memory.
125  * @param size Size of dedicated Mali GPU memory.
126  * @return _MALI_OSK_ERR_OK on success, otherwise failure.
127  */
128 _mali_osk_errcode_t mali_memory_core_resource_dedicated_memory(u32 start, u32 size);
129
130
131 void mali_mem_ump_release(mali_mem_allocation *descriptor);
132 void mali_mem_external_release(mali_mem_allocation *descriptor);
133
134 #endif /* __MALI_MEMORY_H__ */