xref: /rk3399_ARM-atf/plat/mediatek/common/mtk_bl31_lib.c (revision 06f3c7058c42a9f1a9f7df75ea2de71a000855e8)
1 /*
2  * Copyright (c) 2025, MediaTek Inc. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <common/debug.h>
8 #include <lib/xlat_tables/xlat_tables_v2.h>
9 
10 #include <mtk_bl31_interface.h>
11 #include <mtk_sip_svc.h>
12 
13 int mtk_bl31_map_to_sip_error(enum mtk_bl31_status status)
14 {
15 	switch (status) {
16 	case MTK_BL31_STATUS_SUCCESS:
17 		return MTK_SIP_E_SUCCESS;
18 	case MTK_BL31_STATUS_INVALID_PARAM:
19 		return MTK_SIP_E_INVALID_PARAM;
20 	case MTK_BL31_STATUS_NOT_SUPPORTED:
21 		return MTK_SIP_E_NOT_SUPPORTED;
22 	case MTK_BL31_STATUS_INVALID_RANGE:
23 		return MTK_SIP_E_INVALID_RANGE;
24 	case MTK_BL31_STATUS_PERMISSION_DENY:
25 		return MTK_SIP_E_PERMISSION_DENY;
26 	case MTK_BL31_STATUS_LOCK_FAIL:
27 		return MTK_SIP_E_LOCK_FAIL;
28 	default:
29 		ERROR("%s: unknown status: %d\n", __func__, status);
30 	}
31 
32 	return MTK_SIP_E_NOT_SUPPORTED;
33 }
34 
35 int mtk_bl31_mmap_add_dynamic_region(unsigned long long base_pa, size_t size,
36 				     enum mtk_bl31_memory_type type)
37 {
38 	unsigned int attr;
39 
40 	switch (type) {
41 	case MTK_BL31_DEV_RW_SEC:
42 		attr = MT_DEVICE | MT_RW | MT_SECURE;
43 		break;
44 	default:
45 		attr = 0;
46 		ERROR("%s: unknown memory type %d\n", __func__, type);
47 		break;
48 	}
49 
50 	return mmap_add_dynamic_region(base_pa, base_pa, size, attr);
51 }
52 
53 int mtk_bl31_mmap_remove_dynamic_region(uintptr_t base_va, size_t size)
54 {
55 	return mmap_remove_dynamic_region(base_va, size);
56 }
57