]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.c
d8e53df6096ee93d37239e0ab0214fdd6a88a40f
[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 }
39
40 VOID
41 EFIAPI
42 InvalidateInstructionCache (
43 VOID
44 )
45 {
46 ArmCleanDataCache();
47 ArmInvalidateInstructionCache();
48 }
49
50 VOID
51 EFIAPI
52 InvalidateDataCache (
53 VOID
54 )
55 {
56 ArmInvalidateDataCache();
57 }
58
59 VOID *
60 EFIAPI
61 InvalidateInstructionCacheRange (
62 IN VOID *Address,
63 IN UINTN Length
64 )
65 {
66 CacheRangeOperation (Address, Length, ArmCleanDataCacheEntryByMVA);
67 ArmInvalidateInstructionCache ();
68 return Address;
69 }
70
71 VOID
72 EFIAPI
73 WriteBackInvalidateDataCache (
74 VOID
75 )
76 {
77 ArmCleanInvalidateDataCache();
78 }
79
80 VOID *
81 EFIAPI
82 WriteBackInvalidateDataCacheRange (
83 IN VOID *Address,
84 IN UINTN Length
85 )
86 {
87 CacheRangeOperation(Address, Length, ArmCleanInvalidateDataCacheEntryByMVA);
88 return Address;
89 }
90
91 VOID
92 EFIAPI
93 WriteBackDataCache (
94 VOID
95 )
96 {
97 ArmCleanDataCache();
98 }
99
100 VOID *
101 EFIAPI
102 WriteBackDataCacheRange (
103 IN VOID *Address,
104 IN UINTN Length
105 )
106 {
107 CacheRangeOperation(Address, Length, ArmCleanDataCacheEntryByMVA);
108 return Address;
109 }
110
111 VOID *
112 EFIAPI
113 InvalidateDataCacheRange (
114 IN VOID *Address,
115 IN UINTN Length
116 )
117 {
118 CacheRangeOperation(Address, Length, ArmInvalidateDataCacheEntryByMVA);
119 return Address;
120 }