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