From 79b212053dbead3ee04984becb13009a3e637ecc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ky=C3=B6sti=20M=C3=A4lkki?= <kyosti.malkki@gmail.com>
Date: Sat, 16 Apr 2016 13:58:28 +0300
Subject: [PATCH 3/3] AGESA: Align AMDlib functions

Change-Id: I2bf052a717c10760a530f7c4b9a472399e23c0f2
---
 src/vendorcode/amd/agesa/f14/Lib/amdlib.c | 36 +++++++++++++++++++++++++++++--
 src/vendorcode/amd/agesa/f14/Makefile.inc |  4 ----
 2 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/src/vendorcode/amd/agesa/f14/Lib/amdlib.c b/src/vendorcode/amd/agesa/f14/Lib/amdlib.c
index 86e1b9e..8d821cb 100644
--- a/src/vendorcode/amd/agesa/f14/Lib/amdlib.c
+++ b/src/vendorcode/amd/agesa/f14/Lib/amdlib.c
@@ -101,6 +101,7 @@ LibAmdGetDataFromPtr (
  *----------------------------------------------------------------------------------------
  */
 UINT8
+__attribute__ ((aligned (32)))
 ReadIo8 (
   IN       UINT16 Address
   )
@@ -108,6 +109,7 @@ ReadIo8 (
   return __inbyte (Address);
 }
 UINT16
+__attribute__ ((aligned (32)))
 ReadIo16 (
   IN       UINT16 Address
   )
@@ -115,6 +117,7 @@ ReadIo16 (
   return __inword (Address);
 }
 UINT32
+__attribute__ ((aligned (32)))
 ReadIo32 (
   IN       UINT16 Address
   )
@@ -122,6 +125,7 @@ ReadIo32 (
   return __indword (Address);
 }
 VOID
+__attribute__ ((aligned (32)))
 WriteIo8 (
   IN       UINT16 Address,
   IN       UINT8 Data
@@ -130,6 +134,7 @@ WriteIo8 (
   __outbyte (Address, Data);
 }
 VOID
+__attribute__ ((aligned (32)))
 WriteIo16 (
   IN       UINT16 Address,
   IN       UINT16 Data
@@ -138,6 +143,7 @@ WriteIo16 (
   __outword (Address, Data);
 }
 VOID
+__attribute__ ((aligned (32)))
 WriteIo32 (
   IN       UINT16 Address,
   IN       UINT32 Data
@@ -166,6 +172,7 @@ RestoreHwcr (
   __writemsr (0xC0010015, value);
 }
 UINT8
+__attribute__ ((aligned (32)))
 Read64Mem8 (
   IN       UINT64 Address
   )
@@ -181,6 +188,7 @@ Read64Mem8 (
   return dataRead;
 }
 UINT16
+__attribute__ ((aligned (32)))
 Read64Mem16 (
   IN       UINT64 Address
   )
@@ -196,6 +204,7 @@ Read64Mem16 (
   return dataRead;
 }
 UINT32
+__attribute__ ((aligned (32)))
 Read64Mem32 (
   IN       UINT64 Address
   )
@@ -211,6 +220,7 @@ Read64Mem32 (
   return dataRead;
   }
 VOID
+__attribute__ ((aligned (32)))
 Write64Mem8 (
   IN       UINT64 Address,
   IN       UINT8 Data
@@ -227,6 +237,7 @@ Write64Mem8 (
   }
 }
 VOID
+__attribute__ ((aligned (32)))
 Write64Mem16 (
   IN       UINT64 Address,
   IN       UINT16 Data
@@ -243,6 +254,7 @@ Write64Mem16 (
  }
 }
 VOID
+__attribute__ ((aligned (32)))
 Write64Mem32 (
   IN       UINT64 Address,
   IN       UINT32 Data
@@ -363,6 +375,7 @@ LibAmdBitScanReverse (
 }
 
 VOID
+__attribute__ ((aligned (32)))
 LibAmdMsrRead (
   IN       UINT32 MsrAddress,
      OUT   UINT64 *Value,
@@ -372,6 +385,7 @@ LibAmdMsrRead (
   *Value = __readmsr (MsrAddress);
 }
 VOID
+__attribute__ ((aligned (32)))
 LibAmdMsrWrite (
   IN       UINT32 MsrAddress,
   IN       UINT64 *Value,
@@ -476,6 +490,7 @@ StopHere (
  *
  */
 VOID
+__attribute__ ((aligned (32)))
 LibAmdIoRead (
   IN       ACCESS_WIDTH AccessWidth,
   IN       UINT16 IoAddress,
@@ -513,6 +528,7 @@ LibAmdIoRead (
  *
  */
 VOID
+__attribute__ ((aligned (32)))
 LibAmdIoWrite (
   IN       ACCESS_WIDTH AccessWidth,
   IN       UINT16 IoAddress,
@@ -551,6 +567,7 @@ LibAmdIoWrite (
  *
  */
 VOID
+__attribute__ ((aligned (32)))
 LibAmdIoRMW (
   IN       ACCESS_WIDTH AccessWidth,
   IN       UINT16 IoAddress,
@@ -583,6 +600,7 @@ LibAmdIoRMW (
  *
  */
 VOID
+__attribute__ ((aligned (32)))
 LibAmdIoPoll (
   IN       ACCESS_WIDTH AccessWidth,
   IN       UINT16 IoAddress,
@@ -613,6 +631,7 @@ LibAmdIoPoll (
  *
  */
 VOID
+__attribute__ ((aligned (32)))
 LibAmdMemRead (
   IN       ACCESS_WIDTH AccessWidth,
   IN       UINT64 MemAddress,
@@ -650,6 +669,7 @@ LibAmdMemRead (
  *
  */
 VOID
+__attribute__ ((aligned (32)))
 LibAmdMemWrite (
   IN       ACCESS_WIDTH AccessWidth,
   IN       UINT64 MemAddress,
@@ -688,6 +708,7 @@ LibAmdMemWrite (
  *
  */
 VOID
+__attribute__ ((aligned (32)))
 LibAmdMemRMW (
   IN       ACCESS_WIDTH AccessWidth,
   IN       UINT64 MemAddress,
@@ -720,6 +741,7 @@ LibAmdMemRMW (
  *
  */
 VOID
+__attribute__ ((aligned (32)))
 LibAmdMemPoll (
   IN       ACCESS_WIDTH AccessWidth,
   IN       UINT64 MemAddress,
@@ -750,6 +772,7 @@ LibAmdMemPoll (
  *
  */
 VOID
+__attribute__ ((aligned (32)))
 LibAmdPciRead (
   IN       ACCESS_WIDTH AccessWidth,
   IN       PCI_ADDR PciAddress,
@@ -799,6 +822,7 @@ LibAmdPciRead (
  *
  */
 VOID
+__attribute__ ((aligned (32)))
 LibAmdPciWrite (
   IN       ACCESS_WIDTH AccessWidth,
   IN       PCI_ADDR PciAddress,
@@ -849,6 +873,7 @@ LibAmdPciWrite (
  *
  */
 VOID
+__attribute__ ((aligned (32)))
 LibAmdPciRMW (
   IN       ACCESS_WIDTH AccessWidth,
   IN       PCI_ADDR PciAddress,
@@ -881,6 +906,7 @@ LibAmdPciRMW (
  *
  */
 VOID
+__attribute__ ((aligned (32)))
 LibAmdPciPoll (
   IN       ACCESS_WIDTH AccessWidth,
   IN       PCI_ADDR PciAddress,
@@ -947,6 +973,7 @@ GetPciMmioAddress (
  * @param[in]   StdHeader     Standard configuration header
  */
 VOID
+__attribute__ ((aligned (32)))
 LibAmdPciReadBits (
   IN       PCI_ADDR Address,
   IN       UINT8 Highbit,
@@ -980,6 +1007,7 @@ LibAmdPciReadBits (
  * @param[in]   StdHeader     Standard configuration header
  */
 VOID
+__attribute__ ((aligned (32)))
 LibAmdPciWriteBits (
   IN       PCI_ADDR Address,
   IN       UINT8 Highbit,
@@ -1021,6 +1049,7 @@ LibAmdPciWriteBits (
  */
 
 VOID
+__attribute__ ((aligned (32)))
 LibAmdPciFindNextCap (
   IN OUT   PCI_ADDR *Address,
   IN       AMD_CONFIG_PARAMS *StdHeader
@@ -1092,6 +1121,7 @@ LibAmdPciFindNextCap (
  * @param[in]     StdHeader     Standard configuration header (Optional)
  */
 VOID
+__attribute__ ((aligned (32)))
 LibAmdMemFill (
   IN       VOID *Destination,
   IN       UINT8 Value,
@@ -1118,6 +1148,7 @@ LibAmdMemFill (
  * @param[in]     StdHeader     Standard configuration header (Optional)
  */
 VOID
+__attribute__ ((aligned (32)))
 LibAmdMemCopy (
   IN       VOID *Destination,
   IN       CONST VOID *Source,
@@ -1256,8 +1287,8 @@ LibAmdGetPackageType (
  */
 
 
-VOID
-STATIC
+STATIC VOID
+__attribute__ ((aligned (32)))
 LibAmdGetDataFromPtr (
   IN       ACCESS_WIDTH AccessWidth,
   IN       CONST VOID   *Data,
@@ -1298,6 +1329,7 @@ LibAmdGetDataFromPtr (
 
 
 UINT8
+__attribute__ ((aligned (32)))
 LibAmdAccessWidth (
   IN       ACCESS_WIDTH AccessWidth
   )
diff --git a/src/vendorcode/amd/agesa/f14/Makefile.inc b/src/vendorcode/amd/agesa/f14/Makefile.inc
index 1eee9bf..a5f7561 100644
--- a/src/vendorcode/amd/agesa/f14/Makefile.inc
+++ b/src/vendorcode/amd/agesa/f14/Makefile.inc
@@ -330,10 +330,6 @@ libagesa-y += Proc/GNB/Nb/NbPowerMgmt.c
 libagesa-y += Proc/Recovery/HT/htInitReset.c
 libagesa-y += Proc/Mem/Main/mu.c
 
-# Do not optimise performance-critical low-level IO for size with -Os,
-# request -O2 with -falign-functions.
-$(obj)/libagesa/vendorcode/amd/agesa/f14/Lib/amdlib.o: CFLAGS_libagesa += -O2
-
 $(obj)/libagesa.fam14.a: $$(libagesa-objs)
 	@printf " AGESA $(subst $(obj)/,,$(@))\n"
 	$(AR_romstage) rcs $@ $+
-- 
1.9.1

