|
| 1 | +/* |
| 2 | + * Copyright (c) 2016, ARM Limited, All Rights Reserved |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | + * not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +#ifndef __VMPU_FREESCALE_K64_H__ |
| 18 | +#define __VMPU_FREESCALE_K64_H__ |
| 19 | + |
| 20 | +/* MPU fault status codes */ |
| 21 | +#define VMPU_FAULT_NONE (-1) |
| 22 | +#define VMPU_FAULT_MULTIPLE (-2) |
| 23 | + |
| 24 | +/** Get the slave port number from the MPU->CESR SPERR field. |
| 25 | + * @returns The slave port number, or a negative value to signal an error |
| 26 | + * @retval \ref VMPU_FAULT_NONE No MPU violation found |
| 27 | + * @retval \ref VMPU_FAULT_MULTIPLE Multiple MPU violations found |
| 28 | + */ |
| 29 | +UVISOR_FORCEINLINE int vmpu_fault_get_slave_port(void) |
| 30 | +{ |
| 31 | + uint32_t mpu_cesr_sperr = (MPU->CESR & MPU_CESR_SPERR_MASK) >> MPU_CESR_SPERR_SHIFT; |
| 32 | + switch (mpu_cesr_sperr) { |
| 33 | + case 0x00: |
| 34 | + return VMPU_FAULT_NONE; |
| 35 | + case 0x01: |
| 36 | + return 4; |
| 37 | + case 0x02: |
| 38 | + return 3; |
| 39 | + case 0x04: |
| 40 | + return 2; |
| 41 | + case 0x08: |
| 42 | + return 1; |
| 43 | + case 0x10: |
| 44 | + return 0; |
| 45 | + default: |
| 46 | + return VMPU_FAULT_MULTIPLE; |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +/** Clear the fault bits in the MPU->CESR SPERR field. |
| 51 | + * @note We only clear the fault required by the input argument. If there are |
| 52 | + * multiple faults only one will be cleared. |
| 53 | + * @param slave_port[in] Slave port number for which the fault must be |
| 54 | + * cleared |
| 55 | + */ |
| 56 | +UVISOR_FORCEINLINE void vmpu_fault_clear_slave_port(int slave_port) |
| 57 | +{ |
| 58 | + /* We only clear the bits if the slave port is valid. */ |
| 59 | + if (slave_port >= 0 && slave_port <= 4) { |
| 60 | + uint32_t slave_port_bits = 1 << ((uint32_t) slave_port); |
| 61 | + MPU->CESR |= (slave_port_bits << MPU_CESR_SPERR_SHIFT) & MPU_CESR_SPERR_SHIFT; |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +#endif /* __VMPU_FREESCALE_K64_H__ */ |
0 commit comments