]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Nt32Pkg/WinNtBusDriverDxe/WinNtBusDriver.c
BaseTools: AutoGen - clean up access
[mirror_edk2.git] / Nt32Pkg / WinNtBusDriverDxe / WinNtBusDriver.c
... / ...
CommitLineData
1/**@file\r
2\r
3Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
4(C) Copyright 2018 Hewlett Packard Enterprise Development LP<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13Module Name:\r
14\r
15 WinNtBusDriver.c\r
16\r
17Abstract:\r
18\r
19This following section documents the envirnoment variables for the Win NT\r
20build. These variables are used to define the (virtual) hardware\r
21configuration of the NT environment\r
22\r
23A ! can be used to seperate multiple instances in a variable. Each\r
24instance represents a seperate hardware device.\r
25\r
26EFI_WIN_NT_PHYSICAL_DISKS - maps to drives on your system\r
27EFI_WIN_NT_VIRTUAL_DISKS - maps to a device emulated by a file\r
28EFI_WIN_NT_FILE_SYSTEM - mouts a directory as a file system\r
29EFI_WIN_NT_CONSOLE - make a logical comand line window (only one!)\r
30EFI_WIN_NT_GOP - Builds GOP Windows of Width and Height\r
31EFI_WIN_NT_SERIAL_PORT - maps physical serial ports\r
32\r
33 <F>ixed - Fixed disk like a hard drive.\r
34 <R>emovable - Removable media like a floppy or CD-ROM.\r
35 Read <O>nly - Write protected device.\r
36 Read <W>rite - Read write device.\r
37 <block count> - Decimal number of blocks a device supports.\r
38 <block size> - Decimal number of bytes per block.\r
39\r
40 NT envirnonment variable contents. '<' and '>' are not part of the variable,\r
41 they are just used to make this help more readable. There should be no\r
42 spaces between the ';'. Extra spaces will break the variable. A '!' is\r
43 used to seperate multiple devices in a variable.\r
44\r
45 EFI_WIN_NT_VIRTUAL_DISKS =\r
46 <F | R><O | W>;<block count>;<block size>[!...]\r
47\r
48 EFI_WIN_NT_PHYSICAL_DISKS =\r
49 <drive letter>:<F | R><O | W>;<block count>;<block size>[!...]\r
50\r
51 Virtual Disks: These devices use a file to emulate a hard disk or removable\r
52 media device.\r
53\r
54 Thus a 20 MB emulated hard drive would look like:\r
55 EFI_WIN_NT_VIRTUAL_DISKS=FW;40960;512\r
56\r
57 A 1.44MB emulated floppy with a block size of 1024 would look like:\r
58 EFI_WIN_NT_VIRTUAL_DISKS=RW;1440;1024\r
59\r
60 Physical Disks: These devices use NT to open a real device in your system\r
61\r
62 Thus a 120 MB floppy would look like:\r
63 EFI_WIN_NT_PHYSICAL_DISKS=B:RW;245760;512\r
64\r
65 Thus a standard CD-ROM floppy would look like:\r
66 EFI_WIN_NT_PHYSICAL_DISKS=Z:RO;307200;2048\r
67\r
68 EFI_WIN_NT_FILE_SYSTEM =\r
69 <directory path>[!...]\r
70\r
71 Mounting the two directories C:\FOO and C:\BAR would look like:\r
72 EFI_WIN_NT_FILE_SYSTEM=c:\foo!c:\bar\r
73\r
74 EFI_WIN_NT_CONSOLE =\r
75 <window title>\r
76\r
77 Declaring a text console window with the title "My EFI Console" woild look like:\r
78 EFI_WIN_NT_CONSOLE=My EFI Console\r
79\r
80 EFI_WIN_NT_GOP =\r
81 <width> <height>[!...]\r
82\r
83 Declaring a two GOP windows with resolutions of 800x600 and 1024x768 would look like:\r
84 Example : EFI_WIN_NT_GOP=800 600!1024 768\r
85\r
86 EFI_WIN_NT_SERIAL_PORT =\r
87 <port name>[!...]\r
88\r
89 Declaring two serial ports on COM1 and COM2 would look like:\r
90 Example : EFI_WIN_NT_SERIAL_PORT=COM1!COM2\r
91\r
92 EFI_WIN_NT_PASS_THROUGH =\r
93 <BaseAddress>;<Bus#>;<Device#>;<Function#>\r
94\r
95 Declaring a base address of 0xE0000000 (used for PCI Express devices)\r
96 and having NT32 talk to a device located at bus 0, device 1, function 0:\r
97 Example : EFI_WIN_NT_PASS_THROUGH=E000000;0;1;0\r
98\r
99---*/\r
100\r
101//\r
102// The package level header files this module uses\r
103//\r
104#include <Uefi.h>\r
105#include <WinNtDxe.h>\r
106//\r
107// The protocols, PPI and GUID defintions for this module\r
108//\r
109#include <Protocol/WinNtThunk.h>\r
110#include <Protocol/WinNtIo.h>\r
111#include <Protocol/ComponentName.h>\r
112#include <Protocol/DriverBinding.h>\r
113#include <Protocol/DevicePath.h>\r
114//\r
115// The Library classes this module consumes\r
116//\r
117#include <Library/DebugLib.h>\r
118#include <Library/BaseLib.h>\r
119#include <Library/UefiDriverEntryPoint.h>\r
120#include <Library/UefiLib.h>\r
121#include <Library/PcdLib.h>\r
122#include <Library/BaseMemoryLib.h>\r
123#include <Library/UefiBootServicesTableLib.h>\r
124#include <Library/DevicePathLib.h>\r
125#include <Library/MemoryAllocationLib.h>\r
126\r
127#include "WinNtBusDriver.h"\r
128\r
129extern EFI_GUID gWinNtBusDriverGuid;\r
130//\r
131// DriverBinding protocol global\r
132//\r
133EFI_DRIVER_BINDING_PROTOCOL gWinNtBusDriverBinding = {\r
134 WinNtBusDriverBindingSupported,\r
135 WinNtBusDriverBindingStart,\r
136 WinNtBusDriverBindingStop,\r
137 0xa,\r
138 NULL,\r
139 NULL\r
140};\r
141\r
142#define NT_PCD_ARRAY_SIZE (sizeof(mPcdEnvironment)/sizeof(NT_PCD_ENTRY))\r
143\r
144//\r
145// Table to map NT Environment variable to the GUID that should be in\r
146// device path.\r
147//\r
148NT_PCD_ENTRY mPcdEnvironment[] = {\r
149 PcdToken(PcdWinNtConsole), &gEfiWinNtConsoleGuid,\r
150 PcdToken(PcdWinNtGop), &gEfiWinNtGopGuid,\r
151 PcdToken(PcdWinNtSerialPort), &gEfiWinNtSerialPortGuid,\r
152 PcdToken(PcdWinNtFileSystem), &gEfiWinNtFileSystemGuid,\r
153 PcdToken(PcdWinNtVirtualDisk), &gEfiWinNtVirtualDisksGuid,\r
154 PcdToken(PcdWinNtPhysicalDisk), &gEfiWinNtPhysicalDisksGuid\r
155};\r
156\r
157/**\r
158 The user Entry Point for module WinNtBusDriver. The user code starts with this function.\r
159\r
160 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
161 @param[in] SystemTable A pointer to the EFI System Table.\r
162\r
163 @retval EFI_SUCCESS The entry point is executed successfully.\r
164 @retval other Some error occurs when executing this entry point.\r
165\r
166**/\r
167EFI_STATUS\r
168EFIAPI\r
169InitializeWinNtBusDriver(\r
170 IN EFI_HANDLE ImageHandle,\r
171 IN EFI_SYSTEM_TABLE *SystemTable\r
172 )\r
173{\r
174 EFI_STATUS Status;\r
175\r
176 //\r
177 // Install driver model protocol(s).\r
178 //\r
179 Status = EfiLibInstallDriverBindingComponentName2 (\r
180 ImageHandle,\r
181 SystemTable,\r
182 &gWinNtBusDriverBinding,\r
183 ImageHandle,\r
184 &gWinNtBusDriverComponentName,\r
185 &gWinNtBusDriverComponentName2\r
186 );\r
187 ASSERT_EFI_ERROR (Status);\r
188\r
189\r
190 return Status;\r
191}\r
192\r
193VOID *\r
194AllocateMemory (\r
195 IN UINTN Size\r
196 )\r
197{\r
198 VOID *Buffer;\r
199\r
200 Buffer = AllocatePool (Size);\r
201 ASSERT (Buffer != NULL);\r
202\r
203 return Buffer;\r
204}\r
205\r
206\r
207EFI_STATUS\r
208EFIAPI\r
209WinNtBusDriverBindingSupported (\r
210 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
211 IN EFI_HANDLE ControllerHandle,\r
212 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
213 )\r
214/*++\r
215\r
216Routine Description:\r
217\r
218Arguments:\r
219\r
220Returns:\r
221\r
222 None\r
223\r
224**/\r
225// TODO: This - add argument and description to function comment\r
226// TODO: ControllerHandle - add argument and description to function comment\r
227// TODO: RemainingDevicePath - add argument and description to function comment\r
228// TODO: EFI_UNSUPPORTED - add return value to function comment\r
229// TODO: EFI_UNSUPPORTED - add return value to function comment\r
230// TODO: EFI_SUCCESS - add return value to function comment\r
231// TODO: EFI_SUCCESS - add return value to function comment\r
232{\r
233 EFI_STATUS Status;\r
234 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
235 EFI_WIN_NT_THUNK_PROTOCOL *WinNtThunk;\r
236 UINTN Index;\r
237\r
238 //\r
239 // Check the contents of the first Device Path Node of RemainingDevicePath to make sure\r
240 // it is a legal Device Path Node for this bus driver's children.\r
241 //\r
242 if (RemainingDevicePath != NULL) {\r
243 //\r
244 // Check if RemainingDevicePath is the End of Device Path Node, \r
245 // if yes, go on checking other conditions\r
246 //\r
247 if (!IsDevicePathEnd (RemainingDevicePath)) {\r
248 //\r
249 // If RemainingDevicePath isn't the End of Device Path Node,\r
250 // check its validation\r
251 //\r
252 if (RemainingDevicePath->Type != HARDWARE_DEVICE_PATH ||\r
253 RemainingDevicePath->SubType != HW_VENDOR_DP ||\r
254 DevicePathNodeLength(RemainingDevicePath) != sizeof(WIN_NT_VENDOR_DEVICE_PATH_NODE)) {\r
255 return EFI_UNSUPPORTED;\r
256 }\r
257 \r
258 for (Index = 0; Index < NT_PCD_ARRAY_SIZE; Index++) {\r
259 if (CompareGuid (&((VENDOR_DEVICE_PATH *) RemainingDevicePath)->Guid, mPcdEnvironment[Index].DevicePathGuid)) {\r
260 break;\r
261 }\r
262 }\r
263 \r
264 if (Index >= NT_PCD_ARRAY_SIZE) {\r
265 return EFI_UNSUPPORTED;\r
266 }\r
267 }\r
268 }\r
269\r
270 //\r
271 // Open the IO Abstraction(s) needed to perform the supported test\r
272 //\r
273 Status = gBS->OpenProtocol (\r
274 ControllerHandle,\r
275 &gEfiWinNtThunkProtocolGuid,\r
276 (VOID **) &WinNtThunk,\r
277 This->DriverBindingHandle,\r
278 ControllerHandle,\r
279 EFI_OPEN_PROTOCOL_BY_DRIVER\r
280 );\r
281 if (Status == EFI_ALREADY_STARTED) {\r
282 return EFI_SUCCESS;\r
283 }\r
284\r
285 if (EFI_ERROR (Status)) {\r
286 return Status;\r
287 }\r
288\r
289 //\r
290 // Close the I/O Abstraction(s) used to perform the supported test\r
291 //\r
292 gBS->CloseProtocol (\r
293 ControllerHandle,\r
294 &gEfiWinNtThunkProtocolGuid,\r
295 This->DriverBindingHandle,\r
296 ControllerHandle\r
297 );\r
298\r
299 //\r
300 // Open the EFI Device Path protocol needed to perform the supported test\r
301 //\r
302 Status = gBS->OpenProtocol (\r
303 ControllerHandle,\r
304 &gEfiDevicePathProtocolGuid,\r
305 (VOID **) &ParentDevicePath,\r
306 This->DriverBindingHandle,\r
307 ControllerHandle,\r
308 EFI_OPEN_PROTOCOL_BY_DRIVER\r
309 );\r
310 if (Status == EFI_ALREADY_STARTED) {\r
311 return EFI_SUCCESS;\r
312 }\r
313\r
314 if (EFI_ERROR (Status)) {\r
315 return Status;\r
316 }\r
317\r
318 //\r
319 // Since we call through WinNtThunk we need to make sure it's valid\r
320 //\r
321 Status = EFI_SUCCESS;\r
322 if (WinNtThunk->Signature != EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE) {\r
323 Status = EFI_UNSUPPORTED;\r
324 }\r
325\r
326 //\r
327 // Close protocol, don't use device path protocol in the Support() function\r
328 //\r
329 gBS->CloseProtocol (\r
330 ControllerHandle,\r
331 &gEfiDevicePathProtocolGuid,\r
332 This->DriverBindingHandle,\r
333 ControllerHandle\r
334 );\r
335\r
336 return Status;\r
337}\r
338\r
339EFI_STATUS\r
340EFIAPI\r
341WinNtBusDriverBindingStart (\r
342 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
343 IN EFI_HANDLE ControllerHandle,\r
344 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
345 )\r
346/*++\r
347\r
348Routine Description:\r
349\r
350Arguments:\r
351\r
352Returns:\r
353\r
354 None\r
355\r
356--*/\r
357// TODO: This - add argument and description to function comment\r
358// TODO: ControllerHandle - add argument and description to function comment\r
359// TODO: RemainingDevicePath - add argument and description to function comment\r
360// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment\r
361// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment\r
362// TODO: EFI_SUCCESS - add return value to function comment\r
363{\r
364 EFI_STATUS Status;\r
365 EFI_WIN_NT_THUNK_PROTOCOL *WinNtThunk;\r
366 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
367 WIN_NT_BUS_DEVICE *WinNtBusDevice;\r
368 WIN_NT_IO_DEVICE *WinNtDevice;\r
369 UINTN Index;\r
370 CHAR16 *StartString;\r
371 CHAR16 *SubString;\r
372 UINT16 Count;\r
373 UINTN StringSize;\r
374 UINT16 ComponentName[MAX_NT_ENVIRNMENT_VARIABLE_LENGTH];\r
375 WIN_NT_VENDOR_DEVICE_PATH_NODE *Node;\r
376 BOOLEAN CreateDevice;\r
377 CHAR16 *TempStr;\r
378 CHAR16 *PcdTempStr;\r
379 UINTN TempStrSize;\r
380\r
381 Status = EFI_UNSUPPORTED;\r
382\r
383 //\r
384 // Grab the protocols we need\r
385 //\r
386 Status = gBS->OpenProtocol (\r
387 ControllerHandle,\r
388 &gEfiDevicePathProtocolGuid,\r
389 (VOID **) &ParentDevicePath,\r
390 This->DriverBindingHandle,\r
391 ControllerHandle,\r
392 EFI_OPEN_PROTOCOL_BY_DRIVER\r
393 );\r
394 if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
395 return Status;\r
396 }\r
397\r
398 Status = gBS->OpenProtocol (\r
399 ControllerHandle,\r
400 &gEfiWinNtThunkProtocolGuid,\r
401 (VOID **) &WinNtThunk,\r
402 This->DriverBindingHandle,\r
403 ControllerHandle,\r
404 EFI_OPEN_PROTOCOL_BY_DRIVER\r
405 );\r
406 if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
407 return Status;\r
408 }\r
409\r
410 if (Status != EFI_ALREADY_STARTED) {\r
411 WinNtBusDevice = AllocatePool (sizeof (WIN_NT_BUS_DEVICE));\r
412 if (WinNtBusDevice == NULL) {\r
413 return EFI_OUT_OF_RESOURCES;\r
414 }\r
415\r
416 WinNtBusDevice->Signature = WIN_NT_BUS_DEVICE_SIGNATURE;\r
417 WinNtBusDevice->ControllerNameTable = NULL;\r
418\r
419 AddUnicodeString2 (\r
420 "eng",\r
421 gWinNtBusDriverComponentName.SupportedLanguages,\r
422 &WinNtBusDevice->ControllerNameTable,\r
423 L"Windows Bus Controller",\r
424 TRUE\r
425 );\r
426 AddUnicodeString2 (\r
427 "en",\r
428 gWinNtBusDriverComponentName2.SupportedLanguages,\r
429 &WinNtBusDevice->ControllerNameTable,\r
430 L"Windows Bus Controller",\r
431 FALSE\r
432 );\r
433\r
434\r
435 Status = gBS->InstallMultipleProtocolInterfaces (\r
436 &ControllerHandle,\r
437 &gWinNtBusDriverGuid,\r
438 WinNtBusDevice,\r
439 NULL\r
440 );\r
441 if (EFI_ERROR (Status)) {\r
442 FreeUnicodeStringTable (WinNtBusDevice->ControllerNameTable);\r
443 FreePool (WinNtBusDevice);\r
444 return Status;\r
445 }\r
446 }\r
447\r
448 //\r
449 // Loop on the Variable list. Parse each variable to produce a set of handles that\r
450 // represent virtual hardware devices.\r
451 //\r
452 for (Index = 0; Index < NT_PCD_ARRAY_SIZE; Index++) {\r
453 PcdTempStr = (VOID *)LibPcdGetPtr (mPcdEnvironment[Index].Token);\r
454 ASSERT (PcdTempStr != NULL);\r
455\r
456 TempStrSize = StrLen (PcdTempStr);\r
457 TempStr = AllocateMemory (((TempStrSize + 1) * sizeof (CHAR16)));\r
458 StrCpy (TempStr, PcdTempStr);\r
459\r
460 StartString = TempStr;\r
461\r
462 //\r
463 // Parse the envirnment variable into sub strings using '!' as a delimator.\r
464 // Each substring needs it's own handle to be added to the system. This code\r
465 // does not understand the sub string. Thats the device drivers job.\r
466 //\r
467 Count = 0;\r
468 while (*StartString != '\0') {\r
469\r
470 //\r
471 // Find the end of the sub string\r
472 //\r
473 SubString = StartString;\r
474 while (*SubString != '\0' && *SubString != '!') {\r
475 SubString++;\r
476 }\r
477\r
478 if (*SubString == '!') {\r
479 //\r
480 // Replace token with '\0' to make sub strings. If this is the end\r
481 // of the string SubString will already point to NULL.\r
482 //\r
483 *SubString = '\0';\r
484 SubString++;\r
485 }\r
486\r
487 CreateDevice = TRUE;\r
488 if (RemainingDevicePath != NULL) {\r
489 CreateDevice = FALSE;\r
490 //\r
491 // Check if RemainingDevicePath is the End of Device Path Node, \r
492 // if yes, don't create any child device \r
493 //\r
494 if (!IsDevicePathEnd (RemainingDevicePath)) {\r
495 //\r
496 // If RemainingDevicePath isn't the End of Device Path Node,\r
497 // check its validation\r
498 //\r
499 Node = (WIN_NT_VENDOR_DEVICE_PATH_NODE *) RemainingDevicePath;\r
500 if (Node->VendorDevicePath.Header.Type == HARDWARE_DEVICE_PATH &&\r
501 Node->VendorDevicePath.Header.SubType == HW_VENDOR_DP &&\r
502 DevicePathNodeLength (&Node->VendorDevicePath.Header) == sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE)\r
503 ) {\r
504 if (CompareGuid (&Node->VendorDevicePath.Guid, mPcdEnvironment[Index].DevicePathGuid) &&\r
505 Node->Instance == Count\r
506 ) {\r
507 CreateDevice = TRUE;\r
508 }\r
509 }\r
510 }\r
511 }\r
512\r
513 if (CreateDevice) {\r
514\r
515 //\r
516 // Allocate instance structure, and fill in parent information.\r
517 //\r
518 WinNtDevice = AllocateMemory (sizeof (WIN_NT_IO_DEVICE));\r
519 if (WinNtDevice == NULL) {\r
520 return EFI_OUT_OF_RESOURCES;\r
521 }\r
522\r
523 WinNtDevice->Handle = NULL;\r
524 WinNtDevice->ControllerHandle = ControllerHandle;\r
525 WinNtDevice->ParentDevicePath = ParentDevicePath;\r
526\r
527 WinNtDevice->WinNtIo.WinNtThunk = WinNtThunk;\r
528\r
529 //\r
530 // Plus 2 to account for the NULL at the end of the Unicode string\r
531 //\r
532 StringSize = (UINTN) ((UINT8 *) SubString - (UINT8 *) StartString) + sizeof (CHAR16);\r
533 WinNtDevice->WinNtIo.EnvString = AllocateMemory (StringSize);\r
534 if (WinNtDevice->WinNtIo.EnvString != NULL) {\r
535 CopyMem (WinNtDevice->WinNtIo.EnvString, StartString, StringSize);\r
536 }\r
537\r
538 WinNtDevice->ControllerNameTable = NULL;\r
539\r
540 WinNtThunk->SPrintf (ComponentName, sizeof (ComponentName), L"%s", WinNtDevice->WinNtIo.EnvString);\r
541\r
542 WinNtDevice->DevicePath = WinNtBusCreateDevicePath (\r
543 ParentDevicePath,\r
544 mPcdEnvironment[Index].DevicePathGuid,\r
545 Count\r
546 );\r
547 if (WinNtDevice->DevicePath == NULL) {\r
548 FreePool (WinNtDevice);\r
549 return EFI_OUT_OF_RESOURCES;\r
550 }\r
551\r
552 AddUnicodeString2 (\r
553 "eng",\r
554 gWinNtBusDriverComponentName.SupportedLanguages,\r
555 &WinNtDevice->ControllerNameTable,\r
556 ComponentName,\r
557 TRUE\r
558 );\r
559 AddUnicodeString2 (\r
560 "en",\r
561 gWinNtBusDriverComponentName2.SupportedLanguages,\r
562 &WinNtDevice->ControllerNameTable,\r
563 ComponentName,\r
564 FALSE\r
565 );\r
566\r
567\r
568 WinNtDevice->WinNtIo.TypeGuid = mPcdEnvironment[Index].DevicePathGuid;\r
569 WinNtDevice->WinNtIo.InstanceNumber = Count;\r
570\r
571 WinNtDevice->Signature = WIN_NT_IO_DEVICE_SIGNATURE;\r
572\r
573 Status = gBS->InstallMultipleProtocolInterfaces (\r
574 &WinNtDevice->Handle,\r
575 &gEfiDevicePathProtocolGuid,\r
576 WinNtDevice->DevicePath,\r
577 &gEfiWinNtIoProtocolGuid,\r
578 &WinNtDevice->WinNtIo,\r
579 NULL\r
580 );\r
581 if (EFI_ERROR (Status)) {\r
582 FreeUnicodeStringTable (WinNtDevice->ControllerNameTable);\r
583 FreePool (WinNtDevice);\r
584 } else {\r
585 //\r
586 // Open For Child Device\r
587 //\r
588 Status = gBS->OpenProtocol (\r
589 ControllerHandle,\r
590 &gEfiWinNtThunkProtocolGuid,\r
591 (VOID **) &WinNtThunk,\r
592 This->DriverBindingHandle,\r
593 WinNtDevice->Handle,\r
594 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
595 );\r
596 }\r
597 }\r
598\r
599 //\r
600 // Parse Next sub string. This will point to '\0' if we are at the end.\r
601 //\r
602 Count++;\r
603 StartString = SubString;\r
604 }\r
605\r
606 FreePool (TempStr);\r
607 }\r
608\r
609 return EFI_SUCCESS;\r
610}\r
611\r
612\r
613EFI_STATUS\r
614EFIAPI\r
615WinNtBusDriverBindingStop (\r
616 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
617 IN EFI_HANDLE ControllerHandle,\r
618 IN UINTN NumberOfChildren,\r
619 IN EFI_HANDLE *ChildHandleBuffer\r
620 )\r
621/*++\r
622\r
623Routine Description:\r
624\r
625Arguments:\r
626\r
627Returns:\r
628\r
629 None\r
630\r
631--*/\r
632// TODO: This - add argument and description to function comment\r
633// TODO: ControllerHandle - add argument and description to function comment\r
634// TODO: NumberOfChildren - add argument and description to function comment\r
635// TODO: ChildHandleBuffer - add argument and description to function comment\r
636// TODO: EFI_SUCCESS - add return value to function comment\r
637// TODO: EFI_DEVICE_ERROR - add return value to function comment\r
638// TODO: EFI_SUCCESS - add return value to function comment\r
639{\r
640 EFI_STATUS Status;\r
641 UINTN Index;\r
642 BOOLEAN AllChildrenStopped;\r
643 EFI_WIN_NT_IO_PROTOCOL *WinNtIo;\r
644 WIN_NT_BUS_DEVICE *WinNtBusDevice;\r
645 WIN_NT_IO_DEVICE *WinNtDevice;\r
646 EFI_WIN_NT_THUNK_PROTOCOL *WinNtThunk;\r
647\r
648 //\r
649 // Complete all outstanding transactions to Controller.\r
650 // Don't allow any new transaction to Controller to be started.\r
651 //\r
652\r
653 if (NumberOfChildren == 0) {\r
654 //\r
655 // Close the bus driver\r
656 //\r
657 Status = gBS->OpenProtocol (\r
658 ControllerHandle,\r
659 &gWinNtBusDriverGuid,\r
660 (VOID **) &WinNtBusDevice,\r
661 This->DriverBindingHandle,\r
662 ControllerHandle,\r
663 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
664 );\r
665 if (EFI_ERROR (Status)) {\r
666 return Status;\r
667 }\r
668\r
669 gBS->UninstallMultipleProtocolInterfaces (\r
670 ControllerHandle,\r
671 &gWinNtBusDriverGuid,\r
672 WinNtBusDevice,\r
673 NULL\r
674 );\r
675\r
676 FreeUnicodeStringTable (WinNtBusDevice->ControllerNameTable);\r
677\r
678 FreePool (WinNtBusDevice);\r
679\r
680 gBS->CloseProtocol (\r
681 ControllerHandle,\r
682 &gEfiWinNtThunkProtocolGuid,\r
683 This->DriverBindingHandle,\r
684 ControllerHandle\r
685 );\r
686\r
687 gBS->CloseProtocol (\r
688 ControllerHandle,\r
689 &gEfiDevicePathProtocolGuid,\r
690 This->DriverBindingHandle,\r
691 ControllerHandle\r
692 );\r
693 return EFI_SUCCESS;\r
694 }\r
695\r
696 AllChildrenStopped = TRUE;\r
697\r
698 for (Index = 0; Index < NumberOfChildren; Index++) {\r
699\r
700 Status = gBS->OpenProtocol (\r
701 ChildHandleBuffer[Index],\r
702 &gEfiWinNtIoProtocolGuid,\r
703 (VOID **) &WinNtIo,\r
704 This->DriverBindingHandle,\r
705 ControllerHandle,\r
706 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
707 );\r
708 if (!EFI_ERROR (Status)) {\r
709\r
710 WinNtDevice = WIN_NT_IO_DEVICE_FROM_THIS (WinNtIo);\r
711\r
712 Status = gBS->CloseProtocol (\r
713 ControllerHandle,\r
714 &gEfiWinNtThunkProtocolGuid,\r
715 This->DriverBindingHandle,\r
716 WinNtDevice->Handle\r
717 );\r
718\r
719 Status = gBS->UninstallMultipleProtocolInterfaces (\r
720 WinNtDevice->Handle,\r
721 &gEfiDevicePathProtocolGuid,\r
722 WinNtDevice->DevicePath,\r
723 &gEfiWinNtIoProtocolGuid,\r
724 &WinNtDevice->WinNtIo,\r
725 NULL\r
726 );\r
727\r
728 if (EFI_ERROR (Status)) {\r
729 gBS->OpenProtocol (\r
730 ControllerHandle,\r
731 &gEfiWinNtThunkProtocolGuid,\r
732 (VOID **) &WinNtThunk,\r
733 This->DriverBindingHandle,\r
734 WinNtDevice->Handle,\r
735 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
736 );\r
737 } else {\r
738 //\r
739 // Close the child handle\r
740 //\r
741 FreeUnicodeStringTable (WinNtDevice->ControllerNameTable);\r
742 FreePool (WinNtDevice);\r
743 }\r
744 }\r
745\r
746 if (EFI_ERROR (Status)) {\r
747 AllChildrenStopped = FALSE;\r
748 }\r
749 }\r
750\r
751 if (!AllChildrenStopped) {\r
752 return EFI_DEVICE_ERROR;\r
753 }\r
754\r
755 return EFI_SUCCESS;\r
756}\r
757\r
758EFI_DEVICE_PATH_PROTOCOL *\r
759WinNtBusCreateDevicePath (\r
760 IN EFI_DEVICE_PATH_PROTOCOL *RootDevicePath,\r
761 IN EFI_GUID *Guid,\r
762 IN UINT16 InstanceNumber\r
763 )\r
764/*++\r
765\r
766Routine Description:\r
767 Create a device path node using Guid and InstanceNumber and append it to\r
768 the passed in RootDevicePath\r
769\r
770Arguments:\r
771 RootDevicePath - Root of the device path to return.\r
772\r
773 Guid - GUID to use in vendor device path node.\r
774\r
775 InstanceNumber - Instance number to use in the vendor device path. This\r
776 argument is needed to make sure each device path is unique.\r
777\r
778Returns:\r
779\r
780 EFI_DEVICE_PATH_PROTOCOL\r
781\r
782--*/\r
783{\r
784 WIN_NT_VENDOR_DEVICE_PATH_NODE DevicePath;\r
785\r
786 DevicePath.VendorDevicePath.Header.Type = HARDWARE_DEVICE_PATH;\r
787 DevicePath.VendorDevicePath.Header.SubType = HW_VENDOR_DP;\r
788 SetDevicePathNodeLength (&DevicePath.VendorDevicePath.Header, sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE));\r
789\r
790 //\r
791 // The GUID defines the Class\r
792 //\r
793 CopyMem (&DevicePath.VendorDevicePath.Guid, Guid, sizeof (EFI_GUID));\r
794\r
795 //\r
796 // Add an instance number so we can make sure there are no Device Path\r
797 // duplication.\r
798 //\r
799 DevicePath.Instance = InstanceNumber;\r
800\r
801 return AppendDevicePathNode (\r
802 RootDevicePath,\r
803 (EFI_DEVICE_PATH_PROTOCOL *) &DevicePath\r
804 );\r
805}\r