MdePkg/IoLib: Filter/trace port IO/MMIO access

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3246

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
This commit is contained in:
Dandan Bi
2021-03-12 10:26:10 +08:00
committed by mergify[bot]
parent 9c08b3e7d5
commit 38c8be123a
9 changed files with 329 additions and 73 deletions

View File

@@ -1,7 +1,7 @@
/** @file
Common I/O Library routines.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -82,10 +82,15 @@ MmioRead8 (
)
{
UINT8 Value;
BOOLEAN Flag;
MemoryFence ();
Value = *(volatile UINT8*)Address;
MemoryFence ();
Flag = FilterBeforeMmIoRead (FilterWidth8, Address, &Value);
if (Flag) {
MemoryFence ();
Value = *(volatile UINT8*)Address;
MemoryFence ();
}
FilterAfterMmIoRead (FilterWidth8, Address, &Value);
return Value;
}
@@ -112,9 +117,15 @@ MmioWrite8 (
IN UINT8 Value
)
{
MemoryFence ();
*(volatile UINT8*)Address = Value;
MemoryFence ();
BOOLEAN Flag;
Flag = FilterBeforeMmIoWrite (FilterWidth8, Address, &Value);
if (Flag) {
MemoryFence ();
*(volatile UINT8*)Address = Value;
MemoryFence ();
}
FilterAfterMmIoWrite (FilterWidth8, Address, &Value);
return Value;
}
@@ -141,12 +152,16 @@ MmioRead16 (
)
{
UINT16 Value;
BOOLEAN Flag;
ASSERT ((Address & 1) == 0);
MemoryFence ();
Value = *(volatile UINT16*)Address;
MemoryFence ();
Flag = FilterBeforeMmIoRead (FilterWidth16, Address, &Value);
if (Flag) {
MemoryFence ();
Value = *(volatile UINT16*)Address;
MemoryFence ();
}
FilterAfterMmIoRead (FilterWidth16, Address, &Value);
return Value;
}
@@ -174,11 +189,17 @@ MmioWrite16 (
IN UINT16 Value
)
{
BOOLEAN Flag;
ASSERT ((Address & 1) == 0);
MemoryFence ();
*(volatile UINT16*)Address = Value;
MemoryFence ();
Flag = FilterBeforeMmIoWrite (FilterWidth16, Address, &Value);
if (Flag) {
MemoryFence ();
*(volatile UINT16*)Address = Value;
MemoryFence ();
}
FilterAfterMmIoWrite (FilterWidth16, Address, &Value);
return Value;
}
@@ -205,12 +226,17 @@ MmioRead32 (
)
{
UINT32 Value;
BOOLEAN Flag;
ASSERT ((Address & 3) == 0);
MemoryFence ();
Value = *(volatile UINT32*)Address;
MemoryFence ();
Flag = FilterBeforeMmIoRead (FilterWidth32, Address, &Value);
if (Flag) {
MemoryFence ();
Value = *(volatile UINT32*)Address;
MemoryFence ();
}
FilterAfterMmIoRead (FilterWidth32, Address, &Value);
return Value;
}
@@ -238,11 +264,17 @@ MmioWrite32 (
IN UINT32 Value
)
{
BOOLEAN Flag;
ASSERT ((Address & 3) == 0);
MemoryFence ();
*(volatile UINT32*)Address = Value;
MemoryFence ();
Flag = FilterBeforeMmIoWrite (FilterWidth32, Address, &Value);
if (Flag) {
MemoryFence ();
*(volatile UINT32*)Address = Value;
MemoryFence ();
}
FilterAfterMmIoWrite (FilterWidth32, Address, &Value);
return Value;
}
@@ -269,12 +301,17 @@ MmioRead64 (
)
{
UINT64 Value;
BOOLEAN Flag;
ASSERT ((Address & 7) == 0);
MemoryFence ();
Value = *(volatile UINT64*)Address;
MemoryFence ();
Flag = FilterBeforeMmIoRead (FilterWidth64, Address, &Value);
if (Flag) {
MemoryFence ();
Value = *(volatile UINT64*)Address;
MemoryFence ();
}
FilterAfterMmIoRead (FilterWidth64, Address, &Value);
return Value;
}
@@ -300,11 +337,17 @@ MmioWrite64 (
IN UINT64 Value
)
{
BOOLEAN Flag;
ASSERT ((Address & 7) == 0);
MemoryFence ();
*(volatile UINT64*)Address = Value;
MemoryFence ();
Flag = FilterBeforeMmIoWrite (FilterWidth64, Address, &Value);
if (Flag) {
MemoryFence ();
*(volatile UINT64*)Address = Value;
MemoryFence ();
}
FilterAfterMmIoWrite (FilterWidth64, Address, &Value);
return Value;
}