inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

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