Zelalem Aweke | 8e2e24b | 2021-07-13 14:05:20 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef GPT_H |
| 8 | #define GPT_H |
| 9 | |
| 10 | #include <stdint.h> |
| 11 | |
| 12 | #include <arch.h> |
| 13 | |
| 14 | #include "gpt_defs.h" |
| 15 | |
| 16 | #define GPT_DESC_ATTRS(_type, _gpi) \ |
| 17 | ((((_type) & PAS_REG_DESC_TYPE_MASK) \ |
| 18 | << PAS_REG_DESC_TYPE_SHIFT) | \ |
| 19 | (((_gpi) & PAS_REG_GPI_MASK) \ |
| 20 | << PAS_REG_GPI_SHIFT)) |
| 21 | |
| 22 | /* |
| 23 | * Macro to create a GPT entry for this PAS range either as a L0 block |
| 24 | * descriptor or L1 table descriptor depending upon the size of the range. |
| 25 | */ |
| 26 | #define MAP_GPT_REGION(_pa, _sz, _gpi) \ |
| 27 | { \ |
| 28 | .base_pa = (_pa), \ |
| 29 | .size = (_sz), \ |
| 30 | .attrs = GPT_DESC_ATTRS(PAS_REG_DESC_TYPE_ANY, (_gpi)), \ |
| 31 | } |
| 32 | |
| 33 | /* |
| 34 | * Special macro to create a L1 table descriptor at L0 for a 1GB region as |
| 35 | * opposed to creating a block mapping by default. |
| 36 | */ |
| 37 | #define MAP_GPT_REGION_TBL(_pa, _sz, _gpi) \ |
| 38 | { \ |
| 39 | .base_pa = (_pa), \ |
| 40 | .size = (_sz), \ |
| 41 | .attrs = GPT_DESC_ATTRS(PAS_REG_DESC_TYPE_TBL, (_gpi)), \ |
| 42 | } |
| 43 | |
| 44 | /* |
| 45 | * Structure for specifying a Granule range and its properties |
| 46 | */ |
| 47 | typedef struct pas_region { |
| 48 | unsigned long long base_pa; /**< Base address for PAS. */ |
| 49 | size_t size; /**< Size of the PAS. */ |
| 50 | unsigned int attrs; /**< PAS GPI and entry type. */ |
| 51 | } pas_region_t; |
| 52 | |
| 53 | /* |
| 54 | * Structure to initialise the Granule Protection Tables. |
| 55 | */ |
| 56 | typedef struct gpt_init_params { |
| 57 | unsigned int pgs; /**< Address Width of Phisical Granule Size. */ |
| 58 | unsigned int pps; /**< Protected Physical Address Size. */ |
| 59 | unsigned int l0gptsz; /**< Granule size on L0 table entry. */ |
| 60 | pas_region_t *pas_regions; /**< PAS regions to protect. */ |
| 61 | unsigned int pas_count; /**< Number of PAS regions to initialise. */ |
| 62 | uintptr_t l0_mem_base; /**< L0 Table base address. */ |
| 63 | size_t l0_mem_size; /**< Size of memory reserved for L0 tables. */ |
| 64 | uintptr_t l1_mem_base; /**< L1 Table base address. */ |
| 65 | size_t l1_mem_size; /**< Size of memory reserved for L1 tables. */ |
| 66 | } gpt_init_params_t; |
| 67 | |
| 68 | /** @brief Initialise the Granule Protection tables. |
| 69 | */ |
| 70 | int gpt_init(gpt_init_params_t *params); |
| 71 | |
| 72 | /** @brief Enable the Granule Protection Checks. |
| 73 | */ |
| 74 | void gpt_enable(void); |
| 75 | |
| 76 | /** @brief Disable the Granule Protection Checks. |
| 77 | */ |
| 78 | void gpt_disable(void); |
| 79 | |
| 80 | /** @brief Transition a granule between security states. |
| 81 | */ |
| 82 | int gpt_transition_pas(uint64_t pa, |
| 83 | unsigned int src_sec_state, |
| 84 | unsigned int target_pas); |
| 85 | |
| 86 | #endif /* GPT_H */ |