]>
Commit | Line | Data |
---|---|---|
6ae81428 | 1 | /**@file\r |
420fc8e5 | 2 | \r |
3 | Copyright (c) 2006 - 2007, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | WinNtBusDriver.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | This following section documents the envirnoment variables for the Win NT\r | |
19 | build. These variables are used to define the (virtual) hardware\r | |
20 | configuration of the NT environment\r | |
21 | \r | |
22 | A ! can be used to seperate multiple instances in a variable. Each\r | |
23 | instance represents a seperate hardware device.\r | |
24 | \r | |
25 | EFI_WIN_NT_PHYSICAL_DISKS - maps to drives on your system\r | |
26 | EFI_WIN_NT_VIRTUAL_DISKS - maps to a device emulated by a file\r | |
27 | EFI_WIN_NT_FILE_SYSTEM - mouts a directory as a file system\r | |
28 | EFI_WIN_NT_CONSOLE - make a logical comand line window (only one!)\r | |
62409219 | 29 | EFI_WIN_NT_GOP - Builds GOP Windows of Width and Height\r |
420fc8e5 | 30 | EFI_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 | |
128 | extern EFI_GUID gWinNtBusDriverGuid;\r | |
129 | //\r | |
130 | // DriverBinding protocol global\r | |
131 | //\r | |
132 | EFI_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 | 147 | NT_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 | |
166 | EFI_STATUS\r | |
167 | EFIAPI\r | |
168 | InitializeWinNtBusDriver(\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 | |
192 | VOID *\r | |
193 | AllocateMemory (\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 | |
206 | EFI_STATUS\r | |
207 | EFIAPI\r | |
208 | WinNtBusDriverBindingSupported (\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 | |
215 | Routine Description:\r | |
216 | \r | |
217 | Arguments:\r | |
218 | \r | |
219 | Returns:\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 | |
3d6b07b6 | 265 | (VOID **) &ParentDevicePath,\r |
420fc8e5 | 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 | |
3d6b07b6 | 288 | (VOID **) &WinNtThunk,\r |
420fc8e5 | 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 | |
322 | EFI_STATUS\r | |
323 | EFIAPI\r | |
324 | WinNtBusDriverBindingStart (\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 | |
331 | Routine Description:\r | |
332 | \r | |
333 | Arguments:\r | |
334 | \r | |
335 | Returns:\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 | |
420fc8e5 | 348 | EFI_WIN_NT_THUNK_PROTOCOL *WinNtThunk;\r |
349 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
350 | WIN_NT_BUS_DEVICE *WinNtBusDevice;\r | |
351 | WIN_NT_IO_DEVICE *WinNtDevice;\r | |
352 | UINTN Index;\r | |
353 | CHAR16 *StartString;\r | |
354 | CHAR16 *SubString;\r | |
355 | UINT16 Count;\r | |
356 | UINTN StringSize;\r | |
357 | UINT16 ComponentName[MAX_NT_ENVIRNMENT_VARIABLE_LENGTH];\r | |
358 | WIN_NT_VENDOR_DEVICE_PATH_NODE *Node;\r | |
359 | BOOLEAN CreateDevice;\r | |
360 | CHAR16 *TempStr;\r | |
361 | CHAR16 *PcdTempStr;\r | |
362 | UINTN TempStrSize;\r | |
363 | \r | |
364 | Status = EFI_UNSUPPORTED;\r | |
365 | \r | |
366 | //\r | |
367 | // Grab the protocols we need\r | |
368 | //\r | |
369 | Status = gBS->OpenProtocol (\r | |
370 | ControllerHandle,\r | |
371 | &gEfiDevicePathProtocolGuid,\r | |
3d6b07b6 | 372 | (VOID **) &ParentDevicePath,\r |
420fc8e5 | 373 | This->DriverBindingHandle,\r |
374 | ControllerHandle,\r | |
375 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
376 | );\r | |
377 | if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r | |
378 | return Status;\r | |
379 | }\r | |
380 | \r | |
381 | Status = gBS->OpenProtocol (\r | |
382 | ControllerHandle,\r | |
383 | &gEfiWinNtThunkProtocolGuid,\r | |
3d6b07b6 | 384 | (VOID **) &WinNtThunk,\r |
420fc8e5 | 385 | This->DriverBindingHandle,\r |
386 | ControllerHandle,\r | |
387 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
388 | );\r | |
389 | if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r | |
390 | return Status;\r | |
391 | }\r | |
392 | \r | |
393 | if (Status != EFI_ALREADY_STARTED) {\r | |
394 | WinNtBusDevice = AllocatePool (sizeof (WIN_NT_BUS_DEVICE));\r | |
395 | if (WinNtBusDevice == NULL) {\r | |
396 | return EFI_OUT_OF_RESOURCES;\r | |
397 | }\r | |
398 | \r | |
399 | WinNtBusDevice->Signature = WIN_NT_BUS_DEVICE_SIGNATURE;\r | |
400 | WinNtBusDevice->ControllerNameTable = NULL;\r | |
401 | \r | |
e1107a76 | 402 | AddUnicodeString2 (\r |
420fc8e5 | 403 | "eng",\r |
404 | gWinNtBusDriverComponentName.SupportedLanguages,\r | |
405 | &WinNtBusDevice->ControllerNameTable,\r | |
e1107a76 | 406 | L"Windows Bus Controller",\r |
407 | TRUE\r | |
420fc8e5 | 408 | );\r |
e1107a76 | 409 | AddUnicodeString2 (\r |
410 | "en",\r | |
411 | gWinNtBusDriverComponentName2.SupportedLanguages,\r | |
412 | &WinNtBusDevice->ControllerNameTable,\r | |
413 | L"Windows Bus Controller",\r | |
414 | FALSE\r | |
415 | );\r | |
416 | \r | |
420fc8e5 | 417 | \r |
418 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
419 | &ControllerHandle,\r | |
420 | &gWinNtBusDriverGuid,\r | |
421 | WinNtBusDevice,\r | |
422 | NULL\r | |
423 | );\r | |
424 | if (EFI_ERROR (Status)) {\r | |
425 | FreeUnicodeStringTable (WinNtBusDevice->ControllerNameTable);\r | |
426 | FreePool (WinNtBusDevice);\r | |
427 | return Status;\r | |
428 | }\r | |
429 | }\r | |
430 | \r | |
431 | //\r | |
432 | // Loop on the Variable list. Parse each variable to produce a set of handles that\r | |
433 | // represent virtual hardware devices.\r | |
434 | //\r | |
420fc8e5 | 435 | for (Index = 0; Index < NT_PCD_ARRAY_SIZE; Index++) {\r |
cba9012a | 436 | PcdTempStr = (VOID *)LibPcdGetPtr (mPcdEnvironment[Index].Token);\r |
420fc8e5 | 437 | ASSERT (PcdTempStr != NULL);\r |
438 | \r | |
439 | TempStrSize = StrLen (PcdTempStr);\r | |
440 | TempStr = AllocateMemory ((TempStrSize * sizeof (CHAR16)) + 1);\r | |
441 | StrCpy (TempStr, PcdTempStr);\r | |
442 | \r | |
443 | StartString = TempStr;\r | |
444 | \r | |
445 | //\r | |
446 | // Parse the envirnment variable into sub strings using '!' as a delimator.\r | |
447 | // Each substring needs it's own handle to be added to the system. This code\r | |
448 | // does not understand the sub string. Thats the device drivers job.\r | |
449 | //\r | |
450 | Count = 0;\r | |
451 | while (*StartString != '\0') {\r | |
452 | \r | |
453 | //\r | |
454 | // Find the end of the sub string\r | |
455 | //\r | |
456 | SubString = StartString;\r | |
457 | while (*SubString != '\0' && *SubString != '!') {\r | |
458 | SubString++;\r | |
459 | }\r | |
460 | \r | |
461 | if (*SubString == '!') {\r | |
462 | //\r | |
463 | // Replace token with '\0' to make sub strings. If this is the end\r | |
464 | // of the string SubString will already point to NULL.\r | |
465 | //\r | |
466 | *SubString = '\0';\r | |
467 | SubString++;\r | |
468 | }\r | |
469 | \r | |
470 | CreateDevice = TRUE;\r | |
471 | if (RemainingDevicePath != NULL) {\r | |
472 | CreateDevice = FALSE;\r | |
473 | Node = (WIN_NT_VENDOR_DEVICE_PATH_NODE *) RemainingDevicePath;\r | |
474 | if (Node->VendorDevicePath.Header.Type == HARDWARE_DEVICE_PATH &&\r | |
475 | Node->VendorDevicePath.Header.SubType == HW_VENDOR_DP &&\r | |
476 | DevicePathNodeLength (&Node->VendorDevicePath.Header) == sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE)\r | |
477 | ) {\r | |
478 | if (CompareGuid (&Node->VendorDevicePath.Guid, mPcdEnvironment[Index].DevicePathGuid) &&\r | |
479 | Node->Instance == Count\r | |
480 | ) {\r | |
481 | CreateDevice = TRUE;\r | |
482 | }\r | |
483 | }\r | |
484 | }\r | |
485 | \r | |
486 | if (CreateDevice) {\r | |
487 | \r | |
488 | //\r | |
489 | // Allocate instance structure, and fill in parent information.\r | |
490 | //\r | |
491 | WinNtDevice = AllocateMemory (sizeof (WIN_NT_IO_DEVICE));\r | |
492 | if (WinNtDevice == NULL) {\r | |
493 | return EFI_OUT_OF_RESOURCES;\r | |
494 | }\r | |
495 | \r | |
496 | WinNtDevice->Handle = NULL;\r | |
497 | WinNtDevice->ControllerHandle = ControllerHandle;\r | |
498 | WinNtDevice->ParentDevicePath = ParentDevicePath;\r | |
499 | \r | |
500 | WinNtDevice->WinNtIo.WinNtThunk = WinNtThunk;\r | |
501 | \r | |
502 | //\r | |
503 | // Plus 2 to account for the NULL at the end of the Unicode string\r | |
504 | //\r | |
505 | StringSize = (UINTN) ((UINT8 *) SubString - (UINT8 *) StartString) + sizeof (CHAR16);\r | |
506 | WinNtDevice->WinNtIo.EnvString = AllocateMemory (StringSize);\r | |
507 | if (WinNtDevice->WinNtIo.EnvString != NULL) {\r | |
508 | CopyMem (WinNtDevice->WinNtIo.EnvString, StartString, StringSize);\r | |
509 | }\r | |
510 | \r | |
511 | WinNtDevice->ControllerNameTable = NULL;\r | |
512 | \r | |
513 | WinNtThunk->SPrintf (ComponentName, sizeof (ComponentName), L"%s", WinNtDevice->WinNtIo.EnvString);\r | |
514 | \r | |
515 | WinNtDevice->DevicePath = WinNtBusCreateDevicePath (\r | |
516 | ParentDevicePath,\r | |
517 | mPcdEnvironment[Index].DevicePathGuid,\r | |
518 | Count\r | |
519 | );\r | |
520 | if (WinNtDevice->DevicePath == NULL) {\r | |
521 | FreePool (WinNtDevice);\r | |
522 | return EFI_OUT_OF_RESOURCES;\r | |
523 | }\r | |
524 | \r | |
e1107a76 | 525 | AddUnicodeString2 (\r |
420fc8e5 | 526 | "eng",\r |
527 | gWinNtBusDriverComponentName.SupportedLanguages,\r | |
528 | &WinNtDevice->ControllerNameTable,\r | |
e1107a76 | 529 | ComponentName,\r |
530 | TRUE\r | |
420fc8e5 | 531 | );\r |
e1107a76 | 532 | AddUnicodeString2 (\r |
533 | "en",\r | |
534 | gWinNtBusDriverComponentName2.SupportedLanguages,\r | |
535 | &WinNtDevice->ControllerNameTable,\r | |
536 | ComponentName,\r | |
537 | FALSE\r | |
538 | );\r | |
539 | \r | |
420fc8e5 | 540 | \r |
541 | WinNtDevice->WinNtIo.TypeGuid = mPcdEnvironment[Index].DevicePathGuid;\r | |
542 | WinNtDevice->WinNtIo.InstanceNumber = Count;\r | |
543 | \r | |
544 | WinNtDevice->Signature = WIN_NT_IO_DEVICE_SIGNATURE;\r | |
545 | \r | |
546 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
547 | &WinNtDevice->Handle,\r | |
548 | &gEfiDevicePathProtocolGuid,\r | |
549 | WinNtDevice->DevicePath,\r | |
550 | &gEfiWinNtIoProtocolGuid,\r | |
551 | &WinNtDevice->WinNtIo,\r | |
552 | NULL\r | |
553 | );\r | |
554 | if (EFI_ERROR (Status)) {\r | |
555 | FreeUnicodeStringTable (WinNtDevice->ControllerNameTable);\r | |
556 | FreePool (WinNtDevice);\r | |
557 | } else {\r | |
558 | //\r | |
559 | // Open For Child Device\r | |
560 | //\r | |
561 | Status = gBS->OpenProtocol (\r | |
562 | ControllerHandle,\r | |
563 | &gEfiWinNtThunkProtocolGuid,\r | |
3d6b07b6 | 564 | (VOID **) &WinNtThunk,\r |
420fc8e5 | 565 | This->DriverBindingHandle,\r |
566 | WinNtDevice->Handle,\r | |
567 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
568 | );\r | |
420fc8e5 | 569 | }\r |
570 | }\r | |
571 | \r | |
572 | //\r | |
573 | // Parse Next sub string. This will point to '\0' if we are at the end.\r | |
574 | //\r | |
575 | Count++;\r | |
576 | StartString = SubString;\r | |
577 | }\r | |
578 | \r | |
579 | FreePool (TempStr);\r | |
580 | }\r | |
581 | \r | |
582 | return EFI_SUCCESS;\r | |
583 | }\r | |
584 | \r | |
585 | \r | |
586 | EFI_STATUS\r | |
587 | EFIAPI\r | |
588 | WinNtBusDriverBindingStop (\r | |
589 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
590 | IN EFI_HANDLE ControllerHandle,\r | |
591 | IN UINTN NumberOfChildren,\r | |
592 | IN EFI_HANDLE *ChildHandleBuffer\r | |
593 | )\r | |
594 | /*++\r | |
595 | \r | |
596 | Routine Description:\r | |
597 | \r | |
598 | Arguments:\r | |
599 | \r | |
600 | Returns:\r | |
601 | \r | |
602 | None\r | |
603 | \r | |
604 | --*/\r | |
605 | // TODO: This - add argument and description to function comment\r | |
606 | // TODO: ControllerHandle - add argument and description to function comment\r | |
607 | // TODO: NumberOfChildren - add argument and description to function comment\r | |
608 | // TODO: ChildHandleBuffer - add argument and description to function comment\r | |
609 | // TODO: EFI_SUCCESS - add return value to function comment\r | |
610 | // TODO: EFI_DEVICE_ERROR - add return value to function comment\r | |
611 | // TODO: EFI_SUCCESS - add return value to function comment\r | |
612 | {\r | |
613 | EFI_STATUS Status;\r | |
614 | UINTN Index;\r | |
615 | BOOLEAN AllChildrenStopped;\r | |
616 | EFI_WIN_NT_IO_PROTOCOL *WinNtIo;\r | |
617 | WIN_NT_BUS_DEVICE *WinNtBusDevice;\r | |
618 | WIN_NT_IO_DEVICE *WinNtDevice;\r | |
619 | EFI_WIN_NT_THUNK_PROTOCOL *WinNtThunk;\r | |
620 | \r | |
621 | //\r | |
622 | // Complete all outstanding transactions to Controller.\r | |
623 | // Don't allow any new transaction to Controller to be started.\r | |
624 | //\r | |
625 | \r | |
626 | if (NumberOfChildren == 0) {\r | |
627 | //\r | |
628 | // Close the bus driver\r | |
629 | //\r | |
630 | Status = gBS->OpenProtocol (\r | |
631 | ControllerHandle,\r | |
632 | &gWinNtBusDriverGuid,\r | |
3d6b07b6 | 633 | (VOID **) &WinNtBusDevice,\r |
420fc8e5 | 634 | This->DriverBindingHandle,\r |
635 | ControllerHandle,\r | |
636 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
637 | );\r | |
638 | if (EFI_ERROR (Status)) {\r | |
639 | return Status;\r | |
640 | }\r | |
641 | \r | |
642 | gBS->UninstallMultipleProtocolInterfaces (\r | |
643 | ControllerHandle,\r | |
644 | &gWinNtBusDriverGuid,\r | |
645 | WinNtBusDevice,\r | |
646 | NULL\r | |
647 | );\r | |
648 | \r | |
649 | FreeUnicodeStringTable (WinNtBusDevice->ControllerNameTable);\r | |
650 | \r | |
651 | FreePool (WinNtBusDevice);\r | |
652 | \r | |
653 | gBS->CloseProtocol (\r | |
654 | ControllerHandle,\r | |
655 | &gEfiWinNtThunkProtocolGuid,\r | |
656 | This->DriverBindingHandle,\r | |
657 | ControllerHandle\r | |
658 | );\r | |
659 | \r | |
660 | gBS->CloseProtocol (\r | |
661 | ControllerHandle,\r | |
662 | &gEfiDevicePathProtocolGuid,\r | |
663 | This->DriverBindingHandle,\r | |
664 | ControllerHandle\r | |
665 | );\r | |
666 | return EFI_SUCCESS;\r | |
667 | }\r | |
668 | \r | |
669 | AllChildrenStopped = TRUE;\r | |
670 | \r | |
671 | for (Index = 0; Index < NumberOfChildren; Index++) {\r | |
672 | \r | |
673 | Status = gBS->OpenProtocol (\r | |
674 | ChildHandleBuffer[Index],\r | |
675 | &gEfiWinNtIoProtocolGuid,\r | |
3d6b07b6 | 676 | (VOID **) &WinNtIo,\r |
420fc8e5 | 677 | This->DriverBindingHandle,\r |
678 | ControllerHandle,\r | |
679 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
680 | );\r | |
681 | if (!EFI_ERROR (Status)) {\r | |
682 | \r | |
683 | WinNtDevice = WIN_NT_IO_DEVICE_FROM_THIS (WinNtIo);\r | |
684 | \r | |
685 | Status = gBS->CloseProtocol (\r | |
686 | ControllerHandle,\r | |
687 | &gEfiWinNtThunkProtocolGuid,\r | |
688 | This->DriverBindingHandle,\r | |
689 | WinNtDevice->Handle\r | |
690 | );\r | |
691 | \r | |
692 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
693 | WinNtDevice->Handle,\r | |
694 | &gEfiDevicePathProtocolGuid,\r | |
695 | WinNtDevice->DevicePath,\r | |
696 | &gEfiWinNtIoProtocolGuid,\r | |
697 | &WinNtDevice->WinNtIo,\r | |
698 | NULL\r | |
699 | );\r | |
700 | \r | |
701 | if (EFI_ERROR (Status)) {\r | |
702 | gBS->OpenProtocol (\r | |
703 | ControllerHandle,\r | |
704 | &gEfiWinNtThunkProtocolGuid,\r | |
705 | (VOID **) &WinNtThunk,\r | |
706 | This->DriverBindingHandle,\r | |
707 | WinNtDevice->Handle,\r | |
708 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
709 | );\r | |
710 | } else {\r | |
711 | //\r | |
712 | // Close the child handle\r | |
713 | //\r | |
714 | FreeUnicodeStringTable (WinNtDevice->ControllerNameTable);\r | |
715 | FreePool (WinNtDevice);\r | |
716 | }\r | |
717 | }\r | |
718 | \r | |
719 | if (EFI_ERROR (Status)) {\r | |
720 | AllChildrenStopped = FALSE;\r | |
721 | }\r | |
722 | }\r | |
723 | \r | |
724 | if (!AllChildrenStopped) {\r | |
725 | return EFI_DEVICE_ERROR;\r | |
726 | }\r | |
727 | \r | |
728 | return EFI_SUCCESS;\r | |
729 | }\r | |
730 | \r | |
731 | EFI_DEVICE_PATH_PROTOCOL *\r | |
732 | WinNtBusCreateDevicePath (\r | |
733 | IN EFI_DEVICE_PATH_PROTOCOL *RootDevicePath,\r | |
734 | IN EFI_GUID *Guid,\r | |
735 | IN UINT16 InstanceNumber\r | |
736 | )\r | |
737 | /*++\r | |
738 | \r | |
739 | Routine Description:\r | |
740 | Create a device path node using Guid and InstanceNumber and append it to\r | |
741 | the passed in RootDevicePath\r | |
742 | \r | |
743 | Arguments:\r | |
744 | RootDevicePath - Root of the device path to return.\r | |
745 | \r | |
746 | Guid - GUID to use in vendor device path node.\r | |
747 | \r | |
748 | InstanceNumber - Instance number to use in the vendor device path. This\r | |
749 | argument is needed to make sure each device path is unique.\r | |
750 | \r | |
751 | Returns:\r | |
752 | \r | |
753 | EFI_DEVICE_PATH_PROTOCOL\r | |
754 | \r | |
755 | --*/\r | |
756 | {\r | |
757 | WIN_NT_VENDOR_DEVICE_PATH_NODE DevicePath;\r | |
758 | \r | |
759 | DevicePath.VendorDevicePath.Header.Type = HARDWARE_DEVICE_PATH;\r | |
760 | DevicePath.VendorDevicePath.Header.SubType = HW_VENDOR_DP;\r | |
761 | SetDevicePathNodeLength (&DevicePath.VendorDevicePath.Header, sizeof (WIN_NT_VENDOR_DEVICE_PATH_NODE));\r | |
762 | \r | |
763 | //\r | |
764 | // The GUID defines the Class\r | |
765 | //\r | |
766 | CopyMem (&DevicePath.VendorDevicePath.Guid, Guid, sizeof (EFI_GUID));\r | |
767 | \r | |
768 | //\r | |
769 | // Add an instance number so we can make sure there are no Device Path\r | |
770 | // duplication.\r | |
771 | //\r | |
772 | DevicePath.Instance = InstanceNumber;\r | |
773 | \r | |
774 | return AppendDevicePathNode (\r | |
775 | RootDevicePath,\r | |
776 | (EFI_DEVICE_PATH_PROTOCOL *) &DevicePath\r | |
777 | );\r | |
778 | }\r |