import OT_8063_20170412 mali driver
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / gpu / mt8127 / mali / mali / linux / mali_memory_external.c
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 #include "mali_kernel_common.h"
12 #include "mali_osk.h"
13 #include "mali_ukk.h"
14 #include "mali_memory.h"
15 #include "mali_mem_validation.h"
16 #include "mali_uk_types.h"
17
18 void mali_mem_unbind_ext_buf(mali_mem_backend *mem_backend)
19 {
20 mali_mem_allocation *alloc;
21 struct mali_session_data *session;
22 MALI_DEBUG_ASSERT_POINTER(mem_backend);
23 alloc = mem_backend->mali_allocation;
24 MALI_DEBUG_ASSERT_POINTER(alloc);
25 MALI_DEBUG_ASSERT(MALI_MEM_EXTERNAL == mem_backend->type);
26
27 session = alloc->session;
28 MALI_DEBUG_ASSERT_POINTER(session);
29 mali_session_memory_lock(session);
30 mali_mem_mali_map_free(session, alloc->psize, alloc->mali_vma_node.vm_node.start,
31 alloc->flags);
32 mali_session_memory_unlock(session);
33 }
34
35 _mali_osk_errcode_t mali_mem_bind_ext_buf(mali_mem_allocation *alloc,
36 mali_mem_backend *mem_backend,
37 u32 phys_addr,
38 u32 flag)
39 {
40 struct mali_session_data *session;
41 _mali_osk_errcode_t err;
42 u32 virt, phys, size;
43 MALI_DEBUG_ASSERT_POINTER(mem_backend);
44 MALI_DEBUG_ASSERT_POINTER(alloc);
45 size = alloc->psize;
46 session = (struct mali_session_data *)(uintptr_t)alloc->session;
47 MALI_CHECK_NON_NULL(session, _MALI_OSK_ERR_INVALID_ARGS);
48
49 /* check arguments */
50 /* NULL might be a valid Mali address */
51 if (!size) MALI_ERROR(_MALI_OSK_ERR_INVALID_ARGS);
52
53 /* size must be a multiple of the system page size */
54 if (size % _MALI_OSK_MALI_PAGE_SIZE) MALI_ERROR(_MALI_OSK_ERR_INVALID_ARGS);
55
56 /* Validate the mali physical range */
57 if (_MALI_OSK_ERR_OK != mali_mem_validation_check(phys_addr, size)) {
58 return _MALI_OSK_ERR_FAULT;
59 }
60
61 if (flag & _MALI_MAP_EXTERNAL_MAP_GUARD_PAGE) {
62 alloc->flags |= MALI_MEM_FLAG_MALI_GUARD_PAGE;
63 }
64
65 mali_session_memory_lock(session);
66
67 virt = alloc->mali_vma_node.vm_node.start;
68 phys = phys_addr;
69
70 err = mali_mem_mali_map_prepare(alloc);
71 if (_MALI_OSK_ERR_OK != err) {
72 mali_session_memory_unlock(session);
73 return _MALI_OSK_ERR_NOMEM;
74 }
75
76 mali_mmu_pagedir_update(session->page_directory, virt, phys, size, MALI_MMU_FLAGS_DEFAULT);
77
78 if (alloc->flags & MALI_MEM_FLAG_MALI_GUARD_PAGE) {
79 mali_mmu_pagedir_update(session->page_directory, virt + size, phys, _MALI_OSK_MALI_PAGE_SIZE, MALI_MMU_FLAGS_DEFAULT);
80 }
81 MALI_DEBUG_PRINT(3,
82 ("Requested to map physical memory 0x%x-0x%x into virtual memory 0x%x\n",
83 phys_addr, (phys_addr + size - 1),
84 virt));
85 mali_session_memory_unlock(session);
86
87 MALI_SUCCESS;
88 }
89