]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.c
Adding support for BeagleBoard.
[mirror_edk2.git] / ArmPkg / Library / ArmCacheMaintenanceLib / ArmCacheMaintenanceLib.c
... / ...
CommitLineData
1/** @file
2
3 Copyright (c) 2008-2009, Apple Inc. All rights reserved.
4
5 All rights reserved. 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#include <Base.h>
15#include <Library/ArmLib.h>
16#include <Library/PcdLib.h>
17
18VOID
19CacheRangeOperation (
20 IN VOID *Start,
21 IN UINTN Length,
22 IN CACHE_OPERATION CacheOperation,
23 IN LINE_OPERATION LineOperation
24 )
25{
26 UINTN ArmCacheLineLength = ArmDataCacheLineLength();
27 UINTN ArmCacheLineAlignmentMask = ArmCacheLineLength - 1;
28 UINTN ArmCacheOperationThreshold = PcdGet32(PcdArmCacheOperationThreshold);
29
30 if ((CacheOperation != NULL) && (Length >= ArmCacheOperationThreshold))
31 {
32 CacheOperation();
33 }
34 else
35 {
36 // Align address (rounding down)
37 UINTN AlignedAddress = (UINTN)Start - ((UINTN)Start & ArmCacheLineAlignmentMask);
38 UINTN EndAddress = (UINTN)Start + Length;
39
40 // Perform the line operation on an address in each cache line
41 while (AlignedAddress < EndAddress)
42 {
43 LineOperation(AlignedAddress);
44 AlignedAddress += ArmCacheLineLength;
45 }
46 }
47}
48
49VOID
50EFIAPI
51InvalidateInstructionCache (
52 VOID
53 )
54{
55 ArmCleanDataCache();
56 ArmInvalidateInstructionCache();
57}
58
59VOID
60EFIAPI
61InvalidateDataCache (
62 VOID
63 )
64{
65 ArmInvalidateDataCache();
66}
67
68VOID *
69EFIAPI
70InvalidateInstructionCacheRange (
71 IN VOID *Address,
72 IN UINTN Length
73 )
74{
75 CacheRangeOperation(Address, Length, ArmCleanDataCache, ArmCleanDataCacheEntryByMVA);
76 ArmInvalidateInstructionCache();
77 return Address;
78}
79
80VOID
81EFIAPI
82WriteBackInvalidateDataCache (
83 VOID
84 )
85{
86 ArmCleanInvalidateDataCache();
87}
88
89VOID *
90EFIAPI
91WriteBackInvalidateDataCacheRange (
92 IN VOID *Address,
93 IN UINTN Length
94 )
95{
96 CacheRangeOperation(Address, Length, ArmCleanInvalidateDataCache, ArmCleanInvalidateDataCacheEntryByMVA);
97 return Address;
98}
99
100VOID
101EFIAPI
102WriteBackDataCache (
103 VOID
104 )
105{
106 ArmCleanDataCache();
107}
108
109VOID *
110EFIAPI
111WriteBackDataCacheRange (
112 IN VOID *Address,
113 IN UINTN Length
114 )
115{
116 CacheRangeOperation(Address, Length, ArmCleanDataCache, ArmCleanDataCacheEntryByMVA);
117 return Address;
118}
119
120VOID *
121EFIAPI
122InvalidateDataCacheRange (
123 IN VOID *Address,
124 IN UINTN Length
125 )
126{
127 CacheRangeOperation(Address, Length, NULL, ArmInvalidateDataCacheEntryByMVA);
128 return Address;
129}