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