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