]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.c
ArmPkg/ArmLib: move cache maintenance sync barriers out of loop
[mirror_edk2.git] / ArmPkg / Library / ArmCacheMaintenanceLib / ArmCacheMaintenanceLib.c
1 /** @file
2
3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4 Copyright (c) 2011 - 2014, ARM Limited. All rights reserved.
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15 #include <Base.h>
16 #include <Library/ArmLib.h>
17 #include <Library/PcdLib.h>
18
19 VOID
20 CacheRangeOperation (
21 IN VOID *Start,
22 IN UINTN Length,
23 IN LINE_OPERATION LineOperation
24 )
25 {
26 UINTN ArmCacheLineLength = ArmDataCacheLineLength();
27 UINTN ArmCacheLineAlignmentMask = ArmCacheLineLength - 1;
28
29 // Align address (rounding down)
30 UINTN AlignedAddress = (UINTN)Start - ((UINTN)Start & ArmCacheLineAlignmentMask);
31 UINTN EndAddress = (UINTN)Start + Length;
32
33 // Perform the line operation on an address in each cache line
34 while (AlignedAddress < EndAddress) {
35 LineOperation(AlignedAddress);
36 AlignedAddress += ArmCacheLineLength;
37 }
38 ArmDataSynchronizationBarrier ();
39 }
40
41 VOID
42 EFIAPI
43 InvalidateInstructionCache (
44 VOID
45 )
46 {
47 ArmCleanDataCache();
48 ArmInvalidateInstructionCache();
49 }
50
51 VOID
52 EFIAPI
53 InvalidateDataCache (
54 VOID
55 )
56 {
57 ArmInvalidateDataCache();
58 }
59
60 VOID *
61 EFIAPI
62 InvalidateInstructionCacheRange (
63 IN VOID *Address,
64 IN UINTN Length
65 )
66 {
67 CacheRangeOperation (Address, Length, ArmCleanDataCacheEntryByMVA);
68 ArmInvalidateInstructionCache ();
69 return Address;
70 }
71
72 VOID
73 EFIAPI
74 WriteBackInvalidateDataCache (
75 VOID
76 )
77 {
78 ArmCleanInvalidateDataCache();
79 }
80
81 VOID *
82 EFIAPI
83 WriteBackInvalidateDataCacheRange (
84 IN VOID *Address,
85 IN UINTN Length
86 )
87 {
88 CacheRangeOperation(Address, Length, ArmCleanInvalidateDataCacheEntryByMVA);
89 return Address;
90 }
91
92 VOID
93 EFIAPI
94 WriteBackDataCache (
95 VOID
96 )
97 {
98 ArmCleanDataCache();
99 }
100
101 VOID *
102 EFIAPI
103 WriteBackDataCacheRange (
104 IN VOID *Address,
105 IN UINTN Length
106 )
107 {
108 CacheRangeOperation(Address, Length, ArmCleanDataCacheEntryByMVA);
109 return Address;
110 }
111
112 VOID *
113 EFIAPI
114 InvalidateDataCacheRange (
115 IN VOID *Address,
116 IN UINTN Length
117 )
118 {
119 CacheRangeOperation(Address, Length, ArmInvalidateDataCacheEntryByMVA);
120 return Address;
121 }