Committer:
ganlikun
Date:
Mon Oct 24 15:19:39 2022 +0000
Revision:
0:06036f8bee2d
11

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ganlikun 0:06036f8bee2d 1 /**************************************************************************//**
ganlikun 0:06036f8bee2d 2 * @file core_cmSecureAccess.h
ganlikun 0:06036f8bee2d 3 * @brief CMSIS Cortex-M Core Secure Access Header File
ganlikun 0:06036f8bee2d 4 * @version XXX
ganlikun 0:06036f8bee2d 5 * @date 10. June 2016
ganlikun 0:06036f8bee2d 6 *
ganlikun 0:06036f8bee2d 7 * @note
ganlikun 0:06036f8bee2d 8 *
ganlikun 0:06036f8bee2d 9 ******************************************************************************/
ganlikun 0:06036f8bee2d 10 /* Copyright (c) 2016 ARM LIMITED
ganlikun 0:06036f8bee2d 11
ganlikun 0:06036f8bee2d 12 All rights reserved.
ganlikun 0:06036f8bee2d 13 Redistribution and use in source and binary forms, with or without
ganlikun 0:06036f8bee2d 14 modification, are permitted provided that the following conditions are met:
ganlikun 0:06036f8bee2d 15 - Redistributions of source code must retain the above copyright
ganlikun 0:06036f8bee2d 16 notice, this list of conditions and the following disclaimer.
ganlikun 0:06036f8bee2d 17 - Redistributions in binary form must reproduce the above copyright
ganlikun 0:06036f8bee2d 18 notice, this list of conditions and the following disclaimer in the
ganlikun 0:06036f8bee2d 19 documentation and/or other materials provided with the distribution.
ganlikun 0:06036f8bee2d 20 - Neither the name of ARM nor the names of its contributors may be used
ganlikun 0:06036f8bee2d 21 to endorse or promote products derived from this software without
ganlikun 0:06036f8bee2d 22 specific prior written permission.
ganlikun 0:06036f8bee2d 23 *
ganlikun 0:06036f8bee2d 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
ganlikun 0:06036f8bee2d 25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ganlikun 0:06036f8bee2d 26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ganlikun 0:06036f8bee2d 27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
ganlikun 0:06036f8bee2d 28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
ganlikun 0:06036f8bee2d 29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
ganlikun 0:06036f8bee2d 30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
ganlikun 0:06036f8bee2d 31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
ganlikun 0:06036f8bee2d 32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ganlikun 0:06036f8bee2d 33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
ganlikun 0:06036f8bee2d 34 POSSIBILITY OF SUCH DAMAGE.
ganlikun 0:06036f8bee2d 35 ---------------------------------------------------------------------------*/
ganlikun 0:06036f8bee2d 36
ganlikun 0:06036f8bee2d 37
ganlikun 0:06036f8bee2d 38 #ifndef __CORE_CM_SECURE_ACCESS_H
ganlikun 0:06036f8bee2d 39 #define __CORE_CM_SECURE_ACCESS_H
ganlikun 0:06036f8bee2d 40
ganlikun 0:06036f8bee2d 41
ganlikun 0:06036f8bee2d 42 /* ########################### Core Secure Access ########################### */
ganlikun 0:06036f8bee2d 43
ganlikun 0:06036f8bee2d 44 #ifdef FEATURE_UVISOR
ganlikun 0:06036f8bee2d 45 #include "uvisor-lib/uvisor-lib.h"
ganlikun 0:06036f8bee2d 46
ganlikun 0:06036f8bee2d 47 /* Secure uVisor implementation. */
ganlikun 0:06036f8bee2d 48
ganlikun 0:06036f8bee2d 49 /** Set the value at the target address.
ganlikun 0:06036f8bee2d 50 *
ganlikun 0:06036f8bee2d 51 * Equivalent to: `*address = value`.
ganlikun 0:06036f8bee2d 52 * @param address[in] Target address
ganlikun 0:06036f8bee2d 53 * @param value[in] Value to write at the address location.
ganlikun 0:06036f8bee2d 54 */
ganlikun 0:06036f8bee2d 55 #define SECURE_WRITE(address, value) \
ganlikun 0:06036f8bee2d 56 uvisor_write(public_box, UVISOR_RGW_SHARED, address, value, UVISOR_RGW_OP_WRITE, 0xFFFFFFFFUL)
ganlikun 0:06036f8bee2d 57
ganlikun 0:06036f8bee2d 58 /** Get the value at the target address.
ganlikun 0:06036f8bee2d 59 *
ganlikun 0:06036f8bee2d 60 * @param address[in] Target address
ganlikun 0:06036f8bee2d 61 * @returns The value `*address`.
ganlikun 0:06036f8bee2d 62 */
ganlikun 0:06036f8bee2d 63 #define SECURE_READ(address) \
ganlikun 0:06036f8bee2d 64 uvisor_read(public_box, UVISOR_RGW_SHARED, address, UVISOR_RGW_OP_READ, 0xFFFFFFFFUL)
ganlikun 0:06036f8bee2d 65
ganlikun 0:06036f8bee2d 66 /** Get the selected bits at the target address.
ganlikun 0:06036f8bee2d 67 *
ganlikun 0:06036f8bee2d 68 * @param address[in] Target address
ganlikun 0:06036f8bee2d 69 * @param mask[in] Bits to select out of the target address
ganlikun 0:06036f8bee2d 70 * @returns The value `*address & mask`.
ganlikun 0:06036f8bee2d 71 */
ganlikun 0:06036f8bee2d 72 #define SECURE_BITS_GET(address, mask) \
ganlikun 0:06036f8bee2d 73 UVISOR_BITS_GET(public_box, UVISOR_RGW_SHARED, address, mask)
ganlikun 0:06036f8bee2d 74
ganlikun 0:06036f8bee2d 75 /** Check the selected bits at the target address.
ganlikun 0:06036f8bee2d 76 *
ganlikun 0:06036f8bee2d 77 * @param address[in] Address at which to check the bits
ganlikun 0:06036f8bee2d 78 * @param mask[in] Bits to select out of the target address
ganlikun 0:06036f8bee2d 79 * @returns The value `((*address & mask) == mask)`.
ganlikun 0:06036f8bee2d 80 */
ganlikun 0:06036f8bee2d 81 #define SECURE_BITS_CHECK(address, mask) \
ganlikun 0:06036f8bee2d 82 UVISOR_BITS_CHECK(public_box, UVISOR_RGW_SHARED, address, mask)
ganlikun 0:06036f8bee2d 83
ganlikun 0:06036f8bee2d 84 /** Set the selected bits to 1 at the target address.
ganlikun 0:06036f8bee2d 85 *
ganlikun 0:06036f8bee2d 86 * Equivalent to: `*address |= mask`.
ganlikun 0:06036f8bee2d 87 * @param address[in] Target address
ganlikun 0:06036f8bee2d 88 * @param mask[in] Bits to select out of the target address
ganlikun 0:06036f8bee2d 89 */
ganlikun 0:06036f8bee2d 90 #define SECURE_BITS_SET(address, mask) \
ganlikun 0:06036f8bee2d 91 UVISOR_BITS_SET(public_box, UVISOR_RGW_SHARED, address, mask)
ganlikun 0:06036f8bee2d 92
ganlikun 0:06036f8bee2d 93 /** Clear the selected bits at the target address.
ganlikun 0:06036f8bee2d 94 *
ganlikun 0:06036f8bee2d 95 * Equivalent to: `*address &= ~mask`.
ganlikun 0:06036f8bee2d 96 * @param address[in] Target address
ganlikun 0:06036f8bee2d 97 * @param mask[in] Bits to select out of the target address
ganlikun 0:06036f8bee2d 98 */
ganlikun 0:06036f8bee2d 99 #define SECURE_BITS_CLEAR(address, mask) \
ganlikun 0:06036f8bee2d 100 UVISOR_BITS_CLEAR(public_box, UVISOR_RGW_SHARED, address, mask)
ganlikun 0:06036f8bee2d 101
ganlikun 0:06036f8bee2d 102 /** Set the selected bits at the target address to the given value.
ganlikun 0:06036f8bee2d 103 *
ganlikun 0:06036f8bee2d 104 * Equivalent to: `*address = (*address & ~mask) | (value & mask)`.
ganlikun 0:06036f8bee2d 105 * @param address[in] Target address
ganlikun 0:06036f8bee2d 106 * @param mask[in] Bits to select out of the target address
ganlikun 0:06036f8bee2d 107 * @param value[in] Value to write at the address location. Note: The value
ganlikun 0:06036f8bee2d 108 * must be already shifted to the correct bit position
ganlikun 0:06036f8bee2d 109 */
ganlikun 0:06036f8bee2d 110 #define SECURE_BITS_SET_VALUE(address, mask, value) \
ganlikun 0:06036f8bee2d 111 UVISOR_BITS_SET_VALUE(public_box, UVISOR_RGW_SHARED, address, mask, value)
ganlikun 0:06036f8bee2d 112
ganlikun 0:06036f8bee2d 113 /** Toggle the selected bits at the target address.
ganlikun 0:06036f8bee2d 114 *
ganlikun 0:06036f8bee2d 115 * Equivalent to: `*address ^= mask`.
ganlikun 0:06036f8bee2d 116 * @param address[in] Target address
ganlikun 0:06036f8bee2d 117 * @param mask[in] Bits to select out of the target address
ganlikun 0:06036f8bee2d 118 */
ganlikun 0:06036f8bee2d 119 #define SECURE_BITS_TOGGLE(address, mask) \
ganlikun 0:06036f8bee2d 120 UVISOR_BITS_TOGGLE(public_box, UVISOR_RGW_SHARED, address, mask)
ganlikun 0:06036f8bee2d 121
ganlikun 0:06036f8bee2d 122 #else
ganlikun 0:06036f8bee2d 123
ganlikun 0:06036f8bee2d 124 /* Insecure fallback implementation. */
ganlikun 0:06036f8bee2d 125
ganlikun 0:06036f8bee2d 126 /** Set the value at the target address.
ganlikun 0:06036f8bee2d 127 *
ganlikun 0:06036f8bee2d 128 * Equivalent to: `*address = value`.
ganlikun 0:06036f8bee2d 129 * @param address[in] Target address
ganlikun 0:06036f8bee2d 130 * @param value[in] Value to write at the address location.
ganlikun 0:06036f8bee2d 131 */
ganlikun 0:06036f8bee2d 132 #define SECURE_WRITE(address, value) \
ganlikun 0:06036f8bee2d 133 *(address) = (value)
ganlikun 0:06036f8bee2d 134
ganlikun 0:06036f8bee2d 135 /** Get the value at the target address.
ganlikun 0:06036f8bee2d 136 *
ganlikun 0:06036f8bee2d 137 * @param address[in] Target address
ganlikun 0:06036f8bee2d 138 * @returns The value `*address`.
ganlikun 0:06036f8bee2d 139 */
ganlikun 0:06036f8bee2d 140 #define SECURE_READ(address) \
ganlikun 0:06036f8bee2d 141 (*(address))
ganlikun 0:06036f8bee2d 142
ganlikun 0:06036f8bee2d 143 /** Get the selected bits at the target address.
ganlikun 0:06036f8bee2d 144 *
ganlikun 0:06036f8bee2d 145 * @param address[in] Target address
ganlikun 0:06036f8bee2d 146 * @param mask[in] Bits to select out of the target address
ganlikun 0:06036f8bee2d 147 * @returns The value `*address & mask`.
ganlikun 0:06036f8bee2d 148 */
ganlikun 0:06036f8bee2d 149 #define SECURE_BITS_GET(address, mask) \
ganlikun 0:06036f8bee2d 150 (*(address) & (mask))
ganlikun 0:06036f8bee2d 151
ganlikun 0:06036f8bee2d 152 /** Check the selected bits at the target address.
ganlikun 0:06036f8bee2d 153 *
ganlikun 0:06036f8bee2d 154 * @param address[in] Address at which to check the bits
ganlikun 0:06036f8bee2d 155 * @param mask[in] Bits to select out of the target address
ganlikun 0:06036f8bee2d 156 * @returns The value `((*address & mask) == mask)`.
ganlikun 0:06036f8bee2d 157 */
ganlikun 0:06036f8bee2d 158 #define SECURE_BITS_CHECK(address, mask) \
ganlikun 0:06036f8bee2d 159 ((*(address) & (mask)) == (mask))
ganlikun 0:06036f8bee2d 160
ganlikun 0:06036f8bee2d 161 /** Set the selected bits to 1 at the target address.
ganlikun 0:06036f8bee2d 162 *
ganlikun 0:06036f8bee2d 163 * Equivalent to: `*address |= mask`.
ganlikun 0:06036f8bee2d 164 * @param address[in] Target address
ganlikun 0:06036f8bee2d 165 * @param mask[in] Bits to select out of the target address
ganlikun 0:06036f8bee2d 166 */
ganlikun 0:06036f8bee2d 167 #define SECURE_BITS_SET(address, mask) \
ganlikun 0:06036f8bee2d 168 *(address) |= (mask)
ganlikun 0:06036f8bee2d 169
ganlikun 0:06036f8bee2d 170 /** Clear the selected bits at the target address.
ganlikun 0:06036f8bee2d 171 *
ganlikun 0:06036f8bee2d 172 * Equivalent to: `*address &= ~mask`.
ganlikun 0:06036f8bee2d 173 * @param address[in] Target address
ganlikun 0:06036f8bee2d 174 * @param mask[in] Bits to select out of the target address
ganlikun 0:06036f8bee2d 175 */
ganlikun 0:06036f8bee2d 176 #define SECURE_BITS_CLEAR(address, mask) \
ganlikun 0:06036f8bee2d 177 *(address) &= ~(mask)
ganlikun 0:06036f8bee2d 178
ganlikun 0:06036f8bee2d 179 /** Set the selected bits at the target address to the given value.
ganlikun 0:06036f8bee2d 180 *
ganlikun 0:06036f8bee2d 181 * Equivalent to: `*address = (*address & ~mask) | (value & mask)`.
ganlikun 0:06036f8bee2d 182 * @param address[in] Target address
ganlikun 0:06036f8bee2d 183 * @param mask[in] Bits to select out of the target address
ganlikun 0:06036f8bee2d 184 * @param value[in] Value to write at the address location. Note: The value
ganlikun 0:06036f8bee2d 185 * must be already shifted to the correct bit position
ganlikun 0:06036f8bee2d 186 */
ganlikun 0:06036f8bee2d 187 #define SECURE_BITS_SET_VALUE(address, mask, value) \
ganlikun 0:06036f8bee2d 188 *(address) = (*(address) & ~(mask)) | ((value) & (mask))
ganlikun 0:06036f8bee2d 189
ganlikun 0:06036f8bee2d 190 /** Toggle the selected bits at the target address.
ganlikun 0:06036f8bee2d 191 *
ganlikun 0:06036f8bee2d 192 * Equivalent to: `*address ^= mask`.
ganlikun 0:06036f8bee2d 193 * @param address[in] Target address
ganlikun 0:06036f8bee2d 194 * @param mask[in] Bits to select out of the target address
ganlikun 0:06036f8bee2d 195 */
ganlikun 0:06036f8bee2d 196 #define SECURE_BITS_TOGGLE(address, mask) \
ganlikun 0:06036f8bee2d 197 *(address) ^= (mask)
ganlikun 0:06036f8bee2d 198
ganlikun 0:06036f8bee2d 199 #endif
ganlikun 0:06036f8bee2d 200
ganlikun 0:06036f8bee2d 201 #endif /* __CORE_CM_SECURE_ACCESS_H */
ganlikun 0:06036f8bee2d 202