ee6da855ccebdd8b5dc295447420b0607757b431vboxsync/** @file
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync Cache Maintenance Functions.
9ca017ceee656f9d33f2cb6652e401b5f17fcfb7vboxsync
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync This program and the accompanying materials
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync are licensed and made available under the terms and conditions of the BSD License
d4c0b01d95e56701ccb5a430fea1a36dc671153bvboxsync which accompanies this distribution. The full text of the license may be found at
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync http://opensource.org/licenses/bsd-license.php.
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync**/
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync#include <Base.h>
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync#include <Library/CacheMaintenanceLib.h>
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync#include <Library/BaseLib.h>
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync#include <Library/DebugLib.h>
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync#include <Library/PalLib.h>
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync
88c355789359ed9e72ed456a617ccd59d7b0f69avboxsync/**
88c355789359ed9e72ed456a617ccd59d7b0f69avboxsync Invalidates the entire instruction cache in cache coherency domain of the
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync calling CPU.
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync**/
ee6da855ccebdd8b5dc295447420b0607757b431vboxsyncVOID
ee6da855ccebdd8b5dc295447420b0607757b431vboxsyncEFIAPI
1aaa4b75cfc9f222c4308fcb10f44d3aeb3b017dvboxsyncInvalidateInstructionCache (
1aaa4b75cfc9f222c4308fcb10f44d3aeb3b017dvboxsync VOID
1aaa4b75cfc9f222c4308fcb10f44d3aeb3b017dvboxsync )
1aaa4b75cfc9f222c4308fcb10f44d3aeb3b017dvboxsync{
30ddfc88ff06def267c2ffd1b750cc5fe6c310f2vboxsync PalCall (PAL_CACHE_FLUSH, PAL_CACHE_FLUSH_INSTRUCTION_ALL, PAL_CACHE_FLUSH_INVALIDATE_LINES | PAL_CACHE_FLUSH_NO_INTERRUPT, 0);
c4838583fda41f70290ca79ce09e743db0d33488vboxsync}
c606fa3531314e32f0ae90495618aeae47418477vboxsync
dbabc9de5bf52ce5eb77cf82b038e9a6166c5a04vboxsync/**
fccc59981ee96f9e392fbfa0ab3a378d9732ea4evboxsync Invalidates a range of instruction cache lines in the cache coherency domain
a728d62d1cdd12794b98aa645532cdb35b995b6evboxsync of the calling CPU.
1f17f33cc8338f56a4ca17ac85bca4e373663bf5vboxsync
1f17f33cc8338f56a4ca17ac85bca4e373663bf5vboxsync Invalidates the instruction cache lines specified by Address and Length. If
04982697b03f25ee4738b26d1c6a2b26bf06c9e7vboxsync Address is not aligned on a cache line boundary, then entire instruction
04982697b03f25ee4738b26d1c6a2b26bf06c9e7vboxsync cache line containing Address is invalidated. If Address + Length is not
321713c8724d53a5563eda3a70ab0f3830fd9e16vboxsync aligned on a cache line boundary, then the entire instruction cache line
1aaa4b75cfc9f222c4308fcb10f44d3aeb3b017dvboxsync containing Address + Length -1 is invalidated. This function may choose to
9ca017ceee656f9d33f2cb6652e401b5f17fcfb7vboxsync invalidate the entire instruction cache if that is more efficient than
9ca017ceee656f9d33f2cb6652e401b5f17fcfb7vboxsync invalidating the specified range. If Length is 0, then no instruction cache
9ca017ceee656f9d33f2cb6652e401b5f17fcfb7vboxsync lines are invalidated. Address is returned.
9ca017ceee656f9d33f2cb6652e401b5f17fcfb7vboxsync
9ca017ceee656f9d33f2cb6652e401b5f17fcfb7vboxsync If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
9ca017ceee656f9d33f2cb6652e401b5f17fcfb7vboxsync
9ca017ceee656f9d33f2cb6652e401b5f17fcfb7vboxsync @param Address The base address of the instruction cache lines to
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync invalidate. If the CPU is in a physical addressing mode, then
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync Address is a physical address. If the CPU is in a virtual
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync addressing mode, then Address is a virtual address.
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync @param Length The number of bytes to invalidate from the instruction cache.
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync @return Address.
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync**/
0a700967721f334172e15548fbe8e8727426db56vboxsyncVOID *
ee6da855ccebdd8b5dc295447420b0607757b431vboxsyncEFIAPI
c4838583fda41f70290ca79ce09e743db0d33488vboxsyncInvalidateInstructionCacheRange (
c4838583fda41f70290ca79ce09e743db0d33488vboxsync IN VOID *Address,
d4c0b01d95e56701ccb5a430fea1a36dc671153bvboxsync IN UINTN Length
c4838583fda41f70290ca79ce09e743db0d33488vboxsync )
c4838583fda41f70290ca79ce09e743db0d33488vboxsync{
c4838583fda41f70290ca79ce09e743db0d33488vboxsync return AsmFlushCacheRange (Address, Length);
c4838583fda41f70290ca79ce09e743db0d33488vboxsync}
c4838583fda41f70290ca79ce09e743db0d33488vboxsync
3e729152bacbdd8ae206df8fafe3187bb9fb7614vboxsync/**
c4838583fda41f70290ca79ce09e743db0d33488vboxsync Writes back and invalidates the entire data cache in cache coherency domain
c4838583fda41f70290ca79ce09e743db0d33488vboxsync of the calling CPU.
ff525c9827feb8097b272c36e3f0ab91e745f0ffvboxsync
ff525c9827feb8097b272c36e3f0ab91e745f0ffvboxsync Writes back and invalidates the entire data cache in cache coherency domain
ff525c9827feb8097b272c36e3f0ab91e745f0ffvboxsync of the calling CPU. This function guarantees that all dirty cache lines are
ff525c9827feb8097b272c36e3f0ab91e745f0ffvboxsync written back to system memory, and also invalidates all the data cache lines
d70f332ce412cf75187ceda26709e58e4edc69ecvboxsync in the cache coherency domain of the calling CPU.
45b0f96c0edfcb5dbbc783d68ff28a505e84087bvboxsync
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync**/
ee6da855ccebdd8b5dc295447420b0607757b431vboxsyncVOID
d4c0b01d95e56701ccb5a430fea1a36dc671153bvboxsyncEFIAPI
d4c0b01d95e56701ccb5a430fea1a36dc671153bvboxsyncWriteBackInvalidateDataCache (
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync VOID
d4c0b01d95e56701ccb5a430fea1a36dc671153bvboxsync )
d4c0b01d95e56701ccb5a430fea1a36dc671153bvboxsync{
d4c0b01d95e56701ccb5a430fea1a36dc671153bvboxsync PalCall (PAL_CACHE_FLUSH, PAL_CACHE_FLUSH_DATA_ALL, PAL_CACHE_FLUSH_INVALIDATE_LINES | PAL_CACHE_FLUSH_NO_INTERRUPT, 0);
8f574d4912727ef7f831a29e3f836a04b0261392vboxsync}
d4c0b01d95e56701ccb5a430fea1a36dc671153bvboxsync
d4c0b01d95e56701ccb5a430fea1a36dc671153bvboxsync/**
d4c0b01d95e56701ccb5a430fea1a36dc671153bvboxsync Writes back and invalidates a range of data cache lines in the cache
d4c0b01d95e56701ccb5a430fea1a36dc671153bvboxsync coherency domain of the calling CPU.
d4c0b01d95e56701ccb5a430fea1a36dc671153bvboxsync
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync Writes back and invalidates the data cache lines specified by Address and
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync Length. If Address is not aligned on a cache line boundary, then entire data
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync cache line containing Address is written back and invalidated. If Address +
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync Length is not aligned on a cache line boundary, then the entire data cache
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync line containing Address + Length -1 is written back and invalidated. This
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync function may choose to write back and invalidate the entire data cache if
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync that is more efficient than writing back and invalidating the specified
8f574d4912727ef7f831a29e3f836a04b0261392vboxsync range. If Length is 0, then no data cache lines are written back and
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync invalidated. Address is returned.
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync @param Address The base address of the data cache lines to write back and
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync invalidate. If the CPU is in a physical addressing mode, then
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync Address is a physical address. If the CPU is in a virtual
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync addressing mode, then Address is a virtual address.
97b672c60368db8e7ba24563e516fc308e73b192vboxsync @param Length The number of bytes to write back and invalidate from the
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync data cache.
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync @return Address of cache invalidation.
8f574d4912727ef7f831a29e3f836a04b0261392vboxsync
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync**/
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsyncVOID *
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsyncEFIAPI
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsyncWriteBackInvalidateDataCacheRange (
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync IN VOID *Address,
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync IN UINTN Length
4ffa88e3c640c58346df49580a7d02f5b389f75fvboxsync )
4ffa88e3c640c58346df49580a7d02f5b389f75fvboxsync{
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync return AsmFlushCacheRange (Address, Length);
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync}
8f574d4912727ef7f831a29e3f836a04b0261392vboxsync
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync/**
8f574d4912727ef7f831a29e3f836a04b0261392vboxsync Writes Back the entire data cache in cache coherency domain of the calling
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync CPU.
f9bbb477594efad6aaf8accca9a83a2071158f98vboxsync
8f574d4912727ef7f831a29e3f836a04b0261392vboxsync Writes Back the entire data cache in cache coherency domain of the calling
8f574d4912727ef7f831a29e3f836a04b0261392vboxsync CPU. This function guarantees that all dirty cache lines are written back to
8f574d4912727ef7f831a29e3f836a04b0261392vboxsync system memory. This function may also invalidate all the data cache lines in
8f574d4912727ef7f831a29e3f836a04b0261392vboxsync the cache coherency domain of the calling CPU.
8f574d4912727ef7f831a29e3f836a04b0261392vboxsync
8f574d4912727ef7f831a29e3f836a04b0261392vboxsync**/
8f574d4912727ef7f831a29e3f836a04b0261392vboxsyncVOID
df6a45e2f3db089eb8e0491a9a8abb4548327c85vboxsyncEFIAPI
df6a45e2f3db089eb8e0491a9a8abb4548327c85vboxsyncWriteBackDataCache (
df6a45e2f3db089eb8e0491a9a8abb4548327c85vboxsync VOID
df6a45e2f3db089eb8e0491a9a8abb4548327c85vboxsync )
df6a45e2f3db089eb8e0491a9a8abb4548327c85vboxsync{
df6a45e2f3db089eb8e0491a9a8abb4548327c85vboxsync PalCall (PAL_CACHE_FLUSH, PAL_CACHE_FLUSH_DATA_ALL, PAL_CACHE_FLUSH_NO_INVALIDATE_LINES | PAL_CACHE_FLUSH_NO_INTERRUPT, 0);
df6a45e2f3db089eb8e0491a9a8abb4548327c85vboxsync}
b44490b772aa83335ce0c006021542c1bba16820vboxsync
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsync/**
2c55518088b033c1bddc9e854b9537518b2abbc6vboxsync Writes Back a range of data cache lines in the cache coherency domain of the
2c55518088b033c1bddc9e854b9537518b2abbc6vboxsync calling CPU.
2c55518088b033c1bddc9e854b9537518b2abbc6vboxsync
2c55518088b033c1bddc9e854b9537518b2abbc6vboxsync Writes Back the data cache lines specified by Address and Length. If Address
2c55518088b033c1bddc9e854b9537518b2abbc6vboxsync is not aligned on a cache line boundary, then entire data cache line
2c55518088b033c1bddc9e854b9537518b2abbc6vboxsync containing Address is written back. If Address + Length is not aligned on a
2c55518088b033c1bddc9e854b9537518b2abbc6vboxsync cache line boundary, then the entire data cache line containing Address +
2c55518088b033c1bddc9e854b9537518b2abbc6vboxsync Length -1 is written back. This function may choose to write back the entire
0158d474771d8cf8fb0bfbbe297d3f9b74de04ccvboxsync data cache if that is more efficient than writing back the specified range.
0158d474771d8cf8fb0bfbbe297d3f9b74de04ccvboxsync If Length is 0, then no data cache lines are written back. This function may
0158d474771d8cf8fb0bfbbe297d3f9b74de04ccvboxsync also invalidate all the data cache lines in the specified range of the cache
0158d474771d8cf8fb0bfbbe297d3f9b74de04ccvboxsync coherency domain of the calling CPU. Address is returned.
0158d474771d8cf8fb0bfbbe297d3f9b74de04ccvboxsync
0158d474771d8cf8fb0bfbbe297d3f9b74de04ccvboxsync If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
0158d474771d8cf8fb0bfbbe297d3f9b74de04ccvboxsync
0158d474771d8cf8fb0bfbbe297d3f9b74de04ccvboxsync @param Address The base address of the data cache lines to write back. If
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsync the CPU is in a physical addressing mode, then Address is a
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsync physical address. If the CPU is in a virtual addressing
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsync mode, then Address is a virtual address.
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsync @param Length The number of bytes to write back from the data cache.
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsync
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsync @return Address of cache written in main memory.
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsync
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsync**/
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsyncVOID *
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsyncEFIAPI
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsyncWriteBackDataCacheRange (
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync IN VOID *Address,
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsync IN UINTN Length
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsync )
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsync{
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsync return AsmFlushCacheRange (Address, Length);
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsync}
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsync
d35d319b9a415c443751e23006d9a8e7b1a9660fvboxsync/**
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync Invalidates the entire data cache in cache coherency domain of the calling
ee6da855ccebdd8b5dc295447420b0607757b431vboxsync CPU.
8f574d4912727ef7f831a29e3f836a04b0261392vboxsync
f6adf1a86574758258baa232172c965aed0d848dvboxsync Invalidates the entire data cache in cache coherency domain of the calling
CPU. This function must be used with care because dirty cache lines are not
written back to system memory. It is typically used for cache diagnostics. If
the CPU does not support invalidation of the entire data cache, then a write
back and invalidate operation should be performed on the entire data cache.
**/
VOID
EFIAPI
InvalidateDataCache (
VOID
)
{
//
// Invalidation of the entire data cache without writing back is not supported
// on IPF architecture, so a write back and invalidate operation is performed.
//
WriteBackInvalidateDataCache ();
}
/**
Invalidates a range of data cache lines in the cache coherency domain of the
calling CPU.
Invalidates the data cache lines specified by Address and Length. If Address
is not aligned on a cache line boundary, then entire data cache line
containing Address is invalidated. If Address + Length is not aligned on a
cache line boundary, then the entire data cache line containing Address +
Length -1 is invalidated. This function must never invalidate any cache lines
outside the specified range. If Length is 0, then no data cache lines are
invalidated. Address is returned. This function must be used with care
because dirty cache lines are not written back to system memory. It is
typically used for cache diagnostics. If the CPU does not support
invalidation of a data cache range, then a write back and invalidate
operation should be performed on the data cache range.
If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
@param Address The base address of the data cache lines to invalidate. If
the CPU is in a physical addressing mode, then Address is a
physical address. If the CPU is in a virtual addressing mode,
then Address is a virtual address.
@param Length The number of bytes to invalidate from the data cache.
@return Address.
**/
VOID *
EFIAPI
InvalidateDataCacheRange (
IN VOID *Address,
IN UINTN Length
)
{
//
// Invalidation of a data cache range without writing back is not supported on
// IPF architecture, so write back and invalidate operation is performed.
//
return AsmFlushCacheRange (Address, Length);
}