public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: edk2-devel@lists.01.org
Cc: leif.lindholm@linaro.org, alan@softiron.co.uk,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [PATCH edk2-platforms 1/6] Platform/AMD/OverdriveBoard: fix byte order of default MAC addresses
Date: Tue, 11 Dec 2018 16:02:32 +0100	[thread overview]
Message-ID: <20181211150237.32275-2-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <20181211150237.32275-1-ard.biesheuvel@linaro.org>

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(-)

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);
-- 
2.19.2



  reply	other threads:[~2018-12-11 15:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-11 15:02 [PATCH edk2-platforms 0/6] Silicon/Styx: another round of cleanups Ard Biesheuvel
2018-12-11 15:02 ` Ard Biesheuvel [this message]
2018-12-11 15:02 ` [PATCH edk2-platforms 2/6] Silicon/Styx: drop ARM_CPU_AARCH64 define Ard Biesheuvel
2018-12-11 15:02 ` [PATCH edk2-platforms 3/6] Silicon/Styx: get rid of NUM_CORES preprocessor define on command line Ard Biesheuvel
2018-12-11 15:02 ` [PATCH edk2-platforms 4/6] Silicon/Styx: switch to device path protocol driver Ard Biesheuvel
2018-12-11 15:02 ` [PATCH edk2-platforms 5/6] Platform/AMD/OverdriveBoard: enable support for IPv6 networking and HTTP boot Ard Biesheuvel
2018-12-11 15:02 ` [PATCH edk2-platforms 6/6] Platform/AMD/OverdriveBoard: build device tree from source Ard Biesheuvel
2018-12-11 15:53 ` [PATCH edk2-platforms 0/6] Silicon/Styx: another round of cleanups Leif Lindholm
2018-12-11 16:46   ` Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181211150237.32275-2-ard.biesheuvel@linaro.org \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox