]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/ArmTrustZoneLib/ArmTrustZone.c
Arm Packages: Fixed coding style/Line endings to follow EDK2 coding convention
[mirror_edk2.git] / ArmPkg / Library / ArmTrustZoneLib / ArmTrustZone.c
1 /** @file
2 *
3 * Copyright (c) 2011, 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 #include <Library/ArmTrustZoneLib.h>
18
19 #define TZPC_DECPROT0_STATUS_REG 0x800
20 #define TZPC_DECPROT0_SET_REG 0x804
21 #define TZPC_DECPROT0_CLEAR_REG 0x808
22
23 #define TZASC_CONFIGURATION_REG 0x000
24 #define TZASC_REGIONS_REG 0x100
25 #define TZASC_REGION0_LOW_ADDRESS_REG 0x100
26 #define TZASC_REGION0_HIGH_ADDRESS_REG 0x104
27 #define TZASC_REGION0_ATTRIBUTES 0x108
28
29 /**
30 FIXME: Need documentation
31 **/
32 EFI_STATUS
33 TZPCSetDecProtBits (
34 IN UINTN TzpcBase,
35 IN UINTN TzpcId,
36 IN UINTN Bits
37 )
38 {
39 if (TzpcId > TZPC_DECPROT_MAX) {
40 return EFI_INVALID_PARAMETER;
41 }
42
43 MmioWrite32 ((UINTN)TzpcBase + TZPC_DECPROT0_SET_REG + (TzpcId * 0x0C), Bits);
44
45 return EFI_SUCCESS;
46 }
47
48 /**
49 FIXME: Need documentation
50 **/
51 EFI_STATUS
52 TZPCClearDecProtBits (
53 IN UINTN TzpcBase,
54 IN UINTN TzpcId,
55 IN UINTN Bits
56 )
57 {
58 if (TzpcId> TZPC_DECPROT_MAX) {
59 return EFI_INVALID_PARAMETER;
60 }
61
62 MmioWrite32 ((UINTN)TzpcBase + TZPC_DECPROT0_CLEAR_REG + (TzpcId * 0x0C), Bits);
63
64 return EFI_SUCCESS;
65 }
66
67 /**
68 FIXME: Need documentation
69 **/
70 UINT32
71 TZASCGetNumRegions (
72 IN UINTN TzascBase
73 )
74 {
75 return (MmioRead32 ((UINTN)TzascBase + TZASC_CONFIGURATION_REG) & 0xF);
76 }
77
78 /**
79 FIXME: Need documentation
80 **/
81 EFI_STATUS
82 TZASCSetRegion (
83 IN INTN TzascBase,
84 IN UINTN RegionId,
85 IN UINTN Enabled,
86 IN UINTN LowAddress,
87 IN UINTN HighAddress,
88 IN UINTN Size,
89 IN UINTN Security
90 )
91 {
92 UINT32* Region;
93
94 if (RegionId > TZASCGetNumRegions(TzascBase)) {
95 return EFI_INVALID_PARAMETER;
96 }
97
98 Region = (UINT32*)((UINTN)TzascBase + TZASC_REGIONS_REG + (RegionId * 0x10));
99
100 MmioWrite32((UINTN)(Region), LowAddress&0xFFFF8000);
101 MmioWrite32((UINTN)(Region+1), HighAddress);
102 MmioWrite32((UINTN)(Region+2), ((Security & 0xF) <<28) | ((Size & 0x3F) << 1) | (Enabled & 0x1));
103
104 return EFI_SUCCESS;
105 }