Re: [edk2] [PATCH] [staging/HTTPS-TLS] Delete extra TlsCipherMappingTable entries

2016-08-02 Thread Wu, Jiaxin
Reviewed-By: Wu Jiaxin 

Best Regards!
Jiaxin

> -Original Message-
> From: Thomas Palmer [mailto:thomas.pal...@hpe.com]
> Sent: Wednesday, August 3, 2016 5:34 AM
> To: edk2-devel@lists.01.org
> Cc: Wu, Jiaxin ; Long, Qin ;
> joseph.shiffl...@hpe.com; Thomas Palmer 
> Subject: [PATCH] [staging/HTTPS-TLS] Delete extra TlsCipherMappingTable
> entries
> 
> The TlsCipherMappingTable will be used to control which ciphers UEFI
> officially supports. When a user configures the ciphers, each cipher is
> checked against this table and if not found is sent the EFI_UNSUPPORTED
> error.
> 
> However, when an entry is present in TlsCipherMappingTable, but our library
> does not have support for it, the user will not see any error if other ciphers
> are being set at the same time.
> 
> This patch will remove entries from TlsLib's TlsCipherMappingTable that our
> OpenSSL library is not configured to support. This restores behavior of
> immediate feedback to user.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Thomas Palmer 
> ---
>  CryptoPkg/Library/TlsLib/TlsLib.c | 7 ---
>  1 file changed, 7 deletions(-)
> 
> diff --git a/CryptoPkg/Library/TlsLib/TlsLib.c
> b/CryptoPkg/Library/TlsLib/TlsLib.c
> index 1f3554a..aa08595 100644
> --- a/CryptoPkg/Library/TlsLib/TlsLib.c
> +++ b/CryptoPkg/Library/TlsLib/TlsLib.c
> @@ -57,31 +57,24 @@ STATIC CONST TLS_CIPHER_PAIR
> TlsCipherMappingTable[] = {
>{ 0x0002, "NULL-SHA" }, /// TLS_RSA_WITH_NULL_SHA
>{ 0x0004, "RC4-MD5" },  /// TLS_RSA_WITH_RC4_128_MD5
>{ 0x0005, "RC4-SHA" },  /// TLS_RSA_WITH_RC4_128_SHA
> -  { 0x0007, "IDEA-CBC-SHA" }, /// TLS_RSA_WITH_IDEA_CBC_SHA
> -  { 0x0009, "DES-CBC-SHA" },  /// TLS_RSA_WITH_DES_CBC_SHA
>{ 0x000A, "DES-CBC3-SHA" }, /// TLS_RSA_WITH_3DES_EDE_CBC_SHA,
> mandatory TLS 1.1
> -  { 0x0013, "DHE-DSS-DES-CBC3-SHA" }, ///
> TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA, mandatory TLS 1.0
>{ 0x0016, "DHE-RSA-DES-CBC3-SHA" }, ///
> TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
>{ 0x002F, "AES128-SHA" },   /// TLS_RSA_WITH_AES_128_CBC_SHA,
> mandatory TLS 1.2
>{ 0x0030, "DH-DSS-AES128-SHA" },///
> TLS_DH_DSS_WITH_AES_128_CBC_SHA
>{ 0x0031, "DH-RSA-AES128-SHA" },///
> TLS_DH_RSA_WITH_AES_128_CBC_SHA
> -  { 0x0032, "DHE-DSS-AES128-SHA" },   ///
> TLS_DHE_DSS_WITH_AES_128_CBC_SHA
>{ 0x0033, "DHE-RSA-AES128-SHA" },   ///
> TLS_DHE_RSA_WITH_AES_128_CBC_SHA
>{ 0x0035, "AES256-SHA" },   /// TLS_RSA_WITH_AES_256_CBC_SHA
>{ 0x0036, "DH-DSS-AES256-SHA" },///
> TLS_DH_DSS_WITH_AES_256_CBC_SHA
>{ 0x0037, "DH-RSA-AES256-SHA" },///
> TLS_DH_RSA_WITH_AES_256_CBC_SHA
> -  { 0x0038, "DHE-DSS-AES256-SHA" },   ///
> TLS_DHE_DSS_WITH_AES_256_CBC_SHA
>{ 0x0039, "DHE-RSA-AES256-SHA" },   ///
> TLS_DHE_RSA_WITH_AES_256_CBC_SHA
>{ 0x003B, "NULL-SHA256" },  /// TLS_RSA_WITH_NULL_SHA256
>{ 0x003C, "AES128-SHA256" },///
> TLS_RSA_WITH_AES_128_CBC_SHA256
>{ 0x003D, "AES256-SHA256" },///
> TLS_RSA_WITH_AES_256_CBC_SHA256
>{ 0x003E, "DH-DSS-AES128-SHA256" }, ///
> TLS_DH_DSS_WITH_AES_128_CBC_SHA256
>{ 0x003F, "DH-RSA-AES128-SHA256" }, ///
> TLS_DH_RSA_WITH_AES_128_CBC_SHA256
> -  { 0x0040, "DHE-DSS-AES128-SHA256" },///
> TLS_DHE_DSS_WITH_AES_128_CBC_SHA256
>{ 0x0067, "DHE-RSA-AES128-SHA256" },///
> TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
>{ 0x0068, "DH-DSS-AES256-SHA256" }, ///
> TLS_DH_DSS_WITH_AES_256_CBC_SHA256
>{ 0x0069, "DH-RSA-AES256-SHA256" }, ///
> TLS_DH_RSA_WITH_AES_256_CBC_SHA256
> -  { 0x006A, "DHE-DSS-AES256-SHA256" },///
> TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
>{ 0x006B, "DHE-RSA-AES256-SHA256" } ///
> TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
>  };
> 
> --
> 1.9.1

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


Re: [edk2] [patch] MdeModulePkg/UsbMass: Not retry if usb bot transfer execution fail

2016-08-02 Thread Zeng, Star
Reviewed-by: Star Zeng 

-Original Message-
From: Tian, Feng 
Sent: Wednesday, August 3, 2016 10:08 AM
To: Zeng, Star 
Cc: edk2-devel@lists.01.org
Subject: [patch] MdeModulePkg/UsbMass: Not retry if usb bot transfer execution 
fail

[Sorry, this patch was pushed into EDKII trunk by wrong operation.

If the review mail could pass review, I would prefer to not do a roll-back.
Sorry again for that.

If there is other opinions, please let me know.]

The retry mechanism will bring issue if the usb device is unplugged from XHCI 
HC but s/w is trying to access it through BlockIo. The current cmd will get 
device error return status, but the sequential cmds will be timeout. This 
behavior will cause system unresponsive for a long while and bring bad user 
experience.

So we break the retry loop if found device error.

Cc: Star Zeng 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian 
---
 MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c | 9 +++--  
MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c  | 8 ++--
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c 
b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
index 9f99650..96c3622 100644
--- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
+++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
@@ -2,7 +2,7 @@
   Implementation of the command set of USB Mass Storage Specification
   for Bootability, Revision 1.0.
 
-Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.
 This program and the accompanying materials  are licensed and made available 
under the terms and conditions of the BSD License  which accompanies this 
distribution.  The full text of the license may be found at @@ -189,6 +189,11 
@@ UsbBootExecCmd (
 return EFI_TIMEOUT;
   }
 
+  if (Status == EFI_DEVICE_ERROR) {
+DEBUG ((EFI_D_ERROR, "UsbBootExecCmd: Device Error to Exec 0x%x Cmd\n", 
*(UINT8 *)Cmd));
+return EFI_DEVICE_ERROR;
+  }
+
   //
   // If ExecCommand() returns no error and CmdResult is success,
   // then the commnad transfer is successful.
@@ -271,7 +276,7 @@ UsbBootExecCmdWithRetry (
DataLen,
Timeout
);
-if (Status == EFI_SUCCESS || Status == EFI_MEDIA_CHANGED || Status == 
EFI_NO_MEDIA) {
+if (Status == EFI_SUCCESS || Status == EFI_MEDIA_CHANGED || Status 
+ == EFI_NO_MEDIA || Status == EFI_DEVICE_ERROR) {
   break;
 }
 //
diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c 
b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c
index dd83540..0767ff0 100644
--- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c
+++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c
@@ -2,7 +2,7 @@
   Implementation of the USB mass storage Bulk-Only Transport protocol,
   according to USB Mass Storage Class Bulk-Only Transport, Revision 1.0.
 
-Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.
 This program and the accompanying materials  are licensed and made available 
under the terms and conditions of the BSD License  which accompanies this 
distribution.  The full text of the license may be found at @@ -432,7 +432,11 
@@ UsbBotExecCommand (
   // whether it succeeds or fails.
   //
   TransLen = (UINTN) DataLen;
-  UsbBotDataTransfer (UsbBot, DataDir, Data, , Timeout);
+  Status   = UsbBotDataTransfer (UsbBot, DataDir, Data, , Timeout);
+  if (Status == EFI_DEVICE_ERROR) {
+DEBUG ((EFI_D_ERROR, "UsbBotExecCommand: UsbBotDataTransfer (%r)\n", 
Status));
+return Status;
+  }
 
   //
   // Get the status, if that succeeds, interpret the result
--
2.7.1.windows.2

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


[edk2] [patch] MdeModulePkg/UsbMass: Not retry if usb bot transfer execution fail

2016-08-02 Thread Feng Tian
[Sorry, this patch was pushed into EDKII trunk by wrong operation.

If the review mail could pass review, I would prefer to not do a roll-back.
Sorry again for that.

If there is other opinions, please let me know.]

The retry mechanism will bring issue if the usb device is unplugged
from XHCI HC but s/w is trying to access it through BlockIo. The
current cmd will get device error return status, but the sequential
cmds will be timeout. This behavior will cause system unresponsive
for a long while and bring bad user experience.

So we break the retry loop if found device error.

Cc: Star Zeng 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian 
---
 MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c | 9 +++--
 MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c  | 8 ++--
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c 
b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
index 9f99650..96c3622 100644
--- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
+++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
@@ -2,7 +2,7 @@
   Implementation of the command set of USB Mass Storage Specification
   for Bootability, Revision 1.0.
 
-Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -189,6 +189,11 @@ UsbBootExecCmd (
 return EFI_TIMEOUT;
   }
 
+  if (Status == EFI_DEVICE_ERROR) {
+DEBUG ((EFI_D_ERROR, "UsbBootExecCmd: Device Error to Exec 0x%x Cmd\n", 
*(UINT8 *)Cmd));
+return EFI_DEVICE_ERROR;
+  }
+
   //
   // If ExecCommand() returns no error and CmdResult is success,
   // then the commnad transfer is successful.
@@ -271,7 +276,7 @@ UsbBootExecCmdWithRetry (
DataLen,
Timeout
);
-if (Status == EFI_SUCCESS || Status == EFI_MEDIA_CHANGED || Status == 
EFI_NO_MEDIA) {
+if (Status == EFI_SUCCESS || Status == EFI_MEDIA_CHANGED || Status == 
EFI_NO_MEDIA || Status == EFI_DEVICE_ERROR) {
   break;
 }
 //
diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c 
b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c
index dd83540..0767ff0 100644
--- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c
+++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c
@@ -2,7 +2,7 @@
   Implementation of the USB mass storage Bulk-Only Transport protocol,
   according to USB Mass Storage Class Bulk-Only Transport, Revision 1.0.
 
-Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -432,7 +432,11 @@ UsbBotExecCommand (
   // whether it succeeds or fails.
   //
   TransLen = (UINTN) DataLen;
-  UsbBotDataTransfer (UsbBot, DataDir, Data, , Timeout);
+  Status   = UsbBotDataTransfer (UsbBot, DataDir, Data, , Timeout);
+  if (Status == EFI_DEVICE_ERROR) {
+DEBUG ((EFI_D_ERROR, "UsbBotExecCommand: UsbBotDataTransfer (%r)\n", 
Status));
+return Status;
+  }
 
   //
   // Get the status, if that succeeds, interpret the result
-- 
2.7.1.windows.2

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


Re: [edk2] Foreign keyboard support in UEFI

2016-08-02 Thread Senthilarasu_ARUNACH
Aaron,
Thanks for detailed information to start our investigation   . Will keep update 
our findings in this forum.



From: aaron@congatec.com 
[mailto:aaron@congatec.com]
Sent: Tuesday, August 2, 2016 2:16 PM
To: Arunachalam, Senthil 
>
Cc: edk2-devel@lists.01.org
Subject: Re: [edk2] Foreign keyboard support in UEFI

Hi Senthil,

Multi language keyboards support should be pretty transparent to an 
application. The simple text input protocols are designed to return a unicode 
character, and the protocols leave the mapping of keypress into the current 
keyboard layout to the system firmware.  Keyboard layouts are installed into 
the Hii database, and then a set keyboard layout call is made to tell the 
system which keyboard layout to use. Each regional keyboard has a different 
layout (https://msdn.microsoft.com/en-us/goglobal/bb964651.aspx).  The UEFI 
specification (section 31.2.4) maps a keyboard into an enumerated value 
(EFI_KEY in MdePkg\Include\Uefi\UefiInternalFormRepresentation.h) and that 
enumerated value is used as an index into the keyboard layout data to return a 
unicode character for a specific keypress.

If you are not getting a valid return character when you press a key on a usb 
keyboard, then there is a chance that the UsbKbDxe driver does not consider the 
key you pressed as a valid Usb key for the given keyboard layout.  USB 
keyboards return a Usage ID for a given key press 
(http://www.usb.org/developers/hidpage/Hut1_12v2.pdf).  The EDK2 Usb keyboard 
driver (MdeModulePkg/Bus/Usb/UsbKbDxe) retrieves the USB usage id and 
translates it into an EFI_KEY_DATA entry by using the tables in the top of the 
Keyboard.c file (EfiKeyToUsbKeyCodeConvertionTable and mUsbKeyboardLayoutBin).  
It is possible that your system does not correctly map the hid usage id to a 
valid EFI_KEY enum based on the current keyboard mapping layout.

I hope this gives you enough information to start to figure out your issue.





From:
>
To:>
Date:08/01/2016 09:53 PM
Subject:[edk2] Foreign keyboard support in UEFI
Sent by:"edk2-devel" 
>




Hi,
Any one shed some light on supporting multi language key board  support on  
UEFI application? Scan code received from EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL not 
returns  value for
certain keys in  German/Arabic USB keyboard. We are also not sure in mapping 
UEFI code from EFI_HII_DATABASE_PROTOCOL.GetKeyBoardLayOut()).


Thanks
Senthil





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


Re: [edk2] Foreign keyboard support in UEFI

2016-08-02 Thread Senthilarasu_ARUNACH
Dell - Internal Use - Confidential
Aaron,
Thanks for detailed information to start our investigation   . Will keep update 
our findings in this forum.


From: aaron@congatec.com [mailto:aaron@congatec.com]
Sent: Tuesday, August 2, 2016 2:16 PM
To: Arunachalam, Senthil 
Cc: edk2-devel@lists.01.org
Subject: Re: [edk2] Foreign keyboard support in UEFI

Hi Senthil,

Multi language keyboards support should be pretty transparent to an 
application. The simple text input protocols are designed to return a unicode 
character, and the protocols leave the mapping of keypress into the current 
keyboard layout to the system firmware.  Keyboard layouts are installed into 
the Hii database, and then a set keyboard layout call is made to tell the 
system which keyboard layout to use. Each regional keyboard has a different 
layout (https://msdn.microsoft.com/en-us/goglobal/bb964651.aspx).  The UEFI 
specification (section 31.2.4) maps a keyboard into an enumerated value 
(EFI_KEY in MdePkg\Include\Uefi\UefiInternalFormRepresentation.h) and that 
enumerated value is used as an index into the keyboard layout data to return a 
unicode character for a specific keypress.

If you are not getting a valid return character when you press a key on a usb 
keyboard, then there is a chance that the UsbKbDxe driver does not consider the 
key you pressed as a valid Usb key for the given keyboard layout.  USB 
keyboards return a Usage ID for a given key press 
(http://www.usb.org/developers/hidpage/Hut1_12v2.pdf).  The EDK2 Usb keyboard 
driver (MdeModulePkg/Bus/Usb/UsbKbDxe) retrieves the USB usage id and 
translates it into an EFI_KEY_DATA entry by using the tables in the top of the 
Keyboard.c file (EfiKeyToUsbKeyCodeConvertionTable and mUsbKeyboardLayoutBin).  
It is possible that your system does not correctly map the hid usage id to a 
valid EFI_KEY enum based on the current keyboard mapping layout.

I hope this gives you enough information to start to figure out your issue.





From:
>
To:>
Date:08/01/2016 09:53 PM
Subject:[edk2] Foreign keyboard support in UEFI
Sent by:"edk2-devel" 
>




Hi,
Any one shed some light on supporting multi language key board  support on  
UEFI application? Scan code received from EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL not 
returns  value for
certain keys in  German/Arabic USB keyboard. We are also not sure in mapping 
UEFI code from EFI_HII_DATABASE_PROTOCOL.GetKeyBoardLayOut()).


Thanks
Senthil





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

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


Re: [edk2] [Patch] SecurityPkg OpalPasswordDxe: Fix buffer overflow issue.

2016-08-02 Thread Zeng, Star
Reviewed-by: Star Zeng 

-Original Message-
From: Dong, Eric 
Sent: Tuesday, August 2, 2016 7:33 PM
To: edk2-devel@lists.01.org
Cc: Zeng, Star 
Subject: [Patch] SecurityPkg OpalPasswordDxe: Fix buffer overflow issue.

In current code, PSID is processed as string and the length is 0x20.
Current code only reserved 0x20 length buffer for it, no extra buffer for the 
'\0'. When driver call UnicodeStrToAsciiStrS to convert PSID, it search the 
'\0' for the end. So extra dirty data saved in PSID info which caused PSID 
revert action failed. This patch reserved extra 1 byte data for the '\0'.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong 
Cc: Star Zeng 
---
 SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHii.c   | 5 -
 SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHiiFormValues.h | 3 ++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHii.c 
b/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHii.c
index 9a44c56..ee73697 100644
--- a/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHii.c
+++ b/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHii.c
@@ -595,12 +595,15 @@ HiiPsidRevert(
   OPAL_DISK *OpalDisk;
   TCG_RESULTRet;
   OPAL_SESSION  Session;
+  UINT8 TmpBuf[PSID_CHARACTER_STRING_END_LENGTH];
 
   Ret = TcgResultFailure;
 
   OpalHiiGetBrowserData();
 
-  UnicodeStrToAsciiStrS (gHiiConfiguration.Psid, (CHAR8*)Psid.Psid, 
PSID_CHARACTER_LENGTH);
+  ZeroMem (TmpBuf, sizeof (TmpBuf));
+  UnicodeStrToAsciiStrS (gHiiConfiguration.Psid, (CHAR8*)TmpBuf, 
+ PSID_CHARACTER_STRING_END_LENGTH);
+  CopyMem (Psid.Psid, TmpBuf, PSID_CHARACTER_LENGTH);
 
   OpalDisk = HiiGetOpalDiskCB (gHiiConfiguration.SelectedDiskIndex);
   if (OpalDisk != NULL) {
diff --git a/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHiiFormValues.h 
b/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHiiFormValues.h
index 138bcb8..88cf9f5 100644
--- a/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHiiFormValues.h
+++ b/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHiiFormValues.h
@@ -21,6 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 
 // PSID Length
 #define PSID_CHARACTER_LENGTH  0x20
+#define PSID_CHARACTER_STRING_END_LENGTH   0x21
 
 // ID's for various forms that will be used by HII
 #define FORMID_VALUE_MAIN_MENU 0x01
@@ -38,7 +39,7 @@ typedef struct {
 UINT8   KeepUserData;
 UINT16  AvailableFields;
 UINT16  Password[MAX_PASSWORD_CHARACTER_LENGTH];
-UINT16  Psid[PSID_CHARACTER_LENGTH];
+UINT16  Psid[PSID_CHARACTER_STRING_END_LENGTH];
 UINT8   EnableBlockSid;
 } OPAL_HII_CONFIGURATION;
 #pragma pack()
--
2.6.4.windows.1

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


Re: [edk2] Build traceback with new CLANG35 toolset

2016-08-02 Thread Shi, Steven
Cran,
We will send CLANG38 patch to support X86, and the new CLANG38 patch will base 
on current GCC5 implementation. FYI.


Steven Shi
Intel\SSG\STO\UEFI Firmware

Tel: +86 021-61166522
iNet: 821-6522


> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
> Bruce Cran
> Sent: Wednesday, August 03, 2016 2:56 AM
> To: Ard Biesheuvel 
> Cc: edk2-devel-01 
> Subject: Re: [edk2] Build traceback with new CLANG35 toolset
> 
> On 8/2/2016 12:53 PM, Ard Biesheuvel wrote:
> 
> > CLANG35 is not new, and currently only supports ARM and AARCH64
> 
> Oops - thanks. I was thinking of CLANG38 that hasn't been committed yet.
> 
> --
> Bruce
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] [staging/HTTPS-TLS] Delete extra TlsCipherMappingTable entries

2016-08-02 Thread Thomas Palmer
The TlsCipherMappingTable will be used to control which ciphers UEFI
officially supports. When a user configures the ciphers, each cipher
is checked against this table and if not found is sent the
EFI_UNSUPPORTED error.

However, when an entry is present in TlsCipherMappingTable, but our
library does not have support for it, the user will not see any
error if other ciphers are being set at the same time.

This patch will remove entries from TlsLib's TlsCipherMappingTable
that our OpenSSL library is not configured to support. This restores
behavior of immediate feedback to user.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Thomas Palmer 
---
 CryptoPkg/Library/TlsLib/TlsLib.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/CryptoPkg/Library/TlsLib/TlsLib.c 
b/CryptoPkg/Library/TlsLib/TlsLib.c
index 1f3554a..aa08595 100644
--- a/CryptoPkg/Library/TlsLib/TlsLib.c
+++ b/CryptoPkg/Library/TlsLib/TlsLib.c
@@ -57,31 +57,24 @@ STATIC CONST TLS_CIPHER_PAIR TlsCipherMappingTable[] = {
   { 0x0002, "NULL-SHA" }, /// TLS_RSA_WITH_NULL_SHA
   { 0x0004, "RC4-MD5" },  /// TLS_RSA_WITH_RC4_128_MD5
   { 0x0005, "RC4-SHA" },  /// TLS_RSA_WITH_RC4_128_SHA
-  { 0x0007, "IDEA-CBC-SHA" }, /// TLS_RSA_WITH_IDEA_CBC_SHA
-  { 0x0009, "DES-CBC-SHA" },  /// TLS_RSA_WITH_DES_CBC_SHA
   { 0x000A, "DES-CBC3-SHA" }, /// TLS_RSA_WITH_3DES_EDE_CBC_SHA, 
mandatory TLS 1.1
-  { 0x0013, "DHE-DSS-DES-CBC3-SHA" }, /// 
TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA, mandatory TLS 1.0
   { 0x0016, "DHE-RSA-DES-CBC3-SHA" }, /// TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
   { 0x002F, "AES128-SHA" },   /// TLS_RSA_WITH_AES_128_CBC_SHA, 
mandatory TLS 1.2
   { 0x0030, "DH-DSS-AES128-SHA" },/// TLS_DH_DSS_WITH_AES_128_CBC_SHA
   { 0x0031, "DH-RSA-AES128-SHA" },/// TLS_DH_RSA_WITH_AES_128_CBC_SHA
-  { 0x0032, "DHE-DSS-AES128-SHA" },   /// TLS_DHE_DSS_WITH_AES_128_CBC_SHA
   { 0x0033, "DHE-RSA-AES128-SHA" },   /// TLS_DHE_RSA_WITH_AES_128_CBC_SHA
   { 0x0035, "AES256-SHA" },   /// TLS_RSA_WITH_AES_256_CBC_SHA
   { 0x0036, "DH-DSS-AES256-SHA" },/// TLS_DH_DSS_WITH_AES_256_CBC_SHA
   { 0x0037, "DH-RSA-AES256-SHA" },/// TLS_DH_RSA_WITH_AES_256_CBC_SHA
-  { 0x0038, "DHE-DSS-AES256-SHA" },   /// TLS_DHE_DSS_WITH_AES_256_CBC_SHA
   { 0x0039, "DHE-RSA-AES256-SHA" },   /// TLS_DHE_RSA_WITH_AES_256_CBC_SHA
   { 0x003B, "NULL-SHA256" },  /// TLS_RSA_WITH_NULL_SHA256
   { 0x003C, "AES128-SHA256" },/// TLS_RSA_WITH_AES_128_CBC_SHA256
   { 0x003D, "AES256-SHA256" },/// TLS_RSA_WITH_AES_256_CBC_SHA256
   { 0x003E, "DH-DSS-AES128-SHA256" }, /// 
TLS_DH_DSS_WITH_AES_128_CBC_SHA256
   { 0x003F, "DH-RSA-AES128-SHA256" }, /// 
TLS_DH_RSA_WITH_AES_128_CBC_SHA256
-  { 0x0040, "DHE-DSS-AES128-SHA256" },/// 
TLS_DHE_DSS_WITH_AES_128_CBC_SHA256
   { 0x0067, "DHE-RSA-AES128-SHA256" },/// 
TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
   { 0x0068, "DH-DSS-AES256-SHA256" }, /// 
TLS_DH_DSS_WITH_AES_256_CBC_SHA256
   { 0x0069, "DH-RSA-AES256-SHA256" }, /// 
TLS_DH_RSA_WITH_AES_256_CBC_SHA256
-  { 0x006A, "DHE-DSS-AES256-SHA256" },/// 
TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
   { 0x006B, "DHE-RSA-AES256-SHA256" } /// 
TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
 };
 
-- 
1.9.1

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


Re: [edk2] [staging/HTTPS-TLS][PATCH 0/4] Replace the TLS definitions with the standardized one

2016-08-02 Thread Palmer, Thomas
I have two sets of lists,  one for the ciphers the OpenSSL by default 
configures in a new CTX and the other after setting all ciphers available in 
the mapping table.  For both sets I show the affect of removing no-idea/no-dsa 
and adding enable-weak-ciphers

These are the ciphers that are supported by TLS immediately after a TLS_CTX_new 
operation with current OpenSSL config (34):
AES128-GCM-SHA256
AES128-SHA
AES128-SHA256
AES256-GCM-SHA384
AES256-SHA
AES256-SHA256
DES-CBC3-SHA
DH-DSS-AES128-GCM-SHA256
DH-DSS-AES128-SHA
DH-DSS-AES128-SHA256
DH-DSS-AES256-GCM-SHA384
DH-DSS-AES256-SHA
DH-DSS-AES256-SHA256
DH-DSS-DES-CBC3-SHA
DHE-RSA-AES128-GCM-SHA256
DHE-RSA-AES128-SHA
DHE-RSA-AES128-SHA256
DHE-RSA-AES256-GCM-SHA384
DHE-RSA-AES256-SHA
DHE-RSA-AES256-SHA256
DH-RSA-AES128-GCM-SHA256
DH-RSA-AES128-SHA
DH-RSA-AES128-SHA256
DH-RSA-AES256-GCM-SHA384
DH-RSA-AES256-SHA
DH-RSA-AES256-SHA256
DH-RSA-DES-CBC3-SHA
EDH-RSA-DES-CBC3-SHA
PSK-3DES-EDE-CBC-SHA
PSK-AES128-CBC-SHA
PSK-AES256-CBC-SHA
PSK-RC4-SHA
RC4-MD5
RC4-SHA

By removing "no-idea" in process_files we gain (1):
IDEA-CBC-SHA

By removing "no-dsa" in process_files we gain (7):
DHE-DSS-AES128-GCM-SHA256
DHE-DSS-AES128-SHA
DHE-DSS-AES128-SHA256
DHE-DSS-AES256-GCM-SHA384
DHE-DSS-AES256-SHA
DHE-DSS-AES256-SHA256
EDH-DSS-DES-CBC3-SHA

We do not gain any more ciphers with enable-weak-ssl-ciphers at this point.


Now here are the ciphers after TlsSetCipherList has been run with setting all 
ciphers currently in TlsCipherMappingTable.
With original OpenSSL configuration (23):
AES128-SHA
AES128-SHA256
AES256-SHA
AES256-SHA256
DES-CBC3-SHA
DH-DSS-AES128-SHA
DH-DSS-AES128-SHA256
DH-DSS-AES256-SHA
DH-DSS-AES256-SHA256
DHE-RSA-AES128-SHA
DHE-RSA-AES128-SHA256
DHE-RSA-AES256-SHA
DHE-RSA-AES256-SHA256
DH-RSA-AES128-SHA
DH-RSA-AES128-SHA256
DH-RSA-AES256-SHA
DH-RSA-AES256-SHA256
EDH-RSA-DES-CBC3-SHA
NULL-MD5
NULL-SHA
NULL-SHA256
RC4-MD5
RC4-SHA

By removing "no-idea" in process_files we gain (1):
IDEA-CBC-SHA

By removing "no-dsa" in process_files we gain (5):
DHE-DSS-AES256-SHA
DHE-DSS-AES256-SHA256
DHE-DSS-AES128-SHA
DHE-DSS-AES128-SHA256
EDH-DSS-DES-CBC3-SHA

Be adding enable-weak-ssl-ciphers we gain (1):
DES-CBC-SHA


Thomas

-Original Message-
From: Wu, Jiaxin [mailto:jiaxin...@intel.com] 
Sent: Monday, August 1, 2016 9:03 PM
To: Palmer, Thomas ; Long, Qin ; 
edk2-devel@lists.01.org
Cc: Ye, Ting ; Fu, Siyuan ; Gao, Liming 

Subject: RE: [staging/HTTPS-TLS][PATCH 0/4] Replace the TLS definitions with 
the standardized one

Thomas,

Thanks your effort to test the new ciphers, can you provide the info which one 
is unsupported currently?

As Qin's comments, "we'd better to keep the current supported cipher suite for 
our UEFI- TLS enabling". If so, I agree to remove the unsupported one in 
TlsCipherMappingTable instead of changing the current openssl configuration. If 
dsa /idea is required in future, then we can consider how to enable the 
configuration.

So, can you provide the patch to remove the unsupported one in 
TlsCipherMappingTable?


Thanks,
Jiaxin



> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of 
> Palmer, Thomas
> Sent: Tuesday, August 2, 2016 9:51 AM
> To: Wu, Jiaxin ; Long, Qin ; 
> edk2-devel@lists.01.org
> Cc: Ye, Ting ; Fu, Siyuan ; 
> Gao, Liming 
> Subject: Re: [edk2] [staging/HTTPS-TLS][PATCH 0/4] Replace the TLS 
> definitions with the standardized one
> 
> 
> Hi Jiaxin,
> 
>   It sounds like we both agree that TlsCipherMappingTable is the list 
> of what UEFI officially supports.  If it is advertised in 
> TlsCipherMappingTable then OpenSSL needs to support it.
> 
>   My proposal of removing no-dsa / no-idea and adding weak-ciphers is 
> specifically aimed to syncing how OpenSSL is configured/built to what 
> is in TlsCipherMappingTable.  I was busy last week testing out the new 
> ciphers and realized a few were not even getting configured in OpenSSL.
> 
> Thomas
> 
> -Original Message-
> From: Wu, Jiaxin [mailto:jiaxin...@intel.com]
> Sent: Monday, August 1, 2016 8:34 PM
> To: Palmer, Thomas ; Long, Qin 
> ; edk2-devel@lists.01.org
> Cc: Ye, Ting ; Fu, Siyuan ; 
> Gao, Liming 
> Subject: RE: [staging/HTTPS-TLS][PATCH 0/4] Replace the TLS 
> definitions with the standardized one
> 
> Hi Thomas,
> 
> Since the Tls1.h is used to hold the standardized definitions, openssl 
> part is not taken into consideration. The Cipher Suites added in 
> Tls1.h only refers to
> A.5 of rfc-2246, rfc-4346 and rfc-5246. The criteria is removing all 
> the limited/insecurity/deprecated ones that specified in RFC -- "Note 
> that this mode is vulnerable to man-in-the middle attacks and 

Re: [edk2] Tianocore Bugzilla Server is now live

2016-08-02 Thread Andrew Fish

> On Aug 2, 2016, at 12:43 PM, Michael Zimmermann  
> wrote:
> 
> How are security issues treated in UEFI anyway?

They follow the standard ethical disclosure process like then one discussed 
here: http://www.uefi.org/security

> Are they kept a secret forever or just for a specific time span?
> 

The ethical disclosure processes is followed and an timespan is picked that 
lets systems that are going to get updates get fixed. This is how things 
security work in general. 

> A reason for keeping them a secret forever(while pushing
> unsuspicious fixes) probably would be the fact that most UEFI systems don't
> get updated.
> 

No after some reasonable amount of time there will be disclosure to the public. 
The embargo of information is to let as many folks as possible get patches in 
place before the issue is public. 

Thanks,

Andrew Fish

> Thanks
> Michael
> 
> On Tue, Aug 2, 2016 at 9:34 PM, Laszlo Ersek  wrote:
> 
>> On 08/02/16 21:10, Kinney, Michael D wrote:
>>> Michael,
>>> 
>>> I am open to suggestions on this topic.
>>> 
>>> If there is a strong opinion that we need to protect specific fields
>>> from being modified, then we can look into updating the configuration.
>>> 
>>> I think with Bugzilla change history and edk2-bugs mailing list, we can
>>> all see the changes to any issue, so even if someone does do an
>>> incorrect edit, I think we can put it back.
>> 
>> Does "editbugs" include changing the product from "Tianocore Security
>> Issues" to something else, possibly exposing the security issue to the
>> world?
>> 
>> Hm... It probably doesn't matter. If a security issue can be looked at
>> (which is a pre-requisite for the product field to be changed) by anyone
>> in the first place, then they can expose the contents to the world in
>> other ways too. :)
>> 
>> So I think trusting all registered accounts with "editbugs" is a good
>> starting point too.
>> 
>> Thanks
>> Laszlo
>> 
>> 
>>> *From:*Michael Zimmermann [mailto:sigmaepsilo...@gmail.com]
>>> *Sent:* Tuesday, August 2, 2016 11:57 AM
>>> *To:* Laszlo Ersek 
>>> *Cc:* Kinney, Michael D ; edk2-devel-01
>>> 
>>> *Subject:* Re: [edk2] Tianocore Bugzilla Server is now live
>>> 
>>> 
>>> 
>>> Is it just my account or does everybody have the permission
>>> "editbugs  Can edit all bug fields"?
>>> 
>>> 
>>> 
>>> It sounds like this is something only moderators should be able to do.
>>> 
>>> 
>>> 
>>> Thanks
>>> 
>>> Michael
>>> 
>>> 
>>> 
>>> On Thu, Jul 21, 2016 at 8:43 PM, Laszlo Ersek >> > wrote:
>>> 
>>>On 07/21/16 20:07, Kinney, Michael D wrote:
 Laszlo,
 
 Try again...it was disabled for a short period of time.
>>> 
>>>Yes, it's working now.
>>> 
>>>I'll let you know when I'm done with the clipboard "wizardry" and the
>>>occasional reformatting :)
>>> 
>>>Thanks!
>>>Laszlo
>>> 
> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org
>>>] On Behalf Of Laszlo Ersek
> Sent: Thursday, July 21, 2016 10:33 AM
> To: Kinney, Michael D  michael.d.kin...@intel.com>>
> Cc: edk2-devel-01  edk2-de...@ml01.01.org>>
> Subject: Re: [edk2] Tianocore Bugzilla Server is now live
> 
> On 07/21/16 19:05, Kinney, Michael D wrote:
>> Laszlo,
>> 
>> Yes.  We can hold off disabling GitHub.  Let us know when you
>> are ready.
> 
> Thank you! However, github is rejecting my new comments in the
>> browser
> tabs that I have open already, and it rejects my fresh requests
>> for
> issue URLs.
> 
> Thanks,
> Laszlo
>>> 
>>>___
>>>edk2-devel mailing list
>>>edk2-devel@lists.01.org 
>>>https://lists.01.org/mailman/listinfo/edk2-devel
>>> 
>>> 
>>> 
>> 
>> 
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel

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


[edk2] Breaking change issue with NetworkPkg/Ip6Dxe/Ip6ConfigImlp.[c, h]

2016-08-02 Thread Larry Cleeton
This commit (fdc4b0b147b386e966e99893526181dfae9eaeef) changed a data structure 
that is stored in an NVRAM variable. 
See NetworkPkg/Ip6Dxe/Ip6ConfigImpl.[c,h]

This data structure:

typedef struct {
  UINT16Offset;
  UINTN DataSize;
  EFI_IP6_CONFIG_DATA_TYPE  DataType;
} IP6_CONFIG_DATA_RECORD;

Is now:

typedef struct {
  UINT16Offset;
  UINT32 DataSize;< changed size in 
64bit environments
  EFI_IP6_CONFIG_DATA_TYPE  DataType;
} IP6_CONFIG_DATA_RECORD;

Unfortunately with a 64bit implementation this current structure is now *not* 
compatible with an existing NVRAM variable written with the previous version of 
the structure. It's causing me considerable grief so I'm just sharing the 
discovery.  It would only impact you if you update some 64bit machine's 
firmware with a new version containing this change.

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


[edk2] [PATCH] CorebootModulePkg/SecCore: Adding NASM files in SecCore module

2016-08-02 Thread Maurice Ma
Ported MASM/GAS assembly files into NASM files and updated the
inf file to refer to NASM files.

This change has been tested with GCC 4.8 and VS2013 build.

Cc: Prince Agyeman 
Cc: Lee Leahy 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Maurice Ma 
---
 CorebootModulePkg/SecCore/Ia32/SecEntry.nasm | 72 +
 CorebootModulePkg/SecCore/Ia32/Stack.nasm| 78 
 CorebootModulePkg/SecCore/SecCore.inf|  6 +--
 3 files changed, 152 insertions(+), 4 deletions(-)
 create mode 100644 CorebootModulePkg/SecCore/Ia32/SecEntry.nasm
 create mode 100644 CorebootModulePkg/SecCore/Ia32/Stack.nasm

diff --git a/CorebootModulePkg/SecCore/Ia32/SecEntry.nasm 
b/CorebootModulePkg/SecCore/Ia32/SecEntry.nasm
new file mode 100644
index ..2b9b80549900
--- /dev/null
+++ b/CorebootModulePkg/SecCore/Ia32/SecEntry.nasm
@@ -0,0 +1,72 @@
+;--
+;
+; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
+; This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD 
License
+; which accompanies this distribution.  The full text of the license may be 
found at
+; http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+; Abstract:
+;
+;   Entry point for the coreboot UEFI payload.
+;
+;--
+
+SECTION .text
+
+; C Functions
+extern  ASM_PFX(SecStartup)
+
+; Pcds
+extern  ASM_PFX(PcdGet32 (PcdPayloadFdMemBase))
+
+;
+; SecCore Entry Point
+;
+; Processor is in flat protected mode
+;
+; @param[in]  EAX   Initial value of the EAX register (BIST: Built-in Self 
Test)
+; @param[in]  DI'BP': boot-strap processor, or 'AP': application processor
+; @param[in]  EBP   Pointer to the start of the Boot Firmware Volume
+;
+; @return None  This routine does not return
+;
+global ASM_PFX(_ModuleEntryPoint)
+ASM_PFX(_ModuleEntryPoint):
+  ;
+  ; Disable all the interrupts
+  ;
+  cli
+  ;
+  ; Construct the temporary memory at 0x8, length 0x1
+  ;
+  mov esp, (BASE_512KB + SIZE_64KB)
+
+  ;
+  ; Pass BFV into the PEI Core
+  ;
+  pushDWORD [ASM_PFX(PcdGet32 (PcdPayloadFdMemBase))]
+
+  ;
+  ; Pass stack base into the PEI Core
+  ;
+  pushBASE_512KB
+
+  ;
+  ; Pass stack size into the PEI Core
+  ;
+  pushSIZE_64KB
+
+  ;
+  ; Pass Control into the PEI Core
+  ;
+  callASM_PFX(SecStartup)
+
+  ;
+  ; Should never return
+  ;
+  jmp $
+
diff --git a/CorebootModulePkg/SecCore/Ia32/Stack.nasm 
b/CorebootModulePkg/SecCore/Ia32/Stack.nasm
new file mode 100644
index ..c877e52e52b8
--- /dev/null
+++ b/CorebootModulePkg/SecCore/Ia32/Stack.nasm
@@ -0,0 +1,78 @@
+;--
+;
+; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
+; This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD 
License
+; which accompanies this distribution.  The full text of the license may be 
found at
+; http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+; Abstract:
+;
+;   Switch the stack from temporary memory to permanent memory.
+;
+;--
+
+SECTION .text
+
+;--
+; VOID
+; EFIAPI
+; SecSwitchStack (
+;   UINT32   TemporaryMemoryBase,
+;   UINT32   PermenentMemoryBase
+;   );
+;--
+global ASM_PFX(SecSwitchStack)
+ASM_PFX(SecSwitchStack):
+;
+; Save three register: eax, ebx, ecx
+;
+push  eax
+push  ebx
+push  ecx
+push  edx
+
+;
+; !!CAUTION!! this function address's is pushed into stack after
+; migration of whole temporary memory, so need save it to permanent
+; memory at first!
+;
+
+mov   ebx,  [esp + 20]  ; Save the first parameter
+mov   ecx,  [esp + 24]  ; Save the second parameter
+
+;
+; Save this function's return address into permanent memory at first.
+; Then, Fixup the esp point to permanent memory
+;
+mov   eax,  esp
+sub   eax,  ebx
+add   eax,  ecx
+mov   edx,  [esp]   ; copy pushed register's value to 
permanent memory
+mov   [eax], edx
+mov   edx,  [esp + 4]
+mov   [eax + 4], edx
+mov   edx,  [esp + 8]
+mov   [eax + 8], 

Re: [edk2] [PATCH v2] OvmfPkg: use StatusCode Router and Handler from MdeModulePkg

2016-08-02 Thread Laszlo Ersek
On 08/02/16 20:23, Jordan Justen wrote:
> On 2016-08-02 10:25:10, Cinnamon Shia wrote:
>> In the Platform Init v1.4a spec,
>> - Volume 1 "4.7 Status Code Service" defines the
>>   EFI_PEI_SERVICES.ReportStatusCode() service,
>> - Volume 1 "6.3.5 Status Code PPI (Optional)" defines the
>>   EFI_PEI_PROGRESS_CODE_PPI (equivalent to the above),
>> - Volume 2 "14.2 Status Code Runtime Protocol" defines the
>>   EFI_STATUS_CODE_PROTOCOL.
>>
>> These allow PEIMs and DXE (and later) modules to report status codes.
>>
>> Currently OvmfPkg uses modules from under "IntelFrameworkModulePkg/
>> Universal/StatusCode/", which produce the above abstractions (PPI and
>> PROTOCOL) directly, and write the status codes, as they are reported,
>> to the serial port or to a memory buffer. This is called "handling"
>> the status codes.
>>
>> In the Platform Init v1.4a spec,
>> - Volume 3 "7.2.2 Report Status Code Handler PPI" defines
>>   EFI_PEI_RSC_HANDLER_PPI,
>> - Volume 3 "7.2.1 Report Status Code Handler Protocol" defines
>>   EFI_RSC_HANDLER_PROTOCOL.
>>
>> These allow several PEIMs and runtime DXE drivers to register callbacks
>> for status code handling.
>>
>> MdeModulePkg offers a PEIM under
>> "MdeModulePkg/Universal/ReportStatusCodeRouter/Pei" that produces both
>> EFI_PEI_PROGRESS_CODE_PPI and EFI_PEI_RSC_HANDLER_PPI, and a runtime DXE
>> driver under "MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe"
>> that produces both EFI_STATUS_CODE_PROTOCOL and EFI_RSC_HANDLER_PROTOCOL.
>>
>> MdeModulePkg also offers status code handler modules under MdeModulePkg/
>> Universal/StatusCodeHandler/ that depend on EFI_PEI_RSC_HANDLER_PPI and
>> EFI_RSC_HANDLER_PROTOCOL, respectively.
>>
>> The StatusCodeHandler modules register themselves with ReportStatusCodeRouter
>> through EFI_PEI_RSC_HANDLER_PPI / EFI_RSC_HANDLER_PROTOCOL. When another
>> module reports a status code through EFI_PEI_PROGRESS_CODE_PPI /
>> EFI_STATUS_CODE_PROTOCOL, it reaches the phase-matching 
>> ReportStatusCodeRouter
>> module first, which in turn passes the status code to the pre-registered,
>> phase-matching StatusCodeHandler module.
>>
>> The status code handling in the StatusCodeHandler modules is identical
>> to the one currently provided by the IntelFrameworkModulePkg modules.
>> Replace the IntelFareworkModulePkg modules with the MdeModulePkg ones,
>> so we can decrease our dependency on IntelFareworkModulePkg.
> 
> Noting two typos of 'Farework' here. We can fix during commit.

Yeah, that's just more mess from me. I should probably not propose
commit messages at 3 AM :)

> Reviewed-by: Jordan Justen 
> 
> I'll give Laszlo some time to respond too since he's already spent
> some time on it previously.

Thank you.

[jordan.l.jus...@intel.com: point out IntelFareworkModulePkg typos]
Reviewed-by: Jordan Justen 
[ler...@redhat.com: rewrap to 74 cols; fix IntelFareworkModulePkg typos]
Reviewed-by: Laszlo Ersek 
Regression-tested-by: Laszlo Ersek 

Commit a6d594c5fabd.

I also closed .

Thank you Cinnamon for the contribution!

Cheers
Laszlo

> 
> -Jordan
> 
>>
>> Contributed-under: TianoCore Contribution Agreement 1.0
>> Signed-off-by: Cinnamon Shia 
>> Suggested-by: Liming Gao 
>> Fixes: https://tianocore.acgmultimedia.com/show_bug.cgi?id=63
>> ---
>>  OvmfPkg/OvmfPkgIa32.dsc| 7 +--
>>  OvmfPkg/OvmfPkgIa32.fdf| 7 +--
>>  OvmfPkg/OvmfPkgIa32X64.dsc | 7 +--
>>  OvmfPkg/OvmfPkgIa32X64.fdf | 7 +--
>>  OvmfPkg/OvmfPkgX64.dsc | 7 +--
>>  OvmfPkg/OvmfPkgX64.fdf | 7 +--
>>  6 files changed, 30 insertions(+), 12 deletions(-)
>>
>> diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
>> index 8af3267..aeb87b9 100644
>> --- a/OvmfPkg/OvmfPkgIa32.dsc
>> +++ b/OvmfPkg/OvmfPkgIa32.dsc
>> @@ -2,6 +2,7 @@
>>  #  EFI/Framework Open Virtual Machine Firmware (OVMF) platform
>>  #
>>  #  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
>> +#  (C) Copyright 2016 Hewlett Packard Enterprise Development LP
>>  #
>>  #  This program and the accompanying materials
>>  #  are licensed and made available under the terms and conditions of the 
>> BSD License
>> @@ -497,7 +498,8 @@
>>  
>>PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
>>}
>> -  IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf
>> +  
>> MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf
>> +  MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf
>>MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf {
>>  
>>PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
>> @@ -534,7 +536,8 @@
>>DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
>>}
>>  
>> -  
>> IntelFrameworkModulePkg/Universal/StatusCode/RuntimeDxe/StatusCodeRuntimeDxe.inf
>> +  

Re: [edk2] Tianocore Bugzilla Server is now live

2016-08-02 Thread Michael Zimmermann
How are security issues treated in UEFI anyway?
Are they kept a secret forever or just for a specific time span?

A reason for keeping them a secret forever(while pushing
unsuspicious fixes) probably would be the fact that most UEFI systems don't
get updated.

Thanks
Michael

On Tue, Aug 2, 2016 at 9:34 PM, Laszlo Ersek  wrote:

> On 08/02/16 21:10, Kinney, Michael D wrote:
> > Michael,
> >
> > I am open to suggestions on this topic.
> >
> > If there is a strong opinion that we need to protect specific fields
> > from being modified, then we can look into updating the configuration.
> >
> > I think with Bugzilla change history and edk2-bugs mailing list, we can
> > all see the changes to any issue, so even if someone does do an
> > incorrect edit, I think we can put it back.
>
> Does "editbugs" include changing the product from "Tianocore Security
> Issues" to something else, possibly exposing the security issue to the
> world?
>
> Hm... It probably doesn't matter. If a security issue can be looked at
> (which is a pre-requisite for the product field to be changed) by anyone
> in the first place, then they can expose the contents to the world in
> other ways too. :)
>
> So I think trusting all registered accounts with "editbugs" is a good
> starting point too.
>
> Thanks
> Laszlo
>
>
> > *From:*Michael Zimmermann [mailto:sigmaepsilo...@gmail.com]
> > *Sent:* Tuesday, August 2, 2016 11:57 AM
> > *To:* Laszlo Ersek 
> > *Cc:* Kinney, Michael D ; edk2-devel-01
> > 
> > *Subject:* Re: [edk2] Tianocore Bugzilla Server is now live
> >
> >
> >
> > Is it just my account or does everybody have the permission
> > "editbugs  Can edit all bug fields"?
> >
> >
> >
> > It sounds like this is something only moderators should be able to do.
> >
> >
> >
> > Thanks
> >
> > Michael
> >
> >
> >
> > On Thu, Jul 21, 2016 at 8:43 PM, Laszlo Ersek  > > wrote:
> >
> > On 07/21/16 20:07, Kinney, Michael D wrote:
> > > Laszlo,
> > >
> > > Try again...it was disabled for a short period of time.
> >
> > Yes, it's working now.
> >
> > I'll let you know when I'm done with the clipboard "wizardry" and the
> > occasional reformatting :)
> >
> > Thanks!
> > Laszlo
> >
> > >> -Original Message-
> > >> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org
> > ] On Behalf Of Laszlo Ersek
> > >> Sent: Thursday, July 21, 2016 10:33 AM
> > >> To: Kinney, Michael D >
> > >> Cc: edk2-devel-01 >
> > >> Subject: Re: [edk2] Tianocore Bugzilla Server is now live
> > >>
> > >> On 07/21/16 19:05, Kinney, Michael D wrote:
> > >>> Laszlo,
> > >>>
> > >>> Yes.  We can hold off disabling GitHub.  Let us know when you
> are ready.
> > >>
> > >> Thank you! However, github is rejecting my new comments in the
> browser
> > >> tabs that I have open already, and it rejects my fresh requests
> for
> > >> issue URLs.
> > >>
> > >> Thanks,
> > >> Laszlo
> >
> > ___
> > edk2-devel mailing list
> > edk2-devel@lists.01.org 
> > https://lists.01.org/mailman/listinfo/edk2-devel
> >
> >
> >
>
>
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] Tianocore Bugzilla Server is now live

2016-08-02 Thread Laszlo Ersek
On 08/02/16 21:10, Kinney, Michael D wrote:
> Michael,
> 
> I am open to suggestions on this topic.
> 
> If there is a strong opinion that we need to protect specific fields
> from being modified, then we can look into updating the configuration.
> 
> I think with Bugzilla change history and edk2-bugs mailing list, we can
> all see the changes to any issue, so even if someone does do an
> incorrect edit, I think we can put it back.

Does "editbugs" include changing the product from "Tianocore Security
Issues" to something else, possibly exposing the security issue to the
world?

Hm... It probably doesn't matter. If a security issue can be looked at
(which is a pre-requisite for the product field to be changed) by anyone
in the first place, then they can expose the contents to the world in
other ways too. :)

So I think trusting all registered accounts with "editbugs" is a good
starting point too.

Thanks
Laszlo


> *From:*Michael Zimmermann [mailto:sigmaepsilo...@gmail.com]
> *Sent:* Tuesday, August 2, 2016 11:57 AM
> *To:* Laszlo Ersek 
> *Cc:* Kinney, Michael D ; edk2-devel-01
> 
> *Subject:* Re: [edk2] Tianocore Bugzilla Server is now live
> 
>  
> 
> Is it just my account or does everybody have the permission
> "editbugs  Can edit all bug fields"?
> 
>  
> 
> It sounds like this is something only moderators should be able to do.
> 
>  
> 
> Thanks
> 
> Michael
> 
>  
> 
> On Thu, Jul 21, 2016 at 8:43 PM, Laszlo Ersek  > wrote:
> 
> On 07/21/16 20:07, Kinney, Michael D wrote:
> > Laszlo,
> >
> > Try again...it was disabled for a short period of time.
> 
> Yes, it's working now.
> 
> I'll let you know when I'm done with the clipboard "wizardry" and the
> occasional reformatting :)
> 
> Thanks!
> Laszlo
> 
> >> -Original Message-
> >> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org
> ] On Behalf Of Laszlo Ersek
> >> Sent: Thursday, July 21, 2016 10:33 AM
> >> To: Kinney, Michael D  >
> >> Cc: edk2-devel-01  >
> >> Subject: Re: [edk2] Tianocore Bugzilla Server is now live
> >>
> >> On 07/21/16 19:05, Kinney, Michael D wrote:
> >>> Laszlo,
> >>>
> >>> Yes.  We can hold off disabling GitHub.  Let us know when you are 
> ready.
> >>
> >> Thank you! However, github is rejecting my new comments in the browser
> >> tabs that I have open already, and it rejects my fresh requests for
> >> issue URLs.
> >>
> >> Thanks,
> >> Laszlo
> 
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org 
> https://lists.01.org/mailman/listinfo/edk2-devel
> 
>  
> 

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


Re: [edk2] Foreign keyboard support in UEFI

2016-08-02 Thread Aaron . Pop
Hi Senthil,

Multi language keyboards support should be pretty transparent to an 
application. The simple text input protocols are designed to return a 
unicode character, and the protocols leave the mapping of keypress into 
the current keyboard layout to the system firmware.  Keyboard layouts are 
installed into the Hii database, and then a set keyboard layout call is 
made to tell the system which keyboard layout to use. Each regional 
keyboard has a different layout (
https://msdn.microsoft.com/en-us/goglobal/bb964651.aspx).  The UEFI 
specification (section 31.2.4) maps a keyboard into an enumerated value 
(EFI_KEY in MdePkg\Include\Uefi\UefiInternalFormRepresentation.h) and that 
enumerated value is used as an index into the keyboard layout data to 
return a unicode character for a specific keypress. 

If you are not getting a valid return character when you press a key on a 
usb keyboard, then there is a chance that the UsbKbDxe driver does not 
consider the key you pressed as a valid Usb key for the given keyboard 
layout.  USB keyboards return a Usage ID for a given key press (
http://www.usb.org/developers/hidpage/Hut1_12v2.pdf).  The EDK2 Usb 
keyboard driver (MdeModulePkg/Bus/Usb/UsbKbDxe) retrieves the USB usage id 
and translates it into an EFI_KEY_DATA entry by using the tables in the 
top of the Keyboard.c file (EfiKeyToUsbKeyCodeConvertionTable and 
mUsbKeyboardLayoutBin).  It is possible that your system does not 
correctly map the hid usage id to a valid EFI_KEY enum based on the 
current keyboard mapping layout. 

I hope this gives you enough information to start to figure out your 
issue.





From:   
To: 
Date:   08/01/2016 09:53 PM
Subject:[edk2] Foreign keyboard support in UEFI
Sent by:"edk2-devel" 



Hi,
Any one shed some light on supporting multi language key board  support on 
 UEFI application? Scan code received from 
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL not returns  value for
certain keys in  German/Arabic USB keyboard. We are also not sure in 
mapping UEFI code from EFI_HII_DATABASE_PROTOCOL.GetKeyBoardLayOut()).


Thanks
Senthil





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


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


Re: [edk2] Tianocore Bugzilla Server is now live

2016-08-02 Thread Laszlo Ersek
On 08/02/16 20:57, Michael Zimmermann wrote:
> Is it just my account or does everybody have the permission "editbugsCan
> edit all bug fields"?
> 
> It sounds like this is something only moderators should be able to do.

Indeed I noticed this permission when I last looked (in the "whine" thread).

I think it might make sense to restrict this permission to package
maintainers. And, I think "refinements" beyond that should not be
necessary -- I for one certainly would like to be able to edit all
bugzilla fields, regardless of their current values! :)

Thanks
Laszlo

> 
> Thanks
> Michael
> 
> On Thu, Jul 21, 2016 at 8:43 PM, Laszlo Ersek  > wrote:
> 
> On 07/21/16 20:07, Kinney, Michael D wrote:
> > Laszlo,
> >
> > Try again...it was disabled for a short period of time.
> 
> Yes, it's working now.
> 
> I'll let you know when I'm done with the clipboard "wizardry" and the
> occasional reformatting :)
> 
> Thanks!
> Laszlo
> 
> >> -Original Message-
> >> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org
> ] On Behalf Of Laszlo Ersek
> >> Sent: Thursday, July 21, 2016 10:33 AM
> >> To: Kinney, Michael D  >
> >> Cc: edk2-devel-01  >
> >> Subject: Re: [edk2] Tianocore Bugzilla Server is now live
> >>
> >> On 07/21/16 19:05, Kinney, Michael D wrote:
> >>> Laszlo,
> >>>
> >>> Yes.  We can hold off disabling GitHub.  Let us know when you are 
> ready.
> >>
> >> Thank you! However, github is rejecting my new comments in the browser
> >> tabs that I have open already, and it rejects my fresh requests for
> >> issue URLs.
> >>
> >> Thanks,
> >> Laszlo
> 
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org 
> https://lists.01.org/mailman/listinfo/edk2-devel
> 
> 

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


Re: [edk2] Tianocore Bugzilla Server is now live

2016-08-02 Thread Kinney, Michael D
Michael,

I am open to suggestions on this topic.

If there is a strong opinion that we need to protect specific fields from being 
modified, then we can look into updating the configuration.

I think with Bugzilla change history and edk2-bugs mailing list, we can all see 
the changes to any issue, so even if someone does do an incorrect edit, I think 
we can put it back.

Mike


From: Michael Zimmermann [mailto:sigmaepsilo...@gmail.com]
Sent: Tuesday, August 2, 2016 11:57 AM
To: Laszlo Ersek 
Cc: Kinney, Michael D ; edk2-devel-01 

Subject: Re: [edk2] Tianocore Bugzilla Server is now live

Is it just my account or does everybody have the permission "editbugs  Can 
edit all bug fields"?

It sounds like this is something only moderators should be able to do.

Thanks
Michael

On Thu, Jul 21, 2016 at 8:43 PM, Laszlo Ersek 
> wrote:
On 07/21/16 20:07, Kinney, Michael D wrote:
> Laszlo,
>
> Try again...it was disabled for a short period of time.

Yes, it's working now.

I'll let you know when I'm done with the clipboard "wizardry" and the
occasional reformatting :)

Thanks!
Laszlo

>> -Original Message-
>> From: edk2-devel 
>> [mailto:edk2-devel-boun...@lists.01.org]
>>  On Behalf Of Laszlo Ersek
>> Sent: Thursday, July 21, 2016 10:33 AM
>> To: Kinney, Michael D 
>> >
>> Cc: edk2-devel-01 >
>> Subject: Re: [edk2] Tianocore Bugzilla Server is now live
>>
>> On 07/21/16 19:05, Kinney, Michael D wrote:
>>> Laszlo,
>>>
>>> Yes.  We can hold off disabling GitHub.  Let us know when you are ready.
>>
>> Thank you! However, github is rejecting my new comments in the browser
>> tabs that I have open already, and it rejects my fresh requests for
>> issue URLs.
>>
>> Thanks,
>> Laszlo
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

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


Re: [edk2] Tianocore Bugzilla Server is now live

2016-08-02 Thread Michael Zimmermann
Is it just my account or does everybody have the permission "editbugs Can
edit all bug fields"?

It sounds like this is something only moderators should be able to do.

Thanks
Michael

On Thu, Jul 21, 2016 at 8:43 PM, Laszlo Ersek  wrote:

> On 07/21/16 20:07, Kinney, Michael D wrote:
> > Laszlo,
> >
> > Try again...it was disabled for a short period of time.
>
> Yes, it's working now.
>
> I'll let you know when I'm done with the clipboard "wizardry" and the
> occasional reformatting :)
>
> Thanks!
> Laszlo
>
> >> -Original Message-
> >> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
> Laszlo Ersek
> >> Sent: Thursday, July 21, 2016 10:33 AM
> >> To: Kinney, Michael D 
> >> Cc: edk2-devel-01 
> >> Subject: Re: [edk2] Tianocore Bugzilla Server is now live
> >>
> >> On 07/21/16 19:05, Kinney, Michael D wrote:
> >>> Laszlo,
> >>>
> >>> Yes.  We can hold off disabling GitHub.  Let us know when you are
> ready.
> >>
> >> Thank you! However, github is rejecting my new comments in the browser
> >> tabs that I have open already, and it rejects my fresh requests for
> >> issue URLs.
> >>
> >> Thanks,
> >> Laszlo
>
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
>
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [Patch v5 00/48] MP Initialize Library

2016-08-02 Thread Kinney, Michael D
Jeff,

All the updates look good to me.  There are 2 copyright date updates 
missing in the SourceLevelDebugPkg that I replied to separately.

I have tested this on Galileo Gen 2 with SOURCE_DEBUG_ENABLE on and off
and also tested OS boot and ACPI S3.

Series Reviewed-By: Michael Kinney 

Best regards,

Mike

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Jeff 
> Fan
> Sent: Tuesday, August 2, 2016 1:59 AM
> To: edk2-devel@lists.01.org
> Subject: [edk2] [Patch v5 00/48] MP Initialize Library
> 
> We add MP Initialize Library defined in 
> UefiCpuPkg/Include/Library/MpInitLib.h.
> It will provide basic functionalities of MP services and could be consumed by
> CPU MP PEI and CPU MP DXE to produce CPU MP PPI and CPU MP Protocol. Then most
> of code could be shared between PEI and DXE modules.
> 
> PeiMpInitLib and DxeMpInitLib are added to make the CpuMpPei and CpuDxe more
> simply.
> 
> I also updated the Ovmf Platform and Quark platform to consume MP Initialize
> library.
> 
> Thanks Laszlo to verify on OVMF and Mike to verify on Quark.
> 
> v5:
>   1. Update Patches #1, #5, #10 - #12, #14, #16 - #18, #20, #21, #28, #29, 
> #37,
> #43.
>   2. Add Patches #44, #48
>   (Please see the patches commit log for more details)
> 
> v4:
>   1. Update Patches #2 - #6, #10, #15, #28, #30, #31, #33, #34, #38, #41, #43.
>   2. Add Patches #7, #8, #42, #44 - #46.
>   3. Add Reviewed-by: Laszlo Ersek  on Patches #1, #2.
>   (Please see the patches commit log for more details)
> 
> v3:
>   1. Update Patch #2, #4 - #8, #28, #33, #36, #38 per Giri's comments to
>  a. Update SDM date to June, 2016
>  b. Mention BCD format in CPU_MICROCODE_DATE
>  c. Rename ProcessorChecksum to Checksum to match SDM.
>  d. Add whitespace after MpInitLibInitialize
>  e. Rename MpInitLibSwitchBsp to MpInitLibSwitchBSP to match PI spec.
>  f. Rename NumApsExecutingLoction to NumApsExecutingLocation
>  g. Add whitespace after ; in .nasm file
>  h. Rename *RellocateAp* to *RelocateAp*
>   2. Update Patch #16, #17, #29-#32 to
>  a. Use CamelCase for mStopCheckAllApsStatus and 
> CheckAndUpdateApsStatus().
>   3. Update Patch #36 and #39 to
>  a. Add PeiMpInitLib instance in UefiCpuPkg.dsc
>  b. Add DxeMpInitLib instance in UefiCpuPkg.dsc
>   4. Update Patch #39 and #40 to
>  a. move the code of consuming MP Initialize library from patch #40 to
>  patch #39.
>   5. Update Patch #1, #3 - #8, #16 to
>  a. Add Reviewed-by: Giri P Mudusuru 
> 
> I fork the whole tree with the updated v3 patches
> at https://github.com/vanjeff/edk2/tree/MpInitLibV5 for review.
> 
> 
> Jeff Fan (48):
>   UefiCpuPkg/LocalApic.h: Remove duplicated/conflicted definitions
>   UefiCpuPkg/MpInitLib: Add microcode definitions defined in IA32 SDM
>   UefiCpuPkg/CpuS3DataDxe: Move StartupVector allocation to EndOfDxe()
>   UefiCpuPkg/MpInitLib: Add MP Initialize library class definition
>   UefiCpuPkg/MpInitLib: Add two instances PeiMpInitLib and DxeMpInitLib
>   UefiCpuPkg/MpInitLib: Add AP assembly code and MP_CPU_EXCHANGE_INFO
>   UefiCpuPkg/MpInitLib: Fix typo and clean up the code
>   UefiCpuPkg/MpInitLib: Add EnableExecuteDisable in MP_CPU_EXCHANGE_INFO
>   UefiCpuPkg/MpInitLib: Add AsmRelocateApLoop() assembly code
>   UefiCpuPkg/MpInitLib: Add MP_ASSEMBLY_ADDRESS_MAP
>   UefiCpuPkg/MpInitLib: Get ApLoopMode and MointorFilter size
>   UefiCpuPkg/MpInitLib: Allocate and initialize memory of MP Data buffer
>   UefiCpuPkg/MpInitLib: Initialize CPU_AP_DATA for CPU APs
>   UefiCpuPkg/MpInitLib: Add CPU_VOLATILE_REGISTERS & worker functions
>   UefiCpuPkg/MpInitLib: Add MicrocodeDetect() and load microcode on BSP
>   UefiCpuPkg/MpInitLib: Save CPU MP Data pointer
>   UefiCpuPkg/MpInitLib: Register one End of PEI callback function
>   UefiCpuPkg/MpInitLib: Register one period event to check APs status
>   UefiCpuPkg/MpInitLib: Allocate AP reset vector buffer under 1MB
>   UefiCpuPkg/MpInitLib: Add ApWakeupFunction() executed by assembly code
>   UefiCpuPkg/MpInitLib: Fill MP_CPU_EXCHANGE_INFO fields
>   UefiCpuPkg/MpInitLib: Add WakeUpAP()
>   UefiCpuPkg/MpInitLib: Send INIT-SIPI-SIPI to get processor count
>   UefiCpuPkg/MpInitLib: Enable x2APIC mode on BSP/APs
>   UefiCpuPkg/MpInitLib: Sort processor by ascending order of APIC ID
>   UefiCpuPkg/MpInitLib: Skip collect processor count if GUIDed HOB exist
>   UefiCpuPkg/MpInitLib: Implementation of
> MpInitLibGetNumberOfProcessors()
>   UefiCpuPkg/MpInitLib: Implementation of MpInitLibGetProcessorInfo()
>   UefiCpuPkg/MpInitLib: Implementation of MpInitLibWhoAmI()
>   UefiCpuPkg/MpInitLib: Implementation of MpInitLibSwitchBSP()
>   UefiCpuPkg/MpInitLib: Implementation of MpInitLibEnableDisableAP()
>   UefiCpuPkg/MpInitLib: Check APs Status and update APs status
>   UefiCpuPkg/MpInitLib: Implementation of 

Re: [edk2] Build traceback with new CLANG35 toolset

2016-08-02 Thread Bruce Cran

On 8/2/2016 12:53 PM, Ard Biesheuvel wrote:


CLANG35 is not new, and currently only supports ARM and AARCH64


Oops - thanks. I was thinking of CLANG38 that hasn't been committed yet.

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


[edk2] Build traceback with new CLANG35 toolset

2016-08-02 Thread Bruce Cran
I was just testing the new GCC5 and CLANG35 toolsets that have landed in 
git master: GCC5 works perfectly, but with CLANG35 I get the following 
log and traceback:


Build environment: Linux-4.6.4-2-default-x86_64-with-SuSE-20160728-x86_64
Build start time: 12:12:40, Aug.02 2016

WORKSPACE= /mnt/user/workspace/edk2
ECP_SOURCE   = /mnt/user/workspace/edk2/EdkCompatibilityPkg
EDK_SOURCE   = /mnt/user/workspace/edk2/EdkCompatibilityPkg
EFI_SOURCE   = /mnt/user/workspace/edk2/EdkCompatibilityPkg
EDK_TOOLS_PATH   = /mnt/user/workspace/edk2/BaseTools

Architecture(s)  = X64
Build target = RELEASE
Toolchain= CLANG35

Active Platform  = /mnt/user/workspace/edk2/MyPkg/MyPkg.dsc

Processing meta-data .

build.py...
 : error C0DE: Unknown fatal error when processing 
[/mnt/user/workspace/edk2/MyPkg/MyPkg.inf]


(Please send email to edk2-devel@lists.01.org for help, attaching 
following call stack trace!)


(Python 2.7.12 on linux2) Traceback (most recent call last):
  File 
"/mnt/user/workspace/edk2/BaseTools/BinWrappers/PosixLike/../../Source/Python/build/build.py", 
line 2270, in Main

MyBuild.Launch()
  File 
"/mnt/user/workspace/edk2/BaseTools/BinWrappers/PosixLike/../../Source/Python/build/build.py", 
line 2022, in Launch

self._MultiThreadBuildPlatform()
  File 
"/mnt/user/workspace/edk2/BaseTools/BinWrappers/PosixLike/../../Source/Python/build/build.py", 
line 1857, in _MultiThreadBuildPlatform

Ma.CreateMakeFile(True)
  File 
"/mnt/user/workspace/edk2/BaseTools/Source/Python/AutoGen/AutoGen.py", 
line 3923, in CreateMakeFile

if Makefile.Generate():
  File 
"/mnt/user/workspace/edk2/BaseTools/Source/Python/AutoGen/GenMake.py", 
line 184, in Generate

FileContent = self._TEMPLATE_.Replace(self._TemplateDict)
  File 
"/mnt/user/workspace/edk2/BaseTools/Source/Python/AutoGen/GenMake.py", 
line 525, in _CreateTemplateDict

RespDict = self.CommandExceedLimit()
  File 
"/mnt/user/workspace/edk2/BaseTools/Source/Python/AutoGen/GenMake.py", 
line 716, in CommandExceedLimit

Str = self._AutoGenObject._BuildOption[Tool]['FLAGS']
KeyError: 'FLAGS'

--
Bruce

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


Re: [edk2] [PATCH v2] OvmfPkg: use StatusCode Router and Handler from MdeModulePkg

2016-08-02 Thread Jordan Justen
On 2016-08-02 10:25:10, Cinnamon Shia wrote:
> In the Platform Init v1.4a spec,
> - Volume 1 "4.7 Status Code Service" defines the
>   EFI_PEI_SERVICES.ReportStatusCode() service,
> - Volume 1 "6.3.5 Status Code PPI (Optional)" defines the
>   EFI_PEI_PROGRESS_CODE_PPI (equivalent to the above),
> - Volume 2 "14.2 Status Code Runtime Protocol" defines the
>   EFI_STATUS_CODE_PROTOCOL.
> 
> These allow PEIMs and DXE (and later) modules to report status codes.
> 
> Currently OvmfPkg uses modules from under "IntelFrameworkModulePkg/
> Universal/StatusCode/", which produce the above abstractions (PPI and
> PROTOCOL) directly, and write the status codes, as they are reported,
> to the serial port or to a memory buffer. This is called "handling"
> the status codes.
> 
> In the Platform Init v1.4a spec,
> - Volume 3 "7.2.2 Report Status Code Handler PPI" defines
>   EFI_PEI_RSC_HANDLER_PPI,
> - Volume 3 "7.2.1 Report Status Code Handler Protocol" defines
>   EFI_RSC_HANDLER_PROTOCOL.
> 
> These allow several PEIMs and runtime DXE drivers to register callbacks
> for status code handling.
> 
> MdeModulePkg offers a PEIM under
> "MdeModulePkg/Universal/ReportStatusCodeRouter/Pei" that produces both
> EFI_PEI_PROGRESS_CODE_PPI and EFI_PEI_RSC_HANDLER_PPI, and a runtime DXE
> driver under "MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe"
> that produces both EFI_STATUS_CODE_PROTOCOL and EFI_RSC_HANDLER_PROTOCOL.
> 
> MdeModulePkg also offers status code handler modules under MdeModulePkg/
> Universal/StatusCodeHandler/ that depend on EFI_PEI_RSC_HANDLER_PPI and
> EFI_RSC_HANDLER_PROTOCOL, respectively.
> 
> The StatusCodeHandler modules register themselves with ReportStatusCodeRouter
> through EFI_PEI_RSC_HANDLER_PPI / EFI_RSC_HANDLER_PROTOCOL. When another
> module reports a status code through EFI_PEI_PROGRESS_CODE_PPI /
> EFI_STATUS_CODE_PROTOCOL, it reaches the phase-matching ReportStatusCodeRouter
> module first, which in turn passes the status code to the pre-registered,
> phase-matching StatusCodeHandler module.
> 
> The status code handling in the StatusCodeHandler modules is identical
> to the one currently provided by the IntelFrameworkModulePkg modules.
> Replace the IntelFareworkModulePkg modules with the MdeModulePkg ones,
> so we can decrease our dependency on IntelFareworkModulePkg.

Noting two typos of 'Farework' here. We can fix during commit.

Reviewed-by: Jordan Justen 

I'll give Laszlo some time to respond too since he's already spent
some time on it previously.

-Jordan

> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Cinnamon Shia 
> Suggested-by: Liming Gao 
> Fixes: https://tianocore.acgmultimedia.com/show_bug.cgi?id=63
> ---
>  OvmfPkg/OvmfPkgIa32.dsc| 7 +--
>  OvmfPkg/OvmfPkgIa32.fdf| 7 +--
>  OvmfPkg/OvmfPkgIa32X64.dsc | 7 +--
>  OvmfPkg/OvmfPkgIa32X64.fdf | 7 +--
>  OvmfPkg/OvmfPkgX64.dsc | 7 +--
>  OvmfPkg/OvmfPkgX64.fdf | 7 +--
>  6 files changed, 30 insertions(+), 12 deletions(-)
> 
> diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
> index 8af3267..aeb87b9 100644
> --- a/OvmfPkg/OvmfPkgIa32.dsc
> +++ b/OvmfPkg/OvmfPkgIa32.dsc
> @@ -2,6 +2,7 @@
>  #  EFI/Framework Open Virtual Machine Firmware (OVMF) platform
>  #
>  #  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
> +#  (C) Copyright 2016 Hewlett Packard Enterprise Development LP
>  #
>  #  This program and the accompanying materials
>  #  are licensed and made available under the terms and conditions of the BSD 
> License
> @@ -497,7 +498,8 @@
>  
>PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
>}
> -  IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf
> +  
> MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf
> +  MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf
>MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf {
>  
>PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
> @@ -534,7 +536,8 @@
>DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
>}
>  
> -  
> IntelFrameworkModulePkg/Universal/StatusCode/RuntimeDxe/StatusCodeRuntimeDxe.inf
> +  
> MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf
> +  
> MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf
>MdeModulePkg/Universal/PCD/Dxe/Pcd.inf  {
> 
>PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
> diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf
> index 1369734..b4b0a22 100644
> --- a/OvmfPkg/OvmfPkgIa32.fdf
> +++ b/OvmfPkg/OvmfPkgIa32.fdf
> @@ -2,6 +2,7 @@
>  #  Open Virtual Machine Firmware: FDF
>  #
>  #  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
> +#  (C) Copyright 2016 Hewlett Packard Enterprise Development LP
>  #
>  #  This program and 

[edk2] [PATCH v2] OvmfPkg: use StatusCode Router and Handler from MdeModulePkg

2016-08-02 Thread Cinnamon Shia
In the Platform Init v1.4a spec,
- Volume 1 "4.7 Status Code Service" defines the
  EFI_PEI_SERVICES.ReportStatusCode() service,
- Volume 1 "6.3.5 Status Code PPI (Optional)" defines the
  EFI_PEI_PROGRESS_CODE_PPI (equivalent to the above),
- Volume 2 "14.2 Status Code Runtime Protocol" defines the
  EFI_STATUS_CODE_PROTOCOL.

These allow PEIMs and DXE (and later) modules to report status codes.

Currently OvmfPkg uses modules from under "IntelFrameworkModulePkg/
Universal/StatusCode/", which produce the above abstractions (PPI and
PROTOCOL) directly, and write the status codes, as they are reported,
to the serial port or to a memory buffer. This is called "handling"
the status codes.

In the Platform Init v1.4a spec,
- Volume 3 "7.2.2 Report Status Code Handler PPI" defines
  EFI_PEI_RSC_HANDLER_PPI,
- Volume 3 "7.2.1 Report Status Code Handler Protocol" defines
  EFI_RSC_HANDLER_PROTOCOL.

These allow several PEIMs and runtime DXE drivers to register callbacks
for status code handling.

MdeModulePkg offers a PEIM under
"MdeModulePkg/Universal/ReportStatusCodeRouter/Pei" that produces both
EFI_PEI_PROGRESS_CODE_PPI and EFI_PEI_RSC_HANDLER_PPI, and a runtime DXE
driver under "MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe"
that produces both EFI_STATUS_CODE_PROTOCOL and EFI_RSC_HANDLER_PROTOCOL.

MdeModulePkg also offers status code handler modules under MdeModulePkg/
Universal/StatusCodeHandler/ that depend on EFI_PEI_RSC_HANDLER_PPI and
EFI_RSC_HANDLER_PROTOCOL, respectively.

The StatusCodeHandler modules register themselves with ReportStatusCodeRouter
through EFI_PEI_RSC_HANDLER_PPI / EFI_RSC_HANDLER_PROTOCOL. When another
module reports a status code through EFI_PEI_PROGRESS_CODE_PPI /
EFI_STATUS_CODE_PROTOCOL, it reaches the phase-matching ReportStatusCodeRouter
module first, which in turn passes the status code to the pre-registered,
phase-matching StatusCodeHandler module.

The status code handling in the StatusCodeHandler modules is identical
to the one currently provided by the IntelFrameworkModulePkg modules.
Replace the IntelFareworkModulePkg modules with the MdeModulePkg ones,
so we can decrease our dependency on IntelFareworkModulePkg.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Cinnamon Shia 
Suggested-by: Liming Gao 
Fixes: https://tianocore.acgmultimedia.com/show_bug.cgi?id=63
---
 OvmfPkg/OvmfPkgIa32.dsc| 7 +--
 OvmfPkg/OvmfPkgIa32.fdf| 7 +--
 OvmfPkg/OvmfPkgIa32X64.dsc | 7 +--
 OvmfPkg/OvmfPkgIa32X64.fdf | 7 +--
 OvmfPkg/OvmfPkgX64.dsc | 7 +--
 OvmfPkg/OvmfPkgX64.fdf | 7 +--
 6 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 8af3267..aeb87b9 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -2,6 +2,7 @@
 #  EFI/Framework Open Virtual Machine Firmware (OVMF) platform
 #
 #  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+#  (C) Copyright 2016 Hewlett Packard Enterprise Development LP
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD 
License
@@ -497,7 +498,8 @@
 
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
   }
-  IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf
+  
MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf
+  MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf
   MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf {
 
   PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
@@ -534,7 +536,8 @@
   DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
   }
 
-  
IntelFrameworkModulePkg/Universal/StatusCode/RuntimeDxe/StatusCodeRuntimeDxe.inf
+  
MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf
+  
MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf
   MdeModulePkg/Universal/PCD/Dxe/Pcd.inf  {

   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf
index 1369734..b4b0a22 100644
--- a/OvmfPkg/OvmfPkgIa32.fdf
+++ b/OvmfPkg/OvmfPkgIa32.fdf
@@ -2,6 +2,7 @@
 #  Open Virtual Machine Firmware: FDF
 #
 #  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+#  (C) Copyright 2016 Hewlett Packard Enterprise Development LP
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD 
License
@@ -154,7 +155,8 @@ APRIORI PEI {
 #
 INF  MdeModulePkg/Core/Pei/PeiMain.inf
 INF  MdeModulePkg/Universal/PCD/Pei/Pcd.inf
-INF  IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf
+INF  
MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf
+INF  MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf
 INF  

Re: [edk2] [Patch v5 01/48] UefiCpuPkg/LocalApic.h: Remove duplicated/conflicted definitions

2016-08-02 Thread Kinney, Michael D
Jeff,

The copyright dates need to be updated to 2016 in the following 2 files:

  SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
  SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugMp.c

With those updates,

Reviewed-by: Michael Kinney 

Mike

> -Original Message-
> From: Fan, Jeff
> Sent: Tuesday, August 2, 2016 1:59 AM
> To: edk2-devel@lists.01.org
> Cc: Kinney, Michael D ; Tian, Feng 
> ;
> Mudusuru, Giri P ; Laszlo Ersek 
> Subject: [Patch v5 01/48] UefiCpuPkg/LocalApic.h: Remove duplicated/conflicted
> definitions
> 
> #define MSR_IA32_APIC_BASE_ADDRESS is duplicated with #define 
> MSR_IA32_APIC_BASE
> defined in UefiCpuPkg/Include/Register/ArchitecturalMsr.h, so we could remove 
> it
> and update the modules to use MSR_IA32_APIC_BASE from ArchitecturalMsr.h.
> 
> Structure MSR_IA32_APIC_BASE conflicts with #define MSR_IA32_APIC_BASE defined
> in UefiCpuPkg/Include/Register/ArchitecturalMsr.h, so we could remove it and
> update the modules to use structure MSR_IA32_APIC_BASE_REGISTER from
> ArchitecturalMsr.h.
> 
> v5:
>   1. Update SourceLevelDebugPkg to use APIC Base MSR from ArchitecturalMsr.h.
> 
> Cc: Michael Kinney 
> Cc: Feng Tian 
> Cc: Giri P Mudusuru 
> Cc: Laszlo Ersek 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jeff Fan 
> Reviewed-by: Giri P Mudusuru 
> Reviewed-by: Laszlo Ersek 
> ---
>  .../DebugAgent/DebugAgentCommon/DebugAgent.h   |  1 +
>  .../Library/DebugAgent/DebugAgentCommon/DebugMp.c  |  5 ++-
>  UefiCpuPkg/CpuMpPei/CpuMpPei.h |  1 +
>  UefiCpuPkg/CpuMpPei/PeiMpServices.c| 20 -
>  UefiCpuPkg/Include/Register/LocalApic.h| 20 +
>  UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c | 29 ++--
>  .../BaseXApicX2ApicLib/BaseXApicX2ApicLib.c| 51 
> +++---
>  7 files changed, 58 insertions(+), 69 deletions(-)
> 
> diff --git 
> a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
> b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
> index 64e4c3e..18b93a3 100644
> --- a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
> +++ b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
> @@ -34,6 +34,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
> 
>  #include 
>  #include 
> diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugMp.c
> b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugMp.c
> index bdb6742..db9eb6a 100644
> --- a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugMp.c
> +++ b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugMp.c
> @@ -141,6 +141,8 @@ IsBsp (
>IN UINT32  ProcessorIndex
>)
>  {
> +  MSR_IA32_APIC_BASE_REGISTER  MsrApicBase;
> +
>//
>// If there are less than 2 CPUs detected, then the currently executing CPU
>// must be the BSP.  This avoids an access to an MSR that may not be 
> supported
> @@ -150,7 +152,8 @@ IsBsp (
>  return TRUE;
>}
> 
> -  if (AsmMsrBitFieldRead64 (MSR_IA32_APIC_BASE_ADDRESS, 8, 8) == 1) {
> +  MsrApicBase.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
> +  if (MsrApicBase.Bits.BSP == 1) {
>  if (mDebugMpContext.BspIndex != ProcessorIndex) {
>AcquireMpSpinLock ();
>mDebugMpContext.BspIndex = ProcessorIndex;
> diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.h b/UefiCpuPkg/CpuMpPei/CpuMpPei.h
> index b2e578b..0d1a14a 100644
> --- a/UefiCpuPkg/CpuMpPei/CpuMpPei.h
> +++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.h
> @@ -25,6 +25,7 @@
> 
>  #include 
>  #include 
> +#include 
> 
>  #include 
>  #include 
> diff --git a/UefiCpuPkg/CpuMpPei/PeiMpServices.c 
> b/UefiCpuPkg/CpuMpPei/PeiMpServices.c
> index e784377..e06fdf1 100644
> --- a/UefiCpuPkg/CpuMpPei/PeiMpServices.c
> +++ b/UefiCpuPkg/CpuMpPei/PeiMpServices.c
> @@ -1,7 +1,7 @@
>  /** @file
>Implementation of Multiple Processor PPI services.
> 
> -  Copyright (c) 2015, Intel Corporation. All rights reserved.
> +  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
>This program and the accompanying materials
>are licensed and made available under the terms and conditions of the BSD 
> License
>which accompanies this distribution.  The full text of the license may be 
> found at
> @@ -729,9 +729,9 @@ PeiSwitchBSP (
>IN  BOOLEAN  EnableOldBSP
>)
>  {
> -  PEI_CPU_MP_DATA *PeiCpuMpData;
> -  UINTN   CallerNumber;
> -  MSR_IA32_APIC_BASE  ApicBaseMsr;
> +  PEI_CPU_MP_DATA  *PeiCpuMpData;
> +  UINTNCallerNumber;
> +  MSR_IA32_APIC_BASE_REGISTER  ApicBaseMsr;
> 
>

Re: [edk2] [Patch v5 02/48] UefiCpuPkg/MpInitLib: Add microcode definitions defined in IA32 SDM

2016-08-02 Thread Mudusuru, Giri P
Reviewed-by: Giri P Mudusuru  

> -Original Message-
> From: Fan, Jeff
> Sent: Tuesday, August 2, 2016 1:59 AM
> To: edk2-devel@lists.01.org
> Cc: Kinney, Michael D ; Tian, Feng
> ; Mudusuru, Giri P ; Laszlo
> Ersek 
> Subject: [Patch v5 02/48] UefiCpuPkg/MpInitLib: Add microcode definitions
> defined in IA32 SDM
> 
> Add microcode definitions defined in Intel(R) 64 and IA-32 Architectures
> Software Developer's Manual Volume 3A, Section 9.11.
> 
> v4:
>   1. ProcessorSignature type changed to
> CPU_MICROCODE_PROCESSOR_SIGNATURE
>   2. Add pack(1) for structure CPU_MICROCODE_HEADER and
>  CPU_MICROCODE_EXTENDED_TABLE.
> v3:
>   1. Update SDM date to June, 2016
>   2. Mention BCD format in CPU_MICROCODE_DATE
>   3. Rename ProcessorChecksum to Checksum to match SDM.
> 
> Cc: Michael Kinney 
> Cc: Feng Tian 
> Cc: Giri P Mudusuru 
> Cc: Laszlo Ersek 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jeff Fan 
> Reviewed-by: Laszlo Ersek 
> ---
>  UefiCpuPkg/Include/Register/Microcode.h | 200
> 
>  1 file changed, 200 insertions(+)
>  create mode 100644 UefiCpuPkg/Include/Register/Microcode.h
> 
> diff --git a/UefiCpuPkg/Include/Register/Microcode.h
> b/UefiCpuPkg/Include/Register/Microcode.h
> new file mode 100644
> index 000..94529a1
> --- /dev/null
> +++ b/UefiCpuPkg/Include/Register/Microcode.h
> @@ -0,0 +1,200 @@
> +/** @file
> +  Microcode Definitions.
> +
> +  Microcode Definitions based on contents of the
> +  Intel(R) 64 and IA-32 Architectures Software Developer's Manual
> +Volume 3A, Section 9.11  Microcode Definitions
> +
> +  Copyright (c) 2016, Intel Corporation. All rights reserved.
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD
> License
> +  which accompanies this distribution.  The full text of the license may be 
> found
> at
> +  http://opensource.org/licenses/bsd-license.php
> +
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
> EXPRESS OR IMPLIED.
> +
> +  @par Specification Reference:
> +  Intel(R) 64 and IA-32 Architectures Software Developer's Manual, Volume 3A,
> +  June 2016, Chapter 9 Processor Management and Initialization, Section 9-11.
> +
> +**/
> +
> +#ifndef __MICROCODE_H__
> +#define __MICROCODE_H__
> +
> +///
> +/// CPU Microcode Date in BCD format
> +///
> +typedef union {
> +  struct {
> +UINT32   Year:16;
> +UINT32   Day:8;
> +UINT32   Month:8;
> +  } Bits;
> +  UINT32 Uint32;
> +} CPU_MICROCODE_DATE;
> +
> +///
> +/// CPU Microcode Processor Signature format
> +///
> +typedef union {
> +  struct {
> +UINT32   Stepping:4;
> +UINT32   Model:4;
> +UINT32   Family:4;
> +UINT32   Type:2;
> +UINT32   Reserved1:2;
> +UINT32   ExtendedModel:4;
> +UINT32   ExtendedFamily:8;
> +UINT32   Reserved2:4;
> +  } Bits;
> +  UINT32 Uint32;
> +} CPU_MICROCODE_PROCESSOR_SIGNATURE;
> +
> +#pragma pack (1)
> +
> +///
> +/// Microcode Update Format definition
> +///
> +typedef struct {
> +  ///
> +  /// Version number of the update header
> +  ///
> +  UINT32HeaderVersion;
> +  ///
> +  /// Unique version number for the update, the basis for the update
> +  /// signature provided by the processor to indicate the current update
> +  /// functioning within the processor. Used by the BIOS to authenticate
> +  /// the update and verify that the processor loads successfully. The
> +  /// value in this field cannot be used for processor stepping 
> identification
> +  /// alone. This is a signed 32-bit number.
> +  ///
> +  UINT32UpdateRevision;
> +  ///
> +  /// Date of the update creation in binary format: mmdd (e.g.
> +  /// 07/18/98 is 07181998H).
> +  ///
> +  CPU_MICROCODE_DATEDate;
> +  ///
> +  /// Extended family, extended model, type, family, model, and stepping
> +  /// of processor that requires this particular update revision (e.g.,
> +  /// 0650H). Each microcode update is designed specifically for a
> +  /// given extended family, extended model, type, family, model, and
> +  /// stepping of the processor.
> +  /// The BIOS uses the processor signature field in conjunction with the
> +  /// CPUID instruction to determine whether or not an update is
> +  /// appropriate to load on a processor. The information encoded within
> +  /// this field exactly corresponds to the bit representations returned by
> +  /// the CPUID instruction.
> +  ///
> +  CPU_MICROCODE_PROCESSOR_SIGNATURE ProcessorSignature;
> +  ///
> +  /// Checksum of Update Data and Header. Used to 

Re: [edk2] [PATCH 1/3] BaseTools GCC: move -c compiler flag to build rules

2016-08-02 Thread Ard Biesheuvel
On 2 August 2016 at 17:02, Ard Biesheuvel  wrote:
> On 2 August 2016 at 17:01, Leif Lindholm  wrote:
>> On Tue, Aug 02, 2016 at 04:39:30PM +0200, Ard Biesheuvel wrote:
>>> In order to be able to share the compiler flags with the linker (which
>>> is required for LTO since it involves the linker doing code generation
>>> based on the LTO bytecode), move the -c GCC argument to the build rules,
>>> and drop it from the GCC CC_FLAGS definitions in tools_def.
>>>
>>> Contributed-under: TianoCore Contribution Agreement 1.0
>>> Signed-off-by: Ard Biesheuvel 
>>> ---
>>>  BaseTools/Conf/build_rule.template | 16 +---
>>>  BaseTools/Conf/tools_def.template  | 10 +-
>>>  2 files changed, 14 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/BaseTools/Conf/build_rule.template 
>>> b/BaseTools/Conf/build_rule.template
>>> index 9adf3918e42e..7d9f8ca075c2 100644
>>> --- a/BaseTools/Conf/build_rule.template
>>> +++ b/BaseTools/Conf/build_rule.template
>>> @@ -130,7 +130,10 @@
>>>  
>>>  "$(CC)" /Fo${dst} $(CC_FLAGS) $(INC) ${src}
>>>
>>> -
>>> +
>>> +"$(CC)" $(CC_FLAGS) -c -o ${dst} $(INC) ${src}
>>> +
>>> +
>>
>> Apart from the slightly larger patch set, is there any reason not to
>> split out the RVCT handling here and fix up tools_def.template for it
>> too?
>>

OK, i get it now. That actually simplifies the patch, since I don't
need to split off RVCT in build_rules then
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH 1/3] BaseTools GCC: move -c compiler flag to build rules

2016-08-02 Thread Ard Biesheuvel
On 2 August 2016 at 17:01, Leif Lindholm  wrote:
> On Tue, Aug 02, 2016 at 04:39:30PM +0200, Ard Biesheuvel wrote:
>> In order to be able to share the compiler flags with the linker (which
>> is required for LTO since it involves the linker doing code generation
>> based on the LTO bytecode), move the -c GCC argument to the build rules,
>> and drop it from the GCC CC_FLAGS definitions in tools_def.
>>
>> Contributed-under: TianoCore Contribution Agreement 1.0
>> Signed-off-by: Ard Biesheuvel 
>> ---
>>  BaseTools/Conf/build_rule.template | 16 +---
>>  BaseTools/Conf/tools_def.template  | 10 +-
>>  2 files changed, 14 insertions(+), 12 deletions(-)
>>
>> diff --git a/BaseTools/Conf/build_rule.template 
>> b/BaseTools/Conf/build_rule.template
>> index 9adf3918e42e..7d9f8ca075c2 100644
>> --- a/BaseTools/Conf/build_rule.template
>> +++ b/BaseTools/Conf/build_rule.template
>> @@ -130,7 +130,10 @@
>>  
>>  "$(CC)" /Fo${dst} $(CC_FLAGS) $(INC) ${src}
>>
>> -
>> +
>> +"$(CC)" $(CC_FLAGS) -c -o ${dst} $(INC) ${src}
>> +
>> +
>
> Apart from the slightly larger patch set, is there any reason not to
> split out the RVCT handling here and fix up tools_def.template for it
> too?
>

In what sense do we need to fix up tools_def for RVCT?
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH 1/3] BaseTools GCC: move -c compiler flag to build rules

2016-08-02 Thread Leif Lindholm
On Tue, Aug 02, 2016 at 04:39:30PM +0200, Ard Biesheuvel wrote:
> In order to be able to share the compiler flags with the linker (which
> is required for LTO since it involves the linker doing code generation
> based on the LTO bytecode), move the -c GCC argument to the build rules,
> and drop it from the GCC CC_FLAGS definitions in tools_def.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ard Biesheuvel 
> ---
>  BaseTools/Conf/build_rule.template | 16 +---
>  BaseTools/Conf/tools_def.template  | 10 +-
>  2 files changed, 14 insertions(+), 12 deletions(-)
> 
> diff --git a/BaseTools/Conf/build_rule.template 
> b/BaseTools/Conf/build_rule.template
> index 9adf3918e42e..7d9f8ca075c2 100644
> --- a/BaseTools/Conf/build_rule.template
> +++ b/BaseTools/Conf/build_rule.template
> @@ -130,7 +130,10 @@
>  
>  "$(CC)" /Fo${dst} $(CC_FLAGS) $(INC) ${src}
>  
> -
> +
> +"$(CC)" $(CC_FLAGS) -c -o ${dst} $(INC) ${src}
> +
> +

Apart from the slightly larger patch set, is there any reason not to
split out the RVCT handling here and fix up tools_def.template for it
too?

/
Leif

>  # For RVCTCYGWIN CC_FLAGS must be first to work around pathing issues
>  "$(CC)" $(CC_FLAGS) -o ${dst} $(INC) ${src}
>  
> @@ -156,9 +159,8 @@
>  
>  "$(CC)" /Fo${dst} $(CC_FLAGS) $(INC) ${src}
>  
> -
> -# For RVCTCYGWIN CC_FLAGS must be first to work around pathing issues
> -"$(CC)" $(CC_FLAGS) -o ${dst} $(INC) ${src}
> +
> +"$(CC)" $(CC_FLAGS) -c -o ${dst} $(INC) ${src}
>  "$(SYMRENAME)" $(SYMRENAME_FLAGS) ${dst}
>  
>  
> [C-Code-File.BASE.AARCH64,C-Code-File.SEC.AARCH64,C-Code-File.PEI_CORE.AARCH64,C-Code-File.PEIM.AARCH64]
> @@ -172,7 +174,7 @@
>  $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj
>  
>  
> -"$(CC)" $(CC_FLAGS) $(CC_XIPFLAGS) -o ${dst} $(INC) ${src}
> +"$(CC)" $(CC_FLAGS) $(CC_XIPFLAGS) -c -o ${dst} $(INC) ${src}
>  
>  [C-Header-File]
>  
> @@ -446,7 +448,7 @@
>  "$(GENFW)" -o ${dst} -c $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.dll 
> $(GENFW_FLAGS)
>  
>  
> -"$(ASLCC)" -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj $(CC_FLAGS) 
> $(ASLCC_FLAGS) $(INC) ${src}
> +"$(ASLCC)" -c -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj 
> $(CC_FLAGS) $(ASLCC_FLAGS) $(INC) ${src}
>  "$(ASLDLINK)" -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.dll 
> $(ASLDLINK_FLAGS) $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj
>  "$(GENFW)" -o ${dst} -c $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.dll 
> $(GENFW_FLAGS)
>  
> @@ -466,7 +468,7 @@
>  "$(GENFW)" -o ${dst} -c $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.dll 
> $(GENFW_FLAGS)
>  
>  
> -"$(ASLCC)" -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj $(CC_FLAGS) 
> $(ASLCC_FLAGS) $(INC) ${src}
> +"$(ASLCC)" -c -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj 
> $(CC_FLAGS) $(ASLCC_FLAGS) $(INC) ${src}
>  "$(ASLDLINK)" -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.dll 
> $(ASLDLINK_FLAGS) $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj
>  "$(GENFW)" -o ${dst} -c $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.dll 
> $(GENFW_FLAGS)
>  
> diff --git a/BaseTools/Conf/tools_def.template 
> b/BaseTools/Conf/tools_def.template
> index fd9eccb9b92a..289e75cc3be6 100644
> --- a/BaseTools/Conf/tools_def.template
> +++ b/BaseTools/Conf/tools_def.template
> @@ -4330,7 +4330,7 @@ NOOPT_DDK3790xASL_IPF_DLINK_FLAGS= /NOLOGO 
> /NODEFAULTLIB /LTCG /DLL /OPT:REF
>  DEBUG_*_*_OBJCOPY_ADDDEBUGFLAG = 
> --add-gnu-debuglink=$(DEBUG_DIR)/$(MODULE_NAME).debug
>  RELEASE_*_*_OBJCOPY_ADDDEBUGFLAG   =
>  
> -DEFINE GCC_ALL_CC_FLAGS= -g -Os -fshort-wchar 
> -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -c -include AutoGen.h 
> -fno-common
> +DEFINE GCC_ALL_CC_FLAGS= -g -Os -fshort-wchar 
> -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -include AutoGen.h 
> -fno-common
>  DEFINE GCC_IA32_CC_FLAGS   = DEF(GCC_ALL_CC_FLAGS) -m32 
> -malign-double -freorder-blocks -freorder-blocks-and-partition -O2 
> -mno-stack-arg-probe
>  DEFINE GCC_X64_CC_FLAGS= DEF(GCC_ALL_CC_FLAGS) -mno-red-zone 
> -Wno-address -mno-stack-arg-probe
>  DEFINE GCC_IPF_CC_FLAGS= DEF(GCC_ALL_CC_FLAGS) 
> -minline-int-divide-min-latency
> @@ -4362,7 +4362,7 @@ DEFINE GCC_IPF_RC_FLAGS= -I binary -O 
> elf64-ia64-little   -B ia64
>  DEFINE GCC_ARM_RC_FLAGS= -I binary -O elf32-littlearm -B arm 
> --rename-section .data=.hii
>  DEFINE GCC_AARCH64_RC_FLAGS= -I binary -O elf64-littleaarch64 -B 
> aarch64 --rename-section .data=.hii
>  
> 

Re: [edk2] [PATCH 0/3] BaseTools GCC: pass CC flags to linker

2016-08-02 Thread Ard Biesheuvel
On 2 August 2016 at 16:50, Gao, Liming  wrote:
> Ard:
>   Without this change, GCC5 LTO can pass build. With it, what difference will 
> be in the generated image? Original way may generate the wrong image, or new 
> way will generate the smaller image?
>

This is not about code size but about correctness. Compiler switches
for code model or alignment etc may affect the way code is generated
at link time by the LTO routines.
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH 0/3] BaseTools GCC: pass CC flags to linker

2016-08-02 Thread Gao, Liming
Ard:
  Without this change, GCC5 LTO can pass build. With it, what difference will 
be in the generated image? Original way may generate the wrong image, or new 
way will generate the smaller image? 

Thanks
Liming
-Original Message-
From: Ard Biesheuvel [mailto:ard.biesheu...@linaro.org] 
Sent: Tuesday, August 2, 2016 10:39 PM
To: Zhu, Yonghong ; Gao, Liming ; 
Justen, Jordan L ; edk2-devel@lists.01.org; 
leif.lindh...@linaro.org
Cc: sigmaepsilo...@gmail.com; Ard Biesheuvel 
Subject: [PATCH 0/3] BaseTools GCC: pass CC flags to linker

GCC5 runs in LTO mode, which means it may generate code during the link
stage, and this code generation should be subject to the same settings
as ordinary code generation.

Since we now invoke GCC as the linker, we can start passing the CC_FLAGS
to the linker as well, with only minor surgery. This does not bother
non-LTO links at all, and forces the LTO links to use the correct settings.

Ard Biesheuvel (3):
  BaseTools GCC: move -c compiler flag to build rules
  BaseTools GCC5: disable warnings-as-errors for now
  BaseTools GCC: add the compiler flags to the linker command line

 BaseTools/Conf/build_rule.template | 18 ++
 BaseTools/Conf/tools_def.template  | 18 +-
 2 files changed, 19 insertions(+), 17 deletions(-)

-- 
2.7.4

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


Re: [edk2] [PATCH v5 0/8] BaseTools: add support for GCC5 in LTO mode

2016-08-02 Thread Michael Zimmermann
sry but I have to retest everything since I aciidentally checked out a
wrong revision.
will report back later.

On Tue, Aug 2, 2016 at 4:39 PM, Michael Zimmermann  wrote:

> Sry for the late reply but I tried your latest gcc-lto branch to make sure
> my answers are still correct.
> I tested it with all configurations(StdLib:X64/ARM, Ovmf:X64,
> ArmVirtPkg:ARM with both RELEASE and DEBUG).
> In StdLib are many warnings actually. That's because
> of -Wunused-const-variable and -Wmisleading-indentation.
> Also I had to apply the commit to fix 'Unsupported ELF EM_X86_64
> relocation 0x4.' for X64.
>
> '-b RELEASE -a ARM -t GCC5 -p AppPkg/AppPkg.dsc' is the only configuration
> I can't get to compile with gcc6(DEBUG works):
> /tmp/ccYJi1bO.ltrans0.ltrans.o: In function `memmove':
> :(.text+0x3670): multiple definition of `memmove'
> /media/Data/repositories/git/efidroid/testing/linuxtoolchain/edk2/Build/AppPkg/RELEASE_GCC5/ARM/ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib/OUTPUT/CompilerIntrinsicsLib.lib(memmove.obj):(.text+0x0):
> first defined here
> /tmp/ccYJi1bO.ltrans0.ltrans.o: In function `memset':
> :(.text+0x3674): multiple definition of `memset'
> /media/Data/repositories/git/efidroid/testing/linuxtoolchain/edk2/Build/AppPkg/RELEASE_GCC5/ARM/ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib/OUTPUT/CompilerIntrinsicsLib.lib(memset.obj):(.text+0x10):
> first defined here
>
> /media/Data/repositories/git/efidroid/prebuilts/gcc/linux-x86/arm/gcc-linaro-6.1.1~linaro-gcc-6-branch@f3888e76-20160721-x86_64_arm-eabi/bin/../lib/gcc/arm-eabi/6.1.1/../../../../arm-eabi/bin/ld:
> printf.obj: plugin needed to handle lto object
>
> /media/Data/repositories/git/efidroid/prebuilts/gcc/linux-x86/arm/gcc-linaro-6.1.1~linaro-gcc-6-branch@f3888e76-20160721-x86_64_arm-eabi/bin/../lib/gcc/arm-eabi/6.1.1/../../../../arm-eabi/bin/ld:
> puts.obj: plugin needed to handle lto object
>
> /media/Data/repositories/git/efidroid/prebuilts/gcc/linux-x86/arm/gcc-linaro-6.1.1~linaro-gcc-6-branch@f3888e76-20160721-x86_64_arm-eabi/bin/../lib/gcc/arm-eabi/6.1.1/../../../../arm-eabi/bin/ld:
> internal error
> /media/Data/repositories/git/abe/_build/snapshots/binutils-gdb.git~linaro_binutils-2_26-branch/ld/ldlang.c
> 6299
> collect2: error: ld returned 1 exit status
> make: *** [GNUmakefile:417:
> /media/Data/repositories/git/efidroid/testing/linuxtoolchain/edk2/Build/AppPkg/RELEASE_GCC5/ARM/AppPkg/Applications/Main/Main/DEBUG/Main.dll]
> Error 1
>
> Also, I only did compilation tests, I didn't try to run any of the
> produced binaries.
>
> this is the fixed branch:
> https://github.com/M1cha/edk2/commits/edk2-master-gcc6
> it's based on your gcc5-lto-v6 branch.
>
> Thanks
> Michael
>
> On Tue, Aug 2, 2016 at 3:56 PM, Ard Biesheuvel 
> wrote:
>
>> On 2 August 2016 at 15:55, Michael Zimmermann 
>> wrote:
>> > btw, gcc6 seems to work fine too with these patches(it did with the
>> GCC49
>> > configs too on both ARM and x86/x64).
>> >
>>
>> Thanks for the data points. Do you see any warnings during the build?
>>
>
>
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v5 0/8] BaseTools: add support for GCC5 in LTO mode

2016-08-02 Thread Ard Biesheuvel
On 2 August 2016 at 16:39, Michael Zimmermann  wrote:
> Sry for the late reply but I tried your latest gcc-lto branch to make sure
> my answers are still correct.
> I tested it with all configurations(StdLib:X64/ARM, Ovmf:X64, ArmVirtPkg:ARM
> with both RELEASE and DEBUG).
> In StdLib are many warnings actually. That's because of
> -Wunused-const-variable and -Wmisleading-indentation.
> Also I had to apply the commit to fix 'Unsupported ELF EM_X86_64 relocation
> 0x4.' for X64.
>

Only 0x4 or 0x9 or others as well? This is relevent since 0x4 is a PLT
relocation which can be fixed up easily. The GOT based ones are
trickier since they involve a GOT entry with an absolute symbol
address that needs to be fixed up by the PE/COFF loader

> '-b RELEASE -a ARM -t GCC5 -p AppPkg/AppPkg.dsc' is the only configuration I
> can't get to compile with gcc6(DEBUG works):
> /tmp/ccYJi1bO.ltrans0.ltrans.o: In function `memmove':
> :(.text+0x3670): multiple definition of `memmove'
> /media/Data/repositories/git/efidroid/testing/linuxtoolchain/edk2/Build/AppPkg/RELEASE_GCC5/ARM/ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib/OUTPUT/CompilerIntrinsicsLib.lib(memmove.obj):(.text+0x0):
> first defined here
> /tmp/ccYJi1bO.ltrans0.ltrans.o: In function `memset':
> :(.text+0x3674): multiple definition of `memset'
> /media/Data/repositories/git/efidroid/testing/linuxtoolchain/edk2/Build/AppPkg/RELEASE_GCC5/ARM/ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib/OUTPUT/CompilerIntrinsicsLib.lib(memset.obj):(.text+0x10):
> first defined here

Interesting. I wonder where the first memmove resp. memset are coming
from. Are you linking with libgcc are sth like that?

> /media/Data/repositories/git/efidroid/prebuilts/gcc/linux-x86/arm/gcc-linaro-6.1.1~linaro-gcc-6-branch@f3888e76-20160721-x86_64_arm-eabi/bin/../lib/gcc/arm-eabi/6.1.1/../../../../arm-eabi/bin/ld:
> printf.obj: plugin needed to handle lto object
> /media/Data/repositories/git/efidroid/prebuilts/gcc/linux-x86/arm/gcc-linaro-6.1.1~linaro-gcc-6-branch@f3888e76-20160721-x86_64_arm-eabi/bin/../lib/gcc/arm-eabi/6.1.1/../../../../arm-eabi/bin/ld:
> puts.obj: plugin needed to handle lto object
> /media/Data/repositories/git/efidroid/prebuilts/gcc/linux-x86/arm/gcc-linaro-6.1.1~linaro-gcc-6-branch@f3888e76-20160721-x86_64_arm-eabi/bin/../lib/gcc/arm-eabi/6.1.1/../../../../arm-eabi/bin/ld:
> internal error
> /media/Data/repositories/git/abe/_build/snapshots/binutils-gdb.git~linaro_binutils-2_26-branch/ld/ldlang.c
> 6299
> collect2: error: ld returned 1 exit status
> make: *** [GNUmakefile:417:
> /media/Data/repositories/git/efidroid/testing/linuxtoolchain/edk2/Build/AppPkg/RELEASE_GCC5/ARM/AppPkg/Applications/Main/Main/DEBUG/Main.dll]
> Error 1
>

Not sure what's going on here ...

> Also, I only did compilation tests, I didn't try to run any of the produced
> binaries.
>
> this is the fixed branch:
> https://github.com/M1cha/edk2/commits/edk2-master-gcc6
> it's based on your gcc5-lto-v6 branch.
>

Thanks for the report. I will look into this.
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v5 0/8] BaseTools: add support for GCC5 in LTO mode

2016-08-02 Thread Michael Zimmermann
Sry for the late reply but I tried your latest gcc-lto branch to make sure
my answers are still correct.
I tested it with all configurations(StdLib:X64/ARM, Ovmf:X64,
ArmVirtPkg:ARM with both RELEASE and DEBUG).
In StdLib are many warnings actually. That's because
of -Wunused-const-variable and -Wmisleading-indentation.
Also I had to apply the commit to fix 'Unsupported ELF EM_X86_64 relocation
0x4.' for X64.

'-b RELEASE -a ARM -t GCC5 -p AppPkg/AppPkg.dsc' is the only configuration
I can't get to compile with gcc6(DEBUG works):
/tmp/ccYJi1bO.ltrans0.ltrans.o: In function `memmove':
:(.text+0x3670): multiple definition of `memmove'
/media/Data/repositories/git/efidroid/testing/linuxtoolchain/edk2/Build/AppPkg/RELEASE_GCC5/ARM/ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib/OUTPUT/CompilerIntrinsicsLib.lib(memmove.obj):(.text+0x0):
first defined here
/tmp/ccYJi1bO.ltrans0.ltrans.o: In function `memset':
:(.text+0x3674): multiple definition of `memset'
/media/Data/repositories/git/efidroid/testing/linuxtoolchain/edk2/Build/AppPkg/RELEASE_GCC5/ARM/ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib/OUTPUT/CompilerIntrinsicsLib.lib(memset.obj):(.text+0x10):
first defined here
/media/Data/repositories/git/efidroid/prebuilts/gcc/linux-x86/arm/gcc-linaro-6.1.1~linaro-gcc-6-branch@f3888e76-20160721-x86_64_arm-eabi/bin/../lib/gcc/arm-eabi/6.1.1/../../../../arm-eabi/bin/ld:
printf.obj: plugin needed to handle lto object
/media/Data/repositories/git/efidroid/prebuilts/gcc/linux-x86/arm/gcc-linaro-6.1.1~linaro-gcc-6-branch@f3888e76-20160721-x86_64_arm-eabi/bin/../lib/gcc/arm-eabi/6.1.1/../../../../arm-eabi/bin/ld:
puts.obj: plugin needed to handle lto object
/media/Data/repositories/git/efidroid/prebuilts/gcc/linux-x86/arm/gcc-linaro-6.1.1~linaro-gcc-6-branch@f3888e76-20160721-x86_64_arm-eabi/bin/../lib/gcc/arm-eabi/6.1.1/../../../../arm-eabi/bin/ld:
internal error
/media/Data/repositories/git/abe/_build/snapshots/binutils-gdb.git~linaro_binutils-2_26-branch/ld/ldlang.c
6299
collect2: error: ld returned 1 exit status
make: *** [GNUmakefile:417:
/media/Data/repositories/git/efidroid/testing/linuxtoolchain/edk2/Build/AppPkg/RELEASE_GCC5/ARM/AppPkg/Applications/Main/Main/DEBUG/Main.dll]
Error 1

Also, I only did compilation tests, I didn't try to run any of the produced
binaries.

this is the fixed branch:
https://github.com/M1cha/edk2/commits/edk2-master-gcc6
it's based on your gcc5-lto-v6 branch.

Thanks
Michael

On Tue, Aug 2, 2016 at 3:56 PM, Ard Biesheuvel 
wrote:

> On 2 August 2016 at 15:55, Michael Zimmermann 
> wrote:
> > btw, gcc6 seems to work fine too with these patches(it did with the GCC49
> > configs too on both ARM and x86/x64).
> >
>
> Thanks for the data points. Do you see any warnings during the build?
>
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 2/3] BaseTools GCC5: disable warnings-as-errors for now

2016-08-02 Thread Ard Biesheuvel
GCC5 runs in LTO mode, which means it may generate code from an
intermediate representation during the link stage, at which time
additional diagnostics are run that may emit warnings.

Some of these warnings seem to be spurious, e.g., the following
warning which is emitted when building OVMF for IA32 or ArmVirtQemu
for ARM (but not for X64 resp. AARCH64)

  .../MdeModulePkg/Library/UefiHiiLib/HiiLib.c:
 In function 'HiiCreateGuidOpCode.constprop':
  .../MdeModulePkg/Library/UefiHiiLib/HiiLib.c:3228:10:
 error: function may return address of local variable
[-Werror=return-local-addr]
 return (UINT8 *)OpCodePointer;
^
  .../MdeModulePkg/Library/UefiHiiLib/HiiLib.c:3208:17: note: declared here
 EFI_IFR_GUID  OpCode;
   ^
  lto1: all warnings being treated as errors
  lto-wrapper: fatal error: gcc returned 1 exit status

So before adding the contents of CC_FLAGS to the linker command line,
defuse the default '-Werror' by adding '-Wno-error' to DLINK2_FLAGS
for GCC5.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel 
---
 BaseTools/Conf/tools_def.template | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/BaseTools/Conf/tools_def.template 
b/BaseTools/Conf/tools_def.template
index 289e75cc3be6..1f55740929d7 100644
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -4466,9 +4466,9 @@ DEFINE GCC5_X64_CC_FLAGS = 
DEF(GCC49_X64_CC_FLAGS) -flto -fno-builti
 DEFINE GCC5_IA32_X64_DLINK_COMMON= DEF(GCC49_IA32_X64_DLINK_COMMON)
 DEFINE GCC5_IA32_X64_ASLDLINK_FLAGS  = DEF(GCC49_IA32_X64_ASLDLINK_FLAGS)
 DEFINE GCC5_IA32_X64_DLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_FLAGS) -flto
-DEFINE GCC5_IA32_DLINK2_FLAGS= DEF(GCC49_IA32_DLINK2_FLAGS)
+DEFINE GCC5_IA32_DLINK2_FLAGS= DEF(GCC49_IA32_DLINK2_FLAGS) -Wno-error
 DEFINE GCC5_X64_DLINK_FLAGS  = DEF(GCC49_X64_DLINK_FLAGS) -flto
-DEFINE GCC5_X64_DLINK2_FLAGS = DEF(GCC49_X64_DLINK2_FLAGS)
+DEFINE GCC5_X64_DLINK2_FLAGS = DEF(GCC49_X64_DLINK2_FLAGS) -Wno-error
 DEFINE GCC5_ASM_FLAGS= DEF(GCC49_ASM_FLAGS)
 DEFINE GCC5_ARM_ASM_FLAGS= DEF(GCC49_ARM_ASM_FLAGS)
 DEFINE GCC5_AARCH64_ASM_FLAGS= DEF(GCC49_AARCH64_ASM_FLAGS)
@@ -4476,9 +4476,9 @@ DEFINE GCC5_ARM_CC_FLAGS = 
DEF(GCC49_ARM_CC_FLAGS)
 DEFINE GCC5_AARCH64_CC_FLAGS = DEF(GCC49_AARCH64_CC_FLAGS)
 DEFINE GCC5_AARCH64_CC_XIPFLAGS  = DEF(GCC49_AARCH64_CC_XIPFLAGS)
 DEFINE GCC5_ARM_DLINK_FLAGS  = DEF(GCC49_ARM_DLINK_FLAGS)
-DEFINE GCC5_ARM_DLINK2_FLAGS = DEF(GCC49_ARM_DLINK2_FLAGS)
+DEFINE GCC5_ARM_DLINK2_FLAGS = DEF(GCC49_ARM_DLINK2_FLAGS) -Wno-error
 DEFINE GCC5_AARCH64_DLINK_FLAGS  = DEF(GCC49_AARCH64_DLINK_FLAGS)
-DEFINE GCC5_AARCH64_DLINK2_FLAGS = DEF(GCC49_AARCH64_DLINK2_FLAGS)
+DEFINE GCC5_AARCH64_DLINK2_FLAGS = DEF(GCC49_AARCH64_DLINK2_FLAGS) 
-Wno-error
 DEFINE GCC5_ARM_ASLDLINK_FLAGS   = DEF(GCC49_ARM_ASLDLINK_FLAGS)
 DEFINE GCC5_AARCH64_ASLDLINK_FLAGS   = DEF(GCC49_AARCH64_ASLDLINK_FLAGS)
 
-- 
2.7.4

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


[edk2] [PATCH 3/3] BaseTools GCC: add the compiler flags to the linker command line

2016-08-02 Thread Ard Biesheuvel
Now that we invoke GCC as the linker for the GCC toolchain family,
we can pass the CC flags to the linker as well. This is only
required for LTO (which may involve code generation during the link
stage), but does not interfere with non-LTO builds.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel 
---
 BaseTools/Conf/build_rule.template | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/BaseTools/Conf/build_rule.template 
b/BaseTools/Conf/build_rule.template
index 7d9f8ca075c2..ddeef59a9ec6 100644
--- a/BaseTools/Conf/build_rule.template
+++ b/BaseTools/Conf/build_rule.template
@@ -294,7 +294,7 @@
 "$(DLINK)" /OUT:${dst} $(DLINK_FLAGS) $(DLINK_SPATH) 
@$(STATIC_LIBRARY_FILES_LIST)
 
 
-"$(DLINK)" -o ${dst} $(DLINK_FLAGS) 
-Wl,--start-group,@$(STATIC_LIBRARY_FILES_LIST),--end-group $(DLINK2_FLAGS)
+"$(DLINK)" -o ${dst} $(DLINK_FLAGS) 
-Wl,--start-group,@$(STATIC_LIBRARY_FILES_LIST),--end-group $(CC_FLAGS) 
$(DLINK2_FLAGS)
 "$(OBJCOPY)" $(OBJCOPY_FLAGS) ${dst}
 
 
-- 
2.7.4

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


[edk2] [PATCH 0/3] BaseTools GCC: pass CC flags to linker

2016-08-02 Thread Ard Biesheuvel
GCC5 runs in LTO mode, which means it may generate code during the link
stage, and this code generation should be subject to the same settings
as ordinary code generation.

Since we now invoke GCC as the linker, we can start passing the CC_FLAGS
to the linker as well, with only minor surgery. This does not bother
non-LTO links at all, and forces the LTO links to use the correct settings.

Ard Biesheuvel (3):
  BaseTools GCC: move -c compiler flag to build rules
  BaseTools GCC5: disable warnings-as-errors for now
  BaseTools GCC: add the compiler flags to the linker command line

 BaseTools/Conf/build_rule.template | 18 ++
 BaseTools/Conf/tools_def.template  | 18 +-
 2 files changed, 19 insertions(+), 17 deletions(-)

-- 
2.7.4

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


[edk2] [PATCH 1/3] BaseTools GCC: move -c compiler flag to build rules

2016-08-02 Thread Ard Biesheuvel
In order to be able to share the compiler flags with the linker (which
is required for LTO since it involves the linker doing code generation
based on the LTO bytecode), move the -c GCC argument to the build rules,
and drop it from the GCC CC_FLAGS definitions in tools_def.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel 
---
 BaseTools/Conf/build_rule.template | 16 +---
 BaseTools/Conf/tools_def.template  | 10 +-
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/BaseTools/Conf/build_rule.template 
b/BaseTools/Conf/build_rule.template
index 9adf3918e42e..7d9f8ca075c2 100644
--- a/BaseTools/Conf/build_rule.template
+++ b/BaseTools/Conf/build_rule.template
@@ -130,7 +130,10 @@
 
 "$(CC)" /Fo${dst} $(CC_FLAGS) $(INC) ${src}
 
-
+
+"$(CC)" $(CC_FLAGS) -c -o ${dst} $(INC) ${src}
+
+
 # For RVCTCYGWIN CC_FLAGS must be first to work around pathing issues
 "$(CC)" $(CC_FLAGS) -o ${dst} $(INC) ${src}
 
@@ -156,9 +159,8 @@
 
 "$(CC)" /Fo${dst} $(CC_FLAGS) $(INC) ${src}
 
-
-# For RVCTCYGWIN CC_FLAGS must be first to work around pathing issues
-"$(CC)" $(CC_FLAGS) -o ${dst} $(INC) ${src}
+
+"$(CC)" $(CC_FLAGS) -c -o ${dst} $(INC) ${src}
 "$(SYMRENAME)" $(SYMRENAME_FLAGS) ${dst}
 
 
[C-Code-File.BASE.AARCH64,C-Code-File.SEC.AARCH64,C-Code-File.PEI_CORE.AARCH64,C-Code-File.PEIM.AARCH64]
@@ -172,7 +174,7 @@
 $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj
 
 
-"$(CC)" $(CC_FLAGS) $(CC_XIPFLAGS) -o ${dst} $(INC) ${src}
+"$(CC)" $(CC_FLAGS) $(CC_XIPFLAGS) -c -o ${dst} $(INC) ${src}
 
 [C-Header-File]
 
@@ -446,7 +448,7 @@
 "$(GENFW)" -o ${dst} -c $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.dll 
$(GENFW_FLAGS)
 
 
-"$(ASLCC)" -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj $(CC_FLAGS) 
$(ASLCC_FLAGS) $(INC) ${src}
+"$(ASLCC)" -c -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj $(CC_FLAGS) 
$(ASLCC_FLAGS) $(INC) ${src}
 "$(ASLDLINK)" -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.dll 
$(ASLDLINK_FLAGS) $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj
 "$(GENFW)" -o ${dst} -c $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.dll 
$(GENFW_FLAGS)
 
@@ -466,7 +468,7 @@
 "$(GENFW)" -o ${dst} -c $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.dll 
$(GENFW_FLAGS)
 
 
-"$(ASLCC)" -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj $(CC_FLAGS) 
$(ASLCC_FLAGS) $(INC) ${src}
+"$(ASLCC)" -c -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj $(CC_FLAGS) 
$(ASLCC_FLAGS) $(INC) ${src}
 "$(ASLDLINK)" -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.dll 
$(ASLDLINK_FLAGS) $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj
 "$(GENFW)" -o ${dst} -c $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.dll 
$(GENFW_FLAGS)
 
diff --git a/BaseTools/Conf/tools_def.template 
b/BaseTools/Conf/tools_def.template
index fd9eccb9b92a..289e75cc3be6 100644
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -4330,7 +4330,7 @@ NOOPT_DDK3790xASL_IPF_DLINK_FLAGS= /NOLOGO 
/NODEFAULTLIB /LTCG /DLL /OPT:REF
 DEBUG_*_*_OBJCOPY_ADDDEBUGFLAG = 
--add-gnu-debuglink=$(DEBUG_DIR)/$(MODULE_NAME).debug
 RELEASE_*_*_OBJCOPY_ADDDEBUGFLAG   =
 
-DEFINE GCC_ALL_CC_FLAGS= -g -Os -fshort-wchar -fno-strict-aliasing 
-Wall -Werror -Wno-array-bounds -c -include AutoGen.h -fno-common
+DEFINE GCC_ALL_CC_FLAGS= -g -Os -fshort-wchar -fno-strict-aliasing 
-Wall -Werror -Wno-array-bounds -include AutoGen.h -fno-common
 DEFINE GCC_IA32_CC_FLAGS   = DEF(GCC_ALL_CC_FLAGS) -m32 -malign-double 
-freorder-blocks -freorder-blocks-and-partition -O2 -mno-stack-arg-probe
 DEFINE GCC_X64_CC_FLAGS= DEF(GCC_ALL_CC_FLAGS) -mno-red-zone 
-Wno-address -mno-stack-arg-probe
 DEFINE GCC_IPF_CC_FLAGS= DEF(GCC_ALL_CC_FLAGS) 
-minline-int-divide-min-latency
@@ -4362,7 +4362,7 @@ DEFINE GCC_IPF_RC_FLAGS= -I binary -O 
elf64-ia64-little   -B ia64
 DEFINE GCC_ARM_RC_FLAGS= -I binary -O elf32-littlearm -B arm   
  --rename-section .data=.hii
 DEFINE GCC_AARCH64_RC_FLAGS= -I binary -O elf64-littleaarch64 -B 
aarch64 --rename-section .data=.hii
 
-DEFINE GCC44_ALL_CC_FLAGS= -g -fshort-wchar -fno-strict-aliasing 
-Wall -Werror -Wno-array-bounds -ffunction-sections -fdata-sections -c -include 
AutoGen.h -fno-common -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings
+DEFINE GCC44_ALL_CC_FLAGS= -g -fshort-wchar -fno-strict-aliasing 
-Wall -Werror -Wno-array-bounds -ffunction-sections -fdata-sections -include 
AutoGen.h -fno-common -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings
 DEFINE 

Re: [edk2] [PATCH v5 0/8] BaseTools: add support for GCC5 in LTO mode

2016-08-02 Thread Ard Biesheuvel
On 2 August 2016 at 15:55, Michael Zimmermann  wrote:
> btw, gcc6 seems to work fine too with these patches(it did with the GCC49
> configs too on both ARM and x86/x64).
>

Thanks for the data points. Do you see any warnings during the build?
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v5 0/8] BaseTools: add support for GCC5 in LTO mode

2016-08-02 Thread Michael Zimmermann
btw, gcc6 seems to work fine too with these patches(it did with the GCC49
configs too on both ARM and x86/x64).

Thanks
Michael

On Tue, Aug 2, 2016 at 1:42 PM, Ard Biesheuvel 
wrote:

> On 2 August 2016 at 13:41, Shi, Steven  wrote:
> > Ard,
> > Thank you to check in GCC5!
> >
>
> My pleasure. Thanks to you for the comments, discussion and review
> feedback.
>
> --
> Ard.
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
>
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [patch] MdeModulePkg/FvSimpleFileSystem: fix assertions when FV is empty

2016-08-02 Thread Zhang, Chao B
Reviewed-by: Chao Zhang 





Thanks & Best regards
Chao Zhang

-Original Message-
From: Tian, Feng 
Sent: Tuesday, August 02, 2016 4:10 PM
To: Zhang, Chao B
Cc: edk2-devel@lists.01.org
Subject: [patch] MdeModulePkg/FvSimpleFileSystem: fix assertions when FV is 
empty

The original code will assert when dealing with those empty FVs.
The fix is used to solve this bug.

Cc: Chao Zhang 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian 
---
 .../Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c | 9 +++--
 .../FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c | 6 +-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c 
b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c
index c6137ac..b81110f 100644
--- a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c
+++ b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c
@@ -526,7 +526,10 @@ FvSimpleFileSystemOpen (
 InitializeListHead (>Link);
 InsertHeadList (>FileHead, >Link);
 
-NewFile->DirReadNext = FVFS_GET_FIRST_FILE_INFO (Instance);
+NewFile->DirReadNext = NULL;
+if (!IsListEmpty (>FileInfoHead)) {
+  NewFile->DirReadNext = FVFS_GET_FIRST_FILE_INFO (Instance);
+}
 
 *NewHandle = >FileProtocol;
 return EFI_SUCCESS;
@@ -821,7 +824,9 @@ FvSimpleFileSystemSetPosition (
 //
 // Reset directory position to first entry
 //
-File->DirReadNext = FVFS_GET_FIRST_FILE_INFO (Instance);
+if (File->DirReadNext) {
+  File->DirReadNext = FVFS_GET_FIRST_FILE_INFO (Instance); 
+}
   } else if (Position == 0xull) {
 File->Position = File->FvFileInfo->FileInfo.FileSize;
   } else {
diff --git 
a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c 
b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c
index 7167fb9..4e6089b 100644
--- 
a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c
+++ 
b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c
@@ -223,7 +223,11 @@ FvSimpleFileSystemOpenVolume (
 }
   }
 
-  Instance->Root->DirReadNext = FVFS_GET_FIRST_FILE_INFO (Instance);
+  Instance->Root->DirReadNext = NULL;
+  if (!IsListEmpty (>FileInfoHead)) {
+Instance->Root->DirReadNext = FVFS_GET_FIRST_FILE_INFO (Instance);
+  }
+
   *RootFile = >Root->FileProtocol;
   return Status;
 }
-- 
2.7.1.windows.2

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


Re: [edk2] [PATCH] ArmVirtPkg/ArmVirtPrePiUniCoreRelocatable: deal with relaxed XIP alignment

2016-08-02 Thread Ard Biesheuvel
On 2 August 2016 at 13:35, Laszlo Ersek  wrote:
> On 08/02/16 12:17, Ard Biesheuvel wrote:
>> Commit b89919ee8f8c ("BaseTools AARCH64: override XIP module linker
>> alignment to 32 bytes") updated the various AARCH64 toolchain definitions
>> to allow SEC, PEI_CORE and PEIM modules to be built with minimal alignment
>> requirements even when using the AArch64 small code model which normally
>> requires 4 KB section alignment.
>>
>> This involves conversion of ADRP instructions into ADR instructions, which
>> can only be done reliably if the ELF and the PE/COFF sections appear at
>> the same offset modulo 4 KB.
>>
>> The ArmVirtPrePiUniCoreRelocatable linker script did not yet take this
>> into account, so update it by starting the .text section at the next
>> appropriately aligned offset PECOFF_HEADER_SIZE bytes into the image.
>>
>> Contributed-under: TianoCore Contribution Agreement 1.0
>> Signed-off-by: Ard Biesheuvel 
>> ---
>>
>> This fixes the ArmVirtQemuKernel and ArmVirtXen platforms, which are 
>> currently
>> broken when using DEBUG_GCC49, DEBUG_GCC5 or *_CLANG35 (all of which received
>> the linker alignment treatment mentioned above)
>>
>> Symptoms: many occurrences of
>> ...
>> GenFw: ERROR 3000: Invalid
>>   WriteSections64(): <../ArmVirtPrePiUniCoreRelocatable.dll> AARCH64 small
>>  code model requires identical ELF and PE/COFF section offsets modulo 4 
>> KB.
>> ...
>>
>> and a failed build.
>>
>>  ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds 
>> b/ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds
>> index 44df7840adfd..492a8fff380f 100644
>> --- a/ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds
>> +++ b/ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds
>> @@ -14,9 +14,10 @@
>>
>>  SECTIONS
>>  {
>> -  .text 0x0 : ALIGN(CONSTANT(COMMONPAGESIZE)) {
>> -PROVIDE(__reloc_base = .);
>> +  PROVIDE(__reloc_base = .);
>>
>> +  . = PECOFF_HEADER_SIZE;
>> +  .text : ALIGN(CONSTANT(COMMONPAGESIZE)) {
>>  *(.text .text*)
>>  *(.got .got*)
>>  *(.rodata .rodata*)
>>
>
> Acked-by: Laszlo Ersek 

Pushed as d54e2d6c1e68
Thanks
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v2 2/7] BaseTools-GenFw:Add new x86_64 Elf relocation types for PIC/PIE code

2016-08-02 Thread Ard Biesheuvel
On 2 August 2016 at 13:40, Shi, Steven  wrote:
>>
>> CoffAddFixup() must be used for absolute symbol references only. These
>> instructions contain relative symbol references, which are
>> recalculated in WriteSections64().
>>
>> The only absolute symbol reference is the GOT entry for 'n', and your
>> code (in WriteRelocations64()) calculates the address of the GOT entry
>> (which is always in .text BTW) and adds a fixup for it, i.e.,
>>
>> +  CoffAddFixup(
>> +(UINT32)(UINTN)((UINT64)
>> mCoffSectionsOffset[RelShdr->sh_info] + GoTPcRelPtrOffset),
>> +EFI_IMAGE_REL_BASED_DIR64);
>>
>> This code adds a fixup to the PE/COFF .reloc section for the GOT entry
>> containing the address of 'n', and the instructions perform a IP
>> relative load of the contents of the GOT entry to retrieve the address
>> of 'n'.
>>
>> By adding two fixups, the PE/COFF loader will apply the load offset
>> twice, resulting in an incorrect value.
>>
> OK, I get your point now. Yes, the current patch could generate multiple 
> fixups for the same GOT relocation entry. How about we introduce a simple 
> IsDuplicatedCoffFixup() to check whether a converting fixup offset is 
> duplicated before we use CoffAddFixup() to really add it? If it is new, we 
> add it, otherwise just skip it.

That could work, but you have to be aware that fixups are best emitted
in the order they need to be applied in the binary, or it will become
very inefficient. (Please refer to the PE/COFF spec section that
explains the layout of the .reloc section)

What it comes down to is that relocations are grouped by target page,
and for every place in the page that requires a relocation to be
applied, a 4 bit type is emitted followed by a 12-bit offset, which is
the offset into the current page. If you emit fixups for the current
instruction, followed by one for the GOT, it will basically take two
'page switches' every time.

So it would be better to simply emit the relocations, but introduce a
sorting pass that merges all duplicates as well.

Thanks,
Ard.
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v5 0/8] BaseTools: add support for GCC5 in LTO mode

2016-08-02 Thread Ard Biesheuvel
On 2 August 2016 at 13:41, Shi, Steven  wrote:
> Ard,
> Thank you to check in GCC5!
>

My pleasure. Thanks to you for the comments, discussion and review feedback.

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


Re: [edk2] [PATCH v5 0/8] BaseTools: add support for GCC5 in LTO mode

2016-08-02 Thread Shi, Steven
Ard,
Thank you to check in GCC5! 


Steven Shi
Intel\SSG\STO\UEFI Firmware

Tel: +86 021-61166522
iNet: 821-6522


> -Original Message-
> From: Ard Biesheuvel [mailto:ard.biesheu...@linaro.org]
> Sent: Tuesday, August 02, 2016 5:03 PM
> To: Shi, Steven ; Zhu, Yonghong
> ; Gao, Liming ; Justen,
> Jordan L ; edk2-devel-01  de...@lists.01.org>
> Cc: Leif Lindholm ; Laszlo Ersek
> ; Ard Biesheuvel 
> Subject: Re: [PATCH v5 0/8] BaseTools: add support for GCC5 in LTO mode
> 
> On 1 August 2016 at 10:01, Ard Biesheuvel 
> wrote:
> > This v5 to introduce GCC5 is now a 8 piece series, including some
> > preparatory cleanup patches that allow all GCC4x and CLANG35 toolchains
> > to switch to using 'gcc' as the linker. This allows us to get rid of
> > the wrapper script to marshall ld arguments in order to make them
> > understandable by gcc, which is fragile and likely to cause problems in
> > the future.
> >
> > Since there appears to be a natural split between the 'legacy' GCC
> > toolchains UNIXGCC, ELFGCC, and CYGGCC[xASL], both in term of
> supported
> > architectures [IA32, X64, IPF] vs [IA32, X64, ARM, AARCH64], and in
> > terms of maintenance, these toolchains are not moved to using 'gcc' as
> > the linker, and instead, a new BUILDRULEFAMILY is introduced called
> GCCLD
> > that will retain the old behavior.
> >
> > The result is that GCC5 can align much more closely with its predecessors,
> > making the expected maintenance burden of supporting GCC back to v4.4
> > much lower.
> >
> > Changes since v4:
> > - added patch to use 'protected' visibility only for the libraries that
> >   define the module entry points (_ModuleEntryPoint), to prevent them
> from
> >   being optimized away by the LTO routines
> > - added Jordan's ack/RBs
> > - add some extra comments to tools_def.template (#8)
> >
> 
> Thanks all. Committed as
> 
> 1c63516075b3 BaseTools CLANG35: drop problematic use-movt and save-
> temps options
> ff54bcdf2e4e ArmVirtPkg/ArmVirtPrePiUniCoreRelocatable: ignore .hash
> and .note sections
> befb3ba51502 BaseTools UNIXGCC ELFGCC CYGGCC: clone GCC build rule
> family into GCCLD
> a1b8baccc30b BaseTools GCC: use 'gcc' as the linker command for GCC44
> and later
> e1458aaded8e ArmPkg: add prebuilt glue binaries for GCC5 LTO support
> 7fd5d619806d BaseTools GCC: drop GNU notes section from EFI image
> 4a8466d4baba BaseTools GCC: introduce GCC5 toolchain to support GCC
> v5.x in LTO mode
> 
> with Leif and Liming's R-b. I dropped patch #7, and instead made the
> visibility pragma conditional on whether LTO is disabled.
> 
> --
> Ard.
> 
> 
> > Changes since v3:
> > - like Steven does in his GCC5LTO patch, add -fno-builtin to IA32 and X64
> >   CC_FLAGS; this addresses a build issue reported by Liming
> > - add -Os the the linker flags as well, for AARCH64 this does not seem to
> make
> >   a difference, but it is arguably correct since the LTO processing at link
> >   time involves code generation as well
> > - add Laszlo's ack to #2
> > - new patch #6 to omit the autogenerated build-id from the PE/COFF binary
> >
> > Changes since v2:
> > - add license headers to LTO glue files for ARM and AARCH64 (#5)
> > - get rid of lto-ld-wrapper script
> >
> > Ard Biesheuvel (8):
> >   BaseTools CLANG35: drop problematic use-movt and save-temps options
> >   ArmVirtPkg/ArmVirtPrePiUniCoreRelocatable: ignore .hash and .note
> > sections
> >   BaseTools UNIXGCC ELFGCC CYGGCC: clone GCC build rule family into
> > GCCLD
> >   BaseTools GCC: use 'gcc' as the linker command for GCC44 and later
> >   ArmPkg: add prebuilt glue binaries for GCC5 LTO support
> >   BaseTools GCC: drop GNU notes section from EFI image
> >   MdePkg GCC/X64: avoid 'hidden' visibility for module entry points
> >   BaseTools GCC: introduce GCC5 toolchain to support GCC v5.x in LTO
> > mode
> >
> >  ArmPkg/GccLto/liblto-aarch64.a | 
> > Bin 0 -> 1016
> bytes
> >  ArmPkg/GccLto/liblto-aarch64.s |  
> > 27 ++
> >  ArmPkg/GccLto/liblto-arm.a | 
> > Bin 0 -> 2096 bytes
> >  ArmPkg/GccLto/liblto-arm.s |  
> > 61 
> >  ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf|   
> > 2 +-
> >  ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds |   
> > 3 +
> >  BaseTools/Conf/build_rule.template |  
> > 31 +-
> >  BaseTools/Conf/tools_def.template  | 
> > 350
> +++-
> >  BaseTools/Scripts/GccBase.lds  |   
> > 6 +
> >  EmulatorPkg/Unix/Host/Host.inf |   
> > 6 +-
> >  

Re: [edk2] [PATCH v2 2/7] BaseTools-GenFw:Add new x86_64 Elf relocation types for PIC/PIE code

2016-08-02 Thread Shi, Steven
> 
> CoffAddFixup() must be used for absolute symbol references only. These
> instructions contain relative symbol references, which are
> recalculated in WriteSections64().
> 
> The only absolute symbol reference is the GOT entry for 'n', and your
> code (in WriteRelocations64()) calculates the address of the GOT entry
> (which is always in .text BTW) and adds a fixup for it, i.e.,
> 
> +  CoffAddFixup(
> +(UINT32)(UINTN)((UINT64)
> mCoffSectionsOffset[RelShdr->sh_info] + GoTPcRelPtrOffset),
> +EFI_IMAGE_REL_BASED_DIR64);
> 
> This code adds a fixup to the PE/COFF .reloc section for the GOT entry
> containing the address of 'n', and the instructions perform a IP
> relative load of the contents of the GOT entry to retrieve the address
> of 'n'.
> 
> By adding two fixups, the PE/COFF loader will apply the load offset
> twice, resulting in an incorrect value.
> 
OK, I get your point now. Yes, the current patch could generate multiple fixups 
for the same GOT relocation entry. How about we introduce a simple 
IsDuplicatedCoffFixup() to check whether a converting fixup offset is 
duplicated before we use CoffAddFixup() to really add it? If it is new, we add 
it, otherwise just skip it.
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [Patch v5 36/48] OvmfPkg: Add MpInitLib reference in DSC files.

2016-08-02 Thread Laszlo Ersek
On 08/02/16 10:59, Jeff Fan wrote:
> This update is for CpuMpPei consuming MP Initialize library.
> 
> Cc: Michael Kinney 
> Cc: Feng Tian 
> Cc: Jordan Justen 
> Cc: Laszlo Ersek 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jeff Fan 
> ---
>  OvmfPkg/OvmfPkgIa32.dsc| 2 ++
>  OvmfPkg/OvmfPkgIa32X64.dsc | 2 ++
>  OvmfPkg/OvmfPkgX64.dsc | 2 ++
>  3 files changed, 6 insertions(+)
> 
> diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
> index 8af3267..5ed39f7 100644
> --- a/OvmfPkg/OvmfPkgIa32.dsc
> +++ b/OvmfPkg/OvmfPkgIa32.dsc
> @@ -213,6 +213,7 @@ [LibraryClasses.common.PEIM]
>
> DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib.inf
>  !endif
>
> CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
> +  MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
>  
>  [LibraryClasses.common.DXE_CORE]
>HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf
> @@ -292,6 +293,7 @@ [LibraryClasses.common.DXE_DRIVER]
>DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
>  !endif
>PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
> +  MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
>  
>  [LibraryClasses.common.UEFI_APPLICATION]
>PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
> diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
> index 4bb38d0..a1fae56 100644
> --- a/OvmfPkg/OvmfPkgIa32X64.dsc
> +++ b/OvmfPkg/OvmfPkgIa32X64.dsc
> @@ -218,6 +218,7 @@ [LibraryClasses.common.PEIM]
>
> DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib.inf
>  !endif
>
> CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
> +  MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
>  
>  [LibraryClasses.common.DXE_CORE]
>HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf
> @@ -297,6 +298,7 @@ [LibraryClasses.common.DXE_DRIVER]
>DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
>  !endif
>PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
> +  MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
>  
>  [LibraryClasses.common.UEFI_APPLICATION]
>PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
> diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
> index be3aa1f..2ec8e8c 100644
> --- a/OvmfPkg/OvmfPkgX64.dsc
> +++ b/OvmfPkg/OvmfPkgX64.dsc
> @@ -218,6 +218,7 @@ [LibraryClasses.common.PEIM]
>
> DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib.inf
>  !endif
>
> CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
> +  MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
>  
>  [LibraryClasses.common.DXE_CORE]
>HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf
> @@ -297,6 +298,7 @@ [LibraryClasses.common.DXE_DRIVER]
>DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
>  !endif
>PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
> +  MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
>  
>  [LibraryClasses.common.UEFI_APPLICATION]
>PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
> 

Thank you for updating your git config the way I requested :)

Reviewed-by: Laszlo Ersek 
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] ArmVirtPkg/ArmVirtPrePiUniCoreRelocatable: deal with relaxed XIP alignment

2016-08-02 Thread Laszlo Ersek
On 08/02/16 12:17, Ard Biesheuvel wrote:
> Commit b89919ee8f8c ("BaseTools AARCH64: override XIP module linker
> alignment to 32 bytes") updated the various AARCH64 toolchain definitions
> to allow SEC, PEI_CORE and PEIM modules to be built with minimal alignment
> requirements even when using the AArch64 small code model which normally
> requires 4 KB section alignment.
> 
> This involves conversion of ADRP instructions into ADR instructions, which
> can only be done reliably if the ELF and the PE/COFF sections appear at
> the same offset modulo 4 KB.
> 
> The ArmVirtPrePiUniCoreRelocatable linker script did not yet take this
> into account, so update it by starting the .text section at the next
> appropriately aligned offset PECOFF_HEADER_SIZE bytes into the image.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ard Biesheuvel 
> ---
> 
> This fixes the ArmVirtQemuKernel and ArmVirtXen platforms, which are currently
> broken when using DEBUG_GCC49, DEBUG_GCC5 or *_CLANG35 (all of which received
> the linker alignment treatment mentioned above)
> 
> Symptoms: many occurrences of
> ...
> GenFw: ERROR 3000: Invalid
>   WriteSections64(): <../ArmVirtPrePiUniCoreRelocatable.dll> AARCH64 small
>  code model requires identical ELF and PE/COFF section offsets modulo 4 
> KB.
> ...
> 
> and a failed build.
> 
>  ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds 
> b/ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds
> index 44df7840adfd..492a8fff380f 100644
> --- a/ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds
> +++ b/ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds
> @@ -14,9 +14,10 @@
>  
>  SECTIONS
>  {
> -  .text 0x0 : ALIGN(CONSTANT(COMMONPAGESIZE)) {
> -PROVIDE(__reloc_base = .);
> +  PROVIDE(__reloc_base = .);
>  
> +  . = PECOFF_HEADER_SIZE;
> +  .text : ALIGN(CONSTANT(COMMONPAGESIZE)) {
>  *(.text .text*)
>  *(.got .got*)
>  *(.rodata .rodata*)
> 

Acked-by: Laszlo Ersek 
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch] SecurityPkg OpalPasswordDxe: Fix buffer overflow issue.

2016-08-02 Thread Eric Dong
In current code, PSID is processed as string and the length is 0x20.
Current code only reserved 0x20 length buffer for it, no extra buffer
for the '\0'. When driver call UnicodeStrToAsciiStrS to convert PSID,
it search the '\0' for the end. So extra dirty data saved in PSID
info which caused PSID revert action failed. This patch reserved
extra 1 byte data for the '\0'.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong 
Cc: Star Zeng 
---
 SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHii.c   | 5 -
 SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHiiFormValues.h | 3 ++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHii.c 
b/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHii.c
index 9a44c56..ee73697 100644
--- a/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHii.c
+++ b/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHii.c
@@ -595,12 +595,15 @@ HiiPsidRevert(
   OPAL_DISK *OpalDisk;
   TCG_RESULTRet;
   OPAL_SESSION  Session;
+  UINT8 TmpBuf[PSID_CHARACTER_STRING_END_LENGTH];
 
   Ret = TcgResultFailure;
 
   OpalHiiGetBrowserData();
 
-  UnicodeStrToAsciiStrS (gHiiConfiguration.Psid, (CHAR8*)Psid.Psid, 
PSID_CHARACTER_LENGTH);
+  ZeroMem (TmpBuf, sizeof (TmpBuf));
+  UnicodeStrToAsciiStrS (gHiiConfiguration.Psid, (CHAR8*)TmpBuf, 
PSID_CHARACTER_STRING_END_LENGTH);
+  CopyMem (Psid.Psid, TmpBuf, PSID_CHARACTER_LENGTH);
 
   OpalDisk = HiiGetOpalDiskCB (gHiiConfiguration.SelectedDiskIndex);
   if (OpalDisk != NULL) {
diff --git a/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHiiFormValues.h 
b/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHiiFormValues.h
index 138bcb8..88cf9f5 100644
--- a/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHiiFormValues.h
+++ b/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHiiFormValues.h
@@ -21,6 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 
 // PSID Length
 #define PSID_CHARACTER_LENGTH  0x20
+#define PSID_CHARACTER_STRING_END_LENGTH   0x21
 
 // ID's for various forms that will be used by HII
 #define FORMID_VALUE_MAIN_MENU 0x01
@@ -38,7 +39,7 @@ typedef struct {
 UINT8   KeepUserData;
 UINT16  AvailableFields;
 UINT16  Password[MAX_PASSWORD_CHARACTER_LENGTH];
-UINT16  Psid[PSID_CHARACTER_LENGTH];
+UINT16  Psid[PSID_CHARACTER_STRING_END_LENGTH];
 UINT8   EnableBlockSid;
 } OPAL_HII_CONFIGURATION;
 #pragma pack()
-- 
2.6.4.windows.1

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


[edk2] [Patch] BaseTools: Allow string token identifier to use lower case letters

2016-08-02 Thread Yonghong Zhu
This patch is to align the code behavior with UNI spec that string token
identifier can use upper case and lower case letters.

Cc: Liming Gao 
Cc: Felix 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu 
---
 BaseTools/Source/Python/AutoGen/UniClassObject.py | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/UniClassObject.py 
b/BaseTools/Source/Python/AutoGen/UniClassObject.py
index 183b2b2..856d19c 100644
--- a/BaseTools/Source/Python/AutoGen/UniClassObject.py
+++ b/BaseTools/Source/Python/AutoGen/UniClassObject.py
@@ -346,15 +346,15 @@ class UniFileClassObject(object):
 def GetStringObject(self, Item):
 Language = ''
 Value = ''
 
 Name = Item.split()[1]
-# Check the string name is the upper character
+# Check the string name
 if Name != '':
-MatchString = re.match('[A-Z0-9_]+', Name, re.UNICODE)
+MatchString = re.match('^[a-zA-Z][a-zA-Z0-9_]*$', Name, re.UNICODE)
 if MatchString == None or MatchString.end(0) != len(Name):
-EdkLogger.error('Unicode File Parser', FORMAT_INVALID, 'The 
string token name %s defined in UNI file %s contains the invalid lower case 
character.' % (Name, self.File))
+EdkLogger.error('Unicode File Parser', FORMAT_INVALID, 'The 
string token name %s defined in UNI file %s contains the invalid character.' % 
(Name, self.File))
 LanguageList = Item.split(u'#language ')
 for IndexI in range(len(LanguageList)):
 if IndexI == 0:
 continue
 else:
@@ -516,15 +516,15 @@ class UniFileClassObject(object):
 else:
 IndexI = IndexJ
 break
 # Value = Value.replace(u'\r\n', u'')
 Language = GetLanguageCode(Language, self.IsCompatibleMode, 
self.File)
-# Check the string name is the upper character
+# Check the string name
 if not self.IsCompatibleMode and Name != '':
-MatchString = re.match('[A-Z0-9_]+', Name, re.UNICODE)
+MatchString = re.match('^[a-zA-Z][a-zA-Z0-9_]*$', Name, 
re.UNICODE)
 if MatchString == None or MatchString.end(0) != len(Name):
-EdkLogger.error('Unicode File Parser', FORMAT_INVALID, 
'The string token name %s defined in UNI file %s contains the invalid lower 
case character.' % (Name, self.File))
+EdkLogger.error('Unicode File Parser', FORMAT_INVALID, 
'The string token name %s defined in UNI file %s contains the invalid 
character.' % (Name, self.File))
 self.AddStringToList(Name, Language, Value)
 continue
 
 #
 # Get string def information format 2 as below
-- 
2.6.1.windows.1

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


Re: [edk2] [PATCH v5 0/8] BaseTools: add support for GCC5 in LTO mode

2016-08-02 Thread Ard Biesheuvel
On 2 August 2016 at 12:57, Laszlo Ersek  wrote:
> On 08/02/16 11:03, Ard Biesheuvel wrote:
>> On 1 August 2016 at 10:01, Ard Biesheuvel  wrote:
>>> This v5 to introduce GCC5 is now a 8 piece series, including some
>>> preparatory cleanup patches that allow all GCC4x and CLANG35 toolchains
>>> to switch to using 'gcc' as the linker. This allows us to get rid of
>>> the wrapper script to marshall ld arguments in order to make them
>>> understandable by gcc, which is fragile and likely to cause problems in
>>> the future.
>>>
>>> Since there appears to be a natural split between the 'legacy' GCC
>>> toolchains UNIXGCC, ELFGCC, and CYGGCC[xASL], both in term of supported
>>> architectures [IA32, X64, IPF] vs [IA32, X64, ARM, AARCH64], and in
>>> terms of maintenance, these toolchains are not moved to using 'gcc' as
>>> the linker, and instead, a new BUILDRULEFAMILY is introduced called GCCLD
>>> that will retain the old behavior.
>>>
>>> The result is that GCC5 can align much more closely with its predecessors,
>>> making the expected maintenance burden of supporting GCC back to v4.4
>>> much lower.
>>>
>>> Changes since v4:
>>> - added patch to use 'protected' visibility only for the libraries that
>>>   define the module entry points (_ModuleEntryPoint), to prevent them from
>>>   being optimized away by the LTO routines
>>> - added Jordan's ack/RBs
>>> - add some extra comments to tools_def.template (#8)
>>>
>>
>> Thanks all. Committed as
>>
>> 1c63516075b3 BaseTools CLANG35: drop problematic use-movt and save-temps 
>> options
>> ff54bcdf2e4e ArmVirtPkg/ArmVirtPrePiUniCoreRelocatable: ignore .hash
>> and .note sections
>> befb3ba51502 BaseTools UNIXGCC ELFGCC CYGGCC: clone GCC build rule
>> family into GCCLD
>> a1b8baccc30b BaseTools GCC: use 'gcc' as the linker command for GCC44 and 
>> later
>> e1458aaded8e ArmPkg: add prebuilt glue binaries for GCC5 LTO support
>> 7fd5d619806d BaseTools GCC: drop GNU notes section from EFI image
>> 4a8466d4baba BaseTools GCC: introduce GCC5 toolchain to support GCC
>> v5.x in LTO mode
>>
>> with Leif and Liming's R-b. I dropped patch #7, and instead made the
>> visibility pragma conditional on whether LTO is disabled.
>
> Re gcc-5, do we need a patch for "OvmfPkg/build.sh" now? See also
> .
>

Yes, I suppose so.
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] ArmVirtPkg/ArmVirtPrePiUniCoreRelocatable: deal with relaxed XIP alignment

2016-08-02 Thread Ard Biesheuvel
Commit b89919ee8f8c ("BaseTools AARCH64: override XIP module linker
alignment to 32 bytes") updated the various AARCH64 toolchain definitions
to allow SEC, PEI_CORE and PEIM modules to be built with minimal alignment
requirements even when using the AArch64 small code model which normally
requires 4 KB section alignment.

This involves conversion of ADRP instructions into ADR instructions, which
can only be done reliably if the ELF and the PE/COFF sections appear at
the same offset modulo 4 KB.

The ArmVirtPrePiUniCoreRelocatable linker script did not yet take this
into account, so update it by starting the .text section at the next
appropriately aligned offset PECOFF_HEADER_SIZE bytes into the image.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel 
---

This fixes the ArmVirtQemuKernel and ArmVirtXen platforms, which are currently
broken when using DEBUG_GCC49, DEBUG_GCC5 or *_CLANG35 (all of which received
the linker alignment treatment mentioned above)

Symptoms: many occurrences of
...
GenFw: ERROR 3000: Invalid
  WriteSections64(): <../ArmVirtPrePiUniCoreRelocatable.dll> AARCH64 small
 code model requires identical ELF and PE/COFF section offsets modulo 4 KB.
...

and a failed build.

 ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds 
b/ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds
index 44df7840adfd..492a8fff380f 100644
--- a/ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds
+++ b/ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds
@@ -14,9 +14,10 @@
 
 SECTIONS
 {
-  .text 0x0 : ALIGN(CONSTANT(COMMONPAGESIZE)) {
-PROVIDE(__reloc_base = .);
+  PROVIDE(__reloc_base = .);
 
+  . = PECOFF_HEADER_SIZE;
+  .text : ALIGN(CONSTANT(COMMONPAGESIZE)) {
 *(.text .text*)
 *(.got .got*)
 *(.rodata .rodata*)
-- 
2.7.4

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


Re: [edk2] [PATCH] ShellBinPkg Arm/AArch64 Shell binary update

2016-08-02 Thread Leif Lindholm
On Tue, Aug 02, 2016 at 11:21:48AM +0200, Ard Biesheuvel wrote:
> The binaries of ShellBinPkg are generated with ShellPkg from b89919ee8f8c
> ("BaseTools AARCH64: override XIP module linker alignment to 32 bytes")
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ard Biesheuvel 

For the AArch64 variants:
Tested-by: Leif Lindholm 

And in general:
Reviewed-by: Leif Lindholm 

> ---
> 
> The binaries can be found here:
> https://git.linaro.org/people/ard.biesheuvel/uefi-next.git/shortlog/refs/heads/arm-shell-update
> 
>  ShellBinPkg/MinUefiShell/AArch64/Shell.efi | Bin 392416 -> 341280 bytes
>  ShellBinPkg/MinUefiShell/Arm/Shell.efi | Bin 338592 -> 297888 bytes
>  ShellBinPkg/UefiShell/AArch64/Shell.efi| Bin 893696 -> 827456 bytes
>  ShellBinPkg/UefiShell/Arm/Shell.efi| Bin 786592 -> 731680 bytes
>  4 files changed, 0 insertions(+), 0 deletions(-)
> 
> diff --git a/ShellBinPkg/MinUefiShell/AArch64/Shell.efi 
> b/ShellBinPkg/MinUefiShell/AArch64/Shell.efi
> index 53724a609171..162904634635 100755
> Binary files a/ShellBinPkg/MinUefiShell/AArch64/Shell.efi and 
> b/ShellBinPkg/MinUefiShell/AArch64/Shell.efi differ
> diff --git a/ShellBinPkg/MinUefiShell/Arm/Shell.efi 
> b/ShellBinPkg/MinUefiShell/Arm/Shell.efi
> index 251e0ca38227..c84b17bdba80 100755
> Binary files a/ShellBinPkg/MinUefiShell/Arm/Shell.efi and 
> b/ShellBinPkg/MinUefiShell/Arm/Shell.efi differ
> diff --git a/ShellBinPkg/UefiShell/AArch64/Shell.efi 
> b/ShellBinPkg/UefiShell/AArch64/Shell.efi
> index fdfd51803f93..6f2160bd1f46 100755
> Binary files a/ShellBinPkg/UefiShell/AArch64/Shell.efi and 
> b/ShellBinPkg/UefiShell/AArch64/Shell.efi differ
> diff --git a/ShellBinPkg/UefiShell/Arm/Shell.efi 
> b/ShellBinPkg/UefiShell/Arm/Shell.efi
> index f7a8cca681d7..f8d46d496c05 100755
> Binary files a/ShellBinPkg/UefiShell/Arm/Shell.efi and 
> b/ShellBinPkg/UefiShell/Arm/Shell.efi differ
> -- 
> 2.7.4
> 
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [Patch] BaseTools: Keep the Pcd order in the Asbuilt Inf is same with Source

2016-08-02 Thread Gao, Liming
Reviewed-by: Liming Gao 

> -Original Message-
> From: Zhu, Yonghong
> Sent: Tuesday, July 26, 2016 4:18 PM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming 
> Subject: [Patch] BaseTools: Keep the Pcd order in the Asbuilt Inf is same with
> Source
> 
> The original behavior is that in the Asbuilt inf Pcd's order is base on
> the Pcd's offset. Now we change the order to keep it is same with the Pcd
> order in the source inf file.
> 
> Cc: Liming Gao 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Yonghong Zhu 
> ---
>  BaseTools/Source/Python/AutoGen/AutoGen.py | 20 +++-
>  1 file changed, 11 insertions(+), 9 deletions(-)
> 
> diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py
> b/BaseTools/Source/Python/AutoGen/AutoGen.py
> index 8da441f..9758861 100644
> --- a/BaseTools/Source/Python/AutoGen/AutoGen.py
> +++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
> @@ -3571,17 +3571,17 @@ class ModuleAutoGen(AutoGen):
>  ### TODO: How to handles mixed source and binary modules
> 
>  # Find all DynamicEx and PatchableInModule PCDs used by this module
> and dependent libraries
>  # Also find all packages that the DynamicEx PCDs depend on
>  Pcds = []
> -PatchablePcds = {}
> +PatchablePcds = []
>  Packages = []
>  PcdCheckList = []
>  PcdTokenSpaceList = []
>  for Pcd in self.ModulePcdList + self.LibraryPcdList:
>  if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
> -PatchablePcds[Pcd.TokenCName] = Pcd
> +PatchablePcds += [Pcd]
>  PcdCheckList.append((Pcd.TokenCName,
> Pcd.TokenSpaceGuidCName, 'PatchableInModule'))
>  elif Pcd.Type in GenC.gDynamicExPcd:
>  if Pcd not in Pcds:
>  Pcds += [Pcd]
>  PcdCheckList.append((Pcd.TokenCName,
> Pcd.TokenSpaceGuidCName, 'DynamicEx'))
> @@ -3730,19 +3730,21 @@ class ModuleAutoGen(AutoGen):
>  PatchList = parsePcdInfoFromMapFile(
>  os.path.join(self.OutputDir, self.Name + '.map'),
>  os.path.join(self.OutputDir, self.Name + '.efi')
>  )
>  if PatchList:
> -for PatchPcd in PatchList:
> -if PatchPcd[0] in PatchablePcds:
> -key = PatchPcd[0]
> -elif PatchPcd[0] + '_PatchableInModule' in PatchablePcds:
> -key = PatchPcd[0] + '_PatchableInModule'
> +for Pcd in PatchablePcds:
> +TokenCName = Pcd.TokenCName
> +for PcdItem in GlobalData.MixedPcd:
> +if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in
> GlobalData.MixedPcd[PcdItem]:
> +TokenCName = PcdItem[0]
> +break
> +for PatchPcd in PatchList:
> +if TokenCName == PatchPcd[0]:
> +break
>  else:
>  continue
> -Pcd = PatchablePcds[key]
> -TokenCName = PatchPcd[0]
>  PcdValue = ''
>  if Pcd.DatumType != 'VOID*':
>  HexFormat = '0x%02x'
>  if Pcd.DatumType == 'UINT16':
>  HexFormat = '0x%04x'
> --
> 2.6.1.windows.1

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


[edk2] [PATCH] ShellBinPkg Arm/AArch64 Shell binary update

2016-08-02 Thread Ard Biesheuvel
The binaries of ShellBinPkg are generated with ShellPkg from b89919ee8f8c
("BaseTools AARCH64: override XIP module linker alignment to 32 bytes")

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel 
---

The binaries can be found here:
https://git.linaro.org/people/ard.biesheuvel/uefi-next.git/shortlog/refs/heads/arm-shell-update

 ShellBinPkg/MinUefiShell/AArch64/Shell.efi | Bin 392416 -> 341280 bytes
 ShellBinPkg/MinUefiShell/Arm/Shell.efi | Bin 338592 -> 297888 bytes
 ShellBinPkg/UefiShell/AArch64/Shell.efi| Bin 893696 -> 827456 bytes
 ShellBinPkg/UefiShell/Arm/Shell.efi| Bin 786592 -> 731680 bytes
 4 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/ShellBinPkg/MinUefiShell/AArch64/Shell.efi 
b/ShellBinPkg/MinUefiShell/AArch64/Shell.efi
index 53724a609171..162904634635 100755
Binary files a/ShellBinPkg/MinUefiShell/AArch64/Shell.efi and 
b/ShellBinPkg/MinUefiShell/AArch64/Shell.efi differ
diff --git a/ShellBinPkg/MinUefiShell/Arm/Shell.efi 
b/ShellBinPkg/MinUefiShell/Arm/Shell.efi
index 251e0ca38227..c84b17bdba80 100755
Binary files a/ShellBinPkg/MinUefiShell/Arm/Shell.efi and 
b/ShellBinPkg/MinUefiShell/Arm/Shell.efi differ
diff --git a/ShellBinPkg/UefiShell/AArch64/Shell.efi 
b/ShellBinPkg/UefiShell/AArch64/Shell.efi
index fdfd51803f93..6f2160bd1f46 100755
Binary files a/ShellBinPkg/UefiShell/AArch64/Shell.efi and 
b/ShellBinPkg/UefiShell/AArch64/Shell.efi differ
diff --git a/ShellBinPkg/UefiShell/Arm/Shell.efi 
b/ShellBinPkg/UefiShell/Arm/Shell.efi
index f7a8cca681d7..f8d46d496c05 100755
Binary files a/ShellBinPkg/UefiShell/Arm/Shell.efi and 
b/ShellBinPkg/UefiShell/Arm/Shell.efi differ
-- 
2.7.4

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


Re: [edk2] [PATCH 1/2] BaseTools/GenFw AARCH64: convert ADRP to ADR if binary size allows it

2016-08-02 Thread Ard Biesheuvel
On 1 August 2016 at 16:19, Leif Lindholm  wrote:
> Apologies, lost track of this one.
>
> On Mon, Aug 01, 2016 at 01:53:09PM +0200, Ard Biesheuvel wrote:
>> On 27 July 2016 at 13:26, Ard Biesheuvel  wrote:
>> > The ADRP instruction in the AArch64 ISA requires the link time and load
>> > time offsets of a binary to be equal modulo 4 KB. The reason is that this
>> > instruction always produces a multiple of 4 KB, and relies on a subsequent
>> > ADD or LDR instruction to set the offset into the page. The resulting
>> > symbol reference only produces the correct value if the symbol in question
>> > resides at that exact offset into the page, and so loading the binary at
>> > arbitrary offsets is not possible.
>> >
>> > Due to the various levels of padding when packing FVs into FVs into FDs,
>> > this alignment is very costly for XIP code, and so we would like to relax
>> > this alignment requirement if possible.
>> >
>> > Given that symbols that are sufficiently close (within 1 MB) of the
>> > reference can also be reached using an ADR instruction which does not
>> > suffer from this alignment issue, let's replace ADRP instructions with ADR
>> > after linking if the offset can be encoded in this instruction's immediate
>> > field. Note that this only makes sense if the section alignment is < 4 KB.
>> > Otherwise, replacing the ADRP has no benefit, considering that the
>> > subsequent ADD or LDR instruction is retained, and that micro-architectures
>> > are more likely to be optimized for ADRP/ADD pairs (i.e., via micro op
>> > fusing) than for ADR/ADD pairs, which are non-typical.
>> >
>> > Contributed-under: TianoCore Contribution Agreement 1.0
>> > Signed-off-by: Ard Biesheuvel 
>>
>> @Liming, @Leif:
>>
>> are there any objections to these patches? I know it is unfortunate
>> that we need to modify instructions as part of the ELF to PE/COFF
>> conversion, but it is very effective
>
> It's absolutely horrid, but extremely useful.
> For the series:
> Reviewed-by: Leif Lindholm 
>

Thanks

Committed as

026a82abf0bd BaseTools/GenFw AARCH64: convert ADRP to ADR instructions
if binary size allows it
b89919ee8f8c BaseTools AARCH64: override XIP module linker alignment to 32 bytes
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v5 0/8] BaseTools: add support for GCC5 in LTO mode

2016-08-02 Thread Ard Biesheuvel
On 1 August 2016 at 10:01, Ard Biesheuvel  wrote:
> This v5 to introduce GCC5 is now a 8 piece series, including some
> preparatory cleanup patches that allow all GCC4x and CLANG35 toolchains
> to switch to using 'gcc' as the linker. This allows us to get rid of
> the wrapper script to marshall ld arguments in order to make them
> understandable by gcc, which is fragile and likely to cause problems in
> the future.
>
> Since there appears to be a natural split between the 'legacy' GCC
> toolchains UNIXGCC, ELFGCC, and CYGGCC[xASL], both in term of supported
> architectures [IA32, X64, IPF] vs [IA32, X64, ARM, AARCH64], and in
> terms of maintenance, these toolchains are not moved to using 'gcc' as
> the linker, and instead, a new BUILDRULEFAMILY is introduced called GCCLD
> that will retain the old behavior.
>
> The result is that GCC5 can align much more closely with its predecessors,
> making the expected maintenance burden of supporting GCC back to v4.4
> much lower.
>
> Changes since v4:
> - added patch to use 'protected' visibility only for the libraries that
>   define the module entry points (_ModuleEntryPoint), to prevent them from
>   being optimized away by the LTO routines
> - added Jordan's ack/RBs
> - add some extra comments to tools_def.template (#8)
>

Thanks all. Committed as

1c63516075b3 BaseTools CLANG35: drop problematic use-movt and save-temps options
ff54bcdf2e4e ArmVirtPkg/ArmVirtPrePiUniCoreRelocatable: ignore .hash
and .note sections
befb3ba51502 BaseTools UNIXGCC ELFGCC CYGGCC: clone GCC build rule
family into GCCLD
a1b8baccc30b BaseTools GCC: use 'gcc' as the linker command for GCC44 and later
e1458aaded8e ArmPkg: add prebuilt glue binaries for GCC5 LTO support
7fd5d619806d BaseTools GCC: drop GNU notes section from EFI image
4a8466d4baba BaseTools GCC: introduce GCC5 toolchain to support GCC
v5.x in LTO mode

with Leif and Liming's R-b. I dropped patch #7, and instead made the
visibility pragma conditional on whether LTO is disabled.

-- 
Ard.


> Changes since v3:
> - like Steven does in his GCC5LTO patch, add -fno-builtin to IA32 and X64
>   CC_FLAGS; this addresses a build issue reported by Liming
> - add -Os the the linker flags as well, for AARCH64 this does not seem to make
>   a difference, but it is arguably correct since the LTO processing at link
>   time involves code generation as well
> - add Laszlo's ack to #2
> - new patch #6 to omit the autogenerated build-id from the PE/COFF binary
>
> Changes since v2:
> - add license headers to LTO glue files for ARM and AARCH64 (#5)
> - get rid of lto-ld-wrapper script
>
> Ard Biesheuvel (8):
>   BaseTools CLANG35: drop problematic use-movt and save-temps options
>   ArmVirtPkg/ArmVirtPrePiUniCoreRelocatable: ignore .hash and .note
> sections
>   BaseTools UNIXGCC ELFGCC CYGGCC: clone GCC build rule family into
> GCCLD
>   BaseTools GCC: use 'gcc' as the linker command for GCC44 and later
>   ArmPkg: add prebuilt glue binaries for GCC5 LTO support
>   BaseTools GCC: drop GNU notes section from EFI image
>   MdePkg GCC/X64: avoid 'hidden' visibility for module entry points
>   BaseTools GCC: introduce GCC5 toolchain to support GCC v5.x in LTO
> mode
>
>  ArmPkg/GccLto/liblto-aarch64.a | Bin 
> 0 -> 1016 bytes
>  ArmPkg/GccLto/liblto-aarch64.s |  27 
> ++
>  ArmPkg/GccLto/liblto-arm.a | Bin 
> 0 -> 2096 bytes
>  ArmPkg/GccLto/liblto-arm.s |  61 
> 
>  ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf|   2 
> +-
>  ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds |   3 
> +
>  BaseTools/Conf/build_rule.template |  31 
> +-
>  BaseTools/Conf/tools_def.template  | 350 
> +++-
>  BaseTools/Scripts/GccBase.lds  |   6 
> +
>  EmulatorPkg/Unix/Host/Host.inf |   6 
> +-
>  MdePkg/Include/X64/ProcessorBind.h |   9 
> +-
>  MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf |   2 
> +
>  MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf |   2 
> +
>  MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf   |   2 
> +
>  MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf |   2 
> +
>  MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf   |   2 
> +
>  16 files changed, 396 insertions(+), 109 deletions(-)
>  create mode 100644 ArmPkg/GccLto/liblto-aarch64.a
>  create mode 100644 ArmPkg/GccLto/liblto-aarch64.s
>  create mode 100644 ArmPkg/GccLto/liblto-arm.a
>  create mode 100644 ArmPkg/GccLto/liblto-arm.s
>
> --
> 2.7.4
>
___
edk2-devel mailing list

[edk2] [Patch v5 47/48] UefiCpuPkg/CpuDxe: Fixed typo in function header to match PI spec

2016-08-02 Thread Jeff Fan
Cc: Liming Gao 
Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
Reviewed-by: Giri P Mudusuru 
---
 UefiCpuPkg/CpuDxe/CpuMp.c | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c
index f336261..a619a2b 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.c
+++ b/UefiCpuPkg/CpuDxe/CpuMp.c
@@ -299,8 +299,8 @@ StartupAllAPs (
 
   @param[in]  ThisA pointer to the EFI_MP_SERVICES_PROTOCOL
   instance.
-  @param[in]  Procedure   A pointer to the function to be run on
-  enabled APs of the system. See type
+  @param[in]  Procedure   A pointer to the function to be run on 
the
+  designated AP of the system. See type
   EFI_AP_PROCEDURE.
   @param[in]  ProcessorNumber The handle number of the AP. The range is
   from 0 to the total number of logical
@@ -309,34 +309,34 @@ StartupAllAPs (
   
EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
   @param[in]  WaitEvent   The event created by the caller with 
CreateEvent()
   service.  If it is NULL, then execute in
-  blocking mode. BSP waits until all APs 
finish
-  or TimeoutInMicroseconds expires.  If 
it's
+  blocking mode. BSP waits until this AP 
finish
+  or TimeoutInMicroSeconds expires.  If 
it's
   not NULL, then execute in non-blocking 
mode.
   BSP requests the function specified by
-  Procedure to be started on all the 
enabled
-  APs, and go on executing immediately. If
-  all return from Procedure or 
TimeoutInMicroseconds
+  Procedure to be started on this AP,
+  and go on executing immediately. If this 
AP
+  return from Procedure or 
TimeoutInMicroSeconds
   expires, this event is signaled. The BSP
   can use the CheckEvent() or 
WaitForEvent()
   services to check the state of event.  
Type
   EFI_EVENT is defined in CreateEvent() in
   the Unified Extensible Firmware Interface
   Specification.
-  @param[in]  TimeoutInMicroseconds   Indicates the time limit in microseconds 
for
-  APs to return from Procedure, either for
+  @param[in]  TimeoutInMicrosecsond   Indicates the time limit in microseconds 
for
+  this AP to finish this Procedure, either 
for
   blocking or non-blocking mode. Zero means
   infinity.  If the timeout expires before
-  all APs return from Procedure, then 
Procedure
-  on the failed APs is terminated. All 
enabled
-  APs are available for next function 
assigned
+  this AP returns from Procedure, then 
Procedure
+  on the AP is terminated. The
+  AP is available for next function 
assigned
   by 
EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
   or 
EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
   If the timeout expires in blocking mode,
   BSP returns EFI_TIMEOUT.  If the timeout
   expires in non-blocking mode, WaitEvent
   is signaled with SignalEvent().
-  @param[in]  ProcedureArgument   The parameter passed into Procedure for
-  all APs.
+  @param[in]  ProcedureArgument   The parameter passed into Procedure on 
the
+  specified AP.
   @param[out] FinishedIf NULL, this parameter is ignored.  In
   blocking mode, this parameter is 

[edk2] [Patch v5 48/48] UefiCpuPkg/PiSmmCpuDxeSmm: Add gEfiVariableArchProtocolGuid dependency

2016-08-02 Thread Jeff Fan
PiSmmCpuDxeSmm driver's entry point will get some PCDs supported dynamic type.
In case those PCDs are set as DynamicHii type in platform DSC File, it implies
that EFI Variable Arch protocol is required.

This fix is to add gEfiVariableArchProtocolGuid dependency on PiSmmCpuDxeSmm
driver to make sure those DynamicHii PCDs could be read correctly.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
Reviewed-by: Giri P Mudusuru 
---
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf 
b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
index d7e6e07..83e3c55 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
@@ -4,7 +4,7 @@
 # This SMM driver performs SMM initialization, deploy SMM Entry Vector,
 # provides CPU specific services in SMM.
 #
-# Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
+# Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
 #
 # This program and the accompanying materials
 # are licensed and made available under the terms and conditions of the BSD 
License
@@ -155,7 +155,7 @@ [Pcd]
   gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmSyncMode  ## CONSUMES
 
 [Depex]
-  gEfiMpServiceProtocolGuid
+  gEfiMpServiceProtocolGuid AND gEfiVariableArchProtocolGuid
 
 [UserExtensions.TianoCore."ExtraFiles"]
   PiSmmCpuDxeSmmExtra.uni
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 44/48] UefiCpuPkg/CpuDxe: Remove PcdCpuMaxLogicalProcessorNumber consuming

2016-08-02 Thread Jeff Fan
v5:
  If PcdCpuMaxLogicalProcessorNumber is set to 1 on UP system,
  MpInitLibInitialize() will be invoked. This is one bug, we need to
  call MpInitLibInitialize() always and get the BSP information.
  Just to remove PcdCpuMaxLogicalProcessorNumber() consuming from this
  driver.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/CpuDxe/CpuDxe.inf |  3 ---
 UefiCpuPkg/CpuDxe/CpuMp.c| 18 +-
 2 files changed, 5 insertions(+), 16 deletions(-)

diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.inf b/UefiCpuPkg/CpuDxe/CpuDxe.inf
index 0adb66b..bf389bb 100644
--- a/UefiCpuPkg/CpuDxe/CpuDxe.inf
+++ b/UefiCpuPkg/CpuDxe/CpuDxe.inf
@@ -75,9 +75,6 @@ [Ppis]
   gEfiSecPlatformInformation2PpiGuid## UNDEFINED # HOB
   gEfiSecPlatformInformationPpiGuid ## UNDEFINED # HOB
 
-[Pcd]
-  gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber## CONSUMES
-
 [Depex]
   TRUE
 
diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c
index efab78c..f336261 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.c
+++ b/UefiCpuPkg/CpuDxe/CpuMp.c
@@ -613,22 +613,14 @@ InitializeMpSupport (
   UINTN  NumberOfProcessors;
   UINTN  NumberOfEnabledProcessors;
 
-  NumberOfProcessors = (UINTN) PcdGet32 (PcdCpuMaxLogicalProcessorNumber);
-  if (NumberOfProcessors < 1) {
-DEBUG ((DEBUG_ERROR, "Setting PcdCpuMaxLogicalProcessorNumber should be 
more than zero.\n"));
-return;
-  }
-
   //
-  // Only perform AP detection if PcdCpuMaxLogicalProcessorNumber is greater 
than 1
+  // Wakeup APs to do initialization
   //
-  if (NumberOfProcessors > 1) {
-Status = MpInitLibInitialize ();
-ASSERT_EFI_ERROR (Status);
+  Status = MpInitLibInitialize ();
+  ASSERT_EFI_ERROR (Status);
 
-MpInitLibGetNumberOfProcessors (, 
);
-mNumberOfProcessors = NumberOfProcessors;
-  }
+  MpInitLibGetNumberOfProcessors (, 
);
+  mNumberOfProcessors = NumberOfProcessors;
   DEBUG ((EFI_D_ERROR, "Detect CPU count: %d\n", mNumberOfProcessors));
 
   //
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 46/48] MdePkg/MpService.h: Trim whitespace at end of line

2016-08-02 Thread Jeff Fan
Cc: Liming Gao 
Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
Reviewed-by: Giri P Mudusuru 
---
 MdePkg/Include/Protocol/MpService.h | 470 ++--
 1 file changed, 235 insertions(+), 235 deletions(-)

diff --git a/MdePkg/Include/Protocol/MpService.h 
b/MdePkg/Include/Protocol/MpService.h
index 043a10a..0dbd150 100644
--- a/MdePkg/Include/Protocol/MpService.h
+++ b/MdePkg/Include/Protocol/MpService.h
@@ -1,5 +1,5 @@
 /** @file
-  When installed, the MP Services Protocol produces a collection of services 
+  When installed, the MP Services Protocol produces a collection of services
   that are needed for MP management.
 
   The MP Services Protocol provides a generalized way of performing following 
tasks:
@@ -14,32 +14,32 @@
   The Protocol is available only during boot time.
 
   MP Services Protocol is hardware-independent. Most of the logic of this 
protocol
-  is architecturally neutral. It abstracts the multi-processor environment and 
-  status of processors, and provides interfaces to retrieve information, 
maintain, 
+  is architecturally neutral. It abstracts the multi-processor environment and
+  status of processors, and provides interfaces to retrieve information, 
maintain,
   and dispatch.
 
-  MP Services Protocol may be consumed by ACPI module. The ACPI module may use 
this 
+  MP Services Protocol may be consumed by ACPI module. The ACPI module may use 
this
   protocol to retrieve data that are needed for an MP platform and report them 
to OS.
-  MP Services Protocol may also be used to program and configure processors, 
such 
+  MP Services Protocol may also be used to program and configure processors, 
such
   as MTRR synchronization for memory space attributes setting in DXE Services.
-  MP Services Protocol may be used by non-CPU DXE drivers to speed up platform 
boot 
-  by taking advantage of the processing capabilities of the APs, for example, 
using 
+  MP Services Protocol may be used by non-CPU DXE drivers to speed up platform 
boot
+  by taking advantage of the processing capabilities of the APs, for example, 
using
   APs to help test system memory in parallel with other device initialization.
   Diagnostics applications may also use this protocol for multi-processor.
 
 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
-This program and the accompanying materials are licensed and made available 
under 
-the terms and conditions of the BSD License that accompanies this 
distribution.  
+This program and the accompanying materials are licensed and made available 
under
+the terms and conditions of the BSD License that accompanies this distribution.
 The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php.
  
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,  
   
+http://opensource.org/licenses/bsd-license.php.
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
   @par Revision Reference:
-  This Protocol is defined in the UEFI Platform Initialization Specification 
1.2, 
+  This Protocol is defined in the UEFI Platform Initialization Specification 
1.2,
   Volume 2:Driver Execution Environment Core Interface.
-  
+
 **/
 
 #ifndef _MP_SERVICE_PROTOCOL_H_
@@ -64,22 +64,22 @@ typedef struct _EFI_MP_SERVICES_PROTOCOL 
EFI_MP_SERVICES_PROTOCOL;
 #define END_OF_CPU_LIST0x
 
 ///
-/// This bit is used in the StatusFlag field of EFI_PROCESSOR_INFORMATION and 
+/// This bit is used in the StatusFlag field of EFI_PROCESSOR_INFORMATION and
 /// indicates whether the processor is playing the role of BSP. If the bit is 
1,
 /// then the processor is BSP. Otherwise, it is AP.
 ///
 #define PROCESSOR_AS_BSP_BIT 0x0001
 
 ///
-/// This bit is used in the StatusFlag field of EFI_PROCESSOR_INFORMATION and 
-/// indicates whether the processor is enabled. If the bit is 1, then the 
+/// This bit is used in the StatusFlag field of EFI_PROCESSOR_INFORMATION and
+/// indicates whether the processor is enabled. If the bit is 1, then the
 /// processor is enabled. Otherwise, it is disabled.
 ///
 #define PROCESSOR_ENABLED_BIT0x0002
 
 ///
-/// This bit is used in the StatusFlag field of EFI_PROCESSOR_INFORMATION and 
-/// indicates whether the processor is healthy. If the bit is 1, then the 
+/// This bit is used in the StatusFlag field of EFI_PROCESSOR_INFORMATION and
+/// indicates whether the processor is healthy. If the bit is 1, then the
 /// processor is healthy. Otherwise, some fault has been detected for the 
processor.
 ///

[edk2] [Patch v5 41/48] UefiCpuPkg/CpuDxe: Consume MpInitLib to produce CPU MP Protocol services

2016-08-02 Thread Jeff Fan
Consume MP Initialize library to produce CPU MP Protocol services to simply the
code.

v4:
  1. Update CpuDxe.c file header to mention it produces CPU Arch protocol.
  2. Update BistData type from UINT32 to EFI_HEALTH_FLAG.
  3. Move some header location from CpuMp.h to CpuDxe.h.

v3:
  1. Move the code Consume MpInitLib APIs to produce CPU MP Protocol from patch
 #40 to this patch.
  2. Add DxeMpInitLib.inf in DSC file

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/CpuDxe/CpuDxe.c|   2 +-
 UefiCpuPkg/CpuDxe/CpuDxe.h|  12 +-
 UefiCpuPkg/CpuDxe/CpuDxe.inf  |   7 +-
 UefiCpuPkg/CpuDxe/CpuDxe.uni  |  10 +-
 UefiCpuPkg/CpuDxe/CpuDxeExtra.uni |   4 +-
 UefiCpuPkg/CpuDxe/CpuMp.c | 854 +++---
 UefiCpuPkg/CpuDxe/CpuMp.h |   2 -
 UefiCpuPkg/UefiCpuPkg.dsc |   1 +
 8 files changed, 77 insertions(+), 815 deletions(-)

diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/CpuDxe/CpuDxe.c
index 78b2c88..1b94290 100644
--- a/UefiCpuPkg/CpuDxe/CpuDxe.c
+++ b/UefiCpuPkg/CpuDxe/CpuDxe.c
@@ -1,5 +1,5 @@
 /** @file
-  CPU DXE Module.
+  CPU DXE Module to produce CPU ARCH Protocol.
 
   Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.
   This program and the accompanying materials
diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.h b/UefiCpuPkg/CpuDxe/CpuDxe.h
index 2aef626..00d1a8f 100644
--- a/UefiCpuPkg/CpuDxe/CpuDxe.h
+++ b/UefiCpuPkg/CpuDxe/CpuDxe.h
@@ -1,7 +1,7 @@
 /** @file
-  CPU DXE Module.
+  CPU DXE Module to produce CPU ARCH Protocol and CPU MP Protocol.
 
-  Copyright (c) 2008 - 2013, Intel Corporation. All rights reserved.
+  Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
@@ -18,6 +18,10 @@
 #include 
 
 #include 
+#include 
+
+#include 
+#include 
 
 #include 
 #include 
@@ -33,6 +37,10 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
+
 #include 
 #include 
 
diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.inf b/UefiCpuPkg/CpuDxe/CpuDxe.inf
index bdff548..0643bec 100644
--- a/UefiCpuPkg/CpuDxe/CpuDxe.inf
+++ b/UefiCpuPkg/CpuDxe/CpuDxe.inf
@@ -1,5 +1,5 @@
 ## @file
-#  Simple CPU driver installs CPU Architecture Protocol.
+#  CPU driver installs CPU Architecture Protocol and CPU MP protocol.
 #
 #  Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.
 #  This program and the accompanying materials
@@ -41,10 +41,9 @@ [LibraryClasses]
   UefiCpuLib
   UefiLib
   CpuExceptionHandlerLib
-  TimerLib
-  SynchronizationLib
   HobLib
   ReportStatusCodeLib
+  MpInitLib
 
 [Sources]
   ApStartup.c
@@ -71,7 +70,7 @@ [Sources.X64]
 
 [Protocols]
   gEfiCpuArchProtocolGuid   ## PRODUCES
-  gEfiMpServiceProtocolGuid ## SOMETIMES_PRODUCES
+  gEfiMpServiceProtocolGuid ## PRODUCES
 
 [Guids]
   gIdleLoopEventGuid## CONSUMES   ## Event
diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.uni b/UefiCpuPkg/CpuDxe/CpuDxe.uni
index 5ac7810..caf01dc 100644
--- a/UefiCpuPkg/CpuDxe/CpuDxe.uni
+++ b/UefiCpuPkg/CpuDxe/CpuDxe.uni
@@ -1,9 +1,9 @@
 // /** @file
-// Simple CPU driver installs CPU Architecture Protocol.
+// CPU driver installs CPU Architecture Protocol and CPU MP Protocol.
 //
-// Simple CPU driver installs CPU Architecture Protocol.
+// CPU driver installs CPU Architecture Protocol and CPU MP Protocol.
 //
-// Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.
+// Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.
 //
 // This program and the accompanying materials
 // are licensed and made available under the terms and conditions of the BSD 
License
@@ -16,7 +16,7 @@
 // **/
 
 
-#string STR_MODULE_ABSTRACT #language en-US "Installs CPU 
Architecture Protocol"
+#string STR_MODULE_ABSTRACT #language en-US "CPU driver installs 
CPU Architecture Protocol and CPU MP Protocol."
 
-#string STR_MODULE_DESCRIPTION  #language en-US "Simple CPU driver 
installs CPU Architecture Protocol."
+#string STR_MODULE_DESCRIPTION  #language en-US "CPU driver installs 
CPU Architecture Protocol and CPU MP Protocol."
 
diff --git a/UefiCpuPkg/CpuDxe/CpuDxeExtra.uni 
b/UefiCpuPkg/CpuDxe/CpuDxeExtra.uni
index fbfc2e1..c1d2019 100644
--- a/UefiCpuPkg/CpuDxe/CpuDxeExtra.uni
+++ b/UefiCpuPkg/CpuDxe/CpuDxeExtra.uni
@@ -1,7 +1,7 @@
 // /** @file
 // CpuDxe Localized Strings and Content
 //
-// Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.
+// Copyright (c) 2013 - 2016, Intel Corporation. All rights 

[edk2] [Patch v5 45/48] MdePkg/MpService.h: Fixed typo in function header to match PI spec

2016-08-02 Thread Jeff Fan
Cc: Liming Gao 
Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
Reviewed-by: Giri P Mudusuru 
---
 MdePkg/Include/Protocol/MpService.h | 34 +-
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/MdePkg/Include/Protocol/MpService.h 
b/MdePkg/Include/Protocol/MpService.h
index 5934727..043a10a 100644
--- a/MdePkg/Include/Protocol/MpService.h
+++ b/MdePkg/Include/Protocol/MpService.h
@@ -27,7 +27,7 @@
   APs to help test system memory in parallel with other device initialization.
   Diagnostics applications may also use this protocol for multi-processor.
 
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
 This program and the accompanying materials are licensed and made available 
under 
 the terms and conditions of the BSD License that accompanies this 
distribution.  
 The full text of the license may be found at
@@ -388,8 +388,8 @@ EFI_STATUS
 
   @param[in]  ThisA pointer to the EFI_MP_SERVICES_PROTOCOL
   instance.
-  @param[in]  Procedure   A pointer to the function to be run on 
-  enabled APs of the system. See type
+  @param[in]  Procedure   A pointer to the function to be run on 
the
+  designated AP of the system. See type
   EFI_AP_PROCEDURE.
   @param[in]  ProcessorNumber The handle number of the AP. The range 
is 
   from 0 to the total number of logical
@@ -398,13 +398,13 @@ EFI_STATUS
   
EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
   @param[in]  WaitEvent   The event created by the caller with 
CreateEvent()
   service.  If it is NULL, then execute in 
-  blocking mode. BSP waits until all APs 
finish 
+  blocking mode. BSP waits until this AP 
finish 
   or TimeoutInMicroSeconds expires.  If 
it's 
   not NULL, then execute in non-blocking 
mode. 
   BSP requests the function specified by 
-  Procedure to be started on all the 
enabled 
-  APs, and go on executing immediately. If 
-  all return from Procedure or 
TimeoutInMicroSeconds
+  Procedure to be started on this AP, 
+  and go on executing immediately. If this 
AP
+  return from Procedure or 
TimeoutInMicroSeconds
   expires, this event is signaled. The BSP 
   can use the CheckEvent() or 
WaitForEvent() 
   services to check the state of event.  
Type 
@@ -412,20 +412,20 @@ EFI_STATUS
   the Unified Extensible Firmware 
Interface 
   Specification.  
   @param[in]  TimeoutInMicrosecsond   Indicates the time limit in microseconds 
for 
-  APs to return from Procedure, either for 
+  this AP to finish this Procedure, either 
for 
   blocking or non-blocking mode. Zero 
means 
   infinity.  If the timeout expires before 
-  all APs return from Procedure, then 
Procedure
-  on the failed APs is terminated. All 
enabled 
-  APs are available for next function 
assigned 
+  this AP returns from Procedure, then 
Procedure
+  on the AP is terminated. The 
+  AP is available for next function 
assigned 
   by 
EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() 
   or 
EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
   If the timeout expires in blocking mode, 
   BSP returns EFI_TIMEOUT.  If the timeout 
   expires in non-blocking mode, WaitEvent 
   is signaled with SignalEvent().
-  @param[in]  ProcedureArgument 

[edk2] [Patch v5 42/48] UefiCpuPkg/CpuDxe: Move SetMtrrsFromBuffer() location.

2016-08-02 Thread Jeff Fan
Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/CpuDxe/CpuDxe.c | 15 +++
 UefiCpuPkg/CpuDxe/CpuMp.c  | 16 
 2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/CpuDxe/CpuDxe.c
index 1b94290..f6d0a67 100644
--- a/UefiCpuPkg/CpuDxe/CpuDxe.c
+++ b/UefiCpuPkg/CpuDxe/CpuDxe.c
@@ -313,6 +313,21 @@ CpuGetTimerValue (
   return EFI_SUCCESS;
 }
 
+/**
+  A minimal wrapper function that allows MtrrSetAllMtrrs() to be passed to
+  EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() as Procedure.
+
+  @param[in] Buffer  Pointer to an MTRR_SETTINGS object, to be passed to
+ MtrrSetAllMtrrs().
+**/
+VOID
+EFIAPI
+SetMtrrsFromBuffer (
+  IN VOID *Buffer
+  )
+{
+  MtrrSetAllMtrrs (Buffer);
+}
 
 /**
   Implementation of SetMemoryAttributes() service of CPU Architecture Protocol.
diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c
index 38603f9..8f7a56c 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.c
+++ b/UefiCpuPkg/CpuDxe/CpuMp.c
@@ -1001,22 +1001,6 @@ ExitBootServicesCallback (
 }
 
 /**
-  A minimal wrapper function that allows MtrrSetAllMtrrs() to be passed to
-  EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() as Procedure.
-
-  @param[in] Buffer  Pointer to an MTRR_SETTINGS object, to be passed to
- MtrrSetAllMtrrs().
-**/
-VOID
-EFIAPI
-SetMtrrsFromBuffer (
-  IN VOID *Buffer
-  )
-{
-  MtrrSetAllMtrrs (Buffer);
-}
-
-/**
   Initialize Multi-processor support.
 
 **/
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 43/48] UefiCpuPkg/CpuDxe: Remove unused codes and files

2016-08-02 Thread Jeff Fan
v5:
  1. Remove unused PcdCpuApStackSize and PcdCpuApInitTimeOutInMicroSeconds.

v4:
  1. Keep GDT table setup to fix IA32 S3 boot issue.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/CpuDxe/ApStartup.c | 478 --
 UefiCpuPkg/CpuDxe/CpuDxe.h|   1 -
 UefiCpuPkg/CpuDxe/CpuDxe.inf  |   7 -
 UefiCpuPkg/CpuDxe/CpuMp.c | 400 ---
 UefiCpuPkg/CpuDxe/CpuMp.h | 184 +--
 UefiCpuPkg/CpuDxe/Ia32/MpAsm.asm  |  76 --
 UefiCpuPkg/CpuDxe/Ia32/MpAsm.nasm |  68 --
 UefiCpuPkg/CpuDxe/X64/MpAsm.asm   |  76 --
 UefiCpuPkg/CpuDxe/X64/MpAsm.nasm  |  70 --
 9 files changed, 1 insertion(+), 1359 deletions(-)
 delete mode 100644 UefiCpuPkg/CpuDxe/ApStartup.c
 delete mode 100644 UefiCpuPkg/CpuDxe/Ia32/MpAsm.asm
 delete mode 100644 UefiCpuPkg/CpuDxe/Ia32/MpAsm.nasm
 delete mode 100644 UefiCpuPkg/CpuDxe/X64/MpAsm.asm
 delete mode 100644 UefiCpuPkg/CpuDxe/X64/MpAsm.nasm

diff --git a/UefiCpuPkg/CpuDxe/ApStartup.c b/UefiCpuPkg/CpuDxe/ApStartup.c
deleted file mode 100644
index 78fb26f..000
--- a/UefiCpuPkg/CpuDxe/ApStartup.c
+++ /dev/null
@@ -1,478 +0,0 @@
-/** @file
-  CPU DXE AP Startup
-
-  Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.
-  This program and the accompanying materials
-  are licensed and made available under the terms and conditions of the BSD 
License
-  which accompanies this distribution.  The full text of the license may be 
found at
-  http://opensource.org/licenses/bsd-license.php
-
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include "CpuDxe.h"
-#include "CpuGdt.h"
-#include "CpuMp.h"
-
-#pragma pack(1)
-
-typedef struct {
-  UINT8  MoveIa32EferMsrToEcx[5];
-  UINT8  ReadIa32EferMsr[2];
-  UINT8  SetExecuteDisableBitEnableBit[4];
-  UINT8  WriteIa32EferMsr[2];
-
-#if defined (MDE_CPU_IA32)
-  UINT8  MovEaxCr3;
-  UINT32 Cr3Value;
-  UINT8  MovCr3Eax[3];
-
-  UINT8  MoveCr4ToEax[3];
-  UINT8  SetCr4Bit5[4];
-  UINT8  MoveEaxToCr4[3];
-
-  UINT8  MoveCr0ToEax[3];
-  UINT8  SetCr0PagingBit[4];
-  UINT8  MoveEaxToCr0[3];
-#endif
-} ENABLE_EXECUTE_DISABLE_CODE;
-
-ENABLE_EXECUTE_DISABLE_CODE mEnableExecuteDisableCodeTemplate = {
-  { 0xB9, 0x80, 0x00, 0x00, 0xC0 },   // mov ecx, 0xc080
-  { 0x0F, 0x32 }, // rdmsr
-  { 0x0F, 0xBA, 0xE8, 0x0B }, // bts eax, 11
-  { 0x0F, 0x30 }, // wrmsr
-
-#if defined (MDE_CPU_IA32)
-  0xB8, 0x,   // mov eax, cr3 value
-  { 0x0F, 0x22, 0xd8 },   // mov cr3, eax
-
-  { 0x0F, 0x20, 0xE0 },   // mov eax, cr4
-  { 0x0F, 0xBA, 0xE8, 0x05 }, // bts eax, 5
-  { 0x0F, 0x22, 0xE0 },   // mov cr4, eax
-
-  { 0x0F, 0x20, 0xC0 },   // mov eax, cr0
-  { 0x0F, 0xBA, 0xE8, 0x1F }, // bts eax, 31
-  { 0x0F, 0x22, 0xC0 },   // mov cr0, eax
-#endif
-};
-
-typedef struct {
-  UINT8  JmpToCli[2];
-
-  UINT16 GdtLimit;
-  UINT32 GdtBase;
-
-  UINT8  Cli;
-
-  UINT8  MovAxRealSegment; UINT16 RealSegment;
-  UINT8  MovDsAx[2];
-
-  UINT8  MovBxGdtr[3];
-  UINT8  LoadGdt[5];
-
-  UINT8  MovEaxCr0[2];
-  UINT32 MovEaxCr0Value;
-  UINT8  MovCr0Eax[3];
-
-  UINT8  FarJmp32Flat[2]; UINT32 FlatJmpOffset; UINT16 FlatJmpSelector;
-
-  //
-  // Now in IA32
-  //
-  UINT8  MovEaxCr4;
-  UINT32 MovEaxCr4Value;
-  UINT8  MovCr4Eax[3];
-
-  UINT8  MoveDataSelectorIntoAx[2]; UINT16 FlatDataSelector;
-  UINT8  MoveFlatDataSelectorFromAxToDs[2];
-  UINT8  MoveFlatDataSelectorFromAxToEs[2];
-  UINT8  MoveFlatDataSelectorFromAxToFs[2];
-  UINT8  MoveFlatDataSelectorFromAxToGs[2];
-  UINT8  MoveFlatDataSelectorFromAxToSs[2];
-
-  //
-  // Code placeholder to enable PAE Execute Disable for IA32
-  // and enable Execute Disable Bit for X64
-  //
-  ENABLE_EXECUTE_DISABLE_CODE EnableExecuteDisable;
-
-#if defined (MDE_CPU_X64)
-  //
-  // Transition to X64
-  //
-  UINT8  MovEaxCr3;
-  UINT32 Cr3Value;
-  UINT8  MovCr3Eax[3];
-
-  UINT8  MoveCr4ToEax[3];
-  UINT8  SetCr4Bit5[4];
-  UINT8  MoveEaxToCr4[3];
-
-  UINT8  MoveLongModeEnableMsrToEcx[5];
-  UINT8  ReadLmeMsr[2];
-  UINT8  SetLongModeEnableBit[4];
-  UINT8  WriteLmeMsr[2];
-
-  UINT8  MoveCr0ToEax[3];
-  UINT8  SetCr0PagingBit[4];
-  UINT8  MoveEaxToCr0[3];
-  //UINT8  DeadLoop[2];
-
-  UINT8  FarJmp32LongMode; UINT32 LongJmpOffset; UINT16 LongJmpSelector;
-#endif // defined (MDE_CPU_X64)
-
-#if defined (MDE_CPU_X64)
-  UINT8  MovEaxOrRaxCpuDxeEntry[2]; UINTN CpuDxeEntryValue;
-#else
-  UINT8  MovEaxOrRaxCpuDxeEntry; UINTN CpuDxeEntryValue;
-#endif
-  UINT8  JmpToCpuDxeEntry[2];
-
-} STARTUP_CODE;
-
-#pragma pack()
-
-/**
-  

[edk2] [Patch v5 34/48] UefiCpuPkg/MpInitLib: Implementation of MpInitLibStartupAllAPs()

2016-08-02 Thread Jeff Fan
v4:
  1. Simply the internal function StartupAllAPsWorker()'s function
 header due to it is duplicated with MpInitLibStartupAllAPs().
v3:
  1. Use CamelCase for mStopCheckAllApsStatus and
 CheckAndUpdateApsStatus()

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c |  23 -
 UefiCpuPkg/Library/MpInitLib/MpLib.c| 158 
 UefiCpuPkg/Library/MpInitLib/MpLib.h|  41 +
 UefiCpuPkg/Library/MpInitLib/PeiMpLib.c |  13 ++-
 4 files changed, 233 insertions(+), 2 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index 75845bd..1043bec 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -305,7 +305,28 @@ MpInitLibStartupAllAPs (
   OUT UINTN **FailedCpuList OPTIONAL
   )
 {
-  return EFI_UNSUPPORTED;
+  EFI_STATUS  Status;
+
+  //
+  // Temporarily stop checkAllApsStatus for avoid resource dead-lock.
+  //
+  mStopCheckAllApsStatus = TRUE;
+
+  Status = StartupAllAPsWorker (
+ Procedure,
+ SingleThread,
+ WaitEvent,
+ TimeoutInMicroseconds,
+ ProcedureArgument,
+ FailedCpuList
+ );
+
+  //
+  // Start checkAllApsStatus
+  //
+  mStopCheckAllApsStatus = FALSE;
+
+  return Status;
 }
 
 /**
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index c10dcd3..fbe2e8b 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -1720,6 +1720,164 @@ MpInitLibGetNumberOfProcessors (
 
 
 /**
+  Worker function to execute a caller provided function on all enabled APs.
+
+  @param[in]  Procedure   A pointer to the function to be run on
+  enabled APs of the system.
+  @param[in]  SingleThreadIf TRUE, then all the enabled APs execute
+  the function specified by Procedure one 
by
+  one, in ascending order of processor 
handle
+  number.  If FALSE, then all the enabled 
APs
+  execute the function specified by 
Procedure
+  simultaneously.
+  @param[in]  WaitEvent   The event created by the caller with 
CreateEvent()
+  service.
+  @param[in]  TimeoutInMicrosecsond   Indicates the time limit in microseconds 
for
+  APs to return from Procedure, either for
+  blocking or non-blocking mode.
+  @param[in]  ProcedureArgument   The parameter passed into Procedure for
+  all APs.
+  @param[out] FailedCpuList   If all APs finish successfully, then its
+  content is set to NULL. If not all APs
+  finish before timeout expires, then its
+  content is set to address of the buffer
+  holding handle numbers of the failed APs.
+
+  @retval EFI_SUCCESS In blocking mode, all APs have finished 
before
+  the timeout expired.
+  @retval EFI_SUCCESS In non-blocking mode, function has been 
dispatched
+  to all enabled APs.
+  @retval others  Failed to Startup all APs.
+
+**/
+EFI_STATUS
+StartupAllAPsWorker (
+  IN  EFI_AP_PROCEDURE  Procedure,
+  IN  BOOLEAN   SingleThread,
+  IN  EFI_EVENT WaitEvent   OPTIONAL,
+  IN  UINTN TimeoutInMicroseconds,
+  IN  VOID  *ProcedureArgument  OPTIONAL,
+  OUT UINTN **FailedCpuList OPTIONAL
+  )
+{
+  EFI_STATUS  Status;
+  CPU_MP_DATA *CpuMpData;
+  UINTN   ProcessorCount;
+  UINTN   ProcessorNumber;
+  UINTN   CallerNumber;
+  CPU_AP_DATA *CpuData;
+  BOOLEAN HasEnabledAp;
+  CPU_STATE   ApState;
+
+  CpuMpData = GetCpuMpData ();
+
+  if (FailedCpuList != NULL) {
+*FailedCpuList = NULL;
+  }
+
+  if (CpuMpData->CpuCount == 1) {
+return EFI_NOT_STARTED;
+  }
+
+  if (Procedure == NULL) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // Check whether caller processor is BSP
+  //
+  MpInitLibWhoAmI ();
+  if (CallerNumber != CpuMpData->BspNumber) {
+return EFI_DEVICE_ERROR;
+  }
+
+  //
+  // Update 

[edk2] [Patch v5 36/48] OvmfPkg: Add MpInitLib reference in DSC files.

2016-08-02 Thread Jeff Fan
This update is for CpuMpPei consuming MP Initialize library.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Jordan Justen 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 OvmfPkg/OvmfPkgIa32.dsc| 2 ++
 OvmfPkg/OvmfPkgIa32X64.dsc | 2 ++
 OvmfPkg/OvmfPkgX64.dsc | 2 ++
 3 files changed, 6 insertions(+)

diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 8af3267..5ed39f7 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -213,6 +213,7 @@ [LibraryClasses.common.PEIM]
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib.inf
 !endif
   
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
+  MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
 
 [LibraryClasses.common.DXE_CORE]
   HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf
@@ -292,6 +293,7 @@ [LibraryClasses.common.DXE_DRIVER]
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
 !endif
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
+  MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
 
 [LibraryClasses.common.UEFI_APPLICATION]
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index 4bb38d0..a1fae56 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -218,6 +218,7 @@ [LibraryClasses.common.PEIM]
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib.inf
 !endif
   
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
+  MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
 
 [LibraryClasses.common.DXE_CORE]
   HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf
@@ -297,6 +298,7 @@ [LibraryClasses.common.DXE_DRIVER]
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
 !endif
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
+  MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
 
 [LibraryClasses.common.UEFI_APPLICATION]
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index be3aa1f..2ec8e8c 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -218,6 +218,7 @@ [LibraryClasses.common.PEIM]
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib.inf
 !endif
   
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
+  MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
 
 [LibraryClasses.common.DXE_CORE]
   HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf
@@ -297,6 +298,7 @@ [LibraryClasses.common.DXE_DRIVER]
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
 !endif
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
+  MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
 
 [LibraryClasses.common.UEFI_APPLICATION]
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 39/48] UefiCpuPkg/CpuMpPei: Remove unused files and codes

2016-08-02 Thread Jeff Fan
Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/CpuMpPei/CpuMpPei.c| 837 --
 UefiCpuPkg/CpuMpPei/CpuMpPei.h| 248 --
 UefiCpuPkg/CpuMpPei/CpuMpPei.inf  |  29 --
 UefiCpuPkg/CpuMpPei/Ia32/MpEqu.inc|  39 --
 UefiCpuPkg/CpuMpPei/Ia32/MpFuncs.asm  | 250 --
 UefiCpuPkg/CpuMpPei/Ia32/MpFuncs.nasm | 229 --
 UefiCpuPkg/CpuMpPei/Microcode.c   | 213 -
 UefiCpuPkg/CpuMpPei/Microcode.h   |  58 ---
 UefiCpuPkg/CpuMpPei/PeiMpServices.c   | 131 --
 UefiCpuPkg/CpuMpPei/PeiMpServices.h   |  23 -
 UefiCpuPkg/CpuMpPei/X64/MpEqu.inc |  41 --
 UefiCpuPkg/CpuMpPei/X64/MpFuncs.asm   | 290 
 UefiCpuPkg/CpuMpPei/X64/MpFuncs.nasm  | 281 
 13 files changed, 2669 deletions(-)
 delete mode 100644 UefiCpuPkg/CpuMpPei/Ia32/MpEqu.inc
 delete mode 100644 UefiCpuPkg/CpuMpPei/Ia32/MpFuncs.asm
 delete mode 100644 UefiCpuPkg/CpuMpPei/Ia32/MpFuncs.nasm
 delete mode 100644 UefiCpuPkg/CpuMpPei/Microcode.c
 delete mode 100644 UefiCpuPkg/CpuMpPei/Microcode.h
 delete mode 100644 UefiCpuPkg/CpuMpPei/X64/MpEqu.inc
 delete mode 100644 UefiCpuPkg/CpuMpPei/X64/MpFuncs.asm
 delete mode 100644 UefiCpuPkg/CpuMpPei/X64/MpFuncs.nasm

diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.c b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
index b5f8887..a36adf6 100644
--- a/UefiCpuPkg/CpuMpPei/CpuMpPei.c
+++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
@@ -13,843 +13,6 @@
 **/
 
 #include "CpuMpPei.h"
-
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList = {
-  (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | 
EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
-  ,
-  CpuMpEndOfPeiCallback
-};
-
-/**
-  Sort the APIC ID of all processors.
-
-  This function sorts the APIC ID of all processors so that processor number is
-  assigned in the ascending order of APIC ID which eases MP debugging.
-
-  @param PeiCpuMpDataPointer to PEI CPU MP Data
-**/
-STATIC
-VOID
-SortApicId (
-  IN PEI_CPU_MP_DATA   *PeiCpuMpData
-  )
-{
-  UINTN Index1;
-  UINTN Index2;
-  UINTN Index3;
-  UINT32ApicId;
-  PEI_CPU_DATA  CpuData;
-  UINT32ApCount;
-
-  ApCount = PeiCpuMpData->CpuCount - 1;
-
-  if (ApCount != 0) {
-for (Index1 = 0; Index1 < ApCount; Index1++) {
-  Index3 = Index1;
-  //
-  // Sort key is the hardware default APIC ID
-  //
-  ApicId = PeiCpuMpData->CpuData[Index1].ApicId;
-  for (Index2 = Index1 + 1; Index2 <= ApCount; Index2++) {
-if (ApicId > PeiCpuMpData->CpuData[Index2].ApicId) {
-  Index3 = Index2;
-  ApicId = PeiCpuMpData->CpuData[Index2].ApicId;
-}
-  }
-  if (Index3 != Index1) {
-CopyMem (, >CpuData[Index3], sizeof 
(PEI_CPU_DATA));
-CopyMem (
-  >CpuData[Index3],
-  >CpuData[Index1],
-  sizeof (PEI_CPU_DATA)
-  );
-CopyMem (>CpuData[Index1], , sizeof 
(PEI_CPU_DATA));
-  }
-}
-
-//
-// Get the processor number for the BSP
-//
-ApicId = GetInitialApicId ();
-for (Index1 = 0; Index1 < PeiCpuMpData->CpuCount; Index1++) {
-  if (PeiCpuMpData->CpuData[Index1].ApicId == ApicId) {
-PeiCpuMpData->BspNumber = (UINT32) Index1;
-break;
-  }
-}
-  }
-}
-
-/**
-  Enable x2APIC mode on APs.
-
-  @param Buffer  Pointer to private data buffer.
-**/
-STATIC
-VOID
-EFIAPI
-ApFuncEnableX2Apic (
-  IN OUT VOID  *Buffer
-  )
-{
-  SetApicMode (LOCAL_APIC_MODE_X2APIC);
-}
-
-/**
-  Get AP loop mode.
-
-  @param MonitorFilterSize  Returns the largest monitor-line size in bytes.
-
-  @return The AP loop mode.
-**/
-STATIC
-UINT8
-GetApLoopMode (
-  OUT UINT16 *MonitorFilterSize
-  )
-{
-  UINT8  ApLoopMode;
-  UINT32 RegEbx;
-  UINT32 RegEcx;
-  UINT32 RegEdx;
-
-  ASSERT (MonitorFilterSize != NULL);
-
-  ApLoopMode = PcdGet8 (PcdCpuApLoopMode);
-  ASSERT (ApLoopMode >= ApInHltLoop && ApLoopMode <= ApInRunLoop);
-  if (ApLoopMode == ApInMwaitLoop) {
-AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, , NULL);
-if ((RegEcx & BIT3) == 0) {
-  //
-  // If processor does not support MONITOR/MWAIT feature
-  // by CPUID.[EAX=01H]:ECX.BIT3, force AP in Hlt-loop mode
-  //
-  ApLoopMode = ApInHltLoop;
-}
-  }
-
-  if (ApLoopMode == ApInHltLoop) {
-*MonitorFilterSize = 0;
-  } else if (ApLoopMode == ApInRunLoop) {
-*MonitorFilterSize = sizeof (UINT32);
-  } else if (ApLoopMode == ApInMwaitLoop) {
-//
-// CPUID.[EAX=05H]:EBX.BIT0-15: Largest monitor-line size in bytes
-// CPUID.[EAX=05H].EDX: C-states supported using MWAIT
-//
-AsmCpuid (CPUID_MONITOR_MWAIT, NULL, , NULL, );
-*MonitorFilterSize = RegEbx & 0x;
-  }
-
-  return 

[edk2] [Patch v5 33/48] UefiCpuPkg/MpInitLib: Implementation of MpInitLibStartupThisAP()

2016-08-02 Thread Jeff Fan
v4:
  1. Simply the internal function StartupThisAPWorker()'s comment
 header due to it is duplicated with MpInitLibStartupThisAP().

v3:
  1. Use CamelCase for mStopCheckAllApsStatus and
 CheckAndUpdateApsStatus().

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c |  20 +-
 UefiCpuPkg/Library/MpInitLib/MpLib.c| 112 
 UefiCpuPkg/Library/MpInitLib/MpLib.h|  33 ++
 UefiCpuPkg/Library/MpInitLib/PeiMpLib.c |  13 +++-
 4 files changed, 176 insertions(+), 2 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index bd13240..75845bd 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -390,7 +390,25 @@ MpInitLibStartupThisAP (
   OUT BOOLEAN   *Finished   OPTIONAL
   )
 {
-  return EFI_UNSUPPORTED;
+  EFI_STATUS  Status;
+
+  //
+  // temporarily stop checkAllApsStatus for avoid resource dead-lock.
+  //
+  mStopCheckAllApsStatus = TRUE;
+
+  Status = StartupThisAPWorker (
+ Procedure,
+ ProcessorNumber,
+ WaitEvent,
+ TimeoutInMicroseconds,
+ ProcedureArgument,
+ Finished
+ );
+
+  mStopCheckAllApsStatus = FALSE;
+
+  return Status;
 }
 
 /**
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 2691af2..c10dcd3 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -1720,6 +1720,118 @@ MpInitLibGetNumberOfProcessors (
 
 
 /**
+  Worker function to let the caller get one enabled AP to execute a 
caller-provided
+  function.
+
+  @param[in]  Procedure   A pointer to the function to be run on
+  enabled APs of the system.
+  @param[in]  ProcessorNumber The handle number of the AP.
+  @param[in]  WaitEvent   The event created by the caller with 
CreateEvent()
+  service.
+  @param[in]  TimeoutInMicrosecsond   Indicates the time limit in microseconds 
for
+  APs to return from Procedure, either for
+  blocking or non-blocking mode.
+  @param[in]  ProcedureArgument   The parameter passed into Procedure for
+  all APs.
+  @param[out] FinishedIf AP returns from Procedure before the
+  timeout expires, its content is set to 
TRUE.
+  Otherwise, the value is set to FALSE.
+
+  @retval EFI_SUCCESS In blocking mode, specified AP finished 
before
+  the timeout expires.
+  @retval others  Failed to Startup AP.
+
+**/
+EFI_STATUS
+StartupThisAPWorker (
+  IN  EFI_AP_PROCEDURE  Procedure,
+  IN  UINTN ProcessorNumber,
+  IN  EFI_EVENT WaitEvent   OPTIONAL,
+  IN  UINTN TimeoutInMicroseconds,
+  IN  VOID  *ProcedureArgument  OPTIONAL,
+  OUT BOOLEAN   *Finished   OPTIONAL
+  )
+{
+  EFI_STATUS  Status;
+  CPU_MP_DATA *CpuMpData;
+  CPU_AP_DATA *CpuData;
+  UINTN   CallerNumber;
+
+  CpuMpData = GetCpuMpData ();
+
+  if (Finished != NULL) {
+*Finished = FALSE;
+  }
+
+  //
+  // Check whether caller processor is BSP
+  //
+  MpInitLibWhoAmI ();
+  if (CallerNumber != CpuMpData->BspNumber) {
+return EFI_DEVICE_ERROR;
+  }
+
+  //
+  // Check whether processor with the handle specified by ProcessorNumber 
exists
+  //
+  if (ProcessorNumber >= CpuMpData->CpuCount) {
+return EFI_NOT_FOUND;
+  }
+
+  //
+  // Check whether specified processor is BSP
+  //
+  if (ProcessorNumber == CpuMpData->BspNumber) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // Check parameter Procedure
+  //
+  if (Procedure == NULL) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // Update AP state
+  //
+  CheckAndUpdateApsStatus ();
+
+  //
+  // Check whether specified AP is disabled
+  //
+  if (GetApState (>CpuData[ProcessorNumber]) == CpuStateDisabled) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // If WaitEvent is not NULL, execute in non-blocking mode.
+  // BSP saves data for CheckAPsStatus(), and returns EFI_SUCCESS.
+  // CheckAPsStatus() will check completion and timeout periodically.
+  //
+  CpuData = >CpuData[ProcessorNumber];
+  CpuData->WaitEvent= WaitEvent;
+  CpuData->Finished = Finished;
+  CpuData->ExpectedTime = CalculateTimeout 

[edk2] [Patch v5 37/48] QuarkPlatformPkg: Add MpInitLib reference in DSC files.

2016-08-02 Thread Jeff Fan
This update is for CpuDxe consuming MP Initialize library.

v5:
  1. Update Quark DSC files to add PeiMpInitLib.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Kelly Steele 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 QuarkPlatformPkg/Quark.dsc| 2 ++
 QuarkPlatformPkg/QuarkMin.dsc | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/QuarkPlatformPkg/Quark.dsc b/QuarkPlatformPkg/Quark.dsc
index c87bb17..0b845ba 100644
--- a/QuarkPlatformPkg/Quark.dsc
+++ b/QuarkPlatformPkg/Quark.dsc
@@ -196,6 +196,7 @@ [LibraryClasses]
   #
   MtrrLib|QuarkSocPkg/QuarkNorthCluster/Library/MtrrLib/MtrrLib.inf
   LocalApicLib|UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf
+  MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
 
   #
   # Quark North Cluster
@@ -248,6 +249,7 @@ [LibraryClasses.IA32.PEIM,LibraryClasses.IA32.PEI_CORE]
   TimerLib|PcAtChipsetPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf
   
PlatformHelperLib|QuarkPlatformPkg/Library/PlatformHelperLib/PeiPlatformHelperLib.inf
   
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
+  MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
 !if $(SECURE_BOOT_ENABLE) || $(MEASURED_BOOT_ENABLE)
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
 !endif
diff --git a/QuarkPlatformPkg/QuarkMin.dsc b/QuarkPlatformPkg/QuarkMin.dsc
index f8a656e..437b0a6 100644
--- a/QuarkPlatformPkg/QuarkMin.dsc
+++ b/QuarkPlatformPkg/QuarkMin.dsc
@@ -2,7 +2,7 @@
 # Clanton Peak CRB platform with 32-bit DXE for 4MB/8MB flash devices.
 #
 # This package provides Clanton Peak CRB platform specific modules.
-# Copyright (c) 2013 - 2014 Intel Corporation.
+# Copyright (c) 2013 - 2016 Intel Corporation.
 #
 # This program and the accompanying materials
 # are licensed and made available under the terms and conditions of the BSD 
License
@@ -165,6 +165,7 @@ [LibraryClasses]
   #
   MtrrLib|QuarkSocPkg/QuarkNorthCluster/Library/MtrrLib/MtrrLib.inf
   LocalApicLib|UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf
+  MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
 
   #
   # Quark North Cluster
@@ -217,6 +218,7 @@ [LibraryClasses.IA32.PEIM,LibraryClasses.IA32.PEI_CORE]
   TimerLib|PcAtChipsetPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf
   
PlatformHelperLib|QuarkPlatformPkg/Library/PlatformHelperLib/PeiPlatformHelperLib.inf
   
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
+  MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
 !if $(SECURE_BOOT_ENABLE)
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
 !endif
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 40/48] UefiCpuPkg/CpuMpPei: Delete PeiMpServices.c and PeiMpServices.h

2016-08-02 Thread Jeff Fan
Move the code in PeiMpServices.c & PeiMpServices.h to CpuMpPei.c & CpuMpPei.h.

v3:
  1. Rename MpInitLibSwitchBSP to MpInitLibSwitchBSP
  2. Add PeiMpInitLib.inf in DSC file

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/CpuMpPei/CpuMpPei.c  | 395 ++
 UefiCpuPkg/CpuMpPei/CpuMpPei.h  | 332 +
 UefiCpuPkg/CpuMpPei/CpuMpPei.inf|   2 -
 UefiCpuPkg/CpuMpPei/PeiMpServices.c | 410 
 UefiCpuPkg/CpuMpPei/PeiMpServices.h | 354 ---
 5 files changed, 727 insertions(+), 766 deletions(-)
 delete mode 100644 UefiCpuPkg/CpuMpPei/PeiMpServices.c
 delete mode 100644 UefiCpuPkg/CpuMpPei/PeiMpServices.h

diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.c b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
index a36adf6..eaf99c7 100644
--- a/UefiCpuPkg/CpuMpPei/CpuMpPei.c
+++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
@@ -13,6 +13,401 @@
 **/
 
 #include "CpuMpPei.h"
+
+//
+// CPU MP PPI to be installed
+//
+EFI_PEI_MP_SERVICES_PPImMpServicesPpi = {
+  PeiGetNumberOfProcessors,
+  PeiGetProcessorInfo,
+  PeiStartupAllAPs,
+  PeiStartupThisAP,
+  PeiSwitchBSP,
+  PeiEnableDisableAP,
+  PeiWhoAmI,
+};
+
+EFI_PEI_PPI_DESCRIPTOR   mPeiCpuMpPpiDesc = {
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+  ,
+  
+};
+
+/**
+  This service retrieves the number of logical processor in the platform
+  and the number of those logical processors that are enabled on this boot.
+  This service may only be called from the BSP.
+
+  This function is used to retrieve the following information:
+- The number of logical processors that are present in the system.
+- The number of enabled logical processors in the system at the instant
+  this call is made.
+
+  Because MP Service Ppi provides services to enable and disable processors
+  dynamically, the number of enabled logical processors may vary during the
+  course of a boot session.
+
+  If this service is called from an AP, then EFI_DEVICE_ERROR is returned.
+  If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then
+  EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors
+  is returned in NumberOfProcessors, the number of currently enabled processor
+  is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.
+
+  @param[in]  PeiServices An indirect pointer to the PEI Services Table
+  published by the PEI Foundation.
+  @param[in]  ThisPointer to this instance of the PPI.
+  @param[out] NumberOfProcessors  Pointer to the total number of logical 
processors in
+  the system, including the BSP and disabled 
APs.
+  @param[out] NumberOfEnabledProcessors
+  Number of processors in the system that are 
enabled.
+
+  @retval EFI_SUCCESS The number of logical processors and enabled
+  logical processors was retrieved.
+  @retval EFI_DEVICE_ERRORThe calling processor is an AP.
+  @retval EFI_INVALID_PARAMETER   NumberOfProcessors is NULL.
+  NumberOfEnabledProcessors is NULL.
+**/
+EFI_STATUS
+EFIAPI
+PeiGetNumberOfProcessors (
+  IN  CONST EFI_PEI_SERVICES**PeiServices,
+  IN  EFI_PEI_MP_SERVICES_PPI   *This,
+  OUT UINTN *NumberOfProcessors,
+  OUT UINTN *NumberOfEnabledProcessors
+  )
+{
+  if ((NumberOfProcessors == NULL) || (NumberOfEnabledProcessors == NULL)) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  return MpInitLibGetNumberOfProcessors (
+   NumberOfProcessors,
+   NumberOfEnabledProcessors
+   );
+}
+
+/**
+  Gets detailed MP-related information on the requested processor at the
+  instant this call is made. This service may only be called from the BSP.
+
+  This service retrieves detailed MP-related information about any processor
+  on the platform. Note the following:
+- The processor information may change during the course of a boot session.
+- The information presented here is entirely MP related.
+
+  Information regarding the number of caches and their sizes, frequency of 
operation,
+  slot numbers is all considered platform-related information and is not 
provided
+  by this service.
+
+  @param[in]  PeiServices An indirect pointer to the PEI Services Table
+  published by the PEI Foundation.
+  @param[in]  ThisPointer to this instance of the PPI.
+  @param[in]  ProcessorNumber Pointer to the total number of logical 
processors in
+  the system, including the BSP and 

[edk2] [Patch v5 27/48] UefiCpuPkg/MpInitLib: Implementation of MpInitLibGetNumberOfProcessors()

2016-08-02 Thread Jeff Fan
Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 39 +++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 7ae6559..cbaeccc 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -956,6 +956,7 @@ MpInitLibWhoAmI (
 {
   return EFI_UNSUPPORTED;
 }
+
 /**
   Retrieves the number of logical processor in the platform and the number of
   those logical processors that are enabled on this boot. This service may only
@@ -983,9 +984,45 @@ MpInitLibGetNumberOfProcessors (
   OUT UINTN *NumberOfEnabledProcessors OPTIONAL
   )
 {
-  return EFI_UNSUPPORTED;
+  CPU_MP_DATA *CpuMpData;
+  UINTN   CallerNumber;
+  UINTN   ProcessorNumber;
+  UINTN   EnabledProcessorNumber;
+  UINTN   Index;
+
+  CpuMpData = GetCpuMpData ();
+
+  if ((NumberOfProcessors == NULL) && (NumberOfEnabledProcessors == NULL)) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // Check whether caller processor is BSP
+  //
+  MpInitLibWhoAmI ();
+  if (CallerNumber != CpuMpData->BspNumber) {
+return EFI_DEVICE_ERROR;
+  }
+
+  ProcessorNumber= CpuMpData->CpuCount;
+  EnabledProcessorNumber = 0;
+  for (Index = 0; Index < ProcessorNumber; Index++) {
+if (GetApState (>CpuData[Index]) != CpuStateDisabled) {
+  EnabledProcessorNumber ++;
+}
+  }
+
+  if (NumberOfProcessors != NULL) {
+*NumberOfProcessors = ProcessorNumber;
+  }
+  if (NumberOfEnabledProcessors != NULL) {
+*NumberOfEnabledProcessors = EnabledProcessorNumber;
+  }
+
+  return EFI_SUCCESS;
 }
 
+
 /**
   Get pointer to CPU MP Data structure from GUIDed HOB.
 
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 31/48] UefiCpuPkg/MpInitLib: Implementation of MpInitLibEnableDisableAP()

2016-08-02 Thread Jeff Fan
v4:
  1. Simply the internal function MpInitLibEnableDisableAP()'s function
 header due to it is duplicated with MpInitLibEnableDisableAP().
v3:
  1. Use CamelCase for mCheckAllAPsEvent, mStopCheckAllApsStatus.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 20 +++-
 UefiCpuPkg/Library/MpInitLib/MpLib.c| 56 +
 UefiCpuPkg/Library/MpInitLib/MpLib.h| 21 +
 UefiCpuPkg/Library/MpInitLib/PeiMpLib.c |  2 +-
 4 files changed, 97 insertions(+), 2 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index 785653b..988920f 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -454,5 +454,23 @@ MpInitLibEnableDisableAP (
   IN  UINT32*HealthFlag OPTIONAL
   )
 {
-  return EFI_UNSUPPORTED;
+  EFI_STATUS Status;
+  BOOLEANTempStopCheckState;
+
+  TempStopCheckState = FALSE;
+  //
+  // temporarily stop checkAllAPsStatus for initialize parameters.
+  //
+  if (!mStopCheckAllApsStatus) {
+mStopCheckAllApsStatus = TRUE;
+TempStopCheckState = TRUE;
+  }
+
+  Status = EnableDisableApWorker (ProcessorNumber, EnableAP, HealthFlag);
+
+  if (TempStopCheckState) {
+mStopCheckAllApsStatus = FALSE;
+  }
+
+  return Status;
 }
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 8ae08f4..3a266e9 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -1239,6 +1239,62 @@ SwitchBSPWorker (
 }
 
 /**
+  Worker function to let the caller enable or disable an AP from this point 
onward.
+  This service may only be called from the BSP.
+
+  @param[in] ProcessorNumber   The handle number of AP.
+  @param[in] EnableAP  Specifies the new state for the processor for
+   enabled, FALSE for disabled.
+  @param[in] HealthFlagIf not NULL, a pointer to a value that specifies
+   the new health status of the AP.
+
+  @retval EFI_SUCCESS  The specified AP was enabled or disabled 
successfully.
+  @retval others   Failed to Enable/Disable AP.
+
+**/
+EFI_STATUS
+EnableDisableApWorker (
+  IN  UINTN ProcessorNumber,
+  IN  BOOLEAN   EnableAP,
+  IN  UINT32*HealthFlag OPTIONAL
+  )
+{
+  CPU_MP_DATA   *CpuMpData;
+  UINTN CallerNumber;
+
+  CpuMpData = GetCpuMpData ();
+
+  //
+  // Check whether caller processor is BSP
+  //
+  MpInitLibWhoAmI ();
+  if (CallerNumber != CpuMpData->BspNumber) {
+return EFI_DEVICE_ERROR;
+  }
+
+  if (ProcessorNumber == CpuMpData->BspNumber) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  if (ProcessorNumber >= CpuMpData->CpuCount) {
+return EFI_NOT_FOUND;
+  }
+
+  if (!EnableAP) {
+SetApState (>CpuData[ProcessorNumber], CpuStateDisabled);
+  } else {
+SetApState (>CpuData[ProcessorNumber], CpuStateIdle);
+  }
+
+  if (HealthFlag != NULL) {
+CpuMpData->CpuData[ProcessorNumber].CpuHealthy =
+  (BOOLEAN) ((*HealthFlag & PROCESSOR_HEALTH_STATUS_BIT) != 0);
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
   This return the handle number for the calling processor.  This service may be
   called from the BSP and APs.
 
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index bfc7fb7..f8b172f 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -365,6 +365,27 @@ SwitchBSPWorker (
   );
 
 /**
+  Worker function to let the caller enable or disable an AP from this point 
onward.
+  This service may only be called from the BSP.
+
+  @param[in] ProcessorNumber   The handle number of AP.
+  @param[in] EnableAP  Specifies the new state for the processor for
+   enabled, FALSE for disabled.
+  @param[in] HealthFlagIf not NULL, a pointer to a value that specifies
+   the new health status of the AP.
+
+  @retval EFI_SUCCESS  The specified AP was enabled or disabled 
successfully.
+  @retval others   Failed to Enable/Disable AP.
+
+**/
+EFI_STATUS
+EnableDisableApWorker (
+  IN  UINTN ProcessorNumber,
+  IN  BOOLEAN   EnableAP,
+  IN  UINT32*HealthFlag OPTIONAL
+  );
+
+/**
   Get pointer to CPU MP Data structure from GUIDed HOB.
 
   @return  The pointer to CPU MP Data structure.
diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
index cdec010..fe585bd 100644
--- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
+++ 

[edk2] [Patch v5 35/48] UefiCpuPkg/MpInitLib: Place APs in safe loop before hand-off to OS

2016-08-02 Thread Jeff Fan
Register Exit Boot Service callback function MpInitExitBootServicesCallback() to
place AP one safe loop before hand-off to OS.

Allocated one reserved memory and copy the AsmRellocateApLoop() code into it. It
could avoid the CPU Dxe driver (located in Boot Service data range) crashed
after Exit Boot Service event.
Place AP into the target Cx-State (specified by PcdCpuApTargetCstate) could save
power if Monitor-mwait feature supported.
In long mode, switch AP into protected mode could let AP not require page table
when executing this safe loop. Page Table (located in Boot Service data range)
may crashed after Exit Boot Service event.

v3:
  1. Rename *RellocateAp* to *RelocateAp*

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 97 +
 UefiCpuPkg/Library/MpInitLib/MpLib.h| 11 
 2 files changed, 108 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index 1043bec..42d320f 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -21,6 +21,7 @@
 
 CPU_MP_DATA  *mCpuMpData = NULL;
 EFI_EVENTmCheckAllApsEvent = NULL;
+EFI_EVENTmMpInitExitBootServicesEvent = NULL;
 volatile BOOLEAN mStopCheckAllApsStatus = TRUE;
 
 
@@ -186,6 +187,94 @@ CheckApsStatus (
 }
 
 /**
+  Get Protected mode code segment from current GDT table.
+
+  @returen  Protected mode code segment value.
+**/
+UINT16
+GetProtectedModeCS (
+  VOID
+  )
+{
+  IA32_DESCRIPTOR  GdtrDesc;
+  IA32_SEGMENT_DESCRIPTOR  *GdtEntry;
+  UINTNGdtEntryCount;
+  UINT16   Index;
+
+  Index = (UINT16) -1;
+  AsmReadGdtr ();
+  GdtEntryCount = (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR);
+  GdtEntry = (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base;
+  for (Index = 0; Index < GdtEntryCount; Index++) {
+if (GdtEntry->Bits.L == 0) {
+  if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.L == 0) {
+break;
+  }
+}
+GdtEntry++;
+  }
+  ASSERT (Index != -1);
+  return Index * 8;
+}
+
+/**
+  Do sync on APs.
+
+  @param[in, out] Buffer  Pointer to private data buffer.
+**/
+VOID
+EFIAPI
+RelocateApLoop (
+  IN OUT VOID  *Buffer
+  )
+{
+  CPU_MP_DATA*CpuMpData;
+  BOOLEANMwaitSupport;
+  ASM_RELOCATE_AP_LOOP   AsmRelocateApLoopFunc;
+
+  CpuMpData= GetCpuMpData ();
+  MwaitSupport = IsMwaitSupport ();
+  AsmRelocateApLoopFunc = (ASM_RELOCATE_AP_LOOP) (UINTN) Buffer;
+  AsmRelocateApLoopFunc (MwaitSupport, CpuMpData->ApTargetCState, 
CpuMpData->PmCodeSegment);
+  //
+  // It should never reach here
+  //
+  ASSERT (FALSE);
+}
+
+/**
+  Callback function for ExitBootServices.
+
+  @param[in]  Event Event whose notification function is being 
invoked.
+  @param[in]  Context   The pointer to the notification function's 
context,
+which is implementation-dependent.
+
+**/
+VOID
+EFIAPI
+MpInitExitBootServicesCallback (
+  IN EFI_EVENTEvent,
+  IN VOID *Context
+  )
+{
+  CPU_MP_DATA   *CpuMpData;
+  VOID  *ReservedApLoopFunc;
+  //
+  // Avoid APs access invalid buff data which allocated by BootServices,
+  // so we will allocate reserved data for AP loop code.
+  //
+  CpuMpData = GetCpuMpData ();
+  CpuMpData->PmCodeSegment = GetProtectedModeCS ();
+  CpuMpData->ApLoopMode = PcdGet8 (PcdCpuApLoopMode);
+  ReservedApLoopFunc = AllocateReservedCopyPool (
+ CpuMpData->AddressMap.RelocateApLoopFuncSize,
+ CpuMpData->AddressMap.RelocateApLoopFuncAddress
+ );
+  WakeUpAP (CpuMpData, TRUE, 0, RelocateApLoop, ReservedApLoopFunc);
+  DEBUG ((DEBUG_INFO, "MpInitExitBootServicesCallback() done!\n"));
+}
+
+/**
   Initialize global data for MP support.
 
   @param[in] CpuMpData  The pointer to CPU MP Data structure.
@@ -217,6 +306,14 @@ InitMpGlobalData (
   AP_CHECK_INTERVAL
   );
   ASSERT_EFI_ERROR (Status);
+  Status = gBS->CreateEvent (
+  EVT_SIGNAL_EXIT_BOOT_SERVICES,
+  TPL_CALLBACK,
+  MpInitExitBootServicesCallback,
+  NULL,
+  
+  );
+  ASSERT_EFI_ERROR (Status);
 }
 
 /**
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index 06af7cc..e53deb4 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -520,6 +520,17 @@ MicrocodeDetect (
   );
 
 /**
+  Detect whether Mwait-monitor feature is supported.
+
+  @retval TRUEMwait-monitor feature is supported.

[edk2] [Patch v5 38/48] UefiCpuPkg/CpuMpPei: Consume MpInitLib to produce CPU MP PPI services

2016-08-02 Thread Jeff Fan
Consume MP initialize library to produce CPU MP PPI, it could simply the code.

Add STATIC for some internal functions to avoid build issue with the same
functions name in PeiMpInit instance. They will be removed by the next patch.

v4:
  1. Update BistData type from UINT32 to EFI_HEALTH_FLAGS.

v3:
  1. Rename MpInitLibSwitchBSP to MpInitLibSwitchBSP
  2. Add PeiMpInitLib.inf in DSC file

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/CpuMpPei/CpuBist.c   |  53 ++--
 UefiCpuPkg/CpuMpPei/CpuMpPei.c  |  70 --
 UefiCpuPkg/CpuMpPei/CpuMpPei.h  |  10 +-
 UefiCpuPkg/CpuMpPei/CpuMpPei.inf|   1 +
 UefiCpuPkg/CpuMpPei/PeiMpServices.c | 469 +++-
 UefiCpuPkg/UefiCpuPkg.dsc   |   1 +
 6 files changed, 113 insertions(+), 491 deletions(-)

diff --git a/UefiCpuPkg/CpuMpPei/CpuBist.c b/UefiCpuPkg/CpuMpPei/CpuBist.c
index 5629245..641eb10 100644
--- a/UefiCpuPkg/CpuMpPei/CpuBist.c
+++ b/UefiCpuPkg/CpuMpPei/CpuBist.c
@@ -44,15 +44,18 @@ SecPlatformInformation2 (
  OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2
   )
 {
-  PEI_CPU_MP_DATA  *PeiCpuMpData;
   UINTNBistInformationSize;
   UINTNCpuIndex;
   EFI_SEC_PLATFORM_INFORMATION_CPU *CpuInstance;
+  EFI_PROCESSOR_INFORMATIONProcessorInfo;
+  EFI_HEALTH_FLAGS BistData;
+  UINTNNumberOfProcessors;
+  UINTNNumberOfEnabledProcessors;
 
-  PeiCpuMpData = GetMpHobData ();
+  MpInitLibGetNumberOfProcessors(, 
);
 
   BistInformationSize = sizeof (EFI_SEC_PLATFORM_INFORMATION_RECORD2) +
-sizeof (EFI_SEC_PLATFORM_INFORMATION_CPU) * 
PeiCpuMpData->CpuCount;
+sizeof (EFI_SEC_PLATFORM_INFORMATION_CPU) * 
NumberOfProcessors;
   //
   // return the information size if input buffer size is too small
   //
@@ -61,11 +64,12 @@ SecPlatformInformation2 (
 return EFI_BUFFER_TOO_SMALL;
   }
 
-  PlatformInformationRecord2->NumberOfCpus = PeiCpuMpData->CpuCount;
+  PlatformInformationRecord2->NumberOfCpus = (UINT32)NumberOfProcessors;
   CpuInstance = PlatformInformationRecord2->CpuInstance;
-  for (CpuIndex = 0; CpuIndex < PeiCpuMpData->CpuCount; CpuIndex ++) {
-CpuInstance[CpuIndex].CpuLocation= 
PeiCpuMpData->CpuData[CpuIndex].ApicId;
-CpuInstance[CpuIndex].InfoRecord.IA32HealthFlags = 
PeiCpuMpData->CpuData[CpuIndex].Health;
+  for (CpuIndex = 0; CpuIndex < NumberOfProcessors; CpuIndex ++) {
+MpInitLibGetProcessorInfo (CpuIndex, , );
+CpuInstance[CpuIndex].CpuLocation = (UINT32) ProcessorInfo.ProcessorId;
+CpuInstance[CpuIndex].InfoRecord.IA32HealthFlags = BistData;
   }
 
   return EFI_SUCCESS;
@@ -152,13 +156,11 @@ GetBistInfoFromPpi (
   or SEC Platform Information PPI.
 
   @param PeiServices Pointer to PEI Services Table
-  @param PeiCpuMpDataPointer to PEI CPU MP Data
 
 **/
 VOID
 CollectBistDataFromPpi (
-  IN CONST EFI_PEI_SERVICES **PeiServices,
-  IN PEI_CPU_MP_DATA*PeiCpuMpData
+  IN CONST EFI_PEI_SERVICES **PeiServices
   )
 {
   EFI_STATUSStatus;
@@ -170,7 +172,12 @@ CollectBistDataFromPpi (
   EFI_SEC_PLATFORM_INFORMATION_CPU  BspCpuInstance;
   UINTN ProcessorNumber;
   UINTN CpuIndex;
-  PEI_CPU_DATA  *CpuData;
+  EFI_PROCESSOR_INFORMATION ProcessorInfo;
+  EFI_HEALTH_FLAGS  BistData;
+  UINTN NumberOfProcessors;
+  UINTN NumberOfEnabledProcessors;
+
+  MpInitLibGetNumberOfProcessors(, 
);
 
   SecPlatformInformation2 = NULL;
   SecPlatformInformation  = NULL;
@@ -215,21 +222,18 @@ CollectBistDataFromPpi (
   DEBUG ((EFI_D_INFO, "Does not find any stored CPU BIST information from 
PPI!\n"));
 }
   }
-  for (ProcessorNumber = 0; ProcessorNumber < PeiCpuMpData->CpuCount; 
ProcessorNumber ++) {
-CpuData = >CpuData[ProcessorNumber];
+  for (ProcessorNumber = 0; ProcessorNumber < NumberOfProcessors; 
ProcessorNumber ++) {
+MpInitLibGetProcessorInfo (ProcessorNumber, , );
 for (CpuIndex = 0; CpuIndex < NumberOfData; CpuIndex ++) {
   ASSERT (CpuInstance != NULL);
-  if (CpuData->ApicId == CpuInstance[CpuIndex].CpuLocation) {
+  if (ProcessorInfo.ProcessorId == CpuInstance[CpuIndex].CpuLocation) {
 //
 // Update processor's BIST data if it is already stored before
 //
-CpuData->Health = CpuInstance[CpuIndex].InfoRecord.IA32HealthFlags;
+BistData = 

[edk2] [Patch v5 30/48] UefiCpuPkg/MpInitLib: Implementation of MpInitLibSwitchBSP()

2016-08-02 Thread Jeff Fan
v4:
  1. Simply the internal function SwitchBSPWorker()'s comment header
 due to it is duplicated with MpInitLibSwitchBSP().

v3:
  1. Rename MpInitLibSwitchBsp to MpInitLibSwitchBSP.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c |  26 +-
 UefiCpuPkg/Library/MpInitLib/MpLib.c| 144 ++--
 UefiCpuPkg/Library/MpInitLib/MpLib.h|  53 
 UefiCpuPkg/Library/MpInitLib/PeiMpLib.c |   2 +-
 4 files changed, 218 insertions(+), 7 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index 762d76d..785653b 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -389,7 +389,31 @@ MpInitLibSwitchBSP (
   IN BOOLEAN   EnableOldBSP
   )
 {
-  return EFI_UNSUPPORTED;
+  EFI_STATUSStatus;
+  BOOLEAN   OldInterruptState;
+
+  //
+  // Before send both BSP and AP to a procedure to exchange their roles,
+  // interrupt must be disabled. This is because during the exchange role
+  // process, 2 CPU may use 1 stack. If interrupt happens, the stack will
+  // be corrupted, since interrupt return address will be pushed to stack
+  // by hardware.
+  //
+  OldInterruptState = SaveAndDisableInterrupts ();
+
+  //
+  // Mask LINT0 & LINT1 for the old BSP
+  //
+  DisableLvtInterrupts ();
+
+  Status = SwitchBSPWorker (ProcessorNumber, EnableOldBSP);
+
+  //
+  // Restore interrupt state.
+  //
+  SetInterruptState (OldInterruptState);
+
+  return Status;
 }
 
 /**
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 5fbcb26..8ae08f4 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -184,6 +184,26 @@ ExtractProcessorLocation (
 }
 
 /**
+  Worker function for SwitchBSP().
+
+  Worker function for SwitchBSP(), assigned to the AP which is intended
+  to become BSP.
+
+  @param[in] Buffer   Pointer to CPU MP Data
+**/
+VOID
+EFIAPI
+FutureBSPProc (
+  IN  VOID*Buffer
+  )
+{
+  CPU_MP_DATA *DataInHob;
+
+  DataInHob = (CPU_MP_DATA *) Buffer;
+  AsmExchangeRole (>APInfo, >BSPInfo);
+}
+
+/**
   Get the Application Processors state.
 
   @param[in]  CpuDataThe pointer to CPU_AP_DATA of specified AP
@@ -646,11 +666,20 @@ ApWakeupFunction (
   // Invoke AP function here
   //
   Procedure (Parameter);
-  //
-  // Re-get the CPU APICID and Initial APICID
-  //
-  CpuMpData->CpuData[ProcessorNumber].ApicId= GetApicId ();
-  CpuMpData->CpuData[ProcessorNumber].InitialApicId = GetInitialApicId 
();
+  if (CpuMpData->SwitchBspFlag) {
+//
+// Re-get the processor number due to BSP/AP maybe exchange in AP 
function
+//
+GetProcessorNumber (CpuMpData, );
+CpuMpData->CpuData[ProcessorNumber].ApFunction = 0;
+CpuMpData->CpuData[ProcessorNumber].ApFunctionArgument = 0;
+  } else {
+//
+// Re-get the CPU APICID and Initial APICID
+//
+CpuMpData->CpuData[ProcessorNumber].ApicId= GetApicId ();
+CpuMpData->CpuData[ProcessorNumber].InitialApicId = 
GetInitialApicId ();
+  }
 }
 SetApState (>CpuData[ProcessorNumber], CpuStateFinished);
   }
@@ -941,6 +970,7 @@ MpInitLibInitialize (
   CpuMpData->CpuCount = 1;
   CpuMpData->BspNumber= 0;
   CpuMpData->WaitEvent= NULL;
+  CpuMpData->SwitchBspFlag= FALSE;
   CpuMpData->CpuData  = (CPU_AP_DATA *) (CpuMpData + 1);
   CpuMpData->CpuInfoInHob = (UINT64) (UINTN) (CpuMpData->CpuData + 
MaxLogicalProcessorNumber);
   InitializeSpinLock(>MpLock);
@@ -1103,6 +1133,110 @@ MpInitLibGetProcessorInfo (
   return EFI_SUCCESS;
 }
 
+/**
+  Worker function to switch the requested AP to be the BSP from that point 
onward.
+
+  @param[in] ProcessorNumber   The handle number of AP that is to become the 
new BSP.
+  @param[in] EnableOldBSP  If TRUE, then the old BSP will be listed as an
+   enabled AP. Otherwise, it will be disabled.
+
+  @retval EFI_SUCCESS  BSP successfully switched.
+  @retval others   Failed to switch BSP. 
+
+**/
+EFI_STATUS
+SwitchBSPWorker (
+  IN UINTN ProcessorNumber,
+  IN BOOLEAN   EnableOldBSP
+  )
+{
+  CPU_MP_DATA  *CpuMpData;
+  UINTNCallerNumber;
+  CPU_STATEState;
+  MSR_IA32_APIC_BASE_REGISTER  ApicBaseMsr;
+
+  CpuMpData = GetCpuMpData ();
+
+  //
+  // Check whether caller processor is BSP
+ 

[edk2] [Patch v5 21/48] UefiCpuPkg/MpInitLib: Fill MP_CPU_EXCHANGE_INFO fields

2016-08-02 Thread Jeff Fan
FillExchangeInfoData() is used to fill MP_CPU_EXCHANGE_INFO date exchanged
between C code and assembly code of AP reset vector.

v5:
  1. Reference ApWakeupFunction instead of ApCFunction.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 79 
 1 file changed, 79 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index a4a2c44..d08 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -17,6 +17,47 @@
 EFI_GUID mCpuInitMpLibHobGuid = CPU_INIT_MP_LIB_HOB_GUID;
 
 /**
+  The function will check if BSP Execute Disable is enabled.
+  DxeIpl may have enabled Execute Disable for BSP,
+  APs need to get the status and sync up the settings.
+
+  @retval TRUE  BSP Execute Disable is enabled.
+  @retval FALSE BSP Execute Disable is not enabled.
+**/
+BOOLEAN
+IsBspExecuteDisableEnabled (
+  VOID
+  )
+{
+  UINT32  Eax;
+  CPUID_EXTENDED_CPU_SIG_EDX  Edx;
+  MSR_IA32_EFER_REGISTER  EferMsr;
+  BOOLEAN Enabled;
+
+  Enabled = FALSE;
+  AsmCpuid (CPUID_EXTENDED_FUNCTION, , NULL, NULL, NULL);
+  if (Eax >= CPUID_EXTENDED_CPU_SIG) {
+AsmCpuid (CPUID_EXTENDED_CPU_SIG, NULL, NULL, NULL, );
+//
+// CPUID 0x8001
+// Bit 20: Execute Disable Bit available.
+//
+if (Edx.Bits.NX != 0) {
+  EferMsr.Uint64 = AsmReadMsr64 (MSR_IA32_EFER);
+  //
+  // MSR 0xC080
+  // Bit 11: Execute Disable Bit enable.
+  //
+  if (EferMsr.Bits.NXE != 0) {
+Enabled = TRUE;
+  }
+}
+  }
+
+  return Enabled;
+}
+
+/**
   Get the Application Processors state.
 
   @param[in]  CpuDataThe pointer to CPU_AP_DATA of specified AP
@@ -407,6 +448,44 @@ ApWakeupFunction (
 }
 
 /**
+  This function will fill the exchange info structure.
+
+  @param[in] CpuMpData  Pointer to CPU MP Data
+
+**/
+VOID
+FillExchangeInfoData (
+  IN CPU_MP_DATA   *CpuMpData
+  )
+{
+  volatile MP_CPU_EXCHANGE_INFO*ExchangeInfo;
+
+  ExchangeInfo  = CpuMpData->MpCpuExchangeInfo;
+  ExchangeInfo->Lock= 0;
+  ExchangeInfo->StackStart  = CpuMpData->Buffer;
+  ExchangeInfo->StackSize   = CpuMpData->CpuApStackSize;
+  ExchangeInfo->BufferStart = CpuMpData->WakeupBuffer;
+  ExchangeInfo->ModeOffset  = CpuMpData->AddressMap.ModeEntryOffset;
+
+  ExchangeInfo->CodeSegment = AsmReadCs ();
+  ExchangeInfo->DataSegment = AsmReadDs ();
+
+  ExchangeInfo->Cr3 = AsmReadCr3 ();
+
+  ExchangeInfo->CFunction   = (UINTN) ApWakeupFunction;
+  ExchangeInfo->NumApsExecuting = 0;
+  ExchangeInfo->CpuMpData   = CpuMpData;
+
+  ExchangeInfo->EnableExecuteDisable = IsBspExecuteDisableEnabled ();
+
+  //
+  // Get the BSP's data of GDT and IDT
+  //
+  AsmReadGdtr ((IA32_DESCRIPTOR *) >GdtrProfile);
+  AsmReadIdtr ((IA32_DESCRIPTOR *) >IdtrProfile);
+}
+
+/**
   MP Initialize Library initialization.
 
   This service will allocate AP reset vector and wakeup all APs to do APs
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 26/48] UefiCpuPkg/MpInitLib: Skip collect processor count if GUIDed HOB exist

2016-08-02 Thread Jeff Fan
If GUIDed HOB mCpuInitMpLibHobGuid exists, we could get the processor count and
processor APICID and Initial APICID from CPU_INFO_IN_HOB. We needn't to delay
for broadcast INIT-SIPI-SIPI results and could improve performance.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 60 +---
 1 file changed, 55 insertions(+), 5 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index d6eef13..7ae6559 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -765,6 +765,8 @@ MpInitLibInitialize (
   VOID
   )
 {
+  CPU_MP_DATA  *OldCpuMpData;
+  CPU_INFO_IN_HOB  *CpuInfoInHob;
   UINT32   MaxLogicalProcessorNumber;
   UINT32   ApStackSize;
   MP_ASSEMBLY_ADDRESS_MAP  AddressMap;
@@ -778,7 +780,13 @@ MpInitLibInitialize (
   UINTNIndex;
   UINTNApResetVectorSize;
   UINTNBackupBufferAddr;
-  MaxLogicalProcessorNumber = PcdGet32(PcdCpuMaxLogicalProcessorNumber);
+
+  OldCpuMpData = GetCpuMpDataFromGuidedHob ();
+  if (OldCpuMpData == NULL) {
+MaxLogicalProcessorNumber = PcdGet32(PcdCpuMaxLogicalProcessorNumber);
+  } else {
+MaxLogicalProcessorNumber = OldCpuMpData->CpuCount;
+  }
 
   AsmGetAddressMap ();
   ApResetVectorSize = AddressMap.RendezvousFunnelSize + sizeof 
(MP_CPU_EXCHANGE_INFO);
@@ -843,12 +851,53 @@ MpInitLibInitialize (
   //
   MtrrGetAllMtrrs (>MtrrTable);
 
+  if (OldCpuMpData == NULL) {
+//
+// Wakeup all APs and calculate the processor count in system
+//
+CollectProcessorCount (CpuMpData);
+  } else {
+//
+// APs have been wakeup before, just get the CPU Information
+// from HOB
+//
+CpuMpData->CpuCount  = OldCpuMpData->CpuCount;
+CpuMpData->BspNumber = OldCpuMpData->BspNumber;
+CpuMpData->InitFlag  = ApInitReconfig;
+CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) OldCpuMpData->CpuInfoInHob;
+for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
+  InitializeSpinLock(>CpuData[Index].ApLock);
+  CpuMpData->CpuData[Index].ApicId= CpuInfoInHob[Index].ApicId;
+  CpuMpData->CpuData[Index].InitialApicId = 
CpuInfoInHob[Index].InitialApicId;
+  if (CpuMpData->CpuData[Index].InitialApicId >= 255) {
+CpuMpData->X2ApicEnable = TRUE;
+  }
+  CpuMpData->CpuData[Index].Health = CpuInfoInHob[Index].Health;
+  CpuMpData->CpuData[Index].CpuHealthy = (CpuMpData->CpuData[Index].Health 
== 0)? TRUE:FALSE;
+  CpuMpData->CpuData[Index].ApFunction = 0;
+  CopyMem (
+>CpuData[Index].VolatileRegisters,
+>CpuData[0].VolatileRegisters,
+sizeof (CPU_VOLATILE_REGISTERS)
+);
+}
+//
+// Wakeup APs to do some AP initialize sync
+//
+WakeUpAP (CpuMpData, TRUE, 0, ApInitializeSync, CpuMpData);
+//
+// Wait for all APs finished initialization
+//
+while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) {
+  CpuPause ();
+}
+CpuMpData->InitFlag = ApInitDone;
+for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
+  SetApState (>CpuData[Index], CpuStateIdle);
+}
+  }
 
   //
-  // Wakeup all APs and calculate the processor count in system
-  //
-  CollectProcessorCount (CpuMpData);
-  //
   // Initialize global data for MP support
   //
   InitMpGlobalData (CpuMpData);
@@ -936,6 +985,7 @@ MpInitLibGetNumberOfProcessors (
 {
   return EFI_UNSUPPORTED;
 }
+
 /**
   Get pointer to CPU MP Data structure from GUIDed HOB.
 
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 32/48] UefiCpuPkg/MpInitLib: Check APs Status and update APs status

2016-08-02 Thread Jeff Fan
v3:
  1. Use CamelCase for CheckAndUpdateApsStatus().

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c |  37 
 UefiCpuPkg/Library/MpInitLib/MpLib.c| 326 
 UefiCpuPkg/Library/MpInitLib/MpLib.h|  42 +++-
 UefiCpuPkg/Library/MpInitLib/PeiMpLib.c |  11 ++
 4 files changed, 415 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index 988920f..bd13240 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -120,6 +120,43 @@ CheckAndUpdateApsStatus (
   VOID
   )
 {
+  UINTN   ProcessorNumber;
+  EFI_STATUS  Status;
+  CPU_MP_DATA *CpuMpData;
+
+  CpuMpData = GetCpuMpData ();
+
+  //
+  // First, check whether pending StartupAllAPs() exists.
+  //
+  if (CpuMpData->WaitEvent != NULL) {
+
+Status = CheckAllAPs ();
+//
+// If all APs finish for StartupAllAPs(), signal the WaitEvent for it.
+//
+if (Status != EFI_NOT_READY) {
+  Status = gBS->SignalEvent (CpuMpData->WaitEvent);
+  CpuMpData->WaitEvent = NULL;
+}
+  }
+
+  //
+  // Second, check whether pending StartupThisAPs() callings exist.
+  //
+  for (ProcessorNumber = 0; ProcessorNumber < CpuMpData->CpuCount; 
ProcessorNumber++) {
+
+if (CpuMpData->CpuData[ProcessorNumber].WaitEvent == NULL) {
+  continue;
+}
+
+Status = CheckThisAP (ProcessorNumber);
+
+if (Status != EFI_NOT_READY) {
+  gBS->SignalEvent (CpuMpData->CpuData[ProcessorNumber].WaitEvent);
+ CpuMpData->CpuData[ProcessorNumber].WaitEvent = NULL;
+}
+  }
 }
 
 /**
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 3a266e9..2691af2 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -902,6 +902,332 @@ WakeUpAP (
 }
 
 /**
+  Calculate timeout value and return the current performance counter value.
+
+  Calculate the number of performance counter ticks required for a timeout.
+  If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
+  as infinity.
+
+  @param[in]  TimeoutInMicroseconds   Timeout value in microseconds.
+  @param[out] CurrentTime Returns the current value of the 
performance counter.
+
+  @return Expected time stamp counter for timeout.
+  If TimeoutInMicroseconds is 0, return value is also 0, which is 
recognized
+  as infinity.
+
+**/
+UINT64
+CalculateTimeout (
+  IN  UINTN   TimeoutInMicroseconds,
+  OUT UINT64  *CurrentTime
+  )
+{
+  //
+  // Read the current value of the performance counter
+  //
+  *CurrentTime = GetPerformanceCounter ();
+
+  //
+  // If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
+  // as infinity.
+  //
+  if (TimeoutInMicroseconds == 0) {
+return 0;
+  }
+
+  //
+  // GetPerformanceCounterProperties () returns the timestamp counter's 
frequency
+  // in Hz. So multiply the return value with TimeoutInMicroseconds and then 
divide
+  // it by 1,000,000, to get the number of ticks for the timeout value.
+  //
+  return DivU64x32 (
+   MultU64x64 (
+ GetPerformanceCounterProperties (NULL, NULL),
+ TimeoutInMicroseconds
+ ),
+   100
+   );
+}
+
+/**
+  Checks whether timeout expires.
+
+  Check whether the number of elapsed performance counter ticks required for
+  a timeout condition has been reached.
+  If Timeout is zero, which means infinity, return value is always FALSE.
+
+  @param[in, out]  PreviousTime   On input,  the value of the performance 
counter
+  when it was last read.
+  On output, the current value of the 
performance
+  counter
+  @param[in]   TotalTime  The total amount of elapsed time in 
performance
+  counter ticks.
+  @param[in]   TimeoutThe number of performance counter ticks 
required
+  to reach a timeout condition.
+
+  @retval TRUEA timeout condition has been reached.
+  @retval FALSE   A timeout condition has not been reached.
+
+**/
+BOOLEAN
+CheckTimeout (
+  IN OUT UINT64  *PreviousTime,
+  IN UINT64  *TotalTime,
+  IN UINT64  Timeout
+  )
+{
+  UINT64  Start;
+  UINT64  End;
+  UINT64  CurrentTime;
+  INT64   Delta;
+  INT64   Cycle;
+
+  if (Timeout == 0) {
+return FALSE;
+  }
+  GetPerformanceCounterProperties (, );
+  Cycle = End - Start;
+  if (Cycle < 0) {
+Cycle = -Cycle;
+  }
+  Cycle++;
+  CurrentTime = GetPerformanceCounter();
+  Delta 

[edk2] [Patch v5 29/48] UefiCpuPkg/MpInitLib: Implementation of MpInitLibWhoAmI()

2016-08-02 Thread Jeff Fan
v5:
  1. Move checking ProcessNumber before calling GetCpuMpData.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index d0473fd..5fbcb26 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -1126,7 +1126,15 @@ MpInitLibWhoAmI (
   OUT UINTN*ProcessorNumber
   )
 {
-  return EFI_UNSUPPORTED;
+  CPU_MP_DATA   *CpuMpData;
+
+  if (ProcessorNumber == NULL) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  CpuMpData = GetCpuMpData ();
+
+  return GetProcessorNumber (CpuMpData, ProcessorNumber);
 }
 
 /**
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 28/48] UefiCpuPkg/MpInitLib: Implementation of MpInitLibGetProcessorInfo()

2016-08-02 Thread Jeff Fan
v5:
  1. Remove (-1) and use the clean code to calculate the Location->Thread
 and Location->Core.

v4:
  1. Update HealthData type from UINT32 to EFI_HEALTH_FLAGS

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 174 ++-
 1 file changed, 173 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index cbaeccc..d0473fd 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -58,6 +58,132 @@ IsBspExecuteDisableEnabled (
 }
 
 /**
+  Get CPU Package/Core/Thread location information.
+
+  @param[in]  InitialApicId CPU APIC ID
+  @param[out] Location  Pointer to CPU location information
+**/
+VOID
+ExtractProcessorLocation (
+  IN  UINT32 InitialApicId,
+  OUT EFI_CPU_PHYSICAL_LOCATION  *Location
+  )
+{
+  BOOLEANTopologyLeafSupported;
+  UINTN  ThreadBits;
+  UINTN  CoreBits;
+  CPUID_VERSION_INFO_EBX VersionInfoEbx;
+  CPUID_VERSION_INFO_EDX VersionInfoEdx;
+  CPUID_CACHE_PARAMS_EAX CacheParamsEax;
+  CPUID_EXTENDED_TOPOLOGY_EAXExtendedTopologyEax;
+  CPUID_EXTENDED_TOPOLOGY_EBXExtendedTopologyEbx;
+  CPUID_EXTENDED_TOPOLOGY_ECXExtendedTopologyEcx;
+  UINT32 MaxCpuIdIndex;
+  UINT32 SubIndex;
+  UINTN  LevelType;
+  UINT32 MaxLogicProcessorsPerPackage;
+  UINT32 MaxCoresPerPackage;
+
+  //
+  // Check if the processor is capable of supporting more than one logical 
processor.
+  //
+  AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, NULL, );
+  if (VersionInfoEdx.Bits.HTT == 0) {
+Location->Thread  = 0;
+Location->Core= 0;
+Location->Package = 0;
+return;
+  }
+
+  ThreadBits = 0;
+  CoreBits = 0;
+
+  //
+  // Assume three-level mapping of APIC ID: Package:Core:SMT.
+  //
+
+  TopologyLeafSupported = FALSE;
+  //
+  // Get the max index of basic CPUID
+  //
+  AsmCpuid (CPUID_SIGNATURE, , NULL, NULL, NULL);
+
+  //
+  // If the extended topology enumeration leaf is available, it
+  // is the preferred mechanism for enumerating topology.
+  //
+  if (MaxCpuIdIndex >= CPUID_EXTENDED_TOPOLOGY) {
+AsmCpuidEx (
+  CPUID_EXTENDED_TOPOLOGY,
+  0,
+  ,
+  ,
+  ,
+  NULL
+  );
+//
+// If CPUID.(EAX=0BH, ECX=0H):EBX returns zero and maximum input value for
+// basic CPUID information is greater than 0BH, then CPUID.0BH leaf is not
+// supported on that processor.
+//
+if (ExtendedTopologyEbx.Uint32 != 0) {
+  TopologyLeafSupported = TRUE;
+
+  //
+  // Sub-leaf index 0 (ECX= 0 as input) provides enumeration parameters to 
extract
+  // the SMT sub-field of x2APIC ID.
+  //
+  LevelType = ExtendedTopologyEcx.Bits.LevelType;
+  ASSERT (LevelType == CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT);
+  ThreadBits = ExtendedTopologyEax.Bits.ApicIdShift;
+
+  //
+  // Software must not assume any "level type" encoding
+  // value to be related to any sub-leaf index, except sub-leaf 0.
+  //
+  SubIndex = 1;
+  do {
+AsmCpuidEx (
+  CPUID_EXTENDED_TOPOLOGY,
+  SubIndex,
+  ,
+  NULL,
+  ,
+  NULL
+  );
+LevelType = ExtendedTopologyEcx.Bits.LevelType;
+if (LevelType == CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_CORE) {
+  CoreBits = ExtendedTopologyEax.Bits.ApicIdShift - ThreadBits;
+  break;
+}
+SubIndex++;
+  } while (LevelType != CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID);
+}
+  }
+
+  if (!TopologyLeafSupported) {
+AsmCpuid (CPUID_VERSION_INFO, NULL, , NULL, NULL);
+MaxLogicProcessorsPerPackage = 
VersionInfoEbx.Bits.MaximumAddressableIdsForLogicalProcessors;
+if (MaxCpuIdIndex >= CPUID_CACHE_PARAMS) {
+  AsmCpuidEx (CPUID_CACHE_PARAMS, 0, , NULL, NULL, 
NULL);
+  MaxCoresPerPackage = 
CacheParamsEax.Bits.MaximumAddressableIdsForLogicalProcessors + 1;
+} else {
+  //
+  // Must be a single-core processor.
+  //
+  MaxCoresPerPackage = 1;
+}
+
+ThreadBits = (UINTN) (HighBitSet32 (MaxLogicProcessorsPerPackage / 
MaxCoresPerPackage - 1) + 1);
+CoreBits = (UINTN) (HighBitSet32 (MaxCoresPerPackage - 1) + 1);
+  }
+
+  Location->Thread  = InitialApicId & ((1 << ThreadBits) - 1);
+  Location->Core= (InitialApicId >> ThreadBits) & ((1 << CoreBits) - 1);
+  Location->Package = (InitialApicId >> (ThreadBits + CoreBits));
+}
+
+/**
   Get the Application Processors state.
 
   @param[in]  CpuData  

[edk2] [Patch v5 16/48] UefiCpuPkg/MpInitLib: Save CPU MP Data pointer

2016-08-02 Thread Jeff Fan
In PeiMpInitLib, save CPU MP Data pointer into one local Guided HOB.
In DxeMpInitLib, save CPU MP Data pointer into one global variable.

Add helper functions GetCpuMpData()/SaveCpuMpData().

v5:
  1. Move CPU_INIT_MP_LIB_HOB_GUID from MpLib.c to MpLib.h to make
 all C files visible.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 42 +
 UefiCpuPkg/Library/MpInitLib/MpLib.c| 30 ++
 UefiCpuPkg/Library/MpInitLib/MpLib.h| 48 +
 UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 54 +
 4 files changed, 174 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index 46a48a4..e294612 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -13,6 +13,48 @@
 **/
 
 #include "MpLib.h"
+CPU_MP_DATA  *mCpuMpData = NULL;
+
+/**
+  Get the pointer to CPU MP Data structure.
+
+  @return  The pointer to CPU MP Data structure.
+**/
+CPU_MP_DATA *
+GetCpuMpData (
+  VOID
+  )
+{
+  ASSERT (mCpuMpData != NULL);
+  return mCpuMpData;
+}
+
+/**
+  Save the pointer to CPU MP Data structure.
+
+  @param[in] CpuMpData  The pointer to CPU MP Data structure will be saved.
+**/
+VOID
+SaveCpuMpData (
+  IN CPU_MP_DATA   *CpuMpData
+  )
+{
+  mCpuMpData = CpuMpData;
+}
+
+/**
+  Initialize global data for MP support.
+
+  @param[in] CpuMpData  The pointer to CPU MP Data structure.
+**/
+VOID
+InitMpGlobalData (
+  IN CPU_MP_DATA   *CpuMpData
+  )
+{
+  SaveCpuMpData (CpuMpData);
+
+}
 
 /**
   This service executes a caller provided function on all enabled APs.
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 7384f5d..8dfbf57 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -14,6 +14,8 @@
 
 #include "MpLib.h"
 
+EFI_GUID mCpuInitMpLibHobGuid = CPU_INIT_MP_LIB_HOB_GUID;
+
 /**
   Get the Application Processors state.
 
@@ -303,6 +305,12 @@ MpInitLibInitialize (
   //
   MtrrGetAllMtrrs (>MtrrTable);
 
+
+  //
+  // Initialize global data for MP support
+  //
+  InitMpGlobalData (CpuMpData);
+
   return EFI_SUCCESS;
 }
 
@@ -386,3 +394,25 @@ MpInitLibGetNumberOfProcessors (
 {
   return EFI_UNSUPPORTED;
 }
+/**
+  Get pointer to CPU MP Data structure from GUIDed HOB.
+
+  @return  The pointer to CPU MP Data structure.
+**/
+CPU_MP_DATA *
+GetCpuMpDataFromGuidedHob (
+  VOID
+  )
+{
+  EFI_HOB_GUID_TYPE   *GuidHob;
+  VOID*DataInHob;
+  CPU_MP_DATA *CpuMpData;
+
+  CpuMpData = NULL;
+  GuidHob = GetFirstGuidHob ();
+  if (GuidHob != NULL) {
+DataInHob = GET_GUID_HOB_DATA (GuidHob);
+CpuMpData = (CPU_MP_DATA *) (*(UINTN *) DataInHob);
+  }
+  return CpuMpData;
+}
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index 625d061..d3ccac8 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -35,6 +35,11 @@
 #include 
 #include 
 
+#define CPU_INIT_MP_LIB_HOB_GUID \
+  { \
+0x58eb6a19, 0x3699, 0x4c68, { 0xa8, 0x36, 0xda, 0xcd, 0x8e, 0xdc, 0xad, 
0x4a } \
+  }
+
 //
 // AP loop state when APs are in idle state
 // It's value is the same with PcdCpuApLoopMode
@@ -198,6 +203,9 @@ struct _CPU_MP_DATA {
   CPU_AP_DATA*CpuData;
   volatile MP_CPU_EXCHANGE_INFO  *MpCpuExchangeInfo;
 };
+
+extern EFI_GUID mCpuInitMpLibHobGuid;
+
 /**
   Assembly code to place AP into safe loop mode.
 
@@ -233,6 +241,46 @@ AsmGetAddressMap (
   );
 
 /**
+  Get the pointer to CPU MP Data structure.
+
+  @return  The pointer to CPU MP Data structure.
+**/
+CPU_MP_DATA *
+GetCpuMpData (
+  VOID
+  );
+
+/**
+  Save the pointer to CPU MP Data structure.
+
+  @param[in] CpuMpData  The pointer to CPU MP Data structure will be saved.
+**/
+VOID
+SaveCpuMpData (
+  IN CPU_MP_DATA   *CpuMpData
+  );
+
+/**
+  Initialize global data for MP support.
+
+  @param[in] CpuMpData  The pointer to CPU MP Data structure.
+**/
+VOID
+InitMpGlobalData (
+  IN CPU_MP_DATA   *CpuMpData
+  );
+
+/**
+  Get pointer to CPU MP Data structure from GUIDed HOB.
+
+  @return  The pointer to CPU MP Data structure.
+**/
+CPU_MP_DATA *
+GetCpuMpDataFromGuidedHob (
+  VOID
+  );
+  
+/**
   Detect whether specified processor can find matching microcode patch and 
load it.
 
   @param[in] PeiCpuMpDataPointer to PEI CPU MP Data
diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
index a7e9fb8..6211e71 100644
--- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
@@ -15,6 +15,60 @@
 

[edk2] [Patch v5 18/48] UefiCpuPkg/MpInitLib: Register one period event to check APs status

2016-08-02 Thread Jeff Fan
In DxeMpInitLib, register one period event callback function CheckAPsStatus()
used to check AP Status.

v5:
  1. Introduce AP_CHECK_INTERVAL for adjust AP check timer interval potential.

v3:
  1. Use CamelCase for mCheckAllAPsEvent, mStopCheckAllApsStatus and
 CheckAndUpdateApsStatus().
  2. Move SetTimer() from Patch #17 to Patch 16.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
Reviewed-by: Giri P Mudusuru 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 66 +
 1 file changed, 66 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index e294612..2d8bf25 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -13,7 +13,16 @@
 **/
 
 #include "MpLib.h"
+
+#include 
+#include 
+
+#define  AP_CHECK_INTERVAL (EFI_TIMER_PERIOD_MILLISECONDS (100))
+
 CPU_MP_DATA  *mCpuMpData = NULL;
+EFI_EVENTmCheckAllApsEvent = NULL;
+volatile BOOLEAN mStopCheckAllApsStatus = TRUE;
+
 
 /**
   Get the pointer to CPU MP Data structure.
@@ -43,6 +52,43 @@ SaveCpuMpData (
 }
 
 /**
+/**
+  Checks APs status and updates APs status if needed.
+
+**/
+VOID
+CheckAndUpdateApsStatus (
+  VOID
+  )
+{
+}
+
+/**
+  Checks APs' status periodically.
+
+  This function is triggerred by timer perodically to check the
+  state of APs for StartupAllAPs() and StartupThisAP() executed
+  in non-blocking mode.
+
+  @param[in]  EventEvent triggered.
+  @param[in]  Context  Parameter passed with the event.
+
+**/
+VOID
+EFIAPI
+CheckApsStatus (
+  IN  EFI_EVENT   Event,
+  IN  VOID*Context
+  )
+{
+  //
+  // If CheckApsStatus() is not stopped, otherwise return immediately.
+  //
+  if (!mStopCheckAllApsStatus) {
+CheckAndUpdateApsStatus ();
+  }
+}
+/**
   Initialize global data for MP support.
 
   @param[in] CpuMpData  The pointer to CPU MP Data structure.
@@ -52,8 +98,28 @@ InitMpGlobalData (
   IN CPU_MP_DATA   *CpuMpData
   )
 {
+  EFI_STATUS Status;
+
   SaveCpuMpData (CpuMpData);
 
+  Status = gBS->CreateEvent (
+  EVT_TIMER | EVT_NOTIFY_SIGNAL,
+  TPL_NOTIFY,
+  CheckApsStatus,
+  NULL,
+  
+  );
+  ASSERT_EFI_ERROR (Status);
+
+  //
+  // Set timer to check all APs status.
+  //
+  Status = gBS->SetTimer (
+  mCheckAllApsEvent,
+  TimerPeriodic,
+  AP_CHECK_INTERVAL
+  );
+  ASSERT_EFI_ERROR (Status);
 }
 
 /**
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 17/48] UefiCpuPkg/MpInitLib: Register one End of PEI callback function

2016-08-02 Thread Jeff Fan
In PeiMpInitLib, register End of PEI callback function CpuMpEndOfPeiCallback().

v5:
  1. Add comment block for mMpInitLibNotifyList.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.h| 20 +++
 UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 43 +
 2 files changed, 63 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index d3ccac8..f560237 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -290,5 +290,25 @@ MicrocodeDetect (
   IN CPU_MP_DATA *CpuMpData
   );
 
+/**
+  Notify function on End Of PEI PPI.
+
+  On S3 boot, this function will restore wakeup buffer data.
+  On normal boot, this function will flag wakeup buffer to be un-used type.
+
+  @param[in]  PeiServicesThe pointer to the PEI Services Table.
+  @param[in]  NotifyDescriptor   Address of the notification descriptor data 
structure.
+  @param[in]  PpiAddress of the PPI that was installed.
+
+  @retval EFI_SUCCESSWhen everything is OK.
+**/
+EFI_STATUS
+EFIAPI
+CpuMpEndOfPeiCallback (
+  IN EFI_PEI_SERVICES **PeiServices,
+  IN EFI_PEI_NOTIFY_DESCRIPTOR*NotifyDescriptor,
+  IN VOID *Ppi
+  );
+
 #endif
 
diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
index 6211e71..72791b5 100644
--- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
@@ -13,6 +13,17 @@
 **/
 
 #include "MpLib.h"
+#include 
+#include 
+
+//
+// Global PEI notify function descriptor on EndofPei event
+//
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mMpInitLibNotifyList = 
{
+  (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | 
EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+  ,
+  CpuMpEndOfPeiCallback
+};
 
 /**
   Get pointer to CPU MP Data structure.
@@ -55,6 +66,32 @@ SaveCpuMpData (
 
 
 /**
+/**
+  Notify function on End Of PEI PPI.
+
+  On S3 boot, this function will restore wakeup buffer data.
+  On normal boot, this function will flag wakeup buffer to be un-used type.
+
+  @param[in]  PeiServicesThe pointer to the PEI Services Table.
+  @param[in]  NotifyDescriptor   Address of the notification descriptor data 
structure.
+  @param[in]  PpiAddress of the PPI that was installed.
+
+  @retval EFI_SUCCESSWhen everything is OK.
+**/
+EFI_STATUS
+EFIAPI
+CpuMpEndOfPeiCallback (
+  IN EFI_PEI_SERVICES **PeiServices,
+  IN EFI_PEI_NOTIFY_DESCRIPTOR*NotifyDescriptor,
+  IN VOID *Ppi
+  )
+{
+
+  DEBUG ((DEBUG_INFO, "PeiMpInitLib: CpuMpEndOfPeiCallback () invoked\n"));
+
+  return EFI_SUCCESS;
+}
+/**
   Initialize global data for MP support.
 
   @param[in] CpuMpData  The pointer to CPU MP Data structure.
@@ -64,8 +101,14 @@ InitMpGlobalData (
   IN CPU_MP_DATA   *CpuMpData
   )
 {
+  EFI_STATUS  Status;
 
   SaveCpuMpData (CpuMpData);
+  //
+  // Register an event for EndOfPei
+  //
+  Status  = PeiServicesNotifyPpi ();
+  ASSERT_EFI_ERROR (Status);
 }
 
 /**
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 19/48] UefiCpuPkg/MpInitLib: Allocate AP reset vector buffer under 1MB

2016-08-02 Thread Jeff Fan
In PeiMpInitLib, searching unallocated memory under in
EFI_HOB_TYPE_RESOURCE_DESCRIPTOR hobs to find the memory under 1MB for AP reset
vector. After End of PEI event triggered, we need to restore original the buffer
contents to avoid crash the OS on S3 boot.
In DxeMpInitLib, allocate the memory under 1MB for AP reset vector.

Add helper functions AllocateResetVector()/FreeResetVector() used by WakeupAp().

v3:
  1. Move SetTimer() from Patch #17 to Patch 16.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c |  60 
 UefiCpuPkg/Library/MpInitLib/MpLib.h|  20 +++
 UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 245 
 3 files changed, 325 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index 2d8bf25..762d76d 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -52,6 +52,65 @@ SaveCpuMpData (
 }
 
 /**
+  Allocate reset vector buffer.
+
+  @param[in, out]  CpuMpData  The pointer to CPU MP Data structure.
+**/
+VOID
+AllocateResetVector (
+  IN OUT CPU_MP_DATA  *CpuMpData
+  )
+{
+  EFI_STATUSStatus;
+  UINTN ApResetVectorSize;
+  EFI_PHYSICAL_ADDRESS  StartAddress;
+
+  ApResetVectorSize = CpuMpData->AddressMap.RendezvousFunnelSize +
+  sizeof (MP_CPU_EXCHANGE_INFO);
+
+  StartAddress = BASE_1MB;
+  Status = gBS->AllocatePages (
+  AllocateMaxAddress,
+  EfiACPIMemoryNVS,
+  EFI_SIZE_TO_PAGES (ApResetVectorSize),
+  
+  );
+  ASSERT_EFI_ERROR (Status);
+
+  CpuMpData->WakeupBuffer  = (UINTN) StartAddress;
+  CpuMpData->MpCpuExchangeInfo = (MP_CPU_EXCHANGE_INFO *) (UINTN)
+  (CpuMpData->WakeupBuffer + 
CpuMpData->AddressMap.RendezvousFunnelSize);
+  //
+  // copy AP reset code in it
+  //
+  CopyMem (
+(VOID *) CpuMpData->WakeupBuffer,
+(VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress,
+CpuMpData->AddressMap.RendezvousFunnelSize
+);
+}
+
+/**
+  Free AP reset vector buffer.
+
+  @param[in]  CpuMpData  The pointer to CPU MP Data structure.
+**/
+VOID
+FreeResetVector (
+  IN CPU_MP_DATA  *CpuMpData
+  )
+{
+  EFI_STATUSStatus;
+  UINTN ApResetVectorSize;
+  ApResetVectorSize = CpuMpData->AddressMap.RendezvousFunnelSize +
+  sizeof (MP_CPU_EXCHANGE_INFO);
+  Status = gBS->FreePages(
+ (EFI_PHYSICAL_ADDRESS)CpuMpData->WakeupBuffer,
+ EFI_SIZE_TO_PAGES (ApResetVectorSize)
+ );
+  ASSERT_EFI_ERROR (Status);
+}
+
 /**
   Checks APs status and updates APs status if needed.
 
@@ -88,6 +147,7 @@ CheckApsStatus (
 CheckAndUpdateApsStatus ();
   }
 }
+
 /**
   Initialize global data for MP support.
 
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index f560237..80ea0b4 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -261,6 +261,26 @@ SaveCpuMpData (
   );
 
 /**
+  Allocate reset vector buffer.
+
+  @param[in, out]  CpuMpData  The pointer to CPU MP Data structure.
+**/
+VOID
+AllocateResetVector (
+  IN OUT CPU_MP_DATA  *CpuMpData
+  );
+
+/**
+  Free AP reset vector buffer.
+
+  @param[in]  CpuMpData  The pointer to CPU MP Data structure.
+**/
+VOID
+FreeResetVector (
+  IN CPU_MP_DATA  *CpuMpData
+  );
+
+/**
   Initialize global data for MP support.
 
   @param[in] CpuMpData  The pointer to CPU MP Data structure.
diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
index 72791b5..a7e1cde 100644
--- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
@@ -64,8 +64,45 @@ SaveCpuMpData (
 );
 }
 
+/**
+  Get available system memory below 1MB by specified size.
+
+  @param[in] PeiCpuMpDataPointer to PEI CPU MP Data
+**/
+VOID
+BackupAndPrepareWakeupBuffer(
+  IN CPU_MP_DATA  *CpuMpData
+  )
+{
+  CopyMem (
+(VOID *) CpuMpData->BackupBuffer,
+(VOID *) CpuMpData->WakeupBuffer,
+CpuMpData->BackupBufferSize
+);
+  CopyMem (
+(VOID *) CpuMpData->WakeupBuffer,
+(VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress,
+CpuMpData->AddressMap.RendezvousFunnelSize
+);
+}
 
 /**
+  Restore wakeup buffer data.
+
+  @param[in] PeiCpuMpDataPointer to PEI CPU MP Data
+**/
+VOID
+RestoreWakeupBuffer(
+  IN CPU_MP_DATA  *CpuMpData
+  )
+{
+  CopyMem (
+(VOID *) CpuMpData->WakeupBuffer,
+(VOID *) CpuMpData->BackupBuffer,
+CpuMpData->BackupBufferSize
+);
+}
+
 /**
   Notify function on 

[edk2] [Patch v5 23/48] UefiCpuPkg/MpInitLib: Send INIT-SIPI-SIPI to get processor count

2016-08-02 Thread Jeff Fan
CollectProcessorCount() will send the 1st INIT-SIPI-SIPI to get processor count
in system.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 40 
 1 file changed, 40 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index de169e6..8f7cf43 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -268,6 +268,42 @@ GetProcessorNumber (
   return EFI_NOT_FOUND;
 }
 
+/**
+  This function will get CPU count in the system.
+
+  @param[in] CpuMpDataPointer to PEI CPU MP Data
+
+  @return  CPU count detected
+**/
+UINTN
+CollectProcessorCount (
+  IN CPU_MP_DATA *CpuMpData
+  )
+{
+  //
+  // Send 1st broadcast IPI to APs to wakeup APs
+  //
+  CpuMpData->InitFlag = ApInitConfig;
+  CpuMpData->X2ApicEnable = FALSE;
+  WakeUpAP (CpuMpData, TRUE, 0, NULL, NULL);
+  //
+  // Wait for AP task to complete and then exit.
+  //
+  MicroSecondDelay (PcdGet32(PcdCpuApInitTimeOutInMicroSeconds));
+  CpuMpData->InitFlag = ApInitDone;
+  ASSERT (CpuMpData->CpuCount <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber));
+  //
+  // Wait for all APs finished the initialization
+  //
+  while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) {
+CpuPause ();
+  }
+
+  DEBUG ((DEBUG_INFO, "MpInitLib: Find %d processors in system.\n", 
CpuMpData->CpuCount));
+
+  return CpuMpData->CpuCount;
+}
+
 /*
   Initialize CPU AP Data when AP is wakeup at the first time.
 
@@ -705,6 +741,10 @@ MpInitLibInitialize (
 
 
   //
+  // Wakeup all APs and calculate the processor count in system
+  //
+  CollectProcessorCount (CpuMpData);
+  //
   // Initialize global data for MP support
   //
   InitMpGlobalData (CpuMpData);
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 22/48] UefiCpuPkg/MpInitLib: Add WakeUpAP()

2016-08-02 Thread Jeff Fan
WakeUpAP() is used to wakeup APs per current ApLoopMode and make sure APs wake
up successfully.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 121 +++
 UefiCpuPkg/Library/MpInitLib/MpLib.h |  19 ++
 2 files changed, 140 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index d08..de169e6 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -448,6 +448,29 @@ ApWakeupFunction (
 }
 
 /**
+  Wait for AP wakeup and write AP start-up signal till AP is waken up.
+
+  @param[in] ApStartupSignalBuffer  Pointer to AP wakeup signal
+**/
+VOID
+WaitApWakeup (
+  IN volatile UINT32*ApStartupSignalBuffer
+  )
+{
+  //
+  // If AP is waken up, StartupApSignal should be cleared.
+  // Otherwise, write StartupApSignal again till AP waken up.
+  //
+  while (InterlockedCompareExchange32 (
+  (UINT32 *) ApStartupSignalBuffer,
+  WAKEUP_AP_SIGNAL,
+  WAKEUP_AP_SIGNAL
+  ) != 0) {
+CpuPause ();
+  }
+}
+
+/**
   This function will fill the exchange info structure.
 
   @param[in] CpuMpData  Pointer to CPU MP Data
@@ -486,6 +509,104 @@ FillExchangeInfoData (
 }
 
 /**
+  This function will be called by BSP to wakeup AP.
+
+  @param[in] CpuMpData  Pointer to CPU MP Data
+  @param[in] Broadcast  TRUE:  Send broadcast IPI to all APs
+FALSE: Send IPI to AP by ApicId
+  @param[in] ProcessorNumberThe handle number of specified processor
+  @param[in] Procedure  The function to be invoked by AP
+  @param[in] ProcedureArgument  The argument to be passed into AP function
+**/
+VOID
+WakeUpAP (
+  IN CPU_MP_DATA   *CpuMpData,
+  IN BOOLEAN   Broadcast,
+  IN UINTN ProcessorNumber,
+  IN EFI_AP_PROCEDURE  Procedure,  OPTIONAL
+  IN VOID  *ProcedureArgument  OPTIONAL
+  )
+{
+  volatile MP_CPU_EXCHANGE_INFO*ExchangeInfo;
+  UINTNIndex;
+  CPU_AP_DATA  *CpuData;
+  BOOLEAN  ResetVectorRequired;
+
+  CpuMpData->FinishedCount = 0;
+  ResetVectorRequired = FALSE;
+
+  if (CpuMpData->ApLoopMode == ApInHltLoop ||
+  CpuMpData->InitFlag   != ApInitDone) {
+ResetVectorRequired = TRUE;
+AllocateResetVector (CpuMpData);
+FillExchangeInfoData (CpuMpData);
+  } else if (CpuMpData->ApLoopMode == ApInMwaitLoop) {
+//
+// Get AP target C-state each time when waking up AP,
+// for it maybe updated by platform again
+//
+CpuMpData->ApTargetCState = PcdGet8 (PcdCpuApTargetCstate);
+  }
+
+  ExchangeInfo = CpuMpData->MpCpuExchangeInfo;
+
+  if (Broadcast) {
+for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
+  if (Index != CpuMpData->BspNumber) {
+CpuData = >CpuData[Index];
+CpuData->ApFunction = (UINTN) Procedure;
+CpuData->ApFunctionArgument = (UINTN) ProcedureArgument;
+SetApState (CpuData, CpuStateReady);
+if (CpuMpData->InitFlag != ApInitConfig) {
+  *(UINT32 *) CpuData->StartupApSignal = WAKEUP_AP_SIGNAL;
+}
+  }
+}
+if (ResetVectorRequired) {
+  //
+  // Wakeup all APs
+  //
+  SendInitSipiSipiAllExcludingSelf ((UINT32) ExchangeInfo->BufferStart);
+}
+if (CpuMpData->InitFlag != ApInitConfig) {
+  //
+  // Wait all APs waken up if this is not the 1st broadcast of SIPI
+  //
+  for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
+CpuData = >CpuData[Index];
+if (Index != CpuMpData->BspNumber) {
+  WaitApWakeup (CpuData->StartupApSignal);
+}
+  }
+}
+  } else {
+CpuData = >CpuData[ProcessorNumber];
+CpuData->ApFunction = (UINTN) Procedure;
+CpuData->ApFunctionArgument = (UINTN) ProcedureArgument;
+SetApState (CpuData, CpuStateReady);
+//
+// Wakeup specified AP
+//
+ASSERT (CpuMpData->InitFlag != ApInitConfig);
+*(UINT32 *) CpuData->StartupApSignal = WAKEUP_AP_SIGNAL;
+if (ResetVectorRequired) {
+  SendInitSipiSipi (
+CpuData->ApicId,
+(UINT32) ExchangeInfo->BufferStart
+);
+}
+//
+// Wait specified AP waken up
+//
+WaitApWakeup (CpuData->StartupApSignal);
+  }
+
+  if (ResetVectorRequired) {
+FreeResetVector (CpuMpData);
+  }
+}
+
+/**
   MP Initialize Library initialization.
 
   This service will allocate AP reset vector and wakeup all APs to do APs
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index 72a35ef..84e0970 100644
--- 

[edk2] [Patch v5 24/48] UefiCpuPkg/MpInitLib: Enable x2APIC mode on BSP/APs

2016-08-02 Thread Jeff Fan
If x2APIC flag is set, enable x2APIC mode on all APs and BSP. Before we wakeup
APs to enable x2APIC mode, we should wait all APs have finished initialization.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 32 
 1 file changed, 32 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 8f7cf43..d84dfec 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -217,6 +217,20 @@ GetApLoopMode (
 }
 
 /**
+  Enable x2APIC mode on APs.
+
+  @param[in, out] Buffer  Pointer to private data buffer.
+**/
+VOID
+EFIAPI
+ApFuncEnableX2Apic (
+  IN OUT VOID  *Buffer
+  )
+{
+  SetApicMode (LOCAL_APIC_MODE_X2APIC);
+}
+
+/**
   Do sync on APs.
 
   @param[in, out] Buffer  Pointer to private data buffer.
@@ -299,6 +313,24 @@ CollectProcessorCount (
 CpuPause ();
   }
 
+  if (CpuMpData->X2ApicEnable) {
+DEBUG ((DEBUG_INFO, "Force x2APIC mode!\n"));
+//
+// Wakeup all APs to enable x2APIC mode
+//
+WakeUpAP (CpuMpData, TRUE, 0, ApFuncEnableX2Apic, NULL);
+//
+// Wait for all known APs finished
+//
+while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) {
+  CpuPause ();
+}
+//
+// Enable x2APIC on BSP
+//
+SetApicMode (LOCAL_APIC_MODE_X2APIC);
+  }
+  DEBUG ((DEBUG_INFO, "APIC MODE is %d\n", GetApicMode ()));
   DEBUG ((DEBUG_INFO, "MpInitLib: Find %d processors in system.\n", 
CpuMpData->CpuCount));
 
   return CpuMpData->CpuCount;
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 20/48] UefiCpuPkg/MpInitLib: Add ApWakeupFunction() executed by assembly code

2016-08-02 Thread Jeff Fan
ApWakeupFunction() is the first C function executed from AP reset vector. When
APs waken up at the first time, it will sync BSP's MTRR setting and load
microcode on APs and collect APs' BIST information.

When AP tasked finished, it will place APs it one loop specified by ApLoopMode.

v5:
  1. Rename ApCFunction to ApWakeupFunction to meet naming convention.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 198 +++
 UefiCpuPkg/Library/MpInitLib/MpLib.h |   2 +
 2 files changed, 200 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 8dfbf57..a4a2c44 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -174,6 +174,59 @@ GetApLoopMode (
 
   return ApLoopMode;
 }
+
+/**
+  Do sync on APs.
+
+  @param[in, out] Buffer  Pointer to private data buffer.
+**/
+VOID
+EFIAPI
+ApInitializeSync (
+  IN OUT VOID  *Buffer
+  )
+{
+  CPU_MP_DATA  *CpuMpData;
+
+  CpuMpData = (CPU_MP_DATA *) Buffer;
+  //
+  // Sync BSP's MTRR table to AP
+  //
+  MtrrSetAllMtrrs (>MtrrTable);
+  //
+  // Load microcode on AP
+  //
+  MicrocodeDetect (CpuMpData);
+}
+
+/**
+  Find the current Processor number by APIC ID.
+
+  @param[in] CpuMpData Pointer to PEI CPU MP Data
+  @param[in] ProcessorNumber   Return the pocessor number found
+
+  @retval EFI_SUCCESS  ProcessorNumber is found and returned.
+  @retval EFI_NOT_FOUNDProcessorNumber is not found.
+**/
+EFI_STATUS
+GetProcessorNumber (
+  IN CPU_MP_DATA   *CpuMpData,
+  OUT UINTN*ProcessorNumber
+  )
+{
+  UINTN   TotalProcessorNumber;
+  UINTN   Index;
+
+  TotalProcessorNumber = CpuMpData->CpuCount;
+  for (Index = 0; Index < TotalProcessorNumber; Index ++) {
+if (CpuMpData->CpuData[Index].ApicId == GetApicId ()) {
+  *ProcessorNumber = Index;
+  return EFI_SUCCESS;
+}
+  }
+  return EFI_NOT_FOUND;
+}
+
 /*
   Initialize CPU AP Data when AP is wakeup at the first time.
 
@@ -209,6 +262,151 @@ InitializeApData (
 }
 
 /**
+  This function will be called from AP reset code if BSP uses WakeUpAP.
+
+  @param[in] ExchangeInfo Pointer to the MP exchange info buffer
+  @param[in] NumApsExecuting  Number of current executing AP
+**/
+VOID
+EFIAPI
+ApWakeupFunction (
+  IN MP_CPU_EXCHANGE_INFO  *ExchangeInfo,
+  IN UINTN NumApsExecuting
+  )
+{
+  CPU_MP_DATA*CpuMpData;
+  UINTN  ProcessorNumber;
+  EFI_AP_PROCEDURE   Procedure;
+  VOID   *Parameter;
+  UINT32 BistData;
+  volatile UINT32*ApStartupSignalBuffer;
+
+  //
+  // AP finished assembly code and begin to execute C code
+  //
+  CpuMpData = ExchangeInfo->CpuMpData;
+
+  ProgramVirtualWireMode (); 
+
+  while (TRUE) {
+if (CpuMpData->InitFlag == ApInitConfig) {
+  //
+  // Add CPU number
+  //
+  InterlockedIncrement ((UINT32 *) >CpuCount);
+  ProcessorNumber = NumApsExecuting;
+  //
+  // This is first time AP wakeup, get BIST information from AP stack
+  //
+  BistData = *(UINT32 *) (CpuMpData->Buffer + ProcessorNumber * 
CpuMpData->CpuApStackSize - sizeof (UINTN));
+  //
+  // Do some AP initialize sync
+  //
+  ApInitializeSync (CpuMpData);
+  //
+  // Sync BSP's Control registers to APs
+  //
+  RestoreVolatileRegisters (>CpuData[0].VolatileRegisters, 
FALSE);
+  InitializeApData (CpuMpData, ProcessorNumber, BistData);
+  ApStartupSignalBuffer = 
CpuMpData->CpuData[ProcessorNumber].StartupApSignal;
+} else {
+  //
+  // Execute AP function if AP is ready
+  //
+  GetProcessorNumber (CpuMpData, );
+  //
+  // Clear AP start-up signal when AP waken up
+  //
+  ApStartupSignalBuffer = 
CpuMpData->CpuData[ProcessorNumber].StartupApSignal;
+  InterlockedCompareExchange32 (
+(UINT32 *) ApStartupSignalBuffer,
+WAKEUP_AP_SIGNAL,
+0
+);
+  if (CpuMpData->ApLoopMode == ApInHltLoop) {
+//
+// Restore AP's volatile registers saved
+//
+RestoreVolatileRegisters 
(>CpuData[ProcessorNumber].VolatileRegisters, TRUE);
+  }
+
+  if (GetApState (>CpuData[ProcessorNumber]) == CpuStateReady) {
+Procedure = 
(EFI_AP_PROCEDURE)CpuMpData->CpuData[ProcessorNumber].ApFunction;
+Parameter = (VOID *) 
CpuMpData->CpuData[ProcessorNumber].ApFunctionArgument;
+if (Procedure != NULL) {
+  SetApState (>CpuData[ProcessorNumber], CpuStateBusy);
+  //
+  // Invoke AP function here
+  //
+  

[edk2] [Patch v5 12/48] UefiCpuPkg/MpInitLib: Allocate and initialize memory of MP Data buffer

2016-08-02 Thread Jeff Fan
v5:
  1. Add comment block for enum AP_INIT_STATE and structure CPU_AP_DATA.
  2. Add more comment for structure CPU_INFO_IN_HOB.
  3. Add more clarification in structure _CPU_MP_DATA for those fields
 pass from PEI to DXE.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 49 
 UefiCpuPkg/Library/MpInitLib/MpLib.h | 88 
 2 files changed, 137 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 32bbaee..f05db7c 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -93,15 +93,64 @@ MpInitLibInitialize (
   VOID
   )
 {
+  UINT32   MaxLogicalProcessorNumber;
+  UINT32   ApStackSize;
   MP_ASSEMBLY_ADDRESS_MAP  AddressMap;
+  UINTNBufferSize;
   UINT32   MonitorFilterSize;
+  VOID *MpBuffer;
+  UINTNBuffer;
+  CPU_MP_DATA  *CpuMpData;
   UINT8ApLoopMode;
+  UINT8*MonitorBuffer;
   UINTNApResetVectorSize;
+  UINTNBackupBufferAddr;
+  MaxLogicalProcessorNumber = PcdGet32(PcdCpuMaxLogicalProcessorNumber);
 
   AsmGetAddressMap ();
   ApResetVectorSize = AddressMap.RendezvousFunnelSize + sizeof 
(MP_CPU_EXCHANGE_INFO);
+  ApStackSize = PcdGet32(PcdCpuApStackSize);
   ApLoopMode  = GetApLoopMode ();
 
+  BufferSize  = ApStackSize * MaxLogicalProcessorNumber;
+  BufferSize += MonitorFilterSize * MaxLogicalProcessorNumber;
+  BufferSize += sizeof (CPU_MP_DATA);
+  BufferSize += ApResetVectorSize;
+  BufferSize += (sizeof (CPU_AP_DATA) + sizeof (CPU_INFO_IN_HOB))* 
MaxLogicalProcessorNumber;
+  MpBuffer= AllocatePages (EFI_SIZE_TO_PAGES (BufferSize));
+  ASSERT (MpBuffer != NULL);
+  ZeroMem (MpBuffer, BufferSize);
+  Buffer = (UINTN) MpBuffer;
+
+  MonitorBuffer= (UINT8 *) (Buffer + ApStackSize * 
MaxLogicalProcessorNumber);
+  BackupBufferAddr = (UINTN) MonitorBuffer + MonitorFilterSize * 
MaxLogicalProcessorNumber;
+  CpuMpData = (CPU_MP_DATA *) (BackupBufferAddr + ApResetVectorSize);
+  CpuMpData->Buffer   = Buffer;
+  CpuMpData->CpuApStackSize   = ApStackSize;
+  CpuMpData->BackupBuffer = BackupBufferAddr;
+  CpuMpData->BackupBufferSize = ApResetVectorSize;
+  CpuMpData->EndOfPeiFlag = FALSE;
+  CpuMpData->WakeupBuffer = (UINTN) -1;
+  CpuMpData->CpuCount = 1;
+  CpuMpData->BspNumber= 0;
+  CpuMpData->WaitEvent= NULL;
+  CpuMpData->CpuData  = (CPU_AP_DATA *) (CpuMpData + 1);
+  CpuMpData->CpuInfoInHob = (UINT64) (UINTN) (CpuMpData->CpuData + 
MaxLogicalProcessorNumber);
+  InitializeSpinLock(>MpLock);
+  //
+  // Save assembly code information
+  //
+  CopyMem (>AddressMap, , sizeof 
(MP_ASSEMBLY_ADDRESS_MAP));
+  //
+  // Finally set AP loop mode
+  //
+  CpuMpData->ApLoopMode = ApLoopMode;
+  DEBUG ((DEBUG_INFO, "AP Loop Mode is %d\n", CpuMpData->ApLoopMode));
+  //
+  // Store BSP's MTRR setting
+  //
+  MtrrGetAllMtrrs (>MtrrTable);
+
   return EFI_SUCCESS;
 }
 
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index 317facc..e605f8d 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -46,6 +46,47 @@ typedef enum {
 } AP_LOOP_MODE;
 
 //
+// AP initialization state during APs wakeup
+//
+typedef enum {
+  ApInitConfig   = 1,
+  ApInitReconfig = 2,
+  ApInitDone = 3
+} AP_INIT_STATE;
+
+//
+// AP related data
+//
+typedef struct {
+  SPIN_LOCK  ApLock;
+  volatile UINT32*StartupApSignal;
+  volatile UINTN ApFunction;
+  volatile UINTN ApFunctionArgument;
+  UINT32 InitialApicId;
+  UINT32 ApicId;
+  UINT32 Health;
+  BOOLEANCpuHealthy;
+  BOOLEANWaiting;
+  BOOLEAN*Finished;
+  UINT64 ExpectedTime;
+  UINT64 CurrentTime;
+  UINT64 TotalTime;
+  EFI_EVENT  WaitEvent;
+} CPU_AP_DATA;
+
+//
+// Basic CPU information saved in Guided HOB.
+// Because the contents will be shard between PEI and DXE,
+// we need to make sure the each fields offset same in different
+// architecture.
+//
+typedef struct {
+  UINT32 InitialApicId;
+  UINT32 ApicId;
+  UINT32 Health;
+} CPU_INFO_IN_HOB;
+
+//
 // AP reset code information including code address and size,
 // this structure will be shared 

[edk2] [Patch v5 08/48] UefiCpuPkg/MpInitLib: Add EnableExecuteDisable in MP_CPU_EXCHANGE_INFO

2016-08-02 Thread Jeff Fan
EnableExecuteDisable in MP_CPU_EXCHANGE_INFO is used to tell AP reset vector if
enable execute disable feature on APs. This feature should be enabled before CR3
is written.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc|  2 ++
 UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm | 30 ++
 UefiCpuPkg/Library/MpInitLib/MpLib.h   |  1 +
 UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc |  4 +++-
 UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm  | 13 +++
 5 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc 
b/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc
index 015396a..60add86 100644
--- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc
+++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc
@@ -36,4 +36,6 @@ ModeOffsetLocationequLockLocation + 20h
 NumApsExecutingLocation   equLockLocation + 24h
 CodeSegmentLocation   equLockLocation + 28h
 DataSegmentLocation   equLockLocation + 2Ch
+EnableExecuteDisableLocation  equLockLocation + 30h
+Cr3Location   equLockLocation + 3Ch
 
diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm 
b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
index 7050413..8bacb42 100644
--- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
+++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
@@ -85,6 +85,36 @@ Flat32Start:   ; protected 
mode entry point
 movss, dx
 
 movesi, ebx
+
+mov edi, esi
+add edi, EnableExecuteDisableLocation
+cmp byte [edi], 0
+jz  SkipEnableExecuteDisable
+
+;
+; Enable IA32 PAE execute disable
+;
+
+mov ecx, 0xc080
+rdmsr
+bts eax, 11
+wrmsr
+
+mov edi, esi
+add edi, Cr3Location
+mov eax, dword [edi]
+mov cr3, eax
+
+mov eax, cr4
+bts eax, 5
+mov cr4, eax
+
+mov eax, cr0
+bts eax, 31
+mov cr0, eax
+
+SkipEnableExecuteDisable:
+
 movedi, esi
 addedi, LockLocation
 moveax, NotVacantFlag
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index 92d1dd9..28a3cd4 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -55,6 +55,7 @@ typedef struct {
   UINTN NumApsExecuting;
   UINTN CodeSegment;
   UINTN DataSegment;
+  UINTN EnableExecuteDisable;
   UINTN Cr3;
 } MP_CPU_EXCHANGE_INFO;
 
diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc 
b/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc
index 5aac212..d533741 100644
--- a/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc
+++ b/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc
@@ -36,6 +36,8 @@ ModeOffsetLocationequLockLocation + 3Ch
 NumApsExecutingLocation   equLockLocation + 44h
 CodeSegmentLocation   equLockLocation + 4Ch
 DataSegmentLocation   equLockLocation + 54h
-Cr3Location   equLockLocation + 5Ch
+EnableExecuteDisableLocation  equLockLocation + 5Ch
+Cr3Location   equLockLocation + 64h
+
 
 
;---
diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm 
b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
index 848992c..3c55ffa 100644
--- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
+++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
@@ -69,6 +69,19 @@ o32 lgdt   [cs:si]
 movsi, IdtrLocation
 o32 lidt   [cs:si]
 
+movsi, EnableExecuteDisableLocation
+cmpbyte [si], 0
+jz SkipEnableExecuteDisableBit
+
+;
+; Enable execute disable bit
+;
+movecx, 0c080h ; EFER MSR number
+rdmsr  ; Read EFER
+btseax, 11 ; Enable Execute Disable Bit
+wrmsr  ; Write EFER
+
+SkipEnableExecuteDisableBit:
 
 movdi,  DataSegmentLocation
 movedi, [di]   ; Save long mode DS in edi
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 03/48] UefiCpuPkg/CpuS3DataDxe: Move StartupVector allocation to EndOfDxe()

2016-08-02 Thread Jeff Fan
Currently, we will allocate StartupVector buffer under 1MB at entry point
function. But some modules may allocate some hard code address under 1MB.
For example, LegacyBiosDxe driver tries to manage some legacy range under
640KB.

To avoid the conflicts, we move StartupVector buffer allocation to End Of
DXE event callback function.

v4:
  Update the Context parameter is used as a pointer to AcpiCpuDataEx, then
  we needn't to add the global variable.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
Reviewed-by: Giri P Mudusuru 
---
 UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c  | 42 +---
 UefiCpuPkg/CpuS3DataDxe/CpuS3DataDxe.inf |  2 +-
 2 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c 
b/UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c
index 9fb47dc..7bd928f 100644
--- a/UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c
+++ b/UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c
@@ -9,7 +9,7 @@ number of CPUs reported by the MP Services Protocol, so this 
module does not
 support hot plug CPUs.  This module can be copied into a CPU specific package
 and customized if these additional features are required.
 
-Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.
 Copyright (c) 2015, Red Hat, Inc.
 
 This program and the accompanying materials
@@ -84,20 +84,36 @@ AllocateAcpiNvsMemoryBelow4G (
 /**
   Callback function executed when the EndOfDxe event group is signaled.
 
-  We delay saving the MTRR settings until BDS signals EndOfDxe.
+  We delay allocating StartupVector and saving the MTRR settings until BDS 
signals EndOfDxe.
 
   @param[in]  EventEvent whose notification function is being invoked.
   @param[out] Context  Pointer to the MTRR_SETTINGS buffer to fill in.
 **/
 VOID
 EFIAPI
-SaveMtrrsOnEndOfDxe (
+CpuS3DataOnEndOfDxe (
   IN  EFI_EVENT  Event,
   OUT VOID   *Context
   )
 {
+  EFI_STATUS Status;
+  ACPI_CPU_DATA_EX   *AcpiCpuDataEx;
+
+  AcpiCpuDataEx = (ACPI_CPU_DATA_EX *) Context;
+  //
+  // Allocate a 4KB reserved page below 1MB
+  //
+  AcpiCpuDataEx->AcpiCpuData.StartupVector = BASE_1MB - 1;
+  Status = gBS->AllocatePages (
+  AllocateMaxAddress,
+  EfiReservedMemoryType,
+  1,
+  >AcpiCpuData.StartupVector
+  );
+  ASSERT_EFI_ERROR (Status);
+
   DEBUG ((EFI_D_VERBOSE, "%a\n", __FUNCTION__));
-  MtrrGetAllMtrrs (Context);
+  MtrrGetAllMtrrs (>MtrrTable);
 
   //
   // Close event, so it will not be invoked again.
@@ -162,18 +178,6 @@ CpuS3DataInitialize (
   ASSERT_EFI_ERROR (Status);
 
   //
-  // Allocate a 4KB reserved page below 1MB
-  //
-  AcpiCpuData->StartupVector = BASE_1MB - 1;
-  Status = gBS->AllocatePages (
-  AllocateMaxAddress,
-  EfiReservedMemoryType,
-  1,
-  >StartupVector
-  );
-  ASSERT_EFI_ERROR (Status);
-
-  //
   // Get the number of CPUs
   //
   Status = MpServices->GetNumberOfProcessors (
@@ -255,13 +259,13 @@ CpuS3DataInitialize (
 
   //
   // Register EFI_END_OF_DXE_EVENT_GROUP_GUID event.
-  // The notification function saves MTRRs for ACPI_CPU_DATA
+  // The notification function allocates StartupVector and saves MTRRs for 
ACPI_CPU_DATA
   //
   Status = gBS->CreateEventEx (
   EVT_NOTIFY_SIGNAL,
   TPL_CALLBACK,
-  SaveMtrrsOnEndOfDxe,
-  >MtrrTable,
+  CpuS3DataOnEndOfDxe,
+  AcpiCpuData,
   ,
   
   );
diff --git a/UefiCpuPkg/CpuS3DataDxe/CpuS3DataDxe.inf 
b/UefiCpuPkg/CpuS3DataDxe/CpuS3DataDxe.inf
index 857e12b..608e19f 100644
--- a/UefiCpuPkg/CpuS3DataDxe/CpuS3DataDxe.inf
+++ b/UefiCpuPkg/CpuS3DataDxe/CpuS3DataDxe.inf
@@ -9,7 +9,7 @@
 #  support hot plug CPUs.  This module can be copied into a CPU specific 
package
 #  and customized if these additional features are required.
 #
-#  Copyright (c) 2013-2015, Intel Corporation. All rights reserved.
+#  Copyright (c) 2013-2016, Intel Corporation. All rights reserved.
 #  Copyright (c) 2015, Red Hat, Inc.
 #
 #  This program and the accompanying materials
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 07/48] UefiCpuPkg/MpInitLib: Fix typo and clean up the code

2016-08-02 Thread Jeff Fan
1. Rename NumApsExecutingLoction to NumApsExecutingLocation
2. Update some comments in NASM files.
3. Remove PeiCpuMpData from MP_CPU_EXCHANGE_INFO.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc|  2 +-
 UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm | 10 +-
 UefiCpuPkg/Library/MpInitLib/MpLib.h   |  1 -
 UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc |  2 +-
 UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm  | 14 +++---
 5 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc 
b/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc
index 773eab3..015396a 100644
--- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc
+++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc
@@ -33,7 +33,7 @@ GdtrLocation  equLockLocation + 10h
 IdtrLocation  equLockLocation + 16h
 BufferStartLocation   equLockLocation + 1Ch
 ModeOffsetLocationequLockLocation + 20h
-NumApsExecutingLoctionequLockLocation + 24h
+NumApsExecutingLocation   equLockLocation + 24h
 CodeSegmentLocation   equLockLocation + 28h
 DataSegmentLocation   equLockLocation + 2Ch
 
diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm 
b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
index 0852a5b..7050413 100644
--- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
+++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
@@ -71,8 +71,8 @@ o32 lidt   [cs:si]
 xorax,  ax
 movds,  ax
 
-moveax, cr0;Get control register 0
-or eax, 3h ;Set PE bit (bit #0) & MP
+moveax, cr0; Get control register 0
+or eax, 3h ; Set PE bit (bit #0) & MP
 movcr0, eax
 
 jmp0:strict dword 0; far jump to protected mode
@@ -95,7 +95,7 @@ TestLock:
 jz TestLock
 
 movedi, esi
-addedi, NumApsExecutingLoction
+addedi, NumApsExecutingLocation
 incdword [edi]
 movebx, [edi]
 
@@ -133,9 +133,9 @@ CProcedureInvoke:
 addedi, ApProcedureLocation
 moveax, [edi]
 
-call   eax   ; invoke C function
+call   eax   ; Invoke C function
 
-jmp$ ; never reach here
+jmp$ ; Never reach here
 RendezvousFunnelProcEnd:
 
 
;-
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index 0453c22..92d1dd9 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -56,7 +56,6 @@ typedef struct {
   UINTN CodeSegment;
   UINTN DataSegment;
   UINTN Cr3;
-  PEI_CPU_MP_DATA   *PeiCpuMpData;
 } MP_CPU_EXCHANGE_INFO;
 
 #pragma pack()
diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc 
b/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc
index 00f57ce..5aac212 100644
--- a/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc
+++ b/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc
@@ -33,7 +33,7 @@ GdtrLocation  equLockLocation + 20h
 IdtrLocation  equLockLocation + 2Ah
 BufferStartLocation   equLockLocation + 34h
 ModeOffsetLocationequLockLocation + 3Ch
-NumApsExecutingLoctionequLockLocation + 44h
+NumApsExecutingLocation   equLockLocation + 44h
 CodeSegmentLocation   equLockLocation + 4Ch
 DataSegmentLocation   equLockLocation + 54h
 Cr3Location   equLockLocation + 5Ch
diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm 
b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
index f19c75f..848992c 100644
--- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
+++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
@@ -57,7 +57,7 @@ BITS 16
 movdi,  CodeSegmentLocation
 movedx, [di]
 movdi,  ax
-subdi,  02h  
+subdi,  02h
 mov[di],dx ; Patch long mode CS
 subdi,  04h
 addeax, ebx
@@ -117,7 +117,7 @@ TestLock:
 jz TestLock
 
 movedi, esi
-addedi, NumApsExecutingLoction
+addedi, NumApsExecutingLocation
 incdword [edi]
 movebx, [edi]
 
@@ -138,8 +138,8 @@ Releaselock:
 xchg   qword [edi], rax
 
 CProcedureInvoke:
-

[edk2] [Patch v5 14/48] UefiCpuPkg/MpInitLib: Add CPU_VOLATILE_REGISTERS & worker functions

2016-08-02 Thread Jeff Fan
Add CPU_VOLATILE_REGISTERS definitions for CRx and DRx required to be restored
after APs received INIT IPI.

Add worker functions SaveVolatileRegisters()/RestoreVolatileRegisters() used to
save/restore CRx and DRx. It also check if Debugging Extensions supported or
not.

v5:
  1. Add comment block for structure CPU_VOLATILE_REGISTERS.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 71 
 UefiCpuPkg/Library/MpInitLib/MpLib.h | 16 
 2 files changed, 87 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 70e5eb1..0832228 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -47,6 +47,73 @@ SetApState (
 }
 
 /**
+  Save the volatile registers required to be restored following INIT IPI.
+
+  @param[out]  VolatileRegistersReturns buffer saved the volatile resisters
+**/
+VOID
+SaveVolatileRegisters (
+  OUT CPU_VOLATILE_REGISTERS*VolatileRegisters
+  )
+{
+  CPUID_VERSION_INFO_EDXVersionInfoEdx;
+
+  VolatileRegisters->Cr0 = AsmReadCr0 ();
+  VolatileRegisters->Cr3 = AsmReadCr3 ();
+  VolatileRegisters->Cr4 = AsmReadCr4 ();
+
+  AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, NULL, );
+  if (VersionInfoEdx.Bits.DE != 0) {
+//
+// If processor supports Debugging Extensions feature
+// by CPUID.[EAX=01H]:EDX.BIT2
+//
+VolatileRegisters->Dr0 = AsmReadDr0 ();
+VolatileRegisters->Dr1 = AsmReadDr1 ();
+VolatileRegisters->Dr2 = AsmReadDr2 ();
+VolatileRegisters->Dr3 = AsmReadDr3 ();
+VolatileRegisters->Dr6 = AsmReadDr6 ();
+VolatileRegisters->Dr7 = AsmReadDr7 ();
+  }
+}
+
+/**
+  Restore the volatile registers following INIT IPI.
+
+  @param[in]  VolatileRegisters   Pointer to volatile resisters
+  @param[in]  IsRestoreDr TRUE:  Restore DRx if supported
+  FALSE: Do not restore DRx
+**/
+VOID
+RestoreVolatileRegisters (
+  IN CPU_VOLATILE_REGISTERS*VolatileRegisters,
+  IN BOOLEAN   IsRestoreDr
+  )
+{
+  CPUID_VERSION_INFO_EDXVersionInfoEdx;
+
+  AsmWriteCr0 (VolatileRegisters->Cr0);
+  AsmWriteCr3 (VolatileRegisters->Cr3);
+  AsmWriteCr4 (VolatileRegisters->Cr4);
+
+  if (IsRestoreDr) {
+AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, NULL, );
+if (VersionInfoEdx.Bits.DE != 0) {
+  //
+  // If processor supports Debugging Extensions feature
+  // by CPUID.[EAX=01H]:EDX.BIT2
+  //
+  AsmWriteDr0 (VolatileRegisters->Dr0);
+  AsmWriteDr1 (VolatileRegisters->Dr1);
+  AsmWriteDr2 (VolatileRegisters->Dr2);
+  AsmWriteDr3 (VolatileRegisters->Dr3);
+  AsmWriteDr6 (VolatileRegisters->Dr6);
+  AsmWriteDr7 (VolatileRegisters->Dr7);
+}
+  }
+}
+
+/**
   Detect whether Mwait-monitor feature is supported.
 
   @retval TRUEMwait-monitor feature is supported.
@@ -204,6 +271,10 @@ MpInitLibInitialize (
   CpuMpData->CpuInfoInHob = (UINT64) (UINTN) (CpuMpData->CpuData + 
MaxLogicalProcessorNumber);
   InitializeSpinLock(>MpLock);
   //
+  // Save BSP's Control registers to APs
+  //
+  SaveVolatileRegisters (>CpuData[0].VolatileRegisters);
+  //
   // Set BSP basic information
   //
   InitializeApData (CpuMpData, 0, 0);
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index 84bd872..ca8bd44 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -66,6 +66,21 @@ typedef enum {
 } CPU_STATE;
 
 //
+// CPU volatile registers around INIT-SIPI-SIPI
+//
+typedef struct {
+  UINTN  Cr0;
+  UINTN  Cr3;
+  UINTN  Cr4;
+  UINTN  Dr0;
+  UINTN  Dr1;
+  UINTN  Dr2;
+  UINTN  Dr3;
+  UINTN  Dr6;
+  UINTN  Dr7;
+} CPU_VOLATILE_REGISTERS;
+
+//
 // AP related data
 //
 typedef struct {
@@ -78,6 +93,7 @@ typedef struct {
   UINT32 Health;
   BOOLEANCpuHealthy;
   volatile CPU_STATE State;
+  CPU_VOLATILE_REGISTERS VolatileRegisters;
   BOOLEANWaiting;
   BOOLEAN*Finished;
   UINT64 ExpectedTime;
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 06/48] UefiCpuPkg/MpInitLib: Add AP assembly code and MP_CPU_EXCHANGE_INFO

2016-08-02 Thread Jeff Fan
Add assembly code for AP reset vector and the definition of MP_CPU_EXCHANGE_INFO
that are used to exchange the data between C code and assembly code when AP wake
up.

v4:
  1. Copy MP_CPU_EXCHANGE_INFO from UefiCpuPkg/CpuMpPei/CpuMpPei.h
  2. Copy MpEqu.inc and MpFuncs.nasm from UefiCpuPkg/CpuMpPei.

v3:
  1. Rename NumApsExecutingLoction to NumApsExecutingLocation
  2. Add whitespace after ; in .nasm file

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf  |  8 
 .../{CpuMpPei => Library/MpInitLib}/Ia32/MpEqu.inc |  0
 .../MpInitLib}/Ia32/MpFuncs.nasm   |  0
 UefiCpuPkg/Library/MpInitLib/MpLib.h   | 24 ++
 UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf  |  8 
 .../{CpuMpPei => Library/MpInitLib}/X64/MpEqu.inc  |  0
 .../MpInitLib}/X64/MpFuncs.nasm|  0
 7 files changed, 40 insertions(+)
 copy UefiCpuPkg/{CpuMpPei => Library/MpInitLib}/Ia32/MpEqu.inc (100%)
 copy UefiCpuPkg/{CpuMpPei => Library/MpInitLib}/Ia32/MpFuncs.nasm (100%)
 copy UefiCpuPkg/{CpuMpPei => Library/MpInitLib}/X64/MpEqu.inc (100%)
 copy UefiCpuPkg/{CpuMpPei => Library/MpInitLib}/X64/MpFuncs.nasm (100%)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf 
b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
index 1f131c0..e9a2725 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
@@ -27,6 +27,14 @@ [Defines]
 #  VALID_ARCHITECTURES   = IA32 X64
 #
 
+[Sources.IA32]
+  Ia32/MpEqu.inc
+  Ia32/MpFuncs.nasm
+
+[Sources.X64]
+  X64/MpEqu.inc
+  X64/MpFuncs.nasm
+
 [Sources.common]
   DxeMpLib.c
   MpLib.c
diff --git a/UefiCpuPkg/CpuMpPei/Ia32/MpEqu.inc 
b/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc
similarity index 100%
copy from UefiCpuPkg/CpuMpPei/Ia32/MpEqu.inc
copy to UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc
diff --git a/UefiCpuPkg/CpuMpPei/Ia32/MpFuncs.nasm 
b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
similarity index 100%
copy from UefiCpuPkg/CpuMpPei/Ia32/MpFuncs.nasm
copy to UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index 66425d3..0453c22 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -36,5 +36,29 @@
 #include 
 
 
+#pragma pack(1)
+
+//
+// MP CPU exchange information for AP reset code
+// This structure is required to be packed because fixed field offsets
+// into this structure are used in assembly code in this module
+//
+typedef struct {
+  UINTN Lock;
+  UINTN StackStart;
+  UINTN StackSize;
+  UINTN CFunction;
+  IA32_DESCRIPTOR   GdtrProfile;
+  IA32_DESCRIPTOR   IdtrProfile;
+  UINTN BufferStart;
+  UINTN ModeOffset;
+  UINTN NumApsExecuting;
+  UINTN CodeSegment;
+  UINTN DataSegment;
+  UINTN Cr3;
+  PEI_CPU_MP_DATA   *PeiCpuMpData;
+} MP_CPU_EXCHANGE_INFO;
+
+#pragma pack()
 #endif
 
diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf 
b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
index 014a248..c195a38 100644
--- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
+++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
@@ -27,6 +27,14 @@ [Defines]
 #  VALID_ARCHITECTURES   = IA32 X64
 #
 
+[Sources.IA32]
+  Ia32/MpEqu.inc
+  Ia32/MpFuncs.nasm
+
+[Sources.X64]
+  X64/MpEqu.inc
+  X64/MpFuncs.nasm
+
 [Sources.common]
   PeiMpLib.c
   MpLib.c
diff --git a/UefiCpuPkg/CpuMpPei/X64/MpEqu.inc 
b/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc
similarity index 100%
copy from UefiCpuPkg/CpuMpPei/X64/MpEqu.inc
copy to UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc
diff --git a/UefiCpuPkg/CpuMpPei/X64/MpFuncs.nasm 
b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
similarity index 100%
copy from UefiCpuPkg/CpuMpPei/X64/MpFuncs.nasm
copy to UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 10/48] UefiCpuPkg/MpInitLib: Add MP_ASSEMBLY_ADDRESS_MAP

2016-08-02 Thread Jeff Fan
In MpInitLibInitialize(), invoke AsmGetAddress() to get get assembly functions'
entry addresses and the sizes from returned MP_ASSEMBLY_ADDRESS_MAP structure.

v5:
  1. Add more detailed comments for structure MP_ASSEMBLY_ADDRESS_MAP.

v4:
  1. Add AsmRelocateApLoop information return in AsmGetAddress().

v3:
  1. Rename AsmRellocateApLoop to AsmRelocateApLoop.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm |  2 ++
 UefiCpuPkg/Library/MpInitLib/MpLib.c   |  7 ++-
 UefiCpuPkg/Library/MpInitLib/MpLib.h   | 25 +
 UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm  |  3 +++
 4 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm 
b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
index 49f5503..8f6f0bf 100644
--- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
+++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
@@ -204,6 +204,8 @@ ASM_PFX(AsmGetAddressMap):
 movdword [ebx], RendezvousFunnelProcStart
 movdword [ebx +  4h], Flat32Start - RendezvousFunnelProcStart
 movdword [ebx +  8h], RendezvousFunnelProcEnd - 
RendezvousFunnelProcStart
+movdword [ebx + 0Ch], AsmRelocateApLoopStart
+movdword [ebx + 10h], AsmRelocateApLoopEnd - AsmRelocateApLoopStart
 
 popad
 ret
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 12bd04e..3ac79b6 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -34,7 +34,12 @@ MpInitLibInitialize (
   VOID
   )
 {
-  return EFI_UNSUPPORTED;
+  MP_ASSEMBLY_ADDRESS_MAP  AddressMap;
+  UINTNApResetVectorSize;
+
+  AsmGetAddressMap ();
+  ApResetVectorSize = AddressMap.RendezvousFunnelSize + sizeof 
(MP_CPU_EXCHANGE_INFO);
+  return EFI_SUCCESS;
 }
 
 /**
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index 39ec5de..2be1351 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -35,6 +35,18 @@
 #include 
 #include 
 
+//
+// AP reset code information including code address and size,
+// this structure will be shared be C code and assembly code.
+// It is natural aligned by design.
+//
+typedef struct {
+  UINT8 *RendezvousFunnelAddress;
+  UINTN ModeEntryOffset;
+  UINTN RendezvousFunnelSize;
+  UINT8 *RelocateApLoopFuncAddress;
+  UINTN RelocateApLoopFuncSize;
+} MP_ASSEMBLY_ADDRESS_MAP;
 
 #pragma pack(1)
 
@@ -81,5 +93,18 @@ VOID
   IN UINTN   ApTargetCState,
   IN UINTN   PmCodeSegment
   );
+
+/**
+  Assembly code to get starting address and size of the rendezvous entry for 
APs.
+  Information for fixing a jump instruction in the code is also returned.
+
+  @param[out] AddressMap  Output buffer for address map information.
+**/
+VOID
+EFIAPI
+AsmGetAddressMap (
+  OUT MP_ASSEMBLY_ADDRESS_MAP*AddressMap
+  );
+
 #endif
 
diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm 
b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
index d5d7efe..090e9fa 100644
--- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
+++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
@@ -239,6 +239,9 @@ ASM_PFX(AsmGetAddressMap):
 movqword [rcx], rax
 movqword [rcx +  8h], LongModeStart - RendezvousFunnelProcStart
 movqword [rcx + 10h], RendezvousFunnelProcEnd - 
RendezvousFunnelProcStart
+movrax, ASM_PFX(AsmRelocateApLoop)
+movqword [rcx + 18h], rax
+movqword [rcx + 20h], AsmRelocateApLoopEnd - AsmRelocateApLoopStart
 ret
 
 
;-
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 11/48] UefiCpuPkg/MpInitLib: Get ApLoopMode and MointorFilter size

2016-08-02 Thread Jeff Fan
Firstly, get ApLoopMode from PcdCpuApLoopMode. If MonitorMwait feature is not
supported, update ApLoopMode to ApHltLoop. If MonitorMwait feature is supported,
get MointorFilter size by CPUID.[EAX=05H]:EBX.BIT0-15.

v5:
  1. Add comment block for enum AP_LOOP_MODE.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 63 
 UefiCpuPkg/Library/MpInitLib/MpLib.h | 10 ++
 2 files changed, 73 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 3ac79b6..32bbaee 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -16,6 +16,65 @@
 
 
 /**
+  Detect whether Mwait-monitor feature is supported.
+
+  @retval TRUEMwait-monitor feature is supported.
+  @retval FALSE   Mwait-monitor feature is not supported.
+**/
+BOOLEAN
+IsMwaitSupport (
+  VOID
+  )
+{
+  CPUID_VERSION_INFO_ECXVersionInfoEcx;
+
+  AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, , NULL);
+  return (VersionInfoEcx.Bits.MONITOR == 1) ? TRUE : FALSE;
+}
+
+/**
+  Get AP loop mode.
+
+  @param[out] MonitorFilterSize  Returns the largest monitor-line size in 
bytes.
+
+  @return The AP loop mode.
+**/
+UINT8
+GetApLoopMode (
+  OUT UINT32 *MonitorFilterSize
+  )
+{
+  UINT8 ApLoopMode;
+  CPUID_MONITOR_MWAIT_EBX   MonitorMwaitEbx;
+
+  ASSERT (MonitorFilterSize != NULL);
+
+  ApLoopMode = PcdGet8 (PcdCpuApLoopMode);
+  ASSERT (ApLoopMode >= ApInHltLoop && ApLoopMode <= ApInRunLoop);
+  if (ApLoopMode == ApInMwaitLoop) {
+if (!IsMwaitSupport ()) {
+  //
+  // If processor does not support MONITOR/MWAIT feature,
+  // force AP in Hlt-loop mode
+  //
+  ApLoopMode = ApInHltLoop;
+}
+  }
+
+  if (ApLoopMode != ApInMwaitLoop) {
+*MonitorFilterSize = sizeof (UINT32);
+  } else {
+//
+// CPUID.[EAX=05H]:EBX.BIT0-15: Largest monitor-line size in bytes
+// CPUID.[EAX=05H].EDX: C-states supported using MWAIT
+//
+AsmCpuid (CPUID_MONITOR_MWAIT, NULL, , NULL, NULL);
+*MonitorFilterSize = MonitorMwaitEbx.Bits.LargestMonitorLineSize;
+  }
+
+  return ApLoopMode;
+}
+/**
   MP Initialize Library initialization.
 
   This service will allocate AP reset vector and wakeup all APs to do APs
@@ -35,10 +94,14 @@ MpInitLibInitialize (
   )
 {
   MP_ASSEMBLY_ADDRESS_MAP  AddressMap;
+  UINT32   MonitorFilterSize;
+  UINT8ApLoopMode;
   UINTNApResetVectorSize;
 
   AsmGetAddressMap ();
   ApResetVectorSize = AddressMap.RendezvousFunnelSize + sizeof 
(MP_CPU_EXCHANGE_INFO);
+  ApLoopMode  = GetApLoopMode ();
+
   return EFI_SUCCESS;
 }
 
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index 2be1351..317facc 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -36,6 +36,16 @@
 #include 
 
 //
+// AP loop state when APs are in idle state
+// It's value is the same with PcdCpuApLoopMode
+//
+typedef enum {
+  ApInHltLoop   = 1,
+  ApInMwaitLoop = 2,
+  ApInRunLoop   = 3
+} AP_LOOP_MODE;
+
+//
 // AP reset code information including code address and size,
 // this structure will be shared be C code and assembly code.
 // It is natural aligned by design.
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 09/48] UefiCpuPkg/MpInitLib: Add AsmRelocateApLoop() assembly code

2016-08-02 Thread Jeff Fan
AsmRelocateApLoop() is used to place APs into MWAIT-loop if MonitorMwait
feature is supported before hand-off to OS, or place APs into HLT-loop if
MonitorMwait feature is not supported.

If the current mode is long mode, we will switch APs to protected mode
before placing APs in MWAIT-loop or HLT-loop. Thus, once APs wakeup from
loop, APs needn't the page table that may be crashed by OS.

v3:
  1. Rename AsmRellocateApLoop to AsmRelocateApLoop.
  2. Fix typo Proteced to Protected.
  3. Fix typo segement to segment
  4. Use word MONITOR instead of mwait-monitor.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
Reviewed-by: Giri P Mudusuru 
---
 UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm | 24 
 UefiCpuPkg/Library/MpInitLib/MpLib.h   | 21 ++
 UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm  | 54 ++
 3 files changed, 99 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm 
b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
index 8bacb42..49f5503 100644
--- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
+++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
@@ -169,6 +169,30 @@ CProcedureInvoke:
 RendezvousFunnelProcEnd:
 
 
;-
+;  AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment);
+;-
+global ASM_PFX(AsmRelocateApLoop)
+ASM_PFX(AsmRelocateApLoop):
+AsmRelocateApLoopStart:
+cmpbyte [esp + 4], 1
+jnzHltLoop
+MwaitLoop:
+moveax, esp
+xorecx, ecx
+xoredx, edx
+monitor
+moveax, [esp + 8]; Mwait Cx, Target C-State per eax[7:4]
+shleax, 4
+mwait
+jmpMwaitLoop
+HltLoop:
+cli
+hlt
+jmpHltLoop
+ret
+AsmRelocateApLoopEnd:
+
+;-
 ;  AsmGetAddressMap ();
 
;-
 global ASM_PFX(AsmGetAddressMap)
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index 28a3cd4..39ec5de 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -60,5 +60,26 @@ typedef struct {
 } MP_CPU_EXCHANGE_INFO;
 
 #pragma pack()
+/**
+  Assembly code to place AP into safe loop mode.
+
+  Place AP into targeted C-State if MONITOR is supported, otherwise
+  place AP into hlt state.
+  Place AP in protected mode if the current is long mode. Due to AP maybe
+  wakeup by some hardware event. It could avoid accessing page table that
+  may not available during booting to OS.
+
+  @param[in] MwaitSupportTRUE indicates MONITOR is supported.
+ FALSE indicates MONITOR is not supported.
+  @param[in] ApTargetCState  Target C-State value.
+  @param[in] PmCodeSegment   Protected mode code segment value.
+**/
+typedef
+VOID
+(EFIAPI * ASM_RELOCATE_AP_LOOP) (
+  IN BOOLEAN MwaitSupport,
+  IN UINTN   ApTargetCState,
+  IN UINTN   PmCodeSegment
+  );
 #endif
 
diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm 
b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
index 3c55ffa..d5d7efe 100644
--- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
+++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
@@ -177,6 +177,60 @@ CProcedureInvoke:
 RendezvousFunnelProcEnd:
 
 
;-
+;  AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment);
+;-
+global ASM_PFX(AsmRelocateApLoop)
+ASM_PFX(AsmRelocateApLoop):
+AsmRelocateApLoopStart:
+push   rcx
+push   rdx
+
+learsi, [PmEntry]; rsi <- The start address of transition code
+
+push   r8
+push   rsi
+DB 0x48
+retf
+BITS 32
+PmEntry:
+moveax, cr0
+btreax, 31   ; Clear CR0.PG
+movcr0, eax  ; Disable paging and caches
+
+movebx, edx  ; Save EntryPoint to rbx, for rdmsr will 
overwrite rdx
+movecx, 0xc080
+rdmsr
+andah, ~ 1   ; Clear LME
+wrmsr
+moveax, cr4
+andal, ~ (1 << 5); Clear PAE
+movcr4, eax
+
+popedx
+addesp, 4
+popecx,
+addesp, 4
+cmpcl, 1  ; Check mwait-monitor support
+jnzHltLoop
+movebx, edx   ; 

[edk2] [Patch v5 13/48] UefiCpuPkg/MpInitLib: Initialize CPU_AP_DATA for CPU APs

2016-08-02 Thread Jeff Fan
Initialize CPU_AP_DATA for CPU APs and add GetApState()/SetApState() helper
functions to get/set AP state.

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 76 
 UefiCpuPkg/Library/MpInitLib/MpLib.h | 12 ++
 2 files changed, 88 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index f05db7c..70e5eb1 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -14,6 +14,37 @@
 
 #include "MpLib.h"
 
+/**
+  Get the Application Processors state.
+
+  @param[in]  CpuDataThe pointer to CPU_AP_DATA of specified AP
+
+  @return  The AP status
+**/
+CPU_STATE
+GetApState (
+  IN  CPU_AP_DATA *CpuData
+  )
+{
+  return CpuData->State;
+}
+
+/**
+  Set the Application Processors state.
+
+  @param[in]   CpuDataThe pointer to CPU_AP_DATA of specified AP
+  @param[in]   State  The AP status
+**/
+VOID
+SetApState (
+  IN  CPU_AP_DATA *CpuData,
+  IN  CPU_STATE   State
+  )
+{
+  AcquireSpinLock (>ApLock);
+  CpuData->State = State;
+  ReleaseSpinLock (>ApLock);
+}
 
 /**
   Detect whether Mwait-monitor feature is supported.
@@ -74,6 +105,40 @@ GetApLoopMode (
 
   return ApLoopMode;
 }
+/*
+  Initialize CPU AP Data when AP is wakeup at the first time.
+
+  @param[in, out] CpuMpDataPointer to PEI CPU MP Data
+  @param[in]  ProcessorNumber  The handle number of processor
+  @param[in]  BistData Processor BIST data
+
+**/
+VOID
+InitializeApData (
+  IN OUT CPU_MP_DATA  *CpuMpData,
+  IN UINTNProcessorNumber,
+  IN UINT32   BistData
+  )
+{
+  CpuMpData->CpuData[ProcessorNumber].Waiting= FALSE;
+  CpuMpData->CpuData[ProcessorNumber].Health = BistData;
+  CpuMpData->CpuData[ProcessorNumber].CpuHealthy = (BistData == 0) ? TRUE : 
FALSE;
+  CpuMpData->CpuData[ProcessorNumber].ApicId = GetApicId ();
+  CpuMpData->CpuData[ProcessorNumber].InitialApicId = GetInitialApicId ();
+  if (CpuMpData->CpuData[ProcessorNumber].InitialApicId >= 0xFF) {
+//
+// Set x2APIC mode if there are any logical processor reporting
+// an Initial APIC ID of 255 or greater.
+//
+AcquireSpinLock(>MpLock);
+CpuMpData->X2ApicEnable = TRUE;
+ReleaseSpinLock(>MpLock);
+  }
+
+  InitializeSpinLock(>CpuData[ProcessorNumber].ApLock);
+  SetApState (>CpuData[ProcessorNumber], CpuStateIdle);
+}
+
 /**
   MP Initialize Library initialization.
 
@@ -103,6 +168,7 @@ MpInitLibInitialize (
   CPU_MP_DATA  *CpuMpData;
   UINT8ApLoopMode;
   UINT8*MonitorBuffer;
+  UINTNIndex;
   UINTNApResetVectorSize;
   UINTNBackupBufferAddr;
   MaxLogicalProcessorNumber = PcdGet32(PcdCpuMaxLogicalProcessorNumber);
@@ -138,6 +204,10 @@ MpInitLibInitialize (
   CpuMpData->CpuInfoInHob = (UINT64) (UINTN) (CpuMpData->CpuData + 
MaxLogicalProcessorNumber);
   InitializeSpinLock(>MpLock);
   //
+  // Set BSP basic information
+  //
+  InitializeApData (CpuMpData, 0, 0);
+  //
   // Save assembly code information
   //
   CopyMem (>AddressMap, , sizeof 
(MP_ASSEMBLY_ADDRESS_MAP));
@@ -147,6 +217,12 @@ MpInitLibInitialize (
   CpuMpData->ApLoopMode = ApLoopMode;
   DEBUG ((DEBUG_INFO, "AP Loop Mode is %d\n", CpuMpData->ApLoopMode));
   //
+  // Set up APs wakeup signal buffer
+  //
+  for (Index = 0; Index < MaxLogicalProcessorNumber; Index++) {
+CpuMpData->CpuData[Index].StartupApSignal =
+  (UINT32 *)(MonitorBuffer + MonitorFilterSize * Index);
+  }
   // Store BSP's MTRR setting
   //
   MtrrGetAllMtrrs (>MtrrTable);
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index e605f8d..84bd872 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -55,6 +55,17 @@ typedef enum {
 } AP_INIT_STATE;
 
 //
+// AP state
+//
+typedef enum {
+  CpuStateIdle,
+  CpuStateReady,
+  CpuStateBusy,
+  CpuStateFinished,
+  CpuStateDisabled
+} CPU_STATE;
+
+//
 // AP related data
 //
 typedef struct {
@@ -66,6 +77,7 @@ typedef struct {
   UINT32 ApicId;
   UINT32 Health;
   BOOLEANCpuHealthy;
+  volatile CPU_STATE State;
   BOOLEANWaiting;
   BOOLEAN*Finished;
   UINT64 ExpectedTime;
-- 
2.7.4.windows.1

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


[edk2] [Patch v5 05/48] UefiCpuPkg/MpInitLib: Add two instances PeiMpInitLib and DxeMpInitLib

2016-08-02 Thread Jeff Fan
Add two MP Initialize Library instances PeiMpInitLib.inf and DxeMpInitLib.inf
with NULL implementation.

One PeiMpInitLib.inf is consumed by PEI MP driver. Another DxeMpInitLib.inf is
consumed by DXE MP driver.

Place MpInitLibStartupAllAPs()/MpInitLibStartupThisAp()/MpInitLibSwitchBSP()/
MpInitLibEnableDisableAP() into PeiMpLib.c and DxeMpLib.c, because they have
the different implementations and will be updated in latter patches.

v5:
  1. Add back PeiExceptionHandlerLib.inf in UefiCpuPkg.dsc. It is removed
 incorrectly.

v4:
  1. Return EFI_UNSUPPORTED instead of EFI_SUCCESS for NULL implementation of
 all Functions.
  2. Sync MpInitLibxxx functions header updating described in v4 part of Patch
 #4.

v3:
  1. Rename MpInitLibSwitchBsp to MpInitLibSwitchBSP to match PI spec

Cc: Michael Kinney 
Cc: Feng Tian 
Cc: Giri P Mudusuru 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan 
Reviewed-by: Giri P Mudusuru 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf  |  61 ++
 .../Library/MpInitLib/DxeMpInitLib.uni |  12 +-
 .../MpInitLib.h => Library/MpInitLib/DxeMpLib.c}   | 123 +++--
 UefiCpuPkg/Library/MpInitLib/MpLib.c   | 119 
 UefiCpuPkg/Library/MpInitLib/MpLib.h   |  40 +++
 .../MpInitLib/PeiMpInitLib.inf}|  65 +++
 .../Library/MpInitLib/PeiMpInitLib.uni |  12 +-
 .../MpInitLib.h => Library/MpInitLib/PeiMpLib.c}   | 123 -
 UefiCpuPkg/UefiCpuPkg.dsc  |   2 +
 9 files changed, 291 insertions(+), 266 deletions(-)
 create mode 100644 UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
 copy 
MdeModulePkg/Universal/SmmCommunicationBufferDxe/SmmCommunicationBufferExtraDxe.uni
 => UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.uni (60%)
 copy UefiCpuPkg/{Include/Library/MpInitLib.h => Library/MpInitLib/DxeMpLib.c} 
(78%)
 create mode 100644 UefiCpuPkg/Library/MpInitLib/MpLib.c
 create mode 100644 UefiCpuPkg/Library/MpInitLib/MpLib.h
 copy UefiCpuPkg/{CpuMpPei/CpuMpPei.inf => Library/MpInitLib/PeiMpInitLib.inf} 
(54%)
 copy 
MdeModulePkg/Universal/SmmCommunicationBufferDxe/SmmCommunicationBufferExtraDxe.uni
 => UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.uni (60%)
 copy UefiCpuPkg/{Include/Library/MpInitLib.h => Library/MpInitLib/PeiMpLib.c} 
(78%)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf 
b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
new file mode 100644
index 000..1f131c0
--- /dev/null
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
@@ -0,0 +1,61 @@
+## @file
+#  MP Initialize Library instance for DXE driver.
+#
+#  Copyright (c) 2016, Intel Corporation. All rights reserved.
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD 
License
+#  which accompanies this distribution.  The full text of the license may be 
found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+#
+##
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = DxeMpInitLib
+  MODULE_UNI_FILE= DxeMpInitLib.uni
+  FILE_GUID  = B88F7146-9834-4c55-BFAC-481CC0C33736
+  MODULE_TYPE= DXE_DRIVER
+  VERSION_STRING = 1.1
+  LIBRARY_CLASS  = MpInitLib|DXE_DRIVER
+
+#
+# The following information is for reference only and not required by the 
build tools.
+#
+#  VALID_ARCHITECTURES   = IA32 X64
+#
+
+[Sources.common]
+  DxeMpLib.c
+  MpLib.c
+  MpLib.h
+
+[Packages]
+  MdePkg/MdePkg.dec
+  UefiCpuPkg/UefiCpuPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  LocalApicLib
+  MemoryAllocationLib
+  HobLib
+  MtrrLib
+  CpuLib
+  UefiCpuLib
+  UefiBootServicesTableLib
+  HobLib
+
+[Guids]
+  gEfiEventExitBootServicesGuid ## CONSUMES  ## Event
+
+[Pcd]
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber## CONSUMES
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuApInitTimeOutInMicroSeconds  ## 
SOMETIMES_CONSUMES
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize  ## CONSUMES
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchAddress## CONSUMES
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize ## CONSUMES
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode   ## CONSUMES
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate   ## 
SOMETIMES_CONSUMES
+
diff --git 
a/MdeModulePkg/Universal/SmmCommunicationBufferDxe/SmmCommunicationBufferExtraDxe.uni
 b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.uni
similarity index 60%
copy from 

  1   2   >