1 /* 2 * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef SPM_MM_SVC_H 8 #define SPM_MM_SVC_H 9 10 #include <lib/utils_def.h> 11 12 /* 13 * The MM_VERSION_XXX definitions are used when responding to the 14 * MM_VERSION_AARCH32 service request. The version returned is different between 15 * this request and the SPM_MM_VERSION_AARCH32 request - both have been retained 16 * for compatibility. 17 */ 18 #define MM_VERSION_MAJOR U(1) 19 #define MM_VERSION_MAJOR_SHIFT 16 20 #define MM_VERSION_MAJOR_MASK U(0x7FFF) 21 #define MM_VERSION_MINOR U(0) 22 #define MM_VERSION_MINOR_SHIFT 0 23 #define MM_VERSION_MINOR_MASK U(0xFFFF) 24 #define MM_VERSION_FORM(major, minor) ((major << MM_VERSION_MAJOR_SHIFT) | \ 25 (minor)) 26 #define MM_VERSION_COMPILED MM_VERSION_FORM(MM_VERSION_MAJOR, \ 27 MM_VERSION_MINOR) 28 29 #define SPM_MM_VERSION_MAJOR U(0) 30 #define SPM_MM_VERSION_MAJOR_SHIFT 16 31 #define SPM_MM_VERSION_MAJOR_MASK U(0x7FFF) 32 #define SPM_MM_VERSION_MINOR U(1) 33 #define SPM_MM_VERSION_MINOR_SHIFT 0 34 #define SPM_MM_VERSION_MINOR_MASK U(0xFFFF) 35 #define SPM_MM_VERSION_FORM(major, minor) ((major << \ 36 SPM_MM_VERSION_MAJOR_SHIFT) | \ 37 (minor)) 38 #define SPM_MM_VERSION_COMPILED SPM_MM_VERSION_FORM(SPM_MM_VERSION_MAJOR, \ 39 SPM_MM_VERSION_MINOR) 40 41 /* These macros are used to identify SPM-MM calls using the SMC function ID */ 42 #define SPM_MM_FID_MASK U(0xffff) 43 #define SPM_MM_FID_MIN_VALUE U(0x40) 44 #define SPM_MM_FID_MAX_VALUE U(0x7f) 45 #define is_spm_mm_fid(_fid) \ 46 ((((_fid) & SPM_MM_FID_MASK) >= SPM_MM_FID_MIN_VALUE) && \ 47 (((_fid) & SPM_MM_FID_MASK) <= SPM_MM_FID_MAX_VALUE)) 48 49 /* 50 * SMC IDs defined in [1] for accessing MM services from the Non-secure world. 51 * These FIDs occupy the range 0x40 - 0x5f. 52 * [1] DEN0060A_ARM_MM_Interface_Specification.pdf 53 */ 54 #define MM_VERSION_AARCH32 U(0x84000040) 55 #define MM_COMMUNICATE_AARCH64 U(0xC4000041) 56 #define MM_COMMUNICATE_AARCH32 U(0x84000041) 57 58 /* 59 * SMC IDs defined for accessing services implemented by the Secure Partition 60 * Manager from the Secure Partition(s). These services enable a partition to 61 * handle delegated events and request privileged operations from the manager. 62 * They occupy the range 0x60-0x7f. 63 */ 64 #define SPM_MM_VERSION_AARCH32 U(0x84000060) 65 #define MM_SP_EVENT_COMPLETE_AARCH64 U(0xC4000061) 66 #define MM_SP_MEMORY_ATTRIBUTES_GET_AARCH64 U(0xC4000064) 67 #define MM_SP_MEMORY_ATTRIBUTES_SET_AARCH64 U(0xC4000065) 68 69 /* 70 * Macros used by MM_SP_MEMORY_ATTRIBUTES_SET_AARCH64. 71 */ 72 73 #define MM_SP_MEMORY_ATTRIBUTES_ACCESS_NOACCESS U(0) 74 #define MM_SP_MEMORY_ATTRIBUTES_ACCESS_RW U(1) 75 /* Value U(2) is reserved. */ 76 #define MM_SP_MEMORY_ATTRIBUTES_ACCESS_RO U(3) 77 #define MM_SP_MEMORY_ATTRIBUTES_ACCESS_MASK U(3) 78 #define MM_SP_MEMORY_ATTRIBUTES_ACCESS_SHIFT 0 79 80 #define MM_SP_MEMORY_ATTRIBUTES_EXEC (U(0) << 2) 81 #define MM_SP_MEMORY_ATTRIBUTES_NON_EXEC (U(1) << 2) 82 83 84 /* SPM error codes. */ 85 #define SPM_MM_SUCCESS 0 86 #define SPM_MM_NOT_SUPPORTED -1 87 #define SPM_MM_INVALID_PARAMETER -2 88 #define SPM_MM_DENIED -3 89 #define SPM_MM_NO_MEMORY -5 90 91 #ifndef __ASSEMBLER__ 92 93 #include <stdint.h> 94 95 int32_t spm_mm_setup(void); 96 97 uint64_t spm_mm_smc_handler(uint32_t smc_fid, 98 uint64_t x1, 99 uint64_t x2, 100 uint64_t x3, 101 uint64_t x4, 102 void *cookie, 103 void *handle, 104 uint64_t flags); 105 106 /* Helper to enter a secure partition */ 107 uint64_t spm_mm_sp_call(uint32_t smc_fid, 108 uint64_t x1, 109 uint64_t x2, 110 uint64_t x3); 111 112 #endif /* __ASSEMBLER__ */ 113 114 #endif /* SPM_MM_SVC_H */ 115