1 /* 2 * Copyright (c) 2022-2023, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <common/debug.h> 8 #include <emi_mpu.h> 9 #include <mtk_sip_svc.h> 10 11 #define MPU_PHYSICAL_ADDR_SHIFT_BITS (16) 12 13 void set_emi_mpu_regions(void) 14 { 15 /* TODO: set emi mpu region */ 16 INFO("%s, emi mpu is not setting currently\n", __func__); 17 } 18 19 int set_apu_emi_mpu_region(void) 20 { 21 struct emi_region_info_t region_info; 22 23 region_info.start = (unsigned long long)APUSYS_SEC_BUF_PA; 24 region_info.end = (unsigned long long)(APUSYS_SEC_BUF_PA + APUSYS_SEC_BUF_SZ) - 1; 25 region_info.region = APUSYS_SEC_BUF_EMI_REGION; 26 27 SET_ACCESS_PERMISSION(region_info.apc, UNLOCK, 28 FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, 29 FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, 30 NO_PROTECTION, FORBIDDEN, NO_PROTECTION, FORBIDDEN, 31 FORBIDDEN, FORBIDDEN, FORBIDDEN, SEC_RW); 32 33 return emi_mpu_set_protection(®ion_info); 34 } 35 36 static inline uint64_t get_decoded_phys_addr(uint64_t addr) 37 { 38 return (addr << MPU_PHYSICAL_ADDR_SHIFT_BITS); 39 } 40 41 static inline uint32_t get_decoded_zone_id(uint32_t info) 42 { 43 return ((info & 0xFFFF0000) >> MPU_PHYSICAL_ADDR_SHIFT_BITS); 44 } 45 46 int emi_mpu_optee_handler(uint64_t encoded_addr, uint64_t zone_size, 47 uint64_t zone_info) 48 { 49 uint64_t phys_addr = get_decoded_phys_addr(encoded_addr); 50 struct emi_region_info_t region_info; 51 enum MPU_REQ_ORIGIN_ZONE_ID zone_id = get_decoded_zone_id(zone_info); 52 53 INFO("encoded_addr = 0x%lx, zone_size = 0x%lx, zone_info = 0x%lx\n", 54 encoded_addr, zone_size, zone_info); 55 56 if (zone_id != MPU_REQ_ORIGIN_TEE_ZONE_SVP) { 57 ERROR("Invalid param %s, %d\n", __func__, __LINE__); 58 return MTK_SIP_E_INVALID_PARAM; 59 } 60 61 /* SVP DRAM */ 62 region_info.start = phys_addr; 63 region_info.end = phys_addr + zone_size; 64 region_info.region = 4; 65 SET_ACCESS_PERMISSION(region_info.apc, 1, 66 FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, 67 FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, 68 FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, 69 FORBIDDEN, FORBIDDEN, FORBIDDEN, SEC_RW); 70 71 emi_mpu_set_protection(®ion_info); 72 73 return 0; 74 }