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
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.
11 #include "mali_kernel_common.h"
14 #include "mali_memory.h"
15 #include "mali_mem_validation.h"
16 #include "mali_uk_types.h"
18 void mali_mem_unbind_ext_buf(mali_mem_backend
*mem_backend
)
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
);
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
,
32 mali_session_memory_unlock(session
);
35 _mali_osk_errcode_t
mali_mem_bind_ext_buf(mali_mem_allocation
*alloc
,
36 mali_mem_backend
*mem_backend
,
40 struct mali_session_data
*session
;
41 _mali_osk_errcode_t err
;
43 MALI_DEBUG_ASSERT_POINTER(mem_backend
);
44 MALI_DEBUG_ASSERT_POINTER(alloc
);
46 session
= (struct mali_session_data
*)(uintptr_t)alloc
->session
;
47 MALI_CHECK_NON_NULL(session
, _MALI_OSK_ERR_INVALID_ARGS
);
50 /* NULL might be a valid Mali address */
51 if (!size
) MALI_ERROR(_MALI_OSK_ERR_INVALID_ARGS
);
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
);
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
;
61 if (flag
& _MALI_MAP_EXTERNAL_MAP_GUARD_PAGE
) {
62 alloc
->flags
|= MALI_MEM_FLAG_MALI_GUARD_PAGE
;
65 mali_session_memory_lock(session
);
67 virt
= alloc
->mali_vma_node
.vm_node
.start
;
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
;
76 mali_mmu_pagedir_update(session
->page_directory
, virt
, phys
, size
, MALI_MMU_FLAGS_DEFAULT
);
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
);
82 ("Requested to map physical memory 0x%x-0x%x into virtual memory 0x%x\n",
83 phys_addr
, (phys_addr
+ size
- 1),
85 mali_session_memory_unlock(session
);