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