diff options
author | qhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524> | 2008-02-01 14:57:29 +0000 |
---|---|---|
committer | qhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524> | 2008-02-01 14:57:29 +0000 |
commit | 8fd567c6f1f0619eaa15830f4725598f5ced61f5 (patch) | |
tree | a9ba9bdf458731d85a1d0410efdf51046567014a /MdePkg/Library | |
parent | d7e5a9f9ac31a0e28040231ce0909c89df3874e4 (diff) | |
download | edk2-platforms-8fd567c6f1f0619eaa15830f4725598f5ced61f5.tar.xz |
Add alignment checking for IoLib functions to conform to MdeLib spec.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4652 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdePkg/Library')
-rw-r--r-- | MdePkg/Library/BaseIoLibIntrinsic/IoLibIpf.c | 122 |
1 files changed, 68 insertions, 54 deletions
diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLibIpf.c b/MdePkg/Library/BaseIoLibIntrinsic/IoLibIpf.c index f519f87945..23ca5c68ed 100644 --- a/MdePkg/Library/BaseIoLibIntrinsic/IoLibIpf.c +++ b/MdePkg/Library/BaseIoLibIntrinsic/IoLibIpf.c @@ -21,6 +21,38 @@ ((((_Port) & 0xfffc) << 10) | ((_Port) & 0x0fff))
/**
+ Translates I/O port address to memory address.
+
+ This function translates I/O port address to memory address by adding the 64MB
+ aligned I/O Port space to the I/O address.
+ If I/O Port space base is not 64MB aligned, then ASSERT ().
+
+ @param Port The I/O port to read.
+
+ @return The memory address.
+
+**/
+UINTN
+InternalGetMemoryMapAddress (
+ IN UINTN Port
+ )
+{
+ UINTN Address;
+ UINTN IoBlockBaseAddress;
+
+ Address = MAP_PORT_BASE_TO_MEM (Port);
+ IoBlockBaseAddress = PcdGet64(PcdIoBlockBaseAddressForIpf);
+
+ //
+ // Make sure that the I/O Port space base is 64MB aligned.
+ //
+ ASSERT ((IoBlockBaseAddress & 0x3ffffff) == 0);
+ Address += IoBlockBaseAddress;
+
+ return Address;
+}
+
+/**
Reads a 8-bit I/O port.
Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
@@ -38,15 +70,7 @@ IoRead8 ( IN UINT64 Port
)
{
- UINT64 Address;
-
- //
- // Add the 64MB aligned IO Port space to the IO address
- //
- Address = MAP_PORT_BASE_TO_MEM (Port);
- Address += PcdGet64(PcdIoBlockBaseAddressForIpf);
-
- return MmioRead8 (Address);
+ return MmioRead8 (InternalGetMemoryMapAddress (Port));
}
/**
@@ -67,15 +91,7 @@ IoRead16 ( IN UINT64 Port
)
{
- UINT64 Address;
-
- //
- // Add the 64MB aligned IO Port space to the IO address
- //
- Address = MAP_PORT_BASE_TO_MEM (Port);
- Address += PcdGet64(PcdIoBlockBaseAddressForIpf);
-
- return MmioRead16 (Address);
+ return MmioRead16 (InternalGetMemoryMapAddress (Port));
}
/**
@@ -96,15 +112,7 @@ IoRead32 ( IN UINT64 Port
)
{
- UINT64 Address;
-
- //
- // Add the 64MB aligned IO Port space to the IO address
- //
- Address = MAP_PORT_BASE_TO_MEM (Port);
- Address += PcdGet64(PcdIoBlockBaseAddressForIpf);
-
- return MmioRead32 (Address);
+ return MmioRead32 (InternalGetMemoryMapAddress (Port));
}
/**
@@ -151,15 +159,7 @@ IoWrite8 ( IN UINT8 Data
)
{
- UINT64 Address;
-
- //
- // Add the 64MB aligned IO Port space to the IO address
- //
- Address = MAP_PORT_BASE_TO_MEM (Port);
- Address += PcdGet64(PcdIoBlockBaseAddressForIpf);
-
- return MmioWrite8 (Address, Data);
+ return MmioWrite8 (InternalGetMemoryMapAddress (Port), Data);
}
/**
@@ -182,15 +182,7 @@ IoWrite16 ( IN UINT16 Data
)
{
- UINT64 Address;
-
- //
- // Add the 64MB aligned IO Port space to the IO address
- //
- Address = MAP_PORT_BASE_TO_MEM (Port);
- Address += PcdGet64(PcdIoBlockBaseAddressForIpf);
-
- return MmioWrite16 (Address, Data);
+ return MmioWrite16 (InternalGetMemoryMapAddress (Port), Data);
}
/**
@@ -213,15 +205,7 @@ IoWrite32 ( IN UINT32 Data
)
{
- UINT64 Address;
-
- //
- // Add the 64MB aligned IO Port space to the IO address
- //
- Address = MAP_PORT_BASE_TO_MEM (Port);
- Address += PcdGet64(PcdIoBlockBaseAddressForIpf);
-
- return MmioWrite32 (Address, Data);
+ return MmioWrite32 (InternalGetMemoryMapAddress (Port), Data);
}
/**
@@ -299,6 +283,11 @@ MmioRead16 ( {
UINT16 Data;
+ //
+ // Make sure that Address is 16-bit aligned.
+ //
+ ASSERT ((Address & 1) == 0);
+
Address |= BIT63;
MemoryFence ();
@@ -328,6 +317,11 @@ MmioRead32 ( {
UINT32 Data;
+ //
+ // Make sure that Address is 32-bit aligned.
+ //
+ ASSERT ((Address & 3) == 0);
+
Address |= BIT63;
MemoryFence ();
@@ -357,6 +351,11 @@ MmioRead64 ( {
UINT64 Data;
+ //
+ // Make sure that Address is 64-bit aligned.
+ //
+ ASSERT ((Address & 7) == 0);
+
Address |= BIT63;
MemoryFence ();
@@ -416,6 +415,11 @@ MmioWrite16 ( IN UINT16 Data
)
{
+ //
+ // Make sure that Address is 16-bit aligned.
+ //
+ ASSERT ((Address & 1) == 0);
+
Address |= BIT63;
MemoryFence ();
@@ -445,6 +449,11 @@ MmioWrite32 ( IN UINT32 Data
)
{
+ //
+ // Make sure that Address is 32-bit aligned.
+ //
+ ASSERT ((Address & 3) == 0);
+
Address |= BIT63;
MemoryFence ();
@@ -474,6 +483,11 @@ MmioWrite64 ( IN UINT64 Data
)
{
+ //
+ // Make sure that Address is 64-bit aligned.
+ //
+ ASSERT ((Address & 7) == 0);
+
Address |= BIT63;
MemoryFence ();
|