mirror of
				https://github.com/acidanthera/audk.git
				synced 2025-10-31 19:23:54 +01:00 
			
		
		
		
	EdkGenericBdsLib added
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2367 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
		
							parent
							
								
									15f83a8852
								
							
						
					
					
						commit
						8033e93148
					
				
							
								
								
									
										400
									
								
								EdkModulePkg/Include/Library/EdkGenericBdsLib.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										400
									
								
								EdkModulePkg/Include/Library/EdkGenericBdsLib.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,400 @@ | |||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Copyright (c) 2006, 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.              | ||||||
|  | 
 | ||||||
|  | Module Name: | ||||||
|  | 
 | ||||||
|  |   BdsLib.h | ||||||
|  | 
 | ||||||
|  | Abstract: | ||||||
|  | 
 | ||||||
|  |   BDS library definition, include the file and data structure | ||||||
|  | 
 | ||||||
|  | --*/ | ||||||
|  | 
 | ||||||
|  | #ifndef _BDS_LIB_H_ | ||||||
|  | #define _BDS_LIB_H_ | ||||||
|  | 
 | ||||||
|  | extern EFI_HANDLE mBdsImageHandle; | ||||||
|  | 
 | ||||||
|  | //
 | ||||||
|  | // Constants which are variable names used to access variables
 | ||||||
|  | //
 | ||||||
|  | #define VarLegacyDevOrder L"LegacyDevOrder" | ||||||
|  | 
 | ||||||
|  | //
 | ||||||
|  | // Data structures and defines
 | ||||||
|  | //
 | ||||||
|  | #define FRONT_PAGE_QUESTION_ID  0x0000 | ||||||
|  | #define FRONT_PAGE_DATA_WIDTH   0x01 | ||||||
|  | 
 | ||||||
|  | //
 | ||||||
|  | // ConnectType
 | ||||||
|  | //
 | ||||||
|  | #define CONSOLE_OUT 0x00000001 | ||||||
|  | #define STD_ERROR   0x00000002 | ||||||
|  | #define CONSOLE_IN  0x00000004 | ||||||
|  | #define CONSOLE_ALL (CONSOLE_OUT | CONSOLE_IN | STD_ERROR) | ||||||
|  | 
 | ||||||
|  | //
 | ||||||
|  | // Load Option Attributes defined in EFI Specification
 | ||||||
|  | //
 | ||||||
|  | #define LOAD_OPTION_ACTIVE              0x00000001 | ||||||
|  | #define LOAD_OPTION_FORCE_RECONNECT     0x00000002 | ||||||
|  | #define IS_LOAD_OPTION_TYPE(_c, _Mask)  (BOOLEAN) (((_c) & (_Mask)) != 0) | ||||||
|  | 
 | ||||||
|  | //
 | ||||||
|  | // Define Maxmim characters that will be accepted
 | ||||||
|  | //
 | ||||||
|  | #define MAX_CHAR            480 | ||||||
|  | #define MAX_CHAR_SIZE       (MAX_CHAR * 2) | ||||||
|  | 
 | ||||||
|  | #define MIN_ALIGNMENT_SIZE  4 | ||||||
|  | #define ALIGN_SIZE(a)       ((a % MIN_ALIGNMENT_SIZE) ? MIN_ALIGNMENT_SIZE - (a % MIN_ALIGNMENT_SIZE) : 0) | ||||||
|  | 
 | ||||||
|  | //
 | ||||||
|  | // Define maximum characters for boot option variable "BootXXXX"
 | ||||||
|  | //
 | ||||||
|  | #define BOOT_OPTION_MAX_CHAR 10 | ||||||
|  | 
 | ||||||
|  | //
 | ||||||
|  | // This data structure is the part of BDS_CONNECT_ENTRY that we can hard code.
 | ||||||
|  | //
 | ||||||
|  | #define BDS_LOAD_OPTION_SIGNATURE EFI_SIGNATURE_32 ('B', 'd', 'C', 'O') | ||||||
|  | 
 | ||||||
|  | typedef struct { | ||||||
|  | 
 | ||||||
|  |   UINTN                     Signature; | ||||||
|  |   LIST_ENTRY                Link; | ||||||
|  | 
 | ||||||
|  |   EFI_DEVICE_PATH_PROTOCOL  *DevicePath; | ||||||
|  | 
 | ||||||
|  |   CHAR16                    *OptionName; | ||||||
|  |   UINTN                     OptionNumber; | ||||||
|  |   UINT16                    BootCurrent; | ||||||
|  |   UINT32                    Attribute; | ||||||
|  |   CHAR16                    *Description; | ||||||
|  |   VOID                      *LoadOptions; | ||||||
|  |   UINT32                    LoadOptionsSize; | ||||||
|  | 
 | ||||||
|  | } BDS_COMMON_OPTION; | ||||||
|  | 
 | ||||||
|  | typedef struct { | ||||||
|  |   EFI_DEVICE_PATH_PROTOCOL  *DevicePath; | ||||||
|  |   UINTN                     ConnectType; | ||||||
|  | } BDS_CONSOLE_CONNECT_ENTRY; | ||||||
|  | 
 | ||||||
|  | //
 | ||||||
|  | // Lib Functions
 | ||||||
|  | //
 | ||||||
|  | 
 | ||||||
|  | //
 | ||||||
|  | // Bds boot relate lib functions
 | ||||||
|  | //
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibUpdateBootOrderList ( | ||||||
|  |   IN  LIST_ENTRY                 *BdsOptionList, | ||||||
|  |   IN  CHAR16                     *VariableName | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | BdsLibBootNext ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibBootViaBootOption ( | ||||||
|  |   IN  BDS_COMMON_OPTION             * Option, | ||||||
|  |   IN  EFI_DEVICE_PATH_PROTOCOL      * DevicePath, | ||||||
|  |   OUT UINTN                         *ExitDataSize, | ||||||
|  |   OUT CHAR16                        **ExitData OPTIONAL | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibEnumerateAllBootOption ( | ||||||
|  |   IN OUT LIST_ENTRY    *BdsBootOptionList | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | BdsLibBuildOptionFromHandle ( | ||||||
|  |   IN  EFI_HANDLE      Handle, | ||||||
|  |   IN  LIST_ENTRY      *BdsBootOptionList | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | BdsLibBuildOptionFromShell ( | ||||||
|  |   IN  EFI_HANDLE                 Handle, | ||||||
|  |   IN  LIST_ENTRY                 *BdsBootOptionList | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | //
 | ||||||
|  | // Bds misc lib functions
 | ||||||
|  | //
 | ||||||
|  | UINT16 | ||||||
|  | BdsLibGetTimeout ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibGetBootMode ( | ||||||
|  |   OUT EFI_BOOT_MODE       *BootMode | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | BdsLibLoadDrivers ( | ||||||
|  |   IN  LIST_ENTRY          *BdsDriverLists | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibBuildOptionFromVar ( | ||||||
|  |   IN  LIST_ENTRY          *BdsCommonOptionList, | ||||||
|  |   IN  CHAR16              *VariableName | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | VOID                      * | ||||||
|  | BdsLibGetVariableAndSize ( | ||||||
|  |   IN  CHAR16              *Name, | ||||||
|  |   IN  EFI_GUID            *VendorGuid, | ||||||
|  |   OUT UINTN               *VariableSize | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibOutputStrings ( | ||||||
|  |   IN EFI_SIMPLE_TEXT_OUT_PROTOCOL   *ConOut, | ||||||
|  |   ... | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | BDS_COMMON_OPTION         * | ||||||
|  | BdsLibVariableToOption ( | ||||||
|  |   IN OUT LIST_ENTRY               *BdsCommonOptionList, | ||||||
|  |   IN CHAR16                       *VariableName | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibRegisterNewOption ( | ||||||
|  |   IN  LIST_ENTRY                     *BdsOptionList, | ||||||
|  |   IN  EFI_DEVICE_PATH_PROTOCOL       *DevicePath, | ||||||
|  |   IN  CHAR16                         *String, | ||||||
|  |   IN  CHAR16                         *VariableName | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | //
 | ||||||
|  | // Bds connect or disconnect driver lib funcion
 | ||||||
|  | //
 | ||||||
|  | VOID | ||||||
|  | BdsLibConnectAllDriversToAllControllers ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | BdsLibConnectAll ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibConnectDevicePath ( | ||||||
|  |   IN EFI_DEVICE_PATH_PROTOCOL  *DevicePathToConnect | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibConnectAllEfi ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibDisconnectAllEfi ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | //
 | ||||||
|  | // Bds console relate lib functions
 | ||||||
|  | //
 | ||||||
|  | VOID | ||||||
|  | BdsLibConnectAllConsoles ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibConnectAllDefaultConsoles ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibUpdateConsoleVariable ( | ||||||
|  |   IN  CHAR16                    *ConVarName, | ||||||
|  |   IN  EFI_DEVICE_PATH_PROTOCOL  *CustomizedConDevicePath, | ||||||
|  |   IN  EFI_DEVICE_PATH_PROTOCOL  *ExclusiveDevicePath | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibConnectConsoleVariable ( | ||||||
|  |   IN  CHAR16                 *ConVarName | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | //
 | ||||||
|  | // Bds device path relate lib functions
 | ||||||
|  | //
 | ||||||
|  | EFI_DEVICE_PATH_PROTOCOL  * | ||||||
|  | BdsLibUnpackDevicePath ( | ||||||
|  |   IN EFI_DEVICE_PATH_PROTOCOL  *DevPath | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | BdsLibSafeFreePool ( | ||||||
|  |   IN  VOID             *Buffer | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | EFI_DEVICE_PATH_PROTOCOL * | ||||||
|  | BdsLibDelPartMatchInstance ( | ||||||
|  |   IN     EFI_DEVICE_PATH_PROTOCOL  *Multi, | ||||||
|  |   IN     EFI_DEVICE_PATH_PROTOCOL  *Single | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | BOOLEAN | ||||||
|  | BdsLibMatchDevicePaths ( | ||||||
|  |   IN  EFI_DEVICE_PATH_PROTOCOL  *Multi, | ||||||
|  |   IN  EFI_DEVICE_PATH_PROTOCOL  *Single | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | CHAR16                    * | ||||||
|  | DevicePathToStr ( | ||||||
|  |   EFI_DEVICE_PATH_PROTOCOL     *DevPath | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | VOID                      * | ||||||
|  | EfiLibGetVariable ( | ||||||
|  |   IN CHAR16               *Name, | ||||||
|  |   IN EFI_GUID             *VendorGuid | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | //
 | ||||||
|  | // Internal definitions
 | ||||||
|  | //
 | ||||||
|  | typedef struct { | ||||||
|  |   CHAR16  *str; | ||||||
|  |   UINTN   len; | ||||||
|  |   UINTN   maxlen; | ||||||
|  | } POOL_PRINT; | ||||||
|  | 
 | ||||||
|  | typedef struct { | ||||||
|  |   UINT8 Type; | ||||||
|  |   UINT8 SubType; | ||||||
|  |   VOID (*Function) (POOL_PRINT *, VOID *); | ||||||
|  | } DEVICE_PATH_STRING_TABLE; | ||||||
|  | 
 | ||||||
|  | //
 | ||||||
|  | // Internal functions
 | ||||||
|  | //
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsBootByDiskSignatureAndPartition ( | ||||||
|  |   IN  BDS_COMMON_OPTION          * Option, | ||||||
|  |   IN  HARDDRIVE_DEVICE_PATH      * HardDriveDevicePath, | ||||||
|  |   IN  UINT32                     LoadOptionsSize, | ||||||
|  |   IN  VOID                       *LoadOptions, | ||||||
|  |   OUT UINTN                      *ExitDataSize, | ||||||
|  |   OUT CHAR16                     **ExitData OPTIONAL | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | //
 | ||||||
|  | // Notes: EFI 64 shadow all option rom
 | ||||||
|  | //
 | ||||||
|  | #ifdef EFI64 | ||||||
|  | #define EFI64_SHADOW_ALL_LEGACY_ROM() ShadowAllOptionRom (); | ||||||
|  | VOID | ||||||
|  | ShadowAllOptionRom(); | ||||||
|  | #else | ||||||
|  | #define EFI64_SHADOW_ALL_LEGACY_ROM() | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  | //
 | ||||||
|  | // BBS support macros and functions
 | ||||||
|  | //
 | ||||||
|  | #ifdef EFI32 | ||||||
|  | #define REFRESH_LEGACY_BOOT_OPTIONS \ | ||||||
|  |         BdsDeleteAllInvalidLegacyBootOptions ();\ | ||||||
|  |         BdsAddNonExistingLegacyBootOptions (); \ | ||||||
|  |         BdsUpdateLegacyDevOrder () | ||||||
|  | #else | ||||||
|  | #define REFRESH_LEGACY_BOOT_OPTIONS | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsDeleteAllInvalidLegacyBootOptions ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsAddNonExistingLegacyBootOptions ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsUpdateLegacyDevOrder ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsRefreshBbsTableForBoot ( | ||||||
|  |   IN BDS_COMMON_OPTION        *Entry | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsDeleteBootOption ( | ||||||
|  |   IN UINTN                       OptionNumber, | ||||||
|  |   IN OUT UINT16                  *BootOrder, | ||||||
|  |   IN OUT UINTN                   *BootOrderSize | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | //
 | ||||||
|  | //The interface functions relate with Setup Browser Reset Reminder feature
 | ||||||
|  | //
 | ||||||
|  | VOID | ||||||
|  | EnableResetReminderFeature ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | DisableResetReminderFeature ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | EnableResetRequired ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | DisableResetRequired ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | BOOLEAN | ||||||
|  | IsResetReminderFeatureEnable ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | BOOLEAN | ||||||
|  | IsResetRequired ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | SetupResetReminder ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  |    | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibGetHiiHandles ( | ||||||
|  |   IN     EFI_HII_PROTOCOL *Hii, | ||||||
|  |   IN OUT UINT16           *HandleBufferLength, | ||||||
|  |   OUT    EFI_HII_HANDLE   **HiiHandles | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | #endif // _BDS_LIB_H_
 | ||||||
							
								
								
									
										1097
									
								
								EdkModulePkg/Library/EdkGenericBdsLib/BdsBoot.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1097
									
								
								EdkModulePkg/Library/EdkGenericBdsLib/BdsBoot.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										357
									
								
								EdkModulePkg/Library/EdkGenericBdsLib/BdsConnect.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										357
									
								
								EdkModulePkg/Library/EdkGenericBdsLib/BdsConnect.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,357 @@ | |||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Copyright (c) 2006, 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.              | ||||||
|  | 
 | ||||||
|  | Module Name: | ||||||
|  | 
 | ||||||
|  |   BdsConnect.c | ||||||
|  | 
 | ||||||
|  | Abstract: | ||||||
|  | 
 | ||||||
|  |   BDS Lib functions which relate with connect the device | ||||||
|  | 
 | ||||||
|  | --*/ | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | BdsLibConnectAll ( | ||||||
|  |   VOID | ||||||
|  |   ) | ||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Routine Description: | ||||||
|  |    | ||||||
|  |   This function will connect all the system driver to controller | ||||||
|  |   first, and then special connect the default console, this make | ||||||
|  |   sure all the system controller avialbe and the platform default | ||||||
|  |   console connected. | ||||||
|  |    | ||||||
|  | Arguments: | ||||||
|  | 
 | ||||||
|  |   None | ||||||
|  | 
 | ||||||
|  | Returns: | ||||||
|  | 
 | ||||||
|  |   None | ||||||
|  | 
 | ||||||
|  | --*/ | ||||||
|  | { | ||||||
|  |   //
 | ||||||
|  |   // Connect the platform console first
 | ||||||
|  |   //
 | ||||||
|  |   BdsLibConnectAllDefaultConsoles (); | ||||||
|  | 
 | ||||||
|  |   //
 | ||||||
|  |   // Generic way to connect all the drivers
 | ||||||
|  |   //
 | ||||||
|  |   BdsLibConnectAllDriversToAllControllers (); | ||||||
|  | 
 | ||||||
|  |   //
 | ||||||
|  |   // Here we have the assumption that we have already had
 | ||||||
|  |   // platform default console
 | ||||||
|  |   //
 | ||||||
|  |   BdsLibConnectAllDefaultConsoles (); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | BdsLibGenericConnectAll ( | ||||||
|  |   VOID | ||||||
|  |   ) | ||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Routine Description: | ||||||
|  |    | ||||||
|  |   This function will connect all the system drivers to all controllers | ||||||
|  |   first, and then connect all the console devices the system current  | ||||||
|  |   have. After this we should get all the device work and console avariable | ||||||
|  |   if the system have console device. | ||||||
|  |    | ||||||
|  | Arguments: | ||||||
|  | 
 | ||||||
|  |   None | ||||||
|  | 
 | ||||||
|  | Returns: | ||||||
|  | 
 | ||||||
|  |   None | ||||||
|  | 
 | ||||||
|  | --*/ | ||||||
|  | { | ||||||
|  |   //
 | ||||||
|  |   // Most generic way to connect all the drivers
 | ||||||
|  |   //
 | ||||||
|  |   BdsLibConnectAllDriversToAllControllers (); | ||||||
|  |   BdsLibConnectAllConsoles (); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibConnectDevicePath ( | ||||||
|  |   IN EFI_DEVICE_PATH_PROTOCOL  *DevicePathToConnect | ||||||
|  |   ) | ||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Routine Description: | ||||||
|  |   This function will create all handles associate with every device | ||||||
|  |   path node. If the handle associate with one device path node can not | ||||||
|  |   be created success, then still give one chance to do the dispatch, | ||||||
|  |   which load the missing drivers if possible. | ||||||
|  |    | ||||||
|  | Arguments: | ||||||
|  | 
 | ||||||
|  |   DevicePathToConnect  - The device path which will be connected, it can | ||||||
|  |                          be a multi-instance device path | ||||||
|  | 
 | ||||||
|  | Returns: | ||||||
|  | 
 | ||||||
|  |   EFI_SUCCESS          - All handles associate with every device path  | ||||||
|  |                          node have been created | ||||||
|  |    | ||||||
|  |   EFI_OUT_OF_RESOURCES - There is no resource to create new handles | ||||||
|  |    | ||||||
|  |   EFI_NOT_FOUND        - Create the handle associate with one device  | ||||||
|  |                          path node failed | ||||||
|  | 
 | ||||||
|  | --*/ | ||||||
|  | { | ||||||
|  |   EFI_STATUS                Status; | ||||||
|  |   EFI_DEVICE_PATH_PROTOCOL  *DevicePath; | ||||||
|  |   EFI_DEVICE_PATH_PROTOCOL  *CopyOfDevicePath; | ||||||
|  |   EFI_DEVICE_PATH_PROTOCOL  *Instance; | ||||||
|  |   EFI_DEVICE_PATH_PROTOCOL  *RemainingDevicePath; | ||||||
|  |   EFI_DEVICE_PATH_PROTOCOL  *Next; | ||||||
|  |   EFI_HANDLE                Handle; | ||||||
|  |   EFI_HANDLE                PreviousHandle; | ||||||
|  |   UINTN                     Size; | ||||||
|  | 
 | ||||||
|  |   if (DevicePathToConnect == NULL) { | ||||||
|  |     return EFI_SUCCESS; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   DevicePath        = DuplicateDevicePath (DevicePathToConnect); | ||||||
|  |   CopyOfDevicePath  = DevicePath; | ||||||
|  |   if (DevicePath == NULL) { | ||||||
|  |     return EFI_OUT_OF_RESOURCES; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   do { | ||||||
|  |     //
 | ||||||
|  |     // The outer loop handles multi instance device paths.
 | ||||||
|  |     // Only console variables contain multiple instance device paths.
 | ||||||
|  |     //
 | ||||||
|  |     // After this call DevicePath points to the next Instance
 | ||||||
|  |     //
 | ||||||
|  |     Instance  = GetNextDevicePathInstance (&DevicePath, &Size); | ||||||
|  |     Next      = Instance; | ||||||
|  |     while (!IsDevicePathEndType (Next)) { | ||||||
|  |       Next = NextDevicePathNode (Next); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     SetDevicePathEndNode (Next); | ||||||
|  | 
 | ||||||
|  |     //
 | ||||||
|  |     // Start the real work of connect with RemainingDevicePath
 | ||||||
|  |     //
 | ||||||
|  |     PreviousHandle = NULL; | ||||||
|  |     do { | ||||||
|  |       //
 | ||||||
|  |       // Find the handle that best matches the Device Path. If it is only a
 | ||||||
|  |       // partial match the remaining part of the device path is returned in
 | ||||||
|  |       // RemainingDevicePath.
 | ||||||
|  |       //
 | ||||||
|  |       RemainingDevicePath = Instance; | ||||||
|  |       Status              = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &Handle); | ||||||
|  | 
 | ||||||
|  |       if (!EFI_ERROR (Status)) { | ||||||
|  |         if (Handle == PreviousHandle) { | ||||||
|  |           //
 | ||||||
|  |           // If no forward progress is made try invoking the Dispatcher.
 | ||||||
|  |           // A new FV may have been added to the system an new drivers
 | ||||||
|  |           // may now be found.
 | ||||||
|  |           // Status == EFI_SUCCESS means a driver was dispatched
 | ||||||
|  |           // Status == EFI_NOT_FOUND means no new drivers were dispatched
 | ||||||
|  |           //
 | ||||||
|  |           Status = gDS->Dispatch (); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (!EFI_ERROR (Status)) { | ||||||
|  |           PreviousHandle = Handle; | ||||||
|  |           //
 | ||||||
|  |           // Connect all drivers that apply to Handle and RemainingDevicePath,
 | ||||||
|  |           // the Recursive flag is FALSE so only one level will be expanded.
 | ||||||
|  |           //
 | ||||||
|  |           // Do not check the connect status here, if the connect controller fail,
 | ||||||
|  |           // then still give the chance to do dispatch, because partial
 | ||||||
|  |           // RemainingDevicepath may be in the new FV
 | ||||||
|  |           //
 | ||||||
|  |           // 1. If the connect fail, RemainingDevicepath and handle will not
 | ||||||
|  |           //    change, so next time will do the dispatch, then dispatch's status
 | ||||||
|  |           //    will take effect
 | ||||||
|  |           // 2. If the connect success, the RemainingDevicepath and handle will
 | ||||||
|  |           //    change, then avoid the dispatch, we have chance to continue the
 | ||||||
|  |           //    next connection
 | ||||||
|  |           //
 | ||||||
|  |           gBS->ConnectController (Handle, NULL, RemainingDevicePath, FALSE); | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |       //
 | ||||||
|  |       // Loop until RemainingDevicePath is an empty device path
 | ||||||
|  |       //
 | ||||||
|  |     } while (!EFI_ERROR (Status) && !IsDevicePathEnd (RemainingDevicePath)); | ||||||
|  | 
 | ||||||
|  |   } while (DevicePath != NULL); | ||||||
|  | 
 | ||||||
|  |   if (CopyOfDevicePath != NULL) { | ||||||
|  |     gBS->FreePool (CopyOfDevicePath); | ||||||
|  |   } | ||||||
|  |   //
 | ||||||
|  |   // All handle with DevicePath exists in the handle database
 | ||||||
|  |   //
 | ||||||
|  |   return Status; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibConnectAllEfi ( | ||||||
|  |   VOID | ||||||
|  |   ) | ||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Routine Description: | ||||||
|  | 
 | ||||||
|  |   This function will connect all current system handles recursively. The | ||||||
|  |   connection will finish until every handle's child handle created if it have. | ||||||
|  |    | ||||||
|  | Arguments: | ||||||
|  | 
 | ||||||
|  |   None | ||||||
|  | 
 | ||||||
|  | Returns: | ||||||
|  | 
 | ||||||
|  |   EFI_SUCCESS          - All handles and it's child handle have been connected | ||||||
|  |    | ||||||
|  |   EFI_STATUS           - Return the status of gBS->LocateHandleBuffer().  | ||||||
|  | 
 | ||||||
|  | --*/ | ||||||
|  | { | ||||||
|  |   EFI_STATUS  Status; | ||||||
|  |   UINTN       HandleCount; | ||||||
|  |   EFI_HANDLE  *HandleBuffer; | ||||||
|  |   UINTN       Index; | ||||||
|  | 
 | ||||||
|  |   Status = gBS->LocateHandleBuffer ( | ||||||
|  |                   AllHandles, | ||||||
|  |                   NULL, | ||||||
|  |                   NULL, | ||||||
|  |                   &HandleCount, | ||||||
|  |                   &HandleBuffer | ||||||
|  |                   ); | ||||||
|  |   if (EFI_ERROR (Status)) { | ||||||
|  |     return Status; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   for (Index = 0; Index < HandleCount; Index++) { | ||||||
|  |     Status = gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   gBS->FreePool (HandleBuffer); | ||||||
|  | 
 | ||||||
|  |   return EFI_SUCCESS; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibDisconnectAllEfi ( | ||||||
|  |   VOID | ||||||
|  |   ) | ||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Routine Description: | ||||||
|  | 
 | ||||||
|  |   This function will disconnect all current system handles. The disconnection | ||||||
|  |   will finish until every handle have been disconnected. | ||||||
|  |    | ||||||
|  | Arguments: | ||||||
|  | 
 | ||||||
|  |   None | ||||||
|  | 
 | ||||||
|  | Returns: | ||||||
|  | 
 | ||||||
|  |   EFI_SUCCESS          - All handles have been disconnected | ||||||
|  |    | ||||||
|  |   EFI_STATUS           - Return the status of gBS->LocateHandleBuffer().  | ||||||
|  | 
 | ||||||
|  | --*/ | ||||||
|  | { | ||||||
|  |   EFI_STATUS  Status; | ||||||
|  |   UINTN       HandleCount; | ||||||
|  |   EFI_HANDLE  *HandleBuffer; | ||||||
|  |   UINTN       Index; | ||||||
|  | 
 | ||||||
|  |   //
 | ||||||
|  |   // Disconnect all
 | ||||||
|  |   //
 | ||||||
|  |   Status = gBS->LocateHandleBuffer ( | ||||||
|  |                   AllHandles, | ||||||
|  |                   NULL, | ||||||
|  |                   NULL, | ||||||
|  |                   &HandleCount, | ||||||
|  |                   &HandleBuffer | ||||||
|  |                   ); | ||||||
|  |   if (EFI_ERROR (Status)) { | ||||||
|  |     return Status; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   for (Index = 0; Index < HandleCount; Index++) { | ||||||
|  |     Status = gBS->DisconnectController (HandleBuffer[Index], NULL, NULL); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   gBS->FreePool (HandleBuffer); | ||||||
|  | 
 | ||||||
|  |   return EFI_SUCCESS; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | BdsLibConnectAllDriversToAllControllers ( | ||||||
|  |   VOID | ||||||
|  |   ) | ||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Routine Description: | ||||||
|  | 
 | ||||||
|  |   Connects all drivers to all controllers.  | ||||||
|  |   This function make sure all the current system driver will manage | ||||||
|  |   the correspoinding controllers if have. And at the same time, make | ||||||
|  |   sure all the system controllers have driver to manage it if have.  | ||||||
|  |    | ||||||
|  | Arguments: | ||||||
|  |    | ||||||
|  |   None | ||||||
|  |    | ||||||
|  | Returns: | ||||||
|  |    | ||||||
|  |   None | ||||||
|  |    | ||||||
|  | --*/ | ||||||
|  | { | ||||||
|  |   EFI_STATUS  Status; | ||||||
|  | 
 | ||||||
|  |   do { | ||||||
|  |     //
 | ||||||
|  |     // Connect All EFI 1.10 drivers following EFI 1.10 algorithm
 | ||||||
|  |     //
 | ||||||
|  |     BdsLibConnectAllEfi (); | ||||||
|  | 
 | ||||||
|  |     //
 | ||||||
|  |     // Check to see if it's possible to dispatch an more DXE drivers.
 | ||||||
|  |     // The BdsLibConnectAllEfi () may have made new DXE drivers show up.
 | ||||||
|  |     // If anything is Dispatched Status == EFI_SUCCESS and we will try
 | ||||||
|  |     // the connect again.
 | ||||||
|  |     //
 | ||||||
|  |     Status = gDS->Dispatch (); | ||||||
|  | 
 | ||||||
|  |   } while (!EFI_ERROR (Status)); | ||||||
|  | 
 | ||||||
|  | } | ||||||
							
								
								
									
										387
									
								
								EdkModulePkg/Library/EdkGenericBdsLib/BdsConsole.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										387
									
								
								EdkModulePkg/Library/EdkGenericBdsLib/BdsConsole.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,387 @@ | |||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Copyright (c) 2006, 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.              | ||||||
|  | 
 | ||||||
|  | Module Name: | ||||||
|  | 
 | ||||||
|  |   BdsConsole.c | ||||||
|  | 
 | ||||||
|  | Abstract: | ||||||
|  | 
 | ||||||
|  |   BDS Lib functions which contain all the code to connect console device | ||||||
|  | 
 | ||||||
|  | --*/ | ||||||
|  | 
 | ||||||
|  | BOOLEAN | ||||||
|  | IsNvNeed ( | ||||||
|  |   IN CHAR16 *ConVarName | ||||||
|  |   ) | ||||||
|  | { | ||||||
|  |   CHAR16 *Ptr; | ||||||
|  |    | ||||||
|  |   Ptr = ConVarName; | ||||||
|  |    | ||||||
|  |   //
 | ||||||
|  |   // If the variable includes "Dev" at last, we consider
 | ||||||
|  |   // it does not support NV attribute.
 | ||||||
|  |   //
 | ||||||
|  |   while (*Ptr) { | ||||||
|  |     Ptr++; | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   if ((*(Ptr - 3) == 'D') && (*(Ptr - 2) == 'e') && (*(Ptr - 1) == 'v')) { | ||||||
|  |     return FALSE; | ||||||
|  |   } else { | ||||||
|  |     return TRUE; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibUpdateConsoleVariable ( | ||||||
|  |   IN  CHAR16                    *ConVarName, | ||||||
|  |   IN  EFI_DEVICE_PATH_PROTOCOL  *CustomizedConDevicePath, | ||||||
|  |   IN  EFI_DEVICE_PATH_PROTOCOL  *ExclusiveDevicePath | ||||||
|  |   ) | ||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Routine Description: | ||||||
|  | 
 | ||||||
|  |   This function update console variable based on ConVarName, it can  | ||||||
|  |   add or remove one specific console device path from the variable | ||||||
|  | 
 | ||||||
|  | Arguments: | ||||||
|  | 
 | ||||||
|  |   ConVarName   - Console related variable name, ConIn, ConOut, ErrOut. | ||||||
|  | 
 | ||||||
|  |   CustomizedConDevicePath - The console device path which will be added to | ||||||
|  |                             the console variable ConVarName, this parameter | ||||||
|  |                             can not be multi-instance. | ||||||
|  | 
 | ||||||
|  |   ExclusiveDevicePath     - The console device path which will be removed | ||||||
|  |                             from the console variable ConVarName, this | ||||||
|  |                             parameter can not be multi-instance. | ||||||
|  | 
 | ||||||
|  | Returns: | ||||||
|  | 
 | ||||||
|  |   EFI_UNSUPPORTED         - Add or remove the same device path. | ||||||
|  |    | ||||||
|  |   EFI_SUCCESS             - Success add or remove the device path from  | ||||||
|  |                             the console variable. | ||||||
|  | 
 | ||||||
|  | --*/ | ||||||
|  | { | ||||||
|  |   EFI_STATUS                Status; | ||||||
|  |   EFI_DEVICE_PATH_PROTOCOL  *VarConsole; | ||||||
|  |   UINTN                     DevicePathSize; | ||||||
|  |   EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath; | ||||||
|  |   EFI_DEVICE_PATH_PROTOCOL  *TempNewDevicePath; | ||||||
|  |   UINT32                    Attributes; | ||||||
|  | 
 | ||||||
|  |   VarConsole      = NULL; | ||||||
|  |   DevicePathSize  = 0; | ||||||
|  |   Status          = EFI_UNSUPPORTED; | ||||||
|  | 
 | ||||||
|  |   //
 | ||||||
|  |   // Notes: check the device path point, here should check
 | ||||||
|  |   // with compare memory
 | ||||||
|  |   //
 | ||||||
|  |   if (CustomizedConDevicePath == ExclusiveDevicePath) { | ||||||
|  |     return EFI_UNSUPPORTED; | ||||||
|  |   } | ||||||
|  |   //
 | ||||||
|  |   // Delete the ExclusiveDevicePath from current default console
 | ||||||
|  |   //
 | ||||||
|  |   VarConsole = BdsLibGetVariableAndSize ( | ||||||
|  |                 ConVarName, | ||||||
|  |                 &gEfiGlobalVariableGuid, | ||||||
|  |                 &DevicePathSize | ||||||
|  |                 ); | ||||||
|  |                  | ||||||
|  |   //
 | ||||||
|  |   // Initialize NewDevicePath
 | ||||||
|  |   //
 | ||||||
|  |   NewDevicePath  = VarConsole; | ||||||
|  |    | ||||||
|  |   //
 | ||||||
|  |   // If ExclusiveDevicePath is even the part of the instance in VarConsole, delete it.
 | ||||||
|  |   // In the end, NewDevicePath is the final device path.
 | ||||||
|  |   //
 | ||||||
|  |   if (ExclusiveDevicePath != NULL && VarConsole != NULL) { | ||||||
|  |       NewDevicePath = BdsLibDelPartMatchInstance (VarConsole, ExclusiveDevicePath); | ||||||
|  |   } | ||||||
|  |   //
 | ||||||
|  |   // Try to append customized device path to NewDevicePath.
 | ||||||
|  |   //
 | ||||||
|  |   if (CustomizedConDevicePath != NULL) { | ||||||
|  |     if (!BdsLibMatchDevicePaths (NewDevicePath, CustomizedConDevicePath)) { | ||||||
|  |       //
 | ||||||
|  |       // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it.
 | ||||||
|  |       //
 | ||||||
|  |       NewDevicePath = BdsLibDelPartMatchInstance (NewDevicePath, CustomizedConDevicePath); | ||||||
|  |       //
 | ||||||
|  |       // In the first check, the default console variable will be null,
 | ||||||
|  |       // just append current customized device path
 | ||||||
|  |       //
 | ||||||
|  |       TempNewDevicePath = NewDevicePath; | ||||||
|  |       NewDevicePath = AppendDevicePathInstance (NewDevicePath, CustomizedConDevicePath); | ||||||
|  |       BdsLibSafeFreePool(TempNewDevicePath); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   //
 | ||||||
|  |   // The attribute for ConInDev, ConOutDev and ErrOutDev does not include NV.
 | ||||||
|  |   //
 | ||||||
|  |   if (IsNvNeed(ConVarName)) { | ||||||
|  |     //
 | ||||||
|  |     // ConVarName has NV attribute.
 | ||||||
|  |     //
 | ||||||
|  |     Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE; | ||||||
|  |   } else { | ||||||
|  |     //
 | ||||||
|  |     // ConVarName does not have NV attribute.
 | ||||||
|  |     //
 | ||||||
|  |     Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS; | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   //
 | ||||||
|  |   // Finally, Update the variable of the default console by NewDevicePath
 | ||||||
|  |   //
 | ||||||
|  |   gRT->SetVariable ( | ||||||
|  |         ConVarName, | ||||||
|  |         &gEfiGlobalVariableGuid, | ||||||
|  |         Attributes, | ||||||
|  |         GetDevicePathSize (NewDevicePath), | ||||||
|  |         NewDevicePath | ||||||
|  |         ); | ||||||
|  | 
 | ||||||
|  |   if (VarConsole == NewDevicePath) { | ||||||
|  |     BdsLibSafeFreePool(VarConsole); | ||||||
|  |   } else { | ||||||
|  |     BdsLibSafeFreePool(VarConsole); | ||||||
|  |     BdsLibSafeFreePool(NewDevicePath); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   return EFI_SUCCESS; | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibConnectConsoleVariable ( | ||||||
|  |   IN  CHAR16                 *ConVarName | ||||||
|  |   ) | ||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Routine Description: | ||||||
|  | 
 | ||||||
|  |   Connect the console device base on the variable ConVarName, if | ||||||
|  |   device path of the ConVarName is multi-instance device path, if | ||||||
|  |   anyone of the instances is connected success, then this function | ||||||
|  |   will return success. | ||||||
|  | 
 | ||||||
|  | Arguments: | ||||||
|  | 
 | ||||||
|  |   ConVarName   - Console related variable name, ConIn, ConOut, ErrOut. | ||||||
|  | 
 | ||||||
|  | Returns: | ||||||
|  | 
 | ||||||
|  |   EFI_NOT_FOUND           - There is not any console devices connected success | ||||||
|  |    | ||||||
|  |   EFI_SUCCESS             - Success connect any one instance of the console | ||||||
|  |                             device path base on the variable ConVarName. | ||||||
|  | 
 | ||||||
|  | --*/ | ||||||
|  | { | ||||||
|  |   EFI_STATUS                Status; | ||||||
|  |   EFI_DEVICE_PATH_PROTOCOL  *StartDevicePath; | ||||||
|  |   UINTN                     VariableSize; | ||||||
|  |   EFI_DEVICE_PATH_PROTOCOL  *Instance; | ||||||
|  |   EFI_DEVICE_PATH_PROTOCOL  *Next; | ||||||
|  |   EFI_DEVICE_PATH_PROTOCOL  *CopyOfDevicePath; | ||||||
|  |   UINTN                     Size; | ||||||
|  |   BOOLEAN                   DeviceExist; | ||||||
|  | 
 | ||||||
|  |   Status      = EFI_SUCCESS; | ||||||
|  |   DeviceExist = FALSE; | ||||||
|  | 
 | ||||||
|  |   //
 | ||||||
|  |   // Check if the console variable exist
 | ||||||
|  |   //
 | ||||||
|  |   StartDevicePath = BdsLibGetVariableAndSize ( | ||||||
|  |                       ConVarName, | ||||||
|  |                       &gEfiGlobalVariableGuid, | ||||||
|  |                       &VariableSize | ||||||
|  |                       ); | ||||||
|  |   if (StartDevicePath == NULL) { | ||||||
|  |     return EFI_UNSUPPORTED; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   CopyOfDevicePath = StartDevicePath; | ||||||
|  |   do { | ||||||
|  |     //
 | ||||||
|  |     // Check every instance of the console variable
 | ||||||
|  |     //
 | ||||||
|  |     Instance  = GetNextDevicePathInstance (&CopyOfDevicePath, &Size); | ||||||
|  |     Next      = Instance; | ||||||
|  |     while (!IsDevicePathEndType (Next)) { | ||||||
|  |       Next = NextDevicePathNode (Next); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     SetDevicePathEndNode (Next); | ||||||
|  | 
 | ||||||
|  |     //
 | ||||||
|  |     // Connect the instance device path
 | ||||||
|  |     //
 | ||||||
|  |     Status = BdsLibConnectDevicePath (Instance); | ||||||
|  |     if (EFI_ERROR (Status)) { | ||||||
|  |       //
 | ||||||
|  |       // Delete the instance from the console varialbe
 | ||||||
|  |       //
 | ||||||
|  |       BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance); | ||||||
|  |     } else { | ||||||
|  |       DeviceExist = TRUE; | ||||||
|  |     } | ||||||
|  |     BdsLibSafeFreePool(Instance); | ||||||
|  |   } while (CopyOfDevicePath != NULL); | ||||||
|  | 
 | ||||||
|  |   gBS->FreePool (StartDevicePath); | ||||||
|  | 
 | ||||||
|  |   if (DeviceExist == FALSE) { | ||||||
|  |     return EFI_NOT_FOUND; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   return EFI_SUCCESS; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | BdsLibConnectAllConsoles ( | ||||||
|  |   VOID | ||||||
|  |   ) | ||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Routine Description: | ||||||
|  | 
 | ||||||
|  |   This function will search every simpletxt devive in current system, | ||||||
|  |   and make every simpletxt device as pertantial console device. | ||||||
|  | 
 | ||||||
|  | Arguments: | ||||||
|  | 
 | ||||||
|  |   None | ||||||
|  | 
 | ||||||
|  | Returns: | ||||||
|  | 
 | ||||||
|  |   None | ||||||
|  | 
 | ||||||
|  | --*/ | ||||||
|  | { | ||||||
|  |   EFI_STATUS                Status; | ||||||
|  |   UINTN                     Index; | ||||||
|  |   EFI_DEVICE_PATH_PROTOCOL  *ConDevicePath; | ||||||
|  |   UINTN                     HandleCount; | ||||||
|  |   EFI_HANDLE                *HandleBuffer; | ||||||
|  | 
 | ||||||
|  |   Index         = 0; | ||||||
|  |   HandleCount   = 0; | ||||||
|  |   HandleBuffer  = NULL; | ||||||
|  |   ConDevicePath = NULL; | ||||||
|  | 
 | ||||||
|  |   //
 | ||||||
|  |   // Update all the console variables
 | ||||||
|  |   //
 | ||||||
|  |   Status = gBS->LocateHandleBuffer ( | ||||||
|  |                   ByProtocol, | ||||||
|  |                   &gEfiSimpleTextInProtocolGuid, | ||||||
|  |                   NULL, | ||||||
|  |                   &HandleCount, | ||||||
|  |                   &HandleBuffer | ||||||
|  |                   ); | ||||||
|  |   for (Index = 0; Index < HandleCount; Index++) { | ||||||
|  |     Status = gBS->HandleProtocol ( | ||||||
|  |                     HandleBuffer[Index], | ||||||
|  |                     &gEfiDevicePathProtocolGuid, | ||||||
|  |                     (VOID **) &ConDevicePath | ||||||
|  |                     ); | ||||||
|  |     BdsLibUpdateConsoleVariable (L"ConIn", ConDevicePath, NULL); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   BdsLibSafeFreePool(HandleBuffer); | ||||||
|  | 
 | ||||||
|  |   Status = gBS->LocateHandleBuffer ( | ||||||
|  |                   ByProtocol, | ||||||
|  |                   &gEfiSimpleTextOutProtocolGuid, | ||||||
|  |                   NULL, | ||||||
|  |                   &HandleCount, | ||||||
|  |                   &HandleBuffer | ||||||
|  |                   ); | ||||||
|  |   for (Index = 0; Index < HandleCount; Index++) { | ||||||
|  |     Status = gBS->HandleProtocol ( | ||||||
|  |                     HandleBuffer[Index], | ||||||
|  |                     &gEfiDevicePathProtocolGuid, | ||||||
|  |                     (VOID **) &ConDevicePath | ||||||
|  |                     ); | ||||||
|  |     BdsLibUpdateConsoleVariable (L"ConOut", ConDevicePath, NULL); | ||||||
|  |     BdsLibUpdateConsoleVariable (L"ErrOut", ConDevicePath, NULL); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   BdsLibSafeFreePool(HandleBuffer); | ||||||
|  | 
 | ||||||
|  |   //
 | ||||||
|  |   // Connect all console variables
 | ||||||
|  |   //
 | ||||||
|  |   BdsLibConnectAllDefaultConsoles (); | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | EFI_STATUS | ||||||
|  | BdsLibConnectAllDefaultConsoles ( | ||||||
|  |   VOID | ||||||
|  |   ) | ||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Routine Description: | ||||||
|  | 
 | ||||||
|  |   This function will connect console device base on the console  | ||||||
|  |   device variable ConIn, ConOut and ErrOut. | ||||||
|  | 
 | ||||||
|  | Arguments: | ||||||
|  | 
 | ||||||
|  |   None | ||||||
|  | 
 | ||||||
|  | Returns: | ||||||
|  | 
 | ||||||
|  |   EFI_SUCCESS      - At least one of the ConIn and ConOut device have | ||||||
|  |                      been connected success. | ||||||
|  |                       | ||||||
|  |   EFI_STATUS       - Return the status of BdsLibConnectConsoleVariable (). | ||||||
|  | 
 | ||||||
|  | --*/ | ||||||
|  | { | ||||||
|  |   EFI_STATUS                Status; | ||||||
|  | 
 | ||||||
|  |   //
 | ||||||
|  |   // Connect all default console variables
 | ||||||
|  |   //
 | ||||||
|  |   Status = BdsLibConnectConsoleVariable (L"ConIn"); | ||||||
|  |   if (EFI_ERROR (Status)) { | ||||||
|  |     return Status; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   Status = BdsLibConnectConsoleVariable (L"ConOut"); | ||||||
|  |   if (EFI_ERROR (Status)) { | ||||||
|  |     return Status; | ||||||
|  |   } | ||||||
|  |   //
 | ||||||
|  |   // Special treat the err out device, becaues the null
 | ||||||
|  |   // err out var is legal.
 | ||||||
|  |   //
 | ||||||
|  |   BdsLibConnectConsoleVariable (L"ErrOut"); | ||||||
|  | 
 | ||||||
|  |   return EFI_SUCCESS; | ||||||
|  | 
 | ||||||
|  | } | ||||||
							
								
								
									
										1120
									
								
								EdkModulePkg/Library/EdkGenericBdsLib/BdsMisc.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1120
									
								
								EdkModulePkg/Library/EdkGenericBdsLib/BdsMisc.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										1040
									
								
								EdkModulePkg/Library/EdkGenericBdsLib/DevicePath.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1040
									
								
								EdkModulePkg/Library/EdkGenericBdsLib/DevicePath.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										113
									
								
								EdkModulePkg/Library/EdkGenericBdsLib/EdkGenericBdsLib.msa
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								EdkModulePkg/Library/EdkGenericBdsLib/EdkGenericBdsLib.msa
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,113 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0"> | ||||||
|  |   <MsaHeader> | ||||||
|  |     <ModuleName>EdkGenericBdsLib</ModuleName> | ||||||
|  |     <ModuleType>DXE_DRIVER</ModuleType> | ||||||
|  |     <GuidValue>f3aaea62-8985-11db-baff-0040d02b1835</GuidValue> | ||||||
|  |     <Version>1.0</Version> | ||||||
|  |     <Abstract>EDK Generic BDS Common APIs Library Instance.</Abstract> | ||||||
|  |     <Description>The library instance provides common library routines help in  | ||||||
|  |     performance measurement, device path debug print, boot device selections, | ||||||
|  |     boot device connection, console supports in BDS phase and boot from boot | ||||||
|  |     device. | ||||||
|  |     </Description> | ||||||
|  |     <Copyright>Copyright (c) 2006, Intel Corporation.</Copyright> | ||||||
|  |     <License>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.</License> | ||||||
|  |     <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification> | ||||||
|  |   </MsaHeader> | ||||||
|  |   <ModuleDefinitions> | ||||||
|  |     <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures> | ||||||
|  |     <BinaryModule>false</BinaryModule> | ||||||
|  |     <OutputFileBasename>EdkGenericBdsLib</OutputFileBasename> | ||||||
|  |   </ModuleDefinitions> | ||||||
|  |   <LibraryClassDefinitions> | ||||||
|  |     <LibraryClass Usage="ALWAYS_PRODUCED"> | ||||||
|  |       <Keyword>EdkGenericBdsLib</Keyword> | ||||||
|  |     </LibraryClass> | ||||||
|  |     <LibraryClass Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <Keyword>BaseLib</Keyword> | ||||||
|  |     </LibraryClass> | ||||||
|  |     <LibraryClass Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <Keyword>UefiLib</Keyword> | ||||||
|  |     </LibraryClass> | ||||||
|  |     <LibraryClass Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <Keyword>DxeServicesTableLib</Keyword> | ||||||
|  |     </LibraryClass> | ||||||
|  |     <LibraryClass Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <Keyword>DebugLib</Keyword> | ||||||
|  |     </LibraryClass> | ||||||
|  |     <LibraryClass Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <Keyword>PrintLib</Keyword> | ||||||
|  |     </LibraryClass> | ||||||
|  |     <LibraryClass Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <Keyword>HobLib</Keyword> | ||||||
|  |     </LibraryClass> | ||||||
|  |     <LibraryClass Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <Keyword>BaseMemoryLib</Keyword> | ||||||
|  |     </LibraryClass> | ||||||
|  |     <LibraryClass Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <Keyword>MemoryAllocationLib</Keyword> | ||||||
|  |     </LibraryClass> | ||||||
|  |     <LibraryClass Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <Keyword>UefiBootServicesTableLib</Keyword> | ||||||
|  |     </LibraryClass> | ||||||
|  |     <LibraryClass Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <Keyword>UefiRuntimeServicesTableLib</Keyword> | ||||||
|  |     </LibraryClass> | ||||||
|  |     <LibraryClass Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <Keyword>DevicePathLib</Keyword> | ||||||
|  |     </LibraryClass> | ||||||
|  |     <LibraryClass Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <Keyword>PerformanceLib</Keyword> | ||||||
|  |     </LibraryClass> | ||||||
|  |   </LibraryClassDefinitions> | ||||||
|  |   <SourceFiles> | ||||||
|  |     <Filename>BdsBoot.c</Filename> | ||||||
|  |     <Filename>BdsConsole.c</Filename> | ||||||
|  |     <Filename>BdsConnect.c</Filename> | ||||||
|  |     <Filename>DevicePath.c</Filename> | ||||||
|  |     <Filename>Performance.h</Filename> | ||||||
|  |     <Filename>Performance.c</Filename> | ||||||
|  |     <Filename>BdsMisc.c</Filename> | ||||||
|  |     <Filename SupArchList="IPF">Ipf/ShadowRom.c</Filename> | ||||||
|  |   </SourceFiles> | ||||||
|  |   <PackageDependencies> | ||||||
|  |     <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/> | ||||||
|  |     <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/> | ||||||
|  |     <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/> | ||||||
|  |   </PackageDependencies> | ||||||
|  |   <Protocols> | ||||||
|  |     <Protocol Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <ProtocolCName>gEfiLoadedImageProtocolGuid</ProtocolCName> | ||||||
|  |     </Protocol> | ||||||
|  |     <Protocol Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <ProtocolCName>gEfiFirmwareVolumeProtocolGuid</ProtocolCName> | ||||||
|  |     </Protocol> | ||||||
|  |     <Protocol Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <ProtocolCName>gEfiAcpiS3SaveProtocolGuid</ProtocolCName> | ||||||
|  |     </Protocol> | ||||||
|  |     <Protocol Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <ProtocolCName>gEfiSimpleTextOutProtocolGuid</ProtocolCName> | ||||||
|  |     </Protocol> | ||||||
|  |     <Protocol Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <ProtocolCName>gEfiSimpleTextInProtocolGuid</ProtocolCName> | ||||||
|  |     </Protocol> | ||||||
|  |     <Protocol Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <ProtocolCName>gEfiSimpleNetworkProtocolGuid</ProtocolCName> | ||||||
|  |     </Protocol> | ||||||
|  |   </Protocols> | ||||||
|  |   <Guids> | ||||||
|  |     <GuidCNames Usage="ALWAYS_CONSUMED"> | ||||||
|  |       <GuidCName>gEfiShellFileGuid</GuidCName> | ||||||
|  |     </GuidCNames> | ||||||
|  |   </Guids> | ||||||
|  |   <Externs> | ||||||
|  |     <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification> | ||||||
|  |     <Specification>EDK_RELEASE_VERSION 0x00020000</Specification> | ||||||
|  |   </Externs> | ||||||
|  | </ModuleSurfaceArea> | ||||||
							
								
								
									
										48
									
								
								EdkModulePkg/Library/EdkGenericBdsLib/Ipf/ShadowRom.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								EdkModulePkg/Library/EdkGenericBdsLib/Ipf/ShadowRom.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,48 @@ | |||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Copyright (c) 2006, 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.              | ||||||
|  | 
 | ||||||
|  | Module Name: | ||||||
|  |    | ||||||
|  |   ShadowRom.c | ||||||
|  | 
 | ||||||
|  | Abstract: | ||||||
|  | 
 | ||||||
|  |   Shadow all option rom | ||||||
|  | 
 | ||||||
|  | Revision History | ||||||
|  | 
 | ||||||
|  | --*/ | ||||||
|  | 
 | ||||||
|  | UINT8 mShadowRomFlag = 0; | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | ShadowAllOptionRom() | ||||||
|  | { | ||||||
|  |   EFI_STATUS                Status; | ||||||
|  |   EFI_LEGACY_BIOS_PROTOCOL  *LegacyBios; | ||||||
|  |   //
 | ||||||
|  |   // Rom shadow only do once.
 | ||||||
|  |   //
 | ||||||
|  |   if (mShadowRomFlag == 0) { | ||||||
|  |     Status = gBS->LocateProtocol ( | ||||||
|  |                     &gEfiLegacyBiosProtocolGuid, | ||||||
|  |                     NULL, | ||||||
|  |                     &LegacyBios | ||||||
|  |                     ); | ||||||
|  |     if (!EFI_ERROR (Status)) { | ||||||
|  |       LegacyBios->PrepareToBootEfi (LegacyBios, NULL, NULL); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     mShadowRomFlag = 1; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   return ; | ||||||
|  | } | ||||||
							
								
								
									
										399
									
								
								EdkModulePkg/Library/EdkGenericBdsLib/Performance.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										399
									
								
								EdkModulePkg/Library/EdkGenericBdsLib/Performance.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,399 @@ | |||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Copyright (c) 2006, 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.              | ||||||
|  | 
 | ||||||
|  | Module Name: | ||||||
|  | 
 | ||||||
|  |   Performance.c | ||||||
|  | 
 | ||||||
|  | Abstract: | ||||||
|  | 
 | ||||||
|  |   This file include the file which can help to get the system | ||||||
|  |   performance, all the function will only include if the performance | ||||||
|  |   switch is set. | ||||||
|  | 
 | ||||||
|  | --*/ | ||||||
|  | 
 | ||||||
|  | #include "Performance.h" | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | ClearDebugRegisters ( | ||||||
|  |   VOID | ||||||
|  |   ) | ||||||
|  | { | ||||||
|  |   //
 | ||||||
|  |   // BugBug: We should not need to do this. We need to root cause this bug!!!!
 | ||||||
|  |   //
 | ||||||
|  |   AsmWriteDr0 (0); | ||||||
|  |   AsmWriteDr1 (0); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | STATIC | ||||||
|  | VOID | ||||||
|  | GetShortPdbFileName ( | ||||||
|  |   CHAR8  *PdbFileName, | ||||||
|  |   CHAR8  *GaugeString | ||||||
|  |   ) | ||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Routine Description: | ||||||
|  |    | ||||||
|  | Arguments: | ||||||
|  | 
 | ||||||
|  | Returns: | ||||||
|  | 
 | ||||||
|  | --*/ | ||||||
|  | { | ||||||
|  |   UINTN Index; | ||||||
|  |   UINTN Index1; | ||||||
|  |   UINTN StartIndex; | ||||||
|  |   UINTN EndIndex; | ||||||
|  | 
 | ||||||
|  |   if (PdbFileName == NULL) { | ||||||
|  |     AsciiStrCpy (GaugeString, " "); | ||||||
|  |   } else { | ||||||
|  |     StartIndex = 0; | ||||||
|  |     for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++) | ||||||
|  |       ; | ||||||
|  | 
 | ||||||
|  |     for (Index = 0; PdbFileName[Index] != 0; Index++) { | ||||||
|  |       if (PdbFileName[Index] == '\\') { | ||||||
|  |         StartIndex = Index + 1; | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|  |       if (PdbFileName[Index] == '.') { | ||||||
|  |         EndIndex = Index; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     Index1 = 0; | ||||||
|  |     for (Index = StartIndex; Index < EndIndex; Index++) { | ||||||
|  |       GaugeString[Index1] = PdbFileName[Index]; | ||||||
|  |       Index1++; | ||||||
|  |       if (Index1 == PERF_TOKEN_LENGTH - 1) { | ||||||
|  |         break; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     GaugeString[Index1] = 0; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   return ; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | STATIC | ||||||
|  | CHAR8 * | ||||||
|  | GetPdbPath ( | ||||||
|  |   VOID *ImageBase | ||||||
|  |   ) | ||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Routine Description: | ||||||
|  | 
 | ||||||
|  |   Located PDB path name in PE image | ||||||
|  | 
 | ||||||
|  | Arguments: | ||||||
|  | 
 | ||||||
|  |   ImageBase - base of PE to search | ||||||
|  | 
 | ||||||
|  | Returns: | ||||||
|  | 
 | ||||||
|  |   Pointer into image at offset of PDB file name if PDB file name is found, | ||||||
|  |   Otherwise a pointer to an empty string. | ||||||
|  | 
 | ||||||
|  | --*/ | ||||||
|  | { | ||||||
|  |   PE_COFF_LOADER_IMAGE_CONTEXT          ImageContext; | ||||||
|  | 
 | ||||||
|  |   ZeroMem (&ImageContext, sizeof (ImageContext)); | ||||||
|  |   ImageContext.Handle    = ImageBase; | ||||||
|  |   ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory; | ||||||
|  | 
 | ||||||
|  |   PeCoffLoaderGetImageInfo (&ImageContext); | ||||||
|  | 
 | ||||||
|  |   return ImageContext.PdbPointer; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | STATIC | ||||||
|  | VOID | ||||||
|  | GetNameFromHandle ( | ||||||
|  |   IN  EFI_HANDLE     Handle, | ||||||
|  |   OUT CHAR8          *GaugeString | ||||||
|  |   ) | ||||||
|  | { | ||||||
|  |   EFI_STATUS                  Status; | ||||||
|  |   EFI_LOADED_IMAGE_PROTOCOL   *Image; | ||||||
|  |   CHAR8                       *PdbFileName; | ||||||
|  |   EFI_DRIVER_BINDING_PROTOCOL *DriverBinding; | ||||||
|  | 
 | ||||||
|  |   AsciiStrCpy (GaugeString, " "); | ||||||
|  | 
 | ||||||
|  |   //
 | ||||||
|  |   // Get handle name from image protocol
 | ||||||
|  |   //
 | ||||||
|  |   Status = gBS->HandleProtocol ( | ||||||
|  |                   Handle, | ||||||
|  |                   &gEfiLoadedImageProtocolGuid, | ||||||
|  |                   (VOID **)&Image | ||||||
|  |                   ); | ||||||
|  | 
 | ||||||
|  |   if (EFI_ERROR (Status)) { | ||||||
|  |     Status = gBS->OpenProtocol ( | ||||||
|  |                     Handle, | ||||||
|  |                     &gEfiDriverBindingProtocolGuid, | ||||||
|  |                     (VOID **) &DriverBinding, | ||||||
|  |                     NULL, | ||||||
|  |                     NULL, | ||||||
|  |                     EFI_OPEN_PROTOCOL_GET_PROTOCOL | ||||||
|  |                     ); | ||||||
|  |     if (EFI_ERROR (Status)) { | ||||||
|  |       return ; | ||||||
|  |     } | ||||||
|  |     //
 | ||||||
|  |     // Get handle name from image protocol
 | ||||||
|  |     //
 | ||||||
|  |     Status = gBS->HandleProtocol ( | ||||||
|  |                     DriverBinding->ImageHandle, | ||||||
|  |                     &gEfiLoadedImageProtocolGuid, | ||||||
|  |                     (VOID **)&Image | ||||||
|  |                     ); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   PdbFileName = GetPdbPath (Image->ImageBase); | ||||||
|  | 
 | ||||||
|  |   if (PdbFileName != NULL) { | ||||||
|  |     GetShortPdbFileName (PdbFileName, GaugeString); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   return ; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | WriteBootToOsPerformanceData ( | ||||||
|  |   VOID | ||||||
|  |   ) | ||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Routine Description: | ||||||
|  |    | ||||||
|  |   Allocates a block of memory and writes performance data of booting to OS into it. | ||||||
|  | 
 | ||||||
|  | Arguments: | ||||||
|  |    | ||||||
|  |   None | ||||||
|  |    | ||||||
|  | Returns: | ||||||
|  | 
 | ||||||
|  |   None | ||||||
|  | 
 | ||||||
|  | --*/ | ||||||
|  | { | ||||||
|  |   EFI_STATUS                Status; | ||||||
|  |   EFI_CPU_ARCH_PROTOCOL     *Cpu; | ||||||
|  |   EFI_PHYSICAL_ADDRESS      mAcpiLowMemoryBase; | ||||||
|  |   UINT32                    mAcpiLowMemoryLength; | ||||||
|  |   UINT32                    LimitCount; | ||||||
|  |   PERF_HEADER               mPerfHeader; | ||||||
|  |   PERF_DATA                 mPerfData; | ||||||
|  |   EFI_HANDLE                *Handles; | ||||||
|  |   UINTN                     NoHandles; | ||||||
|  |   CHAR8                     GaugeString[PERF_TOKEN_LENGTH]; | ||||||
|  |   UINT8                     *Ptr; | ||||||
|  |   UINT32                    mIndex; | ||||||
|  |   UINT64                    Ticker; | ||||||
|  |   UINT64                    Freq; | ||||||
|  |   UINT32                    Duration; | ||||||
|  |   UINT64                    CurrentTicker; | ||||||
|  |   UINT64                    TimerPeriod; | ||||||
|  |   UINTN                     LogEntryKey; | ||||||
|  |   CONST VOID                *Handle; | ||||||
|  |   CONST CHAR8               *Token; | ||||||
|  |   CONST CHAR8               *Module; | ||||||
|  |   UINT64                    StartTicker; | ||||||
|  |   UINT64                    EndTicker; | ||||||
|  | 
 | ||||||
|  |   //
 | ||||||
|  |   // Retrive time stamp count as early as possilbe
 | ||||||
|  |   //
 | ||||||
|  |   Ticker = AsmReadTsc (); | ||||||
|  | 
 | ||||||
|  |   //
 | ||||||
|  |   // Allocate a block of memory that contain performance data to OS
 | ||||||
|  |   //
 | ||||||
|  |   mAcpiLowMemoryBase = 0xFFFFFFFF; | ||||||
|  |   Status = gBS->AllocatePages ( | ||||||
|  |                   AllocateMaxAddress, | ||||||
|  |                   EfiReservedMemoryType, | ||||||
|  |                   4, | ||||||
|  |                   &mAcpiLowMemoryBase | ||||||
|  |                   ); | ||||||
|  |   if (EFI_ERROR (Status)) { | ||||||
|  |     return ; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   mAcpiLowMemoryLength  = EFI_PAGES_TO_SIZE(4); | ||||||
|  | 
 | ||||||
|  |   Ptr                   = (UINT8 *) ((UINT32) mAcpiLowMemoryBase + sizeof (PERF_HEADER)); | ||||||
|  |   LimitCount            = (mAcpiLowMemoryLength - sizeof (PERF_HEADER)) / sizeof (PERF_DATA); | ||||||
|  | 
 | ||||||
|  |   //
 | ||||||
|  |   // Initialize performance data structure
 | ||||||
|  |   //
 | ||||||
|  |   ZeroMem (&mPerfHeader, sizeof (PERF_HEADER)); | ||||||
|  | 
 | ||||||
|  |   //
 | ||||||
|  |   // Get CPU frequency
 | ||||||
|  |   //
 | ||||||
|  |   Status = gBS->LocateProtocol ( | ||||||
|  |                   &gEfiCpuArchProtocolGuid, | ||||||
|  |                   NULL, | ||||||
|  |                   (VOID **)&Cpu | ||||||
|  |                   ); | ||||||
|  |   if (EFI_ERROR (Status)) { | ||||||
|  |     gBS->FreePages (mAcpiLowMemoryBase, 4); | ||||||
|  |     return ; | ||||||
|  |   } | ||||||
|  |   //
 | ||||||
|  |   // Get Cpu Frequency
 | ||||||
|  |   //
 | ||||||
|  |   Status = Cpu->GetTimerValue (Cpu, 0, &(CurrentTicker), &TimerPeriod); | ||||||
|  |   if (EFI_ERROR (Status)) { | ||||||
|  |     gBS->FreePages (mAcpiLowMemoryBase, 4); | ||||||
|  |     return ; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   Freq                = DivU64x32 (1000000000000ULL, (UINTN) TimerPeriod); | ||||||
|  | 
 | ||||||
|  |   mPerfHeader.CpuFreq = Freq; | ||||||
|  | 
 | ||||||
|  |   //
 | ||||||
|  |   // Record BDS raw performance data
 | ||||||
|  |   //
 | ||||||
|  |   mPerfHeader.BDSRaw = Ticker; | ||||||
|  | 
 | ||||||
|  |   //
 | ||||||
|  |   // Put Detailed performance data into memory
 | ||||||
|  |   //
 | ||||||
|  |   Handles = NULL; | ||||||
|  |   Status = gBS->LocateHandleBuffer ( | ||||||
|  |                   AllHandles, | ||||||
|  |                   NULL, | ||||||
|  |                   NULL, | ||||||
|  |                   &NoHandles, | ||||||
|  |                   &Handles | ||||||
|  |                   ); | ||||||
|  |   if (EFI_ERROR (Status)) { | ||||||
|  |     gBS->FreePages (mAcpiLowMemoryBase, 4); | ||||||
|  |     return ; | ||||||
|  |   } | ||||||
|  |   //
 | ||||||
|  |   // Get DXE drivers performance
 | ||||||
|  |   //
 | ||||||
|  |   for (mIndex = 0; mIndex < NoHandles; mIndex++) { | ||||||
|  |     Ticker = 0; | ||||||
|  |     LogEntryKey = 0; | ||||||
|  |     while ((LogEntryKey = GetPerformanceMeasurement ( | ||||||
|  |                             LogEntryKey, | ||||||
|  |                             &Handle, | ||||||
|  |                             &Token, | ||||||
|  |                             &Module, | ||||||
|  |                             &StartTicker, | ||||||
|  |                             &EndTicker)) != 0) { | ||||||
|  |       if ((Handle == Handles[mIndex]) && (StartTicker < EndTicker)) { | ||||||
|  |         Ticker += (EndTicker - StartTicker); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     Duration = (UINT32) DivU64x32 ( | ||||||
|  |                           Ticker, | ||||||
|  |                           (UINT32) Freq | ||||||
|  |                           ); | ||||||
|  | 
 | ||||||
|  |     if (Duration > 0) { | ||||||
|  |       ZeroMem (&mPerfData, sizeof (PERF_DATA)); | ||||||
|  | 
 | ||||||
|  |       GetNameFromHandle (Handles[mIndex], GaugeString); | ||||||
|  | 
 | ||||||
|  |       AsciiStrCpy (mPerfData.Token, GaugeString); | ||||||
|  |       mPerfData.Duration = Duration; | ||||||
|  | 
 | ||||||
|  |       CopyMem (Ptr, &mPerfData, sizeof (PERF_DATA)); | ||||||
|  |       Ptr += sizeof (PERF_DATA); | ||||||
|  | 
 | ||||||
|  |       mPerfHeader.Count++; | ||||||
|  |       if (mPerfHeader.Count == LimitCount) { | ||||||
|  |         goto Done; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   gBS->FreePool (Handles); | ||||||
|  | 
 | ||||||
|  |   //
 | ||||||
|  |   // Get inserted performance data
 | ||||||
|  |   //
 | ||||||
|  |   LogEntryKey = 0; | ||||||
|  |   while ((LogEntryKey = GetPerformanceMeasurement ( | ||||||
|  |                           LogEntryKey, | ||||||
|  |                           &Handle, | ||||||
|  |                           &Token, | ||||||
|  |                           &Module, | ||||||
|  |                           &StartTicker, | ||||||
|  |                           &EndTicker)) != 0) { | ||||||
|  |     if ((Handle == NULL) && (StartTicker <= EndTicker)) { | ||||||
|  | 
 | ||||||
|  |       ZeroMem (&mPerfData, sizeof (PERF_DATA)); | ||||||
|  | 
 | ||||||
|  |       AsciiStrnCpy (mPerfData.Token, Token, DXE_PERFORMANCE_STRING_SIZE); | ||||||
|  |       mPerfData.Duration = (UINT32) DivU64x32 ( | ||||||
|  |                                       EndTicker - StartTicker, | ||||||
|  |                                       (UINT32) Freq | ||||||
|  |                                       ); | ||||||
|  | 
 | ||||||
|  |       CopyMem (Ptr, &mPerfData, sizeof (PERF_DATA)); | ||||||
|  |       Ptr += sizeof (PERF_DATA); | ||||||
|  | 
 | ||||||
|  |       mPerfHeader.Count++; | ||||||
|  |       if (mPerfHeader.Count == LimitCount) { | ||||||
|  |         goto Done; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  | Done: | ||||||
|  | 
 | ||||||
|  |   ClearDebugRegisters (); | ||||||
|  | 
 | ||||||
|  |   mPerfHeader.Signiture = 0x66726550; | ||||||
|  | 
 | ||||||
|  |   //
 | ||||||
|  |   // Put performance data to memory
 | ||||||
|  |   //
 | ||||||
|  |   CopyMem ( | ||||||
|  |     (UINT32 *) (UINT32) mAcpiLowMemoryBase, | ||||||
|  |     &mPerfHeader, | ||||||
|  |     sizeof (PERF_HEADER) | ||||||
|  |     ); | ||||||
|  | 
 | ||||||
|  |   gRT->SetVariable ( | ||||||
|  |         L"PerfDataMemAddr", | ||||||
|  |         &gEfiGlobalVariableGuid, | ||||||
|  |         EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, | ||||||
|  |         sizeof (UINT32), | ||||||
|  |         (VOID *) &mAcpiLowMemoryBase | ||||||
|  |         ); | ||||||
|  | 
 | ||||||
|  |   return ; | ||||||
|  | } | ||||||
							
								
								
									
										55
									
								
								EdkModulePkg/Library/EdkGenericBdsLib/Performance.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								EdkModulePkg/Library/EdkGenericBdsLib/Performance.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,55 @@ | |||||||
|  | /*++
 | ||||||
|  | 
 | ||||||
|  | Copyright (c) 2006, 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.              | ||||||
|  | 
 | ||||||
|  | Module Name: | ||||||
|  | 
 | ||||||
|  |   Performance.h | ||||||
|  | 
 | ||||||
|  | Abstract: | ||||||
|  | 
 | ||||||
|  |   This file included the performance relete function header and  | ||||||
|  |   definition. | ||||||
|  | 
 | ||||||
|  | --*/ | ||||||
|  | 
 | ||||||
|  | #ifndef _PERF_H_ | ||||||
|  | #define _PERF_H_ | ||||||
|  | 
 | ||||||
|  | #define PERF_TOKEN_LENGTH       28 | ||||||
|  | #define PERF_PEI_ENTRY_MAX_NUM  50 | ||||||
|  | 
 | ||||||
|  | typedef struct { | ||||||
|  |   CHAR8   Token[PERF_TOKEN_LENGTH]; | ||||||
|  |   UINT32  Duration; | ||||||
|  | } PERF_DATA; | ||||||
|  | 
 | ||||||
|  | typedef struct { | ||||||
|  |   UINT64        BootToOs; | ||||||
|  |   UINT64        S3Resume; | ||||||
|  |   UINT32        S3EntryNum; | ||||||
|  |   PERF_DATA     S3Entry[PERF_PEI_ENTRY_MAX_NUM]; | ||||||
|  |   UINT64        CpuFreq; | ||||||
|  |   UINT64        BDSRaw; | ||||||
|  |   UINT32        Count; | ||||||
|  |   UINT32        Signiture; | ||||||
|  | } PERF_HEADER; | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | WriteBootToOsPerformanceData ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | VOID | ||||||
|  | ClearDebugRegisters ( | ||||||
|  |   VOID | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  | #endif | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user