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