1 /** @file
2 *
3 * Copyright (c) 2011-2012, ARM Limited. All rights reserved.
4 *
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
9 *
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 *
13 **/
14
15 #include <Library/BaseLib.h>
16 #include <Library/IoLib.h>
17
18 #include <Drivers/ArmTrustzone.h>
19
20 #define TZPC_DECPROT0_STATUS_REG 0x800
21 #define TZPC_DECPROT0_SET_REG 0x804
22 #define TZPC_DECPROT0_CLEAR_REG 0x808
23
24 #define TZASC_CONFIGURATION_REG 0x000
25 #define TZASC_REGIONS_REG 0x100
26 #define TZASC_REGION0_LOW_ADDRESS_REG 0x100
27 #define TZASC_REGION0_HIGH_ADDRESS_REG 0x104
28 #define TZASC_REGION0_ATTRIBUTES 0x108
29
30 /**
31 FIXME: Need documentation
32 **/
33 EFI_STATUS
TZPCSetDecProtBits(IN UINTN TzpcBase,IN UINTN TzpcId,IN UINTN Bits)34 TZPCSetDecProtBits (
35 IN UINTN TzpcBase,
36 IN UINTN TzpcId,
37 IN UINTN Bits
38 )
39 {
40 if (TzpcId > TZPC_DECPROT_MAX) {
41 return EFI_INVALID_PARAMETER;
42 }
43
44 MmioWrite32 ((UINTN)TzpcBase + TZPC_DECPROT0_SET_REG + (TzpcId * 0x0C), Bits);
45
46 return EFI_SUCCESS;
47 }
48
49 /**
50 FIXME: Need documentation
51 **/
52 EFI_STATUS
TZPCClearDecProtBits(IN UINTN TzpcBase,IN UINTN TzpcId,IN UINTN Bits)53 TZPCClearDecProtBits (
54 IN UINTN TzpcBase,
55 IN UINTN TzpcId,
56 IN UINTN Bits
57 )
58 {
59 if (TzpcId> TZPC_DECPROT_MAX) {
60 return EFI_INVALID_PARAMETER;
61 }
62
63 MmioWrite32 ((UINTN)TzpcBase + TZPC_DECPROT0_CLEAR_REG + (TzpcId * 0x0C), Bits);
64
65 return EFI_SUCCESS;
66 }
67
68 /**
69 FIXME: Need documentation
70 **/
71 UINT32
TZASCGetNumRegions(IN UINTN TzascBase)72 TZASCGetNumRegions (
73 IN UINTN TzascBase
74 )
75 {
76 return (MmioRead32 ((UINTN)TzascBase + TZASC_CONFIGURATION_REG) & 0xF);
77 }
78
79 /**
80 FIXME: Need documentation
81 **/
82 EFI_STATUS
TZASCSetRegion(IN INTN TzascBase,IN UINTN RegionId,IN UINTN Enabled,IN UINTN LowAddress,IN UINTN HighAddress,IN UINTN Size,IN UINTN Security)83 TZASCSetRegion (
84 IN INTN TzascBase,
85 IN UINTN RegionId,
86 IN UINTN Enabled,
87 IN UINTN LowAddress,
88 IN UINTN HighAddress,
89 IN UINTN Size,
90 IN UINTN Security
91 )
92 {
93 UINT32* Region;
94
95 if (RegionId > TZASCGetNumRegions(TzascBase)) {
96 return EFI_INVALID_PARAMETER;
97 }
98
99 Region = (UINT32*)((UINTN)TzascBase + TZASC_REGIONS_REG + (RegionId * 0x10));
100
101 MmioWrite32((UINTN)(Region), LowAddress&0xFFFF8000);
102 MmioWrite32((UINTN)(Region+1), HighAddress);
103 MmioWrite32((UINTN)(Region+2), ((Security & 0xF) <<28) | ((Size & 0x3F) << 1) | (Enabled & 0x1));
104
105 return EFI_SUCCESS;
106 }
107