]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.c
ArmPkg: Replace BSD License with BSD+Patent License
[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 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9 #include <Base.h>
10 #include <Library/ArmLib.h>
11 #include <Library/DebugLib.h>
12 #include <Library/PcdLib.h>
13
14 STATIC
15 VOID
16 CacheRangeOperation (
17 IN VOID *Start,
18 IN UINTN Length,
19 IN LINE_OPERATION LineOperation,
20 IN UINTN LineLength
21 )
22 {
23 UINTN ArmCacheLineAlignmentMask = LineLength - 1;
24
25 // Align address (rounding down)
26 UINTN AlignedAddress = (UINTN)Start - ((UINTN)Start & ArmCacheLineAlignmentMask);
27 UINTN EndAddress = (UINTN)Start + Length;
28
29 // Perform the line operation on an address in each cache line
30 while (AlignedAddress < EndAddress) {
31 LineOperation(AlignedAddress);
32 AlignedAddress += LineLength;
33 }
34 ArmDataSynchronizationBarrier ();
35 }
36
37 VOID
38 EFIAPI
39 InvalidateInstructionCache (
40 VOID
41 )
42 {
43 ASSERT (FALSE);
44 }
45
46 VOID
47 EFIAPI
48 InvalidateDataCache (
49 VOID
50 )
51 {
52 ASSERT (FALSE);
53 }
54
55 VOID *
56 EFIAPI
57 InvalidateInstructionCacheRange (
58 IN VOID *Address,
59 IN UINTN Length
60 )
61 {
62 CacheRangeOperation (Address, Length, ArmCleanDataCacheEntryToPoUByMVA,
63 ArmDataCacheLineLength ());
64 CacheRangeOperation (Address, Length,
65 ArmInvalidateInstructionCacheEntryToPoUByMVA,
66 ArmInstructionCacheLineLength ());
67
68 ArmInstructionSynchronizationBarrier ();
69
70 return Address;
71 }
72
73 VOID
74 EFIAPI
75 WriteBackInvalidateDataCache (
76 VOID
77 )
78 {
79 ASSERT (FALSE);
80 }
81
82 VOID *
83 EFIAPI
84 WriteBackInvalidateDataCacheRange (
85 IN VOID *Address,
86 IN UINTN Length
87 )
88 {
89 CacheRangeOperation(Address, Length, ArmCleanInvalidateDataCacheEntryByMVA,
90 ArmDataCacheLineLength ());
91 return Address;
92 }
93
94 VOID
95 EFIAPI
96 WriteBackDataCache (
97 VOID
98 )
99 {
100 ASSERT (FALSE);
101 }
102
103 VOID *
104 EFIAPI
105 WriteBackDataCacheRange (
106 IN VOID *Address,
107 IN UINTN Length
108 )
109 {
110 CacheRangeOperation(Address, Length, ArmCleanDataCacheEntryByMVA,
111 ArmDataCacheLineLength ());
112 return Address;
113 }
114
115 VOID *
116 EFIAPI
117 InvalidateDataCacheRange (
118 IN VOID *Address,
119 IN UINTN Length
120 )
121 {
122 CacheRangeOperation(Address, Length, ArmInvalidateDataCacheEntryByMVA,
123 ArmDataCacheLineLength ());
124 return Address;
125 }