[6a6ebde] | 1 | /*
|
---|
| 2 | * Copyright (c) 2013 Jan Vesely
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup arm32
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | * @brief Security Extensions Routines
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #ifndef KERN_arm32_SECURITY_EXT_H_
|
---|
| 37 | #define KERN_arm32_SECURITY_EXT_H_
|
---|
| 38 |
|
---|
| 39 | #include <arch/cp15.h>
|
---|
| 40 | #include <arch/regutils.h>
|
---|
| 41 |
|
---|
[a640bc1] | 42 | /** Test whether the current cpu supports security extensions.
|
---|
| 43 | * return true if security extensions are supported, false otherwise.
|
---|
| 44 | * @note The Processor Feature Register 1 that provides this information
|
---|
| 45 | * is available only on armv7+. This function returns false on all\
|
---|
| 46 | * older archs.
|
---|
| 47 | */
|
---|
[6a6ebde] | 48 | static inline bool sec_ext_is_implemented()
|
---|
| 49 | {
|
---|
| 50 | #ifdef PROCESSOR_armv7_a
|
---|
| 51 | const uint32_t idpfr = ID_PFR1_read() & ID_PFR1_SEC_EXT_MASK;
|
---|
| 52 | return idpfr == ID_PFR1_SEC_EXT || idpfr == ID_PFR1_SEC_EXT_RFR;
|
---|
| 53 | #endif
|
---|
| 54 | return false;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
[a640bc1] | 57 | /** Test whether we are running in monitor mode.
|
---|
| 58 | * return true, if the current mode is Monitor mode, false otherwise.
|
---|
| 59 | * @note this is safe to call even on machines that do not implement monitor
|
---|
| 60 | * mode.
|
---|
| 61 | */
|
---|
[7e87436] | 62 | static inline bool sec_ext_is_monitor_mode()
|
---|
| 63 | {
|
---|
| 64 | return (current_status_reg_read() & MODE_MASK) == MONITOR_MODE;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
[a640bc1] | 67 | /** Test whether we are running in a secure state.
|
---|
| 68 | * return true if the current state is secure, false otherwise.
|
---|
| 69 | *
|
---|
| 70 | * @note: This functions will cause undef isntruction trap if we
|
---|
| 71 | * are not running in the secure state.
|
---|
| 72 | *
|
---|
| 73 | * @note: u-boot enables non-secure access to cp 10/11, as well as some other
|
---|
| 74 | * features and switches to non-secure state during boot.
|
---|
| 75 | * Look for 'secureworld_exit' in arch/arm/cpu/armv7/omap3/board.c.
|
---|
| 76 | */
|
---|
[6a6ebde] | 77 | static inline bool sec_ext_is_secure()
|
---|
| 78 | {
|
---|
| 79 | return sec_ext_is_implemented()
|
---|
[7e87436] | 80 | && (sec_ext_is_monitor_mode() || !(SCR_read() & SCR_NS_FLAG));
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[6a6ebde] | 83 | #endif
|
---|
| 84 | /** @}
|
---|
| 85 | */
|
---|