]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - EdkNt32Pkg/Dxe/WinNtThunk/Bus/WinNtBusDriver/WinNtBusDriver.c
Initial import.
[mirror_edk2.git] / EdkNt32Pkg / Dxe / WinNtThunk / Bus / WinNtBusDriver / WinNtBusDriver.c
... / ...
CommitLineData
1/*+++\r
2\r
3Copyright (c) 2006, 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#include "WinNtBusDriver.h"\r
101//#include "PciHostBridge.h"\r
102\r
103//\r
104// Define GUID for the WinNt Bus Driver\r
105//\r
106static EFI_GUID gWinNtBusDriverGuid = {\r
107 0x419f582, 0x625, 0x4531, 0x8a, 0x33, 0x85, 0xa9, 0x96, 0x5c, 0x95, 0xbc\r
108};\r
109\r
110//\r
111// DriverBinding protocol global\r
112//\r
113EFI_DRIVER_BINDING_PROTOCOL gWinNtBusDriverBinding = {\r
114 WinNtBusDriverBindingSupported,\r
115 WinNtBusDriverBindingStart,\r
116 WinNtBusDriverBindingStop,\r
117 0x10,\r
118 NULL,\r
119 NULL\r
120};\r
121\r
122#define NT_PCD_ARRAY_SIZE (sizeof(mPcdEnvironment)/sizeof(NT_PCD_ENTRY))\r
123\r
124//\r
125// Table to map NT Environment variable to the GUID that should be in\r
126// device path.\r
127//\r
128static NT_PCD_ENTRY mPcdEnvironment[] = {\r
129 PcdToken(PcdWinNtConsole), &gEfiWinNtConsoleGuid,\r
130 PcdToken(PcdWinNtUga), &gEfiWinNtUgaGuid,\r
131 PcdToken(PcdWinNtSerialPort), &gEfiWinNtSerialPortGuid,\r
132 PcdToken(PcdWinNtFileSystem), &gEfiWinNtFileSystemGuid,\r
133 PcdToken(PcdWinNtVirtualDisk), &gEfiWinNtVirtualDisksGuid,\r
134 PcdToken(PcdWinNtPhysicalDisk), &gEfiWinNtPhysicalDisksGuid,\r
135 PcdToken(PcdWinNtCpuModel), &gEfiWinNtCPUModelGuid,\r
136 PcdToken(PcdWinNtCpuSpeed), &gEfiWinNtCPUSpeedGuid,\r
137 PcdToken(PcdWinNtMemorySize), &gEfiWinNtMemoryGuid\r
138};\r
139\r
140VOID *\r
141AllocateMemory (\r
142 IN UINTN Size\r
143 )\r
144{\r
145 EFI_STATUS Status;\r
146 VOID *Buffer;\r
147\r
148 Status = gBS->AllocatePool (\r
149 EfiBootServicesData,\r
150 Size,\r
151 (VOID *)&Buffer\r
152 );\r
153 if (EFI_ERROR (Status)) {\r
154 ASSERT (FALSE);\r
155 return NULL;\r
156 }\r
157 return Buffer;\r
158}\r
159\r
160\r
161EFI_STATUS\r
162EFIAPI\r
163WinNtBusDriverBindingSupported (\r
164 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
165 IN EFI_HANDLE ControllerHandle,\r
166 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
167 )\r
168/*++\r
169\r
170Routine Description:\r
171\r
172Arguments:\r
173\r
174Returns:\r
175\r
176 None\r
177\r
178--*/\r
179// TODO: This - add argument and description to function comment\r
180// TODO: ControllerHandle - add argument and description to function comment\r
181// TODO: RemainingDevicePath - add argument and description to function comment\r
182// TODO: EFI_UNSUPPORTED - add return value to function comment\r
183// TODO: EFI_UNSUPPORTED - add return value to function comment\r
184// TODO: EFI_SUCCESS - add return value to function comment\r
185// TODO: EFI_SUCCESS - add return value to function comment\r
186{\r
187 EFI_STATUS Status;\r
188 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
189 EFI_WIN_NT_THUNK_PROTOCOL *WinNtThunk;\r
190 UINTN Index;\r
191\r
192 //\r
193 // Check the contents of the first Device Path Node of RemainingDevicePath to make sure\r
194 // it is a legal Device Path Node for this bus driver's children.\r
195 //\r
196 if (RemainingDevicePath != NULL) {\r
197 if (RemainingDevicePath->Type != HARDWARE_DEVICE_PATH ||\r
198 RemainingDevicePath->SubType != HW_VENDOR_DP ||\r
199 DevicePathNodeLength(RemainingDevicePath) != sizeof(WIN_NT_VENDOR_DEVICE_PATH_NODE)) {\r
200 return EFI_UNSUPPORTED;\r
201 }\r
202\r
203 for (Index = 0; Index < NT_PCD_ARRAY_SIZE; Index++) {\r
204 if (CompareGuid (&((VENDOR_DEVICE_PATH *) RemainingDevicePath)->Guid, mPcdEnvironment[Index].DevicePathGuid)) {\r
205 break;\r
206 }\r
207 }\r
208\r
209 if (Index >= NT_PCD_ARRAY_SIZE) {\r
210 return EFI_UNSUPPORTED;\r
211 }\r
212 }\r
213 \r
214 //\r
215 // Open the IO Abstraction(s) needed to perform the supported test\r
216 //\r
217 Status = gBS->OpenProtocol (\r
218 ControllerHandle,\r
219 &gEfiDevicePathProtocolGuid,\r
220 &ParentDevicePath,\r
221 This->DriverBindingHandle,\r
222 ControllerHandle,\r
223 EFI_OPEN_PROTOCOL_BY_DRIVER\r
224 );\r
225 if (Status == EFI_ALREADY_STARTED) {\r
226 return EFI_SUCCESS;\r
227 }\r
228\r
229 if (EFI_ERROR (Status)) {\r
230 return Status;\r
231 }\r
232\r
233 gBS->CloseProtocol (\r
234 ControllerHandle,\r
235 &gEfiDevicePathProtocolGuid,\r
236 This->DriverBindingHandle,\r
237 ControllerHandle\r
238 );\r
239\r
240 Status = gBS->OpenProtocol (\r
241 ControllerHandle,\r
242 &gEfiWinNtThunkProtocolGuid,\r
243 &WinNtThunk,\r
244 This->DriverBindingHandle,\r
245 ControllerHandle,\r
246 EFI_OPEN_PROTOCOL_BY_DRIVER\r
247 );\r
248 if (Status == EFI_ALREADY_STARTED) {\r
249 return EFI_SUCCESS;\r
250 }\r
251\r
252 if (EFI_ERROR (Status)) {\r
253 return Status;\r
254 }\r
255\r
256 //\r
257 // Since we call through WinNtThunk we need to make sure it's valid\r
258 //\r
259 Status = EFI_SUCCESS;\r
260 if (WinNtThunk->Signature != EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE) {\r
261 Status = EFI_UNSUPPORTED;\r
262 }\r
263\r
264 //\r
265 // Close the I/O Abstraction(s) used to perform the supported test\r
266 //\r
267 gBS->CloseProtocol (\r
268 ControllerHandle,\r
269 &gEfiWinNtThunkProtocolGuid,\r
270 This->DriverBindingHandle,\r
271 ControllerHandle\r
272 );\r
273\r
274 return Status;\r
275}\r
276\r
277EFI_STATUS\r
278EFIAPI\r
279WinNtBusDriverBindingStart (\r
280 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
281 IN EFI_HANDLE ControllerHandle,\r
282 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
283 )\r
284/*++\r
285\r
286Routine Description:\r
287\r
288Arguments:\r
289\r
290Returns:\r
291\r
292 None\r
293\r
294--*/\r
295// TODO: This - add argument and description to function comment\r
296// TODO: ControllerHandle - add argument and description to function comment\r
297// TODO: RemainingDevicePath - add argument and description to function comment\r
298// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment\r
299// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment\r
300// TODO: EFI_SUCCESS - add return value to function comment\r
301{\r
302 EFI_STATUS Status;\r
303 EFI_STATUS InstallStatus;\r
304 EFI_WIN_NT_THUNK_PROTOCOL *WinNtThunk;\r
305 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
306 WIN_NT_BUS_DEVICE *WinNtBusDevice;\r
307 WIN_NT_IO_DEVICE *WinNtDevice;\r
308 UINTN Index;\r
309 CHAR16 *StartString;\r
310 CHAR16 *SubString;\r
311 UINT16 Count;\r
312 UINTN StringSize;\r
313 UINT16 ComponentName[MAX_NT_ENVIRNMENT_VARIABLE_LENGTH];\r
314 WIN_NT_VENDOR_DEVICE_PATH_NODE *Node;\r
315 BOOLEAN CreateDevice;\r
316 CHAR16 *TempStr;\r
317 CHAR16 *PcdTempStr;\r
318 UINTN TempStrSize;\r
319\r
320 //\r
321 // Test Feature Set and Binary Patchable Case\r
322 //\r
323 if (FeaturePcdGet (PcdWinNtFeatureFlag1)) {\r
324 TempStrSize = PatchPcdGet32(PcdWinNtBinaryPatch1) + PatchPcdGet32(PcdWinNtBinaryPatch2);\r
325 }\r
326 \r
327 if (0) {\r
328 //\r
329 // Test Dynamic and DynamicEx \r
330 // (Please add PcdWinNtConsole in "WinNtBusDriver.inf" before enable this code!!!)\r
331 //\r
332 PcdTempStr = PcdGetPtr (PcdWinNtConsole);\r
333 }\r
334\r
335 //\r
336 // Test Dynamic Set and Dynamic Set Ex\r
337 //\r
338 PcdSet32 (PcdWinNtDynamicUINT32, 2006);\r
339\r
340 Status = EFI_UNSUPPORTED;\r
341\r
342 //\r
343 // Grab the protocols we need\r
344 //\r
345 Status = gBS->OpenProtocol (\r
346 ControllerHandle,\r
347 &gEfiDevicePathProtocolGuid,\r
348 &ParentDevicePath,\r
349 This->DriverBindingHandle,\r
350 ControllerHandle,\r
351 EFI_OPEN_PROTOCOL_BY_DRIVER\r
352 );\r
353 if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
354 return Status;\r
355 }\r
356\r
357 Status = gBS->OpenProtocol (\r
358 ControllerHandle,\r
359 &gEfiWinNtThunkProtocolGuid,\r
360 &WinNtThunk,\r
361 This->DriverBindingHandle,\r
362 ControllerHandle,\r
363 EFI_OPEN_PROTOCOL_BY_DRIVER\r
364 );\r
365 if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
366 return Status;\r
367 }\r
368\r
369 if (Status != EFI_ALREADY_STARTED) {\r
370 Status = gBS->AllocatePool (\r
371 EfiBootServicesData,\r
372 sizeof (WIN_NT_BUS_DEVICE),\r
373 (VOID *) &WinNtBusDevice\r
374 );\r
375 if (EFI_ERROR (Status)) {\r
376 return Status;\r
377 }\r
378\r
379 WinNtBusDevice->Signature = WIN_NT_BUS_DEVICE_SIGNATURE;\r
380 WinNtBusDevice->ControllerNameTable = NULL;\r
381\r
382 AddUnicodeString (\r
383 "eng",\r
384 gWinNtBusDriverComponentName.SupportedLanguages,\r
385 &WinNtBusDevice->ControllerNameTable,\r
386 L"Windows Bus Controller"\r
387 );\r
388\r
389 Status = gBS->InstallMultipleProtocolInterfaces (\r
390 &ControllerHandle,\r
391 &gWinNtBusDriverGuid,\r
392 WinNtBusDevice,\r
393 NULL\r
394 );\r
395 if (EFI_ERROR (Status)) {\r
396 FreeUnicodeStringTable (WinNtBusDevice->ControllerNameTable);\r
397 gBS->FreePool (WinNtBusDevice);\r
398 return Status;\r
399 }\r
400 }\r
401\r
402 //\r
403 // Loop on the Variable list. Parse each variable to produce a set of handles that\r
404 // represent virtual hardware devices.\r
405 //\r
406 InstallStatus = EFI_NOT_FOUND;\r
407 for (Index = 0; Index < NT_PCD_ARRAY_SIZE; Index++) {\r
408 PcdTempStr = (VOID *)LibPcdGetPtr (mPcdEnvironment[Index].Token);\r
409 ASSERT (PcdTempStr != NULL);\r
410\r
411 TempStrSize = StrLen (PcdTempStr);\r
412 TempStr = AllocateMemory ((TempStrSize * sizeof (CHAR16)) + 1);\r
413 StrCpy (TempStr, PcdTempStr);\r
414\r
415 StartString = TempStr;\r
416\r
417 //\r
418 // Parse the envirnment variable into sub strings using '!' as a delimator.\r
419 // Each substring needs it's own handle to be added to the system. This code\r
420 // does not understand the sub string. Thats the device drivers job.\r
421 //\r
422 Count = 0;\r
423 while (*StartString != '\0') {\r
424\r
425 //\r
426 // Find the end of the sub string\r
427 //\r
428 SubString = StartString;\r
429 while (*SubString != '\0' && *SubString != '!') {\r
430 SubString++;\r
431 }\r
432\r
433 if (*SubString == '!') {\r
434 //\r
435 // Replace token with '\0' to make sub strings. If this is the end\r
436 // of the string SubString will already point to NULL.\r
437 //\r
438 *SubString = '\0';\r
439 SubString++;\r
440 }\r
441\r
442 CreateDevice = TRUE;\r
443 if (RemainingDevicePath != NULL) {\r
444 CreateDevice = FALSE;\r
445 Node = (WIN_NT_VENDOR_DEVICE_PATH_NODE *) RemainingDevicePath;\r
446 if (Node->VendorDevicePath.Header.Type == HARDWARE_DEVICE_PATH &&\r
447 Node->VendorDevicePath.Header.SubType == HW_VENDOR_DP &&\r
448 DevicePathNodeLength (&Node->VendorDevicePath.Header) == sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE)\r
449 ) {\r
450 if (CompareGuid (&Node->VendorDevicePath.Guid, mPcdEnvironment[Index].DevicePathGuid) &&\r
451 Node->Instance == Count\r
452 ) {\r
453 CreateDevice = TRUE;\r
454 }\r
455 }\r
456 }\r
457\r
458 if (CreateDevice) {\r
459\r
460 //\r
461 // Allocate instance structure, and fill in parent information.\r
462 //\r
463 WinNtDevice = AllocateMemory (sizeof (WIN_NT_IO_DEVICE));\r
464 if (WinNtDevice == NULL) {\r
465 return EFI_OUT_OF_RESOURCES;\r
466 }\r
467\r
468 WinNtDevice->Handle = NULL;\r
469 WinNtDevice->ControllerHandle = ControllerHandle;\r
470 WinNtDevice->ParentDevicePath = ParentDevicePath;\r
471\r
472 WinNtDevice->WinNtIo.WinNtThunk = WinNtThunk;\r
473\r
474 //\r
475 // Plus 2 to account for the NULL at the end of the Unicode string\r
476 //\r
477 StringSize = (UINTN) ((UINT8 *) SubString - (UINT8 *) StartString) + sizeof (CHAR16);\r
478 WinNtDevice->WinNtIo.EnvString = AllocateMemory (StringSize);\r
479 if (WinNtDevice->WinNtIo.EnvString != NULL) {\r
480 CopyMem (WinNtDevice->WinNtIo.EnvString, StartString, StringSize);\r
481 }\r
482\r
483 WinNtDevice->ControllerNameTable = NULL;\r
484\r
485 WinNtThunk->SPrintf (ComponentName, L"%s", WinNtDevice->WinNtIo.EnvString);\r
486\r
487 WinNtDevice->DevicePath = WinNtBusCreateDevicePath (\r
488 ParentDevicePath,\r
489 mPcdEnvironment[Index].DevicePathGuid,\r
490 Count\r
491 );\r
492 if (WinNtDevice->DevicePath == NULL) {\r
493 gBS->FreePool (WinNtDevice);\r
494 return EFI_OUT_OF_RESOURCES;\r
495 }\r
496\r
497 AddUnicodeString (\r
498 "eng",\r
499 gWinNtBusDriverComponentName.SupportedLanguages,\r
500 &WinNtDevice->ControllerNameTable,\r
501 ComponentName\r
502 );\r
503\r
504 WinNtDevice->WinNtIo.TypeGuid = mPcdEnvironment[Index].DevicePathGuid;\r
505 WinNtDevice->WinNtIo.InstanceNumber = Count;\r
506\r
507 WinNtDevice->Signature = WIN_NT_IO_DEVICE_SIGNATURE;\r
508\r
509 Status = gBS->InstallMultipleProtocolInterfaces (\r
510 &WinNtDevice->Handle,\r
511 &gEfiDevicePathProtocolGuid,\r
512 WinNtDevice->DevicePath,\r
513 &gEfiWinNtIoProtocolGuid,\r
514 &WinNtDevice->WinNtIo,\r
515 NULL\r
516 );\r
517 if (EFI_ERROR (Status)) {\r
518 FreeUnicodeStringTable (WinNtDevice->ControllerNameTable);\r
519 gBS->FreePool (WinNtDevice);\r
520 } else {\r
521 //\r
522 // Open For Child Device\r
523 //\r
524 Status = gBS->OpenProtocol (\r
525 ControllerHandle,\r
526 &gEfiWinNtThunkProtocolGuid,\r
527 &WinNtThunk,\r
528 This->DriverBindingHandle,\r
529 WinNtDevice->Handle,\r
530 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
531 );\r
532 if (!EFI_ERROR (Status)) {\r
533 InstallStatus = EFI_SUCCESS;\r
534 }\r
535 }\r
536 }\r
537\r
538 //\r
539 // Parse Next sub string. This will point to '\0' if we are at the end.\r
540 //\r
541 Count++;\r
542 StartString = SubString;\r
543 }\r
544\r
545 gBS->FreePool (TempStr);\r
546 }\r
547\r
548 return EFI_SUCCESS;\r
549}\r
550\r
551\r
552EFI_STATUS\r
553EFIAPI\r
554WinNtBusDriverBindingStop (\r
555 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
556 IN EFI_HANDLE ControllerHandle,\r
557 IN UINTN NumberOfChildren,\r
558 IN EFI_HANDLE *ChildHandleBuffer\r
559 )\r
560/*++\r
561\r
562Routine Description:\r
563\r
564Arguments:\r
565\r
566Returns:\r
567\r
568 None\r
569\r
570--*/\r
571// TODO: This - add argument and description to function comment\r
572// TODO: ControllerHandle - add argument and description to function comment\r
573// TODO: NumberOfChildren - add argument and description to function comment\r
574// TODO: ChildHandleBuffer - add argument and description to function comment\r
575// TODO: EFI_SUCCESS - add return value to function comment\r
576// TODO: EFI_DEVICE_ERROR - add return value to function comment\r
577// TODO: EFI_SUCCESS - add return value to function comment\r
578{\r
579 EFI_STATUS Status;\r
580 UINTN Index;\r
581 BOOLEAN AllChildrenStopped;\r
582 EFI_WIN_NT_IO_PROTOCOL *WinNtIo;\r
583 WIN_NT_BUS_DEVICE *WinNtBusDevice;\r
584 WIN_NT_IO_DEVICE *WinNtDevice;\r
585 EFI_WIN_NT_THUNK_PROTOCOL *WinNtThunk;\r
586\r
587 //\r
588 // Complete all outstanding transactions to Controller.\r
589 // Don't allow any new transaction to Controller to be started.\r
590 //\r
591\r
592 if (NumberOfChildren == 0) {\r
593 //\r
594 // Close the bus driver\r
595 //\r
596 Status = gBS->OpenProtocol (\r
597 ControllerHandle,\r
598 &gWinNtBusDriverGuid,\r
599 &WinNtBusDevice,\r
600 This->DriverBindingHandle,\r
601 ControllerHandle,\r
602 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
603 );\r
604 if (EFI_ERROR (Status)) {\r
605 return Status;\r
606 }\r
607\r
608 gBS->UninstallMultipleProtocolInterfaces (\r
609 ControllerHandle,\r
610 &gWinNtBusDriverGuid,\r
611 WinNtBusDevice,\r
612 NULL\r
613 );\r
614\r
615 FreeUnicodeStringTable (WinNtBusDevice->ControllerNameTable);\r
616\r
617 gBS->FreePool (WinNtBusDevice);\r
618\r
619 gBS->CloseProtocol (\r
620 ControllerHandle,\r
621 &gEfiWinNtThunkProtocolGuid,\r
622 This->DriverBindingHandle,\r
623 ControllerHandle\r
624 );\r
625\r
626 gBS->CloseProtocol (\r
627 ControllerHandle,\r
628 &gEfiDevicePathProtocolGuid,\r
629 This->DriverBindingHandle,\r
630 ControllerHandle\r
631 );\r
632 return EFI_SUCCESS;\r
633 }\r
634\r
635 AllChildrenStopped = TRUE;\r
636\r
637 for (Index = 0; Index < NumberOfChildren; Index++) {\r
638\r
639 Status = gBS->OpenProtocol (\r
640 ChildHandleBuffer[Index],\r
641 &gEfiWinNtIoProtocolGuid,\r
642 &WinNtIo,\r
643 This->DriverBindingHandle,\r
644 ControllerHandle,\r
645 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
646 );\r
647 if (!EFI_ERROR (Status)) {\r
648\r
649 WinNtDevice = WIN_NT_IO_DEVICE_FROM_THIS (WinNtIo);\r
650\r
651 Status = gBS->CloseProtocol (\r
652 ControllerHandle,\r
653 &gEfiWinNtThunkProtocolGuid,\r
654 This->DriverBindingHandle,\r
655 WinNtDevice->Handle\r
656 );\r
657\r
658 Status = gBS->UninstallMultipleProtocolInterfaces (\r
659 WinNtDevice->Handle,\r
660 &gEfiDevicePathProtocolGuid,\r
661 WinNtDevice->DevicePath,\r
662 &gEfiWinNtIoProtocolGuid,\r
663 &WinNtDevice->WinNtIo,\r
664 NULL\r
665 );\r
666\r
667 if (EFI_ERROR (Status)) {\r
668 gBS->OpenProtocol (\r
669 ControllerHandle,\r
670 &gEfiWinNtThunkProtocolGuid,\r
671 (VOID **) &WinNtThunk,\r
672 This->DriverBindingHandle,\r
673 WinNtDevice->Handle,\r
674 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
675 );\r
676 } else {\r
677 //\r
678 // Close the child handle\r
679 //\r
680 FreeUnicodeStringTable (WinNtDevice->ControllerNameTable);\r
681 gBS->FreePool (WinNtDevice);\r
682 }\r
683 }\r
684\r
685 if (EFI_ERROR (Status)) {\r
686 AllChildrenStopped = FALSE;\r
687 }\r
688 }\r
689\r
690 if (!AllChildrenStopped) {\r
691 return EFI_DEVICE_ERROR;\r
692 }\r
693\r
694 return EFI_SUCCESS;\r
695}\r
696\r
697EFI_DEVICE_PATH_PROTOCOL *\r
698WinNtBusCreateDevicePath (\r
699 IN EFI_DEVICE_PATH_PROTOCOL *RootDevicePath,\r
700 IN EFI_GUID *Guid,\r
701 IN UINT16 InstanceNumber\r
702 )\r
703/*++\r
704\r
705Routine Description:\r
706 Create a device path node using Guid and InstanceNumber and append it to\r
707 the passed in RootDevicePath\r
708\r
709Arguments:\r
710 RootDevicePath - Root of the device path to return.\r
711\r
712 Guid - GUID to use in vendor device path node.\r
713\r
714 InstanceNumber - Instance number to use in the vendor device path. This\r
715 argument is needed to make sure each device path is unique.\r
716\r
717Returns:\r
718\r
719 EFI_DEVICE_PATH_PROTOCOL \r
720\r
721--*/\r
722{\r
723 WIN_NT_VENDOR_DEVICE_PATH_NODE DevicePath;\r
724\r
725 DevicePath.VendorDevicePath.Header.Type = HARDWARE_DEVICE_PATH;\r
726 DevicePath.VendorDevicePath.Header.SubType = HW_VENDOR_DP;\r
727 SetDevicePathNodeLength (&DevicePath.VendorDevicePath.Header, sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE));\r
728\r
729 //\r
730 // The GUID defines the Class\r
731 //\r
732 CopyMem (&DevicePath.VendorDevicePath.Guid, Guid, sizeof (EFI_GUID));\r
733\r
734 //\r
735 // Add an instance number so we can make sure there are no Device Path\r
736 // duplication.\r
737 //\r
738 DevicePath.Instance = InstanceNumber;\r
739\r
740 return AppendDevicePathNode (\r
741 RootDevicePath,\r
742 (EFI_DEVICE_PATH_PROTOCOL *) &DevicePath\r
743 );\r
744}\r