summaryrefslogtreecommitdiff
path: root/ArmPkg/Library/ArmTrustZoneLib/ArmTrustZone.c
blob: 8319441f29e3f437e5cc9fd990aeb95e9a2a62ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/** @file
*
*  Copyright (c) 2011, ARM Limited. All rights reserved.
*  
*  This program and the accompanying materials                          
*  are licensed and made available under the terms and conditions of the BSD License         
*  which accompanies this distribution.  The full text of the license may be found at        
*  http://opensource.org/licenses/bsd-license.php                                            
*
*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             
*
**/

#include <Library/BaseLib.h>
#include <Library/IoLib.h>
#include <Library/ArmTrustZoneLib.h>

#define TZPC_DECPROT0_STATUS_REG        0x800
#define TZPC_DECPROT0_SET_REG           0x804
#define TZPC_DECPROT0_CLEAR_REG         0x808

#define TZASC_CONFIGURATION_REG         0x000
#define TZASC_REGIONS_REG               0x100
#define TZASC_REGION0_LOW_ADDRESS_REG   0x100
#define TZASC_REGION0_HIGH_ADDRESS_REG  0x104
#define TZASC_REGION0_ATTRIBUTES        0x108

/**
    FIXME: Need documentation
**/
EFI_STATUS
TZPCSetDecProtBits (
  IN  UINTN TzpcBase,
  IN  UINTN TzpcId,
  IN  UINTN Bits
  )
{
  if (TzpcId > TZPC_DECPROT_MAX) {
    return EFI_INVALID_PARAMETER;
  }

  MmioWrite32 ((UINTN)TzpcBase + TZPC_DECPROT0_SET_REG + (TzpcId * 0x0C), Bits);

  return EFI_SUCCESS;
}

/**
    FIXME: Need documentation
**/
EFI_STATUS
TZPCClearDecProtBits (
  IN  UINTN TzpcBase,
  IN  UINTN TzpcId,
  IN  UINTN Bits
  )
{
  if (TzpcId> TZPC_DECPROT_MAX) {
    return EFI_INVALID_PARAMETER;
  }

  MmioWrite32 ((UINTN)TzpcBase + TZPC_DECPROT0_CLEAR_REG + (TzpcId * 0x0C), Bits);

  return EFI_SUCCESS;
}

/**
    FIXME: Need documentation
**/
UINT32
TZASCGetNumRegions (
  IN UINTN TzascBase
  )
{
  return (MmioRead32 ((UINTN)TzascBase + TZASC_CONFIGURATION_REG) & 0xF);
}

/**
    FIXME: Need documentation
**/
EFI_STATUS
TZASCSetRegion (
  IN  INTN  TzascBase,
  IN  UINTN RegionId,
  IN  UINTN Enabled,
  IN  UINTN LowAddress,
  IN  UINTN HighAddress,
  IN  UINTN Size,
  IN  UINTN Security
  )
{
  UINT32*     Region;

  if (RegionId > TZASCGetNumRegions(TzascBase)) {
    return EFI_INVALID_PARAMETER;
  }

  Region = (UINT32*)((UINTN)TzascBase + TZASC_REGIONS_REG + (RegionId * 0x10));

  MmioWrite32((UINTN)(Region), LowAddress&0xFFFF8000);
  MmioWrite32((UINTN)(Region+1), HighAddress);
  MmioWrite32((UINTN)(Region+2), ((Security & 0xF) <<28) | ((Size & 0x3F) << 1) | (Enabled & 0x1));

  return EFI_SUCCESS;
}