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 /* 42 * These macros are used to identify MM calls using the SMC function ID 43 * See the SMCCC spec's Table 6-4: Reserved Standard Secure Service Call range. 44 */ 45 #define MM_FID_MASK U(0xffff) 46 #define MM_FID_MIN_VALUE U(0x40) 47 #define MM_FID_MAX_VALUE U(0x4f) 48 /* 49 * SMC IDs defined in [1] for accessing MM services from the Non-secure world. 50 * These FIDs occupy the range 0x40 - 0x4f. 51 * [1] DEN0028 - SMC Calling Convention. 52 * Table 6-4: Reserved Standard Secure Service Call range 53 * [2] DEN0060A - Management Mode Interface Specification. 54 */ 55 #define MM_VERSION_AARCH32 U(0x84000040) 56 #define MM_COMMUNICATE_AARCH64 U(0xC4000041) 57 #define MM_COMMUNICATE_AARCH32 U(0x84000041) 58 59 /* 60 * SMC IDs defined for accessing services implemented by the Secure Partition 61 * Manager from the Secure Partition(s). These services enable a partition to 62 * handle delegated events and request privileged operations from the manager. 63 * They occupy the range 0x60-0x7f. 64 */ 65 #define SPM_MM_VERSION_AARCH32 U(0x84000060) 66 #define MM_SP_EVENT_COMPLETE_AARCH64 U(0xC4000061) 67 #define MM_SP_MEMORY_ATTRIBUTES_GET_AARCH64 U(0xC4000064) 68 #define MM_SP_MEMORY_ATTRIBUTES_SET_AARCH64 U(0xC4000065) 69 70 /* 71 * Vendor-specific EL3 range SMC IDs defined for TPM start method for pre-FFA 72 * configuration. These SMCs are converted to MM_COMMUNICATE calls. 73 */ 74 #define TPM_START_SMC_32 U(0x87000040) 75 #define TPM_START_SMC_64 U(0xC7000040) 76 77 /* 78 * Macros used by MM_SP_MEMORY_ATTRIBUTES_SET_AARCH64. 79 */ 80 81 #define MM_SP_MEMORY_ATTRIBUTES_ACCESS_NOACCESS U(0) 82 #define MM_SP_MEMORY_ATTRIBUTES_ACCESS_RW U(1) 83 /* Value U(2) is reserved. */ 84 #define MM_SP_MEMORY_ATTRIBUTES_ACCESS_RO U(3) 85 #define MM_SP_MEMORY_ATTRIBUTES_ACCESS_MASK U(3) 86 #define MM_SP_MEMORY_ATTRIBUTES_ACCESS_SHIFT 0 87 88 #define MM_SP_MEMORY_ATTRIBUTES_EXEC (U(0) << 2) 89 #define MM_SP_MEMORY_ATTRIBUTES_NON_EXEC (U(1) << 2) 90 91 92 /* SPM error codes. */ 93 #define SPM_MM_SUCCESS 0 94 #define SPM_MM_NOT_SUPPORTED -1 95 #define SPM_MM_INVALID_PARAMETER -2 96 #define SPM_MM_DENIED -3 97 #define SPM_MM_NO_MEMORY -5 98 99 #ifndef __ASSEMBLER__ 100 101 #include <stdint.h> 102 #include <tools_share/uuid.h> 103 104 /* 105 * MM Communicate information structure. Required to generate MM Communicate 106 * payload to be shared with Standalone MM. 107 */ 108 typedef struct mm_communicate_header { 109 struct efi_guid header_guid; 110 size_t message_len; 111 uint8_t data[1]; 112 } mm_communicate_header_t; 113 114 int32_t spm_mm_setup(void); 115 116 uint64_t spm_mm_smc_handler(uint32_t smc_fid, 117 uint64_t x1, 118 uint64_t x2, 119 uint64_t x3, 120 uint64_t x4, 121 void *cookie, 122 void *handle, 123 uint64_t flags); 124 125 /* Helper to enter a secure partition */ 126 uint64_t spm_mm_sp_call(uint32_t smc_fid, 127 uint64_t x1, 128 uint64_t x2, 129 uint64_t x3); 130 131 /* Helper to handle TPM Start SVC call */ 132 uint64_t spm_mm_tpm_start_handler(uint32_t smc_fid, 133 uint64_t x1, 134 uint64_t x2, 135 uint64_t x3, 136 uint64_t x4, 137 void *cookie, 138 void *handle, 139 uint64_t flags); 140 141 bool is_spm_mm_fid(uint32_t smc_fid); 142 143 #endif /* __ASSEMBLER__ */ 144 145 #endif /* SPM_MM_SVC_H */ 146