]> git.proxmox.com Git - mirror_edk2.git/blame - Nt32Pkg/WinNtBusDriverDxe/WinNtBusDriver.c
removed gEfiWinNtCPUSpeedGuid, gEfiWinNtCPUModelGuid, and gEfiWinNtMemoryGuid. Replac...
[mirror_edk2.git] / Nt32Pkg / WinNtBusDriverDxe / WinNtBusDriver.c
CommitLineData
420fc8e5 1/*+++\r
2\r
3Copyright (c) 2006 - 2007, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 WinNtBusDriver.c\r
15\r
16Abstract:\r
17\r
18This following section documents the envirnoment variables for the Win NT\r
19build. These variables are used to define the (virtual) hardware\r
20configuration of the NT environment\r
21\r
22A ! can be used to seperate multiple instances in a variable. Each\r
23instance represents a seperate hardware device.\r
24\r
25EFI_WIN_NT_PHYSICAL_DISKS - maps to drives on your system\r
26EFI_WIN_NT_VIRTUAL_DISKS - maps to a device emulated by a file\r
27EFI_WIN_NT_FILE_SYSTEM - mouts a directory as a file system\r
28EFI_WIN_NT_CONSOLE - make a logical comand line window (only one!)\r
29EFI_WIN_NT_UGA - Builds UGA Windows of Width and Height\r
30EFI_WIN_NT_SERIAL_PORT - maps physical serial ports\r
31\r
32 <F>ixed - Fixed disk like a hard drive.\r
33 <R>emovable - Removable media like a floppy or CD-ROM.\r
34 Read <O>nly - Write protected device.\r
35 Read <W>rite - Read write device.\r
36 <block count> - Decimal number of blocks a device supports.\r
37 <block size> - Decimal number of bytes per block.\r
38\r
39 NT envirnonment variable contents. '<' and '>' are not part of the variable,\r
40 they are just used to make this help more readable. There should be no\r
41 spaces between the ';'. Extra spaces will break the variable. A '!' is\r
42 used to seperate multiple devices in a variable.\r
43\r
44 EFI_WIN_NT_VIRTUAL_DISKS =\r
45 <F | R><O | W>;<block count>;<block size>[!...]\r
46\r
47 EFI_WIN_NT_PHYSICAL_DISKS =\r
48 <drive letter>:<F | R><O | W>;<block count>;<block size>[!...]\r
49\r
50 Virtual Disks: These devices use a file to emulate a hard disk or removable\r
51 media device.\r
52\r
53 Thus a 20 MB emulated hard drive would look like:\r
54 EFI_WIN_NT_VIRTUAL_DISKS=FW;40960;512\r
55\r
56 A 1.44MB emulated floppy with a block size of 1024 would look like:\r
57 EFI_WIN_NT_VIRTUAL_DISKS=RW;1440;1024\r
58\r
59 Physical Disks: These devices use NT to open a real device in your system\r
60\r
61 Thus a 120 MB floppy would look like:\r
62 EFI_WIN_NT_PHYSICAL_DISKS=B:RW;245760;512\r
63\r
64 Thus a standard CD-ROM floppy would look like:\r
65 EFI_WIN_NT_PHYSICAL_DISKS=Z:RO;307200;2048\r
66\r
67 EFI_WIN_NT_FILE_SYSTEM =\r
68 <directory path>[!...]\r
69\r
70 Mounting the two directories C:\FOO and C:\BAR would look like:\r
71 EFI_WIN_NT_FILE_SYSTEM=c:\foo!c:\bar\r
72\r
73 EFI_WIN_NT_CONSOLE =\r
74 <window title>\r
75\r
76 Declaring a text console window with the title "My EFI Console" woild look like:\r
77 EFI_WIN_NT_CONSOLE=My EFI Console\r
78\r
79 EFI_WIN_NT_UGA =\r
80 <width> <height>[!...]\r
81\r
82 Declaring a two UGA windows with resolutions of 800x600 and 1024x768 would look like:\r
83 Example : EFI_WIN_NT_UGA=800 600!1024 768\r
84\r
85 EFI_WIN_NT_SERIAL_PORT =\r
86 <port name>[!...]\r
87\r
88 Declaring two serial ports on COM1 and COM2 would look like:\r
89 Example : EFI_WIN_NT_SERIAL_PORT=COM1!COM2\r
90\r
91 EFI_WIN_NT_PASS_THROUGH =\r
92 <BaseAddress>;<Bus#>;<Device#>;<Function#>\r
93\r
94 Declaring a base address of 0xE0000000 (used for PCI Express devices)\r
95 and having NT32 talk to a device located at bus 0, device 1, function 0:\r
96 Example : EFI_WIN_NT_PASS_THROUGH=E000000;0;1;0\r
97\r
98---*/\r
99\r
100//\r
101// The package level header files this module uses\r
102//\r
103#include <Uefi.h>\r
104#include <WinNtDxe.h>\r
105//\r
106// The protocols, PPI and GUID defintions for this module\r
107//\r
108#include <Protocol/WinNtThunk.h>\r
109#include <Protocol/WinNtIo.h>\r
110#include <Protocol/ComponentName.h>\r
111#include <Protocol/DriverBinding.h>\r
112#include <Protocol/DevicePath.h>\r
113//\r
114// The Library classes this module consumes\r
115//\r
116#include <Library/DebugLib.h>\r
117#include <Library/BaseLib.h>\r
118#include <Library/UefiDriverEntryPoint.h>\r
119#include <Library/UefiLib.h>\r
120#include <Library/PcdLib.h>\r
121#include <Library/BaseMemoryLib.h>\r
122#include <Library/UefiBootServicesTableLib.h>\r
123#include <Library/DevicePathLib.h>\r
124#include <Library/MemoryAllocationLib.h>\r
125\r
126#include "WinNtBusDriver.h"\r
127\r
128extern EFI_GUID gWinNtBusDriverGuid;\r
129//\r
130// DriverBinding protocol global\r
131//\r
132EFI_DRIVER_BINDING_PROTOCOL gWinNtBusDriverBinding = {\r
133 WinNtBusDriverBindingSupported,\r
134 WinNtBusDriverBindingStart,\r
135 WinNtBusDriverBindingStop,\r
136 0xa,\r
137 NULL,\r
138 NULL\r
139};\r
140\r
cba9012a 141#define NT_PCD_ARRAY_SIZE (sizeof(mPcdEnvironment)/sizeof(NT_PCD_ENTRY))\r
420fc8e5 142\r
143//\r
144// Table to map NT Environment variable to the GUID that should be in\r
145// device path.\r
146//\r
cba9012a 147static NT_PCD_ENTRY mPcdEnvironment[] = {\r
148 PcdToken(PcdWinNtConsole), &gEfiWinNtConsoleGuid,\r
149 PcdToken(PcdWinNtGop), &gEfiWinNtGopGuid,\r
150 PcdToken(PcdWinNtSerialPort), &gEfiWinNtSerialPortGuid,\r
151 PcdToken(PcdWinNtFileSystem), &gEfiWinNtFileSystemGuid,\r
152 PcdToken(PcdWinNtVirtualDisk), &gEfiWinNtVirtualDisksGuid,\r
b397fbbb 153 PcdToken(PcdWinNtPhysicalDisk), &gEfiWinNtPhysicalDisksGuid\r
420fc8e5 154};\r
155\r
156/**\r
157 The user Entry Point for module WinNtBusDriver. The user code starts with this function.\r
158\r
159 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
160 @param[in] SystemTable A pointer to the EFI System Table.\r
161 \r
162 @retval EFI_SUCCESS The entry point is executed successfully.\r
163 @retval other Some error occurs when executing this entry point.\r
164\r
165**/\r
166EFI_STATUS\r
167EFIAPI\r
168InitializeWinNtBusDriver(\r
169 IN EFI_HANDLE ImageHandle,\r
170 IN EFI_SYSTEM_TABLE *SystemTable\r
171 )\r
172{\r
173 EFI_STATUS Status;\r
174\r
175 //\r
176 // Install driver model protocol(s).\r
177 //\r
178 Status = EfiLibInstallAllDriverProtocols (\r
179 ImageHandle,\r
180 SystemTable,\r
181 &gWinNtBusDriverBinding,\r
182 ImageHandle,\r
183 &gWinNtBusDriverComponentName,\r
184 NULL,\r
185 NULL\r
186 );\r
187 ASSERT_EFI_ERROR (Status);\r
188\r
189\r
190 return Status;\r
191}\r
192\r
193VOID *\r
194AllocateMemory (\r
195 IN UINTN Size\r
196 )\r
197{\r
198 VOID *Buffer;\r
199\r
200 Buffer = AllocatePool (Size);\r
201 ASSERT (Buffer != NULL);\r
202\r
203 return Buffer;\r
204}\r
205\r
206\r
207EFI_STATUS\r
208EFIAPI\r
209WinNtBusDriverBindingSupported (\r
210 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
211 IN EFI_HANDLE ControllerHandle,\r
212 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
213 )\r
214/*++\r
215\r
216Routine Description:\r
217\r
218Arguments:\r
219\r
220Returns:\r
221\r
222 None\r
223\r
224--*/\r
225// TODO: This - add argument and description to function comment\r
226// TODO: ControllerHandle - add argument and description to function comment\r
227// TODO: RemainingDevicePath - add argument and description to function comment\r
228// TODO: EFI_UNSUPPORTED - add return value to function comment\r
229// TODO: EFI_UNSUPPORTED - add return value to function comment\r
230// TODO: EFI_SUCCESS - add return value to function comment\r
231// TODO: EFI_SUCCESS - add return value to function comment\r
232{\r
233 EFI_STATUS Status;\r
234 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
235 EFI_WIN_NT_THUNK_PROTOCOL *WinNtThunk;\r
236 UINTN Index;\r
237\r
238 //\r
239 // Check the contents of the first Device Path Node of RemainingDevicePath to make sure\r
240 // it is a legal Device Path Node for this bus driver's children.\r
241 //\r
242 if (RemainingDevicePath != NULL) {\r
243 if (RemainingDevicePath->Type != HARDWARE_DEVICE_PATH ||\r
244 RemainingDevicePath->SubType != HW_VENDOR_DP ||\r
245 DevicePathNodeLength(RemainingDevicePath) != sizeof(WIN_NT_VENDOR_DEVICE_PATH_NODE)) {\r
246 return EFI_UNSUPPORTED;\r
247 }\r
248\r
249 for (Index = 0; Index < NT_PCD_ARRAY_SIZE; Index++) {\r
250 if (CompareGuid (&((VENDOR_DEVICE_PATH *) RemainingDevicePath)->Guid, mPcdEnvironment[Index].DevicePathGuid)) {\r
251 break;\r
252 }\r
253 }\r
254\r
255 if (Index >= NT_PCD_ARRAY_SIZE) {\r
256 return EFI_UNSUPPORTED;\r
257 }\r
258 }\r
259\r
260 //\r
261 // Open the IO Abstraction(s) needed to perform the supported test\r
262 //\r
263 Status = gBS->OpenProtocol (\r
264 ControllerHandle,\r
265 &gEfiDevicePathProtocolGuid,\r
266 &ParentDevicePath,\r
267 This->DriverBindingHandle,\r
268 ControllerHandle,\r
269 EFI_OPEN_PROTOCOL_BY_DRIVER\r
270 );\r
271 if (Status == EFI_ALREADY_STARTED) {\r
272 return EFI_SUCCESS;\r
273 }\r
274\r
275 if (EFI_ERROR (Status)) {\r
276 return Status;\r
277 }\r
278\r
279 gBS->CloseProtocol (\r
280 ControllerHandle,\r
281 &gEfiDevicePathProtocolGuid,\r
282 This->DriverBindingHandle,\r
283 ControllerHandle\r
284 );\r
285\r
286 Status = gBS->OpenProtocol (\r
287 ControllerHandle,\r
288 &gEfiWinNtThunkProtocolGuid,\r
289 &WinNtThunk,\r
290 This->DriverBindingHandle,\r
291 ControllerHandle,\r
292 EFI_OPEN_PROTOCOL_BY_DRIVER\r
293 );\r
294 if (Status == EFI_ALREADY_STARTED) {\r
295 return EFI_SUCCESS;\r
296 }\r
297\r
298 if (EFI_ERROR (Status)) {\r
299 return Status;\r
300 }\r
301\r
302 //\r
303 // Since we call through WinNtThunk we need to make sure it's valid\r
304 //\r
305 Status = EFI_SUCCESS;\r
306 if (WinNtThunk->Signature != EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE) {\r
307 Status = EFI_UNSUPPORTED;\r
308 }\r
309\r
310 //\r
311 // Close the I/O Abstraction(s) used to perform the supported test\r
312 //\r
313 gBS->CloseProtocol (\r
314 ControllerHandle,\r
315 &gEfiWinNtThunkProtocolGuid,\r
316 This->DriverBindingHandle,\r
317 ControllerHandle\r
318 );\r
319\r
320 return Status;\r
321}\r
322\r
323EFI_STATUS\r
324EFIAPI\r
325WinNtBusDriverBindingStart (\r
326 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
327 IN EFI_HANDLE ControllerHandle,\r
328 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
329 )\r
330/*++\r
331\r
332Routine Description:\r
333\r
334Arguments:\r
335\r
336Returns:\r
337\r
338 None\r
339\r
340--*/\r
341// TODO: This - add argument and description to function comment\r
342// TODO: ControllerHandle - add argument and description to function comment\r
343// TODO: RemainingDevicePath - add argument and description to function comment\r
344// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment\r
345// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment\r
346// TODO: EFI_SUCCESS - add return value to function comment\r
347{\r
348 EFI_STATUS Status;\r
349 EFI_STATUS InstallStatus;\r
350 EFI_WIN_NT_THUNK_PROTOCOL *WinNtThunk;\r
351 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
352 WIN_NT_BUS_DEVICE *WinNtBusDevice;\r
353 WIN_NT_IO_DEVICE *WinNtDevice;\r
354 UINTN Index;\r
355 CHAR16 *StartString;\r
356 CHAR16 *SubString;\r
357 UINT16 Count;\r
358 UINTN StringSize;\r
359 UINT16 ComponentName[MAX_NT_ENVIRNMENT_VARIABLE_LENGTH];\r
360 WIN_NT_VENDOR_DEVICE_PATH_NODE *Node;\r
361 BOOLEAN CreateDevice;\r
362 CHAR16 *TempStr;\r
363 CHAR16 *PcdTempStr;\r
364 UINTN TempStrSize;\r
365\r
366 Status = EFI_UNSUPPORTED;\r
367\r
368 //\r
369 // Grab the protocols we need\r
370 //\r
371 Status = gBS->OpenProtocol (\r
372 ControllerHandle,\r
373 &gEfiDevicePathProtocolGuid,\r
374 &ParentDevicePath,\r
375 This->DriverBindingHandle,\r
376 ControllerHandle,\r
377 EFI_OPEN_PROTOCOL_BY_DRIVER\r
378 );\r
379 if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
380 return Status;\r
381 }\r
382\r
383 Status = gBS->OpenProtocol (\r
384 ControllerHandle,\r
385 &gEfiWinNtThunkProtocolGuid,\r
386 &WinNtThunk,\r
387 This->DriverBindingHandle,\r
388 ControllerHandle,\r
389 EFI_OPEN_PROTOCOL_BY_DRIVER\r
390 );\r
391 if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
392 return Status;\r
393 }\r
394\r
395 if (Status != EFI_ALREADY_STARTED) {\r
396 WinNtBusDevice = AllocatePool (sizeof (WIN_NT_BUS_DEVICE));\r
397 if (WinNtBusDevice == NULL) {\r
398 return EFI_OUT_OF_RESOURCES;\r
399 }\r
400\r
401 WinNtBusDevice->Signature = WIN_NT_BUS_DEVICE_SIGNATURE;\r
402 WinNtBusDevice->ControllerNameTable = NULL;\r
403\r
404 AddUnicodeString (\r
405 "eng",\r
406 gWinNtBusDriverComponentName.SupportedLanguages,\r
407 &WinNtBusDevice->ControllerNameTable,\r
408 L"Windows Bus Controller"\r
409 );\r
410\r
411 Status = gBS->InstallMultipleProtocolInterfaces (\r
412 &ControllerHandle,\r
413 &gWinNtBusDriverGuid,\r
414 WinNtBusDevice,\r
415 NULL\r
416 );\r
417 if (EFI_ERROR (Status)) {\r
418 FreeUnicodeStringTable (WinNtBusDevice->ControllerNameTable);\r
419 FreePool (WinNtBusDevice);\r
420 return Status;\r
421 }\r
422 }\r
423\r
424 //\r
425 // Loop on the Variable list. Parse each variable to produce a set of handles that\r
426 // represent virtual hardware devices.\r
427 //\r
428 InstallStatus = EFI_NOT_FOUND;\r
429 for (Index = 0; Index < NT_PCD_ARRAY_SIZE; Index++) {\r
cba9012a 430 PcdTempStr = (VOID *)LibPcdGetPtr (mPcdEnvironment[Index].Token);\r
420fc8e5 431 ASSERT (PcdTempStr != NULL);\r
432\r
433 TempStrSize = StrLen (PcdTempStr);\r
434 TempStr = AllocateMemory ((TempStrSize * sizeof (CHAR16)) + 1);\r
435 StrCpy (TempStr, PcdTempStr);\r
436\r
437 StartString = TempStr;\r
438\r
439 //\r
440 // Parse the envirnment variable into sub strings using '!' as a delimator.\r
441 // Each substring needs it's own handle to be added to the system. This code\r
442 // does not understand the sub string. Thats the device drivers job.\r
443 //\r
444 Count = 0;\r
445 while (*StartString != '\0') {\r
446\r
447 //\r
448 // Find the end of the sub string\r
449 //\r
450 SubString = StartString;\r
451 while (*SubString != '\0' && *SubString != '!') {\r
452 SubString++;\r
453 }\r
454\r
455 if (*SubString == '!') {\r
456 //\r
457 // Replace token with '\0' to make sub strings. If this is the end\r
458 // of the string SubString will already point to NULL.\r
459 //\r
460 *SubString = '\0';\r
461 SubString++;\r
462 }\r
463\r
464 CreateDevice = TRUE;\r
465 if (RemainingDevicePath != NULL) {\r
466 CreateDevice = FALSE;\r
467 Node = (WIN_NT_VENDOR_DEVICE_PATH_NODE *) RemainingDevicePath;\r
468 if (Node->VendorDevicePath.Header.Type == HARDWARE_DEVICE_PATH &&\r
469 Node->VendorDevicePath.Header.SubType == HW_VENDOR_DP &&\r
470 DevicePathNodeLength (&Node->VendorDevicePath.Header) == sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE)\r
471 ) {\r
472 if (CompareGuid (&Node->VendorDevicePath.Guid, mPcdEnvironment[Index].DevicePathGuid) &&\r
473 Node->Instance == Count\r
474 ) {\r
475 CreateDevice = TRUE;\r
476 }\r
477 }\r
478 }\r
479\r
480 if (CreateDevice) {\r
481\r
482 //\r
483 // Allocate instance structure, and fill in parent information.\r
484 //\r
485 WinNtDevice = AllocateMemory (sizeof (WIN_NT_IO_DEVICE));\r
486 if (WinNtDevice == NULL) {\r
487 return EFI_OUT_OF_RESOURCES;\r
488 }\r
489\r
490 WinNtDevice->Handle = NULL;\r
491 WinNtDevice->ControllerHandle = ControllerHandle;\r
492 WinNtDevice->ParentDevicePath = ParentDevicePath;\r
493\r
494 WinNtDevice->WinNtIo.WinNtThunk = WinNtThunk;\r
495\r
496 //\r
497 // Plus 2 to account for the NULL at the end of the Unicode string\r
498 //\r
499 StringSize = (UINTN) ((UINT8 *) SubString - (UINT8 *) StartString) + sizeof (CHAR16);\r
500 WinNtDevice->WinNtIo.EnvString = AllocateMemory (StringSize);\r
501 if (WinNtDevice->WinNtIo.EnvString != NULL) {\r
502 CopyMem (WinNtDevice->WinNtIo.EnvString, StartString, StringSize);\r
503 }\r
504\r
505 WinNtDevice->ControllerNameTable = NULL;\r
506\r
507 WinNtThunk->SPrintf (ComponentName, sizeof (ComponentName), L"%s", WinNtDevice->WinNtIo.EnvString);\r
508\r
509 WinNtDevice->DevicePath = WinNtBusCreateDevicePath (\r
510 ParentDevicePath,\r
511 mPcdEnvironment[Index].DevicePathGuid,\r
512 Count\r
513 );\r
514 if (WinNtDevice->DevicePath == NULL) {\r
515 FreePool (WinNtDevice);\r
516 return EFI_OUT_OF_RESOURCES;\r
517 }\r
518\r
519 AddUnicodeString (\r
520 "eng",\r
521 gWinNtBusDriverComponentName.SupportedLanguages,\r
522 &WinNtDevice->ControllerNameTable,\r
523 ComponentName\r
524 );\r
525\r
526 WinNtDevice->WinNtIo.TypeGuid = mPcdEnvironment[Index].DevicePathGuid;\r
527 WinNtDevice->WinNtIo.InstanceNumber = Count;\r
528\r
529 WinNtDevice->Signature = WIN_NT_IO_DEVICE_SIGNATURE;\r
530\r
531 Status = gBS->InstallMultipleProtocolInterfaces (\r
532 &WinNtDevice->Handle,\r
533 &gEfiDevicePathProtocolGuid,\r
534 WinNtDevice->DevicePath,\r
535 &gEfiWinNtIoProtocolGuid,\r
536 &WinNtDevice->WinNtIo,\r
537 NULL\r
538 );\r
539 if (EFI_ERROR (Status)) {\r
540 FreeUnicodeStringTable (WinNtDevice->ControllerNameTable);\r
541 FreePool (WinNtDevice);\r
542 } else {\r
543 //\r
544 // Open For Child Device\r
545 //\r
546 Status = gBS->OpenProtocol (\r
547 ControllerHandle,\r
548 &gEfiWinNtThunkProtocolGuid,\r
549 &WinNtThunk,\r
550 This->DriverBindingHandle,\r
551 WinNtDevice->Handle,\r
552 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
553 );\r
554 if (!EFI_ERROR (Status)) {\r
555 InstallStatus = EFI_SUCCESS;\r
556 }\r
557 }\r
558 }\r
559\r
560 //\r
561 // Parse Next sub string. This will point to '\0' if we are at the end.\r
562 //\r
563 Count++;\r
564 StartString = SubString;\r
565 }\r
566\r
567 FreePool (TempStr);\r
568 }\r
569\r
570 return EFI_SUCCESS;\r
571}\r
572\r
573\r
574EFI_STATUS\r
575EFIAPI\r
576WinNtBusDriverBindingStop (\r
577 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
578 IN EFI_HANDLE ControllerHandle,\r
579 IN UINTN NumberOfChildren,\r
580 IN EFI_HANDLE *ChildHandleBuffer\r
581 )\r
582/*++\r
583\r
584Routine Description:\r
585\r
586Arguments:\r
587\r
588Returns:\r
589\r
590 None\r
591\r
592--*/\r
593// TODO: This - add argument and description to function comment\r
594// TODO: ControllerHandle - add argument and description to function comment\r
595// TODO: NumberOfChildren - add argument and description to function comment\r
596// TODO: ChildHandleBuffer - add argument and description to function comment\r
597// TODO: EFI_SUCCESS - add return value to function comment\r
598// TODO: EFI_DEVICE_ERROR - add return value to function comment\r
599// TODO: EFI_SUCCESS - add return value to function comment\r
600{\r
601 EFI_STATUS Status;\r
602 UINTN Index;\r
603 BOOLEAN AllChildrenStopped;\r
604 EFI_WIN_NT_IO_PROTOCOL *WinNtIo;\r
605 WIN_NT_BUS_DEVICE *WinNtBusDevice;\r
606 WIN_NT_IO_DEVICE *WinNtDevice;\r
607 EFI_WIN_NT_THUNK_PROTOCOL *WinNtThunk;\r
608\r
609 //\r
610 // Complete all outstanding transactions to Controller.\r
611 // Don't allow any new transaction to Controller to be started.\r
612 //\r
613\r
614 if (NumberOfChildren == 0) {\r
615 //\r
616 // Close the bus driver\r
617 //\r
618 Status = gBS->OpenProtocol (\r
619 ControllerHandle,\r
620 &gWinNtBusDriverGuid,\r
621 &WinNtBusDevice,\r
622 This->DriverBindingHandle,\r
623 ControllerHandle,\r
624 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
625 );\r
626 if (EFI_ERROR (Status)) {\r
627 return Status;\r
628 }\r
629\r
630 gBS->UninstallMultipleProtocolInterfaces (\r
631 ControllerHandle,\r
632 &gWinNtBusDriverGuid,\r
633 WinNtBusDevice,\r
634 NULL\r
635 );\r
636\r
637 FreeUnicodeStringTable (WinNtBusDevice->ControllerNameTable);\r
638\r
639 FreePool (WinNtBusDevice);\r
640\r
641 gBS->CloseProtocol (\r
642 ControllerHandle,\r
643 &gEfiWinNtThunkProtocolGuid,\r
644 This->DriverBindingHandle,\r
645 ControllerHandle\r
646 );\r
647\r
648 gBS->CloseProtocol (\r
649 ControllerHandle,\r
650 &gEfiDevicePathProtocolGuid,\r
651 This->DriverBindingHandle,\r
652 ControllerHandle\r
653 );\r
654 return EFI_SUCCESS;\r
655 }\r
656\r
657 AllChildrenStopped = TRUE;\r
658\r
659 for (Index = 0; Index < NumberOfChildren; Index++) {\r
660\r
661 Status = gBS->OpenProtocol (\r
662 ChildHandleBuffer[Index],\r
663 &gEfiWinNtIoProtocolGuid,\r
664 &WinNtIo,\r
665 This->DriverBindingHandle,\r
666 ControllerHandle,\r
667 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
668 );\r
669 if (!EFI_ERROR (Status)) {\r
670\r
671 WinNtDevice = WIN_NT_IO_DEVICE_FROM_THIS (WinNtIo);\r
672\r
673 Status = gBS->CloseProtocol (\r
674 ControllerHandle,\r
675 &gEfiWinNtThunkProtocolGuid,\r
676 This->DriverBindingHandle,\r
677 WinNtDevice->Handle\r
678 );\r
679\r
680 Status = gBS->UninstallMultipleProtocolInterfaces (\r
681 WinNtDevice->Handle,\r
682 &gEfiDevicePathProtocolGuid,\r
683 WinNtDevice->DevicePath,\r
684 &gEfiWinNtIoProtocolGuid,\r
685 &WinNtDevice->WinNtIo,\r
686 NULL\r
687 );\r
688\r
689 if (EFI_ERROR (Status)) {\r
690 gBS->OpenProtocol (\r
691 ControllerHandle,\r
692 &gEfiWinNtThunkProtocolGuid,\r
693 (VOID **) &WinNtThunk,\r
694 This->DriverBindingHandle,\r
695 WinNtDevice->Handle,\r
696 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
697 );\r
698 } else {\r
699 //\r
700 // Close the child handle\r
701 //\r
702 FreeUnicodeStringTable (WinNtDevice->ControllerNameTable);\r
703 FreePool (WinNtDevice);\r
704 }\r
705 }\r
706\r
707 if (EFI_ERROR (Status)) {\r
708 AllChildrenStopped = FALSE;\r
709 }\r
710 }\r
711\r
712 if (!AllChildrenStopped) {\r
713 return EFI_DEVICE_ERROR;\r
714 }\r
715\r
716 return EFI_SUCCESS;\r
717}\r
718\r
719EFI_DEVICE_PATH_PROTOCOL *\r
720WinNtBusCreateDevicePath (\r
721 IN EFI_DEVICE_PATH_PROTOCOL *RootDevicePath,\r
722 IN EFI_GUID *Guid,\r
723 IN UINT16 InstanceNumber\r
724 )\r
725/*++\r
726\r
727Routine Description:\r
728 Create a device path node using Guid and InstanceNumber and append it to\r
729 the passed in RootDevicePath\r
730\r
731Arguments:\r
732 RootDevicePath - Root of the device path to return.\r
733\r
734 Guid - GUID to use in vendor device path node.\r
735\r
736 InstanceNumber - Instance number to use in the vendor device path. This\r
737 argument is needed to make sure each device path is unique.\r
738\r
739Returns:\r
740\r
741 EFI_DEVICE_PATH_PROTOCOL\r
742\r
743--*/\r
744{\r
745 WIN_NT_VENDOR_DEVICE_PATH_NODE DevicePath;\r
746\r
747 DevicePath.VendorDevicePath.Header.Type = HARDWARE_DEVICE_PATH;\r
748 DevicePath.VendorDevicePath.Header.SubType = HW_VENDOR_DP;\r
749 SetDevicePathNodeLength (&DevicePath.VendorDevicePath.Header, sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE));\r
750\r
751 //\r
752 // The GUID defines the Class\r
753 //\r
754 CopyMem (&DevicePath.VendorDevicePath.Guid, Guid, sizeof (EFI_GUID));\r
755\r
756 //\r
757 // Add an instance number so we can make sure there are no Device Path\r
758 // duplication.\r
759 //\r
760 DevicePath.Instance = InstanceNumber;\r
761\r
762 return AppendDevicePathNode (\r
763 RootDevicePath,\r
764 (EFI_DEVICE_PATH_PROTOCOL *) &DevicePath\r
765 );\r
766}\r