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