blob: ef7134cbff4e3e5791f801ea32c36ceb5a1c3a27 [file] [log] [blame]
developer880fb172022-09-05 19:08:59 +08001/*
Chungying Lu59c1c2b2023-04-25 15:39:10 +08002 * Copyright (c) 2022-2023, ARM Limited and Contributors. All rights reserved.
developer880fb172022-09-05 19:08:59 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef EMI_MPU_H
8#define EMI_MPU_H
9
10#include <emi_mpu_priv.h>
11#include <platform_def.h>
12
13#define NO_PROTECTION (0)
14#define SEC_RW (1)
15#define SEC_RW_NSEC_R (2)
16#define SEC_RW_NSEC_W (3)
17#define SEC_R_NSEC_R (4)
18#define FORBIDDEN (5)
19#define SEC_R_NSEC_RW (6)
20
21#define LOCK (1)
22#define UNLOCK (0)
23
24#if (EMI_MPU_DGROUP_NUM == 1)
25#define SET_ACCESS_PERMISSION(apc_ary, lock, d7, d6, d5, d4, d3, d2, d1, d0) \
26do { \
27 apc_ary[1] = 0; \
28 apc_ary[0] = \
29 (((unsigned int) d7) << 21) | (((unsigned int) d6) << 18) | \
30 (((unsigned int) d5) << 15) | (((unsigned int) d4) << 12) | \
31 (((unsigned int) d3) << 9) | (((unsigned int) d2) << 6) | \
32 (((unsigned int) d1) << 3) | ((unsigned int) d0) | \
33 ((unsigned int) lock << 31); \
34} while (0)
35#elif (EMI_MPU_DGROUP_NUM == 2)
36#define SET_ACCESS_PERMISSION(apc_ary, lock, d15, d14, d13, d12, d11, d10, \
37 d9, d8, d7, d6, d5, d4, d3, d2, d1, d0) \
38do { \
39 apc_ary[1] = \
40 (((unsigned int) d15) << 21) | (((unsigned int) d14) << 18) | \
41 (((unsigned int) d13) << 15) | (((unsigned int) d12) << 12) | \
42 (((unsigned int) d11) << 9) | (((unsigned int) d10) << 6) | \
43 (((unsigned int) d9) << 3) | ((unsigned int) d8); \
44 apc_ary[0] = \
45 (((unsigned int) d7) << 21) | (((unsigned int) d6) << 18) | \
46 (((unsigned int) d5) << 15) | (((unsigned int) d4) << 12) | \
47 (((unsigned int) d3) << 9) | (((unsigned int) d2) << 6) | \
48 (((unsigned int) d1) << 3) | ((unsigned int) d0) | \
49 ((unsigned int) lock << 31); \
50} while (0)
51#endif
52
53struct emi_region_info_t {
54 unsigned long long start;
55 unsigned long long end;
56 unsigned int region;
57 unsigned int apc[EMI_MPU_DGROUP_NUM];
58};
59
Dawei Chien67611c82023-08-01 18:52:52 +080060enum MPU_REQ_ORIGIN_ZONE_ID {
61 MPU_REQ_ORIGIN_TEE_ZONE_SVP = 0,
62 MPU_REQ_ORIGIN_TEE_ZONE_TUI = 1,
63 MPU_REQ_ORIGIN_TEE_ZONE_WFD = 2,
64 MPU_REQ_ORIGIN_TEE_ZONE_MAX = 3,
65 MPU_REQ_ORIGIN_ZONE_INVALID = 0x7FFFFFFF,
66};
67
developer880fb172022-09-05 19:08:59 +080068int emi_mpu_init(void);
Dawei Chien67611c82023-08-01 18:52:52 +080069int emi_mpu_optee_handler(uint64_t encoded_addr, uint64_t zone_size,
70 uint64_t zone_info);
developer880fb172022-09-05 19:08:59 +080071int emi_mpu_set_protection(struct emi_region_info_t *region_info);
72void set_emi_mpu_regions(void);
Chungying Lu59c1c2b2023-04-25 15:39:10 +080073int set_apu_emi_mpu_region(void);
developer880fb172022-09-05 19:08:59 +080074#endif