mali mess
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / gpu / mt8127 / mali / mali / linux / mali_memory.h
1 /*
2 * This confidential and proprietary software may be used only as
3 * authorised by a licensing agreement from ARM Limited
4 * (C) COPYRIGHT 2013-2015 ARM Limited
5 * ALL RIGHTS RESERVED
6 * The entire notice above must be reproduced on all authorised
7 * copies and copies may only be made to the extent permitted
8 * by a licensing agreement from ARM Limited.
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
36 mali_mmu_get_table_page(mali_dma_addr *table_page, mali_io_address *mapping)
37 {
38 return mali_mem_os_get_table_page(table_page, mapping);
39 }
40
41 /** @brief Release a page table page
42 *
43 * Release a page table page allocated through \a mali_mmu_get_table_page
44 *
45 * @param pa the GPU address of the page to release
46 */
47 MALI_STATIC_INLINE void
48 mali_mmu_release_table_page(mali_dma_addr phys, void *virt)
49 {
50 mali_mem_os_release_table_page(phys, virt);
51 }
52
53 /** @brief mmap function
54 *
55 * mmap syscalls on the Mali device node will end up here.
56 *
57 * This function allocates Mali memory and maps it on CPU and Mali.
58 */
59 int mali_mmap(struct file *filp, struct vm_area_struct *vma);
60
61 /** @brief Start a new memory session
62 *
63 * Called when a process opens the Mali device node.
64 *
65 * @param session Pointer to session to initialize
66 */
67 _mali_osk_errcode_t mali_memory_session_begin(struct mali_session_data *session);
68
69 /** @brief Close a memory session
70 *
71 * Called when a process closes the Mali device node.
72 *
73 * Memory allocated by the session will be freed
74 *
75 * @param session Pointer to the session to terminate
76 */
77 void mali_memory_session_end(struct mali_session_data *session);
78
79 /** @brief Prepare Mali page tables for mapping
80 *
81 * This function will prepare the Mali page tables for mapping the memory
82 * described by \a descriptor.
83 *
84 * Page tables will be reference counted and allocated, if not yet present.
85 *
86 * @param descriptor Pointer to the memory descriptor to the mapping
87 */
88 _mali_osk_errcode_t mali_mem_mali_map_prepare(mali_mem_allocation *descriptor);
89
90 /** @brief Free Mali page tables for mapping
91 *
92 * This function will unmap pages from Mali memory and free the page tables
93 * that are now unused.
94 *
95 * The updated pages in the Mali L2 cache will be invalidated, and the MMU TLBs will be zapped if necessary.
96 *
97 * @param descriptor Pointer to the memory descriptor to unmap
98 */
99 void mali_mem_mali_map_free(struct mali_session_data *session, u32 size, mali_address_t vaddr, u32 flags);
100
101 /** @brief Parse resource and prepare the OS memory allocator
102 *
103 * @param size Maximum size to allocate for Mali GPU.
104 * @return _MALI_OSK_ERR_OK on success, otherwise failure.
105 */
106 _mali_osk_errcode_t mali_memory_core_resource_os_memory(u32 size);
107
108 /** @brief Parse resource and prepare the dedicated memory allocator
109 *
110 * @param start Physical start address of dedicated Mali GPU memory.
111 * @param size Size of dedicated Mali GPU memory.
112 * @return _MALI_OSK_ERR_OK on success, otherwise failure.
113 */
114 _mali_osk_errcode_t mali_memory_core_resource_dedicated_memory(u32 start, u32 size);
115
116
117 struct mali_page_node *_mali_page_node_allocate(mali_page_node_type type);
118
119 void _mali_page_node_ref(struct mali_page_node *node);
120 void _mali_page_node_unref(struct mali_page_node *node);
121 void _mali_page_node_add_page(struct mali_page_node *node, struct page *page);
122
123 void _mali_page_node_add_block_item(struct mali_page_node *node, mali_block_item *item);
124
125 int _mali_page_node_get_ref_count(struct mali_page_node *node);
126 dma_addr_t _mali_page_node_get_phy_addr(struct mali_page_node *node);
127 unsigned long _mali_page_node_get_pfn(struct mali_page_node *node);
128
129 #endif /* __MALI_MEMORY_H__ */