2011-02-02 23:35:30 +01:00
|
|
|
/** @file
|
|
|
|
*
|
2012-02-28 18:16:58 +01:00
|
|
|
* Copyright (c) 2011-2012, ARM Limited. All rights reserved.
|
2011-02-02 23:35:30 +01:00
|
|
|
*
|
2014-08-19 15:29:52 +02:00
|
|
|
* 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.
|
2011-02-02 23:35:30 +01:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <Library/BaseLib.h>
|
|
|
|
#include <Library/IoLib.h>
|
2012-02-28 18:16:58 +01:00
|
|
|
|
|
|
|
#include <Drivers/ArmTrustzone.h>
|
2011-02-02 23:35:30 +01:00
|
|
|
|
|
|
|
#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
|
|
|
|
**/
|
2011-09-23 00:53:54 +02:00
|
|
|
EFI_STATUS
|
|
|
|
TZPCSetDecProtBits (
|
|
|
|
IN UINTN TzpcBase,
|
|
|
|
IN UINTN TzpcId,
|
|
|
|
IN UINTN Bits
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (TzpcId > TZPC_DECPROT_MAX) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2011-02-02 23:35:30 +01:00
|
|
|
|
2011-09-23 00:53:54 +02:00
|
|
|
MmioWrite32 ((UINTN)TzpcBase + TZPC_DECPROT0_SET_REG + (TzpcId * 0x0C), Bits);
|
2011-02-02 23:35:30 +01:00
|
|
|
|
2011-09-23 00:53:54 +02:00
|
|
|
return EFI_SUCCESS;
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
FIXME: Need documentation
|
|
|
|
**/
|
2011-09-23 00:53:54 +02:00
|
|
|
EFI_STATUS
|
|
|
|
TZPCClearDecProtBits (
|
|
|
|
IN UINTN TzpcBase,
|
|
|
|
IN UINTN TzpcId,
|
|
|
|
IN UINTN Bits
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (TzpcId> TZPC_DECPROT_MAX) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2011-02-02 23:35:30 +01:00
|
|
|
|
2011-09-23 00:53:54 +02:00
|
|
|
MmioWrite32 ((UINTN)TzpcBase + TZPC_DECPROT0_CLEAR_REG + (TzpcId * 0x0C), Bits);
|
2011-02-02 23:35:30 +01:00
|
|
|
|
2011-09-23 00:53:54 +02:00
|
|
|
return EFI_SUCCESS;
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
FIXME: Need documentation
|
|
|
|
**/
|
2011-09-23 00:53:54 +02:00
|
|
|
UINT32
|
|
|
|
TZASCGetNumRegions (
|
|
|
|
IN UINTN TzascBase
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return (MmioRead32 ((UINTN)TzascBase + TZASC_CONFIGURATION_REG) & 0xF);
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
FIXME: Need documentation
|
|
|
|
**/
|
2011-09-23 00:53:54 +02:00
|
|
|
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;
|
2011-02-02 23:35:30 +01:00
|
|
|
|
2011-09-23 00:53:54 +02:00
|
|
|
if (RegionId > TZASCGetNumRegions(TzascBase)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2011-02-02 23:35:30 +01:00
|
|
|
|
2011-09-23 00:53:54 +02:00
|
|
|
Region = (UINT32*)((UINTN)TzascBase + TZASC_REGIONS_REG + (RegionId * 0x10));
|
2011-02-02 23:35:30 +01:00
|
|
|
|
2011-09-23 00:53:54 +02:00
|
|
|
MmioWrite32((UINTN)(Region), LowAddress&0xFFFF8000);
|
2011-02-03 00:19:30 +01:00
|
|
|
MmioWrite32((UINTN)(Region+1), HighAddress);
|
|
|
|
MmioWrite32((UINTN)(Region+2), ((Security & 0xF) <<28) | ((Size & 0x3F) << 1) | (Enabled & 0x1));
|
2011-02-02 23:35:30 +01:00
|
|
|
|
2011-09-23 00:53:54 +02:00
|
|
|
return EFI_SUCCESS;
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|