summaryrefslogtreecommitdiff
path: root/drivers/gpu/mali/mali/linux/mali_memory.h
blob: dcdc953f2bd10837de86375a60711a8feaf6c376 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * Copyright (C) 2013-2014 ARM Limited. All rights reserved.
 * 
 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
 * 
 * A copy of the licence is included with the program, and can also be obtained from Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef __MALI_MEMORY_H__
#define __MALI_MEMORY_H__

#include "mali_osk.h"
#include "mali_session.h"

#include <linux/list.h>
#include <linux/mm.h>

#include "mali_memory_types.h"
#include "mali_memory_os_alloc.h"

_mali_osk_errcode_t mali_memory_initialize(void);
void mali_memory_terminate(void);

/** @brief Allocate a page table page
 *
 * Allocate a page for use as a page directory or page table. The page is
 * mapped into kernel space.
 *
 * @return _MALI_OSK_ERR_OK on success, otherwise an error code
 * @param table_page GPU pointer to the allocated page
 * @param mapping CPU pointer to the mapping of the allocated page
 */
MALI_STATIC_INLINE _mali_osk_errcode_t
mali_mmu_get_table_page(mali_dma_addr *table_page, mali_io_address *mapping)
{
	return mali_mem_os_get_table_page(table_page, mapping);
}

/** @brief Release a page table page
 *
 * Release a page table page allocated through \a mali_mmu_get_table_page
 *
 * @param pa the GPU address of the page to release
 */
MALI_STATIC_INLINE void
mali_mmu_release_table_page(mali_dma_addr phys, void *virt)
{
	mali_mem_os_release_table_page(phys, virt);
}

/** @brief mmap function
 *
 * mmap syscalls on the Mali device node will end up here.
 *
 * This function allocates Mali memory and maps it on CPU and Mali.
 */
int mali_mmap(struct file *filp, struct vm_area_struct *vma);

/** @brief Allocate and initialize a Mali memory descriptor
 *
 * @param session Pointer to the session allocating the descriptor
 * @param type Type of memory the descriptor will represent
 */
mali_mem_allocation *mali_mem_descriptor_create(struct mali_session_data *session, mali_mem_type type);

/** @brief Destroy a Mali memory descriptor
 *
 * This function will only free the descriptor itself, and not the memory it
 * represents.
 *
 * @param descriptor Pointer to the descriptor to destroy
 */
void mali_mem_descriptor_destroy(mali_mem_allocation *descriptor);

/** @brief Start a new memory session
 *
 * Called when a process opens the Mali device node.
 *
 * @param session Pointer to session to initialize
 */
_mali_osk_errcode_t mali_memory_session_begin(struct mali_session_data *session);

/** @brief Close a memory session
 *
 * Called when a process closes the Mali device node.
 *
 * Memory allocated by the session will be freed
 *
 * @param session Pointer to the session to terminate
 */
void mali_memory_session_end(struct mali_session_data *session);

/** @brief Prepare Mali page tables for mapping
 *
 * This function will prepare the Mali page tables for mapping the memory
 * described by \a descriptor.
 *
 * Page tables will be reference counted and allocated, if not yet present.
 *
 * @param descriptor Pointer to the memory descriptor to the mapping
 */
_mali_osk_errcode_t mali_mem_mali_map_prepare(mali_mem_allocation *descriptor);

/** @brief Free Mali page tables for mapping
 *
 * This function will unmap pages from Mali memory and free the page tables
 * that are now unused.
 *
 * The updated pages in the Mali L2 cache will be invalidated, and the MMU TLBs will be zapped if necessary.
 *
 * @param descriptor Pointer to the memory descriptor to unmap
 */
void mali_mem_mali_map_free(mali_mem_allocation *descriptor);

/** @brief Parse resource and prepare the OS memory allocator
 *
 * @param size Maximum size to allocate for Mali GPU.
 * @return _MALI_OSK_ERR_OK on success, otherwise failure.
 */
_mali_osk_errcode_t mali_memory_core_resource_os_memory(u32 size);

/** @brief Parse resource and prepare the dedicated memory allocator
 *
 * @param start Physical start address of dedicated Mali GPU memory.
 * @param size Size of dedicated Mali GPU memory.
 * @return _MALI_OSK_ERR_OK on success, otherwise failure.
 */
_mali_osk_errcode_t mali_memory_core_resource_dedicated_memory(u32 start, u32 size);


void mali_mem_ump_release(mali_mem_allocation *descriptor);
void mali_mem_external_release(mali_mem_allocation *descriptor);

#endif /* __MALI_MEMORY_H__ */