+/*+++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+ WinNtBusDriver.c\r
+\r
+Abstract:\r
+\r
+This following section documents the envirnoment variables for the Win NT\r
+build. These variables are used to define the (virtual) hardware\r
+configuration of the NT environment\r
+\r
+A ! can be used to seperate multiple instances in a variable. Each\r
+instance represents a seperate hardware device.\r
+\r
+EFI_WIN_NT_PHYSICAL_DISKS - maps to drives on your system\r
+EFI_WIN_NT_VIRTUAL_DISKS - maps to a device emulated by a file\r
+EFI_WIN_NT_FILE_SYSTEM - mouts a directory as a file system\r
+EFI_WIN_NT_CONSOLE - make a logical comand line window (only one!)\r
+EFI_WIN_NT_UGA - Builds UGA Windows of Width and Height\r
+EFI_WIN_NT_SERIAL_PORT - maps physical serial ports\r
+\r
+ <F>ixed - Fixed disk like a hard drive.\r
+ <R>emovable - Removable media like a floppy or CD-ROM.\r
+ Read <O>nly - Write protected device.\r
+ Read <W>rite - Read write device.\r
+ <block count> - Decimal number of blocks a device supports.\r
+ <block size> - Decimal number of bytes per block.\r
+\r
+ NT envirnonment variable contents. '<' and '>' are not part of the variable,\r
+ they are just used to make this help more readable. There should be no\r
+ spaces between the ';'. Extra spaces will break the variable. A '!' is\r
+ used to seperate multiple devices in a variable.\r
+\r
+ EFI_WIN_NT_VIRTUAL_DISKS =\r
+ <F | R><O | W>;<block count>;<block size>[!...]\r
+\r
+ EFI_WIN_NT_PHYSICAL_DISKS =\r
+ <drive letter>:<F | R><O | W>;<block count>;<block size>[!...]\r
+\r
+ Virtual Disks: These devices use a file to emulate a hard disk or removable\r
+ media device.\r
+\r
+ Thus a 20 MB emulated hard drive would look like:\r
+ EFI_WIN_NT_VIRTUAL_DISKS=FW;40960;512\r
+\r
+ A 1.44MB emulated floppy with a block size of 1024 would look like:\r
+ EFI_WIN_NT_VIRTUAL_DISKS=RW;1440;1024\r
+\r
+ Physical Disks: These devices use NT to open a real device in your system\r
+\r
+ Thus a 120 MB floppy would look like:\r
+ EFI_WIN_NT_PHYSICAL_DISKS=B:RW;245760;512\r
+\r
+ Thus a standard CD-ROM floppy would look like:\r
+ EFI_WIN_NT_PHYSICAL_DISKS=Z:RO;307200;2048\r
+\r
+ EFI_WIN_NT_FILE_SYSTEM =\r
+ <directory path>[!...]\r
+\r
+ Mounting the two directories C:\FOO and C:\BAR would look like:\r
+ EFI_WIN_NT_FILE_SYSTEM=c:\foo!c:\bar\r
+\r
+ EFI_WIN_NT_CONSOLE =\r
+ <window title>\r
+\r
+ Declaring a text console window with the title "My EFI Console" woild look like:\r
+ EFI_WIN_NT_CONSOLE=My EFI Console\r
+\r
+ EFI_WIN_NT_UGA =\r
+ <width> <height>[!...]\r
+\r
+ Declaring a two UGA windows with resolutions of 800x600 and 1024x768 would look like:\r
+ Example : EFI_WIN_NT_UGA=800 600!1024 768\r
+\r
+ EFI_WIN_NT_SERIAL_PORT =\r
+ <port name>[!...]\r
+\r
+ Declaring two serial ports on COM1 and COM2 would look like:\r
+ Example : EFI_WIN_NT_SERIAL_PORT=COM1!COM2\r
+\r
+ EFI_WIN_NT_PASS_THROUGH =\r
+ <BaseAddress>;<Bus#>;<Device#>;<Function#>\r
+\r
+ Declaring a base address of 0xE0000000 (used for PCI Express devices)\r
+ and having NT32 talk to a device located at bus 0, device 1, function 0:\r
+ Example : EFI_WIN_NT_PASS_THROUGH=E000000;0;1;0\r
+\r
+---*/\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <Uefi.h>\r
+#include <WinNtDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/WinNtThunk.h>\r
+#include <Protocol/WinNtIo.h>\r
+#include <Protocol/ComponentName.h>\r
+#include <Protocol/DriverBinding.h>\r
+#include <Protocol/DevicePath.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+#include "WinNtBusDriver.h"\r
+\r
+extern EFI_GUID gWinNtBusDriverGuid;\r
+//\r
+// DriverBinding protocol global\r
+//\r
+EFI_DRIVER_BINDING_PROTOCOL gWinNtBusDriverBinding = {\r
+ WinNtBusDriverBindingSupported,\r
+ WinNtBusDriverBindingStart,\r
+ WinNtBusDriverBindingStop,\r
+ 0xa,\r
+ NULL,\r
+ NULL\r
+};\r
+\r
+#define NT_PCD_ARRAY_SIZE (sizeof(mPcdEnvironment)/sizeof(NT_PCD_ENTRY))\r
+\r
+//\r
+// Table to map NT Environment variable to the GUID that should be in\r
+// device path.\r
+//\r
+static NT_PCD_ENTRY mPcdEnvironment[] = {\r
+ PcdToken(PcdWinNtConsole), &gEfiWinNtConsoleGuid,\r
+ PcdToken(PcdWinNtGop), &gEfiWinNtGopGuid,\r
+ PcdToken(PcdWinNtSerialPort), &gEfiWinNtSerialPortGuid,\r
+ PcdToken(PcdWinNtFileSystem), &gEfiWinNtFileSystemGuid,\r
+ PcdToken(PcdWinNtVirtualDisk), &gEfiWinNtVirtualDisksGuid,\r
+ PcdToken(PcdWinNtPhysicalDisk), &gEfiWinNtPhysicalDisksGuid,\r
+ PcdToken(PcdWinNtCpuModel), &gEfiWinNtCPUModelGuid,\r
+ PcdToken(PcdWinNtCpuSpeed), &gEfiWinNtCPUSpeedGuid,\r
+ PcdToken(PcdWinNtMemorySize), &gEfiWinNtMemoryGuid\r
+};\r
+\r
+/**\r
+ The user Entry Point for module WinNtBusDriver. The user code starts with this function.\r
+\r
+ @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
+ @param[in] SystemTable A pointer to the EFI System Table.\r
+ \r
+ @retval EFI_SUCCESS The entry point is executed successfully.\r
+ @retval other Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeWinNtBusDriver(\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ //\r
+ // Install driver model protocol(s).\r
+ //\r
+ Status = EfiLibInstallAllDriverProtocols (\r
+ ImageHandle,\r
+ SystemTable,\r
+ &gWinNtBusDriverBinding,\r
+ ImageHandle,\r
+ &gWinNtBusDriverComponentName,\r
+ NULL,\r
+ NULL\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+ return Status;\r
+}\r
+\r
+VOID *\r
+AllocateMemory (\r
+ IN UINTN Size\r
+ )\r
+{\r
+ VOID *Buffer;\r
+\r
+ Buffer = AllocatePool (Size);\r
+ ASSERT (Buffer != NULL);\r
+\r
+ return Buffer;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBusDriverBindingSupported (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE ControllerHandle,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+ None\r
+\r
+--*/\r
+// TODO: This - add argument and description to function comment\r
+// TODO: ControllerHandle - add argument and description to function comment\r
+// TODO: RemainingDevicePath - add argument and description to function comment\r
+// TODO: EFI_UNSUPPORTED - add return value to function comment\r
+// TODO: EFI_UNSUPPORTED - add return value to function comment\r
+// TODO: EFI_SUCCESS - add return value to function comment\r
+// TODO: EFI_SUCCESS - add return value to function comment\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
+ EFI_WIN_NT_THUNK_PROTOCOL *WinNtThunk;\r
+ UINTN Index;\r
+\r
+ //\r
+ // Check the contents of the first Device Path Node of RemainingDevicePath to make sure\r
+ // it is a legal Device Path Node for this bus driver's children.\r
+ //\r
+ if (RemainingDevicePath != NULL) {\r
+ if (RemainingDevicePath->Type != HARDWARE_DEVICE_PATH ||\r
+ RemainingDevicePath->SubType != HW_VENDOR_DP ||\r
+ DevicePathNodeLength(RemainingDevicePath) != sizeof(WIN_NT_VENDOR_DEVICE_PATH_NODE)) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ for (Index = 0; Index < NT_PCD_ARRAY_SIZE; Index++) {\r
+ if (CompareGuid (&((VENDOR_DEVICE_PATH *) RemainingDevicePath)->Guid, mPcdEnvironment[Index].DevicePathGuid)) {\r
+ break;\r
+ }\r
+ }\r
+\r
+ if (Index >= NT_PCD_ARRAY_SIZE) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ }\r
+\r
+ //\r
+ // Open the IO Abstraction(s) needed to perform the supported test\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ ControllerHandle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ &ParentDevicePath,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (Status == EFI_ALREADY_STARTED) {\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ gBS->CloseProtocol (\r
+ ControllerHandle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle\r
+ );\r
+\r
+ Status = gBS->OpenProtocol (\r
+ ControllerHandle,\r
+ &gEfiWinNtThunkProtocolGuid,\r
+ &WinNtThunk,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (Status == EFI_ALREADY_STARTED) {\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // Since we call through WinNtThunk we need to make sure it's valid\r
+ //\r
+ Status = EFI_SUCCESS;\r
+ if (WinNtThunk->Signature != EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE) {\r
+ Status = EFI_UNSUPPORTED;\r
+ }\r
+\r
+ //\r
+ // Close the I/O Abstraction(s) used to perform the supported test\r
+ //\r
+ gBS->CloseProtocol (\r
+ ControllerHandle,\r
+ &gEfiWinNtThunkProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle\r
+ );\r
+\r
+ return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBusDriverBindingStart (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE ControllerHandle,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+ None\r
+\r
+--*/\r
+// TODO: This - add argument and description to function comment\r
+// TODO: ControllerHandle - add argument and description to function comment\r
+// TODO: RemainingDevicePath - add argument and description to function comment\r
+// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment\r
+// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment\r
+// TODO: EFI_SUCCESS - add return value to function comment\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_STATUS InstallStatus;\r
+ EFI_WIN_NT_THUNK_PROTOCOL *WinNtThunk;\r
+ EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
+ WIN_NT_BUS_DEVICE *WinNtBusDevice;\r
+ WIN_NT_IO_DEVICE *WinNtDevice;\r
+ UINTN Index;\r
+ CHAR16 *StartString;\r
+ CHAR16 *SubString;\r
+ UINT16 Count;\r
+ UINTN StringSize;\r
+ UINT16 ComponentName[MAX_NT_ENVIRNMENT_VARIABLE_LENGTH];\r
+ WIN_NT_VENDOR_DEVICE_PATH_NODE *Node;\r
+ BOOLEAN CreateDevice;\r
+ CHAR16 *TempStr;\r
+ CHAR16 *PcdTempStr;\r
+ UINTN TempStrSize;\r
+\r
+ Status = EFI_UNSUPPORTED;\r
+\r
+ //\r
+ // Grab the protocols we need\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ ControllerHandle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ &ParentDevicePath,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
+ return Status;\r
+ }\r
+\r
+ Status = gBS->OpenProtocol (\r
+ ControllerHandle,\r
+ &gEfiWinNtThunkProtocolGuid,\r
+ &WinNtThunk,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
+ return Status;\r
+ }\r
+\r
+ if (Status != EFI_ALREADY_STARTED) {\r
+ WinNtBusDevice = AllocatePool (sizeof (WIN_NT_BUS_DEVICE));\r
+ if (WinNtBusDevice == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ WinNtBusDevice->Signature = WIN_NT_BUS_DEVICE_SIGNATURE;\r
+ WinNtBusDevice->ControllerNameTable = NULL;\r
+\r
+ AddUnicodeString (\r
+ "eng",\r
+ gWinNtBusDriverComponentName.SupportedLanguages,\r
+ &WinNtBusDevice->ControllerNameTable,\r
+ L"Windows Bus Controller"\r
+ );\r
+\r
+ Status = gBS->InstallMultipleProtocolInterfaces (\r
+ &ControllerHandle,\r
+ &gWinNtBusDriverGuid,\r
+ WinNtBusDevice,\r
+ NULL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ FreeUnicodeStringTable (WinNtBusDevice->ControllerNameTable);\r
+ FreePool (WinNtBusDevice);\r
+ return Status;\r
+ }\r
+ }\r
+\r
+ //\r
+ // Loop on the Variable list. Parse each variable to produce a set of handles that\r
+ // represent virtual hardware devices.\r
+ //\r
+ InstallStatus = EFI_NOT_FOUND;\r
+ for (Index = 0; Index < NT_PCD_ARRAY_SIZE; Index++) {\r
+ PcdTempStr = (VOID *)LibPcdGetPtr (mPcdEnvironment[Index].Token);\r
+ ASSERT (PcdTempStr != NULL);\r
+\r
+ TempStrSize = StrLen (PcdTempStr);\r
+ TempStr = AllocateMemory ((TempStrSize * sizeof (CHAR16)) + 1);\r
+ StrCpy (TempStr, PcdTempStr);\r
+\r
+ StartString = TempStr;\r
+\r
+ //\r
+ // Parse the envirnment variable into sub strings using '!' as a delimator.\r
+ // Each substring needs it's own handle to be added to the system. This code\r
+ // does not understand the sub string. Thats the device drivers job.\r
+ //\r
+ Count = 0;\r
+ while (*StartString != '\0') {\r
+\r
+ //\r
+ // Find the end of the sub string\r
+ //\r
+ SubString = StartString;\r
+ while (*SubString != '\0' && *SubString != '!') {\r
+ SubString++;\r
+ }\r
+\r
+ if (*SubString == '!') {\r
+ //\r
+ // Replace token with '\0' to make sub strings. If this is the end\r
+ // of the string SubString will already point to NULL.\r
+ //\r
+ *SubString = '\0';\r
+ SubString++;\r
+ }\r
+\r
+ CreateDevice = TRUE;\r
+ if (RemainingDevicePath != NULL) {\r
+ CreateDevice = FALSE;\r
+ Node = (WIN_NT_VENDOR_DEVICE_PATH_NODE *) RemainingDevicePath;\r
+ if (Node->VendorDevicePath.Header.Type == HARDWARE_DEVICE_PATH &&\r
+ Node->VendorDevicePath.Header.SubType == HW_VENDOR_DP &&\r
+ DevicePathNodeLength (&Node->VendorDevicePath.Header) == sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE)\r
+ ) {\r
+ if (CompareGuid (&Node->VendorDevicePath.Guid, mPcdEnvironment[Index].DevicePathGuid) &&\r
+ Node->Instance == Count\r
+ ) {\r
+ CreateDevice = TRUE;\r
+ }\r
+ }\r
+ }\r
+\r
+ if (CreateDevice) {\r
+\r
+ //\r
+ // Allocate instance structure, and fill in parent information.\r
+ //\r
+ WinNtDevice = AllocateMemory (sizeof (WIN_NT_IO_DEVICE));\r
+ if (WinNtDevice == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ WinNtDevice->Handle = NULL;\r
+ WinNtDevice->ControllerHandle = ControllerHandle;\r
+ WinNtDevice->ParentDevicePath = ParentDevicePath;\r
+\r
+ WinNtDevice->WinNtIo.WinNtThunk = WinNtThunk;\r
+\r
+ //\r
+ // Plus 2 to account for the NULL at the end of the Unicode string\r
+ //\r
+ StringSize = (UINTN) ((UINT8 *) SubString - (UINT8 *) StartString) + sizeof (CHAR16);\r
+ WinNtDevice->WinNtIo.EnvString = AllocateMemory (StringSize);\r
+ if (WinNtDevice->WinNtIo.EnvString != NULL) {\r
+ CopyMem (WinNtDevice->WinNtIo.EnvString, StartString, StringSize);\r
+ }\r
+\r
+ WinNtDevice->ControllerNameTable = NULL;\r
+\r
+ WinNtThunk->SPrintf (ComponentName, sizeof (ComponentName), L"%s", WinNtDevice->WinNtIo.EnvString);\r
+\r
+ WinNtDevice->DevicePath = WinNtBusCreateDevicePath (\r
+ ParentDevicePath,\r
+ mPcdEnvironment[Index].DevicePathGuid,\r
+ Count\r
+ );\r
+ if (WinNtDevice->DevicePath == NULL) {\r
+ FreePool (WinNtDevice);\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ AddUnicodeString (\r
+ "eng",\r
+ gWinNtBusDriverComponentName.SupportedLanguages,\r
+ &WinNtDevice->ControllerNameTable,\r
+ ComponentName\r
+ );\r
+\r
+ WinNtDevice->WinNtIo.TypeGuid = mPcdEnvironment[Index].DevicePathGuid;\r
+ WinNtDevice->WinNtIo.InstanceNumber = Count;\r
+\r
+ WinNtDevice->Signature = WIN_NT_IO_DEVICE_SIGNATURE;\r
+\r
+ Status = gBS->InstallMultipleProtocolInterfaces (\r
+ &WinNtDevice->Handle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ WinNtDevice->DevicePath,\r
+ &gEfiWinNtIoProtocolGuid,\r
+ &WinNtDevice->WinNtIo,\r
+ NULL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ FreeUnicodeStringTable (WinNtDevice->ControllerNameTable);\r
+ FreePool (WinNtDevice);\r
+ } else {\r
+ //\r
+ // Open For Child Device\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ ControllerHandle,\r
+ &gEfiWinNtThunkProtocolGuid,\r
+ &WinNtThunk,\r
+ This->DriverBindingHandle,\r
+ WinNtDevice->Handle,\r
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ InstallStatus = EFI_SUCCESS;\r
+ }\r
+ }\r
+ }\r
+\r
+ //\r
+ // Parse Next sub string. This will point to '\0' if we are at the end.\r
+ //\r
+ Count++;\r
+ StartString = SubString;\r
+ }\r
+\r
+ FreePool (TempStr);\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBusDriverBindingStop (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE ControllerHandle,\r
+ IN UINTN NumberOfChildren,\r
+ IN EFI_HANDLE *ChildHandleBuffer\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+ None\r
+\r
+--*/\r
+// TODO: This - add argument and description to function comment\r
+// TODO: ControllerHandle - add argument and description to function comment\r
+// TODO: NumberOfChildren - add argument and description to function comment\r
+// TODO: ChildHandleBuffer - add argument and description to function comment\r
+// TODO: EFI_SUCCESS - add return value to function comment\r
+// TODO: EFI_DEVICE_ERROR - add return value to function comment\r
+// TODO: EFI_SUCCESS - add return value to function comment\r
+{\r
+ EFI_STATUS Status;\r
+ UINTN Index;\r
+ BOOLEAN AllChildrenStopped;\r
+ EFI_WIN_NT_IO_PROTOCOL *WinNtIo;\r
+ WIN_NT_BUS_DEVICE *WinNtBusDevice;\r
+ WIN_NT_IO_DEVICE *WinNtDevice;\r
+ EFI_WIN_NT_THUNK_PROTOCOL *WinNtThunk;\r
+\r
+ //\r
+ // Complete all outstanding transactions to Controller.\r
+ // Don't allow any new transaction to Controller to be started.\r
+ //\r
+\r
+ if (NumberOfChildren == 0) {\r
+ //\r
+ // Close the bus driver\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ ControllerHandle,\r
+ &gWinNtBusDriverGuid,\r
+ &WinNtBusDevice,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ gBS->UninstallMultipleProtocolInterfaces (\r
+ ControllerHandle,\r
+ &gWinNtBusDriverGuid,\r
+ WinNtBusDevice,\r
+ NULL\r
+ );\r
+\r
+ FreeUnicodeStringTable (WinNtBusDevice->ControllerNameTable);\r
+\r
+ FreePool (WinNtBusDevice);\r
+\r
+ gBS->CloseProtocol (\r
+ ControllerHandle,\r
+ &gEfiWinNtThunkProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle\r
+ );\r
+\r
+ gBS->CloseProtocol (\r
+ ControllerHandle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle\r
+ );\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ AllChildrenStopped = TRUE;\r
+\r
+ for (Index = 0; Index < NumberOfChildren; Index++) {\r
+\r
+ Status = gBS->OpenProtocol (\r
+ ChildHandleBuffer[Index],\r
+ &gEfiWinNtIoProtocolGuid,\r
+ &WinNtIo,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+\r
+ WinNtDevice = WIN_NT_IO_DEVICE_FROM_THIS (WinNtIo);\r
+\r
+ Status = gBS->CloseProtocol (\r
+ ControllerHandle,\r
+ &gEfiWinNtThunkProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ WinNtDevice->Handle\r
+ );\r
+\r
+ Status = gBS->UninstallMultipleProtocolInterfaces (\r
+ WinNtDevice->Handle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ WinNtDevice->DevicePath,\r
+ &gEfiWinNtIoProtocolGuid,\r
+ &WinNtDevice->WinNtIo,\r
+ NULL\r
+ );\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ gBS->OpenProtocol (\r
+ ControllerHandle,\r
+ &gEfiWinNtThunkProtocolGuid,\r
+ (VOID **) &WinNtThunk,\r
+ This->DriverBindingHandle,\r
+ WinNtDevice->Handle,\r
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+ );\r
+ } else {\r
+ //\r
+ // Close the child handle\r
+ //\r
+ FreeUnicodeStringTable (WinNtDevice->ControllerNameTable);\r
+ FreePool (WinNtDevice);\r
+ }\r
+ }\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ AllChildrenStopped = FALSE;\r
+ }\r
+ }\r
+\r
+ if (!AllChildrenStopped) {\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+WinNtBusCreateDevicePath (\r
+ IN EFI_DEVICE_PATH_PROTOCOL *RootDevicePath,\r
+ IN EFI_GUID *Guid,\r
+ IN UINT16 InstanceNumber\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Create a device path node using Guid and InstanceNumber and append it to\r
+ the passed in RootDevicePath\r
+\r
+Arguments:\r
+ RootDevicePath - Root of the device path to return.\r
+\r
+ Guid - GUID to use in vendor device path node.\r
+\r
+ InstanceNumber - Instance number to use in the vendor device path. This\r
+ argument is needed to make sure each device path is unique.\r
+\r
+Returns:\r
+\r
+ EFI_DEVICE_PATH_PROTOCOL\r
+\r
+--*/\r
+{\r
+ WIN_NT_VENDOR_DEVICE_PATH_NODE DevicePath;\r
+\r
+ DevicePath.VendorDevicePath.Header.Type = HARDWARE_DEVICE_PATH;\r
+ DevicePath.VendorDevicePath.Header.SubType = HW_VENDOR_DP;\r
+ SetDevicePathNodeLength (&DevicePath.VendorDevicePath.Header, sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE));\r
+\r
+ //\r
+ // The GUID defines the Class\r
+ //\r
+ CopyMem (&DevicePath.VendorDevicePath.Guid, Guid, sizeof (EFI_GUID));\r
+\r
+ //\r
+ // Add an instance number so we can make sure there are no Device Path\r
+ // duplication.\r
+ //\r
+ DevicePath.Instance = InstanceNumber;\r
+\r
+ return AppendDevicePathNode (\r
+ RootDevicePath,\r
+ (EFI_DEVICE_PATH_PROTOCOL *) &DevicePath\r
+ );\r
+}\r