[edk2,edk2-platforms,1/6] Platform/AMD/OverdriveBoard: fix byte order of default MAC addresses

Message ID 20181211150237.32275-2-ard.biesheuvel@linaro.org
State New
Headers show
Series
  • Silicon/Styx: another round of cleanups
Related show

Commit Message

Ard Biesheuvel Dec. 11, 2018, 3:02 p.m.
The PCDs containing the default MAC addresses are of type UINT64,
and so the byte order needs to be inverted. As they are currently,
both default MAC addresses are invalid since they have the multicast
bit set.

For readability, let's switch to a VOID* type PCD while at it.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 Silicon/AMD/Styx/AmdStyx.dec                                 |  4 ++--
 Platform/AMD/OverdriveBoard/OverdriveBoard.dsc               |  4 ++--
 Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.c      |  9 ++++----
 Silicon/AMD/Styx/Drivers/PlatInitPei/PlatInitPei.c           | 24 ++++++++++++--------
 Silicon/AMD/Styx/Library/StyxDtbLoaderLib/StyxDtbLoaderLib.c |  8 +++----
 5 files changed, 26 insertions(+), 23 deletions(-)

-- 
2.19.2

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Patch

diff --git a/Silicon/AMD/Styx/AmdStyx.dec b/Silicon/AMD/Styx/AmdStyx.dec
index 902259dd7267..c2e691cb5ea4 100644
--- a/Silicon/AMD/Styx/AmdStyx.dec
+++ b/Silicon/AMD/Styx/AmdStyx.dec
@@ -42,8 +42,8 @@ 
   gAmdStyxTokenSpaceGuid.PcdSocCoreCount|1|UINT32|0x00000100
   gAmdStyxTokenSpaceGuid.PcdSocCpuId|1|UINT32|0x00000101
 
-  gAmdStyxTokenSpaceGuid.PcdEthMacA|0|UINT64|0x000d0001
-  gAmdStyxTokenSpaceGuid.PcdEthMacB|0|UINT64|0x000d0002
+  gAmdStyxTokenSpaceGuid.PcdEthMacA|{0x0,0x0,0x0,0x0,0x0,0x0}|VOID*|0x000d0001
+  gAmdStyxTokenSpaceGuid.PcdEthMacB|{0x0,0x0,0x0,0x0,0x0,0x0}|VOID*|0x000d0002
 
 [PcdsFixedAtBuild]
   # CPUID Register
diff --git a/Platform/AMD/OverdriveBoard/OverdriveBoard.dsc b/Platform/AMD/OverdriveBoard/OverdriveBoard.dsc
index ce909982c39b..3b9d70de2751 100644
--- a/Platform/AMD/OverdriveBoard/OverdriveBoard.dsc
+++ b/Platform/AMD/OverdriveBoard/OverdriveBoard.dsc
@@ -468,8 +468,8 @@  DEFINE DO_CAPSULE   = FALSE
   gAmdModulePkgTokenSpaceGuid.PcdPort1NetSpeed|1
 
 [PcdsDynamicDefault.common]
-  gAmdStyxTokenSpaceGuid.PcdEthMacA|0x02A1A2A3A4A5
-  gAmdStyxTokenSpaceGuid.PcdEthMacB|0x02B1B2B3B4B5
+  gAmdStyxTokenSpaceGuid.PcdEthMacA|{0x2,0xA1,0xA2,0xA3,0xA4,0xA5}
+  gAmdStyxTokenSpaceGuid.PcdEthMacB|{0x2,0xB1,0xB2,0xB3,0xB4,0xB5}
 
 [PcdsPatchableInModule]
   gAmdModulePkgTokenSpaceGuid.PcdXgbeUseMacFromIscp|TRUE
diff --git a/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.c b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.c
index f1223ada2444..9c17c38a04bf 100644
--- a/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.c
+++ b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.c
@@ -60,15 +60,14 @@  STATIC
 VOID
 SetPackageAddress (
   UINT8         *Package,
-  UINT64        MacAddress,
+  UINT8         *MacAddress,
   UINTN         Size
   )
 {
   UINTN   Index;
 
   for (Index = PACKAGE_MAC_OFFSET; Index < Size; Index += PACKAGE_MAC_INCR) {
-    Package[Index] = (UINT8)MacAddress;
-    MacAddress >>= 8;
+    Package[Index] = *MacAddress++;
   }
 }
 
@@ -165,11 +164,11 @@  InstallSystemDescriptionTables (
       //
       CopyMem (MacPackage, mDefaultMacPackageA, sizeof (MacPackage));
 
-      SetPackageAddress (MacPackage, PcdGet64 (PcdEthMacA), sizeof (MacPackage));
+      SetPackageAddress (MacPackage, PcdGetPtr (PcdEthMacA), sizeof (MacPackage));
       PatchAmlPackage (mDefaultMacPackageA, MacPackage, sizeof (MacPackage),
         (UINT8 *)Table, TableSize);
 
-      SetPackageAddress (MacPackage, PcdGet64 (PcdEthMacB), sizeof (MacPackage));
+      SetPackageAddress (MacPackage, PcdGetPtr (PcdEthMacB), sizeof (MacPackage));
       PatchAmlPackage (mDefaultMacPackageB, MacPackage, sizeof (MacPackage),
         (UINT8 *)Table, TableSize);
 
diff --git a/Silicon/AMD/Styx/Drivers/PlatInitPei/PlatInitPei.c b/Silicon/AMD/Styx/Drivers/PlatInitPei/PlatInitPei.c
index 4ea1dd4b3577..3cd650eee36b 100644
--- a/Silicon/AMD/Styx/Drivers/PlatInitPei/PlatInitPei.c
+++ b/Silicon/AMD/Styx/Drivers/PlatInitPei/PlatInitPei.c
@@ -123,7 +123,7 @@  PlatInitPeiEntryPoint (
   ISCP_CPU_RESET_INFO         CpuResetInfo = {0};
 #if DO_XGBE == 1
   ISCP_MAC_INFO               MacAddrInfo = {0};
-  UINT64                      MacAddr0, MacAddr1;
+  UINTN                       MacSize;
 #endif
   UINTN                       CpuCoreCount, CpuMap, CpuMapSize;
   UINTN                       Index, CoreNum;
@@ -223,16 +223,20 @@  PlatInitPeiEntryPoint (
              PeiServices, &MacAddrInfo );
   ASSERT_EFI_ERROR (Status);
 
-  MacAddr0 = MacAddr1 = 0;
-  for (Index = 0; Index < 6; ++Index) {
-    MacAddr0 |= (UINT64)MacAddrInfo.MacAddress0[Index] << (Index * 8);
-    MacAddr1 |= (UINT64)MacAddrInfo.MacAddress1[Index] << (Index * 8);
-  }
-  PcdSet64 (PcdEthMacA, MacAddr0);
-  PcdSet64 (PcdEthMacB, MacAddr1);
+  MacSize = sizeof(MacAddrInfo.MacAddress0);
+  Status = PcdSetPtrS (PcdEthMacA, &MacSize, MacAddrInfo.MacAddress0);
+  ASSERT_EFI_ERROR (Status);
+  Status = PcdSetPtrS (PcdEthMacB, &MacSize, MacAddrInfo.MacAddress1);
+  ASSERT_EFI_ERROR (Status);
 
-  DEBUG ((EFI_D_ERROR, "EthMacA = 0x%lX\n", PcdGet64 (PcdEthMacA)));
-  DEBUG ((EFI_D_ERROR, "EthMacB = 0x%lX\n", PcdGet64 (PcdEthMacB)));
+  DEBUG ((EFI_D_ERROR, "EthMacA = %02x:%02x:%02x:%02x:%02x:%02x\n",
+    ((UINT8 *)PcdGetPtr (PcdEthMacA))[0], ((UINT8 *)PcdGetPtr (PcdEthMacA))[1],
+    ((UINT8 *)PcdGetPtr (PcdEthMacA))[2], ((UINT8 *)PcdGetPtr (PcdEthMacA))[3],
+    ((UINT8 *)PcdGetPtr (PcdEthMacA))[4], ((UINT8 *)PcdGetPtr (PcdEthMacA))[5]));
+  DEBUG ((EFI_D_ERROR, "EthMacB = %02x:%02x:%02x:%02x:%02x:%02x\n",
+    ((UINT8 *)PcdGetPtr (PcdEthMacB))[0], ((UINT8 *)PcdGetPtr (PcdEthMacB))[1],
+    ((UINT8 *)PcdGetPtr (PcdEthMacB))[2], ((UINT8 *)PcdGetPtr (PcdEthMacB))[3],
+    ((UINT8 *)PcdGetPtr (PcdEthMacB))[4], ((UINT8 *)PcdGetPtr (PcdEthMacB))[5]));
 #endif
 
   // Let other PEI modules know we're done!
diff --git a/Silicon/AMD/Styx/Library/StyxDtbLoaderLib/StyxDtbLoaderLib.c b/Silicon/AMD/Styx/Library/StyxDtbLoaderLib/StyxDtbLoaderLib.c
index b9dfa2367ab2..4ca5d9bebed6 100644
--- a/Silicon/AMD/Styx/Library/StyxDtbLoaderLib/StyxDtbLoaderLib.c
+++ b/Silicon/AMD/Styx/Library/StyxDtbLoaderLib/StyxDtbLoaderLib.c
@@ -168,7 +168,7 @@  VOID
 SetMacAddress (
   IN VOID           *Fdt,
   IN CONST CHAR8    *Device,
-  IN UINT64         MacAddress
+  IN UINT8          *MacAddress
   )
 {
   INT32     Node;
@@ -179,7 +179,7 @@  SetMacAddress (
   if (Node >= 0) {
     SubNode = fdt_subnode_offset (Fdt, Node, Device);
     if (SubNode >= 0) {
-      Rc = fdt_setprop (Fdt, SubNode, "mac-address", (VOID *)&MacAddress,
+      Rc = fdt_setprop (Fdt, SubNode, "mac-address", MacAddress,
              MAC_ADDRESS_BYTES);
       if (Rc) {
         DEBUG ((DEBUG_ERROR,
@@ -289,8 +289,8 @@  SetXgbeStatus (
   SetDeviceStatus (Fdt, "xgmac@e0900000", TRUE);
   SetDeviceStatus (Fdt, "phy@e1240c00", TRUE);
 
-  SetMacAddress (Fdt, "xgmac@e0700000", PcdGet64 (PcdEthMacA));
-  SetMacAddress (Fdt, "xgmac@e0900000", PcdGet64 (PcdEthMacB));
+  SetMacAddress (Fdt, "xgmac@e0700000", PcdGetPtr (PcdEthMacA));
+  SetMacAddress (Fdt, "xgmac@e0900000", PcdGetPtr (PcdEthMacB));
 #else
   SetDeviceStatus (Fdt, "xgmac@e0700000", FALSE);
   SetDeviceStatus (Fdt, "phy@e1240800", FALSE);